diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/EnumerationTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/EnumerationTests.java index 0815efd82b..9d0d9537fb 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/EnumerationTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/EnumerationTests.java @@ -658,7 +658,7 @@ public void testEnum13() { "}\n" + "\n" + "class A {\n" + - " public enum C2{\n" + + " enum C2{\n" + " TEST_C2\n" + " }\n" + "}\n", @@ -699,6 +699,26 @@ public void testEnum13() { //@formatter:on runConformTest(sources); + + checkGCUDeclaration("A.groovy", + "package be.flow;\n" + + "public enum C1 {\n" + + " TEST_C1,\n" + + " private @groovy.transform.Generated C1() {\n" + + " }\n" + + "}\n" + + "public class A {\n" + + " public static enum C2 {\n" + + " TEST_C2,\n" + + " private @groovy.transform.Generated C2() {\n" + + " }\n" + + " }\n" + + " public @groovy.transform.Generated A() {\n" + + " }\n" + + "}"); + + checkDisassemblyFor("be/flow/A$C2.class", + "public static final enum be.flow.A$C2 implements "); } @Test @@ -914,6 +934,9 @@ public void testAbstractMethodWithinEnum1() { " }\n" + " public abstract int foo();\n" + "}"); + + checkDisassemblyFor("Good.class", "public abstract enum Good "); + checkDisassemblyFor("Good$1.class", "\nfinal enum Good$1 {\n "); } @Test diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovyCompilerTestSuite.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovyCompilerTestSuite.java index e97e408cd8..19a5684fdd 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovyCompilerTestSuite.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovyCompilerTestSuite.java @@ -77,7 +77,7 @@ public abstract class GroovyCompilerTestSuite { protected static final long JDK14 = (58L << 16) + ClassFileConstants.MINOR_VERSION_0; protected static final long JDK15 = (59L << 16) + ClassFileConstants.MINOR_VERSION_0; protected static final long JDK16 = (60L << 16) + ClassFileConstants.MINOR_VERSION_0; - protected static final long JDK17 = (60L << 17) + ClassFileConstants.MINOR_VERSION_0; + protected static final long JDK17 = (61L << 16) + ClassFileConstants.MINOR_VERSION_0; @Parameters(name = "Java {1}") public static Iterable params() { @@ -170,8 +170,12 @@ public String getName() { @Override protected INameEnvironment getNameEnvironment(final String[] testFiles, final String[] classPaths) { - this.classpaths = (classPaths == null ? getDefaultClassPaths() : classPaths); - return new InMemoryNameEnvironment(testFiles, getClassLibs(false)); + return getNameEnvironment(testFiles, classPaths, null); + } + + protected INameEnvironment getNameEnvironment(final String[] testFiles, final String[] classPaths, final Map options) { + this.classpaths = (classPaths != null ? classPaths : getDefaultClassPaths()); + return new InMemoryNameEnvironment(testFiles, getClassLibs(false, options)); } private String resolve(final URL jarRef) throws IOException { diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java index b460861309..96d787f76b 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java @@ -795,8 +795,8 @@ protected Expression anonymousInnerClassDef(AST node) { ClassNode outerClass = getClassOrScript(oldNode); String innerClassName = outerClass.getName() + "$" + (anonymousClassCount(outerClass) + 1); if (enumConstantBeingDef) { - classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE); - } else { + classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_ENUM | Opcodes.ACC_FINAL, ClassHelper.OBJECT_TYPE); + } else { // GRECLIPSE edit ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ classNode = new InnerClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE); } ((InnerClassNode) classNode).setAnonymous(true); @@ -1035,8 +1035,9 @@ protected void enumConstantDef(AST node) { // we have to handle an enum constant with a class overriding // a method in which case we need to configure the inner class innerClass.setSuperClass(classNode.getPlainNodeReference()); + /* GRECLIPSE edit innerClass.setModifiers(classNode.getModifiers() | Opcodes.ACC_FINAL); - // GRECLIPSE add + */ innerClass.setNameStart(nameStart); innerClass.setNameEnd(nameEnd - 1); // GRECLIPSE end diff --git a/base/org.codehaus.groovy30/src/org/apache/groovy/parser/antlr4/AstBuilder.java b/base/org.codehaus.groovy30/src/org/apache/groovy/parser/antlr4/AstBuilder.java index f80d0c6c4c..db57897fb7 100644 --- a/base/org.codehaus.groovy30/src/org/apache/groovy/parser/antlr4/AstBuilder.java +++ b/base/org.codehaus.groovy30/src/org/apache/groovy/parser/antlr4/AstBuilder.java @@ -1451,7 +1451,9 @@ public ClassNode visitClassDeclaration(ClassDeclarationContext ctx) { this.hackMixins(classNode); } else if (isEnum) { + /* GRECLIPSE edit -- EnumHelper#makeEnumNode does this classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_ENUM | Opcodes.ACC_FINAL); + */ classNode.setInterfaces(this.visitTypeList(ctx.is)); this.initUsingGenerics(classNode); @@ -3657,7 +3659,7 @@ public InnerClassNode visitAnonymousInnerClassDeclaration(AnonymousInnerClassDec InnerClassNode anonymousInnerClass; if (1 == ctx.t) { // anonymous enum - anonymousInnerClass = new EnumConstantClassNode(outerClass, innerClassName, superClass.getModifiers() | Opcodes.ACC_FINAL, superClass.getPlainNodeReference()); + anonymousInnerClass = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_ENUM | Opcodes.ACC_FINAL, superClass.getPlainNodeReference()); // and remove the final modifier from classNode to allow the sub class superClass.setModifiers(superClass.getModifiers() & ~Opcodes.ACC_FINAL); } else { // anonymous inner class diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java index 83515eb68a..1c71f49df3 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java @@ -882,8 +882,8 @@ protected Expression anonymousInnerClassDef(AST node) { ClassNode outerClass = getClassOrScript(oldNode); String innerClassName = outerClass.getName() + "$" + (anonymousClassCount(outerClass) + 1); if (enumConstantBeingDef) { - classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE); - } else { + classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_ENUM | Opcodes.ACC_FINAL, ClassHelper.OBJECT_TYPE); + } else { // GRECLIPSE edit ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ classNode = new InnerClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE); } ((InnerClassNode) classNode).setAnonymous(true); @@ -1123,8 +1123,9 @@ protected void enumConstantDef(AST node) { // we have to handle an enum constant with a class overriding // a method in which case we need to configure the inner class innerClass.setSuperClass(classNode.getPlainNodeReference()); + /* GRECLIPSE edit innerClass.setModifiers(classNode.getModifiers() | Opcodes.ACC_FINAL); - // GRECLIPSE add + */ innerClass.setNameStart(nameStart); innerClass.setNameEnd(nameEnd - 1); // GRECLIPSE end diff --git a/base/org.codehaus.groovy40/groovy-parser2.jar b/base/org.codehaus.groovy40/groovy-parser2.jar index 1a39d2444d..2e3e3aa2a6 100644 Binary files a/base/org.codehaus.groovy40/groovy-parser2.jar and b/base/org.codehaus.groovy40/groovy-parser2.jar differ diff --git a/base/org.codehaus.groovy40/src/org/apache/groovy/parser/antlr4/AstBuilder.java b/base/org.codehaus.groovy40/src/org/apache/groovy/parser/antlr4/AstBuilder.java index 581cf96541..feb2ba034e 100644 --- a/base/org.codehaus.groovy40/src/org/apache/groovy/parser/antlr4/AstBuilder.java +++ b/base/org.codehaus.groovy40/src/org/apache/groovy/parser/antlr4/AstBuilder.java @@ -1515,8 +1515,7 @@ public ClassNode visitClassDeclaration(final ClassDeclarationContext ctx) { if ((isAnnotation || isEnum) && (isSealed || isNonSealed)) { ModifierNode mn = isSealed ? sealedModifierNodeOptional.get() : nonSealedModifierNodeOptional.get(); - throw createParsingFailedException("modifier `" + mn.getText() + "` is not allowed for " + - (isEnum ? "enum" : "annotation definition"), mn); + throw createParsingFailedException("modifier `" + mn.getText() + "` is not allowed for " + (isEnum ? "enum" : "annotation definition"), mn); } boolean hasPermits = asBoolean(ctx.PERMITS()); @@ -1613,7 +1612,9 @@ public ClassNode visitClassDeclaration(final ClassDeclarationContext ctx) { this.hackMixins(classNode); } else if (isEnum) { + /* GRECLIPSE edit -- EnumHelper#makeEnumNode does this classNode.setModifiers(classNode.getModifiers() | Opcodes.ACC_ENUM | Opcodes.ACC_FINAL); + */ classNode.setInterfaces(this.visitTypeList(ctx.is)); this.initUsingGenerics(classNode); @@ -3829,7 +3830,7 @@ public InnerClassNode visitAnonymousInnerClassDeclaration(final AnonymousInnerCl InnerClassNode anonymousInnerClass; if (1 == ctx.t) { // anonymous enum - anonymousInnerClass = new EnumConstantClassNode(outerClass, innerClassName, superClass.getModifiers() | Opcodes.ACC_FINAL, superClass.getPlainNodeReference()); + anonymousInnerClass = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_ENUM | Opcodes.ACC_FINAL, superClass.getPlainNodeReference()); // and remove the final modifier from classNode to allow the sub class superClass.setModifiers(superClass.getModifiers() & ~Opcodes.ACC_FINAL); } else { // anonymous inner class diff --git a/base/org.codehaus.groovy40/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/base/org.codehaus.groovy40/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java index 0c9f401b3c..b4ac37c6fd 100644 --- a/base/org.codehaus.groovy40/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java +++ b/base/org.codehaus.groovy40/src/org/codehaus/groovy/antlr/AntlrParserPlugin.java @@ -882,8 +882,8 @@ protected Expression anonymousInnerClassDef(AST node) { ClassNode outerClass = getClassOrScript(oldNode); String innerClassName = outerClass.getName() + "$" + (anonymousClassCount(outerClass) + 1); if (enumConstantBeingDef) { - classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE); - } else { + classNode = new EnumConstantClassNode(outerClass, innerClassName, Opcodes.ACC_ENUM | Opcodes.ACC_FINAL, ClassHelper.OBJECT_TYPE); + } else { // GRECLIPSE edit ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ classNode = new InnerClassNode(outerClass, innerClassName, Opcodes.ACC_PUBLIC, ClassHelper.OBJECT_TYPE); } ((InnerClassNode) classNode).setAnonymous(true); @@ -1123,8 +1123,9 @@ protected void enumConstantDef(AST node) { // we have to handle an enum constant with a class overriding // a method in which case we need to configure the inner class innerClass.setSuperClass(classNode.getPlainNodeReference()); + /* GRECLIPSE edit innerClass.setModifiers(classNode.getModifiers() | Opcodes.ACC_FINAL); - // GRECLIPSE add + */ innerClass.setNameStart(nameStart); innerClass.setNameEnd(nameEnd - 1); // GRECLIPSE end diff --git a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java index 57aa36d155..a36b4ea6a1 100644 --- a/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java +++ b/base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java @@ -1143,7 +1143,7 @@ private void createTypeDeclarations(ModuleNode moduleNode) { } boolean isEnum = classNode.isEnum(); - configureSuperClass(typeDeclaration, classNode.getSuperClass(), isEnum, isTrait(classNode)); + if (!isEnum && !isTrait(classNode)) configureSuperClass(typeDeclaration, classNode.getSuperClass()); configureSuperInterfaces(typeDeclaration, classNode); typeDeclaration.fields = createFieldDeclarations(classNode, isEnum); typeDeclaration.methods = createConstructorAndMethodDeclarations(classNode, isEnum, typeDeclaration); @@ -1546,15 +1546,9 @@ private AbstractMethodDeclaration createMethodDeclaration(ClassNode classNode, M //---------------------------------------------------------------------- - private void configureSuperClass(TypeDeclaration typeDeclaration, ClassNode superclass, boolean isEnum, boolean isTrait) { - if ((isEnum && superclass.getName().equals("java.lang.Enum")) || isTrait) { - // Don't wire it in, JDT will do it - typeDeclaration.superclass = null; - } else { - // If the start position is 0 the superclass wasn't actually declared, it was added by Groovy - if (!(superclass.getStart() == 0 && superclass.equals(ClassHelper.OBJECT_TYPE))) { - typeDeclaration.superclass = createTypeReferenceForClassNode(superclass); - } + private void configureSuperClass(TypeDeclaration typeDeclaration, ClassNode superclass) { + if (!(superclass.getStart() == 0 && superclass.equals(ClassHelper.OBJECT_TYPE))) { + typeDeclaration.superclass = createTypeReferenceForClassNode(superclass); } } diff --git a/docs/Getting-Started-with-Groovy-Eclipse-Source-Code.md b/docs/Getting-Started-with-Groovy-Eclipse-Source-Code.md index 0945865bd6..14d4cb5f6e 100644 --- a/docs/Getting-Started-with-Groovy-Eclipse-Source-Code.md +++ b/docs/Getting-Started-with-Groovy-Eclipse-Source-Code.md @@ -167,7 +167,7 @@ This minimal project set should be open in your workspace: * org.eclipse.jdt.groovy.core.tests.builder * org.eclipse.jdt.groovy.core.tests.compiler -Note: Only one JDT patch should be imported (`org.eclipse.jdt.core`, `org.eclipse.jdt.core.tests.builder`, `org.eclipse.jdt.core.tests.compiler`) and it should be matched to the target platform of your workspace. For example, the patch in the `/e421` folder is for Eclipse 4.21 (2021-09). +Note: Only one JDT patch should be imported (`org.eclipse.jdt.core`, `org.eclipse.jdt.core.tests.builder`, `org.eclipse.jdt.core.tests.compiler`) and it should be matched to the target platform of your workspace. For example, the patch in the `/e422` folder is for Eclipse 4.22 (2021-12). ## Test with Eclipse @@ -185,14 +185,15 @@ For manual testing and debugging, right-click on the org.codehaus.groovy.eclipse [Download and install Maven](https://maven.apache.org/). -From the root directory of the repository, execute the following command to build Groovy-Eclipse for Eclipse 4.21 (2021-09). +From the root directory of the repository, execute the following command to build Groovy-Eclipse for Eclipse 4.22 (2021-12). ``` - mvn -Pe4.21 clean install + mvn -Pe4.22 clean install ``` -Replace e4.21 with a different option to build it for another Eclipse version: +Replace e4.22 with a different option to build it for another Eclipse version: +* e4.21 * e4.20 * e4.19 * e4.18 diff --git a/groovy-eclipse.setup b/groovy-eclipse.setup index 64b05d81b1..4bd391c30f 100644 --- a/groovy-eclipse.setup +++ b/groovy-eclipse.setup @@ -72,6 +72,9 @@ defaultValue="2020-06" storageURI="scope://Workspace" label="Target Platform"> + @@ -87,9 +90,6 @@ - Choose the compatibility level of the target platform + filter="(| (scope.product.version.name=2021-12) (scope.product.version.name=latest))"> + + + + - - - - + + + @@ -260,13 +267,6 @@ rootFolder="${git.clone.Groovy-Eclipse.location}/jdt-patch/e417" locateNestedProjects="true"/> - - - + + + + + - - - - -Xmx1G -XX:-OmitStackTraceInFastThrow - 9000 + 7200 true true true diff --git a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index ff86f39ce7..6ebddce5e6 100644 --- a/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e410/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1417,7 +1417,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e411/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e411/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index b64d1c4185..ee0b29881b 100644 --- a/jdt-patch/e411/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e411/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1420,7 +1420,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e412/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e412/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index d4ce59a4a3..a3883bd77f 100644 --- a/jdt-patch/e412/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e412/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1435,7 +1435,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e413/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e413/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index 62e27737fd..6f1b1d61a9 100644 --- a/jdt-patch/e413/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e413/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1483,7 +1483,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e414/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e414/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index a13cfab341..23c59dfe3f 100644 --- a/jdt-patch/e414/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e414/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1519,7 +1519,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e415/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e415/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index 7e71eff751..27d9c3f302 100644 --- a/jdt-patch/e415/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e415/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1519,7 +1519,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e416/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e416/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index e79eb71eb4..eaa8e47c1e 100644 --- a/jdt-patch/e416/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e416/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1599,7 +1599,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e417/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e417/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index 736314f3a7..c2bd22844f 100644 --- a/jdt-patch/e417/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e417/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1583,7 +1583,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e418/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e418/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index 313e76d42d..7d5441f597 100644 --- a/jdt-patch/e418/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e418/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1601,7 +1601,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e419/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e419/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index 313e76d42d..7d5441f597 100644 --- a/jdt-patch/e419/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e419/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1601,7 +1601,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e420/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e420/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index 61594ddcb4..6ed7ad1395 100644 --- a/jdt-patch/e420/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e420/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1617,7 +1617,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e421/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e421/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java index 1722aa726c..de5301661a 100644 --- a/jdt-patch/e421/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java +++ b/jdt-patch/e421/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -1617,7 +1617,10 @@ protected ClassFileReader getClassFileReader(String fileName, String className) } protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { - String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + return getClassLibs(useDefaultClasspaths, null); + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + String encoding = (options != null ? options : getCompilerOptions()).get(CompilerOptions.OPTION_Encoding); if ("".equals(encoding)) encoding = null; if (useDefaultClasspaths && encoding == null) diff --git a/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/.gitignore b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/.gitignore new file mode 100644 index 0000000000..ea8c4bf7f3 --- /dev/null +++ b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/.gitignore @@ -0,0 +1 @@ +/target diff --git a/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/.project b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/.project new file mode 100644 index 0000000000..25326f2f86 --- /dev/null +++ b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/.project @@ -0,0 +1,12 @@ + + + Feature-org.codehaus.groovy.jdt.patch + + + org.eclipse.pde.FeatureBuilder + + + + org.eclipse.pde.FeatureNature + + diff --git a/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/build.properties b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/build.properties new file mode 100644 index 0000000000..8003cbc57e --- /dev/null +++ b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/build.properties @@ -0,0 +1,3 @@ +bin.includes = feature.properties,\ + feature.xml,\ + *.html diff --git a/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/feature.properties b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/feature.properties new file mode 100644 index 0000000000..4e04a9758a --- /dev/null +++ b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/feature.properties @@ -0,0 +1,124 @@ +# contains externalized strings for feature.xml +# java.io.Properties file (ISO 8859-1 with "\" escapes) +# "%foo" in feature.xml corresponds to the key "foo" in this file + +providerName=Pivotal Software, Inc. + +featureName=Eclipse JDT Core patch for Groovy + +descriptionURL=https://github.com/groovy/groovy-eclipse/wiki + +description=This JDT Core patch provides Groovy integration with the JDT and the Java compiler. + +# "licenseURL" property - URL of the "Feature License" +# do not translate value - just change to point to a locale-specific HTML page +licenseURL=license.html + +# "license" property - text of the "Feature Update License" +# should be plain text version of license agreement pointed to be "licenseURL" +license=\ +ECLIPSE FOUNDATION SOFTWARE USER AGREEMENT\n\ +March 17, 2005\n\ +\n\ +Usage Of Content\n\ +\n\ +THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR\n\ +OTHER MATERIALS FOR OPEN SOURCE PROJECTS (COLLECTIVELY "CONTENT").\n\ +USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS\n\ +AGREEMENT AND/OR THE TERMS AND CONDITIONS OF LICENSE AGREEMENTS OR\n\ +NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU\n\ +AGREE THAT YOUR USE OF THE CONTENT IS GOVERNED BY THIS AGREEMENT\n\ +AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS\n\ +OR NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE\n\ +TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND CONDITIONS\n\ +OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED\n\ +BELOW, THEN YOU MAY NOT USE THE CONTENT.\n\ +\n\ +Applicable Licenses\n\ +\n\ +Unless otherwise indicated, all Content made available by the Eclipse Foundation\n\ +is provided to you under the terms and conditions of the Eclipse Public\n\ +License Version 1.0 ("EPL"). A copy of the EPL is provided with this\n\ +Content and is also available at https://www.eclipse.org/legal/epl-v10.html.\n\ +For purposes of the EPL, "Program" will mean the Content.\n\ +\n\ +Content includes, but is not limited to, source code, object code,\n\ +documentation and other files maintained in the Eclipse.org CVS\n\ +repository ("Repository") in CVS modules ("Modules") and made available\n\ +as downloadable archives ("Downloads").\n\ +\n\ + - Content may be structured and packaged into modules to facilitate delivering,\n\ + extending, and upgrading the Content. Typical modules may include plug-ins ("Plug-ins"),\n\ + plug-in fragments ("Fragments"), and features ("Features").\n\ + - Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java? ARchive)\n\ + in a directory named "plugins".\n\ + - A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material.\n\ + Each Feature may be packaged as a sub-directory in a directory named "features".\n\ + Within a Feature, files named "feature.xml" may contain a list of the names and version\n\ + numbers of the Plug-ins and/or Fragments associated with that Feature.\n\ + - Features may also include other Features ("Included Features"). Within a Feature, files\n\ + named "feature.xml" may contain a list of the names and version numbers of Included Features.\n\ +\n\ +Features may also include other Features ("Included Features"). Files named\n\ +"feature.xml" may contain a list of the names and version numbers of\n\ +Included Features.\n\ +\n\ +The terms and conditions governing Plug-ins and Fragments should be\n\ +contained in files named "about.html" ("Abouts"). The terms and\n\ +conditions governing Features and Included Features should be contained\n\ +in files named "license.html" ("Feature Licenses"). Abouts and Feature\n\ +Licenses may be located in any directory of a Download or Module\n\ +including, but not limited to the following locations:\n\ +\n\ + - The top-level (root) directory\n\ + - Plug-in and Fragment directories\n\ + - Inside Plug-ins and Fragments packaged as JARs\n\ + - Sub-directories of the directory named "src" of certain Plug-ins\n\ + - Feature directories\n\ +\n\ +Note: if a Feature made available by the Eclipse Foundation is installed using the\n\ +Eclipse Update Manager, you must agree to a license ("Feature Update\n\ +License") during the installation process. If the Feature contains\n\ +Included Features, the Feature Update License should either provide you\n\ +with the terms and conditions governing the Included Features or inform\n\ +you where you can locate them. Feature Update Licenses may be found in\n\ +the "license" property of files named "feature.properties". Such Abouts,\n\ +Feature Licenses and Feature Update Licenses contain the terms and\n\ +conditions (or references to such terms and conditions) that govern your\n\ +use of the associated Content in that directory.\n\ +\n\ +THE ABOUTS, FEATURE LICENSES AND FEATURE UPDATE LICENSES MAY REFER\n\ +TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS.\n\ +SOME OF THESE OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):\n\ +\n\ + - Common Public License Version 1.0 (available at https://www.eclipse.org/legal/cpl-v10.html)\n\ + - Apache Software License 1.1 (available at https://www.apache.org/licenses/LICENSE)\n\ + - Apache Software License 2.0 (available at https://www.apache.org/licenses/LICENSE-2.0)\n\ + - IBM Public License 1.0 (available at http://oss.software.ibm.com/developerworks/opensource/license10.html)\n\ + - Metro Link Public License 1.00 (available at http://www.opengroup.org/openmotif/supporters/metrolink/license.html)\n\ + - Mozilla Public License Version 1.1 (available at https://www.mozilla.org/MPL/MPL-1.1.html)\n\ +\n\ +IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR\n\ +TO USE OF THE CONTENT. If no About, Feature License or Feature Update License\n\ +is provided, please contact the Eclipse Foundation to determine what terms and conditions\n\ +govern that particular Content.\n\ +\n\ +Cryptography\n\ +\n\ +Content may contain encryption software. The country in which you are\n\ +currently may have restrictions on the import, possession, and use,\n\ +and/or re-export to another country, of encryption software. BEFORE\n\ +using any encryption software, please check the country's laws,\n\ +regulations and policies concerning the import, possession, or use,\n\ +and re-export of encryption software, to see if this is permitted.\n\ +\n\ +Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.\n +########### end of license property ########################################## + +# "copyright" property - text of the "Feature Update Copyright" +copyright=\ +Copyright (c) 2009-2021 Pivotal Software, Inc. and others.\n\ +All rights reserved. This program and the accompanying materials\n\ +are made available under the terms of the Eclipse Public License v1.0\n\ +which accompanies this distribution, and is available at\n\ +https://www.eclipse.org/legal/epl-v10.html\n\ diff --git a/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/feature.xml b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/feature.xml new file mode 100644 index 0000000000..52cf3819b8 --- /dev/null +++ b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/feature.xml @@ -0,0 +1,32 @@ + + + + + + %description + + + + %copyright + + + + %license + + + + + + + + + diff --git a/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/license.html b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/license.html new file mode 100644 index 0000000000..25120c431e --- /dev/null +++ b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/license.html @@ -0,0 +1,109 @@ + + + + +Eclipse.org Software User Agreement +

Eclipse Foundation Software User Agreement

+

March 17, 2005

+ +

Usage Of Content

+ +

THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS + (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND + CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE + OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR + NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND + CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.

+ +

Applicable Licenses

+ +

Unless otherwise indicated, all Content made available by the +Eclipse Foundation is provided to you under the terms and conditions of +the Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is +provided with this Content and is also available at https://www.eclipse.org/legal/epl-v10.html. + For purposes of the EPL, "Program" will mean the Content.

+ +

Content includes, but is not limited to, source code, object code, +documentation and other files maintained in the Eclipse.org CVS +repository ("Repository") in CVS modules ("Modules") and made available +as downloadable archives ("Downloads").

+ +
    +
  • Content may be structured and packaged into modules to +facilitate delivering, extending, and upgrading the Content. Typical +modules may include plug-ins ("Plug-ins"), plug-in fragments +("Fragments"), and features ("Features").
  • +
  • Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java™ ARchive) in a directory named "plugins".
  • +
  • A +Feature is a bundle of one or more Plug-ins and/or Fragments and +associated material. Each Feature may be packaged as a sub-directory in +a directory named "features". Within a Feature, files named +"feature.xml" may contain a list of the names and version numbers of +the Plug-ins and/or Fragments associated with that Feature.
  • +
  • Features +may also include other Features ("Included Features"). Within a +Feature, files named "feature.xml" may contain a list of the names and +version numbers of Included Features.
  • +
+ +

The terms and conditions governing Plug-ins and Fragments should be +contained in files named "about.html" ("Abouts"). The terms and +conditions governing Features and +Included Features should be contained in files named "license.html" +("Feature Licenses"). Abouts and Feature Licenses may be located in any +directory of a Download or Module +including, but not limited to the following locations:

+ +
    +
  • The top-level (root) directory
  • +
  • Plug-in and Fragment directories
  • +
  • Inside Plug-ins and Fragments packaged as JARs
  • +
  • Sub-directories of the directory named "src" of certain Plug-ins
  • +
  • Feature directories
  • +
+ +

Note: if a Feature made available by the Eclipse Foundation is +installed using the Eclipse Update Manager, you must agree to a license +("Feature Update License") during the +installation process. If the Feature contains Included Features, the +Feature Update License should either provide you with the terms and +conditions governing the Included Features or +inform you where you can locate them. Feature Update Licenses may be +found in the "license" property of files named "feature.properties" +found within a Feature. +Such Abouts, Feature Licenses, and Feature Update Licenses contain the +terms and conditions (or references to such terms and conditions) that +govern your use of the associated Content in +that directory.

+ +

THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER +TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND +CONDITIONS. SOME OF THESE +OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):

+ + + +

IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND +CONDITIONS PRIOR TO USE OF THE CONTENT. If no About, Feature License, +or Feature Update License is provided, please +contact the Eclipse Foundation to determine what terms and conditions +govern that particular Content.

+ +

Cryptography

+ +

Content may contain encryption software. The country in which you +are currently may have restrictions on the import, possession, and use, +and/or re-export to another country, of encryption software. BEFORE +using any encryption software, please check the country's laws, +regulations and policies concerning the import, possession, or use, and +re-export of encryption software, to see if this is permitted.

+ +Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. + \ No newline at end of file diff --git a/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/pom.xml b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/pom.xml new file mode 100644 index 0000000000..3dc1c9d217 --- /dev/null +++ b/jdt-patch/e422/Feature-org.codehaus.groovy.jdt.patch/pom.xml @@ -0,0 +1,13 @@ + + 4.0.0 + + ../../../pom.xml + org.codehaus.groovy.eclipse + org.codehaus.groovy.eclipse.parent + 4.4.0-SNAPSHOT + + org.codehaus.groovy.eclipse + org.codehaus.groovy.jdt.patch + 4.4.0-SNAPSHOT + eclipse-feature + \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.classpath b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.classpath new file mode 100644 index 0000000000..73d6894a61 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.classpath @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.gitignore b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.gitignore new file mode 100644 index 0000000000..934e0e06ff --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.gitignore @@ -0,0 +1,2 @@ +/bin +/target diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.project b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.project new file mode 100644 index 0000000000..06dcf605b1 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.project @@ -0,0 +1,26 @@ + + + org.eclipse.jdt.core.tests.builder + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.core.resources.prefs b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..99f26c0203 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.core.runtime.prefs b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000000..5a0ad22d2a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\n diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.jdt.core.prefs b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..c45edd09f5 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,99 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.builder.cleanOutputFolder=clean +org.eclipse.jdt.core.builder.duplicateResourceTask=warning +org.eclipse.jdt.core.builder.invalidClasspath=abort +org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder=ignore +org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch,.svn/ +org.eclipse.jdt.core.circularClasspath=error +org.eclipse.jdt.core.classpath.exclusionPatterns=enabled +org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.doc.comment.support=enabled +org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore +org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=warning +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private +org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=enabled +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public +org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=enabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=warning +org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedImport=error +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.incompatibleJDKLevel=ignore +org.eclipse.jdt.core.incompleteClasspath=error diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.jdt.ui.prefs b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000000..ab1a682988 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,62 @@ +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_functional_interfaces=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.insert_inferred_type_arguments=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=false +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_redundant_modifiers=false +sp_cleanup.remove_redundant_semicolons=true +sp_cleanup.remove_redundant_type_arguments=true +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=true +sp_cleanup.remove_unused_imports=true +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.update_ibm_copyright_to_current_year=true +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_lambda=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..6b0b55e64b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.jdt.core.tests.builder; singleton:=true +Bundle-Version: 3.11.50.qualifier +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Export-Package: org.eclipse.jdt.core.tests.builder +Require-Bundle: org.junit;bundle-version="3.8.1", + org.eclipse.jdt.core;bundle-version="[3.7.0,4.0.0)", + org.eclipse.jdt.core.tests.compiler;bundle-version="[3.4.0,4.0.0)", + org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)", + org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", + org.eclipse.test.performance;bundle-version="[3.1.0,4.0.0)", + org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0)";resolution:=optional, + org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Eclipse-BundleShape: dir +Automatic-Module-Name: org.eclipse.jdt.core.tests.builder diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/about.html b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/about.html new file mode 100644 index 0000000000..164f781a8f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/about.html @@ -0,0 +1,36 @@ + + + + +About + + +

About This Content

+ +

November 30, 2017

+

License

+ +

+ The Eclipse Foundation makes available all content in this plug-in + ("Content"). Unless otherwise indicated below, the Content + is provided to you under the terms and conditions of the Eclipse + Public License Version 2.0 ("EPL"). A copy of the EPL is + available at http://www.eclipse.org/legal/epl-2.0. + For purposes of the EPL, "Program" will mean the Content. +

+ +

+ If you did not receive this Content directly from the Eclipse + Foundation, the Content is being redistributed by another party + ("Redistributor") and different terms and conditions may + apply to your use of any object code in the Content. Check the + Redistributor's license that was provided with the Content. If no such + license exists, contact the Redistributor. Unless otherwise indicated + below, the terms and conditions of the EPL still apply to any source + code in the Content and such source code may be obtained at http://www.eclipse.org. +

+ + + \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/build.properties b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/build.properties new file mode 100644 index 0000000000..ce74f2ba58 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/build.properties @@ -0,0 +1,24 @@ +############################################################################### +# Copyright (c) 2000, 2013 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +# Red Hat Inc. (mistria) - Avoid nested jars +############################################################################### +bin.includes = plugin.xml,\ + test.xml,\ + about.html,\ + .,\ + META-INF/,\ + plugin.properties,\ + workspace/ +source.. = src/ +output.. = bin/ +src.includes=about.html diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/forceQualifierUpdate.txt b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/forceQualifierUpdate.txt new file mode 100644 index 0000000000..073841225f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/forceQualifierUpdate.txt @@ -0,0 +1,2 @@ +# To force a version qualifier update, add the bug here +Bug 480835 - Failures in build due to changes not being picked up by tests diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/plugin.properties b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/plugin.properties new file mode 100644 index 0000000000..67609b5a82 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/plugin.properties @@ -0,0 +1,15 @@ +############################################################################### +# Copyright (c) 2000, 2006 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +providerName=Eclipse.org +pluginName=Java Builder Tests diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/plugin.xml b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/plugin.xml new file mode 100644 index 0000000000..bf08c103ed --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/plugin.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/pom.xml b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/pom.xml new file mode 100644 index 0000000000..16cd8b13c1 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/pom.xml @@ -0,0 +1,24 @@ + + + + 4.0.0 + + eclipse.jdt.core + tests-pom + 4.22.0-SNAPSHOT + ../tests-pom/ + + org.eclipse.jdt + org.eclipse.jdt.core.tests.builder + 3.11.50-SNAPSHOT + eclipse-plugin + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractLeakTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractLeakTest.java new file mode 100644 index 0000000000..9aa043fd8b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractLeakTest.java @@ -0,0 +1,254 @@ +/******************************************************************************* + * Copyright (c) 2019 Andrey Loskutov and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Andrey Loskutov - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.management.ManagementFactory; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; + +/** + * Base class for testing builder related opened file leak tests, see bug 543506 + */ +public abstract class AbstractLeakTest extends BuilderTests { + + static boolean WINDOWS; + static boolean LINUX; + static boolean MAC; + static boolean lsofCheckDone; + + static { + String os = System.getProperty("os.name").toLowerCase(); + WINDOWS = os.contains("windows"); + LINUX = os.contains("linux"); + MAC = os.contains("mac"); + } + + public AbstractLeakTest(String name) { + super(name); + } + + protected void testLeaksOnIncrementalBuild() throws Exception { + if(MAC) { + return; + } + internalTestUsedLibraryLeaks(IncrementalProjectBuilder.INCREMENTAL_BUILD); + } + + protected void testLeaksOnCleanBuild() throws Exception { + if(MAC) { + return; + } + internalTestUsedLibraryLeaks(IncrementalProjectBuilder.CLEAN_BUILD); + } + + protected void testLeaksOnFullBuild() throws Exception { + if(MAC) { + return; + } + internalTestUsedLibraryLeaks(IncrementalProjectBuilder.FULL_BUILD); + } + + private void internalTestUsedLibraryLeaks(int kind) throws Exception { + if(LINUX && !lsofCheckDone) { + selfTestLsof(); + } + + String projectName = getName(); + IPath projectPath = env.addProject(projectName, getCompatibilityLevel()); + env.setOutputFolder(projectPath, ""); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + IPath internalJar = addInternalJar(projectPath); + + createJavaFile(projectPath); + + switch (kind) { + case IncrementalProjectBuilder.CLEAN_BUILD: + cleanBuild(projectName); + assertNotLeaked(internalJar); + break; + case IncrementalProjectBuilder.FULL_BUILD: + fullBuild(projectPath); + assertNotLeaked(internalJar); + break; + case IncrementalProjectBuilder.INCREMENTAL_BUILD: + incrementalBuild(projectPath); + changeJavaFile(projectPath); + incrementalBuild(projectPath); + assertNotLeaked(internalJar); + break; + default: + fail("Unexpected build kind: " + kind); + } + } + + abstract String getCompatibilityLevel(); + + private IPath addInternalJar(IPath projectPath) throws IOException, JavaModelException { + IPath internalJar = addEmptyInternalJar(projectPath, "test.jar"); + return internalJar; + } + + private void createJavaFile(IPath projectPath) { + IPath path = env.addClass(projectPath, "a", "Other", + "package a;\n" + + "public class Other {\n" + + "}" + ); + IFile file = env.getWorkspace().getRoot().getFile(path); + assertTrue("File should exists: " + path, file.exists()); + } + + private void changeJavaFile(IPath projectPath) throws Exception { + IPath path = env.addClass(projectPath, "a", "Other", + "package a;\n" + + "public class Other {\n" + + " // an extra comment \n" + + "}" + ); + IFile file = env.getWorkspace().getRoot().getFile(path); + assertTrue("FIle should exists: " + path, file.exists()); + } + + private void assertNotLeaked(IPath path) throws Exception { + expectingNoProblems(); + IFile file = env.getWorkspace().getRoot().getFile(path); + assertTrue("FIle should exists: " + path, file.exists()); + if(WINDOWS) { + tryRemoveFile(file); + } else if (LINUX) { + checkOpenDescriptors(file); + } + } + + private void tryRemoveFile(IFile file) { + // Note: this is a lame attempt to check for leaked file descriptor + // This works on Windows only, because windows does not allow to delete + // files opened for reading. + // On Linux we need something like lsof -p | grep file name + try { + file.delete(true, null); + } catch (CoreException e) { + try { + // second attempt to avoid delays on teardown + Files.deleteIfExists(file.getLocation().toFile().toPath()); + } catch (Exception e2) { + file.getLocation().toFile().delete(); + // ignore + } + throw new IllegalStateException("File leaked during build: " + file, e); + } + assertFalse("File should be deleted: " + file, file.exists()); + } + + private void checkOpenDescriptors(IFile file) throws Exception { + runGcAndFInalization(); + List processes = getProcessesOpenedFile(Paths.get(file.getLocation().toOSString())); + if(!processes.isEmpty()) { + runGcAndFInalization(); + Thread.sleep(5000); + processes = getProcessesOpenedFile(Paths.get(file.getLocation().toOSString())); + if(!processes.isEmpty()) { + throw new IllegalStateException("File leaked during build: " + file); + } + } + } + + private void runGcAndFInalization() { + System.gc(); + System.runFinalization(); + System.gc(); + System.runFinalization(); + System.gc(); + System.runFinalization(); + } + + + private void selfTestLsof() throws Exception { + Path tempFile = Files.createTempFile("testLsof", "tmp"); + Files.deleteIfExists(tempFile); + Files.write(tempFile, "Hello\nselfTestLsof".getBytes()); + try(InputStream is = new FileInputStream(tempFile.toFile())){ + is.read(); + List list = getProcessesOpenedFile(tempFile); + assertEquals("lsof doesn't work in this environment!", 1, list.size()); + lsofCheckDone = true; + } + } + + private static List getProcessesOpenedFile(Path path) throws Exception { + int pid = getPid(); + // assertTrue("JVM PID must be > 0 : " + pid, pid > 0); + // -F n : to print only name column (note: all lines start with "n") + // -a : to "and" all following options + // -b :to avoid blocking calls + // -p : to select process with opened files + // List lines = readLsofLines("lsof -F n -a -p " + pid + " -b", true); + + // Code above seem to hang... + List lines = readLsofLines("lsof " + path, true); + for (String line : lines) { + if(line.contains("" + pid)) { + return lines; + } + } + return Collections.emptyList(); + } + + private static int getPid() throws Exception { + String jvmName = ManagementFactory.getRuntimeMXBean().getName(); + int indexOfAt = jvmName.indexOf('@'); + String pidSubstring = jvmName.substring(0, indexOfAt); + int pid = Integer.parseInt(pidSubstring); + return pid; + } + + private static List readLsofLines(String cmd, boolean skipFirst) throws Exception { + List lines = new ArrayList<>(); + Process process = Runtime.getRuntime().exec(cmd); + try (BufferedReader rdr = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + if (skipFirst) { + rdr.readLine(); + } + String line; + while((line = rdr.readLine())!= null) { + // remove "n" prefix from lsof output + if(line.startsWith("n")) { + line = line.substring(1); + } + if(line.trim().length() > 1) { + lines.add(line); + } + } + } + lines.sort(null); + return lines; + } + +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractMethodTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractMethodTests.java new file mode 100644 index 0000000000..2610aa75d8 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AbstractMethodTests.java @@ -0,0 +1,330 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.Comparator; + +import junit.framework.*; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IRegion; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.IMethodInfo; + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class AbstractMethodTests extends BuilderTests { + private static final Comparator COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + IResource resource1 = (IResource) o1; + IResource resource2 = (IResource) o2; + String path1 = resource1.getFullPath().toString(); + String path2 = resource2.getFullPath().toString(); + int length1 = path1.length(); + int length2 = path2.length(); + + if (length1 != length2) { + return length1 - length2; + } + return path1.toString().compareTo(path2.toString()); + } + }; + + public AbstractMethodTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(AbstractMethodTests.class); + } + + /** + * Check behavior in 1.2 target mode (NO generated default abstract method) + */ + public void test001() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(project1Path, ""); //$NON-NLS-1$ + + env.setOutputFolder(project1Path, "bin"); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(project1Path, "src"); //$NON-NLS-1$ + + env.addClass(root1, "p1", "IX", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public interface IX {\n" + //$NON-NLS-1$ + " public abstract void foo(IX x);\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath classX = env.addClass(root1, "p2", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n" + //$NON-NLS-1$ + "import p1.*;\n" + //$NON-NLS-1$ + "public abstract class X implements IX {\n" + //$NON-NLS-1$ + " public void foo(IX x){}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(project2Path, ""); //$NON-NLS-1$ + + IPath root2 = env.addPackageFragmentRoot(project2Path, "src"); //$NON-NLS-1$ + env.setOutputFolder(project2Path, "bin"); //$NON-NLS-1$ + + IPath classY =env.addClass(root2, "p3", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n" + //$NON-NLS-1$ + "import p2.*;\n" + //$NON-NLS-1$ + "public class Y extends X{\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + env.addClass(root1, "p2", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n" + //$NON-NLS-1$ + "import p1.*;\n" + //$NON-NLS-1$ + "public abstract class X implements IX {\n" + //$NON-NLS-1$ + " public void foo(I__X x){}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingOnlySpecificProblemFor(classX, new Problem("X.foo(I__X)", "I__X cannot be resolved to a type", classX, 84, 88, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingOnlySpecificProblemFor(classY, new Problem("Y", "The type Y must implement the inherited abstract method IX.foo(IX)", classY, 38, 39, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + //---------------------------- + // Step 3 + //---------------------------- + env.addClass(root1, "p2", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n" + //$NON-NLS-1$ + "import p1.*;\n" + //$NON-NLS-1$ + "public abstract class X implements IX {\n" + //$NON-NLS-1$ + " public void foo(IX x){}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + } + + /** + * Check behavior in 1.1 target mode (generated default abstract method) + */ + public void test002() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + env.getJavaProject(project1Path).setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_1); // need default abstract method + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(project1Path, ""); //$NON-NLS-1$ + + env.setOutputFolder(project1Path, "bin"); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(project1Path, "src"); //$NON-NLS-1$ + + env.addClass(root1, "p1", "IX", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public interface IX {\n" + //$NON-NLS-1$ + " public abstract void foo(IX x);\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath classX = env.addClass(root1, "p2", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n" + //$NON-NLS-1$ + "import p1.*;\n" + //$NON-NLS-1$ + "public abstract class X implements IX {\n" + //$NON-NLS-1$ + " public void foo(IX x){}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(project2Path, ""); //$NON-NLS-1$ + + IPath root2 = env.addPackageFragmentRoot(project2Path, "src"); //$NON-NLS-1$ + env.setOutputFolder(project2Path, "bin"); //$NON-NLS-1$ + + IPath classY =env.addClass(root2, "p3", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n" + //$NON-NLS-1$ + "import p2.*;\n" + //$NON-NLS-1$ + "public class Y extends X{\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + env.addClass(root1, "p2", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n" + //$NON-NLS-1$ + "import p1.*;\n" + //$NON-NLS-1$ + "public abstract class X implements IX {\n" + //$NON-NLS-1$ + " public void foo(I__X x){}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingOnlySpecificProblemFor(classX, new Problem("X.foo(I__X)", "I__X cannot be resolved to a type", classX, 84, 88, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingOnlySpecificProblemFor(classY, new Problem("Y", "The type Y must implement the inherited abstract method IX.foo(IX)", classY, 38, 39, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + //---------------------------- + // Step 3 + //---------------------------- + env.addClass(root1, "p2", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n" + //$NON-NLS-1$ + "import p1.*;\n" + //$NON-NLS-1$ + "public abstract class X implements IX {\n" + //$NON-NLS-1$ + " public void foo(IX x){}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + } + + /** + * Check behavior in 1.1 target mode (generated default abstract method) + */ + public void test003() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + env.getJavaProject(project1Path).setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_1); // need default abstract method + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(project1Path, ""); //$NON-NLS-1$ + + env.setOutputFolder(project1Path, "bin"); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(project1Path, "src"); //$NON-NLS-1$ + + env.addClass(root1, "p1", "IX", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public interface IX {\n" + //$NON-NLS-1$ + " public abstract void foo(IX x);\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root1, "p2", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n" + //$NON-NLS-1$ + "import p1.*;\n" + //$NON-NLS-1$ + "public abstract class X implements IX {\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + + IJavaProject project = env.getJavaProject(project1Path); + IRegion region = JavaCore.newRegion(); + region.add(project); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = "/Project1/bin/p2/X.class\n" + + "/Project1/bin/p1/IX.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + assertEquals("Wrong type", IResource.FILE, resources[0].getType()); + IFile classFile = (IFile) resources[0]; + IClassFileReader classFileReader = null; + InputStream stream = null; + try { + stream = classFile.getContents(); + classFileReader = ToolFactory.createDefaultClassFileReader(stream, IClassFileReader.ALL); + } catch (CoreException e) { + e.printStackTrace(); + } finally { + if (stream != null) { + try { + stream.close(); + } catch(IOException e) { + // ignore + } + } + } + assertNotNull("No class file reader", classFileReader); + IMethodInfo[] methodInfos = classFileReader.getMethodInfos(); + IMethodInfo found = null; + loop: for (int i = 0, max = methodInfos.length; i < max; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if (CharOperation.equals(methodInfo.getName(), "foo".toCharArray())) { + found = methodInfo; + break loop; + } + } + assertNotNull("No method found", found); + assertTrue("Not a synthetic method", found.isSynthetic()); + } + + private String getResourceOuput(IResource[] resources) { + StringWriter stringWriter = new StringWriter(); + PrintWriter writer = new PrintWriter(stringWriter); + for (int i = 0, max = resources.length; i < max; i++) { + writer.println(resources[i].getFullPath().toString()); + } + writer.flush(); + writer.close(); + return Util.convertToIndependantLineDelimiter(String.valueOf(stringWriter)); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AnnotationDependencyTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AnnotationDependencyTests.java new file mode 100644 index 0000000000..6455f2531f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/AnnotationDependencyTests.java @@ -0,0 +1,1672 @@ +/******************************************************************************* + * Copyright (c) 2009, 2014 Walter Harley and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Walter Harley (eclipse@cafewalter.com) - initial implementation + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 365992 - [builder] [null] Change of nullness for a parameter doesn't trigger a build for the files that call the method + * Bug 392099 - [1.8][compiler][null] Apply null annotation on types for null analysis + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.File; +import java.io.IOException; + +import junit.framework.Test; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.Util; +import org.osgi.framework.Bundle; + +/** + * Tests to verify that annotation changes cause recompilation of dependent types. + * See http://bugs.eclipse.org/149768 + */ +public class AnnotationDependencyTests extends BuilderTests { + private IPath srcRoot = null; + private IPath projectPath = null; + + public AnnotationDependencyTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(AnnotationDependencyTests.class); + } + + public void setUp() throws Exception { + super.setUp(); + + this.projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ + env.addExternalJars(this.projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(this.projectPath,""); //$NON-NLS-1$ + + this.srcRoot = env.addPackageFragmentRoot(this.projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(this.projectPath, "bin"); //$NON-NLS-1$ + } + + protected void tearDown() throws Exception { + this.projectPath = null; + this.srcRoot = null; + + super.tearDown(); + } + + private void addAnnotationType() { + String annoCode = "package p1;\n" + + "@interface Anno {\n" + + "String value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "Anno", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoInt {\n" + + "int value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoInt", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoBoolean {\n" + + "boolean value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoBoolean", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoByte {\n" + + "byte value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoByte", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoChar {\n" + + "char value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoChar", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoShort {\n" + + "short value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoShort", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoDouble {\n" + + "double value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoDouble", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoFloat {\n" + + "float value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoFloat", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoLong {\n" + + "long value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoLong", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoStringArray {\n" + + "String[] value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoStringArray", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoAnnotation {\n" + + "AnnoLong value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoAnnotation", annoCode); + annoCode = "package p1;\n" + + "enum E {\n" + + "A, B, C\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "E", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoEnum {\n" + + "E value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoEnum", annoCode); + annoCode = "package p1;\n" + + "@interface AnnoClass {\n" + + "Class value();\n" + + "}\n"; + env.addClass(this.srcRoot, "p1", "AnnoClass", annoCode); + } + + void setupProjectForNullAnnotations() throws IOException, JavaModelException { + // add the org.eclipse.jdt.annotation library (bin/ folder or jar) to the project: + Bundle[] bundles = Platform.getBundles("org.eclipse.jdt.annotation","[1.1.0,2.0.0)"); + File bundleFile = FileLocator.getBundleFile(bundles[0]); + String annotationsLib = bundleFile.isDirectory() ? bundleFile.getPath()+"/bin" : bundleFile.getPath(); + IJavaProject javaProject = env.getJavaProject(this.projectPath); + IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); + int len = rawClasspath.length; + System.arraycopy(rawClasspath, 0, rawClasspath = new IClasspathEntry[len+1], 0, len); + rawClasspath[len] = JavaCore.newLibraryEntry(new Path(annotationsLib), null, null); + javaProject.setRawClasspath(rawClasspath, null); + + javaProject.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + } + + /** + * This test makes sure that changing an annotation on type A causes type B + * to be recompiled, if B references A. See http://bugs.eclipse.org/149768 + */ + public void testTypeAnnotationDependency() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@Anno(\"A1\")" + "\n" + + "public class A {}"; + String a2Code = "package p1; " + "\n" + + "@Anno(\"A2\")" + "\n" + + "public class A {}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + + /** + * This test makes sure that changing an annotation on a field within type A + * causes type B to be recompiled, if B references A. + * See http://bugs.eclipse.org/149768 + */ + public void testFieldAnnotationDependency() throws Exception + { + String a1Code = "package p1; " + "\n" + + "public class A {" + "\n" + + " @Anno(\"A1\")" + "\n" + + " protected int f;" + "\n" + + "}"; + String a2Code = "package p1; " + "\n" + + "public class A {" + "\n" + + " @Anno(\"A2\")" + "\n" + + " protected int f;" + "\n" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + + /** + * This test makes sure that changing an annotation on a method within type A + * causes type B to be recompiled, if B references A. + * See http://bugs.eclipse.org/149768 + */ + public void testMethodAnnotationDependency() throws Exception + { + String a1Code = "package p1; " + "\n" + + "public class A {" + "\n" + + " @Anno(\"A1\")" + "\n" + + " protected int f() { return 0; }" + "\n" + + "}"; + String a2Code = "package p1; " + "\n" + + "public class A {" + "\n" + + " @Anno(\"A2\")" + "\n" + + " protected int f() { return 0; }" + "\n" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + + /** + * This test makes sure that changing an annotation on an inner type X within type A + * causes type B to be recompiled, if B references A. + * Note that B does not directly reference A.X, only A. + * See http://bugs.eclipse.org/149768 + */ + public void testInnerTypeAnnotationDependency() throws Exception + { + String a1Code = "package p1; " + "\n" + + "public class A {" + "\n" + + " @Anno(\"A1\")" + "\n" + + " public class X { }" + "\n" + + "}"; + String a2Code = "package p1; " + "\n" + + "public class A {" + "\n" + + " @Anno(\"A2\")" + "\n" + + " public class X { }" + "\n" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.A$X", "p1.B" }); + } + + /** + * This test makes sure that changing an annotation on a type A + * does not cause type B to be recompiled, if B does not reference A. + * See http://bugs.eclipse.org/149768 + */ + public void testUnrelatedTypeAnnotationDependency() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@Anno(\"A1\")" + "\n" + + "public class A {}"; + String a2Code = "package p1; " + "\n" + + "@Anno(\"A2\")" + "\n" + + "public class A {}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was not recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=214948 + public void testPackageInfoDependency() throws Exception { + String notypes = "@question.SimpleAnnotation(\"foo\") package notypes;"; + String question = "package question;"; + String deprecatedQuestion = "@Deprecated package question;"; + String SimpleAnnotation = "package question; " + "\n" + + "public @interface SimpleAnnotation { String value(); }"; + + IPath notypesPath = env.addClass( this.srcRoot, "notypes", "package-info", notypes ); + env.addClass( this.srcRoot, "question", "package-info", question ); + env.addClass( this.srcRoot, "question", "SimpleAnnotation", SimpleAnnotation ); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + env.addClass( this.srcRoot, "question", "package-info", deprecatedQuestion ); + incrementalBuild( this.projectPath ); + expectingOnlySpecificProblemFor(notypesPath, new Problem("", "The type SimpleAnnotation is deprecated", notypesPath, 10, 26, CategorizedProblem.CAT_DEPRECATION, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ + + env.addClass( this.srcRoot, "question", "package-info", question ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency2() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@Anno(\"A1\")" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@Anno(\"A1\")" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency3() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoInt(24)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoInt(24)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency4() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoByte(3)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoByte(3)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency5() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoBoolean(true)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoBoolean(true)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency6() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoChar('c')" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoChar('c')" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency7() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoDouble(1.0)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoDouble(1.0)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency8() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoFloat(1.0f)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoFloat(1.0f)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency9() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoLong(1L)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoLong(1L)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency10() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoShort(3)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoShort(3)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency11() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoStringArray({\"A1\",\"A2\"})" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoStringArray({\"A1\",\"A2\"})" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency12() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoAnnotation(@AnnoLong(3))" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoAnnotation(@AnnoLong(3))" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency13() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoEnum(E.A)\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoEnum(E.A)\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency14() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoClass(Object.class)\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoClass(Object.class)\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was NOT recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency15() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@Anno(\"A1\")" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@Anno(\"A2\")" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency16() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoInt(3)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoInt(4)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency17() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoByte(3)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoByte(4)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B"}); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency18() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoBoolean(true)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoBoolean(false)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency19() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoChar('c')" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoChar('d')" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency20() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoDouble(1.0)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoDouble(2.0)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency21() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoFloat(1.0f)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoFloat(2.0f)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency22() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoLong(1L)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoLong(2L)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency23() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoShort(3)" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoShort(5)" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency24() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoStringArray({\"A1\",\"A2\"})" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoStringArray({\"A2\",\"A1\"})" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency25() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoAnnotation(@AnnoLong(3))" + "\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoAnnotation(@AnnoLong(4))" + "\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency26() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoEnum(E.A)\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoEnum(E.C)\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=317841 + */ + public void testTypeAnnotationDependency27() throws Exception + { + String a1Code = "package p1; " + "\n" + + "@AnnoClass(Object.class)\n" + + "public class A {\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String a2Code = "package p1; " + "\n" + + "@AnnoClass(String.class)\n" + + "public class A {\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(\"test\");" + + " }" + + "}"; + String bCode = "package p1; " + "\n" + + "public class B {" + "\n" + + " public A a;" + "\n" + + "}"; + + env.addClass( this.srcRoot, "p1", "A", a1Code ); + env.addClass( this.srcRoot, "p1", "B", bCode ); + addAnnotationType(); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit annotation in A + env.addClass( this.srcRoot, "p1", "A", a2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that B was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.A", "p1.B" }); + } + + // Bug 365992 - [builder] [null] Change of nullness for a parameter doesn't trigger a build for the files that call the method + public void testParameterAnnotationDependency01() throws JavaModelException, IOException { + // prepare the project: + setupProjectForNullAnnotations(); + + String test1Code = "package p1;\n" + + "public class Test1 {\n" + + " public void foo() {\n" + + " new Test2().bar(null);\n" + + " }\n" + + "}"; + String test2Code = "package p1;\n" + + "public class Test2 {\n" + + " public void bar(String str) {}\n" + + "}"; + + IPath test1Path = env.addClass( this.srcRoot, "p1", "Test1", test1Code ); + env.addClass( this.srcRoot, "p1", "Test2", test2Code ); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit Test2 to add @NonNull annotation (changes number of annotations) + String test2CodeB = "package p1;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class Test2 {\n" + + " public void bar(@NonNull String str) {}\n" + + "}"; + env.addClass( this.srcRoot, "p1", "Test2", test2CodeB ); + incrementalBuild( this.projectPath ); + expectingProblemsFor(test1Path, + "Problem : Null type mismatch: required \'@NonNull String\' but the provided value is null [ resource :
range : <81,85> category : <90> severity : <2>]"); + + // verify that Test1 was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.Test2" }); + + // fix error by changing to @Nullable (change is only in an annotation name) + String test2CodeC = "package p1;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public class Test2 {\n" + + " public void bar(@Nullable String str) {}\n" + + "}"; + env.addClass( this.srcRoot, "p1", "Test2", test2CodeC ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that Test1 was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.Test2" }); + } + + // Bug 365992 - [builder] [null] Change of nullness for a parameter doesn't trigger a build for the files that call the method + // Bug 366341 - Incremental compiler fails to detect right scope for annotation related code changes + public void testReturnAnnotationDependency01() throws JavaModelException, IOException { + // prepare the project: + setupProjectForNullAnnotations(); + + String test1Code = "package p1;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class Test1 {\n" + + " public @NonNull Object foo() {\n" + + " return new Test2().bar();\n" + + " }\n" + + "}"; + String test2Code = "package p1;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class Test2 {\n" + + " public @NonNull Object bar() { return this; }\n" + + "}"; + + IPath test1Path = env.addClass( this.srcRoot, "p1", "Test1", test1Code ); + env.addClass( this.srcRoot, "p1", "Test2", test2Code ); + + fullBuild( this.projectPath ); + expectingNoProblems(); + + // edit Test2 to replace annotation + String test2CodeB = "package p1;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public class Test2 {\n" + + " public @Nullable Object bar() { return null; }\n" + + "}"; + env.addClass( this.srcRoot, "p1", "Test2", test2CodeB ); + incrementalBuild( this.projectPath ); + expectingProblemsFor(test1Path, + "Problem : Null type mismatch: required \'@NonNull Object\' but the provided value is specified as @Nullable [ resource : range : <126,143> category : <90> severity : <2>]"); + + // verify that Test1 was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.Test2" }); + + // remove annotation, error changes from can be null to unknown nullness + String test2CodeC = "package p1;\n" + + "public class Test2 {\n" + + " public Object bar() { return null; }\n" + + "}"; + env.addClass( this.srcRoot, "p1", "Test2", test2CodeC ); + incrementalBuild( this.projectPath ); + expectingProblemsFor(test1Path, + "Problem : Null type safety: The expression of type 'Object' needs unchecked conversion to conform to \'@NonNull Object\' [ resource : range : <126,143> category : <90> severity : <1>]"); + + // verify that Test1 was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.Test2" }); + + // back to initial OK version (re-add @NonNull annotation) + env.addClass( this.srcRoot, "p1", "Test2", test2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that Test1 was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.Test2" }); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=373571 + // incremental build that uses binary type for Test1 should not report spurious null errors. + public void testReturnAnnotationDependency02() throws JavaModelException, IOException { + // prepare the project: + setupProjectForNullAnnotations(); + + String test1Code = "package p1;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "public class Test1 {\n" + + " public void doStuff(int i) {\n" + + " }\n" + + "}"; + env.addClass( this.srcRoot, "p1", "Test1", test1Code ); + fullBuild( this.projectPath ); + expectingNoProblems(); + + // add Test2 + String test2Code = "package p1;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "public class Test2 extends Test1{\n" + + " @Override\n" + + " public void doStuff(int i) {\n" + + " super.doStuff(i);\n" + + " }\n" + + "}"; + env.addClass( this.srcRoot, "p1", "Test2", test2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that Test2 only was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test2" }); + + // edit Test2 to delete annotation + test2Code = "package p1;\n" + + "public class Test2 extends Test1{\n" + + " @Override\n" + + " public void doStuff(int i) {\n" + + " super.doStuff(i);\n" + + " }\n" + + "}"; + env.addClass( this.srcRoot, "p1", "Test2", test2Code ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + // verify that Test2 only was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test2" }); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=411771 + //[compiler][null] Enum constants not recognized as being NonNull. + //This test case exposes the bug mentioned in the defect. The enum + //definition comes from a file different from where it is accessed. + public void test411771a() throws IOException, JavaModelException { + setupProjectForNullAnnotations(); + String testEnumCode = "package p1;\n" + + "enum TestEnum {FOO };\n"; + env.addClass( this.srcRoot, "p1", "TestEnum", testEnumCode ); + fullBuild( this.projectPath ); + expectingNoProblems(); + + String nullTestCode = "package p1;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class NullTest {\n" + + " public static TestEnum bla() {\n" + + " @NonNull final TestEnum t = TestEnum.FOO;\n" + + " return t;\n" + + " }\n" + + "}"; + env.addClass( this.srcRoot, "p1", "NullTest", nullTestCode ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + expectingUniqueCompiledClasses(new String[] { "p1.NullTest" }); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=411771 + //[compiler][null] Enum constants not recognized as being NonNull. + //Distinguish between enum constant and enum type. The enum type should not + //be marked as NonNull. + public void test411771b() throws IOException, JavaModelException { + setupProjectForNullAnnotations(); + String testEnumCode = "package p1;\n" + + "enum TestEnum { FOO };\n"; + env.addClass( this.srcRoot, "p1", "TestEnum", testEnumCode ); + fullBuild( this.projectPath ); + expectingNoProblems(); + + String testClass = "package p1;\n" + + "public class X { TestEnum f; };\n"; + env.addClass( this.srcRoot, "p1", "X", testClass ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + String nullTestCode = "package p1;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class NullTest {\n" + + " public static TestEnum bla(X x) {\n" + + " @NonNull final TestEnum t = x.f;\n" + + " return t;\n" + + " }\n" + + "}\n"; + IPath test1Path = env.addClass( this.srcRoot, "p1", "NullTest", nullTestCode ); + incrementalBuild( this.projectPath ); + + expectingProblemsFor(test1Path, + "Problem : Null type safety: The expression of type 'TestEnum' needs unchecked conversion to conform to " + + "'@NonNull TestEnum' [ resource : range : <144,147> category : <90> severity : <1>]"); + + expectingUniqueCompiledClasses(new String[] { "p1.NullTest" }); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=411771 + //[compiler][null] Enum constants not recognized as being NonNull. + //A enum may contain fields other than predefined constants. We + //should not tag them as NonNull. + public void test411771c() throws IOException, JavaModelException { + setupProjectForNullAnnotations(); + String testClass = "package p1;\n" + + "public class A {}"; + env.addClass( this.srcRoot, "p1", "A", testClass ); + fullBuild( this.projectPath ); + expectingNoProblems(); + + String testEnumCode = "package p1;\n" + + "enum TestEnum {\n" + + " FOO;\n" + + " public static A a;" + + "};\n"; + env.addClass( this.srcRoot, "p1", "TestEnum", testEnumCode ); + incrementalBuild( this.projectPath ); + expectingNoProblems(); + + String nullTestCode = "package p1;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class NullTest {\n" + + " public static TestEnum bla() {\n" + + " @NonNull final TestEnum t = TestEnum.FOO;\n" + + " return t;\n" + + " }\n" + + " public A testint() {\n" + + " @NonNull A a = TestEnum.a;\n" + + " return a;\n" + + " }\n" + + "}"; + IPath test1Path = env.addClass( this.srcRoot, "p1", "NullTest", nullTestCode ); + incrementalBuild( this.projectPath ); + expectingProblemsFor(test1Path, + "Problem : Null type safety: The expression of type 'A' needs unchecked conversion to conform to " + + "'@NonNull A' [ resource : range : <208,218> category : <90> severity : <1>]"); + + expectingUniqueCompiledClasses(new String[] { "p1.NullTest" }); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BasicBuildTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BasicBuildTests.java new file mode 100644 index 0000000000..6c170df892 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BasicBuildTests.java @@ -0,0 +1,690 @@ +/******************************************************************************* + * Copyright (c) 2000, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 392727 - Cannot compile project when a java file contains $ in its file name + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.util.Hashtable; + +import junit.framework.*; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.core.JavaModelManager; + +/** + * Basic tests of the image builder. + */ +@SuppressWarnings({"rawtypes", "unchecked"}) +public class BasicBuildTests extends BuilderTests { + public BasicBuildTests(String name) { + super(name); + } + static { +// TESTS_NAMES = new String[] { "testBug392727" }; + } + { + System.setProperty(JavaModelManager.MAX_COMPILED_UNITS_AT_ONCE, "0"); + } + public static Test suite() { + return buildTestSuite(BasicBuildTests.class); + } + + public void testBuild() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + } + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23894 + */ + public void testToDoMarker() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_TASK_TAGS, "todo"); //$NON-NLS-1$ + newOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL"); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath pathToA = env.addClass(root, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "//todo nothing\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingOnlySpecificProblemFor(pathToA, new Problem("A", "todo nothing", pathToA, 14, 26, -1, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + JavaCore.setOptions(options); + } + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=91426 + */ + public void testToDoMarker2() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO,FIXME,XXX"); //$NON-NLS-1$ + newOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,HIGH,LOW"); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath pathToA = env.addClass(root, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "//TODO normal\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public void foo() {\n"+ //$NON-NLS-1$ + " //FIXME high\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + " public void foo2() {\n"+ //$NON-NLS-1$ + " //XXX low\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + fullBuild(projectPath); + IMarker[] markers = env.getTaskMarkersFor(pathToA); + assertEquals("Wrong size", 3, markers.length); + try { + IMarker marker = markers[0]; + Object priority = marker.getAttribute(IMarker.PRIORITY); + String message = (String) marker.getAttribute(IMarker.MESSAGE); + assertTrue("Wrong message", message.startsWith("TODO ")); + assertNotNull("No task priority", priority); + assertEquals("Wrong priority", Integer.valueOf(IMarker.PRIORITY_NORMAL), priority); + + marker = markers[1]; + priority = marker.getAttribute(IMarker.PRIORITY); + message = (String) marker.getAttribute(IMarker.MESSAGE); + assertTrue("Wrong message", message.startsWith("FIXME ")); + assertNotNull("No task priority", priority); + assertEquals("Wrong priority", Integer.valueOf(IMarker.PRIORITY_HIGH), priority); + + marker = markers[2]; + priority = marker.getAttribute(IMarker.PRIORITY); + message = (String) marker.getAttribute(IMarker.MESSAGE); + assertTrue("Wrong message", message.startsWith("XXX ")); + assertNotNull("No task priority", priority); + assertEquals("Wrong priority", Integer.valueOf(IMarker.PRIORITY_LOW), priority); + } catch (CoreException e) { + assertTrue(false); + } + JavaCore.setOptions(options); + } + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=110797 + */ + public void testTags() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO,FIXME,XXX"); //$NON-NLS-1$ + newOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,HIGH,LOW"); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath pathToA = env.addClass(root, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "// TODO FIXME need to review the loop TODO should be done\n" + //$NON-NLS-1$ + "public class A {\n" + //$NON-NLS-1$ + "}"); + + fullBuild(projectPath); + IMarker[] markers = env.getTaskMarkersFor(pathToA); + assertEquals("Wrong size", 3, markers.length); + try { + IMarker marker = markers[2]; + Object priority = marker.getAttribute(IMarker.PRIORITY); + String message = (String) marker.getAttribute(IMarker.MESSAGE); + assertEquals("Wrong message", "TODO should be done", message); + assertNotNull("No task priority", priority); + assertEquals("Wrong priority", Integer.valueOf(IMarker.PRIORITY_NORMAL), priority); + + marker = markers[1]; + priority = marker.getAttribute(IMarker.PRIORITY); + message = (String) marker.getAttribute(IMarker.MESSAGE); + assertEquals("Wrong message", "FIXME need to review the loop", message); + assertNotNull("No task priority", priority); + assertEquals("Wrong priority", Integer.valueOf(IMarker.PRIORITY_HIGH), priority); + + marker = markers[0]; + priority = marker.getAttribute(IMarker.PRIORITY); + message = (String) marker.getAttribute(IMarker.MESSAGE); + assertEquals("Wrong message", "TODO need to review the loop", message); + assertNotNull("No task priority", priority); + assertEquals("Wrong priority", Integer.valueOf(IMarker.PRIORITY_NORMAL), priority); + } catch (CoreException e) { + assertTrue(false); + } + JavaCore.setOptions(options); + } + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=110797 + */ + public void testTags2() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO,FIXME,XXX"); //$NON-NLS-1$ + newOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,HIGH,LOW"); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath pathToA = env.addClass(root, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "// TODO TODO need to review the loop\n" + //$NON-NLS-1$ + "public class A {\n" + //$NON-NLS-1$ + "}"); + + fullBuild(projectPath); + IMarker[] markers = env.getTaskMarkersFor(pathToA); + assertEquals("Wrong size", 2, markers.length); + try { + IMarker marker = markers[1]; + Object priority = marker.getAttribute(IMarker.PRIORITY); + String message = (String) marker.getAttribute(IMarker.MESSAGE); + assertEquals("Wrong message", "TODO need to review the loop", message); + assertNotNull("No task priority", priority); + assertEquals("Wrong priority", Integer.valueOf(IMarker.PRIORITY_NORMAL), priority); + + marker = markers[0]; + priority = marker.getAttribute(IMarker.PRIORITY); + message = (String) marker.getAttribute(IMarker.MESSAGE); + assertEquals("Wrong message", "TODO need to review the loop", message); + assertNotNull("No task priority", priority); + assertEquals("Wrong priority", Integer.valueOf(IMarker.PRIORITY_NORMAL), priority); + } catch (CoreException e) { + assertTrue(false); + } + JavaCore.setOptions(options); + } + + /* + * Ensures that a task tag is not user editable + * (regression test for bug 123721 two types of 'remove' for TODO task tags) + */ + public void testTags3() throws CoreException { + Hashtable options = JavaCore.getOptions(); + + try { + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO,FIXME,XXX"); //$NON-NLS-1$ + newOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,HIGH,LOW"); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath pathToA = env.addClass(root, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "// TODO need to review\n" + //$NON-NLS-1$ + "public class A {\n" + //$NON-NLS-1$ + "}"); + + fullBuild(projectPath); + IMarker[] markers = env.getTaskMarkersFor(pathToA); + assertEquals("Marker should not be editable", Boolean.FALSE, markers[0].getAttribute(IMarker.USER_EDITABLE)); + } finally { + JavaCore.setOptions(options); + } + } + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=92821 + */ + public void testUnusedImport() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_IMPORT, JavaCore.WARNING); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "util", "MyException", //$NON-NLS-1$ //$NON-NLS-2$ + "package util;\n" + + "public class MyException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + ); + + env.addClass(root, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + + "import util.MyException;\n" + + "public class Test {\n" + + " /**\n" + + " * @throws MyException\n" + + " */\n" + + " public void bar() {\n" + + " }\n" + + "}" + ); + + fullBuild(projectPath); + expectingNoProblems(); + + JavaCore.setOptions(options); + } + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=98667 + */ + public void test98667() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Aaa$Bbb$Ccc", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "\n" + //$NON-NLS-1$ + "public class Aaa$Bbb$Ccc {\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + } + + /** + * @bug 164707: ArrayIndexOutOfBoundsException in JavaModelManager if source level == 6.0 + * @test Ensure that AIIOB does not longer happen with invalid source level string + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=164707" + */ + public void testBug164707() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + IJavaProject javaProject = env.getJavaProject(projectPath); + javaProject.setOption(JavaCore.COMPILER_SOURCE, "invalid"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + expectingNoProblems(); + } + + /** + * @bug 75471: [prefs] no re-compile when loading settings + * @test Ensure that changing project preferences is well taking into account while rebuilding project + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=75471" + */ + public void _testUpdateProjectPreferences() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "util", "MyException", //$NON-NLS-1$ //$NON-NLS-2$ + "package util;\n" + + "public class MyException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + ); + + IPath cuPath = env.addClass(root, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + + "import util.MyException;\n" + + "public class Test {\n" + + "}" + ); + + fullBuild(projectPath); + expectingSpecificProblemFor( + projectPath, + new Problem("", "The import util.MyException is never used", cuPath, 18, 34, CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$ + + IJavaProject project = env.getJavaProject(projectPath); + project.setOption(JavaCore.COMPILER_PB_UNUSED_IMPORT, JavaCore.IGNORE); + incrementalBuild(projectPath); + expectingNoProblems(); + } + public void _testUpdateWkspPreferences() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "util", "MyException", //$NON-NLS-1$ //$NON-NLS-2$ + "package util;\n" + + "public class MyException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + ); + + IPath cuPath = env.addClass(root, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + + "import util.MyException;\n" + + "public class Test {\n" + + "}" + ); + + fullBuild(); + expectingSpecificProblemFor( + projectPath, + new Problem("", "The import util.MyException is never used", cuPath, 18, 34, CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$ + + // Save preference + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + IEclipsePreferences preferences = manager.getInstancePreferences(); + String unusedImport = preferences.get(JavaCore.COMPILER_PB_UNUSED_IMPORT, null); + try { + // Modify preference + preferences.put(JavaCore.COMPILER_PB_UNUSED_IMPORT, JavaCore.IGNORE); + incrementalBuild(); + expectingNoProblems(); + } + finally { + if (unusedImport == null) { + preferences.remove(JavaCore.COMPILER_PB_UNUSED_IMPORT); + } else { + preferences.put(JavaCore.COMPILER_PB_UNUSED_IMPORT, unusedImport); + } + } + } + + public void testTags4() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO!,TODO,TODO?"); //$NON-NLS-1$ + newOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "HIGH,NORMAL,LOW"); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath pathToA = env.addClass(root, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "// TODO! TODO? need to review the loop\n" + //$NON-NLS-1$ + "public class A {\n" + //$NON-NLS-1$ + "}"); + + fullBuild(projectPath); + IMarker[] markers = env.getTaskMarkersFor(pathToA); + assertEquals("Wrong size", 2, markers.length); + + try { + IMarker marker = markers[1]; + Object priority = marker.getAttribute(IMarker.PRIORITY); + String message = (String) marker.getAttribute(IMarker.MESSAGE); + assertEquals("Wrong message", "TODO? need to review the loop", message); + assertNotNull("No task priority", priority); + assertEquals("Wrong priority", Integer.valueOf(IMarker.PRIORITY_LOW), priority); + + marker = markers[0]; + priority = marker.getAttribute(IMarker.PRIORITY); + message = (String) marker.getAttribute(IMarker.MESSAGE); + assertEquals("Wrong message", "TODO! need to review the loop", message); + assertNotNull("No task priority", priority); + assertEquals("Wrong priority", Integer.valueOf(IMarker.PRIORITY_HIGH), priority); + } catch (CoreException e) { + assertTrue(false); + } + JavaCore.setOptions(options); + } + + // Bug 392727 - Cannot compile project when a java file contains $ in its file name + public void testBug392727() throws JavaModelException { + int save = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + try { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + // this class is the primary unit during build (see comment below) + env.addClass(root, "pack", + "Zork", + "package pack;\npublic class Zork { Main main; }\n" // pull in Main first + ); + + env.addClass(root, "pack", "Main", + "package pack;\n" + + "public class Main {\n" + + " Main$Sub sub;\n" + // indirectly pull in Main$Sub + "}\n" + ); + + env.addClass(root, "pack", "Main$Sub", + "package pack;\n" + + "public class Main$Sub { }\n" + ); + + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 1; + + // Assumption regarding the order of compilation units: + // - org.eclipse.core.internal.dtree.AbstractDataTreeNode.assembleWith(AbstractDataTreeNode[], AbstractDataTreeNode[], boolean) + // assembles children array in lexical order, so "Zork.java" is last + // - org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(DataTreeNode, IElementContentVisitor) + // iterates children last-to-first so "Zork.java" becomes first in sourceFiles of + // org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.addAllSourceFiles(ArrayList) + // - org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(SourceFile[]) + // puts only "Zork.java" into 'toCompile' (due to MAX_AT_ONCE=1) and the others into 'remainingUnits' + // This ensures that NameEnvironment is setup with "Main.java" and "Main$Sub.java" both served from 'additionalUnits' + // which is essential for reproducing the bug. + + fullBuild(projectPath); + expectingNoProblems(); + } finally { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = save; + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=386901 + public void testbBug386901() throws JavaModelException { + + int previous = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + try { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p", "AB", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AB {} \n"+ //$NON-NLS-1$ + "class AZ {}"); //$NON-NLS-1$ + + IPath pathToAA = env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA extends AZ {}"); //$NON-NLS-1$ + + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 1; // units compiled in batches of '1' unit + fullBuild(projectPath); + expectingProblemsFor( + pathToAA, + "Problem : AZ cannot be resolved to a type [ resource : range : <36,38> category : <40> severity : <2>]" + ); + + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 0; // All units compiled at once + fullBuild(projectPath); + expectingNoProblems(); + } finally { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = previous; + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=425420 + public void testBug425420() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ + // don't env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath path = env.addClass(root, "", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "class X {\n" + + " void test() {\n" + + " int x = 0;\n" + + " int y = 0 >= 0 ? x : \"\"; \n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingProblemsFor( + path, + "Problem : The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files [ resource : range : <0,1> category : <10> severity : <2>]" + ); + } + public void testBug549942() throws JavaModelException { + int save = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + try { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + env.addClass(root, "test", + "ARequiresNested", + "package test;\n" + + "\n" + + "public class ARequiresNested {\n" + + " Nested n;\n" + + "}" + ); + + env.addClass(root, "test", + "BRequiresToplevel", + "package test;\n" + + "\n" + + "public class BRequiresToplevel {\n" + + " TopLevel t;\n" + + "}" + ); + + env.addClass(root, "test", + "TopLevel", + "package test;\n" + + "\n" + + "public class TopLevel {\n" + + "\n" + + "}\n" + + "\n" + + "class Nested extends TopLevel {\n" + + "}" + ); + + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 2; + + fullBuild(projectPath); + expectingNoProblems(); + } finally { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = save; + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug530366Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug530366Test.java new file mode 100644 index 0000000000..32eb03ae7c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug530366Test.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2018 Simeon Andreev and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Simeon Andreev - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import static org.junit.Assert.assertArrayEquals; + +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.Util; +import org.junit.internal.ArrayComparisonFailure; + +import junit.framework.Test; + +public class Bug530366Test extends BuilderTests { + + private IPath project; + private IPath src; + private IPath somePackage; + + public Bug530366Test(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(Bug530366Test.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + this.project = env.addProject("TestProjectBug530366"); + env.addExternalJars(this.project, Util.getJavaClassLibs()); + + env.removePackageFragmentRoot(this.project, ""); + this.src = env.addPackageFragmentRoot(this.project, "src"); + this.somePackage = env.addPackage(this.src, "somepackage"); + } + + @Override + protected void tearDown() throws Exception { + env.removeProject(this.project); + + super.tearDown(); + } + + /** + * Test for Bug 530366: Changing class name in source leads to missing inner class compilation artifact + * + * Given classes: + * + *
    + *
  • MyClass1, MyClass1$InnerClass, both defined in MyClass1.java
  • + *
  • MyClass2, MyClass2$InnerClass, both defined in MyClass2.java
  • + *
+ * + * Changing the name of the class in MyClass2.java inside a Java editor, from MyClass2 to MyClass1, + * results in overwriting the compiled .class file for MyClass1$InnerClass. + * + * Changing the name of the class in MyClass2.java inside a Java editor, from MyClass1 back to MyClass2, + * results in a missing .class file for MyClass1$InnerClass. + */ + public void testBug530366() throws Exception { + defineNestingClass("MyClass1"); + fullBuild(); + expectingNoProblems(); + + IProject testProject = ResourcesPlugin.getWorkspace().getRoot().getProject("TestProjectBug530366"); + IFile myClass1InnerClass = testProject.getFile("bin/somepackage/MyClass1$InnerClass.class"); + + URI compilationArtifactUri = myClass1InnerClass.getLocationURI(); + byte[] expectedContents = Files.readAllBytes(Paths.get(compilationArtifactUri)); + + String sourceName = "MyClass2"; + String className = "MyClass1"; // deliberately mismatched source and class names + IPath myClass2 = defineNestingClass(sourceName, className); + + incrementalBuild(); + expectProblems(myClass2); + + byte[] actualContents = Files.readAllBytes(Paths.get(compilationArtifactUri)); + + assertEqualContents(expectedContents, actualContents); + + redefineNestingClass("MyClass2"); + incrementalBuild(); + expectingNoProblems(); + + assertTrue("Java builder removed compilation artifact, but should not have", + myClass1InnerClass.exists()); + } + + private IPath redefineNestingClass(String className) { + env.removeClass(this.somePackage, className); + return defineNestingClass(className); + } + + private IPath defineNestingClass(String className) { + return defineNestingClass(className, className); + } + + private IPath defineNestingClass(String sourceName, String className) { + String classContents = String.join("\n" + , "package somepackage;" + , "" + , "public class " + className + " {" + , "" + , " public static class InnerClass {}" + , "}" + ); + IPath source = env.addClass(this.src, "somepackage", sourceName, classContents); + return source; + } + + private void expectProblems(IPath myClass2) { + Problem mismatchedSource = new Problem("", "The public type MyClass1 must be defined in its own file", myClass2, 35, 43, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR); + Problem alreadyDefined = new Problem("", "The type MyClass1 is already defined", myClass2, 35, 43, -1, IMarker.SEVERITY_ERROR); + Problem[] expectedProblems = { mismatchedSource, alreadyDefined }; + expectingOnlySpecificProblemsFor(myClass2, expectedProblems); + } + + private void assertEqualContents(byte[] expectedContents, byte[] actualContents) throws ArrayComparisonFailure { + String failMessage = + String.join(System.lineSeparator() + , "Java builder overwrote existing class file, but should not have" + , "expected class file contents: " + , new String(expectedContents) + , "actual class file contents: " + , new String(actualContents) + ); + assertArrayEquals(failMessage, expectedContents, actualContents); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug531382Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug531382Test.java new file mode 100644 index 0000000000..099bbc018f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug531382Test.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2018 Simeon Andreev and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Simeon Andreev - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.ByteArrayInputStream; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jdt.core.compiler.BuildContext; +import org.eclipse.jdt.core.tests.builder.ParticipantBuildTests.BuildTestParticipant; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.core.builder.AbstractImageBuilder; + +import junit.framework.Test; + +public class Bug531382Test extends BuilderTests { + + private IPath project; + private IPath src; + private IPath srcPackage; + + private int previousLimit; + + public Bug531382Test(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(Bug531382Test.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + this.project = env.addProject("TestProjectBug531382"); + env.addExternalJars(this.project, Util.getJavaClassLibs()); + + env.removePackageFragmentRoot(this.project, ""); + this.src = env.addPackageFragmentRoot(this.project, "src"); + this.srcPackage = env.addPackage(this.src, "p"); + + /* + * We can work with the limit "as is", however that would mean creating a lot of classes. + * To improve test time we set the limit to a small number and then restore it once the test is done. + * + * This improvement can be removed if the field is to be hidden or made final. + */ + this.previousLimit = AbstractImageBuilder.MAX_AT_ONCE; + AbstractImageBuilder.MAX_AT_ONCE = 42; + } + + @Override + protected void tearDown() throws Exception { + TestBuilderParticipant.PARTICIPANT = null; + + AbstractImageBuilder.MAX_AT_ONCE = this.previousLimit; + + env.removeProject(this.project); + + super.tearDown(); + } + + /** + * Test for Bug 531382. + * + * We create {@link AbstractImageBuilder#MAX_AT_ONCE} sources (e.g. 2000 sources). + * + * A build participant generates one more source during the build. + * + * We expect that this generated source is also compiled after the build. + * To check this we generate the source with an error for it, and we check for the error. + */ + public void testBug531382() throws Exception { + IFolder srcPackageFolder = env.getWorkspace().getRoot().getFolder(this.srcPackage); + assertTrue("package in source must exist", srcPackageFolder.exists()); + + for (int i = 0; i < AbstractImageBuilder.MAX_AT_ONCE; ++i) { + env.addClass(this.src, "p", "X" + i, "package p;\n public class X" + i + " {}"); + } + + final IFile generatedFile = srcPackageFolder.getFile("Generated.java"); + final String contents = "package p;\n public class NameMismatch {}"; + + class GenerateBrokenSource extends BuildTestParticipant { + public void buildStarting(BuildContext[] files, boolean isBatch) { + if (files.length > 0 && !generatedFile.exists()) { + BuildContext context = files[0]; + createFile(generatedFile, contents); + IFile[] generatedFiles = { generatedFile }; + context.recordAddedGeneratedFiles(generatedFiles); + } + } + } + // Creating this sets the build participant singleton. + new GenerateBrokenSource(); + + assertFalse("source to be generated from build participant should not exist before build", generatedFile.exists()); + fullBuild(this.project); + assertTrue("expected source to be generated from build participant", generatedFile.exists()); + + expectCompileProblem(this.project, "The public type NameMismatch must be defined in its own file"); + } + + protected void createFile(IFile generatedFile, String contents) { + boolean force = true; + IProgressMonitor monitor = new NullProgressMonitor(); + try { + generatedFile.create(new ByteArrayInputStream(contents.getBytes()), force, monitor); + generatedFile.setDerived(true, monitor); + } catch (CoreException e) { + throw new AssertionError("failed to generate file in build participant", e); + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug544921Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug544921Test.java new file mode 100644 index 0000000000..5ffa764741 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug544921Test.java @@ -0,0 +1,415 @@ +/******************************************************************************* + * Copyright (c) 2019 Sebastian Zarnekow and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Zarnekow - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; + +import junit.framework.Test; + +public class Bug544921Test extends BuilderTests { + public Bug544921Test(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(Bug544921Test.class); + } + + public void testCompilerRegression() throws JavaModelException, Exception { + IPath projectPath = env.addProject("Bug544921Test", "1.8"); //$NON-NLS-1$ + + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.addClass(projectPath, "a", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package a;\n" + + "import java.util.EnumMap;\n" + + "enum E {}\n" + + "public class Test {\n" + + " Object x = new EnumMap(E.class) {\n" + + " static final long serialVersionUID = 1;\n" + + " {\n" + + " E.values();\n" + + " }\n" + + " };\n" + + "}" //$NON-NLS-1$ + ); + fullBuild(); + expectingNoProblems(); + } + + public void testBuildLargeFile_01() throws JavaModelException, Exception { + IPath projectPath = env.addProject("Bug544921Test", "1.8"); //$NON-NLS-1$ + scaffoldProject(projectPath, 1, 10, 64); + fullBuild(); + expectingNoProblems(); + } + + public void testBuildLargeFile_02() throws JavaModelException, Exception { + IPath projectPath = env.addProject("Bug544921Test", "1.8"); //$NON-NLS-1$ + scaffoldProject(projectPath, 2, 500, 64); + fullBuild(); + expectingNoProblems(); + } + + public void testBuildLargeFile_03() throws JavaModelException, Exception { + IPath projectPath = env.addProject("Bug544921Test", "1.8"); //$NON-NLS-1$ + scaffoldProject(projectPath, 3, 500, 64); + fullBuild(); + expectingNoProblems(); + } + + private boolean hasEnoughMemory(long required) { + long bytes = Runtime.getRuntime().maxMemory(); + long megabytes = bytes / 1024 / 1024; + return megabytes > required; + } + + public void testBuildLargeFile_04() throws JavaModelException, Exception { + if (hasEnoughMemory(2048)) { + IPath projectPath = env.addProject("Bug544921Test", "1.8"); //$NON-NLS-1$ + scaffoldProject(projectPath, 4, 500, 64); + fullBuild(); + expectingNoProblems(); + } + } + + public void testBuildLargeFile_05() throws JavaModelException, Exception { + if (hasEnoughMemory(2048)) { + IPath projectPath = env.addProject("Bug544921Test", "1.8"); //$NON-NLS-1$ + scaffoldProject(projectPath, 5, 500, 64); + fullBuild(); + expectingNoProblems(); + } + } + + public void testBuildLargeFile_08() throws JavaModelException, Exception { + if (hasEnoughMemory(2048)) { + IPath projectPath = env.addProject("Bug544921Test", "1.8"); //$NON-NLS-1$ + scaffoldProject(projectPath, 8, 500, 64); + fullBuild(); + expectingNoProblems(); + } + } + + public void testBuildLargeFile_10() throws JavaModelException, Exception { + if (hasEnoughMemory(2048)) { + IPath projectPath = env.addProject("Bug544921Test", "1.8"); //$NON-NLS-1$ + scaffoldProject(projectPath, 10, 500, 64); + fullBuild(); + expectingNoProblems(); + } + } + + private void scaffoldProject(IPath projectPath, int maxPeripheral, int maxRegister, int maxFields) throws JavaModelException { + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "reg", "Field", //$NON-NLS-1$ //$NON-NLS-2$ + "package reg;\n" + + "\n" + + "import reg.Register.AccessType;\n" + + "\n" + + "public class Field {\n" + + " String name;\n" + + " String description;\n" + + " long bitRange;\n" + + " AccessType accessType;\n" + + "\n" + + " public Field(String name, String description, long bitRange, AccessType accessType) {\n" + + " super();\n" + + " this.name = name;\n" + + " this.description = description;\n" + + " this.bitRange = bitRange;\n" + + " this.accessType = accessType;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"Field [name=\" + name + \", description=\" + description + \", bitRange=\" + bitRange + \", accessType=\"\n" + + " + accessType + \"]\";\n" + + " }\n" + + " \n" + + "}" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "reg", "Peripheral", //$NON-NLS-1$ //$NON-NLS-2$ + "package reg;\n" + + "\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "import java.util.TreeMap;\n" + + "\n" + + "public class Peripheral {\n" + + "\n" + + " String name;\n" + + " String version;\n" + + " String description;\n" + + " String groupName;\n" + + " long baseAddress;\n" + + " long size;\n" + + "\n" + + " Map registersMap;\n" + + "\n" + + " public Peripheral(String name, String version, String description, String groupName,\n" + + " long baseAddress, long size) {\n" + + " super();\n" + + " this.name = name;\n" + + " this.version = version;\n" + + " this.description = description;\n" + + " this.groupName = groupName;\n" + + " this.baseAddress = baseAddress;\n" + + " this.size = size;\n" + + " }\n" + + "\n" + + " private void initRegistersMap(){\n" + + " if (registersMap != null) {\n" + + " return;\n" + + " }\n" + + " registersMap = new TreeMap<>();\n" + + " for (java.lang.reflect.Field field : this.getClass().getDeclaredFields()) {\n" + + " if (!Register.class.isAssignableFrom(field.getType())){\n" + + " continue;\n" + + " }\n" + + " try {\n" + + " registersMap.put(field.getName(), (Register) field.get(this));\n" + + " } catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " public Register getRegister(String name) {\n" + + " return registersMap.get(name);\n" + + " }\n" + + " public Collection getRegisters(){\n" + + " initRegistersMap();\n" + + " return registersMap.values();\n" + + " }\n" + + "}\n" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "reg", "Reg", //$NON-NLS-1$ //$NON-NLS-2$ + "package reg;\n" + + "\n" + + "public final class Reg {\n" + + "\n" + + " Peripheral_TIMER0 peripheral_Timer0 = new Peripheral_TIMER0();\n" + + "\n" + + " public static final class Peripheral_TIMER0 extends Peripheral {\n" + + "\n" + + " public Peripheral_TIMER0() {\n" + + " super(\"TIMER0\", \"1.0\", \"desc\", \"groupName\", 0, 32);\n" + + " }\n" + + "\n" + + " public Reg_CR regCR = new Reg_CR();\n" + + "\n" + + " public static final class Reg_CR extends Register {\n" + + " public Reg_CR() {\n" + + " super(\"CR\", \"\", 0, 32, AccessType.readWrite, 0xf, 0x0);\n" + + " }\n" + + "\n" + + " // fields of CR\n" + + " public Field_EN fieldEn = new Field_EN();\n" + + "\n" + + " public static final class Field_EN extends Field {\n" + + " public Field_EN() {\n" + + " super(\"EN\", \"description\", 0, AccessType.readWrite);\n" + + " }\n" + + " }\n" + + "\n" + + " public Field_RST fieldRST = new Field_RST();\n" + + "\n" + + " public static final class Field_RST extends Field {\n" + + " public Field_RST() {\n" + + " super(\"RST\", \"description\", 1, AccessType.readWrite);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Reg reg = new Reg();\n" + + "\n" + + " System.out.println(reg.peripheral_Timer0.regCR.name + \": \" + reg.peripheral_Timer0.regCR.resetValue);\n" + + " System.out.println(reg.peripheral_Timer0.regCR.fieldEn.name + \": \" + reg.peripheral_Timer0.regCR.fieldEn.bitRange);\n" + + " }\n" + + "}\n" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "reg", "Register", //$NON-NLS-1$ //$NON-NLS-2$ + "package reg;\n" + + "\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "import java.util.TreeMap;\n" + + "\n" + + "public class Register {\n" + + "\n" + + " public enum AccessType {\n" + + " readOnly, readWrite;\n" + + " }\n" + + "\n" + + " String name;\n" + + " String description;\n" + + " long addressOffset;\n" + + " long size;\n" + + " AccessType accessType;\n" + + " long resetValue;\n" + + " long resetMask;\n" + + " long value;\n" + + "\n" + + " Map fieldsMap;\n" + + "\n" + + " public Register(String name, String description, long addressOffset, long size,\n" + + " AccessType accessType, long resetValue, long resetMask) {\n" + + " this.name = name;\n" + + " this.description = description;\n" + + " this.addressOffset = addressOffset;\n" + + " this.size = size;\n" + + " this.accessType = accessType;\n" + + " this.resetValue = resetValue;\n" + + " this.resetMask = resetMask;\n" + + "\n" + + " }\n" + + "\n" + + " private void initFieldsMap(){\n" + + " if (fieldsMap != null) {\n" + + " return;\n" + + " }\n" + + " fieldsMap = new TreeMap<>();\n" + + " for (java.lang.reflect.Field field : this.getClass().getDeclaredFields()) {\n" + + " if (!Field.class.isAssignableFrom(field.getType())){\n" + + " continue;\n" + + " }\n" + + " try {\n" + + " fieldsMap.put(field.getName(), (Field) field.get(this));\n" + + " } catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " public void setValue(long value){\n" + + " this.value = value;\n" + + " }\n" + + "\n" + + " public long getValue(){\n" + + " return this.value;\n" + + " }\n" + + "\n" + + " public Collection getFields(){\n" + + " initFieldsMap();\n" + + " return fieldsMap.values();\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"Register [name=\" + name + \", description=\" + description + \", addressOffset=\" + addressOffset\n" + + " + \", size=\" + size + \", accessType=\" + accessType + \", resetValue=\" + resetValue + \", resetMask=\"\n" + + " + resetMask + \"]\";\n" + + " }\n" + + "\n" + + "\n" + + "}\n" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "reg.generate", "DeviceXY", genSource(maxPeripheral, maxRegister, maxFields)); + } + + public static String genSource(int maxPeripheral, int maxRegister, int maxFields) { + /* + * + * The example that took 25 minutes was generated with: int maxPeripheral = 10; + * int maxRegister = 500; int maxFields = 64; + * + * Still performs ok (less than a minute): int maxPeripheral = 2; int + * maxRegister = 500; int maxFields = 64; + * + * With this (8 MB) it gets already slow (few minutes): int maxPeripheral = 3; + * int maxRegister = 500; int maxFields = 64; + * + * This takes 5 minutes (14MB file-size): int maxPeripheral = 5; int maxRegister + * = 500; int maxFields = 64; + */ + + StringBuilder source = new StringBuilder(); + + source.append("package reg.generate;").append(System.lineSeparator()); + source.append("public class DeviceXY {").append(System.lineSeparator()); + source.append("private static DeviceXY instance;").append(System.lineSeparator()); + source.append("private DeviceXY() {}").append(System.lineSeparator()); + source.append("public static DeviceXY getInstance() {").append(System.lineSeparator()); + source.append(" if (instance == null) { instance = new DeviceXY(); }").append(System.lineSeparator()); + source.append(" return instance;").append(System.lineSeparator()); + source.append("}").append(System.lineSeparator()); + + for (int peripheral = 0; peripheral < maxPeripheral; peripheral++) { + String peripheralName = "peri_" + peripheral; + String peripheralClassName = String.valueOf(Character.toUpperCase(peripheralName.charAt(0))) + + peripheralName.substring(1); + + source.append("public ").append(peripheralClassName).append(" ").append(peripheralName) + .append(" = new ").append(peripheralClassName).append("();").append(System.lineSeparator()); + source.append("public static final class ").append(peripheralClassName) + .append(" extends reg.Peripheral {").append(System.lineSeparator()); + // constructor start + source.append("public ").append(peripheralClassName).append("() {").append(System.lineSeparator()); + source.append(" super(\"").append(peripheralName).append("\",") + .append("\"1.0\",\"desc\", \"groupName\", 0, 32);").append(System.lineSeparator()); + source.append("}").append(System.lineSeparator()); + // constructor end + + for (int register = 0; register < maxRegister; register++) { + String registerName = "reg_" + register; + String registerClassName = String.valueOf(Character.toUpperCase(registerName.charAt(0))) + + registerName.substring(1); + + source.append("public ").append(registerClassName).append(" ").append(registerName) + .append(" = new ").append(registerClassName).append("();").append(System.lineSeparator()); + + source.append("/**").append(System.lineSeparator()); + source.append("* Register ").append(registerName).append(System.lineSeparator()); + source.append("*/").append(System.lineSeparator()); + source.append("public static final class ").append(registerClassName) + .append(" extends reg.Register {").append(System.lineSeparator()); + // constructor start + source.append("public ").append(registerClassName).append("() {") + .append(System.lineSeparator()); + source.append(" super(\"").append(registerName).append("\",") + .append("\"desc\", 0, 32, AccessType.readWrite, 0xf, 0x0);").append(System.lineSeparator()); + source.append("}").append(System.lineSeparator()); + // constructor end + + source.append("//fields").append(System.lineSeparator()); + + for (int field = 0; field < maxFields; field++) { + String fieldName = "field_" + field; + source.append("public ").append("reg.Field").append(" ").append(fieldName) + .append(" = new ").append("reg.Field").append("(\"").append(fieldName).append("\",") + .append("\"desc\", 0, AccessType.readWrite);").append(System.lineSeparator()); + + } + + source.append("}").append(System.lineSeparator()); + } + source.append("}").append(System.lineSeparator()); + } + + + source.append("}").append(System.lineSeparator()); + + return source.toString(); + + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug549457Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug549457Test.java new file mode 100644 index 0000000000..8b4d881e9a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug549457Test.java @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2019 Simeon Andreev and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Simeon Andreev - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.ByteArrayInputStream; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.core.JavaProject; + +import junit.framework.Test; + +public class Bug549457Test extends BuilderTests { + + private IPath project; + private IPath src; + private IPath srcPackage; + private boolean oldAutoBuilding; + + public Bug549457Test(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(Bug549457Test.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + this.project = env.addProject("Bug549457Test"); + env.addExternalJars(this.project, Util.getJavaClassLibs()); + + env.removePackageFragmentRoot(this.project, ""); + this.src = env.addPackageFragmentRoot(this.project, "src"); + this.srcPackage = env.addPackage(this.src, "p"); + + this.oldAutoBuilding = env.isAutoBuilding(); + env.setAutoBuilding(true); + waitForAutoBuild(); + } + + @Override + protected void tearDown() throws Exception { + TestBuilderParticipant.PARTICIPANT = null; + env.removeProject(this.project); + env.setAutoBuilding(this.oldAutoBuilding); + waitForAutoBuild(); + super.tearDown(); + } + + /** + * Test for Bug 549457. + * + * We expect that a JDT compiler setting change triggers a build, resulting in a build problem. + */ + public void testBug549457() throws Exception { + IFolder srcPackageFolder = env.getWorkspace().getRoot().getFolder(this.srcPackage); + assertTrue("package in source must exist", srcPackageFolder.exists()); + + env.addClass(this.src, "p", "X", "package p;\n public interface X { default void foo() { /* cause an error with Java 7 */ } }"); + + fullBuild(this.project); + // For this test, the default is not Java 8. If this changes, we can expect no problems here. The test cares only that the source was compiled. + expectCompileProblem(this.project, "Default methods are allowed only at source level 1.8 or above"); + + IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); + IProject testProject = workspaceRoot.getProject("Bug549457Test"); + IJavaProject javaProject = JavaCore.create(testProject); + javaProject.setOption(CompilerOptions.OPTION_Compliance, "1.8"); + javaProject.setOption(CompilerOptions.OPTION_Source, "1.8"); + testProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); + waitForAutoBuild(); + fullBuild(this.project); + expectNoCompileProblems(this.project); + + String jdtCorePreferencesFile = JavaProject.DEFAULT_PREFERENCES_DIRNAME + IPath.SEPARATOR + JavaProject.JAVA_CORE_PREFS_FILE; + IFile settingsFile = testProject.getFile(jdtCorePreferencesFile); + assertTrue("expected \"" + jdtCorePreferencesFile + "\" to exist after setting compiler compliance to Java 1.7", settingsFile.exists()); + + String newContents = String.join( + CompilerOptions.OPTION_Compliance + "=1.7", + CompilerOptions.OPTION_Source + "=1.7"); + + settingsFile.setContents(new ByteArrayInputStream(newContents.getBytes()), IResource.FORCE, new NullProgressMonitor()); + waitForAutoBuild(); + expectCompileProblem(this.project, "Default methods are allowed only at source level 1.8 or above"); + } + + private void waitForAutoBuild() throws InterruptedException { + Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, new NullProgressMonitor()); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug549646Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug549646Test.java new file mode 100644 index 0000000000..f661339d08 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug549646Test.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2019 Sebastian Zarnekow and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Zarnekow - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class Bug549646Test extends BuilderTests { + public Bug549646Test(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(Bug549646Test.class); + } + + public void testCompilerRegression() throws JavaModelException, Exception { + IPath projectPath = env.addProject("Bug549646Test", "10"); //$NON-NLS-1$ + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED); + + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.addClass(projectPath, "test", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package test;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "public class A {\n" + + " void a(Map a) {\n" + + " for (Entry iterableElement : a.entrySet()) {\n" + + " iterableElement.toString();\n" + + " }\n" + + " }\n" + + "}\n" //$NON-NLS-1$ + ); + env.addClass(projectPath, "test", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package test;\n" + + "import java.util.HashMap;\n" + + "public class B {\n" + + " void test() {\n" + + " new A().a(new HashMap());\n" + + " }\n" + + "}\n" //$NON-NLS-1$ + ); + fullBuild(); + + boolean isJRE11 = CompilerOptions.VERSION_11.equals(System.getProperty("java.specification.version")); + if (isJRE11 && env.getProblemsFor(projectPath).length > 0) { + // bogus class lookup (ignoring modules) due to insufficient data in ct.sym (non-deterministically triggers the below problems) + // see also https://bugs.eclipse.org/549647 + expectingProblemsFor(projectPath, + "Problem : Entry cannot be resolved to a type [ resource : range : <120,125> category : <40> severity : <2>]\n" + + "Problem : The type java.util.Map.Entry is not visible [ resource : range : <43,62> category : <40> severity : <2>]\n" + + "Problem : Type mismatch: cannot convert from element type Map.Entry to Entry [ resource : range : <160,172> category : <40> severity : <2>]"); + } else { + expectingNoProblems(); + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug561287Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug561287Test.java new file mode 100644 index 0000000000..5a167f18e2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug561287Test.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2020 Stephan Herrmann and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.core.builder.AbstractImageBuilder; + +import junit.framework.Test; + +public class Bug561287Test extends BuilderTests { + public Bug561287Test(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(Bug561287Test.class); + } + public void testBuilderRegression() throws JavaModelException, Exception { + int maxAtOnce = AbstractImageBuilder.MAX_AT_ONCE; + AbstractImageBuilder.MAX_AT_ONCE = 2; + try { + IPath projectPath = env.addProject("Bug561287Test", "1.8"); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED); + env.removePackageFragmentRoot(projectPath, ""); + IPath src = env.addPackageFragmentRoot(projectPath, "src"); + + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.addClass(src, "bug561287", "A0", + "package bug561287;\n" + + "import bug561287.sub.B0;\n" + + "\n" + + "public class A0 {\n" + + " B0 b;\n" + + "}\n"); + env.addClass(src, "bug561287", "A1", + "package bug561287;\n" + + "\n" + + "public class A1 {\n" + + "\n" + + "}\n"); + env.addClass(src, "bug561287/sub", "B0", + "package bug561287.sub;\n" + + "\n" + + "public class B0 {\n" + + "\n" + + "}\n" + + "\n"); + env.addFolder(src, "bug561287/sub/directory"); + env.addFile(src, "bug561287/sub/directory/test.txt", ""); + fullBuild(); + + expectingNoProblems(); + } finally { + AbstractImageBuilder.MAX_AT_ONCE = maxAtOnce; + } + } +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug562420Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug562420Test.java new file mode 100644 index 0000000000..90f691a6c7 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug562420Test.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2020 Stephan Herrmann and others. + + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class Bug562420Test extends BuilderTests { + public Bug562420Test(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(Bug562420Test.class); + } + public void testBuilderRegression() throws JavaModelException, Exception { + IPath projectPath = env.addProject("Bug562420Test", "9"); + env.removePackageFragmentRoot(projectPath, ""); + IPath src = env.addPackageFragmentRoot(projectPath, "src"); + + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + IPath testAppPath = env.addClass(src, "org.easylibs.test", "TestApp", + "package org.easylibs.test;\n" + + "public class TestApp {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Hello World\");\n" + + " }\n" + + "}\n"); + env.addFile(testAppPath.removeLastSegments(1), "package-info.java", + "package org.easylibs.test;"); + env.addFile(src, "module-info.java", + "module test {\n" + + " requires java.base;\n" + + " exports org.easylibs.test;\n" + + "}\n"); + fullBuild(); + if (CompilerOptions.versionToJdkLevel(System.getProperty("java.specification.version")) < ClassFileConstants.JDK9) { + expectingProblemsFor(projectPath, + "Problem : java.base cannot be resolved to a module [ resource : range : <24,33> category : <160> severity : <2>]"); + } else { + expectingNoProblems(); + } + + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_SOURCE, "1.8"); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, "1.8"); + fullBuild(); + expectingProblemsFor(projectPath, + "Problem : Syntax error on token \".\", , expected [ resource : range : <28,29> category : <20> severity : <2>]\n" + + "Problem : Syntax error on token \".\", = expected [ resource : range : <47,48> category : <20> severity : <2>]\n" + + "Problem : Syntax error on token \"module\", interface expected [ resource : range : <0,6> category : <20> severity : <2>]"); + } +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug564905Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug564905Test.java new file mode 100644 index 0000000000..86f54d2d5c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug564905Test.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2020 Simeon Andreev and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Simeon Andreev - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.IOException; +import java.net.URI; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.util.Util; +import junit.framework.Test; + +public class Bug564905Test extends BuilderTests { + + private static final String OUTPUT_FOLDER_NAME = "bin"; + + private String projectName; + private IProject project; + private IPath projectPath; + private IPath src; + private IFolder outputFolder; + private boolean oldAutoBuilding; + + public Bug564905Test(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(Bug564905Test.class); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + this.projectName = "Bug564905Test"; + this.projectPath = env.addProject(this.projectName); + this.project = env.getWorkspace().getRoot().getProject(this.projectName); + env.addExternalJars(this.projectPath, Util.getJavaClassLibs()); + + env.removePackageFragmentRoot(this.projectPath, ""); + String outputFolderPath = "tmp/" + OUTPUT_FOLDER_NAME; + this.src = env.addPackageFragmentRoot(this.projectPath, "src", null, outputFolderPath); + this.outputFolder = env.getWorkspace().getRoot().getFolder(this.projectPath.append(outputFolderPath)); + + this.oldAutoBuilding = env.isAutoBuilding(); + env.setAutoBuilding(true); + waitForAutoBuild(); + } + + @Override + protected void tearDown() throws Exception { + TestBuilderParticipant.PARTICIPANT = null; + env.removeProject(this.projectPath); + env.setAutoBuilding(this.oldAutoBuilding); + waitForAutoBuild(); + + super.tearDown(); + } + + /** + * Test for Bug 564905, with option {@code org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder} enabled. + * + * When the output folder of a project is removed in file system, on refresh we expect a build. + */ + public void testBug564905_recreateModifiedClassFileInOutputFolder_enabled() throws Exception { + enableOption_recreateModifiedClassFileInOutputFolder(); + assertOutputFolderEmpty(); + + addSourceAndBuild(); + assertOutputFolderNotEmpty(); + + deleteOutputFolderAndWaitForAutoBuild(); + // we enabled "recreateModifiedClassFileInOutputFolder", so we expect compile artifacts + assertOutputFolderNotEmpty(); + } + + /** + * Test for Bug 564905, with option {@code org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder} disabled. + * + * When the output folder of a project is removed in file system, on refresh we don't expect a build + * as we don't use the option {@link JavaCore#CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER}. + */ + public void testBug564905_recreateModifiedClassFileInOutputFolder_disabled() throws Exception { + disableOption_recreateModifiedClassFileInOutputFolder(); + assertOutputFolderEmpty(); + + addSourceAndBuild(); + assertOutputFolderNotEmpty(); + + deleteOutputFolderAndWaitForAutoBuild(); + // we disabled "recreateModifiedClassFileInOutputFolder", so we don't expect compile artifacts + assertOutputFolderEmpty(); + } + + private void deleteOutputFolderAndWaitForAutoBuild() throws Exception { + // close the project, since the bug 564905 occurs when build state is read from disk + this.project.close(new NullProgressMonitor()); + waitForAutoBuild(); + URI outputFolderUri = this.outputFolder.getLocationURI(); + // delete the output folder with file system API, so that Eclipse resources API "doesn't notice" + deleteFolderInFileSystem(outputFolderUri); + + // re-open the project, refresh it, then wait for auto-build; expect that something was built + this.project.open(new NullProgressMonitor()); + this.project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); + waitForAutoBuild(); + } + + private void addSourceAndBuild() { + IPath srcPackage = env.addPackage(this.src, "p"); + IFolder srcPackageFolder = env.getWorkspace().getRoot().getFolder(srcPackage); + assertTrue("package in source must exist", srcPackageFolder.exists()); + env.addClass(this.src, "p", "X", "package p;\n public interface X { void foo() { /* we want something compiled, anything works */ } }"); + fullBuild(this.projectPath); + } + + private void enableOption_recreateModifiedClassFileInOutputFolder() throws Exception { + setJavaProjectOption(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.ENABLED); + } + + private void disableOption_recreateModifiedClassFileInOutputFolder() throws Exception { + setJavaProjectOption(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.DISABLED); + } + + private void setJavaProjectOption(String optionName, String optionValue) throws Exception { + IJavaProject javaProject = JavaCore.create(this.project); + javaProject.setOption(optionName, optionValue); + this.project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); + waitForAutoBuild(); + } + + private void waitForAutoBuild() throws InterruptedException { + Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, new NullProgressMonitor()); + } + + private static void deleteFolderInFileSystem(URI uri) throws IOException { + Files.walkFileTree(Paths.get(uri), new DeleteVisitor()); + } + + private void assertOutputFolderEmpty() throws CoreException { + assertTrue("output folder must exist", this.outputFolder.exists()); + IResource[] outputFolderContent = this.outputFolder.members(); + assertEquals("output folder must be empty, instead had contents: " + toString(outputFolderContent), 0, outputFolderContent.length); + } + + private void assertOutputFolderNotEmpty() throws CoreException { + assertTrue("output folder must exist", this.outputFolder.exists()); + assertTrue("output folder must not be empty", this.outputFolder.members().length > 0); + } + + private static String toString(IResource[] resources) { + StringBuilder result = new StringBuilder(); + for (IResource resource : resources) { + result.append(resource.getName()); + result.append(System.lineSeparator()); + } + return result.toString(); + } + + static class DeleteVisitor extends SimpleFileVisitor { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (exc != null) { + throw exc; + } + Files.delete(dir); + return FileVisitResult.CONTINUE; + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug571363Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug571363Test.java new file mode 100644 index 0000000000..726fb39c47 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Bug571363Test.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2021 Red Hat Inc. and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat Inc. - initial implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.File; +import java.io.IOException; +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; +import junit.framework.Test; + +public class Bug571363Test extends BuilderTests { + + public Bug571363Test(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(Bug571363Test.class); + } + + /** + * Returns the OS path to the directory that contains this plugin. + */ + protected String getCompilerTestsPluginDirectoryPath() { + try { + URL platformURL = Platform.getBundle("org.eclipse.jdt.core.tests.builder").getEntry("/"); + return new File(FileLocator.toFileURL(platformURL).getFile()).getAbsolutePath(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public void _testBug571363() throws JavaModelException, Exception { + IPath projectPath = env.addProject("Bug571364Test", "12"); //$NON-NLS-1$ + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_11); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_RELEASE, JavaCore.ENABLED); + + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "test", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package test;\n" + + "public class A {\n" + + " org.w3c.dom.Element list;\n" + + "}\n" //$NON-NLS-1$ + ); + StringBuilder buffer = new StringBuilder("\n"); //$NON-NLS-1$ + buffer.append("\n"); //$NON-NLS-1$ + buffer.append(" \n"); //$NON-NLS-1$ + buffer.append(" \n"); + buffer.append(" \n"); + buffer.append(" \n"); + buffer.append(" \n"); + buffer.append(" \n"); + buffer.append(" "); + buffer.append(" \n"); //$NON-NLS-1$ + buffer.append(""); //$NON-NLS-1$ + env.addFile(projectPath, ".classpath", buffer.toString()); //$NON-NLS-1$ + fullBuild(); + + expectingNoProblems(); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuilderTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuilderTests.java new file mode 100644 index 0000000000..bb58958e18 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuilderTests.java @@ -0,0 +1,674 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import static org.eclipse.jdt.core.tests.util.AbstractCompilerTest.*; + +import java.io.FileInputStream; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.List; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.junit.extension.TestCase; +import org.eclipse.jdt.core.tests.util.TestVerifier; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.Compiler; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Base class for Java image builder tests + */ +@SuppressWarnings({"rawtypes", "unchecked"}) +public class BuilderTests extends TestCase { + protected static boolean DEBUG = false; + protected static TestingEnvironment env = null; + protected EfficiencyCompilerRequestor debugRequestor = null; + + public BuilderTests(String name) { + super(name); + } + + protected void cleanBuild() { + this.debugRequestor.clearResult(); + this.debugRequestor.activate(); + env.cleanBuild(); + this.debugRequestor.deactivate(); + } + + protected void cleanBuild(String name) { + this.debugRequestor.clearResult(); + this.debugRequestor.activate(); + env.cleanBuild(name); + this.debugRequestor.deactivate(); + } + + /** Execute the given class. Expecting output and error must be specified. + */ + protected void executeClass( + IPath projectPath, + String className, + String expectingOutput, + String expectedError) { + TestVerifier verifier = new TestVerifier(false); + ArrayList classpath = new ArrayList<>(5); + + IPath workspacePath = env.getWorkspaceRootPath(); + + classpath.add(workspacePath.append(env.getOutputLocation(projectPath)).toOSString()); + IClasspathEntry[] cp = env.getClasspath(projectPath); + for (int i = 0; i < cp.length; i++) { + IPath c = cp[i].getPath(); + String ext = c.getFileExtension(); + if (ext != null && (ext.equals("zip") || ext.equals("jar"))) { //$NON-NLS-1$ //$NON-NLS-2$ + if (c.getDevice() == null) { + classpath.add(workspacePath.append(c).toOSString()); + } else { + classpath.add(c.toOSString()); + } + } + } + + verifier.execute(className, classpath.toArray(new String[0])); + + if (DEBUG) { + System.out.println("ERRORS\n"); //$NON-NLS-1$ + System.out.println(Util.displayString(verifier.getExecutionError())); + + System.out.println("OUTPUT\n"); //$NON-NLS-1$ + System.out.println(Util.displayString(verifier.getExecutionOutput())); + } + String actualError = verifier.getExecutionError(); + + // workaround pb on 1.3.1 VM (line delimitor is not the platform line delimitor) + char[] error = actualError.toCharArray(); + actualError = new String(CharOperation.replace(error, System.getProperty("line.separator").toCharArray(), new char[] { '\n' })); //$NON-NLS-1$ + + if (actualError.indexOf(expectedError) == -1) { + System.out.println("ERRORS\n"); //$NON-NLS-1$ + System.out.println(Util.displayString(actualError)); + } + assertTrue("unexpected error : " + actualError + " expected : " + expectedError, actualError.indexOf(expectedError) != -1); //$NON-NLS-1$ //$NON-NLS-2$ + + String actualOutput = verifier.getExecutionOutput(); + if (actualOutput.indexOf(expectingOutput) == -1) { + System.out.println("OUTPUT\n"); //$NON-NLS-1$ + System.out.println(Util.displayString(actualOutput)); + } + assertTrue("unexpected output :" + actualOutput + " expected: " + expectingOutput, actualOutput.indexOf(expectingOutput) != -1); //$NON-NLS-1$ + + } + + protected void expectingParticipantProblems(IPath path, String expected) { + Problem[] problems = env.getProblemsFor(path, "org.eclipse.jdt.core.tests.compile.problem"); + StringBuilder buf = new StringBuilder(); + for (int i = 0, length = problems.length; i < length; i++) { + Problem problem = problems[i]; + buf.append(problem.getMessage()); + if (i < length - 1) buf.append('\n'); + } + assertEquals("Unexpected problems", expected, buf.toString()); + } + + /** Verifies that given element is not present. + */ + protected void expectingPresenceOf(IPath path) { + expectingPresenceOf(new IPath[] { path }); + } + + /** Verifies that given elements are not present. + */ + protected void expectingPresenceOf(IPath[] paths) { + IPath wRoot = env.getWorkspaceRootPath(); + + for (int i = 0; i < paths.length; i++) + assertTrue(paths[i] + " is not present", wRoot.append(paths[i]).toFile().exists()); //$NON-NLS-1$ + } + + /** Verifies that given element is not present. + */ + protected void expectingNoPresenceOf(IPath path) { + expectingNoPresenceOf(new IPath[] { path }); + } + + /** Verifies that given elements are not present. + */ + protected void expectingNoPresenceOf(IPath[] paths) { + IPath wRoot = env.getWorkspaceRootPath(); + + for (int i = 0; i < paths.length; i++) + assertTrue(paths[i] + " is present", !wRoot.append(paths[i]).toFile().exists()); //$NON-NLS-1$ + } + + /** Verifies that given classes have been compiled. + */ + protected void expectingCompiledClasses(String[] expected) { + String[] actual = this.debugRequestor.getCompiledClasses(); + org.eclipse.jdt.internal.core.util.Util.sort(actual); + org.eclipse.jdt.internal.core.util.Util.sort(expected); + expectingCompiling(actual, expected, "unexpected recompiled units"); //$NON-NLS-1$ + } + + /** + * Verifies that the given classes and no others have been compiled, + * but permits the classes to have been compiled more than once. + */ + protected void expectingUniqueCompiledClasses(String[] expected) { + String[] actual = this.debugRequestor.getCompiledClasses(); + org.eclipse.jdt.internal.core.util.Util.sort(actual); + // Eliminate duplicate entries + int dups = 0; + for (int i = 0; i < actual.length - 1; ++i) { + if (actual[i + 1].equals(actual[i])) { + ++dups; + actual[i] = null; + } + } + String[] uniqueActual = new String[actual.length - dups]; + for (int i = 0, j = 0; i < actual.length; ++i) { + if (actual[i] != null) { + uniqueActual[j++] = actual[i]; + } + } + org.eclipse.jdt.internal.core.util.Util.sort(expected); + expectingCompiling(uniqueActual, expected, "unexpected compiled units"); //$NON-NLS-1$ + } + + /** Verifies that given classes have been compiled in the specified order. + */ + protected void expectingCompilingOrder(String[] expected) { + expectingCompiling(this.debugRequestor.getCompiledFiles(), expected, "unexpected compiling order"); //$NON-NLS-1$ + } + + private void expectingCompiling(String[] actual, String[] expected, String message) { + if (DEBUG) + for (int i = 0; i < actual.length; i++) + System.out.println(actual[i]); + + StringBuilder actualBuffer = new StringBuilder("{ "); //$NON-NLS-1$ + for (int i = 0; i < actual.length; i++) { + if (i > 0) + actualBuffer.append(", "); //$NON-NLS-1$ + actualBuffer.append("\""); + actualBuffer.append(actual[i]); + actualBuffer.append("\""); + } + actualBuffer.append(" }"); + StringBuilder expectedBuffer = new StringBuilder("{ "); //$NON-NLS-1$ + for (int i = 0; i < expected.length; i++) { + if (i > 0) + expectedBuffer.append(", "); //$NON-NLS-1$ + expectedBuffer.append("\""); + expectedBuffer.append(expected[i]); + expectedBuffer.append("\""); + } + expectedBuffer.append(" }"); + assertEquals(message, expectedBuffer.toString(), actualBuffer.toString()); + } + + /** Verifies that the workspace has no problems. + */ + protected void expectingNoProblems() { + expectingNoProblemsFor(env.getWorkspaceRootPath()); + } + + /** Verifies that the given element has no problems. + */ + protected void expectingNoProblemsFor(IPath root) { + expectingNoProblemsFor(new IPath[] { root }); + } + + /** Verifies that the given elements have no problems. + */ + protected void expectingNoProblemsFor(IPath[] roots) { + StringBuilder buffer = new StringBuilder(); + Problem[] allProblems = allSortedProblems(roots); + if (allProblems != null) { + for (int i=0, length=allProblems.length; i expected.length) { + for (Enumeration e = actual.elements(); e.hasMoreElements();) { + IPath path = (IPath) e.nextElement(); + boolean found = false; + for (int i = 0; i < expected.length; ++i) { + if (path.equals(expected[i])) { + found = true; + break; + } + } + if (!found) + assertTrue("unexpected problem(s) with " + path.toString(), false); //$NON-NLS-1$ + } + } + } + + /** Verifies that the given element has a specific problem and + * only the given problem. + */ + protected void expectingOnlySpecificProblemFor(IPath root, Problem problem) { + expectingOnlySpecificProblemsFor(root, new Problem[] { problem }); + } + + /** Verifies that the given element has specifics problems and + * only the given problems. + */ + protected void expectingOnlySpecificProblemsFor(IPath root, Problem[] expectedProblems) { + if (DEBUG) + printProblemsFor(root); + + Problem[] rootProblems = env.getProblemsFor(root); + + for (int i = 0; i < expectedProblems.length; i++) { + Problem expectedProblem = expectedProblems[i]; + boolean found = false; + for (int j = 0; j < rootProblems.length; j++) { + if(expectedProblem.equals(rootProblems[j])) { + found = true; + rootProblems[j] = null; + break; + } + } + if (!found) { + printProblemsFor(root); + } + assertTrue("problem not found: " + expectedProblem.toString(), found); //$NON-NLS-1$ + } + for (int i = 0; i < rootProblems.length; i++) { + if(rootProblems[i] != null) { + printProblemsFor(root); + assertTrue("unexpected problem: " + rootProblems[i].toString(), false); //$NON-NLS-1$ + } + } + } + + /** Verifies that the given element has problems. + */ + protected void expectingProblemsFor(IPath root, String expected) { + expectingProblemsFor(new IPath[] { root }, expected); + } + + /** Verifies that the given elements have problems. + */ + protected void expectingProblemsFor(IPath[] roots, String expected) { + Problem[] problems = allSortedProblems(roots); + assumeEquals("Invalid problem(s)!!!", expected, arrayToString(problems)); //$NON-NLS-1$ + } + + /** + * Verifies that the given element has the expected problems. + */ + protected void expectingProblemsFor(IPath root, List expected) { + expectingProblemsFor(new IPath[] { root }, expected); + } + + /** + * Verifies that the given elements have the expected problems. + */ + protected void expectingProblemsFor(IPath[] roots, List expected) { + Problem[] allProblems = allSortedProblems(roots); + assumeEquals("Invalid problem(s)!!!", arrayToString(expected.toArray()), arrayToString(allProblems)); + } + + /** Verifies that the given element has a specific problem. + */ + protected void expectingSpecificProblemFor(IPath root, Problem problem) { + expectingSpecificProblemsFor(root, new Problem[] { problem }); + } + + /** Verifies that the given element has specific problems. + */ + protected void expectingSpecificProblemsFor(IPath root, Problem[] problems) { + if (DEBUG) + printProblemsFor(root); + + Problem[] rootProblems = env.getProblemsFor(root); + next : for (int i = 0; i < problems.length; i++) { + Problem problem = problems[i]; + for (int j = 0; j < rootProblems.length; j++) { + Problem rootProblem = rootProblems[j]; + if (rootProblem != null) { + if (problem.equals(rootProblem)) { + rootProblems[j] = null; + continue next; + } + } + } + /* + for (int j = 0; j < rootProblems.length; j++) { + Problem pb = rootProblems[j]; + if (pb != null) { + System.out.print("got pb: new Problem(\"" + pb.getLocation() + "\", \"" + pb.getMessage() + "\", \"" + pb.getResourcePath() + "\""); + System.out.print(", " + pb.getStart() + ", " + pb.getEnd() + ", " + pb.getCategoryId()+ ", " + pb.getSeverity()); + System.out.println(")"); + } + } + */ + System.out.println("--------------------------------------------------------------------------------"); + System.out.println("Missing problem while running test "+getName()+":"); + System.out.println(" - expected : " + problem); + System.out.println(" - current: " + arrayToString(rootProblems)); + assumeTrue("missing expected problem: " + problem, false); + } + } + + /** Batch builds the workspace. + */ + protected void fullBuild() { + this.debugRequestor.clearResult(); + this.debugRequestor.activate(); + env.fullBuild(); + this.debugRequestor.deactivate(); + } + + /** Batch builds the given project. + */ + protected void fullBuild(IPath projectPath) { + this.debugRequestor.clearResult(); + this.debugRequestor.activate(); + env.fullBuild(projectPath); + this.debugRequestor.deactivate(); + } + + /** Incrementally builds the given project. + */ + protected void incrementalBuild(IPath projectPath) { + this.debugRequestor.clearResult(); + this.debugRequestor.activate(); + env.incrementalBuild(projectPath); + this.debugRequestor.deactivate(); + } + + /** Incrementally builds the workspace. + */ + protected void incrementalBuild() { + this.debugRequestor.clearResult(); + this.debugRequestor.activate(); + env.incrementalBuild(); + this.debugRequestor.deactivate(); + } + + protected void printProblems() { + printProblemsFor(env.getWorkspaceRootPath()); + } + + protected void printProblemsFor(IPath root) { + printProblemsFor(new IPath[] { root }); + } + + protected void printProblemsFor(IPath[] roots) { + for (int i = 0; i < roots.length; i++) { + IPath path = roots[i]; + + /* get the leaf problems for this type */ + Problem[] problems = env.getProblemsFor(path); + System.out.println(arrayToString(problems)); + System.out.println(); + } + } + + protected String arrayToString(Object[] array) { + StringBuilder buffer = new StringBuilder(); + int length = array == null ? 0 : array.length; + for (int i = 0; i < length; i++) { + if (array[i] != null) { + if (i > 0) buffer.append('\n'); + buffer.append(array[i].toString()); + } + } + return buffer.toString(); + } + + /** Sets up this test. + */ + protected void setUp() throws Exception { + super.setUp(); + + this.debugRequestor = new EfficiencyCompilerRequestor(); + Compiler.DebugRequestor = this.debugRequestor; + if (env == null) { + env = new TestingEnvironment(); + env.openEmptyWorkspace(); + } + env.resetWorkspace(); + + } + /** + * @see junit.framework.TestCase#tearDown() + */ + protected void tearDown() throws Exception { + env.resetWorkspace(); + JavaCore.setOptions(JavaCore.getDefaultOptions()); + super.tearDown(); + } + + /** + * Concatenate and sort all problems for given root paths. + * + * @param roots The path to get the problems + * @return All sorted problems of all given path + */ + Problem[] allSortedProblems(IPath[] roots) { + Problem[] allProblems = null; + for (int i = 0, max=roots.length; i> list = new ArrayList<>(Arrays.asList(classes)); + if (matchesCompliance(F_1_5)) { + list.add(Java50Tests.class); + list.add(PackageInfoTest.class); + list.add(ParticipantBuildTests.class); + list.add(AnnotationDependencyTests.class); + } + if (matchesCompliance(F_1_8)) { + list.add(Bug544921Test.class); + } + if (matchesCompliance(F_9)) { + list.add(LeakTestsAfter9.class); + list.add(Bug549646Test.class); + } + if (matchesCompliance(F_12)) { + list.add(Bug571363Test.class); + } + return list.toArray(new Class[0]); + } + + static boolean matchesCompliance(int level) { + int complianceLevels = getPossibleComplianceLevels(); + return complianceLevels >= level; + } + + public static Test buildTestSuite(Class evaluationTestClass, long ordering) { + TestSuite suite = new TestSuite(evaluationTestClass.getName()); + List tests = buildTestsList(evaluationTestClass, 0, ordering); + for (int index=0, size=tests.size(); index actualProblemMessages = new ArrayList<>(); + Problem[] problems = env.getProblemsFor(project, "org.eclipse.jdt.core.tests.compile.problem"); + if (problems != null) { + for (Problem problem : problems) { + actualProblemMessages.add(problem.getMessage()); + } + } + + List expectedProblemMessages = Arrays.asList(expectedProblemMessage); + assertEquals("expected compile problem not observed", + expectedProblemMessages, actualProblemMessages); + } + + protected static void expectNoCompileProblems(IPath project) { + List actualProblemMessages = new ArrayList<>(); + Problem[] problems = env.getProblemsFor(project, "org.eclipse.jdt.core.tests.compile.problem"); + if (problems != null) { + for (Problem problem : problems) { + actualProblemMessages.add(problem.getMessage()); + } + } + + List expectedProblemMessages = Collections.EMPTY_LIST; + assertEquals("expected no compile problems", + expectedProblemMessages, actualProblemMessages); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java new file mode 100644 index 0000000000..7fa90820ee --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/BuildpathTests.java @@ -0,0 +1,1049 @@ +/******************************************************************************* + * Copyright (c) 2000, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.core.JavaModel; +import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.core.JavaProject; + +import junit.framework.Test; + +@SuppressWarnings({"unchecked", "rawtypes"}) +public class BuildpathTests extends BuilderTests { + +public BuildpathTests(String name) { + super(name); +} + +public static Test suite() { + return buildTestSuite(BuildpathTests.class); +} +@Override +protected void setUp() throws Exception { + this.indexDisabledForTest = false; + super.setUp(); +} + +private String getJdkLevelProblem(String expectedRuntime, String path, int severity) { + Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true); + long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target); + String jclRuntime = CompilerOptions.versionFromJdkLevel(libraryJDK); + StringBuilder jdkLevelProblem = new StringBuilder("Problem : Incompatible .class files version in required binaries. Project 'Project' is targeting a "); + jdkLevelProblem.append(expectedRuntime); + jdkLevelProblem.append(" runtime, but is compiled against '"); + jdkLevelProblem.append(path); + jdkLevelProblem.append("' which requires a "); + jdkLevelProblem.append(jclRuntime); + jdkLevelProblem.append(" runtime [ resource : range : <-1,-1> category : <10> severity : <"); + jdkLevelProblem.append(severity); + jdkLevelProblem.append(">]"); + return jdkLevelProblem.toString(); +} + +public void testClasspathFileChange() throws JavaModelException { + // create project with src folder, and alternate unused src2 folder + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + IPath classTest1 = env.addClass(root, "p1", "Test1", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Test1 extends Zork1 {}" //$NON-NLS-1$ + ); + // not yet on the classpath + IPath src2Path = env.addFolder(projectPath, "src2"); //$NON-NLS-1$ + IPath src2p1Path = env.addFolder(src2Path, "p1"); //$NON-NLS-1$ + env.addFile(src2p1Path, "Zork1.java", //$NON-NLS-1$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Zork1 {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingSpecificProblemFor(classTest1, new Problem("src", "Zork1 cannot be resolved to a type", classTest1,39, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + //---------------------------- + // Step 2 + //---------------------------- + StringBuilder buffer = new StringBuilder("\n"); //$NON-NLS-1$ + buffer.append("\n"); //$NON-NLS-1$ + buffer.append(" \n"); //$NON-NLS-1$ + buffer.append(" \n"); // add src2 on classpath through resource change //$NON-NLS-1$ + String[] classlibs = Util.getJavaClassLibs(); + for (int i = 0; i < classlibs.length; i++) { + buffer.append(" \n"); //$NON-NLS-1$ //$NON-NLS-2$ + } + buffer.append(" \n"); //$NON-NLS-1$ + buffer.append(""); //$NON-NLS-1$ + boolean wasAutoBuilding = env.isAutoBuilding(); + try { + // turn autobuild on + env.setAutoBuilding(true); + // write new .classpath, will trigger autobuild + env.addFile(projectPath, ".classpath", buffer.toString()); //$NON-NLS-1$ + // ensures the builder did see the classpath change + env.waitForAutoBuild(); + expectingNoProblems(); + } finally { + env.setAutoBuilding(wasAutoBuilding); + } +} + +public void testClosedProject() throws JavaModelException, IOException { + IPath project1Path = env.addProject("CP1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath jarPath = addEmptyInternalJar(project1Path, "temp.jar"); + + IPath project2Path = env.addProject("CP2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + + IPath project3Path = env.addProject("CP3"); //$NON-NLS-1$ + env.addExternalJars(project3Path, Util.getJavaClassLibs()); + env.addExternalJar(project3Path, jarPath.toString()); + + fullBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + env.closeProject(project1Path); + + incrementalBuild(); + expectingOnlyProblemsFor(new IPath[] {project2Path, project3Path}); + expectingOnlySpecificProblemsFor(project2Path, + new Problem[] { + new Problem("", "The project cannot be built until build path errors are resolved", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$ + new Problem("Build path", "Project 'CP2' is missing required Java project: 'CP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$ + } + ); + expectingOnlySpecificProblemsFor(project3Path, + new Problem[] { + new Problem("", "The project cannot be built until build path errors are resolved", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$ + new Problem("Build path", "Project 'CP3' is missing required library: '/CP1/temp.jar'", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$ + } + ); + + env.openProject(project1Path); + incrementalBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 3 + //---------------------------- + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.IGNORE); + JavaCore.setOptions(options); + env.closeProject(project1Path); + env.waitForManualRefresh(); + incrementalBuild(); + env.waitForAutoBuild(); + expectingOnlyProblemsFor(new IPath[] {project2Path, project3Path}); + expectingOnlySpecificProblemFor(project2Path, + new Problem("Build path", "Project 'CP2' is missing required Java project: 'CP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$ + ); + expectingOnlySpecificProblemFor(project3Path, + new Problem("Build path", "Project 'CP3' is missing required library: '/CP1/temp.jar'", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$ + ); + + env.openProject(project1Path); + incrementalBuild(); + expectingNoProblems(); + env.removeProject(project1Path); +} + +public void testCorruptBuilder() throws JavaModelException { + IPath project1Path = env.addProject("P1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(project1Path, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;" + //$NON-NLS-1$ + "public class Test {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + + IPath outputFolderPackage = env.getOutputLocation(project1Path).append("p"); //$NON-NLS-1$ + env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$ + + IPath subTest = env.addClass(project1Path, "", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$ + "public class SubTest extends p.Test {}" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingOnlySpecificProblemFor(subTest, new Problem("", "p.Test cannot be resolved to a type", subTest, 29, 35, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$) + + env.addClass(project1Path, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;" + //$NON-NLS-1$ + "public class Test {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.ENABLED); + JavaCore.setOptions(options); + + env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$ + env.waitForManualRefresh(); + incrementalBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + env.removeProject(project1Path); +} + +public void testCorruptBuilder2() throws JavaModelException { + IPath project1Path = env.addProject("P2"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(project1Path, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(project1Path, "src"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(project1Path, "bin"); //$NON-NLS-1$ + + env.addClass(src, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;" + //$NON-NLS-1$ + "public class Test {}" //$NON-NLS-1$ + ); + + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + IPath outputFolderPackage = bin.append("p"); //$NON-NLS-1$ + env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$ + + IPath subTest = env.addClass(src, "p2", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;" + //$NON-NLS-1$ + "public class SubTest extends p.Test {}" //$NON-NLS-1$ + ); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingOnlySpecificProblemFor(subTest, new Problem("", "p.Test cannot be resolved to a type", subTest, 40, 46, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$) + + env.addClass(src, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;" + //$NON-NLS-1$ + "public class Test {}" //$NON-NLS-1$ + ); + + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, JavaCore.ENABLED); + JavaCore.setOptions(options); + + env.removeBinaryClass(outputFolderPackage, "Test"); //$NON-NLS-1$ + env.waitForManualRefresh(); + incrementalBuild(); + expectingNoProblems(); + env.removeProject(project1Path); +} + +/* + * Ensures that changing a type in an external folder and refreshing triggers a rebuild + */ +public void testChangeExternalFolder() throws CoreException { + String externalLib = Util.getOutputDirectory() + File.separator + "externalLib"; + IPath projectPath = env.addProject("Project"); + try { + new File(externalLib).mkdirs(); + Util.compile( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " }\n" + + "}" + }, + new HashMap(), + externalLib + ); + + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.addExternalFolders(projectPath, new String[] {externalLib}); + + IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + env.setOutputFolder(projectPath, ""); + + IPath classY = env.addClass(root, "q", "Y", + "package q;\n"+ + "public class Y {\n" + + " void bar(p.X x) {\n" + + " x.foo();\n" + + " }\n" + + "}" + ); + + fullBuild(projectPath); + env.waitForAutoBuild(); + expectingNoProblems(); + + String externalClassFile = externalLib + File.separator + "p" + File.separator + "X.class"; + long lastModified = new java.io.File(externalClassFile).lastModified(); + try { + Thread.sleep(1000); + } catch(InterruptedException e) { + } + Util.compile( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + "}" + }, + new HashMap(), + externalLib + ); + new java.io.File(externalClassFile).setLastModified(lastModified + 1000); // to be sure its different + + env.getProject(projectPath).refreshLocal(IResource.DEPTH_INFINITE, null); + env.waitForManualRefresh(); + + incrementalBuild(projectPath); + env.waitForAutoBuild(); + expectingProblemsFor( + classY, + "Problem : The method foo() is undefined for the type X [ resource : range : <54,57> category : <50> severity : <2>]" + ); + } finally { + new File(externalLib).delete(); + env.removeProject(projectPath); + } +} + +/* + * Ensures that changing a type in an external ZIP archive and refreshing triggers a rebuild + */ +public void testChangeZIPArchive1() throws Exception { + String externalLib = Util.getOutputDirectory() + File.separator + "externalLib.abc"; + IPath projectPath = env.addProject("Project"); + try { + org.eclipse.jdt.core.tests.util.Util.createJar( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " }\n" + + "}" + }, + externalLib, + "1.4"); + + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.addExternalJars(projectPath, new String[] {externalLib}); + + IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + env.setOutputFolder(projectPath, ""); + + IPath classY = env.addClass(root, "q", "Y", + "package q;\n"+ + "public class Y {\n" + + " void bar(p.X x) {\n" + + " x.foo();\n" + + " }\n" + + "}" + ); + + fullBuild(projectPath); + expectingNoProblems(); + + org.eclipse.jdt.core.tests.util.Util.createJar( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + "}" + }, + externalLib, + "1.4"); + + IJavaProject p = env.getJavaProject(projectPath); + p.getJavaModel().refreshExternalArchives(new IJavaElement[] {p}, null); + + incrementalBuild(projectPath); + expectingProblemsFor( + classY, + "Problem : The method foo() is undefined for the type X [ resource : range : <54,57> category : <50> severity : <2>]" + ); + } finally { + new File(externalLib).delete(); + env.removeProject(projectPath); + } +} + +/* + * Ensures that changing a type in an internal ZIP archive and refreshing triggers a rebuild + */ +public void testChangeZIPArchive2() throws Exception { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + String internalLib = env.getProject("Project").getLocation().toOSString() + File.separator + "internalLib.abc"; + org.eclipse.jdt.core.tests.util.Util.createJar( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " }\n" + + "}" + }, + internalLib, + "1.4"); + env.getProject(projectPath).refreshLocal(IResource.DEPTH_INFINITE, null); + env.addEntry(projectPath, JavaCore.newLibraryEntry(new Path("/Project/internalLib.abc"), null, null)); + + IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + env.setOutputFolder(projectPath, ""); + + IPath classY = env.addClass(root, "q", "Y", + "package q;\n"+ + "public class Y {\n" + + " void bar(p.X x) {\n" + + " x.foo();\n" + + " }\n" + + "}" + ); + + fullBuild(projectPath); + expectingNoProblems(); + + org.eclipse.jdt.core.tests.util.Util.createJar( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + "}" + }, + internalLib, + "1.4"); + + env.getProject(projectPath).refreshLocal(IResource.DEPTH_INFINITE, null); + + incrementalBuild(projectPath); + expectingProblemsFor( + classY, + "Problem : The method foo() is undefined for the type X [ resource : range : <54,57> category : <50> severity : <2>]" + ); + env.removeProject(projectPath); +} + +/* + * Ensures that changing an external jar and refreshing the projects triggers a rebuild + * (regression test for bug 50207 Compile errors fixed by 'refresh' do not reset problem list or package explorer error states) + */ +public void testExternalJarChange() throws JavaModelException, IOException { + // setup + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + IPath classTest = env.addClass(root, "p", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n"+ //$NON-NLS-1$ + "public class X {\n" + //$NON-NLS-1$ + " void foo() {\n" + //$NON-NLS-1$ + " new q.Y().bar();\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + ); + String externalJar = Util.getOutputDirectory() + File.separator + "test.jar"; //$NON-NLS-1$ + Util.createJar( + new String[] { + "q/Y.java", //$NON-NLS-1$ + "package q;\n" + //$NON-NLS-1$ + "public class Y {\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + }, + new HashMap(), + externalJar + ); + env.addExternalJar(projectPath, externalJar); + + // build -> expecting problems + fullBuild(); + expectingProblemsFor( + classTest, + "Problem : The method bar() is undefined for the type Y [ resource : range : <57,60> category : <50> severity : <2>]" + ); + + // fix jar + Util.createJar( + new String[] { + "q/Y.java", //$NON-NLS-1$ + "package q;\n" + //$NON-NLS-1$ + "public class Y {\n" + //$NON-NLS-1$ + " public void bar() {\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + }, + new HashMap(), + externalJar + ); + + // refresh project and rebuild -> expecting no problems + IJavaProject project = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject("Project")); //$NON-NLS-1$ + project.getJavaModel().refreshExternalArchives(new IJavaElement[] {project}, null); + incrementalBuild(); + expectingNoProblems(); + env.removeProject(projectPath); +} + +public void testMissingBuilder() throws JavaModelException { + IPath project1Path = env.addProject("P1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + IPath project2Path = env.addProject("P2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + + env.addClass(project1Path, "", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Test {}" //$NON-NLS-1$ + ); + + IPath sub = env.addClass(project2Path, "", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$ + "public class SubTest extends Test {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + + env.removeRequiredProject(project2Path, project1Path); + + incrementalBuild(); + expectingOnlySpecificProblemFor(sub, new Problem("", "Test cannot be resolved to a type", sub, 29, 33, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$) + + env.addRequiredProject(project2Path, project1Path); + + try { + JavaProject p = (JavaProject) env.getJavaProject(project1Path); + p.deconfigure(); + JavaModelManager.getJavaModelManager().setLastBuiltState(p.getProject(), null); + } catch (CoreException e) { + e.printStackTrace(); + } + + env.addClass(project2Path, "", "SubTest", //$NON-NLS-1$ //$NON-NLS-2$ + "public class SubTest extends Test {}" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + env.removeProject(project1Path); + env.removeProject(project2Path); +} + +public void testMissingFieldType() throws JavaModelException { + IPath projectPath = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + env.addClass(root, "p1", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Test {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + + IPath projectPath2 = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(projectPath2, Util.getJavaClassLibs()); + env.addRequiredProject(projectPath2, projectPath); + IPath root2 = env.getPackageFragmentRootPath(projectPath2, ""); //$NON-NLS-1$ + env.addClass(root2, "p2", "Test2", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Test2 {\n" + //$NON-NLS-1$ + " public static p1.Test field;\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + + IPath projectPath3 = env.addProject("Project3"); //$NON-NLS-1$ + env.addExternalJars(projectPath3, Util.getJavaClassLibs()); + env.addRequiredProject(projectPath3, projectPath2); + IPath root3 = env.getPackageFragmentRootPath(projectPath3, ""); //$NON-NLS-1$ + env.addClass(root3, "p3", "Test3", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class Test3 extends p2.Test2 {\n" + //$NON-NLS-1$ + " static Object field;\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + env.removeProject(projectPath); +} + +public void testMissingLibrary1() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + IPath classTest1 = env.addClass(root, "p1", "Test1", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Test1 {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingOnlyProblemsFor(new IPath[] {projectPath, classTest1}); + expectingOnlySpecificProblemsFor(projectPath, + new Problem[] { + new Problem("", "The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p1", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest1, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$ + } + ); + + //---------------------------- + // Step 2 + //---------------------------- + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + incrementalBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[]{ + bin.append("p1").append("Test1.class"), //$NON-NLS-1$ //$NON-NLS-2$ + }); + env.removeProject(projectPath); +} + +public void testMissingLibrary2() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + IPath classTest1 = env.addClass(root, "p2", "Test1", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Test1 {}" //$NON-NLS-1$ + ); + IPath classTest2 = env.addClass(root, "p2", "Test2", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Test2 {}" //$NON-NLS-1$ + ); + IPath classTest3 = env.addClass(root, "p3", "Test3", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class Test3 {}" //$NON-NLS-1$ + ); + + fullBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor( + projectPath, + new Problem("", "The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + Problem[] prob1 = env.getProblemsFor(classTest1); + Problem[] prob2 = env.getProblemsFor(classTest2); + Problem[] prob3 = env.getProblemsFor(classTest3); + assertEquals("too many problems", prob1.length + prob2.length + prob3.length, 1); //$NON-NLS-1$ + if(prob1.length == 1) { + expectingSpecificProblemFor(classTest1, new Problem("p2", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest1, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + } else if (prob2.length == 1) { + expectingSpecificProblemFor(classTest2, new Problem("p2", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest2, -1, -1, -1, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + } else { + expectingSpecificProblemFor(classTest3, new Problem("p3", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest3, -1, -1, -1, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + //---------------------------- + // Step 2 + //---------------------------- + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[]{ + bin.append("p2").append("Test1.class"), //$NON-NLS-1$ //$NON-NLS-2$ + bin.append("p2").append("Test2.class"), //$NON-NLS-1$ //$NON-NLS-2$ + bin.append("p3").append("Test3.class") //$NON-NLS-1$ //$NON-NLS-2$ + }); + env.removeProject(projectPath); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345 +public void testMissingLibrary3() throws JavaModelException { + this.abortOnFailure = false; // this test is failing on some releng boxes => do not abort on failures + IPath projectPath = env.addProject("Project"); + IJavaProject project = env.getJavaProject(projectPath); + fullBuild(); + expectingNoProblems(); + project.setOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, CompilerOptions.WARNING); + env.waitForManualRefresh(); + env.addLibrary(projectPath, projectPath.append("/lib/dummy.jar"), null, null); + fullBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor( + projectPath, + new Problem("Build path", "Project 'Project' is missing required library: 'lib/dummy.jar'", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, + IMarker.SEVERITY_WARNING)); + project.setOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, CompilerOptions.ERROR); + env.waitForManualRefresh(); + // force classpath change delta - should not have to do this + IClasspathEntry[] classpath = project.getRawClasspath(); + IPath outputLocation; + project.setRawClasspath(null, outputLocation = project.getOutputLocation(), false, null); + project.setRawClasspath(classpath, outputLocation, false, null); + fullBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor( + projectPath, + new Problem("", "The project cannot be built until build path errors are resolved", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); + expectingSpecificProblemFor( + projectPath, + new Problem("Build path", "Project 'Project' is missing required library: 'lib/dummy.jar'", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); + env.removeProject(projectPath); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345 +public void testMissingLibrary4() throws JavaModelException { + this.abortOnFailure = false; // this test is failing on some releng boxes => do not abort on failures + IPath projectPath = env.addProject("Project"); + IJavaProject project = env.getJavaProject(projectPath); + fullBuild(); + expectingNoProblems(); + env.addLibrary(projectPath, projectPath.append("/lib/dummy.jar"), null, null); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor( + projectPath, + new Problem("", "The project cannot be built until build path errors are resolved", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); + expectingSpecificProblemFor( + projectPath, + new Problem("Build path", "Project 'Project' is missing required library: 'lib/dummy.jar'", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); + project.setOption(JavaCore.CORE_INCOMPLETE_CLASSPATH, CompilerOptions.WARNING); + env.waitForManualRefresh(); + incrementalBuild(); + env.waitForManualRefresh(); + expectingSpecificProblemFor( + projectPath, + new Problem("Build path", "Project 'Project' is missing required library: 'lib/dummy.jar'", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, + IMarker.SEVERITY_WARNING)); + env.removeProject(projectPath); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345 +public void testIncompatibleJdkLEvelOnProject() throws JavaModelException { + + // Create project + IPath projectPath = env.addProject("Project"); + IJavaProject project = env.getJavaProject(projectPath); + String[] classlibs = Util.getJavaClassLibs(); + env.addExternalJars(projectPath, classlibs); + Arrays.sort(classlibs); + + // Build it expecting no problem + fullBuild(); + expectingNoProblems(); + + // Build incompatible jdk level problem string + String projectRuntime = project.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true); + + // Change project incompatible jdk level preferences to warning, perform incremental build and expect 1 problem + project.setOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, CompilerOptions.WARNING); + env.waitForManualRefresh(); + incrementalBuild(); + env.waitForAutoBuild(); + long projectRuntimeJDKLevel = CompilerOptions.versionToJdkLevel(projectRuntime); + int max = classlibs.length; + List expectedProblems = new ArrayList(); + for (int i = 0; i < max; i++) { + String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString(); + Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true); + long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target); + if (libraryJDK > projectRuntimeJDKLevel) { + expectedProblems.add(getJdkLevelProblem(projectRuntime, path, IMarker.SEVERITY_WARNING)); + } + } + expectingProblemsFor(projectPath, expectedProblems); + + // Change project incompatible jdk level preferences to error, perform incremental build and expect 2 problems + project.setOption(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, CompilerOptions.ERROR); + env.waitForManualRefresh(); + incrementalBuild(); + env.waitForAutoBuild(); + + expectedProblems = new ArrayList(); + for (int i = 0; i < max; i++) { + String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString(); + Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true); + long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target); + if (libraryJDK > projectRuntimeJDKLevel) { + expectedProblems.add(getJdkLevelProblem(projectRuntime, path, IMarker.SEVERITY_ERROR)); + } + } + expectedProblems.add("Problem : The project cannot be built until build path errors are resolved [ resource : range : <-1,-1> category : <10> severity : <2>]"); + expectingProblemsFor(projectPath, expectedProblems); + + // Remove project to avoid side effect on other tests + env.removeProject(projectPath); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=172345 +public void testIncompatibleJdkLEvelOnWksp() throws JavaModelException { + + // Save preference + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + IEclipsePreferences preferences = manager.getInstancePreferences(); + String incompatibleJdkLevel = preferences.get(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, null); + try { + + // Create project + IPath projectPath = env.addProject("Project"); + IJavaProject project = env.getJavaProject(projectPath); + String[] classlibs = Util.getJavaClassLibs(); + env.addExternalJars(projectPath, classlibs); + + // Build it expecting no problem + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + // Build incompatible jdk level problem string + String wkspRuntime = JavaCore.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); + long wkspRuntimeJDKLevel = CompilerOptions.versionToJdkLevel(wkspRuntime); + // sort classlibs + Arrays.sort(classlibs); + // Change workspace incompatible jdk level preferences to warning, perform incremental build and expect 1 problem + preferences.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, JavaCore.WARNING); + env.waitForManualRefresh(); + incrementalBuild(); + env.waitForAutoBuild(); + List expectedProblems = new ArrayList(); + int max = classlibs.length; + for (int i = 0; i < max; i++) { + String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString(); + Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true); + long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target); + if (libraryJDK > wkspRuntimeJDKLevel) { + expectedProblems.add(getJdkLevelProblem(wkspRuntime, path, IMarker.SEVERITY_WARNING)); + } + } + expectingProblemsFor(projectPath, expectedProblems); + + // Change workspace incompatible jdk level preferences to error, perform incremental build and expect 2 problems + preferences.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, JavaCore.ERROR); + env.waitForManualRefresh(); + incrementalBuild(); + env.waitForAutoBuild(); + expectedProblems = new ArrayList(); + for (int i = 0; i < max; i++) { + String path = project.getPackageFragmentRoot(classlibs[i]).getPath().makeRelative().toString(); + Object target = JavaModel.getTarget(new Path(path).makeAbsolute(), true); + long libraryJDK = org.eclipse.jdt.internal.core.util.Util.getJdkLevel(target); + if (libraryJDK > wkspRuntimeJDKLevel) { + expectedProblems.add(getJdkLevelProblem(wkspRuntime, path, IMarker.SEVERITY_ERROR)); + } + } + expectedProblems.add("Problem : The project cannot be built until build path errors are resolved [ resource : range : <-1,-1> category : <10> severity : <2>]"); + expectingProblemsFor(projectPath, expectedProblems); + + // Remove project to avoid side effect on other tests + env.removeProject(projectPath); + } finally { + // Put back workspace preferences same as before running the test + if (incompatibleJdkLevel == null) { + preferences.remove(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL); + } else { + preferences.put(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL, incompatibleJdkLevel); + } + } +} + +public void testMissingProject() throws JavaModelException { + IPath project1Path = env.addProject("MP1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + IPath project2Path = env.addProject("MP2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + + fullBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + env.removeProject(project1Path); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingOnlyProblemsFor(project2Path); + expectingOnlySpecificProblemsFor(project2Path, + new Problem[] { + new Problem("", "The project cannot be built until build path errors are resolved", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$ + new Problem("Build path", "Project 'MP2' is missing required Java project: 'MP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$ + } + ); + + project1Path = env.addProject("MP1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 3 + //---------------------------- + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.IGNORE); + JavaCore.setOptions(options); + env.waitForManualRefresh(); + env.removeProject(project1Path); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingOnlyProblemsFor(project2Path); + expectingOnlySpecificProblemFor(project2Path, + new Problem("Build path", "Project 'MP2' is missing required Java project: 'MP1'", project2Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$ + ); + + project1Path = env.addProject("MP1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + env.removeProject(project1Path); + env.removeProject(project2Path); +} + +public void testMissingOptionalProject() throws JavaModelException { + IPath project1Path = env.addProject("MP1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + IPath project2Path = env.addProject("MP2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path, true/*optional*/); + + fullBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + env.removeProject(project1Path); + + incrementalBuild(); + expectingNoProblems(); + + project1Path = env.addProject("MP1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + incrementalBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 3 + //---------------------------- + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH, JavaCore.IGNORE); + JavaCore.setOptions(options); + env.waitForManualRefresh(); + env.removeProject(project1Path); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + project1Path = env.addProject("MP1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + incrementalBuild(); + expectingNoProblems(); + env.removeProject(project1Path); + env.removeProject(project2Path); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 +public void test0100() throws JavaModelException { + if (!AbstractCompilerTest.isJRELevel(AbstractCompilerTest.F_1_5)) { + // expected to run only in 1.5 mode on top of a jre 1.5 or above + return; + } + IPath projectPath = env.addProject("P", "1.5"); + IPath defaultPackagePath = env.addPackage(projectPath, ""); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.addClass(defaultPackagePath, "X", + "public interface X {\n" + + " interface Entry {\n" + + " interface Internal extends Entry {\n" + + " Internal createEntry();\n" + + " }\n" + + " }\n" + + "}" + ); + fullBuild(); + expectingNoProblems(); + env.addClass(defaultPackagePath, "Y", + "public class Y implements X.Entry.Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}"); + incrementalBuild(); + expectingNoProblems(); + env.removeProject(projectPath); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=143025 +public void testMissingOutputFolder() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + fullBuild(); + expectingNoProblems(); + + env.removeFolder(bin); + + incrementalBuild(); + expectingNoProblems(); + expectingPresenceOf(bin); // check that bin folder was recreated and is marked as derived + if (!env.getProject(projectPath).getFolder("bin").isDerived()) + fail("output folder is not derived"); + env.removeProject(projectPath); +} +@Override +protected void tearDown() throws Exception { + super.tearDown(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/CopyResourceTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/CopyResourceTests.java new file mode 100644 index 0000000000..58d2a067f3 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/CopyResourceTests.java @@ -0,0 +1,357 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import junit.framework.*; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; + +/** + * Basic tests of the image builder. + */ +@SuppressWarnings({"rawtypes", "unchecked"}) +public class CopyResourceTests extends BuilderTests { + + public CopyResourceTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(CopyResourceTests.class); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=117302 + public void testFilteredResources() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot( + projectPath, + "", //$NON-NLS-1$ + new IPath[] {new org.eclipse.core.runtime.Path("foo/;bar/")}, //$NON-NLS-1$ + new IPath[] {new org.eclipse.core.runtime.Path("foo/ignored/")}, //$NON-NLS-1$ + "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src, "foo", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package foo;"+ //$NON-NLS-1$ + "public class A extends bar.B {}" //$NON-NLS-1$ + ); + env.addClass(src, "bar", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package bar;"+ //$NON-NLS-1$ + "public class B {}" //$NON-NLS-1$ + ); + env.addFolder(src, "foo/skip"); //$NON-NLS-1$ + IPath ignored = env.addFolder(src, "foo/ignored"); //$NON-NLS-1$ + env.addFile(ignored, "test.txt", "test file"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + env.addFile(src.append("bar"), "test.txt", "test file"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + org.eclipse.jdt.core.IJavaProject p = env.getJavaProject("P"); + java.util.Map options = p.getOptions(true); + options.put(org.eclipse.jdt.core.JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, "bar*"); //$NON-NLS-1$ + options.put(org.eclipse.jdt.core.JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER, "enabled"); //$NON-NLS-1$ + p.setOptions(options); + + int max = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + try { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 1; + fullBuild(); + expectingNoProblems(); + expectingNoPresenceOf(projectPath.append("bin/foo/skip/")); //$NON-NLS-1$ + expectingNoPresenceOf(projectPath.append("bin/foo/ignored/")); //$NON-NLS-1$ + expectingNoPresenceOf(projectPath.append("bin/bar/test.txt")); //$NON-NLS-1$ + + env.removeFolder(projectPath.append("bin/bar")); //$NON-NLS-1$ + env.addClass(src, "x", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package x;"+ //$NON-NLS-1$ + "public class A extends bar.B {}" //$NON-NLS-1$ + ); + env.addFile(src.append("bar"), "test.txt", "changed test file"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + incrementalBuild(); + expectingNoProblems(); + expectingNoPresenceOf(projectPath.append("bin/foo/skip/")); //$NON-NLS-1$ + expectingNoPresenceOf(projectPath.append("bin/foo/ignored/")); //$NON-NLS-1$ + expectingNoPresenceOf(projectPath.append("bin/bar/test.txt")); //$NON-NLS-1$ + } finally { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = max; + } + } + + public void testSimpleProject() throws JavaModelException { + IPath projectPath = env.addProject("P1"); //$NON-NLS-1$ + IPath src = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + env.setOutputFolder(projectPath, ""); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addFile(src, "z.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(projectPath.append("z.txt")); //$NON-NLS-1$ + + env.removeFile(src.append("z.txt")); //$NON-NLS-1$ + IPath p = env.addFolder(src, "p"); //$NON-NLS-1$ + env.addFile(p, "p.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + incrementalBuild(); + expectingNoProblems(); + expectingNoPresenceOf(projectPath.append("z.txt")); //$NON-NLS-1$ + expectingPresenceOf(p.append("p.txt")); //$NON-NLS-1$ + } + + public void testProjectWithBin() throws JavaModelException { + IPath projectPath = env.addProject("P2"); //$NON-NLS-1$ + IPath src = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addFile(src, "z.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + projectPath.append("z.txt"), //$NON-NLS-1$ + projectPath.append("bin/z.txt") //$NON-NLS-1$ + }); + + env.removeFile(src.append("z.txt")); //$NON-NLS-1$ + IPath p = env.addFolder(src, "p"); //$NON-NLS-1$ + env.addFile(p, "p.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + incrementalBuild(); + expectingNoProblems(); + expectingNoPresenceOf(new IPath[] { + projectPath.append("z.txt"), //$NON-NLS-1$ + projectPath.append("bin/z.txt") //$NON-NLS-1$ + }); + expectingPresenceOf(new IPath[] { + projectPath.append("p/p.txt"), //$NON-NLS-1$ + projectPath.append("bin/p/p.txt") //$NON-NLS-1$ + }); + } + + public void testProjectWithSrcBin() throws JavaModelException { + IPath projectPath = env.addProject("P3"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addFile(src, "z.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + projectPath.append("src/z.txt"), //$NON-NLS-1$ + projectPath.append("bin/z.txt") //$NON-NLS-1$ + }); + + env.removeFile(src.append("z.txt")); //$NON-NLS-1$ + env.addFile(src, "zz.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + incrementalBuild(); + expectingNoProblems(); + expectingNoPresenceOf(new IPath[] { + projectPath.append("src/z.txt"), //$NON-NLS-1$ + projectPath.append("bin/z.txt") //$NON-NLS-1$ + }); + expectingPresenceOf(new IPath[] { + projectPath.append("src/zz.txt"), //$NON-NLS-1$ + projectPath.append("bin/zz.txt") //$NON-NLS-1$ + }); + } + + public void testProjectWith2SrcBin() throws JavaModelException { + IPath projectPath = env.addProject("P4"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1"); //$NON-NLS-1$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addFile(src1, "z.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + env.addFile(src2, "zz.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + projectPath.append("src1/z.txt"), //$NON-NLS-1$ + projectPath.append("bin/z.txt"), //$NON-NLS-1$ + projectPath.append("src2/zz.txt"), //$NON-NLS-1$ + projectPath.append("bin/zz.txt") //$NON-NLS-1$ + }); + + env.removeFile(src2.append("zz.txt")); //$NON-NLS-1$ + IPath p = env.addFolder(src2, "p"); //$NON-NLS-1$ + env.addFile(p, "p.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + incrementalBuild(); + expectingNoProblems(); + expectingNoPresenceOf(new IPath[] { + projectPath.append("src2/zz.txt"), //$NON-NLS-1$ + projectPath.append("bin/zz.txt") //$NON-NLS-1$ + }); + expectingPresenceOf(new IPath[] { + projectPath.append("src2/p/p.txt"), //$NON-NLS-1$ + projectPath.append("bin/p/p.txt") //$NON-NLS-1$ + }); + } + + public void testProjectWith2SrcAsBin() throws JavaModelException { + IPath projectPath = env.addProject("P5"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1", null, "src1"); //$NON-NLS-1$ //$NON-NLS-2$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2", null, "src2"); //$NON-NLS-1$ //$NON-NLS-2$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addFile(src1, "z.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + env.addFile(src2, "zz.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + projectPath.append("src1/z.txt"), //$NON-NLS-1$ + projectPath.append("src2/zz.txt"), //$NON-NLS-1$ + }); + expectingNoPresenceOf(new IPath[] { + projectPath.append("src2/z.txt"), //$NON-NLS-1$ + projectPath.append("bin") //$NON-NLS-1$ + }); + } + + public void testProjectWith2Src2Bin() throws JavaModelException { + IPath projectPath = env.addProject("P6"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1", null, "bin1"); //$NON-NLS-1$ //$NON-NLS-2$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2", null, "bin2"); //$NON-NLS-1$ //$NON-NLS-2$ + env.setOutputFolder(projectPath, "bin1"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addFile(src1, "z.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + env.addFile(src2, "zz.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + projectPath.append("bin1/z.txt"), //$NON-NLS-1$ + projectPath.append("bin2/zz.txt"), //$NON-NLS-1$ + }); + expectingNoPresenceOf(new IPath[] { + projectPath.append("bin1/zz.txt"), //$NON-NLS-1$ + projectPath.append("bin2/z.txt"), //$NON-NLS-1$ + }); + } + + public void test2ProjectWith1Bin() throws JavaModelException { + IPath projectPath = env.addProject("P7"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + IPath projectPath2 = env.addProject("P8"); //$NON-NLS-1$ + IPath binLocation = env.getProject(projectPath).getFolder("bin").getLocation(); //$NON-NLS-1$ + env.setExternalOutputFolder(projectPath2, "externalBin", binLocation); //$NON-NLS-1$ + env.addExternalJars(projectPath2, Util.getJavaClassLibs()); + + env.addFile(projectPath2, "z.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(bin.append("z.txt")); //$NON-NLS-1$ + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=154693 + public void testBug154693() throws JavaModelException { + IPath projectPath = env.addProject("P9"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + org.eclipse.jdt.core.IJavaProject p = env.getJavaProject("P9"); + java.util.Map options = p.getOptions(true); + options.put(org.eclipse.jdt.core.JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, ".svn/"); //$NON-NLS-1$ + p.setOptions(options); + + IPath folder = env.addFolder(src, "p"); + env.addFolder(folder, ".svn"); + env.addFile(folder, "A.java", "package p;\nclass A{}"); //$NON-NLS-1$ //$NON-NLS-2$ + + fullBuild(); + expectingNoProblems(); + expectingNoPresenceOf(new IPath[] { + projectPath.append("bin/p/.svn") //$NON-NLS-1$ + }); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=194420 + public void testBug194420() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + IPath folder = env.addFolder(src, "p"); + String testContents = "incremental test contents"; //$NON-NLS-1$ + IPath zPath = env.addFile(folder, "z.txt", testContents); //$NON-NLS-1$ + IPath zBinPath = bin.append("p/z.txt"); + org.eclipse.core.resources.IFile zFile = env.getWorkspace().getRoot().getFile(zPath); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(zBinPath); + try { + byte[] contents = new byte[testContents.length()]; + java.io.InputStream stream = zFile.getContents(); + stream.read(contents); + stream.close(); + assumeEquals("File was not copied", testContents, new String(contents)); //$NON-NLS-1$ + } catch (Exception e) { + fail("File was not copied"); //$NON-NLS-1$ + } + + java.io.File file = new java.io.File(zFile.getLocation().toOSString()); + file.delete(); + + fullBuild(); + expectingNoProblems(); + expectingNoPresenceOf(zBinPath); + + testContents = "incremental test contents"; //$NON-NLS-1$ + env.addFile(folder, "z.txt", testContents); //$NON-NLS-1$ + + incrementalBuild(); + expectingNoProblems(); + expectingPresenceOf(zBinPath); + try { + byte[] contents = new byte[testContents.length()]; + java.io.InputStream stream = zFile.getContents(); + stream.read(contents); + stream.close(); + assumeEquals("File was not copied", testContents, new String(contents)); //$NON-NLS-1$ + } catch (Exception e) { + fail("File was not copied"); //$NON-NLS-1$ + } + + env.addFile(folder, "z.txt", "about to be deleted"); //$NON-NLS-1$ //$NON-NLS-2$ + file.delete(); + + incrementalBuild(); + expectingNoProblems(); + expectingNoPresenceOf(zBinPath); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/DependencyTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/DependencyTests.java new file mode 100644 index 0000000000..126c106ec0 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/DependencyTests.java @@ -0,0 +1,1258 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import junit.framework.Test; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.Util; + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class DependencyTests extends BuilderTests { + public DependencyTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(DependencyTests.class); + } + + public void testAbstractMethod() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Indicted", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public abstract class Indicted {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath collaboratorPath = env.addClass(root, "p2", "Collaborator", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Collaborator extends Indicted{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "Indicted", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public abstract class Indicted {\n"+ //$NON-NLS-1$ + " public abstract void foo();\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(collaboratorPath); + expectingOnlySpecificProblemFor(collaboratorPath, new Problem("Collaborator", "The type Collaborator must implement the inherited abstract method Indicted.foo()", collaboratorPath, 38, 50, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=168208 + public void testCaseInvariantType() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + org.eclipse.jdt.core.IJavaProject p = env.getJavaProject("Project"); + java.util.Map options = p.getOptions(true); + options.put(org.eclipse.jdt.core.JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, org.eclipse.jdt.core.JavaCore.DISABLED); //$NON-NLS-1$ + p.setOptions(options); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n" + + " class Node {}\n" + + "}" //$NON-NLS-1$ + ); + + env.addClass(root, "p1", "Bb", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "class Bb {}" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n" + + " class node {}\n" + + "}" //$NON-NLS-1$ + ); + + env.addClass(root, "p1", "Bb", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "class BB {}" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testExactMethodDeleting() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i(int i) {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class C extends p2.B{\n"+ //$NON-NLS-1$ + " int j = i(1);\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath dPath = env.addClass(root, "p3", "D", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class D extends p2.B{\n"+ //$NON-NLS-1$ + " public class M {\n"+ //$NON-NLS-1$ + " int j = i(1);\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p4;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " int foo(p3.C c) { return c.i(1); }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {cPath, dPath, xPath}); + expectingSpecificProblemFor(cPath, new Problem("C", "The method i(int) is undefined for the type C", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(dPath, new Problem("D", "The method i(int) is undefined for the type D.M", dPath, 69, 70, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(xPath, new Problem("X", "The method i(int) is undefined for the type C", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + " protected int i(long l) throws Exception {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {cPath, dPath, xPath}); + expectingSpecificProblemFor(cPath, new Problem("C", "Default constructor cannot handle exception type Exception thrown by implicit super constructor. Must define an explicit constructor", cPath, 50, 54, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(dPath, new Problem("D", "Default constructor cannot handle exception type Exception thrown by implicit super constructor. Must define an explicit constructor", dPath, 69, 73, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(xPath, new Problem("X", "The method i(long) from the type B is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i(int i) {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testExactMethodVisibility() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i() {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class C extends p2.B{\n"+ //$NON-NLS-1$ + " int j = i();\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath dPath = env.addClass(root, "p3", "D", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class D extends p2.B{\n"+ //$NON-NLS-1$ + " public class M {\n"+ //$NON-NLS-1$ + " int j = i();\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p4;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " int foo(p3.C c) { return c.i(); }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " int i() {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {cPath, dPath, xPath}); + expectingSpecificProblemFor(cPath, new Problem("C", "The method i() from the type A is not visible", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(dPath, new Problem("D", "The method i() from the type A is not visible", dPath, 69, 70, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(xPath, new Problem("X", "The method i() from the type A is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " protected int i() {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {xPath}); + expectingSpecificProblemFor(xPath, new Problem("X", "The method i() from the type A is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i() {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testExternalJarChanged() throws CoreException, java.io.IOException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + IPath classTest = env.addClass(root, "p", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n"+ //$NON-NLS-1$ + "public class X {\n" + //$NON-NLS-1$ + " void foo() {\n" + //$NON-NLS-1$ + " new q.Y().bar();\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + ); + String externalJar = Util.getOutputDirectory() + java.io.File.separator + "test.jar"; //$NON-NLS-1$ + Util.createJar( + new String[] { + "q/Y.java", //$NON-NLS-1$ + "package q;\n" + //$NON-NLS-1$ + "public class Y {\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + }, + new java.util.HashMap(), + externalJar + ); + env.addExternalJar(projectPath, externalJar); + + // build -> expecting problems + fullBuild(); + expectingProblemsFor( + classTest, + "Problem : The method bar() is undefined for the type Y [ resource : range : <57,60> category : <50> severity : <2>]" + ); + + // fix jar + Util.createJar( + new String[] { + "q/Y.java", //$NON-NLS-1$ + "package q;\n" + //$NON-NLS-1$ + "public class Y {\n" + //$NON-NLS-1$ + " public void bar() {\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + }, + new java.util.HashMap(), + externalJar + ); + // add new class to trigger an incremental build + env.getProject(projectPath).touch(null); + + // incremental build should notice jar file has changed & do a full build + incrementalBuild(); + expectingNoProblems(); + } + + public void testFieldDeleting() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class C extends p2.B{\n"+ //$NON-NLS-1$ + " int j = i;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p4;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " int foo(p3.C c) { return c.i; }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {cPath, xPath}); + expectingSpecificProblemFor(cPath, new Problem("C", "i cannot be resolved to a variable", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(xPath, new Problem("X", "i cannot be resolved or is not a field", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testFieldVisibility() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class C extends p2.B{\n"+ //$NON-NLS-1$ + " int j = i;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p4;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " int foo(p3.C c) { return c.i; }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " int i;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {cPath, xPath}); + expectingSpecificProblemFor(cPath, new Problem("C", "The field A.i is not visible", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(xPath, new Problem("X", "The field A.i is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " protected int i;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {xPath}); + expectingSpecificProblemFor(xPath, new Problem("X", "The field A.i is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + // 77272 + public void testInterfaceDeleting() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Vehicle", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public interface Vehicle {}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p1", "Car", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public interface Car extends Vehicle {}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p1", "CarImpl", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class CarImpl implements Car {}\n" //$NON-NLS-1$ + ); + + IPath testPath = env.addClass(root, "p1", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Test { public Vehicle createVehicle() { return new CarImpl(); } }\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "Car", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public interface Car {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(testPath); + expectingSpecificProblemFor(testPath, new Problem("Test", "Type mismatch: cannot convert from CarImpl to Vehicle", testPath, 72, 85, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "Car", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public interface Car extends Vehicle {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testMemberTypeDeleting() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public class M { public int i; };\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class C extends p2.B{\n"+ //$NON-NLS-1$ + " M m;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p4;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " int foo(p3.C.M m) { return m.i; }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {cPath, xPath}); + expectingSpecificProblemFor(cPath, new Problem("C", "M cannot be resolved to a type", cPath, 42, 43, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(xPath, new Problem("X", "p3.C.M cannot be resolved to a type", xPath, 38, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public class M { public int i; };\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testMemberTypeVisibility() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public class M { public int i; };\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class C extends p2.B{\n"+ //$NON-NLS-1$ + " M m;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p4;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " int foo(p3.C.M m) { return m.i; }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " class M { public int i; };\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {cPath, xPath}); + expectingSpecificProblemFor(cPath, new Problem("C", "The type M is not visible", cPath, 42, 43, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(xPath, new Problem("X", "The type p3.C.M is not visible", xPath, 38, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " protected class M { public int i; };\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {xPath}); + expectingSpecificProblemFor(xPath, new Problem("X", "The type p3.C.M is not visible", xPath, 38, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public class M { public int i; };\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testMethodDeleting() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i(A a) {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class C extends p2.B{\n"+ //$NON-NLS-1$ + " int j = i(this);\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath dPath = env.addClass(root, "p3", "D", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class D extends p2.B{\n"+ //$NON-NLS-1$ + " public class M {\n"+ //$NON-NLS-1$ + " int j = i(new D());\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p4;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " int foo(p3.C c) { return c.i(c); }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {cPath, dPath, xPath}); + expectingSpecificProblemFor(cPath, new Problem("C", "The method i(C) is undefined for the type C", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(dPath, new Problem("D", "The method i(D) is undefined for the type D.M", dPath, 69, 70, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(xPath, new Problem("X", "The method i(C) is undefined for the type C", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + " public int i(B b) {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i(A a) {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testMethodVisibility() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i(A a) {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class C extends p2.B{\n"+ //$NON-NLS-1$ + " int j = i(this);\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath dPath = env.addClass(root, "p3", "D", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class D extends p2.B{\n"+ //$NON-NLS-1$ + " public class M {\n"+ //$NON-NLS-1$ + " int j = i(new D());\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath xPath = env.addClass(root, "p4", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p4;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " int foo(p3.C c) { return c.i(c); }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " int i(A a) {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {cPath, dPath, xPath}); + expectingSpecificProblemFor(cPath, new Problem("C", "The method i(A) from the type A is not visible", cPath, 50, 51, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(dPath, new Problem("D", "The method i(A) from the type A is not visible", dPath, 69, 70, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(xPath, new Problem("X", "The method i(A) from the type A is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + " protected int i(B b) {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {xPath}); + expectingSpecificProblemFor(xPath, new Problem("X", "The method i(B) from the type B is not visible", xPath, 57, 58, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public int i(A a) {return 1;};\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class B extends A{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testMissingClassFile() throws JavaModelException { + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(project1Path,""); //$NON-NLS-1$ + + IPath root1 = env.addPackageFragmentRoot(project1Path, "src"); //$NON-NLS-1$ + env.setOutputFolder(project1Path, "bin"); //$NON-NLS-1$ + + env.addClass(root1, "p1", "MissingClass", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class MissingClass {}" //$NON-NLS-1$ + ); + + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(project2Path,""); //$NON-NLS-1$ + + IPath root2 = env.addPackageFragmentRoot(project2Path, "src"); //$NON-NLS-1$ + env.setOutputFolder(project2Path, "bin"); //$NON-NLS-1$ + + env.addClass(root2, "p2", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.MissingClass;\n" + + "public class A {\n"+ //$NON-NLS-1$ + " public void foo(MissingClass data) {}\n"+ //$NON-NLS-1$ + " public void foo(String data) {}\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath project3Path = env.addProject("Project3"); //$NON-NLS-1$ + env.addExternalJars(project3Path, Util.getJavaClassLibs()); + env.addRequiredProject(project3Path, project2Path); + // missing required Project1 so MissingClass cannot be found + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(project3Path,""); //$NON-NLS-1$ + + IPath root3 = env.addPackageFragmentRoot(project3Path, "src"); //$NON-NLS-1$ + env.setOutputFolder(project3Path, "bin"); //$NON-NLS-1$ + + IPath bPath = env.addClass(root3, "p3", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "import p2.A;\n" + + "public class B {\n"+ //$NON-NLS-1$ + " public static void main(String[] args) {\n" + //$NON-NLS-1$ + " new A().foo(new String());\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingOnlyProblemsFor(new IPath[] {project3Path, bPath}); + expectingSpecificProblemFor(project3Path, new Problem("Project3", "The project was not built since its build path is incomplete. Cannot find the class file for p1.MissingClass. Fix the build path then try building this project", project3Path, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(bPath, new Problem("B", "The type p1.MissingClass cannot be resolved. It is indirectly referenced from required .class files", bPath, 86, 111, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root2, "p2", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + " public void foo(String data) {}\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + } + + // 181269 + public void testSecondaryTypeDeleting() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A extends Secondary {}\n"+ //$NON-NLS-1$ + "class Secondary {}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + IPath typePath = env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A extends Secondary {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingSpecificProblemFor(typePath, new Problem("A", "Secondary cannot be resolved to a type", typePath, 35, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + // 72468 + public void testTypeDeleting() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {}\n" //$NON-NLS-1$ + ); + + IPath bPath = env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class B extends p1.A{}\n" //$NON-NLS-1$ + ); + + IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class C extends p2.B{}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "class Deleted {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {bPath, cPath}); + expectingSpecificProblemFor(bPath, new Problem("B", "p1.A cannot be resolved to a type", bPath, 35, 39, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(cPath, new Problem("C", "The hierarchy of the type C is inconsistent", cPath, 25, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class B {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + // 72468 + public void testTypeVisibility() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {}\n" //$NON-NLS-1$ + ); + + IPath bPath = env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class B extends p1.A{}\n" //$NON-NLS-1$ + ); + + IPath cPath = env.addClass(root, "p3", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class C extends p2.B{}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "class A {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {bPath, cPath}); + expectingSpecificProblemFor(bPath, new Problem("B", "The type p1.A is not visible", bPath, 35, 39, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(cPath, new Problem("C", "The hierarchy of the type C is inconsistent", cPath, 25, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class B {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class B extends p1.A{}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {bPath, cPath}); + expectingSpecificProblemFor(bPath, new Problem("B", "The type p1.A is not visible", bPath, 35, 39, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(cPath, new Problem("C", "The hierarchy of the type C is inconsistent", cPath, 25, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + // 79163 + public void testTypeVisibility2() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath aPath = env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {\n" + //$NON-NLS-1$ + " void foo() { p2.FooFactory.createFoo().foo(); }\n" + //$NON-NLS-1$ + " void foos() { p2.FooFactory.createFoos().clone(); }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + // Foo & Foos are not public to get visibility problems + env.addClass(root, "p2", "Foo", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "class Foo { public void foo() {} }\n" //$NON-NLS-1$ + ); + env.addClass(root, "p2", "Foos", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "class Foos {}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "FooFactory", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class FooFactory {\n" + //$NON-NLS-1$ + " public static Foo createFoo() { return null; }\n" + //$NON-NLS-1$ + " public static Foos[] createFoos() { return null; }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {aPath}); + expectingSpecificProblemFor(aPath, new Problem("A", "The type Foo is not visible", aPath, 43, 68, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(aPath, new Problem("A", "The type Foos is not visible", aPath, 93, 119, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p2", "Foo", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Foo { public void foo() {} }\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {aPath}); + expectingSpecificProblemFor(aPath, new Problem("A", "The type Foos is not visible", aPath, 93, 119, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p2", "Foos", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Foos { }\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p2", "Foo", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "class Foo { public void foo() {} }\n" //$NON-NLS-1$ + ); + env.addClass(root, "p2", "Foos", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "class Foos {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {aPath}); + expectingSpecificProblemFor(aPath, new Problem("A", "The type Foo is not visible", aPath, 43, 68, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(aPath, new Problem("A", "The type Foos is not visible", aPath, 93, 119, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + public void testTypeVariable() throws JavaModelException { + if ((AbstractCompilerTest.getPossibleComplianceLevels() & AbstractCompilerTest.F_1_5) == 0) return; + + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {}\n" //$NON-NLS-1$ + ); + + IPath bPath = env.addClass(root, "p2", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class B extends p1.A {}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + IPath aPath = env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {bPath}); + expectingSpecificProblemFor(bPath, new Problem("B", "The type A is not generic; it cannot be parameterized with arguments ", bPath, 38, 42, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {aPath, bPath}); + expectingSpecificProblemFor(bPath, new Problem("B", "Bound mismatch: The type T is not a valid substitute for the bounded parameter of the type A", bPath, 43, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(aPath, new Problem("A", "Comparable is a raw type. References to generic type Comparable should be parameterized", aPath, 37, 47, CategorizedProblem.CAT_UNCHECKED_RAW, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class A {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159709 +// Full build and incremental build behave differently for deprecation +// warnings, which is unexpected. Guard test for DeprecatedTest#test015 (the +// builder is not the cause of the bug, but we want to ensure that the end to +// end behavior is OK). +public void test0100() throws JavaModelException { + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + IPath rootPath = env.getPackageFragmentRootPath(projectPath, ""); + env.addClass(rootPath, "a", "N1", + "package a;\n" + + "public class N1 {\n" + + " public void foo() {}\n" + + " /** @deprecated */\n" + + " public class N2 {" + + " public void foo() {}" + + " public class N3 {" + + " public void foo() {}" + + " }" + + " }" + + " void bar() {}\n" + + "}\n" + ); + String M1Contents = + "package p;\n" + + "public class M1 {\n" + + " public void foo() {}\n" + + " /** @deprecated */\n" + + " public class M2 {" + + " public void foo() {}" + + " public class M3 {" + + " public void foo() {}" + + " }" + + " }" + + " void bar() {\n" + + " a.N1.N2.N3 m = null;\n" + + " m.foo();\n" + + " }\n" + + "}\n"; + IPath M1Path = env.addClass(rootPath, "p", "M1", M1Contents); + fullBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {M1Path}); + expectingSpecificProblemFor(M1Path, + new Problem("", "The type N1.N2.N3 is deprecated", + M1Path, 198, 200, CategorizedProblem.CAT_DEPRECATION, IMarker.SEVERITY_WARNING)); + expectingSpecificProblemFor(M1Path, + new Problem("", "The method foo() from the type N1.N2.N3 is deprecated", + M1Path, 217, 222, CategorizedProblem.CAT_DEPRECATION, IMarker.SEVERITY_WARNING)); + M1Path = env.addClass(rootPath, "p", "M1", M1Contents); + incrementalBuild(projectPath); + expectingOnlyProblemsFor(new IPath[] {M1Path}); + expectingSpecificProblemFor(M1Path, + new Problem("", "The type N1.N2.N3 is deprecated", + M1Path, 198, 200, CategorizedProblem.CAT_DEPRECATION, IMarker.SEVERITY_WARNING)); + expectingSpecificProblemFor(M1Path, + new Problem("", "The method foo() from the type N1.N2.N3 is deprecated", + M1Path, 217, 222, CategorizedProblem.CAT_DEPRECATION, IMarker.SEVERITY_WARNING)); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/EfficiencyCompilerRequestor.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/EfficiencyCompilerRequestor.java new file mode 100644 index 0000000000..1a7db581b9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/EfficiencyCompilerRequestor.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.util.ArrayList; +import org.eclipse.jdt.internal.compiler.ClassFile; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.IDebugRequestor; +import org.eclipse.jdt.internal.core.util.Util; + +public class EfficiencyCompilerRequestor implements IDebugRequestor { + private boolean isActive = false; + + private ArrayList compiledClasses = new ArrayList<>(); + private ArrayList compiledFiles = new ArrayList<>(); + private ArrayList classes = new ArrayList<>(); + + + public void acceptDebugResult(CompilationResult result){ + this.compiledFiles.add(new String(result.fileName)); + ClassFile[] classFiles = result.getClassFiles(); + Util.sort(classFiles, new Util.Comparer() { + public int compare(Object a, Object b) { + String aName = new String(((ClassFile)a).fileName()); + String bName = new String(((ClassFile)b).fileName()); + return aName.compareTo(bName); + } + }); + for (int i = 0; i < classFiles.length; i++) { + ClassFile c = classFiles[i]; + this.classes.add(c); + String className = new String(c.fileName()); + this.compiledClasses.add(className.replace('/', '.')); + } + } + + String[] getCompiledClasses(){ + return this.compiledClasses.toArray(new String[this.compiledClasses.size()]); + } + + String[] getCompiledFiles(){ + return this.compiledFiles.toArray(new String[this.compiledFiles.size()]); + } + public ClassFile[] getClassFiles() { + return this.classes.toArray(new ClassFile[this.classes.size()]); + } + + public void clearResult(){ + this.compiledClasses.clear(); + this.compiledFiles.clear(); + this.classes.clear(); + } + + public void reset() { + // do nothing by default + } + + public void activate() { + this.isActive = true; + } + + public void deactivate() { + this.isActive = false; + } + + public boolean isActive() { + return this.isActive; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/EfficiencyTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/EfficiencyTests.java new file mode 100644 index 0000000000..02237c6eae --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/EfficiencyTests.java @@ -0,0 +1,415 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import junit.framework.*; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; + +/** + * Basic efficiency tests of the image builder. + */ +public class EfficiencyTests extends BuilderTests { + public EfficiencyTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(EfficiencyTests.class); + } + + public void testProjectAsClassFolder() throws JavaModelException { + IPath projectPath1 = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(projectPath1, Util.getJavaClassLibs()); + + IPath projectPath2 = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(projectPath2, Util.getJavaClassLibs()); + env.addClassFolder(projectPath2, projectPath1, false); + + env.addClass(projectPath2, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public abstract class X {}\n" //$NON-NLS-1$ + ); + + env.addClass(projectPath2, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Y {}\n" //$NON-NLS-1$ + ); + + fullBuild(); + + env.addClass(projectPath2, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath2); + + // if a full build happens instead of an incremental, then both types will be recompiled + expectingCompiledClasses(new String[]{"p1.X"}); //$NON-NLS-1$ + } + + public void testEfficiency() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Indicted", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public abstract class Indicted {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "Collaborator", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Collaborator extends Indicted{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + + env.addClass(root, "p1", "Indicted", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public abstract class Indicted {\n"+ //$NON-NLS-1$ + " public abstract void foo();\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + expectingCompiledClasses(new String[]{"p2.Collaborator", "p1.Indicted"}); //$NON-NLS-1$ //$NON-NLS-2$ + expectingCompilingOrder(new String[] { "/Project/src/p1/Indicted.java", "/Project/src/p2/Collaborator.java" }); + } + + public void testMethodAddition() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Y extends X{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Z{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void bar(){} \n" + //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " }; \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + expectingCompiledClasses(new String[]{"p1.X", "p2.Y"}); //$NON-NLS-1$ //$NON-NLS-2$ + expectingCompilingOrder(new String[] { "/Project/src/p1/X.java", "/Project/src/p2/Y.java" }); + } + + public void testLocalTypeAddition() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Y extends X{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Z{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " new Object(){ \n" + //$NON-NLS-1$ + " }; \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + expectingCompiledClasses(new String[]{"p1.X", "p1.X$1"}); //$NON-NLS-1$ //$NON-NLS-2$ + expectingCompilingOrder(new String[] { "/Project/src/p1/X.java" }); + } + + public void testLocalTypeAddition2() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " new X(){ \n" + //$NON-NLS-1$ + " void bar(){} \n" + //$NON-NLS-1$ + " }; \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Y extends X{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Z{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " new Object(){ \n" + //$NON-NLS-1$ + " }; \n" + //$NON-NLS-1$ + " new X(){ \n" + //$NON-NLS-1$ + " void bar(){} \n" + //$NON-NLS-1$ + " }; \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + expectingCompiledClasses(new String[]{"p1.X", "p1.X$1", "p1.X$2"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + expectingCompilingOrder(new String[] { "/Project/src/p1/X.java" }); + } + + public void testLocalTypeRemoval() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " new Object(){ \n" + //$NON-NLS-1$ + " }; \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Y extends X{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Z{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + expectingCompiledClasses(new String[]{"p1.X"}); //$NON-NLS-1$ + expectingCompilingOrder(new String[] { "/Project/src/p1/X.java" }); + } + + public void testLocalTypeRemoval2() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " new Object(){ \n" + //$NON-NLS-1$ + " }; \n" + //$NON-NLS-1$ + " new X(){ \n" + //$NON-NLS-1$ + " void bar(){} \n" + //$NON-NLS-1$ + " }; \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Y extends X{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Z{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " new X(){ \n" + //$NON-NLS-1$ + " void bar(){} \n" + //$NON-NLS-1$ + " }; \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + expectingCompiledClasses(new String[]{"p1.X", "p1.X$1"}); //$NON-NLS-1$ //$NON-NLS-2$ + expectingCompilingOrder(new String[] { "/Project/src/p1/X.java" }); + } + // http://dev.eclipse.org/bugs/show_bug.cgi?id=196200 - variation + public void testMissingType001() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo(p2.Y y) { \n" + //$NON-NLS-1$ + " y.bar(null);" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.addClass(root, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Y {\n"+ //$NON-NLS-1$ + " public void bar(Z z) {}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + fullBuild(projectPath); + + env.addClass(root, "p2", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Z {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + expectingCompiledClasses(new String[]{"p1.X", "p2.Y","p2.Z"}); //$NON-NLS-1$ //$NON-NLS-2$ + expectingCompilingOrder( + new String[] { "/Project/src/p2/Z.java", "/Project/src/p2/Y.java", "/Project/src/p1/X.java" }); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java new file mode 100644 index 0000000000..6d698defc8 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ErrorsTests.java @@ -0,0 +1,648 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Hashtable; + +import junit.framework.Test; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IRegion; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.IMethodInfo; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.core.builder.JavaBuilder; + + +/** + * Basic errors tests of the image builder. + */ +@SuppressWarnings({"rawtypes", "unchecked"}) +public class ErrorsTests extends BuilderTests { + private static final IClasspathAttribute ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE = JavaCore.newClasspathAttribute(IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, "true"); + + private static final Comparator COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + IResource resource1 = (IResource) o1; + IResource resource2 = (IResource) o2; + String path1 = resource1.getFullPath().toString(); + String path2 = resource2.getFullPath().toString(); + int length1 = path1.length(); + int length2 = path2.length(); + + if (length1 != length2) { + return length1 - length2; + } + return path1.toString().compareTo(path2.toString()); + } + }; + + public ErrorsTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(ErrorsTests.class); + } + + public void testErrors() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Indicted", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public abstract class Indicted {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + IPath collaboratorPath = env.addClass(root, "p2", "Collaborator", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.*;\n"+ //$NON-NLS-1$ + "public class Collaborator extends Indicted{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p1", "Indicted", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public abstract class Indicted {\n"+ //$NON-NLS-1$ + " public abstract void foo();\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + expectingOnlyProblemsFor(collaboratorPath); + expectingOnlySpecificProblemFor(collaboratorPath, new Problem("Collaborator", "The type Collaborator must implement the inherited abstract method Indicted.foo()", collaboratorPath, 38, 50, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /* + * Regression test for bug 2857 Renaming .java class with errors to .txt leaves errors in Task list (1GK06R3) + */ + public void testRenameToNonJava() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath,""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath cuPath = env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X extends Y {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(projectPath); + expectingOnlyProblemsFor(cuPath); + expectingOnlySpecificProblemFor(cuPath, new Problem("X", "Y cannot be resolved to a type", cuPath, 35, 36, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + + env.renameCU(root.append("p1"), "X.java", "X.txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + incrementalBuild(projectPath); + expectingNoProblems(); + } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test0100() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + IPath classTest1 = env.addClass(root, "p1", "Test1", + "package p1;\n" + + "public class Test1 extends Test2 {}" + ); + fullBuild(); + Problem[] prob1 = env.getProblemsFor(classTest1); + expectingSpecificProblemFor(classTest1, new Problem("p1", "Test2 cannot be resolved to a type", classTest1, 39, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); + assertEquals(JavaBuilder.SOURCE_ID, prob1[0].getSourceId()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test0101() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + IPath classTest1 = env.addClass(root, "p1", "Test1", + "package p1;\n" + + "public class Test1 extends {}" + ); + fullBuild(); + Problem[] prob1 = env.getProblemsFor(classTest1); + expectingSpecificProblemFor(classTest1, new Problem("p1", "Syntax error on token \"extends\", Type expected after this token", classTest1, 31, 38, CategorizedProblem.CAT_SYNTAX, IMarker.SEVERITY_ERROR)); + assertEquals(JavaBuilder.SOURCE_ID, prob1[0].getSourceId()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test0102() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + IPath classTest1 = env.addClass(root, "p1", "Test1", + "package p1;\n" + + "public class Test1 {\n" + + " private static int i;\n" + + " int j = i;\n" + + "}\n" + + "class Test2 {\n" + + " static int i = Test1.i;\n" + + "}\n" + ); + fullBuild(); + Problem[] prob1 = env.getProblemsFor(classTest1); + expectingSpecificProblemFor(classTest1, new Problem("p1", "The field Test1.i is not visible", classTest1, 109, 110, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); + assertEquals(JavaBuilder.SOURCE_ID, prob1[0].getSourceId()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test0103() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + IPath classTest1 = env.addClass(root, "p1", "Test1", + "package p1;\n" + + "public class Test1 {\n" + + " // TODO: marker only\n" + + "}\n" + ); + fullBuild(); + Problem[] prob1 = env.getProblemsFor(classTest1); + expectingSpecificProblemFor(classTest1, new Problem("p1", "TODO: marker only", classTest1, 38, 55, -1, IMarker.SEVERITY_ERROR)); + assertEquals(JavaBuilder.SOURCE_ID, prob1[0].getSourceId()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test0104() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + IPath classTest1 = env.addClass(root, "p1", "Test1", + "package p1;\n" + + "public class Test1 {}" + ); + fullBuild(); + Problem[] prob1 = env.getProblemsFor(classTest1); + expectingSpecificProblemFor(classTest1, + new Problem("p1", "The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files", classTest1, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); + assertEquals(JavaBuilder.SOURCE_ID, prob1[0].getSourceId()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97998 +// Improving the error message in case of a read-only file in output +// directory. Beware: this test only works under Linux - execution on other +// platforms always succeeds, but the result is not significant. +public void _test0105() throws JavaModelException, CoreException, IOException { // FIXME: re-enable! + if ("Linux".equals(System.getProperty("os.name"))) { + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + IPath root = env.getPackageFragmentRootPath(projectPath, ""); + IPath outputFolderPath = env.getOutputLocation(projectPath); + File outputFolder = env.getWorkspaceRootPath().append(outputFolderPath).toFile(); + env.addClass(root, "p1", + "X", + "package p1;\n" + + "public class X {\n" + + "}\n" + ); + try { + fullBuild(projectPath); + expectingNoProblems(); + outputFolder.setReadOnly(); + // outputFolder.setReadable(false); + // PREMATURE no appropriate solution for Windows/NTFS/JDK 1.4 + System.err.println("\n\n=== EXPECTED EXCEPTION ========================================================="); + System.err.println("ErrorsTests#test0105 will emit an expected exception below"); + cleanBuild(); + System.err.println("=== END OF EXPECTED EXCEPTION ==================================================\n\n"); + expectingOnlySpecificProblemFor(env.getWorkspaceRootPath(), + new Problem("", + "The project was not built due to \"Could not delete \'" + + env.getWorkspaceRootPath() + "/P/bin/.classpath\'.\". " + + "Fix the problem, then try refreshing this project and building " + + "it since it may be inconsistent", projectPath, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)); + } finally { + // waiting for JDK 6: outputFolder.setWritable(true); -- workaround: + Process process = null; + try { + process = Runtime.getRuntime().exec("chmod -R a+w " + outputFolder.getAbsolutePath()); + process.waitFor(); + } catch (InterruptedException e) { + // go ahead + } finally { + if (process != null) { + process.destroy(); + } + } + } + try { + cleanBuild(); + expectingNoProblems(); + } catch (Throwable t) { + Process process = null; + try { + process = Runtime.getRuntime().exec("chmod -R a+w " + outputFolder.getAbsolutePath()); + process.waitFor(); + } catch (InterruptedException ie) { + // go ahead + } finally { + if (process != null) { + process.destroy(); + } + } + fail(t.getMessage()); + } + } +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=224715 +public void test0106() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src", null, null); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath classTest1 = env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X implements I {\n" + + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p1", "I", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public interface I {\n" + + " public void foo() {\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + expectingSpecificProblemFor(classTest1, new Problem("p1", "The type X must implement the inherited abstract method I.foo()", classTest1, 25, 26, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); + + IJavaProject project = env.getJavaProject(projectPath); + IRegion region = JavaCore.newRegion(); + region.add(project); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/I.class\n" + + "/Project/bin/p1/X.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + assertEquals("Wrong type", IResource.FILE, resources[1].getType()); + IFile classFile = (IFile) resources[1]; + IClassFileReader classFileReader = null; + InputStream stream = null; + try { + stream = classFile.getContents(); + classFileReader = ToolFactory.createDefaultClassFileReader(stream, IClassFileReader.ALL); + } catch (CoreException e) { + e.printStackTrace(); + } finally { + if (stream != null) { + try { + stream.close(); + } catch(IOException e) { + // ignore + } + } + } + assertNotNull("No class file reader", classFileReader); + IMethodInfo[] methodInfos = classFileReader.getMethodInfos(); + IMethodInfo found = null; + loop: for (int i = 0, max = methodInfos.length; i < max; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if (CharOperation.equals(methodInfo.getName(), "foo".toCharArray())) { + found = methodInfo; + break loop; + } + } + assertNotNull("No method found", found); + assertTrue("Not a synthetic method", found.isSynthetic()); + env.removeProject(projectPath); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=225563 +public void test0107() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src", null, null); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath classTest1 = env.addClass(root, "", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "public class C implements None {\n" + + " public String toString(Arg a) {\n" + + " return null;\n" + + " }\n" + + " public String toString(Arg[] a) {\n" + + " return null;\n" + + " }\n" + + "}" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + expectingOnlySpecificProblemsFor(classTest1, new Problem[] { + new Problem("", "None cannot be resolved to a type", classTest1, 26, 30, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR), + new Problem("", "Arg cannot be resolved to a type", classTest1, 64, 67, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR), + new Problem("", "Arg cannot be resolved to a type", classTest1, 143, 146, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR) + }); + + IJavaProject project = env.getJavaProject(projectPath); + IRegion region = JavaCore.newRegion(); + region.add(project); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 1, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/C.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + assertEquals("Wrong type", IResource.FILE, resources[0].getType()); + IFile classFile = (IFile) resources[0]; + InputStream stream = null; + try { + stream = classFile.getContents(); + ClassFileReader.read(stream, "C.java"); + } catch (Exception e) { + e.printStackTrace(); + assertTrue("Should not happen", false); + } finally { + if (stream != null) { + try { + stream.close(); + } catch(IOException e) { + // ignore + } + } + } +} +private String getResourceOuput(IResource[] resources) { + StringWriter stringWriter = new StringWriter(); + PrintWriter writer = new PrintWriter(stringWriter); + for (int i = 0, max = resources.length; i < max; i++) { + writer.println(resources[i].getFullPath().toString()); + } + writer.flush(); + writer.close(); + return Util.convertToIndependantLineDelimiter(String.valueOf(stringWriter)); +} + +// ignore optional errors +public void test0108() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + env.setOutputFolder(projectPath, "bin"); + IPath root = new Path("/P/src"); + env.addEntry(projectPath, JavaCore.newSourceEntry(root, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + + env.addClass(root, "p", "X", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingNoProblems(); + + JavaCore.setOptions(options); +} + +// two different source folders ignore only from one +public void test0109() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + env.setOutputFolder(projectPath, "bin"); + IPath src = new Path("/P/src"); + IPath src2 = new Path("/P/src2"); + env.addEntry(projectPath, JavaCore.newSourceEntry(src, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + env.addEntry(projectPath, JavaCore.newSourceEntry(src2)); + + env.addClass(src, "p", "X", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + + IPath classY = env.addClass(src2, "q", "Y", + "package q;\n" + + "public class Y {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingNoProblemsFor(src); + expectingOnlySpecificProblemFor(classY, new Problem("q", "The value of the local variable i is not used", classY, 55, 56, CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_ERROR)); + + JavaCore.setOptions(options); +} + +// two different source folders ignore from both +public void test0110() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + env.setOutputFolder(projectPath, "bin"); + IPath src = new Path("/P/src"); + IPath src2 = new Path("/P/src2"); + env.addEntry(projectPath, JavaCore.newSourceEntry(src, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + env.addEntry(projectPath, JavaCore.newSourceEntry(src2, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + + env.addClass(src, "p", "X", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + + env.addClass(src2, "q", "Y", + "package q;\n" + + "public class Y {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingNoProblems(); + + JavaCore.setOptions(options); +} + +//non-optional errors cannot be ignored +public void test0111() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + env.setOutputFolder(projectPath, "bin"); + IPath root = new Path("/P/src"); + env.addEntry(projectPath, JavaCore.newSourceEntry(root, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + + IPath classX = env.addClass(root, "p", "X", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + " public void bar() {\n" + + " a++;\n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingOnlySpecificProblemFor(classX, new Problem("p", "a cannot be resolved to a variable", classX, 84, 85, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); + + JavaCore.setOptions(options); +} + +//task tags cannot be ignored +public void test0112() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + newOptions.put(JavaCore.COMPILER_TASK_TAGS, "TODO"); + newOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL"); + + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("P"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + env.setOutputFolder(projectPath, "bin"); + IPath root = new Path("/P/src"); + env.addEntry(projectPath, JavaCore.newSourceEntry(root, null, null, + null, new IClasspathAttribute[] { ATTR_IGNORE_OPTIONAL_PROBLEMS_TRUE })); + + IPath classX = env.addClass(root, "p", "X", + "package p;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int i;\n" + + " }\n" + + " public void bar() {\n" + + " // TODO nothing\n" + + " }\n" + + "}"); + + fullBuild(projectPath); + expectingOnlySpecificProblemFor(classX, new Problem("p", "TODO nothing", classX, 87, 99, -1, IMarker.SEVERITY_ERROR)); + + JavaCore.setOptions(options); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ExecutionTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ExecutionTests.java new file mode 100644 index 0000000000..0cc33c5ca5 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ExecutionTests.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import junit.framework.*; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; + +/** + * Basic execution tests of the image builder. + */ +public class ExecutionTests extends BuilderTests { + public ExecutionTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(ExecutionTests.class); + } + + public void testSuccess() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.print(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + executeClass(projectPath, "p1.Hello", "Hello world", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + public void testFailure() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath helloPath = env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\")\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + // public static void main(String args[]) { + // System.out.println("Hello world") <-- missing ";" + // } + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(helloPath); + executeClass(projectPath, "p1.Hello", "", //$NON-NLS-1$ //$NON-NLS-2$ + "java.lang.Error: Unresolved compilation problem: \n" + //$NON-NLS-1$ + " Syntax error, insert \";\" to complete BlockStatements\n" //$NON-NLS-1$ + ); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/FriendDependencyTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/FriendDependencyTests.java new file mode 100644 index 0000000000..0f8cdc472a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/FriendDependencyTests.java @@ -0,0 +1,325 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import junit.framework.Test; + +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; +import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.core.builder.ReferenceCollection; +import org.eclipse.jdt.internal.core.builder.State; +import org.eclipse.jdt.internal.core.builder.StringSet; + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class FriendDependencyTests extends BuilderTests { + + public FriendDependencyTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(FriendDependencyTests.class); + } +// this is a compilation only test to verify that this method still exists since API Tooling is using it +public void testIncludes() { + try { + State state = (State) JavaModelManager.getJavaModelManager().getLastBuiltState(null, null); + Map references = state.getReferences(); + ReferenceCollection r = references.values().iterator().next(); + char[][][] qualifiedNames = null; + char[][] simpleNames = null; + char[][] rootNames = null; + r.includes(qualifiedNames, simpleNames, rootNames); + } catch (NullPointerException e) { + // expected + } +} + +// this is a compilation only test to verify that this method still exists since API Tooling is using it +public void testInternSimpleNames() { + ReferenceCollection.internSimpleNames(new StringSet(1), true); + + try { + String className = "org.eclipse.jdt.internal.core.builder.ReferenceCollection"; + Class clazz = Class.forName(className); + //org.eclipse.jdt.internal.core.JavaModelManager.getLastBuiltState(IProject, IProgressMonitor) + Class[] arguments = new Class[2]; + String argumentClassName = "org.eclipse.jdt.internal.core.builder.StringSet"; + arguments[0] = Class.forName(argumentClassName); + arguments[1] = Boolean.TYPE; + clazz.getDeclaredMethod("internSimpleNames", arguments); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} + +//this is a compilation only test to verify that this method still exists since API Tooling is using it +public void testInternQualifiedNames() { + ReferenceCollection.internQualifiedNames(new StringSet(1)); + + try { + String className = "org.eclipse.jdt.internal.core.builder.ReferenceCollection"; + Class clazz = Class.forName(className); + //org.eclipse.jdt.internal.core.JavaModelManager.getLastBuiltState(IProject, IProgressMonitor) + Class[] arguments = new Class[1]; + String argumentClassName = "org.eclipse.jdt.internal.core.builder.StringSet"; + arguments[0] = Class.forName(argumentClassName); + clazz.getDeclaredMethod("internQualifiedNames", arguments); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} +//this is a compilation only test to verify that this method still exists since API Tooling is using it +public void testGetReferences() { + try { + State state = (State) JavaModelManager.getJavaModelManager().getLastBuiltState(null, null); + state.getReferences(); + } catch (NullPointerException e) { + // expected + } + try { + String className = "org.eclipse.jdt.internal.core.builder.State"; + Class clazz = Class.forName(className); + clazz.getDeclaredMethod("getReferences", new Class[0]); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} +//this is a compilation only test to verify that this method still exists since API Tooling is using it +public void testStringSetAdd() { + StringSet s = new StringSet(3); + s.add(""); + + try { + String className = "org.eclipse.jdt.internal.core.builder.StringSet"; + Class clazz = Class.forName(className); + Class[] arguments = new Class[1]; + String argumentClassName = "java.lang.String"; + arguments[0] = Class.forName(argumentClassName); + clazz.getDeclaredMethod("add", arguments); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} +//this is a compilation only test to verify that this method still exists since API Tooling is using it +public void testStringSetclear() { + StringSet s = new StringSet(3); + s.clear(); + + try { + String className = "org.eclipse.jdt.internal.core.builder.StringSet"; + Class clazz = Class.forName(className); + clazz.getDeclaredMethod("clear", new Class[0]); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} +//this is a compilation only test to verify that this method still exists since API Tooling is using it +public void testStringSetNew() { + new StringSet(3); + + try { + String className = "org.eclipse.jdt.internal.core.builder.StringSet"; + Class clazz = Class.forName(className); + Class[] arguments = new Class[1]; + arguments[0] = Integer.TYPE; + clazz.getDeclaredConstructor(arguments); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} +//this is a compilation only test to verify that this field still exists since API Tooling is using it +public void testStringSetElementSize() { + StringSet s = new StringSet(3); + assertEquals("Not expected", 0, s.elementSize); + + try { + String className = "org.eclipse.jdt.internal.core.builder.StringSet"; + Class clazz = Class.forName(className); + clazz.getDeclaredField("elementSize"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} +//this is a compilation only test to verify that this field still exists since API Tooling is using it +public void testSimpleLookupTableKeyTable() { + SimpleLookupTable t = new SimpleLookupTable(3); + assertNotNull("Null", t.keyTable); + + try { + String className = "org.eclipse.jdt.internal.compiler.util.SimpleLookupTable"; + Class clazz = Class.forName(className); + clazz.getDeclaredField("keyTable"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} +//this is a compilation only test to verify that this field still exists since API Tooling is using it +public void testSimpleLookupTableValueTable() { + SimpleLookupTable t = new SimpleLookupTable(3); + assertNotNull("Null", t.valueTable); + + try { + String className = "org.eclipse.jdt.internal.compiler.util.SimpleLookupTable"; + Class clazz = Class.forName(className); + clazz.getDeclaredField("valueTable"); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} +//this is a compilation only test to verify that this method still exists since API Tooling is using it +public void testJavaModelManagerGetJavaModelManager() { + JavaModelManager.getJavaModelManager(); + try { + String className = "org.eclipse.jdt.internal.core.JavaModelManager"; + Class clazz = Class.forName(className); + clazz.getDeclaredMethod("getJavaModelManager", new Class[0]); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} +//this is a compilation only test to verify that this method still exists since API Tooling is using it +public void testJavaModelManagerGetLastBuiltState() { + try { + JavaModelManager.getJavaModelManager().getLastBuiltState(null, null); + } catch (NullPointerException e) { + // expected + } + try { + String className = "org.eclipse.jdt.internal.core.JavaModelManager"; + Class clazz = Class.forName(className); + //org.eclipse.jdt.internal.core.JavaModelManager.getLastBuiltState(IProject, IProgressMonitor) + Class[] arguments = new Class[2]; + String argumentClassName = "org.eclipse.core.resources.IProject"; + String argumentClassName2 = "org.eclipse.core.runtime.IProgressMonitor"; + arguments[0] = Class.forName(argumentClassName); + arguments[1] = Class.forName(argumentClassName2); + clazz.getDeclaredMethod("getLastBuiltState", arguments); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (SecurityException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + assertTrue("Should be there", false); + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/GetResourcesTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/GetResourcesTests.java new file mode 100644 index 0000000000..9ddf18f728 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/GetResourcesTests.java @@ -0,0 +1,1018 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.Comparator; + +import junit.framework.Test; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.IRegion; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; + +/** + * Basic tests of {@link JavaCore#getGeneratedResources(IRegion, boolean)}. + */ +@SuppressWarnings({"rawtypes", "unchecked"}) +public class GetResourcesTests extends BuilderTests { + + private static final Comparator COMPARATOR = new Comparator() { + public int compare(Object o1, Object o2) { + IResource resource1 = (IResource) o1; + IResource resource2 = (IResource) o2; + String path1 = resource1.getFullPath().toString(); + String path2 = resource2.getFullPath().toString(); + int length1 = path1.length(); + int length2 = path2.length(); + + if (length1 != length2) { + return length1 - length2; + } + return path1.toString().compareTo(path2.toString()); + } + }; + + public GetResourcesTests(String name) { + super(name); + } + + static { +// TESTS_NUMBERS = new int[] { 15 }; + } + + public static Test suite() { + return buildTestSuite(GetResourcesTests.class); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test001() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + ICompilationUnit compilationUnit = packageFragment.getCompilationUnit("Hello.java");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(compilationUnit); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 1, resources.length);//$NON-NLS-1$ + String actualOutput = getResourceOuput(resources); + String expectedOutput = "/Project/bin/p1/Hello.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test002() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n"+ //$NON-NLS-1$ + " Object foo() {\n" + //$NON-NLS-1$ + " return new Object() {};\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + ICompilationUnit compilationUnit = packageFragment.getCompilationUnit("Hello.java");//$NON-NLS-1$ + + IRegion region = JavaCore.newRegion(); + region.add(compilationUnit); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$1.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test003() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n"+ //$NON-NLS-1$ + " Object foo() {\n" + + " if(false) {\n" + //$NON-NLS-1$ + " return new Object() {};\n" + + " }\n" + + " return null;\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + ICompilationUnit compilationUnit = packageFragment.getCompilationUnit("Hello.java");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(compilationUnit); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 1, resources.length);//$NON-NLS-1$ + String actualOutput = getResourceOuput(resources); + String expectedOutput = "/Project/bin/p1/Hello.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test004() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n"+ //$NON-NLS-1$ + " Object foo() {\n" + + " return new Object() {};\n" + + " }\n" + //$NON-NLS-1$ + " Object foo2() {\n" + + " return new Object() {};\n" + + " }\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + ICompilationUnit compilationUnit = packageFragment.getCompilationUnit("Hello.java");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(compilationUnit); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 3, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$1.class\n" + + "/Project/bin/p1/Hello$2.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test005() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "a", "Anon", //$NON-NLS-1$ //$NON-NLS-2$ + "package a;\n" + + "\n" + + "public class Anon {\n" + + "\n" + + " Anon() {\n" + + " Object o1 = new Object() {\n" + + " public String toString() {\n" + + " return \"1\"; // a/Anon$3 in 1.5, a/Anon$11 in 1.4\n" + + " }\n" + + " };\n" + + " Object o2 = new Object() {\n" + + " public String toString() {\n" + + " return \"2\"; // a/Anon$4 in 1.5, a/Anon$12 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " void hello() {\n" + + " Object o3 = new Object() {\n" + + " public String toString() {\n" + + " return \"3\"; // a/Anon$5 in 1.5, a/Anon$13 in 1.4\n" + + " }\n" + + " };\n" + + " Object o4 = new Object() {\n" + + " public String toString() {\n" + + " return \"4\"; // a/Anon$6 in 1.5, a/Anon$14 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " static void hello2() {\n" + + " Object o5 = new Object() {\n" + + " public String toString() {\n" + + " return \"5\"; // a/Anon$7 in 1.5, a/Anon$15 in 1.4\n" + + " }\n" + + " };\n" + + " Object o6 = new Object() {\n" + + " public String toString() {\n" + + " return \"6\"; // a/Anon$8 in 1.5, a/Anon$16 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " static {\n" + + " Object o7 = new Object() {\n" + + " public String toString() {\n" + + " return \"7\"; // a/Anon$1 in 1.5, a/Anon$1 in 1.4\n" + + " }\n" + + " };\n" + + "\n" + + " Object o8 = new Object() {\n" + + " public String toString() {\n" + + " return \"8\"; // a/Anon$2 in 1.5, a/Anon$2 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " static class Anon2 {\n" + + " // it\'s an object init block which has different prio as constructor!\n" + + " {\n" + + " Object o1 = new Object() {\n" + + " public String toString() {\n" + + " return \"1\"; // a/Anon$Anon2$1 in 1.5, a/Anon$3 in 1.4\n" + + " }\n" + + " };\n" + + " Object o2 = new Object() {\n" + + " public String toString() {\n" + + " return \"2\"; // a/Anon$Anon2$2 in 1.5, a/Anon$4 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " void hello() {\n" + + " Object o3 = new Object() {\n" + + " public String toString() {\n" + + " return \"3\"; // a/Anon$Anon2$5 in 1.5, a/Anon$7 in 1.4\n" + + " }\n" + + " };\n" + + " Object o4 = new Object() {\n" + + " public String toString() {\n" + + " return \"4\"; // a/Anon$Anon2$6 in 1.5, a/Anon$8 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " static void hello2() {\n" + + " Object o5 = new Object() {\n" + + " public String toString() {\n" + + " return \"5\"; // a/Anon$Anon2$7 in 1.5, a/Anon$9 in 1.4\n" + + " }\n" + + " };\n" + + " Object o6 = new Object() {\n" + + " public String toString() {\n" + + " return \"6\"; // a/Anon$Anon2$8 in 1.5, a/Anon$10 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " static {\n" + + " Object o7 = new Object() {\n" + + " public String toString() {\n" + + " return \"7\"; // a/Anon$Anon2$3 in 1.5, a/Anon$5 in 1.4\n" + + " }\n" + + " };\n" + + "\n" + + " Object o8 = new Object() {\n" + + " public String toString() {\n" + + " return \"8\"; // a/Anon$Anon2$4 in 1.5, a/Anon$6 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + "}"); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("a");//$NON-NLS-1$ + ICompilationUnit compilationUnit = packageFragment.getCompilationUnit("Anon.java");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(compilationUnit); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 18, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/a/Anon.class\n" + + "/Project/bin/a/Anon$1.class\n" + + "/Project/bin/a/Anon$2.class\n" + + "/Project/bin/a/Anon$3.class\n" + + "/Project/bin/a/Anon$4.class\n" + + "/Project/bin/a/Anon$5.class\n" + + "/Project/bin/a/Anon$6.class\n" + + "/Project/bin/a/Anon$7.class\n" + + "/Project/bin/a/Anon$8.class\n" + + "/Project/bin/a/Anon$9.class\n" + + "/Project/bin/a/Anon$10.class\n" + + "/Project/bin/a/Anon$11.class\n" + + "/Project/bin/a/Anon$12.class\n" + + "/Project/bin/a/Anon$13.class\n" + + "/Project/bin/a/Anon$14.class\n" + + "/Project/bin/a/Anon$15.class\n" + + "/Project/bin/a/Anon$16.class\n" + + "/Project/bin/a/Anon$Anon2.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test006() throws JavaModelException { + IPath projectPath = null; + try { + projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ + } catch (RuntimeException e) { + // no 1.5 VM or above is available + return; + } + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "a", "Anon", //$NON-NLS-1$ //$NON-NLS-2$ + "package a;\n" + + "\n" + + "public class Anon {\n" + + "\n" + + " Anon() {\n" + + " Object o1 = new Object() {\n" + + " public String toString() {\n" + + " return \"1\"; // a/Anon$3 in 1.5, a/Anon$11 in 1.4\n" + + " }\n" + + " };\n" + + " Object o2 = new Object() {\n" + + " public String toString() {\n" + + " return \"2\"; // a/Anon$4 in 1.5, a/Anon$12 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " void hello() {\n" + + " Object o3 = new Object() {\n" + + " public String toString() {\n" + + " return \"3\"; // a/Anon$5 in 1.5, a/Anon$13 in 1.4\n" + + " }\n" + + " };\n" + + " Object o4 = new Object() {\n" + + " public String toString() {\n" + + " return \"4\"; // a/Anon$6 in 1.5, a/Anon$14 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " static void hello2() {\n" + + " Object o5 = new Object() {\n" + + " public String toString() {\n" + + " return \"5\"; // a/Anon$7 in 1.5, a/Anon$15 in 1.4\n" + + " }\n" + + " };\n" + + " Object o6 = new Object() {\n" + + " public String toString() {\n" + + " return \"6\"; // a/Anon$8 in 1.5, a/Anon$16 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " static {\n" + + " Object o7 = new Object() {\n" + + " public String toString() {\n" + + " return \"7\"; // a/Anon$1 in 1.5, a/Anon$1 in 1.4\n" + + " }\n" + + " };\n" + + "\n" + + " Object o8 = new Object() {\n" + + " public String toString() {\n" + + " return \"8\"; // a/Anon$2 in 1.5, a/Anon$2 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " static class Anon2 {\n" + + " // it\'s an object init block which has different prio as constructor!\n" + + " {\n" + + " Object o1 = new Object() {\n" + + " public String toString() {\n" + + " return \"1\"; // a/Anon$Anon2$1 in 1.5, a/Anon$3 in 1.4\n" + + " }\n" + + " };\n" + + " Object o2 = new Object() {\n" + + " public String toString() {\n" + + " return \"2\"; // a/Anon$Anon2$2 in 1.5, a/Anon$4 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " void hello() {\n" + + " Object o3 = new Object() {\n" + + " public String toString() {\n" + + " return \"3\"; // a/Anon$Anon2$5 in 1.5, a/Anon$7 in 1.4\n" + + " }\n" + + " };\n" + + " Object o4 = new Object() {\n" + + " public String toString() {\n" + + " return \"4\"; // a/Anon$Anon2$6 in 1.5, a/Anon$8 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " static void hello2() {\n" + + " Object o5 = new Object() {\n" + + " public String toString() {\n" + + " return \"5\"; // a/Anon$Anon2$7 in 1.5, a/Anon$9 in 1.4\n" + + " }\n" + + " };\n" + + " Object o6 = new Object() {\n" + + " public String toString() {\n" + + " return \"6\"; // a/Anon$Anon2$8 in 1.5, a/Anon$10 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " static {\n" + + " Object o7 = new Object() {\n" + + " public String toString() {\n" + + " return \"7\"; // a/Anon$Anon2$3 in 1.5, a/Anon$5 in 1.4\n" + + " }\n" + + " };\n" + + "\n" + + " Object o8 = new Object() {\n" + + " public String toString() {\n" + + " return \"8\"; // a/Anon$Anon2$4 in 1.5, a/Anon$6 in 1.4\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + "}"); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("a");//$NON-NLS-1$ + ICompilationUnit compilationUnit = packageFragment.getCompilationUnit("Anon.java");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(compilationUnit); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 18, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/a/Anon.class\n" + + "/Project/bin/a/Anon$1.class\n" + + "/Project/bin/a/Anon$2.class\n" + + "/Project/bin/a/Anon$3.class\n" + + "/Project/bin/a/Anon$4.class\n" + + "/Project/bin/a/Anon$5.class\n" + + "/Project/bin/a/Anon$6.class\n" + + "/Project/bin/a/Anon$7.class\n" + + "/Project/bin/a/Anon$8.class\n" + + "/Project/bin/a/Anon$Anon2.class\n" + + "/Project/bin/a/Anon$Anon2$1.class\n" + + "/Project/bin/a/Anon$Anon2$2.class\n" + + "/Project/bin/a/Anon$Anon2$3.class\n" + + "/Project/bin/a/Anon$Anon2$4.class\n" + + "/Project/bin/a/Anon$Anon2$5.class\n" + + "/Project/bin/a/Anon$Anon2$6.class\n" + + "/Project/bin/a/Anon$Anon2$7.class\n" + + "/Project/bin/a/Anon$Anon2$8.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + env.removeProject(projectPath); + } + + private String getResourceOuput(IResource[] resources) { + StringWriter stringWriter = new StringWriter(); + PrintWriter writer = new PrintWriter(stringWriter); + for (int i = 0, max = resources.length; i < max; i++) { + writer.println(resources[i].getFullPath().toString()); + } + writer.flush(); + writer.close(); + return Util.convertToIndependantLineDelimiter(String.valueOf(stringWriter)); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test007() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" + //$NON-NLS-1$ + "class Foo {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + ICompilationUnit compilationUnit = packageFragment.getCompilationUnit("Hello.java");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(compilationUnit); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test008() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n" + + " public class Z {}\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(packageFragment); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test009() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(projectPath, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getUnderlyingResource()); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + ICompilationUnit compilationUnit = packageFragment.getCompilationUnit("Hello.java");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(compilationUnit); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 1, resources.length);//$NON-NLS-1$ + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/Hello.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test010() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n" + + " public class Z {}\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addFile(root, "p1/Test.txt", "This is a non-java resource"); + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(packageFragment); + IResource[] resources = JavaCore.getGeneratedResources(region, false); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 3, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + actualOutput = getResourceOuput(resources); + expectedOutput = + "/Project/bin/p1/Test.txt\n" + + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test011() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n" + + " public class Z {}\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(packageFragment); + IResource[] resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.addFile(root, "p1/Test.txt", "This is a non-java resource"); + incrementalBuild(projectPath); + + resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 3, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + actualOutput = getResourceOuput(resources); + expectedOutput = + "/Project/bin/p1/Test.txt\n" + + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test012() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n" + + " public class Z {}\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(packageFragment); + IResource[] resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.addFile(root, "p1/Test.txt", "This is a non-java resource"); + + resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + actualOutput = getResourceOuput(resources); + expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test013() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src", new Path[] {new Path("**/*.txt")}, null); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n" + + " public class Z {}\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(packageFragment); + IResource[] resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.addFile(root, "p1/Test.txt", "This is a non-java resource"); + incrementalBuild(projectPath); + + resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + actualOutput = getResourceOuput(resources); + expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test014() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src", new Path[] {new Path("**/*.txt")}, null); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n" + + " public class Z {}\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IPackageFragmentRoot root2 = project.getPackageFragmentRoot(project.getProject().getWorkspace().getRoot().findMember(root.makeAbsolute())); + IPackageFragment packageFragment = root2.getPackageFragment("p1");//$NON-NLS-1$ + IRegion region = JavaCore.newRegion(); + region.add(packageFragment); + IResource[] resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.addFile(root, "p1/Test.txt", "This is an excluded non-java resource"); + env.addFile(root, "p1/Test.log", "This is an included non-java resource"); + incrementalBuild(projectPath); + + resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 3, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + actualOutput = getResourceOuput(resources); + expectedOutput = + "/Project/bin/p1/Test.log\n" + + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test015() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src", new Path[] {new Path("**/*.txt")}, null); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Hello", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Hello {\n" + + " public class Z {}\n"+ //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(\"Hello world\");\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IJavaProject project = env.getJavaProject(projectPath); + IRegion region = JavaCore.newRegion(); + region.add(project); + IResource[] resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 2, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + String actualOutput = getResourceOuput(resources); + String expectedOutput = + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.addFile(root, "p1/Test.txt", "This is an excluded non-java resource"); + env.addFile(root, "p1/Test.log", "This is an included non-java resource"); + incrementalBuild(projectPath); + + resources = JavaCore.getGeneratedResources(region, true); + assertEquals("Wrong size", 3, resources.length);//$NON-NLS-1$ + Arrays.sort(resources, COMPARATOR); + actualOutput = getResourceOuput(resources); + expectedOutput = + "/Project/bin/p1/Test.log\n" + + "/Project/bin/p1/Hello.class\n" + + "/Project/bin/p1/Hello$Z.class\n"; + assertEquals("Wrong names", Util.convertToIndependantLineDelimiter(expectedOutput), actualOutput); + + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=6584 + public void test016() throws JavaModelException { + try { + JavaCore.getGeneratedResources(null, true); + assertTrue("Region cannot be null", false); + } catch(IllegalArgumentException e) { + // ignore: expected exception + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests.java new file mode 100644 index 0000000000..67f061434c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests.java @@ -0,0 +1,1288 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.util.Hashtable; + +import junit.framework.Test; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.Util; + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class IncrementalTests extends BuilderTests { + + public IncrementalTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(IncrementalTests.class); + } + + /* + * Ensures that the source range for a duplicate secondary type error is correct + * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=77283) + */ + public void testAddDuplicateSecondaryType() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + env.addClass(root, "p", "C", + "package p; \n"+ + "public class C {} \n"+ + "class CC {}"); + + fullBuild(projectPath); + expectingNoProblems(); + + IPath pathToD = env.addClass(root, "p", "D", + "package p; \n"+ + "public class D {} \n"+ + "class CC {}"); + + incrementalBuild(projectPath); + expectingProblemsFor( + pathToD, + "Problem : The type CC is already defined [ resource : range : <37,39> category : <-1> severity : <2>]" + ); + expectingSpecificProblemsFor(pathToD, new Problem[] {new Problem("", "The type CC is already defined", pathToD, 37, 39, -1, IMarker.SEVERITY_ERROR)}); + env.removeProject(projectPath); + } + + public void testDefaultPackage() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, ""); //$NON-NLS-1$ + + env.addClass(projectPath, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {}"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "public class B {}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(projectPath, "", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "public class B {A a;}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } + + public void testDefaultPackage2() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {}"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "public class B {}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(projectPath, "", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "public class B {A a;}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } + + public void testNewJCL() { + //---------------------------- + // Step 1 + //---------------------------- + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + + IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + fullBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + env.addClass(root, "java.lang", "Object", //$NON-NLS-1$ //$NON-NLS-2$ + "package java.lang;\n" + //$NON-NLS-1$ + "public class Object {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + + incrementalBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 3 + //---------------------------- + env.addClass(root, "java.lang", "Throwable", //$NON-NLS-1$ //$NON-NLS-2$ + "package java.lang;\n" + //$NON-NLS-1$ + "public class Throwable {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + + incrementalBuild(); + expectingNoProblems(); + env.removeProject(projectPath); + } + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=17329 + */ + public void testRenameMainType() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + /* A.java */ + IPath pathToA = env.addClass(root, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class A {}"); //$NON-NLS-1$ + + /* B.java */ + IPath pathToB = env.addClass(root, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class B extends A {}"); //$NON-NLS-1$ + + /* C.java */ + IPath pathToC = env.addClass(root, "p", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class C extends B {}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + /* Touch both A and C, removing A main type */ + pathToA = env.addClass(root, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class _A {}"); //$NON-NLS-1$ + + pathToC = env.addClass(root, "p", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class C extends B { }"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingProblemsFor( + new IPath[]{ pathToA, pathToB, pathToC }, + "Problem : A cannot be resolved to a type [ resource : range : <35,36> category : <40> severity : <2>]\n" + + "Problem : The hierarchy of the type C is inconsistent [ resource : range : <25,26> category : <40> severity : <2>]\n" + + "Problem : The public type _A must be defined in its own file [ resource : range : <25,27> category : <40> severity : <2>]" + ); + expectingSpecificProblemFor(pathToA, new Problem("_A", "The public type _A must be defined in its own file", pathToA, 25, 27, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(pathToB, new Problem("B", "A cannot be resolved to a type", pathToB, 35, 36, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(pathToC, new Problem("C", "The hierarchy of the type C is inconsistent", pathToC, 25, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + /* Touch both A and C, removing A main type */ + pathToA = env.addClass(root, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class A {}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=17807 + * case 1 + */ + public void testRemoveSecondaryType() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA {} \n"+ //$NON-NLS-1$ + "class AZ {}"); //$NON-NLS-1$ + + IPath pathToAB = env.addClass(root, "p", "AB", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AB extends AZ {}"); //$NON-NLS-1$ + + env.addClass(root, "p", "BB", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class BB { \n"+ //$NON-NLS-1$ + " void foo(){ \n" + //$NON-NLS-1$ + " System.out.println(new AB()); \n" + //$NON-NLS-1$ + " System.out.println(new ZA()); \n" + //$NON-NLS-1$ + " } \n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class ZZ {} \n"+ //$NON-NLS-1$ + "class ZA {}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + /* Remove AZ and touch BB */ + env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA {}"); //$NON-NLS-1$ + + env.addClass(root, "p", "BB", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class BB { \n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " System.out.println(new AB()); \n" + //$NON-NLS-1$ + " System.out.println(new ZA()); \n" + //$NON-NLS-1$ + " } \n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingProblemsFor( + pathToAB, + "Problem : AZ cannot be resolved to a type [ resource : range : <36,38> category : <40> severity : <2>]" + ); + expectingSpecificProblemFor(pathToAB, new Problem("AB", "AZ cannot be resolved to a type", pathToAB, 36, 38, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA {} \n"+ //$NON-NLS-1$ + "class AZ {}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=17807 + * case 2 + */ + public void testRemoveSecondaryType2() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA {} \n"+ //$NON-NLS-1$ + "class AZ {}"); //$NON-NLS-1$ + + env.addClass(root, "p", "AB", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AB extends AZ {}"); //$NON-NLS-1$ + + IPath pathToBB = env.addClass(root, "p", "BB", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class BB { \n"+ //$NON-NLS-1$ + " void foo(){ \n" + //$NON-NLS-1$ + " System.out.println(new AB()); \n" + //$NON-NLS-1$ + " System.out.println(new ZA()); \n" + //$NON-NLS-1$ + " } \n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class ZZ {} \n"+ //$NON-NLS-1$ + "class ZA {}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + /* Remove ZA and touch BB */ + env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class ZZ {}"); //$NON-NLS-1$ + + pathToBB = env.addClass(root, "p", "BB", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class BB { \n"+ //$NON-NLS-1$ + " void foo() { \n" + //$NON-NLS-1$ + " System.out.println(new AB()); \n" + //$NON-NLS-1$ + " System.out.println(new ZA()); \n" + //$NON-NLS-1$ + " } \n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingProblemsFor( + pathToBB, + "Problem : ZA cannot be resolved to a type [ resource : range : <104,106> category : <40> severity : <2>]" + ); + expectingSpecificProblemFor(pathToBB, new Problem("BB.foo()", "ZA cannot be resolved to a type", pathToBB, 104, 106, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class ZZ {} \n"+ //$NON-NLS-1$ + "class ZA {}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } + + public void testMoveSecondaryType() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA {} \n"+ //$NON-NLS-1$ + "class AZ {}"); //$NON-NLS-1$ + + env.addClass(root, "p", "AB", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AB extends AZ {}"); //$NON-NLS-1$ + + env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class ZZ {}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + /* Move AZ from AA to ZZ */ + env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA {}"); //$NON-NLS-1$ + + env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class ZZ {} \n"+ //$NON-NLS-1$ + "class AZ {}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + + /* Move AZ from ZZ to AA */ + env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA {} \n"+ //$NON-NLS-1$ + "class AZ {}"); //$NON-NLS-1$ + + env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class ZZ {}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } + + public void testMoveMemberType() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA {} \n"+ //$NON-NLS-1$ + "class AZ {static class M{}}"); //$NON-NLS-1$ + + env.addClass(root, "p", "AB", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "import p.AZ.*; \n"+ //$NON-NLS-1$ + "import p.ZA.*; \n"+ //$NON-NLS-1$ + "public class AB extends M {}"); //$NON-NLS-1$ + + env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class ZZ {} \n"+ //$NON-NLS-1$ + "class ZA {}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingOnlySpecificProblemsFor( + root, + new Problem[]{ + new Problem("", "The import p.ZA is never used", new Path("/Project/src/p/AB.java"), 35, 39, CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_WARNING), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + }); + + /* Move M from AA to ZZ */ + env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA {} \n"+ //$NON-NLS-1$ + "class AZ {}"); //$NON-NLS-1$ + + env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class ZZ {} \n"+ //$NON-NLS-1$ + "class ZA {static class M{}}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingOnlySpecificProblemsFor( + root, + new Problem[]{ + new Problem("", "The import p.AZ is never used", new Path("/Project/src/p/AB.java"), 19, 23, CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_WARNING), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + }); + + /* Move M from ZZ to AA */ + env.addClass(root, "p", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class AA {} \n"+ //$NON-NLS-1$ + "class AZ {static class M{}}"); //$NON-NLS-1$ + + env.addClass(root, "p", "ZZ", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class ZZ {} \n"+ //$NON-NLS-1$ + "class ZA {}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingOnlySpecificProblemsFor( + root, + new Problem[]{ + new Problem("", "The import p.ZA is never used", new Path("/Project/src/p/AB.java"), 35, 39, CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_WARNING), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + }); + env.removeProject(projectPath); + } + + public void testMovePackage() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath[] exclusionPatterns = new Path[] {new Path("src2/")}; //$NON-NLS-1$ + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1", exclusionPatterns, null); //$NON-NLS-1$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src1/src2"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(src1, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class A {}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + env.removePackage(src1, "p"); //$NON-NLS-1$ + env.addClass(src2, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class A {}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } + + public void testMovePackage2() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath other = env.addFolder(projectPath, "other"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath classA = env.addClass(src, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class A extends Missing {}"); //$NON-NLS-1$ + IPath classB = env.addClass(src, "p.q", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.q; \n"+ //$NON-NLS-1$ + "public class B extends Missing {}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingSpecificProblemFor( + classA, + new Problem("", "Missing cannot be resolved to a type", new Path("/Project/src/p/A.java"), 35, 42, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + ); + expectingSpecificProblemFor( + classB, + new Problem("", "Missing cannot be resolved to a type", new Path("/Project/src/p/q/B.java"), 37, 44, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + ); + + try { + IProject p = env.getProject(projectPath); + IFolder pFolder = p.getWorkspace().getRoot().getFolder(classA.removeLastSegments(1)); + pFolder.move(other.append("p"), true, false, null); + } catch (CoreException e) { + env.handle(e); + } + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } + + public void testMemberTypeFromClassFile() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class A extends Z {M[] m;}"); //$NON-NLS-1$ + + env.addClass(root, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class B {A a; E e; \n"+ //$NON-NLS-1$ + "void foo() { System.out.println(a.m); }}"); //$NON-NLS-1$ + + env.addClass(root, "p", "E", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class E extends Z { \n"+ //$NON-NLS-1$ + "void foo() { System.out.println(new M()); }}"); //$NON-NLS-1$ + + env.addClass(root, "p", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class Z {static class M {}}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class B {A a; E e; \n"+ //$NON-NLS-1$ + "void foo( ) { System.out.println(a.m); }}"); //$NON-NLS-1$ + + env.addClass(root, "p", "E", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class E extends Z { \n"+ //$NON-NLS-1$ + "void foo( ) { System.out.println(new M()); }}"); //$NON-NLS-1$ + + env.addClass(root, "p", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class Z { static class M {} }"); //$NON-NLS-1$ + + int previous = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 1; // reduce the lot size + incrementalBuild(projectPath); + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = previous; + expectingNoProblems(); + env.removeProject(projectPath); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=372418 + public void testMemberTypeOfOtherProject() throws JavaModelException { + IPath projectPath1 = env.addProject("Project1", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath1, Util.getJavaClassLibs()); + + IPath projectPath2 = env.addProject("Project2", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath2, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath1, ""); //$NON-NLS-1$ + + IPath root1 = env.addPackageFragmentRoot(projectPath1, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath1, "bin"); //$NON-NLS-1$ + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath2, ""); //$NON-NLS-1$ + + IPath root2 = env.addPackageFragmentRoot(projectPath2, "src"); //$NON-NLS-1$ + IPath output2 = env.setOutputFolder(projectPath2, "bin"); //$NON-NLS-1$ + + env.addClassFolder(projectPath1, output2, true); + env.addRequiredProject(projectPath2, projectPath1); + + env.addClass(root1, "pB", "BaseClass", //$NON-NLS-1$ //$NON-NLS-2$ + "package pB; \n"+ //$NON-NLS-1$ + "public class BaseClass {\n" + //$NON-NLS-1$ + " public static class Builder {\n"+ //$NON-NLS-1$ + " public Builder(T t) {\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n");//$NON-NLS-1$ + + env.addClass(root1, "pR", "ReferencingClass", //$NON-NLS-1$ //$NON-NLS-2$ + "package pR; \n"+ //$NON-NLS-1$ + "import pD.DerivedClass.Builder;\n"+ //$NON-NLS-1$ + "public class ReferencingClass {\n" + //$NON-NLS-1$ + " Builder builder = new Builder(null);\n" + //$NON-NLS-1$ + "}\n"); //$NON-NLS-1$ + + env.addClass(root2, "pD", "DerivedClass", //$NON-NLS-1$ //$NON-NLS-2$ + "package pD; \n"+ //$NON-NLS-1$ + "public class DerivedClass extends pB.BaseClass {\n" + //$NON-NLS-1$ + " public static class Builder extends pB.BaseClass.Builder {\n"+ //$NON-NLS-1$ + " public Builder(T t) {\n" + //$NON-NLS-1$ + " super(t);\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n"); //$NON-NLS-1$ + + int previous = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + fullBuild(); + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 1; // reduce the lot size + cleanBuild(); + fullBuild(); + cleanBuild("Project1"); //$NON-NLS-1$ + fullBuild(projectPath1); + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = previous; + expectingNoProblems(); + env.removeProject(projectPath1); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=377401 + public void test$InTypeName() throws JavaModelException { + IPath projectPath1 = env.addProject("Project1", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath1, Util.getJavaClassLibs()); + + IPath projectPath2 = env.addProject("Project2", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath2, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath1, ""); //$NON-NLS-1$ + + IPath root1 = env.addPackageFragmentRoot(projectPath1, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath1, "bin"); //$NON-NLS-1$ + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath2, ""); //$NON-NLS-1$ + + IPath root2 = env.addPackageFragmentRoot(projectPath2, "src"); //$NON-NLS-1$ + IPath output2 = env.setOutputFolder(projectPath2, "bin"); //$NON-NLS-1$ + + env.addClassFolder(projectPath1, output2, true); + env.addRequiredProject(projectPath2, projectPath1); + + env.addClass(root1, "pB", "Builder$a", //$NON-NLS-1$ //$NON-NLS-2$ + "package pB; \n"+ //$NON-NLS-1$ + "public class Builder$a {\n" + //$NON-NLS-1$ + " public Builder$a(T t) {\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n");//$NON-NLS-1$ + + env.addClass(root1, "pR", "ReferencingClass", //$NON-NLS-1$ //$NON-NLS-2$ + "package pR; \n"+ //$NON-NLS-1$ + "import pD.DerivedClass$a;\n"+ //$NON-NLS-1$ + "public class ReferencingClass {\n" + //$NON-NLS-1$ + " DerivedClass$a builder = new DerivedClass$a(null);\n" + //$NON-NLS-1$ + "}\n"); //$NON-NLS-1$ + + env.addClass(root2, "pD", "DerivedClass$a", //$NON-NLS-1$ //$NON-NLS-2$ + "package pD; \n"+ //$NON-NLS-1$ + "public class DerivedClass$a extends pB.Builder$a {\n" + //$NON-NLS-1$ + " public DerivedClass$a(T t) {\n" + //$NON-NLS-1$ + " super(t);\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}\n"); //$NON-NLS-1$ + + int previous = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + fullBuild(); + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 1; // reduce the lot size + cleanBuild(); + fullBuild(); + cleanBuild("Project1"); //$NON-NLS-1$ + fullBuild(projectPath1); + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = previous; + expectingNoProblems(); + env.removeProject(projectPath1); + } + + // http://dev.eclipse.org/bugs/show_bug.cgi?id=27658 + public void testObjectWithSuperInterfaces() throws JavaModelException { + try { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "java.lang", "Object", //$NON-NLS-1$ //$NON-NLS-2$ + "package java.lang; \n"+ //$NON-NLS-1$ + "public class Object implements I {} \n"+ //$NON-NLS-1$ + "interface I {} \n"); //$NON-NLS-1$ + + fullBuild(projectPath); + + expectingOnlySpecificProblemsFor( + root, + new Problem[]{ + new Problem("", "The type java.lang.Object cannot have a superclass or superinterfaces", new Path("/Project/src/java/lang/Object.java"), 33, 39, CategorizedProblem.CAT_INTERNAL, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + }); + + env.addClass(root, "p", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class X {}\n"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + + expectingOnlySpecificProblemsFor( + root, + new Problem[]{ + new Problem("", "The type java.lang.Object cannot have a superclass or superinterfaces", new Path("/Project/src/java/lang/Object.java"), 33, 39, CategorizedProblem.CAT_INTERNAL, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + }); + + env.addClass(root, "p", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p; \n"+ //$NON-NLS-1$ + "public class Y extends X {}\n"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + + expectingOnlySpecificProblemsFor( + root, + new Problem[]{ + new Problem("", "The type java.lang.Object cannot have a superclass or superinterfaces", new Path("/Project/src/java/lang/Object.java"), 33, 39, CategorizedProblem.CAT_INTERNAL, IMarker.SEVERITY_ERROR), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + }); + env.removeProject(projectPath); + + } catch(StackOverflowError e){ + assertTrue("Infinite loop in cycle detection", false); //$NON-NLS-1$ + e.printStackTrace(); + } + } + + /** + * Bugs 6461 + * TODO excluded test + */ + public void _testWrongCompilationUnitLocation() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + IPath x = env.addClass(root, "", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "public class X {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(bin.append("X.class")); //$NON-NLS-1$ + + //---------------------------- + // Step 2 + //---------------------------- + env.addClass(root, "", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingProblemsFor(x, "???"); + expectingNoPresenceOf(bin.append("X.class")); //$NON-NLS-1$ + env.removeProject(projectPath); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=100631 + public void testMemberTypeCollisionWithBinary() throws JavaModelException { + int max = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + try { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {\n"+ //$NON-NLS-1$ + " Object foo(B b) { return b.i; }\n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + env.addClass(root, "", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "public class B {\n"+ //$NON-NLS-1$ + " I.InnerType i;\n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + env.addClass(root, "", "I", //$NON-NLS-1$ //$NON-NLS-2$ + "public interface I {\n"+ //$NON-NLS-1$ + " interface InnerType {}\n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 1; + + env.addClass(root, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {\n"+ //$NON-NLS-1$ + " Object foo(B b) { return b.i; }\n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + env.addClass(root, "", "I", //$NON-NLS-1$ //$NON-NLS-2$ + "public interface I {\n"+ //$NON-NLS-1$ + " interface InnerType {}\n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } finally { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = max; + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=191739 + public void testMemberTypeCollisionWithBinary2() throws JavaModelException { + int max = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + try { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1"); //$NON-NLS-1$ + IPath bin1 = env.setOutputFolder(projectPath, "bin1"); //$NON-NLS-1$ + + env.addClass(src1, "p1", "NoSource", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1; \n"+ + "import p2.Foo;\n"+ //$NON-NLS-1$ + "public class NoSource {\n"+ //$NON-NLS-1$ + " public NoSource(Foo.Bar b) {}\n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2", null, "bin2"); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(src2, "p2", "Foo", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2; \n"+ + "public class Foo {\n"+ //$NON-NLS-1$ + " public static class Bar {\n" + //$NON-NLS-1$ + " public static Bar LocalBar = new Bar();\n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + env.addClass(src2, "p2", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2; \n"+ + "import p1.NoSource;\n"+ //$NON-NLS-1$ + "import p2.Foo.Bar;\n"+ //$NON-NLS-1$ + "public class Test {\n"+ //$NON-NLS-1$ + " NoSource nosrc = new NoSource(Bar.LocalBar);\n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + env.removePackageFragmentRoot(projectPath, "src1"); //$NON-NLS-1$ + env.addClassFolder(projectPath, bin1, false); + + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 1; + + env.addClass(src2, "p2", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2; \n"+ + "import p1.NoSource;\n"+ //$NON-NLS-1$ + "import p2.Foo.Bar;\n"+ //$NON-NLS-1$ + "public class Test {\n"+ //$NON-NLS-1$ + " NoSource nosrc = new NoSource(Bar.LocalBar);\n" + //$NON-NLS-1$ + "}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } finally { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = max; + } + } + + + public void test129316() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, ""); //$NON-NLS-1$ + + IPath yPath = env.addClass(projectPath, "p", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + + "public class Y extends Z {}"); //$NON-NLS-1$ + + env.addClass(projectPath, "p", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + + "public class Z {}"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "import p.Y;\n" + + "public class X {\n" + + " boolean b(Object o) {\n" + + " return o instanceof Y;\n" + + " }\n" + + "}"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(projectPath, "p", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + + "public class Y extends Zork {}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingSpecificProblemFor(yPath, new Problem("Y", "Zork cannot be resolved to a type", yPath, 34, 38, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + IPath xPath = env.addClass(projectPath, "", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "public class X {\n" + + " boolean b(Object o) {\n" + + " return o instanceof p.Y;\n" + + " }\n" + + "}"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingSpecificProblemFor(yPath, new Problem("Y", "Zork cannot be resolved to a type", yPath, 34, 38, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoProblemsFor(xPath); + env.removeProject(projectPath); + } + + public void testSecondaryType() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "", "AB", //$NON-NLS-1$ //$NON-NLS-2$ + "public class AB { AZ z = new AA();}"); //$NON-NLS-1$ + + env.addClass(root, "", "AA", //$NON-NLS-1$ //$NON-NLS-2$ + "public class AA extends AZ {} \n"+ //$NON-NLS-1$ + "class AZ {}"); //$NON-NLS-1$ + + int max = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + try { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 1; + fullBuild(projectPath); + } finally { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = max; + } + expectingNoProblems(); + env.removeProject(projectPath); + } + + // http://dev.eclipse.org/bugs/show_bug.cgi?id=196200 - variation + public void testMissingType001() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath xPath = env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo(p2.Y y) { \n" + //$NON-NLS-1$ + " y.bar(null);" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + " void X() {}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + IPath yPath = env.addClass(root, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Y {\n"+ //$NON-NLS-1$ + " public void bar(Z z) {}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + fullBuild(projectPath); + expectingSpecificProblemFor(xPath, new Problem("X", "This method has a constructor name", xPath, 73, 76, CategorizedProblem.CAT_CODE_STYLE, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(yPath, new Problem("Y", "Z cannot be resolved to a type", yPath, 46, 47, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p2", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Z {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + incrementalBuild(projectPath); + expectingSpecificProblemFor(xPath, new Problem("X", "This method has a constructor name", xPath, 73, 76, CategorizedProblem.CAT_CODE_STYLE, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(projectPath); + } + + // http://dev.eclipse.org/bugs/show_bug.cgi?id=196200 - variation + public void testMissingType002() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath yPath = env.addClass(root, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Y {\n"+ //$NON-NLS-1$ + " public void bar(Z z) {}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + fullBuild(projectPath); + expectingSpecificProblemFor(yPath, new Problem("Y", "Z cannot be resolved to a type", yPath, 46, 47, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + IPath xPath = env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo(p2.Y y) { \n" + //$NON-NLS-1$ + " y.bar(null);" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + " void X() {}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + incrementalBuild(projectPath); + expectingSpecificProblemFor(xPath, new Problem("X", "This method has a constructor name", xPath, 73, 76, CategorizedProblem.CAT_CODE_STYLE, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(yPath, new Problem("Y", "Z cannot be resolved to a type", yPath, 46, 47, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p2", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Z {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + incrementalBuild(projectPath); + expectingSpecificProblemFor(xPath, new Problem("X", "This method has a constructor name", xPath, 73, 76, CategorizedProblem.CAT_CODE_STYLE, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(projectPath); + } + + // http://dev.eclipse.org/bugs/show_bug.cgi?id=196200 - variation + public void testMissingType003() throws JavaModelException { + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath yPath = env.addClass(root, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Y {\n"+ //$NON-NLS-1$ + " public void bar(p1.Z z) {}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + fullBuild(projectPath); + expectingSpecificProblemFor(yPath, new Problem("Y", "p1 cannot be resolved to a type", yPath, 46, 48, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + IPath xPath = env.addClass(root, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void foo(p2.Y y) { \n" + //$NON-NLS-1$ + " y.bar(null);" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + " void X() {}\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + incrementalBuild(projectPath); + expectingSpecificProblemFor(xPath, new Problem("X", "This method has a constructor name", xPath, 73, 76, CategorizedProblem.CAT_CODE_STYLE, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(yPath, new Problem("Y", "p1.Z cannot be resolved to a type", yPath, 46, 50, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(root, "p1", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class Z {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + incrementalBuild(projectPath); + expectingSpecificProblemFor(xPath, new Problem("X", "This method has a constructor name", xPath, 73, 76, CategorizedProblem.CAT_CODE_STYLE, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(projectPath); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=334377 + public void testBug334377() throws JavaModelException { + int max = org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE; + Hashtable options = null; + try { + options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + newOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + JavaCore.setOptions(newOptions); + + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "", "Upper", + "public abstract class Upper {\n" + + " public static enum Mode {IN,OUT;}\n" + + "}\n"); + env.addClass(root, "", "Lower", + "public class Lower extends Upper {};\n"); + env.addClass(root, "", "Bug", + "public class Bug {\n" + + " Upper.Mode m1;\n" + + " void usage(){\n" + + " Lower.Mode m3;\n" + + " if (m1 == null){\n" + + " m3 = Lower.Mode.IN;\n" + + " } else {\n" + + " m3 = m1;\n" + + " }\n" + + " Lower.Mode m2 = (m1 == null ? Lower.Mode.IN : m1);\n" + + " System.out.println(m2);\n" + + " System.out.println(m3);\n" + + " }\n" + + "}\n"); + + fullBuild(projectPath); + expectingNoProblems(); + env.addClass(root, "", "Bug", + "public class Bug {\n" + + " Upper.Mode m1;\n" + + " void usage(){\n" + + " Lower.Mode m3;\n" + + " if (m1 == null){\n" + + " m3 = Lower.Mode.IN;\n" + + " } else {\n" + + " m3 = m1;\n" + + " }\n" + + " Lower.Mode m2 = (m1 == null ? Lower.Mode.IN : m1);\n" + + " System.out.println(m2);\n" + + " System.out.println(m3);\n" + + " }\n" + + "}\n"); + + incrementalBuild(projectPath); + expectingNoProblems(); + env.removeProject(projectPath); + } finally { + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = max; + JavaCore.setOptions(options); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=364450 + // Incremental build should not generate buildpath error + // NOT generated by full build. + public void testBug364450() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath wPath = env.addClass(projectPath, "w", "W", //$NON-NLS-1$ //$NON-NLS-2$ + "package w;\n" + + "public class W {\n" + + " private w.I i;}"); //$NON-NLS-1$ + + IPath aPath = env.addClass(projectPath, "a", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package a;\n" + + "import w.I;\n" + + "import w.W;\n" + + "public class A {}"); //$NON-NLS-1$ + env.waitForManualRefresh(); + fullBuild(projectPath); + env.waitForAutoBuild(); + expectingSpecificProblemFor(wPath, new Problem("W", "w.I cannot be resolved to a type", wPath, 37, 40, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(aPath, new Problem("A", "The import w.I cannot be resolved", aPath, 18, 21, CategorizedProblem.CAT_IMPORT, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + aPath = env.addClass(projectPath, "a", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package a;\n" + + "import w.I;\n" + + "import w.W;\n" + + "public class A {}"); //$NON-NLS-1$ + + env.waitForManualRefresh(); + incrementalBuild(projectPath); + env.waitForAutoBuild(); + expectingSpecificProblemFor(aPath, new Problem("A", "The import w.I cannot be resolved", aPath, 18, 21, CategorizedProblem.CAT_IMPORT, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(projectPath); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=520640 + public void testRemovePackageInDependencyProject() throws JavaModelException { + IPath projectPath1 = env.addProject("Project1"); + env.addExternalJars(projectPath1, Util.getJavaClassLibs()); + + IPath projectPath2 = env.addProject("Project2"); + env.addExternalJars(projectPath2, Util.getJavaClassLibs()); + + + env.addRequiredProject(projectPath1, projectPath2); + + env.addPackage(projectPath2, "emptypackage"); + + fullBuild(); + expectingNoProblems(); + + env.removePackage(projectPath2, "emptypackage"); + incrementalBuild(); + expectingNoProblems(); + + env.removeProject(projectPath2); + env.removeProject(projectPath1); + } + + public void testBug526376() throws JavaModelException { + IPath projectPath = env.addProject("Project"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + env.addClass(root, "p", "A", + "package p; \n"+ + "public class A extends B {} \n"); + + fullBuild(projectPath); + + env.addClass(root, "p", "B", + "package p; \n"+ + "public class B {}\n"); + + incrementalBuild(projectPath); + expectingCompilingOrder(new String[] { "/Project/src/p/B.java", "/Project/src/p/A.java" }); + expectingNoProblems(); + env.removeProject(projectPath); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests18.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests18.java new file mode 100644 index 0000000000..7cd8a8c7b9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/IncrementalTests18.java @@ -0,0 +1,813 @@ +/******************************************************************************* + * Copyright (c) 2013, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.File; +import java.io.IOException; + +import junit.framework.Test; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.osgi.framework.Bundle; + +public class IncrementalTests18 extends BuilderTests { + static { +// TESTS_NAMES = new String[] { "testBug481276b" }; + } + public IncrementalTests18(String name) { + super(name); + } + + public static Test suite() { + return AbstractCompilerTest.buildUniqueComplianceTestSuite(IncrementalTests18.class, ClassFileConstants.JDK1_8); + } + + private void setupProjectForNullAnnotations() throws IOException, JavaModelException { + // add the org.eclipse.jdt.annotation library (bin/ folder or jar) to the project: + Bundle[] bundles = Platform.getBundles("org.eclipse.jdt.annotation","[2.0.0,3.0.0)"); + File bundleFile = FileLocator.getBundleFile(bundles[0]); + String annotationsLib = bundleFile.isDirectory() ? bundleFile.getPath()+"/bin" : bundleFile.getPath(); + IJavaProject javaProject = env.getJavaProject("Project"); + IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); + int len = rawClasspath.length; + System.arraycopy(rawClasspath, 0, rawClasspath = new IClasspathEntry[len+1], 0, len); + rawClasspath[len] = JavaCore.newLibraryEntry(new Path(annotationsLib), null, null); + javaProject.setRawClasspath(rawClasspath, null); + + javaProject.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=423122, [1.8] Missing incremental build dependency from lambda expression to functional interface. + public void test423122() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + env.addClass(root, "p", "I", + "package p; \n"+ + "public interface I { void foo(); } \n" + ); + env.addClass(root, "p", "X", + "package p; \n"+ + "public class X { I i = () -> {}; } \n" + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p", "I", + "package p; \n"+ + "public interface I { } \n" + ); + incrementalBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : The target type of this expression must be a functional interface [ resource : range : <35,40> category : <40> severity : <2>]" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=423122, [1.8] Missing incremental build dependency from lambda expression to functional interface. + public void test423122a() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + env.addClass(root, "test1", "I", + "package test1;\n" + + "public interface I {\n" + + " int method(int a); // change argument type to Object\n" + + "}\n" + ); + env.addClass(root, "test1", "E", + "package test1;\n" + + "public class E {\n" + + " void take(I i) {\n" + + " }\n" + + "}\n" + ); + env.addClass(root, "test1", "Ref", + "package test1;\n" + + "public class Ref {\n" + + " void foo(E e) {\n" + + " e.take((x) -> x+2); // not recompiled when I#method changed\n" + + " }\n" + + "}\n" + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "test1", "I", + "package test1;\n" + + "public interface I {\n" + + " int method(Object a); // change argument type to Object\n" + + "}\n" + ); + incrementalBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : The operator + is undefined for the argument type(s) Object, int [ resource : range : <76,79> category : <60> severity : <2>]" + ); + env.addClass(root, "test1", "I", + "package test1;\n" + + "public interface I {\n" + + " int method(int a); // change argument type back to int\n" + + "}\n" + ); + incrementalBuild(projectPath); + expectingNoProblems(); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427105, [1.8][builder] Differences between incremental and full builds in method contract verification in the presence of type annotations + public void test427105() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + env.addClass(root, "", "X", + "import java.util.List;\n" + + "public class X implements I {\n" + + " public void f(List x, List ls) { \n" + + " }\n" + + "}\n" + ); + env.addClass(root, "", "I", + "import java.util.List;\n" + + "public interface I {\n" + + " void f(@T List x, List ls);\n" + + "}\n" + ); + env.addClass(root, "", "T", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface T {\n" + + "}\n" + ); + + // force annotation encoding into bindings which is necessary to reproduce. + env.getJavaProject("Project").setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + + fullBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : List is a raw type. References to generic type List should be parameterized [ resource : range : <55,59> category : <130> severity : <1>]\n" + + "Problem : List is a raw type. References to generic type List should be parameterized [ resource : range : <68,72> category : <130> severity : <1>]" + ); + env.addClass(root, "", "X", + "import java.util.List;\n" + + "public class X implements I {\n" + + " public void f(List x, List ls) { \n" + + " }\n" + + "}\n" + ); + incrementalBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : List is a raw type. References to generic type List should be parameterized [ resource : range : <55,59> category : <130> severity : <1>]\n" + + "Problem : List is a raw type. References to generic type List should be parameterized [ resource : range : <68,72> category : <130> severity : <1>]" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427105, [1.8][builder] Differences between incremental and full builds in method contract verification in the presence of type annotations + public void test427105a() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + env.addClass(root, "", "X", + "import java.util.List;\n" + + "public class X implements I {\n" + + " public void f(List x, List ls) { \n" + + " }\n" + + "}\n" + ); + env.addClass(root, "", "I", + "import java.util.List;\n" + + "public interface I {\n" + + " void f(@T List x, List ls);\n" + + "}\n" + ); + env.addClass(root, "", "T", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface T {\n" + + "}\n" + ); + + // force annotation encoding into bindings which is necessary to reproduce. + env.getJavaProject("Project").setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + + fullBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : List is a raw type. References to generic type List should be parameterized [ resource : range : <55,59> category : <130> severity : <1>]\n" + + "Problem : List is a raw type. References to generic type List should be parameterized [ resource : range : <68,72> category : <130> severity : <1>]" + ); + env.addClass(root, "", "X", + "import java.util.List;\n" + + "public class X implements I {\n" + + " public void f(@T List x, List ls) { \n" + + " }\n" + + "}\n" + ); + incrementalBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : List is a raw type. References to generic type List should be parameterized [ resource : range : <55,59> category : <130> severity : <1>]\n" + + "Problem : List is a raw type. References to generic type List should be parameterized [ resource : range : <71,75> category : <130> severity : <1>]" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=428071, [1.8][compiler] Bogus error about incompatible return type during override + public void test428071() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + env.addClass(root, "", "K1", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "interface K1 {\n" + + " public Map get();\n" + + "}\n" + ); + env.addClass(root, "", "K", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "public class K implements K1 {\n" + + " public Map get() {\n" + + " return null;\n" + + " }\n" + + "}\n" + ); + env.getJavaProject("Project").setOption(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.IGNORE); + fullBuild(projectPath); + expectingNoProblems(); + env.addClass(root, "", "K", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "public class K implements K1 {\n" + + " public Map get() {\n" + + " return null;\n" + + " }\n" + + "}\n" + ); + incrementalBuild(projectPath); + expectingNoProblems(); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=430425, [1.8][compiler] Type mismatch: cannot convert from StyleConverter to StyleConverter + public void test430425() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.8"); + String jreDirectory = Util.getJREDirectory(); + String jfxJar = Util.toNativePath(jreDirectory + "/lib/ext/jfxrt.jar"); + File file = new File(jfxJar); + if (file.exists()) + env.addExternalJars(projectPath, Util.concatWithClassLibs(jfxJar, false)); + else + return; + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + env.addClass(root, "javafx.css", "StyleConverter", + "package javafx.css;\n" + + "import com.sun.javafx.css.converters.InsetsConverter;\n" + + "import javafx.geometry.Insets;\n" + + "public class StyleConverter {\n" + + " public static StyleConverter getInsetsConverter() {\n" + + " return InsetsConverter.getInstance();\n" + + " }\n" + + " void fred5555() {\n" + + " }\n" + + "}\n" + ); + env.addClass(root, "com.sun.javafx.css.converters", "InsetsConverter", + "package com.sun.javafx.css.converters;\n" + + "import com.sun.javafx.css.StyleConverterImpl;\n" + + "import javafx.css.ParsedValue;\n" + + "import javafx.css.StyleConverter;\n" + + "import javafx.geometry.Insets;\n" + + "public final class InsetsConverter extends StyleConverterImpl {\n" + + " public static StyleConverter getInstance() {\n" + + " return null;\n" + + " }\n" + + "}\n" + ); + env.addClass(root, "javafx.css", "ParsedValue", + "package javafx.css;\n" + + "public class ParsedValue {\n" + + "}\n" + ); + env.getJavaProject("Project").setOption(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.IGNORE); + fullBuild(projectPath); + expectingNoProblems(); + env.addClass(root, "javafx.css", "StyleConverter", + "package javafx.css;\n" + + "import com.sun.javafx.css.converters.InsetsConverter;\n" + + "import javafx.geometry.Insets;\n" + + "public class StyleConverter {\n" + + " public static StyleConverter getInsetsConverter() {\n" + + " return InsetsConverter.getInstance();\n" + + " }\n" + + " void fred555() {\n" + + " }\n" + + "}\n" + ); + incrementalBuild(projectPath); + expectingNoProblems(); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=435544, [compiler][null] Enum constants not recognised as being NonNull (take2) + public void test435544() throws JavaModelException, IOException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + setupProjectForNullAnnotations(); + env.addClass(root, "p", "Y", + "package p; \n" + + "public enum Y {\n" + + " A,\n" + + " B\n" + + "}\n" + + "\n" + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "p", "X", + "package p; \n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class X {\n" + + " @NonNull\n" + + " public Y y = Y.A; // warning without fix\n" + + " void foo(@NonNull Y y) {}\n" + + " void bar() {\n" + + " foo(Y.A); // warning without fix\n" + + " }\n" + + "}\n" + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=442452, [compiler][regression] Bogus error: The interface Comparable cannot be implemented more than once with different arguments + public void testBug442452() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "Entity", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Entity implements IEntity {\n" + + " public int compareTo(IBasicItem o) {\n" + + " return 0;\n" + + " }\n" + + "}\n"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "IEntity", //$NON-NLS-1$ //$NON-NLS-2$ + "public interface IEntity> extends IBasicItem {\n" + + "}\n"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "IBasicItem", //$NON-NLS-1$ //$NON-NLS-2$ + "public interface IBasicItem extends Comparable {\n" + + "}\n"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "IAdvancedItem", //$NON-NLS-1$ //$NON-NLS-2$ + "public interface IAdvancedItem extends Comparable {\n" + + "}\n"); //$NON-NLS-1$ + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(projectPath, "", "Entity", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Entity implements IEntity, IAdvancedItem {\n" + + " public int compareTo(IBasicItem o) {\n" + + " return 0;\n" + + " }\n" + + "}\n"); //$NON-NLS-1$ + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=442755, + // [compiler] NPE at ProblemHandler.handle + public void testBug442755() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, "bin"); + env.addClass(projectPath, "", "Z", + "public interface Z {}\n"); + fullBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : X cannot be resolved to a type [ resource : " + + " range : <31,32> category : <40> severity : <2>]\n" + + "Problem : Y cannot be resolved to a type [ resource : " + + " range : <45,46> category : <40> severity : <2>]"); + env.addClass(projectPath, "", "Unmarshaller", //$NON-NLS-1$ //$NON-NLS-2$ + "public abstract class Unmarshaller {\n" + + " public CONTEXT getContext() {\n" + + " return null;\n" + + " }\n" + + "}\n"); + incrementalBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : The project was not built since its build path is incomplete." + + " Cannot find the class file for Y. Fix the build path then try building" + + " this project [ resource : range : <-1,-1> category : <10> severity : <2>]\n" + + "Problem : The type Y cannot be resolved. It is indirectly referenced from" + + " required .class files [ resource : range : <0,1> category : <10> severity : <2>]"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=442755, + // [compiler] NPE at ProblemHandler.handle + // Simplified test case. + public void testBug442755a() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, "bin"); + env.addClass(projectPath, "", "Z", + "public class Z {}\n"); + fullBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : Y cannot be resolved to a type [ resource : " + + " range : <27,28> category : <40> severity : <2>]"); + env.addClass(projectPath, "", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "public class X {}\n"); + incrementalBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : The project was not built since its build path is incomplete." + + " Cannot find the class file for Y. Fix the build path then try building" + + " this project [ resource : range : <-1,-1> category : <10> severity : <2>]\n" + + "Problem : The type Y cannot be resolved. It is indirectly referenced from" + + " required .class files [ resource : range : <0,1> category : <10> severity : <2>]"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=445049, + // [compiler] java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding + // cannot be cast to org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding + public void test445049() throws JavaModelException, IOException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + setupProjectForNullAnnotations(); + env.addClass(root, "", "I", + "public interface I { int f = 0;}"); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(root, "", "X", "class X implements I { int i = I.super.f;}"); + + incrementalBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : No enclosing instance of the type I is accessible in scope [" + + " resource : range : <31,38> category : <40> severity : <2>]"); + } + + public void testBug481276a() throws Exception { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + setupProjectForNullAnnotations(); + + // clean status from https://bugs.eclipse.org/bugs/attachment.cgi?id=257687 + env.addClass(root, "testNullAnnotations", "package-info", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package testNullAnnotations;\n"); + env.addClass(root, "testNullAnnotations", "NonNullUtils", + "package testNullAnnotations;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public final class NonNullUtils {\n" + + "\n" + + " public static T[] checkNotNull(T @Nullable [] array) {\n" + + " if (array == null) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " return array;\n" + + " }\n" + + "}\n"); + env.addClass(root, "testNullAnnotations", "Snippet", + "package testNullAnnotations;\n" + + "\n" + + "import static testNullAnnotations.NonNullUtils.checkNotNull;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Snippet {\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void foo() {\n" + + " @NonNull Object @Nullable [] objects = null;\n" + + " @NonNull Object @NonNull [] checked3 = checkNotNull(objects); \n" + + " }\n" + + "}\n"); + + fullBuild(projectPath); + expectingNoProblems(); + + // add an error by removing the necessary @Nullable annotation: + env.addClass(root, "testNullAnnotations", "NonNullUtils", + "package testNullAnnotations;\n" + + "\n" + + "public final class NonNullUtils {\n" + + "\n" + + " public static T[] checkNotNull(T [] array) {\n" + + " if (array == null) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " return array;\n" + + " }\n" + + "}\n"); + + incrementalBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : Dead code [" + + " resource : range : <145,202> category : <90> severity : <1>]\n" + + "Problem : Null type mismatch: required \'@NonNull Object @NonNull[]\' but the provided value is null [" + + " resource : range : <316,323> category : <90> severity : <2>]"); + } + + public void testBug481276b() throws Exception { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + setupProjectForNullAnnotations(); + // clean status: + env.addClass(root, "testNullAnnotations", "package-info", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package testNullAnnotations;\n"); + env.addClass(root, "testNullAnnotations", "NonNullUtils", + "package testNullAnnotations;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public final class NonNullUtils {\n" + + "\n" + + " public static <@Nullable T> T[] checkNotNull(T @Nullable[] array) {\n" + + " if (array == null) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " return array;\n" + + " }\n" + + "}\n"); + env.addClass(root, "testNullAnnotations", "Snippet", + "package testNullAnnotations;\n" + + "\n" + + "import static testNullAnnotations.NonNullUtils.checkNotNull;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Snippet {\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void foo() {\n" + + " @NonNull Object @Nullable [] objects = new @NonNull Object[0];\n" + + " @NonNull Object @NonNull [] checked3 = checkNotNull(objects); \n" + + " }\n" + + "}\n"); + + fullBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : Null type mismatch (type annotations): required \'@NonNull Object @NonNull[]\' but this expression has type \'@Nullable Object @NonNull[]\' [" + + " resource : range : <321,342> category : <90> severity : <2>]\n" + + "Problem : Null type mismatch (type annotations): required \'@Nullable Object @Nullable[]\' but this expression has type \'@NonNull Object @Nullable[]\' [" + + " resource : range : <334,341> category : <90> severity : <2>]"); + + // fix error according to https://bugs.eclipse.org/bugs/show_bug.cgi?id=481276#c4 + env.addClass(root, "testNullAnnotations", "NonNullUtils", + "package testNullAnnotations;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public final class NonNullUtils {\n" + + "\n" + + " public static T[] checkNotNull(T @Nullable[] array) {\n" + + " if (array == null) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " return array;\n" + + " }\n" + + "}\n"); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testBug481276c() throws Exception { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + setupProjectForNullAnnotations(); + + // clean status from https://bugs.eclipse.org/bugs/attachment.cgi?id=257687 + env.addClass(root, "testNullAnnotations", "package-info", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package testNullAnnotations;\n"); + env.addClass(root, "testNullAnnotations", "NonNullUtils", + "package testNullAnnotations;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public final class NonNullUtils {\n" + + "\n" + + " public static T[] checkNotNull(T @Nullable [] array) {\n" + + " if (array == null) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " return array;\n" + + " }\n" + + "}\n"); + env.addClass(root, "testNullAnnotations", "Snippet", + "package testNullAnnotations;\n" + + "\n" + + "import static testNullAnnotations.NonNullUtils.checkNotNull;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Snippet {\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void foo() {\n" + + " @NonNull Object @Nullable [] objects = null;\n" + + " @NonNull Object @NonNull [] checked3 = checkNotNull(objects); \n" + + " }\n" + + "}\n"); + + fullBuild(projectPath); + expectingNoProblems(); + + // add a warning by making @NNBD ineffective: + env.addClass(root, "testNullAnnotations", "package-info", + "@org.eclipse.jdt.annotation.NonNullByDefault({})\n" + + "package testNullAnnotations;\n"); + + incrementalBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : Null type safety (type annotations): The expression of type \'@NonNull Object []\' needs unchecked conversion to conform to \'@NonNull Object @NonNull[]\' [" + + " resource : range : <303,324> category : <90> severity : <1>]"); + } + + public void testBug483744_remove() throws JavaModelException, IOException { + IPath projectPath = env.addProject("Project", "1.8"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + setupProjectForNullAnnotations(); + + env.addClass(root, "testNullAnnotations", "package-info", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package testNullAnnotations;\n"); + env.addClass(root, "testNullAnnotations", "NonNullUtils", + "package testNullAnnotations;\n" + + "\n" + + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public final class NonNullUtils {\n" + + "\n" + + " public static List<@NonNull T> checkNotNullContents(List<@Nullable T> list, List<@NonNull T> nList) {\n" + + " return nList;\n" + + " }\n" + + "}\n"); + env.addClass(root, "testNullAnnotations", "Snippet", + "package testNullAnnotations;\n" + + "\n" + + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "import static testNullAnnotations.NonNullUtils.checkNotNullContents;\n" + + "\n" + + "public class Snippet {\n" + + " public List<@NonNull String> foo(List<@Nullable String> inList, List<@NonNull String> nList) {\n" + + " return checkNotNullContents(inList, nList); \n" + + " }\n" + + "}\n"); + + fullBuild(projectPath); + expectingNoProblems(); + + // remove @Nullable (second type annotation): + env.addClass(root, "testNullAnnotations", "NonNullUtils", + "package testNullAnnotations;\n" + + "\n" + + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public final class NonNullUtils {\n" + + "\n" + + " public static List<@NonNull T> checkNotNullContents(List list, List<@NonNull T> nList) {\n" + + " return nList;\n" + + " }\n" + + "}\n"); + incrementalBuild(projectPath); // was throwing NPE + expectingNoProblems(); + + // and add it again: + env.addClass(root, "testNullAnnotations", "NonNullUtils", + "package testNullAnnotations;\n" + + "\n" + + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public final class NonNullUtils {\n" + + "\n" + + " public static List<@NonNull T> checkNotNullContents(List<@Nullable T> list, List<@NonNull T> nList) {\n" + + " return nList;\n" + + " }\n" + + "}\n"); + incrementalBuild(projectPath); // was throwing NPE + expectingNoProblems(); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Java50Tests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Java50Tests.java new file mode 100644 index 0000000000..c5fc66ebc2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Java50Tests.java @@ -0,0 +1,382 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import junit.framework.Test; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.Util; + +public class Java50Tests extends BuilderTests { + + public Java50Tests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(Java50Tests.class); + } + + public void testAnnotation() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, ""); + + IPath usePath = env.addClass(projectPath, "p", "Use", + "package p;\n" + + "@q.Ann\n" + + "public class Use {\n" + + "}" + ); + env.addClass(projectPath, "q", "Ann", + "package q;\n" + + "public @interface Ann {\n" + + "}" + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(projectPath, "q", "Ann", + "package q;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.METHOD)\n" + + "public @interface Ann {\n" + + "}" + ); + + incrementalBuild(projectPath); + expectingProblemsFor( + usePath, + "Problem : The annotation @Ann is disallowed for this location [ resource : range : <11,17> category : <40> severity : <2>]" + ); + } + + public void testHierarchyCycle() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, ""); + + env.addClass(projectPath, "", "A", + "interface A {}\n" + + "interface B extends A {}\n" + + "interface D extends C {}" + ); + env.addClass(projectPath, "", "C", + "interface C extends B {}" + ); + + fullBuild(projectPath); + expectingNoProblems(); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=214237, dupe of + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=205235 + public void testHierarchyCycleInstanceof() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, ""); + + env.addClass(projectPath, "", "A", + "import java.util.Collection;\n" + + "public abstract class A\n" + + ",S extends Collection> {}\n" + + // a specific grouping of classes is needed to hit the problem using + // the test framework + "abstract class B extends A> {\n" + + " boolean isD() {return this instanceof D;}\n" + + "}\n"+ + "final class D extends C {}\n" + ); + env.addClass(projectPath, "", "C", + "public abstract class C extends B {\n" + + " boolean isD() {return this instanceof D;}\n" + + "}\n" + ); + + fullBuild(projectPath); + expectingNoProblems(); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=231293 + public void testMissingRequiredBinaries() throws JavaModelException { + + IPath p1 = env.addProject("P1", "1.5"); //$NON-NLS-1$ + IPath p2 = env.addProject("P2"); //$NON-NLS-1$ + + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + IPath p2bin = env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + env.addClass(root2, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Y {\n"+ //$NON-NLS-1$ + " public void foo(int i) {}\n"+ //$NON-NLS-1$ + " public void foo(int i, Z z) {}\n"+ //$NON-NLS-1$ + "}\n"+ //$NON-NLS-1$ + "class Z {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + + env.addClassFolder(p1, p2bin, false); + env.removeFile(p2bin.append("p2/Z.class")); //$NON-NLS-1$ + + env.addClass(root1, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " void test(p2.Y y) { y.foo(1); }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(p1); + expectingNoProblems(); + + IPath xx = env.addClass(root1, "p1", "XX", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class XX {\n"+ //$NON-NLS-1$ + " void test(p2.Y y) { y.foo('c', null); }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(p1); + expectingOnlySpecificProblemsFor(p1,new Problem[]{ + new Problem("p1", "The project was not built since its build path is incomplete. Cannot find the class file for p2.Z. Fix the build path then try building this project", p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p1", "The type p2.Z cannot be resolved. It is indirectly referenced from required .class files", xx, 51, 67, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)//$NON-NLS-1$ //$NON-NLS-2$ + }); + } + + public void testParameterizedMemberType() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, ""); + + IPath xPath = env.addClass(projectPath, "", "X", + "class X extends A {}" + ); + + IPath aPath = env.addClass(projectPath, "", "A", + "class A extends B.M> {}" + ); + + IPath bPath = env.addClass(projectPath, "", "B", + "class B extends Missing {\n" + + " class M{}\n" + + "}\n" + + "class Missing {}" + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(projectPath, "", "B", + "class B extends Missing {\n" + + " class M{}\n" + + "}" + ); + + incrementalBuild(projectPath); + expectingSpecificProblemFor(xPath, new Problem("X", "The hierarchy of the type X is inconsistent", xPath, 6, 7, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(aPath, new Problem("A", "The hierarchy of the type A is inconsistent", aPath, 6, 7, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(bPath, new Problem("B", "Missing cannot be resolved to a type", bPath, 19, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(projectPath, "", "X", + "class X extends A {}" + ); + + incrementalBuild(projectPath); + expectingSpecificProblemFor(xPath, new Problem("X", "The hierarchy of the type X is inconsistent", xPath, 6, 7, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(aPath, new Problem("A", "The hierarchy of the type A is inconsistent", aPath, 6, 7, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(bPath, new Problem("B", "Missing cannot be resolved to a type", bPath, 19, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(projectPath, "", "B", + "class B extends Missing {\n" + + " class M{}\n" + + "}" + ); + + incrementalBuild(projectPath); + expectingSpecificProblemFor(xPath, new Problem("X", "The hierarchy of the type X is inconsistent", xPath, 6, 7, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(aPath, new Problem("A", "The hierarchy of the type A is inconsistent", aPath, 6, 7, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingSpecificProblemFor(bPath, new Problem("B", "Missing cannot be resolved to a type", bPath, 19, 26, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + env.addClass(projectPath, "", "B", + "class B extends Missing {\n" + + " class M{}\n" + + "}\n" + + "class Missing {}" + ); + + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testParameterizedType1() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, ""); + + IPath usePath = env.addClass(projectPath, "p", "Use", + "package p;\n" + + "import java.util.ArrayList;\n" + + "import q.Other;\n" + + "public class Use {\n" + + " public Use() {\n" + + " new Other().foo(new ArrayList());\n" + + " }\n" + + "}" + ); + env.addClass(projectPath, "q", "Other", + "package q;\n" + + "import java.util.List;\n" + + "public class Other {\n" + + " public void foo(List ls) {}\n" + + "}" + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(projectPath, "q", "Other", + "package q;\n" + + "import java.util.List;\n" + + "public class Other {\n" + + " public void foo(List ls) {}\n" + + "}" + ); + + incrementalBuild(projectPath); + expectingProblemsFor( + usePath, + "Problem : The method foo(List) in the type Other is not applicable for the arguments (ArrayList) [ resource : range : <104,107> category : <50> severity : <2>]" + ); + } + + public void testParameterizedType2() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, ""); + + IPath usePath = env.addClass(projectPath, "p", "Use", + "package p;\n" + + "import java.util.ArrayList;\n" + + "import q.Other;\n" + + "public class Use {\n" + + " public Use() {\n" + + " new Other().foo(new ArrayList());\n" + + " }\n" + + "}" + ); + env.addClass(projectPath, "q", "Other", + "package q;\n" + + "import java.util.List;\n" + + "public class Other {\n" + + " public void foo(List ls) {}\n" + + "}" + ); + + fullBuild(projectPath); + expectingNoProblems(); + + env.addClass(projectPath, "q", "Other", + "package q;\n" + + "import java.util.List;\n" + + "public class Other {\n" + + " public void foo(List ls) throws Exception {}\n" + + "}" + ); + + incrementalBuild(projectPath); + expectingProblemsFor( + usePath, + "Problem : Unhandled exception type Exception [ resource : range : <92,132> category : <40> severity : <2>]" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=294057 + public void testHierarchyNonCycle() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, ""); + + env.addClass(projectPath, "superint", "SuperInterface", + "package superint;\n" + + "public interface SuperInterface {\n" + + " public interface SuperInterfaceGetter {}\n" + + " public interface SuperInterfaceSetter {}\n" + + "}\n" + ); + env.addClass(projectPath, "subint", "SubInterface", + "package subint;\n" + + "import superint.SuperInterface;\n" + + "public interface SubInterface extends\n" + + " SuperInterface {\n" + + " public interface SubInterfaceGetter extends SuperInterfaceGetter {}\n" + + " public interface SubInterfaceSetter extends SuperInterfaceSetter {}\n" + + "}\n" + ); + + fullBuild(projectPath); + expectingProblemsFor( + projectPath, + "Problem : Bound mismatch: The type SubInterface.SubInterfaceGetter is not a valid substitute for the bounded parameter of the type SuperInterface [ resource : range : <105,136> category : <40> severity : <2>]\n" + + "Problem : Bound mismatch: The type SubInterface.SubInterfaceSetter is not a valid substitute for the bounded parameter of the type SuperInterface [ resource : range : <157,188> category : <40> severity : <2>]\n" + + "Problem : SuperInterfaceGetter cannot be resolved to a type [ resource : range : <244,264> category : <40> severity : <2>]\n" + + "Problem : SuperInterfaceSetter cannot be resolved to a type [ resource : range : <320,340> category : <40> severity : <2>]" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=294057 (variation) + public void testHierarchyNonCycle2() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.setOutputFolder(projectPath, ""); + + env.addClass(projectPath, "superint", "SuperInterface", + "package superint;\n" + + "public interface SuperInterface {\n" + + " public interface SuperInterfaceGetter {}\n" + + " public interface SuperInterfaceSetter {}\n" + + "}\n" + ); + env.addClass(projectPath, "subint", "SubInterface", + "package subint;\n" + + "import superint.SuperInterface;\n" + + "import superint.SuperInterface.SuperInterfaceGetter;\n" + + "import superint.SuperInterface.SuperInterfaceSetter;\n" + + "public interface SubInterface extends\n" + + " SuperInterface {\n" + + " public interface SubInterfaceGetter extends SuperInterfaceGetter {}\n" + + " public interface SubInterfaceSetter extends SuperInterfaceSetter {}\n" + + "}\n" + ); + + fullBuild(projectPath); + expectingNoProblems(); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/LeakTestsAfter9.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/LeakTestsAfter9.java new file mode 100644 index 0000000000..f9c569a8bf --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/LeakTestsAfter9.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2019, 2021 Andrey Loskutov and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Andrey Loskutov - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class LeakTestsAfter9 extends AbstractLeakTest { + + public LeakTestsAfter9(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(LeakTestsAfter9.class); + } + + String getCompatibilityLevel() { + return CompilerOptions.VERSION_9; + } + + @Override + public void testLeaksOnCleanBuild() throws Exception { + super.testLeaksOnCleanBuild(); + } + + @Override + public void testLeaksOnFullBuild() throws Exception { + super.testLeaksOnFullBuild(); + } + + @Override + public void testLeaksOnIncrementalBuild() throws Exception { + super.testLeaksOnIncrementalBuild(); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/LeakTestsBefore9.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/LeakTestsBefore9.java new file mode 100644 index 0000000000..f3a837f3bd --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/LeakTestsBefore9.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2019, 2021 Andrey Loskutov and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Andrey Loskutov - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class LeakTestsBefore9 extends AbstractLeakTest { + + public LeakTestsBefore9(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(LeakTestsBefore9.class); + } + + String getCompatibilityLevel() { + return CompilerOptions.VERSION_1_4; + } + + @Override + public void testLeaksOnCleanBuild() throws Exception { + super.testLeaksOnCleanBuild(); + } + + @Override + public void testLeaksOnFullBuild() throws Exception { + super.testLeaksOnFullBuild(); + } + + @Override + public void testLeaksOnIncrementalBuild() throws Exception { + super.testLeaksOnIncrementalBuild(); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/MultiProjectTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/MultiProjectTests.java new file mode 100644 index 0000000000..5f5ab47847 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/MultiProjectTests.java @@ -0,0 +1,2211 @@ +/******************************************************************************* + * Copyright (c) 2000, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.util.Hashtable; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IAccessRule; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.test.OrderedTestSuite; + +import junit.framework.Test; + + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class MultiProjectTests extends BuilderTests { + + public MultiProjectTests(String name) { + super(name); + } + + public static Test suite() { + return new OrderedTestSuite(MultiProjectTests.class); + } + + public void testCompileOnlyDependent() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + env.addClass(root2, "", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "public class B extends A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath project3Path = env.addProject("Project3"); //$NON-NLS-1$ + env.addExternalJars(project3Path, Util.getJavaClassLibs()); + IPath root3 = env.getPackageFragmentRootPath(project3Path, ""); //$NON-NLS-1$ + env.addClass(root3, "", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "public class C {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + env.addClass(root1, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {\n"+ //$NON-NLS-1$ + " int x;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + incrementalBuild(); + env.waitForAutoBuild(); + expectingCompiledClasses(new String[]{"A", "B"}); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(project1Path); + env.removeProject(project2Path); + env.removeProject(project3Path); + } + + // 14103 - avoid recompiling unaffected sources in dependent projects + public void testCompileOnlyStructuralDependent() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.addClass(root1, "", "Unreferenced", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Unreferenced {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + env.addClass(root2, "", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "public class B extends A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath project3Path = env.addProject("Project3"); //$NON-NLS-1$ + env.addExternalJars(project3Path, Util.getJavaClassLibs()); + IPath root3 = env.getPackageFragmentRootPath(project3Path, ""); //$NON-NLS-1$ + env.addClass(root3, "", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "public class C {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + // non-structural change should not fool dependent projcts + env.addClass(root1, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {\n"+ //$NON-NLS-1$ + " // add comment (non-structural change)\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + // structural change, but no actual dependents + env.addClass(root1, "", "Unreferenced", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Unreferenced {\n"+ //$NON-NLS-1$ + " int x; //structural change\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + incrementalBuild(); + env.waitForAutoBuild(); + expectingCompiledClasses(new String[]{"A", "Unreferenced"}); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(project1Path); + env.removeProject(project2Path); + env.removeProject(project3Path); + } + + public void testRemoveField() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE); //$NON-NLS-1$ + JavaCore.setOptions(options); + + //---------------------------- + // Step 1 + //---------------------------- + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {\n"+ //$NON-NLS-1$ + " public int x;\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + IPath b = env.addClass(root2, "", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "public class B {\n"+ //$NON-NLS-1$ + " public void foo(){\n"+ //$NON-NLS-1$ + " int x = new A().x;\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + env.addClass(root1, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + incrementalBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor(b, new Problem("B.foo()", "x cannot be resolved or is not a field", b, 61, 62, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(project1Path); + env.removeProject(project2Path); + } + + public void testCompileOrder() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + //---------------------------- + // Project1 + //---------------------------- + IPath p1 = env.addProject("P1"); //$NON-NLS-1$ + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + IPath c1 = env.addClass(root1, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " W w;\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath p2 = env.addProject("P2"); //$NON-NLS-1$ + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + IPath c2 = env.addClass(root2, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Y {\n"+ //$NON-NLS-1$ + " W w;\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath p3 = env.addProject("P3"); //$NON-NLS-1$ + env.addExternalJars(p3, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$ + IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$ + env.setOutputFolder(p3, "bin"); //$NON-NLS-1$ + + IPath c3 = env.addClass(root3, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class Z {\n"+ //$NON-NLS-1$ + " W w;\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.setBuildOrder(new String[]{"P1", "P3", "P2"});//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + + expectingCompilingOrder(new String[] { "/P1/src/p1/X.java", "/P3/src/p3/Z.java", "/P2/src/p2/Y.java" }); + IPath workspaceRootPath = env.getWorkspaceRootPath(); + expectingOnlySpecificProblemsFor(workspaceRootPath,new Problem[]{ + new Problem("p3", "W cannot be resolved to a type", c3, 31, 32, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p2", "W cannot be resolved to a type", c2, 31, 32, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p1", "W cannot be resolved to a type", c1, 31, 32, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)//$NON-NLS-1$ //$NON-NLS-2$ + }); + JavaCore.setOptions(options); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); + } + + public void testCyclesCleared() throws JavaModelException { + IPath p1 = env.addProject("P1"); //$NON-NLS-1$ + IPath p2 = env.addProject("P2"); //$NON-NLS-1$ + try { + env.addRequiredProject(p1, p2); + env.addRequiredProject(p2, p1); + + fullBuild(); + env.waitForAutoBuild(); + + printProblems(); + expectingOnlySpecificProblemsFor(p1, new Problem[] { + new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), + new Problem("p1", + "The project cannot be built until build path errors are resolved", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) + }); + expectingOnlySpecificProblemsFor(p2, new Problem[] { + new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), + new Problem("p2", + "The project cannot be built until build path errors are resolved", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR) + }); + + env.removeRequiredProject(p1, p2); + + fullBuild(); + env.waitForAutoBuild(); + + expectingNoProblems(); + } finally { + env.removeProject(p1); + env.removeProject(p2); + } + } + + public void testCycle1() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + //---------------------------- + // Project1 + //---------------------------- + IPath p1 = env.addProject("P1"); //$NON-NLS-1$ + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + env.addClass(root1, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "import p2.Y;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " public void bar(Y y){\n"+ //$NON-NLS-1$ + " y.zork();\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath p2 = env.addProject("P2"); //$NON-NLS-1$ + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + env.addClass(root2, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.X;\n"+ //$NON-NLS-1$ + "import p3.Z;\n"+ //$NON-NLS-1$ + "public class Y extends Z{\n"+ //$NON-NLS-1$ + " public X zork(){\n"+ //$NON-NLS-1$ + " X x = foo();\n"+ //$NON-NLS-1$ + " x.bar(this);\n"+ //$NON-NLS-1$ + " return x;\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath p3 = env.addProject("P3"); //$NON-NLS-1$ + env.addExternalJars(p3, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$ + IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$ + env.setOutputFolder(p3, "bin"); //$NON-NLS-1$ + + env.addClass(root3, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "import p1.X;\n"+ //$NON-NLS-1$ + "public class Z {\n"+ //$NON-NLS-1$ + " public X foo(){\n"+ //$NON-NLS-1$ + " return null;\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + // for Project1 + env.addRequiredProject(p1, p2); + env.addRequiredProject(p1, p3); + // for Project2 + env.addRequiredProject(p2, p1); + env.addRequiredProject(p2, p3); + // for Project3 + env.addRequiredProject(p3, p1); + + try { + env.setBuildOrder(new String[]{"P1", "P2", "P3"});//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + + expectingCompilingOrder(new String[] { "/P1/src/p1/X.java", "/P2/src/p2/Y.java", "/P3/src/p3/Z.java", + "/P1/src/p1/X.java", "/P2/src/p2/Y.java", "/P3/src/p3/Z.java", "/P1/src/p1/X.java" }); + expectingOnlySpecificProblemFor(p1, new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + expectingOnlySpecificProblemFor(p2,new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + expectingOnlySpecificProblemFor(p3,new Problem("p3", + "One or more cycles were detected in the build path of project 'P3'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + + JavaCore.setOptions(options); + } finally { + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); + } + } + + public void testCycle2() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + //---------------------------- + // Project1 + //---------------------------- + IPath p1 = env.addProject("P1"); //$NON-NLS-1$ + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + env.addClass(root1, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "import p2.Y;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " public void bar(Y y, int i){\n"+ //$NON-NLS-1$ + " y.zork();\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath p2 = env.addProject("P2"); //$NON-NLS-1$ + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + IPath c2 = env.addClass(root2, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.X;\n"+ //$NON-NLS-1$ + "import p3.Z;\n"+ //$NON-NLS-1$ + "public class Y extends Z{\n"+ //$NON-NLS-1$ + " public X zork(){\n"+ //$NON-NLS-1$ + " X x = foo();\n"+ //$NON-NLS-1$ + " x.bar(this);\n"+ //$NON-NLS-1$ + " return x;\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath p3 = env.addProject("P3"); //$NON-NLS-1$ + env.addExternalJars(p3, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$ + IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$ + env.setOutputFolder(p3, "bin"); //$NON-NLS-1$ + + env.addClass(root3, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "import p1.X;\n"+ //$NON-NLS-1$ + "public class Z {\n"+ //$NON-NLS-1$ + " public X foo(){\n"+ //$NON-NLS-1$ + " return null;\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + // for Project1 + env.addRequiredProject(p1, p2); + env.addRequiredProject(p1, p3); + // for Project2 + env.addRequiredProject(p2, p1); + env.addRequiredProject(p2, p3); + // for Project3 + env.addRequiredProject(p3, p1); + + try { + env.setBuildOrder(new String[]{"P1", "P2", "P3"});//$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingCompilingOrder(new String[] { "/P1/src/p1/X.java", "/P2/src/p2/Y.java", "/P3/src/p3/Z.java", + "/P1/src/p1/X.java", "/P2/src/p2/Y.java", "/P3/src/p3/Z.java", "/P1/src/p1/X.java" }); + expectingOnlySpecificProblemFor(p1,new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + expectingOnlySpecificProblemsFor(p2,new Problem[]{ + new Problem("p2", "The method bar(Y, int) in the type X is not applicable for the arguments (Y)", c2, 106, 109, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + expectingOnlySpecificProblemFor(p3,new Problem("p3", + "One or more cycles were detected in the build path of project 'P3'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + + JavaCore.setOptions(options); + } finally { + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); + } + } + + public void testCycle3() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + //---------------------------- + // Project1 + //---------------------------- + IPath p1 = env.addProject("P1"); //$NON-NLS-1$ + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + env.addClass(root1, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "import p2.Y;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " public void bar(Y y){\n"+ //$NON-NLS-1$ + " y.zork();\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath p2 = env.addProject("P2"); //$NON-NLS-1$ + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + IPath c2 = env.addClass(root2, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.X;\n"+ //$NON-NLS-1$ + "import p3.Z;\n"+ //$NON-NLS-1$ + "public class Y extends Z{\n"+ //$NON-NLS-1$ + " public X zork(){\n"+ //$NON-NLS-1$ + " X x = foo();\n"+ //$NON-NLS-1$ + " x.bar(this);\n"+ //$NON-NLS-1$ + " return x;\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath p3 = env.addProject("P3"); //$NON-NLS-1$ + env.addExternalJars(p3, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$ + IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$ + env.setOutputFolder(p3, "bin"); //$NON-NLS-1$ + + env.addClass(root3, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "import p1.X;\n"+ //$NON-NLS-1$ + "public class Z {\n"+ //$NON-NLS-1$ + " public X foo(){\n"+ //$NON-NLS-1$ + " return null;\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + // for Project1 + env.addRequiredProject(p1, p2); + env.addRequiredProject(p1, p3); + // for Project2 + env.addRequiredProject(p2, p1); + env.addRequiredProject(p2, p3); + // for Project3 + env.addRequiredProject(p3, p1); + + try { + env.setBuildOrder(new String[]{"P1", "P2", "P3"});//$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + + expectingCompilingOrder(new String[] { "/P1/src/p1/X.java", "/P2/src/p2/Y.java", "/P3/src/p3/Z.java", + "/P1/src/p1/X.java", "/P2/src/p2/Y.java", "/P3/src/p3/Z.java", "/P1/src/p1/X.java" }); + expectingOnlySpecificProblemFor(p1,new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + expectingOnlySpecificProblemFor(p2,new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + expectingOnlySpecificProblemFor(p3,new Problem("p3", + "One or more cycles were detected in the build path of project 'P3'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + + env.addClass(root1, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "import p2.Y;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " public void bar(Y y, int i){\n"+ //$NON-NLS-1$ + " y.zork();\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + incrementalBuild(); + env.waitForAutoBuild(); + expectingCompilingOrder(new String[] { "/P1/src/p1/X.java", "/P2/src/p2/Y.java", "/P3/src/p3/Z.java" }); + expectingOnlySpecificProblemFor(p1,new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + expectingOnlySpecificProblemsFor(p2,new Problem[]{ + new Problem("p2", "The method bar(Y, int) in the type X is not applicable for the arguments (Y)", c2, 106, 109, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + expectingOnlySpecificProblemFor(p3,new Problem("p3", + "One or more cycles were detected in the build path of project 'P3'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + + JavaCore.setOptions(options); + } finally { + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); + } + } + public void testCycle4() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING); //$NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + //---------------------------- + // Project1 + //---------------------------- + IPath p1 = env.addProject("P1"); //$NON-NLS-1$ + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + //---------------------------- + // Project2 + //---------------------------- + IPath p2 = env.addProject("P2"); //$NON-NLS-1$ + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + IPath c2 = env.addClass(root2, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p1.X;\n"+ //$NON-NLS-1$ + "import p3.Z;\n"+ //$NON-NLS-1$ + "public class Y extends Z{\n"+ //$NON-NLS-1$ + " public X zork(){\n"+ //$NON-NLS-1$ + " X x = foo();\n"+ //$NON-NLS-1$ + " x.bar(this);\n"+ //$NON-NLS-1$ + " return x;\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath p3 = env.addProject("P3"); //$NON-NLS-1$ + env.addExternalJars(p3, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$ + IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$ + env.setOutputFolder(p3, "bin"); //$NON-NLS-1$ + + IPath c3 = env.addClass(root3, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "import p1.X;\n"+ //$NON-NLS-1$ + "public class Z {\n"+ //$NON-NLS-1$ + " public X foo(){\n"+ //$NON-NLS-1$ + " return null;\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + // for Project1 + env.addRequiredProject(p1, p2); + env.addRequiredProject(p1, p3); + // for Project2 + env.addRequiredProject(p2, p1); + env.addRequiredProject(p2, p3); + // for Project3 + env.addRequiredProject(p3, p1); + + try { + env.setBuildOrder(new String[]{"P1", "P2", "P3"});//$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + + expectingCompilingOrder(new String[] { "/P2/src/p2/Y.java", "/P3/src/p3/Z.java", "/P2/src/p2/Y.java" }); + expectingOnlySpecificProblemFor(p1,new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + expectingOnlySpecificProblemsFor(p2,new Problem[]{ + new Problem("p2", "X cannot be resolved to a type", c2, 87, 88, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p2", "The method foo() from the type Z refers to the missing type X", c2, 93, 96, CategorizedProblem.CAT_MEMBER, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p2", "The import p1 cannot be resolved", c2, 19, 21, CategorizedProblem.CAT_IMPORT, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p2", "X cannot be resolved to a type", c2, 73, 74, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + expectingOnlySpecificProblemsFor(p3,new Problem[]{ + new Problem("p3", "X cannot be resolved to a type", c3, 51, 52, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p3", "The import p1 cannot be resolved", c3, 19, 21, CategorizedProblem.CAT_IMPORT, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p3", + "One or more cycles were detected in the build path of project 'P3'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + + env.addClass(root1, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "import p2.Y;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + " public void bar(Y y){\n"+ //$NON-NLS-1$ + " y.zork();\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + incrementalBuild(); + env.waitForAutoBuild(); + expectingCompilingOrder(new String[] { "/P1/src/p1/X.java", "/P2/src/p2/Y.java", "/P3/src/p3/Z.java", + "/P1/src/p1/X.java", "/P2/src/p2/Y.java" }); + expectingOnlySpecificProblemFor(p1,new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + expectingOnlySpecificProblemFor(p2,new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + expectingOnlySpecificProblemFor(p3,new Problem("p3", + "One or more cycles were detected in the build path of project 'P3'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2, P3}\n" + + "->{P1, P3}", + p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING)); + + JavaCore.setOptions(options); + } finally { + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); + } + } + + public void testCycle5() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING); // $NON-NLS-1$ + + JavaCore.setOptions(newOptions); + + // ---------------------------- + // Project1 + // ---------------------------- + IPath p1 = env.addProject("P1"); //$NON-NLS-1$ + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + IPath c1 = env.addClass(root1, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "import p2.*;\n" + //$NON-NLS-1$ + "import p22.*;\n" + //$NON-NLS-1$ + "public class X {\n" + //$NON-NLS-1$ + " Y y;\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + // ---------------------------- + // Project2 + // ---------------------------- + IPath p2 = env.addProject("P2"); //$NON-NLS-1$ + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + IPath c2 = env.addClass(root2, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n" + //$NON-NLS-1$ + "import p1.*;\n" + //$NON-NLS-1$ + "import p11.*;\n" + //$NON-NLS-1$ + "public class Y {\n" + //$NON-NLS-1$ + " X x;\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + // for Project1 + env.addRequiredProject(p1, p2); + // for Project2 + env.addRequiredProject(p2, p1); + + try { + env.setBuildOrder(new String[] { "P1", "P2" });//$NON-NLS-1$ //$NON-NLS-2$ + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + + expectingCompilingOrder(new String[] { "/P1/src/p1/X.java", "/P2/src/p2/Y.java", "/P1/src/p1/X.java", + "/P2/src/p2/Y.java" }); + expectingOnlySpecificProblemsFor(p1, new Problem[] { + new Problem("p1", "The import p22 cannot be resolved", c1, 32, 35, CategorizedProblem.CAT_IMPORT, //$NON-NLS-1$ //$NON-NLS-2$ + IMarker.SEVERITY_ERROR), new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) }); + expectingOnlySpecificProblemsFor(p2, new Problem[] { + new Problem("p2", "The import p11 cannot be resolved", c2, 32, 35, CategorizedProblem.CAT_IMPORT, //$NON-NLS-1$ //$NON-NLS-2$ + IMarker.SEVERITY_ERROR), new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) }); + + env.addClass(root1, "p11", "XX", //$NON-NLS-1$ //$NON-NLS-2$ + "package p11;\n" + //$NON-NLS-1$ + "public class XX {\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.addClass(root2, "p22", "YY", //$NON-NLS-1$ //$NON-NLS-2$ + "package p22;\n" + //$NON-NLS-1$ + "public class YY {\n" + //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingCompilingOrder(new String[] { "/P1/src/p11/XX.java", "/P2/src/p22/YY.java", "/P2/src/p2/Y.java", + "/P1/src/p1/X.java" }); + expectingOnlySpecificProblemsFor(p1, new Problem[] { + new Problem("p1", "The import p22 is never used", c1, 32, 35, //$NON-NLS-1$ //$NON-NLS-2$ + CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_WARNING), new Problem("p1", //$NON-NLS-1$ + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) }); + expectingOnlySpecificProblemsFor(p2, new Problem[] { + new Problem("p2", "The import p11 is never used", c2, 32, 35, //$NON-NLS-1$ //$NON-NLS-2$ + CategorizedProblem.CAT_UNNECESSARY_CODE, IMarker.SEVERITY_WARNING), new Problem("p2", //$NON-NLS-1$ + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) }); + + JavaCore.setOptions(options); + } finally { + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + } + } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=114349 +// this one fails; compare with testCycle7 (only one change in Object source), +// which passes +public void testCycle6() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING); + + JavaCore.setOptions(newOptions); + + //---------------------------- + // Project1 + //---------------------------- + IPath p1 = env.addProject("P1"); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); + IPath root1 = env.addPackageFragmentRoot(p1, "src"); + env.setOutputFolder(p1, "bin"); + + env.addClass(root1, "java/lang", "Object", + "package java.lang;\n" + + "public class Object {\n" + + " Class getClass() { return null; }\n" + + " String toString() { return \"\"; }\n" + // the line that changes + "}\n" + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath p2 = env.addProject("P2"); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); + IPath root2 = env.addPackageFragmentRoot(p2, "src"); + env.setOutputFolder(p2, "bin"); + + env.addClass(root2, "java/lang", "Class", + "package java.lang;\n" + + "public class Class {\n" + + " String getName() { return \"\"; };\n" + + "}\n" + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath p3 = env.addProject("P3"); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); + IPath root3 = env.addPackageFragmentRoot(p3, "src"); + env.setOutputFolder(p3, "bin"); + + env.addClass(root3, "java/lang", "String", + "package java.lang;\n" + + "public class String {\n" + + "}\n" + ); + + // Dependencies + IPath[] accessiblePaths = new IPath[] {new Path("java/lang/*")}; + IPath[] forbiddenPaths = new IPath[] {new Path("**/*")}; + env.addRequiredProject(p1, p2, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p1, p3, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p2, p1, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p2, p3, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p3, p1, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p3, p2, accessiblePaths, forbiddenPaths, false); + + try { + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingOnlySpecificProblemsFor(p1,new Problem[]{ + new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}\n" + + "P1->{P2, P3}\n" + + "->{P1, P3}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + expectingOnlySpecificProblemsFor(p2,new Problem[]{ + new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}\n" + + "->{P2, P3}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + expectingOnlySpecificProblemsFor(p3,new Problem[]{ + new Problem("p3", + "One or more cycles were detected in the build path of project 'P3'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2, P3}\n" + + "->{P2, P3}\n" + + "->{P1, P3}", + p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + + } finally { + JavaCore.setOptions(options); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=114349 +// this one passes; compare with testCycle6 (only one change in Object source), +// which fails +public void testCycle7() throws JavaModelException { + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING); + + JavaCore.setOptions(newOptions); + + //---------------------------- + // Project1 + //---------------------------- + IPath p1 = env.addProject("P1"); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); + IPath root1 = env.addPackageFragmentRoot(p1, "src"); + env.setOutputFolder(p1, "bin"); + + env.addClass(root1, "java/lang", "Object", + "package java.lang;\n" + + "public class Object {\n" + + " Class getClass() { return null; }\n" + + " String toString() { return null; }\n" + // the line that changes + "}\n" + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath p2 = env.addProject("P2"); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); + IPath root2 = env.addPackageFragmentRoot(p2, "src"); + env.setOutputFolder(p2, "bin"); + + env.addClass(root2, "java/lang", "Class", + "package java.lang;\n" + + "public class Class {\n" + + " String getName() { return \"\"; };\n" + + "}\n" + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath p3 = env.addProject("P3"); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); + IPath root3 = env.addPackageFragmentRoot(p3, "src"); + env.setOutputFolder(p3, "bin"); + + env.addClass(root3, "java/lang", "String", + "package java.lang;\n" + + "public class String {\n" + + "}\n" + ); + + // Dependencies + IPath[] accessiblePaths = new IPath[] {new Path("java/lang/*")}; + IPath[] forbiddenPaths = new IPath[] {new Path("**/*")}; + env.addRequiredProject(p1, p2, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p1, p3, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p2, p1, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p2, p3, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p3, p1, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p3, p2, accessiblePaths, forbiddenPaths, false); + + try { + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingOnlySpecificProblemsFor(p1,new Problem[]{ + new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}\n" + + "P1->{P2, P3}\n" + + "->{P1, P3}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + expectingOnlySpecificProblemsFor(p2,new Problem[]{ + new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2}\n" + + "->{P1, P2, P3}\n" + + "->{P2, P3}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + expectingOnlySpecificProblemsFor(p3,new Problem[]{ + new Problem("p3", + "One or more cycles were detected in the build path of project 'P3'. The paths towards the cycle and cycle are:\n" + + "->{P1, P2, P3}\n" + + "->{P2, P3}\n" + + "->{P1, P3}", + p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + + } finally { + JavaCore.setOptions(options); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); + } +} + public void testCycle8() throws JavaModelException { + // specifically tests projects with (transitive) dependencies on a cycle, i.e., error messages with a non-empty prefix + Hashtable options = JavaCore.getOptions(); + Hashtable newOptions = JavaCore.getOptions(); + newOptions.put(JavaCore.CORE_CIRCULAR_CLASSPATH, JavaCore.WARNING); + + JavaCore.setOptions(newOptions); + + IPath p1 = env.addProject("P1"); + IPath p2 = env.addProject("P2"); + IPath p3 = env.addProject("P3"); + IPath p4 = env.addProject("P4"); + + // Dependencies + IPath[] accessiblePaths = new IPath[] {new Path("java/lang/*")}; + IPath[] forbiddenPaths = new IPath[] {new Path("**/*")}; + env.addRequiredProject(p1, p2, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p2, p3, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p3, p4, accessiblePaths, forbiddenPaths, false); + env.addRequiredProject(p4, p3, accessiblePaths, forbiddenPaths, false); + + try { + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingOnlySpecificProblemsFor(p1,new Problem[]{ + new Problem("p1", + "One or more cycles were detected in the build path of project 'P1'. The paths towards the cycle and cycle are:\n" + + "P1, P2->{P3, P4}", + p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + expectingOnlySpecificProblemsFor(p2,new Problem[]{ + new Problem("p2", + "One or more cycles were detected in the build path of project 'P2'. The paths towards the cycle and cycle are:\n" + + "P2->{P3, P4}", + p2, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING), + }); + expectingOnlySpecificProblemsFor(p3,new Problem[]{ + new Problem("p3", + "One or more cycles were detected in the build path of project 'P3'. The paths towards the cycle and cycle are:\n" + + "->{P3, P4}", + p3, -1,-1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_WARNING) + }); + + } finally { + JavaCore.setOptions(options); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); + env.removeProject(p4); + } + } + + /* + * Full buid case + */ + public void testExcludePartOfAnotherProject1() throws JavaModelException { + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "p.api", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.api;\n" + //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.addClass(root1, "p.internal", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.internal;\n" + //$NON-NLS-1$ + "public class B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path, new IPath[] {}, new IPath[] {new Path("**/internal/")}, false); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + env.addClass(root2, "", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "public class C extends p.api.A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + IPath d = env.addClass(root2, "", "D", //$NON-NLS-1$ //$NON-NLS-2$ + "public class D extends p.internal.B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor(project2Path, new Problem("", "Access restriction: The type 'B' is not API (restriction on required project 'Project1')", d, 23, 35, CategorizedProblem.CAT_RESTRICTION, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(project1Path); + env.removeProject(project2Path); + } + + /* + * Incremental buid case + */ + public void testExcludePartOfAnotherProject2() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "p.api", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.api;\n" + //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.addClass(root1, "p.internal", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.internal;\n" + //$NON-NLS-1$ + "public class B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path, new IPath[] {}, new IPath[] {new Path("**/internal/")}, false); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + env.addClass(root2, "", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "public class C extends p.api.A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + IPath d = env.addClass(root2, "", "D", //$NON-NLS-1$ //$NON-NLS-2$ + "public class D extends p.internal.B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor(project2Path, new Problem("", "Access restriction: The type 'B' is not API (restriction on required project 'Project1')", d, 23, 35, CategorizedProblem.CAT_RESTRICTION, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(project1Path); + env.removeProject(project2Path); + } + + /* + * Fix access restriction problem + */ + public void testExcludePartOfAnotherProject3() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "p.api", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.api;\n" + //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.addClass(root1, "p.internal", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.internal;\n" + //$NON-NLS-1$ + "public class B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path, new IPath[] {}, new IPath[] {new Path("**/internal/")}, false); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + env.addClass(root2, "", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "public class C extends p.api.A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + IPath d = env.addClass(root2, "", "D", //$NON-NLS-1$ //$NON-NLS-2$ + "public class D extends p.internal.B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor(project2Path, new Problem("", "Access restriction: The type 'B' is not API (restriction on required project 'Project1')", d, 23, 35, CategorizedProblem.CAT_RESTRICTION, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + //---------------------------- + // Step 2 + //---------------------------- + env.removeRequiredProject(project2Path, project1Path); + env.addRequiredProject(project2Path, project1Path, new IPath[] {}, new IPath[] {}, false); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + env.removeProject(project1Path); + env.removeProject(project2Path); + } + + /* + * Full buid case + */ + public void testIncludePartOfAnotherProject1() throws JavaModelException { + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "p.api", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.api;\n" + //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.addClass(root1, "p.internal", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.internal;\n" + //$NON-NLS-1$ + "public class B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path, new IPath[] {new Path("**/api/")}, new IPath[] {new Path("**")}, false); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + env.addClass(root2, "", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "public class C extends p.api.A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + IPath d = env.addClass(root2, "", "D", //$NON-NLS-1$ //$NON-NLS-2$ + "public class D extends p.internal.B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor(project2Path, new Problem("", "Access restriction: The type 'B' is not API (restriction on required project 'Project1')", d, 23, 35, CategorizedProblem.CAT_RESTRICTION, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(project1Path); + env.removeProject(project2Path); + } + + /* + * Incremental buid case + */ + public void testIncludePartOfAnotherProject2() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "p.api", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.api;\n" + //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.addClass(root1, "p.internal", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.internal;\n" + //$NON-NLS-1$ + "public class B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path, new IPath[] {new Path("**/api/")}, new IPath[] {new Path("**")}, false); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + env.addClass(root2, "", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "public class C extends p.api.A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + IPath d = env.addClass(root2, "", "D", //$NON-NLS-1$ //$NON-NLS-2$ + "public class D extends p.internal.B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor(project2Path, new Problem("", "Access restriction: The type 'B' is not API (restriction on required project 'Project1')", d, 23, 35, CategorizedProblem.CAT_RESTRICTION, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(project1Path); + env.removeProject(project2Path); + } + + /* + * Fix access restriction problem + */ + public void testIncludePartOfAnotherProject3() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "p.api", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.api;\n" + //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.addClass(root1, "p.internal", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.internal;\n" + //$NON-NLS-1$ + "public class B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path, new IPath[] {new Path("**/api/")}, new IPath[] {new Path("**")}, false); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + env.addClass(root2, "", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "public class C extends p.api.A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + IPath d = env.addClass(root2, "", "D", //$NON-NLS-1$ //$NON-NLS-2$ + "public class D extends p.internal.B {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor(project2Path, new Problem("", "Access restriction: The type 'B' is not API (restriction on required project 'Project1')", d, 23, 35, CategorizedProblem.CAT_RESTRICTION, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + + //---------------------------- + // Step 2 + //---------------------------- + env.removeRequiredProject(project2Path, project1Path); + env.addRequiredProject(project2Path, project1Path, new IPath[] {}, new IPath[] {}, false); + + incrementalBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + env.removeProject(project1Path); + env.removeProject(project2Path); + } + + /* + * Ensures that a type matching a ignore-if-better non-accessible rule is further found when accessible + * on another classpath entry. + * (regression test for bug 98127 Access restrictions started showing up after switching to bundle) + */ + public void testIgnoreIfBetterNonAccessibleRule1() throws JavaModelException { + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + env.addClass(root2, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath project3Path = env.addProject("Project3"); //$NON-NLS-1$ + env.addExternalJars(project3Path, Util.getJavaClassLibs()); + env.addRequiredProject(project3Path, project1Path, new Path("**/p/"), IAccessRule.K_NON_ACCESSIBLE | IAccessRule.IGNORE_IF_BETTER); + env.addRequiredProject(project3Path, project2Path, new Path("**/p/A"), IAccessRule.K_ACCESSIBLE); + IPath root3 = env.getPackageFragmentRootPath(project3Path, ""); //$NON-NLS-1$ + env.addClass(root3, "p3", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n" + //$NON-NLS-1$ + "public class B extends p.A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + env.removeProject(project1Path); + env.removeProject(project2Path); + env.removeProject(project3Path); + } + + /* + * Ensures that a type matching a ignore-if-better non-accessible rule is further found when accessible + * on another classpath entry. + * (regression test for bug 98127 Access restrictions started showing up after switching to bundle) + */ + public void testIgnoreIfBetterNonAccessibleRule2() throws JavaModelException { + //---------------------------- + // Project1 + //---------------------------- + IPath project1Path = env.addProject("Project1"); //$NON-NLS-1$ + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + IPath root1 = env.getPackageFragmentRootPath(project1Path, ""); //$NON-NLS-1$ + env.addClass(root1, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath project2Path = env.addProject("Project2"); //$NON-NLS-1$ + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + IPath root2 = env.getPackageFragmentRootPath(project2Path, ""); //$NON-NLS-1$ + env.addClass(root2, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + //$NON-NLS-1$ + "public class A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath project3Path = env.addProject("Project3"); //$NON-NLS-1$ + env.addExternalJars(project3Path, Util.getJavaClassLibs()); + env.addRequiredProject(project3Path, project1Path, new Path("**/p/"), IAccessRule.K_NON_ACCESSIBLE | IAccessRule.IGNORE_IF_BETTER); + env.addRequiredProject(project3Path, project2Path, new Path("**/p/A"), IAccessRule.K_DISCOURAGED); + IPath root3 = env.getPackageFragmentRootPath(project3Path, ""); //$NON-NLS-1$ + IPath b = env.addClass(root3, "p3", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n" + //$NON-NLS-1$ + "public class B extends p.A {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemFor(project3Path, new Problem("", "Discouraged access: The type 'A' is not API (restriction on required project 'Project2')", b, 35, 38, CategorizedProblem.CAT_RESTRICTION, IMarker.SEVERITY_WARNING)); //$NON-NLS-1$ //$NON-NLS-2$ + env.removeProject(project1Path); + env.removeProject(project2Path); + env.removeProject(project3Path); + } + + public void testMissingRequiredBinaries() throws JavaModelException { + + IPath p1 = env.addProject("P1"); //$NON-NLS-1$ + IPath p2 = env.addProject("P2"); //$NON-NLS-1$ + IPath p3 = env.addProject("P3"); //$NON-NLS-1$ + + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.addRequiredProject(p1, p2); + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + env.addRequiredProject(p2, p3); + env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + env.addExternalJars(p3, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$ + IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$ + env.setOutputFolder(p3, "bin"); //$NON-NLS-1$ + + IPath x = env.addClass(root1, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "import p2.*;\n"+ //$NON-NLS-1$ + "public class X extends Y{\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root2, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "import p3.*;\n"+ //$NON-NLS-1$ + "public class Y extends Z {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(root3, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class Z {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + try { + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + + expectingOnlySpecificProblemsFor(p1,new Problem[]{ + new Problem("p1", "The type p3.Z cannot be resolved. It is indirectly referenced from required .class files", x, 48, 49, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR),//$NON-NLS-1$ //$NON-NLS-2$ + new Problem("p1", "The project was not built since its build path is incomplete. Cannot find the class file for p3.Z. Fix the build path then try building this project", p1, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR)//$NON-NLS-1$ //$NON-NLS-2$ + }); + } finally { + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p1); + env.removeProject(p3); + } + } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159118 +// contrast this with test101: get an error when the class folder is not +// exported from the target project - P1 here +public void test100_class_folder_exported() throws JavaModelException { + IPath P1 = env.addProject("P1"); + env.setOutputFolder(P1, "bin"); + env.addExternalJars(P1, Util.getJavaClassLibs()); + env.addClass( + env.addPackage( + env.getPackageFragmentRootPath(P1, ""), "p"), + "A", + "package p;\n" + + "public class A {\n" + + "}\n" + ); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + env.removePackageFragmentRoot(P1, ""); + env.addClassFolder(P1, P1.append("bin"), true); + IPath P2 = env.addProject("P2"); + env.addExternalJars(P2, Util.getJavaClassLibs()); + env.addRequiredProject(P2, P1); + env.addClass( + env.getPackageFragmentRootPath(P2, ""), + "X", + "import p.A;\n" + + "public class X {\n" + + " A f;\n" + + "}"); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + env.removeProject(P1); + env.removeProject(P2); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159118 +// contrast this with test100: get an error when the class folder is not +// exported from the target project - P1 here +public void test101_class_folder_non_exported() throws JavaModelException { + IPath P1 = env.addProject("P1"); + env.setOutputFolder(P1, "bin"); + env.addExternalJars(P1, Util.getJavaClassLibs()); + env.addClass( + env.addPackage( + env.getPackageFragmentRootPath(P1, ""), "p"), + "A", + "package p;\n" + + "public class A {\n" + + "}\n" + ); + fullBuild(); + expectingNoProblems(); + env.removePackageFragmentRoot(P1, ""); + env.addClassFolder(P1, P1.append("bin"), false); + IPath P2 = env.addProject("P2"); + env.addExternalJars(P2, Util.getJavaClassLibs()); + env.addRequiredProject(P2, P1); + IPath c = env.addClass( + env.getPackageFragmentRootPath(P2, ""), + "X", + "import p.A;\n" + + "public class X {\n" + + " A f;\n" + + "}"); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingSpecificProblemsFor(P2, + new Problem[] { + new Problem("", "The import p cannot be resolved", + c, 7 , 8, CategorizedProblem.CAT_IMPORT, IMarker.SEVERITY_ERROR), + new Problem("", "A cannot be resolved to a type", + c, 31 , 32, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)}); + env.removeProject(P1); + env.removeProject(P2); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=164622 +public void test102_missing_required_binaries() throws JavaModelException { + + IPath p1 = env.addProject("P1"); + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); + IPath root1 = env.addPackageFragmentRoot(p1, "src"); + env.setOutputFolder(p1, "bin"); + + IPath p2 = env.addProject("P2"); + env.addExternalJars(p2, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(p2, ""); + IPath root2 = env.addPackageFragmentRoot(p2, "src"); + env.addRequiredProject(p2, p1); + env.setOutputFolder(p2, "bin"); + + IPath p3 = env.addProject("P3"); + env.addExternalJars(p3, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(p3, ""); + IPath root3 = env.addPackageFragmentRoot(p3, "src"); +// env.addRequiredProject(p3, p1); - missing dependency + env.addRequiredProject(p3, p2); + env.setOutputFolder(p3, "bin"); + + env.addClass(root1, "", "I", + "public interface I {\n" + + "}\n" + ); + + env.addClass(root2, "", "X", + "public class X implements I {\n" + + "}\n" + ); + + IPath y = env.addClass(root3, "", "Y", + "public class Y extends X {\n" + + " X m = new X() {};\n" + + "}\n" + ); + + try { + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingOnlySpecificProblemsFor(p3, new Problem[]{ + new Problem("p3", + "The project was not built since its build path is incomplete. Cannot find the class file for I. Fix the build path then try building this project", + p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), + new Problem("p3", + "The type I cannot be resolved. It is indirectly referenced from required .class files", + y, 23, 24, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), + }); + } finally { + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=164622 +public void test103_missing_required_binaries() throws JavaModelException { + + IPath p1 = env.addProject("P1"); + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); + IPath root1 = env.addPackageFragmentRoot(p1, "src"); + env.setOutputFolder(p1, "bin"); + + IPath p2 = env.addProject("P2"); + env.addExternalJars(p2, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(p2, ""); + IPath root2 = env.addPackageFragmentRoot(p2, "src"); + env.addRequiredProject(p2, p1); + env.setOutputFolder(p2, "bin"); + + IPath p3 = env.addProject("P3"); + env.addExternalJars(p3, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(p3, ""); + IPath root3 = env.addPackageFragmentRoot(p3, "src"); +// env.addRequiredProject(p3, p1); - missing dependency + env.addRequiredProject(p3, p2); + env.setOutputFolder(p3, "bin"); + + env.addClass(root1, "", "I", + "public interface I {\n" + + "}\n" + ); + + env.addClass(root2, "", "X", + "public class X implements I {\n" + + "}\n" + ); + + IPath y = env.addClass(root3, "", "Y", + "public class Y {\n" + + " X m = new X() {};\n" + + " X n = new X() {};\n" + + "}\n" + ); + + try { + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingOnlySpecificProblemsFor(p3, new Problem[]{ + new Problem("p3", + "The project was not built since its build path is incomplete. Cannot find the class file for I. Fix the build path then try building this project", + p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), + new Problem("p3", + "The type I cannot be resolved. It is indirectly referenced from required .class files", + y, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), + }); + } finally { + env.setBuildOrder(null); + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=460993 +public void test104_missing_required_binaries() throws CoreException { + + IPath p0 = env.addProject("JRE17", "1.7"); + env.addExternalJars(p0, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(p0, ""); + IPath root0 = env.addPackageFragmentRoot(p0, "src"); + env.setOutputFolder(p0, "bin"); + + IPath p1 = env.addProject("org.eclipse.jgit", "1.7"); + env.addExternalJars(p1, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(p1, ""); + IPath root1 = env.addPackageFragmentRoot(p1, "src"); + env.addRequiredProject(p1, p0); + env.setOutputFolder(p1, "bin"); + + IPath p2 = env.addProject("org.eclipse.releng.tools", "1.5"); + env.addExternalJars(p2, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(p2, ""); + IPath root2 = env.addPackageFragmentRoot(p2, "src"); +// env.addRequiredProject(p2, p0); - missing dependency + env.addRequiredProject(p2, p1); + env.setOutputFolder(p2, "bin"); + + env.addClass(root0, "jre17", "AutoClosable", + "package jre17;\n" + + "public interface AutoClosable {\n" + + " void closeIt();\n" + + "}\n" + ); + + env.addClass(root1, "org.eclipse.jgit.lib", "Repository", + "package org.eclipse.jgit.lib;\n" + + "import jre17.AutoClosable;\n" + + "public abstract class Repository implements AutoClosable {\n" + + " public void resolve(final String revstr) { }\n" + + "}\n" + ); + + IPath gca = env.addClass(root2, "org.eclipse.releng.tools.git", "GitCopyrightAdapter", + "package org.eclipse.releng.tools.git;\n" + + "import org.eclipse.jgit.lib.Repository;\n" + + "public class GitCopyrightAdapter {\n" + + " void foo(Repository repo) {\n" + + " repo.resolve(\"Head\");\n" + + " }\n" + + "}\n" + ); + env.addClass(root2, "org.eclipse.releng.tools.preferences", "Messages", + "package org.eclipse.releng.tools.preferences;\n" + + "final class Messages {\n" + + " {\n" + + " @SuppressWarnings(\"unused\")\n" + + " Object o = \"\"; // triggers the bug\n" + + " }\n" + + "}\n" + ); + + try { + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + + IFile gcaFile = (IFile) env.getWorkspace().getRoot().findMember(gca); + gcaFile.touch(null); + env.waitForManualRefresh(); + incrementalBuild(p2); + env.waitForAutoBuild(); + expectingNoProblems(); + + } finally { + env.setBuildOrder(null); + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p0); + } +} + + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=438923, [compiler]Type is inappropriately considered "indirectly referenced" +public void test438923() throws JavaModelException { + //---------------------------- + // Project1 + //---------------------------- + IPath p1 = env.addProject("P1"); //$NON-NLS-1$ + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + env.addClass(root1, "p1", "P1I0", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + + "public interface P1I0 {\n" + + " interface II {/*empty*/}\n" + + "}\n" + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath p2 = env.addProject("P2"); //$NON-NLS-1$ + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + env.addClass(root2, "p2", "P2C0", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n" + + "import p1.P1I0;\n" + + "public class P2C0 {\n" + + " public void z(final P1I0.II [] ii) {/*empty*/}\n" + + "}\n" + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath p3 = env.addProject("P3"); //$NON-NLS-1$ + env.addExternalJars(p3, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$ + IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$ + env.setOutputFolder(p3, "bin"); //$NON-NLS-1$ + + env.addClass(root3, "p3", "P3C0", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n" + + "import p2.P2C0;\n" + + "public class P3C0\n" + + " extends P2C0 {/*empty*/}\n" + ); + + // for Project1 + env.addRequiredProject(p2, p1); + env.addRequiredProject(p3, p2); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=461074, "indirectly referenced from required .class files" error for unreachable reference of type in overriding method declaration in a library on classpath +public void test461074() throws JavaModelException { + //---------------------------- + // Project1 + //---------------------------- + IPath p1 = env.addProject("SampleMissing"); //$NON-NLS-1$ + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + env.addClass(root1, "pack.missing", "MissingType", //$NON-NLS-1$ //$NON-NLS-2$ + "package pack.missing;\n" + + "public class MissingType {\n" + + "}\n" + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath p2 = env.addProject("SampleLib", "1.5"); //$NON-NLS-1$ + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + env.addClass(root2, "pack.lib", "TopClass", //$NON-NLS-1$ //$NON-NLS-2$ + "package pack.lib;\n" + + "public class TopClass {\n" + + " Object get() { return null; }\n" + + "}\n" + ); + env.addClass(root2, "pack.lib", "SuperClass", //$NON-NLS-1$ //$NON-NLS-2$ + "package pack.lib;\n" + + "import pack.missing.MissingType;\n" + + "public class SuperClass extends TopClass {\n" + + " @Override\n" + + " MissingType get() { return null; }\n" + + "}\n" + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath p3 = env.addProject("SampleTest", "1.5"); //$NON-NLS-1$ + env.addExternalJars(p3, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$ + IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$ + env.setOutputFolder(p3, "bin"); //$NON-NLS-1$ + + env.addClass(root3, "pack.test", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package pack.test;\n" + + "import pack.lib.SuperClass;\n" + + "public class Test extends SuperClass {/*empty*/}\n" + ); + + // for Project1 + env.addRequiredProject(p2, p1); + env.addRequiredProject(p3, p2); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingNoProblems(); + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=461074, "indirectly referenced from required .class files" error for unreachable reference of type in overriding method declaration in a library on classpath +public void test461074_error() throws JavaModelException { + //---------------------------- + // Project1 + //---------------------------- + IPath p1 = env.addProject("SampleMissing"); //$NON-NLS-1$ + env.addExternalJars(p1, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p1, ""); //$NON-NLS-1$ + IPath root1 = env.addPackageFragmentRoot(p1, "src"); //$NON-NLS-1$ + env.setOutputFolder(p1, "bin"); //$NON-NLS-1$ + + env.addClass(root1, "pack.missing", "MissingType", //$NON-NLS-1$ //$NON-NLS-2$ + "package pack.missing;\n" + + "public class MissingType {\n" + + "}\n" + ); + + //---------------------------- + // Project2 + //---------------------------- + IPath p2 = env.addProject("SampleLib", "1.5"); //$NON-NLS-1$ + env.addExternalJars(p2, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p2, ""); //$NON-NLS-1$ + IPath root2 = env.addPackageFragmentRoot(p2, "src"); //$NON-NLS-1$ + env.setOutputFolder(p2, "bin"); //$NON-NLS-1$ + + env.addClass(root2, "pack.lib", "TopClass", //$NON-NLS-1$ //$NON-NLS-2$ + "package pack.lib;\n" + + "public abstract class TopClass {\n" + + " abstract Object get();\n" + + "}\n" + ); + env.addClass(root2, "pack.lib", "SuperClass", //$NON-NLS-1$ //$NON-NLS-2$ + "package pack.lib;\n" + + "import pack.missing.MissingType;\n" + + "public class SuperClass extends TopClass {\n" + + " @Override\n" + + " MissingType get() { return null; }\n" + + "}\n" + ); + + //---------------------------- + // Project3 + //---------------------------- + IPath p3 = env.addProject("SampleTest", "1.5"); //$NON-NLS-1$ + env.addExternalJars(p3, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(p3, ""); //$NON-NLS-1$ + IPath root3 = env.addPackageFragmentRoot(p3, "src"); //$NON-NLS-1$ + env.setOutputFolder(p3, "bin"); //$NON-NLS-1$ + + IPath test = env.addClass(root3, "pack.test", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package pack.test;\n" + + "import pack.lib.SuperClass;\n" + + "public class Test extends SuperClass {/*empty*/}\n" + ); + + // for Project1 + env.addRequiredProject(p2, p1); + env.addRequiredProject(p3, p2); + env.waitForManualRefresh(); + fullBuild(); + env.waitForAutoBuild(); + expectingOnlySpecificProblemsFor(p3, new Problem[]{ + new Problem("p3", + "The project was not built since its build path is incomplete. Cannot find the class file for pack.missing.MissingType. Fix the build path then try building this project", + p3, -1, -1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), + new Problem("p3", + "The type pack.missing.MissingType cannot be resolved. It is indirectly referenced from required .class files", + test, 0, 1, CategorizedProblem.CAT_BUILDPATH, IMarker.SEVERITY_ERROR), + }); + env.setBuildOrder(null); + env.removeProject(p1); + env.removeProject(p2); + env.removeProject(p3); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/MultiSourceFolderAndOutputFolderTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/MultiSourceFolderAndOutputFolderTests.java new file mode 100644 index 0000000000..70a32574b9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/MultiSourceFolderAndOutputFolderTests.java @@ -0,0 +1,313 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import junit.framework.*; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; + +/** + * Basic tests of the image builder. + */ +public class MultiSourceFolderAndOutputFolderTests extends BuilderTests { + + public MultiSourceFolderAndOutputFolderTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(MultiSourceFolderAndOutputFolderTests.class); + } + + public void test0001() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1", null, "bin1"); //$NON-NLS-1$ //$NON-NLS-2$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src1, "", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "public class X {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(projectPath.append("bin1/X.class")); //$NON-NLS-1$ + expectingNoPresenceOf(projectPath.append("bin/X.class")); //$NON-NLS-1$ + } + + public void test0002() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1", null, "bin1"); //$NON-NLS-1$ //$NON-NLS-2$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src1, "p", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class X {}" //$NON-NLS-1$ + ); + + env.addClass(src2, "p", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class Y {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(projectPath.append("bin1/p/X.class")); //$NON-NLS-1$ + expectingPresenceOf(projectPath.append("bin/p/Y.class")); //$NON-NLS-1$ + expectingNoPresenceOf(projectPath.append("bin/p/X.class")); //$NON-NLS-1$ + expectingNoPresenceOf(projectPath.append("bin1/p/Y.class")); //$NON-NLS-1$ + } + + public void test0003() { + try { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src", null, null); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src/f1", null, null); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + fullBuild(); + expectingNoProblems(); + + assertTrue("JavaModelException", false); //$NON-NLS-1$ + } catch (JavaModelException e) { + assertEquals( + "Cannot nest 'P/src/f1' inside 'P/src'. " + //$NON-NLS-1$ + "To enable the nesting exclude 'f1/' from 'P/src'", //$NON-NLS-1$ + e.getMessage() + ); + } + } + + public void test0004() { + try { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src/f1", null, null); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src", new IPath[]{new Path("f1")}, null); //$NON-NLS-1$ //$NON-NLS-2$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + fullBuild(); + expectingNoProblems(); + + assertTrue("JavaModelException", false); //$NON-NLS-1$ + } catch (JavaModelException e) { + assertEquals( + "End exclusion filter 'f1' with / to fully exclude 'P/src/f1'", //$NON-NLS-1$ + e.getMessage() + ); + } + } + + public void test0005() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src/f1", null, null); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src", new IPath[]{new Path("f1/")}, null); //$NON-NLS-1$ //$NON-NLS-2$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + fullBuild(); + expectingNoProblems(); + } + + public void test0006() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath srcF1 = env.addPackageFragmentRoot(projectPath, "src/f1", null, null); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src", new IPath[]{new Path("f1/")}, null); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src, "p", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class X extends p2.Y{}" //$NON-NLS-1$ + ); + + env.addClass(srcF1, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;"+ //$NON-NLS-1$ + "public class Y {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + } + + public void test0007() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath srcF1 = env.addPackageFragmentRoot(projectPath, "src/f1", null, null); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src", new IPath[]{new Path("f1/")}, null); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + IPath xPath = env.addClass(src, "p", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class X extends f1.p2.Y{}" //$NON-NLS-1$ + ); + + env.addClass(srcF1, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;"+ //$NON-NLS-1$ + "public class Y {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingOnlyProblemsFor(xPath); + } + + public void test0008() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath srcF1 = env.addPackageFragmentRoot(projectPath, "src/f1", null, null); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src", new IPath[]{new Path("f1/")}, null); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + IPath xPath = env.addClass(src, "p", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class X extends p2.Y{}" //$NON-NLS-1$ + ); + + env.addClass(srcF1, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;"+ //$NON-NLS-1$ + "public abstract class Y {"+ //$NON-NLS-1$ + " abstract void foo();"+ //$NON-NLS-1$ + "}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingOnlyProblemsFor(xPath); + + env.addClass(srcF1, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;"+ //$NON-NLS-1$ + "public class Y {}" //$NON-NLS-1$ + ); + + incrementalBuild(); + + expectingNoProblems(); + } + + public void test0009() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addPackageFragmentRoot(projectPath, "", null, "bin2"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addFolder(projectPath, "bin"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "public class X {}" //$NON-NLS-1$ + ); + + + fullBuild(); + + expectingNoProblems(); + expectingPresenceOf(projectPath.append("bin2").append("X.class")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin").append("X.class")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin2").append("bin")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin").append("bin2")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public void test0010() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addPackageFragmentRoot(projectPath, "", new IPath[]{new Path("src/")}, "bin2"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + IPath src = env.addPackageFragmentRoot(projectPath, "src", null, null); //$NON-NLS-1$ //$NON-NLS-2$ + env.addFolder(projectPath, "bin"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "public class X {}" //$NON-NLS-1$ + ); + + env.addClass(src, "", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Y {}" //$NON-NLS-1$ + ); + + + fullBuild(); + + expectingNoProblems(); + expectingPresenceOf(projectPath.append("bin2").append("X.class")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin").append("X.class")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingPresenceOf(projectPath.append("bin").append("Y.class")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin2").append("Y.class")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin2").append("bin")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin").append("bin2")); //$NON-NLS-1$ //$NON-NLS-2$ + } + public void test0011() throws JavaModelException { + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addPackageFragmentRoot(projectPath, "", new IPath[]{new Path("src/")}, null); //$NON-NLS-1$ //$NON-NLS-2$ + IPath src = env.addPackageFragmentRoot(projectPath, "src", null, "bin2"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addFolder(projectPath, "bin"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(projectPath, "", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "public class X {}" //$NON-NLS-1$ + ); + + env.addClass(src, "", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Y {}" //$NON-NLS-1$ + ); + + + fullBuild(); + + expectingNoProblems(); + expectingPresenceOf(projectPath.append("bin").append("X.class")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin2").append("X.class")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingPresenceOf(projectPath.append("bin2").append("Y.class")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin").append("Y.class")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin2").append("bin")); //$NON-NLS-1$ //$NON-NLS-2$ + expectingNoPresenceOf(projectPath.append("bin").append("bin2")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /* + * Regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161 + */ + public void test0012() throws JavaModelException { + IPath projectPath = env.addProject("P"); + env.removePackageFragmentRoot(projectPath, ""); + IPath src = env.addPackageFragmentRoot(projectPath, "", new IPath[] {new Path("p1/p2/p3/X.java"), new Path("Y.java")}, null, ""); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src, "p1.p2.p3", "X", + "package p1.p2.p3;\n" + + "public class X {}" + ); + fullBuild(); + expectingNoProblems(); + + env.addClass(src, "", "Y", + "import p1.p2.p3.X;\n" + + "public class Y extends X {}" + ); + incrementalBuild(); + expectingNoProblems(); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/OutputFolderTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/OutputFolderTests.java new file mode 100644 index 0000000000..7da9c868fe --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/OutputFolderTests.java @@ -0,0 +1,323 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import junit.framework.*; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.core.JavaProject; + +/** + * Basic tests of the image builder. + */ +public class OutputFolderTests extends BuilderTests { + + public OutputFolderTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(OutputFolderTests.class); + } + + public void testChangeOutputFolder() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath bin1 = env.setOutputFolder(projectPath, "bin1"); //$NON-NLS-1$ + + env.addClass(root, "p", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n" + //$NON-NLS-1$ + "public class Test {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(bin1.append("p/Test.class")); //$NON-NLS-1$ + + IPath bin2 = env.setOutputFolder(projectPath, "bin2"); //$NON-NLS-1$ + incrementalBuild(); + expectingNoProblems(); + expectingPresenceOf(bin2.append("p/Test.class")); //$NON-NLS-1$ + } + + public void testDeleteOutputFolder() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + IPath root = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Test {}" //$NON-NLS-1$ + ); + env.addFile(root, "Test.txt", ""); //$NON-NLS-1$ //$NON-NLS-2$ + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[]{ + bin.append("Test.class"), //$NON-NLS-1$ + bin.append("Test.txt") //$NON-NLS-1$ + }); + + env.removeFolder(bin); +// incrementalBuild(); currently not detected by the incremental builder... should it? + fullBuild(); + expectingPresenceOf(new IPath[]{ + bin.append("Test.class"), //$NON-NLS-1$ + bin.append("Test.txt") //$NON-NLS-1$ + }); + } + /* + * Ensures that changing the output to be the project (when the project has a source folder src) + * doesn't scrub the project on exit/restart. + * (regression test for bug 32588 Error saving changed source files; all files in project deleted) + */ + public void testInvalidOutput() throws JavaModelException { + // setup project with 1 src folder and 1 output folder + IPath projectPath = env.addProject("P"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + // add cu and build + env.addClass(projectPath, "src", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {}" //$NON-NLS-1$ + ); + fullBuild(); + expectingNoProblems(); + + // set invalid output foder by editing the .classpath file + env.addFile( + projectPath, + ".classpath", //$NON-NLS-1$ + "\n" + //$NON-NLS-1$ + "\n" + //$NON-NLS-1$ + " \n" + //$NON-NLS-1$ + " \n" + //$NON-NLS-1$ //$NON-NLS-2$ + " \n" + //$NON-NLS-1$ + "" //$NON-NLS-1$ + ); + + // simulate exit/restart + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + JavaProject project = manager.getJavaModel().getJavaProject("P"); //$NON-NLS-1$ + manager.removePerProjectInfo(project, true /* remove external jar files indexes and timestamps*/); + + // change cu and build + IPath cuPath = env.addClass(projectPath, "src", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A { String s;}" //$NON-NLS-1$ + ); + incrementalBuild(); + + expectingPresenceOf(new IPath[] {cuPath}); + } + + public void testSimpleProject() throws JavaModelException { + IPath projectPath = env.addProject("P1"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, ""); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {}" //$NON-NLS-1$ + ); + env.addClass(projectPath, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class B {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + bin.append("A.class"), //$NON-NLS-1$ + bin.append("p/B.class") //$NON-NLS-1$ + }); + } + + public void testProjectWithBin() throws JavaModelException { + IPath projectPath = env.addProject("P2"); //$NON-NLS-1$ + IPath src = env.getPackageFragmentRootPath(projectPath, ""); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {}" //$NON-NLS-1$ + ); + env.addClass(src, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class B {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + bin.append("A.class"), //$NON-NLS-1$ + bin.append("p/B.class") //$NON-NLS-1$ + }); + } + + public void testProjectWithSrcBin() throws JavaModelException { + IPath projectPath = env.addProject("P3"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {}" //$NON-NLS-1$ + ); + env.addClass(src, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class B {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + bin.append("A.class"), //$NON-NLS-1$ + bin.append("p/B.class") //$NON-NLS-1$ + }); + } + + public void testProjectWith2SrcBin() throws JavaModelException { + IPath projectPath = env.addProject("P4"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1"); //$NON-NLS-1$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src1, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {}" //$NON-NLS-1$ + ); + env.addClass(src2, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class B {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + bin.append("A.class"), //$NON-NLS-1$ + bin.append("p/B.class") //$NON-NLS-1$ + }); + } + + public void testProjectWith2SrcAsBin() throws JavaModelException { + IPath projectPath = env.addProject("P5"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1", null, "src1"); //$NON-NLS-1$ //$NON-NLS-2$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2", null, "src2"); //$NON-NLS-1$ //$NON-NLS-2$ + /*IPath bin =*/ env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src1, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {}" //$NON-NLS-1$ + ); + env.addClass(src2, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class B {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + src1.append("A.class"), //$NON-NLS-1$ + src2.append("p/B.class") //$NON-NLS-1$ + }); + } + + public void testProjectWith2Src2Bin() throws JavaModelException { + IPath projectPath = env.addProject("P6"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1", null, "bin1"); //$NON-NLS-1$ //$NON-NLS-2$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2", null, "bin2"); //$NON-NLS-1$ //$NON-NLS-2$ + env.setOutputFolder(projectPath, "bin1"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src1, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {}" //$NON-NLS-1$ + ); + env.addClass(src2, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class B {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + projectPath.append("bin1/A.class"), //$NON-NLS-1$ + projectPath.append("bin2/p/B.class") //$NON-NLS-1$ + }); + } + + public void testProjectWith3Src2Bin() throws JavaModelException { + IPath projectPath = env.addProject("P6"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src1 = env.addPackageFragmentRoot(projectPath, "src1", null, "bin1"); //$NON-NLS-1$ //$NON-NLS-2$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2", null, "bin2"); //$NON-NLS-1$ //$NON-NLS-2$ + IPath src3 = env.addPackageFragmentRoot(projectPath, "src3", null, "bin2"); //$NON-NLS-1$ //$NON-NLS-2$ + env.setOutputFolder(projectPath, "bin1"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(src1, "", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "public class A {}" //$NON-NLS-1$ + ); + env.addClass(src2, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class B {}" //$NON-NLS-1$ + ); + env.addClass(src3, "", "C", //$NON-NLS-1$ //$NON-NLS-2$ + "public class C {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(new IPath[] { + projectPath.append("bin1/A.class"), //$NON-NLS-1$ + projectPath.append("bin2/p/B.class"), //$NON-NLS-1$ + projectPath.append("bin2/C.class") //$NON-NLS-1$ + }); + } + + public void test2ProjectWith1Bin() throws JavaModelException { + IPath projectPath = env.addProject("P7"); //$NON-NLS-1$ + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath bin = env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + IPath projectPath2 = env.addProject("P8"); //$NON-NLS-1$ + IPath binLocation = env.getProject(projectPath).getFolder("bin").getLocation(); //$NON-NLS-1$ + env.setExternalOutputFolder(projectPath2, "externalBin", binLocation); //$NON-NLS-1$ + env.addExternalJars(projectPath2, Util.getJavaClassLibs()); + env.addRequiredProject(projectPath2, projectPath); + + env.addClass(projectPath2, "p", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;"+ //$NON-NLS-1$ + "public class B {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + expectingPresenceOf(bin.append("p/B.class")); //$NON-NLS-1$ + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java new file mode 100644 index 0000000000..5a5e8a40ac --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageInfoTest.java @@ -0,0 +1,738 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Arrays; + +import junit.framework.Test; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.Util; + +@SuppressWarnings("rawtypes") +public class PackageInfoTest extends BuilderTests { + +public PackageInfoTest(String name) { + super(name); +} +// 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[] { "testBug374063" }; +// TESTS_NUMBERS = new int[] { 3 }; +// TESTS_RANGE = new int[] { 21, 50 }; +} +public static Test suite() { + return buildTestSuite(PackageInfoTest.class); +} +public void test001() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "pack", "Annot", //$NON-NLS-1$ //$NON-NLS-2$ + "package pack;\n" + //$NON-NLS-1$ + "public @interface Annot {}" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + + IPath packageInfoPath = env.addFile(root, "pack/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$ + "@Annot package p1" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlyProblemsFor(packageInfoPath); + final Problem[] problems = env.getProblems(); + Arrays.sort(problems); + assertNotNull(problems); + final StringWriter stringWriter = new StringWriter(); + final PrintWriter writer = new PrintWriter(stringWriter); + final int problemsLength = problems.length; + if (problemsLength == 1) { + writer.print(problems[0].getMessage()); + } else { + for (int i = 0; i < problemsLength - 1; i++) + writer.println(problems[i].getMessage()); + writer.print(problems[problemsLength - 1].getMessage()); + } + writer.close(); + final String expectedOutput = + "Syntax error on token \"p1\", ; expected after this token\n" + + "The declared package \"p1\" does not match the expected package \"pack\""; + assertSourceEquals("Different messages", expectedOutput, stringWriter.toString()); +} +public void test002() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "testcase", "Main", //$NON-NLS-1$ //$NON-NLS-2$ + "package testcase;\n" + + "\n" + + "public class Main {\n" + + " public static void main(String[] argv) throws Exception {\n" + + " Package pkg = Package.getPackage(\"testcase\");\n" + + " System.out.print(pkg.getAnnotation(TestAnnotation.class));\n" + + " pkg = Class.forName(\"testcase.package-info\").getPackage();\n" + + " System.out.print(pkg.getAnnotation(TestAnnotation.class));\n" + + " }\n" + + "}" + ); + + env.addClass(root, "testcase", "TestAnnotation", //$NON-NLS-1$ //$NON-NLS-2$ + "package testcase;\n" + + "\n" + + "import static java.lang.annotation.ElementType.PACKAGE;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(PACKAGE)\n" + + "@Retention(RUNTIME)\n" + + "public @interface TestAnnotation {\n" + + "}" + ); + + env.addFile(root, "testcase/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$ + "@TestAnnotation package testcase;" //$NON-NLS-1$ + ); + incrementalBuild(projectPath); + String javaVersion = System.getProperty("java.version"); + if (javaVersion != null && JavaCore.compareJavaVersions(javaVersion, "9") >= 0) { + expectingProblemsFor(new Path("/Project/src/testcase/Main.java"), + "Problem : The method getPackage(String) from the type Package is deprecated [ resource : range : <125,147> category : <110> severity : <1>]"); + } else { + expectingNoProblems(); + } + executeClass(projectPath, "testcase.Main", "@testcase.TestAnnotation()@testcase.TestAnnotation()", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ +} +public void test003() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addPackage(root, "testcase"); + IPath packageInfoPath = env.addFile(root, "testcase/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$ + "" //$NON-NLS-1$ + ); + + incrementalBuild(projectPath); + expectingOnlySpecificProblemFor( + packageInfoPath, + new Problem("testcase/package-info.java", "The declared package \"\" does not match the expected package \"testcase\"", packageInfoPath, 0, 0, CategorizedProblem.CAT_INTERNAL, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ +} +// test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=252555 : NPE +// on duplicate package-info +public void test004() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath otherRoot = env.addPackageFragmentRoot(projectPath, "test"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addPackage(root, "my.foo"); + env.addPackage(otherRoot, "my.foo"); + + env.addFile(root, "my/foo/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$ + "/**\n" + + "* A demo package for foo.\n" + + "*/\n" + + "package my.foo;\n" + ); + + IPath otherPackageInfoPath = env.addFile(otherRoot, + "my/foo/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$ + "/**\n" + + "* A demo package for foo.\n" + + "*/\n" + + "package my.foo;\n" + ); + + incrementalBuild(projectPath); + expectingOnlySpecificProblemFor( + otherPackageInfoPath, + new Problem("my/foo/package-info.java", "The type package-info is already defined", otherPackageInfoPath, 0, 0, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ +} +// test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=258145 : JME +// on duplicate package-info +public void test258145() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath otherRoot = env.addPackageFragmentRoot(projectPath, "test"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addPackage(root, "my.foo"); + env.addFile(root, "my/foo/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$ + "/**\n" + + "* A demo package for foo.\n" + + "*/\n" + + "package my.foo;\n" + ); + + fullBuild(projectPath); + + env.addPackage(otherRoot, "my.foo"); + + IPath otherPackageInfoPath = env.addFile(otherRoot, + "my/foo/package-info.java", //$NON-NLS-1$ //$NON-NLS-2$ + "/**\n" + + "* A demo package for foo.\n" + + "*/\n" + + "package my.foo;\n" + ); + + incrementalBuild(projectPath); + expectingOnlySpecificProblemFor( + otherPackageInfoPath, + new Problem("my/foo/package-info.java", "The type package-info is already defined", otherPackageInfoPath, 0, 0, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=323785 +// (NPE upon creation/deletion of package-info.java in default package) +public void test323785 () throws JavaModelException { + + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + fullBuild(projectPath); + + env.addFile(root, "package-info.java", ""); + + incrementalBuild(projectPath); + expectingNoProblems(); + +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=323785 +// verify that changes to package info containing secondary types do trigger incremental build. +public void test323785a () throws JavaModelException { + + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + IPath xJavaPath = env.addFile(root, "X.java", "class X extends Y {}\n"); + fullBuild(projectPath); + env.addFile(root, "package-info.java", "class Y {}\n"); + incrementalBuild(projectPath); + expectingNoProblems(); + env.addFile(root, "package-info.java", "final class Y {}\n"); + incrementalBuild(projectPath); + expectingOnlySpecificProblemFor( + xJavaPath, + new Problem("X.java", "The type X cannot subclass the final class Y", xJavaPath, 16, 17, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); + +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=372012 +// test missing default nullness annotation for a package without package-info +// test when the package-info is added with the default annotation, the problem disappears +public void testBug372012() throws JavaModelException, IOException { + + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath srcRoot = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + // prepare the project: + setupProjectForNullAnnotations(projectPath); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.ERROR); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION, JavaCore.ERROR); + String test1Code = "package p1;\n" + + "public class Test1 {\n" + + " public void foo() {\n" + + " new Test2().bar(\"\");\n" + + " }\n" + + " class Test1Inner{}\n" + + "}"; + String test2Code = "package p1;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class Test2 {\n" + + " public void bar(String str) {}\n" + + "}"; + String test3Code = "package p1;\n" + + "public class Test3 {\n" + + " public void bar(String str) {}\n" + + "}"; + + IPath test1Path = env.addClass(srcRoot, "p1", "Test1", test1Code); + env.addClass(srcRoot, "p1", "Test2", test2Code); + env.addClass(srcRoot, "p1", "Test3", test3Code); + + fullBuild(projectPath); + expectingNoProblemsFor(test1Path); + // should have only one marker + expectingProblemsFor(srcRoot, + "Problem : A default nullness annotation has not been specified for the package p1 [ resource : range : <8,10> category : <90> severity : <2>]"); + + // add package-info.java with default annotation + String packageInfoCode = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;\n"; + env.addClass(srcRoot, "p1", "package-info", packageInfoCode); + incrementalBuild(projectPath); + expectingProblemsFor(projectPath, + "Problem : Nullness default is redundant with a default specified for the enclosing package p1 [ resource : range : <12,56> category : <120> severity : <2>]"); + + // verify that all package CU's were recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.Test1$Test1Inner", "p1.Test2", "p1.Test3", "p1.package-info" }); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=372012 +// test missing default nullness annotation for a package without package-info +// test when the the default annotations are added to all top level types, the problem stays +public void testBug372012a() throws JavaModelException, IOException { + + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath srcRoot = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + // prepare the project: + setupProjectForNullAnnotations(projectPath); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.ERROR); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION, JavaCore.ERROR); + String test1Code = "package p1;\n" + + "public class Test1 {\n" + + " public void foo() {\n" + + " new Test2().bar(\"\");\n" + + " }\n" + + " class Test1Inner{}\n" + + "}"; + String test2Code = "package p1;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class Test2 {\n" + + " public void bar(String str) {}\n" + + "}"; + + IPath test1Path = env.addClass(srcRoot, "p1", "Test1", test1Code); + env.addClass(srcRoot, "p1", "Test2", test2Code); + + fullBuild(projectPath); + expectingNoProblemsFor(test1Path); + // should have only one marker + expectingProblemsFor(srcRoot, + "Problem : A default nullness annotation has not been specified for the package p1 [ resource : range : <8,10> category : <90> severity : <2>]"); + + // add default annotation to Test1 + test1Code = "package p1;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class Test1 {\n" + + " public void foo() {\n" + + " new Test2().bar(\"\");\n" + + " }\n" + + " class Test1Inner{}\n" + + "}"; + env.addClass(srcRoot, "p1", "Test1", test1Code); + incrementalBuild(projectPath); + // should have only one marker + expectingProblemsFor(srcRoot, + "Problem : A default nullness annotation has not been specified for the package p1 [ resource : range : <8,10> category : <90> severity : <2>]"); + + // verify that all package CU's were recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.Test1$Test1Inner"}); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=372012 +// test missing default nullness annotation for a package without package-info +// test when the the default annotations is added to only 1 top level type, the problem stays +public void testBug372012b() throws JavaModelException, IOException { + + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath srcRoot = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + // prepare the project: + setupProjectForNullAnnotations(projectPath); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.ERROR); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION, JavaCore.ERROR); + String test1Code = "package p1;\n" + + "public class Test1 {\n" + + " public void foo() {\n" + + " new Test2().bar(\"\");\n" + + " }\n" + + " class Test1Inner{}\n" + + "}"; + String test2Code = "package p1;\n" + + "public class Test2 {\n" + + " public void bar(String str) {}\n" + + "}"; + + IPath test1Path = env.addClass(srcRoot, "p1", "Test1", test1Code); + env.addClass(srcRoot, "p1", "Test2", test2Code); + + fullBuild(projectPath); + expectingNoProblemsFor(test1Path); + // should have only one marker + expectingProblemsFor(srcRoot, + "Problem : A default nullness annotation has not been specified for the package p1 [ resource : range : <8,10> category : <90> severity : <2>]"); + + // add default annotation to Test1 + test1Code = "package p1;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class Test1 {\n" + + " public void foo() {\n" + + " new Test2().bar(\"\");\n" + + " }\n" + + " class Test1Inner{}\n" + + "}"; + env.addClass(srcRoot, "p1", "Test1", test1Code); + incrementalBuild(projectPath); + // should have only one marker + expectingProblemsFor(srcRoot, + "Problem : A default nullness annotation has not been specified for the package p1 [ resource : range : <8,10> category : <90> severity : <2>]"); + + // verify that only Test1's CU's were recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.Test1$Test1Inner"}); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=372012 +// test missing default nullness annotation for a package with package-info +// test when the the default annotation is removed from package-info, the problem comes back +public void testBug372012c() throws JavaModelException, IOException { + + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath srcRoot = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + // prepare the project: + setupProjectForNullAnnotations(projectPath); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.ERROR); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION, JavaCore.ERROR); + String test1Code = "package p1;\n" + + "public class Test1 {\n" + + " public void foo() {\n" + + " new Test2().bar(\"\");\n" + + " }\n" + + " class Test1Inner{}\n" + + "}"; + String test2Code = "package p1;\n" + + "public class Test2 {\n" + + " public void bar(String str) {}\n" + + "}"; + // add package-info.java with default annotation + String packageInfoCode = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;\n"; + env.addClass(srcRoot, "p1", "package-info", packageInfoCode); + + env.addClass(srcRoot, "p1", "Test1", test1Code); + env.addClass(srcRoot, "p1", "Test2", test2Code); + env.addClass(srcRoot, "p1", "package-info", packageInfoCode); + + fullBuild(projectPath); + // default annotation present, so no problem + expectingNoProblemsFor(srcRoot); + + // add package-info.java with default annotation + packageInfoCode = + "package p1;\n"; + env.addClass(srcRoot, "p1", "package-info", packageInfoCode); + incrementalBuild(projectPath); + expectingProblemsFor(projectPath, + "Problem : A default nullness annotation has not been specified for the package p1 [ resource : range : <8,10> category : <90> severity : <2>]"); + + // verify that all package CU's were recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.Test1$Test1Inner", "p1.Test2", "p1.package-info" }); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=367836 + */ +public void testBug367836() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(src, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n"+ //$NON-NLS-1$ + "public class A {}" //$NON-NLS-1$ + ); + + IPath bPath = env.addClass(src, "p", "package-info", //$NON-NLS-1$ //$NON-NLS-2$ + "" //$NON-NLS-1$ + ); + + fullBuild(); + expectingOnlySpecificProblemFor(bPath, + new Problem("", "The declared package \"\" does not match the expected package \"p\"", bPath, 0, 0, CategorizedProblem.CAT_INTERNAL, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=374063 +// verify that markers are created on the correct resource +public void testBug374063() throws JavaModelException, IOException { + + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath srcRoot = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + // prepare the project: + setupProjectForNullAnnotations(projectPath); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.ERROR); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION, JavaCore.ERROR); + String test1Code = "package p1;\n" + + "public class Test1 {\n" + + " public String output(List integers) {\n" + + " return \"\";\n" + + " }\n" + + " public void output(List doubles) {}\n" + + "}"; + + env.addClass(srcRoot, "p1", "Test1", test1Code); + + fullBuild(projectPath); + // resource for compile errors should be Test1 and not p1 + expectingProblemsFor(projectPath, + "Problem : A default nullness annotation has not been specified for the package p1 [ resource : range : <8,10> category : <90> severity : <2>]\n" + + "Problem : List cannot be resolved to a type [ resource : range : <130,134> category : <40> severity : <2>]\n" + + "Problem : List cannot be resolved to a type [ resource : range : <58,62> category : <40> severity : <2>]"); + + // add package-info.java with default annotation + String packageInfoCode = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;\n"; + env.addClass(srcRoot, "p1", "package-info", packageInfoCode); + incrementalBuild(projectPath); + expectingProblemsFor(projectPath, + "Problem : List cannot be resolved to a type [ resource : range : <130,134> category : <40> severity : <2>]\n" + + "Problem : List cannot be resolved to a type [ resource : range : <58,62> category : <40> severity : <2>]"); + + // verify that all package CU's were recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.package-info" }); +} +// 382960 +public void testBug382960() throws JavaModelException, IOException, CoreException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + env.removePackageFragmentRoot(projectPath, ""); + IPath srcRoot = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + // prepare the project: + setupProjectForNullAnnotations(projectPath); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.ERROR); + String test1Code = "package p1;\n" + + "public class Test1 {\n" + + " public String output(List integers) {\n" + + " return \"\";\n" + + " }\n" + + " public void output(List doubles) {}\n" + + "}"; + + env.addClass(srcRoot, "p1", "Test1", test1Code); + String packageInfoCode = "package p1;\n"; + env.addClass(srcRoot, "p1", "package-info", packageInfoCode); + fullBuild(projectPath); + expectingProblemsFor(projectPath, + "Problem : A default nullness annotation has not been specified for the package p1 [ resource : range : <8,10> category : <90> severity : <2>]\n" + + "Problem : List cannot be resolved to a type [ resource : range : <130,134> category : <40> severity : <2>]\n" + + "Problem : List cannot be resolved to a type [ resource : range : <58,62> category : <40> severity : <2>]"); + + packageInfoCode = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;\n"; + env.addClass(srcRoot, "p1", "package-info", packageInfoCode); + incrementalBuild(projectPath); + expectingProblemsFor(projectPath, + "Problem : List cannot be resolved to a type [ resource : range : <130,134> category : <40> severity : <2>]\n" + + "Problem : List cannot be resolved to a type [ resource : range : <58,62> category : <40> severity : <2>]"); + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.package-info" }); + + IProject project = env.getProject(projectPath); + IFile packageInfo = project.getFile("/src/p1/package-info.java"); + packageInfo.touch(null); + + incrementalBuild(projectPath); + expectingProblemsFor(projectPath, + "Problem : List cannot be resolved to a type [ resource : range : <130,134> category : <40> severity : <2>]\n" + + "Problem : List cannot be resolved to a type [ resource : range : <58,62> category : <40> severity : <2>]"); + + // verify that only package-info was recompiled + expectingUniqueCompiledClasses(new String[] { "p1.package-info" }); +} +// test that when a package-info.java has been created, markers on the +// package fragments in all source folders are removed. +public void testBug525469() throws JavaModelException, IOException { + + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + fullBuild(projectPath); + + // remove old package fragment root so that names don't collide + env.removePackageFragmentRoot(projectPath, ""); + + IPath srcRoot1 = env.addPackageFragmentRoot(projectPath, "src1"); + IPath srcRoot2 = env.addPackageFragmentRoot(projectPath, "src2"); + env.setOutputFolder(projectPath, "bin"); + // prepare the project: + setupProjectForNullAnnotations(projectPath); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.ERROR); + env.getJavaProject(projectPath).setOption(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION, JavaCore.ERROR); + + String test1Code = "package p1;\n" + + "public class Test1 {\n" + + "}"; + env.addClass(srcRoot1, "p1", "Test1", test1Code); + + String otherClassCode = "package p2;\n" + + "public class OtherClass {\n" + + "}"; + env.addClass(srcRoot1, "p2", "OtherClass", otherClassCode); + + String packageInfoCode2 = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p2;\n"; + env.addClass(srcRoot1, "p2", "package-info", packageInfoCode2); + + fullBuild(projectPath); + + String test2Code = "package p1;\n" + + "public class Test2 {\n" + + "}"; + + env.addClass(srcRoot2, "p1", "Test2", test2Code); + incrementalBuild(projectPath); + + // after the incremental build, as there is no package-info.java for p1, the error is visible in both source directories on the directory for the package p1 + expectingProblemsFor(projectPath, + "Problem : A default nullness annotation has not been specified for the package p1 [ resource : range : <8,10> category : <90> severity : <2>]\n" + + "Problem : A default nullness annotation has not been specified for the package p1 [ resource : range : <8,10> category : <90> severity : <2>]"); + + // add package-info.java with default annotation + String packageInfoCode1 = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;\n"; + env.addClass(srcRoot1, "p1", "package-info", packageInfoCode1); + + // an incremental build is requested, but it will switch to a full build + incrementalBuild(projectPath); + + // verify the expected behaviour: the error marker in the src2 directory must be gone, too + expectingProblemsFor(projectPath, + ""); + + // verify the implementation by doing a full build: all files have been recompiled + expectingUniqueCompiledClasses(new String[] { "p1.Test1", "p1.Test2", "p1.package-info", "p2.OtherClass", "p2.package-info" }); +} + +void setupProjectForNullAnnotations(IPath projectPath) throws IOException, JavaModelException { + // add the org.eclipse.jdt.annotation library (bin/ folder or jar) to the project: + File bundleFile = FileLocator.getBundleFile(Platform.getBundle("org.eclipse.jdt.annotation")); + String annotationsLib = bundleFile.isDirectory() ? bundleFile.getPath()+"/bin" : bundleFile.getPath(); + IJavaProject javaProject = env.getJavaProject(projectPath); + IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); + int len = rawClasspath.length; + System.arraycopy(rawClasspath, 0, rawClasspath = new IClasspathEntry[len+1], 0, len); + rawClasspath[len] = JavaCore.newLibraryEntry(new Path(annotationsLib), null, null); + javaProject.setRawClasspath(rawClasspath, null); + + javaProject.setOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); +} + +protected void assertSourceEquals(String message, String expected, String actual) { + if (actual == null) { + assertEquals(message, expected, null); + return; + } + actual = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(actual); + if (!actual.equals(expected)) { + System.out.print(org.eclipse.jdt.core.tests.util.Util.displayString(actual.toString(), 0)); + } + assertEquals(message, expected, actual); +} +public static Class testClass() { + return PackageInfoTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageTests.java new file mode 100644 index 0000000000..693a4b3f83 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/PackageTests.java @@ -0,0 +1,293 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.File; + +import junit.framework.*; + +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.Util; + +public class PackageTests extends BuilderTests { + + public PackageTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(PackageTests.class); + } + + /** + * Bugs 6564 + */ + public void testNoPackageProblem() throws JavaModelException { + //---------------------------- + // Step 1 + //---------------------------- + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(src, "pack", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package pack;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(src2, "p1", "X", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n"+ //$NON-NLS-1$ + "public class X {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(src2, "p2", "Y", //$NON-NLS-1$ //$NON-NLS-2$ + "package p2;\n"+ //$NON-NLS-1$ + "public class Y extends p1.X {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + env.addClass(src2, "p3", "Z", //$NON-NLS-1$ //$NON-NLS-2$ + "package p3;\n"+ //$NON-NLS-1$ + "public class Z extends p2.Y {\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + + fullBuild(); + expectingNoProblems(); + + //---------------------------- + // Step 2 + //---------------------------- + env.removeClass(env.getPackagePath(src, "pack"), "X"); //$NON-NLS-1$ //$NON-NLS-2$ + env.removePackage(src2, "p3"); //$NON-NLS-1$ + + incrementalBuild(); + expectingNoProblems(); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=251690 + */ + public void testPackageProblem() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath aPath = env.addClass(src, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n"+ //$NON-NLS-1$ + "public class A {}" //$NON-NLS-1$ + ); + + IPath bPath = env.addClass(src, "p.A", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "public class B {}" //$NON-NLS-1$ + ); + + fullBuild(); + expectingOnlySpecificProblemFor(aPath, + new Problem("", "The type A collides with a package", aPath, 24, 25, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + expectingOnlySpecificProblemFor(bPath, + new Problem("", "The declared package \"\" does not match the expected package \"p.A\"", bPath, 0, 1, CategorizedProblem.CAT_INTERNAL, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + } + + public void testNoFolderProblem() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(src, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n"+ //$NON-NLS-1$ + "public class A {}" //$NON-NLS-1$ + ); + + // create folder & contained non-java file (which don't establish package p.A!): + env.addFolder(src, "p/A"); //$NON-NLS-1$ + env.addFile(src, "p/A/some.properties", //$NON-NLS-1$ + "name=Some\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + } + + public void testNoFolderProblem2() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + IPath src2 = env.addPackageFragmentRoot(projectPath, "src2"); + + // create folder & contained non-java file (which don't establish package p.A!): + env.addFolder(src, "p/A"); //$NON-NLS-1$ + env.addFile(src, "p/A/some.properties", //$NON-NLS-1$ + "name=Some\n" //$NON-NLS-1$ + ); + + env.addClass(src2, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n"+ //$NON-NLS-1$ + "public class A {}" //$NON-NLS-1$ + ); + + IPath project2Path = env.addProject("Project2"); + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(project2Path, ""); //$NON-NLS-1$ + IPath srcP2 = env.addPackageFragmentRoot(project2Path, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + env.addRequiredProject(project2Path, projectPath, false); + + env.addClass(srcP2, "q", "Main", + "package q;\n" + + "import p.A;\n" + + "public class Main {\n" + + " A field;\n" + + "}\n"); + + fullBuild(); + expectingNoProblems(); + } + + public void testNestedPackageProblem() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath src = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath aPath = env.addClass(src, "p", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p;\n"+ //$NON-NLS-1$ + "public class A {}\n" //$NON-NLS-1$ + ); + + // a class in a sub-package of p.A seems to establish package p.A, too, causing a conflict indeed: + env.addClass(src, "p.A.c", "B", //$NON-NLS-1$ //$NON-NLS-2$ + "package p.A.c;\n" + + "public class B {}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingOnlySpecificProblemFor(aPath, + new Problem("", "The type A collides with a package", aPath, 24, 25, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ + } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=117092 +// simplistic linked subfolder used as package, external case (not in workspace) +public void test001() throws CoreException { + IPath projectPath = env.addProject("P"); + try { + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath src = env.addPackageFragmentRoot(projectPath, "src"); + IPath bin = env.setOutputFolder(projectPath, "bin"); + env.addClass(src, "p", "X", + "package p;\n" + + "public class X {\n" + + "}\n" + ); + File tmpDir = env.getTmpDirectory(); + File externalPackageDir = new File(tmpDir.getAbsolutePath() + File.separator + "q"); + externalPackageDir.mkdir(); + IFolder folder = env.getWorkspace().getRoot().getFolder(src.append("p/q")); + folder.createLink(externalPackageDir.toURI(), 0, null); + env.addClass(src, "p.q", "Y", + "package p.q;\n" + + "public class Y extends p.X {\n" + + "}\n" + ); + env.addClass(src, "p.q.r", "Z", + "package p.q.r;\n" + + "public class Z extends p.q.Y {\n" + + "}\n" + ); + assertTrue(new File(externalPackageDir.getAbsolutePath() + + File.separator + "r" + File.separator + "Z.java").exists()); + fullBuild(); + expectingPresenceOf(bin.append("p/q/r/Z.class")); + + expectingNoProblems(); + env.removeClass(env.getPackagePath(src, "p.q.r"), "Z"); + env.removePackage(src, "p.q.r"); + incrementalBuild(); + expectingNoProblems(); + } finally { + env.deleteTmpDirectory(); + env.removeProject(projectPath); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=117092 +// simplistic linked subfolder used as package, internal case (in workspace) +public void test002() throws CoreException { + IPath projectPath = env.addProject("P"); + IPath externalProjectPath = env.addProject("EP"); + try { + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath src = env.addPackageFragmentRoot(projectPath, "src"); + IPath bin = env.setOutputFolder(projectPath, "bin"); + env.addClass(src, "p", "X", + "package p;\n" + + "public class X {\n" + + "}\n" + ); + IProject externalProject = env.getProject(externalProjectPath); + IFolder externalFolder = externalProject.getFolder("q"); + externalFolder.create(false /* no need to force */, true /*local */, + null /* no progress monitor */); + IFolder folder = env.getWorkspace().getRoot().getFolder(src.append("p/q")); + folder.createLink(externalFolder.getLocationURI(), 0, null); + env.addClass(src, "p.q", "Y", + "package p.q;\n" + + "public class Y extends p.X {\n" + + "}\n" + ); + env.addClass(src, "p.q.r", "Z", + "package p.q.r;\n" + + "public class Z extends p.q.Y {\n" + + "}\n" + ); + assertTrue(new File(externalFolder.getLocation() + + File.separator + "r" + File.separator + "Z.java").exists()); + env.incrementalBuild(projectPath); + expectingPresenceOf(bin.append("p/q/r/Z.class")); + + expectingNoProblems(); + env.removeClass(env.getPackagePath(src, "p.q.r"), "Z"); + env.removePackage(src, "p.q.r"); + env.incrementalBuild(projectPath); + expectingNoProblems(); + } finally { + env.deleteTmpDirectory(); + env.removeProject(projectPath); + env.removeProject(externalProjectPath); + } +} +} + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java new file mode 100644 index 0000000000..93a90abd4a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ParticipantBuildTests.java @@ -0,0 +1,537 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.io.*; +import java.util.*; + +import junit.framework.*; + +import org.eclipse.core.runtime.*; +import org.eclipse.core.resources.*; +import org.eclipse.jdt.core.*; +import org.eclipse.jdt.core.compiler.*; +import org.eclipse.jdt.core.dom.*; +import org.eclipse.jdt.core.tests.util.Util; + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class ParticipantBuildTests extends BuilderTests { + /** + * Internal synonym for deprecated constant AST.JSL3 + * to alleviate deprecation warnings. + * @deprecated + */ + /*package*/ static final int JLS3_INTERNAL = AST.JLS3; + + public ParticipantBuildTests(String name) { + super(name); + } + + public void tearDown() throws Exception { + TestBuilderParticipant.PARTICIPANT = null; + super.tearDown(); + } + + public static Test suite() { + return buildTestSuite(ParticipantBuildTests.class); + } + + static class BuildTestParticipant extends CompilationParticipant { + BuildTestParticipant() { + TestBuilderParticipant.PARTICIPANT = this; + } + } + + static class ParticipantProblem extends CategorizedProblem { + int counter = 0; + String message; + int id; + char[] filename; + ParticipantProblem(String message, String filename) { + this.message = message; + this.id = this.counter ++; + this.filename = filename.toCharArray(); + } + public String[] getArguments() { return new String[0]; } + public int getID() { return this.id; } + public String getMessage() { return this.message; } + public char[] getOriginatingFileName() { return this.filename; } + public int getSourceStart() { return 0; } + public int getSourceEnd() { return 0; } + public int getSourceLineNumber() { return 1; } + public boolean isError() { return true; } + public boolean isWarning() { return false; } + public boolean isInfo() { return false; } + public void setSourceEnd(int sourceEnd) {/* not needed */} + public void setSourceLineNumber(int lineNumber) {/* not needed */} + public void setSourceStart(int sourceStart) {/* not needed */} + public int getCategoryID() { return 0; } + public String getMarkerType() { return "org.eclipse.jdt.core.tests.compile.problem"; } + } + + CompilationUnit buildCompilationUnit(BuildContext file) { + IJavaProject javaProject = JavaCore.create(file.getFile().getProject()); + ASTParser p = ASTParser.newParser(JLS3_INTERNAL); + p.setProject(javaProject); + p.setSource(file.getContents()); + p.setResolveBindings(true); + p.setKind(ASTParser.K_COMPILATION_UNIT); + p.setUnitName(file.getFile().getName()); + return (CompilationUnit) p.createAST(null); + } + + public void testBuildStarting() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + IPath test = env.addClass(root, "", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Test extends GeneratedType {}\n" //$NON-NLS-1$ + ); + + // install compilationParticipant + new BuildTestParticipant() { + int buildPass = 0; + public void buildStarting(BuildContext[] files, boolean isBatchBuild) { + // want to add a gen'ed source file that is referenced from the initial file to see if its recompiled + BuildContext result = files[0]; + IFile genedType = result.getFile().getParent().getFile(new Path("GeneratedType.java")); //$NON-NLS-1$ + if (this.buildPass == 0 || this.buildPass == 3) { + try { + genedType.create(new ByteArrayInputStream("public class GeneratedType {}".getBytes()), true, null); //$NON-NLS-1$ + } catch (CoreException e) { + e.printStackTrace(); + } + result.recordAddedGeneratedFiles(new IFile[] {genedType}); + } else if (this.buildPass == 1) { + try { + genedType.delete(true, null); + } catch (CoreException e) { + e.printStackTrace(); + } + result.recordDeletedGeneratedFiles(new IFile[] {genedType}); + } + this.buildPass++; + } + }; + incrementalBuild(projectPath); + expectingNoProblems(); + + // GeneratedType will be deleted + env.addClass(root, "", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Test extends GeneratedType {}\n" //$NON-NLS-1$ + ); + incrementalBuild(projectPath); + expectingOnlySpecificProblemFor(test, new Problem("", "GeneratedType cannot be resolved to a type", test, 26, 39, CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR)); + + // GeneratedType will be recreated + env.addClass(root, "", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Test extends GeneratedType {}\n" //$NON-NLS-1$ + ); + incrementalBuild(projectPath); + expectingNoProblems(); + } + + public void testDefaultValue() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "test", "EntryPoint", //$NON-NLS-1$ //$NON-NLS-2$ + "package test;\n" + //$NON-NLS-1$ + "public class EntryPoint { ClassWithNestedAnnotation nestedAnnotation; }" //$NON-NLS-1$ + ); + + env.addClass(root, "test", "ClassWithNestedAnnotation", //$NON-NLS-1$ //$NON-NLS-2$ + "package test;\n" + //$NON-NLS-1$ + "public class ClassWithNestedAnnotation {\n" + //$NON-NLS-1$ + " public final int FOUR = 4; \n " + //$NON-NLS-1$ + " public @interface NestedAnnotation {\n" + //$NON-NLS-1$ + " public enum Character { Winnie, Tiger, Piglet, Eore; }\n" + //$NON-NLS-1$ + " Character value() default Character.Eore; \n" + //$NON-NLS-1$ + " }\n" + //$NON-NLS-1$ + "}" //$NON-NLS-1$ + ); + + // install compilationParticipant + new BuildTestParticipant() { + public boolean isAnnotationProcessor() { + return true; + } + public void processAnnotations(BuildContext[] files) { + for (int i = 0, total = files.length; i < total; i++) { + IFile file = files[i].getFile(); + // Traversing the members of test.ClassWithNestedAnnotation through a reference in EntryPoint.java + if (!"EntryPoint.java".equals(file.getName())) continue; //$NON-NLS-1$ + + List problems = new ArrayList(); + CompilationUnit unit = buildCompilationUnit(files[i]); + List types = unit.types(); + for (int t = 0, l = types.size(); t < l; t++) { + AbstractTypeDeclaration typeDecl = (AbstractTypeDeclaration) types.get(t); + ITypeBinding typeBinding = typeDecl.resolveBinding(); + if (typeBinding == null) continue; + IVariableBinding[] fieldBindings = typeBinding.getDeclaredFields(); + for (int f = 0, fLength = fieldBindings.length; f < fLength; f++) { + IVariableBinding field = fieldBindings[f]; + if ("nestedAnnotation".equals(field.getName())) { + ITypeBinding fieldType = field.getType(); + ITypeBinding[] declaredTypes = fieldType.getDeclaredTypes(); + for (int d = 0, dLength = declaredTypes.length; d < dLength; d++) { + if (!"NestedAnnotation".equals(declaredTypes[d].getName())) continue; + IMethodBinding[] annotationMethods = declaredTypes[d].getDeclaredMethods(); + for (int m = 0, mLength = annotationMethods.length; m < mLength; m++) { + if (!"value".equals(annotationMethods[m].getName())) continue; + Object defaultValue = annotationMethods[m].getDefaultValue(); + assertTrue("Wrong class", defaultValue instanceof IVariableBinding); + IVariableBinding variableBinding = (IVariableBinding) defaultValue; + String defaultString = variableBinding.getName(); + String expected = "Eore"; + if (!expected.equals(defaultString)) { + IProblem problem = new ParticipantProblem("expecting default = " + expected + " not " + defaultString, file.getName()); + problems.add(problem); + } + } + } + IVariableBinding[] nestedFields = fieldType.getDeclaredFields(); + for (int nf = 0, nfLength = nestedFields.length; nf < nfLength; nf++) { + if (!nestedFields[nf].getName().equals("FOUR")) continue; + Object constant = nestedFields[nf].getConstantValue(); + String constantStr = constant == null ? "" : constant.toString(); + String expected = "4"; + if (!constantStr.equals(expected)) + problems.add(new ParticipantProblem("expecting constant = " + expected + " not " + constantStr, file.getName())); + } + } else { + problems.add(new ParticipantProblem("found unexpected field " + field, file.getName())); + } + } + } + if (!problems.isEmpty()) { + CategorizedProblem[] problemArray = new CategorizedProblem[problems.size()]; + problemArray = (CategorizedProblem[]) problems.toArray(problemArray); + files[i].recordNewProblems(problemArray); + } + } + } + }; + + fullBuild(projectPath); + expectingNoProblems(); + } + + /* + * Ensure that participants problems are correctly managed by the Java builder + * (regression test for bug 134345 Problems from CompilationParticipants do not get cleaned up unless there are Java errors) + */ + public void testParticipantProblems() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + + env.addClass(root, "p", "X", + "package p;\n" + + "public class X { /* generate problem*/ }" + ); + + // install compilationParticipant + new BuildTestParticipant() { + public void buildStarting(BuildContext[] files, boolean isBatch) { + for (int i = 0, total = files.length; i < total; i++) { + BuildContext context = files[i]; + if (CharOperation.indexOf("generate problem".toCharArray(), context.getContents(), true) != -1) { + context.recordNewProblems(new CategorizedProblem[] {new ParticipantProblem("Participant problem", context.getFile().getFullPath().toString())}); + } + } + } + }; + + fullBuild(projectPath); + expectingParticipantProblems(projectPath, "Participant problem"); + + env.addClass(root, "p", "X", + "package p;\n" + + "public class X { }" + ); + incrementalBuild(projectPath); + expectingParticipantProblems(projectPath, ""); + } + + public void testProcessAnnotationDeclarations() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "@interface TestAnnotation {}\n" + //$NON-NLS-1$ + "public class Test extends GeneratedType {}\n" //$NON-NLS-1$ + ); + + env.addClass(root, "", "Other", //$NON-NLS-1$ //$NON-NLS-2$ + "public class Other { MissingAnnotation m; }\n" //$NON-NLS-1$ + ); + + // install compilationParticipant + new BuildTestParticipant() { + int count = 2; + public boolean isAnnotationProcessor() { + return true; + } + public void processAnnotations(BuildContext[] files) { + // want to add a gen'ed source file that is referenced from the initial file to see if its recompiled + if (this.count == 2) { + this.count--; + BuildContext result = files[0]; + IFile genedType = result.getFile().getParent().getFile(new Path("MissingAnnotation.java")); //$NON-NLS-1$ + try { + genedType.create(new ByteArrayInputStream("public @interface MissingAnnotation {}".getBytes()), true, null); //$NON-NLS-1$ + } catch (CoreException e) { + e.printStackTrace(); + } + result.recordAddedGeneratedFiles(new IFile[] {genedType}); + } else if (this.count == 1) { + this.count--; + BuildContext result = files[0]; + IFile genedType = result.getFile().getParent().getFile(new Path("GeneratedType.java")); //$NON-NLS-1$ + try { + genedType.create(new ByteArrayInputStream("public class GeneratedType {}".getBytes()), true, null); //$NON-NLS-1$ + } catch (CoreException e) { + e.printStackTrace(); + } + result.recordAddedGeneratedFiles(new IFile[] {genedType}); + } + } + }; + + fullBuild(projectPath); + expectingNoProblems(); + } + + public void testProcessAnnotationQualifiedReferences() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "p1", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "@GeneratedAnnotation\n" + //$NON-NLS-1$ + "public class Test { public void method() { p1.p2.GeneratedType.method(); } }\n" //$NON-NLS-1$ + ); + + env.addClass(root, "p1", "GeneratedAnnotation", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "@interface GeneratedAnnotation{}\n" //$NON-NLS-1$ + ); + + // install compilationParticipant + new BuildTestParticipant() { + public boolean isAnnotationProcessor() { + return true; + } + public void processAnnotations(BuildContext[] files) { + // want to add a gen'ed source file that is referenced from the initial file to see if its recompiled + BuildContext result = files[0]; + IFile genedType = result.getFile().getProject().getFile(new Path("src/p1/p2/GeneratedType.java")); //$NON-NLS-1$ + if (genedType.exists()) return; + try { + IFolder folder = (IFolder) genedType.getParent(); + if(!folder.exists()) + folder.create(true, true, null); + genedType.create(new ByteArrayInputStream("package p1.p2; public class GeneratedType { public static void method(){} }".getBytes()), true, null); //$NON-NLS-1$ + } catch (CoreException e) { + e.printStackTrace(); + } + result.recordAddedGeneratedFiles(new IFile[] {genedType}); + } + }; + + fullBuild(projectPath); + expectingNoProblems(); + } + + public void testProcessAnnotationReferences() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "", "Test", //$NON-NLS-1$ //$NON-NLS-2$ + "@GeneratedAnnotation\n" + //$NON-NLS-1$ + "public class Test {}\n" //$NON-NLS-1$ + ); + + // install compilationParticipant + new BuildTestParticipant() { + public boolean isAnnotationProcessor() { + return true; + } + public void processAnnotations(BuildContext[] files) { + // want to add a gen'ed source file that is referenced from the initial file to see if its recompiled + BuildContext result = files[0]; + IFile genedType = result.getFile().getParent().getFile(new Path("GeneratedAnnotation.java")); //$NON-NLS-1$ + if (genedType.exists()) return; + try { + genedType.create(new ByteArrayInputStream("@interface GeneratedAnnotation {}".getBytes()), true, null); //$NON-NLS-1$ + } catch (CoreException e) { + e.printStackTrace(); + } + result.recordAddedGeneratedFiles(new IFile[] {genedType}); + } + }; + + fullBuild(projectPath); + expectingNoProblems(); + } + + public void testResolvedMethod() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); //$NON-NLS-1$ //$NON-NLS-2$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); //$NON-NLS-1$ + IPath root = env.addPackageFragmentRoot(projectPath, "src"); //$NON-NLS-1$ + env.setOutputFolder(projectPath, "bin"); //$NON-NLS-1$ + + env.addClass(root, "", "Try", //$NON-NLS-1$ //$NON-NLS-2$ + "@SuppressWarnings(\"all\")\n" + //$NON-NLS-1$ + "public class Try {}" //$NON-NLS-1$ + ); + + // install compilationParticipant + new BuildTestParticipant() { + public boolean isAnnotationProcessor() { + return true; + } + public void processAnnotations(BuildContext[] files) { + for (int i = 0, total = files.length; i < total; i++) { + IFile file = files[i].getFile(); + // Traversing the members of test.ClassWithNestedAnnotation through a reference in EntryPoint.java + if (!"Try.java".equals(file.getName())) continue; //$NON-NLS-1$ + + List problems = new ArrayList(); + CompilationUnit unit = buildCompilationUnit(files[i]); + List types = unit.types(); + for (int t = 0, l = types.size(); t < l; t++) { + AbstractTypeDeclaration typeDecl = (AbstractTypeDeclaration) types.get(t); + ITypeBinding typeBinding = typeDecl.resolveBinding(); + if (typeBinding == null) continue; + IAnnotationBinding[] annotations = typeBinding.getAnnotations(); + if (annotations == null || annotations.length == 0) { + throw new IllegalStateException( + "Expected at least one annotation in binding " + typeBinding); + } + IAnnotationBinding targetValue = annotations[0]; + typeBinding = targetValue.getAnnotationType(); + + IMemberValuePairBinding[] pairs = targetValue.getAllMemberValuePairs(); + if (pairs == null || pairs.length == 0) { + throw new IllegalStateException( + "Expected at least one member value pair in " + targetValue + + ", binding was: " + typeBinding); + } + IMethodBinding method = pairs[0].getMethodBinding(); + if (!"value".equals(method.getName())) + problems.add(new ParticipantProblem("method " + method.getName() + " not found", file.getName())); + } + if (!problems.isEmpty()) { + CategorizedProblem[] problemArray = new CategorizedProblem[problems.size()]; + problemArray = (CategorizedProblem[]) problems.toArray(problemArray); + files[i].recordNewProblems(problemArray); + } + } + } + }; + + fullBuild(projectPath); + expectingNoProblems(); + } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test1001() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + env.addClass(root, "p", "X", + "package p;\n" + + "public class X { /* generate problem*/ }" + ); + new BuildTestParticipant() { + public void buildStarting(BuildContext[] files, boolean isBatch) { + for (int i = 0, total = files.length; i < total; i++) { + BuildContext context = files[i]; + if (CharOperation.indexOf("generate problem".toCharArray(), + context.getContents(), true) != -1) { + context.recordNewProblems(new CategorizedProblem[] { + new ParticipantProblem("Participant problem", context.getFile().getFullPath().toString())}); + } + } + } + }; + fullBuild(projectPath); + Problem[] problems = env.getProblemsFor(projectPath, "org.eclipse.jdt.core.tests.compile.problem"); + assertNotNull("null problems array", problems); + assertEquals("unexpected problems count", 1, problems.length); + assertEquals("unexpected generated by attribute", "missing", problems[0].getSourceId()); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158611 +// Checking the GENERATED_BY attribute +public void test1002() throws JavaModelException { + IPath projectPath = env.addProject("Project", "1.5"); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + env.removePackageFragmentRoot(projectPath, ""); + IPath root = env.addPackageFragmentRoot(projectPath, "src"); + env.setOutputFolder(projectPath, "bin"); + env.addClass(root, "p", "X", + "package p;\n" + + "public class X { /* generate problem*/ }" + ); + final String specificGeneratedBy = "specific"; + new BuildTestParticipant() { + public void buildStarting(BuildContext[] files, boolean isBatch) { + for (int i = 0, total = files.length; i < total; i++) { + BuildContext context = files[i]; + if (CharOperation.indexOf("generate problem".toCharArray(), + context.getContents(), true) != -1) { + context.recordNewProblems(new CategorizedProblem[] { + new ParticipantProblem("Participant problem", context.getFile().getFullPath().toString()) { + public String[] getExtraMarkerAttributeNames() { + return new String[] {IMarker.SOURCE_ID}; + } + public Object[] getExtraMarkerAttributeValues() { + return new String[] {specificGeneratedBy}; + } + }}); + } + } + } + }; + fullBuild(projectPath); + Problem[] problems = env.getProblemsFor(projectPath, "org.eclipse.jdt.core.tests.compile.problem"); + assertNotNull("null problems array", problems); + assertEquals("unexpected problems count", 1, problems.length); + assertEquals("unexpected generated by attribute", specificGeneratedBy, problems[0].getSourceId()); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Problem.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Problem.java new file mode 100644 index 0000000000..f2f334876c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/Problem.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.IJavaModelMarker; + +@SuppressWarnings("rawtypes") +public class Problem implements Comparable { + private String location; + private String message; + private IPath resourcePath; + private int start = -1, end = -1, categoryId = -1; + private String sourceId; + private int severity = IMarker.SEVERITY_ERROR; + + public Problem(String location, String message, IPath resourcePath, int start, int end, int categoryId, int severity) { + this.location = location; + this.message = message; + this.resourcePath = resourcePath; + this.start = start; + this.end = end; + this.categoryId = categoryId; + this.severity = severity; +// if ((start > 0 || end > 0) && categoryId <= 0) { +// System.out.print("is categoryId properly set ? new Problem(\"" + location + "\", \"" + message + "\", \"" + resourcePath + "\""); +// System.out.print(", " + start + ", " + end + ", " + categoryId); +// System.out.println(")"); +// } + } + + public Problem(IMarker marker){ + this.location = marker.getAttribute(IMarker.LOCATION, ""); //$NON-NLS-1$ + this.message = marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$ + this.resourcePath = marker.getResource().getFullPath(); + this.start = marker.getAttribute(IMarker.CHAR_START, -1); + this.end = marker.getAttribute(IMarker.CHAR_END, -1); + this.categoryId = marker.getAttribute(IJavaModelMarker.CATEGORY_ID, -1); + this.sourceId = marker.getAttribute(IMarker.SOURCE_ID, "missing"); + this.severity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); + } + public int getCategoryId() { + return this.categoryId; + } + +/** + * Return the IMarker.SOURCE_ID attribute of the underlying marker if any. + * Value null denotes a problem created from explicit structural attributes + * (instead of using a source marker). Value "missing" denotes that the marker + * used to initialize the problem had no IMarker.SOURCE_ID attribute. + * @return the IMarker.SOURCE_ID attribute of the underlying marker if any + */ +public String getSourceId() { + return this.sourceId; +} + /** + * Gets the location. + * @return Returns a String + */ + public String getLocation() { + return this.location; + } + /** + * Gets the message. + * @return Returns a String + */ + public String getMessage() { + return this.message; + } + /** + * Gets the resourcePath. + * @return Returns a IPath + */ + public IPath getResourcePath() { + return this.resourcePath; + } + +public int getSeverity() { + return this.severity; +} + + public int getStart() { + return this.start; + } + + public int getEnd() { + return this.end; + } + + public String toString(){ +// ignore locations since the builder no longer finds exact Java elements +// return "Problem : " + message + " [ resource : <" + resourcePath + "> location <"+ location + "> ]"; + return + "Problem : " + + this.message + + " [ resource : <" + + this.resourcePath + + ">" + + (" range : <" + this.start + "," + this.end + ">") + + (" category : <" + this.categoryId + ">") + + (" severity : <" + this.severity + ">") + + "]"; + } + + public boolean equals(Object o){ + if(o instanceof Problem){ + return toString().equals(o.toString()); + } + return false; + } + + public int compareTo(Object o) { + if(o instanceof Problem){ + Problem problem = (Problem) o; + /* Replace initial implementation with toString() comparison otherwise the problems order may change + * when different VM are used (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=213570)... + if (!(this.getLocation().equals(problem.getLocation()))) { + return this.getLocation().compareTo(problem.getLocation()); + } + if (this.getStart() < problem.getStart()) { + return -1; + } + if (this.getEnd() < problem.getEnd()) { + return -1; + } + return this.getMessage().compareTo(problem.getMessage()); + */ + return toString().compareTo(problem.toString()); + } + return -1; + } +} + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ReferenceCollectionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ReferenceCollectionTest.java new file mode 100644 index 0000000000..c60d73f6b7 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/ReferenceCollectionTest.java @@ -0,0 +1,372 @@ +/******************************************************************************* + * Copyright (c) 2019 Sebastian Zarnekow and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Zarnekow - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import static org.junit.Assert.assertArrayEquals; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Collections; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.core.builder.ReferenceCollection; + +import junit.framework.Test; + +public class ReferenceCollectionTest extends BuilderTests { + + public ReferenceCollectionTest(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(ReferenceCollectionTest.class); + } + + private static class TestableReferenceCollection extends ReferenceCollection { + /* + Make the package visible fields reflectively available for testing + char[][][] qualifiedNameReferences; + char[][] simpleNameReferences; + char[][] rootReferences; + */ + protected TestableReferenceCollection(char[][][] qualifiedNameReferences, char[][] simpleNameReferences, + char[][] rootReferences) { + super(qualifiedNameReferences, simpleNameReferences, rootReferences); + } + + char[][][] getQualifiedNameReferences() { + try { + Field fld = ReferenceCollection.class.getDeclaredField("qualifiedNameReferences"); + fld.setAccessible(true); + return (char[][][]) fld.get(this); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + char[][] getSimpleNameReferences() { + try { + Field fld = ReferenceCollection.class.getDeclaredField("simpleNameReferences"); + fld.setAccessible(true); + return (char[][]) fld.get(this); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + char[][] getRootReferences() { + try { + Field fld = ReferenceCollection.class.getDeclaredField("rootReferences"); + fld.setAccessible(true); + return (char[][]) fld.get(this); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + + public void testInternQualifiedNamesSorts_01() { + char[][][] qualifiedNames = new char[][][] { + CharOperation.splitOn('.', "java.lang.RuntimeException".toCharArray()), + CharOperation.splitOn('.', "a.a.a".toCharArray()), + CharOperation.splitOn('.', "b.b.b".toCharArray()), + CharOperation.splitOn('.', "a.a".toCharArray()), + CharOperation.splitOn('.', "a.b".toCharArray()), + CharOperation.splitOn('.', "com".toCharArray()), + CharOperation.splitOn('.', "a".toCharArray()), + CharOperation.splitOn('.', "b".toCharArray()) + }; + char[][][] expectation = qualifiedNames.clone(); + Collections.shuffle(Arrays.asList(qualifiedNames)); + char[][][] internQualifiedNames = ReferenceCollection.internQualifiedNames(qualifiedNames, true); + assertArrayEquals("Should be sorted, longest first, alphanumeric later", + toStringArray(expectation), + toStringArray(internQualifiedNames)); + } + + public void testInternQualifiedNamesSorts_02() { + char[][][] qualifiedNames = new char[][][] { + CharOperation.splitOn('.', "java.lang.RuntimeException".toCharArray()), + CharOperation.splitOn('.', "a.a.a".toCharArray()), + CharOperation.splitOn('.', "b.b.b".toCharArray()), + CharOperation.splitOn('.', "a.a".toCharArray()), + CharOperation.splitOn('.', "a.b".toCharArray()), + CharOperation.splitOn('.', "com".toCharArray()), + CharOperation.splitOn('.', "a".toCharArray()), + CharOperation.splitOn('.', "b".toCharArray()) + }; + char[][][] expectation = new char[][][] { + CharOperation.splitOn('.', "a.a.a".toCharArray()), + CharOperation.splitOn('.', "b.b.b".toCharArray()), + CharOperation.splitOn('.', "a.a".toCharArray()), + CharOperation.splitOn('.', "a.b".toCharArray()), + CharOperation.splitOn('.', "a".toCharArray()), + CharOperation.splitOn('.', "b".toCharArray()) + }; + Collections.shuffle(Arrays.asList(qualifiedNames)); + char[][][] internQualifiedNames = ReferenceCollection.internQualifiedNames(qualifiedNames, false); + assertArrayEquals("Should be sorted, longest first, alphanumeric later", + toStringArray(expectation), + toStringArray(internQualifiedNames)); + } + + public void testInternSimpleNamesSorts_01() { + char[][] simpleNames = new char[][] { + "Throwable".toCharArray(), + "aaa".toCharArray(), + "bbb".toCharArray(), + "ccc".toCharArray(), + "aa".toCharArray(), + "a".toCharArray() + }; + char[][] expectation = simpleNames.clone(); + Collections.shuffle(Arrays.asList(simpleNames)); + char[][] internSimpleNames = ReferenceCollection.internSimpleNames(simpleNames, false); + assertArrayEquals("Should be sorted, longest first, alphanumeric later", + toStringArray(expectation), + toStringArray(internSimpleNames)); + } + + public void testInternSimpleNamesSorts_02() { + char[][] simpleNames = new char[][] { + "aaa".toCharArray(), + "bbb".toCharArray(), + "Throwable".toCharArray(), + "ccc".toCharArray(), + "java".toCharArray(), + "aa".toCharArray(), + "a".toCharArray() + }; + char[][] expectation = new char[][] { + "aaa".toCharArray(), + "bbb".toCharArray(), + "ccc".toCharArray(), + "aa".toCharArray(), + "a".toCharArray() + }; + Collections.shuffle(Arrays.asList(simpleNames)); + char[][] internSimpleNames = ReferenceCollection.internSimpleNames(simpleNames, true); + assertArrayEquals("Should be sorted, longest first, alphanumeric later", + toStringArray(expectation), + toStringArray(internSimpleNames)); + } + + public void testIncludesWithBinarySearch() { + char[][] simpleNames = ReferenceCollection.internSimpleNames(new char[][] { + "a".toCharArray(), + "b".toCharArray(), + "c".toCharArray(), + "d".toCharArray(), + "e".toCharArray(), + "f".toCharArray(), + "g".toCharArray(), + "h".toCharArray(), + "i".toCharArray(), + "j".toCharArray(), + "k".toCharArray(), + "l".toCharArray(), + "m".toCharArray(), + "n".toCharArray(), + "o".toCharArray(), + "p".toCharArray(), + "q".toCharArray(), + "r".toCharArray(), + "s".toCharArray(), + "t".toCharArray(), + "u".toCharArray(), + "v".toCharArray(), + "w".toCharArray(), + "x".toCharArray(), + "y".toCharArray(), + "z".toCharArray() + }, false); + ReferenceCollection collection = new TestableReferenceCollection(null, simpleNames, null); + for(char[] simpleName: simpleNames) { + assertTrue("Should include " + simpleName[0], collection.includes(simpleName)); + assertFalse("Should not include " + CharOperation.toUpperCase(simpleName)[0], collection.includes(CharOperation.toUpperCase(simpleName))); + } + } + + public void testIncludesWithLinearSearch() { + char[][] simpleNames = ReferenceCollection.internSimpleNames(new char[][] { + "a".toCharArray(), + "b".toCharArray(), + "c".toCharArray(), + "d".toCharArray(), + "e".toCharArray(), + "f".toCharArray(), + "g".toCharArray(), + "h".toCharArray() + }, false); + ReferenceCollection collection = new TestableReferenceCollection(null, simpleNames, null); + for(char[] simpleName: simpleNames) { + assertTrue("Should include " + simpleName[0], collection.includes(simpleName)); + assertFalse("Should not include " + CharOperation.toUpperCase(simpleName)[0], collection.includes(CharOperation.toUpperCase(simpleName))); + } + } + + public void testIncludes01() { + TestableReferenceCollection refColl = new TestableReferenceCollection(null, null, null); + + String[] array = new String[] { "a.a", "b.a", "b.b" }; + refColl.addDependencies(array); + + TestableReferenceCollection other = new TestableReferenceCollection(null, null, null); + String[] array2 = new String[] { "a.a", "B.A", "b.b" }; + other.addDependencies(array2); + + assertTrue(refColl.includes(other.getQualifiedNameReferences(), other.getSimpleNameReferences(), other.getRootReferences())); + assertTrue(other.includes(refColl.getQualifiedNameReferences(), refColl.getSimpleNameReferences(), refColl.getRootReferences())); + } + + public void testIncludes02() { + TestableReferenceCollection refColl = new TestableReferenceCollection(null, null, null); + + String[] array = new String[] { "a.x", "b.y" }; + refColl.addDependencies(array); + + TestableReferenceCollection other = new TestableReferenceCollection(null, null, null); + String[] array2 = new String[] { "a.y", "b.x" }; + other.addDependencies(array2); + + assertTrue(refColl.includes(other.getQualifiedNameReferences(), other.getSimpleNameReferences(), other.getRootReferences())); + assertTrue(other.includes(refColl.getQualifiedNameReferences(), refColl.getSimpleNameReferences(), refColl.getRootReferences())); + } + + public void testIncludes03() { + TestableReferenceCollection refColl = new TestableReferenceCollection(null, null, null); + + String[] array = new String[] { "a.d.y", "c.x" }; + refColl.addDependencies(array); + + TestableReferenceCollection other = new TestableReferenceCollection(null, null, null); + String[] array2 = new String[] { "c.y" }; + other.addDependencies(array2); + + assertTrue(refColl.includes(other.getQualifiedNameReferences(), other.getSimpleNameReferences(), other.getRootReferences())); + assertTrue(other.includes(refColl.getQualifiedNameReferences(), refColl.getSimpleNameReferences(), refColl.getRootReferences())); + } + + public void testIncludes04() { + TestableReferenceCollection refColl = new TestableReferenceCollection(null, null, null); + + String[] array = new String[] { "a.d.y" }; + refColl.addDependencies(array); + + TestableReferenceCollection other = new TestableReferenceCollection(null, null, null); + String[] array2 = new String[] { "a.d" }; + other.addDependencies(array2); + + assertTrue(refColl.includes(other.getQualifiedNameReferences(), other.getSimpleNameReferences(), other.getRootReferences())); + assertTrue(other.includes(refColl.getQualifiedNameReferences(), refColl.getSimpleNameReferences(), refColl.getRootReferences())); + } + + public void testIncludesNot() { + TestableReferenceCollection refColl = new TestableReferenceCollection(null, null, null); + + String[] array = new String[] {"b.a"}; + refColl.addDependencies(array); + + TestableReferenceCollection other = new TestableReferenceCollection(null, null, null); + String[] array2 = new String[] {"B.A"}; + other.addDependencies(array2); + + assertFalse(refColl.includes(other.getQualifiedNameReferences(), other.getSimpleNameReferences(), other.getRootReferences())); + assertFalse(other.includes(refColl.getQualifiedNameReferences(), refColl.getSimpleNameReferences(), refColl.getRootReferences())); + } + + public void testAddDependencies() { + TestableReferenceCollection refColl = new TestableReferenceCollection(null, null, null); + + String[] array = new String[] {"a.b.c.D"}; + refColl.addDependencies(array); + + char[][][] qualifiedNameReferences = refColl.getQualifiedNameReferences(); + String [] strings = toStringArray(qualifiedNameReferences); + assertArrayEquals(new String[] { + "a.b.c.D", + "a.b.c", + "a.b", + "a" + }, strings); + + char[][] simpleNameReferences = refColl.getSimpleNameReferences(); + assertArrayEquals(new String[] { + "D", + "a", + "b", + "c" + }, CharOperation.toStrings(simpleNameReferences)); + + char[][] rootReferences = refColl.getRootReferences(); + assertArrayEquals(new String[] { + "a" + }, CharOperation.toStrings(rootReferences)); + } + + private static String[] toStringArray(char[][][] qualifiedNameReferences) { + return Arrays.stream(qualifiedNameReferences).map(a -> CharOperation.toString(a)).toArray(String[]::new); + } + + private static String[] toStringArray(char[][] qualifiedNameReferences) { + return Arrays.stream(qualifiedNameReferences).map(a -> CharOperation.charToString(a)).toArray(String[]::new); + } + + public void testRegression01() { + char[][][] qualifiedNames = new char[][][] { + CharOperation.splitOn('.', "p1.IX".toCharArray()), + CharOperation.splitOn('.', "p2.X".toCharArray()) + }; + char[][] simpleNames = new char[][] { + "I__X".toCharArray(), "IX".toCharArray(), "p1".toCharArray(), "p2".toCharArray(), "X".toCharArray() + }; + char[][] rootNames = new char[][] { + "java".toCharArray(), "IX".toCharArray(), "p1".toCharArray(), "p2".toCharArray() + }; + ReferenceCollection collection = new TestableReferenceCollection(qualifiedNames, simpleNames, rootNames); + qualifiedNames = ReferenceCollection.internQualifiedNames(new char[][][] { + CharOperation.splitOn('.', "p2".toCharArray()) + }); + simpleNames = ReferenceCollection.internSimpleNames(new char[][] { + "X".toCharArray() + }, true); + rootNames = ReferenceCollection.internSimpleNames(new char[][] { + "p2".toCharArray() + }, false); + + assertTrue("Should include", collection.includes(qualifiedNames, simpleNames, rootNames)); + } + + public void testRegression02() { + char[][][] qualifiedNames = new char[][][] {}; + char[][] simpleNames = new char[][] { + "GeneratedAnnotation".toCharArray(), "Test".toCharArray() + }; + char[][] rootNames = new char[][] { + "java".toCharArray(), "GeneratedAnnotation".toCharArray() + }; + ReferenceCollection collection = new TestableReferenceCollection(qualifiedNames, simpleNames, rootNames); + + qualifiedNames = null; + simpleNames = ReferenceCollection.internSimpleNames(new char[][] { + "GeneratedAnnotation".toCharArray() + }, true); + rootNames = ReferenceCollection.internSimpleNames(new char[][] { + "GeneratedAnnotation".toCharArray() + }, false); + + assertTrue("Should include", collection.includes(qualifiedNames, simpleNames, rootNames)); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/StateTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/StateTest.java new file mode 100644 index 0000000000..2cae4528a8 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/StateTest.java @@ -0,0 +1,351 @@ +/******************************************************************************* + * Copyright (c) 2019 Sebastian Zarnekow and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sebastian Zarnekow - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import static org.junit.Assert.assertArrayEquals; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.Map; +import java.util.Set; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IAccessRule; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo; +import org.eclipse.jdt.internal.core.builder.ClasspathLocation; +import org.eclipse.jdt.internal.core.builder.JavaBuilder; +import org.eclipse.jdt.internal.core.builder.ReferenceCollection; +import org.eclipse.jdt.internal.core.builder.State; + +import junit.framework.Test; + +public class StateTest extends BuilderTests { + + public StateTest(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(StateTest.class); + } + + public void testWriteAndReadState() throws JavaModelException, Exception { + IPath interfaceProjectPath = env.addProject("Interface"); //$NON-NLS-1$ + env.addExternalJars(interfaceProjectPath, Util.getJavaClassLibs()); + + IPath implementationProjectPath = env.addProject("Implementation"); //$NON-NLS-1$ + env.addExternalJars(implementationProjectPath, Util.getJavaClassLibs()); + env.addClassFolder(implementationProjectPath, interfaceProjectPath, false); + + env.addClass(interfaceProjectPath, "a", "Interfaze", //$NON-NLS-1$ //$NON-NLS-2$ + "package a;\n" + + "public interface Interfaze {\n" + + " void callMe();\n" + + "}" //$NON-NLS-1$ + ); + + env.addClass(interfaceProjectPath, "c", "Impl1", //$NON-NLS-1$ //$NON-NLS-2$ + "package c;\n" + + "import a.Interfaze;\n" + + "public class Impl1 implements Interfaze {\n" + + " @Override\n" + + " public void callMe() {\n" + + " }\n" + + "}" + ); + + env.addClass(implementationProjectPath, "b", "Impl2", //$NON-NLS-1$ //$NON-NLS-2$ + "package b;\n" + + "import a.Interfaze;\n" + + "public class Impl2 implements Interfaze {\n" + + " @Override\n" + + " public void callMe() {\n" + + " }\n" + + "}" //$NON-NLS-1$ + ); + fullBuild(); + + writeReadAndCompareReferences(interfaceProjectPath); + writeReadAndCompareReferences(implementationProjectPath); + } + + + public void testBug563546() throws JavaModelException, Exception { + IPath project = env.addProject("Bug563546"); //$NON-NLS-1$ + env.addExternalJars(project, Util.getJavaClassLibs()); + + env.addClass(project, "a", "WithOther", //$NON-NLS-1$ //$NON-NLS-2$ + "package a;\n" + + "class Other {\n" + + "}\n" + + "public class WithOther {\n" + + "}" //$NON-NLS-1$ + ); + fullBuild(); + env.removePackage(project, "a"); + incrementalBuild(); + + writeReadAndCompareReferences(project); + } + + public void testBug567532() throws JavaModelException, Exception { + IPath project = env.addProject("Bug567532"); //$NON-NLS-1$ + String[] classLibs = Util.getJavaClassLibs(); + for (String jar : classLibs) { + env.addEntry(project, + JavaCore.newLibraryEntry( + new Path(jar), + null, + null, + new IAccessRule[0], + new IClasspathAttribute[] { + JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true"), + JavaCore.newClasspathAttribute(IClasspathAttribute.ADD_EXPORTS, + "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED") }, + false)); + } + + env.addClass(project, "a", "WithOther", //$NON-NLS-1$ //$NON-NLS-2$ + "package a;\n" + + "class Other {\n" + + "}\n" + + "public class WithOther {\n" + + "}" //$NON-NLS-1$ + ); + fullBuild(); + env.removePackage(project, "a"); + incrementalBuild(); + + writeReadAndCompareTestBinaryLocations(project); + } + public void testSelfAnnotatedJars() throws CoreException, IOException { + // derived from the same named test in ExternalAnnotation18Test: + IPath projectPath = env.addProject("PrjTest", "1.8"); //$NON-NLS-1$ + IJavaProject project = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectPath.segment(0))); + + project.setOption(JavaCore.CORE_JAVA_BUILD_EXTERNAL_ANNOTATIONS_FROM_ALL_LOCATIONS, JavaCore.ENABLED); + + String projectLoc = project.getProject().getLocation().toString(); + Util.createJar(new String[] { + "pgen/CGen.java", + "package pgen;\n" + + "public class CGen {\n" + + " public String get(String in) { return in; }\n" + + "}\n" + }, + new String[] { + "pgen/CGen.eea", + "class pgen/CGen\n" + + "\n" + + "get\n" + + " (Ljava/lang/String;)Ljava/lang/String;\n" + + " (L1java/lang/String;)L1java/lang/String;\n" + }, + projectLoc+"/lib/prj1.jar", + "1.8"); + IClasspathEntry entry = JavaCore.newLibraryEntry( + new Path("/PrjTest/lib/prj1.jar"), + null/*access rules*/, + null, + false/*exported*/); + env.addEntry(project.getPath(), entry); + + Util.createJar(new String[] { + "pgen2/CGen2.java", + "package pgen2;\n" + + "public class CGen2 {\n" + + " public String get2(Exception in) { return in.toString(); }\n" + + "}\n" + }, + new String[] { + "pgen2/CGen2.eea", + "class pgen2/CGen2\n" + + "\n" + + "get2\n" + + " (Ljava/lang/Exception;)Ljava/lang/String;\n" + + " (L1java/lang/Exception;)L1java/lang/String;\n", + }, + projectLoc+"/lib/prj2.jar", + "1.8"); + entry = JavaCore.newLibraryEntry( + new Path("/PrjTest/lib/prj2.jar"), + null/*access rules*/, + null, + false/*exported*/); + env.addEntry(project.getPath(), entry); + project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); + + env.addFolder(project.getPath(), "src/p"); + env.addFile(project.getPath().append("src").append("p"), "Use.java", + "package p;\n" + + "import pgen.CGen;\n" + + "import pgen2.CGen2;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class Use {\n" + + " public @NonNull String test(CGen c) {\n" + + " String s = c.get(null);\n" + + " return s;\n" + + " }\n" + + " public @NonNull String test2(CGen2 c) {\n" + + " String s = c.get2(null);\n" + + " return s;\n" + + " }\n" + + "}\n"); + project.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null); + writeReadAndCompareExternalAnnotationLocations(project.getProject()); + } + + private void writeReadAndCompareTestBinaryLocations(IPath projectPath) + throws JavaModelException, IOException, CoreException { + JavaModelManager javaModelManager = JavaModelManager.getJavaModelManager(); + IProject project = env.getProject(projectPath); + PerProjectInfo info = javaModelManager.getPerProjectInfoCheckExistence(project); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + State savedState = (State) info.savedState; + JavaBuilder.writeState(savedState, new DataOutputStream(outputStream)); + byte[] bytes = outputStream.toByteArray(); + State readState = JavaBuilder.readState(project, new DataInputStream(new ByteArrayInputStream(bytes))); + assertEqualBinaryLocations(savedState.testBinaryLocations, readState.testBinaryLocations); + } + + private void assertEqualBinaryLocations(ClasspathLocation[] a, + ClasspathLocation[] b) { + assertEquals(a.length, b.length); + assertArrayEquals(a, b); + } + + private void writeReadAndCompareExternalAnnotationLocations(IProject project) + throws JavaModelException, IOException, CoreException { + JavaModelManager javaModelManager = JavaModelManager.getJavaModelManager(); + PerProjectInfo info = javaModelManager.getPerProjectInfoCheckExistence(project); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + State savedState = (State) info.savedState; + JavaBuilder.writeState(savedState, new DataOutputStream(outputStream)); + byte[] bytes = outputStream.toByteArray(); + State readState = JavaBuilder.readState(project, new DataInputStream(new ByteArrayInputStream(bytes))); + assertArrayEquals(savedState.binaryLocations, readState.binaryLocations); + // beyond this point we know that both arrays have the same length + for (int i=0; i < savedState.binaryLocations.length; i++) { + assertTrue("comparing eea locations of "+savedState.binaryLocations[i], savedState.binaryLocations[i].externalAnnotationsEquals(readState.binaryLocations[i])); + } + } + + private void writeReadAndCompareReferences(IPath projectPath) + throws JavaModelException, IOException, CoreException { + JavaModelManager javaModelManager = JavaModelManager.getJavaModelManager(); + IProject project = env.getProject(projectPath); + PerProjectInfo info = javaModelManager.getPerProjectInfoCheckExistence(project); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + State savedState = (State) info.savedState; + JavaBuilder.writeState(savedState, new DataOutputStream(outputStream)); + byte[] bytes = outputStream.toByteArray(); + State readState = JavaBuilder.readState(project, new DataInputStream(new ByteArrayInputStream(bytes))); + Map readReferences = readState.getReferences(); + assertEqualLookupTables(savedState.getReferences(), readReferences); + assertEqualTypeLocators(savedState.typeLocators, readState.typeLocators); + } + + private void assertEqualTypeLocators(Map tl1, Map tl2) { + assertEquals(tl1.size(), tl2.size()); + assertEquals(tl1.toString(), tl2.toString()); + + } + + private void assertEqualLookupTables(Map expectation, Map actual) { + assertEquals(expectation.size(), actual.size()); + Set expectedKeys = expectation.keySet(); + for (String key : expectedKeys) { + ReferenceCollection actualReferenceCollection = actual.get(key); + ReferenceCollection expectedReferenceCollection = expectation.get(key); + assertEqualReferenceCollections(expectedReferenceCollection, actualReferenceCollection); + } + } + + private void assertEqualReferenceCollections(ReferenceCollection expectedReferenceCollection, + ReferenceCollection actualReferenceCollection) { + { + char[][] expected = getSimpleNameReferences(expectedReferenceCollection); + char[][] actual = getSimpleNameReferences(actualReferenceCollection); + assertArrayEquals(toStringArray(expected), toStringArray(actual)); + } + { + char[][] expected = getRootReferences(expectedReferenceCollection); + char[][] actual = getRootReferences(actualReferenceCollection); + assertArrayEquals(toStringArray(expected), toStringArray(actual)); + } + { + char[][][] expected = getQualifiedNameReferences(expectedReferenceCollection); + char[][][] actual = getQualifiedNameReferences(actualReferenceCollection); + assertArrayEquals(toStringArray(expected), toStringArray(actual)); + } + } + + private static String[] toStringArray(char[][][] qualifiedNameReferences) { + return Arrays.stream(qualifiedNameReferences).map(a -> CharOperation.toString(a)).toArray(String[]::new); + } + + private static String[] toStringArray(char[][] qualifiedNameReferences) { + return Arrays.stream(qualifiedNameReferences).map(a -> CharOperation.charToString(a)).toArray(String[]::new); + } + + char[][][] getQualifiedNameReferences(ReferenceCollection collection) { + try { + Field fld = ReferenceCollection.class.getDeclaredField("qualifiedNameReferences"); + fld.setAccessible(true); + return (char[][][]) fld.get(collection); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + char[][] getSimpleNameReferences(ReferenceCollection collection) { + try { + Field fld = ReferenceCollection.class.getDeclaredField("simpleNameReferences"); + fld.setAccessible(true); + return (char[][]) fld.get(collection); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + char[][] getRootReferences(ReferenceCollection collection) { + try { + Field fld = ReferenceCollection.class.getDeclaredField("rootReferences"); + fld.setAccessible(true); + return (char[][]) fld.get(collection); + } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/StaticFinalTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/StaticFinalTests.java new file mode 100644 index 0000000000..7a6f77556a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/StaticFinalTests.java @@ -0,0 +1,318 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import junit.framework.*; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; + +public class StaticFinalTests extends BuilderTests { + + public StaticFinalTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(StaticFinalTests.class); + } + + public void testBoolean() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final boolean VAR = true; }" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "p1", "Main", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class Main {\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(A.VAR);\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "true", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final boolean VAR = false; }" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "false", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + public void testByte() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final byte VAR = (byte) 0; }" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "p1", "Main", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class Main {\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(A.VAR);\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "0", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final byte VAR = (byte) 1; }" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "1", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + public void testChar() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final String VAR = \"Hello\"; }" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "p1", "Main", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class Main {\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(A.VAR);\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "Hello", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final String VAR = \"Bye\"; }" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "Bye", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + public void testDouble() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final double VAR = (double) 2; }" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "p1", "Main", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class Main {\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(A.VAR);\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "2", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final double VAR = (double) 3; }" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "3", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + public void testFloat() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final float VAR = (float) 4; }" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "p1", "Main", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class Main {\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(A.VAR);\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "4", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final float VAR = (float) 5; }" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "5", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + public void testInt() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final int VAR = (int) 6; }" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "p1", "Main", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class Main {\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(A.VAR);\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "6", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final int VAR = (int) 7; }" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "7", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + public void testLong() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final long VAR = (long) 8; }" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "p1", "Main", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class Main {\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(A.VAR);\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "8", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final long VAR = (long) 9; }" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "9", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + public void testShort() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final short VAR = (short) 10; }" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "p1", "Main", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class Main {\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(A.VAR);\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "10", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final short VAR = (short) 11; }" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "11", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + + public void testString() throws JavaModelException { + IPath projectPath = env.addProject("Project"); //$NON-NLS-1$ + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final String VAR = \"Hello\"; }" //$NON-NLS-1$ + ); + + env.addClass(projectPath, "p1", "Main", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class Main {\n" + //$NON-NLS-1$ + " public static void main(String args[]) {\n"+ //$NON-NLS-1$ + " System.out.println(A.VAR);\n"+ //$NON-NLS-1$ + " }\n"+ //$NON-NLS-1$ + "}\n" //$NON-NLS-1$ + ); + + fullBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "Hello", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + env.addClass(projectPath, "p1", "A", //$NON-NLS-1$ //$NON-NLS-2$ + "package p1;\n" + //$NON-NLS-1$ + "public class A { public static final String VAR = \"Bye\"; }" //$NON-NLS-1$ + ); + + incrementalBuild(); + expectingNoProblems(); + executeClass(projectPath, "p1.Main", "Bye", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestAttributeBuilderTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestAttributeBuilderTests.java new file mode 100644 index 0000000000..140ddd944b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestAttributeBuilderTests.java @@ -0,0 +1,905 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 Till Brychcy and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Till Brychcy - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import java.util.HashMap; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.tests.util.Util; +import junit.framework.Test; + +public class TestAttributeBuilderTests extends BuilderTests { + static { + // TESTS_NAMES = new String[] { "testIncrementalBuildTestOnlyProject" }; + } + + + public TestAttributeBuilderTests(String name) { + super(name); + } + + public static Test suite() { + return buildTestSuite(TestAttributeBuilderTests.class); + } + + public void testWithProjectAsMainDependency() throws JavaModelException { + IPath project1Path = env.addProject("Project1"); + env.removePackageFragmentRoot(project1Path, ""); + IPath src1 = env.addPackageFragmentRoot(project1Path, "src", null, "bin"); + IPath tests1 = env.addTestPackageFragmentRoot(project1Path, "tests"); + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(src1, "p1", "P1Class", + "package p1;\n" + + "\n" + + "public class P1Class {\n"+ + "}\n" + ); + env.addClass(src1, "p1", "Production1", + "package p1;\n" + + "\n" + + "public class Production1 {\n" + + " void p1() {\n" + + " new P1Class(); // ok\n" + + " new T1Class(); // forbidden\n" + + " }\n" + + "}\n" + + "" + ); + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class {\n"+ + "}\n" + ); + env.addClass(tests1, "p1", "Test1", + "package p1;\n" + + "\n" + + "public class Test1 {\n" + + " void test1() {\n" + + " new P1Class(); // ok\n" + + " new T1Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + IPath project2Path = env.addProject("Project2"); + env.removePackageFragmentRoot(project2Path, ""); + IPath src2 = env.addPackageFragmentRoot(project2Path, "src", null, "bin"); + IPath tests2 = env.addTestPackageFragmentRoot(project2Path, "tests"); + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + env.addClass(src2, "p2", "P2Class", + "package p2;\n" + + "\n" + + "public class P2Class {\n"+ + "}\n" + ); + env.addClass(src2, "p2", "Production2", + "package p2;\n" + + "\n" + + "import p1.P1Class;\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Production2 {\n" + + " void p2() {\n" + + " new P1Class(); // ok\n" + + " new P2Class(); // ok\n" + + " new T1Class(); // forbidden\n" + + " new T2Class(); // forbidden\n" + + " }\n" + + "}\n" + + "" + ); + env.addClass(tests2, "p2", "T2Class", + "package p2;\n" + + "\n" + + "public class T2Class {\n"+ + "}\n" + ); + env.addClass(tests2, "p2", "Test2", + "package p2;\n" + + "\n" + + "import p1.P1Class;\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Test2 {\n" + + " void test2() {\n" + + " new P1Class(); // ok\n" + + " new P2Class(); // ok\n" + + " new T1Class(); // ok\n" + + " new T2Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + fullBuild(); + expectingProblemsFor(env.getWorkspaceRootPath(), "Problem : T1Class cannot be resolved to a type [ resource : range : <82,89> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <144,151> category : <40> severity : <2>]\n" + + "Problem : T2Class cannot be resolved to a type [ resource : range : <174,181> category : <40> severity : <2>]\n" + + "Problem : The import p1.T1Class cannot be resolved [ resource : range : <39,49> category : <30> severity : <2>]"); + } + public void testWithProjectAsTestDependency() throws JavaModelException { + IPath project1Path = env.addProject("Project1"); + env.removePackageFragmentRoot(project1Path, ""); + IPath src1 = env.addPackageFragmentRoot(project1Path, "src", null, "bin"); + IPath tests1 = env.addTestPackageFragmentRoot(project1Path, "tests"); + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(src1, "p1", "P1Class", + "package p1;\n" + + "\n" + + "public class P1Class {\n"+ + "}\n" + ); + env.addClass(src1, "p1", "Production1", + "package p1;\n" + + "\n" + + "public class Production1 {\n" + + " void p1() {\n" + + " new P1Class(); // ok\n" + + " new T1Class(); // forbidden\n" + + " }\n" + + "}\n" + + "" + ); + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class {\n"+ + "}\n" + ); + env.addClass(tests1, "p1", "Test1", + "package p1;\n" + + "\n" + + "public class Test1 {\n" + + " void test1() {\n" + + " new P1Class(); // ok\n" + + " new T1Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + IPath project2Path = env.addProject("Project2"); + env.removePackageFragmentRoot(project2Path, ""); + IPath src2 = env.addPackageFragmentRoot(project2Path, "src", null, "bin"); + IPath tests2 = env.addTestPackageFragmentRoot(project2Path, "tests"); + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredTestProject(project2Path, project1Path); + env.addClass(src2, "p2", "P2Class", + "package p2;\n" + + "\n" + + "public class P2Class {\n"+ + "}\n" + ); + env.addClass(src2, "p2", "Production2", + "package p2;\n" + + "\n" + + "import p1.P1Class;\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Production2 {\n" + + " void p2() {\n" + + " new P1Class(); // forbidden\n" + + " new P2Class(); // ok\n" + + " new T1Class(); // forbidden\n" + + " new T2Class(); // forbidden\n" + + " }\n" + + "}\n" + + "" + ); + env.addClass(tests2, "p2", "T2Class", + "package p2;\n" + + "\n" + + "public class T2Class {\n"+ + "}\n" + ); + env.addClass(tests2, "p2", "Test2", + "package p2;\n" + + "\n" + + "import p1.P1Class;\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Test2 {\n" + + " void test2() {\n" + + " new P1Class(); // ok\n" + + " new P2Class(); // ok\n" + + " new T1Class(); // ok\n" + + " new T2Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + fullBuild(); + expectingProblemsFor(env.getWorkspaceRootPath(), "Problem : P1Class cannot be resolved to a type [ resource : range : <98,105> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <82,89> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <151,158> category : <40> severity : <2>]\n" + + "Problem : T2Class cannot be resolved to a type [ resource : range : <181,188> category : <40> severity : <2>]\n" + + "Problem : The import p1 cannot be resolved [ resource : range : <20,22> category : <30> severity : <2>]\n" + + "Problem : The import p1 cannot be resolved [ resource : range : <39,41> category : <30> severity : <2>]"); + } + public void testWithProjectAsMainDependencyWithoutTestCode() throws JavaModelException { + IPath project1Path = env.addProject("Project1"); + env.removePackageFragmentRoot(project1Path, ""); + IPath src1 = env.addPackageFragmentRoot(project1Path, "src", null, "bin"); + IPath tests1 = env.addTestPackageFragmentRoot(project1Path, "tests"); + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(src1, "p1", "P1Class", + "package p1;\n" + + "\n" + + "public class P1Class {\n"+ + "}\n" + ); + env.addClass(src1, "p1", "Production1", + "package p1;\n" + + "\n" + + "public class Production1 {\n" + + " void p1() {\n" + + " new P1Class(); // ok\n" + + " new T1Class(); // forbidden\n" + + " }\n" + + "}\n" + + "" + ); + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class {\n"+ + "}\n" + ); + env.addClass(tests1, "p1", "Test1", + "package p1;\n" + + "\n" + + "public class Test1 {\n" + + " void test1() {\n" + + " new P1Class(); // ok\n" + + " new T1Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + IPath project2Path = env.addProject("Project2"); + env.removePackageFragmentRoot(project2Path, ""); + IPath src2 = env.addPackageFragmentRoot(project2Path, "src", null, "bin"); + IPath tests2 = env.addTestPackageFragmentRoot(project2Path, "tests"); + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProjectWithoutTestCode(project2Path, project1Path); + env.addClass(src2, "p2", "P2Class", + "package p2;\n" + + "\n" + + "public class P2Class {\n"+ + "}\n" + ); + env.addClass(src2, "p2", "Production2", + "package p2;\n" + + "\n" + + "import p1.P1Class;\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Production2 {\n" + + " void p2() {\n" + + " new P1Class(); // ok\n" + + " new P2Class(); // ok\n" + + " new T1Class(); // forbidden\n" + + " new T2Class(); // forbidden\n" + + " }\n" + + "}\n" + + "" + ); + env.addClass(tests2, "p2", "T2Class", + "package p2;\n" + + "\n" + + "public class T2Class {\n"+ + "}\n" + ); + env.addClass(tests2, "p2", "Test2", + "package p2;\n" + + "\n" + + "import p1.P1Class;\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Test2 {\n" + + " void test2() {\n" + + " new P1Class(); // ok\n" + + " new P2Class(); // ok\n" + + " new T1Class(); // ok\n" + + " new T2Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + fullBuild(); + expectingProblemsFor(env.getWorkspaceRootPath(), "Problem : T1Class cannot be resolved to a type [ resource : range : <82,89> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <144,151> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <141,148> category : <40> severity : <2>]\n" + + "Problem : T2Class cannot be resolved to a type [ resource : range : <174,181> category : <40> severity : <2>]\n" + + "Problem : The import p1.T1Class cannot be resolved [ resource : range : <39,49> category : <30> severity : <2>]\n" + + "Problem : The import p1.T1Class cannot be resolved [ resource : range : <39,49> category : <30> severity : <2>]"); + } + public void testWithProjectAsTestDependencyWithoutTestCode() throws JavaModelException { + IPath project1Path = env.addProject("Project1"); + env.removePackageFragmentRoot(project1Path, ""); + IPath src1 = env.addPackageFragmentRoot(project1Path, "src", null, "bin"); + IPath tests1 = env.addTestPackageFragmentRoot(project1Path, "tests"); + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(src1, "p1", "P1Class", + "package p1;\n" + + "\n" + + "public class P1Class {\n"+ + "}\n" + ); + env.addClass(src1, "p1", "Production1", + "package p1;\n" + + "\n" + + "public class Production1 {\n" + + " void p1() {\n" + + " new P1Class(); // ok\n" + + " new T1Class(); // forbidden\n" + + " }\n" + + "}\n" + + "" + ); + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class {\n"+ + "}\n" + ); + env.addClass(tests1, "p1", "Test1", + "package p1;\n" + + "\n" + + "public class Test1 {\n" + + " void test1() {\n" + + " new P1Class(); // ok\n" + + " new T1Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + IPath project2Path = env.addProject("Project2"); + env.removePackageFragmentRoot(project2Path, ""); + IPath src2 = env.addPackageFragmentRoot(project2Path, "src", null, "bin"); + IPath tests2 = env.addTestPackageFragmentRoot(project2Path, "tests"); + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredTestProjectWithoutTestCode(project2Path, project1Path); + env.addClass(src2, "p2", "P2Class", + "package p2;\n" + + "\n" + + "public class P2Class {\n"+ + "}\n" + ); + env.addClass(src2, "p2", "Production2", + "package p2;\n" + + "\n" + + "import p1.P1Class;\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Production2 {\n" + + " void p2() {\n" + + " new P1Class(); // forbidden\n" + + " new P2Class(); // ok\n" + + " new T1Class(); // forbidden\n" + + " new T2Class(); // forbidden\n" + + " }\n" + + "}\n" + + "" + ); + env.addClass(tests2, "p2", "T2Class", + "package p2;\n" + + "\n" + + "public class T2Class {\n"+ + "}\n" + ); + env.addClass(tests2, "p2", "Test2", + "package p2;\n" + + "\n" + + "import p1.P1Class;\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Test2 {\n" + + " void test2() {\n" + + " new P1Class(); // ok\n" + + " new P2Class(); // ok\n" + + " new T1Class(); // ok\n" + + " new T2Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + fullBuild(); + expectingProblemsFor(env.getWorkspaceRootPath(), "Problem : P1Class cannot be resolved to a type [ resource : range : <98,105> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <82,89> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <151,158> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <141,148> category : <40> severity : <2>]\n" + + "Problem : T2Class cannot be resolved to a type [ resource : range : <181,188> category : <40> severity : <2>]\n" + + "Problem : The import p1 cannot be resolved [ resource : range : <20,22> category : <30> severity : <2>]\n" + + "Problem : The import p1 cannot be resolved [ resource : range : <39,41> category : <30> severity : <2>]\n" + + "Problem : The import p1.T1Class cannot be resolved [ resource : range : <39,49> category : <30> severity : <2>]"); + } + + public void testIncrementalBuildMainChange() throws JavaModelException { + IPath project1Path = env.addProject("Project1"); + env.removePackageFragmentRoot(project1Path, ""); + IPath src1 = env.addPackageFragmentRoot(project1Path, "src", null, "bin"); + IPath tests1 = env.addTestPackageFragmentRoot(project1Path, "tests"); + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(src1, "p1", "P1Class", + "package p1;\n" + + "\n" + + "class P1Class {\n"+ + "}\n" + ); + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class extends P1Class {\n"+ + "}\n" + ); + + IPath project2Path = env.addProject("Project2"); + env.removePackageFragmentRoot(project2Path, ""); + IPath src2 = env.addPackageFragmentRoot(project2Path, "src", null, "bin"); + IPath tests2 = env.addTestPackageFragmentRoot(project2Path, "tests"); + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + env.addClass(src2, "p2", "P2Class", + "package p2;\n" + + "\n" + + "public class P2Class extends p1.P1Class {\n"+ + "}\n" + ); + env.addClass(tests2, "p2", "T2Class", + "package p2;\n" + + "\n" + + "public class T2Class {\n"+ + "}\n" + ); + env.addClass(tests2, "p2", "Test2", + "package p2;\n" + + "\n" + + "public class Test2 {\n" + + " void test2() {\n" + + " new P2Class();\n" + + " }\n" + + "}\n" + + "" + ); + + fullBuild(); + expectingProblemsFor(env.getWorkspaceRootPath(), "Problem : The type p1.P1Class is not visible [ resource : range : <42,52> category : <40> severity : <2>]"); + + env.addClass(src1, "p1", "P1Class", + "package p1;\n" + + "\n" + + "public class P1Class {\n"+ + "}\n" + ); + incrementalBuild(); + expectingNoProblems(); + expectingCompiledClasses(new String[] { "p1.P1Class", "p1.T1Class", "p2.P2Class", "p2.Test2" }); + expectingCompilingOrder(new String[] { "/Project1/src/p1/P1Class.java", "/Project1/tests/p1/T1Class.java", + "/Project2/src/p2/P2Class.java", "/Project2/tests/p2/Test2.java" }); + } + public void testIncrementalBuildTestChange() throws JavaModelException { + IPath project1Path = env.addProject("Project1"); + env.removePackageFragmentRoot(project1Path, ""); + IPath src1 = env.addPackageFragmentRoot(project1Path, "src", null, "bin"); + IPath tests1 = env.addTestPackageFragmentRoot(project1Path, "tests"); + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(src1, "p1", "P1Class", + "package p1;\n" + + "\n" + + "public class P1Class {\n"+ + "}\n" + ); + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class {\n"+ + "}\n" + ); + env.addClass(tests1, "p1", "Test1", + "package p1;\n" + + "\n" + + "public class Test1 {\n" + + " void test1() {\n" + + " new P1Class();" + + " new T1Class();" + + " }\n" + + "}\n" + + "" + ); + + IPath project2Path = env.addProject("Project2"); + env.removePackageFragmentRoot(project2Path, ""); + IPath src2 = env.addPackageFragmentRoot(project2Path, "src", null, "bin"); + IPath tests2 = env.addTestPackageFragmentRoot(project2Path, "tests"); + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + env.addClass(src2, "p2", "P2Class", + "package p2;\n" + + "\n" + + "public class P2Class extends p1.P1Class {\n"+ + "}\n" + ); + env.addClass(tests2, "p2", "T2Class", + "package p2;\n" + + "\n" + + "public class T2Class extends p1.T1Class {\n"+ + "}\n" + ); + env.addClass(tests2, "p2", "Test2", + "package p2;\n" + + "\n" + + "public class Test2 extends p2.T2Class {\n" + + " void test2(T2Class t) {\n" + + " }\n" + + "}\n" + + "" + ); + + fullBuild(); + expectingNoProblems(); + + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class extends P1Class {\n"+ + "}\n" + ); + incrementalBuild(); + expectingNoProblems(); + expectingCompiledClasses(new String[] { "p1.T1Class", "p1.Test1", "p2.T2Class", "p2.Test2" }); + expectingCompilingOrder(new String[] { "/Project1/tests/p1/T1Class.java", "/Project1/tests/p1/Test1.java", + "/Project2/tests/p2/T2Class.java", "/Project2/tests/p2/Test2.java" }); + } + + public void testIncrementalBuildTestOnlyProject() throws JavaModelException { + IPath project1Path = env.addProject("Project1"); + env.removePackageFragmentRoot(project1Path, ""); + IPath tests1 = env.addTestPackageFragmentRoot(project1Path, "tests"); + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class {\n"+ + "}\n" + ); + env.addClass(tests1, "p1", "Test1", + "package p1;\n" + + "\n" + + "public class Test1 {\n" + + " void test1() {\n" + + " new T1Class();" + + " }\n" + + "}\n" + + "" + ); + + fullBuild(); + expectingNoProblems(); + + IPath test1 = env.addClass(tests1, "p1", "Test1", + "package p1;\n" + + "\n" + + "public class Test1 {\n" + + " void test1() {\n" + + " new X1Class();" + + " }\n" + + "}\n" + + "" + ); + incrementalBuild(); + expectingProblemsFor( + test1, + "Problem : X1Class cannot be resolved to a type [ resource : range : <56,63> category : <40> severity : <2>]" + ); + expectingCompiledClasses(new String[] { "p1.Test1" }); + expectingCompilingOrder(new String[] { "/Project1/tests/p1/Test1.java"}); + } + + public void testClasspathEntryTestAttributeChanges() throws JavaModelException { + IPath project1Path = env.addProject("Project1"); + env.removePackageFragmentRoot(project1Path, ""); + IPath src1 = env.addPackageFragmentRoot(project1Path, "src", null, "bin"); + IPath tests1 = env.addTestPackageFragmentRoot(project1Path, "tests"); + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(src1, "p1", "P1Class", + "package p1;\n" + + "\n" + + "public class P1Class {\n"+ + "}\n" + ); + env.addClass(src1, "p1", "P1Unrelated", + "package p1;\n" + + "\n" + + "public class P1Unrelated {\n"+ + "}\n" + ); + env.addClass(src1, "p1", "Production1", + "package p1;\n" + + "\n" + + "public class Production1 {\n" + + " void p1() {\n" + + " new P1Class(); // ok\n" + + " new T1Class(); // forbidden\n" + + " }\n" + + "}\n" + + "" + ); + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class {\n"+ + "}\n" + ); + env.addClass(tests1, "p1", "Test1", + "package p1;\n" + + "\n" + + "public class Test1 {\n" + + " void test1() {\n" + + " new P1Class(); // ok\n" + + " new T1Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + IPath project2Path = env.addProject("Project2"); + env.removePackageFragmentRoot(project2Path, ""); + IPath src2 = env.addPackageFragmentRoot(project2Path, "src", null, "bin"); + IPath tests2 = env.addTestPackageFragmentRoot(project2Path, "tests"); + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, project1Path); + env.addClass(src2, "p2", "P2Class", + "package p2;\n" + + "\n" + + "public class P2Class {\n"+ + "}\n" + ); + env.addClass(src1, "p2", "P2Unrelated", + "package p2;\n" + + "\n" + + "public class P2Unrelated {\n"+ + "}\n" + ); + env.addClass(src2, "p2", "Production2", + "package p2;\n" + + "\n" + + "import p1.P1Class;\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Production2 {\n" + + " void p2() {\n" + + " new P1Class(); // ok\n" + + " new P2Class(); // ok\n" + + " new T1Class(); // forbidden\n" + + " new T2Class(); // forbidden\n" + + " }\n" + + "}\n" + + "" + ); + env.addClass(tests2, "p2", "T2Class", + "package p2;\n" + + "\n" + + "public class T2Class {\n"+ + "}\n" + ); + env.addClass(tests2, "p2", "Test2", + "package p2;\n" + + "\n" + + "import p1.P1Class;\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Test2 {\n" + + " void test2() {\n" + + " new P1Class(); // ok\n" + + " new P2Class(); // ok\n" + + " new T1Class(); // ok\n" + + " new T2Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + fullBuild(); + expectingProblemsFor(env.getWorkspaceRootPath(), "Problem : T1Class cannot be resolved to a type [ resource : range : <82,89> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <144,151> category : <40> severity : <2>]\n" + + "Problem : T2Class cannot be resolved to a type [ resource : range : <174,181> category : <40> severity : <2>]\n" + + "Problem : The import p1.T1Class cannot be resolved [ resource : range : <39,49> category : <30> severity : <2>]"); + + env.changePackageFragmentRootTestAttribute(project2Path, tests2, false); + incrementalBuild(); + expectingProblemsFor(env.getWorkspaceRootPath(), "Problem : T1Class cannot be resolved to a type [ resource : range : <82,89> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <144,151> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <141,148> category : <40> severity : <2>]\n" + + "Problem : The import p1.T1Class cannot be resolved [ resource : range : <39,49> category : <30> severity : <2>]\n" + + "Problem : The import p1.T1Class cannot be resolved [ resource : range : <39,49> category : <30> severity : <2>]"); + expectingCompiledClasses(new String[]{"p2.P2Class","p2.Production2","p2.T2Class","p2.Test2"}); + + env.changePackageFragmentRootTestAttribute(project1Path, tests1, false); + incrementalBuild(); + expectingNoProblems(); + expectingCompiledClasses(new String[]{"p1.P1Class", "p1.P1Unrelated","p1.Production1","p1.T1Class","p1.Test1","p2.P2Class","p2.P2Unrelated","p2.Production2","p2.T2Class","p2.Test2"}); + + env.changePackageFragmentRootTestAttribute(project2Path, tests2, true); + incrementalBuild(); + expectingProblemsFor(env.getWorkspaceRootPath(), "Problem : T2Class cannot be resolved to a type [ resource : range : <174,181> category : <40> severity : <2>]"); + expectingCompiledClasses(new String[]{"p2.P2Class","p2.Production2","p2.T2Class","p2.Test2"}); + + env.changePackageFragmentRootTestAttribute(project1Path, tests1, true); + incrementalBuild(); + expectingProblemsFor(env.getWorkspaceRootPath(), "Problem : T1Class cannot be resolved to a type [ resource : range : <82,89> category : <40> severity : <2>]\n" + + "Problem : T1Class cannot be resolved to a type [ resource : range : <144,151> category : <40> severity : <2>]\n" + + "Problem : T2Class cannot be resolved to a type [ resource : range : <174,181> category : <40> severity : <2>]\n" + + "Problem : The import p1.T1Class cannot be resolved [ resource : range : <39,49> category : <30> severity : <2>]"); + expectingCompiledClasses(new String[]{"p1.P1Class", "p1.P1Unrelated","p1.Production1","p1.T1Class","p1.Test1","p2.P2Class","p2.P2Unrelated","p2.Production2","p2.T2Class","p2.Test2"}); + + env.changePackageFragmentRootTestAttribute(project2Path, tests2, false); + env.changePackageFragmentRootTestAttribute(project1Path, tests1, false); + incrementalBuild(); + expectingNoProblems(); + expectingCompiledClasses(new String[]{"p1.P1Class", "p1.P1Unrelated","p1.Production1","p1.T1Class","p1.Test1","p2.P2Class","p2.P2Unrelated","p2.Production2","p2.T2Class","p2.Test2"}); + } + + public void testExternalTestJarChanged() throws CoreException, java.io.IOException { + IPath projectPath = env.addProject("Project"); + env.removePackageFragmentRoot(projectPath, ""); + env.addExternalJars(projectPath, Util.getJavaClassLibs()); + + IPath tests = env.addTestPackageFragmentRoot(projectPath, "tests"); + IPath classTest = env.addClass(tests, "p", "X", + "package p;\n"+ + "public class X {\n" + + " void foo() {\n" + + " new q.Y().bar();\n" + + " }\n" + + "}" + ); + String externalJar = Util.getOutputDirectory() + java.io.File.separator + "test.jar"; + Util.createJar( + new String[] { + "q/Y.java", + "package q;\n" + + "public class Y {\n" + + "}" + }, + new HashMap<>(), + externalJar + ); + fullBuild(); + expectingProblemsFor( + classTest, + "Problem : q cannot be resolved to a type [ resource : range : <51,52> category : <40> severity : <2>]" + ); + env.addExternalTestJar(projectPath, externalJar, false); + + incrementalBuild(); + expectingProblemsFor( + classTest, + "Problem : The method bar() is undefined for the type Y [ resource : range : <57,60> category : <50> severity : <2>]" + ); + + Util.createJar( + new String[] { + "q/Y.java", + "package q;\n" + + "public class Y {\n" + + " public void bar() {\n" + + " }\n" + + "}" + }, + new HashMap<>(), + externalJar + ); + + env.getProject(projectPath).touch(null); + + incrementalBuild(); + expectingNoProblems(); + } + + public void testBug536868() throws JavaModelException { + IPath project1Path = env.addProject("Project1"); + env.removePackageFragmentRoot(project1Path, ""); + IPath tests1 = env.addTestPackageFragmentRoot(project1Path, "tests"); + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class {\n"+ + "}\n" + ); + + // project X just reexports Project1 without test code + IPath projectXPath = env.addProject("ProjectX"); + env.removePackageFragmentRoot(projectXPath, ""); + env.addRequiredProjectWithoutTestCode(projectXPath, project1Path, /* isExported */ true); + + + IPath project2Path = env.addProject("Project2"); + env.removePackageFragmentRoot(project2Path, ""); + IPath tests2 = env.addTestPackageFragmentRoot(project2Path, "tests"); + env.addExternalJars(project2Path, Util.getJavaClassLibs()); + env.addRequiredProject(project2Path, projectXPath); + env.addRequiredTestProject(project2Path, project1Path); + env.addClass(tests2, "p2", "Test2", + "package p2;\n" + + "\n" + + "import p1.T1Class;\n" + + "\n" + + "public class Test2 {\n" + + " void test2() {\n" + + " new T1Class(); // ok\n" + + " }\n" + + "}\n" + + "" + ); + + fullBuild(); + expectingNoProblems(); + } + public void testBug559965() throws JavaModelException { + // Bug 559965 - No recompilation when deleting java file from test-source-folder + IPath project1Path = env.addProject("Project1"); + env.removePackageFragmentRoot(project1Path, ""); + IPath src1 = env.addPackageFragmentRoot(project1Path, "src", null, "bin"); + assertNotNull(src1); + + IPath tests1 = env.addTestPackageFragmentRoot(project1Path, "tests"); + env.addExternalJars(project1Path, Util.getJavaClassLibs()); + + env.addClass(tests1, "p1", "T1Class", + "package p1;\n" + + "\n" + + "public class T1Class {\n"+ + "}\n" + ); + env.addClass(tests1, "p1", "Test1", + "package p1;\n" + + "\n" + + "public class Test1 {\n" + + " void test1() {\n" + + " new T1Class();" + + " }\n" + + "}\n" + + "" + ); + + fullBuild(); + expectingNoProblems(); + + env.removeClass(tests1, "p1/T1Class"); + incrementalBuild(); + + expectingProblemsFor(env.getWorkspaceRootPath(), "Problem : T1Class cannot be resolved to a type [ resource : range : <56,63> category : <40> severity : <2>]"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestBuilderParticipant.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestBuilderParticipant.java new file mode 100644 index 0000000000..92e5088e9e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestBuilderParticipant.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.compiler.*; + +public class TestBuilderParticipant extends CompilationParticipant { + + public static CompilationParticipant PARTICIPANT; + +public int aboutToBuild(IJavaProject project) { + return PARTICIPANT.aboutToBuild(project); +} + +public void buildFinished(IJavaProject project) { + PARTICIPANT.buildFinished(project); +} + +public void buildStarting(BuildContext[] files, boolean isBatchBuild) { + PARTICIPANT.buildStarting(files, isBatchBuild); +} + +public void cleanStarting(IJavaProject project) { + PARTICIPANT.cleanStarting(project); +} + +public boolean isActive(IJavaProject project) { + return PARTICIPANT != null; +} + +public boolean isAnnotationProcessor() { + return PARTICIPANT != null && PARTICIPANT.isAnnotationProcessor(); +} + +public void processAnnotations(BuildContext[] files) { + PARTICIPANT.processAnnotations(files); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java new file mode 100644 index 0000000000..4108f26ed0 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/src/org/eclipse/jdt/core/tests/builder/TestingEnvironment.java @@ -0,0 +1,1240 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.builder; + +import org.eclipse.core.resources.*; +import org.eclipse.core.runtime.*; +import org.eclipse.core.runtime.jobs.Job; + +import org.eclipse.jdt.core.*; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.Util; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.core.ClasspathEntry; +import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.core.JavaProject; + +import java.io.*; +import java.util.*; + +public class TestingEnvironment { + + private boolean isOpen = false; + + private IWorkspace workspace = null; + private Hashtable projects = null; + + private void addBuilderSpecs(String projectName) { + try { + IProject project = getProject(projectName); + IProjectDescription description = project.getDescription(); + description.setNatureIds(new String[] { JavaCore.NATURE_ID }); + project.setDescription(description, null); + } catch (CoreException e) { + handleCoreException(e); + } + } + + /** Adds a binary class with the given contents to the + * given package in the workspace. The package is created + * if necessary. If a class with the same name already + * exists, it is replaced. A workspace must be open, + * and the given class name must not end with ".class". + * Returns the path of the added class. + */ + public IPath addBinaryClass(IPath packagePath, String className, byte[] contents) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IPath classPath = packagePath.append(className + ".class"); //$NON-NLS-1$ + createFile(classPath, contents); + return classPath; + } + + /** Adds a binary class with the given contents to the + * given package in the workspace. The package is created + * if necessary. If a class with the same name already + * exists, it is replaced. A workspace must be open, + * and the given class name must not end with ".class". + * Returns the path of the added class. + */ + public IPath addBinaryClass(IPath packageFragmentRootPath, String packageName, String className, byte[] contents) { + /* make sure the package exists */ + if(packageName != null && packageName.length() >0){ + IPath packagePath = addPackage(packageFragmentRootPath, packageName); + + return addBinaryClass(packagePath, className, contents); + } + return addBinaryClass(packageFragmentRootPath, className, contents); + + } + + /** Adds a class with the given contents to the given + * package in the workspace. The package is created + * if necessary. If a class with the same name already + * exists, it is replaced. A workspace must be open, + * and the given class name must not end with ".java". + * Returns the path of the added class. + */ + public IPath addClass(IPath packagePath, String className, String contents) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IPath classPath = packagePath.append(className + ".java"); //$NON-NLS-1$ + try { + createFile(classPath, contents.getBytes("UTF8")); //$NON-NLS-1$ + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + checkAssertion("e1", false); //$NON-NLS-1$ + } + return classPath; + } + + /** Adds a class with the given contents to the given + * package in the workspace. The package is created + * if necessary. If a class with the same name already + * exists, it is replaced. A workspace must be open, + * and the given class name must not end with ".java". + * Returns the path of the added class. + */ + public IPath addClass(IPath packageFragmentRootPath, String packageName, String className, String contents) { + /* make sure the package exists */ + if(packageName != null && packageName.length() >0){ + IPath packagePath = addPackage(packageFragmentRootPath, packageName); + + return addClass(packagePath, className, contents); + } + return addClass(packageFragmentRootPath, className, contents); + } + +/** + * Add a class folder to the classpath of a project. + */ +public void addClassFolder(IPath projectPath, IPath classFolderPath, boolean isExported) throws JavaModelException { + addEntry(projectPath, JavaCore.newLibraryEntry(classFolderPath, null, null, isExported)); +} + + /** Adds a package to the given package fragment root + * in the workspace. The package fragment root is created + * if necessary. If a package with the same name already + * exists, it is not replaced. A workspace must be open. + * Returns the path of the added package. + */ + public IPath addPackage(IPath packageFragmentRootPath, String packageName) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IPath path = + packageFragmentRootPath.append(packageName.replace('.', IPath.SEPARATOR)); + createFolder(path); + return path; + } + + public IPath addPackageFragmentRoot(IPath projectPath, String sourceFolderName) throws JavaModelException { + return addPackageFragmentRoot(projectPath, sourceFolderName, null, null); + } + + public IPath addTestPackageFragmentRoot(IPath projectPath, String sourceFolderName) throws JavaModelException { + return addPackageFragmentRoot(projectPath, sourceFolderName, null, null, "bin-" + sourceFolderName, true); //$NON-NLS-1$ + } + + /** Adds a package fragment root to the workspace. If + * a package fragment root with the same name already + * exists, it is not replaced. A workspace must be open. + * Returns the path of the added package fragment root. + */ + public IPath addPackageFragmentRoot(IPath projectPath, String sourceFolderName, IPath[] exclusionPatterns, String specificOutputLocation) throws JavaModelException { + return addPackageFragmentRoot(projectPath, sourceFolderName, null, exclusionPatterns, specificOutputLocation); + } + + public IPath addPackageFragmentRoot(IPath projectPath, String sourceFolderName, IPath[] inclusionPatterns, IPath[] exclusionPatterns, String specificOutputLocation) throws JavaModelException { + return addPackageFragmentRoot(projectPath, sourceFolderName, inclusionPatterns, exclusionPatterns, specificOutputLocation, false); + } + /** Adds a package fragment root to the workspace. If + * a package fragment root with the same name already + * exists, it is not replaced. A workspace must be open. + * Returns the path of the added package fragment root. + */ + public IPath addPackageFragmentRoot(IPath projectPath, String sourceFolderName, IPath[] inclusionPatterns, IPath[] exclusionPatterns, String specificOutputLocation, boolean isTest) throws JavaModelException { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IPath path = getPackageFragmentRootPath(projectPath, sourceFolderName); + createFolder(path); + IPath outputPath = null; + if (specificOutputLocation != null) { + outputPath = getPackageFragmentRootPath(projectPath, specificOutputLocation); + createFolder(outputPath); + } + IClasspathEntry entry = JavaCore.newSourceEntry( + path, + inclusionPatterns == null ? new Path[0] : inclusionPatterns, + exclusionPatterns == null ? new Path[0] : exclusionPatterns, + outputPath, + isTest ? new IClasspathAttribute[] {JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true")} : ClasspathEntry.NO_EXTRA_ATTRIBUTES); + addEntry(projectPath, entry); + return path; + } + + public void addProject(IProject project){ + this.projects.put(project.getName(), project); + } + + public IPath addProject(String projectName){ + return addProject(projectName, "1.4"); + } + + public IPath addProject(String projectName, String compliance){ + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IProject project = createProject(projectName); + int requiredComplianceFlag = 0; + String compilerVersion = null; + if ("1.5".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_1_5; + compilerVersion = CompilerOptions.VERSION_1_5; + } + else if ("1.6".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_1_6; + compilerVersion = CompilerOptions.VERSION_1_6; + } + else if ("1.7".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_1_7; + compilerVersion = CompilerOptions.VERSION_1_7; + } + else if ("1.8".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_1_8; + compilerVersion = CompilerOptions.VERSION_1_8; + } + else if ("9".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_9; + compilerVersion = CompilerOptions.VERSION_9; + } + else if ("10".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_10; + compilerVersion = CompilerOptions.VERSION_10; + } + else if ("11".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_11; + compilerVersion = CompilerOptions.VERSION_11; + } + else if ("12".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_12; + compilerVersion = CompilerOptions.VERSION_12; + } else if ("13".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_13; + compilerVersion = CompilerOptions.VERSION_13; + } else if ("14".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_14; + compilerVersion = CompilerOptions.VERSION_14; + } else if ("15".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_15; + compilerVersion = CompilerOptions.VERSION_15; + } else if ("16".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_16; + compilerVersion = CompilerOptions.VERSION_16; + } else if ("17".equals(compliance)) { + requiredComplianceFlag = AbstractCompilerTest.F_17; + compilerVersion = CompilerOptions.VERSION_17; + } else if (!"1.4".equals(compliance) && !"1.3".equals(compliance)) { + throw new UnsupportedOperationException("Test framework doesn't support compliance level: " + compliance); + } + if (requiredComplianceFlag != 0) { + if (CompilerOptions.versionToJdkLevel(System.getProperty("java.specification.version")) < requiredComplianceFlag) + throw new RuntimeException("This test requires a " + compliance + " JRE"); + IJavaProject javaProject = JavaCore.create(project); + Map options = new HashMap<>(); + options.put(CompilerOptions.OPTION_Compliance, compilerVersion); + options.put(CompilerOptions.OPTION_Source, compilerVersion); + options.put(CompilerOptions.OPTION_TargetPlatform, compilerVersion); + javaProject.setOptions(options); + } + return project.getFullPath(); + } + + public void addRequiredProject(IPath projectPath, IPath requiredProjectPath) throws JavaModelException { + addRequiredProject(projectPath, requiredProjectPath, new IPath[]{}/*include all*/, new IPath[]{}/*exclude none*/, false); + } + public void addRequiredTestProject(IPath projectPath, IPath requiredProjectPath) throws JavaModelException { + checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$ + IAccessRule[] accessRules = ClasspathEntry.getAccessRules(new IPath[]{}, new IPath[]{}); + addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, accessRules, true, new IClasspathAttribute[] {JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true")}, false)); + } + public void addRequiredProjectWithoutTestCode(IPath projectPath, IPath requiredProjectPath) throws JavaModelException { + addRequiredProjectWithoutTestCode(projectPath, requiredProjectPath, false); + } + public void addRequiredProjectWithoutTestCode(IPath projectPath, IPath requiredProjectPath, boolean isExported) throws JavaModelException { + checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$ + IAccessRule[] accessRules = ClasspathEntry.getAccessRules(new IPath[]{}, new IPath[]{}); + addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, accessRules, true, new IClasspathAttribute[] {JavaCore.newClasspathAttribute(IClasspathAttribute.WITHOUT_TEST_CODE, "true")}, isExported)); + } + + public void addRequiredTestProjectWithoutTestCode(IPath projectPath, IPath requiredProjectPath) throws JavaModelException { + checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$ + IAccessRule[] accessRules = ClasspathEntry.getAccessRules(new IPath[]{}, new IPath[]{}); + addEntry(projectPath, + JavaCore.newProjectEntry(requiredProjectPath, accessRules, true, + new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true"), + JavaCore.newClasspathAttribute(IClasspathAttribute.WITHOUT_TEST_CODE, "true") }, + false)); + } + + /** Adds a project to the classpath of a project. + */ + public void addRequiredProject(IPath projectPath, IPath requiredProjectPath, IPath[] accessibleFiles, IPath[] nonAccessibleFiles, boolean isExported) throws JavaModelException { + checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$ + IAccessRule[] accessRules = ClasspathEntry.getAccessRules(accessibleFiles, nonAccessibleFiles); + addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, accessRules, true, new IClasspathAttribute[0], isExported)); + } + + public void addRequiredProject(IPath projectPath, IPath requiredProjectPath, IPath rule, int ruleKind) throws JavaModelException { + checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$ + IAccessRule accessRule = JavaCore.newAccessRule(rule, ruleKind); + addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, new IAccessRule[] {accessRule}, true, new IClasspathAttribute[0], false)); + } + + public void addRequiredProject(IPath projectPath, IPath requiredProjectPath, boolean isOptional) throws JavaModelException { + checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$ + IClasspathAttribute[] attributes = isOptional ? new IClasspathAttribute[] {JavaCore.newClasspathAttribute(IClasspathAttribute.OPTIONAL, "true")} : new IClasspathAttribute[0]; + addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, null, true, attributes, false)); + } + + public void addExternalFolders(IPath projectPath, String[] folders) throws JavaModelException { + addExternalFolders(projectPath, folders, false); + } + + public void addExternalFolders(IPath projectPath, String[] folders, boolean isExported) throws JavaModelException { + for (int i = 0, max = folders.length; i < max; i++) { + String folder = folders[i]; + checkAssertion("folder name must not end with .zip or .jar", !folder.endsWith(".zip") && !folder.endsWith(".jar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + addEntry(projectPath, JavaCore.newLibraryEntry(new Path(folder), null, null, isExported)); + } + } + + public void addExternalJars(IPath projectPath, String[] jars) throws JavaModelException { + addExternalJars(projectPath, jars, false); + } + + public void addExternalJar(IPath projectPath, String jar) throws JavaModelException { + addExternalJar(projectPath, jar, false); + } + + /** Adds an external jar to the classpath of a project. + */ + public void addExternalJars(IPath projectPath, String[] jars, boolean isExported) throws JavaModelException { + for (int i = 0, max = jars.length; i < max; i++) { + String jar = jars[i]; + addEntry(projectPath, JavaCore.newLibraryEntry(new Path(jar), null, null, isExported)); + } + } + + /** Adds an external jar to the classpath of a project. + */ + public void addExternalJar(IPath projectPath, String jar, boolean isExported) throws JavaModelException { + addEntry(projectPath, JavaCore.newLibraryEntry(new Path(jar), null, null, isExported)); + } + public void addExternalTestJar(IPath projectPath, String jar, boolean isExported) throws JavaModelException { + addEntry(projectPath, JavaCore.newLibraryEntry( + new Path(jar), + null, + null, + ClasspathEntry.NO_ACCESS_RULES, + new IClasspathAttribute[] {JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true")}, + isExported)); + } + +public void addLibrary(IPath projectPath, IPath libraryPath, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath) + throws JavaModelException { + addEntry(projectPath, + JavaCore.newLibraryEntry(libraryPath, sourceAttachmentPath, sourceAttachmentRootPath)); +} + public void addEntry(IPath projectPath, IClasspathEntry entryPath) throws JavaModelException { + IClasspathEntry[] classpath = getRawClasspath(projectPath); + IClasspathEntry[] newClaspath = new IClasspathEntry[classpath.length + 1]; + System.arraycopy(classpath, 0, newClaspath, 0, classpath.length); + newClaspath[classpath.length] = entryPath; + setClasspath(projectPath, newClaspath); + } + + /** Adds a file. + */ + public IPath addFile(IPath root, String fileName, String contents){ + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IPath filePath = root.append(fileName); + try { + createFile(filePath, contents.getBytes("UTF8")); //$NON-NLS-1$ + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + checkAssertion("e1", false); //$NON-NLS-1$ + } + return filePath; + } + + /** Adds a folder. + */ + public IPath addFolder(IPath root, String folderName){ + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IPath folderPath = root.append(folderName); + createFolder(folderPath); + return folderPath; + } + + public IPath addInternalJar(IPath projectPath, String zipName, byte[] contents) throws JavaModelException { + return addInternalJar(projectPath, zipName, contents, false); + } + + /** Adds a jar with the given contents to the the workspace. + * If a jar with the same name already exists, it is + * replaced. A workspace must be open. Returns the path of + * the added jar. + */ + public IPath addInternalJar(IPath projectPath, String zipName, byte[] contents, boolean isExported) throws JavaModelException { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IPath path = projectPath.append(zipName); + + /* remove any existing zip from the java model */ + removeInternalJar(projectPath, zipName); + + createFile(path, contents); + addEntry(projectPath, JavaCore.newLibraryEntry(path, null, null, isExported)); + return path; + } + + private void checkAssertion(String message, boolean b) { + Assert.isTrue(b, message); + } + +public void cleanBuild() { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + try { + getWorkspace().build(IncrementalProjectBuilder.CLEAN_BUILD, null); + } catch (CoreException e) { + handle(e); + } +} + +public void cleanBuild(String projectName) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + try { + getProject(projectName).build(IncrementalProjectBuilder.CLEAN_BUILD, null); + } catch (CoreException e) { + handle(e); + } +} + + /** Closes the testing environment and frees up any + * resources. Once the testing environment is closed, + * it shouldn't be used any more. + */ + public void close() { + try { + if (this.projects != null) { + Enumeration projectNames = this.projects.keys(); + while (projectNames.hasMoreElements()) { + String projectName = projectNames.nextElement(); + getJavaProject(projectName).getJavaModel().close(); + } + } + closeWorkspace(); + } catch (JavaModelException e) { + e.printStackTrace(); + } catch (RuntimeException e) { + e.printStackTrace(); + } + } + + /** Close a project from the workspace. + */ + public void closeProject(IPath projectPath){ + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + try { + getJavaProject(projectPath).getProject().close(null); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + private void closeWorkspace() { + this.isOpen = false; + } + + public IFile createFile(IPath path, byte[] contents) { + ByteArrayInputStream is = null; + try { + IFile file = this.workspace.getRoot().getFile(path); + + is = new ByteArrayInputStream(contents); + if (file.exists()) { + file.setContents(is, true, false, null); + } else { + file.create(is, true, null); + } + return file; + } catch (CoreException e) { + handle(e); + } finally { + if (is != null) { + try { + is.close(); + } catch (IOException e) { + // ignore + } + } + } + return null; + } + + public IFolder createFolder(IPath path) { + checkAssertion("root", !path.isRoot()); //$NON-NLS-1$ + + /* don't create folders for projects */ + if (path.segmentCount() <= 1) { + return null; + } + + IFolder folder = this.workspace.getRoot().getFolder(path); + if (!folder.exists()) { + /* create the parent folder if necessary */ + createFolder(path.removeLastSegments(1)); + + try { + folder.create(true, true, null); + } catch (CoreException e) { + handle(e); + } + } + return folder; + } + + private IProject createProject(String projectName) { + final IProject project = this.workspace.getRoot().getProject(projectName); + try { + IWorkspaceRunnable create = new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + project.create(null, null); + project.open(null); + } + }; + this.workspace.run(create, null); + this.projects.put(projectName, project); + addBuilderSpecs(projectName); + } catch (CoreException e) { + handle(e); + } + return project; + } + + /** + * Safely delete the given resource. + */ + void deleteResource(IResource resource) { + int retryCount = 0; // wait 1 minute at most + IStatus status = null; + while (++retryCount <= 6) { + status = Util.delete(resource); + if (status.isOK()) { + return; + } + System.gc(); + } + handleCoreException(new CoreException(status)); + } + + /** Batch builds the workspace. A workspace must be + * open. + */ + public void fullBuild() { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + try { + getWorkspace().build(IncrementalProjectBuilder.FULL_BUILD, null); + } catch (CoreException e) { + handle(e); + } + } + + /** + * Batch builds a project. A workspace must be open. + */ + public void fullBuild(IPath projectPath) { + fullBuild(projectPath.lastSegment()); + } + + /** + * Batch builds a project. A workspace must be open. + */ + public void fullBuild(String projectName) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + try { + getProject(projectName).build(IncrementalProjectBuilder.FULL_BUILD, null); + } catch (CoreException e) { + handle(e); + } + } + + /** + * Returns the expanded class path. + */ + public IClasspathEntry[] getClasspath(IPath projectPath) { + try { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + JavaProject javaProject = (JavaProject) JavaCore.create(getProject(projectPath)); + return javaProject.getExpandedClasspath(); +// IPath[] packageFragmentRootsPath = new IPath[entries.length]; +// for (int i = 0; i < entries.length; ++i) +// packageFragmentRootsPath[i] = entries[i].getPath(); +// return packageFragmentRootsPath; + } catch (JavaModelException e) { + e.printStackTrace(); + checkAssertion("JavaModelException", false); //$NON-NLS-1$ + return null; // not reachable + } + } + + /** + * Returns the raw class path. + */ + public IClasspathEntry[] getRawClasspath(IPath projectPath) { + try { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + JavaProject javaProject = (JavaProject) JavaCore.create(getProject(projectPath)); + return javaProject.getRawClasspath(); + } catch (JavaModelException e) { + e.printStackTrace(); + checkAssertion("JavaModelException", false); //$NON-NLS-1$ + return null; // not reachable + } + } + + /** + * Returns the Java Model element for the project. + */ + public IJavaProject getJavaProject(IPath projectPath) { + IJavaProject javaProject = JavaCore.create(getProject(projectPath)); + Assert.isNotNull(javaProject); + return javaProject; + } + + /** + * Returns the Java Model element for the project. + */ + public IJavaProject getJavaProject(String projectName) { + IJavaProject javaProject = JavaCore.create(getProject(projectName)); + Assert.isNotNull(javaProject); + return javaProject; + } + + /** + * Return output location for a project. + */ + public IPath getOutputLocation(IPath projectPath){ + try { + IJavaProject javaProject = JavaCore.create(getProject(projectPath)); + return javaProject.getOutputLocation(); + } catch(CoreException e){ + // ignore + } + return null; + } + + /** + * Return all problems with workspace. + */ + public Problem[] getProblems(){ + return getProblemsFor(getWorkspaceRootPath()); + } + + /** + * Return all problems with the specified element. + */ + public Problem[] getProblemsFor(IPath path){ + return getProblemsFor(path, null); + } + /** + * Return all problems with the specified element. + */ + public Problem[] getProblemsFor(IPath path, String additionalMarkerType){ + IResource resource; + if(path.equals(getWorkspaceRootPath())){ + resource = getWorkspace().getRoot(); + } else { + IProject p = getProject(path); + if(p != null && path.equals(p.getFullPath())) { + resource = getProject(path.lastSegment()); + } else if(path.getFileExtension() == null) { + resource = getWorkspace().getRoot().getFolder(path); + } else { + resource = getWorkspace().getRoot().getFile(path); + } + } + try { + ArrayList problems = new ArrayList<>(); + IMarker[] markers = resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); + for (int i = 0; i < markers.length; i++) + problems.add(new Problem(markers[i])); + + markers = resource.findMarkers(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE); + for (int i = 0; i < markers.length; i++) + problems.add(new Problem(markers[i])); + + markers = resource.findMarkers(IJavaModelMarker.TASK_MARKER, true, IResource.DEPTH_INFINITE); + for (int i = 0; i < markers.length; i++) + problems.add(new Problem(markers[i])); + + if (additionalMarkerType != null) { + markers = resource.findMarkers(additionalMarkerType, true, IResource.DEPTH_INFINITE); + for (int i = 0; i < markers.length; i++) + problems.add(new Problem(markers[i])); + } + + Problem[] result = new Problem[problems.size()]; + problems.toArray(result); + Arrays.sort(result, new Comparator() { + public int compare(Problem o1, Problem o2) { + return o1.toString().compareTo(o2.toString()); + } + }); + return result; + } catch(CoreException e){ + // ignore + } + return new Problem[0]; + } + + + /** + * Return all problems with the specified element. + */ + public IMarker[] getTaskMarkersFor(IPath path){ + IResource resource = null; + if(path.equals(getWorkspaceRootPath())){ + resource = getWorkspace().getRoot(); + } else { + IProject p = getProject(path); + if(p != null && path.equals(p.getFullPath())) { + resource = getProject(path.lastSegment()); + } else if(path.getFileExtension() == null) { + resource = getWorkspace().getRoot().getFolder(path); + } else { + resource = getWorkspace().getRoot().getFile(path); + } + } + try { + if (resource != null) { + final IMarker[] markers = resource.findMarkers(IJavaModelMarker.TASK_MARKER, true, IResource.DEPTH_INFINITE); + if (markers.length > 1) { + Arrays.sort(markers, new Comparator() { + public int compare(IMarker o1, IMarker o2) { + IMarker marker1 = o1; + IMarker marker2 = o2; + try { + final int start1 = ((Integer) marker1.getAttribute(IMarker.CHAR_START)).intValue(); + final int start2 = ((Integer) marker2.getAttribute(IMarker.CHAR_START)).intValue(); + return start1 - start2; + } catch (CoreException e) { + return 0; + } + } + }); + } + return markers; + } + } catch(CoreException e){ + // ignore + } + return new IMarker[0]; + } + + /** Return the path of the package + * with the given name. A workspace must be open, and + * the package must exist. + */ + public IPath getPackagePath(IPath root, String packageName) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + if (packageName.length() == 0) { + return root; + } + return root.append(packageName.replace('.', IPath.SEPARATOR)); + } + + /** Return the path of the package fragment root + * with the given name. A workspace must be open, and + * the package fragment root must exist. + */ + public IPath getPackageFragmentRootPath(IPath projectPath, String name) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + if (name.length() == 0) { + return projectPath; + } + return projectPath.append(name); + } + + /** + * Returns the core project. + */ + public IProject getProject(String projectName) { + return this.projects.get(projectName); + } + + /** + * Returns the core project. + */ + public IProject getProject(IPath projectPath) { + return this.projects.get(projectPath.lastSegment()); + } + + private File tmpDirectory; + File getTmpDirectory() { + if (this.tmpDirectory == null) { + this.tmpDirectory = new File(System.getProperty("java.io.tmpdir") + + File.separator + "org.eclipse.jdt.core.builder.tests.tmp"); + if (this.tmpDirectory.exists() && !this.tmpDirectory.isDirectory()) { + Util.delete(this.tmpDirectory); + } + this.tmpDirectory.mkdir(); + } + return this.tmpDirectory; + } + void deleteTmpDirectory() { + if (this.tmpDirectory != null) { + Util.delete(this.tmpDirectory); + this.tmpDirectory = null; + } + } + + /** + * Returns the workspace. + */ + public IWorkspace getWorkspace() { + return this.workspace; + } + + /** + * Returns the path of workspace root. + */ + public IPath getWorkspaceRootPath(){ + return getWorkspace().getRoot().getLocation(); + } + + private IPath getJarRootPath(IPath projectPath) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + return getProject(projectPath).getFullPath(); + } + + protected void handle(Exception e) { + if (e instanceof CoreException) { + handleCoreException((CoreException) e); + } else { + e.printStackTrace(); + Assert.isTrue(false); + } + } + + /** + * Handles a core exception thrown during a testing environment operation + */ + protected void handleCoreException(CoreException e) { + e.printStackTrace(); + IStatus status = e.getStatus(); + String message = e.getMessage(); + if (status.isMultiStatus()) { + MultiStatus multiStatus = (MultiStatus) status; + IStatus[] children = multiStatus.getChildren(); + StringBuilder buffer = new StringBuilder(); + for (int i = 0, max = children.length; i < max; i++) { + IStatus child = children[i]; + if (child != null) { + buffer.append(child.getMessage()); + buffer.append(System.getProperty("line.separator"));//$NON-NLS-1$ + Throwable childException = child.getException(); + if (childException != null) { + childException.printStackTrace(); + } + } + } + message = buffer.toString(); + } + Assert.isTrue( + false, + "Core exception in testing environment: " + message); //$NON-NLS-1$ + } + + /** Incrementally builds the workspace. A workspace must be + * open. + */ + public void incrementalBuild() { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + try { + getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null); + } catch (CoreException e) { + handle(e); + } + } + + /** Incrementally builds a project. A workspace must be + * open. + */ + public void incrementalBuild(IPath projectPath) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + try { + getProject(projectPath).build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null); + } catch (CoreException e) { + handle(e); + } catch(Throwable e) { + e.printStackTrace(); + } + } + + public boolean isAutoBuilding() { + IWorkspace w = getWorkspace(); + IWorkspaceDescription d = w.getDescription(); + return d.isAutoBuilding(); + } + + /** Open an empty workspace. + */ + public void openEmptyWorkspace() { + close(); + openWorkspace(); + this.projects = new Hashtable<>(10); + setup(); + } + + /** Close a project from the workspace. + */ + public void openProject(IPath projectPath){ + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + try { + getJavaProject(projectPath).getProject().open(null); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + private void openWorkspace() { + try { + closeWorkspace(); + + this.workspace = ResourcesPlugin.getWorkspace(); + + // turn off auto-build -- the tests determine when builds occur + IWorkspaceDescription description = this.workspace.getDescription(); + description.setAutoBuilding(false); + this.workspace.setDescription(description); + } catch (Exception e) { + handle(e); + } + } + + /** Renames a compilation unit int the given package in the workspace. + * A workspace must be open. + */ + public void renameCU(IPath packagePath, String cuName, String newName) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IFolder packageFolder = this.workspace.getRoot().getFolder(packagePath); + try { + packageFolder.getFile(cuName).move(packageFolder.getFile(newName).getFullPath(), true, null); + } catch (CoreException e) { + handle(e); + } + } + + /** Removes a binary class from the given package in + * the workspace. A workspace must be open, and the + * given class name must not end with ".class". + */ + public void removeBinaryClass(IPath packagePath, String className) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + className += ".class"; //$NON-NLS-1$ + IFolder packageFolder = this.workspace.getRoot().getFolder(packagePath); + deleteResource(packageFolder.getFile(className)); + } + + /** Removes a class from the given package in the workspace. + * A workspace must be open, and the given class name must + * not end with ".java". + */ + public void removeClass(IPath packagePath, String className) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + className += ".java"; //$NON-NLS-1$ + IFolder packageFolder = this.workspace.getRoot().getFolder(packagePath); + deleteResource(packageFolder.getFile(className)); + } + + /** Removes a package from the given package fragment root + * in the workspace. A workspace must be open. + */ + public void removePackage(IPath packageFragmentRootPath, String packageName) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IPath path = + packageFragmentRootPath.append(packageName.replace('.', IPath.SEPARATOR)); + IFolder folder = this.workspace.getRoot().getFolder(path); + deleteResource(folder); + } + + /** Removes the given package fragment root from the + * the workspace. A workspace must be open. + */ + public void removePackageFragmentRoot(IPath projectPath, String packageFragmentRootName) throws JavaModelException { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + if (packageFragmentRootName.length() > 0) { + IFolder folder = getProject(projectPath).getFolder(packageFragmentRootName); + if (folder.exists()) { + deleteResource(folder); + } + } + IPath rootPath = getPackageFragmentRootPath(projectPath, packageFragmentRootName); + removeEntry(projectPath, rootPath); + } + + /** Remove a project from the workspace. + */ + public void removeProject(IPath projectPath){ + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + try { + getJavaProject(projectPath).close(); + } catch (JavaModelException e) { + e.printStackTrace(); + } + IProject project = getProject(projectPath); + deleteResource(project); + + } + + /** Remove a required project from the classpath + */ + public void removeRequiredProject(IPath projectPath, IPath requiredProject) throws JavaModelException { + removeEntry(projectPath, requiredProject); + } + + /** Remove all elements in the workspace. + */ + public void resetWorkspace(){ + if (this.projects != null) { + Enumeration projectNames = this.projects.keys(); + while (projectNames.hasMoreElements()) { + String projectName = projectNames.nextElement(); + removeProject(getProject(projectName).getFullPath()); + } + } + } + + /** Removes the given internal jar from the workspace. + * A workspace must be open. + */ + public void removeInternalJar(IPath projectPath, String zipName) throws JavaModelException { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + checkAssertion("zipName must end with .zip or .jar", zipName.endsWith(".zip") || zipName.endsWith(".jar")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + /* remove zip from the java model (it caches open zip files) */ + IPath zipPath = getJarRootPath(projectPath).append(zipName); + try { + getJavaProject(projectPath) + .getPackageFragmentRoot(getWorkspace().getRoot().getFile(zipPath)) + .close(); + } catch (JavaModelException e) { + e.printStackTrace(); + } + removePackageFragmentRoot(projectPath, zipName); + + IFile file = getProject(projectPath).getFile(zipName); + deleteResource(file); + } + + /** + * Remove an external jar from the classpath. + */ + public void removeExternalJar(IPath projectPath, IPath jarPath) throws JavaModelException { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + removeEntry(projectPath, jarPath); + } + + private void removeEntry(IPath projectPath, IPath entryPath) throws JavaModelException { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IClasspathEntry[] oldEntries = getRawClasspath(projectPath); + for (int i = 0; i < oldEntries.length; ++i) { + if (oldEntries[i].getPath().equals(entryPath)) { + IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length - 1]; + System.arraycopy(oldEntries, 0, newEntries, 0, i); + System.arraycopy(oldEntries, i + 1, newEntries, i, oldEntries.length - i - 1); + setClasspath(projectPath, newEntries); + } + } + } + + public void changePackageFragmentRootTestAttribute(IPath projectPath, IPath entryPath, boolean isTest) throws JavaModelException { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IClasspathEntry[] oldEntries = getRawClasspath(projectPath); + for (int i = 0; i < oldEntries.length; ++i) { + final IClasspathEntry oldEntry = oldEntries[i]; + if (oldEntry.getPath().equals(entryPath)) { + IClasspathEntry[] newEntries = oldEntries.clone(); + IClasspathAttribute[] classpathAttributes = Arrays.stream(oldEntry.getExtraAttributes()) + .filter(e -> !e.getName().equals(IClasspathAttribute.TEST)).toArray(IClasspathAttribute[]::new); + if(isTest) { + int length=classpathAttributes.length; + System.arraycopy(classpathAttributes, 0, classpathAttributes = new IClasspathAttribute[length + 1], 0, length); + classpathAttributes[length] = JavaCore.newClasspathAttribute(IClasspathAttribute.TEST, "true"); + } + IClasspathEntry entry = JavaCore.newSourceEntry( + entryPath, + oldEntry.getInclusionPatterns(), + oldEntry.getExclusionPatterns(), + oldEntry.getOutputLocation(), + classpathAttributes); + newEntries[i] = entry; + setClasspath(projectPath, newEntries); + return; + } + } + } + + /** Remove a file + */ + public void removeFile(IPath filePath) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + deleteResource(this.workspace.getRoot().getFile(filePath)); + } + + /** Remove a folder + */ + public void removeFolder(IPath folderPath) { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IFolder folder = this.workspace.getRoot().getFolder(folderPath); + deleteResource(folder); + } + + /** Sets the classpath to the given package fragment + * roots. The builder searches the classpath to + * find the java files it needs during a build. + */ +// public void setClasspath(IPath projectPath, IPath[] packageFragmentRootsPath) { +// try { +// checkAssertion("a workspace must be open", fIsOpen); //$NON-NLS-1$ +// IJavaProject javaProject = JavaCore.create(getProject(projectPath)); +// IClasspathEntry[] entries = +// new IClasspathEntry[packageFragmentRootsPath.length]; +// for (int i = 0; i < packageFragmentRootsPath.length; ++i) { +// IPath path = packageFragmentRootsPath[i]; +// if ("jar".equals(path.getFileExtension()) //$NON-NLS-1$ +// || "zip".equals(path.getFileExtension())) { //$NON-NLS-1$ +// entries[i] = JavaCore.newLibraryEntry(path, null, null, isExported); +// } else if (projectPath.isPrefixOf(packageFragmentRootsPath[i])) { +// entries[i] = JavaCore.newSourceEntry(path, IPath[] exclusionPatterns, IPath specificOutputLocation) +// } else { +// entries[i] = JavaCore.newProjectEntry(path, isExported); +// } +// } +// javaProject.setRawClasspath(entries, null); +// } catch (JavaModelException e) { +// e.printStackTrace(); +// checkAssertion("JavaModelException", false); //$NON-NLS-1$ +// } +// } + + public void setAutoBuilding(boolean value) { + try { + IWorkspace w = getWorkspace(); + IWorkspaceDescription d = w.getDescription(); + d.setAutoBuilding(value); + w.setDescription(d); + } catch (CoreException e) { + e.printStackTrace(); + checkAssertion("CoreException", false); //$NON-NLS-1$ + } + } + + public void setBuildOrder(String[] projects) { + try { + IWorkspace w = getWorkspace(); + IWorkspaceDescription d = w.getDescription(); + d.setBuildOrder(projects); + w.setDescription(d); + } catch (CoreException e) { + e.printStackTrace(); + checkAssertion("CoreException", false); //$NON-NLS-1$ + } + } + + public void setClasspath(IPath projectPath, IClasspathEntry[] entries) throws JavaModelException { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IJavaProject javaProject = JavaCore.create(getProject(projectPath)); + javaProject.setRawClasspath(entries, null); + } + + public IPath setExternalOutputFolder(IPath projectPath, String name, IPath externalOutputLocation){ + IPath result = null; + try { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IProject p = getProject(projectPath); + IFolder f = p.getFolder(name); + f.createLink(externalOutputLocation, IResource.ALLOW_MISSING_LOCAL, null); + + result = f.getFullPath(); + IJavaProject javaProject = JavaCore.create(p); + javaProject.setOutputLocation(result, null); + } catch (CoreException e) { + e.printStackTrace(); + checkAssertion("CoreException", false); //$NON-NLS-1$ + } + return result; + } + + public IPath setOutputFolder(IPath projectPath, String outputFolder){ + IPath outputPath = null; + try { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + IJavaProject javaProject = JavaCore.create(getProject(projectPath)); + outputPath = projectPath.append(outputFolder); + javaProject.setOutputLocation(outputPath, null); + } catch (JavaModelException e) { + e.printStackTrace(); + checkAssertion("JavaModelException", false); //$NON-NLS-1$ + } + return outputPath; + } + + private void setup() { + this.isOpen = true; + } + + /** + * Wait for autobuild notification to occur + */ + public void waitForAutoBuild() { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + boolean wasInterrupted = false; + do { + try { + Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null); + boolean enableIndex = true; + JavaModelManager.getIndexManager().waitForIndex(enableIndex, null); + wasInterrupted = false; + } catch (OperationCanceledException e) { + handle(e); + } catch (InterruptedException e) { + wasInterrupted = true; + } + } while (wasInterrupted); + } + + public void waitForManualRefresh() { + checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$ + boolean wasInterrupted = false; + do { + try { + Job.getJobManager().join(ResourcesPlugin.FAMILY_MANUAL_REFRESH, null); + boolean enableIndex = true; + JavaModelManager.getIndexManager().waitForIndex(enableIndex, null); + wasInterrupted = false; + } catch (OperationCanceledException e) { + handle(e); + } catch (InterruptedException e) { + wasInterrupted = true; + } + } while (wasInterrupted); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/test.xml b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/test.xml new file mode 100644 index 0000000000..87d41e0907 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/test.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/workspace/Test571363.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/workspace/Test571363.jar new file mode 100644 index 0000000000..fccdbfee9f Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.builder/workspace/Test571363.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.classpath b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.classpath new file mode 100644 index 0000000000..73d6894a61 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.classpath @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.gitignore b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.gitignore new file mode 100644 index 0000000000..e7af312dd6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.gitignore @@ -0,0 +1,4 @@ +/bin +/endorsed +/target +/test.dat diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.project b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.project new file mode 100644 index 0000000000..bce5dfc9c9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.project @@ -0,0 +1,26 @@ + + + org.eclipse.jdt.core.tests.compiler + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.core.resources.prefs b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..99f26c0203 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.core.runtime.prefs b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000000..5a0ad22d2a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\n diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.jdt.core.prefs b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..239da5461a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,128 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.builder.cleanOutputFolder=clean +org.eclipse.jdt.core.builder.duplicateResourceTask=warning +org.eclipse.jdt.core.builder.invalidClasspath=abort +org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder=ignore +org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch,.svn/ +org.eclipse.jdt.core.circularClasspath=error +org.eclipse.jdt.core.classpath.exclusionPatterns=enabled +org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled +org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore +org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.doc.comment.support=enabled +org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore +org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore +org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=warning +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private +org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=enabled +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public +org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=enabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=warning +org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedImport=error +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.incompatibleJDKLevel=ignore +org.eclipse.jdt.core.incompleteClasspath=error diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.jdt.ui.prefs b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000000..cc05ab3605 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,56 @@ +#Thu Nov 04 13:38:45 EDT 2010 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=false +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=false +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.update_ibm_copyright_to_current_year=true +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..ab64559563 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF @@ -0,0 +1,30 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.jdt.core.tests.compiler;singleton:=true +Bundle-Version: 3.12.1750.qualifier +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Export-Package: org.eclipse.jdt.core.tests.compiler, + org.eclipse.jdt.core.tests.compiler.map, + org.eclipse.jdt.core.tests.compiler.parser, + org.eclipse.jdt.core.tests.compiler.regression, + org.eclipse.jdt.core.tests.dom, + org.eclipse.jdt.core.tests.eval, + org.eclipse.jdt.core.tests.eval.target, + org.eclipse.jdt.core.tests.junit.extension, + org.eclipse.jdt.core.tests.runtime, + org.eclipse.jdt.core.tests.util +Require-Bundle: org.junit;bundle-version="3.8.1", + org.eclipse.jdt.debug;bundle-version="[3.2.0,4.0.0)", + org.eclipse.jdt.core;bundle-version="[3.10.0,4.0.0)", + org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", + org.eclipse.test.performance;bundle-version="[3.10.0,4.0.0)", + org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)", + org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0)";resolution:=optional, + org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Eclipse-BundleShape: dir +Bundle-Activator: org.eclipse.jdt.core.tests.compiler.Activator +Bundle-ActivationPolicy: lazy +Automatic-Module-Name: org.eclipse.jdt.core.tests.compiler diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/META-INF/eclipse.inf b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/META-INF/eclipse.inf new file mode 100644 index 0000000000..4ea66d6f8d --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/META-INF/eclipse.inf @@ -0,0 +1,3 @@ +jarprocessor.exclude.pack=true + +jarprocessor.exclude.children=true \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/about.html b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/about.html new file mode 100644 index 0000000000..164f781a8f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/about.html @@ -0,0 +1,36 @@ + + + + +About + + +

About This Content

+ +

November 30, 2017

+

License

+ +

+ The Eclipse Foundation makes available all content in this plug-in + ("Content"). Unless otherwise indicated below, the Content + is provided to you under the terms and conditions of the Eclipse + Public License Version 2.0 ("EPL"). A copy of the EPL is + available at http://www.eclipse.org/legal/epl-2.0. + For purposes of the EPL, "Program" will mean the Content. +

+ +

+ If you did not receive this Content directly from the Eclipse + Foundation, the Content is being redistributed by another party + ("Redistributor") and different terms and conditions may + apply to your use of any object code in the Content. Check the + Redistributor's license that was provided with the Content. If no such + license exists, contact the Redistributor. Unless otherwise indicated + below, the terms and conditions of the EPL still apply to any source + code in the Content and such source code may be obtained at http://www.eclipse.org. +

+ + + \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/build.properties b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/build.properties new file mode 100644 index 0000000000..cfa629f680 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/build.properties @@ -0,0 +1,23 @@ +############################################################################### +# Copyright (c) 2000, 2013 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +# Red Hat Inc. (mistria) - Avoid nested jars +############################################################################### +bin.includes = test.xml,\ + about.html,\ + .,\ + META-INF/,\ + plugin.properties,\ + workspace/ +source.. = src/ +output.. = bin/ +src.includes = about.html diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/forceQualifierUpdate.txt b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/forceQualifierUpdate.txt new file mode 100644 index 0000000000..c997cd7c6c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/forceQualifierUpdate.txt @@ -0,0 +1,2 @@ +# To force a version qualifier update, add the bug here +Bug 534597 - Unanticipated comparator errors in I20180511-2000 \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/plugin.properties b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/plugin.properties new file mode 100644 index 0000000000..923f64d0db --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/plugin.properties @@ -0,0 +1,15 @@ +############################################################################### +# Copyright (c) 2000, 2006 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +providerName=Eclipse.org +pluginName=Java Compiler Tests diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/pom.xml b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/pom.xml new file mode 100644 index 0000000000..981c5385c4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/pom.xml @@ -0,0 +1,48 @@ + + + + 4.0.0 + + eclipse.jdt.core + tests-pom + 4.22.0-SNAPSHOT + ../tests-pom/ + + org.eclipse.jdt + org.eclipse.jdt.core.tests.compiler + 3.12.1750-SNAPSHOT + eclipse-plugin + + + true + + + + + + maven-clean-plugin + 2.5 + + + + ${basedir} + + test.dat + + + + + + + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/EvalTestsTarget.zip b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/EvalTestsTarget.zip new file mode 100644 index 0000000000..d42def46ad Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/EvalTestsTarget.zip differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/TestJavadocVisibility.zip b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/TestJavadocVisibility.zip new file mode 100644 index 0000000000..cfb2c9bb0e Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/TestJavadocVisibility.zip differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/Activator.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/Activator.java new file mode 100644 index 0000000000..19fd680b98 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/Activator.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Stephan Herrmann and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler; + +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Plugin; +import org.eclipse.core.runtime.Status; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +/** + * Make the PackageAdmin service accessible to tests. + * + * @deprecated uses deprecated class PackageAdmin. + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Activator extends Plugin { + + private static final String PLUGIN_ID = "org.eclipse.jdt.core.tests.compiler"; + + static org.osgi.service.packageadmin.PackageAdmin packageAdmin = null; + + + public void start(BundleContext context) throws Exception { + + ServiceReference ref= context.getServiceReference(org.osgi.service.packageadmin.PackageAdmin.class.getName()); + if (ref!=null) + packageAdmin = (org.osgi.service.packageadmin.PackageAdmin)context.getService(ref); + else + getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, "Failed to load PackageAdmin service. Will not be able to access bundles org.eclipse.jdt.annotation.")); + } + + public void stop(BundleContext context) throws Exception { + // nothing + } + + public static org.osgi.service.packageadmin.PackageAdmin getPackageAdmin() { + return packageAdmin; + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/map/CharArrayMapperTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/map/CharArrayMapperTest.java new file mode 100644 index 0000000000..d977b1968a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/map/CharArrayMapperTest.java @@ -0,0 +1,263 @@ +/******************************************************************************* + * Copyright (c) 2021 jkubitz and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * jkubitz - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.map; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +import org.eclipse.jdt.core.tests.junit.extension.TestCase; +import org.eclipse.jdt.internal.compiler.util.CharArrayHashMap; +import org.eclipse.jdt.internal.compiler.util.CharArrayMap; +import org.eclipse.jdt.internal.compiler.util.CharArrayMapper; +import org.eclipse.jdt.internal.compiler.util.CharDelegateMap; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class CharArrayMapperTest extends TestCase { + public CharArrayMapperTest(String testName) { + super(testName); + } + public static Test suite() { + + TestSuite suite = new TestSuite(CharArrayMapperTest.class.getPackageName()); + suite.addTest(new TestSuite(CharArrayMapperTest.class)); + return suite; + } + void testPutNew(CharArrayMapper map, String keyString) { + int oldSize = map.size(); + String value = "_" + keyString + "_"; + String previous = map.put(keyString.toCharArray(), value); + int newSize = map.size(); + assertEquals("testPutNew1(" + keyString + ")", null, previous); + String vinside = map.get(keyString.toCharArray()); + assertEquals("testPutNew2(" + keyString + ")", value, vinside); + assertEquals("testPutNew3(" + keyString + ")", oldSize+1, newSize); + assertEquals("testPutNew4(" + keyString + ")", map.keys().size(), newSize); + assertEquals("testPutNew5(" + keyString + ")", map.values().size(), newSize); + } + + void testPutExisting(CharArrayMapper map, String keyString) { + int oldSize = map.size(); + String value = "_new_" + keyString + "_"; + String previous = map.get(keyString.toCharArray()); + String returned = map.put(keyString.toCharArray(), value); + int newSize = map.size(); + assertEquals("testPutExisting1(" + keyString + ")", previous, returned); + assertEquals("testPutNew3(" + keyString + ")", oldSize, newSize); + assertEquals("testPutNew4(" + keyString + ")", map.keys().size(), oldSize); + assertEquals("testPutNew5(" + keyString + ")", map.values().size(), oldSize); + map.put(keyString.toCharArray(), previous); // restore + } + + void testGetExisting(CharArrayMapper map, String keyString) { + String value = "_" + keyString + "_"; + String vinside = map.get(keyString.toCharArray()); + assertEquals("testGetExisting1(" + keyString + ")", value, vinside); + assertEquals("testGetExisting2(" + keyString + ")", true, map.values().contains(value)); + assertEquals("testGetExisting3(" + keyString + ")", true, + map.keys().stream().anyMatch(k -> Arrays.equals(k, keyString.toCharArray()))); + } + + void testGetNonExisting(CharArrayMapper map, String keyString) { + String value = "_" + keyString + "_"; + String vinside = map.get(keyString.toCharArray()); + assertEquals("testGetNonExisting1(" + keyString + ")", null, vinside); + assertEquals("testGetNonExisting1(" + keyString + ")", false, map.values().contains(value)); + assertEquals("testGetNonExisting1(" + keyString + ")", false, + map.keys().stream().anyMatch(k -> Arrays.equals(k, keyString.toCharArray()))); + } + + + void testIntList(CharArrayMapper map) { + assertEquals("empty", Collections.emptyList(), map.keys()); + int N = 100; + for (int i = 0; i < N; i++) { + testPutNew(map, "" + i); + testPutExisting(map, "" + i); + testGetExisting(map, "" + i); + } + for (int i = 0; i < N; i++) { + testGetExisting(map, "" + i); + } + for (int i = N + 1; i < N * 2; i++) { + testGetNonExisting(map, "" + i); + } + } + + void testColliding(CharArrayMapper map) { + assertEquals("empty", Collections.emptyList(), map.keys()); + for (int[] collision : hashCollisions) { + int h1 = Arrays.hashCode(("" + collision[0]).toCharArray()); + int h2 = Arrays.hashCode(("" + collision[1]).toCharArray()); + assertEquals("collision(" + collision[0] + "<->" + collision[1] + ")", h1, h2); + for (int i : collision) { + testPutNew(map, "" + i); + testPutExisting(map, "" + i); + testGetExisting(map, "" + i); + } + } + for (int[] collision : hashCollisions) { + for (int i : collision) { + testGetExisting(map, "" + i); + } + } + int N = 100; + for (int i = N + 1; i < N * 2; i++) { + testGetNonExisting(map, "" + i); + } + } + + public void testCharArrayHashMap() { + testIntList(new CharArrayHashMap<>(4)); + testColliding(new CharArrayHashMap<>(4)); + } + + public void testCharArrayMap() { + testIntList(new CharArrayMap<>()); + testColliding(new CharArrayMap<>()); + } + + public void testCharDelegateMap() { + testIntList(new CharDelegateMap<>()); + testColliding(new CharDelegateMap<>()); + } + + static int[][] hashCollisions = { { 17510, 37760009 }, { 17520, 37760019 }, { 17530, 37760029 }, + { 17540, 37760039 }, { 17550, 37760049 }, { 17560, 37760059 }, { 17570, 37760069 }, { 17580, 37760079 }, + { 17590, 37760089 }, { 17610, 37760109 }, { 17620, 37760119 }, { 17630, 37760129 }, { 17640, 37760139 }, + { 17650, 37760149 }, { 17660, 37760159 }, { 17670, 37760169 }, { 17680, 37760179 }, { 17690, 37760189 }, + { 17710, 37760209 }, { 17720, 37760219 }, { 17730, 37760229 }, { 17740, 37760239 }, { 17750, 37760249 }, + { 17760, 37760259 }, { 17770, 37760269 }, { 17780, 37760279 }, { 17790, 37760289 }, { 17810, 37760309 }, + { 17820, 37760319 }, { 17830, 37760329 }, { 17840, 37760339 }, { 17850, 37760349 }, { 17860, 37760359 }, + { 17870, 37760369 }, { 17880, 37760379 }, { 17890, 37760389 }, { 17910, 37760409 }, { 17920, 37760419 }, + { 17930, 37760429 }, { 17940, 37760439 }, { 17950, 37760449 }, { 17960, 37760459 }, { 17970, 37760469 }, + { 17980, 37760479 }, { 17990, 37760489 }, { 18510, 37761009 }, { 18520, 37761019 }, { 18530, 37761029 }, + { 18540, 37761039 }, { 18550, 37761049 }, { 18560, 37761059 }, { 18570, 37761069 }, { 18580, 37761079 }, + { 18590, 37761089 }, { 18610, 37761109 }, { 18620, 37761119 }, { 18630, 37761129 }, { 18640, 37761139 }, + { 18650, 37761149 }, { 18660, 37761159 }, { 18670, 37761169 }, { 18680, 37761179 }, { 18690, 37761189 }, + { 18710, 37761209 }, { 18720, 37761219 }, { 18730, 37761229 }, { 18740, 37761239 }, { 18750, 37761249 }, + { 18760, 37761259 }, { 18770, 37761269 }, { 18780, 37761279 }, { 18790, 37761289 }, { 18810, 37761309 }, + { 18820, 37761319 }, { 18830, 37761329 }, { 18840, 37761339 }, { 18850, 37761349 }, { 18860, 37761359 }, + { 18870, 37761369 }, { 18880, 37761379 }, { 18890, 37761389 }, { 18910, 37761409 }, { 18920, 37761419 }, + { 18930, 37761429 }, { 18940, 37761439 }, { 18950, 37761449 }, { 18960, 37761459 }, { 18970, 37761469 }, + { 18980, 37761479 }, { 18990, 37761489 }, { 19510, 37762009 }, { 19520, 37762019 }, { 19530, 37762029 }, + { 19540, 37762039 }, { 19550, 37762049 }, { 19560, 37762059 }, { 19570, 37762069 }, { 19580, 37762079 }, + { 19590, 37762089 }, { 19610, 37762109 }, { 19620, 37762119 }, { 19630, 37762129 }, { 19640, 37762139 }, + { 19650, 37762149 }, { 19660, 37762159 }, { 19670, 37762169 }, { 19680, 37762179 }, { 19690, 37762189 }, + { 19710, 37762209 }, { 19720, 37762219 }, { 19730, 37762229 }, { 19740, 37762239 }, { 19750, 37762249 }, + { 19760, 37762259 }, { 19770, 37762269 }, { 19780, 37762279 }, { 19790, 37762289 }, { 19810, 37762309 }, + { 19820, 37762319 }, { 19830, 37762329 }, { 19840, 37762339 }, { 19850, 37762349 }, { 19860, 37762359 }, + { 19870, 37762369 }, { 19880, 37762379 }, { 19890, 37762389 }, { 19910, 37762409 }, { 19920, 37762419 }, + { 19930, 37762429 }, { 19940, 37762439 }, { 19950, 37762449 }, { 19960, 37762459 }, { 19970, 37762469 }, + { 19980, 37762479 }, { 19990, 37762489 }, { 27510, 37770009 }, { 27520, 37770019 }, { 27530, 37770029 }, + { 27540, 37770039 }, { 27550, 37770049 }, { 27560, 37770059 }, { 27570, 37770069 }, { 27580, 37770079 }, + { 27590, 37770089 }, { 27610, 37770109 }, { 27620, 37770119 }, { 27630, 37770129 }, { 27640, 37770139 }, + { 27650, 37770149 }, { 27660, 37770159 }, { 27670, 37770169 }, { 27680, 37770179 }, { 27690, 37770189 }, + { 27710, 37770209 }, { 27720, 37770219 }, { 27730, 37770229 }, { 27740, 37770239 }, { 27750, 37770249 }, + { 27760, 37770259 }, { 27770, 37770269 }, { 27780, 37770279 }, { 27790, 37770289 }, { 27810, 37770309 }, + { 27820, 37770319 }, { 27830, 37770329 }, { 27840, 37770339 }, { 27850, 37770349 }, { 27860, 37770359 }, + { 27870, 37770369 }, { 27880, 37770379 }, { 27890, 37770389 }, { 27910, 37770409 }, { 27920, 37770419 }, + { 27930, 37770429 }, { 27940, 37770439 }, { 27950, 37770449 }, { 27960, 37770459 }, { 27970, 37770469 }, + { 27980, 37770479 }, { 27990, 37770489 }, { 28510, 37771009 }, { 28520, 37771019 }, { 28530, 37771029 }, + { 28540, 37771039 }, { 28550, 37771049 }, { 28560, 37771059 }, { 28570, 37771069 }, { 28580, 37771079 }, + { 28590, 37771089 }, { 28610, 37771109 }, { 28620, 37771119 }, { 28630, 37771129 }, { 28640, 37771139 }, + { 28650, 37771149 }, { 28660, 37771159 }, { 28670, 37771169 }, { 28680, 37771179 }, { 28690, 37771189 }, + { 28710, 37771209 }, { 28720, 37771219 }, { 28730, 37771229 }, { 28740, 37771239 }, { 28750, 37771249 }, + { 28760, 37771259 }, { 28770, 37771269 }, { 28780, 37771279 }, { 28790, 37771289 }, { 28810, 37771309 }, + { 28820, 37771319 }, { 28830, 37771329 }, { 28840, 37771339 }, { 28850, 37771349 }, { 28860, 37771359 }, + { 28870, 37771369 }, { 28880, 37771379 }, { 28890, 37771389 }, { 28910, 37771409 }, { 28920, 37771419 }, + { 28930, 37771429 }, { 28940, 37771439 }, { 28950, 37771449 }, { 28960, 37771459 }, { 28970, 37771469 }, + { 28980, 37771479 }, { 28990, 37771489 }, { 29510, 37772009 }, { 29520, 37772019 }, { 29530, 37772029 }, + { 29540, 37772039 }, { 29550, 37772049 }, { 29560, 37772059 }, { 29570, 37772069 }, { 29580, 37772079 }, + { 29590, 37772089 }, { 29610, 37772109 }, { 29620, 37772119 }, { 29630, 37772129 }, { 29640, 37772139 }, + { 29650, 37772149 }, { 29660, 37772159 }, { 29670, 37772169 }, { 29680, 37772179 }, { 29690, 37772189 }, + { 29710, 37772209 }, { 29720, 37772219 }, { 29730, 37772229 }, { 29740, 37772239 }, { 29750, 37772249 }, + { 29760, 37772259 }, { 29770, 37772269 }, { 29780, 37772279 }, { 29790, 37772289 }, { 29810, 37772309 }, + { 29820, 37772319 }, { 29830, 37772329 }, { 29840, 37772339 }, { 29850, 37772349 }, { 29860, 37772359 }, + { 29870, 37772369 }, { 29880, 37772379 }, { 29890, 37772389 }, { 29910, 37772409 }, { 29920, 37772419 }, + { 29930, 37772429 }, { 29940, 37772439 }, { 29950, 37772449 }, { 29960, 37772459 }, { 29970, 37772469 }, + { 29980, 37772479 }, { 29990, 37772489 }, { 37510, 37780009 }, { 37520, 37780019 }, { 37530, 37780029 }, + { 37540, 37780039 }, { 37550, 37780049 }, { 37560, 37780059 }, { 37570, 37780069 }, { 37580, 37780079 }, + { 37590, 37780089 }, { 37610, 37780109 }, { 37620, 37780119 }, { 37630, 37780129 }, { 37640, 37780139 }, + { 37650, 37780149 }, { 37660, 37780159 }, { 37670, 37780169 }, { 37680, 37780179 }, { 37690, 37780189 }, + { 37710, 37780209 }, { 37720, 37780219 }, { 37730, 37780229 }, { 37740, 37780239 }, { 37750, 37780249 }, { 37760, 37780259 }, { 37770, 37780269 }, { 37780, 37780279 }, { 37790, 37780289 }, { 37810, 37780309 }, + { 37820, 37780319 }, { 37830, 37780329 }, { 37840, 37780339 }, { 37850, 37780349 }, { 37860, 37780359 }, + { 37870, 37780369 }, { 37880, 37780379 }, { 37890, 37780389 }, { 37910, 37780409 }, { 37920, 37780419 }, + { 37930, 37780429 }, { 37940, 37780439 }, { 37950, 37780449 }, { 37960, 37780459 }, { 37970, 37780469 }, + { 37980, 37780479 }, { 37990, 37780489 }, { 38510, 37781009 }, { 38520, 37781019 }, { 38530, 37781029 }, + { 38540, 37781039 }, { 38550, 37781049 }, { 38560, 37781059 }, { 38570, 37781069 }, { 38580, 37781079 }, + { 38590, 37781089 }, { 38610, 37781109 }, { 38620, 37781119 }, { 38630, 37781129 }, { 38640, 37781139 }, + { 38650, 37781149 }, { 38660, 37781159 }, { 38670, 37781169 }, { 38680, 37781179 }, { 38690, 37781189 }, + { 38710, 37781209 }, { 38720, 37781219 }, { 38730, 37781229 }, { 38740, 37781239 }, { 38750, 37781249 }, + { 38760, 37781259 }, { 38770, 37781269 }, { 38780, 37781279 }, { 38790, 37781289 }, { 38810, 37781309 }, + { 38820, 37781319 }, { 38830, 37781329 }, { 38840, 37781339 }, { 38850, 37781349 }, { 38860, 37781359 }, + { 38870, 37781369 }, { 38880, 37781379 }, { 38890, 37781389 }, { 38910, 37781409 }, { 38920, 37781419 }, + { 38930, 37781429 }, { 38940, 37781439 }, { 38950, 37781449 }, { 38960, 37781459 }, { 38970, 37781469 }, + { 38980, 37781479 }, { 38990, 37781489 }, { 39510, 37782009 }, { 39520, 37782019 }, { 39530, 37782029 }, + { 39540, 37782039 }, { 39550, 37782049 }, { 39560, 37782059 }, { 39570, 37782069 }, { 39580, 37782079 }, + { 39590, 37782089 }, { 39610, 37782109 }, { 39620, 37782119 }, { 39630, 37782129 }, { 39640, 37782139 }, + { 39650, 37782149 }, { 39660, 37782159 }, { 39670, 37782169 }, { 39680, 37782179 }, { 39690, 37782189 }, + { 39710, 37782209 }, { 39720, 37782219 }, { 39730, 37782229 }, { 39740, 37782239 }, { 39750, 37782249 }, + { 39760, 37782259 }, { 39770, 37782269 }, { 39780, 37782279 }, { 39790, 37782289 }, { 39810, 37782309 }, + { 39820, 37782319 }, { 39830, 37782329 }, { 39840, 37782339 }, { 39850, 37782349 }, { 39860, 37782359 }, + { 39870, 37782369 }, { 39880, 37782379 }, { 39890, 37782389 }, { 39910, 37782409 }, { 39920, 37782419 }, + { 39930, 37782429 }, { 39940, 37782439 }, { 39950, 37782449 }, { 39960, 37782459 }, { 39970, 37782469 }, + { 39980, 37782479 }, { 39990, 37782489 }, { 47510, 37790009 }, { 47520, 37790019 }, { 47530, 37790029 }, + { 47540, 37790039 }, { 47550, 37790049 }, { 47560, 37790059 }, { 47570, 37790069 }, { 47580, 37790079 }, + { 47590, 37790089 }, { 47610, 37790109 }, { 47620, 37790119 }, { 47630, 37790129 }, { 47640, 37790139 }, + { 47650, 37790149 }, { 47660, 37790159 }, { 47670, 37790169 }, { 47680, 37790179 }, { 47690, 37790189 }, + { 47710, 37790209 }, { 47720, 37790219 }, { 47730, 37790229 }, { 47740, 37790239 }, { 47750, 37790249 }, + { 47760, 37790259 }, { 47770, 37790269 }, { 47780, 37790279 }, { 47790, 37790289 }, { 47810, 37790309 }, + { 47820, 37790319 }, { 47830, 37790329 }, { 47840, 37790339 }, { 47850, 37790349 }, { 47860, 37790359 }, + { 47870, 37790369 }, { 47880, 37790379 }, { 47890, 37790389 }, { 47910, 37790409 }, { 47920, 37790419 }, + { 47930, 37790429 }, { 47940, 37790439 }, { 47950, 37790449 }, { 47960, 37790459 }, { 47970, 37790469 }, + { 47980, 37790479 }, { 47990, 37790489 }, { 48510, 37791009 }, { 48520, 37791019 }, { 48530, 37791029 }, + { 48540, 37791039 }, { 48550, 37791049 }, { 48560, 37791059 }, { 48570, 37791069 }, { 48580, 37791079 }, + { 48590, 37791089 }, { 48610, 37791109 }, { 48620, 37791119 }, { 48630, 37791129 }, { 48640, 37791139 }, + { 48650, 37791149 }, { 48660, 37791159 }, { 48670, 37791169 }, { 48680, 37791179 }, { 48690, 37791189 }, + { 48710, 37791209 }, { 48720, 37791219 }, { 48730, 37791229 }, { 48740, 37791239 }, { 48750, 37791249 }, + { 48760, 37791259 }, { 48770, 37791269 }, { 48780, 37791279 }, { 48790, 37791289 }, { 48810, 37791309 }, + { 48820, 37791319 }, { 48830, 37791329 }, { 48840, 37791339 }, { 48850, 37791349 }, { 48860, 37791359 }, + { 48870, 37791369 }, { 48880, 37791379 }, { 48890, 37791389 }, { 48910, 37791409 }, { 48920, 37791419 }, + { 48930, 37791429 }, { 48940, 37791439 }, { 48950, 37791449 }, { 48960, 37791459 }, { 48970, 37791469 }, + { 48980, 37791479 }, { 48990, 37791489 }, { 49510, 37792009 }, { 49520, 37792019 }, { 49530, 37792029 }, + { 49540, 37792039 }, { 49550, 37792049 }, { 49560, 37792059 }, { 49570, 37792069 }, { 49580, 37792079 }, + { 49590, 37792089 }, { 49610, 37792109 }, { 49620, 37792119 }, { 49630, 37792129 }, { 49640, 37792139 }, + { 49650, 37792149 }, { 49660, 37792159 }, { 49670, 37792169 }, { 49680, 37792179 }, { 49690, 37792189 }, + { 49710, 37792209 }, { 49720, 37792219 }, { 49730, 37792229 }, { 49740, 37792239 }, { 49750, 37792249 }, + { 49760, 37792259 }, { 49770, 37792269 }, { 49780, 37792279 }, { 49790, 37792289 }, { 49810, 37792309 }, + { 49820, 37792319 }, { 49830, 37792329 }, { 49840, 37792339 }, { 49850, 37792349 }, { 49860, 37792359 }, + { 49870, 37792369 }, { 49880, 37792379 }, { 49890, 37792389 }, { 49910, 37792409 }, { 49920, 37792419 }, + { 49930, 37792429 }, { 49940, 37792439 }, { 49950, 37792449 }, { 49960, 37792459 }, { 49970, 37792469 }, + { 49980, 37792479 }, { 49990, 37792489 } }; + + /* calculate hashCollisions used above: */ + public static void main(String[] args) { + int N = 100000000; + HashMap> hashCollisions_ = new HashMap<>(); + for (int i = 0; i < N; i++) { + char[] key = ("" + i).toCharArray(); + Integer hashCode = Arrays.hashCode(key); + List l = hashCollisions_.computeIfAbsent(hashCode, h -> new ArrayList<>()); + l.add(i); + if (l.size() > 1) { + System.out.println(l.size() + " collissions:" + hashCode + "->" + l); + } + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractCompletionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractCompletionTest.java new file mode 100644 index 0000000000..e5c8b3d767 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractCompletionTest.java @@ -0,0 +1,457 @@ +/******************************************************************************* + * Copyright (c) 2000, 2011 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import java.util.Locale; + +import org.eclipse.jdt.internal.codeassist.complete.CompletionOnMemberAccess; +import org.eclipse.jdt.internal.codeassist.complete.CompletionParser; +import org.eclipse.jdt.internal.codeassist.complete.CompletionScanner; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.ASTNode; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Initializer; +import org.eclipse.jdt.internal.compiler.ast.ThisReference; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +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.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.Util; + +public abstract class AbstractCompletionTest extends AbstractCompilerTest { + + public final static String NONE = ""; + public final static String NULL = "null"; +public AbstractCompletionTest(String testName){ + super(testName); +} +/* + * DietParse with completionNode check + */ +public void checkDietParse( + char[] source, + int cursorLocation, + String expectedCompletion, + String expectedUnitToString, + String expectedCompletionIdentifier, + String expectedReplacedSource, + String testName) { + this.checkDietParse( + source, + cursorLocation, + expectedCompletion, + null, + expectedUnitToString, + expectedCompletionIdentifier, + expectedReplacedSource, + testName); +} +/* + * DietParse with completionNode check + */ +public void checkDietParse( + char[] source, + int cursorLocation, + String expectedCompletion, + String expectedParentCompletion, + String expectedUnitToString, + String expectedCompletionIdentifier, + String expectedReplacedSource, + String testName) { + + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + CompletionParser parser = + new CompletionParser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory(Locale.getDefault())), + false); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration unit = parser.dietParse(sourceUnit, compilationResult, cursorLocation); + + checkParse( + expectedCompletion, + expectedParentCompletion, + expectedUnitToString, + expectedCompletionIdentifier, + expectedReplacedSource, + testName, + parser, + unit); +} +/* + * Parse a method with completionNode check + */ +public void checkMethodParse( + char[] source, + int cursorLocation, + String expectedCompletion, + String expectedParentCompletion, + String expectedUnitToString, + String expectedCompletionIdentifier, + String expectedReplacedSource, + String[] expectedLabels, + String testName) { + + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + CompletionParser parser = + new CompletionParser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory(Locale.getDefault())), + false); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration unit = parser.dietParse(sourceUnit, compilationResult, cursorLocation); + + ASTNode foundMethod = null; + if (unit.types != null) { + for (int i = 0; i < unit.types.length; i++) { + TypeDeclaration type = unit.types[i]; + ASTNode method = findMethod(type, cursorLocation); + if (method != null) { + foundMethod = method; + break; + } + } + } + + if (foundMethod != null) { + if (foundMethod instanceof AbstractMethodDeclaration) { + parser.parseBlockStatements((AbstractMethodDeclaration)foundMethod, unit); + } else { + TypeDeclaration type = (TypeDeclaration)foundMethod; + FieldDeclaration[] fields = type.fields; + if (fields != null) { + done : for (int i = 0; i < fields.length; i++) { + FieldDeclaration field = fields[i]; + if (field.declarationSourceStart <= cursorLocation && (cursorLocation <= field.declarationSourceEnd || field.declarationSourceEnd == 0)) { + if (field instanceof Initializer) { + parser.parseBlockStatements((Initializer)field, type, unit); + break; + } + break done; // field initializer + } + } + } + } + } + + checkParse( + expectedCompletion, + expectedParentCompletion, + expectedUnitToString, + expectedCompletionIdentifier, + expectedReplacedSource, + testName, + parser, + unit); +} +/* + * Parse a method with completionNode check + */ +public void checkMethodParse( + char[] source, + int cursorLocation, + String expectedCompletion, + String expectedUnitToString, + String expectedCompletionIdentifier, + String expectedReplacedSource, + String testName) { + + this.checkMethodParse( + source, + cursorLocation, + expectedCompletion, + null, + expectedUnitToString, + expectedCompletionIdentifier, + expectedReplacedSource, + null, + testName); +} +/* + * Parse a method with completionNode check + */ +public void checkMethodParse( + char[] source, + int cursorLocation, + String expectedCompletion, + String expectedParentCompletion, + String expectedUnitToString, + String expectedCompletionIdentifier, + String expectedReplacedSource, + String testName) { + + this.checkMethodParse( + source, + cursorLocation, + expectedCompletion, + expectedParentCompletion, + expectedUnitToString, + expectedCompletionIdentifier, + expectedReplacedSource, + null, + testName); +} +/* + * Parse a method with completionNode check + */ +public void checkMethodParse( + char[] source, + int cursorLocation, + String expectedCompletion, + String expectedUnitToString, + String expectedCompletionIdentifier, + String expectedReplacedSource, + String[] expectedLabels, + String testName) { + + this.checkMethodParse( + source, + cursorLocation, + expectedCompletion, + null, + expectedUnitToString, + expectedCompletionIdentifier, + expectedReplacedSource, + expectedLabels, + testName); +} +private void checkParse( + String expectedCompletion, + String expectedParentCompletion, + String expectedUnitToString, + String expectedCompletionIdentifier, + String expectedReplacedSource, + String testName, + CompletionParser parser, + CompilationUnitDeclaration unit) { + String computedCompletion = parser.assistNode == null + ? NONE + : parser.assistNode.toString(); + + String computedParentCompletion = NULL; + if (expectedParentCompletion != null) { + computedParentCompletion = parser.assistNodeParent == null + ? NONE + : parser.assistNodeParent.toString(); + } + + String computedUnitToString = unit.toString(); + //System.out.println(computedUnitToString); + //System.out.println(Util.displayString(computedUnitToString)); + //System.out.println(expectedUnitToString); + + if (!expectedCompletion.equals(computedCompletion)) { + System.out.println(Util.displayString(computedCompletion)); + } + + if(expectedParentCompletion != null) { + if (!expectedParentCompletion.equals(computedParentCompletion)) { + System.out.println(Util.displayString(computedParentCompletion)); + } + } + + if (!expectedUnitToString.equals(computedUnitToString)) { + System.out.println(Util.displayString(computedUnitToString)); + } + + String computedCompletionIdentifier = NULL; + if (expectedCompletionIdentifier != null){ + char[] chars = ((CompletionScanner)parser.scanner).completionIdentifier; + computedCompletionIdentifier = chars == null ? NONE : new String(chars); + } + + String computedReplacedSource = NULL; + if (expectedReplacedSource != null){ + char[] chars = null; + if (parser.assistNode != null){ + int start = parser.assistNode.sourceStart; + int end = parser.assistNode.sourceEnd; + if (parser.assistNode instanceof CompletionOnMemberAccess) { + CompletionOnMemberAccess memberAccess = (CompletionOnMemberAccess) parser.assistNode; + if (!(memberAccess.receiver instanceof ThisReference)) { + // for these CompletionEngine uses a more specific position: + long position = memberAccess.nameSourcePosition; + start = (int) (position >>> 32); + end = (int) position; + } + } + chars = CharOperation.subarray(parser.scanner.source, start, end + 1); + } else { + if (parser.assistIdentifier() != null){ + if (((CompletionScanner)parser.scanner).completedIdentifierEnd + >= ((CompletionScanner)parser.scanner).completedIdentifierStart){ + chars = CharOperation.subarray( + parser.scanner.source, + ((CompletionScanner)parser.scanner).completedIdentifierStart, + ((CompletionScanner)parser.scanner).completedIdentifierEnd + 1); + } + } + } + computedReplacedSource = chars == null ? NONE : new String(chars); + } + assertEquals( + testName, + concatResults( + expectedCompletion, + expectedParentCompletion, + expectedUnitToString, + expectedCompletionIdentifier, + expectedReplacedSource), + concatResults(computedCompletion, + computedParentCompletion, + computedUnitToString, + computedCompletionIdentifier, + computedReplacedSource)); +} +private String concatResults( + String completionNode, + String parentCompletionNode, + String unitToString, + String completionIdentifier, + String replacedSource) { + StringBuilder buffer = new StringBuilder(); + buffer.append("### Completion node ###\n"); + buffer.append(completionNode); + buffer.append("\n### Parent completion node ###\n"); + buffer.append(parentCompletionNode); + buffer.append("\n### Completed identifier ###\n"); + buffer.append(completionIdentifier); + buffer.append("\n### Replaced source ###\n"); + buffer.append(replacedSource); + buffer.append("\n### Completed unit ###\n"); + buffer.append(unitToString); + return buffer.toString(); +} +/* + * Returns the method, the constructor or the type declaring the initializer + * at the cursor location in the given type. + * Returns null if not found. + */ +private ASTNode findMethod(TypeDeclaration type, int cursorLocation) { + if (type.methods != null) { + for (int i = 0; i < type.methods.length; i++) { + AbstractMethodDeclaration method = type.methods[i]; + if (method.declarationSourceStart <= cursorLocation && (cursorLocation <= method.declarationSourceEnd || method.declarationSourceEnd == 0)) { + return method; + } + } + } + if (type.memberTypes != null) { + for (int i = 0; i < type.memberTypes.length; i++) { + TypeDeclaration memberType = type.memberTypes[i]; + ASTNode method = findMethod(memberType, cursorLocation); + if (method != null) { + return method; + } + } + } + FieldDeclaration[] fields = type.fields; + if (fields != null) { + for (int i = 0; i < fields.length; i++) { + FieldDeclaration field = fields[i]; + if (field instanceof Initializer && field.declarationSourceStart <= cursorLocation && (cursorLocation <= field.declarationSourceEnd || field.declarationSourceEnd == 0)) { + return type; + } + } + } + return null; +} +/** + * Runs the given test that checks that diet completion parsing returns the given completion. + */ +protected void runTestCheckDietParse( + String compilationUnit, + String completeBehind, + String expectedCompletionNodeToString, + String expectedUnitDisplayString, + String expectedCompletionIdentifier, + String expectedReplacedSource, + String testName) { + + int cursorLocation = compilationUnit.indexOf(completeBehind) + completeBehind.length() - 1; + this.checkDietParse( + compilationUnit.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedUnitDisplayString, + expectedCompletionIdentifier, + expectedReplacedSource, + testName); +} +/** + * Runs the given test that checks that method completion parsing returns the given completion. + */ +protected void runTestCheckMethodParse( + String compilationUnit, + String completeBehind, + String expectedCompletionNodeToString, + String expectedUnitDisplayString, + String expectedCompletionIdentifier, + String expectedReplacedSource, + String[] expectedLabels, + String testName) { + + int completeBehindStart = compilationUnit.indexOf(completeBehind); + assertTrue("completeBehind string not found", completeBehindStart >= 0); + int cursorLocation = completeBehindStart + completeBehind.length() - 1; + this.checkMethodParse( + compilationUnit.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedUnitDisplayString, + expectedCompletionIdentifier, + expectedReplacedSource, + expectedLabels, + testName); +} +/** + * Runs the given test that checks that method completion parsing returns the given completion. + */ +protected void runTestCheckMethodParse( + String compilationUnit, + String completeBehind, + String expectedCompletionNodeToString, + String expectedUnitDisplayString, + String expectedCompletionIdentifier, + String expectedReplacedSource, + String testName) { + + this.runTestCheckMethodParse( + compilationUnit, + completeBehind, + expectedCompletionNodeToString, + expectedUnitDisplayString, + expectedCompletionIdentifier, + expectedReplacedSource, + null, + testName); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSelectionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSelectionTest.java new file mode 100644 index 0000000000..94a796db91 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSelectionTest.java @@ -0,0 +1,335 @@ +/******************************************************************************* + * Copyright (c) 2000, 2011 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import java.util.Locale; + +import org.eclipse.jdt.internal.codeassist.select.SelectionParser; +import org.eclipse.jdt.internal.codeassist.select.SelectionScanner; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.ASTNode; +import org.eclipse.jdt.internal.compiler.ast.Block; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Initializer; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +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.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.Util; + +public abstract class AbstractSelectionTest extends AbstractCompilerTest { + + public final static String NONE = ""; +public AbstractSelectionTest(String testName){ + super(testName); +} +/* + * DietParse with selectionNode check + */ +public void checkDietParse( + char[] source, + int selectionStart, + int selectionEnd, + String expectedSelection, + String expectedUnitToString, + String expectedSelectionIdentifier, + String expectedSelectedSource, + String testName) { + + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + SelectionParser parser = + new SelectionParser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory(Locale.getDefault()))); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration unit = parser.dietParse(sourceUnit, compilationResult, selectionStart, selectionEnd); + + String computedUnitToString = unit.toString(); + //System.out.println(computedUnitToString); + //System.out.println(Util.displayString(computedUnitToString)); + //System.out.println(expectedUnitToString); + + String computedSelection = parser.assistNode == null + ? NONE + : parser.assistNode.toString(); + assertEquals( + "invalid selection node-" + testName, + expectedSelection, + computedSelection); + + if (!expectedUnitToString.equals(computedUnitToString)) { + System.out.println(Util.displayString(computedUnitToString, 2)); + } + assertEquals( + "invalid selection unit-" + testName, + expectedUnitToString, + computedUnitToString); + + if (expectedSelectionIdentifier != null){ + char[] chars = ((SelectionScanner)parser.scanner).selectionIdentifier; + String computedSelectionIdentifier = chars == null ? NONE : new String(chars); + assertEquals( + "invalid selection identifier-" + testName, + expectedSelectionIdentifier, + computedSelectionIdentifier); + } + if (expectedSelectedSource != null){ + char[] chars = null; + if (parser.assistNode != null){ + chars = CharOperation.subarray( + parser.scanner.source, + parser.assistNode.sourceStart, + parser.assistNode.sourceEnd + 1); + } else { + if (parser.assistIdentifier() != null){ + if (((SelectionScanner)parser.scanner).selectionEnd + >= ((SelectionScanner)parser.scanner).selectionStart){ + chars = CharOperation.subarray( + parser.scanner.source, + ((SelectionScanner)parser.scanner).selectionStart, + ((SelectionScanner)parser.scanner).selectionEnd + 1); + } + } + } + String computedSelectedSource = chars == null ? NONE : new String(chars); + assertEquals( + "invalid replaced source-" + testName, + expectedSelectedSource, + computedSelectedSource); + } +} +/* + * Parse a method with selectionNode check + */ +public void checkMethodParse( + char[] source, + int selectionStart, + int selectionEnd, + String expectedSelection, + String expectedUnitToString, + String expectedSelectionIdentifier, + String expectedSelectedSource, + String[] expectedLabels, + String testName) { + + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + SelectionParser parser = + new SelectionParser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory(Locale.getDefault()))); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration unit = parser.dietParse(sourceUnit, compilationResult, selectionStart, selectionEnd); + + ASTNode foundMethod = null; + if (unit.types != null) { + for (int i = 0; i < unit.types.length; i++) { + TypeDeclaration type = unit.types[i]; + ASTNode method = findMethod(type, selectionStart); + if (method != null) { + foundMethod = method; + break; + } + } + } + assertTrue("no method found at cursor location", foundMethod != null); + if (foundMethod instanceof AbstractMethodDeclaration) { + parser.parseBlockStatements((AbstractMethodDeclaration)foundMethod, unit); + } else { + TypeDeclaration type = (TypeDeclaration)foundMethod; + FieldDeclaration[] fields = type.fields; + if (fields != null) { + for (int i = 0; i < fields.length; i++) { + FieldDeclaration field = fields[i]; + if (field instanceof Initializer && field.sourceStart <= selectionStart && selectionStart <= field.sourceEnd) { + parser.parseBlockStatements((Initializer)field, type, unit); + break; + } + } + } + } + + String computedUnitToString = unit.toString(); + //System.out.println(computedUnitToString); + //System.out.println(expectedUnitToString); + + String computedCompletion = parser.assistNode == null + ? NONE + : parser.assistNode.toString(); + assertEquals( + "invalid selection node-" + testName, + expectedSelection, + computedCompletion); + + if (!expectedUnitToString.equals(computedUnitToString)) { + System.out.println(Util.displayString(computedUnitToString, 2)); + } + assertEquals( + "invalid selection unit-"+testName, + expectedUnitToString, + computedUnitToString); + + if (expectedSelectionIdentifier != null){ + char[] chars = ((SelectionScanner)parser.scanner).selectionIdentifier; + String computedSelectionIdentifier = chars == null ? NONE : new String(chars); + assertEquals( + "invalid selection identifier-" + testName, + expectedSelectionIdentifier, + computedSelectionIdentifier); + } + if (expectedSelectedSource != null){ + char[] chars = null; + if (parser.assistNode != null){ + chars = CharOperation.subarray( + parser.scanner.source, + parser.assistNode.sourceStart, + parser.assistNode.sourceEnd + 1); + } else { + if (parser.assistIdentifier() != null){ + if (((SelectionScanner)parser.scanner).selectionEnd + >= ((SelectionScanner)parser.scanner).selectionStart){ + chars = CharOperation.subarray( + parser.scanner.source, + ((SelectionScanner)parser.scanner).selectionStart, + ((SelectionScanner)parser.scanner).selectionEnd + 1); + } + } + } + String computedReplacedSource = chars == null ? NONE : new String(chars); + assertEquals( + "invalid replaced source-" + testName, + expectedSelectedSource, + computedReplacedSource); + } + if (expectedLabels != null) { +/* + assert("no labels-" + testName, parser.labels != null); + int length = parser.labels.length; + assertEquals("invalid number of labels-" + testName, expectedLabels.length, length); + for (int i = 0; i < length; i++) { + String label = new String(parser.labels[i]); + assertEquals("invalid label-" + testName, expectedLabels[i], label); + } +*/ + } +} +/* + * Parse a method with selectionNode check + */ +public void checkMethodParse( + char[] source, + int selectionStart, + int selectionEnd, + String expectedSelection, + String expectedUnitToString, + String expectedSelectionIdentifier, + String expectedSelectedSource, + String testName) { + + this.checkMethodParse( + source, + selectionStart, + selectionEnd, + expectedSelection, + expectedUnitToString, + expectedSelectionIdentifier, + expectedSelectedSource, + null, + testName); +} +/* + * Returns the method, the constructor or the type declaring the initializer + * at the cursor location in the given type. + * Returns null if not found. + */ +protected ASTNode findMethod(TypeDeclaration type, int cursorLocation) { + if (type.methods != null) { + for (int i = 0; i < type.methods.length; i++) { + AbstractMethodDeclaration method = type.methods[i]; + if (method.declarationSourceStart <= cursorLocation && (cursorLocation <= method.declarationSourceEnd || method.declarationSourceEnd == 0)) { + return method; + } + } + } + if (type.memberTypes != null) { + for (int i = 0; i < type.memberTypes.length; i++) { + TypeDeclaration memberType = type.memberTypes[i]; + ASTNode method = findMethod(memberType, cursorLocation); + if (method != null) { + return method; + } + } + } + FieldDeclaration[] fields = type.fields; + if (fields != null) { + for (int i = 0; i < fields.length; i++) { + FieldDeclaration field = fields[i]; + if (field instanceof Initializer) { + Initializer initializer = (Initializer)field; + Block block = initializer.block; + if (block != null && block.sourceStart <= cursorLocation && (cursorLocation <= block.sourceEnd || block.sourceEnd == 0)) { + return type; + } + } + } + } + return null; +} +/** + * Runs the given test that checks that method completion parsing returns the given completion. + */ +protected void runTestCheckMethodParse( + String compilationUnit, + String selectionStartBehind, + String selectionEndBehind, + String expectedSelectionNodeToString, + String expectedUnitDisplayString, + String expectedSelectionIdentifier, + String expectedReplacedSource, + String testName) { + + int selectionStartBehindStart = compilationUnit.indexOf(selectionStartBehind); + assertTrue("selectionStartBehind string not found", selectionStartBehindStart != -1); + int selectionStart = selectionStartBehindStart + selectionStartBehind.length(); + int selectionEndBehindStart = compilationUnit.indexOf(selectionEndBehind); + assertTrue("selectionEndBehind string not found", selectionEndBehindStart != -1); + int selectionEnd = selectionEndBehindStart + selectionEndBehind.length() - 1; + + this.checkMethodParse( + compilationUnit.toCharArray(), + selectionStart, + selectionEnd, + expectedSelectionNodeToString, + expectedUnitDisplayString, + expectedSelectionIdentifier, + expectedReplacedSource, + testName); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSyntaxTreeTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSyntaxTreeTest.java new file mode 100644 index 0000000000..c9cd046cee --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AbstractSyntaxTreeTest.java @@ -0,0 +1,489 @@ +/******************************************************************************* + * Copyright (c) 2012, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.Locale; + +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.codeassist.complete.CompletionParser; +import org.eclipse.jdt.internal.codeassist.select.SelectionParser; +import org.eclipse.jdt.internal.compiler.ASTVisitor; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; +import org.eclipse.jdt.internal.compiler.DocumentElementParser; +import org.eclipse.jdt.internal.compiler.IDocumentElementRequestor; +import org.eclipse.jdt.internal.compiler.ISourceElementRequestor; +import org.eclipse.jdt.internal.compiler.SourceElementParser; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.ImportReference; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.internal.core.search.indexing.IndexingParser; +import org.eclipse.jdt.internal.core.util.CommentRecorderParser; + +public class AbstractSyntaxTreeTest extends AbstractCompilerTest implements IDocumentElementRequestor, ISourceElementRequestor { + + protected static final int CHECK_PARSER = 0x1; + protected static final int CHECK_COMPLETION_PARSER = 0x2; + protected static final int CHECK_SELECTION_PARSER = 0x4; + protected static final int CHECK_DOCUMENT_ELEMENT_PARSER = 0x8; + protected static final int CHECK_COMMENT_RECORDER_PARSER = 0x10; + protected static final int CHECK_SOURCE_ELEMENT_PARSER = 0x20; + protected static final int CHECK_INDEXING_PARSER = 0x40; + protected static final int CHECK_JAVAC_PARSER = 0x80; + protected static int CHECK_ALL = (CHECK_PARSER | CHECK_COMPLETION_PARSER | CHECK_SELECTION_PARSER | + CHECK_DOCUMENT_ELEMENT_PARSER | CHECK_COMMENT_RECORDER_PARSER | + CHECK_SOURCE_ELEMENT_PARSER | CHECK_INDEXING_PARSER); + public static boolean optimizeStringLiterals = false; + private String referenceCompiler; + private String referenceCompilerTestsScratchArea; + + public AbstractSyntaxTreeTest(String name, String referenceCompiler, String referenceCompilerTestsScratchArea) { + super(name); + this.referenceCompiler = referenceCompiler; + this.referenceCompilerTestsScratchArea = referenceCompilerTestsScratchArea; + } + public void checkParse(int parserToCheck, char[] source, String expectedSyntaxErrorDiagnosis, + String testName, String expectedUnitToString, ASTVisitor visitor) throws IOException { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + options.complianceLevel = ClassFileConstants.JDK1_8; + options.sourceLevel = ClassFileConstants.JDK1_8; + options.targetJDK = ClassFileConstants.JDK1_8; + checkParse(parserToCheck, source, expectedSyntaxErrorDiagnosis, testName, expectedUnitToString, visitor, options); + } + public void checkParse(int parserToCheck, char[] source, String expectedSyntaxErrorDiagnosis, + String testName, String expectedUnitToString, ASTVisitor visitor, CompilerOptions options) throws IOException { + + ICompilationUnit sourceUnit = null; + CompilationResult compilationResult = null; + CompilationUnitDeclaration unit = null; + + if (this.referenceCompiler != null && (parserToCheck & CHECK_JAVAC_PARSER) != 0) { + String javaFilePath = this.referenceCompilerTestsScratchArea + "\\Xyz.java"; + File f = new File(javaFilePath); + FileOutputStream o = new FileOutputStream(f); + OutputStreamWriter w = new OutputStreamWriter(o); + w.write(source); + w.close(); + Process p = Runtime.getRuntime().exec (new String[] { this.referenceCompiler, "-sourcepath", this.referenceCompilerTestsScratchArea, javaFilePath }, null, new File(this.referenceCompilerTestsScratchArea)); + try { + BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); + BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream())); + String line; + while ((line = stderr.readLine())!= null) + System.out.println(line); + while ((line = stdout.readLine())!= null) + System.out.println(line); + assertTrue("javac unhappy", p.waitFor() == 0); + } catch (InterruptedException e) { + System.err.println("Skipped javac behavior check due to interrupt..."); + } + } + if ((parserToCheck & CHECK_PARSER) != 0) { + Parser parser1 = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory(Locale.getDefault())), + optimizeStringLiterals); + sourceUnit = new CompilationUnit(source, testName, null); + compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + unit = parser1.parse(sourceUnit, compilationResult); + parser1.getMethodBodies(unit); + assertDianosticEquals(expectedSyntaxErrorDiagnosis, testName, compilationResult); + assertParseTreeEquals(expectedUnitToString, unit.toString()); + if (visitor != null) { + unit.traverse(visitor, (CompilationUnitScope) null); + } + parser1 = null; + } + + if ((parserToCheck & CHECK_COMPLETION_PARSER) != 0) { + CompletionParser parser2 = new CompletionParser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory(Locale.getDefault())), + false); + compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + unit = parser2.parse(sourceUnit, compilationResult, Integer.MAX_VALUE); + parser2.getMethodBodies(unit); + assertDianosticEquals(expectedSyntaxErrorDiagnosis, testName, compilationResult); + assertParseTreeEquals(expectedUnitToString, unit.toString()); + parser2 = null; + } + if ((parserToCheck & CHECK_SELECTION_PARSER) != 0) { + SelectionParser parser3 = new SelectionParser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory(Locale.getDefault()))); + compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + unit = parser3.parse(sourceUnit, compilationResult, Integer.MAX_VALUE, Integer.MAX_VALUE); + parser3.getMethodBodies(unit); + assertDianosticEquals(expectedSyntaxErrorDiagnosis, testName, compilationResult); + assertParseTreeEquals(expectedUnitToString, unit.toString()); + parser3 = null; + } + if ((parserToCheck & CHECK_DOCUMENT_ELEMENT_PARSER) != 0) { + DocumentElementParser parser4 = new DocumentElementParser( + this, + new DefaultProblemFactory(Locale.getDefault()), + options); + compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + unit = parser4.parse(sourceUnit, compilationResult); + parser4.getMethodBodies(unit); + assertDianosticEquals(expectedSyntaxErrorDiagnosis, testName, compilationResult); + assertParseTreeEquals(expectedUnitToString, unit.toString()); + parser4 = null; + } + if ((parserToCheck & CHECK_COMMENT_RECORDER_PARSER) != 0) { + CommentRecorderParser parser5 = new CommentRecorderParser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory(Locale.getDefault())), + optimizeStringLiterals); + compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + unit = parser5.parse(sourceUnit, compilationResult); + parser5.getMethodBodies(unit); + assertDianosticEquals(expectedSyntaxErrorDiagnosis, testName, compilationResult); + assertParseTreeEquals(expectedUnitToString, unit.toString()); + parser5 = null; + } + if ((parserToCheck & CHECK_SOURCE_ELEMENT_PARSER) != 0) { + SourceElementParser parser6 = new SourceElementParser(this, + new DefaultProblemFactory(Locale.getDefault()), + options, + true, + optimizeStringLiterals); + compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + unit = parser6.parse(sourceUnit, compilationResult); + parser6.getMethodBodies(unit); + assertDianosticEquals(expectedSyntaxErrorDiagnosis, testName, compilationResult); + assertParseTreeEquals(expectedUnitToString, unit.toString()); + parser6 = null; + } + if ((parserToCheck & CHECK_INDEXING_PARSER) != 0) { + IndexingParser parser7 = new IndexingParser(this, + new DefaultProblemFactory(Locale.getDefault()), + options, + true, + optimizeStringLiterals, false); + compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + unit = parser7.parse(sourceUnit, compilationResult); + parser7.getMethodBodies(unit); + assertDianosticEquals(expectedSyntaxErrorDiagnosis, testName, compilationResult); + assertParseTreeEquals(expectedUnitToString, unit.toString()); + parser7 = null; + } + } + + public void checkParse(int parserToCheck, char[] source, String expectedSyntaxErrorDiagnosis, + String testName, String expectedUnitToString) throws IOException { + checkParse(parserToCheck, source, expectedSyntaxErrorDiagnosis, testName, expectedUnitToString, null); + } + + public void checkParse(char[] source, String expectedSyntaxErrorDiagnosis, String testName, String expectedUnitToString) + throws IOException { + checkParse(CHECK_ALL, source, expectedSyntaxErrorDiagnosis, testName, expectedUnitToString); + } + + public void checkParse(char[] source, String expectedSyntaxErrorDiagnosis, String testName, + String expectedUnitToString, ASTVisitor visitor) throws IOException { + checkParse(CHECK_ALL, source, expectedSyntaxErrorDiagnosis, testName, expectedUnitToString, visitor); + } + + private void assertParseTreeEquals(String expectedUnitToString, String computedUnitToString) { + if (expectedUnitToString == null) { // just checking that we are able to digest. + return; + } + if (!expectedUnitToString.equals(computedUnitToString)) { + System.out.println(Util.displayString(computedUnitToString)); + } + assertEquals("Parse Tree is wrong", + Util.convertToIndependantLineDelimiter(expectedUnitToString), + Util.convertToIndependantLineDelimiter(computedUnitToString)); + } + + private void assertDianosticEquals(String expectedSyntaxErrorDiagnosis, String testName, CompilationResult compilationResult) { + String computedSyntaxErrorDiagnosis = getCompilerMessages(compilationResult); + assertEquals( + "Invalid syntax error diagnosis" + testName, + Util.convertToIndependantLineDelimiter(expectedSyntaxErrorDiagnosis), + Util.convertToIndependantLineDelimiter(computedSyntaxErrorDiagnosis)); + } + + private String getCompilerMessages(CompilationResult compilationResult) { + StringBuilder buffer = new StringBuilder(100); + if (compilationResult.hasProblems() || compilationResult.hasTasks()) { + CategorizedProblem[] problems = compilationResult.getAllProblems(); + int count = problems.length; + int problemCount = 0; + char[] unitSource = compilationResult.compilationUnit.getContents(); + for (int i = 0; i < count; i++) { + if (problems[i] != null) { + if (problemCount == 0) + buffer.append("----------\n"); + problemCount++; + buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING")); + buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\')); + try { + buffer.append(((DefaultProblem)problems[i]).errorReportSource(unitSource)); + buffer.append("\n"); + buffer.append(problems[i].getMessage()); + buffer.append("\n"); + } catch (Exception e) { + } + buffer.append("----------\n"); + } + } + } + String computedSyntaxErrorDiagnosis = buffer.toString(); + return computedSyntaxErrorDiagnosis; + } + + public void acceptImport(int declarationStart, int declarationEnd, int[] javaDocPositions, + char[] name, int nameStartPosition, boolean onDemand, int modifiers) { + + + } + + public void acceptInitializer(int declarationStart, int declarationEnd, int[] javaDocPositions, + int modifiers, int modifiersStart, int bodyStart, int bodyEnd) { + + + } + + public void acceptLineSeparatorPositions(int[] positions) { + + + } + + public void acceptPackage(int declarationStart, int declarationEnd, int[] javaDocPositions, + char[] name, int nameStartPosition) { + + + } + + public void acceptProblem(CategorizedProblem problem) { + + + } + + public void enterClass(int declarationStart, int[] javaDocPositions, int modifiers, + int modifiersStart, int classStart, char[] name, int nameStart, int nameEnd, + char[] superclass, int superclassStart, int superclassEnd, char[][] superinterfaces, int[] superinterfaceStarts, + int[] superinterfaceEnds, int bodyStart) { + + + } + + public void enterCompilationUnit() { + + + } + + public void enterConstructor(int declarationStart, int[] javaDocPositions, int modifiers, + int modifiersStart, char[] name, int nameStart, int nameEnd, char[][] parameterTypes, + int[] parameterTypeStarts, int[] parameterTypeEnds, char[][] parameterNames, int[] parameterNameStarts, int[] parameterNameEnds, + int parametersEnd, char[][] exceptionTypes, int[] exceptionTypeStarts, int[] exceptionTypeEnds, int bodyStart) { + + + } + + public void enterField(int declarationStart, int[] javaDocPositions, int modifiers, + int modifiersStart, char[] type, int typeStart, int typeEnd, int typeDimensionCount, + char[] name, int nameStart, int nameEnd, int extendedTypeDimensionCount, int extendedTypeDimensionEnd) { + + + } + + public void enterInterface(int declarationStart, int[] javaDocPositions, int modifiers, + int modifiersStart, int interfaceStart, char[] name, int nameStart, int nameEnd, + char[][] superinterfaces, int[] superinterfaceStarts, int[] superinterfaceEnds, int bodyStart) { + + + } + + public void enterMethod(int declarationStart, int[] javaDocPositions, int modifiers, + int modifiersStart, char[] returnType, int returnTypeStart, int returnTypeEnd, int returnTypeDimensionCount, + char[] name, int nameStart, int nameEnd, char[][] parameterTypes, int[] parameterTypeStarts, + int[] parameterTypeEnds, char[][] parameterNames, int[] parameterNameStarts, int[] parameterNameEnds, int parametersEnd, + int extendedReturnTypeDimensionCount, int extendedReturnTypeDimensionEnd, char[][] exceptionTypes, int[] exceptionTypeStarts, int[] exceptionTypeEnds, + int bodyStart) { + + + } + + public void exitClass(int bodyEnd, int declarationEnd) { + + + } + + public void exitCompilationUnit(int declarationEnd) { + + + } + + public void exitConstructor(int bodyEnd, int declarationEnd) { + + + } + + public void exitField(int bodyEnd, int declarationEnd) { + + + } + + public void exitInterface(int bodyEnd, int declarationEnd) { + + + } + + public void exitMethod(int bodyEnd, int declarationEnd) { + + + } + + public void acceptAnnotationTypeReference(char[][] annotation, int sourceStart, + int sourceEnd) { + + + } + + public void acceptAnnotationTypeReference(char[] annotation, int sourcePosition) { + + + } + + public void acceptConstructorReference(char[] typeName, int argCount, + int sourcePosition) { + + + } + + public void acceptFieldReference(char[] fieldName, int sourcePosition) { + + + } + + public void acceptImport(int declarationStart, int declarationEnd, int nameStart, + int nameEnd, char[][] tokens, boolean onDemand, int modifiers) { + + + } + + public void acceptMethodReference(char[] methodName, int argCount, int sourcePosition) { + + + } + + public void acceptPackage(ImportReference importReference) { + + + } + + public void acceptTypeReference(char[][] typeName, int sourceStart, int sourceEnd) { + + + } + + public void acceptTypeReference(char[] typeName, int sourcePosition) { + + + } + + public void acceptUnknownReference(char[][] name, int sourceStart, int sourceEnd) { + + + } + + public void acceptUnknownReference(char[] name, int sourcePosition) { + + + } + + public void enterConstructor(MethodInfo methodInfo) { + + + } + + public void enterField(FieldInfo fieldInfo) { + + + } + + public void enterInitializer(int declarationStart, int modifiers) { + + + } + + public void enterMethod(MethodInfo methodInfo) { + + + } + + public void enterType(TypeInfo typeInfo) { + + + } + + public void exitConstructor(int declarationEnd) { + + + } + + public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd) { + + + } + + public void exitInitializer(int declarationEnd) { + + + } + + public void exitMethod(int declarationEnd, Expression defaultValue) { + + + } + + public void exitType(int declarationEnd) { + + + } + @Override + public void exitRecordComponent(int declarationEnd, int declarationSourceEnd) { + + } + +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AllocationExpressionCompletionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AllocationExpressionCompletionTest.java new file mode 100644 index 0000000000..847f7721ef --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AllocationExpressionCompletionTest.java @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import junit.framework.Test; + +/** + * Completion is expected to be an AllocationExpression. + */ +public class AllocationExpressionCompletionTest extends AbstractCompletionTest { +public AllocationExpressionCompletionTest(String testName) { + super(testName); +} +public static Test suite() { + return buildAllCompliancesTestSuite(AllocationExpressionCompletionTest.class); +} +/* + * Completion inside an if statement. + */ +public void testInIfStatement() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " void foo() { \n" + + " if (true) { \n" + + " new z.y.X(1, 2, i); \n" + + " } \n" + + " } \n" + + "}\n", + // completeBehind: + "X(1, 2,", + // expectedCompletionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " Bar() {\n" + + " }\n" + + " void foo() {\n" + + " {\n" + + " ;\n" + + " }\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "", + // expectedReplacedSource: + "", + // test name + "" + ); +} +/* + * Completion on a constructor invocation with no qualification and using a qualified type name. + * + * ie. ClassInstanceCreationExpression ::= 'new' ClassType '(' ArgumentListopt ')' ClassBodyopt + * where ClassType is a qualified type name + */ +public void testNoQualificationQualifiedTypeName() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " void foo() { \n" + + " new z.y.X(1, 2, i); \n" + + " } \n" + + "}\n", + // completeBehind: + "X(1, 2,", + // expectedCompletionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " Bar() {\n" + + " }\n" + + " void foo() {\n" + + " ;\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "", + // expectedReplacedSource: + "", + // test name + "" + ); +} +/* + * Completion on a constructor invocation with no qualification and using a simple type name. + * + * ie. ClassInstanceCreationExpression ::= 'new' ClassType '(' ArgumentListopt ')' ClassBodyopt + * where ClassType is a simple type name + */ +public void testNoQualificationSimpleTypeName() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " void foo() { \n" + + " new X(1, 2, i); \n" + + " } \n" + + "}\n", + // completeBehind: + "X(1, 2,", + // expectedCompletionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " Bar() {\n" + + " }\n" + + " void foo() {\n" + + " ;\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "", + // expectedReplacedSource: + "", + // test name + "" + ); +} +/* + * Completion on a constructor invocation qualified with a name. + * + * ie. ClassInstanceCreationExpression ::= ClassInstanceCreationExpressionName 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt + */ +public void testQualifiedWithName() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar {\n" + + " void foo() { \n" + + " Buz.x.new X(1, 2, i); \n" + + " } \n" + + "}\n", + // completeBehind: + "X(1, 2,", + // expectedCompletionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " Bar() {\n" + + " }\n" + + " void foo() {\n" + + " ;\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "", + // expectedReplacedSource: + "", + // test name + "" + ); +} +/* + * Completion on a constructor invocation qualified with a primary. + * + * ie. ClassInstanceCreationExpression ::= Primary '.' 'new' SimpleName '(' ArgumentListopt ')' ClassBodyopt + */ +public void testQualifiedWithPrimary() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " void foo() { \n" + + " primary().new X(1, 2, i); \n" + + " } \n" + + "}\n", + // completeBehind: + "X(1, 2,", + // expectedCompletionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " Bar() {\n" + + " }\n" + + " void foo() {\n" + + " ;\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "", + // expectedReplacedSource: + "", + // test name + "" + ); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AnnotationCompletionParserTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AnnotationCompletionParserTest.java new file mode 100644 index 0000000000..ab78e15829 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AnnotationCompletionParserTest.java @@ -0,0 +1,5147 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + + + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class AnnotationCompletionParserTest extends AbstractCompletionTest { +static { + //TESTS_NAMES= new String[]{"test0087"}; +} + +public AnnotationCompletionParserTest(String testName) { + super(testName); +} +public static Test suite() { + return buildAllCompliancesTestSuite(AnnotationCompletionParserTest.class); +} + +@Override +protected Map getCompilerOptions() { + Map options = super.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); + return options; +} + +public void test0001(){ + String str = + "public @MyAnn class X {\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "class X {\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0002(){ + String str = + "public @MyAnn interface X {\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "interface X {\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0003(){ + String str = + "public @MyAnn enum X {\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "enum X {\n" + + " X() {\n" + + " }\n" + + " () {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0004(){ + String str = + "public @MyAnn @interface X {\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "@interface X {\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0005(){ + String str = + "public @MyAnn class X\n" + + ""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "class X {\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0006(){ + String str = + "public @MyAnn interface X\n" + + ""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "interface X {\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0007(){ + String str = + "public @MyAnn enum X\n" + + ""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "enum X {\n" + + " X() {\n" + + " }\n" + + " () {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0008(){ + String str = + "public @MyAnn @interface X\n" + + ""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "@interface X {\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0009(){ + String str = + "public @MyAnn\n" + + ""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0010(){ + String str = + "public class X {\n" + + " public @MyAnn class Y {\n" + + " }\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " @\n" + + " class Y {\n" + + " Y() {\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0011(){ + String str = + "public class X {\n" + + " public @MyAnn class Y\n" + + ""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " @\n" + + " class Y {\n" + + " Y() {\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0012(){ + String str = + "public class X {\n" + + " public @MyAnn\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " @\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0013_Diet(){ + String str = + "public class X {\n" + + " public void foo() {\n" + + " @MyAnn class Y {\n" + + " }\n" + + " }\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0013_Method(){ + String str = + "public class X {\n" + + " public void foo() {\n" + + " @MyAnn class Y {\n" + + " }\n" + + " }\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public void foo() {\n" + + " @\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0014(){ + String str = + "public @MyAnn(ZORK) class X {\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "class X {\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0015(){ + String str = + "public @MyAnn(ZORK) class X\n" + + ""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "class X {\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0016(){ + String str = + "public @MyAnn(ZORK)\n" + + ""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0017(){ + String str = + "public @MyAnn(v1=\"\", v2=\"\") class X {\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "class X {\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0018(){ + String str = + "public @MyAnn(v1=\"\", v2=\"\")) class X\n" + + ""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n" + + "class X {\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0019(){ + String str = + "public @MyAnn(v1=\"\", v2=\"\")\n" + + ""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0020(){ + String str = + "public @MyAnn(v1=\"\""; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "@\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0021(){ + String str = + "public class X {\n" + + " @MyAnn void foo() {}\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " @\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0022(){ + String str = + "public class X {\n" + + " @MyAnn int var;\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " @\n" + + " int var;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0023(){ + String str = + "public class X {\n" + + " void foo(@MyAnn int i) {}\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " @\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0024_Diet(){ + String str = + "public class X {\n" + + " void foo() {@MyAnn int i}\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0024_Method(){ + String str = + "public class X {\n" + + " void foo() {@MyAnn int i}\n" + + "}"; + + + String completeBehind = "MyAnn"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "MyAnn"; + String expectedReplacedSource = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " @\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0025(){ + String str = + "@Annot(foo)\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot()\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0026(){ + String str = + "public class X {\n" + + " @Annot(foo)\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0027(){ + String str = + "public class X {\n" + + " @Annot(foo)\n" + + " int var;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " int var;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0028_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(foo)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0028_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(foo)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot()\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0029_Diet(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(foo) int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0029_Method(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(foo) int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " @Annot()\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0030(){ + String str = + "public class X {\n" + + " @Annot(foo)\n" + + " X() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0031(){ + String str = + "@Annot(foo\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot()\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0032(){ + String str = + "public class X {\n" + + " @Annot(foo\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0033(){ + String str = + "public class X {\n" + + " @Annot(foo\n" + + " int var;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " int var;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0034_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(foo\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0034_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(foo\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot()\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0035_Diet(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(foo int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0035_Method(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(foo int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " @Annot()\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0036(){ + String str = + "public class X {\n" + + " @Annot(foo\n" + + " X() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0037(){ + String str = + "@Annot(foo=zzz)\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot()\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0038(){ + String str = + "public class X {\n" + + " @Annot(foo=zzz)\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0039(){ + String str = + "public class X {\n" + + " @Annot(foo=zzz)\n" + + " int var;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " int var;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0040_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(foo=zzz)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0040_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(foo=zzz)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot()\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0041_Diet(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(foo=zzz) int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0041_Method(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(foo=zzz) int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " @Annot()\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0042(){ + String str = + "public class X {\n" + + " @Annot(foo=zzz)\n" + + " X() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0043(){ + String str = + "@Annot(foo=zzz\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot()\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0044(){ + String str = + "public class X {\n" + + " @Annot(foo=zzz\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0045(){ + String str = + "public class X {\n" + + " @Annot(foo=zzz\n" + + " int var;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " int var;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0046_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(foo=zzz\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0046_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(foo=zzz\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot()\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0047_Diet(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(foo=zzz int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0047_Method(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(foo=zzz int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " @Annot()\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0048(){ + String str = + "public class X {\n" + + " @Annot(foo=zzz\n" + + " X() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot()"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot()\n" + + " public X() {\n" + + " }\n" + + " zzz X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0049(){ + String str = + "@Annot(yyy=zzz,foo)\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(yyy = zzz,)\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0050(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo)\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0051(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo)\n" + + " int var;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " int var;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0052_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(yyy=zzz,foo)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0052_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(yyy=zzz,foo)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(yyy = zzz,)\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0053_Diet(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(yyy=zzz,foo) int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0053_Method(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(yyy=zzz,foo) int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " @Annot(yyy = zzz,)\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0054(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo)\n" + + " X() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0055(){ + String str = + "@Annot(yyy=zzz,foo\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(yyy = zzz,)\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0056(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0057(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo\n" + + " int var;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " int var;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0058_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(yyy=zzz,foo\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0058_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(yyy=zzz,foo\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(yyy = zzz,)\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0059_Diet(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(yyy=zzz,foo int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0059_Method(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(yyy=zzz,foo int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " @Annot(yyy = zzz,)\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0060(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo\n" + + " X() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0061(){ + String str = + "@Annot(yyy=zzz,foo=zzz)\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(yyy = zzz,)\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0062(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo=zzz)\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0063(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo=zzz)\n" + + " int var;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " int var;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0064_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(yyy=zzz,foo=zzz)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0064_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(yyy=zzz,foo=zzz)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(yyy = zzz,)\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0065_Diet(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(yyy=zzz,foo=zzz) int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0065_Method(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(yyy=zzz,foo=zzz) int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " @Annot(yyy = zzz,)\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0066(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo=zzz)\n" + + " X() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0067(){ + String str = + "@Annot(yyy=zzz,foo=zzz\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(yyy = zzz,)\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0068(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo=zzz\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0069(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo=zzz\n" + + " int var;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " int var;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0070_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(yyy=zzz,foo=zzz\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0070_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(yyy=zzz,foo=zzz\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(yyy = zzz,)\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0071_Diet(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(yyy=zzz,foo=zzz int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0071_Method(){ + String str = + "public class X {\n" + + " void bar(int var1, @Annot(yyy=zzz,foo=zzz int var2) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(int var1) {\n" + + " @Annot(yyy = zzz,)\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0072(){ + String str = + "public class X {\n" + + " @Annot(yyy=zzz,foo=zzz\n" + + " X() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(yyy = zzz,)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(yyy = zzz,)\n" + + " public X() {\n" + + " }\n" + + " zzz X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0073(){ + String str = + "@Annot(zzz=yyy,f)\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "f"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(zzz = yyy,)"; + String completionIdentifier = "f"; + String expectedReplacedSource = "f"; + String expectedUnitDisplayString = + "@Annot(zzz = yyy,)\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0074(){ + String str = + "@Annot(zzz=foo)\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public @Annot(zzz = ) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0075(){ + String str = + "@Annot(zzz= a && foo)\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public @Annot(zzz = (a && )) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0076(){ + String str = + "@Annot(zzz= {foo})\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(zzz = {})\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0078(){ + String str = + "@Annot(zzz= {yyy, foo})\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(zzz = {})\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0079(){ + String str = + "@Annot(zzz=foo\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(zzz = )\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0080(){ + String str = + "@Annot(zzz= a && foo\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(zzz = (a && ))\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0081(){ + String str = + "@Annot(zzz= {yyy, foo}\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(zzz = {})\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0082(){ + String str = + "@Annot(zzz= {yyy, foo\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(zzz = {})\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0083(){ + String str = + "@Annot(zzz= a && (b || (foo && c)))\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "( && c)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public @Annot(zzz = (a && (b || ( && c)))) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0084(){ + String str = + "@Annot(zzz= a && (b || (foo\n" + + "public class X {\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(zzz = )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "@Annot(zzz = )\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0085(){ + String str = + "public class X {\n" + + " @Annot(zzz=foo)\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " @Annot(zzz = ) void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0086(){ + String str = + "public class X {\n" + + " @Annot(zzz= a && foo)\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " @Annot(zzz = (a && )) void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0087(){ + String str = + "public class X {\n" + + " @Annot(zzz= {foo})\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = {})\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0088(){ + String str = + "public class X {\n" + + " @Annot(zzz= {yyy, foo})\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = {})\n"+ + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0089(){ + String str = + "public class X {\n" + + " @Annot(zzz=foo\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = )\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0090(){ + String str = + "public class X {\n" + + " @Annot(zzz= a && foo\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = (a && ))\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0091(){ + String str = + "public class X {\n" + + " @Annot(zzz= {yyy, foo}\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = {})\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0092(){ + String str = + "public class X {\n" + + " @Annot(zzz= {yyy, foo\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = {})\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0093(){ + String str = + "public class X {\n" + + " @Annot(zzz= a && (b || (foo && c)))\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "( && c)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " @Annot(zzz = (a && (b || ( && c)))) void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0094(){ + String str = + "public class X {\n" + + " @Annot(zzz= a && (b || (foo\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(zzz = )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = )\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0095(){ + String str = + "public class X {\n" + + " @Annot(zzz=foo)\n" + + " int bar;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = ) int bar;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0096(){ + String str = + "public class X {\n" + + " @Annot(zzz= a && foo)\n" + + " int bar;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = (a && )) int bar;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0097(){ + String str = + "public class X {\n" + + " @Annot(zzz= {foo})\n" + + " int bar;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = {})\n" + + " int bar;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0098(){ + String str = + "public class X {\n" + + " @Annot(zzz= {yyy, foo})\n" + + " int bar;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = {})\n" + + " int bar;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0099(){ + String str = + "public class X {\n" + + " @Annot(zzz=foo\n" + + " int bar;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = )\n" + + " int bar;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0100(){ + String str = + "public class X {\n" + + " @Annot(zzz= a && foo\n" + + " int bar;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = (a && ))\n" + + " int bar;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0101(){ + String str = + "public class X {\n" + + " @Annot(zzz= {yyy, foo}\n" + + " int bar;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = {})\n" + + " int bar;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0102(){ + String str = + "public class X {\n" + + " @Annot(zzz= {yyy, foo\n" + + " int bar;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = {})\n" + + " int bar;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0103(){ + String str = + "public class X {\n" + + " @Annot(zzz= a && (b || (foo && c)))\n" + + " int bar;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "( && c)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = (a && (b || ( && c)))) int bar;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0104(){ + String str = + "public class X {\n" + + " @Annot(zzz= a && (b || (foo\n" + + " int bar;\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(zzz = )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " @Annot(zzz = )\n" + + " int bar;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0105_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz=foo)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0105_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz=foo)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = )\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0106_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= a && foo)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0106_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= a && foo)\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = (a && ))\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0107_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= {foo})\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0107_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= {foo})\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = {})\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0108_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= {yyy, foo})\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0108_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= {yyy, foo})\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = {})\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0109_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz=foo\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0109_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz=foo\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = )\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0110_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " int var;\n" + + " @Annot(zzz= a && foo\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0110_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " int var;\n" + + " @Annot(zzz= a && foo\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " int var;\n" + + " @Annot(zzz = (a && ))\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0111_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= {yyy, foo}\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0111_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= {yyy, foo}\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = {})\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0112_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= {yyy, foo\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0112_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= {yyy, foo\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = {})\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0113_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= a && (b || (foo && c)))\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0113_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= a && (b || (foo && c)))\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(zzz = )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = )\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0114_Diet(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= a && (b || (foo\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = ""; + String expectedReplacedSource = ""; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0114_Method(){ + String str = + "public class X {\n" + + " void bar() {\n" + + " @Annot(zzz= a && (b || (foo\n" + + " int var;\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(zzz = )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = )\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0115(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz=foo) int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(@Annot(zzz = ) int var) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0116(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz= a && foo) int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(@Annot(zzz = (a && )) int var) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0117(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz= {foo}) int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0118(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz= {yyy, foo}) int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0119_Diet(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz=foo int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0119_Method(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz=foo int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "zzz = "; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = )\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0120_Diet(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz= a && foo int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0120_Method(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz= a && foo int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "(a && )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " @Annot(zzz = (a && ))\n" + + " }\n" + + "}\n"; + + checkMethodParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "full ast"); +} +public void test0121(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz= {yyy, foo} int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0122(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz= {yyy, foo int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0123(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz= a && (b || (foo && c))) int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "( && c)"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar(@Annot(zzz = (a && (b || ( && c)))) int var) {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0124(){ + String str = + "public class X {\n" + + " void bar(@Annot(zzz= a && (b || (foo int var) {\n" + + " }\n" + + "}"; + + + String completeBehind = "foo"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = "@Annot(zzz = )"; + String completionIdentifier = "foo"; + String expectedReplacedSource = "foo"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=148742 +public void test0125(){ + String str = + "public interface X {\n" + + " public void test(@TestAnnotation int testParam);\n" + + "}"; + + + String completeBehind = "@TestAnnotation"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "TestAnnotation"; + String expectedReplacedSource = "TestAnnotation"; + String expectedUnitDisplayString = + "public interface X {\n" + + " @\n" + + " public void test() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148742 +public void test0126(){ + String str = + "public abstract class X {\n" + + " public abstract void test(@TestAnnotation int testParam);\n" + + "}"; + + + String completeBehind = "@TestAnnotation"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = "@"; + String expectedParentNodeToString = ""; + String completionIdentifier = "TestAnnotation"; + String expectedReplacedSource = "TestAnnotation"; + String expectedUnitDisplayString = + "public abstract class X {\n" + + " @\n" + + " public X() {\n" + + " }\n" + + " public abstract void test();\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0127(){ + String str = + "public class Test {\n" + + " public static final int zzint = 0;\n" + + " @ZZAnnotation({ZZ})\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "{ZZ"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "ZZ"; + String expectedReplacedSource = "ZZ"; + String expectedUnitDisplayString = + "public class Test {\n" + + " @ZZAnnotation(value = {})\n" + + " public static final int zzint;\n" + + " public Test() {\n" + + " }\n" + + " () {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0128(){ + String str = + "public class Test {\n" + + " public static final int zzint = 0;\n" + + " @ZZAnnotation(value={ZZ})\n" + + " void bar() {\n" + + " }\n" + + "}"; + + + String completeBehind = "{ZZ"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "ZZ"; + String expectedReplacedSource = "ZZ"; + String expectedUnitDisplayString = + "public class Test {\n" + + " @ZZAnnotation(value = {})\n" + + " public static final int zzint;\n" + + " public Test() {\n" + + " }\n" + + " () {\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +public void test0129(){ + String str = + "public class Test {\n" + + " public static final int zzint = 0;\n" + + " @ZZAnnotation({ZZ\n" + + "}"; + + + String completeBehind = "{ZZ"; + int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1; + String expectedCompletionNodeToString = ""; + String expectedParentNodeToString = ""; + String completionIdentifier = "ZZ"; + String expectedReplacedSource = "ZZ"; + String expectedUnitDisplayString = + "public class Test {\n" + + " @ZZAnnotation(value = {})\n" + + " public static final int zzint;\n" + + " public Test() {\n" + + " }\n" + + " () {\n" + + " }\n" + + "}\n"; + + checkDietParse( + str.toCharArray(), + cursorLocation, + expectedCompletionNodeToString, + expectedParentNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + "diet ast"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AnnotationDietRecoveryTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AnnotationDietRecoveryTest.java new file mode 100644 index 0000000000..40589f6b45 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AnnotationDietRecoveryTest.java @@ -0,0 +1,1972 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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.codeassist.complete.CompletionParser; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; +import org.eclipse.jdt.internal.compiler.SourceElementParser; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +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; + +// This test suite test the first implementation of the annotation recovery. +// Tests must be updated with annotation recovery improvment +// TODO(david) update test suite +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class AnnotationDietRecoveryTest extends AbstractCompilerTest { + private static final boolean CHECK_ALL_PARSE = true; + public static boolean optimizeStringLiterals = false; + public static long sourceLevel = ClassFileConstants.JDK1_3; //$NON-NLS-1$ + +public AnnotationDietRecoveryTest(String testName){ + super(testName); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); +} +public static Class testClass() { + return AnnotationDietRecoveryTest.class; +} +/* + * Toggle compiler in mode -1.5 + */ +@Override +protected Map getCompilerOptions() { + Map options = super.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); + return options; +} + +public void checkParse( + char[] source, + String expectedDietUnitToString, + String expectedDietPlusBodyUnitToString, + String expectedFullUnitToString, + String expectedCompletionDietUnitToString, + String testName) { + + /* using regular parser in DIET mode */ + if (CHECK_ALL_PARSE){ + Parser parser = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault())), + optimizeStringLiterals); + + 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 + getMethodBodies */ + { + Parser parser = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault())), + optimizeStringLiterals); + + 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 FULL mode */ + if (CHECK_ALL_PARSE){ + Parser parser = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault())), + optimizeStringLiterals); + + 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 source element parser in DIET mode */ + if (CHECK_ALL_PARSE){ + SourceElementParser parser = + new SourceElementParser( + new TestSourceElementRequestor(), + new DefaultProblemFactory(Locale.getDefault()), + new CompilerOptions(getCompilerOptions()), + false/*don't record local declarations*/, + true/*optimize string literals*/); + + 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 source element diet structure" + testName, + expectedDietUnitToString, + computedUnitToString); + } + /* using source element parser in FULL mode */ + if (CHECK_ALL_PARSE){ + SourceElementParser parser = + new SourceElementParser( + new TestSourceElementRequestor(), + new DefaultProblemFactory(Locale.getDefault()), + new CompilerOptions(getCompilerOptions()), + false/*don't record local declarations*/, + true/*optimize string literals*/); + + 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 source element full structure" + testName, + expectedFullUnitToString, + computedUnitToString); + } + /* using completion parser in DIET mode */ + if (CHECK_ALL_PARSE){ + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + CompletionParser parser = + new CompletionParser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory(Locale.getDefault())), + false); + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, Integer.MAX_VALUE); + String computedUnitToString = computedUnit.toString(); + if (!expectedCompletionDietUnitToString.equals(computedUnitToString)){ + System.out.println(Util.displayString(computedUnitToString)); + } + assertEquals( + "Invalid completion diet structure" + testName, + expectedCompletionDietUnitToString, + computedUnitToString); + } +} + +public void test0001() { + + String s = + "package a; \n" + + "public @interface X \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @interface X {\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + expectedDietUnitToString; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +public void test0002() { + + String s = + "package a; \n" + + "public @interface X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @interface X {\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + expectedDietUnitToString; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +public void test0003() { + + String s = + "package a; \n" + + "public @interface X { \n" + + " String foo() \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @interface X {\n" + + " String foo() {\n" + +" }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + expectedDietUnitToString; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +public void test0004() { + + String s = + "package a; \n" + + "public @interface X { \n" + + " String foo() default \"blabla\" \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @interface X {\n" + + " String foo() default \"blabla\" {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + expectedDietUnitToString; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=79770 + */ +public void test0005() { + + String s = + "@Documented \n" + + "@Rentention(RententionPolicy.RUNTIME) \n" + + "@Target(ElementType.TYPE) \n" + + "@interface MyAnn { \n" + + " String value() default \"Default Message\" \n" + + "} \n" + + "public class X { \n" + + " public @MyAnn void something() { } \n" + + "} \n"; + + String expectedDietUnitToString = + "@Documented @Rentention(RententionPolicy.RUNTIME) @Target(ElementType.TYPE) @interface MyAnn {\n" + + " String value() default \"Default Message\" {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public @MyAnn void something() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "@Documented @Rentention(RententionPolicy.RUNTIME) @Target(ElementType.TYPE) @interface MyAnn {\n" + + " String value() default \"Default Message\" {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public @MyAnn void something() {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +public void test0006() { + + String s = + "package a; \n" + + "public @interface X { \n" + + " String foo() {} \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @interface X {\n" + + " String foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + expectedDietUnitToString; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +public void test0007() { + + String s = + "package a; \n" + + "public @interface X { \n" + + " String foo( \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @interface X {\n" + + " String foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + expectedDietUnitToString; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +public void test0008() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo(int var1, @Annot(at1=zzz, at2) int var2 { \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo(int var1) {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo(int var1) {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +public void test0009() { + + String s = + "package a; \n" + + "public class X { \n" + + " @SuppressWarnings(\"unchecked\");\n" + + " List l; \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " @SuppressWarnings(\"unchecked\") List l;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " @SuppressWarnings(\"unchecked\") List l;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " List l;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +public void test0010() { + + String s = + "package a; \n" + + "public class X { \n" + + " String foo() { \n" + + " @interface Y { \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " @interface Y {\n" + + " }\n" + + " public X() {\n" + + " }\n" + + " String foo() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " @interface Y {\n" + + " }\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " String foo() {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=176725 +public void test0011() { + + String s = + "package a; \n" + + "public class X { \n" + + " # \n" + + " @AnAnnotation({var}) \n" + + " public void foo() { \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public @AnAnnotation({var}) void foo() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public @AnAnnotation({var}) void foo() {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=210404 +public void test0012() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo(int var1, @Annot(at1=zzz, at2=@Annot(at3=zzz, at4)) int var2 { \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo(int var1) {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo(int var1) {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0013() { + + String s = + "package a; \n" + + "@AnAnnotation(name) \n" + + "@AnAnnotation2(name2) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietPlusBodyUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0014() { + + String s = + "package a; \n" + + "# \n" + + "@AnAnnotation(name) \n" + + "@AnAnnotation2(name2) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0015() { + + String s = + "package a; \n" + + "@AnAnnotation(name) \n" + + "@AnAnnotation2(name2) \n" + + "public class X { \n" + + "# \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0016() { + + String s = + "package a; \n" + + "@AnAnnotation(name) \n" + + "@AnAnnotation2(name2) \n" + + "# \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0017() { + + String s = + "package a; \n" + + "@AnAnnotation(name) \n" + + "# \n" + + "@AnAnnotation2(name2) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0018() { + + String s = + "package a; \n" + + "@AnAnnotation(name=) \n" + + "@AnAnnotation2(name2) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation(name = $missing$) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation(name = $missing$) @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public @AnAnnotation2(name2) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0019() { + + String s = + "package a; \n" + + "@AnAnnotation(name) \n" + + "@AnAnnotation2(name2=) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2 = $missing$) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation(name) @AnAnnotation2(name2 = $missing$) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0020() { + + String s = + "package a; \n" + + "public class X { \n" + + " @AnAnnotation(name) # \n" + + " int field; \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " @AnAnnotation(name) int field;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " @AnAnnotation(name) int field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " int field;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0021() { + + String s = + "package a; \n" + + "public class X { \n" + + " @AnAnnotation(name=) \n" + + " int field; \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " @AnAnnotation(name = $missing$) int field;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " @AnAnnotation(name = $missing$) int field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " int field;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0022() { + + String s = + "package a; \n" + + "public class X { \n" + + " @AnAnnotation(name) # \n" + + " void foo() {} \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " @AnAnnotation(name) void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " @AnAnnotation(name) void foo() {\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0023() { + + String s = + "package a; \n" + + "public class X { \n" + + " @AnAnnotation(name=) \n" + + " void foo() {} \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " @AnAnnotation(name = $missing$) void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " @AnAnnotation(name = $missing$) void foo() {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0024() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo(int param1, @AnAnnotation(name) # int param2) {} \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo(int param1) {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo(int param1) {\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0025() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo(int param1, @AnAnnotation(name=) int param2) {} \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo(int param1) {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo(int param1) {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0026() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo(int param1, @AnAnnotation(@AnAnnotation1(name1=\"a\", name2=) int param2) {} \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo(int param1) {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo(int param1) {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0027() { + + String s = + "package a; \n" + + "@AnAnnotation1(name1=\"a\", #) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation1(name1 = \"a\") class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation1(name1 = \"a\") class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0028() { + + String s = + "package a; \n" + + "@AnAnnotation1(name1=\"a\", name2=@AnAnnotation2(name3=\"b\"), #) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation1(name1 = \"a\",name2 = @AnAnnotation2(name3 = \"b\")) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation1(name1 = \"a\",name2 = @AnAnnotation2(name3 = \"b\")) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0030() { + + String s = + "package a; \n" + + "@AnAnnotation1(\"a\"#) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation1(\"a\") class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation1(\"a\") class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0031() { + + String s = + "package a; \n" + + "@AnAnnotation1(\"a\", name2=@AnAnnotation2(name3=\"b\"), #) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation1(\"a\") @AnAnnotation2(name3 = \"b\") class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation1(\"a\") @AnAnnotation2(name3 = \"b\") class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0032() { + + String s = + "package a; \n" + + "@AnAnnotation1(\"a\", name2=@AnAnnotation2(name3=\"b\")) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation1(\"a\") @AnAnnotation2(name3 = \"b\") class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation1(\"a\") @AnAnnotation2(name3 = \"b\") class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0033() { + + String s = + "package a; \n" + + "@AnAnnotation1(name=new Object() {}) # \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation1(name = new Object() {\n" + + "}) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation1(name = new Object() {\n" + + "}) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0034() { + + String s = + "package a; \n" + + "@AnAnnotation1(name=new Object() {},#) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation1(name = new Object() {\n" + + "}) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation1(name = new Object() {\n" + + "}) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0035() { + + String s = + "package a; \n" + + "@AnAnnotation1(name=new Object() {#}) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation1(name = $missing$) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation1(name = $missing$) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227855 +public void test0036() { + + String s = + "package a; \n" + + "# \n" + + "public class Test { \n" + + " public Test() {} \n" + + " @SuppressWarnings(value=\"\") \n" + + " private int id; \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class Test {\n" + + " private @SuppressWarnings(value = \"\") int id;\n" + + " public Test() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class Test {\n" + + " private @SuppressWarnings(value = \"\") int id;\n" + + " public Test() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class Test {\n" + + " private @SuppressWarnings(value = \"\") int id;\n" + + " public Test() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227855 +public void test0037() { + + String s = + "package a; \n" + + "# \n" + + "public class Test { \n" + + " public int id0; \n" + + " @SuppressWarnings(value=\"\") \n" + + " private int id; \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class Test {\n" + + " public int id0;\n" + + " private @SuppressWarnings(value = \"\") int id;\n" + + " public Test() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class Test {\n" + + " public int id0;\n" + + " private @SuppressWarnings(value = \"\") int id;\n" + + " public Test() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class Test {\n" + + " public int id0;\n" + + " private @SuppressWarnings(value = \"\") int id;\n" + + " public Test() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228464 +public void test0038() { + + String s = + "package a; \n" + + "@AnAnnotation(name=) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation(name = $missing$) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation(name = $missing$) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228464 +public void test0039() { + + String s = + "package a; \n" + + "@AnAnnotation(name1=a,name2=) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation(name1 = a,name2 = $missing$) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation(name1 = a,name2 = $missing$) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228464 +public void test0040() { + + String s = + "package a; \n" + + "@AnAnnotation(name1=a,name2=,name3=c) \n" + + "public class X { \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public @AnAnnotation(name1 = a,name2 = $missing$) class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public @AnAnnotation(name1 = a,name2 = $missing$) class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=366003 +public void test0041() { + + String s = + "package snippet;\n" + + "public class Bug366003 {\n" + + " void foo(Object o1){}\n" + + " @Blah org.User(@Bla String str){}\n" + + "}\n"; + + String expectedDietUnitToString = + "package snippet;\n" + + "public class Bug366003 {\n" + + " public Bug366003() {\n" + + " }\n" + + " void foo(Object o1) {\n" + + " }\n" + + " @Blah User(@Bla String str) {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "package snippet;\n" + + "public class Bug366003 {\n" + + " public Bug366003() {\n" + + " super();\n" + + " }\n" + + " void foo(Object o1) {\n" + + " }\n" + + " @Blah User(@Bla String str) {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = expectedDietUnitToString; + + String expectedCompletionDietUnitToString = + "package snippet;\n" + + "public class Bug366003 {\n" + + " public Bug366003() {\n" + + " }\n" + + " void foo(Object o1) {\n" + + " }\n" + + " User(@Bla String str) {\n" + + " }\n" + + "}\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, + testName); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AnnotationSelectionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AnnotationSelectionTest.java new file mode 100644 index 0000000000..f2d45adae6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/AnnotationSelectionTest.java @@ -0,0 +1,645 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +public class AnnotationSelectionTest extends AbstractSelectionTest { +public AnnotationSelectionTest(String testName) { + super(testName); +} +/* + * Selection at specific location + */ +public void test0001() { + + String str = + "public @MyAnn class X { \n" + + "} \n"; + + String selection = "MyAnn"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "MyAnn"; + String expectedUnitDisplayString = + "public @ class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "MyAnn"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0003() { + + String str = + "public @MyAnn.ZZ class X { \n" + + "} \n"; + + String selection = "ZZ"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "ZZ"; + String expectedUnitDisplayString = + "public @ class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "MyAnn.ZZ"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +//TODO enable this test when selection parser support this test case +public void _test0005() { + + String str = + "public @MyAnn.ZZ" + + " \n"; + + String selection = "ZZ"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "ZZ"; + String expectedUnitDisplayString = + "public @ class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "MyAnn.ZZ"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0007() { + + String str = + "public class X {" + + " public @MyAnn void foo(" + + " " + + "} \n"; + + String selection = "MyAnn"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public @ void foo() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "MyAnn"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0009() { + + String str = + "public class X {" + + " public @MyAnn Object var" + + "} \n"; + + String selection = "MyAnn"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " public @ Object var;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "MyAnn"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0011() { + + String str = + "public class X {" + + " public @MyAnn class Y {" + + " }" + + "} \n"; + + String selection = "MyAnn"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "MyAnn"; + String expectedUnitDisplayString = + "public class X {\n" + + " public @ class Y {\n" + + " public Y() {\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "MyAnn"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0013() { + + String str = + "public @MyAnn() class X {" + + "} \n"; + + String selection = "MyAnn"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "MyAnn"; + String expectedUnitDisplayString = + "public @() class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "MyAnn"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0015() { + + String str = + "public @MyAnn(value = \"\") class X {" + + "} \n"; + + String selection = "MyAnn"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "MyAnn"; + String expectedUnitDisplayString = + "public @(value = \"\") class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "MyAnn"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0017() { + + String str = + "public @MyAnn(value1 = \"\", value2 = \"\") class X {" + + "} \n"; + + String selection = "value1"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "value1"; + String expectedUnitDisplayString = + "public @MyAnn(,value2 = \"\") class X {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "value1"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ExplicitConstructorInvocationCompletionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ExplicitConstructorInvocationCompletionTest.java new file mode 100644 index 0000000000..c0a0849653 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ExplicitConstructorInvocationCompletionTest.java @@ -0,0 +1,388 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import junit.framework.Test; + +/** + * Completion is expected to be an ExplicitConstructorInvocation + * or inside an ExplicitConstructorInvocation + */ +public class ExplicitConstructorInvocationCompletionTest extends AbstractCompletionTest { +public ExplicitConstructorInvocationCompletionTest(String testName) { + super(testName); +} +public static Test suite() { + return buildAllCompliancesTestSuite(ExplicitConstructorInvocationCompletionTest.class); +} +/* + * Completion on a qualified 'super' constructor invocation. + * + * ie. ExplicitConstructorInvocation ::= Primary '.' 'super' '(' ArgumentListopt ')' ';' + */ +public void testPrimarySuper() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " static Bar x; \n" + + " public class InnerBar { \n" + + " InnerBar(Bar x) { \n" + + " } \n" + + " } \n" + + " public class SubInnerBar extends InnerBar { \n" + + " SubInnerBar(Bar x) { \n" + + " primary().super(1, 2, i); \n" + + " } \n" + + " } \n" + + "} \n", + // completeBehind: + "super(1, 2,", + // expectedCompletionNodeToString: + ";", + // expectedUnitDisplayString: + "class Bar {\n" + + " public class InnerBar {\n" + + " InnerBar(Bar x) {\n" + + " }\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar(Bar x) {\n" + + " ;\n" + + " }\n" + + " }\n" + + " static Bar x;\n" + + " () {\n" + + " }\n" + + " Bar() {\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "", + // expectedReplacedSource: + "", + // test name + "" + ); +} +/* + * Completion on a qualified 'this' constructor invocation. + * + * ie. ExplicitConstructorInvocation ::= Primary '.' 'this' '(' ArgumentListopt ')' ';' + */ +public void testPrimaryThis() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " static Bar x; \n" + + " public class InnerBar { \n" + + " InnerBar(Bar x) { \n" + + " } \n" + + " } \n" + + " public class SubInnerBar extends InnerBar { \n" + + " SubInnerBar(Bar x) { \n" + + " primary().this(1, 2, i); \n" + + " } \n" + + " } \n" + + "} \n", + // completeBehind: + "this(1, 2,", + // expectedCompletionNodeToString: + ";", + // expectedUnitDisplayString: + "class Bar {\n" + + " public class InnerBar {\n" + + " InnerBar(Bar x) {\n" + + " }\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar(Bar x) {\n" + + " ;\n" + + " }\n" + + " }\n" + + " static Bar x;\n" + + " () {\n" + + " }\n" + + " Bar() {\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "", + // expectedReplacedSource: + "", + // test name + "" + ); +} +/* + * Completion on a 'super' constructor invocation. + * + * ie. ExplicitConstructorInvocation ::= 'super' '(' ArgumentListopt ')' ';' + */ +public void testSuper() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " Bar() { \n" + + " super(1, 2, i); \n" + + " } \n" + + "} \n", + // completeBehind: + "super(1, 2,", + // expectedCompletionNodeToString: + ";", + // expectedUnitDisplayString: + "class Bar {\n" + + " Bar() {\n" + + " ;\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "", + // expectedReplacedSource: + "", + // test name + "" + ); +} +/* + * Completion on a 'this' constructor invocation. + * + * ie. ExplicitConstructorInvocation ::= 'this' '(' ArgumentListopt ')' ';' + */ +public void testThis() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " Bar() { \n" + + " this(1, 2, i); \n" + + " } \n" + + "} \n", + // completeBehind: + "this(1, 2,", + // expectedCompletionNodeToString: + ";", + // expectedUnitDisplayString: + "class Bar {\n" + + " Bar() {\n" + + " ;\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "", + // expectedReplacedSource: + "", + // test name + "" + ); +} +/* + * ExplicitConstructorInvocation ::= Name '.' 'super' '(' ')' ';' + */ +public void testWrapperNameSuper() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " static Bar x; \n" + + " public class InnerBar { \n" + + " InnerBar(Bar x) { \n" + + " } \n" + + " } \n" + + " public class SubInnerBar extends InnerBar { \n" + + " SubInnerBar() { \n" + + " Bar.super(fred().xyz); \n" + + " } \n" + + " } \n" + + "} \n", + // completeBehind: + "fred().x", + // expectedCompletionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " public class InnerBar {\n" + + " InnerBar(Bar x) {\n" + + " }\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar() {\n" + + " Bar.super();\n" + + " }\n" + + " }\n" + + " static Bar x;\n" + + " () {\n" + + " }\n" + + " Bar() {\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "x", + // expectedReplacedSource: + "xyz", + // test name + "" + ); +} +/* + * ExplicitConstructorInvocation ::= Name '.' 'this' '(' ')' ';' + */ +public void testWrapperNameThis() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " static Bar x; \n" + + " public class InnerBar { \n" + + " InnerBar(Bar x) { \n" + + " } \n" + + " } \n" + + " public class SubInnerBar extends InnerBar { \n" + + " SubInnerBar() { \n" + + " Bar.this(fred().xyz); \n" + + " } \n" + + " } \n" + + "} \n", + // completeBehind: + "fred().x", + // expectedCompletionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " public class InnerBar {\n" + + " InnerBar(Bar x) {\n" + + " }\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar() {\n" + + " Bar.this();\n" + + " }\n" + + " }\n" + + " static Bar x;\n" + + " () {\n" + + " }\n" + + " Bar() {\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "x", + // expectedReplacedSource: + "xyz", + // test name + "" + ); +} +/* + * ExplicitConstructorInvocation ::= Primary '.' 'this' '(' ')' ';' + */ +public void testWrapperPrimarySuper() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " static Bar x; \n" + + " public class InnerBar { \n" + + " InnerBar(Bar x) { \n" + + " } \n" + + " } \n" + + " public class SubInnerBar extends InnerBar { \n" + + " SubInnerBar(Bar x) { \n" + + " primary().super(fred().xyz); \n" + + " } \n" + + " } \n" + + "} \n", + // completeBehind: + "fred().x", + // expectedCompletionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " public class InnerBar {\n" + + " InnerBar(Bar x) {\n" + + " }\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar(Bar x) {\n" + + " primary().super();\n" + + " }\n" + + " }\n" + + " static Bar x;\n" + + " () {\n" + + " }\n" + + " Bar() {\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "x", + // expectedReplacedSource: + "xyz", + // test name + "" + ); +} +/* + * ExplicitConstructorInvocation ::= 'super' '(' ')' ';' + */ +public void testWrapperSuper() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " Bar() { \n" + + " super(fred().xyz); \n" + + " } \n" + + "} \n", + // completeBehind: + "x", + // expectedCompletionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " Bar() {\n" + + " super();\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "x", + // expectedReplacedSource: + "xyz", + // test name + "" + ); +} +/* + * ExplicitConstructorInvocation ::= 'this' '(' ')' ';' + */ +public void testWrapperThis() { + this.runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " Bar() { \n" + + " this(fred().xyz); \n" + + " } \n" + + "} \n", + // completeBehind: + "x", + // expectedCompletionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " Bar() {\n" + + " this();\n" + + " }\n" + + "}\n", + // expectedCompletionIdentifier: + "x", + // expectedReplacedSource: + "xyz", + // test name + "" + ); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ExplicitConstructorInvocationSelectionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ExplicitConstructorInvocationSelectionTest.java new file mode 100644 index 0000000000..d9ec20d873 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ExplicitConstructorInvocationSelectionTest.java @@ -0,0 +1,232 @@ +/******************************************************************************* + * Copyright (c) 2000, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +/** + * Selection is expected to be wrapped with an explicit constructor invocation. + */ +public class ExplicitConstructorInvocationSelectionTest extends AbstractSelectionTest { +public ExplicitConstructorInvocationSelectionTest(String testName) { + super(testName); +} +/* + * ExplicitConstructorInvocation ::= Name '.' 'super' '(' ')' ';' + */ +public void testNameSuper() { + runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " static Bar x; \n" + + " public class InnerBar { \n" + + " InnerBar(Bar x) { \n" + + " } \n" + + " } \n" + + " public class SubInnerBar extends InnerBar { \n" + + " SubInnerBar() { \n" + + " Bar.super(fred()); \n" + + " } \n" + + " } \n" + + "} \n", + // selectionStartBehind: + "Bar.super(", + // selectionEndBehind: + "fred", + // expectedSelectionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " public class InnerBar {\n" + + " InnerBar(Bar x) {\n" + + " }\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar() {\n" + + " Bar.super();\n" + + " }\n" + + " }\n" + + " static Bar x;\n" + + " () {\n" + + " }\n" + + " Bar() {\n" + + " }\n" + + "}\n", + // expectedSelectionIdentifier: + "fred", + // expectedReplacedSource: + "fred()", + // testName: + "" + ); +} +/* + * ExplicitConstructorInvocation ::= Primary '.' 'this' '(' ')' ';' + */ +public void testPrimarySuper() { + runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " static Bar x; \n" + + " public class InnerBar { \n" + + " InnerBar(Bar x) { \n" + + " } \n" + + " } \n" + + " public class SubInnerBar extends InnerBar { \n" + + " SubInnerBar(Bar x) { \n" + + " primary().super(fred()); \n" + + " } \n" + + " } \n" + + "} \n", + // selectionStartBehind: + "super(", + // selectionEndBehind: + "fred", + // expectedSelectionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " public class InnerBar {\n" + + " InnerBar(Bar x) {\n" + + " }\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar(Bar x) {\n" + + " primary().super();\n" + + " }\n" + + " }\n" + + " static Bar x;\n" + + " () {\n" + + " }\n" + + " Bar() {\n" + + " }\n" + + "}\n", + // expectedSelectionIdentifier: + "fred", + // expectedReplacedSource: + "fred()", + // testName: + "" + ); +} +/* + * ExplicitConstructorInvocation ::= 'this' '(' ')' ';' + */ +public void testThis() { + runTestCheckMethodParse( + // compilationUnit: + "class Bar { \n" + + " Bar() { \n" + + " this(fred()); \n" + + " } \n" + + "} \n", + // selectionStartBehind: + "this(", + // selectionEndBehind: + "fred", + // expectedSelectionNodeToString: + "", + // expectedUnitDisplayString: + "class Bar {\n" + + " Bar() {\n" + + " this();\n" + + " }\n" + + "}\n", + // expectedSelectionIdentifier: + "fred", + // expectedReplacedSource: + "fred()", + // testName: + ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0002() { + + String str = + "public class X { \n" + + " void foo(){; \n" + + " Z z; \n" + + " } \n" + + "} \n"; + + String selection = "Z"; + + String expectedCompletionNodeToString = ">"; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " > z;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "Z"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0004() { + + String str = + "public class X { \n" + + " void foo(){; \n" + + " Y.Z z; \n" + + " } \n" + + "} \n"; + + String selection = "Z"; + + String expectedCompletionNodeToString = ">"; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " > z;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "Y.Z"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0006() { + + String str = + "public class X { \n" + + " void foo(){; \n" + + " Y.Z z; \n" + + " } \n" + + "} \n"; + + String selection = "Z"; + + String expectedCompletionNodeToString = ".Z>"; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " .Z> z;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "Y.Z"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection at specific location + */ +public void test0008() { + + String str = + "public class X { \n" + + " void foo(){; \n" + + " Y.Z z; \n" + + " } \n" + + "} \n"; + + String selection = "Z"; + + String expectedCompletionNodeToString = ".Z>"; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " .Z> z;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "Y.Z"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection of simple name + */ +public void test0010() { + + String str = + "public class X { \n" + + " void foo(){; \n" + + " Z z; \n" + + " } \n" + + "} \n"; + + String selection = "Z"; + + String expectedCompletionNodeToString = ">"; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " > z;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "Z"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection of qualified name + */ +public void test0012() { + + String str = + "public class X { \n" + + " void foo(){; \n" + + " Y.Z z; \n" + + " } \n" + + "} \n"; + + String selection = "Z"; + + String expectedCompletionNodeToString = ">"; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " > z;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "Y.Z"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection of qualified name + */ +public void test0014() { + + String str = + "public class X { \n" + + " void foo(){; \n" + + " Y.Z z; \n" + + " } \n" + + "} \n"; + + String selection = "Z"; + + String expectedCompletionNodeToString = ".Z>"; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " .Z> z;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "Y.Z"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection of qualified name + */ +public void test0016() { + + String str = + "public class X { \n" + + " void foo(){; \n" + + " Y.Z z; \n" + + " } \n" + + "} \n"; + + String selection = "Z"; + + String expectedCompletionNodeToString = ".Z>"; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " .Z> z;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "Y.Z"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test0018() { + + String str = + "public class X { \n" + + " public X() { \n" + + " } \n" + + " void foo(){; \n" + + " new X(); \n" + + " } \n" + + "} \n"; + + String selection = "X"; + + String expectedCompletionNodeToString = "X()>"; + + String completionIdentifier = "X"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " X()>;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "new X()"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test0020() { + + String str = + "public class X { \n" + + " public class Inner { \n" + + " public Inner() { \n" + + " } \n" + + " } \n" + + " void foo(X x){; \n" + + " x.new Inner(); \n" + + " } \n" + + "} \n"; + + String selection = "Inner"; + + String expectedCompletionNodeToString = "Inner()>"; + + String completionIdentifier = "Inner"; + String expectedUnitDisplayString = + "public class X {\n" + + " public class Inner {\n" + + " public Inner() {\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " }\n" + + " void foo(X x) {\n" + + " Inner()>;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "x.new Inner()"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Selection of simple name + */ +public void test0022() { + + String str = + "public class X { \n" + + " Y.Z z; \n" + + "} \n"; + + String selection = "Z"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "public class X {\n" + + " z;\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "Y.Z"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255142 +public void test0024() { + + String str = + "import java.util.List;\n" + + "public class X {\n" + + " T bar(T t) { return t; }\n" + + " void foo(boolean b, Runnable r) {\n" + + " Zork z = null;\n" + + " String s = (String) bar(z); // 5\n" + + " }\n" + + "}\n" + + "\n"; + + String selection = "bar"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "bar"; + String expectedUnitDisplayString = + "import java.util.List;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " T bar(T t) {\n" + + " }\n" + + " void foo(boolean b, Runnable r) {\n" + + " Zork z;\n" + + " String s = (String) ;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "bar(z)"; + String testName = ""; + + int selectionStart = string.indexOf(selection); + int selectionEnd = selectionStart + selection.length() - 1; + + this.checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424110, [1.8][hovering] Hover, F3 does not work for method reference in method invocation +public void test424110a() throws JavaModelException { + String string = + "public class X {\n" + + " int i = fun(X::m); // [2] Does not work\n" + + " public static int m(int x) {\n" + + " return x;\n" + + " }\n" + + " private int fun(F f) {\n" + + " return f.foo(0);\n" + + " }\n" + + "}\n" + + "interface F {\n" + + " int foo(int x);\n" + + "}\n"; + + String selection = "m"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "m"; + String expectedUnitDisplayString = + "public class X {\n" + + " int i = fun();\n" + + " public X() {\n" + + " }\n" + + " public static int m(int x) {\n" + + " }\n" + + " private int fun(F f) {\n" + + " }\n" + + "}\n" + + "interface F {\n" + + " int foo(int x);\n" + + "}\n"; + String expectedReplacedSource = "X::m"; + String testName = ""; + + int selectionStart = string.indexOf(selection); + int selectionEnd = selectionStart + selection.length() - 1; + + this.checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=476693 +public void test476693() throws JavaModelException { + String string = + "import static java.util.stream.Collectors.toList;\n" + + "import java.util.List;\n" + + "import java.util.Spliterator;\n" + + "import java.util.stream.Stream;\n" + + "interface Seq extends Stream, Iterable {\n" + + " @Override\n" + + " default Spliterator spliterator() {\n" + + " return Iterable.super.spliterator();\n" + + " }\n" + + "}\n" + + "interface Tuple2 {}\n" + + "interface Tuple3 {}\n" + + "\n" + + "public class Test {\n" + + " Seq> m(Stream arg1, Stream arg2) {\n" + + " System.out.println(\"m1\"); return null;\n" + + " }\n" + + " Seq> m(Seq arg1, Seq arg2){\n" + + " System.out.println(\"m3\"); return null;\n" + + " }\n" + + " void m(Seq c1, Seq c2, Seq c3) {\n" + + " // Click F3 on the m() call. This will jump to m1, erroneously\n" + + " List> l = m(c1, c2).collect(toList());\n" + + " System.out.println(\"Hello\"); // This shouldn't appear in the selection parse tree\n" + + " }\n" + + "}"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "m"; + String expectedUnitDisplayString = + "import static java.util.stream.Collectors.toList;\n" + + "import java.util.List;\n" + + "import java.util.Spliterator;\n" + + "import java.util.stream.Stream;\n" + + "interface Seq extends Stream, Iterable {\n" + + " default @Override Spliterator spliterator() {\n" + + " }\n" + + "}\n" + + "interface Tuple2 {\n" + + "}\n" + + "interface Tuple3 {\n" + + "}\n" + + "public class Test {\n" + + " public Test() {\n" + + " }\n" + + " Seq> m(Stream arg1, Stream arg2) {\n" + + " }\n" + + " Seq> m(Seq arg1, Seq arg2) {\n" + + " }\n" + + " void m(Seq c1, Seq c2, Seq c3) {\n" + + " List> l = .collect(toList());\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "m(c1, c2)"; + String testName = ""; + + int selectionStart = string.indexOf("byteValue"); + int selectionEnd = selectionStart + completionIdentifier.length() - 1; + + this.checkMethodParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test495912a() { + String string = + "package xy;\n" + + "public class Test {\n" + + " {\n" + + " Runnable r = () -> {\n" + + " Integer i= 1;\n" + + " byte b= i.byteValue();\n" + + " if (true) {\n" + + " if (false) {\n" + + " }\n" + + " }\n" + + " for (int i1 = 0; i1 < 42; i1++) {\n" + + " }\n" + + " };\n" + + " }\n" + + " public void foo(Runnable r) {\n" + + " }\n" + + "}"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "byteValue"; + String expectedUnitDisplayString = + "package xy;\n" + + "public class Test {\n" + + " {\n" + + " {\n" + + " Runnable r = () -> {\n" + + " Integer i;\n" + + " byte b = ;\n" + + " if (true)\n" + + " {\n" + + " if (false)\n" + + " {\n" + + " }\n" + + " }\n" + + " for (int i1;; (i1 < 42); i1 ++) \n" + + " {\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + " public Test() {\n" + + " }\n" + + " public void foo(Runnable r) {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "i.byteValue()"; + String testName = ""; + + int selectionStart = string.indexOf("getTransientData"); + int selectionEnd = selectionStart + selectionIdentifier.length() - 1; + + this.checkMethodParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedSelectionNodeToString, + expectedUnitDisplayString, + selectionIdentifier, + expectedReplacedSource, + testName); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest9.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest9.java new file mode 100644 index 0000000000..c96f67973f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionParserTest9.java @@ -0,0 +1,373 @@ +/******************************************************************************* + * Copyright (c) 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import org.eclipse.jdt.core.JavaModelException; + +import junit.framework.Test; + +public class SelectionParserTest9 extends AbstractSelectionTest { +static { +// TESTS_NUMBERS = new int[] { 1 }; +// TESTS_NAMES = new String[] { "test510339_007" }; +} +public static Test suite() { + return buildMinimalComplianceTestSuite(SelectionParserTest9.class, F_9); +} + +public SelectionParserTest9(String testName) { + super(testName); +} + +public void test510339_001_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " exports pack1;\n" + + "}\n"; + + + String selection = "pack1"; + String selectKey = ""; + + String completionIdentifier = "pack1"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " exports " + expectedCompletionNodeToString +";\n" + + "}\n"; + String expectedReplacedSource = "pack1"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test510339_002_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " exports pack1 to second;\n" + + "}\n"; + + + String selection = "second"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "second"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " exports pack1 to "+ expectedCompletionNodeToString + ";\n" + + "}\n"; + String expectedReplacedSource = "second"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test510339_003_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " opens pack1;\n" + + "}\n"; + + + String selection = "pack1"; + String selectKey = ""; + + String completionIdentifier = "pack1"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " opens " + expectedCompletionNodeToString +";\n" + + "}\n"; + String expectedReplacedSource = "pack1"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test510339_004_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " opens pack1 to second;\n" + + "}\n"; + + + String selection = "second"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "second"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " opens pack1 to "+ expectedCompletionNodeToString + ";\n" + + "}\n"; + String expectedReplacedSource = "second"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test510339_005_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " requires second;\n" + + "}\n"; + + + String selection = "second"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "second"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " requires "+ expectedCompletionNodeToString + ";\n" + + "}\n"; + String expectedReplacedSource = "second"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test510339_006_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " uses Z;\n" + + "}\n"; + + + String selection = "Z"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " uses "+ expectedCompletionNodeToString + ";\n" + + "}\n"; + String expectedReplacedSource = "Z"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test510339_007_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " uses pack1.Z;\n" + + "}\n"; + + + String selection = "Z"; + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " uses " + ";\n" + + "}\n"; + String expectedReplacedSource = "pack1.Z"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test510339_008_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " provides Y with Z;\n" + + "}\n"; + + + String selection = "Y"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Y"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " provides "+ expectedCompletionNodeToString + " with Z;\n" + + "}\n"; + String expectedReplacedSource = "Y"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test510339_009_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " provides pack1.Y with Z;\n" + + "}\n"; + + + String selection = "Y"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Y"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " provides with Z;\n" + + "}\n"; + String expectedReplacedSource = "pack1.Y"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test510339_010_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " provides Y with Z;\n" + + "}\n"; + + + String selection = "Z"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " provides Y with "+ expectedCompletionNodeToString + ";\n" + + "}\n"; + String expectedReplacedSource = "Z"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test510339_011_since_9() throws JavaModelException { + String string = "module my.mod {\n" + + " provides Y with pack1.Z;\n" + + "}\n"; + + + String selection = "Z"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Z"; + String expectedUnitDisplayString = + "module my.mod {\n" + + " provides Y with "+ expectedCompletionNodeToString + ";\n" + + "}\n"; + String expectedReplacedSource = "pack1.Z"; + String testName = "module-info.java"; + + int selectionStart = string.lastIndexOf(selection); + int selectionEnd = string.lastIndexOf(selection) + selection.length() - 1; + + checkDietParse( + string.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java new file mode 100644 index 0000000000..1ec97fccfb --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest.java @@ -0,0 +1,2518 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import junit.framework.Test; + +public class SelectionTest extends AbstractSelectionTest { +static { +// TESTS_NUMBERS = new int[] { 53 }; +} +public static Test suite() { + return buildAllCompliancesTestSuite(SelectionTest.class); +} + +public SelectionTest(String testName) { + super(testName); +} +/* + * Select superclass + */ +public void test01() { + + String str = + "import java.io.*; \n" + + " \n" + + "public class X extends IOException { \n" + + "} \n"; + + String selectionStartBehind = "extends "; + String selectionEndBehind = "IOException"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "IOException"; + String expectedUnitDisplayString = + "import java.io.*;\n" + + "public class X extends {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "IOException"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select qualified superclass + */ +public void test03() { + + String str = + "public class X extends java.io.IOException { \n" + + "} \n"; + + String selectionStartBehind = "java.io."; + String selectionEndBehind = "IOException"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "IOException"; + String expectedUnitDisplayString = + "public class X extends {\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "java.io.IOException"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select message send + */ +public void test05() { + + String str = + "public class X extends java.io.IOException { \n" + + " int foo(){ \n" + + " System.out.println(\"hello\"); \n"; + + String selectionStartBehind = "System.out."; + String selectionEndBehind = "println"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "println"; + String expectedUnitDisplayString = + "public class X extends java.io.IOException {\n" + + " public X() {\n" + + " }\n" + + " int foo() {\n" + + " ;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "System.out.println(\"hello\")"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select message send with sibling method + */ +public void test07() { + + String str = + "public class X extends \n" + + " int foo(){ \n" + + " this.bar(\"hello\"); \n" + + " int bar(String s){ \n" + + " return s.length(); \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "this."; + String selectionEndBehind = "this.bar"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "bar"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " int foo() {\n" + + " ;\n" + + " }\n" + + " int bar(String s) {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "this.bar(\"hello\")"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select field reference with syntax errors + */ +public void test09() { + + String str = + "public class X \n" + + " int num \n" + + " int foo(){ \n" + + " int j = this.num; \n" + + "} \n"; + + String selectionStartBehind = "this."; + String selectionEndBehind = "this.num"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "num"; + String expectedUnitDisplayString = + "public class X {\n" + + " int num;\n" + + " public X() {\n" + + " }\n" + + " int foo() {\n" + + " int j = ;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "this.num"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select allocation + */ +public void test11() { + + String str = + "public class X { \n" + + " X(int i){} \n" + + " int foo(){ \n" + + " int j = 0; \n" + + " X x = new X(j); \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "new "; + String selectionEndBehind = "new X"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "X"; + String expectedUnitDisplayString = + "public class X {\n" + + " X(int i) {\n" + + " }\n" + + " int foo() {\n" + + " int j;\n" + + " X x = ;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "new X(j)"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select qualified name reference receiver + */ +public void test13() { + + String str = + "public class X { \n" + + " int foo(){ \n" + + " java.lang.System.out.println(); \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "java.lang."; + String selectionEndBehind = "java.lang.System"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "System"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " int foo() {\n" + + " ;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "java.lang.System.out"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select variable type with modifier + */ +public void test15() { + + String str = + "public class X { \n" + + " int foo(){ \n" + + " final System sys = null; \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "final "; + String selectionEndBehind = "final System"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "System"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " int foo() {\n" + + " final sys;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "System"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select name + */ +public void test17() { + + String str = + "public class X { \n" + + " int foo(){ \n" + + " System \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "\n "; + String selectionEndBehind = "\n System"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "System"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " int foo() {\n" + + " ;\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = "System"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select cast type + */ +public void test19() { + + String str = + "public class X { \n" + + " Object foo(){ \n" + + " return (Object) this; \n" + + " } \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "return ("; + String selectionEndBehind = "return (Object"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "Object"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " Object foo() {\n" + + " return () this;\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = "Object"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select import + */ +public void test21() { + + String str = + "import x.y.Other; \n" + + "public class X { \n" + + " int foo(){ \n" + + " } \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "y."; + String selectionEndBehind = "y.Other"; + + String expectedCompletionNodeToString = ""; + String completionIdentifier = "Other"; + String expectedUnitDisplayString = + "import ;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " int foo() {\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = "x.y.Other"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select array initializer type + */ +public void test23() { + + String str = + "public class X { \n" + + " int foo(){ \n" + + " String[] p = new String[]{\"Left\"};\n" + +// " } \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "new "; + String selectionEndBehind = "new String"; + String expectedCompletionNodeToString = ""; + String completionIdentifier = "String"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " int foo() {\n" + + " String[] p = ;\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = "String"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select super + */ +public void test25() { + + String str = + "public class G { \n" + + " Object foo() { \n" + + " return super.foo(); \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "return "; + String selectionEndBehind = "return super"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "super"; + String expectedUnitDisplayString = + "public class G {\n" + + " public G() {\n" + + " }\n" + + " Object foo() {\n" + + " return ;\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = "super"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select super constructor call + */ +public void test27() { + + String str = + "public class G { \n" + + " G() { \n" + + " super(); \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "\n\t\t"; + String selectionEndBehind = "super"; + + String expectedCompletionNodeToString = ";"; + + String completionIdentifier = "super"; + String expectedUnitDisplayString = + "public class G {\n" + + " G() {\n" + + " ;\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = "super()"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select qualified super constructor call with arguments + */ +public void test29() { + + String str = + "public class G { \n" + + " class M {} \n" + + " static Object foo() { \n" + + " class X extends M { \n" + + " X (){ \n" + + " new G().super(23 + \"hello\"); \n" + + " } \n" + + " } \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "new G()."; + String selectionEndBehind = "new G().super"; + + String expectedCompletionNodeToString = ";"; + + String completionIdentifier = "super"; + String expectedUnitDisplayString = + "public class G {\n" + + " class M {\n" + + " M() {\n" + + " }\n" + + " }\n" + + " public G() {\n" + + " }\n" + + " static Object foo() {\n" + + " class X extends M {\n" + + " X() {\n" + + " ;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "new G().super(23 + \"hello\")"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Regression test for 1FVQ0LK + */ +public void test31() { + + String str = + "class X { \n" + + " Y f; \n" + + " void foo() { \n" + + " new Bar(fred()); \n" + + " Z z= new Z(); \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "\n\t"; + String selectionEndBehind = "Y"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Y"; + String expectedUnitDisplayString = + "class X {\n" + + " f;\n" + + " X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = "Y"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Regression test for 1FWT4AJ: ITPCOM:WIN98 - SelectionParser produces duplicate type declaration + */ +public void test32() { + + String str = + "package search; \n"+ + "import java.io.*; \n"+ + "public class PhraseQuery { \n"+ + " public boolean containsPhrase(){ \n"+ + " try { \n"+ + " char currentChar = \"hello\".toLowerCase() \n"+ + " } \n"+ + "} \n"; + + String selectionStartBehind = "\"hello\"."; + String selectionEndBehind = "\"hello\".toLowerCase"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "toLowerCase"; + String expectedUnitDisplayString = + "package search;\n" + + "import java.io.*;\n" + + "public class PhraseQuery {\n" + + " public PhraseQuery() {\n" + + " }\n" + + " public boolean containsPhrase() {\n" + + " {\n" + + " char currentChar = ;\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = "\"hello\".toLowerCase()"; + String testName = "<1FWT4AJ: ITPCOM:WIN98 - SelectionParser produces duplicate type declaration>"; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Regression test for 1G4CLZM: ITPJUI:WINNT - 'Import Selection' - Set not found + */ +public void test33() { + + String str = + " import java.util.AbstractMap; \n"+ + " public class c4 extends AbstractMap { \n"+ + " /** \n"+ + " * @see AbstractMap#entrySet \n"+ + " */ \n"+ + " public Set entrySet() { \n"+ + " return null; \n"+ + " } \n"+ + " } \n"; + + String selectionStartBehind = "\n\t\tpublic "; + String selectionEndBehind = "public Set"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Set"; + String expectedUnitDisplayString = + "import java.util.AbstractMap;\n" + + "public class c4 extends AbstractMap {\n" + + " public c4() {\n" + + " }\n" + + " public entrySet() {\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = "Set"; + String testName = "<1G4CLZM: ITPJUI:WINNT - 'Import Selection' - Set not found>"; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Regression test for 1GB99S3: ITPJUI:WINNT - SH: NPE in editor while getting hover help + */ +public void test34() { + + String str = + "public class X { \n"+ + " public int foo() { \n"+ + " Object[] array = new Object[0]; \n"+ + " return array.length; \n"+ + " } \n"+ + "} \n"; + + String selectionStartBehind = "\n\t\treturn "; + String selectionEndBehind = "array.length"; + + String expectedCompletionNodeToString = NONE; + + String completionIdentifier = NONE; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public int foo() {\n" + + " Object[] array;\n" + + " return array.length;\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = NONE; + String testName = "<1GB99S3: ITPJUI:WINNT - SH: NPE in editor while getting hover help>"; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} + +/* + * Select this constructor call + */ +public void test35() { + + String str = + "public class G { \n" + + " G() { \n" + + " } \n" + + " G(int x) { \n" + + " this(); \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "\n\t\t"; + String selectionEndBehind = "this"; + + String expectedCompletionNodeToString = ";"; + + String completionIdentifier = "this"; + String expectedUnitDisplayString = + "public class G {\n" + + " G() {\n" + + " }\n" + + " G(int x) {\n" + + " ;\n" + + " }\n" + + "}\n"; + + String expectedReplacedSource = "this()"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * Select qualified this constructor call with arguments + */ +public void test37() { + + String str = + "public class G { \n" + + " static Object foo() { \n" + + " class X { \n" + + " X (){ \n" + + " } \n" + + " X (int x){ \n" + + " new G().this(23 + \"hello\"); \n" + + " } \n" + + " } \n" + + " } \n" + + "} \n"; + + String selectionStartBehind = "new G()."; + String selectionEndBehind = "new G().this"; + + String expectedCompletionNodeToString = ";"; + + String completionIdentifier = "this"; + String expectedUnitDisplayString = + "public class G {\n" + + " public G() {\n" + + " }\n" + + " static Object foo() {\n" + + " class X {\n" + + " X() {\n" + + " super();\n"+ + " }\n" + + " X(int x) {\n" + + " ;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "new G().this(23 + \"hello\")"; + String testName = ""; + + int selectionStart = str.indexOf(selectionStartBehind) + selectionStartBehind.length(); + int selectionEnd = str.indexOf(selectionEndBehind) + selectionEndBehind.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * bugs 3293 search does not work in inner class (1GEUQHJ) + */ +public void test39() { + + String str = + "public class X { \n" + + " Object hello = new Object(){ \n" + + " public void foo(String s){ \n" + + " s.length(); \n" + + " } \n" + + " }; \n" + + "} \n"; + + String selectionStartBehind = "s."; + String selectionEndBehind = "length"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "length"; + String expectedUnitDisplayString = + "public class X {\n" + + " Object hello = new Object() {\n" + + " public void foo(String s) {\n" + + " ;\n" + + " }\n" + + " };\n" + + " public X() {\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "s.length()"; + String testName = ""; + + int selectionStart = str.indexOf(selection); + int selectionEnd = str.indexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * bugs 11475 selection on local name. + */ +public void test41() { + + String str = + "public class X { \n" + + " public void foo(){ \n" + + " Object var; \n" + + " } \n" + + "} \n"; + + String selection = "var"; + + String expectedCompletionNodeToString = ";"; + + String completionIdentifier = "var"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public void foo() {\n" + + " ;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "var"; + String testName = ""; + + int selectionStart = str.indexOf(selection); + int selectionEnd = str.indexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * bugs 11475 selection on argument name inside catch statement. + */ +public void test43() { + + String str = + "public class X { \n" + + " public void foo(){ \n" + + " try{ \n" + + " }catch(Object var){}\n" + + " } \n" + + "} \n"; + + String selection = "var"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "var"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public void foo() {\n" + + " ;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "var"; + String testName = ""; + + int selectionStart = str.indexOf(selection); + int selectionEnd = str.indexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * bugs 14468 + */ +public void test45() { + + String str = + "public class X { \n" + + " void foo() {\n" + + " if(x instanceof Object s){\n" + + " }\n" + + " } \n" + + "} \n"; + + String selection = "Object"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Object"; + String expectedUnitDisplayString = + "public class X {\n"+ + " public X() {\n"+ + " }\n"+ + " void foo() {\n"+ + " if ((x instanceof s))\n" + + " {\n" + + " }\n" + + " }\n"+ + "}\n"; + String expectedReplacedSource = "Object"; + String testName = ""; + + int selectionStart = str.indexOf(selection); + int selectionEnd = str.indexOf(selection) + selection.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * bugs 14468 + */ +public void test47() { + + String str = + "public class X { \n" + + " void foo() {\n" + + " boolean y = x instanceof Object;\n" + + " } \n" + + "} \n"; + + String selection = "Object"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Object"; + String expectedUnitDisplayString = + "public class X {\n"+ + " public X() {\n"+ + " }\n"+ + " void foo() {\n"+ + " boolean y = (x instanceof );\n"+ + " }\n"+ + "}\n"; + String expectedReplacedSource = "Object"; + String testName = ""; + + int selectionStart = str.indexOf(selection); + int selectionEnd = str.indexOf(selection) + selection.length() - 1; + + checkDietParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * bugs 28064 + */ +public void test49() { + + String str = + "public class X { \n" + + " X x = new X(){}\n" + + "} \n"; + + String selection = "X"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "X"; + String expectedUnitDisplayString = + "public class X {\n"+ + " X x = ;\n"+ + " public X() {\n"+ + " }\n"+ + "}\n"; + String expectedReplacedSource = "new X()"; + String testName = ""; + + int selectionStart = str.indexOf(selection); + int selectionEnd = str.indexOf(selection) + selection.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +/* + * bugs https://bugs.eclipse.org/bugs/show_bug.cgi?id=52422 + */ +public void test51() { + + String str = + "public class X { \n" + + " void foo() {\n" + + " new Object(){\n" + + " void foo0(){\n" + + " new Object(){\n" + + " void bar(){\n" + + " bar2();\n" + + " }\n" + + " void bar2() {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "} \n"; + + String selection = "bar2"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "bar2"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " new Object() {\n" + + " void foo0() {\n" + + " new Object() {\n" + + " void bar() {\n" + + " ;\n" + + " }\n" + + " void bar2() {\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "bar2()"; + String testName = ""; + + int selectionStart = str.indexOf(selection); + int selectionEnd = str.indexOf(selection) + selection.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +public void test53() { + + String str = + "public class X { \n" + + " void foo(String[] stringArray) {\n" + + " for(String string2 : stringArray);\n" + + " }\n" + + "} \n"; + + String selection = "string2"; + + String expectedCompletionNodeToString = ";"; + + String completionIdentifier = "string2"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo(String[] stringArray) {\n" + + " for ( : stringArray) \n" + + " ;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "string2"; + String testName = ""; + + int selectionStart = str.indexOf(selection); + int selectionEnd = str.indexOf(selection) + selection.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=84001 +public void test55() { + + String str = + "public class X { \n" + + " void foo() {\n" + + " new Test.Sub();\n" + + " }\n" + + "} \n"; + + String selection = "Sub"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "Sub"; + String expectedUnitDisplayString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " ;\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "new Test.Sub()"; + String testName = ""; + + int selectionStart = str.indexOf(selection); + int selectionEnd = str.indexOf(selection) + selection.length() - 1; + + this.checkMethodParse( + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest2.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest2.java new file mode 100644 index 0000000000..2270f501e4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SelectionTest2.java @@ -0,0 +1,233 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import java.util.Locale; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.codeassist.select.SelectionParser; +import org.eclipse.jdt.internal.codeassist.select.SelectionScanner; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.ASTNode; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Initializer; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +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.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; + +public class SelectionTest2 extends AbstractSelectionTest { + +public SelectionTest2(String testName) { + super(testName); +} +boolean thereWasAnNPE = false; +static class SpecialSelectionParser extends SelectionParser { + public SpecialSelectionParser(ProblemReporter problemReporter) { + super(problemReporter); + } + public void doNPEInParser(){ + this.stack = null; + } +} + + SpecialSelectionParser createParser(){ + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + SpecialSelectionParser parser = + new SpecialSelectionParser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory(Locale.getDefault()))); + return parser; +} +void checkMethodParse( + SelectionParser parser, + char[] source, + int selectionStart, + int selectionEnd, + String expectedSelection, + String expectedUnitToString, + String expectedSelectionIdentifier, + String expectedSelectedSource, + + String testName) { + + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + CompilationUnitDeclaration unit = parser.dietParse(sourceUnit, compilationResult, selectionStart, selectionEnd); + + ASTNode foundMethod = null; + if (unit.types != null) { + for (int i = 0; i < unit.types.length; i++) { + TypeDeclaration type = unit.types[i]; + ASTNode method = findMethod(type, selectionStart); + if (method != null) { + foundMethod = method; + break; + } + } + } + assertTrue("no method found at cursor location", foundMethod != null); + if (foundMethod instanceof AbstractMethodDeclaration) { + parser.parseBlockStatements((AbstractMethodDeclaration)foundMethod, unit); + } else { + TypeDeclaration type = (TypeDeclaration)foundMethod; + if (type.fields != null) { + for (int i = 0; i < type.fields.length; i++) { + FieldDeclaration field = type.fields[i]; + if (field instanceof Initializer && field.sourceStart <= selectionStart && selectionStart <= field.sourceEnd) { + parser.parseBlockStatements((Initializer)field, type, unit); + break; + } + } + } + } + + String computedUnitToString = unit.toString(); + //System.out.println(computedUnitToString); + //System.out.println(Util.displayString(computedUnitToString)); + //System.out.println(expectedUnitToString); + + String computedCompletion = parser.assistNode == null + ? NONE + : parser.assistNode.toString(); + assertEquals( + "invalid selection node-" + testName, + expectedSelection, + computedCompletion); + + assertEquals( + "invalid selection location-"+testName, + expectedUnitToString, + computedUnitToString); + + if (expectedSelectionIdentifier != null){ + char[] chars = ((SelectionScanner)parser.scanner).selectionIdentifier; + String computedSelectionIdentifier = chars == null ? NONE : new String(chars); + assertEquals( + "invalid selection identifier-" + testName, + expectedSelectionIdentifier, + computedSelectionIdentifier); + } + if (expectedSelectedSource != null){ + char[] chars = null; + if (parser.assistNode != null){ + chars = CharOperation.subarray( + parser.scanner.source, + parser.assistNode.sourceStart, + parser.assistNode.sourceEnd + 1); + } else { + if (parser.assistIdentifier() != null){ + if (((SelectionScanner)parser.scanner).selectionEnd + >= ((SelectionScanner)parser.scanner).selectionStart){ + chars = CharOperation.subarray( + parser.scanner.source, + ((SelectionScanner)parser.scanner).selectionStart, + ((SelectionScanner)parser.scanner).selectionEnd + 1); + } + } + } + String computedReplacedSource = chars == null ? NONE : new String(chars); + assertEquals( + "invalid replaced source-" + testName, + expectedSelectedSource, + computedReplacedSource); + } +} +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=30946 + */ +public void testBug30946() { + final SpecialSelectionParser parser = createParser(); + Thread query = new Thread( + new Runnable(){ + @Override + public void run(){ + String str = + "public class A {\n" + + " void foo() {\n" + + " if (true) {\n" + + " if()\n" + + " switch (1) {\n" + + " case A.B:\n" + + " C d= (C) s;\n" + + " here\n" + + " }\n" + + " }\n" + + " }\n" + + "}n"; + + String selection = "here"; + + String expectedCompletionNodeToString = ""; + + String completionIdentifier = "here"; + String expectedUnitDisplayString = + "public class A {\n" + + " public A() {\n" + + " }\n" + + " void foo() {\n" + + " {\n" + + " {\n" + + " C d;\n" + + " ;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + String expectedReplacedSource = "here"; + String testName = ""; + + int selectionStart = str.lastIndexOf(selection); + int selectionEnd = str.lastIndexOf(selection) + selection.length() - 1; + + try { + SelectionTest2.this.checkMethodParse( + parser, + str.toCharArray(), + selectionStart, + selectionEnd, + expectedCompletionNodeToString, + expectedUnitDisplayString, + completionIdentifier, + expectedReplacedSource, + testName); + } catch (NullPointerException e) { + SelectionTest2.this.thereWasAnNPE = true; + } + } + }); + + query.start(); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + // force parser to stop + parser.doNPEInParser(); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + assertTrue("there is an infinite loop", !this.thereWasAnNPE); + +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SingleCompletionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SingleCompletionTest.java new file mode 100644 index 0000000000..b503ee295b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SingleCompletionTest.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import java.lang.reflect.InvocationTargetException; + +import junit.framework.TestCase; + +/** + * Only 1 test should be in this class + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class SingleCompletionTest extends AbstractCompletionTest { +/** + * SingleCompletionTest constructor comment. + * @param testName java.lang.String + */ +public SingleCompletionTest(String testName) { + super(testName); +} +private void run(Class testClass, String methodName) { + try { + java.lang.reflect.Constructor constructor = testClass.getDeclaredConstructor(new Class[] {String.class}); + TestCase test = (TestCase)constructor.newInstance(new Object[] {"single completion test"}); + java.lang.reflect.Method method = testClass.getDeclaredMethod(methodName, new Class[] {}); + method.invoke(test, new Object[] {}); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + Throwable target = e.getTargetException(); + if (target instanceof RuntimeException) { + throw (RuntimeException)target; + } + if (target instanceof Error) { + throw (Error)target; + } + throw new Error(target.getMessage()); + } +} +/* + * The test. + */ +public void test() { + run(NameReferenceCompletionTest.class, "testMethodInvocationAnonymousInnerClass2"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java new file mode 100644 index 0000000000..627a9a2484 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java @@ -0,0 +1,5398 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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.JavaCore; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.internal.compiler.ISourceElementRequestor; +import org.eclipse.jdt.internal.compiler.SourceElementParser; +import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.ImportReference; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class SourceElementParserTest extends AbstractCompilerTest implements ISourceElementRequestor { + private SourceType currentType; + private SourceMethod currentMethod; + private SourceField currentField; + private SourceField currentRecordComp; + private SourceInitializer currentInitializer; + private char[] source; + private SourcePackage currentPackage; + private SourceImport[] currentImports; + private int numberOfImports; +public SourceElementParserTest(String testName) { + super(testName); +} +public SourceElementParserTest(String testName, char[] source) { + super(testName); + this.source = source; +} +static { +// TESTS_NUMBERS = new int[] { 81 }; +} +public static Test suite() { + return buildAllCompliancesTestSuite(SourceElementParserTest.class); +} +/** + * acceptAnnotationTypeReference method comment. + */ +public void acceptAnnotationTypeReference(char[][] typeName, int sourceStart, int sourceEnd) {} +/** + * acceptAnnotationTypeReference method comment. + */ +public void acceptAnnotationTypeReference(char[] typeName, int sourcePosition) {} +/** + * acceptConstructorReference method comment. + */ +public void acceptConstructorReference(char[] typeName, int argCount, int sourcePosition) { + if (this.currentMethod == null) { + if (this.currentType != null) { + StringBuilder buffer = new StringBuilder(); + buffer.append(typeName).append("(").append(argCount).append(")\n"); + this.currentType.setDefaultConstructor(buffer.toString()); + } + return; + } + if (this.currentMethod.isConstructor()) { + StringBuilder buffer = new StringBuilder(); + buffer.append(typeName).append("(").append(argCount).append(")\n"); + this.currentMethod.setExplicitConstructorCall(buffer.toString()); + } else { + if (this.currentType != null) { + StringBuilder buffer = new StringBuilder(); + buffer.append(typeName).append("(").append(argCount).append(")\n"); + this.currentType.setDefaultConstructor(buffer.toString()); + } + } +} +/** + * acceptFieldReference method comment. + */ +public void acceptFieldReference(char[] fieldName, int sourcePosition) {} +/** + * acceptImport method comment. + */ +public void acceptImport( + int declarationStart, + int declarationEnd, + int nameStart, + int nameEnd, + char[][] tokens, + boolean onDemand, + int modifiers) { + + addImport( + new SourceImport(declarationStart, declarationEnd, CharOperation.concatWith(tokens, '.'), onDemand, modifiers, this.source)); +} +/** + * acceptLineSeparatorPositions method comment. + */ +public void acceptLineSeparatorPositions(int[] positions) {} +/** + * acceptMethodReference method comment. + */ +public void acceptMethodReference(char[] methodName, int argCount, int sourcePosition) {} +/** + * acceptPackage method comment. + */ +public void acceptPackage(ImportReference importReference) { + + this.currentPackage = + new SourcePackage(importReference.declarationSourceStart, importReference.declarationSourceEnd, CharOperation.concatWith(importReference.getImportName(), '.'), this.source); +} +/** + * acceptProblem method comment. + */ +public void acceptProblem(CategorizedProblem problem) {} +/** + * acceptTypeReference method comment. + */ +public void acceptTypeReference(char[][] typeName, int sourceStart, int sourceEnd) {} +/** + * acceptTypeReference method comment. + */ +public void acceptTypeReference(char[] typeName, int sourcePosition) {} +/** + * acceptUnknownReference method comment. + */ +public void acceptUnknownReference(char[][] name, int sourceStart, int sourceEnd) {} +/** + * acceptUnknownReference method comment. + */ +public void acceptUnknownReference(char[] name, int sourcePosition) {} +protected void addImport(SourceImport sourceImport) { + if (this.currentImports == null) { + this.currentImports = new SourceImport[4]; + } + + if (this.numberOfImports == this.currentImports.length) { + System.arraycopy( + this.currentImports, + 0, + this.currentImports = new SourceImport[this.numberOfImports * 2], + 0, + this.numberOfImports); + } + this.currentImports[this.numberOfImports++] = sourceImport; +} +public void dietParse(String s, String testName) { + this.dietParse(s, testName, false); +} +public void dietParse(String s, String testName, boolean recordLocalDeclaration) { + + this.source = s.toCharArray(); + reset(); + SourceElementParser parser = + new SourceElementParser( + this, + new DefaultProblemFactory(Locale.getDefault()), + new CompilerOptions(getCompilerOptions()), + recordLocalDeclaration/*don't record local declarations*/, + true/*optimize string literals*/); + + ICompilationUnit sourceUnit = new CompilationUnit(this.source, testName, null); + + parser.parseCompilationUnit(sourceUnit, false, null); + +} +public static String displayModifiers(int modifiers) { + StringBuilder buffer = new StringBuilder(); + + if ((modifiers & ClassFileConstants.AccPublic) != 0) + buffer.append("public "); + if ((modifiers & ClassFileConstants.AccProtected) != 0) + buffer.append("protected "); + if ((modifiers & ClassFileConstants.AccPrivate) != 0) + buffer.append("private "); + if ((modifiers & ClassFileConstants.AccFinal) != 0) + buffer.append("final "); + if ((modifiers & ClassFileConstants.AccStatic) != 0) + buffer.append("static "); + if ((modifiers & ClassFileConstants.AccAbstract) != 0) + buffer.append("abstract "); + if ((modifiers & ClassFileConstants.AccNative) != 0) + buffer.append("native "); + if ((modifiers & ClassFileConstants.AccSynchronized) != 0) + buffer.append("synchronized "); + return buffer.toString(); +} +public void enterType(TypeInfo typeInfo) { + if (this.currentType == null) { + // top level type + this.currentType = + new SourceType( + null, + typeInfo.declarationStart, + typeInfo.modifiers, + typeInfo.name, + typeInfo.nameSourceStart, + typeInfo.nameSourceEnd, + typeInfo.superclass, + typeInfo.superinterfaces, + this.source); + this.currentType.setPackage(this.currentPackage); + setImports(); + } else { + // member type + SourceType memberType; + this.currentType.addMemberType( + memberType = + new SourceType( + this.currentType.getName(), + typeInfo.declarationStart, + typeInfo.modifiers, + typeInfo.name, + typeInfo.nameSourceStart, + typeInfo.nameSourceEnd, + typeInfo.superclass, + typeInfo.superinterfaces, + this.source)); + memberType.parent = this.currentType; + this.currentType = memberType; + } + if (typeInfo.typeParameters != null) { + for (int i = 0, length = typeInfo.typeParameters.length; i < length; i++) { + TypeParameterInfo typeParameterInfo = typeInfo.typeParameters[i]; + addTypeParameterToType(typeParameterInfo); + } + } +} +public void enterCompilationUnit() { +} +public void enterConstructor(MethodInfo methodInfo) { + enterAbtractMethod(methodInfo); +} +public void enterField(FieldInfo fieldInfo) { + if (fieldInfo.isRecordComponent) { + this.currentType.addRecordComponent( + this.currentRecordComp = + new SourceField( + fieldInfo.declarationStart, + fieldInfo.modifiers, + fieldInfo.type, + fieldInfo.name, + fieldInfo.nameSourceStart, + fieldInfo.nameSourceEnd, + this.source)); + } else { + this.currentType.addField( + this.currentField = + new SourceField( + fieldInfo.declarationStart, + fieldInfo.modifiers, + fieldInfo.type, + fieldInfo.name, + fieldInfo.nameSourceStart, + fieldInfo.nameSourceEnd, + this.source)); + } +} +public void enterInitializer(int declarationSourceStart, int modifiers) { + this.currentType.addField( + this.currentInitializer = new SourceInitializer( + declarationSourceStart, + modifiers)); +} +public void exitInitializer(int declarationSourceEnd) { + this.currentInitializer.setDeclarationSourceEnd(declarationSourceEnd); +} +public void enterMethod(MethodInfo methodInfo) { + enterAbtractMethod(methodInfo); +} +protected void enterAbtractMethod(MethodInfo methodInfo) { + this.currentType.addMethod( + this.currentMethod = + new SourceMethod( + methodInfo.declarationStart, + methodInfo.modifiers, + methodInfo.returnType, + methodInfo.name, // null for constructors + methodInfo.nameSourceStart, + methodInfo.nameSourceEnd, + methodInfo.parameterTypes, + methodInfo.parameterNames, + methodInfo.exceptionTypes, + this.source)); + + if (methodInfo.typeParameters != null) { + for (int i = 0, length = methodInfo.typeParameters.length; i < length; i++) { + TypeParameterInfo typeParameterInfo = methodInfo.typeParameters[i]; + addTypeParameterToMethod(typeParameterInfo); + } + } +} +public void addTypeParameterToMethod(TypeParameterInfo typeParameterInfo) { + if (this.currentMethod.typeParameterNames == null) { + this.currentMethod.typeParameterNames = new char[][] {typeParameterInfo.name}; + this.currentMethod.typeParameterBounds = new char[][][] {typeParameterInfo.bounds}; + } else { + int length = this.currentMethod.typeParameterNames.length; + System.arraycopy(this.currentMethod.typeParameterNames, 0, this.currentMethod.typeParameterNames = new char[length+1][],0, length); + this.currentMethod.typeParameterNames[length] = typeParameterInfo.name; + System.arraycopy(this.currentMethod.typeParameterBounds, 0, this.currentMethod.typeParameterBounds = new char[length+1][][],0, length); + this.currentMethod.typeParameterBounds[length] = typeParameterInfo.bounds; + } +} +public void addTypeParameterToType(TypeParameterInfo typeParameterInfo) { + if (this.currentType.typeParameterNames == null) { + this.currentType.typeParameterNames = new char[][] {typeParameterInfo.name}; + this.currentType.typeParameterBounds = new char[][][] {typeParameterInfo.bounds}; + } else { + int length = this.currentType.typeParameterNames.length; + System.arraycopy(this.currentType.typeParameterNames, 0, this.currentType.typeParameterNames = new char[length+1][],0, length); + this.currentMethod.typeParameterNames[length] = typeParameterInfo.name; + System.arraycopy(this.currentType.typeParameterBounds, 0, this.currentType.typeParameterBounds = new char[length+1][][],0, length); + this.currentType.typeParameterBounds[length] = typeParameterInfo.bounds; + } +} +public void exitType(int declarationEnd) { + this.currentType.setDeclarationSourceEnd(declarationEnd); + if (this.currentType.parent != null) { + this.currentType = this.currentType.parent; + } +} +public void exitCompilationUnit(int declarationEnd) {} +public void exitConstructor(int declarationEnd) { + exitAbstractMethod(declarationEnd); +} +public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd) { + this.currentField.setDeclarationSourceEnd(declarationEnd); +} +public void exitRecordComponent(int declarationEnd, int declarationSourceEnd) { + this.currentRecordComp.setDeclarationSourceEnd(declarationEnd); +} +public void exitMethod(int declarationEnd, Expression defaultValue) { + exitAbstractMethod(declarationEnd); +} +protected void exitAbstractMethod(int declarationEnd) { + this.currentMethod.setDeclarationSourceEnd(declarationEnd); +} +public void fullParse(String s, String testName) { + this.fullParse(s, testName, false); +} +public void fullParse(String s, String testName, Map options) { + this.fullParse(s, testName, false, options); +} +public void fullParse(String s, String testName, boolean recordLocalDeclaration, Map options) { + this.source = s.toCharArray(); + reset(); + SourceElementParser parser = + new SourceElementParser( + this, new DefaultProblemFactory(Locale.getDefault()), + new CompilerOptions(options), + recordLocalDeclaration/*don't record local declarations*/, + true/*optimize string literals*/); + + ICompilationUnit sourceUnit = new CompilationUnit(this.source, testName, null); + + parser.parseCompilationUnit(sourceUnit, true, null); +} +public void fullParse(String s, String testName, boolean recordLocalDeclaration) { + this.fullParse(s, testName, recordLocalDeclaration, getCompilerOptions()); +} +public void reset() { + this.currentType = null; + this.currentMethod = null; + this.currentField = null; + this.currentPackage = null; + this.currentImports = null; + this.numberOfImports = 0; +} +public void setImports() { + if (this.currentImports == null) + return; + if (this.numberOfImports != this.currentImports.length) { + System.arraycopy( + this.currentImports, + 0, + this.currentImports = new SourceImport[this.numberOfImports], + 0, + this.numberOfImports); + } + this.currentType.setImports(this.currentImports); +} +public void test01() { + + String s = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "void foo() {\n" + + "System.out.println();\n" + + "\n" + + "public int h;\n" + + "public int[] i = { 0, 1 };\n" + + "\n" + + "int bar" + "\\" + "u0065(){\n" + + "void truc(){\n" + + "}\n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tpublic int h;\n" + + "\tpublic int[] i;\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tint bare() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test01: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 52, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 178, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("Invalid fields length ", 2, fields.length); + + assertEquals("Invalid declaration source start for field h", 105, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 117, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 119, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 144, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 69, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 103, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bare", 147, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bare", 163, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 164, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 177, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bare", "bar" + "\\" + "u0065", methods[1].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test02() { + + String s = + "/** javadoc comment */\n" + + "public class X {\n" + + "}\n"; + + String expectedUnitToString = + "public class X {\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test02: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 40, + this.currentType.getDeclarationSourceEnd()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test03() { + + String s = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "void foo() {\n" + + "System.out.println();\n" + + "\n" + + "public int h;\n" + + "public int[] i = { 0, 1 };\n" + + "\n" + + "int bar" + "\\" + "u0065(){\n" + + "void truc(){\n" + + "}\n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tpublic int h;\n" + + "\tpublic int[] i;\n" + + "\tvoid foo() {}\n" + + "\tint bare() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test03: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 52, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 178, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("Invalid fields length ", 2, fields.length); + + assertEquals("Invalid declaration source start for field h", 105, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 117, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 119, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 144, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 69, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 103, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 147, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 163, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 164, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 177, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bare", "bar" + "\\" + "u0065", methods[1].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test04() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " class L { \n" + + " void baz(){} \n" + + " } \n" + + " \n" + + " public int h; \n" + + " public int[] i = { 0, 1 }; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tpublic int h;\n" + + "\tpublic int[] i;\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + String testName = "test04: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 89, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 372, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("Invalid fields length ", 2, fields.length); + + assertEquals("Invalid declaration source start for field h", 248, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 260, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 271, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 296, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 115, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 222, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 317, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 337, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 339, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 360, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test05() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " class L { \n" + + " void baz(){} \n" + + " } \n" + + " \n" + + " public int h; \n" + + " public int[] i = { 0, 1 }; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tpublic int h;\n" + + "\tpublic int[] i;\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test05: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 89, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 372, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("Invalid fields length ", 2, fields.length); + + assertEquals("Invalid declaration source start for field h", 248, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 260, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 271, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 296, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 115, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 222, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 317, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 337, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 339, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 360, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test06() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " X x; \n" + + " Object a, b = null; \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " public int h; \n" + + " public int[] i = { 0, 1 }; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tX x;\n" + + "\tObject a;\n" + + "\tObject b;\n" + + "\tpublic int h;\n" + + "\tpublic int[] i;\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test06: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 89, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 347, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("Invalid fields length ", 5, fields.length); + + assertEquals("Invalid declaration source start for field x", 115, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 118, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field a", 131, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field a", 139, fields[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field b", 131, fields[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field b", 149, fields[2].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field h", 223, fields[3].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 235, fields[3].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 246, fields[4].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 271, fields[4].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 159, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 221, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 292, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 312, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 314, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 335, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test07() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " X x; \n" + + " Object a, b = null; \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " public int h; \n" + + " public int[] i = { 0, 1 }; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tX x;\n" + + "\tObject a;\n" + + "\tObject b;\n" + + "\tpublic int h;\n" + + "\tpublic int[] i;\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test07: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 89, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 347, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("Invalid fields length ", 5, fields.length); + + assertEquals("Invalid declaration source start for field xh", 115, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 118, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field a", 131, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field a", 139, fields[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field b", 131, fields[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field b", 149, fields[2].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field h", 223, fields[3].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 235, fields[3].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 246, fields[4].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 271, fields[4].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 159, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 221, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 292, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 312, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 314, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 335, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test08() { + + String s = + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " void baz(){} \n" + + " } \n" + + " \n" + + " void bar(){ \n" + + " } \n" + + " void truc(){ \n" + + " } \n" + + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test08: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 198, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 27, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 100, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 127, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 149, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 163, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 185, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test09() { + + String s = + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " void baz(){} \n" + + " } \n" + + " \n" + + " void bar(){ \n" + + " } \n" + + " void truc(){ \n" + + " } \n" + + "} \n"; + + + String expectedUnitToString = + "public class X {\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test09: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 198, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 27, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 100, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 127, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 149, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 163, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 185, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test10() { + + String s = + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " void baz(){} \n" + + " } \n" + + " /** comment \n" + + " * \n" + + " * \n" + + " */ \n" + + " \n" + + " void bar(){ \n" + + " } \n" + + " void truc(){ \n" + + " } \n" + + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test10: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 415, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 27, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 100, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 114, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 366, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 380, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 402, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test11() { + + String s = + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " void baz(){} \n" + + " /** comment \n" + + " * \n" + + " * \n" + + " */ \n" + + " int[][] j[] = null, k; // comment \n" + + " \n" + + " void bar(){ \n" + + " } \n" + + " void truc(){ \n" + + " } \n" + + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tint[][][] j;\n" + + "\tint[][] k;\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid baz() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test11: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 449, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + + assertEquals("Invalid declaration source start for field j", 102, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field j", 305, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field k", 102, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field k", 308, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 4, methods.length); + + assertEquals("Invalid declaration source start for method foo", 27, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 76, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method baz", 79, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method baz", 90, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 378, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 400, methods[2].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 414, methods[3].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 436, methods[3].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method baz", "baz", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[2].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[3].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test12() { + + String s = + "import java.util.Enumeration;\n" + + "import java.util.Hashtable;" + + "\n" + + "/** comment */\n" + + "public class A2 {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " void baz(){}\n" + + " /** comment\n" + + " *\n" + + " *\n" + + " */\n" + + " static { } // comment\n" + + " \n" + + "\n" + + " void bar(){\n" + + " }\n" + + " void truc(){\n" + + " }\n" + + "}\n"; + + String expectedUnitToString = + "import java.util.Enumeration;\n" + + "import java.util.Hashtable;\n" + + "public class A2 {\n" + + "\tstatic {}\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid baz() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test12: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 58, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 231, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("Invalid fields length ", 1, fields.length); + + assertEquals("Invalid declaration source start for initializer", 145, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for initializer", 181, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 4, methods.length); + + assertEquals("Invalid declaration source start for method foo", 92, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 128, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method baz", 131, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method baz", 142, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 183, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 212, methods[2].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 215, methods[3].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 229, methods[3].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method baz", "baz", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[2].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[3].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test13() { + + String s = + "import java.util.Enumeration;\n" + + "import java.util.Hashtable;\n" + + "\n" + + "public class A2 {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " void baz(){}\n" + + " static { }\n" + + " \n" + + "\n" + + " void bar(){\n" + + " }\n" + + " void truc(){\n" + + " }\n" + + "}\n"; + + String expectedUnitToString = + "import java.util.Enumeration;\n" + + "import java.util.Hashtable;\n" + + "public class A2 {\n" + + "\tstatic {}\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid baz() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + String testName = "test13: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 59, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 180, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + + assertEquals(" invalid fields length", 1, fields.length); + + assertEquals("Invalid declaration source start for initializer", 132, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for initializer", 141, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 4, methods.length); + + assertEquals("Invalid declaration source start for method foo", 78, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 114, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method baz", 117, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method baz", 128, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 148, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 161, methods[2].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 164, methods[3].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 178, methods[3].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method baz", "baz", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[2].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[3].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test14() { + + String s = + "import java.util.Enumeration;\n" + + "import java.util.Hashtable;\n" + + "\n" + + "public class A2 {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " void baz(){}\n" + + " static { }\n" + + " }\n" + + "\n" + + " void bar(){\n" + + " }\n" + + " void truc(){\n" + + " }\n" + + "}\n"; + + String expectedUnitToString = + "import java.util.Enumeration;\n" + + "import java.util.Hashtable;\n" + + "public class A2 {\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test14: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 59, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 180, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("Invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 78, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 144, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 148, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 161, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 164, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 178, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test15() { + + String s = + "public class X { \n" + + " class Y { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " public int h; \n" + + " public int[] i = {0, 1}; \n" + + " void bar(){ \n" + + " void baz(){ \n" + + " } \n"; + + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t\tpublic int h;\n" + + "\t\tpublic int[] i;\n" + + "\t\tjava.lang.Object(0)\n" + + "\t\tvoid foo() {}\n" + + "\t\tvoid bar() {}\n" + + "\t\tvoid baz() {}\n" + + "\t}\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test15: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 227, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals(" invalid members length ", 1, members.length); + + fields = members[0].getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" invalid fields length ", 2, fields.length); + + assertEquals("Invalid declaration source start for field h", 117, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 129, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 140, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 163, fields[1].getDeclarationSourceEnd()); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 48, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 103, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 171, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 191, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method baz", 193, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method baz", 215, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method baz", "baz", methods[2].getActualName()); + + SourceType member = members[0]; + assertEquals( + "Invalid class declarationSourceStart ", + 26, + member.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 227, + member.getDeclarationSourceEnd()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test16() { + + String s = + "public class X { \n" + + " class Y { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " public int h; \n" + + " public int[] i = {0, 1}; \n" + + " void bar(){ \n" + + " void baz(){ \n" + + " } \n"; + + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t\tpublic int h;\n" + + "\t\tpublic int[] i;\n" + + "\t\tvoid foo() {}\n" + + "\t\tvoid bar() {}\n" + + "\t\tvoid baz() {}\n" + + "\t}\n" + + "}"; + + String testName = "test16: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 227, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals(" invalid members length ", 1, members.length); + + fields = members[0].getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" invalid fields length ", 2, fields.length); + + assertEquals("Invalid declaration source start for field h", 117, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 129, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 140, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 163, fields[1].getDeclarationSourceEnd()); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid methods length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 48, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 103, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 171, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 191, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method baz", 193, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method baz", 215, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method baz", "baz", methods[2].getActualName()); + + SourceType member = members[0]; + assertEquals( + "Invalid class declarationSourceStart ", + 26, + member.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 227, + member.getDeclarationSourceEnd()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test17() { + + String s = + "public class X { \n" + + " class Y { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " public int h; \n" + + " public int[] i = {0, 1}; \n" + + " void bar(){ \n" + + " void baz(){ \n" + + " } \n"; + + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t\tjava.lang.Object(0)\n" + + "\t\tvoid foo() {}\n" + + "\t}\n" + + "\tpublic int h;\n" + + "\tpublic int[] i;\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid bar() {}\n" + + "\tvoid baz() {}\n" + + "}"; + + String testName = "test17: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 241, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" invalid fields length ", 2, fields.length); + + assertEquals("Invalid declaration source start for field h", 131, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 143, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 154, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 177, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid fields length ", 2, methods.length); + + assertEquals("Invalid declaration source start for method bar", 185, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 205, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method baz", 207, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method baz", 229, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method baz", "baz", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals(" invalid members length ", 1, members.length); + + fields = members[0].getFields(); + assertTrue(" invalid fields ", fields == null); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid methods length ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 48, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 103, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType member = members[0]; + assertEquals( + "Invalid class declarationSourceStart ", + 26, + member.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 117, + member.getDeclarationSourceEnd()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test18() { + + String s = + "public class X { \n" + + " class Y { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " public int h; \n" + + " public int[] i = {0, 1}; \n" + + " void bar(){ \n" + + " void baz(){ \n" + + " } \n"; + + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t\tvoid foo() {}\n" + + "\t}\n" + + "\tpublic int h;\n" + + "\tpublic int[] i;\n" + + "\tvoid bar() {}\n" + + "\tvoid baz() {}\n" + + "}"; + + String testName = "test18: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 241, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" invalid fields length ", 2, fields.length); + + assertEquals("Invalid declaration source start for field h", 131, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 143, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 154, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 177, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid fields length ", 2, methods.length); + + assertEquals("Invalid declaration source start for method bar", 185, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 205, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method baz", 207, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method baz", 229, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method baz", "baz", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals(" invalid members length ", 1, members.length); + + fields = members[0].getFields(); + assertTrue(" invalid fields ", fields == null); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid methods length ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 48, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 103, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType member = members[0]; + assertEquals( + "Invalid class declarationSourceStart ", + 26, + member.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 117, + member.getDeclarationSourceEnd()); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test19() { + + String s = + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + "} \n" + + " void bar(){ \n" + + " int x; \n" + + " void baz(){ \n" + + " } \n" + + " int y; \n"; + + + String expectedUnitToString = + "public class X {\n" + + "\t{}\n" + + "\tint y;\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid baz() {}\n" + + "}"; + + String testName = "test19: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 197, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" invalid fields length ", 2, fields.length); + + assertEquals("Invalid declaration source start for initializer", 90, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for initializer", 90, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field y", 181, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field y", 186, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid fields length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 26, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 77, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 104, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 143, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method baz", 145, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method baz", 167, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method baz", "baz", methods[2].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test20() { + + String s = + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + "} \n" + + " void bar(){ \n" + + " public int x; \n" + + " void baz(){ \n" + + " } \n" + + " int y; \n"; + + + String expectedUnitToString = + "public class X {\n" + + "\t{}\n" + + "\tpublic int x;\n" + + "\tint y;\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid baz() {}\n" + + "}"; + + String testName = "test20: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 201, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" invalid fields length ", 3, fields.length); + + assertEquals("Invalid declaration source start for initializer", 90, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for initializer", 90, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field x", 126, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 138, fields[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field y", 185, fields[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field y", 190, fields[2].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid fields length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 26, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 77, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 104, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 124, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method baz", 149, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method baz", 171, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method baz", "baz", methods[2].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test21() { + + String s = + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + "} \n" + + " void bar(){ \n" + + " public int x; \n" + + " void baz(){ \n" + + " } \n" + + " int y; \n"; + + + String expectedUnitToString = + "public class X {\n" + + "\t{}\n" + + "\tpublic int x;\n" + + "\tint y;\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid baz() {}\n" + + "}"; + + String testName = "test21: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 201, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" invalid fields length ", 3, fields.length); + + assertEquals("Invalid declaration source start for initializer", 90, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for initializer", 90, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field x", 126, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 138, fields[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field y", 185, fields[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field y", 190, fields[2].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid fields length ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 26, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 77, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 104, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 124, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method baz", 149, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method baz", 171, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method baz", "baz", methods[2].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test22() { + + String s = + "public class X extends { \n" + + " void foo() { \n" + + " } \n" + + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "}"; + + String testName = "test22: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 67, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid fields length ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 32, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 54, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test23() { + + String s = + "public class X extends Thread { \n" + + " void foo() throws \n" + + " void bar() \n" + + " } \n" + + "} \n"; + + String expectedUnitToString = + "public class X extends Thread {\n" + + "\tThread(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "}"; + + String testName = "test23: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 98, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid fields length ", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 37, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 61, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 63, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 85, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test24() { + + String s = + "public class X implements \n" + + " void foo() \n" + + " void bar() \n" + + " } \n" + + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "}"; + + String testName = "test24: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 91, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid fields length ", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 34, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 54, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 56, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 78, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test25() { + + String s = + "public class X implements Y, \n" + + " void foo() \n" + + " void bar() \n" + + " } \n" + + "} \n"; + + String expectedUnitToString = + "public class X implements Y, {\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "}"; + + String testName = "test25: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 92, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("contains superinterfaces " , this.currentType.getInterfaceNames() != null); + assertEquals(" invalid superinterfaces length ", 1, this.currentType.getInterfaceNames().length); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" invalid fields length ", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 35, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 55, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 57, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 79, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test26() { + + String s = + "public class X implements \n" + + " class Y { \n" + + " void bar() \n" + + " } \n" + + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t\tjava.lang.Object(0)\n" + + "\t\tvoid bar() {}\n" + + "\t}\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test26: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 102, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals(" contains one member ", 1, members.length); + + assertEquals( + "Invalid class declarationSourceStart ", + 34, + members[0].getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 90, + members[0].getDeclarationSourceEnd()); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains one method ", 1, methods.length); + + assertEquals("Invalid declaration source start for method bar", 56, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 77, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[0].getActualName()); + + members = members[0].getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test27() { + + String s = + "public class X \n" + + " fieldX; \n" + + " class Y { \n" + + " void bar() \n" + + " } \n" + + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t\tjava.lang.Object(0)\n" + + "\t\tvoid bar() {}\n" + + "\t}\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test27: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 113, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals(" contains one member ", 1, members.length); + + assertEquals( + "Invalid class declarationSourceStart ", + 45, + members[0].getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 101, + members[0].getDeclarationSourceEnd()); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains one method ", 1, methods.length); + + assertEquals("Invalid declaration source start for method bar", 67, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 88, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[0].getActualName()); + + members = members[0].getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test28() { + + String s = + "public class X \n" + + " fieldX; \n" + + " class Y \n" + + " } \n" + + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t\tjava.lang.Object(0)\n" + + "\t}\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test28: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 78, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals(" contains one member ", 1, members.length); + + assertEquals( + "Invalid class declarationSourceStart ", + 45, + members[0].getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 65, + members[0].getDeclarationSourceEnd()); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods == null); + + members = members[0].getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test29() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " class L extends { \n" + + " public int l; \n" + + " void baz(){} \n" + + " } \n" + + " \n" + + " public int h; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tpublic int h;\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test29: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 88, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 357, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("contains one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field h", 276, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 288, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains 3 methods ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 114, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 250, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 312, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 332, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 334, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 355, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test30() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " class L extends { \n" + + " public int l; \n" + + " void baz(){} \n" + + " } \n" + + " \n" + + " public int h; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tpublic int h;\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test30: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 88, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 357, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("contains one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field h", 276, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 288, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains 3 methods ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 114, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 250, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 312, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 332, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 334, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 355, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test31() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " new X(){ \n" + + " void baz() {} \n" + + " }.baz(); \n" + + " \n" + + " public int h; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tpublic int h;\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test31: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 89, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 334, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("contains one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field h", 253, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 265, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains 3 methods ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 115, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 251, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 289, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 309, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 311, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 332, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test32() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " new X(){ \n" + + " void baz() {} \n" + + " \n" + + " public int h; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "}"; + + String testName = "test32: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 89, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 315, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains one methods ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 115, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 315, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test33() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " new X(){ \n" + + " void baz() {} \n" + + " \n" + + " public int h; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tvoid foo() {}\n" + + "}"; + + String testName = "test33: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 89, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 315, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains one methods ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 115, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 315, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test34() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " new X(){ \n" + + " void baz() \n" + + " } \n" + + " } \n" + + " public int h; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tpublic int h;\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test34: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 88, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 342, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("contains one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field h", 250, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field h", 262, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains 3 methods ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 114, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 236, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 286, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 306, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 308, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 329, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test35() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " class L extends { \n" + + " public int l; \n" + + " void baz(){} \n" + + " } \n" + + " \n" + + " int h; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test35: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 76, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 309, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains 3 methods ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 99, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 260, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 262, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 279, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 281, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 299, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test36() { + + String s = + "package a; \n" + + "import java.lang.*; \n" + + "import java.util.*; \n" + + " \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " \n" + + " class L extends { \n" + + " public int l; \n" + + " void baz(){} \n" + + " } \n" + + " \n" + + " int h; \n" + + " \n" + + " void bar(){ \n" + + " void truc(){ \n" + + "} \n"; + + String expectedUnitToString = + "package a;\n" + + "import java.lang.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + "\tvoid foo() {}\n" + + "\tvoid bar() {}\n" + + "\tvoid truc() {}\n" + + "}"; + + String testName = "test36: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 76, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 309, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains 3 methods ", 3, methods.length); + + assertEquals("Invalid declaration source start for method foo", 99, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 260, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 262, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 279, methods[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method truc", 281, methods[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method truc", 299, methods[2].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + assertEquals(" Invalid actual name for method truc", "truc", methods[2].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test37() { + + String s = + "public class X { \n" + + " int x; \n" + + " \n" + + " int foo(){ } \n" + + " \n" + + " class Y { \n" + + " int y; \n" + + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t\tint y;\n" + + "\t\tjava.lang.Object(0)\n" + + "\t}\n" + + "\tint x;\n" + + "\tjava.lang.Object(0)\n" + + "\tint foo() {}\n" + + "}"; + + String testName = "test37: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 112, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("contains one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field x", 23, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 28, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains one methods ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 46, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 57, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals("contains one member ", 1, members.length); + + assertEquals( + "Invalid class declarationSourceStart ", + 73, + members[0].getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 104, + members[0].getDeclarationSourceEnd()); + + fields = members[0].getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("contains one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field y", 92, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field y", 97, fields[0].getDeclarationSourceEnd()); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test38() { + + String s = + "public class X { \n" + + " int x; \n" + + " \n" + + " int foo(){ } \n" + + " \n" + + " class Y { \n" + + " int y; \n" + + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t\tint y;\n" + + "\t}\n" + + "\tint x;\n" + + "\tint foo() {}\n" + + "}"; + + String testName = "test38: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 112, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("contains one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field x", 23, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 28, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains one methods ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 46, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 57, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals("contains one member ", 1, members.length); + + assertEquals( + "Invalid class declarationSourceStart ", + 73, + members[0].getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 104, + members[0].getDeclarationSourceEnd()); + + fields = members[0].getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("contains one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field y", 92, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field y", 97, fields[0].getDeclarationSourceEnd()); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test39() { + + String s = + "public class X { \n" + + " int x; \n" + + " \n" + + " int foo(){ } \n" + + " \n" + + " class Y \n" + + "} \n" + + " int y; \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t\tjava.lang.Object(0)\n" + + "\t}\n" + + "\tint x;\n" + + "\tint y;\n" + + "\tjava.lang.Object(0)\n" + + "\tint foo() {}\n" + + "}"; + + String testName = "test39: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 109, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("contains one field ", 2, fields.length); + + assertEquals("Invalid declaration source start for field x", 23, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 28, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field y", 98, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field y", 103, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains one methods ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 46, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 57, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals("contains one member ", 1, members.length); + + assertEquals( + "Invalid class declarationSourceStart ", + 73, + members[0].getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 87, + members[0].getDeclarationSourceEnd()); + + fields = members[0].getFields(); + assertTrue(" invalid fields ", fields == null); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test40() { + + String s = + "public class X { \n" + + " int x; \n" + + " \n" + + " int foo(){ } \n" + + " \n" + + " class Y \n" + + "} \n" + + " int y; \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tclass Y {\n" + + "\t}\n" + + "\tint x;\n" + + "\tint y;\n" + + "\tint foo() {}\n" + + "}"; + + String testName = "test40: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 109, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("contains one field ", 2, fields.length); + + assertEquals("Invalid declaration source start for field x", 23, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 28, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field y", 98, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field y", 103, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains one methods ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 46, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 57, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members != null); + assertEquals("contains one member ", 1, members.length); + + assertEquals( + "Invalid class declarationSourceStart ", + 73, + members[0].getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 87, + members[0].getDeclarationSourceEnd()); + + fields = members[0].getFields(); + assertTrue(" invalid fields ", fields == null); + + methods = members[0].getMethods(); + assertTrue(" invalid methods ", methods == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test41() { + + String s = + "public class X { \n"+ + " void hell" + "\\" + "u006f()\n"+ + " static void foo() { \n"+ + " X x; \n"+ + " x = new X(23); \n"+ + " System.out.println(); \n"+ + " \n"+ + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tjava.lang.Object(0)\n" + + "\tvoid hello() {}\n" + + "\tstatic void foo() {}\n" + + "}"; + + String testName = "test41: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 139, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals(" contains one methods ", 2, methods.length); + + assertEquals("Invalid declaration source start for method hello", 22, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method hello", 39, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method foo", 41, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 130, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method hello", "hell" + "\\" + "u006f", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test42() { + + String s = + "public class X { \n" + + " int x \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tint x;\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test42: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 29, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" contains one field", 1, fields.length); + + assertEquals("Invalid declaration source start for field x", 20, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 24, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test43() { + + String s = + "public class X { \n" + + " int x \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tint x;\n" + + "}"; + + String testName = "test43: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 29, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" contains one field", 1, fields.length); + + assertEquals("Invalid declaration source start for field x", 20, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 24, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test44() { + + String s = + "public class X { \n" + + " int x, y \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tint x;\n" + + "\tint y;\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test44: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 31, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" contains one field", 2, fields.length); + + assertEquals("Invalid declaration source start for field x", 20, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 25, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field y", 20, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field y", 27, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test45() { + + String s = + "public class X { \n" + + " int x, y \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tint x;\n" + + "\tint y;\n" + + "}"; + + String testName = "test45: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 31, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" contains one field", 2, fields.length); + + assertEquals("Invalid declaration source start for field x", 20, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 25, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field y", 20, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field y", 27, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test46() { + + String s = + "public class X { \n" + + " String s = \" \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tString s;\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test46: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 34, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" contains one field", 1, fields.length); + + assertEquals("Invalid declaration source start for field s", 20, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field s", 34, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test47() { + + String s = + "public class X { \n" + + " String s = \" \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tString s;\n" + + "}"; + + String testName = "test47: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 34, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("doesn't contain superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" contains one field", 1, fields.length); + + assertEquals("Invalid declaration source start for field s", 20, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field s", 34, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test48() { + + String s = + "public class X implements Y, \n" + + " String s = \" \n"; + + String expectedUnitToString = + "public class X implements Y, String, {\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test48: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 50, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has 2 superinterfaces " , this.currentType.getInterfaceNames() != null); + assertEquals("2 superinterfaces " , 2, this.currentType.getInterfaceNames().length); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test49() { + + String s = + "public class X implements Y, \n" + + " String s = \" \n"; + + String expectedUnitToString = + "public class X implements Y, String, {\n" + + "}"; + + String testName = "test49: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 50, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has 2 superinterfaces " , this.currentType.getInterfaceNames() != null); + assertEquals("2 superinterfaces " , 2, this.currentType.getInterfaceNames().length); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test50() { + + String s = + "public class X implements \n"+ + "int x \n"+ + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tint x;\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test50: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 42, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field x", 29, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 33, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test51() { + + String s = + "public class X implements \n"+ + "int x \n"+ + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tint x;\n" + + "}"; + + String testName = "test51: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 42, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field x", 29, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 33, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test52() { + + String s = + "public class X public int foo(int bar(static String s"; + + String expectedUnitToString = + "public class X {\n" + + "\tstatic String s;\n" + + "\tjava.lang.Object(0)\n" + + "\tpublic int foo() {}\n" + + "\tint bar() {}\n" + + "}"; + + String testName = "test52: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 52, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field s", 38, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field s", 52, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + + assertEquals("Invalid declaration source start for method foo", 15, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 29, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 30, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 37, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test53() { + + String s = + "public class X public int foo(int x, int bar public String s;"; + + String expectedUnitToString = + "public class X {\n" + + "\tpublic String s;\n" + + "\tjava.lang.Object(0)\n" + + "\tpublic int foo(int x, int bar, ) {}\n" + + "}"; + + String testName = "test53: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 60, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has one field ", 1, fields.length); + + assertEquals("Invalid declaration source start for field s", 45, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field s", 60, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has one method ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 15, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 44, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test54() { + + String s = + "public class X \n" + + " public int foo( \n" + + " int bar( \n" + + " static String s, int x \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tstatic String s;\n" + + "\tint x;\n" + + "\tjava.lang.Object(0)\n" + + "\tpublic int foo() {}\n" + + "\tint bar() {}\n" + + "}"; + + String testName = "test54: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 78, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has 2 fields ", 2, fields.length); + + assertEquals("Invalid declaration source start for field s", 55, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field s", 70, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field x", 72, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 76, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has 2 methods ", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 20, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 38, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 40, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 52, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test55() { + + String s = + "public class X \n" + + " public int foo( \n" + + " int bar( \n" + + " static String s, int x \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tstatic String s;\n" + + "\tint x;\n" + + "\tpublic int foo() {}\n" + + "\tint bar() {}\n" + + "}"; + + String testName = "test55: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 78, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has 2 fields ", 2, fields.length); + + assertEquals("Invalid declaration source start for field s", 55, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field s", 70, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field x", 72, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 76, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has 2 methods ", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 20, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 38, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method bar", 40, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method bar", 52, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method bar", "bar", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test56() { + + String s = + "class X { \n" + + " String s; \n" + + " \n" + + " public void foo( \n" + + " static int x \n" + + "} \n"; + + + String expectedUnitToString = + "class X {\n" + + "\tString s;\n" + + "\tstatic int x;\n" + + "\tjava.lang.Object(0)\n" + + "\tpublic void foo() {}\n" + + "}"; + + String testName = "test56: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 75, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has 2 fields ", 2, fields.length); + + assertEquals("Invalid declaration source start for field s", 16, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field s", 24, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field x", 60, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 71, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has 1 method ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 39, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 57, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test57() { + + String s = + "class X { \n" + + " String s; \n" + + " \n" + + " public void foo( \n" + + " static int x \n" + + "} \n"; + + + String expectedUnitToString = + "class X {\n" + + "\tString s;\n" + + "\tstatic int x;\n" + + "\tpublic void foo() {}\n" + + "}"; + + String testName = "test57: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 75, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has 2 fields ", 2, fields.length); + + assertEquals("Invalid declaration source start for field s", 16, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field s", 24, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field x", 60, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 71, fields[1].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has 1 method ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 39, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 57, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test58() { + + String s = + "public class X { \n"+ + " int foo(){ \n"+ + " String s = \" \n"+ + " } \n"+ + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tjava.lang.Object(0)\n" + + "\tint foo() {}\n" + + "}"; + + String testName = "test58: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 62, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has 1 method ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 21, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 54, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test59() { + + String s = + + "class X { \n" + + " int foo(AA a, BB b, IOEx \n" + + " \n"; + + String expectedUnitToString = + "class X {\n" + + "\tjava.lang.Object(0)\n" + + "\tint foo(AA a, BB b, ) {}\n" + + "}"; + + String testName = "test59: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 60, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has 1 method ", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 20, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 60, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test60() { + + String s = + "public class X { \n"+ + " final static int foo(){ \n"+ + " return \"1; \n"+ + " } \n"+ + " public static void main(String argv[]){ \n"+ + " foo(); \n"+ + " } \n"+ + "} \n"; + + String expectedUnitToString = + "public class X {\n" + + "\tjava.lang.Object(0)\n" + + "\tfinal static int foo() {}\n" + + "\tpublic static void main(String[] argv, ) {}\n" + + "}"; + + String testName = "test60: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 161, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has 1 method ", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 25, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 75, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method main", 89, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method main", 148, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method main", "main", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test61() { + + String s = + "public class X { \n"+ + " { \n"+ + " int x;"; + + String expectedUnitToString = + "public class X {\n" + + "\t{}\n" + + "\tjava.lang.Object(0)\n" + + "}"; + + String testName = "test61: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 47, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + + assertEquals("Invalid declaration source start for initializer", 25, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for initializer", 47, fields[0].getDeclarationSourceEnd()); + + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test62() { + + String s = + "public class X { \n"+ + " int foo(){ \n"+ + " if(true){ \n"+ + " int x;"; + + String expectedUnitToString = + "public class X {\n" + + "\tjava.lang.Object(0)\n" + + "\tint foo() {}\n" + + "}"; + + String testName = "test62: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 78, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has one method", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 27, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 78, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test63() { + + String s = + "public class X { \n"+ + " int foo(){} \n"+ + "} \n"+ + "int x;\n"; + + String expectedUnitToString = + "public class X {\n" + + "\tint x;\n" + + "\tjava.lang.Object(0)\n" + + "\tint foo() {}\n" + + "}"; + + String testName = "test63: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 66, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has one field", 1, fields.length); + + assertEquals("Invalid declaration source start for field x", 60, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 65, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has one method", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 27, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 37, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test64() { + + String s = + "public class X { \n"+ + " int foo(){} \n"+ + "} \n"+ + "int x;\n"; + + String expectedUnitToString = + "public class X {\n" + + "\tint x;\n" + + "\tint foo() {}\n" + + "}"; + + String testName = "test64: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 66, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has one field", 1, fields.length); + + assertEquals("Invalid declaration source start for field x", 60, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field x", 65, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has one method", 1, methods.length); + + assertEquals("Invalid declaration source start for method foo", 27, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 37, methods[0].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test65() { + + String s = + "public class X { \n"+ + " int foo(){} \n"+ + "} \n"+ + "int x();\n"; + + String expectedUnitToString = + "public class X {\n" + + "\t{}\n" + + "\tint foo() {}\n" + + "\tint x() {}\n" + + "}"; + + String testName = "test65: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 68, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals(" invalid fields length ", 1, fields.length); + + assertEquals("Invalid declaration source start for initializer", 47, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for initializer", 47, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has two methods", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 27, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 37, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method x", 60, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method x", 67, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method x", "x", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test66() { + + String s = + "public interface X { \n"+ + " int foo() {}; \n"+ + "} \n"+ + "int x();\n"; + + String expectedUnitToString = + "public interface X {\n" + + "\tint foo() {}\n" + + "\tint x() {}\n" + + "}"; + + String testName = "test66: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 72, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has two methods", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 30, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 41, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method x", 64, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method x", 71, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method x", "x", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test67() { + + String s = + "public interface X { \n"+ + " int foo() {}; \n"+ + " int x(); \n"+ + "}"; + + String expectedUnitToString = + "public interface X {\n" + + "\tint foo() {}\n" + + "\tint x() {}\n" + + "}"; + + String testName = "test67: diet parse"; + dietParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 71, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has two methods", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 30, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 41, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method x", 54, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method x", 61, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method x", "x", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test68() { + + String s = + "public interface X { \n"+ + " int foo() {}; \n"+ + " int x(); \n"+ + "}"; + + String expectedUnitToString = + "public interface X {\n" + + "\tint foo() {}\n" + + "\tint x() {}\n" + + "}"; + + String testName = "test68: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 71, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has two methods", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 30, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 41, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method x", 54, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method x", 61, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method x", "x", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test69() { + + String s = + "public interface X { \n"+ + "float y; \n"+ + " int foo() ; \n"+ + " int x(); \n"+ + "}"; + + String expectedUnitToString = + "public interface X {\n" + + "\tfloat y;\n" + + "\tint foo() {}\n" + + "\tint x() {}\n" + + "}"; + + String testName = "test69: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 87, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has one field", 1, fields.length); + + assertEquals("Invalid declaration source start for field y", 27, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field y", 34, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has two methods", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 48, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 58, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method x", 70, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method x", 77, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method x", "x", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test70() { + + String s = + "public interface X { \n"+ + " int foo(); \n"+ + " int x(); \n"+ + "}"; + + String expectedUnitToString = + "public interface X {\n" + + "\tint foo() {}\n" + + "\tint x() {}\n" + + "}"; + + String testName = "test70: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 69, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields == null); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has two methods", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 30, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 39, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method x", 52, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method x", 59, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method x", "x", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test71() { + + String s = + "public interface X { \n"+ + " int[] i = ; \n"+ + " int foo() {} \n"+ + " int x(); \n"+ + "}"; + + String expectedUnitToString = + "public interface X {\n" + + "\tint[] i;\n" + + "\tint foo() {}\n" + + "\tint x() {}\n" + + "}"; + + String testName = "test71: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 93, + this.currentType.getDeclarationSourceEnd()); + + assertTrue("has no superinterfaces " , this.currentType.getInterfaceNames() == null); + + SourceField[] fields = this.currentType.getFields(); + assertTrue(" invalid fields ", fields != null); + assertEquals("has one field", 1, fields.length); + + assertEquals("Invalid declaration source start for field i", 30, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field i", 49, fields[0].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods != null); + assertEquals("has two methods", 2, methods.length); + + assertEquals("Invalid declaration source start for method foo", 53, methods[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method foo", 64, methods[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for method x", 76, methods[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for method x", 83, methods[1].getDeclarationSourceEnd()); + + assertEquals(" Invalid actual name for method foo", "foo", methods[0].getActualName()); + + assertEquals(" Invalid actual name for method x", "x", methods[1].getActualName()); + + SourceType[] members = this.currentType.getMemberTypes(); + assertTrue(" invalid members ", members == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test72() { + + String s = + "public class X { \n"+ + " X() { \n" + + " this(); \n" + + " } \n" + + "}"; + + String expectedUnitToString = + "public class X {\n" + + "\tX() {\n" + + "\t\tX(0)\n" + + "\t}\n" + + "}"; + + String testName = "test72: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test73() { + + String s = + "public class X extends Toto { \n"+ + " X() { \n" + + " this(); \n" + + " } \n" + + " X(int i) { \n" + + " super(); \n" + + " } \n" + + " X() { \n" + + " this(0); \n" + + " } \n" + + "}"; + + String expectedUnitToString = + "public class X extends Toto {\n" + + "\tX() {\n" + + "\t\tX(0)\n" + + "\t}\n" + + "\tX(int i, ) {\n" + + "\t\tToto(0)\n" + + "\t}\n" + + "\tX() {\n" + + "\t\tX(1)\n" + + "\t}\n" + + "}"; + + String testName = "test73: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test74() { + + String s = + "public class X extends Toto { \n"+ + " class Y extends Throwable { \n" + + " } \n" + + " X() { \n" + + " this(); \n" + + " } \n" + + " X(int i) { \n" + + " super(); \n" + + " } \n" + + " X() { \n" + + " this(0); \n" + + " } \n" + + " public Object foo(int i) { \n" + + " return new Object() {}; \n" + + " } \n" + + "}"; + + String expectedUnitToString = + "public class X extends Toto {\n" + + "\tclass Y extends Throwable {\n" + + "\t\tThrowable(0)\n" + + "\t}\n" + + "\tX() {\n" + + "\t\tX(0)\n" + + "\t}\n" + + "\tX(int i, ) {\n" + + "\t\tToto(0)\n" + + "\t}\n" + + "\tX() {\n" + + "\t\tX(1)\n" + + "\t}\n" + + "\tpublic Object foo(int i, ) {}\n" + + "}"; + + String testName = "test74: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +/* + * bugs 16126 + */ +public void test75() { + String s = + "public class P#AField {\n" + + " public void setP#A(String P#A) {\n" + + " this.P#A = P#A;\n" + + " }\n" + + "}"; + + String expectedUnitToString = + "public class P {\n" + + " {}\n" + + " public void setP;\n" + + " java.lang.Object(0)\n" + + " A(String P, ) {}\n" + + "}"; + + String testName = "test75: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test76() { + + String s = + "class X {\n" + + " public static int j = 0;\n" + + " /* static */ {\n" + + " }" + + " public static int i = 9;\n" + + "}\n"; + + String expectedUnitToString = + "class X {\n" + + " public static int j;\n" + + " {}\n" + + " public static int i;\n" + + " java.lang.Object(0)\n" + + "}"; + + String testName = "test76: full parse"; + fullParse(s,testName); + + assertEquals( + "Invalid class declarationSourceStart ", + 0, + this.currentType.getDeclarationSourceStart()); + + assertEquals( + "Invalid class declarationSourceEnd ", + 84, + this.currentType.getDeclarationSourceEnd()); + + SourceField[] fields = this.currentType.getFields(); + assertTrue("invalid fields ", fields != null); + assertEquals("Invalid fields length ", 3, fields.length); + + assertEquals("Invalid declaration source start for field j", 12, fields[0].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for field j", 35, fields[0].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for initializer", 39, fields[1].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end for initializer", 56, fields[1].getDeclarationSourceEnd()); + + assertEquals("Invalid declaration source start for field i", 59, fields[2].getDeclarationSourceStart()); + assertEquals("Invalid declaration source end field i", 82, fields[2].getDeclarationSourceEnd()); + + SourceMethod[] methods = this.currentType.getMethods(); + assertTrue(" invalid methods ", methods == null); + + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +/** + * Bug 99662:[1.5] JavaModel returns inexistent IType for package-info ICompilationUnits + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=99662" + * + */ +public void testBug99662() { + + String s = + "@Deprecated\n" + + "package p;\n"; + + String testName = "package-info.java"; + fullParse(s,testName); + + assertNull("package-info.java file should not have ANY type!", this.currentType); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=167357 +public void _test77() { + + String s = + "public class X {\n" + + " void foo() {\n" + + " class Y {\n" + + " String s = null;\n" + + " {\n" + + " class Z {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + + String expectedUnitToString = + "public class X implements Y, String, {\n" + + "}"; + + String testName = "test77: diet parse"; + dietParse(s,testName, true); + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=167357 +public void _test78() { + + String s = + "public class X {\n" + + " void foo() {\n" + + " class Y {\n" + + " String s = null;\n" + + " {\n" + + " class Z {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + + String expectedUnitToString = + "public class X implements Y, String, {\n" + + "}"; + + String testName = "test78: full parse"; + fullParse(s,testName, true); + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=167357 +public void _test79() { + + String s = + "public class X {\n" + + " void foo() {\n" + + " class Y {\n" + + " {\n" + + " class Z {\n" + + " }\n" + + " }\n" + + " String s = null;\n" + + " }\n" + + " }\n" + + "}"; + + String expectedUnitToString = + "public class X implements Y, String, {\n" + + "}"; + + String testName = "test79: diet parse"; + dietParse(s,testName, true); + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=167357 +public void _test80() { + + String s = + "public class X {\n" + + " void foo() {\n" + + " class Y {\n" + + " {\n" + + " class Z {\n" + + " }\n" + + " }\n" + + " String s = null;\n" + + " }\n" + + " }\n" + + "}"; + + String expectedUnitToString = + "public class X implements Y, String, {\n" + + "}"; + + String testName = "test80: full parse"; + fullParse(s,testName, true); + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +public void test81() { + + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + + String s = + "import java.util.Collection;\n" + + "\n" + + "public class X {\n" + + " public abstract class AbstractData {}\n" + + " \n" + + " public interface IScalarData {}\n" + + "\n" + + " private static interface ValueObjectPropertyIterator {\n" + + " public void iterateOnValueObjectProperty(IScalarData scalarObject, T valueObject, Class valueObjectType, final String name, final Class scalarType) throws Exception;\n" + + " }\n" + + "\n" + + " private static void iterateOnValueObjectProperties(IScalarData scalarObject, T valueObject, ValueObjectPropertyIterator valueObjectPropertyIterator) {}\n" + + " \n" + + " public static void loadScalarFromValueObject(IScalarData scalarObject, T valueObject) {\n" + + " iterateOnValueObjectProperties(scalarObject, valueObject, new ValueObjectPropertyIterator() {\n" + + " public void iterateOnValueObjectProperty(IScalarData scalarObject, T valueObject, Class valueObjectType, String name, Class scalarType) throws Exception {\n" + + " if (true) {\n" + + " if (true) {\n" + + " if (true) {\n" + + " final Collection> lazyCollection = createLazyCollection(\n" + + " name, scalarType, null, null,\n" + + " new CollectionProviderForTargetCollection>() {\n" + + " @Override\n" + + " public Collection> provideCollection(\n" + + " final Collection targetCollection, final Class> scalarCollectionType) {\n" + + " return null;\n" + + " }\n" + + " });\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " abstract class CollectionProviderForTargetCollection {\n" + + " abstract public Collection provideCollection(Collection targetCollection, Class scalarCollectionType);\n" + + " }\n" + + "\n" + + " private Collection createLazyCollection(String name,\n" + + " Class scalarType, final Collection valueObjectCollection,\n" + + " final Class scalarCollectionType, CollectionProviderForTargetCollection collectionProvider) {\n" + + " return null;\n" + + " }\n" + + " });\n" + + " }\n" + + "}"; + + String expectedUnitToString = + "import java.util.Collection;\n" + + "public class X {\n" + + " public abstract class AbstractData {\n" + + " java.lang.Object(0)\n" + + " }\n" + + " public interface IScalarData {\n" + + " }\n" + + " private static interface ValueObjectPropertyIterator {\n" + + " public void iterateOnValueObjectProperty(IScalarData scalarObject, T valueObject, Class valueObjectType, String name, Class scalarType, ) throws Exception, {}\n" + + " }\n" + + " java.lang.Object(0)\n" + + " private static void iterateOnValueObjectProperties(IScalarData scalarObject, T valueObject, ValueObjectPropertyIterator valueObjectPropertyIterator, ) {}\n" + + " public static void loadScalarFromValueObject(IScalarData scalarObject, T valueObject, ) {}\n" + + "}"; + + String testName = "test81: full parse"; + fullParse(s,testName, options); + assertEquals( + "Invalid source " + testName, + expectedUnitToString, + this.currentType.toString()); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceField.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceField.java new file mode 100644 index 0000000000..14e9d87f34 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceField.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.env.ISourceField; + +public class SourceField implements ISourceField { + protected int modifiers; + protected char[] typeName; + protected char[] name; + protected int declarationStart; + protected int declarationEnd; + protected int nameSourceStart; + protected int nameSourceEnd; + protected char[] source; +public SourceField( + int declarationStart, + int modifiers, + char[] typeName, + char[] name, + int nameSourceStart, + int nameSourceEnd, + char[] source) { + + this.declarationStart = declarationStart; + this.modifiers = modifiers; + this.typeName = typeName; + this.name = name; + this.nameSourceStart = nameSourceStart; + this.nameSourceEnd = nameSourceEnd; + this.source = source; +} +public String displayModifiers() { + StringBuilder buffer = new StringBuilder(); + + if (this.modifiers == 0) + return null; + if ((this.modifiers & ClassFileConstants.AccPublic) != 0) + buffer.append("public "); + if ((this.modifiers & ClassFileConstants.AccProtected) != 0) + buffer.append("protected "); + if ((this.modifiers & ClassFileConstants.AccPrivate) != 0) + buffer.append("private "); + if ((this.modifiers & ClassFileConstants.AccFinal) != 0) + buffer.append("final "); + if ((this.modifiers & ClassFileConstants.AccStatic) != 0) + buffer.append("static "); + if ((this.modifiers & ClassFileConstants.AccAbstract) != 0) + buffer.append("abstract "); + if ((this.modifiers & ClassFileConstants.AccNative) != 0) + buffer.append("native "); + if ((this.modifiers & ClassFileConstants.AccSynchronized) != 0) + buffer.append("synchronized "); + return buffer.toString(); +} +public String getActualName() { + StringBuilder buffer = new StringBuilder(); + buffer.append(this.source, this.nameSourceStart, this.nameSourceEnd - this.nameSourceStart + 1); + return buffer.toString(); +} +public int getDeclarationSourceEnd() { + return this.declarationEnd; +} +public int getDeclarationSourceStart() { + return this.declarationStart; +} +public char[] getInitializationSource() { + return null; +} +public int getModifiers() { + return this.modifiers; +} +public char[] getName() { + return this.name; +} +public int getNameSourceEnd() { + return this.nameSourceEnd; +} +public int getNameSourceStart() { + return this.nameSourceStart; +} +public char[] getTypeName() { + return this.typeName; +} +protected void setDeclarationSourceEnd(int position) { + this.declarationEnd = position; +} +public String tabString(int tab) { + /*slow code*/ + + String s = ""; + for (int i = tab; i > 0; i--) + s = s + "\t"; + return s; +} +@Override +public String toString() { + return toString(0); +} +public String toString(int tab) { + StringBuilder buffer = new StringBuilder(); + buffer.append(tabString(tab)); + String displayModifiers = displayModifiers(); + if (displayModifiers != null) { + buffer.append(displayModifiers); + } + buffer.append(this.typeName).append(" ").append(this.name); + buffer.append(";"); + return buffer.toString(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceImport.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceImport.java new file mode 100644 index 0000000000..6c367b43f6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceImport.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +public class SourceImport { + int declarationSourceStart; + int declarationSourceEnd; + char[] name; + boolean onDemand; + int modifiers; + char[] source; +/** + * @param declarationSourceStart int + * @param declarationSourceEnd int + * @param name char[] + * @param onDemand boolean + */ +public SourceImport( + int declarationSourceStart, + int declarationSourceEnd, + char[] name, + boolean onDemand, + int modifiers, + char[] source) { + + this.declarationSourceStart = declarationSourceStart; + this.declarationSourceEnd = declarationSourceEnd; + this.name = name; + this.onDemand = onDemand; + this.modifiers = modifiers; + this.source = source; +} +/** + * + * @return java.lang.String + */ +@Override +public String toString() { + StringBuilder buffer = new StringBuilder(); + buffer + .append( + this.source, + this.declarationSourceStart, + this.declarationSourceEnd - this.declarationSourceStart + 1) + .append("\n"); + return buffer.toString(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceInitializer.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceInitializer.java new file mode 100644 index 0000000000..df4cc46476 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceInitializer.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +public class SourceInitializer extends SourceField { +public SourceInitializer( + int declarationStart, + int modifiers) { + super(declarationStart, modifiers, null, null, -1, -1, null); +} + +@Override +public void setDeclarationSourceEnd(int declarationSourceEnd) { + this.declarationEnd = declarationSourceEnd; +} + +@Override +public String toString(int tab) { + if (this.modifiers == ClassFileConstants.AccStatic) { + return tabString(tab) + "static {}"; + } + return tabString(tab) + "{}"; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceMethod.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceMethod.java new file mode 100644 index 0000000000..7e2bf6ae11 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceMethod.java @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.env.ISourceMethod; + +public class SourceMethod implements ISourceMethod { + private int modifiers; + private int declarationStart; + private int declarationEnd; + private char[] returnTypeName; + private char[] selector; + private int nameSourceStart; + private int nameSourceEnd; + private char[][] argumentTypeNames; + private char[][] argumentNames; + private char[][] exceptionTypeNames; + private char[] source; + private String explicitConstructorCall; + char[][] typeParameterNames; + char[][][] typeParameterBounds; + +public SourceMethod( + int declarationStart, + int modifiers, + char[] returnTypeName, + char[] selector, + int nameSourceStart, + int nameSourceEnd, + char[][] argumentTypeNames, + char[][] argumentNames, + char[][] exceptionTypeNames, + char[] source) { + + this.declarationStart = declarationStart; + this.modifiers = modifiers; + this.returnTypeName = returnTypeName; + this.selector = selector; + this.nameSourceStart = nameSourceStart; + this.nameSourceEnd = nameSourceEnd; + this.argumentTypeNames = argumentTypeNames; + this.argumentNames = argumentNames; + this.exceptionTypeNames = exceptionTypeNames; + this.source = source; +} +public String displayModifiers() { + StringBuilder buffer = new StringBuilder(); + + if (this.modifiers == 0) + return null; + if ((this.modifiers & ClassFileConstants.AccPublic) != 0) + buffer.append("public "); + if ((this.modifiers & ClassFileConstants.AccProtected) != 0) + buffer.append("protected "); + if ((this.modifiers & ClassFileConstants.AccPrivate) != 0) + buffer.append("private "); + if ((this.modifiers & ClassFileConstants.AccFinal) != 0) + buffer.append("final "); + if ((this.modifiers & ClassFileConstants.AccStatic) != 0) + buffer.append("static "); + if ((this.modifiers & ClassFileConstants.AccAbstract) != 0) + buffer.append("abstract "); + if ((this.modifiers & ClassFileConstants.AccNative) != 0) + buffer.append("native "); + if ((this.modifiers & ClassFileConstants.AccSynchronized) != 0) + buffer.append("synchronized "); + if (buffer.toString().trim().equals("")) + return null; + return buffer.toString().trim(); +} +public String getActualName() { + StringBuilder buffer = new StringBuilder(); + buffer.append(this.source, this.nameSourceStart, this.nameSourceEnd - this.nameSourceStart + 1); + return buffer.toString(); +} +public char[][] getArgumentNames() { + return this.argumentNames; +} +public char[][] getArgumentTypeNames() { + return this.argumentTypeNames; +} +public int getDeclarationSourceEnd() { + return this.declarationEnd; +} +public int getDeclarationSourceStart() { + return this.declarationStart; +} +public char[][] getExceptionTypeNames() { + return this.exceptionTypeNames; +} +public int getModifiers() { + return this.modifiers; +} +public int getNameSourceEnd() { + return this.nameSourceEnd; +} +public int getNameSourceStart() { + return this.nameSourceStart; +} +public char[] getReturnTypeName() { + return this.returnTypeName; +} +public char[] getSelector() { + return this.selector; +} +public char[][][] getTypeParameterBounds() { + return this.typeParameterBounds; +} +public char[][] getTypeParameterNames() { + return this.typeParameterNames; +} +public boolean isConstructor() { + return this.returnTypeName == null; +} +protected void setDeclarationSourceEnd(int position) { + this.declarationEnd = position; +} +protected void setExplicitConstructorCall(String s) { + this.explicitConstructorCall = s; +} +public String tabString(int tab) { + /*slow code*/ + + String s = ""; + for (int i = tab; i > 0; i--) + s = s + "\t"; + return s; +} +@Override +public String toString() { + return toString(0); +} +public String toString(int tab) { + StringBuilder buffer = new StringBuilder(); + buffer.append(tabString(tab)); + String displayModifiers = displayModifiers(); + if (displayModifiers != null) { + buffer.append(displayModifiers).append(" "); + } + if (this.returnTypeName != null) { + buffer.append(this.returnTypeName).append(" "); + } + buffer.append(this.selector).append("("); + if (this.argumentTypeNames != null) { + for (int i = 0, max = this.argumentTypeNames.length; i < max; i++) { + buffer.append(this.argumentTypeNames[i]).append(" ").append( + this.argumentNames[i]).append( + ", "); + } + } + buffer.append(") "); + if (this.exceptionTypeNames != null) { + buffer.append("throws "); + for (int i = 0, max = this.exceptionTypeNames.length; i < max; i++) { + buffer.append(this.exceptionTypeNames[i]).append(", "); + } + } + if (this.explicitConstructorCall != null) { + buffer.append("{\n").append(tabString(tab+1)).append(this.explicitConstructorCall).append(tabString(tab)).append("}"); + } else { + buffer.append("{}"); + } + return buffer.toString(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourcePackage.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourcePackage.java new file mode 100644 index 0000000000..3e674326de --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourcePackage.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +public class SourcePackage { + int declarationSourceStart; + int declarationSourceEnd; + char[] name; + char[] source; +/** + * @param declarationSourceStart int + * @param declarationSourceEnd int + * @param name char[] + * @param source char[] + */ +public SourcePackage( + int declarationSourceStart, + int declarationSourceEnd, + char[] name, + char[] source) { + + this.declarationSourceStart = declarationSourceStart; + this.declarationSourceEnd = declarationSourceEnd; + this.name = name; + this.source = source; +} +/** + * + * @return java.lang.String + */ +@Override +public String toString() { + StringBuilder buffer = new StringBuilder(); + buffer + .append( + this.source, + this.declarationSourceStart, + this.declarationSourceEnd - this.declarationSourceStart + 1) + .append("\n"); + return buffer.toString(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java new file mode 100644 index 0000000000..ac6ad0df47 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java @@ -0,0 +1,313 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +public final class SourceType { + private int modifiers; + private int declarationStart; + private int declarationEnd; + private char[] fileName; + private SourcePackage packageName; + private SourceImport[] imports; + private char[] enclosingTypeName; + private char[] name; + private int nameSourceStart; + private int nameSourceEnd; + private char[] superclassName; + private char[][] interfaceNames; + private SourceType[] memberTypes; + private int numberOfMemberTypes; + private SourceMethod[] methods; + private int numberOfMethods; + private SourceField[] fields; + private SourceField[] recordComponents; + private int numberOfFields; + private int numberOfComponents; + private char[] source; + SourceType parent; + char[][] typeParameterNames; + char[][][] typeParameterBounds; + + // Buffering. + private char[] qualifiedName; + private String defaultConstructor; +public SourceType( + char[] enclosingTypeName, + int declarationStart, + int modifiers, + char[] name, + int nameSourceStart, + int nameSourceEnd, + char[] superclassName, + char[][] interfaceNames, + char[] source) { + + this.enclosingTypeName = enclosingTypeName; + this.declarationStart = declarationStart; + + this.modifiers = modifiers; + this.name = name; + this.nameSourceStart = nameSourceStart; + this.nameSourceEnd = nameSourceEnd; + this.superclassName = superclassName; + this.interfaceNames = interfaceNames; + this.source = source; +} +protected void addField(SourceField sourceField) { + if (this.fields == null) { + this.fields = new SourceField[4]; + } + + if (this.numberOfFields == this.fields.length) { + System.arraycopy( + this.fields, + 0, + this.fields = new SourceField[this.numberOfFields * 2], + 0, + this.numberOfFields); + } + this.fields[this.numberOfFields++] = sourceField; +} +protected void addRecordComponent(SourceField comp) { + if (this.recordComponents == null) { + this.recordComponents = new SourceField[4]; + } + if (this.numberOfComponents == this.recordComponents.length) { + System.arraycopy( + this.recordComponents, + 0, + this.recordComponents = new SourceField[this.numberOfComponents * 2], + 0, + this.numberOfComponents); + } + this.recordComponents[this.numberOfComponents++] = comp; +} +protected void addMemberType(SourceType sourceMemberType) { + if(this.memberTypes == null) { + this.memberTypes = new SourceType[4]; + } + + if(this.numberOfMemberTypes == this.memberTypes.length) { + System.arraycopy(this.memberTypes, 0, this.memberTypes = new SourceType[this.numberOfMemberTypes * 2], 0, this.numberOfMemberTypes); + } + this.memberTypes[this.numberOfMemberTypes++] = sourceMemberType; +} +protected void addMethod(SourceMethod sourceMethod) { + if (this.methods == null) { + this.methods = new SourceMethod[4]; + } + + if (this.numberOfMethods == this.methods.length) { + System.arraycopy( + this.methods, + 0, + this.methods = new SourceMethod[this.numberOfMethods * 2], + 0, + this.numberOfMethods); + } + this.methods[this.numberOfMethods++] = sourceMethod; +} +public String displayModifiers() { + StringBuilder buffer = new StringBuilder(); + + if (this.modifiers == 0) + return null; + if ((this.modifiers & ClassFileConstants.AccPublic) != 0) + buffer.append("public "); + if ((this.modifiers & ClassFileConstants.AccProtected) != 0) + buffer.append("protected "); + if ((this.modifiers & ClassFileConstants.AccPrivate) != 0) + buffer.append("private "); + if ((this.modifiers & ClassFileConstants.AccFinal) != 0) + buffer.append("final "); + if ((this.modifiers & ClassFileConstants.AccStatic) != 0) + buffer.append("static "); + if ((this.modifiers & ClassFileConstants.AccAbstract) != 0) + buffer.append("abstract "); + if ((this.modifiers & ClassFileConstants.AccNative) != 0) + buffer.append("native "); + if ((this.modifiers & ClassFileConstants.AccSynchronized) != 0) + buffer.append("synchronized "); + return buffer.toString().trim(); +} +public String getActualName() { + StringBuilder buffer = new StringBuilder(); + buffer.append(this.source, this.nameSourceStart, this.nameSourceEnd - this.nameSourceStart + 1); + return buffer.toString(); +} +public int getDeclarationSourceEnd() { + return this.declarationEnd; +} +public int getDeclarationSourceStart() { + return this.declarationStart; +} +public char[] getEnclosingTypeName() { + return this.enclosingTypeName; +} +public SourceField[] getFields() { + if (this.fields != null && this.fields.length != this.numberOfFields) { + System.arraycopy(this.fields, 0, this.fields = new SourceField[this.numberOfFields], 0, this.numberOfFields); + } + return this.fields; +} +public char[] getFileName() { + return this.fileName; +} +public char[][] getImports() { + if (this.imports == null) return null; + int importLength = this.imports.length; + char[][] importNames = new char[importLength][]; + for (int i = 0, max = importLength; i < max; i++) { + importNames[i] = this.imports[i].name; + } + return importNames; +} +public char[][] getInterfaceNames() { + return this.interfaceNames; +} +public SourceType[] getMemberTypes() { + if (this.memberTypes != null && this.memberTypes.length != this.numberOfMemberTypes) { + System.arraycopy( + this.memberTypes, + 0, + this.memberTypes = new SourceType[this.numberOfMemberTypes], + 0, + this.numberOfMemberTypes); + } + return this.memberTypes; +} +public SourceMethod[] getMethods() { + if (this.methods != null && this.methods.length != this.numberOfMethods) { + System.arraycopy(this.methods, 0, this.methods = new SourceMethod[this.numberOfMethods], 0, this.numberOfMethods); + } + return this.methods; +} +public int getModifiers() { + return this.modifiers; +} +public char[] getName() { + return this.name; +} +public int getNameSourceEnd() { + return this.nameSourceEnd; +} +public int getNameSourceStart() { + return this.nameSourceStart; +} +public char[] getPackageName() { + return this.packageName.name; +} +public char[] getQualifiedName() { + if (this.qualifiedName == null) { + StringBuilder temp = new StringBuilder(); + temp.append(this.packageName); + temp.append('.'); + temp.append(this.name); + this.qualifiedName = temp.toString().toCharArray(); + } + return this.qualifiedName; +} +public char[] getSuperclassName() { + return this.superclassName; +} +public boolean isBinaryType() { + return false; +} +public boolean isClass() { + return (this.modifiers & ClassFileConstants.AccInterface) == 0; +} +public boolean isInterface() { + return (this.modifiers & ClassFileConstants.AccInterface) == ClassFileConstants.AccInterface; +} +public void setDeclarationSourceEnd(int position) { + this.declarationEnd = position; +} +public void setDefaultConstructor(String s) { + this.defaultConstructor = s; +} +public void setImports(SourceImport[] imports) { + this.imports = imports; +} +public void setPackage(SourcePackage sourcePackage) { + this.packageName = sourcePackage; +} +public void setSuperclass(char[] superclassName) { + this.superclassName = superclassName; +} +public void setSuperinterfaces(char[][] superinterfacesNames) { + this.interfaceNames = superinterfacesNames; +} +public String tabString(int tab) { + /*slow code*/ + + String s = ""; + for (int i = tab; i > 0; i--) + s = s + "\t"; + return s; +} +@Override +public String toString() { + return toString(0); +} +public String toString(int tab) { + + StringBuilder buffer = new StringBuilder(); + if (this.packageName != null) { + buffer.append(tabString(tab)).append(this.packageName); + } + if (this.imports != null) { + for (int i = 0, max = this.imports.length; i < max; i++) { + buffer.append(tabString(tab)).append(this.imports[i]); + } + } + buffer.append(tabString(tab)); + String displayModifiers = displayModifiers(); + if (displayModifiers != null) { + buffer.append(displayModifiers).append(" "); + } + buffer.append(isInterface() ? "interface " : "class ").append(this.name).append(" "); + if (this.superclassName != null) { + buffer.append("extends ").append(this.superclassName).append(" "); + } + if (this.interfaceNames != null) { + buffer.append("implements "); + for (int i = 0, max = this.interfaceNames.length; i < max; i++) { + buffer.append(this.interfaceNames[i]).append(", "); + } + } + buffer.append("{\n"); + if (this.memberTypes != null) { + for (int i = 0, max = this.numberOfMemberTypes; i < max; i++) { + buffer.append(this.memberTypes[i].toString(tab + 1)).append("\n"); + } + } + if (this.fields != null) { + for (int i = 0, max = this.numberOfFields; i < max; i++) { + buffer.append(this.fields[i].toString(tab + 1)).append("\n"); + } + } + if (this.defaultConstructor != null) { + buffer.append(tabString(tab + 1)).append(this.defaultConstructor); + } + if (this.methods != null) { + for (int i = 0, max = this.numberOfMethods; i < max; i++) { + buffer.append(this.methods[i].toString(tab + 1)).append("\n"); + } + } + buffer.append(tabString(tab)).append("}"); + return buffer.toString(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java new file mode 100644 index 0000000000..5a6fbfcbf3 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java @@ -0,0 +1,3952 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import java.util.Locale; + +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.classfmt.ClassFileConstants; +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 StatementRecoveryTest extends AbstractCompilerTest { + public static final boolean ONLY_DIET_PLUS_BODY_WITH_STATEMENT_RECOVERY = false; + + public static boolean optimizeStringLiterals = false; + public static long sourceLevel = ClassFileConstants.JDK1_3; //$NON-NLS-1$ + +static { +// TESTS_NAMES = new String[] { "test0037"}; +// TESTS_RANGE = new int[] {10, 20}; +} +public static Test suite() { + return buildAllCompliancesTestSuite(StatementRecoveryTest.class); +} +public StatementRecoveryTest(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())), + optimizeStringLiterals); + parser.setMethodsFullRecovery(false); + 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())), + optimizeStringLiterals); + + 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())), + optimizeStringLiterals); + parser.setMethodsFullRecovery(false); + 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())), + optimizeStringLiterals); + + 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())), + optimizeStringLiterals); + parser.setMethodsFullRecovery(false); + 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())), + optimizeStringLiterals); + + 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); + + } +} + +public void test0001() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + expectedDietPlusBodyUnitToString; + + String expectedFullUnitToString = + expectedDietPlusBodyUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0002() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0003() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " # \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0004() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0005() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " System.out.println(); \n" + + " # \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0006() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0007() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0008() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0009() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0010() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() {} \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietPlusBodyUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietPlusBodyUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0011() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() {} \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0012() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() {} \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0013() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() {} \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " class Y { \n" + + " void foo() {} \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0014() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0015() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0016() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0017() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0018() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0019() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0020() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " class Z { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0021() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void foo() {} \n" + + " }; \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietPlusBodyUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietPlusBodyUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0022() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void foo() {} \n" + + " }; \n" + + " System.out.println(); \n" + + " # \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0023() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void bar() {} \n" + + " }; \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void bar() {\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0024() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void bar() {} \n" + + " }; \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void bar() {} \n" + + " }; \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void bar() {\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void bar() {\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0025() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " }; \n" + + " System.out.println(); \n" + + " # \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0026() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " }; \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0027() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " }; \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " }; \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0028() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " } \n" + + " }; \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0029() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + " }; \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0030() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + " }; \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0031() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " new Object() { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + " }; \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " new Object() {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + " };\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0032() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " System.out.println(); \n" + + " bar(new Object() { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " # \n" + + " System.out.println(); \n" + + " if(true) { \n" + + " System.out.println(); \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + " }); \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " bar(new Object() {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " System.out.println();\n" + + " if (true)\n" + + " {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "});\n" + + " System.out.println();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0033() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " class Z { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0034() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " new Object() { \n" + + " void foo() { \n" + + " System.out.println(); \n" + + " } \n" + + " }; \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " new Object() {\n" + + " void foo() {\n" + + " System.out.println();\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0035() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " bar(\\u0029 \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " bar();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0036() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " if(true) { \n" + + " foo(); \n" + + " } \n" + + " for(; \n" + + " if(true) { \n" + + " foo(); \n" + + " } \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " if (true)\n" + + " {\n" + + " foo();\n" + + " }\n" + + " for (; ; ) \n" + + " ;\n" + + " if (true)\n" + + " {\n" + + " foo();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0037() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " if() { \n" + + " foo(); \n" + + " } \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " if ($missing$)\n" + + " {\n" + + " foo();\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0038() { + String s = + "package p1; \n"+ + "public class A { \n"+ + " public interface B { \n"+ + " public abstract void aMethod (int A); \n"+ + " public interface C { \n"+ + " public abstract void anotherMethod(int A);\n"+ + " } \n"+ + " } \n"+ + " public class aClass implements B, B.C { \n"+ + " public void aMethod (int A) { \n"+ + " public void anotherMethod(int A) {}; \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "}"; + + String expectedDietUnitToString = + "package p1;\n" + + "public class A {\n" + + " public interface B {\n" + + " public interface C {\n" + + " public abstract void anotherMethod(int A);\n" + + " }\n" + + " public abstract void aMethod(int A);\n" + + " }\n" + + " public class aClass implements B, B.C {\n" + + " public aClass() {\n" + + " }\n" + + " public void aMethod(int A) {\n" + + " }\n" + + " }\n" + + " public A() {\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package p1;\n" + + "public class A {\n" + + " public interface B {\n" + + " public interface C {\n" + + " public abstract void anotherMethod(int A);\n" + + " }\n" + + " public abstract void aMethod(int A);\n" + + " }\n" + + " public class aClass implements B, B.C {\n" + + " public aClass() {\n" + + " super();\n" + + " }\n" + + " public void aMethod(int A) {\n" + + " }\n" + + " }\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package p1;\n" + + "public class A {\n" + + " public interface B {\n" + + " public interface C {\n" + + " public abstract void anotherMethod(int A);\n" + + " }\n" + + " public abstract void aMethod(int A);\n" + + " }\n" + + " public class aClass implements B, B.C {\n" + + " public aClass() {\n" + + " super();\n" + + " }\n" + + " public void aMethod(int A) {\n" + + " public void anotherMethod;\n" + + (this.complianceLevel < ClassFileConstants.JDK14 + ? + " int A;\n" + + " ;\n" + : + "" + ) + + " }\n" + + " }\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "package p1;\n" + + "public class A {\n" + + " public interface B {\n" + + " public interface C {\n" + + " public abstract void anotherMethod(int A);\n" + + " }\n" + + " public abstract void aMethod(int A);\n" + + " }\n" + + " public class aClass implements B, B.C {\n" + + " public aClass() {\n" + + " }\n" + + " public void aMethod(int A) {\n" + + " }\n" + + " public void anotherMethod(int A) {\n" + + " }\n" + + " }\n" + + " {\n" + + " }\n" + + " public A() {\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0039() { + + String s = + "package a; \n" + + "public class X { \n" + + " { \n" + + " System.out.println(); \n" + + " foo() \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " {\n" + + " }\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " {\n" + + " }\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " {\n" + + " System.out.println();\n" + + " foo();\n" + + " System.out.println();\n" + + " }\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0040() { + + String s = + "package a; \n" + + "public class X { \n" + + " { \n" + + " System.out.println(); \n" + + " class Y { \n" + + " { \n" + + " System.out.println(); \n" + + " foo() \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " {\n" + + " }\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " {\n" + + " }\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " {\n" + + " System.out.println();\n" + + " class Y {\n" + + " {\n" + + " System.out.println();\n" + + " foo();\n" + + " System.out.println();\n" + + " }\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0041() { + + String s = + "package a; \n" + + "public class X { \n" + + " { \n" + + " System.out.println(); \n" + + " class Y { \n" + + " { \n" + + " System.out.println(); \n" + + " foo() \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " class Z { \n" + + " { \n" + + " System.out.println(); \n" + + " foo() \n" + + " System.out.println(); \n" + + " } \n" + + " } \n" + + " System.out.println(); \n" + + " foo() \n" + + " System.out.println(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " {\n" + + " }\n" + + " public X() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " {\n" + + " }\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " {\n" + + " System.out.println();\n" + + " class Y {\n" + + " {\n" + + " System.out.println();\n" + + " foo();\n" + + " System.out.println();\n" + + " }\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " class Z {\n" + + " {\n" + + " System.out.println();\n" + + " foo();\n" + + " System.out.println();\n" + + " }\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " System.out.println();\n" + + " foo();\n" + + " System.out.println();\n" + + " }\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void test0042() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " for(int i \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " for (int i;; ; ) \n" + + " ;\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=80339 +public void test0043() { + + String s = + "package a; \n" + + "public interface Test { \n" + + " public void myMethod() \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public interface Test {\n" + + " public void myMethod() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public interface Test {\n" + + " public void myMethod() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public interface Test {\n" + + " public void myMethod() {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=173992 +public void test0044() { + + String s = + "import java.io.EOFException;\n" + + "import java.io.FileNotFoundException;\n" + + "import java.io.IOException;\n" + + "import org.xml.sax.SAXException;\n" + + "public class X {\n" + + "public void doSomething() throws FileNotFoundException, EOFException, SAXException{\n" + + "\n" + + "}\n" + + "public void doSomethingElse() {\n" + + "try {\n" + + " doSomething();\n" + + "}\n" + + " catch ( SAXException exception) {\n" + + "\n" + + "} \n" + + "catch ( FileNotFoundException exception ) {\n" + + "\n" + + "} \n" + + "catch (\n" + + " // working before the slashes\n" + + ") {\n" + + "\n" + + "} \n" + + "} \n" + + "}\n"; + + String expectedDietUnitToString = + "import java.io.EOFException;\n" + + "import java.io.FileNotFoundException;\n" + + "import java.io.IOException;\n" + + "import org.xml.sax.SAXException;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public void doSomething() throws FileNotFoundException, EOFException, SAXException {\n" + + " }\n" + + " public void doSomethingElse() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "import java.io.EOFException;\n" + + "import java.io.FileNotFoundException;\n" + + "import java.io.IOException;\n" + + "import org.xml.sax.SAXException;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void doSomething() throws FileNotFoundException, EOFException, SAXException {\n" + + " }\n" + + " public void doSomethingElse() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "import java.io.EOFException;\n" + + "import java.io.FileNotFoundException;\n" + + "import java.io.IOException;\n" + + "import org.xml.sax.SAXException;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void doSomething() throws FileNotFoundException, EOFException, SAXException {\n" + + " }\n" + + " public void doSomethingElse() {\n" + + " try\n" + + " {\n" + + " doSomething();\n" + + " }\n" + + " catch (SAXException exception)\n" + + " {\n" + + " }\n" + + " catch (FileNotFoundException exception)\n" + + " {\n" + + " }\n" + + " catch ($missing$ $missing$)\n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204662 +public void test0045() { + + String s = + "public class BadClass {\n" + + "\n" + + " public void method(Object obj) {\n" + + "\n" + + " /*//this version compiles\n" + + " People oPeople;\n" + + " {oPeople= (People) obj;}//*/\n" + + "\n" + + " /*//this version fails, but the compiler errors are fine\n" + + " class People oPeople;\n" + + " oPeople= (class People) obj;//*/\n" + + "\n" + + " //this version fails with internal compiler error\n" + + " class People oPeople;\n" + + " {oPeople= (class People) obj;}\n" + + " }\n" + + "\n" + + "}\n"; + + String expectedDietUnitToString = + "public class BadClass {\n" + + " public BadClass() {\n" + + " }\n" + + " public void method(Object obj) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class BadClass {\n" + + " public BadClass() {\n" + + " super();\n" + + " }\n" + + " public void method(Object obj) {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class BadClass {\n" + + " public BadClass() {\n" + + " super();\n" + + " }\n" + + " public void method(Object obj) {\n" + + " class People {\n" + + " {\n" + + " class People {\n" + + " People() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + " People() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204662 +public void test0046() { + + String s = + "public class X {\n" + + " public void foo() { \n" + + " class Y ;\n" + + " \n" + + " {\n" + + " class Z ;\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietUnitToString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " class Y {\n" + + " {\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204662 +public void test0047() { + + String s = + "public class X {\n" + + " public void foo() { \n" + + " class Y ;\n" + + " \n" + + " void bar() {\n" + + " class Z ;\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietUnitToString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " void bar() {\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +public void testBug430336() { + + String s = + "package test1;\n" + + "import java.util.Collection;\n" + + "public class E {\n" + + " void foo(Collection collection) {\n" + + " collection\n" + + " }\n" + + "}\n"; + + String expectedDietUnitToString = + "package test1;\n" + + "import java.util.Collection;\n" + + "public class E {\n" + + " public E() {\n" + + " }\n" + + " void foo(Collection collection) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package test1;\n" + + "import java.util.Collection;\n" + + "public class E {\n" + + " public E() {\n" + + " super();\n" + + " }\n" + + " void foo(Collection collection) {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package test1;\n" + + "import java.util.Collection;\n" + + "public class E {\n" + + " public E() {\n" + + " super();\n" + + " }\n" + + " void foo(Collection collection) {\n" + + " collection = $missing$;\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest_1_5.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest_1_5.java new file mode 100644 index 0000000000..333be59167 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest_1_5.java @@ -0,0 +1,797 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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.classfmt.ClassFileConstants; +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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class StatementRecoveryTest_1_5 extends AbstractCompilerTest { + public static final boolean ONLY_DIET_PLUS_BODY_WITH_STATEMENT_RECOVERY = false; + + public static boolean optimizeStringLiterals = false; + public static long sourceLevel = ClassFileConstants.JDK1_3; //$NON-NLS-1$ + +static { +// TESTS_NAMES = new String[] { "test0037"}; +// TESTS_RANGE = new int[] {10, 20}; +} +public static Test suite() { + return buildAllCompliancesTestSuite(StatementRecoveryTest_1_5.class); +} +public StatementRecoveryTest_1_5(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())), + optimizeStringLiterals); + 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())), + optimizeStringLiterals); + + 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())), + optimizeStringLiterals); + 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())), + optimizeStringLiterals); + + 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())), + optimizeStringLiterals); + 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())), + optimizeStringLiterals); + + 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); + + } +} + +@Override +protected Map getCompilerOptions() { + Map options = super.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); + return options; +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=142793 +public void test0001() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo(Collection c) { \n" + + " for(String s: c) { \n" + + " try { \n" + + " foo(); ` \n" + + " } ` \n" + + " } \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo(Collection c) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo(Collection c) {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo(Collection c) {\n" + + " for (String s : c) \n" + + " {\n" + + " try\n" + + " {\n" + + " foo();\n" + + " }\n" + + " finally\n" + + " {\n" + + " }\n" + + " }\n" + + " ;\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo(Collection c) {\n" + + " }\n" + + "}\n"; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=211180 +public void test0002() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " # \n" + + " @MyAnnot(value=) \n" + + " int i; ` \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " @MyAnnot(value = $missing$) int i;\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0003() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " @AnAnnotation(name) # \n" + + " int var; \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " @AnAnnotation(name) int var;\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0004() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " @AnAnnotation(name=) \n" + + " int var; \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " @AnAnnotation(name = $missing$) int var;\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0005() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " foo1(); \n" + + " @AnAnnotation(name) # \n" + + " class Y {} \n" + + " foo2(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " @AnAnnotation(name) class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " foo1();\n" + + " @AnAnnotation(name) class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " foo2();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0006() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " foo1(); \n" + + " @AnAnnotation(name=) \n" + + " class Y {} \n" + + " foo2(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " @AnAnnotation(name = $missing$) class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " foo1();\n" + + " @AnAnnotation(name = $missing$) class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " foo2();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778 +public void test0007() { + + String s = + "package a; \n" + + "public class X { \n" + + " void foo() { \n" + + " foo1(); \n" + + " final @AnAnnotation(name) # \n" + + " class Y {} \n" + + " foo2(); \n" + + " } \n" + + "} \n"; + + String expectedDietUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " final @AnAnnotation(name) class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "package a;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " void foo() {\n" + + " foo1();\n" + + " final @AnAnnotation(name) class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " foo2();\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340691 +// Verify that we don't get a recovered enum declaration when the error token is after an +// incorrectly used modifier +public void test0008() { + String s = + "public class Try {\n" + + "\n" + + " void m() {\n" + + "\n" + + " synchronized new Object();\n" + + "\n" + + " }\n" + + "}\n" + + "\n"; + + String expectedDietUnitToString = + "public class Try {\n" + + " public Try() {\n" + + " }\n" + + " void m() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class Try {\n" + + " public Try() {\n" + + " super();\n" + + " }\n" + + " void m() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class Try {\n" + + " public Try() {\n" + + " super();\n" + + " }\n" + + " void m() {\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedFullUnitToString; + + String testName = "test"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SyntaxErrorTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SyntaxErrorTest.java new file mode 100644 index 0000000000..7ace4ce4cf --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SyntaxErrorTest.java @@ -0,0 +1,527 @@ +/******************************************************************************* + * Copyright (c) 2000, 2012 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import java.util.Locale; + +import org.eclipse.jdt.core.compiler.CategorizedProblem; +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.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +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.DefaultProblem; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; + +public class SyntaxErrorTest extends AbstractCompilerTest { + public static boolean optimizeStringLiterals = false; + public static long sourceLevel = ClassFileConstants.JDK1_3; //$NON-NLS-1$ + +public SyntaxErrorTest(String testName){ + super(testName); +} +public void checkParse( + char[] source, + String expectedSyntaxErrorDiagnosis, + String testName) { + + /* using regular parser in DIET mode */ + Parser parser = + new Parser( + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(getCompilerOptions()), + new DefaultProblemFactory(Locale.getDefault())), + optimizeStringLiterals); + ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); + + parser.parse(sourceUnit, compilationResult); + + StringBuilder buffer = new StringBuilder(100); + if (compilationResult.hasProblems() || compilationResult.hasTasks()) { + CategorizedProblem[] problems = compilationResult.getAllProblems(); + int count = problems.length; + int problemCount = 0; + char[] unitSource = compilationResult.compilationUnit.getContents(); + for (int i = 0; i < count; i++) { + if (problems[i] != null) { + if (problemCount == 0) + buffer.append("----------\n"); + problemCount++; + buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING")); + buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\')); + try { + buffer.append(((DefaultProblem)problems[i]).errorReportSource(unitSource)); + buffer.append("\n"); + buffer.append(problems[i].getMessage()); + buffer.append("\n"); + } catch (Exception e) { + } + buffer.append("----------\n"); + } + } + } + String computedSyntaxErrorDiagnosis = buffer.toString(); + //System.out.println(Util.displayString(computedSyntaxErrorDiagnosis)); + assertEquals( + "Invalid syntax error diagnosis" + testName, + Util.convertToIndependantLineDelimiter(expectedSyntaxErrorDiagnosis), + Util.convertToIndependantLineDelimiter(computedSyntaxErrorDiagnosis)); +} +/* + * Should diagnose parenthesis mismatch + */ +public void test01() { + + String s = + "public class X { \n"+ + " public void solve(){ \n"+ + " \n"+ + " X[] results = new X[10]; \n"+ + " for(int i = 0; i < 10; i++){ \n"+ + " X result = results[i]; \n"+ + " boolean found = false; \n"+ + " for(int j = 0; j < 10; j++){ \n"+ + " if (this.equals(result.documentName){ \n"+ + " found = true; \n"+ + " break; \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + " return andResult; \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n" + + "1. ERROR in (at line 9)\n" + + " if (this.equals(result.documentName){ \n" + + " ^\n" + + "Syntax error, insert \") Statement\" to complete BlockStatements\n" + + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +/* + * Should diagnose brace mismatch + */ +public void test02() { + + String s = + "class Bar { \n"+ + " Bar() { \n"+ + " this(fred().x{);\n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n" + + "1. ERROR in (at line 3)\n" + + " this(fred().x{);\n" + + " ^\n" + + "Syntax error on token \"{\", delete this token\n" + + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +/* + * Should diagnose parenthesis mismatch + */ +public void test03() { + + String s = + "public class X { // should complain \n"+ + " int foo( \n"+ + " [ arg1, \n"+ + " { arg2, ] \n"+ + " arg3, \n"+ + " ){ \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n" + + "1. ERROR in (at line 3)\n" + + " [ arg1, \n" + + " ^\n" + + "Syntax error on token \"[\", byte expected\n" + + "----------\n" + + "2. ERROR in (at line 4)\n" + + " { arg2, ] \n" + + " ^\n" + + "Syntax error on token \"{\", byte expected\n" + + "----------\n" + + "3. ERROR in (at line 4)\n" + + " { arg2, ] \n" + + " ^\n" + + "Syntax error on token \"]\", byte expected\n" + + "----------\n" + + "4. ERROR in (at line 5)\n" + + " arg3, \n" + + " ^\n" + + "Syntax error on token \",\", FormalParameter expected after this token\n" + + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +/* + * Should not diagnose parenthesis mismatch + */ +public void test04() { + + String s = + "public class X { // should not complain \n"+ + " int foo( \n"+ + " { arg1, \n"+ + " { arg2, } \n"+ + " arg3, } \n"+ + " ){ \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n" + + "1. ERROR in (at line 2)\n" + + " int foo( \n" + + " ^\n" + + "Syntax error on token \"(\", = expected\n" + + "----------\n" + + "2. ERROR in (at line 5)\n" + + " arg3, } \n" + + " ^^^^\n" + + "Syntax error on token \"arg3\", delete this token\n" + + "----------\n" + + "3. ERROR in (at line 6)\n" + + " ){ \n" + + " ^\n" + + "Syntax error on token \")\", ; expected\n" + + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=61189 +public void test05() { + + String s = + "public class X { \n"+ + " public void foo() { \n"+ + " (X) foo(); \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n"+ + "1. ERROR in (at line 3)\n"+ + " (X) foo(); \n"+ + " ^\n"+ + "Syntax error, insert \"AssignmentOperator Expression\" to complete Assignment\n"+ + "----------\n"+ + "2. ERROR in (at line 3)\n"+ + " (X) foo(); \n"+ + " ^\n"+ + "Syntax error, insert \";\" to complete BlockStatements\n"+ + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=61189 +public void test06() { + + String s = + "public class X { \n"+ + " public void foo(int i) { \n"+ + " i; \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n" + + "1. ERROR in (at line 3)\n" + + " i; \n" + + " ^\n" + + "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration\n" + + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133292 +public void test07() { + + String s = + "public class X { \n"+ + " java.lang.Object o[] = { new String(\"SUCCESS\") ; }; \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n"+ + "1. ERROR in (at line 2)\n"+ + " java.lang.Object o[] = { new String(\"SUCCESS\") ; }; \n"+ + " ^\n"+ + "Syntax error on token \";\", , expected\n"+ + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133292 +public void test08() { + + String s = + "public class X { \n"+ + " Object o[] = { new String(\"SUCCESS\") ; }; \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n"+ + "1. ERROR in (at line 2)\n"+ + " Object o[] = { new String(\"SUCCESS\") ; }; \n"+ + " ^\n"+ + "Syntax error on token \";\", , expected\n"+ + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133292 +public void test09() { + + String s = + "public class X { \n"+ + " void foo() { \n"+ + " java.lang.Object o[] = { new String(\"SUCCESS\") ; }; \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n"+ + "1. ERROR in (at line 3)\n"+ + " java.lang.Object o[] = { new String(\"SUCCESS\") ; }; \n"+ + " ^\n"+ + "Syntax error on token \";\", , expected\n"+ + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133292 +public void test10() { + + String s = + "public class X { \n"+ + " void foo() { \n"+ + " Object o[] = { new String(\"SUCCESS\") ; }; \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n"+ + "1. ERROR in (at line 3)\n"+ + " Object o[] = { new String(\"SUCCESS\") ; }; \n"+ + " ^\n"+ + "Syntax error on token \";\", , expected\n"+ + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=80339 +public void test11() { + + String s = + "package a; \n"+ + "public interface Test { \n"+ + " public void myMethod() \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n"+ + "1. ERROR in (at line 3)\n"+ + " public void myMethod() \n"+ + " ^\n"+ + "Syntax error, insert \";\" to complete MethodDeclaration\n"+ + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=80339 +public void test12() { + + String s = + "package a; \n"+ + "public interface Test { \n"+ + " public void myMethod() \n"+ + " System.out.println(); \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n"+ + "1. ERROR in (at line 3)\n"+ + " public void myMethod() \n"+ + " ^\n"+ + "Syntax error on token \")\", { expected after this token\n"+ + "----------\n"+ + "2. ERROR in (at line 5)\n"+ + " } \n"+ + " ^\n"+ + "Syntax error, insert \"}\" to complete InterfaceBody\n"+ + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=221266 +public void test13() { + + String s = + "package a; \n"+ + "public class Test { \n"+ + " public void foo() { \n"+ + " foo(a \"\\\"\"); \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n"+ + "1. ERROR in (at line 4)\n"+ + " foo(a \"\\\"\"); \n"+ + " ^^^^\n"+ + "Syntax error on token \"\"\\\"\"\", delete this token\n"+ + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=212713 +public void test14() { + + String s = + "public interface Test {\n"+ + " static { }\n"+ + " { }\n"+ + "}\n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n" + + "1. ERROR in (at line 2)\n" + + " static { }\n" + + " ^^^^\n" + + "The interface Test cannot define an initializer\n" + + "----------\n" + + "2. ERROR in (at line 3)\n" + + " { }\n" + + " ^^^^^^^^^^^\n" + + "The interface Test cannot define an initializer\n" + + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=210419 +public void test15() { + + String s = + "package bug;\n" + + "public class Test {\n" + + " static int X;\n" + + " String field = { String str;\n" + + " switch (X) {\n" + + " case 0:\n" + + " str = \"zero\";\n" + + " break;\n" + + " default:\n" + + " str = \"other\";\n" + + " break;\n" + + " }\n" + + " this.field = str;\n" + + " };\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new Test().field);\n" + + " }\n" + + "}\n"; + + String expectedSyntaxErrorDiagnosis = + "----------\n" + + "1. ERROR in (at line 4)\n" + + " String field = { String str;\n" + + " ^^^^^^^^\n" + + "Syntax error on token(s), misplaced construct(s)\n" + + "----------\n" + + "2. ERROR in (at line 4)\n" + + " String field = { String str;\n" + + " ^\n" + + "Syntax error on token \";\", { expected after this token\n" + + "----------\n"; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis, + testName); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java new file mode 100644 index 0000000000..84a0b6abdc --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java @@ -0,0 +1,329 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Jesper Steen Møller - Contributions for + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type + * + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.core.tests.compiler.regression.JEP286ReservedWordTest; +import org.eclipse.jdt.core.tests.junit.extension.TestCase; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Run all parser regression tests + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class TestAll extends junit.framework.TestCase { + + public final static List TEST_CLASSES_1_5 = new ArrayList(); + static { + /* completion tests */ + TEST_CLASSES_1_5.addAll(RunCompletionParserTests.TEST_CLASSES_1_5); + /* selection tests */ + TEST_CLASSES_1_5.add(GenericsSelectionTest.class); + TEST_CLASSES_1_5.add(AnnotationSelectionTest.class); + TEST_CLASSES_1_5.add(EnumSelectionTest.class); + /* recovery tests */ + TEST_CLASSES_1_5.add(GenericDietRecoveryTest.class); + TEST_CLASSES_1_5.add(EnumDietRecoveryTest.class); + TEST_CLASSES_1_5.add(AnnotationDietRecoveryTest.class); + TEST_CLASSES_1_5.add(StatementRecoveryTest_1_5.class); + } + +public TestAll(String testName) { + super(testName); +} + +public static TestSuite getTestSuite(boolean addComplianceDiagnoseTest) { + ArrayList testClasses = new ArrayList(); + + /* completion tests */ + testClasses.addAll(RunCompletionParserTests.TEST_CLASSES); + + /* selection tests */ + testClasses.add(ExplicitConstructorInvocationSelectionTest.class); + testClasses.add(SelectionTest.class); + testClasses.add(SelectionTest2.class); + testClasses.add(SelectionJavadocTest.class); + + /* recovery tests */ + testClasses.add(DietRecoveryTest.class); + testClasses.add(StatementRecoveryTest.class); + + /* source element parser tests */ + testClasses.add(SourceElementParserTest.class); + + /* document element parser tests */ + testClasses.add(DocumentElementParserTest.class); + + /* syntax error diagnosis tests */ + testClasses.add(SyntaxErrorTest.class); + testClasses.add(DualParseSyntaxErrorTest.class); + testClasses.add(ParserTest.class); + if (addComplianceDiagnoseTest) + testClasses.add(ComplianceDiagnoseTest.class); + + TestSuite all = new TestSuite(TestAll.class.getName()); + int possibleComplianceLevels = AbstractCompilerTest.getPossibleComplianceLevels(); + if ((possibleComplianceLevels & AbstractCompilerTest.F_1_3) != 0) { + ArrayList tests_1_3 = (ArrayList)testClasses.clone(); + TestCase.resetForgottenFilters(tests_1_3); + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK1_3, tests_1_3)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_1_4) != 0) { + ArrayList tests_1_4 = (ArrayList)testClasses.clone(); + TestCase.resetForgottenFilters(tests_1_4); + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK1_4, tests_1_4)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_1_5) != 0) { + ArrayList tests_1_5 = (ArrayList)testClasses.clone(); + tests_1_5.addAll(TEST_CLASSES_1_5); + TestCase.resetForgottenFilters(tests_1_5); + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK1_5, tests_1_5)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_1_6) != 0) { + ArrayList tests_1_6 = (ArrayList)testClasses.clone(); + tests_1_6.addAll(TEST_CLASSES_1_5); + TestCase.resetForgottenFilters(tests_1_6); + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK1_6, tests_1_6)); + } + 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); + TestCase.resetForgottenFilters(tests_1_7); + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK1_7, tests_1_7)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_1_8) != 0) { + ArrayList tests_1_8 = (ArrayList)testClasses.clone(); + tests_1_8.addAll(TEST_CLASSES_1_5); + tests_1_8.add(ParserTest1_7.class); + tests_1_8.add(LambdaExpressionSyntaxTest.class); + tests_1_8.add(ReferenceExpressionSyntaxTest.class); + tests_1_8.add(TypeAnnotationSyntaxTest.class); + tests_1_8.add(CompletionParserTest18.class); + tests_1_8.add(SelectionParserTest18.class); + TestCase.resetForgottenFilters(tests_1_8); + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK1_8, tests_1_8)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_9) != 0) { + ArrayList tests_9 = (ArrayList)testClasses.clone(); + tests_9.addAll(TEST_CLASSES_1_5); + tests_9.add(ParserTest1_7.class); + tests_9.add(LambdaExpressionSyntaxTest.class); + tests_9.add(ReferenceExpressionSyntaxTest.class); + tests_9.add(TypeAnnotationSyntaxTest.class); + tests_9.add(CompletionParserTest18.class); + tests_9.add(SelectionParserTest18.class); + tests_9.add(SelectionParserTest9.class); + tests_9.add(ModuleDeclarationSyntaxTest.class); + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK9, tests_9)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_10) != 0) { + ArrayList tests_10 = (ArrayList)testClasses.clone(); + tests_10.addAll(TEST_CLASSES_1_5); + tests_10.add(ParserTest1_7.class); + tests_10.add(LambdaExpressionSyntaxTest.class); + tests_10.add(ReferenceExpressionSyntaxTest.class); + tests_10.add(TypeAnnotationSyntaxTest.class); + tests_10.add(CompletionParserTest18.class); + tests_10.add(SelectionParserTest18.class); + tests_10.add(SelectionParserTest9.class); + tests_10.add(SelectionParserTest10.class); + tests_10.add(ModuleDeclarationSyntaxTest.class); + tests_10.add(JEP286ReservedWordTest.class); + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.JDK10, tests_10)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_11) != 0) { + ArrayList tests_11 = (ArrayList)testClasses.clone(); + tests_11.addAll(TEST_CLASSES_1_5); + tests_11.add(ParserTest1_7.class); + tests_11.add(LambdaExpressionSyntaxTest.class); + tests_11.add(ReferenceExpressionSyntaxTest.class); + tests_11.add(TypeAnnotationSyntaxTest.class); + tests_11.add(CompletionParserTest18.class); + tests_11.add(SelectionParserTest18.class); + tests_11.add(SelectionParserTest9.class); + tests_11.add(SelectionParserTest10.class); + tests_11.add(ModuleDeclarationSyntaxTest.class); + tests_11.add(JEP286ReservedWordTest.class); + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_11), tests_11)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_12) != 0) { + ArrayList tests_12 = (ArrayList)testClasses.clone(); + tests_12.addAll(TEST_CLASSES_1_5); + tests_12.add(ParserTest1_7.class); + tests_12.add(LambdaExpressionSyntaxTest.class); + tests_12.add(ReferenceExpressionSyntaxTest.class); + tests_12.add(TypeAnnotationSyntaxTest.class); + tests_12.add(CompletionParserTest18.class); + tests_12.add(SelectionParserTest18.class); + tests_12.add(SelectionParserTest9.class); + tests_12.add(SelectionParserTest10.class); + tests_12.add(SelectionParserTest12.class); + tests_12.add(ModuleDeclarationSyntaxTest.class); + tests_12.add(JEP286ReservedWordTest.class); + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_12), tests_12)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_13) != 0) { + ArrayList tests_13 = (ArrayList)testClasses.clone(); + tests_13.addAll(TEST_CLASSES_1_5); + tests_13.add(ParserTest1_7.class); + tests_13.add(LambdaExpressionSyntaxTest.class); + tests_13.add(ReferenceExpressionSyntaxTest.class); + tests_13.add(TypeAnnotationSyntaxTest.class); + tests_13.add(CompletionParserTest18.class); + tests_13.add(SelectionParserTest18.class); + tests_13.add(SelectionParserTest9.class); + tests_13.add(SelectionParserTest10.class); + tests_13.add(SelectionParserTest12.class); + tests_13.add(ModuleDeclarationSyntaxTest.class); + tests_13.add(JEP286ReservedWordTest.class); + //TODO:To add SwitchExpressionYieldTests here as well as master + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_13), tests_13)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_14) != 0) { + ArrayList tests_14 = (ArrayList)testClasses.clone(); + tests_14.addAll(TEST_CLASSES_1_5); + tests_14.add(ParserTest1_7.class); + tests_14.add(LambdaExpressionSyntaxTest.class); + tests_14.add(ReferenceExpressionSyntaxTest.class); + tests_14.add(TypeAnnotationSyntaxTest.class); + tests_14.add(CompletionParserTest18.class); + tests_14.add(SelectionParserTest18.class); + tests_14.add(SelectionParserTest9.class); + tests_14.add(SelectionParserTest10.class); + tests_14.add(SelectionParserTest12.class); + tests_14.add(ModuleDeclarationSyntaxTest.class); + tests_14.add(JEP286ReservedWordTest.class); + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_14), tests_14)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_15) != 0) { + ArrayList tests_15 = (ArrayList)testClasses.clone(); + tests_15.addAll(TEST_CLASSES_1_5); + tests_15.add(ParserTest1_7.class); + tests_15.add(LambdaExpressionSyntaxTest.class); + tests_15.add(ReferenceExpressionSyntaxTest.class); + tests_15.add(TypeAnnotationSyntaxTest.class); + tests_15.add(CompletionParserTest18.class); + tests_15.add(SelectionParserTest18.class); + tests_15.add(SelectionParserTest9.class); + tests_15.add(SelectionParserTest10.class); + tests_15.add(SelectionParserTest12.class); + tests_15.add(ModuleDeclarationSyntaxTest.class); + tests_15.add(JEP286ReservedWordTest.class); + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_15), tests_15)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_16) != 0) { + ArrayList tests_16 = (ArrayList)testClasses.clone(); + tests_16.addAll(TEST_CLASSES_1_5); + tests_16.add(ParserTest1_7.class); + tests_16.add(LambdaExpressionSyntaxTest.class); + tests_16.add(ReferenceExpressionSyntaxTest.class); + tests_16.add(TypeAnnotationSyntaxTest.class); + tests_16.add(CompletionParserTest18.class); + tests_16.add(SelectionParserTest18.class); + tests_16.add(SelectionParserTest9.class); + tests_16.add(SelectionParserTest10.class); + tests_16.add(SelectionParserTest12.class); + tests_16.add(ModuleDeclarationSyntaxTest.class); + tests_16.add(JEP286ReservedWordTest.class); + tests_16.add(PatternMatchingSelectionTest.class); + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_16), tests_16)); + } + if ((possibleComplianceLevels & AbstractCompilerTest.F_17) != 0) { + ArrayList tests_17 = (ArrayList)testClasses.clone(); + tests_17.addAll(TEST_CLASSES_1_5); + tests_17.add(ParserTest1_7.class); + tests_17.add(LambdaExpressionSyntaxTest.class); + tests_17.add(ReferenceExpressionSyntaxTest.class); + tests_17.add(TypeAnnotationSyntaxTest.class); + tests_17.add(CompletionParserTest18.class); + tests_17.add(SelectionParserTest18.class); + tests_17.add(SelectionParserTest9.class); + tests_17.add(SelectionParserTest10.class); + tests_17.add(SelectionParserTest12.class); + tests_17.add(ModuleDeclarationSyntaxTest.class); + tests_17.add(JEP286ReservedWordTest.class); + tests_17.add(PatternMatchingSelectionTest.class); + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + all.addTest(AbstractCompilerTest.buildComplianceTestSuite(ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_17), tests_17)); + } + return all; +} +public static Test suite() { + return getTestSuite(true); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestSourceElementRequestor.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestSourceElementRequestor.java new file mode 100644 index 0000000000..6287d57867 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestSourceElementRequestor.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2000, 2010 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.internal.compiler.ISourceElementRequestor; +import org.eclipse.jdt.internal.compiler.ast.Expression; +import org.eclipse.jdt.internal.compiler.ast.ImportReference; + +public class TestSourceElementRequestor implements ISourceElementRequestor { +/** + * DummySourceElementRequestor constructor comment. + */ +public TestSourceElementRequestor() { + super(); +} +/** + * acceptAnnotationTypeReference method comment. + */ +public void acceptAnnotationTypeReference(char[][] typeName, int sourceStart, int sourceEnd) {} +/** + * acceptAnnotationTypeReference method comment. + */ +public void acceptAnnotationTypeReference(char[] typeName, int sourcePosition) {} +/** + * acceptConstructorReference method comment. + */ +public void acceptConstructorReference(char[] typeName, int argCount, int sourcePosition) {} +/** + * acceptFieldReference method comment. + */ +public void acceptFieldReference(char[] fieldName, int sourcePosition) {} +/** + * acceptImport method comment. + */ +public void acceptImport(int declarationStart, int declarationEnd, int nameStart, int nameEnd, char[][] tokens, boolean onDemand, int modifiers) {} +/** + * acceptLineSeparatorPositions method comment. + */ +public void acceptLineSeparatorPositions(int[] positions) {} +/** + * acceptMethodReference method comment. + */ +public void acceptMethodReference(char[] methodName, int argCount, int sourcePosition) {} +/** + * acceptPackage method comment. + */ +public void acceptPackage(ImportReference importReference) {} +/** + * acceptProblem method comment. + */ +public void acceptProblem(CategorizedProblem problem) {} +/** + * acceptTypeReference method comment. + */ +public void acceptTypeReference(char[][] typeName, int sourceStart, int sourceEnd) {} +/** + * acceptTypeReference method comment. + */ +public void acceptTypeReference(char[] typeName, int sourcePosition) {} +/** + * acceptUnknownReference method comment. + */ +public void acceptUnknownReference(char[][] name, int sourceStart, int sourceEnd) {} +/** + * acceptUnknownReference method comment. + */ +public void acceptUnknownReference(char[] name, int sourcePosition) {} +/** + * enterCompilationUnit method comment. + */ +public void enterCompilationUnit() {} +/** + * enterConstructor method comment. + */ +public void enterConstructor(MethodInfo methodInfo) {} +/** + * enterField method comment. + */ +public void enterField(FieldInfo fieldInfo) {} +/** + * enterMethod method comment. + */ +public void enterMethod(MethodInfo methodInfo) {} +/** + * enterType method comment. + */ +public void enterType(TypeInfo typeInfo) {} +/** + * exitCompilationUnit method comment. + */ +public void exitCompilationUnit(int declarationEnd) {} +/** + * exitConstructor method comment. + */ +public void exitConstructor(int declarationEnd) {} +/** + * exitField method comment. + */ +public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd) {} +public void exitRecordComponent(int declarationEnd, int declarationSourceEnd) {} +/** + * exitMethod method comment. + */ +public void exitMethod(int declarationEnd, Expression defaultValue) {} + +/** + * enterInitializer method comment. + */ +public void enterInitializer(int sourceStart, int sourceEnd) { +} + +/** + * exitInitializer method comment. + */ +public void exitInitializer(int sourceEnd) { +} +/** + * exitType method comment. + */ +public void exitType(int declarationEnd) {} + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TypeAnnotationSyntaxTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TypeAnnotationSyntaxTest.java new file mode 100644 index 0000000000..c90d246dea --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TypeAnnotationSyntaxTest.java @@ -0,0 +1,3834 @@ +/******************************************************************************* + * Copyright (c) 2009, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for + * Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.parser; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.util.HashMap; +import java.util.Map; +import junit.framework.Test; +import org.eclipse.jdt.core.tests.util.CompilerTestSetup; +import org.eclipse.jdt.internal.compiler.ASTVisitor; +import org.eclipse.jdt.internal.compiler.ast.Annotation; +import org.eclipse.jdt.internal.compiler.ast.Argument; +import org.eclipse.jdt.internal.compiler.ast.ArrayTypeReference; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation; +import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.NormalAnnotation; +import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference; +import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation; +import org.eclipse.jdt.internal.compiler.ast.SingleTypeReference; +import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.lookup.BlockScope; +import org.eclipse.jdt.internal.compiler.lookup.ClassScope; +import org.eclipse.jdt.internal.compiler.lookup.MethodScope; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class TypeAnnotationSyntaxTest extends AbstractSyntaxTreeTest { + + private static String jsr308TestScratchArea = "c:\\Jsr308TestScratchArea"; + private static String referenceCompiler = "C:\\jdk-7-ea-bin-b75-windows-i586-30_oct_2009\\jdk7\\bin\\javac.exe"; + + static { +// TESTS_NAMES = new String [] { "test0137" }; + } + public static Class testClass() { + return TypeAnnotationSyntaxTest.class; + } + @Override + public void initialize(CompilerTestSetup setUp) { + super.initialize(setUp); + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + + static final class LocationPrinterVisitor extends ASTVisitor { + TypeReference enclosingReference; + Map locations; + + public LocationPrinterVisitor() { + this.locations = new HashMap(); + } + + public Map getLocations() { + return this.locations; + } + public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { + this.enclosingReference = fieldDeclaration.type; + return true; + } + public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { + TypeReference returnType = methodDeclaration.returnType; + if (returnType != null) { + this.enclosingReference = returnType; + returnType.traverse(this, scope); + } + if (methodDeclaration.thrownExceptions != null) { + int thrownExceptionsLength = methodDeclaration.thrownExceptions.length; + for (int i = 0; i < thrownExceptionsLength; i++) { + TypeReference typeReference = methodDeclaration.thrownExceptions[i]; + this.enclosingReference = typeReference; + typeReference.traverse(this, scope); + } + } + return false; + } + public boolean visit(Argument argument, ClassScope scope) { + this.enclosingReference = argument.type; + return true; + } + public boolean visit(Argument argument, BlockScope scope) { + this.enclosingReference = argument.type; + return true; + } + public boolean visit(MarkerAnnotation annotation, BlockScope scope) { + if (this.enclosingReference != null) { + storeLocations(annotation, Annotation.getLocations(this.enclosingReference, annotation)); + } + return false; + } + public boolean visit(SingleMemberAnnotation annotation, BlockScope scope) { + if (this.enclosingReference != null) { + storeLocations(annotation, Annotation.getLocations(this.enclosingReference, annotation)); + } + return false; + } + public boolean visit(NormalAnnotation annotation, BlockScope scope) { + if (this.enclosingReference != null) { + storeLocations(annotation, Annotation.getLocations(this.enclosingReference, annotation)); + } + return false; + } + public void storeLocations(Annotation annotation, int[] tab) { + String key = String.valueOf(annotation); + if (this.locations.get(key) != null) { + return; + } + if (tab == null) { + this.locations.put(key, null); + return; + } + + StringBuffer buffer = new StringBuffer("["); + for (int i = 0, max = tab.length; i < max; i += 2) { + if (i > 0) { + buffer.append(", "); + } + switch (tab[i]) { + case 0: + buffer.append("ARRAY"); + break; + case 1: + buffer.append("INNER_TYPE"); + break; + case 2: + buffer.append("WILDCARD"); + break; + case 3: + buffer.append("TYPE_ARGUMENT(").append(tab[i+1]).append(')'); + break; + } + } + buffer.append(']'); + this.locations.put(key, String.valueOf(buffer)); + } + + public boolean visit(ArrayTypeReference arrayReference, BlockScope scope) { + if (this.enclosingReference == null) return false; + return true; + } + public boolean visit(ParameterizedSingleTypeReference typeReference, BlockScope scope) { + if (this.enclosingReference == null) return false; + return true; + } + public boolean visit(SingleTypeReference typeReference, BlockScope scope) { + if (this.enclosingReference == null) return false; + return true; + } + } +public TypeAnnotationSyntaxTest(String testName){ + super(testName, referenceCompiler, jsr308TestScratchArea); + if (referenceCompiler != null) { + File f = new File(jsr308TestScratchArea); + if (!f.exists()) { + f.mkdir(); + } + if (f.exists()) { + try { + OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(new File(jsr308TestScratchArea + File.separator + "Marker.java"))); + w.write("@interface Marker {}\n".toCharArray()); + w.close(); + w = new OutputStreamWriter(new FileOutputStream(new File(jsr308TestScratchArea + File.separator + "Normal.java"))); + w.write("@interface Normal {\n\tint value() default 10;\n}\n".toCharArray()); + w.close(); + w = new OutputStreamWriter(new FileOutputStream(new File(jsr308TestScratchArea + File.separator + "SingleMember.java"))); + w.write("@interface SingleMember {\n\tint value() default 10;\n}\n".toCharArray()); + w.close(); + w = new OutputStreamWriter(new FileOutputStream(new File(jsr308TestScratchArea + File.separator + "Positive.java"))); + w.write("@interface Positive {}\n".toCharArray()); + w.close(); + w = new OutputStreamWriter(new FileOutputStream(new File(jsr308TestScratchArea + File.separator + "Negative.java"))); + w.write("@interface Negative{}\n".toCharArray()); + w.close(); + w = new OutputStreamWriter(new FileOutputStream(new File(jsr308TestScratchArea + File.separator + "Readonly.java"))); + w.write("@interface Readonly {}\n".toCharArray()); + w.close(); + w = new OutputStreamWriter(new FileOutputStream(new File(jsr308TestScratchArea + File.separator + "NonNull.java"))); + w.write("@interface NonNull {}\n".toCharArray()); + w.close(); + w = new OutputStreamWriter(new FileOutputStream(new File(jsr308TestScratchArea + File.separator + "HashMap.java"))); + w.write("class HashMap {\n class Iterator {}; \n}\n".toCharArray()); + w.close(); + CHECK_ALL |= CHECK_JAVAC_PARSER; + } catch (IOException e) { + // ignore + } + } + } +} + +static { +// TESTS_NAMES = new String[] { "test0038", "test0039", "test0040a" }; +// TESTS_NUMBERS = new int[] { 133, 134, 135 }; + if (!(new File(referenceCompiler).exists())) { + referenceCompiler = null; + jsr308TestScratchArea = null; + } +} +void traverse (File f) throws IOException { + if (f.isDirectory()) { + File [] files = f.listFiles(); + for (int i = 0; i < files.length; i++) { + traverse(files[i]); + } + } else { + if (f.getName().endsWith(".java")) { + System.out.println(f.getCanonicalPath()); + char [] contents = new char[(int) f.length()]; + FileInputStream fs = new FileInputStream(f); + InputStreamReader isr = null; + try { + isr = new InputStreamReader(fs); + } finally { + if (isr != null) isr.close(); + } + isr.read(contents); + checkParse(contents, null, f.getCanonicalPath(), null); + } + } +} +public void _test000() throws IOException { + traverse(new File("C:\\jsr308tests")); +} + +public void test0001() throws IOException { + String source = "@Marker class A extends String {}\n;" + + "@Marker class B extends @Marker String {}\n" + + "@Marker class C extends @Marker @SingleMember(0) String {}\n" + + "@Marker class D extends @Marker @SingleMember(0) @Normal(Value = 0) String {}\n" + + "@Marker class E extends String {}\n;"; + + String expectedUnitToString = + "@Marker class A extends String {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class B extends @Marker String {\n" + + " B() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class C extends @Marker @SingleMember(0) String {\n" + + " C() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class D extends @Marker @SingleMember(0) @Normal(Value = 0) String {\n" + + " D() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class E extends String {\n" + + " E() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER , source.toCharArray(), null, "test0001", expectedUnitToString); +} +public void test0002() throws IOException { + String source = "class A extends String {}\n;" + + "class B extends @Marker String {}\n" + + "class C extends @Marker @SingleMember(0) String {}\n" + + "class D extends @Marker @SingleMember(0) @Normal(Value = 0) String {}\n" + + "class E extends String {}\n;"; + + String expectedUnitToString = + "class A extends String {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "class B extends @Marker String {\n" + + " B() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "class C extends @Marker @SingleMember(0) String {\n" + + " C() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "class D extends @Marker @SingleMember(0) @Normal(Value = 0) String {\n" + + " D() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "class E extends String {\n" + + " E() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0002", expectedUnitToString); +} +public void test0003() throws IOException { + String source = "@Marker class A implements Comparable, " + + " @Marker Serializable," + + " Cloneable {\n" + + "}\n"; + String expectedUnitToString = + "@Marker class A implements Comparable, @Marker Serializable, Cloneable {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0003", expectedUnitToString); +} +public void test0004() throws IOException { + String source = "@Marker class A implements Comparable, " + + " @Marker @SingleMember(0) Serializable," + + " Cloneable {\n" + + "}\n"; + String expectedUnitToString = + "@Marker class A implements Comparable, @Marker @SingleMember(0) Serializable, Cloneable {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0004", expectedUnitToString); +} +public void test0005() throws IOException { + String source = "@Marker class A implements Comparable, " + + " @Marker @SingleMember(0) @Normal(Value=0) Serializable," + + " Cloneable {\n" + + "}\n"; + String expectedUnitToString = + "@Marker class A implements Comparable, @Marker @SingleMember(0) @Normal(Value = 0) Serializable, Cloneable {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0005", expectedUnitToString); +} +public void test0006() throws IOException { + String source = "@Marker class A implements @Marker Comparable, " + + " @Marker @SingleMember(0) @Normal(Value=0) Serializable," + + " @Marker Cloneable {\n" + + "}\n"; + String expectedUnitToString = + "@Marker class A implements @Marker Comparable, @Marker @SingleMember(0) @Normal(Value = 0) Serializable, @Marker Cloneable {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0006", expectedUnitToString); +} +public void test007() throws IOException { + String source = "@Marker class A extends Object implements Comparable, " + + " @Marker @SingleMember(10) @Normal(Value=0) Serializable," + + " Cloneable {\n" + + "}\n"; + String expectedUnitToString = + "@Marker class A extends Object implements Comparable, @Marker @SingleMember(10) @Normal(Value = 0) Serializable, Cloneable {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0007", expectedUnitToString); +} +public void test0008() throws IOException { + String source = "@Marker class A extends @Marker Object implements Comparable, " + + " @Marker @SingleMember(0) @Normal(Value=0) Serializable," + + " Cloneable {\n" + + "}\n"; + String expectedUnitToString = + "@Marker class A extends @Marker Object implements Comparable, @Marker @SingleMember(0) @Normal(Value = 0) Serializable, Cloneable {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0008", expectedUnitToString); +} +public void test0009() throws IOException { + String source = "@Marker class A extends @Marker @SingleMember(0) Object implements Comparable, " + + " @Marker @SingleMember(0) @Normal(Value=0) Serializable," + + " Cloneable {\n" + + "}\n"; + String expectedUnitToString = + "@Marker class A extends @Marker @SingleMember(0) Object implements Comparable, @Marker @SingleMember(0) @Normal(Value = 0) Serializable, Cloneable {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0009", expectedUnitToString); +} +public void test0010() throws IOException { + String source = "@Marker class A extends @Marker @SingleMember(0) @Normal(Value=0) Object implements Comparable, " + + " @Marker @SingleMember(0) @Normal(Value=0) Serializable," + + " Cloneable {\n" + + "}\n"; + String expectedUnitToString = + "@Marker class A extends @Marker @SingleMember(0) @Normal(Value = 0) Object implements Comparable, @Marker @SingleMember(0) @Normal(Value = 0) Serializable, Cloneable {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0010", expectedUnitToString); +} +public void test0011() throws IOException { + String source = "public class A {\n" + + " int[] f[];\n" + + " @Marker String[] @Marker[][] s[] @SingleMember(0)[][] @Normal(Value = 0)[][];\n" + + " float[] p[];\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " int[][] f;\n" + + " @Marker String[] @Marker [][][] @SingleMember(0) [][] @Normal(Value = 0) [][] s;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0011", expectedUnitToString); +} +public void test0012() throws IOException { + String source = "public class A implements @Readonly Comparable, @NonNull Serializable, Cloneable {\n" + + " int[] f[];\n" + + " @English String[] @NonNull[] s[] @Nullable[][];\n" + + " float[] p[];\n" + + "public static void main(String args[]) {\n" + + " @Readonly String @Nullable[] @NonNull[] s;\n" + + " s = new @Readonly String @NonNull[5] @Nullable[];\n" + + "}\n" + + "}\n"; + String expectedUnitToString = + "public class A implements @Readonly Comparable, @NonNull Serializable, Cloneable {\n" + + " int[][] f;\n" + + " @English String[] @NonNull [][] @Nullable [][] s;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " @Readonly String @Nullable [] @NonNull [] s;\n" + + " s = new @Readonly String @NonNull [5] @Nullable [];\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0012", expectedUnitToString); +} +public void test0013() throws IOException { + String source = "public class A implements @Readonly Comparable, @NonNull Serializable, Cloneable {\n" + + " int[] f[];\n" + + " @English String[] @NonNull[] s[] @Nullable[][];\n" + + " float[] p[];\n" + + "public static void main(String args[]) {\n" + + " @Readonly String s;\n" + + " s = new @Readonly String @NonNull[] @Nullable[] { {\"Hello\"}, {\"World\"}} [0][0];\n" + + "}\n" + + "}\n"; + String expectedUnitToString = + "public class A implements @Readonly Comparable, @NonNull Serializable, Cloneable {\n" + + " int[][] f;\n" + + " @English String[] @NonNull [][] @Nullable [][] s;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " @Readonly String s;\n" + + " s = new @Readonly String @NonNull [] @Nullable []{{\"Hello\"}, {\"World\"}}[0][0];\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0013", expectedUnitToString); +} +public void test0014() throws IOException { + String source = "public class A implements @Readonly Comparable, @NonNull Serializable, Cloneable {\n" + + " int[] f[];\n" + + " @English String[] @NonNull[] s[] @Nullable[][];\n" + + " float[] p[];\n" + + "public static int main(String args[])[] @Marker[][] @Marker @SingleMember(0) @Normal(Value=0)[][] {\n" + + " @Readonly String @Nullable[] @NonNull[] s;\n" + + " s = new @Readonly String @NonNull[5] @Nullable[];\n" + + "}\n" + + "}\n"; + String expectedUnitToString = + "public class A implements @Readonly Comparable, @NonNull Serializable, Cloneable {\n" + + " int[][] f;\n" + + " @English String[] @NonNull [][] @Nullable [][] s;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public static int[] @Marker [][] @Marker @SingleMember(0) @Normal(Value = 0) [][] main(String[] args) {\n" + + " @Readonly String @Nullable [] @NonNull [] s;\n" + + " s = new @Readonly String @NonNull [5] @Nullable [];\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0014", expectedUnitToString); + +} +public void test0015() throws IOException { + String source = "public class A implements @Readonly Comparable, @NonNull Serializable, Cloneable {\n" + + " int[] f[];\n" + + " @English String[] @NonNull[] s[] @Nullable[][];\n" + + " float[] p[];\n" + + "public static int main(String args[])[] @Marker[][] @Marker @SingleMember(0) @Normal(Value=0)[][] {\n" + + " @Readonly String @Nullable[] @NonNull[] s;\n" + + " s = new @Readonly String @NonNull[5] @Nullable[];\n" + + "}\n" + + "@Marker public A () {}\n" + + "}\n"; + String expectedUnitToString = + "public class A implements @Readonly Comparable, @NonNull Serializable, Cloneable {\n" + + " int[][] f;\n" + + " @English String[] @NonNull [][] @Nullable [][] s;\n" + + " float[][] p;\n" + + " public static int[] @Marker [][] @Marker @SingleMember(0) @Normal(Value = 0) [][] main(String[] args) {\n" + + " @Readonly String @Nullable [] @NonNull [] s;\n" + + " s = new @Readonly String @NonNull [5] @Nullable [];\n" + + " }\n" + + " public @Marker A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0015", expectedUnitToString); +} +// parameters +public void test0016() throws IOException { + String source = "public class A {\n" + + "@Marker public int[] @Marker[][] main(int[] @SingleMember(10)[][] args[] @Normal(Value = 10)[][])[] @Marker[][] {\n" + + "}\n" + + "}"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker int[] @Marker [][][] @Marker [][] main(int[] @SingleMember(10) [][][] @Normal(Value = 10) [][] args) {\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0016", expectedUnitToString); +} +public void test0017() throws IOException { + String source = "public class A {\n" + + "@Marker public int[] @Marker[][] main(String[] @SingleMember(10)[][] args[] @Normal(Value = 10)[][])[] @Marker[][] {\n" + + "}\n" + + "}"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker int[] @Marker [][][] @Marker [][] main(String[] @SingleMember(10) [][][] @Normal(Value = 10) [][] args) {\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0017", expectedUnitToString); +} +public void test0018() throws IOException { + String source = "public class A {\n" + + "@Marker public int[] @Marker[][] main(HashMap[] @SingleMember(10)[][] args[] @Normal(Value = 10)[][])[] @Marker[][] {\n" + + "}\n" + + "}"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker int[] @Marker [][][] @Marker [][] main(HashMap[] @Normal(Value = 10) [][][] @SingleMember(10) [][] args) {\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0018", expectedUnitToString); +} +public void test0019() throws IOException { + String source = "public class A {\n" + + "@Marker public int[] @Marker [][] main(HashMap.Iterator[] @SingleMember(10) [][] args[] @Normal(Value = 10) [][])[] @Marker [][] {\n" + + "}\n" + + "}"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker int[] @Marker [][][] @Marker [][] main(HashMap.Iterator[] @Normal(Value = 10) [][][] @SingleMember(10) [][] args) {\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0019", expectedUnitToString); +} +// varargs annotation +public void test0020() throws IOException { + String source = "public class A {\n" + + "@Marker public int[] @Marker[][] main(int[] @SingleMember(10)[][] @Marker ... args )[] @Marker[][] {\n" + + "}\n" + + "}"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker int[] @Marker [][][] @Marker [][] main(int[] @SingleMember(10) [][] @Marker ... args) {\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0020", expectedUnitToString); +} +public void test0021() throws IOException { + String source = "public class A {\n" + + "@Marker public int[] @Marker[][] main(String[] @SingleMember(10)[][] @Marker ... args )[] @Marker[][] {\n" + + "}\n" + + "}"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker int[] @Marker [][][] @Marker [][] main(String[] @SingleMember(10) [][] @Marker ... args) {\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0021", expectedUnitToString); +} +public void test0022() throws IOException { + String source = "public class A {\n" + + "@Marker public int[] @Marker[][] main(HashMap[] @SingleMember(10)[][] @Marker ... args )[] @Marker[][] {\n" + + "}\n" + + "}"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker int[] @Marker [][][] @Marker [][] main(HashMap[] @SingleMember(10) [][] @Marker ... args) {\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0022", expectedUnitToString); +} +public void test0023() throws IOException { + String source = "public class A {\n" + + "@Marker public int[] @Marker[][] main(HashMap.Iterator[] @SingleMember(10)[][] @Marker ... args )[] @Marker[][] {\n" + + "}\n" + + "}"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker int[] @Marker [][][] @Marker [][] main(HashMap.Iterator[] @SingleMember(10) [][] @Marker ... args) {\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0023", expectedUnitToString); +} +// local variables +public void test0024() throws IOException { + String source = "public class A implements @Readonly Comparable, @NonNull Serializable, Cloneable {\n" + + "public static void main(String args[]) {\n" + + " int[] f[];\n" + + " @English String[] @NonNull[] s[] @Nullable[][];\n" + + " float[] p[];\n" + + "}\n" + + "}\n"; + String expectedUnitToString = + "public class A implements @Readonly Comparable, @NonNull Serializable, Cloneable {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int[][] f;\n" + + " @English String[] @NonNull [][] @Nullable [][] s;\n" + + " float[][] p;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0024", expectedUnitToString); +} +// type parameter +public void test0025() throws IOException { + String source = "class A {\n" + + "public void foo() {\n" + + "}\n" + + "}\n"; + String expectedUnitToString = + "class A {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0025", expectedUnitToString); +} +// Type +public void test0026() throws IOException { + String source = "class A {\n" + + "public @Marker int foo() {\n" + + " return 0;\n" + + "}\n" + + "public int bar() {\n" + + " return 0;\n" + + "}\n" + + "}\n"; + String expectedError = ""; + checkParse(CHECK_PARSER, source.toCharArray(), expectedError, "test0026", null); +} +// Type +public void test0027() throws IOException { + String source = "class A {\n" + + "public @Marker String foo() {\n" + + " return null;\n" + + "}\n" + + "public String bar () {\n" + + " return null;\n" + + "}\n" + + "}\n"; + String expectedError = ""; + checkParse(CHECK_PARSER, source.toCharArray(), expectedError, "test0027", null); +} +//Type +public void test0028() throws IOException { + String source = "class A {\n" + + "public @Marker HashMap<@Readonly String, Object> foo() {\n" + + " return null;\n" + + "}\n" + + "public HashMap bar () {\n" + + " return null;\n" + + "}\n" + + "}\n"; + String expectedError = ""; + checkParse(CHECK_PARSER, source.toCharArray(), expectedError, "test0028", null); +} +// Type +public void test0029() throws IOException { + String source = "class A {\n" + + "public @Marker HashMap<@Readonly String, Object>.Iterator foo() {\n" + + " return null;\n" + + "}\n" + + "public HashMap.Iterator bar () {\n" + + " return null;\n" + + "}\n" + + "}\n"; + String expectedError = ""; + checkParse(CHECK_PARSER, source.toCharArray(), expectedError, "test0029", null); +} +//Type +public void test0030() throws IOException { + String source = "class A {\n" + + "public @Marker HashMap<@Readonly String, Object>.Iterator[] @NonEmpty[][] foo() {\n" + + " return null;\n" + + "}\n" + + "public HashMap.Iterator[] @NonEmpty[][] bar () {\n" + + " return null;\n" + + "}\n" + + "}\n"; + String expectedError = ""; + checkParse(CHECK_PARSER, source.toCharArray(), expectedError, "test0030", null); +} +//Type +public void test0031() throws IOException { + String source = "class A {\n" + + "public @Marker int[] @NonEmpty[][] foo() {\n" + + " return 0;\n" + + "}\n" + + "public int[] @NonEmpty[][] bar() {\n" + + " return 0;\n" + + "}\n" + + "}\n"; + String expectedError = ""; + checkParse(CHECK_PARSER, source.toCharArray(), expectedError, "test0031", null); +} +// Type +public void test0032() throws IOException { + String source = "class A {\n" + + "public @Marker String[]@NonEmpty[][] foo() {\n" + + " return null;\n" + + "}\n" + + "public String[]@NonEmpty[][] bar () {\n" + + " return null;\n" + + "}\n" + + "}\n"; + String expectedError = ""; + checkParse(CHECK_PARSER, source.toCharArray(), expectedError, "test0032", null); +} +//Type +public void test0033() throws IOException { + String source = "class A {\n" + + "public @Marker HashMap<@Readonly String, Object>[] @NonEmpty[][] foo() {\n" + + " return null;\n" + + "}\n" + + "public HashMap[]@NonEmpty[][] bar () {\n" + + " return null;\n" + + "}\n" + + "}\n"; + String expectedError = ""; + checkParse(CHECK_PARSER, source.toCharArray(), expectedError, "test0033", null); +} +// Type0 field declaration. +public void test0034() throws IOException { + String source = "public class A {\n" + + " int[] f[];\n" + + " @Marker int k;\n" + + " float[] p[];\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " int[][] f;\n" + + " @Marker int k;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0034", expectedUnitToString); +} +//Type0 field declaration. +public void test0035() throws IOException { + String source = "public class A {\n" + + " int[] f[];\n" + + " @Marker String k;\n" + + " float[] p[];\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " int[][] f;\n" + + " @Marker String k;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0035", expectedUnitToString); +} +//Type0 field declaration. +public void test0036() throws IOException { + String source = "public class A {\n" + + " int[] f[];\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer> k;\n" + + " float[] p[];\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " int[][] f;\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer> k;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0036", expectedUnitToString); +} +//Type0 field declaration. +public void test0037() throws IOException { + String source = "public class A {\n" + + " int[] f[];\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator k;\n" + + " float[] p[];\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " int[][] f;\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator k;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0037", expectedUnitToString); +} +//Type0 field declaration. +public void test0038() throws IOException { + String source = "public class A {\n" + + " int[] f[];\n" + + " @Marker int[] @NonEmpty[][] k;\n" + + " float[] p[];\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " int[][] f;\n" + + " @Marker int[] @NonEmpty [][] k;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0038", expectedUnitToString); +} +//Type0 field declaration. +public void test0039() throws IOException { + String source = "public class A {\n" + + " int[] f[];\n" + + " @Marker String[] @NonEmpty[][]k;\n" + + " float[] p[];\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " int[][] f;\n" + + " @Marker String[] @NonEmpty [][] k;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0039", expectedUnitToString); +} +//Type0 field declaration. +public void test0040() throws IOException { + String source = "public class A {\n" + + " int[] f[];\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>[] @NonEmpty[][] k;\n" + + " float[] p[];\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " int[][] f;\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>[] @NonEmpty [][] k;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0040", expectedUnitToString); +} +//Type0 field declaration. +public void test0041() throws IOException { + String source = "public class A {\n" + + " int[] f[];\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator[] @NonEmpty[][] k;\n" + + " float[] p[];\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " int[][] f;\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator[] @NonEmpty [][] k;\n" + + " float[][] p;\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0041", expectedUnitToString); +} +//Type0 MethodHeaderName. +public void test0042() throws IOException { + String source = "public class A {\n" + + " public @Marker int foo() { return 0; }\n" + + " public int bar() { return 0; }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker int foo() {\n" + + " return 0;\n" + + " }\n" + + " public int bar() {\n" + + " return 0;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0042", expectedUnitToString); +} +//Type0 MethodHeaderName. +public void test0043() throws IOException { + String source = "public class A {\n" + + " public @Marker String foo() { return null; }\n" + + " public String bar() { return null; }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker String foo() {\n" + + " return null;\n" + + " }\n" + + " public String bar() {\n" + + " return null;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0043", expectedUnitToString); +} +//Type0 MethodHeaderName. +public void test0044() throws IOException { + String source = "public class A {\n" + + " public @Marker HashMap<@Positive Integer, @Negative Integer> foo() { return null; }\n" + + " public HashMap<@Positive Integer, @Negative Integer> bar() { return null; }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker HashMap<@Positive Integer, @Negative Integer> foo() {\n" + + " return null;\n" + + " }\n" + + " public HashMap<@Positive Integer, @Negative Integer> bar() {\n" + + " return null;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0044", expectedUnitToString); +} +//Type0 MethodHeaderName. +public void test0045() throws IOException { + String source = "public class A {\n" + + " public @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator foo() { return null; }\n" + + " public HashMap<@Positive Integer, @Negative Integer>.Iterator bar() { return null; }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator foo() {\n" + + " return null;\n" + + " }\n" + + " public HashMap<@Positive Integer, @Negative Integer>.Iterator bar() {\n" + + " return null;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0045", expectedUnitToString); +} +//Type0 MethodHeaderName. +public void test0046() throws IOException { + String source = "public class A {\n" + + " public @Marker int[] foo() @NonEmpty[][] { return 0; }\n" + + " public int[] @NonEmpty[][] bar() { return 0; }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker int[] @NonEmpty [][] foo() {\n" + + " return 0;\n" + + " }\n" + + " public int[] @NonEmpty [][] bar() {\n" + + " return 0;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0046", expectedUnitToString); +} +//Type0 MethodHeaderName. +public void test0047() throws IOException { + String source = "public class A {\n" + + " public @Marker String[] foo() @NonEmpty[][] { return null; }\n" + + " public String[] @NonEmpty[][] bar() { return null; }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker String[] @NonEmpty [][] foo() {\n" + + " return null;\n" + + " }\n" + + " public String[] @NonEmpty [][] bar() {\n" + + " return null;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0047", expectedUnitToString); +} +//Type0 MethodHeaderName. +public void test0048() throws IOException { + String source = "public class A {\n" + + " public @Marker HashMap<@Positive Integer, @Negative Integer>[] foo() @NonEmpty[][] { return null; }\n" + + " public HashMap<@Positive Integer, @Negative Integer> [] @NonEmpty[][] bar() { return null; }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker HashMap<@Positive Integer, @Negative Integer> @NonEmpty [][][] foo() {\n" + + " return null;\n" + + " }\n" + + " public HashMap<@Positive Integer, @Negative Integer>[] @NonEmpty [][] bar() {\n" + + " return null;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0048", expectedUnitToString); +} +//Type0 MethodHeaderName. +public void test0049() throws IOException { + String source = "public class A {\n" + + " public @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator[] foo() @NonEmpty[][] { return null; }\n" + + " public HashMap<@Positive Integer, @Negative Integer>.Iterator[] @NonEmpty[][] bar() { return null; }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator @NonEmpty [][][] foo() {\n" + + " return null;\n" + + " }\n" + + " public HashMap<@Positive Integer, @Negative Integer>.Iterator[] @NonEmpty [][] bar() {\n" + + " return null;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0049", expectedUnitToString); +} +//Type0 local variable declaration +public void test0050() throws IOException { + String source = "public class A {\n" + + " public void foo() {\n" + + " @Marker int p;\n" + + " int q;\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " @Marker int p;\n" + + " int q;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0050", expectedUnitToString); +} +//Type0 local variable declaration +public void test0051() throws IOException { + String source = "public class A {\n" + + " public void foo() {\n" + + " @Marker String p;\n" + + " String q;\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " @Marker String p;\n" + + " String q;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0051", expectedUnitToString); +} +//Type0 local variable declaration +public void test0052() throws IOException { + String source = "public class A {\n" + + " public void foo() {\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer> p;\n" + + " HashMap<@Positive Integer, @Negative Integer> q;\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer> p;\n" + + " HashMap<@Positive Integer, @Negative Integer> q;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0052", expectedUnitToString); +} +//Type0 local variable declaration +public void test0053() throws IOException { + String source = "public class A {\n" + + " public void foo() {\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator p;\n" + + " HashMap<@Positive Integer, @Negative Integer>.Iterator q;\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator p;\n" + + " HashMap<@Positive Integer, @Negative Integer>.Iterator q;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0053", expectedUnitToString); +} +//Type0 local variable declaration +public void test0054() throws IOException { + String source = "public class A {\n" + + " public void foo() {\n" + + " @Marker int[] @NonNull[] p @NonEmpty[][];\n" + + " int[] @NonNull[] q @NonEmpty[][];\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " @Marker int[] @NonNull [] @NonEmpty [][] p;\n" + + " int[] @NonNull [] @NonEmpty [][] q;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0054", expectedUnitToString); +} +//Type0 local variable declaration +public void test0055() throws IOException { + String source = "public class A {\n" + + " public void foo() {\n" + + " @Marker String[] @NonNull[] p @NonEmpty[][];\n" + + " String[] @NonNull[] q @NonEmpty[][];\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " @Marker String[] @NonNull [] @NonEmpty [][] p;\n" + + " String[] @NonNull [] @NonEmpty [][] q;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0055", expectedUnitToString); +} +//Type0 local variable declaration +public void test0056() throws IOException { + String source = "public class A {\n" + + " public void foo() {\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>[] @NonNull[] p @NonEmpty[][];\n" + + " HashMap<@Positive Integer, @Negative Integer>[] @NonNull[] q @NonEmpty[][];\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer> @NonEmpty [][][] @NonNull [] p;\n" + + " HashMap<@Positive Integer, @Negative Integer> @NonEmpty [][][] @NonNull [] q;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0056", expectedUnitToString); +} +//Type0 local variable declaration +public void test0057() throws IOException { + String source = "public class A {\n" + + " public void foo() {\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator[] @NonNull[] p @NonEmpty[][];\n" + + " HashMap<@Positive Integer, @Negative Integer>.Iterator[] @NonNull[] @NonEmpty[][] q;\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " @Marker HashMap<@Positive Integer, @Negative Integer>.Iterator @NonEmpty [][][] @NonNull [] p;\n" + + " HashMap<@Positive Integer, @Negative Integer>.Iterator[] @NonNull [] @NonEmpty [][] q;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0057", expectedUnitToString); +} +//Type0 foreach +public void test0058() throws IOException { + String source = "public class A {\n" + + " public void foo() {\n" + + " String @NonNull[] @Marker[] s @Readonly[];\n" + + " for (@Readonly String @NonNull[] si @Marker[] : s) {}\n" + + " for (String @NonNull[] sii @Marker[] : s) {}\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " String @NonNull [] @Marker [] @Readonly [] s;\n" + + " for (@Readonly String @NonNull [] @Marker [] si : s) \n" + + " {\n" + + " }\n" + + " for (String @NonNull [] @Marker [] sii : s) \n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0058", expectedUnitToString); +} +//Type0 foreach +public void test0059() throws IOException { + String source = "public class A {\n" + + " public void foo() {\n" + + " int @NonNull[] @Marker[] s @Readonly[];\n" + + " for (@Readonly int @NonNull[] si @Marker[] : s) {}\n" + + " for (int @NonNull[] sii @Marker[] : s) {}\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class A {\n" + + " public A() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " int @NonNull [] @Marker [] @Readonly [] s;\n" + + " for (@Readonly int @NonNull [] @Marker [] si : s) \n" + + " {\n" + + " }\n" + + " for (int @NonNull [] @Marker [] sii : s) \n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0059", expectedUnitToString); +} +// cast expression +public void test0060() throws IOException { + String source = "public class Clazz {\n" + + "public static void main(String[] args) {\n" + + "int x;\n" + + "x = (Integer)\n" + + "(@Readonly Object)\n" + + "(@Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator[] @Normal(Value=0)[][] )\n" + + "(@Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator[] @SingleMember(0)[][] )\n" + + "(@Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator[] @Marker[][] )\n" + + "(@Readonly Object)\n" + + "(@Readonly HashMap<@Positive Integer, @Negative Integer>[] @Normal(Value=0)[][] )\n" + + "(@Readonly HashMap<@Positive Integer, @Negative Integer>[] @SingleMember(0)[][] )\n" + + "(@Readonly HashMap<@Positive Integer, @Negative Integer>[] @Marker[][] )\n" + + "(@Readonly Object)\n" + + "(@Readonly String[] @Normal(Value=0)[][] )\n" + + "(@Readonly String[] @SingleMember(0)[][] )\n" + + "(@Readonly String[] @Marker[][] )\n" + + "(@Readonly Object)\n" + + "(@Readonly int[] @Normal(Value=0)[][] )\n" + + "(@Readonly int[] @SingleMember(0)[][] )\n" + + "(@Readonly int[] @Marker[][] )\n" + + "(@Readonly Object)\n" + + "(@Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator)\n" + + "(@Readonly Object)\n" + + "(@Readonly HashMap<@Positive Integer, @Negative Integer>)\n" + + "(@Readonly Object)\n" + + "(@ReadOnly String)\n" + + "(@Readonly Object)\n" + + "(@Readonly int) 10;\n" + + "}\n" + + "}\n"; + String expectedUnitToString = + "public class Clazz {\n" + + " public Clazz() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int x;\n" + + " x = (Integer) (@Readonly Object) (@Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator[] @Normal(Value = 0) [][]) (@Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator[] @SingleMember(0) [][]) (@Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator[] @Marker [][]) (@Readonly Object) (@Readonly HashMap<@Positive Integer, @Negative Integer>[] @Normal(Value = 0) [][]) (@Readonly HashMap<@Positive Integer, @Negative Integer>[] @SingleMember(0) [][]) (@Readonly HashMap<@Positive Integer, @Negative Integer>[] @Marker [][]) (@Readonly Object) (@Readonly String[] @Normal(Value = 0) [][]) (@Readonly String[] @SingleMember(0) [][]) (@Readonly String[] @Marker [][]) (@Readonly Object) (@Readonly int[] @Normal(Value = 0) [][]) (@Readonly int[] @SingleMember(0) [][]) (@Readonly int[] @Marker [][]) (@Readonly Object) (@Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator) (@Readonly Object) (@Readonly HashMap<@Positive Integer, @Negative Integer>) (@Readonly Object) (@ReadOnly String) (@Readonly Object) (@Readonly int) 10;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0060", expectedUnitToString); +} +//cast expression +public void test0061() throws IOException { + String source = "public class Clazz {\n" + + "public static void main(String[] args) {\n" + + "int x;\n" + + "x = (Integer)\n" + + "(Object)\n" + + "(@Readonly HashMap.Iterator[] @Normal(Value=0)[][] )\n" + + "(HashMap<@Positive Integer, Integer>.Iterator[] @SingleMember(0)[][] )\n" + + "(@Readonly HashMap.Iterator[] @Marker[][] )\n" + + "(Object)\n" + + "(@Readonly HashMap<@Positive Integer, Integer>[] @Normal(Value=0)[][] )\n" + + "(HashMap[] @SingleMember(0)[][] )\n" + + "(@Readonly HashMap<@Positive Integer, Integer>[] @Marker[][] )\n" + + "(Object)\n" + + "(@Readonly String[] @Normal(Value=0)[][] )\n" + + "(String[] @SingleMember(0)[][] )\n" + + "(@Readonly String[] @Marker[][] )\n" + + "(Object)\n" + + "(@Readonly int[] @Normal(Value=0)[][] )\n" + + "(int[] @SingleMember(0)[][] )\n" + + "(@Readonly int[] @Marker[][] )\n" + + "(Object)\n" + + "(@Readonly HashMap.Iterator)\n" + + "(Object)\n" + + "(@Readonly HashMap<@Positive Integer, Integer>)\n" + + "(Object)\n" + + "(@ReadOnly String)\n" + + "(Object)\n" + + "(@Readonly int) 10;\n" + + "}\n" + + "}\n"; + String expectedUnitToString = + "public class Clazz {\n" + + " public Clazz() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int x;\n" + + " x = (Integer) (Object) (@Readonly HashMap.Iterator[] @Normal(Value = 0) [][]) (HashMap<@Positive Integer, Integer>.Iterator[] @SingleMember(0) [][]) (@Readonly HashMap.Iterator[] @Marker [][]) (Object) (@Readonly HashMap<@Positive Integer, Integer>[] @Normal(Value = 0) [][]) (HashMap[] @SingleMember(0) [][]) (@Readonly HashMap<@Positive Integer, Integer>[] @Marker [][]) (Object) (@Readonly String[] @Normal(Value = 0) [][]) (String[] @SingleMember(0) [][]) (@Readonly String[] @Marker [][]) (Object) (@Readonly int[] @Normal(Value = 0) [][]) (int[] @SingleMember(0) [][]) (@Readonly int[] @Marker [][]) (Object) (@Readonly HashMap.Iterator) (Object) (@Readonly HashMap<@Positive Integer, Integer>) (Object) (@ReadOnly String) (Object) (@Readonly int) 10;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0061", expectedUnitToString); +} +// instanceof checks +public void test0062() throws IOException { + String source = "public class Clazz {\n" + + "public static void main(Object o) {\n" + + "if (o instanceof @Readonly String) {\n" + + "} else if (o instanceof @Readonly int[] @NonEmpty[][] ) {\n" + + "} else if (o instanceof @Readonly String[] @NonEmpty[][] ) {\n" + + "} else if (o instanceof @Readonly HashMap[] @NonEmpty[][] ) {\n" + + "} else if (o instanceof @Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator[] @NonEmpty[][] ) {\n" + + "} else if (o instanceof @Readonly HashMap) {\n" + + "} else if (o instanceof @Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator) {\n" + + "}\n" + + "}\n" + + "}"; + String expectedUnitToString = + "public class Clazz {\n" + + " public Clazz() {\n" + + " super();\n" + + " }\n" + + " public static void main(Object o) {\n" + + " if ((o instanceof @Readonly String))\n" + + " {\n" + + " }\n" + + " else\n" + + " if ((o instanceof @Readonly int[] @NonEmpty [][]))\n" + + " {\n" + + " }\n" + + " else\n" + + " if ((o instanceof @Readonly String[] @NonEmpty [][]))\n" + + " {\n" + + " }\n" + + " else\n" + + " if ((o instanceof @Readonly HashMap[] @NonEmpty [][]))\n" + + " {\n" + + " }\n" + + " else\n" + + " if ((o instanceof @Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator[] @NonEmpty [][]))\n" + + " {\n" + + " }\n" + + " else\n" + + " if ((o instanceof @Readonly HashMap))\n" + + " {\n" + + " }\n" + + " else\n" + + " if ((o instanceof @Readonly HashMap<@Positive Integer, @Negative Integer>.Iterator))\n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0062", expectedUnitToString); +} +// assorted unclassified +public void test0063() throws IOException { + String source = "import java.util.HashMap;\n" + + "import java.util.Map; \n" + + "\n" + + "public class Clazz <@A M extends @B String, @C N extends @D Comparable> extends\n" + + " @E Object implements @F Comparable <@G Object> {\n" + + " \n" + + " Clazz(char[] ...args) { \n" + + " }\n" + + " \n" + + " int @I[] f @J[], g, h[], i@K[];\n" + + " int @L[][]@M[] f2; \n" + + " \n" + + " Clazz (int @N[] @O... a) {}\n" + + " int @R[]@S[] aa() {}\n" + + " \n" + + " int @T[]@U[]@V[] a () @W[]@X[]@Y[] { return null; }\n" + + " \n" + + " public void main(String @A[] @B ... args) throws @D Exception {\n" + + " \n" + + " HashMap<@E String, @F String> b1;\n" + + " \n" + + " int b; b = (@G int) 10;\n" + + " \n" + + " char @H[]@I[] ch; ch = (@K char @L[]@M[])(@N char @O[]@P[]) null;\n" + + " \n" + + " int[] i; i = new @Q int @R[10];\n" + + " \n" + + " \n" + + " Integer w; w = new X<@S String, @T Integer>().get(new @U Integer(12));\n" + + " throw new @V Exception(\"test\");\n" + + " boolean c; c = null instanceof @W String;\n" + + " } \n" + + " public <@X X, @Y Y> void foo(X x, Y @Z... y) { \n" + + " \n" + + "}\n" + + " \n" + + " void foo(Map m){}\n" + + " public int compareTo(Object arg0) {\n" + + " return 0;\n" + + " }\n" + + "\n" + + "}\n" + + "class X<@C K, @D T extends @E Object & @F Comparable> {\n" + + " \n" + + " public Integer get(Integer integer) {\n" + + " return null;\n" + + " }\n" + + "}\n"; + + + String expectedUnitToString = "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class Clazz<@A M extends @B String, @C N extends @D Comparable> extends @E Object implements @F Comparable<@G Object> {\n" + + " int @I [] @J [] f;\n" + + " int @I [] g;\n" + + " int @I [][] h;\n" + + " int @I [] @K [] i;\n" + + " int @L [][] @M [] f2;\n" + + " Clazz(char[]... args) {\n" + + " super();\n" + + " }\n" + + " Clazz(int @N [] @O ... a) {\n" + + " super();\n" + + " }\n" + + " int @R [] @S [] aa() {\n" + + " }\n" + + " int @T [] @U [] @V [] @W [] @X [] @Y [] a() {\n" + + " return null;\n" + + " }\n" + + " public void main(String @A [] @B ... args) throws @D Exception {\n" + + " HashMap<@E String, @F String> b1;\n" + + " int b;\n" + + " b = (@G int) 10;\n" + + " char @H [] @I [] ch;\n" + + " ch = (@K char @L [] @M []) (@N char @O [] @P []) null;\n" + + " int[] i;\n" + + " i = new @Q int @R [10];\n" + + " Integer w;\n" + + " w = new X<@S String, @T Integer>().get(new @U Integer(12));\n" + + " throw new @V Exception(\"test\");\n" + + " boolean c;\n" + + " c = (null instanceof @W String);\n" + + " }\n" + + " public <@X X, @Y Y>void foo(X x, Y @Z ... y) {\n" + + " }\n" + + " void foo(Map m) {\n" + + " }\n" + + " public int compareTo(Object arg0) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class X<@C K, @D T extends @E Object & @F Comparable> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public Integer get(Integer integer) {\n" + + " return null;\n" + + " }\n" + + "}\n"; + // indexing parser avoids creating lots of nodes, so parse tree comes out incorrectly. + // this is not bug, but intended behavior - see IndexingParser.newSingleNameReference(char[], long) + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0063", expectedUnitToString); +} +//assorted unclassified +public void test0064() throws IOException { + String source = "class X> {}\n"; + String expectedUnitToString = "class X> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + // indexing parser avoids creating lots of nodes, so parse tree comes out incorrectly. + // this is not bug, but intended behavior - see IndexingParser.newSingleNameReference(char[], long) + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test064", expectedUnitToString); +} +//type class literal expression +public void test0066() throws IOException { + String source = "public class X {\n" + + " & Cloneable> void foo(T t) {}\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " & Cloneable>void foo(T t) {\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0066", expectedUnitToString); +} +//check locations +public void test0067() throws IOException { + String source = + "public class X {\n" + + " @H String @E[] @F[] @G[] field;\n" + + " @A Map<@B String, @C List<@D Object>> field2;\n" + + " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @H String @E [] @F [] @G [] field;\n" + + " @A Map<@B String, @C List<@D Object>> field2;\n" + + " @A Map<@B String, @H String @E [] @F [] @G []> field3;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0067", expectedUnitToString); +} +//check locations +public void test0068() throws IOException { + String source = + "public class X {\n" + + " @H String @E[] @F[] @G[] field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @H String @E [] @F [] @G [] field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0068", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 4, locations.size()); + assertEquals("Wrong location", null, locations.get("@E")); + assertEquals("Wrong location", "[ARRAY]", locations.get("@F")); + assertEquals("Wrong location", "[ARRAY, ARRAY]", locations.get("@G")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY]", locations.get("@H")); +} +//check locations +public void test0069() throws IOException { + String source = + "public class X {\n" + + " @A Map<@B String, @H String> field3;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A Map<@B String, @H String> field3;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0069", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 3, locations.size()); + assertEquals("Wrong location", null, locations.get("@A")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0)]", locations.get("@B")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1)]", locations.get("@H")); +} +//check locations +public void test0070() throws IOException { + String source = + "public class X {\n" + + " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A Map<@B String, @H String @E [] @F [] @G []> field3;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0070", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 6, locations.size()); + assertEquals("Wrong location", null, locations.get("@A")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0)]", locations.get("@B")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1)]", locations.get("@E")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), ARRAY]", locations.get("@F")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), ARRAY, ARRAY]", locations.get("@G")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), ARRAY, ARRAY, ARRAY]", locations.get("@H")); +} +//check locations +public void test0071() throws IOException { + String source = + "public class X {\n" + + " @A Map<@B String, @C List<@H String @E[][] @G[]>> field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A Map<@B String, @C List<@H String @E [][] @G []>> field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0071", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 6, locations.size()); + assertEquals("Wrong location", null, locations.get("@A")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0)]", locations.get("@B")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1)]", locations.get("@C")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]", locations.get("@H")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]", locations.get("@E")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), TYPE_ARGUMENT(0), ARRAY, ARRAY]", locations.get("@G")); +} +//check locations +public void test0072() throws IOException { + String source = + "public class X {\n" + + " @A Map<@B String, @C List<@H String @E[][] @G[]>>[] @I[] @J[] field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A Map<@B String, @C List<@H String @E [][] @G []>>[] @I [] @J [] field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0072", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 8, locations.size()); + assertEquals("Wrong location", "[ARRAY]", locations.get("@I")); + assertEquals("Wrong location", "[ARRAY, ARRAY]", locations.get("@J")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY]", locations.get("@A")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0)]", locations.get("@B")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1)]", locations.get("@C")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1), TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]", locations.get("@H")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]", locations.get("@E")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1), TYPE_ARGUMENT(0), ARRAY, ARRAY]", locations.get("@G")); +} +//check locations +public void test0073() throws IOException { + String source = + "public class X {\n" + + " @A Map<@B String, @C List<@H String @E[][] @G[]>> @I[][] @J[] field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A Map<@B String, @C List<@H String @E [][] @G []>> @I [][] @J [] field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0073", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 8, locations.size()); + assertEquals("Wrong location", null, locations.get("@I")); + assertEquals("Wrong location", "[ARRAY, ARRAY]", locations.get("@J")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY]", locations.get("@A")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0)]", locations.get("@B")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1)]", locations.get("@C")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1), TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]", locations.get("@H")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]", locations.get("@E")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1), TYPE_ARGUMENT(0), ARRAY, ARRAY]", locations.get("@G")); +} +//check locations +public void test0074() throws IOException { + String source = + "public class X {\n" + + " @A Map<@C List<@H String @E[][] @G[]>, String @B[] @D[]> @I[] @F[] @J[] field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A Map<@C List<@H String @E [][] @G []>, String @B [] @D []> @I [] @F [] @J [] field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0074", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 10, locations.size()); + assertEquals("Wrong location", null, locations.get("@I")); + assertEquals("Wrong location", "[ARRAY]", locations.get("@F")); + assertEquals("Wrong location", "[ARRAY, ARRAY]", locations.get("@J")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY]", locations.get("@A")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0)]", locations.get("@C")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0), TYPE_ARGUMENT(0)]", locations.get("@E")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY, ARRAY]", locations.get("@G")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]", locations.get("@H")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1), ARRAY]", locations.get("@D")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1)]", locations.get("@B")); +} +//check locations +public void test0075() throws IOException { + String source = + "public class X {\n" + + " @A Map<@C List<@H String @E[][] @G[]>, @B List> [] @I[] @F[] @J[] field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A Map<@C List<@H String @E [][] @G []>, @B List>[] @I [] @F [] @J [] field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0075", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 10, locations.size()); + assertEquals("Wrong location", "[ARRAY]", locations.get("@I")); + assertEquals("Wrong location", "[ARRAY, ARRAY]", locations.get("@F")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY]", locations.get("@J")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, ARRAY]", locations.get("@A")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0)]", locations.get("@C")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0), TYPE_ARGUMENT(0)]", locations.get("@E")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY, ARRAY]", locations.get("@G")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]", locations.get("@H")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1)]", locations.get("@B")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(1), TYPE_ARGUMENT(0), ARRAY]", locations.get("@D")); +} +//check locations +public void test0076() throws IOException { + String source = + "public class X {\n" + + " @A Map<@B String, @C List<@D Object>> field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A Map<@B String, @C List<@D Object>> field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0076", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 4, locations.size()); + assertEquals("Wrong location", null, locations.get("@A")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0)]", locations.get("@B")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1)]", locations.get("@C")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]", locations.get("@D")); +} +//check locations +public void test0077() throws IOException { + String source = + "public class X {\n" + + " @H String @E[] @F[] @G[] field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @H String @E [] @F [] @G [] field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0077", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 4, locations.size()); + assertEquals("Wrong location", null, locations.get("@E")); + assertEquals("Wrong location", "[ARRAY]", locations.get("@F")); + assertEquals("Wrong location", "[ARRAY, ARRAY]", locations.get("@G")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY]", locations.get("@H")); +} +//check locations +public void test0078() throws IOException { + String source = + "public class X {\n" + + " @A Map<@B Comparable<@C Object @D[] @E[] @F[]>, @G List<@H Document>> field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A Map<@B Comparable<@C Object @D [] @E [] @F []>, @G List<@H Document>> field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0078", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 8, locations.size()); + assertEquals("Wrong location", null, locations.get("@A")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0)]", locations.get("@B")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]", locations.get("@C")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0), TYPE_ARGUMENT(0)]", locations.get("@D")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY]", locations.get("@E")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY, ARRAY]", locations.get("@F")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1)]", locations.get("@G")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]", locations.get("@H")); +} +//check locations +public void test0079() throws IOException { + String source = + "public class X {\n" + + " @A java.util.Map<@B Comparable<@C Object @D[] @E[] @F[]>, @G List<@H Document>> field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A java.util.Map<@B Comparable<@C Object @D [] @E [] @F []>, @G List<@H Document>> field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0079", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 8, locations.size()); + assertEquals("Wrong location", null, locations.get("@A")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0)]", locations.get("@B")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]", locations.get("@C")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0), TYPE_ARGUMENT(0)]", locations.get("@D")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY]", locations.get("@E")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY, ARRAY]", locations.get("@F")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1)]", locations.get("@G")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]", locations.get("@H")); +} +//check locations +public void test0080() throws IOException { + String source = + "public class X {\n" + + " @B Map field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @B Map field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0080", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 2, locations.size()); + assertEquals("Wrong location", null, locations.get("@B")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), WILDCARD]", locations.get("@A")); +} +//check locations +public void test0081() throws IOException { + String source = + "public class X {\n" + + " @H java.lang.String @E[] @F[] @G[] field;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @H java.lang.String @E [] @F [] @G [] field;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0081", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 4, locations.size()); + assertEquals("Wrong location", null, locations.get("@E")); + assertEquals("Wrong location", "[ARRAY]", locations.get("@F")); + assertEquals("Wrong location", "[ARRAY, ARRAY]", locations.get("@G")); + assertEquals("Wrong location", "[ARRAY, ARRAY, ARRAY]", locations.get("@H")); +} +//check locations +public void test0082() throws IOException { + String source = + "public class X {\n" + + " @A Map<@B java.lang.String, @H java.lang.String @E[] @F[] @G[]> field3;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A Map<@B java.lang.String, @H java.lang.String @E [] @F [] @G []> field3;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + LocationPrinterVisitor visitor = new LocationPrinterVisitor(); + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0082", expectedUnitToString, visitor); + Map locations = visitor.getLocations(); + assertEquals("Wrong size", 6, locations.size()); + assertEquals("Wrong location", null, locations.get("@A")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(0)]", locations.get("@B")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1)]", locations.get("@E")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), ARRAY]", locations.get("@F")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), ARRAY, ARRAY]", locations.get("@G")); + assertEquals("Wrong location", "[TYPE_ARGUMENT(1), ARRAY, ARRAY, ARRAY]", locations.get("@H")); +} +public void test0083() throws IOException { + String source = + "@Marker class A {}\n;" + + "@Marker class B extends @Marker A {}\n" + + "@Marker class C extends @Marker @SingleMember(0) A {}\n" + + "@Marker class D extends @Marker @SingleMember(0) @Normal(value = 0) A {}\n" + + "@Marker class E extends B {}\n;"; + + String expectedUnitToString = + "@Marker class A {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class B extends @Marker A {\n" + + " B() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class C extends @Marker @SingleMember(0) A {\n" + + " C() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class D extends @Marker @SingleMember(0) @Normal(value = 0) A {\n" + + " D() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class E extends B {\n" + + " E() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0083", expectedUnitToString); +} + +// To test Parser.consumeAdditionalBound() with Type annotations +public void test0084() throws IOException { + String source = + "@Marker interface I<@Negative T> {}\n" + + "@SingleMember(0) interface J<@Positive T> {}\n" + + "@Marker class A implements I<@SingleMember(0) A>, J<@Marker A> {}\n" + + "@Normal(value = 1) class X & @Marker @SingleMember(1) J<@Readonly A>> {\n" + + "}"; + String expectedUnitToString = + "@Marker interface I<@Negative T> {\n" + + "}\n" + + "@SingleMember(0) interface J<@Positive T> {\n" + + "}\n" + + "@Marker class A implements I<@SingleMember(0) A>, J<@Marker A> {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Normal(value = 1) class X & @Marker @SingleMember(1) J<@Readonly A>> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0084", expectedUnitToString ); +} + +// To test Parser.consumeAdditionalBound() with Type annotations +public void test0085() throws IOException { + String source = + "import java.io.Serializable;\n" + + "\n" + + "@SingleMember(10) class X {\n" + + " @Negative T t;\n" + + " @Marker X(@Readonly T t) {\n" + + " this.t = t;\n" + + " }\n" + + " void foo(@Marker X this) {\n" + + " (this == null ? t : t).run();\n" + + " ((@Marker V) t).run();\n" + + " }\n" + + " public static void main(@Readonly String @Marker [] args) {\n" + + " new @Marker X<@Marker A, @Negative A>(new @Marker A()).foo();\n" + + " }\n" + + "}\n" + + "@Marker class A implements @Marker Serializable, @SingleMember(1) Runnable {\n" + + " public void run() {\n" + + " System.out.print(\"AA\");\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "import java.io.Serializable;\n" + + "@SingleMember(10) class X {\n" + + " @Negative T t;\n" + + " @Marker X(@Readonly T t) {\n" + + " super();\n" + + " this.t = t;\n" + + " }\n" + + " void foo(@Marker X this) {\n" + + " ((this == null) ? t : t).run();\n" + + " ((@Marker V) t).run();\n" + + " }\n" + + " public static void main(@Readonly String @Marker [] args) {\n" + + " new @Marker X<@Marker A, @Negative A>(new @Marker A()).foo();\n" + + " }\n" + + "}\n" + + "@Marker class A implements @Marker Serializable, @SingleMember(1) Runnable {\n" + + " A() {\n" + + " super();\n" + + " }\n" + + " public void run() {\n" + + " System.out.print(\"AA\");\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0085", expectedUnitToString ); +} + +// To test Parser.classInstanceCreation() with type annotations +public void test0086() throws IOException { + String source = + "class X {\n" + + " @Marker X() {\n" + + " System.out.print(\"new X created\");\n" + + " }\n" + + " void f() throws @Marker InstantiationException {\n" + + " X testX;\n" + + " testX = new @Readonly @Negative X();\n" + + " Double d;\n" + + " d = new @Marker @Positive Double(1.1);\n" + + " throw new @Positive @Normal(value = 10) InstantiationException(\"test\");\n" + + " }\n" + + "}"; + String expectedUnitToString = + "class X {\n" + + " @Marker X() {\n" + + " super();\n" + + " System.out.print(\"new X created\");\n" + + " }\n" + + " void f() throws @Marker InstantiationException {\n" + + " X testX;\n" + + " testX = new @Readonly @Negative X();\n" + + " Double d;\n" + + " d = new @Marker @Positive Double(1.1);\n" + + " throw new @Positive @Normal(value = 10) InstantiationException(\"test\");\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0086", expectedUnitToString ); +} + +// To test Parser.classInstanceCreation() with type annotations +public void test0087() throws IOException { + String source = + "class X {\n" + + " @Marker X() {\n" + + " System.out.print(\"new X created\");\n" + + " }\n" + + " @Marker class Inner {\n" + + " @Normal(value = 10) Inner(){\n" + + " System.out.print(\"X.Inner created\");\n" + + " }\n" + + " }\n" + + " public String getString(){\n" + + " return \"hello\";\n" + + " }\n" + + " void f(@Marker X this) {\n" + + " String testString;\n" + + " testString = new @Readonly @Negative X().getString();\n" + + " X.Inner testInner;\n" + + " testInner = new @Readonly X.Inner();\n" + + " int i;\n" + + " for(i = 0; i < 10; i++)\n" + + " System.out.print(\"test\");\n" + + " }\n" + + "}"; + String expectedUnitToString = + "class X {\n" + + " @Marker class Inner {\n" + + " @Normal(value = 10) Inner() {\n" + + " super();\n" + + " System.out.print(\"X.Inner created\");\n" + + " }\n" + + " }\n" + + " @Marker X() {\n" + + " super();\n" + + " System.out.print(\"new X created\");\n" + + " }\n" + + " public String getString() {\n" + + " return \"hello\";\n" + + " }\n" + + " void f(@Marker X this) {\n" + + " String testString;\n" + + " testString = new @Readonly @Negative X().getString();\n" + + " X.Inner testInner;\n" + + " testInner = new @Readonly X.Inner();\n" + + " int i;\n" + + " for (i = 0; (i < 10); i ++) \n" + + " System.out.print(\"test\");\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0087", expectedUnitToString ); +} + +// To test Parser.classInstanceCreation() with type annotations +public void test0088() throws IOException { + String source = + "import java.io.Serializable;\n" + + "class X {\n" + + " public static void main(String[] args) {\n" + + " new @Marker Serializable() {\n" + + " };\n" + + " new @Positive @Marker Serializable() {\n" + + " public long serialVersion;\n" + + " };\n" + + " }\n" + + "}"; + String expectedUnitToString = + "import java.io.Serializable;\n" + + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new @Marker Serializable() {\n" + + " };\n" + + " new @Positive @Marker Serializable() {\n" + + " public long serialVersion;\n" + + " };\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0088", expectedUnitToString ); +} + +// To test Parser.classInstanceCreation() with type annotations +public void test0089() throws IOException { + String source = + "import java.io.Serializable;\n" + + "class X{\n" + + " public void f() {\n" + + " X testX;\n" + + " testX = new @Marker @SingleMember(10) X<@Negative Integer>();\n" + + " System.out.print(\"object created\");\n" + + " }\n" + + "}"; + String expectedUnitToString = + "import java.io.Serializable;\n" + + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public void f() {\n" + + " X testX;\n" + + " testX = new @Marker @SingleMember(10) X<@Negative Integer>();\n" + + " System.out.print(\"object created\");\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0089", expectedUnitToString ); +} + +// To test Parser.classInstanceCreation() with type annotations +public void test0090() throws IOException { + String source = + "class X <@Marker T extends @Readonly String> {\n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new @Readonly X().baz(\"SUCCESS\");\n" + // Parser.classInstanceCreation called + " }\n" + + " void baz(final T t) {\n" + + " new @Readonly @Marker Object() {\n" + // Parser.classInstanceCreation called + " void print() {\n" + + " }\n" + + " }.print();\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class X<@Marker T extends @Readonly String> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new @Readonly X().baz(\"SUCCESS\");\n" + + " }\n" + + " void baz(final T t) {\n" + + " new @Readonly @Marker Object() {\n" + + " void print() {\n" + + " }\n" + + "}.print();\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0090", expectedUnitToString ); +} + +// To test Parser.consumeArrayCreationExpressionWithInitializer() with Type Annotations +public void test0091() throws IOException { + String source = + "class X <@Marker T extends @Readonly String> {\n" + + " public static void main(String[] args) {\n" + + " int [] x1;\n" + + " x1 = new int @Marker @SingleMember(2) [] {-1, -2};\n" + + " Integer [][] x2;\n" + + " x2 = new @Positive Integer @Marker @SingleMember(3) [] @SingleMember(3) [] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class X<@Marker T extends @Readonly String> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int[] x1;\n" + + " x1 = new int @Marker @SingleMember(2) []{(- 1), (- 2)};\n" + + " Integer[][] x2;\n" + + " x2 = new @Positive Integer @Marker @SingleMember(3) [] @SingleMember(3) []{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0091", expectedUnitToString ); +} + +// To test Parser.consumeArrayCreationExpressionWithInitializer() with Type Annotations +public void test0092() throws IOException { + String source = + "class X {\n" + + " static class T {\n" + + " public @Readonly Object @Normal(value = 10) [] f() {\n" + + " return new @Readonly Object @Normal(value = 10) [] {this, T.this};\n" + + " }\n" + + " }\n" + + "}"; + String expectedUnitToString = + "class X {\n" + + " static class T {\n" + + " T() {\n" + + " super();\n" + + " }\n" + + " public @Readonly Object @Normal(value = 10) [] f() {\n" + + " return new @Readonly Object @Normal(value = 10) []{this, T.this};\n" + + " }\n" + + " }\n" + + " X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0092", expectedUnitToString ); +} + +// To test Parser.consumeArrayCreationExpressionWithInitializer() with Type Annotations +public void test0093() throws IOException { + String source = + "class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.Arrays.asList(new @Readonly Object @SingleMember(1) [] {\"1\"});\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " java.util.Arrays.asList(new @Readonly Object @SingleMember(1) []{\"1\"});\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0093", expectedUnitToString ); +} + +// To test Parser.consumeArrayCreationExpressionWithInitializer() with Type Annotations +public void test0094() throws IOException { + String source = + "class X {\n" + + " public boolean test() {\n" + + " String[] s;\n" + + " s = foo(new @Marker String @SingleMember(1) []{\"hello\"});\n" + + " return s != null;\n" + + " }\n" + + " public <@Marker F> F @SingleMember(1) [] foo(F[] f) {\n" + + " return f;\n" + + " }\n" + + "}"; + String expectedUnitToString = + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public boolean test() {\n" + + " String[] s;\n" + + " s = foo(new @Marker String @SingleMember(1) []{\"hello\"});\n" + + " return (s != null);\n" + + " }\n" + + " public <@Marker F>F @SingleMember(1) [] foo(F[] f) {\n" + + " return f;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0094", expectedUnitToString ); +} + +// To test Parser.consumeArrayCreationExpressionWithInitializer() with Type Annotations +public void test0095() throws IOException { + String source = + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "@Marker class Deejay {\n" + + " @Marker class Counter<@Marker T> {}\n" + + " public void f(String[] args) {\n" + + " Counter<@Positive Integer> songCounter;\n" + + " songCounter = new Counter<@Positive Integer>();\n" + + " Counter<@Readonly String> genre;\n" + + " genre = new Counter<@Readonly String>();\n" + + " List<@Marker Counter> list1;\n" + + " list1 = Arrays.asList(new @Marker Counter @Normal(value = 2) @Marker [] {songCounter, genre});\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "@Marker class Deejay {\n" + + " @Marker class Counter<@Marker T> {\n" + + " Counter() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " Deejay() {\n" + + " super();\n" + + " }\n" + + " public void f(String[] args) {\n" + + " Counter<@Positive Integer> songCounter;\n" + + " songCounter = new Counter<@Positive Integer>();\n" + + " Counter<@Readonly String> genre;\n" + + " genre = new Counter<@Readonly String>();\n" + + " List<@Marker Counter> list1;\n" + + " list1 = Arrays.asList(new @Marker Counter @Normal(value = 2) @Marker []{songCounter, genre});\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0095", expectedUnitToString ); +} + +// To test Parser.consumeArrayCreationExpressionWithoutInitializer() with Type Annotations +public void test0096() throws IOException { + String source = + "class X <@Marker T extends @Readonly String> {\n" + + " public static void main(String[] args) {\n" + + " int [] x1;\n" + + " x1 = new int @Marker @SingleMember(10) [10];\n" + + " Integer [][] x2;\n" + + " x2 = new @Positive Integer @Marker [10] @Normal(value = 10) [10];\n" + + " char[][] tokens;\n" + + " tokens = new char @SingleMember(0) [0] @Normal(value = 10) @Marker [];\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class X<@Marker T extends @Readonly String> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int[] x1;\n" + + " x1 = new int @Marker @SingleMember(10) [10];\n" + + " Integer[][] x2;\n" + + " x2 = new @Positive Integer @Marker [10] @Normal(value = 10) [10];\n" + + " char[][] tokens;\n" + + " tokens = new char @SingleMember(0) [0] @Normal(value = 10) @Marker [];\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0096", expectedUnitToString ); +} + +// To test Parser.consumeArrayCreationExpressionWithoutInitializer() with Type Annotations +public void test0097() throws IOException { + String source = + "class X {\n" + + " public @Readonly Object @Normal(value = 10) [] f(@Marker X this) {\n" + + " return new @Readonly Object @Normal(value = 10) [10];\n" + + " }\n" + + "}"; + String expectedUnitToString = + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public @Readonly Object @Normal(value = 10) [] f(@Marker X this) {\n" + + " return new @Readonly Object @Normal(value = 10) [10];\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0097", expectedUnitToString ); +} + +// To test Parser.consumeArrayCreationExpressionWithoutInitializer() with Type Annotations +public void test0098() throws IOException { + String source = + "class X {\n" + + " public boolean test() {\n" + + " String[] s;\n" + + " s = foo(new @Marker String @SingleMember(1) [10]);\n" + + " return s != null;\n" + + " }\n" + + " public <@Marker F> F @SingleMember(1) [] foo(F[] f) {\n" + + " return f;\n" + + " }\n" + + "}"; + String expectedUnitToString = + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public boolean test() {\n" + + " String[] s;\n" + + " s = foo(new @Marker String @SingleMember(1) [10]);\n" + + " return (s != null);\n" + + " }\n" + + " public <@Marker F>F @SingleMember(1) [] foo(F[] f) {\n" + + " return f;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0098", expectedUnitToString ); +} + +// To test Parser.consumeArrayCreationExpressionWithoutInitializer() with Type Annotations +public void test0099() throws IOException { + String source = + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "class X<@Marker T> {\n" + + " public void test() {\n" + + " List<@Marker X> a;\n" + + " a = Arrays.asList(new @Marker X @SingleMember(0) [0]);\n" + + " String @Marker [] @SingleMember(1) [] x;\n" + + " x = new @Readonly String @Normal(value = 5) [5] @SingleMember(1) [1];\n" + + " }\n" + + "}"; + String expectedUnitToString = + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "class X<@Marker T> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public void test() {\n" + + " List<@Marker X> a;\n" + + " a = Arrays.asList(new @Marker X @SingleMember(0) [0]);\n" + + " String @Marker [] @SingleMember(1) [] x;\n" + + " x = new @Readonly String @Normal(value = 5) [5] @SingleMember(1) [1];\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0099", expectedUnitToString ); +} + +// To test Parser.consumeArrayCreationExpressionWithoutInitializer() with Type Annotations +public void test0100() throws IOException { + String source = + "import java.util.*;\n" + + "class X {\n" + + " public Integer[] getTypes() {\n" + + " List<@Positive Integer> list;\n" + + " list = new ArrayList<@Positive Integer>();\n" + + " return list == null \n" + + " ? new @Positive Integer @SingleMember(0) [0] \n" + + " : list.toArray(new @Positive Integer @Marker [list.size()]);\n" + + " }\n" + + "}"; + String expectedUnitToString = + "import java.util.*;\n" + + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public Integer[] getTypes() {\n" + + " List<@Positive Integer> list;\n" + + " list = new ArrayList<@Positive Integer>();\n" + + " return ((list == null) ? new @Positive Integer @SingleMember(0) [0] : list.toArray(new @Positive Integer @Marker [list.size()]));\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0100", expectedUnitToString ); +} + +// To test Parser.consumeCastExpressionWithGenericsArray() with Type Annotations +public void test0101() throws IOException { + String source = + "import java.util.*;\n" + + "\n" + + "@Marker class X {\n" + + " Vector data;\n" + + " public void t() {\n" + + " Vector<@Readonly Object> v;\n" + + " v = (@Marker @SingleMember(0) Vector<@Readonly Object>) data.elementAt(0);\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "import java.util.*;\n" + + "@Marker class X {\n" + + " Vector data;\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public void t() {\n" + + " Vector<@Readonly Object> v;\n" + + " v = (@Marker @SingleMember(0) Vector<@Readonly Object>) data.elementAt(0);\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0101", expectedUnitToString ); +} + +// To test Parser.consumeCastExpressionWithGenericsArray() with Type Annotations +// To test Parser.consumeClassHeaderExtends() with Type Annotations +public void test0102() throws IOException { + String source = + "class X {\n" + + " X<@Readonly String> bar() {\n" + + " return (@Marker AX<@Readonly String>) new X<@Readonly String>();\n" + + " }\n" + + " X<@Readonly String> bar(Object o) {\n" + + " return (@Marker AX<@Readonly String>) o;\n" + + " }\n" + + " X<@Negative E> foo(Object o) {\n" + + " return (@Marker @Normal(value = 10) AX<@Negative E>) o;\n" + + " } \n" + + " X baz(Object o) {\n" + + " return (@Marker AX) null;\n" + + " }\n" + + " X baz2(BX bx) {\n" + + " return (@Marker @SingleMember(10) X) bx;\n" + + " }\n" + + "}\n" + + "@Normal(value = 1) class AX<@Marker F> extends @Marker X<@SingleMember(10)F> {}\n" + + "@Normal(value = 2) class BX extends @Marker @SingleMember(1) AX<@Readonly String> {}\n"; + String expectedUnitToString = + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " X<@Readonly String> bar() {\n" + + " return (@Marker AX<@Readonly String>) new X<@Readonly String>();\n" + + " }\n" + + " X<@Readonly String> bar(Object o) {\n" + + " return (@Marker AX<@Readonly String>) o;\n" + + " }\n" + + " X<@Negative E> foo(Object o) {\n" + + " return (@Marker @Normal(value = 10) AX<@Negative E>) o;\n" + + " }\n" + + " X baz(Object o) {\n" + + " return (@Marker AX) null;\n" + + " }\n" + + " X baz2(BX bx) {\n" + + " return (@Marker @SingleMember(10) X) bx;\n" + + " }\n" + + "}\n" + + "@Normal(value = 1) class AX<@Marker F> extends @Marker X<@SingleMember(10) F> {\n" + + " AX() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Normal(value = 2) class BX extends @Marker @SingleMember(1) AX<@Readonly String> {\n" + + " BX() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0102", expectedUnitToString ); +} + +// To test Parser.consumeCastExpressionWithGenericsArray() with Type Annotations +public void test0103() throws IOException { + String source = + "import java.lang.reflect.Array;\n" + + "@Marker class X<@Readonly T> {\n" + + " T @SingleMember(0) [] theArray;\n" + + " public X(Class clazz) {\n" + + " theArray = (@Marker @SingleMember(0) T @Normal(value = 10) []) Array.newInstance(clazz, 10); // Compiler warning\n" + + " }\n" + + "}"; + String expectedUnitToString = + "import java.lang.reflect.Array;\n" + + "@Marker class X<@Readonly T> {\n" + + " T @SingleMember(0) [] theArray;\n" + + " public X(Class clazz) {\n" + + " super();\n" + + " theArray = (@Marker @SingleMember(0) T @Normal(value = 10) []) Array.newInstance(clazz, 10);\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0103", expectedUnitToString ); +} + +// To test Parser.consumeCastExpressionWithGenericsArray() with Type Annotations +public void test0104() throws IOException { + String source = + "import java.util.*;\n" + + "class X {\n" + + " void method(Object o) {\n" + + " if (o instanceof String[]){\n" + + " String[] s;\n" + + " s = (@Marker @Readonly String @Marker []) o;\n" + + " }\n" + + " if (o instanceof @Readonly List[]) {\n" + + " List[] es;\n" + + " es = (@Marker List @SingleMember(0) []) o;\n" + + " }\n" + + " }\n" + + "}"; + String expectedUnitToString = + "import java.util.*;\n" + + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " void method(Object o) {\n" + + " if ((o instanceof String[]))\n" + + " {\n" + + " String[] s;\n" + + " s = (@Marker @Readonly String @Marker []) o;\n" + + " }\n" + + " if ((o instanceof @Readonly List[]))\n" + + " {\n" + + " List[] es;\n" + + " es = (@Marker List @SingleMember(0) []) o;\n" + + " }\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0104", expectedUnitToString ); +} + + +// To test Parser.consumeCastExpressionWithPrimitiveType() with Type Annotations +public void test0105() throws IOException { + String source = + "import java.util.HashMap;\n" + + "class X {\n" + + " public static void main(String[] args) {\n" + + " HashMap subst;\n" + + " subst = new HashMap();\n" + + " subst.put((@Marker byte)1, (@Positive byte)1);\n" + + " if (1 + subst.get((@Positive @Normal(value = 10) byte)1) > 0.f) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "import java.util.HashMap;\n" + + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " HashMap subst;\n" + + " subst = new HashMap();\n" + + " subst.put((@Marker byte) 1, (@Positive byte) 1);\n" + + " if (((1 + subst.get((@Positive @Normal(value = 10) byte) 1)) > 0.f))\n" + + " {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0105", expectedUnitToString ); +} + +// To test Parser.consumeCastExpressionWithPrimitiveType() with Type Annotations +public void test0106() throws IOException { + String source = + "class X{\n" + + " private float x, y, z;\n" + + " float magnitude () {\n" + + " return (@Marker @Positive float) Math.sqrt((x*x) + (y*y) + (z*z));\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class X {\n" + + " private float x;\n" + + " private float y;\n" + + " private float z;\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " float magnitude() {\n" + + " return (@Marker @Positive float) Math.sqrt((((x * x) + (y * y)) + (z * z)));\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0106", expectedUnitToString ); +} + +// To test Parser.consumeCastExpressionWithQualifiedGenericsArray() with Type Annotations +// Javac version b76 crashes on type annotations on type arguments to parameterized classes +// in a qualified generic reference +public void test0107() throws IOException { + String source = + "class C1 {\n" + + " class C11 { }\n" + + " @Marker class C12 {\n" + + " T t;\n" + + " C1<@Readonly T>.C11 m() {\n" + + " C1<@Readonly T>.C11[] ts;\n" + + " ts = (@Marker C1<@Readonly T>.C11[]) new @Marker C1.C11 @Normal(value = 5) [5];\n" + + " return ts;\n" + + " }\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class C1 {\n" + + " class C11 {\n" + + " C11() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " @Marker class C12 {\n" + + " T t;\n" + + " C12() {\n" + + " super();\n" + + " }\n" + + " C1<@Readonly T>.C11 m() {\n" + + " C1<@Readonly T>.C11[] ts;\n" + + " ts = (@Marker C1<@Readonly T>.C11[]) new @Marker C1.C11 @Normal(value = 5) [5];\n" + + " return ts;\n" + + " }\n" + + " }\n" + + " C1() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0107", expectedUnitToString ); +} + +// To test Parser.consumeFormalParameter() with Type Annotations +public void test0108() throws IOException { + String source = + "class X {\n" + + " int field;" + + " public void test(@Marker X x,@Positive int i){\n" + + " x.field = i;\n" + + " }\n" + + " public static void main(@Readonly String args @Normal(10) []){" + + " System.exit(0);\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class X {\n" + + " int field;\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public void test(@Marker X x, @Positive int i) {\n" + + " x.field = i;\n" + + " }\n" + + " public static void main(@Readonly String @Normal(10) [] args) {\n" + + " System.exit(0);\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0108", expectedUnitToString ); +} + +// To test Parser.consumeFormalParameter() with Type Annotations +public void test0109() throws IOException { + String source = + "class X<@Marker T> {\n" + + " T field;" + + " public void test(@Marker @SingleMember(1) X x,@Positive T i){\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class X<@Marker T> {\n" + + " T field;\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public void test(@Marker @SingleMember(1) X x, @Positive T i) {\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0109", expectedUnitToString ); +} + +// To test Parser.consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() +// with Type Annotations +// Javac b76 crashes with type annotations in qualified class instance creation expression +public void test0110() throws IOException { + String source = + "class X {\n" + + " class MX {\n" + + " @Marker MX(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new @Marker @SingleMember(10) X().new <@Readonly String> @Marker MX(\"SUCCESS\");\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class X {\n" + + " class MX {\n" + + " @Marker MX(T t) {\n" + + " super();\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new @Marker @SingleMember(10) X().new <@Readonly String>@Marker MX(\"SUCCESS\");\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0110", expectedUnitToString); +} + +// To test Parser.consumeClassInstanceCreationExpressionWithTypeArguments() +// with Type Annotations +public void test0111() throws IOException { + String source = + "class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new <@Readonly String> @Marker @SingleMember(0) X(\"SUCCESS\");\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class X {\n" + + " public X(T t) {\n" + + " super();\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new <@Readonly String>@Marker @SingleMember(0) X(\"SUCCESS\");\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0111", expectedUnitToString); +} + +// To test Parser.consumeEnhancedForStatementHeaderInit() with Type Annotations +public void test0112() throws IOException { + String source = + "import java.util.*;\n" + + "class X {\n" + + " List list() { return null; }\n" + + " void m2() { for (@SingleMember(10) Iterator<@Marker X> i = list().iterator(); i.hasNext();); }\n" + + " void m3() {\n" + + " Integer [] array;\n" + + " array = new Integer [] {1, 2, 3};\n" + + " List> xList;\n" + + " xList = null;\n" + + " for(@Positive @SingleMember(10) Integer i: array) {}\n" + + " for(@Marker @Normal(value = 5) List<@Readonly X> x: xList) {}\n" + + " }" + + "}\n"; + String expectedUnitToString = + "import java.util.*;\n" + + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " List list() {\n" + + " return null;\n" + + " }\n" + + " void m2() {\n" + + " for (@SingleMember(10) Iterator<@Marker X> i = list().iterator();; i.hasNext(); ) \n" + + " ;\n" + + " }\n" + + " void m3() {\n" + + " Integer[] array;\n" + + " array = new Integer[]{1, 2, 3};\n" + + " List> xList;\n" + + " xList = null;\n" + + " for (@Positive @SingleMember(10) Integer i : array) \n" + + " {\n" + + " }\n" + + " for (@Marker @Normal(value = 5) List<@Readonly X> x : xList) \n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_COMPLETION_PARSER & ~CHECK_SELECTION_PARSER & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0112", expectedUnitToString ); + expectedUnitToString = + "import java.util.*;\n" + + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " List list() {\n" + + " return null;\n" + + " }\n" + + " void m2() {\n" + + " for (@SingleMember(10) Iterator<@Marker X> i;; i.hasNext(); ) \n" + + " ;\n" + + " }\n" + + " void m3() {\n" + + " Integer[] array;\n" + + " array = new Integer[]{1, 2, 3};\n" + + " List> xList;\n" + + " xList = null;\n" + + " for (@Positive @SingleMember(10) Integer i : array) \n" + + " {\n" + + " }\n" + + " for (@Marker @Normal(value = 5) List<@Readonly X> x : xList) \n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + checkParse(CHECK_COMPLETION_PARSER & CHECK_SELECTION_PARSER, source.toCharArray(), null, "test0112", expectedUnitToString ); +} + +// To test Parser.consumeEnterAnonymousClassBody() with Type Annotations +public void test0113() throws IOException { + String source = + "@Marker class X {\n" + + " void f(@Normal(value = 5) X this) {\n" + + " new @Marker @SingleMember(10) Object() {\n" + + " void foo(){\n" + + " System.out.println(\"test\");\n" + + " }\n" + + " }.foo();\n" + + " }\n" + + "}"; + String expectedUnitToString = + "@Marker class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " void f(@Normal(value = 5) X this) {\n" + + " new @Marker @SingleMember(10) Object() {\n" + + " void foo() {\n" + + " System.out.println(\"test\");\n" + + " }\n" + + "}.foo();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_DOCUMENT_ELEMENT_PARSER, source.toCharArray(), null, "test0113", expectedUnitToString ); +} + +// To test Parser.consumeEnterAnonymousClassBody() with Type Annotations +public void test0114() throws IOException { + String source = + "class Toplevel2{\n" + + " public boolean foo(){\n" + + " Toplevel2 o;\n" + + " o = new @Marker @Normal(value = 5) Toplevel2() { \n" + + " public boolean foo() { return false; } // no copy in fact\n" + + " };\n" + + " return o.foo();\n" + + " }\n" + + "}"; + String expectedUnitToString = + "class Toplevel2 {\n" + + " Toplevel2() {\n" + + " super();\n" + + " }\n" + + " public boolean foo() {\n" + + " Toplevel2 o;\n" + + " o = new @Marker @Normal(value = 5) Toplevel2() {\n" + + " public boolean foo() {\n" + + " return false;\n" + + " }\n" + + "};\n" + + " return o.foo();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_DOCUMENT_ELEMENT_PARSER, source.toCharArray(), null, "test0114", expectedUnitToString ); +} + +// To test Parser.consumeEnterAnonymousClassBody() with Type Annotations +public void test0115() throws IOException { + String source = + "class X {\n" + + " T foo(T t) {\n" + + " System.out.println(t);\n" + + " return t;\n" + + " }\n" + + " public static void main(String @Normal(value = 5) [] args) {\n" + + " new @Marker X<@SingleMember(10) @Normal(value = 5) XY>() {\n" + + " void run() {\n" + + " foo(new @Marker XY());\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" + + "@Marker class XY {\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " T foo(T t) {\n" + + " System.out.println(t);\n" + + " return t;\n" + + " }\n" + + " public static void main(String @Normal(value = 5) [] args) {\n" + + " new @Marker X<@SingleMember(10) @Normal(value = 5) XY>() {\n" + + " void run() {\n" + + " foo(new @Marker XY());\n" + + " }\n" + + "}.run();\n" + + " }\n" + + "}\n" + + "@Marker class XY {\n" + + " XY() {\n" + + " super();\n" + + " }\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_DOCUMENT_ELEMENT_PARSER, source.toCharArray(), null, "test0115", expectedUnitToString ); +} + +// To test Parser.consumeInsideCastExpressionLL1() with Type Annotations +public void test0116() throws IOException { + String source = + "class X{\n" + + " public void test1(){\n" + + " throw (@Marker Error) null; \n" + + " } \n" + + " public void test2(){\n" + + " String s;\n" + + " s = (@Marker @SingleMember(10) String) null;\n" + + " byte b;\n" + + " b = 0;\n" + + " Byte i;\n" + + " i = (@Positive Byte) b;\n" + + " } \n" + + " public void test3(java.io.Serializable name) {\n" + + " Object temp;\n" + + " temp = (Object)name;\n" + + " System.out.println( (String)temp );\n" + + " }\n" + + "}"; + String expectedUnitToString = + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public void test1() {\n" + + " throw (@Marker Error) null;\n" + + " }\n" + + " public void test2() {\n" + + " String s;\n" + + " s = (@Marker @SingleMember(10) String) null;\n" + + " byte b;\n" + + " b = 0;\n" + + " Byte i;\n" + + " i = (@Positive Byte) b;\n" + + " }\n" + + " public void test3(java.io.Serializable name) {\n" + + " Object temp;\n" + + " temp = (Object) name;\n" + + " System.out.println((String) temp);\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0116", expectedUnitToString ); +} + +// To test Parser.consumeInstanceOfExpression() with Type Annotations +public void test0117() throws IOException { + String source = + "import java.util.*;\n" + + "class X <@NonNull T>{\n" + + " public void test1(Object obj) {\n" + + " if(obj instanceof @Marker @NonNull X) {\n" + + " X newX;\n" + + " newX = (@NonNull X) obj;\n" + + " }\n" + + " }\n" + + " @NonNull T foo(@NonNull T t) {\n" + + " if (t instanceof @NonNull @Marker List @Normal(value = 10) []) {\n" + + " List @SingleMember (10) [] es;\n" + + " es = (@Marker List @SingleMember(10) []) t;\n" + + " }\n" + + " if (t instanceof @Marker @Normal(value = 5) X) {\n" + + " return t;\n" + + " }\n" + + " return t;\n" + + " }\n" + + "}"; + String expectedUnitToString = + "import java.util.*;\n" + + "class X<@NonNull T> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public void test1(Object obj) {\n" + + " if ((obj instanceof @Marker @NonNull X))\n" + + " {\n" + + " X newX;\n" + + " newX = (@NonNull X) obj;\n" + + " }\n" + + " }\n" + + " @NonNull T foo(@NonNull T t) {\n" + + " if ((t instanceof @NonNull @Marker List @Normal(value = 10) []))\n" + + " {\n" + + " List @SingleMember(10) [] es;\n" + + " es = (@Marker List @SingleMember(10) []) t;\n" + + " }\n" + + " if ((t instanceof @Marker @Normal(value = 5) X))\n" + + " {\n" + + " return t;\n" + + " }\n" + + " return t;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER , source.toCharArray(), null, "test0117", expectedUnitToString ); +} + +// To test Parser.consumeInstanceOfExpressionWithName() with Type Annotations +public void test0118() throws IOException { + String source = + "class Outer {\n" + + " Inner inner;\n" + + " class Inner {\n" + + " E e;\n" + + " @NonNull E getOtherElement(Object other) {\n" + + " if (!(other instanceof @Marker @SingleMember(10) Outer.Inner))\n" + + " throw new @Marker IllegalArgumentException(String.valueOf(other));\n" + + " Inner that;\n" + + " that = (@Marker Inner) other;\n" + + " return that.e;\n" + + " }\n" + + " }\n" + + "}"; + String expectedUnitToString = + "class Outer {\n" + + " class Inner {\n" + + " E e;\n" + + " Inner() {\n" + + " super();\n" + + " }\n" + + " @NonNull E getOtherElement(Object other) {\n" + + " if ((! (other instanceof @Marker @SingleMember(10) Outer.Inner)))\n" + + " throw new @Marker IllegalArgumentException(String.valueOf(other));\n" + + " Inner that;\n" + + " that = (@Marker Inner) other;\n" + + " return that.e;\n" + + " }\n" + + " }\n" + + " Inner inner;\n" + + " Outer() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER , source.toCharArray(), null, "test0118", expectedUnitToString ); +} + +// To test Parser.consumeTypeArgument() with Type Annotations +public void test0119() throws IOException { + String source = + "class X<@SingleMember(1) Xp1 extends @Readonly String, @NonNull Xp2 extends @NonNull Comparable> extends @Marker XS<@SingleMember(10) Xp2> {\n" + + "\n" + + " public static void main(String @Marker [] args) {\n" + + " Integer w;\n" + + " w = new @Marker X<@Readonly @SingleMember(10) String,@Positive Integer>().get(new @Positive Integer(12));\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " Xp2 get(@Marker X this, Xp2 t) {\n" + + " System.out.print(\"{X::get}\");\n" + + " return super.get(t);\n" + + " }\n" + + "}\n" + + "@Marker class XS <@NonNull XSp1> {\n" + + " XSp1 get(XSp1 t) {\n" + + " @NonNull @SingleMember(10) Y.M mObject;\n" + + " mObject = new @SingleMember(10) @NonNull Y.M();\n" + + " System.out.print(\"{XS::get}\");\n" + + " return t;\n" + + " }\n" + + "}\n" + + "class X2{}\n" + + "@Marker class Y extends @Marker X2<@NonNull Y.M, @NonNull @SingleMember(1) Y.N> {\n" + + " static class M{}\n" + + " static class N extends M{}\n" + + "}\n"; + String expectedUnitToString = + "class X<@SingleMember(1) Xp1 extends @Readonly String, @NonNull Xp2 extends @NonNull Comparable> extends @Marker XS<@SingleMember(10) Xp2> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String @Marker [] args) {\n" + + " Integer w;\n" + + " w = new @Marker X<@Readonly @SingleMember(10) String, @Positive Integer>().get(new @Positive Integer(12));\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " Xp2 get(@Marker X this, Xp2 t) {\n" + + " System.out.print(\"{X::get}\");\n" + + " return super.get(t);\n" + + " }\n" + + "}\n" + + "@Marker class XS<@NonNull XSp1> {\n" + + " XS() {\n" + + " super();\n" + + " }\n" + + " XSp1 get(XSp1 t) {\n" + + " @NonNull @SingleMember(10) Y.M mObject;\n" + + " mObject = new @SingleMember(10) @NonNull Y.M();\n" + + " System.out.print(\"{XS::get}\");\n" + + " return t;\n" + + " }\n" + + "}\n" + + "class X2 {\n" + + " X2() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class Y extends @Marker X2<@NonNull Y.M, @NonNull @SingleMember(1) Y.N> {\n" + + " static class M {\n" + + " M() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " static class N extends M {\n" + + " N() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0119", expectedUnitToString ); +} + +// To test Parser.consumeTypeArgument() with Type Annotations +public void test0120() throws IOException { + String source = + "class X {\n" + + "}\n" + + "class Y {\n" + + " @Marker X x;\n" + + "}\n"; + String expectedUnitToString = + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " @Marker X x;\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0120", expectedUnitToString ); +} + +// To test Parser.consumeTypeArgumentReferenceType1() with Type Annotations +public void test0121() throws IOException { + String source = + "@Marker class X <@NonNull T> {\n" + + " protected T t;\n" + + " @Marker X(@NonNull T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<@Marker X<@Readonly @NonNull String>> xs;\n" + + " xs = new @Marker X<@Marker X<@Readonly @NonNull String>>(new @Marker X<@Readonly @NonNull @SingleMember(10) String>(\"SUCCESS\"));\n" + + " System.out.println(xs.t.t);\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "@Marker class X<@NonNull T> {\n" + + " protected T t;\n" + + " @Marker X(@NonNull T t) {\n" + + " super();\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<@Marker X<@Readonly @NonNull String>> xs;\n" + + " xs = new @Marker X<@Marker X<@Readonly @NonNull String>>(new @Marker X<@Readonly @NonNull @SingleMember(10) String>(\"SUCCESS\"));\n" + + " System.out.println(xs.t.t);\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_INDEXING_PARSER, source.toCharArray(), null, "test0121", expectedUnitToString ); +} + +// To test Parser.consumeTypeParameter1WithExtendsAndBounds() and Parser.consumeWildcardBoundsSuper() with +// Type Annotations +public void test0122() throws IOException { + String source = + "@Marker class Foo extends @Marker Foo1 implements @Marker @SingleMember(10) Comparable<@Marker Foo1> {\n" + + " public int compareTo(Foo1 arg0) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class Foo1 {}\n" + + "@Marker class X<@NonNull T extends @NonNull @Normal (value = 5) Object & @Marker Comparable> {\n" + + " public static void main(String[] args) {\n" + + " new @Marker @SingleMember(10) X<@Marker Foo>();\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "@Marker class Foo extends @Marker Foo1 implements @Marker @SingleMember(10) Comparable<@Marker Foo1> {\n" + + " Foo() {\n" + + " super();\n" + + " }\n" + + " public int compareTo(Foo1 arg0) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class Foo1 {\n" + + " Foo1() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class X<@NonNull T extends @NonNull @Normal(value = 5) Object & @Marker Comparable> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new @Marker @SingleMember(10) X<@Marker Foo>();\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0122", expectedUnitToString ); +} + +// To test Parser.consumeTypeParameter1WithExtendsAndBounds() with Type Annotations +public void test0123() throws IOException { + String source = + "@Marker class Foo extends @Marker Foo1 implements @Marker @SingleMember(10) Comparable {\n" + + " public int compareTo(Object arg0) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class Foo1 {}\n" + + "@Marker class X<@NonNull T extends @NonNull @Normal (value = 5) Object & @Marker Comparable, @NonNull V extends @Readonly Object> {\n" + + " public static void main(String[] args) {\n" + + " new @Marker @SingleMember(10) X<@Marker Foo, @SingleMember(0) Foo1>();\n" + + " Class <@NonNull Foo> c;\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "@Marker class Foo extends @Marker Foo1 implements @Marker @SingleMember(10) Comparable {\n" + + " Foo() {\n" + + " super();\n" + + " }\n" + + " public int compareTo(Object arg0) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class Foo1 {\n" + + " Foo1() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@Marker class X<@NonNull T extends @NonNull @Normal(value = 5) Object & @Marker Comparable, @NonNull V extends @Readonly Object> {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new @Marker @SingleMember(10) X<@Marker Foo, @SingleMember(0) Foo1>();\n" + + " Class<@NonNull Foo> c;\n" + + " }\n" + + "}\n"; + checkParse(source.toCharArray(), null, "test0123", expectedUnitToString ); +} +//To test type annotations on static class member access in a declaration +public void test0125() throws IOException { + String source = + "public class X extends @A(\"Hello, World!\") Y<@B @C('(') String[] @D[]> {}"; + String expectedUnitToString = + "public class X extends @A(\"Hello, World!\") Y<@B @C(\'(\') String[] @D []> {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0125", expectedUnitToString ); +} +//To test type annotations on static class member access in a declaration +public void test0126() throws IOException { + String source = + "public class X {\n" + + " @A(\"Hello, World!\") @B @C('(') String@E[] @D[] f;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A(\"Hello, World!\") @B @C(\'(\') String @E [] @D [] f;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0126", expectedUnitToString ); +} +//To test type annotations on static class member access in a declaration +public void test0127() throws IOException { + String source = + "public class X {\n" + + " @A(\"Hello, World!\") Y<@B @C('(') String[] @D[]> f;\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " @A(\"Hello, World!\") Y<@B @C(\'(\') String[] @D []> f;\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0127", expectedUnitToString ); +} +//type class literal expression +public void test0128() throws IOException { + String source = + "public class X {\n" + + " public boolean foo(String s) {\n" + + " return (s instanceof @C('_') Object[]);\n" + + " }\n" + + " public Object foo1(String s) {\n" + + " return new @B(3) @A(\"new Object\") Object[] {};\n" + + " }\n" + + " public Class foo2(String s) {\n" + + " return null;\n" + + " }\n" + + " public Class foo3(String s) {\n" + + " return null;\n" + + " }\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public boolean foo(String s) {\n" + + " return (s instanceof @C(\'_\') Object[]);\n" + + " }\n" + + " public Object foo1(String s) {\n" + + " return new @B(3) @A(\"new Object\") Object[]{};\n" + + " }\n" + + " public Class foo2(String s) {\n" + + " return null;\n" + + " }\n" + + " public Class foo3(String s) {\n" + + " return null;\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0128", expectedUnitToString ); +} +//instanceof checks +public void test0129() throws IOException { + String source = "public class Clazz {\n" + + "public static void main(Object o) {\n" + + "if (o instanceof @Readonly String) {\n" + + "}\n" + + "}\n" + + "}"; + String expectedUnitToString = + "public class Clazz {\n" + + " public Clazz() {\n" + + " super();\n" + + " }\n" + + " public static void main(Object o) {\n" + + " if ((o instanceof @Readonly String))\n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0129", expectedUnitToString); +} +//instanceof checks +public void test0130() throws IOException { + String source = "public class Clazz {\n" + + "public static void foo() {\n" + + " if (o instanceof @Readonly String[]) {}" + + "}\n" + + "}"; + String expectedUnitToString = + "public class Clazz {\n" + + " public Clazz() {\n" + + " super();\n" + + " }\n" + + " public static void foo() {\n" + + " if ((o instanceof @Readonly String[]))\n" + + " {\n" + + " }\n" + + " }\n" + + "}\n"; + checkParse(CHECK_ALL & ~CHECK_JAVAC_PARSER, source.toCharArray(), null, "test0130", expectedUnitToString); +} +//cast +public void test0131() throws IOException { + String source = + "public class X {\n" + + " public void foo(Object o) {\n" + + " if (o instanceof String[][]) {\n" + + " String[][] tab = (@C('_') @B(3) String[] @A[]) o;\n" + + " System.out.println(tab.length);\n" + + " }\n" + + " System.out.println(o);\n" + + " }\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo(Object o) {\n" + + " if ((o instanceof String[][]))\n" + + " {\n" + + " String[][] tab = (@C(\'_\') @B(3) String[] @A []) o;\n" + + " System.out.println(tab.length);\n" + + " }\n" + + " System.out.println(o);\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0130", expectedUnitToString); +} +//cast +public void test0132() throws IOException { + String source = + "public class X {\n" + + " public void foo(Object o) {\n" + + " if (o instanceof String[][]) {\n" + + " String[][] tab = (@C('_') @B(3) String@D[] @A[]) o;\n" + + " System.out.println(tab.length);\n" + + " }\n" + + " System.out.println(o);\n" + + " }\n" + + "}"; + String expectedUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo(Object o) {\n" + + " if ((o instanceof String[][]))\n" + + " {\n" + + " String[][] tab = (@C(\'_\') @B(3) String @D [] @A []) o;\n" + + " System.out.println(tab.length);\n" + + " }\n" + + " System.out.println(o);\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0130", expectedUnitToString); +} +//generic type arguments in a generic method invocation +public void test0133() throws IOException { + String source = + "public class X {\n" + + " static T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.<@D() @A(value = \"hello\") String, @B X>foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " static T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.<@D() @A(value = \"hello\") String, @B X>foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0130", expectedUnitToString); +} +//generic type arguments in a generic method invocation +public void test0134() throws IOException { + String source = + "public class X {\n" + + "\n" + + " T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " System.out.println(x.<@D() @A(value = \"hello\") String, @B X>foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " System.out.println(x.<@D() @A(value = \"hello\") String, @B X>foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0130", expectedUnitToString); +} +//generic type arguments in a generic constructor invocation +public void test0135() throws IOException { + String source = + "public class X {\n" + + " X(T t, U u) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new <@D() @A(value = \"hello\") String, @B X> X();\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class X {\n" + + " X(T t, U u) {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new <@D() @A(value = \"hello\") String, @B X>X();\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0130", expectedUnitToString); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383600 -- Receiver annotation - new syntax. +public void test0136() throws IOException { + String source = + "public class X {\n" + + " public class Y {\n" + + " void foo(@Marker X this) {\n" + + " }\n" + + " public class Z {\n" + + " Z(@D() @A(value = \"hello\") X.Y X.Y.this) {\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new Y().new Z();\n" + + " }\n" + + "}\n"; + String expectedUnitToString = + "public class X {\n" + + " public class Y {\n" + + " public class Z {\n" + + " Z(@D() @A(value = \"hello\") X.Y X.Y.this) {\n" + + " super();\n" + + " }\n" + + " }\n" + + " public Y() {\n" + + " super();\n" + + " }\n" + + " void foo(@Marker X this) {\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new Y().new Z();\n" + + " }\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0130", expectedUnitToString); +} +// Support type annotations for wildcard +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388085 +public void test0137() throws IOException { + String source = + "class X {\n" + + " public void main(Four<@Marker ? super String, @Marker ? extends Object> param) {\n" + + " One<@Marker ? extends Two<@Marker ? extends Three<@Marker ? extends Four<@Marker ? super String,@Marker ? extends Object>>>> one = null;\n" + + " Two<@Marker ? extends Three<@Marker ? extends Four<@Marker ? super String,@Marker ? extends Object>>> two = null;\n" + + " Three<@Marker ? extends Four<@Marker ? super String,@Marker ? extends Object>> three = null;\n" + + " Four<@Marker ? super String,@Marker ? extends Object> four = param;\n" + + " }\n" + + "}\n" + + "class One {}\n" + + "class Two {}\n" + + "class Three {}\n" + + "class Four {}\n" + + "@interface Marker {}"; + String expectedUnitToString = + "class X {\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public void main(Four<@Marker ? super String, @Marker ? extends Object> param) {\n" + + " One<@Marker ? extends Two<@Marker ? extends Three<@Marker ? extends Four<@Marker ? super String, @Marker ? extends Object>>>> one = null;\n" + + " Two<@Marker ? extends Three<@Marker ? extends Four<@Marker ? super String, @Marker ? extends Object>>> two = null;\n" + + " Three<@Marker ? extends Four<@Marker ? super String, @Marker ? extends Object>> three = null;\n" + + " Four<@Marker ? super String, @Marker ? extends Object> four = param;\n" + + " }\n" + + "}\n" + + "class One {\n" + + " One() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "class Two {\n" + + " Two() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "class Three {\n" + + " Three() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "class Four {\n" + + " Four() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "@interface Marker {\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0137", expectedUnitToString); +} +public void test0138() throws IOException { + String source = + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [bar()] @Marker @Marker2 [];\n" + + " int @Marker [][][] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [X.bar2(2)] @Marker @Marker2 [];\n" + + " }\n" + + " public int bar() {\n" + + " return 2;\n" + + " }\n" + + " public static int bar2(int k) {\n" + + " return k;\n" + + " }\n" + + "}\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker2 {}\n"; + String expectedUnitToString = + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [bar()] @Marker @Marker2 [];\n" + + " int @Marker [][][] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [X.bar2(2)] @Marker @Marker2 [];\n" + + " }\n" + + " public int bar() {\n" + + " return 2;\n" + + " }\n" + + " public static int bar2(int k) {\n" + + " return k;\n" + + " }\n" + + "}\n" + + "@Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {\n" + + "}\n" + + "@Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker2 {\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0137", expectedUnitToString); +} +// Support for annotations on ellipsis in lambda expression +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432574 +public void test0139() throws IOException { + String source = + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "public class X {\n" + + " FI fi = (String @T1[] @T1... x) -> {};\n" + + "}\n" + + "interface FI {\n" + + " void foo(String[]... x);\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T1 {\n" + + "}\n"; + String expectedUnitToString = + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "public class X {\n" + + " FI fi = (String @T1 [] @T1 ... x) -> {\n" + + " };\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + "}\n" + + "interface FI {\n" + + " void foo(String[]... x);\n" + + "}\n" + + "@Target(ElementType.TYPE_USE) @interface T1 {\n" + + "}\n"; + checkParse(CHECK_PARSER, source.toCharArray(), null, "test0139", expectedUnitToString); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ASTImplTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ASTImplTests.java new file mode 100644 index 0000000000..c9893032c6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ASTImplTests.java @@ -0,0 +1,1064 @@ +/******************************************************************************* + * Copyright (c) 2006, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.ASTVisitor; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; +import org.eclipse.jdt.internal.compiler.ast.Argument; +import org.eclipse.jdt.internal.compiler.ast.BinaryExpression; +import org.eclipse.jdt.internal.compiler.ast.CharLiteral; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.CombinedBinaryExpression; +import org.eclipse.jdt.internal.compiler.ast.ExtendedStringLiteral; +import org.eclipse.jdt.internal.compiler.ast.JavadocSingleTypeReference; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation; +import org.eclipse.jdt.internal.compiler.ast.MemberValuePair; +import org.eclipse.jdt.internal.compiler.ast.NormalAnnotation; +import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation; +import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.ast.StringLiteral; +import org.eclipse.jdt.internal.compiler.ast.StringLiteralConcatenation; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.BlockScope; +import org.eclipse.jdt.internal.compiler.lookup.ClassScope; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; + +/** + * A tests series especially meant to validate the internals of our AST + * implementation. + */ +@SuppressWarnings({ "rawtypes" }) +public class ASTImplTests extends AbstractRegressionTest { +public ASTImplTests(String name) { + super(name); +} + + // Static initializer to specify tests subset using TESTS_* static variables + // All specified tests which does not belong to the class are skipped... + // 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[] { "test2050" }; +// TESTS_NUMBERS = new int[] { 3 }; +// TESTS_NUMBERS = new int[] { 2999 }; +// TESTS_RANGE = new int[] { 2050, -1 }; + } + +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public static Class testClass() { + return ASTImplTests.class; +} + +// Helper methods +static Parser defaultParser = new Parser( + new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(), + new DefaultProblemFactory()), false); +public void runConformTest(String fileName, String fileContents, + Parser parser, ASTCollector visitor, String expected) { + CompilationUnit source = + new CompilationUnit(fileContents.toCharArray(), fileName, null); + CompilationResult compilationResult = + new CompilationResult(source, 1, 1, 10); + CompilationUnitDeclaration unit = parser.parse(source, compilationResult); + assertEquals(0, compilationResult.problemCount); + unit.traverse(visitor, unit.scope); + String result = visitor.result(); + if (! expected.equals(result)) { + System.out.println(getClass().getName() + '#' + getName()); + System.out.println("Expected:"); + System.out.println(expected); + System.out.println("But was:"); + System.out.println(result); + System.out.println("Cut and paste:"); + System.out.println(Util.displayString(result, INDENT, SHIFT)); + } + assertEquals(expected, result); +} + +// AST implementation - visiting binary expressions +public void test0001_regular_binary_expression() { + runConformTest( + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s1 = \"s1\";\n" + + " String s2 = \"s2\";\n" + + " String s3 = \"s3\";\n" + + " String s4 = \"s4\";\n" + + " System.out.println(s1 + \"l1\" + s2 + \"l2\" +\n" + + " s3 + \"l3\" + s4);\n" + + " }\n" + + "}\n", + defaultParser, + new ASTBinaryExpressionCollector(), + "[v SL \"s1\"]\n" + + "[ev SL \"s1\"]\n" + + "[v SL \"s2\"]\n" + + "[ev SL \"s2\"]\n" + + "[v SL \"s3\"]\n" + + "[ev SL \"s3\"]\n" + + "[v SL \"s4\"]\n" + + "[ev SL \"s4\"]\n" + + "[v BE ((((((s1 + \"l1\") + s...) + s4)]\n" + + "[v BE (((((s1 + \"l1\") + s2...+ \"l3\")]\n" + + "[v BE ((((s1 + \"l1\") + s2)...) + s3)]\n" + + "[v BE (((s1 + \"l1\") + s2) + \"l2\")]\n" + + "[v BE ((s1 + \"l1\") + s2)]\n" + + "[v BE (s1 + \"l1\")]\n" + + "[v SNR s1]\n" + + "[ev SNR s1]\n" + + "[v SL \"l1\"]\n" + + "[ev SL \"l1\"]\n" + + "[ev BE (s1 + \"l1\")]\n" + + "[v SNR s2]\n" + + "[ev SNR s2]\n" + + "[ev BE ((s1 + \"l1\") + s2)]\n" + + "[v SL \"l2\"]\n" + + "[ev SL \"l2\"]\n" + + "[ev BE (((s1 + \"l1\") + s2) + \"l2\")]\n" + + "[v SNR s3]\n" + + "[ev SNR s3]\n" + + "[ev BE ((((s1 + \"l1\") + s2)...) + s3)]\n" + + "[v SL \"l3\"]\n" + + "[ev SL \"l3\"]\n" + + "[ev BE (((((s1 + \"l1\") + s2...+ \"l3\")]\n" + + "[v SNR s4]\n" + + "[ev SNR s4]\n" + + "[ev BE ((((((s1 + \"l1\") + s...) + s4)]\n"); +} + +// AST implementation - visiting binary expressions +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Adding combined binary expressions +public void test0002_combined_binary_expression() { + CombinedBinaryExpression.defaultArityMaxStartingValue = 3; + // one CBE each fourth BE + runConformTest( + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s1 = \"s1\";\n" + + " String s2 = \"s2\";\n" + + " String s3 = \"s3\";\n" + + " String s4 = \"s4\";\n" + + " System.out.println(s1 + \"l1\" + s2 + \"l2\" +\n" + + " s3 + \"l3\" + s4);\n" + + " }\n" + + "}\n", + defaultParser, + new ASTBinaryExpressionCollector() { + @Override + public void endVisit(BinaryExpression binaryExpression, BlockScope scope) { + if (binaryExpression instanceof CombinedBinaryExpression && + ((CombinedBinaryExpression) binaryExpression). + referencesTable != null) { + this.collector.append("[ev CBE " + + cut(binaryExpression.toString()) + "]\n"); + } else { + super.endVisit(binaryExpression, scope); + } + } + }, + "[v SL \"s1\"]\n" + + "[ev SL \"s1\"]\n" + + "[v SL \"s2\"]\n" + + "[ev SL \"s2\"]\n" + + "[v SL \"s3\"]\n" + + "[ev SL \"s3\"]\n" + + "[v SL \"s4\"]\n" + + "[ev SL \"s4\"]\n" + + "[v BE ((((((s1 + \"l1\") + s...) + s4)]\n" + + "[v BE (((((s1 + \"l1\") + s2...+ \"l3\")]\n" + + "[v BE ((((s1 + \"l1\") + s2)...) + s3)]\n" + + "[v BE (((s1 + \"l1\") + s2) + \"l2\")]\n" + + "[v BE ((s1 + \"l1\") + s2)]\n" + + "[v BE (s1 + \"l1\")]\n" + + "[v SNR s1]\n" + + "[ev SNR s1]\n" + + "[v SL \"l1\"]\n" + + "[ev SL \"l1\"]\n" + + "[ev BE (s1 + \"l1\")]\n" + + "[v SNR s2]\n" + + "[ev SNR s2]\n" + + "[ev BE ((s1 + \"l1\") + s2)]\n" + + "[v SL \"l2\"]\n" + + "[ev SL \"l2\"]\n" + + "[ev BE (((s1 + \"l1\") + s2) + \"l2\")]\n" + + "[v SNR s3]\n" + + "[ev SNR s3]\n" + + "[ev CBE ((((s1 + \"l1\") + s2)...) + s3)]\n" + + "[v SL \"l3\"]\n" + + "[ev SL \"l3\"]\n" + + "[ev BE (((((s1 + \"l1\") + s2...+ \"l3\")]\n" + + "[v SNR s4]\n" + + "[ev SNR s4]\n" + + "[ev BE ((((((s1 + \"l1\") + s...) + s4)]\n"); + CombinedBinaryExpression.defaultArityMaxStartingValue = + CombinedBinaryExpression.ARITY_MAX_MIN; +} + +// AST implementation - visiting binary expressions +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Adding combined binary expressions +public void test0003_combined_binary_expression() { + Parser parser = new Parser( + new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(), + new DefaultProblemFactory()), true); // optimize string literals + CombinedBinaryExpression.defaultArityMaxStartingValue = 2; + // one CBE each third BE - except the top one, which is degenerate (no + // references table) + runConformTest( + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s1 = \"s1\";\n" + + " String s2 = \"s2\";\n" + + " String s3 = \"s3\";\n" + + " String s4 = \"s4\";\n" + + " System.out.println(s1 + \"l1\" + s2 + \"l2\" +\n" + + " s3 + \"l3\" + s4);\n" + + " }\n" + + "}\n", + parser, + new ASTBinaryExpressionCollector() { + @Override + public void endVisit(BinaryExpression binaryExpression, BlockScope scope) { + if (binaryExpression instanceof CombinedBinaryExpression && + ((CombinedBinaryExpression) binaryExpression). + referencesTable != null) { + this.collector.append("[ev CBE " + + cut(binaryExpression.toString()) + "]\n"); + } else { + super.endVisit(binaryExpression, scope); + } + } + }, + "[v SL \"s1\"]\n" + + "[ev SL \"s1\"]\n" + + "[v SL \"s2\"]\n" + + "[ev SL \"s2\"]\n" + + "[v SL \"s3\"]\n" + + "[ev SL \"s3\"]\n" + + "[v SL \"s4\"]\n" + + "[ev SL \"s4\"]\n" + + "[v BE ((((((s1 + \"l1\") + s...) + s4)]\n" + + "[v BE (((((s1 + \"l1\") + s2...+ \"l3\")]\n" + + "[v BE ((((s1 + \"l1\") + s2)...) + s3)]\n" + + "[v BE (((s1 + \"l1\") + s2) + \"l2\")]\n" + + "[v BE ((s1 + \"l1\") + s2)]\n" + + "[v BE (s1 + \"l1\")]\n" + + "[v SNR s1]\n" + + "[ev SNR s1]\n" + + "[v SL \"l1\"]\n" + + "[ev SL \"l1\"]\n" + + "[ev BE (s1 + \"l1\")]\n" + + "[v SNR s2]\n" + + "[ev SNR s2]\n" + + "[ev BE ((s1 + \"l1\") + s2)]\n" + + "[v SL \"l2\"]\n" + + "[ev SL \"l2\"]\n" + + "[ev CBE (((s1 + \"l1\") + s2) + \"l2\")]\n" + + "[v SNR s3]\n" + + "[ev SNR s3]\n" + + "[ev BE ((((s1 + \"l1\") + s2)...) + s3)]\n" + + "[v SL \"l3\"]\n" + + "[ev SL \"l3\"]\n" + + "[ev BE (((((s1 + \"l1\") + s2...+ \"l3\")]\n" + + "[v SNR s4]\n" + + "[ev SNR s4]\n" + + "[ev BE ((((((s1 + \"l1\") + s...) + s4)]\n"); + CombinedBinaryExpression.defaultArityMaxStartingValue = + CombinedBinaryExpression.ARITY_MAX_MIN; +} + +// AST implementation - visiting binary expressions +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Adding combined binary expressions - effect of a literal at the start with +// string literal optimization +public void test0004_combined_binary_expression() { + Parser parser = new Parser( + new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(), + new DefaultProblemFactory()), true); // optimize string literals + runConformTest( + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s1 = \"s1\";\n" + + " System.out.println(\"l\" + \"1\" + s1);\n" + + // "l" + "1" is collapsed into "l1" without affecting binary + // expressions: only one BE + " }\n" + + "}\n", + parser, + new ASTBinaryExpressionCollector(), + "[v SL \"s1\"]\n" + + "[ev SL \"s1\"]\n" + + "[v BE (ExtendedStringLiter...} + s1)]\n" + + "[v ESL ExtendedStringLiteral{l1}]\n" + + "[ev ESL ExtendedStringLiteral{l1}]\n" + + "[v SNR s1]\n" + + "[ev SNR s1]\n" + + "[ev BE (ExtendedStringLiter...} + s1)]\n"); +} + +// AST implementation - visiting binary expressions +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Adding combined binary expressions - effect of a literal at the start without +// string literals optimization +public void test0005_combined_binary_expression() { + runConformTest( + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s1 = \"s1\";\n" + + " System.out.println(\"l\" + \"1\" + s1);\n" + + // "l" + "1" is handled by a string literal concatenation without + // affecting binary expressions: only one BE + " }\n" + + "}\n", + defaultParser, + new ASTBinaryExpressionCollector(), + "[v SL \"s1\"]\n" + + "[ev SL \"s1\"]\n" + + "[v BE (StringLiteralConcat...} + s1)]\n" + + "[v SLC StringLiteralConcate...\n" + + "\"1\"+\n" + + "}]\n" + + "[v SL \"l\"]\n" + + "[ev SL \"l\"]\n" + + "[v SL \"1\"]\n" + + "[ev SL \"1\"]\n" + + "[ev SLC StringLiteralConcate...\n" + + "\"1\"+\n" + + "}]\n" + + "[v SNR s1]\n" + + "[ev SNR s1]\n" + + "[ev BE (StringLiteralConcat...} + s1)]\n"); +} + +// AST implementation - visiting binary expressions +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Adding combined binary expressions - cutting the traversal half-way down +public void test0006_combined_binary_expression() { + CombinedBinaryExpression.defaultArityMaxStartingValue = 1; + runConformTest( + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s1 = \"s1\";\n" + + " String s2 = \"s2\";\n" + + " String s3 = \"s3\";\n" + + " String s4 = \"s4\";\n" + + " System.out.println(s1 + \"l1\" + s2 + \"l2\" +\n" + + " s3 + s1 + s4);\n" + + " }\n" + + "}\n", + defaultParser, + new ASTBinaryExpressionCollector() { + @Override + public boolean visit(BinaryExpression binaryExpression, BlockScope scope) { + super.visit(binaryExpression, scope); + if (binaryExpression.right instanceof StringLiteral) { + return false; + } + return true; + } + }, + "[v SL \"s1\"]\n" + + "[ev SL \"s1\"]\n" + + "[v SL \"s2\"]\n" + + "[ev SL \"s2\"]\n" + + "[v SL \"s3\"]\n" + + "[ev SL \"s3\"]\n" + + "[v SL \"s4\"]\n" + + "[ev SL \"s4\"]\n" + + "[v BE ((((((s1 + \"l1\") + s...) + s4)]\n" + + "[v BE (((((s1 + \"l1\") + s2...) + s1)]\n" + + "[v BE ((((s1 + \"l1\") + s2)...) + s3)]\n" + + "[v BE (((s1 + \"l1\") + s2) + \"l2\")]\n" + + "[ev BE (((s1 + \"l1\") + s2) + \"l2\")]\n" + + "[v SNR s3]\n" + + "[ev SNR s3]\n" + + "[ev BE ((((s1 + \"l1\") + s2)...) + s3)]\n" + + "[v SNR s1]\n" + + "[ev SNR s1]\n" + + "[ev BE (((((s1 + \"l1\") + s2...) + s1)]\n" + + "[v SNR s4]\n" + + "[ev SNR s4]\n" + + "[ev BE ((((((s1 + \"l1\") + s...) + s4)]\n"); + CombinedBinaryExpression.defaultArityMaxStartingValue = + CombinedBinaryExpression.ARITY_MAX_MIN; +} + +// AST implementation - visiting binary expressions +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Adding combined binary expressions - cutting the traversal right away +public void test0007_combined_binary_expression() { + CombinedBinaryExpression.defaultArityMaxStartingValue = 4; + runConformTest( + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s1 = \"s1\";\n" + + " String s2 = \"s2\";\n" + + " String s3 = \"s3\";\n" + + " String s4 = \"s4\";\n" + + " System.out.println(s1 + \"l1\" + s2 + \"l2\" +\n" + + " s3 + \"l3\" + s4);\n" + + " }\n" + + "}\n", + defaultParser, + new ASTBinaryExpressionCollector() { + @Override + public boolean visit(BinaryExpression binaryExpression, BlockScope scope) { + super.visit(binaryExpression, scope); + return false; + } + }, + "[v SL \"s1\"]\n" + + "[ev SL \"s1\"]\n" + + "[v SL \"s2\"]\n" + + "[ev SL \"s2\"]\n" + + "[v SL \"s3\"]\n" + + "[ev SL \"s3\"]\n" + + "[v SL \"s4\"]\n" + + "[ev SL \"s4\"]\n" + + "[v BE ((((((s1 + \"l1\") + s...) + s4)]\n" + + "[ev BE ((((((s1 + \"l1\") + s...) + s4)]\n"); + CombinedBinaryExpression.defaultArityMaxStartingValue = + CombinedBinaryExpression.ARITY_MAX_MIN; +} + +// AST implementation - visiting binary expressions +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Adding combined binary expressions - case of one-deep expression +public void test0008_combined_binary_expression() { + runConformTest( + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s1 = \"s1\";\n" + + " String s2 = \"s2\";\n" + + " System.out.println(s1 + \"l1\" + s2 + \"l2\");\n" + + " System.out.println(s1 + s2);\n" + + " }\n" + + "}\n", + defaultParser, + new ASTBinaryExpressionCollector() { + @Override + public void endVisit(BinaryExpression binaryExpression, BlockScope scope) { + if (binaryExpression instanceof CombinedBinaryExpression) { + this.collector.append("[ev CBE " + + cut(binaryExpression.toString()) + "]\n"); + } else { + super.endVisit(binaryExpression, scope); + } + } + }, + "[v SL \"s1\"]\n" + + "[ev SL \"s1\"]\n" + + "[v SL \"s2\"]\n" + + "[ev SL \"s2\"]\n" + + "[v BE (((s1 + \"l1\") + s2) + \"l2\")]\n" + + "[v BE ((s1 + \"l1\") + s2)]\n" + + "[v BE (s1 + \"l1\")]\n" + + "[v SNR s1]\n" + + "[ev SNR s1]\n" + + "[v SL \"l1\"]\n" + + "[ev SL \"l1\"]\n" + + "[ev BE (s1 + \"l1\")]\n" + + "[v SNR s2]\n" + + "[ev SNR s2]\n" + + "[ev BE ((s1 + \"l1\") + s2)]\n" + + "[v SL \"l2\"]\n" + + "[ev SL \"l2\"]\n" + + "[ev CBE (((s1 + \"l1\") + s2) + \"l2\")]\n" + + "[v BE (s1 + s2)]\n" + + "[v SNR s1]\n" + + "[ev SNR s1]\n" + + "[v SNR s2]\n" + + "[ev SNR s2]\n" + + "[ev BE (s1 + s2)]\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// check if the generated code is OK when leveraging CombinedBinaryExpression +public void test0009_combined_binary_expression() { + assertEquals(20, CombinedBinaryExpression.ARITY_MAX_MIN); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void main(String args[]) {\n" + + " final int max = 30; \n" + + " String s[] = new String[max];\n" + + " for (int i = 0; i < max; i++) {\n" + + " s[i] = \"a\";\n" + + " }\n" + + " foo(s);\n" + + "}\n" + + "static void foo (String s[]) {\n" + + " System.out.println(\n" + + " s[0] + s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + \n" + + " s[7] + s[8] + s[9] + s[10] + s[11] + s[12] + s[13] +\n" + + " s[14] + s[15] + s[16] + s[17] + s[18] + s[19] + \n" + + " s[20] + s[21] + s[22] + s[23] + s[24] + s[25] + \n" + + " s[26] + s[27] + s[28] + s[29]\n" + + " );\n" + + "}\n" + + "}"}, + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// check if the generated code is OK when leveraging CombinedBinaryExpression +// variant involving constant binary expressions deep in the tree +public void test0010_combined_binary_expression() { + assertEquals(20, CombinedBinaryExpression.ARITY_MAX_MIN); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void main(String args[]) {\n" + + " final int max = 30; \n" + + " String s[] = new String[max];\n" + + " for (int i = 0; i < max; i++) {\n" + + " s[i] = \"a\";\n" + + " }\n" + + " foo(s);\n" + + "}\n" + + "static void foo (String s[]) {\n" + + " final String c = \"a\";" + + " System.out.println(\n" + + " c + c + c + c + s[4] + s[5] + s[6] + s[7] + s[8] + \n" + + " s[9] + s[10] + s[11] + s[12] + s[13] + s[14] + \n" + + " s[15] + s[16] + s[17] + s[18] + s[19] + s[20] + \n" + + " s[21] + s[22] + s[23] + s[24] + s[25] + s[26] + \n" + + " s[27] + s[28] + s[29]\n" + + " );\n" + + "}\n" + + "}" + }, + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// check if the generated code is OK when leveraging CombinedBinaryExpression +// variant involving a constant combined binary expression +public void test0011_combined_binary_expression() { + assertEquals(20, CombinedBinaryExpression.ARITY_MAX_MIN); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void main(String args[]) {\n" + + " final int max = 30; \n" + + " String s[] = new String[max];\n" + + " for (int i = 0; i < max; i++) {\n" + + " s[i] = \"a\";\n" + + " }\n" + + " foo(s);\n" + + "}\n" + + "static void foo (String s[]) {\n" + + " final String c = \"a\";" + + " System.out.println(\n" + + " c + c + c + c + c + c + c + c + c + c + \n" + + " c + c + c + c + c + c + c + c + c + c + \n" + + " c + c + s[22] + s[23] + s[24] + s[25] + s[26] + \n" + + " s[27] + s[28] + s[29]\n" + + " );\n" + + "}\n" + + "}" + }, + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); +} + +// AST implementation - visiting binary expressions +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Adding combined binary expressions - checking recursive print +public void test0012_combined_binary_expression() { + CombinedBinaryExpression.defaultArityMaxStartingValue = 2; + runConformTest( + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s1 = \"s1\";\n" + + " String s2 = \"s2\";\n" + + " String s3 = \"s3\";\n" + + " String s4 = \"s4\";\n" + + " System.out.println(s1 + \"l1\" + s2 + \"l2\" +\n" + + " s3 + s1 + s4);\n" + + " }\n" + + "}\n", + defaultParser, + new ASTCollector() { + public boolean visit(BinaryExpression binaryExpression, + BlockScope scope) { + super.visit(binaryExpression, scope); + this.collector.append(binaryExpression); + return true; + } + }, + "((((((s1 + \"l1\") + s2) + \"l2\") + s3) + s1) + s4)(((((s1 + \"l1\")" + + " + s2) + \"l2\") + s3) + s1)((((s1 + \"l1\") + s2) + \"l2\") + s3)" + + "(((s1 + \"l1\") + s2) + \"l2\")((s1 + \"l1\") + s2)(s1 + \"l1\")"); + CombinedBinaryExpression.defaultArityMaxStartingValue = + CombinedBinaryExpression.ARITY_MAX_MIN; +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// check if the generated code is OK when leveraging CombinedBinaryExpression +// variant involving a left-deep right expression at the topmost level +public void test0013_combined_binary_expression() { + assertEquals(20, CombinedBinaryExpression.ARITY_MAX_MIN); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void main(String args[]) {\n" + + " final int max = 30; \n" + + " String s[] = new String[max];\n" + + " for (int i = 0; i < max; i++) {\n" + + " s[i] = \"a\";\n" + + " }\n" + + " foo(s);\n" + + "}\n" + + "static void foo (String s[]) {\n" + + " System.out.println(\n" + + " \"b\" + (s[0] + s[1] + s[2] + s[3] + s[4] + s[5] + s[6] + \n" + + " s[7] + s[8] + s[9] + s[10] + s[11] + s[12] + s[13] +\n" + + " s[14] + s[15] + s[16] + s[17] + s[18] + s[19] + \n" + + " s[20] + s[21] + s[22] + s[23] + s[24] + s[25] + \n" + + " s[26] + s[27] + s[28] + s[29])\n" + + " );\n" + + "}\n" + + "}" + }, + "baaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// check if the generated code is OK when leveraging CombinedBinaryExpression +// variant involving a left-deep right expression at the topmost level, with +// a constant high in tree +public void test0014_combined_binary_expression() { + assertEquals(20, CombinedBinaryExpression.ARITY_MAX_MIN); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void main(String args[]) {\n" + + " final int max = 30; \n" + + " String s[] = new String[max];\n" + + " for (int i = 0; i < max; i++) {\n" + + " s[i] = \"a\";\n" + + " }\n" + + " foo(s);\n" + + "}\n" + + "static void foo (String s[]) {\n" + + " final String c = \"c\";\n" + + " System.out.println(\n" + + " \"b\" + \n" + + " (c + c + c + c + c + c + c + c + c + c + \n" + + " c + c + c + c + c + c + c + c + c + c + \n" + + " c + c + s[0])\n" + + " );\n" + + "}\n" + + "}" + }, + "bcccccccccccccccccccccca"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// check if the generated code is OK when leveraging CombinedBinaryExpression +// variant involving a left-deep right expression at the topmost level, with +// a constant low in tree +public void test0015_combined_binary_expression() { + assertEquals(20, CombinedBinaryExpression.ARITY_MAX_MIN); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void main(String args[]) {\n" + + " final int max = 30; \n" + + " String s[] = new String[max];\n" + + " for (int i = 0; i < max; i++) {\n" + + " s[i] = \"a\";\n" + + " }\n" + + " foo(s);\n" + + "}\n" + + "static void foo (String s[]) {\n" + + " final String c = \"c\";\n" + + " System.out.println(\n" + + " \"b\" + \n" + + " (c + c + c + c + c + c + c + c + c + c + \n" + + " c + c + c + c + c + c + c + c + c + c + \n" + + " s[0] + s[1] + s[2])\n" + + " );\n" + + "}\n" + + "}" + }, + "bccccccccccccccccccccaaa"); +} + +// AST implementation - binary expressions +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Adding combined binary expressions - alternate operands +public void test0016_combined_binary_expression() { + CombinedBinaryExpression.defaultArityMaxStartingValue = 2; + this.runConformTest( + "X.java", + "public class X {\n" + + "void foo(int i1, int i2, int i3, int i4) {\n" + + " System.out.println(i1 - i2 + 0 + i3 + 0 + i4);\n" + + "}\n" + + "}\n", + defaultParser, + new ASTCollector() { + public boolean visit(BinaryExpression binaryExpression, + BlockScope scope) { + super.visit(binaryExpression, scope); + this.collector.append(binaryExpression); + return true; + } + }, + "(((((i1 - i2) + 0) + i3) + 0) + i4)((((i1 - i2) + 0) + i3) + 0)" + + "(((i1 - i2) + 0) + i3)((i1 - i2) + 0)(i1 - i2)"); + CombinedBinaryExpression.defaultArityMaxStartingValue = + CombinedBinaryExpression.ARITY_MAX_MIN; +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=157170 +public void test0017() { + CompilerOptions options = new CompilerOptions(); + options.complianceLevel = ClassFileConstants.JDK1_5; + options.sourceLevel = ClassFileConstants.JDK1_5; + options.targetJDK = ClassFileConstants.JDK1_5; + this.runConformTest( + "X.java", + "@interface Annot {\n" + + " int value() default 0;\n" + + "}\n" + + "@Annot\n" + + "@Annot(3)\n" + + "@Annot(value=4)\n" + + "public class X {\n" + + "}\n", + new Parser( + new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory()), false), + new AnnotationCollector(), + "marker annotation start visit\n" + + "marker annotation end visit\n" + + "single member annotation start visit\n" + + "3\n" + + "single member annotation end visit\n" + + "normal annotation start visit\n" + + "member value pair start visit\n" + + "value, 4\n" + + "member value pair end visit\n" + + "normal annotation end visit\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=157170 +public void test0018() { + CompilerOptions options = new CompilerOptions(); + options.complianceLevel = ClassFileConstants.JDK1_5; + options.sourceLevel = ClassFileConstants.JDK1_5; + options.targetJDK = ClassFileConstants.JDK1_5; + options.docCommentSupport = true; + this.runConformTest( + "X.java", + "@interface Annot {\n" + + " int value() default 0;\n" + + "}\n" + + "/**\n" + + " * @see Annot\n" + + " */\n" + + "@Annot\n" + + "@Annot(3)\n" + + "@Annot(value=4)\n" + + "public class X {\n" + + " /**\n" + + " * @see Annot\n" + + " */\n" + + " public void foo() {}\n" + + "}\n", + new Parser( + new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory()), false), + new AnnotationCollector(), + "java doc single type reference start visit\n" + + "java doc single type reference end visit\n" + + "marker annotation start visit\n" + + "marker annotation end visit\n" + + "single member annotation start visit\n" + + "3\n" + + "single member annotation end visit\n" + + "normal annotation start visit\n" + + "member value pair start visit\n" + + "value, 4\n" + + "member value pair end visit\n" + + "normal annotation end visit\n" + + "java doc single type reference start visit\n" + + "java doc single type reference end visit\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=157170 +public void test0019() { + CompilerOptions options = new CompilerOptions(); + options.complianceLevel = ClassFileConstants.JDK1_5; + options.sourceLevel = ClassFileConstants.JDK1_5; + options.targetJDK = ClassFileConstants.JDK1_5; + options.docCommentSupport = true; + this.runConformTest( + "X.java", + "@interface Annot {\n" + + " int value() default 0;\n" + + "}\n" + + "/**\n" + + " * @see Annot\n" + + " */\n" + + "@Annot\n" + + "@Annot(3)\n" + + "@Annot(value=4)\n" + + "public class X {\n" + + " /**\n" + + " * @see Annot\n" + + " */\n" + + " public void foo(@Annot int i) {\n" + + " @Annot int j = 0;" + + " }\n" + + "}\n", + new Parser( + new ProblemReporter(DefaultErrorHandlingPolicies.proceedWithAllProblems(), + options, + new DefaultProblemFactory()), false), + new AnnotationCollector(), + "java doc single type reference start visit\n" + + "java doc single type reference end visit\n" + + "marker annotation start visit\n" + + "marker annotation end visit\n" + + "single member annotation start visit\n" + + "3\n" + + "single member annotation end visit\n" + + "normal annotation start visit\n" + + "member value pair start visit\n" + + "value, 4\n" + + "member value pair end visit\n" + + "normal annotation end visit\n" + + "java doc single type reference start visit\n" + + "java doc single type reference end visit\n" + + "start argument\n" + + "marker annotation start visit\n" + + "marker annotation end visit\n" + + "exit argument\n" + + "start local declaration\n" + + "marker annotation start visit\n" + + "marker annotation end visit\n" + + "exit local declaration\n"); +} +} + +// Helper classes: define visitors leveraged by some tests +class ASTCollector extends ASTVisitor { + StringBuffer collector = new StringBuffer(); +public String result() { + return this.collector.toString(); +} +} + +class ASTBinaryExpressionCollector extends ASTCollector { +static final int LIMIT = 30; +// help limit the output in length by suppressing the middle +// part of strings which length exceeds LIMIT +String cut(String source) { + int length; + if ((length = source.length()) > LIMIT) { + StringBuilder result = new StringBuilder(length); + result.append(source.substring(0, LIMIT - 10)); + result.append("..."); + result.append(source.substring(length - 7, length)); + return result.toString(); + } else { + return source; + } +} +public void endVisit(BinaryExpression binaryExpression, BlockScope scope) { + this.collector.append("[ev BE " + cut(binaryExpression.toString()) + "]\n"); + super.endVisit(binaryExpression, scope); +} + +public void endVisit(CharLiteral charLiteral, BlockScope scope) { + this.collector.append("[ev CL " + cut(charLiteral.toString()) + "]\n"); + super.endVisit(charLiteral, scope); +} + +public void endVisit(ExtendedStringLiteral literal, BlockScope scope) { + this.collector.append("[ev ESL " + cut(literal.toString()) + "]\n"); + super.endVisit(literal, scope); +} + +public void endVisit(SingleNameReference singleNameReference, + BlockScope scope) { + this.collector.append("[ev SNR " + cut(singleNameReference.toString()) + + "]\n"); + super.endVisit(singleNameReference, scope); +} + +public void endVisit(StringLiteral stringLiteral, BlockScope scope) { + this.collector.append("[ev SL " + cut(stringLiteral.toString()) + "]\n"); + super.endVisit(stringLiteral, scope); +} + +public void endVisit(StringLiteralConcatenation literal, BlockScope scope) { + this.collector.append("[ev SLC " + cut(literal.toString()) + "]\n"); + super.endVisit(literal, scope); +} + +public boolean visit(BinaryExpression binaryExpression, BlockScope scope) { + this.collector.append("[v BE " + cut(binaryExpression.toString()) + "]\n"); + return super.visit(binaryExpression, scope); +} + +public boolean visit(CharLiteral charLiteral, BlockScope scope) { + this.collector.append("[v CL " + cut(charLiteral.toString()) + "]\n"); + return super.visit(charLiteral, scope); +} + +public boolean visit(ExtendedStringLiteral literal, BlockScope scope) { + this.collector.append("[v ESL " + cut(literal.toString()) + "]\n"); + return super.visit(literal, scope); +} + +public boolean visit(SingleNameReference singleNameReference, + BlockScope scope) { + this.collector.append("[v SNR " + cut(singleNameReference.toString()) + + "]\n"); + return super.visit(singleNameReference, scope); +} + +public boolean visit(StringLiteral stringLiteral, BlockScope scope) { + this.collector.append("[v SL " + cut(stringLiteral.toString()) + "]\n"); + return super.visit(stringLiteral, scope); +} + +public boolean visit(StringLiteralConcatenation literal, BlockScope scope) { + this.collector.append("[v SLC " + cut(literal.toString()) + "]\n"); + return super.visit(literal, scope); +} +} +class AnnotationCollector extends ASTCollector { +public boolean visit(MarkerAnnotation annotation, BlockScope scope) { + this.collector.append("marker annotation start visit\n"); + return true; +} +public void endVisit(MarkerAnnotation annotation, BlockScope scope) { + this.collector.append("marker annotation end visit\n"); +} +public boolean visit(NormalAnnotation annotation, BlockScope scope) { + this.collector.append("normal annotation start visit\n"); + return true; +} +public void endVisit(NormalAnnotation annotation, BlockScope scope) { + this.collector.append("normal annotation end visit\n"); +} +public boolean visit(SingleMemberAnnotation annotation, BlockScope scope) { + this.collector.append("single member annotation start visit\n"); + this.collector.append(annotation.memberValue.toString()); + this.collector.append("\n"); + return true; +} +public void endVisit(SingleMemberAnnotation annotation, BlockScope scope) { + this.collector.append("single member annotation end visit\n"); +} +public void endVisit(JavadocSingleTypeReference typeRef, BlockScope scope) { + this.collector.append("java doc single type reference end visit\n"); +} +public void endVisit(JavadocSingleTypeReference typeRef, ClassScope scope) { + this.collector.append("java doc single type reference end visit\n"); +} +public boolean visit(JavadocSingleTypeReference typeRef, BlockScope scope) { + this.collector.append("java doc single type reference start visit\n"); + return true; +} +public boolean visit(JavadocSingleTypeReference typeRef, ClassScope scope) { + this.collector.append("java doc single type reference start visit\n"); + return true; +} +public boolean visit(MemberValuePair pair, BlockScope scope) { + this.collector.append("member value pair start visit\n"); + this.collector.append(pair.name); + this.collector.append(", "); + this.collector.append(pair.value.toString()); + this.collector.append("\n"); + return true; +} +public void endVisit(MemberValuePair pair, BlockScope scope) { + this.collector.append("member value pair end visit\n"); +} +/* (non-Javadoc) + * @see org.eclipse.jdt.internal.compiler.ASTVisitor#endVisit(org.eclipse.jdt.internal.compiler.ast.Argument, org.eclipse.jdt.internal.compiler.lookup.BlockScope) + */ +public void endVisit(Argument argument, BlockScope scope) { + this.collector.append("exit argument\n"); +} +/* (non-Javadoc) + * @see org.eclipse.jdt.internal.compiler.ASTVisitor#endVisit(org.eclipse.jdt.internal.compiler.ast.Argument, org.eclipse.jdt.internal.compiler.lookup.ClassScope) + */ +public void endVisit(Argument argument, ClassScope scope) { + this.collector.append("exit argument\n"); +} +/* (non-Javadoc) + * @see org.eclipse.jdt.internal.compiler.ASTVisitor#endVisit(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration, org.eclipse.jdt.internal.compiler.lookup.BlockScope) + */ +public void endVisit(LocalDeclaration localDeclaration, BlockScope scope) { + this.collector.append("exit local declaration\n"); +} +/* (non-Javadoc) + * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.Argument, org.eclipse.jdt.internal.compiler.lookup.BlockScope) + */ +public boolean visit(Argument argument, BlockScope scope) { + this.collector.append("start argument\n"); + return true; +} +/* (non-Javadoc) + * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.Argument, org.eclipse.jdt.internal.compiler.lookup.ClassScope) + */ +public boolean visit(Argument argument, ClassScope scope) { + this.collector.append("start argument\n"); + return true; +} +/* (non-Javadoc) + * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration, org.eclipse.jdt.internal.compiler.lookup.BlockScope) + */ +public boolean visit(LocalDeclaration localDeclaration, BlockScope scope) { + this.collector.append("start local declaration\n"); + return true; +} +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractBatchCompilerTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractBatchCompilerTest.java new file mode 100644 index 0000000000..5a8a7ce6a6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractBatchCompilerTest.java @@ -0,0 +1,961 @@ +/******************************************************************************* + * Copyright (c) 2017, 2021 GK Software AG and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringReader; +import java.util.ArrayList; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.compiler.CompilationProgress; +import org.eclipse.jdt.core.compiler.batch.BatchCompiler; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.batch.ClasspathLocation; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.batch.Main; + +public abstract class AbstractBatchCompilerTest extends AbstractRegressionTest { + + protected static abstract class Matcher { + abstract boolean match(String effective); + abstract String expected(); // for use in JUnit comparison framework + } + + /** + * Used for preview features especially. + * @param compilerVersion - CompilerOptions.version string + * @return true if spec version is same as compiler version + */ + public static boolean isJREVersionEqualTo(String compilerVersion) { + String specVersion = System.getProperty("java.specification.version"); + return specVersion != null && Integer.valueOf(specVersion) == Integer.valueOf(compilerVersion); + } + /** + * Abstract normalizer for output comparison. This class merely embodies a + * chain of responsibility, plus the signature of the method of interest + * here, that is {@link #normalized(String) normalized}. + */ + protected static abstract class Normalizer { + private Normalizer nextInChain; + Normalizer(Normalizer nextInChain) { + this.nextInChain = nextInChain; + } + String normalized(String originalValue) { + String result; + if (this.nextInChain == null) + result = Util.convertToIndependantLineDelimiter(originalValue); + else + result = this.nextInChain.normalized(originalValue); + return result; + } + } + + /** + * This normalizer replaces occurrences of a given string with a given + * placeholder. + */ + protected static class StringNormalizer extends Normalizer { + private String match; + private int matchLength; + private String placeholder; + StringNormalizer(Normalizer nextInChain, String match, String placeholder) { + super(nextInChain); + this.match = match; + this.matchLength = match.length(); + this.placeholder = placeholder; + } + @Override + String normalized(String originalValue) { + String result; + StringBuilder normalizedValueBuffer = new StringBuilder(originalValue); + int nextOccurrenceIndex; + while ((nextOccurrenceIndex = normalizedValueBuffer.indexOf(this.match)) != -1) + normalizedValueBuffer.replace(nextOccurrenceIndex, + nextOccurrenceIndex + this.matchLength, this.placeholder); + result = super.normalized(normalizedValueBuffer.toString()); + return result; + } + } + + protected static class TestCompilationProgress extends CompilationProgress { + boolean isCanceled = false; + int workedSoFar = 0; + StringBuffer buffer = new StringBuffer(); + public void begin(int remainingWork) { + this.buffer.append("----------\n[worked: 0 - remaining: ").append(remainingWork).append("]\n"); + } + public void done() { + this.buffer.append("----------\n"); + } + public boolean isCanceled() { + return this.isCanceled; + } + public void setTaskName(String name) { + this.buffer.append(name).append('\n'); + } + public String toString() { + return this.buffer.toString(); + } + public void worked(int workIncrement, int remainingWork) { + this.workedSoFar += workIncrement; + this.buffer.append("[worked: ").append(this.workedSoFar).append(" - remaining: ").append(remainingWork).append("]\n"); + } + } + + public static final String OUTPUT_DIR_PLACEHOLDER = "---OUTPUT_DIR_PLACEHOLDER---"; + public static final String LIB_DIR_PLACEHOLDER = "---LIB_DIR_PLACEHOLDER---"; + + /** + * Normalizer instance that replaces occurrences of OUTPUT_DIR with + * OUTPUT_DIR_PLACEHOLDER and changes file separator to / if the + * platform file separator is different from /. + */ + protected static Normalizer outputDirNormalizer; + static { + if (File.separatorChar == '/') { + outputDirNormalizer = + new StringNormalizer( + new StringNormalizer( + null, OUTPUT_DIR, OUTPUT_DIR_PLACEHOLDER), + LIB_DIR, LIB_DIR_PLACEHOLDER); + } + else { + outputDirNormalizer = + new StringNormalizer( + new StringNormalizer( + new StringNormalizer( + null, File.separator, "/"), + OUTPUT_DIR, OUTPUT_DIR_PLACEHOLDER), + LIB_DIR, LIB_DIR_PLACEHOLDER); + } + } + + public AbstractBatchCompilerTest(String name) { + super(name); + } + + protected static final String JRE_HOME_DIR = Util.getJREDirectory(); + protected static final Main MAIN = new Main(null/*outWriter*/, null/*errWriter*/, false/*systemExit*/, null/*options*/, null/*progress*/); + + private static boolean CASCADED_JARS_CREATED; + @Override + protected void setUp() throws Exception { + super.setUp(); + CASCADED_JARS_CREATED = false; // initialization needed for each subclass individually + } + + protected void createCascadedJars() { + if (!CASCADED_JARS_CREATED) { + File libDir = new File(LIB_DIR); + Util.delete(libDir); // make sure we recycle the libs + libDir.mkdirs(); + try { + Util.createJar( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib2.jar\n", + "p/S1.java", + "package p;\n" + + "public class S1 {\n" + + "}", + }, + LIB_DIR + "/lib1.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/B.java", + "package p;\n" + + "public class B {\n" + + "}", + "p/R.java", + "package p;\n" + + "public class R {\n" + + " public static final int R2 = 2;\n" + + "}", + }, + new String[] { + "p/S2.java", + "package p;\n" + + "public class S2 {\n" + + "}", + }, + LIB_DIR + "/lib2.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/C.java", + "package p;\n" + + "public class C {\n" + + "}", + "p/R.java", + "package p;\n" + + "public class R {\n" + + " public static final int R3 = 3;\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib4.jar\n", + }, + LIB_DIR + "/lib3.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/D.java", + "package p;\n" + + "public class D {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib1.jar lib3.jar\n", + }, + LIB_DIR + "/lib4.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/C.java", + "package p;\n" + + "public class C {\n" + + "}", + "p/R.java", + "package p;\n" + + "public class R {\n" + + " public static final int R3 = 3;\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: s/lib6.jar\n", + }, + LIB_DIR + "/lib5.jar", + JavaCore.VERSION_1_4); + new File(LIB_DIR + "/s").mkdir(); + Util.createJar( + new String[] { + "p/D.java", + "package p;\n" + + "public class D {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: ../lib7.jar\n", + }, + LIB_DIR + "/s/lib6.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib2.jar\n", + }, + LIB_DIR + "/lib7.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/F.java", + "package p;\n" + + "public class F {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: " + LIB_DIR + "/lib3.jar lib1.jar\n", + }, + LIB_DIR + "/lib8.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/G.java", + "package p;\n" + + "public class G {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib1.jar\n" + + "Class-Path: lib3.jar\n", + }, + LIB_DIR + "/lib9.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + "}", + }, + // spoiled jar: MANIFEST.MF is a directory + new String[] { + "META-INF/MANIFEST.MF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib2.jar\n", + }, + LIB_DIR + "/lib10.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path:\n", + }, + LIB_DIR + "/lib11.jar", + JavaCore.VERSION_1_4); + Util.createJar( + null, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path:lib1.jar\n", // missing space + }, + LIB_DIR + "/lib12.jar", + JavaCore.VERSION_1_4); + Util.createJar( + null, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path:lib1.jar lib1.jar\n", // missing space + }, + LIB_DIR + "/lib13.jar", + JavaCore.VERSION_1_4); + Util.createJar( + null, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + " Class-Path: lib1.jar\n", // extra space at line start + }, + LIB_DIR + "/lib14.jar", + JavaCore.VERSION_1_4); + Util.createJar( + null, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: lib1.jar", // missing newline at end + }, + LIB_DIR + "/lib15.jar", + JavaCore.VERSION_1_4); + Util.createJar( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: \n" + + " lib2.jar\n", + "p/S1.java", + "package p;\n" + + "public class S1 {\n" + + "}", + }, + LIB_DIR + "/lib16.jar", + JavaCore.VERSION_1_4); + new File(LIB_DIR + "/dir").mkdir(); + Util.createJar( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + "}", + }, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Created-By: Eclipse JDT Test Harness\n" + + "Class-Path: ../lib2.jar\n", + }, + LIB_DIR + "/dir/lib17.jar", + JavaCore.VERSION_1_4); + CASCADED_JARS_CREATED = true; + } catch (IOException e) { + // ignore + } + } + } + + protected String getLibraryClassesAsQuotedString() { + String[] paths = Util.getJavaClassLibs(); + StringBuffer buffer = new StringBuffer(); + buffer.append('"'); + for (int i = 0, max = paths.length; i < max; i++) { + if (i != 0) { + buffer.append(File.pathSeparatorChar); + } + buffer.append(paths[i]); + } + buffer.append('"'); + return String.valueOf(buffer); + } + + protected String getJCEJarAsQuotedString() { + if (Util.isMacOS()) { + return "\"" + JRE_HOME_DIR + "/../Classes/jce.jar\""; + } + return "\"" + JRE_HOME_DIR + "/lib/jce.jar\""; + } + + protected String getExtDirectory() { + return JRE_HOME_DIR + "/lib/ext"; + } + + /** + * Run a compilation test that is expected to complete successfully and + * compare the outputs to expected ones. + * + * @param testFiles + * the source files, given as a suite of file name, file content; + * file names are relative to the output directory + * @param commandLine + * the command line to pass to + * {@link BatchCompiler#compile(String, PrintWriter, PrintWriter, org.eclipse.jdt.core.compiler.CompilationProgress) BatchCompiler#compile} + * @param expectedSuccessOutOutputString + * the expected contents of the standard output stream; pass null + * to bypass the comparison + * @param expectedSuccessErrOutputString + * the expected contents of the standard error output stream; + * pass null to bypass the comparison + * @param shouldFlushOutputDirectory + * pass true to get the output directory flushed before the test + * runs + */ + protected void runConformTest(String[] testFiles, String commandLine, String expectedSuccessOutOutputString, String expectedSuccessErrOutputString, boolean shouldFlushOutputDirectory) { + runTest(true, testFiles, commandLine, expectedSuccessOutOutputString, + expectedSuccessErrOutputString, shouldFlushOutputDirectory, null/*progress*/); + } + + /** + * Run a compilation test that is expected to fail and compare the outputs + * to expected ones. + * + * @param testFiles + * the source files, given as a suite of file name, file content; + * file names are relative to the output directory + * @param commandLine + * the command line to pass to + * {@link BatchCompiler#compile(String, PrintWriter, PrintWriter, org.eclipse.jdt.core.compiler.CompilationProgress) BatchCompiler#compile} + * @param expectedFailureOutOutputString + * the expected contents of the standard output stream; pass null + * to bypass the comparison + * @param expectedFailureErrOutputString + * the expected contents of the standard error output stream; + * pass null to bypass the comparison + * @param shouldFlushOutputDirectory + * pass true to get the output directory flushed before the test + * runs + */ + protected void runNegativeTest(String[] testFiles, String commandLine, String expectedFailureOutOutputString, String expectedFailureErrOutputString, boolean shouldFlushOutputDirectory) { + runTest(false, testFiles, commandLine, expectedFailureOutOutputString, + expectedFailureErrOutputString, shouldFlushOutputDirectory, null/*progress*/); + } + + protected void runProgressTest(String[] testFiles, String commandLine, String expectedOutOutputString, String expectedErrOutputString, String expectedProgress) { + runTest(true/*shouldCompileOK*/, testFiles, commandLine, expectedOutOutputString, expectedErrOutputString, true/*shouldFlushOutputDirectory*/, new TestCompilationProgress()); + } + + protected void runProgressTest(boolean shouldCompileOK, String[] testFiles, String commandLine, String expectedOutOutputString, String expectedErrOutputString, TestCompilationProgress progress, String expectedProgress) { + runTest(shouldCompileOK, testFiles, commandLine, expectedOutOutputString, expectedErrOutputString, true/*shouldFlushOutputDirectory*/, progress); + String actualProgress = progress.toString(); + if (!semiNormalizedComparison(expectedProgress, actualProgress, outputDirNormalizer)) { + System.out.println(Util.displayString(outputDirNormalizer.normalized(actualProgress), 2)); + assertEquals( + "Unexpected progress", + expectedProgress, + actualProgress); + } + } + + /** + * Worker method for runConformTest and runNegativeTest. + * + * @param shouldCompileOK + * set to true if the compiler should compile the given sources + * without errors + * @param testFiles + * the source files, given as a suite of file name, file content; + * file names are relative to the output directory + * @param extraArguments + * the command line to pass to {@link Main#compile(String[]) + * Main#compile} or other arguments to pass to {@link + * #invokeCompiler(PrintWriter, PrintWriter, Object, + * BatchCompilerTest.TestCompilationProgress)} (for use + * by extending test classes) + * @param expectedOutOutputString + * the expected contents of the standard output stream; pass null + * to bypass the comparison + * @param expectedErrOutputString + * the expected contents of the standard error output stream; + * pass null to bypass the comparison + * @param shouldFlushOutputDirectory + * pass true to get the output directory flushed before the test + * runs + */ + protected void runTest(boolean shouldCompileOK, String[] testFiles, Object extraArguments, String expectedOutOutputString, String expectedErrOutputString, boolean shouldFlushOutputDirectory, TestCompilationProgress progress) { + File outputDirectory = new File(OUTPUT_DIR); + if (shouldFlushOutputDirectory) + Util.flushDirectoryContent(outputDirectory); + try { + if (!outputDirectory.isDirectory()) { + outputDirectory.mkdirs(); + } + if (testFiles != null) { + PrintWriter sourceFileWriter; + for (int i = 0; i < testFiles.length; i += 2) { + String fileName = OUTPUT_DIR + File.separator + testFiles[i]; + File file = new File(fileName), innerOutputDirectory = file + .getParentFile(); + if (!innerOutputDirectory.isDirectory()) { + innerOutputDirectory.mkdirs(); + } + sourceFileWriter = new PrintWriter(new FileOutputStream(file)); + try { + sourceFileWriter.write(testFiles[i + 1]); + } finally { + sourceFileWriter.close(); + } + } + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + String printerWritersNameRoot = OUTPUT_DIR + File.separator + testName(); + String outFileName = printerWritersNameRoot + "out.txt", + errFileName = printerWritersNameRoot + "err.txt"; + PrintWriter out = null; + PrintWriter err = null; + boolean compileOK; + try { + try { + out = new PrintWriter(new FileOutputStream(outFileName)); + err = new PrintWriter(new FileOutputStream(errFileName)); + } catch (FileNotFoundException e) { + System.out.println(getClass().getName() + '#' + getName()); + e.printStackTrace(); + throw new RuntimeException(e); + } + compileOK = invokeCompiler(out, err, extraArguments, progress); + } finally { + if (out != null) + out.close(); + if (err != null) + err.close(); + } + String outOutputString = Util.fileContent(outFileName), + errOutputString = Util.fileContent(errFileName); + boolean compareOK = false, outCompareOK = false, errCompareOK = false; + if (compileOK == shouldCompileOK) { + compareOK = + (outCompareOK = semiNormalizedComparison(expectedOutOutputString, + outOutputString, outputDirNormalizer)) + && (errCompareOK = semiNormalizedComparison(expectedErrOutputString, + errOutputString, outputDirNormalizer)); + } + // test sanity of the test definition: did we forget to use "---OUTPUT_DIR_PLACEHOLDER---" instead of OUTPUT_DIR? + if (!outCompareOK) { + assertEquals("outputDirNormalizer should not affect expectedOutOutput", expectedOutOutputString, outputDirNormalizer.normalized(expectedOutOutputString)); + } + if (!errCompareOK) { + assertEquals("outputDirNormalizer should not affect expectedErrOutput", expectedErrOutputString, outputDirNormalizer.normalized(expectedErrOutputString)); + } + if (compileOK != shouldCompileOK || !compareOK) { + System.out.println(getClass().getName() + '#' + getName()); + if (testFiles != null) { + for (int i = 0; i < testFiles.length; i += 2) { + System.out.print(testFiles[i]); + System.out.println(" ["); + System.out.println(testFiles[i + 1]); + System.out.println("]"); + } + } + } + if (compileOK != shouldCompileOK) + System.out.println(errOutputString); + if (compileOK == shouldCompileOK && !compareOK) { + System.out.println( + "------------ [START OUT] ------------\n" + + "------------- Expected: -------------\n" + + expectedOutOutputString + + "\n------------- but was: -------------\n" + + outOutputString + + "\n--------- (cut and paste:) ----------\n" + + Util.displayString(outputDirNormalizer + .normalized(outOutputString)) + + "\n------------- [END OUT] -------------\n" + + "------------ [START ERR] ------------\n" + + "------------- Expected: -------------\n" + + expectedErrOutputString + + "\n------------- but was: -------------\n" + + errOutputString + + "\n--------- (cut and paste:) ----------\n" + + Util.displayString(outputDirNormalizer + .normalized(errOutputString)) + + "\n------------- [END ERR] -------------\n"); + } + if (shouldCompileOK) + assertTrue("Unexpected problems [out: " + outOutputString + "][err: " + errOutputString + "]", compileOK); + else + assertFalse("Unexpected success: [out: " + outOutputString + "][err: " + errOutputString + "]", compileOK); + if (!outCompareOK) { + // calling assertEquals to benefit from the comparison UI + // (need appropriate exception) + assertEquals( + "Unexpected standard output for invocation with arguments [" + + extraArguments + "]", + expectedOutOutputString, + outOutputString); + } + if (!errCompareOK) { + assertEquals( + "Unexpected error output for invocation with arguments [" + + extraArguments + "]", + expectedErrOutputString, + errOutputString); + } + } + + protected boolean invokeCompiler(PrintWriter out, PrintWriter err, Object extraArguments, TestCompilationProgress compilationProgress) { + try { + final String[] tokenizedCommandLine = Main.tokenize((String) extraArguments); + return new Main(out, err, false, null /* customDefaultOptions */, compilationProgress /* compilationProgress*/).compile(tokenizedCommandLine); + } catch (RuntimeException e) { + System.out.println(getClass().getName() + '#' + getName()); + e.printStackTrace(); + throw e; + } + } + + protected void runTest(boolean shouldCompileOK, String[] testFiles, String commandLine, Matcher outOutputStringMatcher, Matcher errOutputStringMatcher, boolean shouldFlushOutputDirectory) { + File outputDirectory = new File(OUTPUT_DIR); + if (shouldFlushOutputDirectory) + Util.flushDirectoryContent(outputDirectory); + try { + if (!outputDirectory.isDirectory()) { + outputDirectory.mkdirs(); + } + PrintWriter sourceFileWriter; + for (int i = 0; i < testFiles.length; i += 2) { + String fileName = OUTPUT_DIR + File.separator + testFiles[i]; + File file = new File(fileName), innerOutputDirectory = file + .getParentFile(); + if (!innerOutputDirectory.isDirectory()) { + innerOutputDirectory.mkdirs(); + } + sourceFileWriter = new PrintWriter(new FileOutputStream(file)); + try { + sourceFileWriter.write(testFiles[i + 1]); + } finally { + sourceFileWriter.close(); + } + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + throw new RuntimeException(e); + } + String printerWritersNameRoot = OUTPUT_DIR + File.separator + testName(); + String outFileName = printerWritersNameRoot + "out.txt", + errFileName = printerWritersNameRoot + "err.txt"; + Main batchCompiler; + PrintWriter out = null; + PrintWriter err = null; + boolean compileOK; + try { + try { + out = new PrintWriter(new FileOutputStream(outFileName)); + err = new PrintWriter(new FileOutputStream(errFileName)); + batchCompiler = new Main(out, err, false/*systemExit*/, null/*options*/, null/*progress*/); + } catch (FileNotFoundException e) { + System.out.println(getClass().getName() + '#' + getName()); + e.printStackTrace(); + throw new RuntimeException(e); + } + try { + final String[] tokenizeCommandLine = Main.tokenize(commandLine); + compileOK = batchCompiler.compile(tokenizeCommandLine); + } catch (RuntimeException e) { + compileOK = false; + System.out.println(getClass().getName() + '#' + getName()); + e.printStackTrace(); + throw e; + } + } finally { + if (out != null) + out.close(); + if (err != null) + err.close(); + } + String outOutputString = Util.fileContent(outFileName), + errOutputString = Util.fileContent(errFileName); + boolean compareOK = false, outCompareOK = false, errCompareOK = false; + String expectedErrOutputString = null, expectedOutOutputString = null; + if (compileOK == shouldCompileOK) { + if (outOutputStringMatcher == null) { + outCompareOK = true; + } else { + outCompareOK = outOutputStringMatcher.match(outOutputString); + expectedOutOutputString = outOutputStringMatcher.expected(); + } + if (errOutputStringMatcher == null) { + errCompareOK = true; + } else { + errCompareOK = errOutputStringMatcher.match(errOutputString); + expectedErrOutputString = errOutputStringMatcher.expected(); + } + compareOK = outCompareOK && errCompareOK; + } + if (compileOK != shouldCompileOK || !compareOK) { + System.out.println(getClass().getName() + '#' + getName()); + for (int i = 0; i < testFiles.length; i += 2) { + System.out.print(testFiles[i]); + System.out.println(" ["); + System.out.println(testFiles[i + 1]); + System.out.println("]"); + } + } + if (compileOK != shouldCompileOK) + System.out.println(errOutputString); + if (compileOK == shouldCompileOK && !compareOK) { + System.out.println( + "------------ [START OUT] ------------\n" + + "------------- Expected: -------------\n" + + expectedOutOutputString + + "\n------------- but was: -------------\n" + + outOutputString + + "\n--------- (cut and paste:) ----------\n" + + Util.displayString(outputDirNormalizer + .normalized(outOutputString)) + + "\n------------- [END OUT] -------------\n" + + "------------ [START ERR] ------------\n" + + "------------- Expected: -------------\n" + + expectedErrOutputString + + "\n------------- but was: -------------\n" + + errOutputString + + "\n--------- (cut and paste:) ----------\n" + + Util.displayString(outputDirNormalizer + .normalized(errOutputString)) + + "\n------------- [END ERR] -------------\n"); + } + if (shouldCompileOK) + assertTrue("Unexpected problems: " + errOutputString, compileOK); + else + assertTrue("Unexpected success: " + errOutputString, !compileOK); + if (!outCompareOK) { + // calling assertEquals to benefit from the comparison UI + // (need appropriate exception) + assertEquals( + "Unexpected standard output for invocation with arguments [" + + commandLine + "]", + expectedOutOutputString, + outOutputString); + } + if (!errCompareOK) { + assertEquals( + "Unexpected error output for invocation with arguments [" + + commandLine + "]", + expectedErrOutputString, + errOutputString); + } + } + + protected void runClasspathTest(String classpathInput, String[] expectedClasspathEntries, String expectedError) { + File outputDirectory = new File(OUTPUT_DIR); + if (!outputDirectory.isDirectory()) { + outputDirectory.mkdirs(); + } + ArrayList paths = new ArrayList<>(Main.DEFAULT_SIZE_CLASSPATH); + try { + (new Main(new PrintWriter(System.out), new PrintWriter(System.err), true/*systemExit*/, null/*options*/, null/*progress*/)). + processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, classpathInput, null /* customEncoding */, true /* isSourceOnly */, false /* rejectDestinationPathOnJars*/); + } catch (IllegalArgumentException e) { + // e.printStackTrace(); + if (expectedError == null) { + fail("unexpected invalid input exception: " + e.getMessage()); + } else if (! expectedError.equals(e.getMessage())) { + System.out.println("\"" + e.getMessage() + "\""); + assertEquals(expectedError, e.getMessage()); + } + return; + } + if (expectedError == null) { + int l = paths.size(); + assertEquals("unexpected classpaths entries number: ", + expectedClasspathEntries == null ? 0 : expectedClasspathEntries.length / 3, l); + for (int i = 0, j = 0; i < l ; i++) { + ClasspathLocation result = (ClasspathLocation) paths.get(i); + String expected = expectedClasspathEntries[j++]; + String actual = result.toString(); + if (! actual.equals("ClasspathDirectory " + expected + File.separator) && + ! actual.equals("Classpath for jar file " + expected)) { + assertEquals("dir/jar " + expected, actual); + } + expected = expectedClasspathEntries[j++]; + if (result.accessRuleSet == null) { + assertNull("actual access rule is null instead of <" + expected +">", expected); + } else if (! result.accessRuleSet.toString(false). + startsWith("AccessRuleSet " + expected)) { + System.out.println("\"" + result.accessRuleSet.toString(false) + "\""); + fail("inappropriate rules (expected " + expected + + ", got " + result.accessRuleSet.toString(false)); + } + expected = expectedClasspathEntries[j++]; + if (expected == null) { + assertNull(result.destinationPath); + } else if (expected == Main.NONE && + result.destinationPath != Main.NONE) { + fail("expected 'none' output directory"); + } else if (! expected.equals(result.destinationPath)) { + System.out.println("\"" + result.destinationPath + "\""); + assertEquals(expected, result.destinationPath); + } + } + } else { + fail("missing error: " + expectedError); + } + } + + /** + * Check that no line of message extends beyond width columns. Tabs count for + * 4 characters. + * @param message the message to check + * @param width the maximum number of columns for the message + */ + protected void checkWidth(String message, int width) { + BufferedReader reader = new BufferedReader( + new StringReader(message.replaceAll("\t", " "))); + String line; + try { + while ((line = reader.readLine()) != null) { + assertTrue("line exceeds " + width + "characters: " + line, + line.length() <= width); + } + } catch (IOException e) { + // should never happen on a StringReader + } + } + + private static boolean equals(String a, String b) { + StringBuilder aBuffer = new StringBuilder(a), bBuffer = new StringBuilder(b); + int length = aBuffer.length(), bLength; + boolean result = true; + if (length != (bLength = bBuffer.length())) { + System.err.println("a and b lengths differ"); + if (length > bLength) { + length = bLength; + } + result = false; + } + for (int i = 0; i < length; i++) + if (aBuffer.charAt(i) != bBuffer.charAt(i)) { + int beforeStart = i - 5, beforeEnd = i - 1, afterStart = i + 1, afterEnd = i + 5; + if (beforeStart < 0) { + beforeStart = 0; + if (beforeEnd < 0) + beforeEnd = 0; + } + if (afterEnd >= length) { + afterEnd = length - 1; + if (afterStart >= length) + afterStart = length - 1; + } + System.err.println("a and b differ at rank: " + i + + "\na: ..." + aBuffer.substring(beforeStart, beforeEnd) + + "<" + aBuffer.charAt(i) + ">" + + aBuffer.substring(afterStart, afterEnd) + "..." + + "\nb: ..." + bBuffer.substring(beforeStart, beforeEnd) + + "<" + bBuffer.charAt(i) + ">" + + bBuffer.substring(afterStart, afterEnd) + "..."); + return false; + } + return result; // may be false if one of the strings equals the beginning + // of the other one, which is longer anyway + } + + /** + * Return true if and only if the two strings passed as parameters compare + * equal, modulo the transformation of the second string by a normalizer + * passed in parameter. This is meant to erase the variations of subparts of + * the compared strings in function of the test machine, the user account, + * etc. + * + * @param keep + * the first string to compare, gets compared as it is + * @param normalize + * the second string to compare, passed through the normalizer + * before comparison + * @param normalizer + * the transformation applied to normalize + * @return true if keep and normalize compare equal after normalize has been + * normalized + */ + protected boolean semiNormalizedComparison(String keep, String normalize, Normalizer normalizer) { + if (keep == null) + return normalize == null; + if (normalize == null) + return false; + // return keep.equals(normalizer.normalized(normalize)); + return equals(keep, normalizer.normalized(normalize)); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java new file mode 100644 index 0000000000..4cc0ae21be --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractComparableTest.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2000, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * bug 376590 - Private fields with @Inject are ignored by unused field validation + * Ulrich Grave - Contributions for + * bug 386692 - Missing "unused" warning on "autowired" fields + * Pierre-Yves B. - Contribution for + * bug 542520 - [JUnit 5] Warning The method xxx from the type X is never used locally is shown when using MethodSource + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class AbstractComparableTest extends AbstractRegressionTest { + + protected static final String GOOGLE_INJECT_NAME = "com/google/inject/Inject.java"; + protected static final String GOOGLE_INJECT_CONTENT = + "package com.google.inject;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import java.lang.annotation.Target;\n" + + "@Target({ METHOD, CONSTRUCTOR, FIELD })\n" + + "@Retention(RUNTIME)\n" + + "public @interface Inject {\n" + + "\n" + + " boolean optional() default false;\n" + + "}"; + + protected static final String JAVAX_INJECT_NAME = "javax/inject/Inject.java"; + protected static final String JAVAX_INJECT_CONTENT = + "package javax.inject;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "import java.lang.annotation.Target;\n" + + "@Target({ METHOD, CONSTRUCTOR, FIELD })\n" + + "@Retention(RUNTIME)\n" + + "public @interface Inject {}\n"; + + protected static final String SPRINGFRAMEWORK_AUTOWIRED_NAME = "org/springframework/beans/factory/annotation/Autowired.java"; + protected static final String SPRINGFRAMEWORK_AUTOWIRED_CONTENT = + "package org.springframework.beans.factory.annotation;\n" + + "import java.lang.annotation.Documented;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD})\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Documented\n" + + "public @interface Autowired {\n" + + "\n" + + " boolean required() default true;\n" + + "\n" + + "}"; + + protected static final String JUNIT_METHODSOURCE_NAME = "org/junit/jupiter/params/provider/MethodSource.java"; + protected static final String JUNIT_METHODSOURCE_CONTENT = + "package org.junit.jupiter.params.provider;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "public @interface MethodSource {\n" + + "\n" + + " String[] value() default \"\";\n" + + "\n" + + "}"; + + public static Test buildComparableTestSuite(Class evaluationTestClass) { + Test suite = buildMinimalComplianceTestSuite(evaluationTestClass, F_1_5); + TESTS_COUNTERS.put(evaluationTestClass.getName(), Integer.valueOf(suite.countTestCases())); + return suite; + } + + public AbstractComparableTest(String name) { + super(name); + } + + /* + * Toggle compiler in mode -1.5 + */ + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFinalParameterBound, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotation, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportMissingDeprecatedAnnotation, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.WARNING); + return options; + } + + protected String intersection(String... types) { + // From JDK 12, Comparable gets two new super interfaces, namely Constable and ConstantDesc. + // The idea is to append Comparable with &Constable&ConstantDesc automatically. + if (isJRE12Plus) { + int index = -1; + for(int i = 0; i < types.length; i++) { + if (types[i].startsWith("Comparable") && !types[i].endsWith("ConstantDesc")) { + if ((types.length <= i+1) || !types[i+1].startsWith("CharSequence")) { + index = i; + break; + } + } + } + if (index >= 0) { + index++; + String[] temp = new String[types.length + 2]; + System.arraycopy(types, 0, temp, 0, index); + temp[index] = "Constable"; + temp[index+1] = "ConstantDesc"; + if (index < types.length) + System.arraycopy(types, index, temp, index+2, types.length - index); + types = temp; + } + } + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return String.join(" & ", types); + return String.join("&", types); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractNullAnnotationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractNullAnnotationTest.java new file mode 100644 index 0000000000..585dc27f4f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractNullAnnotationTest.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * Copyright (c) 2010, 2018 GK Software AG and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.osgi.framework.Bundle; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public abstract class AbstractNullAnnotationTest extends AbstractComparableTest { + + // class libraries including our default null annotation types: + String[] LIBS; + + // names and content of custom annotations used in a few tests: + static final String CUSTOM_NONNULL_NAME = "org/foo/NonNull.java"; + static final String CUSTOM_NONNULL_CONTENT = + "package org.foo;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({METHOD,PARAMETER,LOCAL_VARIABLE})\n" + + "public @interface NonNull {\n" + + "}\n"; + static final String CUSTOM_NONNULL_CONTENT_JSR308 = + "package org.foo;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({METHOD,PARAMETER,LOCAL_VARIABLE,TYPE_USE})\n" + + "public @interface NonNull {\n" + + "}\n"; + static final String CUSTOM_NULLABLE_NAME = "org/foo/Nullable.java"; + static final String CUSTOM_NULLABLE_CONTENT = "package org.foo;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({METHOD,PARAMETER,LOCAL_VARIABLE})\n" + + "public @interface Nullable {\n" + + "}\n"; + static final String CUSTOM_NULLABLE_CONTENT_JSR308 = "package org.foo;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({METHOD,PARAMETER,LOCAL_VARIABLE,TYPE_USE})\n" + + "public @interface Nullable {\n" + + "}\n"; + static final String CUSTOM_NNBD_NAME = "org/foo/NonNullByDefault.java"; + static final String CUSTOM_NNBD_CONTENT = "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" + + "public @interface NonNullByDefault {\n" + // has no details, so default default locations should be applied + "}\n"; + + public AbstractNullAnnotationTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + setUpAnnotationLib(); + } + + /** + * @deprecated indirectly uses deprecated class PackageAdmin + */ + protected void setUpAnnotationLib() throws IOException { + if (this.LIBS == null) { + String[] defaultLibs = getDefaultClassPaths(); + int len = defaultLibs.length; + this.LIBS = new String[len+1]; + System.arraycopy(defaultLibs, 0, this.LIBS, 0, len); + String version = this.complianceLevel >= ClassFileConstants.JDK1_8 ? "[2.0.0,3.0.0)" : "[1.1.0,2.0.0)"; + Bundle[] bundles = org.eclipse.jdt.core.tests.compiler.Activator.getPackageAdmin().getBundles("org.eclipse.jdt.annotation", version); + File bundleFile = FileLocator.getBundleFile(bundles[0]); + if (bundleFile.isDirectory()) + this.LIBS[len] = bundleFile.getPath()+"/bin"; + else + this.LIBS[len] = bundleFile.getPath(); + } + } + + // Conditionally augment problem detection settings + static boolean setNullRelatedOptions = true; + + @Override + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + if (setNullRelatedOptions) { + defaultOptions.put(JavaCore.COMPILER_PB_NULL_REFERENCE, JavaCore.ERROR); + defaultOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + defaultOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR); + defaultOptions.put(JavaCore.COMPILER_PB_INCLUDE_ASSERTS_IN_NULL_ANALYSIS, JavaCore.ENABLED); + + defaultOptions.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION_FOR_INTERFACE_METHOD_IMPLEMENTATION, JavaCore.DISABLED); + + // enable null annotations: + defaultOptions.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + + defaultOptions.put(CompilerOptions.OPTION_PessimisticNullAnalysisForFreeTypeVariables, JavaCore.ERROR); + defaultOptions.put(CompilerOptions.OPTION_ReportNonNullTypeVariableFromLegacyInvocation, JavaCore.WARNING); + + // leave other new options at these defaults: +// defaultOptions.put(CompilerOptions.OPTION_ReportNullContractViolation, JavaCore.ERROR); +// defaultOptions.put(CompilerOptions.OPTION_ReportPotentialNullContractViolation, JavaCore.ERROR); +// defaultOptions.put(CompilerOptions.OPTION_ReportNullContractInsufficientInfo, CompilerOptions.WARNING); + +// defaultOptions.put(CompilerOptions.OPTION_NullableAnnotationName, "org.eclipse.jdt.annotation.Nullable"); +// defaultOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "org.eclipse.jdt.annotation.NonNull"); + } + return defaultOptions; + } + /** Test expecting a null-error from ecj, none from javac. */ + protected void runNegativeNullTest(String[] sourceFiles, String expectedCompileError, String[] libs, boolean shouldFlush, Map options) { + runNegativeTest( + sourceFiles, + expectedCompileError, + libs, + shouldFlush, + options, + null /* do not check error string */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + /** Test with JDT null annotations, expecting a null-error from ecj, none from javac. */ + void runNegativeTestWithLibs(String[] testFiles, String expectedErrorLog) { + runNegativeTestWithLibs( + false /*shouldFlush*/, + testFiles, + getCompilerOptions(), + expectedErrorLog, + false /*skipJavac*/); + } + /** Test with JDT null annotations, expecting a null-error from ecj, none from javac. */ + void runNegativeTestWithLibs(boolean shouldFlushOutputDirectory, String[] testFiles, Map customOptions, String expectedErrorLog) { + runNegativeTestWithLibs( + shouldFlushOutputDirectory, + testFiles, + customOptions, + expectedErrorLog, + // runtime options + false); + } + /** Test with JDT null annotations, expecting a null-error from ecj, none from javac. */ + void runNegativeTestWithLibs(boolean shouldFlushOutputDirectory, String[] testFiles, Map customOptions, + String expectedErrorLog, boolean skipJavaC) { + runNegativeTest( + shouldFlushOutputDirectory, + testFiles, + this.LIBS, + customOptions, + expectedErrorLog, + // runtime options + skipJavaC ? JavacTestOptions.SKIP : + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + void runNegativeTestWithLibs(String[] testFiles, Map customOptions, String expectedErrorLog) { + runNegativeTestWithLibs(false /* flush output directory */, testFiles, customOptions, expectedErrorLog); + } + void runNegativeTestWithLibs(String[] testFiles, Map customOptions, String expectedErrorLog, boolean skipJavac) { + runNegativeTestWithLibs(false /* flush output directory */, testFiles, customOptions, expectedErrorLog, skipJavac); + } + void runConformTestWithLibs(String[] testFiles, Map customOptions, String expectedCompilerLog) { + runConformTestWithLibs(true /* flush output directory */, testFiles, customOptions, expectedCompilerLog); + } + void runConformTestWithLibs(String[] testFiles, Map customOptions, String expectedCompilerLog, String expectedOutput) { + runConformTestWithLibs(true/* flush output directory */, testFiles, customOptions, expectedCompilerLog, expectedOutput); + } + void runConformTestWithLibs(boolean shouldFlushOutputDirectory, String[] testFiles, Map customOptions, + String expectedCompilerLog, String expectedOutput) { + runConformTest( + shouldFlushOutputDirectory, + testFiles, + this.LIBS, + customOptions, + expectedCompilerLog, + expectedOutput, + "",/* expected error */ + JavacTestOptions.DEFAULT); + } + void runConformTestWithLibs(boolean shouldFlushOutputDirectory, String[] testFiles, Map customOptions, String expectedCompilerLog) { + runConformTest( + shouldFlushOutputDirectory, + testFiles, + this.LIBS, + customOptions, + expectedCompilerLog, + "",/* expected output */ + "",/* expected error */ + JavacTestOptions.DEFAULT); + } + /** Test with JDT null annotations, expecting a null-warning from ecj, none from javac. */ + void runWarningTestWithLibs(boolean shouldFlushOutputDirectory, String[] testFiles, + Map customOptions, String expectedCompilerLog) + { + runWarningTestWithLibs(shouldFlushOutputDirectory, testFiles, customOptions, expectedCompilerLog, ""); + } + void runWarningTestWithLibs(boolean shouldFlushOutputDirectory, String[] testFiles, + Map customOptions, String expectedCompilerLog, String expectedOutput) + { + runConformTest( + shouldFlushOutputDirectory, + testFiles, + this.LIBS, + customOptions, + expectedCompilerLog, + expectedOutput, + "",/* expected error */ + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + void runConformTest(String[] testFiles, Map customOptions, String expectedOutputString) { + runConformTest( + testFiles, + expectedOutputString, + null /*classLibraries*/, + true /*shouldFlushOutputDirectory*/, + null /*vmArguments*/, + customOptions, + null /*customRequestor*/); + + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java new file mode 100644 index 0000000000..0e3f018b04 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java @@ -0,0 +1,4073 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * bug 335093 - [compiler][null] minimal hook for future null annotation support + * bug 388800 - [1.8] adjust tests to 1.8 JRE + * bug 402237 - [1.8][compiler] investigate differences between compilers re MethodVerifyTest + * bug 391376 - [1.8] check interaction of default methods with bridge methods and generics + * Bug 412203 - [compiler] Internal compiler error: java.lang.IllegalArgumentException: info cannot be null + * Bug 422051 - [1.8][compiler][tests] cleanup excuses (JavacHasABug) in InterfaceMethodTests + * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) + * Bug 425721 - [1.8][compiler] Nondeterministic results in GenericsRegressionTest_1_8.testBug424195a + * Jesper S Moller - Contributions for bug 378674 - "The method can be declared as static" is wrong + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.net.URL; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.compiler.batch.BatchCompiler; +import org.eclipse.jdt.core.search.SearchDocument; +import org.eclipse.jdt.core.search.SearchParticipant; +import org.eclipse.jdt.core.tests.junit.extension.StopableTestCase; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.CompilerTestSetup; +import org.eclipse.jdt.core.tests.util.TestVerifier; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.core.util.ClassFormatException; +import org.eclipse.jdt.internal.compiler.ASTVisitor; +import org.eclipse.jdt.internal.compiler.Compiler; +import org.eclipse.jdt.internal.compiler.ICompilerRequestor; +import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; +import org.eclipse.jdt.internal.compiler.IProblemFactory; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.IrritantSet; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; +import org.eclipse.jdt.internal.core.search.JavaSearchParticipant; +import org.eclipse.jdt.internal.core.search.indexing.BinaryIndexer; +import org.eclipse.jdt.internal.core.util.Messages; +import org.osgi.framework.Bundle; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public abstract class AbstractRegressionTest extends AbstractCompilerTest implements StopableTestCase { + + static final String[] env = System.getenv().entrySet().stream() + .filter(e -> !"JAVA_TOOL_OPTIONS".equals(e.getKey()) && !"_JAVA_OPTIONS".equals(e.getKey())) + .map(e -> e.getKey() + "=" + e.getValue()) + .toArray(String[]::new); + + protected class Runner { + boolean shouldFlushOutputDirectory = true; + // input: + String[] testFiles; + String[] dependantFiles; + String[] classLibraries; + boolean libsOnModulePath; + // control compilation: + Map customOptions; + boolean performStatementsRecovery; + boolean generateOutput; + ICompilerRequestor customRequestor; + // compiler result: + String expectedCompilerLog; + String[] alternateCompilerLogs; + boolean showCategory; + boolean showWarningToken; + // javac: + boolean skipJavac; + public String expectedJavacOutputString; + JavacTestOptions javacTestOptions; + // execution: + boolean forceExecution; + String[] vmArguments; + String expectedOutputString; + String expectedErrorString; + + ASTVisitor visitor; + + protected void runConformTest() { + runTest(this.shouldFlushOutputDirectory, + this.testFiles, + this.dependantFiles != null ? this.dependantFiles : new String[] {}, + this.classLibraries, + this.libsOnModulePath, + this.customOptions, + this.performStatementsRecovery, + new Requestor( + this.generateOutput, + this.customRequestor, + this.showCategory, + this.showWarningToken), + false, + this.expectedCompilerLog, + this.alternateCompilerLogs, + this.forceExecution, + this.vmArguments, + this.expectedOutputString, + this.expectedErrorString, + this.visitor, + this.expectedJavacOutputString != null ? this.expectedJavacOutputString : this.expectedOutputString, + this.skipJavac ? JavacTestOptions.SKIP : this.javacTestOptions); + } + + protected void runNegativeTest() { + runTest(this.shouldFlushOutputDirectory, + this.testFiles, + this.dependantFiles != null ? this.dependantFiles : new String[] {}, + this.classLibraries, + this.libsOnModulePath, + this.customOptions, + this.performStatementsRecovery, + new Requestor( + this.generateOutput, + this.customRequestor, + this.showCategory, + this.showWarningToken), + true, + this.expectedCompilerLog, + this.alternateCompilerLogs, + this.forceExecution, + this.vmArguments, + this.expectedOutputString, + this.expectedErrorString, + this.visitor, + this.expectedJavacOutputString != null ? this.expectedJavacOutputString : this.expectedOutputString, + this.skipJavac ? JavacTestOptions.SKIP : this.javacTestOptions); + } + + protected void runWarningTest() { + runTest(this.shouldFlushOutputDirectory, + this.testFiles, + this.dependantFiles != null ? this.dependantFiles : new String[] {}, + this.classLibraries, + this.libsOnModulePath, + this.customOptions, + this.performStatementsRecovery, + new Requestor( + this.generateOutput, + this.customRequestor, + this.showCategory, + this.showWarningToken), + false, + this.expectedCompilerLog, + this.alternateCompilerLogs, + this.forceExecution, + this.vmArguments, + this.expectedOutputString, + this.expectedErrorString, + this.visitor, + this.expectedJavacOutputString != null ? this.expectedJavacOutputString : this.expectedOutputString, + this.skipJavac ? JavacTestOptions.SKIP : this.javacTestOptions); + } + } + + // javac comparison related types, fields and methods - see runJavac for + // details +static class JavacCompiler { + String rootDirectoryPath; + String javacPathName; + String version; // not intended to be modified - one of JavaCore.VERSION_1_* + int minor; + String rawVersion; // not intended to be modified - more complete version name + long compliance; + public static final long EXIT_VALUE_MASK = 0x00000000FFFFFFFFL; + public static final long ERROR_LOG_MASK = 0xFFFFFFFF00000000L; + private String classpath; + JavacCompiler(String rootDirectoryPath) throws IOException, InterruptedException { + this(rootDirectoryPath, null); + } + JavacCompiler(String rootDirectoryPath, String rawVersion) throws IOException, InterruptedException { + this.rootDirectoryPath = rootDirectoryPath; + this.javacPathName = new File(rootDirectoryPath + File.separator + + "bin" + File.separator + JAVAC_NAME).getCanonicalPath(); + // WORK don't need JAVAC_NAME any more; suppress this as we work towards code cleanup + if (rawVersion == null) { + rawVersion = getVersion(this.javacPathName); + } + this.version = versionFromRawVersion(rawVersion, this.javacPathName); + this.compliance = CompilerOptions.versionToJdkLevel(this.version); + this.minor = minorFromRawVersion(this.version, rawVersion); + this.rawVersion = rawVersion; + StringBuilder classpathBuffer = new StringBuilder(" -classpath "); + this.classpath = classpathBuffer.toString(); + } + /** Call this if " -classpath " should be replaced by some other option token. */ + protected void usePathOption(String option) { + this.classpath = option; + } + static String getVersion(String javacPathName) throws IOException, InterruptedException { + Process fetchVersionProcess = null; + try { + fetchVersionProcess = Runtime.getRuntime().exec(javacPathName + " -version", env, null); + Logger versionStdErrLogger = new Logger(fetchVersionProcess.getErrorStream(), ""); // for javac <= 1.8 + Logger versionStdOutLogger = new Logger(fetchVersionProcess.getInputStream(), ""); // for javac >= 9 + versionStdErrLogger.start(); + versionStdOutLogger.start(); + fetchVersionProcess.waitFor(); + // make sure we get the whole output + versionStdErrLogger.join(); + versionStdOutLogger.join(); + String loggedVersion = versionStdErrLogger.buffer.toString(); + if (loggedVersion.isEmpty()) + loggedVersion = versionStdOutLogger.buffer.toString(); + int eol = loggedVersion.indexOf('\n'); + if (eol != -1) { + loggedVersion = loggedVersion.substring(0, eol); + } + if (loggedVersion.startsWith("javac ")) { + loggedVersion = loggedVersion.substring(6, loggedVersion.length()); + } + return loggedVersion; + } finally { + if (fetchVersionProcess != null) { + fetchVersionProcess.destroy(); // closes process streams + } + } + } + static String versionFromRawVersion(String rawVersion, String javacPathName) { + if (rawVersion.indexOf("1.4") != -1 || + (javacPathName != null && + javacPathName.indexOf("1.4") != -1) + /* in fact, SUN javac 1.4 does not support the -version option; + * this is a imperfect heuristic to catch the case */) { + return JavaCore.VERSION_1_4; + } else if (rawVersion.indexOf("1.5") != -1) { + return JavaCore.VERSION_1_5; + } else if (rawVersion.indexOf("1.6") != -1) { + return JavaCore.VERSION_1_6; + } else if (rawVersion.indexOf("1.7") != -1) { + return JavaCore.VERSION_1_7; + } else if (rawVersion.indexOf("1.8") != -1) { + return JavaCore.VERSION_1_8; + } else if(rawVersion.startsWith("9")) { + return JavaCore.VERSION_9; + } else if(rawVersion.startsWith("10")) { + return JavaCore.VERSION_10; + } else if(rawVersion.startsWith("11")) { + return JavaCore.VERSION_11; + } else if(rawVersion.startsWith("12")) { + return JavaCore.VERSION_12; + } else if(rawVersion.startsWith("13")) { + return JavaCore.VERSION_13; + } else if(rawVersion.startsWith("14")) { + return JavaCore.VERSION_14; + } else if(rawVersion.startsWith("15")) { + return JavaCore.VERSION_15; + } else if(rawVersion.startsWith("16")) { + return JavaCore.VERSION_16; + } else if(rawVersion.startsWith("17")) { + return JavaCore.VERSION_17; + } else { + throw new RuntimeException("unknown javac version: " + rawVersion); + } + } + // projects known raw versions to minors; minors should grow with time, so + // that before and after relationships be easy to implement upon compilers + // of the same version; two latest digits are used for variants into levels + // denoted by the two first digits + static int minorFromRawVersion (String version, String rawVersion) { + if (version == JavaCore.VERSION_1_5) { + if ("1.5.0_15-ea".equals(rawVersion)) { + return 1500; + } + if ("1.5.0_16-ea".equals(rawVersion)) { // b01 + return 1600; + } + } + if (version == JavaCore.VERSION_1_6) { + if ("1.6.0_10-ea".equals(rawVersion)) { + return 1000; + } + if ("1.6.0_10-beta".equals(rawVersion)) { // b24 + return 1010; + } + if ("1.6.0_45".equals(rawVersion)) { + return 1045; + } + } + if (version == JavaCore.VERSION_1_7) { + if ("1.7.0-ea".equals(rawVersion)) { + return 0000; + } + if ("1.7.0_10".equals(rawVersion)) { + return 1000; + } + if ("1.7.0_25".equals(rawVersion)) { + return 2500; + } + if ("1.7.0_80".equals(rawVersion)) { + return 8000; + } + } + if (version == JavaCore.VERSION_1_8) { + if ("1.8.0-ea".equals(rawVersion) || ("1.8.0".equals(rawVersion))) { + return 0000; + } + if ("1.8.0_40".equals(rawVersion)) { + return 1000; // corresponds to JLS maintenance release 2015-02-13 + } + if ("1.8.0_45".equals(rawVersion)) { + return 1100; // corresponds to JLS maintenance release 2015-02-13 + } + if ("1.8.0_60".equals(rawVersion)) { + return 1500; + } + if ("1.8.0_131".equals(rawVersion)) { + return 1700; + } + if ("1.8.0_152".equals(rawVersion)) { + return 1900; + } + if ("1.8.0_162".equals(rawVersion)) { + return 2100; + } + if ("1.8.0_171".equals(rawVersion)) { + return 2200; + } + if ("1.8.0_172".equals(rawVersion)) { + return 2300; + } + if ("1.8.0_181".equals(rawVersion)) { + return 2400; + } + if ("1.8.0_182".equals(rawVersion)) { + return 2500; + } + if ("1.8.0_202".equals(rawVersion)) { + return 2600; + } + if ("1.8.0_212".equals(rawVersion)) { + return 2700; + } + } + if (version == JavaCore.VERSION_9) { + if ("9".equals(rawVersion)) { + return 0000; + } + if ("9.0.1".equals(rawVersion)) { + return 0100; + } + if ("9.0.4".equals(rawVersion)) { + return 0400; + } + } + if (version == JavaCore.VERSION_10) { + if ("10".equals(rawVersion)) { + return 0000; + } + if ("10.0.1".equals(rawVersion)) { + return 0100; + } + if ("10.0.2".equals(rawVersion)) { + return 0200; + } + } + if (version == JavaCore.VERSION_11) { + if ("11".equals(rawVersion)) { + return 0000; + } + if ("11.0.1".equals(rawVersion)) { + return 0100; + } + if ("11.0.2".equals(rawVersion)) { + return 0200; + } + } + if (version == JavaCore.VERSION_12) { + if ("12".equals(rawVersion)) { + return 0000; + } + if ("12.0.1".equals(rawVersion)) { + return 0100; + } + if ("12.0.2".equals(rawVersion)) { + return 0200; + } + } + if (version == JavaCore.VERSION_13) { + if ("13-ea".equals(rawVersion)) { + return 0000; + } + if ("13".equals(rawVersion)) { + return 0000; + } + if ("13.0.1".equals(rawVersion)) { + return 0100; + } + if ("13.0.2".equals(rawVersion)) { + return 0200; + } + } + if (version == JavaCore.VERSION_14) { + if ("14-ea".equals(rawVersion)) { + return 0000; + } + if ("14".equals(rawVersion)) { + return 0000; + } + if ("14.0.1".equals(rawVersion)) { + return 0100; + } + if ("14.0.2".equals(rawVersion)) { + return 0200; + } + } + if (version == JavaCore.VERSION_15) { + if ("15-ea".equals(rawVersion)) { + return 0000; + } + if ("15".equals(rawVersion)) { + return 0000; + } + if ("15.0.1".equals(rawVersion)) { + return 0100; + } + if ("15.0.2".equals(rawVersion)) { + return 0200; + } + } + if (version == JavaCore.VERSION_16) { + if ("16-ea".equals(rawVersion)) { + return 0000; + } + if ("16".equals(rawVersion)) { + return 0000; + } + if ("16.0.1".equals(rawVersion)) { + return 0100; + } + if ("16.0.2".equals(rawVersion)) { + return 0200; + } + } + if (version == JavaCore.VERSION_17) { + if ("17-ea".equals(rawVersion)) { + return 0000; + } + if ("17".equals(rawVersion)) { + return 0000; + } + if ("17.0.1".equals(rawVersion)) { + return 0100; + } + if ("17.0.2".equals(rawVersion)) { + return 0200; + } + } + throw new RuntimeException("unknown raw javac version: " + rawVersion); + } + // returns 0L if everything went fine; else the lower word contains the + // exit value and the upper word is non-zero iff the error log has contents + long compile(File directory, String options, String[] sourceFileNames, StringBuffer log) throws IOException, InterruptedException { + return compile(directory, options, sourceFileNames, log, true); + } + long compile(File directory, String options, String[] sourceFileNames, StringBuffer log, boolean extendCommandLine) throws IOException, InterruptedException { + Process compileProcess = null; + long result = 0L; + // WORK classpath should depend on the compiler, not on the default runtime + try { + if (!directory.exists()) { + directory.mkdir(); + } + StringBuilder cmdLine = new StringBuilder(this.javacPathName); + cmdLine.append(this.classpath); + cmdLine.append(". "); + cmdLine.append(options); + if (extendCommandLine) { + for (int i = 0; i < sourceFileNames.length; i ++) { + cmdLine.append(' '); + cmdLine.append(sourceFileNames[i]); + } + } + String cmdLineAsString; + // WORK improve double-quotes management on Linux + if ("Linux".equals(System.getProperty("os.name"))) { + cmdLineAsString = cmdLine.toString().replaceAll("\"", ""); + } else { + cmdLineAsString = cmdLine.toString(); + } + compileProcess = Runtime.getRuntime().exec(cmdLineAsString, env, directory); + Logger errorLogger = new Logger(compileProcess.getErrorStream(), + "ERROR", log == null ? new StringBuffer() : log); + errorLogger.start(); + int compilerResult = compileProcess.waitFor(); + result |= compilerResult; // caveat: may never terminate under specific conditions + errorLogger.join(); // make sure we get the whole output + if (errorLogger.buffer.length() > 0) { + System.err.println("--- javac err: ---"); + System.err.println(errorLogger.buffer.toString()); + result |= ERROR_LOG_MASK; + } + } finally { + if (compileProcess != null) { + compileProcess.destroy(); + } + } + return result; + } +} +static class JavaRuntime { + private String rootDirectoryPath; + private String javaPathName; + String version; // not intended to be modified - one of JavaCore.VERSION_1_* + String rawVersion; // not intended to be modified - more complete version name + int minor; + private static HashMap runtimes = new HashMap(); + static JavaRuntime runtimeFor(JavacCompiler compiler) throws IOException, InterruptedException { + JavaRuntime cached = (JavaRuntime) runtimes.get(compiler.rawVersion); + if (cached == null) { + cached = new JavaRuntime(compiler.rootDirectoryPath, compiler.version, compiler.rawVersion, compiler.minor); + runtimes.put(compiler.rawVersion, cached); + } + return cached; + } + public static JavaRuntime fromCurrentVM() throws IOException, InterruptedException { + String rawVersion = System.getProperty("java.version"); + JavaRuntime cached = (JavaRuntime) runtimes.get(rawVersion); + if (cached == null) { + String jreRootDirPath = Util.getJREDirectory(); + String version = JavacCompiler.versionFromRawVersion(rawVersion, jreRootDirPath); + int minor = JavacCompiler.minorFromRawVersion(version, rawVersion); + cached = new JavaRuntime(jreRootDirPath, version, rawVersion, minor); + runtimes.put(rawVersion, cached); + } + return cached; + } + private JavaRuntime(String rootDirectoryPath, String version, String rawVersion, int minor) throws IOException, InterruptedException { + this.rootDirectoryPath = rootDirectoryPath; + this.javaPathName = new File(this.rootDirectoryPath + File.separator + + "bin" + File.separator + JAVA_NAME).getCanonicalPath(); + this.version = version; + this.rawVersion = rawVersion; + this.minor = minor; + } + // returns 0 if everything went fine + int execute(File directory, String options, String className, StringBuffer stdout, StringBuffer stderr) throws IOException, InterruptedException { + Process executionProcess = null; + try { + StringBuilder cmdLine = new StringBuilder(this.javaPathName); + if (options.contains("-cp ")) + cmdLine.append(' '); // i.e., -cp will be appended below, just ensure separation from javaPathname + else + cmdLine.append(" -classpath . "); // default classpath + cmdLine.append(options); + cmdLine.append(' '); + cmdLine.append(className); + executionProcess = Runtime.getRuntime().exec(cmdLine.toString(), env, directory); + Logger outputLogger = new Logger(executionProcess.getInputStream(), + "RUNTIME OUTPUT", stdout == null ? new StringBuffer() : stdout); + outputLogger.start(); + Logger errorLogger = new Logger(executionProcess.getErrorStream(), + "RUNTIME ERROR", stderr == null ? new StringBuffer() : stderr); + errorLogger.start(); + int result = executionProcess.waitFor(); // caveat: may never terminate under specific conditions + outputLogger.join(); // make sure we get the whole output + errorLogger.join(); // make sure we get the whole output + return result; + } finally { + if (executionProcess != null) { + executionProcess.destroy(); + } + } + } +} +@SuppressWarnings("synthetic-access") +protected static class JavacTestOptions { + static final JavacTestOptions DEFAULT = new JavacTestOptions(); + static final JavacTestOptions SKIP = new JavacTestOptions() { + @Override + boolean skip(JavacCompiler compiler) { + return true; + } + }; + static JavacTestOptions forRelease(String release) { + JavacTestOptions options = new JavacTestOptions(Long.parseLong(release)); + if (isJRE9Plus) + options.setCompilerOptions("-release "+release); + else + options.setCompilerOptions("-source 1."+release+" -target 1."+release); + return options; + } + static JavacTestOptions forRelease(String release, String additionalOptions) { + JavacTestOptions options = new JavacTestOptions(Long.parseLong(release)); + String result = isJRE9Plus ? "-release "+release : "-source 1."+release+" -target 1."+release; + if (additionalOptions != null) + result = result + " " + additionalOptions; + options.setCompilerOptions(result); + return options; + } + static JavacTestOptions forReleaseWithPreview(String release) { + JavacTestOptions options = new JavacTestOptions(Long.parseLong(release)); + if (isJRE9Plus) + options.setCompilerOptions("--release "+release+" --enable-preview -Xlint:-preview"); + else + throw new IllegalArgumentException("preview not supported at release "+release); + return options; + } + static JavacTestOptions forReleaseWithPreview(String release, String additionalOptions) { + JavacTestOptions options = new JavacTestOptions(Long.parseLong(release)); + if (isJRE9Plus) { + String result = "--release "+release+" --enable-preview -Xlint:-preview"; + if (additionalOptions != null) + result = result + " " + additionalOptions; + options.setCompilerOptions(result); + + } + else + throw new IllegalArgumentException("preview not supported at release "+release); + return options; + } + public static class SuppressWarnings extends JavacTestOptions { + public SuppressWarnings(String token) { + setCompilerOptions("-Xlint:-"+token); + } + } + // TODO (maxime) enable selective javac output dir manipulations between + // tests steps + // some tests manipulate the OUTPUT_DIR explicitly between run*Test calls; + // however, these manipulations are not reflected in the javac output + // directory (yet); skipping until we fix this + static final JavacTestOptions SKIP_UNTIL_FRAMEWORK_FIX = new JavacTestOptions() { + @Override + boolean skip(JavacCompiler compiler) { + return true; + } + }; + long minJavacCompliance = 0; + private String compilerOptions = ""; + public JavacTestOptions() { + } + public JavacTestOptions(String compilerOptions) { + this.compilerOptions = compilerOptions; + } + public JavacTestOptions(long compliance) { + this.minJavacCompliance = compliance; + } + String getCompilerOptions() { + return this.compilerOptions; + } + public void setCompilerOptions(String options) { + this.compilerOptions = options; + } + boolean skip(JavacCompiler compiler) { + if (this.minJavacCompliance > 0) + return compiler.compliance < this.minJavacCompliance; + return false; + } + static class MismatchType { + static final int EclipseErrorsJavacNone = 0x0001; + static final int EclipseErrorsJavacWarnings = 0x0002; + static final int JavacErrorsEclipseNone = 0x0004; + static final int JavacErrorsEclipseWarnings = 0x0008; + static final int EclipseWarningsJavacNone = 0x0010; + static final int JavacWarningsEclipseNone = 0x0020; + static final int StandardOutputMismatch = 0x0040; + static final int ErrorOutputMismatch = 0x0080; + static final int JavacAborted = 0x0100; + static final int JavacNotLaunched = 0x0200; + static final int JavaAborted = 0x0400; + static final int JavaNotLaunched = 0x0800; + static final int CompileErrorMismatch = 0x1000; + } + public static class Excuse extends JavacTestOptions { + protected int mismatchType; + public boolean isIntermittent; + Excuse(int mismatchType) { + this.mismatchType = mismatchType; + } + @Override + Excuse excuseFor(JavacCompiler compiler) { + return this; + } + public boolean clears(int mismatch) { + return this.mismatchType == 0 || (this.mismatchType & mismatch) == mismatch; // one excuse can clear multiple mismatches + } + public static Excuse + EclipseHasSomeMoreWarnings = RUN_JAVAC ? + new Excuse(MismatchType.EclipseWarningsJavacNone) : null, + EclipseWarningConfiguredAsError = RUN_JAVAC ? + new Excuse(MismatchType.EclipseErrorsJavacWarnings | MismatchType.EclipseErrorsJavacNone) : null, + JavacCompilesBogusReferencedFileAgain = RUN_JAVAC ? + new Excuse(MismatchType.EclipseErrorsJavacNone) : null, + // bugs not found on javac bug site, but points to a javac bug. + JavacDoesNotCompileCorrectSource = RUN_JAVAC ? + new JavacHasABug(MismatchType.JavacErrorsEclipseNone) : null, + /* A General Excuse - Revisit periodically */ + JavacCompilesIncorrectSource = RUN_JAVAC ? + new JavacHasABug(MismatchType.EclipseErrorsJavacNone | + MismatchType.EclipseErrorsJavacWarnings | + MismatchType.EclipseWarningsJavacNone) : null, + JavacGeneratesIncorrectCode = RUN_JAVAC ? + new JavacHasABug(MismatchType.StandardOutputMismatch) : null, + JavacHasWarningsEclipseNotConfigured = RUN_JAVAC ? + new JavacHasABug(MismatchType.JavacWarningsEclipseNone) : null, + JavacHasErrorsEclipseHasWarnings = RUN_JAVAC ? + new JavacHasABug(MismatchType.JavacErrorsEclipseWarnings) : null, + JavacHasErrorsEclipseHasNone = RUN_JAVAC ? + new JavacHasABug(MismatchType.JavacErrorsEclipseNone) : null; + } + Excuse excuseFor(JavacCompiler compiler) { + return null; + } + public static class EclipseHasABug extends Excuse { + EclipseHasABug(int mismatchType) { + super(mismatchType); + } + public static EclipseHasABug + EclipseBug159851 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159851 + new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance < ClassFileConstants.JDK1_7 ? this : null; + } + } : null, + EclipseBug177715 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=177715 + new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance < ClassFileConstants.JDK1_8 ? this : null; // in 1.8 rejected by both compilers + } + } : null, + EclipseBug207935 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 + new EclipseHasABug(MismatchType.EclipseErrorsJavacNone | MismatchType.EclipseWarningsJavacNone) : null, + EclipseBug216558 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 + new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null, + EclipseBug235550 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235550 + new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null, + EclipseBug235809 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235809 + new EclipseHasABug(MismatchType.StandardOutputMismatch) : null, + EclipseBug236217 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236217 + new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance < ClassFileConstants.JDK1_8 ? this : null; // in 1.8 accepted by both compilers + } + } : null, + EclipseBug236236 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236236 + new EclipseHasABug(MismatchType.EclipseErrorsJavacNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance > ClassFileConstants.JDK1_5 ? this : null; + } + }: null, + EclipseBug236242 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236242 + new EclipseHasABug(MismatchType.EclipseErrorsJavacWarnings) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance == ClassFileConstants.JDK1_7 ? this : null; + } + }: null, + EclipseBug236243 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236243 + new EclipseHasABug(MismatchType.EclipseErrorsJavacNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance > ClassFileConstants.JDK1_6 ? this : null; + } + }: null, + EclipseBug236379 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236379 + new EclipseHasABug(MismatchType.EclipseWarningsJavacNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance > ClassFileConstants.JDK1_5 ? null : this; + } + }: null, + EclipseBug424410 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=424410 + new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null, + EclipseBug427719 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427719 + new EclipseHasABug(MismatchType.JavacErrorsEclipseWarnings) : null, + EclipseBug421922 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421922 + new EclipseHasABug(MismatchType.EclipseErrorsJavacNone) : null, + EclipseBug428061 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=428061 + new EclipseHasABug(MismatchType.JavacErrorsEclipseNone | + MismatchType.JavacErrorsEclipseWarnings) : null, + EclipseBug510528 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=510528 + new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null, + EclipseBug531531 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=531531 + new EclipseHasABug(MismatchType.EclipseErrorsJavacNone) : null, + EclipseBug529197 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=529197 + new EclipseHasABug(MismatchType.EclipseErrorsJavacNone) : null; + } + // Justification based upon: + // - Eclipse bugs opened to investigate differences and closed as INVALID + // on grounds other than an identified javac bug; + // - Eclipse bugs that discuss the topic in depth and explain why we made a + // given choice; + // - explanations inlined here (no bug available, apparently not worth + // opening one). + public static class EclipseJustification extends Excuse { + EclipseJustification(int mismatchType) { + super(mismatchType); + } + public static final EclipseJustification + EclipseBug72704 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72704 + new EclipseJustification(MismatchType.EclipseErrorsJavacNone) : null, + EclipseBug83902 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 + new EclipseJustification(MismatchType.EclipseWarningsJavacNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance > ClassFileConstants.JDK1_5 ? this : null; + } + } : null, + EclipseBug83902b = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 + new EclipseJustification(MismatchType.JavacErrorsEclipseWarnings) : null, + EclipseBug95021 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 + new EclipseJustification(MismatchType.JavacErrorsEclipseNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance == ClassFileConstants.JDK1_7 ? this : null; + } + // WORK consider adding reversed pivots + } : null, + EclipseBug126712 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=126712 & http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6342411 + new EclipseJustification(MismatchType.StandardOutputMismatch) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance > ClassFileConstants.JDK1_5 ? this : null; + } + // WORK consider adding reversed pivots + } : null, + EclipseBug126744 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=126744 + new EclipseJustification(MismatchType.JavacErrorsEclipseNone) : null, + EclipseBug151275 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=151275 + new EclipseJustification(MismatchType.JavacErrorsEclipseNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance < ClassFileConstants.JDK1_7 ? this : null; + } + } : null, + EclipseBug159214 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 + new EclipseJustification(MismatchType.EclipseErrorsJavacNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance == ClassFileConstants.JDK1_6 ? this : null; + } + // WORK consider adding reversed pivots + } : null, + EclipseBug169017 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=169017 + new EclipseJustification(MismatchType.JavacErrorsEclipseNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance > ClassFileConstants.JDK1_5 ? this : null; + } + // WORK consider adding reversed pivots + } : null, + EclipseBug180789 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 + new EclipseJustification(MismatchType.EclipseErrorsJavacWarnings) : null, + EclipseBug218677 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=218677 + new EclipseJustification(MismatchType.EclipseErrorsJavacNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance > ClassFileConstants.JDK1_6 ? this : null; + } + // WORK consider adding reversed pivots + } : null, + EclipseBug234815 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=234815 + new EclipseJustification(MismatchType.JavacErrorsEclipseNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance < ClassFileConstants.JDK1_7 ? this : null; + } + }: null, + EclipseBug235543 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235543 + new EclipseJustification(MismatchType.EclipseErrorsJavacNone) : null, + EclipseBug235546 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235546 + new EclipseJustification(MismatchType.JavacErrorsEclipseNone) : null, + EclipseBug449063 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063 + new EclipseJustification(MismatchType.StandardOutputMismatch) : null, + EclipseBug561549 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=561549 + new EclipseJustification(MismatchType.EclipseErrorsJavacNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance > ClassFileConstants.JDK9 ? this : null; + } + } : null; + public static final EclipseJustification + EclipseJustification0001 = RUN_JAVAC ? + new EclipseJustification(MismatchType.EclipseErrorsJavacNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance < ClassFileConstants.JDK1_7 ? this : null; + } + } : null; + /* javac 1.6- properly detects duplicate attributes in annotations in the + * simplest case (AnnotationTest#18b) but fails on a slightly more + * complex one where the duplicate is within an embedded annotation; + * there seems to be no reason for not reporting the error + * (AnnotationTest#18) */ + } + public static class JavacHasABug extends Excuse { + long pivotCompliance; + int pivotMinor; + int[] minorsFixed; + static final int NO_FIX = -1; + static final int IRRELEVANT = -2; + JavacHasABug(int mismatchType) { + super(mismatchType); + } +// private JavacHasABug(int mismatchType, int[] minorsFixed) { +// super(mismatchType); +// this.minorsFixed = minorsFixed; +// } + private JavacHasABug(int mismatchType, long pivotCompliance, int pivotMinor) { + super(mismatchType); + this.pivotCompliance = pivotCompliance; + this.pivotMinor = pivotMinor; + } + public JavacHasABug(int mismatchType, long pivotCompliance, int pivotMinor, boolean intermittent) { + this(mismatchType, pivotCompliance, pivotMinor); + this.isIntermittent = intermittent; + } + @Override + Excuse excuseFor(JavacCompiler compiler) { + if (this.minorsFixed != null) { + if (compiler.compliance == ClassFileConstants.JDK1_8) { + return this.minorsFixed[5] > compiler.minor || this.minorsFixed[5] < 0 ? + this : null; + } else if (compiler.compliance == ClassFileConstants.JDK1_7) { + return this.minorsFixed[4] > compiler.minor || this.minorsFixed[4] < 0 ? + this : null; + } else if (compiler.compliance == ClassFileConstants.JDK1_6) { + return this.minorsFixed[3] > compiler.minor || this.minorsFixed[3] < 0 ? + this : null; + } else if (compiler.compliance == ClassFileConstants.JDK1_5) { + return this.minorsFixed[2] > compiler.minor || this.minorsFixed[2] < 0 ? + this : null; + } else if (compiler.compliance == ClassFileConstants.JDK1_4) { + return this.minorsFixed[1] > compiler.minor || this.minorsFixed[1] < 0 ? + this : null; + } else if (compiler.compliance == ClassFileConstants.JDK1_3) { + return this.minorsFixed[0] > compiler.minor || this.minorsFixed[0] < 0 ? + this : null; + } + throw new RuntimeException(); // should not get there + } else if (this.pivotCompliance > 0) { + if (this.pivotCompliance < compiler.compliance) { + return null; + } else if (this.pivotCompliance > compiler.compliance) { + return this; + } else { + return this.pivotMinor > compiler.minor ? this : null; + } + } else if (this.pivotCompliance < 0) { + if (this.pivotCompliance < -compiler.compliance) { + return null; + } else if (this.pivotCompliance > -compiler.compliance) { + return this; + } else { + return this.pivotMinor <= compiler.minor ? this : null; + } + } + return this; + } + // bugs that we know precisely of + public static JavacHasABug + JavacBug4094180 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4094180 + new JavacHasABug(MismatchType.EclipseErrorsJavacNone) : null, + JavacBug4660984 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4660984 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=235555 + new JavacHasABug(MismatchType.JavacErrorsEclipseNone) : null, + JavacBug5042462 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5042462 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 + new JavacHasABug( + MismatchType.JavacErrorsEclipseNone, + ClassFileConstants.JDK1_7, 0 /* 1.7.0 b17 */) : null, + JavacBug5061359 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5061359 + new JavacHasABug( + MismatchType.EclipseErrorsJavacNone, + ClassFileConstants.JDK1_7, 0 /* 1.7.0 b03 */) : null, + JavacBug6302954 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=98379 + new JavacHasABug( + MismatchType.JavacErrorsEclipseNone, + ClassFileConstants.JDK1_7, 0 /* 1.7.0 b03 */) : null, + JavacBug6400189 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6400189 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=167952 + new JavacHasABug( + MismatchType.EclipseErrorsJavacNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance == ClassFileConstants.JDK1_6 ? this : null; + } + } : null, + JavacBug6500701 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6500701 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=209779 + new JavacHasABug( + MismatchType.StandardOutputMismatch, + ClassFileConstants.JDK1_7, 0) : null, + JavacBug6531075 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6531075 + new JavacHasABug( + MismatchType.StandardOutputMismatch, + ClassFileConstants.JDK1_7, 0) : null, // fixed in jdk7 b27; unfortunately, we do not have a distinct minor for this, hence former jdk7s will report an unused excuse + JavacBug6569404 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6569404 + new JavacHasABug( + MismatchType.JavacErrorsEclipseNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + // present only in javac6 between 1.6.0_10_b08 and EOL + return (compiler.compliance == ClassFileConstants.JDK1_6 && compiler.minor >= 10) ? this : null; + } + } : null, + JavacBug6557661 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6557661 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 + new JavacHasABug( + MismatchType.EclipseErrorsJavacNone) : null, + JavacBug6573446 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6573446 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 + new JavacHasABug( + MismatchType.EclipseErrorsJavacNone) : null, + JavacBug6575821 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6575821 + new JavacHasABug( + MismatchType.JavacErrorsEclipseNone, + ClassFileConstants.JDK1_6, 10 /* 1.6.0_10_b08 or better - maybe before */) : null, + JavacBug8033810 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8033810 + new JavacHasABug(MismatchType.EclipseErrorsJavacNone) : null, + JavacBug8144673 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8144673 + new JavacHasABug(MismatchType.JavacErrorsEclipseNone, ClassFileConstants.JDK9, 0100) : null, + JavacBug8204534 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8204534 + new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK11, 0000) : null, + JavacBug8207032 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8207032 + new JavacHasABug(MismatchType.EclipseErrorsJavacNone) : null, + JavacBug8044196 = RUN_JAVAC ? // likely https://bugs.openjdk.java.net/browse/JDK-8044196, intermittently masked by https://bugs.openjdk.java.net/browse/JDK-8029161 + new JavacHasABug(MismatchType.EclipseErrorsJavacNone, ClassFileConstants.JDK9, 0000, true) : null, + JavacBug6337964 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=112433 + new JavacHasABug(MismatchType.JavacErrorsEclipseNone, ClassFileConstants.JDK1_6, 1045/*guessed*/, true) : null, + JavacBug8144832 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8144832 + new JavacHasABug(MismatchType.JavacErrorsEclipseNone, ClassFileConstants.JDK9, 0000) : null, + JavacBug8179483_switchExpression = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8179483 + new JavacBug8179483(" --release 13 --enable-preview -Xlint:-preview") : null, + JavacBug8221413_switchExpression = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8221413 + new JavacBug8221413(" --release 12 --enable-preview -Xlint:-preview") : null, + JavacBug8226510_switchExpression = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8226510 + new JavacBug8226510(" --release 12 --enable-preview -Xlint:-preview") : null, + JavacBug8231436 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8231436 to implement https://bugs.openjdk.java.net/browse/JDK-8231435 + new JavacHasABug(MismatchType.JavacErrorsEclipseNone) : null, + JavacBug8231436_EclipseWarns = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8231436 to implement https://bugs.openjdk.java.net/browse/JDK-8231435 + new JavacHasABug(MismatchType.JavacErrorsEclipseWarnings) : null; + + // bugs that have been fixed but that we've not identified + public static JavacHasABug + JavacBugFixed_6_10 = RUN_JAVAC ? + new JavacHasABug( + 0 /* all */, + ClassFileConstants.JDK1_6, 1000 /* 1.6.0_10_b08 or better - maybe before */) : null, + JavacBugFixed_6_10_b24 = RUN_JAVAC ? + new JavacHasABug( + 0 /* all */, + ClassFileConstants.JDK1_6, 1010 /* 1.6.0_10_b24 or better - maybe before */) : null, + JavacBugFixed_7 = RUN_JAVAC ? + new JavacHasABug( + 0 /* all */, + ClassFileConstants.JDK1_7, 0 /* 1.7.0_b24 or better - maybe before */) : null, + JavacBugFixed_901 = RUN_JAVAC ? + new JavacHasABug( + 0 /* all */, + ClassFileConstants.JDK9, 0100 /* 9.0.1 or better */) : null; + // bugs that have neither been fixed nor formally identified but which outcomes are obvious enough to clear any doubts + public static JavacHasABug + JavacThrowsAnException = RUN_JAVAC ? // some of these are transient - that is, depend on the system on which the test is run, aka stack overflow + new JavacHasABug( + MismatchType.JavacErrorsEclipseNone) : null, + JavacThrowsAnExceptionForJava_1_5_0_16 = RUN_JAVAC ? + new JavacHasABug( + MismatchType.JavacErrorsEclipseNone) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance != ClassFileConstants.JDK1_5 || + compiler.minor != 1600 ? null : this; + } + }: null, + JavacThrowsAnExceptionForJava_since9_EclipseWarns = RUN_JAVAC ? + new JavacHasABug( + MismatchType.JavacErrorsEclipseWarnings) { + @Override + Excuse excuseFor(JavacCompiler compiler) { + return compiler.compliance < ClassFileConstants.JDK9 ? null : this; + } + }: null; + public static JavacHasABug + NoWarningForMissingJavadocTag = RUN_JAVAC ? + new JavacHasABug(MismatchType.EclipseErrorsJavacNone) + : null, + NoWarningForDuplicateJavadocTag = RUN_JAVAC ? + new JavacHasABug(MismatchType.EclipseErrorsJavacNone) + : null; + } + public static class JavacBug8179483 extends JavacHasABug { + String extraJavacOptions; + public JavacBug8179483(String extraJavacOptions) { + super(MismatchType.EclipseErrorsJavacWarnings); + this.extraJavacOptions = extraJavacOptions; + } + @Override + String getCompilerOptions() { + return super.getCompilerOptions() + this.extraJavacOptions; + } + } + public static class JavacBug8221413 extends JavacHasABug { + String extraJavacOptions; + public JavacBug8221413(String extraJavacOptions) { + super(MismatchType.JavacErrorsEclipseNone); + this.extraJavacOptions = extraJavacOptions; + } + @Override + String getCompilerOptions() { + return super.getCompilerOptions() + this.extraJavacOptions; + } + } + public static class JavacBug8226510 extends JavacHasABug { + String extraJavacOptions; + public JavacBug8226510(String extraJavacOptions) { + super(MismatchType.EclipseErrorsJavacWarnings); + this.extraJavacOptions = extraJavacOptions; + } + @Override + String getCompilerOptions() { + return super.getCompilerOptions() + this.extraJavacOptions; + } + } +} + +// PREMATURE: Logger helps us monitor processes outputs (standard and error); +// some asynchronous mechanism is needed here since not consuming +// the streams fast enough can result into bad behaviors (as +// documented in Process); however, we could have a single worker +// take care of this + static class Logger extends Thread { + StringBuffer buffer; + InputStream inputStream; + String type; + Logger(InputStream inputStream, String type) { + this.inputStream = inputStream; + this.type = type; + this.buffer = new StringBuffer(); + } + Logger(InputStream inputStream, String type, StringBuffer buffer) { + this.inputStream = inputStream; + this.type = type; + this.buffer = buffer; + } + + @Override + public void run() { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(this.inputStream)); + String line = null; + while ((line = reader.readLine()) != null) { + this.buffer./*append(this.type).append("->").*/append(line).append("\n"); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + protected static int[] DIFF_COUNTERS = new int[3]; + protected static final String EVAL_DIRECTORY = Util.getOutputDirectory() + File.separator + "eval"; + public static int INDENT = 2; + protected static final String JAVA_NAME = + File.pathSeparatorChar == ':' ? "java" : "java.exe"; + protected static final String JAVAC_NAME = + File.pathSeparatorChar == ':' ? "javac" : "javac.exe"; + + protected static String JAVAC_OUTPUT_DIR_NAME = + Util.getOutputDirectory() + File.separator + "javac"; + static File JAVAC_OUTPUT_DIR; + protected static String javacCommandLineHeader; + protected static PrintWriter javacFullLog; + // flags errors so that any error in a test case prevents + // java execution + private static String javacFullLogFileName; + protected static String javaCommandLineHeader; + + // needed for multiple test calls within a single test method + protected static boolean javacTestErrorFlag; + + protected static String javacTestName; + + protected static IPath jdkRootDirPath; + + // list of available javac compilers, as defined by the jdk.roots + // variable, which should hold a File.pathSeparatorChar separated + // list of paths for to-be-tested JDK root directories + protected static List javacCompilers = null; + + public static final String OUTPUT_DIR = Util.getOutputDirectory() + File.separator + "regression"; + public static final String LIB_DIR = Util.getOutputDirectory() + File.separator + "lib"; + + public final static String PACKAGE_INFO_NAME = new String(TypeConstants.PACKAGE_INFO_NAME); + public final static String MODULE_INFO_NAME = new String(TypeConstants.MODULE_INFO_NAME); + + public static boolean SHIFT = false; + public static String PREVIEW_ALLOWED_LEVEL = JavaCore.latestSupportedJavaVersion(); + + protected static final String SOURCE_DIRECTORY = Util.getOutputDirectory() + File.separator + "source"; + + protected String[] classpaths; + protected boolean createdVerifier; + protected INameEnvironment javaClassLib; + protected TestVerifier verifier; + protected boolean shouldSwallowCaptureId; + public AbstractRegressionTest(String name) { + super(name); + } + protected boolean checkPreviewAllowed() { + return this.complianceLevel == ClassFileConstants.getLatestJDKLevel(); + } + protected void checkClassFile(String className, String source, String expectedOutput) throws ClassFormatException, IOException { + this.checkClassFile("", className, source, expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + protected void checkClassFile(String className, String source, String expectedOutput, int mode) throws ClassFormatException, IOException { + this.checkClassFile("", className, source, expectedOutput, mode); + } + protected void checkClassFile(String directoryName, String className, String disassembledClassName, String source, String expectedOutput, + int mode, boolean suppressConsole) throws ClassFormatException, IOException + { + compileAndDeploy(source, directoryName, className, suppressConsole); + try { + File directory = new File(EVAL_DIRECTORY, directoryName); + if (!directory.exists()) { + assertTrue(".class file not generated properly in " + directory, false); + } + File f = new File(directory, disassembledClassName + ".class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", mode); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + FileInputStream stream = null; + try { + stream = new FileInputStream(f); + ClassFileReader.read(stream, className + ".class", true); + } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) { + e.printStackTrace(); + assertTrue("ClassFormatException", false); + } catch (IOException e) { + e.printStackTrace(); + assertTrue("IOException", false); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + /* ignore */ + } + } + } + } finally { + removeTempClass(className); + } + } + + protected void checkClassFile(String directoryName, String className, String source, String expectedOutput, int mode) throws ClassFormatException, IOException { + this.checkClassFile(directoryName, className, className, source, expectedOutput, mode, false); + } + + protected ClassFileReader getInternalClassFile(String directoryName, String className, String disassembledClassName, String source) throws ClassFormatException, IOException { + compileAndDeploy(source, directoryName, className, false); + try { + File directory = new File(EVAL_DIRECTORY, directoryName); + if (!directory.exists()) { + assertTrue(".class file not generated properly in " + directory, false); + } + File f = new File(directory, disassembledClassName + ".class"); + ClassFileReader classFileReader = null; + FileInputStream stream = null; + try { + stream = new FileInputStream(f); + classFileReader = ClassFileReader.read(stream, className + ".class", true); + } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) { + e.printStackTrace(); + assertTrue("ClassFormatException", false); + } catch (IOException e) { + e.printStackTrace(); + assertTrue("IOException", false); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + /* ignore */ + } + } + } + return classFileReader; + } finally { + removeTempClass(className); + } + } + + protected void checkDisassembledClassFile(String fileName, String className, String expectedOutput) throws Exception { + this.checkDisassembledClassFile(fileName, className, expectedOutput, ClassFileBytesDisassembler.DETAILED); + } + protected void checkDisassembledClassFile(String fileName, String className, String expectedOutput, int mode) throws Exception { + File classFile = new File(fileName); + if (!classFile.exists()) { + assertTrue(".class file doesn't exist", false); + } + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(classFile); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", mode); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + index = result.indexOf(Messages.classformat_classformatexception); + if (index != -1) { + int start = Math.max(0, index - 300); + int end = index + Messages.classformat_classformatexception.length(); + fail("ClassFormatException swallowed in Disassembler:\n..." + result.substring(start, end)); + } + + FileInputStream stream = null; + try { + stream = new FileInputStream(classFile); + ClassFileReader.read(stream, className + ".class", true); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + /* ignore */ + } + } + } + } + + protected void compileAndDeploy(String source, String directoryName, String className, boolean suppressConsole) { + File directory = new File(SOURCE_DIRECTORY); + if (!directory.exists()) { + if (!directory.mkdirs()) { + System.out.println("Could not create " + SOURCE_DIRECTORY); + return; + } + } + if (directoryName != null && directoryName.length() != 0) { + directory = new File(SOURCE_DIRECTORY, directoryName); + if (!directory.exists()) { + if (!directory.mkdirs()) { + System.out.println("Could not create " + directory); + return; + } + } + } + String fileName = directory.getAbsolutePath() + File.separator + className + ".java"; + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); + writer.write(source); + writer.flush(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + StringBuffer buffer = new StringBuffer() + .append("\"") + .append(fileName) + .append("\" -d \"") + .append(EVAL_DIRECTORY); + String processAnnot = this.enableAPT ? "" : "-proc:none"; + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + buffer.append("\" -1.4 -source 1.3 -target 1.2"); + } else if (this.complianceLevel == ClassFileConstants.JDK1_5) { + buffer.append("\" -1.5"); + } else if (this.complianceLevel == ClassFileConstants.JDK1_6) { + buffer.append("\" -1.6 " + processAnnot); + } else if (this.complianceLevel == ClassFileConstants.JDK1_7) { + buffer.append("\" -1.7 " + processAnnot); + } else if (this.complianceLevel == ClassFileConstants.JDK1_8) { + buffer.append("\" -1.8 " + processAnnot); + } else if (this.complianceLevel == ClassFileConstants.JDK9) { + buffer.append("\" -9 " + processAnnot); + } else if (this.complianceLevel == ClassFileConstants.JDK10) { + buffer.append("\" -10 " + processAnnot); + } else { + int major = (int)(this.complianceLevel>>16); + buffer.append("\" -" + (major - ClassFileConstants.MAJOR_VERSION_0)); + } + if (this.complianceLevel == ClassFileConstants.getLatestJDKLevel() && this.enablePreview) + buffer.append(" --enable-preview "); + buffer + .append(" -preserveAllLocals -proceedOnError -nowarn -g -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append(SOURCE_DIRECTORY) + .append("\""); + OutputStream out = System.out; + OutputStream err = System.err; + if (suppressConsole) { + out = err = new OutputStream() { + @Override + public void write(int b) { + // silently swallow + } + }; + } + BatchCompiler.compile(buffer.toString(), new PrintWriter(out), new PrintWriter(err), null/*progress*/); + } + + /* + * Compute the problem log from given requestor and compare the result to + * the expected one. + * When there's a difference, display the expected output in the console as + * code string to allow easy copy/paste in the test to fix the failure. + * Also write test files to the console output. + * Fail if exception is non null. + */ + protected void checkCompilerLog(String[] testFiles, Requestor requestor, + String[] alternatePlatformIndependantExpectedLogs, Throwable exception) { + String computedProblemLog = Util.convertToIndependantLineDelimiter(requestor.problemLog.toString()); + if (this.shouldSwallowCaptureId) + computedProblemLog = Pattern.compile("capture#(\\d+)").matcher(computedProblemLog).replaceAll("capture"); + + ProblemLog problemLog = new ProblemLog(computedProblemLog); + int i; + for (i = 0; i < alternatePlatformIndependantExpectedLogs.length; i++) { + if (problemLog.sameAs(alternatePlatformIndependantExpectedLogs[i])) + return; // OK + } + logTestTitle(); + System.out.println(Util.displayString(computedProblemLog, INDENT, SHIFT)); + logTestFiles(false, testFiles); + if (exception == null) { + assertEquals("Invalid problem log ", alternatePlatformIndependantExpectedLogs[i-1], computedProblemLog); + } + } + + /** + * Used for performing order-independent log comparisons. + */ + private static final class ProblemLog { + final Set logEntry = new HashSet<>(); + + public ProblemLog(String log) { + String[] entries = log.split("----------\n"); + Pattern pattern = Pattern.compile("\\A(\\d*\\. )"); + + for (String entry : entries) { + Matcher matcher = pattern.matcher(entry); + if (matcher.find()) { + entry = entry.substring(matcher.end()); + } + this.logEntry.add(entry); + } + } + + public boolean sameAs(String toTest) { + ProblemLog log = new ProblemLog(toTest); + return equals(log); + } + + @Override + public int hashCode() { + return this.logEntry.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ProblemLog other = (ProblemLog) obj; + return this.logEntry.equals(other.logEntry); + } + } + + protected void dualPrintln(String message) { + System.out.println(message); + javacFullLog.println(message); + } + protected void executeClass( + String sourceFile, + String expectedSuccessOutputString, + String[] classLib, + boolean shouldFlushOutputDirectory, + String[] vmArguments, + Map customOptions, + ICompilerRequestor clientRequestor) { + + // Compute class name by removing ".java" and replacing slashes with dots + String className = sourceFile.substring(0, sourceFile.lastIndexOf('.')).replace('/', '.').replace('\\', '.'); + if (className.endsWith(PACKAGE_INFO_NAME)) return; + + if (vmArguments != null) { + if (this.verifier != null) { + this.verifier.shutDown(); + } + this.verifier = new TestVerifier(false); + this.createdVerifier = true; + } + boolean passed = + this.verifier.verifyClassFiles( + sourceFile, + className, + expectedSuccessOutputString, + this.classpaths, + null, + vmArguments); + assertTrue(this.verifier.failureReason, // computed by verifyClassFiles(...) action + passed); + if (vmArguments != null) { + if (this.verifier != null) { + this.verifier.shutDown(); + } + this.verifier = new TestVerifier(false); + this.createdVerifier = true; + } + } + + /* + * Returns the references in the given .class file. + */ + protected String findReferences(String classFilePath) { + // check that "new Z().init()" is bound to "AbstractB.init()" + final StringBuilder references = new StringBuilder(10); + final SearchParticipant participant = new JavaSearchParticipant() { + final SearchParticipant searchParticipant = this; + public SearchDocument getDocument(final String documentPath) { + return new SearchDocument(documentPath, this.searchParticipant) { + public byte[] getByteContents() { + try { + return org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(getPath())); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + public char[] getCharContents() { + // not used + return null; + } + public String getEncoding() { + // not used + return null; + } + }; + } + }; + SearchDocument document = participant.getDocument(new File(classFilePath).getPath()); + BinaryIndexer indexer = new BinaryIndexer(document) { + protected void addIndexEntry(char[] category, char[] key) { + references.append(category); + references.append('/'); + references.append(key); + references.append('\n'); + } + }; + indexer.indexDocument(); + String computedReferences = references.toString(); + return computedReferences; + } + + protected ClassFileReader getClassFileReader(String fileName, String className) { + File classFile = new File(fileName); + if (!classFile.exists()) { + assertTrue(".class file doesn't exist", false); + } + FileInputStream stream = null; + try { + stream = new FileInputStream(classFile); + ClassFileReader reader = ClassFileReader.read(stream, className + ".class", true); + return reader; + } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) { + e.printStackTrace(); + assertTrue("ClassFormatException", false); + } catch (IOException e) { + e.printStackTrace(); + assertTrue("IOException", false); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + /* ignore */ + } + } + } + return null; + } + + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths, Map options) { + if (options == null) + options = getCompilerOptions(); + String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + if ("".equals(encoding)) + encoding = null; + String release = null; + if (CompilerOptions.ENABLED.equals(options.get(CompilerOptions.OPTION_Release))) { + release = getCompilerOptions().get(CompilerOptions.OPTION_Compliance); + } + if (useDefaultClasspaths && encoding == null) + return DefaultJavaRuntimeEnvironment.create(this.classpaths, release); + // fall back to FileSystem + INameEnvironment[] classLibs = new INameEnvironment[1]; + classLibs[0] = new FileSystem(this.classpaths, new String[]{}, // ignore initial file names + encoding, release + ); + return classLibs; + } + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { + return getClassLibs(useDefaultClasspaths, null); + } + @Override + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + defaultOptions.put(CompilerOptions.OPTION_ReportUnnecessaryElse, CompilerOptions.WARNING ); + defaultOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.WARNING); + return defaultOptions; + } + protected boolean isMinimumCompliant(long compliance) { + Map options = getCompilerOptions(); + CompilerOptions compOptions = new CompilerOptions(options); + return compOptions.complianceLevel >= compliance; + } + + protected void enableAllWarningsForIrritants(Map options, IrritantSet irritants) { + int[] bits = irritants.getBits(); + for (int i = 0; i < bits.length; i++) { + int bit = bits[i]; + for (int b = 0; b < IrritantSet.GROUP_SHIFT; b++) { + int single = bit & (1 << b); + if (single != 0) { + single |= (i< limitModules) { + super(Util.getJavaClassLibs(), new String[0], null, limitModules); + } + } + /* + * Will consider first the source units passed as arguments, then investigate the classpath: jdklib + output dir + */ + protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths, Map options) { + this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths; + return new InMemoryNameEnvironment(testFiles, getClassLibs((classPaths == null), options)); + } + protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths) { + return getNameEnvironment(testFiles, classPaths, null); + } + protected IProblemFactory getProblemFactory() { + return new DefaultProblemFactory(Locale.getDefault()); + } + // overridden in AbstractRegressionTests9 + protected CompilationUnit[] getCompilationUnits(String[] testFiles) { + return Util.compilationUnits(testFiles); + } + + @Override + public void initialize(CompilerTestSetup setUp) { + super.initialize(setUp); + if (setUp instanceof RegressionTestSetup) { + RegressionTestSetup regressionTestSetUp = (RegressionTestSetup)setUp; + this.javaClassLib = regressionTestSetUp.javaClassLib; + this.verifier = regressionTestSetUp.verifier; + } + } + + void logTestFiles(boolean logTitle, String[] testFiles) { + if (logTitle) { + logTestTitle(); + } + for (int i = 0; i < testFiles.length; i += 2) { + System.out.print(testFiles[i]); + System.out.println(" ["); //$NON-NLS-1$ + String content = testFiles[i + 1]; + if (content.length() > 10000) { + System.out.println(content.substring(0, 10000)); + System.out.println("...(truncated)"); //$NON-NLS-1$ + } else { + System.out.println(content); + } + System.out.println("]"); //$NON-NLS-1$ + } + } + void logTestTitle() { + System.out.println(getClass().getName() + '#' + getName()); + } + + /* + * Write given source test files in current output sub-directory. + * Use test name for this sub-directory name (ie. test001, test002, etc...) + */ + protected void printFiles(String[] testFiles) { + for (int i=0, length=testFiles.length; i 10000) { + System.out.println(content.substring(0, 10000)); + System.out.println("...(truncated)"); //$NON-NLS-1$ + } else { + System.out.println(content); + } + } + System.out.println(""); + } + protected void printJavacResultsSummary() { + if (RUN_JAVAC) { + Integer count = (Integer)TESTS_COUNTERS.get(CURRENT_CLASS_NAME); + if (count != null) { + int newCount = count.intValue()-1; + TESTS_COUNTERS.put(CURRENT_CLASS_NAME, Integer.valueOf(newCount)); + if (newCount == 0) { + if (DIFF_COUNTERS[0]!=0 || DIFF_COUNTERS[1]!=0 || DIFF_COUNTERS[2]!=0) { + dualPrintln("==========================================================================="); + dualPrintln("Results summary:"); + } + if (DIFF_COUNTERS[0]!=0) + dualPrintln(" - "+DIFF_COUNTERS[0]+" test(s) where Javac found errors/warnings but Eclipse did not"); + if (DIFF_COUNTERS[1]!=0) + dualPrintln(" - "+DIFF_COUNTERS[1]+" test(s) where Eclipse found errors/warnings but Javac did not"); + if (DIFF_COUNTERS[2]!=0) + dualPrintln(" - "+DIFF_COUNTERS[2]+" test(s) where Eclipse and Javac did not have same output"); + System.out.println("\n"); + } + } + dualPrintln("\n\nFull results sent to " + javacFullLogFileName); + javacFullLog.flush(); + } + } + protected void removeTempClass(String className) { + File dir = new File(SOURCE_DIRECTORY); + String[] fileNames = dir.list(); + if (fileNames != null) { + for (int i = 0, max = fileNames.length; i < max; i++) { + if (fileNames[i].indexOf(className) != -1) { + Util.delete(SOURCE_DIRECTORY + File.separator + fileNames[i]); + } + } + } + + dir = new File(EVAL_DIRECTORY); + fileNames = dir.list(); + if (fileNames != null) { + for (int i = 0, max = fileNames.length; i < max; i++) { + if (fileNames[i].indexOf(className) != -1) { + Util.delete(EVAL_DIRECTORY + File.separator + fileNames[i]); + } + } + } + + } + +// WORK replace null logs (no test) by empty string in most situations (more +// complete coverage) and see what happens + protected void runConformTest(String[] testFiles) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + null /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + null /* do not check compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.DEFAULT /* default javac test options */); + } + + // WORK replace null logs (no test) by empty string in most situations (more + // complete coverage) and see what happens + protected void runConformTest(String[] testFiles, ASTVisitor visitor) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + new String[] {}, + // compiler options + null /* no class libraries */, + false, + null /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + null /* do not check compiler log */, + null /* no alternate compiler logs */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + visitor, + // javac options + null /* do not check javac output string */, + JavacTestOptions.DEFAULT /* default javac test options */); + } + + protected void runConformTest(String[] testFiles, String expectedOutputString) { + runConformTest(false, JavacTestOptions.DEFAULT, testFiles, expectedOutputString); + } + protected void runConformTest(boolean skipJavac, JavacTestOptions javacTestOptions, String[] testFiles, String expectedOutputString) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + null /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + null /* do not check compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + expectedOutputString /* expected output string */, + null /* do not check error string */, + // javac options + skipJavac ? JavacTestOptions.SKIP : + javacTestOptions != null ? javacTestOptions : JavacTestOptions.DEFAULT /* default javac test options */); + } + protected void runConformTest(String[] testFiles, Map customOptions) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + customOptions /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + null /* do not check compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.DEFAULT /* default javac test options */); + } + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { + runConformTest(testFiles, expectedOutput, customOptions, null); + } + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions, String[] vmArguments, Charset charset) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + customOptions /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + null /* do not check compiler log */, + // runtime options + false /* do not force execution */, + vmArguments /* no vm arguments */, + // runtime results + expectedOutput /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.DEFAULT /* default javac test options */, + charset); + } + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions, String[] vmArguments, JavacTestOptions javacOptions) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + customOptions /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + null /* do not check compiler log */, + // runtime options + false /* do not force execution */, + vmArguments /* no vm arguments */, + // runtime results + expectedOutput /* expected output string */, + null /* do not check error string */, + // javac options + javacOptions); + } + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions, String[] vmArguments) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + customOptions /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + null /* do not check compiler log */, + // runtime options + false /* do not force execution */, + vmArguments /* no vm arguments */, + // runtime results + expectedOutput /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.DEFAULT /* default javac test options */); + } + protected void runConformTest( + String[] testFiles, + String[] dependantFiles, + String expectedSuccessOutputString) { + runTest( + true, + testFiles, + dependantFiles, + null, + false, + null, + false, + null, + false, + null, + null, + false, + null, + expectedSuccessOutputString, + null, + null, + expectedSuccessOutputString, + JavacTestOptions.DEFAULT, + Charset.defaultCharset()); + } + + protected void runConformTest( + String[] testFiles, + String expectedOutputString, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + String[] vmArguments) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + null /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + null /* do not check compiler log */, + // runtime options + false /* do not force execution */, + vmArguments /* vm arguments */, + // runtime results + expectedOutputString /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.DEFAULT /* default javac test options */); + } + + protected void runConformTest( + String[] testFiles, + String expectedOutputString, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + String[] vmArguments, + Map customOptions, + ICompilerRequestor customRequestor) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false /* do not perform statements recovery */, + customRequestor /* custom requestor */, + // compiler results + false /* expecting no compiler errors */, + null /* do not check compiler log */, + // runtime options + false /* do not force execution */, + vmArguments /* vm arguments */, + // runtime results + expectedOutputString /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.DEFAULT /* default javac test options */); + } + + // WORK good candidate for elimination (8 instances) + protected void runConformTest( + String[] testFiles, + String expectedSuccessOutputString, + String[] classLib, + boolean shouldFlushOutputDirectory, + String[] vmArguments, + Map customOptions, + ICompilerRequestor clientRequestor, + boolean skipJavac) { + runConformTest( + testFiles, + expectedSuccessOutputString, + classLib, + shouldFlushOutputDirectory, + vmArguments, + customOptions, + clientRequestor, + skipJavac, + (skipJavac ? + JavacTestOptions.SKIP : + JavacTestOptions.DEFAULT)); + } + + protected void runConformTest( + String[] testFiles, + String expectedSuccessOutputString, + String[] classLib, + boolean shouldFlushOutputDirectory, + String[] vmArguments, + Map customOptions, + ICompilerRequestor clientRequestor, + boolean skipJavac, + JavacTestOptions javacTestOptions) { + runTest( + shouldFlushOutputDirectory, + testFiles, + classLib, + customOptions, + false /* do not perform statements recovery */, + clientRequestor, + false, + null, + false, + vmArguments, + expectedSuccessOutputString, + null, + javacTestOptions); + } + + protected static void javacUsePathOption(String option) { + if (AbstractRegressionTest.javacCompilers != null) { + for (JavacCompiler compiler : AbstractRegressionTest.javacCompilers) { + compiler.usePathOption(option); + } + } + } + + /* + * Run Sun compilation using javac. + * Launch compilation in a thread and verify that it does not take more than 5s + * to perform it. Otherwise abort the process and log in console. + * TODO (maxime) not sure we really do that 5s cap any more. + * A semi verbose output is sent to the console that analyzes differences + * of behaviors between javac and Eclipse on a per test basis. A more + * verbose output is produced into a file which name is printed on the + * console. Such files can be compared between various javac releases + * to check potential changes. + * To enable such tests, specify the following VM properies in the launch + * configuration: + * -Drun.javac=enabled + * mandatory - tells the test suite to run javac tests + * -Djdk.root= + * optional - enables to find the javac that will be run by the tests + * suite; the root directory must be specified as an absolute path and + * should point to the JDK root, aka /opt/jdk1.5.0_05 for Linux or + * c:/JDK_50 for Windows; in case this property is not specified, the + * tests suite will use the runtime JRE of the launching configuration. + * Note that enabling javac tests implies running into 1.5 compliance level + * (or higher). + */ + protected void runJavac( + String[] testFiles, + final String expectedProblemLog, + final String expectedSuccessOutputString, + boolean shouldFlushOutputDirectory) { + String testName = null; + Process compileProcess = null; + Process execProcess = null; + try { + // Init test name + testName = testName(); + + // Cleanup javac output dir if needed + File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR_NAME); + if (shouldFlushOutputDirectory) { + Util.delete(javacOutputDirectory); + } + + // Write files in dir + writeFiles(testFiles); + + // Prepare command line + StringBuilder cmdLine = new StringBuilder(javacCommandLineHeader); + // compute extra classpath + String[] classpath = Util.concatWithClassLibs(JAVAC_OUTPUT_DIR_NAME, false); + StringBuilder cp = new StringBuilder(" -classpath "); + int length = classpath.length; + for (int i = 0; i < length; i++) { + if (i > 0) + cp.append(File.pathSeparatorChar); + if (classpath[i].indexOf(" ") != -1) { + cp.append("\"" + classpath[i] + "\""); + } else { + cp.append(classpath[i]); + } + } + cmdLine.append(cp); + // add source files + for (int i = 0; i < testFiles.length; i += 2) { + // *.java is not enough (p1/X.java, p2/Y.java) + cmdLine.append(' '); + cmdLine.append(testFiles[i]); + } + + // Launch process + compileProcess = Runtime.getRuntime().exec( + cmdLine.toString(), env, this.outputTestDirectory); + + // Log errors + Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR"); + + // Log output + Logger outputLogger = new Logger(compileProcess.getInputStream(), "OUTPUT"); + + // start the threads to run outputs (standard/error) + errorLogger.start(); + outputLogger.start(); + + // Wait for end of process + int exitValue = compileProcess.waitFor(); + errorLogger.join(); // make sure we get the whole output + outputLogger.join(); + + // Report raw javac results + if (! testName.equals(javacTestName)) { + javacTestName = testName; + javacTestErrorFlag = false; + javacFullLog.println("-----------------------------------------------------------------"); + javacFullLog.println(CURRENT_CLASS_NAME + " " + testName); + } + if (exitValue != 0) { + javacTestErrorFlag = true; + } + if (errorLogger.buffer.length() > 0) { + javacFullLog.println("--- javac err: ---"); + javacFullLog.println(errorLogger.buffer.toString()); + } + if (outputLogger.buffer.length() > 0) { + javacFullLog.println("--- javac out: ---"); + javacFullLog.println(outputLogger.buffer.toString()); + } + + // Compare compilation results + if (expectedProblemLog == null || expectedProblemLog.length() == 0) { + // Eclipse found no error and no warning + if (exitValue != 0) { + // Javac found errors + System.out.println("----------------------------------------"); + System.out.println(testName + " - Javac has found error(s) but Eclipse expects conform result:\n"); + javacFullLog.println("JAVAC_MISMATCH: Javac has found error(s) but Eclipse expects conform result"); + System.out.println(errorLogger.buffer.toString()); + printFiles(testFiles); + DIFF_COUNTERS[0]++; + } + else { + // Javac found no error - may have found warnings + if (errorLogger.buffer.length() > 0) { + System.out.println("----------------------------------------"); + System.out.println(testName + " - Javac has found warning(s) but Eclipse expects conform result:\n"); + javacFullLog.println("JAVAC_MISMATCH: Javac has found warning(s) but Eclipse expects conform result"); + System.out.println(errorLogger.buffer.toString()); + printFiles(testFiles); + DIFF_COUNTERS[0]++; + } + if (expectedSuccessOutputString != null && !javacTestErrorFlag) { + // Neither Eclipse nor Javac found errors, and we have a runtime + // bench value + StringBuilder javaCmdLine = new StringBuilder(javaCommandLineHeader); + javaCmdLine.append(cp); + javaCmdLine.append(' ').append(testFiles[0].substring(0, testFiles[0].indexOf('.'))); + // assume executable class is name of first test file - PREMATURE check if this is also the case in other test fwk classes + execProcess = Runtime.getRuntime().exec(javaCmdLine.toString(), env, this.outputTestDirectory); + Logger logger = new Logger(execProcess.getInputStream(), ""); + // PREMATURE implement consistent error policy + logger.start(); + exitValue = execProcess.waitFor(); + logger.join(); // make sure we get the whole output + String javaOutput = logger.buffer.toString().trim(); + if (!expectedSuccessOutputString.equals(javaOutput)) { + System.out.println("----------------------------------------"); + System.out.println(testName + " - Javac and Eclipse runtime output is not the same:"); + javacFullLog.println("JAVAC_MISMATCH: Javac and Eclipse runtime output is not the same"); + dualPrintln("eclipse:"); + dualPrintln(expectedSuccessOutputString); + dualPrintln("javac:"); + dualPrintln(javaOutput); + System.out.println("\n"); + printFiles(testFiles); // PREMATURE consider printing files to the log as well + DIFF_COUNTERS[2]++; + } + } + } + } + else { + // Eclipse found errors or warnings + if (errorLogger.buffer.length() == 0) { + System.out.println("----------------------------------------"); + System.out.println(testName + " - Eclipse has found error(s)/warning(s) but Javac did not find any:"); + javacFullLog.println("JAVAC_MISMATCH: Eclipse has found error(s)/warning(s) but Javac did not find any"); + dualPrintln("eclipse:"); + dualPrintln(expectedProblemLog); + printFiles(testFiles); + DIFF_COUNTERS[1]++; + } else if (expectedProblemLog.indexOf("ERROR") > 0 && exitValue == 0){ + System.out.println("----------------------------------------"); + System.out.println(testName + " - Eclipse has found error(s) but Javac only found warning(s):"); + javacFullLog.println("JAVAC_MISMATCH: Eclipse has found error(s) but Javac only found warning(s)"); + dualPrintln("eclipse:"); + dualPrintln(expectedProblemLog); + System.out.println("javac:"); + System.out.println(errorLogger.buffer.toString()); + printFiles(testFiles); + DIFF_COUNTERS[1]++; + } else { + // PREMATURE refine comparison + // TODO (frederic) compare warnings in each result and verify they are similar... +// System.out.println(testName+": javac has found warnings :"); +// System.out.print(errorLogger.buffer.toString()); +// System.out.println(testName+": we're expecting warning results:"); +// System.out.println(expectedProblemLog); + } + } + } + catch (InterruptedException e1) { + if (compileProcess != null) compileProcess.destroy(); + if (execProcess != null) execProcess.destroy(); + System.out.println(testName+": Sun javac compilation was aborted!"); + javacFullLog.println("JAVAC_WARNING: Sun javac compilation was aborted!"); + e1.printStackTrace(javacFullLog); + } + catch (Throwable e) { + System.out.println(testName+": could not launch Sun javac compilation!"); + e.printStackTrace(); + javacFullLog.println("JAVAC_ERROR: could not launch Sun javac compilation!"); + e.printStackTrace(javacFullLog); + // PREMATURE failing the javac pass or comparison could also fail + // the test itself + } + finally { + // Clean up written file(s) + Util.delete(this.outputTestDirectory); + } + } + // WORK factorize all runJavac implementations, including overrides + protected boolean runJavac(String options, String[] testFileNames, String currentDirectoryPath) { + Process compileProcess = null; + try { + // Prepare command line + StringBuilder cmdLine = new StringBuilder(javacCommandLineHeader); + cmdLine.append(' '); + cmdLine.append(options); + // add source files + for (int i = 0; i < testFileNames.length; i ++) { + // *.java is not enough (p1/X.java, p2/Y.java) + cmdLine.append(' '); + cmdLine.append(testFileNames[i]); + } + // Launch process + File currentDirectory = new File(currentDirectoryPath); + compileProcess = Runtime.getRuntime().exec( + cmdLine.toString(), env, currentDirectory); + + // Log errors + Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR"); + errorLogger.start(); + + // Wait for end of process + int exitValue = compileProcess.waitFor(); + errorLogger.join(); // make sure we get the whole output + + // Check results + if (exitValue != 0) { + return false; + } + if (errorLogger.buffer.length() > 0) { + System.err.println("--- javac err: ---"); + System.err.println(errorLogger.buffer.toString()); + return false; + } + } + catch (Throwable e) { + e.printStackTrace(System.err); + } + finally { + if (compileProcess != null) { + compileProcess.destroy(); // closes process streams + } + } + return true; + } +/* + * Run Sun compilation using one or more versions of javac. Compare the + * results to expected ones, raising mismatches as needed. + * To enable such tests, specify the following VM properies in the launch + * configuration: + * -Drun.javac=enabled + * mandatory - tells the test suite to run javac tests + * -Djdk.roots= + * optional - enables to find the versions of javac that will be run by + * the tests suite; the root directories must be specified as a + * File.pathSeparator separated list of absolute paths which should + * point each to a JDK root, aka /opt/jdk1.5.0_05 for Linux or + * c:/JDK_50 for Windows; in case this property is not specified, the + * tests suite will use the runtime JRE of the launching configuration. + * Note that enabling javac tests implies running into 1.5 compliance level + * (or higher). + */ +// WORK unify use of output, error, log, etc... +protected void runJavac( + String[] testFiles, + boolean expectingCompilerErrors, + String expectedCompilerLog, + String expectedOutputString, + String expectedErrorString, + boolean shouldFlushOutputDirectory, + JavacTestOptions options, + String[] vmArguments, + String[] classLibraries, + boolean libsOnModulePath) { + // WORK we're probably doing too much around class libraries in general - java should be able to fetch its own runtime libs + // WORK reorder parameters + if (options == JavacTestOptions.SKIP) { + return; + } + if (options == null) { + options = JavacTestOptions.DEFAULT; + } + String newOptions = options.getCompilerOptions(); + if (newOptions.indexOf(" -d ") < 0) { + newOptions = newOptions.concat(" -d ."); + } + if (newOptions.indexOf(" -Xlint") < 0) { + newOptions = newOptions.concat(" -Xlint"); + } + if (newOptions.indexOf(" -implicit") < 0) { + newOptions = newOptions.concat(" -implicit:none"); + } + if (classLibraries != null) { + List filteredLibs = new ArrayList<>(); + for (String lib : classLibraries) { + if (!lib.startsWith(jdkRootDirPath.toString())) // this can fail if jdkRootDirPath is a symlink + filteredLibs.add(lib); + } + if (!filteredLibs.isEmpty()) { + newOptions = newOptions + .concat(libsOnModulePath ? " --module-path " : " -classpath ") + .concat(String.join(File.pathSeparator, filteredLibs.toArray(new String[filteredLibs.size()]))); + } + } + String testName = testName(); + Iterator compilers = javacCompilers.iterator(); + while (compilers.hasNext()) { + JavacCompiler compiler = compilers.next(); + if (!options.skip(compiler) && compiler.compliance == this.complianceLevel) { + // WORK this may exclude some compilers under some conditions (when + // complianceLevel is not set); consider accepting the compiler + // in such case and see what happens + JavacTestOptions.Excuse excuse = options.excuseFor(compiler); + StringBuffer compilerLog = new StringBuffer(); + File javacOutputDirectory = null; + int mismatch = 0; + String sourceFileNames[] = null; + try { + // cleanup javac output dir if needed + javacOutputDirectory = new File(JAVAC_OUTPUT_DIR_NAME + + File.separator + compiler.rawVersion); // need to change output directory per javac version + if (shouldFlushOutputDirectory) { + Util.delete(javacOutputDirectory); + } else { + deleteSourceFiles(javacOutputDirectory); + } + javacOutputDirectory.mkdirs(); + // write test files + for (int i = 0, length = testFiles.length; i < length; ) { + String fileName = testFiles[i++]; + String contents = testFiles[i++]; + fileName = expandFileNameForJavac(fileName); + File file = new File(javacOutputDirectory, fileName); + if (fileName.lastIndexOf('/') >= 0) { + File dir = file.getParentFile(); + if (!dir.exists()) { + dir.mkdirs(); + } + } + Util.writeToFile(contents, file.getPath()); + } + // compute source file names + int testFilesLength = testFiles.length; + sourceFileNames = new String[testFilesLength / 2]; + for (int i = 0, j = 0; i < testFilesLength; i += 2, j++) { + sourceFileNames[j] = expandFileNameForJavac(testFiles[i]); + } + + // compile + long compilerResult = compiler.compile(javacOutputDirectory, newOptions /* options */, sourceFileNames, compilerLog); + // check cumulative javac results + // WORK need to use a per compiler approach + if (! testName.equals(javacTestName)) { + javacTestName = testName; + javacTestErrorFlag = false; + } + if ((compilerResult & JavacCompiler.EXIT_VALUE_MASK) != 0) { + javacTestErrorFlag = true; + } + // compare compilation results + if (expectingCompilerErrors) { + if ((compilerResult & JavacCompiler.EXIT_VALUE_MASK) == 0) { + if ((compilerResult & JavacCompiler.ERROR_LOG_MASK) == 0) { + mismatch = JavacTestOptions.MismatchType.EclipseErrorsJavacNone; + } else { + mismatch = JavacTestOptions.MismatchType.EclipseErrorsJavacWarnings; + } + } + } else { + if ((compilerResult & JavacCompiler.EXIT_VALUE_MASK) != 0) { + if (expectedCompilerLog != null /* null skips warnings test */ && expectedCompilerLog.length() > 0) { + mismatch = JavacTestOptions.MismatchType.JavacErrorsEclipseWarnings; + } else { + mismatch = JavacTestOptions.MismatchType.JavacErrorsEclipseNone; + } + } else if (expectedCompilerLog != null /* null skips warnings test */) { + if (expectedCompilerLog.length() > 0 && (compilerResult & JavacCompiler.ERROR_LOG_MASK) == 0) { + mismatch = JavacTestOptions.MismatchType.EclipseWarningsJavacNone; + } else if (expectedCompilerLog.length() == 0 && (compilerResult & JavacCompiler.ERROR_LOG_MASK) != 0) { + mismatch = JavacTestOptions.MismatchType.JavacWarningsEclipseNone; + } + } + } + } + catch (InterruptedException e1) { + e1.printStackTrace(); + mismatch = JavacTestOptions.MismatchType.JavacAborted; + } + catch (Throwable e) { + e.printStackTrace(); + mismatch = JavacTestOptions.MismatchType.JavacNotLaunched; + } + String output = null; + String err = null; + try { + String className = testFiles[0].substring(0, testFiles[0].lastIndexOf('.')); + if ((expectedOutputString != null || expectedErrorString != null) && + !javacTestErrorFlag && mismatch == 0 && sourceFileNames != null && + !className.endsWith(PACKAGE_INFO_NAME) && !className.endsWith(MODULE_INFO_NAME)) { + JavaRuntime runtime = JavaRuntime.fromCurrentVM(); + StringBuffer stderr = new StringBuffer(); + StringBuffer stdout = new StringBuffer(); + String vmOptions = ""; + if (vmArguments != null) { + int l = vmArguments.length; + if (l > 0) { + StringBuffer buffer = new StringBuffer(vmArguments[0]); + for (int i = 1; i < l; i++) { + buffer.append(' '); + buffer.append(vmArguments[i]); + } + vmOptions = buffer.toString(); + } + } + runtime.execute(javacOutputDirectory, vmOptions, className, stdout, stderr); + if (expectedOutputString != null /* null skips output test */) { + output = stdout.toString().trim(); + if (!expectedOutputString.equals(output)) { + mismatch = JavacTestOptions.MismatchType.StandardOutputMismatch; + } + } + // WORK move to a logic in which if stdout is empty whereas + // it should have had contents, stderr is leveraged as + // potentially holding indications regarding the failure + if (expectedErrorString != null /* null skips error test */ && mismatch == 0) { + err = adjustErrorOutput(stderr.toString().trim()); + if (!errorStringMatch(expectedErrorString, err)) { + mismatch = JavacTestOptions.MismatchType.ErrorOutputMismatch; + } + } + } + } + catch (InterruptedException e1) { + e1.printStackTrace(); + mismatch = JavacTestOptions.MismatchType.JavaAborted; + } + catch (Throwable e) { + e.printStackTrace(); + mismatch = JavacTestOptions.MismatchType.JavaNotLaunched; + } + handleMismatch(compiler, testName, testFiles, expectedCompilerLog, expectedOutputString, + expectedErrorString, compilerLog, output, err, excuse, mismatch); + } + } +} +private void deleteSourceFiles(File directory) { + try { + if (!directory.exists()) + return; + Files.walk(directory.toPath()) + .filter(f -> f.toString().endsWith(SuffixConstants.SUFFIX_STRING_java)) + .map(java.nio.file.Path::toFile) + .filter(File::isFile) + .forEach(File::delete); + } catch (IOException e) { + e.printStackTrace(); + } +} +private boolean errorStringMatch(String expectedErrorStringStart, String actualError) { + /* + * From TestVerifier.checkBuffers(): + * This is an opportunistic heuristic for error strings comparison: + * - null means skip test; + * - empty means exactly empty; + * - other means starts with. + * If this became insufficient, we could envision using specific + * matchers for specific needs. + */ + if (expectedErrorStringStart == null) + return true; + // special case: command-line java does not like missing main methods ... + if (actualError.indexOf("java.lang.NoSuchMethodError: main") != -1 + || actualError.indexOf("Error: Main method not found in class") != -1) + return true; // ... ignore this. + if (expectedErrorStringStart.length() == 0) + return expectedErrorStringStart.equals(actualError); + if (actualError.startsWith(expectedErrorStringStart)) + return true; + return false; +} +/** Hook for AbstractRegressionTest9 */ +protected String expandFileNameForJavac(String fileName) { + return fileName; +} +void handleMismatch(JavacCompiler compiler, String testName, String[] testFiles, String expectedCompilerLog, + String expectedOutputString, String expectedErrorString, StringBuffer compilerLog, String output, String err, + JavacTestOptions.Excuse excuse, int mismatch) { + if (mismatch != 0) { + if (excuse != null && excuse.clears(mismatch)) { + excuse = null; + } else { + System.err.println("----------------------------------------"); + logTestFiles(true, testFiles); + switch (mismatch) { + case JavacTestOptions.MismatchType.EclipseErrorsJavacNone: + assertEquals(testName + " - Eclipse found error(s) but Javac did not find any", + "", expectedCompilerLog.toString()); + break; + case JavacTestOptions.MismatchType.EclipseErrorsJavacWarnings: + assertEquals(testName + " - Eclipse found error(s) but Javac only found warning(s)", + expectedCompilerLog.toString(), compilerLog.toString()); + break; + case JavacTestOptions.MismatchType.JavacErrorsEclipseNone: + assertEquals(testName + " - Javac found error(s) but Eclipse did not find any", + "", compilerLog.toString()); + break; + case JavacTestOptions.MismatchType.JavacErrorsEclipseWarnings: + assertEquals(testName + " - Javac found error(s) but Eclipse only found warning(s)", + expectedCompilerLog.toString(), compilerLog.toString()); + break; + case JavacTestOptions.MismatchType.EclipseWarningsJavacNone: + assertEquals(testName + " - Eclipse found warning(s) but Javac did not find any", + "", expectedCompilerLog.toString()); + break; + case JavacTestOptions.MismatchType.JavacWarningsEclipseNone: + assertEquals(testName + " - Javac found warning(s) but Eclipse did not find any", + "", compilerLog.toString()); + break; + case JavacTestOptions.MismatchType.StandardOutputMismatch: + assertEquals(testName + " - Eclipse/Javac standard output mismatch", + expectedOutputString, output); + break; + case JavacTestOptions.MismatchType.ErrorOutputMismatch: + assertEquals(testName + " - Eclipse/Javac standard error mismatch", + expectedErrorString, err); + break; + case JavacTestOptions.MismatchType.JavacAborted: + case JavacTestOptions.MismatchType.JavacNotLaunched: + fail(testName + " - Javac failure"); + break; + case JavacTestOptions.MismatchType.JavaAborted: + case JavacTestOptions.MismatchType.JavaNotLaunched: + fail(testName + " - Java failure"); + break; + case JavacTestOptions.MismatchType.CompileErrorMismatch: + fail(testName + " Javac failure did not match \"" + expectedCompilerLog +'\"'); + break; + default: + throw new RuntimeException("unexpected mismatch value: " + mismatch); + } + } + } + if (excuse != null) { + if (excuse.isIntermittent) + System.err.println(testName + ": unused execuse (intermittent bug) "+excuse + " for compiler " + compiler); + else + fail(testName + ": unused excuse " + excuse + " for compiler " + compiler); + } +} + +private String adjustErrorOutput(String error) { + // VerifyTests performs an explicit e.printStackTrace() which has slightly different format + // from a stack trace written directly by a dying JVM (during javac testing), adjust if needed: + final String excPrefix = "Exception in thread \"main\" "; + if (error.startsWith(excPrefix)) + return error.substring(excPrefix.length())+'\n'; + return error; +} + +//runNegativeTest( +// // test directory preparation +// new String[] { /* test files */ +// }, +// // compiler results +// "" /* expected compiler log */); +protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) { + runNegativeTest(false/*skipJavac*/, null, testFiles, expectedCompilerLog); +} +//runNegativeTest( +// skipJavac +// javacTestOptions +//// test directory preparation +//new String[] { /* test files */ +// }, +//// compiler results +//"" /* expected compiler log */); +protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOptions, String[] testFiles, String expectedCompilerLog) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + null /* no custom options */, + false /* do not perform statements recovery */, + new Requestor( /* custom requestor */ + false, + null /* no custom requestor */, + false, + false), + // compiler results + expectedCompilerLog == null || /* expecting compiler errors */ + expectedCompilerLog.indexOf("ERROR") != -1, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + skipJavac ? JavacTestOptions.SKIP : + javacTestOptions != null ? javacTestOptions : + JavacTestOptions.DEFAULT /* default javac test options */); +} +protected void runNegativeTest(String[] testFiles, String expectedCompilerLog, boolean performStatementRecovery) { + runNegativeTest(false/*skipJavac*/, null, testFiles, expectedCompilerLog, performStatementRecovery); +} +protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOptions, String[] testFiles, String expectedCompilerLog, boolean performStatementRecovery) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + null /* no custom options */, + performStatementRecovery, + new Requestor( /* custom requestor */ + false, + null /* no custom requestor */, + false, + false), + // compiler results + expectedCompilerLog == null || /* expecting compiler errors */ + expectedCompilerLog.indexOf("ERROR") != -1, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + skipJavac ? JavacTestOptions.SKIP : + javacTestOptions != null ? javacTestOptions : + JavacTestOptions.DEFAULT /* default javac test options */); +} + // WORK potential elimination candidate (24 calls) - else clean up inline + protected void runNegativeTest( + String[] testFiles, + String expectedProblemLog, + String[] classLib, + boolean shouldFlushOutputDirectory) { + runNegativeTest(false, null, testFiles, expectedProblemLog, classLib, shouldFlushOutputDirectory); + } + protected void runNegativeTest( + boolean skipJavac, + JavacTestOptions javacTestOptions, + String[] testFiles, + String expectedProblemLog, + String[] classLib, + boolean shouldFlushOutputDirectory) { + runTest( + shouldFlushOutputDirectory, + testFiles, + classLib, + null, + false, + new Requestor( /* custom requestor */ + false, + null /* no custom requestor */, + false, + false), + // compiler results + expectedProblemLog == null || /* expecting compiler errors */ + expectedProblemLog.indexOf("ERROR") != -1, + expectedProblemLog, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + skipJavac ? JavacTestOptions.SKIP : + javacTestOptions != null ? javacTestOptions : + JavacTestOptions.DEFAULT /* javac test options */); + } + protected void runNegativeTest( + String[] testFiles, + String expectedCompilerLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + Map customOptions) { + runNegativeTest(testFiles, expectedCompilerLog, classLibraries, shouldFlushOutputDirectory, null, customOptions); + } + protected void runNegativeTest( + String[] testFiles, + String expectedCompilerLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + String[] vmArguments, + Map customOptions) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false /* do not perform statements recovery */, + new Requestor( /* custom requestor */ + false, + null /* no custom requestor */, + false, + false), + // compiler results + expectedCompilerLog == null || /* expecting compiler errors */ + expectedCompilerLog.indexOf("ERROR") != -1, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + vmArguments /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.DEFAULT /* default javac test options */); + } + protected void runNegativeTest( + boolean skipJavac, + JavacTestOptions javacTestOptions, + String[] testFiles, + String expectedCompilerLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + Map customOptions) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false /* do not perform statements recovery */, + new Requestor( /* custom requestor */ + false, + null /* no custom requestor */, + false, + false), + // compiler results + expectedCompilerLog == null || /* expecting compiler errors */ + expectedCompilerLog.indexOf("ERROR") != -1, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + skipJavac ? JavacTestOptions.SKIP : + javacTestOptions != null ? javacTestOptions : + JavacTestOptions.DEFAULT /* default javac test options */); + } + protected void runNegativeTest( + String[] testFiles, + String expectedCompilerLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + Map customOptions, + String expectedErrorString) { + runNegativeTest(testFiles, expectedCompilerLog, classLibraries, + shouldFlushOutputDirectory, customOptions, expectedErrorString, + JavacTestOptions.DEFAULT); + } + protected void runNegativeTest( + String[] testFiles, + String expectedCompilerLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + Map customOptions, + String expectedErrorString, + JavacTestOptions javacTestOptions) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false /* do not perform statements recovery */, + new Requestor( /* custom requestor */ + false, + null /* no custom requestor */, + false, + false), + // compiler results + expectedCompilerLog == null || /* expecting compiler errors */ + expectedCompilerLog.indexOf("ERROR") != -1, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + expectedErrorString /* do not check error string */, + // javac options + javacTestOptions /* default javac test options */); + } + protected void runNegativeTest( + String[] testFiles, + String expectedProblemLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + Map customOptions, + boolean generateOutput, + boolean showCategory, + boolean showWarningToken) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false, + new Requestor( /* custom requestor */ + generateOutput, + null /* no custom requestor */, + showCategory, + showWarningToken), + // compiler results + expectedProblemLog == null || /* expecting compiler errors */ + expectedProblemLog.indexOf("ERROR") != -1, + expectedProblemLog, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.DEFAULT /* javac test options */); + } + + /** + * Log contains all problems (warnings+errors) + */ + // WORK potential candidate for elimination (19 calls) + protected void runNegativeTest( + String[] testFiles, + String expectedCompilerLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + Map customOptions, + boolean generateOutput, + boolean showCategory, + boolean showWarningToken, + boolean skipJavac, + boolean performStatementsRecovery) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + performStatementsRecovery /* perform statements recovery */, + new Requestor( /* custom requestor */ + generateOutput, + null /* no custom requestor */, + showCategory, + showWarningToken), + // compiler results + expectedCompilerLog == null || /* expecting compiler errors */ + expectedCompilerLog.indexOf("ERROR") != -1, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + skipJavac ? + JavacTestOptions.SKIP : + JavacTestOptions.DEFAULT /* javac test options */); + } + protected void runNegativeTest( + String[] testFiles, + String expectedCompilerLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + Map customOptions, + boolean generateOutput, + boolean showCategory, + boolean showWarningToken, + boolean skipJavac, + JavacTestOptions javacOptions, + boolean performStatementsRecovery) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + performStatementsRecovery /* perform statements recovery */, + new Requestor( /* custom requestor */ + generateOutput, + null /* no custom requestor */, + showCategory, + showWarningToken), + // compiler results + expectedCompilerLog == null || /* expecting compiler errors */ + expectedCompilerLog.indexOf("ERROR") != -1, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + skipJavac ? + JavacTestOptions.SKIP : + javacOptions/* javac test options */); + } + public void runTest( + String[] testFiles, + boolean expectingCompilerErrors, + String expectedCompilerLog, + String expectedOutputString, + String expectedErrorString, + boolean forceExecution, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + String[] vmArguments, + Map customOptions, + ICompilerRequestor customRequestor, + boolean skipJavac) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false /* do not perform statements recovery */, + customRequestor /* custom requestor */, + // compiler results + expectingCompilerErrors /* expecting compiler errors */, + expectedCompilerLog /* expected compiler log */, + // runtime options + forceExecution /* force execution */, + vmArguments /* vm arguments */, + // runtime results + expectedOutputString /* expected output string */, + expectedErrorString /* expected error string */, + // javac options + skipJavac ? + JavacTestOptions.SKIP : + JavacTestOptions.DEFAULT /* javac test options */); + + } + + // WORK get this out + protected void runTest( + String[] testFiles, + boolean expectingCompilerErrors, + String expectedCompilerLog, + String expectedOutputString, + String expectedErrorString, + boolean forceExecution, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + String[] vmArguments, + Map customOptions, + ICompilerRequestor clientRequestor, + JavacTestOptions javacTestOptions) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false /* do not perform statements recovery */, + clientRequestor /* custom requestor */, + // compiler results + expectingCompilerErrors /* expecting compiler errors */, + expectedCompilerLog /* expected compiler log */, + // runtime options + forceExecution /* force execution */, + vmArguments /* vm arguments */, + // runtime results + expectedOutputString /* expected output string */, + expectedErrorString /* expected error string */, + // javac options + javacTestOptions /* javac test options */); + } + protected void runTest( + // test directory preparation + boolean shouldFlushOutputDirectory, + String[] testFiles, + // compiler options + String[] classLibraries, + Map customOptions, + boolean performStatementsRecovery, + ICompilerRequestor customRequestor, + // compiler results + boolean expectingCompilerErrors, + String expectedCompilerLog, + // runtime options + boolean forceExecution, + String[] vmArguments, + // runtime results + String expectedOutputString, + String expectedErrorString, + // javac options + JavacTestOptions javacTestOptions) { + runTest( + shouldFlushOutputDirectory, + testFiles, + new String[] {}, + classLibraries, + false, + customOptions, + performStatementsRecovery, + customRequestor, + expectingCompilerErrors, + expectedCompilerLog, + null, // alternate compile errors + forceExecution, + vmArguments, + expectedOutputString, + expectedErrorString, + null, + expectedOutputString, + javacTestOptions, + Charset.defaultCharset()); + } + private void runTest( + // test directory preparation + boolean shouldFlushOutputDirectory, + String[] testFiles, + // compiler options + String[] classLibraries, + Map customOptions, + boolean performStatementsRecovery, + ICompilerRequestor customRequestor, + // compiler results + boolean expectingCompilerErrors, + String expectedCompilerLog, + // runtime options + boolean forceExecution, + String[] vmArguments, + // runtime results + String expectedOutputString, + String expectedErrorString, + // javac options + JavacTestOptions javacTestOptions, + Charset charset) { + runTest( + shouldFlushOutputDirectory, + testFiles, + new String[] {}, + classLibraries, + false, + customOptions, + performStatementsRecovery, + customRequestor, + expectingCompilerErrors, + expectedCompilerLog, + null, // alternate compile errors + forceExecution, + vmArguments, + expectedOutputString, + expectedErrorString, + null, + expectedOutputString, + javacTestOptions, + charset); + } + /** Call this if the compiler randomly produces different error logs. */ + protected void runNegativeTestMultiResult(String[] testFiles, Map options, String[] alternateCompilerErrorLogs) { + runTest( + false, + testFiles, + new String[] {}, + null, + false, + options, + false, + new Requestor( /* custom requestor */ + false, + null /* no custom requestor */, + false, + false), + true, + null, + alternateCompilerErrorLogs, + false, + null, + null, + null, + null, + null, + JavacTestOptions.DEFAULT, + Charset.defaultCharset()); + } + private void runTest( + // test directory preparation + boolean shouldFlushOutputDirectory, + String[] testFiles, + String[] dependantFiles, + // compiler options + String[] classLibraries, + boolean libsOnModulePath, + Map customOptions, + boolean performStatementsRecovery, + ICompilerRequestor customRequestor, + // compiler results + boolean expectingCompilerErrors, + String expectedCompilerLog, + String[] alternateCompilerLogs, + // runtime options + boolean forceExecution, + String[] vmArguments, + // runtime results + String expectedOutputString, + String expectedErrorString, + final ASTVisitor visitor, + // javac options + String expectedJavacOutputString, + JavacTestOptions javacTestOptions) { + runTest( shouldFlushOutputDirectory, + testFiles, + dependantFiles, + classLibraries, + libsOnModulePath, + customOptions, + performStatementsRecovery, + customRequestor, + expectingCompilerErrors, + expectedCompilerLog, + alternateCompilerLogs, + forceExecution, + vmArguments, + expectedOutputString, + expectedErrorString, + visitor, + expectedJavacOutputString, + javacTestOptions, + Charset.defaultCharset()); + } +// This is a worker method to support regression tests. To ease policy changes, +// it should not be called directly, but through the runConformTest and +// runNegativeTest series. +// calling templates: +// runTest( +// // test directory preparation +// true /* flush output directory */, +// false /* do not flush output directory */, +// shouldFlushOutputDirectory /* should flush output directory */, +// +// new String[] { /* test files */ +// }, +// null /* no test files */, +// testFiles /* test files */, +// +// // compiler options +// null /* no class libraries */, +// new String[] { /* class libraries */ +// }, +// classLibraries /* class libraries */, +// +// null /* no custom options */, +// customOptions /* custom options */, +// +// true /* perform statements recovery */, +// false /* do not perform statements recovery */, +// performStatementsRecovery /* perform statements recovery */, +// +// null /* no custom requestor */, +// customRequestor /* custom requestor */, +// +// // compiler results +// false /* expecting no compiler errors */, +// true /* expecting compiler errors */, +// expectingCompilerErrors /* expecting compiler errors */, +// +// null /* do not check compiler log */, +// "" /* expected compiler log */, +// expectedCompilerLog /* expected compiler log */, +// +// // runtime options +// false /* do not force execution */, +// true /* force execution */, +// forceExecution /* force execution */, +// +// null /* no vm arguments */, +// new String[] { /* vm arguments */ +// }, +// vmArguments /* vm arguments */, +// +// // runtime results +// null /* do not check output string */, +// "" /* expected output string */, +// expectedOutputString /* expected output string */, +// +// null /* do not check error string */, +// "" /* expected error string */, +// expectedErrorString /* expected error string */, +// +// // javac options +// JavacTestOptions.SKIP /* skip javac tests */); +// JavacTestOptions.DEFAULT /* default javac test options */); +// javacTestOptions /* javac test options */); +// TODO Maxime future work: +// - reduce the number of tests that implicitly skip parts like logs +// comparisons; while this is due to eat up more time, we will gain in +// coverage (and detection of unwanted changes); of course, this will tend +// to 'over constrain' some tests, but a reasonable approach would be to +// unable the comparison for tests which just happen to be fine; +// - check the callees statistics for wrapper methods and tune them accordingly +// (aka, suppress low profile ones). +// WORK log test files in all failure cases (ez cut and paste) + private void runTest( + // test directory preparation + boolean shouldFlushOutputDirectory, + String[] testFiles, + String[] dependantFiles, + // compiler options + String[] classLibraries, + boolean libsOnModulePath, + Map customOptions, + boolean performStatementsRecovery, + ICompilerRequestor customRequestor, + // compiler results + boolean expectingCompilerErrors, + String expectedCompilerLog, + String[] alternateCompilerLogs, + // runtime options + boolean forceExecution, + String[] vmArguments, + // runtime results + String expectedOutputString, + String expectedErrorString, + final ASTVisitor visitor, + // javac options + String expectedJavacOutputString, + JavacTestOptions javacTestOptions, + Charset charset) { + // non-javac part + if (shouldFlushOutputDirectory) + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + if (testFiles != null && (testFiles.length % 2) != 0) { + fail("odd number of strings in testFiles"); + } + + Requestor requestor = + customRequestor instanceof Requestor ? + (Requestor) customRequestor : + new Requestor( + forceExecution, + customRequestor, + false, /* show category */ + false /* show warning token*/); + requestor.outputPath = OUTPUT_DIR.endsWith(File.separator) ? OUTPUT_DIR : OUTPUT_DIR + File.separator; + // WORK should not have to test a constant? + + Map options = getCompilerOptions(); + if (customOptions != null) { + options.putAll(customOptions); + } + CompilerOptions compilerOptions = new CompilerOptions(options); + compilerOptions.performMethodsFullRecovery = performStatementsRecovery; + compilerOptions.performStatementsRecovery = performStatementsRecovery; + INameEnvironment nameEnvironment = getNameEnvironment(dependantFiles, classLibraries, options); + Compiler batchCompiler = + new Compiler( + nameEnvironment, + getErrorHandlingPolicy(), + compilerOptions, + requestor, + getProblemFactory()) { + public void process(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration unit, int i) { + super.process(unit, i); + if (visitor != null) { + unit.traverse(visitor, unit.scope); + } + } + }; + /* GROOVY edit + if (this.enableAPT) { + batchCompiler.annotationProcessorManager = getAnnotationProcessorManager(batchCompiler); + } + */ + compilerOptions.produceReferenceInfo = true; + Throwable exception = null; + try { + batchCompiler.compile(getCompilationUnits(testFiles)); // compile all files together + } catch(RuntimeException e){ + exception = e; + throw e; + } catch(Error e) { + exception = e; + throw e; + } finally { + nameEnvironment.cleanup(); + String[] alternatePlatformIndepentLogs = null; + if (expectedCompilerLog != null) { + alternatePlatformIndepentLogs = new String[] {Util.convertToIndependantLineDelimiter(expectedCompilerLog)}; + } else if (alternateCompilerLogs != null) { + alternatePlatformIndepentLogs = new String[alternateCompilerLogs.length]; + for (int i = 0; i < alternateCompilerLogs.length; i++) + alternatePlatformIndepentLogs[i] = Util.convertToIndependantLineDelimiter(alternateCompilerLogs[i]); + } + if (alternatePlatformIndepentLogs != null) { + checkCompilerLog(testFiles, requestor, alternatePlatformIndepentLogs, exception); + } + if (exception == null) { + if (expectingCompilerErrors) { + if (!requestor.hasErrors) { + logTestFiles(true, testFiles); + fail("Unexpected success"); + } + } else if (requestor.hasErrors) { + if (!"".equals(requestor.problemLog)) { + logTestFiles(true, testFiles); + System.out.println("Copy-paste compiler log:"); + System.out.println(Util.displayString(Util.convertToIndependantLineDelimiter(requestor.problemLog.toString()), INDENT, SHIFT)); + assertEquals("Unexpected failure", "", requestor.problemLog); + } + } + } + } + if (!requestor.hasErrors || forceExecution) { + String sourceFile = testFiles[0]; + + // Compute class name by removing ".java" and replacing slashes with dots + String className = sourceFile.substring(0, sourceFile.lastIndexOf('.')).replace('/', '.').replace('\\', '.'); + if (!className.endsWith(PACKAGE_INFO_NAME) && !className.endsWith(MODULE_INFO_NAME)) { + + if (vmArguments != null) { + if (this.verifier != null) { + this.verifier.shutDown(); + } + this.verifier = new TestVerifier(false); + this.createdVerifier = true; + } + boolean passed = + this.verifier.verifyClassFiles( + sourceFile, + className, + expectedOutputString, + expectedErrorString, + this.classpaths, + null, + vmArguments); + if (!passed) { + System.out.println(getClass().getName() + '#' + getName()); + String execErrorString = this.verifier.getExecutionError(); + if (execErrorString != null && execErrorString.length() > 0) { + System.out.println("[ERR]:"+execErrorString); //$NON-NLS-1$ + } + String execOutputString = this.verifier.getExecutionOutput(); + if (execOutputString != null && execOutputString.length() > 0) { + System.out.println("[OUT]:"+execOutputString); //$NON-NLS-1$ + } + logTestFiles(false, testFiles); + assertEquals(this.verifier.failureReason, expectedErrorString == null ? "" : expectedErrorString, execErrorString); + assertEquals(this.verifier.failureReason, expectedOutputString == null ? "" : expectedOutputString, execOutputString); + } + assertTrue(this.verifier.failureReason, // computed by verifyClassFiles(...) action + passed); + if (vmArguments != null) { + if (this.verifier != null) { + this.verifier.shutDown(); + } + this.verifier = new TestVerifier(false); + this.createdVerifier = true; + } + } + } + // javac part + if (RUN_JAVAC && javacTestOptions != JavacTestOptions.SKIP) { + runJavac(testFiles, expectingCompilerErrors, expectedCompilerLog, + expectedJavacOutputString, expectedErrorString, shouldFlushOutputDirectory, + javacTestOptions, vmArguments, classLibraries, libsOnModulePath); + } + } + /* GROOVY edit + class DummyAnnotationProcessingManager extends BaseAnnotationProcessorManager { + + ProcessorInfo processorInfo = null; + public ProcessorInfo discoverNextProcessor() { + ProcessorInfo temp = this.processorInfo; + this.processorInfo = null; + return temp; + } + + public void reportProcessorException(Processor p, Exception e) { + throw new AbortCompilation(null, e); + } + + @Override + public void setProcessors(Object[] processors) { + // Nothing to do here + } + + @Override + public void configure(Object batchCompiler, String[] options) { + this._processingEnv = new DummyEnvironmentImpl((Compiler) batchCompiler); + } + public void processAnnotations(CompilationUnitDeclaration[] units, ReferenceBinding[] referenceBindings, boolean isLastRound) { + if (this.processorInfo == null) { + this.processorInfo = new ProcessorInfo(new DummyProcessor()); + } + super.processAnnotations(units, referenceBindings, isLastRound); + } + + @Override + public void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject, boolean isTestCode) { + // Nothing to do here + } + @SupportedAnnotationTypes("*") + class DummyProcessor extends AbstractProcessor { + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + return true; + } + } + + class DummyEnvironmentImpl extends BaseProcessingEnvImpl { + public DummyEnvironmentImpl(Compiler compiler) { + this._compiler = compiler; + } + @Override + public Locale getLocale() { + return Locale.getDefault(); + } + } + } + + protected AbstractAnnotationProcessorManager getAnnotationProcessorManager(Compiler compiler) { + try { + AbstractAnnotationProcessorManager annotationManager = new DummyAnnotationProcessingManager(); + annotationManager.configure(compiler, new String[0]); + annotationManager.setErr(new PrintWriter(System.err)); + annotationManager.setOut(new PrintWriter(System.out)); + return annotationManager; + } catch(UnsupportedClassVersionError e) { + System.err.println(e); + } + return null; + } + */ +public void runConformTest( + // test directory preparation + String[] testFiles, + // javac options + JavacTestOptions javacTestOptions) { +runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + null /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + "" /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + javacTestOptions /* javac test options */); +} +// runConformTest( +// // test directory preparation +// true /* flush output directory */, +// false /* do not flush output directory */, +// shouldFlushOutputDirectory /* should flush output directory */, +// +// new String[] { /* test files */ +// }, +// null /* no test files */, +// testFiles /* test files */, +// +// // compiler results +// null /* do not check compiler log */, +// "" /* expected compiler log */, +// expectedCompilerLog /* expected compiler log */, +// +// // runtime results +// null /* do not check output string */, +// "" /* expected output string */, +// expectedOutputString /* expected output string */, +// +// null /* do not check error string */, +// "" /* expected error string */, +// expectedErrorString /* expected error string */, +// +// // javac options +// JavacTestOptions.SKIP /* skip javac tests */); +// JavacTestOptions.DEFAULT /* default javac test options */); +// javacTestOptions /* javac test options */); +protected void runConformTest( + // test directory preparation + boolean shouldFlushOutputDirectory, + String[] testFiles, + // compiler results + String expectedCompilerLog, + // runtime results + String expectedOutputString, + String expectedErrorString, + // javac options + JavacTestOptions javacTestOptions) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + null /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + expectedOutputString /* expected output string */, + expectedErrorString /* expected error string */, + // javac options + javacTestOptions /* javac test options */); +} +// runConformTest( +// // test directory preparation +// true /* flush output directory */, +// false /* do not flush output directory */, +// +// new String[] { /* test files */ +// }, +// null /* no test files */, +// +// // compiler options +// null /* no class libraries */, +// new String[] { /* class libraries */ +// }, +// +// null /* no custom options */, +// customOptions /* custom options */, +// +// // compiler results +// null /* do not check compiler log */, +// "----------\n" + /* expected compiler log */ +// "" /* expected compiler log */, +// +// // runtime results +// null /* do not check output string */, +// "" /* expected output string */, +// expectedOutputString /* expected output string */, +// +// null /* do not check error string */, +// "" /* expected error string */, +// expectedErrorString /* expected error string */, +// +// // javac options +// JavacTestOptions.SKIP /* skip javac tests */); +// JavacTestOptions.DEFAULT /* default javac test options */); +// javacTestOptions /* javac test options */); +protected void runConformTest( + // test directory preparation + boolean shouldFlushOutputDirectory, + String[] testFiles, + //compiler options + String[] classLibraries /* class libraries */, + Map customOptions /* custom options */, + // compiler results + String expectedCompilerLog, + // runtime results + String expectedOutputString, + String expectedErrorString, + // javac options + JavacTestOptions javacTestOptions) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + expectedOutputString /* expected output string */, + expectedErrorString /* expected error string */, + // javac options + javacTestOptions /* javac test options */); +} +// runNegativeTest( +// // test directory preparation +// new String[] { /* test files */ +// }, +// null /* no test files */, +// // compiler results +// "----------\n" + /* expected compiler log */ +// // javac options +// JavacTestOptions.SKIP /* skip javac tests */); +// JavacTestOptions.DEFAULT /* default javac test options */); +// javacTestOptions /* javac test options */); +protected void runNegativeTest( + // test directory preparation + String[] testFiles, + // compiler results + String expectedCompilerLog, + // javac options + JavacTestOptions javacTestOptions) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + // compiler options + null /* no class libraries */, + null /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + true /* expecting compiler errors */, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + javacTestOptions /* javac test options */); +} +protected void runNegativeTest( +// test directory preparation +String[] testFiles, +String[] dependentFiles, +// compiler results +String expectedCompilerLog, +// javac options +JavacTestOptions javacTestOptions) { + runTest( + // test directory preparation + true /* flush output directory */, + testFiles /* test files */, + dependentFiles, + // compiler options + null /* no class libraries */, + false, + null /* no custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + true /* expecting compiler errors */, + expectedCompilerLog /* expected compiler log */, + // runtime options + null, + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + null, + null, + // javac options + javacTestOptions /* javac test options */, + Charset.defaultCharset()); +} +protected void runNegativeTest( + // test directory preparation + boolean shouldFlushOutputDirectory, + String[] testFiles, + // compiler options + String[] classLibraries, + Map customOptions, + // compiler results + String expectedCompilerLog, + // javac options + JavacTestOptions javacTestOptions) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + expectedCompilerLog == null || /* expecting compiler errors */ + expectedCompilerLog.indexOf("ERROR") != -1, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + null /* no vm arguments */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + javacTestOptions /* javac test options */); +} +// runNegativeTest( +// // test directory preparation +// true /* flush output directory */, +// false /* do not flush output directory */, +// shouldFlushOutputDirectory /* should flush output directory */, +// +// new String[] { /* test files */ +// }, +// null /* no test files */, +// +// // compiler options +// null /* no class libraries */, +// new String[] { /* class libraries */ +// }, +// classLibraries /* class libraries */, +// +// null /* no custom options */, +// customOptions /* custom options */, +// +// // compiler results +// null /* do not check compiler log */, +// "----------\n" + /* expected compiler log */ +// +// //runtime results +// null /* do not check output string */, +// "" /* expected output string */, +// expectedOutputString /* expected output string */, +// +// null /* do not check error string */, +// "" /* expected error string */, +// expectedErrorString /* expected error string */, +// +// // javac options +// JavacTestOptions.SKIP /* skip javac tests */); +// JavacTestOptions.DEFAULT /* default javac test options */); +// javacTestOptions /* javac test options */); +protected void runNegativeTest( + // test directory preparation + boolean shouldFlushOutputDirectory, + String[] testFiles, + // compiler options + String[] classLibraries, + Map customOptions, + // compiler results + String expectedCompilerLog, + // runtime results + String expectedOutputString, + String expectedErrorString, + // javac options + JavacTestOptions javacTestOptions) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + true /* expecting compiler errors */, + expectedCompilerLog /* expected compiler log */, + // runtime options + true /* force execution */, + null /* no vm arguments */, + // runtime results + expectedOutputString /* expected output string */, + expectedErrorString /* expected error string */, + // javac options + javacTestOptions /* javac test options */); +} + @Override + protected void setUp() throws Exception { + super.setUp(); + if (this.verifier == null) { + this.verifier = new TestVerifier(true); + this.createdVerifier = true; + } + if (RUN_JAVAC) { + // WORK make all needed inits once and for all + if (isFirst()) { + if (javacFullLog == null) { + // One time initialization of javac related concerns + // compute command lines and extract javac version + JAVAC_OUTPUT_DIR = new File(JAVAC_OUTPUT_DIR_NAME); + // WORK simplify jdk.root out + String jdkRootDirectory = System.getProperty("jdk.root"); + if (jdkRootDirectory == null) + jdkRootDirPath = (new Path(Util.getJREDirectory())).removeLastSegments(1); + else + jdkRootDirPath = new Path(jdkRootDirectory); + + StringBuilder cmdLineHeader = new StringBuilder(jdkRootDirPath. + append("bin").append(JAVA_NAME).toString()); // PREMATURE replace JAVA_NAME and JAVAC_NAME with locals? depends on potential reuse + javaCommandLineHeader = cmdLineHeader.toString(); + cmdLineHeader = new StringBuilder(jdkRootDirPath. + append("bin").append(JAVAC_NAME).toString()); + cmdLineHeader.append(" -classpath . "); + // start with the current directory which contains the source files + String version = JavacCompiler.getVersion(cmdLineHeader.toString()); + cmdLineHeader.append(" -d "); + cmdLineHeader.append(JAVAC_OUTPUT_DIR_NAME.indexOf(" ") != -1 ? "\"" + JAVAC_OUTPUT_DIR_NAME + "\"" : JAVAC_OUTPUT_DIR_NAME); + cmdLineHeader.append(" -source 1.5 -deprecation -Xlint "); // enable recommended warnings + // WORK new javac system does not do that... reconsider + // REVIEW consider enabling all warnings instead? Philippe does not see + // this as ez to use (too many changes in logs) + javacCommandLineHeader = cmdLineHeader.toString(); + new File(Util.getOutputDirectory()).mkdirs(); + // TODO maxime check why this happens to miss in some cases + // WORK if we keep a full log, it should not mix javac versions... + javacFullLogFileName = Util.getOutputDirectory() + File.separatorChar + + version.replace(' ', '_') + "_" + + (new SimpleDateFormat("yyyyMMdd_HHmmss")).format(new Date()) + + ".txt"; + javacFullLog = + new PrintWriter(new FileOutputStream(javacFullLogFileName)); // static that is initialized once, closed at process end + javacFullLog.println(version); // so that the contents is self sufficient + System.out.println("***************************************************************************"); + System.out.println("* Sun Javac compiler output archived into file:"); + System.out.println("* " + javacFullLogFileName); + System.out.println("***************************************************************************"); + javacCompilers = new ArrayList<>(); + String jdkRoots = System.getProperty("jdk.roots"); + if (jdkRoots == null) { + javacCompilers.add(new JavacCompiler(jdkRootDirPath.toString())); + } else { + StringTokenizer tokenizer = new StringTokenizer(jdkRoots, File.pathSeparator); + while (tokenizer.hasMoreTokens()) { + javacCompilers.add(new JavacCompiler(tokenizer.nextToken())); + } + } + } + // per class initialization + CURRENT_CLASS_NAME = getClass().getName(); + dualPrintln("***************************************************************************"); + System.out.print("* Comparison with Sun Javac compiler for class "); + dualPrintln(CURRENT_CLASS_NAME.substring(CURRENT_CLASS_NAME.lastIndexOf('.')+1) + + " (" + TESTS_COUNTERS.get(CURRENT_CLASS_NAME) + " tests)"); + System.out.println("***************************************************************************"); + DIFF_COUNTERS[0] = 0; + DIFF_COUNTERS[1] = 0; + DIFF_COUNTERS[2] = 0; + } + } + } + + @Override + public void stop() { + this.verifier.shutDown(); + } + + @Override + protected void tearDown() throws Exception { + if (this.createdVerifier) { + stop(); + } + // clean up output dir + File outputDir = new File(OUTPUT_DIR); + if (outputDir.exists()) { + Util.flushDirectoryContent(outputDir); + } + File libDir = new File(LIB_DIR); + if (libDir.exists()) { + Util.flushDirectoryContent(libDir); + } + super.tearDown(); + if (RUN_JAVAC) { + if (JAVAC_OUTPUT_DIR.exists()) { + Util.flushDirectoryContent(JAVAC_OUTPUT_DIR); + } + printJavacResultsSummary(); + } + } + /** + * Returns the OS path to the directory that contains this plugin. + */ + protected String getCompilerTestsPluginDirectoryPath() { + try { + URL platformURL = Platform.getBundle("org.eclipse.jdt.core.tests.compiler").getEntry("/"); + return new File(FileLocator.toFileURL(platformURL).getFile()).getAbsolutePath(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + protected Map setPresetPreviewOptions() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.latestSupportedJavaVersion()); + options.put(JavaCore.COMPILER_SOURCE, JavaCore.latestSupportedJavaVersion()); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.latestSupportedJavaVersion()); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + return options; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java new file mode 100644 index 0000000000..ecfbe4cbb0 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest9.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2017, 2021 GK Software AG, and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.batch.BasicModule; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; + +public class AbstractRegressionTest9 extends AbstractRegressionTest { + + public AbstractRegressionTest9(String name) { + super(name); + } + + protected Map moduleMap = new HashMap<>(); // by name + protected Map file2module = new HashMap<>(); + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + this.moduleMap.clear(); + this.file2module.clear(); + DefaultJavaRuntimeEnvironment.cleanUpDefaultJreClassLibs(); + } + + @Override + protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths, Map options) { + this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths; + INameEnvironment[] classLibs = getClassLibs(classPaths == null, options); + for (INameEnvironment nameEnvironment : classLibs) { + ((FileSystem) nameEnvironment).scanForModules(createParser()); + } + return new InMemoryNameEnvironment9(testFiles, this.moduleMap, classLibs); + } + + @Override + protected CompilationUnit[] getCompilationUnits(String[] testFiles) { + Map moduleFiles= new HashMap<>(); // filename -> modulename + + CompilationUnit[] compilationUnits = Util.compilationUnits(testFiles); + + // scan for all module-info.java: + for (int i = 0; i < testFiles.length; i+=2) { + IModule module = extractModuleDesc(testFiles[i], testFiles[i+1], compilationUnits[i/2]); + if (module != null) { + this.moduleMap.put(String.valueOf(module.name()), module); + moduleFiles.put(testFiles[0], module.name()); + } + } + // record module information in CUs: + for (int i = 0; i < compilationUnits.length; i++) { + char[] fileName = compilationUnits[i].getFileName(); + String fileNameString = String.valueOf(compilationUnits[i].getFileName()); + if (CharOperation.endsWith(fileName, TypeConstants.MODULE_INFO_FILE_NAME)) { + compilationUnits[i].module = moduleFiles.get(fileNameString); + } else { + String modName = this.file2module.get(fileNameString.replace(File.separator, "/")); + if (modName != null) { + compilationUnits[i].module = modName.toCharArray(); + } + } + } + return compilationUnits; + } + + /** + * javac cannot leverage our internal map {@code file2module}, so we better + * neatly place each file into a sub directory matching the module name. + */ + @Override + protected String expandFileNameForJavac(String fileName) { + String fileNameAsKey = fileName.replace(File.separator, "/"); + if (this.file2module != null && this.file2module.containsKey(fileNameAsKey)) { + fileName = new String(this.file2module.get(fileNameAsKey))+File.separator+fileName; + } + return fileName; + } + + private IModule extractModuleDesc(String fileName, String fileContent, ICompilationUnit cu) { + if (fileName.toLowerCase().endsWith(IModule.MODULE_INFO_JAVA)) { + Parser parser = createParser(); + + CompilationResult compilationResult = new CompilationResult(cu, 0, 1, 10); + CompilationUnitDeclaration unit = parser.parse(cu, compilationResult); + if (unit.isModuleInfo() && unit.moduleDeclaration != null) { + return new BasicModule(unit.moduleDeclaration, null); + } + } + return null; + } + + private Parser createParser() { + Map opts = new HashMap(); + opts.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); + return new Parser( + new ProblemReporter(getErrorHandlingPolicy(), new CompilerOptions(opts), getProblemFactory()), + false); + } + + // ------------------------------------------------------ + + /** Use in tests to associate the CU in given files to the module of the given name. */ + public void associateToModule(String moduleName, String... fileNames) { + for (String fileName : fileNames) + this.file2module.put(fileName, moduleName); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java new file mode 100644 index 0000000000..aa0794173e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java @@ -0,0 +1,4604 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * bug 388739 - [1.8][compiler] consider default methods when detecting whether a class needs to be declared abstract + * bug 399567 - [1.8] Different error message from the reference compiler + * bug 401796 - [1.8][compiler] don't treat default methods as overriding an independent inherited abstract method + * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) + * Bug 423505 - [1.8] Implement "18.5.4 More Specific Method Inference" + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.*; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class AmbiguousMethodTest extends AbstractComparableTest { + + static { +// TESTS_NAMES = new String [] { "test010a" }; + } + public AmbiguousMethodTest(String name) { + super(name); + } + + public static Test suite() { + return buildComparableTestSuite(testClass()); + } + + public static Class testClass() { + return AmbiguousMethodTest.class; + } + + @Override + protected Map getCompilerOptions() { + Map compilerOptions = super.getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); + return compilerOptions; + } + public void test000() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test { public static void main(String[] args) { new B().foo(new C()); } }\n" + + "class A { void foo(A a) {} }\n" + + "class B extends A { void foo(B b) { System.out.println(1); } }\n" + + "class C extends B {}" + }, + "1" + ); + } + public void test000a() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test { public static void main(String[] args) { new Subtype().foo(1, \"works\"); } }\n" + + "class Supertype { void foo(U1 u, T1 t) {} }\n" + + "class Subtype extends Supertype { void foo(U3 u, T2 t) { System.out.println(t); } }" + }, + "works" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=122881 + public void test001() { + this.runConformTest( + new String[] { + "C.java", + "public class C { public static void main(String[] args) { new B().m(\"works\"); } }\n" + + "class B extends A { @Override > void m(T t) { System.out.println(t); } }\n" + + "abstract class A { abstract > void m(T t); }" + }, + "works" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=122881 + public void test002() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static interface I1 { void method(E1 o); }\n" + + " static interface I2 { void method(E2 o); }\n" + + " static interface I3 extends I1, I2 {}\n" + + " static class Class1 implements I3 {\n" + + " public void method(String o) { System.out.println(o); }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I3 i = new Class1();\n" + + " i.method(\"works\");\n" + + " }\n" + + "}" + }, + "works"); + } else { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static interface I1 { void method(E1 o); }\n" + + " static interface I2 { void method(E2 o); }\n" + + " static interface I3 extends I1, I2 {}\n" + + " static class Class1 implements I3 {\n" + + " public void method(String o) { System.out.println(o); }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I3 i = new Class1();\n" + + " i.method(\"works\");\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " static interface I3 extends I1, I2 {}\n" + + " ^^\n" + + "Name clash: The method method(E2) of type X.I2 has the same erasure as method(E1) of type X.I1 but does not override it\n" + + "----------\n"); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=122881 + public void test002a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static interface I1 { void method(E o); }\n" + + " static interface I2 { void method(E o); }\n" + + " static interface I3 extends I1, I2 {}\n" + + " static class Class1 implements I3 {\n" + + " public void method(String o) { System.out.println(o); }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I3 i = new Class1();\n" + + " i.method(\"works\");\n" + + " }\n" + + "}" + }, + "works" + ); + } + public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { void foo() { new BB().test(); } }\n" + + "class AA { void test() {} }\n" + + "class BB extends AA { void test() {} }\n" + + "class CC {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X { void foo() { new BB().test(); } }\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " class BB extends AA { void test() {} }\n" + + " ^^^^^^\n" + + "Name clash: The method test() of type BB has the same erasure as test() of type AA but does not override it\n" + + "----------\n" + ); + } + public void test003a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void singleMatch() { System.out.print(new BB().test(new N(), new Integer(1))); }\n" + + " void betterMatch() { System.out.print(new CC().test(new N(), new Integer(1))); }\n" + + " void worseMatch() { System.out.print(new DD().test(new N(), new Integer(1))); }\n" + + " public static void main(String[] s) {\n" + + " new X().singleMatch();\n" + + " new X().betterMatch();\n" + + " new X().worseMatch();\n" + + " }\n" + + "}\n" + + "class AA { int test(T t, Number num) { return 1; } }\n" + + "class BB extends AA { @Override int test(N n, Number num) { return 2; } }\n" + + "class CC extends AA { int test(N n, U u) { return 3; } }\n" + + "class DD extends AA { int test(M m, U u) { return 4; } }\n" + + "class M {}\n" + + "class N extends M {}", + }, + "231" + ); + } + public void test003b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void ambiguous() { new BB().test(new N()); }\n" + + " void exactMatch() { new CC().test(new N()); }\n" + + "}\n" + + "class AA { void test(T t) {} }\n" + + "class BB extends AA { void test(N n) {} }\n" + + "class CC extends AA { @Override void test(N n) {} }\n" + + "class M {}\n" + + "class N extends M {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\r\n" + + " void ambiguous() { new BB().test(new N()); }\r\n" + + " ^^^^\n" + + "The method test(N) is ambiguous for the type BB\n" + + "----------\n" + ); + } + public void test003c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void ambiguous() { new BB().test(new N(), Integer.valueOf(1)); }\n" + + "}\n" + + "class AA { void test(T t, Integer i) {} }\n" + + "class BB extends AA { void test(N n, U u) {} }\n" + + "class M {}\n" + + "class N extends M {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void ambiguous() { new BB().test(new N(), Integer.valueOf(1)); }\n" + + " ^^^^\n" + + "The method test(N, Integer) is ambiguous for the type BB\n" + + "----------\n" + ); + } + public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test(M m) {\n" + + " m.id(Integer.valueOf(111));\n" + + " }\n" + + "}\n" + + "class C { public void id(T t) {} }\n" + + "class M extends C { public void id(Integer i) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " m.id(Integer.valueOf(111));\n" + + " ^^\n" + + "The method id(Integer) is ambiguous for the type M\n" + + "----------\n" + // reference to id is ambiguous, both method id(A) in C and method id(B) in M match + ); + } + public void test004a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void test(M m) {\n" + + " m.id(new Integer(111));\n" + + " }\n" + + "}\n" + + "class C { public void id(T t) {} }\n" + + "class M extends C { public void id(Integer i) {} }\n" + }, + "" + ); + } + public void test005() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo() { }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " N foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " new X().foo();\n" + + " ^^^\n" + + "The method foo() is ambiguous for the type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo() { }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " N foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() { }\n" + + " N foo() { return null; }\n" + + " void test () {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B {}\n" + }, + expectedCompilerLog); +/* javac 7 +X.java:3: name clash: foo() and foo() have the same erasure + N foo() { return null; } + ^ + where N,S are type-variables: + N extends B declared in method foo() + S extends A declared in method foo() +1 error + */ + } + public void test006() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new Y().foo(\"X\");\n" + + " ^^^\n" + + "The method foo(Object) is ambiguous for the type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " new Y().foo2(\"X\");\n" + + " ^^^^\n" + + "The method foo2(Object) is ambiguous for the type Y\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " void foo(T2 t) {}\n" + + " ^^^^^^^^^\n" + + "Name clash: The method foo(T2) of type Y has the same erasure as foo(U1) of type X but does not override it\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " void foo2(T2 t) {}\n" + + " ^^^^^^^^^^\n" + + "Name clash: The method foo2(T2) of type Y has the same erasure as foo2(U2) of type X but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new Y().foo(\"X\");\n" + + " ^^^\n" + + "The method foo(Object) is ambiguous for the type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " new Y().foo2(\"X\");\n" + + " ^^^^\n" + + "The method foo2(Object) is ambiguous for the type Y\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " void foo(T2 t) {}\n" + + " ^^^^^^^^^\n" + + "Name clash: The method foo(T2) of type Y has the same erasure as foo(U1) of type X but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " void foo2(T2 t) {}\n" + + " ^^^^^^^^^^\n" + + "Name clash: The method foo2(T2) of type Y has the same erasure as foo2(U2) of type X but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test() {\n" + + " new Y().foo(\"X\");\n" + + " new Y().foo2(\"X\");\n" + + " }\n" + + " U1 foo(U1 t) {return null;}\n" + + " U2 foo2(U2 t) {return null;}\n" + + "}\n" + + "class Y extends X {\n" + + " void foo(T2 t) {}\n" + + " void foo2(T2 t) {}\n" + + "}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: reference to foo is ambiguous, both method foo(U1) in X and method + foo(T2) in Y match + new Y().foo("X"); + ^ + where U1,T2 are type-variables: + U1 extends Object declared in method foo(U1) + T2 extends Object declared in class Y +X.java:4: reference to foo2 is ambiguous, both method foo2(U2) in X and meth +od foo2(T2) in Y match + new Y().foo2("X"); + ^ + where U2,U3,T2 are type-variables: + U2 extends Object declared in method foo2(U2) + U3 extends Object declared in method foo2(T2) + T2 extends Object declared in class Y +X.java:10: name clash: foo(T2) in Y and foo(U1) in X have the same erasure, +yet neither overrides the other + void foo(T2 t) {} + ^ + where T2,U1 are type-variables: + T2 extends Object declared in class Y + U1 extends Object declared in method foo(U1) +X.java:11: name clash: foo2(T2) in Y and foo2(U2) in X have the same era +sure, yet neither overrides the other + void foo2(T2 t) {} + ^ + where U3,T2,U2 are type-variables: + U3 extends Object declared in method foo2(T2) + T2 extends Object declared in class Y + U2 extends Object declared in method foo2(U2) +4 errors + */ + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=129056 + public void test007() { + this.runNegativeTest( + new String[] { + "B.java", + "public class B {\n" + + " public static void main(String[] args) {\n" + + " new M().foo(Integer.valueOf(1), 2);\n" + + " new N().foo(Integer.valueOf(1), 2);\n" + + " }\n" + + "}" + + "interface I { void foo(Number arg1, Number arg2); }\n" + + "class M {\n" + + " public void foo(int arg1, int arg2) {}\n" + + " public void foo(Number arg1, Number arg2) {}\n" + + "}\n" + + "class N implements I {\n" + + " public void foo(int arg1, int arg2) {}\n" + + " public void foo(Number arg1, Number arg2) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in B.java (at line 3)\r\n" + + " new M().foo(Integer.valueOf(1), 2);\r\n" + + " ^^^\n" + + "The method foo(int, int) is ambiguous for the type M\n" + + "----------\n" + + "2. ERROR in B.java (at line 4)\r\n" + + " new N().foo(Integer.valueOf(1), 2);\r\n" + + " ^^^\n" + + "The method foo(int, int) is ambiguous for the type N\n" + + "----------\n" + // reference to foo is ambiguous, both method foo(int,int) in M and method foo(java.lang.Number,java.lang.Number) in M match + // reference to foo is ambiguous, both method foo(int,int) in N and method foo(java.lang.Number,java.lang.Number) in N match + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=123943 - case 1 + public void test008() { + this.runConformTest( + new String[] { + "AA.java", + "public class AA {\n" + + " public static void main(String[] a) { System.out.print(new C().test(new T())); }\n" + + "}" + + "class S {}\n" + + "class T extends S {}\n" + + "class B { int test(U u) {return -1;} }\n" + + "class C extends B { @Override int test(S s) {return 1;} }" + }, + "1" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=123943 - case 1 + public void test008a() { + this.runNegativeTest( + new String[] { + "A.java", + "public class A { void check() { new C().test(new T()); } }\n" + + "class S {}\n" + + "class T extends S {}\n" + + "class B { int test(S s) {return 1;} }\n" + + "class C extends B { int test(U u) {return -1;} }" + }, + "----------\n" + + "1. ERROR in A.java (at line 1)\n" + + " public class A { void check() { new C().test(new T()); } }\n" + + " ^^^^\n" + + "The method test(T) is ambiguous for the type C\n" + + "----------\n" + + "2. ERROR in A.java (at line 5)\n" + + " class C extends B { int test(U u) {return -1;} }\n" + + " ^^^^^^^^^\n" + + "Name clash: The method test(U) of type C has the same erasure as test(S) of type B but does not override it\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=123943 - case 2 + // see also Bug 399567 - [1.8] Different error message from the reference compiler + public void test009() { + String[] testFiles = + new String[] { + "T.java", + "import java.util.*;\n" + + "public class T {\n" + + " void test() {\n" + + " OrderedSet os = null;\n" + + " os.add(\"hello\");\n" + + " OrderedSet os2 = null;\n" + + " os2.add(1);\n" + + " }\n" + + "}\n" + + "interface OrderedSet extends List, Set { boolean add(E o); }\n" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_8) + this.runConformTest(testFiles, ""); + else + this.runNegativeTest( + testFiles, + "----------\n" + + "1. WARNING in T.java (at line 5)\n" + + " os.add(\"hello\");\n" + + " ^^\n" + + "Null pointer access: The variable os can only be null at this location\n" + + "----------\n" + + "2. WARNING in T.java (at line 7)\n" + + " os2.add(1);\n" + + " ^^^\n" + + "Null pointer access: The variable os2 can only be null at this location\n" + + "----------\n" + + "3. ERROR in T.java (at line 10)\n" + + " interface OrderedSet extends List, Set { boolean add(E o); }\n" + + " ^^^^^^^^^^\n" + + "Duplicate default methods named spliterator with the parameters () and () are inherited from the types Set and List\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=123943 variant to make it pass on JRE8 + public void test009a() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runConformTest( + new String[] { + "T.java", + "import java.util.*;\n" + + "public class T {\n" + + " void test() {\n" + + " OrderedSet os = null;\n" + + " os.add(\"hello\");\n" + + " OrderedSet os2 = null;\n" + + " os2.add(1);\n" + + " }\n" + + "}\n" + + "interface OrderedSet extends List, Set {\n" + + " boolean add(E o);\n" + + " default Spliterator spliterator() { return null; }\n" + + "}\n" + }, + "" + ); + } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 +public void test010a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Listener {}\n" + + " interface ErrorListener {}\n" + + " static Object createParser(L1 l) { return null; }\n" + + " static Object createParser(L2 l) { return null; }\n" + + " public static void main(String[] s) {\n" + + " class A implements Listener, ErrorListener {}\n" + + " createParser(new A());\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " createParser(new A());\n" + + " ^^^^^^^^^^^^\n" + + "The method createParser(A) is ambiguous for the type X\n" + + "----------\n" + ); +// javac 7 randomly picks which ever method is second +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 +public void test010b() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Listener {}\n" + + " interface ErrorListener {}\n" + + " static int createParser(L1 l) { return 1; }\n" + + " static int createParser(L2 l) { return 2; }\n" + + " public static void main(String[] s) {\n" + + " class A implements Listener, ErrorListener {}\n" + + " System.out.print(createParser(new A()));\n" + + " }\n" + + "}" + }, + "2" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 +public void test010c() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Listener {}\n" + + " interface ErrorListener {}\n" + + " static int createParser(Listener l) { return 1; }\n" + + " static int createParser(L l) { return 2; }\n" + + " public static void main(String[] s) {\n" + + " class A implements Listener, ErrorListener {}\n" + + " System.out.print(createParser(new A()));\n" + + " }\n" + + "}" + }, + "2" + ); +} + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106090 + public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " void foo(A n, T t) throws ExOne {}\n" + + " void test(X x) throws ExTwo { x.foo(Integer.valueOf(1), Integer.valueOf(2)); }\n" + + " void test2(X x) throws ExTwo { x.foo(Integer.valueOf(1), Integer.valueOf(2)); }\n" + + "}\n" + + "class Y {\n" + + " void foo(C x, C n) throws ExTwo {}\n" + + "}\n" + + "class ExOne extends Exception {static final long serialVersionUID = 1;}\n" + + "class ExTwo extends Exception {static final long serialVersionUID = 2;}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void test2(X x) throws ExTwo { x.foo(Integer.valueOf(1), Integer.valueOf(2)); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " void test2(X x) throws ExTwo { x.foo(Integer.valueOf(1), Integer.valueOf(2)); }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(Number, Number) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + // test2 - warning: [unchecked] unchecked call to foo(C,C) as a member of the raw type Y + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106090 + public void test011a() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in Combined.java (at line 2)\n" + + " > void pickOne(T value) throws ExOne {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method pickOne(T) is the same as another method in type Combined\n" + + "----------\n" + + "2. WARNING in Combined.java (at line 3)\n" + + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method pickOne(Comparable) is the same as another method in type Combined\n" + + "----------\n": + "----------\n" + + "1. ERROR in Combined.java (at line 2)\n" + + " > void pickOne(T value) throws ExOne {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method pickOne(T) is the same as another method in type Combined\n" + + "----------\n" + + "2. ERROR in Combined.java (at line 3)\n" + + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method pickOne(Comparable) is the same as another method in type Combined\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "Combined.java", + "public class Combined {\n" + + " > void pickOne(T value) throws ExOne {}\n" + + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + + " void pickOne(Combined c) throws ExOne { c.pickOne(\"test\"); }\n" + + " void pickTwo(Number n, T t) throws ExOne {}\n" + + " void pickTwo(A x, Number n) throws ExTwo {}\n" + + " void pickTwo(Combined c) throws ExTwo { c.pickTwo(Integer.valueOf(1), 2); }\n" + + "}\n" + + "class ExOne extends Exception {static final long serialVersionUID = 1;}\n" + + "class ExTwo extends Exception {static final long serialVersionUID = 2;}" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: pickOne(Comparable) and pickOne(T#2) have the same erasure + T pickOne(Comparable value) throws ExTwo { return null;} + ^ + where T#1,T#2 are type-variables: + T#1 extends Object declared in method pickOne(Comparable) + T#2 extends Comparable declared in method pickOne(T#2) +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106090 + public void test011b() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in Test1.java (at line 2)\n" + + " > void pickOne(T value) throws ExOne {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method pickOne(T) is the same as another method in type Test1\n" + + "----------\n" + + "2. WARNING in Test1.java (at line 3)\n" + + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method pickOne(Comparable) is the same as another method in type Test1\n" + + "----------\n" + + "3. WARNING in Test1.java (at line 4)\n" + + " void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation pickOne(Comparable) of the generic method pickOne(T) of type Test1\n" + + "----------\n" + + "4. WARNING in Test1.java (at line 4)\n" + + " void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n": + "----------\n" + + "1. ERROR in Test1.java (at line 2)\n" + + " > void pickOne(T value) throws ExOne {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method pickOne(T) is the same as another method in type Test1\n" + + "----------\n" + + "2. ERROR in Test1.java (at line 3)\n" + + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method pickOne(Comparable) is the same as another method in type Test1\n" + + "----------\n" + + "3. WARNING in Test1.java (at line 4)\n" + + " void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation pickOne(Comparable) of the generic method pickOne(T) of type Test1\n" + + "----------\n" + + "4. WARNING in Test1.java (at line 4)\n" + + " void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "Test1.java", + "public class Test1 {\n" + + " > void pickOne(T value) throws ExOne {}\n" + + " T pickOne(Comparable value) throws ExTwo { return null;}\n" + + " void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) \"test\"); }\n" + + "}\n" + + "class ExOne extends Exception {static final long serialVersionUID = 1;}\n" + + "class ExTwo extends Exception {static final long serialVersionUID = 2;}" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: pickOne(Comparable) and pickOne(T#2) have the same erasure + T pickOne(Comparable value) throws ExTwo { return null;} + ^ + where T#1,T#2 are type-variables: + T#1 extends Object declared in method pickOne(Comparable) + T#2 extends Comparable declared in method pickOne(T#2) +X.java:4: warning: [unchecked] unchecked method invocation: method pickOne in class Test1 is applied to given types + void pickOne2(Test1 c) throws ExOne { c.pickOne((Comparable) "test"); } + ^ + required: T + found: Comparable + where T is a type-variable: + T extends Comparable declared in method pickOne(T) +1 error +1 warning + */ + } + public void test012() { + this.runConformTest( + new String[] { + "XX.java", + "public class XX {\n" + + " public static void main(String[] s) { System.out.println(new B().id(new Integer(1))); }\n" + + "}\n" + + "class A { public int id(T t) {return 2;} }\n" + + "class B extends A { public int id(Integer i) {return 1;} }" + }, + "1" + ); + } + public void test012a() { + this.runNegativeTest( + new String[] { + "XX.java", + "public class XX {\n" + + " public static void main(String[] s) { System.out.println(new B().id(Integer.valueOf(1))); }\n" + + "}\n" + + "class A { public int id(T t) {return 2;} }\n" + + "class B extends A { public int id(Integer i) {return 1;} }" + }, + "----------\n" + + "1. ERROR in XX.java (at line 2)\r\n" + + " public static void main(String[] s) { System.out.println(new B().id(Integer.valueOf(1))); }\r\n" + + " ^^\n" + + "The method id(Integer) is ambiguous for the type B\n" + + "----------\n" + // reference to id is ambiguous, both method id(T) in A and method id(java.lang.Integer) in B match + ); + } + public void test013() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void m(E e) { System.out.print(1); }\n" + + " void m(E e) { System.out.print(2); }\n" + + " public static void main(String[] args) {\n" + + " new X().m(new A());\n" + + " new X().m(new B());\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + }, + "12" + ); + } + public void test014() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void a(G x) { System.out.print(1); }\n" + + " void b(F x) { System.out.print(2); }\n" + + " public static void main(String[] args) {\n" + + " H h = null;\n" + + " G g = null;\n" + + " new X().a(h);\n" + + " new X().a(g);\n" + + " new X().b(h);\n" + + " new X().b(g);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "1122" + ); + } + public void test014a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void a(G x) { System.out.print(1); }\n" + + " void b(F x) { System.out.print(2); }\n" + + " public static void main(String[] args) {\n" + + " H h = null;\n" + + " G g = null;\n" + + " new X().a(h);\n" + + " new X().a(g);\n" + + " new X().b(h);\n" + + " new X().b(g);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "1122" + ); + } + public void test014b() { + this.runConformTest( + new String[] { + "X0.java", + "public class X0 {\n" + + " void two(G x) { System.out.print(1); }\n" + + " void two(F x) { System.out.print(2); }\n" + + " void three(G x) { System.out.print(3); }\n" + + " void three(F x) { System.out.print(4); }\n" + + " public static void main(String[] args) {\n" + + " H h = null;\n" + + " new X0().two(h);\n" + + " new X0().three(h);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "13" + ); + } + public void test014c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void a(G x) {}\n" + + " void a(F x) {}\n" + + " void b(G x) {}\n" + + " void b(F x) {}\n" + + " public static void main(String[] args) {\n" + + " H h = null;\n" + + " new X().a(h);\n" + + " new X().b(h);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\r\n" + + " void a(G x) {}\r\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\r\n" + + " void b(F x) {}\r\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\r\n" + + " new X().a(h);\r\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + // reference to a is ambiguous, both method a(G) in X and method a(F) in X match + ); + } + public void test014d() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void one(G x) {}\n" + + " void one(F x) {}\n" + + " public static void main(String[] args) {\n" + + " H h = null;\n" + + " new X().one(h);\n" + // no match + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\r\n" + + " new X().one(h);\r\n" + + " ^^^\n" + + "The method one(G) in the type X is not applicable for the arguments (H)\n" + + "----------\n" + ); + } + public void test014e() { + this.runConformTest( + new String[] { + "X1.java", + "public class X1 {\n" + + " void two(G x) { System.out.print(1); }\n" + + " void two(F x) { System.out.print(2); }\n" + + " void three(G x) { System.out.print(3); }\n" + + " void three(F x) { System.out.print(4); }\n" + + " void four(G x) { System.out.print(5); }\n" + + " void four(F x) { System.out.print(6); }\n" + + " public static void main(String[] args) {\n" + + " H h = null;\n" + + " new X1().two(h);\n" + + " new X1().three(h);\n" + + " new X1().four(h);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "145" + ); + } + public void test014f() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void three(G x) {}\n" + + " void three(F x) {}\n" + + " public static void main(String[] args) {\n" + + " H h = null;\n" + + " new X().three(h);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\r\n" + + " new X().three(h);\r\n" + + " ^^^^^\n" + + "The method three(G) is ambiguous for the type X\n" + + "----------\n" + ); + } + public void test014g() { + this.runConformTest( + new String[] { + "X3.java", + "public class X3 {\n" + + " void one(G x) { System.out.print(1); }\n" + + " void one(F x) { System.out.print(2); }\n" + + " void two(G x) { System.out.print(3); }\n" + + " void two(F x) { System.out.print(4); }\n" + + " void four(G x) { System.out.print(5); }\n" + + " void four(F x) { System.out.print(6); }\n" + + " public static void main(String[] args) {\n" + + " H h = null;\n" + + " new X3().one(h);\n" + + " new X3().two(h);\n" + + " new X3().four(h);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "135" + ); + } + public void test014h() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void x(G x) { System.out.print(true); }\n" + + " void x(F x) { System.out.print(false); }\n" + + " void x2(G x) { System.out.print(true); }\n" + + " void x2(F x) { System.out.print(false); }\n" + + " void a(G x) {}\n" + + " void a(F x) {}\n" + + " void a2(G x) {}\n" + + " void a2(F x) {}\n" + + " void a3(G x) {}\n" + + " > void a3(T x) {}\n" + + " void a4(G x) {}\n" + + " > void a4(S x) {}\n" + + " void a5(T x) {}\n" + + " void a5(F x) {}\n" + + " void a6(T x) {}\n" + + " > void a6(S x) {}\n" + + " void b(G x) { System.out.print(true); }\n" + + " void b(F x) { System.out.print(false); }\n" + + " void b2(G x) { System.out.print(true); }\n" + + " void b2(T x) { System.out.print(false); }\n" + + " void b3(G x) { System.out.print(true); }\n" + + " void b3(F x) { System.out.print(false); }\n" + + " > void b4(T x) { System.out.print(true); }\n" + + " void b4(F x) { System.out.print(false); }\n" + + " > void b5(S x) { System.out.print(true); }\n" + + " void b5(F x) { System.out.print(false); }\n" + + " void c(G x) { System.out.print(true); }\n" + + " void c(F x) { System.out.print(false); }\n" + + " public static void main(String[] args) {\n" + + " H h = null;\n" + + " H hraw = null;\n" + + " new X().x(h);\n" + + " new X().x(hraw);\n" + + " new X().x2(h);\n" + + " new X().x2(hraw);\n" + + " new X().b(h);\n" + + " new X().b(hraw);\n" + + " new X().b2(h);\n" + + " new X().b2(hraw);\n" + + " new X().b3(h);\n" + + " new X().b3(hraw);\n" + + " new X().b4(h);\n" + + " new X().b4(hraw);\n" + + " new X().b5(h);\n" + + " new X().b5(hraw);\n" + + " new X().c(h);\n" + + " new X().c(hraw);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "truetruetruetruetruetruetruetruetruetruetruetruetruetruetruetrue" + ); + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y extends X {\n" + + " public static void ambiguousCases() {\n" + + " H h = null;\n" + + " H hraw = null;\n" + + " new X().a(h);\n" + + " new X().a(hraw);\n" + + " new X().a2(h);\n" + + " new X().a2(hraw);\n" + + " new X().a3(h);\n" + + " new X().a3(hraw);\n" + + " new X().a4(h);\n" + + " new X().a4(hraw);\n" + + " new X().a5(h);\n" + + " new X().a5(hraw);\n" + + " new X().a6(h);\n" + + " new X().a6(hraw);\n" + + " }\n" + + "}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in Y.java (at line 4)\n" + + " H hraw = null;\n" + + " ^\n" + + "H is a raw type. References to generic type H should be parameterized\n" + + "----------\n" + + "2. ERROR in Y.java (at line 5)\n" + + " new X().a(h);\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in Y.java (at line 6)\n" + + " new X().a(hraw);\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + + "4. ERROR in Y.java (at line 7)\n" + + " new X().a2(h);\n" + + " ^^\n" + + "The method a2(G) is ambiguous for the type X\n" + + "----------\n" + + "5. ERROR in Y.java (at line 8)\n" + + " new X().a2(hraw);\n" + + " ^^\n" + + "The method a2(G) is ambiguous for the type X\n" + + "----------\n" + + "6. ERROR in Y.java (at line 9)\n" + + " new X().a3(h);\n" + + " ^^\n" + + "The method a3(G) is ambiguous for the type X\n" + + "----------\n" + + "7. ERROR in Y.java (at line 10)\n" + + " new X().a3(hraw);\n" + + " ^^\n" + + "The method a3(G) is ambiguous for the type X\n" + + "----------\n" + + "8. ERROR in Y.java (at line 11)\n" + + " new X().a4(h);\n" + + " ^^\n" + + "The method a4(G) is ambiguous for the type X\n" + + "----------\n" + + "9. ERROR in Y.java (at line 12)\n" + + " new X().a4(hraw);\n" + + " ^^\n" + + "The method a4(G) is ambiguous for the type X\n" + + "----------\n" + + "10. ERROR in Y.java (at line 13)\n" + + " new X().a5(h);\n" + + " ^^\n" + + "The method a5(H) is ambiguous for the type X\n" + + "----------\n" + + "11. ERROR in Y.java (at line 14)\n" + + " new X().a5(hraw);\n" + + " ^^\n" + + "The method a5(H) is ambiguous for the type X\n" + + "----------\n" + + "12. ERROR in Y.java (at line 15)\n" + + " new X().a6(h);\n" + + " ^^\n" + + "The method a6(H) is ambiguous for the type X\n" + + "----------\n" + + "13. ERROR in Y.java (at line 16)\n" + + " new X().a6(hraw);\n" + + " ^^\n" + + "The method a6(H) is ambiguous for the type X\n" + + "----------\n" + : // in 1.8 fewer of the calls are ambiguous + "----------\n" + + "1. WARNING in Y.java (at line 4)\n" + + " H hraw = null;\n" + + " ^\n" + + "H is a raw type. References to generic type H should be parameterized\n" + + "----------\n" + + "2. ERROR in Y.java (at line 5)\n" + + " new X().a(h);\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in Y.java (at line 6)\n" + + " new X().a(hraw);\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + + "4. ERROR in Y.java (at line 7)\n" + + " new X().a2(h);\n" + + " ^^\n" + + "The method a2(G) is ambiguous for the type X\n" + + "----------\n" + + "5. ERROR in Y.java (at line 8)\n" + + " new X().a2(hraw);\n" + + " ^^\n" + + "The method a2(G) is ambiguous for the type X\n" + + "----------\n" + + "6. ERROR in Y.java (at line 13)\n" + + " new X().a5(h);\n" + + " ^^\n" + + "The method a5(H) is ambiguous for the type X\n" + + "----------\n" + + "7. ERROR in Y.java (at line 14)\n" + + " new X().a5(hraw);\n" + + " ^^\n" + + "The method a5(H) is ambiguous for the type X\n" + + "----------\n"), + null, + false + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=262209 + public void test014i() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "interface J extends I {}\n" + + "\n" + + "class X {\n" + + " void a(G x) {}\n" + + " > void a(S x) {}\n" + + "\n" + + " void b(G x) {}\n" + + " void b(F x) {}\n" + + "\n" + + " void c(G x) {}\n" + + " void c(F x) {}\n" + + "\n" + + " void d(G x) {}\n" + + " void d(F x) {}\n" + + "\n" + + " void e(G x) {}\n" + + " void e(F x) {}\n" + + "\n" + + " void f(G x) {}\n" + + " void f(S x) {}\n" + + "\n" + + " void g(G x) {}\n" + + " > void g(S x) {}\n" + + "\n" + + " void a2(T x) {}\n" + + " > void a2(S x) {}\n" + + "\n" + + " void b2(T x) {}\n" + + " void b2(F x) {}\n" + + "\n" + + " void c2(T x) {}\n" + + " void c2(F x) {}\n" + + "\n" + + " void d2(T x) {}\n" + + " void d2(F x) {}\n" + + "\n" + + " void e2(T x) {}\n" + + " void e2(F x) {}\n" + + "\n" + + " void f2(T x) {}\n" + + " void f2(S x) {}\n" + + "\n" + + " void g2(T x) {}\n" + + " > void g2(S x) {}\n" + + "\n" + + " void test() {\n" + + " X x = new X();\n" + + " H h = null;\n" + + " H hraw = null;\n" + + "\n" + + " x.a(h);\n" + + " x.a(hraw);\n" + + "\n" + + " x.b(h);\n" + + " x.b(hraw);\n" + + "\n" + + " x.c(h);\n" + + " x.c(hraw);\n" + + "\n" + + " x.d(h);\n" + + " x.d(hraw);\n" + + "\n" + + " x.e(h);\n" + + " x.e(hraw);\n" + + "\n" + + " x.f(h);\n" + + " x.f(hraw);\n" + + "\n" + + " x.g(h);\n" + + " x.g(hraw);\n" + + "\n" + + " x.a2(h);\n" + + " x.a2(hraw);\n" + + "\n" + + " x.b2(h); \n" + + " x.b2(hraw);\n" + + "\n" + + " x.c2(h);\n" + + " x.c2(hraw);\n" + + "\n" + + " x.d2(h);\n" + + " x.d2(hraw);\n" + + "\n" + + " x.e2(h);\n" + + " x.e2(hraw);\n" + + "\n" + + " x.f2(h);\n" + + " x.f2(hraw);\n" + + "\n" + + " x.g2(h); \n" + + " x.g2(hraw);\n" + + " }\n" + + "}\n" + + "\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends B implements I {}\n" + + "class F {} \n" + + "class G extends F implements J {}\n" + + "class H extends G {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void a(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " void b(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " void b(F x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " void c(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 14)\n" + + " void d(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 17)\n" + + " void e(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 20)\n" + + " void f(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 21)\n" + + " void f(S x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 23)\n" + + " void g(G x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "10. WARNING in X.java (at line 24)\n" + + " > void g(S x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 26)\n" + + " void a2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "12. WARNING in X.java (at line 29)\n" + + " void b2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "13. WARNING in X.java (at line 30)\n" + + " void b2(F x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "14. WARNING in X.java (at line 32)\n" + + " void c2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "15. WARNING in X.java (at line 35)\n" + + " void d2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "16. WARNING in X.java (at line 38)\n" + + " void e2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "17. WARNING in X.java (at line 41)\n" + + " void f2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "18. WARNING in X.java (at line 42)\n" + + " void f2(S x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "19. WARNING in X.java (at line 42)\n" + + " void f2(S x) {}\n" + + " ^\n" + + "J is a raw type. References to generic type J should be parameterized\n" + + "----------\n" + + "20. WARNING in X.java (at line 44)\n" + + " void g2(T x) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "21. WARNING in X.java (at line 45)\n" + + " > void g2(S x) {}\n" + + " ^\n" + + "F is a raw type. References to generic type F should be parameterized\n" + + "----------\n" + + "22. WARNING in X.java (at line 50)\n" + + " H hraw = null;\n" + + " ^\n" + + "H is a raw type. References to generic type H should be parameterized\n" + + "----------\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "23. ERROR in X.java (at line 52)\n" + + " x.a(h);\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + + "24. ERROR in X.java (at line 53)\n" + + " x.a(hraw);\n" + + " ^\n" + + "The method a(G) is ambiguous for the type X\n" + + "----------\n" + + "25. ERROR in X.java (at line 58)\n" + + " x.c(h);\n" + + " ^\n" + + "The method c(G) is ambiguous for the type X\n" + + "----------\n" + + "26. ERROR in X.java (at line 59)\n" + + " x.c(hraw);\n" + + " ^\n" + + "The method c(G) is ambiguous for the type X\n" + + "----------\n" + + "27. ERROR in X.java (at line 61)\n" + + " x.d(h);\n" + + " ^\n" + + "The method d(G) is ambiguous for the type X\n" + + "----------\n" + + "28. ERROR in X.java (at line 62)\n" + + " x.d(hraw);\n" + + " ^\n" + + "The method d(G) is ambiguous for the type X\n" + + "----------\n" + + "29. ERROR in X.java (at line 64)\n" + + " x.e(h);\n" + + " ^\n" + + "The method e(G) is ambiguous for the type X\n" + + "----------\n" + + "30. ERROR in X.java (at line 65)\n" + + " x.e(hraw);\n" + + " ^\n" + + "The method e(G) is ambiguous for the type X\n" + + "----------\n" + + "31. ERROR in X.java (at line 71)\n" + + " x.g(hraw);\n" + + " ^\n" + + "The method g(G) is ambiguous for the type X\n" + + "----------\n" + + "32. ERROR in X.java (at line 73)\n" + + " x.a2(h);\n" + + " ^^\n" + + "The method a2(H) is ambiguous for the type X\n" + + "----------\n" + + "33. ERROR in X.java (at line 74)\n" + + " x.a2(hraw);\n" + + " ^^\n" + + "The method a2(H) is ambiguous for the type X\n" + + "----------\n" + + "34. ERROR in X.java (at line 79)\n" + + " x.c2(h);\n" + + " ^^\n" + + "The method c2(H) is ambiguous for the type X\n" + + "----------\n" + + "35. ERROR in X.java (at line 80)\n" + + " x.c2(hraw);\n" + + " ^^\n" + + "The method c2(H) is ambiguous for the type X\n" + + "----------\n" + + "36. ERROR in X.java (at line 82)\n" + + " x.d2(h);\n" + + " ^^\n" + + "The method d2(H) is ambiguous for the type X\n" + + "----------\n" + + "37. ERROR in X.java (at line 83)\n" + + " x.d2(hraw);\n" + + " ^^\n" + + "The method d2(H) is ambiguous for the type X\n" + + "----------\n" + + "38. ERROR in X.java (at line 85)\n" + + " x.e2(h);\n" + + " ^^\n" + + "The method e2(H) is ambiguous for the type X\n" + + "----------\n" + + "39. ERROR in X.java (at line 86)\n" + + " x.e2(hraw);\n" + + " ^^\n" + + "The method e2(H) is ambiguous for the type X\n" + + "----------\n" + + "40. ERROR in X.java (at line 92)\n" + + " x.g2(hraw);\n" + + " ^^\n" + + "The method g2(H) is ambiguous for the type X\n" + + "----------\n" + + "41. WARNING in X.java (at line 98)\n" + : // fewer ambiguities in 1.8 + "23. ERROR in X.java (at line 61)\n" + + " x.d(h);\n" + + " ^\n" + + "The method d(G) is ambiguous for the type X\n" + + "----------\n" + + "24. ERROR in X.java (at line 62)\n" + + " x.d(hraw);\n" + + " ^\n" + + "The method d(G) is ambiguous for the type X\n" + + "----------\n" + + "25. ERROR in X.java (at line 64)\n" + + " x.e(h);\n" + + " ^\n" + + "The method e(G) is ambiguous for the type X\n" + + "----------\n" + + "26. ERROR in X.java (at line 65)\n" + + " x.e(hraw);\n" + + " ^\n" + + "The method e(G) is ambiguous for the type X\n" + + "----------\n" + + "27. ERROR in X.java (at line 82)\n" + + " x.d2(h);\n" + + " ^^\n" + + "The method d2(H) is ambiguous for the type X\n" + + "----------\n" + + "28. ERROR in X.java (at line 83)\n" + + " x.d2(hraw);\n" + + " ^^\n" + + "The method d2(H) is ambiguous for the type X\n" + + "----------\n" + + "29. ERROR in X.java (at line 85)\n" + + " x.e2(h);\n" + + " ^^\n" + + "The method e2(H) is ambiguous for the type X\n" + + "----------\n" + + "30. ERROR in X.java (at line 86)\n" + + " x.e2(hraw);\n" + + " ^^\n" + + "The method e2(H) is ambiguous for the type X\n" + + "----------\n" + + "31. WARNING in X.java (at line 98)\n" + ) + + " class C extends B implements I {}\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 + public void test015() { + this.runConformTest( + new String[] { + "E.java", + "public class E {\n" + + " public static void main(String[] s) {\n" + + " IJ ij = new K();\n" + + " try { ij.m(); } catch(E11 e) {}\n" + + " }\n" + + "}\n" + + "interface I { void m() throws E1; }\n" + + "interface J { void m() throws E11; }\n" + + "interface IJ extends I, J {}\n" + + "class K implements IJ { public void m() {} }\n" + + "class E1 extends Exception { static final long serialVersionUID = 1; }\n" + + "class E11 extends E1 { static final long serialVersionUID = 2; }\n" + + "class E2 extends Exception { static final long serialVersionUID = 3; }" + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 + public void _test016() { + this.runConformTest( + new String[] { + "E.java", + "public class E {\n" + + " public static void main(String[] s) {\n" + + " IJ ij = new K();\n" + + " try { ij.m(); } catch(E11 e) {}\n" + + " }\n" + + "}\n" + + "interface I { void m() throws E1; }\n" + + "interface J { void m() throws E2, E11; }\n" + + "interface IJ extends I, J {}\n" + + "class K implements IJ { public void m() {} }\n" + + "class E1 extends Exception { static final long serialVersionUID = 1; }\n" + + "class E11 extends E1 { static final long serialVersionUID = 2; }\n" + + "class E2 extends Exception { static final long serialVersionUID = 3; }" + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 + public void _test016a() { + this.runNegativeTest( + new String[] { + "E.java", + "public class E {\n" + + " public static void main(String[] s) {\n" + + " IJ ij = new K();\n" + + " ij.m();\n" + + " try { ij.m(); } catch(E2 e) {}\n" + + " }\n" + + "}\n" + + "interface I { void m() throws E1; }\n" + + "interface J { void m() throws E2, E11; }\n" + + "interface IJ extends I, J {}\n" + + "class K implements IJ { public void m() {} }\n" + + "class E1 extends Exception { static final long serialVersionUID = 1; }\n" + + "class E11 extends E1 { static final long serialVersionUID = 2; }\n" + + "class E2 extends Exception { static final long serialVersionUID = 3; }" + }, + "----------\n" + + "1. ERROR in E.java (at line 4)\r\n" + + " ij.m();\r\n" + + " ^^^^^^\n" + + "Unhandled exception type E11\n" + + "----------\n" + + "2. ERROR in E.java (at line 5)\r\n" + + " try { ij.m(); } catch(E2 e) {}\r\n" + + " ^^^^^^\n" + + "Unhandled exception type E11\n" + + "----------\n" + + "3. ERROR in E.java (at line 5)\r\n" + + " try { ij.m(); } catch(E2 e) {}\r\n" + + " ^^\n" + + "Unreachable catch block for E2. This exception is never thrown from the try statement body\n" + + "----------\n" + // 4: unreported exception E11; must be caught or declared to be thrown + // 5: exception E2 is never thrown in body of corresponding try statement + // 5: unreported exception E11; must be caught or declared to be thrown + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=149893 + public void test017() { + this.runConformTest( + new String[] { + "AbstractFilter.java", + "import java.util.*;\n" + + "public class AbstractFilter implements IFilter {\n" + + " public final boolean selekt(E obj) { return true; }\n" + + " public final List filter(List elements) {\n" + + " if ((elements == null) || (elements.size() == 0)) return elements;\n" + + " List okElements = new ArrayList(elements.size());\n" + + " for (E obj : elements) {\n" + + " if (selekt(obj)) okElements.add(obj);\n" + + " }\n" + + " return okElements;" + + " }\n" + + "}\n" + + "interface IFilter {\n" + + " boolean selekt(E obj);\n" + + " List filter(List elements);\n" + + "}" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 + public void test018() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) + return; + this.runConformTest( + new String[] { + "Y.java", + "class X {\n" + + " public static X make(Class clazz) {\n" + + " System.out.print(false);\n" + + " return new X();\n" + + " }\n" + + "}\n" + + "public class Y extends X {\n" + + " public static Y make(Class clazz) {\n" + + " System.out.print(true);\n" + + " return new Y();\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " Y.make(String.class);\n" + + " }\n" + + "}" + }, + "true"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 + // in fact, Y make(Class clazz) is the most + // specific method according to JLS 15.12.2.5 + public void test019() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) + return; + + this.runConformTest( + new String[] { + "Y.java", + "class X {\n" + + " public static X make(Class clazz) {\n" + + " System.out.print(false);\n" + + " return new X();\n" + + " }\n" + + "}\n" + + "public class Y extends X {\n" + + " public static Y make(Class clazz) {\n" + + " System.out.print(true);\n" + + " return new Y();\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " Y.make(getClazz());\n" + + " }\n" + + " public static Class getClazz() {\n" + + " return String.class;\n" + + " }\n" + + "}" + }, + "true"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 + public void test020() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) + return; + this.runConformTest( + new String[] { + "Y.java", + "class X {\n" + + " public static X make(Class clazz) {\n" + + " System.out.print(true);\n" + + " return new X();\n" + + " }\n" + + "}\n" + + "public class Y extends X {\n" + + " public static Y make(Class clazz) {\n" + + " System.out.print(false);\n" + + " return new Y();\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " Y.make(getClazz().newInstance().getClass());\n" + + " }\n" + + " public static Class getClazz() {\n" + + " return String.class;\n" + + " }\n" + + "}" + }, + "true"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 + // variant: having both methods in the same class should not change anything + public void test021() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in Y.java (at line 3)\n" + + " public class Y extends X {\n" + + " ^^^^^^\n" + + "The type parameter V should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in Y.java (at line 4)\n" + + " public static Y make(Class clazz) {\n" + + " ^^^^^^\n" + + "The type parameter W should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "3. WARNING in Y.java (at line 4)\n" + + " public static Y make(Class clazz) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method make(Class) is the same as another method in type Y\n" + + "----------\n" + + "4. WARNING in Y.java (at line 8)\n" + + " public static X make(Class clazz) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method make(Class) is the same as another method in type Y\n" + + "----------\n" + + "5. WARNING in Y.java (at line 13)\n" + + " Y.make(getClazz());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation make(Class) of the generic method make(Class) of type Y\n" + + "----------\n" + + "6. WARNING in Y.java (at line 13)\n" + + " Y.make(getClazz());\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n" + + "7. WARNING in Y.java (at line 15)\n" + + " public static Class getClazz() {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n": + "----------\n" + + "1. WARNING in Y.java (at line 3)\n" + + " public class Y extends X {\n" + + " ^^^^^^\n" + + "The type parameter V should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in Y.java (at line 4)\n" + + " public static Y make(Class clazz) {\n" + + " ^^^^^^\n" + + "The type parameter W should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "3. ERROR in Y.java (at line 4)\n" + + " public static Y make(Class clazz) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method make(Class) is the same as another method in type Y\n" + + "----------\n" + + "4. ERROR in Y.java (at line 8)\n" + + " public static X make(Class clazz) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method make(Class) is the same as another method in type Y\n" + + "----------\n" + + "5. WARNING in Y.java (at line 13)\n" + + " Y.make(getClazz());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation make(Class) of the generic method make(Class) of type Y\n" + + "----------\n" + + "6. WARNING in Y.java (at line 13)\n" + + " Y.make(getClazz());\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n" + + "7. WARNING in Y.java (at line 15)\n" + + " public static Class getClazz() {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "Y.java", + "class X {\n" + + "}\n" + + "public class Y extends X {\n" + + " public static Y make(Class clazz) {\n" + + " System.out.print(true);\n" + + " return new Y();\n" + + " }\n" + + " public static X make(Class clazz) {\n" + + " System.out.print(false);\n" + + " return new X();\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " Y.make(getClazz());\n" + + " }\n" + + " public static Class getClazz() {\n" + + " return String.class;\n" + + " }\n" + + "}" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:8: name clash: make(Class) and make(Class) have the same erasure + public static X make(Class clazz) { + ^ + where U,W are type-variables: + U extends Object declared in method make(Class) + W extends String declared in method make(Class) +X.java:13: warning: [unchecked] unchecked conversion + Y.make(getClazz()); + ^ + required: Class + found: Class + where W#1,W#2 are type-variables: + W#1 extends String declared in method make(Class) + W#2 extends String declared in method make(Class) +X.java:13: warning: [unchecked] unchecked method invocation: method make in class Y is applied to given types + Y.make(getClazz()); + ^ + required: Class + found: Class + where W is a type-variable: + W extends String declared in method make(Class) +1 error +2 warnings + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=147647 + // variant: using instances triggers raw methods, which are ambiguous + public void test022() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class Y extends X {\n" + + " ^^^^^^\n" + + "The type parameter V should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public Y make(Class clazz) {\n" + + " ^^^^^^\n" + + "The type parameter W should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " public Y make(Class clazz) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method make(Class) is the same as another method in type Y\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " public X make(Class clazz) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method make(Class) is the same as another method in type Y\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "7. ERROR in X.java (at line 13)\n" + + " y.make(String.class);\n" + + " ^^^^\n" + + "The method make(Class) is ambiguous for the type Y\n" + + "----------\n" + + "8. ERROR in X.java (at line 14)\n" + + " y.make(getClazz());\n" + + " ^^^^\n" + + "The method make(Class) is ambiguous for the type Y\n" + + "----------\n" + + "9. ERROR in X.java (at line 15)\n" + + " y.make(getClazz().newInstance().getClass());\n" + + " ^^^^\n" + + "The method make(Class) is ambiguous for the type Y\n" + + "----------\n" + + "10. WARNING in X.java (at line 17)\n" + + " public static Class getClazz() {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n": + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class Y extends X {\n" + + " ^^^^^^\n" + + "The type parameter V should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public Y make(Class clazz) {\n" + + " ^^^^^^\n" + + "The type parameter W should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " public Y make(Class clazz) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method make(Class) is the same as another method in type Y\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public X make(Class clazz) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method make(Class) is the same as another method in type Y\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 13)\n" + + " y.make(String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method make(Class) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 14)\n" + + " y.make(getClazz());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method make(Class) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 15)\n" + + " y.make(getClazz().newInstance().getClass());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method make(Class) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "10. WARNING in X.java (at line 17)\n" + + " public static Class getClazz() {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "}\n" + + "class Y extends X {\n" + + " public Y make(Class clazz) {\n" + + " return new Y();\n" + + " }\n" + + " public X make(Class clazz) {\n" + + " return new X();\n" + + " }\n" + + " @SuppressWarnings({\"deprecation\"})\n" + + " public static void main(String[] args) throws Exception {\n" + + " Y y = new Y();\n" + + " y.make(String.class);\n" + + " y.make(getClazz());\n" + + " y.make(getClazz().newInstance().getClass());\n" + + " }\n" + + " public static Class getClazz() {\n" + + " return String.class;\n" + + " }\n" + + "}" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:7: name clash: make(Class) and make(Class) have the same erasure + public X make(Class clazz) { + ^ + where U,W are type-variables: + U extends Object declared in method make(Class) + W extends String declared in method make(Class) +X.java:12: warning: [unchecked] unchecked call to make(Class) as a member of the raw type Y + y.make(String.class); + ^ + where W is a type-variable: + W extends String declared in method make(Class) +X.java:13: warning: [unchecked] unchecked call to make(Class) as a member of the raw type Y + y.make(getClazz()); + ^ + where W is a type-variable: + W extends String declared in method make(Class) +X.java:14: warning: [unchecked] unchecked call to make(Class) as a member of the raw type Y + y.make(getClazz().newInstance().getClass()); + ^ + where W is a type-variable: + W extends String declared in method make(Class) +1 error +3 warnings + */ + } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159711 +public void test023() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void staticFoo(Collection p) {\n" + + " System.out.print(1);\n" + + " }\n" + + " public static > void staticFoo(T p) {\n" + + " System.out.print(2);\n" + + " }\n" + + " public void foo(Collection p) {\n" + + " System.out.print(1);\n" + + " }\n" + + " public > void foo(T p) {\n" + + " System.out.print(2);\n" + + " }\n" + + " public void foo2(Collection p) {\n" + + " System.out.print(1);\n" + + " }\n" + + " public void foo2(List p) {\n" + + " System.out.print(2);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " staticFoo(new ArrayList(Arrays.asList(\"\")));\n" + + " new X().foo(new ArrayList(Arrays.asList(\"\")));\n" + + " new X().foo2(new ArrayList(Arrays.asList(\"\")));\n" + + " }\n" + + "}" + }, + "222"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159711 +// self contained variant +public void test024() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(L1 p) {\n" + + " System.out.println(1);\n" + + " }\n" + + " public static > void foo(T p) {\n" + + " System.out.println(2);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new L3());\n" + + " }\n" + + "}", + "L1.java", + "public interface L1 {\n" + + "}", + "L2.java", + "public interface L2 extends L1 {\n" + + "}", + "L3.java", + "public class L3 implements L2 {\n" + + " public L3() {\n" + + " }\n" + + "}", + }, + "2"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162026 +public void test025() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " J m = new Y();\n" + + " void foo() {\n" + + " m.foo(1.0f);\n" + + " }\n" + + "}", + "I.java", + "public interface I {\n" + + " T foo(final Number p);\n" + + "}", + "J.java", + "public interface J extends I {\n" + + " Float foo(final Number p);\n" + + "}", + "Y.java", + "public class Y implements J {\n" + + " public Float foo(final Number p){\n" + + " return null;\n" + + " }\n" + + "}", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162026 +// variant +public void test026() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " (new Y()).foo(1.0f);\n" + + " }\n" + + "}", + "I.java", + "public interface I {\n" + + " T foo(final Number p);\n" + + "}", + "J.java", + "public interface J extends I {\n" + + " Float foo(final Number p);\n" + + "}", + "Y.java", + "public class Y implements J {\n" + + " public Float foo(final Number p){\n" + + " return null;" + + " }\n" + + "}", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162026 +// variant +public void test027() { + this.runNegativeTest( + new String[] { + "J.java", + "public interface J {\n" + + " T foo(final Number p);\n" + + " Float foo(final Number p);\n" + + "}", + }, + "----------\n" + + "1. ERROR in J.java (at line 2)\n" + + " T foo(final Number p);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method foo(Number) in type J\n" + + "----------\n" + + "2. ERROR in J.java (at line 3)\n" + + " Float foo(final Number p);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method foo(Number) in type J\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +public void test028() { + this.runConformTest( + new String[] { /* test files */ + "X.java", + "interface Irrelevant {}\n" + + "interface I {\n" + + " Object foo(Number n);\n" + + "}\n" + + "interface J extends Irrelevant, I {\n" + + " String foo(Number n);\n" + + "}\n" + + "interface K {\n" + + " Object foo(Number n);\n" + + "}\n" + + "public abstract class X implements J, K {\n" + + " void foo() {\n" + + " foo(0.0f);\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant - simplified +public void test029() { + this.runConformTest( + new String[] { /* test files */ + "X.java", + "interface J {\n" + + " String foo(Number n);\n" + + "}\n" + + "interface K {\n" + + " Object foo(Number n);\n" + + "}\n" + + "public abstract class X implements J, K {\n" + + " void foo() {\n" + + " foo(0.0f);\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant - same return type +public void test030() { + this.runConformTest( + new String[] { + "X.java", + "interface J {\n" + + " Object foo(Number n);\n" + + "}\n" + + "interface K {\n" + + " Object foo(Number n);\n" + + "}\n" + + "public abstract class X implements J, K {\n" + + " void foo() {\n" + + " foo(0.0f);\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant +public void test031() { + this.runConformTest( + new String[] { /* test files */ + "X.java", + "interface Irrelevant {}\n" + + "interface I {\n" + + " Object foo(Number n);\n" + + "}\n" + + "interface J extends Irrelevant, I {\n" + + " String foo(Number n);\n" + + "}\n" + + "interface K {\n" + + " Object foo(Number n);\n" + + "}\n" + + "public abstract class X implements Irrelevant, I, J, K {\n" + + " void foo() {\n" + + " foo(0.0f);\n" + + " }\n" + + "}" + }); +} +// tests 32-34 were moved to MethodVerifyTest 134-140 + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant - the inheriting class implements foo +public void test035() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo(Number n);\n" + + "}\n" + + "abstract class J {\n" + + " abstract String foo(Number n);\n" + + "}\n" + + "public class X extends J implements I {\n" + + " void bar() {\n" + + " foo(0.0f);\n" + // calls X#foo(Number) + " }\n" + + " public String foo(Number n) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant - extending instead of implementing +public void test037() { + this.runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "interface I {\n" + + " Object foo(Number n);\n" + + "}\n" + + "abstract class J {\n" + + " abstract String foo(Number n);\n" + + "}\n" + + "public abstract class X extends J implements I {\n" + + " void bar() {\n" + + " foo(0.0f);\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant - no promotion of parameter from float to Number +public void test038() { + this.runConformTest( + new String[] { /* test files */ + "X.java", + "interface I {\n" + + " Object foo(float f);\n" + + "}\n" + + "abstract class J {\n" + + " public abstract String foo(float f);\n" + + "}\n" + + "public abstract class X extends J implements I {\n" + + " void bar() {\n" + + " foo(0.0f);\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant - an explicit cast solves the issue +public void test039() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo(float f);\n" + + "}\n" + + "abstract class J {\n" + + " public abstract String foo(float f);\n" + + "}\n" + + "public abstract class X extends J implements I {\n" + + " void bar() {\n" + + " String s = ((J) this).foo(0.0f);\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant - an explicit cast solves the issue +public void test040() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo(float f);\n" + + "}\n" + + "abstract class J {\n" + + " public abstract String foo(float f);\n" + + "}\n" + + "public abstract class X extends J implements I {\n" + + " void bar() {\n" + + " Object o = ((I) this).foo(0.0f);\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant - connecting return types +public void test041() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo(float f);\n" + + "}\n" + + "abstract class J {\n" + + " public abstract String foo(float f);\n" + + "}\n" + + "public abstract class X extends J implements I {\n" + + " void bar() {\n" + + " String s = ((I) this).foo(0.0f);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s = ((I) this).foo(0.0f);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to String\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant - a further inheriting class implements String foo +public void test042() { + this.runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "interface I {\n" + + " Object foo(float f);\n" + + "}\n" + + "abstract class J {\n" + + " public abstract String foo(float f);\n" + + "}\n" + + "public abstract class X extends J implements I {\n" + + " void bar() {\n" + + " foo(0.0f);\n" + + " }\n" + + "}\n" + + "class Z extends X {\n" + + " @Override" + + " public String foo(float f) {\n" + + " return null;\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162065 +// variant - a further inheriting class implements Object foo +public void test043() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo(float f);\n" + + "}\n" + + "abstract class J {\n" + + " public abstract String foo(float f);\n" + + "}\n" + + "public abstract class X extends J implements I {\n" + + " void bar() {\n" + + " foo(0.0f);\n" + + " }\n" + + "}\n" + + "class Z extends X {\n" + + " @Override\n" + + " public Object foo(float f) {\n" + // cannot override String foo + " return null;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " public Object foo(float f) {\n" + + " ^^^^^^\n" + + "The return type is incompatible with J.foo(float)\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163370 +public void test044() { + this.runConformTest( + new String[] { + "X.java", + "interface I {}\n" + + "class Y {}\n" + + "public class X> implements I {\n" + + " public static > X bar(X s) {\n" + + " return null;\n" + + " }\n" + + " public static > X bar(I c) {\n" + + " return null;\n" + + " }\n" + + " public static > X foo(X s) {\n" + + " X result = bar(s);\n" + + " return result;\n" + + " }\n" + + "}" + }, + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=165620 +public void test045() { + this.runConformTest( + new String[] { + "X.java", + "abstract class Y implements I {\n" + + "}\n" + + "interface I { \n" + + "}\n" + + "interface J {\n" + + "}\n" + + "class X {\n" + + " public static > V foo(final I a)\n" + + " {\n" + + " return null;\n" + + " }\n" + + " public static > V foo(final Y a)\n" + + " {\n" + + " return null;\n" + + " }\n" + + " public static > void test(final Y a)\n" + + " {\n" + + " foo(a);\n" + + " }\n" + + "}" + }, + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163370 +// variant +public void test046() { + this.runConformTest( + new String[] { + "X.java", + "abstract class Y implements I {\n" + + "}\n" + + "interface I { \n" + + "}\n" + + "interface J {\n" + + "}\n" + + "class X {\n" + + " public static , W extends J> V foo(final I a)\n" + + " {\n" + + " return null;\n" + + " }\n" + + " public static , W extends J> V foo(final Y a)\n" + + " {\n" + + " return null;\n" + + " }\n" + + " public static , W extends J> void test(final Y a)\n" + + " {\n" + + " foo(a);\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 +public void test047() { + this.runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(T t) {\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public int method();\n" + + "}\n" + + "interface J {\n" + + " public boolean method();\n" + + "}\n" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "The return types are incompatible for the inherited methods I.method(), J.method()\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug5061359 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 +// Variant: javac complains as well if we attempt to use method, but noone +// complains upon bar or CONSTANT. +public void test048() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(T t) {\n" + + " t.method();\n" + + " t.bar();\n" + + " if (t.CONSTANT > 0);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public int method();\n" + + " void bar();\n" + + "}\n" + + "interface J {\n" + + " public boolean method();\n" + + " static final int CONSTANT = 0;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "The return types are incompatible for the inherited methods I.method(), J.method()\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " t.method();\n" + + " ^^^^^^\n" + + "The method method() is ambiguous for the type T\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " if (t.CONSTANT > 0);\n" + + " ^^^^^^^^\n" + + "The static field J.CONSTANT should be accessed in a static way\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 +// can't implement both interfaces though +public void test049() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " public int method();\n" + + "}\n" + + "interface J {\n" + + " public boolean method();\n" + + "}\n" + + "class X implements I, J {\n" + + " public int method() {\n" + + " return 0;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " public int method() {\n" + + " ^^^\n" + + "The return type is incompatible with J.method()\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163590 +// variant: secure the legal case +public void test050() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(T t) {\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public int method();\n" + + "}\n" + + "interface J {\n" + + " public int method();\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355 +public void test051() { + this.runNegativeTest( + false /* skipJavac */, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + null : JavacTestOptions.EclipseHasABug.EclipseBug427719, + new String[] { /* test files */ + "X.java", + "interface I {\n" + + "}\n" + + "class Y {\n" + + " void bar(I x) {\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " void foo() {\n" + + " bar(new Z());\n" + + " }\n" + + " void bar(Z x) {\n" + + " }\n" + + " private static final class Z implements I {\n" + + " }\n" + + "}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " bar(new Z());\n" + + " ^^^\n" + + "The method bar(X.Z) is ambiguous for the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " private static final class Z implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + : this.complianceLevel < ClassFileConstants.JDK11 ? + // in 1.8 bar(Z) is recognized as being more specific than bar(I<#RAW>) + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " bar(new Z());\n" + + " ^^^^^^^\n" + + "Access to enclosing constructor X.Z() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " private static final class Z implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " private static final class Z implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n")); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355 +// variant +public void test052() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + "}\n" + + "class Y {\n" + + " void bar(I x) {\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " void foo() {\n" + + " bar(new Z());\n" + + " }\n" + + " void bar(Z x) {\n" + + " }\n" + + " private static final class Z implements I {\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355 +// variant +public void test053() { + this.runNegativeTest( + false /* skipJavac */, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + null : JavacTestOptions.EclipseHasABug.EclipseBug427719, + new String[] { /* test files */ + "X.java", + "interface I {\n" + + "}\n" + + "class Y {\n" + + " void bar(I x) {\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " void foo() {\n" + + " bar(new Z(){});\n" + + " }\n" + + " void bar(Z x) {\n" + + " }\n" + + " private static class Z implements I {\n" + + " }\n" + + "}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " bar(new Z(){});\n" + + " ^^^\n" + + "The method bar(X.Z) is ambiguous for the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " private static class Z implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + : this.complianceLevel < ClassFileConstants.JDK11 ? + // in 1.8 bar(Z) is recognized as being more specific than bar(I<#RAW>) + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " bar(new Z(){});\n" + + " ^^^\n" + + "Access to enclosing constructor X.Z() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " private static class Z implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " private static class Z implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n")); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355 +// variant +public void test054() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar(Z x) {\n" + + " System.out.println(\"bar(Z)\");\n" + + " }\n" + + " void bar(I x) {\n" + + " System.out.println(\"bar(I)\");\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " (new X()).bar(new Z());\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "class Z implements I {}" + }, + "bar(Z)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166355 +// variant +public void _test055() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "class X {\n" + + " void bar(Z x) {\n" + + " System.out.println(\"bar(Z)\");\n" + + " }\n" + + " void bar(I x) {\n" + + " System.out.println(\"bar(I)\");\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " (new X()).bar(new Z());\n" + + " }\n" + + "}\n" + + "class Z implements I {}" + }, + "ERR"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184190 +public void test056() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) + return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar(X x) {\n" + + " ZA z = ZA.foo(x);\n" + + " z.toString();\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static Y foo(X x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class YA extends Y {\n" + + " public static YA foo(X x) {\n" + + " return (YA) Y.foo(x);\n" + + " }\n" + + "}\n" + + "class ZA extends YA {\n" + + " public static ZA foo(X x) {\n" + + " return (ZA) Y.foo(x);\n" + + " }\n" + + "}\n" + + "abstract class A {\n" + + "}\n" + + "abstract class B extends A {\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=186382 +public void test057() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " @Override > T4 foo(G4 g) { return super.foo(g); }\n" + + "}\n" + + "class Y extends Z {\n" + + " @Override > T3 foo(G3 g) { return super.foo(g); }\n" + + "}\n" + + "class Z {\n" + + " > T2 foo(G2 g) { return null; }\n" + + "}\n" + + "interface I {}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=188741 +public void test058() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends A {\n" + + " void x(G g) { System.out.print(1); }\n" + + " void x(G g, G g2) { System.out.print(1); }\n" + + " public static void main(String[] s) {\n" + + " H h = new H();\n" + + " new X().x(h);\n" + + " new X().x(h, h);\n" + + " }\n" + + "}\n" + + "class A {\n" + + " void x(T t) { System.out.print(2); }\n" + + " void x(T t, U u) { System.out.print(2); }\n" + + "}\n" + + "class F {}\n" + + "class G extends F {}\n" + + "class H extends G {}" + }, + "11"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=188741 +public void test058a() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends java.util.ArrayList {\n" + + " private static final long serialVersionUID = 1L;\n" + + " public void add(Comparable o) {}\n" + + " public void test() { add(\"hello\"); }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=188960 +public void test059() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " X() {}\n" + + " X(String s) {}\n" + + " X(T t) {}\n" + + " void foo(String s) {}\n" + + " void foo(T t) {}\n" + + "}\n" + + "class NoErrorSubclass extends X {}\n" + + "class StringOnlySubClass extends X {\n" + + " StringOnlySubClass(String s) { super(s); }\n" + + " @Override void foo(String s) { super.foo(s); }\n" + + "}\n" + + "class Test {\n" + + " Object o = new X(\"xyz\");\n" + + " void test(X x) { x.foo(\"xyz\"); }\n" + + "}" + }, + // no error is reported against duplicate constructors - but the call is reported as ambiguous + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " class NoErrorSubclass extends X {}\n" + + " ^^^^^^^^^^^^^^^\n" + + "Duplicate methods named foo with the parameters (T) and (String) are defined by the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " StringOnlySubClass(String s) { super(s); }\n" + + " ^^^^^^^^^\n" + + "The constructor X(String) is ambiguous\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " @Override void foo(String s) { super.foo(s); }\n" + + " ^^^\n" + + "The method foo(String) is ambiguous for the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " Object o = new X(\"xyz\");\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(String) is ambiguous\n" + + "----------\n" + + "5. ERROR in X.java (at line 15)\n" + + " void test(X x) { x.foo(\"xyz\"); }\n" + + " ^^^\n" + + "The method foo(String) is ambiguous for the type X\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=191029 +public void test059a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.TreeMap;\n" + + "class X {\n" + + " void test(TreeMap tm) {\n" + + " TreeMap copy = new TreeMap(tm);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " TreeMap copy = new TreeMap(tm);\n" + + " ^^^^^^^\n" + + "TreeMap is a raw type. References to generic type TreeMap should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " TreeMap copy = new TreeMap(tm);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor TreeMap(SortedMap) belongs to the raw type TreeMap. References to generic type TreeMap should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " TreeMap copy = new TreeMap(tm);\n" + + " ^^^^^^^\n" + + "TreeMap is a raw type. References to generic type TreeMap should be parameterized\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=189933 +public void test060() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void bar(K p) {\n" + + " new Y(p);\n" + + " new Y((J) p);\n" + + " new Y((I) p);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " Y(I p) {}\n" + + " Y(J p) {}\n" + + "}\n" + + "interface I {}\n" + + "interface J extends I {}\n" + + "interface K extends I, J {}" + }, + "" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=189933 +// variant +public void test061() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void bar(K p) {\n" + + " new Y(p);\n" + + " new Y((J) p);\n" + + " new Y((I) p);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " Y(I p) {}\n" + + " Y(J p) {}\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n" + + "interface K extends I, J {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new Y(p);\n" + + " ^^^^^^^^\n" + + "The constructor Y(I) is ambiguous\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " new Y(p);\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " new Y((J) p);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor Y(J) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " new Y((J) p);\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 5)\n" + + " new Y((I) p);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor Y(I) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 5)\n" + + " new Y((I) p);\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=193265 +public void test062() { + this.runConformTest( + new String[] { + "X.java", + "enum E implements I {\n" + + " F;\n" + + "}\n" + + "interface I {}\n" + + "interface Spec {\n" + + " & I> void method(T1 t);\n" + + "}\n" + + "abstract class X implements Spec {\n" + + " public & I> void method(T2 t) {}\n" + + " void test() { method(E.F); }\n" + + "}" + }, + "" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=196254 +public void test063() { + this.runConformTest( + new String[] { + "Test.java", + "interface I {}\n" + + "class X {\n" + + " void method(X that) {}\n" + + "}\n" + + "class Y extends X {\n" + + " @Override void method(X that) { System.out.print(1); }\n" + + "}\n" + + "public class Test {\n" + + " public static void main(String[] args) { new Y().method((X) null); }\n" + + "}" + }, + "1" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=198120 +public void test064() { + this.runConformTest( + new String[] { + "A.java", + "interface I {\n" + + " void x(I i);\n" + + "}\n" + + "public abstract class A implements I {\n" + + " public void x(I i) {}\n" + + "}\n" + + "class B extends A {\n" + + " void y(A a) { super.x(a); }\n" + + "}" + }, + "" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200547 +public void test065() { + this.runConformTest( + new String[] { + "A.java", + "public abstract class A {\n" + + " abstract > void m(T x);\n" + + "}\n" + + "class B extends A {\n" + + " @Override > void m(T x) {}\n" + + "}" + }, + "" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214558 +public void test066() { + this.runNegativeTest( + new String[] { + "A.java", + "import java.util.*;\n" + + "public class A {\n" + + " void foo(Collection c) {}\n" + + " void foo(Collection c, Object o) {}\n" + + " public static void main(String[] args) {\n" + + " new B().foo(new ArrayList());\n" + + " new B().foo(new ArrayList(), args[0]);\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " void foo(ArrayList a) {}\n" + + " void foo(ArrayList a, Object o) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 6)\n" + + " new B().foo(new ArrayList());\n" + + " ^^^\n" + + "The method foo(ArrayList) is ambiguous for the type B\n" + + "----------\n" + + "2. WARNING in A.java (at line 6)\n" + + " new B().foo(new ArrayList());\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "3. ERROR in A.java (at line 7)\n" + + " new B().foo(new ArrayList(), args[0]);\n" + + " ^^^\n" + + "The method foo(ArrayList, Object) is ambiguous for the type B\n" + + "----------\n" + + "4. WARNING in A.java (at line 7)\n" + + " new B().foo(new ArrayList(), args[0]);\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "5. WARNING in A.java (at line 11)\n" + + " void foo(ArrayList a) {}\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "6. WARNING in A.java (at line 12)\n" + + " void foo(ArrayList a, Object o) {}\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214558 - positive case +public void test067() { + this.runConformTest( + new String[] { + "A.java", + "import java.util.*;\n" + + "public class A {\n" + + " void foo(Collection c) {}\n" + + " public static void main(String[] args) {\n" + + " new B().foo(new ArrayList());\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " void foo(ArrayList a) {System.out.print(1);}\n" + + "}" + }, + "1" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 +public void test068() { + this.runConformTest( + new String[] { + "X.java", + "interface A { X foo(); }\n" + + "interface B extends A { X foo(); }\n" + + "interface C extends B, A {}\n" + + "interface D extends A, B {}\n" + + "public class X {\n" + + " public void bar() {\n" + + " C c = null;\n" + + " X c_b = c.foo();\n" + + " D d = null;\n" + + " X d_b = d.foo();\n" + + " }\n" + + "}" + }, + "" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 - variation +public void test069() { + this.runNegativeTest( + new String[] { + "X.java", + "interface A { X foo(); }\n" + + "interface B extends A { X foo(); }\n" + + "interface C extends B, A {}\n" + + "interface D extends A, B {}\n" + + "public class X {\n" + + " void test(C c, D d) {\n" + + " X c_b = c.foo();\n" + + " X d_b = d.foo();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " interface B extends A { X foo(); }\n" + + " ^^^^^^^^^^^^^^\n" + + "The return type is incompatible with A.foo()\n" + + "----------\n" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 - variation +public void test070() { + this.runNegativeTest( + new String[] { + "X.java", + "interface A { X foo(); }\n" + + "interface B { X foo(); }\n" + + "interface C extends B, A {}\n" + + "interface D extends A, B {}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " C c = null;\n" + + " X c_b = c.foo();\n" + + " D d = null;\n" + + " X d_b = d.foo();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " interface C extends B, A {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods B.foo(), A.foo()\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " interface D extends A, B {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods A.foo(), B.foo()\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " X c_b = c.foo();\n" + + " ^^^\n" + + "The method foo() is ambiguous for the type C\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " X d_b = d.foo();\n" + + " ^^^\n" + + "The method foo() is ambiguous for the type D\n" + + "----------\n" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 - variation +public void test071() { + this.runConformTest( + new String[] { + "Y.java", + "interface I {\n" + + " Integer a();\n" + + " Float b();\n" + + "}\n" + + "interface J {\n" + + " Integer a();\n" + + " Double c();\n" + + "}\n" + + "abstract class X {\n" + + " public abstract Float b();\n" + + " public Double c() { return null; }\n" + + "}\n" + + "abstract class Y extends X implements I, J {\n" + + " void test() {\n" + + " Integer i = a();\n" + + " Float f = b();\n" + + " Double d = c();\n" + + " }\n" + + "}" + }, + "" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 - variation +public void test072() { + this.runConformTest( + new String[] { + "Y.java", + "interface I {\n" + + " Number a();\n" + + " Number b();\n" + + "}\n" + + "interface J {\n" + + " Integer a();\n" + + " Number c();\n" + + "}\n" + + "abstract class X {\n" + + " public abstract Float b();\n" + + " public Double c() { return null; }\n" + + "}\n" + + "abstract class Y extends X implements I, J {\n" + + " void test() {\n" + + " Integer i = a();\n" + + " Float f = b();\n" + + " Double d = c();\n" + + " }\n" + + "}\n" + + "abstract class Y2 extends X implements J, I {\n" + + " void test() {\n" + + " Integer i = a();\n" + + " Float f = b();\n" + + " Double d = c();\n" + + " }\n" + + "}" + }, + "" // javac reports 4 ambiguous errors, 2 each of a() & b() even tho the return types are sustitutable + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251279 - variation +public void test073() { + this.runNegativeTest( + new String[] { + "Y.java", + "interface I {\n" + + " int a();\n" + + " int b();\n" + + "}\n" + + "interface J {\n" + + " byte a();\n" + + " int c();\n" + + "}\n" + + "abstract class X {\n" + + " public abstract byte b();\n" + + " public byte c() { return 1; }\n" + + "}\n" + + "abstract class Y extends X implements I, J {\n" + + " void test() {\n" + + " byte a = a();\n" + + " byte b = b();\n" + + " byte c = c();\n" + + " }\n" + + "}\n" + + "abstract class Y2 extends X implements J, I {\n" + + " void test() {\n" + + " byte a = a();\n" + + " byte b = b();\n" + + " byte c = c();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Y.java (at line 13)\n" + + " abstract class Y extends X implements I, J {\n" + + " ^\n" + + "The return types are incompatible for the inherited methods J.c(), X.c()\n" + + "----------\n" + + "2. ERROR in Y.java (at line 13)\n" + + " abstract class Y extends X implements I, J {\n" + + " ^\n" + + "The return types are incompatible for the inherited methods I.b(), X.b()\n" + + "----------\n" + + "3. ERROR in Y.java (at line 13)\n" + + " abstract class Y extends X implements I, J {\n" + + " ^\n" + + "The return types are incompatible for the inherited methods I.a(), J.a()\n" + + "----------\n" + + "4. ERROR in Y.java (at line 20)\n" + + " abstract class Y2 extends X implements J, I {\n" + + " ^^\n" + + "The return types are incompatible for the inherited methods J.c(), X.c()\n" + + "----------\n" + + "5. ERROR in Y.java (at line 20)\n" + + " abstract class Y2 extends X implements J, I {\n" + + " ^^\n" + + "The return types are incompatible for the inherited methods I.b(), X.b()\n" + + "----------\n" + + "6. ERROR in Y.java (at line 20)\n" + + " abstract class Y2 extends X implements J, I {\n" + + " ^^\n" + + "The return types are incompatible for the inherited methods J.a(), I.a()\n" + + "----------\n" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=206930 +public void test074() { + this.runNegativeTest( + false /* skipJavac */, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + null : JavacTestOptions.EclipseHasABug.EclipseBug427719, + new String[] { + "Y.java", + "interface I {}\n" + + "class A {\n" + + " void a(I x) {}\n" + + " void b(I x) {}\n" + + " void b(I[] x) {}\n" + + " void c(I x) {}\n" + + "}\n" + + "class B extends A {}\n" + + "class C extends B implements I {\n" + + " void a(C c) {}\n" + + " void b(C c) {}\n" + + " void b(C[] c) {}\n" + + " void c(C c) {}\n" + + "}\n" + + "class D extends C {\n" + + " void test() {\n" + + " a(new C());\n" + + " a(new D());\n" + + " b(new C());\n" + // ambiguous b(I) in A and b(C) in C match + " b(new D());\n" + // ambiguous b(I) in A and b(C) in C match + " b(new C[0]);\n" + // ambiguous b(I[]) in A and b(C[]) in C match + " b(new D[0]);\n" + // ambiguous b(I[]) in A and b(C[]) in C match + " c(new C());\n" + // ambiguous c(I) in A and c(C) in C match + " c(new D());\n" + // ambiguous c(I) in A and c(C) in C match + " }\n" + + "}\n" + + "class A2 {\n" + + " void a(I x) {}\n" + + " void b(I x) {}\n" + + " void c(I x) {}\n" + + " void d(I x) {}\n" + + "}\n" + + "class B2 extends A2 {}\n" + + "class C2 extends B2 implements I {\n" + + " void a(C2 c) {}\n" + + " void b(C2 c) {}\n" + + " void c(C2 c) {}\n" + + " void d(C2 c) {}\n" + + "}\n" + + "class D2 extends C2 {\n" + + " void test() {\n" + + " a(new C2());\n" + + " a(new D2());\n" + + " b(new C2());\n" + + " b(new D2());\n" + + " c(new C2());\n" + + " c(new D2());\n" + + " d(new C2());\n" + + " d(new D2());\n" + + " }\n" + + "}\n" + + "public class Y {}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in Y.java (at line 3)\n" + + " void a(I x) {}\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "2. WARNING in Y.java (at line 9)\n" + + " class C extends B implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "3. ERROR in Y.java (at line 19)\n" + + " b(new C());\n" + + " ^\n" + + "The method b(C) is ambiguous for the type D\n" + + "----------\n" + + "4. ERROR in Y.java (at line 20)\n" + + " b(new D());\n" + + " ^\n" + + "The method b(C) is ambiguous for the type D\n" + + "----------\n" + + "5. ERROR in Y.java (at line 21)\n" + + " b(new C[0]);\n" + + " ^\n" + + "The method b(C[]) is ambiguous for the type D\n" + + "----------\n" + + "6. ERROR in Y.java (at line 22)\n" + + " b(new D[0]);\n" + + " ^\n" + + "The method b(C[]) is ambiguous for the type D\n" + + "----------\n" + + "7. ERROR in Y.java (at line 23)\n" + + " c(new C());\n" + + " ^\n" + + "The method c(C) is ambiguous for the type D\n" + + "----------\n" + + "8. ERROR in Y.java (at line 24)\n" + + " c(new D());\n" + + " ^\n" + + "The method c(C) is ambiguous for the type D\n" + + "----------\n" + + "9. WARNING in Y.java (at line 28)\n" + + " void a(I x) {}\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "10. WARNING in Y.java (at line 33)\n" + + " class B2 extends A2 {}\n" + + " ^^\n" + + "A2 is a raw type. References to generic type A2 should be parameterized\n" + + "----------\n" + + "11. WARNING in Y.java (at line 34)\n" + + " class C2 extends B2 implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + : // no ambiguities in 1.8 + "----------\n" + + "1. WARNING in Y.java (at line 3)\n" + + " void a(I x) {}\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "2. WARNING in Y.java (at line 9)\n" + + " class C extends B implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "3. WARNING in Y.java (at line 28)\n" + + " void a(I x) {}\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "4. WARNING in Y.java (at line 33)\n" + + " class B2 extends A2 {}\n" + + " ^^\n" + + "A2 is a raw type. References to generic type A2 should be parameterized\n" + + "----------\n" + + "5. WARNING in Y.java (at line 34)\n" + + " class C2 extends B2 implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n") + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=266421 +public void test075() { + this.runNegativeTest( + new String[] { + "C.java", + "abstract class A {\n" + + " abstract int x(T val);\n" + + "}\n" + + "class B extends A {\n" + + " @Override int x(T val) { return 0; }\n" + + "}\n" + + "class C extends B {\n" + + " int test(Double val) { return x(val); }\n" + + "}" + }, + "----------\n" + + "1. WARNING in C.java (at line 1)\n" + + " abstract class A {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. WARNING in C.java (at line 4)\n" + + " class B extends A {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=268837 +// See that this test case exhibits the bug 345947 +public void test076() { + String output = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " J b();\n" + + " ^^^\n" + + "Name clash: The method b() of type J has the same erasure as b() of type I but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " J b = ints.a();\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from J to J\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " J c = ints.a();\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from J to J\n" + + "----------\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 should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 19)\n" + + " I f = ints.a();\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from J to I\n" + + "----------\n" + + "6. ERROR in X.java (at line 20)\n" + + " I g = ints.a();\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from J to I\n" + + "----------\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 should be parameterized\n" + + "----------\n" + + "8. ERROR in X.java (at line 24)\n" + + " ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\n" + + "9. ERROR in X.java (at line 25)\n" + + " J a = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\n" + + "10. ERROR in X.java (at line 26)\n" + + " J b = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\n" + + "11. ERROR in X.java (at line 27)\n" + + " J c = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\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 should be parameterized\n" + + "----------\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\n" + + "----------\n" + + "14. ERROR in X.java (at line 29)\n" + + " I e = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\n" + + "15. ERROR in X.java (at line 30)\n" + + " I f = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\n" + + "16. ERROR in X.java (at line 31)\n" + + " I g = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\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 should be parameterized\n" + + "----------\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\n" + + "----------\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 should be parameterized\n" + + "----------\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 should be parameterized\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " J b();\n" + + " ^^^\n" + + "Name clash: The method b() of type J has the same erasure as b() of type I but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " J b = ints.a();\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from J to J\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " J c = ints.a();\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from J to J\n" + + "----------\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 should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 19)\n" + + " I f = ints.a();\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from J to I\n" + + "----------\n" + + "6. ERROR in X.java (at line 20)\n" + + " I g = ints.a();\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from J to I\n" + + "----------\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 should be parameterized\n" + + "----------\n" + + "8. ERROR in X.java (at line 24)\n" + + " ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\n" + + "9. ERROR in X.java (at line 25)\n" + + " J a = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\n" + + "10. ERROR in X.java (at line 26)\n" + + " J b = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\n" + + "11. ERROR in X.java (at line 27)\n" + + " J c = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\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 should be parameterized\n" + + "----------\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\n" + + "----------\n" + + "14. ERROR in X.java (at line 29)\n" + + " I e = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\n" + + "15. ERROR in X.java (at line 30)\n" + + " I f = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\n" + + "16. ERROR in X.java (at line 31)\n" + + " I g = ints.b();\n" + + " ^\n" + + "The method b() is ambiguous for the type J\n" + + "----------\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 should be parameterized\n" + + "----------\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\n" + + "----------\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 should be parameterized\n" + + "----------\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 should be parameterized\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " I a();\n" + + " I b();\n" + + " I c();\n" + + "}\n" + + "interface J extends I {\n" + + " J a();\n" + + " J b();\n" + + " J c();\n" + + "}\n" + + "class X {\n" + + " void a(J ints) {\n" + + " ints.a();\n" + + " J a = ints.a();\n" + + " J b = ints.a();\n" + // incompatible types + " J c = ints.a();\n" + // incompatible types + " J d = ints.a();\n" + + " I e = ints.a();\n" + + " I f = ints.a();\n" + // incompatible types + " I g = ints.a();\n" + // incompatible types + " I h = ints.a();\n" + + " }\n" + + " void b(J ints) {\n" + + " ints.b();\n" + // ambiguous + " J a = ints.b();\n" + // ambiguous + " J b = ints.b();\n" + // ambiguous + " J c = ints.b();\n" + // ambiguous + " J d = ints.b();\n" + // ambiguous + " I e = ints.b();\n" + // ambiguous + " I f = ints.b();\n" + // ambiguous + " I g = ints.b();\n" + // ambiguous + " I h = ints.b();\n" + // ambiguous + " }\n" + + " void c(J ints) {\n" + + " ints.c();\n" + + " J a = ints.c();\n" + + " J b = ints.c();\n" + + " J c = ints.c();\n" + + " J d = ints.c();\n" + + " I e = ints.c();\n" + + " I f = ints.c();\n" + + " I g = ints.c();\n" + + " I h = ints.c();\n" + + " }\n" + + "}" + }, + output + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=270194 +public void test077() { + this.runConformTest( + new String[] { + "X.java", + "abstract class X implements I {\n" + + " public , D extends J> A method(A arg) { return null; }\n" + + " void test(Y c) { method(c); }\n" + + "}\n" + + "interface I {\n" + + " , D extends J> A method(A arg);\n" + + "}\n" + + "interface J, D extends J> {}\n" + + "class Y implements J, Y> {}" + }, + "" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=287592 +public void test078() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " class Field { T value; }\n" + + " void a(T value) {}\n" + + " void a(Field field) {}\n" + + " void b(T value) {}\n" + + " void b(Field field) {}\n" + + " void c(String value) {}\n" + + " void c(Field field) {}\n" + + " void test(X x) {\n" + + " x.a(null);\n" + + " x.a(null);\n" + + " x.b(null);\n" + + " x.b(null);\n" + + " x.c(null);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " x.b(null);\n" + + " ^\n" + + "The method b(Number) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " x.b(null);\n" + + " ^\n" + + "The method b(Integer) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " x.c(null);\n" + + " ^\n" + + "The method c(String) is ambiguous for the type X\n" + + "----------\n" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=292350 +// See that this test case exhibits the bug 345947 +public void test079() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "interface One {\n" + + " I x() throws IllegalAccessError;\n" + + " I y() throws IllegalAccessError;\n" + + "}\n" + + "interface Two extends One {\n" + + " I x() throws IllegalAccessError;\n" + + " I y() throws IllegalAccessError;\n" + + "}\n" + + "class X {\n" + + " void x(Two t) { t.x(); }\n" + + " void y(Two t) { t.y(); }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I 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 y() throws IllegalAccessError;\n" + + " ^\n" + + "Type safety: The return type I for y() from the type Two needs unchecked conversion to conform to I from the type One\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=293384 +public void test080() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public abstract class BaseA {};\n" + + " static public abstract class BaseB extends BaseA {};\n" + + " static public class Real extends BaseB {};\n" + + " static BaseA ask(String prompt) {\n" + + " Real impl = new Real();\n" + + " return (BaseA) ask(prompt, impl);\n" + + " }\n" + + " static BaseA ask(String prompt, Real impl) {\n" + + " return null;\n" + + " }\n" + + " static T ask(String prompt, T impl) {\n" + + " return null;\n" + + " }\n" + + " static public void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 +public void test081() { + this.runConformTest( + new String[] { + "C.java", + "class A implements I {\n" + + " public void doSet(ModelType valueGetter) {\n" + + " this.set((ValueType) valueGetter.getObject());\n" + + " }\n" + + " public void set(Object object) {\n" + + " System.out.println(\"In A.set(Object)\");\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " public void set(CharSequence string) {\n" + + " System.out.println(\"In B.set(CharSequence)\");\n" + + " }\n" + + "}\n" + + "public class C extends B {\n" + + " static public void main(String[] args) {\n" + + " C c = new C();\n" + + " c.run();\n" + + " }\n" + + " public void run() {\n" + + " E e = new E(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E extends D {\n" + + " private Class typeClass;\n" + + " public E(Class typeClass) {\n" + + " this.typeClass = typeClass;\n" + + " }\n" + + " public Type getObject() {\n" + + " try {\n" + + " return (Type) typeClass.newInstance();\n" + + " } catch (Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void doSet(ModelType model);\n" + + " public void set(ValueType value);\n" + + "}\n" + + }, + "In B.set(CharSequence)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 +public void test082() { + this.runConformTest( + new String[] { + "C.java", + "class A extends I {\n" + + " public void doSet(ModelType valueGetter) {\n" + + " this.set((ValueType) valueGetter.getObject());\n" + + " }\n" + + " public void set(Object object) {\n" + + " System.out.println(\"In A.set(Object)\");\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " public void set(CharSequence string) {\n" + + " System.out.println(\"In B.set(CharSequence)\");\n" + + " }\n" + + "}\n" + + "public class C extends B {\n" + + " static public void main(String[] args) {\n" + + " C c = new C();\n" + + " c.run();\n" + + " }\n" + + " public void run() {\n" + + " E e = new E(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E extends D {\n" + + " private Class typeClass;\n" + + " public E(Class typeClass) {\n" + + " this.typeClass = typeClass;\n" + + " }\n" + + " public Type getObject() {\n" + + " try {\n" + + " return (Type) typeClass.newInstance();\n" + + " } catch (Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "}\n" + + "abstract class I {\n" + + " public abstract void doSet(ModelType model);\n" + + " public abstract void set(ValueType value);\n" + + "}\n" + + }, + "In B.set(CharSequence)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 +public void test083() { + this.runConformTest( + new String[] { + "C.java", + "class A implements I {\n" + + " public void doSet(ModelType valueGetter) {\n" + + " this.set((ValueType) valueGetter.getObject());\n" + + " }\n" + + " public void set(Object object) {\n" + + " System.out.println(\"In A.set(Object)\");\n" + + " }\n" + + "}\n" + + "class B extends A implements I {\n" + + " public void set(CharSequence string) {\n" + + " System.out.println(\"In B.set(CharSequence)\");\n" + + " }\n" + + "}\n" + + "public class C extends B {\n" + + " static public void main(String[] args) {\n" + + " C c = new C();\n" + + " c.run();\n" + + " }\n" + + " public void run() {\n" + + " E e = new E(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E extends D {\n" + + " private Class typeClass;\n" + + " public E(Class typeClass) {\n" + + " this.typeClass = typeClass;\n" + + " }\n" + + " public Type getObject() {\n" + + " try {\n" + + " return (Type) typeClass.newInstance();\n" + + " } catch (Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void doSet(ModelType model);\n" + + " public void set(ValueType value);\n" + + "}\n" + + }, + "In B.set(CharSequence)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 +public void test084() { + this.runConformTest( + new String[] { + "C.java", + "abstract class A implements I {\n" + + " public void doSet(ModelType valueGetter) {\n" + + " this.set((ValueType) valueGetter.getObject());\n" + + " }\n" + + " public void set(Object object) {\n" + + " System.out.println(\"In A.set(Object)\");\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + "}\n" + + "public class C extends B {\n" + + " static public void main(String[] args) {\n" + + " C c = new C();\n" + + " c.run();\n" + + " }\n" + + " public void run() {\n" + + " E e = new E(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E extends D {\n" + + " private Class typeClass;\n" + + " public E(Class typeClass) {\n" + + " this.typeClass = typeClass;\n" + + " }\n" + + " public Type getObject() {\n" + + " try {\n" + + " return (Type) typeClass.newInstance();\n" + + " } catch (Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void doSet(ModelType model);\n" + + " public void set(ValueType value);\n" + + "}\n" + + }, + "In A.set(Object)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 +public void test085() { + this.runConformTest( + new String[] { + "C.java", + "class A implements I {\n" + + " public void doSet(ModelType valueGetter) {\n" + + " this.set((ValueType) valueGetter.getObject());\n" + + " }\n" + + " public void set(Object object) {\n" + + " System.out.println(\"In A.set(Object)\");\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + "}\n" + + "public class C extends B {\n" + + " static public void main(String[] args) {\n" + + " C c = new C();\n" + + " c.run();\n" + + " }\n" + + " public void run() {\n" + + " E e = new E(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E extends D {\n" + + " private Class typeClass;\n" + + " public E(Class typeClass) {\n" + + " this.typeClass = typeClass;\n" + + " }\n" + + " public Type getObject() {\n" + + " try {\n" + + " return (Type) typeClass.newInstance();\n" + + " } catch (Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void doSet(ModelType model);\n" + + " public void set(ValueType value);\n" + + "}\n" + + }, + "In A.set(Object)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358 +public void test086() { + this.runConformTest( + new String[] { + "C.java", + "class A {\n" + + " public void doSet(ModelType valueGetter) {\n" + + " this.set((ValueType) valueGetter.getObject());\n" + + " }\n" + + " public void set(Object object) {\n" + + " System.out.println(\"In A.set(Object)\");\n" + + " }\n" + + "}\n" + + "class B extends A {\n" + + " public void set(CharSequence string) {\n" + + " System.out.println(\"In B.set(CharSequence)\");\n" + + " }\n" + + "}\n" + + "public class C extends B {\n" + + " static public void main(String[] args) {\n" + + " C c = new C();\n" + + " c.run();\n" + + " }\n" + + " public void run() {\n" + + " E e = new E(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "}\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class E extends D {\n" + + " private Class typeClass;\n" + + " public E(Class typeClass) {\n" + + " this.typeClass = typeClass;\n" + + " }\n" + + " public Type getObject() {\n" + + " try {\n" + + " return (Type) typeClass.newInstance();\n" + + " } catch (Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void doSet(ModelType model);\n" + + " public void set(ValueType value);\n" + + "}\n" + + }, + "In A.set(Object)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=321485 +public void test087() { + String source = + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static List with(List p) { return null; } \n" + + " public static Collection with(Collection p) { return null; }\n" + + " static { with(null); }\n" + + "} \n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( // FIXME: Eclipse has a bug + new String[] { "X.java", source }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " static { with(null); }\n" + + " ^^^^\n" + + "The method with(List) is ambiguous for the type X\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { "X.java", source } + ); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=354579 +public void test088a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int foo () { return 0; } \n" + + " double foo() { return 0.0; }\n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int foo () { return 0; } \n" + + " ^^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " double foo() { return 0.0; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=354579 +public void test088b() { + this.runNegativeTest( + new String[] { + "X.java", + "public interface X {\n" + + " int foo (); \n" + + " double foo();\n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int foo (); \n" + + " ^^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " double foo();\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=354579 +public void test089() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " int m2(List a) {return 0;} \n" + + " double m2(List b) {return 0.0;}\n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int m2(List a) {return 0;} \n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method m2(List) in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " double m2(List b) {return 0.0;}\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method m2(List) in type X\n" + + "----------\n" + ); +} +public void testBug426521() { + runNegativeTest( + new String[] { + "Test.java", + "import java.util.List;\n" + + "\n" + + "class Test {\n" + + " void m(List l, U v) { }\n" + + "\n" + + " void m(List l1, List l2) { }\n" + + "\n" + + " void test(List l) {\n" + + " m(l, l); //JDK 6/7 give ambiguity here - EJC compiles ok\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? "" : + "----------\n" + + "1. ERROR in Test.java (at line 9)\n" + + " m(l, l); //JDK 6/7 give ambiguity here - EJC compiles ok\n" + + " ^\n" + + "The method m(List, Object) is ambiguous for the type Test\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428845 +public void testBug428845() { + runNegativeTest( + new String[] { + "AmbiguousTest.java", + "import java.io.File;\n" + + "public class AmbiguousTest {\n" + + " static interface IInterface {\n" + + " public void method(File file);\n" + + " }\n" + + " static abstract class AbstractClass implements IInterface {\n" + + " public void method(File file) {\n" + + " System.err.println(\"file\");\n" + + " }\n" + + " public void method(String string) {\n" + + " System.err.println(\"string\");\n" + + " }\n" + + " }\n" + + " private static AbstractClass newAbstractClass() {\n" + + " return new AbstractClass() {};\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " newAbstractClass().method(null);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in AmbiguousTest.java (at line 18)\n" + + " newAbstractClass().method(null);\n" + + " ^^^^^^\n" + + "The method method(File) is ambiguous for the type AmbiguousTest.AbstractClass\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=458563 - invalid ambiguous method error on Java 8 that isn't seen on Java 7 (or with javac) +public void testBug458563() { + runConformTest( + new String[] { + "X.java", + "interface IStoredNode extends INodeHandle, NodeHandle { }\n" + + "interface NodeHandle extends INodeHandle { }\n" + + "class DocumentImpl implements INodeHandle {\n" + + " public Object getNodeId() {return null;}\n" + + "}\n" + + "interface INodeHandle {\n" + + " public Object getNodeId();\n" + + "}\n" + + "public class X {\n" + + " public void foo(IStoredNode bar) {\n" + + " bar.getNodeId();\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=458563 - invalid ambiguous method error on Java 8 that isn't seen on Java 7 (or with javac) +public void testBug458563a() { + runConformTest( + new String[] { + "X.java", + "interface IStoredNode extends INodeHandle, NodeHandle { }\n" + + "interface NodeHandle extends INodeHandle { }\n" + + "class DocumentImpl implements INodeHandle {\n" + + " public Object getNodeId() {return null;}\n" + + "}\n" + + "interface INodeHandle {\n" + + " public Object getNodeId();\n" + + "}\n" + + "public class X {\n" + + " public void foo(IStoredNode bar) {\n" + + " bar.getNodeId();\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=466730 - Java 8: single method with generics is ambiguous when using import static ...* and inheritance +public void testBug466730() { + runConformTest( + new String[] { + "bug/Base.java", + "package bug;\n" + + "public class Base {\n" + + " public static Object works() {\n" + + " throw new IllegalStateException();\n" + + " }\n" + + " public static T fails() {\n" + + " throw new IllegalStateException();\n" + + " }\n" + + "}\n", + "bug/Derived.java", + "package bug;\n" + + "public class Derived extends Base {}\n", + "bug/StaticImportBug.java", + "package bug;\n" + + "import static bug.Base.*;\n" + + "import static bug.Derived.*;\n" + + "public class StaticImportBug {\n" + + " void m() {\n" + + " java.util.Objects.requireNonNull(works());\n" + + " java.util.Objects.requireNonNull(fails());\n" + + " }\n" + + "}\n" + }); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java new file mode 100644 index 0000000000..d32ba377d8 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java @@ -0,0 +1,12352 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 295551 - Add option to automatically promote all warnings to error + * bug 185682 - Increment/decrement operators mark local variables as read + * bug 366003 - CCE in ASTNode.resolveAnnotations(ASTNode.java:639) + * bug 384663 - Package Based Annotation Compilation Error in JDT 3.8/4.2 (works in 3.7.2) + * bug 386356 - Type mismatch error with annotations and generics + * bug 331649 - [compiler][null] consider null annotations for fields + * bug 376590 - Private fields with @Inject are ignored by unused field validation + * Bug 392099 - [1.8][compiler][null] Apply null annotation on types for null analysis + * Bug 469584 - ClassCastException in Annotation.detectStandardAnnotation (320) + * Jesper S Moller - Contributions for + * bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration + * bug 412153 - [1.8][compiler] Check validity of annotations which may be repeatable + * Ulrich Grave - Contributions for + * bug 386692 - Missing "unused" warning on "autowired" fields + * Pierre-Yves B. - Contributions for + * bug 542520 - [JUnit 5] Warning The method xxx from the type X is never used locally is shown when using MethodSource + * bug 546084 - Using Junit 5s MethodSource leads to ClassCastException + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Locale; +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.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.Compiler; +import org.eclipse.jdt.internal.compiler.ICompilerRequestor; +import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; +import org.eclipse.jdt.internal.compiler.IProblemFactory; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.IrritantSet; +import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; +import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class AnnotationTest extends AbstractComparableTest { + + // Static initializer to specify tests subset using TESTS_* static variables + // All specified tests which do not belong to the class are skipped... + static { +// TESTS_NAMES = new String[] { "testBug506888c" }; +// TESTS_NUMBERS = new int[] { 297 }; +// TESTS_RANGE = new int[] { 294, -1 }; + } + + String reportMissingJavadocComments = null; + private String repeatableIntroText; + private String repeatableTrailerText; + + public AnnotationTest(String name) { + super(name); + } + + public static Test suite() { + return buildComparableTestSuite(testClass()); + } + + public static Class testClass() { + return AnnotationTest.class; + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, CompilerOptions.PRIVATE); + if (this.reportMissingJavadocComments != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + return options; + } + @Override + protected INameEnvironment getNameEnvironment(String[] testFiles, String[] classPaths, Map options) { + if (this.javaClassLib != null) { + this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths; + return new InMemoryNameEnvironment(testFiles, new INameEnvironment[] {this.javaClassLib }); + } + return super.getNameEnvironment(testFiles, classPaths, options); + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.reportMissingJavadocComments = null; + this.repeatableIntroText = this.complianceLevel >= ClassFileConstants.JDK1_8 ? + "Duplicate annotation of non-repeatable type " + : + "Duplicate annotation "; + this.repeatableTrailerText = this.complianceLevel >= ClassFileConstants.JDK1_8 ? + ". Only annotation types marked @Repeatable can be used multiple times at one target.\n" + : + ". Repeated annotations are allowed only at source level 1.8 or above\n"; + this.javaClassLib = null; // use only in selected tests + } + + public void test001() { + this.runConformTest( + new String[] { + "X.java", + "public @interface X { \n" + + " String value(); \n" + + "}" + }, + ""); + } + + // check invalid annotation + public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public @Foo class X {\n" + + "}\n" + + "\n" + + "@interface Foo {\n" + + " String value();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public @Foo class X {\n" + + " ^^^^\n" + + "The annotation @Foo must define the attribute value\n" + + "----------\n"); + } + + // check annotation method cannot indirectly return annotation type (circular ref) + public void test003() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " Bar value();\n" + + "}\n" + + "\n" + + "@interface Bar {\n" + + " Foo value();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 2)\n" + + " Bar value();\n" + + " ^^^\n" + + "Cycle detected: a cycle exists between annotation attributes of Foo and Bar\n" + + "----------\n" + + "2. ERROR in Foo.java (at line 6)\n" + + " Foo value();\n" + + " ^^^\n" + + "Cycle detected: a cycle exists between annotation attributes of Bar and Foo\n" + + "----------\n"); + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85538 + this.runNegativeTest( + new String[] { + "X.java", + "@interface Nested {\n" + + " String name() default \"Hans\";\n" + + " N2 nest();\n" + + "}\n" + + "@interface N2 {\n" + + " Nested n2() default @Nested(name=\"Haus\", nest= @N2);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " N2 nest();\n" + + " ^^\n" + + "Cycle detected: a cycle exists between annotation attributes of Nested and N2\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Nested n2() default @Nested(name=\"Haus\", nest= @N2);\n" + + " ^^^^^^\n" + + "Cycle detected: a cycle exists between annotation attributes of N2 and Nested\n" + + "----------\n"); + } + + // check annotation method cannot directly return annotation type + public void test004() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " Foo value();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 2)\n" + + " Foo value();\n" + + " ^^^\n" + + "Cycle detected: the annotation type Foo cannot contain attributes of the annotation type itself\n" + + "----------\n"); + } + + // check annotation type cannot have superclass + public void test005() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public @interface Foo extends Object {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 1)\n" + + " public @interface Foo extends Object {\n" + + " ^^^\n" + + "Annotation type declaration cannot have an explicit superclass\n" + + "----------\n"); + } + + // check annotation type cannot have superinterfaces + public void test006() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public @interface Foo implements Cloneable {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 1)\n" + + " public @interface Foo implements Cloneable {\n" + + " ^^^\n" + + "Annotation type declaration cannot have explicit superinterfaces\n" + + "----------\n"); + } + + // check annotation method cannot be specified parameters + // TODO (olivier) unoptimal syntax error -> no parameter for annotation method? + public void test007() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " String value(int i);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 2)\n" + + " String value(int i);\n" + + " ^^^^^^^^^^^^\n" + + "Annotation attributes cannot have parameters\n" + + "----------\n"); + } + + // annotation method cannot be generic? + public void test008() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " T value();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 2)\n" + + " T value();\n" + + " ^\n" + + "Invalid type T for the annotation attribute Foo.value; only primitive type, String, Class, annotation, enumeration are permitted or 1-dimensional arrays thereof\n" + + "----------\n" + + "2. ERROR in Foo.java (at line 2)\n" + + " T value();\n" + + " ^^^^^^^\n" + + "Annotation attributes cannot be generic\n" + + "----------\n"); + } + + // check annotation method return type + public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " \n" + + " Runnable value();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Runnable value();\n" + + " ^^^^^^^^\n" + + "Invalid type Runnable for the annotation attribute X.value; only primitive type, String, Class, annotation, enumeration are permitted or 1-dimensional arrays thereof\n" + + "----------\n"); + } + + // check annotation method missing return type + // TODO (olivier) we should get rid of syntax error here (tolerate invalid constructor scenario) + public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " \n" + + " value();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " value();\n" + + " ^^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n"); + } + + // check annotation denotes annotation type + public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "@Object\n" + + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Object\n" + + " ^^^^^^\n" + + "Object is not an annotation type\n" + + "----------\n"); + } + + // check for duplicate annotations + public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + "@Foo @Foo\n" + + "public class X {\n" + + "}\n" + + "@interface Foo {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Foo @Foo\n" + + " ^^^^\n" + + this.repeatableIntroText + "@Foo"+ this.repeatableTrailerText + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " @Foo @Foo\n" + + " ^^^^\n" + + this.repeatableIntroText + "@Foo"+ this.repeatableTrailerText + + "----------\n"); + } + + // check single member annotation - no need to specify value if member has default value + public void test013() { + this.runConformTest( + new String[] { + "X.java", + "@Foo(\"hello\") public class X {\n" + + "}\n" + + "\n" + + "@interface Foo {\n" + + " String id() default \"\";\n" + + " String value() default \"\";\n" + + "}\n" + }, + ""); + } + + // check single member annotation - need to speficy value if member has no default value + public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + "@Foo(\"hello\") public class X {\n" + + "}\n" + + "\n" + + "@interface Foo {\n" + + " String id() default \"\";\n" + + " String value() default \"\";\n" + + " String foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Foo(\"hello\") public class X {\n" + + " ^^^^\n" + + "The annotation @Foo must define the attribute foo\n" + + "----------\n"); + } + + // check normal annotation - need to speficy value if member has no default value + public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + "@Foo(\n" + + " id = \"hello\") public class X {\n" + + "}\n" + + "\n" + + "@interface Foo {\n" + + " String id() default \"\";\n" + + " String value() default \"\";\n" + + " String foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Foo(\n" + + " ^^^^\n" + + "The annotation @Foo must define the attribute foo\n" + + "----------\n"); + } + + // check normal annotation - if single member, no need to be named 'value' + public void test016() { + this.runConformTest( + new String[] { + "X.java", + "@interface Name {\n" + + " String first();\n" + + " String last();\n" + + "}\n" + + "@interface Author {\n" + + " Name name();\n" + + "}\n" + + "public class X {\n" + + " \n" + + " @Author(name = @Name(first=\"Bill\", last=\"Yboy\")) \n" + + " void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + } + + // check single member annotation can only refer to 'value' member + public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Name {\n" + + " String first();\n" + + " String last();\n" + + "}\n" + + "@interface Author {\n" + + " Name name();\n" + + "}\n" + + "@Author(@Name(first=\"Joe\",last=\"Hacker\")) \n" + + "public class X {\n" + + " \n" + + " @Author(name = @Name(first=\"Bill\", last=\"Yboy\")) \n" + + " void foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " @Author(@Name(first=\"Joe\",last=\"Hacker\")) \n" + + " ^^^^^^^\n" + + "The annotation @Author must define the attribute name\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " @Author(@Name(first=\"Joe\",last=\"Hacker\")) \n" + + " ^^^^^\n" + + "The attribute value is undefined for the annotation type Author\n" + + "----------\n"); + } + + // check for duplicate member value pairs + public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Name {\n" + + " String first();\n" + + " String last();\n" + + "}\n" + + "@interface Author {\n" + + " Name name();\n" + + "}\n" + + "public class X {\n" + + " \n" + + " @Author(name = @Name(first=\"Bill\", last=\"Yboy\", last=\"dup\")) \n" + + " void foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " @Author(name = @Name(first=\"Bill\", last=\"Yboy\", last=\"dup\")) \n" + + " ^^^^\n" + + "Duplicate attribute last in annotation @Name\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " @Author(name = @Name(first=\"Bill\", last=\"Yboy\", last=\"dup\")) \n" + + " ^^^^\n" + + "Duplicate attribute last in annotation @Name\n" + + "----------\n", + JavacTestOptions.EclipseJustification.EclipseJustification0001); + } + + // check for duplicate member value pairs - simplified to check javac + public void test018b() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Name {\n" + + " String first();\n" + + " String last();\n" + + "}\n" + + "public class X {\n" + + " @Name(first=\"Bill\", last=\"Yboy\", last=\"dup\")\n" + + " void foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " @Name(first=\"Bill\", last=\"Yboy\", last=\"dup\")\n" + + " ^^^^\n" + + "Duplicate attribute last in annotation @Name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " @Name(first=\"Bill\", last=\"Yboy\", last=\"dup\")\n" + + " ^^^^\n" + + "Duplicate attribute last in annotation @Name\n" + + "----------\n"); + } + // check class annotation member value must be a class literal + public void test019() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Foo {\n" + + " Class value() default X.clazz();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @Foo( clazz() )\n" + + " void foo() {}\n" + + " static Class clazz() { return X.class; }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " Class value() default X.clazz();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " Class value() default X.clazz();\n" + + " ^^^^^^^^^\n" + + "The value for annotation attribute Foo.value must be a class literal\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " @Foo( clazz() )\n" + + " ^^^^^^^\n" + + "The value for annotation attribute Foo.value must be a class literal\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " static Class clazz() { return X.class; }\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); + } + + // check primitive annotation member value must be a constant + public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Foo {\n" + + " int value() default X.val();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @Foo( val() )\n" + + " void foo() {}\n" + + " static int val() { return 0; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int value() default X.val();\n" + + " ^^^^^^^\n" + + "The value for annotation attribute Foo.value must be a constant expression\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " @Foo( val() )\n" + + " ^^^^^\n" + + "The value for annotation attribute Foo.value must be a constant expression\n" + + "----------\n"); + } + + // check String annotation member value must be a constant + public void test021() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Foo {\n" + + " String value() default X.val();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @Foo( val() )\n" + + " void foo() {}\n" + + " static String val() { return \"\"; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " String value() default X.val();\n" + + " ^^^^^^^\n" + + "The value for annotation attribute Foo.value must be a constant expression\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " @Foo( val() )\n" + + " ^^^^^\n" + + "The value for annotation attribute Foo.value must be a constant expression\n" + + "----------\n"); + } + // check String annotation member value must be a constant + public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Foo {\n" + + " String[] value() default null;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @Foo( null )\n" + + " void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " String[] value() default null;\n" + + " ^^^^\n" + + "The value for annotation attribute Foo.value must be a constant expression\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " @Foo( null )\n" + + " ^^^^\n" + + "The value for annotation attribute Foo.value must be a constant expression\n" + + "----------\n"); + } + + // check use of array initializer + public void test023() { + this.runConformTest( + new String[] { + "X.java", + "@interface Foo {\n" + + " String[] value() default {};\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @Foo( {} )\n" + + " void foo() {}\n" + + "}\n" + }, + ""); + } + + // check use of binary annotation - check referencing binary annotation + public void test024() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " String[] value() default {};\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo({})\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test025() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " String[] value() default {};\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test026() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " int value() default 8;\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test027() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " byte value() default (byte)255;\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test028() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " boolean value() default true;\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test029() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " char value() default ' ';\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test030() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " short value() default (short)1024;\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test031() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " double value() default 0.0;\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test032() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " float value() default -0.0f;\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test033() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " long value() default 1234567890L;\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test034() { + this.runConformTest( + new String[] { + "Foo.java", + "public @interface Foo {\n" + + " String value() default \"Hello, World\";\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test035() { + this.runConformTest( + new String[] { + "Foo.java", + "enum E {\n" + + " CONST1\n" + + "}\n" + + "@interface Foo {\n" + + " E value() default E.CONST1;\n" + + "}" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test036() { + this.runConformTest( + new String[] { + "Foo.java", + "@interface Foo {\n" + + " Class value() default Object.class;\n" + + "}" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test037() { + this.runConformTest( + new String[] { + "Foo.java", + "@interface Y {\n" + + " int id() default 8;\n" + + " Class type();\n" + + "}\n" + + "public @interface Foo {\n" + + " Y value() default @Y(id=10,type=Object.class);\n" + + "}" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @Foo()\n" + + " void foo() {}\n" + + "}\n" + }, + "", + null, + false, + null); + } + + // check use of binary annotation - check default value presence + public void test038() { + this.runConformTest( + new String[] { + "Foo.java", + "@interface Foo {\n" + + " int id() default 8;\n" + + " Class type();\n" + + "}" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "@Foo(type=String.class) public class X {\n" + + "}" + }, + "", + null, + false, + null); + } + + // check annotation member modifiers + public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " native int id() default 0;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " native int id() default 0;\n" + + " ^^^^\n" + + "Illegal modifier for the annotation attribute X.id; only public & abstract are permitted\n" + + "----------\n"); + } + + // check annotation member modifiers (validity unchanged despite grammar change from JSR 335 - default methods) + // and https://bugs.eclipse.org/bugs/show_bug.cgi?id=3383968 + public void test039a() { + String extra = this.complianceLevel < ClassFileConstants.JDK17 ? "" : + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " strictfp double val() default 0.1;\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n"; + int offset = this.complianceLevel < ClassFileConstants.JDK17 ? 0 : 1; + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " strictfp double val() default 0.1;\n" + + " synchronized String id() default \"zero\";\n" + + "}" + }, + extra + + "----------\n" + + (1 + offset) + ". ERROR in X.java (at line 2)\n" + + " strictfp double val() default 0.1;\n" + + " ^^^^^\n" + + "Illegal modifier for the annotation attribute X.val; only public & abstract are permitted\n" + + "----------\n" + + (2 + offset) + ". ERROR in X.java (at line 3)\n" + + " synchronized String id() default \"zero\";\n" + + " ^^^^\n" + + "Illegal modifier for the annotation attribute X.id; only public & abstract are permitted\n" + + "----------\n"); + } + + // check annotation array field initializer + public void test040() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " int[] tab;\n" + + " int[] value();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int[] tab;\n" + + " ^^^\n" + + "The blank final field tab may not have been initialized\n" + + "----------\n"); + } + + // check annotation array field initializer + public void test041() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " int[] tab = value();\n" + + " int[] value();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int[] tab = value();\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static method value() from the type X\n" + + "----------\n"); + } + + // check annotation array field initializer + public void test042() { + this.runConformTest( + new String[] { + "X.java", + "public @interface X {\n" + + " int[] tab = { 0 , \"aaa\".length() };\n" + + "}\n" + }, + ""); + } + + // check annotation field initializer + public void test043() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " int value;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int value;\n" + + " ^^^^^\n" + + "The blank final field value may not have been initialized\n" + + "----------\n"); + } + + // check annotation field initializer + public void test044() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " protected int value = 0;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " protected int value = 0;\n" + + " ^^^^^\n" + + "Illegal modifier for the annotation field X.value; only public, static & final are permitted\n" + + "----------\n"); + } + + // check incompatible default values + public void test045() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface X {\n" + + " int id () default 10L; \n" + + " int[] ids() default { 10L };\n" + + " Class cls() default new Object();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int id () default 10L; \n" + + " ^^^\n" + + "Type mismatch: cannot convert from long to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " int[] ids() default { 10L };\n" + + " ^^^\n" + + "Type mismatch: cannot convert from long to int\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " Class cls() default new Object();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Class cls() default new Object();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Class\n" + + "----------\n"); + } + + // check need for constant pair value + public void test046() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface I {\n" + + " boolean val() default true;\n" + + "}\n" + + "\n" + + "public class X {\n" + + "\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + " @I(val = bar()) void foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " @I(val = bar()) void foo() {\n" + + " ^^^^^\n" + + "The value for annotation attribute I.val must be a constant expression\n" + + "----------\n"); + } + + // check array handling of singleton + public void test047() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " boolean[] val() default {true};\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(val = false) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(val={false})\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + + ClassFileReader fileReader = ClassFileReader.read(new File(OUTPUT_DIR + File.separator +"I.class")); + assertEquals("Not an annotation type declaration", TypeDeclaration.ANNOTATION_TYPE_DECL, TypeDeclaration.kind(fileReader.getModifiers())); + } + + // check invalid constant in array initializer + public void test048() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface I {\n" + + " boolean[] value();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(value={false, X.class != null }) void foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " @I(value={false, X.class != null }) void foo() {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The value for annotation attribute I.value must be a constant expression\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79349 + public void test049() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Target(ElementType.TYPE)\n" + + "@interface MyAnn {\n" + + " String value() default \"Default Message\";\n" + + "}\n" + + "\n" + + "@MyAnn\n" + + "public class X {\n" + + " public @MyAnn void something() { } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " public @MyAnn void something() { } \n" + + " ^^^^^^\n" + + "The annotation @MyAnn is disallowed for this location\n" + + "----------\n"); + } + + // check array handling of singleton + public void test050() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " String[] value();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(\"Hello\") void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value={\"Hello\"})\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + + public void test051() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " String value() default \"Hello\";\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(\"Hi\") void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value=\"Hi\")\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + + public void test052() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " int value() default 0;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(2) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value=(int) 2)\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + public void test053() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " byte value() default 0;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(2) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value=(byte) 2)\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + public void test054() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " short value() default 0;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(2) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value=(short) 2)\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + public void test055() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " char value() default ' ';\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I('@') void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value=\'@\')\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + public void test056() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " long value() default 6;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(Long.MAX_VALUE) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value=9223372036854775807L)\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + public void test057() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " float value();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(-0.0f) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value=-0.0f)\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + public void test058() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " double value();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(-0.0) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value=-0.0)\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + + public void test059() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface Foo {\n" + + " double value() default 0.0;\n" + + " int id();\n" + + "}\n" + + "@interface I {\n" + + " Foo value();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(@Foo(id=5)) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value=@Foo(id=(int) 5))\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + + public void test060() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "enum Color {" + + " BLUE, RED, GREEN\n" + + "}\n" + + "@interface I {\n" + + " Color value() default Color.GREEN;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(Color.RED) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value=Color.RED)\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + public void test061() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "enum Color {" + + " BLUE, RED, GREEN\n" + + "}\n" + + "@interface I {\n" + + " Color[] value() default { Color.GREEN };\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(Color.RED) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(value={Color.RED})\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + public void test062() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface Foo {\n" + + " double value() default 0.0;\n" + + " int id() default 0;\n" + + "}\n" + + "enum Color {" + + " BLUE, RED, GREEN\n" + + "}\n" + + "@interface I {\n" + + " Color[] enums() default { Color.GREEN };\n" + + " Foo[] annotations() default { @Foo() };\n" + + " int[] ints() default { 0, 1, 2, 3 };\n" + + " byte[] bytes() default { 0 };\n" + + " short[] shorts() default { 0 };\n" + + " long[] longs() default { Long.MIN_VALUE, Long.MAX_VALUE };\n" + + " String[] strings() default { \"\" };\n" + + " boolean[] booleans() default { true, false };\n" + + " float[] floats() default { Float.MAX_VALUE };\n" + + " double[] doubles() default { Double.MAX_VALUE };\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(enums=Color.RED,\n" + + " annotations=@Foo(),\n" + + " ints=2,\n" + + " bytes=1,\n" + + " shorts=5,\n" + + " longs=Long.MIN_VALUE,\n" + + " strings=\"Hi\",\n" + + " booleans=true,\n" + + " floats=0.0f,\n" + + " doubles=-0.0) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " @I(enums={Color.RED},\n" + + " annotations={@Foo},\n" + + " ints={(int) 2},\n" + + " bytes={(byte) 1},\n" + + " shorts={(short) 5},\n" + + " longs={-9223372036854775808L},\n" + + " strings={\"Hi\"},\n" + + " booleans={true},\n" + + " floats={0.0f},\n" + + " doubles={-0.0})\n" + + " void foo();"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } + } + public void test063() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface Foo {\n" + + " double value() default 0.0;\n" + + " int id() default 0;\n" + + "}\n" + + "enum Color {" + + " BLUE, RED, GREEN\n" + + "}\n" + + "@interface I {\n" + + " Color enums() default Color.GREEN;\n" + + " Foo annotations() default @Foo();\n" + + " int ints() default 0;\n" + + " byte bytes() default 0;\n" + + " short shorts() default 0;\n" + + " long longs() default Long.MIN_VALUE;\n" + + " String strings() default \"\";\n" + + " boolean booleans() default true;\n" + + " float floats() default Float.MAX_VALUE;\n" + + " double doubles() default Double.MAX_VALUE;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(enums=Color.RED,\n" + + " annotations=@Foo(),\n" + + " ints=2,\n" + + " bytes=1,\n" + + " shorts=5,\n" + + " longs=Long.MIN_VALUE,\n" + + " strings=\"Hi\",\n" + + " booleans=true,\n" + + " floats=0.0f,\n" + + " doubles=-0.0) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " @I(enums=Color.RED,\n" + + " annotations=@Foo,\n" + + " ints=(int) 2,\n" + + " bytes=(byte) 1,\n" + + " shorts=(short) 5,\n" + + " longs=-9223372036854775808L,\n" + + " strings=\"Hi\",\n" + + " booleans=true,\n" + + " floats=0.0f,\n" + + " doubles=-0.0)\n" + + " void foo();"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } + } + + public void test064() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " String[] names();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(names={\"Hello\"}) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(names={\"Hello\"})\n" + + " void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79848 + public void test065() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " Class[] classes();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(classes = {X.class, I.class}) public void foo(){\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " @I(classes={X,I})\n" + + " public void foo();"; + + if (actualOutput.indexOf(expectedOutput) == -1) { + System.out.println(org.eclipse.jdt.core.tests.util.Util.displayString(actualOutput, 2)); + } + assertTrue("unexpected bytecode sequence", actualOutput.indexOf(expectedOutput) != -1); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79844 + public void test066() { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " short value() default 0;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(2) void foo() {\n" + + " }\n" + + "}\n" + + "\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79844 - variation + public void test067() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface I {\n" + + " int value() default 0L;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(2) void foo() {\n" + + " }\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int value() default 0L;\n" + + " ^^\n" + + "Type mismatch: cannot convert from long to int\n" + + "----------\n"); + } + // 79844 - variation + public void test068() { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " short[] value() default 2;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(2) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79844 - variation + public void test069() { + this.runConformTest( + new String[] { + "X.java", + "@interface I {\n" + + " short[] value() default { 2 };\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(2) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79847 + public void test070() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface I {\n" + + " int[][] ids();\n" + + " Object[][] obs();\n" + + "}\n" + + "\n" + + "public class X {\n" + + "\n" + + " @I(ids = {{1 , 2}, { 3 }}) public void foo(){\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int[][] ids();\n" + + " ^^^^^^^\n" + + "Invalid type int[][] for the annotation attribute I.ids; only primitive type, String, Class, annotation, enumeration are permitted or 1-dimensional arrays thereof\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Object[][] obs();\n" + + " ^^^^^^^^^^\n" + + "Invalid type Object[][] for the annotation attribute I.obs; only primitive type, String, Class, annotation, enumeration are permitted or 1-dimensional arrays thereof\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " @I(ids = {{1 , 2}, { 3 }}) public void foo(){\n" + + " ^^\n" + + "The annotation @I must define the attribute obs\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " @I(ids = {{1 , 2}, { 3 }}) public void foo(){\n" + + " ^^^^^^^\n" + + "The value for annotation attribute I.ids must be a constant expression\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " @I(ids = {{1 , 2}, { 3 }}) public void foo(){\n" + + " ^^^^^\n" + + "The value for annotation attribute I.ids must be a constant expression\n" + + "----------\n"); + } + + public void test071() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface I {\n" + + " int hashCode();\n" + + " Object clone();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(hashCode = 0) public void foo(){\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int hashCode();\n" + + " ^^^^^^^^^^\n" + + "The annotation type I cannot override the method Annotation.hashCode()\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Object clone();\n" + + " ^^^^^^\n" + + "Invalid type Object for the annotation attribute I.clone; only primitive type, String, Class, annotation, enumeration are permitted or 1-dimensional arrays thereof\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Object clone();\n" + + " ^^^^^^^\n" + + "The annotation type I cannot override the method Object.clone()\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " @I(hashCode = 0) public void foo(){\n" + + " ^^\n" + + "The annotation @I must define the attribute clone\n" + + "----------\n"); + } + + // check annotation cannot refer to inherited methods as attributes + public void test072() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface I {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(hashCode = 0) public void foo(){\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @I(hashCode = 0) public void foo(){\n" + + " ^^^^^^^^\n" + + "The attribute hashCode is undefined for the annotation type I\n" + + "----------\n"); + } + + // check code generation of annotation default attribute (autowrapping) + public void test073() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface Foo {\n" + + " double value() default 0.0;\n" + + " int id() default 0;\n" + + "}\n" + + "enum Color {" + + " BLUE, RED, GREEN\n" + + "}\n" + + "@interface I {\n" + + " Color[] enums() default Color.GREEN;\n" + + " Foo[] annotations() default @Foo();\n" + + " int[] ints() default 0;\n" + + " byte[] bytes() default 1;\n" + + " short[] shorts() default 3;\n" + + " long[] longs() default Long.MIN_VALUE;\n" + + " String[] strings() default \"\";\n" + + " boolean[] booleans() default true;\n" + + " float[] floats() default Float.MAX_VALUE;\n" + + " double[] doubles() default Double.MAX_VALUE;\n" + + " Class[] classes() default I.class;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @I(enums=Color.RED,\n" + + " annotations=@Foo(),\n" + + " ints=2,\n" + + " bytes=1,\n" + + " shorts=5,\n" + + " longs=Long.MIN_VALUE,\n" + + " strings=\"Hi\",\n" + + " booleans=true,\n" + + " floats=0.0f,\n" + + " doubles=-0.0) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"I.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "abstract @interface I extends java.lang.annotation.Annotation {\n" + + " \n" + + " // Method descriptor #8 ()[LColor;\n" + + " public abstract Color[] enums() default {Color.GREEN};\n" + + " \n" + + " // Method descriptor #13 ()[LFoo;\n" + + " public abstract Foo[] annotations() default {@Foo};\n" + + " \n" + + " // Method descriptor #16 ()[I\n" + + " public abstract int[] ints() default {(int) 0};\n" + + " \n" + + " // Method descriptor #19 ()[B\n" + + " public abstract byte[] bytes() default {(byte) 1};\n" + + " \n" + + " // Method descriptor #22 ()[S\n" + + " public abstract short[] shorts() default {(short) 3};\n" + + " \n" + + " // Method descriptor #25 ()[J\n" + + " public abstract long[] longs() default {-9223372036854775808L};\n" + + " \n" + + " // Method descriptor #29 ()[Ljava/lang/String;\n" + + " public abstract java.lang.String[] strings() default {\"\"};\n" + + " \n" + + " // Method descriptor #32 ()[Z\n" + + " public abstract boolean[] booleans() default {true};\n" + + " \n" + + " // Method descriptor #34 ()[F\n" + + " public abstract float[] floats() default {3.4028235E38f};\n" + + " \n" + + " // Method descriptor #37 ()[D\n" + + " public abstract double[] doubles() default {1.7976931348623157E308};\n" + + " \n" + + " // Method descriptor #41 ()[Ljava/lang/Class;\n" + + " public abstract java.lang.Class[] classes() default {I};\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } + } + // check code generation of annotation default attribute non array types + public void test074() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface Foo {\n" + + " double value() default 0.0;\n" + + " int id() default 0;\n" + + "}\n" + + "enum Color {" + + " BLUE, RED, GREEN\n" + + "}\n" + + "@interface I {\n" + + " Color _enum() default Color.GREEN;\n" + + " Foo _annotation() default @Foo;\n" + + " int _int() default 0;\n" + + " byte _byte() default 1;\n" + + " short _short() default 3;\n" + + " long _long() default Long.MIN_VALUE;\n" + + " String _string() default \"\";\n" + + " boolean _boolean() default true;\n" + + " float _float() default Float.MAX_VALUE;\n" + + " double _double() default Double.MAX_VALUE;\n" + + " Class _class() default I.class;\n" + + "}\n" + + "public class X {\n" + + " @I(_enum=Color.RED,\n" + + " _annotation=@Foo(),\n" + + " _int=2,\n" + + " _byte=1,\n" + + " _short=5,\n" + + " _long=Long.MIN_VALUE,\n" + + " _string=\"Hi\",\n" + + " _boolean=true,\n" + + " _float=0.0f,\n" + + " _double=-0.0) void foo() {\n" + + " }\n" + + "}\n" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"I.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "abstract @interface I extends java.lang.annotation.Annotation {\n" + + " \n" + + " // Method descriptor #8 ()LColor;\n" + + " public abstract Color _enum() default Color.GREEN;\n" + + " \n" + + " // Method descriptor #13 ()LFoo;\n" + + " public abstract Foo _annotation() default @Foo;\n" + + " \n" + + " // Method descriptor #16 ()I\n" + + " public abstract int _int() default (int) 0;\n" + + " \n" + + " // Method descriptor #19 ()B\n" + + " public abstract byte _byte() default (byte) 1;\n" + + " \n" + + " // Method descriptor #22 ()S\n" + + " public abstract short _short() default (short) 3;\n" + + " \n" + + " // Method descriptor #25 ()J\n" + + " public abstract long _long() default -9223372036854775808L;\n" + + " \n" + + " // Method descriptor #29 ()Ljava/lang/String;\n" + + " public abstract java.lang.String _string() default \"\";\n" + + " \n" + + " // Method descriptor #32 ()Z\n" + + " public abstract boolean _boolean() default true;\n" + + " \n" + + " // Method descriptor #34 ()F\n" + + " public abstract float _float() default 3.4028235E38f;\n" + + " \n" + + " // Method descriptor #37 ()D\n" + + " public abstract double _double() default 1.7976931348623157E308;\n" + + " \n" + + " // Method descriptor #41 ()Ljava/lang/Class;\n" + + " public abstract java.lang.Class _class() default I;\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } + } + // check detection of duplicate target element specification + public void test075() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "\n" + + "@Target ({FIELD, FIELD})\n" + + "@interface Tgt {\n" + + " E[] foo();\n" + + " int[] bar();\n" + + "}\n" + + "enum E {\n" + + " BLEU, BLANC, ROUGE\n" + + "}\n" + + "\n" + + "@Tgt( foo = { E.BLEU, E.BLEU}, bar = { 0, 0} )\n" + + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Target ({FIELD, FIELD})\n" + + " ^^^^^\n" + + "Duplicate element FIELD specified in annotation @Target\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " @Tgt( foo = { E.BLEU, E.BLEU}, bar = { 0, 0} )\n" + + " ^^^^\n" + + "The annotation @Tgt is disallowed for this location\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77463 + public void test076() { + this.runNegativeTest( + new String[] { + "X.java", + "private @interface TestAnnot {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " private @interface TestAnnot {\n" + + " ^^^^^^^^^\n" + + "Illegal modifier for the annotation type TestAnnot; only public & abstract are permitted\n" + + "----------\n"); + } + // check @Override annotation - strictly for superclasses (overrides) and not interfaces (implements) + public void test077() { + String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 + ? "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " void foo() {}\n" + + " ^^^^^\n" + + "The method foo() of type X must override a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " public void baz() {}\n" + + " ^^^^^\n" + + "The method baz() of type X must override a superclass method\n" + + "----------\n" + : "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " void foo() {}\n" + + " ^^^^^\n" + + "The method foo() of type X must override or implement a supertype method\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "class Further {\n" + + " void bar() {}\n" + + "}\n" + + "\n" + + "class Other extends Further {\n" + + "}\n" + + "\n" + + "interface Baz {\n" + + " void baz();\n" + + "}\n" + + "\n" + + "public class X extends Other implements Baz {\n" + + " @Override\n" + + " void foo() {}\n" + + " @Override\n" + + " void bar() {}\n" + + " @Override\n" + + " public void baz() {}\n" + + "}\n" + }, + expectedOutput); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80114 + public void test078() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " X() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X() {}\n" + + " ^^^\n" + + "Annotation type declaration cannot have a constructor\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80014 + public void test079() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "\n" + + "@Retention(RUNTIME)\n" + + "@Target({TYPE})\n" + + "@interface Attr {\n" + + " public int tst() default -1;\n" + + "}\n" + + "\n" + + "@Attr \n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Object e = X.class.getAnnotation(Attr.class);\n" + + " System.out.print(e);\n" + + " }\n" + + "}" + }, + "@Attr(tst=-1)"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80014 + public void test080() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "\n" + + "@Retention(CLASS)\n" + + "@Target({TYPE})\n" + + "@interface Attr {\n" + + " public int tst() default -1;\n" + + "}\n" + + "\n" + + "@Attr \n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Object e = X.class.getAnnotation(Attr.class);\n" + + " System.out.print(e);\n" + + " }\n" + + "}" + }, + "null"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80014 + public void test081() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "\n" + + "@Retention(SOURCE)\n" + + "@Target({TYPE})\n" + + "@interface Attr {\n" + + " public int tst() default -1;\n" + + "}\n" + + "\n" + + "@Attr \n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Object e = X.class.getAnnotation(Attr.class);\n" + + " System.out.print(e);\n" + + " }\n" + + "}" + }, + "null"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80014 + public void test082() { + this.runConformTest( + new String[] { + "Attr.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "\n" + + "@Retention(SOURCE)\n" + + "@Target({TYPE})\n" + + "@interface Attr {\n" + + " public int tst() default -1;\n" + + "}", + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "@Attr \n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Object e = X.class.getAnnotation(Attr.class);\n" + + " System.out.print(e);\n" + + " }\n" + + "}" + }, + "null", + null, + false, + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80014 + public void test083() { + this.runConformTest( + new String[] { + "Attr.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "\n" + + "@Retention(CLASS)\n" + + "@Target({TYPE})\n" + + "@interface Attr {\n" + + " public int tst() default -1;\n" + + "}", + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "@Attr \n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Object e = X.class.getAnnotation(Attr.class);\n" + + " System.out.print(e);\n" + + " }\n" + + "}" + }, + "null", + null, + false, + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80014 + public void test084() { + this.runConformTest( + new String[] { + "Attr.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "\n" + + "@Retention(RUNTIME)\n" + + "@Target({TYPE})\n" + + "@interface Attr {\n" + + " public int tst() default -1;\n" + + "}", + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "@Attr \n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Object e = X.class.getAnnotation(Attr.class);\n" + + " System.out.print(e);\n" + + " }\n" + + "}" + }, + "@Attr(tst=-1)", + null, + false, + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76751 + public void test085() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "\n" + + "public class X {\n" + + "\n" + + " @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @interface\n" + + "TestAnnotation {\n" + + "\n" + + " String testAttribute();\n" + + "\n" + + " }\n" + + " @TestAnnotation(testAttribute = \"test\") class A {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.print(A.class.isAnnotationPresent(TestAnnotation.class));\n" + + " }\n" + + "\n" + + "}" + }, + "true"); + } + // check handling of empty array initializer + public void test086() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target({}) @interface I {}\n" + + "@I public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @I public class X {}\n" + + " ^^\n" + + "The annotation @I is disallowed for this location\n" + + "----------\n"); + } + + // check type targeting annotation also allowed for annotation type + public void test087() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "\n" + + "@Target(TYPE)\n" + + "@interface Annot {\n" + + "}\n" + + "\n" + + "@Annot\n" + + "public @interface X {\n" + + "}\n" + }, + ""); + } + + // check parameter/local target for annotation + public void test088() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "\n" + + "@Target(LOCAL_VARIABLE)\n" + + "@interface Annot {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void foo(@Annot int i) {\n" + + " @Annot int j;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " void foo(@Annot int i) {\n" + + " ^^^^^^\n" + + "The annotation @Annot is disallowed for this location\n" + + "----------\n"); + } + + // Add check for parameter + public void test089() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "\n" + + "public class X {\n" + + "\n" + + " @Target(ElementType.PARAMETER) @interface I {}\n" + + " \n" + + " void m(@I int i){\n" + + " }\n" + + "}" + }, + ""); + } + // Add check that type includes annotation type + public void test090() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "\n" + + "public class X {\n" + + "\n" + + " @Target(ElementType.TYPE) @interface Annot1 {}\n" + + " \n" + + " @Annot1 @interface Annot2 {}\n" + + "}" + }, + ""); + } + // Add check that a field cannot have an annotation targetting TYPE + public void test091() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "\n" + + "public class X {\n" + + "\n" + + " @Target(ElementType.TYPE) @interface Marker {}\n" + + " \n" + + " @Marker static int i = 123;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " @Marker static int i = 123;\n" + + " ^^^^^^^\n" + + "The annotation @X.Marker is disallowed for this location\n" + + "----------\n"); + } + // Add check that a field cannot have an annotation targetting FIELD + public void test092() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "\n" + + "public class X {\n" + + "\n" + + " @Target(ElementType.FIELD) @interface Marker {}\n" + + " \n" + + " @Marker static int i = 123;\n" + + "}" + }, + ""); + } + // @Inherited can only be used on annotation types + public void test093() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Inherited;\n" + + "\n" + + "@Deprecated\n" + + "@Inherited\n" + + "class A {\n" + + "}\n" + + "\n" + + "class B extends A {\n" + + "}\n" + + "\n" + + "class C extends B {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " C c;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Inherited\n" + + " ^^^^^^^^^^\n" + + "The annotation @Inherited is disallowed for this location\n" + + "----------\n"); + } + // check handling of empty array initializer (binary check) + public void test094() { + this.runConformTest( + new String[] { + "I.java", + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target({}) @interface I {}", + }, + ""); + this.runNegativeTest( + new String[] { + "X.java", + "@I public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @I public class X {}\n" + + " ^^\n" + + "The annotation @I is disallowed for this location\n" + + "----------\n", + null, + false, + null); + } + + // check no interaction between Retention and Target (switch fall-thru) + public void test095() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Ann {}\n" + + "\n" + + "public class X {\n" + + " @Ann\n" + + " void foo() {}\n" + + "}\n", + }, + ""); + } + + // check attributes for parameters + public void test096() { + this.runConformTest( + new String[] { + "X.java", + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Annotation;\n" + + "import java.lang.reflect.Method;\n" + + "\n" + + "@Retention(CLASS) @interface Attr {\n" + + "}\n" + + "\n" + + "@Retention(RUNTIME) @interface Foo {\n" + + " int id() default 0;\n" + + "}\n" + + "@Foo(id=5) @Attr public class X {\n" + + " public void foo(@Foo(id=5) @Attr final int j, @Attr final int k, int n) {\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " Class c = X.class;\n" + + " Annotation[] annots = c.getAnnotations();\n" + + " System.out.print(annots.length);\n" + + " Method method = c.getMethod(\"foo\", Integer.TYPE, Integer.TYPE, Integer.TYPE);\n" + + " Annotation[][] annotations = method.getParameterAnnotations();\n" + + " final int length = annotations.length;\n" + + " System.out.print(length);\n" + + " if (length == 3) {\n" + + " System.out.print(annotations[0].length);\n" + + " System.out.print(annotations[1].length);\n" + + " System.out.print(annotations[2].length);\n" + + " }\n" + + " } catch(NoSuchMethodException e) {\n" + + " }\n" + + " }\n" + + "}", + }, + "13100"); + } + + public void test097() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface I {\n" + + " int id default 0;\n" + + "}\n" + + "\n" + + "@I() public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.println(X.class.getAnnotation(I.class));\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int id default 0;\n" + + " ^^^^^^^\n" + + "Syntax error on token \"default\", = expected\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80328 + public void test098() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface I {\n" + + " int id default 0;\n" + + "}\n" + + "\n" + + "@I() public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.println(X.class.getAnnotation(I.class));\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int id default 0;\n" + + " ^^^^^^^\n" + + "Syntax error on token \"default\", = expected\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80780 + public void test099() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.lang.reflect.Method;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object o = new X();\n" + + " for (Method m : o.getClass().getMethods()) {\n" + + " if (m.isAnnotationPresent(MyAnon.class)) {\n" + + " System.out.println(m.getAnnotation(MyAnon.class).c());\n" + + " }\n" + + " }\n" + + " }\n" + + " @MyAnon(c = X.class) \n" + + " public void foo() {}\n" + + "\n" + + " @Retention(RetentionPolicy.RUNTIME) \n" + + " public @interface MyAnon {\n" + + " Class c();\n" + + " }\n" + + " public interface I {\n" + + " }\n" + + "}" + }, + "class X"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String expectedOutput = null; + if (options.targetJDK == ClassFileConstants.JDK1_5) { + expectedOutput = + " Inner classes:\n" + + " [inner class info: #66 X$I, outer class info: #1 X\n" + + " inner name: #68 I, accessflags: 1545 public abstract static],\n" + + " [inner class info: #27 X$MyAnon, outer class info: #1 X\n" + + " inner name: #69 MyAnon, accessflags: 9737 public abstract static]\n"; + } else if (options.targetJDK == ClassFileConstants.JDK1_6) { + expectedOutput = + " Inner classes:\n" + + " [inner class info: #70 X$I, outer class info: #1 X\n" + + " inner name: #72 I, accessflags: 1545 public abstract static],\n" + + " [inner class info: #27 X$MyAnon, outer class info: #1 X\n" + + " inner name: #73 MyAnon, accessflags: 9737 public abstract static]\n"; + } else { + return; + } + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80544 + public void test100() { + this.runConformTest( + new String[] { + "X.java", + "abstract class Foo {\n" + + " abstract protected boolean accept(Object o);\n" + + "}\n" + + "\n" + + "public class X extends Foo {\n" + + " @Override \n" + + " protected boolean accept(Object o) { return false; }\n" + + "}\n", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81148 + public void test101() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(Element)\n" + + "public @interface X {\n" + + " \n" + + " boolean UML() default false;\n" + + " boolean platformDependent() default true;\n" + + " boolean OSDependent() default true;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @Target(Element)\n" + + " ^^^^^^^\n" + + "Element cannot be resolved to a variable\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80964 + public void test102() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @TestAnnotation(testAttribute = \"test\") class A {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(A.class.isAnnotationPresent(TestAnnotation.class));\n" + + " }\n" + + "}", + "TestAnnotation.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface\n" + + "TestAnnotation {\n" + + " String testAttribute();\n" + + "}\n" + }, + "true"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80964 + public void test103() { + this.runConformTest( + new String[] { + "TestAnnotation.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface\n" + + "TestAnnotation {\n" + + " String testAttribute();\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @TestAnnotation(testAttribute = \"test\") class A {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(A.class.isAnnotationPresent(TestAnnotation.class));\n" + + " }\n" + + "}", + }, + "true", + null, + false, + null); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81825 + public void test104() { + this.runConformTest( + new String[] { + "X.java", + "@interface ValuesAnnotation {\n" + + " byte[] byteArrayValue();\n" + + " char[] charArrayValue();\n" + + " boolean[] booleanArrayValue();\n" + + " int[] intArrayValue();\n" + + " short[] shortArrayValue();\n" + + " long[] longArrayValue();\n" + + " float[] floatArrayValue();\n" + + " double[] doubleArrayValue();\n" + + " String[] stringArrayValue();\n" + + " ValuesEnum[] enumArrayValue();\n" + + " ValueAttrAnnotation[] annotationArrayValue();\n" + + " Class[] classArrayValue();\n" + + " byte byteValue();\n" + + " char charValue();\n" + + " boolean booleanValue();\n" + + " int intValue();\n" + + " short shortValue();\n" + + " long longValue();\n" + + " float floatValue();\n" + + " double doubleValue();\n" + + " String stringValue();\n" + + " ValuesEnum enumValue();\n" + + " ValueAttrAnnotation annotationValue();\n" + + " Class classValue();\n" + + "}\n" + + "enum ValuesEnum {\n" + + " ONE, TWO;\n" + + "}\n" + + "\n" + + "@interface ValueAttrAnnotation {\n" + + " String value() default \"\";\n" + + "}\n" + + "@interface ValueAttrAnnotation1 {\n" + + " String value();\n" + + "}\n" + + "@interface ValueAttrAnnotation2 {\n" + + " String value();\n" + + "}\n" + + "@ValuesAnnotation(\n" + + " byteValue = 1,\n" + + " charValue = \'A\',\n" + + " booleanValue = true,\n" + + " intValue = 1,\n" + + " shortValue = 1,\n" + + " longValue = 1L,\n" + + " floatValue = 1.0f,\n" + + " doubleValue = 1.0d,\n" + + " stringValue = \"A\",\n" + + "\n" + + " enumValue = ValuesEnum.ONE,\n" + + " annotationValue = @ValueAttrAnnotation( \"annotation\"),\n" + + " classValue = X.class,\n" + + "\n" + + " byteArrayValue = { 1, -1},\n" + + " charArrayValue = { \'c\', \'b\', (char)-1},\n" + + " booleanArrayValue = {true, false},\n" + + " intArrayValue = { 1, -1},\n" + + " shortArrayValue = { (short)1, (short)-1},\n" + + " longArrayValue = { 1L, -1L},\n" + + " floatArrayValue = { 1.0f, -1.0f},\n" + + " doubleArrayValue = { 1.0d, -1.0d},\n" + + " stringArrayValue = { \"aa\", \"bb\"},\n" + + "\n" + + " enumArrayValue = {ValuesEnum.ONE, ValuesEnum.TWO},\n" + + " annotationArrayValue = {@ValueAttrAnnotation( \"annotation1\"),\n" + + "@ValueAttrAnnotation( \"annotation2\")},\n" + + " classArrayValue = {X.class, X.class}\n" + + ")\n" + + "@ValueAttrAnnotation1( \"classAnnotation1\")\n" + + "@ValueAttrAnnotation2( \"classAnnotation2\")\n" + + "public class X {\n" + + "\n" + + " @ValueAttrAnnotation1( \"fieldAnnotation1\")\n" + + " @ValueAttrAnnotation2( \"fieldAnnotation2\")\n" + + " public String testfield = \"test\";\n" + + "\n" + + " @ValueAttrAnnotation1( \"methodAnnotation1\")\n" + + " @ValueAttrAnnotation2( \"methodAnnotation2\")\n" + + " @ValueAttrAnnotation()\n" + + " public void testMethod( \n" + + " @ValueAttrAnnotation1( \"param1Annotation1\") \n" + + " @ValueAttrAnnotation2( \"param1Annotation2\") String param1, \n" + + " @ValueAttrAnnotation1( \"param2Annotation1\") \n" + + " @ValueAttrAnnotation2( \"param2Annotation2\") int param2) {\n" + + " // @ValueAttrAnnotation( \"codeAnnotation\")\n" + + " }\n" + + "}\n" + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82136 + public void test105() { + this.runConformTest( + new String[] { + "Property.java", + "import java.lang.annotation.Documented;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "public @interface Property\n" + + "{\n" + + " String property();\n" + + " String identifier() default \"\";\n" + + "}", + "Properties.java", + "import java.lang.annotation.Documented;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "public @interface Properties {\n" + + " Property[] value();\n" + + "}", + "X.java", + "@Properties({\n" + + " @Property(property = \"prop\", identifier = \"someIdentifier\"),\n" + + " @Property(property = \"type\")\n" + + "})\n" + + "public interface X {\n" + + " void setName();\n" + + " String getName();\n" + + "}" + }, + ""); + try { + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + new ClassFileReader(classFileBytes, "X.java".toCharArray(), true); + } catch (ClassFormatException e) { + assertTrue("ClassFormatException", false); + } catch (IOException e) { + assertTrue("IOException", false); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83939 + public void test106() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " int[] bar() default null;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int[] bar() default null;\n" + + " ^^^^\n" + + "The value for annotation attribute X.bar must be a constant expression\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83939 + public void test107() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Ann {\n" + + " int[] bar();\n" + + "}\n" + + "@Ann(bar=null) class X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Ann(bar=null) class X {}\n" + + " ^^^^\n" + + "The value for annotation attribute Ann.bar must be a constant expression\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83939 - variation + public void test108() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Foo {}\n" + + "\n" + + "@interface Bar {\n" + + " Foo[] foo() default null;\n" + + "}\n" + + "\n" + + "@Bar(foo=null)\n" + + "public class X { \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Foo[] foo() default null;\n" + + " ^^^^\n" + + "The value for annotation attribute Bar.foo must be some @Foo annotation \n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " @Bar(foo=null)\n" + + " ^^^^\n" + + "The value for annotation attribute Bar.foo must be some @Foo annotation \n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83939 - variation + public void test109() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Foo {}\n" + + "\n" + + "@interface Bar {\n" + + " Foo[] foo() default \"\";\n" + + "}\n" + + "\n" + + "@Bar(foo=\"\")\n" + + "public class X { \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Foo[] foo() default \"\";\n" + + " ^^\n" + + "The value for annotation attribute Bar.foo must be some @Foo annotation \n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " @Bar(foo=\"\")\n" + + " ^^\n" + + "The value for annotation attribute Bar.foo must be some @Foo annotation \n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84791 + public void test110() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "import java.util.Arrays;\n" + + "\n" + + "@interface Ann {\n" + + "}\n" + + "\n" + + "interface Iface extends Ann {\n" + + "}\n" + + "\n" + + "abstract class Klass implements Ann {\n" + + "}\n" + + "\n" + + "class SubKlass extends Klass {\n" + + " public Class annotationType() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = SubKlass.class;\n" + + " System.out.print(\"Classes:\");\n" + + " while (c != Object.class) {\n" + + " System.out.print(\"-> \" + c.getName());\n" + + " c = c.getSuperclass();\n" + + " }\n" + + "\n" + + " System.out.print(\", Interfaces:\");\n" + + " c = SubKlass.class;\n" + + " while (c != Object.class) {\n" + + " Class[] i = c.getInterfaces();\n" + + " System.out.print(\"-> \" + Arrays.asList(i));\n" + + " c = c.getSuperclass();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "Classes:-> SubKlass-> Klass, Interfaces:-> []-> [interface Ann]"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84791 - variation + public void test111() { + Map customOptions = getCompilerOptions(); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotation, + CompilerOptions.ERROR); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, + CompilerOptions.DISABLED); + + String expectedOutput = + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " interface Iface extends Ann {\n" + + " ^^^\n" + + "The annotation type Ann should not be used as a superinterface for Iface\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " abstract class Klass implements Ann {\n" + + " ^^^\n" + + "The annotation type Ann should not be used as a superinterface for Klass\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " class SubKlass extends Klass {\n" + + " ^^^^^^^^\n" + + "The type SubKlass must implement the inherited abstract method Ann.foo()\n" + + "----------\n" + + "4. WARNING in X.java (at line 20)\n" + + " class AnnImpl implements Ann {\n" + + " ^^^\n" + + "The annotation type Ann should not be used as a superinterface for AnnImpl\n" + + "----------\n" + + "5. ERROR in X.java (at line 21)\n" + + " public boolean equals(Object obj) { return false; }\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The method equals(Object) of type AnnImpl should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "6. ERROR in X.java (at line 22)\n" + + " public int hashCode() { return 0; }\n" + + " ^^^^^^^^^^\n" + + "The method hashCode() of type AnnImpl should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "7. ERROR in X.java (at line 23)\n" + + " public String toString() { return null; }\n" + + " ^^^^^^^^^^\n" + + "The method toString() of type AnnImpl should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "8. WARNING in X.java (at line 30)\n" + + " Class c = SubKlass.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 41)\n" + + " Class[] i = c.getInterfaces();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"; + + this.runNegativeTest( + true, + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "import java.util.Arrays;\n" + + "\n" + + "@interface Ann {\n" + + " int foo();\n" + + "}\n" + + "\n" + + "interface Iface extends Ann {\n" + + "}\n" + + "\n" + + "abstract class Klass implements Ann {\n" + + "}\n" + + "\n" + + "class SubKlass extends Klass {\n" + + " public Class annotationType() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class AnnImpl implements Ann {\n" + + " public boolean equals(Object obj) { return false; }\n" + + " public int hashCode() { return 0; }\n" + + " public String toString() { return null; }\n" + + " public Class annotationType() { return null; }\n" + + " public int foo() { return 0; }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = SubKlass.class;\n" + + " System.out.println(\"Classes:\");\n" + + " while (c != Object.class) {\n" + + " System.out.println(\"-> \" + c.getName());\n" + + " c = c.getSuperclass();\n" + + " }\n" + + "\n" + + " System.out.println();\n" + + " System.out.println(\"Interfaces:\");\n" + + " c = SubKlass.class;\n" + + " while (c != Object.class) {\n" + + " Class[] i = c.getInterfaces();\n" + + " System.out.println(\"-> \" + Arrays.asList(i));\n" + + " c = c.getSuperclass();\n" + + " }\n" + + " }\n" + + "}\n", + }, + null, customOptions, + expectedOutput, + JavacTestOptions.SKIP); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86291 + public void test112() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Annot {\n" + + " String foo1() default \"\";\n" + + "}\n" + + "@Annot(foo1=zzz)\n" + + "public class X {\n" + + " static final String zzz = \"\";\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Annot(foo1=zzz)\n" + + " ^^^\n" + + "zzz cannot be resolved to a variable\n" + + "----------\n"); + } + public void test113() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Annot {\n" + + " String foo();\n" + + "}\n" + + "@Annot( foo = new String(){} )\n" + + "public class X {\n" + + " \n" + + " \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Annot( foo = new String(){} )\n" + + " ^^^^^^\n" + + "An anonymous class cannot subclass the final class String\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86291 - variation + public void test114() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Annot {\n" + + " Class foo();\n" + + "}\n" + + "@Annot( foo = M.class )\n" + + "public class X {\n" + + " class M {}\n" + + " \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " Class foo();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " @Annot( foo = M.class )\n" + + " ^\n" + + "M cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86291 - variation + public void test115() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Annot {\n" + + " Class foo();\n" + + " String bar() default \"\";\n" + + "}\n" + + "@Annot(foo = M.class, bar = baz()+s)\n" + + "public class X {\n" + + " class M {\n" + + " }\n" + + " final static String s = \"\";\n" + + " String baz() { return null; }\n" + + " @Annot(foo = T.class, bar = s)\n" + + " T foo(T t, String s) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " Class foo();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " @Annot(foo = M.class, bar = baz()+s)\n" + + " ^\n" + + "M cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " @Annot(foo = M.class, bar = baz()+s)\n" + + " ^^^\n" + + "The method baz() is undefined for the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " @Annot(foo = M.class, bar = baz()+s)\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " @Annot(foo = T.class, bar = s)\n" + + " ^^^^^^^\n" + + "Illegal class literal for the type parameter T\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " T foo(T t, String s) {\n" + + " ^\n" + + "The parameter s is hiding a field from type X\n" + + "----------\n"); + } + // check @Deprecated support + public void test116() { + this.runNegativeTest( + new String[] { + "X.java", + "/** @deprecated */\n" + + "@Deprecated\n" + + "public class X {\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " X x;\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 2)\n" + + " X x;\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "2. ERROR in Y.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @Deprecated support + public void test117() { + this.runNegativeTest( + new String[] { + "X.java", + "@Deprecated\n" + + "public class X {\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " X x;\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 2)\n" + + " X x;\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "2. ERROR in Y.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @Deprecated support + public void test118() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Deprecated {}\n" + + "\n" + + "@Deprecated // not the real @Deprecated interface\n" + + "public class X {\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " X x;\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @Deprecated support + public void test119() { + this.runNegativeTest( + new String[] { + "X.java", + "@Deprecated\n" + + "public class X {\n" + + " void foo(){}\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " void foo(){ super.foo(); }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 1)\n" + + " public class Y extends X {\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "2. WARNING in Y.java (at line 2)\n" + + " void foo(){ super.foo(); }\n" + + " ^^^^^\n" + + "The method foo() of type Y should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "3. WARNING in Y.java (at line 2)\n" + + " void foo(){ super.foo(); }\n" + + " ^^^^^\n" + + "The method foo() from the type X is deprecated\n" + + "----------\n" + + "4. ERROR in Y.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @Deprecated support + public void test120() { + this.runNegativeTest( + new String[] { + "X.java", + "@Deprecated\n" + + "public class X {\n" + + " void foo(){}\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " void foo(){ super.foo(); }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 1)\n" + + " public class Y extends X {\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "2. WARNING in Y.java (at line 2)\n" + + " void foo(){ super.foo(); }\n" + + " ^^^^^\n" + + "The method foo() of type Y should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "3. WARNING in Y.java (at line 2)\n" + + " void foo(){ super.foo(); }\n" + + " ^^^^^\n" + + "The method foo() from the type X is deprecated\n" + + "----------\n" + + "4. ERROR in Y.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check missing @Deprecated detection + public void test121() { + this.runNegativeTest( + new String[] { + "X.java", + "/** @deprecated */\n" + + "public class X {\n" + + " /** @deprecated */\n" + + " public static class Y {\n" + + " }\n" + + " /** @deprecated */\n" + + " int i;\n" + + " /** @deprecated */\n" + + " public void flag() {}\n" + + " void doNotFlag() {}\n" + + " Zork z;\n" + + "} \n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public class X {\n" + + " ^\n" + + "The deprecated type X should be annotated with @Deprecated\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public static class Y {\n" + + " ^\n" + + "The deprecated type X.Y should be annotated with @Deprecated\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " int i;\n" + + " ^\n" + + "The deprecated field X.i should be annotated with @Deprecated\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " public void flag() {}\n" + + " ^^^^^^\n" + + "The deprecated method flag() of type X should be annotated with @Deprecated\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88446 + public void test122() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "class GenericWithInnerAnnotation {\n" + + " @Retention(RetentionPolicy.RUNTIME)\n" + + " @Target(ElementType.METHOD)\n" + + " public @interface MyAnnotation {\n" + + " }\n" + + "}\n" + + "public class X extends GenericWithInnerAnnotation {\n" + + " @MyAnnotation\n" + + " public void aMethod() {\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " Method method = X.class.getDeclaredMethod(\"aMethod\", new Class[]{});\n" + + " System.out.print(method.getName());\n" + + " Annotation[] annotations = method.getAnnotations();\n" + + " System.out.println(annotations.length);\n" + + " } catch(NoSuchMethodException e) {\n" + + " }\n" + + " }\n" + + "}", + }, + "aMethod1"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90110 + public void test123() { + this.runNegativeTest( + new String[] { + "X.java", + "class SuperX {\n" + + "\n" + + " static void notOverridden() {\n" + + " return;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends SuperX {\n" + + "\n" + + " static void notOverridden() {\n" + + " return;\n" + + " }\n" + + " Zork z;\n" + + "} \n", + }, + "----------\n" + + "1. 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=90110 - variation + public void test124() { + this.runNegativeTest( + new String[] { + "X.java", + "class SuperX {\n" + + "\n" + + " void notOverridden() {\n" + + " return;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends SuperX {\n" + + "\n" + + " void notOverridden() {\n" + + " return;\n" + + " }\n" + + " Zork z;\n" + + "} \n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " void notOverridden() {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method notOverridden() of type X should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test125() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "\n" + + "public class X implements Ann {\n" + + " \n" + + " Ann ann = new X();\n" + + " public Class annotationType() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "@interface Ann {}\n" + + "\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90484 - check no missing @Override warning + public void test126() { + this.runNegativeTest( + new String[] { + "X.java", + "public interface X {\n" + + " Zork z;\n" + + " X clone();\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 @SuppressWarning support + public void test127() { + this.runNegativeTest( + new String[] { + "X.java", + "@Deprecated\n" + + "public class X {\n" + + " void foo(){}\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " @SuppressWarnings(\"all\")\n" + + " void foo(){ super.foo(); }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 1)\n" + + " public class Y extends X {\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "2. ERROR in Y.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @SuppressWarning support + public void test128() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo(List list) {\n" + + " List ls1 = list;\n" + + " }\n" + + " @SuppressWarnings({\"unchecked\", \"rawtypes\"})\n" + + " void bar(List list) {\n" + + " List ls2 = list;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(List list) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " List ls1 = list;\n" + + " ^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @SuppressWarning support + public void test129() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "@SuppressWarnings(\"unchecked\")\n" + + "public class X {\n" + + " void foo() {\n" + + " Map[] map = new HashMap[10];\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @SuppressWarning support + public void test130() { + Map customOptions = new Hashtable(); + String[] warnings = CompilerOptions.warningOptionNames(); + for (int i = 0, ceil = warnings.length; i < ceil; i++) { + customOptions.put(warnings[i], CompilerOptions.WARNING); + } + this.runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n", + }, + null, + customOptions, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " public static void main(String[] args) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "3. WARNING in X.java (at line 2)\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " ^^^^^\n" + + "Empty block should be documented\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + // check @SuppressWarning support + public void test131() { + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"all\")\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @SuppressWarning support + public void test132() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "import java.util.Vector;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " W.deprecated();\n" + + " List l = new Vector();\n" + + " l.size();\n" + + " try {\n" + + " // do nothing\n" + + " } finally {\n" + + " throw new Error();\n" + + " }\n" + + " // Zork z;\n" + + " }\n" + + "\n" + + " class S implements Serializable {\n" + + " String dummy;\n" + + " }\n" + + "}", + "W.java", + "public class W {\n" + + " // @deprecated\n" + + " @Deprecated\n" + + " static void deprecated() {\n" + + " // do nothing\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " W.deprecated();\n" + + " ^^^^^^^^^^^^\n" + + "The method deprecated() from the type W is deprecated\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " List l = new Vector();\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Vector needs unchecked conversion to conform to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " List l = new Vector();\n" + + " ^^^^^^\n" + + "Vector is a raw type. References to generic type Vector should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " } finally {\n" + + " throw new Error();\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "finally block does not complete normally\n" + + "----------\n" + + "5. WARNING in X.java (at line 18)\n" + + " class S implements Serializable {\n" + + " ^\n" + + "The serializable class S does not declare a static final serialVersionUID field of type long\n" + + "----------\n", + null, + true, + null, + "java.lang.Error"); + } + // check @SuppressWarning support + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89436 + public void test133() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "import java.util.Vector;\n" + + "\n" + + "@SuppressWarnings( { \"deprecation\",//$NON-NLS-1$\n" + + " \"finally\",//$NON-NLS-1$\n" + + " \"rawtypes\",//$NON-NLS-1$\n" + + " \"serial\",//$NON-NLS-1$\n" + + " \"unchecked\"//$NON-NLS-1$\n" + + "})\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " W.deprecated();\n" + + " List l = new Vector();\n" + + " l.size();\n" + + " try {\n" + + " // do nothing\n" + + " } finally {\n" + + " throw new Error();\n" + + " }\n" + + " }\n" + + "\n" + + " class S implements Serializable {\n" + + " Zork dummy;\n" + + " }\n" + + "}", + "W.java", + "public class W {\n" + + " // @deprecated\n" + + " @Deprecated\n" + + " static void deprecated() {\n" + + " // do nothing\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " Zork dummy;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @SuppressWarning support + public void test134() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "import java.util.Vector;\n" + + "\n" + + "public class X {\n" + + " @SuppressWarnings( { \"deprecation\",//$NON-NLS-1$\n" + + " \"finally\",//$NON-NLS-1$\n" + + " \"rawtypes\",//$NON-NLS-1$\n" + + " \"unchecked\"//$NON-NLS-1$\n" + + " })\n" + + " public static void main(String[] args) {\n" + + " W.deprecated();\n" + + " List l = new Vector();\n" + + " l.size();\n" + + " try {\n" + + " // do nothing\n" + + " } finally {\n" + + " throw new Error();\n" + + " }\n" + + " }\n" + + "\n" + + " @SuppressWarnings({\"unchecked\", \"rawtypes\"}//$NON-NLS-1$//$NON-NLS-2$\n" + + " )\n" + + " List l = new Vector();\n" + + "\n" + + " @SuppressWarnings(\"serial\"//$NON-NLS-1$\n" + + " )\n" + + " class S implements Serializable {\n" + + " Zork dummy;\n" + + " }\n" + + "}", + "W.java", + "public class W {\n" + + " // @deprecated\n" + + " @Deprecated\n" + + " static void deprecated() {\n" + + " // do nothing\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 29)\n" + + " Zork dummy;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @SuppressWarning support + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69505 -- NOT READY YET: "all" only so far, no file support -- + // hence no import support + public void test135() { + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"all\")//$NON-NLS-1$\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (false) {\n" + + " ;\n" + + " } else {\n" + + " }\n" + + " Zork z;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " import java.util.List;\n" + + " ^^^^^^\n" + + "Syntax error on token \"import\", package expected\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @SuppressWarning support + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=71968 + public void test136() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"unused\"//$NON-NLS-1$\n" + + " )\n" + + " private static final String marker = \"never used mark\"; //$NON-NLS-1$\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Zork z;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // check @SuppressWarning support + public void test137() { + Map customOptions = new Hashtable(); + String[] warnings = CompilerOptions.warningOptionNames(); + for (int i = 0, ceil = warnings.length; i < ceil; i++) { + customOptions.put(warnings[i], CompilerOptions.WARNING); + } + customOptions.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "import java.util.Vector;\n" + + "\n" + + "@SuppressWarnings(\"all\")\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " W.deprecated();\n" + + " List l = new Vector();\n" + + " l.size();\n" + + " try {\n" + + " // do nothing\n" + + " } finally {\n" + + " throw new Error();\n" + + " }\n" + + " Zork z;\n" + + " }\n" + + "\n" + + " class S implements Serializable {\n" + + " String dummy;\n" + + " }\n" + + "}", + "W.java", + "public class W {\n" + + " // @deprecated\n" + + " @Deprecated\n" + + " static void deprecated() {\n" + + " // do nothing\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public class X {\n" + + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " public static void main(String[] args) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " W.deprecated();\n" + + " ^^^^^^^^^^^^\n" + + "The method deprecated() from the type W is deprecated\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " List l = new Vector();\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Vector needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " List l = new Vector();\n" + + " ^^^^^^\n" + + "Vector is a raw type. References to generic type Vector should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. WARNING in X.java (at line 19)\n" + + " class S implements Serializable {\n" + + " ^\n" + + "The serializable class S does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in W.java (at line 1)\n" + + " public class W {\n" + + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + null, true, customOptions); + } + // check @SuppressWarning support + public void test138() { + Map customOptions = new Hashtable(); + customOptions.put(CompilerOptions.OPTION_ReportUnhandledWarningToken, CompilerOptions.WARNING); + this.runNegativeTest( + + new String[] { + "X.java", + "@SuppressWarnings(\"zork\")//$NON-NLS-1$\n" + + "public class X {\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " @SuppressWarnings(\"zork\")//$NON-NLS-1$\n" + + " ^^^^^^\n" + + "Unsupported @SuppressWarnings(\"zork\")\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, true, customOptions); + } + // check @SuppressWarning support + public void test139() { + Map customOptions = new Hashtable(); + customOptions.put(CompilerOptions.OPTION_ReportUnhandledWarningToken, CompilerOptions.WARNING); + this.runNegativeTest( + + new String[] { + "X.java", + "@SuppressWarnings({\"zork\", \"warningToken\"})//$NON-NLS-1$//$NON-NLS-2$\n" + + "public class X {\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " @SuppressWarnings({\"zork\", \"warningToken\"})//$NON-NLS-1$//$NON-NLS-2$\n" + + " ^^^^^^\n" + + "Unsupported @SuppressWarnings(\"zork\")\n" + + "----------\n" + + "2. WARNING in X.java (at line 1)\n" + + " @SuppressWarnings({\"zork\", \"warningToken\"})//$NON-NLS-1$//$NON-NLS-2$\n" + + " ^^^^^^^^^^^^^^\n" + + "Unsupported @SuppressWarnings(\"warningToken\")\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, true, customOptions); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90111 - variation + public void test140() { + String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 + ? "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " static void foo(){} \n" + + " ^^^^^\n" + + "The method foo() of type Bar must override a superclass method\n" + + "----------\n" + : "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " static void foo(){} \n" + + " ^^^^^\n" + + "The method foo() of type Bar must override or implement a supertype method\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(){}\n" + + "}\n" + + "class Bar extends X {\n" + + " @Override\n" + + " static void foo(){} \n" + + "}\n" + + "\n" + }, + expectedOutput, + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94867 + public void test141() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface X1 {\n" + + " Class[] expected1() default {};\n" + + " Class[] expected2() default {};\n" + + " Class[] expected3() default {};\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @X1(expected1=Throwable.class, expected2={})\n" + + " public static void main(String[] args) {\n" + + " \n" + + " }\n" + + " void foo() {\n" + + " Class[] c1 = {};\n" + + " Class[] c2 = {};\n" + + " Class[] c3 = {};\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " Class[] c1 = {};\n" + + " ^^\n" + + "Cannot create a generic array of Class\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " Class[] c2 = {};\n" + + " ^^\n" + + "Cannot create a generic array of Class\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94308 + public void test142() { + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"deprecation\")\n" + + "public class X extends p.OldStuff {\n" + + " /**\n" + + " * @see p.OldStuff#foo()\n" + + " */\n" + + " @Override\n" + + " public void foo() {\n" + + " super.foo();\n" + + " }\n" + + "}\n", + "p/OldStuff.java", + "package p;\n" + + "@Deprecated\n" + + "public class OldStuff {\n" + + " public void foo() {\n" + + " } \n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\OldStuff.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, + null); + } + public void test142b() { + Map raiseInvalidJavadocSeverity = + new HashMap(2); + raiseInvalidJavadocSeverity.put( + CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + // admittingly, when these are errors, SuppressWarnings is not enough to + // filter them out *but* the deprecation level being WARNING, we get them + // out anyway + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"deprecation\")\n" + + "public class X extends p.OldStuff {\n" + + " /**\n" + + " * @see p.OldStuff#foo()\n" + + " */\n" + + " @Override\n" + + " public void foo() {\n" + + " super.foo();\n" + + " }\n" + + "}\n", + "p/OldStuff.java", + "package p;\n" + + "@Deprecated\n" + + "public class OldStuff {\n" + + " public void foo() {\n" + + " } \n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\OldStuff.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, + raiseInvalidJavadocSeverity); + } +// check that @SuppressWarning is reported as unused when corresponding warning is moved from +// warning to error +public void test142c() { + Map raiseDeprecationReduceInvalidJavadocSeverity = + new HashMap(2); + raiseDeprecationReduceInvalidJavadocSeverity.put( + CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + raiseDeprecationReduceInvalidJavadocSeverity.put( + CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.WARNING); + this.runNegativeTest( + true, + new String[] { + "X.java", + "@SuppressWarnings(\"deprecation\")\n" + + "public class X extends p.OldStuff {\n" + + " /**\n" + + " * @see p.OldStuff#foo()\n" + + " */\n" + + " @Override\n" + + " public void foo() {\n" + + " super.foo();\n" + + " }\n" + + "}\n", + "p/OldStuff.java", + "package p;\n" + + "@Deprecated\n" + + "public class OldStuff {\n" + + " public void foo() {\n" + + " } \n" + + "}\n", + }, + null, + raiseDeprecationReduceInvalidJavadocSeverity, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"deprecation\")\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public class X extends p.OldStuff {\n" + + " ^^^^^^^^\n" + + "The type OldStuff is deprecated\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " super.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type OldStuff is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +public void test143() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends p.OldStuff {\n" + + " @SuppressWarnings(\"all\")\n" + + " public void foo() {\n" + + " super.foo();\n" + + " }\n" + + "}\n", + "p/OldStuff.java", + "package p;\n" + + "@Deprecated\n" + + "public class OldStuff {\n" + + " public void foo() {\n" + + " } \n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X extends p.OldStuff {\n" + + " ^^^^^^^^\n" + + "The type OldStuff is deprecated\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p\\OldStuff.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + public void test144() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " Zork z;\n" + + " @SuppressWarnings(\"all\") \n" + + " public static class EverythingWrong {\n" + + " private EverythingWrong() {}\n" + + " @BeforeClass public void notStaticBC() {}\n" + + " @BeforeClass static void notPublicBC() {}\n" + + " @BeforeClass public static int nonVoidBC() { return 0; }\n" + + " @BeforeClass public static void argumentsBC(int i) {}\n" + + " @BeforeClass public static void fineBC() {}\n" + + " @AfterClass public void notStaticAC() {}\n" + + " @AfterClass static void notPublicAC() {}\n" + + " @AfterClass public static int nonVoidAC() { return 0; }\n" + + " @AfterClass public static void argumentsAC(int i) {}\n" + + " @AfterClass public static void fineAC() {}\n" + + " @After public static void staticA() {}\n" + + " @After void notPublicA() {}\n" + + " @After public int nonVoidA() { return 0; }\n" + + " @After public void argumentsA(int i) {}\n" + + " @After public void fineA() {}\n" + + " @Before public static void staticB() {}\n" + + " @Before void notPublicB() {}\n" + + " @Before public int nonVoidB() { return 0; }\n" + + " @Before public void argumentsB(int i) {}\n" + + " @Before public void fineB() {}\n" + + " @Test public static void staticT() {}\n" + + " @Test void notPublicT() {}\n" + + " @Test public int nonVoidT() { return 0; }\n" + + " @Test public void argumentsT(int i) {}\n" + + " @Test public void fineT() {}\n" + + " }\n" + + " @Test public void testFailures() throws Exception {\n" + + " List problems= new TestIntrospector(EverythingWrong.class).validateTestMethods();\n" + + " int errorCount= 1 + 4 * 5; // missing constructor plus four invalid methods for each annotation */\n" + + " assertEquals(errorCount, problems.size());\n" + + " }\n" + + " public static junit.framework.Test suite() {\n" + + " return null; // new JUnit4TestAdapter(TestMethodTest.class);\n" + + " }\n" + + " void assertEquals(int i, int j) {\n" + + " }\n" + + "}\n" + + "@interface BeforeClass {}\n" + + "@interface AfterClass {}\n" + + "@interface Test {}\n" + + "@interface After {}\n" + + "@interface Before {}\n" + + "class TestIntrospector {\n" + + " TestIntrospector(Class c) {}\n" + + " List validateTestMethods() { return null; }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 34)\n" + + " List problems= new TestIntrospector(EverythingWrong.class).validateTestMethods();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 38)\n" + + " public static junit.framework.Test suite() {\n" + + " ^^^^^\n" + + "junit cannot be resolved to a type\n" + + "----------\n" + + "4. WARNING in X.java (at line 50)\n" + + " TestIntrospector(Class c) {}\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 51)\n" + + " List validateTestMethods() { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89937 + public void test145() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Annot {\n" + + " int foo();\n" + + " int bar();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " static final int yyy = 0;\n" + + " @Annot(foo=zzz, bar = yyy)\n" + + " static final int zzz = 0;\n" + + "}\n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " @Annot(foo=zzz, bar = yyy)\n" + + " ^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=96631 + public void test146() { + this.runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(value={})\n" + + "public class X {\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=96974 + public void test147() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings({\"nls\"})\n" + + "public class X {\n" + + " String test= \"\";\n" + + "}", + }, + "", + null, + true, + options + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=97466 + public void test148() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static void foo() {\n" + + " @interface Bar {\n" + + " public String bar = \"BUG\";\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @interface Bar {\n" + + " ^^^\n" + + "The member annotation Bar can only be defined inside a top-level class or interface or in a static context\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=96991 + public void test149() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar() {\n" + + " @Annot(foo = zzz)\n" + + " final int zzz = 0;\n" + + "\n" + + " @Annot(foo = kkk)\n" + + " int kkk = 1;\n" + + "\n" + + " }\n" + + " @Annot(foo = fff)\n" + + " final int fff = 0;\n" + + " \n" + + " @Annot(foo = Member.ttt)\n" + + " static class Member {\n" + + " final static int ttt = 2;\n" + + " }\n" + + "}\n" + + "@interface Annot {\n" + + " int foo();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " @Annot(foo = kkk)\n" + + " ^^^\n" + + "The value for annotation attribute Annot.foo must be a constant expression\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " @Annot(foo = fff)\n" + + " ^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=98091 + public void test150() { + this.runConformTest( + true, + new String[] { + "X.java", + "@SuppressWarnings(\"assertIdentifier\")\n" + + "class X {}", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " @SuppressWarnings(\"assertIdentifier\")\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Unsupported @SuppressWarnings(\"assertIdentifier\")\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test151() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportAutoboxing, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings({\"boxing\"})\n" + + "public class X {\n" + + " static void foo(int i) {}\n" + + " public static void main(String[] args) {\n" + + " foo(Integer.valueOf(0));\n" + + " }\n" + + "}", + }, + "", + null, + true, + options + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test152() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportAutoboxing, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings({\"boxing\"})\n" + + "public class X {\n" + + " static void foo(Integer i) {}\n" + + " public static void main(String[] args) {\n" + + " foo(0);\n" + + " }\n" + + "}", + }, + "", + null, + true, + options + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test153() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "enum E { A, B, C }\n" + + "public class X {\n" + + " @SuppressWarnings({\"incomplete-switch\"})\n" + + " public static void main(String[] args) {\n" + + " for (E e : E.values()) {\n" + + " switch(e) {\n" + + " case A :\n" + + " System.out.println(e);\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + options + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test154() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static int i;\n" + + " @SuppressWarnings({\"hiding\"})\n" + + " public static void main(String[] args) {\n" + + " for (int i = 0, max = args.length; i < max; i++) {\n" + + " System.out.println(args[i]);\n" + + " }\n" + + " }\n" + + "}", + }, + "", + null, + true, + options + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test155() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings({\"hiding\"})\n" + + "public class X { \n"+ + " { int x = \n"+ + " new Object() { \n"+ + " int foo() { \n"+ + " int x = 0;\n" + + " return x; \n"+ + " } \n"+ + " }.foo(); \n"+ + " } \n"+ + "}\n", + }, + "", + null, + true, + options + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test156() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportTypeParameterHiding, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class T {}\n" + + "@SuppressWarnings({\"hiding\"})\n" + + "public class X {\n"+ + "}\n", + }, + "", + null, + true, + options + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test157() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportHiddenCatchBlock, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({\"hiding\"})\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new BX();\n" + + " } catch(BX e) {\n" + + " } catch(AX e) {\n" + + " }\n" + + " }\n" + + "} \n" + + "@SuppressWarnings({\"serial\"})\n" + + "class AX extends Exception {}\n" + + "@SuppressWarnings({\"serial\"})\n" + + "class BX extends AX {}\n" + }; + runner.javacTestOptions = JavacTestOptions.SKIP; // javac doesn't support @SW("hiding") here, see test157b + runner.runConformTest(); + } + public void test157b() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportHiddenCatchBlock, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new BX();\n" + + " } catch(BX e) {\n" + + " } catch(AX e) {\n" + + " }\n" + + " }\n" + + "} \n" + + "@SuppressWarnings({\"serial\"})\n" + + "class AX extends Exception {}\n" + + "@SuppressWarnings({\"serial\"})\n" + + "class BX extends AX {}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " } catch(AX e) {\n" + + " ^^\n" + + "Unreachable catch block for AX. Only more specific exceptions are thrown and they are handled by previous catch block(s).\n" + + "----------\n"; + runner.runWarningTest(); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test158() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFinallyBlockNotCompletingNormally, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({\"finally\"})\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new AX();\n" + + " } finally {\n" + + " return;\n" + + " }\n" + + " }\n" + + "} \n" + + "@SuppressWarnings({\"serial\"})\n" + + "class AX extends Exception {}" + }, + "", + null, + true, + options + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test159() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportIndirectStaticAccess, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "X.java", + "@SuppressWarnings({\"static-access\"})\n" + + "public class X extends XZ {\n" + + " \n" + + " void foo() {\n" + + " int j = X.S;\n" + + " int k = super.S;\n" + + " int l = XZ.S;\n" + + " int m = XY.S;\n" + + " \n" + + " bar();\n" + + " X.bar();\n" + + " XY.bar();\n" + + " XZ.bar();\n" + + " }\n" + + "}\n" + + "class XY {\n" + + " static int S = 10;\n" + + " static void bar(){}\n" + + "}\n" + + "class XZ extends XY {\n" + + "}" + }; + runner.javacTestOptions = JavacTestOptions.SKIP; // only testing Eclipse-specific @SW + runner.runConformTest(); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test160() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "X.java", + "@SuppressWarnings(\"static-access\")\n" + + "public class X {\n" + + " void foo() {\n" + + " int m = new XY().S;\n" + + " }\n" + + "}\n" + + "class XY {\n" + + " static int S = 10;\n" + + "}" + }; + runner.javacTestOptions = JavacTestOptions.SKIP; // only testing Eclipse-specific @SW + runner.runConformTest(); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test161() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnqualifiedFieldAccess, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"unqualified-field-access\")\n" + + "public class X {\n" + + " int i;\n" + + " int foo() {\n" + + " return i;\n" + + " }\n" + + "}" + }, + "", + null, + true, + options + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test162() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings({\"unchecked\", \"rawtypes\"})\n" + + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX ax2 = ax.p;\n" + + " ax.p = new AX();\n" + + " ax.q = new AX();\n" + + " ax.r = new AX();\n" + + " System.out.println(ax2);\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

p;\n" + + " AX q;\n" + + " AX r;\n" + + " BX s;\n" + + "}\n" + + "\n" + + "class BX {\n" + + "}\n", + }, + "", + null, + true, + options + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test163() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownException, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "@SuppressWarnings(\"unused\")\n" + + "public class X {\n" + + " \n" + + " public void foo(int i) throws java.io.IOException {\n" + + " int j = 0;\n" + + " class C {\n" + + " private void bar() {}\n" + + " }\n" + + " }\n" + + "}", + "Y.java", // ================= + "public class Y extends Zork {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " public class Y extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, + options + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test164() { + String[] testFiles = new String[] { + "X.java", + "@SuppressWarnings({\"synthetic-access\", \"unused\"})\n" + + "public class X {\n" + + " private int i;\n" + + " private void bar() {}\n" + + " public void foo() {\n" + + " class C {\n" + + " private void bar() {\n" + + " System.out.println(i);\n" + + " i = 0;\n" + + " bar();\n" + + " }\n" + + " };\n" + + " new C().bar();\n" + + " }\n" + + "}" + }; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.WARNING); + if (isMinimumCompliant(ClassFileConstants.JDK11)) { // no synthetic due to nestmate + this.runConformTest(testFiles); + return; + } + this.runNegativeTest( + testFiles, + "", + null, + true, + options + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99009 + public void test165() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingDeprecatedAnnotation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, CompilerOptions.PRIVATE); + this.runConformTest( + true, + new String[] { + "X.java", + "/**\n" + + " * @see Y\n" + + " */\n" + + "@SuppressWarnings(\"deprecation\")\n" + + "public class X extends Y {\n" + + " /**\n" + + " * @see Y#foo()\n" + + " * @see Y#j\n" + + " */\n" + + " public void foo() {\n" + + " super.foo();\n" + + " }\n" + + "}", + "Y.java", + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public class Y {\n" + + " /**\n" + + " * @deprecated\n" + + " */\n" + + " public void foo() {}\n" + + " /**\n" + + " * @deprecated\n" + + " */\n" + + " public int j;\n" + + "}" + }, + null, + options, + "", + null, null, + JavacTestOptions.SKIP /* suppressed deprecation related warnings */ + ); + } + + // check array handling of singleton + public void test166() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Inherited;\n" + + "\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Inherited()\n" + + "@interface ParameterAnnotation {\n" + + " String value() default \"Default\";\n" + + "}\n"+ + "@interface ClassAnnotation {\n" + + " String value() default \"Default\";\n" + + "}\n" + + "\n" + + "enum EnumClass{\n" + + " Value1, Value2, Value3\n" + + "}\n" + + "\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Inherited()\n" + + "@interface ValueAnnotation {\n" + + " String value() default \"Default\";\n" + + " boolean booleanValue() default true;\n" + + " char charValue() default \'q\';\n" + + " byte byteValue() default 123;\n" + + " short shortValue() default 12345;\n" + + " int intValue() default 1234567890;\n" + + " float floatValue() default 12345.6789f;\n" + + " double doubleValue() default 12345.6789;\n" + + " long longValue() default 1234567890123456789l;\n" + + " String stringValue() default \"stringValue\";\n" + + " EnumClass enumValue() default EnumClass.Value1;\n" + + " Class classValue() default EnumClass.class;\n" + + " ClassAnnotation annotationValue() default @ClassAnnotation();\n" + + " boolean[] booleanArrayValue() default {true, false};\n" + + " char[] charArrayValue() default {\'q\', \'m\'};\n" + + " byte[] byteArrayValue() default {123, -123};\n" + + " short[] shortArrayValue() default {12345, -12345};\n" + + " int[] intArrayValue() default {1234567890, -1234567890};\n" + + " float[] floatArrayValue() default {12345.6789f, -12345.6789f};\n" + + " double[] doubleArrayValue() default {12345.6789, -12345.6789};\n" + + " long[] longArrayValue() default {1234567890123456789l, -1234567890123456789l};\n" + + " String[] stringArrayValue() default {\"stringValue\", \"valueString\"};\n" + + " EnumClass[] enumArrayValue() default {EnumClass.Value1, EnumClass.Value2};\n" + + " Class[] classArrayValue() default {X.class, EnumClass.class};\n" + + " ClassAnnotation[] annotationArrayValue() default {@ClassAnnotation(), @ClassAnnotation()};\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @ValueAnnotation(\n" + + " value=\"ValueAnnotation\",\n" + + " booleanValue=true,\n" + + " charValue=\'m\',\n" + + " byteValue=-123,\n" + + " shortValue=-12345,\n" + + " intValue=-1234567890,\n" + + " floatValue=-12345.6789f,\n" + + " doubleValue=-12345.6789,\n" + + " longValue=-1234567890123456789l,\n" + + " stringValue=\"valueString\",\n" + + " enumValue=EnumClass.Value3,\n" + + " classValue=X.class,\n" + + " annotationValue=@ClassAnnotation(value=\"ClassAnnotation\"),\n" + + " booleanArrayValue={\n" + + " false,\n" + + " true\n" + + " },\n" + + " charArrayValue={\n" + + " \'m\',\n" + + " \'q\'\n" + + " },\n" + + " byteArrayValue={\n" + + " -123,\n" + + " 123\n" + + " },\n" + + " shortArrayValue={\n" + + " -12345,\n" + + " 12345\n" + + " },\n" + + " intArrayValue={\n" + + " -1234567890,\n" + + " 1234567890\n" + + " },\n" + + " floatArrayValue={\n" + + " -12345.6789f,\n" + + " 12345.6789f\n" + + " },\n" + + " doubleArrayValue={\n" + + " -12345.6789,\n" + + " 12345.6789\n" + + " },\n" + + " longArrayValue={\n" + + " -1234567890123456789l,\n" + + " 1234567890123456789l\n" + + " },\n" + + " stringArrayValue={\n" + + " \"valueString\",\n" + + " \"stringValue\"\n" + + " },\n" + + " enumArrayValue={\n" + + " EnumClass.Value2,\n" + + " EnumClass.Value1\n" + + " },\n" + + " classArrayValue={\n" + + " EnumClass.class,\n" + + " X.class\n" + + " },\n" + + " annotationArrayValue={\n" + + " @ClassAnnotation(value=\"ClassAnnotation1\"),\n" + + " @ClassAnnotation(value=\"ClassAnnotation2\")\n" + + " })\n" + + " public String field;\n" + + " @ValueAnnotation(\n" + + " value=\"ValueAnnotation\",\n" + + " booleanValue=true,\n" + + " charValue=\'m\',\n" + + " byteValue=-123,\n" + + " shortValue=-12345,\n" + + " intValue=-1234567890,\n" + + " floatValue=-12345.6789f,\n" + + " doubleValue=-12345.6789,\n" + + " longValue=-1234567890123456789l,\n" + + " stringValue=\"valueString\",\n" + + " enumValue=EnumClass.Value3,\n" + + " classValue=X.class,\n" + + " annotationValue=@ClassAnnotation(value=\"ClassAnnotation\"),\n" + + " booleanArrayValue={\n" + + " false,\n" + + " true\n" + + " },\n" + + " charArrayValue={\n" + + " \'m\',\n" + + " \'q\'\n" + + " },\n" + + " byteArrayValue={\n" + + " -123,\n" + + " 123\n" + + " },\n" + + " shortArrayValue={\n" + + " -12345,\n" + + " 12345\n" + + " },\n" + + " intArrayValue={\n" + + " -1234567890,\n" + + " 1234567890\n" + + " },\n" + + " floatArrayValue={\n" + + " -12345.6789f,\n" + + " 12345.6789f\n" + + " },\n" + + " doubleArrayValue={\n" + + " -12345.6789,\n" + + " 12345.6789\n" + + " },\n" + + " longArrayValue={\n" + + " -1234567890123456789l,\n" + + " 1234567890123456789l\n" + + " },\n" + + " stringArrayValue={\n" + + " \"valueString\",\n" + + " \"stringValue\"\n" + + " },\n" + + " enumArrayValue={\n" + + " EnumClass.Value2,\n" + + " EnumClass.Value1\n" + + " },\n" + + " classArrayValue={\n" + + " EnumClass.class,\n" + + " X.class\n" + + " },\n" + + " annotationArrayValue={\n" + + " @ClassAnnotation(value=\"ClassAnnotation1\"),\n" + + " @ClassAnnotation(value=\"ClassAnnotation2\")\n" + + " })\n" + + " public X(@ParameterAnnotation(value=\"ParameterAnnotation\") @Deprecated() String param1, @ParameterAnnotation(value=\"ParameterAnnotation\") String param2) {\n" + + " }\n" + + " @ValueAnnotation(\n" + + " value=\"ValueAnnotation\",\n" + + " booleanValue=true,\n" + + " charValue=\'m\',\n" + + " byteValue=-123,\n" + + " shortValue=-12345,\n" + + " intValue=-1234567890,\n" + + " floatValue=-12345.6789f,\n" + + " doubleValue=-12345.6789,\n" + + " longValue=-1234567890123456789l,\n" + + " stringValue=\"valueString\",\n" + + " enumValue=EnumClass.Value3,\n" + + " classValue=X.class,\n" + + " annotationValue=@ClassAnnotation(value=\"ClassAnnotation\"),\n" + + " booleanArrayValue={\n" + + " false,\n" + + " true\n" + + " },\n" + + " charArrayValue={\n" + + " \'m\',\n" + + " \'q\'\n" + + " },\n" + + " byteArrayValue={\n" + + " -123,\n" + + " 123\n" + + " },\n" + + " shortArrayValue={\n" + + " -12345,\n" + + " 12345\n" + + " },\n" + + " intArrayValue={\n" + + " -1234567890,\n" + + " 1234567890\n" + + " },\n" + + " floatArrayValue={\n" + + " -12345.6789f,\n" + + " 12345.6789f\n" + + " },\n" + + " doubleArrayValue={\n" + + " -12345.6789,\n" + + " 12345.6789\n" + + " },\n" + + " longArrayValue={\n" + + " -1234567890123456789l,\n" + + " 1234567890123456789l\n" + + " },\n" + + " stringArrayValue={\n" + + " \"valueString\",\n" + + " \"stringValue\"\n" + + " },\n" + + " enumArrayValue={\n" + + " EnumClass.Value2,\n" + + " EnumClass.Value1\n" + + " },\n" + + " classArrayValue={\n" + + " EnumClass.class,\n" + + " X.class\n" + + " },\n" + + " annotationArrayValue={\n" + + " @ClassAnnotation(value=\"ClassAnnotation1\"),\n" + + " @ClassAnnotation(value=\"ClassAnnotation2\")\n" + + " })\n" + + " public void method(@ParameterAnnotation(value=\"ParameterAnnotation\") @Deprecated() String param1, @ParameterAnnotation(value=\"ParameterAnnotation\") String param2){\n" + + " }\n" + + "}" + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + final byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + new ClassFileReader(classFileBytes, "X.java".toCharArray(), true); + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=99469 + public void test167() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public foo(@Deprecated() String s) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public foo(@Deprecated() String s) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94759 + public void test168() { + String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 + ? "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Override I clone();\n" + + " ^^^^^^^\n" + + "The method clone() of type I must override a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " @Override void foo();\n" + + " ^^^^^\n" + + "The method foo() of type J must override a superclass method\n" + + "----------\n" + : "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Override I clone();\n" + + " ^^^^^^^\n" + + "The method clone() of type I must override or implement a supertype method\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " @Override I clone();\n" + + " void foo();\n" + + "}\n" + + "\n" + + "interface J extends I {\n" + + " @Override void foo();\n" + + "}\n", + }, + expectedOutput); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 + public void test169() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "@SuppressWarnings(\"serial\")\n" + + "public class X extends Exception {\n" + + " String s = \"Hello\"; \n" + + "}" + }, + null, + customOptions, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " String s = \"Hello\"; \n" + + " ^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation + public void test170() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X extends Exception {\n" + + " @SuppressWarnings(\"nls\")\n" + + " String s = \"Hello\"; \n" + + "}" + }, + "", + null, true, null, customOptions, null); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation + public void test171() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "public class X extends Exception {\n" + + " @SuppressWarnings(\"nls\")\n" + + " String s = \"Hello\"; \n" + + " @SuppressWarnings(\"serial\")\n" + // no nls-warning here + " String s2 = \"Hello2\"; \n" + // but an nls-warning here + "}" + }, + null, customOptions, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X extends Exception {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " @SuppressWarnings(\"serial\")\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"serial\")\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " String s2 = \"Hello2\"; \n" + + " ^^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + null, null, JavacTestOptions.SKIP); // nls-warnings are specific to Eclipse - special-casing this special case is irrelevant for javac + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation + public void test172() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "@SuppressWarnings(\"serial\")\n" + + "public class X extends Exception {\n" + + " @SuppressWarnings(\"nls\")\n" + + " String s = \"Hello\"; \n" + + " @SuppressWarnings(\"serial\")\n" + + " String s2 = \"Hello2\"; \n" + + "}" + }, + null, customOptions, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " @SuppressWarnings(\"serial\")\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"serial\")\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " String s2 = \"Hello2\"; \n" + + " ^^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation + public void test173() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "@interface Annot {\n" + + " String value() default \"NONE\";\n" + + "}\n" + + "@Annot(\"serial\")\n" + + "public class X extends Exception {\n" + + " @SuppressWarnings(\"nls\")\n" + + " String s = \"Hello\"; \n" + + " @SuppressWarnings(\"serial\")\n" + + " String s2 = \"Hello2\"; \n" + + "}" + }, + null, + customOptions, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public class X extends Exception {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " @SuppressWarnings(\"serial\")\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"serial\")\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " String s2 = \"Hello2\"; \n" + + " ^^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + null, null, JavacTestOptions.SKIP); // nls-warnings are specific to Eclipse - special-casing this special case is irrelevant for javac + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation + public void test174() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + final String source = "@interface Annot {\n" + + " int value() default 0;\n" + + "}\n" + + "@interface Annot2 {\n" + + " String value();\n" + + "}\n" + + "@Annot(value=5)\n" + + "public class X {\n" + + " @Annot2(value=\"nls\")\n" + + " String s = null; \n" + + " @SuppressWarnings(\"serial\")\n" + + " String s2 = \"Hello2\"; \n" + + "}"; + this.runConformTest( + true, + new String[] { + "X.java", + source + }, + null, customOptions, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " @SuppressWarnings(\"serial\")\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"serial\")\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " String s2 = \"Hello2\"; \n" + + " ^^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation + public void test175() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + final String source = "@interface Annot {\n" + + " int value() default 0;\n" + + "}\n" + + "@interface Annot2 {\n" + + " String value();\n" + + "}\n" + + "@Annot(value=5)\n" + + "public class X {\n" + + " @Annot2(value=\"nls\") String s = \"value\"; \n" + + " @SuppressWarnings(\"serial\")\n" + + " String s2 = \"Hello2\"; \n" + + "}"; + this.runConformTest( + true, + new String[] { + "X.java", + source + }, + null, customOptions, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " @Annot2(value=\"nls\") String s = \"value\"; \n" + + " ^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " @SuppressWarnings(\"serial\")\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"serial\")\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " String s2 = \"Hello2\"; \n" + + " ^^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97220 - variation + public void test176() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + final String source = "@interface Annot {\n" + + " int value() default 0;\n" + + "}\n" + + "@interface Annot2 {\n" + + " String value();\n" + + "}\n" + + "@Annot(value=5)\n" + + "public class X {\n" + + " @Annot2(value=\"nls\") String s = \"value\"; \n" + + " @SuppressWarnings({\"serial\", \"nls\"})\n" + + " String s2 = \"Hello2\"; \n" + + " @Annot(value=5) void foo() {}\n" + + "}"; + this.runConformTest( + true, + new String[] { + "X.java", + source + }, + null, customOptions, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " @Annot2(value=\"nls\") String s = \"value\"; \n" + + " ^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " @SuppressWarnings({\"serial\", \"nls\"})\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"serial\")\n" + + "----------\n", + null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=108263 + public void test177() { + this.runConformTest( + new String[] { + "X.java", + "public @interface X {\n" + + " public static final Integer foo = B.zzz; \n" + + " public static final int foo3 = B.zzz2; \n" + + "}\n" + + "class B {\n" + + " public static final Integer zzz = new Integer(0);\n" + + " public static final int zzz2 = 0;\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=111076 + public void test178() { + runConformTest( + true, + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " private void testme(boolean check) {\n" + + " ArrayList aList = new ArrayList();\n" + + " for (@SuppressWarnings(\"unusedLocal\")\n" + + " Integer i : aList) {\n" + + " System.out.println(\"checking\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + null, + "", + null, + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=112433 + public void test179() { + this.runConformTest( + true, + new String[] { + "X.java", + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "@Target({TYPE, FIELD, METHOD,\n" + + " PARAMETER, CONSTRUCTOR,\n" + + " LOCAL_VARIABLE, PACKAGE,})\n" + + "@Retention(CLASS)\n" + + "public @interface X {}" + }, + "", + "", + null, + JavacTestOptions.JavacHasABug.JavacBug6337964); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=116028 + public void test180() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Field;\n" + + "\n" + + "public class X {\n" + + " @Deprecated public static Object x, y, z;\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Class c = X.class;\n" + + " int counter = 0;\n" + + " for (Field f : c.getFields()) {\n" + + " counter += f.getDeclaredAnnotations().length;\n" + + " }\n" + + " System.out.print(counter);\n" + + " }\n" + + "}" + }, + "3"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=116028 + public void test181() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Field;\n" + + "\n" + + "public class X {\n" + + " public static Object x, y, z;\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Class c = X.class;\n" + + " int counter = 0;\n" + + " for (Field f : c.getFields()) {\n" + + " counter += f.getDeclaredAnnotations().length;\n" + + " }\n" + + " System.out.print(counter);\n" + + " }\n" + + "}" + }, + "0"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=110593 + public void test182() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void foo(Y y) {\n" + + " y.initialize(null, null, null);\n" + + " }\n" + + "}\n" + + "\n" + + "\n", // ================= + "Y.java", // ================= + "public class Y {\n" + + "\n" + + " /**\n" + + " * @deprecated\n" + + " */\n" + + " public void initialize(Zork z, String s) {\n" + + " }\n" + + "\n" + + " public void initialize(Zork z, String s, Thread t) {\n" + + " }\n" + + "}\n" + + "\n" + + "\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " y.initialize(null, null, null);\n" + + " ^^^^^^^^^^\n" + + "The method initialize(Zork, String, Thread) from the type Y refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. WARNING in Y.java (at line 6)\n" + + " public void initialize(Zork z, String s) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The deprecated method initialize(Zork, String) of type Y should be annotated with @Deprecated\n" + + "----------\n" + + "2. ERROR in Y.java (at line 6)\n" + + " public void initialize(Zork z, String s) {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in Y.java (at line 6)\n" + + " public void initialize(Zork z, String s) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter z\n" + + "----------\n" + + "4. ERROR in Y.java (at line 6)\n" + + " public void initialize(Zork z, String s) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter s\n" + + "----------\n" + + "5. ERROR in Y.java (at line 9)\n" + + " public void initialize(Zork z, String s, Thread t) {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=110593 - variation + public void test183() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void foo(Y y) {\n" + + " int i = y.initialize;\n" + + " }\n" + + "}\n" + + "\n", // ================= + "Y.java", // ================= + "public class Y {\n" + + "\n" + + " /**\n" + + " * @deprecated\n" + + " */\n" + + " public Zork initialize;\n" + + "}\n" + + "\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int i = y.initialize;\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " int i = y.initialize;\n" + + " ^^^^^^^^^^\n" + + "The field Y.initialize is deprecated\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y.java (at line 6)\n" + + " public Zork initialize;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in Y.java (at line 6)\n" + + " public Zork initialize;\n" + + " ^^^^^^^^^^\n" + + "The deprecated field Y.initialize should be annotated with @Deprecated\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=110593 - variation + public void test184() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void foo() {\n" + + " Y.initialize i;\n" + + " }\n" + + "}\n" + + "\n" + + "\n", // ================= + "Y.java", // ================= + "public class Y {\n" + + "\n" + + " /**\n" + + " * @deprecated\n" + + " */\n" + + " public class initialize extends Zork {\n" + + " }\n" + + "}\n" + + "\n" + + "\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Y.initialize i;\n" + + " ^^^^^^^^^^\n" + + "The type Y.initialize is deprecated\n" + + "----------\n" + + "----------\n" + + "1. WARNING in Y.java (at line 6)\n" + + " public class initialize extends Zork {\n" + + " ^^^^^^^^^^\n" + + "The deprecated type Y.initialize should be annotated with @Deprecated\n" + + "----------\n" + + "2. ERROR in Y.java (at line 6)\n" + + " public class initialize extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=123522 + public void test185() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import p.A;\n" + + "@SuppressWarnings(\"all\")\n" + + "public class X {\n" + + " void foo(A a) {\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "\n" + + "class Y {\n" + + " A a;\n" + + "}\n", // ================= + "p/A.java", // ================= + "package p;\n" + + "@Deprecated\n" + + "public class A {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " A a;\n" + + " ^\n" + + "The type A is deprecated\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=124346 + public void test186() { + this.runNegativeTest( + new String[] { + "p1/X.java", // ================= + "package p1;\n" + + "public class X {\n" + + " @Deprecated\n" + + " class Y implements p2.I {\n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + "p2/I.java", // ================= + "package p2;\n" + + "@Deprecated\n" + + "public interface I {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in p1\\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=124346 - variation + public void test187() { + this.runNegativeTest( + new String[] { + "p1/X.java", // ================= + "package p1;\n" + + "import p2.I;\n" + + "@Deprecated\n" + + "public class X {\n" + + " Zork z;\n" + + "}\n", // ================= + "p2/I.java", // ================= + "package p2;\n" + + "@Deprecated\n" + + "public interface I {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in p1\\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=126332 + public void test188() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface A1 {\n" + + " int[] values();\n" + + "}\n" + + "@A1(values = new int[] { 1, 2 })\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @A1(values = new int[] { 1, 2 })\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The value for annotation attribute A1.values must be an array initializer\n" + + "----------\n"); + } + // partial recompile - keep a binary + public void test189() { + this.runConformTest( + true, + new String[] { + "A1.java", + "@A2(@A1(m1 = \"u\"))\n" + + "public @interface A1 {\n" + + " String m1();\n" + + " String m2() default \"v\";\n" + + "}\n", + "A2.java", + "@A2(@A1(m1 = \"u\", m2 = \"w\"))\n" + + "public @interface A2 {\n" + + " A1[] value();\n" + + "}\n", + }, + "", + "", + null, + JavacTestOptions.DEFAULT); + // keep A2 binary, recompile A1 with a name change + this.runConformTest( + false, // do not flush A2.class + new String[] { + "A1.java", + "@A2(@A1(m1 = \"u\"))\n" + + "public @interface A1 {\n" + + " String m1();\n" + + " String m3() default \"v\";\n" + + "}\n", + }, + null, + "", + null, + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); + } +// transitive closure on binary types does not need to include annotations +public void test190() { + this.runConformTest( + new String[] { + "A.java", + "public @interface A {\n" + + " int value();\n" + + "}\n" + }, + ""); + String binName1 = OUTPUT_DIR + File.separator + "bin1"; + File bin1 = new File(binName1); + bin1.mkdir(); + String [] javaClassLibs = Util.getJavaClassLibs(); + int javaClassLibsLength; + String [] xClassLibs = new String[(javaClassLibsLength = javaClassLibs.length) + 2]; + System.arraycopy(javaClassLibs, 0, xClassLibs, 0, javaClassLibsLength); + xClassLibs[javaClassLibsLength] = OUTPUT_DIR; + xClassLibs[javaClassLibsLength + 1] = binName1; + (new File(OUTPUT_DIR + File.separator + "A.class")).renameTo(new File(binName1 + File.separator + "A.class")); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @A(0)\n" + + " void foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " new X().foo();\n" + + " }\n" + + "}", + }, + "SUCCESS", + xClassLibs, + false, // do not flush + null); + String binName2 = OUTPUT_DIR + File.separator + "bin2"; + File bin2 = new File(binName2); + bin2.mkdir(); + (new File(OUTPUT_DIR + File.separator + "X.class")).renameTo(new File(binName2 + File.separator + "X.class")); + String [] yClassLibs = new String[javaClassLibsLength + 2]; + System.arraycopy(javaClassLibs, 0, yClassLibs, 0, javaClassLibsLength); + yClassLibs[javaClassLibsLength] = OUTPUT_DIR; + yClassLibs[javaClassLibsLength + 1] = binName2; + // Y compiles despite the fact that A is not on the classpath + this.runConformTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String args[]) {\n" + + " new X().foo();\n" + + " }\n" + + "}", + }, + "SUCCESS", + yClassLibs, + false, // do not flush + null); +} + +// transitive closure on binary types does not need to include annotations - variant +public void test191() { + this.runConformTest( + new String[] { + "A.java", + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" + + "public @interface A {\n" + + " int value();\n" + + "}\n" + }, + ""); + String binName1 = OUTPUT_DIR + File.separator + "bin1"; + File bin1 = new File(binName1); + bin1.mkdir(); + String [] javaClassLibs = Util.getJavaClassLibs(); + int javaClassLibsLength; + String [] xClassLibs = new String[(javaClassLibsLength = javaClassLibs.length) + 2]; + System.arraycopy(javaClassLibs, 0, xClassLibs, 0, javaClassLibsLength); + xClassLibs[javaClassLibsLength] = OUTPUT_DIR; + xClassLibs[javaClassLibsLength + 1] = binName1; + (new File(OUTPUT_DIR + File.separator + "A.class")).renameTo(new File(binName1 + File.separator + "A.class")); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @A(0)\n" + + " void foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " new X().foo();\n" + + " }\n" + + "}", + }, + "SUCCESS", + xClassLibs, + false, // do not flush + null); + String binName2 = OUTPUT_DIR + File.separator + "bin2"; + File bin2 = new File(binName2); + bin2.mkdir(); + (new File(OUTPUT_DIR + File.separator + "X.class")).renameTo(new File(binName2 + File.separator + "X.class")); + String [] yClassLibs = new String[javaClassLibsLength + 2]; + System.arraycopy(javaClassLibs, 0, yClassLibs, 0, javaClassLibsLength); + yClassLibs[javaClassLibsLength] = OUTPUT_DIR; + yClassLibs[javaClassLibsLength + 1] = binName2; + // Y compiles despite the fact that A is not on the classpath + this.runConformTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String args[]) {\n" + + " new X().foo();\n" + + " }\n" + + "}", + }, + "SUCCESS", + yClassLibs, + false, // do not flush + null); +} + +public void test192() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @ATest(groups={\"a\",\"b\"})\n" + + " void foo(){\n" + + " }\n" + + " @ATest(groups=\"c\")\n" + + " void bar(){\n" + + " }\n" + + "}\n" + + "@interface ATest {\n" + + " String[] groups();\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=102160 +public void test193() { + this.runNegativeTest( + new String[] { + "A.java", + "public @interface A {\n" + + " A circular1();\n" + + "}\n" + + "@interface B {\n" + + " A circular2();\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " A circular1();\n" + + " ^\n" + + "Cycle detected: the annotation type A cannot contain attributes of the annotation type itself\n" + + "----------\n" + ); + this.runNegativeTest( + new String[] { + "A.java", + "public @interface A {\n" + + " B circular2();\n" + + " A circular1();\n" + + "}\n" + + "@interface B {\n" + + " A circular();\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " B circular2();\n" + + " ^\n" + + "Cycle detected: a cycle exists between annotation attributes of A and B\n" + + "----------\n" + + "2. ERROR in A.java (at line 3)\n" + + " A circular1();\n" + + " ^\n" + + "Cycle detected: the annotation type A cannot contain attributes of the annotation type itself\n" + + "----------\n" + + "3. ERROR in A.java (at line 6)\n" + + " A circular();\n" + + " ^\n" + + "Cycle detected: a cycle exists between annotation attributes of B and A\n" + + "----------\n" + ); + this.runNegativeTest( + new String[] { + "A.java", + "public @interface A {\n" + + " A circular1();\n" + + " B circular2();\n" + + "}\n" + + "@interface B {\n" + + " A circular();\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " A circular1();\n" + + " ^\n" + + "Cycle detected: the annotation type A cannot contain attributes of the annotation type itself\n" + + "----------\n" + + "2. ERROR in A.java (at line 3)\n" + + " B circular2();\n" + + " ^\n" + + "Cycle detected: a cycle exists between annotation attributes of A and B\n" + + "----------\n" + + "3. ERROR in A.java (at line 6)\n" + + " A circular();\n" + + " ^\n" + + "Cycle detected: a cycle exists between annotation attributes of B and A\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130017 +public void test194() { + String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 + ? "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @Override\n" + + " ^^^^^^^^^\n" + + "The annotation @Override is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " public static void foo() {}\n" + + " ^^^^^\n" + + "The method foo() of type X must override a superclass method\n" + + "----------\n" + : "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @Override\n" + + " ^^^^^^^^^\n" + + "The annotation @Override is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " public static void foo() {}\n" + + " ^^^^^\n" + + "The method foo() of type X must override or implement a supertype method\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "class Base {\n" + + " public static void foo() {}\n" + + "}\n" + + "public class X extends Base {\n" + + " @Override\n" + + " X(){}\n" + + " \n" + + " @Override\n" + + " public static void foo() {}\n" + + "}\n" + }, + expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130516 +public void test195() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"cast\")\n" + + " void foo() {\n" + + " String s = (String) \"hello\";\n" + + " }\n" + + " void bar() {\n" + + " String s = (String) \"hello\";\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " String s = (String) \"hello\";\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n" + + "2. 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=133440 +public void test196() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " enum MyEnum {\n" + + " VAL_1, VAL_2\n" + + " }\n" + + " public MyEnum theValue() default null;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public MyEnum theValue() default null;\n" + + " ^^^^\n" + + "The value for annotation attribute X.theValue must be an enum constant expression\n" + + "----------\n"); +} +// no override between package private methods +public void test197() { + String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 + ? "----------\n" + + "1. WARNING in p\\X.java (at line 4)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method X.foo() does not override the inherited method from OldStuff since it is private to a different package\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 4)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() of type X must override a superclass method\n" + + "----------\n" + : "----------\n" + + "1. WARNING in p\\X.java (at line 4)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method X.foo() does not override the inherited method from OldStuff since it is private to a different package\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 4)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() of type X must override or implement a supertype method\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X extends q.OldStuff {\n" + + " @Override\n" + + " void foo() {\n" + + " }\n" + + "}\n", + "q/OldStuff.java", + "package q;\n" + + "public class OldStuff {\n" + + " void foo() {\n" + + " } \n" + + "}\n", + }, + expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134129 +public void test198() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Anno {\n" + + " boolean b() default false;\n" + + " String[] c() default \"\";\n" + + "}\n" + + "@Anno(b = {})\n" + + "public class X {\n" + + " @Anno(c = { 0 })\n" + + " void foo(){}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @Anno(b = {})\n" + + " ^^\n" + + "Type mismatch: cannot convert from Object[] to boolean\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " @Anno(c = { 0 })\n" + + " ^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=138443 +public void test199() { + this.runConformTest( + true, + new String[] { + "X.java", + "@interface AttributeOverrides {\n" + + " AttributeOverride[] value();\n" + + "}\n" + + "@interface AttributeOverride {\n" + + " String name();\n" + + " Column column();\n" + + "}\n" + + "@interface Column {\n" + + " String name();\n" + + "}\n" + + "@AttributeOverrides({\n" + + " @AttributeOverride( name=\"city\", column=@Column( name=\"DIAB99C_TXCTY\" )),\n" + + " @AttributeOverride( name=\"state\", column=@Column( name=\"DIAB99C_TXSTAT\" )),\n" + + " @AttributeOverride( name=\"zipCode\", column=@Column( name=\"DIAB99C_TXZIP\")),\n" + + "}) public class X {}" + }, + "", + "", + null, + JavacTestOptions.JavacHasABug.JavacBug6337964); +} +// JLS 3 - 9.6: cannot override Object's methods +public void test200() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface X {\n" + + " int clone();\n" + + " String finalize();\n" + + " boolean getClass();\n" + + " long notify();\n" + + " double notifyAll();\n" + + " float wait();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int clone();\n" + + " ^^^^^^^\n" + + "The annotation type X cannot override the method Object.clone()\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " String finalize();\n" + + " ^^^^^^^^^^\n" + + "The annotation type X cannot override the method Object.finalize()\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " boolean getClass();\n" + + " ^^^^^^^^^^\n" + + "The annotation type X cannot override the method Object.getClass()\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " long notify();\n" + + " ^^^^^^^^\n" + + "The annotation type X cannot override the method Object.notify()\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " double notifyAll();\n" + + " ^^^^^^^^^^^\n" + + "The annotation type X cannot override the method Object.notifyAll()\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " float wait();\n" + + " ^^^^^^\n" + + "The annotation type X cannot override the method Object.wait()\n" + + "----------\n"); +} +//JLS 3 - 9.6: cannot override Annotation's methods +public void test201() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface X {\n" + + " char hashCode();\n" + + " int annotationType();\n" + + " Class toString();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " char hashCode();\n" + + " ^^^^^^^^^^\n" + + "The annotation type X cannot override the method Annotation.hashCode()\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " int annotationType();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The annotation type X cannot override the method Annotation.annotationType()\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " Class toString();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Class toString();\n" + + " ^^^^^^^^^^\n" + + "The annotation type X cannot override the method Annotation.toString()\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=143259 +public void test202() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " @Ann(m=Object)\n" + + " private int foo;\n" + + " private NonExisting bar;\n" + + " }\n" + + " @interface Ann {\n" + + " String m();\n" + + " }\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Ann(m=Object)\n" + + " ^^^^^^\n" + + "Object cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " private NonExisting bar;\n" + + " ^^^^^^^^^^^\n" + + "NonExisting cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=143259 - variation +public void test203() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @Ann(m=Object())\n" + + " private void foo(){}\n" + + " private NonExisting bar(){}\n" + + "}\n" + + "@interface Ann {\n" + + " String m();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Ann(m=Object())\n" + + " ^^^^^^\n" + + "The method Object() is undefined for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " private NonExisting bar(){}\n" + + " ^^^^^^^^^^^\n" + + "NonExisting cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=143259 - variation +public void test204() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @Ann(m=bar(null))\n" + + " private void foo(){}\n" + + " private NonExisting bar(NonExisting ne){}\n" + + "}\n" + + "@interface Ann {\n" + + " String m();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Ann(m=bar(null))\n" + + " ^^^\n" + + "The method bar(NonExisting) from the type X refers to the missing type NonExisting\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " private NonExisting bar(NonExisting ne){}\n" + + " ^^^^^^^^^^^\n" + + "NonExisting cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " private NonExisting bar(NonExisting ne){}\n" + + " ^^^^^^^^^^^\n" + + "NonExisting cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=143259 - variation +public void test205() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @Ann(m=foo())\n" + + " private void foo(){}\n" + + " private NonExisting bar(NonExisting ne){}\n" + + "}\n" + + "@interface Ann {\n" + + " String m();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Ann(m=foo())\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from void to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " private NonExisting bar(NonExisting ne){}\n" + + " ^^^^^^^^^^^\n" + + "NonExisting cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " private NonExisting bar(NonExisting ne){}\n" + + " ^^^^^^^^^^^\n" + + "NonExisting cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=143259 - variation +public void test206() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @Ann(m=bar())\n" + + " private void foo(){}\n" + + " private NonExisting bar(){}\n" + + "}\n" + + "@interface Ann {\n" + + " String m();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Ann(m=bar())\n" + + " ^^^\n" + + "The method bar() from the type X refers to the missing type NonExisting\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " private NonExisting bar(){}\n" + + " ^^^^^^^^^^^\n" + + "NonExisting cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=143259 - variation +public void test207() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + "@Ann(m=foo)\n" + + " private NonExisting foo;\n" + + " private NonExisting bar;\n" + + " }\n" + + " @interface Ann {\n" + + " String m();\n" + + " }\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Ann(m=foo)\n" + + " ^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " @Ann(m=foo)\n" + + " ^^^\n" + + "NonExisting cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " private NonExisting foo;\n" + + " ^^^^^^^^^^^\n" + + "NonExisting cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " private NonExisting bar;\n" + + " ^^^^^^^^^^^\n" + + "NonExisting cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751 +public void test208() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public MyEnum value();\n" + + "}\n" + + "enum MyEnum {\n" + + " ONE, TWO, THREE\n" + + "}\n" + + "@MyAnnotation(X.FOO) class MyClass {\n" + + "}\n" + + "public class X {\n" + + " public static final MyEnum FOO = MyEnum.TWO;\n" + + " public static void main(String[] args) {\n" + + " MyAnnotation annotation =\n" + + " MyClass.class.getAnnotation(MyAnnotation.class);\n" + + " System.out.println(annotation.value().toString());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @MyAnnotation(X.FOO) class MyClass {\n" + + " ^^^^^\n" + + "The value for annotation attribute MyAnnotation.value must be an enum constant expression\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751 +public void test209() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public MyEnum value();\n" + + "}\n" + + "enum MyEnum {\n" + + " ONE, TWO, THREE\n" + + "}\n" + + "@MyAnnotation(value=X.FOO) class MyClass {\n" + + "}\n" + + "public class X {\n" + + " public static final MyEnum FOO = MyEnum.TWO;\n" + + " public static void main(String[] args) {\n" + + " MyAnnotation annotation =\n" + + " MyClass.class.getAnnotation(MyAnnotation.class);\n" + + " System.out.println(annotation.value().toString());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @MyAnnotation(value=X.FOO) class MyClass {\n" + + " ^^^^^\n" + + "The value for annotation attribute MyAnnotation.value must be an enum constant expression\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751 +public void test210() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public MyEnum[] value();\n" + + "}\n" + + "enum MyEnum {\n" + + " ONE, TWO, THREE\n" + + "}\n" + + "@MyAnnotation(value= { X.FOO }) class MyClass {\n" + + "}\n" + + "public class X {\n" + + " public static final MyEnum FOO = MyEnum.TWO;\n" + + " public static void main(String[] args) {\n" + + " MyAnnotation annotation =\n" + + " MyClass.class.getAnnotation(MyAnnotation.class);\n" + + " System.out.println(annotation.value().toString());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @MyAnnotation(value= { X.FOO }) class MyClass {\n" + + " ^^^^^\n" + + "The value for annotation attribute MyAnnotation.value must be an enum constant expression\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149751 +public void test211() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public MyEnum[] value();\n" + + "}\n" + + "enum MyEnum {\n" + + " ONE, TWO, THREE\n" + + "}\n" + + "@MyAnnotation(value= { null }) class MyClass {\n" + + "}\n" + + "public class X {\n" + + " public static final MyEnum FOO = MyEnum.TWO;\n" + + " public static void main(String[] args) {\n" + + " MyAnnotation annotation =\n" + + " MyClass.class.getAnnotation(MyAnnotation.class);\n" + + " System.out.println(annotation.value().toString());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @MyAnnotation(value= { null }) class MyClass {\n" + + " ^^^^\n" + + "The value for annotation attribute MyAnnotation.value must be an enum constant expression\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156891 +public void test212() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public MyEnum[] values();\n" + + "}\n" + + "enum MyEnum {\n" + + " ONE, TWO, THREE\n" + + "}\n" + + "public class X {\n" + + "\n" + + " private static final MyEnum[] myValues = { MyEnum.ONE, MyEnum.TWO };\n" + + " @MyAnnotation(values=myValues) \n" + + " public void dothetrick(){} \n" + + "\n" + + " public static void main(String[] args)throws Exception {\n" + + " MyAnnotation sluck = X.class.getMethod(\"dothetrick\", new Class[0]).getAnnotation(MyAnnotation.class);\n" + + " System.out.println(sluck.values().length);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " @MyAnnotation(values=myValues) \n" + + " ^^^^^^^^\n" + + "The value for annotation attribute MyAnnotation.values must be an array initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156891 +public void test213() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "@Retention(RUNTIME) @interface MyAnnotation {\n" + + " public int[] values();\n" + + "}\n" + + "public class X {\n" + + "\n" + + " private static final int[] myValues = { 1, 2, 3 };\n" + + " @MyAnnotation(values=myValues) \n" + + " public void dothetrick(){} \n" + + "\n" + + " public static void main(String[] args)throws Exception {\n" + + " MyAnnotation sluck = X.class.getMethod(\"dothetrick\", new Class[0]).getAnnotation(MyAnnotation.class);\n" + + " System.out.println(sluck.values().length);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @MyAnnotation(values=myValues) \n" + + " ^^^^^^^^\n" + + "The value for annotation attribute MyAnnotation.values must be an array initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141931 +public void test214() { + Map customOptions = getCompilerOptions(); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotation, + CompilerOptions.ERROR); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, + CompilerOptions.DISABLED); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 + ? "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo();\n" + + " ^^^^^\n" + + "The method foo() of type I must override a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public void foo() {}\n" + + " ^^^^^\n" + + "The method foo() of type X must override a superclass method\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " void foo();\n" + + " ^^^^^\n" + + "The method foo() of type J must override a superclass method\n" + + "----------\n" + : "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo();\n" + + " ^^^^^\n" + + "The method foo() of type I must override or implement a supertype method\n" + + "----------\n"; + this.runNegativeTest( + true, + new String[] { + "X.java", + "interface I {\n" + + " @Override\n" + + " void foo();\n" + + " void bar();\n" + + "}\n" + + "public class X implements I {\n" + + " @Override\n" + + " public void foo() {}\n" + + " public void bar() {}\n" + + "}\n" + + "interface J extends I {\n" + + " @Override\n" + + " void foo();\n" + + "}\n", + }, + null, + customOptions, + expectedOutput, + JavacTestOptions.SKIP); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=141931 +// variant +public void test215() { + String sources[] = new String[] { + "I.java", + "public interface I {\n" + + " void foo();\n" + + "}\n", + "X.java", + "abstract class X implements I {\n" + + "}\n", + "Y.java", + "class Y extends X {\n" + + " @Override\n" + + " public void foo() {}\n" + + "}\n"}; + if (new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6) { + this.runNegativeTest(sources, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " public void foo() {}\n" + + " ^^^^^\n" + + "The method foo() of type Y must override a superclass method\n" + + "----------\n"); + } else { + this.runConformTest(sources, + ""); + } +} +// extending java.lang.annotation.Annotation +public void test216() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "public class X {\n" + + " void bar(MyConstructor constructor, Class ann) {\n" + + " constructor.getAnnotation(ann).message();\n" + + " }\n" + + "}\n" + + "@interface Ann {\n" + + " String message();\n" + + "}\n" + + "class MyConstructor {\n" + + " public T getAnnotation(Class c) { return null; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void bar(MyConstructor constructor, Class ann) {\n" + + " ^^^^^^^^^^^^^\n" + + "MyConstructor is a raw type. References to generic type MyConstructor should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " constructor.getAnnotation(ann).message();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type MyConstructor. References to generic type MyConstructor should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " constructor.getAnnotation(ann).message();\n" + + " ^^^^^^^\n" + + "The method message() is undefined for the type Annotation\n" + + "----------\n"); +} +// extending java.lang.annotation.Annotation +public void test217() { + Map customOptions = getCompilerOptions(); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotation, + CompilerOptions.ERROR); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, + CompilerOptions.DISABLED); + String expectedOutput = + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void bar(MyConstructor constructor, Class ann) {\n" + + " ^^^^^^^^^^^^^\n" + + "MyConstructor is a raw type. References to generic type MyConstructor should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " constructor.getAnnotation(ann).message();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type MyConstructor. References to generic type MyConstructor should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " constructor.getAnnotation(ann).message();\n" + + " ^^^^^^^\n" + + "The method message() is undefined for the type Annotation\n" + + "----------\n"; + this.runNegativeTest( + true, + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "public class X {\n" + + " void bar(MyConstructor constructor, Class ann) {\n" + + " constructor.getAnnotation(ann).message();\n" + + " }\n" + + "}\n" + + "@interface Ann {\n" + + " String message();\n" + + "}\n" + + "interface Z {\n" + + " T getAnnotation(Class c);\n" + + "}\n" + + "class MyAccessibleObject implements Z {\n" + + " public T getAnnotation(Class c) { return null; }\n" + + "}\n" + + "class MyConstructor {\n" + + " public T getAnnotation(Class c) { return null; }\n" + + "}\n", + }, + null, + customOptions, + expectedOutput, + JavacTestOptions.SKIP); +} +// extending java.lang.annotation.Annotation +public void test218() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "import java.lang.reflect.Constructor;\n" + + "public class X {\n" + + " void bar(Constructor constructor, Class ann) {\n" + + " constructor.getAnnotation(ann).message();\n" + + " }\n" + + "}\n" + + "@interface Ann {\n" + + " String message();\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void bar(Constructor constructor, Class ann) {\n" + + " ^^^^^^^^^^^\n" + + "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " constructor.getAnnotation(ann).message();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " constructor.getAnnotation(ann).message();\n" + + " ^^^^^^^\n" + + "The method message() is undefined for the type Annotation\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBug6400189); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=167217 +public void test219() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @MyB1(MyA2.XX)\n" + + " public void foo(){}\n" + + "}", + "MyA1.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA1 {\n" + + "}", + "MyA2.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA2 {\n" + + " public static final MyA1 XX = null;\n" + + "}", + "MyB1.java", + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE, METHOD\n" + + "})\n" + + "public @interface MyB1 {\n" + + " MyA1 value();\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @MyB1(MyA2.XX)\n" + + " ^^^^^^^\n" + + "The value for annotation attribute MyB1.value must be some @MyA1 annotation \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167217 +public void test220() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @MyB1({MyA2.XX})\n" + + " public void foo(){}\n" + + "}", + "MyA1.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA1 {\n" + + "}", + "MyA2.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA2 {\n" + + " public static final MyA1 XX = null;\n" + + "}", + "MyB1.java", + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE, METHOD\n" + + "})\n" + + "public @interface MyB1 {\n" + + " MyA1[] value();\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @MyB1({MyA2.XX})\n" + + " ^^^^^^^\n" + + "The value for annotation attribute MyB1.value must be some @MyA1 annotation \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167217 +public void test221() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @MyB1(null)\n" + + " public void foo(){}\n" + + "}", + "MyA1.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA1 {\n" + + "}", + "MyA2.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA2 {\n" + + " public static final MyA1 XX = null;\n" + + "}", + "MyB1.java", + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE, METHOD\n" + + "})\n" + + "public @interface MyB1 {\n" + + " MyA1 value();\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @MyB1(null)\n" + + " ^^^^\n" + + "The value for annotation attribute MyB1.value must be some @MyA1 annotation \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167217 +public void test222() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @MyB1({null})\n" + + " public void foo(){}\n" + + "}", + "MyA1.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA1 {\n" + + "}", + "MyA2.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA2 {\n" + + " public static final MyA1 XX = null;\n" + + "}", + "MyB1.java", + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE, METHOD\n" + + "})\n" + + "public @interface MyB1 {\n" + + " MyA1[] value();\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @MyB1({null})\n" + + " ^^^^\n" + + "The value for annotation attribute MyB1.value must be some @MyA1 annotation \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167217 +public void test223() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @MyB1(@MyA1())\n" + + " public void foo(){}\n" + + "}", + "MyA1.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA1 {\n" + + "}", + "MyA2.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA2 {\n" + + " public static final MyA1 XX = null;\n" + + "}", + "MyB1.java", + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE, METHOD\n" + + "})\n" + + "public @interface MyB1 {\n" + + " MyA1 value();\n" + + "}" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167217 +public void test224() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @MyB1({@MyA1(), @MyA1})\n" + + " public void foo(){}\n" + + "}", + "MyA1.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA1 {\n" + + "}", + "MyA2.java", + "import static java.lang.annotation.ElementType.TYPE;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE\n" + + "})\n" + + "public @interface MyA2 {\n" + + " public static final MyA1 XX = null;\n" + + "}", + "MyB1.java", + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target( {\n" + + " TYPE, METHOD\n" + + "})\n" + + "public @interface MyB1 {\n" + + " MyA1[] value();\n" + + "}" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=XXXXX +public void test225() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public void myMethod() {\n"+ + " @MyAnnot1()\n"+ + " }\n"+ + "}\n"+ + "@interface MyAnnot1 {\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @MyAnnot1()\n" + + " ^\n" + + "Syntax error, insert \"enum Identifier\" to complete EnumHeader\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " @MyAnnot1()\n" + + " ^\n" + + "Syntax error, insert \"EnumBody\" to complete BlockStatements\n" + + "----------\n", + null, + true, + null /* no custom options */, + false /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + true /* do not perform statements recovery */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179477 - variation +public void test226() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public @interface Annot {\n" + + " float[] value();\n" + + " Class[] classe();\n" + + " }\n" + + " @Annot(value={x}, classe={Zork.class,zork})\n" + + " class Inner {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " @Annot(value={x}, classe={Zork.class,zork})\n" + + " ^\n" + + "x cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " @Annot(value={x}, classe={Zork.class,zork})\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " @Annot(value={x}, classe={Zork.class,zork})\n" + + " ^^^^^^^^^^\n" + + "Class cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " @Annot(value={x}, classe={Zork.class,zork})\n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " @Annot(value={x}, classe={Zork.class,zork})\n" + + " ^^^^\n" + + "The value for annotation attribute X.Annot.classe must be a class literal\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186822 +public void test227() { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public @interface X {}\n" + + " ^\n" + + "Syntax error, annotation declaration cannot have type parameters\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 +public void test228() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"unchecked\") //unused\n" + + " void doNoEvil(){\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " @SuppressWarnings(\"unchecked\") //unused\n" + + " ^^^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unchecked\")\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y.java (at line 2)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 +public void test229() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({\"unchecked\",\"all\"})\n" + + " void doNoEvil(){\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. 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=127533 - variation +public void test230() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + enableAllWarningsForIrritants(options, IrritantSet.UNUSED); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({\"zork\", \"unused\" })\n" + + " void foo() {}\n" + + "}\n" + + "@SuppressWarnings({\"all\"})\n" + + "class X2 {\n" + + " @SuppressWarnings({\"zork\", \"unused\" })\n" + + " void foo() {}\n" + + "}\n", + }, + null, options, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " @SuppressWarnings({\"zork\", \"unused\" })\n" + + " ^^^^^^\n" + + "Unsupported @SuppressWarnings(\"zork\")\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " @SuppressWarnings({\"zork\", \"unused\" })\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unused\")\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " @SuppressWarnings({\"zork\", \"unused\" })\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unused\")\n" + + "----------\n", + null, null, JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation +public void test231() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + enableAllWarningsForIrritants(options, IrritantSet.UNUSED); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({\"zork\", \"unused\",\"all\"})\n" + + " void foo() {}\n" + + "}\n" + + "\n" + + "@SuppressWarnings({\"all\"})\n" + + "class X2 {\n" + + " @SuppressWarnings(\"unused\")\n" + + " void foo() {}\n" + + " Object z;\n" + + "}\n", + }, + null, options, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @SuppressWarnings({\"zork\", \"unused\",\"all\"})\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unused\")\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " @SuppressWarnings(\"unused\")\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unused\")\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation +public void test232() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({\"finally\",\"finally\"})\n" + + " public int test(int p) {\n" + + " try {\n" + + " return 1;\n" + + " } finally {\n" + + " return 2;\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y {}", + }, + null, options, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @SuppressWarnings({\"finally\",\"finally\"})\n" + + " ^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"finally\")\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation +public void test233() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({\"finally\",\"finally\"})\n" + + " public int test(int p) {\n" + + " try {\n" + + " return Zork;\n" + + " } finally {\n" + + " return 2;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " @SuppressWarnings({\"finally\",\"finally\"})\n" + + " ^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"finally\")\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " return Zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a variable\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127533 - variation +public void test234() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"finally\")\n" + // unused but no complaint since an error is nested (can't tell for sure) + " public int test(int p) {\n" + + " return Zork;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return Zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a variable\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207758 +public void test235() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void foo() {\n" + + " ArrayList al = null;\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " List ls = al;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " ArrayList al = null;\n" + + " ^^^^^^^^^\n" + + "ArrayList cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207758 - variation +public void test236() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void foo() {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " List ls = bar();\n" + + " }\n" + + " ArrayList bar() {\n" + + " return null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " List ls = bar();\n" + + " ^^^\n" + + "The method bar() from the type X refers to the missing type ArrayList\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " ArrayList bar() {\n" + + " ^^^^^^^^^\n" + + "ArrayList cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207758 - variation +public void test237() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " B get() { return null; }\n" + + " void foo() {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " List ls = get();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X {\n" + + " ^^^^^^^^^\n" + + "ArrayList cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " List ls = get();\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from B to List\n" + + "----------\n"); +} +public void test238() { + // check that if promoted to ERROR, unhandled warning token shouldn't be suppressed by @SuppressWarnings("all") + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnhandledWarningToken, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({\"zork\",\"all\"})\n" + + " void foo() {}\n" + + "}\n", + }, + null, options, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @SuppressWarnings({\"zork\",\"all\"})\n" + + " ^^^^^^\n" + + "Unsupported @SuppressWarnings(\"zork\")\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 +public void test239() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X implements I {}\n" + + "@SuppressWarnings(\"unused\")\n" + + "class Y extends X implements I {\n" + + " Zork z;\n" + + "}\n" + + "class Z extends X implements I {}\n" + + "interface I {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " class Z extends X implements I {}\n" + + " ^\n" + + "Redundant superinterface I for the type Z, already defined by X\n" + + "----------\n", + null, + false, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207411 +public void test240() { + this.runNegativeTest( + new String[] { + "X.java", + "@Deprecated @Zork\n" + + "public class X {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Deprecated @Zork\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210213 +public void test241() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public static T asClassUnchecked(Object object, T requiredClassObject) {\n" + + " return (T) object;\n" + + " }\n" + + " public static void main(String... args) {\n" + + " try {\n" + + " X[] xs = X.asClassUnchecked(\"abc\", (X[])null);\n" + + " System.out.println(xs.length);\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, + null, + options, + null); +} +///https://bugs.eclipse.org/bugs/show_bug.cgi?id=210422 - variation +public void test242() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public final class X implements Serializable {\n" + + " class SMember extends String {} \n" + + " @Annot(value = new SMember())\n" + + " void bar() {}\n" + + " @Annot(value = \n" + + " new X(){\n" + + " ZorkAnonymous1 z;\n" + + " void foo() {\n" + + " this.bar();\n" + + " Zork2 z;\n" + + " }\n" + + " })\n" + + " void foo() {}\n" + + "}\n" + + "@interface Annot {\n" + + " String value();\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public final class X implements Serializable {\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 3)\n" + + " class SMember extends String {} \n" + + " ^^^^^^\n" + + "The type SMember cannot subclass the final class String\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " @Annot(value = new SMember())\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.SMember to String\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " new X(){\n" + + " ^\n" + + "An anonymous class cannot subclass the final class X\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " ZorkAnonymous1 z;\n" + + " ^^^^^^^^^^^^^^\n" + + "ZorkAnonymous1 cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210213 - variation +public void test243() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings(\"unchecked\")\n" + + " void foo() {\n" + + " \n" + + " }\n" + + "} \n", + }, + "", + null, + false, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210213 - variation +public void test244() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.WARNING); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings(\"unchecked\")\n" + + " void foo() {\n" + + " \n" + + " }\n" + + "} \n", + }, + null, options, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " ^^^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unchecked\")\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210213 - variation +public void test245() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + enableAllWarningsForIrritants(options, IrritantSet.UNUSED); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings({\"unchecked\",\"unused\"})\n" + + " void foo() {\n" + + " \n" + + " }\n" + + "} \n", + }, + null, options, + "----------\n" + + "1. INFO in X.java (at line 3)\n" + + " @SuppressWarnings({\"unchecked\",\"unused\"})\n" + + " ^^^^^^^^^^^\n" + + "At least one of the problems in category \'unchecked\' is not analysed due to a compiler option being ignored\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " @SuppressWarnings({\"unchecked\",\"unused\"})\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unused\")\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210213 - variation +public void test245_ignored() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportSuppressWarningNotFullyAnalysed, CompilerOptions.IGNORE); + enableAllWarningsForIrritants(options, IrritantSet.UNUSED); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings({\"unchecked\",\"unused\"})\n" + + " void foo() {\n" + + " \n" + + " }\n" + + "} \n", + }, + null, options, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @SuppressWarnings({\"unchecked\",\"unused\"})\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unused\")\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210213 - variation +public void test245_error() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportSuppressWarningNotFullyAnalysed, CompilerOptions.ERROR); + enableAllWarningsForIrritants(options, IrritantSet.UNUSED); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings({\"unchecked\",\"unused\"})\n" + + " void foo() {\n" + + " \n" + + " }\n" + + "} \n", + }, + null, options, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @SuppressWarnings({\"unchecked\",\"unused\"})\n" + + " ^^^^^^^^^^^\n" + + "At least one of the problems in category \'unchecked\' is not analysed due to a compiler option being ignored\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " @SuppressWarnings({\"unchecked\",\"unused\"})\n" + + " ^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unused\")\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210213 - variation +public void test246() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings(\"all\")\n" + + " void foo() {\n" + + " \n" + + " }\n" + + "} \n", + }, + "", + null, + false, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=211609 +public void test247() { + if (this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + // only enable in 1.6 mode + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + new String[] { + "TestAnnotation.java", + "public @interface TestAnnotation {\n" + + " Class targetItem() default void.class;\n" + + "}" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @TestAnnotation\n" + + " private String foo;\n" + + "}", + }, + "", + null, + false, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=211609 +public void test248() { + this.runNegativeTest( + new String[] { + "TestAnnotation.java", + "public @interface TestAnnotation {\n" + + " String targetItem() default void.class;\n" + + "}" + }, + "----------\n" + + "1. ERROR in TestAnnotation.java (at line 2)\n" + + " String targetItem() default void.class;\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090 +public void test249() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "@Zork\n" + + "public class X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Zork\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = "public class X {"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090 +public void test250() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "@Deprecated\n" + + "@Zork\n" + + "@Annot(1)\n" + + "public class X {}", + "Annot.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Retention(RUNTIME)\n" + + "@interface Annot {\n" + + " int value() default -1;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Zork\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = + "@java.lang.Deprecated\n" + + "@Annot(value=(int) 1)\n" + + "public class X {"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090 +public void test251() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "@Deprecated\n" + + "@Zork\n" + + "@Annot(1)\n" + + "public class X {}", + "Annot.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Retention(CLASS)\n" + + "@interface Annot {\n" + + " int value() default -1;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Zork\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = + "@Annot(value=(int) 1)\n" + + "@java.lang.Deprecated\n" + + "public class X {"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090 +public void test252() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public void foo(@Deprecated @Zork @Annot(2) int i) {}\n" + + "}", + "Annot.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Retention(CLASS)\n" + + "@interface Annot {\n" + + " int value() default -1;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(@Deprecated @Zork @Annot(2) int i) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #22 @java.lang.Deprecated(\n" + + " )\n" + + " RuntimeInvisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 2\n" + + " #17 @Zork(\n" + + " )\n" + + " #18 @Annot(\n" + + " #19 value=(int) 2 (constant type)\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090 +public void test253() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public void foo(@Deprecated @Zork @Annot(2) int i) {}\n" + + "}", + "Annot.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Retention(RUNTIME)\n" + + "@interface Annot {\n" + + " int value() default -1;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(@Deprecated @Zork @Annot(2) int i) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 2\n" + + " #19 @java.lang.Deprecated(\n" + + " )\n" + + " #20 @Annot(\n" + + " #21 value=(int) 2 (constant type)\n" + + " )\n" + + " RuntimeInvisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #17 @Zork(\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090 +public void test254() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public void foo(@Deprecated int j, @Zork @Annot(3) int i) {}\n" + + "}", + "Annot.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Retention(RUNTIME)\n" + + "@interface Annot {\n" + + " int value() default -1;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(@Deprecated int j, @Zork @Annot(3) int i) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #19 @java.lang.Deprecated(\n" + + " )\n" + + " Number of annotations for parameter 1: 1\n" + + " #20 @Annot(\n" + + " #21 value=(int) 3 (constant type)\n" + + " )\n" + + " RuntimeInvisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 0\n" + + " Number of annotations for parameter 1: 1\n" + + " #17 @Zork(\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090 +public void test255() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public void foo(@Deprecated int j, @Annot(\"\") @Deprecated int i) {}\n" + + "}", + "Annot.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Retention(RUNTIME)\n" + + "@interface Annot {\n" + + " int value() default -1;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(@Deprecated int j, @Annot(\"\") @Deprecated int i) {}\n" + + " ^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #17 @java.lang.Deprecated(\n" + + " )\n" + + " Number of annotations for parameter 1: 1\n" + + " #17 @java.lang.Deprecated(\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090 +public void test256() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public void foo(@Deprecated int j, @Annot(\"\") @Deprecated int i) {}\n" + + "}", + "Annot.java", + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Retention(CLASS)\n" + + "@interface Annot {\n" + + " int value() default -1;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(@Deprecated int j, @Annot(\"\") @Deprecated int i) {}\n" + + " ^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #20 @java.lang.Deprecated(\n" + + " )\n" + + " Number of annotations for parameter 1: 1\n" + + " #20 @java.lang.Deprecated(\n" + + " )"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216570 +public void test257() { + if (new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static interface IFoo {\n" + + " public boolean eval(String s);\n" + + " }\n" + + " static class Foo implements IFoo {\n" + + " @Override\n" + + " public boolean eval(String s) {\n" + + " return true;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public boolean eval(String s) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The method eval(String) of type X.Foo must override a superclass method\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static interface IFoo {\n" + + " public boolean eval(String s);\n" + + " }\n" + + " static class Foo implements IFoo {\n" + + " @Override\n" + + " public boolean eval(String s) {\n" + + " return true;\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167262 +public void test258() { + String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 + ? "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " void bar();//3\n" + + " ^^^^^\n" + + "The method bar() of type Bar must override a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " public void bar() {}//4\n" + + " ^^^^^\n" + + "The method bar() of type BarImpl must override a superclass method\n" + + "----------\n" + : "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " void bar();//3\n" + + " ^^^^^\n" + + "The method bar() of type Bar must override or implement a supertype method\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "interface Foo {\n" + + " @Override\n" + + " String toString();//1\n" + + "}\n" + + "interface Bar extends Foo {\n" + + " @Override\n" + + " String toString();//2\n" + + " @Override\n" + + " void bar();//3\n" + + "}\n" + + "class BarImpl implements Bar {\n" + + " @Override\n" + + " public void bar() {}//4\n" + + "}\n" + }, + expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239273 +public void test259() { + this.runConformTest( + new String[] { + "Jpf.java", + "public class Jpf {\n" + + " @interface Action {\n" + + " Forward[] forwards();\n" + + " }\n" + + " @interface Forward {\n" + + " String name();\n" + + " String path();\n" + + " ActionOutput[] actionOutputs();\n" + + " }\n" + + " @interface ActionOutput {\n" + + " String name();\n" + + " Class type();\n" + + " }\n" + + " @Jpf.Action( \n" + + " forwards = { \n" + + " @Jpf.Forward(\n" + + " name = \"success\", \n" + + " path = \"results.jsp\", \n" + + " actionOutputs = { \n" + + " @Jpf.ActionOutput(\n" + + " name = \"mybeanmethodResult\", \n" + + " type = java.lang.String[].class) }) })\n" + + " public Forward mybeanmethod() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=245435 +public void test260() { + this.runConformTest( + new String[] { + "X.java", + "@X.StringAnnotation(X.CONSTANT_EXPRESSION)\n" + + "public class X {\n" + + " public @interface StringAnnotation {\n" + + " String value();\n" + + " }\n" + + " public final static String CONSTANT = \"Constant\";\n" + + " public final static String CONSTANT_EXPRESSION = CONSTANT + \"Expression\";\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239273 +public void test261() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + new String[] { + "X.java",//===================== + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Other().foo();\n" + + " }\n" + + "}\n", + "Annot.java",//===================== + "public @interface Annot {\n" + + " Class value();\n" + + "}\n", + "Other.java",//===================== + "public class Other {\n" + + " @Annot(value = Other[].class)\n" + + " void foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS", + null, + true, + null, + options, + null); + this.runConformTest( + new String[] { + "X.java",//===================== + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Other().foo();\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239273 - variation +public void test262() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + new String[] { + "X.java",//===================== + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Other().foo();\n" + + " }\n" + + "}\n", + "Annot.java",//===================== + "public @interface Annot {\n" + + " String[] values();\n" + + "}\n", + "Other.java",//===================== + "public class Other {\n" + + " @Annot(values = {\"foo\",\"bar\"})\n" + + " void foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS", + null, + true, + null, + options, + null); + this.runConformTest( + new String[] { + "X.java",//===================== + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Other().foo();\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239273 - variation +public void test263() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + new String[] { + "X.java",//===================== + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Other().foo();\n" + + " }\n" + + "}\n", + "Annot.java",//===================== + "public @interface Annot {\n" + + " String[] values();\n" + + "}\n", + "Other.java",//===================== + "public class Other {\n" + + " @Annot(values = {\"foo\",\"bar\"})\n" + + " void foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS", + null, + true, + null, + options, + null); + this.runConformTest( + new String[] { + "X.java",//===================== + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Other().foo();\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=256035 +public void test264() { + this.runConformTest( + new String[] { + "X.java", + "@interface Anno {\n" + + " String value();\n" + + "}\n" + + "\n" + + "@Anno(X.B)\n" + + "public class X {\n" + + " public static final String A = \"a\";\n" + + " public static final String B = A + \"b\";\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=258906 +public void test265() { + + INameEnvironment nameEnvironment = new FileSystem(Util.getJavaClassLibs(), new String[] {}, null); + IErrorHandlingPolicy errorHandlingPolicy = new IErrorHandlingPolicy() { + public boolean proceedOnErrors() { return true; } + public boolean stopOnFirstError() { return false; } + public boolean ignoreAllErrors() { return false; } + }; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + CompilerOptions compilerOptions = new CompilerOptions(options); + compilerOptions.performMethodsFullRecovery = false; + compilerOptions.performStatementsRecovery = false; + Requestor requestor = new Requestor(false, null /*no custom requestor*/, false, /* show category */ false /* show warning token*/); + requestor.outputPath = "bin/"; + IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); + + Compiler compiler = new Compiler(nameEnvironment, errorHandlingPolicy, compilerOptions, requestor, problemFactory); + compiler.options.produceReferenceInfo = true; + + String code = "@javax.xml.bind.annotation.XmlSchema(namespace = \"test\")\npackage testpack;\n"; + ICompilationUnit source = new CompilationUnit(code.toCharArray(), "testpack/package-info.java", null); + + // don't call compile as would be normally expected since that wipes out the lookup environment + // before we could query it. Use internal API resolve instead which can run a subset of the + // compilation steps for us. + + compiler.resolve (source, + true, // verifyMethods, + true, // boolean analyzeCode, + false // generateCode + ); + char [][] compoundName = new char [][] { "testpack".toCharArray(), "package-info".toCharArray()}; + ReferenceBinding type = compiler.lookupEnvironment.getType(compoundName); + AnnotationBinding[] annotations = null; + if (type != null && type.isValidBinding()) { + annotations = type.getAnnotations(); + } + assertTrue ("Annotations missing on package-info interface", annotations != null && annotations.length == 1); + assertEquals("Wrong annotation on package-info interface ", "@XmlSchema(namespace = (String)\"test\")", annotations[0].toString()); + nameEnvironment.cleanup(); + if (requestor.hasErrors) + System.err.print(requestor.problemLog); // problem log empty if no problems + compiler = null; +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220311 +public void test266() { + this.runNegativeTest( + new String[] { + "p/package-info.java", + "@Deprecated\n" + + "@Deprecated\n" + + "package p;" + }, + "----------\n" + + "1. ERROR in p\\package-info.java (at line 1)\n" + + " @Deprecated\n" + + " ^^^^^^^^^^^\n" + + this.repeatableIntroText + "@Deprecated"+ this.repeatableTrailerText + + "----------\n" + + "2. ERROR in p\\package-info.java (at line 2)\n" + + " @Deprecated\n" + + " ^^^^^^^^^^^\n" + + this.repeatableIntroText + "@Deprecated"+ this.repeatableTrailerText + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=261323. +// Test to make sure that the use of a static import as an annotation value counts as a use +// (and consequently that there is no unused static import warning) +public void test267() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + + runNegativeTest( + true, + new String[] { + "com/SomeTest.java", + "package com;\n" + + "import static com.SomeTest.UNCHECKED;\n" + + "@SuppressWarnings(UNCHECKED)\n" + + "public class SomeTest {\n" + + " public static final String UNCHECKED = \"unchecked\";\n" + + "}\n" + }, + null, customOptions, + "----------\n" + + "1. ERROR in com\\SomeTest.java (at line 3)\n" + + " @SuppressWarnings(UNCHECKED)\n" + + " ^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unchecked\")\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262304 +public void test268() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " protected enum E {\n" + + " E1, E2\n" + + " }\n" + + " protected @interface Anno1 { E value(); }\n" + + " protected @interface Anno2 { E value(); }\n" + + " protected @interface Anno3 { E value(); }\n" + + " @Anno1(true ? E.E1 : E.E2)\n" + + " @Anno2(bar())\n" + + " @Anno3(((E.E1)))\n" + + " public void foo() {\n" + + " }\n" + + " public E bar() { return E.E1; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " @Anno1(true ? E.E1 : E.E2)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The value for annotation attribute X.Anno1.value must be an enum constant expression\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " @Anno2(bar())\n" + + " ^^^^^\n" + + "The value for annotation attribute X.Anno2.value must be an enum constant expression\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=274917 +public void test269() { + Map customOptions = new Hashtable(); + String[] warnings = CompilerOptions.warningOptionNames(); + for (int i = 0, ceil = warnings.length; i < ceil; i++) { + customOptions.put(warnings[i], CompilerOptions.WARNING); + } + this.runConformTest( + true, + new String[] { + "X.java", + "@interface X {}", + }, + null, + customOptions, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " @interface X {}\n" + + " ^^\n" + + "Empty block should be documented\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=287009 +public void test270() { + this.runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " @interface Anno {\n" + + " Anno value();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Test.java (at line 3)\n" + + " Anno value();\n" + + " ^^^^\n" + + "Cycle detected: the annotation type Test.Anno cannot contain attributes of the annotation type itself\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=289576 +public void test271() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface A {}\n" + + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private void foo(@A Object o) {}\n" + + "}" + }, + ""); + + String expectedOutput = + " // Method descriptor #15 (Ljava/lang/Object;)V\n" + + " // Stack: 0, Locals: 2\n" + + " private void foo(@A java.lang.Object o);\n"; + + checkDisassembledClassFile(OUTPUT_DIR + File.separator +"X.class", "X", expectedOutput, ClassFileBytesDisassembler.DETAILED); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=289516 +public void test272() throws Exception { + if (this.complianceLevel != ClassFileConstants.JDK1_5) { + return; + } + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + this.runConformTest( + new String[] { + "X.java", + "@interface A {}\n" + + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private void foo(@A Object o) {}\n" + + "}" + }, + "", + null, + true, + null, + options, + null, + true); + + String expectedOutput = + " // Method descriptor #15 (Ljava/lang/Object;)V\n" + + " // Stack: 0, Locals: 2\n" + + " private void foo(@A java.lang.Object o);\n"; + + checkDisassembledClassFile(OUTPUT_DIR + File.separator +"X.class", "X", expectedOutput, ClassFileBytesDisassembler.DETAILED); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=289576 +public void test273() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface A {}\n" + + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private X(@A Object o) {}\n" + + "}" + }, + ""); + + String expectedOutput = + " // Method descriptor #6 (Ljava/lang/Object;)V\n" + + " // Stack: 1, Locals: 2\n" + + " private X(@A java.lang.Object o);\n"; + + checkDisassembledClassFile(OUTPUT_DIR + File.separator +"X.class", "X", expectedOutput, ClassFileBytesDisassembler.DETAILED); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163194 +// To check Missing override annotation error when a method implements +// and also overrides a method in a superclass +public void test274a() { + String testString [] = new String[] { + "T.java", + "public interface T {\n" + + " void m();\n" + + "}\n" + + "abstract class A implements T {\n" + + "}\n" + + "class B extends A {\n" + + " public void m() {}\n" + + "}\n" + }; + Map customOptions = getCompilerOptions(); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotation, + CompilerOptions.ERROR); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, + CompilerOptions.ENABLED); + if (new CompilerOptions(customOptions).sourceLevel >= ClassFileConstants.JDK1_6) { + String expectedOutput = + "----------\n" + + "1. ERROR in T.java (at line 7)\n" + + " public void m() {}\n" + + " ^^^\n" + + "The method m() of type B should be tagged with @Override since it actually overrides a superinterface method\n" + + "----------\n"; + this.runNegativeTest( + true, + testString, + null, customOptions, + expectedOutput, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } else { + this.runConformTest( + true, testString, + null, + customOptions, + null, + null, null, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163194 +// To check Missing override annotation error when a method implements but +// doesn't overrides +public void test274b() { + String testString [] = new String[] { + "Over.java", + "interface I {\n" + + " void m();\n" + + "}\n" + + "public class Over implements I {\n" + + " public void m() {}\n" + + "}\n" + }; + Map customOptions = getCompilerOptions(); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotation, + CompilerOptions.ERROR); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, + CompilerOptions.ENABLED); + if (new CompilerOptions(customOptions).sourceLevel >= ClassFileConstants.JDK1_6) { + String expectedOutput = + "----------\n" + + "1. ERROR in Over.java (at line 5)\n" + + " public void m() {}\n" + + " ^^^\n" + + "The method m() of type Over should be tagged with @Override since it actually overrides a superinterface method\n" + + "----------\n"; + this.runNegativeTest( + true, + testString, + null, customOptions, + expectedOutput, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } else { + this.runConformTest( + true, testString, + null, + customOptions, + null, + null, null, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163194 +// To check Missing override annotation error when a method simply overrides +public void test274c() { + String testString [] = new String[] { + "B.java", + "interface A {\n" + + " void m();\n" + + "}\n" + + "public interface B extends A {\n" + + " void m();\n" + + "}\n" + }; + Map customOptions = getCompilerOptions(); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotation, + CompilerOptions.ERROR); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, + CompilerOptions.ENABLED); + if (new CompilerOptions(customOptions).sourceLevel >= ClassFileConstants.JDK1_6) { + String expectedOutput = + "----------\n" + + "1. ERROR in B.java (at line 5)\n" + + " void m();\n" + + " ^^^\n" + + "The method m() of type B should be tagged with @Override since it actually overrides a superinterface method\n" + + "----------\n"; + this.runNegativeTest( + true, + testString, + null, customOptions, + expectedOutput, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } else { + this.runConformTest( + true, testString, + null, + customOptions, + null, + null, null, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=163194 +// To check missing override annotation if the method has a signature +// that is override-equivalent to that of any public method declared in Object. +public void test274d() { + String testString [] = new String[] { + "A.java", + "public interface A {\n" + + " String toString();\n" + + "}\n" + }; + Map customOptions = getCompilerOptions(); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotation, + CompilerOptions.ERROR); + customOptions.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, + CompilerOptions.ENABLED); + if (new CompilerOptions(customOptions).sourceLevel >= ClassFileConstants.JDK1_6) { + String expectedOutput = + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " String toString();\n" + + " ^^^^^^^^^^\n" + + "The method toString() of type A should be tagged with @Override since it actually overrides a superinterface method\n" + + "----------\n"; + this.runNegativeTest( + true, + testString, + null, customOptions, + expectedOutput, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } else { + this.runConformTest( + true, testString, + null, + customOptions, + null, + null, null, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282770. +public void test275() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement, CompilerOptions.ENABLED); + + runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public static final boolean DEBUG = false;\n" + + "// @SuppressWarnings(\"unused\")\n" + + " public void foo() {\n" + + " if (DEBUG)\n" + + " System.out.println(\"true\");\n" + + " else\n" + + " System.out.println(\"false\");\n" + + " \n" + + " }\n" + + "}\n" + }, + null, + customOptions, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " System.out.println(\"true\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + "", + "", + JavacTestOptions.SKIP); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282770. +public void test276() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement, CompilerOptions.ENABLED); + + runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public static final boolean DEBUG = false;\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void foo() {\n" + + " if (DEBUG)\n" + + " System.out.println(\"true\");\n" + + " else\n" + + " System.out.println(\"false\");\n" + + " \n" + + " }\n" + + "}\n" + }, + null, + customOptions, + "", + "", + "", + JavacTestOptions.SKIP); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282770. +public void test277() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement, CompilerOptions.DISABLED); + + runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public static final boolean DEBUG = false;\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void foo() {\n" + + " if (0 < 1)\n" + + " System.out.println(\"true\");\n" + + " else\n" + + " System.out.println(\"false\");\n" + + " \n" + + " }\n" + + "}\n" + }, + null, + customOptions, + "", + "", + "", + JavacTestOptions.SKIP); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=293777 +// To verify that a misleading warning against @Override annotation is not +// issued in case the method signature has not been resolved properly. +public void test278() { + String testString [] = new String[] { + "A.java", + "import javax.swing.JComponent;\n" + + "public class A extends JComponent {\n" + + " @Override\n" + + " protected void paintComponent(Graphics g) {" + + " }\n" + + "}\n" + }; + String expectedOutput = + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " public class A extends JComponent {\n" + + " ^\n" + + "The serializable class A does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in A.java (at line 4)\n" + + " protected void paintComponent(Graphics g) { }\n" + + " ^^^^^^^^\n" + + "Graphics cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest( + testString, + expectedOutput); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=301683 +public void test279() { + String testString [] = new String[] { + "A.java", + "public class A {\n" + + " public @interface Inline {\n" + + " String value();\n" + + " }\n" + + " @Inline(\"foo\")\n" + + " public Zork test;\n" + + " public native void method();\n" + + "}" + }; + String expectedOutput = + "----------\n" + + "1. ERROR in A.java (at line 6)\n" + + " public Zork test;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest( + testString, + expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test280() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "A.java", + "public class A {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private int i;\n" + // problem configured as warning but still suppressed + "}\n" + }; + runConformTest( + testFiles, + null, + null, + true, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test281() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.DISABLED); // this option overrides the next + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "A.java", + "public class A {\n" + + " @SuppressWarnings(\"unused\")\n" + + " private int i;\n" + + "}\n" + }; + String expectedErrorString = + "----------\n" + + "1. ERROR in A.java (at line 3)\n" + + " private int i;\n" + + " ^\n" + + "The value of the field A.i is not used\n" + + "----------\n"; + runNegativeTest( + true, + testFiles, + null, + customOptions, + expectedErrorString, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test282() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "A.java", + "import java.util.Map;\n" + + "public class A {\n" + + " @SuppressWarnings({\"rawtypes\", \"unused\"})\n" + //suppress a warning and an error + " private Map i;\n" + + "}\n" + }; + runConformTest( + testFiles, + null, + null, + true, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551 +public void test283() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "A.java", + "public class A {\n" + + " @SuppressWarnings(\"all\")\n" + + " private void i;\n" + // cannot suppress mandatory error + "}\n" + }; + String expectedErrorString = + "----------\n" + + "1. ERROR in A.java (at line 3)\n" + + " private void i;\n" + + " ^\n" + + "void is an invalid type for the variable i\n" + + "----------\n"; + runNegativeTest( + true, + testFiles, + null, + customOptions, + expectedErrorString, + JavacTestOptions.SKIP); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304031 +public void test284() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " @SuppressWarnings(\"cast\")\n" + + " int i= (int) 0;\n" + + " @SuppressWarnings(\"cast\")\n" + + " byte b= (byte) i;\n" + + " System.out.println(b);\n" + + " }\n" + + "}" + }; + String expectedErrorString = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @SuppressWarnings(\"cast\")\n" + + " ^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"cast\")\n" + + "----------\n"; + runNegativeTest( + true, + testFiles, + null, + customOptions, + expectedErrorString, + JavacTestOptions.SKIP); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304031 +public void test285() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " @SuppressWarnings(\"cast\")\n" + + " int i= (int) 0;\n" + + " @SuppressWarnings(\"cast\")\n" + + " byte b= (byte) i;\n" + + " System.out.println(b);\n" + + " }\n" + + "}" + }; + String expectedErrorString = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @SuppressWarnings(\"cast\")\n" + + " ^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"cast\")\n" + + "----------\n"; + runNegativeTest( + true, + testFiles, + null, + customOptions, + expectedErrorString, + JavacTestOptions.SKIP); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304031 +public void test286() { + Map raiseDeprecationReduceInvalidJavadocSeverity = + new HashMap(2); + raiseDeprecationReduceInvalidJavadocSeverity.put( + CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + raiseDeprecationReduceInvalidJavadocSeverity.put( + CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + raiseDeprecationReduceInvalidJavadocSeverity.put( + CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"deprecation\")\n" + + "public class X extends p.OldStuff {\n" + + " /**\n" + + " * @see p.OldStuff#foo()\n" + + " */\n" + + " @Override\n" + + " public void foo() {\n" + + " super.foo();\n" + + " }\n" + + "}\n", + "p/OldStuff.java", + "package p;\n" + + "@Deprecated\n" + + "public class OldStuff {\n" + + " public void foo() {\n" + + " } \n" + + "}\n", + }, + "", + null, + true, + null, + raiseDeprecationReduceInvalidJavadocSeverity, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=311849 +public void test287() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " void foo(ArrayList arg) {\n" + + " for (\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " boolean a= arg.add(1), b= arg.add(1);\n" + + " Boolean.FALSE;\n" + + " ) {\n" + + " System.out.println(a && b);\n" + + " }\n" + + " }\n" + + "}", + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=311849 +public void test288() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " ArrayList arg;\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " boolean a= arg.add(1), b= arg.add(1);\n" + + "}", + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=311849 +public void test289() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " void foo(ArrayList arg) {\n" + + " for (\n" + + " @Deprecated\n" + + " @Other\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " boolean a= arg.add(1), b= arg.add(1);\n" + + " Boolean.FALSE;\n" + + " ) {\n" + + " System.out.println(a && b);\n" + + " }\n" + + " }\n" + + "}", + "Other.java", + "@interface Other {}" + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=313109 +public void test290() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "class X {\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " void foo(ArrayList arg) {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " boolean aa = arg.add(1), bb = arg.add(1);\n" + + " if (bb)\n" + + " System.out.println(\"hi\");\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=313109 +public void test291() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "class X {\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " void foo(ArrayList arg) {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " boolean aa = arg.add(1), bb = arg.add(1);\n" + + " if (aa)\n" + + " System.out.println(\"hi\");\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=313109 +public void test292() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "class X {\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " void foo(ArrayList arg) {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " boolean aa = arg.add(1), bb = arg.add(1);\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316456 +public void test293() { + this.runNegativeTest( + new String[] { + "X.java", + "@A(name = X.QUERY_NAME, query = X.QUERY)\n" + + "public class X {\n" + + " public static final String QUERY_NAME = \"client.query.name\";\n" + + " private static final String QUERY = \"from Client\";\n" + + "}\n" + + "@interface A{\n" + + " String name();\n" + + " String query();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @A(name = X.QUERY_NAME, query = X.QUERY)\n" + + " ^^^^^\n" + + "The field X.QUERY is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179566 +public void test294() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportMissingJavadocComments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "A.java", + "/** */\n" + + "public class A {\n" + + " @SuppressWarnings(\"javadoc\")\n" + + " public int foo(int i) { return 0; }\n" + + "}\n" + }; + runConformTest( + testFiles, + null, + null, + true, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179566 +public void test295() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportMissingJavadocComments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "A.java", + "/** */\n" + + "public class A {\n" + + " /**\n" + + " * @param j the given param/\n" + + " */\n" + + " @SuppressWarnings(\"javadoc\")\n" + + " public int foo(int i) { return 0; }\n" + + "}\n" + }; + runConformTest( + testFiles, + null, + null, + true, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179566 +public void test296() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportMissingJavadocComments, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "A.java", + "/** */\n" + + "public class A {\n" + + " /**\n" + + " * @param i/\n" + + " */\n" + + " @SuppressWarnings(\"javadoc\")\n" + + " public int foo(int i) { return 0; }\n" + + "}\n" + }; + runConformTest( + testFiles, + null, + null, + true, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=343621 +public void test297() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.ENABLED); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnhandledWarningToken, CompilerOptions.WARNING); + runner.customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + runner.customOptions.put(CompilerOptions.OPTION_ReportComparingIdentical, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + + runner.expectedCompilerLog = + "----------\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) { + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in A.java (at line 10)\n" + + " public final Object build(Class... 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"; + } + runner.testFiles = new String[] { + "A.java", + "public class A {\n" + + " public void one() {\n" + + " @SuppressWarnings(\"unused\")\n" + + " Object object = new Object();\n" + + " }\n" + + " public void two() {\n" + + " @SuppressWarnings({ \"unchecked\", \"unused\" })\n" + + " Object object = build();\n" + + " }\n" + + " public final Object build(Class... objects) {\n" + + " return null;\n" + + " }\n" + + " public boolean bar() {\n" + + " int i = 0;\n" + + " return i == i;\n" + + " }\n" + + "}" + }; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +// Bug 366003 - CCE in ASTNode.resolveAnnotations(ASTNode.java:639) +// many syntax errors fixed, does not trigger CCE +public void testBug366003() { + runNegativeTest( + new String[] { + "snippet/Bug366003.java", + "package snippet;\n" + + "public class Bug366003 {\n" + + " public void foo(@NonNull Object o1) {\n" + + " System.out.println(o1.toString()); // OK: o1 cannot be null\n" + + " } \n" + + " @NonNull Object bar(@Nullable String s1) {\n" + + " foo(null); // cannot pass null argument\n" + + " @NonNull String s= null; // cannot assign null value\n" + + " @NonNull String t= s1; // cannot assign potentially null value\n" + + " return null; // cannot return null value\n" + + " }\n" + + "}\n" + + "org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + "" + }, + "----------\n" + + "1. ERROR in snippet\\Bug366003.java (at line 3)\n" + + " public void foo(@NonNull Object o1) {\n" + + " ^^^^^^^\n" + + "NonNull cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in snippet\\Bug366003.java (at line 6)\n" + + " @NonNull Object bar(@Nullable String s1) {\n" + + " ^^^^^^^\n" + + "NonNull cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in snippet\\Bug366003.java (at line 6)\n" + + " @NonNull Object bar(@Nullable String s1) {\n" + + " ^^^^^^^^\n" + + "Nullable cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in snippet\\Bug366003.java (at line 8)\n" + + " @NonNull String s= null; // cannot assign null value\n" + + " ^^^^^^^\n" + + "NonNull cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in snippet\\Bug366003.java (at line 9)\n" + + " @NonNull String t= s1; // cannot assign potentially null value\n" + + " ^^^^^^^\n" + + "NonNull cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in snippet\\Bug366003.java (at line 12)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n" + + "7. ERROR in snippet\\Bug366003.java (at line 13)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^\n" + + "Syntax error, insert \"Identifier (\" to complete MethodHeaderName\n" + + "----------\n" + + "8. ERROR in snippet\\Bug366003.java (at line 13)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^\n" + + "Syntax error, insert \")\" to complete MethodDeclaration\n" + + "----------\n" + + "9. ERROR in snippet\\Bug366003.java (at line 13)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^\n" + + "Syntax error, insert \";\" to complete MethodDeclaration\n" + + "----------\n" + + "10. ERROR in snippet\\Bug366003.java (at line 13)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "11. ERROR in snippet\\Bug366003.java (at line 13)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "12. ERROR in snippet\\Bug366003.java (at line 13)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^^^^\n" + + "NonNull cannot be resolved to a type\n" + + "----------\n" + + "13. ERROR in snippet\\Bug366003.java (at line 13)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^^^^^\n" + + "Nullable cannot be resolved to a type\n" + + "----------\n" + + "14. ERROR in snippet\\Bug366003.java (at line 13)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^\n" + + "Syntax error, insert \";\" to complete ConstructorDeclaration\n" + + "----------\n"); +} +// Bug 366003 - CCE in ASTNode.resolveAnnotations(ASTNode.java:639) +// code is garbage, triggers CCE +public void testBug366003b() { + runNegativeTest( + new String[] { + "snippet/Bug366003.java", + "package snippet;\n" + + "public class Bug366003 {\n" + + " public void foo(@Blah Object o1) { \n" + + "System.out.println(o1.toString()); // OK: o1 cannot be null } \n" + + "@Blah Object bar(@BlahBlah String s1) { foo(null); // cannot pass\n" + + "null argument @Blah String s= null; // cannot assign null value \n" + + " @Blah String t= s1; // cannot assign potentially null value \n" + + "return null; // cannot return null value }\n" + + "}\n" + + "\n" + + "org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + "" + }, + "----------\n" + + "1. ERROR in snippet\\Bug366003.java (at line 3)\n" + + " public void foo(@Blah Object o1) { \n" + + " ^^^^\n" + + "Blah cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in snippet\\Bug366003.java (at line 4)\n" + + " System.out.println(o1.toString()); // OK: o1 cannot be null } \n" + + " ^\n" + + "Syntax error, insert \"}\" to complete MethodBody\n" + + "----------\n" + + "3. ERROR in snippet\\Bug366003.java (at line 5)\n" + + " @Blah Object bar(@BlahBlah String s1) { foo(null); // cannot pass\n" + + " ^^^^\n" + + "Blah cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in snippet\\Bug366003.java (at line 5)\n" + + " @Blah Object bar(@BlahBlah String s1) { foo(null); // cannot pass\n" + + " ^^^^^^^^\n" + + "BlahBlah cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in snippet\\Bug366003.java (at line 6)\n" + + " null argument @Blah String s= null; // cannot assign null value \n" + + " ^^^^\n" + + "Syntax error on token \"null\", @ expected\n" + + "----------\n" + + "6. ERROR in snippet\\Bug366003.java (at line 11)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^\n" + + "Syntax error, insert \"Identifier (\" to complete MethodHeaderName\n" + + "----------\n" + + "7. ERROR in snippet\\Bug366003.java (at line 11)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^\n" + + "Syntax error, insert \")\" to complete MethodDeclaration\n" + + "----------\n" + + "8. ERROR in snippet\\Bug366003.java (at line 11)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^\n" + + "Syntax error, insert \";\" to complete MethodDeclaration\n" + + "----------\n" + + "9. ERROR in snippet\\Bug366003.java (at line 11)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "10. ERROR in snippet\\Bug366003.java (at line 11)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "11. ERROR in snippet\\Bug366003.java (at line 11)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^^^^\n" + + "NonNull cannot be resolved to a type\n" + + "----------\n" + + "12. ERROR in snippet\\Bug366003.java (at line 11)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^^^^^^^^\n" + + "Nullable cannot be resolved to a type\n" + + "----------\n" + + "13. ERROR in snippet\\Bug366003.java (at line 11)\n" + + " org.eclipse.User.User(@NonNull String name, int uid, @Nullable String email)\n" + + " ^\n" + + "Syntax error, insert \";\" to complete ConstructorDeclaration\n" + + "----------\n"); +} +// Bug 366003 - CCE in ASTNode.resolveAnnotations(ASTNode.java:639) +// minimal syntax error to trigger CCE +public void testBug366003c() { + runNegativeTest( + new String[] { + "snippet/Bug366003.java", + "package snippet;\n" + + "public class Bug366003 {\n" + + " void foo(Object o1) {\n" + + " }\n" + + "org.User(@Bla String a)" + }, + "----------\n" + + "1. ERROR in snippet\\Bug366003.java (at line 5)\n" + + " org.User(@Bla String a)\n" + + " ^^^\n" + + "Syntax error, insert \"Identifier (\" to complete MethodHeaderName\n" + + "----------\n" + + "2. ERROR in snippet\\Bug366003.java (at line 5)\n" + + " org.User(@Bla String a)\n" + + " ^^^\n" + + "Syntax error, insert \")\" to complete MethodDeclaration\n" + + "----------\n" + + "3. ERROR in snippet\\Bug366003.java (at line 5)\n" + + " org.User(@Bla String a)\n" + + " ^^^\n" + + "Syntax error, insert \";\" to complete MethodDeclaration\n" + + "----------\n" + + "4. ERROR in snippet\\Bug366003.java (at line 5)\n" + + " org.User(@Bla String a)\n" + + " ^^^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "5. ERROR in snippet\\Bug366003.java (at line 5)\n" + + " org.User(@Bla String a)\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "6. ERROR in snippet\\Bug366003.java (at line 5)\n" + + " org.User(@Bla String a)\n" + + " ^^^\n" + + "Bla cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in snippet\\Bug366003.java (at line 5)\n" + + " org.User(@Bla String a)\n" + + " ^\n" + + "Syntax error, insert \";\" to complete ConstructorDeclaration\n" + + "----------\n"); +} +// unfinished attempt to trigger the same CCE via catch formal parameters +public void testBug366003d() { + runNegativeTest( + new String[] { + "snippet/Bug366003.java", + "package snippet; \n" + + "public class Bug366003 {\n" + + " void foo() {\n" + + " try {\n" + + " System.out.println(\"\");\n" + + " } catch (Exeption eFirst) {\n" + + " e } catch (@Blah Exception eSecond) {\n" + + " e }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in snippet\\Bug366003.java (at line 7)\n" + + " e } catch (@Blah Exception eSecond) {\n" + + " ^\n" + + "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration\n" + + "----------\n" + + "2. ERROR in snippet\\Bug366003.java (at line 7)\n" + + " e } catch (@Blah Exception eSecond) {\n" + + " ^\n" + + "Syntax error, insert \";\" to complete BlockStatements\n" + + "----------\n" + + "3. ERROR in snippet\\Bug366003.java (at line 8)\n" + + " e }\n" + + " ^\n" + + "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration\n" + + "----------\n" + + "4. ERROR in snippet\\Bug366003.java (at line 8)\n" + + " e }\n" + + " ^\n" + + "Syntax error, insert \";\" to complete BlockStatements\n" + + "----------\n"); +} +public void testBug366003e() { + runNegativeTest( + new String[] { + "snippet/Bug366003.java", + "package snippet;\n" + + "public class Bug366003 {\n" + + " void foo(Object o1){}\n" + + " @Blah org.User(@Bla String str){}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in snippet\\Bug366003.java (at line 4)\n" + + " @Blah org.User(@Bla String str){}\n" + + " ^^^^\n" + + "Blah cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in snippet\\Bug366003.java (at line 4)\n" + + " @Blah org.User(@Bla String str){}\n" + + " ^^^^\n" + + "Syntax error on token \"User\", Identifier expected after this token\n" + + "----------\n" + + "3. ERROR in snippet\\Bug366003.java (at line 4)\n" + + " @Blah org.User(@Bla String str){}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "4. ERROR in snippet\\Bug366003.java (at line 4)\n" + + " @Blah org.User(@Bla String str){}\n" + + " ^^^\n" + + "Bla cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 +public void testBug365437a() { + Map customOptions = getCompilerOptions(); + enableAllWarningsForIrritants(customOptions, IrritantSet.NULL); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + String testFiles [] = new String[] { + "p/A.java", + "package p;\n" + + "import p1.*;\n" + + "public class A {\n" + + " @p1.PreDestroy\n" + + " private void foo1(){}\n" + + " @PreDestroy\n" + + " private void foo2(){}\n" + + " @SuppressWarnings(\"null\")\n" + + " @PostConstruct\n" + + " private void foo1a(){}\n" + + " @PostConstruct\n" + + " private void foo2a(){}\n" + + " @Deprecated" + + " private void foo3(){}" + + "}\n", + "p1/PreDestroy.java", + "package p1;\n" + + "public @interface PreDestroy{}", + "p1/PostConstruct.java", + "package p1;\n" + + "public @interface PostConstruct{}" + }; + String expectedErrorString = + "----------\n" + + "1. WARNING in p\\A.java (at line 8)\n" + + " @SuppressWarnings(\"null\")\n" + + " ^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"null\")\n" + + "----------\n" + + "2. ERROR in p\\A.java (at line 13)\n" + + " @Deprecated private void foo3(){}}\n" + + " ^^^^^^\n" + + "The method foo3() from the type A is never used locally\n" + + "----------\n"; + runNegativeTest( + true, + testFiles, + null, + customOptions, + expectedErrorString, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 +public void testBug365437b() { + if (isJRE11Plus) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "p.NonNull"); + String testFiles [] = new String[] { + "A.java", + "import javax.annotation.*;\n" + + "public class A {\n" + + " @javax.annotation.PreDestroy\n" + + " private void foo1(){}\n" + + " @PreDestroy\n" + + " private void foo2(){}\n" + + " @javax.annotation.Resource\n" + + " private void foo1a(){}\n" + + " @Resource\n" + + " @p.NonNull\n" + + " private Object foo2a(){ return new Object();}\n" + + " @javax.annotation.PostConstruct\n" + + " @Deprecated\n" + + " private void foo3(){}\n" + + " @p.NonNull\n" + + " private Object foo3a(){ return new Object();}\n" + + "}\n", + "p/NonNull.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE})\n" + + "public @interface NonNull {\n" + + "}" + }; + String expectedErrorString = + "----------\n" + + "1. ERROR in A.java (at line 16)\n" + + " private Object foo3a(){ return new Object();}\n" + + " ^^^^^^^\n" + + "The method foo3a() from the type A is never used locally\n" + + "----------\n"; + INameEnvironment save = this.javaClassLib; + try { + if (isJRE9Plus) { + List limitModules = Arrays.asList("java.se", "java.xml.ws.annotation"); + this.javaClassLib = new CustomFileSystem(limitModules); + } + runNegativeTest( + true, + testFiles, + null, + customOptions, + expectedErrorString, + isJRE9Plus ? JavacTestOptions.SKIP : JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); // javac9+ cannot access javax.annotation + } finally { + this.javaClassLib = save; + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 +// @SafeVarargs +public void testBug365437c() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + Map customOptions = getCompilerOptions(); + enableAllWarningsForIrritants(customOptions, IrritantSet.NULL); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + String testFiles [] = new String[] { + "p/A.java", + "package p;\n" + + "import p1.*;\n" + + "public class A {\n" + + " @p1.PreDestroy\n" + + " private void foo1(){}\n" + + " @PreDestroy\n" + + " private void foo2(){}\n" + + " @SuppressWarnings(\"null\")\n" + + " @PostConstruct\n" + + " private void foo1a(){}\n" + + " @PostConstruct\n" + + " private void foo2a(){}\n" + + " @SafeVarargs" + + " private final void foo3(Object... o){}" + + "}\n", + "p1/PreDestroy.java", + "package p1;\n" + + "public @interface PreDestroy{}", + "p1/PostConstruct.java", + "package p1;\n" + + "public @interface PostConstruct{}" + }; + String expectedErrorString = + "----------\n" + + "1. WARNING in p\\A.java (at line 8)\n" + + " @SuppressWarnings(\"null\")\n" + + " ^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"null\")\n" + + "----------\n" + + "2. ERROR in p\\A.java (at line 13)\n" + + " @SafeVarargs private final void foo3(Object... o){}}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The method foo3(Object...) from the type A is never used locally\n" + + "----------\n"; + runNegativeTest( + true, + testFiles, + null, + customOptions, + expectedErrorString, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 +// unused constructor +public void testBug365437d() { + Map customOptions = getCompilerOptions(); + enableAllWarningsForIrritants(customOptions, IrritantSet.NULL); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_NonNullByDefaultAnnotationName, "p.NonNullByDefault"); + this.runNegativeTest( + true, + new String[] { + "Example.java", + "class Example {\n" + + " @p.Annot\n" + + " private Example() {\n" + + " }\n" + + " public Example(int i) {\n" + + " }\n" + + "}\n" + + "class E1 {\n" + + " @Deprecated\n" + + " private E1() {}\n" + + " public E1(long l) {}\n" + + "}\n" + + "class E2 {\n" + + " @SuppressWarnings(\"null\")\n" + + " private E2() {}\n" + + " public E2(long l) {}\n" + + "}\n" + + "class E3 {\n" + + " @p.NonNullByDefault\n" + + " private E3() {}\n" + + " public E3(long l) {}\n" + + "}\n" + + "class E4 {\n" + + " @Deprecated\n" + + " @p.Annot\n" + + " private E4() {}\n" + + " public E4(long l) {}\n" + + "}\n", + "p/NonNullByDefault.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target({TYPE, METHOD,CONSTRUCTOR})\n" + + "public @interface NonNullByDefault {\n" + + "}", + "p/Annot.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE, CONSTRUCTOR})\n" + + "public @interface Annot {\n" + + "}" + }, + null, customOptions, + "----------\n" + + "1. ERROR in Example.java (at line 10)\n" + + " private E1() {}\n" + + " ^^^^\n" + + "The constructor E1() is never used locally\n" + + "----------\n" + + "2. WARNING in Example.java (at line 14)\n" + + " @SuppressWarnings(\"null\")\n" + + " ^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"null\")\n" + + "----------\n" + + "3. ERROR in Example.java (at line 15)\n" + + " private E2() {}\n" + + " ^^^^\n" + + "The constructor E2() is never used locally\n" + + "----------\n" + + "4. ERROR in Example.java (at line 20)\n" + + " private E3() {}\n" + + " ^^^^\n" + + "The constructor E3() is never used locally\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 +// unused field +public void testBug365437e() { + Map customOptions = getCompilerOptions(); + enableAllWarningsForIrritants(customOptions, IrritantSet.NULL); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "p.NonNull"); + this.runNegativeTest( + true, + new String[] { + "Example.java", + "class Example {\n" + + " @p.Annot\n" + + " private int Ex;\n" + + "}\n" + + "class E1 {\n" + + " @Deprecated\n" + + " private int E1;\n" + + "}\n" + + "class E2 {\n" + + " @SuppressWarnings(\"null\")\n" + + " private int E2;\n" + + "}\n" + + "class E3 {\n" + + " @p.NonNull\n" + + " private Object E3 = new Object();\n" + + "}\n" + + "class E4 {\n" + + " @Deprecated\n" + + " @p.Annot\n" + + " private int E4;\n" + + "}\n", + "p/NonNull.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE, FIELD})\n" + + "public @interface NonNull {\n" + + "}", + "p/Annot.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE, FIELD})\n" + + "public @interface Annot {\n" + + "}" + }, + null, customOptions, + "----------\n" + + "1. ERROR in Example.java (at line 7)\n" + + " private int E1;\n" + + " ^^\n" + + "The value of the field E1.E1 is not used\n" + + "----------\n" + + "2. WARNING in Example.java (at line 10)\n" + + " @SuppressWarnings(\"null\")\n" + + " ^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"null\")\n" + + "----------\n" + + "3. ERROR in Example.java (at line 11)\n" + + " private int E2;\n" + + " ^^\n" + + "The value of the field E2.E2 is not used\n" + + "----------\n" + + "4. ERROR in Example.java (at line 15)\n" + + " private Object E3 = new Object();\n" + + " ^^\n" + + "The value of the field E3.E3 is not used\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=365437 +// unused type +public void testBug365437f() { + Map customOptions = getCompilerOptions(); + enableAllWarningsForIrritants(customOptions, IrritantSet.NULL); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_NonNullByDefaultAnnotationName, "p.NonNullByDefault"); + this.runNegativeTest( + true, + new String[] { + "Example.java", + "class Example {\n" + + " @p.Annot\n" + + " private class Ex{}\n" + + "}\n" + + "class E1 {\n" + + " @Deprecated\n" + + " private class E11{}\n" + + "}\n" + + "class E2 {\n" + + " @SuppressWarnings(\"null\")\n" + + " private class E22{}\n" + + "}\n" + + "class E3 {\n" + + " @p.NonNullByDefault\n" + + " private class E33{}\n" + + "}\n" + + "class E4 {\n" + + " @Deprecated\n" + + " @p.Annot\n" + + " private class E44{}\n" + + "}\n", + "p/NonNullByDefault.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target({TYPE, METHOD,PARAMETER})\n" + + "public @interface NonNullByDefault {\n" + + "}", + "p/Annot.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE, CONSTRUCTOR})\n" + + "public @interface Annot {\n" + + "}" + }, + null, customOptions, + "----------\n" + + "1. ERROR in Example.java (at line 7)\n" + + " private class E11{}\n" + + " ^^^\n" + + "The type E1.E11 is never used locally\n" + + "----------\n" + + "2. WARNING in Example.java (at line 10)\n" + + " @SuppressWarnings(\"null\")\n" + + " ^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"null\")\n" + + "----------\n" + + "3. ERROR in Example.java (at line 11)\n" + + " private class E22{}\n" + + " ^^^\n" + + "The type E2.E22 is never used locally\n" + + "----------\n" + + "4. ERROR in Example.java (at line 15)\n" + + " private class E33{}\n" + + " ^^^\n" + + "The type E3.E33 is never used locally\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/376590 - Private fields with @Inject are ignored by unused field validation +// using com.google.inject.Inject +public void testBug376590a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + GOOGLE_INJECT_NAME, + GOOGLE_INJECT_CONTENT, + "Example.java", + "import com.google.inject.Inject;\n" + + "class Example {\n" + + " private @Inject Object o;\n" + + " private @Inject Example() {}\n" + // no warning on constructor + " public Example(Object o) { this.o = o; }\n" + + " private @Inject void setO(Object o) { this.o = o;}\n" + // no warning on method + "}\n" + }, + null, customOptions, + "----------\n" + + "1. ERROR in Example.java (at line 3)\n" + + " private @Inject Object o;\n" + + " ^\n" + + "The value of the field Example.o is not used\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/376590 - Private fields with @Inject are ignored by unused field validation +// using javax.inject.Inject - slight variation +public void testBug376590b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + JAVAX_INJECT_NAME, + JAVAX_INJECT_CONTENT, + "Example.java", + "class Example {\n" + + " private @javax.inject.Inject Object o;\n" + + " private Example() {} // also warn here: no @Inject\n" + + " public Example(Object o) { this.o = o; }\n" + + " private @javax.inject.Inject void setO(Object o) { this.o = o;}\n" + + "}\n" + }, + null, customOptions, + "----------\n" + + "1. ERROR in Example.java (at line 2)\n" + + " private @javax.inject.Inject Object o;\n" + + " ^\n" + + "The value of the field Example.o is not used\n" + + "----------\n" + + "2. ERROR in Example.java (at line 3)\n" + + " private Example() {} // also warn here: no @Inject\n" + + " ^^^^^^^^^\n" + + "The constructor Example() is never used locally\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/376590 - Private fields with @Inject are ignored by unused field validation +// using javax.inject.Inject, combined with standard as well as custom annotations +public void testBug376590c() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_AnnotationBasedNullAnalysis, CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_NonNullAnnotationName, "p.NonNull"); + this.runNegativeTest( + true, + new String[] { + JAVAX_INJECT_NAME, + JAVAX_INJECT_CONTENT, + "Example.java", + "import javax.inject.Inject;\n" + + "class Example {\n" + + " private @Inject @p.NonNull Object o; // do warn, annotations don't signal a read\n" + + " private @Deprecated @Inject String old; // do warn, annotations don't signal a read\n" + + " private @Inject @p.Annot Object o2;\n" + // don't warn, custom annotation could imply a read access + "}\n", + "p/NonNull.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE,FIELD})\n" + + "public @interface NonNull {\n" + + "}", + "p/Annot.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target({TYPE, METHOD,PARAMETER,LOCAL_VARIABLE, CONSTRUCTOR, FIELD})\n" + + "public @interface Annot {\n" + + "}" + }, + null, customOptions, + "----------\n" + + "1. ERROR in Example.java (at line 3)\n" + + " private @Inject @p.NonNull Object o; // do warn, annotations don't signal a read\n" + + " ^\n" + + "The value of the field Example.o is not used\n" + + "----------\n" + + "2. ERROR in Example.java (at line 4)\n" + + " private @Deprecated @Inject String old; // do warn, annotations don't signal a read\n" + + " ^^^\n" + + "The value of the field Example.old is not used\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void testBug376429a() { + this.runNegativeTest( + new String[] { + "Try.java", + "public @interface Try { \n" + + " byte[] value(); \n" + + " @Try t();\n"+ + " @Try u();\n"+ + "}" + }, + "----------\n" + + "1. ERROR in Try.java (at line 3)\n" + + " @Try t();\n" + + " ^^^^\n" + + "The annotation @Try must define the attribute value\n" + + "----------\n" + + "2. ERROR in Try.java (at line 3)\n" + + " @Try t();\n" + + " ^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "3. ERROR in Try.java (at line 3)\n" + + " @Try t();\n" + + " ^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "4. ERROR in Try.java (at line 4)\n" + + " @Try u();\n" + + " ^^^^\n" + + "The annotation @Try must define the attribute value\n" + + "----------\n" + + "5. ERROR in Try.java (at line 4)\n" + + " @Try u();\n" + + " ^^^\n" + + "Return type for the method is missing\n" + + "----------\n"); +} +public void testBug376429b() { + this.runNegativeTest( + new String[] { + "Try.java", + "public @interface Try { \n" + + " @Try t();\n"+ + " byte[] value(); \n" + + "}" + }, + "----------\n" + + "1. ERROR in Try.java (at line 2)\n" + + " @Try t();\n" + + " ^^^^\n" + + "The annotation @Try must define the attribute value\n" + + "----------\n" + + "2. ERROR in Try.java (at line 2)\n" + + " @Try t();\n" + + " ^^^\n" + + "Return type for the method is missing\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=371832 +//Unused imports should be reported even if other errors are suppressed. +public void testBug371832() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.ERROR); + String testFiles [] = new String[] { + "A.java", + "import java.util.List;\n"+ + "@SuppressWarnings(\"serial\")\n" + + "public class A implements java.io.Serializable {\n" + + " void foo() { \n" + + " }\n"+ + "}\n" + }; + String expectedErrorString = + "----------\n" + + "1. ERROR in A.java (at line 1)\n" + + " import java.util.List;\n" + + " ^^^^^^^^^^^^^^\n" + + "The import java.util.List is never used\n" + + "----------\n"; + runNegativeTest( + true, + testFiles, + null, + customOptions, + expectedErrorString, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/384663 +// Package Based Annotation Compilation Error in JDT 3.8/4.2 (works in 3.7.2) +public void testBug384663() { + String[] testFiles = { + "annotations/test/IExtendsInterface.java", + "package annotations.test;\n" + + "public interface IExtendsInterface extends Interface {}\n", + + "annotations/test/Interface.java", + "package annotations.test;\n" + + "public interface Interface {}\n", + + "annotations/test/package-info.java", + "@AnnotationDefinition(\"Test1\") \n" + + "package annotations.test;\n" + + "import annotations.AnnotationDefinition;", + + "annotations/AnnotationDefinition.java", + "package annotations;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Target(ElementType.PACKAGE)\n" + + "public @interface AnnotationDefinition {\n" + + " String value();\n" + + "}", + }; + runConformTest(testFiles); +} + +// Bug 386356 - Type mismatch error with annotations and generics +// test case from comment 9 +public void _testBug386356_1() { + runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import javax.xml.bind.annotation.adapters.XmlAdapter;\n" + + "public abstract class X extends XmlAdapter {\n" + + "}", + + "p/package-info.java", + "@XmlJavaTypeAdapters({ @XmlJavaTypeAdapter(value = X.class, type = X.class) })\n" + + "package p;\n" + + "import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; \n" + + "import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;" + + }); +} + +// Bug 386356 - Type mismatch error with annotations and generics +// test case from comment 6 +public void testBug386356_2() { + if (isJRE11Plus) + return; + INameEnvironment save = this.javaClassLib; + try { + if (isJRE9Plus) { + List limitModules = Arrays.asList("java.se", "java.xml.bind"); + this.javaClassLib = new CustomFileSystem(limitModules); + } + runConformTest( + new String[] { + "com/ermahgerd/Ermahgerd.java", + "package com.ermahgerd;\n" + + "\n" + + "public class Ermahgerd {\n" + + "}", + + "com/ermahgerd/package-info.java", + "@XmlJavaTypeAdapters({ @XmlJavaTypeAdapter(value = ErmahgerdXmlAdapter.class, type = Ermahgerd.class) })\n" + + "package com.ermahgerd;\n" + + "import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;\n" + + "import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;", + + "com/ermahgerd/ErmahgerdXmlAdapter.java", + "package com.ermahgerd;\n" + + "\n" + + "import javax.xml.bind.annotation.adapters.XmlAdapter;\n" + + "\n" + + "public class ErmahgerdXmlAdapter extends XmlAdapter {\n" + + "\n" + + " @Override\n" + + " public String marshal(Ermahgerd arg0) throws Exception {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public Ermahgerd unmarshal(String arg0) throws Exception {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "}" + }, + isJRE9Plus ? JavacTestOptions.SKIP : JavacTestOptions.DEFAULT); // javac9+ cannot access javax.xml.bind + } finally { + this.javaClassLib = save; + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=398657 +public void test398657() throws Exception { + if (this.complianceLevel != ClassFileConstants.JDK1_5) { + return; + } + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + this.runConformTest( + new String[] { + "p/Annot.java", + "package p;\n" + + "public @interface Annot {\n" + + " static public enum E { A }\n" + + " E getEnum();\n" + + "}", + "X.java", + "import static p.Annot.E.*;\n" + + "import p.Annot;" + + "@Annot(getEnum=A)\n" + + "public class X {}" + }, + "", + null, + true, + null, + options, + null, + true); + + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #22 p/Annot$E, outer class info: #24 p/Annot\n" + + " inner name: #26 E, accessflags: 16409 public static final]\n"; + + checkDisassembledClassFile(OUTPUT_DIR + File.separator +"X.class", "X", expectedOutput, ClassFileBytesDisassembler.DETAILED); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=398657 +public void test398657_2() throws Exception { + if (this.complianceLevel != ClassFileConstants.JDK1_5) { + return; + } + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + this.runConformTest( + new String[] { + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " static public @interface Annot {\n" + + " int id();\n" + + " }\n" + + "}", + "X.java", + "import p.Y.Annot;\n" + + "@Annot(id=4)\n" + + "public class X {}" + }, + "", + null, + true, + null, + options, + null, + true); + + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #21 p/Y$Annot, outer class info: #23 p/Y\n" + + " inner name: #25 Annot, accessflags: 9737 public abstract static]\n"; + + checkDisassembledClassFile(OUTPUT_DIR + File.separator +"X.class", "X", expectedOutput, ClassFileBytesDisassembler.DETAILED); +} +// check invalid and annotations on package +public void test384567() { + this.runNegativeTest( + new String[] { + "xy/X.java", + "public final synchronized @Foo private package xy;\n" + + "class X {\n" + + "}\n" + + "\n" + + "@interface Foo {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in xy\\X.java (at line 1)\n" + + " public final synchronized @Foo private package xy;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, modifiers are not allowed here\n" + + "----------\n" + + "2. ERROR in xy\\X.java (at line 1)\n" + + " public final synchronized @Foo private package xy;\n" + + " ^^^^\n" + + "Package annotations must be in file package-info.java\n" + + "----------\n"); +} +//check invalid modifiers on package +public void test384567_2() { + this.runNegativeTest( + new String[] { + "xy/X.java", + "public final synchronized private package xy;\n" + + "class X {\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in xy\\X.java (at line 1)\n" + + " public final synchronized private package xy;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, modifiers are not allowed here\n" + + "----------\n"); +} +// Bug 416107 - Incomplete error message for member interface and annotation +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=416107 +public void test416107a() { + if (this.complianceLevel < ClassFileConstants.JDK16) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " @interface Bar {\n" + + " public String bar = \"BUG\";\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @interface Bar {\n" + + " ^^^\n" + + "The member annotation Bar can only be defined inside a top-level class or interface or in a static context\n" + + "----------\n"); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " @interface Bar {\n" + + " public String bar = \"BUG\";\n" + + " }\n" + + " }\n" + + "}", + }, + ""); + + } +} +public void test416107b() { + if (this.complianceLevel < ClassFileConstants.JDK16) { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " interface Bar {\n" + + " public String bar = \"BUG\";\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " interface Bar {\n" + + " ^^^\n" + + "The member interface Bar can only be defined inside a top-level class or interface or in a static context\n" + + "----------\n"); + } else { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " interface Bar {\n" + + " public String bar = \"BUG\";\n" + + " }\n" + + " }\n" + + "}", + }, + ""); + + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427367 +public void test427367() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + this.runNegativeTest( + new String[] { + "X.java", + "@interface Annot1 {\n" + + " Thread.State value() default Thread.State.NEW;\n" + + " int value2() default 1;\n" + + "}\n" + + "@interface Annot2 {\n" + + " Thread.State value() default Thread.State.NEW;\n" + + "}\n" + + "@Annot1(value = XXThread.State.BLOCKED, value2 = 42)\n" + + "@Annot2(value = XYThread.State.BLOCKED)\n" + + "public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " @Annot1(value = XXThread.State.BLOCKED, value2 = 42)\n" + + " ^^^^^^^^\n" + + "XXThread cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " @Annot2(value = XYThread.State.BLOCKED)\n" + + " ^^^^^^^^\n" + + "XYThread cannot be resolved to a variable\n" + + "----------\n", + null, + true, + null, + true, // generate output + false, + false); + + String expectedOutput = "@Annot1@Annot2\n" + + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 3, Locals: 1\n" + + " public X();\n" + + " 0 new java.lang.Error [8]\n" + + " 3 dup\n" + + " 4 ldc [10]\n" + + " 6 invokespecial java.lang.Error(java.lang.String) [12]\n" + + " 9 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + "\n" + + "}"; + try { + checkDisassembledClassFile(OUTPUT_DIR + File.separator +"X.class", "X", expectedOutput, ClassFileBytesDisassembler.DETAILED); + } catch(org.eclipse.jdt.core.util.ClassFormatException cfe) { + fail("Error reading classfile"); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=376977 +public void test376977() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "import p.Outer;\n" + + "@Outer(nest= {@Nested()})\n" + + "public class X {}", + "p/Outer.java", + "package p;\n" + + "public @interface Outer {\n" + + " Nested[] nest();" + + "}", + "p/Nested.java", + "package p;\n" + + "public @interface Nested {\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Outer(nest= {@Nested()})\n" + + " ^^^^^^\n" + + "Nested cannot be resolved to a type\n" + + "----------\n", + null, + true, + null, + false, + false, + false); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=438437 - [1.8][compiler] Annotations +// on enum constants interpreted only as type annotations if the annotation type +// specifies ElementType.TYPE_USE in @Target along with others. +public void test438437() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target({ElementType.TYPE_USE, ElementType.FIELD})\n" + + "@interface TUF {} \n" + + "@Target({ElementType.FIELD})\n" + + "@interface F {} \n" + + "@Target({ElementType.TYPE_USE})\n" + + "@interface TU1 {} \n" + + "@Target({ElementType.LOCAL_VARIABLE})\n" + + "@interface LV {} \n" + + "@Target({ElementType.TYPE_USE})\n" + + "@interface TU2 {} \n" + + "class Y {}\n" + + "public enum X {\n" + + " @TUF E1,\n" + // Error without the fix. + " @F E2,\n" + + " @TU1 E3,\n" + // Error is reported as no type exists for the Enum. + " @LV E4,\n" + + " @TUF @TU1 @F E5,\n" + + " @TUF @TU1 @F @TU2 E6;\n" + + " @TUF Y y11;\n" + + " @F Y y12;\n" + + " @TU1 Y y13;\n" + // No error reported as type exists. + " @LV Y y14;\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " @TU1 E3,\n" + + " ^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " @LV E4,\n" + + " ^^^\n" + + "The annotation @LV is disallowed for this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " @TUF @TU1 @F E5,\n" + + " ^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " @TUF @TU1 @F @TU2 E6;\n" + + " ^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "5. ERROR in X.java (at line 20)\n" + + " @TUF @TU1 @F @TU2 E6;\n" + + " ^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "6. ERROR in X.java (at line 24)\n" + + " @LV Y y14;\n" + + " ^^^\n" + + "The annotation @LV is disallowed for this location\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=434556, Broken class file generated for incorrect annotation usage +public void test434556() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + this.runNegativeTest( + new String[] { + "A.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " int i();\n" + + "}\n" + + "public class A {\n" + + " @C(b={},i=42)\n" + + " public void xxx() {}\n" + + " public static void main(String []argv) throws Exception {\n" + + " System.out.println(A.class.getDeclaredMethod(\"xxx\").getAnnotations()[0]); \n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 8)\n" + + " @C(b={},i=42)\n" + + " ^\n" + + "The attribute b is undefined for the annotation type C\n" + + "----------\n", + null, + true, + null, + true, // generate output + false, + false); + + String expectedOutput = "@C(i=(int) 42)\n" + + " public void xxx();\n" + + " 0 new java.lang.Error [20]\n" + + " 3 dup\n" + + " 4 ldc [22]\n" + + " 6 invokespecial java.lang.Error(java.lang.String) [24]\n" + + " 9 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: A\n" + + " \n"; + try { + checkDisassembledClassFile(OUTPUT_DIR + File.separator +"A.class", "A", expectedOutput, ClassFileBytesDisassembler.DETAILED); + } catch(org.eclipse.jdt.core.util.ClassFormatException cfe) { + fail("Error reading classfile"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433747, [compiler] TYPE Annotation allowed in package-info instead of only PACKAGE +public void test433747() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + String[] src = new String[] { + "p/package-info.java", + "@PackageAnnot(\"p123456\")\n" + + "package p;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE)\n" + + "@interface PackageAnnot {\n" + + " String value();\n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_6) { + this.runConformTest(src, ""); + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p/package-info.class", "", "p123456"); + } else { + this.runNegativeTest( + src, + "----------\n" + + "1. ERROR in p\\package-info.java (at line 1)\n" + + " @PackageAnnot(\"p123456\")\n" + + " ^^^^^^^^^^^^^\n" + + "The annotation @PackageAnnot is disallowed for this location\n" + + "----------\n", + null, + true, + null, + true, // generate output + false, + false); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=456960 - Broken classfile generated for incorrect annotation usage - case 2 +public void test456960() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + this.runNegativeTest( + new String[] { + "X.java", + "@Bar(String)\n" + + "public class X {\n" + + "}", + "Bar.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Bar {\n" + + " Class[] value();\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Bar(String)\n" + + " ^^^^^^\n" + + "String cannot be resolved to a variable\n" + + "----------\n", + null, + true, + null, + true, // generate output + false, + false); + + String expectedOutput = + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 3, Locals: 1\n" + + " public X();\n" + + " 0 new java.lang.Error [8]\n" + + " 3 dup\n" + + " 4 ldc [10]\n" + + " 6 invokespecial java.lang.Error(java.lang.String) [12]\n" + + " 9 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + "}"; + try { + checkDisassembledClassFile(OUTPUT_DIR + File.separator +"X.class", "X", expectedOutput, ClassFileBytesDisassembler.DETAILED); + } catch(org.eclipse.jdt.core.util.ClassFormatException cfe) { + fail("Error reading classfile"); + } + +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=449330 - [1.6]Eclipse compiler doesn't compile annotations in class files +public void test449330() throws Exception { + String[] testFiles = new String[] { + "p/X.java", + "package p;\n" + + "@java.lang.annotation.Target(value={java.lang.annotation.ElementType.TYPE})\n" + + "@interface X { public java.lang.String name(); }\n", + "p/package-info.java", + "@X(name=\"HELLO\")\n" + + "package p;\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_6) { + this.runConformTest(testFiles); + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p/package-info.class", "", "HELLO"); + } else { + this.runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in p\\package-info.java (at line 1)\n" + + " @X(name=\"HELLO\")\n" + + " ^^\n" + + "The annotation @X is disallowed for this location\n" + + "----------\n"); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=449330 - [1.6]Eclipse compiler doesn't compile annotations in class files +//Retention Policy set to RUNTIME +public void test449330a() throws Exception { + String[] testFiles = new String[] { + "p/X.java", + "package p;\n" + + "@java.lang.annotation.Target(value={java.lang.annotation.ElementType.TYPE})\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" + + "@interface X { public java.lang.String name(); }\n", + "p/package-info.java", + "@X(name=\"HELLO\")\n" + + "package p;\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_6) { + this.runConformTest(testFiles, ""); + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p/package-info.class", "", "HELLO"); + } else { + this.runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in p\\package-info.java (at line 1)\n" + + " @X(name=\"HELLO\")\n" + + " ^^\n" + + "The annotation @X is disallowed for this location\n" + + "----------\n"); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=449330 - [1.6]Eclipse compiler doesn't compile annotations in class files +//Annotation target not set +public void test449330b() throws Exception { + String[] testFiles = new String[] { + "p/X.java", + "package p;\n" + + "@interface X { public java.lang.String name(); }\n", + "p/package-info.java", + "@X(name=\"HELLO\")\n" + + "package p;\n" + }; + this.runConformTest(testFiles, ""); + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p/package-info.class", "", "HELLO"); +} +//https://bugs.eclipse.org/386692 +public void testBug386692() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + SPRINGFRAMEWORK_AUTOWIRED_NAME, + SPRINGFRAMEWORK_AUTOWIRED_CONTENT, + "Example.java", + "class Example {\n" + + " private @org.springframework.beans.factory.annotation.Autowired Object o;\n" + + " private Example() {}\n" + + " public Example(Object o) { this.o = o; }\n" + + " private @org.springframework.beans.factory.annotation.Autowired void setO(Object o) { this.o = o;}\n" + + "}\n" + }, + null, customOptions, + "----------\n" + + "1. ERROR in Example.java (at line 2)\n" + + " private @org.springframework.beans.factory.annotation.Autowired Object o;\n" + + " ^\n" + + "The value of the field Example.o is not used\n" + + "----------\n" + + "2. ERROR in Example.java (at line 3)\n" + + " private Example() {}\n" + + " ^^^^^^^^^\n" + + "The constructor Example() is never used locally\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=464977 +public void testBug464977() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_6 || this.complianceLevel > ClassFileConstants.JDK1_8) { + return; // Enough to run in 3 levels rather! + } + boolean apt = this.enableAPT; + String source = "@Deprecated\n" + + "public class DeprecatedClass {\n" + + "}"; + String version = ""; + if (this.complianceLevel == ClassFileConstants.JDK1_8) { + version = "1.8 : 52.0"; + } else if (this.complianceLevel == ClassFileConstants.JDK1_7) { + version = "1.7 : 51.0"; + } else if (this.complianceLevel == ClassFileConstants.JDK1_6) { + version = "1.6 : 50.0"; + } + String expectedOutput = "// Compiled from DeprecatedClass.java (version " + version + ", super bit, deprecated)\n" + + "@Deprecated\n" + + "public class DeprecatedClass {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public DeprecatedClass();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: DeprecatedClass\n" + + "\n" + + "}"; + try { + this.enableAPT = true; + checkClassFile("DeprecatedClass", source, expectedOutput, ClassFileBytesDisassembler.DETAILED | ClassFileBytesDisassembler.COMPACT); + } finally { + this.enableAPT = apt; + } +} +public void testBug469584() { + runNegativeTest( + new String[] { + "CCETest.java", + "import java.lang.annotation.*;\n" + + "\n" + + "@Retention({RetentionPolicy.CLASS, RetentionPolicy.RUNTIME})\n" + + "public @interface CCETest {\n" + + "\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in CCETest.java (at line 3)\n" + + " @Retention({RetentionPolicy.CLASS, RetentionPolicy.RUNTIME})\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from RetentionPolicy[] to RetentionPolicy\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=472178 +public void test472178() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; // Enough to run in 3 levels rather! + } + String source = + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "import java.util.ArrayList;\n" + + "import java.util.Iterator;\n" + + " \n" + + "/**\n" + + " * @author gglab\n" + + " */\n" + + "public class Test extends ArrayList {\n" + + " public void iterateRemove()\n" + + " {\n" + + " for (Iterator iter = this.iterator(); iter.hasNext();) {\n" + + " Object key = iter.next();\n" + + " @Flowannotation\n" + + " Foo<@Flowannotation String> f = new Foo();\n" + + " @Flowannotation long l = (@Flowannotation long)f.getI(); // this line causes parse error\n" + + " iter.remove();\n" + + " }\n" + + " }\n" + + " \n" + + " @Flowannotation\n" + + " class Foo<@Flowannotation T>\n" + + " {\n" + + " @Flowannotation\n" + + " public int getI()\n" + + " {\n" + + " return 3;\n" + + " }\n" + + " }\n" + + " \n" + + " @Target({ ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.METHOD, ElementType.LOCAL_VARIABLE, ElementType.TYPE, ElementType.FIELD,\n" + + " ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})\n" + + " @Retention(RetentionPolicy.RUNTIME)\n" + + " @interface Flowannotation {}\n" + + " public static void main(String[] args) {}\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 3, Locals: 6\n" + + " public void iterateRemove();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual Test.iterator() : Iterator [17]\n" + + " 4 astore_1 [iter]\n" + + " 5 goto 37\n" + + " 8 aload_1 [iter]\n" + + " 9 invokeinterface Iterator.next() : Object [21] [nargs: 1]\n" + + " 14 astore_2 [key]\n" + + " 15 new Test$Foo [27]\n" + + " 18 dup\n" + + " 19 aload_0 [this]\n" + + " 20 invokespecial Test$Foo(Test) [29]\n" + + " 23 astore_3 [f]\n" + + " 24 aload_3 [f]\n" + + " 25 invokevirtual Test$Foo.getI() : int [32]\n" + + " 28 i2l\n" + + " 29 lstore 4 [l]\n" + + " 31 aload_1 [iter]\n" + + " 32 invokeinterface Iterator.remove() : void [36] [nargs: 1]\n" + + " 37 aload_1 [iter]\n" + + " 38 invokeinterface Iterator.hasNext() : boolean [39] [nargs: 1]\n" + + " 43 ifne 8\n" + + " 46 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 8, line: 15]\n" + + " [pc: 15, line: 17]\n" + + " [pc: 24, line: 18]\n" + + " [pc: 31, line: 19]\n" + + " [pc: 37, line: 14]\n" + + " [pc: 46, line: 21]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 47] local: this index: 0 type: Test\n" + + " [pc: 5, pc: 46] local: iter index: 1 type: Iterator\n" + + " [pc: 15, pc: 37] local: key index: 2 type: Object\n" + + " [pc: 24, pc: 37] local: f index: 3 type: Foo\n" + + " [pc: 31, pc: 37] local: l index: 4 type: long\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 47] local: this index: 0 type: Test\n" + + " [pc: 5, pc: 46] local: iter index: 1 type: Iterator\n" + + " [pc: 24, pc: 37] local: f index: 3 type: String>\n" + + " Stack map table: number of frames 2\n" + + " [pc: 8, append: {Iterator}]\n" + + " [pc: 37, same]\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #55 @Flowannotation(\n" + + " target type = 0x47 CAST\n" + + " offset = 24\n" + + " type argument index = 0\n" + + " )\n" + + " #55 @Flowannotation(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 24, pc: 37] index: 3\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " #55 @Flowannotation(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 24, pc: 37] index: 3\n" + + " location = [INNER_TYPE, TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #55 @Flowannotation(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 31, pc: 37] index: 4\n" + + " )\n"; + checkClassFile("Test", source, expectedOutput, ClassFileBytesDisassembler.DETAILED | ClassFileBytesDisassembler.COMPACT); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=470665 +public void testBug470665() throws Exception { + if (this.complianceLevel <= ClassFileConstants.JDK1_7) { + return; // Enough to run in the last two levels! + } + boolean apt = this.enableAPT; + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in A.java (at line 10)\n" + + " };\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in A.java (at line 10)\n" + + " };\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n" + + "----------\n" + + "1. WARNING in B.java (at line 12)\n" + + " X x = new X();\n" + + " ^^^^^^^\n" + + "Access to enclosing constructor B.X() is emulated by a synthetic accessor method\n" + + "----------\n"; + String[] sources = new String[] { + "A.java", + "public final class A {\n" + + " String myString;\n" + + " public interface B {\n" + + " void test();\n" + + " }\n" + + " private final B b = new B() {\n" + + " @Override\n" + + " public void test() {}\n" + + " }\n" + + "};\n" + + "}", + "B.java", + "public class B {\n" + + " private static class X {\n" + + " static final Object instance1;\n" + + " static {\n" + + " try {\n" + + " instance1 = new Object();\n" + + " } catch (Throwable e) {\n" + + " throw new AssertionError(e);\n" + + " }\n" + + " }\n" + + " }\n" + + " X x = new X();\n" + + " Object o = X.instance1;\n" + + "}" + }; + try { + this.enableAPT = true; + runNegativeTest(sources, errMessage); + } finally { + this.enableAPT = apt; + } +} +public void testBug506888a() throws Exception { + if (this.complianceLevel <= ClassFileConstants.JDK1_5) { + return; + } + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings({\"incomplete-switch\"})\n" + + " void foo() {\n" + + " }\n" + + "} \n", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. INFO in X.java (at line 3)\n" + + " @SuppressWarnings({\"incomplete-switch\"})\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "At least one of the problems in category \'incomplete-switch\' is not analysed due to a compiler option being ignored\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +public void testBug506888b() throws Exception { + if (this.complianceLevel <= ClassFileConstants.JDK1_5) { + return; + } + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings({\"incomplete-switch\"})\n" + + " void foo(Color c) {\n" + + " switch(c) {\n" + + " }\n" + + " }\n" + + " enum Color { BLUE, RED; } \n" + + "} \n", + }, + options); +} +public void testBug506888c() throws Exception { + if (this.complianceLevel <= ClassFileConstants.JDK1_5) { + return; + } + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.WARNING); + runner.customOptions.put(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, CompilerOptions.WARNING); + runner.customOptions.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.WARNING); + runner.customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings({\"incomplete-switch\", \"unchecked\"})\n" + + " void foo(Color c) {\n" + + " switch(c) {\n" + + " }\n" + + " }\n" + + " enum Color { BLUE, RED; } \n" + + "} \n", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " @SuppressWarnings({\"incomplete-switch\", \"unchecked\"})\n" + + " ^^^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"unchecked\")\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +public void testBug506888d() throws Exception { + if (this.complianceLevel <= ClassFileConstants.JDK1_5) { + return; + } + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings({\"incomplete-switch\"})\n" + + " void foo() {\n" + + " }\n" + + "} \n", + }, + "", + null, true, options); +} +public void testBug506888e() throws Exception { + if (this.complianceLevel <= ClassFileConstants.JDK1_5) { + return; + } + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedLabel, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings({\"unused\"})\n" + + " void foo() {}\n" + + "} \n", + }, + "", + null, true, options); +} +public void testBug506888f() throws Exception { + + class MyCompilerRequestor implements ICompilerRequestor { + String[] problemArguments = null; + + @Override + public void acceptResult(CompilationResult result) { + for (CategorizedProblem problem : result.getAllProblems()) { + String[] arguments = problem.getArguments(); + if (arguments != null && arguments.length > 0) { + this.problemArguments = arguments; + return; + } + } + } + } + + if (this.complianceLevel <= ClassFileConstants.JDK1_5) { + return; + } + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownException, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + MyCompilerRequestor requestor = new MyCompilerRequestor(); + runTest(new String[] { + "X.java", + "public class X {\n" + + " \n" + + " @SuppressWarnings({\"unused\"})\n" + + " void foo() {\n" + + " }\n" + + "} \n", + }, + false, + "----------\n" + + "1. INFO in X.java (at line 3)\n" + + " @SuppressWarnings({\"unused\"})\n" + + " ^^^^^^^^\n" + + "At least one of the problems in category \'unused\' is not analysed due to a compiler option being ignored\n" + + "----------\n", + "" /*expectedOutputString */, + "" /* expectedErrorString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + options, + new Requestor(true, requestor, false, true), + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + assertNotNull(requestor.problemArguments); + assertEquals(1, requestor.problemArguments.length); + assertEquals(JavaCore.COMPILER_PB_UNUSED_PARAMETER, requestor.problemArguments[0]); +} +public void testBug537593_001() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + class MyCompilerRequestor implements ICompilerRequestor { + String[] problemArguments = null; + + @Override + public void acceptResult(CompilationResult result) { + for (CategorizedProblem problem : result.getAllProblems()) { + String[] arguments = problem.getArguments(); + if (arguments != null && arguments.length > 0) { + this.problemArguments = arguments; + return; + } + } + } + } + + if (this.complianceLevel <= ClassFileConstants.JDK1_5) { + return; + } + String[] files = new String[] { + "X.java", + "\n" + + "public class X {\n" + + "\n" + + " protected void bar(Z z) {\n" + + " System.out.println(z.toString());\n" + + " }\n" + + "\n" + + " public void foo() {\n" + + " bar(() -> {\n" + + " foo2(new I() {\n" + + " @SuppressWarnings({\"unused\"})\n" + + " public void bar2() {}\n" + + " });\n" + + " });\n" + + " }\n" + + " public static void main(String[] args) {}\n" + + "\n" + + " public Z foo2(I i) {\n" + + " return i == null ? null : null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface Z {\n" + + " void apply();\n" + + "}\n" + + "\n" + + "interface I {}\n" + + "\n", + }; + + Map options = getCompilerOptions(); + Object[] opts = { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException, + CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionIncludeDocCommentReference, + CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionWhenOverriding, + CompilerOptions.OPTION_ReportUnusedExceptionParameter, + CompilerOptions.OPTION_ReportUnusedImport, + CompilerOptions.OPTION_ReportUnusedLabel, + CompilerOptions.OPTION_ReportUnusedLocal, + CompilerOptions.OPTION_ReportUnusedObjectAllocation, + CompilerOptions.OPTION_ReportUnusedParameter, + CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, + CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, + CompilerOptions.OPTION_ReportUnusedPrivateMember, + CompilerOptions.OPTION_ReportUnusedTypeArgumentsForMethodInvocation, + CompilerOptions.OPTION_ReportUnusedTypeParameter, + CompilerOptions.OPTION_ReportUnusedWarningToken, + CompilerOptions.OPTION_ReportRedundantSuperinterface, + CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, + }; + for (Object option : opts) + options.put(option, CompilerOptions.WARNING); + MyCompilerRequestor requestor = new MyCompilerRequestor(); + runTest(files, + false, + "", + "" /*expectedOutputString */, + "" /* expectedErrorString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + options, + new Requestor(true, requestor, false, true), + JavacTestOptions.DEFAULT); + assertNull(requestor.problemArguments); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=542520 - [JUnit 5] Warning The method xxx from the type X +// is never used locally is shown when using MethodSource - common case +public void testBug542520a() throws Exception { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + JUNIT_METHODSOURCE_NAME, + JUNIT_METHODSOURCE_CONTENT, + "ExampleTest.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import org.junit.jupiter.params.provider.MethodSource;\n" + + "public class ExampleTest {\n" + + "\n" + + " @MethodSource(\"getIntegers\")\n" + + " void testIntegers(Integer integer) {}\n" + + " \n" + + " private static List getIntegers() {\n" + + " return Arrays.asList(0, 5, 1);\n" + + " }\n" + + "}\n", + }; + runner.runConformTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=542520 - [JUnit 5] Warning The method xxx from the type X +// is never used locally is shown when using MethodSource - variation with fully qualified annotation +public void testBug542520b() throws Exception { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + JUNIT_METHODSOURCE_NAME, + JUNIT_METHODSOURCE_CONTENT, + "ExampleTest.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class ExampleTest {\n" + + "\n" + + " @org.junit.jupiter.params.provider.MethodSource(\"getIntegers\")\n" + + " void testIntegers(Integer integer) {}\n" + + " \n" + + " private static List getIntegers() {\n" + + " return Arrays.asList(0, 5, 1);\n" + + " }\n" + + "}\n", + }; + runner.runConformTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=542520 - [JUnit 5] Warning The method xxx from the type X +// is never used locally is shown when using MethodSource - marker annotation +public void testBug542520c() throws Exception { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + JUNIT_METHODSOURCE_NAME, + JUNIT_METHODSOURCE_CONTENT, + "ExampleTest.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import org.junit.jupiter.params.provider.MethodSource;\n" + + "public class ExampleTest {\n" + + "\n" + + " @MethodSource\n" + + " void testIntegers(Integer integer) {}\n" + + " \n" + + " private static List testIntegers() {\n" + + " return Arrays.asList(0, 5, 1);\n" + + " }\n" + + "}\n", + }; + runner.runConformTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=542520 - [JUnit 5] Warning The method xxx from the type X +// is never used locally is shown when using MethodSource - missing no-args method source +public void testBug542520d() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + JUNIT_METHODSOURCE_NAME, + JUNIT_METHODSOURCE_CONTENT, + "ExampleTest.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import org.junit.jupiter.params.provider.MethodSource;\n" + + "public class ExampleTest {\n" + + "\n" + + " @MethodSource(\"getIntegers\")\n" + + " void testIntegers(Integer integer) {}\n" + + " \n" + + " private static List getIntegers(int i) {\n" + + " return Arrays.asList(0, 5, 1);\n" + + " }\n" + + "}\n", + }, + null, customOptions, + "----------\n" + + "1. ERROR in ExampleTest.java (at line 9)\n" + + " private static List getIntegers(int i) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The method getIntegers(int) from the type ExampleTest is never used locally\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=546084 - Using Junit 5s MethodSource leads to +// ClassCastException - string concatenation, i.e. BinaryExpression in @MethodSource annotation +public void testBug546084a() throws Exception { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + JUNIT_METHODSOURCE_NAME, + JUNIT_METHODSOURCE_CONTENT, + "ExampleTest.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import org.junit.jupiter.params.provider.MethodSource;\n" + + "public class ExampleTest {\n" + + "\n" + + " private final String TEST_METHOD_PREFIX = \"get\";\n" + + " @MethodSource(TEST_METHOD_PREFIX + \"Integers\")\n" + + " void testIntegers(Integer integer) {}\n" + + " \n" + + " private static List getIntegers() {\n" + + " return Arrays.asList(0, 5, 1);\n" + + " }\n" + + "}\n", + }; + runner.runConformTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=546084 - Using Junit 5s MethodSource leads to +// ClassCastException - non string value, e.g. ClassLiteralAccess in @MethodSource annotation +public void testBug546084b() throws Exception { + this.runNegativeTest( + new String[] { + JUNIT_METHODSOURCE_NAME, + JUNIT_METHODSOURCE_CONTENT, + "ExampleTest.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import org.junit.jupiter.params.provider.MethodSource;\n" + + "public class ExampleTest {\n" + + "\n" + + " @MethodSource(Object.class)\n" + + " void testIntegers(Integer integer) {}\n" + + " \n" + + " private static List getIntegers(int i) {\n" + + " return Arrays.asList(0, 5, 1);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in ExampleTest.java (at line 6)\n" + + " @MethodSource(Object.class)\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to String[]\n" + + "----------\n" + + "2. WARNING in ExampleTest.java (at line 9)\n" + + " private static List getIntegers(int i) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The method getIntegers(int) from the type ExampleTest is never used locally\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=546084 - Using Junit 5s MethodSource leads to +//ClassCastException - array of string values, e.g. ArrayInitializer in @MethodSource annotation +public void testBug546084c() throws Exception { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + JUNIT_METHODSOURCE_NAME, + JUNIT_METHODSOURCE_CONTENT, + "ExampleTest.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import org.junit.jupiter.params.provider.MethodSource;\n" + + "public class ExampleTest {\n" + + "\n" + + " @MethodSource({ \"getIntegers\" })\n" + + " void testIntegers(Integer integer) {}\n" + + " \n" + + " private static List getIntegers() {\n" + + " return Arrays.asList(0, 5, 1);\n" + + " }\n" + + "}\n", + }; + runner.runConformTest(); +} +public void testBug490698_comment16() { + runConformTest( + new String[] { + "foo/bar/AnnotationError.java", + "package foo.bar;\n" + + "\n" + + "import static java.lang.annotation.ElementType.FIELD;\n" + + "import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" + + "\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import java.util.function.Predicate;\n" + + "\n" + + "public class AnnotationError {\n" + + "\n" + + " public enum P {\n" + + " AAA\n" + + " }\n" + + "\n" + + " @Target(FIELD)\n" + + " @Retention(RUNTIME)\n" + + " public @interface A {\n" + + " P value();\n" + + " }\n" + + "\n" + + " @Target(FIELD)\n" + + " @Retention(RUNTIME)\n" + + " public @interface FF {\n" + + " }\n" + + "\n" + + " public static class Bool extends AnnotationError {\n" + + " }\n" + + "\n" + + " @A(P.AAA)\n" + + " @FF\n" + + " public static final AnnotationError.Bool FOO = new AnnotationError.Bool();\n" + + "}\n" + }); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest_9.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest_9.java new file mode 100644 index 0000000000..56cf9d3d57 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest_9.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + + +import junit.framework.Test; + +public class AnnotationTest_9 extends AbstractComparableTest { + + public AnnotationTest_9(String name) { + super(name); + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); + } + + public static Class testClass() { + return AnnotationTest_9.class; + } + + public void testBug532913() throws Exception { + runConformTest( + new String[] { + "p/A.java", + "package p;\n" + + "@java.lang.annotation.Target({\n" + + " java.lang.annotation.ElementType.TYPE, java.lang.annotation.ElementType.METHOD})\n" + + "@Deprecated\n" + + "public @interface A {}\n", + },""); + runConformTest( + new String[] { + "X.java", + "import p.A;\n" + + "class X {\n" + + " @A void foo() {}\n" + + "}\n", + },"", null, false, null); + } + public void testBug521054a() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X {\n" + + " String value(X this);\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " String value(X this);\n" + + " ^^^^^^^^^^^^^\n" + + "Annotation attributes cannot have parameters\n" + + "----------\n", + null, true); + } + public void testBug521054b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "@java.lang.annotation.Repeatable(Container.class)\n" + + "public @interface X {\n" + + " String value();\n" + + "}\n" + + "@interface Container {\n" + + " X[] value(Container this);\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X[] value(Container this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Annotation attributes cannot have parameters\n" + + "----------\n", + null, true); + } + public void testBug521054c() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "@java.lang.annotation.Repeatable(Container.class)\n" + + "public @interface X {\n" + + " String value(X this, int i);\n" + + "}\n" + + "@interface Container {\n" + + " X[] value();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " String value(X this, int i);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Annotation attributes cannot have parameters\n" + + "----------\n", + null, true); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ArrayTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ArrayTest.java new file mode 100644 index 0000000000..383757b34a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ArrayTest.java @@ -0,0 +1,599 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for Bug 331872 - [compiler] NPE in Scope.createArrayType when attempting qualified access from type parameter + * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for + * Bug 409247 - [1.8][compiler] Verify error with code allocating multidimensional array + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class ArrayTest extends AbstractRegressionTest { + + static { +// TESTS_NUMBERS = new int[] { 18 }; + } + public ArrayTest(String name) { + super(name); + } + + public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); + } + + public static Class testClass() { + return ArrayTest.class; + } + +public void test001() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " int[] x= new int[] {,};\n" + + "}\n", + }); +} + +/** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=28615 + */ +public void test002() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public static void main(String[] args) {\n" + + " float[] tab = new float[] {-0.0f};\n" + + " System.out.print(tab[0]);\n" + + " }\n" + + "}", + }, + "-0.0"); +} +/** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=28615 + */ +public void test003() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public static void main(String[] args) {\n" + + " float[] tab = new float[] {0.0f};\n" + + " System.out.print(tab[0]);\n" + + " }\n" + + "}", + }, + "0.0"); +} +/** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=28615 + */ +public void test004() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] {-0};\n" + + " System.out.print(tab[0]);\n" + + " }\n" + + "}", + }, + "0"); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=37387 + */ +public void test005() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private static final Object X[] = new Object[]{null,null};\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " static {};\n" + + " 0 iconst_2\n" + + " 1 anewarray java.lang.Object [3]\n" + + " 4 putstatic X.X : java.lang.Object[] [9]\n" + + " 7 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} +/** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=80597 + */ +public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " char[][][] array = new char[][][10];\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " char[][][] array = new char[][][10];\n" + + " ^^\n" + + "Cannot specify an array dimension after an empty dimension\n" + + "----------\n"); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=85203 + */ +public void test007() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static long lfield;\n" + + " \n" + + " public static void main(String[] args) {\n" + + " lfield = args.length;\n" + + " lfield = args(args).length;\n" + + " \n" + + " }\n" + + " static String[] args(String[] args) {\n" + + " return args;\n" + + " }\n" + + "}\n", + }, + ""); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=85125 + */ +public void test008() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public String getTexts(int i) [] {\n" + + " String[] texts = new String[1];\n" + + " return texts; \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +// check deep resolution of faulty initializer (no array expected type) +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=120263 +public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " X x = { 10, zork() };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X x = { 10, zork() };\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from int[] to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " X x = { 10, zork() };\n" + + " ^^^^\n" + + "The method zork() is undefined for the type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=124101 +public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " int i = {};\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int i = {};\n" + + " ^^\n" + + "Type mismatch: cannot convert from Object[] to int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148807 - variation +public void test011() throws Exception { + if (new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_5) { + // there is a bug on 1.4 VMs which make them fail verification (see 148807) + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " Object[][] all = new String[1][];\n" + + " all[0] = new Object[0];\n" + + " } catch (ArrayStoreException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "SUCCESS"); + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 anewarray java.lang.String[] [16]\n" + + " 4 astore_1 [all]\n" + + " 5 aload_1 [all]\n" + + " 6 iconst_0\n" + + " 7 iconst_0\n" + + " 8 anewarray java.lang.Object [3]\n" + + " 11 aastore\n" + + " 12 goto 24\n" + + " 15 astore_1 [e]\n" + + " 16 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + + " 19 ldc [24]\n" + + " 21 invokevirtual java.io.PrintStream.println(java.lang.String) : void [26]\n" + + " 24 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 12] -> 15 when : java.lang.ArrayStoreException\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 5, line: 5]\n" + + " [pc: 12, line: 6]\n" + + " [pc: 16, line: 7]\n" + + " [pc: 24, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 25] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 5, pc: 12] local: all index: 1 type: java.lang.Object[][]\n" + + " [pc: 16, pc: 24] local: e index: 1 type: java.lang.ArrayStoreException\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148807 - variation +public void test012() throws Exception { + if (new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_5) { + // there is a bug on 1.4 VMs which make them fail verification (see 148807) + return; + } + this.runConformTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + " Map fValueMap;\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public Object[][] getAllChoices() {\n" + + " Object[][] all = new String[this.fValueMap.size()][];\n" + + " return all;\n" + + " }\n" + + "}", // =================, + }, + "SUCCESS"); + String expectedOutput = + " // Method descriptor #35 ()[[Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 2\n" + + " public java.lang.Object[][] getAllChoices();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield X.fValueMap : java.util.Map [36]\n" + + " 4 invokeinterface java.util.Map.size() : int [38] [nargs: 1]\n" + + " 9 anewarray java.lang.String[] [44]\n" + + " 12 astore_1 [all]\n" + + " 13 aload_1 [all]\n" + + " 14 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 13, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: X\n" + + " [pc: 13, pc: 15] local: all index: 1 type: java.lang.Object[][]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//check resolution of faulty initializer +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179477 +public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String[] m(String arg) {\n" + + " System.out.println(argument + argument);\n" + + " return new String[] { argument + argument, argument/*no problem*/ };\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(argument + argument);\n" + + " ^^^^^^^^\n" + + "argument cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " System.out.println(argument + argument);\n" + + " ^^^^^^^^\n" + + "argument cannot be resolved to a variable\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " return new String[] { argument + argument, argument/*no problem*/ };\n" + + " ^^^^^^^^\n" + + "argument cannot be resolved to a variable\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " return new String[] { argument + argument, argument/*no problem*/ };\n" + + " ^^^^^^^^\n" + + "argument cannot be resolved to a variable\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " return new String[] { argument + argument, argument/*no problem*/ };\n" + + " ^^^^^^^^\n" + + "argument cannot be resolved to a variable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247307 +// Check return type of array#clone() +public void test014() throws Exception { + Map optionsMap = getCompilerOptions(); + CompilerOptions options = new CompilerOptions(optionsMap); + if (options.complianceLevel > ClassFileConstants.JDK1_4) { + // check that #clone() return type is changed ONLY from -source 1.5 only (independant from compliance level) + optionsMap.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(long[] longs) throws Exception {\n" + + " long[] other = longs.clone();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " long[] other = longs.clone();\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to long[]\n" + + "----------\n", + null, + true, + optionsMap); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247307 - variation +//Check return type of array#clone() +public void test015() throws Exception { + if ( new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_5) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(long[] longs) throws Exception {\n" + + " long[] other = longs.clone();\n" + + " }\n" + + "}\n", + }, + ""); +} +//https:bugs.eclipse.org/bugs/show_bug.cgi?id=247307 - variation +//Check constant pool declaring class of array#clone() +public void test016() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(long[] longs) throws Exception {\n" + + " Object other = longs.clone();\n" + + " }\n" + + "}\n", + }, + ""); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel <= ClassFileConstants.JDK1_4 + ? " // Method descriptor #15 ([J)V\n" + + " // Stack: 1, Locals: 3\n" + + " void foo(long[] longs) throws java.lang.Exception;\n" + + " 0 aload_1 [longs]\n" + + " 1 invokevirtual java.lang.Object.clone() : java.lang.Object [19]\n" + + " 4 astore_2 [other]\n" + + " 5 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 5, line: 4]\n" + : " // Method descriptor #15 ([J)V\n" + + " // Stack: 1, Locals: 3\n" + + " void foo(long[] longs) throws java.lang.Exception;\n" + + " 0 aload_1 [longs]\n" + + " 1 invokevirtual long[].clone() : java.lang.Object [19]\n" + + " 4 astore_2 [other]\n" + + " 5 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 5, line: 4]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } + return; +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247307 - variation +//Check constant pool declaring class of array#clone() +public void test017() throws Exception { + Map optionsMap = getCompilerOptions(); + CompilerOptions options = new CompilerOptions(optionsMap); + if (options.complianceLevel > ClassFileConstants.JDK1_4) { + // check that #clone() return type is changed ONLY from -source 1.5 only (independant from compliance level) + optionsMap.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(long[] longs) throws Exception {\n" + + " Object other = longs.clone();\n" + + " }\n" + + "}\n", + }, + "", + null, + true, + null, + optionsMap, + null); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([J)V\n" + + " // Stack: 1, Locals: 3\n" + + " void foo(long[] longs) throws java.lang.Exception;\n" + + " 0 aload_1 [longs]\n" + + " 1 invokevirtual java.lang.Object.clone() : java.lang.Object [19]\n" + + " 4 astore_2 [other]\n" + + " 5 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 5, line: 4]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} + +// https://bugs.eclipse.org/331872 - [compiler] NPE in Scope.createArrayType when attempting qualified access from type parameter +public void test018() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runNegativeTest( + new String[] { + "X.java", + "public class X

{\n" + + " void foo(p.O[] elems) {\n" + + " }\n" + + " void bar() {\n" + + " foo(new Object[0]);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(p.O[] elems) {\n" + + " ^^^^^\n" + + "Illegal qualified access from the type parameter p\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " foo(new Object[0]);\n" + + " ^^^\n" + + "The method foo(Object[]) is undefined for the type X

\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=409247 - [1.8][compiler] Verify error with code allocating multidimensional array +public void test019() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X [][][] x = new X[10][10][];\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssertionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssertionTest.java new file mode 100644 index 0000000000..5f4e0e3fb1 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssertionTest.java @@ -0,0 +1,643 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class AssertionTest extends AbstractRegressionTest { +// 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[] { "test000" }; +// TESTS_NUMBERS = new int[] { 13, 14 }; +// TESTS_RANGE = new int[] { 11, -1 }; + } + public AssertionTest(String name) { + super(name); + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_4); + } + + public static Class testClass() { + return AssertionTest.class; + } + + public void test001() { + this.runNegativeTest( + new String[] { + "assert.java", + "public class assert {}\n", + }, + "----------\n" + + "1. ERROR in assert.java (at line 1)\n" + + " public class assert {}\n" + + " ^^^^^^\n" + + "Syntax error on token \"assert\", Identifier expected\n" + + "----------\n"); + } + + public void test002() { + this.runConformTest(new String[] { + "A4.java", + "public class A4 { \n" + + " public static void main(String[] args) {\n" + + " try { \n" + + " int i = 4;\n" + + " assert i != 4;\n" + + " System.out.println(i);\n" + + " } catch(AssertionError e){ \n" + + " System.out.print(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + "} \n" }, + "SUCCESS", //expected display + null, // use default class-path + true, // flush previous output dir content + new String[] {"-ea"}); + } + + public void test003() { + this.runConformTest(new String[] { + "A4.java", + "public class A4 { \n" + + " public static void main(String[] args) {\n" + + " int i = 4;\n" + + " assert i != 4;\n" + + " System.out.println(i);\n" + + " } \n" + + "} \n" }, + "4", + null, // use default class-path + true, // flush previous output dir content + new String[] {"-da"}); + } + public void test004() { + this.runConformTest(new String[] { + "A4.java", + "public class A4 { \n" + + " public static void main(String[] args) {\n" + + " try { \n" + + " assert false : \"SUC\"; \n" + + " } catch(AssertionError e){ \n" + + " System.out.print(e.getMessage()); \n" + + " } \n" + + " try { \n" + + " assert false : new Object(){ public String toString(){ return \"CESS\";}}; \n" + + " } catch(AssertionError e){ \n" + + " System.out.println(e.getMessage()); \n" + + " } \n" + + " } \n" + + "} \n" }, + "SUCCESS", //expected display + null, // use default class-path + true, // flush previous output dir content + new String[] {"-ea"}); + } + public void test005() { + this.runConformTest(new String[] { + "A4.java", + "public class A4 { \n" + + " public static void main(String[] args) {\n" + + " try { \n" + + " assert false : 1; \n" + + " } catch(AssertionError e){ \n" + + " System.out.print(e.getMessage()); \n" + + " } \n" + + " try { \n" + + " int i = 2; \n" + + " assert false : i; \n" + + " } catch(AssertionError e){ \n" + + " System.out.println(e.getMessage()); \n" + + " } \n" + + " } \n" + + "} \n" }, + "12", //expected display + null, // use default class-path + true, // flush previous output dir content + new String[] {"-ea"}); + } + public void test006() { + this.runNegativeTest(new String[] { + "A4.java", + "public class A4 { \n" + + " public static void main(String[] args) {\n" + + " try { \n" + + " assert false : unbound; \n" + + " } catch(AssertionError e){ \n" + + " System.out.println(e.getMessage()); \n" + + " } \n" + + " } \n" + + "} \n" }, + "----------\n" + + "1. ERROR in A4.java (at line 4)\n" + + " assert false : unbound; \n" + + " ^^^^^^^\n" + + "unbound cannot be resolved to a variable\n" + + "----------\n"); + } + public void test007() { + this.runConformTest(new String[] { + "A4.java", + "public class A4 { \n" + + " public static void main(String[] args) {\n" + + " try { \n" + + " assert false : 1L; \n" + + " } catch(AssertionError e){ \n" + + " System.out.print(e.getMessage()); \n" + + " } \n" + + " try { \n" + + " assert false : 0L; \n" // 0L isn't 0 + + " } catch(AssertionError e){ \n" + + " System.out.print(e.getMessage()); \n" + + " } \n" + + " try { \n" + + " long l = 2L; \n" + + " assert false : l; \n" + + " } catch(AssertionError e){ \n" + + " System.out.println(e.getMessage()); \n" + + " } \n" + + " } \n" + + "} \n" }, + "102", //expected display + null, // use default class-path + true, // flush previous output dir content + new String[] {"-ea"}); + } + public void test008() { + this.runConformTest(new String[] { + "A4.java", + "public class A4 { \n" + + " public static void main(String[] args) {\n" + + " try { \n" + + " assert false : 1.0f; \n" + + " } catch(AssertionError e){ \n" + + " System.out.print(e.getMessage()); \n" + + " } \n" + + " try { \n" + + " float f = 2.0f; \n" + + " assert false : f; \n" + + " } catch(AssertionError e){ \n" + + " System.out.println(e.getMessage()); \n" + + " } \n" + + " } \n" + + "} \n" }, + "1.02.0", //expected display + null, // use default class-path + true, // do not flush previous output dir content + new String[] {"-ea"}); + } + public void test009() { + this.runConformTest(new String[] { + "A4.java", + "public class A4 { \n" + + " public static void main(String[] args) {\n" + + " try { \n" + + " assert false : 1.0; \n" + + " } catch(AssertionError e){ \n" + + " System.out.print(e.getMessage()); \n" + + " } \n" + + " try { \n" + + " double d = 2.0; \n" + + " assert false : d; \n" + + " } catch(AssertionError e){ \n" + + " System.out.println(e.getMessage()); \n" + + " } \n" + + " } \n" + + "} \n" }, + "1.02.0", //expected display + null, // use default class-path + true, // flush previous output dir content + new String[] {"-ea"}); + } + // http://dev.eclipse.org/bugs/show_bug.cgi?id=22334 + public void test010() { + this.runConformTest(new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) { \n" + + " I.Inner inner = new I.Inner(); \n" + + " try { \n" + + " inner.test(); \n" + + " System.out.println(\"FAILED\"); \n" + + " } catch(AssertionError e){ \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + "} \n" + + "interface I { \n" + + " public static class Inner { \n" + + " public void test() { \n" + + " assert false; \n" + + " } \n" + + " } \n" + + "} \n" }, + "SUCCESS", + null, // use default classpath + true, // flush previous output dir content + new String[] {"-ea"}); + } + + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=28750 + */ + public void test011() { + this.runConformTest( + new String[] { + "AssertTest.java", + "public class AssertTest {\n" + + " public AssertTest() {}\n" + + " public class InnerClass {\n" + + " InnerClass() {\n" + + " assert(false);\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) { \n" + + " System.out.print(\"SUCCESS\"); \n" + + " } \n" + + "}" + }, + "SUCCESS"); // expected output + } + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=57743 + */ + public void test012() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main( String[] args ) {\n" + + " try {\n" + + " throw new Throwable( \"This is a test\");\n" + + " }\n" + + " catch( Throwable ioe ) {\n" + + " assert false : ioe;\n" + + " }\n" + + " System.out.print(\"SUCCESS\"); \n" + + " }\n" + + "}\n" + }, + "SUCCESS"); // expected output + } + + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=157389 + */ + public void test013() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Y {\n" + + " public static void test() {\n" + + " assert false;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " ClassLoader classLoader = new X().getClass().getClassLoader();\n" + + " // enable assertion for X.Y\n" + + " classLoader.setClassAssertionStatus(\"X$Y\", true);\n" + + " X.Y.test();\n" + + " }\n" + + "}" + }, + "SUCCESS"); // expected output + } + + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=163600 + */ + public void test014() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static class Foo {\n" + + " public void myMethod(boolean trash) {\n" + + " System.out.println(\"Expecting class Foo\");\n" + + " Class c = Foo.class;\n" + + " System.out.println(\"Got the class \" + c);\n" + + " }\n" + + " }\n" + + " public static class Bar {\n" + + " public void myMethod(boolean doAssert) {\n" + + " System.out.println(\"Expecting class Bar\");\n" + + " Class c = Bar.class;\n" + + " System.out.println(\"Got the class \" + c);\n" + + " assert c.getName().endsWith(\"Bar\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Foo().myMethod(false);\n" + + " new Bar().myMethod(false);\n" + + " }\n" + + "}" + }, + "Expecting class Foo\n" + + "Got the class class X$Foo\n" + + "Expecting class Bar\n" + + "Got the class class X$Bar"); // expected output + } + + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=163600 + */ + public void test015() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static class Foo {\n" + + " public void myMethod(boolean trash) {\n" + + " System.out.println(\"Expecting class Foo\");\n" + + " Class c = Foo.class;\n" + + " System.out.println(\"Got the class \" + c);\n" + + " }\n" + + " }\n" + + " public static class Bar {\n" + + " public void myMethod(boolean doAssert) {\n" + + " System.out.println(\"Expecting class Bar\");\n" + + " Class c = Bar.class;\n" + + " try {\n" + + " assert c.getName().endsWith(\"Bar2\");\n" + + " } catch(AssertionError e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " System.out.println(\"Got the class \" + c);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Foo().myMethod(false);\n" + + " new Bar().myMethod(false);\n" + + " }\n" + + "}" + }, + "Expecting class Foo\n" + + "Got the class class X$Foo\n" + + "Expecting class Bar\n" + + "SUCCESS\n" + + "Got the class class X$Bar", + null, // use default classpath + true, // flush previous output dir content + new String[] {"-ea"}); + } + + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=163600 + */ + public void test016() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static class Foo {\n" + + " public void myMethod(boolean trash) {\n" + + " System.out.println(\"Expecting class Foo\");\n" + + " Class c = Foo.class;\n" + + " System.out.println(\"Got the class \" + c);\n" + + " }\n" + + " }\n" + + " public static class Bar {\n" + + " public void myMethod(boolean doAssert) {\n" + + " System.out.println(\"Expecting class Bar\");\n" + + " Class c = Bar.class;\n" + + " try {\n" + + " assert c.getName().endsWith(\"Bar2\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " } catch(AssertionError e) {\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + " System.out.println(\"Got the class \" + c);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Foo().myMethod(false);\n" + + " new Bar().myMethod(false);\n" + + " }\n" + + "}" + }, + "Expecting class Foo\n" + + "Got the class class X$Foo\n" + + "Expecting class Bar\n" + + "SUCCESS\n" + + "Got the class class X$Bar", + null, // use default classpath + true, // flush previous output dir content + new String[] {"-da"}); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=255008 + public void test017() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " protected void transform1(boolean srcPts) {\n" + + " final float error1;\n" + + " assert !(srcPts && (error1 = maxError()) > 0) : error1;\n" + + " }\n" + + " float foo1(boolean srcPts) {\n" + + " final float error2;\n" + + " if (!(srcPts && (error2 = maxError()) > 0)) {\n" + + " } else {\n" + + " return error2;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + " float bar1(boolean srcPts) {\n" + + " final float error3;\n" + + " if ((srcPts && (error3 = maxError()) > 0)) {\n" + + " return error3;\n" + + " }\n" + + " return 0;\n" + + " } \n" + + " protected void transform2(boolean srcPts) {\n" + + " final float error4;\n" + + " assert (srcPts && (error4 = maxError()) > 0) : error4;\n" + + " }\n" + + " float foo2(boolean srcPts) {\n" + + " final float error5;\n" + + " if (srcPts && (error5 = maxError()) > 0) {\n" + + " } else {\n" + + " return error5;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + " float bar2(boolean srcPts) {\n" + + " final float error6;\n" + + " if (!(srcPts && (error6 = maxError()) > 0)) {\n" + + " return error6;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + " private float maxError() {\n" + + " return 0;\n" + + " }\n" + + "\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 23)\n" + + " assert (srcPts && (error4 = maxError()) > 0) : error4;\n" + + " ^^^^^^\n" + + "The local variable error4 may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 29)\n" + + " return error5;\n" + + " ^^^^^^\n" + + "The local variable error5 may not have been initialized\n" + + "----------\n" + + "3. ERROR in X.java (at line 36)\n" + + " return error6;\n" + + " ^^^^^^\n" + + "The local variable error6 may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=328361 + public void test018() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " static final int i;\n" + + " static {\n" + + " assert (i = 0) == 0;\n" + + " System.out.println(i);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " static final int i;\n" + + " ^\n" + + "The blank final field i may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.println(i);\n" + + " ^\n" + + "The blank final field i may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=328361 + public void test019() { + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " static final int i;\n" + + " static {\n" + + " i = 0;\n" + + " assert i == 0;\n" + + " System.out.println(i);\n" + + " }\n" + + "}" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=328361 + public void test020() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void method1() {\n" + + " int i;" + + " assert (i = 0) == 0;\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " System.out.println(i);\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=328361 + public void test021() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public int bar() {\n" + + " return 1;\n" + + " }\n" + + " void method1() {\n" + + " int i;" + + " assert (i = this.bar()) == 0;\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(i);\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=328361 + public void test022() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public int bar() {\n" + + " return 1;\n" + + " }\n" + + " void method1() {\n" + + " int i;\n" + + " assert i++ == 0;\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " assert i++ == 0;\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " System.out.println(i);\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); + } + public void test023() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runConformTest(new String[] {"X.java", + "interface Foo {\n" + + " default Object test(Object a) {\n" + + " assert a != null; // triggers creation of bogus synthetic field\n" + + " return a;\n" + + " }\n" + + "}\n" + + "public class X implements Foo {\n" + + " public static void main(String[] args) {\n" + + " new X().test(\"\");\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + "}\n"}, "Hello"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java new file mode 100644 index 0000000000..c1dd988f1b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest.java @@ -0,0 +1,2184 @@ +/******************************************************************************* + * Copyright (c) 2005, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 185682 - Increment/decrement operators mark local variables as read + * bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class AssignmentTest extends AbstractRegressionTest { + +public AssignmentTest(String name) { + super(name); +} +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportNoEffectAssignment, CompilerOptions.ERROR); + return options; +} +// 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[] { "test000" }; +// TESTS_NUMBERS = new int[] { 69 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public static Test suite() { + Test suite = buildAllCompliancesTestSuite(testClass()); + return suite; +} +/* + * no effect assignment bug + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=27235 + */ +public void test001() { + this.runConformTest( new String[] { + "X.java", + "public class X { \n" + + " int i; \n" + + " X(int j) { \n" + + " i = j; \n" + + " } \n" + + " X() { \n" + + " } \n" + + " class B extends X { \n" + + " B() { \n" + + " this.i = X.this.i; \n" + + " } \n" + + " } \n" + + " public static void main(String[] args) { \n" + + " X a = new X(3); \n" + + " System.out.print(a.i + \" \"); \n" + + " System.out.print(a.new B().i); \n" + + " } \n" + + "} \n", + }, + "3 3"); +} + +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int a; \n" + + " X next; \n" + + " public void foo(int arg){ \n" + + " \n" + + " zork = zork; \n" + + " arg = zork; \n" + + " \n" + + " arg = arg; // noop \n" + + " a = a; // noop \n" + + " this.next = this.next; // noop \n" + + " this.next = next; // noop \n" + + " \n" + + " next.a = next.a; // could raise NPE \n" + + " this.next.next.a = next.next.a; // could raise NPE \n" + + " a = next.a; // could raise NPE \n" + + " this. a = next.a; \n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " zork = zork; \n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " zork = zork; \n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " arg = zork; \n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " arg = arg; // noop \n" + + " ^^^^^^^^^\n" + + "The assignment to variable arg has no effect\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " a = a; // noop \n" + + " ^^^^^\n" + + "The assignment to variable a has no effect\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " this.next = this.next; // noop \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The assignment to variable next has no effect\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " this.next = next; // noop \n" + + " ^^^^^^^^^^^^^^^^\n" + + "The assignment to variable next has no effect\n" + + "----------\n"); +} +public void test003() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int portNumber;\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.portNumber = Integer.parseInt(\"12\");\n" + + " x.run();\n" + + " }\n" + + " private void run() {\n" + + " System.out.println(portNumber);\n" + + " }\n" + + "}", // ================= + + }, + "12"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=151787 +public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " // correctly passes compilation\n" + + " static class Test1 {\n" + + " private final Object o;\n" + + " \n" + + " Test1() {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " \n" + + " // correctly passes compilation\n" + + " static class Test2 {\n" + + " private final Object o;\n" + + " \n" + + " Test2() {\n" + + " this.o = new Object();\n" + + " }\n" + + " }\n" + + " \n" + + " // correctly fails compilation\n" + + " static class Test3 {\n" + + " private final Object o;\n" + + " \n" + + " Test3() {\n" + + " System.out.println(o); // illegal; o is not definitely assigned\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " \n" + + " // correctly passes compilation\n" + + " static class Test4 {\n" + + " private final Object o;\n" + + " \n" + + " Test4() {\n" + + " System.out.println(this.o); // legal\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " \n" + + " // incorrectly passes compilation\n" + + " static class Test5 {\n" + + " private final Object o;\n" + + " \n" + + " Test5() {\n" + + " Test5 other = this;\n" + + " other.o = new Object(); // illegal! other.o is not assignable\n" + + " } // error: this.o is not definitely assigned\n" + + " }\n" + + " \n" + + " // flags wrong statement as error\n" + + " static class Test6 {\n" + + " private final Object o;\n" + + " static Test6 initing;\n" + + " \n" + + " Test6() {\n" + + " initing = this;\n" + + " System.out.println(\"greetings\");\n" + + " Test6 other = initing;\n" + + " other.o = new Object(); // illegal! other.o is not assignable\n" + + " o = new Object(); // legal\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " private final Object o;\n" + + " ^\n" + + "The value of the field X.Test1.o is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " private final Object o;\n" + + " ^\n" + + "The value of the field X.Test2.o is not used\n" + + "----------\n" + + "3. ERROR in X.java (at line 25)\n" + + " System.out.println(o); // illegal; o is not definitely assigned\n" + + " ^\n" + + "The blank final field o may not have been initialized\n" + + "----------\n" + + (this.complianceLevel >= ClassFileConstants.JDK1_7 ? + "4. ERROR in X.java (at line 35)\n" + + " System.out.println(this.o); // legal\n" + + " ^\n" + + "The blank final field o may not have been initialized\n" + + "----------\n" + + "5. WARNING in X.java (at line 42)\n" + + " private final Object o;\n" + + " ^\n" + + "The value of the field X.Test5.o is not used\n" + + "----------\n" + + "6. ERROR in X.java (at line 44)\n" + + " Test5() {\n" + + " ^^^^^^^\n" + + "The blank final field o may not have been initialized\n" + + "----------\n" + + "7. ERROR in X.java (at line 46)\n" + + " other.o = new Object(); // illegal! other.o is not assignable\n" + + " ^\n" + + "The final field X.Test5.o cannot be assigned\n" + + "----------\n" + + "8. WARNING in X.java (at line 52)\n" + + " private final Object o;\n" + + " ^\n" + + "The value of the field X.Test6.o is not used\n" + + "----------\n" + + "9. ERROR in X.java (at line 59)\n" + + " other.o = new Object(); // illegal! other.o is not assignable\n" + + " ^\n" + + "The final field X.Test6.o cannot be assigned\n" + + "----------\n" + : + "4. WARNING in X.java (at line 42)\n" + + " private final Object o;\n" + + " ^\n" + + "The value of the field X.Test5.o is not used\n" + + "----------\n" + + "5. ERROR in X.java (at line 44)\n" + + " Test5() {\n" + + " ^^^^^^^\n" + + "The blank final field o may not have been initialized\n" + + "----------\n" + + "6. ERROR in X.java (at line 46)\n" + + " other.o = new Object(); // illegal! other.o is not assignable\n" + + " ^\n" + + "The final field X.Test5.o cannot be assigned\n" + + "----------\n" + + "7. WARNING in X.java (at line 52)\n" + + " private final Object o;\n" + + " ^\n" + + "The value of the field X.Test6.o is not used\n" + + "----------\n" + + "8. ERROR in X.java (at line 59)\n" + + " other.o = new Object(); // illegal! other.o is not assignable\n" + + " ^\n" + + "The final field X.Test6.o cannot be assigned\n" + + "----------\n")); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190391 +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " final int contents;\n" + + " \n" + + " X() {\n" + + " contents = 3;\n" + + " }\n" + + " X(X other) {\n" + + " other.contents = 5;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X one = new X();\n" + + " System.out.println(\"one.contents: \" + one.contents);\n" + + " X two = new X(one);\n" + + " System.out.println(\"one.contents: \" + one.contents);\n" + + " System.out.println(\"two.contents: \" + two.contents);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X(X other) {\n" + + " ^^^^^^^^^^\n" + + "The blank final field contents may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " other.contents = 5;\n" + + " ^^^^^^^^\n" + + "The final field X.contents cannot be assigned\n" + + "----------\n"); +} +// final multiple assignment +public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final int v;\n" + + " for (int i = 0; i < 10; i++) {\n" + + " v = i;\n" + + " }\n" + + " v = 0;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " v = i;\n" + + " ^\n" + + "The final local variable v may already have been assigned\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " v = 0;\n" + + " ^\n" + + "The final local variable v may already have been assigned\n" + + "----------\n"); +} + +// null part has been repeated into NullReferenceTest#test1033 +public void test033() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " String a,b;\n" + + " do{\n" + + " a=\"Hello \";\n" + + " }while(a!=null);\n" + + " \n" + + " if(a!=null)\n" + + " {\n" + + " b=\"World!\";\n" + + " }\n" + + " System.out.println(a+b);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " }while(a!=null);\n" + + " ^\n" + + "Redundant null check: The variable a cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " if(a!=null)\n" + + " ^\n" + + "Null comparison always yields false: The variable a can only be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " System.out.println(a+b);\n" + + " ^\n" + + "The local variable b may not have been initialized\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=84215 +//TODO (philippe) should move to InitializationTest suite +public void test034() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public final class X \n" + + "{\n" + + " public static String vdg;\n" + + " public static final String aa = null;\n" + + " public static final int a = 14;\n" + + " public static final int b = 3;\n" + + " private static final int c = 12;\n" + + " private static final int d = 2; \n" + + " private static final int e = 3; \n" + + " private static final int f = 34; \n" + + " private static final int g = 35; \n" + + " private static final int h = 36; \n" + + " private static final int j = 4;\n" + + " private static final int k = 1;\n" + + " public static final int aba = 1;\n" + + " public static final int as = 11;\n" + + " public static final int ad = 12;\n" + + " public static final int af = 13;\n" + + " public static final int ag = 2;\n" + + " public static final int ah = 21;\n" + + " public static final int aj = 22;\n" + + " public static final int ak = 3;\n" + + " public static final String aaad = null;\n" + + " public static final int aaaf = 1;\n" + + " public static final int aaag = 2;\n" + + " public static final int aaha = 2;\n" + + " static int cxvvb = 1;\n" + + " static int z = a;\n" + + " String asdff;\n" + + " public static String ppfp;\n" + + " public static int ppfpged;\n" + + " boolean asfadf;\n" + + " boolean cbxbx;\n" + + " private static long tyt, rrky;\n" + + " private static int dgjt, ykjr6y;\n" + + " private static final int krykr = 1;\n" + + " protected static int rykr5;\n" + + " protected static int dhfg;\n" + + " private static int dthj;\n" + + " private static int fkffy;\n" + + " private static String fhfy;\n" + + " protected static String fhmf;\n" + + " protected String ryur6;\n" + + " protected String dhdthd;\n" + + " protected String dth5;\n" + + " protected String kfyk;\n" + + " private String ntd;\n" + + " public int asdasdads;\n" + + " public static final int dntdr = 7;\n" + + " public static final int asys = 1;\n" + + " public static final int djd5rwas = 11;\n" + + " public static final int dhds45rjd = 12;\n" + + " public static final int srws4jd = 13;\n" + + " public static final int s4ts = 2;\n" + + " public static final int dshes4 = 21;\n" + + " public static final int drthed56u = 22;\n" + + " public static final int drtye45 = 23;\n" + + " public static final int xxbxrb = 3;\n" + + " public static final int xfbxr = 31;\n" + + " public static final int asgw4y = 32;\n" + + " public static final int hdtrhs5r = 33;\n" + + " public static final int dshsh = 34;\n" + + " public static final int ds45yuwsuy = 4;\n" + + " public static final int astgs45rys = 5;\n" + + " public static final int srgs4y = 6;\n" + + " public static final int srgsryw45 = -6;\n" + + " public static final int srgdtgjd45ry = -7;\n" + + " public static final int srdjs43t = 1;\n" + + " public static final int sedteued5y = 2;\n" + + " public static int jrfd6u;\n" + + " public static int udf56u;\n" + + " private String jf6tu;\n" + + " private String jf6tud;\n" + + " String bsrh;\n" + + " protected X(String a)\n" + + " {\n" + + " }\n" + + " private long sfhdsrhs;\n" + + " private boolean qaafasdfs;\n" + + " private int sdgsa;\n" + + " private long dgse4;\n" + + " long sgrdsrg;\n" + + " public void gdsthsr()\n" + + " {\n" + + " }\n" + + " private int hsrhs;\n" + + " private void hsrhsdsh()\n" + + " {\n" + + " }\n" + + " private String dsfhshsr;\n" + + " protected void sfhsh4rsrh()\n" + + " {\n" + + " }\n" + + " protected void shsrhsh()\n" + + " {\n" + + " }\n" + + " protected void sfhstuje56u()\n" + + " {\n" + + " }\n" + + " public void dhdrt6u()\n" + + " {\n" + + " }\n" + + " public void hdtue56u()\n" + + " {\n" + + " }\n" + + " private void htdws4()\n" + + " {\n" + + " }\n" + + " String mfmgf;\n" + + " String mgdmd;\n" + + " String mdsrh;\n" + + " String nmdr;\n" + + " private void oyioyio()\n" + + " {\n" + + " }\n" + + " protected static long oyioyreye()\n" + + " {\n" + + " return 0;\n" + + " }\n" + + " protected static long etueierh()\n" + + " {\n" + + " return 0;\n" + + " }\n" + + " protected static void sdfgsgs()\n" + + " {\n" + + " }\n" + + " protected static void fhsrhsrh()\n" + + " {\n" + + " }\n" + + "\n" + + " long dcggsdg;\n" + + " int ssssssgsfh;\n" + + " long ssssssgae;\n" + + " long ssssssfaseg;\n" + + " public void zzzdged()\n" + + " {\n" + + " }\n" + + " \n" + + " String t;\n" + + " protected void xxxxxcbsg()\n" + + " {\n" + + " }\n" + + "\n" + + " \n" + + " public void vdg()\n" + + " {\n" + + " }\n" + + " \n" + + " private int[] fffcvffffffasdfaef;\n" + + " private int[] fffcffffffasdfaef;\n" + + " private long[] ffcvfffffffasdfaef;\n" + + " private int fffffghffffasdfaef; \n" + + " private int fffffdffffasdfaef; \n" + + " private String ffafffffffasdfaef;\n" + + " \n" + + " private void fffffffffasdfaef()\n" + + " {\n" + + " }\n" + + " \n" + + " private boolean aaaadgasrg;\n" + + " private void ddddgaergnj()\n" + + " {\n" + + " }\n" + + "\n" + + " private void aaaadgaeg()\n" + + " {\n" + + " }\n" + + " \n" + + " private void aaaaaaefadfgh()\n" + + " {\n" + + " }\n" + + " \n" + + " private void addddddddafge()\n" + + " {\n" + + " }\n" + + " \n" + + " static boolean aaaaaaaefae;\n" + + " protected void aaaaaaefaef()\n" + + " {\n" + + " }\n" + + "\n" + + " private void ggggseae()\n" + + " {\n" + + " }\n" + + "\n" + + " private static void ggggggsgsrg()\n" + + " {\n" + + " }\n" + + "\n" + + " private static synchronized void ggggggfsfgsr()\n" + + " {\n" + + " }\n" + + "\n" + + " private void aaaaaadgaeg()\n" + + " {\n" + + " }\n" + + " \n" + + " private void aaaaadgaerg()\n" + + " {\n" + + " }\n" + + " \n" + + " private void bbbbbbsfryghs()\n" + + " {\n" + + " }\n" + + " \n" + + " private void bfbbbbbbfssreg()\n" + + " {\n" + + " }\n" + + "\n" + + " private void bbbbbbfssfb()\n" + + " {\n" + + " }\n" + + "\n" + + " private void bbbbbbfssb()\n" + + " {\n" + + " }\n" + + "\n" + + " private void bbbbfdssb()\n" + + " {\n" + + " }\n" + + " \n" + + " boolean dggggggdsg;\n" + + "\n" + + " public void hdfhdr()\n" + + " {\n" + + " }\n" + + " \n" + + " private void dhdrtdrs()\n" + + " {\n" + + " }\n" + + " \n" + + " private void dghdthtdhd()\n" + + " {\n" + + " }\n" + + " \n" + + " private void dhdhdtdh()\n" + + " {\n" + + " }\n" + + " \n" + + " private void fddhdsh()\n" + + " {\n" + + " }\n" + + " \n" + + " private boolean sdffgsdg()\n" + + " {\n" + + " return true;\n" + + " }\n" + + " \n" + + " private static boolean sdgsdg()\n" + + " {\n" + + " return false;\n" + + " }\n" + + " \n" + + " protected static final void sfdgsg()\n" + + " {\n" + + " }\n" + + "\n" + + " static int[] fghtys;\n" + + "\n" + + " protected static final int sdsst = 1;\n" + + " private static X asdfahnr;\n" + + " private static int ssdsdbrtyrtdfhd, ssdsrtyrdbdfhd;\n" + + " protected static int ssdsrtydbdfhd, ssdsrtydffbdfhd;\n" + + " protected static int ssdrtyhrtysdbdfhd, ssyeghdsdbdfhd;\n" + + " private static int ssdsdrtybdfhd, ssdsdehebdfhd;\n" + + " protected static int ssdthrtsdbdfhd, ssdshethetdbdfhd;\n" + + " private static String sstrdrfhdsdbdfhd;\n" + + " protected static int ssdsdbdfhd, ssdsdethbdfhd;\n" + + " private static long ssdshdfhchddbdfhd;\n" + + " private static long ssdsdvbbdfhd;\n" + + " \n" + + " \n" + + " protected static long ssdsdbdfhd()\n" + + " {\n" + + " return 0;\n" + + " }\n" + + "\n" + + " protected static long sdgsrsbsf()\n" + + " {\n" + + " return 0;\n" + + " }\n" + + "\n" + + " protected static void sfgsfgssghr()\n" + + " {\n" + + " }\n" + + " \n" + + " protected static String sgsgsrg()\n" + + " {\n" + + " return null;\n" + + " }\n" + + "\n" + + " protected static void sdgshsdygra()\n" + + " {\n" + + " }\n" + + "\n" + + " private static String sdfsdfs()\n" + + " {\n" + + " return null;\n" + + " }\n" + + "\n" + + " static boolean ryweyer;\n" + + "\n" + + " protected static void adfadfaghsfh()\n" + + " {\n" + + " }\n" + + " \n" + + " protected static void ghasghasrg()\n" + + " {\n" + + " }\n" + + "\n" + + " private static void aadfadfaf()\n" + + " {\n" + + " }\n" + + "\n" + + " protected static void aadfadf()\n" + + " {\n" + + " }\n" + + " \n" + + " private static int fgsfhwr()\n" + + " {\n" + + " return 0;\n" + + " }\n" + + "\n" + + " protected static int gdfgfgrfg()\n" + + " {\n" + + " return 0;\n" + + " }\n" + + "\n" + + " protected static int asdfsfs()\n" + + " {\n" + + " return 0;\n" + + " }\n" + + "\n" + + " protected static String sdgs;\n" + + " protected static String sdfsh4e;\n" + + " protected static final int gsregs = 0;\n" + + " \n" + + " protected static String sgsgsd()\n" + + " {\n" + + " return null;\n" + + " }\n" + + "\n" + + " private byte[] sdhqtgwsrh(String rsName, int id)\n" + + " {\n" + + " String rs = null;\n" + + " try\n" + + " {\n" + + " rs = \"\";\n" + + " return null;\n" + + " }\n" + + " catch (Exception ex)\n" + + " {\n" + + " }\n" + + " finally\n" + + " {\n" + + " if (rs != null)\n" + + " {\n" + + " try\n" + + " {\n" + + " rs.toString();\n" + + " }\n" + + " catch (Exception ex)\n" + + " {\n" + + " }\n" + + " }\n" + + " }\n" + + " return null;\n" + + " }\n" + + "\n" + + " private void dgagadga()\n" + + " {\n" + + " }\n" + + " \n" + + " private String adsyasta;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 356)\n" + + " if (rs != null)\n" + + " ^^\n" + + "Redundant null check: The variable rs cannot be null at this location\n" + + "----------\n", + null/*classLibs*/, + true/*shouldFlush*/, + options); +} +/* + * Check scenario: i = i++ + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=84480 + * disabled: https://bugs.eclipse.org/bugs/show_bug.cgi?id=111898 + */ +public void test035() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int f;\n" + + " void foo(int i) {\n" + + " i = i++;\n" + + " i = ++i;\n" + + " f = f++;\n" + + " f = ++f;\n" + + " Zork z;" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " i = ++i;\n" + + " ^^^^^^^\n" + + "The assignment to variable i has no effect\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " f = ++f;\n" + + " ^^^^^^^\n" + + "The assignment to variable f has no effect\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork z; }\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test036() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " do {\n" + + " o = null;\n" + + " } while (o != null);\n" + + " if (o == null) {\n" + + " // throw new Exception();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " } while (o != null);\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " if (o == null) {\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=93588 +public void test037() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Object implements Runnable {\n" + + " int interval = 5;\n" + + " public void run() {\n" + + " try {\n" + + " Thread.sleep(interval = interval + 100);\n" + + " Thread.sleep(interval += 100);\n" + + " } catch (InterruptedException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().run();\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111703 +public void test038() { + String expectedError = this.complianceLevel < ClassFileConstants.JDK16 ? + "----------\n" + + "1. WARNING in X.java (at line 19)\n" + + " public void valueChanged(TreeSelectionEvent e) {\n" + + " ^\n" + + "The parameter e is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. ERROR in X.java (at line 23)\n" + + " static {\n" + + " ^\n" + + "Cannot define static initializer in inner type new ActionListener(){}\n" + + "----------\n" + + "3. ERROR in X.java (at line 24)\n" + + " myTree.addTreeSelectionListener(list);\n" + + " ^^^^^^\n" + + "Cannot make a static reference to the non-static field myTree\n" + + "----------\n" + + "4. WARNING in X.java (at line 26)\n" + + " public void actionPerformed(ActionEvent e) {\n" + + " ^\n" + + "The parameter e is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 19)\n" + + " public void valueChanged(TreeSelectionEvent e) {\n" + + " ^\n" + + "The parameter e is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. ERROR in X.java (at line 24)\n" + + " myTree.addTreeSelectionListener(list);\n" + + " ^^^^^^\n" + + "Cannot make a static reference to the non-static field myTree\n" + + "----------\n" + + "3. WARNING in X.java (at line 26)\n" + + " public void actionPerformed(ActionEvent e) {\n" + + " ^\n" + + "The parameter e is hiding another local variable defined in an enclosing scope\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.awt.event.*;\n" + + "\n" + + "import javax.swing.*;\n" + + "import javax.swing.event.*;\n" + + "\n" + + "public class X {\n" + + " JButton myButton = new JButton();\n" + + " JTree myTree = new JTree();\n" + + " ActionListener action;\n" + + " X() {\n" + + " action = new ActionListener() {\n" + + " public void actionPerformed(ActionEvent e) {\n" + + " if (true) {\n" + + " // unlock document\n" + + " final Object document = new Object();\n" + + " myButton.addActionListener(new ActionListener() {\n" + + " private static boolean selectionChanged;\n" + + " static TreeSelectionListener list = new TreeSelectionListener() {\n" + + " public void valueChanged(TreeSelectionEvent e) {\n" + + " selectionChanged = true;\n" + + " }\n" + + " };\n" + + " static {\n" + + " myTree.addTreeSelectionListener(list);\n" + + " }\n" + + " public void actionPerformed(ActionEvent e) {\n" + + " if(!selectionChanged)\n" + + " myButton.removeActionListener(this);\n" + + " }\n" + + " });\n" + + " }\n" + + " }\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X();\n" + + " }\n" + + "\n" + + "}", + }, + expectedError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111898 +public void test039() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int a = 1;\n" + + " a = a++;\n" + + " System.out.print(\"a=\"+a);\n" + + " \n" + + " int b = 1;\n" + + " System.out.print(b = b++);\n" + + " System.out.println(\"b=\"+b);\n" + + " }\n" + + "}\n", + }, + "a=11b=1"); +} +// warn upon parameter assignment +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773 +public void test040() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " b = false;\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " b = false;\n" + + " ^\n" + + "The parameter b should not be assigned\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// warn upon parameter assignment +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773 +// diagnose within fake reachable code +public void test041() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " if (false) {\n" + + " b = false;\n" + + " }\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " b = false;\n" + + " ^\n" + + "The parameter b should not be assigned\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// warn upon parameter assignment +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773 +// diagnose within fake reachable code +public void test042() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " if (true) {\n" + + " return;\n" + + " }\n" + + " b = false;\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " b = false;\n" + + " ^\n" + + "The parameter b should not be assigned\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// warn upon parameter assignment +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=53773 +// we only show the 'assignment to final' error here +public void test043() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(final boolean b) {\n" + + " if (false) {\n" + + " b = false;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " b = false;\n" + + " ^\n" + + "The final local variable b cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n", + null, true, options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100369 +public void test044() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int length1 = 0;\n" + + " {\n" + + " length1 = length1; // already detected\n" + + " }\n" + + " int length2 = length2 = 0; // not detected\n" + + " int length3 = 0;\n" + + " {\n" + + " length3 = length3 = 0; // not detected\n" + + " }\n" + + " static void foo() {\n" + + " int length1 = 0;\n" + + " length1 = length1; // already detected\n" + + " int length2 = length2 = 0; // not detected\n" + + " int length3 = 0;\n" + + " length3 = length3 = 0; // not detected\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " length1 = length1; // already detected\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The assignment to variable length1 has no effect\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " int length2 = length2 = 0; // not detected\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The assignment to variable length2 has no effect\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " length3 = length3 = 0; // not detected\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The assignment to variable length3 has no effect\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " length1 = length1; // already detected\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The assignment to variable length1 has no effect\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " int length2 = length2 = 0; // not detected\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The assignment to variable length2 has no effect\n" + + "----------\n" + + "6. ERROR in X.java (at line 16)\n" + + " length3 = length3 = 0; // not detected\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The assignment to variable length3 has no effect\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133351 +public void test045() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " int length2 = length2 = 0; // first problem\n" + + " int length3 = 0;\n" + + " length3 = length3 = 0; // second problem\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int length2 = length2 = 0; // first problem\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The assignment to variable length2 has no effect\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " length3 = length3 = 0; // second problem\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The assignment to variable length3 has no effect\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +public void test046() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " X.s = s;" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X.s = s; }\n" + + " ^^^^^^^\n" + + "The assignment to variable s has no effect\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +public void test047() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static X MyX;\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " X.MyX.s = s;" + // MyX could hold any extending type, hence we must not complain + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +// we could decide that MyX won't change, hence that the assignment +// on line a has no effect, but we accept this as a limit +public void _test048() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final X MyX = new X();\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " X.MyX.s = s;" + // a + " }\n" + + "}\n", + }, + "ERR"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +// adding a package to the picture +public void test049() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " p.X.s = s;" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " p.X.s = s; }\n" + + " ^^^^^^^^^\n" + + "The assignment to variable s has no effect\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +// adding an inner class to the picture +public void test050() { + String expectedError = this.complianceLevel < ClassFileConstants.JDK16 ? + "----------\n" + + "1. ERROR in p\\X.java (at line 4)\n" + + " public static String s;\n" + + " ^\n" + + "The field s cannot be declared static in a non-static inner type, unless initialized with a constant expression\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 6)\n" + + " X.XX.s = s; }\n" + + " ^^^^^^^^^^\n" + + "The assignment to variable s has no effect\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in p\\X.java (at line 6)\n" + + " X.XX.s = s; }\n" + + " ^^^^^^^^^^\n" + + "The assignment to variable s has no effect\n" + + "----------\n"; + + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " class XX {\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " X.XX.s = s;" + + " }\n" + + " }\n" + + "}\n", + }, + expectedError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200724 +// swap lhs and rhs +public void test051() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String s;\n" + + " void foo(String s1) {\n" + + " s = X.s;" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " s = X.s; }\n" + + " ^^^^^^^\n" + + "The assignment to variable s has no effect\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=206017 +public void test052() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " int i = \"aaa\";\n" + + " i = \"bbb\";\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int i = \"aaa\";\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " i = \"bbb\";\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=206017 +public void test053() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int i = \"aaa\";\n" + + " { \n" + + " i = \"bbb\";\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int i = \"aaa\";\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " i = \"bbb\";\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235543 +public void _test054_definite_unassignment_try_catch() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " final int i;\n" + + " try {\n" + + " if (false) {\n" + + " i = 0;\n" + + " System.out.println(i);\n" + + " throw new MyException();\n" + + " }\n" + + " } catch (Exception e) {\n" + + " i = 1; // missing error\n" + + " }\n" + + " }\n" + + "}\n" + + "class MyException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 11)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235543 +// variant +public void test055_definite_unassignment_try_catch() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " final int i;\n" + + " try {\n" + + " if (false) {\n" + + " i = 0;\n" + + " System.out.println(i);\n" + + " throw new MyException();\n" + + " }\n" + + " } catch (MyException e) {\n" + + " i = 1;\n" + + " }\n" + + " }\n" + + "}\n" + + "class MyException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 11)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + + "----------\n", + // javac options + JavacTestOptions.EclipseJustification.EclipseBug235543 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235546 +public void test056_definite_unassignment_infinite_for_loop() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " final int i;\n" + + " for (;true;) {\n" + + " if (true) {\n" + + " break;\n" + + " } else {\n" + + " i = 0;\n" + + " }\n" + + " }\n" + + " i = 1;\n" + + " System.out.println(i);\n" + + " }\n" + + "}" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "1" /* expected output string */, + "" /* expected error string */, + JavacTestOptions.EclipseJustification.EclipseBug235546 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235546 +// variant +public void test057_definite_unassignment_infinite_while_loop() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " final int i;\n" + + " while (true) {\n" + + " if (true) {\n" + + " break;\n" + + " } else {\n" + + " i = 0;\n" + + " }\n" + + " }\n" + + " i = 1;\n" + + " System.out.println(i);\n" + + " }\n" + + "}" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "1" /* expected output string */, + "" /* expected error string */, + JavacTestOptions.EclipseJustification.EclipseBug235546 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235550 +public void test058_definite_unassignment_try_finally() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " final int i;\n" + + " do {\n" + + " try {\n" + + " break;\n" + + " } finally {\n" + + " i = 0;\n" + + " }\n" + + " } while (args.length > 0);\n" + + " System.out.println(i);\n" + + " }\n" + + "}" + }, + // runtime result: + "0"); + // NB: javac reports: "error: variable i might be assigned in loop" + // I hold to be wrong +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235555 +public void test059_definite_unassignment_assign_in_for_condition() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " final int i;\n" + + " for (; 0 < (i = 1); i = i + 1) {\n" + + " break;\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + JavacTestOptions.JavacHasABug.JavacBug4660984 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235555 +// variant +public void test060_definite_unassignment_assign_in_for_condition() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " final int i;\n" + + " for (; 0 < (i = 1);) {\n" + + " break;\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + // runtime results + "SUCCESS" /* expected output string */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=241841 +public void test061() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " java.sql.Date d = new java.util.Date();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " java.sql.Date d = new java.util.Date();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from java.util.Date to java.sql.Date\n" + + "----------\n"); +} + +// challenge widening conversion +public void test062() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " byte b;\n" + + " short s;\n" + + " char c;\n" + + " boolean z;\n" + + " int i;\n" + + " long j;\n" + + " float f;\n" + + " double d;\n" + + "void foo() {\n" + + " boolean[] booleans = { b, s, c, z, i, j, f, d, };\n" + + " byte[] bytes = { b, s, c, z, i, j, f, d, };\n" + + " short[] shorts = { b, s, c, z, i, j, f, d, };\n" + + " char[] chars = { b, s, c, z, i, j, f, d, };\n" + + " int[] ints = { b, s, c, z, i, j, f, d, };\n" + + " long[] longs = { b, s, c, z, i, j, f, d, };\n" + + " float[] floats = { b, s, c, z, i, j, f, d, };\n" + + " double[] doubles = { b, s, c, z, i, j, f, d, };\n" + + "}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from byte to boolean\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from short to boolean\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from char to boolean\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from int to boolean\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from long to boolean\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from float to boolean\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from double to boolean\n" + + "----------\n" + + "8. ERROR in X.java (at line 12)\n" + + " byte[] bytes = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from short to byte\n" + + "----------\n" + + "9. ERROR in X.java (at line 12)\n" + + " byte[] bytes = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from char to byte\n" + + "----------\n" + + "10. ERROR in X.java (at line 12)\n" + + " byte[] bytes = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from boolean to byte\n" + + "----------\n" + + "11. ERROR in X.java (at line 12)\n" + + " byte[] bytes = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from int to byte\n" + + "----------\n" + + "12. ERROR in X.java (at line 12)\n" + + " byte[] bytes = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from long to byte\n" + + "----------\n" + + "13. ERROR in X.java (at line 12)\n" + + " byte[] bytes = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from float to byte\n" + + "----------\n" + + "14. ERROR in X.java (at line 12)\n" + + " byte[] bytes = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from double to byte\n" + + "----------\n" + + "15. ERROR in X.java (at line 13)\n" + + " short[] shorts = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from char to short\n" + + "----------\n" + + "16. ERROR in X.java (at line 13)\n" + + " short[] shorts = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from boolean to short\n" + + "----------\n" + + "17. ERROR in X.java (at line 13)\n" + + " short[] shorts = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from int to short\n" + + "----------\n" + + "18. ERROR in X.java (at line 13)\n" + + " short[] shorts = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from long to short\n" + + "----------\n" + + "19. ERROR in X.java (at line 13)\n" + + " short[] shorts = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from float to short\n" + + "----------\n" + + "20. ERROR in X.java (at line 13)\n" + + " short[] shorts = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from double to short\n" + + "----------\n" + + "21. ERROR in X.java (at line 14)\n" + + " char[] chars = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from byte to char\n" + + "----------\n" + + "22. ERROR in X.java (at line 14)\n" + + " char[] chars = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from short to char\n" + + "----------\n" + + "23. ERROR in X.java (at line 14)\n" + + " char[] chars = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from boolean to char\n" + + "----------\n" + + "24. ERROR in X.java (at line 14)\n" + + " char[] chars = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from int to char\n" + + "----------\n" + + "25. ERROR in X.java (at line 14)\n" + + " char[] chars = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from long to char\n" + + "----------\n" + + "26. ERROR in X.java (at line 14)\n" + + " char[] chars = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from float to char\n" + + "----------\n" + + "27. ERROR in X.java (at line 14)\n" + + " char[] chars = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from double to char\n" + + "----------\n" + + "28. ERROR in X.java (at line 15)\n" + + " int[] ints = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from boolean to int\n" + + "----------\n" + + "29. ERROR in X.java (at line 15)\n" + + " int[] ints = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from long to int\n" + + "----------\n" + + "30. ERROR in X.java (at line 15)\n" + + " int[] ints = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from float to int\n" + + "----------\n" + + "31. ERROR in X.java (at line 15)\n" + + " int[] ints = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from double to int\n" + + "----------\n" + + "32. ERROR in X.java (at line 16)\n" + + " long[] longs = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from boolean to long\n" + + "----------\n" + + "33. ERROR in X.java (at line 16)\n" + + " long[] longs = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from float to long\n" + + "----------\n" + + "34. ERROR in X.java (at line 16)\n" + + " long[] longs = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from double to long\n" + + "----------\n" + + "35. ERROR in X.java (at line 17)\n" + + " float[] floats = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from boolean to float\n" + + "----------\n" + + "36. ERROR in X.java (at line 17)\n" + + " float[] floats = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from double to float\n" + + "----------\n" + + "37. ERROR in X.java (at line 18)\n" + + " double[] doubles = { b, s, c, z, i, j, f, d, };\n" + + " ^\n" + + "Type mismatch: cannot convert from boolean to double\n" + + "----------\n"); +} +//challenge narrowing conversion +public void test063() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " byte b;\n" + + " short s;\n" + + " char c;\n" + + " boolean z;\n" + + " int i;\n" + + " long j;\n" + + " float f;\n" + + " double d;\n" + + "void foo() {\n" + + " boolean[] booleans = { (boolean)b, (boolean)s, (boolean)c, (boolean)z, (boolean)i, (boolean)j, (boolean)f, (boolean)d, };\n" + + " byte[] bytes = { (byte)b, (byte)s, (byte)c, (byte)z, (byte)i, (byte)j, (byte)f, (byte)d, };\n" + + " short[] shorts = { (short)b, (short)s, (short)c, (short)z, (short)i, (short)j, (short)f, (short)d, };\n" + + " char[] chars = { (char)b, (char)s, (char)c, (char)z, (char)i, (char)j, (char)f, (char)d, };\n" + + " int[] ints = { (int)b, (int)s, (int)c, (int)z, (int)i, (int)j, (int)f, (int)d, };\n" + + " long[] longs = { (long)b, (long)s, (long)c, (long)z, (long)i, (long)j, (long)f, (long)d, };\n" + + " float[] floats = { (float)b, (float)s, (float)c, (float)z, (float)i, (float)j, (float)f, (float)d, };\n" + + " double[] doubles = { (double)b, (double)s, (double)c, (double)z, (double)i, (double)j, (double)f, (double)d, };\n" + + "}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { (boolean)b, (boolean)s, (boolean)c, (boolean)z, (boolean)i, (boolean)j, (boolean)f, (boolean)d, };\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from byte to boolean\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { (boolean)b, (boolean)s, (boolean)c, (boolean)z, (boolean)i, (boolean)j, (boolean)f, (boolean)d, };\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from short to boolean\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { (boolean)b, (boolean)s, (boolean)c, (boolean)z, (boolean)i, (boolean)j, (boolean)f, (boolean)d, };\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from char to boolean\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { (boolean)b, (boolean)s, (boolean)c, (boolean)z, (boolean)i, (boolean)j, (boolean)f, (boolean)d, };\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from int to boolean\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { (boolean)b, (boolean)s, (boolean)c, (boolean)z, (boolean)i, (boolean)j, (boolean)f, (boolean)d, };\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from long to boolean\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { (boolean)b, (boolean)s, (boolean)c, (boolean)z, (boolean)i, (boolean)j, (boolean)f, (boolean)d, };\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from float to boolean\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " boolean[] booleans = { (boolean)b, (boolean)s, (boolean)c, (boolean)z, (boolean)i, (boolean)j, (boolean)f, (boolean)d, };\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from double to boolean\n" + + "----------\n" + + "8. ERROR in X.java (at line 12)\n" + + " byte[] bytes = { (byte)b, (byte)s, (byte)c, (byte)z, (byte)i, (byte)j, (byte)f, (byte)d, };\n" + + " ^^^^^^^\n" + + "Cannot cast from boolean to byte\n" + + "----------\n" + + "9. ERROR in X.java (at line 13)\n" + + " short[] shorts = { (short)b, (short)s, (short)c, (short)z, (short)i, (short)j, (short)f, (short)d, };\n" + + " ^^^^^^^^\n" + + "Cannot cast from boolean to short\n" + + "----------\n" + + "10. ERROR in X.java (at line 14)\n" + + " char[] chars = { (char)b, (char)s, (char)c, (char)z, (char)i, (char)j, (char)f, (char)d, };\n" + + " ^^^^^^^\n" + + "Cannot cast from boolean to char\n" + + "----------\n" + + "11. ERROR in X.java (at line 15)\n" + + " int[] ints = { (int)b, (int)s, (int)c, (int)z, (int)i, (int)j, (int)f, (int)d, };\n" + + " ^^^^^^\n" + + "Cannot cast from boolean to int\n" + + "----------\n" + + "12. ERROR in X.java (at line 16)\n" + + " long[] longs = { (long)b, (long)s, (long)c, (long)z, (long)i, (long)j, (long)f, (long)d, };\n" + + " ^^^^^^^\n" + + "Cannot cast from boolean to long\n" + + "----------\n" + + "13. ERROR in X.java (at line 17)\n" + + " float[] floats = { (float)b, (float)s, (float)c, (float)z, (float)i, (float)j, (float)f, (float)d, };\n" + + " ^^^^^^^^\n" + + "Cannot cast from boolean to float\n" + + "----------\n" + + "14. ERROR in X.java (at line 18)\n" + + " double[] doubles = { (double)b, (double)s, (double)c, (double)z, (double)i, (double)j, (double)f, (double)d, };\n" + + " ^^^^^^^^^\n" + + "Cannot cast from boolean to double\n" + + "----------\n"); +} +public void test064() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " byte b = (byte)1;\n" + + " b += 1;\n" + + " System.out.print(b);\n" + + " }\n" + + "}\n", + }, + "2" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=282891 +public void test065() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportComparingIdentical, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " protected boolean foo = false;\n" + + " public boolean test() {\n" + + " return foo || (foo = foo());\n" + + " }\n" + + " public boolean test2() {\n" + + " return foo && (foo = foo());\n" + + " }\n" + + " public boolean test3() {\n" + + " return foo && (foo = foo);\n" + + " }\n" + + " boolean foo() { return true; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " return foo && (foo = foo);\n" + + " ^^^^^^^^^^^\n" + + "The assignment to variable foo has no effect\n" + + "----------\n", + null, + true, + options + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=290376 +public void test066() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportComparingIdentical, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public boolean test() {\n" + + " int i = 1;\n" + + " if (i != (i = 2)) {\n" + + " System.out.println(\"The first warning is unjust.\");\n" + + " }\n" + + " if ((i = 3) != i) {\n" + + " System.out.println(\"The second warning is just.\");\n" + + " }\n" + + " return false;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if ((i = 3) != i) {\n" + + " ^^^^^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n", + null, + true, + options + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=290376 +public void test067() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportComparingIdentical, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public boolean test() {\n" + + " String s = \"Hello World\";\n" + + " if (s != (s = \"\")) {\n" + + " System.out.println(\"The first warning is unjust.\");\n" + + " }\n" + + " if ((s = \"\") != s) {\n" + + " System.out.println(\"The second warning is just.\");\n" + + " }\n" + + " return false;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if ((s = \"\") != s) {\n" + + " ^^^^^^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n", + null, + true, + options + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=362279 +public void test068() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Integer f = 'a'; // Field declaration.\n" + + " public Integer main() {\n" + + " Integer i = 'a'; // local declaration with initialization.\n" + + " i = 'a'; // assignment\n" + + " Integer [] ia = new Integer [] { 'a' }; // array initializer.\n" + + " return 'a'; // return statement.\n" + + " switch (i) {\n" + + " case 'a' : // case statement\n" + + " }\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_5 ? + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Integer f = \'a\'; // Field declaration.\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Integer i = \'a\'; // local declaration with initialization.\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " i = \'a\'; // assignment\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Integer [] ia = new Integer [] { \'a\' }; // array initializer.\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " return \'a\'; // return statement.\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " switch (i) {\n" + + " ^\n" + + "Cannot switch on a value of type Integer. Only convertible int values or enum variables are permitted\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Integer f = \'a\'; // Field declaration.\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Integer i = \'a\'; // local declaration with initialization.\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " i = \'a\'; // assignment\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Integer [] ia = new Integer [] { \'a\' }; // array initializer.\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " return \'a\'; // return statement.\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " case \'a\' : // case statement\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=480989 +public void testbug480989() { + String src = + "public abstract class Unassigned {\n" + + " public Unassigned() {}\n" + + " static class SubClass extends Unassigned {\n" + + " private final String test;\n" + + " public SubClass(String atest) { // rename\n" + + " System.out.println(this.test);\n" + + " this.test = atest;\n" + + " System.out.println(this.test);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new SubClass(\"Hello World!\");\n" + + " }\n" + + "}\n"; + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "Unassigned.java", + src + }, + "----------\n" + + "1. ERROR in Unassigned.java (at line 6)\n" + + " System.out.println(this.test);\n" + + " ^^^^\n" + + "The blank final field test may not have been initialized\n" + + "----------\n"); + } else { + this.runConformTest( + new String[] { + "Unassigned.java", + src + }, + "null\n" + + "Hello World!"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=486908 +public void testBug486908_A(){ + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runConformTest(new String[] { + "Random.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Random {\n" + + " private final List values;\n" + + " public Random() {\n" + + " values = new ArrayList<>();\n" + + " }\n" + + " public Random(Object arg) {\n" + + " if(arg instanceof Random) {\n" + + " values = ((Random)(arg)).values; //Compile error here.\n" + + " } else {\n" + + " throw new IllegalArgumentException(\"arg is not instance of Random\");\n" + + " }\n" + + " }\n" + + " public static void foo() {\n" + + " return;\n" + + " }\n" + + " public static void main(String[] args){\n" + + " foo();\n" + + " }\n" + + "}\n" + }); +} +} +public void testBug486908_B() { + this.runConformTest(new String[] { + "Sample.java", + "public class Sample {\n" + + " public final String value;\n" + + " public Sample() {\n" + + " this.value = new Sample().value;\n" + + " }\n" + + " public static void foo() {\n" + + " return;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + "}\n" + }); +} +public static Class testClass() { + return AssignmentTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest_1_5.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest_1_5.java new file mode 100644 index 0000000000..fb8a22161c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest_1_5.java @@ -0,0 +1,330 @@ +/******************************************************************************* + * Copyright (c) 2009, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class AssignmentTest_1_5 extends AbstractRegressionTest { + +public AssignmentTest_1_5(String name) { + super(name); +} +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportNoEffectAssignment, CompilerOptions.ERROR); + return options; +} +// 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[] { "test000" }; +// TESTS_NUMBERS = new int[] { 15 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test1() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer value = 4711;\n" + + " double test = 47d;\n" + + " value += test;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " value += test;\n" + + " ^^^^^^^^^^^^^\n" + + "The operator += is undefined for the argument type(s) Integer, double\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test2() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer value = 4711;\n" + + " float test = 47f;\n" + + " value += test;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " value += test;\n" + + " ^^^^^^^^^^^^^\n" + + "The operator += is undefined for the argument type(s) Integer, float\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test3() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer value = 4711;\n" + + " byte test = 47;\n" + + " value += test;\n" + + " System.out.println(value);\n" + + " }\n" + + "}", + }, + "4758"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test4() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer value = 4711;\n" + + " char test = 'a';\n" + + " value += test;\n" + + " System.out.println(value);\n" + + " }\n" + + "}", + }, + "4808"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test5() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer value = 4711;\n" + + " long test = 100L;\n" + + " value += test;\n" + + " System.out.println(value);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " value += test;\n" + + " ^^^^^^^^^^^^^\n" + + "The operator += is undefined for the argument type(s) Integer, long\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test6() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer value = 4711;\n" + + " boolean test = true;\n" + + " value += test;\n" + + " System.out.println(value);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " value += test;\n" + + " ^^^^^^^^^^^^^\n" + + "The operator += is undefined for the argument type(s) int, boolean\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test7() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer value = 4711;\n" + + " short test = 32767;\n" + + " value += test;\n" + + " System.out.println(value);\n" + + " }\n" + + "}", + }, + "37478"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test8() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int x = -8;\n" + + " x += 7.8f;\n" + + " System.out.println(x == 0 ? \"SUCCESS\" : \"FAILED\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +public void test9() { + this.runConformTest( + new String[] { + "X.java", + "class XSuper {\n" + + " T value;\n" + + "}\n" + + "public class X extends XSuper{\n" + + " public void a() {\n" + + " this.value += 1;\n" + + " this.value = this.value + 1;\n" + + " System.out.println(this.value);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " X x = new X();\n" + + " x.value = \"[\";\n" + + " x.a();\n" + + " }\n" + + "}\n", + }, + "[11"); +} +public void test10() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " int i = b++;\n" + + " System.out.print(i);\n" + + " System.out.print(b);\n" + + " }\n" + + "}\n", + }, + "12" + ); +} +public void test11() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) { \n" + + " Long _long = new Long(44);\n" + + " byte b = (byte) 1;\n" + + " char c = (char) 2;\n" + + " short s = (short) 32767;\n" + + " int i = 10;\n" + + " long l = 80L;\n" + + " _long >>>= b;\n" + + " _long <<= c;\n" + + " _long >>= s;\n" + + " _long >>>= i;\n" + + " _long = 77l;\n" + + " _long <<= l;\n" + + " System.out.println(_long);\n" + + " }\n" + + "}", + }, + "5046272" + ); +} +public void test12() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " int i = ++b;\n" + + " System.out.print(i);\n" + + " System.out.print(b);\n" + + " }\n" + + "}\n", + }, + "22" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test13() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer value = 4711;\n" + + " long test = 47L;\n" + + " value &= test;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " value &= test;\n" + + " ^^^^^^^^^^^^^\n" + + "The operator &= is undefined for the argument type(s) Integer, long\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test14() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer value = 4711;\n" + + " long test = 47L;\n" + + " value |= test;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " value |= test;\n" + + " ^^^^^^^^^^^^^\n" + + "The operator |= is undefined for the argument type(s) Integer, long\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test15() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Byte value = (byte) 1;\n" + + " value++;\n" + + " System.out.println(value);\n" + + " }\n" + + "}", + }, + "2"); +} +public static Class testClass() { + return AssignmentTest_1_5.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest_1_7.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest_1_7.java new file mode 100644 index 0000000000..a49aa3f0d1 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AssignmentTest_1_7.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2005, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class AssignmentTest_1_7 extends AbstractRegressionTest { + +public AssignmentTest_1_7(String name) { + super(name); +} +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportNoEffectAssignment, CompilerOptions.ERROR); + return options; +} +// 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[] { "test000" }; +// TESTS_NUMBERS = new int[] { 61 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); +} +/* + * no effect assignment bug + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=27235 + */ +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object o = new X();\n" + + " String s = \"ESS\";\n" + + " o += s;\n" + + " System.out.println(o);\n" + + " }\n" + + " public String toString() {\n" + + " return \"SUCC\";\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +public static Class testClass() { + return AssignmentTest_1_7.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java new file mode 100644 index 0000000000..fd54b3da70 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AutoBoxingTest.java @@ -0,0 +1,5277 @@ +/******************************************************************************* + * Copyright (c) 2005, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class AutoBoxingTest extends AbstractComparableTest { + + public AutoBoxingTest(String name) { + super(name); + } + + @Override + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_ReportAutoboxing, CompilerOptions.WARNING); + return defaultOptions; + } + + // 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[] { "test000" }; +// TESTS_NUMBERS = new int[] { 78 }; +// TESTS_RANGE = new int[] { 151, -1 }; + } + public static Test suite() { + return buildComparableTestSuite(testClass()); + } + + public static Class testClass() { + return AutoBoxingTest.class; + } + + public void test001() { // constant cases of base type -> Number + // int -> Integer + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(1);\n" + + " }\n" + + " public static void test(Integer i) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // byte -> Byte + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test((byte)127);\n" + + " }\n" + + " public static void test(Byte b) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // char -> Character + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test('b');\n" + + " }\n" + + " public static void test(Character c) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // float -> Float + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(-0.0f);\n" + + " }\n" + + " public static void test(Float f) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // double -> Double + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(0.0);\n" + + " }\n" + + " public static void test(Double d) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // long -> Long + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(Long.MAX_VALUE);\n" + + " }\n" + + " public static void test(Long l) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // short -> Short + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(Short.MAX_VALUE);\n" + + " }\n" + + " public static void test(Short s) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // boolean -> Boolean + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(false);\n" + + " }\n" + + " public static void test(Boolean b) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + } + + public void test002() { // non constant cases of base type -> Number + // int -> Integer + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int bar() {return 1;}\n" + + " public static void main(String[] s) {\n" + + " test(bar());\n" + + " }\n" + + " public static void test(Integer i) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // byte -> Byte + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static byte bar() {return 1;}\n" + + " public static void main(String[] s) {\n" + + " test(bar());\n" + + " }\n" + + " public static void test(Byte b) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // char -> Character + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static char bar() {return 'c';}\n" + + " public static void main(String[] s) {\n" + + " test(bar());\n" + + " }\n" + + " public static void test(Character c) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // float -> Float + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float bar() {return 0.0f;}\n" + + " public static void main(String[] s) {\n" + + " test(bar());\n" + + " }\n" + + " public static void test(Float f) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // double -> Double + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static double bar() {return 0.0;}\n" + + " public static void main(String[] s) {\n" + + " test(bar());\n" + + " }\n" + + " public static void test(Double d) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // long -> Long + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static long bar() {return 0;}\n" + + " public static void main(String[] s) {\n" + + " test(bar());\n" + + " }\n" + + " public static void test(Long l) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // short -> Short + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static short bar() {return 0;}\n" + + " public static void main(String[] s) {\n" + + " test(bar());\n" + + " }\n" + + " public static void test(Short s) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // boolean -> Boolean + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static boolean bar() {return true;}\n" + + " public static void main(String[] s) {\n" + + " test(bar());\n" + + " }\n" + + " public static void test(Boolean b) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + } + + public void test003() { // Number -> base type + // Integer -> int + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(new Integer(1));\n" + + " }\n" + + " public static void test(int i) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // Byte -> byte + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(new Byte((byte) 1));\n" + + " }\n" + + " public static void test(byte b) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // Byte -> long + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(new Byte((byte) 1));\n" + + " }\n" + + " public static void test(long l) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // Character -> char + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(new Character('c'));\n" + + " }\n" + + " public static void test(char c) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // Float -> float + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(new Float(0.0f));\n" + + " }\n" + + " public static void test(float f) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // Double -> double + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(new Double(0.0));\n" + + " }\n" + + " public static void test(double d) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // Long -> long + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(new Long(0L));\n" + + " }\n" + + " public static void test(long l) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // Short -> short + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(new Short((short) 0));\n" + + " }\n" + + " public static void test(short s) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + // Boolean -> boolean + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " test(Boolean.TRUE);\n" + + " }\n" + + " public static void test(boolean b) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + } + + public void test004() { // autoboxing method is chosen over private exact match & visible varargs method + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.test(1);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " private static void test(int i) { System.out.print('n'); }\n" + + " static void test(int... i) { System.out.print('n'); }\n" + + " public static void test(Integer i) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Y().test(1);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " private void test(int i) { System.out.print('n'); }\n" + + " void test(int... i) { System.out.print('n'); }\n" + + " public void test(Integer i) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + } + + public void test005() { // this is NOT an ambiguous case as 'long' is matched before autoboxing kicks in + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Y().test(1);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " void test(Integer i) { System.out.print('n'); }\n" + + " void test(long i) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + } + + public void test006() { + this.runNegativeTest( // Integers are not compatible with Longs, even though ints are compatible with longs + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Y().test(1, 1);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " void test(Long i, int j) { System.out.print('n'); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new Y().test(1, 1);\n" + + " ^^^^\n" + + "The method test(Long, int) in the type Y is not applicable for the arguments (int, int)\n" + + "----------\n" + // test(java.lang.Long,int) in Y cannot be applied to (int,int) + ); + this.runNegativeTest( // likewise with Byte and Integer + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Y().test((byte) 1, 1);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " void test(Integer i, int j) { System.out.print('n'); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new Y().test((byte) 1, 1);\n" + + " ^^^^\n" + + "The method test(Integer, int) in the type Y is not applicable for the arguments (byte, int)\n" + + "----------\n" + // test(java.lang.Integer,int) in Y cannot be applied to (byte,int) + ); + } + + public void test007() { + this.runConformTest( // this is NOT an ambiguous case as Long is not a match for int + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Y().test(1, 1);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " void test(Long i, int j) { System.out.print('n'); }\n" + + " void test(long i, Integer j) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + } + + public void test008() { // test autoboxing AND varargs method match + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.test(1, new Integer(2), -3);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static void test(int ... i) { System.out.print('y'); }\n" + + "}\n", + }, + "y" + ); + } + + public void test009() { + this.runNegativeTest( // 2 of these sends are ambiguous + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public static void main(String[] s) {\n" + + " new Y().test(1, 1);\n" + // reference to test is ambiguous, both method test(java.lang.Integer,int) in Y and method test(int,java.lang.Integer) in Y match + " new Y().test(Integer.valueOf(1), Integer.valueOf(1));\n" + // reference to test is ambiguous + " }\n" + + "}\n" + + "class Y {\n" + + " void test(Integer i, int j) {}\n" + + " void test(int i, Integer j) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new Y().test(1, 1);\n" + + " ^^^^\n" + + "The method test(Integer, int) is ambiguous for the type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " new Y().test(Integer.valueOf(1), Integer.valueOf(1));\n" + + " ^^^^\n" + + "The method test(Integer, int) is ambiguous for the type Y\n" + + "----------\n" + ); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Y().test(new Integer(1), 1);\n" + + " new Y().test(1, new Integer(1));\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " void test(Integer i, int j) { System.out.print(1); }\n" + + " void test(int i, Integer j) { System.out.print(2); }\n" + + "}\n", + }, + "12" + ); + } + + public void test010() { // local declaration assignment tests + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " int i = Y.test();\n" + + " System.out.print(i);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static Byte test() { return new Byte((byte) 1); }\n" + + "}\n", + }, + "1" + ); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Object o = Y.test();\n" + + " System.out.print(o);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static int test() { return 1; }\n" + + "}\n", + }, + "1" + ); + } + + public void test011() { // field declaration assignment tests + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int i = Y.test();\n" + + " public static void main(String[] s) {\n" + + " System.out.print(i);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static Byte test() { return new Byte((byte) 1); }\n" + + "}\n", + }, + "1" + ); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static Object o = Y.test();\n" + + " public static void main(String[] s) {\n" + + " System.out.print(o);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static int test() { return 1; }\n" + + "}\n", + }, + "1" + ); + } + + public void test012() { // varargs and autoboxing + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer x = new Integer(15); \n" + + " int y = 32;\n" + + " System.out.printf(\"%x + %x\", x, y);\n" + + " }\n" + + "}", + }, + "f + 20" + ); + } + + public void test013() { // foreach and autoboxing + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + " for (final Integer e : tab) {\n" + + " System.out.print(e);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "123456789" + ); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer[] tab = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + " for (final int e : tab) {\n" + + " System.out.print(e);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "123456789" + ); + } + + public void test014() { // switch + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Integer i = new Integer(1);\n" + + " switch(i) {\n" + + " case 1 : System.out.print('y');\n" + + " }\n" + + " }\n" + + "}\n", + }, + "y" + ); + } + + public void test015() { // return statement + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static Integer foo1() {\n" + + " return 0;\n" + + " }\n" + + " static int foo2() {\n" + + " return new Integer(0);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(foo1());\n" + + " System.out.println(foo2());\n" + + " }\n" + + "}\n", + }, + "00" + ); + } + + public void test016() { // conditional expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer i = args.length == 0 ? 0 : new Integer(1);\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "0" + ); + } + + public void test017() { // cast expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer i = new Integer(1);\n" + + " System.out.println((int)i);\n" + + " }\n" + + "}\n", + }, + "1" + ); + } + + public void test018() { // cast expression + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public static void main(String[] args) {\n" + + " Float f = args.length == 0 ? Float.valueOf(0) : 0;\n" + + " System.out.println((int)f);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Float f = args.length == 0 ? Float.valueOf(0) : 0;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type float is boxed into Float\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Float f = args.length == 0 ? Float.valueOf(0) : 0;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The expression of type Float is unboxed into float\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " System.out.println((int)f);\n" + + " ^^^^^^\n" + + "Cannot cast from Float to int\n" + + "----------\n"); + } + + public void test019() { // cast expression + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println((Integer) 0);\n" + + " System.out.println((Float) 0);\n" + + " \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " System.out.println((Integer) 0);\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " System.out.println((Float) 0);\n" + + " ^^^^^^^^^\n" + + "Cannot cast from int to Float\n" + + "----------\n"); + } + + public void test020() { // binary expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " System.out.println(2 + b);\n" + + " }\n" + + "}\n", + }, + "3" + ); + } + + public void test021() { // unary expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " Integer i = +b + (-b);\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "0" + ); + } + + public void test022() { // unary expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " Integer i = 0;\n" + + " int n = b + i;\n" + + " System.out.println(n);\n" + + " }\n" + + "}\n", + }, + "1" + ); + } + + public void test023() { // 78849 + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Character cValue = new Character('c');\n" + + " if ('c' == cValue) System.out.println('y');\n" + + " }\n" + + "}\n", + }, + "y" + ); + } + + public void test024() { // 79254 + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) { test(2); }\n" + + " static void test(Object o) { System.out.println('y'); }\n" + + "}\n", + }, + "y" + ); + } + + public void test025() { // 79641 + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) { test(true); }\n" + + " static void test(Object ... o) { System.out.println('y'); }\n" + + "}\n", + }, + "y" + ); + } + + public void test026() { // compound assignment + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " Integer i = 0;\n" + + " i += b;\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "1" + ); + } + + public void test027() { // equal expression + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " if (0 == new X()) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (0 == new X()) {\n" + + " ^^^^^^^^^^^^\n" + + "Incompatible operand types int and X\n" + + "----------\n" + ); + } + + public void test028() { // unary expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " int i = +b;\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "1" + ); + } + + public void test029() { // generic type case + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " for (int i = 0; i < 5; i++) {\n" + + " list.add(i);\n" + + " }\n" + + " int sum = 0;\n" + + " for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {\n" + + " sum += iterator.next();\n" + + " }\n" + + " System.out.print(sum);\n" + + " }\n" + + "}", + }, + "10" + ); + } + + public void test030() { // boolean expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Boolean b = Boolean.TRUE;\n" + + " \n" + + " if (b && !b) {\n" + + " System.out.print(\"THEN\");\n" + + " } else {\n" + + " System.out.print(\"ELSE\");\n" + + " }\n" + + " }\n" + + "}", + }, + "ELSE" + ); + } + + public void test031() { // boolean expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Boolean foo() { return Boolean.FALSE; }\n" + + " public static void main(String[] args) {\n" + + " Boolean b = foo();\n" + + " \n" + + " if (!b) {\n" + + " System.out.print(\"THEN\");\n" + + " } else {\n" + + " System.out.print(\"ELSE\");\n" + + " }\n" + + " }\n" + + "}", + }, + "THEN" + ); + } + + public void test032() throws Exception { // boolean expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (new Integer(1) == new Integer(0)) {\n" + + " System.out.println();\n" + + " }\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS" + ); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new java.lang.Integer [16]\n" + + " 3 dup\n" + + " 4 iconst_1\n" + + " 5 invokespecial java.lang.Integer(int) [18]\n" + + " 8 new java.lang.Integer [16]\n" + + " 11 dup\n" + + " 12 iconst_0\n" + + " 13 invokespecial java.lang.Integer(int) [18]\n" + + " 16 if_acmpne 25\n" + + " 19 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 22 invokevirtual java.io.PrintStream.println() : void [27]\n" + + " 25 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 28 ldc [32]\n" + + " 30 invokevirtual java.io.PrintStream.print(java.lang.String) : void [34]\n" + + " 33 return\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test033() { // boolean expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print(Boolean.TRUE || Boolean.FALSE);\n" + + " }\n" + + "}", + }, + "true" + ); + } + + public void test034() { // postfix expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " int i = b++;\n" + + " System.out.print(i);\n" + + " System.out.print(b);\n" + + " }\n" + + "}\n", + }, + "12" + ); + } + + public void test035() { // postfix expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " int i = b--;\n" + + " System.out.print(i);\n" + + " System.out.print(b);\n" + + " }\n" + + "}\n", + }, + "10" + ); + } + + public void test036() { // prefix expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " int i = ++b;\n" + + " System.out.print(i);\n" + + " System.out.print(b);\n" + + " }\n" + + "}\n", + }, + "22" + ); + } + + public void test037() { // prefix expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Byte b = new Byte((byte)1);\n" + + " int i = --b;\n" + + " System.out.print(i);\n" + + " System.out.print(b);\n" + + " }\n" + + "}\n", + }, + "00" + ); + } + + public void test038() { // boolean expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static boolean foo() { return false; }\n" + + " public static void main(String[] s) {\n" + + " boolean b = foo();\n" + + " System.out.print(b || Boolean.FALSE);\n" + + " }\n" + + "}", + }, + "false" + ); + } + + public void test039() { // equal expression + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int i = 0;\n" + + " if (i != null) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (i != null) {\n" + + " ^^^^^^^^^\n" + + "The operator != is undefined for the argument type(s) int, null\n" + + "----------\n" + ); + } + + public void test040() { // boolean expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Integer i = new Integer(1);\n" + + " if (i == null)\n" + + " i++;\n" + + " System.out.print(i);\n" + + " }\n" + + "}", + }, + "1" + ); + } + + public void test041() { // equal expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer i = 0;\n" + + " if (i != null) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS" + ); + } + + public void test042() { // conditional expression + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Boolean bar() { return Boolean.TRUE; } \n" + + " public static void main(String[] args) {\n" + + " Integer i = bar() ? new Integer(1) : null;\n" + + " int j = i;\n" + + " System.out.print(j);\n" + + " }\n" + + "}", + }, + "1" + ); + } + + public void test043() { // compound assignment + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer i = 0;\n" + + " i += \"aaa\";\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Integer i = 0;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " i += \"aaa\";\n" + + " ^^^^^^^^^^\n" + + "The operator += is undefined for the argument type(s) Integer, String\n" + + "----------\n"); + } + + public void test044() { // compound assignment + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer i = 0;\n" + + " i += null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Integer i = 0;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " i += null;\n" + + " ^^^^^^^^^\n" + + "The operator += is undefined for the argument type(s) Integer, null\n" + + "----------\n"); + } + + public void test045() { // binary expression + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer i = 0;\n" + + " i = i + null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Integer i = 0;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " i = i + null;\n" + + " ^^^^^^^^\n" + + "The operator + is undefined for the argument type(s) Integer, null\n" + + "----------\n"); + } + + public void test046() { // postfix increment + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Byte b = new Byte((byte)1);\n" + + " b++;\n" + + " System.out.println((Byte)b);\n" + + " }\n" + + "}\n", + }, + "2"); + } + + public void test047() { // postfix increment + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Byte b = new Byte((byte)1);\n" + + " b++;\n" + + " if (b instanceof Byte) {\n" + + " System.out.println(\"SUCCESS\" + b);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS2"); + } + + public void test048() { // postfix increment + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Byte b = new Byte((byte)1);\n" + + " public static void main(String[] s) {\n" + + " b++;\n" + + " if (b instanceof Byte) {\n" + + " System.out.print(\"SUCCESS\" + b);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS2"); + } + + public void test049() { // postfix increment + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static class Y {\n" + + " public static Byte b = new Byte((byte)1);\n" + + " }\n" + + " public static void main(String[] s) {\n" + + " X.Y.b++;\n" + + " if (X.Y.b instanceof Byte) {\n" + + " System.out.print(\"SUCCESS\" + X.Y.b);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS2"); + } + + public void test050() { // prefix increment + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Byte b = new Byte((byte)1);\n" + + " public static void main(String[] s) {\n" + + " ++b;\n" + + " if (b instanceof Byte) {\n" + + " System.out.print(\"SUCCESS\" + b);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS2"); + } + + public void test051() { // prefix increment + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static class Y {\n" + + " public static Byte b = new Byte((byte)1);\n" + + " }\n" + + " public static void main(String[] s) {\n" + + " ++X.Y.b;\n" + + " if (X.Y.b instanceof Byte) {\n" + + " System.out.print(\"SUCCESS\" + X.Y.b);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS2"); + } + + public void test052() { // boxing in var decl + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Byte b = 0;\n" + + " ++b;\n" + + " foo(0);\n" + + " }\n" + + " static void foo(Byte b) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Byte b = 0;\n" + + " ^\n" + + "The expression of type int is boxed into Byte\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " ++b;\n" + + " ^^^\n" + + "The expression of type byte is boxed into Byte\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " ++b;\n" + + " ^\n" + + "The expression of type Byte is unboxed into int\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " foo(0);\n" + + " ^^^\n" + + "The method foo(Byte) in the type X is not applicable for the arguments (int)\n" + + "----------\n"); + } + + public void test053() { // boxing in var decl + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Byte b = 1;\n" + + " ++b;\n" + + " if (b instanceof Byte) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test054() { // boxing in field decl + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static Byte b = 1;\n" + + " public static void main(String[] s) {\n" + + " ++b;\n" + + " if (b instanceof Byte) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test055() { // boxing in foreach + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " byte[] bytes = {0, 1, 2};\n" + + " for(Integer i : bytes) {\n" + + " System.out.print(i);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for(Integer i : bytes) {\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from element type byte to Integer\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " for(Integer i : bytes) {\n" + + " ^^^^^\n" + + "The expression of type byte is boxed into Integer\n" + + "----------\n"); + } + + public void test056() { // boxing in foreach + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " int[] ints = {0, 1, 2};\n" + + " for(Integer i : ints) {\n" + + " System.out.print(i);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "012"); + } + + public void test057() { // boxing in foreach + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " byte[] bytes = {0, 1, 2};\n" + + " for(Byte b : bytes) {\n" + + " System.out.print(b);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "012"); + } + + public void test058() { // autoboxing and generics + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " for (int i = 0; i < 5; i++) {\n" + + " list.add(i);\n" + + " }\n" + + " int sum = 0;\n" + + " for (Integer i : list) {\n" + + " sum += i;\n" + + " } \n" + + " System.out.print(sum);\n" + + " }\n" + + "}\n", + }, + "10"); + } + + public void test059() { // autoboxing and generics + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " for (int i = 0; i < 5; i++) {\n" + + " list.add(i);\n" + + " }\n" + + " int sum = 0;\n" + + " for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {\n" + + " if (1 == iterator.next()) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test060() { // autoboxing and boolean expr + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " for (int i = 0; i < 5; i++) {\n" + + " list.add(i % 2 == 0);\n" + + " }\n" + + " for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {\n" + + " if (iterator.next()) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test061() { // autoboxing and boolean expr + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " boolean b = true;\n" + + " for (int i = 0; i < 5; i++) {\n" + + " list.add((i % 2 == 0) && b);\n" + + " }\n" + + " for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {\n" + + " if (iterator.next()) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test062() { // autoboxing and generics + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " boolean b = true;\n" + + " for (int i = 0; i < 5; i++) {\n" + + " list.add(i);\n" + + " }\n" + + " int sum = 0;\n" + + " for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {\n" + + " sum = sum + iterator.next();\n" + + " }\n" + + " System.out.println(sum);\n" + + " }\n" + + "}\n", + }, + "10"); + } + + public void test063() { // autoboxing and generics + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " boolean b = true;\n" + + " for (int i = 0; i < 5; i++) {\n" + + " list.add(i);\n" + + " }\n" + + " int val = 0;\n" + + " for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {\n" + + " val = ~ iterator.next();\n" + + " }\n" + + " System.out.println(val);\n" + + " }\n" + + "}\n", + }, + "-5"); + } + + public void test064() { // autoboxing and generics + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " boolean b = true;\n" + + " for (int i = 0; i < 5; i++) {\n" + + " list.add(i);\n" + + " }\n" + + " int val = 0;\n" + + " for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {\n" + + " val += (int) iterator.next();\n" + + " }\n" + + " System.out.println(val);\n" + + " }\n" + + "}\n", + }, + "10"); + } + + public void test065() { // generic type case + foreach statement + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " for (int i = 0; i < 5; i++) {\n" + + " list.add(i);\n" + + " }\n" + + " int sum = 0;\n" + + " for (int i : list) {\n" + + " sum += i;\n" + + " }\n" + + " System.out.print(sum);\n" + + " }\n" + + "}", + }, + "10" + ); + } + + public void test066() { // array case + foreach statement + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer[] tab = new Integer[] {0, 1, 2, 3, 4};\n" + + " int sum = 0;\n" + + " for (int i : tab) {\n" + + " sum += i;\n" + + " }\n" + + " System.out.print(sum);\n" + + " }\n" + + "}", + }, + "10" + ); + } + + public void test067() { // array case + foreach statement + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] {0, 1, 2, 3, 4};\n" + + " int sum = 0;\n" + + " for (Integer i : tab) {\n" + + " sum += i;\n" + + " }\n" + + " System.out.print(sum);\n" + + " }\n" + + "}", + }, + "10" + ); + } + + public void test068() { // generic type case + foreach statement + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " for (int i = 0; i < 5; i++) {\n" + + " list.add(i);\n" + + " }\n" + + " int sum = 0;\n" + + " for (Integer i : list) {\n" + + " sum += i;\n" + + " }\n" + + " System.out.print(sum);\n" + + " }\n" + + "}", + }, + "10" + ); + } + + public void test069() { // assert + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Boolean bool = true;\n" + + " assert bool : \"failed\";\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test070() { // assert + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List lb = new ArrayList();\n" + + " lb.add(true);\n" + + " Iterator iterator = lb.iterator();\n" + + " assert iterator.next() : \"failed\";\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test071() { // assert + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List lb = new ArrayList();\n" + + " lb.add(true);\n" + + " Iterator iterator = lb.iterator();\n" + + " assert args != null : iterator.next();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81971 + public void test072() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " doFoo(getVoid());\n" + + " }\n" + + "\n" + + " private static void doFoo(Object o) { }\n" + + "\n" + + " private static void getVoid() { }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " doFoo(getVoid());\n" + + " ^^^^^\n" + + "The method doFoo(Object) in the type X is not applicable for the arguments (void)\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81571 + public void test073() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public static void main(String[] args) {\n" + + " a(Integer.valueOf(1), 2);\n" + + " }\n" + + " public static void a(int a, int b) { System.out.println(\"SUCCESS\"); }\n" + + " public static void a(Object a, Object b) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " a(Integer.valueOf(1), 2);\n" + + " ^\n" + + "The method a(int, int) is ambiguous for the type X\n" + + "----------\n" + // a is ambiguous, both method a(int,int) in X and method a(java.lang.Object,java.lang.Object) in X match + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82432 + public void test074() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object e() {\n" + + " return \"\".compareTo(\"\") > 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new X().e());\n" + + " }\n" + + "}", + }, + "false"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82432 - variation + public void test075() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object e() {\n" + + " return \"\".compareTo(\"\") > 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new X().e());\n" + + " }\n" + + " Zork z;\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return \"\".compareTo(\"\") > 0;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "2. 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=82432 - variation + public void test076() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object e() {\n" + + " int i = 12; \n" + + " boolean b = false;\n" + + " switch(i) {\n" + + " case 0: return i > 0;\n" + + " case 1: return i >= 0;\n" + + " case 2: return i < 0;\n" + + " case 3: return i <= 0;\n" + + " case 4: return i == 0;\n" + + " case 5: return i != 0;\n" + + " case 6: return i & 0;\n" + + " case 7: return i ^ 0;\n" + + " case 8: return i | 0;\n" + + " case 9: return b && b;\n" + + " default: return b || b;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new X().e());\n" + + " }\n" + + " Zork z;\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " case 0: return i > 0;\n" + + " ^^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " case 1: return i >= 0;\n" + + " ^^^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " case 2: return i < 0;\n" + + " ^^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " case 3: return i <= 0;\n" + + " ^^^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " case 4: return i == 0;\n" + + " ^^^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "6. WARNING in X.java (at line 11)\n" + + " case 5: return i != 0;\n" + + " ^^^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " case 6: return i & 0;\n" + + " ^^^^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "8. WARNING in X.java (at line 13)\n" + + " case 7: return i ^ 0;\n" + + " ^^^^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "9. WARNING in X.java (at line 14)\n" + + " case 8: return i | 0;\n" + + " ^^^^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "10. WARNING in X.java (at line 15)\n" + + " case 9: return b && b;\n" + + " ^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "11. WARNING in X.java (at line 15)\n" + + " case 9: return b && b;\n" + + " ^^^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "12. WARNING in X.java (at line 16)\n" + + " default: return b || b;\n" + + " ^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "13. WARNING in X.java (at line 16)\n" + + " default: return b || b;\n" + + " ^^^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "14. ERROR in X.java (at line 22)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82432 - variation + public void test077() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object e() {\n" + + " int i = 12; \n" + + " boolean b = false;\n" + + " switch(i) {\n" + + " case 0: return i > 0;\n" + + " case 1: return i >= 0;\n" + + " case 2: return i < 0;\n" + + " case 3: return i <= 0;\n" + + " case 4: return i == 0;\n" + + " case 5: return i != 0;\n" + + " case 6: return i & 0;\n" + + " case 7: return i ^ 0;\n" + + " case 8: return i | 0;\n" + + " case 9: return b && b;\n" + + " default: return b || b;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new X().e());\n" + + " }\n" + + "}", + }, + "false"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81923 + public void test078() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(A... t) {}\n" + + " void foo(T... t) {}\n" + + " void zip(T t) {}\n" + + " void test() {\n" + + " new X(10, 20);\n" + + " foo(10);\n" + + " foo(10, 20);\n" + + " zip(10);\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82407 + public void _test079() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "public class X {\n" + + " static HashMap substitutionList(String s1, String s2) {\n" + + " HashMap subst = new HashMap();\n" + + " for (int i = 0; i < s1.length(); i++) {\n" + + " char key = s1.charAt(i);\n" + + " char value = s2.charAt(i);\n" + + " if (subst.containsKey(key)) {\n" + + " if (value != subst.get(key)) {\n" + + " return null;\n" + + " }\n" + + " } else if (subst.containsValue(value)) {\n" + + " return null;\n" + + " } else {\n" + + " subst.put(key, value);\n" + + " }\n" + + " }\n" + + " return subst;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Bogon\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82407 - variation + public void test080() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " HashMap subst = new HashMap();\n" + + " subst.put(\'a\', \'a\');\n" + + " if (\'a\' == subst.get(\'a\')) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82407 - variation + public void test081() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " HashMap subst = new HashMap();\n" + + " subst.put((byte)1, (byte)1);\n" + + " if (1 + subst.get((byte)1) > 0.f) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82859 + public void test082() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(void.class == Void.TYPE);\n" + + " }\n" + + "}" + }, + "true" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82647 + public void test083() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int counter = 0;\n" + + "\n" + + " public boolean wasNull() {\n" + + " return ++counter % 2 == 0;\n" + + " }\n" + + "\n" + + " private Byte getByte() {\n" + + " return (byte) 0;\n" + + " }\n" + + "\n" + + " private Short getShort() {\n" + + " return (short) 0;\n" + + " }\n" + + "\n" + + " private Long getLong() {\n" + + " return 0L;\n" + + " }\n" + + "\n" + + " private Integer getInt() {\n" + + " return 0; // autoboxed okay\n" + + " }\n" + + "\n" + + " // This should be the same as the second one.\n" + + " private Byte getBytey() {\n" + + " byte value = getByte();\n" + + " return wasNull() ? null : value;\n" + + " }\n" + + "\n" + + " private Byte getByteyNoBoxing() {\n" + + " byte value = getByte();\n" + + " return wasNull() ? null : (Byte) value;\n" + + " }\n" + + "\n" + + " // This should be the same as the second one.\n" + + " private Short getShorty() {\n" + + " short value = getShort();\n" + + " return wasNull() ? null : value;\n" + + " }\n" + + "\n" + + " private Short getShortyNoBoxing() {\n" + + " short value = getShort();\n" + + " return wasNull() ? null : (Short) value;\n" + + " }\n" + + "\n" + + " // This should be the same as the second one.\n" + + " private Long getLongy() {\n" + + " long value = getLong();\n" + + " return wasNull() ? null : value;\n" + + " }\n" + + "\n" + + " private Long getLongyNoBoxing() {\n" + + " long value = getLong();\n" + + " return wasNull() ? null : (Long) value;\n" + + " }\n" + + "\n" + + " // This should be the same as the second one.\n" + + " private Integer getIntegery() {\n" + + " int value = getInt();\n" + + " return wasNull() ? null : value;\n" + + " }\n" + + "\n" + + " private Integer getIntegeryNoBoxing() {\n" + + " int value = getInt();\n" + + " return wasNull() ? null : (Integer) value;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82647 - variation + public void test084() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Short foo() {\n" + + " short value = 0;\n" + + " return this == null ? null : value;\n" + + " }\n" + + " boolean bar() {\n" + + " short value = 0;\n" + + " return null == value;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return this == null ? null : value;\n" + + " ^^^^^\n" + + "The expression of type short is boxed into Short\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return null == value;\n" + + " ^^^^^^^^^^^^^\n" + + "The operator == is undefined for the argument type(s) null, short\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83965 + public void test085() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " private static void checkByteConversions(Byte _byte) {\n" + + " short s = (short) _byte;\n" + + " short s2 = _byte;\n" + + " int i = (int) _byte;\n" + + " long l = (long) _byte;\n" + + " float f = (float) _byte;\n" + + " double d = (double) _byte;\n" + + " if ( _byte.byteValue() != s ) {\n" + + " System.err.println(\"Must be equal 0\");\n" + + " }\n" + + " if ( _byte.byteValue() != i ) {\n" + + " System.err.println(\"Must be equal 1\");\n" + + " }\n" + + " if ( _byte.byteValue() != l ) {\n" + + " System.err.println(\"Must be equal 2\");\n" + + " }\n" + + " if ( _byte.byteValue() != f ) {\n" + + " System.err.println(\"Must be equal 3\");\n" + + " }\n" + + " if ( _byte.byteValue() != d ) {\n" + + " System.err.println(\"Must be equal 4\");\n" + + " }\n" + + " } \n" + + "\n" + + " private static void checkCharacterConversions(Character _character) {\n" + + " int i = (int) _character;\n" + + " long l = (long) _character;\n" + + " float f = (float) _character;\n" + + " double d = (double) _character;\n" + + " if ( _character.charValue() != i ) {\n" + + " System.err.println(\"Must be equal 9\");\n" + + " }\n" + + " if ( _character.charValue() != l ) {\n" + + " System.err.println(\"Must be equal 10\");\n" + + " }\n" + + " if ( _character.charValue() != f ) {\n" + + " System.err.println(\"Must be equal 11\");\n" + + " }\n" + + " if ( _character.charValue() != d ) {\n" + + " System.err.println(\"Must be equal 12\");\n" + + " }\n" + + " }\n" + + "\n" + + " private static void checkFloatConversions(Float _float) {\n" + + " double d = (double) _float;\n" + + " if ( _float.floatValue() != d ) {\n" + + " System.err.println(\"Must be equal 18\");\n" + + " }\n" + + " }\n" + + "\n" + + " private static void checkIntegerConversions(Integer _integer) {\n" + + " long l = (long) _integer;\n" + + " float f = (float) _integer;\n" + + " double d = (double) _integer;\n" + + " if ( _integer.intValue() != l ) {\n" + + " System.err.println(\"Must be equal 13\");\n" + + " }\n" + + " if ( _integer.intValue() != f ) {\n" + + " System.err.println(\"Must be equal 14\");\n" + + " }\n" + + " if ( _integer.intValue() != d ) {\n" + + " System.err.println(\"Must be equal 15\");\n" + + " }\n" + + " }\n" + + "\n" + + " private static void checkIntegerConversions(Short _short) {\n" + + " int i = (int) _short;\n" + + " long l = (long) _short;\n" + + " float f = (float) _short;\n" + + " double d = (double) _short;\n" + + " if ( _short.shortValue() != i ) {\n" + + " System.err.println(\"Must be equal 5\");\n" + + " }\n" + + " if ( _short.shortValue() != l ) {\n" + + " System.err.println(\"Must be equal 6\");\n" + + " }\n" + + " if ( _short.shortValue() != f ) {\n" + + " System.err.println(\"Must be equal 7\");\n" + + " }\n" + + " if ( _short.shortValue() != d ) {\n" + + " System.err.println(\"Must be equal 8\");\n" + + " }\n" + + " }\n" + + "\n" + + " private static void checkLongConversions(Long _long) {\n" + + " float f = (float) _long;\n" + + " double d = (double) _long;\n" + + " if ( _long.longValue() != f ) {\n" + + " System.err.println(\"Must be equal 16\");\n" + + " }\n" + + " if ( _long.longValue() != d ) {\n" + + " System.err.println(\"Must be equal 17\");\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String args[]) {\n" + + " Byte _byte = new Byte((byte)2);\n" + + " Character _character = new Character(\'@\');\n" + + " Short _short = new Short((short)255);\n" + + " Integer _integer = new Integer(12345678);\n" + + " Long _long = new Long(1234567890);\n" + + " Float _float = new Float(-0.0);\n" + + "\n" + + " checkByteConversions(_byte);\n" + + " checkIntegerConversions(_short);\n" + + " checkCharacterConversions(_character);\n" + + " checkIntegerConversions(_integer);\n" + + " checkLongConversions(_long);\n" + + " checkFloatConversions(_float);\n" + + "\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84055 + public void test086() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static void checkConversions(byte _byte) {\n" + + " Short s = (short) _byte; // cast is necessary\n" + + " Short s2 = _byte; // ko\n" + + " } \n" + + " public static void main(String args[]) {\n" + + " byte _byte = 2;\n" + + " checkConversions(_byte);\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Short s = (short) _byte; // cast is necessary\n" + + " ^^^^^^^^^^^^^\n" + + "The expression of type short is boxed into Short\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Short s2 = _byte; // ko\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from byte to Short\n" + + "----------\n" + ); + } + // autoboxing and type argument inference + public void test087() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(T t) { return t; }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int i = new X().foo(12);\n" + + " System.out.println(i);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " int i = new X().foo(12);\n" + + " ^^^^^^^^^^^^^^^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " int i = new X().foo(12);\n" + + " ^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + ); + } + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=84480 - variation with autoboxing diagnosis on + */ + public void test088() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportAutoboxing, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int f;\n" + + " void foo(int i) {\n" + + " i = i++;\n" + + " i = ++i;\n" + + " f = f++;\n" + + " f = ++f;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " i = ++i;\n" + + " ^^^^^^^\n" + + "The assignment to variable i has no effect\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " f = ++f;\n" + + " ^^^^^^^\n" + + "The assignment to variable f has no effect\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, + customOptions); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84345 + public void test089() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public Object foo() {\n" + + " byte b = 0;\n" + + " Number n = (Number) b;\n" + + "\n" + + " java.io.Serializable o = null;\n" + + " if (o == 0) return o;\n" + + " return this;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Number n = (Number) b;\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from byte to Number\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Number n = (Number) b;\n" + + " ^\n" + + "The expression of type byte is boxed into Byte\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " if (o == 0) return o;\n" + + " ^^^^^^\n" + + "Incompatible operand types Serializable and int\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84345 - variation + public void test090() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public Object foo() {\n" + + " \n" + + " Boolean b = null;\n" + + " if (b == true) return b;\n" + + " Object o = null;\n" + + " if (o == true) return o;\n" + + " return this;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " if (b == true) return b;\n" + + " ^\n" + + "The expression of type Boolean is unboxed into boolean\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " if (o == true) return o;\n" + + " ^^^^^^^^^\n" + + "Incompatible operand types Object and boolean\n" + + "----------\n" + ); + } + + // type argument inference and autoboxing + public void test091() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Comparable c1 = foo(\"\", new Integer(5));\n" + + " Object o = foo(\"\", 5);\n" + + " }\n" + + " public static T foo(T t1, T t2) { \n" + + " System.out.print(\"foo(\"+t1.getClass().getSimpleName()+\",\"+t2.getClass().getSimpleName()+\")\");\n" + + " return null; \n" + + " }\n" + + "}\n" + }, + "foo(String,Integer)foo(String,Integer)" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84669 + public void test092() { + this.runConformTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " public X()\n" + + " {\n" + + " super();\n" + + " }\n" + + "\n" + + " public Object convert(Object value)\n" + + " {\n" + + " Double d = (Double)value;\n" + + " d = (d/100);\n" + + " return d;\n" + + " }\n" + + "\n" + + " public static void main(String[] args)\n" + + " {\n" + + " X test = new X();\n" + + " Object value = test.convert(new Double(50));\n" + + " System.out.println(value);\n" + + " }\n" + + "}\n" + }, + "0.5" + ); + } + + public void test093() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer someInteger = 12;\n" + + " System.out.println((args == null ? someInteger : \'A\') == \'A\');\n" + + " }\n" + + "}\n" + }, + "true" + ); + } + + public void test094() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer someInteger = 12;\n" + + " System.out.println((args == null ? someInteger : \'A\') == \'A\');\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Integer someInteger = 12;\n" + + " ^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " System.out.println((args == null ? someInteger : \'A\') == \'A\');\n" + + " ^^^^^^^^^^^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "3. 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=80630 + public void test095() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean b = true;\n" + + " Character _Character = new Character(\' \');\n" + + " char c = \' \';\n" + + " Integer _Integer = new Integer(2);\n" + + " if ((b ? _Character : _Integer) == c) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } else {\n" + + " System.out.println(\"FAILURE\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80630 - variation + public void test096() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public static void main(String[] args) {\n" + + " boolean b = true;\n" + + " Character _Character = Character.valueOf(\' \');\n" + + " char c = \' \';\n" + + " Integer _Integer = Integer.valueOf(2);\n" + + " if ((b ? _Character : _Integer) == c) {\n" + + " System.out.println(zork);\n" + + " } else {\n" + + " System.out.println(\"FAILURE\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " if ((b ? _Character : _Integer) == c) {\n" + + " ^^^^^^^^^^\n" + + "The expression of type Character is unboxed into int\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " if ((b ? _Character : _Integer) == c) {\n" + + " ^^^^^^^^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " System.out.println(zork);\n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n" + ); + } + // conditional operator: bool ? Integer : Integer --> Integer (identical operand types) + // but bool ? Integer : Short --> unboxed int + public void test097() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Integer i = 1;\n" + + " Integer j = 2;\n" + + " Short s = 3;\n" + + " foo(args != null ? i : j);\n" + + " foo(args != null ? i : s);\n" + + " }\n" + + " static void foo(int i) {\n" + + " System.out.print(\"[int:\"+i+\"]\");\n" + + " }\n" + + " static void foo(Integer i) {\n" + + " System.out.print(\"[Integer:\"+i+\"]\");\n" + + " }\n" + + "}\n" + }, + "[Integer:1][int:1]" + ); + } + // conditional operator: bool ? Integer : Integer --> Integer (identical operand types) + // but bool ? Integer : Short --> unboxed int + // check autoboxing warnings + public void test098() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Integer i = 1;\n" + + " Integer j = 2;\n" + + " Short s = 3;\n" + + " foo(args != null ? i : j);\n" + + " foo(args != null ? i : s);\n" + + " Zork z;\n" + + " }\n" + + " static void foo(int i) {\n" + + " System.out.print(\"[int:\"+i+\"]\");\n" + + " }\n" + + " static void foo(Integer i) {\n" + + " System.out.print(\"[Integer:\"+i+\"]\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Integer i = 1;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Integer j = 2;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " Short s = 3;\n" + + " ^\n" + + "The expression of type int is boxed into Short\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " foo(args != null ? i : s);\n" + + " ^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " foo(args != null ? i : s);\n" + + " ^\n" + + "The expression of type Short is unboxed into int\n" + + "----------\n" + + "6. 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=84801 + public void test099() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends A {\n" + + " public void m(Object o) { System.out.println(\"SUCCESS\"); }\n" + + " public static void main(String[] args) { ((A) new X()).m(1); }\n" + + "}\n" + + "interface I { void m(Object o); }\n" + + "abstract class A implements I {\n" + + " public final void m(int i) {\n" + + " System.out.print(\"SUCCESS + \");\n" + + " m(new Integer(i));\n" + + " }\n" + + " public final void m(double d) {\n" + + " System.out.print(\"FAILED\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS + SUCCESS" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87267 + public void test100() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer[] integers = {};\n" + + " int[] ints = (int[]) integers;\n" + + " float[] floats = {};\n" + + " Float[] fs = (Float[]) floats;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int[] ints = (int[]) integers;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Integer[] to int[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Float[] fs = (Float[]) floats;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot cast from float[] to Float[]\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85491 + public void test101() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object... i) { System.out.print(1); }\n" + + " void foo(int... i) { System.out.print(2); }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public static void main(String[] args) {\n" + + " new X().foo(1);\n" + + " new X().foo(Integer.valueOf(1));\n" + + " new X().foo(1, Integer.valueOf(1));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X().foo(1);\n" + + " ^^^\n" + + "The method foo(Object[]) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " new X().foo(Integer.valueOf(1));\n" + + " ^^^\n" + + "The method foo(Object[]) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " new X().foo(1, Integer.valueOf(1));\n" + + " ^^^\n" + + "The method foo(Object[]) is ambiguous for the type X\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Number... i) { System.out.print(1); }\n" + + " void foo(int... i) { System.out.print(2); }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public static void main(String[] args) {\n" + + " new X().foo(1);\n" + + " new X().foo(Integer.valueOf(1));\n" + + " new X().foo(1, Integer.valueOf(1));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X().foo(1);\n" + + " ^^^\n" + + "The method foo(Number[]) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " new X().foo(Integer.valueOf(1));\n" + + " ^^^\n" + + "The method foo(Number[]) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " new X().foo(1, Integer.valueOf(1));\n" + + " ^^^\n" + + "The method foo(Number[]) is ambiguous for the type X\n" + + "----------\n" + ); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(int i, Object... o) { System.out.print(1); }\n" + + " void foo(Integer o, int... i) { System.out.print(2); }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public static void main(String[] args) {\n" + + " new X().foo(1);\n" + + " new X().foo(Integer.valueOf(1));\n" + + " new X().foo(1, Integer.valueOf(1));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X().foo(1);\n" + + " ^^^\n" + + "The method foo(int, Object[]) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " new X().foo(Integer.valueOf(1));\n" + + " ^^^\n" + + "The method foo(int, Object[]) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " new X().foo(1, Integer.valueOf(1));\n" + + " ^^^\n" + + "The method foo(int, Object[]) is ambiguous for the type X\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84801 + public void test102() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class Cla {\n" + + " A val;\n" + + " public Cla(A x) { val = x; }\n" + + " A getVal() { return val; }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " \n" + + " void proc0(Cla b0) {\n" + + " final Long t1 = b0.getVal();\n" + + " System.out.print(t1);\n" + + " final long t2 = b0.getVal();\n" + + " System.out.print(t2);\n" + + " }\n" + + "\n" + + " void proc1(Cla obj) {\n" + + " final Long t3 = obj.getVal();\n" + + " System.out.print(t3);\n" + + " final long t4 = obj.getVal();\n" + + " System.out.print(t4);\n" + + " }\n" + + " \n" + + " void proc2(Cla obj) {\n" + + " final Long t5 = obj.getVal();\n" + + " System.out.print(t5);\n" + + " final long t6 = obj.getVal();\n" + + " System.out.println(t6);\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.proc0(new Cla(0l));\n" + + " x.proc1(new Cla(1l));\n" + + " x.proc2(new Cla(2l));\n" + + " }\n" + + "}\n" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "001122" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84801 - variation (check warnings) + public void test103() { + this.runNegativeTest( + new String[] { + "X.java", + "class Cla {\n" + + " Zork z;\n" + + " A val;\n" + + " public Cla(A x) { val = x; }\n" + + " A getVal() { return val; }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " \n" + + " void proc0(Cla b0) {\n" + + " final Long t1 = b0.getVal();\n" + + " System.out.print(t1);\n" + + " final long t2 = b0.getVal();\n" + + " System.out.print(t2);\n" + + " }\n" + + "\n" + + " void proc1(Cla obj) {\n" + + " final Long t3 = obj.getVal();\n" + + " System.out.print(t3);\n" + + " final long t4 = obj.getVal();\n" + + " System.out.print(t4);\n" + + " }\n" + + " \n" + + " void proc2(Cla obj) {\n" + + " final Long t5 = obj.getVal();\n" + + " System.out.print(t5);\n" + + " final long t6 = obj.getVal();\n" + + " System.out.printltn(t6);\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.proc0(new Cla(0l));\n" + + " x.proc1(new Cla(1l));\n" + + " x.proc2(new Cla(2l));\n" + + " }\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" + + "2. WARNING in X.java (at line 13)\n" + + " final long t2 = b0.getVal();\n" + + " ^^^^^^^^^^^\n" + + "The expression of type Long is unboxed into long\n" + + "----------\n" + + "3. WARNING in X.java (at line 20)\n" + + " final long t4 = obj.getVal();\n" + + " ^^^^^^^^^^^^\n" + + "The expression of type capture#2-of ? extends Long is unboxed into long\n" + + "----------\n" + + "4. WARNING in X.java (at line 24)\n" + + " void proc2(Cla obj) {\n" + + " ^^^^\n" + + "The type parameter U should not be bounded by the final type Long. Final types cannot be further extended\n" + + "----------\n" + + "5. WARNING in X.java (at line 27)\n" + + " final long t6 = obj.getVal();\n" + + " ^^^^^^^^^^^^\n" + + "The expression of type U is unboxed into long\n" + + "----------\n" + + "6. ERROR in X.java (at line 28)\n" + + " System.out.printltn(t6);\n" + + " ^^^^^^^^\n" + + "The method printltn(long) is undefined for the type PrintStream\n" + + "----------\n" + + "7. WARNING in X.java (at line 33)\n" + + " x.proc0(new Cla(0l));\n" + + " ^^\n" + + "The expression of type long is boxed into Long\n" + + "----------\n" + + "8. WARNING in X.java (at line 34)\n" + + " x.proc1(new Cla(1l));\n" + + " ^^\n" + + "The expression of type long is boxed into Long\n" + + "----------\n" + + "9. WARNING in X.java (at line 35)\n" + + " x.proc2(new Cla(2l));\n" + + " ^^\n" + + "The expression of type long is boxed into Long\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=95868 + public void test104() { + this.runConformTest( + false /* skipJavac */, + JavacTestOptions.Excuse.JavacGeneratesIncorrectCode, + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " String x = \"\";\n" + + " HashMap y = new HashMap();\n" + + " Integer w = (x.equals(\"X\") ? 0 : y.get(\"yKey\"));\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101779 +public void test105() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "final class Pair {\n" + + " public F first;\n" + + " public S second;\n" + + "\n" + + " public static Pair create(F f, S s) {\n" + + " return new Pair(f, s);\n" + + " }\n" + + "\n" + + " public Pair(final F f, final S s) {\n" + + " first = f;\n" + + " second = s;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public void a() {\n" + + " Pair p = Pair.create(1, 3);\n" + + " // p.first -= 1; // should be rejected ?\n" + + " p.first--;\n" + + " --p.first;\n" + + " p.first = p.first - 1;\n" + + " System.out.println(p.first);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " new X().a();\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "-2" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101779 - variation +public void test106() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class XSuper {\n" + + " T value;\n" + + "}\n" + + "public class X extends XSuper{\n" + + " public void a() {\n" + + " value--;\n" + + " --value;\n" + + " value -= 1;\n" + + " value = value - 1;\n" + + " System.out.println(value);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " X x = new X();\n" + + " x.value = 5;\n" + + " x.a();\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "1" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101779 - variation +public void test107() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class XSuper {\n" + + " T value;\n" + + "}\n" + + "public class X extends XSuper{\n" + + " public void a() {\n" + + " this.value--;\n" + + " --this.value;\n" + + " this.value -= 1;\n" + + " this.value = this.value - 1;\n" + + " System.out.println(this.value);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " X x = new X();\n" + + " x.value = 5;\n" + + " x.a();\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "1" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101779 - variation +public void test108() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class XSuper {\n" + + " T value;\n" + + "}\n" + + "public class X extends XSuper{\n" + + " public static void a(X x) {\n" + + " x.value--;\n" + + " --x.value;\n" + + " x.value -= 1;\n" + + " x.value = x.value - 1;\n" + + " System.out.println(x.value);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " X x = new X();\n" + + " x.value = 5;\n" + + " a(x);\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "1" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100043 +public void test109() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int foo = 0;\n" + + " String bar = \"zero\";\n" + + " System.out.println((foo != 0) ? foo : bar);\n" + + " }\n" + + "}\n", + }, + "zero"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100043 - variation +public void test110() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " if (new Boolean(true) ? true : new Boolean(false)) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " } else {\n" + + " System.out.print(\"FAILED\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105524 +public void test111() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class Wrapper< T >\n" + + "{\n" + + " public T value;\n" + + "}\n" + + "\n" + + "public class X\n" + + "{\n" + + " public static void main( final String[ ] args )\n" + + " {\n" + + " final Wrapper< Integer > wrap = new Wrapper< Integer >( );\n" + + " wrap.value = 0;\n" + + " wrap.value = wrap.value + 1; // works\n" + + " wrap.value++; // throws VerifyError\n" + + " wrap.value += 1; // throws VerifyError\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105284 +public void test112() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Short s;\n" + + " s = 5; // Type mismatch: cannot convert from int to Short\n" + + " Short[] shorts = { 0, 1, 2, 3 };\n" + + " System.out.println(s+shorts[2]);\n" + + " }\n" + + "}\n", + }, + "7"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105284 - variation +public void test113() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Short s;\n" + + " s = 5; // Type mismatch: cannot convert from int to Short\n" + + "\n" + + " int i = 0;\n" + + " s = i; // not a constant\n" + + " \n" + + " bar(4);\n" + + " Short[] shorts = { 0, 1, 2, 3 };\n" + + " }\n" + + " void bar(Short s) {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " s = 5; // Type mismatch: cannot convert from int to Short\n" + + " ^\n" + + "The expression of type int is boxed into Short\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " s = i; // not a constant\n" + + " ^\n" + + "Type mismatch: cannot convert from int to Short\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " bar(4);\n" + + " ^^^\n" + + "The method bar(Short) in the type X is not applicable for the arguments (int)\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " Short[] shorts = { 0, 1, 2, 3 };\n" + + " ^\n" + + "The expression of type int is boxed into Short\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " Short[] shorts = { 0, 1, 2, 3 };\n" + + " ^\n" + + "The expression of type int is boxed into Short\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " Short[] shorts = { 0, 1, 2, 3 };\n" + + " ^\n" + + "The expression of type int is boxed into Short\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " Short[] shorts = { 0, 1, 2, 3 };\n" + + " ^\n" + + "The expression of type int is boxed into Short\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100182 +public void test114() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " char c = \'a\';\n" + + " System.out.printf(\"%c\",c); \n" + + " System.out.printf(\"%d\\n\",(int)c); \n" + + " }\n" + + " Zork z;\n" + + "}\n" , + }, + // ensure no unnecessary cast warning + "----------\n" + + "1. WARNING in X.java (at line 4)\r\n" + + " System.out.printf(\"%c\",c); \r\n" + + " ^\n" + + "The expression of type char is boxed into Character\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\r\n" + + " System.out.printf(\"%d\\n\",(int)c); \r\n" + + " ^^^^^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\r\n" + + " Zork z;\r\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100182 - variation +public void test115() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " char c = \'a\';\n" + + " System.out.printf(\"%c\",c); \n" + + " System.out.printf(\"%d\\n\",(int)c); \n" + + " }\n" + + "}\n", + }, + "a97"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106870 +public void test116() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean foo(Long l, Float f) {\n" + + " return f == l;\n" + + " }\n" + + " float bar(Long l, Float f) {\n" + + " return this == null ? f : l;\n" + + " }\n" + + " double baz(Long l, Float f) {\n" + + " return this == null ? f : l;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " return f == l;\r\n" + + " ^^^^^^\n" + + "Incompatible operand types Float and Long\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\r\n" + + " return this == null ? f : l;\r\n" + + " ^\n" + + "The expression of type Float is unboxed into float\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\r\n" + + " return this == null ? f : l;\r\n" + + " ^\n" + + "The expression of type Long is unboxed into float\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\r\n" + + " return this == null ? f : l;\r\n" + + " ^\n" + + "The expression of type Float is unboxed into float\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\r\n" + + " return this == null ? f : l;\r\n" + + " ^\n" + + "The expression of type Long is unboxed into float\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122987 +public void test117() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args)\n" + + " {\n" + + " Object obj = true ? true : 17.3;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Object obj = true ? true : 17.3;\n" + + " ^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Object obj = true ? true : 17.3;\n" + + " ^^^^\n" + + "The expression of type double is boxed into Double\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +// Integer array and method with T extends Integer bound +public void test118() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void foo(final T[] p) {\n" + + // we have a warning here, since no class can extend Integer, but the code + // still needs to execute + " System.out.println(p[0] / 4);\n" + + " }\n" + + " public static void main(final String[] args) {\n" + + " X.foo(new Integer[] { 4, 8, 16 });\n" + + " }\n" + + "}", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "1" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBug6575821 /* javac test options */); +} + +// Integer as member of a parametrized class +public void test119() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T m;\n" + + " X(T p) {\n" + + " this.m = p;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X l = new X(0);\n" + // boxing + " l.m++;\n" + // boxing + unboxing + " System.out.println(l.m);\n" + + " }\n" + + "}", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "1" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=137918 +public void test120() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int a = 100;\n" + + " boolean c = a instanceof Integer;\n" + + " Integer i = (Integer) a;\n" + + " System.out.println(c);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " boolean c = a instanceof Integer;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types int and Integer\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " Integer i = (Integer) a;\n" + + " ^^^^^^^^^^^\n" + + "Unnecessary cast from int to Integer\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " Integer i = (Integer) a;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156108 +public void test121() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final int i = -128;\n" + + " Byte b = i;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Byte no = 127; // warning: int boxed to Byte > fine\n" + + " switch (no) { // warning: Byte is unboxed into int > why in int??? output\n" + + " case -128: // error: cannot convert int to Byte > needs a explicit (byte)cast.\n" + + " break;\n" + + " case (byte) 127: // works\n" + + " break;\n" + + " }\n" + + " no = new Byte(127);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Byte b = i;\n" + + " ^\n" + + "The expression of type int is boxed into Byte\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " Byte no = 127; // warning: int boxed to Byte > fine\n" + + " ^^^\n" + + "The expression of type int is boxed into Byte\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " switch (no) { // warning: Byte is unboxed into int > why in int??? output\n" + + " ^^\n" + + "The expression of type Byte is unboxed into int\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " no = new Byte(127);\n" + + " ^^^^^^^^^^^^^\n" + + "The constructor Byte(int) is undefined\n" + + "----------\n" +); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156108 - variation +public void test122() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Byte foo() {\n" + + " final int i = -128;\n" + + " return i;\n" + + " }\n" + + " Byte bar() {\n" + + " final int i = 1000;\n" + + " return i;\n" + + " } \n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return i;\n" + + " ^\n" + + "The expression of type int is boxed into Byte\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return i;\n" + + " ^\n" + + "Type mismatch: cannot convert from int to Byte\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155255 +public void test123() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo1();\n" + + " foo2();\n" + + " foo3();\n" + + " foo4();\n" + + " System.out.println(\"[done]\");\n" + + " }\n" + + " static void foo1() {\n" + + " Object x = true ? true : \"\";\n" + + " System.out.print(\"[1:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + + " }\n" + + " static void foo2() {\n" + + " Object x = Boolean.TRUE != null ? true : \"\";\n" + + " System.out.print(\"[2:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + + " }\n" + + " static void foo3() {\n" + + " Object x = false ? \"\" : false;\n" + + " System.out.print(\"[3:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + + " }\n" + + " static void foo4() {\n" + + " Object x = Boolean.TRUE == null ? \"\" : false;\n" + + " System.out.print(\"[4:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + + " }\n" + + "}", // ================= + }, + "[1:true,java.lang.Boolean][2:true,java.lang.Boolean][3:false,java.lang.Boolean][4:false,java.lang.Boolean][done]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155255 - variation +public void test124() { + String specVersion = System.getProperty("java.specification.version"); + isJRE15Plus = Integer.valueOf(specVersion) >= Integer.valueOf(CompilerOptions.VERSION_15); + String bounds = isJRE15Plus ? "Object&Serializable&Comparable&Constable" : "Object&Serializable&Comparable"; + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo5() {\n" + + " boolean x = false ? \"\" : false;\n" + + " System.out.print(\"[4:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + + " } \n" + + "}", // ================= + }, + this.complianceLevel >= ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " boolean x = false ? \"\" : false;\n" + + " ^^\n" + + "Type mismatch: cannot convert from String to boolean\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " System.out.print(\"[4:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + + " ^^^^^^^^^^^^\n" + + "Cannot invoke getClass() on the primitive type boolean\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " boolean x = false ? \"\" : false;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from "+ bounds +" to boolean\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " boolean x = false ? \"\" : false;\n" + + " ^^^^^\n" + + "The expression of type boolean is boxed into Boolean\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " System.out.print(\"[4:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + + " ^^^^^^^^^^^^\n" + + "Cannot invoke getClass() on the primitive type boolean\n" + + "----------\n"); + } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155255 - variation +public void test125() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo1();\n" + + " foo2();\n" + + " foo3();\n" + + " System.out.println(\"[done]\");\n" + + " }\n" + + " static void foo1() {\n" + + " Object x = true ? 3.0f : false;\n" + + " System.out.print(\"[1:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + + " }\n" + + " static void foo2() {\n" + + " Object x = true ? 2 : false;\n" + + " System.out.print(\"[2:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + + " }\n" + + " static void foo3() {\n" + + " Object x = false ? 2 : false;\n" + + " System.out.print(\"[3:\"+ x + \",\" + x.getClass().getCanonicalName() + \"]\");\n" + + " }\n" + + "}\n", // ================= + }, + "[1:3.0,java.lang.Float][2:2,java.lang.Integer][3:false,java.lang.Boolean][done]"); + } +public void test126() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " int i = 12;\n" + + " Integer r1 = b ? null : i;\n" + + " int r2 = b ? null : i;\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Integer r1 = b ? null : i;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " int r2 = b ? null : i;\n" + + " ^^^^^^^^^^^^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " int r2 = b ? null : i;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test127() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Object[] os1 = new Object[] {(long)1234567};\n" + + " Object[] os2 = new Object[] {1234567};\n" + + " Object o1 = os1[0], o2 = os2[0];\n" + + " if (o1.getClass().equals(o2.getClass())) {\n" + + " System.out.println(\"FAILED:o1[\"+o1.getClass().getName()+\"],o2:[\"+o2.getClass()+\"]\");\n" + + " } else {\n" + + " System.out.println(\"SUCCESS:o1[\"+o1.getClass().getName()+\"],o2:[\"+o2.getClass()+\"]\");\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS:o1[java.lang.Long],o2:[class java.lang.Integer]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159987 +public void test128() { + // check there is no unncessary cast warning when autoboxing, even in array initializer + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Object o1 = (long) 1234567;\n" + + " Object[] os1 = new Object[] { (long) 1234567 };\n" + + " Object[] os2 = { (long) 1234567 };\n" + + " foo((long) 1234567);\n" + + " }\n" + + " static void foo(Object o) {\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object o1 = (long) 1234567;\n" + + " ^^^^^^^^^^^^^^\n" + + "The expression of type long is boxed into Long\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Object[] os1 = new Object[] { (long) 1234567 };\n" + + " ^^^^^^^^^^^^^^\n" + + "The expression of type long is boxed into Long\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " Object[] os2 = { (long) 1234567 };\n" + + " ^^^^^^^^^^^^^^\n" + + "The expression of type long is boxed into Long\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " foo((long) 1234567);\n" + + " ^^^^^^^^^^^^^^\n" + + "The expression of type long is boxed into Long\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155104 +public void test129() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X{\n" + + " java.io.Serializable field=this==null?8:\"\".getBytes();\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\r\n" + + " java.io.Serializable field=this==null?8:\"\".getBytes();\r\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\r\n" + + " Zork z;\r\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174879 +public void test130() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Boolean[] myBool = new Boolean[1];\n" + + " void foo() {\n" + + " if (this.myBool[0]) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().foo();\n" + + " System.out.println(\"FAILURE\");\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174879 +public void test131() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Boolean myBool = null;\n" + + " void foo() {\n" + + " if (myBool) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().foo();\n" + + " System.out.println(\"FAILURE\");\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174879 +public void test132() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static Boolean myBool = null;\n" + + " static void foo() {\n" + + " if (myBool) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " foo();\n" + + " System.out.println(\"FAILURE\");\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174879 +public void test133() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Boolean myBool = null;\n" + + " void foo() {\n" + + " if (this.myBool) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().foo();\n" + + " System.out.println(\"FAILURE\");\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174879 +public void test134() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static Boolean MyBool = null;\n" + + " static void foo() {\n" + + " if (X.MyBool) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " foo();\n" + + " System.out.println(\"FAILURE\");\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 +public void test135() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo() { return null; }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " A ua = a;\n" + + " try {\n" + + " long s = a.foo();\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test136() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo(Object o) {\n" + + " return (T) o; // should get unchecked warning\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " try {\n" + + " long s = a.foo(new Object());\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test137() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " A ua = a;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " long s = a.foo;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test138() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X extends A{\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " A ua = this;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " long s = foo;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test139() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X extends A{\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " A ua = this;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " long s = this.foo;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test140() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " long foo() {\n" + + " return 0L;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " Long s = a.foo();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test141() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " long foo = 0L;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " Long s = a.foo;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test142() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " long foo = 0L;\n" + + "}\n" + + "\n" + + "public class X extends A {\n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " }\n" + + " void bar() {\n" + + " Long s = foo;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test143() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " long foo = 0L;\n" + + "}\n" + + "\n" + + "public class X extends A {\n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " }\n" + + " void bar() {\n" + + " Long s = this.foo;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test144() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T[] foo;\n" + + "}\n" + + "\n" + + "public class X extends A{\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " A ua = this;\n" + + " ua.foo = new Object[1];\n" + + " try {\n" + + " long s = this.foo[0];\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test145() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " long[] foo = { 0L };\n" + + "}\n" + + "\n" + + "public class X extends A {\n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " }\n" + + " void bar() {\n" + + " Long s = this.foo[0];\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177372 - variation +public void test146() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " long s = a.foo.MAX_VALUE;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=184957 +public void test147() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if(new Integer(2) == 0) {}\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=184957 +public void test148() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Z test = new Z(1, 1);\n" + + " System.out.println(\"SUCCESS\" + test.foo());\n" + + " }\n" + + "}", + "Z.java", + "class Z {\n" + + " public Z(A a, B b) {\n" + + " }\n" + + " public int foo() {\n" + + " return 0;\n" + + " }\n" + + "}" + }, + "SUCCESS0"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=184957 +public void test149() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Z test = new Z(1, 1);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + "Z.java", + "class Z {\n" + + " public Z(A a, B b) {\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=184957 +public void test150() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if(new Integer(2) == 0) {\n" + + " System.out.println(\"FAILED\");\n" + + " } else {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=184957 +public void test151() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if(new Double(2.0) == 0.0) {\n" + + " System.out.println(\"FAILED\");\n" + + " } else {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=184957 +public void test152() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if(new Double(2.0) == 0.0) {}\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223685 +public void test153() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Integer a = 0;\n" + + " char b = (char)((int)a);\n" + + " char c = (char)(a + 1);\n" + + " char d = (char)(a);\n" + + " int e = (int) a;\n" + + " Integer f = (Integer) e;\n" + + " }\n" + + " void bar() {\n" + + " X x = (X) null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Integer a = 0;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " char b = (char)((int)a);\n" + + " ^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " char c = (char)(a + 1);\n" + + " ^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " char d = (char)(a);\n" + + " ^^^^^^^^^\n" + + "Cannot cast from Integer to char\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " int e = (int) a;\n" + + " ^^^^^^^\n" + + "Unnecessary cast from Integer to int\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " int e = (int) a;\n" + + " ^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "7. WARNING in X.java (at line 8)\n" + + " Integer f = (Integer) e;\n" + + " ^^^^^^^^^^^\n" + + "Unnecessary cast from int to Integer\n" + + "----------\n" + + "8. WARNING in X.java (at line 8)\n" + + " Integer f = (Integer) e;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "9. WARNING in X.java (at line 11)\n" + + " X x = (X) null;\n" + + " ^^^^^^^^\n" + + "Unnecessary cast from null to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232565 +public void test154() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T counter;\n" + + " public static void main(String[] args) {\n" + + " bar(new X());\n" + + " new Y().foo();\n" + + " new Y().baz();\n" + + " }\n" + + " static void bar(X x) {\n" + + " x.counter = 0;\n" + + " System.out.print(Integer.toString(x.counter++));\n" + + " }\n" + + "}\n" + + "\n" + + "class Y extends X {\n" + + " Y() {\n" + + " this.counter = 0;\n" + + " }\n" + + " void foo() {\n" + + " System.out.print(Integer.toString(counter++));\n" + + " }\n" + + " void baz() {\n" + + " System.out.println(Integer.toString(this.counter++));\n" + + " }\n" + + "}\n", + }, + "000"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232565 - variation +public void test155() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T[] counter;\n" + + " public static void main(String[] args) {\n" + + " bar(new X());\n" + + " new Y().foo();\n" + + " new Y().baz();\n" + + " }\n" + + " static void bar(X x) {\n" + + " x.counter = new Integer[]{ 0 };\n" + + " System.out.print(Integer.toString(x.counter[0]++));\n" + + " }\n" + + "}\n" + + "\n" + + "class Y extends X {\n" + + " Y() {\n" + + " this.counter = new Integer[]{ 0 };\n" + + " }\n" + + " void foo() {\n" + + " System.out.print(Integer.toString(counter[0]++));\n" + + " }\n" + + " void baz() {\n" + + " System.out.println(Integer.toString(this.counter[0]++));\n" + + " }\n" + + "}\n", + }, + "000"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232565 - variation +public void test156() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void print(Character c) {\n" + + " System.out.print((char) c);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " char c = \'H\';\n" + + " print(c++);\n" + + " print(c++);\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}\n", + }, + "HIdone"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232565 - variation +public void test157() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " char c = \'H\';\n" + + " static void print(Character c) {\n" + + " System.out.print((char) c);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " print(x.c++);\n" + + " print(x.c++);\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}\n", + }, + "HIdone"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232565 - variation +public void test158() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static X singleton = new X();\n" + + " static X singleton() { return singleton; }\n" + + " char c = \'H\';\n" + + " \n" + + " static void print(Character c) {\n" + + " System.out.print((char) c);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " print(singleton().c++);\n" + + " print(singleton().c++);\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}\n", + }, + "HIdone"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236019 +public void test159() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {\n" + + " ArrayList params;\n" + + " public int getSqlParamCount() {\n" + + " return params == null ? null:params.size();\n" + + " }\n" + + " public int getSqlParamCount2() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " ArrayList params;\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " return params == null ? null:params.size();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " return params == null ? null:params.size();\n" + + " ^^^^^^^^^^^^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " return null;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from null to int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232565 - variation +public void test160() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T counter;\n" + + " public static void main(String[] args) {\n" + + " bar(new X());\n" + + " new Y().foo();\n" + + " new Y().baz();\n" + + " }\n" + + " static void bar(X x) {\n" + + " x.counter = 0;\n" + + " System.out.print(Integer.toString(++x.counter));\n" + + " }\n" + + "}\n" + + "\n" + + "class Y extends X {\n" + + " Y() {\n" + + " this.counter = 0;\n" + + " }\n" + + " void foo() {\n" + + " System.out.print(Integer.toString(++counter));\n" + + " }\n" + + " void baz() {\n" + + " System.out.println(Integer.toString(++this.counter));\n" + + " }\n" + + "}\n", + }, + "111"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232565 - variation +public void test161() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T[] counter;\n" + + " public static void main(String[] args) {\n" + + " bar(new X());\n" + + " new Y().foo();\n" + + " new Y().baz();\n" + + " }\n" + + " static void bar(X x) {\n" + + " x.counter = new Integer[]{ 0 };\n" + + " System.out.print(Integer.toString(++x.counter[0]));\n" + + " }\n" + + "}\n" + + "\n" + + "class Y extends X {\n" + + " Y() {\n" + + " this.counter = new Integer[]{ 0 };\n" + + " }\n" + + " void foo() {\n" + + " System.out.print(Integer.toString(++counter[0]));\n" + + " }\n" + + " void baz() {\n" + + " System.out.println(Integer.toString(++this.counter[0]));\n" + + " }\n" + + "}\n", + }, + "111"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232565 - variation +public void test162() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void print(Character c) {\n" + + " System.out.print((char) c);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " char c = \'H\';\n" + + " print(++c);\n" + + " print(++c);\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}\n", + }, + "IJdone"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232565 - variation +public void test163() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " char c = \'H\';\n" + + " static void print(Character c) {\n" + + " System.out.print((char) c);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " print(++x.c);\n" + + " print(++x.c);\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}\n", + }, + "IJdone"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232565 - variation +public void test164() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static X singleton = new X();\n" + + " static X singleton() { return singleton; }\n" + + " char c = \'H\';\n" + + " \n" + + " static void print(Character c) {\n" + + " System.out.print((char) c);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " print(++singleton().c);\n" + + " print(++singleton().c);\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}\n", + }, + "IJdone"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231709 +public void test165() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Integer i1 = 10 ;\n" + + " final short s = 100;\n" + + " i1 = s;\n" + + " switch (i1)\n" + + " {\n" + + " case s:\n" + + " }\n" + + " }\n" + + " public void bar() {\n" + + " Integer i2 = 10 ;\n" + + " final byte b = 100;\n" + + " i2 = b;\n" + + " switch (i2)\n" + + " {\n" + + " case b:\n" + + " }\n" + + " } \n" + + " public void baz() {\n" + + " Integer i3 = 10 ;\n" + + " final char c = 100;\n" + + " i3 = c;\n" + + " switch (i3)\n" + + " {\n" + + " case c:\n" + + " }\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Integer i1 = 10 ;\n" + + " ^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " i1 = s;\n" + + " ^\n" + + "Type mismatch: cannot convert from short to Integer\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " switch (i1)\n" + + " ^^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " case s:\n" + + " ^\n" + + "Type mismatch: cannot convert from short to Integer\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " Integer i2 = 10 ;\n" + + " ^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " i2 = b;\n" + + " ^\n" + + "Type mismatch: cannot convert from byte to Integer\n" + + "----------\n" + + "7. WARNING in X.java (at line 15)\n" + + " switch (i2)\n" + + " ^^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "8. ERROR in X.java (at line 17)\n" + + " case b:\n" + + " ^\n" + + "Type mismatch: cannot convert from byte to Integer\n" + + "----------\n" + + "9. WARNING in X.java (at line 21)\n" + + " Integer i3 = 10 ;\n" + + " ^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "10. ERROR in X.java (at line 23)\n" + + " i3 = c;\n" + + " ^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "11. WARNING in X.java (at line 24)\n" + + " switch (i3)\n" + + " ^^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n" + + "12. ERROR in X.java (at line 26)\n" + + " case c:\n" + + " ^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231709 - variation +public void test166() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(short s, byte b, char c) {\n" + + " Integer is = s;\n" + + " Integer ib = b;\n" + + " Integer ic = c; \n" + + " }\n" + + " void foo() {\n" + + " final short s = 0;\n" + + " final byte b = 0;\n" + + " final char c = 0;\n" + + " Integer is = s;\n" + + " Integer ib = b;\n" + + " Integer ic = c; \n" + + " }\n" + + " void foo2() {\n" + + " Integer is = (short)0;\n" + + " Integer ib = (byte)0;\n" + + " Integer ic = (char)0; \n" + + " }\n" + + " void foo3() {\n" + + " Short si = 0;\n" + + " Byte bi = 0;\n" + + " Character ci = 0;\n" + + " }\n" + + " void foo4() {\n" + + " Short si = (byte) 0;\n" + + " Byte bi = (short) 0;\n" + + " Character ci = (short) 0;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Integer is = s;\n" + + " ^\n" + + "Type mismatch: cannot convert from short to Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Integer ib = b;\n" + + " ^\n" + + "Type mismatch: cannot convert from byte to Integer\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Integer ic = c; \n" + + " ^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " Integer is = s;\n" + + " ^\n" + + "Type mismatch: cannot convert from short to Integer\n" + + "----------\n" + + "5. ERROR in X.java (at line 12)\n" + + " Integer ib = b;\n" + + " ^\n" + + "Type mismatch: cannot convert from byte to Integer\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " Integer ic = c; \n" + + " ^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "7. ERROR in X.java (at line 16)\n" + + " Integer is = (short)0;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from short to Integer\n" + + "----------\n" + + "8. ERROR in X.java (at line 17)\n" + + " Integer ib = (byte)0;\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from byte to Integer\n" + + "----------\n" + + "9. ERROR in X.java (at line 18)\n" + + " Integer ic = (char)0; \n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from char to Integer\n" + + "----------\n" + + "10. WARNING in X.java (at line 21)\n" + + " Short si = 0;\n" + + " ^\n" + + "The expression of type int is boxed into Short\n" + + "----------\n" + + "11. WARNING in X.java (at line 22)\n" + + " Byte bi = 0;\n" + + " ^\n" + + "The expression of type int is boxed into Byte\n" + + "----------\n" + + "12. WARNING in X.java (at line 23)\n" + + " Character ci = 0;\n" + + " ^\n" + + "The expression of type int is boxed into Character\n" + + "----------\n" + + "13. WARNING in X.java (at line 26)\n" + + " Short si = (byte) 0;\n" + + " ^^^^^^^^\n" + + "The expression of type byte is boxed into Short\n" + + "----------\n" + + "14. WARNING in X.java (at line 27)\n" + + " Byte bi = (short) 0;\n" + + " ^^^^^^^^^\n" + + "The expression of type short is boxed into Byte\n" + + "----------\n" + + "15. WARNING in X.java (at line 28)\n" + + " Character ci = (short) 0;\n" + + " ^^^^^^^^^\n" + + "The expression of type short is boxed into Character\n" + + "----------\n"); +} +public void test167() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo(Comparable x) {\n" + + " System.out.println( \"one\" );" + + " return null;\n" + + " }\n" + + " void foo(int x) {\n" + + " System.out.println( \"two\" );\n" + + " }\n" + + " void bar() {\n" + + " Integer i = 1;\n" + + " String s = foo(i); \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Integer i = 1;\n" + + " ^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " String s = foo(i); \n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from void to String\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " String s = foo(i); \n" + + " ^\n" + + "The expression of type Integer is unboxed into int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=264843 +public void test168() { + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"deprecation\")\n" + + "public class X {\n" + + " T a() { return 35; }\n" + + " T[] b() { return new int[]{35}; }\n" + + " T c() { return Integer.valueOf(35); }\n" + + " T[] d() { return new Integer[]{35}; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " T a() { return 35; }\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " T a() { return 35; }\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " T[] b() { return new int[]{35}; }\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " T[] b() { return new int[]{35}; }\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from int[] to T[]\n" + + "----------\n" + + "5. WARNING in X.java (at line 5)\n" + + " T c() { return Integer.valueOf(35); }\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "6. ERROR in X.java (at line 5)\n" + + " T c() { return Integer.valueOf(35); }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Integer to T\n" + + "----------\n" + + "7. WARNING in X.java (at line 6)\n" + + " T[] d() { return new Integer[]{35}; }\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "8. ERROR in X.java (at line 6)\n" + + " T[] d() { return new Integer[]{35}; }\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Integer[] to T[]\n" + + "----------\n" + + "9. WARNING in X.java (at line 6)\n" + + " T[] d() { return new Integer[]{35}; }\n" + + " ^^\n" + + "The expression of type int is boxed into Integer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=264843 +public void test169() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T x = 12;\n" + + " Byte y = 12;\n" + + " void x(T t) {\n" + + " t = 5;\n" + + " switch (t) {\n" + + " case 1:\n" + + " break;\n" + + " }\n" + + " }\n" + + " void y(Byte t) {\n" + + " t = 5;\n" + + " switch (t) {\n" + + " case 1:\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " T x = 12;\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " Byte y = 12;\n" + + " ^^\n" + + "The expression of type int is boxed into Byte\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " t = 5;\n" + + " ^\n" + + "Type mismatch: cannot convert from int to T\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " switch (t) {\n" + + " ^\n" + + "The expression of type T is unboxed into int\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " case 1:\n" + + " ^\n" + + "Type mismatch: cannot convert from int to T\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " t = 5;\n" + + " ^\n" + + "The expression of type int is boxed into Byte\n" + + "----------\n" + + "8. WARNING in X.java (at line 13)\n" + + " switch (t) {\n" + + " ^\n" + + "The expression of type Byte is unboxed into int\n" + + "----------\n"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AutomaticModuleNamingTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AutomaticModuleNamingTest.java new file mode 100644 index 0000000000..ccde5f7f52 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AutomaticModuleNamingTest.java @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2017 Till Brychcy and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Till Brychcy - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import static org.eclipse.jdt.internal.compiler.env.AutomaticModuleNaming.determineAutomaticModuleName; +import static org.eclipse.jdt.internal.compiler.env.AutomaticModuleNaming.determineAutomaticModuleNameFromFileName; + +import java.io.File; + +import org.eclipse.jdt.core.tests.util.Util; + +import junit.framework.Test; + +public class AutomaticModuleNamingTest extends AbstractRegressionTest { + static { + // TESTS_NAMES = new String[] { "testManifest" }; + } + + public AutomaticModuleNamingTest(String name) { + super(name); + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + + public static Class testClass() { + return AutomaticModuleNamingTest.class; + } + + public void testManifest() throws Exception { + String dirName = OUTPUT_DIR + File.separator + "automatic"; + try { + String metaInfDir = dirName + File.separator + "META-INF"; + new File(metaInfDir).mkdirs(); + + Util.createFile(metaInfDir + File.separator + "MANIFEST.MF", // + "Manifest-Version: 1.0\n" // + + "Automatic-Module-Name: module.123\n"); + Util.zip(new File(dirName), dirName + File.separator + "foo.bar-1.2.3.jar"); + assertEquals("module.123", new String( + determineAutomaticModuleName((dirName + File.separator + "foo.bar-1.2.3.jar").toString()))); + } finally { + Util.delete(dirName); + } + } + + public void testSimple() throws Exception { + assertEquals("junit", new String(determineAutomaticModuleNameFromFileName("junit.jar", false, true))); + } + + public void testWithVersion() throws Exception { + assertEquals("junit", new String(determineAutomaticModuleNameFromFileName("junit-4.8.2.jar", false, true))); + } + + public void testMultiParts() throws Exception { + assertEquals("foo.bar", new String(determineAutomaticModuleNameFromFileName("foo-bar.jar", false, true))); + } + + public void testMultiPartWithVersion() throws Exception { + assertEquals("foo.bar", + new String(determineAutomaticModuleNameFromFileName("foo-bar-1.2.3-SNAPSHOT.jar", false, true))); + } + + public void testMultiPartWithNumberWithoutDot() throws Exception { + assertEquals("foo.bar.3d", + new String(determineAutomaticModuleNameFromFileName("foo-bar-3d-1.2.3-SNAPSHOT.jar", false, true))); + } + + public void testSpecialCharacters() throws Exception { + assertEquals("foo.bar", + new String(determineAutomaticModuleNameFromFileName("?foo?bar?-1.2.3-SNAPSHOT.jar", false, true))); + } + + public void testMultipleSpecialCharacters() throws Exception { + assertEquals("foo.bar", new String( + determineAutomaticModuleNameFromFileName("?@#foo?@#bar?@#-1.2.3-SNAPSHOT.jar", false, true))); + } + + public void testMultipleSpecialCharactersWithDirectory() throws Exception { + assertEquals("foo.bar.bla", + new String(determineAutomaticModuleNameFromFileName( + File.separator + "somedir" + File.separator + "?@#foo?@#bar?@#bla?@#-1.2.3-SNAPSHOT.jar", true, + true))); + } + + public void testFileEndsWithDotJar() throws Exception { + assertEquals("module.jar", new String( + determineAutomaticModuleNameFromFileName("somedir" + File.separator + "module.jar.jar", true, true))); + } + + public void testProjectNameEndsWithDotJar() throws Exception { + // for hypothetical use case: project on module path treated as automatic module + assertEquals("module.jar", new String( + determineAutomaticModuleNameFromFileName("somedir" + File.separator + "module.jar", true, false))); + } + + public void testUPPERCASE() throws Exception { + // upper case .JAR isn't mentioned in the spec, but currently handled like .jar + assertEquals("FOO.BAR", new String(determineAutomaticModuleNameFromFileName("FOO-BAR.JAR", true, true))); + } + + public void testZip() throws Exception { + // .ZIP isn't mentioned in the spec. + assertEquals("CLASSES12.ZIP", + new String(determineAutomaticModuleNameFromFileName("CLASSES12.ZIP", true, true))); + } + + public void testBug529680() throws Exception { + assertEquals("hibernate.jpa", new String( + determineAutomaticModuleNameFromFileName("hibernate-jpa-2.1-api-1.0.0.Final.jar", true, true))); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java new file mode 100644 index 0000000000..b2e42d291a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java @@ -0,0 +1,13251 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Benjamin Muskalla - Contribution for bug 239066 + * Stephan Herrmann - Contributions for + * bug 236385 - [compiler] Warn for potential programming problem if an object is created but not used + * bug 295551 - Add option to automatically promote all warnings to errors + * bug 185682 - Increment/decrement operators mark local variables as read + * bug 349326 - [1.7] new warning for missing try-with-resources + * bug 359721 - [options] add command line option for new warning token "resource" + * bug 186342 - [compiler][null] Using annotations for null checking + * bug 365208 - [compiler][batch] command line options for annotation based null analysis + * bug 370639 - [compiler][resource] restore the default for resource leak warnings + * bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations + * bug 374605 - Unreasonable warning for enum-based switch statements + * bug 375366 - ECJ ignores unusedParameterIncludeDocCommentReference unless enableJavadoc option is set + * bug 388281 - [compiler][null] inheritance of null annotations as an option + * bug 381443 - [compiler][null] Allow parameter widening from @NonNull to unannotated + * bug 383368 - [compiler][null] syntactic null analysis for field references + * Bug 392099 - [1.8][compiler][null] Apply null annotation on types for null analysis + * Bug 440477 - [null] Infrastructure for feeding external annotations into compilation + * Bug 440687 - [compiler][batch][null] improve command line option for external annotations + * Bug 408815 - [batch][null] Add CLI option for COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS + * Jesper Steen Moller - Contributions for + * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code + * bug 407297 - [1.8][compiler] Control generation of parameter names by option + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintWriter; +import java.text.MessageFormat; +import java.util.Iterator; +import java.util.List; + +import junit.framework.Test; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.batch.ClasspathDirectory; +import org.eclipse.jdt.internal.compiler.batch.ClasspathJar; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.batch.Main; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.util.ManifestAnalyzer; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class BatchCompilerTest extends AbstractBatchCompilerTest { + + static { +// TESTS_NAMES = new String[] { "test440477" }; +// TESTS_NUMBERS = new int[] { 306 }; +// TESTS_RANGE = new int[] { 298, -1 }; + } + public BatchCompilerTest(String name) { + super(name); + } + /** + * This test suite only needs to be run on one compliance. + * As it includes some specific 1.5 tests, it must be used with a least a 1.5 VM + * and not be duplicated in general test suite. + * @see TestAll + */ + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); + } + public static Class testClass() { + return BatchCompilerTest.class; + } + static class StringMatcher extends Matcher { + private String expected; + private Normalizer normalizer; + StringMatcher(String expected, Normalizer normalizer) { + this.expected = expected; + this.normalizer = normalizer; + } + @Override + boolean match(String effective) { + if (this.expected == null) { + return effective == null; + } + if (this.normalizer == null) { + return this.expected.equals(effective); + } + return this.expected.equals(this.normalizer.normalized(effective)); + } + @Override + String expected() { + return this.expected; + } + } + static class SubstringMatcher extends Matcher { + private String substring; + SubstringMatcher(String substring) { + this.substring = substring; + } + @Override + boolean match(String effective) { + effective = outputDirNormalizer.normalized(effective); + return effective.indexOf(this.substring) != -1; + } + @Override + String expected() { + return "*" + this.substring + "*"; + } + } + static final Matcher EMPTY_STRING_MATCHER = new Matcher() { + @Override + String expected() { + return org.eclipse.jdt.internal.compiler.util.Util.EMPTY_STRING; + } + @Override + boolean match(String effective) { + return effective != null && effective.length() == 0; + } + }; + static final Matcher ONE_FILE_GENERATED_MATCHER = new SubstringMatcher("[1 .class file generated]"); + static final Matcher TWO_FILES_GENERATED_MATCHER = new SubstringMatcher("[2 .class files generated]"); + + /** + * This normalizer replaces the whole classpaths section of a log file with + * a normalized placeholder. + */ + private static class XMLClasspathsSectionNormalizer extends Normalizer { + XMLClasspathsSectionNormalizer() { + super(null); + } + XMLClasspathsSectionNormalizer(Normalizer nextInChain) { + super(nextInChain); + } + @Override + String normalized(String originalValue) { + String result; + StringBuilder normalizedValueBuffer = new StringBuilder(originalValue); + int classpathsStartTagStart = normalizedValueBuffer + .indexOf(""), classpathsEndTagStart = normalizedValueBuffer + .indexOf(""); + if (classpathsStartTagStart != -1 && classpathsEndTagStart != -1 + && classpathsStartTagStart < classpathsEndTagStart) + normalizedValueBuffer.replace(classpathsStartTagStart + 12, + classpathsEndTagStart, "NORMALIZED SECTION"); + result = super.normalized(normalizedValueBuffer.toString()); + return result; + } + } + + /** + * This normalizer removes a selected range of lines from a log file. + */ + private static class LinesRangeNormalizer extends Normalizer { + private int first, number; + + LinesRangeNormalizer() { + super(null); + this.first = this.number = 0; + } + + LinesRangeNormalizer(Normalizer nextInChain) { + super(nextInChain); + this.first = this.number = 0; + } + + /** + * Make a new normalizer able to suppress a range of lines delimited by + * "\n" sequences from a log file (or another string). + * + * @param nextInChain + * the next normalizer in the chain of responsibility; pass + * null if none is needed + * @param firstLineToRemove + * the index of the first line to remove, starting at 0 + * @param linesNumber + * the number or lines to remove; if 0, no other + * transformation occurs than those operated by nextInChain + * (if any) + */ + LinesRangeNormalizer(Normalizer nextInChain, int firstLineToRemove, + int linesNumber) { + super(nextInChain); + this.first = firstLineToRemove; + this.number = linesNumber >= 0 ? linesNumber : 0; + } + + @Override + String normalized(String originalValue) { + String result; + if (this.number == 0 || originalValue.length() == 0) + result = super.normalized(originalValue); + else { + final int START = 0, KEEPING = 1, KEEPING_R = 2, SKIPING = 3, SKIPING_R = 4, END = 5, ERROR = 6; + int state = START, currentLineIndex = 0, currentCharIndex = 0, sourceLength; + char currentChar = '\0'; + if (this.first <= 0) + state = SKIPING; + else + state = KEEPING; + StringBuilder normalizedValueBuffer = new StringBuilder(), source = new StringBuilder( + originalValue); + sourceLength = source.length(); + while (state != END && state != ERROR) { + if (currentCharIndex < sourceLength) { + currentChar = source.charAt(currentCharIndex++); + switch (currentChar) { + case '\r': + switch (state) { + case KEEPING: + normalizedValueBuffer.append(currentChar); + state = KEEPING_R; + break; + case SKIPING: + state = SKIPING_R; + break; + default: + state = ERROR; + } + break; + case '\n': + currentLineIndex++; + switch (state) { + case KEEPING: // tolerate Linux line delimiters + case KEEPING_R: + normalizedValueBuffer.append(currentChar); + if (currentLineIndex == this.first) { + state = SKIPING; + } + break; + case SKIPING: // tolerate Linux line delimiters + case SKIPING_R: + // in effect, we tolerate too big first and number + // values + if (currentLineIndex >= this.first + this.number) { + if (currentCharIndex < sourceLength) + normalizedValueBuffer.append(source + .substring(currentCharIndex)); + state = END; + } else { + state = SKIPING; + } + break; + default: + state = ERROR; + } + break; + default: + switch (state) { + case KEEPING: + normalizedValueBuffer.append(currentChar); + break; + case SKIPING: + break; + default: + state = ERROR; + } + + } + } + else if (currentChar == '\n') + state = END; + else + state = ERROR; + } + if (state == ERROR) + normalizedValueBuffer + .append("UNEXPECTED ERROR in LinesRangeNormalizer"); + result = super.normalized(normalizedValueBuffer.toString()); + } + return result; + } + } + + /** + * Normalizer instance for non XML log files. + */ + private static Normalizer textLogsNormalizer = new StringNormalizer( + new XMLClasspathsSectionNormalizer(new LinesRangeNormalizer(null, + 0, 2)), OUTPUT_DIR, OUTPUT_DIR_PLACEHOLDER); + + /** + * Normalizer instance for XML log files. + */ + private static Normalizer xmlLogsNormalizer = new StringNormalizer( + new XMLClasspathsSectionNormalizer(new LinesRangeNormalizer(null, + 1, 1)), OUTPUT_DIR, OUTPUT_DIR_PLACEHOLDER); + + +public void test001() { + + String commandLine = "-classpath \"D:/a folder\";d:/jdk1.4/jre/lib/rt.jar -1.4 -preserveAllLocals -g -verbose d:/eclipse/workspaces/development2.0/plugins/Bar/src2/ -d d:/test"; + String expected = " <-classpath> <-1.4> <-preserveAllLocals> <-g> <-verbose> <-d> "; + + String[] args = Main.tokenize(commandLine); + StringBuilder buffer = new StringBuilder(30); + for (int i = 0; i < args.length; i++){ + buffer.append(" <"+args[i]+">"); + } + String result = buffer.toString(); + //System.out.println(Util.displayString(result, 2)); + assertEquals("incorrect tokenized command line", + expected, + result); +} +public void test002() { + + String commandLine = "-classpath \"a folder\";\"b folder\""; + String expected = " <-classpath> "; + + String[] args = Main.tokenize(commandLine); + StringBuilder buffer = new StringBuilder(30); + for (int i = 0; i < args.length; i++){ + buffer.append(" <"+args[i]+">"); + } + String result = buffer.toString(); + //System.out.println(Util.displayString(result, 2)); + assertEquals("incorrect tokenized command line", + expected, + result); +} +public void test003() { + + String commandLine = "-classpath \"a folder;b folder\""; + String expected = " <-classpath> "; + + String[] args = Main.tokenize(commandLine); + StringBuilder buffer = new StringBuilder(30); + for (int i = 0; i < args.length; i++){ + buffer.append(" <"+args[i]+">"); + } + String result = buffer.toString(); + //System.out.println(Util.displayString(result, 2)); + assertEquals("incorrect tokenized command line", + expected, + result); +} +public void test004() { + + String commandLine = "\"d:/tmp A/\"A.java -classpath \"d:/tmp A\";d:/jars/rt.jar -nowarn -time -g -d d:/tmp"; + String expected = " <-classpath> <-nowarn> <-time> <-g> <-d> "; + + String[] args = Main.tokenize(commandLine); + StringBuilder buffer = new StringBuilder(30); + for (int i = 0; i < args.length; i++){ + buffer.append(" <"+args[i]+">"); + } + String result = buffer.toString(); + //System.out.println(Util.displayString(result, 2)); + assertEquals("incorrect tokenized command line", + expected, + result); +} +public void test005() { + + String commandLine = "\"d:/tmp A/\"A.java -classpath d:/jars/rt.jar;\"d:/tmp A\";\"toto\" -nowarn -time -g -d d:/tmp"; + String expected = " <-classpath> <-nowarn> <-time> <-g> <-d> "; + + String[] args = Main.tokenize(commandLine); + StringBuilder buffer = new StringBuilder(30); + for (int i = 0; i < args.length; i++){ + buffer.append(" <"+args[i]+">"); + } + String result = buffer.toString(); + //System.out.println(Util.displayString(result, 2)); + assertEquals("incorrect tokenized command line", + expected, + result); +} +public void test006() { + + String commandLine = "\"d:/tmp A/A.java\" -classpath d:/jars/rt.jar;\"d:/tmp A\";d:/tmpB/ -nowarn -time -g -d d:/tmp"; + String expected = " <-classpath> <-nowarn> <-time> <-g> <-d> "; + + String[] args = Main.tokenize(commandLine); + StringBuilder buffer = new StringBuilder(30); + for (int i = 0; i < args.length; i++){ + buffer.append(" <"+args[i]+">"); + } + String result = buffer.toString(); + //System.out.println(Util.displayString(result, 2)); + assertEquals("incorrect tokenized command line", + expected, + result); +} +// test the tester - runConformTest +public void test007(){ + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" + + ")\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (false) {\n" + + " ;\n" + + " } else {\n" + + " }\n" + + " // Zork z;\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -bootclasspath " + getLibraryClassesAsQuotedString() + + " -cp " + getJCEJarAsQuotedString() + + " -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal" + + " -verbose -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "[parsing ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" + + "[reading java/lang/Object.class]\n" + + "[analyzing ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" + + "[reading java/util/List.class]\n" + + "[reading java/lang/SuppressWarnings.class]\n" + + "[reading java/lang/String.class]\n" + + "[writing X.class - #1]\n" + + "[completed ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" + + "[1 unit compiled]\n" + + "[1 .class file generated]\n", + "", // changed with bug 123522: now the SuppressWarning upon the first type + // influences warnings on unused imports + true); +} +// test the tester - runNegativeTest +public void test008(){ + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" + + ")\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (false) {\n" + + " ;\n" + + " } else {\n" + + " }\n" + + " Zork z;\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -bootclasspath " + getLibraryClassesAsQuotedString() + + " -cp " + getJCEJarAsQuotedString() + + " -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "1 problem (1 error)\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=92398 -- a case that works, another that does not +// revisit this test case depending on https://bugs.eclipse.org/bugs/show_bug.cgi?id=95349 +public void test009(){ + this.runNegativeTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + " OK1 ok1;\n" + + " OK2 ok2;\n" + + " Warn warn;\n" + + " KO ko;\n" + + " Zork z;\n" + + "}", + "OK1.java", + "/** */\n" + + "public class OK1 {\n" + + " // empty\n" + + "}", + "OK2.java", + "/** */\n" + + "public class OK2 {\n" + + " // empty\n" + + "}", + "Warn.java", + "/** */\n" + + "public class Warn {\n" + + " // empty\n" + + "}", + "KO.java", + "/** */\n" + + "public class KO {\n" + + " // empty\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -cp \"" + OUTPUT_DIR + "[+OK2" + File.pathSeparator + "~Warn" + + File.pathSeparator + "-KO]\"" + + " -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + + " Warn warn;\n" + + " ^^^^\n" + + "Discouraged access: The type \'Warn\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---\')\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 6)\n" + + " KO ko;\n" + + " ^^\n" + + "Access restriction: The type \'KO\' is not API (restriction on classpath entry \'---OUTPUT_DIR_PLACEHOLDER---\')\n" + + "----------\n" + + "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3 problems (1 error, 2 warnings)\n", + true); +} +// command line - no user classpath nor bootclasspath +public void test010(){ + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" + + ")\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (false) {\n" + + " ;\n" + + " } else {\n" + + " }\n" + + " // Zork z;\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -verbose -warn:+deprecation,syntheticAccess,uselessTypeCheck,unsafe,finalBound,unusedLocal" + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "[parsing ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" + + "[reading java/lang/Object.class]\n" + + "[analyzing ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" + + "[reading java/util/List.class]\n" + + "[reading java/lang/SuppressWarnings.class]\n" + + "[reading java/lang/String.class]\n" + + "[writing X.class - #1]\n" + + "[completed ---OUTPUT_DIR_PLACEHOLDER---/X.java - #1/1]\n" + + "[1 unit compiled]\n" + + "[1 .class file generated]\n", + "", + true); +} +// command line - unusual classpath (ends with ';', still OK) +public void test011_classpath(){ + this.runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -g -preserveAllLocals" + + " -cp \"" + OUTPUT_DIR + "[+**/OK2;~**/Warn;-KO]" + + "\"" + File.pathSeparator + + " -proceedOnError -referenceInfo -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} +private String getVersionOptions() { + StringBuilder builder = new StringBuilder(); + String template = " -15 -15.0 use 15 compliance (-source 15 -target 15)\n"; + for(int i = ClassFileConstants.MAJOR_VERSION_15; i <= ClassFileConstants.MAJOR_LATEST_VERSION; i++) { + builder.append(template.replace("15", "" + (i - ClassFileConstants.MAJOR_VERSION_0))); + } + return builder.toString(); +} +// command line - help +// amended for https://bugs.eclipse.org/bugs/show_bug.cgi?id=141512 (checking +// width) +public void test012(){ + final String expectedOutput = + "{0} {1}\n" + + "{2}\n" + + " \n" + + " Usage: \n" + + " If directories are specified, then their source contents are compiled.\n" + + " Possible options are listed below. Options enabled by default are prefixed\n" + + " with ''+''.\n" + + " \n" + + " Classpath options:\n" + + " -cp -classpath \n" + + " specify location for application classes and sources.\n" + + " Each directory or file can specify access rules for\n" + + " types between ''['' and '']'' (e.g. [-X] to forbid\n" + + " access to type X, [~X] to discourage access to type X,\n" + + " [+p/X" + File.pathSeparator + "-p/*] to forbid access to all types in package p\n" + + " but allow access to p/X)\n" + + " -bootclasspath \n" + + " specify location for system classes. Each directory or\n" + + " file can specify access rules for types between ''[''\n" + + " and '']''\n" + + " -sourcepath \n" + + " specify location for application sources. Each directory\n" + + " or file can specify access rules for types between ''[''\n" + + " and '']''. Each directory can further specify a specific\n" + + " destination directory using a ''-d'' option between ''[''\n" + + " and '']''; this overrides the general ''-d'' option.\n" + + " .class files created from source files contained in a\n" + + " jar file are put in the user.dir folder in case no\n" + + " general ''-d'' option is specified. ZIP archives cannot\n" + + " override the general ''-d'' option\n" + + " -extdirs \n" + + " specify location for extension ZIP archives\n" + + " -endorseddirs \n" + + " specify location for endorsed ZIP archives\n" + + " -d destination directory (if omitted, no directory is\n" + + " created); this option can be overridden per source\n" + + " directory\n" + + " -d none generate no .class files\n" + + " -encoding specify default encoding for all source files. Each\n" + + " file/directory can override it when suffixed with\n" + + " ''['''']'' (e.g. X.java[utf8]).\n" + + " If multiple default encodings are specified, the last\n" + + " one will be used.\n" + + " \n" + + " Module compilation options:\n" + + " These options are meaningful only in Java 9 environment or later.\n" + + " --module-source-path \n" + + " specify where to find source files for multiple modules\n" + + " -p --module-path \n" + + " specify where to find application modules\n" + + " --processor-module-path \n" + + " specify module path where annotation processors\n" + + " can be found\n" + + " --system Override location of system modules\n" + + " --add-exports /=(,)*\n" + + " specify additional package exports clauses to the\n" + + " given modules\n" + + " --add-reads =(,)*\n" + + " specify additional modules to be considered as required\n" + + " by given modules\n" + + " --add-modules (,)*\n" + + " specify the additional module names that should be\n" + + " resolved to be root modules\n" + + " --limit-modules (,)*\n" + + " specify the observable module names\n" + + " --release compile for a specific VM version\n" + + " \n" + + " Compliance options:\n" + + " -1.3 use 1.3 compliance (-source 1.3 -target 1.1)\n" + + " -1.4 + use 1.4 compliance (-source 1.3 -target 1.2)\n" + + " -1.5 -5 -5.0 use 1.5 compliance (-source 1.5 -target 1.5)\n" + + " -1.6 -6 -6.0 use 1.6 compliance (-source 1.6 -target 1.6)\n" + + " -1.7 -7 -7.0 use 1.7 compliance (-source 1.7 -target 1.7)\n" + + " -1.8 -8 -8.0 use 1.8 compliance (-source 1.8 -target 1.8)\n" + + " -1.9 -9 -9.0 use 1.9 compliance (-source 1.9 -target 1.9)\n" + + " -10 -10.0 use 10 compliance (-source 10 -target 10)\n" + + " -11 -11.0 use 11 compliance (-source 11 -target 11)\n" + + " -12 -12.0 use 12 compliance (-source 12 -target 12)\n" + + " -13 -13.0 use 13 compliance (-source 13 -target 13)\n" + + " -14 -14.0 use 14 compliance (-source 14 -target 14)\n" + + getVersionOptions() + + " -source set source level: 1.3 to 1.9, 10 to "+ CompilerOptions.getLatestVersion() +"\n" + + " (or 6, 6.0, etc)\n" + + " -target set classfile target: 1.3 to 1.9, 10 to "+ CompilerOptions.getLatestVersion() +"\n" + + " (or 6, 6.0, etc)\n" + + " cldc1.1 can also be used to generate the StackMap\n" + + " attribute\n" + + " --enable-preview enable support for preview features of the\n" + + " latest Java release\n" + + " \n" + + " Warning options:\n" + + " -deprecation + deprecation outside deprecated code (equivalent to\n" + + " -warn:+deprecation)\n" + + " -nowarn -warn:none disable all warnings\n" + + " -nowarn:[]\n" + + " specify directories from which optional problems should\n" + + " be ignored\n" + + " -?:warn -help:warn display advanced warning options\n" + + " \n" + + " Error options:\n" + + " -err: convert exactly the listed warnings\n" + + " to be reported as errors\n" + + " -err:+ enable additional warnings to be\n" + + " reported as errors\n" + + " -err:- disable specific warnings to be\n" + + " reported as errors\n" + + " \n" + + " Info options:\n" + + " -info: convert exactly the listed warnings\n" + + " to be reported as infos\n" + + " -info:+ enable additional warnings to be\n" + + " reported as infos\n" + + " -info:- disable specific warnings to be\n" + + " reported as infos\n" + + " \n" + + " Setting warning, error or info options using properties file:\n" + + " -properties set warnings/errors/info option based on the properties\n" + + " file contents. This option can be used with -nowarn,\n" + + " -err:.., -info: or -warn:.. options, but the last one\n" + + " on the command line sets the options to be used.\n" + + " \n" + + " Debug options:\n" + + " -g[:lines,vars,source] custom debug info\n" + + " -g:lines,source + both lines table and source debug info\n" + + " -g all debug info\n" + + " -g:none no debug info\n" + + " -preserveAllLocals preserve unused local vars for debug purpose\n" + + " \n" + + " Annotation processing options:\n" + + " These options are meaningful only in a 1.6 environment.\n" + + " -Akey[=value] options that are passed to annotation processors\n" + + " -processorpath \n" + + " specify locations where to find annotation processors.\n" + + " If this option is not used, the classpath will be\n" + + " searched for processors\n" + + " -processor \n" + + " qualified names of the annotation processors to run.\n" + + " This bypasses the default annotation discovery process\n" + + " -proc:only run annotation processors, but do not compile\n" + + " -proc:none perform compilation but do not run annotation\n" + + " processors\n" + + " -s destination directory for generated source files\n" + + " -XprintProcessorInfo print information about which annotations and elements\n" + + " a processor is asked to process\n" + + " -XprintRounds print information about annotation processing rounds\n" + + " -classNames \n" + + " qualified names of binary classes to process\n" + + " \n" + + " Advanced options:\n" + + " @ read command line arguments from file\n" + + " -maxProblems max number of problems per compilation unit (100 by\n" + + " default)\n" + + " -log log to a file. If the file extension is ''.xml'', then\n" + + " the log will be a xml file.\n" + + " -proceedOnError[:Fatal]\n" + + " do not stop at first error, dumping class files with\n" + + " problem methods\n" + + " With \":Fatal\", all optional errors are treated as fatal\n" + + " -failOnWarning fail compilation if there are warnings\n" + + " -verbose enable verbose output\n" + + " -referenceInfo compute reference info\n" + + " -progress show progress (only in -log mode)\n" + + " -time display speed information \n" + + " -noExit do not call System.exit(n) at end of compilation (n==0\n" + + " if no error)\n" + + " -repeat repeat compilation process times for perf analysis\n" + + " -inlineJSR inline JSR bytecode (implicit if target >= 1.5)\n" + + " -enableJavadoc consider references in javadoc\n" + + " -parameters generate method parameters attribute (for target >= 1.8)\n" + + " -genericsignature generate generic signature for lambda expressions\n" + + " -Xemacs used to enable emacs-style output in the console.\n" + + " It does not affect the xml log output\n" + + " -missingNullDefault report missing default nullness annotation\n" + + " -annotationpath \n" + + " specify locations where to find external annotations\n" + + " to support annotation-based null analysis.\n" + + " The special name CLASSPATH will cause lookup of\n" + + " external annotations from the classpath and sourcepath.\n" + + " \n" + + " -? -help print this help message\n" + + " -v -version print compiler version\n" + + " -showversion print compiler version and continue\n" + + " \n" + + " Ignored options:\n" + + " -J A adapt(Class type) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + null, + lib1Path, + JavaCore.VERSION_1_5); + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " Bundle b = Bundle.adapt(BundleWiring.class);\n" + + "}\n" + + "class BundleWiring {}\n", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -cp lib1.jar" // relative + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.4 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 2)\n" + + " Bundle b = Bundle.adapt(BundleWiring.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Bundle\n" + + "----------\n" + + "1 problem (1 error)\n", + true); + } catch (IOException e) { + System.err.println("BatchCompilerTest#testInference14 could not write to current working directory " + currentWorkingDirectoryPath); + } finally { + new File(lib1Path).delete(); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328775 - Compiler fails to warn about invalid cast in 1.4 mode. +public void testInferenceIn15Project(){ // ensure 1.5 complains too + String currentWorkingDirectoryPath = System.getProperty("user.dir"); + if (currentWorkingDirectoryPath == null) { + fail("BatchCompilerTest#testInference14 could not access the current working directory " + currentWorkingDirectoryPath); + } else if (!new File(currentWorkingDirectoryPath).isDirectory()) { + fail("BatchCompilerTest#testInference14 current working directory is not a directory " + currentWorkingDirectoryPath); + } + String lib1Path = currentWorkingDirectoryPath + File.separator + "lib1.jar"; + try { + Util.createJar( + new String[] { + "Bundle.java", + "public class Bundle {\n" + + " static A adapt(Class type) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + null, + lib1Path, + JavaCore.VERSION_1_5); + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " Bundle b = Bundle.adapt(BundleWiring.class);\n" + + "}\n" + + "class BundleWiring {}\n", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -cp lib1.jar" // relative + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 2)\n" + + " Bundle b = Bundle.adapt(BundleWiring.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from BundleWiring to Bundle\n" + + "----------\n" + + "1 problem (1 error)\n", + true); + } catch (IOException e) { + System.err.println("BatchCompilerTest#testInference14 could not write to current working directory " + currentWorkingDirectoryPath); + } finally { + new File(lib1Path).delete(); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=186565 Test interaction between 1.4 and 1.5 class files +public void test186565(){ + String outputDirName = OUTPUT_DIR + File.separator + "d", + metaInfDirName = outputDirName + File.separator + "META-INF", + jarFileName = outputDirName + File.separator + "classB15.jar"; + this.runConformTest( + new String[] { + "d/B.java", + "public class B extends A {\n" + + "}", + "d/A.java", + "public class A {\n" + + "}", + }, + "\"" + outputDirName + "\"" + + " -1.5 -g -preserveAllLocals" + + " -d \"" + outputDirName + "\"", + "", + "", + true /* flush output directory */); + File outputDirectory = new File(outputDirName); + File metaInfDirectory = new File(metaInfDirName); + metaInfDirectory.mkdirs(); + try { + Util.createFile(metaInfDirName + File.separator + "MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Class-Path: ../d/classB15.jar\n"); + } catch (IOException e) { + fail("could not create manifest file"); + } + Util.delete(outputDirName + File.separator + "A.class"); + Util.delete(outputDirName + File.separator + "A.java"); + try { + Util.zip(outputDirectory, jarFileName); + } catch (IOException e) { + fail("could not create jar file"); + } + Util.delete(outputDirName + File.separator + "B.class"); + Util.delete(outputDirName + File.separator + "B.java"); + this.runConformTest( + new String[] { + "d/A.java", + "public class A {\n" + + "}", + "d/C.java", + "public class C extends B {\n" + + "}", + }, + "\"" + outputDirName + "\"" + + " -1.5 -g -preserveAllLocals" + + " -cp \"" + jarFileName + "\"" + + " -d \"" + OUTPUT_DIR + "\"", + "", + "", + false /* do not flush output directory */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=330347 - Test retention of bridge methods. +public void testBridgeMethodRetention(){ + String currentWorkingDirectoryPath = System.getProperty("user.dir"); + if (currentWorkingDirectoryPath == null) { + fail("BatchCompilerTest#testBridgeMethodRetention could not access the current working directory " + currentWorkingDirectoryPath); + } else if (!new File(currentWorkingDirectoryPath).isDirectory()) { + fail("BatchCompilerTest#testBridgeMethodRetention current working directory is not a directory " + currentWorkingDirectoryPath); + } + String lib1Path = currentWorkingDirectoryPath + File.separator + "lib1.jar"; + try { + Util.createJar( + new String[] { + "Comparable.java", + "public interface Comparable {\n" + + " public int compareTo(T o);\n" + + "}\n", + "Character.java", + "public class Character implements Comparable {\n" + + " public int compareTo(Character obj) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + }, + null, + lib1Path, + JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "src/X.java", + "public class X {\n" + + " Object fValue;\n" + + " public int compareTo(Object obj) {\n" + + " return ((Character)fValue).compareTo(obj);\n" + + " }\n" + + "}\n", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -cp lib1.jar" // relative + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.4 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); + } catch (IOException e) { + System.err.println("BatchCompilerTest#testBridgeMethodRetention could not write to current working directory " + currentWorkingDirectoryPath); + } finally { + new File(lib1Path).delete(); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 -- with new option kicking in +public void testReportingUnavoidableGenericProblems() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Adaptable {\n" + + " public Object getAdapter(Class clazz); \n" + + "}\n" + + "public class X implements Adaptable {\n" + + " public Object getAdapter(Class clazz) {\n" + + " return null;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -warn:-unavoidableGenericProblems -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" + + " public Object getAdapter(Class clazz); \n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2 problems (1 error, 1 warning)\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 -- without new option kicking in +public void testReportingUnavoidableGenericProblems2() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Adaptable {\n" + + " public Object getAdapter(Class clazz); \n" + + "}\n" + + "public class X implements Adaptable {\n" + + " public Object getAdapter(Class clazz) {\n" + + " return null;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -1.5 -warn:+unavoidableGenericProblems -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" + + " public Object getAdapter(Class clazz); \n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + + " public Object getAdapter(Class clazz) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3 problems (1 error, 2 warnings)\n", + true); +} +//-warn option - regression tests +public void test0308_warn_options() { + // check the option introduced in bug 359721 + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo() throws java.io.IOException {\n" + + " FileReader r = new FileReader(\"f1\");\n" + + " char[] cs = new char[1024];\n" + + " r.read(cs);\n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -warn:-resource -1.7 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} +//-warn option - regression tests +public void test0309_warn_options() { + // check the option introduced in bug 359721 + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo(boolean b) throws java.io.IOException {\n" + + " FileReader r = new FileReader(\"f1\");\n" + + " char[] cs = new char[1024];\n" + + " r.read(cs);\n" + + " if (b) r.close();\n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -warn:+resource -1.7 -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 4)\n" + + " FileReader r = new FileReader(\"f1\");\n" + + " ^\n" + + "Potential resource leak: \'r\' may not be closed\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=366829 +// -warn option - regression test to check option syncOverride +// Warning when when a class overrides a synchronized method without synchronizing it +public void test310_warn_options() { + this.runConformTest( + new String[] { + "X.java", + "class X { synchronized void foo() {} }\n" + + "class Y extends X { @Override void foo() { } }" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -warn:syncOverride -1.5 -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" + + " class Y extends X { @Override void foo() { } }\n" + + " ^^^^^\n" + + "The method Y.foo() is overriding a synchronized method without being synchronized\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=366829 +// -warn option - regression test to check option syncOverride +// Warning when when a class overrides a synchronized method without synchronizing it +public void test310b_warn_options() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar() { new X() { @Override void foo() {} }; }\n"+ + " synchronized void foo() { }\n"+ + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -warn:syncOverride -1.5 -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" + + " void bar() { new X() { @Override void foo() {} }; }\n"+ + " ^^^^^\n" + + "The method new X(){}.foo() is overriding a synchronized method without being synchronized\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342 +// -warn option - regression tests to check option nullAnnot (with args) +// Null warnings because of annotations - custom annotation types used - challenging various kinds of diagnostics +public void test312_warn_options() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@SuppressWarnings(\"unused\")\n" + + "public class X {\n" + + " public void test() { Object o = null; o.toString();}\n" + + " @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" + + " if (o.toString() == \"\"){ return null;}\n" + + " if (o2 == null) {}\n" + + " goo(null).toString();\n" + + " Object local = null;\n" + + " o.toString();\n" + + " return null;\n" + + " }\n" + + " @Nullable Object goo(@NonNull Object o2) {\n" + + " return new Object();\n" + + " }\n" + + " @NonNullByDefault Object hoo(Object o2) {\n" + + " if (o2 == null){}\n" + + " if (o2 == null){\n" + + " return null;\n" + + " }\n" + + " return new Object();\n" + + " }\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface NonNull{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface Nullable{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" + + "@interface NonNullByDefault{\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" +// + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+nullAnnot(p.Nullable|p.NonNull|p.NonNullByDefault) -warn:+null -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 6)\n" + + " public void test() { Object o = null; o.toString();}\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" + + " if (o.toString() == \"\"){ return null;}\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n" + + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 8)\n" + + " if (o.toString() == \"\"){ return null;}\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " if (o2 == null) {}\n" + + " ^^\n" + + "Null comparison always yields false: The variable o2 is specified as @NonNull\n" + + "----------\n" + + "5. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 10)\n" + + " goo(null).toString();\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: The method goo(Object) may return null\n" + + "----------\n" + + "6. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 10)\n" + + " goo(null).toString();\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "7. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 13)\n" + + " return null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "8. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 19)\n" + + " if (o2 == null){}\n" + + " ^^\n" + + "Null comparison always yields false: The variable o2 is specified as @NonNull\n" + + "----------\n" + + "9. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 20)\n" + + " if (o2 == null){\n" + + " ^^\n" + + "Null comparison always yields false: The variable o2 is specified as @NonNull\n" + + "----------\n" + + "9 problems (9 warnings)\n", + true); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +// -warn/-error option : enumSwitchPedantic +public void test317_warn_options() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "enum Color { RED, GREEN };\n" + + "public class X {\n" + + " int getVal(Color c) {\n" + + " switch (c) {\n" + + " case RED: return 1;\n" + + " default : return 0;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+enumSwitchPedantic -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 5)\n" + + " switch (c) {\n" + + " ^\n" + + "The enum constant GREEN should have a corresponding case label in this enum switch on Color. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +// -warn/-error option : enumSwitchPedantic: increase severity to ERROR +public void test318_warn_options() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "enum Color { RED, GREEN };\n" + + "public class X {\n" + + " int getVal(Color c) {\n" + + " switch (c) {\n" + + " case RED: return 1;\n" + + " default : return 0;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -err:+enumSwitchPedantic -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 5)\n" + + " switch (c) {\n" + + " ^\n" + + "The enum constant GREEN should have a corresponding case label in this enum switch on Color. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'\n" + + "----------\n" + + "1 problem (1 error)\n", + true); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +// -warn/-error option : switchDefault +public void test319_warn_options() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "enum Color { RED, GREEN };\n" + + "public class X {\n" + + " int getVal(Color c) {\n" + + " switch (c) {\n" + + " case RED: return 1;\n" + + " case GREEN : return 2;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+switchDefault -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 5)\n" + + " switch (c) {\n" + + " ^\n" + + "The switch over the enum type Color should have a default case\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//default +public void test317_nowarn_options() { + this.runConformTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[\"" + + OUTPUT_DIR + File.separator + "src" + + "\"] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//two different source folders ignore only from one +public void test318_nowarn_options() { + this.runConformTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + "src2/Y.java", + "public class Y {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src2/Y.java\"" + + " -warn:javadoc -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src" + + "\"] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src2/Y.java (at line 3)\n" + + " @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//two different source folders ignore from both +public void test319_nowarn_options() { + this.runConformTest( + new String[] { + "src1/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + "src2/Y.java", + "public class Y {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "src1/X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src2/Y.java\"" + + " -warn:javadoc -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src1\"" + File.pathSeparator + + "\"" + OUTPUT_DIR + File.separator + + "src2\"] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//two different source folders ignore from both using multiple -nowarn +public void test320_nowarn_options() { + this.runConformTest( + new String[] { + "src1/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + "src2/Y.java", + "public class Y {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "src1/X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src2/Y.java\"" + + " -warn:javadoc -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src1\"] -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src2\"] " + + "-proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn: +public void test321_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn: -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn:[ +public void test322_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[ -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:[\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn:[src +public void test323_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[src -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:[src\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn:src] +public void test324_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:src] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:src]\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn[src] +public void test325_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn[src] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn[src]\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn:[src1]src2 +public void test326_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[src1]src2 -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:[src1]src2\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//option syntax error -nowarn:[] +public void test327_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[] -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "invalid syntax for nowarn option: -nowarn:[]\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//non-optional errors cannot be ignored +public void test328_nowarn_options() { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " a++;\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src]\" -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 6)\n" + + " a++;\n" + + " ^\n" + + "a cannot be resolved to a variable\n" + + "----------\n" + + "1 problem (1 error)\n", + true); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220928 +//-nowarn option - regression tests +//task tags cannot be ignored +public void test329_nowarn_options() { + this.runConformTest( + new String[] { + "src/X.java", + "public class X {\n" + + " /**\n" + + " @param\n" + + " */\n" + + " public void foo() {\n" + + " // TODO nothing\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -warn:javadoc,tasks(TODO) -nowarn:[" + + "\"" + OUTPUT_DIR + File.separator + "src]\" -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 6)\n" + + " // TODO nothing\n" + + " ^^^^^^^^^^^^\n" + + "TODO nothing\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=408815 +// -warn option - regression tests to check option unlikelyCollectionMethodArgumentType +public void test330_warn_options() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " Integer foo(Map map) {\n" + + " return map.get(3);\n" + + " }\n" + + "}\n", + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:-unlikelyCollectionMethodArgumentType -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +}//https://bugs.eclipse.org/bugs/show_bug.cgi?id=408815 +//-warn option - regression tests to check option unlikelyEqualsArgumentType +public void test331_warn_options() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " boolean foo() {\n" + + " return \"three\".equals(3);\n" + + " }\n" + + "}\n", + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -info:-unlikelyEqualsArgumentType -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375409 +public void testBug375409a() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + "/** \n" + + "* Description {@see String}, {@category cat}\n" + + "* @param a\n" + + "*/\n" + + "public void foo(int i) {}}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:invalidJavadoc -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 4)\n" + + " * Description {@see String}, {@category cat}\n" + + " ^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 4)\n" + + " * Description {@see String}, {@category cat}\n" + + " ^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 5)\n" + + " * @param a\n" + + " ^\n" + + "Javadoc: Parameter a is not declared\n" + + "----------\n" + + "3 problems (3 warnings)\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375409 +public void testBug375409b() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + "/** \n" + + "* Description {@see String}, {@category cat}\n" + + "* @param a\n" + + "*/\n" + + "public void foo(int i) {}}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:missingJavadocTags,missingJavadocTagsVisibility(public) -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 7)\n" + + " public void foo(int i) {}}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter i\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375409 +public void testBug375409c() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + "/** \n" + + "* Description {@see String}, {@category cat}\n" + + "* @param a\n" + + "*/\n" + + "public void foo(int i) {}}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:missingJavadocComments -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 2)\n" + + " public class X {\n" + + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375409 +public void testBug375409d() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + "/** \n" + + "* Description {@see String}, {@category cat}\n" + + "* @param a\n" + + "*/\n" + + "void foo(int i) {}\n" + + "/** \n" + + "* Description {@see String}, {@category cat}\n" + + "* @param a\n" + + "*/\n" + + "public void foo2(int i2) {}}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:missingJavadocTags,missingJavadocTagsVisibility(public) -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 12)\n" + + " public void foo2(int i2) {}}\n" + + " ^^\n" + + "Javadoc: Missing tag for parameter i2\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375409 +// -warn option - regression tests to check option nullAnnotConflict +public void testBug375409e() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" + + " Object o3 = new X().bar();\n" + // need a local to involve flow analysis + " return o3;\n" + + " }\n" + + " @Nullable Object bar() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface NonNull{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface Nullable{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" + + "@interface NonNullByDefault{\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -1.5" + + " -warn:+nullAnnot(p.Nullable|p.NonNull|p.NonNullByDefault),+null,-nullAnnotConflict " + + "-proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375409 +// -warn option - regression tests to check option nullAnnotRedundant +public void testBug375409f() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@NonNullByDefault public class X {\n" + + " @NonNull Object foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface NonNull{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface Nullable{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" + + "@interface NonNullByDefault{\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -1.5" + + " -warn:+nullAnnot(p.Nullable|p.NonNull|p.NonNullByDefault),+null,-nullAnnotRedundant " + + "-proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 6)\n" + + " return null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375409 +// -warn option - regression tests to check option nullUncheckedConversion +public void testBug375409g() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" + + " return new X().bar();\n" + + " }\n" + + " Object bar() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface NonNull{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface Nullable{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" + + "@interface NonNullByDefault{\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -1.5" + + " -warn:+nullAnnot(p.Nullable|p.NonNull|p.NonNullByDefault) -warn:+null -warn:-nullUncheckedConversion " + + "-proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} + + +// Bug 375366 - ECJ ignores unusedParameterIncludeDocCommentReference unless enableJavadoc option is set +// when -properties is used process javadoc by default +public void testBug375366a() throws IOException { + createOutputTestDirectory("regression/.settings"); + Util.createFile(OUTPUT_DIR+"/.settings/org.eclipse.jdt.core.prefs", + "eclipse.preferences.version=1\n" + + "org.eclipse.jdt.core.compiler.problem.unusedParameter=warning\n"); + this.runConformTest( + new String[] { + "bugs/warning/ShowBug.java", + "package bugs.warning;\n" + + "\n" + + "public class ShowBug {\n" + + " /**\n" + + " * \n" + + " * @param unusedParam\n" + + " */\n" + + " public void foo(Object unusedParam) {\n" + + " \n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "bugs" + File.separator + "warning" + File.separator + "ShowBug.java\"" + + " -1.5" + + " -properties " + OUTPUT_DIR + File.separator +".settings" + File.separator + "org.eclipse.jdt.core.prefs " + + " -d \"" + OUTPUT_DIR + "\"", + "", + "", + false /*don't flush output dir*/); +} + +// Bug 375366 - ECJ ignores unusedParameterIncludeDocCommentReference unless enableJavadoc option is set +// property file explicitly disables javadoc processing +public void testBug375366b() throws IOException { + createOutputTestDirectory("regression/.settings"); + Util.createFile(OUTPUT_DIR+"/.settings/org.eclipse.jdt.core.prefs", + "eclipse.preferences.version=1\n" + + "org.eclipse.jdt.core.compiler.problem.unusedParameter=warning\n" + + "org.eclipse.jdt.core.compiler.doc.comment.support=disabled\n"); + this.runTest( + true, // compile OK, expecting only warning + new String[] { + "bugs/warning/ShowBug.java", + "package bugs.warning;\n" + + "\n" + + "public class ShowBug {\n" + + " /**\n" + + " * \n" + + " * @param unusedParam\n" + + " */\n" + + " public void foo(Object unusedParam) {\n" + + " \n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "bugs" + File.separator + "warning" + File.separator + "ShowBug.java\"" + + " -1.5" + + " -properties " + OUTPUT_DIR + File.separator +".settings" + File.separator + "org.eclipse.jdt.core.prefs " + + " -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/bugs/warning/ShowBug.java (at line 8)\n" + + " public void foo(Object unusedParam) {\n" + + " ^^^^^^^^^^^\n" + + "The value of the parameter unusedParam is not used\n" + + "----------\n" + + "1 problem (1 warning)\n", + false /*don't flush output dir*/, + null /* progress */); +} +// see also: +// org.eclipse.jdt.core.tests.compiler.regression.NullAnnotationBatchCompilerTest.testBug375366c() +// org.eclipse.jdt.core.tests.compiler.regression.NullAnnotationBatchCompilerTest.testBug375366d() + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780 +public void test385780_warn_option() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "public X() {\n"+ + "}\n"+ + "public void ph(int t) {\n"+ + "}\n"+ + "}\n"+ + "interface doNothingInterface {\n"+ + "}\n"+ + "class doNothing {\n"+ + "public void doNothingMethod() {"+ + "}\n"+ + "}\n"+ + "class noerror {\n"+ + "public void doNothing(T t) {"+ + "}"+ + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -warn:unusedTypeParameter -proc:none -1.7 -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "Unused type parameter T\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" + + " public X() {\n" + + " ^\n" + + "Unused type parameter S\n" + + "----------\n" + + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 7)\n" + + " interface doNothingInterface {\n" + + " ^\n" + + "Unused type parameter T\n" + + "----------\n" + + "4. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 10)\n" + + " public void doNothingMethod() {}\n" + + " ^\n" + + "Unused type parameter T\n" + + "----------\n" + + "4 problems (4 warnings)\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405225 +public void test405225_extdirs() { + if (AbstractCompilerTest.isJRE9Plus) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo() throws java.io.IOException {\n" + + " FileReader r = new FileReader(\"f1\");\n" + + " char[] cs = new char[1024];\n" + + " r.read(cs);\n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -warn:-resource -1.7 -extdirs \"" + LIB_DIR + "\" -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); +} +//Bug 408038 - Classes which implement Externalizable should not have an unused constructor warning +public void test408038a() { + this.runConformTest( + new String[] { + "externalizable/warning/X.java", + "package externalizable.warning;\n" + + "\n" + + "public class X {\n" + + " private class Y {\n" + + " static final int i = 10;\n" + + " public Y() {}\n" + + " public Y(int x) {System.out.println(x);}\n" + + " }\n" + + "\n" + + " public void zoo() {\n" + + " System.out.println(Y.i);\n" + + " Y y = new Y(5);\n" + + " System.out.println(y);\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "externalizable" + File.separator + "warning" + File.separator + "X.java\"" + + " -1.6 -d none", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/externalizable/warning/X.java (at line 6)\n" + + " public Y() {}\n" + + " ^^^\n" + + "The constructor X.Y() is never used locally\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} +//Bug 408038 - Classes which implement Externalizable should not have an unused constructor warning +public void test408038b() { + this.runConformTest( + new String[] { + "externalizable/warning/X.java", + "package externalizable.warning;\n" + + "\n" + + "public class X {\n" + + " private static class Y {\n" + + " static final int i = 10;\n" + + " public Y() {}\n" + + " public Y(int x) {System.out.println(x);}\n" + + " }\n" + + "\n" + + " public void zoo() {\n" + + " System.out.println(Y.i);\n" + + " Y y = new Y(5);\n" + + " System.out.println(y);\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "externalizable" + File.separator + "warning" + File.separator + "X.java\"" + + " -1.6 -d none", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/externalizable/warning/X.java (at line 6)\n" + + " public Y() {}\n" + + " ^^^\n" + + "The constructor X.Y() is never used locally\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} +//Bug 408038 - Classes which implement Externalizable should not have an unused constructor warning +public void test408038c() { + this.runConformTest( + new String[] { + "externalizable/warning/X.java", + "package externalizable.warning;\n" + + "import java.io.Externalizable;\n" + + "import java.io.IOException;\n" + + "import java.io.ObjectInput;\n" + + "import java.io.ObjectOutput;\n" + + "\n" + + "public class X {\n" + + " private static class Y implements Externalizable {\n" + + " static final int i = 10;\n" + + " public Y() {}\n" + + " public Y(int x) {System.out.println(x);}\n" + + "\n" + + " @Override\n" + + " public void writeExternal(ObjectOutput out) throws IOException {\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void readExternal(ObjectInput in) throws IOException,\n" + + " ClassNotFoundException {\n" + + " }\n" + + " }\n" + + "\n" + + " public void zoo() {\n" + + " System.out.println(Y.i);\n" + + " Y y = new Y(5);\n" + + " System.out.println(y);\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "externalizable" + File.separator + "warning" + File.separator + "X.java\"" + + " -1.6 -d none", + "", + "", + true); +} +//Bug 408038 - Classes which implement Externalizable should not have an unused constructor warning +public void test408038d() { + this.runConformTest( + new String[] { + "externalizable/warning/X.java", + "package externalizable.warning;\n" + + "import java.io.Externalizable;\n" + + "import java.io.IOException;\n" + + "import java.io.ObjectInput;\n" + + "import java.io.ObjectOutput;\n" + + "\n" + + "public class X {\n" + + " private class Y implements Externalizable {\n" + + " static final int i = 10;\n" + + " public Y() {}\n" + + " public Y(int x) {System.out.println(x);}\n" + + "\n" + + " @Override\n" + + " public void writeExternal(ObjectOutput out) throws IOException {\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void readExternal(ObjectInput in) throws IOException,\n" + + " ClassNotFoundException {\n" + + " }\n" + + " }\n" + + "\n" + + " public void zoo() {\n" + + " System.out.println(Y.i);\n" + + " Y y = new Y(5);\n" + + " System.out.println(y);\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "externalizable" + File.separator + "warning" + File.separator + "X.java\"" + + " -1.6 -d none", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/externalizable/warning/X.java (at line 10)\n" + + " public Y() {}\n" + + " ^^^\n" + + "The constructor X.Y() is never used locally\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} +// Bug 408038 - Classes which implement Externalizable should not have an unused constructor warning +// The test case is not directly related to the bug. It was discovered as a result +// of the bug. Please see comment 16 bullet 4 in bugzilla. +public void test408038e() { + this.runConformTest( + new String[] { + "externalizable/warning/X.java", + "package externalizable.warning;\n" + + "class X {\n" + + " int i;\n" + + " private X(int x) {i = x;}\n" + + " X() {}\n" + + " public int foo() {\n" + + " X x = new X();\n" + + " return x.i;\n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "externalizable" + File.separator + "warning" + File.separator + "X.java\"" + + " -1.6 -d none", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/externalizable/warning/X.java (at line 4)\n" + + " private X(int x) {i = x;}\n" + + " ^^^^^^^^\n" + + "The constructor X(int) is never used locally\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=419351 +public void testBug419351() { + String backup = System.getProperty("java.endorsed.dirs"); + if (backup == null) + return; // Don't bother running if it is JRE9, where there's no endorsed.dir + String endorsedPath = LIB_DIR + File.separator + "endorsed"; + new File(endorsedPath).mkdir(); + String lib1Path = endorsedPath + File.separator + "lib1.jar"; + try { + System.setProperty("java.endorsed.dirs", endorsedPath); + Util.createJar( + new String[] { + "java/lang/String.java", + "package java.lang;\n" + + "public class String {\n" + + " public String(java.lang.Object obj) {}\n" + + "}\n" + }, + null, + lib1Path, + JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "src/X.java", + "public class X {\n" + + " public void foo(Object obj) {\n" + + " java.lang.String str = new java.lang.String(obj);\n" + + " }\n" + + "}\n", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.4 -nowarn" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); + } catch (IOException e) { + } finally { + System.setProperty("java.endorsed.dirs", backup); + new File(endorsedPath).delete(); + new File(lib1Path).delete(); + } +} + +public void test501457() throws IOException { + this.runConformTest(new String[] { + "FailingClass.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.util.ArrayList;\n" + + "public class FailingClass {\n" + + " protected void test(MethodHandle handle) throws Throwable {\n" + + " handle.invoke(null, new ArrayList<>());\n" + + " }\n" + + "}\n" + }, + " -1.8 " + + " -sourcepath \"" + OUTPUT_DIR + "\" " + + "\"" + OUTPUT_DIR + File.separator + "FailingClass.java", + "", + "", + true + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=439750 +public void test439750() { + this.runConformTest( + new String[] { + "externalizable/warning/X.java", + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "class X {\n" + + " public static void main(String[] args) {\n" + + " FileInputStream fis = null;\n" + + " try {\n" + + " fis = new FileInputStream(\"xyz\");\n" + + " System.out.println(\"fis\");\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " } finally {\n" + + " try {\n" + + " if (fis != null) fis.close();\n" + + " } catch (Exception e) {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "externalizable" + File.separator + "warning" + File.separator + "X.java\"" + + " -1.6 -warn:unused -warn:unusedExceptionParam -d none", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/externalizable/warning/X.java (at line 14)\n" + + " } catch (Exception e) {}\n" + + " ^\n" + + "The value of the exception parameter e is not used\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); +} + +/** + * A fast exit/result is expected when secondary types are searched with the reserved class name "package-info", + * because there can not exist a secondary type with the name "package-info", because it is a reserved class name. + * This fast exit improves the performance, because the search for secondary types is very expensive regarding performance + * (all classes of a package have to get loaded, parsed and analyzed). + */ +public void testFileSystem_findSecondaryInClass() { + final String testScratchArea = "fileSystemTestScratchArea"; + + File testScratchAreaFile = new File(Util.getOutputDirectory(), testScratchArea); + try { + if(!testScratchAreaFile.exists()) { + testScratchAreaFile.mkdirs(); + } + + assertTrue(testScratchAreaFile.exists()); + + Classpath classpath = FileSystem.getClasspath(testScratchAreaFile.getPath(), null, null); + assertNotNull(classpath); + assertTrue(classpath instanceof ClasspathDirectory); + + ClasspathDirectory classpathDirectory = (ClasspathDirectory)classpath; + NameEnvironmentAnswer answer = classpathDirectory.findSecondaryInClass(TypeConstants.PACKAGE_INFO_NAME, null, null); + assertNull(answer); //No answer is expected, because "package-info" isn't a secondary type. + + try { + //When there is a call with another name like "package-info", an exception is expected, because the search can not get executed successfully + // when no value for qualifiedPackageName is provided. + classpathDirectory.findSecondaryInClass("X".toCharArray(), null, null); + fail("An exception is expected, because the parameter qualifiedPackageName can not be NULL!"); + } catch(Exception e) {} + } finally { + if(testScratchAreaFile.exists()) { + Util.delete(testScratchAreaFile); + } + } +} +//same as test293, but for -info: instead of -err: +public void test496137a(){ + createCascadedJars(); + this.runConformTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " A a;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + LIB_DIR + File.separator + "lib3.jar[~p/A]\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo -info:+discouraged" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "----------\n" + + "1. INFO in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 4)\n" + + " A a;\n" + + " ^\n" + + "Discouraged access: The type \'A\' is not API (restriction on classpath entry \'---LIB_DIR_PLACEHOLDER---/lib3.jar\')\n" + + "----------\n" + + "1 problem (1 info)\n", + true); +} +//same as test294, but for -info: instead of -err: +public void test496137b(){ + this.runConformTest( + new String[] { + "src/X.java", + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -cp \"" + LIB_DIR + "\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo -info:+discouraged2" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "invalid info token: \'discouraged2\'. Ignoring this info token and compiling\n", + true); +} +//same as test296, but for -info: instead of -err: +public void test496137c(){ + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -cp \"" + LIB_DIR + "\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo -info:" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "invalid info configuration: \'-info:\'\n", + true); +} +//same as test297, but for -info: instead of -err: +public void test496137d(){ + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -cp \"" + LIB_DIR + "\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo -info" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "invalid info configuration: \'-info\'\n", + true); +} +//same as testBug375366b, but for =info: instead of =warning: +public void test496137e() throws IOException { + createOutputTestDirectory("regression/.settings"); + Util.createFile(OUTPUT_DIR+"/.settings/org.eclipse.jdt.core.prefs", + "eclipse.preferences.version=1\n" + + "org.eclipse.jdt.core.compiler.problem.unusedParameter=info\n" + + "org.eclipse.jdt.core.compiler.doc.comment.support=disabled\n"); + this.runTest( + true, // compile OK, expecting only warning + new String[] { + "bugs/warning/ShowBug.java", + "package bugs.warning;\n" + + "\n" + + "public class ShowBug {\n" + + " /**\n" + + " * \n" + + " * @param unusedParam\n" + + " */\n" + + " public void foo(Object unusedParam) {\n" + + " \n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "bugs" + File.separator + "warning" + File.separator + "ShowBug.java\"" + + " -1.5" + + " -properties " + OUTPUT_DIR + File.separator +".settings" + File.separator + "org.eclipse.jdt.core.prefs " + + " -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. INFO in ---OUTPUT_DIR_PLACEHOLDER---/bugs/warning/ShowBug.java (at line 8)\n" + + " public void foo(Object unusedParam) {\n" + + " ^^^^^^^^^^^\n" + + "The value of the parameter unusedParam is not used\n" + + "----------\n" + + "1 problem (1 info)\n", + false /*don't flush output dir*/, + null /* progress */); +} +// variation of test496137a to test that -warn:none turns off all info, too +public void test496137f(){ + createCascadedJars(); + this.runConformTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "/** */\n" + + "public class X {\n" + + " A a;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp \"" + LIB_DIR + File.separator + "lib3.jar[~p/A]\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo -info:+discouraged -warn:none" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); +} +public void testReleaseOption() throws Exception { + try { + Object valueOf = javax.lang.model.SourceVersion.valueOf("RELEASE_9"); + if (valueOf != null) + return; + } catch (IllegalArgumentException ignore) { + } + this.runNegativeTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 8 -d \"" + OUTPUT_DIR + "\"", + "", + "option --release is supported only when run with JDK 9 or above\n", + true); +} + +public void testBug531579() throws Exception { + if (!isJRE9Plus) return; + // these types replace inaccessible types from JRE/javax.xml.bind: + runConformTest(new String[] { + "src/javax/xml/bind/JAXBContext.java", + "package javax.xml.bind;\n" + + "public abstract class JAXBContext {\n" + + " public static JAXBContext newInstance( String contextPath )\n" + + " throws JAXBException {\n" + + " return null;\n" + + " }\n" + + "}\n", + "src/javax/xml/bind/JAXBException.java", + "package javax.xml.bind;\n" + + "public class JAXBException extends Exception {}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "src/javax/xml/bind/JAXBContext.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src/javax/xml/bind/JAXBException.java\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.8" + + " -warn:none" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); + + runConformTest(new String[] { + "src/p1/ImportJAXBType.java", + "package p1;\n" + + "\n" + + "import javax.xml.bind.JAXBContext;\n" + + "\n" + + "public class ImportJAXBType {\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " JAXBContext context = JAXBContext.newInstance(\"\");\n" + + " }\n" + + "\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "src/p1/ImportJAXBType.java\"" + + " -cp \"" + OUTPUT_DIR + File.separator + "bin\" " + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " -1.9" + + " -warn:none" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + false); +} + +public void testFailOnWarnings_NoWarning() { + this.runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -failOnWarning" + + " -d \"" + OUTPUT_DIR + File.separator + "bin/\"", + "", + "", + true); + +} + +public void testFailOnWarnings_WithWarning() { + this.runNegativeTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "private int a;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -failOnWarning" + + " -d \"" + OUTPUT_DIR + File.separator + "bin/\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + + " private int a;\n" + + " ^\n" + + "The value of the field X.a is not used\n" + + "----------\n" + + "1 problem (1 warning)\n" + + "error: warnings found and -failOnWarning specified\n" + + "", + true); +} +public void testUnusedObjectAllocation() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " new X();\n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -err:+unused" + + " -d \"" + OUTPUT_DIR + File.separator + "bin/\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + + " new X();\n" + + " ^^^^^^^\n" + + "The allocated object is never used\n" + + "----------\n" + + "1 problem (1 error)\n", + true); + +} +public void testBug573153() { + String output = MAIN.bind("configure.source", "10"); + String template = "source level should be in '1.1'...'1.8','9'...'15' (or '5.0'..'15.0'): 10"; + template = template.replace("15", CompilerOptions.getLatestVersion()); + assertEquals("configure.source is not updated", template, output); + + output = MAIN.bind("configure.targetJDK", "10"); + template = "target level should be in '1.1'...'1.8','9'...'15' (or '5.0'..'15.0') or cldc1.1: 10"; + template = template.replace("15", CompilerOptions.getLatestVersion()); + assertEquals("configure.source is not updated", template, output); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest2.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest2.java new file mode 100644 index 0000000000..cf0fa2700b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest2.java @@ -0,0 +1,422 @@ +/******************************************************************************* + * Copyright (c) 2018, 2020 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class BatchCompilerTest2 extends AbstractBatchCompilerTest { + + static { +// TESTS_NAMES = new String[] { "test440477" }; +// TESTS_NUMBERS = new int[] { 306 }; +// TESTS_RANGE = new int[] { 298, -1 }; + } + + /** + * This test suite only needs to be run on one compliance. + * As it includes some specific 1.5 tests, it must be used with a least a 1.5 VM + * and not be duplicated in general test suite. + * @see TestAll + */ + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_11); + } + public static Class testClass() { + return BatchCompilerTest2.class; + } + public BatchCompilerTest2(String name) { + super(name); + } + public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" + + ")\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (false) {\n" + + " ;\n" + + " } else {\n" + + " }\n" + + " Zork z;\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -10 --enable-preview", + "", + "Preview of features is supported only at the latest source level\n", + true); +} +public void test002() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" + + ")\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (false) {\n" + + " ;\n" + + " } else {\n" + + " }\n" + + " Zork z;\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --enable-preview -" + CompilerOptions.getLatestVersion() + " ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "1 problem (1 error)\n", + true); +} +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = (Integer x, var y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " lam.apply(20, 200);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k, Integer z);\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --enable-preview -" + CompilerOptions.getLatestVersion() + " ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + + " I lam = (Integer x, var y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^\n" + + "\'var\' cannot be mixed with non-var parameters\n" + + "----------\n" + + "1 problem (1 error)\n", + true); +} +public void test004() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" + + ")\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (false) {\n" + + " ;\n" + + " } else {\n" + + " }\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --enable-preview -" + CompilerOptions.getLatestVersion() + " ", + "", + "", + true); + String expectedOutput = ".65535, super bit)"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +public void test005() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" + + ")\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (false) {\n" + + " ;\n" + + " } else {\n" + + " }\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --enable-preview -" + CompilerOptions.getLatestVersion() + " ", + "", + "", + true); + String expectedOutput = "65535, super bit)"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +public void test006() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "@SuppressWarnings(\"all\"//$NON-NLS-1$\n" + + ")\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (false) {\n" + + " ;\n" + + " } else {\n" + + " }\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -source 11", + "", + "", + true); + String expectedOutput = "// Compiled from X.java (version 11 : 55.0, super bit)"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +public void testBug540123a() throws Exception { + this.runConformTest( + new String[] { + "SecurePrefs.java", + "public class SecurePrefs {\n" + + " public SecurePrefs node (String s) {\n" + + " System.out.println(s);\n" + + " return null;\n" + + " }\n" + + "}", + "SecurePrefsRoot.java", + "public class SecurePrefsRoot extends SecurePrefs {\n" + + "\n" + + " public void foo() {\n" + + " SecurePrefs node = node(\"Hello\");\n" + + " if (node != null)\n" + + " System.out.println(node.toString());\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new SecurePrefsRoot().foo();\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "SecurePrefsRoot.java\"" + +" \"" + OUTPUT_DIR + File.separator + "SecurePrefs.java\"" + + " -source 1.3 -target 1.2", + "", + "", + true); + String expectedOutput = "invokevirtual SecurePrefsRoot.node(java.lang.String) : SecurePrefs [14]"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "SecurePrefsRoot.class", "SecurePrefsRoot", expectedOutput); +} +public void testBug540123b() throws Exception { + this.runConformTest( + new String[] { + "SecurePrefs.java", + "public class SecurePrefs {\n" + + " public SecurePrefs node (String s) {\n" + + " System.out.println(s);\n" + + " return null;\n" + + " }\n" + + "}", + "SecurePrefsRoot.java", + "public class SecurePrefsRoot extends SecurePrefs {\n" + + "\n" + + " public void foo() {\n" + + " SecurePrefs node = node(\"Hello\");\n" + + " if (node != null)\n" + + " System.out.println(node.toString());\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new SecurePrefsRoot().foo();\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "SecurePrefsRoot.java\"" + +" \"" + OUTPUT_DIR + File.separator + "SecurePrefs.java\"" + + " -source 1.3", + "", + "", + true); + String expectedOutput = "invokevirtual SecurePrefsRoot.node(java.lang.String) : SecurePrefs [14]"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "SecurePrefsRoot.class", "SecurePrefsRoot", expectedOutput); +} +public void testBug540123c() throws Exception { + this.runConformTest( + new String[] { + "SecurePrefs.java", + "public class SecurePrefs {\n" + + " public SecurePrefs node (String s) {\n" + + " System.out.println(s);\n" + + " return null;\n" + + " }\n" + + "}", + "SecurePrefsRoot.java", + "public class SecurePrefsRoot extends SecurePrefs {\n" + + "\n" + + " public void foo() {\n" + + " SecurePrefs node = node(\"Hello\");\n" + + " if (node != null)\n" + + " System.out.println(node.toString());\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new SecurePrefsRoot().foo();\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "SecurePrefsRoot.java\"" + +" \"" + OUTPUT_DIR + File.separator + "SecurePrefs.java\"" + + " -target 1.3", + "", + "", + true); + String expectedOutput = "invokevirtual SecurePrefsRoot.node(java.lang.String) : SecurePrefs [14]"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "SecurePrefsRoot.class", "SecurePrefsRoot", expectedOutput); +} +public void testBug540123d() throws Exception { + this.runConformTest( + new String[] { + "SecurePrefs.java", + "public class SecurePrefs {\n" + + " public SecurePrefs node (String s) {\n" + + " System.out.println(s);\n" + + " return null;\n" + + " }\n" + + "}", + "SecurePrefsRoot.java", + "public class SecurePrefsRoot extends SecurePrefs {\n" + + "\n" + + " public void foo() {\n" + + " SecurePrefs node = node(\"Hello\");\n" + + " if (node != null)\n" + + " System.out.println(node.toString());\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new SecurePrefsRoot().foo();\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "SecurePrefsRoot.java\"" + +" \"" + OUTPUT_DIR + File.separator + "SecurePrefs.java\"" + + " -1.4", + "", + "", + true); + String expectedOutput = "invokevirtual SecurePrefsRoot.node(java.lang.String) : SecurePrefs [14]"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "SecurePrefsRoot.class", "SecurePrefsRoot", expectedOutput); +} +public void testBug540123e() throws Exception { + this.runConformTest( + new String[] { + "SecurePrefs.java", + "public class SecurePrefs {\n" + + " public SecurePrefs node (String s) {\n" + + " System.out.println(s);\n" + + " return null;\n" + + " }\n" + + "}", + "SecurePrefsRoot.java", + "public class SecurePrefsRoot extends SecurePrefs {\n" + + "\n" + + " public void foo() {\n" + + " SecurePrefs node = node(\"Hello\");\n" + + " if (node != null)\n" + + " System.out.println(node.toString());\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new SecurePrefsRoot().foo();\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "SecurePrefsRoot.java\"" + +" \"" + OUTPUT_DIR + File.separator + "SecurePrefs.java\"" + + " -1.3", + "", + "", + true); + String expectedOutput = "invokevirtual SecurePrefs.node(java.lang.String) : SecurePrefs [14]"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "SecurePrefsRoot.class", "SecurePrefsRoot", expectedOutput); +} +public void testBug562473() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -source " + CompilerOptions.getLatestVersion() + + " -target " + CompilerOptions.getLatestVersion() + " ", + "", + "", + true); +} +public void testBug568802() { + String currentWorkingDirectoryPath = System.getProperty("user.dir"); + String libPath = currentWorkingDirectoryPath + File.separator + "lib568802.jar"; + try { + Util.createJar( + new String[] { + "hello/World.java;\n", + "package hello;\n" + + "public class World {}\n", + "module-info.java;\n", + "module HelloModule {}\n" + }, + libPath, + JavaCore.VERSION_11, + false); + this.runConformTest( + new String[] { + "X.java", + "import hello.World;\n" + + "public class X {\n" + + " World field = new World();\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -cp " + libPath + // relative + " -source " + CompilerOptions.getLatestVersion() + + " -target " + CompilerOptions.getLatestVersion() + " ", + "", + "", + true); + } catch (IOException e) { + System.err.println("BatchCompilerTest2#testBug568802 could not write to current working directory " + currentWorkingDirectoryPath); + } finally { + new File(libPath).delete(); + } +} + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_14.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_14.java new file mode 100644 index 0000000000..75c3005994 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_14.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2020 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class BatchCompilerTest_14 extends AbstractBatchCompilerTest { + + static { +// TESTS_NAMES = new String[] { "testBatchBug565787_001" }; +// TESTS_NUMBERS = new int[] { 306 }; +// TESTS_RANGE = new int[] { 298, -1 }; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_14); + } + public static Class testClass() { + return BatchCompilerTest_14.class; + } + public BatchCompilerTest_14(String name) { + super(name); + } +public void testBatchBug565787_001() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n"+ + " class MR {\n"+ + " public int mrCompare(String str1, String str2) {\n"+ + " return 0;\n"+ + " }\n"+ + " };\n"+ + " \n"+ + " void m1() {\n"+ + " MR mr = new MR();\n"+ + " String[] array = {\"one\"};\n"+ + " Arrays.sort(array, mr::mrCompare);\n"+ + " }\n"+ + "}\n", + "Y.java", + "import java.util.HashSet;\n" + + "import java.util.function.Supplier;\n" + + "public class Y {\n"+ + " class MR {\n"+ + " public void mr(Supplier supplier) {}\n"+ + " };\n"+ + " \n"+ + " void m1() {\n"+ + " MR mr = new MR();\n"+ + " mr.mr(HashSet::new);\n"+ + " }\n"+ + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "Y.java\"" + +" \"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -source " + CompilerOptions.getLatestVersion(), + "", + "", + true); + String expectedOutput = "Bootstrap methods:\n" + + " 0 : # 44 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #46 (Ljava/lang/Object;Ljava/lang/Object;)I\n" + + " #51 X$MR.mrCompare:(Ljava/lang/String;Ljava/lang/String;)I\n" + + " #52 (Ljava/lang/String;Ljava/lang/String;)I\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_15.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_15.java new file mode 100644 index 0000000000..b67fc11d63 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_15.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2018, 2020 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class BatchCompilerTest_15 extends AbstractBatchCompilerTest { + + static { +// TESTS_NAMES = new String[] { "test440477" }; +// TESTS_NUMBERS = new int[] { 306 }; +// TESTS_RANGE = new int[] { 298, -1 }; + } + + /** + * This test suite only needs to be run on one compliance. + * As it includes some specific 1.5 tests, it must be used with a least a 1.5 VM + * and not be duplicated in general test suite. + * @see TestAll + */ + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_15); + } + public static Class testClass() { + return BatchCompilerTest_15.class; + } + public BatchCompilerTest_15(String name) { + super(name); + } + public void testBug564047_001(){ + if (!AbstractBatchCompilerTest.isJREVersionEqualTo(CompilerOptions.VERSION_15)) + return; // preview test - relevant only at level 15 + + String currentWorkingDirectoryPath = System.getProperty("user.dir"); + if (currentWorkingDirectoryPath == null) { + System.err.println("BatchCompilerTest#testBug564047_001 could not access the current working directory " + currentWorkingDirectoryPath); + } else if (!new File(currentWorkingDirectoryPath).isDirectory()) { + System.err.println("BatchCompilerTest#testBug564047_001 current working directory is not a directory " + currentWorkingDirectoryPath); + } else { + String lib1Path = currentWorkingDirectoryPath + File.separator + "lib1.jar"; + try { + Util.createJar( + new String[] { + "p/Y.java", + "package p;\n" + + "public sealed class Y permits Z{}", + "p/Z.java", + "package p;\n" + + "public final class Z extends Y{}", + }, + lib1Path, + JavaCore.VERSION_15, + true); + this.runNegativeTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "public class X extends Y {\n" + + " public static void main(String[] args){\n" + + " System.out.println(0);\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/p/X.java\"" + + " -cp " + lib1Path // relative + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " --release 15 --enable-preview -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 2)\n" + + " public class X extends Y {\n" + + " ^\n" + + "The class X with a sealed direct superclass or a sealed direct superinterface Y should be declared either final, sealed, or non-sealed\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 2)\n" + + " public class X extends Y {\n" + + " ^\n" + + "The type X extending a sealed class Y should be a permitted subtype of Y\n" + + "----------\n" + + "2 problems (2 errors)\n", + true); + } catch (IOException e) { + System.err.println("BatchCompilerTest#testBug563430_001 could not write to current working directory " + currentWorkingDirectoryPath); + } finally { + new File(lib1Path).delete(); + } + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_16.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_16.java new file mode 100644 index 0000000000..d60df4fa0c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest_16.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2021 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; +import java.io.File; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; +@SuppressWarnings({ "rawtypes" }) +public class BatchCompilerTest_16 extends AbstractBatchCompilerTest { + static { +// TESTS_NAMES = new String[] { "testBug571454_001" }; +// TESTS_NUMBERS = new int[] { 306 }; +// TESTS_RANGE = new int[] { 298, -1 }; + } + /** + * This test suite only needs to be run on one compliance. + * As it includes some specific 1.5 tests, it must be used with a least a 1.5 VM + * and not be duplicated in general test suite. + * @see TestAll + */ + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_16); + } + public static Class testClass() { + return BatchCompilerTest_16.class; + } + public BatchCompilerTest_16(String name) { + super(name); + } + public void testBug571454_001(){ + if (!AbstractBatchCompilerTest.isJREVersionEqualTo(CompilerOptions.VERSION_16)) + return; + String currentWorkingDirectoryPath = System.getProperty("user.dir"); + if (currentWorkingDirectoryPath == null) { + System.err.println("BatchCompilerTest#testBug564047_001 could not access the current working directory " + currentWorkingDirectoryPath); + } else if (!new File(currentWorkingDirectoryPath).isDirectory()) { + System.err.println("BatchCompilerTest#testBug564047_001 current working directory is not a directory " + currentWorkingDirectoryPath); + } else { + try { + this.runNegativeTest( + new String[] { + "src/X.java", + "public class X {\n"+ + " public static void main(String argv[]) {\n"+ + " R rec = new R(3);\n"+ + " if (rec.x() == 3) {\n" + + " // do nothing\n" + + " }\n" + + " }\n"+ + "}\n", + "src/R.java", + "record R(int x) {\n"+ + " R {\n"+ + " super();\n"+ + " }\n"+ + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src/R.java\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " --release 16 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/R.java (at line 3)\n" + + " super();\n" + + " ^^^^^^^^\n" + + "The body of a compact constructor must not contain an explicit constructor call\n" + + "----------\n" + + "1 problem (1 error)\n", + true); + } finally { + } + } + } + public void testBug570399(){ + this.runConformTest( + new String[] { + "src/X.java", + "public class X {\n"+ + " public static void main(String argv[]) {\n"+ + " new R(3);\n"+ + " new R();\n"+ + " }\n"+ + "}\n", + "src/R.java", + "record R(int x) {\n"+ + " R() {\n"+ + " this(0);\n"+ + " }\n"+ + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src/R.java\"" + + " -sourcepath \"" + OUTPUT_DIR + File.separator + "src\"" + + " --release 16 -g -preserveAllLocals" + + " -proceedOnError -referenceInfo" + + " -d \"" + OUTPUT_DIR + File.separator + "bin\" ", + "", + "", + true); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BinaryLiteralTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BinaryLiteralTest.java new file mode 100644 index 0000000000..b5ee00f698 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BinaryLiteralTest.java @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2011, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +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/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java new file mode 100644 index 0000000000..c41989d72c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BooleanTest.java @@ -0,0 +1,2456 @@ +/******************************************************************************* + * Copyright (c) 2005, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class BooleanTest extends AbstractRegressionTest { + +public BooleanTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public void test001() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public Object getAccessibleSelection(int i) {\n" + + " int c, d;\n" + + " if ((this == null) || ((d = 4) > 0)) {\n" + + " c = 2;\n" + + " }\n" + + " else {\n" + + " if (this == null) {\n" + + " c = 3;\n" + + " i++;\n" + + " }\n" + + " i++;\n" + + " }\n" + + " return null;\n" + + " }\n" + + " public String getAccessibleSelection2(int i) {\n" + + " int c, d;\n" + + " return ((this == null) || ((d = 4) > 0))\n" + + " ? String.valueOf(c = 2)\n" + + " : String.valueOf(i++); \n" + + " }\n" + + "}\n", + }); +} + +public void test002() { + this.runConformTest(new String[] { + "p/H.java", + "package p;\n" + + "public class H {\n" + + " Thread fPeriodicSaveThread;\n" + + " public void bar() {\n" + + " int a = 0, b = 0;\n" + + " if (a == 0 || (b = 2) == 2) {\n" + + " //a = 1;\n" + + " }\n" + + " System.out.println(b);\n" + + " if (b != 0) {\n" + + " System.err.println(\"b should be equal to 0.\");\n" + + " System.exit(-1);\n" + + " }\n" + + " }\n" + + " public void bar2() {\n" + + " int a = 0, b = 0;\n" + + " if (a == 1 && (b = 2) == 2) {\n" + + " //a = 1;\n" + + " }\n" + + " System.out.println(b);\n" + + " if (b != 0) {\n" + + " System.err.println(\"b should be equal to 0.\");\n" + + " System.exit(-1);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new H().bar();\n" + + " new H().bar2();\n" + + " }\n" + + "}\n", + }); +} +public void test003() { + this.runConformTest(new String[] { + "p/I.java", + "package p;\n" + + "/**\n" + + " * This test0 should run without producing a java.lang.ClassFormatError\n" + + " */\n" + + "public class I {\n" + + " public static void main(String[] args) {\n" + + " int i = 1, j;\n" + + " if (((i > 0) || ((j = 10) > j--)) && (i < 12)) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + " public static void main1(String[] args) {\n" + + " int i = 1, j;\n" + + " if (((i < 12) && ((j = 10) > j--)) || (i > 0)) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + " public static void main2(String[] args) {\n" + + " int i = 1, j;\n" + + " if (((i < 12) && ((j = 10) > j--)) && (i > 0)) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}\n", + }); +} +public void test004() { + this.runConformTest(new String[] { + "p/J.java", + "package p;\n" + + "/**\n" + + " * This test0 should run without producing a java.lang.ClassFormatError\n" + + " */\n" + + "public class J {\n" + + " public static void main(String[] args) {\n" + + " int i = 1, j;\n" + + " if (((i > 0) || ((j = 10) > j--)) && (i < 12)) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}\n", + }); +} + +public void test005() { + this.runConformTest(new String[] { + "p/M.java", + "package p;\n" + + "public class M {\n" + + " public static void main(String[] args) {\n" + + " int a = 0, b = 0;\n" + + " if (a == 0 || (b = 2) == 2) {\n" + + " }\n" + + " if (b != 0) {\n" + + " System.out.println(\"b should be equal to zero\");\n" + + " System.exit(-1);\n" + + " }\n" + + " }\n" + + "}\n", + }); +} + +public void test006() { + this.runConformTest(new String[] { + "p/Q.java", + "package p;\n" + + "/**\n" + + " * This test0 should run without producing a java.lang.VerifyError\n" + + " */\n" + + "public class Q {\n" + + " boolean bar() {\n" + + " if (false && foo()) {\n" + + " return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + " boolean foo() {\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Q().bar();\n" + + " }\n" + + "}\n", + }); +} + +// Bug 6596 +public void test007() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " Object t;\n" + + " public static void main(String args[]) {\n" + + " new Test().testMethod();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " private void testMethod(){\n" + + " boolean a = false;\n" + + " boolean b = false;\n" + + " if (!(a&&b)){}\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +// Bug 6596 +public void test008() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " Object t;\n" + + " public static void main(String args[]) {\n" + + " new Test().testMethod();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " private void testMethod(){\n" + + " boolean a = false;\n" + + " boolean b = false;\n" + + " if (!(a||b)){}\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +// Bug 6596 +public void test009() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " Object t;\n" + + " public static void main(String args[]) {\n" + + " new Test().testMethod();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " private void testMethod(){\n" + + " final boolean a = false;\n" + + " boolean b = false;\n" + + " if (!(a&&b)){}\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} + +// Bug 6596 +public void test010() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " Object t;\n" + + " public static void main(String args[]) {\n" + + " new Test().testMethod();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " private void testMethod(){\n" + + " boolean a = false;\n" + + " boolean b = false;\n" + + " if (a == b){}\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} + +// Bug 46675 +public void test011() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = null;\n" + + " boolean b = s != null && (s.length() == 0 ? TestConst.c1 : TestConst.c2);\n" + + " if (!b) System.out.println(\"SUCCESS\");\n" + + " }\n" + + "\n" + + " public static class TestConst {\n" + + " public static final boolean c1 = true;\n" + + " public static final boolean c2 = true;\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} + +// Bug 46675 - variation +public void test012() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = \"aaa\";\n" + + " boolean b = s != null && (s.length() == 0 ? TestConst.c1 : TestConst.c2);\n" + + " if (b) System.out.println(\"SUCCESS\");\n" + + " }\n" + + "\n" + + " public static class TestConst {\n" + + " public static final boolean c1 = true;\n" + + " public static final boolean c2 = true;\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} + +// Bug 46675 - variation +public void test013() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = \"aaa\";\n" + + " boolean b = s == null || (s.length() == 0 ? TestConst.c1 : TestConst.c2);\n" + + " if (!b) System.out.println(\"SUCCESS\");\n" + + " }\n" + + "\n" + + " public static class TestConst {\n" + + " public static final boolean c1 = false;\n" + + " public static final boolean c2 = false;\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} + +// Bug 47881 +public void test014() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String args[]) {\n" + + " boolean b = true;\n" + + " b = b && false; \n" + + " if (b) {\n" + + " System.out.println(\"FAILED\");\n" + + " } else {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", + }, + "SUCCESS"); +} + +// Bug 47881 - variation +public void test015() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String args[]) {\n" + + " boolean b = true;\n" + + " b = b || true; \n" + + " if (b) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } else {\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", + }, + "SUCCESS"); +} +// Bug 47881 - variation +public void test016() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String args[]) {\n" + + " boolean b = false;\n" + + " b = b && true; \n" + + " if (b) {\n" + + " System.out.println(\"FAILED\");\n" + + " } else {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", + }, + "SUCCESS"); +} + +// Bug 47881 - variation +public void test017() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String args[]) {\n" + + " boolean b = true;\n" + + " b = b || false; \n" + + " if (b) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } else {\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 +public void test018() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0++) || true) != ((true && true) && (!(false || true)))));\n" + + " }\n" + + "}\n", + }, + "true"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 getstatic X.f0 : float [26]\n" + + " 10 fconst_1\n" + + " 11 fadd\n" + + " 12 putstatic X.f0 : float [26]\n" + + " 15 iconst_1\n" + + " 16 invokevirtual java.io.PrintStream.println(boolean) : void [28]\n" + + " 19 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 16, line: 8]\n" + + " [pc: 19, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 20] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 20] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test019() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0++) || false) != true));\n" + + " }\n" + + "}\n", + }, + "false"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 5, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 lload_1 [l11]\n" + + " 8 l2f\n" + + " 9 getstatic X.f0 : float [26]\n" + + " 12 dup\n" + + " 13 fconst_1\n" + + " 14 fadd\n" + + " 15 putstatic X.f0 : float [26]\n" + + " 18 fcmpg\n" + + " 19 ifge 26\n" + + " 22 iconst_0\n" + + " 23 goto 27\n" + + " 26 iconst_1\n" + + " 27 invokevirtual java.io.PrintStream.println(boolean) : void [28]\n" + + " 30 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 27, line: 8]\n" + + " [pc: 30, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 31] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 31] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test020() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0) | true) != false));\n" + + " }\n" + + "}\n", + }, + "true"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 iconst_1\n" + + " 8 invokevirtual java.io.PrintStream.println(boolean) : void [26]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 11, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 12] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test021() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0) && false) != true));\n" + + " }\n" + + "}\n", + }, + "true"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 iconst_1\n" + + " 8 invokevirtual java.io.PrintStream.println(boolean) : void [26]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 11, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 12] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test022() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0) & false) != true));\n" + + " }\n" + + "}\n", + }, + "true"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 iconst_1\n" + + " 8 invokevirtual java.io.PrintStream.println(boolean) : void [26]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 11, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 12] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 +public void test023() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0++) || true) == ((true && true) && (!(false || true)))));\n" + + " }\n" + + "}\n", + }, + "false"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 getstatic X.f0 : float [26]\n" + + " 10 fconst_1\n" + + " 11 fadd\n" + + " 12 putstatic X.f0 : float [26]\n" + + " 15 iconst_0\n" + + " 16 invokevirtual java.io.PrintStream.println(boolean) : void [28]\n" + + " 19 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 16, line: 8]\n" + + " [pc: 19, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 20] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 20] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test024() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0++) || false) == true));\n" + + " }\n" + + "}\n", + }, + "true"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 5, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 lload_1 [l11]\n" + + " 8 l2f\n" + + " 9 getstatic X.f0 : float [26]\n" + + " 12 dup\n" + + " 13 fconst_1\n" + + " 14 fadd\n" + + " 15 putstatic X.f0 : float [26]\n" + + " 18 fcmpg\n" + + " 19 ifge 26\n" + + " 22 iconst_1\n" + + " 23 goto 27\n" + + " 26 iconst_0\n" + + " 27 invokevirtual java.io.PrintStream.println(boolean) : void [28]\n" + + " 30 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 27, line: 8]\n" + + " [pc: 30, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 31] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 31] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test025() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0) | true) == false));\n" + + " }\n" + + "}\n", + }, + "false"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 iconst_0\n" + + " 8 invokevirtual java.io.PrintStream.println(boolean) : void [26]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 11, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 12] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test026() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0) && false) == true));\n" + + " }\n" + + "}\n", + }, + "false"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 iconst_0\n" + + " 8 invokevirtual java.io.PrintStream.println(boolean) : void [26]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 11, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 12] local: l11 index: 1 type: long\n" + + "}"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test027() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0) & false) == true));\n" + + " }\n" + + "}\n", + }, + "false"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 iconst_0\n" + + " 8 invokevirtual java.io.PrintStream.println(boolean) : void [26]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 11, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 12] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test028() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0) || true) == false));\n" + + " }\n" + + "}\n", + }, + "false"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 iconst_0\n" + + " 8 invokevirtual java.io.PrintStream.println(boolean) : void [26]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 11, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 12] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test029() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " System.out.println(\n" + + " ((foo() || bar()) || true) && false); \n" + + " }\n" + + " static boolean foo(){ \n" + + " System.out.print(\"foo\");\n" + + " return false;\n" + + " }\n" + + " static boolean bar(){\n" + + " System.out.print(\"bar\");\n" + + " return true;\n" + + " }\n" + + "}\n", + }, + "foobarfalse"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + + " 3 invokestatic X.foo() : boolean [24]\n" + + " 6 ifne 13\n" + + " 9 invokestatic X.bar() : boolean [28]\n" + + " 12 pop\n" + + " 13 iconst_0\n" + + " 14 invokevirtual java.io.PrintStream.println(boolean) : void [31]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 3, line: 7]\n" + + " [pc: 14, line: 6]\n" + + " [pc: 17, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: args index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117120 - variation +public void test030() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static float f0;\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " \n" + + " System.out.println(\n" + + " (((l11 < f0++) || true) == ((foo() || bar()) || true)));\n" + + " }\n" + + " static boolean foo() {\n" + + " System.out.print(\"foo\");\n" + + " return false;\n" + + " }\n" + + " static boolean bar() {\n" + + " System.out.print(\"bar\");\n" + + " return true;\n" + + " }\n" + + "}\n", + }, + "foobartrue"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 getstatic X.f0 : float [26]\n" + + " 10 fconst_1\n" + + " 11 fadd\n" + + " 12 putstatic X.f0 : float [26]\n" + + " 15 invokestatic X.foo() : boolean [28]\n" + + " 18 ifne 25\n" + + " 21 invokestatic X.bar() : boolean [32]\n" + + " 24 pop\n" + + " 25 iconst_1\n" + + " 26 invokevirtual java.io.PrintStream.println(boolean) : void [35]\n" + + " 29 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 7, line: 9]\n" + + " [pc: 26, line: 8]\n" + + " [pc: 29, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 30] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 30] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117451 +public void test031() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public float f0;\n" + + "\n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " X x = new X();\n" + + " System.out.println(\n" + + " (((l11 < x.f0) || true) != false));\n" + + " }\n" + + "}\n", + }, + "true"); + // ensure optimized boolean codegen sequence + String expectedOutput = this.complianceLevel == ClassFileConstants.JDK1_3 + ? " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 new X [1]\n" + + " 7 dup\n" + + " 8 invokespecial X() [20]\n" + + " 11 astore_3 [x]\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 15 aload_3 [x]\n" + + " 16 invokevirtual java.lang.Object.getClass() : java.lang.Class [27]\n" + + " 19 pop\n" + + " 20 iconst_1\n" + + " 21 invokevirtual java.io.PrintStream.println(boolean) : void [31]\n" + + " 24 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 7]\n" + + " [pc: 12, line: 8]\n" + + " [pc: 15, line: 9]\n" + + " [pc: 21, line: 8]\n" + + " [pc: 24, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 25] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 25] local: l11 index: 1 type: long\n" + + " [pc: 12, pc: 25] local: x index: 3 type: X\n" + + : " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 new X [1]\n" + + " 7 dup\n" + + " 8 invokespecial X() [20]\n" + + " 11 astore_3 [x]\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 15 aload_3 [x]\n" + + " 16 getfield X.f0 : float [27]\n" + + " 19 pop\n" + + " 20 iconst_1\n" + + " 21 invokevirtual java.io.PrintStream.println(boolean) : void [29]\n" + + " 24 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 7]\n" + + " [pc: 12, line: 8]\n" + + " [pc: 15, line: 9]\n" + + " [pc: 21, line: 8]\n" + + " [pc: 24, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 25] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 25] local: l11 index: 1 type: long\n" + + " [pc: 12, pc: 25] local: x index: 3 type: X\n"; + + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117451 - variation +public void test032() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static float f0;\n" + + "\n" + + " public static void main(String[] args)\n" + + " {\n" + + " long l11 = -26;\n" + + " System.out.println(\n" + + " (((l11 < (f0=13)) || true) != false));\n" + + " }\n" + + "}\n", + }, + "true"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [18]\n" + + " 3 lstore_1 [l11]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 7 ldc [26]\n" + + " 9 putstatic X.f0 : float [27]\n" + + " 12 iconst_1\n" + + " 13 invokevirtual java.io.PrintStream.println(boolean) : void [29]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 7]\n" + + " [pc: 7, line: 8]\n" + + " [pc: 13, line: 7]\n" + + " [pc: 16, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 17] local: l11 index: 1 type: long\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} + +public void test033() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean b = true;\n" + + " System.out.print(b ^ b);\n" + + " System.out.println(b ^ true);\n" + + " } \n" + + "}\n", + }, + "falsefalse"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 istore_1 [b]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 5 iload_1 [b]\n" + + " 6 iload_1 [b]\n" + + " 7 ixor\n" + + " 8 invokevirtual java.io.PrintStream.print(boolean) : void [22]\n" + + " 11 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 14 iload_1 [b]\n" + + " 15 iconst_1\n" + + " 16 ixor\n" + + " 17 invokevirtual java.io.PrintStream.println(boolean) : void [28]\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 11, line: 5]\n" + + " [pc: 20, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 21] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 21] local: b index: 1 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test034() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean b = true;\n" + + " if ((b ^ true) || b) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " } \n" + + "}\n", + }, + "SUCCESS"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 istore_1 [b]\n" + + " 2 iload_1 [b]\n" + + " 3 ifeq 10\n" + + " 6 iload_1 [b]\n" + + " 7 ifeq 18\n" + + " 10 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 13 ldc [22]\n" + + " 15 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 18 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 10, line: 5]\n" + + " [pc: 18, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 19] local: b index: 1 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117451 - variation +public void test035() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static float f0;\n" + + " public static void main(String[] args) {\n" + + " System.out.println((X.f0 > 0 || true) == false);\n" + + " } \n" + + "}\n", + }, + "false"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + + " 3 iconst_0\n" + + " 4 invokevirtual java.io.PrintStream.println(boolean) : void [24]\n" + + " 7 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 7, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 8] local: args index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117451 - variation +public void test036() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " float f0;\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " System.out.println((this.f0 > 0 || true) == false);\n" + + " } \n" + + "}\n", + }, + "false"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " void foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [24]\n" + + " 3 iconst_0\n" + + " 4 invokevirtual java.io.PrintStream.println(boolean) : void [30]\n" + + " 7 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 7, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 8] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=147024 +public void test037() throws Exception { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " public static final boolean T = true;\n" + + " public static final boolean F = false;\n" + + " \n" + + " public boolean getFlagBT() {\n" + + " boolean b = this.T;\n" + + " if (this.T)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int getFlagIT() {\n" + + " boolean b = this.T;\n" + + " if (this.T)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + "\n" + + " public boolean getFlagBF() {\n" + + " boolean b = this.F;\n" + + " if (this.F)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int getFlagIF() {\n" + + " boolean b = this.F;\n" + + " if (this.F)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + " public boolean getFlagBT2() {\n" + + " boolean b = T;\n" + + " if (T)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int getFlagIT2() {\n" + + " boolean b = T;\n" + + " if (T)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + "\n" + + " public boolean getFlagBF2() {\n" + + " boolean b = F;\n" + + " if (F)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int getFlagIF2() {\n" + + " boolean b = F;\n" + + " if (F)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + " public boolean getFlagBT3() {\n" + + " X self = this;\n" + + " boolean b = self.T;\n" + + " if (self.T)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int getFlagIT3() {\n" + + " X self = this;\n" + + " boolean b = self.T;\n" + + " if (self.T)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + "\n" + + " public boolean getFlagBF3() {\n" + + " X self = this;\n" + + " boolean b = self.F;\n" + + " if (self.F)\n" + + " return true;\n" + + " else\n" + + " return false;\n" + + " }\n" + + " public int getFlagIF3() {\n" + + " X self = this;\n" + + " boolean b = self.F;\n" + + " if (self.F)\n" + + " return 0;\n" + + " else\n" + + " return 1;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"It worked.\");\n" + + " }\n" + + "}", // ================= + }, + "It worked."); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 2\n" + + " public boolean getFlagBT();\n" + + " 0 iconst_1\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_1\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 2, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " public int getFlagIT();\n" + + " 0 iconst_1\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_0\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 2, line: 16]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 2\n" + + " public boolean getFlagBF();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_0\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 22]\n" + + " [pc: 2, line: 26]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " public int getFlagIF();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_1\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 30]\n" + + " [pc: 2, line: 34]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 2\n" + + " public boolean getFlagBT2();\n" + + " 0 iconst_1\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_1\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 37]\n" + + " [pc: 2, line: 39]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " public int getFlagIT2();\n" + + " 0 iconst_1\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_0\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 45]\n" + + " [pc: 2, line: 47]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 2\n" + + " public boolean getFlagBF2();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_0\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 53]\n" + + " [pc: 2, line: 57]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " public int getFlagIF2();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iconst_1\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 61]\n" + + " [pc: 2, line: 65]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " [pc: 2, pc: 4] local: b index: 1 type: boolean\n" + + " \n" + + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 3\n" + + " public boolean getFlagBT3();\n" + + " 0 aload_0 [this]\n" + + " 1 astore_1 [self]\n" + + " 2 iconst_1\n" + + " 3 istore_2 [b]\n" + + " 4 iconst_1\n" + + " 5 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 68]\n" + + " [pc: 2, line: 69]\n" + + " [pc: 4, line: 71]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 6] local: this index: 0 type: X\n" + + " [pc: 2, pc: 6] local: self index: 1 type: X\n" + + " [pc: 4, pc: 6] local: b index: 2 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 3\n" + + " public int getFlagIT3();\n" + + " 0 aload_0 [this]\n" + + " 1 astore_1 [self]\n" + + " 2 iconst_1\n" + + " 3 istore_2 [b]\n" + + " 4 iconst_0\n" + + " 5 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 77]\n" + + " [pc: 2, line: 78]\n" + + " [pc: 4, line: 80]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 6] local: this index: 0 type: X\n" + + " [pc: 2, pc: 6] local: self index: 1 type: X\n" + + " [pc: 4, pc: 6] local: b index: 2 type: boolean\n" + + " \n" + + " // Method descriptor #21 ()Z\n" + + " // Stack: 1, Locals: 3\n" + + " public boolean getFlagBF3();\n" + + " 0 aload_0 [this]\n" + + " 1 astore_1 [self]\n" + + " 2 iconst_0\n" + + " 3 istore_2 [b]\n" + + " 4 iconst_0\n" + + " 5 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 86]\n" + + " [pc: 2, line: 87]\n" + + " [pc: 4, line: 91]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 6] local: this index: 0 type: X\n" + + " [pc: 2, pc: 6] local: self index: 1 type: X\n" + + " [pc: 4, pc: 6] local: b index: 2 type: boolean\n" + + " \n" + + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 3\n" + + " public int getFlagIF3();\n" + + " 0 aload_0 [this]\n" + + " 1 astore_1 [self]\n" + + " 2 iconst_0\n" + + " 3 istore_2 [b]\n" + + " 4 iconst_1\n" + + " 5 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 94]\n" + + " [pc: 2, line: 95]\n" + + " [pc: 4, line: 99]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 6] local: this index: 0 type: X\n" + + " [pc: 2, pc: 6] local: self index: 1 type: X\n" + + " [pc: 4, pc: 6] local: b index: 2 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test038() throws Exception { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " static boolean foo() { System.out.print(\"[foo]\"); return false; }\n" + + " static boolean bar() { System.out.print(\"[bar]\"); return true; }\n" + + " public static void main(String[] args) {\n" + + " if ((foo() || bar()) && false) {\n" + + " return;\n" + + " }\n" + + " System.out.println(\"[done]\");\n" + + " }\n" + + "}", // ================= + }, + "[foo][bar][done]"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #34 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 invokestatic X.foo() : boolean [35]\n" + + " 3 ifne 10\n" + + " 6 invokestatic X.bar() : boolean [37]\n" + + " 9 pop\n" + + " 10 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 13 ldc [39]\n" + + " 15 invokevirtual java.io.PrintStream.println(java.lang.String) : void [41]\n" + + " 18 return\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162965 +public void test039() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean a = true, b;\n" + + " if (a ? false : (b = true))\n" + + " a = b;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 istore_1 [a]\n" + + " 2 iload_1 [a]\n" + + " 3 ifeq 9\n" + + " 6 goto 17\n" + + " 9 iconst_1\n" + + " 10 dup\n" + + " 11 istore_2 [b]\n" + + " 12 ifeq 17\n" + + " 15 iload_2 [b]\n" + + " 16 istore_1 [a]\n" + + " 17 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 20 ldc [22]\n" + + " 22 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 25 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 15, line: 5]\n" + + " [pc: 17, line: 6]\n" + + " [pc: 25, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 26] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 26] local: a index: 1 type: boolean\n" + + " [pc: 12, pc: 17] local: b index: 2 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162965 - variation +public void test040() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean a = true, b = false;\n" + + " if (!(a ? true : (b = true)))\n" + + " a = b;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 istore_1 [a]\n" + + " 2 iconst_0\n" + + " 3 istore_2 [b]\n" + + " 4 iload_1 [a]\n" + + " 5 ifeq 11\n" + + " 8 goto 19\n" + + " 11 iconst_1\n" + + " 12 dup\n" + + " 13 istore_2 [b]\n" + + " 14 ifne 19\n" + + " 17 iload_2 [b]\n" + + " 18 istore_1 [a]\n" + + " 19 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 22 ldc [22]\n" + + " 24 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 27 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 17, line: 5]\n" + + " [pc: 19, line: 6]\n" + + " [pc: 27, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 28] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 28] local: a index: 1 type: boolean\n" + + " [pc: 4, pc: 28] local: b index: 2 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162965 - variation +public void test041() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean a = true, b = false;\n" + + " if (a ? true : (b = false))\n" + + " a = b;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 istore_1 [a]\n" + + " 2 iconst_0\n" + + " 3 istore_2 [b]\n" + + " 4 iload_1 [a]\n" + + " 5 ifeq 11\n" + + " 8 goto 17\n" + + " 11 iconst_0\n" + + " 12 dup\n" + + " 13 istore_2 [b]\n" + + " 14 ifeq 19\n" + + " 17 iload_2 [b]\n" + + " 18 istore_1 [a]\n" + + " 19 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 22 ldc [22]\n" + + " 24 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 27 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 17, line: 5]\n" + + " [pc: 19, line: 6]\n" + + " [pc: 27, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 28] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 28] local: a index: 1 type: boolean\n" + + " [pc: 4, pc: 28] local: b index: 2 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162965 - variation +public void test042() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean a = true, b;\n" + + " if (a ? (b = true) : false)\n" + + " a = b;\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + "}\n", // ================= + }, + "SUCCESS"); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 istore_1 [a]\n" + + " 2 iload_1 [a]\n" + + " 3 ifeq 14\n" + + " 6 iconst_1\n" + + " 7 dup\n" + + " 8 istore_2 [b]\n" + + " 9 ifeq 14\n" + + " 12 iload_2 [b]\n" + + " 13 istore_1 [a]\n" + + " 14 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 17 ldc [22]\n" + + " 19 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 22 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 12, line: 5]\n" + + " [pc: 14, line: 6]\n" + + " [pc: 22, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 23] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 23] local: a index: 1 type: boolean\n" + + " [pc: 9, pc: 14] local: b index: 2 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185567 +public void test043() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " X(boolean b1) {\n" + + " if (b1 || (false && b1)) {\n" + + " System.out.println(b);\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #8 (Z)V\n" + + " // Stack: 2, Locals: 2\n" + + " X(boolean b1);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 iload_1 [b1]\n" + + " 5 ifne 11\n" + + " 8 goto 21\n" + + " 11 getstatic java.lang.System.out : java.io.PrintStream [13]\n" + + " 14 aload_0 [this]\n" + + " 15 getfield X.b : boolean [19]\n" + + " 18 invokevirtual java.io.PrintStream.println(boolean) : void [21]\n" + + " 21 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 11, line: 5]\n" + + " [pc: 21, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 22] local: this index: 0 type: X\n" + + " [pc: 0, pc: 22] local: b1 index: 1 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185567 - variation +public void test044() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(boolean b1) {\n" + + " if (b1 || !(true || b1)) {\n" + + " System.out.println(b1);\n" + + " }\n" + + " } \n" + + "}\n", // ================= + }, + ""); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #6 (Z)V\n" + + " // Stack: 2, Locals: 2\n" + + " X(boolean b1);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 iload_1 [b1]\n" + + " 5 ifne 11\n" + + " 8 goto 18\n" + + " 11 getstatic java.lang.System.out : java.io.PrintStream [11]\n" + + " 14 iload_1 [b1]\n" + + " 15 invokevirtual java.io.PrintStream.println(boolean) : void [17]\n" + + " 18 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " [pc: 4, line: 3]\n" + + " [pc: 11, line: 4]\n" + + " [pc: 18, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: this index: 0 type: X\n" + + " [pc: 0, pc: 19] local: b1 index: 1 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185567 - variation +public void test045() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b1, boolean b2){\n" + + " if (b1 || ((b1 && b2) && false)) {\n" + + " System.out.println(b1); \n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #15 (ZZ)V\n" + + " // Stack: 2, Locals: 3\n" + + " void foo(boolean b1, boolean b2);\n" + + " 0 iload_1 [b1]\n" + + " 1 ifne 15\n" + + " 4 iload_1 [b1]\n" + + " 5 ifeq 22\n" + + " 8 iload_2 [b2]\n" + + " 9 ifeq 22\n" + + " 12 goto 22\n" + + " 15 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 18 iload_1 [b1]\n" + + " 19 invokevirtual java.io.PrintStream.println(boolean) : void [22]\n" + + " 22 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 15, line: 4]\n" + + " [pc: 22, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 23] local: this index: 0 type: X\n" + + " [pc: 0, pc: 23] local: b1 index: 1 type: boolean\n" + + " [pc: 0, pc: 23] local: b2 index: 2 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185567 - variation +public void test046() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo2(boolean b1, boolean b2){\n" + + " if (b1 || ((b1 || b2) && false)) {\n" + + " System.out.println(b1); \n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #15 (ZZ)V\n" + + " // Stack: 2, Locals: 3\n" + + " void foo2(boolean b1, boolean b2);\n" + + " 0 iload_1 [b1]\n" + + " 1 ifne 15\n" + + " 4 iload_1 [b1]\n" + + " 5 ifne 22\n" + + " 8 iload_2 [b2]\n" + + " 9 ifeq 22\n" + + " 12 goto 22\n" + + " 15 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 18 iload_1 [b1]\n" + + " 19 invokevirtual java.io.PrintStream.println(boolean) : void [22]\n" + + " 22 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 15, line: 4]\n" + + " [pc: 22, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 23] local: this index: 0 type: X\n" + + " [pc: 0, pc: 23] local: b1 index: 1 type: boolean\n" + + " [pc: 0, pc: 23] local: b2 index: 2 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185567 - variation +public void test047() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(boolean b1) {\n" + + " int i;\n" + + " if (((b1 && false) && true) || true) {\n" + + " System.out.println(b1);\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #6 (Z)V\n" + + " // Stack: 2, Locals: 2\n" + + " X(boolean b1);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [11]\n" + + " 7 iload_1 [b1]\n" + + " 8 invokevirtual java.io.PrintStream.println(boolean) : void [17]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 11, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n" + + " [pc: 0, pc: 12] local: b1 index: 1 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185567 - variation +public void test048() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(boolean b1) {\n" + + " int i;\n" + + " if (((false && b1) && false) || true) {\n" + + " System.out.println(b1);\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #6 (Z)V\n" + + " // Stack: 2, Locals: 2\n" + + " X(boolean b1);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [11]\n" + + " 7 iload_1 [b1]\n" + + " 8 invokevirtual java.io.PrintStream.println(boolean) : void [17]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 11, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n" + + " [pc: 0, pc: 12] local: b1 index: 1 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185567 - variation +public void test049() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(boolean b1) {\n" + + " int i;\n" + + " if (((b1 && b1) && false) || true) {\n" + + " System.out.println(b1);\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #6 (Z)V\n" + + " // Stack: 2, Locals: 2\n" + + " X(boolean b1);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 iload_1 [b1]\n" + + " 5 ifeq 8\n" + + " 8 getstatic java.lang.System.out : java.io.PrintStream [11]\n" + + " 11 iload_1 [b1]\n" + + " 12 invokevirtual java.io.PrintStream.println(boolean) : void [17]\n" + + " 15 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 15, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 16] local: this index: 0 type: X\n" + + " [pc: 0, pc: 16] local: b1 index: 1 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} + +public void test050() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean t1 = true, t2 = true;\n" + + " if (t1){\n" + + " if (t2){\n" + + " return;\n" + + " }\n" + + " // dead goto bytecode\n" + + " }else{\n" + + " System.out.println();\n" + + " } \n" + + " }\n" + + "}\n", // ================= + }, + ""); + // ensure optimized boolean codegen sequence + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 istore_1 [t1]\n" + + " 2 iconst_1\n" + + " 3 istore_2 [t2]\n" + + " 4 iload_1 [t1]\n" + + " 5 ifeq 13\n" + + " 8 iload_2 [t2]\n" + + " 9 ifeq 19\n" + + " 12 return\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 16 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 19 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 12, line: 6]\n" + + " [pc: 13, line: 10]\n" + + " [pc: 19, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 20] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 20] local: t1 index: 1 type: boolean\n" + + " [pc: 4, pc: 20] local: t2 index: 2 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public static Class testClass() { + return BooleanTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BootstrapMethodAttributeTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BootstrapMethodAttributeTest.java new file mode 100644 index 0000000000..07b44ee6ac --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BootstrapMethodAttributeTest.java @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2011, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; + +@SuppressWarnings({ "rawtypes" }) +public class BootstrapMethodAttributeTest extends AbstractRegressionTest { + public BootstrapMethodAttributeTest(String name) { + super(name); + } + + public static Class testClass() { + return BootstrapMethodAttributeTest.class; + } + + // Use this static initializer to specify subset for tests + // All specified tests which does not belong to the class are skipped... + static { +// TESTS_PREFIX = "testBug95521"; +// TESTS_NAMES = new String[] { "testBug359495" }; +// TESTS_NUMBERS = new int[] { 53 }; +// TESTS_RANGE = new int[] { 23 -1,}; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_7); + } + public void test001() throws Exception { + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "TestBootstrapMethodAtt.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "// (version 1.2 : 46.0, no super bit)\n" + + "public class test.G {\n" + + " \n" + + " // Method descriptor #2 ()V\n" + + " // Stack: 0, Locals: 0\n" + + " public static void call();\n" + + " 0 invokedynamic 0 dyn() : void [18]\n" + + " 5 return\n" + + "\n" + + "Bootstrap methods:\n" + + " 0 : # 17 arguments: {#1}\n" + + "}"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java new file mode 100644 index 0000000000..c979cdf012 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java @@ -0,0 +1,3576 @@ +/******************************************************************************* + * Copyright (c) 2003, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * Bug 428274 - [1.8] [compiler] Cannot cast from Number to double + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.Excuse; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class CastTest extends AbstractRegressionTest { + +public CastTest(String name) { + super(name); +} +@Override +protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return defaultOptions; +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +static { +// TESTS_NAMES = new String[] { "test428388d" }; +} +/* + * check extra checkcast (interface->same interface) + */ +public void test001() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) { \n" + + " Cloneable c1 = new int[0]; \n"+ + " Cloneable c2 = (Cloneable)c1; \n" + + " System.out.print(\"SUCCESS\"); \n" + + " } \n" + + "} \n", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 newarray int [10]\n" + + " 3 astore_1 [c1]\n" + + " 4 aload_1 [c1]\n" + + " 5 astore_2 [c2]\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 ldc [22]\n" + + " 11 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 6, line: 5]\n" + + " [pc: 14, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 15] local: c1 index: 1 type: java.lang.Cloneable\n" + + " [pc: 6, pc: 15] local: c2 index: 2 type: java.lang.Cloneable\n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} + +public void test002() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " // standard expressions\n" + + " String s = (String) null; // UNnecessary\n" + + " String t = (String) \"hello\"; // UNnecessary\n" + + " float f = (float) 12; // UNnecessary\n" + + " int i = (int)12.0; // necessary\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 4)\n" + + " String s = (String) null; // UNnecessary\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary cast from null to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " String t = (String) \"hello\"; // UNnecessary\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " float f = (float) 12; // UNnecessary\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from int to float\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test003() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " // message sends \n" + + " foo((Object) \"hello\"); // necessary\n" + + " foo((String) \"hello\"); // UNnecessary\n" + + " foo((Object) null); // necessary\n" + + " foo((String) null); // UNnecessary but keep as useful documentation \n" + + " }\n" + + " static void foo(String s) {\n" + + " System.out.println(\"foo(String):\"+s);\n" + + " }\n" + + " static void foo(Object o) {\n" + + " System.out.println(\"foo(Object):\"+o);\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " foo((String) \"hello\"); // UNnecessary\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test004() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " // constructors\n" + + " new X((Object) \"hello\"); // necessary\n" + + " new X((String) \"hello\"); // UNnecessary\n" + + " new X((Object) null); // necessary\n" + + " new X((String) null); // UNnecessary but keep as useful documentation\n" + + " }\n" + + " X(){}\n" + + " X(String s){\n" + + " System.out.println(\"new X(String):\"+s);\n" + + " }\n" + + " X(Object o){\n" + + " System.out.println(\"new X(Object):\"+o);\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " new X((String) \"hello\"); // UNnecessary\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test005() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " // qualified allocations\n" + + " new X().new XM3((Object) \"hello\"); // necessary\n" + + " new X().new XM3((String) \"hello\"); // UNnecessary\n" + + " new X().new XM3((Object) null); // necessary\n" + + " new X().new XM3((String) null); // UNnecessary but keep as useful documentation\n" + + " new X().new XM3((Object) \"hello\"){}; // necessary\n" + + " new X().new XM3((String) \"hello\"){}; // UNnecessary\n" + + " new X().new XM3((Object) null){}; // necessary\n" + + " new X().new XM3((String) null){}; // UNnecessary but keep as useful documentation\n" + + " }\n" + + " X(){}\n" + + " static class XM1 extends X {}\n" + + " static class XM2 extends X {}\n" + + " class XM3 {\n" + + " XM3(String s){\n" + + " System.out.println(\"new XM3(String):\"+s);\n" + + " }\n" + + " XM3(Object o){\n" + + " System.out.println(\"new XM3(Object):\"+o);\n" + + " }\n" + + " } \n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " new X().new XM3((String) \"hello\"); // UNnecessary\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " new X().new XM3((String) \"hello\"){}; // UNnecessary\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void _test006() { // TODO (philippe) add support to conditional expression for unnecessary cast + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " // ternary operator\n" + + " String s = null, t = null; \n" + + " X x0 = s == t\n" + + " ? (X)new XM1() // UNnecessary\n" + + " : new X();\n" + + " X x1 = s == t \n" + + " ? (X)new XM1() // necessary\n" + + " : new XM2();\n" + + " X x2 = s == t \n" + + " ? new XM1()\n" + + " : (X)new XM2(); // necessary\n" + + " X x3 = s == t \n" + + " ? (X)new XM1() // necessary\n" + + " : (X)new XM2(); // necessary\n" + + " }\n" + + " X(){}\n" + + " static class XM1 extends X {}\n" + + " static class XM2 extends X {}\n" + + "}\n" + }, + "x", + null, + true, + customOptions); +} + +public void test007() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " X(){}\n" + + " class XM3 {\n" + + " XM3(String s){\n" + + " System.out.println(\"new XM3(String):\"+s);\n" + + " }\n" + + " XM3(Object o){\n" + + " System.out.println(\"new XM3(Object):\"+o);\n" + + " }\n" + + " } \n" + + " \n" + + " class XM4 extends XM3 {\n" + + " XM4(String s){\n" + + " super((Object) s); // necessary\n" + + " System.out.println(\"new XM4(String):\"+s);\n" + + " }\n" + + " XM4(Object o){\n" + + " super((String) o); // necessary\n" + + " System.out.println(\"new XM4(Object):\"+o);\n" + + " }\n" + + " XM4(Thread t){\n" + + " super((Object) t); // UNnecessary\n" + + " System.out.println(\"new XM4(Thread):\"+t);\n" + + " }\n" + + " XM4(){\n" + + " super((String)null); // UNnecessary but keep as useful documentation\n" + + " System.out.println(\"new XM4():\");\n" + + " }\n" + + " XM4(int i){\n" + + " super((Object)null); // necessary\n" + + " System.out.println(\"new XM4():\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 22)\n" + + " super((Object) t); // UNnecessary\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from Thread to Object\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test008() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean b1 = new XM1() instanceof X; // UNnecessary\n" + + " boolean b2 = new X() instanceof XM1; // necessary\n" + + " boolean b3 = null instanceof X;\n" + + " }\n" + + " static class XM1 extends X {}\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " boolean b1 = new XM1() instanceof X; // UNnecessary\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type X.XM1 is already an instance of type X\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test009() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean b1 = ((X) new XM1()) == new X(); // UNnecessary\n" + + " boolean b2 = ((X) new XM1()) == new XM2(); // necessary\n" + + " boolean b3 = ((X) null) == new X(); // UNnecessary\n" + + " }\n" + + " static class XM1 extends X {}\n" + + " static class XM2 extends X {}\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ "1. ERROR in X.java (at line 3)\n" + + " boolean b1 = ((X) new XM1()) == new X(); // UNnecessary\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X.XM1 to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " boolean b3 = ((X) null) == new X(); // UNnecessary\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from null to X\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test010() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " long l1 = ((long) 1) + 2L; // UNnecessary\n" + + " long l2 = ((long)1) + 2; // necessary\n" + + " long l3 = 0;" + + " l3 += (long)12; // UNnecessary\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " long l1 = ((long) 1) + 2L; // UNnecessary\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from int to long\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " long l3 = 0; l3 += (long)12; // UNnecessary\n" + + " ^^^^^^^^\n" + + "Unnecessary cast from int to long\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test011() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s1 = ((long) 1) + \"hello\"; // necessary\n" + + " String s2 = ((String)\"hello\") + 2; // UNnecessary\n" + + " String s3 = ((String)null) + null; // necessary\n" + + " String s4 = ((int) (byte)1) + \"hello\"; // necessary\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 4)\n" + + " String s2 = ((String)\"hello\") + 2; // UNnecessary\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test012() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " // message sends \n" + + " X x = new YM1(); \n" + + " foo((X) x); // UNnecessary\n" + + " foo((XM1) x); // UNnecessary\n" + + " foo((YM1) x); // necessary \n" + + " }\n" + + " static void foo(X x) {}\n" + + " static void foo(YM1 ym1) {}\n" + + " static class XM1 extends X {}\n" + + " static class YM1 extends XM1 {}\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " foo((X) x); // UNnecessary\n" + + " ^^^^^\n" + + "Unnecessary cast from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " foo((XM1) x); // UNnecessary\n" + + " ^^^^^^^\n" + + "Unnecessary cast from X to X.XM1\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=42289 +public void test013() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int a = 0, b = 1;\n" + + " long d;\n" + + " d = (long)a; // unnecessary\n" + + " d = (long)a + b; // necessary \n" + + " d = d + a + (long)b; // unnecessary\n" + + " }\n" + + "}\n" + + "\n", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " d = (long)a; // unnecessary\n" + + " ^^^^^^^\n" + + "Unnecessary cast from int to long\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " d = d + a + (long)b; // unnecessary\n" + + " ^^^^^^^\n" + + "Unnecessary cast from int to long\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// 39925 - Unnecessary instanceof checking leads to a NullPointerException +public void test014() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " boolean b = new Cloneable() {} instanceof Cloneable;\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " boolean b = new Cloneable() {} instanceof Cloneable;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type new Cloneable(){} is already an instance of type Cloneable\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// narrowing cast on base types may change value, thus necessary +public void test015() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo() { \n" + + " int lineCount = 10; \n" + + " long time = 1000; \n" + + " double linePerSeconds1 = ((int) (lineCount * 10000.0 / time)) / 10.0; // necessary \n" + + " double linePerSeconds2 = ((double) (lineCount * 10000.0 / time)) / 10.0; // UNnecessary \n" + + " } \n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " double linePerSeconds2 = ((double) (lineCount * 10000.0 / time)) / 10.0; // UNnecessary \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from double to double\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// narrowing cast on base types may change value, thus necessary +public void test016() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo() { \n" + + " int lineCount = 10; \n" + + " long time = 1000; \n" + + " print((int) (lineCount * 10000.0 / time)); // necessary \n" + + " print((double) (lineCount * 10000.0 / time)); // UNnecessary \n" + + " } \n" + + " void print(double d) {} \n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " print((double) (lineCount * 10000.0 / time)); // UNnecessary \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from double to double\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//fault tolerance (40288) +public void test017() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar() {\n" + + " foo((X) this);\n" + + " foo((X) zork());\n" + // unbound #zork() should not cause NPE + " }\n" + + " void foo(X x) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " foo((X) this);\n" + + " ^^^^^^^^\n" + + "Unnecessary cast from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " foo((X) zork());\n" + + " ^^^^\n" + + "The method zork() is undefined for the type X\n" + + "----------\n", + null, + true, + customOptions); +} +//fault tolerance (40423) +public void test018() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " static Y[] foo(int[] tab) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " Y[] bar() {\n" + + " return (Y[]) Y.foo(new double[] {});\n" + // no cast warning until method is applicable + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " return (Y[]) Y.foo(new double[] {});\n" + + " ^^^\n" + + "The method foo(int[]) in the type Y is not applicable for the arguments (double[])\n" + + "----------\n", + null, + true, + customOptions); +} +//fault tolerance (40288) +public void tes019() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar() {\n" + + " X x1 =(X) this;\n" + + " X x2 = (X) zork();\n" + // unbound #zork() should not cause NPE + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X x1 =(X) this;\n" + + " ^^^^^^^^\n" + + "Unnecessary cast to type X for expression of type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " X x2 = (X) zork();\n" + + " ^^^^\n" + + "The method zork() is undefined for the type X\n" + + "----------\n", + null, + true, + customOptions); +} +//fault tolerance +public void test020() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar() {\n" + + " long l = (long)zork() + 2;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " long l = (long)zork() + 2;\n" + + " ^^^^\n" + + "The method zork() is undefined for the type X\n" + + "----------\n", + null, + true, + customOptions); +} + +// unnecessary cast diagnosis should also consider receiver type (40572) +public void test021() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class Member1 {}\n" + + " public class Member2 {}\n" + + " class Member3 {}\n" + + " public static class Member4 {\n" + + " public static class M4Member {}\n" + + " }\n" + + "}\n", + "p2/B.java", + "package p2;\n" + + "import p1.A;\n" + + "public class B extends A {\n" + + " public class Member1 {}\n" + + "}\n", + "p1/C.java", + "package p1;\n" + + "import p2.B;\n" + + "public class C extends B {\n" + + " void baz(B b) {\n" + + " ((A)b).new Member1(); // necessary since would bind to B.Member instead\n" + + " ((A)b).new Member2(); // UNnecessary\n" + + " ((A)b).new Member3(); // necessary since visibility issue\n" + + " ((A)b).new Member4().new M4Member(); // fault tolerance\n" + + " ((A)zork()).new Member1(); // fault-tolerance\n" + + " // anonymous\n"+ + " ((A)b).new Member1(){}; // necessary since would bind to B.Member instead\n" + + " ((A)b).new Member2(){}; // UNnecessary\n" + + " ((A)b).new Member3(){}; // necessary since visibility issue\n" + + " ((A)b).new Member4().new M4Member(){}; // fault tolerance\n" + + " ((A)zork()).new Member1(){}; // fault-tolerance\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\C.java (at line 6)\n" + + " ((A)b).new Member2(); // UNnecessary\n" + + " ^^^^^^\n" + + "Unnecessary cast from B to A\n" + + "----------\n" + + "2. ERROR in p1\\C.java (at line 8)\n" + + " ((A)b).new Member4().new M4Member(); // fault tolerance\n" + + " ^^^^^^\n" + + "Unnecessary cast from B to A\n" + + "----------\n" + + "3. ERROR in p1\\C.java (at line 9)\n" + + " ((A)zork()).new Member1(); // fault-tolerance\n" + + " ^^^^\n" + + "The method zork() is undefined for the type C\n" + + "----------\n" + + "4. ERROR in p1\\C.java (at line 12)\n" + + " ((A)b).new Member2(){}; // UNnecessary\n" + + " ^^^^^^\n" + + "Unnecessary cast from B to A\n" + + "----------\n" + + "5. ERROR in p1\\C.java (at line 14)\n" + + " ((A)b).new Member4().new M4Member(){}; // fault tolerance\n" + + " ^^^^^^\n" + + "Unnecessary cast from B to A\n" + + "----------\n" + + "6. ERROR in p1\\C.java (at line 15)\n" + + " ((A)zork()).new Member1(){}; // fault-tolerance\n" + + " ^^^^\n" + + "The method zork() is undefined for the type C\n" + + "----------\n", + null, + true, + customOptions); +} +// unnecessary cast diagnosis should tolerate array receiver type (40752) +public void test022() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X { \n" + + " void foo(java.util.Map map){ \n" + + " int[] fillPattern = new int[0]; \n" + + " if (fillPattern.equals((int[])map.get(\"x\"))) { \n" + + " } \n" + + " } \n"+ + "} \n", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 4)\n" + + " if (fillPattern.equals((int[])map.get(\"x\"))) { \n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to int[]\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// unnecessary cast diagnosis should tolerate array receiver type (40752) +public void test023() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " final long lgLow32BitMask1 = ~(~((long) 0) << 32); // necessary\n" + + " final long lgLow32BitMask2 = ~(~0 << 32); // necessary\n" + + " final long lgLow32BitMask3 = ~(~((long) 0L) << 32); // unnecessary\n" + + " final long lgLow32BitMask4 = ~(~((int) 0L) << 32); // necessary\n" + + " System.out.println(\"lgLow32BitMask1: \"+lgLow32BitMask1);\n" + + " System.out.println(\"lgLow32BitMask2: \"+lgLow32BitMask2);\n" + + " }\n" + + "}", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " final long lgLow32BitMask3 = ~(~((long) 0L) << 32); // unnecessary\n" + + " ^^^^^^^^^^^\n" + + "Unnecessary cast from long to long\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// unnecessary cast diagnosis for message receiver (44400) +public void test024() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public void foo(Object bar) {\n" + + " System.out.println(((Object) bar).toString());\n" + + " }\n" + + "}", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(((Object) bar).toString());\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to Object\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// unnecessary cast diagnosis for message receiver (44400) +// variation with field access +public void test025() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " int i;\n" + + " public void foo(X bar) {\n" + + " System.out.println(((X) bar).i);\n" + + " }\n" + + "}", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 4)\n" + + " System.out.println(((X) bar).i);\n" + + " ^^^^^^^^^\n" + + "Unnecessary cast from X to X\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47074 + */ +public void test026() { + + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = null;\n" + + " B b = (B) a;\n" + + " }\n" + + "}\n" + + "interface A {\n" + + " void doSomething();\n" + + "}\n" + + "interface B {\n" + + " int doSomething();\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " B b = (B) a;\n" + + " ^^^^^\n" + + "Cannot cast from A to B\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = null;\n" + + " B b = (B) a;\n" + + " }\n" + + "}\n" + + "interface A {\n" + + " void doSomething();\n" + + "}\n" + + "interface B {\n" + + " int doSomething();\n" + + "}", + }, + ""); + +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47074 + */ +public void test027() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = null;\n" + + " boolean b = a instanceof B;\n" + + " }\n" + + "}\n" + + "interface A {\n" + + " void doSomething();\n" + + "}\n" + + "interface B {\n" + + " int doSomething();\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " boolean b = a instanceof B;\n" + + " ^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types A and B\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = null;\n" + + " boolean b = a instanceof B;\n" + + " }\n" + + "}\n" + + "interface A {\n" + + " void doSomething();\n" + + "}\n" + + "interface B {\n" + + " int doSomething();\n" + + "}", + }, + ""); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47074 + */ +public void test028() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = null;\n" + + " B b = null;\n" + + " boolean c = a == b;\n" + + " }\n" + + "}\n" + + "interface A {\n" + + " void doSomething();\n" + + "}\n" + + "interface B {\n" + + " int doSomething();\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " boolean c = a == b;\n" + + " ^^^^^^\n" + + "Incompatible operand types A and B\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = null;\n" + + " B b = null;\n" + + " boolean c = a == b;\n" + + " }\n" + + "}\n" + + "interface A {\n" + + " void doSomething();\n" + + "}\n" + + "interface B {\n" + + " int doSomething();\n" + + "}", + }, + ""); + +} + +/* + * verify error when assigning null to array + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26903 + */ +public void test029() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) { \n" + + " try { \n" + + " char[][] qName; \n" + + " qName = null; \n" + + " qName[0] = new char[1]; \n" + + " } catch(Exception e){ \n" + + " } \n" + + " try { \n" + + " char[][] qName; \n" + + " qName = (char[][])null; \n" + + " qName[0] = new char[1]; \n" + + " } catch(Exception e){ \n" + + " } \n" + + " try { \n" + + " char[][] qName; \n" + + " qName = (char[][])(char[][])(char[][])null; \n" + + " qName[0] = new char[2]; \n" + + " } catch(Exception e){ \n" + + " } \n" + + " try { \n" + + " char[][] qName; \n" + + " qName = args.length > 1 ? new char[1][2] : null; \n" + + " qName[0] = new char[3]; \n" + + " } catch(Exception e){ \n" + + " } \n" + + " System.out.println(\"SUCCESS\"); \n"+ + " } \n" + + "} \n", + }, + "SUCCESS"); +} + +/* + * verify error when assigning null to array + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26903 + */ +public void test030() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) { \n" + + " try { \n" + + " char[][] qName = null; \n" + + " qName[0] = new char[1]; \n" + + " } catch(Exception e){ \n" + + " } \n" + + " try { \n" + + " char[][] qName = (char[][])null; \n" + + " qName[0] = new char[1]; \n" + + " } catch(Exception e){ \n" + + " } \n" + + " try { \n" + + " char[][] qName = (char[][])(char[][])(char[][])null; \n" + + " qName[0] = new char[2]; \n" + + " } catch(Exception e){ \n" + + " } \n" + + " try { \n" + + " char[][] qName = args.length > 1 ? new char[1][2] : null; \n" + + " qName[0] = new char[3]; \n" + + " } catch(Exception e){ \n" + + " } \n" + + " System.out.println(\"SUCCESS\"); \n"+ + " } \n" + + "} \n", + }, + "SUCCESS"); +} + +/* + * verify error when assigning null to array + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26903 + */ +public void test031() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) { \n" + + " try { \n" + + " char[][] qName = null; \n" + + " setName(qName[0]); \n" + + " } catch(Exception e){ \n" + + " } \n" + + " try { \n" + + " char[][] qName = (char[][])null; \n" + + " setName(qName[0]); \n" + + " } catch(Exception e){ \n" + + " } \n" + + " try { \n" + + " char[][] qName = (char[][])(char[][])(char[][])null; \n" + + " setName(qName[0]); \n" + + " } catch(Exception e){ \n" + + " } \n" + + " try { \n" + + " char[][] qName = args.length > 1 ? new char[1][2] : null; \n" + + " setName(qName[0]); \n" + + " } catch(Exception e){ \n" + + " } \n" + + " System.out.println(\"SUCCESS\"); \n"+ + " } \n" + + " static void setName(char[] name) { \n"+ + " } \n" + + "} \n", + }, + "SUCCESS"); +} +/* + * verify error when assigning null to array + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26903 + */ +public void test032() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " ((int[]) null)[0] = 0;\n" + + " ((int[]) null)[0] += 1;\n" + + " ((int[]) null)[0] ++;\n" + + " } catch (NullPointerException e) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} + +/* + * unused cast diagnosis + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=54763 + */ +public void test033() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " List list = (List) new ArrayList();\n" + + " list = (List) new ArrayList();\n" + + " \n" + + " String s = (String) \"hello\";\n" + + " s += (List) new ArrayList();\n" + + " \n" + + " ArrayList alist = new ArrayList();\n" + + " List list2 = (List) alist;\n" + + " list2 = (List) alist;\n" + + " \n" + + " String s2 = (String) \"hello\";\n" + + " s2 += (List) alist;\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " List list = (List) new ArrayList();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " list = (List) new ArrayList();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " String s = (String) \"hello\";\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " s += (List) new ArrayList();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " List list2 = (List) alist;\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " list2 = (List) alist;\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n" + + "7. ERROR in X.java (at line 16)\n" + + " String s2 = (String) \"hello\";\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n" + + "8. ERROR in X.java (at line 17)\n" + + " s2 += (List) alist;\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +/* + * check non insertion of checkcast for unnecessary cast to interfaces + * (same test case as test033) + */ +public void test034() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " List list = (List) new ArrayList();\n" + + " list = (List) new ArrayList();\n" + + " \n" + + " ArrayList alist = new ArrayList();\n" + + " List list2 = (List) alist;\n" + + " list2 = (List) alist;\n" + + " \n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new java.util.ArrayList [16]\n" + + " 3 dup\n" + + " 4 invokespecial java.util.ArrayList() [18]\n" + + " 7 astore_1 [list]\n" + + " 8 new java.util.ArrayList [16]\n" + + " 11 dup\n" + + " 12 invokespecial java.util.ArrayList() [18]\n" + + " 15 astore_1 [list]\n" + + " 16 new java.util.ArrayList [16]\n" + + " 19 dup\n" + + " 20 invokespecial java.util.ArrayList() [18]\n" + + " 23 astore_2 [alist]\n" + + " 24 aload_2 [alist]\n" + + " 25 astore_3 [list2]\n" + + " 26 aload_2 [alist]\n" + + " 27 astore_3 [list2]\n" + + " 28 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 31 ldc [25]\n" + + " 33 invokevirtual java.io.PrintStream.println(java.lang.String) : void [27]\n" + + " 36 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 8, line: 7]\n" + + " [pc: 16, line: 9]\n" + + " [pc: 24, line: 10]\n" + + " [pc: 26, line: 11]\n" + + " [pc: 28, line: 13]\n" + + " [pc: 36, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 37] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 37] local: list index: 1 type: java.util.List\n" + + " [pc: 24, pc: 37] local: alist index: 2 type: java.util.ArrayList\n" + + " [pc: 26, pc: 37] local: list2 index: 3 type: java.util.List\n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +// javac incorrectly accepts it +public void test035() { + String[] sources = { + "Test231.java", + "public class Test231 implements Test231i\n" + + "{\n" + + " void foo()\n" + + " {\n" + + " new Object()\n" + + " {\n" + + " Test231i bar()\n" + + " {\n" + + " return (Test231i)this;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + + "\n" + + "\n" + + "interface Test231i\n" + + "{\n" + + "}\n" + }; + if (this.complianceLevel < ClassFileConstants.JDK9) { + runNegativeTest(sources, + "----------\n" + + "1. ERROR in Test231.java (at line 9)\n" + + " return (Test231i)this;\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot cast from new Object(){} to Test231i\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } else { + runConformTest(sources, ""); + } +} +public void test036() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public final class X {\n" + + " private static final boolean DO_BUG = true;\n" + + "\n" + + " // Workaround: cast null to Base\n" + + " private static Base base = DO_BUG ?\n" + + " // (Base)null\n" + + " null : new Base() {\n" + + " public final String test() {\n" + + " return (\"anonymous\");\n" + + " }\n" + + " };\n" + + "\n" + + " private X() {\n" + + " }\n" + + "\n" + + " public static void main(String[] argv) {\n" + + " if (base == null)\n" + + " System.out.println(\"no base\");\n" + + " else\n" + + " System.out.println(base.test());\n" + + " }\n" + + "\n" + + " private static abstract class Base {\n" + + " public Base() {\n" + + " }\n" + + "\n" + + " public abstract String test();\n" + + " }\n" + + "}\n" + }, + // compiler results + "", /* expected compiler log */ + // runtime results + "no base" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +public void test037() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer[] integers = {};\n" + + " int[] ints = (int[]) integers;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int[] ints = (int[]) integers;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Integer[] to int[]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101208 +public void test038() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " System.out.println(null instanceof Object);\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " Zork z;\r\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//unnecessary cast warnings in assignment (Object o = (String) something). +public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " Object fo = (String) new Object();\n" + + " void foo(ArrayList al) {\n" + + " List l = (List) al;\n" + + " Object o;\n" + + " o = (ArrayList) al;\n" + + " Object o2 = (ArrayList) al;\n" + + " o = (ArrayList) l;\n" + + " Object o3 = (ArrayList) l;\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object fo = (String) new Object();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to String\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " List l = (List) al;\n" + + " ^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " o = (ArrayList) al;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to ArrayList\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " Object o2 = (ArrayList) al;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to ArrayList\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " o = (ArrayList) l;\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to ArrayList\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " Object o3 = (ArrayList) l;\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to ArrayList\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//http://bugs.eclipse.org/bugs/show_bug.cgi?id=116647 +public void test040() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " {\n" + + " int i = 12;\n" + + " int j = (byte) i;\n" + + " float f = (float) i;\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " float f = (float) i;\n" + + " ^^^^^^^^^\n" + + "Unnecessary cast from int to float\n" + + "----------\n" + + "2. 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=158855 +public void test041() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " class A extends X {\n" + + " public void callMe() {\n" + + " }\n" + + " }\n" + + " public abstract void callMe();\n" + + " class B {\n" + + " public void callSite() {\n" + + " // expect warning not there:\n" + + " ((A) this.getAA()).callMe();\n" + + " Integer max = Integer.valueOf(1);\n" + + " // execpted warning there:\n" + + " Integer other = (Integer) max;\n" + + " }\n" + + " public X getAA() {\n" + + " Zork z;\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " Integer other = (Integer) max;\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary cast from Integer to Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159654 +public void test042() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\"); \n" + + " }\n" + + " \n" + + " public static void foo(boolean b, List l) {\n" + + " if (b) {\n" + + " String s = (String) l.get(0);\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159654 +public void test043() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\"); \n" + + " }\n" + + " \n" + + " public static void foo(boolean b, List l) {\n" + + " if (b) {\n" + + " Object o = (Object) l.get(0);\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159822 +public void test044() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String s;\n" + + " public static void main(String[] args) throws Throwable {\n" + + " if (args.length == 0) {\n" + + " Class c = Class.forName(\"X\");\n" + + " String s = ((X) c.newInstance()).s;\n" + + " System.out.println(s);\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}", + }, + "null"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239305 +public void test045() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(castLongToInt(3));\n" + + " }\n" + + " private static int castLongToInt(long longVal) {\n" + + " return (int)((long)longVal);\n" + + " }\n" + + "}\n", + }, + "3"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282869 +public void test046() { + this.runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " char a = 65;\n" + + " String b = \"\" + a; // -> \"A\"\n" + + " String c = \"\" + (int) a;\n" + + " System.out.print(b);\n" + + " System.out.print(c);\n" + + " \n" + + " String logText = \" second case \";\n" + + " char firstChar = 65;\n" + + " logText += (int) firstChar;\n" + + " System.out.println(logText);\n" + + " }\n" + + "}", + }, + "", + "A65 second case 65", + "", + JavacTestOptions.SKIP); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287676 +// Test to make sure that an unnecessary cast warning is produced in case of +// wrapper types like Integer, Character, Short, Byte, etc. +public void test047() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X{\n" + + " void test() {" + + " Integer a = 1;\n" + + " ArrayList aList = new ArrayList(1);\n" + + " a = (Integer)a + (Integer)2;\n" + + " if ((Character)aList.get(0) == 'c')\n" + + " System.out.println();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " a = (Integer)a + (Integer)2;\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from Integer to Integer\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " a = (Integer)a + (Integer)2;\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from int to Integer\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " if ((Character)aList.get(0) == 'c')\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Character to Character\n" + + "----------\n" + ); +} +public void testBug418795() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses autoboxing + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Integer smallNumber = 42;\n" + + " Integer largeNumber = 500;\n" + + "\n" + + " // this prints:\n" + + " if (smallNumber == 42)\n" + + " System.out.println(\"42\");\n" + + "\n" + + " // this prints:\n" + + " if (largeNumber == 500)\n" + + " System.out.println(\"500\");\n" + + "\n" + + " // this prints:\n" + + " if (smallNumber == (Object) 42)\n" + + " System.out.println(\"42\");\n" + + "\n" + + " // this doesn't print:\n" + + " if (largeNumber == (Object) 500)\n" + + " System.out.println(\"500\");\n" + + "" + + " }\n" + + "}\n" + }, + options); +} +public void testBug329437() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses autoboxing + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String... args) {\n" + + " Integer a = Integer.valueOf(10);\n" + + " Integer b = Integer.valueOf(10);\n" + + " boolean abEqual = (int)a == (int)b;\n" + + " System.out.println(abEqual);\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug521778() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int intThruFloat(int x) { return (int)(float)x; }\n" + + " static long longThruFloat(long x) { return (long)(float)x; }\n" + + " static long longThruDouble(long x) { return (long)(double)x; }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(intThruFloat(2147483646));\n" + + " System.out.println(longThruFloat(-9223372036854775806L));\n" + + " System.out.print(longThruDouble(-9223372036854775807L));\n" + + " }\n" + + "}\n" + }, + "2147483647\n" + // not the + "-9223372036854775808\n" + // same as + "-9223372036854775808", // the input + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302919 +public void test048() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) return; + this.runNegativeTest( + new String[] { + "A.java", + "public class A extends D {\n" + + " public class A1 extends D1 {\n" + + " }\n" + + " void m1(A tree) {\n" + + " A.A1 v = ((A.A1) tree.root);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class D {\n" + + " protected D1 root;\n" + + " protected class D1 {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302919 +public void test049() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) return; + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "A.java", + "public class A {\n" + + " void foo(Other2.Member2 om2) {\n" + + " Other.Member m = (Other.Member) om2;\n" + + " m = om2;\n" + + " }\n" + + "}\n" + + "class Other {\n" + + " class Member {}\n" + + "}\n" + + "class Other2 extends Other {\n" + + " class Member2 extends Other.Member {\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in A.java (at line 3)\n" + + " Other.Member m = (Other.Member) om2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Other2.Member2 to Other.Member\n" + + "----------\n"; + runner.javacTestOptions = + Excuse.EclipseHasSomeMoreWarnings; // javac is inconsistent: accepting both assignments, not issuing a warning though in simpler cases it does + // note that javac 1.6 doesn't even accept the syntax of this cast + runner.runWarningTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302919 +public void test050() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) return; + this.runNegativeTest( + new String[] { + "A.java", + "public class A extends D {\n" + + " public class A1 extends D.D1 {\n" + + " }\n" + + " void m1(A tree) {\n" + + " A.A1 v = ((A.A1) tree.root);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class D {\n" + + " protected D1 root;\n" + + " protected class D1 {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test051() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " boolean y = (boolean) x;\n" + + " System.out.println(y);\n" + + " }\n" + + " public static Object foo() {\n" + + " return Boolean.TRUE;\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " boolean y = (boolean) x;\n" + + " ^^^^^^^^^^^\n" + + "Cannot cast from Object to boolean\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "true" + ); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test052() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " byte y = (byte) x;\n" + + " System.out.println(y);\n" + + " }\n" + + " public static Object foo() {\n" + + " return Byte.valueOf((byte)1);\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " byte y = (byte) x;\n" + + " ^^^^^^^^\n" + + "Cannot cast from Object to byte\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "1" + ); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test053() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " char y = (char) x;\n" + + " System.out.println(y);\n" + + " }\n" + + " public static Object foo() {\n" + + " return Character.valueOf('d');\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " char y = (char) x;\n" + + " ^^^^^^^^\n" + + "Cannot cast from Object to char\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "d" + ); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +// Also confirm that a check cast and unboxing conversion are generated. +public void test054() throws Exception { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " int y = (int) x;\n" + + " System.out.println(y);\n" + + " }\n" + + " public static Object foo() {\n" + + " return Integer.valueOf(1);\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int y = (int) x;\n" + + " ^^^^^^^\n" + + "Cannot cast from Object to int\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "1" + ); + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 invokestatic X.foo() : java.lang.Object [16]\n" + + " 3 astore_1 [x]\n" + + " 4 aload_1 [x]\n" + + " 5 checkcast java.lang.Integer [20]\n" + + " 8 invokevirtual java.lang.Integer.intValue() : int [22]\n" + + " 11 istore_2 [y]\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [26]\n" + + " 15 iload_2 [y]\n" + + " 16 invokevirtual java.io.PrintStream.println(int) : void [32]\n" + + " 19 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 12, line: 5]\n" + + " [pc: 19, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 20] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 20] local: x index: 1 type: java.lang.Object\n" + + " [pc: 12, pc: 20] local: y index: 2 type: int\n" + + " \n"; + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test055() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " long y = (long) x;\n" + + " System.out.println(y);\n" + + " }\n" + + " public static Object foo() {\n" + + " return Long.valueOf(Long.MAX_VALUE);\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " long y = (long) x;\n" + + " ^^^^^^^^\n" + + "Cannot cast from Object to long\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "9223372036854775807" + ); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test056() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " short y = (short) x;\n" + + " System.out.println(y);\n" + + " }\n" + + " public static Object foo() {\n" + + " return Short.valueOf((short) 1);\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " short y = (short) x;\n" + + " ^^^^^^^^^\n" + + "Cannot cast from Object to short\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "1" + ); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test057() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " double y = (double) x;\n" + + " System.out.println(y);\n" + + " }\n" + + " public static Object foo() {\n" + + " return Double.valueOf(1.0);\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " double y = (double) x;\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from Object to double\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "1.0" + ); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test058() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " float y = (float) x;\n" + + " System.out.println(y);\n" + + " }\n" + + " public static Object foo() {\n" + + " return Float.valueOf(1.0f);\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " float y = (float) x;\n" + + " ^^^^^^^^^\n" + + "Cannot cast from Object to float\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "1.0" + ); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test059() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " try {\n" + + " int y = (int) x;\n" + + " } catch (ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAIL\");\n" + + " }\n" + + " public static Object foo() {\n" + + " return Float.valueOf(1.0f);\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " int y = (int) x;\n" + + " ^^^^^^^\n" + + "Cannot cast from Object to int\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "SUCCESS" + ); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test059b() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " try {\n" + + " int y = (int) x;\n" + + " } catch (ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAIL\");\n" + + " }\n" + + " public static Object foo() {\n" + + " return Boolean.TRUE;\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " int y = (int) x;\n" + + " ^^^^^^^\n" + + "Cannot cast from Object to int\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "SUCCESS" + ); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test059c() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " try {\n" + + " char y = (char) x;\n" + + " } catch (ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAIL\");\n" + + " }\n" + + " public static Object foo() {\n" + + " return Boolean.TRUE;\n" + + " }\n" + + "}"; + if (options.sourceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " char y = (char) x;\n" + + " ^^^^^^^^\n" + + "Cannot cast from Object to char\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + source + }, + "SUCCESS" + ); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test060() { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " Boolean y = (Boolean) x;\n" + + " System.out.println(y);\n" + + " }\n" + + " public static Object foo() {\n" + + " return Boolean.TRUE;\n" + + " }\n" + + "}"; + this.runConformTest( + new String[] { + "X.java", + source + }, + "true" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353085 +public void test061() { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object x = foo();\n" + + " try {\n" + + " Float y = (Float) x;\n" + + " } catch (ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAIL\");\n" + + " }\n" + + " public static Object foo() {\n" + + " return Boolean.TRUE;\n" + + " }\n" + + "}"; + this.runConformTest( + new String[] { + "X.java", + source + }, + "SUCCESS" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=359284 +// Verify that checkcast is emitted for a cast expression. +public void test061b() throws Exception { + String source = + "public class X {\n" + + "public X() {\n" + + " Object[] x = (Object[])null;\n" + + "}\n" + + "}\n"; + this.runConformTest( + new String[] { + "X.java", + source + }, + "" + ); + String expectedOutput = + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 aconst_null\n" + + " 5 checkcast java.lang.Object[] [10]\n" + + " 8 astore_1 [x]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " [pc: 4, line: 3]\n" + + " [pc: 9, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " [pc: 9, pc: 10] local: x index: 1 type: java.lang.Object[]\n" + + "}"; + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=420283, [1.8] Wrong error "Type is not visible" for cast to intersection type +public void test420283() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " void foo(List l) {\n" + + " Integer i = (Integer & Serializable) l.get(0);\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Integer i = (Integer & Serializable) l.get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Integer to Integer & Serializable\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Integer i = (Integer & Serializable) l.get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Additional bounds are not allowed in cast operator at source levels below 1.8\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " void foo(List l) {\n" + + " Integer i = (Integer & Serializable) l.get(0);\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS" + ); +} + +public void testBug428274() { + String source = + "public class Junk4 {\n" + + " static void setValue(Number n) {\n" + + " int rounded = (int) Math.round((double) n);\n" + + " System.out.println(rounded);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " setValue(Double.valueOf(3.3));\n" + + " setValue(Double.valueOf(3.7));\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + runNegativeTest( + new String[] { + "Junk4.java", + source + }, + "----------\n" + + "1. ERROR in Junk4.java (at line 3)\n" + + " int rounded = (int) Math.round((double) n);\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from Number to double\n" + + "----------\n"); + } else { + runConformTest( + new String[] { + "Junk4.java", + source + }, + "3\n4"); + } +} +public void testBug428274b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; // uses generics + Runner runner = new Runner(); + runner.testFiles = new String[] { + "Junk4.java", + "public class Junk4 {\n" + + " void setValue(T n) {\n" + + " int rounded = (int) Math.round((double) n);\n" + + " System.out.println(rounded);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Junk4 j = new Junk4();\n" + + " j.setValue(Double.valueOf(3.3));\n" + + " j.setValue(Double.valueOf(3.7));\n" + + " }\n" + + "}\n" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in Junk4.java (at line 3)\n" + + " int rounded = (int) Math.round((double) n);\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from T to double\n" + + "----------\n"; + runner.runNegativeTest(); + } else { + runner.expectedOutputString = + "3\n4"; + runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8144832; + runner.runConformTest(); + } +} +// note: spec allows all reference types, but neither javac nor common sense accept arrays :) +public void testBug428274c() { + String source = + "public class Junk4 {\n" + + " static void setValue(Object[] n) {\n" + + " int rounded = (int) Math.round((double) n);\n" + + " System.out.println(rounded);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " setValue(new Double[] { Double.valueOf(3.3) });\n" + + " }\n" + + "}\n"; + runNegativeTest( + new String[] { + "Junk4.java", + source + }, + "----------\n" + + "1. ERROR in Junk4.java (at line 3)\n" + + " int rounded = (int) Math.round((double) n);\n" + + " ^^^^^^^^^^\n" + + "Cannot cast from Object[] to double\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int x = (int) \"Hello\";\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int x = (int) \"Hello\";\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot cast from String to int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388a() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void setValue(Number n) {\n" + + " int rounded = (int) Math.round((double) n);\n" + + " System.out.println(rounded);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " setValue(Double.valueOf(3.3));\n" + + " setValue(Double.valueOf(3.7));\n" + + " }\n" + + "}\n", + }, + "3\n4"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 (Ljava/lang/Number;)V\n" + + " // Stack: 2, Locals: 2\n" + + " static void setValue(java.lang.Number n);\n" + + " 0 aload_0 [n]\n" + + " 1 checkcast java.lang.Double [16]\n" + + " 4 invokevirtual java.lang.Double.doubleValue() : double [18]\n" + + " 7 invokestatic java.lang.Math.round(double) : long [22]\n" + + " 10 l2i\n" + + " 11 istore_1 [rounded]\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 15 iload_1 [rounded]\n" + + " 16 invokevirtual java.io.PrintStream.println(int) : void [34]\n" + + " 19 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 12, line: 4]\n" + + " [pc: 19, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 20] local: n index: 0 type: java.lang.Number\n" + + " [pc: 12, pc: 20] local: rounded index: 1 type: int\n" + + " \n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static void setValue(Number n) {\n" + + " char rounded = (char) n;\n" + + " System.out.println(rounded);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " setValue(Double.valueOf(3.3));\n" + + " setValue(Double.valueOf(3.7));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " char rounded = (char) n;\n" + + " ^^^^^^^^\n" + + "Cannot cast from Number to char\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388c() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void setValue(Number n) {\n" + + " try {\n" + + " byte rounded = (byte) n;\n" + + " System.out.println(rounded);\n" + + " } catch (ClassCastException c) {\n" + + " System.out.println(\"CCE\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " setValue(Double.valueOf(3.3));\n" + + " setValue(Double.valueOf(3.7));\n" + + " }\n" + + "}\n", + }, + "CCE\nCCE"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388d() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X implements Serializable {\n" + + " static int test(Serializable v) {\n" + + " try {\n" + + " return (int)v;\n" + + " } catch (ClassCastException c) {\n" + + " System.out.println(\"CCE\");\n" + + " }\n" + + " return -1;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int i = test(new X());\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "CCE\n-1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388e() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X implements Serializable {\n" + + " static int test(Serializable v) {\n" + + " try {\n" + + " return (int)v;\n" + + " } catch (ClassCastException c) {\n" + + " System.out.println(\"CCE\");\n" + + " }\n" + + " return -1;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int i = test(new Long(1234));\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "CCE\n-1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388f() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X implements Serializable {\n" + + " static int test(Serializable v) {\n" + + " try {\n" + + " return (int)v;\n" + + " } catch (ClassCastException c) {\n" + + " System.out.println(\"CCE\");\n" + + " }\n" + + " return -1;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int i = test(new Integer(1234));\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "1234"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388g() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X implements Serializable {\n" + + " static int test(S b) {\n" + + " return (int) b;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " int i = test(Boolean.TRUE);\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public class X implements Serializable {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " static int test(S b) {\n" + + " ^^^^^^^\n" + + "The type parameter S should not be bounded by the final type Boolean. Final types cannot be further extended\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " return (int) b;\n" + + " ^^^^^^^\n" + + "Cannot cast from S to int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388h() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // uses intersection cast + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X implements Serializable {\n" + + " static int test(Serializable b) {\n" + + " return (int) (Boolean & Serializable) b;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int i = test(Boolean.TRUE);\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public class X implements Serializable {\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 4)\n" + + " return (int) (Boolean & Serializable) b;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Boolean & Serializable to int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388i() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X implements Serializable {\n" + + " static int test(Serializable v) {\n" + + " try {\n" + + " return (int)v;\n" + + " } catch (ClassCastException c) {\n" + + " System.out.println(\"CCE\");\n" + + " }\n" + + " return -1;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int i = test(new Integer(1234));\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "1234"); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #17 (Ljava/io/Serializable;)I\n" + + " // Stack: 2, Locals: 2\n" + + " static int test(java.io.Serializable v);\n" + + " 0 aload_0 [v]\n" + + " 1 checkcast java.lang.Integer [18]\n" + + " 4 invokevirtual java.lang.Integer.intValue() : int [20]\n" + + " 7 ireturn\n" + + " 8 astore_1 [c]\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [24]\n" + + " 12 ldc [30]\n" + + " 14 invokevirtual java.io.PrintStream.println(java.lang.String) : void [32]\n" + + " 17 iconst_m1\n" + + " 18 ireturn\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428388, [1.8][compiler] Casting to primitives is over tolerant - probable regression since bug 428274 +public void test428388j() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // uses intersection cast + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X implements Serializable {\n" + + " static int test(Serializable b) {\n" + + " return (int) (Integer & Serializable) b;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int i = test(10101010);\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "10101010"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428522, [1.8] VerifyError when a non primitive type cast to primitive type +public void test428522() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " long l = (long) ((Object) 100L);\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", + }, + "OK", customOptions); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [16]\n" + + " 3 invokestatic java.lang.Long.valueOf(long) : java.lang.Long [18]\n" + + " 6 checkcast java.lang.Long [19]\n" + + " 9 invokevirtual java.lang.Long.longValue() : long [24]\n" + + " 12 pop2\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 16 ldc [34]\n" + + " 18 invokevirtual java.io.PrintStream.println(java.lang.String) : void [36]\n" + + " 21 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 13, line: 4]\n" + + " [pc: 21, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 22] local: args index: 0 type: java.lang.String[]\n" + + "}"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428522, [1.8] VerifyError when a non primitive type cast to primitive type +public void test428522a() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " long l = (long) ((Object) 100L);\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", + }, + "OK", customOptions); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc2_w [16]\n" + + " 3 invokestatic java.lang.Long.valueOf(long) : java.lang.Long [18]\n" + + " 6 checkcast java.lang.Long [19]\n" + + " 9 invokevirtual java.lang.Long.longValue() : long [24]\n" + + " 12 lstore_1 [l]\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 16 ldc [34]\n" + + " 18 invokevirtual java.io.PrintStream.println(java.lang.String) : void [36]\n" + + " 21 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 13, line: 4]\n" + + " [pc: 21, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 22] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 13, pc: 22] local: l index: 1 type: long\n" + + "}"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428522, [1.8] VerifyError when a non primitive type cast to primitive type +public void test428522b() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " try {\n" + + " int l = (int) ((Object) 100L);\n" + + " } catch (ClassCastException c) {\n" + + " System.out.println(\"CCE:OK\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "CCE:OK", customOptions); + +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428522, [1.8] VerifyError when a non primitive type cast to primitive type +public void test428522c() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " int l = (int) ((Object) 100);\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", + }, + "OK", customOptions); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 100\n" + + " 2 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [16]\n" + + " 5 checkcast java.lang.Integer [17]\n" + + " 8 invokevirtual java.lang.Integer.intValue() : int [22]\n" + + " 11 pop\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [26]\n" + + " 15 ldc [32]\n" + + " 17 invokevirtual java.io.PrintStream.println(java.lang.String) : void [34]\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 12, line: 4]\n" + + " [pc: 20, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 21] local: args index: 0 type: java.lang.String[]\n" + + "}"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=441731 JDT reports unnecessary cast, using the Quickfix to remove it creates syntax error +public void test441731() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "interface MUIElement {}\n" + + "interface MUIElementContainer extends MUIElement{}\n" + + "interface MWindowElement extends MUIElement {}\n" + + "interface MWindow extends MUIElementContainer {}\n" + + "public class X {\n" + + " void test(MUIElementContainer me) {\n" + + " if(((MUIElement) me) instanceof MWindow) return;\n" + + " MWindow mw = (MWindow)((MUIElement)me);\n" + + " }\n" + + "}\n" + }, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448112, [compiler] Compiler crash (ArrayIndexOutOfBoundsException at StackMapFrame.addStackItem()) with unused variable +public void test448112() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " static class Y {\n" + + " public Object getAttribute(String name) {\n" + + " return new Long(100L);\n" + + " }\n" + + " }\n" + + " public static void foo2(Y y) {\n" + + "\n" + + " try {\n" + + " long v1 = (Long) y.getAttribute(\"v1\");\n" + + " long v2 = (Long) y.getAttribute(\"v2\");\n" + + "\n" + + " System.out.println(String.valueOf(v1));\n" + + "\n" + + " } catch (java.lang.Throwable t) {}\n" + + " }\n" + + " \n" + + " public static void main(String args[]) {\n" + + " foo2(new Y());\n" + + " }\n" + + "}", + }, + "100", customOptions); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " public static void foo2(X.Y y);\n" + + " 0 aload_0 [y]\n" + + " 1 ldc [16]\n" + + " 3 invokevirtual X$Y.getAttribute(java.lang.String) : java.lang.Object [18]\n" + + " 6 checkcast java.lang.Long [24]\n" + + " 9 invokevirtual java.lang.Long.longValue() : long [26]\n" + + " 12 lstore_1 [v1]\n" + + " 13 aload_0 [y]\n" + + " 14 ldc [30]\n" + + " 16 invokevirtual X$Y.getAttribute(java.lang.String) : java.lang.Object [18]\n" + + " 19 checkcast java.lang.Long [24]\n" + + " 22 pop\n" + + " 23 getstatic java.lang.System.out : java.io.PrintStream [32]\n" + + " 26 lload_1 [v1]\n" + + " 27 invokestatic java.lang.String.valueOf(long) : java.lang.String [38]\n" + + " 30 invokevirtual java.io.PrintStream.println(java.lang.String) : void [44]\n" + + " 33 goto 37\n" + + " 36 pop\n" + + " 37 return\n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=461706 [1.8][compiler] "Unnecessary cast" problems for necessary cast in lambda expression +public void test461706() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "Bug.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Bug {\n" + + " private static class AndCondition implements ICondition {\n" + + " public AndCondition(ICondition cond1, ICondition cond2) {\n" + + " // todo\n" + + " }\n" + + " }\n" + + " private static class SimpleCondition implements ICondition {\n" + + " }\n" + + " private static interface ICondition {\n" + + " ICondition TRUE = new SimpleCondition();\n" + + " default ICondition and(final ICondition cond) {\n" + + " return new AndCondition(this, cond);\n" + + " }\n" + + " }\n" + + " public static void main(final String[] args) {\n" + + " final List conditions = new ArrayList<>();\n" + + " conditions.stream()\n" + + " .map(x -> (ICondition)x)\n" + + " .reduce((x, y) -> x.and(y))\n" + + " .orElse(ICondition.TRUE);\n" + + " }\n" + + "}" + }, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=461706 [1.8][compiler] "Unnecessary cast" problems for necessary cast in lambda expression +public void test461706a() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "Bug.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Bug {\n" + + " private static class AndCondition implements ICondition {\n" + + " public AndCondition(ICondition cond1, ICondition cond2) {\n" + + " // todo\n" + + " }\n" + + " }\n" + + " static class SimpleCondition implements ICondition {\n" + + " }\n" + + " private static interface ICondition {\n" + + " ICondition TRUE = new SimpleCondition();\n" + + " default ICondition and(final ICondition cond) {\n" + + " return new AndCondition(this, cond);\n" + + " }\n" + + " }\n" + + " public static void main(final String[] args) {\n" + + " final List conditions = new ArrayList<>();\n" + + " conditions.stream()\n" + + " .map(x -> (ICondition)x)\n" + + " .reduce((x, y) -> x.and(y))\n" + + " .orElse(ICondition.TRUE);\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in Bug.java (at line 20)\n" + + " .map(x -> (ICondition)x)\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary cast from Bug.ICondition to Bug.ICondition\n" + + "----------\n"; + runner.runWarningTest(); +} +public void testAnonymous_bug520727() { + String[] source = { + "O.java", + "import java.io.Serializable;\n" + + "public class O {\n" + + " Object in = new Object() {\n" + + " public Object foo() {\n" + + " return (Serializable) this;\n" + + " }\n" + + " };\n" + + "}\n" + }; + if (this.complianceLevel < ClassFileConstants.JDK9) { + runNegativeTest(source, + "----------\n" + + "1. ERROR in O.java (at line 5)\n" + + " return (Serializable) this;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from new Object(){} to Serializable\n" + + "----------\n"); + } else { + // starting from JLS 9, anonymous classes are *not* final, hence casting is legal: + runConformTest(source,""); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=543727 False positive "Unnecessary cast" +public void test543727() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "Bug.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Bug {\n" + + " public static void main(String[] args) {\n" + + " List> vector = new ArrayList<>();\n" + + " vector.add(0);\n" + + " if (vector.get(0) == (Integer)0) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + " }" + + "}\n", + }, + "SUCCESS"); +} +public void test543727_notequals() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "Bug.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Bug {\n" + + " public static void main(String[] args) {\n" + + " List> vector = new ArrayList<>();\n" + + " vector.add(0);\n" + + " if (vector.get(0) != (Integer)1) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + " }" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=548647 JDT reports unnecessary cast, using the Quickfix to remove it creates syntax error +public void test548647() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "interface MUIElement {}\n" + + "interface MUIElementContainer extends MUIElement{}\n" + + "interface MWindowElement extends MUIElement {}\n" + + "interface MWindow extends MUIElementContainer {}\n" + + "public class X {\n" + + " MUIElementContainer field;\n" + + " MUIElementContainer getField() {\n" + + " return field;\n" + + " }\n" + + " void test(MUIElementContainer me) {\n" + + " MUIElementContainer localVar = me;\n" + + " if ((Object) localVar instanceof MWindow) return;\n" + + " if(((Object) me) instanceof MWindow) return;\n" + + " if ((MUIElement)field instanceof MWindow) return;\n" + + " if ((MUIElement)getField() instanceof MWindow) return;\n" + + " MWindow mw = (MWindow)((MUIElement)me);\n" + + " }\n" + + "}\n" + }, + customOptions); +} +public void test548647a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "Bug.java", + "public class Bug {\n" + + " Integer k;\n" + + " private Number getK() { return k; }\n" + + " public void fn(Number n) {\n" + + " Number j = n;\n" + + " if ((Number) n instanceof Long) return;\n" + + " if ((Number) k instanceof Integer) return;\n" + + " if ((Number) j instanceof Integer) return;\n" + + " if ((Number) getK() instanceof Integer) return;\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in Bug.java (at line 6)\n" + + " if ((Number) n instanceof Long) return;\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from Number to Number\n" + + "----------\n" + + "2. WARNING in Bug.java (at line 7)\n" + + " if ((Number) k instanceof Integer) return;\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from Integer to Number\n" + + "----------\n" + + "3. WARNING in Bug.java (at line 8)\n" + + " if ((Number) j instanceof Integer) return;\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from Number to Number\n" + + "----------\n" + + "4. WARNING in Bug.java (at line 9)\n" + + " if ((Number) getK() instanceof Integer) return;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Number to Number\n" + + "----------\n"; + runner.runWarningTest(); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=472466 [compiler] bogus warning "unnecessary cast" +public void test472466() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public int foo() {\n" + + " Object x = 4;\n" + + " Integer y = 5;\n" + + " if (x == (Object)50) return -1;\n" + + " if (x == (Integer)50) return -2;\n" + + " if ((Integer)x == (Integer)50) return -3;\n" + + " if (y == 7) return -4;\n" + + " if ((Integer)y == 9) return -5;\n" + + " if ((Object)50 == x) return -6;\n" + + " if ((Integer)50 == x) return -7;\n" + + " if ((Integer)50 == (Integer)x) return -8;\n" + + " if (7 == y) return -9;\n" + + " return 0;\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " if ((Integer)y == 9) return -5;\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from Integer to Integer\n" + + "----------\n"; + runner.runWarningTest(); +} + +public void testBug561167() { + if (this.complianceLevel < ClassFileConstants.JDK10) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var s = (String) null; // Necessary\n" + + " var t = (String) \"hello\"; // UNnecessary\n" + + " var f = (float) 12; // Necessary\n" + + " var g = (float)f; // UNnecessary\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " var t = (String) \"hello\"; // UNnecessary\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " var g = (float)f; // UNnecessary\n" + + " ^^^^^^^^\n" + + "Unnecessary cast from float to float\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +public static Class testClass() { + return CastTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CharOperationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CharOperationTest.java new file mode 100644 index 0000000000..1d1b72628e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CharOperationTest.java @@ -0,0 +1,174 @@ +/******************************************************************************* + * Copyright (c) 2005, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.core.compiler.CharOperation; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class CharOperationTest extends AbstractRegressionTest { + +public CharOperationTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} +public static Class testClass() { + return CharOperationTest.class; +} +public void test001() { + char[] array = { 'a' , 'b', 'b', 'c', 'a', 'b', 'c', 'a' }; + char[] toBeReplaced = { 'b', 'c' }; + char replacementChar = 'a'; + int start = 4; + int end = 8; + CharOperation.replace(array, toBeReplaced, replacementChar, start, end); + char[] result = { 'a' , 'b', 'b', 'c', 'a', 'a', 'a', 'a' }; + + for (int i = 0, max = array.length; i < max; i++) { + assertEquals("Wrong value at " + i, result[i], array[i]); + } +} +public void test002() { + char[] array = { 'a' , 'b', 'b', 'c', 'a', 'b', 'c', 'a' }; + char[] toBeReplaced = { 'b', 'c' }; + char replacementChar = 'a'; + int start = 2; + int end = 3; + CharOperation.replace(array, toBeReplaced, replacementChar, start, end); + char[] result = { 'a' , 'b', 'a', 'c', 'a', 'b', 'c', 'a' }; + + for (int i = 0, max = array.length; i < max; i++) { + assertEquals("Wrong value at " + i, result[i], array[i]); + } +} +public void test003() { + char[] second = { 'a' , 'b', 'b', 'c', 'a', 'b', 'c', 'a' }; + char[] first = { 'b', 'c', 'a' }; + int start = 2; + int end = 5; + assertTrue(CharOperation.equals(first, second, start, end, true)); +} +public void test004() { + char[] second = { 'A' }; + char[] first = { 'a' }; + int start = 0; + int end = 1; + assertTrue(CharOperation.equals(first, second, start, end, false)); +} +public void test005() { + char[] array = { 'a' , 'b', 'b', 'c', 'a', 'b', 'c', 'a' }; + char[] toBeReplaced = { 'b', 'c' }; + char replacementChar = 'a'; + CharOperation.replace(array, toBeReplaced, replacementChar); + char[] result = { 'a' , 'a', 'a', 'a', 'a', 'a', 'a', 'a' }; + + for (int i = 0, max = array.length; i < max; i++) { + assertEquals("Wrong value at " + i, result[i], array[i]); + } +} +public void test006() { + char[] array = { 'a' , 'a', 'a', 'a', 'a', 'b', 'c', 'a' }; + char[] toBeReplaced = { 'a', 'a' }; + char[] replacementChar = { 'a' }; + char[] result = CharOperation.replace(array, toBeReplaced, replacementChar); + char[] expectedValue = { 'a' , 'a', 'a', 'b', 'c', 'a' }; + assertEquals("Wrong size", expectedValue.length, result.length); + for (int i = 0, max = expectedValue.length; i < max; i++) { + assertEquals("Wrong value at " + i, result[i], expectedValue[i]); + } +} +// test compareTo(char[], char[]) +public void test007() { + char[] array = { 'a' , 'a', 'a', 'a', 'a', 'b', 'c', 'a' }; + char[] array2 = { 'a', 'a' }; + assertTrue(CharOperation.compareTo(array, array2) > 0); + + array2 = new char[] { 'a', 'a' }; + array = new char[] { 'a' , 'a', 'a', 'a', 'a', 'b', 'c', 'a' }; + assertTrue(CharOperation.compareTo(array2, array) < 0); + + array = new char[] { 'a' , 'a', 'a', 'a', 'a', 'b', 'c', 'a' }; + array2 = new char[] { 'a' , 'a', 'a', 'a', 'a', 'b', 'c', 'a' }; + assertTrue(CharOperation.compareTo(array, array2) == 0); + assertTrue(CharOperation.compareTo(array2, array) == 0); + + array = new char[] { 'a' , 'b', 'c' }; + array2 = new char[] { 'a' , 'b', 'c', 'a', 'a'}; + assertTrue(CharOperation.compareTo(array, array2) < 0); + + array = new char[] { 'a' , 'b', 'c' }; + array2 = new char[] { 'a' , 'b', 'd'}; + assertTrue(CharOperation.compareTo(array, array2) < 0); +} +// test indexOf case sensitive +public void test008() { + char[] array = new char[] { 'a' , 'b', 'c' }; + char[] array2 = new char[] { 'a' , 'b', 'c', 'a', 'a'}; + assertTrue(CharOperation.indexOf(array, array2, true, -1) < 0); +} +// test indexOf case insensitive +public void test009() { + char[] array = new char[] { 'a' , 'b', 'c' }; + char[] array2 = new char[] { 'a' , 'b', 'c', 'a', 'a'}; + assertTrue(CharOperation.indexOf(array, array2, false, -1) < 0); +} +//test new API org.eclipse.jdt.core.compiler.CharOperation.prefixEquals(char[], char[], boolean, int) +public void test010() { + char[] name = new char[] { 'a' , 'b', 'c', 'a', 'a' }; + char[] prefix = new char[] { 'c', 'a', 'a' }; + assertTrue(CharOperation.prefixEquals(prefix, name, false, 2)); + prefix = new char[] { 'c', 'a', 'a', 'a' }; + assertFalse(CharOperation.prefixEquals(prefix, name, false, 2)); + prefix = new char[] { 'c', 'a', 'A' }; + assertFalse(CharOperation.prefixEquals(prefix, name, true, 2)); + prefix = new char[] { 'b', 'c' }; + assertFalse(CharOperation.prefixEquals(prefix, name, false, 2)); + assertTrue(CharOperation.prefixEquals(prefix, name, false, 1)); +} +// test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=324189 +public void test011() { + char[] pattern = new char[] { 'a' }; + char[] name = "AnotherA".toCharArray(); + assertFalse("Should not match", CharOperation.match( + pattern, + 0, + 1, + name, + 0, + 8, + false)); +} +// test the javadoc examples +public void test012() { + assertTrue("Should match", CharOperation.match( + new char[] { '?', 'b', '*' }, + 1, + 3, + new char[] { 'a', 'b', 'c' , 'd' }, + 1, + 4, + true)); + assertFalse("Should not match", CharOperation.match( + new char[] { '?', 'b', '*' }, + 1, + 2, + new char[] { 'a', 'b', 'c' , 'd' }, + 1, + 4, + true)); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileComparatorTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileComparatorTest.java new file mode 100644 index 0000000000..730162f047 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileComparatorTest.java @@ -0,0 +1,474 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; +import java.io.*; + +import org.eclipse.jdt.core.compiler.batch.BatchCompiler; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; + +@SuppressWarnings({ "rawtypes" }) +public class ClassFileComparatorTest extends AbstractRegressionTest { + + public ClassFileComparatorTest(String name) { + super(name); + } + public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); + } + + public static Class testClass() { + return ClassFileComparatorTest.class; + } + + + private void compileAndDeploy(String source, String className) { + File directory = new File(SOURCE_DIRECTORY); + if (!directory.exists()) { + if (!directory.mkdirs()) { + System.out.println("Could not create " + SOURCE_DIRECTORY); + return; + } + } + String fileName = SOURCE_DIRECTORY + File.separator + className + ".java"; + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); + writer.write(source); + writer.flush(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + StringBuilder buffer = new StringBuilder(); + buffer + .append("\"") + .append(fileName) + .append("\" -d \"") + .append(EVAL_DIRECTORY) + .append("\" -nowarn -g -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append(SOURCE_DIRECTORY) + .append("\""); + BatchCompiler.compile(buffer.toString(), new PrintWriter(System.out), new PrintWriter(System.err), null/*progress*/); + } + + private boolean areStructurallyDifferent(String classFile1, String classFile2, boolean orderRequired, boolean excludeSynthetic) { + FileInputStream stream = null; + try { + ClassFileReader reader = ClassFileReader.read(EVAL_DIRECTORY + File.separator + classFile1 + ".class"); + int fileLength; + File file = new File(EVAL_DIRECTORY + File.separator + classFile2 + ".class"); + byte classFileBytes[] = new byte[fileLength = (int) file.length()]; + stream = new java.io.FileInputStream(file); + int bytesRead = 0; + int lastReadSize = 0; + while ((lastReadSize != -1) && (bytesRead != fileLength)) { + lastReadSize = stream.read(classFileBytes, bytesRead, fileLength - bytesRead); + bytesRead += lastReadSize; + } + return reader.hasStructuralChanges(classFileBytes, orderRequired, excludeSynthetic); + } catch(IOException e) { + return true; + } catch(ClassFormatException e) { + return true; + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + /* ignore */ + } + } + } + } + + public void test001() { + try { + String sourceA001 = + "public class A001 {\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + " public String toString() {\n" + + " return \"hello\";\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA001, "A001"); + String sourceA001_2 = + "public class A001_2 {\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + " public String toString() {\n" + + " return \"hello\";\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA001_2, "A001_2"); + assertTrue(!areStructurallyDifferent("A001", "A001_2", false, false)); + } finally { + removeTempClass("A001"); + } + } + + public void test002() { + try { + String sourceA002 = + "public class A002 {\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA002, "A002"); + String sourceA002_2 = + "public class A002_2 {\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + " public String toString() {\n" + + " return \"hello\";\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA002_2, "A002_2"); + assertTrue(areStructurallyDifferent("A002", "A002_2", false, false)); + } finally { + removeTempClass("A002"); + } + } + + public void test003() { + try { + String sourceA003 = + "public class A003 {\n" + + "public static final int II = 5;\n" + + "}"; + compileAndDeploy(sourceA003, "A003"); + String sourceA003_2 = + "public class A003_2 {\n" + + "public static final int II = 6;\n" + + "}"; + compileAndDeploy(sourceA003_2, "A003_2"); + assertTrue(areStructurallyDifferent("A003", "A003_2", false, false)); + } finally { + removeTempClass("A003"); + } + } + public void test004() { + try { + String sourceA004 = + "public class A004 {\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + " public String toString() {\n" + + " return \"hello\";\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA004, "A004"); + String sourceA004_2 = + "public class A004_2 {\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + " public String toString() {\n" + + " return \"hello\";\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA004_2, "A004_2"); + assertTrue(!areStructurallyDifferent("A004", "A004_2", true, true)); + } finally { + removeTempClass("A004"); + } + } + public void test005() { + try { + String sourceA005 = + "public class A005 {\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA005, "A005"); + String sourceA005_2 = + "public class A005_2 {\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + " public String toString() {\n" + + " return \"hello\";\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA005_2, "A005_2"); + assertTrue(areStructurallyDifferent("A005", "A005_2", true, true)); + } finally { + removeTempClass("A005"); + } + } + public void test006() { + try { + String sourceA006 = + "public class A006 {\n" + + "public static final int II = 5;\n" + + "}"; + compileAndDeploy(sourceA006, "A006"); + String sourceA006_2 = + "public class A006_2 {\n" + + "public static final int II = 6;\n" + + "}"; + compileAndDeploy(sourceA006_2, "A006_2"); + assertTrue(areStructurallyDifferent("A006", "A006_2", true, true)); + } finally { + removeTempClass("A006"); + } + } + + public void test007() { + try { + String sourceA007 = + "public class A007 {\n" + + "public static final int II = 6;\n" + + "public Runnable foo() {\n" + + "\treturn null;\n"+ + "}\n" + + "}"; + compileAndDeploy(sourceA007, "A007"); + String sourceA007_2 = + "public class A007_2 {\n" + + "public static final int II = 6;\n" + + "public Runnable foo() {\n" + + "\treturn new Runnable() {public void run() {}};\n"+ + "}\n" + + "}"; + compileAndDeploy(sourceA007_2, "A007_2"); + assertTrue(!areStructurallyDifferent("A007", "A007_2", true, true)); + } finally { + removeTempClass("A007"); + } + } + public void test008() { + try { + String sourceA008 = + "public class A008 {\n" + + "private int i = 6;\n" + + "public int foo() {\n" + + "\treturn i;\n"+ + "}\n" + + "}"; + compileAndDeploy(sourceA008, "A008"); + String sourceA008_2 = + "public class A008_2 {\n" + + "private int i = 6;\n" + + "public int foo() {\n" + + "\treturn 2;\n"+ + "}\n" + + "}"; + compileAndDeploy(sourceA008_2, "A008_2"); + assertTrue(!areStructurallyDifferent("A008", "A008_2", true, false)); + } finally { + removeTempClass("A008"); + } + } + + public void test009() { + try { + String sourceA009 = + "public class A009 {\n" + + "private int i = 6;\n" + + "public int foo() {\n" + + "\tclass A {\n" + + "\t\tint get() {\n" + + "\t\t\treturn i;\n" + + "\t\t}\n" + + "\t}\n" + + "\treturn new A().get();\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA009, "A009"); + String sourceA009_2 = + "public class A009_2 {\n" + + "private int i = 6;\n" + + "public int foo() {\n" + + "\treturn 2;\n"+ + "}\n" + + "}"; + compileAndDeploy(sourceA009_2, "A009_2"); + assertTrue(areStructurallyDifferent("A009", "A009_2", true, false)); + } finally { + removeTempClass("A009"); + } + } + public void test010() { + try { + String sourceA010 = + "public class A010 {\n" + + "private int i = 6;\n" + + "public int foo() {\n" + + "\tclass A {\n" + + "\t\tint get() {\n" + + "\t\t\treturn i;\n" + + "\t\t}\n" + + "\t}\n" + + "\treturn new A().get();\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA010, "A010"); + String sourceA010_2 = + "public class A010_2 {\n" + + "private int i = 6;\n" + + "public int foo() {\n" + + "\treturn 2;\n"+ + "}\n" + + "}"; + compileAndDeploy(sourceA010_2, "A010_2"); + assertTrue(!areStructurallyDifferent("A010", "A010_2", true, true)); + } finally { + removeTempClass("A010"); + } + } + + public void test011() { + try { + String sourceA011 = + "public class A011 {\n" + + "private int i = 6;\n" + + "public int foo() {\n" + + "\tclass A {\n" + + "\t\tint get() {\n" + + "\t\t\treturn i;\n" + + "\t\t}\n" + + "\t}\n" + + "\treturn new A().get();\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA011, "A011"); + String sourceA011_2 = + "public class A011_2 {\n" + + "private int i = 6;\n" + + "public int foo() {\n" + + "\treturn 2;\n"+ + "}\n" + + "}"; + compileAndDeploy(sourceA011_2, "A011_2"); + assertTrue(!areStructurallyDifferent("A011", "A011_2", false, true)); + } finally { + removeTempClass("A011"); + } + } + public void test012() { + try { + String sourceA012 = + "public class A012 {\n" + + "public Class foo() {\n" + + "\treturn null;\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA012, "A012"); + String sourceA012_2 = + "public class A012_2 {\n" + + "public Class foo() {\n" + + "\treturn A012_2.class;\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA012_2, "A012_2"); + assertTrue(areStructurallyDifferent("A012", "A012_2", false, false)); + } finally { + removeTempClass("A012"); + } + } + public void test013() { + try { + String sourceA013 = + "public class A013 {\n" + + "public Class foo() {\n" + + "\treturn null;\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA013, "A013"); + String sourceA013_2 = + "public class A013_2 {\n" + + "public Class foo() {\n" + + "\treturn A013_2.class;\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA013_2, "A013_2"); + assertTrue(!areStructurallyDifferent("A013", "A013_2", false, true)); + } finally { + removeTempClass("A013"); + } + } + public void test014() { + try { + String sourceA014 = + "public class A014 {\n" + + "public Class foo() {\n" + + "\treturn null;\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA014, "A014"); + String sourceA014_2 = + "public class A014_2 {\n" + + "public Class foo() {\n" + + "\treturn A014_2.class;\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA014_2, "A014_2"); + assertTrue(!areStructurallyDifferent("A014", "A014_2", true, true)); + } finally { + removeTempClass("A014"); + } + } + + public void test015() { + try { + String sourceA015 = + "public class A015 {\n" + + " public class B {\n" + + " }\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + " public String toString() {\n" + + " return \"hello\";\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA015, "A015"); + assertTrue(!areStructurallyDifferent("A015$B", "A015$B", false, false)); + } finally { + removeTempClass("A015"); + } + } + + public void test016() { + try { + String sourceA016 = + "public class A016 {\n" + + "public void boo() {\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA016, "A016"); + String sourceA016_2 = + "public class A016_2 {\n" + + "public void foo() {\n" + + "}\n" + + "}"; + compileAndDeploy(sourceA016_2, "A016_2"); + assertTrue(areStructurallyDifferent("A016", "A016_2", false, false)); + } finally { + removeTempClass("A016"); + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_17.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_17.java new file mode 100644 index 0000000000..f6d7746329 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_17.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2020, 2021 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; +import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; + +@SuppressWarnings({ "rawtypes" }) +public class ClassFileReaderTest_17 extends AbstractRegressionTest { + static { + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_17); + } + public static Class testClass() { + return ClassFileReaderTest_17.class; + } + + public ClassFileReaderTest_17(String name) { + super(name); + } + + // Needed to run tests individually from JUnit + @Override + protected void setUp() throws Exception { + super.setUp(); + this.complianceLevel = ClassFileConstants.JDK17; + } + + public void testBug564227_001() throws Exception { + String source = + "sealed class X permits Y, Z{\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "final class Y extends X{}\n" + + "final class Z extends X{}\n"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + char[][] permittedSubtypesNames = classFileReader.getPermittedSubtypeNames(); + + assertEquals(2, permittedSubtypesNames.length); + + char [][] expected = {"Y".toCharArray(), "Z".toCharArray()}; + assertTrue(CharOperation.equals(permittedSubtypesNames, expected)); + + } + public void testBug565782_001() throws Exception { + String source = + "sealed interface I {}\n"+ + "enum X implements I {\n"+ + " ONE {};\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + char[][] permittedSubtypesNames = classFileReader.getPermittedSubtypeNames(); + + assertEquals(1, permittedSubtypesNames.length); + + char [][] expected = {"X$1".toCharArray()}; + assertTrue(CharOperation.equals(permittedSubtypesNames, expected)); + + int modifiers = classFileReader.getModifiers(); + assertTrue("sealed modifier expected", (modifiers & ExtraCompilerModifiers.AccSealed) != 0); + } + public void testBug565782_002() throws Exception { + String source = + "sealed interface I {}\n"+ + "class X {\n"+ + " enum E implements I {\n"+ + " ONE {};\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X.E", "X$E", source); + char[][] permittedSubtypesNames = classFileReader.getPermittedSubtypeNames(); + + assertEquals(1, permittedSubtypesNames.length); + + char [][] expected = {"X$E$1".toCharArray()}; + assertTrue(CharOperation.equals(permittedSubtypesNames, expected)); + + int modifiers = classFileReader.getModifiers(); + assertTrue("sealed modifier expected", (modifiers & ExtraCompilerModifiers.AccSealed) != 0); + } + public void testBug545510_1() throws Exception { + String source = + "strictfp class X {\n"+ + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + + int modifiers = classFileReader.getModifiers(); + assertTrue("strictfp modifier not expected", (modifiers & ClassFileConstants.AccStrictfp) == 0); + } + public void testBug545510_2() throws Exception { + String source = + "class X {\n"+ + " strictfp void foo() {}\n"+ + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + IBinaryMethod[] methods = classFileReader.getMethods(); + IBinaryMethod method = methods[1]; + int modifiers = method.getModifiers(); + assertTrue("strictfp modifier not expected", (modifiers & ClassFileConstants.AccStrictfp) == 0); + } + public void testBug545510_3() throws Exception { + String source = + "strictfp class X {\n"+ + " void foo() {}\n"+ + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + IBinaryMethod[] methods = classFileReader.getMethods(); + IBinaryMethod method = methods[1]; + int modifiers = method.getModifiers(); + assertTrue("strictfp modifier not expected", (modifiers & ClassFileConstants.AccStrictfp) == 0); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_4.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_4.java new file mode 100644 index 0000000000..978347aca2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_4.java @@ -0,0 +1,2878 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; + +@SuppressWarnings({ "rawtypes" }) +public class ClassFileReaderTest_1_4 extends AbstractRegressionTest { + static { +// TESTS_NAMES = new String[] { "test127" }; +// TESTS_NUMBERS = new int[] { 78, 79 }; +// TESTS_RANGE = new int[] { 169, 180 }; + } + + public static Test suite() { + return buildUniqueComplianceTestSuite(testClass(), ClassFileConstants.JDK1_4); + } + public static Class testClass() { + return ClassFileReaderTest_1_4.class; + } + + public ClassFileReaderTest_1_4(String name) { + super(name); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=15051 + */ + public void test001() throws Exception { + String source = + "public class A001 {\n" + + " private int i = 6;\n" + + " public int foo() {\n" + + " class A {\n" + + " int get() {\n" + + " return i;\n" + + " }\n" + + " }\n" + + " return new A().get();\n" + + " }\n" + + "};"; + String expectedOutput = + " // Method descriptor #19 ()I\n" + + " // Stack: 3, Locals: 1\n" + + " public int foo();\n" + + " 0 new A001$1$A [20]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 invokespecial A001$1$A(A001) [22]\n" + + " 8 invokevirtual A001$1$A.get() : int [25]\n" + + " 11 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: A001\n"; + checkClassFile("A001", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=25188 + */ + public void test002() throws Exception { + String source = + "public class A002 {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(); /* \\u000d: CARRIAGE RETURN */\n" + + " System.out.println();\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 6, line: 4]\n" + + " [pc: 12, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: args index: 0 type: java.lang.String[]\n"; + checkClassFile("A002", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26098 + */ + public void test003() throws Exception { + String source = + "public class A003 {\n" + + "\n" + + " public int bar() {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " public void foo() {\n" + + " System.out.println(bar());\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int bar();\n" + + " 0 iconst_0\n" + + " 1 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 2] local: this index: 0 type: A003\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public void foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [17]\n" + + " 3 aload_0 [this]\n" + + " 4 invokevirtual A003.bar() : int [23]\n" + + " 7 invokevirtual java.io.PrintStream.println(int) : void [25]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 10, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: this index: 0 type: A003\n"; + checkClassFile("A003", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test004() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " && !b) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 bipush 6\n" + + " 4 istore_2 [i]\n" + + " 5 iload_2 [i]\n" + + " 6 bipush 6\n" + + " 8 if_icmpne 22\n" + + " 11 iload_1 [b]\n" + + " 12 ifne 22\n" + + " 15 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 18 iload_2 [i]\n" + + " 19 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 22 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 5, line: 5]\n" + + " [pc: 11, line: 6]\n" + + " [pc: 15, line: 7]\n" + + " [pc: 22, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 23] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 23] local: b index: 1 type: boolean\n" + + " [pc: 5, pc: 23] local: i index: 2 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test005() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " && true) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpne 16\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 12 iload_1 [i]\n" + + " 13 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 9, line: 6]\n" + + " [pc: 16, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 17] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test006() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " && false) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 4] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test007() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (true\n" + + " && !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iload_1 [b]\n" + + " 3 ifne 12\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 12, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 13] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test008() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (false\n" + + " && !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 3] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 3] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test009() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " || !b) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 bipush 6\n" + + " 4 istore_2 [i]\n" + + " 5 iload_2 [i]\n" + + " 6 bipush 6\n" + + " 8 if_icmpeq 15\n" + + " 11 iload_1 [b]\n" + + " 12 ifne 22\n" + + " 15 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 18 iload_2 [i]\n" + + " 19 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 22 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 5, line: 5]\n" + + " [pc: 11, line: 6]\n" + + " [pc: 15, line: 7]\n" + + " [pc: 22, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 23] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 23] local: b index: 1 type: boolean\n" + + " [pc: 5, pc: 23] local: i index: 2 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test010() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " || true) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 6 iload_1 [i]\n" + + " 7 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 6]\n" + + " [pc: 10, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 11] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test011() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " || false) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpne 16\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 12 iload_1 [i]\n" + + " 13 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 9, line: 6]\n" + + " [pc: 16, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 17] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test012() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (true\n" + + " || !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 5 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 6]\n" + + " [pc: 8, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 9] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 9] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test013() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (false\n" + + " || !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iload_1 [b]\n" + + " 3 ifne 12\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 12, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 13] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test014() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " == !b) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 bipush 6\n" + + " 4 istore_2 [i]\n" + + " 5 iload_2 [i]\n" + + " 6 bipush 6\n" + + " 8 if_icmpne 15\n" + + " 11 iconst_1\n" + + " 12 goto 16\n" + + " 15 iconst_0\n" + + " 16 iload_1 [b]\n" + + " 17 ifeq 24\n" + + " 20 iconst_0\n" + + " 21 goto 25\n" + + " 24 iconst_1\n" + + " 25 if_icmpne 35\n" + + " 28 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 31 iload_2 [i]\n" + + " 32 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 35 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 5, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " [pc: 28, line: 7]\n" + + " [pc: 35, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 36] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 36] local: b index: 1 type: boolean\n" + + " [pc: 5, pc: 36] local: i index: 2 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test015() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " == true) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpne 16\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 12 iload_1 [i]\n" + + " 13 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 9, line: 6]\n" + + " [pc: 16, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 17] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test016() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " == false) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpeq 16\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 12 iload_1 [i]\n" + + " 13 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 9, line: 6]\n" + + " [pc: 16, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 17] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test017() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (true\n" + + " == !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iload_1 [b]\n" + + " 3 ifne 12\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 12, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 13] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test018() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (false\n" + + " == !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iload_1 [b]\n" + + " 3 ifeq 12\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 12, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 13] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + * http: //bugs.eclipse.org/bugs/show_bug.cgi?id=26881 + */ + public void test019() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " int i = 6;\n" + + " if ((i == 5)\n" + + " ? b : !b) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 bipush 6\n" + + " 4 istore_2 [i]\n" + + " 5 iload_2 [i]\n" + + " 6 iconst_5\n" + + " 7 if_icmpne 17\n" + + " 10 iload_1 [b]\n" + + " 11 ifeq 28\n" + + " 14 goto 21\n" + + " 17 iload_1 [b]\n" + + " 18 ifne 28\n" + + " 21 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 24 iload_2 [i]\n" + + " 25 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 28 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 5, line: 5]\n" + + " [pc: 10, line: 6]\n" + + " [pc: 21, line: 7]\n" + + " [pc: 28, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 29] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 29] local: b index: 1 type: boolean\n" + + " [pc: 5, pc: 29] local: i index: 2 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test020() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (i\n" + + " >= 5) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 iconst_5\n" + + " 5 if_icmplt 15\n" + + " 8 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 11 iload_1 [i]\n" + + " 12 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 15 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 15, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 16] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 16] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test021() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (i\n" + + " >= 0) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 iflt 14\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 10 iload_1 [i]\n" + + " 11 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 14, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 15] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test022() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (0\n" + + " >= i) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 ifgt 14\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 10 iload_1 [i]\n" + + " 11 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 14, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 15] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test023() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (i\n" + + " > 0) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 ifle 14\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 10 iload_1 [i]\n" + + " 11 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 14, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 15] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test024() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (0\n" + + " > i) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 ifge 14\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 10 iload_1 [i]\n" + + " 11 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 14, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 15] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test025() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (i\n" + + " > 5) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 iconst_5\n" + + " 5 if_icmple 15\n" + + " 8 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 11 iload_1 [i]\n" + + " 12 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 15 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 15, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 16] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 16] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test026() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (i\n" + + " < 0) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 ifge 14\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 10 iload_1 [i]\n" + + " 11 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 14, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 15] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test027() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (0\n" + + " < i) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 ifle 14\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 10 iload_1 [i]\n" + + " 11 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 14, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 15] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test028() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (i\n" + + " < 5) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 iconst_5\n" + + " 5 if_icmpge 15\n" + + " 8 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 11 iload_1 [i]\n" + + " 12 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 15 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 15, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 16] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 16] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test029() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (i\n" + + " <= 0) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 ifgt 14\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 10 iload_1 [i]\n" + + " 11 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 14, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 15] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test030() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (0\n" + + " <= i) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 iflt 14\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 10 iload_1 [i]\n" + + " 11 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 14, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 15] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test031() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (i\n" + + " <= 5) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 iconst_5\n" + + " 5 if_icmpgt 15\n" + + " 8 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 11 iload_1 [i]\n" + + " 12 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 15 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 15, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 16] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 16] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test032() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if (i\n" + + " <= 5) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 iconst_5\n" + + " 5 if_icmpgt 15\n" + + " 8 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 11 iload_1 [i]\n" + + " 12 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 15 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 15, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 16] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 16] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test033() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " & !b) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 bipush 6\n" + + " 4 istore_2 [i]\n" + + " 5 iload_2 [i]\n" + + " 6 bipush 6\n" + + " 8 if_icmpne 15\n" + + " 11 iconst_1\n" + + " 12 goto 16\n" + + " 15 iconst_0\n" + + " 16 iload_1 [b]\n" + + " 17 ifeq 24\n" + + " 20 iconst_0\n" + + " 21 goto 25\n" + + " 24 iconst_1\n" + + " 25 iand\n" + + " 26 ifeq 36\n" + + " 29 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 32 iload_2 [i]\n" + + " 33 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 36 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 5, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " [pc: 29, line: 7]\n" + + " [pc: 36, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 37] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 37] local: b index: 1 type: boolean\n" + + " [pc: 5, pc: 37] local: i index: 2 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test034() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " & true) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpne 16\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 12 iload_1 [i]\n" + + " 13 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 9, line: 6]\n" + + " [pc: 16, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 17] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test035() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " & false) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 4] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test036() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (true\n" + + " & !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iload_1 [b]\n" + + " 3 ifne 12\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 12, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 13] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test037() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (false\n" + + " & !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 3] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 3] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test038() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " | !b) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 bipush 6\n" + + " 4 istore_2 [i]\n" + + " 5 iload_2 [i]\n" + + " 6 bipush 6\n" + + " 8 if_icmpne 15\n" + + " 11 iconst_1\n" + + " 12 goto 16\n" + + " 15 iconst_0\n" + + " 16 iload_1 [b]\n" + + " 17 ifeq 24\n" + + " 20 iconst_0\n" + + " 21 goto 25\n" + + " 24 iconst_1\n" + + " 25 ior\n" + + " 26 ifeq 36\n" + + " 29 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 32 iload_2 [i]\n" + + " 33 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 36 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 5, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " [pc: 29, line: 7]\n" + + " [pc: 36, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 37] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 37] local: b index: 1 type: boolean\n" + + " [pc: 5, pc: 37] local: i index: 2 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test039() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " | true) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 6 iload_1 [i]\n" + + " 7 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 6]\n" + + " [pc: 10, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 11] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test040() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " | false) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpne 16\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 12 iload_1 [i]\n" + + " 13 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 9, line: 6]\n" + + " [pc: 16, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 17] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test041() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (true\n" + + " | !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 5 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 6]\n" + + " [pc: 8, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 9] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 9] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test042() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (false\n" + + " | !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iload_1 [b]\n" + + " 3 ifne 12\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 12, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 13] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test043() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " ^ !b) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 bipush 6\n" + + " 4 istore_2 [i]\n" + + " 5 iload_2 [i]\n" + + " 6 bipush 6\n" + + " 8 if_icmpne 15\n" + + " 11 iconst_1\n" + + " 12 goto 16\n" + + " 15 iconst_0\n" + + " 16 iload_1 [b]\n" + + " 17 ifeq 24\n" + + " 20 iconst_0\n" + + " 21 goto 25\n" + + " 24 iconst_1\n" + + " 25 ixor\n" + + " 26 ifeq 36\n" + + " 29 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 32 iload_2 [i]\n" + + " 33 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 36 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 5, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " [pc: 29, line: 7]\n" + + " [pc: 36, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 37] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 37] local: b index: 1 type: boolean\n" + + " [pc: 5, pc: 37] local: i index: 2 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test044() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " ^ true) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpeq 16\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 12 iload_1 [i]\n" + + " 13 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 9, line: 6]\n" + + " [pc: 16, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 17] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test045() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " int i = 6;\n" + + " if ((i == 6) \n" + + " ^ false) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 6\n" + + " 2 istore_1 [i]\n" + + " 3 iload_1 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpne 16\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 12 iload_1 [i]\n" + + " 13 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 9, line: 6]\n" + + " [pc: 16, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 17] local: i index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test046() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (true\n" + + " ^ !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iload_1 [b]\n" + + " 3 ifeq 12\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 12, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 13] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26753 + */ + public void test047() throws Exception { + String source = + "public class A {\n" + + " public static void main(String[] args) {\n" + + " boolean b = false;\n" + + " if (false\n" + + " ^ !b) { \n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 iload_1 [b]\n" + + " 3 ifne 12\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 12, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 13] local: b index: 1 type: boolean\n"; + checkClassFile("A", source, expectedOutput); + } + + public void test048() throws Exception { + String source = + "public class A {\n" + + "\n" + + " static int foo(boolean bool) {\n" + + " int j;\n" + + " try {\n" + + " if (bool) return 1;\n" + + " j = 2;\n" + + " } finally {\n" + + " j = 3;\n" + + " }\n" + + " return j;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " foo(false);\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 (Z)I\n" + + " // Stack: 1, Locals: 4\n" + + " static int foo(boolean bool);\n" + + " 0 iload_0 [bool]\n" + + " 1 ifeq 9\n" + + " 4 jsr 20\n" + + " 7 iconst_1\n" + + " 8 ireturn\n" + + " 9 iconst_2\n" + + " 10 istore_1 [j]\n" + + " 11 goto 25\n" + + " 14 astore_3\n" + + " 15 jsr 20\n" + + " 18 aload_3\n" + + " 19 athrow\n" + + " 20 astore_2\n" + + " 21 iconst_3\n" + + " 22 istore_1 [j]\n" + + " 23 ret 2\n" + + " 25 jsr 20\n" + + " 28 iload_1 [j]\n" + + " 29 ireturn\n" + + " Exception Table:\n" + + " [pc: 0, pc: 7] -> 14 when : any\n" + + " [pc: 9, pc: 14] -> 14 when : any\n" + + " [pc: 25, pc: 28] -> 14 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 9, line: 7]\n" + + " [pc: 11, line: 8]\n" + + " [pc: 18, line: 10]\n" + + " [pc: 20, line: 8]\n" + + " [pc: 21, line: 9]\n" + + " [pc: 23, line: 10]\n" + + " [pc: 28, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 30] local: bool index: 0 type: boolean\n" + + " [pc: 11, pc: 14] local: j index: 1 type: int\n" + + " [pc: 23, pc: 30] local: j index: 1 type: int\n"; + checkClassFile("A", source, expectedOutput); + } + + public void test049() throws Exception { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + " static void foo() {\n" + + " int i = 5;\n" + + " if ((i == 6) && false) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " static void foo();\n" + + " 0 iconst_5\n" + + " 1 istore_0 [i]\n" + + " 2 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 2, line: 10]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 3] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test050() throws Exception { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + " static void foo() {\n" + + " int i = 5;\n" + + " if ((i == 6) && false) {}\n" + + " else { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void foo();\n" + + " 0 iconst_5\n" + + " 1 istore_0 [i]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 5 iload_0 [i]\n" + + " 6 invokevirtual java.io.PrintStream.println(int) : void [27]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 2, line: 9]\n" + + " [pc: 9, line: 11]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 10] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test051() throws Exception { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " bar();\n" + + " }\n" + + " static void bar() {\n" + + " int i = 6;\n" + + " if ((i == 6) || true) {\n" + + " } else {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " static void bar();\n" + + " 0 bipush 6\n" + + " 2 istore_0 [i]\n" + + " 3 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 3, line: 11]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 4] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test052() throws Exception { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " bar();\n" + + " }\n" + + " static void bar() {\n" + + " int i = 6;\n" + + " if ((i == 6) || true) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void bar();\n" + + " 0 bipush 6\n" + + " 2 istore_0 [i]\n" + + " 3 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 6 iload_0 [i]\n" + + " 7 invokevirtual java.io.PrintStream.println(int) : void [27]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 3, line: 8]\n" + + " [pc: 10, line: 10]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 11] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test053() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo2();\n" + + " }\n" + + " static void foo2() {\n" + + " int i = 5;\n" + + " if ((i == 6) && (boom() && false)) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void foo2();\n" + + " 0 iconst_5\n" + + " 1 istore_0 [i]\n" + + " 2 iload_0 [i]\n" + + " 3 bipush 6\n" + + " 5 if_icmpne 12\n" + + " 8 invokestatic X.boom() : boolean [26]\n" + + " 11 pop\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 2, line: 10]\n" + + " [pc: 12, line: 13]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 13] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test054() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo2();\n" + + " }\n" + + " static void foo2() {\n" + + " int i = 5;\n" + + " if ((i == 6) && (boom() && false)) {\n" + + " } else {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void foo2();\n" + + " 0 iconst_5\n" + + " 1 istore_0 [i]\n" + + " 2 iload_0 [i]\n" + + " 3 bipush 6\n" + + " 5 if_icmpne 12\n" + + " 8 invokestatic X.boom() : boolean [26]\n" + + " 11 pop\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 15 iload_0 [i]\n" + + " 16 invokevirtual java.io.PrintStream.println(int) : void [34]\n" + + " 19 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 2, line: 10]\n" + + " [pc: 12, line: 12]\n" + + " [pc: 19, line: 14]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 20] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test055() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " bar2();\n" + + " }\n" + + " static void bar2() {\n" + + " int i = 6;\n" + + " if ((i == 6) || (boom() || true)) {\n" + + " } else {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void bar2();\n" + + " 0 bipush 6\n" + + " 2 istore_0 [i]\n" + + " 3 iload_0 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpeq 13\n" + + " 9 invokestatic X.boom() : boolean [26]\n" + + " 12 pop\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 3, line: 10]\n" + + " [pc: 13, line: 14]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 14] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test056() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " bar2();\n" + + " }\n" + + " static void bar2() {\n" + + " int i = 6;\n" + + " if ((i == 6) || (boom() || true)) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void bar2();\n" + + " 0 bipush 6\n" + + " 2 istore_0 [i]\n" + + " 3 iload_0 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpeq 13\n" + + " 9 invokestatic X.boom() : boolean [26]\n" + + " 12 pop\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 16 iload_0 [i]\n" + + " 17 invokevirtual java.io.PrintStream.println(int) : void [34]\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 3, line: 10]\n" + + " [pc: 13, line: 11]\n" + + " [pc: 20, line: 13]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 21] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test057() throws Exception { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo3();\n" + + " }\n" + + " static void foo3() {\n" + + " int i = 5;\n" + + " if (false && (i == 6)) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " static void foo3();\n" + + " 0 iconst_5\n" + + " 1 istore_0 [i]\n" + + " 2 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 2, line: 10]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 3] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test058() throws Exception { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo3();\n" + + " }\n" + + " static void foo3() {\n" + + " int i = 5;\n" + + " if (false && (i == 6)) {\n" + + " } else {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void foo3();\n" + + " 0 iconst_5\n" + + " 1 istore_0 [i]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 5 iload_0 [i]\n" + + " 6 invokevirtual java.io.PrintStream.println(int) : void [27]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 2, line: 9]\n" + + " [pc: 9, line: 11]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 10] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test059() throws Exception { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " bar3();\n" + + " }\n" + + " static void bar3() {\n" + + " int i = 6;\n" + + " if (true || (i == 6)) {\n" + + " } else {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " static void bar3();\n" + + " 0 bipush 6\n" + + " 2 istore_0 [i]\n" + + " 3 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 3, line: 11]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 4] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test060() throws Exception { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " bar3();\n" + + " }\n" + + " static void bar3() {\n" + + " int i = 6;\n" + + " if (true || (i == 6)) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void bar3();\n" + + " 0 bipush 6\n" + + " 2 istore_0 [i]\n" + + " 3 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 6 iload_0 [i]\n" + + " 7 invokevirtual java.io.PrintStream.println(int) : void [27]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 3, line: 8]\n" + + " [pc: 10, line: 10]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 11] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test061() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo4();\n" + + " }\n" + + " static void foo4() {\n" + + " int i = 5;\n" + + " if ((false && boom()) && (i == 6)) { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " static void foo4();\n" + + " 0 iconst_5\n" + + " 1 istore_0 [i]\n" + + " 2 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 2, line: 13]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 3] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test062() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo4();\n" + + " }\n" + + " static void foo4() {\n" + + " int i = 5;\n" + + " if ((false && boom()) && (i == 6)) {\n" + + " } else { \n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void foo4();\n" + + " 0 iconst_5\n" + + " 1 istore_0 [i]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [26]\n" + + " 5 iload_0 [i]\n" + + " 6 invokevirtual java.io.PrintStream.println(int) : void [32]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 2, line: 12]\n" + + " [pc: 9, line: 14]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 10] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test063() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " bar4();\n" + + " }\n" + + " static void bar4() {\n" + + " int i = 6;\n" + + " if ((true || boom()) || (i == 6)) {\n" + + " } else {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " static void bar4();\n" + + " 0 bipush 6\n" + + " 2 istore_0 [i]\n" + + " 3 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 3, line: 14]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 4] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test064() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " bar4();\n" + + " }\n" + + " static void bar4() {\n" + + " int i = 6;\n" + + " if ((true || boom()) || (i == 6)) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void bar4();\n" + + " 0 bipush 6\n" + + " 2 istore_0 [i]\n" + + " 3 getstatic java.lang.System.out : java.io.PrintStream [26]\n" + + " 6 iload_0 [i]\n" + + " 7 invokevirtual java.io.PrintStream.println(int) : void [32]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 3, line: 11]\n" + + " [pc: 10, line: 13]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 11] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test065() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo5();\n" + + " }\n" + + " static void foo5() {\n" + + " int i = 5;\n" + + " if (((i == 6) && (boom() && false)) && false) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void foo5();\n" + + " 0 iconst_5\n" + + " 1 istore_0 [i]\n" + + " 2 iload_0 [i]\n" + + " 3 bipush 6\n" + + " 5 if_icmpne 12\n" + + " 8 invokestatic X.boom() : boolean [26]\n" + + " 11 pop\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 2, line: 10]\n" + + " [pc: 12, line: 13]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 13] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test066() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo5();\n" + + " }\n" + + " static void foo5() {\n" + + " int i = 5;\n" + + " if (((i == 6) && (boom() && false)) && false) {\n" + + " } else {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void foo5();\n" + + " 0 iconst_5\n" + + " 1 istore_0 [i]\n" + + " 2 iload_0 [i]\n" + + " 3 bipush 6\n" + + " 5 if_icmpne 12\n" + + " 8 invokestatic X.boom() : boolean [26]\n" + + " 11 pop\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 15 iload_0 [i]\n" + + " 16 invokevirtual java.io.PrintStream.println(int) : void [34]\n" + + " 19 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 2, line: 10]\n" + + " [pc: 12, line: 12]\n" + + " [pc: 19, line: 14]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 20] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test067() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " bar5();\n" + + " }\n" + + " static void bar5() {\n" + + " int i = 6;\n" + + " if (((i == 6) || (boom() || true)) && true) {\n" + + " } else {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void bar5();\n" + + " 0 bipush 6\n" + + " 2 istore_0 [i]\n" + + " 3 iload_0 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpeq 13\n" + + " 9 invokestatic X.boom() : boolean [26]\n" + + " 12 pop\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 3, line: 10]\n" + + " [pc: 13, line: 14]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 14] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + public void test068() throws Exception { + String source = + "public class X {\n" + + " static boolean boom() { \n" + + " throw new NullPointerException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " bar5();\n" + + " }\n" + + " static void bar5() {\n" + + " int i = 6;\n" + + " if (((i == 6) || (boom() || true)) && true) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static void bar5();\n" + + " 0 bipush 6\n" + + " 2 istore_0 [i]\n" + + " 3 iload_0 [i]\n" + + " 4 bipush 6\n" + + " 6 if_icmpeq 13\n" + + " 9 invokestatic X.boom() : boolean [26]\n" + + " 12 pop\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 16 iload_0 [i]\n" + + " 17 invokevirtual java.io.PrintStream.println(int) : void [34]\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 3, line: 10]\n" + + " [pc: 13, line: 11]\n" + + " [pc: 20, line: 13]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 21] local: i index: 0 type: int\n"; + checkClassFile("X", source, expectedOutput); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47886 + */ + public void test069() throws Exception { + String source = + "public interface I {\n" + + "}"; + String expectedOutput = + "// Compiled from I.java (version 1.2 : 46.0, no super bit)\n" + + "public abstract interface I {\n" + + " Constant pool:\n" + + " constant #1 class: #2 I\n" + + " constant #2 utf8: \"I\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"SourceFile\"\n" + + " constant #6 utf8: \"I.java\"\n" + + "}"; + checkClassFile("I", source, expectedOutput); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=111219 + public void test072() throws Exception { + String source = + "package p;\n" + + "public abstract class X {\n" + + " public static final double CONST = Double.POSITIVE_INFINITY;\n" + + " X(X x) {}\n" + + " int foo() { return 0; }\n" + + " double foo2() { return 0; }\n" + + " byte foo3() { return 0; }\n" + + " char foo4() { return 0; }\n" + + " float foo5() { return 0; }\n" + + " long foo6() { return 0; }\n" + + " short foo7() { return 0; }\n" + + " Object foo8() { return null; }\n" + + " boolean foo9() { return false; }\n" + + " void foo10() {}\n" + + " native void foo11();\n" + + " abstract String foo12();\n" + + "}"; + String expectedOutput = + "package p;\n" + + "public abstract class X {\n" + + " \n" + + " public static final double CONST = 1.0 / 0.0;\n" + + " \n" + + " X(p.X x) {\n" + + " }\n" + + " \n" + + " int foo() {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " double foo2() {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " byte foo3() {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " char foo4() {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " float foo5() {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " long foo6() {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " short foo7() {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " java.lang.Object foo8() {\n" + + " return null;\n" + + " }\n" + + " \n" + + " boolean foo9() {\n" + + " return false;\n" + + " }\n" + + " \n" + + " void foo10() {\n" + + " }\n" + + " \n" + + " native void foo11();\n" + + " \n" + + " abstract java.lang.String foo12();\n" + + "}"; + checkClassFile("p", "X", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=111219 + public void test073() throws Exception { + String source = + "public class X {\n" + + " public static final double CONST = Double.POSITIVE_INFINITY;\n" + + " X(X x) {}\n" + + "}"; + String expectedOutput = + "public class X {\n" + + " \n" + + " public static final double CONST = 1.0 / 0.0;\n" + + " \n" + + " X(X x) {\n" + + " }\n" + + "}"; + checkClassFile("", "X", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=111219 + public void test074() throws Exception { + String source = + "package p;\n" + + "public class X {\n" + + " public static final double CONST = Double.POSITIVE_INFINITY;\n" + + " X(X x) {}\n" + + "}"; + String expectedOutput = + "package p;\n" + + "public class X {\n" + + " \n" + + " public static final double CONST = 1.0 / 0.0;\n" + + " \n" + + " X(X x) {\n" + + " }\n" + + "}"; + checkClassFile("p", "X", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY | ClassFileBytesDisassembler.COMPACT); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=111219 + public void test075() throws Exception { + String source = + "package p;\n" + + "public class X {\n" + + " public static final String CONST = \"\";\n" + + " X(X x) {}\n" + + "}"; + String expectedOutput = + "package p;\n" + + "public class X {\n" + + " \n" + + " public static final String CONST = \"\";\n" + + " \n" + + " X(X x) {\n" + + " }\n" + + "}"; + checkClassFile("p", "X", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY | ClassFileBytesDisassembler.COMPACT); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=111219 + public void test076() throws Exception { + String source = + "public class X {\n" + + " void foo() {\n" + + " try {\n" + + " System.out.println(\"Hello\");\n" + + " } catch(Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = + " Exception Table:\n" + + " [pc: 0, pc: 8] -> 11 when : Exception\n"; + checkClassFile("", "X", source, expectedOutput, ClassFileBytesDisassembler.DETAILED | ClassFileBytesDisassembler.COMPACT); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=34373 + public void test077() throws Exception { + String source = + "package p;\n" + + "public class X {\n" + + " private static class A {}\n" + + "}"; + String expectedOutput = + "private static class p.X$A {\n"; + checkClassFile("p", "X", "X$A", source, expectedOutput, ClassFileBytesDisassembler.DETAILED | ClassFileBytesDisassembler.COMPACT, false); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=102473 + public void test078() throws Exception { + String source = + "public class X {\n" + + " X(int i, int j) {}\n" + + " void foo(String s, double d) {}\n" + + "}"; + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + IBinaryMethod[] methodInfos = classFileReader.getMethods(); + assertNotNull("No method infos", methodInfos); + int length = methodInfos.length; + assertTrue("At least one method", length > 0); + for (int i = 0; i < length; i++) { + char[][] argNames = methodInfos[i].getArgumentNames(); + assertNotNull("No names", argNames); + assertEquals("Wrong size", 2, argNames.length); + if (CharOperation.equals(methodInfos[i].getSelector(), "".toCharArray())) { + assertEquals("Wrong argument name", "i", new String(argNames[0])); + assertEquals("Wrong argument name", "j", new String(argNames[1])); + } else if (CharOperation.equals(methodInfos[i].getSelector(), "foo".toCharArray())) { + assertEquals("Wrong argument name", "s", new String(argNames[0])); + assertEquals("Wrong argument name", "d", new String(argNames[1])); + } + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=102473 + public void test079() throws Exception { + String source = + "public class X {\n" + + " X(int i, int j) {}\n" + + " void foo(String s, double d) throws Exception {\n" + + " try {\n" + + " System.out.println(s + d);\n" + + " } catch(Exception e) {\n" + + " e.printStackTrace();\n" + + " throw e;\n" + + " } finally {\n" + + " System.out.println(\"done\");\n" + + " }\n" + + " }\n" + + "}"; + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + IBinaryMethod[] methodInfos = classFileReader.getMethods(); + assertNotNull("No method infos", methodInfos); + int length = methodInfos.length; + assertTrue("At least one method", length > 0); + for (int i = 0; i < length; i++) { + char[][] argNames = methodInfos[i].getArgumentNames(); + assertNotNull("No names", argNames); + assertEquals("Wrong size", 2, argNames.length); + if (CharOperation.equals(methodInfos[i].getSelector(), "".toCharArray())) { + assertEquals("Wrong argument name", "i", new String(argNames[0])); + assertEquals("Wrong argument name", "j", new String(argNames[1])); + } else if (CharOperation.equals(methodInfos[i].getSelector(), "foo".toCharArray())) { + assertEquals("Wrong argument name", "s", new String(argNames[0])); + assertEquals("Wrong argument name", "d", new String(argNames[1])); + } + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=102473 + public void test080() throws Exception { + String source = + "public class X {\n" + + " X(int i, int j) {}\n" + + " void foo(String s, double d) throws Exception {\n" + + " try {\n" + + " int k = 0;\n" + + " System.out.println(s + d + k);\n" + + " } catch(Exception e) {\n" + + " e.printStackTrace();\n" + + " throw e;\n" + + " } finally {\n" + + " System.out.println(\"done\");\n" + + " }\n" + + " }\n" + + "}"; + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + IBinaryMethod[] methodInfos = classFileReader.getMethods(); + assertNotNull("No method infos", methodInfos); + int length = methodInfos.length; + assertTrue("At least one method", length > 0); + for (int i = 0; i < length; i++) { + char[][] argNames = methodInfos[i].getArgumentNames(); + assertNotNull("No names", argNames); + assertEquals("Wrong size", 2, argNames.length); + if (CharOperation.equals(methodInfos[i].getSelector(), "".toCharArray())) { + assertEquals("Wrong argument name", "i", new String(argNames[0])); + assertEquals("Wrong argument name", "j", new String(argNames[1])); + } else if (CharOperation.equals(methodInfos[i].getSelector(), "foo".toCharArray())) { + assertEquals("Wrong argument name", "s", new String(argNames[0])); + assertEquals("Wrong argument name", "d", new String(argNames[1])); + } + } + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_5.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_5.java new file mode 100644 index 0000000000..984d5ac295 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_5.java @@ -0,0 +1,622 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +@SuppressWarnings({ "rawtypes" }) +public class ClassFileReaderTest_1_5 extends AbstractRegressionTest { + static { +// TESTS_NAMES = new String[] { "test127" }; +// TESTS_NUMBERS = new int[] { 16 }; +// TESTS_RANGE = new int[] { 169, 180 }; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); + } + public static Class testClass() { + return ClassFileReaderTest_1_5.class; + } + + public ClassFileReaderTest_1_5(String name) { + super(name); + } + + /** + * @deprecated + */ + private void checkClassFileUsingInputStream(String directoryName, String className, String source, String expectedOutput, int mode) throws IOException { + compileAndDeploy(source, directoryName, className, false); + BufferedInputStream inputStream = null; + try { + File directory = new File(EVAL_DIRECTORY, directoryName); + if (!directory.exists()) { + assertTrue(".class file not generated properly in " + directory, false); + } + File f = new File(directory, className + ".class"); + inputStream = new BufferedInputStream(new FileInputStream(f)); + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(inputStream, IClassFileReader.ALL); + assertNotNull(classFileReader); + String result = ToolFactory.createDefaultClassFileDisassembler().disassemble(classFileReader, "\n", mode); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + // ignore + } + } + removeTempClass(className); + } + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=76440 + */ + public void test001() throws Exception { + String source = + "public class X {\n" + + " X(String s) {\n" + + " }\n" + + " public void foo(int i, long l, String[][]... args) {\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #18 (IJ[[[Ljava/lang/String;)V\n" + + " // Stack: 0, Locals: 5\n" + + " public void foo(int i, long l, java.lang.String[][]... args);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: i index: 1 type: int\n" + + " [pc: 0, pc: 1] local: l index: 2 type: long\n" + + " [pc: 0, pc: 1] local: args index: 4 type: java.lang.String[][][]\n" + + "}"; + checkClassFile("X", source, expectedOutput); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=76472 + */ + public void test002() throws Exception { + String source = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " long[] tab = new long[] {};\n" + + " System.out.println(tab.clone());\n" + + " System.out.println(tab.clone());\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 newarray long [11]\n" + + " 3 astore_1 [tab]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 7 aload_1 [tab]\n" + + " 8 invokevirtual long[].clone() : java.lang.Object [22]\n" + + " 11 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [28]\n" + + " 14 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 17 aload_1 [tab]\n" + + " 18 invokevirtual long[].clone() : java.lang.Object [22]\n" + + " 21 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [28]\n" + + " 24 return\n"; + checkClassFile("X", source, expectedOutput); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=111420 + public void test003() throws Exception { + String source = + "public class Y {\n" + + " U field;\n" + + " String field2;\n" + + " Y(T t) {}\n" + + " T foo(T t, String... s) {\n" + + " return t;\n" + + " }\n" + + "}"; + String expectedOutput = + "public class Y {\n" + + " \n" + + " U field;\n" + + " \n" + + " String field2;\n" + + " \n" + + " Y(T t) {\n" + + " }\n" + + " \n" + + " T foo(T t, String... s) {\n" + + " return null;\n" + + " }\n" + + "}"; + checkClassFile("", "Y", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY | ClassFileBytesDisassembler.COMPACT); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=111420 + public void test004() throws Exception { + String source = + "public class Y {\n" + + " U field;\n" + + " String field2;\n" + + " Y(T t) {}\n" + + " T foo(T t, String... s) {\n" + + " return t;\n" + + " }\n" + + "}"; + String expectedOutput = + "public class Y {\n" + + " \n" + + " U field;\n" + + " \n" + + " java.lang.String field2;\n" + + " \n" + + " Y(T t) {\n" + + " }\n" + + " \n" + + " T foo(T t, java.lang.String... s) {\n" + + " return null;\n" + + " }\n" + + "}"; + checkClassFile("", "Y", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=76440 + */ + public void test005() throws Exception { + String source = + "public class X {\n" + + " X(String s) {\n" + + " }\n" + + " public static void foo(int i, long l, String[][]... args) {\n" + + " }\n" + + "}"; + String expectedOutput = + " // Method descriptor #18 (IJ[[[Ljava/lang/String;)V\n" + + " // Stack: 0, Locals: 4\n" + + " public static void foo(int i, long l, java.lang.String[][]... args);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: i index: 0 type: int\n" + + " [pc: 0, pc: 1] local: l index: 1 type: long\n" + + " [pc: 0, pc: 1] local: args index: 3 type: java.lang.String[][][]\n" + + "}"; + checkClassFile("X", source, expectedOutput); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=111494 + */ + public void test006() throws Exception { + String source = + "public enum X { \n" + + " \n" + + " BLEU(10),\n" + + " BLANC(20),\n" + + " ROUGE(30);\n" + + " X(int i) {}\n" + + "}\n"; + String expectedOutput = + "public enum X {\n" + + " \n" + + " BLEU(0),\n" + + " \n" + + " BLANC(0),\n" + + " \n" + + " ROUGE(0),;\n" + + " \n" + + " private X(int i) {\n" + + " }\n" + + "}"; + checkClassFile("", "X", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=111494 + * TODO corner case that doesn't produce the right source + */ + public void test007() throws Exception { + String source = + "public enum X {\n" + + " BLEU(0) {\n" + + " public String colorName() {\n" + + " return \"BLEU\";\n" + + " }\n" + + " },\n" + + " BLANC(1) {\n" + + " public String colorName() {\n" + + " return \"BLANC\";\n" + + " }\n" + + " },\n" + + " ROUGE(2) {\n" + + " public String colorName() {\n" + + " return \"ROUGE\";\n" + + " }\n" + + " },;\n" + + " \n" + + " X(int i) {\n" + + " }\n" + + " abstract public String colorName();\n" + + "}"; + String expectedOutput = + "public enum X {\n" + + " \n" + + " BLEU(0),\n" + + " \n" + + " BLANC(0),\n" + + " \n" + + " ROUGE(0),;\n" + + " \n" + + " private X(int i) {\n" + + " }\n" + + " \n" + + " public abstract java.lang.String colorName();\n" + + "}"; + checkClassFile("", "X", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=111494 + * TODO corner case that doesn't produce the right source + */ + public void test008() throws Exception { + String source = + "interface I {\n" + + " String colorName();\n" + + "}\n" + + "public enum X implements I {\n" + + " BLEU(0) {\n" + + " public String colorName() {\n" + + " return \"BLEU\";\n" + + " }\n" + + " },\n" + + " BLANC(1) {\n" + + " public String colorName() {\n" + + " return \"BLANC\";\n" + + " }\n" + + " },\n" + + " ROUGE(2) {\n" + + " public String colorName() {\n" + + " return \"ROUGE\";\n" + + " }\n" + + " },;\n" + + " \n" + + " X(int i) {\n" + + " }\n" + + "}"; + String expectedOutput = + "public enum X implements I {\n" + + " \n" + + " BLEU(0),\n" + + " \n" + + " BLANC(0),\n" + + " \n" + + " ROUGE(0),;\n" + + " \n" + + " private X(int i) {\n" + + " }\n" + + "}"; + checkClassFile("", "X", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=111767 + */ + public void test009() throws Exception { + String source = + "@interface X {\n" + + " String firstName();\n" + + " String lastName() default \"Smith\";\n" + + "}\n"; + String expectedOutput = + "abstract @interface X {\n" + + " \n" + + " public abstract java.lang.String firstName();\n" + + " \n" + + " public abstract java.lang.String lastName() default \"Smith\";\n" + + "}"; + checkClassFile("", "X", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=111767 + * @deprecated Using deprecated API + */ + public void test010() throws Exception { + String source = + "@interface X {\n" + + " String firstName();\n" + + " String lastName() default \"Smith\";\n" + + "}\n"; + String expectedOutput = + "abstract @interface X {\n" + + " \n" + + " public abstract java.lang.String firstName();\n" + + " \n" + + " public abstract java.lang.String lastName() default \"Smith\";\n" + + "}"; + checkClassFileUsingInputStream("", "X", source, expectedOutput, ClassFileBytesDisassembler.WORKING_COPY); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=203577 + */ + public void test011() throws Exception { + String source = + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(value={})\n" + + "@Retention(value=RetentionPolicy.RUNTIME)\n" + + "public @interface X {}"; + String expectedOutput = + "public abstract @interface X extends java.lang.annotation.Annotation {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 class: #6 java/lang/annotation/Annotation\n" + + " constant #6 utf8: \"java/lang/annotation/Annotation\"\n" + + " constant #7 utf8: \"SourceFile\"\n" + + " constant #8 utf8: \"X.java\"\n" + + " constant #9 utf8: \"RuntimeVisibleAnnotations\"\n" + + " constant #10 utf8: \"Ljava/lang/annotation/Target;\"\n" + + " constant #11 utf8: \"value\"\n" + + " constant #12 utf8: \"Ljava/lang/annotation/Retention;\"\n" + + " constant #13 utf8: \"Ljava/lang/annotation/RetentionPolicy;\"\n" + + " constant #14 utf8: \"RUNTIME\"\n" + + "\n" + + " RuntimeVisibleAnnotations: \n" + + " #10 @java.lang.annotation.Target(\n" + + " #11 value=[\n" + + " ]\n" + + " )\n" + + " #12 @java.lang.annotation.Retention(\n" + + " #11 value=java.lang.annotation.RetentionPolicy.RUNTIME(enum type #13.#14)\n" + + " )\n" + + "}"; + checkClassFile("", "X", source, expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=203609 + */ + public void test012() throws Exception { + String source = + "@Deprecated\n" + + "package p;"; + String expectedOutput = + "abstract interface p.package-info {\n" + + "}"; + if (this.complianceLevel > ClassFileConstants.JDK1_5) { + expectedOutput = "abstract synthetic interface p.package-info {\n" + + "}"; + } + checkClassFile("p", "package-info", source, expectedOutput, ClassFileBytesDisassembler.DEFAULT); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=217907 + */ + public void test013() throws Exception { + String source = + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(value={})\n" + + "@Retention(value=RetentionPolicy.RUNTIME)\n" + + "public @interface X {}"; + String expectedOutput = + "public abstract @interface X extends Annotation {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 class: #6 java/lang/annotation/Annotation\n" + + " constant #6 utf8: \"java/lang/annotation/Annotation\"\n" + + " constant #7 utf8: \"SourceFile\"\n" + + " constant #8 utf8: \"X.java\"\n" + + " constant #9 utf8: \"RuntimeVisibleAnnotations\"\n" + + " constant #10 utf8: \"Ljava/lang/annotation/Target;\"\n" + + " constant #11 utf8: \"value\"\n" + + " constant #12 utf8: \"Ljava/lang/annotation/Retention;\"\n" + + " constant #13 utf8: \"Ljava/lang/annotation/RetentionPolicy;\"\n" + + " constant #14 utf8: \"RUNTIME\"\n" + + "\n" + + " RuntimeVisibleAnnotations: \n" + + " #10 @Target(\n" + + " #11 value=[\n" + + " ]\n" + + " )\n" + + " #12 @Retention(\n" + + " #11 value=RetentionPolicy.RUNTIME(enum type #13.#14)\n" + + " )\n" + + "}"; + checkClassFile("", "X", source, expectedOutput, ClassFileBytesDisassembler.SYSTEM | ClassFileBytesDisassembler.COMPACT); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=217907 + */ + public void test014() throws Exception { + String source = + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(value={})\n" + + "@Retention(value=RetentionPolicy.RUNTIME)\n" + + "public @interface X {}"; + String expectedOutput = + "@Target(value={})\n" + + "@Retention(value=RetentionPolicy.RUNTIME)\n" + + "public abstract @interface X extends Annotation {\n" + + "\n" + + "}"; + checkClassFile("", "X", source, expectedOutput, ClassFileBytesDisassembler.DETAILED | ClassFileBytesDisassembler.COMPACT); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=217910 + */ + public void test015() throws Exception { + String source = + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "public class X {\n" + + " public void foo(@Deprecated @Annot(2) int i) {}\n" + + "}\n" + + "@Retention(CLASS)\n" + + "@interface Annot {\n" + + " int value() default -1;\n" + + "}"; + String expectedOutput = + " public void foo(@Deprecated @Annot(value=(int) 2) int i);"; + checkClassFile("", "X", source, expectedOutput, ClassFileBytesDisassembler.DETAILED | ClassFileBytesDisassembler.COMPACT); + } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=286405 + */ + public void test016() throws Exception { + String source = + "public @interface MonAnnotation {\n" + + " String test1() default \"\\0\";\n" + + " char test2() default '\\0';\n" + + "}\n" + + ""; + String expectedOutput = + " public abstract char test2() default \'\\u0000\';"; + checkClassFile("", "MonAnnotation", source, expectedOutput, ClassFileBytesDisassembler.DETAILED | ClassFileBytesDisassembler.COMPACT); + } + + public void testBug504031() throws Exception { + String source = + "package test;\n" + + "@RunWith(JUnitPlatform.class)\n" + + "@SelectPackages(\"test.dynamic.TODO\")\n" + + "public class AllTests {\n" + + " @Test\n" + + " void test1() {\n" + + " }\n" + + "} \n" + + "\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" + + "@interface RunWith {\n" + + " Class value();\n" + + "}\n" + + "@interface SelectPackages {\n" + + "}\n" + + "class Runner {}\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" + + "@interface Test {}\n"; + + String expectedOutput = + "@RunWith(value=JUnitPlatform)\n" + + "public class test.AllTests {\n" + + " Constant pool:\n" + + " constant #1 class: #2 test/AllTests\n" + + " constant #2 utf8: \"test/AllTests\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 class: #9 java/lang/Error\n" + + " constant #9 utf8: \"java/lang/Error\"\n" + + " constant #10 string: #11 \"Unresolved compilation problems: \\n\\tJUnitPlatform cannot be resolved to a type\\n\\tClass cannot be resolved to a type\\n\\tThe attribute value is undefined for the annotation type SelectPackages\\n\"\n" + + " constant #11 utf8: \"Unresolved compilation problems: \\n\\tJUnitPlatform cannot be resolved to a type\\n\\tClass cannot be resolved to a type\\n\\tThe attribute value is undefined for the annotation type SelectPackages\\n\"\n" + + " constant #12 method_ref: #8.#13 java/lang/Error. (Ljava/lang/String;)V\n" + + " constant #13 name_and_type: #5.#14 (Ljava/lang/String;)V\n" + + " constant #14 utf8: \"(Ljava/lang/String;)V\"\n" + + " constant #15 utf8: \"LineNumberTable\"\n" + + " constant #16 utf8: \"LocalVariableTable\"\n" + + " constant #17 utf8: \"this\"\n" + + " constant #18 utf8: \"Ltest/AllTests;\"\n" + + " constant #19 utf8: \"test1\"\n" + + " constant #20 utf8: \"RuntimeVisibleAnnotations\"\n" + + " constant #21 utf8: \"Ltest/Test;\"\n" + + " constant #22 string: #23 \"Unresolved compilation problem: \\n\"\n" + + " constant #23 utf8: \"Unresolved compilation problem: \\n\"\n" + + " constant #24 utf8: \"SourceFile\"\n" + + " constant #25 utf8: \"AllTests.java\"\n" + + " constant #26 utf8: \"RuntimeInvisibleAnnotations\"\n" + // unused but tolerated + " constant #27 utf8: \"Ltest/SelectPackages;\"\n" + // unused but tolerated + " constant #28 utf8: \"value\"\n" + + " constant #29 utf8: \"Ltest/RunWith;\"\n" + + " constant #30 utf8: \"LJUnitPlatform;\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 3, Locals: 1\n" + + " public AllTests();\n" + + " 0 new Error [8]\n" + + " 3 dup\n" + + " 4 ldc cannot be resolved to a type\\n\\tThe attribute value is undefined for the annotation type SelectPackages\\n\"> [10]\n" + + " 6 invokespecial Error(String) [12]\n" + + " 9 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: AllTests\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 3, Locals: 1\n" + + " @Test\n" + + " void test1();\n" + + " 0 new Error [8]\n" + + " 3 dup\n" + + " 4 ldc [22]\n" + + " 6 invokespecial Error(String) [12]\n" + + " 9 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: AllTests\n" + + " RuntimeVisibleAnnotations: \n" + + " #21 @Test(\n" + + " )\n" + + "\n" + + " RuntimeVisibleAnnotations: \n" + + " #29 @RunWith(\n" + + " #28 value=JUnitPlatform (#30 class type)\n" + + " )\n" + + "}"; + int mode = ClassFileBytesDisassembler.DETAILED | ClassFileBytesDisassembler.COMPACT | ClassFileBytesDisassembler.SYSTEM; + checkClassFile("test", "AllTests", "AllTests", source, expectedOutput, mode, true/*suppress expected errors*/); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_8.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_8.java new file mode 100644 index 0000000000..695daeef76 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClassFileReaderTest_1_8.java @@ -0,0 +1,597 @@ +/******************************************************************************* + * Copyright (c) 2013, 2019 GoPivotal, Inc. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for + * Bug 407191 - [1.8] Binary access support for type annotations + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +import java.io.File; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.codegen.AnnotationTargetTypeConstants; +import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation; +import org.eclipse.jdt.internal.compiler.env.IBinaryElementValuePair; +import org.eclipse.jdt.internal.compiler.env.IBinaryField; +import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; +import org.eclipse.jdt.internal.compiler.env.IBinaryTypeAnnotation; + +@SuppressWarnings({ "rawtypes" }) +public class ClassFileReaderTest_1_8 extends AbstractRegressionTest { + static { + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + public static Class testClass() { + return ClassFileReaderTest_1_8.class; + } + + public ClassFileReaderTest_1_8(String name) { + super(name); + } + + // Needed to run tests individually from JUnit + @Override + protected void setUp() throws Exception { + super.setUp(); + this.complianceLevel = ClassFileConstants.JDK1_8; + } + + public void test001_classTypeParameter() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "public class X<@Foo T1,@Bar(iii=99) T2> {}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int iii() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + + IBinaryTypeAnnotation[] typeAnnotations = classFileReader.getTypeAnnotations(); + assertEquals(2,typeAnnotations.length); + + assertEquals("@LFoo; CLASS_TYPE_PARAMETER(type_parameter_index=0)", printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LBar;(iii=(int)99) CLASS_TYPE_PARAMETER(type_parameter_index=1)", printTypeAnnotation(typeAnnotations[1])); + } + + public void test001a_classTypeParameterDifferingRetentions() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "public class X<@Foo T1,@Bar(iii=99) T2> {}\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int iii() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + + IBinaryTypeAnnotation[] typeAnnotations = classFileReader.getTypeAnnotations(); + assertEquals(2,typeAnnotations.length); + + assertEquals("@LBar;(iii=(int)99) CLASS_TYPE_PARAMETER(type_parameter_index=1)", printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LFoo; CLASS_TYPE_PARAMETER(type_parameter_index=0)", printTypeAnnotation(typeAnnotations[1])); + } + + public void test002_methodTypeParameter() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "public class X {\n" + + " <@Foo T1, @Bar(3) T2> void foo(T1 t1,T2 t2) {}\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int value() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader cfr = getInternalClassFile("", "X", "X", source); + + IBinaryMethod method = getMethod(cfr,"foo"); + assertNotNull(method); + IBinaryTypeAnnotation[] typeAnnotations = method.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(2,typeAnnotations.length); + assertEquals("@LFoo; METHOD_TYPE_PARAMETER(type_parameter_index=0)",printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LBar;(value=(int)3) METHOD_TYPE_PARAMETER(type_parameter_index=1)",printTypeAnnotation(typeAnnotations[1])); + } + + public void test003_classExtends() throws Exception { + this.complianceLevel = ClassFileConstants.JDK1_8; + String source = + "import java.lang.annotation.*;\n" + + "public class X extends @Foo @Bar(iii=34) Object implements java.io.@Bar(iii=1) Serializable {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int iii() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + + IBinaryTypeAnnotation[] typeAnnotations = classFileReader.getTypeAnnotations(); + assertEquals(3,typeAnnotations.length); + assertEquals("@LFoo; CLASS_EXTENDS(type_index=-1)", printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LBar;(iii=(int)34) CLASS_EXTENDS(type_index=-1)", printTypeAnnotation(typeAnnotations[1])); + assertEquals("@LBar;(iii=(int)1) CLASS_EXTENDS(type_index=0)", printTypeAnnotation(typeAnnotations[2])); + } + + public void test004_classExtends() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "public class X extends Y<@Foo String,@Bar Integer> implements I<@Foo String> {\n" + + "}\n" + + "class Y {}\n" + + "interface I {}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int iii() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + + IBinaryTypeAnnotation[] typeAnnotations = classFileReader.getTypeAnnotations(); + assertEquals(3,typeAnnotations.length); + assertEquals("@LFoo; CLASS_EXTENDS(type_index=-1), location=[TYPE_ARGUMENT(0)]", printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LBar; CLASS_EXTENDS(type_index=-1), location=[TYPE_ARGUMENT(1)]", printTypeAnnotation(typeAnnotations[1])); + assertEquals("@LFoo; CLASS_EXTENDS(type_index=0), location=[TYPE_ARGUMENT(0)]", printTypeAnnotation(typeAnnotations[2])); + } + + public void test005_classTypeParameterBound() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "public class X & @Bar(3) Cloneable> {}\n" + + "class Y {}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int value() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = getInternalClassFile("", "X", "X", source); + + IBinaryTypeAnnotation[] typeAnnotations = classFileReader.getTypeAnnotations(); + assertEquals(4,typeAnnotations.length); + assertEquals("@LFoo; CLASS_TYPE_PARAMETER_BOUND(type_parameter_index=1, bound_index=0), location=[TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]", printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LBar;(value=(int)1) CLASS_TYPE_PARAMETER_BOUND(type_parameter_index=1, bound_index=0), location=[TYPE_ARGUMENT(0)]", printTypeAnnotation(typeAnnotations[1])); + assertEquals("@LBar;(value=(int)2) CLASS_TYPE_PARAMETER_BOUND(type_parameter_index=1, bound_index=0), location=[TYPE_ARGUMENT(0), ARRAY, ARRAY]", printTypeAnnotation(typeAnnotations[2])); + assertEquals("@LBar;(value=(int)3) CLASS_TYPE_PARAMETER_BOUND(type_parameter_index=1, bound_index=1)", printTypeAnnotation(typeAnnotations[3])); + } + + public void test006_methodTypeParameterBound() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "public class X{\n" + + " & @Bar(3) Cloneable> void foo(T t) {}\n" + + "}\n" + + "class Y {}\n" + + "class Z {}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int value() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader cfr = getInternalClassFile("", "X", "X", source); + + IBinaryMethod method = getMethod(cfr,"foo"); + assertNotNull(method); + IBinaryTypeAnnotation[] typeAnnotations = method.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(4,typeAnnotations.length); + assertEquals("@LFoo; METHOD_TYPE_PARAMETER_BOUND(type_parameter_index=0, bound_index=0), location=[TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]",printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LBar;(value=(int)1) METHOD_TYPE_PARAMETER_BOUND(type_parameter_index=0, bound_index=0), location=[TYPE_ARGUMENT(0)]", printTypeAnnotation(typeAnnotations[1])); + assertEquals("@LBar;(value=(int)2) METHOD_TYPE_PARAMETER_BOUND(type_parameter_index=0, bound_index=0), location=[TYPE_ARGUMENT(0), ARRAY, ARRAY]", printTypeAnnotation(typeAnnotations[2])); + assertEquals("@LBar;(value=(int)3) METHOD_TYPE_PARAMETER_BOUND(type_parameter_index=0, bound_index=1)", printTypeAnnotation(typeAnnotations[3])); + } + + public void test007_field() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "import java.util.Map;\n" + + "public class X{\n" + + " @Foo Map<@Bar(1) String, @Bar(2) String @Bar(3)[] @Bar(4)[] @Bar(5)[]> field3;\n" + + "}\n" + + "class Y {}\n" + + "class Z {}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int value() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader cfr = getInternalClassFile("", "X", "X", source); + + IBinaryField field = getField(cfr,"field3"); + assertNotNull(field); + IBinaryTypeAnnotation[] typeAnnotations = field.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(6,typeAnnotations.length); + assertEquals("@LFoo; FIELD",printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LBar;(value=(int)1) FIELD, location=[TYPE_ARGUMENT(0)]", printTypeAnnotation(typeAnnotations[1])); + assertEquals("@LBar;(value=(int)2) FIELD, location=[TYPE_ARGUMENT(1), ARRAY, ARRAY, ARRAY]", printTypeAnnotation(typeAnnotations[2])); + assertEquals("@LBar;(value=(int)3) FIELD, location=[TYPE_ARGUMENT(1)]", printTypeAnnotation(typeAnnotations[3])); + assertEquals("@LBar;(value=(int)4) FIELD, location=[TYPE_ARGUMENT(1), ARRAY]", printTypeAnnotation(typeAnnotations[4])); + assertEquals("@LBar;(value=(int)5) FIELD, location=[TYPE_ARGUMENT(1), ARRAY, ARRAY]", printTypeAnnotation(typeAnnotations[5])); + } + + public void test008_methodReturn() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "import java.util.Map;\n" + + "public class X{\n" + + " @Bar(3) @Foo int foo() {\n" + + " return 1;\n" + + " }\n" + + " @Bar(3) int @Foo [] foo2() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int value() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader cfr = getInternalClassFile("", "X", "X", source); + + IBinaryMethod method = getMethod(cfr,"foo"); + assertNotNull(method); + IBinaryTypeAnnotation[] typeAnnotations = method.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(2,typeAnnotations.length); + assertEquals("@LBar;(value=(int)3) METHOD_RETURN",printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LFoo; METHOD_RETURN", printTypeAnnotation(typeAnnotations[1])); + + method = getMethod(cfr,"foo2"); + assertNotNull(method); + typeAnnotations = method.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(2,typeAnnotations.length); + assertEquals("@LBar;(value=(int)3) METHOD_RETURN, location=[ARRAY]",printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LFoo; METHOD_RETURN", printTypeAnnotation(typeAnnotations[1])); + } + + public void test009_methodReceiver() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "import java.util.Map;\n" + + "public class X{\n" + + " void foo(@Bar(3) X this) {}\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int value() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader cfr = getInternalClassFile("", "X", "X", source); + + IBinaryMethod method = getMethod(cfr,"foo"); + assertNotNull(method); + IBinaryTypeAnnotation[] typeAnnotations = method.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(1,typeAnnotations.length); + assertEquals("@LBar;(value=(int)3) METHOD_RECEIVER", printTypeAnnotation(typeAnnotations[0])); + } + + public void test010_methodFormalParameter() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "import java.util.Map;\n" + + "public class X{\n" + + " void foo(@Bar(3) String s, @Foo int i) {}\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int value() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader cfr = getInternalClassFile("", "X", "X", source); + + IBinaryMethod method = getMethod(cfr,"foo"); + assertNotNull(method); + IBinaryTypeAnnotation[] typeAnnotations = method.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(2,typeAnnotations.length); + assertEquals("@LBar;(value=(int)3) METHOD_FORMAL_PARAMETER(method_formal_parameter_index=0)",printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LFoo; METHOD_FORMAL_PARAMETER(method_formal_parameter_index=1)",printTypeAnnotation(typeAnnotations[1])); + } + + public void test011_throws() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "import java.util.Map;\n" + + "public class X{\n" + + " void foo() throws @Foo Exception, @Bar(1) Throwable {}\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int value() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader cfr = getInternalClassFile("", "X", "X", source); + + IBinaryMethod method = getMethod(cfr,"foo"); + assertNotNull(method); + IBinaryTypeAnnotation[] typeAnnotations = method.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(2,typeAnnotations.length); + assertEquals("@LFoo; THROWS(throws_type_index=0)",printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LBar;(value=(int)1) THROWS(throws_type_index=1)",printTypeAnnotation(typeAnnotations[1])); + } + public void test012_annotationMethodReturn() throws Exception { + String source = + "import java.lang.annotation.*;\n" + + "import java.util.Map;\n" + + "public @interface X{\n" + + " @Bar(3) @Foo int foo();\n" + + " @Bar(3) int @Foo [] foo2();\n" + + " @Bar(7) @Foo String value() default \"aaa\";\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Foo {\n" + + "}\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Bar {\n" + + " int value() default -1;\n" + + "}"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader cfr = getInternalClassFile("", "X", "X", source); + + IBinaryMethod method = getMethod(cfr,"foo"); + assertNotNull(method); + IBinaryTypeAnnotation[] typeAnnotations = method.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(2,typeAnnotations.length); + assertEquals("@LBar;(value=(int)3) METHOD_RETURN",printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LFoo; METHOD_RETURN", printTypeAnnotation(typeAnnotations[1])); + + method = getMethod(cfr,"foo2"); + assertNotNull(method); + typeAnnotations = method.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(2,typeAnnotations.length); + assertEquals("@LBar;(value=(int)3) METHOD_RETURN, location=[ARRAY]",printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LFoo; METHOD_RETURN", printTypeAnnotation(typeAnnotations[1])); + + method = getMethod(cfr,"value"); + assertNotNull(method); + typeAnnotations = method.getTypeAnnotations(); + assertNotNull(typeAnnotations); + assertEquals(2,typeAnnotations.length); + assertEquals("@LBar;(value=(int)7) METHOD_RETURN",printTypeAnnotation(typeAnnotations[0])); + assertEquals("@LFoo; METHOD_RETURN", printTypeAnnotation(typeAnnotations[1])); + assertEquals(((org.eclipse.jdt.internal.compiler.impl.Constant)method.getDefaultValue()).stringValue(), "aaa"); + } + + public void testBug548596() { + /*- + * Test548596.jar contains classes for the following kotlin code (compiled with kotlin 1.3.21): + * package k; + * class A { + * class B { + * class C { + * // + * } + * } + * } + */ + String[] libs = getDefaultClassPaths(); + int len = libs.length; + System.arraycopy(libs, 0, libs = new String[len+1], 0, len); + libs[libs.length-1] = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test548596.jar"; + + runConformTest( + new String[] { + "j/Usage.java", + "package j;\n" + + "\n" + + "import k.A.B.C;\n" + + "\n" + + "public class Usage {\n" + + " C c;\n" + + "}" + }, + "", + libs, + false, + null + ); + } + + /** + * Produce a nicely formatted type annotation for testing. Exercises the API for type annotations. + * Output examples:
+ * @Foo(id=34) CLASS_EXTENDS, type_index=-1, location=[ARRAY, INNER_TYPE, TYPE_ARGUMENT(0)]
+ */ + private String printTypeAnnotation(IBinaryTypeAnnotation typeAnnotation) { + StringBuilder sb = new StringBuilder(); + // The annotation: + IBinaryAnnotation annotation = typeAnnotation.getAnnotation(); + sb.append('@').append(annotation.getTypeName()); + IBinaryElementValuePair[] pairs = annotation.getElementValuePairs(); + if (pairs.length != 0) { + sb.append('('); + for (int i = 0; i < pairs.length; i++) { + if (i > 0) { + sb.append(','); + } + sb.append(pairs[i].getName()).append('=').append(pairs[i].getValue()); + } + sb.append(')'); + } + sb.append(' '); + + // target type + int targetType = typeAnnotation.getTargetType(); + switch (targetType) { + case AnnotationTargetTypeConstants.CLASS_TYPE_PARAMETER: + sb.append("CLASS_TYPE_PARAMETER(type_parameter_index=").append(typeAnnotation.getTypeParameterIndex()).append(')'); + break; + case AnnotationTargetTypeConstants.METHOD_TYPE_PARAMETER: + sb.append("METHOD_TYPE_PARAMETER(type_parameter_index=").append(typeAnnotation.getTypeParameterIndex()).append(')'); + break; + case AnnotationTargetTypeConstants.CLASS_EXTENDS: + sb.append("CLASS_EXTENDS(type_index=").append((short)typeAnnotation.getSupertypeIndex()).append(')'); + break; + case AnnotationTargetTypeConstants.CLASS_TYPE_PARAMETER_BOUND: + sb.append("CLASS_TYPE_PARAMETER_BOUND(type_parameter_index="). + append(typeAnnotation.getTypeParameterIndex()). + append(", bound_index=").append(typeAnnotation.getBoundIndex()). + append(')'); + break; + case AnnotationTargetTypeConstants.METHOD_TYPE_PARAMETER_BOUND: + sb.append("METHOD_TYPE_PARAMETER_BOUND(type_parameter_index="). + append(typeAnnotation.getTypeParameterIndex()). + append(", bound_index=").append(typeAnnotation.getBoundIndex()). + append(')'); + break; + case AnnotationTargetTypeConstants.FIELD: + sb.append("FIELD"); + break; + case AnnotationTargetTypeConstants.METHOD_RETURN: + sb.append("METHOD_RETURN"); + break; + case AnnotationTargetTypeConstants.METHOD_RECEIVER: + sb.append("METHOD_RECEIVER"); + break; + case AnnotationTargetTypeConstants.METHOD_FORMAL_PARAMETER : + sb.append("METHOD_FORMAL_PARAMETER(method_formal_parameter_index="). + append(typeAnnotation.getMethodFormalParameterIndex()).append(')'); + break; + case AnnotationTargetTypeConstants.THROWS : + sb.append("THROWS(throws_type_index="). + append(typeAnnotation.getThrowsTypeIndex()).append(')'); + break; + default: throw new IllegalStateException("nyi "+targetType); + } + + // location + int[] typepath = typeAnnotation.getTypePath(); + + if (typepath != IBinaryTypeAnnotation.NO_TYPE_PATH) { + sb.append(", location=["); //$NON-NLS-1$ + for (int i = 0, max = typepath.length; i < max; i += 2) { + if (i > 0) { + sb.append(", "); //$NON-NLS-1$ + } + switch (typepath[i]) { + case 0: + sb.append("ARRAY"); //$NON-NLS-1$ + break; + case 1: + sb.append("INNER_TYPE"); //$NON-NLS-1$ + break; + case 2: + sb.append("WILDCARD"); //$NON-NLS-1$ + break; + case 3: + sb.append("TYPE_ARGUMENT(").append(typepath[i+1]).append(')'); //$NON-NLS-1$ + break; + } + } + sb.append(']'); + } + return sb.toString(); + } + + private IBinaryMethod getMethod(ClassFileReader cfr,String methodname) { + IBinaryMethod[] methods = cfr.getMethods(); + if (methods == null) { + return null; + } + char[] methodnameAsCharArray = methodname.toCharArray(); + for (int i = 0, max = methods.length; i < max; i++) { + if (CharOperation.equals(methods[i].getSelector(),methodnameAsCharArray)) { + return methods[i]; + } + } + return null; + } + + private IBinaryField getField(ClassFileReader cfr,String fieldname) { + IBinaryField[] fields = cfr.getFields(); + if (fields == null) { + return null; + } + char[] fieldnameAsCharArray = fieldname.toCharArray(); + for (int i = 0, max = fields.length; i < max; i++) { + if (CharOperation.equals(fields[i].getName(),fieldnameAsCharArray)) { + return fields[i]; + } + } + return null; + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClasspathJmodTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClasspathJmodTests.java new file mode 100644 index 0000000000..fff7b4bc35 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ClasspathJmodTests.java @@ -0,0 +1,267 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.core.tests.util.Util; + +import junit.framework.Test; + +public class ClasspathJmodTests extends ModuleCompilationTests { + + static { +// TESTS_NAMES = new String[] { "testPackageConflict4a" }; + // TESTS_NUMBERS = new int[] { 1 }; + // TESTS_RANGE = new int[] { 298, -1 }; + } + + public ClasspathJmodTests(String name) { + super(name); + } + @Override + public void setUp() throws Exception { + super.setUp(); + System.setProperty("modules.to.load", "java.base"); + } + + @Override + public void tearDown() throws Exception { + super.tearDown(); + System.setProperty("modules.to.load", ""); + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); + } + + public static Class testClass() { + return ClasspathJmodTests.class; + } + private String getJavaSqlJMod() { + String home = Util.getJREDirectory(); + return home + File.separator + "jmods" + File.separator + "java.sql.jmod" + File.pathSeparator; + } + @Override + public void test001() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" --module-path \"") + .append(getJavaSqlJMod()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + runConformModuleTest(files, + buffer, + "", + "", + false, + "p.X"); + } + @Override + public void test002() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" --module-path \"") + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 2)\n" + + " requires java.sql;\n" + + " ^^^^^^^^\n" + + "java.sql cannot be resolved to a module\n" + + "----------\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/X.java (at line 3)\n" + + " public static java.sql.Connection getConnection() {\n" + + " ^^^^^^^^\n" + + "java.sql cannot be resolved to a type\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "p.X"); + } + @Override + public void test003() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(getJavaSqlJMod()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 2)\n" + + " requires java.sql;\n" + + " ^^^^^^^^\n" + + "java.sql cannot be resolved to a module\n" + + "----------\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/X.java (at line 3)\n" + + " public static java.sql.Connection getConnection() {\n" + + " ^^^^^^^^\n" + + "java.sql cannot be resolved to a type\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "p.X"); + } + @Override + public void test004() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" --module-path \"") + .append(getJavaSqlJMod()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/X.java (at line 3)\n" + + " public static java.sql.Connection getConnection() {\n" + + " ^^^^^^^^\n" + + "java.sql cannot be resolved to a type\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "p.X"); + } + @Override + public void test005() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + " requires mod.two;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "import q.Y;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return Y.con;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " exports q;\n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " public static java.sql.Connection con = null;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" --module-path \"") + .append(getJavaSqlJMod()) + .append("\" ") + .append(" -warn:-exports") // Y.con unreliably refers to Connection (missing requires transitive) + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CollisionCase.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CollisionCase.java new file mode 100644 index 0000000000..df7a231a2e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CollisionCase.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2003, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class CollisionCase extends AbstractRegressionTest { + +public CollisionCase(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} +public static Class testClass() { + return CollisionCase.class; +} + +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "import foo.bar;\n" + + "public class X { \n" + + " foo afoo; \n" + + " bar abar; \n" + + " public static void main(String[] args) { \n" + + " System.out.print(\"SUCCESS\"); \n" + + " } \n" + + "} \n", + "foo.java", + "public class foo {}\n", + "foo/bar.java", + "package foo;\n" + + "public class bar {}\n", + }, + "SUCCESS"); +} + +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " foo afoo; \n" + + " foo.bar abar; \n" + + "} \n", + "foo.java", + "public class foo {}\n", + "foo/bar.java", + "package foo;\n" + + "public class bar {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " foo.bar abar; \n" + + " ^^^^^^^\n" + + "foo.bar cannot be resolved to a type\n" + + "----------\n"); +} +// http://bugs.eclipse.org/bugs/show_bug.cgi?id=84886 +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " class MyFoo {\n" + + " class Bar {}\n" + + " }\n" + + " static class MyFoo$Bar {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static class MyFoo$Bar {}\n" + + " ^^^^^^^^^\n" + + "Duplicate nested type MyFoo$Bar\n" + + "----------\n"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java new file mode 100644 index 0000000000..c83115a8f8 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java @@ -0,0 +1,2437 @@ +/******************************************************************************* + * Copyright (c) 2006, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Benjamin Muskalla - Contribution for bug 239066 + * Stephan Herrmann - Contributions for + * bug 236385: [compiler] Warn for potential programming problem if an object is created but not used + * bug 349326 - [1.7] new warning for missing try-with-resources + * bug 186342 - [compiler][null] Using annotations for null checking + * bug 365662 - [compiler][null] warn on contradictory and redundant null annotations + * bug 365859 - [compiler][null] distinguish warnings based on flow analysis vs. null annotations + * bug 374605 - Unreasonable warning for enum-based switch statements + * bug 382353 - [1.8][compiler] Implementation property modifiers should be accepted on default methods. + * bug 382347 - [1.8][compiler] Compiler accepts incorrect default method inheritance + * bug 388281 - [compiler][null] inheritance of null annotations as an option + * bug 381443 - [compiler][null] Allow parameter widening from @NonNull to unannotated + * bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types + * bug 331649 - [compiler][null] consider null annotations for fields + * bug 382789 - [compiler][null] warn when syntactically-nonnull expression is compared against null + * bug 402028 - [1.8][compiler] null analysis for reference expressions + * bug 401796 - [1.8][compiler] don't treat default methods as overriding an independent inherited abstract method + * bug 404649 - [1.8][compiler] detect illegal reference to indirect or redundant super + * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic + * Bug 392099 - [1.8][compiler][null] Apply null annotation on types for null analysis + * Bug 415043 - [1.8][null] Follow-up re null type annotations after bug 392099 + * Bug 392238 - [1.8][compiler][null] Detect semantically invalid null type annotations + * Bug 416307 - [1.8][compiler][null] subclass with type parameter substitution confuses null checking + * Bug 424637 - [1.8][compiler][null] AIOOB in ReferenceExpression.resolveType with a method reference to Files::walk + * Bug 418743 - [1.8][null] contradictory annotations on invocation of generic method not reported + * Bug 430150 - [1.8][null] stricter checking against type variables + * Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit type bound of binary type + * Bug 438467 - [compiler][null] Better error position for "The method _ cannot implement the corresponding method _ due to incompatible nullness constraints" + * Bug 446442 - [1.8] merge null annotations from super methods + * Bug 458361 - [1.8][null] reconciler throws NPE in ProblemReporter.illegalReturnRedefinition() + * Jesper S Moller - Contributions for + * bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression + * bug 382721 - [1.8][compiler] Effectively final variables needs special treatment + * bug 384567 - [1.5][compiler] Compiler accepts illegal modifiers on package declaration + * bug 412153 - [1.8][compiler] Check validity of annotations which may be repeatable + * bug 419209 - [1.8] Repeating container annotations should be rejected in the presence of annotation it contains + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type + *******************************************************************************/ +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; + +import junit.framework.Test; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.ICompilerRequestor; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.IrritantSet; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; + +/** + * This class is meant to gather test cases related to the invocation of the + * compiler, be it at an API or non API level. + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class CompilerInvocationTests extends AbstractRegressionTest { + + public CompilerInvocationTests(String name) { + super(name); + } + + // Static initializer to specify tests subset using TESTS_* static variables + // All specified tests which does not belong to the class are skipped... + // 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[] { "test011_problem_categories" }; +// TESTS_NUMBERS = new int[] { 1 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_RANGE = new int[] { 1, 2049 }; +// TESTS_RANGE = new int[] { 449, 451 }; +// TESTS_RANGE = new int[] { 900, 999 }; + } + + public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); + } + + public static Class testClass() { + return CompilerInvocationTests.class; + } + +// irritant vs warning token - check To/From symmetry + public void test001_irritant_warning_token() { + Map matcher = new HashMap(); + for (int group = 0; group < IrritantSet.GROUP_MAX; group++) { + for (int i = 0; i < 29; i++) { + int irritant = (group << IrritantSet.GROUP_SHIFT) + (1 << i); + String token = CompilerOptions.warningTokenFromIrritant(irritant); + if (token != null) { + matcher.put(token, token); + assertTrue(CompilerOptions.warningTokenToIrritants(token) != null); + } + } + } + // Add one for "preview", which doesn't have any irritant at the moment + matcher.put("preview", "preview"); + String[] allTokens = CompilerOptions.warningTokens; + int length = allTokens.length; + matcher.put("all", "all"); // all gets undetected in the From/To loop + assertEquals(allTokens.length, matcher.size()); + for (int i = 0; i < length; i++) { + Object object = matcher.get(allTokens[i]); + assertNotNull(object); + } + } + +// problem categories - check that none is left unspecified +// see also discussion in https://bugs.eclipse.org/bugs/show_bug.cgi?id=208383 + public void test002_problem_categories() { + try { + Class iProblemClass; + Field[] fields = (iProblemClass = IProblem.class).getFields(); + for (int i = 0, length = fields.length; i < length; i++) { + Field field = fields[i]; + if (field.getType() == Integer.TYPE) { + int problemId = field.getInt(iProblemClass), + maskedProblemId = problemId & IProblem.IgnoreCategoriesMask; + if (maskedProblemId != 0 && maskedProblemId != IProblem.IgnoreCategoriesMask + && ProblemReporter.getProblemCategory(ProblemSeverities.Error, + problemId) == CategorizedProblem.CAT_UNSPECIFIED) { + fail("unspecified category for problem " + field.getName()); + } + } + } + } catch (IllegalAccessException e) { + fail("could not access members"); + } + } + + static class TasksReader implements ICompilerRequestor { + CompilationResult result; + + public void acceptResult(CompilationResult compilationResult) { + this.result = compilationResult; + } + } + + static String taskTagsAsCutAndPaste(CategorizedProblem tasks[]) { + StringBuilder result = new StringBuilder(); + String arguments[]; + for (int i = 0; i < tasks.length - 1; i++) { + arguments = tasks[i].getArguments(); + System.out.print("\t\t\"["); + System.out.print(arguments[0]); + System.out.print(','); + System.out.print(arguments[1]); + System.out.print(','); + System.out.print(arguments[2]); + System.out.println("]\\n\" +"); + } + arguments = tasks[tasks.length - 1].getArguments(); + System.out.print("\t\t\"["); + System.out.print(arguments[0]); + System.out.print(','); + System.out.print(arguments[1]); + System.out.print(','); + System.out.print(arguments[2]); + System.out.println("]\\n\""); + return result.toString(); + } + + static String taskTagsAsStrings(CategorizedProblem tasks[]) { + StringBuilder result = new StringBuilder(); + String arguments[]; + for (int i = 0; i < tasks.length; i++) { + arguments = tasks[i].getArguments(); + result.append('['); + result.append(arguments[0]); + result.append(','); + result.append(arguments[1]); + result.append(','); + result.append(arguments[2]); + result.append(']'); + result.append("\n"); + } + return result.toString(); + } + + public void runTaskTagsOptionsTest(String[] testFiles, Map customOptions, String expectedTags) { + TasksReader reader = new TasksReader(); + Map options = JavaCore.getDefaultOptions(); + if (customOptions != null) { + options.putAll(customOptions); + } + this.runConformTest(testFiles, "", null /* no extra class libraries */, true /* flush output directory */, + null, /* no VM args */ + options, reader, true /* skip javac */); + String tags = taskTagsAsStrings(reader.result.tasks); + if (!tags.equals(expectedTags)) { + System.out.println(getClass().getName() + '#' + getName()); + System.out.println("Effective results:"); + System.out.println(tags); + System.out.println("Cut and paste:"); + taskTagsAsCutAndPaste(reader.result.tasks); + assertEquals(expectedTags, tags); + } + } + +// Basic test on task tags: watch default behavior + public void test003_task_tags_options() { + runTaskTagsOptionsTest( + new String[] { "X.java", + "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n" + + " }\n" + "}\n" }, + null, "[FIXME, message contents,HIGH]\n" + "[TODO, message contents,NORMAL]\n" + + "[XXX, message contents,NORMAL]\n"); + } + +// effect of cancelling priorities +// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed + public void _test004_task_tags_options() { + Map customOptions = new HashMap(); + customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, ""); + runTaskTagsOptionsTest( + new String[] { "X.java", + "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n" + + " }\n" + "}\n" }, + customOptions, "[FIXME, message contents,NORMAL]\n" + "[TODO, message contents,NORMAL]\n" + + "[XXX, message contents,NORMAL]\n"); + } + +// effect of cancelling priorities +// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed + public void _test005_task_tags_options() { + Map customOptions = new HashMap(); + customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, ",,"); + runTaskTagsOptionsTest( + new String[] { "X.java", + "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n" + + " }\n" + "}\n" }, + customOptions, "[FIXME,message contents,NORMAL]\n" + "[TODO,message contents,NORMAL]\n" + + "[XXX,message contents,NORMAL]\n"); + // would expect an exception of some sort + } + +// effect of changing priorities +// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed + public void _test006_task_tags_options() { + Map customOptions = new HashMap(); + customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "A,B,C,D,E"); + runTaskTagsOptionsTest( + new String[] { "X.java", + "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n" + + " }\n" + "}\n" }, + customOptions, "[FIXME,message contents,NORMAL]\n" + "[TODO,message contents,NORMAL]\n" + + "[XXX,message contents,NORMAL]\n"); + // would expect an exception of some sort + } + +// effect of changing priorities + public void test007_task_tags_options() { + Map customOptions = new HashMap(); + customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,NORMAL,NORMAL"); + runTaskTagsOptionsTest( + new String[] { "X.java", + "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n" + + " }\n" + "}\n" }, + customOptions, "[FIXME, message contents,NORMAL]\n" + "[TODO, message contents,NORMAL]\n" + + "[XXX, message contents,NORMAL]\n"); + } + +// effect of changing priorities +// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed + public void _test008_task_tags_options() { + Map customOptions = new HashMap(); + customOptions.put(JavaCore.COMPILER_TASK_PRIORITIES, "NORMAL,NORMAL"); // one less than the number of tags + runTaskTagsOptionsTest( + new String[] { "X.java", + "public class X {\n" + " void foo(X x) {\n" + " // FIXME TODO XXX message contents\n" + + " }\n" + "}\n" }, + customOptions, "[FIXME,message contents,NORMAL]\n" + "[TODO,message contents,NORMAL]\n" + + "[XXX,message contents,NORMAL]\n"); + } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=206423 +// that bug showed that we had no coverage in the area of missing message +// templates, which can occur downstream in the localization process (assuming +// that we always release the English version right) + public void test009_missing_message_templates() { + assertEquals("Unable to retrieve the error message for problem id: 2097151. Check compiler resources.", + new DefaultProblemFactory().getLocalizedMessage(Integer.MAX_VALUE, new String[] {})); + } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=206423 + public void test010_missing_elaboration_templates() { + assertEquals( + "Unable to retrieve the error message elaboration for elaboration id: 1073741823. Check compiler resources.", + new DefaultProblemFactory().getLocalizedMessage(0, Integer.MAX_VALUE / 2, new String[] { "Zork" })); + } + +// problem categories - check that categories match expected ones +// see also discussion in https://bugs.eclipse.org/bugs/show_bug.cgi?id=208383 +public void test011_problem_categories() { + try { + Class iProblemClass; + class ProblemAttributes { + boolean deprecated; + int category; + ProblemAttributes(int category) { + this.category = category; + } + ProblemAttributes(boolean deprecated) { + this.deprecated = deprecated; + } + } + ProblemAttributes DEPRECATED = new ProblemAttributes(true); + Map expectedProblemAttributes = new HashMap(); + expectedProblemAttributes.put("AbstractMethodCannotBeOverridden", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AbstractMethodInAbstractClass", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AbstractMethodInEnum", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AbstractMethodMustBeImplemented", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AbstractMethodMustBeImplementedOverConcreteMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AbstractMethodsInConcreteClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("AbstractServiceImplementation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("AmbiguousConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AmbiguousConstructorInDefaultConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AmbiguousConstructorInImplicitConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AmbiguousField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AmbiguousMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AmbiguousType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("AnnotatedTypeArgumentToUnannotated", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("AnnotatedTypeArgumentToUnannotatedSuperHint", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("AnnotationCannotOverrideMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("AnnotationCircularity", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("AnnotationCircularitySelfReference", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("AnnotationFieldNeedConstantInitialization", DEPRECATED); + expectedProblemAttributes.put("AnnotationMembersCannotHaveParameters", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("AnnotationMembersCannotHaveTypeParameters", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("AnnotationTypeDeclarationCannotHaveConstructor", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("AnnotationTypeDeclarationCannotHaveSuperclass", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("AnnotationTypeDeclarationCannotHaveSuperinterfaces", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("AnnotationTypeUsedAsSuperInterface", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("AnnotationValueMustBeAnEnumConstant", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("AnnotationValueMustBeAnnotation", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("AnnotationValueMustBeArrayInitializer", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("AnnotationValueMustBeClassLiteral", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("AnnotationValueMustBeConstant", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("AnonymousClassCannotExtendFinalClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ApplicableMethodOverriddenByInapplicable", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("ArgumentHidingField", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("ArgumentHidingLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("ArgumentIsNeverUsed", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("ArgumentTypeAmbiguous", DEPRECATED); + expectedProblemAttributes.put("ArgumentTypeCannotBeVoid", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("ArgumentTypeCannotBeVoidArray", DEPRECATED); + expectedProblemAttributes.put("ArgumentTypeInheritedNameHidesEnclosingName", DEPRECATED); + expectedProblemAttributes.put("ArgumentTypeInternalNameProvided", DEPRECATED); + expectedProblemAttributes.put("ArgumentTypeNotFound", DEPRECATED); + expectedProblemAttributes.put("ArgumentTypeNotVisible", DEPRECATED); + expectedProblemAttributes.put("ArrayConstantsOnlyInArrayInitializers", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ArrayReferencePotentialNullReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + 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("AutoManagedVariableResourceNotBelow9", 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)); + expectedProblemAttributes.put("BoundHasConflictingArguments", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("BoundMustBeAnInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("BoxingConversion", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("BytecodeExceeds64KLimit", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("BytecodeExceeds64KLimitForClinit", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("BytecodeExceeds64KLimitForConstructor", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("BytecodeExceeds64KLimitForSwitchTable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("CannotAllocateVoidArray", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("CannotDeclareEnumSpecialMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("CannotDefineAnnotationInLocalType", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("CannotDefineDimensionExpressionsWithInit", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("CannotDefineEnumInLocalType", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("CannotDefineInterfaceInLocalType", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("CannotDefineStaticInitializerInLocalType", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("CannotExtendEnum", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("CannotHideAnInstanceMethodWithAStaticMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("CannotImplementIncompatibleNullness", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("CannotImportPackage", new ProblemAttributes(CategorizedProblem.CAT_IMPORT)); + expectedProblemAttributes.put("CannotInferElidedTypes", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("CannotInferInvocationType", 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)); + expectedProblemAttributes.put("CodeSnippetMissingClass", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("CodeSnippetMissingMethod", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("ConstNonNullFieldComparisonYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ContainerAnnotationTypeHasNonDefaultMembers", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ContainerAnnotationTypeHasShorterRetention", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ContainerAnnotationTypeHasWrongValueType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ContainerAnnotationTypeMustHaveValue", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ContradictoryNullAnnotations", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ContradictoryNullAnnotationsOnBound", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ContradictoryNullAnnotationsInferred", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ContradictoryNullAnnotationsInferredFunctionType", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ConflictingImport", new ProblemAttributes(CategorizedProblem.CAT_IMPORT)); + expectedProblemAttributes.put("ConflictingNullAnnotations", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ConstructedArrayIncompatible", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("ConstructionTypeMismatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ConflictingInheritedNullAnnotations", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ConstructorReferenceNotBelow18", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ConstructorVarargsArgumentNeedCast", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("CyclicModuleDependency", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("CorruptedSignature", new ProblemAttributes(CategorizedProblem.CAT_BUILDPATH)); + expectedProblemAttributes.put("DanglingReference", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("DeadCode", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("DefaultMethodNotBelow18", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("DefaultMethodOverridesObjectMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("DereferencingNullableExpression", 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("DisallowedTargetForContainerAnnotationType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("DisallowedTargetForAnnotation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("DisallowedExplicitThisParameter", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("DiscouragedReference", new ProblemAttributes(CategorizedProblem.CAT_RESTRICTION)); + expectedProblemAttributes.put("DuplicateAnnotation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("DuplicateAnnotationNotMarkedRepeatable", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("DuplicateAnnotationMember", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("DuplicateBlankFinalFieldInitialization", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("DuplicateBounds", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("DuplicateBoundInIntersectionCast", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("DuplicateCase", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("DuplicateDefaultCase", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("DuplicateExports", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + 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("DuplicateInheritedDefaultMethods", 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)); + expectedProblemAttributes.put("DuplicateModifierForArgument", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("DuplicateModifierForField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("DuplicateModifierForMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("DuplicateModifierForType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("DuplicateModifierForVariable", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("DuplicateModuleRef", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("DuplicateNestedType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("DuplicateOpens", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("DuplicateParameterizedMethods", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("DuplicateRequires", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("DuplicateResource", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("DuplicateServices", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("DuplicateSuperInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("DuplicateTargetInTargetAnnotation", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("DuplicateTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("DuplicateTypes", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("DuplicateUses", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + 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)); + expectedProblemAttributes.put("EnumAbstractMethodMustBeImplemented", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("EnumConstantCannotDefineAbstractMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("EnumConstantMustImplementAbstractMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("EnumConstantsCannotBeSurroundedByParenthesis", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("EnumStaticFieldInInInitializerContext", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("EnumSwitchCannotTargetField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("ExceptionParameterIsNeverUsed", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("ExceptionTypeAmbiguous", DEPRECATED); + expectedProblemAttributes.put("ExceptionTypeInheritedNameHidesEnclosingName", DEPRECATED); + expectedProblemAttributes.put("ExceptionTypeInternalNameProvided", DEPRECATED); + expectedProblemAttributes.put("ExceptionTypeNotFound", DEPRECATED); + expectedProblemAttributes.put("ExceptionTypeNotVisible", DEPRECATED); + expectedProblemAttributes.put("ExplicitThisParameterNotInLambda", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ExplicitThisParameterNotBelow18", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ExplicitlyClosedAutoCloseable", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("ExportingForeignPackage", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("ExportedPackageDoesNotExistOrIsEmpty", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("ExpressionShouldBeAVariable", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ExternalProblemFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("ExternalProblemNotFixable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("ExplicitAnnotationTargetRequired", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("FallthroughCase", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("FieldComparisonYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("FieldHidingField", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("FieldHidingLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("FieldMissingDeprecatedAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("FieldMustBeFinal", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("FieldTypeAmbiguous", DEPRECATED); + expectedProblemAttributes.put("FieldTypeInheritedNameHidesEnclosingName", DEPRECATED); + expectedProblemAttributes.put("FieldTypeInternalNameProvided", DEPRECATED); + expectedProblemAttributes.put("FieldTypeNotFound", DEPRECATED); + expectedProblemAttributes.put("FieldTypeNotVisible", DEPRECATED); + expectedProblemAttributes.put("FinalBoundForTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("FinalFieldAssignment", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + 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("GenericInferenceError", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); // TODO should be removed via https://bugs.eclipse.org/404675 + expectedProblemAttributes.put("GenericMethodTypeArgumentMismatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("GenericTypeCannotExtendThrowable", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("HidingEnclosingType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("HierarchyCircularity", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("HierarchyCircularitySelfReference", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("HierarchyHasProblems", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalAbstractModifierCombinationForMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalStrictfpForAbstractInterfaceMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalAccessFromTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalAnnotationForBaseType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalCast", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalClassLiteralForTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalDeclarationOfThisParameter", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("IllegalDefaultModifierSpecification", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalDefinitionToNonNullParameter", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("IllegalDimension", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("IllegalEnclosingInstanceSpecification", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + 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("IllegalBasetypeInIntersectionCast", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierCombinationFinalAbstractForClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierCombinationFinalVolatileForField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierCombinationForInterfaceMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierCombinationForPrivateInterfaceMethod9", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForAnnotationField", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("IllegalModifierForAnnotationMemberType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForAnnotationMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForAnnotationType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForArgument", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("StrictfpNotRequired", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("IllegalModifierForEnum", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForEnumConstant", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForEnumConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForInterfaceField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForInterfaceMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForInterfaceMethod18", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForLocalClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForLocalEnum", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForMemberClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForMemberEnum", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForMemberInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForModule", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("IllegalModifierForInterfaceMethod9", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifierForVariable", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalModifiersForElidedType", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("IllegalModifiers", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("IllegalParameterNullityRedefinition", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("IllegalPrimitiveOrArrayTypeForEnclosingInstance", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalQualifiedEnumConstantLabel", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalQualifiedParameterizedTypeAllocation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalQualifierForExplicitThis", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("IllegalQualifierForExplicitThis2", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("IllegalRedefinitionOfTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("IllegalReturnNullityRedefinition", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("IllegalReturnNullityRedefinitionFreeTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("IllegalRedefinitionToNonNullParameter", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("IllegalStaticModifierForMemberType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalTypeAnnotationsInStaticMemberAccess", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("IllegalTypeArgumentsInRawConstructorReference", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalTypeForExplicitThis", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + 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("IllegalUsageOfTypeAnnotations", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("IllegalVararg", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalVarargInLambda", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForMemberType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IllegalVisibilityModifierForInterfaceMemberType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ImplicitObjectBoundNoNullDefault", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("ImportAmbiguous", DEPRECATED); + expectedProblemAttributes.put("ImportInheritedNameHidesEnclosingName", DEPRECATED); + expectedProblemAttributes.put("ImportInternalNameProvided", DEPRECATED); + expectedProblemAttributes.put("ImportNotFound", new ProblemAttributes(CategorizedProblem.CAT_IMPORT)); + expectedProblemAttributes.put("ImportNotVisible", DEPRECATED); + expectedProblemAttributes.put("IncompatibleExceptionInInheritedMethodThrowsClause", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IncompatibleExceptionInThrowsClause", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("IncompatibleLambdaParameterType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IncompatibleMethodReference", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IncompatibleReturnType", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("IncompatibleReturnTypeForNonInheritedInterfaceMethod", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("IncompatibleTypesInConditionalOperator", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IncompatibleTypesInEqualityOperator", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IncompatibleTypesInForeach", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + + expectedProblemAttributes.put("IncorrectArityForParameterizedConstructor", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IncorrectArityForParameterizedMethod", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + 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)); + expectedProblemAttributes.put("InheritedDefaultMethodConflictsWithOtherInherited", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("InheritedFieldHidesEnclosingName", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("InheritedIncompatibleReturnType", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("InheritedMethodHidesEnclosingName", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("InheritedMethodReducesVisibility", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("InheritedParameterLackingNonNullAnnotation", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("InheritedTypeHidesEnclosingName", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("InitializerMustCompleteNormally", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("InstanceFieldDuringConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("InstanceMethodDuringConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("InterfaceAmbiguous", DEPRECATED); + expectedProblemAttributes.put("InterfaceCannotHaveConstructors", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InterfaceCannotHaveInitializers", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("InterfaceInheritedNameHidesEnclosingName", DEPRECATED); + expectedProblemAttributes.put("InterfaceInternalNameProvided", DEPRECATED); + expectedProblemAttributes.put("InterfaceNotFound", DEPRECATED); + expectedProblemAttributes.put("InterfaceNotFunctionalInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("InterfaceNotVisible", DEPRECATED); + expectedProblemAttributes.put("InterfaceStaticMethodInvocationNotBelow18", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InterfaceSuperInvocationNotBelow18", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InternalTypeNameProvided", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IntersectionCastNotBelow18", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("InvalidAnnotationMemberType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("InvalidArrayConstructorReference", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + 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)); + expectedProblemAttributes.put("InvalidClassInstantiation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("InvalidContinue", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("InvalidDigit", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidEncoding", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("InvalidEscape", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidExplicitConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidExpressionAsStatement", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidFileNameForPackageAnnotations", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidFloat", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidHexa", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidHighSurrogate", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidInput", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidLowSurrogate", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidLocationForModifiers", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidNullToSynchronized", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("InvalidOctal", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidOpensStatement", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("InvalidOperator", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("InvalidParameterizedExceptionType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("InvalidParenthesizedExpression", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidServiceIntfType", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("InvalidServiceImplType", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("InvalidTypeExpression", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("InvalidTypeArguments", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("InvalidTypeForCollection", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("InvalidTypeForCollectionTarget14", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("InvalidTypeForStaticImport", new ProblemAttributes(CategorizedProblem.CAT_IMPORT)); + expectedProblemAttributes.put("InvalidTypeToSynchronized", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + 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)); + expectedProblemAttributes.put("InvalidUsageOfForeachStatements", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidUsageOfStaticImports", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidUsageOfTypeAnnotations", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidUsageOfTypeArguments", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidUsageOfTypeParameters", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidUsageOfTypeParametersForAnnotationDeclaration", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidUsageOfTypeParametersForEnumDeclaration", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidUsageOfVarargs", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidUsageOfWildcard", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("InvalidVoidExpression", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("IsClassPathCorrect", new ProblemAttributes(CategorizedProblem.CAT_BUILDPATH)); + expectedProblemAttributes.put("JavadocAmbiguousConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocAmbiguousField", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocAmbiguousMethod", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocAmbiguousMethodReference", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocAmbiguousType", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateParamName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateProvidesTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateReturnTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateThrowsClassName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateUsesTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocEmptyReturnTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocGenericConstructorTypeArgumentMismatch", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocGenericMethodTypeArgumentMismatch", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocHiddenReference", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocIncorrectArityForParameterizedConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocIncorrectArityForParameterizedMethod", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInheritedFieldHidesEnclosingName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInheritedMethodHidesEnclosingName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInheritedNameHidesEnclosingTypeName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInternalTypeNameProvided", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidMemberTypeQualification", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidModuleQualification", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidParamName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidParamTagName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidParamTagTypeParameter", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidProvidesClass", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidProvidesClassName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidSeeArgs", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidSeeHref", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidSeeReference", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidSeeUrlReference", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidThrowsClass", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidThrowsClassName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidUsesClass", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidUsesClassName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidValueReference", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMalformedSeeReference", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMessagePrefix", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("JavadocMissing", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingHashCharacter", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingIdentifier", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingParamName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingParamTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingProvidesClassName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingProvidesTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingReturnTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingSeeReference", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingTagDescription", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingThrowsClassName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingThrowsTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingUsesClassName", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingUsesTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocNoMessageSendOnArrayType", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocNoMessageSendOnBaseType", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocNonGenericConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocNonGenericMethod", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocNonStaticTypeFromStaticInvocation", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocNotAccessibleType", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocNotVisibleConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + 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("JavadocTypeArgumentsForRawGenericConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocTypeArgumentsForRawGenericMethod", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocUndefinedConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocUndefinedField", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocUndefinedMethod", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocUndefinedType", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocUnexpectedTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocUnexpectedText", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocUnterminatedInlineTag", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + expectedProblemAttributes.put("JavadocUsingDeprecatedConstructor", new ProblemAttributes(CategorizedProblem.CAT_JAVADOC)); + 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("LambdaDescriptorMentionsUnmentionable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("LambdaExpressionNotBelow18", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("LambdaRedeclaresArgument", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("LambdaRedeclaresLocal", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("LambdaShapeComputationError", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + 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("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)); + expectedProblemAttributes.put("MethodNameClash", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("MethodNameClashHidden", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("MethodReducesVisibility", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("MethodReferenceNotBelow18", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("MethodReferenceSwingsBothWays", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("MethodRequiresBody", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("MethodReturnsVoid", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("MethodVarargsArgumentNeedCast", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("MisplacedTypeAnnotations", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("MissingArgumentsForParameterizedMemberType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("MissingDefaultCase", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("MissingEnclosingInstance", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("MissingEnclosingInstanceForConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("MissingEnumConstantCase", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("MissingEnumConstantCaseDespiteDefault", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("MissingEnumDefaultCase", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("MissingNonNullByDefaultAnnotationOnPackage", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("MissingNonNullByDefaultAnnotationOnType", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("MissingNullAnnotationImplicitlyUsed", new ProblemAttributes(CategorizedProblem.CAT_BUILDPATH)); + expectedProblemAttributes.put("MissingOverrideAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("MissingOverrideAnnotationForInterfaceMethodImplementation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("MissingRequiresTransitiveForTypeInAPI", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("MissingReturnType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("MissingSemiColon", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("MissingSerialVersion", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("MissingSynchronizedModifierInInheritedMethod", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("MissingTypeInConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("MissingTypeInLambda", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UnterminatedTextBlock", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED)); + expectedProblemAttributes.put("MissingTypeInMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("MissingValueForAnnotationMember", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("MissingValueFromLambda", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("MultiCatchNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("MultipleFunctionalInterfaces", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("StaticInterfaceMethodNotBelow18", 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)); + expectedProblemAttributes.put("NeedToEmulateConstructorAccess", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("NeedToEmulateFieldReadAccess", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("NeedToEmulateFieldWriteAccess", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("NeedToEmulateMethodAccess", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("NestedServiceImpl", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("NoAdditionalBoundAfterTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("NoFieldOnBaseType", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NoGenericLambda", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("NoImplicitStringConversionForCharArrayExpression", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NoMessageSendOnArrayType", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NoMessageSendOnBaseType", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NoSuperInInterfaceContext", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("NonBlankFinalLocalAssignment", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("NonConstantExpression", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("NonDenotableTypeArgumentForAnonymousDiamond", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("NonExternalizedStringLiteral", new ProblemAttributes(CategorizedProblem.CAT_NLS)); + expectedProblemAttributes.put("NonGenericConstructor", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("NonGenericMethod", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("NonGenericType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("NonNullDefaultDetailIsNotEvaluated", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("NonNullExpressionComparisonYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NonNullMessageSendComparisonYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NonNullSpecdFieldComparisonYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NonNullLocalVariableComparisonYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NonNullTypeVariableFromLegacyMethod", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NonNullMethodTypeVariableFromLegacyMethod", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NonPublicTypeInAPI", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NonStaticAccessToStaticField", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("NonStaticAccessToStaticMethod", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("NonStaticContextForEnumMemberType", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("NonStaticFieldFromStaticInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NonStaticOrAlienTypeReceiver", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NonStaticTypeFromStaticInvocation", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("NotAnnotationType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("NotAccessibleConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NotAccessibleField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NotAccessibleMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NotAccessibleType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("NotAccessiblePackage", new ProblemAttributes(CategorizedProblem.CAT_IMPORT)); + expectedProblemAttributes.put("NotExportedTypeInAPI", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ConflictingPackageFromModules", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("ConflictingPackageFromOtherModules", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("NotVisibleConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NotVisibleConstructorInDefaultConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NotVisibleConstructorInImplicitConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NotVisibleField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NotVisibleMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("NotVisibleType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("NullableFieldReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullAnnotationAtQualifyingType", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("NullAnnotationUnsupportedLocation", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("NullAnnotationUnsupportedLocationAtType", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("NullExpressionReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullLocalVariableComparisonYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullLocalVariableInstanceofYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullLocalVariableReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullityMismatchAgainstFreeTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullityMismatchingTypeAnnotation", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullityMismatchingTypeAnnotationSuperHint", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullityMismatchTypeArgument", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullityUncheckedTypeAnnotationDetail", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullityUncheckedTypeAnnotationDetailSuperHint", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullNotCompatibleToFreeTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NullSourceString", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("NullUnboxing", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("NumericValueOutOfRange", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("ObjectCannotBeGeneric", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("ObjectCannotHaveSuperTypes", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("ObjectHasNoSuperclass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ObjectMustBeClass", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("OuterLocalMustBeEffectivelyFinal", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("OuterLocalMustBeFinal", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("OverridingDeprecatedMethod", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("OverridingDeprecatedSinceVersionMethod", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("OverridingTerminallyDeprecatedMethod", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("OverridingTerminallyDeprecatedSinceVersionMethod", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("OverridingMethodWithoutSuperInvocation", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("OverridingNonVisibleMethod", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("PackageCollidesWithType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("PackageDoesNotExistOrIsEmpty", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("PackageIsNotExpectedPackage", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("ParameterAssignment", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("ParameterLackingNonNullAnnotation", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ParameterLackingNullableAnnotation", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + 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("ParsingError", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorDeleteToken", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorDeleteTokens", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorInsertToComplete", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorInsertToCompletePhrase", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorInsertToCompleteScope", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorInsertTokenAfter", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorInsertTokenBefore", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorInvalidToken", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorMergeTokens", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorMisplacedConstruct", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorNoSuggestion", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorNoSuggestionForTokens", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ParsingErrorOnKeyword", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + 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("PatternVariableNotInScope", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED)); + expectedProblemAttributes.put("PatternVariableRedefined", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("PatternSubtypeOfExpression", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("IllegalModifierForPatternVariable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("PatternVariableRedeclared", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + 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("PotentiallyUnclosedCloseable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("PotentiallyUnclosedCloseableAtExit", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("PotentialNullLocalVariableReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("PotentialNullExpressionReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("PotentialNullMessageSendReference", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("PotentialNullUnboxing", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ProviderMethodOrConstructorRequiredForServiceImpl", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("PublicClassMustMatchFileName", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RawMemberTypeCannotBeParameterized", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RawTypeReference", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + 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("RedundantNullAnnotation", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("RedundantNullCheckAgainstNonNullType", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RedundantNullCheckOnConstNonNullField", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RedundantNullCheckOnField", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RedundantNullCheckOnNonNullExpression", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RedundantNullCheckOnNonNullSpecdField", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RedundantNullCheckOnNonNullLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RedundantNullCheckOnNonNullMessageSend", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RedundantNullCheckOnNullLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RedundantNullCheckOnSpecdNonNullLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotation", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationModule", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationPackage", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationType", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationMethod", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationLocal", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("RedundantSuperinterface", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("ReferenceExpressionParameterNullityMismatch", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ReferenceExpressionParameterNullityUnchecked", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ReferenceExpressionReturnNullRedef", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ReferenceExpressionReturnNullRedefUnchecked", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ReferenceToForwardField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("RequiredNonNullButProvidedFreeTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RequiredNonNullButProvidedNull", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RequiredNonNullButProvidedPotentialNull", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RequiredNonNullButProvidedSpecdNullable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("RequiredNonNullButProvidedUnknown", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ReferenceToForwardTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RepeatableAnnotationTypeIsDocumented", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RepeatableAnnotationTypeIsInherited", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RepeatableAnnotationTypeTargetMismatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RepeatableAnnotationWithRepeatingContainerAnnotation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RepeatedAnnotationWithContainerAnnotation", 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("ReturnTypeMismatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + 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("ServiceImplDefaultConstructorNotPublic", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ServiceImplNotDefinedByModule", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ShouldImplementHashcode", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ShouldReturnValue", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("ShouldReturnValueHintMissingDefault", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("SpecdNonNullLocalVariableComparisonYieldsFalse", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + 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("StaticMethodShouldBeAccessedStatically", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("StringConstantIsExceedingUtf8Limit", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SuperAccessCannotBypassDirectSuper", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SuperCallCannotBypassOverride", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + 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); + expectedProblemAttributes.put("SuperclassMustBeAClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SuperclassNotFound", DEPRECATED); + expectedProblemAttributes.put("SuperclassNotVisible", DEPRECATED); + expectedProblemAttributes.put("SuperfluousSemicolon", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("SwitchOnEnumNotBelow15", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SwitchOnStringsNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("TargetTypeNotAFunctionalInterface", 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)); + expectedProblemAttributes.put("ToleratedMisplacedTypeAnnotations", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("TooManyArgumentSlots", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("TooManyArrayDimensions", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("TooManyBytesForStringConstant", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("TooManyConstantsInConstantPool", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("TooManyFields", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("TooManyLocalVariableSlots", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("TooManyMethods", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("TooManyParametersForSyntheticMethod", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("TooManySyntheticArgumentSlots", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("TypeAnnotationAtQualifiedName", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("TypeArgumentMismatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("TypeArgumentsForRawGenericConstructor", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("TypeArgumentsForRawGenericMethod", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("TypeCollidesWithPackage", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("TypeHidingType", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("TypeHidingTypeParameterFromMethod", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("TypeHidingTypeParameterFromType", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("TypeMismatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("TypeMissingDeprecatedAnnotation", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("TypeParameterHidingType", new ProblemAttributes(CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT)); + expectedProblemAttributes.put("UnboxingConversion", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("UncheckedAccessOfValueOfFreeTypeVariable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UnclosedCloseable", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UnclosedCloseableAtExit", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UndefinedAnnotationMember", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UndefinedConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UndefinedConstructorInDefaultConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UndefinedConstructorInImplicitConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UndefinedField", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UndefinedLabel", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("UndefinedMethod", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UndefinedModule", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("UndefinedModuleAddReads", new ProblemAttributes(CategorizedProblem.CAT_BUILDPATH)); + 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("UninitializedBlankFinalFieldHintMissingDefault", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UninitializedFreeTypeVariableField", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UninitializedFreeTypeVariableFieldHintMissingDefault", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UninitializedLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("UninitializedLocalVariableHintMissingDefault", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("UninitializedNonNullField", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UninitializedNonNullFieldHintMissingDefault", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UninternedIdentityComparison", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("UnlikelyCollectionMethodArgumentType", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UnlikelyEqualsArgumentType", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UnmatchedBracket", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("UnnamedPackageInNamedModule", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("UnnecessaryArgumentCast", DEPRECATED); + 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("UnnecessaryNLSTag", new ProblemAttributes(CategorizedProblem.CAT_NLS)); + expectedProblemAttributes.put("UnnecessaryNullCaseInSwitchOverNonNull", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UnqualifiedFieldAccess", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("UnreachableCatch", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("UnresolvedVariable", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UnsafeCast", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("UnsafeElementTypeConversion", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + expectedProblemAttributes.put("UnsafeGenericArrayForVarargs", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + expectedProblemAttributes.put("UnsafeGenericCast", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + expectedProblemAttributes.put("UnsafeNullnessCast", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UnsafeRawConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + expectedProblemAttributes.put("UnsafeRawFieldAssignment", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + expectedProblemAttributes.put("UnsafeRawGenericConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + expectedProblemAttributes.put("UnsafeRawGenericMethodInvocation", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + expectedProblemAttributes.put("UnsafeRawMethodInvocation", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + expectedProblemAttributes.put("UnsafeReturnTypeOverride", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + expectedProblemAttributes.put("UnsafeTypeConversion", new ProblemAttributes(CategorizedProblem.CAT_UNCHECKED_RAW)); + expectedProblemAttributes.put("UnstableAutoModuleName", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("ConflictingPackageInModules", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("UnterminatedComment", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("UnterminatedString", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("UnusedConstructorDeclaredThrownException", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM)); + expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UnusedPrivateType", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UnusedTypeArgumentsForConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UnusedTypeParameter", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UnusedTypeArgumentsForMethodInvocation", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("UnusedWarningToken", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("UseAssertAsAnIdentifier", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("UseEnumAsAnIdentifier", new ProblemAttributes(CategorizedProblem.CAT_CODE_STYLE)); + expectedProblemAttributes.put("IllegalUseOfUnderscoreAsAnIdentifier", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ErrorUseOfUnderscoreAsAnIdentifier", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("UsingDeprecatedConstructor", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedField", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedMethod", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedModule", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedPackage", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("UsingDeprecatedType", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionConstructor", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionField", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionMethod", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionModule", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionPackage", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionType", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedConstructor", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedField", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedMethod", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedModule", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedPackage", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedType", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionConstructor", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionField", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionMethod", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionModule", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionPackage", new ProblemAttributes(CategorizedProblem.CAT_MODULE)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionType", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionType", new ProblemAttributes(CategorizedProblem.CAT_DEPRECATION)); + expectedProblemAttributes.put("VarCannotBeMixedWithNonVarParams", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarIsNotAllowedHere", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarIsReserved", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarIsReservedInFuture", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarLocalCannotBeArray", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarLocalCannotBeArrayInitalizers", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("VarLocalCannotBeLambda", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("VarLocalCannotBeMethodReference", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("VarLocalInitializedToNull", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("VarLocalInitializedToVoid", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("VarLocalMultipleDeclarators", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarLocalReferencesItself", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarLocalCannotBeArray", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarLocalWithoutInitizalier", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("VarargsElementTypeNotVisible", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("VarargsElementTypeNotVisibleForConstructor", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("VarargsConflict", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("VariableTypeCannotBeVoid", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("VariableTypeCannotBeVoidArray", DEPRECATED); + expectedProblemAttributes.put("VoidMethodReturnsValue", new ProblemAttributes(CategorizedProblem.CAT_MEMBER)); + expectedProblemAttributes.put("WildcardConstructorInvocation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("WildcardFieldAssignment", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("WildcardMethodInvocation", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("illFormedParameterizationOfFunctionalInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("lambdaParameterTypeMismatched", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("lambdaSignatureMismatched", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalArrayOfUnionType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalArrayTypeInIntersectionCast", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("ProblemNotAnalysed", new ProblemAttributes(CategorizedProblem.CAT_UNNECESSARY_CODE)); + expectedProblemAttributes.put("SwitchExpressionsIncompatibleResultExpressionTypes", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SwitchExpressionsEmptySwitchBlock", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionsNoResultExpression", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SwitchExpressionSwitchLabeledBlockCompletesNormally", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionLastStatementCompletesNormally", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionIllegalLastStatement", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionTrailingSwitchLabels", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("switchMixedCase", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionMissingDefaultCase", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionNotBelow12", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchCaseLabelWithArrowNotBelow12", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionPreviewDisabled", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchCaseLabelWithArrowPreviewDisabled", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionBreakMissingValue", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionMissingEnumConstantCase", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("PreviewFeatureDisabled", new ProblemAttributes(CategorizedProblem.CAT_COMPLIANCE)); + expectedProblemAttributes.put("PreviewFeatureUsed", new ProblemAttributes(CategorizedProblem.CAT_COMPLIANCE)); + expectedProblemAttributes.put("PreviewFeatureNotSupported", new ProblemAttributes(CategorizedProblem.CAT_COMPLIANCE)); + expectedProblemAttributes.put("PreviewFeaturesNotAllowed", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED)); + expectedProblemAttributes.put("FeatureNotSupported", new ProblemAttributes(CategorizedProblem.CAT_COMPLIANCE)); + expectedProblemAttributes.put("PreviewAPIUsed", new ProblemAttributes(CategorizedProblem.CAT_COMPLIANCE)); + expectedProblemAttributes.put("SwitchExpressionsYieldIncompatibleResultExpressionTypes", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SwitchExpressionsYieldEmptySwitchBlock", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsYieldNoResultExpression", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionaYieldSwitchLabeledBlockCompletesNormally", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionsYieldLastStatementCompletesNormally", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionsYieldTrailingSwitchLabels", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchPreviewMixedCase", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsYieldMissingDefaultCase", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsYieldMissingValue", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsYieldMissingEnumConstantCase", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsYieldIllegalLastStatement", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionsYieldBreakNotAllowed", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsYieldUnqualifiedMethodWarning", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsYieldUnqualifiedMethodError", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsYieldOutsideSwitchExpression", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsYieldRestrictedGeneralWarning", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionsYieldIllegalStatement", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationWarning", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationError", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL)); + expectedProblemAttributes.put("MultiConstantCaseLabelsNotSupported", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("ArrowInCaseStatementsNotSupported", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsNotSupported", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsBreakOutOfSwitchExpression", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsContinueOutOfSwitchExpression", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("SwitchExpressionsReturnWithinSwitchExpression", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("RecordIllegalModifierForRecord", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordIllegalModifierForInnerRecord", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordIllegalComponentNameInRecord", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordNonStaticFieldDeclarationInRecord", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordAccessorMethodHasThrowsClause", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordCanonicalConstructorHasThrowsClause", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordCanonicalConstructorVisibilityReduced", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordMultipleCanonicalConstructors", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordCompactConstructorHasReturnStatement", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordDuplicateComponent", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordIllegalNativeModifierInRecord", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordInstanceInitializerBlockInRecord", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RestrictedTypeName", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordIllegalAccessorReturnType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordAccessorMethodShouldNotBeGeneric", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordAccessorMethodShouldBePublic", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordCanonicalConstructorShouldNotBeGeneric", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordCanonicalConstructorHasReturnStatement", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordCanonicalConstructorHasExplicitConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordCompactConstructorHasExplicitConstructorCall", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordNestedRecordInherentlyStatic", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordAccessorMethodShouldNotBeStatic", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordCannotExtendRecord", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordComponentCannotBeVoid", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordIllegalVararg", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordStaticReferenceToOuterLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordCannotDefineRecordInLocalType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordComponentsCannotHaveModifiers", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordIllegalParameterNameInCanonicalConstructor", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordIllegalExplicitFinalFieldAssignInCompactConstructor", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordMissingExplicitConstructorCallInNonCanonicalConstructor", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordIllegalStaticModifierForLocalClassOrInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordIllegalModifierForLocalRecord", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("RecordIllegalExtendedDimensionsForRecordComponent", new ProblemAttributes(CategorizedProblem.CAT_SYNTAX)); + expectedProblemAttributes.put("LocalStaticsIllegalVisibilityModifierForInterfaceLocalType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("IllegalModifierForLocalEnumDeclaration", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedMissingClassModifier", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedDisAllowedNonSealedModifierInClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedSuperClassDoesNotPermit", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedSuperInterfaceDoesNotPermit", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedMissingSealedModifier", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedMissingInterfaceModifier", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedDuplicateTypeInPermits", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedNotDirectSuperClass", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedPermittedTypeOutsideOfModule", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedPermittedTypeOutsideOfPackage", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedSealedTypeMissingPermits", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedInterfaceIsSealedAndNonSealed", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedDisAllowedNonSealedModifierInInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedNotDirectSuperInterface", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedLocalDirectSuperTypeSealed", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedAnonymousClassCannotExtendSealedType", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("LocalReferencedInGuardMustBeEffectivelyFinal", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED)); + expectedProblemAttributes.put("SealedSuperTypeInDifferentPackage", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SealedSuperTypeDisallowed", new ProblemAttributes(CategorizedProblem.CAT_TYPE)); + expectedProblemAttributes.put("SafeVarargsOnSyntheticRecordAccessor", new ProblemAttributes(true)); + expectedProblemAttributes.put("DiscouragedValueBasedTypeSynchronization", new ProblemAttributes(true)); + expectedProblemAttributes.put("ConstantWithPatternIncompatible", new ProblemAttributes(true)); + expectedProblemAttributes.put("IllegalFallthroughToPattern", new ProblemAttributes(true)); + expectedProblemAttributes.put("OnlyOnePatternCaseLabelAllowed", new ProblemAttributes(true)); + expectedProblemAttributes.put("CannotMixPatternAndDefault", new ProblemAttributes(true)); + expectedProblemAttributes.put("CannotMixNullAndNonTypePattern", new ProblemAttributes(true)); + expectedProblemAttributes.put("PatternDominated", new ProblemAttributes(true)); + expectedProblemAttributes.put("IllegalTotalPatternWithDefault", new ProblemAttributes(true)); + expectedProblemAttributes.put("EnhancedSwitchMissingDefault", new ProblemAttributes(true)); + expectedProblemAttributes.put("DuplicateTotalPattern", new ProblemAttributes(true)); + expectedProblemAttributes.put("UnexpectedTypeinSwitchPattern", new ProblemAttributes(true)); + + StringBuffer failures = new StringBuffer(); + StringBuffer correctResult = new StringBuffer(70000); + Field[] fields = (iProblemClass = IProblem.class).getFields(); + Arrays.sort(fields, new Comparator() { + @Override + 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]; + if (field.getType() == Integer.TYPE) { + int problemId = field.getInt(iProblemClass); + int maskedProblemId = problemId & IProblem.IgnoreCategoriesMask; + if (maskedProblemId != 0 && maskedProblemId != IProblem.IgnoreCategoriesMask) { + String name = field.getName(); + ProblemAttributes expectedAttributes = (ProblemAttributes) expectedProblemAttributes.get(name); + if (expectedAttributes == null) { + failures.append("missing expected problem attributes for problem " + name + "\n"); + int actualCategory = ProblemReporter.getProblemCategory(ProblemSeverities.Error, problemId); + correctResult.append("\t\texpectedProblemAttributes.put(\"" + name + + "\", new ProblemAttributes(CategorizedProblem." + categoryName(actualCategory) + + "));\n"); + } else if (!expectedAttributes.deprecated) { + int actualCategory = ProblemReporter.getProblemCategory(ProblemSeverities.Error, problemId); + correctResult.append("\t\texpectedProblemAttributes.put(\"" + name + + "\", new ProblemAttributes(CategorizedProblem." + categoryName(actualCategory) + + "));\n"); + if (expectedAttributes.category != actualCategory) { + failures.append("category mismatch for problem " + name + " (expected " + + categoryName(expectedAttributes.category) + ", got " + + categoryName(actualCategory) + ")\n"); + } + if (watchInternalCategory && actualCategory == CategorizedProblem.CAT_INTERNAL) { + if (printHeader) { + printHeader = false; + System.err.println("CAT_INTERNAL for problems:"); + } + System.err.println("\t" + name); + } + } else { + correctResult.append("\t\texpectedProblemAttributes.put(\"" + name + "\", DEPRECATED);\n"); + } + } + } + } + if (failures.length() > 0) { + System.out.println(correctResult); + System.out.println(); + } + assertEquals(failures.toString(), 0, failures.length()); + } catch (IllegalAccessException e) { + fail("could not access members"); + } + } + + private static Map categoryNames; + + private String categoryName(int category) { + if (categoryNames == null) { + categoryNames = new HashMap(); + Field[] fields = CategorizedProblem.class.getFields(); + for (int i = 0, length = fields.length; i < length; i++) { + Field field = fields[i]; + if (field.getType() == Integer.TYPE) { + String name = field.getName(); + if (name.startsWith("CAT_")) { + try { + categoryNames.put(Integer.valueOf(field.getInt(CategorizedProblem.class)), name); + } catch (IllegalArgumentException e) { + } catch (IllegalAccessException e) { + } + } + } + } + } + return (String) categoryNames.get(Integer.valueOf(category)); + } + +// compiler problems tuning +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=218603 +public void test012_compiler_problems_tuning() { + try { + class ProblemAttributes { + boolean skip; + String option; + ProblemAttributes(String option) { + this.option = option; + } + ProblemAttributes(boolean skip) { + this.skip = skip; + } + } + ProblemAttributes SKIP = new ProblemAttributes(true); + Map expectedProblemAttributes = new HashMap(); + expectedProblemAttributes.put("AbstractMethodCannotBeOverridden", SKIP); + expectedProblemAttributes.put("AbstractMethodInAbstractClass", SKIP); + expectedProblemAttributes.put("AbstractMethodInEnum", SKIP); + expectedProblemAttributes.put("AbstractMethodMustBeImplemented", SKIP); + expectedProblemAttributes.put("AbstractMethodMustBeImplementedOverConcreteMethod", SKIP); + expectedProblemAttributes.put("AbstractMethodsInConcreteClass", SKIP); + expectedProblemAttributes.put("AbstractServiceImplementation", SKIP); + expectedProblemAttributes.put("AmbiguousConstructor", SKIP); + expectedProblemAttributes.put("AmbiguousConstructorInDefaultConstructor", SKIP); + expectedProblemAttributes.put("AmbiguousConstructorInImplicitConstructorCall", SKIP); + expectedProblemAttributes.put("AmbiguousField", SKIP); + expectedProblemAttributes.put("AmbiguousMethod", SKIP); + expectedProblemAttributes.put("AmbiguousType", SKIP); + expectedProblemAttributes.put("AnnotatedTypeArgumentToUnannotated", new ProblemAttributes(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED)); + expectedProblemAttributes.put("AnnotatedTypeArgumentToUnannotatedSuperHint", new ProblemAttributes(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED)); + expectedProblemAttributes.put("AnnotationCannotOverrideMethod", SKIP); + expectedProblemAttributes.put("AnnotationCircularity", SKIP); + expectedProblemAttributes.put("AnnotationCircularitySelfReference", SKIP); + expectedProblemAttributes.put("AnnotationFieldNeedConstantInitialization", SKIP); + expectedProblemAttributes.put("AnnotationMembersCannotHaveParameters", SKIP); + expectedProblemAttributes.put("AnnotationMembersCannotHaveTypeParameters", SKIP); + expectedProblemAttributes.put("AnnotationTypeDeclarationCannotHaveConstructor", SKIP); + expectedProblemAttributes.put("AnnotationTypeDeclarationCannotHaveSuperclass", SKIP); + expectedProblemAttributes.put("AnnotationTypeDeclarationCannotHaveSuperinterfaces", SKIP); + expectedProblemAttributes.put("AnnotationTypeUsedAsSuperInterface", new ProblemAttributes(JavaCore.COMPILER_PB_ANNOTATION_SUPER_INTERFACE)); + expectedProblemAttributes.put("AnnotationValueMustBeAnEnumConstant", SKIP); + expectedProblemAttributes.put("AnnotationValueMustBeAnnotation", SKIP); + expectedProblemAttributes.put("AnnotationValueMustBeArrayInitializer", SKIP); + expectedProblemAttributes.put("AnnotationValueMustBeClassLiteral", SKIP); + expectedProblemAttributes.put("AnnotationValueMustBeConstant", SKIP); + expectedProblemAttributes.put("AnonymousClassCannotExtendFinalClass", SKIP); + expectedProblemAttributes.put("ApplicableMethodOverriddenByInapplicable", SKIP); + expectedProblemAttributes.put("ArgumentHidingField", new ProblemAttributes(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING)); + expectedProblemAttributes.put("ArgumentHidingLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING)); + expectedProblemAttributes.put("ArgumentIsNeverUsed", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PARAMETER)); + expectedProblemAttributes.put("ArgumentTypeAmbiguous", SKIP); + expectedProblemAttributes.put("ArgumentTypeCannotBeVoid", SKIP); + expectedProblemAttributes.put("ArgumentTypeCannotBeVoidArray", SKIP); + expectedProblemAttributes.put("ArgumentTypeInheritedNameHidesEnclosingName", SKIP); + expectedProblemAttributes.put("ArgumentTypeInternalNameProvided", SKIP); + expectedProblemAttributes.put("ArgumentTypeNotFound", SKIP); + expectedProblemAttributes.put("ArgumentTypeNotVisible", SKIP); + expectedProblemAttributes.put("ArrayConstantsOnlyInArrayInitializers", SKIP); + expectedProblemAttributes.put("ArrayReferencePotentialNullReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE)); + 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("AutoManagedVariableResourceNotBelow9", SKIP); + expectedProblemAttributes.put("BinaryLiteralNotBelow17", SKIP); + expectedProblemAttributes.put("BodyForAbstractMethod", SKIP); + expectedProblemAttributes.put("BodyForNativeMethod", SKIP); + expectedProblemAttributes.put("BoundCannotBeArray", SKIP); + expectedProblemAttributes.put("BoundHasConflictingArguments", SKIP); + expectedProblemAttributes.put("BoundMustBeAnInterface", SKIP); + expectedProblemAttributes.put("BoxingConversion", new ProblemAttributes(JavaCore.COMPILER_PB_AUTOBOXING)); + expectedProblemAttributes.put("BytecodeExceeds64KLimit", SKIP); + expectedProblemAttributes.put("BytecodeExceeds64KLimitForClinit", SKIP); + expectedProblemAttributes.put("BytecodeExceeds64KLimitForConstructor", SKIP); + expectedProblemAttributes.put("BytecodeExceeds64KLimitForSwitchTable", SKIP); + expectedProblemAttributes.put("CannotAllocateVoidArray", SKIP); + expectedProblemAttributes.put("CannotDeclareEnumSpecialMethod", SKIP); + expectedProblemAttributes.put("CannotDefineAnnotationInLocalType", SKIP); + expectedProblemAttributes.put("CannotDefineDimensionExpressionsWithInit", SKIP); + expectedProblemAttributes.put("CannotDefineEnumInLocalType", SKIP); + expectedProblemAttributes.put("CannotDefineInterfaceInLocalType", SKIP); + expectedProblemAttributes.put("CannotDefineStaticInitializerInLocalType", SKIP); + expectedProblemAttributes.put("CannotExtendEnum", SKIP); + expectedProblemAttributes.put("CannotHideAnInstanceMethodWithAStaticMethod", SKIP); + expectedProblemAttributes.put("CannotImportPackage", SKIP); + expectedProblemAttributes.put("CannotImplementIncompatibleNullness", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("CannotInferElidedTypes", SKIP); + expectedProblemAttributes.put("CannotInferInvocationType", 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); + expectedProblemAttributes.put("CodeSnippetMissingClass", SKIP); + expectedProblemAttributes.put("CodeSnippetMissingMethod", SKIP); + expectedProblemAttributes.put("ComparingIdentical", new ProblemAttributes(JavaCore.COMPILER_PB_COMPARING_IDENTICAL)); + expectedProblemAttributes.put("ConstNonNullFieldComparisonYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("ConflictingImport", SKIP); + expectedProblemAttributes.put("ConflictingNullAnnotations", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("ConstructedArrayIncompatible", SKIP); + expectedProblemAttributes.put("ConstructionTypeMismatch", SKIP); + expectedProblemAttributes.put("ConflictingInheritedNullAnnotations", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("ConstructorReferenceNotBelow18", SKIP); + expectedProblemAttributes.put("ContainerAnnotationTypeHasNonDefaultMembers", SKIP); + expectedProblemAttributes.put("ContainerAnnotationTypeHasShorterRetention", SKIP); + expectedProblemAttributes.put("ContainerAnnotationTypeHasWrongValueType", SKIP); + expectedProblemAttributes.put("ContainerAnnotationTypeMustHaveValue", SKIP); + expectedProblemAttributes.put("ContradictoryNullAnnotations", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("ContradictoryNullAnnotationsOnBound", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("ContradictoryNullAnnotationsInferred", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("ContradictoryNullAnnotationsInferredFunctionType", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("ConstructorVarargsArgumentNeedCast", new ProblemAttributes(JavaCore.COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST)); + expectedProblemAttributes.put("CorruptedSignature", SKIP); + expectedProblemAttributes.put("CyclicModuleDependency", SKIP); + expectedProblemAttributes.put("DanglingReference", SKIP); + expectedProblemAttributes.put("DeadCode", new ProblemAttributes(JavaCore.COMPILER_PB_DEAD_CODE)); + expectedProblemAttributes.put("DefaultMethodNotBelow18", SKIP); + expectedProblemAttributes.put("DefaultMethodOverridesObjectMethod", SKIP); + expectedProblemAttributes.put("DereferencingNullableExpression", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE)); + expectedProblemAttributes.put("DiamondNotBelow17", SKIP); + expectedProblemAttributes.put("DirectInvocationOfAbstractMethod", SKIP); + expectedProblemAttributes.put("DisallowedTargetForAnnotation", SKIP); + expectedProblemAttributes.put("DisallowedTargetForContainerAnnotationType", SKIP); + expectedProblemAttributes.put("DiscouragedReference", new ProblemAttributes(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE)); + expectedProblemAttributes.put("DuplicateAnnotation", SKIP); + expectedProblemAttributes.put("DuplicateAnnotationNotMarkedRepeatable", SKIP); + expectedProblemAttributes.put("DuplicateAnnotationMember", SKIP); + expectedProblemAttributes.put("DuplicateBlankFinalFieldInitialization", SKIP); + expectedProblemAttributes.put("DuplicateBounds", SKIP); + expectedProblemAttributes.put("DuplicateBoundInIntersectionCast", SKIP); + expectedProblemAttributes.put("DuplicateCase", SKIP); + expectedProblemAttributes.put("DuplicateDefaultCase", SKIP); + expectedProblemAttributes.put("DuplicateExports", SKIP); + expectedProblemAttributes.put("DuplicateField", SKIP); + expectedProblemAttributes.put("DuplicateFinalLocalInitialization", SKIP); + expectedProblemAttributes.put("DuplicateImport", SKIP); + expectedProblemAttributes.put("DuplicateInheritedMethods", SKIP); + expectedProblemAttributes.put("DuplicateInheritedDefaultMethods", SKIP); + expectedProblemAttributes.put("DuplicateLabel", SKIP); + expectedProblemAttributes.put("DuplicateMethod", SKIP); + expectedProblemAttributes.put("DuplicateMethodErasure", SKIP); + expectedProblemAttributes.put("DuplicateModifierForArgument", SKIP); + expectedProblemAttributes.put("DuplicateModifierForField", SKIP); + expectedProblemAttributes.put("DuplicateModifierForMethod", SKIP); + expectedProblemAttributes.put("DuplicateModifierForType", SKIP); + expectedProblemAttributes.put("DuplicateModifierForVariable", SKIP); + expectedProblemAttributes.put("DuplicateModuleRef", SKIP); + expectedProblemAttributes.put("DuplicateNestedType", SKIP); + expectedProblemAttributes.put("DuplicateOpens", SKIP); + expectedProblemAttributes.put("DuplicateParameterizedMethods", SKIP); + expectedProblemAttributes.put("DuplicateRequires", SKIP); + expectedProblemAttributes.put("DuplicateResource", SKIP); + expectedProblemAttributes.put("DuplicateServices", SKIP); + expectedProblemAttributes.put("DuplicateSuperInterface", SKIP); + expectedProblemAttributes.put("DuplicateTargetInTargetAnnotation", SKIP); + expectedProblemAttributes.put("DuplicateTypeVariable", SKIP); + expectedProblemAttributes.put("DuplicateTypes", SKIP); + expectedProblemAttributes.put("DuplicateUses", SKIP); + expectedProblemAttributes.put("EmptyControlFlowStatement", new ProblemAttributes(JavaCore.COMPILER_PB_EMPTY_STATEMENT)); + expectedProblemAttributes.put("EnclosingInstanceInConstructorCall", SKIP); + expectedProblemAttributes.put("EndOfSource", SKIP); + expectedProblemAttributes.put("EnumAbstractMethodMustBeImplemented", SKIP); + expectedProblemAttributes.put("EnumConstantCannotDefineAbstractMethod", SKIP); + expectedProblemAttributes.put("EnumConstantMustImplementAbstractMethod", SKIP); + expectedProblemAttributes.put("EnumConstantsCannotBeSurroundedByParenthesis", SKIP); + expectedProblemAttributes.put("EnumStaticFieldInInInitializerContext", SKIP); + expectedProblemAttributes.put("EnumSwitchCannotTargetField", SKIP); + expectedProblemAttributes.put("ExceptionParameterIsNeverUsed", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_EXCEPTION_PARAMETER)); + expectedProblemAttributes.put("ExceptionTypeAmbiguous", SKIP); + expectedProblemAttributes.put("ExceptionTypeInheritedNameHidesEnclosingName", SKIP); + expectedProblemAttributes.put("ExceptionTypeInternalNameProvided", SKIP); + expectedProblemAttributes.put("ExceptionTypeNotFound", SKIP); + expectedProblemAttributes.put("ExceptionTypeNotVisible", SKIP); + expectedProblemAttributes.put("ExplicitThisParameterNotInLambda", SKIP); + expectedProblemAttributes.put("ExplicitThisParameterNotBelow18", SKIP); + expectedProblemAttributes.put("ExplicitlyClosedAutoCloseable", new ProblemAttributes(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE)); + expectedProblemAttributes.put("ExportingForeignPackage", SKIP); + expectedProblemAttributes.put("ExportedPackageDoesNotExistOrIsEmpty", SKIP); + expectedProblemAttributes.put("ExpressionShouldBeAVariable", SKIP); + expectedProblemAttributes.put("ExternalProblemFixable", SKIP); + expectedProblemAttributes.put("ExternalProblemNotFixable", SKIP); + expectedProblemAttributes.put("ExplicitAnnotationTargetRequired", SKIP); + expectedProblemAttributes.put("FallthroughCase", new ProblemAttributes(JavaCore.COMPILER_PB_FALLTHROUGH_CASE)); + expectedProblemAttributes.put("FieldComparisonYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("FieldHidingField", new ProblemAttributes(JavaCore.COMPILER_PB_FIELD_HIDING)); + expectedProblemAttributes.put("FieldHidingLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_FIELD_HIDING)); + expectedProblemAttributes.put("FieldMissingDeprecatedAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION)); + expectedProblemAttributes.put("FieldMustBeFinal", SKIP); + expectedProblemAttributes.put("FieldTypeAmbiguous", SKIP); + expectedProblemAttributes.put("FieldTypeInheritedNameHidesEnclosingName", SKIP); + expectedProblemAttributes.put("FieldTypeInternalNameProvided", SKIP); + expectedProblemAttributes.put("FieldTypeNotFound", SKIP); + expectedProblemAttributes.put("FieldTypeNotVisible", SKIP); + expectedProblemAttributes.put("FinalBoundForTypeVariable", new ProblemAttributes(JavaCore.COMPILER_PB_FINAL_PARAMETER_BOUND)); + expectedProblemAttributes.put("FinalFieldAssignment", SKIP); + 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("GenericInferenceError", SKIP); // TODO should be removed via https://bugs.eclipse.org/404675 + expectedProblemAttributes.put("GenericMethodTypeArgumentMismatch", SKIP); + expectedProblemAttributes.put("GenericTypeCannotExtendThrowable", SKIP); + expectedProblemAttributes.put("HidingEnclosingType", SKIP); + expectedProblemAttributes.put("HierarchyCircularity", SKIP); + expectedProblemAttributes.put("HierarchyCircularitySelfReference", SKIP); + expectedProblemAttributes.put("HierarchyHasProblems", SKIP); + expectedProblemAttributes.put("IllegalAbstractModifierCombinationForMethod", SKIP); + expectedProblemAttributes.put("IllegalStrictfpForAbstractInterfaceMethod", SKIP); + expectedProblemAttributes.put("IllegalAccessFromTypeVariable", SKIP); + expectedProblemAttributes.put("IllegalAnnotationForBaseType", SKIP); + expectedProblemAttributes.put("IllegalCast", SKIP); + expectedProblemAttributes.put("IllegalClassLiteralForTypeVariable", SKIP); + expectedProblemAttributes.put("IllegalDeclarationOfThisParameter", SKIP); + expectedProblemAttributes.put("IllegalDefaultModifierSpecification", SKIP); + expectedProblemAttributes.put("IllegalDefinitionToNonNullParameter", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("IllegalDimension", SKIP); + expectedProblemAttributes.put("IllegalEnclosingInstanceSpecification", SKIP); + 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("IllegalBasetypeInIntersectionCast", SKIP); + expectedProblemAttributes.put("IllegalModifierCombinationFinalAbstractForClass", SKIP); + expectedProblemAttributes.put("IllegalModifierCombinationFinalVolatileForField", SKIP); + expectedProblemAttributes.put("IllegalModifierCombinationForInterfaceMethod", SKIP); + expectedProblemAttributes.put("IllegalModifierCombinationForPrivateInterfaceMethod9", SKIP); + expectedProblemAttributes.put("IllegalModifierForAnnotationField", SKIP); + expectedProblemAttributes.put("IllegalModifierForAnnotationMemberType", SKIP); + expectedProblemAttributes.put("IllegalModifierForAnnotationMethod", SKIP); + expectedProblemAttributes.put("IllegalModifierForAnnotationType", SKIP); + expectedProblemAttributes.put("IllegalModifierForArgument", SKIP); + expectedProblemAttributes.put("IllegalModifierForClass", SKIP); + expectedProblemAttributes.put("IllegalModifierForConstructor", SKIP); + expectedProblemAttributes.put("StrictfpNotRequired", SKIP); + expectedProblemAttributes.put("IllegalModifierForEnum", SKIP); + expectedProblemAttributes.put("IllegalModifierForEnumConstant", SKIP); + expectedProblemAttributes.put("IllegalModifierForEnumConstructor", SKIP); + expectedProblemAttributes.put("IllegalModifierForField", SKIP); + expectedProblemAttributes.put("IllegalModifierForInterface", SKIP); + expectedProblemAttributes.put("IllegalModifierForInterfaceField", SKIP); + expectedProblemAttributes.put("IllegalModifierForInterfaceMethod", SKIP); + expectedProblemAttributes.put("IllegalModifierForInterfaceMethod18", SKIP); + expectedProblemAttributes.put("IllegalModifierForLocalClass", SKIP); + expectedProblemAttributes.put("IllegalModifierForLocalEnum", SKIP); + expectedProblemAttributes.put("IllegalModifierForMemberClass", SKIP); + expectedProblemAttributes.put("IllegalModifierForMemberEnum", SKIP); + expectedProblemAttributes.put("IllegalModifierForMemberInterface", SKIP); + expectedProblemAttributes.put("IllegalModifierForMethod", SKIP); + expectedProblemAttributes.put("IllegalModifierForModule", SKIP); + expectedProblemAttributes.put("IllegalModifierForInterfaceMethod9", SKIP); + expectedProblemAttributes.put("IllegalModifierForVariable", SKIP); + expectedProblemAttributes.put("IllegalModifiersForElidedType", SKIP); + expectedProblemAttributes.put("IllegalModifiers", SKIP); + expectedProblemAttributes.put("IllegalParameterNullityRedefinition", SKIP); + expectedProblemAttributes.put("IllegalPrimitiveOrArrayTypeForEnclosingInstance", SKIP); + expectedProblemAttributes.put("IllegalQualifiedEnumConstantLabel", SKIP); + expectedProblemAttributes.put("IllegalQualifiedParameterizedTypeAllocation", SKIP); + expectedProblemAttributes.put("IllegalQualifierForExplicitThis", SKIP); + expectedProblemAttributes.put("IllegalQualifierForExplicitThis2", SKIP); + expectedProblemAttributes.put("IllegalRedefinitionOfTypeVariable", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("IllegalRedefinitionToNonNullParameter", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("IllegalReturnNullityRedefinition", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("IllegalReturnNullityRedefinitionFreeTypeVariable", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("IllegalStaticModifierForMemberType", SKIP); + expectedProblemAttributes.put("IllegalTypeAnnotationsInStaticMemberAccess", SKIP); + expectedProblemAttributes.put("IllegalTypeArgumentsInRawConstructorReference", SKIP); + expectedProblemAttributes.put("IllegalTypeForExplicitThis", SKIP); + expectedProblemAttributes.put("IllegalTypeVariableSuperReference", SKIP); + expectedProblemAttributes.put("IllegalUnderscorePosition", SKIP); + expectedProblemAttributes.put("IllegalUsageOfQualifiedTypeReference", SKIP); + expectedProblemAttributes.put("IllegalUsageOfTypeAnnotations", SKIP); + expectedProblemAttributes.put("IllegalVararg", SKIP); + expectedProblemAttributes.put("IllegalVarargInLambda", SKIP); + expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForField", SKIP); + expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForMemberType", SKIP); + expectedProblemAttributes.put("IllegalVisibilityModifierCombinationForMethod", SKIP); + expectedProblemAttributes.put("IllegalVisibilityModifierForInterfaceMemberType", SKIP); + expectedProblemAttributes.put("ImplicitObjectBoundNoNullDefault", SKIP); + expectedProblemAttributes.put("ImportAmbiguous", SKIP); + expectedProblemAttributes.put("ImportInheritedNameHidesEnclosingName", SKIP); + expectedProblemAttributes.put("ImportInternalNameProvided", SKIP); + expectedProblemAttributes.put("ImportNotFound", SKIP); + expectedProblemAttributes.put("ImportNotVisible", SKIP); + expectedProblemAttributes.put("IncompatibleExceptionInInheritedMethodThrowsClause", SKIP); + expectedProblemAttributes.put("IncompatibleExceptionInThrowsClause", SKIP); + expectedProblemAttributes.put("IncompatibleExceptionInThrowsClauseForNonInheritedInterfaceMethod", new ProblemAttributes(JavaCore.COMPILER_PB_INCOMPATIBLE_NON_INHERITED_INTERFACE_METHOD)); + expectedProblemAttributes.put("IncompatibleReturnType", SKIP); + expectedProblemAttributes.put("IncompatibleReturnTypeForNonInheritedInterfaceMethod", new ProblemAttributes(JavaCore.COMPILER_PB_INCOMPATIBLE_NON_INHERITED_INTERFACE_METHOD)); + expectedProblemAttributes.put("IncompatibleTypesInConditionalOperator", SKIP); + expectedProblemAttributes.put("IncompatibleTypesInEqualityOperator", SKIP); + expectedProblemAttributes.put("IncompatibleTypesInForeach", SKIP); + expectedProblemAttributes.put("IncompatibleLambdaParameterType", SKIP); + expectedProblemAttributes.put("IncompatibleMethodReference", SKIP); + expectedProblemAttributes.put("IncorrectArityForParameterizedConstructor", SKIP); + expectedProblemAttributes.put("IncorrectArityForParameterizedMethod", SKIP); + 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)); + expectedProblemAttributes.put("InheritedDefaultMethodConflictsWithOtherInherited", SKIP); + expectedProblemAttributes.put("InheritedFieldHidesEnclosingName", SKIP); + expectedProblemAttributes.put("InheritedIncompatibleReturnType", SKIP); + expectedProblemAttributes.put("InheritedMethodHidesEnclosingName", SKIP); + expectedProblemAttributes.put("InheritedMethodReducesVisibility", SKIP); + expectedProblemAttributes.put("InheritedParameterLackingNonNullAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED)); + expectedProblemAttributes.put("InheritedTypeHidesEnclosingName", SKIP); + expectedProblemAttributes.put("InitializerMustCompleteNormally", SKIP); + expectedProblemAttributes.put("InstanceFieldDuringConstructorInvocation", SKIP); + expectedProblemAttributes.put("InstanceMethodDuringConstructorInvocation", SKIP); + expectedProblemAttributes.put("InterfaceAmbiguous", SKIP); + expectedProblemAttributes.put("InterfaceCannotHaveConstructors", SKIP); + expectedProblemAttributes.put("InterfaceCannotHaveInitializers", SKIP); + expectedProblemAttributes.put("InterfaceInheritedNameHidesEnclosingName", SKIP); + expectedProblemAttributes.put("InterfaceInternalNameProvided", SKIP); + expectedProblemAttributes.put("InterfaceNotFound", SKIP); + expectedProblemAttributes.put("InterfaceNotFunctionalInterface", SKIP); + expectedProblemAttributes.put("InterfaceNotVisible", SKIP); + expectedProblemAttributes.put("InterfaceStaticMethodInvocationNotBelow18", SKIP); + expectedProblemAttributes.put("InterfaceSuperInvocationNotBelow18", SKIP); + expectedProblemAttributes.put("InternalTypeNameProvided", SKIP); + expectedProblemAttributes.put("IntersectionCastNotBelow18", SKIP); + expectedProblemAttributes.put("InvalidAnnotationMemberType", SKIP); + expectedProblemAttributes.put("InvalidArrayConstructorReference", SKIP); + expectedProblemAttributes.put("InvalidBinary", SKIP); + expectedProblemAttributes.put("InvalidBreak", SKIP); + expectedProblemAttributes.put("InvalidCatchBlockSequence", SKIP); + expectedProblemAttributes.put("InvalidCharacterConstant", SKIP); + expectedProblemAttributes.put("InvalidClassInstantiation", SKIP); + expectedProblemAttributes.put("InvalidContinue", SKIP); + expectedProblemAttributes.put("InvalidDigit", SKIP); + expectedProblemAttributes.put("InvalidEncoding", SKIP); + expectedProblemAttributes.put("InvalidEscape", SKIP); + expectedProblemAttributes.put("InvalidExplicitConstructorCall", SKIP); + expectedProblemAttributes.put("InvalidExpressionAsStatement", SKIP); + expectedProblemAttributes.put("InvalidFileNameForPackageAnnotations", SKIP); + expectedProblemAttributes.put("InvalidFloat", SKIP); + expectedProblemAttributes.put("InvalidHexa", SKIP); + expectedProblemAttributes.put("InvalidHighSurrogate", SKIP); + expectedProblemAttributes.put("InvalidInput", SKIP); + expectedProblemAttributes.put("InvalidLowSurrogate", SKIP); + expectedProblemAttributes.put("InvalidLocationForModifiers", SKIP); + expectedProblemAttributes.put("InvalidNullToSynchronized", SKIP); + expectedProblemAttributes.put("InvalidOctal", SKIP); + expectedProblemAttributes.put("InvalidOpensStatement", SKIP); + expectedProblemAttributes.put("InvalidOperator", SKIP); + expectedProblemAttributes.put("InvalidParameterizedExceptionType", SKIP); + expectedProblemAttributes.put("InvalidParenthesizedExpression", SKIP); + expectedProblemAttributes.put("InvalidServiceIntfType", SKIP); + expectedProblemAttributes.put("InvalidServiceImplType", SKIP); + expectedProblemAttributes.put("InvalidTypeArguments", SKIP); + expectedProblemAttributes.put("InvalidTypeExpression", SKIP); + expectedProblemAttributes.put("InvalidTypeForCollection", SKIP); + expectedProblemAttributes.put("InvalidTypeForCollectionTarget14", SKIP); + expectedProblemAttributes.put("InvalidTypeForStaticImport", SKIP); + expectedProblemAttributes.put("InvalidTypeToSynchronized", SKIP); + 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); + expectedProblemAttributes.put("InvalidUsageOfForeachStatements", SKIP); + expectedProblemAttributes.put("InvalidUsageOfReceiverAnnotations", SKIP); + expectedProblemAttributes.put("InvalidUsageOfStaticImports", SKIP); + expectedProblemAttributes.put("InvalidUsageOfTypeAnnotations", SKIP); + expectedProblemAttributes.put("InvalidUsageOfTypeArguments", SKIP); + expectedProblemAttributes.put("InvalidUsageOfTypeParameters", SKIP); + expectedProblemAttributes.put("InvalidUsageOfTypeParametersForAnnotationDeclaration", SKIP); + expectedProblemAttributes.put("InvalidUsageOfTypeParametersForEnumDeclaration", SKIP); + expectedProblemAttributes.put("InvalidUsageOfVarargs", SKIP); + expectedProblemAttributes.put("InvalidUsageOfWildcard", SKIP); + expectedProblemAttributes.put("InvalidVoidExpression", SKIP); + expectedProblemAttributes.put("IsClassPathCorrect", SKIP); + expectedProblemAttributes.put("JavadocAmbiguousConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocAmbiguousField", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocAmbiguousMethod", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocAmbiguousMethodReference", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocAmbiguousType", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateParamName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateProvidesTag", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateReturnTag", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateTag", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateThrowsClassName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocDuplicateUsesTag", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocEmptyReturnTag", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocGenericConstructorTypeArgumentMismatch", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocGenericMethodTypeArgumentMismatch", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocHiddenReference", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocIncorrectArityForParameterizedConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocIncorrectArityForParameterizedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInheritedFieldHidesEnclosingName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInheritedMethodHidesEnclosingName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInheritedNameHidesEnclosingTypeName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInternalTypeNameProvided", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidMemberTypeQualification", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidModuleQualification", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidParamName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidParamTagName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidParamTagTypeParameter", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidProvidesClass", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidProvidesClassName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidSeeArgs", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidSeeHref", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidSeeReference", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidSeeUrlReference", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidTag", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidThrowsClass", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidThrowsClassName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidUsesClass", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidUsesClassName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocInvalidValueReference", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMalformedSeeReference", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMessagePrefix", SKIP); + expectedProblemAttributes.put("JavadocMissing", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS)); + expectedProblemAttributes.put("JavadocMissingHashCharacter", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingIdentifier", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingParamName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingParamTag", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS)); + expectedProblemAttributes.put("JavadocMissingProvidesClass", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingProvidesClassName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingProvidesTag", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS)); + expectedProblemAttributes.put("JavadocMissingReturnTag", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS)); + expectedProblemAttributes.put("JavadocMissingSeeReference", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingTagDescription", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingThrowsClassName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingThrowsTag", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS)); + expectedProblemAttributes.put("JavadocMissingUsesClass", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingUsesClassName", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocMissingUsesTag", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS)); + expectedProblemAttributes.put("JavadocNoMessageSendOnArrayType", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocNoMessageSendOnBaseType", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocNonGenericConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocNonGenericMethod", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocNonStaticTypeFromStaticInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocNotAccessibleType", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocNotVisibleConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + 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("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)); + expectedProblemAttributes.put("JavadocUndefinedField", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocUndefinedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocUndefinedType", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocUnexpectedTag", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocUnexpectedText", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocUnterminatedInlineTag", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + expectedProblemAttributes.put("JavadocUsingDeprecatedConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_INVALID_JAVADOC)); + 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("LambdaDescriptorMentionsUnmentionable", SKIP); + expectedProblemAttributes.put("LambdaExpressionNotBelow18", SKIP); + expectedProblemAttributes.put("LambdaRedeclaresArgument", SKIP); + expectedProblemAttributes.put("LambdaRedeclaresLocal", SKIP); + expectedProblemAttributes.put("LambdaShapeComputationError", 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("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); + expectedProblemAttributes.put("MethodNameClash", SKIP); + expectedProblemAttributes.put("MethodNameClashHidden", SKIP); + expectedProblemAttributes.put("MethodReducesVisibility", SKIP); + expectedProblemAttributes.put("MethodReferenceNotBelow18", SKIP); + expectedProblemAttributes.put("MethodReferenceSwingsBothWays", SKIP); + expectedProblemAttributes.put("MethodRequiresBody", SKIP); + expectedProblemAttributes.put("MethodReturnsVoid", SKIP); + expectedProblemAttributes.put("MethodVarargsArgumentNeedCast", new ProblemAttributes(JavaCore.COMPILER_PB_VARARGS_ARGUMENT_NEED_CAST)); + expectedProblemAttributes.put("MisplacedTypeAnnotations", SKIP); + expectedProblemAttributes.put("MissingArgumentsForParameterizedMemberType", SKIP); + expectedProblemAttributes.put("MissingDefaultCase", new ProblemAttributes(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE)); + expectedProblemAttributes.put("MissingEnclosingInstance", SKIP); + expectedProblemAttributes.put("MissingEnclosingInstanceForConstructorCall", SKIP); + expectedProblemAttributes.put("MissingEnumConstantCase", new ProblemAttributes(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH)); + expectedProblemAttributes.put("MissingEnumConstantCaseDespiteDefault", new ProblemAttributes(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH)); + expectedProblemAttributes.put("MissingEnumDefaultCase", new ProblemAttributes(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE)); + expectedProblemAttributes.put("MissingNonNullByDefaultAnnotationOnPackage", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION)); + expectedProblemAttributes.put("MissingNonNullByDefaultAnnotationOnType", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION)); + expectedProblemAttributes.put("MissingNullAnnotationImplicitlyUsed", SKIP); + expectedProblemAttributes.put("MissingOverrideAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION)); + expectedProblemAttributes.put("MissingOverrideAnnotationForInterfaceMethodImplementation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION)); + expectedProblemAttributes.put("MissingRequiresTransitiveForTypeInAPI", new ProblemAttributes(JavaCore.COMPILER_PB_API_LEAKS)); + expectedProblemAttributes.put("MissingReturnType", SKIP); + expectedProblemAttributes.put("MissingSemiColon", SKIP); + expectedProblemAttributes.put("MissingSerialVersion", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION)); + expectedProblemAttributes.put("MissingSynchronizedModifierInInheritedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD)); + expectedProblemAttributes.put("MissingTypeInConstructor", SKIP); + expectedProblemAttributes.put("MissingTypeInLambda", SKIP); + expectedProblemAttributes.put("UnterminatedTextBlock", SKIP); + expectedProblemAttributes.put("MissingTypeInMethod", SKIP); + expectedProblemAttributes.put("MissingValueForAnnotationMember", SKIP); + expectedProblemAttributes.put("MissingValueFromLambda", SKIP); + expectedProblemAttributes.put("MultiCatchNotBelow17", SKIP); + expectedProblemAttributes.put("MultipleFunctionalInterfaces", SKIP); + expectedProblemAttributes.put("StaticInterfaceMethodNotBelow18", SKIP); + expectedProblemAttributes.put("MustDefineEitherDimensionExpressionsOrInitializer", SKIP); + expectedProblemAttributes.put("MustSpecifyPackage", SKIP); + expectedProblemAttributes.put("NativeMethodsCannotBeStrictfp", SKIP); + expectedProblemAttributes.put("NeedToEmulateConstructorAccess", new ProblemAttributes(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION)); + expectedProblemAttributes.put("NeedToEmulateFieldReadAccess", new ProblemAttributes(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION)); + expectedProblemAttributes.put("NeedToEmulateFieldWriteAccess", new ProblemAttributes(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION)); + expectedProblemAttributes.put("NeedToEmulateMethodAccess", new ProblemAttributes(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION)); + expectedProblemAttributes.put("NestedServiceImpl", SKIP); + expectedProblemAttributes.put("NoAdditionalBoundAfterTypeVariable", SKIP); + expectedProblemAttributes.put("NoFieldOnBaseType", SKIP); + expectedProblemAttributes.put("NoGenericLambda", SKIP); + expectedProblemAttributes.put("NoImplicitStringConversionForCharArrayExpression", new ProblemAttributes(JavaCore.COMPILER_PB_CHAR_ARRAY_IN_STRING_CONCATENATION)); + expectedProblemAttributes.put("NoMessageSendOnArrayType", SKIP); + expectedProblemAttributes.put("NoMessageSendOnBaseType", SKIP); + expectedProblemAttributes.put("NoSuperInInterfaceContext", SKIP); + expectedProblemAttributes.put("NonBlankFinalLocalAssignment", SKIP); + expectedProblemAttributes.put("NonConstantExpression", SKIP); + expectedProblemAttributes.put("NonDenotableTypeArgumentForAnonymousDiamond", SKIP); + expectedProblemAttributes.put("NonExternalizedStringLiteral", new ProblemAttributes(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL)); + expectedProblemAttributes.put("NonGenericConstructor", SKIP); + expectedProblemAttributes.put("NonGenericMethod", SKIP); + expectedProblemAttributes.put("NonGenericType", SKIP); + expectedProblemAttributes.put("NonNullDefaultDetailIsNotEvaluated", SKIP); + expectedProblemAttributes.put("NonNullExpressionComparisonYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("NonNullSpecdFieldComparisonYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("NonNullLocalVariableComparisonYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("NonNullMessageSendComparisonYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("NonNullTypeVariableFromLegacyMethod", new ProblemAttributes(JavaCore.COMPILER_PB_NONNULL_TYPEVAR_FROM_LEGACY_INVOCATION)); + expectedProblemAttributes.put("NonNullMethodTypeVariableFromLegacyMethod", new ProblemAttributes(JavaCore.COMPILER_PB_NONNULL_TYPEVAR_FROM_LEGACY_INVOCATION)); + expectedProblemAttributes.put("NonPublicTypeInAPI", new ProblemAttributes(JavaCore.COMPILER_PB_API_LEAKS)); + expectedProblemAttributes.put("NonStaticAccessToStaticField", new ProblemAttributes(JavaCore.COMPILER_PB_STATIC_ACCESS_RECEIVER)); + expectedProblemAttributes.put("NonStaticAccessToStaticMethod", new ProblemAttributes(JavaCore.COMPILER_PB_STATIC_ACCESS_RECEIVER)); + expectedProblemAttributes.put("NonStaticContextForEnumMemberType", SKIP); + expectedProblemAttributes.put("NonStaticFieldFromStaticInvocation", SKIP); + expectedProblemAttributes.put("NonStaticOrAlienTypeReceiver", SKIP); + expectedProblemAttributes.put("NonStaticTypeFromStaticInvocation", SKIP); + expectedProblemAttributes.put("NotAnnotationType", SKIP); + expectedProblemAttributes.put("NotAccessibleConstructor", SKIP); + expectedProblemAttributes.put("NotAccessibleField", SKIP); + expectedProblemAttributes.put("NotAccessibleMethod", SKIP); + expectedProblemAttributes.put("NotAccessibleType", SKIP); + expectedProblemAttributes.put("NotAccessiblePackage", SKIP); + expectedProblemAttributes.put("NotExportedTypeInAPI", new ProblemAttributes(JavaCore.COMPILER_PB_API_LEAKS)); + expectedProblemAttributes.put("ConflictingPackageFromModules", SKIP); + expectedProblemAttributes.put("ConflictingPackageFromOtherModules", SKIP); + expectedProblemAttributes.put("NotVisibleConstructor", SKIP); + expectedProblemAttributes.put("NotVisibleConstructorInDefaultConstructor", SKIP); + expectedProblemAttributes.put("NotVisibleConstructorInImplicitConstructorCall", SKIP); + expectedProblemAttributes.put("NotVisibleField", SKIP); + expectedProblemAttributes.put("NotVisibleMethod", SKIP); + expectedProblemAttributes.put("NotVisibleType", SKIP); + expectedProblemAttributes.put("NullableFieldReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE)); + expectedProblemAttributes.put("NullAnnotationAtQualifyingType", SKIP); + expectedProblemAttributes.put("NullAnnotationUnsupportedLocation", SKIP); + expectedProblemAttributes.put("NullAnnotationUnsupportedLocationAtType", SKIP); + expectedProblemAttributes.put("NullityMismatchAgainstFreeTypeVariable", new ProblemAttributes(JavaCore.COMPILER_PB_PESSIMISTIC_NULL_ANALYSIS_FOR_FREE_TYPE_VARIABLES)); + expectedProblemAttributes.put("NullityMismatchingTypeAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("NullityMismatchingTypeAnnotationSuperHint", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("NullityMismatchTypeArgument", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("NullityUncheckedTypeAnnotationDetail", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION)); + expectedProblemAttributes.put("NullityUncheckedTypeAnnotationDetailSuperHint", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION)); + expectedProblemAttributes.put("NullExpressionReference", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_REFERENCE)); + expectedProblemAttributes.put("NullLocalVariableComparisonYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("NullLocalVariableInstanceofYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("NullLocalVariableReference", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_REFERENCE)); + expectedProblemAttributes.put("NullNotCompatibleToFreeTypeVariable", new ProblemAttributes(JavaCore.COMPILER_PB_PESSIMISTIC_NULL_ANALYSIS_FOR_FREE_TYPE_VARIABLES)); + expectedProblemAttributes.put("NullSourceString", SKIP); + expectedProblemAttributes.put("NullUnboxing", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_REFERENCE)); + expectedProblemAttributes.put("NumericValueOutOfRange", SKIP); + expectedProblemAttributes.put("ObjectCannotBeGeneric", SKIP); + expectedProblemAttributes.put("ObjectCannotHaveSuperTypes", SKIP); + expectedProblemAttributes.put("ObjectHasNoSuperclass", SKIP); + expectedProblemAttributes.put("ObjectMustBeClass", SKIP); + expectedProblemAttributes.put("OuterLocalMustBeEffectivelyFinal", SKIP); + expectedProblemAttributes.put("OuterLocalMustBeFinal", SKIP); + expectedProblemAttributes.put("OverridingDeprecatedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("OverridingDeprecatedSinceVersionMethod", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("OverridingTerminallyDeprecatedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("OverridingTerminallyDeprecatedSinceVersionMethod", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("OverridingMethodWithoutSuperInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_OVERRIDING_METHOD_WITHOUT_SUPER_INVOCATION)); + expectedProblemAttributes.put("OverridingNonVisibleMethod", new ProblemAttributes(JavaCore.COMPILER_PB_OVERRIDING_PACKAGE_DEFAULT_METHOD)); + expectedProblemAttributes.put("PackageCollidesWithType", SKIP); + expectedProblemAttributes.put("PackageDoesNotExistOrIsEmpty", SKIP); + expectedProblemAttributes.put("PackageIsNotExpectedPackage", SKIP); + expectedProblemAttributes.put("ParameterAssignment", new ProblemAttributes(JavaCore.COMPILER_PB_PARAMETER_ASSIGNMENT)); + expectedProblemAttributes.put("ParameterLackingNonNullAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED)); + expectedProblemAttributes.put("ParameterLackingNullableAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("ParameterMismatch", SKIP); + expectedProblemAttributes.put("ParameterizedConstructorArgumentTypeMismatch", SKIP); + expectedProblemAttributes.put("ParameterizedMethodArgumentTypeMismatch", SKIP); + expectedProblemAttributes.put("ParsingError", SKIP); + expectedProblemAttributes.put("ParsingErrorDeleteToken", SKIP); + expectedProblemAttributes.put("ParsingErrorDeleteTokens", SKIP); + expectedProblemAttributes.put("ParsingErrorInsertToComplete", SKIP); + expectedProblemAttributes.put("ParsingErrorInsertToCompletePhrase", SKIP); + expectedProblemAttributes.put("ParsingErrorInsertToCompleteScope", SKIP); + expectedProblemAttributes.put("ParsingErrorInsertTokenAfter", SKIP); + expectedProblemAttributes.put("ParsingErrorInsertTokenBefore", SKIP); + expectedProblemAttributes.put("ParsingErrorInvalidToken", SKIP); + expectedProblemAttributes.put("ParsingErrorMergeTokens", SKIP); + expectedProblemAttributes.put("ParsingErrorMisplacedConstruct", SKIP); + expectedProblemAttributes.put("ParsingErrorNoSuggestion", SKIP); + expectedProblemAttributes.put("ParsingErrorNoSuggestionForTokens", SKIP); + expectedProblemAttributes.put("ParsingErrorOnKeyword", SKIP); + expectedProblemAttributes.put("ParsingErrorOnKeywordNoSuggestion", SKIP); + expectedProblemAttributes.put("ParsingErrorReplaceTokens", SKIP); + expectedProblemAttributes.put("ParsingErrorUnexpectedEOF", SKIP); + expectedProblemAttributes.put("PatternVariableNotInScope", SKIP); + expectedProblemAttributes.put("PatternVariableRedefined", SKIP); + expectedProblemAttributes.put("PatternSubtypeOfExpression", SKIP); + expectedProblemAttributes.put("IllegalModifierForPatternVariable", SKIP); + expectedProblemAttributes.put("PatternVariableRedeclared", 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("PotentiallyUnclosedCloseable", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE)); + expectedProblemAttributes.put("PotentiallyUnclosedCloseableAtExit", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE)); + expectedProblemAttributes.put("PotentialNullExpressionReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE)); + expectedProblemAttributes.put("PotentialNullLocalVariableReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE)); + expectedProblemAttributes.put("PotentialNullUnboxing", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE)); + expectedProblemAttributes.put("PotentialNullMessageSendReference", new ProblemAttributes(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE)); + expectedProblemAttributes.put("ProblemNotAnalysed", new ProblemAttributes(JavaCore.COMPILER_PB_SUPPRESS_WARNINGS_NOT_FULLY_ANALYSED)); + expectedProblemAttributes.put("ProviderMethodOrConstructorRequiredForServiceImpl", SKIP); + expectedProblemAttributes.put("PublicClassMustMatchFileName", SKIP); + expectedProblemAttributes.put("RawMemberTypeCannotBeParameterized", SKIP); + expectedProblemAttributes.put("RawTypeReference", new ProblemAttributes(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE)); + 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("RedundantNullAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION)); + expectedProblemAttributes.put("RedundantNullCheckAgainstNonNullType", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("RedundantNullCheckOnConstNonNullField", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("RedundantNullCheckOnField", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("RedundantNullCheckOnNonNullExpression", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("RedundantNullCheckOnNonNullSpecdField", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("RedundantNullCheckOnNonNullLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("RedundantNullCheckOnNonNullMessageSend", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("RedundantNullCheckOnNullLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("RedundantNullCheckOnSpecdNonNullLocalVariable", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationModule", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationPackage", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationType", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationMethod", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationLocal", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION)); + expectedProblemAttributes.put("RedundantNullDefaultAnnotationField", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION)); + expectedProblemAttributes.put("RedundantSuperinterface", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE)); + expectedProblemAttributes.put("ReferenceExpressionParameterNullityMismatch", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("ReferenceExpressionParameterNullityUnchecked", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION)); + expectedProblemAttributes.put("ReferenceExpressionReturnNullRedef", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("ReferenceExpressionReturnNullRedefUnchecked", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION)); + expectedProblemAttributes.put("ReferenceToForwardField", SKIP); + expectedProblemAttributes.put("ReferenceToForwardTypeVariable", SKIP); + expectedProblemAttributes.put("RepeatableAnnotationTypeIsDocumented", SKIP); + expectedProblemAttributes.put("RepeatableAnnotationTypeIsInherited", SKIP); + expectedProblemAttributes.put("RepeatableAnnotationTypeTargetMismatch", SKIP); + expectedProblemAttributes.put("RepeatableAnnotationWithRepeatingContainerAnnotation", SKIP); + expectedProblemAttributes.put("RepeatedAnnotationWithContainerAnnotation", SKIP); + expectedProblemAttributes.put("RequiredNonNullButProvidedFreeTypeVariable", new ProblemAttributes(JavaCore.COMPILER_PB_PESSIMISTIC_NULL_ANALYSIS_FOR_FREE_TYPE_VARIABLES)); + expectedProblemAttributes.put("RequiredNonNullButProvidedNull", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("RequiredNonNullButProvidedPotentialNull", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_ANNOTATION_INFERENCE_CONFLICT)); + expectedProblemAttributes.put("RequiredNonNullButProvidedUnknown", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION)); + expectedProblemAttributes.put("RequiredNonNullButProvidedSpecdNullable", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION)); + expectedProblemAttributes.put("ResourceHasToImplementAutoCloseable", SKIP); + expectedProblemAttributes.put("ReturnTypeAmbiguous", SKIP); + expectedProblemAttributes.put("ReturnTypeCannotBeVoidArray", SKIP); + expectedProblemAttributes.put("ReturnTypeInheritedNameHidesEnclosingName", SKIP); + expectedProblemAttributes.put("ReturnTypeInternalNameProvided", SKIP); + expectedProblemAttributes.put("ReturnTypeMismatch", SKIP); + expectedProblemAttributes.put("ReturnTypeNotFound", SKIP); + expectedProblemAttributes.put("ReturnTypeNotVisible", SKIP); + expectedProblemAttributes.put("SafeVarargsOnFixedArityMethod", SKIP); + expectedProblemAttributes.put("SafeVarargsOnNonFinalInstanceMethod", SKIP); + expectedProblemAttributes.put("ServiceImplDefaultConstructorNotPublic", SKIP); + expectedProblemAttributes.put("ServiceImplNotDefinedByModule", SKIP); + expectedProblemAttributes.put("ShouldImplementHashcode", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_HASHCODE_METHOD)); + expectedProblemAttributes.put("ShouldReturnValue", SKIP); + expectedProblemAttributes.put("ShouldReturnValueHintMissingDefault", SKIP); + expectedProblemAttributes.put("SpecdNonNullLocalVariableComparisonYieldsFalse", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("StaticInheritedMethodConflicts", SKIP); + expectedProblemAttributes.put("StaticMemberOfParameterizedType", SKIP); + expectedProblemAttributes.put("StaticMethodRequested", SKIP); + expectedProblemAttributes.put("StaticMethodShouldBeAccessedStatically", SKIP); + expectedProblemAttributes.put("StringConstantIsExceedingUtf8Limit", SKIP); + expectedProblemAttributes.put("SuperAccessCannotBypassDirectSuper", SKIP); + expectedProblemAttributes.put("SuperCallCannotBypassOverride", 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("SwitchOnEnumNotBelow15", SKIP); + expectedProblemAttributes.put("SwitchOnStringsNotBelow17", SKIP); + expectedProblemAttributes.put("TargetTypeNotAFunctionalInterface", SKIP); + expectedProblemAttributes.put("Task", SKIP); + expectedProblemAttributes.put("ThisInStaticContext", SKIP); + expectedProblemAttributes.put("ThisSuperDuringConstructorInvocation", SKIP); + expectedProblemAttributes.put("ToleratedMisplacedTypeAnnotations", SKIP); + expectedProblemAttributes.put("TooManyArgumentSlots", SKIP); + expectedProblemAttributes.put("TooManyArrayDimensions", SKIP); + expectedProblemAttributes.put("TooManyBytesForStringConstant", SKIP); + expectedProblemAttributes.put("TooManyConstantsInConstantPool", SKIP); + expectedProblemAttributes.put("TooManyFields", SKIP); + expectedProblemAttributes.put("TooManyLocalVariableSlots", SKIP); + expectedProblemAttributes.put("TooManyMethods", SKIP); + expectedProblemAttributes.put("TooManyParametersForSyntheticMethod", SKIP); + expectedProblemAttributes.put("TooManySyntheticArgumentSlots", SKIP); + expectedProblemAttributes.put("TypeAnnotationAtQualifiedName", SKIP); + expectedProblemAttributes.put("TypeArgumentMismatch", SKIP); + expectedProblemAttributes.put("TypeArgumentsForRawGenericConstructor", SKIP); + expectedProblemAttributes.put("TypeArgumentsForRawGenericMethod", SKIP); + expectedProblemAttributes.put("TypeCollidesWithPackage", SKIP); + expectedProblemAttributes.put("TypeHidingType", new ProblemAttributes(JavaCore.COMPILER_PB_TYPE_PARAMETER_HIDING)); + expectedProblemAttributes.put("TypeHidingTypeParameterFromMethod", new ProblemAttributes(JavaCore.COMPILER_PB_TYPE_PARAMETER_HIDING)); + expectedProblemAttributes.put("TypeHidingTypeParameterFromType", new ProblemAttributes(JavaCore.COMPILER_PB_TYPE_PARAMETER_HIDING)); + expectedProblemAttributes.put("TypeMismatch", SKIP); + expectedProblemAttributes.put("TypeMissingDeprecatedAnnotation", new ProblemAttributes(JavaCore.COMPILER_PB_MISSING_DEPRECATED_ANNOTATION)); + expectedProblemAttributes.put("TypeParameterHidingType", new ProblemAttributes(JavaCore.COMPILER_PB_TYPE_PARAMETER_HIDING)); + expectedProblemAttributes.put("UnboxingConversion", new ProblemAttributes(JavaCore.COMPILER_PB_AUTOBOXING)); + expectedProblemAttributes.put("UncheckedAccessOfValueOfFreeTypeVariable", new ProblemAttributes(JavaCore.COMPILER_PB_PESSIMISTIC_NULL_ANALYSIS_FOR_FREE_TYPE_VARIABLES)); + expectedProblemAttributes.put("UnclosedCloseable", new ProblemAttributes(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE)); + expectedProblemAttributes.put("UnclosedCloseableAtExit", new ProblemAttributes(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE)); + expectedProblemAttributes.put("UndefinedAnnotationMember", SKIP); + expectedProblemAttributes.put("UndefinedConstructor", SKIP); + expectedProblemAttributes.put("UndefinedConstructorInDefaultConstructor", SKIP); + expectedProblemAttributes.put("UndefinedConstructorInImplicitConstructorCall", SKIP); + expectedProblemAttributes.put("UndefinedField", SKIP); + expectedProblemAttributes.put("UndefinedLabel", SKIP); + expectedProblemAttributes.put("UndefinedMethod", SKIP); + expectedProblemAttributes.put("UndefinedModule", SKIP); + expectedProblemAttributes.put("UndefinedModuleAddReads", SKIP); + 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("UninitializedBlankFinalFieldHintMissingDefault", SKIP); + expectedProblemAttributes.put("UninitializedFreeTypeVariableField", SKIP); + expectedProblemAttributes.put("UninitializedFreeTypeVariableFieldHintMissingDefault", SKIP); + expectedProblemAttributes.put("UninitializedLocalVariable", SKIP); + expectedProblemAttributes.put("UninitializedLocalVariableHintMissingDefault", SKIP); + expectedProblemAttributes.put("UninitializedNonNullField", SKIP); + expectedProblemAttributes.put("UninitializedNonNullFieldHintMissingDefault", SKIP); + expectedProblemAttributes.put("UninternedIdentityComparison", SKIP); + expectedProblemAttributes.put("UnlikelyCollectionMethodArgumentType", new ProblemAttributes(JavaCore.COMPILER_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE)); + expectedProblemAttributes.put("UnlikelyEqualsArgumentType", new ProblemAttributes(JavaCore.COMPILER_PB_UNLIKELY_EQUALS_ARGUMENT_TYPE)); + expectedProblemAttributes.put("UnmatchedBracket", SKIP); + expectedProblemAttributes.put("UnnamedPackageInNamedModule", SKIP); + expectedProblemAttributes.put("UnnecessaryArgumentCast", SKIP); + expectedProblemAttributes.put("UnnecessaryCast", new ProblemAttributes(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK)); + expectedProblemAttributes.put("UnnecessaryElse", new ProblemAttributes(JavaCore.COMPILER_PB_UNNECESSARY_ELSE)); + expectedProblemAttributes.put("UnnecessaryInstanceof", new ProblemAttributes(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK)); + expectedProblemAttributes.put("UnnecessaryNLSTag", new ProblemAttributes(JavaCore.COMPILER_PB_NON_NLS_STRING_LITERAL)); + expectedProblemAttributes.put("UnnecessaryNullCaseInSwitchOverNonNull", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK)); + expectedProblemAttributes.put("UnqualifiedFieldAccess", new ProblemAttributes(JavaCore.COMPILER_PB_UNQUALIFIED_FIELD_ACCESS)); + expectedProblemAttributes.put("UnreachableCatch", SKIP); + expectedProblemAttributes.put("UnresolvedVariable", SKIP); + expectedProblemAttributes.put("UnsafeCast", SKIP); + expectedProblemAttributes.put("UnsafeElementTypeConversion", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); + expectedProblemAttributes.put("UnsafeGenericArrayForVarargs", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); + expectedProblemAttributes.put("UnsafeGenericCast", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); + expectedProblemAttributes.put("UnsafeNullnessCast", new ProblemAttributes(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION)); + expectedProblemAttributes.put("UnsafeRawConstructorInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); + expectedProblemAttributes.put("UnsafeRawFieldAssignment", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); + expectedProblemAttributes.put("UnsafeRawGenericConstructorInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); + expectedProblemAttributes.put("UnsafeRawGenericMethodInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); + expectedProblemAttributes.put("UnsafeRawMethodInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); + expectedProblemAttributes.put("UnsafeReturnTypeOverride", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); + expectedProblemAttributes.put("UnsafeTypeConversion", new ProblemAttributes(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION)); + expectedProblemAttributes.put("UnstableAutoModuleName", new ProblemAttributes(JavaCore.COMPILER_PB_UNSTABLE_AUTO_MODULE_NAME)); + expectedProblemAttributes.put("ConflictingPackageInModules", SKIP); + expectedProblemAttributes.put("UnterminatedComment", SKIP); + expectedProblemAttributes.put("UnterminatedString", SKIP); + expectedProblemAttributes.put("UnusedConstructorDeclaredThrownException", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION)); + expectedProblemAttributes.put("UnusedImport", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_IMPORT)); + expectedProblemAttributes.put("UnusedLabel", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_LABEL)); + expectedProblemAttributes.put("UnusedMethodDeclaredThrownException", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION)); + expectedProblemAttributes.put("UnusedObjectAllocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_OBJECT_ALLOCATION)); + expectedProblemAttributes.put("UnusedPrivateConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); + expectedProblemAttributes.put("UnusedPrivateField", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); + expectedProblemAttributes.put("UnusedPrivateMethod", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); + expectedProblemAttributes.put("UnusedPrivateType", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER)); + expectedProblemAttributes.put("UnusedTypeArgumentsForConstructorInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_TYPE_ARGUMENTS_FOR_METHOD_INVOCATION)); + expectedProblemAttributes.put("UnusedTypeParameter", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_TYPE_PARAMETER)); + expectedProblemAttributes.put("UnusedTypeArgumentsForMethodInvocation", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_TYPE_ARGUMENTS_FOR_METHOD_INVOCATION)); + expectedProblemAttributes.put("UnusedWarningToken", new ProblemAttributes(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN)); + expectedProblemAttributes.put("UseAssertAsAnIdentifier", new ProblemAttributes(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER)); + expectedProblemAttributes.put("UseEnumAsAnIdentifier", new ProblemAttributes(JavaCore.COMPILER_PB_ENUM_IDENTIFIER)); + expectedProblemAttributes.put("IllegalUseOfUnderscoreAsAnIdentifier", SKIP); + expectedProblemAttributes.put("ErrorUseOfUnderscoreAsAnIdentifier", SKIP); + expectedProblemAttributes.put("UsingDeprecatedConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedField", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedModule", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedPackage", SKIP); + expectedProblemAttributes.put("UsingDeprecatedType", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionField", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionMethod", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionModule", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionPackage", SKIP); + expectedProblemAttributes.put("UsingDeprecatedSinceVersionType", new ProblemAttributes(JavaCore.COMPILER_PB_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedField", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedMethod", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedModule", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedPackage", SKIP); + expectedProblemAttributes.put("UsingTerminallyDeprecatedType", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionConstructor", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionField", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionMethod", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionModule", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionPackage", SKIP); + expectedProblemAttributes.put("UsingTerminallyDeprecatedSinceVersionType", new ProblemAttributes(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION)); + expectedProblemAttributes.put("VarargsConflict", SKIP); + expectedProblemAttributes.put("VarargsElementTypeNotVisible", SKIP); + expectedProblemAttributes.put("VarargsElementTypeNotVisibleForConstructor", SKIP); + expectedProblemAttributes.put("VariableTypeCannotBeVoid", SKIP); + expectedProblemAttributes.put("VariableTypeCannotBeVoidArray", SKIP); + expectedProblemAttributes.put("VoidMethodReturnsValue", SKIP); + expectedProblemAttributes.put("WildcardConstructorInvocation", SKIP); + expectedProblemAttributes.put("WildcardFieldAssignment", SKIP); + expectedProblemAttributes.put("WildcardMethodInvocation", SKIP); + expectedProblemAttributes.put("illFormedParameterizationOfFunctionalInterface", SKIP); + expectedProblemAttributes.put("lambdaParameterTypeMismatched", SKIP); + expectedProblemAttributes.put("lambdaSignatureMismatched", SKIP); + expectedProblemAttributes.put("DisallowedExplicitThisParameter", SKIP); + expectedProblemAttributes.put("IllegalArrayOfUnionType", SKIP); + expectedProblemAttributes.put("IllegalArrayTypeInIntersectionCast", SKIP); + expectedProblemAttributes.put("VarCannotBeMixedWithNonVarParams", SKIP); + expectedProblemAttributes.put("VarIsNotAllowedHere", SKIP); + expectedProblemAttributes.put("VarIsReserved", SKIP); + expectedProblemAttributes.put("VarIsReservedInFuture", SKIP); + expectedProblemAttributes.put("VarLocalCannotBeArray", SKIP); + expectedProblemAttributes.put("VarLocalCannotBeArrayInitalizers", SKIP); + expectedProblemAttributes.put("VarLocalCannotBeLambda", SKIP); + expectedProblemAttributes.put("VarLocalCannotBeMethodReference", SKIP); + expectedProblemAttributes.put("VarLocalInitializedToNull", SKIP); + expectedProblemAttributes.put("VarLocalInitializedToVoid", SKIP); + expectedProblemAttributes.put("VarLocalMultipleDeclarators", SKIP); + expectedProblemAttributes.put("VarLocalReferencesItself", SKIP); + expectedProblemAttributes.put("VarLocalTooManyBrackets", SKIP); + expectedProblemAttributes.put("VarLocalWithoutInitizalier", SKIP); + expectedProblemAttributes.put("SwitchExpressionsIncompatibleResultExpressionTypes",SKIP); + expectedProblemAttributes.put("SwitchExpressionsEmptySwitchBlock",SKIP); + expectedProblemAttributes.put("SwitchExpressionsNoResultExpression",SKIP); + expectedProblemAttributes.put("SwitchExpressionSwitchLabeledBlockCompletesNormally",SKIP); + expectedProblemAttributes.put("SwitchExpressionLastStatementCompletesNormally",SKIP); + expectedProblemAttributes.put("SwitchExpressionIllegalLastStatement",SKIP); + expectedProblemAttributes.put("SwitchExpressionTrailingSwitchLabels",SKIP); + expectedProblemAttributes.put("switchMixedCase", SKIP); + expectedProblemAttributes.put("SwitchExpressionMissingDefaultCase",SKIP); + expectedProblemAttributes.put("SwitchExpressionNotBelow12", SKIP); + expectedProblemAttributes.put("SwitchCaseLabelWithArrowNotBelow12", SKIP); + expectedProblemAttributes.put("SwitchExpressionPreviewDisabled", SKIP); + expectedProblemAttributes.put("SwitchCaseLabelWithArrowPreviewDisabled", SKIP); + expectedProblemAttributes.put("SwitchExpressionBreakMissingValue", SKIP); + expectedProblemAttributes.put("SwitchExpressionMissingEnumConstantCase", SKIP); + expectedProblemAttributes.put("PreviewFeatureDisabled", SKIP); + expectedProblemAttributes.put("PreviewFeatureUsed", SKIP); + expectedProblemAttributes.put("PreviewFeatureNotSupported", SKIP); + expectedProblemAttributes.put("PreviewFeaturesNotAllowed", SKIP); + expectedProblemAttributes.put("FeatureNotSupported", SKIP); + expectedProblemAttributes.put("PreviewAPIUsed", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldIncompatibleResultExpressionTypes", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldEmptySwitchBlock", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldNoResultExpression", SKIP); + expectedProblemAttributes.put("SwitchExpressionaYieldSwitchLabeledBlockCompletesNormally", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldLastStatementCompletesNormally", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldTrailingSwitchLabels", SKIP); + expectedProblemAttributes.put("SwitchPreviewMixedCase", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldMissingDefaultCase", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldMissingValue", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldMissingEnumConstantCase", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldIllegalLastStatement", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldBreakNotAllowed", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldUnqualifiedMethodWarning", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldUnqualifiedMethodError", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldOutsideSwitchExpression", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldRestrictedGeneralWarning", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldIllegalStatement", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationWarning", SKIP); + expectedProblemAttributes.put("SwitchExpressionsYieldTypeDeclarationError", SKIP); + expectedProblemAttributes.put("MultiConstantCaseLabelsNotSupported", SKIP); + expectedProblemAttributes.put("ArrowInCaseStatementsNotSupported", SKIP); + expectedProblemAttributes.put("SwitchExpressionsNotSupported", SKIP); + expectedProblemAttributes.put("SwitchExpressionsBreakOutOfSwitchExpression", SKIP); + expectedProblemAttributes.put("SwitchExpressionsContinueOutOfSwitchExpression", SKIP); + expectedProblemAttributes.put("SwitchExpressionsReturnWithinSwitchExpression", SKIP); + expectedProblemAttributes.put("RecordIllegalModifierForRecord", SKIP); + expectedProblemAttributes.put("RecordIllegalModifierForInnerRecord", SKIP); + expectedProblemAttributes.put("RecordIllegalComponentNameInRecord", SKIP); + expectedProblemAttributes.put("RecordNonStaticFieldDeclarationInRecord", SKIP); + expectedProblemAttributes.put("RecordAccessorMethodHasThrowsClause", SKIP); + expectedProblemAttributes.put("RecordCanonicalConstructorHasThrowsClause", SKIP); + expectedProblemAttributes.put("RecordCanonicalConstructorVisibilityReduced", SKIP); + expectedProblemAttributes.put("RecordMultipleCanonicalConstructors", SKIP); + expectedProblemAttributes.put("RecordCompactConstructorHasReturnStatement", SKIP); + expectedProblemAttributes.put("RecordDuplicateComponent", SKIP); + expectedProblemAttributes.put("RecordIllegalNativeModifierInRecord", SKIP); + expectedProblemAttributes.put("RecordInstanceInitializerBlockInRecord", SKIP); + expectedProblemAttributes.put("RestrictedTypeName", SKIP); + expectedProblemAttributes.put("RecordIllegalAccessorReturnType", SKIP); + expectedProblemAttributes.put("RecordAccessorMethodShouldNotBeGeneric", SKIP); + expectedProblemAttributes.put("RecordAccessorMethodShouldBePublic", SKIP); + expectedProblemAttributes.put("RecordCanonicalConstructorShouldNotBeGeneric", SKIP); + expectedProblemAttributes.put("RecordCanonicalConstructorHasReturnStatement", SKIP); + expectedProblemAttributes.put("RecordCanonicalConstructorHasExplicitConstructorCall", SKIP); + expectedProblemAttributes.put("RecordCompactConstructorHasExplicitConstructorCall", SKIP); + expectedProblemAttributes.put("RecordNestedRecordInherentlyStatic", SKIP); + expectedProblemAttributes.put("RecordAccessorMethodShouldNotBeStatic", SKIP); + expectedProblemAttributes.put("RecordCannotExtendRecord", SKIP); + expectedProblemAttributes.put("RecordComponentCannotBeVoid", SKIP); + expectedProblemAttributes.put("RecordIllegalVararg", SKIP); + expectedProblemAttributes.put("RecordStaticReferenceToOuterLocalVariable",SKIP); + expectedProblemAttributes.put("RecordCannotDefineRecordInLocalType",SKIP); + expectedProblemAttributes.put("RecordMissingExplicitConstructorCallInNonCanonicalConstructor",SKIP); + expectedProblemAttributes.put("RecordIllegalStaticModifierForLocalClassOrInterface", SKIP); + expectedProblemAttributes.put("RecordIllegalExtendedDimensionsForRecordComponent", SKIP); + expectedProblemAttributes.put("RecordIllegalModifierForLocalRecord", SKIP); + expectedProblemAttributes.put("RecordComponentsCannotHaveModifiers",SKIP); + expectedProblemAttributes.put("RecordIllegalParameterNameInCanonicalConstructor",SKIP); + expectedProblemAttributes.put("RecordIllegalExplicitFinalFieldAssignInCompactConstructor",SKIP); + expectedProblemAttributes.put("LocalStaticsIllegalVisibilityModifierForInterfaceLocalType",SKIP); + expectedProblemAttributes.put("IllegalModifierForLocalEnumDeclaration",SKIP); + expectedProblemAttributes.put("SealedMissingClassModifier", SKIP); + expectedProblemAttributes.put("SealedDisAllowedNonSealedModifierInClass", SKIP); + expectedProblemAttributes.put("SealedSuperClassDoesNotPermit", SKIP); + expectedProblemAttributes.put("SealedSuperInterfaceDoesNotPermit", SKIP); + expectedProblemAttributes.put("SealedMissingSealedModifier", SKIP); + expectedProblemAttributes.put("SealedMissingInterfaceModifier", SKIP); + expectedProblemAttributes.put("SealedDuplicateTypeInPermits", SKIP); + expectedProblemAttributes.put("SealedNotDirectSuperClass", SKIP); + expectedProblemAttributes.put("SealedPermittedTypeOutsideOfModule", SKIP); + expectedProblemAttributes.put("SealedPermittedTypeOutsideOfPackage", SKIP); + expectedProblemAttributes.put("SealedSealedTypeMissingPermits", SKIP); + expectedProblemAttributes.put("SealedInterfaceIsSealedAndNonSealed", SKIP); + expectedProblemAttributes.put("SealedDisAllowedNonSealedModifierInInterface", SKIP); + expectedProblemAttributes.put("SealedSuperInterfaceDoesNotPermit", SKIP); + expectedProblemAttributes.put("SealedNotDirectSuperInterface", SKIP); + expectedProblemAttributes.put("SealedLocalDirectSuperTypeSealed", SKIP); + expectedProblemAttributes.put("SealedSuperTypeInDifferentPackage", SKIP); + expectedProblemAttributes.put("SealedSuperTypeDisallowed", SKIP); + expectedProblemAttributes.put("SealedAnonymousClassCannotExtendSealedType", SKIP); + expectedProblemAttributes.put("LocalReferencedInGuardMustBeEffectivelyFinal", SKIP); + expectedProblemAttributes.put("SafeVarargsOnSyntheticRecordAccessor", SKIP); + expectedProblemAttributes.put("DiscouragedValueBasedTypeSynchronization", SKIP); + expectedProblemAttributes.put("ConstantWithPatternIncompatible", SKIP); + expectedProblemAttributes.put("IllegalFallthroughToPattern", SKIP); + expectedProblemAttributes.put("OnlyOnePatternCaseLabelAllowed", SKIP); + expectedProblemAttributes.put("CannotMixPatternAndDefault", SKIP); + expectedProblemAttributes.put("CannotMixNullAndNonTypePattern", SKIP); + expectedProblemAttributes.put("PatternDominated", SKIP); + expectedProblemAttributes.put("IllegalTotalPatternWithDefault", SKIP); + expectedProblemAttributes.put("EnhancedSwitchMissingDefault", SKIP); + expectedProblemAttributes.put("DuplicateTotalPattern", SKIP); + expectedProblemAttributes.put("UnexpectedTypeinSwitchPattern", SKIP); + + Map constantNamesIndex = new HashMap(); + Field[] fields = JavaCore.class.getFields(); + for (int i = 0, length = fields.length; i < length; i++) { + Field field = fields[i]; + String fieldName; + if (field.getType() == String.class && (fieldName = field.getName()).startsWith("COMPILER_PB_")) { + constantNamesIndex.put(field.get(null), fieldName); + } + } + fields = IProblem.class.getFields(); + StringBuffer failures = new StringBuffer(); + StringBuffer correctResult = new StringBuffer(70000); + Arrays.sort(fields, new Comparator() { + @Override + 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) { + int problemId = field.getInt(null), maskedProblemId = problemId & IProblem.IgnoreCategoriesMask; + if (maskedProblemId != 0 && maskedProblemId != IProblem.IgnoreCategoriesMask) { + String name = field.getName(); + ProblemAttributes expectedAttributes = (ProblemAttributes) expectedProblemAttributes.get(name); + String actualTuningOption = JavaCore.getOptionForConfigurableSeverity(problemId); + if (expectedAttributes == null) { + failures.append("missing expected problem attributes for problem " + name + "\n"); + } else if (!expectedAttributes.skip && !expectedAttributes.option.equals(actualTuningOption)) { + failures.append("tuning option mismatch for problem " + name + " (expected " + + expectedAttributes.option + ", got " + actualTuningOption + ")\n"); + } + String optionFieldName = (String) constantNamesIndex.get(actualTuningOption); + correctResult.append("\t\texpectedProblemAttributes.put(\"" + name + "\", " + + (optionFieldName != null ? "new ProblemAttributes(JavaCore." + optionFieldName + ")" + : "SKIP") + + ");\n"); + } + } + } + if (failures.length() > 0) { + System.out.println(correctResult); + System.out.println(); + } + assertEquals(failures.toString(), 0, failures.length()); + } catch (IllegalAccessException e) { + fail("could not access members"); + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java new file mode 100644 index 0000000000..387d9c6989 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java @@ -0,0 +1,3506 @@ +/******************************************************************************* + * Copyright (c) 2000, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Compliance_1_3 extends AbstractRegressionTest { +boolean docSupport = false; + +public Compliance_1_3(String name) { + super(name); +} + +/* + * Toggle compiler in mode -1.3 + */ +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + if (this.docSupport) { + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, CompilerOptions.ENABLED); + } + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + return options; +} +public static Test suite() { + return buildUniqueComplianceTestSuite(testClass(), ClassFileConstants.JDK1_3); +} +public static Class testClass() { + return Compliance_1_3.class; +} +// Use this static initializer to specify subset for tests +// All specified tests which does not belong to the class are skipped... +static { +// TESTS_NAMES = new String[] { "Bug58069" }; +// TESTS_NUMBERS = new int[] { 104 }; +// TESTS_RANGE = new int[] { 76, -1 }; +} +/* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ +@Override +protected void setUp() throws Exception { + super.setUp(); + // Javadoc disabled by default + this.docSupport = false; +} + +// test001 - moved to SuperTypeTest#test002 +// test002 - moved to SuperTypeTest#test003 +// test003 - moved to SuperTypeTest#test004 +// test004 - moved to SuperTypeTest#test005 +// test005 - moved to SuperTypeTest#test006 +// test006 - moved to SuperTypeTest#test007 +// test007 - moved to TryStatementTest#test057 +// test008 - moved to LookupTest#test074 +// test009 - moved to RuntimeTests#test1004 + +// check actualReceiverType when array type +public void test010() { + this.runConformTest( + new String[] { + "p1/Z.java", + "package p1; \n"+ + "public class Z { \n" + + " public static void main(String[] arguments) { \n"+ + " String[] s = new String[]{\"SUCCESS\" }; \n" + + " System.out.print(s.length); \n" + + " System.out.print(((String[])s.clone())[0]); \n" + + " } \n"+ + "} \n" + }, + "1SUCCESS"); +} +// test unreachable code complaints +public void test011() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " void foo() { \n"+ + " while (false); \n" + + " while (false) System.out.println(\"unreachable\"); \n" + + " do ; while (false); \n" + + " do System.out.println(\"unreachable\"); while (false); \n" + + " for (;false;); \n" + + " for (;false;) System.out.println(\"unreachable\"); \n" + + " if (false); \n" + + " if (false)System.out.println(\"unreachable\"); \n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 5)\n" + + " while (false) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 9)\n" + + " for (;false;) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. WARNING in p1\\X.java (at line 11)\n" + + " if (false)System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +// binary compatibility +public void test012() { + this.runConformTest( + new String[] { + "p1/Y.java", + "package p1; \n" + + "class Store { \n" + + " String value; \n" + + " Store(String value){ \n" + + " this.value = value; \n" + + " } \n" + + "} \n" + + "class Top { \n" + + " static String bar = \"Top.bar\"; \n" + + " String foo = \"Top.foo\"; \n" + + " Store store = new Store(\"Top.store\"); \n" + + " static Store sstore = new Store(\"Top.sstore\"); \n" + + " static Top ss = new Top(); \n" + + "} \n" + + "public class Y extends Updated { \n" + + " public static void main(String[] arguments) { \n" + + " new Y().test(); \n" + + " } \n" + + " void test() { \n" + + " System.out.print(\"*** FIELD ACCESS ***\"); \n" + + " System.out.print(\"*1* new Updated().bar: \" + new Updated().bar); \n" + + " System.out.print(\"*2* new Updated().foo: \" + new Updated().foo); \n" + + " System.out.print(\"*3* new Y().foo: \" + new Y().foo); \n" + + " System.out.print(\"*4* new Y().bar: \" + new Y().bar); \n" + + " System.out.print(\"*5* bar: \" + bar); \n" + + " System.out.print(\"*6* foo: \" + foo); \n" + + " System.out.print(\"*7* Y.bar: \" + Y.bar); \n" + + " System.out.print(\"*8* this.bar: \" + this.bar); \n" + + " System.out.print(\"*9* this.foo: \" + this.foo); \n" + + " System.out.print(\"*10* store.value: \" + store.value); \n" + + " System.out.print(\"*11* sstore.value: \" + sstore.value); \n" + + " System.out.print(\"*12* ss.sstore.value: \" + ss.sstore.value); \n" + + " } \n" + + "} \n", + "p1/Updated.java", + "package p1; \n" + + "public class Updated extends Top { \n" + + "} \n" + }, + "*** FIELD ACCESS ***" + +"*1* new Updated().bar: Top.bar" + +"*2* new Updated().foo: Top.foo" + +"*3* new Y().foo: Top.foo" + +"*4* new Y().bar: Top.bar" + +"*5* bar: Top.bar" + +"*6* foo: Top.foo" + +"*7* Y.bar: Top.bar" + +"*8* this.bar: Top.bar" + +"*9* this.foo: Top.foo" + +"*10* store.value: Top.store" + +"*11* sstore.value: Top.sstore" + +"*12* ss.sstore.value: Top.sstore"); + + this.runConformTest( + new String[] { + "p1/Updated.java", + "package p1; \n"+ + "public class Updated extends Top { \n"+ + " public static void main(String[] arguments) { \n"+ + " Y.main(arguments); \n" + + " } \n" + + " static String bar = \"Updated.bar\"; \n" + + " String foo = \"Updated.foo\"; \n" + + " Store store = new Store(\"Updated.store\"); \n" + + " static Store sstore = new Store(\"Updated.sstore\"); \n" + + " static Updated ss = new Updated(); \n" + + "} \n" + }, + "*** FIELD ACCESS ***" + +"*1* new Updated().bar: Top.bar" + +"*2* new Updated().foo: Top.foo" + +"*3* new Y().foo: Top.foo" + +"*4* new Y().bar: Top.bar" + +"*5* bar: Top.bar" + +"*6* foo: Top.foo" + +"*7* Y.bar: Top.bar" + +"*8* this.bar: Top.bar" + +"*9* this.foo: Top.foo" + +"*10* store.value: Top.store" + +"*11* sstore.value: Top.sstore" + +"*12* ss.sstore.value: Top.sstore", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} +// binary compatibility +public void test013() { + this.runConformTest( + new String[] { + "p1/Y.java", + "package p1; \n" + + "class Store { \n" + + " String value; \n" + + " Store(String value){ \n" + + " this.value = value; \n" + + " } \n" + + "} \n" + + "class Top { \n" + + " static String bar() { return \"Top.bar()\"; } \n" + + " String foo() { return \"Top.foo()\"; } \n" + + "} \n" + + "public class Y extends Updated { \n" + + " public static void main(String[] arguments) { \n" + + " new Y().test(); \n" + + " } \n" + + " void test() { \n" + + " System.out.print(\"*** METHOD ACCESS ***\"); \n" + + " System.out.print(\"*1* new Updated().bar(): \" + new Updated().bar()); \n" + + " System.out.print(\"*2* new Updated().foo(): \" + new Updated().foo()); \n" + + " System.out.print(\"*3* new Y().foo(): \" + new Y().foo()); \n" + + " System.out.print(\"*4* new Y().bar(): \" + new Y().bar()); \n" + + " System.out.print(\"*5* bar(): \" + bar()); \n" + + " System.out.print(\"*6* foo(): \" + foo()); \n" + + " System.out.print(\"*7* Y.bar(): \" + Y.bar()); \n" + + " System.out.print(\"*8* this.bar(): \" + this.bar()); \n" + + " System.out.print(\"*9* this.foo(): \" + this.foo()); \n" + + " } \n" + + "} \n", + "p1/Updated.java", + "package p1; \n" + + "public class Updated extends Top { \n" + + "} \n" + }, + "*** METHOD ACCESS ***" + +"*1* new Updated().bar(): Top.bar()" + +"*2* new Updated().foo(): Top.foo()" + +"*3* new Y().foo(): Top.foo()" + +"*4* new Y().bar(): Top.bar()" + +"*5* bar(): Top.bar()" + +"*6* foo(): Top.foo()" + +"*7* Y.bar(): Top.bar()" + +"*8* this.bar(): Top.bar()" + +"*9* this.foo(): Top.foo()"); + + this.runConformTest( + new String[] { + "p1/Updated.java", + "package p1; \n"+ + "public class Updated extends Top { \n"+ + " public static void main(String[] arguments) { \n"+ + " Y.main(arguments); \n" + + " } \n" + + " static String bar() { return \"Updated.bar()\"; } \n" + + " String foo() { return \"Updated.foo()\"; } \n" + + "} \n" + }, + "*** METHOD ACCESS ***" + +"*1* new Updated().bar(): Top.bar()" + +"*2* new Updated().foo(): Updated.foo()" + +"*3* new Y().foo(): Updated.foo()" + +"*4* new Y().bar(): Top.bar()" + +"*5* bar(): Top.bar()" + +"*6* foo(): Updated.foo()" + +"*7* Y.bar(): Top.bar()" + +"*8* this.bar(): Top.bar()" + +"*9* this.foo(): Updated.foo()", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} + +public void test014() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n" + + "class T { \n" + + " void foo(boolean b) { \n" + + " System.out.print(\"T.foo(boolean)#\"); \n" + + " } \n" + + " boolean bar = false; \n" + + " class Member { \n" + + " void display(){ System.out.print(\"T.Member#\"); } \n" + + " } \n" + + "} \n" + + "public class X { \n" + + " void foo(int i) { \n" + + " System.out.println(\"X.foo(int)#\"); \n" + + " } \n" + + " int bar; \n" + + " class Member { \n" + + " void display(){ System.out.print(\"X.Member#\"); } \n" + + " } \n" + + " public static void main(String[] arguments) { \n" + + " new X().bar(); \n" + + " } \n" + + " void bar() { \n" + + " new T() { \n" + + " { \n" + + " foo(true); \n" + + " System.out.print((boolean)bar + \"#\"); \n" + + " Member m = new Member(); \n" + + " m.display(); \n" + + " } \n" + + " }; \n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 25)\n" + + " foo(true); \n" + + " ^^^\n" + + "The method foo is defined in an inherited type and an enclosing scope\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 26)\n" + + " System.out.print((boolean)bar + \"#\"); \n" + + " ^^^\n" + + "The field bar is defined in an inherited type and an enclosing scope \n" + + "----------\n" + + "3. ERROR in p1\\X.java (at line 27)\n" + + " Member m = new Member(); \n" + + " ^^^^^^\n" + + "The type Member is defined in an inherited type and an enclosing scope\n" + + "----------\n" + + "4. ERROR in p1\\X.java (at line 27)\n" + + " Member m = new Member(); \n" + + " ^^^^^^\n" + + "The type Member is defined in an inherited type and an enclosing scope\n" + + "----------\n" + ); +} + +/* + * check handling of default abstract methods + */ +public void test015() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " C c = new C() { \n"+ + " public void doSomething(){ \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " }; \n"+ + " c.doSomething(); \n"+ + " } \n"+ + "} \n"+ + "interface I { \n"+ + " void doSomething(); \n"+ + "} \n"+ + "abstract class C implements I { \n"+ + "} \n" + }, + "SUCCESS"); +} + +public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(boolean b) {} \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " foo(0); \n" + + " ^^^\n" + + "The method foo(boolean) in the type T is not applicable for the arguments (int)\n" + + "----------\n"); +} + +public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(boolean b) {} \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(false); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " foo(false); \n" + + " ^^^\n" + + "The method foo is defined in an inherited type and an enclosing scope\n" + + "----------\n"); +} + +public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(int j) {} \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " foo(0); \n" + + " ^^^\n" + + "The method foo is defined in an inherited type and an enclosing scope\n" + + "----------\n"); +} +public void test019() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(int j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "class U { \n"+ + " void foo(int j) { System.out.println(\"FAILED\"); } \n"+ + "} \n"+ + "public class X extends U { \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +public void test020() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(int j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "class U { \n"+ + " void foo(boolean j) { System.out.println(\"FAILED\"); } \n"+ + "} \n"+ + "public class X extends U { \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +public void test020a() { + this.runNegativeTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(U j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "class U { \n"+ + "} \n"+ + "public class X extends U { \n"+ + " void foo(X j) { System.out.println(\"FAILED\"); } \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(new X()); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\r\n" + + " foo(new X()); \r\n" + + " ^^^\n" + + "The method foo is defined in an inherited type and an enclosing scope\n" + + "----------\n"); +} +// binary check for 11511 +public void test021() { + this.runConformTest( + new String[] { + "p1/Z.java", + "package p1; \n" + + "public class Z extends AbstractA { \n" + + " public static void main(String[] arguments) { \n" + + " new Z().init(); \n" + + " } \n" + + "} \n" + + "abstract class AbstractB implements K { \n" + + " public void init() { \n" + + " System.out.println(\"AbstractB.init()\"); \n" + + " } \n" + + "} \n" + + "interface K { \n" + + " void init(); \n" + + " void init(int i); \n" + + "} \n", + "p1/AbstractA.java", + "package p1; \n" + + "public abstract class AbstractA extends AbstractB implements K { \n" + + " public void init(int i) { \n" + + " } \n" + + "} \n" + }, + "AbstractB.init()"); // no special vm args + + String computedReferences = findReferences(OUTPUT_DIR + "/p1/Z.class"); + boolean check = + computedReferences.indexOf("ref/p1") >= 0 + && computedReferences.indexOf("ref/AbstractB") >= 0 + && computedReferences.indexOf("methodRef/init/0") >= 0; + if (!check){ + System.out.println(computedReferences); + } + assertTrue("did not bind 'new Z().init()' to AbstractB.init()'", check); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis + */ +public void test022() { + + this.runNegativeTest( + new String[] { + "p1/T.java", + "package p1; \n"+ + "interface II {} \n"+ + "class TT { \n"+ + " void foo(boolean b) {} \n"+ + " void foo(int i, boolean b) {} \n"+ + " void foo(String s) {} \n"+ + "} \n"+ + "public abstract class T implements II { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(0); // should say that foo(int, boolean) isn't applicable \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void boo() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(true); // should complain ambiguity \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\T.java (at line 13)\n" + + " foo(0); // should say that foo(int, boolean) isn\'t applicable \n" + + " ^^^\n" + + "The method foo(int, boolean) in the type TT is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in p1\\T.java (at line 20)\n" + + " foo(true); // should complain ambiguity \n" + + " ^^^\n" + + "The method foo is defined in an inherited type and an enclosing scope\n" + + "----------\n"); +} + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis + */ +public void test023() { + + this.runNegativeTest( + new String[] { + "p1/T.java", + "package p1; \n"+ + "interface II {} \n"+ + "abstract class TT { \n"+ // 259+ABSTRACT + " void foo(boolean b) {} \n"+ + " void foo(int i, boolean b) {} \n"+ + " void foo(String s) {} \n"+ + "} \n"+ + "public abstract class T implements II { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(0); // should say that foo(int, boolean) isn't applicable \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void boo() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(true); // should complain ambiguity \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\T.java (at line 13)\n" + + " foo(0); // should say that foo(int, boolean) isn\'t applicable \n" + + " ^^^\n" + + "The method foo(int, boolean) in the type TT is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in p1\\T.java (at line 20)\n" + + " foo(true); // should complain ambiguity \n" + + " ^^^\n" + + "The method foo is defined in an inherited type and an enclosing scope\n" + + "----------\n"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis + */ +public void test024() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "interface II {} \n"+ + "abstract class T implements II { \n"+ + " void foo(boolean b) {} \n"+ + " void foo(int i, boolean b) {} \n"+ + "} \n"+ + "abstract class TT implements II { \n"+ + " void foo(boolean b) {} \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); // javac says foo cannot be resolved because of multiple matches \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void bar2() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(0); // should say that foo(boolean) isn't applicable \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void boo() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(true); // should complain ambiguity \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 15)\n" + + " foo(0); // javac says foo cannot be resolved because of multiple matches \n" + + " ^^^\n" + + "The method foo(int, boolean) in the type T is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 22)\n" + + " foo(0); // should say that foo(boolean) isn\'t applicable \n" + + " ^^^\n" + + "The method foo(boolean) in the type TT is not applicable for the arguments (int)\n" + + "----------\n" + + "3. ERROR in p1\\X.java (at line 29)\n" + + " foo(true); // should complain ambiguity \n" + + " ^^^\n" + + "The method foo is defined in an inherited type and an enclosing scope\n" + + "----------\n"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis (no matter if super is abstract or not) + */ +public void test025() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X extends AbstractY { \n"+ + " void bar(){ \n"+ + " init(\"hello\"); \n"+ + " } \n"+ + "} \n"+ + "abstract class AbstractY implements I { \n"+ + "} \n"+ + "interface I { \n"+ + " void init(String s, int i); \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public class X extends AbstractY { \n" + + " ^\n" + + "The type X must implement the inherited abstract method I.init(String, int)\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 4)\n" + + " init(\"hello\"); \n" + + " ^^^^\n" + + "The method init(String, int) in the type AbstractY is not applicable for the arguments (String)\n" + + "----------\n"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis (no matter if super is abstract or not) + */ +public void test026() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X extends AbstractY { \n"+ + " void bar(){ \n"+ + " init(\"hello\"); \n"+ + " } \n"+ + "} \n"+ + "class AbstractY implements I { \n"+ + "} \n"+ + "interface I { \n"+ + " void init(String s, int i); \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " init(\"hello\"); \n" + + " ^^^^\n" + + "The method init(String, int) in the type I is not applicable for the arguments (String)\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 7)\n" + + " class AbstractY implements I { \n" + + " ^^^^^^^^^\n" + + "The type AbstractY must implement the inherited abstract method I.init(String, int)\n" + + "----------\n" +); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11922 + * code gen for for(;false;...) + */ +public void test027() { + + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " for (;false;p()); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " static void p(){ \n"+ + " System.out.println(\"FAILED\"); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=12445 + * should report unreachable empty statement + */ +public void test028() { + + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n" + + "interface FooInterface { \n" + + " public boolean foo(int a); \n" + + " public boolean bar(int a); \n" + + "} \n" + + "public class X extends Z { \n" + + " public boolean foo(int a){ return true; } \n" + + " public boolean bar(int a){ return false; } \n" + + " public static void main(String[] arguments) { \n"+ + " System.out.println(new X().test(0)); \n"+ + " } \n" + + "}\n" + + "abstract class Z implements FooInterface { \n" + + " public boolean foo(int a, int b) { \n" + + " return true; \n" + + " } \n" + + " public String test(int a) { \n" + + " boolean result = foo(a); \n" + + " if (result) \n" + + " return \"SUCCESS\"; \n" + + " else \n" + + " return \"FAILED\"; \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * verify error on qualified name ref in 1.4 + */ +public void test029() { + + this.runConformTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args) { \n" + + " new X(); \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " Woof woof_1; \n" + + " public class Honk { \n" + + " Integer honks; \n" + + " } \n" + + " public class Meow { \n" + + " Honk honk_1; \n" + + " } \n" + + " public class Woof { \n" + + " Meow meow_1; \n" + + " } \n" + + " public void setHonks(int num) { \n" + + " // This is the line that causes the VerifyError \n" + + " woof_1.meow_1.honk_1.honks = new Integer(num); \n" + + " // Here is equivalent code that does not cause the error. \n" + + " // Honk h = woof_1.moo_1.meow_1.honk_1; \n" + + " // h.honks = new Integer(num); \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * 1.4 signals invocations of non-visible abstract protected method implementations. + */ +public void test030() { + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args){ \n" + + " new q.X2().foo(\"String\"); \n" + + " new q.X2().bar(\"String\"); \n" + + " new q.X2().barbar(\"String\"); \n" + + " new q.X2().baz(\"String\"); \n" + + " } \n" + + "} \n", + + "p/X1.java", + "package p; \n" + + "public abstract class X1 { \n" + + " protected void foo(Object o){ System.out.println(\"X1.foo(Object)\"); } \n" + + " protected void bar(Object o){ System.out.println(\"X1.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X1.barbar(Object)\"); } \n" + + " protected void baz(Object o) { System.out.println(\"X1.baz(Object)\"); } \n" + + "} \n", + + "q/X2.java", + "package q; \n" + + "public class X2 extends p.X1 { \n" + + " protected void foo(int i) { System.out.println(\"X2.foo(int)\"); } \n" + + " protected void bar(Object o) { System.out.println(\"X2.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " protected void baz(String s) { System.out.println(\"X2.baz(String)\"); } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 6)\n" + + " new q.X2().barbar(\"String\"); \n" + + " ^^^^^^\n" + + "The method barbar(Object) from the type X2 is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in q\\X2.java (at line 5)\n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method X2.barbar(Object) does not override the inherited method from X1 since it is private to a different package\n" + + "----------\n"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * 1.4 signals invocations of non-visible abstract protected method implementations. + */ +public void test031() { + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X extends q.X2 { \n" + + " public static void main(String[] args){ \n" + + " new X().doSomething(); \n" + + " } \n" + + " void doSomething(){ \n" + + " foo(\"String\"); \n" + + " bar(\"String\"); \n" + + " barbar(\"String\"); \n" + + " baz(\"String\"); \n" + + " } \n" + + "} \n", + + "p/X1.java", + "package p; \n" + + "public abstract class X1 { \n" + + " protected void foo(Object o){ System.out.println(\"X1.foo(Object)\"); } \n" + + " protected void bar(Object o){ System.out.println(\"X1.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X1.barbar(Object)\"); } \n" + + " protected void baz(Object o) { System.out.println(\"X1.baz(Object)\"); } \n" + + "} \n", + + "q/X2.java", + "package q; \n" + + "public class X2 extends p.X1 { \n" + + " protected void foo(int i) { System.out.println(\"X2.foo(int)\"); } \n" + + " protected void bar(Object o) { System.out.println(\"X2.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " protected void baz(String s) { System.out.println(\"X2.baz(String)\"); } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 9)\n" + + " barbar(\"String\"); \n" + + " ^^^^^^\n" + + "The method barbar(Object) from the type X2 is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in q\\X2.java (at line 5)\n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method X2.barbar(Object) does not override the inherited method from X1 since it is private to a different package\n" + + "----------\n" +); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * 1.4 signals invocations of non-visible abstract protected field implementations. + */ +public void test032() { + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args){ \n" + + " System.out.println(new q.X2().foo); \n" + + " System.out.println(new q.X2().bar); \n" + + " } \n" + + "} \n", + + "p/X1.java", + "package p; \n" + + "public abstract class X1 { \n" + + " protected String foo = \"X1.foo\"; \n" + + " String bar = \"X1.bar\"; \n" + + "} \n", + + "q/X2.java", + "package q; \n" + + "public class X2 extends p.X1 { \n" + + " protected String foo = \"X2.foo\"; \n" + + " String bar = \"X2.bar\"; \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 4)\n" + + " System.out.println(new q.X2().foo); \n" + + " ^^^\n" + + "The field X2.foo is not visible\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 5)\n" + + " System.out.println(new q.X2().bar); \n" + + " ^^^\n" + + "The field X2.bar is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in q\\X2.java (at line 3)\n" + + " protected String foo = \"X2.foo\"; \n" + + " ^^^\n" + + "The field X2.foo is hiding a field from type X1\n" + + "----------\n"); +} +/* + * Initialization of synthetic fields prior to super constructor call + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23075 + */ +public void test033() { + + this.runConformTest( + new String[] { + "A.java", + "public class A { \n"+ + " public int m; \n"+ + " public void pp() { \n"+ + " C c = new C(4); \n"+ + " System.out.println(c.get()); \n"+ + " } \n"+ + " public static void main(String[] args) { \n"+ + " A a = new A(); \n"+ + " try { \n"+ + " a.pp(); \n"+ + " System.out.println(\"SyntheticInit BEFORE SuperConstructorCall\"); \n"+ + " } catch(NullPointerException e) { \n"+ + " System.out.println(\"SyntheticInit AFTER SuperConstructorCall\"); // should no longer occur with target 1.4 \n"+ + " } \n"+ + " } \n"+ + " class C extends B { \n"+ + " public C(int x1) { \n"+ + " super(x1); \n"+ + " } \n"+ + " protected void init(int x1) { \n"+ + " x = m * x1; // <- NULL POINTER EXCEPTION because of m \n"+ + " } \n"+ + " } \n"+ + "} \n"+ + "class B { \n"+ + " int x; \n"+ + " public B(int x1) { \n"+ + " init(x1); \n"+ + " } \n"+ + " protected void init(int x1) { \n"+ + " x = x1; \n"+ + " } \n"+ + " public int get() { \n"+ + " return x; \n"+ + " } \n"+ + "} \n" + }, + "SyntheticInit AFTER SuperConstructorCall"); +} + +/* + * Initialization of synthetic fields prior to super constructor call - NPE check + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=25174 + */ +public void test034() { + + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new X2(); \n"+ + " } \n"+ + " class X1 { \n"+ + " X1(){ \n"+ + " this.baz(); \n"+ + " } \n"+ + " void baz() { \n"+ + " System.out.println(\"-X1.baz()\"); \n"+ + " } \n"+ + " } \n"+ + " class X2 extends X1 { \n"+ + " void baz() { \n"+ + " System.out.print(X.this==null ? \"X.this == null\" : \"X.this != null\"); \n"+ + " X1 x1 = X.this.new X1(){ \n"+ + " void baz(){ \n"+ + " System.out.println(\"-X$1.baz()\"); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " } \n"+ + "}\n", + }, + "X.this == null-X$1.baz()"); +} + +public void test035() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " class Y { Y(int i){} } \n"+ + " public static void main(String[] arguments) { \n"+ + " int i = 1; \n" + + " try { \n" + + " X x =null; \n" + + " x.new Y(++i); \n" + + " System.out.println(\"SUCCESS:\"+i); \n" + + " } catch(NullPointerException e){ \n" + + " System.out.println(\"FAILED\"); \n" + + " } \n" + + " } \n"+ + "} \n", + }, + "SUCCESS:2" + ); +} + +public void test036() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " class Y {} \n"+ + " static class Z extends Y { \n"+ + " Z (X x){ \n"+ + " x.super(); \n" + + " } \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " try { \n" + + " new Z(null); \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } catch(NullPointerException e){ \n" + + " System.out.println(\"FAILED\"); \n" + + " } \n" + + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=24744 + * http://dev.eclipse.org/bugs/show_bug.cgi?id=23096 + */ +public void test037() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_TaskTags, "TODO:"); + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n"+ + "public class X {\n"+ + "}\n"+ + "// TODO: something" + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 4)\n" + + " // TODO: something\n" + + " ^^^^^^^^^^^^^^^\n" + + "TODO: something\n" + + "----------\n", + null, + true, + customOptions); +} + +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=24833 + * http://dev.eclipse.org/bugs/show_bug.cgi?id=23096 + */ +public void test038() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_TaskTags, "TODO:"); + this.runNegativeTest( + new String[] { + "X.java", + "// TODO: something" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " // TODO: something\n" + + " ^^^^^^^^^^^^^^^\n" + + "TODO: something\n" + + "----------\n", + null, + true, + customOptions, + "java.lang.ClassNotFoundException"); +} + +/* + * unreachable empty statement/block not diagnosed in 1.3 + */ +public void test039() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args){ \n"+ + " for (;null != null;); \n"+ + " for (;null != null;){} \n"+ + " for (;false;); \n"+ + " for (;false;){} \n"+ + " while (false); \n"+ + " while (false){} \n"+ + " if (false) {} else {} \n"+ + " if (false) ; else ; \n"+ + " System.out.println(\"SUCCESS\"); \n" + + " } \n"+ + "} \n", + }, + "SUCCESS"); +} + +// jls6.5.5.1 - simple type names favor member type over toplevel one. +//http://bugs.eclipse.org/bugs/show_bug.cgi?id=30705 +public void test040() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " interface Homonym {} \n"+ // takes precedence over others. + " void foo() { \n"+ + " class Homonym extends X { \n"+ + " { \n"+ + " class Y extends Homonym {}; \n"+ // X$Homonym + " } \n"+ + " } \n"+ + " } \n"+ + "} \n"+ + "class Homonym extends X { \n"+ + " { \n"+ + " class Y extends Homonym {}; \n"+ // X$Homonym + " } \n"+ + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class Homonym extends X { \n" + + " ^^^^^^^\n" + + "The type Homonym is hiding the type X.Homonym\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class Y extends Homonym {}; \n" + + " ^^^^^^^\n" + + "The type Homonym is defined in an inherited type and an enclosing scope\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " class Y extends Homonym {}; \n" + + " ^^^^^^^\n" + + "The type X.Homonym cannot be the superclass of Y; a superclass must be a class\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " class Y extends Homonym {}; \n" + + " ^^^^^^^\n" + + "The type Homonym is defined in an inherited type and an enclosing scope\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " class Y extends Homonym {}; \n" + + " ^^^^^^^\n" + + "The type X.Homonym cannot be the superclass of Y; a superclass must be a class\n" + + "----------\n"); +} +/* + * 30856 - 1.4 compliant mode should consider abstract method matches + */ +public void test041() { + this.runConformTest( + new String[] { + "p/X.java", //================================ + "package p; \n" + + "public class X { \n" + + " void foo(int i, float f){} \n" + + " public static void main(String[] args) { \n" + + " q.Y y = new q.Y.Z(); \n" + + " y.bar(); \n" + + " } \n" + + "} \n", + "q/Y.java", //================================ + "package q; \n" + + "public abstract class Y extends p.X implements I { \n" + + " public void bar(){ foo(1, 2); } \n" + + " public static class Z extends Y { \n" + + " public void foo(float f, int i) { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + "} \n" + + "interface I { \n" + + " void foo(float f, int i); \n" + + "} \n", + }, + "SUCCESS"); +} +/* + * variation - 30856 - 1.4 compliant mode should consider abstract method matches + */ +public void test042() { + this.runConformTest( + new String[] { + "p/X.java", //================================ + "package p; \n" + + "public class X extends X0 { \n" + + " void foo(int i, float f){} \n" + + " public static void main(String[] args) { \n" + + " q.Y y = new q.Y.Z(); \n" + + " y.bar(); \n" + + " } \n" + + "} \n" + + "class X0 { \n" + + " void foo(int i, double d){} \n" + // extra match + "} \n", + "q/Y.java", //================================ + "package q; \n" + + "public abstract class Y extends p.X implements I { \n" + + " public void bar(){ foo(1, 2); } \n" + + " public static class Z extends Y { \n" + + " public void foo(float f, int i) { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + "} \n" + + "interface I { \n" + + " void foo(float f, int i); \n" + + "} \n", + }, + "SUCCESS"); +} + +// binary compatibility +public void _test043() { + this.runConformTest( + new String[] { + "p1/Y.java", + "package p1; \n" + + "public class Y extends A implements I { \n" + + " public static void main(String[] args) { \n" + + " Y.printValues(); \n" + + " } \n" + + " public static void printValues() { \n" + + " System.out.println(\"i=\"+i+\",j=\"+j+\",Y.i=\"+Y.i+\",Y.j=\"+Y.j); \n" + + " } \n" + + "} \n", + "p1/A.java", + "package p1; \n" + + "public class A { \n" + + " static int i = 1; \n" + + "} \n", + "p1/I.java", + "package p1; \n" + + "interface I { \n" + + " int j = \"aa\".length(); \n" + + "} \n", + }, + "i=1,j=2,Y.i=1,Y.j=2"); + + this.runConformTest( + new String[] { + "p1/A.java", + "package p1; \n" + + "public class A { \n" + + " static int j = 3; \n" + + " public static void main(String[] args) { \n" + + " Y.printValues(); \n" + + " } \n" + + "} \n", + "p1/I.java", + "package p1; \n" + + "interface I { \n" + + " int j = \"aaaa\".length(); \n" + + "} \n", + }, + "i=4,j=3,Y.i=4,Y.j=3", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} +/* + * array.clone() should use array type in methodRef + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=36307 + */ +public void test044() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " args.clone(); \n"+ + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " 1 invokevirtual java.lang.Object.clone() : java.lang.Object [16]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} + +// 39172 +public void test045() { + this.runConformTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args) { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " return;; \n" + // unreachable empty statement - no complaint in 1.3 mode + " } \n" + + "} \n" + }, + "SUCCESS" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39467 + * should diagnose missing abstract method implementation + */ +public void test046() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + "}\n" + + "abstract class Y extends Z {\n" + + " public abstract void foo();\n" + + "}\n" + + "abstract class Z extends T {\n" + + "}\n" + + "class T implements I {\n" + + " public void foo(){}\n" + + "}\n" + + "interface I {\n" + + " public void foo ();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y {\n" + + " ^\n" + + "The type X must implement the inherited abstract method Y.foo()\n" + + "----------\n" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40442 + * Abstract class fails to invoke interface-defined method in 1.4 compliance mode. + */ +public void test047() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends AbstractDoubleAlgorithm {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " ((ObjectAlgorithm)(new X())).operate(new Double(0));\n" + + " }\n" + + " public void operate(Double pDouble)\n" + + " {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "abstract class AbstractDoubleAlgorithm implements DoubleAlgorithm {\n" + + " public void operate(Object pObject)\n" + + " {\n" + + " operate((Double)pObject);\n" + + " }\n" + + "}\n" + + "interface DoubleAlgorithm extends ObjectAlgorithm {\n" + + " void operate(Double pDouble);\n" + + "}\n" + + "interface ObjectAlgorithm {\n" + + " void operate(Object pObject);\n" + + "}" + }, + "SUCCESS" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40442 + * Abstract class fails to invoke interface-defined method in 1.4 compliance mode. + * variation with 2 found methods + */ +public void test048() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends AbstractDoubleAlgorithm {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " ((ObjectAlgorithm)(new X())).operate(new Double(0));\n" + + " }\n" + + " public void operate(Double pDouble)\n" + + " {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "abstract class AbstractDoubleAlgorithm implements DoubleAlgorithm {\n" + + " public void operate(Object pObject)\n" + + " {\n" + + " operate((Double)pObject);\n" + + " }\n" + + " public void operate(X x) {}\n" + + "}\n" + + "interface DoubleAlgorithm extends ObjectAlgorithm {\n" + + " void operate(Double pDouble);\n" + + "}\n" + + "interface ObjectAlgorithm {\n" + + " void operate(Object pObject);\n" + + "}" + }, + "SUCCESS" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=41278 + */ +public void test049() { + this.runConformTest( + new String[] { + "pa/Caller.java", + "package pa;\n" + + "import pb.Concrete;\n" + + "public class Caller {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Concrete aConcrete = new Concrete(); \n" + + " aConcrete.callme();\n" + + " }\n" + + "}\n", + "pa/Abstract.java", + "package pa;\n" + + "public abstract class Abstract {\n" + + "\n" + + " protected void callme(){}\n" + + "}\n", + "pb/Concrete.java", + "package pb;\n" + + "public class Concrete extends pa.Abstract {\n" + + "\n" + + " protected void callme(){ System.out.println(\"SUCCESS\"); }\n" + + "}\n", + }, + "SUCCESS"); +} + +public void test050() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " int a1 = 1;\n" + + " int a2 = 1;\n" + + " a1 = 2;\n" + + " while (false) {};\n" + + " a2 = 2;\n" + + " }\n" + + "}\n", + }); +} + +public void test051() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " int a1 = 1;\n" + + " int a2 = 1;\n" + + " a1 = 2;\n" + + " while (false);\n" + + " a2 = 2;\n" + + " }\n" + + "}\n", + }); +} + +public void test052() { + this.runNegativeTest( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static void main(String[] argv) {\n" + + " foo();\n" + + " }\n" + + " private int i;\n" + + " static class Y extends X {\n" + + " int x = i;\n" + + " }\n" + + " public static void foo() {\n" + + " return;\n" + + " }\n" + + "}", + + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " int a1 = 1;\n" + + " int a2 = 1;\n" + + " a1 = 2;\n" + + " while (false);\n" + + " a2 = 2;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p\\A.java (at line 8)\n" + + " int x = i;\n" + + " ^\n" + + "Cannot make a static reference to the non-static field i\n" + + "----------\n"); +} + +public void test053() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "class X {\n" + + " static class A {\n" + + " interface I {\n" + + " int a = 3;\n" + + " }\n" + + " } \n" + + " interface I { \n" + + " int b = 4;\n" + + " }\n" + + " class Y extends A implements I {\n" + + " Object F() {\n" + + " return new I() {\n" + + " int c = a; // WE SHOULD NOT BE ABLE TO SEE BOTH a and b\n" + + " int d = b; // WE SHOULD NOT BE ABLE TO SEE BOTH a and b\n" + + " };\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 13)\n" + + " return new I() {\n" + + " ^\n" + + "The type I is defined in an inherited type and an enclosing scope\n" + + "----------\n" + ); +} + +public void test054() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " static class A {\n" + + " interface I {\n" + + " int a = 3;\n" + + " void foo();\n" + + " }\n" + + " }\n" + + " interface I {\n" + + " int a = 4;\n" + + " void foo();\n" + + " }\n" + + " class Y extends A implements I {\n" + + " public void foo() {\n" + + " new I() {\n" + + " public void foo() {\n" + + " System.out.println(\"X$1::foo-\" + a);\n" + + " }\n" + + " }\n" + + " .foo();\n" + + " }\n" + + " }\n" + + "public static void main(String argv[]) {\n" + + " new X().new Y().foo();\n" + + "}\n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 15)\n" + + " new I() {\n" + + " ^\n" + + "The type I is defined in an inherited type and an enclosing scope\n" + + "----------\n" + ); +} +public void test055() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " static class A {\n" + + " interface I2 {\n" + + " int a = 3;\n" + + " void foo();\n" + + " }\n" + + " }\n" + + " interface I1 {\n" + + " int a = 4;\n" + + " void foo(int a);\n" + + " }\n" + + " class Y extends A implements I1 {\n" + + " public void foo(int a) {\n" + + " new I2() {\n" + + " public void foo() {\n" + + " System.out.println(\"X$1::foo-\" + a);\n" + + " }\n" + + " }\n" + + " .foo();\n" + + " }\n" + + " }\n" + + "public static void main(String argv[]) {\n" + + " new X().new Y().foo(8);\n" + + "}\n" + + "}", + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 11)\n" + + " void foo(int a);\n" + + " ^\n" + + "The parameter a is hiding a field from type X.I1\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 14)\n" + + " public void foo(int a) {\n" + + " ^\n" + + "The parameter a is hiding a field from type X.I1\n" + + "----------\n" + + "3. ERROR in p\\X.java (at line 17)\n" + + " System.out.println(\"X$1::foo-\" + a);\n" + + " ^\n" + + "The field a is defined in an inherited type and an enclosing scope \n" + + "----------\n" + ); +} + +public void test056() { + this.runNegativeTest( + new String[] { + "p/MethodQualification.java", + "package p;\n" + + "public class MethodQualification {\n" + + " void foo() {\n" + + " System.out.println(\"Inherited foo() for anonymous type\");\n" + + " class Local {\n" + + " void foo(){\n" + + " System.out.println(\"Enclosing foo() for anonymous type\");\n" + + " new MethodQualification () { {foo();} };\n" + + " }\n" + + " };\n" + + " } \n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\MethodQualification.java (at line 8)\n" + + " new MethodQualification () { {foo();} };\n" + + " ^^^\n" + + "The method foo is defined in an inherited type and an enclosing scope\n" + + "----------\n" + ); +} + +public void test057() { + this.runNegativeTest( + new String[] { + "p/AG.java", + "package p;\n" + + "/**\n" + + " * 1F9RITI\n" + + " */\n" + + "public class AG {\n" + + " public class X {\n" + + " class B {\n" + + " int intValueOfB = -9;\n" + + " }\n" + + " class SomeInner extends A {\n" + + " void someMethod() {\n" + + " int i = new B().intValueOfB; //HERE ERROR SHOULD BE DETECTED\n" + + " }\n" + + " }\n" + + " }\n" + + " class A {\n" + + " class B {\n" + + " int intValueOfB = -9;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\AG.java (at line 12)\n" + + " int i = new B().intValueOfB; //HERE ERROR SHOULD BE DETECTED\n" + + " ^\n" + + "The type B is defined in an inherited type and an enclosing scope\n" + + "----------\n" + ); +} + +public void test058() { + this.runNegativeTest( + new String[] { + "p/AE.java", + "package p;\n" + + "/**\n" + + " * 1F9RITI\n" + + " */\n" + + "public class AE {\n" + + " public class X {\n" + + " int intValue = 153;\n" + + " class SomeInner extends A {\n" + + " void someMethod() {\n" + + " int i = intValue; //HERE THE ERROR - SHOULD HAVE A QUALIFICATION\n" + + " }\n" + + " }\n" + + " }\n" + + " class A {\n" + + " int intValue = 153;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\AE.java (at line 10)\n" + + " int i = intValue; //HERE THE ERROR - SHOULD HAVE A QUALIFICATION\n" + + " ^^^^^^^^\n" + + "The field intValue is defined in an inherited type and an enclosing scope \n" + + "----------\n" + ); +} + +public void test059() { + this.runNegativeTest( + new String[] { + "p/FieldQualification.java", + "package p;\n" + + "public class FieldQualification {\n" + + " String field = \"Inherited field for anonymous type\";\n" + + "void foo() {\n" + + " class Local {\n" + + " String field = \"Enclosing field for anonymous type\";\n" + + " void foo() {\n" + + " System.out.println(\"Enclosing foo() for anonymous type\");\n" + + " new FieldQualification() {\n" + + " {\n" + + " System.out.println(field);\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + "}\n" + + "}", + }, + "----------\n" + + "1. WARNING in p\\FieldQualification.java (at line 6)\n" + + " String field = \"Enclosing field for anonymous type\";\n" + + " ^^^^^\n" + + "The field Local.field is hiding a field from type FieldQualification\n" + + "----------\n" + + "2. ERROR in p\\FieldQualification.java (at line 11)\n" + + " System.out.println(field);\n" + + " ^^^^^\n" + + "The field field is defined in an inherited type and an enclosing scope \n" + + "----------\n" + ); +} + +public void test060() { + this.runNegativeTest( + new String[] { + "p/AF.java", + "package p;\n" + + "/**\n" + + " * 1F9RITI\n" + + " */\n" + + "public class AF {\n" + + " public class X {\n" + + " int intMethod() {\n" + + " return 3333;\n" + + " }\n" + + " class SomeInner extends A {\n" + + " void someMethod() {\n" + + " int i = intMethod(); //ERROR HERE SHOULD BE DETECTED\n" + + " }\n" + + " }\n" + + " }\n" + + " class A {\n" + + " int intMethod() {\n" + + " return 3333;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\AF.java (at line 12)\n" + + " int i = intMethod(); //ERROR HERE SHOULD BE DETECTED\n" + + " ^^^^^^^^^\n" + + "The method intMethod is defined in an inherited type and an enclosing scope\n" + + "----------\n" + ); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=32342 + */ +public void test061() { + this.runNegativeTest( + new String[] { + "p/X.java", //====================== + "package p; \n" + + "public class X extends q.Y { \n" + + " X someField; \n" + // no ambiguity since inherited Y.X isn't visible + "} \n" + + "class Z extends q.Y { \n" + + " Z someField; \n" + // ambiguous + "} \n", + "q/Y.java", //====================== + "package q; \n" + + "public class Y { \n" + + " private static class X {} \n" + + " public static class Z {} \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 6)\n" + + " Z someField; \n" + + " ^\n" + + "The type Z is defined in an inherited type and an enclosing scope\n" + + "----------\n"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11435 + * variant - must still complain when targeting super abstract method + */ +public void test062() { + + this.runNegativeTest( + new String[] { + "p1/Y.java", + "package p1; \n"+ + "public class Y extends AbstractT { \n"+ + " public void init(){ \n"+ + " super.init(); \n"+ + " } \n"+ + "} \n"+ + "abstract class AbstractT implements J { \n"+ + "} \n"+ + "interface J { \n"+ + " void init(); \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\Y.java (at line 4)\n" + + " super.init(); \n" + + " ^^^^^^^^^^^^\n" + + "Cannot directly invoke the abstract method init() for the type AbstractT\n" + + "----------\n"); // expected log +} + +public void test063() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " class Y extends X {} \n"+ + " class Z extends Y { \n"+ + " Z(){ \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n" + + " } \n" + + " public static void main(String[] arguments) { \n"+ + " new X().new Z(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} +/** + * Allow selection of own enclosing instance arg for super constructor call in 1.3 compliant mode + */ +public void test064() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo {\n" + + " public static void main(String[] args) {\n"+ + " System.out.println(\"SUCCESS\");\n"+ + " }\n"+ + " public class Bar extends Foo {\n" + + " public Bar() {\n" + + " }\n" + + " }\n" + + " public class Baz extends Bar {\n" + + " public Baz() {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} + +public void test065() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new Y().new Z().bar(); \n"+ + " } \n"+ + " String foo() { return \"X-foo\"; } \n"+ + " class Y extends X { \n"+ + " String foo() { return \"Y-foo\"; } \n"+ + " class Z extends Y { \n"+ + " Z(){ \n"+ + " //X.this.super(); \n"+ + " } \n"+ + " String foo() { return \"Z-foo\"; } \n"+ + " void bar () { \n"+ + " System.out.println(X.this.foo()); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + "X-foo"); +} + +/* + * Check that anonymous type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test066() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(Object o) {}\n" + + " class M extends X {\n" + + " M(){\n" + + " super(null);\n" + + " }\n" + + " M(Object o) {\n" + + " super(new M(){});\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(new M(){});\n" + + " ^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); +} + +/* + * Check that indirect member type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test067() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(Object o) {\n" + + " }\n" + + " class N extends X {\n" + + " N(Object o) {\n" + + " super(o);\n" + + " }\n" + + " }\n" + + " class M extends N {\n" + + " M() {\n" + + " super(null); //1\n" + + " }\n" + + " M(Object o) {\n" + + " super(new M());//2\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. 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"); +} + +/* + * Check that indirect member type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test068() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n"+ + " System.out.println(\"SUCCESS\");\n"+ + " }\n"+ + " class MX1 extends X {\n" + + " MX1() {\n" + + " }\n" + + " }\n" + + " class MX2 extends MX1 {\n" + + " MX2() {\n" + + " super(); // ko\n" + // incorrectly accepted in 1.3 + " }\n" + + " MX2(X x) {\n" + + " this(); // ok\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} + +/* + * Check that indirect member type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test069() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX3 extends X {\n" + + " MX3(X x) {\n" + + " }\n" + + " }\n" + + " class MX4 extends MX3 {\n" + + " MX4() {\n" + + " super(new MX4()); // ko\n" + + " }\n" + + " MX4(X x) {\n" + + " this(); // ok\n" + + " }\n" + + " MX4(int i) {\n" + + " this(new MX4()); // ko\n" + + " }\n" + + " }\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 14)\n" + + " this(new MX4()); // ko\n" + + " ^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); +} + +// binary compatibility +public void test070() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Middle {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(new X().field);\n" + + " }\n" + + "}\n" + + "class Middle extends Top {\n" + + "}\n" + + "class Top {\n" + + " String field = \"Top.field\";\n" + + "}\n" + }, + "Top.field"); + + this.runConformTest( + new String[] { + "Middle.java", + "public class Middle extends Top {\n" + + " public static void main(String[] arguments) { \n"+ + " X.main(arguments); \n" + + " } \n" + + " String field = \"Middle.field\";\n" + + "}\n" + }, + "Top.field", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} + +/* + * 43429 - AbstractMethodError calling clone() at runtime when using Eclipse compiler + */ +public void test071() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public interface Copyable extends Cloneable {\n" + + " public Object clone() throws CloneNotSupportedException;\n" + + " }\n" + + " public interface TestIf extends Copyable {\n" + + " }\n" + + " public static class ClassA implements Copyable {\n" + + " public Object clone() throws CloneNotSupportedException {\n" + + " return super.clone();\n" + + " }\n" + + " }\n" + + " public static class ClassB implements TestIf {\n" + + " public Object clone() throws CloneNotSupportedException {\n" + + " return super.clone();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " Copyable o1 = new ClassA();\n" + + " ClassB o2 = new ClassB();\n" + + " TestIf o3 = o2;\n" + + " Object clonedObject;\n" + + " clonedObject = o1.clone();\n" + + " clonedObject = o2.clone();\n" + + " // The following line fails at runtime with AbstractMethodError when\n" + + " // compiled with Eclipse\n" + + " clonedObject = o3.clone();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} + +public void test072() { + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " f();\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " static void f() {\n" + + " Object x = new Object() {\n" + + " {\n" + + " if (true) throw null;\n" + + " }\n" + + " };\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " if (true) throw null;\n" + + " ^^^^\n" + + "Cannot throw null as an exception\n" + + "----------\n"); +} + +// 52221 +public void test073() { + + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " public static void main(String[] args) {\n" + + " \n" + + " switch(args.length) {\n" + + " \n" + + " case 1:\n" + + " int i = 0;\n" + + " class Local {\n" + + " }\n" + + " break;\n" + + " \n" + + " case 0 :\n" + + " System.out.println(i); // local var can be referred to, only an initialization pb\n" + + " System.out.println(new Local());\n" + + " break;\n" + + "\n" + + " case 2 :\n" + + " class Local { // not a duplicate\n" + + " }\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " class Local { // not a duplicate\n" + + " ^^^^^\n" + + "Duplicate nested type Local\n" + + "----------\n"); +} + +// checking for captured outer local initialization status +// NOTE: only complain against non-inlinable outer locals +// http://bugs.eclipse.org/bugs/show_bug.cgi?id=26134 +public void test074() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) { \n" + + " String nonInlinedString = \"[Local]\"; \n" + + " int i = 2; \n" + + " switch(i){ \n" + + " case 1: \n" + + " final String displayString = nonInlinedString;\n" + + " final String inlinedString = \"a\"; \n" + + " class Local { \n" + + " public String toString() { \n" + + " return inlinedString + displayString; \n" + + " } \n" + + " } \n" + + " case 2: \n" + + " System.out.print(new Local()); \n" + + " System.out.print(\"-\"); \n" + + " System.out.println(new Local(){ \n" + + " public String toString() { \n" + + " return super.toString()+\": anonymous\"; \n" + + " } \n" + + " }); \n" + + " } \n" + + " } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " System.out.print(new Local()); \n" + + " ^^^^^^^^^^^\n" + + "The local variable displayString may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " System.out.println(new Local(){ \n" + + " public String toString() { \n" + + " return super.toString()+\": anonymous\"; \n" + + " } \n" + + " }); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The local variable displayString may not have been initialized\n" + + "----------\n"); +} +public void test075() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public void foo(int p1) {} \n" + + " public void foo(short p1) {} \n" + + "} \n", + "Y.java", + "public class Y extends X { \n" + + " public void foo(long p1) {} \n" + + " public void test() { foo((short) 1); } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in Y.java (at line 3)\r\n" + + " public void test() { foo((short) 1); } \r\n" + + " ^^^\n" + + "The method foo(long) is ambiguous for the type Y\n" + + "----------\n"); +} +/** + * Test fix bug 58069 for type. + * @see
58069 + */ +public void test076() { + this.docSupport = true; + runNegativeTest( + new String[] { + "IX.java", + "interface IX {\n" + + " public static class Problem extends Exception {}\n" + + "}\n", + "X.java", + "public abstract class X {\n" + + " public static class Problem extends Exception {}\n" + + " public abstract static class InnerClass implements IX {\n" + + " /**\n" + + " * @throws Problem \n" + + " */\n" + + " public void foo() throws IllegalArgumentException {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. WARNING in IX.java (at line 2)\n" + + " public static class Problem extends Exception {}\n" + + " ^^^^^^^\n" + + "The serializable class Problem does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public static class Problem extends Exception {}\n" + + " ^^^^^^^\n" + + "The serializable class Problem does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @throws Problem \n" + + " ^^^^^^^\n" + + "Javadoc: The type Problem is defined in an inherited type and an enclosing scope\n" + + "----------\n" + ); +} +/** + * Test fix bug 58069 for method. + * Note that problem is not flagged in doc comments as it is only raised while verifying + * implicit method and javadoc resolution does not use it. + */ +public void test077() { + this.docSupport = true; + this.runNegativeTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar() { \n"+ + " return \"FAILED\"; \n" + + " } \n"+ + " void foo(){ \n"+ + " /** @see #bar() */\n" + + " class Y extends Secondary { \n"+ + " /** @see #bar() */\n" + + " String z = bar(); \n" + + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " String bar(){ return \"FAILED\"; } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\Test.java (at line 13)\n" + + " String z = bar(); \n" + + " ^^^\n" + + "The method bar is defined in an inherited type and an enclosing scope\n" + + "----------\n" + ); +} +/** + * Test fix bug 58069 for field. + * Note that problem is not flagged in doc comments as it is only raised while verifying + * Name or Qualified name references and javadoc reference is a field reference. + */ +public void test078() { + this.docSupport = true; + this.runNegativeTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar = \"FAILED\";"+ + " void foo(){ \n"+ + " /** @see #bar */\n" + + " class Y extends Secondary { \n"+ + " /** @see #bar */\n" + + " String z = bar; \n"+ + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " String bar = \"FAILED\"; \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\Test.java (at line 10)\n" + + " String z = bar; \n" + + " ^^^\n" + + "The field bar is defined in an inherited type and an enclosing scope \n" + + "----------\n" + ); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47227 + */ +public void test079() { + this.runNegativeTest( + new String[] { + "Hello.java", + "void ___eval() {\n" + + " new Runnable() {\n" + + " int ___run() throws Throwable {\n" + + " return blah;\n" + + " }\n" + + " private String blarg;\n" + + " public void run() {\n" + + " }\n" + + " };\n" + + "}\n" + + "public class Hello {\n" + + " private static int x;\n" + + " private String blah;\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public void hello() {\n" + + " }\n" + + " public boolean blah() {\n" + + " return false;\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Hello.java (at line 1)\n" + + " void ___eval() {\n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + + "2. ERROR in Hello.java (at line 2)\n" + + " new Runnable() {\n" + + " int ___run() throws Throwable {\n" + + " return blah;\n" + + " }\n" + + " private String blarg;\n" + + " public void run() {\n" + + " }\n" + + " };\n" + + "}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + ); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67643 + * from 1.5 source level on most specific common super type is allowed + */ +public void test080() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {\n" + + " private static class C1 extends ArrayList {\n" + + " }\n" + + " private static class C2 extends ArrayList {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " ArrayList list = args == null ? new C1(): new C2();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private static class C1 extends ArrayList {\n" + + " ^^\n" + + "The serializable class C1 does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " private static class C2 extends ArrayList {\n" + + " ^^\n" + + "The serializable class C2 does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " ArrayList list = args == null ? new C1(): new C2();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types X.C1 and X.C2\n" + + "----------\n"); +} +public void test081() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X foo() { return this; } \n" + + "}\n" + + "class Y extends X {\n" + + " public Y foo() { return this; } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public Y foo() { return this; } \n" + + " ^\n" + + "The return type is incompatible with X.foo()\n" + + "----------\n"); +} +// covariance +public void test082() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X x = new X1();\n" + + " System.out.println(x.foo());\n" + + " }\n" + + " Object foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 extends X {\n" + + " String foo() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " String foo() {\n" + + " ^^^^^^\n" + + "The return type is incompatible with X.foo()\n" + + "----------\n"); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=66533 + */ +public void test084() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object enum = null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object enum = null;\n" + + " ^^^^\n" + + "\'enum\' should not be used as an identifier, since it is a reserved keyword from source level 1.5 on\n" + + "----------\n"); +} +/** + * Test unused import with static + */ +public void test085() { + this.runNegativeTest( + new String[] { + "A.java", + "import static j.l.S.*;\n" + + "import static j.l.S.in;\n" + + "\n" + + "public class A {\n" + + "\n" + + "}\n", + "j/l/S.java", + "package j.l;\n" + + "public class S {\n" + + " public static int in;\n" + + "}\n" + }, + "----------\n" + + "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 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 or greater\n" + + "----------\n" + + "3. ERROR in A.java (at line 2)\n" + + " import static j.l.S.in;\n" + + " ^^^^^^^^\n" + + "The import j.l.S.in cannot be resolved\n" + + "----------\n" + ); +} +/** + * Test invalid static import syntax + */ +public void test086() { + this.runNegativeTest( + new String[] { + "p/S.java", + "package p;\n" + + "public class S {\n" + + " public final static String full = \"FULL\";\n" + + " public final static String success = \"SUCCESS\";\n" + + "}\n", + "X.java", + "import static p.S;\n" + + "public class X {\n" + + " public static void main ( String[] args) {\n" + + " \n" + + " System.out.print(full+\" \"+p.S.success);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "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 or greater\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.print(full+\" \"+p.S.success);\n" + + " ^^^^\n" + + "full cannot be resolved to a variable\n" + + "----------\n" + ); +} +public void test087() { + this.runNegativeTest( + new String[] { + "p/S.java", + "public class S {\n" + + " public final static String full = \"FULL\";\n" + + " public final static String success = \"SUCCESS\";\n" + + "}\n", + "X.java", + "import static S;\n" + + "public class X {\n" + + " public static void main ( String[] args) {\n" + + " \n" + + " System.out.print(full+\" \"+S.success);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "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 or greater\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.print(full+\" \"+S.success);\n" + + " ^^^^\n" + + "full cannot be resolved to a variable\n" + + "----------\n" + ); +} +public void test088() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Date;\n" + + "import java.lang.reflect.*;\n" + + "public class X extends Date implements Runnable{\n" + + " \n" + + " Integer w = Integer.valueOf(90);\n" + + " protected double x = 91.1;\n" + + " public long y = 92;\n" + + " static public Boolean z = Boolean.valueOf(true); \n" + + " public class X_inner {\n" + + " public X_inner() {\n" + + " this.super();\n" + + " System.out.println(\"....\");\n" + + " }\n" + + " }\n" + + " X_inner a = new X_inner();\n" + + " public interface X_interface {\n" + + " public void f(); \n" + + " }\n" + + " static {\n" + + " System.out.println(\"Static initializer\");\n" + + " }\n" + + " public X() { } \n" + + " public X(int a1,int b1) { } \n" + + " private void a() { System.out.println(\"A\");} \n" + + " protected void b() { System.out.println(\"B\");} \n" + + " public void c() { System.out.println(\"C\");} \n" + + " static public int d() {System.out.println(\"Static D\");return -1;} \n" + + " public static void main(String args[]) {\n" + + " X b = new X();\n" + + " Class c = b.getClass();\n" + + " Class _getClasses [] = X.class.getClasses(); \n" + + "// System.out.println(_getClasses[0].toString());\n" + + "// System.out.println(_getClasses[1].toString());\n" + + " if (_getClasses.length == 0) {System.out.println(\"FAILED\");};\n" + + " Constructor _getConstructors[] = c.getConstructors(); \n" + + " try {\n" + + " Field _getField = c.getField(\"y\");\n" + + " Method _getMethod = c.getMethod(\"d\",null);\n" + + " \n" + + " Boolean b_z = X.z; \n" + + " }\n" + + " catch (NoSuchFieldException e) { System.out.println(\"NoSuchFieldException\");}\n" + + " catch (NoSuchMethodException e) { System.out.println(\"NoSuchMethodException\");};\n" + + " } \n" + + " public void run() {System.out.println(\"RUN\");} \n" + + "}", + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 4)\n" + + " public class X extends Date implements Runnable{\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 12)\n" + + " this.super();\n" + + " ^^^^\n" + + "Illegal enclosing instance specification for type Object\n" + + "----------\n"); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78089 + */ +public void test089() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " @interface I1 {}\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + "----------\n" + + "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 or greater\n" + + "----------\n"); +} +//78104 +public void test090() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(int[] ints, Object o) {\n" + + " ints = ints.clone();\n" + + " ints = (int[])ints.clone();\n" + + " X x = this.clone();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " ints = ints.clone();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to int[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X x = this.clone();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + ); +} +//78104 - variation +public void test091() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " args = args.clone();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " args = args.clone();\r\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to String[]\n" + + "----------\n" + ); +} +// check autoboxing only enabled in 5.0 source mode +public void test092() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Boolean b) {\n" + + " if (b) { \n" + + " int i = 0;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (b) { \n" + + " ^\n" + + "Type mismatch: cannot convert from Boolean to boolean\n" + + "----------\n" + ); +} +public void test093() { + this.runNegativeTest( + new String[] { + "p/X_1.java", + "package p;\n" + + "/* dena JTest Suite, Version 2.2, September 1997\n" + + " * Copyright (c) 1995-1997 Modena Software (I) Pvt. Ltd., All Rights Reserved\n" + + " */\n" + + "/* Section : Inner classes \n" + + " * FileName : ciner026.java\n" + + " * Purpose : Positive test for Inner classes\n" + + " * \n" + + " * An anonymous class can have initializers but cannot have a constructor.\n" + + " * The argument list of the associated new expression is implicitely \n" + + " * passed to the constructor of the super class. \n" + + " *\n" + + " */\n" + + " \n" + + " class X_1 {\n" + + " static int xx = 100;\n" + + " //inner class Y \n" + + " static class Y { \n" + + " public int j = 0;\n" + + " Y(int x){ j = x; }\n" + + " } \n" + + " public void call_inner()\n" + + " {\n" + + " int i = test_anonymous().j;\n" + + " } \n" + + " public static void main(String argv[])\n" + + " {\n" + + " X_1 ox = new X_1();\n" + + " ox.call_inner(); \n" + + " } \n" + + "public void newMethod ( ) {\n" + + " Float f1 = null;\n" + + " f1=(f1==0.0)?1.0:f1;\n" + + "}\n" + + " static Y test_anonymous()\n" + + " { \n" + + " //anonymous implementation of class Y\n" + + " return new Y(xx) //xx should be implicitely passed to Y()\n" + + " {\n" + + " }; \n" + + " \n" + + " } //end test_anonymous \n" + + "} ", + }, + "----------\n" + + "1. ERROR in p\\X_1.java (at line 33)\n" + + " f1=(f1==0.0)?1.0:f1;\n" + + " ^^^^^^^^^\n" + + "Incompatible operand types Float and double\n" + + "----------\n" + ); +} +/* + * Test unused import warning in presence of syntax errors + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21022 + */ +public void test094(){ + + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*; \n" + + "public class X { \n" + + " void foo(){\n" + + " ()\n" + + " IOException e;\n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " ()\n" + + " ^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=84743 +public void test095(){ + + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "interface J {\n" + + " String foo();\n" + + "}\n" + + " \n" + + "public class X implements I {\n" + + " public int foo() {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = new X();\n" + + " try {\n" + + " J j = (J) i;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " J j = (J) i;\n" + + " ^^^^^\n" + + "Cannot cast from I to J\n" + + "----------\n"); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47074 + */ +public void test096() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " interface A {\n" + + " void doSomething();\n" + + " }\n" + + "\n" + + " interface B {\n" + + " int doSomething();\n" + + " }\n" + + "\n" + + " interface C extends B {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " \n" + + " A a = null;\n" + + " C c = (C)a; //COMPILER ERROR\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " C c = (C)a; //COMPILER ERROR\n" + + " ^^^^\n" + + "Cannot cast from X.A to X.C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=79396 +public void test097() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " int cst = X1.CST;\n" + + " X2.Root.foo();\n" + + " }\n" + + " static void foo() {}\n" + + "}\n" + + "\n" + + "class X1 {\n" + + " static {\n" + + " System.out.print(\"[X1]\");\n" + + " }\n" + + " public static final int CST = 12;\n" + + " static X Root = null;\n" + + "}\n" + + "class X2 {\n" + + " static {\n" + + " System.out.print(\"[X2]\");\n" + + " }\n" + + " public final int CST = 12;\n" + + " static X Root = null;\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=78906 +public void test098() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " System.out.print(\"foo\");\n" + + " }\n" + + " class Y {\n" + + " String this$0;\n" + + " String this$0$;\n" + + " void print() { \n" + + " foo();\n" + + " System.out.println(this$0+this$0$);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y y = new X().new Y();\n" + + " y.this$0 = \"hello\";\n" + + " y.this$0$ = \"world\";\n" + + " y.print();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String this$0;\n" + + " ^^^^^^\n" + + "Duplicate field X.Y.this$0\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=77349 +public void test099() { + this.runNegativeTest( + new String[] { + "I.java", + "public interface I extends Cloneable {\n" + + " class Inner {\n" + + " Object bar(I i) throws CloneNotSupportedException { return i.clone(); }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in I.java (at line 3)\n" + + " Object bar(I i) throws CloneNotSupportedException { return i.clone(); }\n" + + " ^^^^^^^^^\n" + + "Access to enclosing method clone() from the type Object is emulated by a synthetic accessor method\n" + + "----------\n", + null, + true, + null, + "java.lang.ClassFormatError" + // no compile errors but generates ClassFormatError if run + ); +} + +public void test100() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int \\ud800\\udc05\\ud800\\udc04\\ud800\\udc03\\ud800\\udc02\\ud800\\udc01\\ud800\\udc00;\n" + + " void foo() {\n" + + " int \\ud800\\udc05\\ud800\\udc04\\ud800\\udc03\\ud800\\udc02\\ud800\\udc01\\ud800\\udc00;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int \\ud800\\udc05\\ud800\\udc04\\ud800\\udc03\\ud800\\udc02\\ud800\\udc01\\ud800\\udc00;\n" + + " ^^^^^^\n" + + "Invalid unicode\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " int \\ud800\\udc05\\ud800\\udc04\\ud800\\udc03\\ud800\\udc02\\ud800\\udc01\\ud800\\udc00;\n" + + " ^^^^^^\n" + + "Invalid unicode\n" + + "----------\n" + ); +} +public void test101() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Character c0 = \'a\';\n" + + " public static void main(String argv[]) {\n" + + " Character c1;\n" + + " c1 = \'b\';\n" + + "\n" + + " Character c2 = \'c\';\n" + + " Character[] c3 = { \'d\' };\n" + + " \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Character c0 = \'a\';\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Character\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " c1 = \'b\';\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Character\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Character c2 = \'c\';\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Character\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " Character[] c3 = { \'d\' };\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Character\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108856 +public void test102() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Object() {\n" + + " {\n" + + " new Object() {\n" + + " {\n" + + " System.out.println(this.getClass().getName());\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + "X$2"); +} +public void test103() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(X.class);\n" + + " }\n" + + "}\n", + }, + "class X"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "// Compiled from X.java (version 1.1 : 45.3, super bit)\n" + + "public class X {\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/Class;\n" + + " static synthetic java.lang.Class class$0;\n" + + " \n" + + " // Method descriptor #9 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [11]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #18 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 3 getstatic X.class$0 : java.lang.Class [25]\n" + + " 6 dup\n" + + " 7 ifnonnull 35\n" + + " 10 pop\n" + + " 11 ldc [27]\n" + + " 13 invokestatic java.lang.Class.forName(java.lang.String) : java.lang.Class [28]\n" + + " 16 dup\n" + + " 17 putstatic X.class$0 : java.lang.Class [25]\n" + + " 20 goto 35\n" + + " 23 new java.lang.NoClassDefFoundError [34]\n" + + " 26 dup_x1\n" + + " 27 swap\n" + + " 28 invokevirtual java.lang.Throwable.getMessage() : java.lang.String [36]\n" + + " 31 invokespecial java.lang.NoClassDefFoundError(java.lang.String) [42]\n" + + " 34 athrow\n" + + " 35 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [45]\n" + + " 38 return\n" + + " Exception Table:\n" + + " [pc: 11, pc: 16] -> 23 when : java.lang.ClassNotFoundException\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 38, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 39] local: args index: 0 type: java.lang.String[]\n" + + "}"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=125570 +public void test104() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Object() {\n" + + " {\n" + + " new Object() {\n" + + " {\n" + + " class Y {\n" + + " {\n" + + " System.out.print(this.getClass());\n" + + " System.out.print(\' \');\n" + + " System.out.print(this.getClass().getName());\n" + + " }\n" + + " }\n" + + " ;\n" + + " new Y();\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "}" + }, + "class X$1$Y X$1$Y"); +} + +// enclosing instance - note that the behavior is different in 1.5 +public void test105() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Y { }\n" + + " static class Z1 {\n" + + " Runnable m;\n" + + " Z1(Runnable p) {\n" + + " this.m = p;\n" + + " }\n" + + " }\n" + + " class Z2 extends Z1 {\n" + + " Z2(final Y p) {\n" + + " super(new Runnable() {\n" + + " public void run() {\n" + + " foo(p);\n" + + " }\n" + + " });\n" + + " }\n" + + " }\n" + + " void foo(Y p) { }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " foo(p);\n" + + " ^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 +public void test106() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "import java.util.zip.*;\n" + + "public class X {\n" + + " void x() throws ZipException {\n" + + " IandJ ij= new K();\n" + + " ij.m();\n" + + " }\n" + + " void y() throws ZipException {\n" + + " K k= new K();\n" + + " k.m();\n" + + " }\n" + + "}\n" + + "interface I { void m() throws IOException; }\n" + + "interface J { void m() throws ZipException; }\n" + + "interface IandJ extends I, J {}\n" + + "class K implements IandJ { public void m() throws ZipException { } }" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " ij.m();\n" + + " ^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 +public void test107() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " C c = new D();\n" + + " c.xyz();\n" + + " }\n" + + "}\n" + + "class AException extends Exception { }\n" + + "class BException extends Exception { }\n" + + "interface A { void xyz() throws AException; }\n" + + "interface B { void xyz() throws BException; }\n" + + "interface C extends A, B { }\n" + + "class D implements C {\n" + + " public void xyz() { System.out.println(1); }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " c.xyz();\n" + + " ^^^^^^^\n" + + "Unhandled exception type AException\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " class AException extends Exception { }\n" + + " ^^^^^^^^^^\n" + + "The serializable class AException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " class BException extends Exception { }\n" + + " ^^^^^^^^^^\n" + + "The serializable class BException does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java new file mode 100644 index 0000000000..3a230b585b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java @@ -0,0 +1,3518 @@ +/******************************************************************************* + * Copyright (c) 2000, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Compliance_1_4 extends AbstractRegressionTest { +boolean docSupport = false; + +public Compliance_1_4(String name) { + super(name); +} + +/* + * Toggle compiler in mode -1.4 + */ +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + if (this.docSupport) { + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, CompilerOptions.ENABLED); + } + return options; +} +public static Test suite() { + return buildUniqueComplianceTestSuite(testClass(), ClassFileConstants.JDK1_4); +} +public static Class testClass() { + return Compliance_1_4.class; +} +// Use this static initializer to specify subset for tests +// All specified tests which does not belong to the class are skipped... +static { +// TESTS_NAMES = new String[] { "test079" }; +// TESTS_NUMBERS = new int[] { 104 }; +// TESTS_RANGE = new int[] { 85, -1 }; +} +/* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ +@Override +protected void setUp() throws Exception { + super.setUp(); + // Javadoc disabled by default + this.docSupport = false; +} + +// test001 - moved to SuperTypeTest#test002 +// test002 - moved to SuperTypeTest#test003 +// test003 - moved to SuperTypeTest#test004 +// test004 - moved to SuperTypeTest#test005 +// test005 - moved to SuperTypeTest#test006 +// test006 - moved to SuperTypeTest#test007 +// test007 - moved to TryStatementTest#test057 +// test008 - moved to LookupTest#test074 +// test009 - moved to RuntimeTests#test1004 + +// check actualReceiverType when array type +public void test010() { + this.runConformTest( + new String[] { + "p1/Z.java", + "package p1; \n"+ + "public class Z { \n" + + " public static void main(String[] arguments) { \n"+ + " String[] s = new String[]{\"SUCCESS\" }; \n" + + " System.out.print(s.length); \n" + + " System.out.print(((String[])s.clone())[0]); \n" + + " } \n"+ + "} \n" + }, + "1SUCCESS"); +} +// test unreachable code complaints +public void test011() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " void foo() { \n"+ + " while (false); \n" + + " while (false) System.out.println(\"unreachable\"); \n" + + " do ; while (false); \n" + + " do System.out.println(\"unreachable\"); while (false); \n" + + " for (;false;); \n" + + " for (;false;) System.out.println(\"unreachable\"); \n" + + " if (false); \n" + + " if (false)System.out.println(\"unreachable\"); \n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " while (false); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 5)\n" + + " while (false) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in p1\\X.java (at line 8)\n" + + " for (;false;); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "4. ERROR in p1\\X.java (at line 9)\n" + + " for (;false;) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "5. WARNING in p1\\X.java (at line 10)\n" + + " if (false); \n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in p1\\X.java (at line 11)\n" + + " if (false)System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + ); +} +// binary compatibility +public void test012() { + this.runConformTest( + new String[] { + "p1/Y.java", + "package p1; \n" + + "class Store { \n" + + " String value; \n" + + " Store(String value){ \n" + + " this.value = value; \n" + + " } \n" + + "} \n" + + "class Top { \n" + + " static String bar = \"Top.bar\"; \n" + + " String foo = \"Top.foo\"; \n" + + " Store store = new Store(\"Top.store\"); \n" + + " static Store sstore = new Store(\"Top.sstore\"); \n" + + " static Top ss = new Top(); \n" + + "} \n" + + "public class Y extends Updated { \n" + + " public static void main(String[] arguments) { \n" + + " new Y().test(); \n" + + " } \n" + + " void test() { \n" + + " System.out.print(\"*** FIELD ACCESS ***\"); \n" + + " System.out.print(\"*1* new Updated().bar: \" + new Updated().bar); \n" + + " System.out.print(\"*2* new Updated().foo: \" + new Updated().foo); \n" + + " System.out.print(\"*3* new Y().foo: \" + new Y().foo); \n" + + " System.out.print(\"*4* new Y().bar: \" + new Y().bar); \n" + + " System.out.print(\"*5* bar: \" + bar); \n" + + " System.out.print(\"*6* foo: \" + foo); \n" + + " System.out.print(\"*7* Y.bar: \" + Y.bar); \n" + + " System.out.print(\"*8* this.bar: \" + this.bar); \n" + + " System.out.print(\"*9* this.foo: \" + this.foo); \n" + + " System.out.print(\"*10* store.value: \" + store.value); \n" + + " System.out.print(\"*11* sstore.value: \" + sstore.value); \n" + + " System.out.print(\"*12* ss.sstore.value: \" + ss.sstore.value); \n" + + " } \n" + + "} \n", + "p1/Updated.java", + "package p1; \n" + + "public class Updated extends Top { \n" + + "} \n" + }, + "*** FIELD ACCESS ***" + +"*1* new Updated().bar: Top.bar" + +"*2* new Updated().foo: Top.foo" + +"*3* new Y().foo: Top.foo" + +"*4* new Y().bar: Top.bar" + +"*5* bar: Top.bar" + +"*6* foo: Top.foo" + +"*7* Y.bar: Top.bar" + +"*8* this.bar: Top.bar" + +"*9* this.foo: Top.foo" + +"*10* store.value: Top.store" + +"*11* sstore.value: Top.sstore" + +"*12* ss.sstore.value: Top.sstore"); + + this.runConformTest( + new String[] { + "p1/Updated.java", + "package p1; \n"+ + "public class Updated extends Top { \n"+ + " public static void main(String[] arguments) { \n"+ + " Y.main(arguments); \n" + + " } \n" + + " static String bar = \"Updated.bar\"; \n" + + " String foo = \"Updated.foo\"; \n" + + " Store store = new Store(\"Updated.store\"); \n" + + " static Store sstore = new Store(\"Updated.sstore\"); \n" + + " static Updated ss = new Updated(); \n" + + "} \n" + }, + "*** FIELD ACCESS ***" + +"*1* new Updated().bar: Updated.bar" + +"*2* new Updated().foo: Updated.foo" + +"*3* new Y().foo: Updated.foo" + +"*4* new Y().bar: Updated.bar" + +"*5* bar: Updated.bar" + +"*6* foo: Updated.foo" + +"*7* Y.bar: Updated.bar" + +"*8* this.bar: Updated.bar" + +"*9* this.foo: Updated.foo" + +"*10* store.value: Updated.store" + +"*11* sstore.value: Updated.sstore" + +"*12* ss.sstore.value: Top.sstore", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} +// binary compatibility +public void test013() { + this.runConformTest( + new String[] { + "p1/Y.java", + "package p1; \n" + + "class Store { \n" + + " String value; \n" + + " Store(String value){ \n" + + " this.value = value; \n" + + " } \n" + + "} \n" + + "class Top { \n" + + " static String bar() { return \"Top.bar()\"; } \n" + + " String foo() { return \"Top.foo()\"; } \n" + + "} \n" + + "public class Y extends Updated { \n" + + " public static void main(String[] arguments) { \n" + + " new Y().test(); \n" + + " } \n" + + " void test() { \n" + + " System.out.print(\"*** METHOD ACCESS ***\"); \n" + + " System.out.print(\"*1* new Updated().bar(): \" + new Updated().bar()); \n" + + " System.out.print(\"*2* new Updated().foo(): \" + new Updated().foo()); \n" + + " System.out.print(\"*3* new Y().foo(): \" + new Y().foo()); \n" + + " System.out.print(\"*4* new Y().bar(): \" + new Y().bar()); \n" + + " System.out.print(\"*5* bar(): \" + bar()); \n" + + " System.out.print(\"*6* foo(): \" + foo()); \n" + + " System.out.print(\"*7* Y.bar(): \" + Y.bar()); \n" + + " System.out.print(\"*8* this.bar(): \" + this.bar()); \n" + + " System.out.print(\"*9* this.foo(): \" + this.foo()); \n" + + " } \n" + + "} \n", + "p1/Updated.java", + "package p1; \n" + + "public class Updated extends Top { \n" + + "} \n" + }, + "*** METHOD ACCESS ***" + +"*1* new Updated().bar(): Top.bar()" + +"*2* new Updated().foo(): Top.foo()" + +"*3* new Y().foo(): Top.foo()" + +"*4* new Y().bar(): Top.bar()" + +"*5* bar(): Top.bar()" + +"*6* foo(): Top.foo()" + +"*7* Y.bar(): Top.bar()" + +"*8* this.bar(): Top.bar()" + +"*9* this.foo(): Top.foo()"); + + this.runConformTest( + new String[] { + "p1/Updated.java", + "package p1; \n"+ + "public class Updated extends Top { \n"+ + " public static void main(String[] arguments) { \n"+ + " Y.main(arguments); \n" + + " } \n" + + " static String bar() { return \"Updated.bar()\"; } \n" + + " String foo() { return \"Updated.foo()\"; } \n" + + "} \n" + }, + "*** METHOD ACCESS ***" + +"*1* new Updated().bar(): Updated.bar()" + +"*2* new Updated().foo(): Updated.foo()" + +"*3* new Y().foo(): Updated.foo()" + +"*4* new Y().bar(): Updated.bar()" + +"*5* bar(): Updated.bar()" + +"*6* foo(): Updated.foo()" + +"*7* Y.bar(): Updated.bar()" + +"*8* this.bar(): Updated.bar()" + +"*9* this.foo(): Updated.foo()", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} + +public void test014() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n" + + "class T { \n" + + " void foo(boolean b) { \n" + + " System.out.print(\"T.foo(boolean)#\"); \n" + + " } \n" + + " boolean bar = false; \n" + + " class Member { \n" + + " void display(){ System.out.print(\"T.Member#\"); } \n" + + " } \n" + + "} \n" + + "public class X { \n" + + " void foo(int i) { \n" + + " System.out.println(\"X.foo(int)#\"); \n" + + " } \n" + + " int bar; \n" + + " class Member { \n" + + " void display(){ System.out.print(\"X.Member#\"); } \n" + + " } \n" + + " public static void main(String[] arguments) { \n" + + " new X().bar(); \n" + + " } \n" + + " void bar() { \n" + + " new T() { \n" + + " { \n" + + " foo(true); \n" + + " System.out.print((boolean)bar + \"#\"); \n" + + " Member m = new Member(); \n" + + " m.display(); \n" + + " } \n" + + " }; \n" + + " } \n" + + "} \n" + }, + "T.foo(boolean)#false#T.Member#"); +} + +/* + * check handling of default abstract methods + */ +public void test015() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " C c = new C() { \n"+ + " public void doSomething(){ \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " }; \n"+ + " c.doSomething(); \n"+ + " } \n"+ + "} \n"+ + "interface I { \n"+ + " void doSomething(); \n"+ + "} \n"+ + "abstract class C implements I { \n"+ + "} \n" + }, + "SUCCESS"); +} + +public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(boolean b) {} \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " foo(0); \n" + + " ^^^\n" + + "The method foo(boolean) in the type T is not applicable for the arguments (int)\n" + + "----------\n"); +} + +public void test017() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(boolean b) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(false); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} + +public void test018() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(int j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +public void test019() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(int j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "class U { \n"+ + " void foo(int j) { System.out.println(\"FAILED\"); } \n"+ + "} \n"+ + "public class X extends U { \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +public void test020() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(int j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "class U { \n"+ + " void foo(boolean j) { System.out.println(\"FAILED\"); } \n"+ + "} \n"+ + "public class X extends U { \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +public void test020a() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(U j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "class U { \n"+ + "} \n"+ + "public class X extends U { \n"+ + " void foo(X j) { System.out.println(\"FAILED\"); } \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(new X()); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +// binary check for 11511 +public void test021() { + this.runConformTest( + new String[] { + "p1/Z.java", + "package p1; \n" + + "public class Z extends AbstractA { \n" + + " public static void main(String[] arguments) { \n" + + " new Z().init(); \n" + + " } \n" + + "} \n" + + "abstract class AbstractB implements K { \n" + + " public void init() { \n" + + " System.out.println(\"AbstractB.init()\"); \n" + + " } \n" + + "} \n" + + "interface K { \n" + + " void init(); \n" + + " void init(int i); \n" + + "} \n", + "p1/AbstractA.java", + "package p1; \n" + + "public abstract class AbstractA extends AbstractB implements K { \n" + + " public void init(int i) { \n" + + " } \n" + + "} \n" + }, + "AbstractB.init()"); // no special vm args + + // check that "new Z().init()" is bound to "Z.init()" + String computedReferences = findReferences(OUTPUT_DIR + "/p1/Z.class"); + boolean check = + computedReferences.indexOf("constructorRef/Z/0") >= 0 + && computedReferences.indexOf("methodRef/init/0") >= 0; + if (!check){ + System.out.println(computedReferences); + } + assertTrue("did not bind 'new Z().init()' to Z.init()'", check); +} + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis + */ +public void test022() { + + this.runNegativeTest( + new String[] { + "p1/T.java", + "package p1; \n"+ + "interface II {} \n"+ + "class TT { \n"+ + " void foo(boolean b) {} \n"+ + " void foo(int i, boolean b) {} \n"+ + " void foo(String s) {} \n"+ + "} \n"+ + "public abstract class T implements II { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(0); // should say that foo(int, boolean) isn't applicable \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void boo() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(true); // should not complain about ambiguity \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\T.java (at line 13)\n" + + " foo(0); // should say that foo(int, boolean) isn\'t applicable \n" + + " ^^^\n" + + "The method foo(int, boolean) in the type TT is not applicable for the arguments (int)\n" + + "----------\n"); +} + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis + */ +public void test023() { + + this.runNegativeTest( + new String[] { + "p1/T.java", + "package p1; \n"+ + "interface II {} \n"+ + "abstract class TT { \n"+ // 259+ABSTRACT + " void foo(boolean b) {} \n"+ + " void foo(int i, boolean b) {} \n"+ + " void foo(String s) {} \n"+ + "} \n"+ + "public abstract class T implements II { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(0); // should say that foo(int, boolean) isn't applicable \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void boo() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(true); // should complain ambiguity \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\T.java (at line 13)\n" + + " foo(0); // should say that foo(int, boolean) isn\'t applicable \n" + + " ^^^\n" + + "The method foo(int, boolean) in the type TT is not applicable for the arguments (int)\n" + + "----------\n"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis + */ +public void test024() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "interface II {} \n"+ + "abstract class T implements II { \n"+ + " void foo(boolean b) {} \n"+ + " void foo(int i, boolean b) {} \n"+ + "} \n"+ + "abstract class TT implements II { \n"+ + " void foo(boolean b) {} \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); // javac says foo cannot be resolved because of multiple matches \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void bar2() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(0); // should say that foo(boolean) isn't applicable \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void boo() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(true); // should complain ambiguity \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 15)\n" + + " foo(0); // javac says foo cannot be resolved because of multiple matches \n" + + " ^^^\n" + + "The method foo(int, boolean) in the type T is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 22)\n" + + " foo(0); // should say that foo(boolean) isn\'t applicable \n" + + " ^^^\n" + + "The method foo(boolean) in the type TT is not applicable for the arguments (int)\n" + + "----------\n"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis (no matter if super is abstract or not) + */ +public void test025() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X extends AbstractY { \n"+ + " void bar(){ \n"+ + " init(\"hello\"); \n"+ + " } \n"+ + "} \n"+ + "abstract class AbstractY implements I { \n"+ + "} \n"+ + "interface I { \n"+ + " void init(String s, int i); \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public class X extends AbstractY { \n" + + " ^\n" + + "The type X must implement the inherited abstract method I.init(String, int)\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 4)\n" + + " init(\"hello\"); \n" + + " ^^^^\n" + + "The method init(String, int) in the type I is not applicable for the arguments (String)\n" + + "----------\n"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis (no matter if super is abstract or not) + */ +public void test026() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X extends AbstractY { \n"+ + " void bar(){ \n"+ + " init(\"hello\"); \n"+ + " } \n"+ + "} \n"+ + "class AbstractY implements I { \n"+ + "} \n"+ + "interface I { \n"+ + " void init(String s, int i); \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " init(\"hello\"); \n" + + " ^^^^\n" + + "The method init(String, int) in the type I is not applicable for the arguments (String)\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 7)\n" + + " class AbstractY implements I { \n" + + " ^^^^^^^^^\n" + + "The type AbstractY must implement the inherited abstract method I.init(String, int)\n" + + "----------\n" +); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11922 + * should report unreachable empty statement + */ +public void test027() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " for (;false;p()); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " static void p(){ \n"+ + " System.out.println(\"FAILED\"); \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. WARNING in p1\\X.java (at line 4)\n" + + " for (;false;p()); \n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 4)\n" + + " for (;false;p()); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=12445 + * should report unreachable empty statement + */ +public void test028() { + + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n" + + "interface FooInterface { \n" + + " public boolean foo(int a); \n" + + " public boolean bar(int a); \n" + + "} \n" + + "public class X extends Z { \n" + + " public boolean foo(int a){ return true; } \n" + + " public boolean bar(int a){ return false; } \n" + + " public static void main(String[] arguments) { \n"+ + " System.out.println(new X().test(0)); \n"+ + " } \n" + + "}\n" + + "abstract class Z implements FooInterface { \n" + + " public boolean foo(int a, int b) { \n" + + " return true; \n" + + " } \n" + + " public String test(int a) { \n" + + " boolean result = foo(a); \n" + + " if (result) \n" + + " return \"SUCCESS\"; \n" + + " else \n" + + " return \"FAILED\"; \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * verify error on qualified name ref in 1.4 + */ +public void test029() { + + this.runConformTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args) { \n" + + " new X(); \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " Woof woof_1; \n" + + " public class Honk { \n" + + " Integer honks; \n" + + " } \n" + + " public class Meow { \n" + + " Honk honk_1; \n" + + " } \n" + + " public class Woof { \n" + + " Meow meow_1; \n" + + " } \n" + + " public void setHonks(int num) { \n" + + " // This is the line that causes the VerifyError \n" + + " woof_1.meow_1.honk_1.honks = new Integer(num); \n" + + " // Here is equivalent code that does not cause the error. \n" + + " // Honk h = woof_1.moo_1.meow_1.honk_1; \n" + + " // h.honks = new Integer(num); \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * 1.4 signals invocations of non-visible abstract protected method implementations. + */ +public void test030() { + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args){ \n" + + " new q.X2().foo(\"String\"); \n" + + " new q.X2().bar(\"String\"); \n" + + " new q.X2().barbar(\"String\"); \n" + + " new q.X2().baz(\"String\"); \n" + + " } \n" + + "} \n", + + "p/X1.java", + "package p; \n" + + "public abstract class X1 { \n" + + " protected void foo(Object o){ System.out.println(\"X1.foo(Object)\"); } \n" + + " protected void bar(Object o){ System.out.println(\"X1.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X1.barbar(Object)\"); } \n" + + " protected void baz(Object o) { System.out.println(\"X1.baz(Object)\"); } \n" + + "} \n", + + "q/X2.java", + "package q; \n" + + "public class X2 extends p.X1 { \n" + + " protected void foo(int i) { System.out.println(\"X2.foo(int)\"); } \n" + + " protected void bar(Object o) { System.out.println(\"X2.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " protected void baz(String s) { System.out.println(\"X2.baz(String)\"); } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " new q.X2().bar(\"String\"); \n" + + " ^^^\n" + + "The method bar(Object) from the type X2 is not visible\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 6)\n" + + " new q.X2().barbar(\"String\"); \n" + + " ^^^^^^\n" + + "The method barbar(Object) from the type X2 is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in q\\X2.java (at line 5)\n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method X2.barbar(Object) does not override the inherited method from X1 since it is private to a different package\n" + + "----------\n"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * 1.4 signals invocations of non-visible abstract protected method implementations. + */ +public void test031() { + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X extends q.X2 { \n" + + " public static void main(String[] args){ \n" + + " new X().doSomething(); \n" + + " } \n" + + " void doSomething(){ \n" + + " foo(\"String\"); \n" + + " bar(\"String\"); \n" + + " barbar(\"String\"); \n" + + " baz(\"String\"); \n" + + " } \n" + + "} \n", + + "p/X1.java", + "package p; \n" + + "public abstract class X1 { \n" + + " protected void foo(Object o){ System.out.println(\"X1.foo(Object)\"); } \n" + + " protected void bar(Object o){ System.out.println(\"X1.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X1.barbar(Object)\"); } \n" + + " protected void baz(Object o) { System.out.println(\"X1.baz(Object)\"); } \n" + + "} \n", + + "q/X2.java", + "package q; \n" + + "public class X2 extends p.X1 { \n" + + " protected void foo(int i) { System.out.println(\"X2.foo(int)\"); } \n" + + " protected void bar(Object o) { System.out.println(\"X2.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " protected void baz(String s) { System.out.println(\"X2.baz(String)\"); } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 9)\n" + + " barbar(\"String\"); \n" + + " ^^^^^^\n" + + "The method barbar(Object) from the type X2 is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in q\\X2.java (at line 5)\n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method X2.barbar(Object) does not override the inherited method from X1 since it is private to a different package\n" + + "----------\n" +); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * 1.4 signals invocations of non-visible abstract protected field implementations. + */ +public void test032() { + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args){ \n" + + " System.out.println(new q.X2().foo); \n" + + " System.out.println(new q.X2().bar); \n" + + " } \n" + + "} \n", + + "p/X1.java", + "package p; \n" + + "public abstract class X1 { \n" + + " protected String foo = \"X1.foo\"; \n" + + " String bar = \"X1.bar\"; \n" + + "} \n", + + "q/X2.java", + "package q; \n" + + "public class X2 extends p.X1 { \n" + + " protected String foo = \"X2.foo\"; \n" + + " String bar = \"X2.bar\"; \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 4)\n" + + " System.out.println(new q.X2().foo); \n" + + " ^^^\n" + + "The field X2.foo is not visible\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 5)\n" + + " System.out.println(new q.X2().bar); \n" + + " ^^^\n" + + "The field X2.bar is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in q\\X2.java (at line 3)\n" + + " protected String foo = \"X2.foo\"; \n" + + " ^^^\n" + + "The field X2.foo is hiding a field from type X1\n" + + "----------\n"); +} + +/* + * Initialization of synthetic fields prior to super constructor call + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23075 + */ +public void test033() { + + this.runConformTest( + new String[] { + "A.java", + "public class A { \n"+ + " public int m; \n"+ + " public void pp() { \n"+ + " C c = new C(4); \n"+ + " System.out.println(c.get()); \n"+ + " } \n"+ + " public static void main(String[] args) { \n"+ + " A a = new A(); \n"+ + " try { \n"+ + " a.pp(); \n"+ + " System.out.println(\"SyntheticInit BEFORE SuperConstructorCall\"); \n"+ + " } catch(NullPointerException e) { \n"+ + " System.out.println(\"SyntheticInit AFTER SuperConstructorCall\"); // should no longer occur with target 1.4 \n"+ + " } \n"+ + " } \n"+ + " class C extends B { \n"+ + " public C(int x1) { \n"+ + " super(x1); \n"+ + " } \n"+ + " protected void init(int x1) { \n"+ + " x = m * x1; // <- NULL POINTER EXCEPTION because of m \n"+ + " } \n"+ + " } \n"+ + "} \n"+ + "class B { \n"+ + " int x; \n"+ + " public B(int x1) { \n"+ + " init(x1); \n"+ + " } \n"+ + " protected void init(int x1) { \n"+ + " x = x1; \n"+ + " } \n"+ + " public int get() { \n"+ + " return x; \n"+ + " } \n"+ + "} \n" + }, + "0\n" + + "SyntheticInit BEFORE SuperConstructorCall"); +} +/* + * Initialization of synthetic fields prior to super constructor call - NPE check + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=25174 + */ +public void test034() { + + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new X2(); \n"+ + " } \n"+ + " class X1 { \n"+ + " X1(){ \n"+ + " this.baz(); \n"+ + " } \n"+ + " void baz() { \n"+ + " System.out.println(\"-X1.baz()\"); \n"+ + " } \n"+ + " } \n"+ + " class X2 extends X1 { \n"+ + " void baz() { \n"+ + " System.out.print(X.this==null ? \"X.this == null\" : \"X.this != null\"); \n"+ + " X1 x1 = X.this.new X1(){ \n"+ + " void baz(){ \n"+ + " System.out.println(\"-X$1.baz()\"); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " } \n"+ + "}\n", + }, + "X.this != null-X$1.baz()"); +} + +public void test035() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " class Y { Y(int i){} } \n"+ + " public static void main(String[] arguments) { \n"+ + " int i = 1; \n" + + " try { \n" + + " X x =null; \n" + + " x.new Y(++i); \n" + // i won't get incremented before NPE + " System.out.println(\"FAILED\"); \n" + + " } catch(NullPointerException e){ \n" + + " System.out.println(\"SUCCESS:\"+i); \n" + + " } \n" + + " } \n"+ + "} \n", + }, + "SUCCESS:1" + ); +} + +public void test036() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " class Y {} \n"+ + " static class Z extends Y { \n"+ + " Z (X x){ \n"+ + " x.super(); \n" + + " } \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " try { \n" + + " new Z(null); \n" + + " System.out.println(\"FAILED\"); \n" + + " } catch(NullPointerException e){ \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=24744 + * http://dev.eclipse.org/bugs/show_bug.cgi?id=23096 + * + * NOTE: since JLS got revised to allow unterminated line comments (32476) + */ +public void test037() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_TaskTags, "TODO:"); + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n"+ + "public class X {\n"+ + "}\n"+ + "// TODO: something" + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 4)\n" + + " // TODO: something\n" + + " ^^^^^^^^^^^^^^^\n" + + "TODO: something\n" + + "----------\n", + null, + true, + customOptions); +} + +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=24833 + * http://dev.eclipse.org/bugs/show_bug.cgi?id=23096 + * + * NOTE: since JLS got revised to allow unterminated line comments (32476) + */ +public void test038() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_TaskTags, "TODO:"); + this.runNegativeTest( + new String[] { + "X.java", + "// TODO: something" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " // TODO: something\n" + + " ^^^^^^^^^^^^^^^\n" + + "TODO: something\n" + + "----------\n", + null, + true, + customOptions, + "java.lang.ClassNotFoundException"); +} + +/* + * unreachable empty statement/block are diagnosed in 1.3 + */ +public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args){ \n"+ + " for (;null != null;); \n"+ + " for (;null != null;){} \n"+ + " for (;false;); \n"+ + " for (;false;){} \n"+ + " while (false); \n"+ + " while (false){} \n"+ + " if (false) {} else {} \n"+ + " if (false) ; else ; \n"+ + " System.out.println(\"FAILED\"); \n" + + " } \n"+ + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " for (;false;); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " for (;false;){} \n" + + " ^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " while (false); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " while (false){} \n" + + " ^^\n" + + "Unreachable code\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " if (false) {} else {} \n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " if (false) ; else ; \n" + + " ^\n" + + "Dead code\n" + + "----------\n" +); +} +// jls6.5.5.1 - simple type names favor member type over toplevel one. +//http://bugs.eclipse.org/bugs/show_bug.cgi?id=30705 +public void test040() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " interface Homonym {} \n"+ // takes precedence over others. + " void foo() { \n"+ + " class Homonym extends X { \n"+ + " { \n"+ + " class Y extends Homonym {}; \n"+ // X$Homonym + " } \n"+ + " } \n"+ + " } \n"+ + "} \n"+ + "class Homonym extends X { \n"+ + " { \n"+ + " class Y extends Homonym {}; \n"+ // X$Homonym + " } \n"+ + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class Homonym extends X { \n" + + " ^^^^^^^\n" + + "The type Homonym is hiding the type X.Homonym\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class Y extends Homonym {}; \n" + + " ^^^^^^^\n" + + "The type X.Homonym cannot be the superclass of Y; a superclass must be a class\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " class Y extends Homonym {}; \n" + + " ^^^^^^^\n" + + "The type X.Homonym cannot be the superclass of Y; a superclass must be a class\n" + + "----------\n"); +} +/* + * 30856 - 1.4 compliant mode should consider abstract method matches + */ +public void test041() { + this.runConformTest( + new String[] { + "p/X.java", //================================ + "package p; \n" + + "public class X { \n" + + " void foo(int i, float f){} \n" + + " public static void main(String[] args) { \n" + + " q.Y y = new q.Y.Z(); \n" + + " y.bar(); \n" + + " } \n" + + "} \n", + "q/Y.java", //================================ + "package q; \n" + + "public abstract class Y extends p.X implements I { \n" + + " public void bar(){ foo(1, 2); } \n" + + " public static class Z extends Y { \n" + + " public void foo(float f, int i) { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + "} \n" + + "interface I { \n" + + " void foo(float f, int i); \n" + + "} \n", + }, + "SUCCESS"); +} +/* + * variation - 30856 - 1.4 compliant mode should consider abstract method matches + */ +public void test042() { + this.runConformTest( + new String[] { + "p/X.java", //================================ + "package p; \n" + + "public class X extends X0 { \n" + + " void foo(int i, float f){} \n" + + " public static void main(String[] args) { \n" + + " q.Y y = new q.Y.Z(); \n" + + " y.bar(); \n" + + " } \n" + + "} \n" + + "class X0 { \n" + + " void foo(int i, double d){} \n" + // extra match + "} \n", + "q/Y.java", //================================ + "package q; \n" + + "public abstract class Y extends p.X implements I { \n" + + " public void bar(){ foo(1, 2); } \n" + + " public static class Z extends Y { \n" + + " public void foo(float f, int i) { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + "} \n" + + "interface I { \n" + + " void foo(float f, int i); \n" + + "} \n", + }, + "SUCCESS"); +} + +// binary compatibility +public void _test043() { + this.runConformTest( + new String[] { + "p1/Y.java", + "package p1; \n" + + "public class Y extends A implements I { \n" + + " public static void main(String[] args) { \n" + + " Y.printValues(); \n" + + " } \n" + + " public static void printValues() { \n" + + " System.out.println(\"i=\"+i+\",j=\"+j+\",Y.i=\"+Y.i+\",Y.j=\"+Y.j); \n" + + " } \n" + + "} \n", + "p1/A.java", + "package p1; \n" + + "public class A { \n" + + " static int i = 1; \n" + + "} \n", + "p1/I.java", + "package p1; \n" + + "interface I { \n" + + " int j = \"aa\".length(); \n" + + "} \n", + }, + "i=1,j=2,Y.i=1,Y.j=2"); + + this.runConformTest( + new String[] { + "p1/A.java", + "package p1; \n" + + "public class A { \n" + + " static int j = 3; \n" + + " public static void main(String[] args) { \n" + + " Y.printValues(); \n" + + " } \n" + + "} \n", + "p1/I.java", + "package p1; \n" + + "interface I { \n" + + " int j = \"aaaa\".length(); \n" + + "} \n", + }, + "i=4,j=3,Y.i=4,Y.j=3", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} +/* + * array.clone() should use array type in methodRef + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=36307 + */ +public void test044() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " args.clone(); \n"+ + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel <= ClassFileConstants.JDK1_4 + ? " 1 invokevirtual java.lang.Object.clone() : java.lang.Object [16]\n" + : " 1 invokevirtual java.lang.String[].clone() : java.lang.Object [16]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +// 39172 +public void test045() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args) { \n" + + " System.out.println(\"FAILED\"); \n" + + " return;; \n" + // unreachable empty statement - must complain in 1.4 mode + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " return;; \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39467 + * should diagnose missing abstract method implementation + */ +public void test046() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + "}\n" + + "abstract class Y extends Z {\n" + + " public abstract void foo();\n" + + "}\n" + + "abstract class Z extends T {\n" + + "}\n" + + "class T implements I {\n" + + " public void foo(){}\n" + + "}\n" + + "interface I {\n" + + " public void foo ();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y {\n" + + " ^\n" + + "The type X must implement the inherited abstract method Y.foo()\n" + + "----------\n" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40442 + * Abstract class fails to invoke interface-defined method in 1.4 compliance mode. + */ +public void test047() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends AbstractDoubleAlgorithm {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " ((ObjectAlgorithm)(new X())).operate(new Double(0));\n" + + " }\n" + + " public void operate(Double pDouble)\n" + + " {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "abstract class AbstractDoubleAlgorithm implements DoubleAlgorithm {\n" + + " public void operate(Object pObject)\n" + + " {\n" + + " operate((Double)pObject);\n" + + " }\n" + + "}\n" + + "interface DoubleAlgorithm extends ObjectAlgorithm {\n" + + " void operate(Double pDouble);\n" + + "}\n" + + "interface ObjectAlgorithm {\n" + + " void operate(Object pObject);\n" + + "}" + }, + "SUCCESS" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40442 + * Abstract class fails to invoke interface-defined method in 1.4 compliance mode. + * variation with 2 found methods + */ +public void test048() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends AbstractDoubleAlgorithm {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " ((ObjectAlgorithm)(new X())).operate(new Double(0));\n" + + " }\n" + + " public void operate(Double pDouble)\n" + + " {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "abstract class AbstractDoubleAlgorithm implements DoubleAlgorithm {\n" + + " public void operate(Object pObject)\n" + + " {\n" + + " operate((Double)pObject);\n" + + " }\n" + + " public void operate(X x) {}\n" + + "}\n" + + "interface DoubleAlgorithm extends ObjectAlgorithm {\n" + + " void operate(Double pDouble);\n" + + "}\n" + + "interface ObjectAlgorithm {\n" + + " void operate(Object pObject);\n" + + "}" + }, + "SUCCESS" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=41278 + */ +public void test049() { + this.runNegativeTest( + new String[] { + "pa/Caller.java", + "package pa;\n" + + "import pb.Concrete;\n" + + "public class Caller {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Concrete aConcrete = new Concrete(); \n" + + " aConcrete.callme();\n" + + " }\n" + + "}\n", + "pa/Abstract.java", + "package pa;\n" + + "public abstract class Abstract {\n" + + "\n" + + " protected void callme(){}\n" + + "}\n", + "pb/Concrete.java", + "package pb;\n" + + "public class Concrete extends pa.Abstract {\n" + + "\n" + + " protected void callme(){ System.out.println(\"SUCCESS\"); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in pa\\Caller.java (at line 7)\n" + + " aConcrete.callme();\n" + + " ^^^^^^\n" + + "The method callme() from the type Concrete is not visible\n" + + "----------\n"); +} + +public void test050() { + this.runNegativeTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " int a1 = 1;\n" + + " int a2 = 1;\n" + + " a1 = 2;\n" + + " while (false) {};\n" + + " a2 = 2;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 10)\n" + + " while (false) {};\n" + + " ^^\n" + + "Unreachable code\n" + + "----------\n"); +} + +public void test051() { + this.runNegativeTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " int a1 = 1;\n" + + " int a2 = 1;\n" + + " a1 = 2;\n" + + " while (false);\n" + + " a2 = 2;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 10)\n" + + " while (false);\n" + + " ^\n" + + "Unreachable code\n" + + "----------\n"); +} + +public void test052() { + this.runNegativeTest( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static void main(String[] argv) {\n" + + " foo();\n" + + " }\n" + + " private int i;\n" + + " static class Y extends X {\n" + + " int x = i;\n" + + " }\n" + + " public static void foo() {\n" + + " return;\n" + + " }\n" + + "}", + + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " int a1 = 1;\n" + + " int a2 = 1;\n" + + " a1 = 2;\n" + + " while (false);\n" + + " a2 = 2;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in p\\A.java (at line 6)\n" + + " private int i;\n" + + " ^\n" + + "The value of the field A.i is not used\n" + + "----------\n" + + "2. ERROR in p\\A.java (at line 8)\n" + + " int x = i;\n" + + " ^\n" + + "Cannot make a static reference to the non-static field i\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p\\X.java (at line 10)\n" + + " while (false);\n" + + " ^\n" + + "Unreachable code\n" + + "----------\n"); +} + +public void test053() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "class X {\n" + + " static class A {\n" + + " interface I {\n" + + " int a = 3;\n" + + " }\n" + + " } \n" + + " interface I { \n" + + " int b = 4;\n" + + " }\n" + + " class Y extends A implements I {\n" + + " Object F() {\n" + + " return new I() {\n" + + " int c = a; // WE SHOULD NOT BE ABLE TO SEE BOTH a and b\n" + + " int d = b; // WE SHOULD NOT BE ABLE TO SEE BOTH a and b\n" + + " };\n" + + " }\n" + + " }\n" + + "}", + } + ); +} + +public void test054() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " static class A {\n" + + " interface I {\n" + + " int a = 3;\n" + + " void foo();\n" + + " }\n" + + " }\n" + + " interface I {\n" + + " int a = 4;\n" + + " void foo();\n" + + " }\n" + + " class Y extends A implements I {\n" + + " public void foo() {\n" + + " new I() {\n" + + " public void foo() {\n" + + " System.out.println(\"X$1::foo-\" + a);\n" + + " }\n" + + " }\n" + + " .foo();\n" + + " }\n" + + " }\n" + + "public static void main(String argv[]) {\n" + + " new X().new Y().foo();\n" + + "}\n" + + "}", + } + ); +} +public void test055() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " static class A {\n" + + " interface I2 {\n" + + " int a = 3;\n" + + " void foo();\n" + + " }\n" + + " }\n" + + " interface I1 {\n" + + " int a = 4;\n" + + " void foo(int a);\n" + + " }\n" + + " class Y extends A implements I1 {\n" + + " public void foo(int a) {\n" + + " new I2() {\n" + + " public void foo() {\n" + + " System.out.println(\"X$1::foo-\" + a);\n" + + " }\n" + + " }\n" + + " .foo();\n" + + " }\n" + + " }\n" + + "public static void main(String argv[]) {\n" + + " new X().new Y().foo(8);\n" + + "}\n" + + "}", + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 11)\n" + + " void foo(int a);\n" + + " ^\n" + + "The parameter a is hiding a field from type X.I1\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 14)\n" + + " public void foo(int a) {\n" + + " ^\n" + + "The parameter a is hiding a field from type X.I1\n" + + "----------\n" + ); +} + +public void test056() { + this.runConformTest( + new String[] { + "p/MethodQualification.java", + "package p;\n" + + "public class MethodQualification {\n" + + " void foo() {\n" + + " System.out.println(\"Inherited foo() for anonymous type\");\n" + + " class Local {\n" + + " void foo(){\n" + + " System.out.println(\"Enclosing foo() for anonymous type\");\n" + + " new MethodQualification () { {foo();} };\n" + + " }\n" + + " };\n" + + " } \n" + + "}", + }, + "" + ); +} + +public void test057() { + this.runConformTest( + new String[] { + "p/AG.java", + "package p;\n" + + "/**\n" + + " * 1F9RITI\n" + + " */\n" + + "public class AG {\n" + + " public class X {\n" + + " class B {\n" + + " int intValueOfB = -9;\n" + + " }\n" + + " class SomeInner extends A {\n" + + " void someMethod() {\n" + + " int i = new B().intValueOfB; \n" + + " }\n" + + " }\n" + + " }\n" + + " class A {\n" + + " class B {\n" + + " int intValueOfB = -9;\n" + + " }\n" + + " }\n" + + "}", + }, + "" + ); +} + +public void test058() { + this.runConformTest( + new String[] { + "p/AE.java", + "package p;\n" + + "/**\n" + + " * 1F9RITI\n" + + " */\n" + + "public class AE {\n" + + " public class X {\n" + + " int intValue = 153;\n" + + " class SomeInner extends A {\n" + + " void someMethod() {\n" + + " int i = intValue; \n" + + " }\n" + + " }\n" + + " }\n" + + " class A {\n" + + " int intValue = 153;\n" + + " }\n" + + "}", + }, + "" + ); +} + +public void test059() { + this.runNegativeTest( + new String[] { + "p/FieldQualification.java", + "package p;\n" + + "public class FieldQualification {\n" + + " String field = \"Inherited field for anonymous type\";\n" + + "void foo() {\n" + + " class Local {\n" + + " String field = \"Enclosing field for anonymous type\";\n" + + " void foo() {\n" + + " System.out.println(\"Enclosing foo() for anonymous type\");\n" + + " new FieldQualification() {\n" + + " {\n" + + " System.out.println(field);\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + "}\n" + + "}", + }, + "----------\n" + + "1. WARNING in p\\FieldQualification.java (at line 5)\n" + + " class Local {\n" + + " ^^^^^\n" + + "The type Local is never used locally\n" + + "----------\n" + + "2. WARNING in p\\FieldQualification.java (at line 6)\n" + + " String field = \"Enclosing field for anonymous type\";\n" + + " ^^^^^\n" + + "The field Local.field is hiding a field from type FieldQualification\n" + + "----------\n" + + "3. WARNING in p\\FieldQualification.java (at line 6)\n" + + " String field = \"Enclosing field for anonymous type\";\n" + + " ^^^^^\n" + + "The value of the field Local.field is not used\n" + + "----------\n" + + "4. WARNING in p\\FieldQualification.java (at line 7)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type Local is never used locally\n" + + "----------\n"); +} + +public void test060() { + this.runConformTest( + new String[] { + "p/AF.java", + "package p;\n" + + "/**\n" + + " * 1F9RITI\n" + + " */\n" + + "public class AF {\n" + + " public class X {\n" + + " int intMethod() {\n" + + " return 3333;\n" + + " }\n" + + " class SomeInner extends A {\n" + + " void someMethod() {\n" + + " int i = intMethod();\n" + + " }\n" + + " }\n" + + " }\n" + + " class A {\n" + + " int intMethod() {\n" + + " return 3333;\n" + + " }\n" + + " }\n" + + "}", + }, + "" + ); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=32342 + */ +public void test061() { + this.runNegativeTest( + new String[] { + "p/X.java", //====================== + "package p; \n" + + "public class X extends q.Y { \n" + + " X someField; \n" + // no ambiguity since inherited Y.X isn't visible + "} \n" + + "class Z extends q.Y { \n" + + " Z someField; \n" + // ambiguous + "} \n", + "q/Y.java", //====================== + "package q; \n" + + "public class Y { \n" + + " private static class X {} \n" + + " public static class Z {} \n" + + "} \n" + }, + "----------\n" + + "1. WARNING in q\\Y.java (at line 3)\n" + + " private static class X {} \n" + + " ^\n" + + "The type Y.X is never used locally\n" + + "----------\n"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11435 + * variant - must still complain when targeting super abstract method + */ +public void test062() { + + this.runNegativeTest( + new String[] { + "p1/Y.java", + "package p1; \n"+ + "public class Y extends AbstractT { \n"+ + " public void init(){ \n"+ + " super.init(); \n"+ + " } \n"+ + "} \n"+ + "abstract class AbstractT implements J { \n"+ + "} \n"+ + "interface J { \n"+ + " void init(); \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\Y.java (at line 4)\n" + + " super.init(); \n" + + " ^^^^^^^^^^^^\n" + + "Cannot directly invoke the abstract method init() for the type J\n" + + "----------\n"); // expected log +} + +public void test063() { + this.runNegativeTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " class Y extends X {} \n"+ + " class Z extends Y { \n"+ + " Z(){ \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n" + + " } \n" + + " public static void main(String[] arguments) { \n"+ + " new X().new Z(); \n"+ + " } \n"+ + "} \n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 5)\n" + + " Z(){ \n" + + " ^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n" + ); +} + +/** + * Refuse selection of own enclosing instance arg for super constructor call in 1.3 compliant mode + */ +public void test064() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public class Foo {\n" + + " public static void main(String[] args) {\n"+ + " System.out.println(\"SUCCESS\");\n"+ + " }\n"+ + " public class Bar extends Foo {\n" + + " public Bar() {\n" + + " }\n" + + " }\n" + + " public class Baz extends Bar {\n" + + " public Baz() {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 10)\n" + + " public Baz() {\n" + + " ^^^^^\n" + + "No enclosing instance of type Foo is available due to some intermediate constructor invocation\n" + + "----------\n"); +} + +public void test065() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new Y().new Z().bar(); \n"+ + " } \n"+ + " String foo() { return \"X-foo\"; } \n"+ + " class Y extends X { \n"+ + " String foo() { return \"Y-foo\"; } \n"+ + " class Z extends Y { \n"+ + " Z(){ \n"+ + " //X.this.super(); \n"+ + " } \n"+ + " String foo() { return \"Z-foo\"; } \n"+ + " void bar () { \n"+ + " System.out.println(X.this.foo()); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Z(){ \n" + + " ^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); +} + +/* + * Check that anonymous type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test066() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(Object o) {}\n" + + " class M extends X {\n" + + " M(){\n" + + " super(null);\n" + + " }\n" + + " M(Object o) {\n" + + " super(new M(){});\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(new M(){});\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 M(){});\n" + + " ^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); +} + +/* + * Check that indirect member type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test067() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(Object o) {\n" + + " }\n" + + " class N extends X {\n" + + " N(Object o) {\n" + + " super(o);\n" + + " }\n" + + " }\n" + + " class M extends N {\n" + + " M() {\n" + + " super(null); //1\n" + + " }\n" + + " M(Object o) {\n" + + " super(new M());//2\n" + + " }\n" + + " }\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"); +} + +/* + * Check that indirect member type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test068() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX1 extends X {\n" + + " MX1() {\n" + + " }\n" + + " }\n" + + " class MX2 extends MX1 {\n" + + " MX2() {\n" + + " super(); // ko\n" + + " }\n" + + " MX2(X x) {\n" + + " this(); // ok\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(); // ko\n" + + " ^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); +} + +/* + * Check that indirect member type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test069() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX3 extends X {\n" + + " MX3(X x) {\n" + + " }\n" + + " }\n" + + " class MX4 extends MX3 {\n" + + " MX4() {\n" + + " super(new MX4()); // ko\n" + + " }\n" + + " MX4(X x) {\n" + + " this(); // ok\n" + + " }\n" + + " MX4(int i) {\n" + + " this(new MX4()); // ko\n" + + " }\n" + + " }\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"); +} + +// binary compatibility +public void test070() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Middle {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(new X().field);\n" + + " }\n" + + "}\n" + + "class Middle extends Top {\n" + + "}\n" + + "class Top {\n" + + " String field = \"Top.field\";\n" + + "}\n" + }, + "Top.field"); + + this.runConformTest( + new String[] { + "Middle.java", + "public class Middle extends Top {\n" + + " public static void main(String[] arguments) { \n"+ + " X.main(arguments); \n" + + " } \n" + + " String field = \"Middle.field\";\n" + + "}\n" + }, + "Middle.field", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} + +/* + * 43429 - AbstractMethodError calling clone() at runtime when using Eclipse compiler + */ +public void test071() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public interface Copyable extends Cloneable {\n" + + " public Object clone() throws CloneNotSupportedException;\n" + + " }\n" + + " public interface TestIf extends Copyable {\n" + + " }\n" + + " public static class ClassA implements Copyable {\n" + + " public Object clone() throws CloneNotSupportedException {\n" + + " return super.clone();\n" + + " }\n" + + " }\n" + + " public static class ClassB implements TestIf {\n" + + " public Object clone() throws CloneNotSupportedException {\n" + + " return super.clone();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " Copyable o1 = new ClassA();\n" + + " ClassB o2 = new ClassB();\n" + + " TestIf o3 = o2;\n" + + " Object clonedObject;\n" + + " clonedObject = o1.clone();\n" + + " clonedObject = o2.clone();\n" + + " // The following line fails at runtime with AbstractMethodError when\n" + + " // compiled with Eclipse\n" + + " clonedObject = o3.clone();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +public void test072() { + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " f();\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " static void f() {\n" + + " Object x = new Object() {\n" + + " {\n" + + " if (true) throw null;\n" + + " }\n" + + " };\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +// 52221 +public void test073() { + + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " public static void main(String[] args) {\n" + + " \n" + + " switch(args.length) {\n" + + " \n" + + " case 1:\n" + + " int i = 0;\n" + + " class Local {\n" + + " }\n" + + " break;\n" + + " \n" + + " case 0 :\n" + + " System.out.println(i); // local var can be referred to, only an initialization pb\n" + + " System.out.println(new Local());\n" + + " break;\n" + + "\n" + + " case 2 :\n" + + " class Local { // not a duplicate\n" + + " }\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " System.out.println(new Local());\n" + + " ^^^^^\n" + + "Local cannot be resolved to a type\n" + + "----------\n"); +} + +// checking for captured outer local initialization status +// NOTE: only complain against non-inlinable outer locals +// http://bugs.eclipse.org/bugs/show_bug.cgi?id=26134 +public void test074() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) { \n" + + " String nonInlinedString = \"[Local]\"; \n" + + " int i = 2; \n" + + " switch(i){ \n" + + " case 1: \n" + + " final String displayString = nonInlinedString;\n" + + " final String inlinedString = \"a\"; \n" + + " class Local { \n" + + " public String toString() { \n" + + " return inlinedString + displayString; \n" + + " } \n" + + " } \n" + + " case 2: \n" + + " System.out.print(new Local()); \n" + + " System.out.print(\"-\"); \n" + + " System.out.println(new Local(){ \n" + + " public String toString() { \n" + + " return super.toString()+\": anonymous\"; \n" + + " } \n" + + " }); \n" + + " } \n" + + " } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " System.out.print(new Local()); \n" + + " ^^^^^\n" + + "Local cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " System.out.println(new Local(){ \n" + + " ^^^^^\n" + + "Local cannot be resolved to a type\n" + + "----------\n"); +} +public void test075() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void foo(int p1) {} \n" + + " public void foo(short p1) {} \n" + + "} \n", + "Y.java", + "public class Y extends X { \n" + + " public void foo(long p1) {} \n" + + " public void testEc() { foo((short)1); } \n" + + "} \n", + }, + "SUCCESS"); +} + +/** + * Test fix for bug 58069. + * @see 58069 + */ +public void test076() { + this.docSupport = true; + runNegativeTest( + new String[] { + "IX.java", + "interface IX {\n" + + " public static class Problem extends Exception {}\n" + + "}\n", + "X.java", + "public abstract class X {\n" + + " public static class Problem extends Exception {}\n" + + " public abstract static class InnerClass implements IX {\n" + + " /**\n" + + " * @throws Problem \n" + + " */\n" + + " public void foo() throws IllegalArgumentException {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. WARNING in IX.java (at line 2)\n" + + " public static class Problem extends Exception {}\n" + + " ^^^^^^^\n" + + "The serializable class Problem does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public static class Problem extends Exception {}\n" + + " ^^^^^^^\n" + + "The serializable class Problem does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @throws Problem \n" + + " ^^^^^^^\n" + + "Javadoc: Exception Problem is not declared\n" + + "----------\n" ); +} +/** + * Test fix bug 58069 for method. + * Note that problem is not flagged in doc comments as it is only raised while verifying + * implicit method and javadoc resolution does not use it. + */ +public void test077() { + this.docSupport = true; + this.runConformTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar() { \n"+ + " return \"FAILED\"; \n" + + " } \n"+ + " void foo(){ \n"+ + " /** @see #bar() */\n" + + " class Y extends Secondary { \n"+ + " /** @see #bar() */\n" + + " String z = bar(); \n" + + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " String bar(){ return \"FAILED\"; } \n" + + "} \n" + } + ); +} +/** + * Test fix bug 58069 for field. + * Note that problem is not flagged in doc comments as it is only raised while verifying + * Name or Qualified name references and javadoc reference is a field reference. + */ +public void test078() { + this.docSupport = true; + this.runConformTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar = \"FAILED\";"+ + " void foo(){ \n"+ + " /** @see #bar */\n" + + " class Y extends Secondary { \n"+ + " /** @see #bar */\n" + + " String z = bar; \n"+ + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " String bar = \"FAILED\"; \n" + + "} \n" + } + ); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47227 + */ +public void test079() { + this.runNegativeTest( + new String[] { + "Hello.java", + "void ___eval() {\n" + + " new Runnable() {\n" + + " int ___run() throws Throwable {\n" + + " return blah;\n" + + " }\n" + + " private String blarg;\n" + + " public void run() {\n" + + " }\n" + + " };\n" + + "}\n" + + "public class Hello {\n" + + " private static int x;\n" + + " private String blah;\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public void hello() {\n" + + " }\n" + + " public boolean blah() {\n" + + " return false;\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Hello.java (at line 1)\n" + + " void ___eval() {\n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + + "2. ERROR in Hello.java (at line 2)\n" + + " new Runnable() {\n" + + " int ___run() throws Throwable {\n" + + " return blah;\n" + + " }\n" + + " private String blarg;\n" + + " public void run() {\n" + + " }\n" + + " };\n" + + "}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + ); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67643 + * from 1.5 source level on most specific common super type is allowed + */ +public void test080() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {\n" + + " private static class C1 extends ArrayList {\n" + + " }\n" + + " private static class C2 extends ArrayList {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " ArrayList list = args == null ? new C1(): new C2();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private static class C1 extends ArrayList {\n" + + " ^^\n" + + "The serializable class C1 does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " private static class C2 extends ArrayList {\n" + + " ^^\n" + + "The serializable class C2 does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " ArrayList list = args == null ? new C1(): new C2();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types X.C1 and X.C2\n" + + "----------\n"); +} +public void test081() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X foo() { return this; } \n" + + "}\n" + + "class Y extends X {\n" + + " public Y foo() { return this; } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public Y foo() { return this; } \n" + + " ^\n" + + "The return type is incompatible with X.foo()\n" + + "----------\n"); +} +// covariance +public void test082() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X x = new X1();\n" + + " System.out.println(x.foo());\n" + + " }\n" + + " Object foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 extends X {\n" + + " String foo() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " String foo() {\n" + + " ^^^^^^\n" + + "The return type is incompatible with X.foo()\n" + + "----------\n"); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=66533 + */ +public void test084() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object enum = null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object enum = null;\n" + + " ^^^^\n" + + "\'enum\' should not be used as an identifier, since it is a reserved keyword from source level 1.5 on\n" + + "----------\n"); +} +/** + * Test unused import with static + */ +public void test085() { + this.runNegativeTest( + new String[] { + "A.java", + "import static j.l.S.*;\n" + + "import static j.l.S.in;\n" + + "\n" + + "public class A {\n" + + "\n" + + "}\n", + "j/l/S.java", + "package j.l;\n" + + "public class S {\n" + + " public static int in;\n" + + "}\n" + }, + "----------\n" + + "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 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 or greater\n" + + "----------\n" + + "3. ERROR in A.java (at line 2)\n" + + " import static j.l.S.in;\n" + + " ^^^^^^^^\n" + + "The import j.l.S.in cannot be resolved\n" + + "----------\n" + ); +} +/** + * Test invalid static import syntax + */ +public void test086() { + this.runNegativeTest( + new String[] { + "p/S.java", + "package p;\n" + + "public class S {\n" + + " public final static String full = \"FULL\";\n" + + " public final static String success = \"SUCCESS\";\n" + + "}\n", + "X.java", + "import static p.S;\n" + + "public class X {\n" + + " public static void main ( String[] args) {\n" + + " \n" + + " System.out.print(full+\" \"+p.S.success);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "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 or greater\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.print(full+\" \"+p.S.success);\n" + + " ^^^^\n" + + "full cannot be resolved to a variable\n" + + "----------\n" + ); +} +public void test087() { + this.runNegativeTest( + new String[] { + "p/S.java", + "public class S {\n" + + " public final static String full = \"FULL\";\n" + + " public final static String success = \"SUCCESS\";\n" + + "}\n", + "X.java", + "import static S;\n" + + "public class X {\n" + + " public static void main ( String[] args) {\n" + + " \n" + + " System.out.print(full+\" \"+S.success);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "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 or greater\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " import static S;\n" + + " ^\n" + + "The import S cannot be resolved\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " System.out.print(full+\" \"+S.success);\n" + + " ^^^^\n" + + "full cannot be resolved to a variable\n" + + "----------\n" + ); +} +public void test088() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Date;\n" + + "import java.lang.reflect.*;\n" + + "public class X extends Date implements Runnable{\n" + + " \n" + + " Integer w = Integer.valueOf(90);\n" + + " protected double x = 91.1;\n" + + " public long y = 92;\n" + + " static public Boolean z = Boolean.valueOf(true); \n" + + " public class X_inner {\n" + + " public X_inner() {\n" + + " this.super();\n" + + " System.out.println(\"....\");\n" + + " }\n" + + " }\n" + + " X_inner a = new X_inner();\n" + + " public interface X_interface {\n" + + " public void f(); \n" + + " }\n" + + " static {\n" + + " System.out.println(\"Static initializer\");\n" + + " }\n" + + " public X() { } \n" + + " public X(int a1,int b1) { } \n" + + " private void a() { System.out.println(\"A\");} \n" + + " protected void b() { System.out.println(\"B\");} \n" + + " public void c() { System.out.println(\"C\");} \n" + + " static public int d() {System.out.println(\"Static D\");return -1;} \n" + + " public static void main(String args[]) {\n" + + " X b = new X();\n" + + " Class c = b.getClass();\n" + + " Class _getClasses [] = X.class.getClasses(); \n" + + "// System.out.println(_getClasses[0].toString());\n" + + "// System.out.println(_getClasses[1].toString());\n" + + " if (_getClasses.length == 0) {System.out.println(\"FAILED\");};\n" + + " Constructor _getConstructors[] = c.getConstructors(); \n" + + " try {\n" + + " Field _getField = c.getField(\"y\");\n" + + " Method _getMethod = c.getMethod(\"d\",null);\n" + + " \n" + + " Boolean b_z = X.z; \n" + + " }\n" + + " catch (NoSuchFieldException e) { System.out.println(\"NoSuchFieldException\");}\n" + + " catch (NoSuchMethodException e) { System.out.println(\"NoSuchMethodException\");};\n" + + " } \n" + + " public void run() {System.out.println(\"RUN\");} \n" + + "}", + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 4)\n" + + " public class X extends Date implements Runnable{\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 12)\n" + + " this.super();\n" + + " ^^^^\n" + + "Illegal enclosing instance specification for type Object\n" + + "----------\n" + + "3. WARNING in p\\X.java (at line 25)\n" + + " private void a() { System.out.println(\"A\");} \n" + + " ^^^\n" + + "The method a() from the type X is never used locally\n" + + "----------\n"); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78089 + */ +public void test089() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " @interface I1 {}\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + "----------\n" + + "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 or greater\n" + + "----------\n"); +} +//78104 +public void test090() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(int[] ints, Object o) {\n" + + " ints = ints.clone();\n" + + " ints = (int[])ints.clone();\n" + + " X x = this.clone();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " ints = ints.clone();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to int[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X x = this.clone();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + ); +} +//78104 - variation +public void test091() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " args = args.clone();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " args = args.clone();\r\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to String[]\n" + + "----------\n" + ); +} +// check autoboxing only enabled in 5.0 source mode +public void test092() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Boolean b) {\n" + + " if (b) { \n" + + " int i = 0;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (b) { \n" + + " ^\n" + + "Type mismatch: cannot convert from Boolean to boolean\n" + + "----------\n" + ); +} +public void test093() { + this.runNegativeTest( + new String[] { + "p/X_1.java", + "package p;\n" + + "/* dena JTest Suite, Version 2.2, September 1997\n" + + " * Copyright (c) 1995-1997 Modena Software (I) Pvt. Ltd., All Rights Reserved\n" + + " */\n" + + "/* Section : Inner classes \n" + + " * FileName : ciner026.java\n" + + " * Purpose : Positive test for Inner classes\n" + + " * \n" + + " * An anonymous class can have initializers but cannot have a constructor.\n" + + " * The argument list of the associated new expression is implicitely \n" + + " * passed to the constructor of the super class. \n" + + " *\n" + + " */\n" + + " \n" + + " class X_1 {\n" + + " static int xx = 100;\n" + + " //inner class Y \n" + + " static class Y { \n" + + " public int j = 0;\n" + + " Y(int x){ j = x; }\n" + + " } \n" + + " public void call_inner()\n" + + " {\n" + + " int i = test_anonymous().j;\n" + + " } \n" + + " public static void main(String argv[])\n" + + " {\n" + + " X_1 ox = new X_1();\n" + + " ox.call_inner(); \n" + + " } \n" + + "public void newMethod ( ) {\n" + + " Float f1 = null;\n" + + " f1=(f1==0.0)?1.0:f1;\n" + + "}\n" + + " static Y test_anonymous()\n" + + " { \n" + + " //anonymous implementation of class Y\n" + + " return new Y(xx) //xx should be implicitely passed to Y()\n" + + " {\n" + + " }; \n" + + " \n" + + " } //end test_anonymous \n" + + "} ", + }, + "----------\n" + + "1. ERROR in p\\X_1.java (at line 33)\n" + + " f1=(f1==0.0)?1.0:f1;\n" + + " ^^^^^^^^^\n" + + "Incompatible operand types Float and double\n" + + "----------\n" + ); +} +/* + * Test unused import warning in presence of syntax errors + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21022 + */ +public void test094(){ + + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*; \n" + + "public class X { \n" + + " void foo(){\n" + + " ()\n" + + " IOException e;\n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " ()\n" + + " ^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=84743 +public void test095(){ + + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "interface J {\n" + + " String foo();\n" + + "}\n" + + " \n" + + "public class X implements I {\n" + + " public int foo() {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = new X();\n" + + " try {\n" + + " J j = (J) i;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " J j = (J) i;\n" + + " ^^^^^\n" + + "Cannot cast from I to J\n" + + "----------\n"); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47074 + */ +public void test096() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " interface A {\n" + + " void doSomething();\n" + + " }\n" + + "\n" + + " interface B {\n" + + " int doSomething();\n" + + " }\n" + + "\n" + + " interface C extends B {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " \n" + + " A a = null;\n" + + " C c = (C)a; //COMPILER ERROR\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " C c = (C)a; //COMPILER ERROR\n" + + " ^^^^\n" + + "Cannot cast from X.A to X.C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=79396 +public void test097() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " int cst = X1.CST;\n" + + " X2.Root.foo();\n" + + " }\n" + + " static void foo() {}\n" + + "}\n" + + "\n" + + "class X1 {\n" + + " static {\n" + + " System.out.print(\"[X1]\");\n" + + " }\n" + + " public static final int CST = 12;\n" + + " static X Root = null;\n" + + "}\n" + + "class X2 {\n" + + " static {\n" + + " System.out.print(\"[X2]\");\n" + + " }\n" + + " public final int CST = 12;\n" + + " static X Root = null;\n" + + "}\n" + }, + "[X2]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=78906 +public void test098() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " System.out.print(\"foo\");\n" + + " }\n" + + " class Y {\n" + + " String this$0;\n" + + " String this$0$;\n" + + " void print() { \n" + + " foo();\n" + + " System.out.println(this$0+this$0$);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y y = new X().new Y();\n" + + " y.this$0 = \"hello\";\n" + + " y.this$0$ = \"world\";\n" + + " y.print();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String this$0;\n" + + " ^^^^^^\n" + + "Duplicate field X.Y.this$0\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=77349 +public void test099() { + this.runNegativeTest( + new String[] { + "I.java", + "public interface I extends Cloneable {\n" + + " class Inner {\n" + + " Object bar(I i) throws CloneNotSupportedException { return i.clone(); }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 3)\n" + + " Object bar(I i) throws CloneNotSupportedException { return i.clone(); }\n" + + " ^^^^^\n" + + "The method clone() is undefined for the type I\n" + + "----------\n" + ); +} + +public void test100() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int \\ud800\\udc05\\ud800\\udc04\\ud800\\udc03\\ud800\\udc02\\ud800\\udc01\\ud800\\udc00;\n" + + " void foo() {\n" + + " int \\ud800\\udc05\\ud800\\udc04\\ud800\\udc03\\ud800\\udc02\\ud800\\udc01\\ud800\\udc00;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int \\ud800\\udc05\\ud800\\udc04\\ud800\\udc03\\ud800\\udc02\\ud800\\udc01\\ud800\\udc00;\n" + + " ^^^^^^\n" + + "Invalid unicode\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " int \\ud800\\udc05\\ud800\\udc04\\ud800\\udc03\\ud800\\udc02\\ud800\\udc01\\ud800\\udc00;\n" + + " ^^^^^^\n" + + "Invalid unicode\n" + + "----------\n" + ); +} + +public void test101() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Character c0 = \'a\';\n" + + " public static void main(String argv[]) {\n" + + " Character c1;\n" + + " c1 = \'b\';\n" + + "\n" + + " Character c2 = \'c\';\n" + + " Character[] c3 = { \'d\' };\n" + + " \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Character c0 = \'a\';\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Character\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " c1 = \'b\';\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Character\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Character c2 = \'c\';\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Character\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " Character[] c3 = { \'d\' };\n" + + " ^^^\n" + + "Type mismatch: cannot convert from char to Character\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108856 +public void test102() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Object() {\n" + + " {\n" + + " new Object() {\n" + + " {\n" + + " System.out.println(this.getClass().getName());\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + "X$2"); +} +public void test103() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(X.class);\n" + + " }\n" + + "}\n", + }, + "class X"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "// Compiled from X.java (version 1.4 : 48.0, super bit)\n" + + "public class X {\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/Class;\n" + + " static synthetic java.lang.Class class$0;\n" + + " \n" + + " // Method descriptor #9 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [11]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #18 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 3 getstatic X.class$0 : java.lang.Class [25]\n" + + " 6 dup\n" + + " 7 ifnonnull 35\n" + + " 10 pop\n" + + " 11 ldc [27]\n" + + " 13 invokestatic java.lang.Class.forName(java.lang.String) : java.lang.Class [28]\n" + + " 16 dup\n" + + " 17 putstatic X.class$0 : java.lang.Class [25]\n" + + " 20 goto 35\n" + + " 23 new java.lang.NoClassDefFoundError [34]\n" + + " 26 dup_x1\n" + + " 27 swap\n" + + " 28 invokevirtual java.lang.Throwable.getMessage() : java.lang.String [36]\n" + + " 31 invokespecial java.lang.NoClassDefFoundError(java.lang.String) [42]\n" + + " 34 athrow\n" + + " 35 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [45]\n" + + " 38 return\n" + + " Exception Table:\n" + + " [pc: 11, pc: 16] -> 23 when : java.lang.ClassNotFoundException\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 38, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 39] local: args index: 0 type: java.lang.String[]\n" + + "}"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=125570 +public void test104() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Object() {\n" + + " {\n" + + " new Object() {\n" + + " {\n" + + " class Y {\n" + + " {\n" + + " System.out.print(this.getClass());\n" + + " System.out.print(\' \');\n" + + " System.out.print(this.getClass().getName());\n" + + " }\n" + + " }\n" + + " ;\n" + + " new Y();\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "}" + }, + "class X$1$Y X$1$Y"); +} + +// enclosing instance - note that the behavior is different in 1.5 +public void test105() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Y { }\n" + + " static class Z1 {\n" + + " Runnable m;\n" + + " Z1(Runnable p) {\n" + + " this.m = p;\n" + + " }\n" + + " }\n" + + " class Z2 extends Z1 {\n" + + " Z2(final Y p) {\n" + + " super(new Runnable() {\n" + + " public void run() {\n" + + " foo(p);\n" + + " }\n" + + " });\n" + + " }\n" + + " }\n" + + " void foo(Y p) { }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " foo(p);\n" + + " ^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 +public void test106() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "import java.util.zip.*;\n" + + "public class X {\n" + + " void x() throws ZipException {\n" + + " IandJ ij= new K();\n" + + " ij.m();\n" + + " }\n" + + " void y() throws ZipException {\n" + + " K k= new K();\n" + + " k.m();\n" + + " }\n" + + "}\n" + + "interface I { void m() throws IOException; }\n" + + "interface J { void m() throws ZipException; }\n" + + "interface IandJ extends I, J {}\n" + + "class K implements IandJ { public void m() throws ZipException { } }" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 +public void test107() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " C c = new D();\n" + + " c.xyz();\n" + + " }\n" + + "}\n" + + "class AException extends Exception { }\n" + + "class BException extends Exception { }\n" + + "interface A { void xyz() throws AException; }\n" + + "interface B { void xyz() throws BException; }\n" + + "interface C extends A, B { }\n" + + "class D implements C {\n" + + " public void xyz() { System.out.println(1); }\n" + + "}" + }, + "1"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java new file mode 100644 index 0000000000..6192c7a5b9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java @@ -0,0 +1,3618 @@ +/******************************************************************************* + * Copyright (c) 2000, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Compliance_1_5 extends AbstractComparableTest { +boolean docSupport = false; + +public Compliance_1_5(String name) { + super(name); +} + +/* + * Toggle compiler in mode -1.5 + */ +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); + if (this.docSupport) { + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, CompilerOptions.ENABLED); + } + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + return options; +} +public static Test suite() { + return buildComparableTestSuite(testClass()); +} +// Use this static initializer to specify subset for tests +// All specified tests which does not belong to the class are skipped... +static { + // Names of tests to run: can be "testBugXXXX" or "BugXXXX") +// TESTS_NAMES = new String[] { "test079" }; + // Numbers of tests to run: "test" will be run for each number of this array +// TESTS_NUMBERS = new int[] { 88 }; + // Range numbers of tests to run: all tests between "test" and "test" will be run for { first, last } +// TESTS_RANGE = new int[] { 85, -1 }; +} +/* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ +@Override +protected void setUp() throws Exception { + super.setUp(); + // Javadoc disabled by default + this.docSupport = false; +} + +// test001 - moved to SuperTypeTest#test002 +// test002 - moved to SuperTypeTest#test003 +// test003 - moved to SuperTypeTest#test004 +// test004 - moved to SuperTypeTest#test005 +// test005 - moved to SuperTypeTest#test006 +// test006 - moved to SuperTypeTest#test007 +// test007 - moved to TryStatementTest#test057 +// test008 - moved to LookupTest#test074 +// test009 - moved to RuntimeTests#test1004 + +// check actualReceiverType when array type +public void test010() { + this.runConformTest( + new String[] { + "p1/Z.java", + "package p1; \n"+ + "public class Z { \n" + + " public static void main(String[] arguments) { \n"+ + " String[] s = new String[]{\"SUCCESS\" }; \n" + + " System.out.print(s.length); \n" + + " System.out.print(((String[])s.clone())[0]); \n" + + " } \n"+ + "} \n" + }, + "1SUCCESS"); +} +// test unreachable code complaints +public void test011() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " void foo() { \n"+ + " while (false); \n" + + " while (false) System.out.println(\"unreachable\"); \n" + + " do ; while (false); \n" + + " do System.out.println(\"unreachable\"); while (false); \n" + + " for (;false;); \n" + + " for (;false;) System.out.println(\"unreachable\"); \n" + + " if (false); \n" + + " if (false)System.out.println(\"unreachable\"); \n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " while (false); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 5)\n" + + " while (false) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in p1\\X.java (at line 8)\n" + + " for (;false;); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "4. ERROR in p1\\X.java (at line 9)\n" + + " for (;false;) System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "5. WARNING in p1\\X.java (at line 10)\n" + + " if (false); \n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in p1\\X.java (at line 11)\n" + + " if (false)System.out.println(\"unreachable\"); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +/// binary compatibility +public void test012() { + this.runConformTest( + new String[] { + "p1/Y.java", + "package p1; \n" + + "class Store { \n" + + " String value; \n" + + " Store(String value){ \n" + + " this.value = value; \n" + + " } \n" + + "} \n" + + "class Top { \n" + + " static String bar = \"Top.bar\"; \n" + + " String foo = \"Top.foo\"; \n" + + " Store store = new Store(\"Top.store\"); \n" + + " static Store sstore = new Store(\"Top.sstore\"); \n" + + " static Top ss = new Top(); \n" + + "} \n" + + "public class Y extends Updated { \n" + + " public static void main(String[] arguments) { \n" + + " new Y().test(); \n" + + " } \n" + + " void test() { \n" + + " System.out.print(\"*** FIELD ACCESS ***\"); \n" + + " System.out.print(\"*1* new Updated().bar: \" + new Updated().bar); \n" + + " System.out.print(\"*2* new Updated().foo: \" + new Updated().foo); \n" + + " System.out.print(\"*3* new Y().foo: \" + new Y().foo); \n" + + " System.out.print(\"*4* new Y().bar: \" + new Y().bar); \n" + + " System.out.print(\"*5* bar: \" + bar); \n" + + " System.out.print(\"*6* foo: \" + foo); \n" + + " System.out.print(\"*7* Y.bar: \" + Y.bar); \n" + + " System.out.print(\"*8* this.bar: \" + this.bar); \n" + + " System.out.print(\"*9* this.foo: \" + this.foo); \n" + + " System.out.print(\"*10* store.value: \" + store.value); \n" + + " System.out.print(\"*11* sstore.value: \" + sstore.value); \n" + + " System.out.print(\"*12* ss.sstore.value: \" + ss.sstore.value); \n" + + " } \n" + + "} \n", + "p1/Updated.java", + "package p1; \n" + + "public class Updated extends Top { \n" + + "} \n" + }, + "*** FIELD ACCESS ***" + +"*1* new Updated().bar: Top.bar" + +"*2* new Updated().foo: Top.foo" + +"*3* new Y().foo: Top.foo" + +"*4* new Y().bar: Top.bar" + +"*5* bar: Top.bar" + +"*6* foo: Top.foo" + +"*7* Y.bar: Top.bar" + +"*8* this.bar: Top.bar" + +"*9* this.foo: Top.foo" + +"*10* store.value: Top.store" + +"*11* sstore.value: Top.sstore" + +"*12* ss.sstore.value: Top.sstore"); + + this.runConformTest( + new String[] { + "p1/Updated.java", + "package p1; \n"+ + "public class Updated extends Top { \n"+ + " public static void main(String[] arguments) { \n"+ + " Y.main(arguments); \n" + + " } \n" + + " static String bar = \"Updated.bar\"; \n" + + " String foo = \"Updated.foo\"; \n" + + " Store store = new Store(\"Updated.store\"); \n" + + " static Store sstore = new Store(\"Updated.sstore\"); \n" + + " static Updated ss = new Updated(); \n" + + "} \n" + }, + "*** FIELD ACCESS ***" + +"*1* new Updated().bar: Updated.bar" + +"*2* new Updated().foo: Updated.foo" + +"*3* new Y().foo: Updated.foo" + +"*4* new Y().bar: Updated.bar" + +"*5* bar: Updated.bar" + +"*6* foo: Updated.foo" + +"*7* Y.bar: Updated.bar" + +"*8* this.bar: Updated.bar" + +"*9* this.foo: Updated.foo" + +"*10* store.value: Updated.store" + +"*11* sstore.value: Updated.sstore" + +"*12* ss.sstore.value: Top.sstore", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} +// binary compatibility +public void test013() { + this.runConformTest( + new String[] { + "p1/Y.java", + "package p1; \n" + + "class Store { \n" + + " String value; \n" + + " Store(String value){ \n" + + " this.value = value; \n" + + " } \n" + + "} \n" + + "class Top { \n" + + " static String bar() { return \"Top.bar()\"; } \n" + + " String foo() { return \"Top.foo()\"; } \n" + + "} \n" + + "public class Y extends Updated { \n" + + " public static void main(String[] arguments) { \n" + + " new Y().test(); \n" + + " } \n" + + " void test() { \n" + + " System.out.print(\"*** METHOD ACCESS ***\"); \n" + + " System.out.print(\"*1* new Updated().bar(): \" + new Updated().bar()); \n" + + " System.out.print(\"*2* new Updated().foo(): \" + new Updated().foo()); \n" + + " System.out.print(\"*3* new Y().foo(): \" + new Y().foo()); \n" + + " System.out.print(\"*4* new Y().bar(): \" + new Y().bar()); \n" + + " System.out.print(\"*5* bar(): \" + bar()); \n" + + " System.out.print(\"*6* foo(): \" + foo()); \n" + + " System.out.print(\"*7* Y.bar(): \" + Y.bar()); \n" + + " System.out.print(\"*8* this.bar(): \" + this.bar()); \n" + + " System.out.print(\"*9* this.foo(): \" + this.foo()); \n" + + " } \n" + + "} \n", + "p1/Updated.java", + "package p1; \n" + + "public class Updated extends Top { \n" + + "} \n" + }, + "*** METHOD ACCESS ***" + +"*1* new Updated().bar(): Top.bar()" + +"*2* new Updated().foo(): Top.foo()" + +"*3* new Y().foo(): Top.foo()" + +"*4* new Y().bar(): Top.bar()" + +"*5* bar(): Top.bar()" + +"*6* foo(): Top.foo()" + +"*7* Y.bar(): Top.bar()" + +"*8* this.bar(): Top.bar()" + +"*9* this.foo(): Top.foo()"); + + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "p1/Updated.java", + "package p1; \n"+ + "public class Updated extends Top { \n"+ + " public static void main(String[] arguments) { \n"+ + " Y.main(arguments); \n" + + " } \n" + + " static String bar() { return \"Updated.bar()\"; } \n" + + " String foo() { return \"Updated.foo()\"; } \n" + + "} \n" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "*** METHOD ACCESS ***" /* expected output string */ + +"*1* new Updated().bar(): Updated.bar()" + +"*2* new Updated().foo(): Updated.foo()" + +"*3* new Y().foo(): Updated.foo()" + +"*4* new Y().bar(): Updated.bar()" + +"*5* bar(): Updated.bar()" + +"*6* foo(): Updated.foo()" + +"*7* Y.bar(): Updated.bar()" + +"*8* this.bar(): Updated.bar()" + +"*9* this.foo(): Updated.foo()", + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacThrowsAnExceptionForJava_1_5_0_16 /* javac test options */); + // transient error +} + +public void test014() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n" + + "class T { \n" + + " void foo(boolean b) { \n" + + " System.out.print(\"T.foo(boolean)#\"); \n" + + " } \n" + + " boolean bar = false; \n" + + " class Member { \n" + + " void display(){ System.out.print(\"T.Member#\"); } \n" + + " } \n" + + "} \n" + + "public class X { \n" + + " void foo(int i) { \n" + + " System.out.println(\"X.foo(int)#\"); \n" + + " } \n" + + " int bar; \n" + + " class Member { \n" + + " void display(){ System.out.print(\"X.Member#\"); } \n" + + " } \n" + + " public static void main(String[] arguments) { \n" + + " new X().bar(); \n" + + " } \n" + + " void bar() { \n" + + " new T() { \n" + + " { \n" + + " foo(true); \n" + + " System.out.print((boolean)bar + \"#\"); \n" + + " Member m = new Member(); \n" + + " m.display(); \n" + + " } \n" + + " }; \n" + + " } \n" + + "} \n" + }, + "T.foo(boolean)#false#T.Member#"); +} + +/* + * check handling of default abstract methods + */ +public void test015() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " C c = new C() { \n"+ + " public void doSomething(){ \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " }; \n"+ + " c.doSomething(); \n"+ + " } \n"+ + "} \n"+ + "interface I { \n"+ + " void doSomething(); \n"+ + "} \n"+ + "abstract class C implements I { \n"+ + "} \n" + }, + "SUCCESS"); +} + +public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(boolean b) {} \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " foo(0); \n" + + " ^^^\n" + + "The method foo(boolean) in the type T is not applicable for the arguments (int)\n" + + "----------\n"); +} + +public void test017() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(boolean b) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(false); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} + +public void test018() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(int j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +public void test019() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(int j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "class U { \n"+ + " void foo(int j) { System.out.println(\"FAILED\"); } \n"+ + "} \n"+ + "public class X extends U { \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +public void test020() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(int j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "class U { \n"+ + " void foo(boolean j) { System.out.println(\"FAILED\"); } \n"+ + "} \n"+ + "public class X extends U { \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +public void test020a() { + this.runConformTest( + new String[] { + "X.java", + "class T { \n"+ + " void foo(U j) { System.out.println(\"SUCCESS\"); } \n"+ + "} \n"+ + "class U { \n"+ + "} \n"+ + "public class X extends U { \n"+ + " void foo(X j) { System.out.println(\"FAILED\"); } \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(new X()); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().bar(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS"); +} +// binary check for 11511 +public void test021() { + this.runConformTest( + new String[] { + "p1/Z.java", + "package p1; \n" + + "public class Z extends AbstractA { \n" + + " public static void main(String[] arguments) { \n" + + " new Z().init(); \n" + + " } \n" + + "} \n" + + "abstract class AbstractB implements K { \n" + + " public void init() { \n" + + " System.out.println(\"AbstractB.init()\"); \n" + + " } \n" + + "} \n" + + "interface K { \n" + + " void init(); \n" + + " void init(int i); \n" + + "} \n", + "p1/AbstractA.java", + "package p1; \n" + + "public abstract class AbstractA extends AbstractB implements K { \n" + + " public void init(int i) { \n" + + " } \n" + + "} \n" + }, + "AbstractB.init()"); // no special vm args + + // check that "new Z().init()" is bound to "Z.init()" + String computedReferences = findReferences(OUTPUT_DIR + "/p1/Z.class"); + boolean check = + computedReferences.indexOf("constructorRef/Z/0") >= 0 + && computedReferences.indexOf("methodRef/init/0") >= 0; + if (!check){ + System.out.println(computedReferences); + } + assertTrue("did not bind 'new Z().init()' to Z.init()'", check); +} + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis + */ +public void test022() { + + this.runNegativeTest( + new String[] { + "p1/T.java", + "package p1; \n"+ + "interface II {} \n"+ + "class TT { \n"+ + " void foo(boolean b) {} \n"+ + " void foo(int i, boolean b) {} \n"+ + " void foo(String s) {} \n"+ + "} \n"+ + "public abstract class T implements II { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(0); // should say that foo(int, boolean) isn't applicable \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void boo() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(true); // should not complain about ambiguity \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\T.java (at line 13)\n" + + " foo(0); // should say that foo(int, boolean) isn\'t applicable \n" + + " ^^^\n" + + "The method foo(int, boolean) in the type TT is not applicable for the arguments (int)\n" + + "----------\n"); +} + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis + */ +public void test023() { + + this.runNegativeTest( + new String[] { + "p1/T.java", + "package p1; \n"+ + "interface II {} \n"+ + "abstract class TT { \n"+ // 259+ABSTRACT + " void foo(boolean b) {} \n"+ + " void foo(int i, boolean b) {} \n"+ + " void foo(String s) {} \n"+ + "} \n"+ + "public abstract class T implements II { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(0); // should say that foo(int, boolean) isn't applicable \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void boo() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(true); // should complain ambiguity \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\T.java (at line 13)\n" + + " foo(0); // should say that foo(int, boolean) isn\'t applicable \n" + + " ^^^\n" + + "The method foo(int, boolean) in the type TT is not applicable for the arguments (int)\n" + + "----------\n"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis + */ +public void test024() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "interface II {} \n"+ + "abstract class T implements II { \n"+ + " void foo(boolean b) {} \n"+ + " void foo(int i, boolean b) {} \n"+ + "} \n"+ + "abstract class TT implements II { \n"+ + " void foo(boolean b) {} \n"+ + "} \n"+ + "public class X { \n"+ + " void foo(int i) {} \n"+ + " void bar() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(0); // javac says foo cannot be resolved because of multiple matches \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void bar2() { \n"+ + " new TT() { \n"+ + " { \n"+ + " foo(0); // should say that foo(boolean) isn't applicable \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " void boo() { \n"+ + " new T() { \n"+ + " { \n"+ + " foo(true); // should complain ambiguity \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 15)\n" + + " foo(0); // javac says foo cannot be resolved because of multiple matches \n" + + " ^^^\n" + + "The method foo(int, boolean) in the type T is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 22)\n" + + " foo(0); // should say that foo(boolean) isn\'t applicable \n" + + " ^^^\n" + + "The method foo(boolean) in the type TT is not applicable for the arguments (int)\n" + + "----------\n"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis (no matter if super is abstract or not) + */ +public void test025() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X extends AbstractY { \n"+ + " void bar(){ \n"+ + " init(\"hello\"); \n"+ + " } \n"+ + "} \n"+ + "abstract class AbstractY implements I { \n"+ + "} \n"+ + "interface I { \n"+ + " void init(String s, int i); \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public class X extends AbstractY { \n" + + " ^\n" + + "The type X must implement the inherited abstract method I.init(String, int)\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 4)\n" + + " init(\"hello\"); \n" + + " ^^^^\n" + + "The method init(String, int) in the type I is not applicable for the arguments (String)\n" + + "----------\n"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - applicable error diagnosis (no matter if super is abstract or not) + */ +public void test026() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X extends AbstractY { \n"+ + " void bar(){ \n"+ + " init(\"hello\"); \n"+ + " } \n"+ + "} \n"+ + "class AbstractY implements I { \n"+ + "} \n"+ + "interface I { \n"+ + " void init(String s, int i); \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " init(\"hello\"); \n" + + " ^^^^\n" + + "The method init(String, int) in the type I is not applicable for the arguments (String)\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 7)\n" + + " class AbstractY implements I { \n" + + " ^^^^^^^^^\n" + + "The type AbstractY must implement the inherited abstract method I.init(String, int)\n" + + "----------\n"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11922 + * should report unreachable empty statement + */ +public void test027() { + + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " for (;false;p()); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " static void p(){ \n"+ + " System.out.println(\"FAILED\"); \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. WARNING in p1\\X.java (at line 4)\n" + + " for (;false;p()); \n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 4)\n" + + " for (;false;p()); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" +); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=12445 + * should report unreachable empty statement + */ +public void test028() { + + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n" + + "interface FooInterface { \n" + + " public boolean foo(int a); \n" + + " public boolean bar(int a); \n" + + "} \n" + + "public class X extends Z { \n" + + " public boolean foo(int a){ return true; } \n" + + " public boolean bar(int a){ return false; } \n" + + " public static void main(String[] arguments) { \n"+ + " System.out.println(new X().test(0)); \n"+ + " } \n" + + "}\n" + + "abstract class Z implements FooInterface { \n" + + " public boolean foo(int a, int b) { \n" + + " return true; \n" + + " } \n" + + " public String test(int a) { \n" + + " boolean result = foo(a); \n" + + " if (result) \n" + + " return \"SUCCESS\"; \n" + + " else \n" + + " return \"FAILED\"; \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * verify error on qualified name ref in 1.4 + */ +public void test029() { + + this.runConformTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args) { \n" + + " new X(); \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " Woof woof_1; \n" + + " public class Honk { \n" + + " Integer honks; \n" + + " } \n" + + " public class Meow { \n" + + " Honk honk_1; \n" + + " } \n" + + " public class Woof { \n" + + " Meow meow_1; \n" + + " } \n" + + " public void setHonks(int num) { \n" + + " // This is the line that causes the VerifyError \n" + + " woof_1.meow_1.honk_1.honks = new Integer(num); \n" + + " // Here is equivalent code that does not cause the error. \n" + + " // Honk h = woof_1.moo_1.meow_1.honk_1; \n" + + " // h.honks = new Integer(num); \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * 1.4 signals invocations of non-visible abstract protected method implementations. + */ +public void test030() { + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args){ \n" + + " new q.X2().foo(\"String\"); \n" + + " new q.X2().bar(\"String\"); \n" + + " new q.X2().barbar(\"String\"); \n" + + " new q.X2().baz(\"String\"); \n" + + " } \n" + + "} \n", + + "p/X1.java", + "package p; \n" + + "public abstract class X1 { \n" + + " protected void foo(Object o){ System.out.println(\"X1.foo(Object)\"); } \n" + + " protected void bar(Object o){ System.out.println(\"X1.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X1.barbar(Object)\"); } \n" + + " protected void baz(Object o) { System.out.println(\"X1.baz(Object)\"); } \n" + + "} \n", + + "q/X2.java", + "package q; \n" + + "public class X2 extends p.X1 { \n" + + " protected void foo(int i) { System.out.println(\"X2.foo(int)\"); } \n" + + " protected void bar(Object o) { System.out.println(\"X2.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " protected void baz(String s) { System.out.println(\"X2.baz(String)\"); } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " new q.X2().bar(\"String\"); \n" + + " ^^^\n" + + "The method bar(Object) from the type X2 is not visible\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 6)\n" + + " new q.X2().barbar(\"String\"); \n" + + " ^^^^^^\n" + + "The method barbar(Object) from the type X2 is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in q\\X2.java (at line 4)\n" + + " protected void bar(Object o) { System.out.println(\"X2.bar(Object)\"); } \n" + + " ^^^^^^^^^^^^^\n" + + "The method bar(Object) of type X2 should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. WARNING in q\\X2.java (at line 5)\n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method X2.barbar(Object) does not override the inherited method from X1 since it is private to a different package\n" + + "----------\n"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * 1.4 signals invocations of non-visible abstract protected method implementations. + */ +public void test031() { + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X extends q.X2 { \n" + + " public static void main(String[] args){ \n" + + " new X().doSomething(); \n" + + " } \n" + + " void doSomething(){ \n" + + " foo(\"String\"); \n" + + " bar(\"String\"); \n" + + " barbar(\"String\"); \n" + + " baz(\"String\"); \n" + + " } \n" + + "} \n", + + "p/X1.java", + "package p; \n" + + "public abstract class X1 { \n" + + " protected void foo(Object o){ System.out.println(\"X1.foo(Object)\"); } \n" + + " protected void bar(Object o){ System.out.println(\"X1.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X1.barbar(Object)\"); } \n" + + " protected void baz(Object o) { System.out.println(\"X1.baz(Object)\"); } \n" + + "} \n", + + "q/X2.java", + "package q; \n" + + "public class X2 extends p.X1 { \n" + + " protected void foo(int i) { System.out.println(\"X2.foo(int)\"); } \n" + + " protected void bar(Object o) { System.out.println(\"X2.bar(Object)\"); } \n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " protected void baz(String s) { System.out.println(\"X2.baz(String)\"); } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 9)\n" + + " barbar(\"String\"); \n" + + " ^^^^^^\n" + + "The method barbar(Object) from the type X2 is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in q\\X2.java (at line 4)\n" + + " protected void bar(Object o) { System.out.println(\"X2.bar(Object)\"); } \n" + + " ^^^^^^^^^^^^^\n" + + "The method bar(Object) of type X2 should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. WARNING in q\\X2.java (at line 5)\n" + + " void barbar(Object o){ System.out.println(\"X2.barbar(Object)\"); } \n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method X2.barbar(Object) does not override the inherited method from X1 since it is private to a different package\n" + + "----------\n" +); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21580 + * 1.4 signals invocations of non-visible abstract protected field implementations. + */ +public void test032() { + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args){ \n" + + " System.out.println(new q.X2().foo); \n" + + " System.out.println(new q.X2().bar); \n" + + " } \n" + + "} \n", + + "p/X1.java", + "package p; \n" + + "public abstract class X1 { \n" + + " protected String foo = \"X1.foo\"; \n" + + " String bar = \"X1.bar\"; \n" + + "} \n", + + "q/X2.java", + "package q; \n" + + "public class X2 extends p.X1 { \n" + + " protected String foo = \"X2.foo\"; \n" + + " String bar = \"X2.bar\"; \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 4)\n" + + " System.out.println(new q.X2().foo); \n" + + " ^^^\n" + + "The field X2.foo is not visible\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 5)\n" + + " System.out.println(new q.X2().bar); \n" + + " ^^^\n" + + "The field X2.bar is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in q\\X2.java (at line 3)\n" + + " protected String foo = \"X2.foo\"; \n" + + " ^^^\n" + + "The field X2.foo is hiding a field from type X1\n" + + "----------\n"); +} + +/* + * Initialization of synthetic fields prior to super constructor call + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23075 + */ +public void test033() { + + this.runConformTest( + new String[] { + "A.java", + "public class A { \n"+ + " public int m; \n"+ + " public void pp() { \n"+ + " C c = new C(4); \n"+ + " System.out.println(c.get()); \n"+ + " } \n"+ + " public static void main(String[] args) { \n"+ + " A a = new A(); \n"+ + " try { \n"+ + " a.pp(); \n"+ + " System.out.println(\"SyntheticInit BEFORE SuperConstructorCall\"); \n"+ + " } catch(NullPointerException e) { \n"+ + " System.out.println(\"SyntheticInit AFTER SuperConstructorCall\"); // should no longer occur with target 1.4 \n"+ + " } \n"+ + " } \n"+ + " class C extends B { \n"+ + " public C(int x1) { \n"+ + " super(x1); \n"+ + " } \n"+ + " protected void init(int x1) { \n"+ + " x = m * x1; // <- NULL POINTER EXCEPTION because of m \n"+ + " } \n"+ + " } \n"+ + "} \n"+ + "class B { \n"+ + " int x; \n"+ + " public B(int x1) { \n"+ + " init(x1); \n"+ + " } \n"+ + " protected void init(int x1) { \n"+ + " x = x1; \n"+ + " } \n"+ + " public int get() { \n"+ + " return x; \n"+ + " } \n"+ + "} \n" + }, + "0\n" + + "SyntheticInit BEFORE SuperConstructorCall"); +} +/* + * Initialization of synthetic fields prior to super constructor call - NPE check + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=25174 + */ +public void test034() { + + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new X2(); \n"+ + " } \n"+ + " class X1 { \n"+ + " X1(){ \n"+ + " this.baz(); \n"+ + " } \n"+ + " void baz() { \n"+ + " System.out.println(\"-X1.baz()\"); \n"+ + " } \n"+ + " } \n"+ + " class X2 extends X1 { \n"+ + " void baz() { \n"+ + " System.out.print(X.this==null ? \"X.this == null\" : \"X.this != null\"); \n"+ + " X1 x1 = X.this.new X1(){ \n"+ + " void baz(){ \n"+ + " System.out.println(\"-X$1.baz()\"); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " } \n"+ + "}\n", + }, + "X.this != null-X$1.baz()"); +} + +public void test035() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " class Y { Y(int i){} } \n"+ + " public static void main(String[] arguments) { \n"+ + " int i = 1; \n" + + " try { \n" + + " X x =null; \n" + + " x.new Y(++i); \n" + // i won't get incremented before NPE + " System.out.println(\"FAILED\"); \n" + + " } catch(NullPointerException e){ \n" + + " System.out.println(\"SUCCESS:\"+i); \n" + + " } \n" + + " } \n"+ + "} \n", + }, + "SUCCESS:1" + ); +} + +public void test036() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " class Y {} \n"+ + " static class Z extends Y { \n"+ + " Z (X x){ \n"+ + " x.super(); \n" + + " } \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " try { \n" + + " new Z(null); \n" + + " System.out.println(\"FAILED\"); \n" + + " } catch(NullPointerException e){ \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=24744 + * http://dev.eclipse.org/bugs/show_bug.cgi?id=23096 + * + * NOTE: since JLS got revised to allow unterminated line comments (32476) + */ +public void test037() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_TaskTags, "TODO:"); + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "p/X.java", + "package p; \n"+ + "public class X {\n"+ + "}\n"+ + "// TODO: something" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in p\\X.java (at line 4)\n" + + " // TODO: something\n" + + " ^^^^^^^^^^^^^^^\n" + + "TODO: something\n" + + "----------\n", + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); +} + +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=24833 + * http://dev.eclipse.org/bugs/show_bug.cgi?id=23096 + * + * NOTE: since JLS got revised to allow unterminated line comments (32476) + */ +public void test038() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_TaskTags, "TODO:"); + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "// TODO: something" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 1)\n" + + " // TODO: something\n" + + " ^^^^^^^^^^^^^^^\n" + + "TODO: something\n" + + "----------\n", + // runtime results + null /* do not check output string */, + "java.lang.ClassNotFoundException" /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); +} + +/* + * unreachable empty statement/block are diagnosed in 1.3 + */ +public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args){ \n"+ + " for (;null != null;); \n"+ + " for (;null != null;){} \n"+ + " for (;false;); \n"+ + " for (;false;){} \n"+ + " while (false); \n"+ + " while (false){} \n"+ + " if (false) {} else {} \n"+ + " if (false) ; else ; \n"+ + " System.out.println(\"FAILED\"); \n" + + " } \n"+ + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " for (;false;); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " for (;false;){} \n" + + " ^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " while (false); \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " while (false){} \n" + + " ^^\n" + + "Unreachable code\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " if (false) {} else {} \n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " if (false) ; else ; \n" + + " ^\n" + + "Dead code\n" + + "----------\n"); +} +// jls6.5.5.1 - simple type names favor member type over toplevel one. +//http://bugs.eclipse.org/bugs/show_bug.cgi?id=30705 +public void test040() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " interface Homonym {} \n"+ // takes precedence over others. + " void foo() { \n"+ + " class Homonym extends X { \n"+ + " { \n"+ + " class Y extends Homonym {}; \n"+ // X$Homonym + " } \n"+ + " } \n"+ + " } \n"+ + "} \n"+ + "class Homonym extends X { \n"+ + " { \n"+ + " class Y extends Homonym {}; \n"+ // X$Homonym + " } \n"+ + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class Homonym extends X { \n" + + " ^^^^^^^\n" + + "The type Homonym is hiding the type X.Homonym\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class Y extends Homonym {}; \n" + + " ^^^^^^^\n" + + "The type X.Homonym cannot be the superclass of Y; a superclass must be a class\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " class Y extends Homonym {}; \n" + + " ^^^^^^^\n" + + "The type X.Homonym cannot be the superclass of Y; a superclass must be a class\n" + + "----------\n"); +} +/* + * 30856 - 1.4 compliant mode should consider abstract method matches + */ +public void test041() { + this.runConformTest( + new String[] { + "p/X.java", //================================ + "package p; \n" + + "public class X { \n" + + " void foo(int i, float f){} \n" + + " public static void main(String[] args) { \n" + + " q.Y y = new q.Y.Z(); \n" + + " y.bar(); \n" + + " } \n" + + "} \n", + "q/Y.java", //================================ + "package q; \n" + + "public abstract class Y extends p.X implements I { \n" + + " public void bar(){ foo(1, 2); } \n" + + " public static class Z extends Y { \n" + + " public void foo(float f, int i) { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + "} \n" + + "interface I { \n" + + " void foo(float f, int i); \n" + + "} \n", + }, + "SUCCESS"); +} +/* + * variation - 30856 - 1.4 compliant mode should consider abstract method matches + */ +public void test042() { + this.runConformTest( + new String[] { + "p/X.java", //================================ + "package p; \n" + + "public class X extends X0 { \n" + + " void foo(int i, float f){} \n" + + " public static void main(String[] args) { \n" + + " q.Y y = new q.Y.Z(); \n" + + " y.bar(); \n" + + " } \n" + + "} \n" + + "class X0 { \n" + + " void foo(int i, double d){} \n" + // extra match + "} \n", + "q/Y.java", //================================ + "package q; \n" + + "public abstract class Y extends p.X implements I { \n" + + " public void bar(){ foo(1, 2); } \n" + + " public static class Z extends Y { \n" + + " public void foo(float f, int i) { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + "} \n" + + "interface I { \n" + + " void foo(float f, int i); \n" + + "} \n", + }, + "SUCCESS"); +} + +// binary compatibility +public void _test043() { + this.runConformTest( + new String[] { + "p1/Y.java", + "package p1; \n" + + "public class Y extends A implements I { \n" + + " public static void main(String[] args) { \n" + + " Y.printValues(); \n" + + " } \n" + + " public static void printValues() { \n" + + " System.out.println(\"i=\"+i+\",j=\"+j+\",Y.i=\"+Y.i+\",Y.j=\"+Y.j); \n" + + " } \n" + + "} \n", + "p1/A.java", + "package p1; \n" + + "public class A { \n" + + " static int i = 1; \n" + + "} \n", + "p1/I.java", + "package p1; \n" + + "interface I { \n" + + " int j = \"aa\".length(); \n" + + "} \n", + }, + "i=1,j=2,Y.i=1,Y.j=2"); + + this.runConformTest( + new String[] { + "p1/A.java", + "package p1; \n" + + "public class A { \n" + + " static int j = 3; \n" + + " public static void main(String[] args) { \n" + + " Y.printValues(); \n" + + " } \n" + + "} \n", + "p1/I.java", + "package p1; \n" + + "interface I { \n" + + " int j = \"aaaa\".length(); \n" + + "} \n", + }, + "i=4,j=3,Y.i=4,Y.j=3", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} +/* + * array.clone() should use array type in methodRef + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=36307 + */ +public void test044() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " args.clone(); \n"+ + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " 1 invokevirtual java.lang.String[].clone() : java.lang.Object [16]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +// 39172 +public void test045() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public static void main(String[] args) { \n" + + " System.out.println(\"FAILED\"); \n" + + " return;; \n" + // unreachable empty statement - must complain in 1.4 mode + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " return;; \n" + + " ^\n" + + "Unreachable code\n" + + "----------\n" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39467 + * should diagnose missing abstract method implementation + */ +public void test046() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + "}\n" + + "abstract class Y extends Z {\n" + + " public abstract void foo();\n" + + "}\n" + + "abstract class Z extends T {\n" + + "}\n" + + "class T implements I {\n" + + " public void foo(){}\n" + + "}\n" + + "interface I {\n" + + " public void foo ();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y {\n" + + " ^\n" + + "The type X must implement the inherited abstract method Y.foo()\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public abstract void foo();\n" + + " ^^^^^\n" + + "The method foo() of type Y should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40442 + * Abstract class fails to invoke interface-defined method in 1.4 compliance mode. + */ +public void test047() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends AbstractDoubleAlgorithm {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " ((ObjectAlgorithm)(new X())).operate(new Double(0));\n" + + " }\n" + + " public void operate(Double pDouble)\n" + + " {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "abstract class AbstractDoubleAlgorithm implements DoubleAlgorithm {\n" + + " public void operate(Object pObject)\n" + + " {\n" + + " operate((Double)pObject);\n" + + " }\n" + + "}\n" + + "interface DoubleAlgorithm extends ObjectAlgorithm {\n" + + " void operate(Double pDouble);\n" + + "}\n" + + "interface ObjectAlgorithm {\n" + + " void operate(Object pObject);\n" + + "}" + }, + "SUCCESS" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40442 + * Abstract class fails to invoke interface-defined method in 1.4 compliance mode. + * variation with 2 found methods + */ +public void test048() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends AbstractDoubleAlgorithm {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " ((ObjectAlgorithm)(new X())).operate(new Double(0));\n" + + " }\n" + + " public void operate(Double pDouble)\n" + + " {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "abstract class AbstractDoubleAlgorithm implements DoubleAlgorithm {\n" + + " public void operate(Object pObject)\n" + + " {\n" + + " operate((Double)pObject);\n" + + " }\n" + + " public void operate(X x) {}\n" + + "}\n" + + "interface DoubleAlgorithm extends ObjectAlgorithm {\n" + + " void operate(Double pDouble);\n" + + "}\n" + + "interface ObjectAlgorithm {\n" + + " void operate(Object pObject);\n" + + "}" + }, + "SUCCESS" + ); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=41278 + */ +public void test049() { + this.runNegativeTest( + new String[] { + "pa/Caller.java", + "package pa;\n" + + "import pb.Concrete;\n" + + "public class Caller {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Concrete aConcrete = new Concrete(); \n" + + " aConcrete.callme();\n" + + " }\n" + + "}\n", + "pa/Abstract.java", + "package pa;\n" + + "public abstract class Abstract {\n" + + "\n" + + " protected void callme(){}\n" + + "}\n", + "pb/Concrete.java", + "package pb;\n" + + "public class Concrete extends pa.Abstract {\n" + + "\n" + + " protected void callme(){ System.out.println(\"SUCCESS\"); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in pa\\Caller.java (at line 7)\n" + + " aConcrete.callme();\n" + + " ^^^^^^\n" + + "The method callme() from the type Concrete is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in pb\\Concrete.java (at line 4)\n" + + " protected void callme(){ System.out.println(\"SUCCESS\"); }\n" + + " ^^^^^^^^\n" + + "The method callme() of type Concrete should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); +} + +public void test050() { + this.runNegativeTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " int a1 = 1;\n" + + " int a2 = 1;\n" + + " a1 = 2;\n" + + " while (false) {};\n" + + " a2 = 2;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 10)\n" + + " while (false) {};\n" + + " ^^\n" + + "Unreachable code\n" + + "----------\n"); +} + +public void test051() { + this.runNegativeTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " int a1 = 1;\n" + + " int a2 = 1;\n" + + " a1 = 2;\n" + + " while (false);\n" + + " a2 = 2;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 10)\n" + + " while (false);\n" + + " ^\n" + + "Unreachable code\n" + + "----------\n"); +} + +public void test052() { + this.runNegativeTest( + new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static void main(String[] argv) {\n" + + " foo();\n" + + " }\n" + + " private int i;\n" + + " static class Y extends X {\n" + + " int x = i;\n" + + " }\n" + + " public static void foo() {\n" + + " return;\n" + + " }\n" + + "}", + + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " int a1 = 1;\n" + + " int a2 = 1;\n" + + " a1 = 2;\n" + + " while (false);\n" + + " a2 = 2;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p\\A.java (at line 8)\n" + + " int x = i;\n" + + " ^\n" + + "Cannot make a static reference to the non-static field i\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p\\X.java (at line 10)\n" + + " while (false);\n" + + " ^\n" + + "Unreachable code\n" + + "----------\n"); +} + +public void test053() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "class X {\n" + + " static class A {\n" + + " interface I {\n" + + " int a = 3;\n" + + " }\n" + + " } \n" + + " interface I { \n" + + " int b = 4;\n" + + " }\n" + + " class Y extends A implements I {\n" + + " Object F() {\n" + + " return new I() {\n" + + " int c = a; // WE SHOULD NOT BE ABLE TO SEE BOTH a and b\n" + + " int d = b; // WE SHOULD NOT BE ABLE TO SEE BOTH a and b\n" + + " };\n" + + " }\n" + + " }\n" + + "}", + } + ); +} + +public void test054() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " static class A {\n" + + " interface I {\n" + + " int a = 3;\n" + + " void foo();\n" + + " }\n" + + " }\n" + + " interface I {\n" + + " int a = 4;\n" + + " void foo();\n" + + " }\n" + + " class Y extends A implements I {\n" + + " public void foo() {\n" + + " new I() {\n" + + " public void foo() {\n" + + " System.out.println(\"X$1::foo-\" + a);\n" + + " }\n" + + " }\n" + + " .foo();\n" + + " }\n" + + " }\n" + + "public static void main(String argv[]) {\n" + + " new X().new Y().foo();\n" + + "}\n" + + "}", + } + ); +} +public void test055() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "p/X.java", + "package p;\n" + + "public class X {\n" + + " static class A {\n" + + " interface I2 {\n" + + " int a = 3;\n" + + " void foo();\n" + + " }\n" + + " }\n" + + " interface I1 {\n" + + " int a = 4;\n" + + " void foo(int a);\n" + + " }\n" + + " class Y extends A implements I1 {\n" + + " public void foo(int a) {\n" + + " new I2() {\n" + + " public void foo() {\n" + + " System.out.println(\"X$1::foo-\" + a);\n" + + " }\n" + + " }\n" + + " .foo();\n" + + " }\n" + + " }\n" + + "public static void main(String argv[]) {\n" + + " new X().new Y().foo(8);\n" + + "}\n" + + "}", + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in p\\X.java (at line 11)\n" + + " void foo(int a);\n" + + " ^\n" + + "The parameter a is hiding a field from type X.I1\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 14)\n" + + " public void foo(int a) {\n" + + " ^\n" + + "The parameter a is hiding a field from type X.I1\n" + + "----------\n", + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); +} + +public void test056() { + this.runConformTest( + new String[] { + "p/MethodQualification.java", + "package p;\n" + + "public class MethodQualification {\n" + + " void foo() {\n" + + " System.out.println(\"Inherited foo() for anonymous type\");\n" + + " class Local {\n" + + " void foo(){\n" + + " System.out.println(\"Enclosing foo() for anonymous type\");\n" + + " new MethodQualification () { {foo();} };\n" + + " }\n" + + " };\n" + + " } \n" + + "}", + }, + "" + ); +} + +public void test057() { + this.runConformTest( + new String[] { + "p/AG.java", + "package p;\n" + + "/**\n" + + " * 1F9RITI\n" + + " */\n" + + "public class AG {\n" + + " public class X {\n" + + " class B {\n" + + " int intValueOfB = -9;\n" + + " }\n" + + " class SomeInner extends A {\n" + + " void someMethod() {\n" + + " int i = new B().intValueOfB; \n" + + " }\n" + + " }\n" + + " }\n" + + " class A {\n" + + " class B {\n" + + " int intValueOfB = -9;\n" + + " }\n" + + " }\n" + + "}", + }, + "" + ); +} + +public void test058() { + this.runConformTest( + new String[] { + "p/AE.java", + "package p;\n" + + "/**\n" + + " * 1F9RITI\n" + + " */\n" + + "public class AE {\n" + + " public class X {\n" + + " int intValue = 153;\n" + + " class SomeInner extends A {\n" + + " void someMethod() {\n" + + " int i = intValue; \n" + + " }\n" + + " }\n" + + " }\n" + + " class A {\n" + + " int intValue = 153;\n" + + " }\n" + + "}", + }, + "" + ); +} + +public void test059() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "p/FieldQualification.java", + "package p;\n" + + "public class FieldQualification {\n" + + " String field = \"Inherited field for anonymous type\";\n" + + "void foo() {\n" + + " class Local {\n" + + " String field = \"Enclosing field for anonymous type\";\n" + + " void foo() {\n" + + " System.out.println(\"Enclosing foo() for anonymous type\");\n" + + " new FieldQualification() {\n" + + " {\n" + + " System.out.println(field);\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + "}\n" + + "}", + }, + // compiler results + "----------\n" + + "1. WARNING in p\\FieldQualification.java (at line 6)\n" + + " String field = \"Enclosing field for anonymous type\";\n" + + " ^^^^^\n" + + "The field Local.field is hiding a field from type FieldQualification\n" + + "----------\n", + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); +} + +public void test060() { + this.runConformTest( + new String[] { + "p/AF.java", + "package p;\n" + + "/**\n" + + " * 1F9RITI\n" + + " */\n" + + "public class AF {\n" + + " public class X {\n" + + " int intMethod() {\n" + + " return 3333;\n" + + " }\n" + + " class SomeInner extends A {\n" + + " void someMethod() {\n" + + " int i = intMethod(); \n" + + " }\n" + + " }\n" + + " }\n" + + " class A {\n" + + " int intMethod() {\n" + + " return 3333;\n" + + " }\n" + + " }\n" + + "}", + }, + "" + ); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=32342 + */ +public void test061() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "p/X.java", //====================== + "package p; \n" + + "public class X extends q.Y { \n" + + " X someField; \n" + // no ambiguity since inherited Y.X isn't visible + "} \n" + + "class Z extends q.Y { \n" + + " Z someField; \n" + // ambiguous + "} \n", + "q/Y.java", //====================== + "package q; \n" + + "public class Y { \n" + + " private static class X {} \n" + + " public static class Z {} \n" + + "} \n" + }, + // compiler results + "", + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.DEFAULT /* javac test options */); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11435 + * variant - must still complain when targeting super abstract method + */ +public void test062() { + + this.runNegativeTest( + new String[] { + "p1/Y.java", + "package p1; \n"+ + "public class Y extends AbstractT { \n"+ + " public void init(){ \n"+ + " super.init(); \n"+ + " } \n"+ + "} \n"+ + "abstract class AbstractT implements J { \n"+ + "} \n"+ + "interface J { \n"+ + " void init(); \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\Y.java (at line 4)\n" + + " super.init(); \n" + + " ^^^^^^^^^^^^\n" + + "Cannot directly invoke the abstract method init() for the type J\n" + + "----------\n"); // expected log +} + +public void test063() { + String[] sources = new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " class Y extends X {} \n"+ + " class Z extends Y { \n"+ + " Z(){ \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n" + + " } \n" + + " public static void main(String[] arguments) { \n"+ + " new X().new Z(); \n"+ + " } \n"+ + "} \n", + }; + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runConformTest(sources, "SUCCESS"); + } else { + this.runNegativeTest( + sources, + "----------\n" + + "1. ERROR in p1\\X.java (at line 5)\n" + + " Z(){ \n" + + " ^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); + } +} + +/** + * Refuse selection of own enclosing instance arg for super constructor call in 1.5 compliant mode + */ +public void test064() { + String[] sources = new String[] { + "Foo.java", + "public class Foo {\n" + + " public static void main(String[] args) {\n"+ + " System.out.println(\"SUCCESS\");\n"+ + " }\n"+ + " public class Bar extends Foo {\n" + + " public Bar() {\n" + + " }\n" + + " }\n" + + " public class Baz extends Bar {\n" + + " public Baz() {\n" + + " }\n" + + " }\n" + + "}\n" + }; + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runConformTest(sources, "SUCCESS"); + } else { + this.runNegativeTest( + sources, + "----------\n" + + "1. ERROR in Foo.java (at line 10)\n" + + " public Baz() {\n" + + " ^^^^^\n" + + "No enclosing instance of type Foo is available due to some intermediate constructor invocation\n" + + "----------\n"); + } +} + +public void test065() { + String[] sources = new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new Y().new Z().bar(); \n"+ + " } \n"+ + " String foo() { return \"X-foo\"; } \n"+ + " class Y extends X { \n"+ + " String foo() { return \"Y-foo\"; } \n"+ + " class Z extends Y { \n"+ + " Z(){ \n"+ + " //X.this.super(); \n"+ + " } \n"+ + " String foo() { return \"Z-foo\"; } \n"+ + " void bar () { \n"+ + " System.out.println(X.this.foo()); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }; + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runConformTest(sources, "X-foo"); + } else { + this.runNegativeTest( + sources, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " String foo() { return \"Y-foo\"; } \n" + + " ^^^^^\n" + + "The method foo() of type X.Y should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " Z(){ \n" + + " ^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " String foo() { return \"Z-foo\"; } \n" + + " ^^^^^\n" + + "The method foo() of type X.Y.Z should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); + } +} + +/* + * Check that anonymous type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test066() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(Object o) {}\n" + + " class M extends X {\n" + + " M(){\n" + + " super(null);\n" + + " }\n" + + " M(Object o) {\n" + + " super(new M(){});\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(new M(){});\n" + + " ^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); +} + +/* + * 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"; + } else if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + expectedError = + "----------\n" + + "1. 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", + "public class X {\n" + + " X(Object o) {\n" + + " }\n" + + " class N extends X {\n" + + " N(Object o) {\n" + + " super(o);\n" + + " }\n" + + " }\n" + + " class M extends N {\n" + + " M() {\n" + + " super(null); //1\n" + + " }\n" + + " M(Object o) {\n" + + " super(new M());//2\n" + + " }\n" + + " }\n" + + "}\n", + }, + expectedError); +} + +/* + * Check that indirect member type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test068() { + String[] sources = new String[] { + "X.java", + "public class X {\n" + + " class MX1 extends X {\n" + + " MX1() {\n" + + " }\n" + + " }\n" + + " class MX2 extends MX1 {\n" + + " MX2() {\n" + + " super(); // ko\n" + + " }\n" + + " MX2(X x) {\n" + + " this(); // ok\n" + + " }\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runConformTest(sources); + } else { + this.runNegativeTest( + sources, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(); // ko\n" + + " ^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); + } +} + +/* + * 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"; + } else if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + 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", + "public class X {\n" + + " class MX3 extends X {\n" + + " MX3(X x) {\n" + + " }\n" + + " }\n" + + " class MX4 extends MX3 {\n" + + " MX4() {\n" + + " super(new MX4()); // ko\n" + + " }\n" + + " MX4(X x) {\n" + + " this(); // ok\n" + + " }\n" + + " MX4(int i) {\n" + + " this(new MX4()); // ko\n" + + " }\n" + + " }\n" + + "}\n", + }, + expectedError); +} + +// binary compatibility +public void test070() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Middle {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(new X().field);\n" + + " }\n" + + "}\n" + + "class Middle extends Top {\n" + + "}\n" + + "class Top {\n" + + " String field = \"Top.field\";\n" + + "}\n" + }, + "Top.field"); + + this.runConformTest( + new String[] { + "Middle.java", + "public class Middle extends Top {\n" + + " public static void main(String[] arguments) { \n"+ + " X.main(arguments); \n" + + " } \n" + + " String field = \"Middle.field\";\n" + + "}\n" + }, + "Middle.field", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} + +/* + * 43429 - AbstractMethodError calling clone() at runtime when using Eclipse compiler + */ +public void test071() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public interface Copyable extends Cloneable {\n" + + " public Object clone() throws CloneNotSupportedException;\n" + + " }\n" + + " public interface TestIf extends Copyable {\n" + + " }\n" + + " public static class ClassA implements Copyable {\n" + + " public Object clone() throws CloneNotSupportedException {\n" + + " return super.clone();\n" + + " }\n" + + " }\n" + + " public static class ClassB implements TestIf {\n" + + " public Object clone() throws CloneNotSupportedException {\n" + + " return super.clone();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " Copyable o1 = new ClassA();\n" + + " ClassB o2 = new ClassB();\n" + + " TestIf o3 = o2;\n" + + " Object clonedObject;\n" + + " clonedObject = o1.clone();\n" + + " clonedObject = o2.clone();\n" + + " // The following line fails at runtime with AbstractMethodError when\n" + + " // compiled with Eclipse\n" + + " clonedObject = o3.clone();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +public void test072() { + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " f();\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " static void f() {\n" + + " Object x = new Object() {\n" + + " {\n" + + " if (true) throw null;\n" + + " }\n" + + " };\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +// 52221 +public void test073() { + + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " public static void main(String[] args) {\n" + + " \n" + + " switch(args.length) {\n" + + " \n" + + " case 1:\n" + + " int i = 0;\n" + + " class Local {\n" + + " }\n" + + " break;\n" + + " \n" + + " case 0 :\n" + + " System.out.println(i); // local var can be referred to, only an initialization pb\n" + + " System.out.println(new Local());\n" + + " break;\n" + + "\n" + + " case 2 :\n" + + " class Local { // not a duplicate\n" + + " }\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " System.out.println(new Local());\n" + + " ^^^^^\n" + + "Local cannot be resolved to a type\n" + + "----------\n"); +} + +// checking for captured outer local initialization status +// NOTE: only complain against non-inlinable outer locals +// http://bugs.eclipse.org/bugs/show_bug.cgi?id=26134 +public void test074() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) { \n" + + " String nonInlinedString = \"[Local]\"; \n" + + " int i = 2; \n" + + " switch(i){ \n" + + " case 1: \n" + + " final String displayString = nonInlinedString;\n" + + " final String inlinedString = \"a\"; \n" + + " class Local { \n" + + " public String toString() { \n" + + " return inlinedString + displayString; \n" + + " } \n" + + " } \n" + + " case 2: \n" + + " System.out.print(new Local()); \n" + + " System.out.print(\"-\"); \n" + + " System.out.println(new Local(){ \n" + + " public String toString() { \n" + + " return super.toString()+\": anonymous\"; \n" + + " } \n" + + " }); \n" + + " } \n" + + " } \n" + + "} \n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " public String toString() { \n" + + " ^^^^^^^^^^\n" + + "The method toString() of type Local should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " System.out.print(new Local()); \n" + + " ^^^^^\n" + + "Local cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 17)\n" + + " System.out.println(new Local(){ \n" + + " ^^^^^\n" + + "Local cannot be resolved to a type\n" + + "----------\n"); +} +public void test075() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void foo(int p1) {} \n" + + " public void foo(short p1) {} \n" + + "} \n", + "Y.java", + "public class Y extends X { \n" + + " public void foo(long p1) {} \n" + + " public void testEc() { foo((short)1); } \n" + + "} \n", + }, + "SUCCESS"); +} + +/** + * Test fix for bug 58069. + * @see 58069 + */ +public void test076() { + this.docSupport = true; + runNegativeTest( + new String[] { + "IX.java", + "interface IX {\n" + + " public static class Problem extends Exception {}\n" + + "}\n", + "X.java", + "public abstract class X {\n" + + " public static class Problem extends Exception {}\n" + + " public abstract static class InnerClass implements IX {\n" + + " /**\n" + + " * @throws Problem \n" + + " */\n" + + " public void foo() throws IllegalArgumentException {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. WARNING in IX.java (at line 2)\n" + + " public static class Problem extends Exception {}\n" + + " ^^^^^^^\n" + + "The serializable class Problem does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public static class Problem extends Exception {}\n" + + " ^^^^^^^\n" + + "The serializable class Problem does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @throws Problem \n" + + " ^^^^^^^\n" + + "Javadoc: Exception Problem is not declared\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +/** + * Test fix bug 58069 for method. + * Note that problem is not flagged in doc comments as it is only raised while verifying + * implicit method and javadoc resolution does not use it. + */ +public void test077() { + this.docSupport = true; + this.runConformTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar() { \n"+ + " return \"FAILED\"; \n" + + " } \n"+ + " void foo(){ \n"+ + " /** @see #bar() */\n" + + " class Y extends Secondary { \n"+ + " /** @see #bar() */\n" + + " String z = bar(); \n" + + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " String bar(){ return \"FAILED\"; } \n" + + "} \n" + } + ); +} +/** + * Test fix bug 58069 for field. + * Note that problem is not flagged in doc comments as it is only raised while verifying + * Name or Qualified name references and javadoc reference is a field reference. + */ +public void test078() { + this.docSupport = true; + this.runConformTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar = \"FAILED\";"+ + " void foo(){ \n"+ + " /** @see #bar */\n" + + " class Y extends Secondary { \n"+ + " /** @see #bar */\n" + + " String z = bar; \n"+ + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " String bar = \"FAILED\"; \n" + + "} \n" + } + ); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47227 + */ +// TODO: Enable after Bug 552769 is fixed +public void test079() { + + String expectedErrorLog = "----------\n" + + "1. ERROR in Hello.java (at line 1)\n" + + " void ___eval() {\n" + + " ^^^^\n" + + "Syntax error on token \"void\", @ expected\n" + + "----------\n" + + "2. ERROR in Hello.java (at line 1)\n" + + " void ___eval() {\n" + + " ^\n" + + "Syntax error on token \")\", delete this token\n" + + "----------\n" + + "3. ERROR in Hello.java (at line 9)\n" + + " };\n" + + "}\n" + + " ^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + + "4. ERROR in Hello.java (at line 23)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "5. ERROR in Hello.java (at line 23)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete MemberValue\n" + + "----------\n" + + "6. ERROR in Hello.java (at line 23)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \")\" to complete Modifiers\n" + + "----------\n" + + "7. ERROR in Hello.java (at line 23)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"enum Identifier\" to complete EnumHeader\n" + + "----------\n" + + "8. ERROR in Hello.java (at line 23)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"EnumBody\" to complete CompilationUnit\n" + + "----------\n"; + String expectedErrorLog_J14 = "----------\n" + + "1. ERROR in Hello.java (at line 1)\n" + + " void ___eval() {\n" + + " ^^^^\n" + + "Syntax error on token \"void\", record expected\n" + + "----------\n" + + "2. ERROR in Hello.java (at line 2)\n" + + " new Runnable() {\n" + + " ^^^\n" + + "Syntax error on token \"new\", record expected\n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "Hello.java", + "void ___eval() {\n" + + " new Runnable() {\n" + + " int ___run() throws Throwable {\n" + + " return blah;\n" + + " }\n" + + " private String blarg;\n" + + " public void run() {\n" + + " }\n" + + " };\n" + + "}\n" + + "public class Hello {\n" + + " private static int x;\n" + + " private String blah;\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public void hello() {\n" + + " }\n" + + " public boolean blah() {\n" + + " return false;\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK14 ? + expectedErrorLog :expectedErrorLog_J14 + ); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67643 + * from 1.5 source level on most specific common super type is allowed + */ +public void test080() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {\n" + + " private static class C1 extends ArrayList {\n" + + " }\n" + + " private static class C2 extends ArrayList {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " ArrayList list = args == null ? new C1(): new C2();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +public void test081() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X foo() { return this; } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " public Y foo() { return this; } \n" + + "}\n" + }, + "SUCCESS"); +} +// covariance +public void test082() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X x = new X1();\n" + + " System.out.println(x.foo());\n" + + " }\n" + + " Object foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 extends X {\n" + + " String foo() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} + +/** + * Test fix for bug 71079: [1.5] ClassCastException resolving Javadoc + * @see 71079 + */ +public void test083() { + this.docSupport = true; + this.runConformTest( + new String[] { + "X.java", + "public @interface X {\n" + + " /** Value */\n" + + " String[] value();\n" + + "}\n" + } + ); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=66533 + */ +public void test084() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object enum = null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object enum = null;\n" + + " ^^^^\n" + + "Syntax error on token \"enum\", delete this token\n" + + "----------\n"); +} +/** + * Test unused import with static + */ +public void test085() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "A.java", + "import static j.l.S.*;\n" + + "import static j.l.S.in;\n" + + "\n" + + "public class A {\n" + + "\n" + + "}\n", + "j/l/S.java", + "package j.l;\n" + + "public class S {\n" + + " public static int in;\n" + + "}\n" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in A.java (at line 1)\n" + + " import static j.l.S.*;\n" + + " ^^^^^\n" + + "The import j.l.S is never used\n" + + "----------\n" + + "2. WARNING in A.java (at line 2)\n" + + " import static j.l.S.in;\n" + + " ^^^^^^^^\n" + + "The import j.l.S.in is never used\n" + + "----------\n", + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); +} +/** + * Test invalid static import syntax + */ +public void test086() { + this.runNegativeTest( + new String[] { + "p/S.java", + "package p;\n" + + "public class S {\n" + + " public final static String full = \"FULL\";\n" + + " public final static String success = \"SUCCESS\";\n" + + "}\n", + "X.java", + "import static p.S;\n" + + "public class X {\n" + + " public static void main ( String[] args) {\n" + + " \n" + + " System.out.print(full+\" \"+p.S.success);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static p.S;\n" + + " ^^^\n" + + "The static import p.S must be a field or member type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.print(full+\" \"+p.S.success);\n" + + " ^^^^\n" + + "full cannot be resolved to a variable\n" + + "----------\n" + ); +} +public void test087() { + this.runNegativeTest( + new String[] { + "S.java", + "public class S {\n" + + " public final static String full = \"FULL\";\n" + + " public final static String success = \"SUCCESS\";\n" + + "}\n", + "X.java", + "import static S;\n" + + "public class X {\n" + + " public static void main ( String[] args) {\n" + + " \n" + + " System.out.print(full+\" \"+S.success);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static S;\n" + + " ^\n" + + "The import S cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.print(full+\" \"+S.success);\n" + + " ^^^^\n" + + "full cannot be resolved to a variable\n" + + "----------\n" + ); +} +public void test088() { + String errorMessage = + "----------\n" + + "1. WARNING in p\\X.java (at line 4)\n" + + " public class X extends Date implements Runnable{\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 12)\n" + + " this.super();\n" + + " ^^^^\n" + + "Illegal enclosing instance specification for type Object\n" + + "----------\n" + + "3. WARNING in p\\X.java (at line 39)\n" + + " Method _getMethod = c.getMethod(\"d\",null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type null of the last argument to method getMethod(String, Class...) doesn't exactly match the vararg parameter type. Cast to Class[] to confirm the non-varargs invocation, or pass individual arguments of type Class for a varargs invocation.\n" + + "----------\n"; + String javaVersion = System.getProperty("java.version"); + int allPossibleLevels = getPossibleComplianceLevels(); + boolean isLevelGreaterThan5 = (allPossibleLevels & ~(F_1_3 | F_1_4 | F_1_5)) != 0; + if (isLevelGreaterThan5 + || (allPossibleLevels == AbstractCompilerTest.F_1_5 && javaVersion.indexOf("1.5") == -1)) { + errorMessage = + "----------\n" + + "1. WARNING in p\\X.java (at line 4)\n" + + " public class X extends Date implements Runnable{\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 12)\n" + + " this.super();\n" + + " ^^^^\n" + + "Illegal enclosing instance specification for type Object\n" + + "----------\n" + + "3. WARNING in p\\X.java (at line 39)\n" + + " Method _getMethod = c.getMethod(\"d\",null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type null of the last argument to method getMethod(String, Class...) doesn't exactly match the vararg parameter type. Cast to Class[] to confirm the non-varargs invocation, or pass individual arguments of type Class for a varargs invocation.\n" + + "----------\n" + + "4. WARNING in p\\X.java (at line 39)\n" + + " Method _getMethod = c.getMethod(\"d\",null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getMethod(String, Class...) belongs to the raw type Class. References to generic type Class should be parameterized\n" + + "----------\n"; + } + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Date;\n" + + "import java.lang.reflect.*;\n" + + "public class X extends Date implements Runnable{\n" + + " \n" + + " Integer w = Integer.valueOf(90);\n" + + " protected double x = 91.1;\n" + + " public long y = 92;\n" + + " static public Boolean z = Boolean.valueOf(true); \n" + + " public class X_inner {\n" + + " public X_inner() {\n" + + " this.super();\n" + + " System.out.println(\"....\");\n" + + " }\n" + + " }\n" + + " X_inner a = new X_inner();\n" + + " public interface X_interface {\n" + + " public void f(); \n" + + " }\n" + + " static {\n" + + " System.out.println(\"Static initializer\");\n" + + " }\n" + + " public X() { } \n" + + " public X(int a1,int b1) { } \n" + + " private void a() { System.out.println(\"A\");} \n" + + " protected void b() { System.out.println(\"B\");} \n" + + " public void c() { System.out.println(\"C\");} \n" + + " static public int d() {System.out.println(\"Static D\");return -1;} \n" + + " public static void main(String args[]) {\n" + + " X b = new X();\n" + + " Class c = b.getClass();\n" + + " Class _getClasses [] = X.class.getClasses(); \n" + + "// System.out.println(_getClasses[0].toString());\n" + + "// System.out.println(_getClasses[1].toString());\n" + + " if (_getClasses.length == 0) {System.out.println(\"FAILED\");};\n" + + " Constructor _getConstructors[] = c.getConstructors(); \n" + + " try {\n" + + " Field _getField = c.getField(\"y\");\n" + + " Method _getMethod = c.getMethod(\"d\",null);\n" + + " \n" + + " Boolean b_z = X.z; \n" + + " }\n" + + " catch (NoSuchFieldException e) { System.out.println(\"NoSuchFieldException\");}\n" + + " catch (NoSuchMethodException e) { System.out.println(\"NoSuchMethodException\");};\n" + + " } \n" + + " public void run() {System.out.println(\"RUN\");} \n" + + "}", + }, + errorMessage); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78089 + */ +public void test089() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " @interface I1 {}\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +//78104 +public void test090() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(int[] ints, Object o) {\n" + + " ints = ints.clone();\n" + + " ints = (int[])ints.clone();\n" + + " X x = this.clone();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X x = this.clone();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + ); +} +//78104 - variation +public void test091() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " args = args.clone();\n" + + " }\n" + + "}", + }, + "" + ); +} +// check autoboxing only enabled in 1.5 source mode +public void test092() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Boolean b) {\n" + + " if (b) { \n" + + " int i = 0;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "" + ); +} +public void test093() { + this.runNegativeTest( + new String[] { + "p/X_1.java", + "package p;\n" + + "/* dena JTest Suite, Version 2.2, September 1997\n" + + " * Copyright (c) 1995-1997 Modena Software (I) Pvt. Ltd., All Rights Reserved\n" + + " */\n" + + "/* Section : Inner classes \n" + + " * FileName : ciner026.java\n" + + " * Purpose : Positive test for Inner classes\n" + + " * \n" + + " * An anonymous class can have initializers but cannot have a constructor.\n" + + " * The argument list of the associated new expression is implicitely \n" + + " * passed to the constructor of the super class. \n" + + " *\n" + + " */\n" + + " \n" + + " class X_1 {\n" + + " static int xx = 100;\n" + + " //inner class Y \n" + + " static class Y { \n" + + " public int j = 0;\n" + + " Y(int x){ j = x; }\n" + + " } \n" + + " public void call_inner()\n" + + " {\n" + + " int i = test_anonymous().j;\n" + + " } \n" + + " public static void main(String argv[])\n" + + " {\n" + + " X_1 ox = new X_1();\n" + + " ox.call_inner(); \n" + + " } \n" + + "public void newMethod ( ) {\n" + + " Float f1 = null;\n" + + " f1=(f1==0.0)?1.0:f1;\n" + + "}\n" + + " static Y test_anonymous()\n" + + " { \n" + + " //anonymous implementation of class Y\n" + + " return new Y(xx) //xx should be implicitely passed to Y()\n" + + " {\n" + + " }; \n" + + " \n" + + " } //end test_anonymous \n" + + "} ", + }, + "----------\n" + + "1. ERROR in p\\X_1.java (at line 33)\n" + + " f1=(f1==0.0)?1.0:f1;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from double to Float\n" + + "----------\n" + ); +} +/* + * Test unused import warning in presence of syntax errors + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21022 + */ +public void test094(){ + + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*; \n" + + "public class X { \n" + + " void foo(){\n" + + " ()\n" + + " IOException e;\n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " ()\n" + + " ^\n" + + "Syntax error on token \"(\", AnnotationName expected before this token\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=84743 +public void test095(){ + + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "interface J {\n" + + " String foo();\n" + + "}\n" + + " \n" + + "public class X implements I {\n" + + " public int foo() {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = new X();\n" + + " try {\n" + + " J j = (J) i;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=47074 + */ +public void test096() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " interface A {\n" + + " void doSomething();\n" + + " }\n" + + "\n" + + " interface B {\n" + + " int doSomething();\n" + + " }\n" + + "\n" + + " interface C extends B {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " \n" + + " A a = null;\n" + + " C c = (C)a; \n" + + " }\n" + + "}" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=79396 +public void test097() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " int cst = X1.CST;\n" + + " X2.Root.foo();\n" + + " }\n" + + " static void foo() {}\n" + + "}\n" + + "\n" + + "class X1 {\n" + + " static {\n" + + " System.out.print(\"[X1]\");\n" + + " }\n" + + " public static final int CST = 12;\n" + + " static X Root = null;\n" + + "}\n" + + "class X2 {\n" + + " static {\n" + + " System.out.print(\"[X2]\");\n" + + " }\n" + + " public final int CST = 12;\n" + + " static X Root = null;\n" + + "}\n" + }, + "[X2]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=78906 +public void test098() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " System.out.print(\"foo\");\n" + + " }\n" + + " class Y {\n" + + " String this$0;\n" + + " String this$0$;\n" + + " void print() { \n" + + " foo();\n" + + " System.out.println(this$0+this$0$);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y y = new X().new Y();\n" + + " y.this$0 = \"hello\";\n" + + " y.this$0$ = \"world\";\n" + + " y.print();\n" + + " }\n" + + "}\n" + }, + "foohelloworld"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=77349 +public void test099() { + this.runNegativeTest( + new String[] { + "I.java", + "public interface I extends Cloneable {\n" + + " class Inner {\n" + + " Object bar(I i) throws CloneNotSupportedException { return i.clone(); }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 3)\n" + + " Object bar(I i) throws CloneNotSupportedException { return i.clone(); }\n" + + " ^^^^^\n" + + "The method clone() is undefined for the type I\n" + + "----------\n" + ); +} + +public void test100() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int \\ud800\\udc05\\ud800\\udc04\\ud800\\udc03\\ud800\\udc02\\ud800\\udc01\\ud800\\udc00;\n" + + " void foo() {\n" + + " int \\ud800\\udc05\\ud800\\udc04\\ud800\\udc03\\ud800\\udc02\\ud800\\udc01\\ud800\\udc00;\n" + + " }\n" + + "}\n" + } + ); +} +public void test101() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Character c0 = \'a\';\n" + + " public static void main(String argv[]) {\n" + + " Character c1;\n" + + " c1 = \'b\';\n" + + "\n" + + " Character c2 = \'c\';\n" + + " Character[] c3 = { \'d\' };\n" + + " \n" + + " }\n" + + "}\n" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108856 +public void test102() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Object() {\n" + + " {\n" + + " new Object() {\n" + + " {\n" + + " System.out.println(this.getClass().getName());\n" + + " System.out.println(this.getClass().getSimpleName());\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + "X$1$1"); +} +public void test103() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(X.class);\n" + + " }\n" + + "}\n", + }, + "class X"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 ldc [1]\n" + + " 5 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [22]\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 8, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 9] local: args index: 0 type: java.lang.String[]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=125570 +public void test104() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " new Object() {\n" + + " {\n" + + " new Object() {\n" + + " {\n" + + " class Y {\n" + + " {\n" + + " System.out.print(this.getClass());\n" + + " System.out.print(\' \');\n" + + " System.out.print(this.getClass().getSimpleName());\n" + + " }\n" + + " }\n" + + " ;\n" + + " new Y();\n" + + " }\n" + + " };\n" + + " }\n" + + " };\n" + + " }\n" + + "}" + }, + "class X$1$1$1Y Y"); +} + +// enclosing instance - note that the behavior is different in 1.3 and 1.4 +public void test105() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Y { }\n" + + " static class Z1 {\n" + + " Runnable m;\n" + + " Z1(Runnable p) {\n" + + " this.m = p;\n" + + " }\n" + + " }\n" + + " class Z2 extends Z1 {\n" + + " Z2(final Y p) {\n" + + " super(new Runnable() {\n" + + " public void run() {\n" + + " foo(p);\n" + + " }\n" + + " });\n" + + " }\n" + + " }\n" + + " void foo(Y p) { }\n" + + "}\n" + }, + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=79798 +public void test106() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "import java.util.zip.*;\n" + + "public class X {\n" + + " void x() throws ZipException {\n" + + " IandJ ij= new K();\n" + + " ij.m();\n" + + " }\n" + + " void y() throws ZipException {\n" + + " K k= new K();\n" + + " k.m();\n" + + " }\n" + + "}\n" + + "interface I { void m() throws IOException; }\n" + + "interface J { void m() throws ZipException; }\n" + + "interface IandJ extends I, J {}\n" + + "class K implements IandJ { public void m() throws ZipException { } }" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99986 +public void test107() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " C c = new D();\n" + + " c.xyz();\n" + + " }\n" + + "}\n" + + "class AException extends Exception { }\n" + + "class BException extends Exception { }\n" + + "interface A { void xyz() throws AException; }\n" + + "interface B { void xyz() throws BException; }\n" + + "interface C extends A, B { }\n" + + "class D implements C {\n" + + " public void xyz() { System.out.println(1); }\n" + + "}" + }, + "1"); +} + +public static Class testClass() { + return Compliance_1_5.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_6.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_6.java new file mode 100644 index 0000000000..3d83fced85 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_6.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2009, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Compliance_1_6 extends AbstractComparableTest { + +public Compliance_1_6(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_6); +} +// Use this static initializer to specify subset for tests +// All specified tests which does not belong to the class are skipped... +static { +// Names of tests to run: can be "testBugXXXX" or "BugXXXX") +// TESTS_NAMES = new String[] { "Bug58069" }; +// Numbers of tests to run: "test" will be run for each number of this array +// TESTS_NUMBERS = new int[] { 104 }; +// Range numbers of tests to run: all tests between "test" and "test" 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() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public interface MyInterface {\n" + + " public void hello();\n" + + " }\n" + + " private static class MyClass implements MyInterface {\n" + + " @Override\n" + + " public void hello() {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " MyClass m = new MyClass();\n" + + " m.hello();\n" + + " }\n" + + "}" + }, + "Hello", + null /* no extra class libraries */, + true /* flush output directory */, + null, + options, + null/* do not perform statements recovery */); +} +public static Class testClass() { + return Compliance_1_6.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_7.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_7.java new file mode 100644 index 0000000000..3dbb11f36a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_7.java @@ -0,0 +1,233 @@ +/******************************************************************************* + * Copyright (c) 2011, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 390889 - [1.8][compiler] Evaluate options to support 1.7- projects against 1.8 JRE. + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +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" will be run for each number of this array +// TESTS_NUMBERS = new int[] { 104 }; +// Range numbers of tests to run: all tests between "test" and "test" 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 List 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); +} +// Project with 1.7 compliance compiled against JRE 7, 8 +// regular case +public void testBug390889_a() { + Map options = 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); + this.runConformTest( + new String[] { + "MyComp.java", + "import java.util.Comparator;\n" + + "public class MyComp implements Comparator {\n" + + " @Override\n" + + " public int compare(Object o1, Object o2) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class MyStringComp implements Comparator {\n" + + " @Override\n" + + " public int compare(String o1, String o2) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null, + options, + null/* do not perform statements recovery */); +} +// Project with 1.7 compliance compiled against JRE 8 +// default method implements a regular abstract interface method +public void testBug390889_b() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + runConformTest( + new String[] { + "I1.java", + "interface I0 {\n" + + " void foo();\n" + + "}\n" + + "public interface I1 extends I0 {\n" + + " @Override\n" + + " default void foo() {}\n" + + "}\n" + }); + + Map options = 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); + this.runConformTest( + new String[] { + "C1.java", + "public class C1 implements I1 {\n" + + "}\n" + }, + "", + null /* no extra class libraries */, + false /* don't flush output directory */, + null, + options, + null/* do not perform statements recovery */); +} +// Project with 1.7 compliance compiled against JRE 7, 8 +// assert that different forms of method invocation do not produce different result (as javac does) +public void testBug390889_c() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + runConformTest( + new String[] { + "I.java", + "interface I {\n" + + " default void foo() {}\n" + + "}\n" + }); + + Map options = 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); + this.runConformTest( + new String[] { + "CI.java", + "public class CI implements I {\n" + + " void test(I i) {\n" + + " this.foo();\n" + + " i.foo();\n" + + " }\n" + + "}\n" + }, + "", + null /* no extra class libraries */, + false /* don't flush output directory */, + null, + options, + null/* do not perform statements recovery */); +} +// Project with 1.7 compliance compiled against JRE 8 +// assert that 1.8 constructs are not allowed at compliance 1.7 +public void testBug490988() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + Map options = 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); + this.runNegativeTest( + new String[] { + "Thing.java", + "import java.util.Comparator;\n" + + "import java.util.Iterator;\n" + + "public class Thing implements Iterator {\n" + + " void breaking() {\n" + + " Iterator.super.remove(); // not 1.7-compliant (must be an error)\n" + + " Comparator.naturalOrder(); // not 1.7-compliant (bad error message)\n" + + " }\n" + + " @Override\n" + + " public boolean hasNext() {\n" + + " return false;\n" + + " }\n" + + " @Override\n" + + " public Object next() {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Thing().breaking();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Thing.java (at line 5)\n" + + " Iterator.super.remove(); // not 1.7-compliant (must be an error)\n" + + " ^^^^^^^^^^^^^^\n" + + "Super method references to interface default methods are allowed only at source level 1.8 or above\n" + + "----------\n" + + "2. ERROR in Thing.java (at line 6)\n" + + " Comparator.naturalOrder(); // not 1.7-compliant (bad error message)\n" + + " ^^^^^^^^^^^^\n" + + "References to interface static methods are allowed only at source level 1.8 or above\n" + + "----------\n", + null, + false, + options); +} +public static Class testClass() { + return Compliance_1_7.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_CLDC.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_CLDC.java new file mode 100644 index 0000000000..56f06b69b4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_CLDC.java @@ -0,0 +1,321 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Compliance_CLDC extends AbstractRegressionTest { + +public Compliance_CLDC(String name) { + super(name); +} + +/* + * Toggle compiler in mode -1.3 + */ +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_3); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_CLDC1_1); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3); + return options; +} +public static Test suite() { + return buildUniqueComplianceTestSuite(testClass(), ClassFileConstants.JDK1_3); +} +public static Class testClass() { + return Compliance_CLDC.class; +} +// Use this static initializer to specify subset for tests +// All specified tests which does not belong to the class are skipped... +static { +// TESTS_NAMES = new String[] { "Bug58069" }; +// TESTS_NUMBERS = new int[] { 104 }; +// TESTS_RANGE = new int[] { 76, -1 }; +} +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "import java.awt.Image;\n" + + "import java.awt.Toolkit;\n" + + "import java.awt.image.ImageProducer;\n" + + "import java.net.URL;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public Image loadImage(String name) {\n" + + " Toolkit toolkit= Toolkit.getDefaultToolkit();\n" + + " try {\n" + + " URL url= X.class.getResource(name);\n" + + " return toolkit.createImage((ImageProducer) url.getContent());\n" + + " } catch (Exception ex) {\n" + + " }\n" + + " return null;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}", + }, + "OK"); +} +public void test002() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.print(X.class != null);\n" + + " System.out.print(String.class != null);\n" + + " System.out.print(Object.class != null);\n" + + " System.out.print(X.class != null);\n" + + " }\n" + + "}", + }, + "truetruetruetrue"); + + String expectedOutput = + " // Method descriptor #20 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 3 getstatic X.class$0 : java.lang.Class [27]\n" + + " 6 dup\n" + + " 7 ifnonnull 35\n" + + " 10 pop\n" + + " 11 ldc [29]\n" + + " 13 invokestatic java.lang.Class.forName(java.lang.String) : java.lang.Class [30]\n" + + " 16 dup\n" + + " 17 putstatic X.class$0 : java.lang.Class [27]\n" + + " 20 goto 35\n" + + " 23 new java.lang.NoClassDefFoundError [36]\n" + + " 26 dup_x1\n" + + " 27 swap\n" + + " 28 invokevirtual java.lang.Throwable.getMessage() : java.lang.String [38]\n" + + " 31 invokespecial java.lang.NoClassDefFoundError(java.lang.String) [44]\n" + + " 34 athrow\n" + + " 35 ifnull 42\n" + + " 38 iconst_1\n" + + " 39 goto 43\n" + + " 42 iconst_0\n" + + " 43 invokevirtual java.io.PrintStream.print(boolean) : void [47]\n" + + " 46 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 49 getstatic X.class$1 : java.lang.Class [53]\n" + + " 52 dup\n" + + " 53 ifnonnull 81\n" + + " 56 pop\n" + + " 57 ldc [55]\n" + + " 59 invokestatic java.lang.Class.forName(java.lang.String) : java.lang.Class [30]\n" + + " 62 dup\n" + + " 63 putstatic X.class$1 : java.lang.Class [53]\n" + + " 66 goto 81\n" + + " 69 new java.lang.NoClassDefFoundError [36]\n" + + " 72 dup_x1\n" + + " 73 swap\n" + + " 74 invokevirtual java.lang.Throwable.getMessage() : java.lang.String [38]\n" + + " 77 invokespecial java.lang.NoClassDefFoundError(java.lang.String) [44]\n" + + " 80 athrow\n" + + " 81 ifnull 88\n" + + " 84 iconst_1\n" + + " 85 goto 89\n" + + " 88 iconst_0\n" + + " 89 invokevirtual java.io.PrintStream.print(boolean) : void [47]\n" + + " 92 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 95 getstatic X.class$2 : java.lang.Class [57]\n" + + " 98 dup\n" + + " 99 ifnonnull 127\n" + + " 102 pop\n" + + " 103 ldc [59]\n" + + " 105 invokestatic java.lang.Class.forName(java.lang.String) : java.lang.Class [30]\n" + + " 108 dup\n" + + " 109 putstatic X.class$2 : java.lang.Class [57]\n" + + " 112 goto 127\n" + + " 115 new java.lang.NoClassDefFoundError [36]\n" + + " 118 dup_x1\n" + + " 119 swap\n" + + " 120 invokevirtual java.lang.Throwable.getMessage() : java.lang.String [38]\n" + + " 123 invokespecial java.lang.NoClassDefFoundError(java.lang.String) [44]\n" + + " 126 athrow\n" + + " 127 ifnull 134\n" + + " 130 iconst_1\n" + + " 131 goto 135\n" + + " 134 iconst_0\n" + + " 135 invokevirtual java.io.PrintStream.print(boolean) : void [47]\n" + + " 138 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 141 getstatic X.class$0 : java.lang.Class [27]\n" + + " 144 dup\n" + + " 145 ifnonnull 173\n" + + " 148 pop\n" + + " 149 ldc [29]\n" + + " 151 invokestatic java.lang.Class.forName(java.lang.String) : java.lang.Class [30]\n" + + " 154 dup\n" + + " 155 putstatic X.class$0 : java.lang.Class [27]\n" + + " 158 goto 173\n" + + " 161 new java.lang.NoClassDefFoundError [36]\n" + + " 164 dup_x1\n" + + " 165 swap\n" + + " 166 invokevirtual java.lang.Throwable.getMessage() : java.lang.String [38]\n" + + " 169 invokespecial java.lang.NoClassDefFoundError(java.lang.String) [44]\n" + + " 172 athrow\n" + + " 173 ifnull 180\n" + + " 176 iconst_1\n" + + " 177 goto 181\n" + + " 180 iconst_0\n" + + " 181 invokevirtual java.io.PrintStream.print(boolean) : void [47]\n" + + " 184 return\n" + + " Exception Table:\n" + + " [pc: 11, pc: 16] -> 23 when : java.lang.ClassNotFoundException\n" + + " [pc: 57, pc: 62] -> 69 when : java.lang.ClassNotFoundException\n" + + " [pc: 103, pc: 108] -> 115 when : java.lang.ClassNotFoundException\n" + + " [pc: 149, pc: 154] -> 161 when : java.lang.ClassNotFoundException\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 46, line: 5]\n" + + " [pc: 92, line: 6]\n" + + " [pc: 138, line: 7]\n" + + " [pc: 184, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 185] local: args index: 0 type: java.lang.String[]\n" + + " Stack map : number of frames 16\n" + + " [pc: 23, full, stack: {java.lang.ClassNotFoundException}, locals: {java.lang.String[]}]\n" + + " [pc: 35, full, stack: {java.io.PrintStream, java.lang.Class}, locals: {java.lang.String[]}]\n" + + " [pc: 42, full, stack: {java.io.PrintStream}, locals: {java.lang.String[]}]\n" + + " [pc: 43, full, stack: {java.io.PrintStream, int}, locals: {java.lang.String[]}]\n" + + " [pc: 69, full, stack: {java.lang.ClassNotFoundException}, locals: {java.lang.String[]}]\n" + + " [pc: 81, full, stack: {java.io.PrintStream, java.lang.Class}, locals: {java.lang.String[]}]\n" + + " [pc: 88, full, stack: {java.io.PrintStream}, locals: {java.lang.String[]}]\n" + + " [pc: 89, full, stack: {java.io.PrintStream, int}, locals: {java.lang.String[]}]\n" + + " [pc: 115, full, stack: {java.lang.ClassNotFoundException}, locals: {java.lang.String[]}]\n" + + " [pc: 127, full, stack: {java.io.PrintStream, java.lang.Class}, locals: {java.lang.String[]}]\n" + + " [pc: 134, full, stack: {java.io.PrintStream}, locals: {java.lang.String[]}]\n" + + " [pc: 135, full, stack: {java.io.PrintStream, int}, locals: {java.lang.String[]}]\n" + + " [pc: 161, full, stack: {java.lang.ClassNotFoundException}, locals: {java.lang.String[]}]\n" + + " [pc: 173, full, stack: {java.io.PrintStream, java.lang.Class}, locals: {java.lang.String[]}]\n" + + " [pc: 180, full, stack: {java.io.PrintStream}, locals: {java.lang.String[]}]\n" + + " [pc: 181, full, stack: {java.io.PrintStream, int}, locals: {java.lang.String[]}]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +public void test003() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.print(int.class != null);\n" + + " }\n" + + "}", + }, + "true"); + + String expectedOutput = + "// Compiled from X.java (version 1.1 : 45.3, super bit)\n" + + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 getstatic java.lang.Integer.TYPE : java.lang.Class [22]\n" + + " 6 ifnull 13\n" + + " 9 iconst_1\n" + + " 10 goto 14\n" + + " 13 iconst_0\n" + + " 14 invokevirtual java.io.PrintStream.print(boolean) : void [28]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 17, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: args index: 0 type: java.lang.String[]\n" + + " Stack map : number of frames 2\n" + + " [pc: 13, full, stack: {java.io.PrintStream}, locals: {java.lang.String[]}]\n" + + " [pc: 14, full, stack: {java.io.PrintStream, int}, locals: {java.lang.String[]}]\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +public void test004() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.InputStream;\n" + + "\n" + + "public class X {\n" + + " private static final Y[] A = new Y[1];\n" + + "\n" + + " public static void x() {\n" + + " for (int i = 0; i < 0; i++) {\n" + + " try {\n" + + " A[i] = foo(X.class.getResourceAsStream(\"\"), null);\n" + + " } catch (Throwable e) {\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " public static boolean a = false;\n" + + "\n" + + " private static int b = -1;\n" + + "\n" + + " private static int C = 0;\n" + + "\n" + + " public static void z(int c) {\n" + + " if (!a || (b == c && A[c].foo() == C)) {\n" + + " return;\n" + + " }\n" + + " y();\n" + + " b = c;\n" + + " try {\n" + + " A[c].bar();\n" + + " } catch (Throwable e) {\n" + + " }\n" + + " }\n" + + "\n" + + " public static void y() {\n" + + " }\n" + + "\n" + + " static Y foo(InputStream stream, String s) {\n" + + " return null;\n" + + " }\n" + + "}", + "Y.java", + "interface Y {\n" + + " int foo();\n" + + " void bar();\n" + + "}" + }, + ""); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConcurrentBatchCompilerTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConcurrentBatchCompilerTest.java new file mode 100644 index 0000000000..202ee51af2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConcurrentBatchCompilerTest.java @@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2012, 2014 IBM Corporation GK Software AG and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.PrintWriter; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.ast.FakedTrackingVariable; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class ConcurrentBatchCompilerTest extends BatchCompilerTest { + + public static Test suite() { + return buildUniqueComplianceTestSuite(testClass(), ClassFileConstants.JDK1_6); + } + public static Class testClass() { + return ConcurrentBatchCompilerTest.class; + } + public ConcurrentBatchCompilerTest(String name) { + super(name); + } + + Thread runner1; + Thread runner2; + + static int COUNT = 100; + + /* Invoke the compiler COUNT times to increase bug probabililty. */ + @Override + protected boolean invokeCompiler(PrintWriter out, PrintWriter err, Object extraArguments, TestCompilationProgress compilationProgress) { + boolean success = true; + for (int j=0; j parts= new ArrayList();\n" + + " int commaIndex= idString.indexOf(',');\n" + + " while (commaIndex > 0) {\n" + + " int length= Integer.valueOf(idString.substring(0, commaIndex)).intValue();\n" + + " String part= idString.substring(commaIndex+1, commaIndex+1+length);\n" + + " parts.add(part);\n" + + " idString= idString.substring(commaIndex+1+length);\n" + + " commaIndex= idString.indexOf(',');\n" + + " }\n" + + " String[] result= parts.toArray(new String[parts.size()]);\n" + + " return new CompositeId(result);\n" + + " }\n" + + " \n" + + " @Override\n" + + " public String toString() {\n" + + " StringBuffer buf= new StringBuffer();\n" + + " for (int i= 0; i < fParts.length; i++) {\n" + + " buf.append(fParts[i].length());\n" + + " buf.append(',');\n" + + " buf.append(fParts[i]);\n" + + " }\n" + + " return buf.toString();\n" + + " }\n" + + " \n" + + " public String get(int index) {\n" + + " return fParts[index];\n" + + " }\n" + + " \n" + + " public int getPartCount() {\n" + + " return fParts.length;\n" + + " }\n" + + "}\n" + + "" + }, + "\"" + OUTPUT_DIR + File.separator + "org/eclipse/jdt/internal/launching/CompositeId.java\"" + + " -1.5 -g -preserveAllLocals" + + " -proceedOnError -d \"" + OUTPUT_DIR + "\"", + "", + "", + false); + } catch (Throwable t) { + thrown[0] = t; + } + } + }); + this.runner2 = new Thread(new Runnable() { + @Override + public void run() { + try { + // from ResourceLeakTests.test056e(): + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "test01/X.java", + "package test01;\n" + + "import java.io.File;\n" + + "import java.io.FileReader;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " FileReader getReader(String filename) throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " return fileReader;\n" + // don't complain here, pass responsibility to caller + " }\n" + + " void foo() throws IOException {\n" + + " FileReader reader = getReader(\"somefile\");\n" + + " char[] in = new char[50];\n" + + " reader.read(in);\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "test01/X.java\"" + + " -1.5 -g -preserveAllLocals -err:+resource" + + " -proceedOnError -d \"" + OUTPUT_DIR + "\"", + "", + errorOutput.toString(), + false); + } catch (Throwable t) { + thrown[1] = t; + } + } + }); + + this.runner2.start(); + this.runner1.start(); + this.runner1.join(); + this.runner2.join(); + if (thrown[0] != null) throw thrown[0]; + if (thrown[1] != null) throw thrown[1]; + } finally { + FakedTrackingVariable.TEST_372319 = false; + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConditionalExpressionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConditionalExpressionTest.java new file mode 100644 index 0000000000..63c4d650b2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConditionalExpressionTest.java @@ -0,0 +1,632 @@ +/******************************************************************************* + * Copyright (c) 2005, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class ConditionalExpressionTest extends AbstractRegressionTest { + + public ConditionalExpressionTest(String name) { + super(name); + } + + // 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[] { "test003" }; +// TESTS_NUMBERS = new int[] { 65 }; +// TESTS_RANGE = new int[] { 11, -1 }; + } + public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); + } + + public static Class testClass() { + return ConditionalExpressionTest.class; + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=100162 + public void test001() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " final boolean isA = true;\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " System.out.print(x.isA ? \"SUCCESS\" : \"FAILURE\");\n" + + " }\n" + + "}", + }, + "SUCCESS" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=107193 + public void test002() { + this.runConformTest( + new String[] { + "X.java", + "class RecipeElement {\n" + + " public static final RecipeElement[] NO_CHILDREN= new RecipeElement[0]; \n" + + "}\n" + + "class Ingredient extends RecipeElement { }\n" + + "class X extends RecipeElement {\n" + + " private Ingredient[] fIngredients;\n" + + " public RecipeElement[] getChildren() {\n" + + " return fIngredients == null ? NO_CHILDREN : fIngredients;\n" + + " }\n" + + "}", + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=426078, Bug 426078 - [1.8] VerifyError when conditional expression passed as an argument + public void test003() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean isOdd(boolean what) {\n" + + " return square(what ? new Integer(1) : new Integer(2)) % 2 == 1; // trouble here\n" + + " }\n" + + " int square(int i) {\n" + + " return i * i;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(new X().isOdd(true));\n" + + " }\n" + + "}\n", + }, + "true" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=423685, - [1.8] poly conditional expression must not use lub + public void test004() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + "class A{/**/}\n" + + "class B extends A {/**/}\n" + + "class G {\n" + + " G gb=null;\n" + + " G gsa=null;\n" + + " G l = (true)? gsa : gb;\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " G l = (true)? gsa : gb;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from G to G\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + "class A{/**/}\n" + + "class B extends A {/**/}\n" + + "class G {\n" + + " G gb=null;\n" + + " G gsa=null;\n" + + " G l = (true)? gsa : gb;\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", + }, + "OK" + ); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=425181, - Cast expression in ternary operation reported as incompatible + public void test005() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " I i = true ? (I) null : (I) null; // Type mismatch reported\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "interface J extends I {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " I i = true ? (I) null : (I) null; // Type mismatch reported\n" + + " ^\n" + + "J is a raw type. References to generic type J should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I i = true ? (I) null : (I) null; // Type mismatch reported\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from I to I\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " I i = true ? (I) null : (I) null; // Type mismatch reported\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\n" + + " I i = true ? (I) null : (I) null; // Type mismatch reported\n" + + " ^\n" + + "J is a raw type. References to generic type J should be parameterized\n" + + "----------\n" + ); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " I i = true ? (I) null : (I) null; // Type mismatch reported\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "interface J extends I {}\n", + }, + "OK" + ); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=426315, - [1.8][compiler] UnsupportedOperationException with conditional expression + public void test006() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int foo(Object x) {\n" + + " return 0;\n" + + " }\n" + + " static int foo(int e) { \n" + + " return 1; \n" + + " }\n" + + " public static void main(String args[]) {\n" + + " Object x = new Object();\n" + + " System.out.println(foo(true ? x : new int[0]) != 0);\n" + + " }\n" + + "}\n", + }, + "false" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=426680, - [1.8][compiler] Incorrect handling of poly conditional leads to CCE + public void test007() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "interface BinaryOperation {\n" + + " T operate(T x, T y);\n" + + "}\n" + + "class StringCatenation implements BinaryOperation { \n" + + " public String operate(String x, String y) { return x + y; }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " foo(false ? (a,b)->a+b :new StringCatenation());\n" + + " }\n" + + " static void foo(BinaryOperation x) {\n" + + " x.operate(5, 15);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " foo(false ? (a,b)->a+b :new StringCatenation());\n" + + " ^^^\n" + + "The method foo(BinaryOperation) in the type X is not applicable for the arguments ((false ? ( a, b) -> (a + b) : new StringCatenation()))\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " foo(false ? (a,b)->a+b :new StringCatenation());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from StringCatenation to BinaryOperation\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=426680, - [1.8][compiler] Incorrect handling of poly conditional leads to CCE + public void test008() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "interface BinaryOperation {\n" + + " T operate(T x, T y);\n" + + "}\n" + + "class StringCatenation implements BinaryOperation { \n" + + " public String operate(String x, String y) { return x + y; }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " foo(false ? new StringCatenation() : (a,b)->a+b);\n" + + " }\n" + + " static void foo(BinaryOperation x) {\n" + + " x.operate(5, 15);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " foo(false ? new StringCatenation() : (a,b)->a+b);\n" + + " ^^^\n" + + "The method foo(BinaryOperation) in the type X is not applicable for the arguments ((false ? new StringCatenation() : ( a, b) -> (a + b)))\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " foo(false ? new StringCatenation() : (a,b)->a+b);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from StringCatenation to BinaryOperation\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427207, - [1.8][bytecode] Runtime type problem: Instruction type does not match stack map + // Reference poly conditional in assignment context + public void test009() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(test(1, X::intToSome));\n" + + " }\n" + + " static Some test(T value, Function f) {\n" + + " return (value == null) ? new Nothing() : f.apply(value);\n" + + " }\n" + + " static SomeInt intToSome(int i) {\n" + + " return new SomeInt();\n" + + " }\n" + + " static abstract class Some {}\n" + + " static class SomeInt extends Some {\n" + + " public String toString() {\n" + + " return \"SomeInt instance\";\n" + + " }\n" + + " }\n" + + " static class Nothing extends Some {}\n" + + "}\n", + }, + "SomeInt instance"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427207, - [1.8][bytecode] Runtime type problem: Instruction type does not match stack map + // Reference poly conditional in poly invocation context + public void test010() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(test(1, X::intToSome));\n" + + " }\n" + + " static Some test(T value, Function f) {\n" + + " return id((value == null) ? new Nothing<>() : f.apply(value));\n" + + " }\n" + + " static T id(T t) {\n" + + " return t;\n" + + " }\n" + + " static SomeInt intToSome(int i) {\n" + + " return new SomeInt();\n" + + " }\n" + + " static abstract class Some {}\n" + + " static class SomeInt extends Some {\n" + + " public String toString() {\n" + + " return \"SomeInt instance\";\n" + + " }\n" + + " }\n" + + " static class Nothing extends Some {}\n" + + "}\n", + }, + "SomeInt instance"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427207, - [1.8][bytecode] Runtime type problem: Instruction type does not match stack map + // Reference poly conditional in assignment context, order reversed. + public void test011() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(test(1, X::intToSome));\n" + + " }\n" + + " static Some test(T value, Function f) {\n" + + " return (value == null) ? f.apply(value) : new Nothing();\n" + + " }\n" + + " static SomeInt intToSome(int i) {\n" + + " return new SomeInt();\n" + + " }\n" + + " static abstract class Some {}\n" + + " static class SomeInt extends Some {\n" + + " public String toString() {\n" + + " return \"SomeInt instance\";\n" + + " }\n" + + " }\n" + + " static class Nothing extends Some {\n" + + " public String toString() {\n" + + " return \"Nothing instance\";\n" + + " }\n" + + " }\n" + + "}\n", + }, + "Nothing instance"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427207, - [1.8][bytecode] Runtime type problem: Instruction type does not match stack map + // Reference poly conditional in poly invocation context, order reversed. + public void test012() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(test(1, X::intToSome));\n" + + " }\n" + + " static Some test(T value, Function f) {\n" + + " return id((value == null) ? f.apply(value) : new Nothing<>());\n" + + " }\n" + + " static T id(T t) {\n" + + " return t;\n" + + " }\n" + + " static SomeInt intToSome(int i) {\n" + + " return new SomeInt();\n" + + " }\n" + + " static abstract class Some {}\n" + + " static class SomeInt extends Some {\n" + + " public String toString() {\n" + + " return \"SomeInt instance\";\n" + + " }\n" + + " }\n" + + " static class Nothing extends Some {\n" + + " public String toString() {\n" + + " return \"Nothing instance\";\n" + + " }\n" + + " }\n" + + "}\n", + }, + "Nothing instance"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427207, - [1.8][bytecode] Runtime type problem: Instruction type does not match stack map + // Reference poly conditional in poly invocation context, interface types + public void test013() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(test(1, X::intToSome));\n" + + " }\n" + + " static Some test(T value, Function f) {\n" + + " return id((value == null) ? new Nothing<>() : f.apply(value));\n" + + " }\n" + + " static T id(T t) {\n" + + " return t;\n" + + " }\n" + + " static SomeInt intToSome(int i) {\n" + + " return new SomeInt();\n" + + " }\n" + + " static interface Some {}\n" + + " static class SomeInt implements Some {\n" + + " public String toString() {\n" + + " return \"SomeInt instance\";\n" + + " }\n" + + " }\n" + + " static class Nothing implements Some {}\n" + + "}", + }, + "SomeInt instance"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427438, - NPE at org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.generateCode + public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(Class clazz) {\n" + + " }\n" + + " public void error() {\n" + + " boolean test = false;\n" + + " int i = 1;\n" + + " new X(test ? (i == 2 ? D.class : E.class) : null);\n" + + " }\n" + + " public class D {\n" + + " }\n" + + " public class E {\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_5 ? "" : + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public X(Class clazz) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427438, - NPE at org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.generateCode + public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(Class clazz) {\n" + + " }\n" + + " public void error() {\n" + + " boolean test = false;\n" + + " int i = 1;\n" + + " new X(test ? null : (i == 2 ? D.class : E.class));\n" + + " }\n" + + " public class D {\n" + + " }\n" + + " public class E {\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_5 ? "" : + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public X(Class clazz) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427625, - NPE at org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.generateCode + public void test427625() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public void error(Collection c) {\n" + + " boolean b =true;\n" + + " c.add(b ? Integer.valueOf(1)\n" + + " : c==null ? null \n" + + " : c instanceof List ? Integer.valueOf(1) \n" + + " : o()); \n" + + " }\n" + + " public Object o() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "", + null, true, options); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=432487, NullPointerException during compilation using jdk1.8.0 + public void testBug432487() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " String f() {\n" + + " return \"\";\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "void f(String x) {}\n" + + " void bar(Y y) {\n" + + " f(y.f2() == 1 ? null : y.f());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " f(y.f2() == 1 ? null : y.f());\n" + + " ^^\n" + + "The method f2() is undefined for the type Y\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=437444#c113, - Error building JRE8 + public void test437444_c113() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " public X(Z[] n) {\n" + + " super((n == null) ? null : n.clone());\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public Y(Z[] notifications) {\n" + + " }\n" + + "}\n" + + "interface Z {}\n", + }, + ""); + } + public void test437444_2() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " public X(int[] n) {\n" + + " super((n == null) ? null : n.clone());\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public Y(int[] notifications) {\n" + + " }\n" + + "}\n" + + "interface Z {}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=484425: [bytecode] Bad type on operand stack - compiler omitted instructions for unboxing null Boolean + public void test484425() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " if ((false) ? true: null);\n" + + " } catch(NullPointerException npe) {\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "Success"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java new file mode 100644 index 0000000000..f77298a22a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ConstantTest.java @@ -0,0 +1,1632 @@ +/******************************************************************************* + * Copyright (c) 2003, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +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.env.ClassSignature; +import org.eclipse.jdt.internal.compiler.env.EnumConstantSignature; +import org.eclipse.jdt.internal.compiler.impl.BooleanConstant; +import org.eclipse.jdt.internal.compiler.impl.ByteConstant; +import org.eclipse.jdt.internal.compiler.impl.CharConstant; +import org.eclipse.jdt.internal.compiler.impl.Constant; +import org.eclipse.jdt.internal.compiler.impl.DoubleConstant; +import org.eclipse.jdt.internal.compiler.impl.FloatConstant; +import org.eclipse.jdt.internal.compiler.impl.IntConstant; +import org.eclipse.jdt.internal.compiler.impl.LongConstant; +import org.eclipse.jdt.internal.compiler.impl.ShortConstant; +import org.eclipse.jdt.internal.compiler.impl.StringConstant; +import org.eclipse.jdt.internal.compiler.problem.ShouldNotImplement; + +@SuppressWarnings({ "rawtypes" }) +public class ConstantTest extends AbstractRegressionTest { + +public ConstantTest(String name) { + super(name); +} +// Use this static initializer to specify subset for tests +// All specified tests which does not belong to the class are skipped... +static { +// TESTS_PREFIX = "testBug95521"; +// TESTS_NAMES = new String[] { "testBug566332_01" }; +// TESTS_NUMBERS = new int[] { 21 }; +// TESTS_RANGE = new int[] { 23, -1 }; +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} +public void test001() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X { \n" + + "public static void main (String args []) {\n" + + " foo(); \n" + + "}\n" + + "public static void foo() {\n" + + " if(55f!=00000000000000000000055F) // HERE VA/Java detects an unexpected error\n" + + " {\n" + + "System.out.println(\"55f!=00000000000000000000055F\");\n" + + " }\n" + + " else\n" + + " {\n" + + "System.out.println(\"55f==00000000000000000000055F\");\n" + + " }\n" + + " } \n" + + "}\n", + }); +} + +public void test002() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main (String args []) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " if(55f!=00000000000000000000055F) // HERE VA/Java detects an unexpected error\n" + + " {\n" + + " System.out.println(\"55f!=00000000000000000000055F\");\n" + + " }\n" + + " else\n" + + " {\n" + + " System.out.println(\"55f==00000000000000000000055F\");\n" + + " }\n" + + " } \n" + + "}\n", + }); +} + +public void test003() { + this.runConformTest(new String[] { + "p/Z.java", + "package p;\n" + + "public class Z {\n" + + " public static void main(String[] cargs) throws Exception {\n" + + " System.out.println(System.getProperty(\"java.vm.info\", \"J9\"));\n" + + " System.out.write((byte) 0x89);\n" + + " System.out.println();\n" + + " System.out.println(\"\u00E2?\u00B0\");\n" + + " System.out.println(Integer.toHexString(\"\u00E2?\u00B0\".charAt(0)));\n" + + " }\n" + + "}\n", + }); +} + +public void test004() { + this.runConformTest( + new String[] { + "TempClassFormat.java", + "/**\n" + + " * Insert the type's description here.\n" + + " * Creation date: (02/28/01 2:58:07 PM)\n" + + " * @author: Administrator\n" + + " */\n" + + "public class TempClassFormat {\n" + + " // ERROR NUMBERS\n" + + "\n" + + " // Blank field error numbers\n" + + " private static final String PERSON_ID_BLANK = \"2\";\n" + + " private static final String DEMOGRAPHIC_TYPE_BLANK = \"3\";\n" + + " private static final String EMPLOYEE_NUMBER_BLANK = \"23\";\n" + + " private static final String WORK_PHONE_AREA_CODE_BLANK = \"25\";\n" + + " private static final String WORK_PHONE1_BLANK = \"26\";\n" + + " private static final String WORK_PHONE2_BLANK = \"27\";\n" + + " private static final String WORK_ADDRESS1_BLANK = \"28\";\n" + + " private static final String WORK_CITY_BLANK = \"29\";\n" + + " private static final String WORK_STATE_BLANK = \"30\";\n" + + " private static final String WORK_ZIP5_BLANK = \"31\";\n" + + " private static final String BENEFITS_SALARY_BLANK = \"32\";\n" + + " private static final String TRUE_SALARY_BLANK = \"33\";\n" + + " private static final String PAY_FREQUENCY_BLANK = \"34\";\n" + + " private static final String WORK_HOURS_BLANK = \"35\";\n" + + " private static final String LOCATION_ID_BLANK = \"36\";\n" + + " private static final String SALARY_GRADE_BLANK = \"37\";\n" + + " private static final String DATE_OF_HIRE_BLANK = \"38\";\n" + + " private static final String RETIRE_VEST_PERCENT_BLANK = \"39\";\n" + + " private static final String JOB_CODE_BLANK = \"40\";\n" + + " private static final String UNION_FLAG_BLANK = \"41\";\n" + + " private static final String OFFICER_FLAG_BLANK = \"42\";\n" + + " private static final String PIN_USER_ID_BLANK = \"43\";\n" + + " private static final String VENDOR_EMPLOYEE_ID_BLANK = \"44\";\n" + + " private static final String MODIFIED_BY_BLANK = \"8\";\n" + + " private static final String MODIFIED_DATE_BLANK = \"9\";\n" + + " \n" + + " \n" + + " // Invalid field error numbers\n" + + " private static final String DEMOGRAPHIC_TYPE_INVALID = \"54\";\n" + + " private static final String EMPLOYER_ID_INVALID = \"22\";\n" + + " private static final String WORK_STATE_INVALID = \"70\";\n" + + " private static final String PAY_FREQUENCY_INVALID = \"138\";\n" + + " private static final String WORK_HOURS_TOO_SMALL = \"140\";\n" + + " private static final String DATE_OF_HIRE_INVALID = \"75\";\n" + + " private static final String DATE_OF_HIRE_AFTER_TODAY = \"137\";\n" + + " private static final String RETIRE_VEST_PERCENT_TOO_LARGE = \"77\";\n" + + " private static final String RETIRE_VEST_PERCENT_TOO_SMALL = \"139\";\n" + + " private static final String UNION_FLAG_INVALID = \"78\";\n" + + " private static final String OFFICER_FLAG_INVALID = \"79\";\n" + + " private static final String BENEFIT_GROUP_ID_INVALID = \"45\";\n" + + " private static final String LAST_PERSON_SEQ_NUMBER_INVALID = \"80\";\n" + + "\n" + + " // Field not numeric error numbers\n" + + " private static final String WORK_PHONE_AREA_CODE_NOT_NUMERIC = \"67\";\n" + + " private static final String WORK_PHONE1_NOT_NUMERIC = \"68\";\n" + + " private static final String WORK_PHONE2_NOT_NUMERIC = \"69\";\n" + + " private static final String WORK_PHONE_EXTENSION_NOT_NUMERIC = \"109\";\n" + + " private static final String WORK_ZIP5_NOT_NUMERIC = \"71\";\n" + + " private static final String WORK_ZIP4_NOT_NUMERIC = \"46\";\n" + + " private static final String BENEFITS_SALARY_NOT_NUMERIC = \"72\";\n" + + " private static final String TRUE_SALARY_NOT_NUMERIC = \"73\";\n" + + " private static final String WORK_HOURS_NOT_NUMERIC = \"74\";\n" + + " private static final String RETIRE_VEST_PERCENT_NOT_NUMERIC = \"76\";\n" + + " \n" + + " // Field too short error numbers\n" + + " private static final String WORK_PHONE_AREA_CODE_TOO_SHORT = \"110\";\n" + + " private static final String WORK_PHONE1_TOO_SHORT = \"111\";\n" + + " private static final String WORK_PHONE2_TOO_SHORT = \"112\";\n" + + " private static final String WORK_STATE_TOO_SHORT = \"113\";\n" + + " private static final String WORK_ZIP5_TOO_SHORT = \"114\";\n" + + " private static final String WORK_ZIP4_TOO_SHORT = \"115\";\n" + + "\n" + + " // Field too long error numbers\n" + + " private static final String PERSON_ID_TOO_LONG = \"82\";\n" + + " private static final String EMPLOYEE_NUMBER_TOO_LONG = \"116\";\n" + + " private static final String WORK_PHONE_AREA_CODE_TOO_LONG = \"117\";\n" + + " private static final String WORK_PHONE1_TOO_LONG = \"118\";\n" + + " private static final String WORK_PHONE2_TOO_LONG = \"119\";\n" + + " private static final String WORK_PHONE_EXTENSION_TOO_LONG = \"120\";\n" + + " private static final String WORK_ADDRESS1_TOO_LONG = \"121\";\n" + + " private static final String WORK_ADDRESS2_TOO_LONG = \"122\";\n" + + " private static final String WORK_CITY_TOO_LONG = \"123\";\n" + + " private static final String WORK_STATE_TOO_LONG = \"124\";\n" + + " private static final String WORK_ZIP5_TOO_LONG = \"125\";\n" + + " private static final String WORK_ZIP4_TOO_LONG = \"126\";\n" + + " private static final String BENEFITS_SALARY_TOO_LONG = \"127\";\n" + + " private static final String TRUE_SALARY_TOO_LONG = \"128\";\n" + + " private static final String WORK_HOURS_TOO_LONG = \"129\";\n" + + " private static final String LOCATION_ID_TOO_LONG = \"130\";\n" + + " private static final String SALARY_GRADE_TOO_LONG = \"131\";\n" + + " private static final String RETIRE_VEST_PERCENT_TOO_LONG = \"132\";\n" + + " private static final String JOB_CODE_TOO_LONG = \"133\";\n" + + " private static final String PIN_USER_ID_TOO_LONG = \"134\";\n" + + " private static final String VENDOR_EMPLOYEE_ID_TOO_LONG = \"135\";\n" + + " private static final String MODIFIED_BY_TOO_LONG = \"86\";\n" + + "\n" + + " // Administrator approval error numbers\n" + + " private static final String EMPLOYER_ID_REQ_APPR = \"623\";\n" + + " private static final String EMPLOYEE_NUMBER_REQ_APPR = \"624\";\n" + + " private static final String STATUS_FLAG_REQ_APPR = \"625\";\n" + + " private static final String WORK_PHONE_AREA_CODE_REQ_APPR = \"626\";\n" + + " private static final String WORK_PHONE1_REQ_APPR = \"627\";\n" + + " private static final String WORK_PHONE2_REQ_APPR = \"628\";\n" + + " private static final String WORK_PHONE_EXTENSION_REQ_APPR = \"629\";\n" + + " private static final String WORK_ADDRESS1_REQ_APPR = \"630\";\n" + + " private static final String WORK_ADDRESS2_REQ_APPR = \"631\";\n" + + " private static final String WORK_CITY_REQ_APPR = \"632\";\n" + + " private static final String WORK_STATE_REQ_APPR = \"633\";\n" + + " private static final String WORK_ZIP5_REQ_APPR = \"634\";\n" + + " private static final String WORK_ZIP4_REQ_APPR = \"635\";\n" + + " private static final String BENEFITS_SALARY_REQ_APPR = \"636\";\n" + + " private static final String TRUE_SALARY_REQ_APPR = \"637\";\n" + + " private static final String PAY_FREQUENCY_REQ_APPR = \"638\";\n" + + " private static final String WORK_HOURS_REQ_APPR = \"639\";\n" + + " private static final String LOCATION_ID_REQ_APPR = \"640\";\n" + + " private static final String SALARY_GRADE_REQ_APPR = \"641\";\n" + + " private static final String DATE_OF_HIRE_REQ_APPR = \"642\";\n" + + " private static final String RETIRE_VEST_PERCENT_REQ_APPR = \"643\";\n" + + " private static final String JOB_CODE_REQ_APPR = \"644\";\n" + + " private static final String UNION_FLAG_REQ_APPR = \"645\";\n" + + " private static final String OFFICER_FLAG_REQ_APPR = \"646\";\n" + + " private static final String PIN_USER_ID_REQ_APPR = \"647\";\n" + + " private static final String VENDOR_EMPLOYEE_ID_REQ_APPR = \"648\";\n" + + " private static final String BENEFIT_GROUP_ID_REQ_APPR = \"649\";\n" + + " private static final String LAST_PERSON_SEQ_NBR_REQ_APPR = \"650\";\n" + + " \n" + + "public static void main(String[] args) {\n" + + " System.out.println(\"Success\");\n" + + "}\n" + + "}" + }, + "Success"); +} + +public void test005() { + this.runConformTest( + new String[] { + "Code.java", + "public class Code {\n" + + " public static final String s = \"\";\n" + + " public static final String s2 = \"()V\";\n" + + " public Code(int i) {\n" + + " }\n" + + "public static void main(String[] args) {\n" + + " System.out.print(s.length());\n" + + " System.out.println(s2.length());\n" + + "}\n" + + "}" + }, + "83"); +} + +public void test006() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n" + + "public class X { \n" + + " X otherX; \n" + + " static String STR = \"SUCCESS\"; \n" + + " public static void main(String args[]) { \n" + + " try { \n" + + " System.out.println(new X().otherX.STR); \n" + + " } catch(NullPointerException e){ \n" + + " System.out.println(\"FAILED\"); \n" + + " } \n" + + " } \n" + + "} \n", + }, + "SUCCESS"); +} + +/* + * null is not a constant + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26585 + */ +public void test007() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static final boolean F = false; \n"+ + " public static final String Str = F ? \"dummy\" : null; \n"+ + " public static void main(String[] args) { \n"+ + " if (Str == null) \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " else \n"+ + " System.out.println(\"FAILED\"); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS"); +} + +/* + * null is not a constant + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26138 + */ +public void test008() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] args) { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " void foo(){ \n"+ + " while (null == null); //not an inlinable constant\n"+ + " System.out.println(\"unreachable but shouldn't be flagged\"); \n" + + " } \n"+ + "} \n", + }, + "SUCCESS"); +} + +/* + * 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[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) { \n" + + " if (null == null) System.out.print(\"1\"); \n" + + " if ((null==null ? null:null) == (null==null ? null:null)) \n" + + " System.out.print(\"2\"); \n" + + " boolean b = (\"[\" + null + \"]\") == \"[null]\"; // cannot inline \n" + + " System.out.print(\"3\"); \n" + + " final String s = (String) null; \n" + + " if (s == null) System.out.print(\"4\"); \n" + + " final String s2 = (String) \"aaa\"; \n" + + " if (s2 == \"aaa\") System.out.println(\"5\"); \n" + + " } \n" + + "}", + }, + "12345"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 ldc [22]\n" + + " 5 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 8 aconst_null\n" + + " 9 aconst_null\n" + + " 10 if_acmpne 21\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 16 ldc [30]\n" + + " 18 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 21 new java.lang.StringBuffer [32]\n" + + " 24 dup\n" + + " 25 ldc [34]\n" + + " 27 invokespecial java.lang.StringBuffer(java.lang.String) [36]\n" + + " 30 aconst_null\n" + + " 31 invokevirtual java.lang.StringBuffer.append(java.lang.Object) : java.lang.StringBuffer [38]\n" + + " 34 ldc [42]\n" + + " 36 invokevirtual java.lang.StringBuffer.append(java.lang.String) : java.lang.StringBuffer [44]\n" + + " 39 invokevirtual java.lang.StringBuffer.toString() : java.lang.String [47]\n" + + " 42 ldc [51]\n" + + " 44 if_acmpne 51\n" + + " 47 iconst_1\n" + + " 48 goto 52\n" + + " 51 iconst_0\n" + + " 52 istore_1 [b]\n" + + " 53 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 56 ldc [53]\n" + + " 58 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 61 aconst_null\n" + + " 62 astore_2 [s]\n" + + " 63 aload_2 [s]\n" + + " 64 ifnonnull 75\n" + + " 67 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 70 ldc [55]\n" + + " 72 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 75 ldc [57]\n" + + " 77 astore_3 [s2]\n" + + " 78 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 81 ldc [59]\n" + + " 83 invokevirtual java.io.PrintStream.println(java.lang.String) : void [61]\n" + + " 86 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 8, line: 4]\n" + + " [pc: 13, line: 5]\n" + + " [pc: 21, line: 6]\n" + + " [pc: 53, line: 7]\n" + + " [pc: 61, line: 8]\n" + + " [pc: 63, line: 9]\n" + + " [pc: 75, line: 10]\n" + + " [pc: 78, line: 11]\n" + + " [pc: 86, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 87] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 53, pc: 87] local: b index: 1 type: boolean\n" + + " [pc: 63, pc: 87] local: s index: 2 type: java.lang.String\n" + + " [pc: 78, pc: 87] local: s2 index: 3 type: java.lang.String\n"; + + String expectedOutput15 = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 ldc [22]\n" + + " 5 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 8 aconst_null\n" + + " 9 aconst_null\n" + + " 10 if_acmpne 21\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 16 ldc [30]\n" + + " 18 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 21 new java.lang.StringBuilder [32]\n" + + " 24 dup\n" + + " 25 ldc [34]\n" + + " 27 invokespecial java.lang.StringBuilder(java.lang.String) [36]\n" + + " 30 aconst_null\n" + + " 31 invokevirtual java.lang.StringBuilder.append(java.lang.Object) : java.lang.StringBuilder [38]\n" + + " 34 ldc [42]\n" + + " 36 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [44]\n" + + " 39 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [47]\n" + + " 42 ldc [51]\n" + + " 44 if_acmpne 51\n" + + " 47 iconst_1\n" + + " 48 goto 52\n" + + " 51 iconst_0\n" + + " 52 istore_1 [b]\n" + + " 53 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 56 ldc [53]\n" + + " 58 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 61 aconst_null\n" + + " 62 astore_2 [s]\n" + + " 63 aload_2 [s]\n" + + " 64 ifnonnull 75\n" + + " 67 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 70 ldc [55]\n" + + " 72 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 75 ldc [57]\n" + + " 77 astore_3 [s2]\n" + + " 78 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 81 ldc [59]\n" + + " 83 invokevirtual java.io.PrintStream.println(java.lang.String) : void [61]\n" + + " 86 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 8, line: 4]\n" + + " [pc: 13, line: 5]\n" + + " [pc: 21, line: 6]\n" + + " [pc: 53, line: 7]\n" + + " [pc: 61, line: 8]\n" + + " [pc: 63, line: 9]\n" + + " [pc: 75, line: 10]\n" + + " [pc: 78, line: 11]\n" + + " [pc: 86, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 87] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 53, pc: 87] local: b index: 1 type: boolean\n" + + " [pc: 63, pc: 87] local: s index: 2 type: java.lang.String\n" + + " [pc: 78, pc: 87] local: s2 index: 3 type: java.lang.String\n"; + + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + int index = actualOutput.indexOf(expectedOutput15); + if (index == -1 || expectedOutput15.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput15, actualOutput); + } + } else { + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } +} + +/* + * null is not a constant + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26138 + */ +public void test010() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) { \n" + + " if (null == null) {\n"+ + " System.out.print(\"SUCCESS\"); \n" + + " return; \n" + + " } \n" + + " System.out.print(\"SHOULDN'T BE GENERATED\"); \n" + + " } \n" + + "} \n", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 ldc [22]\n" + + " 5 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 8 return\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 12 ldc [30]\n" + + " 14 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 9, line: 7]\n" + + " [pc: 17, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: args index: 0 type: java.lang.String[]\n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} + +//http://bugs.eclipse.org/bugs/show_bug.cgi?id=30704 +public void test011() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public static void main(String[] args) {\n" + + " System.out.print((01.f == 1) && (01e0f == 1)); \n" + + " }\n" + + "}", + }, + "true"); +} + +//http://bugs.eclipse.org/bugs/show_bug.cgi?id=79545 +public void test012() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String C = \"\" + +\' \';\n" + + " public static String I = \"\" + +32;\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.print(C);\n" + + " System.out.print(I);\n" + + " }\n" + + "}", + }, + "3232"); +} +//http://bugs.eclipse.org/bugs/show_bug.cgi?id=97190 +public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(-9223372036854775809L); // KO\n" + + " System.out.println(9223372036854775809L); // KO\n" + + " System.out.println(9223372036854775808L); // KO\n" + + " System.out.println(23092395825689123986L); // KO\n" + + " System.out.println(-9223372036854775808L); // OK\n" + + " System.out.println(9223372036854775807L); // OK\n" + + " System.out.println(2309239582568912398L); // OK\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(-9223372036854775809L); // KO\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The literal 9223372036854775809L of type long is out of range \n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " System.out.println(9223372036854775809L); // KO\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The literal 9223372036854775809L of type long is out of range \n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " System.out.println(9223372036854775808L); // KO\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The literal 9223372036854775808L of type long is out of range \n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " System.out.println(23092395825689123986L); // KO\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The literal 23092395825689123986L of type long is out of range \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110182 +public void test014() throws Exception { + if (this.complianceLevel > ClassFileConstants.JDK1_5) return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X fx;\n" + + " final static boolean DBG = false;\n" + + " void foo1(X x) {\n" + + " if (x.DBG) {\n" + + " boolean b = x.DBG;\n" + + " }\n" + + " boolean bb;\n" + + " if (bb = x.DBG) {\n" + + " boolean b = x.DBG;\n" + + " }\n" + + " }\n" + + " void foo2(X x) {\n" + + " while (x.DBG) {\n" + + " boolean b = x.DBG;\n" + + " }\n" + + " }\n" + + " void foo3(X x) {\n" + + " for (;x.DBG;) {\n" + + " boolean b = x.DBG;\n" + + " }\n" + + " }\n" + + " void foo4(X x) {\n" + + " boolean b = x.DBG ? x == null : x.DBG;\n" + + " }\n" + + " void foo5() {\n" + + " if (this.fx.DBG) {\n" + + " boolean b = this.fx.DBG;\n" + + " }\n" + + " }\n" + + " void foo6() {\n" + + " while (this.fx.DBG) {\n" + + " boolean b = this.fx.DBG;\n" + + " }\n" + + " }\n" + + " void foo7() {\n" + + " for (;this.fx.DBG;) {\n" + + " boolean b = this.fx.DBG;\n" + + " }\n" + + " }\n" + + " void foo8() {\n" + + " boolean b = this.fx.DBG ? this.fx == null : this.fx.DBG;\n" + + " }\n" + + "}\n", + }, + ""); + // ensure boolean codegen got optimized (optimizedBooleanConstant) + String expectedOutput = + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void foo1(X x);\n" + + " 0 iconst_0\n" + + " 1 dup\n" + + " 2 istore_2 [bb]\n" + + " 3 ifeq 8\n" + + " 6 iconst_0\n" + + " 7 istore_3\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 6, line: 10]\n" + + " [pc: 8, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 9] local: this index: 0 type: X\n" + + " [pc: 0, pc: 9] local: x index: 1 type: X\n" + + " [pc: 3, pc: 9] local: bb index: 2 type: boolean\n" + + " \n" + + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 0, Locals: 2\n" + + " void foo2(X x);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 17]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: x index: 1 type: X\n" + + " \n" + + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 0, Locals: 2\n" + + " void foo3(X x);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 22]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: x index: 1 type: X\n" + + " \n" + + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 1, Locals: 3\n" + + " void foo4(X x);\n" + + " 0 iconst_0\n" + + " 1 istore_2 [b]\n" + + " 2 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 24]\n" + + " [pc: 2, line: 25]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 3] local: this index: 0 type: X\n" + + " [pc: 0, pc: 3] local: x index: 1 type: X\n" + + " [pc: 2, pc: 3] local: b index: 2 type: boolean\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo5();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 30]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo6();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 35]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo7();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 40]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo8();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 42]\n" + + " [pc: 2, line: 43]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 3] local: this index: 0 type: X\n" + + " [pc: 2, pc: 3] local: b index: 1 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110182 - variation +public void test015() throws Exception { + if(this.complianceLevel > ClassFileConstants.JDK1_5) return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X fx;\n" + + " final static boolean DBG = false;\n" + + " void foo1(X x) {\n" + + " if (x.DBG) {\n" + + " boolean b = x.DBG;\n" + + " }\n" + + " boolean bb;\n" + + " if (bb = x.DBG) {\n" + + " boolean b = x.DBG;\n" + + " }\n" + + " }\n" + + " void foo2(X x) {\n" + + " while (x.DBG) {\n" + + " boolean b = x.DBG;\n" + + " }\n" + + " }\n" + + " void foo3(X x) {\n" + + " for (;x.DBG;) {\n" + + " boolean b = x.DBG;\n" + + " }\n" + + " }\n" + + " void foo4(X x) {\n" + + " boolean b = x.DBG ? x == null : x.DBG;\n" + + " }\n" + + " void foo5() {\n" + + " if (this.fx.DBG) {\n" + + " boolean b = this.fx.DBG;\n" + + " }\n" + + " }\n" + + " void foo6() {\n" + + " while (this.fx.DBG) {\n" + + " boolean b = this.fx.DBG;\n" + + " }\n" + + " }\n" + + " void foo7() {\n" + + " for (;this.fx.DBG;) {\n" + + " boolean b = this.fx.DBG;\n" + + " }\n" + + " }\n" + + " void foo8() {\n" + + " boolean b = this.fx.DBG ? this.fx == null : this.fx.DBG;\n" + + " }\n" + + "}\n", + }, + ""); + // ensure boolean codegen got optimized (optimizedBooleanConstant) + String expectedOutput = + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void foo1(X x);\n" + + " 0 iconst_0\n" + + " 1 dup\n" + + " 2 istore_2 [bb]\n" + + " 3 ifeq 8\n" + + " 6 iconst_0\n" + + " 7 istore_3\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 6, line: 10]\n" + + " [pc: 8, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 9] local: this index: 0 type: X\n" + + " [pc: 0, pc: 9] local: x index: 1 type: X\n" + + " [pc: 3, pc: 9] local: bb index: 2 type: boolean\n" + + " \n" + + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 0, Locals: 2\n" + + " void foo2(X x);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 17]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: x index: 1 type: X\n" + + " \n" + + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 0, Locals: 2\n" + + " void foo3(X x);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 22]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: x index: 1 type: X\n" + + " \n" + + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 1, Locals: 3\n" + + " void foo4(X x);\n" + + " 0 iconst_0\n" + + " 1 istore_2 [b]\n" + + " 2 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 24]\n" + + " [pc: 2, line: 25]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 3] local: this index: 0 type: X\n" + + " [pc: 0, pc: 3] local: x index: 1 type: X\n" + + " [pc: 2, pc: 3] local: b index: 2 type: boolean\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo5();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 30]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo6();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 35]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo7();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 40]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo8();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [b]\n" + + " 2 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 42]\n" + + " [pc: 2, line: 43]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 3] local: this index: 0 type: X\n" + + " [pc: 2, pc: 3] local: b index: 1 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110182 - variation +public void test016() throws Exception { + if(this.complianceLevel > ClassFileConstants.JDK1_5) return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X fx;\n" + + " final static boolean DBG = false;\n" + + " void foo1(X x) {\n" + + " boolean b;\n" + + " if (false ? false : x.DBG) {\n" + + " boolean bb = x.DBG;\n" + + " }\n" + + " }\n" + + " void foo2(X x) {\n" + + " boolean b;\n" + + " while (x == null ? x.DBG : x.DBG) {\n" + + " boolean bb = x.DBG;\n" + + " }\n" + + " }\n" + + " void foo3(X x) {\n" + + " boolean b;\n" + + " for (;x == null ? x.DBG : x.DBG;) {\n" + + " boolean bb = x.DBG;\n" + + " }\n" + + " }\n" + + " void foo4(X x) {\n" + + " boolean bb = (x == null ? x.DBG : x.DBG) ? x == null : x.DBG;\n" + + " }\n" + + "}\n", + }, + ""); + // ensure boolean codegen got optimized (optimizedBooleanConstant) + String expectedOutput = + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 0, Locals: 2\n" + + " void foo1(X x);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: x index: 1 type: X\n" + + " \n" + + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo2(X x);\n" + + " 0 aload_1 [x]\n" + + " 1 ifnonnull 4\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 12]\n" + + " [pc: 4, line: 15]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " [pc: 0, pc: 5] local: x index: 1 type: X\n" + + " \n" + + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo3(X x);\n" + + " 0 aload_1 [x]\n" + + " 1 ifnonnull 4\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 18]\n" + + " [pc: 4, line: 21]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " [pc: 0, pc: 5] local: x index: 1 type: X\n" + + " \n" + + " // Method descriptor #20 (LX;)V\n" + + " // Stack: 1, Locals: 3\n" + + " void foo4(X x);\n" + + " 0 aload_1 [x]\n" + + " 1 ifnonnull 4\n" + + " 4 iconst_0\n" + + " 5 istore_2 [bb]\n" + + " 6 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 23]\n" + + " [pc: 6, line: 24]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 7] local: this index: 0 type: X\n" + + " [pc: 0, pc: 7] local: x index: 1 type: X\n" + + " [pc: 6, pc: 7] local: bb index: 2 type: boolean\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//http://bugs.eclipse.org/bugs/show_bug.cgi?id=117495 +public void test017() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int x = 2;\n" + + " System.out.println(\"n: \"+(x > 1 ? 2 : 1.0));\n" + + " }\n" + + "}", + }, + "n: 2.0"); +} +//http://bugs.eclipse.org/bugs/show_bug.cgi?id=117495 +public void test018() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"n: \"+(true ? 2 : 1.0));\n" + + " }\n" + + "}", + }, + "n: 2.0"); +} + +// http://bugs.eclipse.org/bugs/show_bug.cgi?id=154822 +// null is not a constant - again +public void test019() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Enclosed {\n" + + " static final String constant = \"\";\n" + + " static final String notAConstant;\n" + + " static {\n" + + " notAConstant = null;\n" + + " }\n" + + " }\n" + + "}", + }, + ""); +} + +// http://bugs.eclipse.org/bugs/show_bug.cgi?id=154822 +// null is not a constant - again +public void test020() { + if (this.complianceLevel >= ClassFileConstants.JDK16) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Inner {\n" + + " static final String constant = \"\";\n" + + " static final String notAConstant = null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " static final String notAConstant = null;\n" + + " ^^^^^^^^^^^^\n" + + "The field notAConstant cannot be declared static in a non-static inner type, unless initialized with a constant expression\n" + + "----------\n"); +} +public void testAllConstants() { + Constant byteConstant = ByteConstant.fromValue((byte) 1); + Constant byteConstant2 = ByteConstant.fromValue((byte) 2); + Constant byteConstant3 = ByteConstant.fromValue((byte) 1); + Constant charConstant = CharConstant.fromValue('c'); + Constant charConstant2 = CharConstant.fromValue('d'); + Constant charConstant3 = CharConstant.fromValue('c'); + Constant booleanConstant = BooleanConstant.fromValue(true); + Constant booleanConstant2 = BooleanConstant.fromValue(false); + Constant booleanConstant3 = BooleanConstant.fromValue(true); + Constant doubleConstant = DoubleConstant.fromValue(1.0); + Constant doubleConstant2 = DoubleConstant.fromValue(2.0); + Constant doubleConstant3 = DoubleConstant.fromValue(1.0); + Constant floatConstant = FloatConstant.fromValue(1.0f); + Constant floatConstant2 = FloatConstant.fromValue(2.0f); + Constant floatConstant3 = FloatConstant.fromValue(1.0f); + Constant intConstant = IntConstant.fromValue(20); + Constant intConstant2 = IntConstant.fromValue(30); + Constant intConstant3 = IntConstant.fromValue(20); + Constant longConstant = LongConstant.fromValue(3L); + Constant longConstant2 = LongConstant.fromValue(4L); + Constant longConstant3 = LongConstant.fromValue(3L); + Constant shortConstant = ShortConstant.fromValue((short) 4); + Constant shortConstant2 = ShortConstant.fromValue((short) 3); + Constant shortConstant3 = ShortConstant.fromValue((short) 4); + Constant stringConstant = StringConstant.fromValue("test"); + Constant stringConstant2 = StringConstant.fromValue("test2"); + Constant stringConstant3 = StringConstant.fromValue("test"); + Constant stringConstant4 = StringConstant.fromValue(null); + Constant stringConstant5 = StringConstant.fromValue(null); + ClassSignature classSignature = new ClassSignature("java.lang.Object".toCharArray()); + ClassSignature classSignature2 = new ClassSignature("java.lang.String".toCharArray()); + ClassSignature classSignature3 = new ClassSignature("java.lang.Object".toCharArray()); + EnumConstantSignature enumConstantSignature = new EnumConstantSignature("myEnum".toCharArray(), "C".toCharArray()); + EnumConstantSignature enumConstantSignature2 = new EnumConstantSignature("myEnum".toCharArray(), "A".toCharArray()); + EnumConstantSignature enumConstantSignature3 = new EnumConstantSignature("myEnum".toCharArray(), "C".toCharArray()); + EnumConstantSignature enumConstantSignature4 = new EnumConstantSignature("myEnum2".toCharArray(), "A".toCharArray()); + + verifyConstantEqualsAndHashcode(byteConstant, byteConstant2, byteConstant3, intConstant); + verifyConstantEqualsAndHashcode(charConstant, charConstant2, charConstant3, byteConstant); + verifyConstantEqualsAndHashcode(booleanConstant, booleanConstant2, booleanConstant3, byteConstant); + verifyConstantEqualsAndHashcode(doubleConstant, doubleConstant2, doubleConstant3, byteConstant); + verifyConstantEqualsAndHashcode(floatConstant, floatConstant2, floatConstant3, byteConstant); + verifyConstantEqualsAndHashcode(intConstant, intConstant2, intConstant3, stringConstant); + verifyConstantEqualsAndHashcode(longConstant, longConstant2, longConstant3, byteConstant); + verifyConstantEqualsAndHashcode(shortConstant, shortConstant2, shortConstant3, byteConstant); + verifyConstantEqualsAndHashcode(stringConstant, stringConstant2, stringConstant3, byteConstant); + verifyConstantEqualsAndHashcode(stringConstant, stringConstant4, stringConstant3, byteConstant); + verifyConstantEqualsAndHashcode(stringConstant4, stringConstant3, stringConstant5, byteConstant); + verifyConstantEqualsAndHashcode(classSignature, classSignature2, classSignature3, byteConstant); + verifyConstantEqualsAndHashcode(enumConstantSignature, enumConstantSignature2, enumConstantSignature3, byteConstant); + verifyConstantEqualsAndHashcode(enumConstantSignature, enumConstantSignature4, enumConstantSignature3, byteConstant); + assertNotNull(Constant.NotAConstant.toString()); + + verifyValues(byteConstant, charConstant, booleanConstant, doubleConstant, floatConstant, intConstant, longConstant, shortConstant, stringConstant); + // check equals between to null string constants + assertTrue(stringConstant4.equals(stringConstant5)); +} +private void verifyValues( + Constant byteConstant, + Constant charConstant, + Constant booleanConstant, + Constant doubleConstant, + Constant floatConstant, + Constant intConstant, + Constant longConstant, + Constant shortConstant, + Constant stringConstant) { + + // byteValue() + byteConstant.byteValue(); + charConstant.byteValue(); + try { + booleanConstant.byteValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + doubleConstant.byteValue(); + floatConstant.byteValue(); + intConstant.byteValue(); + longConstant.byteValue(); + shortConstant.byteValue(); + try { + stringConstant.byteValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + + // booleanValue() + try { + byteConstant.booleanValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + try { + charConstant.booleanValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + booleanConstant.booleanValue(); + try { + doubleConstant.booleanValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + try { + floatConstant.booleanValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + try { + intConstant.booleanValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + try { + longConstant.booleanValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + try { + shortConstant.booleanValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + try { + stringConstant.booleanValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + + // charValue() + byteConstant.charValue(); + charConstant.charValue(); + try { + booleanConstant.charValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + doubleConstant.charValue(); + floatConstant.charValue(); + intConstant.charValue(); + longConstant.charValue(); + shortConstant.charValue(); + try { + stringConstant.charValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + + // doubleValue() + byteConstant.doubleValue(); + charConstant.doubleValue(); + try { + booleanConstant.doubleValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + doubleConstant.doubleValue(); + floatConstant.doubleValue(); + intConstant.doubleValue(); + longConstant.doubleValue(); + shortConstant.doubleValue(); + try { + stringConstant.doubleValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + + // floatValue() + byteConstant.floatValue(); + charConstant.floatValue(); + try { + booleanConstant.floatValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + doubleConstant.floatValue(); + floatConstant.floatValue(); + intConstant.floatValue(); + longConstant.floatValue(); + shortConstant.floatValue(); + try { + stringConstant.floatValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + + // intValue() + byteConstant.intValue(); + charConstant.intValue(); + try { + booleanConstant.intValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + doubleConstant.intValue(); + floatConstant.intValue(); + intConstant.intValue(); + longConstant.intValue(); + shortConstant.intValue(); + try { + stringConstant.intValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + + // longValue() + byteConstant.longValue(); + charConstant.longValue(); + try { + booleanConstant.longValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + doubleConstant.longValue(); + floatConstant.longValue(); + intConstant.longValue(); + longConstant.longValue(); + shortConstant.longValue(); + try { + stringConstant.longValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + + // shortValue() + byteConstant.shortValue(); + charConstant.shortValue(); + try { + booleanConstant.shortValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + doubleConstant.shortValue(); + floatConstant.shortValue(); + intConstant.shortValue(); + longConstant.shortValue(); + shortConstant.shortValue(); + try { + stringConstant.shortValue(); + assertTrue(false); + } catch(ShouldNotImplement e) { + // ignore + } + + // stringValue() + byteConstant.stringValue(); + charConstant.stringValue(); + booleanConstant.stringValue(); + doubleConstant.stringValue(); + floatConstant.stringValue(); + intConstant.stringValue(); + longConstant.stringValue(); + shortConstant.stringValue(); + stringConstant.stringValue(); +} +private void verifyConstantEqualsAndHashcode( + Object o, + Object o2, + Object o3, + Object o4) { + assertTrue(o.equals(o)); + assertTrue(o.equals(o3)); + assertFalse(o.equals(o2)); + assertFalse(o.equals(o4)); + assertFalse(o.equals(null)); + assertFalse(o.hashCode() == o2.hashCode()); + assertNotNull(o.toString()); + + if (o instanceof Constant) { + assertTrue("Not the same values", ((Constant) o).hasSameValue((Constant) o3)); + assertFalse("Have same values", ((Constant) o).hasSameValue((Constant) o2)); + 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 void testBug566332_01() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String switchVar = \"abc\";\n" + + " final String caseStr = true ? \"abc\" : \"def\";\n" + + " switch (switchVar) {\n" + + " case caseStr: System.out.println(\"Pass\");\n" + + " }\n" + + " }\n" + + "} ", + }, + "Pass"); +} +public void testBug566332_02() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String switchVar = \"abc\";\n" + + " final String caseStr = false ? \"abc\" : \"def\";\n" + + " switch (switchVar) {\n" + + " case caseStr: System.out.println(\"Pass\");\n" + + " }\n" + + " }\n" + + "} ", + }, + ""); +} +public void testBug566332_03() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean b = true;\n" + + " String switchVar = \"abc\";\n" + + " final String caseStr = b ? \"abc\" : \"def\";\n" + + " switch (switchVar) {\n" + + " case caseStr: System.out.println(\"Pass\");\n" + + " }\n" + + " }\n" + + "} ", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case caseStr: System.out.println(\"Pass\");\n" + + " ^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n"); +} +// Same as testBug566332_01(), but without the variable being final +public void testBug566332_04() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String switchVar = \"abc\";\n" + + " String caseStr = true ? \"abc\" : \"def\";\n" + + " switch (switchVar) {\n" + + " case caseStr: System.out.println(\"Pass\");\n" + + " }\n" + + " }\n" + + "} ", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " String caseStr = true ? \"abc\" : \"def\";\n" + + " ^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " case caseStr: System.out.println(\"Pass\");\n" + + " ^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n"); +} +public void testBug569498() { + if (this.complianceLevel < ClassFileConstants.JDK11) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " final String s1 = \"\";\n" + + " public void m(Object s) {\n" + + " final boolean b = false;\n" + + " final String s2 = \"\";\n" + + " m(b? s1 : s2);\n" + + " }\n" + + " public static void main(String[] args) {}\n" + + "}", + }, + ""); +} +public static Class testClass() { + return ConstantTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DebugAttributeTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DebugAttributeTest.java new file mode 100644 index 0000000000..c969c22377 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DebugAttributeTest.java @@ -0,0 +1,292 @@ +/******************************************************************************* + * Copyright (c) 2006, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; +import java.io.File; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; + +@SuppressWarnings({ "rawtypes" }) +public class DebugAttributeTest extends AbstractRegressionTest { + + public DebugAttributeTest(String name) { + super(name); + } + + public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); + } + + public static Class testClass() { + return DebugAttributeTest.class; + } + +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=124212 + */ +public void test001() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s;\n" + + " if(args.length == 0) {\n" + + " s = \"SUCCESS\";\n" + + " } else {\n" + + " return;\n" + + " }\n" + + " System.out.println(s);\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " Local variable table:\n" + + " [pc: 0, pc: 20] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 11] local: s index: 1 type: java.lang.String\n" + + " [pc: 12, pc: 20] local: s index: 1 type: java.lang.String\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=205046 +public void test002() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"line 1\");\n" + + " myBlock: {\n" + + " System.out.print(\"line 2\");\n" + + " if (false) {\n" + + " break myBlock;\n" + + " }\n" + + " System.out.print(\"line 3\");\n" + + " }\n" + + " System.out.print(\"line 4\");\n" + + " }" + + "}", + }, + "line 1line 2line 3line 4"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 ldc [22]\n" + + " 5 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 8 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 11 ldc [30]\n" + + " 13 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 16 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 19 ldc [32]\n" + + " 21 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 24 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 27 ldc [34]\n" + + " 29 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 32 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 16, line: 9]\n" + + " [pc: 24, line: 11]\n" + + " [pc: 32, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 33] local: args index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258950 +public void test003() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.Iterator;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List l = new ArrayList();\n" + + " List l2 = new ArrayList();\n" + + " l.add(new X());\n" + + " for (Iterator iterator = l.iterator(); iterator.hasNext() ;) {\n" + + " l2.add(((X) iterator.next()).toString()\n" + + " .substring(3));\n" + + " }\n" + + " for (Iterator iterator = l2.iterator(); iterator.hasNext() ;) {\n" + + " System.out.println(iterator.next());\n" + + " }\n" + + " }" + + " public String toString() {\n" + + " return \"NO_SUCCESS\";\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new java.util.ArrayList [16]\n" + + " 3 dup\n" + + " 4 invokespecial java.util.ArrayList() [18]\n" + + " 7 astore_1 [l]\n" + + " 8 new java.util.ArrayList [16]\n" + + " 11 dup\n" + + " 12 invokespecial java.util.ArrayList() [18]\n" + + " 15 astore_2 [l2]\n" + + " 16 aload_1 [l]\n" + + " 17 new X [1]\n" + + " 20 dup\n" + + " 21 invokespecial X() [19]\n" + + " 24 invokeinterface java.util.List.add(java.lang.Object) : boolean [20] [nargs: 2]\n" + + " 29 pop\n" + + " 30 aload_1 [l]\n" + + " 31 invokeinterface java.util.List.iterator() : java.util.Iterator [26] [nargs: 1]\n" + + " 36 astore_3 [iterator]\n" + + " 37 goto 63\n" + + " 40 aload_2 [l2]\n" + + " 41 aload_3 [iterator]\n" + + " 42 invokeinterface java.util.Iterator.next() : java.lang.Object [30] [nargs: 1]\n" + + " 47 checkcast X [1]\n" + + " 50 invokevirtual X.toString() : java.lang.String [36]\n" + + " 53 iconst_3\n" + + " 54 invokevirtual java.lang.String.substring(int) : java.lang.String [40]\n" + + " 57 invokeinterface java.util.List.add(java.lang.Object) : boolean [20] [nargs: 2]\n" + + " 62 pop\n" + + " 63 aload_3 [iterator]\n" + + " 64 invokeinterface java.util.Iterator.hasNext() : boolean [46] [nargs: 1]\n" + + " 69 ifne 40\n" + + " 72 aload_2 [l2]\n" + + " 73 invokeinterface java.util.List.iterator() : java.util.Iterator [26] [nargs: 1]\n" + + " 78 astore_3 [iterator]\n" + + " 79 goto 94\n" + + " 82 getstatic java.lang.System.out : java.io.PrintStream [50]\n" + + " 85 aload_3 [iterator]\n" + + " 86 invokeinterface java.util.Iterator.next() : java.lang.Object [30] [nargs: 1]\n" + + " 91 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [56]\n" + + " 94 aload_3 [iterator]\n" + + " 95 invokeinterface java.util.Iterator.hasNext() : boolean [46] [nargs: 1]\n" + + " 100 ifne 82\n" + + " 103 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 8, line: 7]\n" + + " [pc: 16, line: 8]\n" + + " [pc: 30, line: 9]\n" + + " [pc: 40, line: 10]\n" + + " [pc: 53, line: 11]\n" + + " [pc: 57, line: 10]\n" + + " [pc: 63, line: 9]\n" + + " [pc: 72, line: 13]\n" + + " [pc: 82, line: 14]\n" + + " [pc: 94, line: 13]\n" + + " [pc: 103, line: 16]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262717 +public void test004() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X{\n" + + " public class Inner {\n" + + " public void foo() {\n" + + " int i = 0;\n" + + " final int NEW = 1;\n" + + " if (i == NEW) {\n" + + " System.out.println();\n" + + " }\n" + + " bar();\n" + + " }\n" + + " }\n" + + " public void bar() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new Inner().foo();\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + String expectedOutput = + " 22 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 4, line: 6]\n" + + " [pc: 9, line: 7]\n" + + " [pc: 15, line: 9]\n" + + " [pc: 22, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 23] local: this index: 0 type: X.Inner\n" + + " [pc: 2, pc: 23] local: i index: 1 type: int\n" + + " [pc: 4, pc: 23] local: NEW index: 2 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X$Inner.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultJavaRuntimeEnvironment.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultJavaRuntimeEnvironment.java new file mode 100644 index 0000000000..ac050e9ba2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DefaultJavaRuntimeEnvironment.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Iterator; +import java.util.Map.Entry; + +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.util.JRTUtil; + +public class DefaultJavaRuntimeEnvironment extends FileSystem { + + private DefaultJavaRuntimeEnvironment(String[] jreClasspaths, String release) { + super(jreClasspaths, new String[] {} /* ignore initial file names */, null, release); + } + private DefaultJavaRuntimeEnvironment(Classpath[] jreClasspaths) { + super(jreClasspaths, new String[] {} /* ignore initial file names */, false); + } + + private static INameEnvironment[] defaultJreClassLibs; + + public static INameEnvironment[] create(String[] jreClasspaths) { + return create(jreClasspaths, null); + } + public static INameEnvironment[] create(String[] jreClasspaths, String release) { + if (defaultJreClassLibs == null) { + if (release != null && !release.equals("")) { + defaultJreClassLibs = new INameEnvironment[1]; + Classpath[] classpath = new Classpath[jreClasspaths.length]; + for(int i = 0; i < classpath.length; i++) { + if (jreClasspaths[i].endsWith(JRTUtil.JRT_FS_JAR)) { + File file = new File(jreClasspaths[0]); + classpath[i] = FileSystem.getOlderSystemRelease(file.getParentFile().getParent(), release, null); + + } else { + classpath[i] = FileSystem.getClasspath(jreClasspaths[i], null, null); + } + } + defaultJreClassLibs[0] = new DefaultJavaRuntimeEnvironment(classpath); + } + } + if (defaultJreClassLibs == null) { + defaultJreClassLibs = new INameEnvironment[1]; + defaultJreClassLibs[0] = new DefaultJavaRuntimeEnvironment(jreClasspaths, release); + } + return defaultJreClassLibs; + } + + public void cleanup() { + // reset output folder only, which is the last entry on the classpath list + // see #getDefaultClassPaths() + Classpath outputFolder = this.classpaths[this.classpaths.length - 1]; + // and remove the path from cached module locations: + for (Iterator> iterator = this.moduleLocations.entrySet().iterator(); iterator.hasNext();) { + Entry entry = iterator.next(); + if (entry.getValue().equals(outputFolder)) + iterator.remove(); + } + outputFolder.reset(); + } + + public static void cleanUpDefaultJreClassLibs() { + if (defaultJreClassLibs != null && defaultJreClassLibs.length > 0) { + if (defaultJreClassLibs[0] instanceof DefaultJavaRuntimeEnvironment) + defaultJreClassLibs[0].cleanup(); + } + } + + private static String[] javaLibsAndOutputDir; + + static String[] getDefaultClassPaths() { + if (javaLibsAndOutputDir == null) + javaLibsAndOutputDir = Util.concatWithClassLibs(AbstractRegressionTest.OUTPUT_DIR, false); + return javaLibsAndOutputDir; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated15Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated15Test.java new file mode 100644 index 0000000000..4abad628f3 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated15Test.java @@ -0,0 +1,308 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 354536 - compiling package-info.java still depends on the order of compilation units + * bug 384870 - [compiler] @Deprecated annotation not detected if preceded by other annotation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.HashMap; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Deprecated15Test extends AbstractRegressionTest { +public Deprecated15Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); +} +public void test001() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public class X {\n" + + "}\n", + "Y.java", + "import p.X;\n" + + "public class Y {\n" + + " Zork z;\n" + + " void foo() {\n" + + " X x;\n" + + " X[] xs = { x };\n" + + " }\n" + + " void bar() {\n" + + " p.X x;\n" + + " p.X[] xs = { x };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 1)\n" + + " import p.X;\n" + + " ^^^\n" + + "The type X is deprecated\n" + + "----------\n" + + "2. ERROR in Y.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in Y.java (at line 5)\n" + + " X x;\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "4. WARNING in Y.java (at line 5)\n" + + " X x;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "5. WARNING in Y.java (at line 6)\n" + + " X[] xs = { x };\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "6. WARNING in Y.java (at line 6)\n" + + " X[] xs = { x };\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "7. WARNING in Y.java (at line 9)\n" + + " p.X x;\n" + + " ^^^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "8. WARNING in Y.java (at line 9)\n" + + " p.X x;\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "9. WARNING in Y.java (at line 10)\n" + + " p.X[] xs = { x };\n" + + " ^^^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "10. WARNING in Y.java (at line 10)\n" + + " p.X[] xs = { x };\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n", + null, + true, + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159709 +// guard variant for DeprecatedTest#test015 using an annotation +public void test002() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); + this.runNegativeTest( + true, + new String[] { + "p/M1.java", + "package p;\n" + + "public class M1 {\n" + + " void bar() {\n" + + " a.N1.N2.N3 m = null;\n" + + " m.foo();\n" + + " }\n" + + "}\n", + "a/N1.java", + "package a;\n" + + "public class N1 {\n" + + " @Deprecated\n" + + " public class N2 {" + + " public void foo() {}" + + " public class N3 {" + + " public void foo() {}" + + " }" + + " }" + + "}\n", + }, + null, customOptions, + "----------\n" + + "1. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2 is deprecated\n" + + "----------\n" + + "2. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2.N3 is deprecated\n" + + "----------\n" + + "3. ERROR in p\\M1.java (at line 5)\n" + + " m.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type N1.N2.N3 is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=161214 +// shows that Member2 is properly tagged as deprecated (use the debugger, since +// we do not report deprecation in the unit where the deprecated type is +// declared anyway) +public void test003() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " void foo() {\n" + + " class Local {\n" + + " class Member1 {\n" + + " void bar() {\n" + + " Member2 m2; // Member2 is deprecated\n" + + " }\n" + + " }\n" + + " @Deprecated\n" + + " class Member2 {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191909 +public void test004() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "test1/E01.java", + "package test1;\n" + + "public class E01 {\n" + + " @Deprecated\n" + + " public static int x = 5, y= 10;\n" + + "}", + "test1/E02.java", + "package test1;\n" + + "public class E02 {\n" + + " public void foo() {\n" + + " System.out.println(E01.x);\n" + + " System.out.println(E01.y);\n" + + " }\n" + + "}" + }, + null, customOptions, + "----------\n" + + "1. ERROR in test1\\E02.java (at line 4)\n" + + " System.out.println(E01.x);\n" + + " ^\n" + + "The field E01.x is deprecated\n" + + "----------\n" + + "2. ERROR in test1\\E02.java (at line 5)\n" + + " System.out.println(E01.y);\n" + + " ^\n" + + "The field E01.y is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// Bug 354536 - compiling package-info.java still depends on the order of compilation units +public void test005() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public static class Inner {" + + " public void foo() {}\n" + + " }\n" + + "}\n", + "p1/package-info.java", + "@java.lang.Deprecated\n" + + "package p1;\n", + "p2/C.java", + "package p2;\n" + + "public class C {\n" + + " void bar(p1.X.Inner a) {\n" + + " a.foo();\n" + + " }\n" + + "}\n", + }, + null, customOptions, + "----------\n" + + "1. ERROR in p2\\C.java (at line 3)\n" + + " void bar(p1.X.Inner a) {\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "2. ERROR in p2\\C.java (at line 3)\n" + + " void bar(p1.X.Inner a) {\n" + + " ^^^^^\n" + + "The type X.Inner is deprecated\n" + + "----------\n" + + "3. ERROR in p2\\C.java (at line 4)\n" + + " a.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type X.Inner is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/384870 - [compiler] @Deprecated annotation not detected if preceded by other annotation +public void test006() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "test1/E02.java", + "package test1;\n" + + "public class E02 {\n" + + " public void foo(E01 arg) {\n" + + " // nop\n" + + " }\n" + + "}", + "test1/E01.java", + "package test1;\n" + + "@SuppressWarnings(\"all\") @Deprecated\n" + + "public class E01 {\n" + + " public static int x = 5;\n" + + "}" + }, + null, customOptions, + "----------\n" + + "1. ERROR in test1\\E02.java (at line 3)\n" + + " public void foo(E01 arg) {\n" + + " ^^^\n" + + "The type E01 is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +public static Class testClass() { + return Deprecated15Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated18Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated18Test.java new file mode 100644 index 0000000000..7068824a67 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated18Test.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2014, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Deprecated18Test extends AbstractRegressionTest { +public Deprecated18Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} +public void test412555() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError, + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Runnable r = () -> {\n" + + " Y.callMe();\n" + + " };\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " @Deprecated\n" + + " public static void callMe() {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Y.callMe();\n" + + " ^^^^^^^^\n" + + "The method callMe() from the type Y is deprecated\n" + + "----------\n", + null, + true, + options); +} +public static Class testClass() { + return Deprecated18Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java new file mode 100644 index 0000000000..460219383c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Deprecated9Test.java @@ -0,0 +1,1013 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 GK Software SE, and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class Deprecated9Test extends AbstractRegressionTest9 { + public Deprecated9Test(String name) { + super(name); + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); + } + + static { +// TESTS_NAMES = new String[] { "test007" }; + } + + @Override + protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { + if (this.javaClassLib != null) { + String encoding = getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + if ("".equals(encoding)) + encoding = null; + return new INameEnvironment[] { + this.javaClassLib, + new FileSystem(this.classpaths, new String[]{}, // ignore initial file names + encoding // default encoding + )}; + } + return super.getClassLibs(useDefaultClasspaths); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159709 + // guard variant for DeprecatedTest#test015 using an annotation + public void test002() { + Map customOptions = new HashMap<>(); + customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING); + customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); + this.runNegativeTest( + true, + new String[] { + "p/M1.java", + "package p;\n" + + "public class M1 {\n" + + " void bar() {\n" + + " a.N1.N2.N3 m = null;\n" + + " m.foo();\n" + + " }\n" + + "}\n", + "a/N1.java", + "package a;\n" + + "public class N1 {\n" + + " @Deprecated(since=\"1.2\",forRemoval=true)\n" + + " public class N2 {" + + " public void foo() {}" + + " public class N3 {" + + " public void foo() {}" + + " }" + + " }" + + "}\n", + }, + null, customOptions, + "----------\n" + + "1. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2 has been deprecated since version 1.2 and marked for removal\n" + + "----------\n" + + "2. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2.N3 has been deprecated and marked for removal\n" + + "----------\n" + + "3. ERROR in p\\M1.java (at line 5)\n" + + " m.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type N1.N2.N3 has been deprecated and marked for removal\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void test002binary() { + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING); + runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "a/N1.java", + "package a;\n" + + "public class N1 {\n" + + " @Deprecated(since=\"1.2\",forRemoval=true)\n" + + " public class N2 {" + + " public void foo() {}" + + " public class N3 {" + + " public void foo() {}" + + " }" + + " }" + + "}\n" + }; + runner.runConformTest(); + + runner.shouldFlushOutputDirectory = false; + runner.testFiles = + new String[] { + "p/M1.java", + "package p;\n" + + "public class M1 {\n" + + " void bar() {\n" + + " a.N1.N2.N3 m = null;\n" + + " m.foo();\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2 has been deprecated since version 1.2 and marked for removal\n" + + "----------\n" + + "2. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2.N3 has been deprecated and marked for removal\n" + + "----------\n" + + "3. ERROR in p\\M1.java (at line 5)\n" + + " m.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type N1.N2.N3 has been deprecated and marked for removal\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=191909 + public void test004() { + Map customOptions = new HashMap<>(); + customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING); + customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "test1/E01.java", + "package test1;\n" + + "public class E01 {\n" + + " @Deprecated(forRemoval=true,since=\"3\")\n" + + " public static int x = 5, y= 10;\n" + + "}", + "test1/E02.java", + "package test1;\n" + + "public class E02 {\n" + + " public void foo() {\n" + + " System.out.println(E01.x);\n" + + " System.out.println(E01.y);\n" + + " }\n" + + "}" + }, + null, customOptions, + "----------\n" + + "1. ERROR in test1\\E02.java (at line 4)\n" + + " System.out.println(E01.x);\n" + + " ^\n" + + "The field E01.x has been deprecated since version 3 and marked for removal\n" + + "----------\n" + + "2. ERROR in test1\\E02.java (at line 5)\n" + + " System.out.println(E01.y);\n" + + " ^\n" + + "The field E01.y has been deprecated since version 3 and marked for removal\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + // Bug 354536 - compiling package-info.java still depends on the order of compilation units + public void test005a() { + Map customOptions = new HashMap<>(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportTerminalDeprecation, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public static class Inner {" + + " public void foo() {}\n" + + " }\n" + + "}\n", + "p1/package-info.java", + "@java.lang.Deprecated(forRemoval=true)\n" + + "package p1;\n", + "p2/C.java", + "package p2;\n" + + "public class C {\n" + + " void bar(p1.X.Inner a) {\n" + + " a.foo();\n" + + " }\n" + + "}\n", + }, + null, customOptions, + "----------\n" + + "1. ERROR in p2\\C.java (at line 3)\n" + + " void bar(p1.X.Inner a) {\n" + + " ^\n" + + "The type X has been deprecated and marked for removal\n" + + "----------\n" + + "2. ERROR in p2\\C.java (at line 3)\n" + + " void bar(p1.X.Inner a) {\n" + + " ^^^^^\n" + + "The type X.Inner has been deprecated and marked for removal\n" + + "----------\n" + + "3. ERROR in p2\\C.java (at line 4)\n" + + " a.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type X.Inner has been deprecated and marked for removal\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void test005b() { + Map customOptions = new HashMap<>(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportTerminalDeprecation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public static class Inner {" + + " public void foo() {}\n" + + " }\n" + + "}\n", + "p1/package-info.java", + "@java.lang.Deprecated(forRemoval=true)\n" + + "package p1;\n", + "p2/C.java", + "package p2;\n" + + "public class C {\n" + + " void bar(p1.X.Inner a) {\n" + + " a.foo();\n" + + " }\n" + + "}\n", + }, + customOptions); + } + public void test005c() { + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + runner.customOptions.put(CompilerOptions.OPTION_ReportTerminalDeprecation, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public static class Inner {\n" + + " @java.lang.Deprecated(forRemoval=true)\n" + + " public void foo() {}\n" + + " }\n" + + "}\n", + "p1/package-info.java", + "@java.lang.Deprecated(forRemoval=false)\n" + + "package p1;\n", + "p2/C.java", + "package p2;\n" + + "public class C {\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " void bar(p1.X.Inner a) {\n" + + " a.foo();\n" + + " }\n" + + "}\n", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in p2\\C.java (at line 5)\n" + + " a.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type X.Inner has been deprecated and marked for removal\n" + + "----------\n"; + runner.runWarningTest(); + } + public void test006() { + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + runner.customOptions.put(CompilerOptions.OPTION_ReportTerminalDeprecation, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "test1/E02.java", + "package test1;\n" + + "public class E02 {\n" + + " public void foo(E01 arg) {\n" + + " // nop\n" + + " }\n" + + "}", + "test1/E01.java", + "package test1;\n" + + "@SuppressWarnings(\"all\") @Deprecated(since=\"4\")\n" + + "public class E01 {\n" + + " public static int x = 5;\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in test1\\E02.java (at line 3)\n" + + " public void foo(E01 arg) {\n" + + " ^^^\n" + + "The type E01 is deprecated since version 4\n" + + "----------\n"; + runner.runWarningTest(); + } + // method overriding + public void test007() { + Map customOptions = new HashMap<>(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportTerminalDeprecation, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.ENABLED); + this.runNegativeTest( + true, + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " @java.lang.Deprecated(forRemoval=false)\n" + + " public void foo() {}\n" + + " @java.lang.Deprecated(forRemoval=true)\n" + + " public void bar() {}\n" + + "}\n", + "p2/C.java", + "package p2;\n" + + "import p1.X;\n" + + "public class C extends X {\n" + + " @Override public void foo() {}\n" + + " @Override public void bar() {}\n" + + "}\n", + }, + null, customOptions, + "----------\n" + + "1. WARNING in p2\\C.java (at line 4)\n" + + " @Override public void foo() {}\n" + + " ^^^^^\n" + + "The method C.foo() overrides a deprecated method from X\n" + + "----------\n" + + "2. ERROR in p2\\C.java (at line 5)\n" + + " @Override public void bar() {}\n" + + " ^^^^^\n" + + "The method C.bar() overrides a method from X that has been deprecated and marked for removal\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testSinceSource() { + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION_WHEN_OVERRIDING_DEPRECATED_METHOD, CompilerOptions.ENABLED); + runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "test1/E01.java", + "package test1;\n" + + "public class E01 {\n" + + " @Deprecated(since=\"1.0\") protected static class Old {}\n" + + " @Deprecated(since=\"2\") public static int x = 5, y= 10;\n" + + " @Deprecated(since=\"3.0.0\") public E01() {}\n" + + " @Deprecated(since=\"4-SNAPSHOT\") protected void old() {}\n" + + "}", + "test1/E02.java", + "package test1;\n" + + "public class E02 {\n" + + " public void foo() {\n" + + " System.out.println(new E01.Old());\n" + + " E01 e = new E01();\n" + + " e.old();\n" + + " System.out.println(E01.x);\n" + + " System.out.println(E01.y);\n" + + " }\n" + + " class E03 extends E01 {\n" + + " protected void old() {}\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in test1\\E02.java (at line 4)\n" + + " System.out.println(new E01.Old());\n" + + " ^^^^^^^^^\n" + + "The constructor E01.Old() is deprecated since version 1.0\n" + + "----------\n" + + "2. WARNING in test1\\E02.java (at line 4)\n" + + " System.out.println(new E01.Old());\n" + + " ^^^\n" + + "The type E01.Old is deprecated since version 1.0\n" + + "----------\n" + + "3. WARNING in test1\\E02.java (at line 5)\n" + + " E01 e = new E01();\n" + + " ^^^^^\n" + + "The constructor E01() is deprecated since version 3.0.0\n" + + "----------\n" + + "4. WARNING in test1\\E02.java (at line 6)\n" + + " e.old();\n" + + " ^^^^^\n" + + "The method old() from the type E01 is deprecated since version 4-SNAPSHOT\n" + + "----------\n" + + "5. WARNING in test1\\E02.java (at line 7)\n" + + " System.out.println(E01.x);\n" + + " ^\n" + + "The field E01.x is deprecated since version 2\n" + + "----------\n" + + "6. WARNING in test1\\E02.java (at line 8)\n" + + " System.out.println(E01.y);\n" + + " ^\n" + + "The field E01.y is deprecated since version 2\n" + + "----------\n" + + "7. WARNING in test1\\E02.java (at line 10)\n" + + " class E03 extends E01 {\n" + + " ^^^\n" + + "The constructor E01() is deprecated since version 3.0.0\n" + + "----------\n" + + "8. WARNING in test1\\E02.java (at line 11)\n" + + " protected void old() {}\n" + + " ^^^^^\n" + + "The method E02.E03.old() overrides a method from E01 that is deprecated since version 4-SNAPSHOT\n" + + "----------\n"; + runner.runWarningTest(); + } + public void testSinceBinary() { + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION_WHEN_OVERRIDING_DEPRECATED_METHOD, CompilerOptions.ENABLED); + runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "test1/E01.java", + "package test1;\n" + + "public class E01 {\n" + + " @Deprecated(since=\"1.0\") protected static class Old {}\n" + + " @Deprecated(since=\"2\") public static int x = 5, y= 10;\n" + + " @Deprecated(since=\"3.0.0\") public E01() {}\n" + + " @Deprecated(since=\"4-SNAPSHOT\") protected void old() {}\n" + + "}" + }; + runner.runConformTest(); + + runner.shouldFlushOutputDirectory = false; + runner.testFiles = + new String[] { + "test1/E02.java", + "package test1;\n" + + "public class E02 {\n" + + " public void foo() {\n" + + " System.out.println(new E01.Old());\n" + + " E01 e = new E01();\n" + + " e.old();\n" + + " System.out.println(E01.x);\n" + + " System.out.println(E01.y);\n" + + " }\n" + + " class E03 extends E01 {\n" + + " protected void old() {}\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in test1\\E02.java (at line 4)\n" + + " System.out.println(new E01.Old());\n" + + " ^^^^^^^^^\n" + + "The constructor E01.Old() is deprecated since version 1.0\n" + + "----------\n" + + "2. WARNING in test1\\E02.java (at line 4)\n" + + " System.out.println(new E01.Old());\n" + + " ^^^\n" + + "The type E01.Old is deprecated since version 1.0\n" + + "----------\n" + + "3. WARNING in test1\\E02.java (at line 5)\n" + + " E01 e = new E01();\n" + + " ^^^^^\n" + + "The constructor E01() is deprecated since version 3.0.0\n" + + "----------\n" + + "4. WARNING in test1\\E02.java (at line 6)\n" + + " e.old();\n" + + " ^^^^^\n" + + "The method old() from the type E01 is deprecated since version 4-SNAPSHOT\n" + + "----------\n" + + "5. WARNING in test1\\E02.java (at line 7)\n" + + " System.out.println(E01.x);\n" + + " ^\n" + + "The field E01.x is deprecated since version 2\n" + + "----------\n" + + "6. WARNING in test1\\E02.java (at line 8)\n" + + " System.out.println(E01.y);\n" + + " ^\n" + + "The field E01.y is deprecated since version 2\n" + + "----------\n" + + "7. WARNING in test1\\E02.java (at line 10)\n" + + " class E03 extends E01 {\n" + + " ^^^\n" + + "The constructor E01() is deprecated since version 3.0.0\n" + + "----------\n" + + "8. WARNING in test1\\E02.java (at line 11)\n" + + " protected void old() {}\n" + + " ^^^^^\n" + + "The method E02.E03.old() overrides a method from E01 that is deprecated since version 4-SNAPSHOT\n" + + "----------\n"; + runner.runWarningTest(); + } + public void testSinceTerminally() { + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION_WHEN_OVERRIDING_DEPRECATED_METHOD, CompilerOptions.ENABLED); + runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "test1/E01.java", + "package test1;\n" + + "public class E01 {\n" + + " @Deprecated(since=\"1.0\", forRemoval=true) protected static class Old {}\n" + + " @Deprecated(since=\"2\", forRemoval=true) public static int x = 5, y= 10;\n" + + " @Deprecated(since=\"3.0.0\", forRemoval=true) public E01() {}\n" + + " @Deprecated(since=\"4-SNAPSHOT\", forRemoval=true) protected void old() {}\n" + + "}", + "test1/E02.java", + "package test1;\n" + + "public class E02 {\n" + + " public void foo() {\n" + + " System.out.println(new E01.Old());\n" + + " E01 e = new E01();\n" + + " e.old();\n" + + " System.out.println(E01.x);\n" + + " System.out.println(E01.y);\n" + + " }\n" + + " class E03 extends E01 {\n" + + " protected void old() {}\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in test1\\E02.java (at line 4)\n" + + " System.out.println(new E01.Old());\n" + + " ^^^^^^^^^\n" + + "The constructor E01.Old() has been deprecated since version 1.0 and marked for removal\n" + + "----------\n" + + "2. ERROR in test1\\E02.java (at line 4)\n" + + " System.out.println(new E01.Old());\n" + + " ^^^\n" + + "The type E01.Old has been deprecated since version 1.0 and marked for removal\n" + + "----------\n" + + "3. ERROR in test1\\E02.java (at line 5)\n" + + " E01 e = new E01();\n" + + " ^^^^^\n" + + "The constructor E01() has been deprecated since version 3.0.0 and marked for removal\n" + + "----------\n" + + "4. ERROR in test1\\E02.java (at line 6)\n" + + " e.old();\n" + + " ^^^^^\n" + + "The method old() from the type E01 has been deprecated since version 4-SNAPSHOT and marked for removal\n" + + "----------\n" + + "5. ERROR in test1\\E02.java (at line 7)\n" + + " System.out.println(E01.x);\n" + + " ^\n" + + "The field E01.x has been deprecated since version 2 and marked for removal\n" + + "----------\n" + + "6. ERROR in test1\\E02.java (at line 8)\n" + + " System.out.println(E01.y);\n" + + " ^\n" + + "The field E01.y has been deprecated since version 2 and marked for removal\n" + + "----------\n" + + "7. ERROR in test1\\E02.java (at line 10)\n" + + " class E03 extends E01 {\n" + + " ^^^\n" + + "The constructor E01() has been deprecated since version 3.0.0 and marked for removal\n" + + "----------\n" + + "8. ERROR in test1\\E02.java (at line 11)\n" + + " protected void old() {}\n" + + " ^^^^^\n" + + "The method E02.E03.old() overrides a method from E01 that has been deprecated since version 4-SNAPSHOT and marked for removal\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); + } + public void testDeprecatedPackageExport() { + associateToModule("mod1", + "p1/package-info.java", "p1/C1.java", + "p2/package-info.java", "p2/C2.java", + "p3/package-info.java", "p3/C3.java", + "p4/package-info.java", "p4/C4.java"); + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.ERROR); + runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "p1/package-info.java", + "@Deprecated package p1;\n", + "p1/C1.java", + "package p1; public class C1 {}\n", + "p2/package-info.java", + "@Deprecated(since=\"13\") package p2;\n", + "p2/C2.java", + "package p2; public class C2 {}\n", + "p3/package-info.java", + "@Deprecated(since=\"13\",forRemoval=true) package p3;\n", + "p3/C3.java", + "package p3; public class C3 {}\n", + "p4/package-info.java", + "@Deprecated(since=\"14\",forRemoval=true) package p4;\n", + "p4/C4.java", + "package p4; public class C4 {}\n", + "module-info.java", + "module mod1 {\n" + + " exports p1;\n" + + " exports p2;\n" + + " exports p3;\n" + + " opens p4;\n" + + "}\n" + }; + runner.runConformTest(); + } + public void testDeprecatedModule() { + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.WARNING); + runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "folder0/module-info.java", + "@Deprecated module mod.dep {}\n", + "folder1/module-info.java", + "@Deprecated(since=\"42\") module mod.dep.since {}\n", + "folder2/module-info.java", + "@Deprecated(forRemoval=true) module mod.dep.terminally {}\n", + "folder3/module-info.java", + "@Deprecated(since=\"42\",forRemoval=true) module mod.dep.since.terminally {}\n", + "module-info.java", + "module mod1 {\n" + + " requires mod.dep;\n" + + " requires mod.dep.since;\n" + + " requires mod.dep.terminally;\n" + + " requires mod.dep.since.terminally;\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in module-info.java (at line 2)\n" + + " requires mod.dep;\n" + + " ^^^^^^^\n" + + "The module mod.dep is deprecated\n" + + "----------\n" + + "2. WARNING in module-info.java (at line 3)\n" + + " requires mod.dep.since;\n" + + " ^^^^^^^^^^^^^\n" + + "The module mod.dep.since is deprecated since version 42\n" + + "----------\n" + + "3. ERROR in module-info.java (at line 4)\n" + + " requires mod.dep.terminally;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The module mod.dep.terminally has been deprecated and marked for removal\n" + + "----------\n" + + "4. ERROR in module-info.java (at line 5)\n" + + " requires mod.dep.since.terminally;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The module mod.dep.since.terminally has been deprecated since version 42 and marked for removal\n" + + "----------\n"; + runner.runNegativeTest(); + } + public void testDeprecatedProvidedServices() { + javacUsePathOption(" --module-source-path "); + associateToModule("mod0", "module-info.java", "p1/IServiceDep.java", "p1/IServiceDepSince.java", "p1/IServiceTermDep.java", "p1/IServiceTermDepSince.java"); + associateToModule("mod1", "p1impl/ServiceDep.java", "p1impl/ServiceDepSince.java", "p1impl/ServiceTermDep.java", "p1impl/ServiceTermDepSince.java"); + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.INFO); + runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "p1/IServiceDep.java", + "package p1;\n" + + "@Deprecated\n" + + "public interface IServiceDep {}\n", + "p1/IServiceDepSince.java", + "package p1;\n" + + "@Deprecated(since=\"2\")\n" + + "public interface IServiceDepSince {}\n", + "p1/IServiceTermDep.java", + "package p1;\n" + + "@Deprecated(forRemoval=true)\n" + + "public interface IServiceTermDep {}\n", + "p1/IServiceTermDepSince.java", + "package p1;\n" + + "@Deprecated(since=\"3\",forRemoval=true)\n" + + "public interface IServiceTermDepSince {}\n", + "module-info.java", + "module mod0 {\n" + + " exports p1;\n" + + "}\n", + "p1impl/ServiceDep.java", + "package p1impl;\n" + + "@Deprecated\n" + + "public class ServiceDep implements p1.IServiceDep {}\n", + "p1impl/ServiceDepSince.java", + "package p1impl;\n" + + "@Deprecated(since=\"2\")\n" + + "public class ServiceDepSince implements p1.IServiceDepSince {}\n", + "p1impl/ServiceTermDep.java", + "package p1impl;\n" + + "@Deprecated(forRemoval=true)\n" + + "public class ServiceTermDep implements p1.IServiceTermDep {}\n", + "p1impl/ServiceTermDepSince.java", + "package p1impl;\n" + + "@Deprecated(since=\"3\",forRemoval=true)\n" + + "public class ServiceTermDepSince implements p1.IServiceTermDepSince {}\n", + "mod1/module-info.java", + "module mod1 {\n" + + " requires mod0;\n" + + " provides p1.IServiceDep with p1impl.ServiceDep;\n" + + " provides p1.IServiceDepSince with p1impl.ServiceDepSince;\n" + + " provides p1.IServiceTermDep with p1impl.ServiceTermDep;\n" + + " provides p1.IServiceTermDepSince with p1impl.ServiceTermDepSince;\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. INFO in mod1\\module-info.java (at line 3)\n" + + " provides p1.IServiceDep with p1impl.ServiceDep;\n" + + " ^^^^^^^^^^^\n" + + "The type IServiceDep is deprecated\n" + + "----------\n" + + "2. INFO in mod1\\module-info.java (at line 3)\n" + + " provides p1.IServiceDep with p1impl.ServiceDep;\n" + + " ^^^^^^^^^^\n" + + "The type ServiceDep is deprecated\n" + + "----------\n" + + "3. INFO in mod1\\module-info.java (at line 4)\n" + + " provides p1.IServiceDepSince with p1impl.ServiceDepSince;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type IServiceDepSince is deprecated since version 2\n" + + "----------\n" + + "4. INFO in mod1\\module-info.java (at line 4)\n" + + " provides p1.IServiceDepSince with p1impl.ServiceDepSince;\n" + + " ^^^^^^^^^^^^^^^\n" + + "The type ServiceDepSince is deprecated since version 2\n" + + "----------\n" + + "5. WARNING in mod1\\module-info.java (at line 5)\n" + + " provides p1.IServiceTermDep with p1impl.ServiceTermDep;\n" + + " ^^^^^^^^^^^^^^^\n" + + "The type IServiceTermDep has been deprecated and marked for removal\n" + + "----------\n" + + "6. WARNING in mod1\\module-info.java (at line 5)\n" + + " provides p1.IServiceTermDep with p1impl.ServiceTermDep;\n" + + " ^^^^^^^^^^^^^^\n" + + "The type ServiceTermDep has been deprecated and marked for removal\n" + + "----------\n" + + "7. WARNING in mod1\\module-info.java (at line 6)\n" + + " provides p1.IServiceTermDepSince with p1impl.ServiceTermDepSince;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The type IServiceTermDepSince has been deprecated since version 3 and marked for removal\n" + + "----------\n" + + "8. WARNING in mod1\\module-info.java (at line 6)\n" + + " provides p1.IServiceTermDepSince with p1impl.ServiceTermDepSince;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type ServiceTermDepSince has been deprecated since version 3 and marked for removal\n" + + "----------\n"; + runner.runWarningTest(); + } + public void testDeprecatedUsedServices() { + javacUsePathOption(" --module-path "); + + associateToModule("mod0", "p1/IServiceDep.java", "p1/IServiceDepSince.java", "p1/IServiceTermDep.java", "p1/IServiceTermDepSince.java"); + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.INFO); + runner.customOptions.put(JavaCore.COMPILER_PB_TERMINAL_DEPRECATION, CompilerOptions.WARNING); + runner.testFiles = + new String[] { + "p1/IServiceDep.java", + "package p1;\n" + + "@Deprecated\n" + + "public interface IServiceDep {}\n", + "p1/IServiceDepSince.java", + "package p1;\n" + + "@Deprecated(since=\"2\")\n" + + "public interface IServiceDepSince {}\n", + "p1/IServiceTermDep.java", + "package p1;\n" + + "@Deprecated(forRemoval=true)\n" + + "public interface IServiceTermDep {}\n", + "p1/IServiceTermDepSince.java", + "package p1;\n" + + "@Deprecated(since=\"3\",forRemoval=true)\n" + + "public interface IServiceTermDepSince {}\n", + "module-info.java", + "module mod0 {\n" + + " exports p1;\n" + + "}\n", + }; + runner.runConformTest(); + + runner.shouldFlushOutputDirectory = false; + runner.testFiles = + new String[] { + "module-info.java", + "module mod2 {\n" + + " requires mod0;\n" + + " uses p1.IServiceDep;\n" + + " uses p1.IServiceDepSince;\n" + + " uses p1.IServiceTermDep;\n" + + " uses p1.IServiceTermDepSince;\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. INFO in module-info.java (at line 3)\n" + + " uses p1.IServiceDep;\n" + + " ^^^^^^^^^^^\n" + + "The type IServiceDep is deprecated\n" + + "----------\n" + + "2. INFO in module-info.java (at line 4)\n" + + " uses p1.IServiceDepSince;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type IServiceDepSince is deprecated since version 2\n" + + "----------\n" + + "3. WARNING in module-info.java (at line 5)\n" + + " uses p1.IServiceTermDep;\n" + + " ^^^^^^^^^^^^^^^\n" + + "The type IServiceTermDep has been deprecated and marked for removal\n" + + "----------\n" + + "4. WARNING in module-info.java (at line 6)\n" + + " uses p1.IServiceTermDepSince;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The type IServiceTermDepSince has been deprecated since version 3 and marked for removal\n" + + "----------\n"; + runner.runWarningTest(); + } + public void testBug533063_1() throws Exception { + INameEnvironment save = this.javaClassLib; + try { + List limitModules = Arrays.asList("java.se", "jdk.xml.bind"); + this.javaClassLib = new CustomFileSystem(limitModules); + Runner runner = new Runner(); + runner.testFiles = new String[] { + "module-info.java", + "module my.mod {\n" + + " requires jdk.xml.bind;\n" + + "}\n" + }; + if (isJRE11Plus) { + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in module-info.java (at line 2)\n" + + " requires jdk.xml.bind;\n" + + " ^^^^^^^^^^^^\n" + + "jdk.xml.bind cannot be resolved to a module\n" + + "----------\n"; + runner.runNegativeTest(); + } else { + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in module-info.java (at line 2)\n" + + " requires jdk.xml.bind;\n" + + " ^^^^^^^^^^^^\n" + + "The module jdk.xml.bind has been deprecated since version 9 and marked for removal\n" + + "----------\n"; + runner.runWarningTest(); + } + } finally { + this.javaClassLib = save; + } + } + public void testBug533063_2() throws Exception { + javacUsePathOption(" --module-path "); + + runConformTest(new String[] { + "dont.use/module-info.java", + "@Deprecated(forRemoval=true,since=\"9\") module dont.use {}\n" + }); + this.moduleMap.clear(); // don't use the source module beyond this point + Runner runner = new Runner(); + runner.shouldFlushOutputDirectory = false; + runner.testFiles = new String[] { + "my.mod/module-info.java", + "module my.mod {\n" + + " requires dont.use;\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in my.mod\\module-info.java (at line 2)\n" + + " requires dont.use;\n" + + " ^^^^^^^^\n" + + "The module dont.use has been deprecated since version 9 and marked for removal\n" + + "----------\n"; + runner.runWarningTest(); + } + public void testBug534304() throws Exception { + runNegativeTest( + new String[] { + "p1/C1.java", + "package p1;\n" + + "\n" + + "import pdep.Dep1;\n" + + "\n" + + "public class C1 {\n" + + " Dep1 f;\n" + + "}\n", + "pdep/Dep1.java", + "package pdep;\n" + + "\n" + + "import pmissing.CMissing;\n" + + "\n" + + "@Deprecated(since=\"13\")\n" + + "@CMissing\n" + + "public class Dep1 {\n" + + "\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p1\\C1.java (at line 3)\n" + + " import pdep.Dep1;\n" + + " ^^^^^^^^^\n" + + "The type Dep1 is deprecated since version 13\n" + + "----------\n" + + "2. WARNING in p1\\C1.java (at line 6)\n" + + " Dep1 f;\n" + + " ^^^^\n" + + "The type Dep1 is deprecated since version 13\n" + + "----------\n" + + "----------\n" + + "1. ERROR in pdep\\Dep1.java (at line 3)\n" + + " import pmissing.CMissing;\n" + + " ^^^^^^^^\n" + + "The import pmissing cannot be resolved\n" + + "----------\n" + + "2. ERROR in pdep\\Dep1.java (at line 6)\n" + + " @CMissing\n" + + " ^^^^^^^^\n" + + "CMissing cannot be resolved to a type\n" + + "----------\n"); + } + public void testBug542795() throws Exception { + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, CompilerOptions.ERROR); + runner.testFiles = new String[] { + "test/ReaderWarningView.java", + "package test;\n" + + "@java.lang.Deprecated\n" + + "public class ReaderWarningView {}\n", + "Test.java", + "public class Test implements test.Screen.Component {}\n", + "test/Screen.java", + "package test;\n" + + "@interface Annot{ Class value(); }\n" + + "@Annot(test.Screen.Component.class)\n" + + "@java.lang.Deprecated\n" + + "public final class Screen {\n" + + " @java.lang.Deprecated\n" + + " public interface Component extends test.ReaderWarningView.Component {\n" + + " }\n" + + "}\n", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in Test.java (at line 1)\n" + + " public class Test implements test.Screen.Component {}\n" + + " ^^^^\n" + + "The hierarchy of the type Test is inconsistent\n" + + "----------\n" + + "2. ERROR in Test.java (at line 1)\n" + + " public class Test implements test.Screen.Component {}\n" + + " ^^^^^^\n" + + "The type Screen is deprecated\n" + + "----------\n" + + "3. ERROR in Test.java (at line 1)\n" + + " public class Test implements test.Screen.Component {}\n" + + " ^^^^^^^^^\n" + + "The type Screen.Component is deprecated\n" + + "----------\n" + + "----------\n" + + "1. ERROR in test\\Screen.java (at line 7)\n" + + " public interface Component extends test.ReaderWarningView.Component {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "test.ReaderWarningView.Component cannot be resolved to a type\n" + + "----------\n"; + runner.runNegativeTest(); + } + public static Class testClass() { + return Deprecated9Test.class; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DeprecatedTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DeprecatedTest.java new file mode 100644 index 0000000000..dc9e3bbd24 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/DeprecatedTest.java @@ -0,0 +1,972 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class DeprecatedTest extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test008a" }; +} + +protected char[][] invisibleType; + +public DeprecatedTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +@Override +protected void tearDown() throws Exception { + this.invisibleType = null; + super.tearDown(); +} + +@Override +protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths, Map options) { + // constructs a name environment that is able to hide a type of name 'this.invisibleType': + this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths; + return new InMemoryNameEnvironment(testFiles, getClassLibs(classPaths == null, options)) { + @Override + public NameEnvironmentAnswer findType(char[][] compoundTypeName) { + if (DeprecatedTest.this.invisibleType != null && CharOperation.equals(DeprecatedTest.this.invisibleType, compoundTypeName)) + return null; + return super.findType(compoundTypeName); + } + @Override + public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) { + if (DeprecatedTest.this.invisibleType != null && DeprecatedTest.this.invisibleType.length == packageName.length+1) { + char[][] packName = CharOperation.subarray(DeprecatedTest.this.invisibleType, 0, DeprecatedTest.this.invisibleType.length-1); + if (CharOperation.equals(packageName, packName)) { + char[] simpleName = DeprecatedTest.this.invisibleType[DeprecatedTest.this.invisibleType.length-1]; + if (CharOperation.equals(simpleName, typeName)) + return null; + } + } + return super.findType(typeName, packageName); + } + }; +} + +public void test001() { + this.runNegativeTest(new String[] { + "p/B.java", + "package p;\n" + + "class B extends A {\n" + + " float x = super.x;\n" + + "}\n", + + "p/A.java", + "package p;\n" + + "class A {\n" + + " /** @deprecated */\n" + + " int x = 1;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in p\\B.java (at line 3)\n" + + " float x = super.x;\n" + + " ^\n" + + "The field B.x is hiding a field from type A\n" + + "----------\n" + + "2. WARNING in p\\B.java (at line 3)\n" + + " float x = super.x;\n" + + " ^\n" + + "The field A.x is deprecated\n" + + "----------\n" + ); +} +public void test002() { + this.runNegativeTest(new String[] { + "p/C.java", + "package p;\n" + + "class C {\n" + + " static int x = new A().x;\n" + + "}\n", + + "p/A.java", + "package p;\n" + + "class A {\n" + + " /** @deprecated */\n" + + " int x = 1;\n" + + "}\n", + + }, + "----------\n" + + "1. WARNING in p\\C.java (at line 3)\n" + + " static int x = new A().x;\n" + + " ^\n" + + "The field A.x is deprecated\n" + + "----------\n" + ); +} +public void test003() { + this.runNegativeTest(new String[] { + "p/Top.java", + "package p;\n" + + "public class Top {\n" + + " \n" + + " class M1 {\n" + + " class M2 {}\n" + + " };\n" + + " \n" + + " static class StaticM1 {\n" + + " static class StaticM2 {\n" + + " class NonStaticM3{}};\n" + + " };\n" + + " \n" + + "public static void main(String argv[]){\n" + + " Top tip = new Top();\n" + + " System.out.println(\"Still alive 0\");\n" + + " tip.testStaticMember();\n" + + " System.out.println(\"Still alive 1\");\n" + + " tip.testStaticMember1();\n" + + " System.out.println(\"Still alive 2\");\n" + + " tip.testStaticMember2();\n" + + " System.out.println(\"Still alive 3\");\n" + + " tip.testStaticMember3();\n" + + " System.out.println(\"Still alive 4\");\n" + + " tip.testStaticMember4();\n" + + " System.out.println(\"Completed\");\n" + + "}\n" + + " void testMember(){\n" + + " new M1().new M2();}\n" + + " void testStaticMember(){\n" + + " new StaticM1().new StaticM2();}\n" + + " void testStaticMember1(){\n" + + " new StaticM1.StaticM2();}\n" + + " void testStaticMember2(){\n" + + " new StaticM1.StaticM2().new NonStaticM3();}\n" + + " void testStaticMember3(){\n" + + " // define an anonymous subclass of the non-static M3\n" + + " new StaticM1.StaticM2().new NonStaticM3(){};\n" + + " } \n" + + " void testStaticMember4(){\n" + + " // define an anonymous subclass of the non-static M3\n" + + " new StaticM1.StaticM2().new NonStaticM3(){\n" + + " Object hello(){\n" + + " return new StaticM1.StaticM2().new NonStaticM3();\n" + + " }};\n" + + " \n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\Top.java (at line 30)\n" + + " new StaticM1().new StaticM2();}\n" + + " ^^^^^^^^^^^^^^\n" + + "Illegal enclosing instance specification for type Top.StaticM1.StaticM2\n" + + "----------\n" + + "2. WARNING in p\\Top.java (at line 42)\n" + + " Object hello(){\n" + + " ^^^^^^^\n" + + "The method hello() from the type new Top.StaticM1.StaticM2.NonStaticM3(){} is never used locally\n" + + "----------\n"); +} +/** + * Regression test for PR #1G9ES9B + */ +public void test004() { + this.runNegativeTest(new String[] { + "p/Warning.java", + "package p;\n" + + "import java.util.Date;\n" + + "public class Warning {\n" + + "public Warning() {\n" + + " super();\n" + + " Date dateObj = new Date();\n" + + " dateObj.UTC(1,2,3,4,5,6);\n" + + "}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in p\\Warning.java (at line 7)\n" + + " dateObj.UTC(1,2,3,4,5,6);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The static method UTC(int, int, int, int, int, int) from the type Date should be accessed in a static way\n" + + "----------\n" + + "2. WARNING in p\\Warning.java (at line 7)\n" + + " dateObj.UTC(1,2,3,4,5,6);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method UTC(int, int, int, int, int, int) from the type Date is deprecated\n" + + "----------\n"); +} +public void test005() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "/**\n" + + " * @deprecated\n" + + " */\n" + + " public static class Y {\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " System.out.print(\"SUCCESS\"); \n" + + " } \n" + + "}" + }, + "SUCCESS", // expected output + null, + true, // flush previous output dir content + null, // special vm args + null, // custom options + null); // custom requestor + this.runNegativeTest( + new String[] { + "A.java", + "public class A extends X.Y {}" + }, + "----------\n" + + "1. WARNING in A.java (at line 1)\n" + + " public class A extends X.Y {}\n" + + " ^\n" + + "The type X.Y is deprecated\n" + + "----------\n",// expected output + null, + false, // flush previous output dir content + null); // custom options +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=40839 +public void test006() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " @deprecated\n" + + " */\n" + + " ; // line comment\n" + + " static int i;\n" + + " public static void main(String[] args) { \n" + + " System.out.print(\"SUCCESS\"); \n" + + " } \n" + + "}" + }, + "SUCCESS", // expected output + null, + true, // flush previous output dir content + null, // special vm args + null, // custom options + null); // custom requestor + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "A.java", + "public class A {\n" + + " public static void main(String[] args) { \n" + + " System.out.print(X.i); \n" + + " } \n" + + "}" + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "0" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.DEFAULT /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=88124 +public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public class X {\n" + + "}\n", + + "Y.java", + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public class Y {\n" + + " Zork z;\n" + + " X x;\n" + + " X foo() {\n" + + " X x; // unexpected deprecated warning here\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Y.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in Y.java (at line 8)\n" + + " X x; // unexpected deprecated warning here\n" + + " ^\n" + + "The local variable x is hiding a field from type Y\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=88124 - variation +public void test008() { + this.runConformTest( + new String[] { + "X.java", + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public class X {\n" + + "}\n", + }, + ""); + this.runNegativeTest( + new String[] { + "Y.java", + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public class Y {\n" + + " Zork z;\n" + + " void foo() {\n" + + " X x; // unexpected deprecated warning here\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Y.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n",// expected output + null, + false, // flush previous output dir content + null); // custom options +} +// variation of test008 on behalf of Bug 526335 - [9][hovering] Deprecation warning should show the new 'since' deprecation value +// verify that we don't attempt to access java.lang.Deprecated in a 1.4 based compilation. +public void test008a() throws IOException { + String jarPath = LIB_DIR+File.separator+"p008a"+File.separator+"x.jar"; + Util.createJar(new String[] { + "X.java", + "package p008a;\n" + + "@Deprecated\n" + + "public class X {\n" + + "}\n", + }, + jarPath, + "1.5"); + + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Y.java", + "public class Y {\n" + + " void foo() {\n" + + " p008a.X x;\n" + + " }\n" + + "}\n", + }; + String[] libs = getDefaultClassPaths(); + libs = Arrays.copyOf(libs, libs.length+1); + libs[libs.length-1] = jarPath; + runner.classLibraries = libs; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in Y.java (at line 3)\n" + + " p008a.X x;\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + // simulate we were running on a JRE without java.lang.Deprecated + this.invisibleType = TypeConstants.JAVA_LANG_DEPRECATED; + } + runner.runWarningTest(); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=88124 - variation +public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public class X {\n" + + "}\n", + + "Y.java", + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public class Y {\n" + + " Zork z;\n" + + " void foo() {\n" + + " X x; // unexpected deprecated warning here\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Y.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=88187 +public void test010() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public class X {\n" + + " /**\n" + + " * @see I2#foo()\n" + + " */\n" + + " I1 foo() {\n" + + " return null;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + "I1.java", + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public interface I1 {\n" + + " // empty block\n" + + "}\n", + "I2.java", + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public interface I2 {\n" + + " I1 foo(); // unexpected warning here\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, + customOptions); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=123522 +public void test011() { + this.runNegativeTest( + new String[] { + "p1/X.java", // ================= + "package p1;\n" + + "import p2.I;\n" + + "/** @deprecated */\n" + + "public class X {\n" + + " Zork z;\n" + + "}\n", // ================= + "p2/I.java", // ================= + "package p2;\n" + + "/** @deprecated */\n" + + "public interface I {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +// @deprecated upon locals do not influence the deprecation diagnostic +// JLS3 9.6 +public void test012() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, + CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, + CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo() {\n" + + " /** @deprecated */\n" + + " int i1 = Y.m;\n" + + " }\n" + + " /** @deprecated */\n" + + " void bar() {\n" + + " int i1 = Y.m;\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " /** @deprecated */\n" + + " static int m;\n" + + "}\n", }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 4)\n" + + " int i1 = Y.m;\n" + + " ^\n" + + "The field Y.m is deprecated\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// @deprecated upon locals do not influence the deprecation diagnostic +// JLS3 9.6 +// @Deprecated variant +public void test013() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, + CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, + CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo() {\n" + + " @Deprecated\n" + + " int i1 = Y.m;\n" + + " }\n" + + " @Deprecated\n" + + " void bar() {\n" + + " int i1 = Y.m;\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " @Deprecated\n" + + " static int m;\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 4)\n" + + " int i1 = Y.m;\n" + + " ^\n" + + "The field Y.m is deprecated\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159243 +public void test014() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "/**\n" + + " * @deprecated\n" + + " */\n" + + "public class X {\n" + + "}\n", + "Y.java", + "import p.X;\n" + + "public class Y {\n" + + " Zork z;\n" + + " void foo() {\n" + + " X x;\n" + + " X[] xs = { x };\n" + + " }\n" + + " void bar() {\n" + + " p.X x;\n" + + " p.X[] xs = { x };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 1)\n" + + " import p.X;\n" + + " ^^^\n" + + "The type X is deprecated\n" + + "----------\n" + + "2. ERROR in Y.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in Y.java (at line 5)\n" + + " X x;\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "4. WARNING in Y.java (at line 6)\n" + + " X[] xs = { x };\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "5. WARNING in Y.java (at line 9)\n" + + " p.X x;\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n" + + "6. WARNING in Y.java (at line 10)\n" + + " p.X[] xs = { x };\n" + + " ^\n" + + "The type X is deprecated\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159709 +// the order of the CUs must not modify the behavior, see also test016 +public void test015() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "p/M1.java", + "package p;\n" + + "public class M1 {\n" + + " void bar() {\n" + + " a.N1.N2.N3 m = null;\n" + + " m.foo();\n" + + " }\n" + + "}\n", + "a/N1.java", + "package a;\n" + + "public class N1 {\n" + + " /** @deprecated */\n" + + " public class N2 {" + + " public class N3 {" + + " public void foo() {}" + + " }" + + " }" + + "}\n", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2 is deprecated\n" + + "----------\n" + + "2. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2.N3 is deprecated\n" + + "----------\n" + + "3. ERROR in p\\M1.java (at line 5)\n" + + " m.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type N1.N2.N3 is deprecated\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159709 +public void test016() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "a/N1.java", + "package a;\n" + + "public class N1 {\n" + + " /** @deprecated */\n" + + " public class N2 {" + + " public class N3 {" + + " public void foo() {}" + + " }" + + " }" + + "}\n", + "p/M1.java", + "package p;\n" + + "public class M1 {\n" + + " void bar() {\n" + + " a.N1.N2.N3 m = null;\n" + + " m.foo();\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2 is deprecated\n" + + "----------\n" + + "2. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2.N3 is deprecated\n" + + "----------\n" + + "3. ERROR in p\\M1.java (at line 5)\n" + + " m.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type N1.N2.N3 is deprecated\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159709 +// variant: self-contained case, hence no report +public void test017() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "a/N1.java", + "package a;\n" + + "public class N1 {\n" + + " /** @deprecated */\n" + + " public class N2 {" + + " public class N3 {" + + " public void foo() {}" + + " }" + + " }" + + " void bar() {\n" + + " a.N1.N2.N3 m = null;\n" + + " m.foo();\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + customOptions, + null, + false); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159709 +// variant: using a binary class +// ** +public void test018() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "a/N1.java", + "package a;\n" + + "public class N1 {\n" + + " /** @deprecated */\n" + + " public class N2 {" + + " public class N3 {" + + " public void foo() {}" + + " }" + + " }" + + "}\n" + }, + "", + null, + true, + null, + customOptions, + null, + false); + runNegativeTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "p/M1.java", + "package p;\n" + + "public class M1 {\n" + + " void bar() {\n" + + " a.N1.N2.N3 m = null;\n" + + " m.foo();\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2 is deprecated\n" + + "----------\n" + + "2. ERROR in p\\M1.java (at line 4)\n" + + " a.N1.N2.N3 m = null;\n" + + " ^^\n" + + "The type N1.N2.N3 is deprecated\n" + + "----------\n" + + "3. ERROR in p\\M1.java (at line 5)\n" + + " m.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type N1.N2.N3 is deprecated\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191909 (1.4 variant) +public void test019() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "test1/E01.java", + "package test1;\n" + + "public class E01 {\n" + + " /** @deprecated */\n" + + " public static int x = 5, y= 10;\n" + + "}", + "test1/E02.java", + "package test1;\n" + + "public class E02 {\n" + + " public void foo() {\n" + + " System.out.println(E01.x);\n" + + " System.out.println(E01.y);\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in test1\\E02.java (at line 4)\n" + + " System.out.println(E01.x);\n" + + " ^\n" + + "The field E01.x is deprecated\n" + + "----------\n" + + "2. ERROR in test1\\E02.java (at line 5)\n" + + " System.out.println(E01.y);\n" + + " ^\n" + + "The field E01.y is deprecated\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=300031 +public void test020() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "a.b.c.d/Deprecated.java", + "package a.b.c.d;\n" + + "public class Deprecated {\n" + + " /** @deprecated */\n" + + " public class Inner {\n" + + " /** @deprecated */\n" + + " public class Inn {\n" + + " }\n" + + " }\n" + + " /** @deprecated */\n" + + " public Deprecated foo(){ return null;}\n" + + " /** @deprecated */\n" + + " public Deprecated goo(){ return null;}\n" + + " /** @deprecated */\n" + + " public static Deprecated bar(){ return null;}\n" + + "}\n", + "a.b.c.d.e/T.java", + "package a.b.c.d.e;\n" + + "import a.b.c.d.Deprecated;\n" + + "public class T {\n" + + " a.b.c.d.Deprecated f;\n" + + " a.b.c.d.Deprecated.Inner.Inn g;\n" + + " Deprecated.Inner i;\n" + + " public void m() {\n" + + " f.foo().goo();\n" + + " a.b.c.d.Deprecated.bar();\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in a.b.c.d.e\\T.java (at line 5)\n" + + " a.b.c.d.Deprecated.Inner.Inn g;\n" + + " ^^^^^\n" + + "The type Deprecated.Inner is deprecated\n" + + "----------\n" + + "2. ERROR in a.b.c.d.e\\T.java (at line 5)\n" + + " a.b.c.d.Deprecated.Inner.Inn g;\n" + + " ^^^\n" + + "The type Deprecated.Inner.Inn is deprecated\n" + + "----------\n" + + "3. ERROR in a.b.c.d.e\\T.java (at line 6)\n" + + " Deprecated.Inner i;\n" + + " ^^^^^\n" + + "The type Deprecated.Inner is deprecated\n" + + "----------\n" + + "4. ERROR in a.b.c.d.e\\T.java (at line 8)\n" + + " f.foo().goo();\n" + + " ^^^^^\n" + + "The method foo() from the type Deprecated is deprecated\n" + + "----------\n" + + "5. ERROR in a.b.c.d.e\\T.java (at line 8)\n" + + " f.foo().goo();\n" + + " ^^^^^\n" + + "The method goo() from the type Deprecated is deprecated\n" + + "----------\n" + + "6. ERROR in a.b.c.d.e\\T.java (at line 9)\n" + + " a.b.c.d.Deprecated.bar();\n" + + " ^^^^^\n" + + "The method bar() from the type Deprecated is deprecated\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public static Class testClass() { + return DeprecatedTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnclosingMethodAttributeTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnclosingMethodAttributeTest.java new file mode 100644 index 0000000000..ab419627a1 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnclosingMethodAttributeTest.java @@ -0,0 +1,260 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.Compiler; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; + +@SuppressWarnings({ "rawtypes" }) +public class EnclosingMethodAttributeTest extends AbstractComparableTest { + public EnclosingMethodAttributeTest(String name) { + super(name); + } + + // 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[] { "test127" }; +// TESTS_NUMBERS = new int[] { 4 }; +// TESTS_RANGE = new int[] { 169, 180 }; + } + + public static Test suite() { + return buildComparableTestSuite(testClass()); + } + + public static Class testClass() { + return EnclosingMethodAttributeTest.class; + } + + public void test001() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void main(String[] args) throws Exception {\n" + + " class MyLocal$A {\n" + + " class Member {\n" + + " }\n" + + " };\n" + + " System.out.print(MyLocal$A.Member.class.getEnclosingMethod() != null);\n" + + " System.out.print(MyLocal$A.Member.class.getEnclosingConstructor() != null);\n" + + "\n" + + " System.out.print(MyLocal$A.class.getEnclosingMethod()!= null);\n" + + " System.out.print(MyLocal$A.class.getEnclosingConstructor() != null); \n" + + " \n" + + " System.out.print(X.class.getEnclosingMethod() != null);\n" + + " System.out.print(X.class.getEnclosingConstructor() != null); \n" + + "}\n" + + "public Object foo() {\n" + + " return new Object() {};\n" + + "}\n" + + "}" + }, + "falsefalsetruefalsefalsefalse"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X$1.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = " Enclosing Method: #22 #24 X.foo()Ljava/lang/Object;\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test002() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void main(String[] args) throws Exception {\n" + + " class MyLocal$A {\n" + + " class Member {\n" + + " public Object foo() {\n" + + " return new Object() {};\n" + + " }\n" + + " }\n" + + " };\n" + + " System.out.print(MyLocal$A.Member.class.getEnclosingMethod() != null);\n" + + " System.out.print(MyLocal$A.Member.class.getEnclosingConstructor() != null);\n" + + "\n" + + " System.out.print(MyLocal$A.class.getEnclosingMethod()!= null);\n" + + " System.out.print(MyLocal$A.class.getEnclosingConstructor() != null); \n" + + " \n" + + " System.out.print(X.class.getEnclosingMethod() != null);\n" + + " System.out.print(X.class.getEnclosingConstructor() != null); \n" + + "}\n" + + "}" + }, + "falsefalsetruefalsefalsefalse"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator + "X$1MyLocal$A$Member$1.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = " Enclosing Method: #22 #24 X$1MyLocal$A$Member.foo()Ljava/lang/Object;\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162356 + public void test003() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.*;\n" + + "public class X {\n" + + " public void test() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {\n" + + " class LocalClass {\n" + + " public void method() {\n" + + " }\n" + + " };\n" + + " LocalClass localClass = new LocalClass();\n" + + " Class cc = localClass.getClass();\n" + + " System.out.println(\"enclosing class = \" + cc.getEnclosingClass());\n" + + " System.out.println(\"enclosing method = \" + cc.getEnclosingMethod());\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " X t = new X();\n" + + " try {\n" + + " t.test();\n" + + " } catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}" + }, + "enclosing class = class X\n" + + "enclosing method = public void X.test() throws java.lang.NoSuchMethodException,java.lang.IllegalAccessException,java.lang.reflect.InvocationTargetException"); + + INameEnvironment nameEnvironment = getNameEnvironment(new String[]{}, null); + nameEnvironment.findType(new char[][] {new char[0], "X$1LocalClass".toCharArray()}); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator + "X$1LocalClass.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #1 X$1LocalClass, outer class info: #0\n" + + " inner name: #28 LocalClass, accessflags: 0 default]\n"; + + // check inner classes info + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + + expectedOutput = + " Enclosing Method: #23 #25 X.test()V\n"; + + // check enclosing method + index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=288920 + public void test004() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.*;\n" + + "interface I {\n" + + " public String run();\n" + + "}\n" + + "public class X {\n" + + " public Object test(String s, int i) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {\n" + + " return (new I() {" + + " public String run() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " }).run();\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " X t = new X();\n" + + " try {\n" + + " System.out.println(t.test(\"\", 0));\n" + + " } catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}" + }, + "SUCCESS"); + + Requestor requestor = + new Requestor( + true, + null, + false, /* show category */ + false /* show warning token*/); + requestor.outputPath = OUTPUT_DIR.endsWith(File.separator) ? OUTPUT_DIR : OUTPUT_DIR + File.separator; + // WORK should not have to test a constant? + + Map options = getCompilerOptions(); + CompilerOptions compilerOptions = new CompilerOptions(options); + compilerOptions.performMethodsFullRecovery = true; + compilerOptions.performStatementsRecovery = true; + INameEnvironment nameEnvironment = getNameEnvironment(new String[]{}, null); + Compiler batchCompiler = + new Compiler( + nameEnvironment, + getErrorHandlingPolicy(), + compilerOptions, + requestor, + getProblemFactory()); + ReferenceBinding binaryType = batchCompiler.lookupEnvironment.askForType(new char[][] {new char[0], "X$1".toCharArray()}, batchCompiler.lookupEnvironment.UnNamedModule); + assertNotNull("Should not be null", binaryType); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java new file mode 100644 index 0000000000..0046d79446 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java @@ -0,0 +1,7299 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * Bug 365519 - editorial cleanup after bug 186342 and bug 365387 + * Bug 265744 - Enum switch should warn about missing default + * Bug 374605 - Unreasonable warning for enum-based switch statements + * bug 388739 - [1.8][compiler] consider default methods when detecting whether a class needs to be declared abstract + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +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; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class EnumTest extends AbstractComparableTest { + + String reportMissingJavadocComments = null; + + public EnumTest(String name) { + super(name); + } + + // 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[] { "test187" }; +// TESTS_NUMBERS = new int[] { 185 }; +// TESTS_RANGE = new int[] { 21, 50 }; + } + public static Test suite() { + return buildComparableTestSuite(testClass()); + } + + public static Class testClass() { + return EnumTest.class; + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + if (this.reportMissingJavadocComments != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + return options; + } + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.reportMissingJavadocComments = null; + } + +// test simple valid enum and its usage +public void test000() { + runConformTest( + new String[] { + "e/X.java", + "package e;\n" + + "import e.T;\n" + + "import static e.T.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"JDTCore team:\");\n" + + " T oldest = null;\n" + + " int maxAge = Integer.MIN_VALUE;\n" + + " for (T t : T.values()) {\n" + + " if (t == YODA) continue;// skip YODA\n" + + " t.setRole(t.isManager());\n" + + " if (t.age() > maxAge) {\n" + + " oldest = t;\n" + + " maxAge = t.age();\n" + + " }\n" + + " System.out.print(\" \"+ t + ':'+t.age()+':'+location(t)+':'+t.role);\n" + + " }\n" + + " System.out.println(\" WINNER is:\" + T.valueOf(oldest.name()));\n" + + " }\n" + + "\n" + + " private enum Location { SNZ, OTT }\n" + + "\n" + + " private static Location location(T t) {\n" + + " switch(t) {\n" + + " case PHILIPPE: \n" + + " case DAVID:\n" + + " case JEROME:\n" + + " case FREDERIC:\n" + + " return Location.SNZ;\n" + + " case OLIVIER:\n" + + " case KENT:\n" + + " return Location.OTT;\n" + + " default:\n" + + " throw new AssertionError(\"Unknown team member: \" + t);\n" + + " }\n" + + " }\n" + + "}\n", + "e/T.java", + "package e;\n" + + "public enum T {\n" + + " PHILIPPE(37) {\n" + + " public boolean isManager() {\n" + + " return true;\n" + + " }\n" + + " },\n" + + " DAVID(27),\n" + + " JEROME(33),\n" + + " OLIVIER(35),\n" + + " KENT(40),\n" + + " YODA(41),\n" + + " FREDERIC;\n" + + " final static int OLD = 41;\n" + + "\n" + + " enum Role { M, D }\n" + + "\n" + + " int age;\n" + + " Role role;\n" + + "\n" + + " T() { this(OLD); }\n" + + " T(int age) {\n" + + " this.age = age;\n" + + " }\n" + + " public int age() { return this.age; }\n" + + " public boolean isManager() { return false; }\n" + + " void setRole(boolean mgr) {\n" + + " this.role = mgr ? Role.M : Role.D;\n" + + " }\n" + + "}\n" + }, + "JDTCore team: PHILIPPE:37:SNZ:M DAVID:27:SNZ:D JEROME:33:SNZ:D OLIVIER:35:OTT:D KENT:40:OTT:D FREDERIC:41:SNZ:D WINNER is:FREDERIC" + ); +} +// check assignment to enum constant is disallowed +public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X { \n" + + " BLEU, \n" + + " BLANC, \n" + + " ROUGE;\n" + + " static {\n" + + " BLEU = null;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " BLEU = null;\n" + + " ^^^^\n" + + "The final field X.BLEU cannot be assigned\n" + + "----------\n"); +} +// check diagnosis for duplicate enum constants +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X { \n" + + " \n" + + " BLEU, \n" + + " BLANC, \n" + + " ROUGE,\n" + + " BLEU;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " BLEU, \n" + + " ^^^^\n" + + "Duplicate field X.BLEU\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " BLEU;\n" + + " ^^^^\n" + + "Duplicate field X.BLEU\n" + + "----------\n"); +} +// check properly rejecting enum constant modifiers +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X { \n" + + " \n" + + " public BLEU, \n" + + " transient BLANC, \n" + + " ROUGE, \n" + + " abstract RED {\n" + + " void test() {}\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public BLEU, \n" + + " ^^^^\n" + + "Illegal modifier for the enum constant BLEU; no modifier is allowed\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " transient BLANC, \n" + + " ^^^^^\n" + + "Illegal modifier for the enum constant BLANC; no modifier is allowed\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " abstract RED {\n" + + " ^^^\n" + + "Illegal modifier for the enum constant RED; no modifier is allowed\n" + + "----------\n"); +} +// check using an enum constant +public void test004() { + this.runConformTest( + new String[] { + "X.java", + "public enum X { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.println(BLEU);\n" + + " }\n" + + " \n" + + "}\n" + }, + "BLEU"); +} +// check method override diagnosis (with no enum constants) +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X { \n" + + " ;\n" + + " protected Object clone() { return this; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " protected Object clone() { return this; }\n" + + " ^^^^^^^\n" + + "Cannot override the final method from Enum\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " protected Object clone() { return this; }\n" + + " ^^^^^^^\n" + + "The method clone() of type X should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); +} +// check generated #values() method +public void test006() { + this.runConformTest( + new String[] { + "X.java", + "public enum X { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " public static void main(String[] args) {\n" + + " for(X x: X.values()) {\n" + + " System.out.print(x);\n" + + " }\n" + + " }\n" + + " \n" + + "}\n" + }, + "BLEUBLANCROUGE"); +} +// tolerate user definition for $VALUES +public void test007() { + this.runConformTest( + new String[] { + "X.java", + "public enum X { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " int $VALUES;\n" + + " public static void main(String[] args) {\n" + + " for(X x: X.values()) {\n" + + " System.out.print(x);\n" + + " }\n" + + " }\n" + + " \n" + + "}\n" + }, + "BLEUBLANCROUGE"); +} +// reject user definition for #values() +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " void dup() {} \n" + + " void values() {} \n" + + " void dup() {} \n" + + " void values() {} \n" + + " Missing dup() {} \n" + + " public static void main(String[] args) {\n" + + " for(X x: X.values()) {\n" + + " System.out.print(x);\n" + + " }\n" + + " }\n" + + " \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " void dup() {} \n" + + " ^^^^^\n" + + "Duplicate method dup() in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " void values() {} \n" + + " ^^^^^^^^\n" + + "The enum X already defines the method values() implicitly\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " void dup() {} \n" + + " ^^^^^\n" + + "Duplicate method dup() in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " void values() {} \n" + + " ^^^^^^^^\n" + + "The enum X already defines the method values() implicitly\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " Missing dup() {} \n" + + " ^^^^^^^\n" + + "Missing cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " Missing dup() {} \n" + + " ^^^^^\n" + + "Duplicate method dup() in type X\n" + + "----------\n"); +} +// switch on enum +public void test009() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " //void values() {}\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X x = BLEU;\n" + + " switch(x) {\n" + + " case BLEU :\n" + + " System.out.println(\"SUCCESS\");\n" + + " break;\n" + + " case BLANC :\n" + + " case ROUGE :\n" + + " System.out.println(\"FAILED\");\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + " \n" + + "}" + }, + "SUCCESS"); +} +// duplicate switch case +public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " //void values() {}\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X x = BLEU;\n" + + " switch(x) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLEU :\n" + + " case BLANC :\n" + + " case ROUGE :\n" + + " System.out.println(\"FAILED\");\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + " \n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " case BLEU :\n" + + " ^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " case BLEU :\n" + + " ^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n"); +} +// reject user definition for #values() +public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " void values() {} \n" + + " void values() {} \n" + + " public static void main(String[] args) {\n" + + " for(X x: X.values()) {\n" + + " System.out.print(x);\n" + + " }\n" + + " }\n" + + " \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " void values() {} \n" + + " ^^^^^^^^\n" + + "The enum X already defines the method values() implicitly\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " void values() {} \n" + + " ^^^^^^^^\n" + + "The enum X already defines the method values() implicitly\n" + + "----------\n"); +} +// check abstract method diagnosis +public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X implements Runnable { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public enum X implements Runnable { \n" + + " ^\n" + + "The type X must implement the inherited abstract method Runnable.run()\n" + + "----------\n"); +} +// check enum constants with wrong arguments +public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X { \n" + + " \n" + + " BLEU(10),\n" + + " BLANC(20),\n" + + " ROUGE(30);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " BLEU(10),\n" + + " ^^^^\n" + + "The constructor X(int) is undefined\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " BLANC(20),\n" + + " ^^^^^\n" + + "The constructor X(int) is undefined\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " ROUGE(30);\n" + + " ^^^^^\n" + + "The constructor X(int) is undefined\n" + + "----------\n"); +} +// check enum constants with extra arguments +public void test014() { + this.runConformTest( + new String[] { + "X.java", + "public enum X { \n" + + " \n" + + " BLEU(10),\n" + + " BLANC(20),\n" + + " ROUGE(30);\n" + + "\n" + + " int val;\n" + + " X(int val) {\n" + + " this.val = val;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " for(X x: values()) {\n" + + " System.out.print(x.val);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "102030"); +} +// check enum constants with wrong arguments +public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X { \n" + + " \n" + + " BLEU(10),\n" + + " BLANC(),\n" + + " ROUGE(30);\n" + + "\n" + + " int val;\n" + + " X(int val) {\n" + + " this.val = val;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " for(X x: values()) {\n" + + " System.out.print(x.val);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " BLANC(),\n" + + " ^^^^^\n" + + "The constructor X() is undefined\n" + + "----------\n"); +} +// check enum constants with wrong arguments +public void test016() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " \n" + + " BLEU(10) {\n" + + " String foo() { // inner\n" + + " return super.foo() + this.val;\n" + + " }\n" + + " },\n" + + " BLANC(20),\n" + + " ROUGE(30);\n" + + "\n" + + " int val;\n" + + " X(int val) {\n" + + " this.val = val;\n" + + " }\n" + + " String foo() { // outer\n" + + " return this.name();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " for(X x: values()) {\n" + + " System.out.print(x.foo());\n" + + " }\n" + + " }\n" + + "}\n" + }, + "BLEU10BLANCROUGE"); +} +// check enum constants with empty arguments +public void test017() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " \n" + + " BLEU()\n" + + "}\n" + }, + ""); +} +// cannot extend enums +public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " BLEU()\n" + + "}\n" + + "\n" + + "class XX extends X implements X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " class XX extends X implements X {\n" + + " ^\n" + + "The type X cannot be the superclass of XX; a superclass must be a class\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " class XX extends X implements X {\n" + + " ^\n" + + "The type X cannot be a superinterface of XX; a superinterface must be an interface\n" + + "----------\n"); +} +// 74851 +public void test019() { + this.runConformTest( + new String[] { + "MonthEnum.java", + "public enum MonthEnum {\n" + + " JANUARY (30),\n" + + " FEBRUARY (28),\n" + + " MARCH (31),\n" + + " APRIL (30),\n" + + " MAY (31),\n" + + " JUNE (30),\n" + + " JULY (31),\n" + + " AUGUST (31),\n" + + " SEPTEMBER (31),\n" + + " OCTOBER (31),\n" + + " NOVEMBER (30),\n" + + " DECEMBER (31);\n" + + " \n" + + " private final int days;\n" + + " \n" + + " MonthEnum(int days) {\n" + + " this.days = days;\n" + + " }\n" + + " \n" + + " public int getDays() {\n" + + " boolean leapYear = true;\n" + + " switch(this) {\n" + + " case FEBRUARY: if(leapYear) return days+1;\n" + + " default: return days;\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.println(JANUARY.getDays());\n" + + " }\n" + + " \n" + + "}\n", + }, + "30"); +} +// 74226 +public void test020() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo{\n" + + " public enum Rank {FIRST,SECOND,THIRD}\n" + + " public void setRank(Rank rank){}\n" + + "}\n", + }, + ""); +} +// 74226 variation - check nested enum is implicitly static +public void test021() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public class Foo {\n" + + " public static enum Rank {FIRST,SECOND,THIRD;\n" + + " void bar() { foo(); } \n" + + " }\n" + + " public void setRank(Rank rank){}\n" + + " void foo() {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Foo.java (at line 3)\n" + + " void bar() { foo(); } \n" + + " ^^^\n" + + "Cannot make a static reference to the non-static method foo() from the type Foo\n" + + "----------\n"); +} +// 77151 - cannot use qualified name to denote enum constants in switch case label +public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " enum MX { BLEU, BLANC, ROUGE }\n" + + " \n" + + " void foo(MX e) {\n" + + " switch(e) {\n" + + " case MX.BLEU : break;\n" + + " case MX.BLANC : break;\n" + + " case MX.ROUGE : break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case MX.BLEU : break;\n" + + " ^^^^^^^\n" + + "The qualified case label X.MX.BLEU must be replaced with the unqualified enum constant BLEU\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " case MX.BLANC : break;\n" + + " ^^^^^^^^\n" + + "The qualified case label X.MX.BLANC must be replaced with the unqualified enum constant BLANC\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " case MX.ROUGE : break;\n" + + " ^^^^^^^^\n" + + "The qualified case label X.MX.ROUGE must be replaced with the unqualified enum constant ROUGE\n" + + "----------\n"); +} + +// 77212 +public void test023() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public enum RuleType{ SUCCESS, FAILURE }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(RuleType.valueOf(RuleType.SUCCESS.name()));\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} + +// 77244 - cannot declare final enum +public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + "public final enum X {\n" + + " FOO() {}\n" + + "}\n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public final enum X {\n" + + " ^\n" + + "Illegal modifier for the enum X; only public is permitted\n" + + "----------\n"); +} + +// values is using arraycopy instead of clone +public void test025() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " SUC, CESS;\n" + + " public static void main(String[] args) {\n" + + " for (X x : values()) {\n" + + " System.out.print(x.name());\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} + +// check enum name visibility +public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Couleur { BLEU, BLANC, ROUGE }\n" + + "}\n" + + "\n" + + "class Y {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " void foo(Couleur c) {\n" + + " ^^^^^^^\n" + + "Couleur cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " case BLEU :\n" + + " ^^^^\n" + + "BLEU cannot be resolved to a variable\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " case BLANC :\n" + + " ^^^^^\n" + + "BLANC cannot be resolved to a variable\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " case ROUGE :\n" + + " ^^^^^\n" + + "ROUGE cannot be resolved to a variable\n" + + "----------\n"); +} +// check enum name visibility +public void test027() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Couleur { BLEU, BLANC, ROUGE }\n" + + " class Y {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " } \n" + + " }\n" + + "}\n", + }, + ""); +} +// check enum name visibility +public void test028() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Couleur { \n" + + " BLEU, BLANC, ROUGE;\n" + + " static int C = 0;\n" + + " static void FOO() {}\n" + + " }\n" + + " class Y {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " FOO();\n" + + " C++;\n" + + " } \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " FOO();\n" + + " ^^^\n" + + "The method FOO() is undefined for the type X.Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " C++;\n" + + " ^\n" + + "C cannot be resolved to a variable\n" + + "----------\n"); +} +// check enum name visibility +public void test029() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Couleur { \n" + + " BLEU, BLANC, ROUGE; // take precedence over toplevel BLEU type\n" + + " }\n" + + " class Y {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " } \n" + + " }\n" + + "}\n" + + "\n" + + "class BLEU {}\n", + }, + ""); +} +// check enum name visibility +public void test030() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Couleur { \n" + + " BLEU, BLANC, ROUGE; // take precedence over sibling constant from Color\n" + + " }\n" + + " enum Color { \n" + + " BLEU, BLANC, ROUGE;\n" + + " }\n" + + " class Y {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " } \n" + + " }\n" + + "}\n" + + "\n" + + "class BLEU {}\n", + }, + ""); +} +// check enum name visibility +public void test031() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Couleur { \n" + + " BLEU, BLANC, ROUGE; // take precedence over toplevel BLEU type\n" + + " }\n" + + " class Y implements IX, JX {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " } \n" + + " }\n" + + "}\n" + + "\n" + + "interface IX {\n" + + " int BLEU = 1;\n" + + "}\n" + + "interface JX {\n" + + " int BLEU = 2;\n" + + "}\n" + + "class BLEU {}\n" + + "\n", + }, + ""); +} + +// check Enum cannot be used as supertype (explicitly) +public void test032() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Enum {\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X extends Enum {\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends Enum {\n" + + " ^^^^\n" + + "The type X may not subclass Enum explicitly\n" + + "----------\n"); +} + +// Javadoc in enum (see bug 78018) +public void test033() { + this.runConformTest( + new String[] { + "E.java", + " /**\n" + + " * Valid javadoc\n" + + " * @author ffr\n" + + " */\n" + + "public enum E {\n" + + " /** Valid javadoc */\n" + + " TEST,\n" + + " /** Valid javadoc */\n" + + " VALID;\n" + + " /** Valid javadoc */\n" + + " public void foo() {}\n" + + "}\n" + } + ); +} +public void test034() { + this.runNegativeTest( + new String[] { + "E.java", + " /**\n" + + " * Invalid javadoc\n" + + " * @exception NullPointerException Invalid tag\n" + + " * @throws NullPointerException Invalid tag\n" + + " * @return Invalid tag\n" + + " * @param x Invalid tag\n" + + " */\n" + + "public enum E { TEST, VALID }\n" + }, + "----------\n" + + "1. ERROR in E.java (at line 3)\n" + + " * @exception NullPointerException Invalid tag\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in E.java (at line 4)\n" + + " * @throws NullPointerException Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in E.java (at line 5)\n" + + " * @return Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in E.java (at line 6)\n" + + " * @param x Invalid tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void test035() { + this.runConformTest( + new String[] { + "E.java", + " /**\n" + + " * @see \"Valid normal string\"\n" + + " * @see Valid URL link reference\n" + + " * @see Object\n" + + " * @see #TEST\n" + + " * @see E\n" + + " * @see E#TEST\n" + + " */\n" + + "public enum E { TEST, VALID }\n" + } + ); +} +public void test036() { + this.runNegativeTest( + new String[] { + "E.java", + " /**\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " * @see invalid no text allowed after the href\n" + + " * @see\n" + + " * @see #VALIDE\n" + + " */\n" + + "public enum E { TEST, VALID }\n" + }, + "----------\n" + + "1. ERROR in E.java (at line 2)\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n" + + "2. ERROR in E.java (at line 3)\n" + + " * @see invalid no text allowed after the href\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n" + + "3. ERROR in E.java (at line 4)\n" + + " * @see\n" + + " ^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n" + + "4. ERROR in E.java (at line 5)\n" + + " * @see #VALIDE\n" + + " ^^^^^^\n" + + "Javadoc: VALIDE cannot be resolved or is not a field\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void test037() { + this.runConformTest( + new String[] { + "E.java", + " /**\n" + + " * Value test: {@value #TEST}\n" + + " * or: {@value E#TEST}\n" + + " */\n" + + "public enum E { TEST, VALID }\n" + } + ); +} +public void test038() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.runNegativeTest( + new String[] { + "E.java", + "public enum E { TEST, VALID;\n" + + " public void foo() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in E.java (at line 1)\n" + + " public enum E { TEST, VALID;\n" + + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "2. ERROR in E.java (at line 1)\n" + + " public enum E { TEST, VALID;\n" + + " ^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "3. ERROR in E.java (at line 1)\n" + + " public enum E { TEST, VALID;\n" + + " ^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "4. ERROR in E.java (at line 2)\n" + + " public void foo() {}\n" + + " ^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void test039() { + this.runNegativeTest( + new String[] { + "E.java", + "public enum E {\n" + + " /**\n" + + " * @exception NullPointerException Invalid tag\n" + + " * @throws NullPointerException Invalid tag\n" + + " * @return Invalid tag\n" + + " * @param x Invalid tag\n" + + " */\n" + + " TEST,\n" + + " VALID;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in E.java (at line 3)\n" + + " * @exception NullPointerException Invalid tag\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in E.java (at line 4)\n" + + " * @throws NullPointerException Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in E.java (at line 5)\n" + + " * @return Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in E.java (at line 6)\n" + + " * @param x Invalid tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void test040() { + this.runConformTest( + new String[] { + "E.java", + "public enum E {\n" + + " /**\n" + + " * @see E\n" + + " * @see #VALID\n" + + " */\n" + + " TEST,\n" + + " /**\n" + + " * @see E#TEST\n" + + " * @see E\n" + + " */\n" + + " VALID;\n" + + " /**\n" + + " * @param x the object\n" + + " * @return String\n" + + " * @see Object\n" + + " */\n" + + " public String val(Object x) { return x.toString(); }\n" + + "}\n" + } + ); +} +public void test041() { + this.runNegativeTest( + new String[] { + "E.java", + "public enum E {\n" + + " /**\n" + + " * @see e\n" + + " * @see #VALIDE\n" + + " */\n" + + " TEST,\n" + + " /**\n" + + " * @see E#test\n" + + " * @see EUX\n" + + " */\n" + + " VALID;\n" + + " /**\n" + + " * @param obj the object\n" + + " * @return\n" + + " * @see Objet\n" + + " */\n" + + " public String val(Object x) { return x.toString(); }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in E.java (at line 3)\n" + + " * @see e\n" + + " ^\n" + + "Javadoc: e cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in E.java (at line 4)\n" + + " * @see #VALIDE\n" + + " ^^^^^^\n" + + "Javadoc: VALIDE cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in E.java (at line 8)\n" + + " * @see E#test\n" + + " ^^^^\n" + + "Javadoc: test cannot be resolved or is not a field\n" + + "----------\n" + + "4. ERROR in E.java (at line 9)\n" + + " * @see EUX\n" + + " ^^^\n" + + "Javadoc: EUX cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in E.java (at line 13)\n" + + " * @param obj the object\n" + + " ^^^\n" + + "Javadoc: Parameter obj is not declared\n" + + "----------\n" + + "6. ERROR in E.java (at line 14)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n" + + "7. ERROR in E.java (at line 15)\n" + + " * @see Objet\n" + + " ^^^^^\n" + + "Javadoc: Objet cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in E.java (at line 17)\n" + + " public String val(Object x) { return x.toString(); }\n" + + " ^\n" + + "Javadoc: Missing tag for parameter x\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void test042() { + this.runConformTest( + new String[] { + "E.java", + "public enum E {\n" + + " /**\n" + + " * Test value: {@value #TEST}\n" + + " */\n" + + " TEST,\n" + + " /**\n" + + " * Valid value: {@value E#VALID}\n" + + " */\n" + + " VALID;\n" + + " /**\n" + + " * Test value: {@value #TEST}\n" + + " * Valid value: {@value E#VALID}\n" + + " * @param x the object\n" + + " * @return String\n" + + " */\n" + + " public String val(Object x) { return x.toString(); }\n" + + "}\n" + } + ); +} + +// External javadoc references to enum +public void test043() { + this.runConformTest( + new String[] { + "test/E.java", + "package test;\n" + + "public enum E { TEST, VALID }\n", + "test/X.java", + "import static test.E.TEST;\n" + + " /**\n" + + " * @see test.E\n" + + " * @see test.E#VALID\n" + + " * @see #TEST\n" + + " */\n" + + "public class X {}\n" + } + ); +} +public void test044() { + this.runConformTest( + new String[] { + "test/E.java", + "package test;\n" + + "public enum E { TEST, VALID }\n", + "test/X.java", + "import static test.E.TEST;\n" + + " /**\n" + + " * Valid value = {@value test.E#VALID}\n" + + " * Test value = {@value #TEST}\n" + + " */\n" + + "public class X {}\n" + } + ); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78321 + */ +public void test045() { + this.runConformTest( + new String[] { + "X.java", + "public enum X\n" + + "{\n" + + " FIRST,\n" + + " SECOND,\n" + + " THIRD;\n" + + "\n" + + " static {\n" + + " for (X t : values()) {\n" + + " System.out.print(t.name());\n" + + " }\n" + + " }\n" + + "\n" + + " X() {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}" + }, + "FIRSTSECONDTHIRD" + ); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78464 + */ +public void test046() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " a(1);\n" + + " X(int i) {\n" + + " }\n" + + "}" + }, + "" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78914 + */ +public void test047() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " ;\n" + + " X() {\n" + + " super();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " super();\n" + + " ^^^^^^^^\n" + + "Cannot invoke super constructor from enum constructor X()\n" + + "----------\n" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77211 + */ +public void test048() { + this.runConformTest( + new String[] { + "StopLight.java", + "public enum StopLight{\n" + + " RED{\n" + + " public StopLight next(){ return GREEN; }\n" + + " },\n" + + " GREEN{\n" + + " public StopLight next(){ return YELLOW; }\n" + + " },\n" + + " YELLOW{\n" + + " public StopLight next(){ return RED; }\n" + + " };\n" + + "\n" + + " public abstract StopLight next();\n" + + "}" + }, + "" + ); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78915 + */ +public void test049() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract enum X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public abstract enum X {}\n" + + " ^\n" + + "Illegal modifier for the enum X; only public is permitted\n" + + "----------\n" + ); +} + +public void test050() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {}" + }, + "" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78914 - variation + */ +public void test051() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " BLEU (0) {\n" + + " }\n" + + " ;\n" + + " X() {\n" + + " this(0);\n" + + " }\n" + + " X(int i) {\n" + + " }\n" + + "}\n" + }, + "" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78916 + */ +public void test052() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " A\n" + + " ;\n" + + " \n" + + " public abstract void foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " A\n" + + " ^\n" + + "The enum constant A must implement the abstract method foo()\n" + + "----------\n" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78916 - variation + */ +public void test053() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " A () { public void foo() {} }\n" + + " ;\n" + + " \n" + + " public abstract void foo();\n" + + "}\n" + }, + "" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78916 - variation + */ +public void test054() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " A() {}\n" + + " ;\n" + + " \n" + + " public abstract void foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " A() {}\n" + + " ^\n" + + "The enum constant A must implement the abstract method foo()\n" + + "----------\n" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78916 - variation + */ +public void test055() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " ;\n" + + " \n" + + " public abstract void foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public abstract void foo();\n" + + " ^^^^^\n" + + "The enum X can only define the abstract method foo() if it also defines enum constants with corresponding implementations\n" + + "----------\n" + ); +} +// TODO (philippe) enum cannot be declared as local type + +// TODO (philippe) check one cannot redefine Enum incorrectly + +// TODO (philippe) check enum syntax recovery +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78914 - variation + */ +public void test056() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " PLUS {\n" + + " double eval(double x, double y) { return x + y; }\n" + + " };\n" + + "\n" + + " // Perform the arithmetic X represented by this constant\n" + + " abstract double eval(double x, double y);\n" + + "}" + }, + "" + ); + String expectedOutput = + "// Signature: Ljava/lang/Enum;\n" + + "public abstract enum X {\n"; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77430 + */ +public void test057() { + this.runConformTest( + new String[] { + "Enum2.java", + "public class Enum2 {\n" + + " enum Color { RED, GREEN };\n" + + " public static void main(String[] args) {\n" + + " Color c= Color.GREEN;\n" + + " switch (c) {\n" + + " case RED:\n" + + " System.out.println(Color.RED);\n" + + " break;\n" + + " case GREEN:\n" + + " System.out.println(c);\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + "}\n" + }, + "GREEN" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77430 - variation + */ +public void test058() { + this.runNegativeTest( + new String[] { + "X.java", + "enum X { a }\n" + + "class A {\n" + + " public static void main(String[] args) {\n" + + " test(X.a, 9);\n" + + " test2(X.a, 3);\n" + + " }\n" + + " static void test(X x, int a) {\n" + + " if (x == a) a++; // incomparable types: X and int\n" + + " switch(x) {\n" + + " case a : System.out.println(a); // prints \'9\'\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + " static void test2(X x, final int aa) {\n" + + " switch(x) {\n" + + " case aa : // unqualified enum constant error\n" + + " System.out.println(a); // cannot find a\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " if (x == a) a++; // incomparable types: X and int\n" + + " ^^^^^^\n" + + "Incompatible operand types X and int\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " case aa : // unqualified enum constant error\n" + + " ^^\n" + + "aa cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in X.java (at line 17)\n" + + " System.out.println(a); // cannot find a\n" + + " ^\n" + + "a cannot be resolved to a variable\n" + + "----------\n" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=81262 + */ +public void test059() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " MONDAY {\n" + + " public void foo() {\n" + + " }\n" + + " };\n" + + " private X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=81589 + */ +public void test060() { + this.runNegativeTest( + new String[] { + "com/flarion/test/a/MyEnum.java", + "package com.flarion.test.a;\n" + + "public enum MyEnum {\n" + + "\n" + + " First, Second;\n" + + " \n" + + "}\n", + "com/flarion/test/b/MyClass.java", + "package com.flarion.test.b;\n" + + "import com.flarion.test.a.MyEnum;\n" + + "import static com.flarion.test.a.MyEnum.First;\n" + + "import static com.flarion.test.a.MyEnum.Second;\n" + + "public class MyClass {\n" + + "\n" + + " public void myMethod() {\n" + + " MyEnum e = MyEnum.First;\n" + + " switch (e) {\n" + + " case First:\n" + + " break;\n" + + " case Second:\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " throw new Exception();\n" + // fake error to cause dump of unused import warnings + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in com\\flarion\\test\\b\\MyClass.java (at line 3)\n" + + " import static com.flarion.test.a.MyEnum.First;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import com.flarion.test.a.MyEnum.First is never used\n" + + "----------\n" + + "2. WARNING in com\\flarion\\test\\b\\MyClass.java (at line 4)\n" + + " import static com.flarion.test.a.MyEnum.Second;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import com.flarion.test.a.MyEnum.Second is never used\n" + + "----------\n" + + "3. ERROR in com\\flarion\\test\\b\\MyClass.java (at line 16)\n" + + " throw new Exception();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82217 + */ +public void test061() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " A, B, C;\n" + + " public static final X D = null;\n" + + "}\n" + + "\n" + + "class A {\n" + + " private void foo(X x) {\n" + + " switch (x) {\n" + + " case D:\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant A needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant B needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant C needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " case D:\n" + + " ^\n" + + "The field X.D cannot be referenced from an enum case label; only enum constants can be used in enum switch\n" + + "----------\n"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82217 - variation with qualified name + */ +public void test062() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE, JavaCore.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " A, B, C;\n" + + " public static final X D = null;\n" + + "}\n" + + "\n" + + "class A {\n" + + " private void foo(X x) {\n" + + " switch (x) {\n" + + " case X.D:\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " switch (x) {\n" + + " ^\n" + + "The switch over the enum type X should have a default case\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant A needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant B needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant C needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " case X.D:\n" + + " ^\n" + + "The field X.D cannot be referenced from an enum case label; only enum constants can be used in enum switch\n" + + "----------\n", + null, // classlibs + true, // flush + options); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=81945 + */ +public void test063() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Option { ALPHA, BRAVO };\n" + + " void method1(Option item) {\n" + + " switch (item) {\n" + + " case ALPHA: break;\n" + + " case BRAVO: break;\n" + + " default: break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82590 + */ +public void test064() { + this.runConformTest( + new String[] { + "X.java", + "public enum X implements B {\n" + + "\n" + + " C1 {\n" + + " public void test() {};\n" + + " },\n" + + " C2 {\n" + + " public void test() {};\n" + + " }\n" + + "}\n" + + "\n" + + "interface B {\n" + + " public void test();\n" + + " \n" + + "}\n", + }, + ""); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83847 + */ +public void test065() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " A;\n" + + " private void foo() {\n" + + " X e= new X() {\n" + + " };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X e= new X() {\n" + + " ^\n" + + "Cannot instantiate the type X\n" + + "----------\n"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83860 + */ +public void test066() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " SUCCESS (0) {};\n" + + " private X(int i) {}\n" + + " public static void main(String[] args) {\n" + + " for (X x : values()) {\n" + + " System.out.print(x);\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83219 + */ +public void test067() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " ONE, TWO, THREE;\n" + + " abstract int getSquare();\n" + + " abstract int getSquare();\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " ONE, TWO, THREE;\n" + + " ^^^\n" + + "The enum constant ONE must implement the abstract method getSquare()\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " ONE, TWO, THREE;\n" + + " ^^^\n" + + "The enum constant TWO must implement the abstract method getSquare()\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " ONE, TWO, THREE;\n" + + " ^^^^^\n" + + "The enum constant THREE must implement the abstract method getSquare()\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " abstract int getSquare();\n" + + " ^^^^^^^^^^^\n" + + "Duplicate method getSquare() in type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " abstract int getSquare();\n" + + " ^^^^^^^^^^^\n" + + "Duplicate method getSquare() in type X\n" + + "----------\n"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83648 + */ +public void test068() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " A(1, 3), B(1, 3), C(1, 3) { }\n" + + " ;\n" + + " public X(int i, int j) { }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public X(int i, int j) { }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal modifier for the enum constructor; only private is permitted.\n" + + "----------\n"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83648 + */ +public void test069() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " A(1, 3), B(1, 3), C(1, 3) { }\n" + + " ;\n" + + " protected X(int i, int j) { }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " protected X(int i, int j) { }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal modifier for the enum constructor; only private is permitted.\n" + + "----------\n"); +} + +public void test070() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " PLUS {\n" + + " double eval(double x, double y) { return x + y; }\n" + + " };\n" + + "\n" + + " // Perform the arithmetic X represented by this constant\n" + + " abstract double eval(double x, double y);\n" + + "}" + }, + "" + ); + String expectedOutput = + " // Method descriptor #18 (Ljava/lang/String;I)V\n" + + " // Stack: 3, Locals: 3\n" + + " private X(java.lang.String arg0, int arg1);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 iload_2 [arg1]\n" + + " 3 invokespecial java.lang.Enum(java.lang.String, int) [25]\n" + + " 6 return\n"; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83901 +public void test071() { + this.runConformTest( // no methods to implement + new String[] { + "X1.java", + "public enum X1 implements I {\n" + + " ;\n" + + "}\n" + + "interface I {}\n" + }, + "" + ); + this.runConformTest( // no methods to implement with constant + new String[] { + "X1a.java", + "public enum X1a implements I {\n" + + " A;\n" + + "}\n" + + "interface I {}\n" + }, + "" + ); + this.runConformTest( // no methods to implement with constant body + new String[] { + "X1b.java", + "public enum X1b implements I {\n" + + " A() { void random() {} };\n" + + "}\n" + + "interface I {}\n" + }, + "" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83901 +public void test072() { + this.runConformTest( // implement inherited method + new String[] { + "X2.java", + "public enum X2 implements I {\n" + + " ;\n" + + " public void test() {}\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "" + ); + this.runConformTest( // implement inherited method with constant + new String[] { + "X2a.java", + "public enum X2a implements I {\n" + + " A;\n" + + " public void test() {}\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "" + ); + this.runConformTest( // implement inherited method with constant body + new String[] { + "X2b.java", + "public enum X2b implements I {\n" + + " A() { public void test() {} };\n" + + " public void test() {}\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "" + ); + this.runConformTest( // implement inherited method with random constant body + new String[] { + "X2c.java", + "public enum X2c implements I {\n" + + " A() { void random() {} };\n" + + " public void test() {}\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83901 +public void test073() { + this.runNegativeTest( // implement inherited method but as abstract + new String[] { + "X3.java", + "public enum X3 implements I {\n" + + " ;\n" + + " public abstract void test();\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "----------\n" + + "1. ERROR in X3.java (at line 3)\n" + + " public abstract void test();\n" + + " ^^^^^^\n" + + "The enum X3 can only define the abstract method test() if it also defines enum constants with corresponding implementations\n" + + "----------\n" + // X3 is not abstract and does not override abstract method test() in X3 + ); + this.runNegativeTest( // implement inherited method as abstract with constant + new String[] { + "X3a.java", + "public enum X3a implements I {\n" + + " A;\n" + + " public abstract void test();\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "----------\n" + + "1. ERROR in X3a.java (at line 2)\n" + + " A;\n" + + " ^\n" + + "The enum constant A must implement the abstract method test()\n" + + "----------\n" + // X3a is not abstract and does not override abstract method test() in X3a + ); + this.runConformTest( // implement inherited method as abstract with constant body + new String[] { + "X3b.java", + "public enum X3b implements I {\n" + + " A() { public void test() {} };\n" + + " public abstract void test();\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "" + ); + this.runNegativeTest( // implement inherited method as abstract with random constant body + new String[] { + "X3c.java", + "public enum X3c implements I {\n" + + " A() { void random() {} };\n" + + " public abstract void test();\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "----------\n" + + "1. ERROR in X3c.java (at line 2)\n" + + " A() { void random() {} };\n" + + " ^\n" + + "The enum constant A must implement the abstract method test()\n" + + "----------\n" + // is not abstract and does not override abstract method test() in X3c + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83901 +public void test074() { + this.runNegativeTest( // define abstract method + new String[] { + "X4.java", + "public enum X4 {\n" + + " ;\n" + + " public abstract void test();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X4.java (at line 3)\n" + + " public abstract void test();\n" + + " ^^^^^^\n" + + "The enum X4 can only define the abstract method test() if it also defines enum constants with corresponding implementations\n" + + "----------\n" + // X4 is not abstract and does not override abstract method test() in X4 + ); + this.runNegativeTest( // define abstract method with constant + new String[] { + "X4a.java", + "public enum X4a {\n" + + " A;\n" + + " public abstract void test();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X4a.java (at line 2)\n" + + " A;\n" + + " ^\n" + + "The enum constant A must implement the abstract method test()\n" + + "----------\n" + // X4a is not abstract and does not override abstract method test() in X4a + ); + this.runConformTest( // define abstract method with constant body + new String[] { + "X4b.java", + "public enum X4b {\n" + + " A() { public void test() {} };\n" + + " public abstract void test();\n" + + "}\n" + }, + "" + ); + this.runNegativeTest( // define abstract method with random constant body + new String[] { + "X4c.java", + "public enum X4c {\n" + + " A() { void random() {} };\n" + + " public abstract void test();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X4c.java (at line 2)\n" + + " A() { void random() {} };\n" + + " ^\n" + + "The enum constant A must implement the abstract method test()\n" + + "----------\n" + // is not abstract and does not override abstract method test() in X4c + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83901 +public void test075() { + this.runNegativeTest( // do not implement inherited method + new String[] { + "X5.java", + "public enum X5 implements I {\n" + + " ;\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "----------\n" + + "1. ERROR in X5.java (at line 1)\n" + + " public enum X5 implements I {\n" + + " ^^\n" + + "The type X5 must implement the inherited abstract method I.test()\n" + + "----------\n" + // X5 is not abstract and does not override abstract method test() in I + ); + this.runNegativeTest( // do not implement inherited method & have constant with no body + new String[] { + "X5a.java", + "public enum X5a implements I {\n" + + " A;\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "----------\n" + + "1. ERROR in X5a.java (at line 1)\n" + + " public enum X5a implements I {\n" + + " ^^^\n" + + "The type X5a must implement the inherited abstract method I.test()\n" + + "----------\n" + // X5a is not abstract and does not override abstract method test() in I + ); + this.runConformTest( // do not implement inherited method & have constant with body + new String[] { + "X5b.java", + "public enum X5b implements I {\n" + + " A() { public void test() {} };\n" + + " ;\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "" + ); + this.runNegativeTest( // do not implement inherited method & have constant with random body + new String[] { + "X5c.java", + "public enum X5c implements I {\n" + + " A() { void random() {} };\n" + + " ;\n" + + " private X5c() {}\n" + + "}\n" + + "interface I { void test(); }\n" + }, + "----------\n" + + "1. ERROR in X5c.java (at line 2)\n" + + " A() { void random() {} };\n" + + " ^\n" + + "The enum constant A must implement the abstract method test()\n" + + "----------\n" + // is not abstract and does not override abstract method test() in I + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 +public void test076() { // bridge method needed + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) { ((I) E.A).foo(); }\n" + + "}\n" + + "interface I { I foo(); }\n" + + "enum E implements I {\n" + + " A;\n" + + " public E foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "SUCCESS" + ); +} + +public void test077() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " E.A.bar();\n" + + " }\n" + + "}\n" + + "enum E {\n" + + " A {\n" + + " void bar() {\n" + + " new M();\n" + + " }\n" + + " };\n" + + " abstract void bar();\n" + + " \n" + + " class M {\n" + + " M() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS" + ); +} + +public void test078() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " E.A.bar();\n" + + " }\n" + + "}\n" + + "enum E {\n" + + " A {\n" + + " void bar() {\n" + + " new X(){\n" + + " void baz() {\n" + + " new M();\n" + + " }\n" + + " }.baz();\n" + + " }\n" + + " };\n" + + " abstract void bar();\n" + + " \n" + + " class M {\n" + + " M() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=85397 +public void test079() throws Exception { + String op = + this.complianceLevel < ClassFileConstants.JDK17 ? + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private strictfp X() {}\n" + + " ^^^\n" + + "Illegal modifier for the constructor in type X; only public, protected & private are permitted\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private strictfp X() {}\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " private strictfp X() {}\n" + + " ^^^\n" + + "Illegal modifier for the constructor in type X; only public, protected & private are permitted\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " A, B;\n" + + " private strictfp X() {}\n" + + "}\n" + }, + op + ); + this.runConformTest( + new String[] { + "X.java", + "public strictfp enum X {\n" + + " A, B;\n" + + " private X() {}\n" + + "}\n" + }, + "" + ); + + String[] expectedOutputs = + this.complianceLevel < ClassFileConstants.JDK17 ? + new String[] { + " private strictfp X(java.lang.String arg0, int arg1);\n", + " public static strictfp X[] values();\n", + " public static strictfp X valueOf(java.lang.String arg0);\n" + } : + new String[] { + " private X(java.lang.String arg0, int arg1);\n", + " public static X[] values();\n", + " public static X valueOf(java.lang.String arg0);\n" + }; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + for (int i = 0, max = expectedOutputs.length; i < max; i++) { + String expectedOutput = expectedOutputs[i]; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=87064 +public void test080() { + this.runConformTest( + new String[] { + "X.java", + "interface TestInterface {\n" + + " int test();\n" + + "}\n" + + "\n" + + "public enum X implements TestInterface {\n" + + " TEST {\n" + + " public int test() {\n" + + " return 42;\n" + + " }\n" + + " },\n" + + " ENUM {\n" + + " public int test() {\n" + + " return 37;\n" + + " }\n" + + " };\n" + + "} \n" + }, + "" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=87818 +public void test081() { + String expectedErrorMessage = this.complianceLevel < ClassFileConstants.JDK16 ? + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " enum E {}\n" + + " ^\n" + + "The member enum E can only be defined inside a top-level class or interface or in a static context\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " enum E {}\n" + + " Zork();\n" + + " }\n" + + "}" + }, + expectedErrorMessage); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88223 +public void test082() { + if ( this.complianceLevel < ClassFileConstants.JDK16) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " enum E {}\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " enum E {}\n" + + " ^\n" + + "The member enum E must be defined inside a static member type\n" + + "----------\n"); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " enum E {}\n" + + " }\n" + + "}" + }, + ""); + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Y {\n" + + " enum E {}\n" + + " }\n" + + "}" + }, + ""); + if ( this.complianceLevel < ClassFileConstants.JDK16) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " class Local {\n" + + " enum E {}\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " enum E {}\n" + + " ^\n" + + "The member enum E can only be defined inside a top-level class or interface or in a static context\n" + + "----------\n"); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " class Local {\n" + + " enum E {}\n" + + " }\n" + + " }\n" + + "}" + }, + ""); + } +} + + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=87998 - check no emulation warning +public void test083() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " INPUT {\n" + + " @Override\n" + + " public X getReverse() {\n" + + " return OUTPUT;\n" + + " }\n" + + " },\n" + + " OUTPUT {\n" + + " @Override\n" + + " public X getReverse() {\n" + + " return INPUT;\n" + + " }\n" + + " },\n" + + " INOUT {\n" + + " @Override\n" + + " public X getReverse() {\n" + + " return INOUT;\n" + + " }\n" + + " };\n" + + " X(){}\n" + + " Zork z;\n" + + " public abstract X getReverse();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 21)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=87998 - check private constructor generation +public void test084() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " INPUT {\n" + + " @Override\n" + + " public X getReverse() {\n" + + " return OUTPUT;\n" + + " }\n" + + " },\n" + + " OUTPUT {\n" + + " @Override\n" + + " public X getReverse() {\n" + + " return INPUT;\n" + + " }\n" + + " },\n" + + " INOUT {\n" + + " @Override\n" + + " public X getReverse() {\n" + + " return INOUT;\n" + + " }\n" + + " };\n" + + " X(){}\n" + + " public abstract X getReverse();\n" + + "}\n", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #20 (Ljava/lang/String;I)V\n" + + " // Stack: 3, Locals: 3\n" + + " private X(java.lang.String arg0, int arg1);\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88625 +public void test085() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Test1 {\n" + + " test11, test12\n" + + " };\n" + + " enum Test2 {\n" + + " test21, test22\n" + + " };\n" + + "\n" + + " void foo1(Test1 t1, Test2 t2) {\n" + + " boolean b = t1 == t2;\n" + + " }\n" + + " void foo2(Test1 t1, Object t2) {\n" + + " boolean b = t1 == t2;\n" + + " }\n" + + " void foo3(Test1 t1, Enum t2) {\n" + + " boolean b = t1 == t2;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " boolean booleanTest = (Test1.test11 == Test2.test22);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " boolean b = t1 == t2;\n" + + " ^^^^^^^^\n" + + "Incompatible operand types X.Test1 and X.Test2\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " void foo3(Test1 t1, Enum t2) {\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " boolean booleanTest = (Test1.test11 == Test2.test22);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types X.Test1 and X.Test2\n" + + "----------\n"); +} +public void test086() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Test1 {\n" + + " V;\n" + + " static int foo = 0;\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test087() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Test1 {\n" + + " V;\n" + + " interface Foo {}\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test088() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " enum Test1 {\n" + + " V;\n" + + " }\n" + + " Object foo() {\n" + + " return this;\n" + + " }\n" + + "\n" + + " static class Sub extends X {\n" + + " @Override\n" + + " Test1 foo() {\n" + + " return Test1.V;\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test089() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " enum Test1 {\n" + + " V;\n" + + " protected final Test1 clone() { return V; }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " protected final Test1 clone() { return V; }\n" + + " ^^^^^^^\n" + + "Cannot override the final method from Enum\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " protected final Test1 clone() { return V; }\n" + + " ^^^^^^^\n" + + "The method clone() of type X.Test1 should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); +} +public void test090() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " enum Test1 {\n" + + " V;\n" + + " public Test1 foo() { return V; }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + "java/lang/Object.java", + "package java.lang;\n" + + "public class Object {\n" + + " public Object foo() { return this; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public Test1 foo() { return V; }\n" + + " ^^^^^\n" + + "The method foo() of type X.Test1 should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test091() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " enum Test1 {\n" + + " V;\n" + + " void foo() {}\n" + + " }\n" + + " class Member {\n" + + " void bar(E e) {\n" + + " e.foo();\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test092() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " enum Test1 {\n" + + " V;\n" + + " void foo() {}\n" + + " }\n" + + " class Member {\n" + + " void bar(E e) {\n" + + " e.foo();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " class Member {\n" + + " ^^^^^\n" + + "The type X.Test1 is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " e.foo();\n" + + " ^^^\n" + + "The method foo() is undefined for the type E\n" + + "----------\n"); +} +// check wildcard can extend Enum superclass +public void test093() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " enum Test1 {\n" + + " V;\n" + + " void foo() {}\n" + + " }\n" + + " class Member {\n" + + " E e;\n" + + " void bar(Member me) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +// check super bit is set +public void test094() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + "}\n", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "// Signature: Ljava/lang/Enum;\n" + + "public final enum X {\n" + + " \n" + + " // Field descriptor #6 [LX;\n" + + " private static final synthetic X[] ENUM$VALUES;\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 1, Locals: 0\n" + + " static {};\n" + + " 0 iconst_0\n" + + " 1 anewarray X [1]\n" + + " 4 putstatic X.ENUM$VALUES : X[] [10]\n" + + " 7 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " \n" + + " // Method descriptor #15 (Ljava/lang/String;I)V\n" + + " // Stack: 3, Locals: 3\n" + + " private X(java.lang.String arg0, int arg1);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 iload_2 [arg1]\n" + + " 3 invokespecial java.lang.Enum(java.lang.String, int) [16]\n" + + " 6 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 7] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #21 ()[LX;\n" + + " // Stack: 5, Locals: 3\n" + + " public static X[] values();\n" + + " 0 getstatic X.ENUM$VALUES : X[] [10]\n" + + " 3 dup\n" + + " 4 astore_0\n" + + " 5 iconst_0\n" + + " 6 aload_0\n" + + " 7 arraylength\n" + + " 8 dup\n" + + " 9 istore_1\n" + + " 10 anewarray X [1]\n" + + " 13 dup\n" + + " 14 astore_2\n" + + " 15 iconst_0\n" + + " 16 iload_1\n" + + " 17 invokestatic java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int) : void [22]\n" + + " 20 aload_2\n" + + " 21 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " \n" + + " // Method descriptor #29 (Ljava/lang/String;)LX;\n" + + " // Stack: 2, Locals: 1\n" + + " public static X valueOf(java.lang.String arg0);\n" + + " 0 ldc [1]\n" + + " 2 aload_0 [arg0]\n" + + " 3 invokestatic java.lang.Enum.valueOf(java.lang.Class, java.lang.String) : java.lang.Enum [30]\n" + + " 6 checkcast X [1]\n" + + " 9 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} +public void test095() { // check missing abstract cases from multiple interfaces + this.runNegativeTest( + new String[] { + "X.java", + "public enum X implements I, J { \n" + + " ROUGE;\n" + + "}\n" + + "interface I { void foo(); }\n" + + "interface J { void foo(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public enum X implements I, J { \n" + + " ^\n" + + "The type X must implement the inherited abstract method J.foo()\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public enum X implements I, J { \n" + + " ROUGE;\n" + + " public void foo() {}\n" + + "}\n" + + "interface I { void foo(int i); }\n" + + "interface J { void foo(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public enum X implements I, J { \n" + + " ^\n" + + "The type X must implement the inherited abstract method I.foo(int)\n" + + "----------\n"); +} +public void test096() { // check for raw vs. parameterized parameter types + this.runConformTest( + new String[] { + "X.java", + "public enum X implements I { \n" + + " ROUGE;\n" + + " public void foo(A a) {}\n" + + "}\n" + + "interface I { void foo(A a); }\n" + + "class A {}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public enum X implements I { \n" + + " ROUGE { public void foo(A a) {} }\n" + + " ;\n" + + "}\n" + + "interface I { void foo(A a); }\n" + + "class A {}\n" + }, + ""); + this.runNegativeTest( + new String[] { + "X.java", + "public enum X implements I { \n" + + " ROUGE;\n" + + " public void foo(A a) {}\n" + + "}\n" + + "interface I { void foo(A a); }\n" + + "class A {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public enum X implements I { \n" + + " ^\n" + + "The type X must implement the inherited abstract method I.foo(A)\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public void foo(A a) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) of type X has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " interface I { void foo(A a); }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=89982 +public void test097() { + this.runNegativeTest( + new String[] { + "E.java", + "public class E {\n" + + " enum Numbers { ONE, TWO, THREE }\n" + + " static final String BLANK = \" \";\n" + + " void foo(Colors color) {\n" + + " switch (color) {\n" + + " case BLUE:\n" + + " case RED:\n" + + " break;\n" + + " default: // nop\n" + + " } \n" + + " }\n" + + "}\n" + + "/**\n" + + " * Enumeration of some basic colors.\n" + + " */\n" + + "enum Colors {\n" + + " BLACK,\n" + + " WHITE,\n" + + " RED \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in E.java (at line 6)\n" + + " case BLUE:\n" + + " ^^^^\n" + + "BLUE cannot be resolved or is not a field\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=89982 - variation +public void test098() { + this.runNegativeTest( + new String[] { + "E.java", + "public class E {\n" + + " enum Numbers { ONE, TWO, THREE }\n" + + " static final String BLANK = \" \";\n" + + " void foo(Colors color) {\n" + + " switch (color) {\n" + + " } \n" + + " }\n" + + "}\n" + + "/**\n" + + " * Enumeration of some basic colors.\n" + + " */\n" + + "enum Colors {\n" + + " BLACK,\n" + + " WHITE,\n" + + " RED; \n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in E.java (at line 5)\n" + + " switch (color) {\n" + + " ^^^^^\n" + + "The enum constant BLACK needs a corresponding case label in this enum switch on Colors\n" + + "----------\n" + + "2. WARNING in E.java (at line 5)\n" + + " switch (color) {\n" + + " ^^^^^\n" + + "The enum constant RED needs a corresponding case label in this enum switch on Colors\n" + + "----------\n" + + "3. WARNING in E.java (at line 5)\n" + + " switch (color) {\n" + + " ^^^^^\n" + + "The enum constant WHITE needs a corresponding case label in this enum switch on Colors\n" + + "----------\n" + + "4. ERROR in E.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=89274 +public void test099() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {\n" + + " enum E {\n" + + " v1, v2;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends A {\n" + + " void a(A.E e) {\n" + + " b(e); // no unchecked warning\n" + + " }\n" + + "\n" + + " void b(E e) {\n" + + " A.E e1 = e;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " A.E e1 = e;\n" + + " ^^^^^^^^^^^^\n" + + "The member type A.E cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type A\n" + + "----------\n"); +} +/* from JLS +"It is a compile-time error to reference a static field of an enum type +that is not a compile-time constant (15.28) from constructors, instance +initializer blocks, or instance variable initializer expressions of that +type. It is a compile-time error for the constructors, instance initializer +blocks, or instance variable initializer expressions of an enum constant e1 +to refer to itself or an enum constant of the same type that is declared to +the right of e1." + */ +public void test100() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + "\n" + + " anEnumValue {\n" + + " private final X thisOne = anEnumValue;\n" + + "\n" + + " @Override String getMessage() {\n" + + " return \"Here is what thisOne gets assigned: \" + thisOne;\n" + + " }\n" + + " };\n" + + "\n" + + " abstract String getMessage();\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(anEnumValue.getMessage());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " private final X thisOne = anEnumValue;\n" + + " ^^^^^^^^^^^\n" + + "Cannot refer to the static enum field X.anEnumValue within an initializer\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=91761 +public void test101() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Foo {\n" + + " public boolean bar();\n" + + "}\n" + + "enum BugDemo {\n" + + " CONSTANT(new Foo() {\n" + + " public boolean bar() {\n" + + " Zork z;\n" + + " return true;\n" + + " }\n" + + " });\n" + + " BugDemo(Foo foo) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=90775 +public void test102() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " enum SomeEnum {\n" + + " A, B;\n" + + " static SomeEnum foo() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " Enum e = SomeEnum.A;\n" + + " \n" + + " Set set1 = EnumSet.of(SomeEnum.A);\n" + + " Set set2 = EnumSet.of(SomeEnum.foo());\n" + + " \n" + + " Foo foo = null;\n" + + "}\n" + + "class Foo > {\n" + + "}\n" + + "class Bar extends Foo {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " Foo foo = null;\n" + + " ^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter > of the type Foo\n" + + "----------\n" + + "2. WARNING in X.java (at line 19)\n" + + " class Bar extends Foo {\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=93396 +public void test103() { + this.runNegativeTest( + new String[] { + "BadEnum.java", + "public class BadEnum {\n" + + " public interface EnumInterface {\n" + + " public T getMethod();\n" + + " }\n" + + " public enum EnumClass implements EnumInterface {\n" + + " ENUM1 { public String getMethod() { return \"ENUM1\";} },\n" + + " ENUM2 { public String getMethod() { return \"ENUM2\";} };\n" + + " }\n" + + "}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in BadEnum.java (at line 10)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=90215 +public void test104() { + this.runConformTest( + new String[] { + "p/Placeholder.java", + "package p;\n" + + "\n" + + "public class Placeholder {\n" + + " public static void main(String... argv) {\n" + + " ClassWithBadEnum.EnumClass constant = ClassWithBadEnum.EnumClass.ENUM1;\n" + // forward ref + " ClassWithBadEnum.main(argv);\n" + + " }\n" + + "} \n" + + "\n", + "p/ClassWithBadEnum.java", + "package p;\n" + + "\n" + + "public class ClassWithBadEnum {\n" + + " public interface EnumInterface {\n" + + " public T getMethod();\n" + + " }\n" + + "\n" + + " public enum EnumClass implements EnumInterface {\n" + + " ENUM1 { public String getMethod() { return \"ENUM1\";} },\n" + + " ENUM2 { public String getMethod() { return \"ENUM2\";} };\n" + + " }\n" + + " private EnumClass enumVar; \n" + + " public EnumClass getEnumVar() {\n" + + " return enumVar;\n" + + " }\n" + + " public void setEnumVar(EnumClass enumVar) {\n" + + " this.enumVar = enumVar;\n" + + " }\n" + + "\n" + + " public static void main(String... argv) {\n" + + " int a = 1;\n" + + " ClassWithBadEnum badEnum = new ClassWithBadEnum();\n" + + " badEnum.setEnumVar(ClassWithBadEnum.EnumClass.ENUM1);\n" + + " // Should fail if bug manifests itself because there will be two getInternalValue() methods\n" + + " // one returning an Object instead of a String\n" + + " String s3 = badEnum.getEnumVar().getMethod();\n" + + " System.out.println(s3);\n" + + " }\n" + + "} \n", + }, + "ENUM1"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void test105() { + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "Black" + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {BLACK, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "Black", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void test106() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " }\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "SUCCESS", + null, + true, + null, + options, + null + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {BLACK, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "SUCCESS", + null, + false, + null, + null, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void test107() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "BlackBlack", + null, + true, + null, + options, + null + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color { BLACK }" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "BlackBlack", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void test108() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " default:\n" + + " System.out.print(\"Error\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "Black", + null, + true, + null, + options, + null + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {RED, GREEN, YELLOW, BLACK, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "Black", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void test109() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Color c = null;\n" + + " try {\n" + + " c = BLACK;\n" + + " } catch(NoSuchFieldError e) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "Black", + null, + true, + null, + options, + null + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {RED, GREEN, YELLOW, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "SUCCESS", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void test110() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public int[] $SWITCH_TABLE$pack$Color;\n" + + " public int[] $SWITCH_TABLE$pack$Color() { return null; }\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "Black", + null, + true, + null, + options, + null + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {BLACK, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "Black", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void test111() { + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "@SuppressWarnings(\"incomplete-switch\")\n" + + "public class X {\n" + + " public int[] $SWITCH_TABLE$pack$Color;\n" + + " public int[] $SWITCH_TABLE$pack$Color() { return null; }\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "BlackBlack" + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {BLACK, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "BlackBlack", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97247 +public void test112() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "com/annot/Foo.java", + "package com.annot;\n" + + "\n" + + "import static com.annot.TestType.*;\n" + + "\n" + + "public class Foo {\n" + + " @Test(type=PERFORMANCE)\n" + + " public void testBar() throws Exception {\n" + + " Test annotation = this.getClass().getMethod(\"testBar\").getAnnotation(Test.class);\n" + + " switch (annotation.type()) {\n" + + " case PERFORMANCE:\n" + + " System.out.println(PERFORMANCE);\n" + + " break;\n" + + " case CORRECTNESS:\n" + + " System.out.println(CORRECTNESS);\n" + + " break;\n" + + " } \n" + + " }\n" + + "}", + "com/annot/Test.java", + "package com.annot;\n" + + "\n" + + "import static com.annot.TestType.CORRECTNESS;\n" + + "import static java.lang.annotation.ElementType.METHOD;\n" + + "\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(METHOD)\n" + + "public @interface Test {\n" + + " TestType type() default CORRECTNESS;\n" + + "}", + "com/annot/TestType.java", + "package com.annot;\n" + + "\n" + + "public enum TestType {\n" + + " CORRECTNESS,\n" + + " PERFORMANCE\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=93789 +public void test113() { + if (this.complianceLevel >= ClassFileConstants.JDK16) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "enum BugDemo {\n" + + " FOO() {\n" + + " static int bar;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " static int bar;\n" + + " ^^^\n" + + "The field bar cannot be declared static in a non-static inner type, unless initialized with a constant expression\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99428 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=99655 +public void test114() { + this.runConformTest( + new String[] { + "EnumTest.java", + "import java.lang.reflect.*;\n" + + "import java.lang.annotation.*;\n" + + "@ExpectedModifiers(Modifier.FINAL)\n" + + "public enum EnumTest {\n" + + " X(255);\n" + + " EnumTest(int r) {}\n" + + " public static void main(String argv[]) throws Exception {\n" + + " test(\"EnumTest\");\n" + + " test(\"EnumTest$EnumA\");\n" + + " test(\"EnumTest$EnumB\");\n" + + " test(\"EnumTest$EnumB2\");\n" + + " test(\"EnumTest$EnumB3\");\n" + + // TODO (kent) need verifier to detect when an Enum should be tagged as abstract + //" test(\"EnumTest$EnumC\");\n" + + //" test(\"EnumTest$EnumC2\");\n" + + " test(\"EnumTest$EnumC3\");\n" + + " test(\"EnumTest$EnumD\");\n" + + " }\n" + + " static void test(String className) throws Exception {\n" + + " Class c = Class.forName(className);\n" + + " ExpectedModifiers em = (ExpectedModifiers) c.getAnnotation(ExpectedModifiers.class);\n" + + " if (em != null) {\n" + + " int classModifiers = c.getModifiers();\n" + + " int expected = em.value();\n" + + " if (expected != (classModifiers & (Modifier.ABSTRACT|Modifier.FINAL|Modifier.STATIC))) {\n" + + " if ((expected & Modifier.ABSTRACT) != (classModifiers & Modifier.ABSTRACT))\n" + + " System.out.println(\"FAILED ABSTRACT: \" + className);\n" + + " if ((expected & Modifier.FINAL) != (classModifiers & Modifier.FINAL))\n" + + " System.out.println(\"FAILED FINAL: \" + className);\n" + + " if ((expected & Modifier.STATIC) != (classModifiers & Modifier.STATIC))\n" + + " System.out.println(\"FAILED STATIC: \" + className);\n" + + " }\n" + + " }\n" + + " }\n" + + " @ExpectedModifiers(Modifier.FINAL|Modifier.STATIC)\n" + + " enum EnumA {\n" + + " A;\n" + + " }\n" + + " @ExpectedModifiers(Modifier.STATIC)\n" + + " enum EnumB {\n" + + " B {\n" + + " int value() { return 1; }\n" + + " };\n" + + " int value(){ return 0; }\n" + + " }\n" + + " @ExpectedModifiers(Modifier.STATIC)\n" + + " enum EnumB2 {\n" + + " B2 {};\n" + + " int value(){ return 0; }\n" + + " }\n" + + " @ExpectedModifiers(Modifier.FINAL|Modifier.STATIC)\n" + + " enum EnumB3 {\n" + + " B3;\n" + + " int value(){ return 0; }\n" + + " }\n" + + " @ExpectedModifiers(Modifier.STATIC)\n" + + " enum EnumC implements I {\n" + + " C {\n" + + " int value() { return 1; }\n" + + " };\n" + + " int value(){ return 0; }\n" + + " public void foo(){}\n" + + " }\n" + + " @ExpectedModifiers(Modifier.STATIC)\n" + + " enum EnumC2 implements I {\n" + + " C2 {};\n" + + " int value(){ return 0; }\n" + + " public void foo(){}\n" + + " }\n" + + " @ExpectedModifiers(Modifier.FINAL|Modifier.STATIC)\n" + + " enum EnumC3 implements I {\n" + + " C3;\n" + + " int value(){ return 0; }\n" + + " public void foo(){}\n" + + " }\n" + + " @ExpectedModifiers(Modifier.ABSTRACT|Modifier.STATIC)\n" + + " enum EnumD {\n" + + " D {\n" + + " int value() { return 1; }\n" + + " };\n" + + " abstract int value();\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void foo();\n" + + "}\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface ExpectedModifiers {\n" + + " int value();\n" + + "}" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101713 +public void test115() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " VALUE;\n" + + "\n" + + " static int ASD;\n" + + " final static int CST = 0;\n" + + " \n" + + " private X() {\n" + + " VALUE = null;\n" + + " ASD = 5;\n" + + " X.VALUE = null;\n" + + " X.ASD = 5;\n" + + " \n" + + " System.out.println(CST);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " VALUE = null;\n" + + " ^^^^^\n" + + "Cannot refer to the static enum field X.VALUE within an initializer\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " ASD = 5;\n" + + " ^^^\n" + + "Cannot refer to the static enum field X.ASD within an initializer\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " X.VALUE = null;\n" + + " ^^^^^\n" + + "Cannot refer to the static enum field X.VALUE within an initializer\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " X.ASD = 5;\n" + + " ^^^\n" + + "Cannot refer to the static enum field X.ASD within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101713 - variation +public void test116() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X { \n" + + " BLEU, \n" + + " BLANC, \n" + + " ROUGE;\n" + + " {\n" + + " BLEU = null;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " BLEU = null;\n" + + " ^^^^\n" + + "Cannot refer to the static enum field X.BLEU within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101713 - variation +public void test117() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X { \n" + + " BLEU, \n" + + " BLANC, \n" + + " ROUGE;\n" + + " {\n" + + " X x = BLEU.BLANC; // ko\n" + + " X x2 = BLEU; // ko\n" + + " }\n" + + " static {\n" + + " X x = BLEU.BLANC; // ok\n" + + " X x2 = BLEU; // ok\n" + + " } \n" + + " X dummy = BLEU; // ko\n" + + " static X DUMMY = BLANC; // ok\n" + + " X() {\n" + + " X x = BLEU.BLANC; // ko\n" + + " X x2 = BLEU; // ko\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X x = BLEU.BLANC; // ko\n" + + " ^^^^\n" + + "Cannot refer to the static enum field X.BLEU within an initializer\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X x = BLEU.BLANC; // ko\n" + + " ^^^^^\n" + + "Cannot refer to the static enum field X.BLANC within an initializer\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " X x = BLEU.BLANC; // ko\n" + + " ^^^^^\n" + + "The static field X.BLANC should be accessed in a static way\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " X x2 = BLEU; // ko\n" + + " ^^^^\n" + + "Cannot refer to the static enum field X.BLEU within an initializer\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " X x = BLEU.BLANC; // ok\n" + + " ^^^^^\n" + + "The static field X.BLANC should be accessed in a static way\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " X dummy = BLEU; // ko\n" + + " ^^^^\n" + + "Cannot refer to the static enum field X.BLEU within an initializer\n" + + "----------\n" + + "7. ERROR in X.java (at line 16)\n" + + " X x = BLEU.BLANC; // ko\n" + + " ^^^^\n" + + "Cannot refer to the static enum field X.BLEU within an initializer\n" + + "----------\n" + + "8. ERROR in X.java (at line 16)\n" + + " X x = BLEU.BLANC; // ko\n" + + " ^^^^^\n" + + "Cannot refer to the static enum field X.BLANC within an initializer\n" + + "----------\n" + + "9. WARNING in X.java (at line 16)\n" + + " X x = BLEU.BLANC; // ko\n" + + " ^^^^^\n" + + "The static field X.BLANC should be accessed in a static way\n" + + "----------\n" + + "10. ERROR in X.java (at line 17)\n" + + " X x2 = BLEU; // ko\n" + + " ^^^^\n" + + "Cannot refer to the static enum field X.BLEU within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=102265 +public void test118() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public enum X {\n" + + " one,\n" + + " two;\n" + + " \n" + + " static ArrayList someList;\n" + + " \n" + + " private X() {\n" + + " if (someList == null) {\n" + + " someList = new ArrayList();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " static ArrayList someList;\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " if (someList == null) {\n" + + " ^^^^^^^^\n" + + "Cannot refer to the static enum field X.someList within an initializer\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " someList = new ArrayList();\n" + + " ^^^^^^^^\n" + + "Cannot refer to the static enum field X.someList within an initializer\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " someList = new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"); +} +public void test119() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " BLEU, BLANC, ROUGE;\n" + + " final static int CST = 0;\n" + + " enum Member {\n" + + " ;\n" + + " Object obj1 = CST;\n" + + " Object obj2 = BLEU;\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=102213 +public void test120() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + "\n" + + " A() {\n" + + " final X a = A;\n" + + " final X a2 = B.A;\n" + + " @Override void foo() {\n" + + " System.out.println(String.valueOf(a));\n" + + " System.out.println(String.valueOf(a2));\n" + + " }\n" + + " },\n" + + " B() {\n" + + " @Override void foo(){}\n" + + " };\n" + + " abstract void foo();\n" + + "\n" + + " public static void main(String[] args) {\n" + + " A.foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " final X a = A;\n" + + " ^\n" + + "Cannot refer to the static enum field X.A within an initializer\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " final X a2 = B.A;\n" + + " ^\n" + + "Cannot refer to the static enum field X.B within an initializer\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " final X a2 = B.A;\n" + + " ^\n" + + "Cannot refer to the static enum field X.A within an initializer\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " final X a2 = B.A;\n" + + " ^\n" + + "The static field X.A should be accessed in a static way\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=92165 +public void test121() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + "\n" + + " UNKNOWN();\n" + + "\n" + + " private static String error;\n" + + "\n" + + " {\n" + + " error = \"error\";\n" + + " }\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " error = \"error\";\n" + + " ^^^^^\n" + + "Cannot refer to the static enum field X.error within an initializer\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105592 +public void test122() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public enum State {\n" + + " NORMAL\n" + + " }\n" + + " public void foo() {\n" + + " State state = State.NORMAL;\n" + + " switch (state) {\n" + + " case (NORMAL) :\n" + + " System.out.println(State.NORMAL);\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " case (NORMAL) :\n" + + " ^^^^^^^^\n" + + "Enum constants cannot be surrounded by parenthesis\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110403 +public void test123() { + this.runNegativeTest( + new String[] { + "Foo.java", + "enum Foo {\n" + + " A(0);\n" + + " Foo(int x) {\n" + + " t[0]=x;\n" + + " }\n" + + " private static final int[] t = new int[12];\n" + + "}", + }, + "----------\n" + + "1. ERROR in Foo.java (at line 4)\n" + + " t[0]=x;\n" + + " ^\n" + + "Cannot refer to the static enum field Foo.t within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=1101417 +public void test124() { + this.runNegativeTest( + new String[] { + "X.java", + " public enum X {\n" + + " max {\n" + + " { \n" + + " val=3; \n" + + " } \n" + + " @Override public String toString() {\n" + + " return Integer.toString(val);\n" + + " }\n" + + " }; \n" + + " {\n" + + " val=2;\n" + + " }\n" + + " private int val; \n" + + " public static void main(String[] args) {\n" + + " System.out.println(max); // 3\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " val=3; \n" + + " ^^^\n" + + "Cannot make a static reference to the non-static field val\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " return Integer.toString(val);\n" + + " ^^^\n" + + "Cannot make a static reference to the non-static field val\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112231 +public void test125() { + this.runNegativeTest( + new String[] { + "X.java", + "\n" + + "public class X {\n" + + " interface I {\n" + + " int values();\n" + + " enum E implements I {\n" + + " A, B, C;\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " enum E implements I {\n" + + " ^\n" + + "This static method cannot hide the instance method from X.I\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126087 +public void test126() { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " enum NoValues {}\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"[\"+NoValues.values().length+\"]\");\n" + + " }\n" + + " }\n" + }, + "[0]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126087 +public void test127() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " VALUE {\n" + + " void foo() {\n" + + " };\n" + + " };\n" + + " abstract void foo();\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"[\"+X.values().length+\"]\");\n" + + " }\n" + + "}" + }, + "[1]"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " private static final synthetic X[] ENUM$VALUES;\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } + + disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X$1.class")); + actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + expectedOutput = + "ENUM$VALUES"; + + index = actualOutput.indexOf(expectedOutput); + if (index != -1) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index != -1) { + assertTrue("Must not have field ENUM$VALUES", false); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127766 +public void test128() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main( String[] args) {\n" + + " Enum e = new Enum(\"foo\", 2) {\n" + + " public int compareTo( Object o) {\n" + + " return 0;\n" + + " }\n" + + " };\n" + + " System.out.println(e);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Enum e = new Enum(\"foo\", 2) {\n" + + " ^^^^\n" + + "The type new Enum(){} may not subclass Enum explicitly\n" + + "----------\n", + null, + true, + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=141155 +public void test129() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " A, B, C;\n" + + "}\n", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "// Signature: Ljava/lang/Enum;\n" + + "public final enum X {\n" + + " \n" + + " // Field descriptor #6 LX;\n" + + " public static final enum X A;\n" + + " \n" + + " // Field descriptor #6 LX;\n" + + " public static final enum X B;\n" + + " \n" + + " // Field descriptor #6 LX;\n" + + " public static final enum X C;\n" + + " \n" + + " // Field descriptor #10 [LX;\n" + + " private static final synthetic X[] ENUM$VALUES;\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 4, Locals: 0\n" + + " static {};\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 ldc [14]\n" + + " 6 iconst_0\n" + + " 7 invokespecial X(java.lang.String, int) [15]\n" + + " 10 putstatic X.A : X [19]\n" + + " 13 new X [1]\n" + + " 16 dup\n" + + " 17 ldc [21]\n" + + " 19 iconst_1\n" + + " 20 invokespecial X(java.lang.String, int) [15]\n" + + " 23 putstatic X.B : X [22]\n" + + " 26 new X [1]\n" + + " 29 dup\n" + + " 30 ldc [24]\n" + + " 32 iconst_2\n" + + " 33 invokespecial X(java.lang.String, int) [15]\n" + + " 36 putstatic X.C : X [25]\n" + + " 39 iconst_3\n" + + " 40 anewarray X [1]\n" + + " 43 dup\n" + + " 44 iconst_0\n" + + " 45 getstatic X.A : X [19]\n" + + " 48 aastore\n" + + " 49 dup\n" + + " 50 iconst_1\n" + + " 51 getstatic X.B : X [22]\n" + + " 54 aastore\n" + + " 55 dup\n" + + " 56 iconst_2\n" + + " 57 getstatic X.C : X [25]\n" + + " 60 aastore\n" + + " 61 putstatic X.ENUM$VALUES : X[] [27]\n" + + " 64 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " [pc: 39, line: 1]\n" + + " \n" + + " // Method descriptor #18 (Ljava/lang/String;I)V\n" + + " // Stack: 3, Locals: 3\n" + + " private X(java.lang.String arg0, int arg1);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 iload_2 [arg1]\n" + + " 3 invokespecial java.lang.Enum(java.lang.String, int) [31]\n" + + " 6 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 7] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #34 ()[LX;\n" + + " // Stack: 5, Locals: 3\n" + + " public static X[] values();\n" + + " 0 getstatic X.ENUM$VALUES : X[] [27]\n" + + " 3 dup\n" + + " 4 astore_0\n" + + " 5 iconst_0\n" + + " 6 aload_0\n" + + " 7 arraylength\n" + + " 8 dup\n" + + " 9 istore_1\n" + + " 10 anewarray X [1]\n" + + " 13 dup\n" + + " 14 astore_2\n" + + " 15 iconst_0\n" + + " 16 iload_1\n" + + " 17 invokestatic java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int) : void [35]\n" + + " 20 aload_2\n" + + " 21 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " \n" + + " // Method descriptor #42 (Ljava/lang/String;)LX;\n" + + " // Stack: 2, Locals: 1\n" + + " public static X valueOf(java.lang.String arg0);\n" + + " 0 ldc [1]\n" + + " 2 aload_0 [arg0]\n" + + " 3 invokestatic java.lang.Enum.valueOf(java.lang.Class, java.lang.String) : java.lang.Enum [43]\n" + + " 6 checkcast X [1]\n" + + " 9 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + "}"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=141810 +public void test130() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for(Action a : Action.values()) {\n" + + " switch(a) {\n" + + " case ONE:\n" + + " System.out.print(\"1\");\n" + + " break;\n" + + " case TWO:\n" + + " System.out.print(\"2\");\n" + + " break;\n" + + " default:\n" + + " System.out.print(\"default\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "Action.java", + "enum Action { ONE, TWO }" + }, + "12" + ); + + this.runConformTest( + new String[] { + "Action.java", + "enum Action {ONE, TWO, THREE}" + }, + "", + null, + false, + null + ); + + executeClass( + "X.java", + "12default", + null, + false, + null, + null, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=145732 +public void test131() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " //A,B\n" + + " ;\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(X.valueOf(null));\n" + + " } catch (NullPointerException e) {\n" + + " System.out.println(\"NullPointerException\");\n" + + " } catch (IllegalArgumentException e) {\n" + + " System.out.println(\"IllegalArgumentException\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "NullPointerException"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=145732 - variation +public void test132() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " A,B\n" + + " ;\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(X.valueOf(null));\n" + + " } catch (NullPointerException e) {\n" + + " System.out.println(\"NullPointerException\");\n" + + " } catch (IllegalArgumentException e) {\n" + + " System.out.println(\"IllegalArgumentException\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "NullPointerException"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=147747 +public void test133() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " A, B, C;\n" + + " public static void main(String[] args) {}\n" + + "}\n", + }, + ""); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #12 ()V\n" + + " // Stack: 4, Locals: 0\n" + + " static {};\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 ldc [14]\n" + + " 6 iconst_0\n" + + " 7 invokespecial X(java.lang.String, int) [15]\n" + + " 10 putstatic X.A : X [19]\n" + + " 13 new X [1]\n" + + " 16 dup\n" + + " 17 ldc [21]\n" + + " 19 iconst_1\n" + + " 20 invokespecial X(java.lang.String, int) [15]\n" + + " 23 putstatic X.B : X [22]\n" + + " 26 new X [1]\n" + + " 29 dup\n" + + " 30 ldc [24]\n" + + " 32 iconst_2\n" + + " 33 invokespecial X(java.lang.String, int) [15]\n" + + " 36 putstatic X.C : X [25]\n" + + " 39 iconst_3\n" + + " 40 anewarray X [1]\n" + + " 43 dup\n" + + " 44 iconst_0\n" + + " 45 getstatic X.A : X [19]\n" + + " 48 aastore\n" + + " 49 dup\n" + + " 50 iconst_1\n" + + " 51 getstatic X.B : X [22]\n" + + " 54 aastore\n" + + " 55 dup\n" + + " 56 iconst_2\n" + + " 57 getstatic X.C : X [25]\n" + + " 60 aastore\n" + + " 61 putstatic X.ENUM$VALUES : X[] [27]\n" + + " 64 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " [pc: 39, line: 1]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149042 +public void test134() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " INITIAL ,\n" + + " OPENED {\n" + + " {\n" + + " System.out.printf(\"After the %s constructor\\n\",INITIAL);\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.printf(\"After the %s constructor\\n\",INITIAL);\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field X.INITIAL within an initializer\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149562 +// a default case is required to consider that b is initialized (in case E +// takes new values in the future) +public void test135() { + this.runNegativeTest( + new String[] { + "E.java", + "public enum E {\n" + + " A,\n" + + " B\n" + + "}", + "X.java", + "public class X {\n" + + " boolean foo(E e) {\n" + + " boolean b;\n" + + " switch (e) {\n" + + " case A:\n" + + " b = true;\n" + + " break;\n" + + " case B:\n" + + " b = false;\n" + + " break;\n" + + " }\n" + + " return b;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " return b;\n" + + " ^\n" + + "The local variable b may not have been initialized. Note that a problem regarding missing 'default:' on 'switch' has been suppressed, which is perhaps related to this problem\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=151368 +public void test136() { + this.runConformTest( + new String[] { + "X.java", + "import p.BeanName;\n" + + "public class X {\n" + + " Object o = BeanName.CreateStepApiOperation;\n" + + "}", + "p/BeanName.java", + "package p;\n" + + "public enum BeanName {\n" + + "\n" + + " //~ Enum constants ---------------------------------------------------------\n" + + "\n" + + " AbortAllJobsOperation,\n" + + " AbortJobApiOperation,\n" + + " AbortStepOperation,\n" + + " AclVoter,\n" + + " AcquireNamedLockApiOperation,\n" + + " AuthenticationManager,\n" + + " BeginStepOperation,\n" + + " CloneApiOperation,\n" + + " CommanderDao,\n" + + " CommanderServer,\n" + + " ConfigureQuartzOperation,\n" + + " CreateAclEntryApiOperation,\n" + + " CreateActualParameterApiOperation,\n" + + " CreateFormalParameterApiOperation,\n" + + " CreateProcedureApiOperation,\n" + + " CreateProjectApiOperation,\n" + + " CreateResourceApiOperation,\n" + + " CreateScheduleApiOperation,\n" + + " CreateStepApiOperation,\n" + + " DeleteAclEntryApiOperation,\n" + + " DeleteActualParameterApiOperation,\n" + + " DeleteFormalParameterApiOperation,\n" + + " DeleteJobApiOperation,\n" + + " DeleteProcedureApiOperation,\n" + + " DeleteProjectApiOperation,\n" + + " DeletePropertyApiOperation,\n" + + " DeleteResourceApiOperation,\n" + + " DeleteScheduleApiOperation,\n" + + " DeleteStepApiOperation,\n" + + " DispatchApiRequestOperation,\n" + + " DumpStatisticsApiOperation,\n" + + " ExpandJobStepAction,\n" + + " ExportApiOperation,\n" + + " FinishStepOperation,\n" + + " GetAccessApiOperation,\n" + + " GetAclEntryApiOperation,\n" + + " GetActualParameterApiOperation,\n" + + " GetActualParametersApiOperation,\n" + + " GetFormalParameterApiOperation,\n" + + " GetFormalParametersApiOperation,\n" + + " GetJobDetailsApiOperation,\n" + + " GetJobInfoApiOperation,\n" + + " GetJobStatusApiOperation,\n" + + " GetJobStepDetailsApiOperation,\n" + + " GetJobStepStatusApiOperation,\n" + + " GetJobsApiOperation,\n" + + " GetProcedureApiOperation,\n" + + " GetProceduresApiOperation,\n" + + " GetProjectApiOperation,\n" + + " GetProjectsApiOperation,\n" + + " GetPropertiesApiOperation,\n" + + " GetPropertyApiOperation,\n" + + " GetResourceApiOperation,\n" + + " GetResourcesApiOperation,\n" + + " GetResourcesInPoolApiOperation,\n" + + " GetScheduleApiOperation,\n" + + " GetSchedulesApiOperation,\n" + + " GetStepApiOperation,\n" + + " GetStepsApiOperation,\n" + + " GetVersionsApiOperation,\n" + + " GraphWorkflowApiOperation,\n" + + " HibernateFlushListener,\n" + + " ImportApiOperation,\n" + + " IncrementPropertyApiOperation,\n" + + " InvokeCommandOperation,\n" + + " InvokePostProcessorOperation,\n" + + " LoginApiOperation,\n" + + " LogManager,\n" + + " LogMessageApiOperation,\n" + + " ModifyAclEntryApiOperation,\n" + + " ModifyActualParameterApiOperation,\n" + + " ModifyFormalParameterApiOperation,\n" + + " ModifyProcedureApiOperation,\n" + + " ModifyProjectApiOperation,\n" + + " ModifyPropertyApiOperation,\n" + + " ModifyResourceApiOperation,\n" + + " ModifyScheduleApiOperation,\n" + + " ModifyStepApiOperation,\n" + + " MoveStepApiOperation,\n" + + " PauseSchedulerApiOperation,\n" + + " QuartzQueue,\n" + + " QuartzScheduler,\n" + + " ReleaseNamedLockApiOperation,\n" + + " ResourceInvoker,\n" + + " RunProcedureApiOperation,\n" + + " RunQueryApiOperation,\n" + + " SaxReader,\n" + + " ScheduleStepsOperation,\n" + + " SessionCache,\n" + + " SetJobNameApiOperation,\n" + + " SetPropertyApiOperation,\n" + + " SetStepStatusAction,\n" + + " StartWorkflowOperation,\n" + + " StateRefreshOperation,\n" + + " StepCompletionPrecondition,\n" + + " StepOutcomePrecondition,\n" + + " StepScheduler,\n" + + " TemplateOperation,\n" + + " TimeoutWatchdog,\n" + + " UpdateConfigurationOperation,\n" + + " Workspace,\n" + + " XmlRequestHandler;\n" + + "\n" + + " //~ Static fields/initializers ---------------------------------------------\n" + + "\n" + + " public static final int MAX_BEAN_NAME_LENGTH = 33;\n" + + "\n" + + " //~ Methods ----------------------------------------------------------------\n" + + "\n" + + " /**\n" + + " * Get this bean name as a property name, i.e. uncapitalized.\n" + + " *\n" + + " * @return String\n" + + " */\n" + + " public String getPropertyName()\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n", // =================, + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156540 +public void test137() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " interface Interface {\n" + + " public int value();\n" + + " }\n" + + "\n" + + " public enum MyEnum implements Interface {\n" + + " ;\n" + + "\n" + + " MyEnum(int value) { this.value = value; } \n" + + " public int value() { return this.value; }\n" + + "\n" + + " private int value;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(MyEnum.values().length);\n" + + " }\n" + + "}", // =================, + }, + "0"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156591 +public void test138() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " PLUS {\n" + + " double eval(double x, double y) {\n" + + " return x + y;\n" + + " }\n" + + " },\n" + + " MINUS {\n" + + " @Override\n" + + " abstract double eval(double x, double y);\n" + + " };\n" + + " abstract double eval(double x, double y);\n" + + "}\n" + + "\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " double eval(double x, double y) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method eval(double, double) of type new X(){} should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " MINUS {\n" + + " ^^^^^\n" + + "The enum constant MINUS cannot define abstract methods\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " abstract double eval(double x, double y);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method eval cannot be abstract in the enum constant MINUS\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156591 - variation +public void test139() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " PLUS {\n" + + " double eval(double x, double y) {\n" + + " return x + y;\n" + + " }\n" + + " },\n" + + " MINUS {\n" + + " abstract double eval2(double x, double y);\n" + + " };\n" + + "\n" + + " abstract double eval(double x, double y);\n" + + "}\n" + + "\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " double eval(double x, double y) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method eval(double, double) of type new X(){} should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " MINUS {\n" + + " ^^^^^\n" + + "The enum constant MINUS cannot define abstract methods\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " MINUS {\n" + + " ^^^^^\n" + + "The enum constant MINUS must implement the abstract method eval(double, double)\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " abstract double eval2(double x, double y);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method eval2 cannot be abstract in the enum constant MINUS\n" + + "----------\n" + ); +} +//check final modifier +public void test140() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " PLUS {/*ANONYMOUS*/}, MINUS;\n" + + " void bar(X x) {\n" + + " Runnable r = (Runnable)x;\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//check final modifier +public void test141() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " PLUS, MINUS;\n" + + " void bar(X x) {\n" + + " Runnable r = (Runnable)x;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Runnable r = (Runnable)x;\n" + + " ^^^^^^^^^^^\n" + + "Cannot cast from X to Runnable\n" + + "----------\n"); +} +public void test142() { + this.runConformTest( + new String[] { + "X.java", + "enum Week {\n" + + " Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " new X().bar(); \n" + + " }\n" + + " void foo() {\n" + + " for (Week w : Week.values())\n" + + " System.out.print(w + \" \");\n" + + " }\n" + + " void bar() {\n" + + " for (Week w : java.util.EnumSet.range(Week.Monday, Week.Friday)) {\n" + + " System.out.print(w + \" \");\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "Monday Tuesday Wednesday Thursday Friday Saturday Sunday Monday Tuesday Wednesday Thursday Friday"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=166866 +public void test143() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " A {\n" + + " @Override\n" + + " public String toString() {\n" + + " return a();\n" + + " }\n" + + " public abstract String a();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " A {\n" + + " ^\n" + + "The enum constant A cannot define abstract methods\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public abstract String a();\n" + + " ^^^\n" + + "The method a cannot be abstract in the enum constant A\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186822 +public void test144() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public enum X {}\n" + + " ^\n" + + "Syntax error, enum declaration cannot have type parameters\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186822 +public void test145() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "EnumA.java", + "public enum EnumA {\n" + + " B1,\n" + + " B2;\n" + + " public void foo(){}\n" + + "}", + "ClassC.java", + "public class ClassC {\n" + + " void bar() {\n" + + " EnumA.B1.B1.foo();\n" + + " EnumA.B1.B2.foo();\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in ClassC.java (at line 3)\n" + + " EnumA.B1.B1.foo();\n" + + " ^^\n" + + "The static field EnumA.B1 should be accessed in a static way\n" + + "----------\n" + + "2. ERROR in ClassC.java (at line 4)\n" + + " EnumA.B1.B2.foo();\n" + + " ^^\n" + + "The static field EnumA.B2 should be accessed in a static way\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207915 +public void test146() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " enum MyEnum {\n" + + " A, B\n" + + " }\n" + + " final String test;\n" + + " public X(MyEnum e) { // error\n" + + " switch (e) {\n" + + " case A:\n" + + " test = \"a\";\n" + + " break;\n" + + " case B:\n" + + " test = \"a\";\n" + + " break;\n" + + " // default: test = \"unknown\"; // enabling this line fixes above error\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public X(MyEnum e) { // error\n" + + " ^^^^^^^^^^^\n" + + "The blank final field test may not have been initialized. Note that a problem regarding missing 'default:' on 'switch' has been suppressed, which is perhaps related to this problem\n" + + "----------\n"); +} +// normal error when other warning is enabled +public void test146b() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE, JavaCore.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " enum MyEnum {\n" + + " A, B\n" + + " }\n" + + " final String test;\n" + + " public X(MyEnum e) { // error\n" + + " switch (e) {\n" + + " case A:\n" + + " test = \"a\";\n" + + " break;\n" + + " case B:\n" + + " test = \"a\";\n" + + " break;\n" + + " // default: test = \"unknown\"; // enabling this line fixes above error\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public X(MyEnum e) { // error\n" + + " ^^^^^^^^^^^\n" + + "The blank final field test may not have been initialized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " switch (e) {\n" + + " ^\n" + + "The switch over the enum type X.MyEnum should have a default case\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 +public void test147() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public abstract enum E {\n" + + " SUCCESS;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 3)\n" + + " public abstract enum E {\n" + + " ^\n" + + "Illegal modifier for the member enum E; only public, protected, private & static are permitted\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "Y.java", + "import p.X;\n" + + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "null" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.Excuse.JavacHasErrorsEclipseHasNone /* javac test options */); // note that Eclipse has errors for X while javac alsore reports for X - no conflict +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation +public void test148() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public abstract enum E implements Runnable {\n" + + " SUCCESS;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 3)\n" + + " public abstract enum E implements Runnable {\n" + + " ^\n" + + "Illegal modifier for the member enum E; only public, protected, private & static are permitted\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 3)\n" + + " public abstract enum E implements Runnable {\n" + + " ^\n" + + "The type X.E must implement the inherited abstract method Runnable.run()\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "Y.java", + "import p.X;\n" + + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "null" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.Excuse.JavacHasErrorsEclipseHasNone /* javac test options */);// see prev note +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation +public void test149() throws Exception { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public enum E implements Runnable {\n" + + " SUCCESS;\n" + + " public void run(){}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Class c = E.class;\n" + + " System.out.println(c.getName() + \":\" + X.E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + "p.X$E:SUCCESS"); + + String expectedOutput = + "// Signature: Ljava/lang/Enum;Ljava/lang/Runnable;\n" + + "public static final enum p.X$E implements java.lang.Runnable {\n"; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"p" + File.separator + "X$E.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation +public void test150() throws Exception { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public enum E implements Runnable {\n" + + " SUCCESS;\n" + + " public void run(){}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Class c = E.class;\n" + + " System.out.println(c.getName() + \":\" + X.E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + "p.X$E:SUCCESS"); + + this.runConformTest( + new String[] { + "Y.java", + "import p.X;\n" + + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + "SUCCESS", + null, + false, + null); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation +public void test151() throws Exception { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public enum E implements Runnable {\n" + + " SUCCESS {};\n" + + " public void run(){}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Class c = E.class;\n" + + " System.out.println(c.getName() + \":\" + X.E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + "p.X$E:SUCCESS"); + + String expectedOutput = + "// Signature: Ljava/lang/Enum;Ljava/lang/Runnable;\n" + + "public abstract static enum p.X$E implements java.lang.Runnable {\n"; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"p" + File.separator + "X$E.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation +public void test152() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public enum E implements Runnable {\n" + + " SUCCESS {};\n" + + " public void run(){}\n" + + " }\n" + + "}\n" + }, + ""); + this.runConformTest( + new String[] { + "Y.java", + "import p.X;\n" + + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + "SUCCESS", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 +public void test153() { + this.runNegativeTest( + new String[] { + "TestEnum.java", + "public enum TestEnum {\n" + + " RED, GREEN, BLUE; \n" + + " static int test = 0; \n" + + "\n" + + " TestEnum() {\n" + + " TestEnum.test=10;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in TestEnum.java (at line 6)\n" + + " TestEnum.test=10;\n" + + " ^^^^\n" + + "Cannot refer to the static enum field TestEnum.test within an initializer\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test154() { + this.runNegativeTest( + new String[] { + "TestEnum2.java", + "public enum TestEnum2 {\n" + + " ; \n" + + " static int test = 0; \n" + + " TestEnum2() {\n" + + " TestEnum2.test=11;\n" + + " }\n" + + "}\n" + + "class X {\n" + + " static int test = 0;\n" + + " X() {\n" + + " X.test = 13;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in TestEnum2.java (at line 5)\n" + + " TestEnum2.test=11;\n" + + " ^^^^\n" + + "Cannot refer to the static enum field TestEnum2.test within an initializer\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test155() { + this.runConformTest( + new String[] { + "TestEnum.java", + "public enum TestEnum {\n" + + " RED, GREEN, BLUE; \n" + + " static int test = 0; \n" + + "}\n" + + "\n" + + "enum TestEnum2 {\n" + + " ; \n" + + " TestEnum2() {\n" + + " TestEnum.test=12;\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test156() { + this.runConformTest( + new String[] { + "TestEnum.java", + "public enum TestEnum {\n" + + " RED, GREEN, BLUE; \n" + + " static int test = 0; \n" + + "\n" + + " TestEnum() {\n" + + " new Object() {\n" + + " { TestEnum.test=10; }\n" + + " };\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test157() { + this.runNegativeTest( + new String[] { + "Foo.java", + "enum Foo {\n" + + " ONE, TWO, THREE;\n" + + " static int val = 10;\n" + + " Foo () {\n" + + " this(Foo.val);\n" + + " System.out.println(Foo.val);\n" + + " }\n" + + " Foo(int i){}\n" + + " {\n" + + " System.out.println(Foo.val);\n" + + " }\n" + + " int field = Foo.val;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 5)\n" + + " this(Foo.val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "2. ERROR in Foo.java (at line 6)\n" + + " System.out.println(Foo.val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "3. ERROR in Foo.java (at line 10)\n" + + " System.out.println(Foo.val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "4. ERROR in Foo.java (at line 12)\n" + + " int field = Foo.val;\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test158() { + this.runNegativeTest( + new String[] { + "Foo.java", + "enum Foo {\n" + + " ONE, TWO, THREE;\n" + + " static int val = 10;\n" + + " Foo () {\n" + + " this(val);\n" + + " System.out.println(val);\n" + + " }\n" + + " Foo(int i){}\n" + + " {\n" + + " System.out.println(val);\n" + + " }\n" + + " int field = val;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 5)\n" + + " this(val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "2. ERROR in Foo.java (at line 6)\n" + + " System.out.println(val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "3. ERROR in Foo.java (at line 10)\n" + + " System.out.println(val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "4. ERROR in Foo.java (at line 12)\n" + + " int field = val;\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test159() { + this.runNegativeTest( + new String[] { + "Foo.java", + "enum Foo {\n" + + " ONE, TWO, THREE;\n" + + " static int val = 10;\n" + + " Foo () {\n" + + " this(get().val);\n" + + " System.out.println(get().val);\n" + + " }\n" + + " Foo(int i){}\n" + + " {\n" + + " System.out.println(get().val);\n" + + " }\n" + + " int field = get().val;\n" + + " Foo get() { return ONE; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 5)\n" + + " this(get().val);\n" + + " ^^^\n" + + "Cannot refer to an instance method while explicitly invoking a constructor\n" + + "----------\n" + + "2. WARNING in Foo.java (at line 5)\n" + + " this(get().val);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "3. ERROR in Foo.java (at line 5)\n" + + " this(get().val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "4. WARNING in Foo.java (at line 6)\n" + + " System.out.println(get().val);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "5. ERROR in Foo.java (at line 6)\n" + + " System.out.println(get().val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "6. WARNING in Foo.java (at line 10)\n" + + " System.out.println(get().val);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "7. ERROR in Foo.java (at line 10)\n" + + " System.out.println(get().val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "8. WARNING in Foo.java (at line 12)\n" + + " int field = get().val;\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "9. ERROR in Foo.java (at line 12)\n" + + " int field = get().val;\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test160() { + this.runNegativeTest( + new String[] { + "Foo.java", + "enum Foo {\n" + + " ONE, TWO, THREE;\n" + + " static int val = 10;\n" + + " Foo () {\n" + + " this(get().val = 1);\n" + + " System.out.println(get().val = 2);\n" + + " }\n" + + " Foo(int i){}\n" + + " {\n" + + " System.out.println(get().val = 3);\n" + + " }\n" + + " int field = get().val = 4;\n" + + " Foo get() { return ONE; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 5)\n" + + " this(get().val = 1);\n" + + " ^^^\n" + + "Cannot refer to an instance method while explicitly invoking a constructor\n" + + "----------\n" + + "2. WARNING in Foo.java (at line 5)\n" + + " this(get().val = 1);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "3. ERROR in Foo.java (at line 5)\n" + + " this(get().val = 1);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "4. WARNING in Foo.java (at line 6)\n" + + " System.out.println(get().val = 2);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "5. ERROR in Foo.java (at line 6)\n" + + " System.out.println(get().val = 2);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "6. WARNING in Foo.java (at line 10)\n" + + " System.out.println(get().val = 3);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "7. ERROR in Foo.java (at line 10)\n" + + " System.out.println(get().val = 3);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "8. WARNING in Foo.java (at line 12)\n" + + " int field = get().val = 4;\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "9. ERROR in Foo.java (at line 12)\n" + + " int field = get().val = 4;\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test161() { + this.runConformTest( + new String[] { + "EnumTest1.java", + "enum EnumTest1 {\n" + + " ;\n" + + " static int foo = EnumTest2.bar;\n" + + "}\n" + + "enum EnumTest2 {\n" + + " ;\n" + + " static int bar = EnumTest1.foo;\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239225 +public void test162() { + this.runNegativeTest( + new String[] { + "Status.java", // ================= + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "public enum Status {\n" + + " GOOD((byte) 0x00), BAD((byte) 0x02);\n" + + "\n" + + " private static Map mapping;\n" + + "\n" + + " private Status(final byte newValue) {\n" + + "\n" + + " if (Status.mapping == null) {\n" + + " Status.mapping = new HashMap();\n" + + " }\n" + + "\n" + + " Status.mapping.put(newValue, this);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in Status.java (at line 11)\n" + + " if (Status.mapping == null) {\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n" + + "2. ERROR in Status.java (at line 12)\n" + + " Status.mapping = new HashMap();\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n" + + "3. ERROR in Status.java (at line 15)\n" + + " Status.mapping.put(newValue, this);\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239225 - variation +public void test163() { + this.runConformTest( + new String[] { + "Status.java", // ================= + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "enum Status {\n" + + " GOOD((byte) 0x00), BAD((byte) 0x02);\n" + + " private byte value;\n" + + " private static Map mapping;\n" + + " private Status(final byte newValue) {\n" + + " this.value = newValue;\n" + + " }\n" + + " static {\n" + + " Status.mapping = new HashMap();\n" + + " for (Status s : values()) {\n" + + " Status.mapping.put(s.value, s);\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251523 +public void test164() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public enum X {\n" + + " ;\n" + + " private X valueOf(String arg0) { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private X valueOf(String arg0) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum X already defines the method valueOf(String) implicitly\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251523 - variation +public void test165() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "class Other {\n" + + " int dupField;//1\n" + + " int dupField;//2\n" + + " int dupField;//3\n" + + " int dupField;//4\n" + + " void dupMethod(int i) {}//5\n" + + " void dupMethod(int i) {}//6\n" + + " void dupMethod(int i) {}//7\n" + + " void dupMethod(int i) {}//8\n" + + " void foo() {\n" + + " int i = dupMethod(dupField);\n" + + " }\n" + + "}\n" + + "\n" + + "public enum X {\n" + + " ;\n" + + " private X valueOf(String arg0) { return null; }//9\n" + + " private X valueOf(String arg0) { return null; }//10\n" + + " private X valueOf(String arg0) { return null; }//11\n" + + " void foo() {\n" + + " int i = valueOf(\"\");\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int dupField;//1\n" + + " ^^^^^^^^\n" + + "Duplicate field Other.dupField\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " int dupField;//2\n" + + " ^^^^^^^^\n" + + "Duplicate field Other.dupField\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " int dupField;//3\n" + + " ^^^^^^^^\n" + + "Duplicate field Other.dupField\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " int dupField;//4\n" + + " ^^^^^^^^\n" + + "Duplicate field Other.dupField\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " void dupMethod(int i) {}//5\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Duplicate method dupMethod(int) in type Other\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " void dupMethod(int i) {}//6\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Duplicate method dupMethod(int) in type Other\n" + + "----------\n" + + "7. ERROR in X.java (at line 8)\n" + + " void dupMethod(int i) {}//7\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Duplicate method dupMethod(int) in type Other\n" + + "----------\n" + + "8. ERROR in X.java (at line 9)\n" + + " void dupMethod(int i) {}//8\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Duplicate method dupMethod(int) in type Other\n" + + "----------\n" + + "9. ERROR in X.java (at line 11)\n" + + " int i = dupMethod(dupField);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from void to int\n" + + "----------\n" + + "10. ERROR in X.java (at line 17)\n" + + " private X valueOf(String arg0) { return null; }//9\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum X already defines the method valueOf(String) implicitly\n" + + "----------\n" + + "11. ERROR in X.java (at line 18)\n" + + " private X valueOf(String arg0) { return null; }//10\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum X already defines the method valueOf(String) implicitly\n" + + "----------\n" + + "12. ERROR in X.java (at line 19)\n" + + " private X valueOf(String arg0) { return null; }//11\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum X already defines the method valueOf(String) implicitly\n" + + "----------\n" + + "13. ERROR in X.java (at line 21)\n" + + " int i = valueOf(\"\");\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251814 +public void test166() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public enum X {\n" + + " ;\n" + + " private int valueOf(String arg0) { return 0; }//11\n" + + " void foo() {\n" + + " int i = valueOf(\"\");\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private int valueOf(String arg0) { return 0; }//11\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum X already defines the method valueOf(String) implicitly\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int i = valueOf(\"\");\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to int\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + // check for presence of #valueOf(...) in problem type + String expectedOutput = + "public final enum X {\n" + + " \n" + + " // Method descriptor #6 (Ljava/lang/String;I)V\n" + + " // Stack: 3, Locals: 3\n" + + " private X(java.lang.String arg0, int arg1);\n" + + " 0 new java.lang.Error [8]\n" + + " 3 dup\n" + + " 4 ldc [10]\n" + + " 6 invokespecial java.lang.Error(java.lang.String) [12]\n" + + " 9 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #20 ()V\n" + + " // Stack: 3, Locals: 1\n" + + " void foo();\n" + + " 0 new java.lang.Error [8]\n" + + " 3 dup\n" + + " 4 ldc [21]\n" + + " 6 invokespecial java.lang.Error(java.lang.String) [12]\n" + + " 9 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + "}"; + + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251814 - variation +public void test167() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public enum X {\n" + + " ;\n" + + " static int valueOf(String arg0) { return 0; }//9\n" + + " void foo() {\n" + + " int i = X.valueOf(\"\");\n" + + " }\n" + + "}\n", + "Other.java",// ================= + "public class Other {\n" + + " void foo() {\n" + + " int i = X.valueOf(\"\");\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " static int valueOf(String arg0) { return 0; }//9\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum X already defines the method valueOf(String) implicitly\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int i = X.valueOf(\"\");\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to int\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Other.java (at line 3)\n" + + " int i = X.valueOf(\"\");\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to int\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + // check consistency of problem when incremental compiling against X problemType + this.runNegativeTest( + new String[] { + "Other.java",// ================= + "public class Other {\n" + + " void foo() {\n" + + " int i = X.valueOf(\"\");\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in Other.java (at line 3)\n" + + " int i = X.valueOf(\"\");\n" + + " ^^^^^^^\n" + + "The method valueOf(Class, String) in the type Enum is not applicable for the arguments (String)\n" + + "----------\n", + null, + false, // flush output + null, + true, // generate output + false, + false); + } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255452 +public void test168() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "enum BadEnum {\n" + + " CRAZY(CRAZY), // <-- illegal forward reference reported by all compilers\n" + + " IMPOSSIBLE(BadEnum.IMPOSSIBLE); // <-- illegal forward reference (javac 1.6 only)\n" + + " private BadEnum(BadEnum self) {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " X x1 = new X(x1);//1 - WRONG\n" + + " static X X2 = new X(X.X2);//2 - OK\n" + + " X x3 = new X(this.x3);//3 - OK\n" + + " X(X x) {}\n" + + " X(int i) {}\n" + + " static int VALUE() { return 13; }\n" + + " int value() { return 14; }\n" + + "}\n" + + "class Y extends X {\n" + + " X x1 = new X(x1);//6 - WRONG\n" + + " static X X2 = new X(Y.X2);//7 - OK\n" + + " X x3 = new X(this.x3);//8 - OK\n" + + " Y(Y y) { super(y); }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " CRAZY(CRAZY), // <-- illegal forward reference reported by all compilers\n" + + " ^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " IMPOSSIBLE(BadEnum.IMPOSSIBLE); // <-- illegal forward reference (javac 1.6 only)\n" + + " ^^^^^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " X x1 = new X(x1);//1 - WRONG\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "4. WARNING in X.java (at line 17)\n" + + " X x1 = new X(x1);//6 - WRONG\n" + + " ^^\n" + + "The field Y.x1 is hiding a field from type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 17)\n" + + " X x1 = new X(x1);//6 - WRONG\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "6. WARNING in X.java (at line 18)\n" + + " static X X2 = new X(Y.X2);//7 - OK\n" + + " ^^\n" + + "The field Y.X2 is hiding a field from type X\n" + + "----------\n" + + "7. WARNING in X.java (at line 19)\n" + + " X x3 = new X(this.x3);//8 - OK\n" + + " ^^\n" + + "The field Y.x3 is hiding a field from type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255452 - variation +public void test169() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "enum BadEnum {\n" + + " NOWAY(BadEnum.NOWAY.CONST),\n" + + " INVALID(INVALID.CONST),\n" + + " WRONG(WRONG.VALUE()),\n" + + " ILLEGAL(ILLEGAL.value());\n" + + " final static int CONST = 12;\n" + + " private BadEnum(int i) {\n" + + " }\n" + + " static int VALUE() { return 13; }\n" + + " int value() { return 14; }\n" + + "}\n" + + "public class X {\n" + + " final static int CONST = 12;\n" + + " X x4 = new X(x4.CONST);//4 - WRONG\n" + + " X x5 = new X(x5.value());//5 - WRONG\n" + + " X(int i) {}\n" + + " static int VALUE() { return 13; }\n" + + " int value() { return 14; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " NOWAY(BadEnum.NOWAY.CONST),\n" + + " ^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " NOWAY(BadEnum.NOWAY.CONST),\n" + + " ^^^^^\n" + + "The static field BadEnum.CONST should be accessed in a static way\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " INVALID(INVALID.CONST),\n" + + " ^^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\n" + + " INVALID(INVALID.CONST),\n" + + " ^^^^^\n" + + "The static field BadEnum.CONST should be accessed in a static way\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " WRONG(WRONG.VALUE()),\n" + + " ^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "6. WARNING in X.java (at line 4)\n" + + " WRONG(WRONG.VALUE()),\n" + + " ^^^^^^^^^^^^^\n" + + "The static method VALUE() from the type BadEnum should be accessed in a static way\n" + + "----------\n" + + "7. ERROR in X.java (at line 5)\n" + + " ILLEGAL(ILLEGAL.value());\n" + + " ^^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "8. ERROR in X.java (at line 14)\n" + + " X x4 = new X(x4.CONST);//4 - WRONG\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "9. WARNING in X.java (at line 14)\n" + + " X x4 = new X(x4.CONST);//4 - WRONG\n" + + " ^^^^^\n" + + "The static field X.CONST should be accessed in a static way\n" + + "----------\n" + + "10. ERROR in X.java (at line 15)\n" + + " X x5 = new X(x5.value());//5 - WRONG\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=263877 +public void test170() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "enum Days {\n" + + " Monday(\"Mon\", Days.OFFSET + 0), // should not complain\n" + + " Tuesday(\"Tue\", Days.Wednesday.hashCode()), // should complain since enum constant\n" + + " Wednesday(\"Wed\", OFFSET + 2); // should complain since unqualified\n" + + " public static final int OFFSET = 0; // cannot move this above, else more errors\n" + + " Days(String abbr, int index) {\n" + + " }\n" + + "}\n" + + "\n" + + "class X {\n" + + " public static final int FOO = X.OFFSET + 0;\n" + + " public static final int BAR = OFFSET + 1;\n" + + " public static final int OFFSET = 0; // cannot move this above, else more errors\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Tuesday(\"Tue\", Days.Wednesday.hashCode()), // should complain since enum constant\n" + + " ^^^^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Wednesday(\"Wed\", OFFSET + 2); // should complain since unqualified\n" + + " ^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " public static final int BAR = OFFSET + 1;\n" + + " ^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=267670. Make sure we don't emit any unused +// warnings about enumerators. Since these could be used in indirect ways not obvious. +public void test171() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "public class X { \n" + + " private enum Colors {\n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " for (Colors c: Colors.values()) {\n" + + " System.out.print(c);\n" + + " }\n" + + " }\n" + + "}\n" + }, + null, customOptions, + "", + "BLEUBLANCROUGE", null, + JavacTestOptions.DEFAULT); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=267670. Make sure we don't emit any unused +// warnings about enumerators. Since these could be used in indirect ways not obvious. This +// test also verifies that while we don't complain about individual enumerators not being used +// we DO complain if the enumeration type itself is not used. +public void test172() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "public class X { \n" + + " private enum Greet {\n" + + " HELLO, HOWDY, BONJOUR; \n" + + " }\n" + + " private enum Colors {\n" + + " RED, BLACK, BLUE;\n"+ + " }\n" + + " private enum Complaint {" + + " WARNING, ERROR, FATAL_ERROR, PANIC;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Greet g = Greet.valueOf(\"HELLO\");\n" + + " System.out.print(g);\n" + + " Colors c = Enum.valueOf(Colors.class, \"RED\");\n" + + " System.out.print(c);\n" + + " }\n" + + "}\n" + }, + null, customOptions, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " private enum Complaint { WARNING, ERROR, FATAL_ERROR, PANIC;\n" + + " ^^^^^^^^^\n" + + "The type X.Complaint is never used locally\n" + + "----------\n", + "HELLORED", null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=273990 +public void test173() { + this.runNegativeTest( + new String[] { + "E.java", + "public enum E {\n" + + " A(E.STATIK);\n" + + " private static int STATIK = 1;\n" + + " private E(final int i) {}\n" + + "}\n", + "E2.java", + "public enum E2 {\n" + + " A(E2.STATIK);\n" + + " static int STATIK = 1;\n" + + " private E2(final int i) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in E.java (at line 2)\n" + + " A(E.STATIK);\n" + + " ^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "----------\n" + + "1. ERROR in E2.java (at line 2)\n" + + " A(E2.STATIK);\n" + + " ^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=278562 +public void test174() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "interface S {}\n" + + "enum A implements S {\n" + + " L;\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " i(A.L);\n" + + " }\n" + + " static void i(Enum enumConstant) {\n" + + " Map m = new HashMap();\n" + + " for (Enum e : enumConstant.getDeclaringClass().getEnumConstants()) {\n" + + " m.put(e.name(), e);\n" + + " }\n" + + " System.out.print(1);\n" + + " }\n" + + "}\n" + }, + "1" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=278562 +public void test175() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "interface S {}\n" + + "enum A implements S {\n" + + " L, M, N, O;\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " i(new Enum[] {A.L, A.M, A.N, A.O});\n" + + " }\n" + + " static void i(Enum[] tab) {\n" + + " Map m = new HashMap();\n" + + " for (Enum s : tab) {\n" + + " m.put(s.name(), s);\n" + + " }\n" + + " System.out.print(1);\n" + + " }\n" + + "}\n" + }, + "1" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285701 +public void test176() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " A(\"\"), B(\"SUCCESS\"), C(\"Hello\");\n" + + " \n" + + " String message;\n" + + " \n" + + " X(@Deprecated String s) {\n" + + " this.message = s;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return this.message;\n" + + " }\n" + + "}" + }, + "" + ); + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + false, + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.B);\n" + + " }\n" + + "}" + }, + null, + options, + "", + "SUCCESS", + "", + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285701 +public void test177() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " A(\"\", 0, \"A\"), B(\"SUCCESS\", 0, \"B\"), C(\"Hello\", 0, \"C\");\n" + + " \n" + + " private String message;\n" + + " private int index;\n" + + " private String name;\n" + + " \n" + + " X(@Deprecated String s, int i, @Deprecated String name) {\n" + + " this.message = s;\n" + + " this.index = i;\n" + + " this.name = name;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return this.message + this.name;\n" + + " }\n" + + "}" + }, + "" + ); + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + false, + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.B);\n" + + " }\n" + + "}" + }, + null, + options, + "", + "SUCCESSB", + "", + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285701 +public void test178() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static enum Y {\n" + + " A(\"\", 0, \"A\"), B(\"SUCCESS\", 0, \"B\"), C(\"Hello\", 0, \"C\");\n" + + " \n" + + " private String message;\n" + + " private int index;\n" + + " private String name;\n" + + " Y(@Deprecated String s, int i, @Deprecated String name) {\n" + + " this.message = s;\n" + + " this.index = i;\n" + + " this.name = name;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return this.message + this.name;\n" + + " }\n" + + " }\n" + + "}" + }, + "" + ); + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + false, + new String[] { + "Z.java", + "public class Z {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.Y.B);\n" + + " }\n" + + "}" + }, + null, + options, + "", + "SUCCESSB", + "", + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285701 +public void test179() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public enum Y {\n" + + " A(\"\", 0, \"A\"), B(\"SUCCESS\", 0, \"B\"), C(\"Hello\", 0, \"C\");\n" + + " \n" + + " private String message;\n" + + " private int index;\n" + + " private String name;\n" + + " Y(@Deprecated String s, int i, @Deprecated String name) {\n" + + " this.message = s;\n" + + " this.index = i;\n" + + " this.name = name;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return this.message + this.name;\n" + + " }\n" + + " }\n" + + "}" + }, + "" + ); + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + false, + new String[] { + "Z.java", + "public class Z {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.Y.B);\n" + + " }\n" + + "}" + }, + null, + options, + "", + "SUCCESSB", + "", + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=289892 +public void test180() { + this.runConformTest( + new String[] { + "p/package-info.java", + "@p.Annot(state=p.MyEnum.BROKEN)\n" + + "package p;", + "p/Annot.java", + "package p;\n" + + "@Annot(state=MyEnum.KO)\n" + + "public @interface Annot {\n" + + " MyEnum state() default MyEnum.KO;\n" + + "}", + "p/MyEnum.java", + "package p;\n" + + "@Annot(state=MyEnum.KO)\n" + + "public enum MyEnum {\n" + + " WORKS, OK, KO, BROKEN, ;\n" + + "}", + "test180/package-info.java", + "@p.Annot(state=p.MyEnum.OK)\n" + + "package test180;", + "test180/Test.java", + "package test180;\n" + + "import p.MyEnum;\n" + + "import p.Annot;\n" + + "@Annot(state=MyEnum.OK)\n" + + "public class Test {}", + }, + "" + ); + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + JavacTestOptions.Excuse excuse = JavacTestOptions.Excuse.JavacHasErrorsEclipseHasNone; + if(this.complianceLevel >= ClassFileConstants.JDK16) { + excuse = null; + } + this.runConformTest( + false, + new String[] { + "X.java", + "import test180.Test;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Test.class);\n" + + " }\n" + + "}" + }, + null, + options, + "", + "class test180.Test", + "", + excuse); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=289892 +// in interaction with null annotations +// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=365519#c4 item (6) +public void test180a() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + this.runConformTest( + new String[] { + "p/package-info.java", + "@p.Annot(state=p.MyEnum.BROKEN)\n" + + "package p;", + "p/Annot.java", + "package p;\n" + + "@Annot(state=MyEnum.KO)\n" + + "public @interface Annot {\n" + + " MyEnum state() default MyEnum.KO;\n" + + "}", + "p/MyEnum.java", + "package p;\n" + + "@Annot(state=MyEnum.KO)\n" + + "public enum MyEnum {\n" + + " WORKS, OK, KO, BROKEN, ;\n" + + "}", + "test180/package-info.java", + "@p.Annot(state=p.MyEnum.OK)\n" + + "package test180;", + "test180/Test.java", + "package test180;\n" + + "import p.MyEnum;\n" + + "import p.Annot;\n" + + "@Annot(state=MyEnum.OK)\n" + + "public class Test {}", + }, + "", + null, + true, + null, + options, + null + ); + options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + JavacTestOptions.Excuse excuse = JavacTestOptions.Excuse.JavacHasErrorsEclipseHasNone; + if(this.complianceLevel >= ClassFileConstants.JDK16) { + excuse = null; + } + this.runConformTest( + false, + new String[] { + "X.java", + "import test180.Test;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Test.class);\n" + + " }\n" + + "}" + }, + null, + options, + "", + "class test180.Test", + "", + excuse); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=300133 +public void test181() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " A {\n" + + " @Override\n" + + " public Object foo(final String s) {\n" + + " class Local {\n" + + " public String toString() {\n" + + " return s;\n" + + " }\n" + + " }\n" + + " return new Local();\n" + + " }\n" + + " };\n" + + " public abstract Object foo(String s);\n" + + " public static void main(String... args) {\n" + + " System.out.println(A.foo(\"SUCCESS\"));\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test182() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " int n = 0;\n" + + " for (E e : E.values()) {\n" + + " if (e.val() == E.VALUES[n++] ) {\n" + + " System.out.print(e.val());\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "E.java", + "enum E {\n" + + " a1(1), a2(2);\n" + + " static int[] VALUES = { 1, 2 };\n" + + " private int value;\n" + + " E(int v) {\n" + + " this.value = v;\n" + + " }\n" + + " public int val() {\n" + + " return this.value;\n" + + " }\n" + + "}" + }, + "12", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test183() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " }\n" + + " static {\n" + + " int n = 0;\n" + + " for (E e : E.values()) {\n" + + " if (e.val() == E.VALUES[n++] ) {\n" + + " System.out.print(e.val());\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "E.java", + "enum E {\n" + + " a1(1), a2(2);\n" + + " static int[] VALUES = { 1, 2 };\n" + + " private int value;\n" + + " E(int v) {\n" + + " this.value = v;\n" + + " }\n" + + " public int val() {\n" + + " return this.value;\n" + + " }\n" + + "}" + }, + "12", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test184() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new X();\n" + + " }\n" + + " X() {\n" + + " int n = 0;\n" + + " for (E e : E.values()) {\n" + + " if (e.val() == E.VALUES[n++] ) {\n" + + " System.out.print(e.val());\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "E.java", + "enum E {\n" + + " a1(1), a2(2);\n" + + " static int[] VALUES = { 1, 2 };\n" + + " private int value;\n" + + " E(int v) {\n" + + " this.value = v;\n" + + " }\n" + + " public int val() {\n" + + " return this.value;\n" + + " }\n" + + "}" + }, + "12", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id= +public void test185() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " A, B;\n" + + " private X() throws Exception {\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " A, B;\n" + + " ^\n" + + "Unhandled exception type Exception\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " A, B;\n" + + " ^\n" + + "Unhandled exception type Exception\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test186() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_MISSING_ENUM_CASE_DESPITE_DEFAULT, JavaCore.ENABLED); + this.runNegativeTest( + new String[] { + "Y.java", + "enum X {\n" + + " A, B;\n" + + "}\n" + + "public class Y {\n" + + " void test(X x) {\n" + + " switch (x) {\n" + + " case A: System.out.println(\"A\"); break;\n" + + " default : System.out.println(\"unknown\"); break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 6)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant B should have a corresponding case label in this enum switch on X. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'\n" + + "----------\n", + null, // classlibs + true, // flush + options, // customOptions + false /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + false /* performStatementsRecovery */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test187() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_MISSING_ENUM_CASE_DESPITE_DEFAULT, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.ERROR); + this.runConformTest( + new String[] { + "Y.java", + "enum X {\n" + + " A, B;\n" + + "}\n" + + "public class Y {\n" + + " void test(X x) {\n" + + " switch (x) {\n" + + " case A: System.out.println(\"A\");\n" + + " //$FALL-THROUGH$\n" + + " //$CASES-OMITTED$\n" + + " default : System.out.println(\"unknown\"); break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, // classlibs + true, // flush + null, // vmArgs + options, + null /*requestor*/); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test187a() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_MISSING_ENUM_CASE_DESPITE_DEFAULT, JavaCore.ENABLED); + this.runNegativeTest( + new String[] { + "Y.java", + "enum X {\n" + + " A, B;\n" + + "}\n" + + "public class Y {\n" + + " void test(X x) {\n" + + " switch (x) {\n" + + " case A: System.out.println(\"A\"); break;\n" + + " //$CASES-OMITTED$\n" + // not strong enough to suppress the warning if default: is missing + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 6)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant B needs a corresponding case label in this enum switch on X\n" + + "----------\n", + null, // classlibs + true, // flush + options, // customOptions + false /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + false /* performStatementsRecovery */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test187b() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + this.runConformTest( + new String[] { + "Y.java", + "enum X {\n" + + " A, B;\n" + + "}\n" + + "public class Y {\n" + + " @SuppressWarnings(\"incomplete-switch\")\n" + + " void test(X x) {\n" + + " switch (x) {\n" + + " case A: System.out.println(\"A\"); break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, // classlibs + true, // flush + null, // vmArgs + options, + null /*requestor*/); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test188() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE, JavaCore.WARNING); + this.runNegativeTest( + new String[] { + "Y.java", + "enum X {\n" + + " A, B;\n" + + "}\n" + + "public class Y {\n" + + " void test(X x) {\n" + + " switch (x) {\n" + + " case A: System.out.println(\"A\"); break;\n" + + " case B: System.out.println(\"B\"); break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 6)\n" + + " switch (x) {\n" + + " ^\n" + + "The switch over the enum type X should have a default case\n" + + "----------\n", + null, // classlibs + true, // flush + options, // customOptions + false /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + false /* performStatementsRecovery */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test189() { + Map options = getCompilerOptions(); + //options.put(JavaCore.COMPILER_PB_MISSING_DEFAULT_CASE, JavaCore.WARNING); + this.runNegativeTest( + new String[] { + "Y.java", + "enum X {\n" + + " A, B;\n" + + "}\n" + + "public class Y {\n" + + " int test(X x) {\n" + + " switch (x) {\n" + + " case A: return 1;\n" + + " case B: return 2;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Y.java (at line 5)\n" + + " int test(X x) {\n" + + " ^^^^^^^^^\n" + + "This method must return a result of type int. Note that a problem regarding missing 'default:' on 'switch' has been suppressed, which is perhaps related to this problem\n" + + "----------\n", + null, // classlibs + true, // flush + options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433060 [1.8][compiler] enum E{I;} causes NPE in AllocationExpression.checkTypeArgumentRedundancy +public void test433060() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_REDUNDANT_TYPE_ARGUMENTS, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " OBJ;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public enum X {\n" + + " ^\n" + + "Syntax error, enum declaration cannot have type parameters\n" + + "----------\n", + null, + true, + options); +} +public void test434442() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runConformTest(new String[] { + "X.java", + "interface I {\n" + + " public enum Letter {\n" + + " A, B;\n" + + " }\n" + + " public default void test(Letter letter) {\n" + + " switch (letter) {\n" + + " case A:\n" + + " System.out.println(\"A\");\n" + + " break;\n" + + " case B:\n" + + " System.out.println(\"B\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "public class X implements I {\n" + + " public static void main(String[] args) {\n" + + " try{\n" + + " X x = new X();\n" + + " x.test(Letter.A);\n" + + " }\n" + + " catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "} \n" + + "\n" + }); +} +public void test476281() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + this.runConformTest(new String[] { + "LambdaEnumLocalClassBug.java", + "public enum LambdaEnumLocalClassBug {\n" + + " A(() -> {\n" + + " class Foo {\n" + + " }\n" + + " new Foo();\n" + + " System.out.println(\"Success\");\n" + + " })\n" + + ";\n" + + " private final Runnable runnable;\n" + + " private LambdaEnumLocalClassBug(Runnable runnable) {\n" + + " this.runnable = runnable;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " A.runnable.run();\n" + + " }\n" + + "}"}, + "Success"); +} +public void test476281a() { + this.runConformTest(new String[] { + "Test.java", + "public enum Test {\n" + + " B(new Runnable() {\n" + + " public void run() {\n" + + " //\n" + + " class Foo {\n" + + " \n" + + " }\n" + + " new Foo();\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + "});\n" + + " private final Runnable runnable;\n" + + " private Test(Runnable runnable) {\n" + + " this.runnable = runnable;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " B.runnable.run();\n" + + " }\n" + + "}"}, + "Success"); +} +public void testBug388314() throws Exception { + this.runConformTest( + new String[] { + "p/Nullable.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Target(value = { FIELD, LOCAL_VARIABLE, METHOD, PARAMETER })\n" + + "public @interface Nullable {\n" + + " // Nothing to do.\n" + + "}", + "p/EnumWithNullable.java", + "package p;\n" + + "public enum EnumWithNullable {\n" + + " A;\n" + + "\n" + + " @Nullable\n" + + " private final Object b;\n" + + "\n" + + " private EnumWithNullable(@Nullable Object b) {\n" + + " this.b = b;\n" + + " }\n" + + "\n" + + " private EnumWithNullable() {\n" + + " this(null);\n" + + " }\n" + + "}\n" + }, + ""); + + String expectedOutput = + " // Method descriptor #27 (Ljava/lang/String;ILjava/lang/Object;)V\n" + + " // Stack: 3, Locals: 4\n" + + " private EnumWithNullable(java.lang.String arg0, int arg1, @p.Nullable java.lang.Object b);\n"; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"p" + File.separator + "EnumWithNullable.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExpressionContextTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExpressionContextTests.java new file mode 100644 index 0000000000..0af58e6053 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExpressionContextTests.java @@ -0,0 +1,664 @@ +/******************************************************************************* + * Copyright (c) 2013, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Jesper S Moller - realigned with bug 399695 + *******************************************************************************/ + +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class ExpressionContextTests extends AbstractRegressionTest { + +static { + // TESTS_NAMES = new String[] { "test380112e"}; + // TESTS_NUMBERS = new int[] { 50 }; + // TESTS_RANGE = new int[] { 11, -1 }; +} + +public ExpressionContextTests(String name) { + super(name); +} + +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} + +@Override +protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + return defaultOptions; +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "public class X {\n" + + " Object o = () -> {};\n" + + " Object p = (I) () -> {};\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Object o = () -> {};\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test002() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "interface J {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "public class X {\n" + + " Object p = (I & J) () -> {};\n" + + "}\n" , + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "interface J {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "public class X {\n" + + " Object p = (int & I & J) () -> {};\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Object p = (int & I & J) () -> {};\n" + + " ^^^\n" + + "Base types are not allowed in intersection cast operator\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Object p = (int & I & J) () -> {};\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "interface J {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "public class X {\n" + + " Object p = (X[] & Serializable & Cloneable) new X[0];\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Object p = (X[] & Serializable & Cloneable) new X[0];\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Arrays are not allowed in intersection cast operator\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Object p = (X[] & Serializable & Cloneable) new X[0];\n" + + " ^^^^^^^^^^^^\n" + + "Serializable cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "interface J {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "public class X {\n" + + " Object p = (I & X) () -> {};\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Object p = (I & X) () -> {};\n" + + " ^\n" + + "The type X is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Object p = (I & X) () -> {};\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "interface J {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "public class X {\n" + + " Object p = (I & J & I) () -> {};\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Object p = (I & J & I) () -> {};\n" + + " ^\n" + + "Duplicate type in intersection cast operator\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Object p = (I & J & I) () -> {};\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " void doit(List x);\n" + + " default void doitalso () {}\n" + + " boolean equals(Object o);\n" + + "}\n" + + "public class X {\n" + + " I i = (List p) -> {};\n" + + " I i2 = (List p) -> {};\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i2 = (List p) -> {};\n" + + " ^^^^\n" + + "Lambda expression\'s parameter p is expected to be of type List\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "interface J {\n" + + " void doit();\n" + + " default void doitalso () {}\n" + + "}\n" + + "public class X {\n" + + " Object p = (@Marker java.lang. @Readonly String & I & J) () -> {};\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Object p = (@Marker java.lang. @Readonly String & I & J) () -> {};\n" + + " ^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Object p = (@Marker java.lang. @Readonly String & I & J) () -> {};\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Object p = (@Marker java.lang. @Readonly String & I & J) () -> {};\n" + + " ^^^^^^^^\n" + + "Readonly cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " Object p = (@Marker java.lang. @Readonly String & I & J) () -> {};\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test009() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "interface I {\n" + + " void doit(List x);\n" + + " boolean equals(Object o);\n" + + "}\n" + + "public class X {\n" + + " I i = (List p) -> {};\n" + + " I i2 = (Map & I) null;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " I i2 = (Map & I) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from null to I & Map\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "interface I {\n" + + " void doit(List x);\n" + + " boolean equals(Object o);\n" + + "}\n" + + "public class X {\n" + + " I i = (List p) -> {};\n" + + " I i2 = (Map.Entry & I & Serializable) null;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i2 = (Map.Entry & I & Serializable) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The member type Map.Entry cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type Map\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " I i2 = (Map.Entry & I & Serializable) null;\n" + + " ^^^^^^^^^^^^\n" + + "Serializable cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + "}\n" + + "interface J {\n" + + "}\n" + + "interface K {\n" + + "}\n" + + "public class X {\n" + + " X X = (X & J & K) new Y();\n" + + "}\n" + + "class Y {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " X X = (X & J & K) new Y();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Y to X & J & K\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + "}\n" + + "interface J {\n" + + "}\n" + + "interface K {\n" + + "}\n" + + "public class X {\n" + + " X X = (X & J & K) new Y();\n" + + "}\n" + + "class Y extends X implements Zork {\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " X X = (X & J & K) new Y();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Y to X & J & K\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " class Y extends X implements Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + "}\n" + + "interface J {\n" + + "}\n" + + "interface K {\n" + + "}\n" + + "public class X {\n" + + " X X = (X & J & K) new Y();\n" + + "}\n" + + "final class Y extends X {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " X X = (X & J & K) new Y();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Y to X & J & K\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " X X = (X & J & K) new Y();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Y to X & J & K\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + "}\n" + + "interface J {\n" + + "}\n" + + "interface K {\n" + + "}\n" + + "public class X {\n" + + " I i = null;\n" + + " X X = (X & J & K) i;\n" + + "}\n" + + "final class Y extends P {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " final class Y extends P {\n" + + " ^\n" + + "P cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + "}\n" + + "interface J {\n" + + "}\n" + + "interface K {\n" + + "}\n" + + "final public class X {\n" + + " I i = null;\n" + + " X X = (X & J & K) i;\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " X X = (X & J & K) i;\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot cast from I to X & J & K\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + "}\n" + + "interface J {\n" + + "}\n" + + "interface K {\n" + + "}\n" + + "final public class X implements I {\n" + + " I i = null;\n" + + " X X = (X & J & K) i;\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399773, [1.8][compiler] Cast expression should allow for additional bounds to form intersection types +public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + "}\n" + + "interface J {\n" + + "}\n" + + "interface K {\n" + + "}\n" + + "public class X {\n" + + " I i = null;\n" + + " X X = (X & J & K) (X & K & J) i;\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " X X = (X & J & K) (X & K & J) i;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X & K & J to X & J & K\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399778, [1.8][compiler] Conditional operator expressions should propagate target types +public void test018() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "class X {\n" + + " Object o = (I) () -> {};\n" + + " I k = (()->{});\n" + + " I i = 1 == 2 ? () -> {} : () -> {};\n" + + " I j = () -> {};\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " I i = 1 == 2 ? () -> {} : () -> {};\n" + + " ^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399778, [1.8][compiler] Conditional operator expressions should propagate target types +public void test019() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "class X {\n" + + " I [] k = {(()->{}), ()->{}, 1 == 2 ? () -> {} : ()->{}};\n" + + " I [][] i = {{()->{}}};\n" + + " void foo() {\n" + + " I i = () -> {};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " I [] k = {(()->{}), ()->{}, 1 == 2 ? () -> {} : ()->{}};\n" + + " ^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " I i = () -> {};\n" + + " ^\n" + + "The local variable i is hiding a field from type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399778, [1.8][compiler] Conditional operator expressions should propagate target types +public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " J doit(int x);\n" + + "}\n" + + "interface J {\n" + + " K doit();\n" + + "}\n" + + "interface K {\n" + + " I doit();\n" + + "}" + + "class X {\n" + + " I foo() {\n" + + " return x -> { return () -> () -> \"Hello\"; };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " return x -> { return () -> () -> \"Hello\"; };\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to I\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399778, [1.8][compiler] Conditional operator expressions should propagate target types +public void test021() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "class X {\n" + + " I foo() {\n" + + " return \"Hello\" + () -> {};\n" + + " }\n" + + " I goo() {\n" + + " return \"Hello\" + (I)(() -> {});\n" + + " }\n" + + " I zoo() {\n" + + " return 10 + (() -> {});\n" + + " }\n" + + " I boo() {\n" + + " return 10 + (I) (() -> {});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return \"Hello\" + () -> {};\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " return \"Hello\" + (I)(() -> {});\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from String to I\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " return 10 + (() -> {});\n" + + " ^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " return 10 + (I) (() -> {});\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The operator + is undefined for the argument type(s) int, I\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401222, [1.8][compiler] Conditional operator expressions results differ from 8b76 +public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "class X {\n" + + " int foo(int x) {\n" + + " List l = x == 2 ? (List)(null) : 1;\n" + + " List m = x == 2 ? 1 : (List)(null);\n" + + " return 1;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " List l = x == 2 ? (List)(null) : 1;\n" + + " ^\n" + + "Type mismatch: cannot convert from int to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " List m = x == 2 ? 1 : (List)(null);\n" + + " ^\n" + + "Type mismatch: cannot convert from int to List\n" + + "----------\n"); +} +public static Class testClass() { + return ExpressionContextTests.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java new file mode 100644 index 0000000000..413278c55c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java @@ -0,0 +1,279 @@ +/******************************************************************************* + * Copyright (c) 2003, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class ExternalizeStringLiterals15Test extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test000" }; +// TESTS_NUMBERS = new int[] { 7 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public ExternalizeStringLiterals15Test(String name) { + super(name); +} +public static Test suite() { + return buildUniqueComplianceTestSuite(testClass(), ClassFileConstants.JDK1_5); +} + +public void test001() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "@Target({TYPE, FIELD, METHOD,\n" + + " PARAMETER, CONSTRUCTOR,\n" + + " LOCAL_VARIABLE, PACKAGE})\n" + + "@Retention(CLASS)\n" + + "public @interface X\n" + + "{\n" + + " String[] value() default {};\n" + + " String justification() default \"\";\n" + + "}" + }, + "", + null, + true, + null, + customOptions, + null); +} +public void test002() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "X.java", + "class X {\n" + + " String s2 = \"test1\"; //$NON-NLS-1$\n" + + " String s3 = \"test2\"; //$NON-NLS-1$//$NON-NLS-2$\n" + + "\n" + + "\n" + + " void foo() {\n" + + " String s4 = null;\n" + + " String s5 = \"test3\";\n" + + " String s6 = \"test4\";\n" + + " System.out.println(\"test5\");\n" + + " }\n" + + "}", + }, + null, customOptions, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " String s3 = \"test2\"; //$NON-NLS-1$//$NON-NLS-2$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " String s5 = \"test3\";\n" + + " ^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " String s6 = \"test4\";\n" + + " ^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " System.out.println(\"test5\");\n" + + " ^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +public void test003() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "X.java", + "class X {\n" + + " String s2 = \"test1\"; //$NON-NLS-1$\n" + + " String s3 = \"test2\"; //$NON-NLS-1$//$NON-NLS-2$\n" + + "\n" + + "\n" + + " void foo() {\n" + + " String s4 = null;\n" + + " String s5 = null;//$NON-NLS-1$\n" + + " String s6 = \"test4\";\n" + + " System.out.println(\"test5\");\n" + + " }\n" + + "}", + }, + null, customOptions, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " String s3 = \"test2\"; //$NON-NLS-1$//$NON-NLS-2$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " String s5 = null;//$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " String s6 = \"test4\";\n" + + " ^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " System.out.println(\"test5\");\n" + + " ^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +public void test004() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "class X {\n" + + " String s2 = \"test1\"; //$NON-NLS-1$\n" + + " String s3 = \"test2\"; //$NON-NLS-1$//$NON-NLS-2$\n" + + " \n" + + " @SuppressWarnings(\"nls\")\n" + + " void foo() {\n" + + " String s4 = null;\n" + + " String s5 = null;//$NON-NLS-1$\n" + + " String s6 = \"test4\";\n" + + " System.out.println(\"test5\");\n" + + " }\n" + + "}", + }, + null, customOptions, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " String s3 = \"test2\"; //$NON-NLS-1$//$NON-NLS-2$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n", + null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162903 +public void test005() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "X.java", + "class X {\n" + + "\n" + + " void foo() {\n" + + " String s6 = \"SUCCESS\";\n" + + " System.out.println(s6);\n" + + " }\n" + + "}", + }, + null, customOptions, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " String s6 = \"SUCCESS\";\n" + + " ^^^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162903 +public void test006() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"nls\")\n" + + " public static void main(String[] args) {\n" + + " String s6 = \"SUCCESS\";\n" + + " System.out.println(s6);\n" + + " }\n" + + "}", + }, + "SUCCESS", + null, + true, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=237245 +public void test007() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @Annot({\n" + + " @A(name = \"name\", //$NON-NLS-1$\n" + + " value = \"Test\") //$NON-NLS-1$\n" + + " })\n" + + " @X2(\"\") //$NON-NLS-1$\n" + + " void foo() {\n" + + " }\n" + + "}\n" + + "@interface Annot {\n" + + " A[] value();\n" + + "}\n" + + "@interface A {\n" + + " String name();\n" + + " String value();\n" + + "}\n" + + "@interface X2 {\n" + + " String value();\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @A(name = \"name\", //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " value = \"Test\") //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " @X2(\"\") //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n", + null, + true, + customOptions); +} +public static Class testClass() { + return ExternalizeStringLiterals15Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiteralsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiteralsTest.java new file mode 100644 index 0000000000..0b8cf38289 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiteralsTest.java @@ -0,0 +1,817 @@ +/******************************************************************************* + * Copyright (c) 2003, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class ExternalizeStringLiteralsTest extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test000" }; +// TESTS_NUMBERS = new int[] { 16 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public ExternalizeStringLiteralsTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public void test001() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "A.java", + "public class A {\n" + + " void foo() {\n" + + " System.out.println(\"a\");\n" + + " } //$NON-NLS-1$ \n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in A.java (at line 3)\n" + + " System.out.println(\"a\");\n" + + " ^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "2. ERROR in A.java (at line 4)\n" + + " } //$NON-NLS-1$ \n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +public void test002() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class X {\n" + + " String s = null; //$NON-NLS-1$\n" + + " String s2 = \"\"; //$NON-NLS-1$\n" + + " String s3 = \"\"; //$NON-NLS-1$//$NON-NLS-2$\n" + + " \n" + + " void foo() {\n" + + " String s4 = null; //$NON-NLS-1$\n" + + " String s5 = \"\"; //$NON-NLS-1$\n" + + " String s6 = \"\"; //$NON-NLS-2$//$NON-NLS-1$\n" + + " System.out.println(\"foo\");//$NON-NLS-1$//$NON-NLS-2$\n" + + " } //$NON-NLS-1$\n" + + " //$NON-NLS-1$\n" + + "}//$NON-NLS-3$", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " String s = null; //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " String s3 = \"\"; //$NON-NLS-1$//$NON-NLS-2$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " String s4 = null; //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " String s6 = \"\"; //$NON-NLS-2$//$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " System.out.println(\"foo\");//$NON-NLS-1$//$NON-NLS-2$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " } //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "7. ERROR in X.java (at line 13)\n" + + " }//$NON-NLS-3$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test003() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "p/Foo.java", + "package p;\n" + + "public class Foo { \n" + + " public void foo() {\n" + + " System.out.println(\"string1\" + \"string2\" //$NON-NLS-1$\n" + + " );\n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\Foo.java (at line 4)\n" + + " System.out.println(\"string1\" + \"string2\" //$NON-NLS-1$\n" + + " ^^^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "2. ERROR in p\\Foo.java (at line 6)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n", + null, + true, + customOptions); +} +public void test004() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "p/Foo.java", + "package p;\n" + + "public class Foo { \n" + + " public void foo() {\n" + + " //$NON-NLS-1$\n" + + " };\n" + + "}", + }, + "", + null, + true, + null, + customOptions, + null); +} +public void test005() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " String s = \"\"; //$NON-NLS-1$//$NON-NLS-1$\r\n" + + " }\r\n" + + "}", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " String s = \"\"; //$NON-NLS-1$//$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test006() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " String s = \"\"; //$NON-NLS-1$//$NON-NLS-1$\r\n" + + " }\r\n" + + "", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " String s = \"\"; //$NON-NLS-1$//$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n", + null, + true, + customOptions); +} +public void test007() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " String s = null; //$NON-NLS-1$//$NON-NLS-1$\r\n" + + " }\r\n" + + "}", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " String s = null; //$NON-NLS-1$//$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " String s = null; //$NON-NLS-1$//$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test008() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\r\n" + + " }\r\n" + + "}", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test009() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "p/Foo.java", + "package p;\n" + + "public class Foo { \n" + + " public void foo(int i) {\n" + + " System.out.println(\"test1\" + i + \"test2\"); //$NON-NLS-2$//$NON-NLS-1$\r\n" + + " };\n" + + "}", + }, + "", + null, + true, + null, + customOptions, + null); +} +public void test010() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " int i = s;\n" + + " System.out.println(s);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " int i = s;\n" + + " ^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n", + null, + true, + customOptions); +} +public void test011() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int i = null;\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " System.out.println(s + i);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int i = null;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from null to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " String s = \"test\"; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n", + null, + true, + customOptions); +} +public void test012() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int i = null;\n" + + " String s = null; //$NON-NLS-2$//$NON-NLS-3$\n" + + " System.out.println(s + i);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int i = null;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from null to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " String s = null; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " String s = null; //$NON-NLS-2$//$NON-NLS-3$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n", + null, + true, + customOptions); +} +public void test013() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = \"test1\";\n" + + " System.out.println(s);\n" + + " }\n" + + "}", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " String s = \"test1\";\n" + + " ^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=112973 +public void test014() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = \"test1\"; //$NON-NLS-?$\n" + + " System.out.println(s);\n" + + " }\n" + + "}", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " String s = \"test1\"; //$NON-NLS-?$\n" + + " ^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " String s = \"test1\"; //$NON-NLS-?$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114077 +public void test015() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " String s1= null; //$NON-NLS-1$\n" + + " String s2= \"\";\n" + + " }\n" + + "}", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " String s1= null; //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " String s2= \"\";\n" + + " ^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114077 +public void test016() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " private String s1= null; //$NON-NLS-1$\n" + + " \n" + + " public void foo() {\n" + + " String s2= \"\";\n" + + " }\n" + + "}", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " private String s1= null; //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary $NON-NLS$ tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " String s2= \"\";\n" + + " ^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148352 +public void test017() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String locationInAST) {\n" + + " String enclosingType= \"\"; //$NON-NLS-1$\n" + + " if (locationInAST != null) {\n" + + " enclosingType.toString()\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " enclosingType.toString()\n" + + " ^\n" + + "Syntax error, insert \";\" to complete BlockStatements\n" + + "----------\n", + null, + true, + customOptions, + false, + false, + false, + false, + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=213692 +public void test018() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " #\n" + + " String s1= \"1\"; //$NON-NLS-1$\n" + + " public void foo() {\n" + + " String s2= \"2\"; //$NON-NLS-1$\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " #\n" + + " ^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n", + null, + true, + customOptions, + false, + false, + false, + false, + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=213692 +public void test019() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String s1= \"1\"; //$NON-NLS-1$\n" + + " #\n" + + " public void foo() {\n" + + " String s2= \"2\"; //$NON-NLS-1$\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " #\n" + + " ^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n", + null, + true, + customOptions, + false, + false, + false, + false, + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=213692 +public void test020() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String s1= \"1\"; //$NON-NLS-1$\n" + + " public void foo() {\n" + + " #\n" + + " String s2= \"2\"; //$NON-NLS-1$\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " #\n" + + " ^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n", + null, + true, + customOptions, + false, + false, + false, + false, + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=213692 +public void test021() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String s1= \"1\"; //$NON-NLS-1$\n" + + " public void foo() {\n" + + " String s2= \"2\"; //$NON-NLS-1$\n" + + " #\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " #\n" + + " ^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n", + null, + true, + customOptions, + false, + false, + false, + false, + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=213692 +public void test022() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " #\n" + + " String s1= \"1\"; //$NON-NLS-1$\n" + + " public void foo() {\n" + + " #\n" + + " String s2= \"2\"; //$NON-NLS-1$\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " #\n" + + " ^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " #\n" + + " ^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n", + null, + true, + customOptions, + false, + false, + false, + false, + true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=213692 +public void test023() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public String toString() {\n" + + " StringBuffer output = new StringBuffer(10);\n" + + " output.append(this != null) ? null : \"\"); //$NON-NLS-1$\n" + + " output.append(\" \"); //$NON-NLS-1$\n" + + " return output.toString();\n" + + " } \n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " output.append(this != null) ? null : \"\"); //$NON-NLS-1$\n" + + " ^\n" + + "Syntax error on token \")\", delete this token\n" + + "----------\n", + null, + true, + customOptions, + false, + false, + false, + false, + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=443456, [1.8][compiler][lambda] $NON-NLS$ in lambda statement used as argument does not work +public void test443456() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.concurrent.Callable;\n" + + "public class X {\n" + + " Callable c;\n" + + " void setC(Callable c) {\n" + + " this.c = c;\n" + + " }\n" + + " X() {\n" + + " setC(() -> \"ee\"); //$NON-NLS-1$\n" + + " }\n" + + "}\n", + }, + "", + null, + true, + customOptions); +} +public static Class testClass() { + return ExternalizeStringLiteralsTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java new file mode 100644 index 0000000000..bd8fd95364 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java @@ -0,0 +1,826 @@ +/******************************************************************************* + * Copyright (c) 2005, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class FieldAccessTest extends AbstractRegressionTest { + static { +// TESTS_NAMES = new String[] { "test000" }; +// TESTS_NUMBERS = new int[] { 22 }; +// TESTS_RANGE = new int[] { 21, 50 }; + } + +public FieldAccessTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportIndirectStaticAccess, CompilerOptions.ERROR); + return options; +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149004 +public void test001() { + this.runConformTest( + new String[] { + "foo/BaseFoo.java", + "package foo;\n" + + "class BaseFoo {\n" + + " public static final int VAL = 0;\n" + + "}", + "foo/NextFoo.java", + "package foo;\n" + + "public class NextFoo extends BaseFoo {\n" + + "}", + "bar/Bar.java", + "package bar;\n" + + "public class Bar {\n" + + " int v = foo.NextFoo.VAL;\n" + + "}" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149004 +public void test002() { + this.runNegativeTest( + new String[] { + "foo/BaseFoo.java", + "package foo;\n" + + "public class BaseFoo {\n" + + " public static final int VAL = 0;\n" + + "}", + "foo/NextFoo.java", + "package foo;\n" + + "public class NextFoo extends BaseFoo {\n" + + "}", + "bar/Bar.java", + "package bar;\n" + + "public class Bar {\n" + + " int v = foo.NextFoo.VAL;\n" + + "}" + }, + "----------\n" + + "1. ERROR in bar\\Bar.java (at line 3)\n" + + " int v = foo.NextFoo.VAL;\n" + + " ^^^\n" + + "The static field BaseFoo.VAL should be accessed directly\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149004 +public void test003() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "foo/BaseFoo.java", + "package foo;\n" + + "class BaseFoo {\n" + + " public static final int VAL = 0;\n" + + "}", + "foo/NextFoo.java", + "package foo;\n" + + "public class NextFoo extends BaseFoo {\n" + + "}", + "bar/Bar.java", + "package bar;\n" + + "import foo.NextFoo;\n" + + "public class Bar {\n" + + " NextFoo[] tab = new NextFoo[] { new NextFoo() };\n" + + " int v = tab[0].VAL;\n" + + "}" + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149004 +public void test004() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + this.runNegativeTest( + true, + new String[] { + "foo/BaseFoo.java", + "package foo;\n" + + "public class BaseFoo {\n" + + " public static final int VAL = 0;\n" + + "}", + "foo/NextFoo.java", + "package foo;\n" + + "public class NextFoo extends BaseFoo {\n" + + "}", + "bar/Bar.java", + "package bar;\n" + + "import foo.NextFoo;\n" + + "public class Bar {\n" + + " NextFoo[] tab = new NextFoo[] { new NextFoo() };\n" + + " int v = tab[0].VAL;\n" + + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in bar\\Bar.java (at line 5)\n" + + " int v = tab[0].VAL;\n" + + " ^^^\n" + + "The static field BaseFoo.VAL should be accessed directly\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142234 +public void test005() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnqualifiedFieldAccess, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " private String memberVariable;\n" + + " public String getMemberVariable() {\n" + + " return (memberVariable);\n" + + " }\n" + + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return (memberVariable);\n" + + " ^^^^^^^^^^^^^^\n" + + "Unqualified access to the field X.memberVariable \n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142234 +public void test006() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnqualifiedFieldAccess, CompilerOptions.ERROR); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " private String memberVariable;\n" + + " public String getMemberVariable() {\n" + + " return \\u0028memberVariable\\u0029;\n" + + " }\n" + + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return \\u0028memberVariable\\u0029;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unqualified access to the field X.memberVariable \n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179056 +public void test007() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private void foo() {\n" + + " new A().a2.a.test = 8;\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " private int test;\n" + + " A a2;\n" + + " A a = new A();\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new A().a2.a.test = 8;\n" + + " ^^^^\n" + + "The field A.test is not visible\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179056 +public void test008() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private void foo() {\n" + + " new A().a2.a.test = 8;\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " int test;\n" + + " private A a2;\n" + + " A a = new A();\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new A().a2.a.test = 8;\n" + + " ^^\n" + + "The field A.a2 is not visible\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179056 +public void test009() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private void foo() {\n" + + " new A().a2.a.test = 8;\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " int test;\n" + + " A a2;\n" + + " private A a = new A();\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new A().a2.a.test = 8;\n" + + " ^\n" + + "The field A.a is not visible\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179056 +public void test010() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private void foo() {\n" + + " A.a2.a.test = 8;\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " static int test;\n" + + " static A a2;\n" + + " static private A a = new A();\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " A.a2.a.test = 8;\n" + + " ^\n" + + "The field A.a is not visible\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179056 +public void test011() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private void foo() {\n" + + " A.a2.a.test = 8;\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " static int test;\n" + + " static private A a2;\n" + + " static A a = new A();\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " A.a2.a.test = 8;\n" + + " ^^\n" + + "The field A.a2 is not visible\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179056 +public void test012() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private void foo() {\n" + + " A.a2.a.test = 8;\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " private static int test;\n" + + " static A a2;\n" + + " A a = new A();\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " A.a2.a.test = 8;\n" + + " ^^^^\n" + + "The field A.test is not visible\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179056 +public void test013() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends A {\n" + + " private void foo() {\n" + + " test = 8;\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " private int test;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " test = 8;\n" + + " ^^^^\n" + + "The field A.test is not visible\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179056 +public void test014() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends A {\n" + + " private void foo() {\n" + + " this.test = 8;\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " private int test;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " this.test = 8;\n" + + " ^^^^\n" + + "The field A.test is not visible\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179056 +public void test015() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends A {\n" + + " private void foo() {\n" + + " MyA.test = 8;\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " private static A MyA;\n" + + " static int test;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " MyA.test = 8;\n" + + " ^^^\n" + + "The field A.MyA is not visible\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179056 +public void test016() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends A {\n" + + " private void foo() {\n" + + " MyA2.MyA.test = 8;\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " private static A MyA;\n" + + " static A MyA2;\n" + + " static int test;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " MyA2.MyA.test = 8;\n" + + " ^^^\n" + + "The field A.MyA is not visible\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=222534 +public void test017() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.WARNING); + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " private static class Inner1 {\n" + + " private int field;\n" + + " }\n" + + " private static class Inner2 extends Inner1 {\n" + + " private int field;\n" + + " public void bar() {System.out.println(field);}\n" + + " }\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", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=222534 - variation +public void test018() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.WARNING); + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " public static int field;\n" + + " private static class Inner1 {\n" + + " private int field;\n" + + " }\n" + + " private static class Inner2 extends Inner1 {\n" + + " private int field;\n" + + " public void bar() {System.out.println(field);}\n" + + " }\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" + + "2. WARNING in X.java (at line 5)\n" + + " private int field;\n" + + " ^^^^^\n" + + "The field X.Inner1.field is hiding a field from type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " private int field;\n" + + " ^^^^^\n" + + "The field X.Inner2.field is hiding a field from type X\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=222534 - variation +public void test019() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING); + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " private static class Inner1 {\n" + + " private int field;\n" + + " }\n" + + " private static class Inner2 extends Inner1 {\n" + + " public void bar(int field) {System.out.println(field);}\n" + + " }\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", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=222534 - variation +public void test020() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING); + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " public static int field;\n" + + " private static class Inner1 {\n" + + " private int field;\n" + + " }\n" + + " private static class Inner2 extends Inner1 {\n" + + " public void bar(int field) {System.out.println(field);}\n" + + " }\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" + + "2. WARNING in X.java (at line 5)\n" + + " private int field;\n" + + " ^^^^^\n" + + "The field X.Inner1.field is hiding a field from type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " public void bar(int field) {System.out.println(field);}\n" + + " ^^^^^\n" + + "The parameter field is hiding a field from type X\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=303830 +public void test021() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public void bar() {\n" + + " ArrayList myList = new ArrayList();\n" + + " int len = myList.length;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int len = myList.length;\n" + + " ^^^^^^\n" + + "length cannot be resolved or is not a field\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=303830 +public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static int NEW_FIELD;\n" + + "}", + "Y.java", + "public class Y {\n" + + " void foo() {\n" + + " int i = X.OLD_FIELD;\n" + + " }\n" + + " void bar() {\n" + + " int j = X.OLD_FIELD;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " int i = X.OLD_FIELD;\n" + + " ^^^^^^^^^\n" + + "OLD_FIELD cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in Y.java (at line 6)\n" + + " int j = X.OLD_FIELD;\n" + + " ^^^^^^^^^\n" + + "OLD_FIELD cannot be resolved or is not a field\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318171 +public void test023() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public abstract class A {\n" + + " protected int field;\n" + + "}\n", + "p2/B.java", + "package p2;\n" + + "import p1.A;\n" + + "public abstract class B extends A {\n" + + " protected int field;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p2\\B.java (at line 4)\n" + + " protected int field;\n" + + " ^^^^^\n" + + "The field B.field is hiding a field from type A\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318171 +public void test024() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public abstract class A extends Super {\n" + + "}\n", + "p1/Super.java", + "package p1;\n" + + "public abstract class Super extends SuperSuper {\n" + + "}\n", + "p1/SuperSuper.java", + "package p1;\n" + + "public abstract class SuperSuper {\n" + + " protected int field;\n" + + "}\n", + "p2/B.java", + "package p2;\n" + + "import p1.A;\n" + + "public abstract class B extends A {\n" + + " protected int field;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p2\\B.java (at line 4)\n" + + " protected int field;\n" + + " ^^^^^\n" + + "The field B.field is hiding a field from type SuperSuper\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318171 +public void test025() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public abstract class A extends Super {\n" + + "}\n", + "p1/Super.java", + "package p1;\n" + + "public abstract class Super extends SuperSuper {\n" + + "}\n", + "p1/SuperSuper.java", + "package p1;\n" + + "public abstract class SuperSuper implements Interface{\n" + + "}\n", + "p1/Interface.java", + "package p1;\n" + + "public interface Interface{\n" + + " int field = 123;\n" + + "}\n", + "p2/B.java", + "package p2;\n" + + "import p1.A;\n" + + "public abstract class B extends A {\n" + + " protected int field;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p2\\B.java (at line 4)\n" + + " protected int field;\n" + + " ^^^^^\n" + + "The field B.field is hiding a field from type Interface\n" + + "----------\n"); +} +public void testBug361039() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // to leverage autounboxing + runNegativeTest( + new String[] { + "Bug361039.java", + "public class Bug361039 {\n" + + " public Bug361039(boolean b) {\n" + + " }\n" + + " private Object foo() {\n" + + " return new Bug361039(!((Boolean)this.f));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug361039.java (at line 5)\n" + + " return new Bug361039(!((Boolean)this.f));\n" + + " ^\n" + + "f cannot be resolved or is not a field\n" + + "----------\n"); +} +public void testBug568959_001() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // lambda + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public void foo(Object o) {\n"+ + " I i = () -> {\n"+ + " while (o.eq) {\n"+ + " // nothing\n"+ + " }\n"+ + " };\n"+ + " }\n"+ + "}\n"+ + "interface I { \n"+ + " public abstract void run();\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " while (o.eq) {\n" + + " ^^\n" + + "eq cannot be resolved or is not a field\n" + + "----------\n"); +} +public static Class testClass() { + return FieldAccessTest.class; +} +} + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java new file mode 100644 index 0000000000..95c16a822b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java @@ -0,0 +1,4713 @@ +/******************************************************************************* + * Copyright (c) 2005, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 236385 - [compiler] Warn for potential programming problem if an object is created but not used + * bug 349326 - [1.7] new warning for missing try-with-resources + * bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) + * bug 383690 - [compiler] location of error re uninitialized final field should be aligned + * bug 391517 - java.lang.VerifyError on code that runs correctly in Eclipse 3.7 and eclipse 3.6 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.ASTVisitor; +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class FlowAnalysisTest extends AbstractRegressionTest { +static { +// TESTS_NAMES = new String[] { "testBug380313" }; +// TESTS_NUMBERS = new int[] { 43 }; +} +public FlowAnalysisTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +private boolean checkSwitchAllowedLevel() { + return this.complianceLevel >= ClassFileConstants.JDK14; +} +public void test001() { + this.runNegativeTest(new String[] { + "X.java", // ================= + "public class X {\n" + + " public String foo(int i) {\n" + + " if (true) {\n" + + " return null;\n" + + " }\n" + + " if (i > 0) {\n" + + " return null;\n" + + " }\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public String foo(int i) {\n" + + " ^^^^^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " if (i > 0) {\n" + + " return null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127255 +// Compiler incorrectly reports "variable may not have been initialized" +public void test002() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test() {\n" + + " int c1, c2;\n" + + " while ((char) (c1 = 0) == 1) {}\n" + + " if (c1 == 0) {} // silent\n" + + " if (c2 == 0) {} // complain\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (c2 == 0) {} // complain\n" + + " ^^\n" + + "The local variable c2 may not have been initialized\n" + + "----------\n", + null, true, options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127255 +// Compiler incorrectly reports "variable may not have been initialized" +public void test003() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test() {\n" + + " int c1, c2;\n" + + " while ((char) (c1 = 0) == 1) ;\n" + + " if (c1 == 0) {} // silent\n" + + " if (c2 == 0) {} // complain\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (c2 == 0) {} // complain\n" + + " ^^\n" + + "The local variable c2 may not have been initialized\n" + + "----------\n", + null, true, options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127255 +// Compiler incorrectly reports "variable may not have been initialized" +public void test004() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test() {\n" + + " int c1, c2;\n" + + " for (;(char) (c1 = 0) == 1;) ;\n" + + " if (c1 == 0) {} // silent\n" + + " if (c2 == 0) {} // complain\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (c2 == 0) {} // complain\n" + + " ^^\n" + + "The local variable c2 may not have been initialized\n" + + "----------\n", + null, true, options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127255 +// Compiler incorrectly reports "variable may not have been initialized" +public void test005() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportParameterAssignment, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test() {\n" + + " int c1, c2;\n" + + " do ; while ((char) (c1 = 0) == 1);\n" + + " if (c1 == 0) {} // silent\n" + + " if (c2 == 0) {} // complain\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (c2 == 0) {} // complain\n" + + " ^^\n" + + "The local variable c2 may not have been initialized\n" + + "----------\n", + null, true, options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// basic scenario +public void test006() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0); // silent because first case\n" + + " case 1:\n" + + " System.out.println(1); // complain: possible fall-through\n" + + " break;\n" + + " case 2:\n" + + " System.out.println(3); // silent because of break\n" + + " return;\n" + + " case 3: // silent because of return\n" + + " case 4: // silent because grouped cases\n" + + " default:\n" + + " System.out.println(\"default\"); //$NON-NLS-1$\n" + + " }\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " case 1:\n" + + " ^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// SuppressWarnings effect - explicit fallthrough token +public void test007() { + if (this.complianceLevel == ClassFileConstants.JDK1_5) { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"fallthrough\")\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0); // silent because first case\n" + + " case 1:\n" + + " System.out.println(1); // silent because of SuppressWarnings\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, true, options); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// deep return (1) - fake reachable is seen as reachable +public void test008() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0);\n" + + " if (true) {\n" + + " return;\n" + + " }\n" + + " case 1:\n" + + " System.out.println(1);\n" + + " }\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 9)\n" + + " case 1:\n" + + " ^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// deep return (2) +public void test009() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(int p, boolean b) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0);\n" + + " if (b) {\n" + + " return;\n" + + " }\n" + + " else {\n" + + " return;\n" + + " }\n" + + " case 1:\n" + + " System.out.println(1);\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null, true, null, options, null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// deep return (3), limit: cannot recognize that we won't return +public void test010() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public void test(int p, boolean b) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.exit(0);\n" + + " case 1:\n" + // complain + " System.out.println(1);\n" + + " }\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " case 1:\n" + + " ^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// SuppressWarnings effect - implicit, using all token +public void test011() { + if (this.complianceLevel == ClassFileConstants.JDK1_5) { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"all\")\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0); // silent because first case\n" + + " case 1:\n" + + " System.out.println(1); // silent because of SuppressWarnings\n" + + " }\n" + + " }\n" + + " Zork z;\n" + // complain on Zork (unknown type) + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, true, options); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127730 +// [compiler] skip fall-through case warning when the fall-through is documented +// skip because of comment +public void _test012() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0); // silent because first case\n" + + " // on purpose fall-through\n" + + " case 1:\n" + + " System.out.println(1); // silent because of comment alone on its line above \n" + + " }\n" + + " }\n" + + "}" + }, + "", + null, true, null, options, null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127730 +// [compiler] skip fall-through case warning when the fall-through is documented +// skip because of comment - default label +public void _test013() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0); // silent because first case\n" + + " // on purpose fall-through\n" + + " default:\n" + + " System.out.println(1); // silent because of comment alone on its line above \n" + + " }\n" + + " }\n" + + "}" + }, + "", + null, true, null, options, null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// basic scenario: default label +public void test014() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0); // silent because first case\n" + + // note: the comment above is not alone on its line, hence it does not + // protect against fall-through diagnostic + " default:\n" + + " System.out.println(1); // complain: possible fall-through\n" + + " }\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " default:\n" + + " ^^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// skip because of comment - variants +public void test015() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0); // silent because first case\n" + + " // on purpose fall-through\n" + + "\n" + // extraneous line breaks fall-through protection + " case 1:\n" + + " System.out.println(1); // silent because of comment alone on its line above \n" + + " }\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 8)\n" + + " case 1:\n" + + " ^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// skip because of comment - variants +public void test016() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0); // silent because first case\n" + + " // on purpose fall-through\n" + + " /* other comment */\n" + // non-single line comment breaks fall-through protection + " case 1:\n" + + " System.out.println(1); // silent because of comment alone on its line above \n" + + " }\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 8)\n" + + " case 1:\n" + + " ^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127730 +// [compiler] skip fall-through case warning when the fall-through is documented +// skip because of comment - variants +public void _test017() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0);\n" + + "// on purpose fall-through\n" + // very beginning of line + " case 1:\n" + + " System.out.println(1); // silent because of comment alone on its line above \n" + + " }\n" + + " }\n" + + "}" + }, + "", + null, true, null, options, null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127730 +// [compiler] skip fall-through case warning when the fall-through is documented +// skip because of comment - variants +public void _test018() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0);\n" + + " //\n" + // empty line comment alone upon its line + " case 1:\n" + + " System.out.println(1); // silent because of comment alone on its line above \n" + + " }\n" + + " }\n" + + "}" + }, + "", + null, true, null, options, null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// conditioned break +public void test019() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public void test(int p, boolean b) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " if (b) {\n" + + " break;\n" + + " }\n" + + " case 1:\n" + + " System.out.println(1); // silent because of comment alone on its line above \n" + + " }\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 8)\n" + + " case 1:\n" + + " ^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// default reporting is ignore +public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(int p) {\n" + + " switch (p) {\n" + + " case 0:\n" + + " System.out.println(0); // silent because first case\n" + + " case 1:\n" + + " System.out.println(1); // silent because default level is ignore\n" + + " }\n" + + " }\n" + + " Zork z;\n" + // complain on Zork (unknown type) + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=67836 +// [compiler] warning on fall through +// problem category +public void test021() { + if (ProblemReporter.getProblemCategory(ProblemSeverities.Warning, IProblem.FallthroughCase) != + CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM) { + fail("bad category for fall-through case problem"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128840 +public void test022() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportEmptyStatement, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (true)\n" + + " ;\n" + + " else\n" + + " ;\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 4)\n" + + " ;\n" + + " ^\n" + + "Empty control-flow statement\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " ;\n" + + " ^\n" + + "Empty control-flow statement\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +public void test023() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final X x;\n" + + " while (true) {\n" + + " if (true) {\n" + + " break;\n" + + " }\n" + + " x = new X();\n" + + " }\n" + + " x.foo();\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " x = new X();\n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " x.foo();\n" + + " ^\n" + + "The local variable x may not have been initialized\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=132974 +public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(boolean b) {\n" + + " final Object l;\n" + + " do {\n" + + " if (b) {\n" + + " l = new Object();\n" + + " break;\n" + + " }\n" + + " } while (false);\n" + + " l.toString();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " l.toString();\n" + + " ^\n" + + "The local variable l may not have been initialized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=135602 +public void test025() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"[starting]\");\n" + + " X l = new X();\n" + + " l.testLoop();\n" + + " System.out.println(\"[finished]\");\n" + + " }\n" + + "\n" + + " public void testLoop() {\n" + + " int loops = 0;\n" + + "\n" + + " do {\n" + + " System.out.print(\"[Loop \" + loops + \"]\");\n" + + " if (loops > 2) {\n" + + " return;\n" + + " }\n" + + "\n" + + " if (loops < 4) {\n" + + " ++loops;\n" + + " continue; \n" + + " }\n" + + " } while (false);\n" + + " }\n" + + "\n" + + "}\n" + }, + "[starting][Loop 0][finished]"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=137298 +public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1) {\n" + + " int a00, a01, a02, a03, a04, a05, a06, a07, a08, a09;\n" + + " int a10, a11, a12, a13, a14, a15, a16, a17, a18, a19;\n" + + " int a20, a21, a22, a23, a24, a25, a26, a27, a28, a29;\n" + + " int a30, a31, a32, a33, a34, a35, a36, a37, a38, a39;\n" + + " int a40, a41, a42, a43, a44, a45, a46, a47, a48, a49;\n" + + " int a50, a51, a52, a53, a54, a55, a56, a57, a58, a59;\n" + + " int a60, a61, a62, a63, a64, a65, a66, a67, a68, a69;\n" + + " String s;\n" + + " Object o2 = o1;\n" + + " if (o2 == null) {\n" + + " s = \"\";\n" + + " }\n" + + " System.out.println(s);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " System.out.println(s);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Non-recursive approach for deep binary expressions. Check that the +// flow analysis doesn't break. +public void test027() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " String s;\n" + + " if (args.length == 0) {\n" + + " s = \"s\";\n" + + " } else {\n" + + " s = args[0];\n" + + " }\n" + + " System.out.println(s + \"-\" + s + \"-\" + s + \"-\" +\n" + + " s + \"-\" + s + \"-\" + s + \"-\" +\n" + + " s + \"-\" + s + \"-\" + s + \"-\" +\n" + + " s + \"-\" + s + \"-\" + s + \"-\" +\n" + + " s + \"-\" + s + \"-\" + s + \"-\");\n" + + " }\n" + + "}" + }, + "s-s-s-s-s-s-s-s-s-s-s-s-s-s-s-"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155423 +public void test028() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " {\n" + + " if (true) throw new NullPointerException();\n" + + " }\n" + + "}\n" // ================= + }, + ""); + // check no default return opcode is appended + String expectedOutput = + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 new java.lang.NullPointerException [10]\n" + + " 7 dup\n" + + " 8 invokespecial java.lang.NullPointerException() [12]\n" + + " 11 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 3]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155423 - variation +public void test029() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " {\n" + + " if (true) throw new NullPointerException();\n" + + " }\n" + + " X() {\n" + + " System.out.println();\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // check no default return opcode is appended + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 new java.lang.NullPointerException [10]\n" + + " 7 dup\n" + + " 8 invokespecial java.lang.NullPointerException() [12]\n" + + " 11 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 4, line: 3]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155423 - variation +public void test030() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class Y {\n" + + " Y(Object o) {\n" + + " System.out.print(o);\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends Y {\n" + + " {\n" + + " if (true)\n" + + " throw new NullPointerException();\n" + + " }\n" + + "\n" + + " X() {\n" + + " super(new Object() {\n" + + " public String toString() {\n" + + " return \"SUCCESS:\";\n" + + " }\n" + + " });\n" + + " System.out.println();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X();\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"caught:NPE\");\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS:caught:NPE"); + // check no default return opcode is appended + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 3, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 new X$1 [8]\n" + + " 4 dup\n" + + " 5 invokespecial X$1() [10]\n" + + " 8 invokespecial Y(java.lang.Object) [12]\n" + + " 11 new java.lang.NullPointerException [15]\n" + + " 14 dup\n" + + " 15 invokespecial java.lang.NullPointerException() [17]\n" + + " 18 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 11, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155423 - variation +public void test031() { + this.runConformTest( + new String[] { + "X.java", + "class Y {\n" + + " Y(Object o) {\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends Y {\n" + + " final int blank;\n" + + " {\n" + + " if (true)\n" + + " throw new NullPointerException();\n" + + " }\n" + + "\n" + + " X() {\n" + + " super(new Object() {});\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155423 - variation +public void test032() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " Y(int i) {\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends Y {\n" + + " final int blank;\n" + + " {\n" + + " if (true)\n" + + " throw new NullPointerException();\n" + + " }\n" + + "\n" + + " X() {\n" + + " super(blank = 0);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " super(blank = 0);\n" + + " ^^^^^\n" + + "Cannot refer to an instance field blank while explicitly invoking a constructor\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155423 - variation +public void test033() { + this.runConformTest( + new String[] { + "X.java", + "class Y {\n" + + " Y(int i) {\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " final int blank;\n" + + " {\n" + + " if (true)\n" + + " throw new NullPointerException();\n" + + " }\n" + + " X() {\n" + + " super(0);\n" + + " blank = 0;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918 +public void test034() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo1() {\n" + + " switch (1) {\n" + + " case 0:\n" + + " final int i = 1;\n" + + " case i: // should complain: i not initialized\n" + + " System.out.println(i); // should complain: i not initialized\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case i: // should complain: i not initialized\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " System.out.println(i); // should complain: i not initialized\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918 +// variant +public void test035() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo2() {\n" + + " switch (1) {\n" + + " case 0:\n" + + " int j = 0;\n" + + " case 1:\n" + + " System.out.println(j); // should complain: j not initialized\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(j); // should complain: j not initialized\n" + + " ^\n" + + "The local variable j may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162918 +// variant - not a flow analysis issue per se, contrast with 34 and 35 above +public void test036() { + String src = + "public class X {\n" + + " void foo3() {\n" + + " switch (1) {\n" + + " case 0:\n" + + " class Local {\n" + + " }\n" + + " ;\n" + + " case 1:\n" + + " new Local();\n" + // complain for compliance >= 1.4 + " }\n" + + " }\n" + + "}"; + if (this.complianceLevel <= ClassFileConstants.JDK1_3) { + this.runConformTest( + new String[] { + "X.java", + src + }, + "" + ); + } else { + this.runNegativeTest( + new String[] { + "X.java", + src + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " new Local();\n" + + " ^^^^^\n" + + "Local cannot be resolved to a type\n" + + "----------\n"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 +public void test037() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " if (false) {\n" + + " String s;\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false) {\n" + + " String s;\n" + + " System.out.println(s);\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.println(s);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 +// variant: the declaration is outside of the fake reachable block +public void test038() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s;\n" + + " if (false) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 +// variant with deeper nesting +public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " if (false) {\n" + + " String s;\n" + + " if (System.out != null) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false) {\n" + + " String s;\n" + + " if (System.out != null) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " System.out.println(s);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 +// variant - checking duplicate initialization of final variables +public void test040() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final String s = \"\";\n" + + " if (false) {\n" + + " s = \"\";\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " s = \"\";\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " s = \"\";\n" + + " ^\n" + + "The final local variable s cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 +// variant - checking duplicate initialization of final variables +public void test041() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final String s;\n" + + " s = \"\";\n" + + " if (false) {\n" + + " s = \"\";\n" + + " }\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166641 +// variant - checking duplicate initialization of final variables +public void test042() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final String s;\n" + + " if (false) {\n" + + " s = \"\";\n" + + " }\n" + + " s = \"\";\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " s = \"\";\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " s = \"\";\n" + + " ^\n" + + "The final local variable s may already have been assigned\n" + + "----------\n"); +} +// switch and definite assignment +public void test043() { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " public static void main(String[] args) {\n" + + " for (int i = 0; i < 3; i++) {\n" + + " System.out.print(i);\n" + + " switch (i) {\n" + + " case 1:\n" + + " final int j;\n" + + " j = 1;\n" + + " System.out.println(j);\n" + + " break;\n" + + " case 2:\n" + + " j = 2;\n" + + " System.out.println(j);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "011\n22"); +} +// switch and definite assignment +public void test044() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " public static void main(String[] args) {\n" + + " for (int i = 0; i < 3; i++) {\n" + + " System.out.print(i);\n" + + " switch (i) {\n" + + " case 1:\n" + + " final int j = 1;\n" + + " System.out.println(j);\n" + + " break;\n" + + " case 2:\n" + + " j = 2;\n" + + " System.out.println(j);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " j = 2;\n" + + " ^\n" + + "The final local variable j cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n"); +} +// switch and definite assignment +// ** +public void test045() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " public static void main(String[] args) {\n" + + " switch (args.length) {\n" + + " case 1:\n" + + " final int j = 1;\n" + + " case 2:\n" + + " switch (5) {\n" + + " case j:\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " case j:\n" + + " ^\n" + + "The local variable j may not have been initialized\n" + + "----------\n"); +} +// for and definite assignment +public void test046() { + this.runConformTest( + true, + new String[] { + "X.java", + "public abstract class X {\n" + + " public static void main(String args[]) {\n" + + " for (final int i; 0 < (i = 1); i = i + 1) {\n" + + " System.out.println(i);\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " for (final int i; 0 < (i = 1); i = i + 1) {\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + "1", + "", + JavacTestOptions.JavacHasABug.JavacBug4660984); +} +// do while and named labels +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472 +// variant +public void test047() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " done: do\n" + + " break done;\n" + + " while (false);\n" + + " System.out.println();\n" + + " }\n" + + "}\n", + }, + ""); +} +// labeled loop +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200158 +// contrast this with test049 +public void test048() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " private static final boolean b = false;\n" + + " public Object foo() {\n" + + " if (b) {\n" + + " label: while (bar()) {\n" + + " }\n" + + " return null;\n" + + " }\n" + + " return null;\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}\n" + }, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " label: while (bar()) {\n" + + " ^^^^^\n" + + "The label label is never explicitly referenced\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + "" /* expectedErrorString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} +// labeled loop +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=200158 +// variant: this one passes +public void test049() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " private static final boolean b = false;\n" + + " public Object foo() {\n" + + " if (b) {\n" + + " while (bar()) {\n" + + " }\n" + + " return null;\n" + + " }\n" + + " return null;\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}\n" + }, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + "" /* expectedErrorString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235781 +public void test050_definite_assigment_and_if_true() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " final int i;\n" + + " X() {\n" + + " if (true) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235781 +// variant +public void test051_definite_assigment_and_if_true() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " X() {\n" + + " final int i;\n" + + " if (true) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n" + } + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 +public void test052() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " if (b && false) {\n" + + " int i = 0; // deadcode\n" + + " return; // 1\n" + + " }\n" + + " return;\n" + + " return;\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (b && false) {\n" + + " int i = 0; // deadcode\n" + + " return; // 1\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test053() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " if (false && b) {\n" + + " int j = 0; // deadcode\n" + + " return; // 2\n" + + " }\n" + + " return;\n" + + " return;\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false && b) {\n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " if (false && b) {\n" + + " int j = 0; // deadcode\n" + + " return; // 2\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test054() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " while (true) {\n" + + " if (true) break;\n" + + " int k = 0; // deadcode\n" + + " }\n" + + " return;\n" + + " return;\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " int k = 0; // deadcode\n" + + " ^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test055() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " if (true || b) {\n" + + " int l = 0; // deadcode\n" + + " return; // 2a\n" + + " } \n" + + " return;\n" + + " return;\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (true || b) {\n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test056() { + if (this.complianceLevel < ClassFileConstants.JDK1_4) { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void bar() {\n" + + " return;\n" + + " {\n" + + " return; // 3\n" + + " }\n" + + " }\n" + + " void baz() {\n" + + " return;\n" + + " {\n" + + " }\n" + + " } \n" + + " void baz2() {\n" + + " return;\n" + + " ; // 4\n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " {\n" + + " return; // 3\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " {\n" + + " }\n" + + " ^^^^^\n" + + "Unreachable code\n" + + "----------\n"); + return; + } + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void bar() {\n" + + " return;\n" + + " {\n" + + " return; // 3\n" + + " }\n" + + " }\n" + + " void baz() {\n" + + " return;\n" + + " {\n" + + " }\n" + + " } \n" + + " void baz2() {\n" + + " return;\n" + + " ; // 4\n" + + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " {\n" + + " return; // 3\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " {\n" + + " }\n" + + " ^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " ; // 4\n" + + " ^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110544 +public void test057() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(int x, int[] array) {\n" + + " for (int i = 0; \n" + + " i < array.length; \n" + + " i++) {//dead code\n" + + " if (x == array[i])\n" + + " return;\n" + + " else\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " i++) {//dead code\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " break;\n" + + " ^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test058() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo() {\n" + + " if (false) {\n" + + " class Local {\n" + + " int i = 12;\n" + + " { i++; }\n" + + " void method() {\n" + + " if (false)\n" + + " System.out.println();\n" + + " return;\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " if (false) {\n" + + " class Local {\n" + + " int i = 12;\n" + + " { i++; }\n" + + " void method() {\n" + + " if (false)\n" + + " System.out.println();\n" + + " return;\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " class Local {\n" + + " ^^^^^\n" + + "The type Local is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " void method() {\n" + + " ^^^^^^^^\n" + + "The method method() from the type Local is never used locally\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test059() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " int i = false && b ? 0 : 1;\n" + + " if (false) {\n" + + " int j = false && b ? 0 : 1;\n" + + " }\n" + + " return;\n" + + " return;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " int i = false && b ? 0 : 1;\n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " int i = false && b ? 0 : 1;\n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " int j = false && b ? 0 : 1;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=48399 - variation +public void test060() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static final boolean DEBUG = false;\n" + + " static final int DEBUG_LEVEL = 0;\n" + + " boolean check() { return true; }\n" + + " void foo(boolean b) {\n" + + " if (DEBUG)\n" + + " System.out.println(\"fake reachable1\"); //$NON-NLS-1$\n" + + " if (DEBUG && b)\n" + + " System.out.println(\"fake reachable2\"); //$NON-NLS-1$\n" + + " if (DEBUG && check())\n" + + " System.out.println(\"fake reachable3\"); //$NON-NLS-1$\n" + + " if (b && DEBUG)\n" + + " System.out.println(\"fake reachable4\"); //$NON-NLS-1$\n" + + " if (check() && DEBUG)\n" + + " System.out.println(\"fake reachable5\"); //$NON-NLS-1$\n" + + " if (DEBUG_LEVEL > 1) \n" + + " System.out.println(\"fake reachable6\"); //$NON-NLS-1$\n" + + " return;\n" + + " return;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " if (DEBUG && b)\n" + + " ^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " System.out.println(\"fake reachable2\"); //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " if (DEBUG && check())\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " System.out.println(\"fake reachable3\"); //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " System.out.println(\"fake reachable4\"); //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in X.java (at line 15)\n" + + " System.out.println(\"fake reachable5\"); //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "7. WARNING in X.java (at line 17)\n" + + " System.out.println(\"fake reachable6\"); //$NON-NLS-1$\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "8. ERROR in X.java (at line 19)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=265962 +public void test061() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private static final boolean isIS() {\n" + + " return System.currentTimeMillis()<0 ;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " do {\n" + + " return;\n" + + " } while(isIS() && false);\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // ensure optimized boolean codegen sequence + String expectedOutput = + " public static void main(java.lang.String[] args);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: args index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=265962 - variation +public void test062() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " private static final boolean isIS() {\n" + + " return System.currentTimeMillis()<0 ;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " do {\n" + + " return;\n" + + " } while(isIS() && false);\n" + + " return;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 +public void test063() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() { return false; } \n" + + " public void foo() {" + + " if (bar())\n" + + " new IllegalArgumentException(\"You must not bar!\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new IllegalArgumentException(\"You must not bar!\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The allocated object is never used\n" + + "----------\n", + null /* classLibraries */, + true /* shouldFlushOutputDirectory */, + compilerOptions); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 +// non-throwable type +public void test064() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() { return false; } \n" + + " public void foo() {" + + " if (bar())\n" + + " new String(\"You must not bar!\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new String(\"You must not bar!\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The allocated object is never used\n" + + "----------\n", + null /* classLibraries */, + true /* shouldFlushOutputDirectory */, + compilerOptions); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 +// warning suppressed +public void test065() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.WARNING); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() { return false; }\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void foo() {" + + " if (bar())\n" + + " new IllegalArgumentException(\"You must not bar!\");\n" + + " }\n" + + "}", + }, + "" /* expectedOutputString */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + compilerOptions /* customOptions */, + null /* clientRequestor */); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 +// warning ignored (default) +public void test066() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() { return false; }\n" + + " public void foo() {" + + " if (bar())\n" + + " new IllegalArgumentException(\"You must not bar!\");\n" + + " }\n" + + "}", + }, + "" /* expectedOutputString */); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 +// instance is assigned +public void test067() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() { return false; }\n" + + " Throwable t;\n" + + " public void foo() {" + + " t = new IllegalArgumentException(\"You must not bar!\");\n" + + " }\n" + + "}", + }, + "" /* expectedOutputString */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + compilerOptions /* customOptions */, + null /* clientRequestor */); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 +// method invoked +public void test068() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() { return false; }\n" + + " public void foo() {" + + " if (bar())\n" + + " new IllegalArgumentException(\"You must not bar!\").printStackTrace();\n" + + " }\n" + + "}", + }, + "" /* expectedOutputString */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + compilerOptions /* customOptions */, + null /* clientRequestor */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236385 +//anonymous type +public void test069() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() { return false; } \n" + + " public void foo() {" + + " if (bar())\n" + + " new Object() {};\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new Object() {};\n" + + " ^^^^^^^^^^^^^^^\n" + + "The allocated object is never used\n" + + "----------\n", + null /* classLibraries */, + true /* shouldFlushOutputDirectory */, + compilerOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322154 +public void test070() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "public final class X {\n" + + " private X (){\n" + + " boolean flagSet = true;\n" + + " Object first = true ? null : \"\"; \n" + + " Object second = flagSet || first == null ? null :\n" + + " new Object() {};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Object first = true ? null : \"\"; \n" + + " ^^\n" + + "Dead code\n" + + "----------\n", + null /* classLibraries */, + true /* shouldFlushOutputDirectory */, + compilerOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=324154 +public void test071() { + runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " static {\n" + + " try {\n" + + " while(true) {\n" + + " if (true)\n" + + " throw new NumberFormatException();\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch(IOException e ) {\n" + + " // empty\n" + + " } \n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " throw new IOException();\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 9)\n" + + " throw new IOException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234 +// Warn uninitialized variable in deadcode if deadcode has been inferred +// by null analysis +public void testBug338234a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int i;\n" + + " String str = null;\n" + + " if (str != null)\n" + + " i++; \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " i++; \n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " i++; \n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234 +// Don't warn uninitialized variable in deadcode if deadcode has not been inferred +// by null analysis +public void testBug338234b() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int i;\n" + + " l: {\n" + + " if(false)\n" + + " break l;\n" + + " return;\n" + + " }\n" + + " i++; \n" + + " }\n" + + "}\n" + }, + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234 +// Warn uninitialized field in deadcode if deadcode has been inferred +// by null analysis +public void testBug338234c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public final int field1;\n" + + " {\n" + + " int i;\n" + + " String str = null;\n" + + " if(str != null)\n" + + " i = field1;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public final int field1;\n" + + " ^^^^^^\n" + + "The blank final field field1 may not have been initialized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " i = field1;\n" + + " ^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " i = field1;\n" + + " ^^^^^^\n" + + "The blank final field field1 may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234 +// Warn uninitialized field in deadcode if deadcode has been inferred +// by null analysis +public void testBug338234d() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " int i;\n" + + " String str = null;\n" + + " if(b){\n" + + " if(str == null)\n" + + " return;\n" + + " } else {\n" + + " i = 2;\n" + + " }\n" + + " i++;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " i++;\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// variant < 1.7 using Closeable: not closed +public void testCloseable1() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.WARNING); + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file); // not closed\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " FileReader fileReader = new FileReader(file); // not closed\n" + + " ^^^^^^^^^^\n" + + "Resource leak: 'fileReader' is never closed\n" + + "----------\n", + null, true, options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// variant < 1.7 using Closeable: resource is closed, cannot suggest try-with-resources < 1.7 +public void testCloseable2() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.WARNING); + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file); // not closed\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " fileReader.close();\n" + + " }\n" + + "}\n" + }, + "", + null, true, null, options, null); +} +// Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) +// return/break/continue inside anonymous class inside try-catch inside initializer +public void testLocalClassInInitializer1() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static {\n" + + " final int i=4;\n" + + " try {\n" + + " Runnable runner = new Runnable() {\n" + + " public void run() {\n" + + " switch (i) {" + + " case 4: break;\n" + + " }\n" + + " int j = i;\n" + + " while (j++ < 10) {\n" + + " if (j == 2) continue;\n" + + " if (j == 4) break;\n" + + " if (j == 6) return;\n" + + " }\n" + + " }\n" + + " };\n" + + " } catch (RuntimeException re) {}\n" + + " }\n" + + "}\n" + }, + ""); +} +// Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) +// break/continue illegally inside anonymous class inside loop (loop is out of scope for break/continue) +public void testLocalClassInInitializer2() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void f () {\n" + + " while (true) {\n" + + " class Inner1 {\n" + + " { if (true) break; }\n" + + " }\n" + + " new Inner1();\n" + + " }\n" + + " } \n" + + " void g () {\n" + + " outer: for (int i=1;true;i++) {\n" + + " class Inner2 {\n" + + " int j = 3;\n" + + " void foo () {\n" + + " if (2 == j) continue outer;\n" + + " else continue;\n" + + " }\n" + + " }\n" + + " new Inner2().foo();\n" + + " }\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " { if (true) break; }\n" + + " ^^^^^^\n" + + "break cannot be used outside of a loop or a switch\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " outer: for (int i=1;true;i++) {\n" + + " ^^^^^\n" + + "The label outer is never explicitly referenced\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " if (2 == j) continue outer;\n" + + " ^^^^^^^^^^^^^^^\n" + + "The label outer is missing\n" + + "----------\n" + + "4. ERROR in X.java (at line 16)\n" + + " else continue;\n" + + " ^^^^^^^^^\n" + + "continue cannot be used outside of a loop\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380313 +// Verify that the code runs fine with all compliance levels. +public void testBug380313() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public void foo() throws Exception {\n" + + " int i = 1;\n" + + " int j = 2;\n" + + " try {\n" + + " if ((bar() == 1)) {\n" + + " if ((i == 1)) {\n" + + " int n = bar();\n" + + " if (n == 35) {\n" + + " j = 2;\n" + + " } else {\n" + + " if (bar() > 0)\n" + + " return;\n" + + " }\n" + + " } else {\n" + + " throw new Exception();\n" + + " }\n" + + " } else {\n" + + " throw new Exception();\n" + + " }\n" + + " if (bar() == 0)\n" + + " return;\n" + + " } finally {\n" + + " bar();\n" + + " }\n" + + " }\n" + + "\n" + + " private int bar() {\n" + + " return 0;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380313 +// try with resources +// Verify that the code runs fine with all compliance levels. +public void testBug380313b() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + "public void foo() throws Exception {\n" + + " int i = 1;\n" + + " try {\n" + + " try (FileInputStream fis = new FileInputStream(\"\")) {\n" + + " if (i == 2)" + + " return;\n" + + " }\n" + + " if (i == 35) \n" + + " return;\n" + + " } catch(IOException e) {\n" + + " bar();\n" + + " } finally {\n" + + " bar();\n" + + " }\n" + + " }\n" + + "\n" + + " private int bar() {\n" + + " return 0;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380750 +// verify that s0 is not reported as uninitialized +public void testBug380750() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(String[] args) {\n" + + " String s0;\n" + + " for(String s : singleton(s0=\"\")) {\n" + + " System.out.println(s);\n" + + " }\n" + + " System.out.println(s0);\n" + + " }\n" + + " String[] singleton(String s) {\n" + + " return new String[] {s};\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=391517 +// java.lang.VerifyError on code that runs correctly in Eclipse 3.7 and eclipse 3.6 +public void testBug391517() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.PrintWriter;\n" + + "\n" + + "public class X {\n" + + "\n" + + " private static final int CONSTANT = 0;\n" + + "\n" + + " public static void main(String[] args) {\n" + + " // TODO Auto-generated method stub\n" + + "\n" + + " }\n" + + "\n" + + " static void addStackTrace(String prefix) {\n" + + " if (CONSTANT == 0) {\n" + + " return;\n" + + " }\n" + + " PrintWriter pw = null;\n" + + " new Exception().printStackTrace(pw);\n" + + " if (bar() == null) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "\n" + + " static Object bar() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=415997 +// Bug 415997 - java.lang.VerifyError: Expecting a stackmap frame at branch target +public void testBug415997a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object o = null;\n" + + " if (o == null)\n" + + " if (true)\n" + + " return;\n" + + " }\n" + + "}" + }, + ""); +} +public void testBug415997b() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object o = null;\n" + + " if (o == null) {}\n" + + " else\n" + + " if (true)\n" + + " return;\n" + + " }\n" + + "}" + }, + ""); +} +public void testBug415997c() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.println(ParseExpr11());\n" + + " }\n" + + " static final public Object ParseExpr11() throws Exception {\n" + + " Object expr;\n" + + " Object op = null;\n" + + " expr = ParseVarExpr();\n" + + " if (op == null) {\n" + + " if (true)\n" + + " return expr;\n" + + " }\n" + + " {\n" + + " throw new Exception(\"++/-- not supported in TUD Bantam Java.\");\n" + + " }\n" + + " }\n" + + " private static Object ParseVarExpr() {\n" + + " // TODO Auto-generated method stub\n" + + " return \"test\";\n" + + " }\n" + + "}" + }, + "test"); +} +public void testBug499809() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo {\n" + + " static void foo( ) {\n" + + " String _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, a, b,\n" + + " c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, s0, s1, s2, s3, s4, s5, s6, s7;\n" + + " Object ob = new Object();\n" + + " int int1 = 0, int2 = 2, int3, int4;\n" + + " if (ob != null) {\n" + + " int4 = 1;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}\n" + }, + "Done"); +} +public void testBug499809a() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo {\n" + + " static void foo( ) {\n" + + " String _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, a, b,\n" + + " c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, s0, s1, s2, s3, s4, s5, s6, s7;\n" + + " Object ob = new Object();\n" + + " int int1 = 0, int2 = 2, int3, int4;\n" + + " if (ob == null) {\n" + + " int1 = 1;\n" + + " } else {\n" + + " int4 = 1;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}\n" + }, + "Done"); +} +//Bug 506315 - ASTParser.createASTs() in StackMapFrame.addStackItem throws IllegalArgumentException +public void testBug506315() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runNegativeTest( + new String[] { + "Test.java", + "import java.util.function.Consumer;\n" + + "public class Test {\n" + + " public void test(String method) {\n" + + " String str;\n" + + " if (!method.equals(\"\")) {\n" + + " str = \"String\";\n" + + " str.concat(method);\n" + + " }\n" + + " new Consumer() {\n" + + " public void accept(String s) {\n" + + " str = \"String\";\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in Test.java (at line 11)\n" + + " str = \"String\";\n" + + " ^^^\n" + + "Cannot refer to the non-final local variable str defined in an enclosing scope\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in Test.java (at line 11)\n" + + " str = \"String\";\n" + + " ^^^\n" + + "Local variable str defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +public void _testBug533435() { + this.runConformTest( + new String[] { + "X.java", + "public interface X {}\n" + }, new ASTVisitor() { + public boolean visit(TypeDeclaration typeDeclaration, + CompilationUnitScope scope) { + if (new String(typeDeclaration.name).equals("X")) { + typeDeclaration.methods = + new AbstractMethodDeclaration[0]; + typeDeclaration.fields = new FieldDeclaration[0]; + scope.referenceContext.analyseCode(); + //should not fail + } + return true; + } + }); +} +public void testBug537804_comment0() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses an annotation + runConformTest( + new String[] { + "Test.java", + "public class Test\n" + + "{\n" + + " private boolean dummy;\n" + + "\n" + + "//Test\n" + + " void testMethod()\n" + + " {\n" + + " @SuppressWarnings(\"unused\")\n" + + " boolean action;\n" + + "\n" + + " OUTER:\n" + + " {\n" + + " while (true)\n" + + " {\n" + + " if (dummy)\n" + + " break OUTER;\n" + + "\n" + + " action = true;\n" + + " break;\n" + + " }\n" + + "\n" + + " return;\n" + + " }\n" + + "\n" + + " return;\n" + + " }\n" + + "\n" + + "//Main Method\n" + + " public static void main(String[] arguments)\n" + + " {\n" + + " //No operation\n" + + " }\n" + + "}\n" + }); +} +public void testBug537804_comment5() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test\n" + + "{\n" + + " private boolean dummy;\n" + + "\n" + + "//Test\n" + + " void testMethod()\n" + + " {\n" + + " boolean action;\n" + + "\n" + + " OUTER:\n" + + " {\n" + + " while (true)\n" + + " {\n" + + " if (dummy)\n" + + " break OUTER;\n" + + "\n" + + " action = true;\n" + + " break;\n" + + " }\n" + + "\n" + + " if (action) //Okay.\n" + + " noOp();\n" + + "\n" + + " return;\n" + + " }\n" + + "\n" + + " if (action) //Missing error: 'action' may not be initialized!\n" + + " noOp();\n" + + "\n" + + " return;\n" + + " }\n" + + " void noOp()\n" + + " {\n" + + " //No operation\n" + + " }\n" + + "\n" + + "//Main Method\n" + + " public static void main(String[] arguments)\n" + + " {\n" + + " //No operation\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 27)\n" + + " if (action) //Missing error: \'action\' may not be initialized!\n" + + " ^^^^^^\n" + + "The local variable action may not have been initialized\n" + + "----------\n"); +} +public void testBug548318_001() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " yield k;\n" + + " ^\n" + + "The local variable k may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " return k + it;\n" + + " ^\n" + + "The local variable k may not have been initialized\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " final int k;\n" + + "\n" + + " int it = switch (i) { \n" + + " case 1 -> {\n" + + " k = 1;\n" + + " yield k ;\n" + + " }\n" + + " default -> {\n" + + " yield k;\n" + + " }\n" + + " };\n" + + " return k + it;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); + +} +public void testBug548318_002() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " k = switch (i) { \n" + + " ^\n" + + "The final local variable k may already have been assigned\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " yield k;\n" + + " ^\n" + + "The local variable k may not have been initialized\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " final int k;\n" + + "\n" + + " k = switch (i) { \n" + + " case 1 -> {\n" + + " k = 1;\n" + + " yield k ;\n" + + " }\n" + + " default -> {\n" + + " yield k;\n" + + " }\n" + + " };\n" + + " return k;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/* + * k is definitely assigned - no errors on that front. + */ +public void testBug548318_003() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 23)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " final int k;\n" + + "\n" + + " int it = switch (i) { \n" + + " case 1 -> {\n" + + " k = 1;\n" + + " yield k ;\n" + + " }\n" + + " case 2 -> {\n" + + " k = 2;\n" + + " yield k ;\n" + + " }\n" + + " default -> {\n" + + " k = 3;\n" + + " yield k;\n" + + " }\n" + + " };\n" + + " return k;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +public void testBug548318_004() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " k = 1;\n" + + " ^\n" + + "The final local variable k cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " k = 2;\n" + + " ^\n" + + "The final local variable k cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " k = 3;\n" + + " ^\n" + + "The final local variable k cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n" + + "4. ERROR in X.java (at line 23)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " final int k = 1;\n" + + "\n" + + " int it = switch (i) { \n" + + " case 1 -> {\n" + + " k = 1;\n" + + " yield k ;\n" + + " }\n" + + " case 2 -> {\n" + + " k = 2;\n" + + " yield k ;\n" + + " }\n" + + " default -> {\n" + + " k = 3;\n" + + " yield k;\n" + + " }\n" + + " };\n" + + " return k;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +public void testBug548318_005() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " yield k ;\n" + + " ^\n" + + "The local variable k may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " return k;\n" + + " ^\n" + + "The local variable k may not have been initialized\n" + + "----------\n" + + "3. ERROR in X.java (at line 22)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " final int k;\n" + + "\n" + + " int it = switch (i) { \n" + + " case 1 -> {\n" + + " k = 1;\n" + + " yield k ;\n" + + " }\n" + + " case 2 -> {\n" + + " yield k ;\n" + + " }\n" + + " default -> {\n" + + " k = 3;\n" + + " yield k;\n" + + " }\n" + + " };\n" + + " return k;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * V is definitely assigned after a switch expression when true iff for every value yield statement with + * expression e in the switch block that may exit the switch expression, V is definitely assigned after e when true. + * V is definitely assigned after a switch expression when false iff for every value yield statement with + * expression e in the switch block that may exit the switch expression, V is definitely assigned after e when false. + */ +public void testBug548318_006() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " boolean b = switch (i) {\n" + + " case 1 :\n" + + " v = 1;\n" + + " yield true;\n" + + " case 2 : {\n" + + " v = 2;\n" + + " yield true;\n" + + " }\n" + + " default : {\n" + + " v = 3;\n" + + " yield false;\n" + + " }\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * V is definitely unassigned after a switch expression when true iff for every value yield statement with expression + * e in the switch block that may exit the switch expression, V is definitely unassigned before the value yield + * statement and V is definitely unassigned after e when true. + * V is definitely unassigned after a switch expression when false iff for every value yield statement with expression + * e in the switch block that may exit the switch expression, V is definitely unassigned before the value yield + * statement and V is definitely unassigned after e when false. + */ +public void testBug548318_007() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " return v + d;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " boolean b = switch (i) {\n" + + " case 1 :\n" + + " //v = 1;\n" + + " yield true;\n" + + " case 2 : {\n" + + " //v = 2;\n" + + " yield true;\n" + + " }\n" + + " default : {\n" + + " //v = 3;\n" + + " yield false;\n" + + " }\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement. + */ +public void testBug548318_008() { + if (!checkSwitchAllowedLevel()) + return; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v = 1;\n" + + " boolean b = switch (i) {\n" + + " case 1 :\n" + + " //v = 1;\n" + + " yield true;\n" + + " case 2 : {\n" + + " //v = 2;\n" + + " yield true;\n" + + " }\n" + + " default : {\n" + + " //v = 3;\n" + + " yield false;\n" + + " }\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement. + */ +public void testBug548318_009() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " boolean b = switch (v) {\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " boolean b = switch (v) {\n" + + " case 1 :\n" + + " v = 1;\n" + + " yield true;\n" + + " case 2 : {\n" + + " v = 2;\n" + + " yield true;\n" + + " }\n" + + " default : {\n" + + " v = 3;\n" + + " yield false;\n" + + " }\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * V is [un]assigned before the first statement of the first switch labeled statement group in the switch block + * iff V is [un]assigned after the selector expression. + */ +public void testBug548318_010() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " boolean b = switch (i + (v =1)) {\n" + + " case 1 :\n" + + " v += 1;\n" + + " yield true;\n" + + " case 2 : {\n" + + " v = 2;\n" + + " yield true;\n" + + " }\n" + + " default : {\n" + + " v = 3;\n" + + " yield false;\n" + + " }\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * V is [un]assigned before the first statement of the first switch labeled statement group in the switch block + * iff V is [un]assigned after the selector expression. + */ +public void testBug548318_011() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " v += 1;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " boolean b = switch (i) {\n" + + " case 1 :\n" + + " v += 1;\n" + + " yield true;\n" + + " case 2 : {\n" + + " v = 2;\n" + + " yield true;\n" + + " }\n" + + " default : {\n" + + " v = 3;\n" + + " yield false;\n" + + " }\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * V is [un]assigned before the first statement of any switch labeled statement group other than the first iff + * V is [un]assigned after the selector expression and V is [un]assigned after the preceding statement. + * and V is [un]assigned after the preceding statement + */ +public void testBug548318_012() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " boolean b = switch (i + (v =1)) {\n" + + " case 1 :\n" + + " v = 1;\n" + + " yield true;\n" + + " case 2 : {\n" + + " v += 2;\n" + + " yield true;\n" + + " }\n" + + " default : {\n" + + " v = 3;\n" + + " yield false;\n" + + " }\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * V is [un]assigned before the first statement of any switch labeled statement group other than the first iff + * V is [un]assigned after the selector expression and V is [un]assigned after the preceding statement. + * and V is [un]assigned after the preceding statement" + */ +public void testBug548318_012b() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " return v + d;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " boolean b = switch (i) {\n" + + " case 1 :i =1;\n" + + " case 2 : {\n" + + " yield true;\n" + + " }\n" + + " default : {\n" + + " v = 3;\n" + + " yield false;\n" + + " }\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * V is [un]assigned before the first statement of any switch labeled statement group other than the first iff + * V is [un]assigned after the selector expression and V is [un]assigned after the preceding statement. + * and V is [un]assigned after the preceding statement" needs to be checked + */ +public void testBug548318_013() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " v += 2;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " boolean b = switch (i) {\n" + + " case 1 :\n" + + " v = 1;\n" + + " yield true;\n" + + " case 2 : {\n" + + " v += 2;\n" + + " yield true;\n" + + " }\n" + + " default : {\n" + + " v = 3;\n" + + " yield false;\n" + + " }\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + "\n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * The following rules apply only if the switch block of a switch expression consists of switch labeled rules: + * V is definitely assigned after a switch expression when true iff for every switch labeled rule one of the following is true: + * It is a switch labeled expression e and V is definitely assigned after e when true. + * It is a switch labeled block b and for every value yield statement expression e contained in b that may exit the switch expression, + * V is definitely assigned after e when true. + * It is a switch labeled throw statement. + * + * V is definitely assigned after a switch expression when false iff for every switch labeled rule one of the following is true: + * It is a switch labeled expression e and V is definitely assigned after e when false. + * It is a switch labeled block b and for every value yield statement expression e contained in b that may exit the switch expression, + * V is definitely assigned after e when false. + * It is a switch labeled throw statement. + */ +public void testBug548318_014() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 23)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int v;\n" + + " boolean b = switch (i ) {\n" + + " case 0 -> (v = 1) != 0;\n" + + " case 1 -> (v = 1) == 0;\n" + + " case 2 -> {\n" + + " v = 2;\n" + + " yield true;\n" + + " }\n" + + " case 3 -> {\n" + + " v = 3;\n" + + " yield false;\n" + + " }\n" + + " default -> throw new IOException();\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * The following rules apply only if the switch block of a switch expression consists of switch labeled rules: + * V is definitely unassigned after a switch expression when true iff for every switch labeled rule one of the following is true: + * It is a switch labeled expression e and V is definitely unassigned after e when true . + * It is a switch labeled block b and for every value yield statement expression e contained in b that + * may exit the switch expression, V is definitely unassigned before the value yield statement and + * V is definitely unassigned after e when true. + * It is a switch labeled throw statement. + * + * V is definitely unassigned after a switch expression when false iff for every switch labeled rule one of the following is true: + * It is a switch labeled expression e and V is definitely unassigned after e when false. + * It is a switch labeled block b and for every value yield statement expression e contained in b that may + * exit the switch expression, V is definitely unassigned before the value yield statement and V is definitely unassigned + * after e when false. + * It is a switch labeled throw statement. + */ +public void testBug548318_015() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " return v + d;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int v;\n" + + " boolean b = switch (i ) {\n" + + " case 0 -> true;\n" + + " case 1 -> false;\n" + + " case 2 -> {\n" + + " yield true;\n" + + " }\n" + + " case 3 -> {\n" + + " yield false;\n" + + " }\n" + + " default -> throw new IOException();\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * V is [un]assigned before any switch labeled expression or statement in the switch + * block iff V is [un]assigned after the selector expression. + */ +public void testBug548318_016() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int v;\n" + + " boolean b = switch ((v = 1)) {\n" + + " case 0 -> v != 0;\n" + + " default -> throw new IOException();\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.7 , Suppose that the switch expression has result expressions e1, …, en, all of + * which are boolean-valued. + * The following rules apply only if the switch block of a switch expression consists of switch labeled rules: + * V is [un]assigned before any switch labeled expression or statement in the switch + * block iff V is [un]assigned after the selector expression. + */ +public void testBug548318_017() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case 0 -> v != 0;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " return v + d;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int v;\n" + + " boolean b = switch (i) {\n" + + " case 0 -> v != 0;\n" + + " default -> throw new IOException();\n" + + " };\n" + + " int d = b == true ? 0 : 1; \n" + + " return v + d;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, V is [un]assigned after a switch expression (15.28) iff all of the following are true: + * V is [un]assigned before every yield statement that may exit the switch statement. + * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the + * expression, block, or throw statement of the switch labeled rule. + */ +public void testBug548318_018() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " int t = switch (i) {\n" + + " case 0 : {\n" + + " v = 1; // definitely assigned before yield\n" + + " yield v;\n" + + " }\n" + + " case 2 : {\n" + + " yield v =1; // definitely assigned after e\n" + + " }\n" + + " default : {\n" + + " yield v = 2;\n" + + " }\n" + + " };\n" + + " return v + t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, V is [un]assigned after a switch expression (15.28) iff all of the following are true: + * V is [un]assigned before every yield statement that may exit the switch statement. + * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the + * expression, block, or throw statement of the switch labeled rule. + */ +public void testBug548318_019() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " return v + t;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " int t = switch (i) {\n" + + " case 0 : {\n" + + " yield 1;\n" + + " }\n" + + " case 2 : {\n" + + " yield 2;\n" + + " }\n" + + " default : {\n" + + " yield 3;\n" + + " }\n" + + " };\n" + + " return v + t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of + * which are boolean-valued. + * V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement. + */ +public void testBug548318_020() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v =1;\n" + + " int t = switch (v) {\n" + + " case 0 : {\n" + + " yield 1;\n" + + " }\n" + + " case 2 : {\n" + + " yield 2;\n" + + " }\n" + + " default : {\n" + + " yield 3;\n" + + " }\n" + + " };\n" + + " return t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of + * which are boolean-valued. + * V is [un]assigned before the selector expression iff V is [un]assigned before the switch statement. + */ +public void testBug548318_021() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int t = switch (v) {\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " int t = switch (v) {\n" + + " case 0 : {\n" + + " yield 1;\n" + + " }\n" + + " case 2 : {\n" + + " yield 2;\n" + + " }\n" + + " default : {\n" + + " yield 3;\n" + + " }\n" + + " };\n" + + " return t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of + * which are boolean-valued. + * V is [un]assigned before the first block statement of a switch labeled statement group (14.11.1) of a switch expression + * iff both of following are true: + * V is [un]assigned after the selector expression of the switch statement. + * If the switch labeled statement group is not the first in the switch block, + * V is [un]assigned after the last block statement of the preceding switch labeled statement group. + */ +public void testBug548318_022() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v =1;\n" + + " int t = switch (v) {\n" + + " case 0 : {\n" + + " yield v;\n" + + " }\n" + + " case 2 : {\n" + + " yield 2;\n" + + " }\n" + + " default : {\n" + + " yield 3;\n" + + " }\n" + + " };\n" + + " return t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of + * which are boolean-valued. + * V is [un]assigned before the first block statement of a switch labeled statement group (14.11.1) of a switch expression + * iff both of following are true: + * V is [un]assigned after the selector expression of the switch statement. + * If the switch labeled statement group is not the first in the switch block, + * V is [un]assigned after the last block statement of the preceding switch labeled statement group. + */ +public void testBug548318_023() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " yield v;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " int t = switch (i) {\n" + + " case 0 : {\n" + + " yield v;\n" + + " }\n" + + " case 2 : {\n" + + " yield 2;\n" + + " }\n" + + " default : {\n" + + " yield 3;\n" + + " }\n" + + " };\n" + + " return t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of + * which are boolean-valued. + * V is [un]assigned before the first block statement of a switch labeled statement group (14.11.1) of a switch expression + * iff both of following are true: + * V is [un]assigned after the selector expression of the switch statement. + * If the switch labeled statement group is not the first in the switch block, + * V is [un]assigned after the last block statement of the preceding switch labeled statement group. + */ +public void testBug548318_024() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " yield v;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v ;\n" + + " int t = switch (i) {\n" + + " case 0 : {\n" + + " yield 1;\n" + + " }\n" + + " case 2 : {\n" + + " yield v;\n" + + " }\n" + + " default : {\n" + + " yield 3;\n" + + " }\n" + + " };\n" + + " return t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, V is [un]assigned after a switch expression (15.28) iff all of the following are true: + * V is [un]assigned before every yield statement that may exit the switch statement. + * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the + * expression, block, or throw statement of the switch labeled rule. + */ +public void testBug548318_025() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int v ;\n" + + " int t = switch (i) {\n" + + " case 0 -> v = 1;\n" + + " case 2 -> {\n" + + " if (i > 1) {\n" + + " yield v = 2;\n" + + " }\n" + + " yield v = 3;\n" + + " }\n" + + " default -> throw new IOException();\n" + + " };\n" + + " return v + t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " // TODO Auto-generated catch block\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, V is [un]assigned after a switch expression (15.28) iff all of the following are true: + * V is [un]assigned before every yield statement that may exit the switch statement. + * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the + * expression, block, or throw statement of the switch labeled rule. + */ +public void testBug548318_026() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " return v + t;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int v ;\n" + + " int t = switch (i) {\n" + + " case 0 -> 1;\n" + + " case 2 -> {\n" + + " if (i > 1) {\n" + + " yield 2;\n" + + " }\n" + + " yield 3;\n" + + " }\n" + + " default -> throw new IOException();\n" + + " };\n" + + " return v + t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " // TODO Auto-generated catch block\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of + * which are boolean-valued. + * V is [un]assigned before the expression, block, or throw statement of a switch labeled rule of a + * switch expression iff V is [un]assigned after the selector expression of the switch expression. + */ +public void testBug548318_027() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int v ;\n" + + " int t = switch (v = 1) {\n" + + " case 0 -> v;\n" + + " case 2 -> {\n" + + " if (i > 1) {\n" + + " yield 2;\n" + + " }\n" + + " yield 3;\n" + + " }\n" + + " default -> throw new IOException();\n" + + " };\n" + + " return v + t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " // TODO Auto-generated catch block\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.1.8, Suppose that the switch expression has result expressions e1, …, en, not all of + * which are boolean-valued. + * V is [un]assigned before the expression, block, or throw statement of a switch labeled rule of a + * switch expression iff V is [un]assigned after the selector expression of the switch expression. + */ +public void testBug548318_028() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case 0 -> v;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int v ;\n" + + " int t = switch (i) {\n" + + " case 0 -> v;\n" + + " case 2 -> {\n" + + " if (i > 1) {\n" + + " yield 2;\n" + + " }\n" + + " yield 3;\n" + + " }\n" + + " default -> throw new IOException();\n" + + " };\n" + + " return t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " // TODO Auto-generated catch block\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.2.9, [tests the second rule - assigned] + * V is [un]assigned after a switch statement (14.11) iff all of the following are true: + * V is [un]assigned before every break statement that may exit the switch statement. + * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the + * expression, block, or throw statement of the switch labeled rule. + * If there is a switch labeled statement group (14.11.1) in the switch block, then V is [un]assigned + * after the last block statement of the last switch labeled statement group. + * If there is no default label in the switch block, or if the switch block ends with a switch label + * followed by }, then V is [un]assigned after the selector expression + */ +public void testBug548318_029() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int v ;\n" + + " switch (i) {\n" + + " case 0 -> {\n" + + " v = 0;\n" + + " }\n" + + " case 2 -> {\n" + + " if (i > 1) {\n" + + " v = 2;\n" + + " break;\n" + + " }\n" + + " v = 3;\n" + + " break;\n" + + " }\n" + + " default -> throw new IOException();\n" + + " };\n" + + " return v;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " // TODO Auto-generated catch block\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +/** + * From JLS 13 16.2.9, [tests the second rule - unassigned] + * V is [un]assigned after a switch statement (14.11) iff all of the following are true: + * V is [un]assigned before every break statement that may exit the switch statement. + * For each switch labeled rule (14.11.1) in the switch block, V is [un]assigned after the + * expression, block, or throw statement of the switch labeled rule. + * If there is a switch labeled statement group (14.11.1) in the switch block, then V is [un]assigned + * after the last block statement of the last switch labeled statement group. + * If there is no default label in the switch block, or if the switch block ends with a switch label + * followed by }, then V is [un]assigned after the selector expression + */ +public void testBug548318_030() { + if (!checkSwitchAllowedLevel()) + return; + setPresetPreviewOptions(); + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " return v;\n" + + " ^\n" + + "The local variable v may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 24)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + String[] testFiles = new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int v ;\n" + + " switch (i) {\n" + + " case 0 -> {\n" + + " v = 0;\n" + + " }\n" + + " case 2 -> {\n" + + " if (i > 1) {\n" + + " v = 2;\n" + + " break;\n" + + " }\n" + + " // v = 3;\n" + + " break;\n" + + " }\n" + + " default -> throw new IOException();\n" + + " };\n" + + " return v;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " Zork();\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " // TODO Auto-generated catch block\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true); +} +public static Class testClass() { + return FlowAnalysisTest.class; +} +} + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest8.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest8.java new file mode 100644 index 0000000000..87766c69c6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest8.java @@ -0,0 +1,632 @@ +/******************************************************************************* + * Copyright (c) 2013, 2020 GK Software AG and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.JavaCore; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class FlowAnalysisTest8 extends AbstractNullAnnotationTest { + +//Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which do not belong to the class are skipped... +static { +// TESTS_NAMES = new String[] { "testReferenceExpression" }; +// TESTS_NUMBERS = new int[] { 561 }; +// TESTS_RANGE = new int[] { 1, 2049 }; +} + +public FlowAnalysisTest8(String name) { + super(name); +} + +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} + +public static Class testClass() { + return FlowAnalysisTest8.class; +} + +// Lambda with elided args inherits null contract from the super method +public void testLambda_01() { + Map customOptions = getCompilerOptions(); + runNegativeTestWithLibs( + new String[] { + "ISAM.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface ISAM {\n" + + " @NonNull String toString(@NonNull String prefix, @Nullable Object o);\n" + + "}\n", + "X.java", + "public class X {\n" + + " void test() {\n" + + " ISAM printer = (p,o) -> p.concat(o.toString());\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " ISAM printer = (p,o) -> p.concat(o.toString());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type 'String' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " ISAM printer = (p,o) -> p.concat(o.toString());\n" + + " ^\n" + + "Potential null pointer access: this expression has a '@Nullable' type\n" + + "----------\n"); +} + +// Lambda with declared args violates null contract of super +public void testLambda_02() { + Map customOptions = getCompilerOptions(); + runNegativeTestWithLibs( + new String[] { + "ISAM.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface ISAM {\n" + + " void process(@NonNull Object nn, @Nullable Object n, Object u);\n" + + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void test() {\n" + + // try to override, illegal except for unchanged o1: + " ISAM printer = (@NonNull Object o1, @NonNull Object o2, @NonNull Object o3) -> System.out.println(2);\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " ISAM printer = (@NonNull Object o1, @NonNull Object o2, @NonNull Object o3) -> System.out.println(2);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter o2, inherited method from ISAM declares this parameter as @Nullable\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " ISAM printer = (@NonNull Object o1, @NonNull Object o2, @NonNull Object o3) -> System.out.println(2);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter o3, inherited method from ISAM does not constrain this parameter\n" + + "----------\n"); +} + +// Lambda with declared args inherits / modifies contract of super +public void testLambda_03() { + Map customOptions = getCompilerOptions(); + runNegativeTestWithLibs( + new String[] { + "ISAM.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface ISAM {\n" + + " void process(@NonNull Object nn, @Nullable Object n, Object u);\n" + + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void test() {\n" + + // fill-in all from super: + " ISAM printer1 = (Object o1, Object o2, Object o3) \n" + + " -> System.out.println(o1.toString()+o2.toString()+o3.toString());\n" + + // legal overrides: (however, @NonNull -> @Nullable is probably nonsense) + " ISAM printer3 = (@Nullable Object o1, @Nullable Object o2, @Nullable Object o3) \n" + + " -> System.out.println(o1.toString()+o2.toString()+o3.toString());\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " -> System.out.println(o1.toString()+o2.toString()+o3.toString());\n" + + " ^^\n" + + "Potential null pointer access: The variable o2 may be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " -> System.out.println(o1.toString()+o2.toString()+o3.toString());\n" + + " ^^\n" + + "Potential null pointer access: this expression has a '@Nullable' type\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " -> System.out.println(o1.toString()+o2.toString()+o3.toString());\n" + + " ^^\n" + + "Potential null pointer access: this expression has a '@Nullable' type\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " -> System.out.println(o1.toString()+o2.toString()+o3.toString());\n" + + " ^^\n" + + "Potential null pointer access: this expression has a '@Nullable' type\n" + + "----------\n"); +} + +// Lambda with declared args has illegal @NonNull an primitive argument +public void testLambda_04() { + Map customOptions = getCompilerOptions(); + runNegativeTestWithLibs( + new String[] { + "ISAM.java", + "public interface ISAM {\n" + + " void process(int i);\n" + + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void test() {\n" + + " ISAM printer1 = (@NonNull int i) \n" + + " -> System.out.println(i);\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " ISAM printer1 = (@NonNull int i) \n" + + " ^^^^^^^^\n" + + "The nullness annotation @NonNull is not applicable for the primitive type int\n" + + "----------\n"); +} + +// Lambda inherits null contract and has block with return statement +public void testLambda_05() { + Map customOptions = getCompilerOptions(); + runNegativeTestWithLibs( + new String[] { + "ISAM.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface ISAM {\n" + + " @NonNull String toString(Object o);\n" + + "}\n", + "X.java", + "public class X {\n" + + " void test() {\n" + + " ISAM printer = (o) -> {\n" + + " System.out.print(13);\n" + + " return null; // error\n" + + " };\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return null; // error\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); +} +// Lambda has no descriptor (overriding method from Object), don't bail out with NPE during analysis +public void testLambda_05a() { + Map customOptions = getCompilerOptions(); + runNegativeTest( + new String[] { + "ISAM.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface ISAM {\n" + + " @NonNull String toString();\n" + + "}\n", + "X.java", + "public class X {\n" + + " void test() {\n" + + " ISAM printer = () -> {\n" + + " System.out.print(13);\n" + + " return null;\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " ISAM printer = () -> {\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n", + this.LIBS, + true /*flush*/, + customOptions); +} +// Test flows with ReferenceExpression regarding: +// - definite assignment +// - unused local +public void testReferenceExpression1() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " public void bar();\n" + + "}\n", + "X.java", + "public class X {\n" + + " public void moo() {}\n" + + " public static void soo() {}\n" + + " void testAssignment() {\n" + + " X x;\n" + + " I i = x::moo; // x is unassigned\n" + + " i.bar();\n" + + " I i2 = X::soo;\n" + // OK + " }\n" + + " void testStatic() {\n" + + " X xs;\n" + + " I is = xs::soo;\n" + + " }\n" + + " void testUse() {\n" + + " X x1 = this, x2 = this; // x2 is not used, only x is\n" + + " I i = x1::moo;\n" + + " i.bar();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = x::moo; // x is unassigned\n" + + " ^\n" + + "The local variable x may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " I is = xs::soo;\n" + + " ^^^^^^^\n" + + "The method soo() from the type X should be accessed in a static way \n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " X x1 = this, x2 = this; // x2 is not used, only x is\n" + + " ^^\n" + + "The value of the local variable x2 is not used\n" + + "----------\n", + null/*libs*/, true/*flush*/, options); +} +public void testReferenceExpression_null_1() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTest( + false /*skipJavac */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError, + new String[] { + "I.java", + "public interface I {\n" + + " public void foo();\n" + + "}\n", + "X.java", + "public class X {\n" + + " public void bar() {}\n" + + " void test() {\n" + + " X x = null;\n" + + " I i = x::bar;\n" + + " i.foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " I i = x::bar;\n" + + " ^\n" + + "Null pointer access: The variable x can only be null at this location\n" + + "----------\n", + null/*libs*/, true/*flush*/, options); +} +public void testReferenceExpression_nullAnnotation_1() { + runNegativeTestWithLibs( + new String[] { + "I.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface I {\n" + + " public @NonNull String foo(@Nullable Object s);\n" + + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " public @Nullable String bar(@NonNull Object s) { return s.toString(); }\n" + + " void test() {\n" + + " I i = this::bar;\n" + + " System.out.print(i.foo(null));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " I i = this::bar;\n" + + " ^^^^^^^^^\n" + + "Null type mismatch at parameter 1: required '@NonNull Object' but provided '@Nullable Object' via method descriptor I.foo(Object)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " I i = this::bar;\n" + + " ^^^^^^^^^\n" + + "Null type mismatch at method return type: Method descriptor I.foo(Object) promises '@NonNull String' but referenced method provides '@Nullable String'\n" + + "----------\n"); +} +public void testReferenceExpression_nullAnnotation_2() { + runWarningTestWithLibs( + true, /* skipJavac */ + new String[] { + "I.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface I {\n" + + " public @NonNull String foo(@Nullable Object s);\n" + + "}\n", + "X.java", + "public class X {\n" + + " public String bar(Object s) { return s.toString(); }\n" + + " void test() {\n" + + " I i = this::bar;\n" + + " System.out.print(i.foo(null));\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " I i = this::bar;\n" + + " ^^^^^^^^^\n" + + "Null type safety at method return type: Method descriptor I.foo(Object) promises \'@NonNull String\' but referenced method provides \'String\'\n" + + "----------\n"); +} +public void testReferenceExpression_nullAnnotation_3() { + runNegativeTest( + new String[] { + "I.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface I {\n" + + " public @NonNull String foo(Object s);\n" + + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " public @NonNull String bar(@NonNull Object s) { return \"\"; }\n" + + " void test() {\n" + + " I i = this::bar;\n" + + " System.out.print(i.foo(null));\n" + + " }\n" + + " Zork zork;\n" + // make warning visible by forcing an error + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " I i = this::bar;\n" + + " ^^^^^^^^^\n" + + "Null type safety: parameter 1 provided via method descriptor I.foo(Object) needs unchecked conversion to conform to '@NonNull Object'\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + this.LIBS, + true /*flush*/, + getCompilerOptions()); +} +public void testBug535308a() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public int someTest() {\n" + + " boolean unused = false;\n" + + " final boolean thisIsFalse = false;\n" + + " if (getSomeValue() == thisIsFalse) {\n" + + " return 0;\n" + + " }\n" + + " return 1;\n" + + " }\n" + + " private boolean getSomeValue() {\n" + + " return true;\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " boolean unused = false;\n" + + " ^^^^^^\n" + + "The value of the local variable unused is not used\n" + + "----------\n"; + runner.classLibraries = + this.LIBS; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +public void testBug535308b() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public int someTest() {\n" + + " boolean unused = false;\n" + + " final boolean thisIsFalse = false;\n" + + " if (getSomeValue() != thisIsFalse) {\n" + + " return 0;\n" + + " }\n" + + " return 1;\n" + + " }\n" + + "\n" + + " private boolean getSomeValue() {\n" + + " return true;\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " boolean unused = false;\n" + + " ^^^^^^\n" + + "The value of the local variable unused is not used\n" + + "----------\n"; + runner.classLibraries = + this.LIBS; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +public void testBug535308c() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public int someTest() {\n" + + " boolean unused = false;\n" + + " final boolean thisIsFalse = false;\n" + + " if (thisIsFalse != getSomeValue()) {\n" + + " return 0;\n" + + " }\n" + + " return 1;\n" + + " }\n" + + "\n" + + " private boolean getSomeValue() {\n" + + " return true;\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " boolean unused = false;\n" + + " ^^^^^^\n" + + "The value of the local variable unused is not used\n" + + "----------\n"; + runner.classLibraries = + this.LIBS; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +public void testBug535308d() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public int someTest() {\n" + + " boolean unused = false;\n" + + " final boolean thisIsFalse = false;\n" + + " if (thisIsFalse == getSomeValue()) {\n" + + " return 0;\n" + + " }\n" + + " return 1;\n" + + " }\n" + + "\n" + + " private boolean getSomeValue() {\n" + + " return true;\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " boolean unused = false;\n" + + " ^^^^^^\n" + + "The value of the local variable unused is not used\n" + + "----------\n"; + runner.classLibraries = + this.LIBS; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +public void testBug535308e() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public int someTest() {\n" + + " boolean used = false;\n" + + " final boolean thisIsFalse = false;\n" + + " if (used == getSomeValue()) {\n" + + " return 0;\n" + + " }\n" + + " return 1;\n" + + " }\n" + + "\n" + + " private boolean getSomeValue() {\n" + + " return true;\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " final boolean thisIsFalse = false;\n" + + " ^^^^^^^^^^^\n" + + "The value of the local variable thisIsFalse is not used\n" + + "----------\n"; + runner.classLibraries = + this.LIBS; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +public void testBug474080() { + runNegativeTest( + new String[] { + "Test.java", + "import java.io.IOException;\n" + + "interface Config {\n" + + " double getTime(long l);\n" + + "}\n" + + "class MarketMaker {\n" + + " static double closeTime;\n" + + "}\n" + + "public class Test {\n" + + " boolean stopped;\n" + + " Config config;\n" + + " long tick() { return 0L; }\n" + + " void doStuff() {}\n" + + " public void start() {\n" + + " new Thread(() -> {\n" + + " while (eventSequence.running) {\n" + // unresolved + " try\n" + + " {\n" + + " double t = config.getTime(tick());\n" + + " if ((t >= MarketMaker.closeTime)) {\n" + + " if ((! stopped)) {\n" + + " try {\n" + + " System.out.println(\"Stopping...\");\n" + + " doStuff();\n" + + " Thread.sleep(250);\n" + + " System.out.println(\"Simulation finished\");\n" + + " } catch (InterruptedException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + +// " mainFrame.simulator.stop();\n" + + " stopped = true;\n" + + " }\n" + + " }\n" + + " }\n" + + " catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " }).start();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 15)\n" + + " while (eventSequence.running) {\n" + + " ^^^^^^^^^^^^^\n" + + "eventSequence cannot be resolved to a variable\n" + + "----------\n"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForStatementTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForStatementTest.java new file mode 100644 index 0000000000..fb65b32716 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForStatementTest.java @@ -0,0 +1,1788 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class ForStatementTest extends AbstractRegressionTest { + +public ForStatementTest(String name) { + super(name); +} + +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + return options; +} +// Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which do not belong to the class are skipped... +static { +// TESTS_NAMES = new String[] { "test000" }; +// TESTS_NUMBERS = new int[] { 45, 46 }; +// TESTS_RANGE = new int[] { 34, 38 }; +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Object m(int[] arg) {\n" + + " yyLoop: for (int i = 0;; ++i) {\n" + + " yyInner: for (;;) {\n" + + " switch (arg[i]) {\n" + + " case 0:\n" + + " break;\n" + + " case 1:\n" + + " continue yyInner;\n" + + " }\n" + + " if (i == 32)\n" + + " return arg;\n" + + " if (i == 12)\n" + + " break;\n" + + " continue yyLoop;\n" + + " }\n" + + " if (i == 32)\n" + + " return null;\n" + + " if (i > 7)\n" + + " continue yyLoop;\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=180471 +public void test002() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo2(int[] array) {\n" + + " for (int i = 0; i < array.length; i++) {\n" + + " System.out.println(i);\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + + String expectedOutput = + " // Method descriptor #15 ([I)V\n" + + " // Stack: 2, Locals: 3\n" + + " void foo2(int[] array);\n" + + " 0 iconst_0\n" + + " 1 istore_2 [i]\n" + + " 2 iload_2 [i]\n" + + " 3 aload_1 [array]\n" + + " 4 arraylength\n" + + " 5 if_icmpge 15\n" + + " 8 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 11 iload_2 [i]\n" + + " 12 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 15 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 8, line: 4]\n" + + " [pc: 15, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 16] local: this index: 0 type: X\n" + + " [pc: 0, pc: 16] local: array index: 1 type: int[]\n" + + " [pc: 2, pc: 15] local: i index: 2 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=180471 - variation +public void test003() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo4(int[] array) {\n" + + " do {\n" + + " System.out.println();\n" + + " break;\n" + + " } while (array.length > 0);\n" + + " }\n" + + "}\n", // ================= + }, + ""); + + String expectedOutput = + " // Method descriptor #15 ([I)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo4(int[] array);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 6 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 6, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 7] local: this index: 0 type: X\n" + + " [pc: 0, pc: 7] local: array index: 1 type: int[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=180471 - variation +public void test004() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo1(int[] array) {\n" + + " while (array.length > 0) {\n" + + " System.out.println();\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + + String expectedOutput = + " // Method descriptor #15 ([I)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo1(int[] array);\n" + + " 0 aload_1 [array]\n" + + " 1 arraylength\n" + + " 2 ifle 11\n" + + " 5 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 8 invokevirtual java.io.PrintStream.println() : void [22]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 5, line: 4]\n" + + " [pc: 11, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n" + + " [pc: 0, pc: 12] local: array index: 1 type: int[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=195317 +public void test005() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int mode = 1;\n" + + " loop: for (;;) {\n" + + " switch (mode) {\n" + + " case 2 :\n" + + " return;\n" + + " case 1:\n" + + " mode = 2;\n" + + " continue loop;\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + ""); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 istore_1 [mode]\n" + + " 2 iload_1 [mode]\n" + + " 3 tableswitch default: 27\n" + + " case 1: 25\n" + + " case 2: 24\n" + + " 24 return\n" + + " 25 iconst_2\n" + + " 26 istore_1 [mode]\n" + + " 27 goto 2\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 24, line: 7]\n" + + " [pc: 25, line: 9]\n" + + " [pc: 27, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 30] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 30] local: mode index: 1 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=457426 +public void test006() throws Exception { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + "\n" + + " public void show() {\n" + + " String s1 = \"\"; String s2 = \"\"; String s3 = \"\"; String s4 = \"\"; String s5 = \"\"; String s6 = \"\"; String s7 = \"\"; String s8 = \"\"; String s9 = \"\"; String s10 = \"\";\n" + + " String s11 = \"\"; String s12 = \"\"; String s13 = \"\"; String s14 = \"\"; String s15 = \"\"; String s16 = \"\"; String s17 = \"\"; String s18 = \"\"; String s19 = \"\"; String s20 = \"\";\n" + + " String s21 = \"\"; String s22 = \"\"; String s23 = \"\"; String s24 = \"\"; String s25 = \"\"; String s26 = \"\"; String s27 = \"\"; String s28 = \"\"; String s29 = \"\"; String s30 = \"\";\n" + + " String s31 = \"\"; String s32 = \"\"; String s33 = \"\"; String s34 = \"\"; String s35 = \"\"; String s36 = \"\"; String s37 = \"\"; String s38 = \"\"; String s39 = \"\"; String s40 = \"\";\n" + + " String s41 = \"\"; String s42 = \"\"; String s43 = \"\"; String s44 = \"\"; String s45 = \"\"; String s46 = \"\"; String s47 = \"\"; String s48 = \"\"; String s49 = \"\"; String s50 = \"\";\n" + + " String s51 = \"\"; String s52 = \"\"; String s53 = \"\"; String s54 = \"\"; String s55 = \"\"; String s56 = \"\"; String s57 = \"\"; String s58 = \"\"; String s59 = \"\"; String s60 = \"\";\n" + + " String s61 = \"\"; String s62 = \"\"; String s63 = \"\"; String s64 = \"\"; String s65 = \"\"; String s66 = \"\"; String s67 = \"\"; String s68 = \"\"; String s69 = \"\"; String s70 = \"\";\n" + + " String s71 = \"\"; String s72 = \"\"; String s73 = \"\"; String s74 = \"\"; String s75 = \"\"; String s76 = \"\"; String s77 = \"\"; String s78 = \"\"; String s79 = \"\"; String s80 = \"\";\n" + + " String s81 = \"\"; String s82 = \"\"; String s83 = \"\"; String s84 = \"\"; String s85 = \"\"; String s86 = \"\"; String s87 = \"\"; String s88 = \"\"; String s89 = \"\"; String s90 = \"\";\n" + + " String s91 = \"\"; String s92 = \"\"; String s93 = \"\"; String s94 = \"\"; String s95 = \"\"; String s96 = \"\"; String s97 = \"\"; String s98 = \"\"; String s99 = \"\"; String s100 = \"\";\n" + + " String s101 = \"\"; String s102 = \"\"; String s103 = \"\"; String s104 = \"\"; String s105 = \"\"; String s106 = \"\"; String s107 = \"\"; String s108 = \"\"; String s109 = \"\"; String s110 = \"\";\n" + + " String s111 = \"\"; String s112 = \"\"; String s113 = \"\"; String s114 = \"\"; String s115 = \"\"; String s116 = \"\"; String s117 = \"\"; String s118 = \"\"; String s119 = \"\"; String s120 = \"\";\n" + + " String s121 = \"\"; String s122 = \"\"; String s123 = \"\"; String s124 = \"\"; String s125 = \"\"; String s126 = \"\"; String s127 = \"\"; String s128 = \"\"; String s129 = \"\"; String s130 = \"\";\n" + + " String s131 = \"\"; String s132 = \"\"; String s133 = \"\"; String s134 = \"\"; String s135 = \"\"; String s136 = \"\"; String s137 = \"\"; String s138 = \"\"; String s139 = \"\"; String s140 = \"\";\n" + + " String s141 = \"\"; String s142 = \"\"; String s143 = \"\"; String s144 = \"\"; String s145 = \"\"; String s146 = \"\"; String s147 = \"\"; String s148 = \"\"; String s149 = \"\"; String s150 = \"\";\n" + + " String s151 = \"\"; String s152 = \"\"; String s153 = \"\"; String s154 = \"\"; String s155 = \"\"; String s156 = \"\"; String s157 = \"\"; String s158 = \"\"; String s159 = \"\"; String s160 = \"\";\n" + + " String s161 = \"\"; String s162 = \"\"; String s163 = \"\"; String s164 = \"\"; String s165 = \"\"; String s166 = \"\"; String s167 = \"\"; String s168 = \"\"; String s169 = \"\"; String s170 = \"\";\n" + + " String s171 = \"\"; String s172 = \"\"; String s173 = \"\"; String s174 = \"\"; String s175 = \"\"; String s176 = \"\"; String s177 = \"\"; String s178 = \"\"; String s179 = \"\"; String s180 = \"\";\n" + + " String s181 = \"\"; String s182 = \"\"; String s183 = \"\"; String s184 = \"\"; String s185 = \"\"; String s186 = \"\"; String s187 = \"\"; String s188 = \"\"; String s189 = \"\"; String s190 = \"\";\n" + + " String s191 = \"\"; String s192 = \"\"; String s193 = \"\"; String s194 = \"\"; String s195 = \"\"; String s196 = \"\"; String s197 = \"\"; String s198 = \"\"; String s199 = \"\"; String s200 = \"\";\n" + + " String s201 = \"\"; String s202 = \"\"; String s203 = \"\"; String s204 = \"\"; String s205 = \"\"; String s206 = \"\"; String s207 = \"\"; String s208 = \"\"; String s209 = \"\"; String s210 = \"\";\n" + + " String s211 = \"\"; String s212 = \"\"; String s213 = \"\"; String s214 = \"\"; String s215 = \"\"; String s216 = \"\"; String s217 = \"\"; String s218 = \"\"; String s219 = \"\"; String s220 = \"\";\n" + + " String s221 = \"\"; String s222 = \"\"; String s223 = \"\"; String s224 = \"\"; String s225 = \"\"; String s226 = \"\"; String s227 = \"\"; String s228 = \"\"; String s229 = \"\"; String s230 = \"\";\n" + + " String s231 = \"\"; String s232 = \"\"; String s233 = \"\"; String s234 = \"\"; String s235 = \"\"; String s236 = \"\"; String s237 = \"\"; String s238 = \"\"; String s239 = \"\"; String s240 = \"\";\n" + + " String s241 = \"\"; String s242 = \"\"; String s243 = \"\"; String s244 = \"\"; String s245 = \"\"; String s246 = \"\"; String s247 = \"\"; String s248 = \"\"; String s249 = \"\"; String s250 = \"\";\n" + + " String s251 = \"\"; String s252 = \"\";\n" + + "\n" + + " int size1 = 1;\n" + + " int size2 = 2;\n" + + " int size3 = 3;\n" + + "\n" + + " int[][][] intArray = new int[size1][size2][size3];\n" + + " \n" + + " for (int i = 0; i < size1; i++) {\n" + + " for (int j = 0; j < size2; j++) {\n" + + " boolean on = false;\n" + + " for (int k = 0; k < size3; k++) {\n" + + " intArray[i][j][k] = on ? 0 : 1;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().show();\n" + + " }\n" + + "}", + }, + "", + settings); + + String expectedOutput = + " public void show();\n" + + " 0 ldc [15]\n" + + " 2 astore_1 [s1]\n" + + " 3 ldc [15]\n" + + " 5 astore_2 [s2]\n" + + " 6 ldc [15]\n" + + " 8 astore_3 [s3]\n" + + " 9 ldc [15]\n" + + " 11 astore 4 [s4]\n" + + " 13 ldc [15]\n" + + " 15 astore 5 [s5]\n" + + " 17 ldc [15]\n" + + " 19 astore 6 [s6]\n" + + " 21 ldc [15]\n" + + " 23 astore 7 [s7]\n" + + " 25 ldc [15]\n" + + " 27 astore 8 [s8]\n" + + " 29 ldc [15]\n" + + " 31 astore 9 [s9]\n" + + " 33 ldc [15]\n" + + " 35 astore 10 [s10]\n" + + " 37 ldc [15]\n" + + " 39 astore 11 [s11]\n" + + " 41 ldc [15]\n" + + " 43 astore 12 [s12]\n" + + " 45 ldc [15]\n" + + " 47 astore 13 [s13]\n" + + " 49 ldc [15]\n" + + " 51 astore 14 [s14]\n" + + " 53 ldc [15]\n" + + " 55 astore 15 [s15]\n" + + " 57 ldc [15]\n" + + " 59 astore 16 [s16]\n" + + " 61 ldc [15]\n" + + " 63 astore 17 [s17]\n" + + " 65 ldc [15]\n" + + " 67 astore 18 [s18]\n" + + " 69 ldc [15]\n" + + " 71 astore 19 [s19]\n" + + " 73 ldc [15]\n" + + " 75 astore 20 [s20]\n" + + " 77 ldc [15]\n" + + " 79 astore 21 [s21]\n" + + " 81 ldc [15]\n" + + " 83 astore 22 [s22]\n" + + " 85 ldc [15]\n" + + " 87 astore 23 [s23]\n" + + " 89 ldc [15]\n" + + " 91 astore 24 [s24]\n" + + " 93 ldc [15]\n" + + " 95 astore 25 [s25]\n" + + " 97 ldc [15]\n" + + " 99 astore 26 [s26]\n" + + " 101 ldc [15]\n" + + " 103 astore 27 [s27]\n" + + " 105 ldc [15]\n" + + " 107 astore 28 [s28]\n" + + " 109 ldc [15]\n" + + " 111 astore 29 [s29]\n" + + " 113 ldc [15]\n" + + " 115 astore 30 [s30]\n" + + " 117 ldc [15]\n" + + " 119 astore 31 [s31]\n" + + " 121 ldc [15]\n" + + " 123 astore 32 [s32]\n" + + " 125 ldc [15]\n" + + " 127 astore 33 [s33]\n" + + " 129 ldc [15]\n" + + " 131 astore 34 [s34]\n" + + " 133 ldc [15]\n" + + " 135 astore 35 [s35]\n" + + " 137 ldc [15]\n" + + " 139 astore 36 [s36]\n" + + " 141 ldc [15]\n" + + " 143 astore 37 [s37]\n" + + " 145 ldc [15]\n" + + " 147 astore 38 [s38]\n" + + " 149 ldc [15]\n" + + " 151 astore 39 [s39]\n" + + " 153 ldc [15]\n" + + " 155 astore 40 [s40]\n" + + " 157 ldc [15]\n" + + " 159 astore 41 [s41]\n" + + " 161 ldc [15]\n" + + " 163 astore 42 [s42]\n" + + " 165 ldc [15]\n" + + " 167 astore 43 [s43]\n" + + " 169 ldc [15]\n" + + " 171 astore 44 [s44]\n" + + " 173 ldc [15]\n" + + " 175 astore 45 [s45]\n" + + " 177 ldc [15]\n" + + " 179 astore 46 [s46]\n" + + " 181 ldc [15]\n" + + " 183 astore 47 [s47]\n" + + " 185 ldc [15]\n" + + " 187 astore 48 [s48]\n" + + " 189 ldc [15]\n" + + " 191 astore 49 [s49]\n" + + " 193 ldc [15]\n" + + " 195 astore 50 [s50]\n" + + " 197 ldc [15]\n" + + " 199 astore 51 [s51]\n" + + " 201 ldc [15]\n" + + " 203 astore 52 [s52]\n" + + " 205 ldc [15]\n" + + " 207 astore 53 [s53]\n" + + " 209 ldc [15]\n" + + " 211 astore 54 [s54]\n" + + " 213 ldc [15]\n" + + " 215 astore 55 [s55]\n" + + " 217 ldc [15]\n" + + " 219 astore 56 [s56]\n" + + " 221 ldc [15]\n" + + " 223 astore 57 [s57]\n" + + " 225 ldc [15]\n" + + " 227 astore 58 [s58]\n" + + " 229 ldc [15]\n" + + " 231 astore 59 [s59]\n" + + " 233 ldc [15]\n" + + " 235 astore 60 [s60]\n" + + " 237 ldc [15]\n" + + " 239 astore 61 [s61]\n" + + " 241 ldc [15]\n" + + " 243 astore 62 [s62]\n" + + " 245 ldc [15]\n" + + " 247 astore 63 [s63]\n" + + " 249 ldc [15]\n" + + " 251 astore 64 [s64]\n" + + " 253 ldc [15]\n" + + " 255 astore 65 [s65]\n" + + " 257 ldc [15]\n" + + " 259 astore 66 [s66]\n" + + " 261 ldc [15]\n" + + " 263 astore 67 [s67]\n" + + " 265 ldc [15]\n" + + " 267 astore 68 [s68]\n" + + " 269 ldc [15]\n" + + " 271 astore 69 [s69]\n" + + " 273 ldc [15]\n" + + " 275 astore 70 [s70]\n" + + " 277 ldc [15]\n" + + " 279 astore 71 [s71]\n" + + " 281 ldc [15]\n" + + " 283 astore 72 [s72]\n" + + " 285 ldc [15]\n" + + " 287 astore 73 [s73]\n" + + " 289 ldc [15]\n" + + " 291 astore 74 [s74]\n" + + " 293 ldc [15]\n" + + " 295 astore 75 [s75]\n" + + " 297 ldc [15]\n" + + " 299 astore 76 [s76]\n" + + " 301 ldc [15]\n" + + " 303 astore 77 [s77]\n" + + " 305 ldc [15]\n" + + " 307 astore 78 [s78]\n" + + " 309 ldc [15]\n" + + " 311 astore 79 [s79]\n" + + " 313 ldc [15]\n" + + " 315 astore 80 [s80]\n" + + " 317 ldc [15]\n" + + " 319 astore 81 [s81]\n" + + " 321 ldc [15]\n" + + " 323 astore 82 [s82]\n" + + " 325 ldc [15]\n" + + " 327 astore 83 [s83]\n" + + " 329 ldc [15]\n" + + " 331 astore 84 [s84]\n" + + " 333 ldc [15]\n" + + " 335 astore 85 [s85]\n" + + " 337 ldc [15]\n" + + " 339 astore 86 [s86]\n" + + " 341 ldc [15]\n" + + " 343 astore 87 [s87]\n" + + " 345 ldc [15]\n" + + " 347 astore 88 [s88]\n" + + " 349 ldc [15]\n" + + " 351 astore 89 [s89]\n" + + " 353 ldc [15]\n" + + " 355 astore 90 [s90]\n" + + " 357 ldc [15]\n" + + " 359 astore 91 [s91]\n" + + " 361 ldc [15]\n" + + " 363 astore 92 [s92]\n" + + " 365 ldc [15]\n" + + " 367 astore 93 [s93]\n" + + " 369 ldc [15]\n" + + " 371 astore 94 [s94]\n" + + " 373 ldc [15]\n" + + " 375 astore 95 [s95]\n" + + " 377 ldc [15]\n" + + " 379 astore 96 [s96]\n" + + " 381 ldc [15]\n" + + " 383 astore 97 [s97]\n" + + " 385 ldc [15]\n" + + " 387 astore 98 [s98]\n" + + " 389 ldc [15]\n" + + " 391 astore 99 [s99]\n" + + " 393 ldc [15]\n" + + " 395 astore 100 [s100]\n" + + " 397 ldc [15]\n" + + " 399 astore 101 [s101]\n" + + " 401 ldc [15]\n" + + " 403 astore 102 [s102]\n" + + " 405 ldc [15]\n" + + " 407 astore 103 [s103]\n" + + " 409 ldc [15]\n" + + " 411 astore 104 [s104]\n" + + " 413 ldc [15]\n" + + " 415 astore 105 [s105]\n" + + " 417 ldc [15]\n" + + " 419 astore 106 [s106]\n" + + " 421 ldc [15]\n" + + " 423 astore 107 [s107]\n" + + " 425 ldc [15]\n" + + " 427 astore 108 [s108]\n" + + " 429 ldc [15]\n" + + " 431 astore 109 [s109]\n" + + " 433 ldc [15]\n" + + " 435 astore 110 [s110]\n" + + " 437 ldc [15]\n" + + " 439 astore 111 [s111]\n" + + " 441 ldc [15]\n" + + " 443 astore 112 [s112]\n" + + " 445 ldc [15]\n" + + " 447 astore 113 [s113]\n" + + " 449 ldc [15]\n" + + " 451 astore 114 [s114]\n" + + " 453 ldc [15]\n" + + " 455 astore 115 [s115]\n" + + " 457 ldc [15]\n" + + " 459 astore 116 [s116]\n" + + " 461 ldc [15]\n" + + " 463 astore 117 [s117]\n" + + " 465 ldc [15]\n" + + " 467 astore 118 [s118]\n" + + " 469 ldc [15]\n" + + " 471 astore 119 [s119]\n" + + " 473 ldc [15]\n" + + " 475 astore 120 [s120]\n" + + " 477 ldc [15]\n" + + " 479 astore 121 [s121]\n" + + " 481 ldc [15]\n" + + " 483 astore 122 [s122]\n" + + " 485 ldc [15]\n" + + " 487 astore 123 [s123]\n" + + " 489 ldc [15]\n" + + " 491 astore 124 [s124]\n" + + " 493 ldc [15]\n" + + " 495 astore 125 [s125]\n" + + " 497 ldc [15]\n" + + " 499 astore 126 [s126]\n" + + " 501 ldc [15]\n" + + " 503 astore 127 [s127]\n" + + " 505 ldc [15]\n" + + " 507 astore 128 [s128]\n" + + " 509 ldc [15]\n" + + " 511 astore 129 [s129]\n" + + " 513 ldc [15]\n" + + " 515 astore 130 [s130]\n" + + " 517 ldc [15]\n" + + " 519 astore 131 [s131]\n" + + " 521 ldc [15]\n" + + " 523 astore 132 [s132]\n" + + " 525 ldc [15]\n" + + " 527 astore 133 [s133]\n" + + " 529 ldc [15]\n" + + " 531 astore 134 [s134]\n" + + " 533 ldc [15]\n" + + " 535 astore 135 [s135]\n" + + " 537 ldc [15]\n" + + " 539 astore 136 [s136]\n" + + " 541 ldc [15]\n" + + " 543 astore 137 [s137]\n" + + " 545 ldc [15]\n" + + " 547 astore 138 [s138]\n" + + " 549 ldc [15]\n" + + " 551 astore 139 [s139]\n" + + " 553 ldc [15]\n" + + " 555 astore 140 [s140]\n" + + " 557 ldc [15]\n" + + " 559 astore 141 [s141]\n" + + " 561 ldc [15]\n" + + " 563 astore 142 [s142]\n" + + " 565 ldc [15]\n" + + " 567 astore 143 [s143]\n" + + " 569 ldc [15]\n" + + " 571 astore 144 [s144]\n" + + " 573 ldc [15]\n" + + " 575 astore 145 [s145]\n" + + " 577 ldc [15]\n" + + " 579 astore 146 [s146]\n" + + " 581 ldc [15]\n" + + " 583 astore 147 [s147]\n" + + " 585 ldc [15]\n" + + " 587 astore 148 [s148]\n" + + " 589 ldc [15]\n" + + " 591 astore 149 [s149]\n" + + " 593 ldc [15]\n" + + " 595 astore 150 [s150]\n" + + " 597 ldc [15]\n" + + " 599 astore 151 [s151]\n" + + " 601 ldc [15]\n" + + " 603 astore 152 [s152]\n" + + " 605 ldc [15]\n" + + " 607 astore 153 [s153]\n" + + " 609 ldc [15]\n" + + " 611 astore 154 [s154]\n" + + " 613 ldc [15]\n" + + " 615 astore 155 [s155]\n" + + " 617 ldc [15]\n" + + " 619 astore 156 [s156]\n" + + " 621 ldc [15]\n" + + " 623 astore 157 [s157]\n" + + " 625 ldc [15]\n" + + " 627 astore 158 [s158]\n" + + " 629 ldc [15]\n" + + " 631 astore 159 [s159]\n" + + " 633 ldc [15]\n" + + " 635 astore 160 [s160]\n" + + " 637 ldc [15]\n" + + " 639 astore 161 [s161]\n" + + " 641 ldc [15]\n" + + " 643 astore 162 [s162]\n" + + " 645 ldc [15]\n" + + " 647 astore 163 [s163]\n" + + " 649 ldc [15]\n" + + " 651 astore 164 [s164]\n" + + " 653 ldc [15]\n" + + " 655 astore 165 [s165]\n" + + " 657 ldc [15]\n" + + " 659 astore 166 [s166]\n" + + " 661 ldc [15]\n" + + " 663 astore 167 [s167]\n" + + " 665 ldc [15]\n" + + " 667 astore 168 [s168]\n" + + " 669 ldc [15]\n" + + " 671 astore 169 [s169]\n" + + " 673 ldc [15]\n" + + " 675 astore 170 [s170]\n" + + " 677 ldc [15]\n" + + " 679 astore 171 [s171]\n" + + " 681 ldc [15]\n" + + " 683 astore 172 [s172]\n" + + " 685 ldc [15]\n" + + " 687 astore 173 [s173]\n" + + " 689 ldc [15]\n" + + " 691 astore 174 [s174]\n" + + " 693 ldc [15]\n" + + " 695 astore 175 [s175]\n" + + " 697 ldc [15]\n" + + " 699 astore 176 [s176]\n" + + " 701 ldc [15]\n" + + " 703 astore 177 [s177]\n" + + " 705 ldc [15]\n" + + " 707 astore 178 [s178]\n" + + " 709 ldc [15]\n" + + " 711 astore 179 [s179]\n" + + " 713 ldc [15]\n" + + " 715 astore 180 [s180]\n" + + " 717 ldc [15]\n" + + " 719 astore 181 [s181]\n" + + " 721 ldc [15]\n" + + " 723 astore 182 [s182]\n" + + " 725 ldc [15]\n" + + " 727 astore 183 [s183]\n" + + " 729 ldc [15]\n" + + " 731 astore 184 [s184]\n" + + " 733 ldc [15]\n" + + " 735 astore 185 [s185]\n" + + " 737 ldc [15]\n" + + " 739 astore 186 [s186]\n" + + " 741 ldc [15]\n" + + " 743 astore 187 [s187]\n" + + " 745 ldc [15]\n" + + " 747 astore 188 [s188]\n" + + " 749 ldc [15]\n" + + " 751 astore 189 [s189]\n" + + " 753 ldc [15]\n" + + " 755 astore 190 [s190]\n" + + " 757 ldc [15]\n" + + " 759 astore 191 [s191]\n" + + " 761 ldc [15]\n" + + " 763 astore 192 [s192]\n" + + " 765 ldc [15]\n" + + " 767 astore 193 [s193]\n" + + " 769 ldc [15]\n" + + " 771 astore 194 [s194]\n" + + " 773 ldc [15]\n" + + " 775 astore 195 [s195]\n" + + " 777 ldc [15]\n" + + " 779 astore 196 [s196]\n" + + " 781 ldc [15]\n" + + " 783 astore 197 [s197]\n" + + " 785 ldc [15]\n" + + " 787 astore 198 [s198]\n" + + " 789 ldc [15]\n" + + " 791 astore 199 [s199]\n" + + " 793 ldc [15]\n" + + " 795 astore 200 [s200]\n" + + " 797 ldc [15]\n" + + " 799 astore 201 [s201]\n" + + " 801 ldc [15]\n" + + " 803 astore 202 [s202]\n" + + " 805 ldc [15]\n" + + " 807 astore 203 [s203]\n" + + " 809 ldc [15]\n" + + " 811 astore 204 [s204]\n" + + " 813 ldc [15]\n" + + " 815 astore 205 [s205]\n" + + " 817 ldc [15]\n" + + " 819 astore 206 [s206]\n" + + " 821 ldc [15]\n" + + " 823 astore 207 [s207]\n" + + " 825 ldc [15]\n" + + " 827 astore 208 [s208]\n" + + " 829 ldc [15]\n" + + " 831 astore 209 [s209]\n" + + " 833 ldc [15]\n" + + " 835 astore 210 [s210]\n" + + " 837 ldc [15]\n" + + " 839 astore 211 [s211]\n" + + " 841 ldc [15]\n" + + " 843 astore 212 [s212]\n" + + " 845 ldc [15]\n" + + " 847 astore 213 [s213]\n" + + " 849 ldc [15]\n" + + " 851 astore 214 [s214]\n" + + " 853 ldc [15]\n" + + " 855 astore 215 [s215]\n" + + " 857 ldc [15]\n" + + " 859 astore 216 [s216]\n" + + " 861 ldc [15]\n" + + " 863 astore 217 [s217]\n" + + " 865 ldc [15]\n" + + " 867 astore 218 [s218]\n" + + " 869 ldc [15]\n" + + " 871 astore 219 [s219]\n" + + " 873 ldc [15]\n" + + " 875 astore 220 [s220]\n" + + " 877 ldc [15]\n" + + " 879 astore 221 [s221]\n" + + " 881 ldc [15]\n" + + " 883 astore 222 [s222]\n" + + " 885 ldc [15]\n" + + " 887 astore 223 [s223]\n" + + " 889 ldc [15]\n" + + " 891 astore 224 [s224]\n" + + " 893 ldc [15]\n" + + " 895 astore 225 [s225]\n" + + " 897 ldc [15]\n" + + " 899 astore 226 [s226]\n" + + " 901 ldc [15]\n" + + " 903 astore 227 [s227]\n" + + " 905 ldc [15]\n" + + " 907 astore 228 [s228]\n" + + " 909 ldc [15]\n" + + " 911 astore 229 [s229]\n" + + " 913 ldc [15]\n" + + " 915 astore 230 [s230]\n" + + " 917 ldc [15]\n" + + " 919 astore 231 [s231]\n" + + " 921 ldc [15]\n" + + " 923 astore 232 [s232]\n" + + " 925 ldc [15]\n" + + " 927 astore 233 [s233]\n" + + " 929 ldc [15]\n" + + " 931 astore 234 [s234]\n" + + " 933 ldc [15]\n" + + " 935 astore 235 [s235]\n" + + " 937 ldc [15]\n" + + " 939 astore 236 [s236]\n" + + " 941 ldc [15]\n" + + " 943 astore 237 [s237]\n" + + " 945 ldc [15]\n" + + " 947 astore 238 [s238]\n" + + " 949 ldc [15]\n" + + " 951 astore 239 [s239]\n" + + " 953 ldc [15]\n" + + " 955 astore 240 [s240]\n" + + " 957 ldc [15]\n" + + " 959 astore 241 [s241]\n" + + " 961 ldc [15]\n" + + " 963 astore 242 [s242]\n" + + " 965 ldc [15]\n" + + " 967 astore 243 [s243]\n" + + " 969 ldc [15]\n" + + " 971 astore 244 [s244]\n" + + " 973 ldc [15]\n" + + " 975 astore 245 [s245]\n" + + " 977 ldc [15]\n" + + " 979 astore 246 [s246]\n" + + " 981 ldc [15]\n" + + " 983 astore 247 [s247]\n" + + " 985 ldc [15]\n" + + " 987 astore 248 [s248]\n" + + " 989 ldc [15]\n" + + " 991 astore 249 [s249]\n" + + " 993 ldc [15]\n" + + " 995 astore 250 [s250]\n" + + " 997 ldc [15]\n" + + " 999 astore 251 [s251]\n" + + " 1001 ldc [15]\n" + + " 1003 astore 252 [s252]\n" + + " 1005 iconst_1\n" + + " 1006 istore 253 [size1]\n" + + " 1008 iconst_2\n" + + " 1009 istore 254 [size2]\n" + + " 1011 iconst_3\n" + + " 1012 istore 255 [size3]\n" + + " 1014 iload 253 [size1]\n" + + " 1016 iload 254 [size2]\n" + + " 1018 iload 255 [size3]\n" + + " 1020 multianewarray int[][][] [17]\n" + + " 1024 wide\n" + + " 1025 astore 256 [intArray]\n" + + " 1028 iconst_0\n" + + " 1029 wide\n" + + " 1030 istore 257 [i]\n" + + " 1033 goto 1124\n" + + " 1036 iconst_0\n" + + " 1037 wide\n" + + " 1038 istore 258 [j]\n" + + " 1041 goto 1109\n" + + " 1044 iconst_0\n" + + " 1045 wide\n" + + " 1046 istore 259 [on]\n" + + " 1049 iconst_0\n" + + " 1050 wide\n" + + " 1051 istore 260 [k]\n" + + " 1054 goto 1094\n" + + " 1057 wide\n" + + " 1058 aload 256 [intArray]\n" + + " 1061 wide\n" + + " 1062 iload 257 [i]\n" + + " 1065 aaload\n" + + " 1066 wide\n" + + " 1067 iload 258 [j]\n" + + " 1070 aaload\n" + + " 1071 wide\n" + + " 1072 iload 260 [k]\n" + + " 1075 wide\n" + + " 1076 iload 259 [on]\n" + + " 1079 ifeq 1086\n" + + " 1082 iconst_0\n" + + " 1083 goto 1087\n" + + " 1086 iconst_1\n" + + " 1087 iastore\n" + + " 1088 wide\n" + + " 1089 iinc 260 1 [k]\n" + + " 1094 wide\n" + + " 1095 iload 260 [k]\n" + + " 1098 iload 255 [size3]\n" + + " 1100 if_icmplt 1057\n" + + " 1103 wide\n" + + " 1104 iinc 258 1 [j]\n" + + " 1109 wide\n" + + " 1110 iload 258 [j]\n" + + " 1113 iload 254 [size2]\n" + + " 1115 if_icmplt 1044\n" + + " 1118 wide\n" + + " 1119 iinc 257 1 [i]\n" + + " 1124 wide\n" + + " 1125 iload 257 [i]\n" + + " 1128 iload 253 [size1]\n" + + " 1130 if_icmplt 1036\n" + + " 1133 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 37, line: 5]\n" + + " [pc: 77, line: 6]\n" + + " [pc: 117, line: 7]\n" + + " [pc: 157, line: 8]\n" + + " [pc: 197, line: 9]\n" + + " [pc: 237, line: 10]\n" + + " [pc: 277, line: 11]\n" + + " [pc: 317, line: 12]\n" + + " [pc: 357, line: 13]\n" + + " [pc: 397, line: 14]\n" + + " [pc: 437, line: 15]\n" + + " [pc: 477, line: 16]\n" + + " [pc: 517, line: 17]\n" + + " [pc: 557, line: 18]\n" + + " [pc: 597, line: 19]\n" + + " [pc: 637, line: 20]\n" + + " [pc: 677, line: 21]\n" + + " [pc: 717, line: 22]\n" + + " [pc: 757, line: 23]\n" + + " [pc: 797, line: 24]\n" + + " [pc: 837, line: 25]\n" + + " [pc: 877, line: 26]\n" + + " [pc: 917, line: 27]\n" + + " [pc: 957, line: 28]\n" + + " [pc: 997, line: 29]\n" + + " [pc: 1005, line: 31]\n" + + " [pc: 1008, line: 32]\n" + + " [pc: 1011, line: 33]\n" + + " [pc: 1014, line: 35]\n" + + " [pc: 1028, line: 37]\n" + + " [pc: 1036, line: 38]\n" + + " [pc: 1044, line: 39]\n" + + " [pc: 1049, line: 40]\n" + + " [pc: 1057, line: 41]\n" + + " [pc: 1088, line: 40]\n" + + " [pc: 1103, line: 38]\n" + + " [pc: 1118, line: 37]\n" + + " [pc: 1133, line: 46]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1134] local: this index: 0 type: X\n" + + " [pc: 3, pc: 1134] local: s1 index: 1 type: java.lang.String\n" + + " [pc: 6, pc: 1134] local: s2 index: 2 type: java.lang.String\n" + + " [pc: 9, pc: 1134] local: s3 index: 3 type: java.lang.String\n" + + " [pc: 13, pc: 1134] local: s4 index: 4 type: java.lang.String\n" + + " [pc: 17, pc: 1134] local: s5 index: 5 type: java.lang.String\n" + + " [pc: 21, pc: 1134] local: s6 index: 6 type: java.lang.String\n" + + " [pc: 25, pc: 1134] local: s7 index: 7 type: java.lang.String\n" + + " [pc: 29, pc: 1134] local: s8 index: 8 type: java.lang.String\n" + + " [pc: 33, pc: 1134] local: s9 index: 9 type: java.lang.String\n" + + " [pc: 37, pc: 1134] local: s10 index: 10 type: java.lang.String\n" + + " [pc: 41, pc: 1134] local: s11 index: 11 type: java.lang.String\n" + + " [pc: 45, pc: 1134] local: s12 index: 12 type: java.lang.String\n" + + " [pc: 49, pc: 1134] local: s13 index: 13 type: java.lang.String\n" + + " [pc: 53, pc: 1134] local: s14 index: 14 type: java.lang.String\n" + + " [pc: 57, pc: 1134] local: s15 index: 15 type: java.lang.String\n" + + " [pc: 61, pc: 1134] local: s16 index: 16 type: java.lang.String\n" + + " [pc: 65, pc: 1134] local: s17 index: 17 type: java.lang.String\n" + + " [pc: 69, pc: 1134] local: s18 index: 18 type: java.lang.String\n" + + " [pc: 73, pc: 1134] local: s19 index: 19 type: java.lang.String\n" + + " [pc: 77, pc: 1134] local: s20 index: 20 type: java.lang.String\n" + + " [pc: 81, pc: 1134] local: s21 index: 21 type: java.lang.String\n" + + " [pc: 85, pc: 1134] local: s22 index: 22 type: java.lang.String\n" + + " [pc: 89, pc: 1134] local: s23 index: 23 type: java.lang.String\n" + + " [pc: 93, pc: 1134] local: s24 index: 24 type: java.lang.String\n" + + " [pc: 97, pc: 1134] local: s25 index: 25 type: java.lang.String\n" + + " [pc: 101, pc: 1134] local: s26 index: 26 type: java.lang.String\n" + + " [pc: 105, pc: 1134] local: s27 index: 27 type: java.lang.String\n" + + " [pc: 109, pc: 1134] local: s28 index: 28 type: java.lang.String\n" + + " [pc: 113, pc: 1134] local: s29 index: 29 type: java.lang.String\n" + + " [pc: 117, pc: 1134] local: s30 index: 30 type: java.lang.String\n" + + " [pc: 121, pc: 1134] local: s31 index: 31 type: java.lang.String\n" + + " [pc: 125, pc: 1134] local: s32 index: 32 type: java.lang.String\n" + + " [pc: 129, pc: 1134] local: s33 index: 33 type: java.lang.String\n" + + " [pc: 133, pc: 1134] local: s34 index: 34 type: java.lang.String\n" + + " [pc: 137, pc: 1134] local: s35 index: 35 type: java.lang.String\n" + + " [pc: 141, pc: 1134] local: s36 index: 36 type: java.lang.String\n" + + " [pc: 145, pc: 1134] local: s37 index: 37 type: java.lang.String\n" + + " [pc: 149, pc: 1134] local: s38 index: 38 type: java.lang.String\n" + + " [pc: 153, pc: 1134] local: s39 index: 39 type: java.lang.String\n" + + " [pc: 157, pc: 1134] local: s40 index: 40 type: java.lang.String\n" + + " [pc: 161, pc: 1134] local: s41 index: 41 type: java.lang.String\n" + + " [pc: 165, pc: 1134] local: s42 index: 42 type: java.lang.String\n" + + " [pc: 169, pc: 1134] local: s43 index: 43 type: java.lang.String\n" + + " [pc: 173, pc: 1134] local: s44 index: 44 type: java.lang.String\n" + + " [pc: 177, pc: 1134] local: s45 index: 45 type: java.lang.String\n" + + " [pc: 181, pc: 1134] local: s46 index: 46 type: java.lang.String\n" + + " [pc: 185, pc: 1134] local: s47 index: 47 type: java.lang.String\n" + + " [pc: 189, pc: 1134] local: s48 index: 48 type: java.lang.String\n" + + " [pc: 193, pc: 1134] local: s49 index: 49 type: java.lang.String\n" + + " [pc: 197, pc: 1134] local: s50 index: 50 type: java.lang.String\n" + + " [pc: 201, pc: 1134] local: s51 index: 51 type: java.lang.String\n" + + " [pc: 205, pc: 1134] local: s52 index: 52 type: java.lang.String\n" + + " [pc: 209, pc: 1134] local: s53 index: 53 type: java.lang.String\n" + + " [pc: 213, pc: 1134] local: s54 index: 54 type: java.lang.String\n" + + " [pc: 217, pc: 1134] local: s55 index: 55 type: java.lang.String\n" + + " [pc: 221, pc: 1134] local: s56 index: 56 type: java.lang.String\n" + + " [pc: 225, pc: 1134] local: s57 index: 57 type: java.lang.String\n" + + " [pc: 229, pc: 1134] local: s58 index: 58 type: java.lang.String\n" + + " [pc: 233, pc: 1134] local: s59 index: 59 type: java.lang.String\n" + + " [pc: 237, pc: 1134] local: s60 index: 60 type: java.lang.String\n" + + " [pc: 241, pc: 1134] local: s61 index: 61 type: java.lang.String\n" + + " [pc: 245, pc: 1134] local: s62 index: 62 type: java.lang.String\n" + + " [pc: 249, pc: 1134] local: s63 index: 63 type: java.lang.String\n" + + " [pc: 253, pc: 1134] local: s64 index: 64 type: java.lang.String\n" + + " [pc: 257, pc: 1134] local: s65 index: 65 type: java.lang.String\n" + + " [pc: 261, pc: 1134] local: s66 index: 66 type: java.lang.String\n" + + " [pc: 265, pc: 1134] local: s67 index: 67 type: java.lang.String\n" + + " [pc: 269, pc: 1134] local: s68 index: 68 type: java.lang.String\n" + + " [pc: 273, pc: 1134] local: s69 index: 69 type: java.lang.String\n" + + " [pc: 277, pc: 1134] local: s70 index: 70 type: java.lang.String\n" + + " [pc: 281, pc: 1134] local: s71 index: 71 type: java.lang.String\n" + + " [pc: 285, pc: 1134] local: s72 index: 72 type: java.lang.String\n" + + " [pc: 289, pc: 1134] local: s73 index: 73 type: java.lang.String\n" + + " [pc: 293, pc: 1134] local: s74 index: 74 type: java.lang.String\n" + + " [pc: 297, pc: 1134] local: s75 index: 75 type: java.lang.String\n" + + " [pc: 301, pc: 1134] local: s76 index: 76 type: java.lang.String\n" + + " [pc: 305, pc: 1134] local: s77 index: 77 type: java.lang.String\n" + + " [pc: 309, pc: 1134] local: s78 index: 78 type: java.lang.String\n" + + " [pc: 313, pc: 1134] local: s79 index: 79 type: java.lang.String\n" + + " [pc: 317, pc: 1134] local: s80 index: 80 type: java.lang.String\n" + + " [pc: 321, pc: 1134] local: s81 index: 81 type: java.lang.String\n" + + " [pc: 325, pc: 1134] local: s82 index: 82 type: java.lang.String\n" + + " [pc: 329, pc: 1134] local: s83 index: 83 type: java.lang.String\n" + + " [pc: 333, pc: 1134] local: s84 index: 84 type: java.lang.String\n" + + " [pc: 337, pc: 1134] local: s85 index: 85 type: java.lang.String\n" + + " [pc: 341, pc: 1134] local: s86 index: 86 type: java.lang.String\n" + + " [pc: 345, pc: 1134] local: s87 index: 87 type: java.lang.String\n" + + " [pc: 349, pc: 1134] local: s88 index: 88 type: java.lang.String\n" + + " [pc: 353, pc: 1134] local: s89 index: 89 type: java.lang.String\n" + + " [pc: 357, pc: 1134] local: s90 index: 90 type: java.lang.String\n" + + " [pc: 361, pc: 1134] local: s91 index: 91 type: java.lang.String\n" + + " [pc: 365, pc: 1134] local: s92 index: 92 type: java.lang.String\n" + + " [pc: 369, pc: 1134] local: s93 index: 93 type: java.lang.String\n" + + " [pc: 373, pc: 1134] local: s94 index: 94 type: java.lang.String\n" + + " [pc: 377, pc: 1134] local: s95 index: 95 type: java.lang.String\n" + + " [pc: 381, pc: 1134] local: s96 index: 96 type: java.lang.String\n" + + " [pc: 385, pc: 1134] local: s97 index: 97 type: java.lang.String\n" + + " [pc: 389, pc: 1134] local: s98 index: 98 type: java.lang.String\n" + + " [pc: 393, pc: 1134] local: s99 index: 99 type: java.lang.String\n" + + " [pc: 397, pc: 1134] local: s100 index: 100 type: java.lang.String\n" + + " [pc: 401, pc: 1134] local: s101 index: 101 type: java.lang.String\n" + + " [pc: 405, pc: 1134] local: s102 index: 102 type: java.lang.String\n" + + " [pc: 409, pc: 1134] local: s103 index: 103 type: java.lang.String\n" + + " [pc: 413, pc: 1134] local: s104 index: 104 type: java.lang.String\n" + + " [pc: 417, pc: 1134] local: s105 index: 105 type: java.lang.String\n" + + " [pc: 421, pc: 1134] local: s106 index: 106 type: java.lang.String\n" + + " [pc: 425, pc: 1134] local: s107 index: 107 type: java.lang.String\n" + + " [pc: 429, pc: 1134] local: s108 index: 108 type: java.lang.String\n" + + " [pc: 433, pc: 1134] local: s109 index: 109 type: java.lang.String\n" + + " [pc: 437, pc: 1134] local: s110 index: 110 type: java.lang.String\n" + + " [pc: 441, pc: 1134] local: s111 index: 111 type: java.lang.String\n" + + " [pc: 445, pc: 1134] local: s112 index: 112 type: java.lang.String\n" + + " [pc: 449, pc: 1134] local: s113 index: 113 type: java.lang.String\n" + + " [pc: 453, pc: 1134] local: s114 index: 114 type: java.lang.String\n" + + " [pc: 457, pc: 1134] local: s115 index: 115 type: java.lang.String\n" + + " [pc: 461, pc: 1134] local: s116 index: 116 type: java.lang.String\n" + + " [pc: 465, pc: 1134] local: s117 index: 117 type: java.lang.String\n" + + " [pc: 469, pc: 1134] local: s118 index: 118 type: java.lang.String\n" + + " [pc: 473, pc: 1134] local: s119 index: 119 type: java.lang.String\n" + + " [pc: 477, pc: 1134] local: s120 index: 120 type: java.lang.String\n" + + " [pc: 481, pc: 1134] local: s121 index: 121 type: java.lang.String\n" + + " [pc: 485, pc: 1134] local: s122 index: 122 type: java.lang.String\n" + + " [pc: 489, pc: 1134] local: s123 index: 123 type: java.lang.String\n" + + " [pc: 493, pc: 1134] local: s124 index: 124 type: java.lang.String\n" + + " [pc: 497, pc: 1134] local: s125 index: 125 type: java.lang.String\n" + + " [pc: 501, pc: 1134] local: s126 index: 126 type: java.lang.String\n" + + " [pc: 505, pc: 1134] local: s127 index: 127 type: java.lang.String\n" + + " [pc: 509, pc: 1134] local: s128 index: 128 type: java.lang.String\n" + + " [pc: 513, pc: 1134] local: s129 index: 129 type: java.lang.String\n" + + " [pc: 517, pc: 1134] local: s130 index: 130 type: java.lang.String\n" + + " [pc: 521, pc: 1134] local: s131 index: 131 type: java.lang.String\n" + + " [pc: 525, pc: 1134] local: s132 index: 132 type: java.lang.String\n" + + " [pc: 529, pc: 1134] local: s133 index: 133 type: java.lang.String\n" + + " [pc: 533, pc: 1134] local: s134 index: 134 type: java.lang.String\n" + + " [pc: 537, pc: 1134] local: s135 index: 135 type: java.lang.String\n" + + " [pc: 541, pc: 1134] local: s136 index: 136 type: java.lang.String\n" + + " [pc: 545, pc: 1134] local: s137 index: 137 type: java.lang.String\n" + + " [pc: 549, pc: 1134] local: s138 index: 138 type: java.lang.String\n" + + " [pc: 553, pc: 1134] local: s139 index: 139 type: java.lang.String\n" + + " [pc: 557, pc: 1134] local: s140 index: 140 type: java.lang.String\n" + + " [pc: 561, pc: 1134] local: s141 index: 141 type: java.lang.String\n" + + " [pc: 565, pc: 1134] local: s142 index: 142 type: java.lang.String\n" + + " [pc: 569, pc: 1134] local: s143 index: 143 type: java.lang.String\n" + + " [pc: 573, pc: 1134] local: s144 index: 144 type: java.lang.String\n" + + " [pc: 577, pc: 1134] local: s145 index: 145 type: java.lang.String\n" + + " [pc: 581, pc: 1134] local: s146 index: 146 type: java.lang.String\n" + + " [pc: 585, pc: 1134] local: s147 index: 147 type: java.lang.String\n" + + " [pc: 589, pc: 1134] local: s148 index: 148 type: java.lang.String\n" + + " [pc: 593, pc: 1134] local: s149 index: 149 type: java.lang.String\n" + + " [pc: 597, pc: 1134] local: s150 index: 150 type: java.lang.String\n" + + " [pc: 601, pc: 1134] local: s151 index: 151 type: java.lang.String\n" + + " [pc: 605, pc: 1134] local: s152 index: 152 type: java.lang.String\n" + + " [pc: 609, pc: 1134] local: s153 index: 153 type: java.lang.String\n" + + " [pc: 613, pc: 1134] local: s154 index: 154 type: java.lang.String\n" + + " [pc: 617, pc: 1134] local: s155 index: 155 type: java.lang.String\n" + + " [pc: 621, pc: 1134] local: s156 index: 156 type: java.lang.String\n" + + " [pc: 625, pc: 1134] local: s157 index: 157 type: java.lang.String\n" + + " [pc: 629, pc: 1134] local: s158 index: 158 type: java.lang.String\n" + + " [pc: 633, pc: 1134] local: s159 index: 159 type: java.lang.String\n" + + " [pc: 637, pc: 1134] local: s160 index: 160 type: java.lang.String\n" + + " [pc: 641, pc: 1134] local: s161 index: 161 type: java.lang.String\n" + + " [pc: 645, pc: 1134] local: s162 index: 162 type: java.lang.String\n" + + " [pc: 649, pc: 1134] local: s163 index: 163 type: java.lang.String\n" + + " [pc: 653, pc: 1134] local: s164 index: 164 type: java.lang.String\n" + + " [pc: 657, pc: 1134] local: s165 index: 165 type: java.lang.String\n" + + " [pc: 661, pc: 1134] local: s166 index: 166 type: java.lang.String\n" + + " [pc: 665, pc: 1134] local: s167 index: 167 type: java.lang.String\n" + + " [pc: 669, pc: 1134] local: s168 index: 168 type: java.lang.String\n" + + " [pc: 673, pc: 1134] local: s169 index: 169 type: java.lang.String\n" + + " [pc: 677, pc: 1134] local: s170 index: 170 type: java.lang.String\n" + + " [pc: 681, pc: 1134] local: s171 index: 171 type: java.lang.String\n" + + " [pc: 685, pc: 1134] local: s172 index: 172 type: java.lang.String\n" + + " [pc: 689, pc: 1134] local: s173 index: 173 type: java.lang.String\n" + + " [pc: 693, pc: 1134] local: s174 index: 174 type: java.lang.String\n" + + " [pc: 697, pc: 1134] local: s175 index: 175 type: java.lang.String\n" + + " [pc: 701, pc: 1134] local: s176 index: 176 type: java.lang.String\n" + + " [pc: 705, pc: 1134] local: s177 index: 177 type: java.lang.String\n" + + " [pc: 709, pc: 1134] local: s178 index: 178 type: java.lang.String\n" + + " [pc: 713, pc: 1134] local: s179 index: 179 type: java.lang.String\n" + + " [pc: 717, pc: 1134] local: s180 index: 180 type: java.lang.String\n" + + " [pc: 721, pc: 1134] local: s181 index: 181 type: java.lang.String\n" + + " [pc: 725, pc: 1134] local: s182 index: 182 type: java.lang.String\n" + + " [pc: 729, pc: 1134] local: s183 index: 183 type: java.lang.String\n" + + " [pc: 733, pc: 1134] local: s184 index: 184 type: java.lang.String\n" + + " [pc: 737, pc: 1134] local: s185 index: 185 type: java.lang.String\n" + + " [pc: 741, pc: 1134] local: s186 index: 186 type: java.lang.String\n" + + " [pc: 745, pc: 1134] local: s187 index: 187 type: java.lang.String\n" + + " [pc: 749, pc: 1134] local: s188 index: 188 type: java.lang.String\n" + + " [pc: 753, pc: 1134] local: s189 index: 189 type: java.lang.String\n" + + " [pc: 757, pc: 1134] local: s190 index: 190 type: java.lang.String\n" + + " [pc: 761, pc: 1134] local: s191 index: 191 type: java.lang.String\n" + + " [pc: 765, pc: 1134] local: s192 index: 192 type: java.lang.String\n" + + " [pc: 769, pc: 1134] local: s193 index: 193 type: java.lang.String\n" + + " [pc: 773, pc: 1134] local: s194 index: 194 type: java.lang.String\n" + + " [pc: 777, pc: 1134] local: s195 index: 195 type: java.lang.String\n" + + " [pc: 781, pc: 1134] local: s196 index: 196 type: java.lang.String\n" + + " [pc: 785, pc: 1134] local: s197 index: 197 type: java.lang.String\n" + + " [pc: 789, pc: 1134] local: s198 index: 198 type: java.lang.String\n" + + " [pc: 793, pc: 1134] local: s199 index: 199 type: java.lang.String\n" + + " [pc: 797, pc: 1134] local: s200 index: 200 type: java.lang.String\n" + + " [pc: 801, pc: 1134] local: s201 index: 201 type: java.lang.String\n" + + " [pc: 805, pc: 1134] local: s202 index: 202 type: java.lang.String\n" + + " [pc: 809, pc: 1134] local: s203 index: 203 type: java.lang.String\n" + + " [pc: 813, pc: 1134] local: s204 index: 204 type: java.lang.String\n" + + " [pc: 817, pc: 1134] local: s205 index: 205 type: java.lang.String\n" + + " [pc: 821, pc: 1134] local: s206 index: 206 type: java.lang.String\n" + + " [pc: 825, pc: 1134] local: s207 index: 207 type: java.lang.String\n" + + " [pc: 829, pc: 1134] local: s208 index: 208 type: java.lang.String\n" + + " [pc: 833, pc: 1134] local: s209 index: 209 type: java.lang.String\n" + + " [pc: 837, pc: 1134] local: s210 index: 210 type: java.lang.String\n" + + " [pc: 841, pc: 1134] local: s211 index: 211 type: java.lang.String\n" + + " [pc: 845, pc: 1134] local: s212 index: 212 type: java.lang.String\n" + + " [pc: 849, pc: 1134] local: s213 index: 213 type: java.lang.String\n" + + " [pc: 853, pc: 1134] local: s214 index: 214 type: java.lang.String\n" + + " [pc: 857, pc: 1134] local: s215 index: 215 type: java.lang.String\n" + + " [pc: 861, pc: 1134] local: s216 index: 216 type: java.lang.String\n" + + " [pc: 865, pc: 1134] local: s217 index: 217 type: java.lang.String\n" + + " [pc: 869, pc: 1134] local: s218 index: 218 type: java.lang.String\n" + + " [pc: 873, pc: 1134] local: s219 index: 219 type: java.lang.String\n" + + " [pc: 877, pc: 1134] local: s220 index: 220 type: java.lang.String\n" + + " [pc: 881, pc: 1134] local: s221 index: 221 type: java.lang.String\n" + + " [pc: 885, pc: 1134] local: s222 index: 222 type: java.lang.String\n" + + " [pc: 889, pc: 1134] local: s223 index: 223 type: java.lang.String\n" + + " [pc: 893, pc: 1134] local: s224 index: 224 type: java.lang.String\n" + + " [pc: 897, pc: 1134] local: s225 index: 225 type: java.lang.String\n" + + " [pc: 901, pc: 1134] local: s226 index: 226 type: java.lang.String\n" + + " [pc: 905, pc: 1134] local: s227 index: 227 type: java.lang.String\n" + + " [pc: 909, pc: 1134] local: s228 index: 228 type: java.lang.String\n" + + " [pc: 913, pc: 1134] local: s229 index: 229 type: java.lang.String\n" + + " [pc: 917, pc: 1134] local: s230 index: 230 type: java.lang.String\n" + + " [pc: 921, pc: 1134] local: s231 index: 231 type: java.lang.String\n" + + " [pc: 925, pc: 1134] local: s232 index: 232 type: java.lang.String\n" + + " [pc: 929, pc: 1134] local: s233 index: 233 type: java.lang.String\n" + + " [pc: 933, pc: 1134] local: s234 index: 234 type: java.lang.String\n" + + " [pc: 937, pc: 1134] local: s235 index: 235 type: java.lang.String\n" + + " [pc: 941, pc: 1134] local: s236 index: 236 type: java.lang.String\n" + + " [pc: 945, pc: 1134] local: s237 index: 237 type: java.lang.String\n" + + " [pc: 949, pc: 1134] local: s238 index: 238 type: java.lang.String\n" + + " [pc: 953, pc: 1134] local: s239 index: 239 type: java.lang.String\n" + + " [pc: 957, pc: 1134] local: s240 index: 240 type: java.lang.String\n" + + " [pc: 961, pc: 1134] local: s241 index: 241 type: java.lang.String\n" + + " [pc: 965, pc: 1134] local: s242 index: 242 type: java.lang.String\n" + + " [pc: 969, pc: 1134] local: s243 index: 243 type: java.lang.String\n" + + " [pc: 973, pc: 1134] local: s244 index: 244 type: java.lang.String\n" + + " [pc: 977, pc: 1134] local: s245 index: 245 type: java.lang.String\n" + + " [pc: 981, pc: 1134] local: s246 index: 246 type: java.lang.String\n" + + " [pc: 985, pc: 1134] local: s247 index: 247 type: java.lang.String\n" + + " [pc: 989, pc: 1134] local: s248 index: 248 type: java.lang.String\n" + + " [pc: 993, pc: 1134] local: s249 index: 249 type: java.lang.String\n" + + " [pc: 997, pc: 1134] local: s250 index: 250 type: java.lang.String\n" + + " [pc: 1001, pc: 1134] local: s251 index: 251 type: java.lang.String\n" + + " [pc: 1005, pc: 1134] local: s252 index: 252 type: java.lang.String\n" + + " [pc: 1008, pc: 1134] local: size1 index: 253 type: int\n" + + " [pc: 1011, pc: 1134] local: size2 index: 254 type: int\n" + + " [pc: 1014, pc: 1134] local: size3 index: 255 type: int\n" + + " [pc: 1028, pc: 1134] local: intArray index: 256 type: int[][][]\n" + + " [pc: 1033, pc: 1133] local: i index: 257 type: int\n" + + " [pc: 1041, pc: 1118] local: j index: 258 type: int\n" + + " [pc: 1049, pc: 1103] local: on index: 259 type: boolean\n" + + " [pc: 1054, pc: 1103] local: k index: 260 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=457426 +public void test007() throws Exception { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + "\n" + + " public void show() {\n" + + " String s1 = \"\"; String s2 = \"\"; String s3 = \"\"; String s4 = \"\"; String s5 = \"\"; String s6 = \"\"; String s7 = \"\"; String s8 = \"\"; String s9 = \"\"; String s10 = \"\";\n" + + " String s11 = \"\"; String s12 = \"\"; String s13 = \"\"; String s14 = \"\"; String s15 = \"\"; String s16 = \"\"; String s17 = \"\"; String s18 = \"\"; String s19 = \"\"; String s20 = \"\";\n" + + " String s21 = \"\"; String s22 = \"\"; String s23 = \"\"; String s24 = \"\"; String s25 = \"\"; String s26 = \"\"; String s27 = \"\"; String s28 = \"\"; String s29 = \"\"; String s30 = \"\";\n" + + " String s31 = \"\"; String s32 = \"\"; String s33 = \"\"; String s34 = \"\"; String s35 = \"\"; String s36 = \"\"; String s37 = \"\"; String s38 = \"\"; String s39 = \"\"; String s40 = \"\";\n" + + " String s41 = \"\"; String s42 = \"\"; String s43 = \"\"; String s44 = \"\"; String s45 = \"\"; String s46 = \"\"; String s47 = \"\"; String s48 = \"\"; String s49 = \"\"; String s50 = \"\";\n" + + " String s51 = \"\"; String s52 = \"\"; String s53 = \"\"; String s54 = \"\"; String s55 = \"\"; String s56 = \"\"; String s57 = \"\"; String s58 = \"\"; String s59 = \"\"; String s60 = \"\";\n" + + " String s61 = \"\"; String s62 = \"\"; String s63 = \"\"; String s64 = \"\"; String s65 = \"\"; String s66 = \"\"; String s67 = \"\"; String s68 = \"\"; String s69 = \"\"; String s70 = \"\";\n" + + " String s71 = \"\"; String s72 = \"\"; String s73 = \"\"; String s74 = \"\"; String s75 = \"\"; String s76 = \"\"; String s77 = \"\"; String s78 = \"\"; String s79 = \"\"; String s80 = \"\";\n" + + " String s81 = \"\"; String s82 = \"\"; String s83 = \"\"; String s84 = \"\"; String s85 = \"\"; String s86 = \"\"; String s87 = \"\"; String s88 = \"\"; String s89 = \"\"; String s90 = \"\";\n" + + " String s91 = \"\"; String s92 = \"\"; String s93 = \"\"; String s94 = \"\"; String s95 = \"\"; String s96 = \"\"; String s97 = \"\"; String s98 = \"\"; String s99 = \"\"; String s100 = \"\";\n" + + " String s101 = \"\"; String s102 = \"\"; String s103 = \"\"; String s104 = \"\"; String s105 = \"\"; String s106 = \"\"; String s107 = \"\"; String s108 = \"\"; String s109 = \"\"; String s110 = \"\";\n" + + " String s111 = \"\"; String s112 = \"\"; String s113 = \"\"; String s114 = \"\"; String s115 = \"\"; String s116 = \"\"; String s117 = \"\"; String s118 = \"\"; String s119 = \"\"; String s120 = \"\";\n" + + " String s121 = \"\"; String s122 = \"\"; String s123 = \"\"; String s124 = \"\"; String s125 = \"\"; String s126 = \"\"; String s127 = \"\"; String s128 = \"\"; String s129 = \"\"; String s130 = \"\";\n" + + " String s131 = \"\"; String s132 = \"\"; String s133 = \"\"; String s134 = \"\"; String s135 = \"\"; String s136 = \"\"; String s137 = \"\"; String s138 = \"\"; String s139 = \"\"; String s140 = \"\";\n" + + " String s141 = \"\"; String s142 = \"\"; String s143 = \"\"; String s144 = \"\"; String s145 = \"\"; String s146 = \"\"; String s147 = \"\"; String s148 = \"\"; String s149 = \"\"; String s150 = \"\";\n" + + " String s151 = \"\"; String s152 = \"\"; String s153 = \"\"; String s154 = \"\"; String s155 = \"\"; String s156 = \"\"; String s157 = \"\"; String s158 = \"\"; String s159 = \"\"; String s160 = \"\";\n" + + " String s161 = \"\"; String s162 = \"\"; String s163 = \"\"; String s164 = \"\"; String s165 = \"\"; String s166 = \"\"; String s167 = \"\"; String s168 = \"\"; String s169 = \"\"; String s170 = \"\";\n" + + " String s171 = \"\"; String s172 = \"\"; String s173 = \"\"; String s174 = \"\"; String s175 = \"\"; String s176 = \"\"; String s177 = \"\"; String s178 = \"\"; String s179 = \"\"; String s180 = \"\";\n" + + " String s181 = \"\"; String s182 = \"\"; String s183 = \"\"; String s184 = \"\"; String s185 = \"\"; String s186 = \"\"; String s187 = \"\"; String s188 = \"\"; String s189 = \"\"; String s190 = \"\";\n" + + " String s191 = \"\"; String s192 = \"\"; String s193 = \"\"; String s194 = \"\"; String s195 = \"\"; String s196 = \"\"; String s197 = \"\"; String s198 = \"\"; String s199 = \"\"; String s200 = \"\";\n" + + " String s201 = \"\"; String s202 = \"\"; String s203 = \"\"; String s204 = \"\"; String s205 = \"\"; String s206 = \"\"; String s207 = \"\"; String s208 = \"\"; String s209 = \"\"; String s210 = \"\";\n" + + " String s211 = \"\"; String s212 = \"\"; String s213 = \"\"; String s214 = \"\"; String s215 = \"\"; String s216 = \"\"; String s217 = \"\"; String s218 = \"\"; String s219 = \"\"; String s220 = \"\";\n" + + " String s221 = \"\"; String s222 = \"\"; String s223 = \"\"; String s224 = \"\"; String s225 = \"\"; String s226 = \"\"; String s227 = \"\"; String s228 = \"\"; String s229 = \"\"; String s230 = \"\";\n" + + " String s231 = \"\"; String s232 = \"\"; String s233 = \"\"; String s234 = \"\"; String s235 = \"\"; String s236 = \"\"; String s237 = \"\"; String s238 = \"\"; String s239 = \"\"; String s240 = \"\";\n" + + " String s241 = \"\"; String s242 = \"\"; String s243 = \"\"; String s244 = \"\"; String s245 = \"\"; String s246 = \"\"; String s247 = \"\"; String s248 = \"\"; String s249 = \"\"; String s250 = \"\";\n" + + " String s251 = \"\"; String s252 = \"\";\n" + + "\n" + + " int size1 = 1;\n" + + " int size2 = 2;\n" + + " int size3 = 3;\n" + + "\n" + + " int[][][] intArray = new int[size1][size2][];\n" + + " \n" + + " for (int i = 0; i < size1; i++) {\n" + + " for (int j = 0; j < size2; j++) {\n" + + " boolean on = false;\n" + + " intArray[i][j] = new int[size3];\n" + + " for (int k = 0; k < size3; k++) {\n" + + " intArray[i][j][k] = on ? 0 : 1;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().show();\n" + + " }\n" + + "}", + }, + "", + settings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=457426 +public void test008() throws Exception { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + "\n" + + " public void show() {\n" + + " String s1 = \"\"; String s2 = \"\"; String s3 = \"\"; String s4 = \"\"; String s5 = \"\"; String s6 = \"\"; String s7 = \"\"; String s8 = \"\"; String s9 = \"\"; String s10 = \"\";\n" + + " String s11 = \"\"; String s12 = \"\"; String s13 = \"\"; String s14 = \"\"; String s15 = \"\"; String s16 = \"\"; String s17 = \"\"; String s18 = \"\"; String s19 = \"\"; String s20 = \"\";\n" + + " String s21 = \"\"; String s22 = \"\"; String s23 = \"\"; String s24 = \"\"; String s25 = \"\"; String s26 = \"\"; String s27 = \"\"; String s28 = \"\"; String s29 = \"\"; String s30 = \"\";\n" + + " String s31 = \"\"; String s32 = \"\"; String s33 = \"\"; String s34 = \"\"; String s35 = \"\"; String s36 = \"\"; String s37 = \"\"; String s38 = \"\"; String s39 = \"\"; String s40 = \"\";\n" + + " String s41 = \"\"; String s42 = \"\"; String s43 = \"\"; String s44 = \"\"; String s45 = \"\"; String s46 = \"\"; String s47 = \"\"; String s48 = \"\"; String s49 = \"\"; String s50 = \"\";\n" + + " String s51 = \"\"; String s52 = \"\"; String s53 = \"\"; String s54 = \"\"; String s55 = \"\"; String s56 = \"\"; String s57 = \"\"; String s58 = \"\"; String s59 = \"\"; String s60 = \"\";\n" + + " String s61 = \"\"; String s62 = \"\"; String s63 = \"\"; String s64 = \"\"; String s65 = \"\"; String s66 = \"\"; String s67 = \"\"; String s68 = \"\"; String s69 = \"\"; String s70 = \"\";\n" + + " String s71 = \"\"; String s72 = \"\"; String s73 = \"\"; String s74 = \"\"; String s75 = \"\"; String s76 = \"\"; String s77 = \"\"; String s78 = \"\"; String s79 = \"\"; String s80 = \"\";\n" + + " String s81 = \"\"; String s82 = \"\"; String s83 = \"\"; String s84 = \"\"; String s85 = \"\"; String s86 = \"\"; String s87 = \"\"; String s88 = \"\"; String s89 = \"\"; String s90 = \"\";\n" + + " String s91 = \"\"; String s92 = \"\"; String s93 = \"\"; String s94 = \"\"; String s95 = \"\"; String s96 = \"\"; String s97 = \"\"; String s98 = \"\"; String s99 = \"\"; String s100 = \"\";\n" + + " String s101 = \"\"; String s102 = \"\"; String s103 = \"\"; String s104 = \"\"; String s105 = \"\"; String s106 = \"\"; String s107 = \"\"; String s108 = \"\"; String s109 = \"\"; String s110 = \"\";\n" + + " String s111 = \"\"; String s112 = \"\"; String s113 = \"\"; String s114 = \"\"; String s115 = \"\"; String s116 = \"\"; String s117 = \"\"; String s118 = \"\"; String s119 = \"\"; String s120 = \"\";\n" + + " String s121 = \"\"; String s122 = \"\"; String s123 = \"\"; String s124 = \"\"; String s125 = \"\"; String s126 = \"\"; String s127 = \"\"; String s128 = \"\"; String s129 = \"\"; String s130 = \"\";\n" + + " String s131 = \"\"; String s132 = \"\"; String s133 = \"\"; String s134 = \"\"; String s135 = \"\"; String s136 = \"\"; String s137 = \"\"; String s138 = \"\"; String s139 = \"\"; String s140 = \"\";\n" + + " String s141 = \"\"; String s142 = \"\"; String s143 = \"\"; String s144 = \"\"; String s145 = \"\"; String s146 = \"\"; String s147 = \"\"; String s148 = \"\"; String s149 = \"\"; String s150 = \"\";\n" + + " String s151 = \"\"; String s152 = \"\"; String s153 = \"\"; String s154 = \"\"; String s155 = \"\"; String s156 = \"\"; String s157 = \"\"; String s158 = \"\"; String s159 = \"\"; String s160 = \"\";\n" + + " String s161 = \"\"; String s162 = \"\"; String s163 = \"\"; String s164 = \"\"; String s165 = \"\"; String s166 = \"\"; String s167 = \"\"; String s168 = \"\"; String s169 = \"\"; String s170 = \"\";\n" + + " String s171 = \"\"; String s172 = \"\"; String s173 = \"\"; String s174 = \"\"; String s175 = \"\"; String s176 = \"\"; String s177 = \"\"; String s178 = \"\"; String s179 = \"\"; String s180 = \"\";\n" + + " String s181 = \"\"; String s182 = \"\"; String s183 = \"\"; String s184 = \"\"; String s185 = \"\"; String s186 = \"\"; String s187 = \"\"; String s188 = \"\"; String s189 = \"\"; String s190 = \"\";\n" + + " String s191 = \"\"; String s192 = \"\"; String s193 = \"\"; String s194 = \"\"; String s195 = \"\"; String s196 = \"\"; String s197 = \"\"; String s198 = \"\"; String s199 = \"\"; String s200 = \"\";\n" + + " String s201 = \"\"; String s202 = \"\"; String s203 = \"\"; String s204 = \"\"; String s205 = \"\"; String s206 = \"\"; String s207 = \"\"; String s208 = \"\"; String s209 = \"\"; String s210 = \"\";\n" + + " String s211 = \"\"; String s212 = \"\"; String s213 = \"\"; String s214 = \"\"; String s215 = \"\"; String s216 = \"\"; String s217 = \"\"; String s218 = \"\"; String s219 = \"\"; String s220 = \"\";\n" + + " String s221 = \"\"; String s222 = \"\"; String s223 = \"\"; String s224 = \"\"; String s225 = \"\"; String s226 = \"\"; String s227 = \"\"; String s228 = \"\"; String s229 = \"\"; String s230 = \"\";\n" + + " String s231 = \"\"; String s232 = \"\"; String s233 = \"\"; String s234 = \"\"; String s235 = \"\"; String s236 = \"\"; String s237 = \"\"; String s238 = \"\"; String s239 = \"\"; String s240 = \"\";\n" + + " String s241 = \"\"; String s242 = \"\"; String s243 = \"\"; String s244 = \"\"; String s245 = \"\"; String s246 = \"\"; String s247 = \"\"; String s248 = \"\"; String s249 = \"\"; String s250 = \"\";\n" + + " String s251 = \"\"; String s252 = \"\";\n" + + "\n" + + " int size1 = 1;\n" + + " int size2 = 2;\n" + + " int size3 = 3;\n" + + "\n" + + " String[][][] array = new String[size1][size2][size3];\n" + + " \n" + + " for (int i = 0; i < size1; i++) {\n" + + " for (int j = 0; j < size2; j++) {\n" + + " boolean on = false;\n" + + " for (int k = 0; k < size3; k++) {\n" + + " array[i][j][k] = on ? \"true\" : \"false\";\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().show();\n" + + " }\n" + + "}", + }, + "", + settings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=457426 +public void test009() throws Exception { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + "\n" + + " public void show() {\n" + + " String s1 = \"\"; String s2 = \"\"; String s3 = \"\"; String s4 = \"\"; String s5 = \"\"; String s6 = \"\"; String s7 = \"\"; String s8 = \"\"; String s9 = \"\"; String s10 = \"\";\n" + + " String s11 = \"\"; String s12 = \"\"; String s13 = \"\"; String s14 = \"\"; String s15 = \"\"; String s16 = \"\"; String s17 = \"\"; String s18 = \"\"; String s19 = \"\"; String s20 = \"\";\n" + + " String s21 = \"\"; String s22 = \"\"; String s23 = \"\"; String s24 = \"\"; String s25 = \"\"; String s26 = \"\"; String s27 = \"\"; String s28 = \"\"; String s29 = \"\"; String s30 = \"\";\n" + + " String s31 = \"\"; String s32 = \"\"; String s33 = \"\"; String s34 = \"\"; String s35 = \"\"; String s36 = \"\"; String s37 = \"\"; String s38 = \"\"; String s39 = \"\"; String s40 = \"\";\n" + + " String s41 = \"\"; String s42 = \"\"; String s43 = \"\"; String s44 = \"\"; String s45 = \"\"; String s46 = \"\"; String s47 = \"\"; String s48 = \"\"; String s49 = \"\"; String s50 = \"\";\n" + + " String s51 = \"\"; String s52 = \"\"; String s53 = \"\"; String s54 = \"\"; String s55 = \"\"; String s56 = \"\"; String s57 = \"\"; String s58 = \"\"; String s59 = \"\"; String s60 = \"\";\n" + + " String s61 = \"\"; String s62 = \"\"; String s63 = \"\"; String s64 = \"\"; String s65 = \"\"; String s66 = \"\"; String s67 = \"\"; String s68 = \"\"; String s69 = \"\"; String s70 = \"\";\n" + + " String s71 = \"\"; String s72 = \"\"; String s73 = \"\"; String s74 = \"\"; String s75 = \"\"; String s76 = \"\"; String s77 = \"\"; String s78 = \"\"; String s79 = \"\"; String s80 = \"\";\n" + + " String s81 = \"\"; String s82 = \"\"; String s83 = \"\"; String s84 = \"\"; String s85 = \"\"; String s86 = \"\"; String s87 = \"\"; String s88 = \"\"; String s89 = \"\"; String s90 = \"\";\n" + + " String s91 = \"\"; String s92 = \"\"; String s93 = \"\"; String s94 = \"\"; String s95 = \"\"; String s96 = \"\"; String s97 = \"\"; String s98 = \"\"; String s99 = \"\"; String s100 = \"\";\n" + + " String s101 = \"\"; String s102 = \"\"; String s103 = \"\"; String s104 = \"\"; String s105 = \"\"; String s106 = \"\"; String s107 = \"\"; String s108 = \"\"; String s109 = \"\"; String s110 = \"\";\n" + + " String s111 = \"\"; String s112 = \"\"; String s113 = \"\"; String s114 = \"\"; String s115 = \"\"; String s116 = \"\"; String s117 = \"\"; String s118 = \"\"; String s119 = \"\"; String s120 = \"\";\n" + + " String s121 = \"\"; String s122 = \"\"; String s123 = \"\"; String s124 = \"\"; String s125 = \"\"; String s126 = \"\"; String s127 = \"\"; String s128 = \"\"; String s129 = \"\"; String s130 = \"\";\n" + + " String s131 = \"\"; String s132 = \"\"; String s133 = \"\"; String s134 = \"\"; String s135 = \"\"; String s136 = \"\"; String s137 = \"\"; String s138 = \"\"; String s139 = \"\"; String s140 = \"\";\n" + + " String s141 = \"\"; String s142 = \"\"; String s143 = \"\"; String s144 = \"\"; String s145 = \"\"; String s146 = \"\"; String s147 = \"\"; String s148 = \"\"; String s149 = \"\"; String s150 = \"\";\n" + + " String s151 = \"\"; String s152 = \"\"; String s153 = \"\"; String s154 = \"\"; String s155 = \"\"; String s156 = \"\"; String s157 = \"\"; String s158 = \"\"; String s159 = \"\"; String s160 = \"\";\n" + + " String s161 = \"\"; String s162 = \"\"; String s163 = \"\"; String s164 = \"\"; String s165 = \"\"; String s166 = \"\"; String s167 = \"\"; String s168 = \"\"; String s169 = \"\"; String s170 = \"\";\n" + + " String s171 = \"\"; String s172 = \"\"; String s173 = \"\"; String s174 = \"\"; String s175 = \"\"; String s176 = \"\"; String s177 = \"\"; String s178 = \"\"; String s179 = \"\"; String s180 = \"\";\n" + + " String s181 = \"\"; String s182 = \"\"; String s183 = \"\"; String s184 = \"\"; String s185 = \"\"; String s186 = \"\"; String s187 = \"\"; String s188 = \"\"; String s189 = \"\"; String s190 = \"\";\n" + + " String s191 = \"\"; String s192 = \"\"; String s193 = \"\"; String s194 = \"\"; String s195 = \"\"; String s196 = \"\"; String s197 = \"\"; String s198 = \"\"; String s199 = \"\"; String s200 = \"\";\n" + + " String s201 = \"\"; String s202 = \"\"; String s203 = \"\"; String s204 = \"\"; String s205 = \"\"; String s206 = \"\"; String s207 = \"\"; String s208 = \"\"; String s209 = \"\"; String s210 = \"\";\n" + + " String s211 = \"\"; String s212 = \"\"; String s213 = \"\"; String s214 = \"\"; String s215 = \"\"; String s216 = \"\"; String s217 = \"\"; String s218 = \"\"; String s219 = \"\"; String s220 = \"\";\n" + + " String s221 = \"\"; String s222 = \"\"; String s223 = \"\"; String s224 = \"\"; String s225 = \"\"; String s226 = \"\"; String s227 = \"\"; String s228 = \"\"; String s229 = \"\"; String s230 = \"\";\n" + + " String s231 = \"\"; String s232 = \"\"; String s233 = \"\"; String s234 = \"\"; String s235 = \"\"; String s236 = \"\"; String s237 = \"\"; String s238 = \"\"; String s239 = \"\"; String s240 = \"\";\n" + + " String s241 = \"\"; String s242 = \"\"; String s243 = \"\"; String s244 = \"\"; String s245 = \"\"; String s246 = \"\"; String s247 = \"\"; String s248 = \"\"; String s249 = \"\"; String s250 = \"\";\n" + + " String s251 = \"\"; String s252 = \"\";\n" + + "\n" + + " int size1 = 1;\n" + + " int size2 = 2;\n" + + " int size3 = 3;\n" + + "\n" + + " boolean[][][] array = new boolean[size1][size2][size3];\n" + + " \n" + + " for (int i = 0; i < size1; i++) {\n" + + " for (int j = 0; j < size2; j++) {\n" + + " boolean on = false;\n" + + " for (int k = 0; k < size3; k++) {\n" + + " array[i][j][k] = on ? true : false;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().show();\n" + + " }\n" + + "}", + }, + "", + settings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=457426 +public void test010() throws Exception { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + "\n" + + " public void show() {\n" + + " String s1 = \"\"; String s2 = \"\"; String s3 = \"\"; String s4 = \"\"; String s5 = \"\"; String s6 = \"\"; String s7 = \"\"; String s8 = \"\"; String s9 = \"\"; String s10 = \"\";\n" + + " String s11 = \"\"; String s12 = \"\"; String s13 = \"\"; String s14 = \"\"; String s15 = \"\"; String s16 = \"\"; String s17 = \"\"; String s18 = \"\"; String s19 = \"\"; String s20 = \"\";\n" + + " String s21 = \"\"; String s22 = \"\"; String s23 = \"\"; String s24 = \"\"; String s25 = \"\"; String s26 = \"\"; String s27 = \"\"; String s28 = \"\"; String s29 = \"\"; String s30 = \"\";\n" + + " String s31 = \"\"; String s32 = \"\"; String s33 = \"\"; String s34 = \"\"; String s35 = \"\"; String s36 = \"\"; String s37 = \"\"; String s38 = \"\"; String s39 = \"\"; String s40 = \"\";\n" + + " String s41 = \"\"; String s42 = \"\"; String s43 = \"\"; String s44 = \"\"; String s45 = \"\"; String s46 = \"\"; String s47 = \"\"; String s48 = \"\"; String s49 = \"\"; String s50 = \"\";\n" + + " String s51 = \"\"; String s52 = \"\"; String s53 = \"\"; String s54 = \"\"; String s55 = \"\"; String s56 = \"\"; String s57 = \"\"; String s58 = \"\"; String s59 = \"\"; String s60 = \"\";\n" + + " String s61 = \"\"; String s62 = \"\"; String s63 = \"\"; String s64 = \"\"; String s65 = \"\"; String s66 = \"\"; String s67 = \"\"; String s68 = \"\"; String s69 = \"\"; String s70 = \"\";\n" + + " String s71 = \"\"; String s72 = \"\"; String s73 = \"\"; String s74 = \"\"; String s75 = \"\"; String s76 = \"\"; String s77 = \"\"; String s78 = \"\"; String s79 = \"\"; String s80 = \"\";\n" + + " String s81 = \"\"; String s82 = \"\"; String s83 = \"\"; String s84 = \"\"; String s85 = \"\"; String s86 = \"\"; String s87 = \"\"; String s88 = \"\"; String s89 = \"\"; String s90 = \"\";\n" + + " String s91 = \"\"; String s92 = \"\"; String s93 = \"\"; String s94 = \"\"; String s95 = \"\"; String s96 = \"\"; String s97 = \"\"; String s98 = \"\"; String s99 = \"\"; String s100 = \"\";\n" + + " String s101 = \"\"; String s102 = \"\"; String s103 = \"\"; String s104 = \"\"; String s105 = \"\"; String s106 = \"\"; String s107 = \"\"; String s108 = \"\"; String s109 = \"\"; String s110 = \"\";\n" + + " String s111 = \"\"; String s112 = \"\"; String s113 = \"\"; String s114 = \"\"; String s115 = \"\"; String s116 = \"\"; String s117 = \"\"; String s118 = \"\"; String s119 = \"\"; String s120 = \"\";\n" + + " String s121 = \"\"; String s122 = \"\"; String s123 = \"\"; String s124 = \"\"; String s125 = \"\"; String s126 = \"\"; String s127 = \"\"; String s128 = \"\"; String s129 = \"\"; String s130 = \"\";\n" + + " String s131 = \"\"; String s132 = \"\"; String s133 = \"\"; String s134 = \"\"; String s135 = \"\"; String s136 = \"\"; String s137 = \"\"; String s138 = \"\"; String s139 = \"\"; String s140 = \"\";\n" + + " String s141 = \"\"; String s142 = \"\"; String s143 = \"\"; String s144 = \"\"; String s145 = \"\"; String s146 = \"\"; String s147 = \"\"; String s148 = \"\"; String s149 = \"\"; String s150 = \"\";\n" + + " String s151 = \"\"; String s152 = \"\"; String s153 = \"\"; String s154 = \"\"; String s155 = \"\"; String s156 = \"\"; String s157 = \"\"; String s158 = \"\"; String s159 = \"\"; String s160 = \"\";\n" + + " String s161 = \"\"; String s162 = \"\"; String s163 = \"\"; String s164 = \"\"; String s165 = \"\"; String s166 = \"\"; String s167 = \"\"; String s168 = \"\"; String s169 = \"\"; String s170 = \"\";\n" + + " String s171 = \"\"; String s172 = \"\"; String s173 = \"\"; String s174 = \"\"; String s175 = \"\"; String s176 = \"\"; String s177 = \"\"; String s178 = \"\"; String s179 = \"\"; String s180 = \"\";\n" + + " String s181 = \"\"; String s182 = \"\"; String s183 = \"\"; String s184 = \"\"; String s185 = \"\"; String s186 = \"\"; String s187 = \"\"; String s188 = \"\"; String s189 = \"\"; String s190 = \"\";\n" + + " String s191 = \"\"; String s192 = \"\"; String s193 = \"\"; String s194 = \"\"; String s195 = \"\"; String s196 = \"\"; String s197 = \"\"; String s198 = \"\"; String s199 = \"\"; String s200 = \"\";\n" + + " String s201 = \"\"; String s202 = \"\"; String s203 = \"\"; String s204 = \"\"; String s205 = \"\"; String s206 = \"\"; String s207 = \"\"; String s208 = \"\"; String s209 = \"\"; String s210 = \"\";\n" + + " String s211 = \"\"; String s212 = \"\"; String s213 = \"\"; String s214 = \"\"; String s215 = \"\"; String s216 = \"\"; String s217 = \"\"; String s218 = \"\"; String s219 = \"\"; String s220 = \"\";\n" + + " String s221 = \"\"; String s222 = \"\"; String s223 = \"\"; String s224 = \"\"; String s225 = \"\"; String s226 = \"\"; String s227 = \"\"; String s228 = \"\"; String s229 = \"\"; String s230 = \"\";\n" + + " String s231 = \"\"; String s232 = \"\"; String s233 = \"\"; String s234 = \"\"; String s235 = \"\"; String s236 = \"\"; String s237 = \"\"; String s238 = \"\"; String s239 = \"\"; String s240 = \"\";\n" + + " String s241 = \"\"; String s242 = \"\"; String s243 = \"\"; String s244 = \"\"; String s245 = \"\"; String s246 = \"\"; String s247 = \"\"; String s248 = \"\"; String s249 = \"\"; String s250 = \"\";\n" + + " String s251 = \"\"; String s252 = \"\";\n" + + "\n" + + " int size1 = 1;\n" + + " int size2 = 2;\n" + + " int size3 = 3;\n" + + "\n" + + " long[][][] array = new long[size1][size2][size3];\n" + + " \n" + + " for (int i = 0; i < size1; i++) {\n" + + " for (int j = 0; j < size2; j++) {\n" + + " boolean on = false;\n" + + " for (int k = 0; k < size3; k++) {\n" + + " array[i][j][k] = on ? 234L : 12345L;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().show();\n" + + " }\n" + + "}", + }, + "", + settings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=457426 +public void test011() throws Exception { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + "\n" + + " public void show() {\n" + + " String s1 = \"\"; String s2 = \"\"; String s3 = \"\"; String s4 = \"\"; String s5 = \"\"; String s6 = \"\"; String s7 = \"\"; String s8 = \"\"; String s9 = \"\"; String s10 = \"\";\n" + + " String s11 = \"\"; String s12 = \"\"; String s13 = \"\"; String s14 = \"\"; String s15 = \"\"; String s16 = \"\"; String s17 = \"\"; String s18 = \"\"; String s19 = \"\"; String s20 = \"\";\n" + + " String s21 = \"\"; String s22 = \"\"; String s23 = \"\"; String s24 = \"\"; String s25 = \"\"; String s26 = \"\"; String s27 = \"\"; String s28 = \"\"; String s29 = \"\"; String s30 = \"\";\n" + + " String s31 = \"\"; String s32 = \"\"; String s33 = \"\"; String s34 = \"\"; String s35 = \"\"; String s36 = \"\"; String s37 = \"\"; String s38 = \"\"; String s39 = \"\"; String s40 = \"\";\n" + + " String s41 = \"\"; String s42 = \"\"; String s43 = \"\"; String s44 = \"\"; String s45 = \"\"; String s46 = \"\"; String s47 = \"\"; String s48 = \"\"; String s49 = \"\"; String s50 = \"\";\n" + + " String s51 = \"\"; String s52 = \"\"; String s53 = \"\"; String s54 = \"\"; String s55 = \"\"; String s56 = \"\"; String s57 = \"\"; String s58 = \"\"; String s59 = \"\"; String s60 = \"\";\n" + + " String s61 = \"\"; String s62 = \"\"; String s63 = \"\"; String s64 = \"\"; String s65 = \"\"; String s66 = \"\"; String s67 = \"\"; String s68 = \"\"; String s69 = \"\"; String s70 = \"\";\n" + + " String s71 = \"\"; String s72 = \"\"; String s73 = \"\"; String s74 = \"\"; String s75 = \"\"; String s76 = \"\"; String s77 = \"\"; String s78 = \"\"; String s79 = \"\"; String s80 = \"\";\n" + + " String s81 = \"\"; String s82 = \"\"; String s83 = \"\"; String s84 = \"\"; String s85 = \"\"; String s86 = \"\"; String s87 = \"\"; String s88 = \"\"; String s89 = \"\"; String s90 = \"\";\n" + + " String s91 = \"\"; String s92 = \"\"; String s93 = \"\"; String s94 = \"\"; String s95 = \"\"; String s96 = \"\"; String s97 = \"\"; String s98 = \"\"; String s99 = \"\"; String s100 = \"\";\n" + + " String s101 = \"\"; String s102 = \"\"; String s103 = \"\"; String s104 = \"\"; String s105 = \"\"; String s106 = \"\"; String s107 = \"\"; String s108 = \"\"; String s109 = \"\"; String s110 = \"\";\n" + + " String s111 = \"\"; String s112 = \"\"; String s113 = \"\"; String s114 = \"\"; String s115 = \"\"; String s116 = \"\"; String s117 = \"\"; String s118 = \"\"; String s119 = \"\"; String s120 = \"\";\n" + + " String s121 = \"\"; String s122 = \"\"; String s123 = \"\"; String s124 = \"\"; String s125 = \"\"; String s126 = \"\"; String s127 = \"\"; String s128 = \"\"; String s129 = \"\"; String s130 = \"\";\n" + + " String s131 = \"\"; String s132 = \"\"; String s133 = \"\"; String s134 = \"\"; String s135 = \"\"; String s136 = \"\"; String s137 = \"\"; String s138 = \"\"; String s139 = \"\"; String s140 = \"\";\n" + + " String s141 = \"\"; String s142 = \"\"; String s143 = \"\"; String s144 = \"\"; String s145 = \"\"; String s146 = \"\"; String s147 = \"\"; String s148 = \"\"; String s149 = \"\"; String s150 = \"\";\n" + + " String s151 = \"\"; String s152 = \"\"; String s153 = \"\"; String s154 = \"\"; String s155 = \"\"; String s156 = \"\"; String s157 = \"\"; String s158 = \"\"; String s159 = \"\"; String s160 = \"\";\n" + + " String s161 = \"\"; String s162 = \"\"; String s163 = \"\"; String s164 = \"\"; String s165 = \"\"; String s166 = \"\"; String s167 = \"\"; String s168 = \"\"; String s169 = \"\"; String s170 = \"\";\n" + + " String s171 = \"\"; String s172 = \"\"; String s173 = \"\"; String s174 = \"\"; String s175 = \"\"; String s176 = \"\"; String s177 = \"\"; String s178 = \"\"; String s179 = \"\"; String s180 = \"\";\n" + + " String s181 = \"\"; String s182 = \"\"; String s183 = \"\"; String s184 = \"\"; String s185 = \"\"; String s186 = \"\"; String s187 = \"\"; String s188 = \"\"; String s189 = \"\"; String s190 = \"\";\n" + + " String s191 = \"\"; String s192 = \"\"; String s193 = \"\"; String s194 = \"\"; String s195 = \"\"; String s196 = \"\"; String s197 = \"\"; String s198 = \"\"; String s199 = \"\"; String s200 = \"\";\n" + + " String s201 = \"\"; String s202 = \"\"; String s203 = \"\"; String s204 = \"\"; String s205 = \"\"; String s206 = \"\"; String s207 = \"\"; String s208 = \"\"; String s209 = \"\"; String s210 = \"\";\n" + + " String s211 = \"\"; String s212 = \"\"; String s213 = \"\"; String s214 = \"\"; String s215 = \"\"; String s216 = \"\"; String s217 = \"\"; String s218 = \"\"; String s219 = \"\"; String s220 = \"\";\n" + + " String s221 = \"\"; String s222 = \"\"; String s223 = \"\"; String s224 = \"\"; String s225 = \"\"; String s226 = \"\"; String s227 = \"\"; String s228 = \"\"; String s229 = \"\"; String s230 = \"\";\n" + + " String s231 = \"\"; String s232 = \"\"; String s233 = \"\"; String s234 = \"\"; String s235 = \"\"; String s236 = \"\"; String s237 = \"\"; String s238 = \"\"; String s239 = \"\"; String s240 = \"\";\n" + + " String s241 = \"\"; String s242 = \"\"; String s243 = \"\"; String s244 = \"\"; String s245 = \"\"; String s246 = \"\"; String s247 = \"\"; String s248 = \"\"; String s249 = \"\"; String s250 = \"\";\n" + + " String s251 = \"\"; String s252 = \"\";\n" + + "\n" + + " int size1 = 1;\n" + + " int size2 = 2;\n" + + " int size3 = 3;\n" + + "\n" + + " double[][][] array = new double[size1][size2][size3];\n" + + " \n" + + " for (int i = 0; i < size1; i++) {\n" + + " for (int j = 0; j < size2; j++) {\n" + + " boolean on = false;\n" + + " for (int k = 0; k < size3; k++) {\n" + + " array[i][j][k] = on ? 2.0 : 3.0;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().show();\n" + + " }\n" + + "}", + }, + "", + settings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=457426 +public void test012() throws Exception { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + "\n" + + " public void show() {\n" + + " String s1 = \"\"; String s2 = \"\"; String s3 = \"\"; String s4 = \"\"; String s5 = \"\"; String s6 = \"\"; String s7 = \"\"; String s8 = \"\"; String s9 = \"\"; String s10 = \"\";\n" + + " String s11 = \"\"; String s12 = \"\"; String s13 = \"\"; String s14 = \"\"; String s15 = \"\"; String s16 = \"\"; String s17 = \"\"; String s18 = \"\"; String s19 = \"\"; String s20 = \"\";\n" + + " String s21 = \"\"; String s22 = \"\"; String s23 = \"\"; String s24 = \"\"; String s25 = \"\"; String s26 = \"\"; String s27 = \"\"; String s28 = \"\"; String s29 = \"\"; String s30 = \"\";\n" + + " String s31 = \"\"; String s32 = \"\"; String s33 = \"\"; String s34 = \"\"; String s35 = \"\"; String s36 = \"\"; String s37 = \"\"; String s38 = \"\"; String s39 = \"\"; String s40 = \"\";\n" + + " String s41 = \"\"; String s42 = \"\"; String s43 = \"\"; String s44 = \"\"; String s45 = \"\"; String s46 = \"\"; String s47 = \"\"; String s48 = \"\"; String s49 = \"\"; String s50 = \"\";\n" + + " String s51 = \"\"; String s52 = \"\"; String s53 = \"\"; String s54 = \"\"; String s55 = \"\"; String s56 = \"\"; String s57 = \"\"; String s58 = \"\"; String s59 = \"\"; String s60 = \"\";\n" + + " String s61 = \"\"; String s62 = \"\"; String s63 = \"\"; String s64 = \"\"; String s65 = \"\"; String s66 = \"\"; String s67 = \"\"; String s68 = \"\"; String s69 = \"\"; String s70 = \"\";\n" + + " String s71 = \"\"; String s72 = \"\"; String s73 = \"\"; String s74 = \"\"; String s75 = \"\"; String s76 = \"\"; String s77 = \"\"; String s78 = \"\"; String s79 = \"\"; String s80 = \"\";\n" + + " String s81 = \"\"; String s82 = \"\"; String s83 = \"\"; String s84 = \"\"; String s85 = \"\"; String s86 = \"\"; String s87 = \"\"; String s88 = \"\"; String s89 = \"\"; String s90 = \"\";\n" + + " String s91 = \"\"; String s92 = \"\"; String s93 = \"\"; String s94 = \"\"; String s95 = \"\"; String s96 = \"\"; String s97 = \"\"; String s98 = \"\"; String s99 = \"\"; String s100 = \"\";\n" + + " String s101 = \"\"; String s102 = \"\"; String s103 = \"\"; String s104 = \"\"; String s105 = \"\"; String s106 = \"\"; String s107 = \"\"; String s108 = \"\"; String s109 = \"\"; String s110 = \"\";\n" + + " String s111 = \"\"; String s112 = \"\"; String s113 = \"\"; String s114 = \"\"; String s115 = \"\"; String s116 = \"\"; String s117 = \"\"; String s118 = \"\"; String s119 = \"\"; String s120 = \"\";\n" + + " String s121 = \"\"; String s122 = \"\"; String s123 = \"\"; String s124 = \"\"; String s125 = \"\"; String s126 = \"\"; String s127 = \"\"; String s128 = \"\"; String s129 = \"\"; String s130 = \"\";\n" + + " String s131 = \"\"; String s132 = \"\"; String s133 = \"\"; String s134 = \"\"; String s135 = \"\"; String s136 = \"\"; String s137 = \"\"; String s138 = \"\"; String s139 = \"\"; String s140 = \"\";\n" + + " String s141 = \"\"; String s142 = \"\"; String s143 = \"\"; String s144 = \"\"; String s145 = \"\"; String s146 = \"\"; String s147 = \"\"; String s148 = \"\"; String s149 = \"\"; String s150 = \"\";\n" + + " String s151 = \"\"; String s152 = \"\"; String s153 = \"\"; String s154 = \"\"; String s155 = \"\"; String s156 = \"\"; String s157 = \"\"; String s158 = \"\"; String s159 = \"\"; String s160 = \"\";\n" + + " String s161 = \"\"; String s162 = \"\"; String s163 = \"\"; String s164 = \"\"; String s165 = \"\"; String s166 = \"\"; String s167 = \"\"; String s168 = \"\"; String s169 = \"\"; String s170 = \"\";\n" + + " String s171 = \"\"; String s172 = \"\"; String s173 = \"\"; String s174 = \"\"; String s175 = \"\"; String s176 = \"\"; String s177 = \"\"; String s178 = \"\"; String s179 = \"\"; String s180 = \"\";\n" + + " String s181 = \"\"; String s182 = \"\"; String s183 = \"\"; String s184 = \"\"; String s185 = \"\"; String s186 = \"\"; String s187 = \"\"; String s188 = \"\"; String s189 = \"\"; String s190 = \"\";\n" + + " String s191 = \"\"; String s192 = \"\"; String s193 = \"\"; String s194 = \"\"; String s195 = \"\"; String s196 = \"\"; String s197 = \"\"; String s198 = \"\"; String s199 = \"\"; String s200 = \"\";\n" + + " String s201 = \"\"; String s202 = \"\"; String s203 = \"\"; String s204 = \"\"; String s205 = \"\"; String s206 = \"\"; String s207 = \"\"; String s208 = \"\"; String s209 = \"\"; String s210 = \"\";\n" + + " String s211 = \"\"; String s212 = \"\"; String s213 = \"\"; String s214 = \"\"; String s215 = \"\"; String s216 = \"\"; String s217 = \"\"; String s218 = \"\"; String s219 = \"\"; String s220 = \"\";\n" + + " String s221 = \"\"; String s222 = \"\"; String s223 = \"\"; String s224 = \"\"; String s225 = \"\"; String s226 = \"\"; String s227 = \"\"; String s228 = \"\"; String s229 = \"\"; String s230 = \"\";\n" + + " String s231 = \"\"; String s232 = \"\"; String s233 = \"\"; String s234 = \"\"; String s235 = \"\"; String s236 = \"\"; String s237 = \"\"; String s238 = \"\"; String s239 = \"\"; String s240 = \"\";\n" + + " String s241 = \"\"; String s242 = \"\"; String s243 = \"\"; String s244 = \"\"; String s245 = \"\"; String s246 = \"\"; String s247 = \"\"; String s248 = \"\"; String s249 = \"\"; String s250 = \"\";\n" + + " String s251 = \"\"; String s252 = \"\";\n" + + "\n" + + " int size1 = 1;\n" + + " int size2 = 2;\n" + + " int size3 = 3;\n" + + "\n" + + " float[][][] array = new float[size1][size2][size3];\n" + + " \n" + + " for (int i = 0; i < size1; i++) {\n" + + " for (int j = 0; j < size2; j++) {\n" + + " boolean on = false;\n" + + " for (int k = 0; k < size3; k++) {\n" + + " array[i][j][k] = on ? 2.0f : 3.0f;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().show();\n" + + " }\n" + + "}", + }, + "", + settings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=457426 +public void test013() throws Exception { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + "\n" + + " public void show() {\n" + + " String s1 = \"\"; String s2 = \"\"; String s3 = \"\"; String s4 = \"\"; String s5 = \"\"; String s6 = \"\"; String s7 = \"\"; String s8 = \"\"; String s9 = \"\"; String s10 = \"\";\n" + + " String s11 = \"\"; String s12 = \"\"; String s13 = \"\"; String s14 = \"\"; String s15 = \"\"; String s16 = \"\"; String s17 = \"\"; String s18 = \"\"; String s19 = \"\"; String s20 = \"\";\n" + + " String s21 = \"\"; String s22 = \"\"; String s23 = \"\"; String s24 = \"\"; String s25 = \"\"; String s26 = \"\"; String s27 = \"\"; String s28 = \"\"; String s29 = \"\"; String s30 = \"\";\n" + + " String s31 = \"\"; String s32 = \"\"; String s33 = \"\"; String s34 = \"\"; String s35 = \"\"; String s36 = \"\"; String s37 = \"\"; String s38 = \"\"; String s39 = \"\"; String s40 = \"\";\n" + + " String s41 = \"\"; String s42 = \"\"; String s43 = \"\"; String s44 = \"\"; String s45 = \"\"; String s46 = \"\"; String s47 = \"\"; String s48 = \"\"; String s49 = \"\"; String s50 = \"\";\n" + + " String s51 = \"\"; String s52 = \"\"; String s53 = \"\"; String s54 = \"\"; String s55 = \"\"; String s56 = \"\"; String s57 = \"\"; String s58 = \"\"; String s59 = \"\"; String s60 = \"\";\n" + + " String s61 = \"\"; String s62 = \"\"; String s63 = \"\"; String s64 = \"\"; String s65 = \"\"; String s66 = \"\"; String s67 = \"\"; String s68 = \"\"; String s69 = \"\"; String s70 = \"\";\n" + + " String s71 = \"\"; String s72 = \"\"; String s73 = \"\"; String s74 = \"\"; String s75 = \"\"; String s76 = \"\"; String s77 = \"\"; String s78 = \"\"; String s79 = \"\"; String s80 = \"\";\n" + + " String s81 = \"\"; String s82 = \"\"; String s83 = \"\"; String s84 = \"\"; String s85 = \"\"; String s86 = \"\"; String s87 = \"\"; String s88 = \"\"; String s89 = \"\"; String s90 = \"\";\n" + + " String s91 = \"\"; String s92 = \"\"; String s93 = \"\"; String s94 = \"\"; String s95 = \"\"; String s96 = \"\"; String s97 = \"\"; String s98 = \"\"; String s99 = \"\"; String s100 = \"\";\n" + + " String s101 = \"\"; String s102 = \"\"; String s103 = \"\"; String s104 = \"\"; String s105 = \"\"; String s106 = \"\"; String s107 = \"\"; String s108 = \"\"; String s109 = \"\"; String s110 = \"\";\n" + + " String s111 = \"\"; String s112 = \"\"; String s113 = \"\"; String s114 = \"\"; String s115 = \"\"; String s116 = \"\"; String s117 = \"\"; String s118 = \"\"; String s119 = \"\"; String s120 = \"\";\n" + + " String s121 = \"\"; String s122 = \"\"; String s123 = \"\"; String s124 = \"\"; String s125 = \"\"; String s126 = \"\"; String s127 = \"\"; String s128 = \"\"; String s129 = \"\"; String s130 = \"\";\n" + + " String s131 = \"\"; String s132 = \"\"; String s133 = \"\"; String s134 = \"\"; String s135 = \"\"; String s136 = \"\"; String s137 = \"\"; String s138 = \"\"; String s139 = \"\"; String s140 = \"\";\n" + + " String s141 = \"\"; String s142 = \"\"; String s143 = \"\"; String s144 = \"\"; String s145 = \"\"; String s146 = \"\"; String s147 = \"\"; String s148 = \"\"; String s149 = \"\"; String s150 = \"\";\n" + + " String s151 = \"\"; String s152 = \"\"; String s153 = \"\"; String s154 = \"\"; String s155 = \"\"; String s156 = \"\"; String s157 = \"\"; String s158 = \"\"; String s159 = \"\"; String s160 = \"\";\n" + + " String s161 = \"\"; String s162 = \"\"; String s163 = \"\"; String s164 = \"\"; String s165 = \"\"; String s166 = \"\"; String s167 = \"\"; String s168 = \"\"; String s169 = \"\"; String s170 = \"\";\n" + + " String s171 = \"\"; String s172 = \"\"; String s173 = \"\"; String s174 = \"\"; String s175 = \"\"; String s176 = \"\"; String s177 = \"\"; String s178 = \"\"; String s179 = \"\"; String s180 = \"\";\n" + + " String s181 = \"\"; String s182 = \"\"; String s183 = \"\"; String s184 = \"\"; String s185 = \"\"; String s186 = \"\"; String s187 = \"\"; String s188 = \"\"; String s189 = \"\"; String s190 = \"\";\n" + + " String s191 = \"\"; String s192 = \"\"; String s193 = \"\"; String s194 = \"\"; String s195 = \"\"; String s196 = \"\"; String s197 = \"\"; String s198 = \"\"; String s199 = \"\"; String s200 = \"\";\n" + + " String s201 = \"\"; String s202 = \"\"; String s203 = \"\"; String s204 = \"\"; String s205 = \"\"; String s206 = \"\"; String s207 = \"\"; String s208 = \"\"; String s209 = \"\"; String s210 = \"\";\n" + + " String s211 = \"\"; String s212 = \"\"; String s213 = \"\"; String s214 = \"\"; String s215 = \"\"; String s216 = \"\"; String s217 = \"\"; String s218 = \"\"; String s219 = \"\"; String s220 = \"\";\n" + + " String s221 = \"\"; String s222 = \"\"; String s223 = \"\"; String s224 = \"\"; String s225 = \"\"; String s226 = \"\"; String s227 = \"\"; String s228 = \"\"; String s229 = \"\"; String s230 = \"\";\n" + + " String s231 = \"\"; String s232 = \"\"; String s233 = \"\"; String s234 = \"\"; String s235 = \"\"; String s236 = \"\"; String s237 = \"\"; String s238 = \"\"; String s239 = \"\"; String s240 = \"\";\n" + + " String s241 = \"\"; String s242 = \"\"; String s243 = \"\"; String s244 = \"\"; String s245 = \"\"; String s246 = \"\"; String s247 = \"\"; String s248 = \"\"; String s249 = \"\"; String s250 = \"\";\n" + + " String s251 = \"\"; String s252 = \"\";\n" + + "\n" + + " int size1 = 1;\n" + + " int size2 = 2;\n" + + " int size3 = 3;\n" + + "\n" + + " char[][][] array = new char[size1][size2][size3];\n" + + " \n" + + " for (int i = 0; i < size1; i++) {\n" + + " for (int j = 0; j < size2; j++) {\n" + + " boolean on = false;\n" + + " for (int k = 0; k < size3; k++) {\n" + + " array[i][j][k] = on ? 'c' : 'd';\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().show();\n" + + " }\n" + + "}", + }, + "", + settings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=457426 +public void test014() throws Exception { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + "\n" + + " public void show() {\n" + + " String s1 = \"\"; String s2 = \"\"; String s3 = \"\"; String s4 = \"\"; String s5 = \"\"; String s6 = \"\"; String s7 = \"\"; String s8 = \"\"; String s9 = \"\"; String s10 = \"\";\n" + + " String s11 = \"\"; String s12 = \"\"; String s13 = \"\"; String s14 = \"\"; String s15 = \"\"; String s16 = \"\"; String s17 = \"\"; String s18 = \"\"; String s19 = \"\"; String s20 = \"\";\n" + + " String s21 = \"\"; String s22 = \"\"; String s23 = \"\"; String s24 = \"\"; String s25 = \"\"; String s26 = \"\"; String s27 = \"\"; String s28 = \"\"; String s29 = \"\"; String s30 = \"\";\n" + + " String s31 = \"\"; String s32 = \"\"; String s33 = \"\"; String s34 = \"\"; String s35 = \"\"; String s36 = \"\"; String s37 = \"\"; String s38 = \"\"; String s39 = \"\"; String s40 = \"\";\n" + + " String s41 = \"\"; String s42 = \"\"; String s43 = \"\"; String s44 = \"\"; String s45 = \"\"; String s46 = \"\"; String s47 = \"\"; String s48 = \"\"; String s49 = \"\"; String s50 = \"\";\n" + + " String s51 = \"\"; String s52 = \"\"; String s53 = \"\"; String s54 = \"\"; String s55 = \"\"; String s56 = \"\"; String s57 = \"\"; String s58 = \"\"; String s59 = \"\"; String s60 = \"\";\n" + + " String s61 = \"\"; String s62 = \"\"; String s63 = \"\"; String s64 = \"\"; String s65 = \"\"; String s66 = \"\"; String s67 = \"\"; String s68 = \"\"; String s69 = \"\"; String s70 = \"\";\n" + + " String s71 = \"\"; String s72 = \"\"; String s73 = \"\"; String s74 = \"\"; String s75 = \"\"; String s76 = \"\"; String s77 = \"\"; String s78 = \"\"; String s79 = \"\"; String s80 = \"\";\n" + + " String s81 = \"\"; String s82 = \"\"; String s83 = \"\"; String s84 = \"\"; String s85 = \"\"; String s86 = \"\"; String s87 = \"\"; String s88 = \"\"; String s89 = \"\"; String s90 = \"\";\n" + + " String s91 = \"\"; String s92 = \"\"; String s93 = \"\"; String s94 = \"\"; String s95 = \"\"; String s96 = \"\"; String s97 = \"\"; String s98 = \"\"; String s99 = \"\"; String s100 = \"\";\n" + + " String s101 = \"\"; String s102 = \"\"; String s103 = \"\"; String s104 = \"\"; String s105 = \"\"; String s106 = \"\"; String s107 = \"\"; String s108 = \"\"; String s109 = \"\"; String s110 = \"\";\n" + + " String s111 = \"\"; String s112 = \"\"; String s113 = \"\"; String s114 = \"\"; String s115 = \"\"; String s116 = \"\"; String s117 = \"\"; String s118 = \"\"; String s119 = \"\"; String s120 = \"\";\n" + + " String s121 = \"\"; String s122 = \"\"; String s123 = \"\"; String s124 = \"\"; String s125 = \"\"; String s126 = \"\"; String s127 = \"\"; String s128 = \"\"; String s129 = \"\"; String s130 = \"\";\n" + + " String s131 = \"\"; String s132 = \"\"; String s133 = \"\"; String s134 = \"\"; String s135 = \"\"; String s136 = \"\"; String s137 = \"\"; String s138 = \"\"; String s139 = \"\"; String s140 = \"\";\n" + + " String s141 = \"\"; String s142 = \"\"; String s143 = \"\"; String s144 = \"\"; String s145 = \"\"; String s146 = \"\"; String s147 = \"\"; String s148 = \"\"; String s149 = \"\"; String s150 = \"\";\n" + + " String s151 = \"\"; String s152 = \"\"; String s153 = \"\"; String s154 = \"\"; String s155 = \"\"; String s156 = \"\"; String s157 = \"\"; String s158 = \"\"; String s159 = \"\"; String s160 = \"\";\n" + + " String s161 = \"\"; String s162 = \"\"; String s163 = \"\"; String s164 = \"\"; String s165 = \"\"; String s166 = \"\"; String s167 = \"\"; String s168 = \"\"; String s169 = \"\"; String s170 = \"\";\n" + + " String s171 = \"\"; String s172 = \"\"; String s173 = \"\"; String s174 = \"\"; String s175 = \"\"; String s176 = \"\"; String s177 = \"\"; String s178 = \"\"; String s179 = \"\"; String s180 = \"\";\n" + + " String s181 = \"\"; String s182 = \"\"; String s183 = \"\"; String s184 = \"\"; String s185 = \"\"; String s186 = \"\"; String s187 = \"\"; String s188 = \"\"; String s189 = \"\"; String s190 = \"\";\n" + + " String s191 = \"\"; String s192 = \"\"; String s193 = \"\"; String s194 = \"\"; String s195 = \"\"; String s196 = \"\"; String s197 = \"\"; String s198 = \"\"; String s199 = \"\"; String s200 = \"\";\n" + + " String s201 = \"\"; String s202 = \"\"; String s203 = \"\"; String s204 = \"\"; String s205 = \"\"; String s206 = \"\"; String s207 = \"\"; String s208 = \"\"; String s209 = \"\"; String s210 = \"\";\n" + + " String s211 = \"\"; String s212 = \"\"; String s213 = \"\"; String s214 = \"\"; String s215 = \"\"; String s216 = \"\"; String s217 = \"\"; String s218 = \"\"; String s219 = \"\"; String s220 = \"\";\n" + + " String s221 = \"\"; String s222 = \"\"; String s223 = \"\"; String s224 = \"\"; String s225 = \"\"; String s226 = \"\"; String s227 = \"\"; String s228 = \"\"; String s229 = \"\"; String s230 = \"\";\n" + + " String s231 = \"\"; String s232 = \"\"; String s233 = \"\"; String s234 = \"\"; String s235 = \"\"; String s236 = \"\"; String s237 = \"\"; String s238 = \"\"; String s239 = \"\"; String s240 = \"\";\n" + + " String s241 = \"\"; String s242 = \"\"; String s243 = \"\"; String s244 = \"\"; String s245 = \"\"; String s246 = \"\"; String s247 = \"\"; String s248 = \"\"; String s249 = \"\"; String s250 = \"\";\n" + + " String s251 = \"\"; String s252 = \"\";\n" + + "\n" + + " int size1 = 1;\n" + + " int size2 = 2;\n" + + " int size3 = 3;\n" + + "\n" + + " byte[][][] array = new byte[size1][size2][size3];\n" + + " \n" + + " for (int i = 0; i < size1; i++) {\n" + + " for (int j = 0; j < size2; j++) {\n" + + " boolean on = false;\n" + + " for (int k = 0; k < size3; k++) {\n" + + " array[i][j][k] = on ? (byte) 1 : (byte) 0;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().show();\n" + + " }\n" + + "}", + }, + "", + settings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=457426 +public void test015() throws Exception { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + "\n" + + " public void show() {\n" + + " String s1 = \"\"; String s2 = \"\"; String s3 = \"\"; String s4 = \"\"; String s5 = \"\"; String s6 = \"\"; String s7 = \"\"; String s8 = \"\"; String s9 = \"\"; String s10 = \"\";\n" + + " String s11 = \"\"; String s12 = \"\"; String s13 = \"\"; String s14 = \"\"; String s15 = \"\"; String s16 = \"\"; String s17 = \"\"; String s18 = \"\"; String s19 = \"\"; String s20 = \"\";\n" + + " String s21 = \"\"; String s22 = \"\"; String s23 = \"\"; String s24 = \"\"; String s25 = \"\"; String s26 = \"\"; String s27 = \"\"; String s28 = \"\"; String s29 = \"\"; String s30 = \"\";\n" + + " String s31 = \"\"; String s32 = \"\"; String s33 = \"\"; String s34 = \"\"; String s35 = \"\"; String s36 = \"\"; String s37 = \"\"; String s38 = \"\"; String s39 = \"\"; String s40 = \"\";\n" + + " String s41 = \"\"; String s42 = \"\"; String s43 = \"\"; String s44 = \"\"; String s45 = \"\"; String s46 = \"\"; String s47 = \"\"; String s48 = \"\"; String s49 = \"\"; String s50 = \"\";\n" + + " String s51 = \"\"; String s52 = \"\"; String s53 = \"\"; String s54 = \"\"; String s55 = \"\"; String s56 = \"\"; String s57 = \"\"; String s58 = \"\"; String s59 = \"\"; String s60 = \"\";\n" + + " String s61 = \"\"; String s62 = \"\"; String s63 = \"\"; String s64 = \"\"; String s65 = \"\"; String s66 = \"\"; String s67 = \"\"; String s68 = \"\"; String s69 = \"\"; String s70 = \"\";\n" + + " String s71 = \"\"; String s72 = \"\"; String s73 = \"\"; String s74 = \"\"; String s75 = \"\"; String s76 = \"\"; String s77 = \"\"; String s78 = \"\"; String s79 = \"\"; String s80 = \"\";\n" + + " String s81 = \"\"; String s82 = \"\"; String s83 = \"\"; String s84 = \"\"; String s85 = \"\"; String s86 = \"\"; String s87 = \"\"; String s88 = \"\"; String s89 = \"\"; String s90 = \"\";\n" + + " String s91 = \"\"; String s92 = \"\"; String s93 = \"\"; String s94 = \"\"; String s95 = \"\"; String s96 = \"\"; String s97 = \"\"; String s98 = \"\"; String s99 = \"\"; String s100 = \"\";\n" + + " String s101 = \"\"; String s102 = \"\"; String s103 = \"\"; String s104 = \"\"; String s105 = \"\"; String s106 = \"\"; String s107 = \"\"; String s108 = \"\"; String s109 = \"\"; String s110 = \"\";\n" + + " String s111 = \"\"; String s112 = \"\"; String s113 = \"\"; String s114 = \"\"; String s115 = \"\"; String s116 = \"\"; String s117 = \"\"; String s118 = \"\"; String s119 = \"\"; String s120 = \"\";\n" + + " String s121 = \"\"; String s122 = \"\"; String s123 = \"\"; String s124 = \"\"; String s125 = \"\"; String s126 = \"\"; String s127 = \"\"; String s128 = \"\"; String s129 = \"\"; String s130 = \"\";\n" + + " String s131 = \"\"; String s132 = \"\"; String s133 = \"\"; String s134 = \"\"; String s135 = \"\"; String s136 = \"\"; String s137 = \"\"; String s138 = \"\"; String s139 = \"\"; String s140 = \"\";\n" + + " String s141 = \"\"; String s142 = \"\"; String s143 = \"\"; String s144 = \"\"; String s145 = \"\"; String s146 = \"\"; String s147 = \"\"; String s148 = \"\"; String s149 = \"\"; String s150 = \"\";\n" + + " String s151 = \"\"; String s152 = \"\"; String s153 = \"\"; String s154 = \"\"; String s155 = \"\"; String s156 = \"\"; String s157 = \"\"; String s158 = \"\"; String s159 = \"\"; String s160 = \"\";\n" + + " String s161 = \"\"; String s162 = \"\"; String s163 = \"\"; String s164 = \"\"; String s165 = \"\"; String s166 = \"\"; String s167 = \"\"; String s168 = \"\"; String s169 = \"\"; String s170 = \"\";\n" + + " String s171 = \"\"; String s172 = \"\"; String s173 = \"\"; String s174 = \"\"; String s175 = \"\"; String s176 = \"\"; String s177 = \"\"; String s178 = \"\"; String s179 = \"\"; String s180 = \"\";\n" + + " String s181 = \"\"; String s182 = \"\"; String s183 = \"\"; String s184 = \"\"; String s185 = \"\"; String s186 = \"\"; String s187 = \"\"; String s188 = \"\"; String s189 = \"\"; String s190 = \"\";\n" + + " String s191 = \"\"; String s192 = \"\"; String s193 = \"\"; String s194 = \"\"; String s195 = \"\"; String s196 = \"\"; String s197 = \"\"; String s198 = \"\"; String s199 = \"\"; String s200 = \"\";\n" + + " String s201 = \"\"; String s202 = \"\"; String s203 = \"\"; String s204 = \"\"; String s205 = \"\"; String s206 = \"\"; String s207 = \"\"; String s208 = \"\"; String s209 = \"\"; String s210 = \"\";\n" + + " String s211 = \"\"; String s212 = \"\"; String s213 = \"\"; String s214 = \"\"; String s215 = \"\"; String s216 = \"\"; String s217 = \"\"; String s218 = \"\"; String s219 = \"\"; String s220 = \"\";\n" + + " String s221 = \"\"; String s222 = \"\"; String s223 = \"\"; String s224 = \"\"; String s225 = \"\"; String s226 = \"\"; String s227 = \"\"; String s228 = \"\"; String s229 = \"\"; String s230 = \"\";\n" + + " String s231 = \"\"; String s232 = \"\"; String s233 = \"\"; String s234 = \"\"; String s235 = \"\"; String s236 = \"\"; String s237 = \"\"; String s238 = \"\"; String s239 = \"\"; String s240 = \"\";\n" + + " String s241 = \"\"; String s242 = \"\"; String s243 = \"\"; String s244 = \"\"; String s245 = \"\"; String s246 = \"\"; String s247 = \"\"; String s248 = \"\"; String s249 = \"\"; String s250 = \"\";\n" + + " String s251 = \"\"; String s252 = \"\";\n" + + "\n" + + " int size1 = 1;\n" + + " int size2 = 2;\n" + + " int size3 = 3;\n" + + "\n" + + " short[][][] array = new short[size1][size2][size3];\n" + + " \n" + + " for (int i = 0; i < size1; i++) {\n" + + " for (int j = 0; j < size2; j++) {\n" + + " boolean on = false;\n" + + " for (int k = 0; k < size3; k++) {\n" + + " array[i][j][k] = on ? (short) 1 : (short) 0;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().show();\n" + + " }\n" + + "}", + }, + "", + settings); +} +public static Class testClass() { + return ForStatementTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java new file mode 100644 index 0000000000..81d397006d --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ForeachStatementTest.java @@ -0,0 +1,3076 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 388800 - [1.8] adjust tests to 1.8 JRE + * bug 393719 - [compiler] inconsistent warnings on iteration variables + * Jesper S Moller - Contribution for + * bug 401853 - Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError) + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class ForeachStatementTest extends AbstractComparableTest { + +public ForeachStatementTest(String name) { + super(name); +} + +/* + * Toggle compiler in mode -1.5 + */ +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); + return options; +} +// Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which do not belong to the class are skipped... +static { +// TESTS_NAMES = new String[] { "test055" }; +// TESTS_NUMBERS = new int[] { 50, 51, 52, 53 }; +// TESTS_RANGE = new int[] { 34, 38 }; +} +public static Test suite() { + return buildComparableTestSuite(testClass()); +} +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " \n" + + " for (char c : \"SUCCESS\".toCharArray()) {\n" + + " System.out.print(c);\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " \n" + + " for (int value : new int[] {value}) {\n" + + " System.out.println(value);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for (int value : new int[] {value}) {\n" + + " ^^^^^\n" + + "value cannot be resolved to a variable\n" + + "----------\n"); +} +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " \n" + + " for (int value : value) {\n" + + " System.out.println(value);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for (int value : value) {\n" + + " ^^^^^\n" + + "value cannot be resolved to a variable\n" + + "----------\n"); +} +public void test004() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + " int sum = 0;\n" + + " loop: for (final int e : tab) {\n" + + " sum += e;\n" + + " if (e == 3) {\n" + + " break loop;\n" + + " }\n" + + " }\n" + + " System.out.println(sum);\n" + + " }\n" + + "}\n", + }, + "6"); +} +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final int i;\n" + + " int[] tab = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + " int sum = 0;\n" + + " loop: for (final int e : tab) {\n" + + " sum += e;\n" + + " if (e == 3) {\n" + + " i = 1;\n" + + " break loop;\n" + + " }\n" + + " }\n" + + " System.out.println(sum + i);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " System.out.println(sum + i);\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); +} +public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " final int i;\n" + + " int[] tab = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + " loop: for (final int e : tab) {\n" + + " i = e;\n" + + " if (e == 3) {\n" + + " i = 1;\n" + + " break loop;\n" + + " }\n" + + " }\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " i = e;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " i = 1;\n" + + " ^\n" + + "The final local variable i may already have been assigned\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " System.out.println(i);\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); +} +public void test007() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int i;\n" + + " int[] tab = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + " for (final int e : tab) {\n" + + " i = e;\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + true, + null, + customOptions, + null/*no custom requestor*/); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 7\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 9\n" + + " 2 newarray int [10]\n" + + " 4 dup\n" + + " 5 iconst_0\n" + + " 6 iconst_1\n" + + " 7 iastore\n" + + " 8 dup\n" + + " 9 iconst_1\n" + + " 10 iconst_2\n" + + " 11 iastore\n" + + " 12 dup\n" + + " 13 iconst_2\n" + + " 14 iconst_3\n" + + " 15 iastore\n" + + " 16 dup\n" + + " 17 iconst_3\n" + + " 18 iconst_4\n" + + " 19 iastore\n" + + " 20 dup\n" + + " 21 iconst_4\n" + + " 22 iconst_5\n" + + " 23 iastore\n" + + " 24 dup\n" + + " 25 iconst_5\n" + + " 26 bipush 6\n" + + " 28 iastore\n" + + " 29 dup\n" + + " 30 bipush 6\n" + + " 32 bipush 7\n" + + " 34 iastore\n" + + " 35 dup\n" + + " 36 bipush 7\n" + + " 38 bipush 8\n" + + " 40 iastore\n" + + " 41 dup\n" + + " 42 bipush 8\n" + + " 44 bipush 9\n" + + " 46 iastore\n" + + " 47 astore_2 [tab]\n" + + " 48 aload_2 [tab]\n" + + " 49 dup\n" + + " 50 astore 6\n" + + " 52 arraylength\n" + + " 53 istore 5\n" + + " 55 iconst_0\n" + + " 56 istore 4\n" + + " 58 goto 72\n" + + " 61 aload 6\n" + + " 63 iload 4\n" + + " 65 iaload\n" + + " 66 istore_3 [e]\n" + + " 67 iload_3 [e]\n" + + " 68 istore_1\n" + + " 69 iinc 4 1\n" + + " 72 iload 4\n" + + " 74 iload 5\n" + + " 76 if_icmplt 61\n" + + " 79 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 82 ldc [22]\n" + + " 84 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 87 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 48, line: 6]\n" + + " [pc: 67, line: 7]\n" + + " [pc: 69, line: 6]\n" + + " [pc: 79, line: 9]\n" + + " [pc: 87, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 88] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 48, pc: 88] local: tab index: 2 type: int[]\n" + + " [pc: 67, pc: 69] local: e index: 3 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Iterable col) {\n" + + " for (X x : col) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo(Iterable col) {\n" + + " ^^^^^^^^\n" + + "Iterable is a raw type. References to generic type Iterable should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " for (X x : col) {\n" + + " ^^^\n" + + "Type mismatch: cannot convert from element type Object to X\n" + + "----------\n"); +} +public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Iterable col) {\n" + + " for (X x : col) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (X x : col) {\n" + + " ^^^\n" + + "Type mismatch: cannot convert from element type String to X\n" + + "----------\n"); +} +/* + * Test implicit conversion to float. If missing, VerifyError + */ +public void test010() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + " int sum = 0;\n" + + " loop: for (final float e : tab) {\n" + + " sum += e;\n" + + " if (e == 3) {\n" + + " break loop;\n" + + " }\n" + + " }\n" + + " System.out.println(sum);\n" + + " }\n" + + "}\n", + }, + "6"); +} +/* + * Cannot convert int[] to int + */ +public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[][] tab = new int[][] {\n" + + " new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },\n" + + " new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },\n" + + " };\n" + + " loop: for (final int e : tab) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " loop: for (final int e : tab) {\n" + + " ^^^\n" + + "Type mismatch: cannot convert from element type int[] to int\n" + + "----------\n"); +} +/* + * Ensure access to int[] + */ +public void test012() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[][] tab = new int[][] {\n" + + " new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },\n" + + " new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },\n" + + " };\n" + + " for (final int[] e : tab) {\n" + + " System.out.print(e.length);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "99"); +} +/* + * Ensure access to int[] + */ +public void test013() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[][] tab = new int[][] {\n" + + " new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },\n" + + " new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 },\n" + + " };\n" + + " for (final int[] e : tab) {\n" + + " System.out.print(e[0]);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "11"); +} +/* + * Empty block action + */ +public void test014() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] { 1 };\n" + + " for (final int e : tab) {\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 newarray int [10]\n" + + " 3 dup\n" + + " 4 iconst_0\n" + + " 5 iconst_1\n" + + " 6 iastore\n" + + " 7 astore_1 [tab]\n" + + " 8 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 11 ldc [22]\n" + + " 13 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 7]\n" + + " [pc: 16, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 17] local: tab index: 1 type: int[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +/* + * Empty statement action + */ +public void test015() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] { 1 };\n" + + " for (final int e : tab);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 newarray int [10]\n" + + " 3 dup\n" + + " 4 iconst_0\n" + + " 5 iconst_1\n" + + " 6 iastore\n" + + " 7 astore_1 [tab]\n" + + " 8 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 11 ldc [22]\n" + + " 13 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 16, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 17] local: tab index: 1 type: int[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +/* + * Empty block action + */ +public void test016() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] { 1 };\n" + + " for (final int e : tab) {;\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 5\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 newarray int [10]\n" + + " 3 dup\n" + + " 4 iconst_0\n" + + " 5 iconst_1\n" + + " 6 iastore\n" + + " 7 astore_1 [tab]\n" + + " 8 aload_1 [tab]\n" + + " 9 dup\n" + + " 10 astore 4\n" + + " 12 arraylength\n" + + " 13 istore_3\n" + + " 14 iconst_0\n" + + " 15 istore_2\n" + + " 16 goto 22\n" + + " 19 iinc 2 1\n" + + " 22 iload_2\n" + + " 23 iload_3\n" + + " 24 if_icmplt 19\n" + + " 27 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 30 ldc [22]\n" + + " 32 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 35 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 27, line: 7]\n" + + " [pc: 35, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 36] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 36] local: tab index: 1 type: int[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +/* + * Ensure access to int[] + */ +public void test017() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] { 1 };\n" + + " for (final int e : tab) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +/* + * Break the loop + */ +public void test018() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] { 1 };\n" + + " for (final int e : tab) {\n" + + " System.out.println(e);\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "1"); + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 newarray int [10]\n" + + " 3 dup\n" + + " 4 iconst_0\n" + + " 5 iconst_1\n" + + " 6 iastore\n" + + " 7 astore_1 [tab]\n" + + " 8 aload_1 [tab]\n" + + " 9 dup\n" + + " 10 astore_3\n" + + " 11 arraylength\n" + + " 12 ifeq 26\n" + + " 15 aload_3\n" + + " 16 iconst_0\n" + + " 17 iaload\n" + + " 18 istore_2 [e]\n" + + " 19 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 22 iload_2 [e]\n" + + " 23 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 26 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 19, line: 6]\n" + + " [pc: 26, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 27] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 27] local: tab index: 1 type: int[]\n" + + " [pc: 19, pc: 26] local: e index: 2 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +/* + * Break the loop + */ +public void test019() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] {};\n" + + " System.out.print(\"SUC\");\n" + + " for (final int e : tab) {\n" + + " System.out.print(\"1x\");\n" + + " break;\n" + + " }\n" + + " System.out.println(\"CESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 newarray int [10]\n" + + " 3 astore_1 [tab]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 7 ldc [22]\n" + + " 9 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 12 aload_1 [tab]\n" + + " 13 dup\n" + + " 14 astore_2\n" + + " 15 arraylength\n" + + " 16 ifeq 27\n" + + " 19 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 22 ldc [30]\n" + + " 24 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 27 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 30 ldc [32]\n" + + " 32 invokevirtual java.io.PrintStream.println(java.lang.String) : void [34]\n" + + " 35 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 12, line: 6]\n" + + " [pc: 19, line: 7]\n" + + " [pc: 27, line: 10]\n" + + " [pc: 35, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 36] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 36] local: tab index: 1 type: int[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +/* + * Break the loop + */ +public void test020() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] {};\n" + + " System.out.print(\"SUC\");\n" + + " loop: for (final int e : tab) {\n" + + " System.out.print(\"1x\");\n" + + " continue loop;\n" + + " }\n" + + " System.out.println(\"CESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 5\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 newarray int [10]\n" + + " 3 astore_1 [tab]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 7 ldc [22]\n" + + " 9 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 12 aload_1 [tab]\n" + + " 13 dup\n" + + " 14 astore 4\n" + + " 16 arraylength\n" + + " 17 istore_3\n" + + " 18 iconst_0\n" + + " 19 istore_2\n" + + " 20 goto 34\n" + + " 23 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 26 ldc [30]\n" + + " 28 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 31 iinc 2 1\n" + + " 34 iload_2\n" + + " 35 iload_3\n" + + " 36 if_icmplt 23\n" + + " 39 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 42 ldc [32]\n" + + " 44 invokevirtual java.io.PrintStream.println(java.lang.String) : void [34]\n" + + " 47 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 12, line: 6]\n" + + " [pc: 23, line: 7]\n" + + " [pc: 31, line: 6]\n" + + " [pc: 39, line: 10]\n" + + " [pc: 47, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 48] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 48] local: tab index: 1 type: int[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test021() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + " int sum = 0;\n" + + " int i = 0;\n" + + " loop1: while(true) {\n" + + " i++;\n" + + " loop: for (final int e : tab) {\n" + + " sum += e;\n" + + " if (i == 3) {\n" + + " break loop1;\n" + + " } else if (e == 5) {\n" + + " break loop;\n" + + " } else {\n" + + " continue;\n" + + " }\n" + + " }\n" + + " }\n" + + " System.out.println(sum);\n" + + " }\n" + + "}", + }, + "31"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 8\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 9\n" + + " 2 newarray int [10]\n" + + " 4 dup\n" + + " 5 iconst_0\n" + + " 6 iconst_1\n" + + " 7 iastore\n" + + " 8 dup\n" + + " 9 iconst_1\n" + + " 10 iconst_2\n" + + " 11 iastore\n" + + " 12 dup\n" + + " 13 iconst_2\n" + + " 14 iconst_3\n" + + " 15 iastore\n" + + " 16 dup\n" + + " 17 iconst_3\n" + + " 18 iconst_4\n" + + " 19 iastore\n" + + " 20 dup\n" + + " 21 iconst_4\n" + + " 22 iconst_5\n" + + " 23 iastore\n" + + " 24 dup\n" + + " 25 iconst_5\n" + + " 26 bipush 6\n" + + " 28 iastore\n" + + " 29 dup\n" + + " 30 bipush 6\n" + + " 32 bipush 7\n" + + " 34 iastore\n" + + " 35 dup\n" + + " 36 bipush 7\n" + + " 38 bipush 8\n" + + " 40 iastore\n" + + " 41 dup\n" + + " 42 bipush 8\n" + + " 44 bipush 9\n" + + " 46 iastore\n" + + " 47 astore_1 [tab]\n" + + " 48 iconst_0\n" + + " 49 istore_2 [sum]\n" + + " 50 iconst_0\n" + + " 51 istore_3 [i]\n" + + " 52 iinc 3 1 [i]\n" + + " 55 aload_1 [tab]\n" + + " 56 dup\n" + + " 57 astore 7\n" + + " 59 arraylength\n" + + " 60 istore 6\n" + + " 62 iconst_0\n" + + " 63 istore 5\n" + + " 65 goto 100\n" + + " 68 aload 7\n" + + " 70 iload 5\n" + + " 72 iaload\n" + + " 73 istore 4 [e]\n" + + " 75 iload_2 [sum]\n" + + " 76 iload 4 [e]\n" + + " 78 iadd\n" + + " 79 istore_2 [sum]\n" + + " 80 iload_3 [i]\n" + + " 81 iconst_3\n" + + " 82 if_icmpne 88\n" + + " 85 goto 110\n" + + " 88 iload 4 [e]\n" + + " 90 iconst_5\n" + + " 91 if_icmpne 97\n" + + " 94 goto 52\n" + + " 97 iinc 5 1\n" + + " 100 iload 5\n" + + " 102 iload 6\n" + + " 104 if_icmplt 68\n" + + " 107 goto 52\n" + + " 110 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 113 iload_2 [sum]\n" + + " 114 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 117 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 48, line: 4]\n" + + " [pc: 50, line: 5]\n" + + " [pc: 52, line: 7]\n" + + " [pc: 55, line: 8]\n" + + " [pc: 75, line: 9]\n" + + " [pc: 80, line: 10]\n" + + " [pc: 85, line: 11]\n" + + " [pc: 88, line: 12]\n" + + " [pc: 94, line: 13]\n" + + " [pc: 97, line: 8]\n" + + " [pc: 107, line: 6]\n" + + " [pc: 110, line: 19]\n" + + " [pc: 117, line: 20]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 118] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 48, pc: 118] local: tab index: 1 type: int[]\n" + + " [pc: 50, pc: 118] local: sum index: 2 type: int\n" + + " [pc: 52, pc: 118] local: i index: 3 type: int\n" + + " [pc: 75, pc: 97] local: e index: 4 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test022() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " ArrayList arrayList = new ArrayList();\n" + + " for (int i = 0; i < 10; i++) {\n" + + " arrayList.add(new Integer(i));\n" + + " }\n" + + " int sum = 0;\n" + + " for (Integer e : arrayList) {\n" + + " sum += e.intValue();\n" + + " }\n" + + " System.out.println(sum);\n" + + " }\n" + + "}", + }, + "45"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 5\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new java.util.ArrayList [16]\n" + + " 3 dup\n" + + " 4 invokespecial java.util.ArrayList() [18]\n" + + " 7 astore_1 [arrayList]\n" + + " 8 iconst_0\n" + + " 9 istore_2 [i]\n" + + " 10 goto 29\n" + + " 13 aload_1 [arrayList]\n" + + " 14 new java.lang.Integer [19]\n" + + " 17 dup\n" + + " 18 iload_2 [i]\n" + + " 19 invokespecial java.lang.Integer(int) [21]\n" + + " 22 invokevirtual java.util.ArrayList.add(java.lang.Object) : boolean [24]\n" + + " 25 pop\n" + + " 26 iinc 2 1 [i]\n" + + " 29 iload_2 [i]\n" + + " 30 bipush 10\n" + + " 32 if_icmplt 13\n" + + " 35 iconst_0\n" + + " 36 istore_2 [sum]\n" + + " 37 aload_1 [arrayList]\n" + + " 38 invokevirtual java.util.ArrayList.iterator() : java.util.Iterator [28]\n" + + " 41 astore 4\n" + + " 43 goto 64\n" + + " 46 aload 4\n" + + " 48 invokeinterface java.util.Iterator.next() : java.lang.Object [32] [nargs: 1]\n" + + " 53 checkcast java.lang.Integer [19]\n" + + " 56 astore_3 [e]\n" + + " 57 iload_2 [sum]\n" + + " 58 aload_3 [e]\n" + + " 59 invokevirtual java.lang.Integer.intValue() : int [38]\n" + + " 62 iadd\n" + + " 63 istore_2 [sum]\n" + + " 64 aload 4\n" + + " 66 invokeinterface java.util.Iterator.hasNext() : boolean [42] [nargs: 1]\n" + + " 71 ifne 46\n" + + " 74 getstatic java.lang.System.out : java.io.PrintStream [46]\n" + + " 77 iload_2 [sum]\n" + + " 78 invokevirtual java.io.PrintStream.println(int) : void [52]\n" + + " 81 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 13, line: 7]\n" + + " [pc: 26, line: 6]\n" + + " [pc: 35, line: 9]\n" + + " [pc: 37, line: 10]\n" + + " [pc: 57, line: 11]\n" + + " [pc: 64, line: 10]\n" + + " [pc: 74, line: 13]\n" + + " [pc: 81, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 82] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 82] local: arrayList index: 1 type: java.util.ArrayList\n" + + " [pc: 10, pc: 35] local: i index: 2 type: int\n" + + " [pc: 37, pc: 82] local: sum index: 2 type: int\n" + + " [pc: 57, pc: 64] local: e index: 3 type: java.lang.Integer\n" + + " Local variable type table:\n" + + " [pc: 8, pc: 82] local: arrayList index: 1 type: java.util.ArrayList\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} + +/* + * Type mismatch, using non parameterized collection type (indirectly implementing parameterized type) + */ +public void test023() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (Thread s : new AX()) {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class AX implements Iterable {\n" + + " \n" + + " public Iterator iterator() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " for (Thread s : new AX()) {\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from element type String to Thread\n" + + "----------\n"); +} +public void test024() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String[] tab = new String[] {\"SUCCESS\"};\n" + + " List list = new ArrayList();\n" + + " for (String arg : tab) { \n" + + " list.add(arg);\n" + + " }\n" + + " for (Object arg: list) {\n" + + " System.out.print(arg);\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 7\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 anewarray java.lang.String [16]\n" + + " 4 dup\n" + + " 5 iconst_0\n" + + " 6 ldc [18]\n" + + " 8 aastore\n" + + " 9 astore_1 [tab]\n" + + " 10 new java.util.ArrayList [20]\n" + + " 13 dup\n" + + " 14 invokespecial java.util.ArrayList() [22]\n" + + " 17 astore_2 [list]\n" + + " 18 aload_1 [tab]\n" + + " 19 dup\n" + + " 20 astore 6\n" + + " 22 arraylength\n" + + " 23 istore 5\n" + + " 25 iconst_0\n" + + " 26 istore 4\n" + + " 28 goto 48\n" + + " 31 aload 6\n" + + " 33 iload 4\n" + + " 35 aaload\n" + + " 36 astore_3 [arg]\n" + + " 37 aload_2 [list]\n" + + " 38 aload_3 [arg]\n" + + " 39 invokeinterface java.util.List.add(java.lang.Object) : boolean [23] [nargs: 2]\n" + + " 44 pop\n" + + " 45 iinc 4 1\n" + + " 48 iload 4\n" + + " 50 iload 5\n" + + " 52 if_icmplt 31\n" + + " 55 aload_2 [list]\n" + + " 56 invokeinterface java.util.List.iterator() : java.util.Iterator [29] [nargs: 1]\n" + + " 61 astore 4\n" + + " 63 goto 81\n" + + " 66 aload 4\n" + + " 68 invokeinterface java.util.Iterator.next() : java.lang.Object [33] [nargs: 1]\n" + + " 73 astore_3 [arg]\n" + + " 74 getstatic java.lang.System.out : java.io.PrintStream [39]\n" + + " 77 aload_3 [arg]\n" + + " 78 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [45]\n" + + " 81 aload 4\n" + + " 83 invokeinterface java.util.Iterator.hasNext() : boolean [51] [nargs: 1]\n" + + " 88 ifne 66\n" + + " 91 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 10, line: 7]\n" + + " [pc: 18, line: 8]\n" + + " [pc: 37, line: 9]\n" + + " [pc: 45, line: 8]\n" + + " [pc: 55, line: 11]\n" + + " [pc: 74, line: 12]\n" + + " [pc: 81, line: 11]\n" + + " [pc: 91, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 92] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 10, pc: 92] local: tab index: 1 type: java.lang.String[]\n" + + " [pc: 18, pc: 92] local: list index: 2 type: java.util.List\n" + + " [pc: 37, pc: 45] local: arg index: 3 type: java.lang.String\n" + + " [pc: 74, pc: 81] local: arg index: 3 type: java.lang.Object\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test025() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public static void bug(List lines) {\n" + + " for (int i=0; i<1; i++) {\n" + + " for (String test: lines) {\n" + + " System.out.print(test);\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " ArrayList tab = new ArrayList();\n" + + " tab.add(\"SUCCESS\");\n" + + " bug(tab);\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +// 68440 - verify error due to local variable invalid slot sharing +public void test026() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object[] array = {\n" + + " };\n" + + " void test() {\n" + + " for (Object object : array) {\n" + + " String str = object.toString();\n" + + " str += \"\";\n" + // force 'str' to be preserved during codegen + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().test();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +// 68863 - missing local variable attribute after foreach statement +public void test027() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object[] array = {\n" + + " };\n" + + " java.util.ArrayList i; \n" + + " for (Object object : array) {\n" + + " if (args == null) {\n" + + " i = null;\n" + + " break;\n" + + " }\n" + + " return;\n" + + " };\n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 anewarray java.lang.Object [3]\n" + + " 4 astore_1 [array]\n" + + " 5 aload_1 [array]\n" + + " 6 dup\n" + + " 7 astore_2\n" + + " 8 arraylength\n" + + " 9 ifeq 22\n" + + " 12 aload_0 [args]\n" + + " 13 ifnonnull 21\n" + + " 16 aconst_null\n" + + " 17 pop\n" + + " 18 goto 22\n" + + " 21 return\n" + + " 22 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 25 ldc [22]\n" + + " 27 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 30 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 5, line: 6]\n" + + " [pc: 12, line: 7]\n" + + " [pc: 16, line: 8]\n" + + " [pc: 18, line: 9]\n" + + " [pc: 21, line: 11]\n" + + " [pc: 22, line: 13]\n" + + " [pc: 30, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 31] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 5, pc: 31] local: array index: 1 type: java.lang.Object[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//72760 - missing local variable attribute after foreach statement +public void test028() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String args[]) {\n" + + " ArrayList> slist = new ArrayList>();\n" + + " \n" + + " slist.add(new ArrayList());\n" + + " slist.get(0).add(\"SU\");\n" + + " slist.get(0).add(\"C\");\n" + + " slist.get(0).add(\"C\");\n" + + " \n" + + " slist.add(new ArrayList());\n" + + " slist.get(1).add(\"E\");\n" + + " slist.get(1).add(\"S\");\n" + + " slist.get(1).add(\"S\");\n" + + " \n" + + " for (int i=0; i [27]\n" + + " 30 invokevirtual java.util.ArrayList.add(java.lang.Object) : boolean [19]\n" + + " 33 pop\n" + + " 34 aload_1 [slist]\n" + + " 35 iconst_0\n" + + " 36 invokevirtual java.util.ArrayList.get(int) : java.lang.Object [23]\n" + + " 39 checkcast java.util.ArrayList [16]\n" + + " 42 ldc [29]\n" + + " 44 invokevirtual java.util.ArrayList.add(java.lang.Object) : boolean [19]\n" + + " 47 pop\n" + + " 48 aload_1 [slist]\n" + + " 49 iconst_0\n" + + " 50 invokevirtual java.util.ArrayList.get(int) : java.lang.Object [23]\n" + + " 53 checkcast java.util.ArrayList [16]\n" + + " 56 ldc [29]\n" + + " 58 invokevirtual java.util.ArrayList.add(java.lang.Object) : boolean [19]\n" + + " 61 pop\n" + + " 62 aload_1 [slist]\n" + + " 63 new java.util.ArrayList [16]\n" + + " 66 dup\n" + + " 67 invokespecial java.util.ArrayList() [18]\n" + + " 70 invokevirtual java.util.ArrayList.add(java.lang.Object) : boolean [19]\n" + + " 73 pop\n" + + " 74 aload_1 [slist]\n" + + " 75 iconst_1\n" + + " 76 invokevirtual java.util.ArrayList.get(int) : java.lang.Object [23]\n" + + " 79 checkcast java.util.ArrayList [16]\n" + + " 82 ldc [31]\n" + + " 84 invokevirtual java.util.ArrayList.add(java.lang.Object) : boolean [19]\n" + + " 87 pop\n" + + " 88 aload_1 [slist]\n" + + " 89 iconst_1\n" + + " 90 invokevirtual java.util.ArrayList.get(int) : java.lang.Object [23]\n" + + " 93 checkcast java.util.ArrayList [16]\n" + + " 96 ldc [33]\n" + + " 98 invokevirtual java.util.ArrayList.add(java.lang.Object) : boolean [19]\n" + + " 101 pop\n" + + " 102 aload_1 [slist]\n" + + " 103 iconst_1\n" + + " 104 invokevirtual java.util.ArrayList.get(int) : java.lang.Object [23]\n" + + " 107 checkcast java.util.ArrayList [16]\n" + + " 110 ldc [33]\n" + + " 112 invokevirtual java.util.ArrayList.add(java.lang.Object) : boolean [19]\n" + + " 115 pop\n" + + " 116 iconst_0\n" + + " 117 istore_2 [i]\n" + + " 118 goto 168\n" + + " 121 aload_1 [slist]\n" + + " 122 iload_2 [i]\n" + + " 123 invokevirtual java.util.ArrayList.get(int) : java.lang.Object [23]\n" + + " 126 checkcast java.util.ArrayList [16]\n" + + " 129 invokevirtual java.util.ArrayList.iterator() : java.util.Iterator [35]\n" + + " 132 astore 4\n" + + " 134 goto 155\n" + + " 137 aload 4\n" + + " 139 invokeinterface java.util.Iterator.next() : java.lang.Object [39] [nargs: 1]\n" + + " 144 checkcast java.lang.String [45]\n" + + " 147 astore_3 [s]\n" + + " 148 getstatic java.lang.System.out : java.io.PrintStream [47]\n" + + " 151 aload_3 [s]\n" + + " 152 invokevirtual java.io.PrintStream.print(java.lang.String) : void [53]\n" + + " 155 aload 4\n" + + " 157 invokeinterface java.util.Iterator.hasNext() : boolean [59] [nargs: 1]\n" + + " 162 ifne 137\n" + + " 165 iinc 2 1 [i]\n" + + " 168 iload_2 [i]\n" + + " 169 aload_1 [slist]\n" + + " 170 invokevirtual java.util.ArrayList.size() : int [63]\n" + + " 173 if_icmplt 121\n" + + " 176 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 20, line: 9]\n" + + " [pc: 34, line: 10]\n" + + " [pc: 48, line: 11]\n" + + " [pc: 62, line: 13]\n" + + " [pc: 74, line: 14]\n" + + " [pc: 88, line: 15]\n" + + " [pc: 102, line: 16]\n" + + " [pc: 116, line: 18]\n" + + " [pc: 121, line: 19]\n" + + " [pc: 148, line: 20]\n" + + " [pc: 155, line: 19]\n" + + " [pc: 165, line: 18]\n" + + " [pc: 176, line: 23]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 177] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 177] local: slist index: 1 type: java.util.ArrayList\n" + + " [pc: 118, pc: 176] local: i index: 2 type: int\n" + + " [pc: 148, pc: 155] local: s index: 3 type: java.lang.String\n" + + " Local variable type table:\n" + + " [pc: 8, pc: 177] local: slist index: 1 type: java.util.ArrayList>\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=86487 +public void test029() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String args[]) {\n" + + " ArrayList arr = new ArrayList();\n" + + " arr.add(0);\n" + + " arr.add(1);\n" + + " int counter = 0;\n" + + " // tested statement:\n" + + " for (int i : arr){\n" + + " ++counter;\n" + + " }\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=86487 +public void test030() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String args[]) {\n" + + " int[] arr = new int[2];\n" + + " arr[0]= 0;\n" + + " arr[1]= 1;\n" + + " int counter = 0;\n" + + " // tested statement:\n" + + " for (int i : arr){\n" + + " ++counter;\n" + + " }\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=86487 +public void test031() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String args[]) {\n" + + " ArrayList arr = new ArrayList();\n" + + " arr.add(new Object());\n" + + " int counter = 0;\n" + + " // tested statement:\n" + + " for (Object o : arr){\n" + + " ++counter;\n" + + " }\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +public void test032() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " abstract class Member implements Iterable {\n" + + " }\n" + + " void foo(Member m) {\n" + + " for(String s : m) {\n" + + " return;\n" + + " } \n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108783 +public void test033() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " abstract class Member implements Iterable {\n" + + " }\n" + + " void foo(Member m) {\n" + + " for(String s : m) {\n" + + " return;\n" + + " } \n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108783 - variation +public void test034() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new Bar());\n" + + " }\n" + + " void foo(T t) {\n" + + " for (String s : t) {\n" + + " System.out.print(s);\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n" + + "class ArrayIterator implements Iterator {\n" + + " T[] values;\n" + + " int count;\n" + + " ArrayIterator(T[] values) {\n" + + " this.values = values;\n" + + " this.count = 0;\n" + + " }\n" + + " public boolean hasNext() {\n" + + " return this.count < this.values.length;\n" + + " }\n" + + " public T next() {\n" + + " if (this.count >= this.values.length) throw new NoSuchElementException();\n" + + " T value = this.values[this.count];\n" + + " this.values[this.count++] = null; // clear\n" + + " return value;\n" + + " }\n" + + " public void remove() {\n" + + " }\n" + + "}\n" + + "class Bar implements Iterable {\n" + + " public Iterator iterator() {\n" + + " return new ArrayIterator(new String[]{\"a\",\"b\"});\n" + + " }\n" + + "}\n", + }, + "ab"); + // ensure proper declaring class (Bar): 1 invokevirtual Bar.iterator() : java.util.Iterator [33] + String expectedOutput = + " // Method descriptor #25 (LBar;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void foo(Bar t);\n" + + " 0 aload_1 [t]\n" + + " 1 invokevirtual Bar.iterator() : java.util.Iterator [30]\n" + + " 4 astore_3\n" + + " 5 goto 25\n" + + " 8 aload_3\n" + + " 9 invokeinterface java.util.Iterator.next() : java.lang.Object [34] [nargs: 1]\n" + + " 14 checkcast java.lang.String [40]\n" + + " 17 astore_2 [s]\n" + + " 18 getstatic java.lang.System.out : java.io.PrintStream [42]\n" + + " 21 aload_2 [s]\n" + + " 22 invokevirtual java.io.PrintStream.print(java.lang.String) : void [48]\n" + + " 25 aload_3\n" + + " 26 invokeinterface java.util.Iterator.hasNext() : boolean [54] [nargs: 1]\n" + + " 31 ifne 8\n" + + " 34 getstatic java.lang.System.out : java.io.PrintStream [42]\n" + + " 37 invokevirtual java.io.PrintStream.println() : void [58]\n" + + " 40 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 18, line: 9]\n" + + " [pc: 25, line: 8]\n" + + " [pc: 34, line: 11]\n" + + " [pc: 40, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 41] local: this index: 0 type: X\n" + + " [pc: 0, pc: 41] local: t index: 1 type: Bar\n" + + " [pc: 18, pc: 25] local: s index: 2 type: java.lang.String\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 41] local: this index: 0 type: X\n" + + " [pc: 0, pc: 41] local: t index: 1 type: T\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108783 - variation +public void test035() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new Bar());\n" + + " }\n" + + " void foo(T t) {\n" + + " for (String s : t) {\n" + + " System.out.print(s);\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n" + + "class ArrayIterator implements Iterator {\n" + + " T[] values;\n" + + " int count;\n" + + " ArrayIterator(T[] values) {\n" + + " this.values = values;\n" + + " this.count = 0;\n" + + " }\n" + + " public boolean hasNext() {\n" + + " return this.count < this.values.length;\n" + + " }\n" + + " public T next() {\n" + + " if (this.count >= this.values.length) throw new NoSuchElementException();\n" + + " T value = this.values[this.count];\n" + + " this.values[this.count++] = null; // clear\n" + + " return value;\n" + + " }\n" + + " public void remove() {\n" + + " }\n" + + "}\n" + + "interface IFoo extends Iterable {\n" + + "}\n" + + "class Bar implements IFoo {\n" + + " public Iterator iterator() {\n" + + " return new ArrayIterator(new String[]{\"a\",\"b\"});\n" + + " }\n" + + "}\n", + }, + "ab"); + // ensure proper declaring class (IFoo): 1 invokeinterface IFoo.iterator() : java.util.Iterator [35] [nargs: 1] + String expectedOutput = + " // Method descriptor #25 (LIFoo;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void foo(IFoo t);\n" + + " 0 aload_1 [t]\n" + + " 1 invokeinterface IFoo.iterator() : java.util.Iterator [30] [nargs: 1]\n" + + " 6 astore_3\n" + + " 7 goto 27\n" + + " 10 aload_3\n" + + " 11 invokeinterface java.util.Iterator.next() : java.lang.Object [36] [nargs: 1]\n" + + " 16 checkcast java.lang.String [42]\n" + + " 19 astore_2 [s]\n" + + " 20 getstatic java.lang.System.out : java.io.PrintStream [44]\n" + + " 23 aload_2 [s]\n" + + " 24 invokevirtual java.io.PrintStream.print(java.lang.String) : void [50]\n" + + " 27 aload_3\n" + + " 28 invokeinterface java.util.Iterator.hasNext() : boolean [56] [nargs: 1]\n" + + " 33 ifne 10\n" + + " 36 getstatic java.lang.System.out : java.io.PrintStream [44]\n" + + " 39 invokevirtual java.io.PrintStream.println() : void [60]\n" + + " 42 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 20, line: 9]\n" + + " [pc: 27, line: 8]\n" + + " [pc: 36, line: 11]\n" + + " [pc: 42, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 43] local: this index: 0 type: X\n" + + " [pc: 0, pc: 43] local: t index: 1 type: IFoo\n" + + " [pc: 20, pc: 27] local: s index: 2 type: java.lang.String\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 43] local: this index: 0 type: X\n" + + " [pc: 0, pc: 43] local: t index: 1 type: T\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=108783 +public void test036() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "\n" + + "public class X implements Iterable, Runnable {\n" + + " public > void foo(T t) {\n" + + " for (String s : t)\n" + + " System.out.print(s);\n" + + " }\n" + + " public void run() { /* */ }\n" + + " private List list = Arrays.asList(new String[] { \"a\", \"b\" });\n" + + " public Iterator iterator() {\n" + + " return this.list.iterator();\n" + + " }\n" + + " public static void main(String... args) {\n" + + " X x = new X();\n" + + " x.foo(x);\n" + + " }\n" + + "}", + }, + "ab"); + String expectedOutput = + " // Method descriptor #37 (Ljava/lang/Runnable;)V\n" + + " // Signature: ;>(TT;)V\n" + + " // Stack: 2, Locals: 4\n" + + " public void foo(java.lang.Runnable t);\n" + + " 0 aload_1 [t]\n" + + " 1 checkcast java.lang.Iterable [5]\n" + + " 4 invokeinterface java.lang.Iterable.iterator() : java.util.Iterator [39] [nargs: 1]\n" + + " 9 astore_3\n" + + " 10 goto 30\n" + + " 13 aload_3\n" + + " 14 invokeinterface java.util.Iterator.next() : java.lang.Object [43] [nargs: 1]\n" + + " 19 checkcast java.lang.String [18]\n" + + " 22 astore_2 [s]\n" + + " 23 getstatic java.lang.System.out : java.io.PrintStream [49]\n" + + " 26 aload_2 [s]\n" + + " 27 invokevirtual java.io.PrintStream.print(java.lang.String) : void [55]\n" + + " 30 aload_3\n" + + " 31 invokeinterface java.util.Iterator.hasNext() : boolean [61] [nargs: 1]\n" + + " 36 ifne 13\n" + + " 39 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 23, line: 8]\n" + + " [pc: 30, line: 7]\n" + + " [pc: 39, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 40] local: this index: 0 type: X\n" + + " [pc: 0, pc: 40] local: t index: 1 type: java.lang.Runnable\n" + + " [pc: 23, pc: 30] local: s index: 2 type: java.lang.String\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 40] local: t index: 1 type: T\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108783 +public void test037() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public static > void foo(T t) {\n" + + " for (String s : t)\n" + + " System.out.print(s);\n" + + " }\n" + + " private static ArrayList list = new ArrayList();\n" + + " static {\n" + + " list.addAll(Arrays.asList(new String[] { \"a\", \"b\" }));\n" + + " }\n" + + " public static void main(String... args) {\n" + + " foo(list);\n" + + " }\n" + + "}", + }, + "ab"); + + String expectedOutput = + " // Method descriptor #41 (Ljava/util/ArrayList;)V\n" + + " // Signature: ;>(TT;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void foo(java.util.ArrayList t);\n" + + " 0 aload_0 [t]\n" + + " 1 invokevirtual java.util.ArrayList.iterator() : java.util.Iterator [43]\n" + + " 4 astore_2\n" + + " 5 goto 25\n" + + " 8 aload_2\n" + + " 9 invokeinterface java.util.Iterator.next() : java.lang.Object [47] [nargs: 1]\n" + + " 14 checkcast java.lang.String [19]\n" + + " 17 astore_1 [s]\n" + + " 18 getstatic java.lang.System.out : java.io.PrintStream [53]\n" + + " 21 aload_1 [s]\n" + + " 22 invokevirtual java.io.PrintStream.print(java.lang.String) : void [59]\n" + + " 25 aload_2\n" + + " 26 invokeinterface java.util.Iterator.hasNext() : boolean [65] [nargs: 1]\n" + + " 31 ifne 8\n" + + " 34 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 18, line: 9]\n" + + " [pc: 25, line: 8]\n" + + " [pc: 34, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 35] local: t index: 0 type: java.util.ArrayList\n" + + " [pc: 18, pc: 25] local: s index: 1 type: java.lang.String\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 35] local: t index: 0 type: T\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119175 +public void test038() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashSet;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.foo();\n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + " public void foo() {\n" + + " for(Object o : new HashSet()) {\n" + + " System.out.println(o);\n" + + " continue;\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 3\n" + + " public void foo();\n" + + " 0 new java.util.HashSet [37]\n" + + " 3 dup\n" + + " 4 invokespecial java.util.HashSet() [39]\n" + + " 7 invokevirtual java.util.HashSet.iterator() : java.util.Iterator [40]\n" + + " 10 astore_2\n" + + " 11 goto 28\n" + + " 14 aload_2\n" + + " 15 invokeinterface java.util.Iterator.next() : java.lang.Object [44] [nargs: 1]\n" + + " 20 astore_1 [o]\n" + + " 21 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 24 aload_1 [o]\n" + + " 25 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [50]\n" + + " 28 aload_2\n" + + " 29 invokeinterface java.util.Iterator.hasNext() : boolean [53] [nargs: 1]\n" + + " 34 ifne 14\n" + + " 37 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 21, line: 10]\n" + + " [pc: 28, line: 9]\n" + + " [pc: 37, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 38] local: this index: 0 type: X\n" + + " [pc: 21, pc: 28] local: o index: 1 type: java.lang.Object\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150074 +public void test039() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashSet;\n" + + "import java.util.Set;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " for (Object o : initForEach()) {\n" + + " }\n" + + " }\n" + + "\n" + + " static class MyIterator implements Iterator {\n" + + " Iterator iterator;\n" + + " \n" + + " MyIterator(Iterator it) {\n" + + " this.iterator = it;\n" + + " }\n" + + " public boolean hasNext() {\n" + + " System.out.println(\"hasNext\");\n" + + " return this.iterator.hasNext();\n" + + " } \n" + + " public T next() {\n" + + " System.out.println(\"next\");\n" + + " return this.iterator.next();\n" + + " }\n" + + " public void remove() {\n" + + " System.out.println(\"remove\");\n" + + " this.iterator.remove();\n" + + " }\n" + + " }\n" + + " \n" + + " static Set initForEach() {\n" + + " System.out.println(\"initForEach\");\n" + + " HashSet set = new HashSet() {\n" + + " private static final long serialVersionUID = 1L;\n" + + " public Iterator iterator() {\n" + + " System.out.println(\"iterator\");\n" + + " return new MyIterator(super.iterator());\n" + + " }\n" + + " };\n" + + " for (int i = 0; i < 3; i++) set.add(i);\n" + + " return set;\n" + + " }\n" + + "}", + }, + "initForEach\n" + + "iterator\n" + + "hasNext\n" + + "next\n" + + "hasNext\n" + + "next\n" + + "hasNext\n" + + "next\n" + + "hasNext"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 invokestatic X.initForEach() : java.util.Set [16]\n" + + " 3 invokeinterface java.util.Set.iterator() : java.util.Iterator [20] [nargs: 1]\n" + + " 8 astore_1\n" + + " 9 goto 19\n" + + " 12 aload_1\n" + + " 13 invokeinterface java.util.Iterator.next() : java.lang.Object [26] [nargs: 1]\n" + + " 18 pop\n" + + " 19 aload_1\n" + + " 20 invokeinterface java.util.Iterator.hasNext() : boolean [32] [nargs: 1]\n" + + " 25 ifne 12\n" + + " 28 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 28, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 29] local: args index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150074 +public void test040() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashSet;\n" + + "import java.util.Set;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " for (Object o : initForEach()) {\n" + + " }\n" + + " }\n" + + "\n" + + " static class MyIterator implements Iterator {\n" + + " Iterator iterator;\n" + + " \n" + + " MyIterator(Iterator it) {\n" + + " this.iterator = it;\n" + + " }\n" + + " public boolean hasNext() {\n" + + " System.out.println(\"hasNext\");\n" + + " return this.iterator.hasNext();\n" + + " } \n" + + " public T next() {\n" + + " System.out.println(\"next\");\n" + + " return this.iterator.next();\n" + + " }\n" + + " public void remove() {\n" + + " System.out.println(\"remove\");\n" + + " this.iterator.remove();\n" + + " }\n" + + " }\n" + + " \n" + + " static Set initForEach() {\n" + + " System.out.println(\"initForEach\");\n" + + " HashSet set = new HashSet() {\n" + + " private static final long serialVersionUID = 1L;\n" + + " public Iterator iterator() {\n" + + " System.out.println(\"iterator\");\n" + + " return new MyIterator(super.iterator());\n" + + " }\n" + + " };\n" + + " for (int i = 0; i < 3; i++) set.add(i);\n" + + " return set;\n" + + " }\n" + + "}", + }, + "initForEach\n" + + "iterator\n" + + "hasNext\n" + + "next\n" + + "hasNext\n" + + "next\n" + + "hasNext\n" + + "next\n" + + "hasNext", + null, + true, + null, + options, + null); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 invokestatic X.initForEach() : java.util.Set [16]\n" + + " 3 invokeinterface java.util.Set.iterator() : java.util.Iterator [20] [nargs: 1]\n" + + " 8 astore_2\n" + + " 9 goto 19\n" + + " 12 aload_2\n" + + " 13 invokeinterface java.util.Iterator.next() : java.lang.Object [26] [nargs: 1]\n" + + " 18 astore_1\n" + + " 19 aload_2\n" + + " 20 invokeinterface java.util.Iterator.hasNext() : boolean [32] [nargs: 1]\n" + + " 25 ifne 12\n" + + " 28 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 28, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 29] local: args index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150074 +public void test041() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (int i : initForEach()) {\n" + + " }\n" + + " }\n" + + " static int[] initForEach() {\n" + + " System.out.println(\"initForEach\");\n" + + " return new int[] {1, 2, 3, 4};\n" + + " }\n" + + "}", + }, + "initForEach"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 invokestatic X.initForEach() : int[] [16]\n" + + " 3 pop\n" + + " 4 return\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150074 +public void test042() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (int i : initForEach()) {\n" + + " }\n" + + " }\n" + + " static int[] initForEach() {\n" + + " System.out.println(\"initForEach\");\n" + + " return new int[] {1, 2, 3, 4};\n" + + " }\n" + + "}", + }, + "initForEach", + null, + true, + null, + options, + null); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 5\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 invokestatic X.initForEach() : int[] [16]\n" + + " 3 dup\n" + + " 4 astore 4\n" + + " 6 arraylength\n" + + " 7 istore_3\n" + + " 8 iconst_0\n" + + " 9 istore_2\n" + + " 10 goto 21\n" + + " 13 aload 4\n" + + " 15 iload_2\n" + + " 16 iaload\n" + + " 17 istore_1\n" + + " 18 iinc 2 1\n" + + " 21 iload_2\n" + + " 22 iload_3\n" + + " 23 if_icmplt 13\n" + + " 26 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 26, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 27] local: args index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150074 +public void test043() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " for (int i : initForEach()) {\n" + + " }\n" + + " }\n" + + " static int[] initForEach() {\n" + + " System.out.println(\"initForEach\");\n" + + " return new int[] {1, 2, 3, 4};\n" + + " }\n" + + "}", + }, + "initForEach"); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 0\n" + + " public static void foo();\n" + + " 0 invokestatic X.initForEach() : int[] [21]\n" + + " 3 pop\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 8]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150074 +public void test044() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " for (int i : initForEach()) {\n" + + " }\n" + + " }\n" + + " static int[] initForEach() {\n" + + " System.out.println(\"initForEach\");\n" + + " return new int[] {1, 2, 3, 4};\n" + + " }\n" + + "}", + }, + "initForEach", + null, + true, + null, + options, + null); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 4\n" + + " public static void foo();\n" + + " 0 invokestatic X.initForEach() : int[] [21]\n" + + " 3 dup\n" + + " 4 astore_3\n" + + " 5 arraylength\n" + + " 6 istore_2\n" + + " 7 iconst_0\n" + + " 8 istore_1\n" + + " 9 goto 19\n" + + " 12 aload_3\n" + + " 13 iload_1\n" + + " 14 iaload\n" + + " 15 istore_0\n" + + " 16 iinc 1 1\n" + + " 19 iload_1\n" + + " 20 iload_2\n" + + " 21 if_icmplt 12\n" + + " 24 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 24, line: 8]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150074 +public void test045() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (int i : initForEach()) {\n" + + " System.out.print(\'a\');\n" + + " }\n" + + " }\n" + + " static int[] initForEach() {\n" + + " return new int[] {1, 2, 3, 4};\n" + + " }\n" + + "}", + }, + "aaaa", + null, + true, + null, + options, + null); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 5\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 invokestatic X.initForEach() : int[] [16]\n" + + " 3 dup\n" + + " 4 astore 4\n" + + " 6 arraylength\n" + + " 7 istore_3\n" + + " 8 iconst_0\n" + + " 9 istore_2\n" + + " 10 goto 29\n" + + " 13 aload 4\n" + + " 15 iload_2\n" + + " 16 iaload\n" + + " 17 istore_1 [i]\n" + + " 18 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 21 bipush 97\n" + + " 23 invokevirtual java.io.PrintStream.print(char) : void [26]\n" + + " 26 iinc 2 1\n" + + " 29 iload_2\n" + + " 30 iload_3\n" + + " 31 if_icmplt 13\n" + + " 34 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 18, line: 4]\n" + + " [pc: 26, line: 3]\n" + + " [pc: 34, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 35] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 18, pc: 26] local: i index: 1 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150074 +public void test046() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (int i : initForEach()) {\n" + + " System.out.print(\'a\');\n" + + " }\n" + + " }\n" + + " static int[] initForEach() {\n" + + " return new int[] {1, 2, 3, 4};\n" + + " }\n" + + "}", + }, + "aaaa", + null, + true, + null, + options, + null); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 invokestatic X.initForEach() : int[] [16]\n" + + " 3 dup\n" + + " 4 astore_3\n" + + " 5 arraylength\n" + + " 6 istore_2\n" + + " 7 iconst_0\n" + + " 8 istore_1\n" + + " 9 goto 23\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [20]\n" + + " 15 bipush 97\n" + + " 17 invokevirtual java.io.PrintStream.print(char) : void [26]\n" + + " 20 iinc 1 1\n" + + " 23 iload_1\n" + + " 24 iload_2\n" + + " 25 if_icmplt 12\n" + + " 28 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 12, line: 4]\n" + + " [pc: 20, line: 3]\n" + + " [pc: 28, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 29] local: args index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=180471 +public void test047() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo3(int[] array) {\n" + + " for (int i : array) {\n" + + " System.out.println(i);\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + + String expectedOutput = + " // Method descriptor #15 ([I)V\n" + + " // Stack: 2, Locals: 4\n" + + " void foo3(int[] array);\n" + + " 0 aload_1 [array]\n" + + " 1 dup\n" + + " 2 astore_3\n" + + " 3 arraylength\n" + + " 4 ifeq 18\n" + + " 7 aload_3\n" + + " 8 iconst_0\n" + + " 9 iaload\n" + + " 10 istore_2 [i]\n" + + " 11 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 14 iload_2 [i]\n" + + " 15 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 18 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 11, line: 4]\n" + + " [pc: 18, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: this index: 0 type: X\n" + + " [pc: 0, pc: 19] local: array index: 1 type: int[]\n" + + " [pc: 11, pc: 18] local: i index: 2 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=180471 - variation +public void test048() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo3(java.util.List ls) {\n" + + " for (String s : ls) {\n" + + " System.out.println(s);\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + + String expectedOutput = + " // Method descriptor #15 (Ljava/util/List;)V\n" + + " // Signature: (Ljava/util/List;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void foo3(java.util.List ls);\n" + + " 0 aload_1 [ls]\n" + + " 1 invokeinterface java.util.List.iterator() : java.util.Iterator [18] [nargs: 1]\n" + + " 6 astore_3\n" + + " 7 aload_3\n" + + " 8 invokeinterface java.util.Iterator.hasNext() : boolean [24] [nargs: 1]\n" + + " 13 ifeq 33\n" + + " 16 aload_3\n" + + " 17 invokeinterface java.util.Iterator.next() : java.lang.Object [30] [nargs: 1]\n" + + " 22 checkcast java.lang.String [34]\n" + + " 25 astore_2 [s]\n" + + " 26 getstatic java.lang.System.out : java.io.PrintStream [36]\n" + + " 29 aload_2 [s]\n" + + " 30 invokevirtual java.io.PrintStream.println(java.lang.String) : void [42]\n" + + " 33 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 26, line: 4]\n" + + " [pc: 33, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 34] local: this index: 0 type: X\n" + + " [pc: 0, pc: 34] local: ls index: 1 type: java.util.List\n" + + " [pc: 26, pc: 33] local: s index: 2 type: java.lang.String\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 34] local: ls index: 1 type: java.util.List\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=180471 - variation +public void test049() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo3(java.util.List l) {\n" + + " for (Object o : l) {\n" + + " System.out.println(o);\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); + + String expectedOutput = + " // Method descriptor #15 (Ljava/util/List;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void foo3(java.util.List l);\n" + + " 0 aload_1 [l]\n" + + " 1 invokeinterface java.util.List.iterator() : java.util.Iterator [16] [nargs: 1]\n" + + " 6 astore_3\n" + + " 7 aload_3\n" + + " 8 invokeinterface java.util.Iterator.hasNext() : boolean [22] [nargs: 1]\n" + + " 13 ifeq 30\n" + + " 16 aload_3\n" + + " 17 invokeinterface java.util.Iterator.next() : java.lang.Object [28] [nargs: 1]\n" + + " 22 astore_2 [o]\n" + + " 23 getstatic java.lang.System.out : java.io.PrintStream [32]\n" + + " 26 aload_2 [o]\n" + + " 27 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [38]\n" + + " 30 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 23, line: 4]\n" + + " [pc: 30, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 31] local: this index: 0 type: X\n" + + " [pc: 0, pc: 31] local: l index: 1 type: java.util.List\n" + + " [pc: 23, pc: 30] local: o index: 2 type: java.lang.Object\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=291472 +public void test050() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private T values;\n" + + " public X(T values) {\n" + + " this.values = values;\n" + + " }\n" + + " public T getValues() {\n" + + " return values;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(new short[] { 1, 2, 3, 4, 5 });\n" + + " for (int i : x.getValues()) {\n" + + " System.out.print(i);\n" + + " }\n" + + " }\n" + + "}", + }, + "12345"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=291472 +public void test051() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private T values;\n" + + " public X(T values) {\n" + + " this.values = values;\n" + + " }\n" + + " public T getValues() {\n" + + " return values;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(new short[] { 1, 2, 3, 4, 5 });\n" + + " for (long l : x.getValues()) {\n" + + " System.out.print(l);\n" + + " }\n" + + " }\n" + + "}", + }, + "12345"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=291472 +public void test052() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private T values;\n" + + " public X(T values) {\n" + + " this.values = values;\n" + + " }\n" + + " public T getValues() {\n" + + " return values;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(new Short[] { 1, 2, 3, 4, 5 });\n" + + " for (int i : x.getValues()) {\n" + + " System.out.print(i);\n" + + " }\n" + + " }\n" + + "}", + }, + "12345"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=291472 +public void test053() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private T values;\n" + + " public X(T values) {\n" + + " this.values = values;\n" + + " }\n" + + " public T getValues() {\n" + + " return values;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(new Short[] { 1, 2, 3, 4, 5 });\n" + + " for (long i : x.getValues()) {\n" + + " System.out.print(i);\n" + + " }\n" + + " }\n" + + "}", + }, + "12345"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=321085 +public void test054() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashSet;\n" + + "import java.util.Set;\n" + + "public class X {\n" + + " void foo() {\n" + + " HashSet x = new HashSet();\n" + + " x.add(\"a\");\n" + + " HashSet y = new HashSet();\n" + + " y.add(1);\n" + + " Set [] OK= new Set[] { x, y };\n" + + " for (Set BUG : new Set[] { x, y }) {\n" + + " for (String str : BUG)\n" + + " System.out.println(str);\n" + + " }\n" + + " Set [] set = new Set[] { x, y };\n" + + " for (Set BUG : set) {\n" + + " for (String str : BUG)\n" + + " System.out.println(str);\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Set [] OK= new Set[] { x, y };\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Set[] needs unchecked conversion to conform to Set[]\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " for (Set BUG : new Set[] { x, y }) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Elements of type Set need unchecked conversion to conform to Set\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " Set [] set = new Set[] { x, y };\n" + + " ^^^\n" + + "Set is a raw type. References to generic type Set should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " for (Set BUG : set) {\n" + + " ^^^\n" + + "Type safety: Elements of type Set need unchecked conversion to conform to Set\n" + + "----------\n" + + "5. ERROR in X.java (at line 20)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/393719 +// like test054 but suppressing the warnings. +public void test055() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashSet;\n" + + "import java.util.Set;\n" + + "public class X {\n" + + " void foo() {\n" + + " HashSet x = new HashSet();\n" + + " x.add(\"a\");\n" + + " HashSet y = new HashSet();\n" + + " y.add(1);\n" + + " @SuppressWarnings(\"unchecked\") Set [] OK= new Set[] { x, y };\n" + + " for (@SuppressWarnings(\"unchecked\") Set BUG : new Set[] { x, y }) {\n" + + " for (String str : BUG)\n" + + " System.out.println(str);\n" + + " }\n" + + " @SuppressWarnings({\"rawtypes\", \"unchecked\"}) Set [] set = new Set[] { x, y };\n" + + " for (@SuppressWarnings(\"unchecked\") Set BUG : set) {\n" + + " for (String str : BUG)\n" + + " System.out.println(str);\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/393719 +// "unchecked" warning against the collection (raw Iterable) +public void test056() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void testRawType(@SuppressWarnings(\"rawtypes\") List lists) {\n" + + " List stringList = lists.get(0); // (1)\n" + + " for (List strings : lists) // (2)\n" + + " stringList = strings;\n" + + " for (@SuppressWarnings(\"unchecked\") List strings : lists) // no warning\n" + + " stringList = strings;\n" + + " System.out.println(stringList.get(0));\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List stringList = lists.get(0); // (1)\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " for (List strings : lists) // (2)\n" + + " ^^^^^\n" + + "Type safety: Elements of type List need unchecked conversion to conform to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401853 +// Eclipse Java compiler creates invalid bytecode (java.lang.VerifyError) +public void test057() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] argv) {\n" + + " for (long l : new ArrayList()) {}\n" + + " }\n" + + "}", + }, + "", + null, + true, + null, + options, + null); + + String expectedOutput = + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] argv);\n" + + " 0 new java.util.ArrayList [16]\n" + + " 3 dup\n" + + " 4 invokespecial java.util.ArrayList() [18]\n" + + " 7 invokevirtual java.util.ArrayList.iterator() : java.util.Iterator [19]\n" + + " 10 astore_1\n" + + " 11 goto 27\n" + + " 14 aload_1\n" + + " 15 invokeinterface java.util.Iterator.next() : java.lang.Object [23] [nargs: 1]\n" + + " 20 checkcast java.lang.Long [29]\n" + + " 23 invokevirtual java.lang.Long.longValue() : long [31]\n" + + " 26 pop2\n" + + " 27 aload_1\n" + + " 28 invokeinterface java.util.Iterator.hasNext() : boolean [35] [nargs: 1]\n" + + " 33 ifne 14\n" + + " 36 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 36, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 37] local: argv index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425632, [1.8][compiler] Compiler gets the scope of enhanced for loop's expression wrong. +public void test425632() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int[] i = {1, 2, 3};\n" + + " public static void main(String [] args) {\n" + + " for (int i : i) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "1\n2\n3"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=508215 +public void testBug508215() throws Exception { + this.runConformTest( + new String[] { + "linenumber/DebugErrorVarargs1Arg.java", + "package linenumber;\n" + + "import java.util.Arrays;\n" + + "\n" + + "public class DebugErrorVarargs1Arg {\n" + + " public static void main(String[] args) {\n" + + " for (Integer i : Arrays.asList(1)) {\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + "}\n" + + "", + } + ); + + String expectedOutput = + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 anewarray java.lang.Integer [16]\n" + + " 4 dup\n" + + " 5 iconst_0\n" + + " 6 iconst_1\n" + + " 7 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [18]\n" + + " 10 aastore\n" + + " 11 invokestatic java.util.Arrays.asList(java.lang.Object[]) : java.util.List [22]\n" + + " 14 invokeinterface java.util.List.iterator() : java.util.Iterator [28] [nargs: 1]\n" + + " 19 astore_2\n" + + " 20 goto 40\n" + + " 23 aload_2\n" + + " 24 invokeinterface java.util.Iterator.next() : java.lang.Object [34] [nargs: 1]\n" + + " 29 checkcast java.lang.Integer [16]\n" + + " 32 astore_1 [i]\n" + + " 33 getstatic java.lang.System.out : java.io.PrintStream [40]\n" + + " 36 aload_1 [i]\n" + + " 37 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [46]\n" + + " 40 aload_2\n" + + " 41 invokeinterface java.util.Iterator.hasNext() : boolean [52] [nargs: 1]\n" + + " 46 ifne 23\n" + + " 49 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 33, line: 7]\n" + + " [pc: 40, line: 6]\n" + + " [pc: 49, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 50] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 33, pc: 40] local: i index: 1 type: java.lang.Integer\n" + + ""; + + File f = new File(OUTPUT_DIR + File.separator + "linenumber" + File.separator + "DebugErrorVarargs1Arg.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public static Class testClass() { + return ForeachStatementTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeSignatureTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeSignatureTest.java new file mode 100644 index 0000000000..eccffc39ed --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeSignatureTest.java @@ -0,0 +1,1329 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import junit.framework.Test; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.IAttributeNamesConstants; +import org.eclipse.jdt.core.util.IClassFileAttribute; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.ICodeAttribute; +import org.eclipse.jdt.core.util.ILocalVariableTypeTableAttribute; +import org.eclipse.jdt.core.util.ILocalVariableTypeTableEntry; +import org.eclipse.jdt.core.util.IMethodInfo; +import org.eclipse.jdt.core.util.ISignatureAttribute; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.env.IBinaryField; +import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "rawtypes" }) +public class GenericTypeSignatureTest extends AbstractRegressionTest { + static class Logger extends Thread { + StringBuffer buffer; + InputStream inputStream; + String type; + Logger(InputStream inputStream, String type) { + this.inputStream = inputStream; + this.type = type; + this.buffer = new StringBuffer(); + } + + @Override + public void run() { + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(this.inputStream)); + String line = null; + while ((line = reader.readLine()) != null) { + this.buffer.append(this.type).append("->").append(line); + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + static final String RUN_SUN_JAVAC = System.getProperty("run.javac"); + static boolean RunJavac = CompilerOptions.ENABLED.equals(RUN_SUN_JAVAC); + // WORK unify runJavac methods (do we really need a different one here?) + + // 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[] { "test000" }; +// TESTS_NUMBERS = new int[] { 0 }; +// TESTS_RANGE = new int[] { 21, 50 }; +// } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); + } + + public static Class testClass() { + return GenericTypeSignatureTest.class; + } + + IPath dirPath = new Path(OUTPUT_DIR); // WORK check whether needed or not + + public GenericTypeSignatureTest(String name) { + super(name); + } + + /** + */ + protected void cleanUp() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + } + + protected String[] getFileNames(String[] testFiles) { + int length = testFiles.length; + int max = length / 2; + String[] fileNames = new String[max]; + for (int i=0; i < max; i++) { + fileNames[i] = testFiles[i*2]; + } + return fileNames; + } + /* + * Run Sun compilation using javac. + * Use JRE directory to retrieve javac bin directory and current classpath for + * compilation. + * Launch compilation in a thread and verify that it does not take more than 5s + * to perform it. Otherwise abort the process and log in console. + */ + // WORK unify with AbstractRegressionTest + protected void runJavac(final String testName, String[] testFiles) { + try { + // Write files in dir + writeFiles(testFiles); + + final String[] fileNames = getFileNames(testFiles); + Process process = null; + try { + // Compute classpath + String[] classpath = getDefaultClassPaths(); + StringBuilder cp = new StringBuilder(); + int length = classpath.length; + for (int i = 0; i < length; i++) { + if (classpath[i].indexOf(" ") != -1) { + cp.append("\"" + classpath[i] + "\""); + } else { + cp.append(classpath[i]); + } + if (i<(length-1)) cp.append(";"); + } + // Compute command line + IPath jdkDir = (new Path(Util.getJREDirectory())).removeLastSegments(1); + IPath javacPath; + // WORK improve platform management here + if ("Linux".equals(System.getProperty("os.name"))) { + javacPath = jdkDir.append("bin").append("javac"); + } else { + javacPath = jdkDir.append("bin").append("javac.exe"); + } + StringBuilder cmdLine = new StringBuilder(javacPath.toString()); + cmdLine.append(" -classpath "); + cmdLine.append(cp); + cmdLine.append(" -source 1.5 -deprecation -g -Xlint "); // enable recommended warnings + for (int i = 0, length2 = fileNames.length; i < length2; i++) { + cmdLine.append(fileNames[i] + " "); + } +// System.out.println(testName+": "+cmdLine.toString()); +// System.out.println(GenericTypeTest.this.dirPath.toFile().getAbsolutePath()); + String cmdLineAsString; + // WORK improve double-quotes management on Linux + if ("Linux".equals(System.getProperty("os.name"))) { + cmdLineAsString = cmdLine.toString().replaceAll("\"", ""); + } else { + cmdLineAsString = cmdLine.toString(); + } + // Launch process + process = Runtime.getRuntime().exec(cmdLineAsString, null, GenericTypeSignatureTest.this.dirPath.toFile()); + // Log errors + Logger errorLogger = new Logger(process.getErrorStream(), "ERROR"); + + // Log output + Logger outputLogger = new Logger(process.getInputStream(), "OUTPUT"); + + // start the threads to run outputs (standard/error) + errorLogger.start(); + outputLogger.start(); + + // Wait for end of process + if (process.waitFor() != 0) { + System.out.println(testName+": javac has found error(s)!"); + } + } catch (IOException ioe) { + System.out.println(testName+": Not possible to launch Sun javac compilation!"); + } catch (InterruptedException e1) { + if (process != null) process.destroy(); + System.out.println(testName+": Sun javac compilation was aborted!"); + } + } catch (Exception e) { + // fails silently... + e.printStackTrace(); + } + } + + public void test001() { + final String[] testsSource = new String[] { + "X.java", + "public class X extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " super(t);\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X> xs = new X>(new X(\"SUCCESS\"));\n" + + " System.out.print(xs.t.t);\n" + + " }\n" + + "}", + "p/A.java", + "package p;\n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p;\n" + + " }\n" + + "}" + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + assertEquals("Wrong signature", "Lp/A;", new String(classFileReader.getGenericSignature())); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + IClassFileAttribute classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + ISignatureAttribute signatureAttribute = (ISignatureAttribute) classFileAttribute; + char[] signature = signatureAttribute.getSignature(); + assertNotNull("no signature", signature); + assertEquals("Wrong signature", "Lp/A;", new String(signature)); + IMethodInfo[] methodInfos = classFileReader.getMethodInfos(); + int length = methodInfos.length; + assertEquals("Wrong size", 2, length); + IMethodInfo mainMethod = null; + for (int i = 0; i < length; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if ("main".equals(new String(methodInfo.getName()))) { + mainMethod = methodInfo; + break; + } + } + if (mainMethod == null) { + assertNotNull(mainMethod); + return; + } + ICodeAttribute codeAttribute = mainMethod.getCodeAttribute(); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(codeAttribute, IAttributeNamesConstants.LOCAL_VARIABLE_TYPE_TABLE); + assertNotNull(classFileAttribute); + ILocalVariableTypeTableAttribute localVariableTypeTableAttribute = (ILocalVariableTypeTableAttribute) classFileAttribute; + ILocalVariableTypeTableEntry[] entries = localVariableTypeTableAttribute.getLocalVariableTypeTable(); + ILocalVariableTypeTableEntry xsEntry = null; + for (int i = 0, max = entries.length; i < max; i++) { + ILocalVariableTypeTableEntry entry = entries[i]; + if ("xs".equals(new String(entry.getName()))) { + xsEntry = entry; + break; + } + } + if (xsEntry == null) { + assertNotNull(xsEntry); + return; + } + signature = xsEntry.getSignature(); + assertNotNull("no signature", signature); + assertEquals("Wrong signature", "LX;>;", new String(signature)); + + IMethodInfo constructorMethod = null; + for (int i = 0; i < length; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if ("".equals(new String(methodInfo.getName()))) { + constructorMethod = methodInfo; + break; + } + } + if (constructorMethod == null) { + assertNotNull(constructorMethod); + return; + } + codeAttribute = constructorMethod.getCodeAttribute(); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(codeAttribute, IAttributeNamesConstants.LOCAL_VARIABLE_TYPE_TABLE); + assertNotNull(classFileAttribute); + localVariableTypeTableAttribute = (ILocalVariableTypeTableAttribute) classFileAttribute; + entries = localVariableTypeTableAttribute.getLocalVariableTypeTable(); + ILocalVariableTypeTableEntry thisEntry = null; + for (int i = 0, max = entries.length; i < max; i++) { + ILocalVariableTypeTableEntry entry = entries[i]; + if ("this".equals(new String(entry.getName()))) { + thisEntry = entry; + break; + } + } + if (thisEntry == null) { + assertNotNull(thisEntry); + return; + } + signature = thisEntry.getSignature(); + assertNotNull("no signature", signature); + assertEquals("Wrong signature", "LX;", new String(signature)); + ILocalVariableTypeTableEntry tEntry = null; + for (int i = 0, max = entries.length; i < max; i++) { + ILocalVariableTypeTableEntry entry = entries[i]; + if ("t".equals(new String(entry.getName()))) { + tEntry = entry; + break; + } + } + if (tEntry == null) { + assertNotNull(tEntry); + return; + } + signature = tEntry.getSignature(); + assertNotNull("no signature", signature); + assertEquals("Wrong signature", "TT;", new String(signature)); + + if (!RunJavac) return; + + // Compare with javac + cleanUp(); + runJavac("test001", testsSource); + + classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + signatureAttribute = (ISignatureAttribute) classFileAttribute; + signature = signatureAttribute.getSignature(); + assertNotNull("no signature", signature); + assertEquals("Wrong signature", "Lp/A;", new String(signature)); + methodInfos = classFileReader.getMethodInfos(); + length = methodInfos.length; + assertEquals("Wrong size", 2, length); + mainMethod = null; + for (int i = 0; i < length; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if ("main".equals(new String(methodInfo.getName()))) { + mainMethod = methodInfo; + break; + } + } + if (mainMethod == null) { + assertNotNull(mainMethod); + return; + } + codeAttribute = mainMethod.getCodeAttribute(); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(codeAttribute, IAttributeNamesConstants.LOCAL_VARIABLE_TYPE_TABLE); + assertNotNull(classFileAttribute); + localVariableTypeTableAttribute = (ILocalVariableTypeTableAttribute) classFileAttribute; + entries = localVariableTypeTableAttribute.getLocalVariableTypeTable(); + xsEntry = null; + for (int i = 0, max = entries.length; i < max; i++) { + ILocalVariableTypeTableEntry entry = entries[i]; + if ("xs".equals(new String(entry.getName()))) { + xsEntry = entry; + break; + } + } + if (xsEntry == null) { + assertNotNull(xsEntry); + return; + } + signature = xsEntry.getSignature(); + assertNotNull("no signature", signature); + assertEquals("Wrong signature", "LX;>;", new String(signature)); + + constructorMethod = null; + for (int i = 0; i < length; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if ("".equals(new String(methodInfo.getName()))) { + constructorMethod = methodInfo; + break; + } + } + if (constructorMethod == null) { + assertNotNull(constructorMethod); + return; + } + codeAttribute = constructorMethod.getCodeAttribute(); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(codeAttribute, IAttributeNamesConstants.LOCAL_VARIABLE_TYPE_TABLE); + assertNotNull(classFileAttribute); + localVariableTypeTableAttribute = (ILocalVariableTypeTableAttribute) classFileAttribute; + entries = localVariableTypeTableAttribute.getLocalVariableTypeTable(); + thisEntry = null; + for (int i = 0, max = entries.length; i < max; i++) { + ILocalVariableTypeTableEntry entry = entries[i]; + if ("this".equals(new String(entry.getName()))) { + thisEntry = entry; + break; + } + } + if (thisEntry == null) { + assertNotNull(thisEntry); + return; + } + signature = thisEntry.getSignature(); + assertNotNull("no signature", signature); + assertEquals("Wrong signature", "LX;", new String(signature)); + tEntry = null; + for (int i = 0, max = entries.length; i < max; i++) { + ILocalVariableTypeTableEntry entry = entries[i]; + if ("t".equals(new String(entry.getName()))) { + tEntry = entry; + break; + } + } + if (tEntry == null) { + assertNotNull(tEntry); + return; + } + signature = tEntry.getSignature(); + assertNotNull("no signature", signature); + assertEquals("Wrong signature", "TT;", new String(signature)); + } + + public void test002() { + final String[] testsSource = new String[] { + "X.java", + "class X extends p.A {\n" + + " X() {\n" + + " super(null);\n" + + " }\n" + + "}", + "p/A.java", + "package p;\n" + + "public class A

{\n" + + " protected A(P p) {\n" + + " }\n" + + "}" + }; + this.runConformTest(testsSource); + + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + IClassFileAttribute classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + ISignatureAttribute signatureAttribute = (ISignatureAttribute) classFileAttribute; + assertEquals("Wrong signature", "Lp/A;", new String(signatureAttribute.getSignature())); + + classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "p/A.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + signatureAttribute = (ISignatureAttribute) classFileAttribute; + char[] signature = signatureAttribute.getSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "Ljava/lang/Object;", new String(signature)); + + IMethodInfo[] methodInfos = classFileReader.getMethodInfos(); + int length = methodInfos.length; + assertEquals("Wrong size", 1, length); + IMethodInfo constructorMethod = methodInfos[0]; + ICodeAttribute codeAttribute = constructorMethod.getCodeAttribute(); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(codeAttribute, IAttributeNamesConstants.LOCAL_VARIABLE_TYPE_TABLE); + assertNotNull(classFileAttribute); + ILocalVariableTypeTableAttribute localVariableTypeTableAttribute = (ILocalVariableTypeTableAttribute) classFileAttribute; + ILocalVariableTypeTableEntry[] entries = localVariableTypeTableAttribute.getLocalVariableTypeTable(); + ILocalVariableTypeTableEntry thisEntry = null; + for (int i = 0, max = entries.length; i < max; i++) { + ILocalVariableTypeTableEntry entry = entries[i]; + if ("this".equals(new String(entry.getName()))) { + thisEntry = entry; + break; + } + } + if (thisEntry == null) { + assertNotNull(thisEntry); + return; + } + assertEquals("Wrong signature", "Lp/A;", new String(thisEntry.getSignature())); + ILocalVariableTypeTableEntry tEntry = null; + for (int i = 0, max = entries.length; i < max; i++) { + ILocalVariableTypeTableEntry entry = entries[i]; + if ("p".equals(new String(entry.getName()))) { + tEntry = entry; + break; + } + } + if (tEntry == null) { + assertNotNull(tEntry); + return; + } + signature = tEntry.getSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "TP;", new String(signature)); + + if (!RunJavac) return; + + // Compare with javac + cleanUp(); + runJavac("test002", testsSource); + + classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + signatureAttribute = (ISignatureAttribute) classFileAttribute; + assertEquals("Wrong signature", "Lp/A;", new String(signatureAttribute.getSignature())); + + classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "p/A.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + signatureAttribute = (ISignatureAttribute) classFileAttribute; + signature = signatureAttribute.getSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "Ljava/lang/Object;", new String(signature)); + + methodInfos = classFileReader.getMethodInfos(); + length = methodInfos.length; + assertEquals("Wrong size", 1, length); + constructorMethod = methodInfos[0]; + codeAttribute = constructorMethod.getCodeAttribute(); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(codeAttribute, IAttributeNamesConstants.LOCAL_VARIABLE_TYPE_TABLE); + assertNotNull(classFileAttribute); + localVariableTypeTableAttribute = (ILocalVariableTypeTableAttribute) classFileAttribute; + entries = localVariableTypeTableAttribute.getLocalVariableTypeTable(); + thisEntry = null; + for (int i = 0, max = entries.length; i < max; i++) { + ILocalVariableTypeTableEntry entry = entries[i]; + if ("this".equals(new String(entry.getName()))) { + thisEntry = entry; + break; + } + } + if (thisEntry == null) { + assertNotNull(thisEntry); + return; + } + signature = thisEntry.getSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "Lp/A;", new String(signature)); + tEntry = null; + for (int i = 0, max = entries.length; i < max; i++) { + ILocalVariableTypeTableEntry entry = entries[i]; + if ("p".equals(new String(entry.getName()))) { + tEntry = entry; + break; + } + } + if (tEntry == null) { + assertNotNull(tEntry); + return; + } + signature = tEntry.getSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "TP;", new String(signature)); + } + + public void test003() { + final String[] testsSource = new String[] { + "X.java", + "public class X > extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " super(t);\n" + + " this.t = t;\n" + + " }\n" + + "}", + "p/A.java", + "package p;\n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p;\n" + + " }\n" + + "}", + "p/B.java", + "package p;\n" + + "public interface B {\n" + + "}" + }; + this.runConformTest(testsSource); + + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + IClassFileAttribute classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + ISignatureAttribute signatureAttribute = (ISignatureAttribute) classFileAttribute; + assertEquals("Wrong signature", ";>Lp/A;", new String(signatureAttribute.getSignature())); + + if (!RunJavac) return; + + // Compare with javac + cleanUp(); + runJavac("test003", testsSource); + + classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + signatureAttribute = (ISignatureAttribute) classFileAttribute; + assertEquals("Wrong signature", ";>Lp/A;", new String(signatureAttribute.getSignature())); + } + + public void test004() { + final String[] testsSource = new String[] { + "X.java", + "public class X extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " super(t);\n" + + " this.t = t;\n" + + " }\n" + + "}", + "p/A.java", + "package p;\n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p;\n" + + " }\n" + + "}", + "p/B.java", + "package p;\n" + + "public interface B {\n" + + "}" + }; + this.runConformTest(testsSource); + + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + IClassFileAttribute classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + ISignatureAttribute signatureAttribute = (ISignatureAttribute) classFileAttribute; + assertEquals("Wrong signature", "Lp/A;", new String(signatureAttribute.getSignature())); + + if (!RunJavac) return; + + // Compare with javac + cleanUp(); + runJavac("test004", testsSource); + + classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + signatureAttribute = (ISignatureAttribute) classFileAttribute; + assertEquals("Wrong signature", "Lp/A;", new String(signatureAttribute.getSignature())); + } + + public void test005() { + final String[] testsSource = new String[] { + "X.java", + "public class X extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " super(t);\n" + + " this.t = t;\n" + + " }\n" + + "}", + "p/A.java", + "package p;\n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p;\n" + + " }\n" + + "}", + "p/B.java", + "package p;\n" + + "public interface B {\n" + + "}", + "p/C.java", + "package p;\n" + + "public interface C {\n" + + "}" + }; + this.runConformTest(testsSource); + + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + IClassFileAttribute classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + ISignatureAttribute signatureAttribute = (ISignatureAttribute) classFileAttribute; + char[] signature = signatureAttribute.getSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "Lp/A;", new String(signature)); + + if (!RunJavac) return; + + // Compare with javac + cleanUp(); + runJavac("test005", testsSource); + + classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + assertNotNull(classFileReader); + classFileAttribute = org.eclipse.jdt.internal.core.util.Util.getAttribute(classFileReader, IAttributeNamesConstants.SIGNATURE); + assertNotNull(classFileAttribute); + signatureAttribute = (ISignatureAttribute) classFileAttribute; + signature = signatureAttribute.getSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "Lp/A;", new String(signature)); + } + + public void test006() { + final String[] testsSource = new String[] { + "X.java", + "public class X {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T foo(T t1) {\n" + + " return t1;\n" + + " }\n" + + " T field;\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + assertEquals("Wrong signature", "Ljava/lang/Object;", new String(classFileReader.getGenericSignature())); + + IBinaryField[] fields = classFileReader.getFields(); + assertNotNull("No fields", fields); + assertEquals("Wrong size", 2, fields.length); + assertEquals("Wrong name", "field", new String(fields[1].getName())); + char[] signature = fields[1].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "TT;", new String(signature)); + + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 3, methods.length); + assertEquals("Wrong name", "foo", new String(methods[1].getSelector())); + signature = methods[1].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "(TT;)TT;", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + + public void test007() { + final String[] testsSource = new String[] { + "X.java", + "public class X {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T foo(X x1) {\n" + + " return x1.t;\n" + + " }\n" + + " X field;\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + assertEquals("Wrong signature", "Ljava/lang/Object;", new String(classFileReader.getGenericSignature())); + + IBinaryField[] fields = classFileReader.getFields(); + assertNotNull("No fields", fields); + assertEquals("Wrong size", 2, fields.length); + assertEquals("Wrong name", "field", new String(fields[1].getName())); + char[] signature = fields[1].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "LX;", new String(signature)); + + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 3, methods.length); + assertEquals("Wrong name", "foo", new String(methods[1].getSelector())); + signature = methods[1].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "(LX;)TT;", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + + public void test008() { + final String[] testsSource = new String[] { + "X.java", + "public class X {\n" + + " T newInstance() throws IllegalAccessException {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 3, methods.length); + assertEquals("Wrong name", "newInstance", new String(methods[1].getSelector())); + char[] signature = methods[1].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "()TT;", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + + public void test009() { + final String[] testsSource = new String[] { + "X.java", + "public class X {\n" + + "class MX {\n" + + "}\n" + + " \n" + + "public static void main(String[] args) {\n" + + " new X().foo(new X().new MX());\n" + + "}\n" + + "void foo(X.MX mx) {\n" + + " System.out.println(\"SUCCESS\");\n" + + "}\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 3, methods.length); + assertEquals("Wrong name", "foo", new String(methods[2].getSelector())); + char[] signature = methods[2].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "(LX.MX;)V", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + + public void test010() { + final String[] testsSource = new String[] { + "X.java", + "public class X {\n" + + "class MX {\n" + + "}\n" + + " \n" + + "public static void main(String[] args) {\n" + + " new X().foo(new X().new MX());\n" + + "}\n" + + "void foo(X.MX mx) {\n" + + " System.out.println(\"SUCCESS\");\n" + + "}\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 3, methods.length); + assertEquals("Wrong name", "foo", new String(methods[2].getSelector())); + char[] signature = methods[2].getGenericSignature(); + assertNull("Unexpected generic signature", signature); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + + public void test011() { + final String[] testsSource = new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new X().new MX());\n" + + " }\n" + + " void foo(X.MX mx) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 3, methods.length); + assertEquals("Wrong name", "foo", new String(methods[2].getSelector())); + char[] signature = methods[2].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "(LX.MX<*>;)V", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + + // WORK check whether needed or not + /* + * Write given source test files in current output sub-directory. + * Use test name for this sub-directory name (ie. test001, test002, etc...) + */ + @Override + protected void writeFiles(String[] testFiles) { + // Compute and create specific dir + IPath dirFilePath = (IPath) this.dirPath.clone(); + File dir = dirFilePath.toFile(); + if (!dir.exists()) { + dir.mkdirs(); + } + + // For each given test files + for (int i=0, length=testFiles.length; i= 0) { + dirFilePath = filePath.removeLastSegments(1); + dir = dirFilePath.toFile(); + if (!dir.exists()) { + dir.mkdirs(); + } + } + Util.writeToFile(contents, filePath.toString()); + } + } + + public void test012() { + final String[] testsSource = new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new X().new MX());\n" + + " }\n" + + " void foo(X.MX mx) { // no signature\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 3, methods.length); + assertEquals("Wrong name", "foo", new String(methods[2].getSelector())); + assertNull("Wrong signature", methods[2].getGenericSignature()); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + + public void test013() { + final String[] testsSource = new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void foo(ArrayList arr) {\n" + + " for (U e : arr) {\n" + + " System.out.println(e);\n" + + " }\n" + + " }\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 3, methods.length); + assertEquals("Wrong name", "foo", new String(methods[2].getSelector())); + char[] signature = methods[2].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "(Ljava/util/ArrayList;)V", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + // 59983 - incorrect signature for List + public void test014() { + final String[] testsSource = new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " private List games = new ArrayList();\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryField[] fields = classFileReader.getFields(); + assertNotNull("No fields", fields); + assertEquals("Wrong size", 1, fields.length); + assertEquals("Wrong name", "games", new String(fields[0].getName())); + char[] signature = fields[0].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "Ljava/util/List;", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + // 65953 - incorrect signature for generic interface + public void test015() { + final String[] testsSource = new String[] { + "X.java", + "public interface X {\n" + + "}", + }; + this.runConformTest( + testsSource, + ""); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + char[] signature = classFileReader.getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "Ljava/lang/Object;", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + // 70975 - invalid signature for method with array of type variables + public void test016() { + final String[] testsSource = new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void foo(U[] arr) {\n" + + " }\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 3, methods.length); + assertEquals("Wrong name", "foo", new String(methods[2].getSelector())); + char[] signature = methods[2].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "([TU;)V", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + public void test017() { + final String[] testsSource = new String[] { + "X.java", + "public class X {\n" + + " static class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new MX());\n" + + " }\n" + + " void foo(X.MX mx) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }; + this.runConformTest( + testsSource, + "SUCCESS"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 3, methods.length); + assertEquals("Wrong name", "foo", new String(methods[2].getSelector())); + char[] signature = methods[2].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "(LX$MX<*>;)V", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=98322 + public void test018() { + final String[] testsSource = new String[] { + "X.java", + "public class X {\n" + + " public abstract static class Key {\n" + + " public abstract String getName();\n" + + " }\n" + + " public class Holder {}\n" + + " \n" + + " void baz(X.Holder h) {} // (LX.Holder;)V\n" + + " void bar(X.Holder h) {} // n/a\n" + + " void foo(X.Holder h) {} // (LX.Holder;)V\n" + + "}\n", + }; + this.runConformTest( + testsSource, + ""); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 4, methods.length); + + assertEquals("Wrong name", "baz", new String(methods[1].getSelector())); + char[] signature = methods[1].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "(LX.Holder;)V", new String(signature)); + + assertEquals("Wrong name", "bar", new String(methods[2].getSelector())); + signature = methods[2].getGenericSignature(); + assertNull("No signature", signature); + + assertEquals("Wrong name", "foo", new String(methods[3].getSelector())); + signature = methods[3].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "(LX.Holder;)V", new String(signature)); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=100293 + public void test019() { + final String[] testsSource = new String[] { + "X.java", + "public class X {\n" + + " public abstract static class Key {\n" + + " public abstract String getName();\n" + + " }\n" + + " public class Holder {}\n" + + " \n" + + " X.Holder foo() { return null; }\n" + + " \n" + + " static void bar() {\n" + + " Object o = new X().foo();\n" + + " class Local {\n" + + " X.Holder field;\n" + + " Local foo1() { return null; }\n" + + " Local foo2() { return null; }\n" + + " Local foo3() { return null; }\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runConformTest( + testsSource, + ""); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X$1Local.class"); + IBinaryField[] fields = classFileReader.getFields(); + assertNotNull("No fields", fields); + assertEquals("Wrong size", 1, fields.length); + + assertEquals("Wrong name", "field", new String(fields[0].getName())); + char[] signature = fields[0].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "LX.Holder;", new String(signature)); + + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 4, methods.length); + + assertEquals("Wrong name", "foo1", new String(methods[1].getSelector())); + signature = methods[1].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "()LX$1Local;", new String(signature)); + + assertEquals("Wrong name", "foo2", new String(methods[2].getSelector())); + signature = methods[2].getGenericSignature(); + assertNotNull("No signature", signature); + assertEquals("Wrong signature", "()LX$1Local;", new String(signature)); + + assertEquals("Wrong name", "foo3", new String(methods[3].getSelector())); + signature = methods[3].getGenericSignature(); + assertNull("No signature", signature); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 - variation + public void test020() { + final String[] testsSource = new String[] { + "X.java", + "public interface X {\n" + + " interface Entry {\n" + + " interface Internal extends Entry {\n" + + " Internal createEntry();\n" + + " }\n" + + " }\n" + + "}\n", + }; + this.runConformTest( + testsSource, + ""); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X$Entry$Internal.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 1, methods.length); + assertEquals("Wrong name", "createEntry", new String(methods[0].getSelector())); + char[] signature = methods[0].getGenericSignature(); + assertNull("Unexpected signature", signature); // no generic signature should have been produced + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + + public void testBug460491() { + final String[] testsSource = new String[] { + "C.java", + "public class C {\n" + + " static class F { }\n" + + " interface G { }\n" + + " class H { }\n" + + " void m1(F f) {}\n" + + " void m2(G g) {}\n" + + " void m3(H h) {}\n" + + "}\n" + }; + this.runConformTest( + testsSource, + ""); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "C.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 4, methods.length); // incl ctor + + IBinaryMethod m1 = methods[1]; + assertEquals("Wrong name", "m1", new String(m1.getSelector())); + char[] signature = m1.getGenericSignature(); + assertNull("Unexpected signature", signature); // no generic signature should have been produced + + + IBinaryMethod m2 = methods[2]; + assertEquals("Wrong name", "m2", new String(m2.getSelector())); + signature = m2.getGenericSignature(); + assertNull("Unexpected signature", signature); // no generic signature should have been produced + + IBinaryMethod m3 = methods[3]; + assertEquals("Wrong name", "m3", new String(m3.getSelector())); + signature = m3.getGenericSignature(); + assertEquals("Wrong signature", "(LC.H;)V", String.valueOf(signature)); // generic signature *should* have been produced + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java new file mode 100644 index 0000000000..5300470149 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java @@ -0,0 +1,53006 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * bug 383690 - [compiler] location of error re uninitialized final field should be aligned + * bug 388800 - [1.8] adjust tests to 1.8 JRE + * bug 388795 - [compiler] detection of name clash depends on order of super interfaces + * bug 388739 - [1.8][compiler] consider default methods when detecting whether a class needs to be declared abstract + * bug 395681 - [compiler] Improve simulation of javac6 behavior from bug 317719 after fixing bug 388795 + * bug 406928 - computation of inherited methods seems damaged (affecting @Overrides) + * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) + * Bug 424286 - [1.8] Update type inference to spec version 0.9.1 + * Bug 426676 - [1.8][compiler] Wrong generic method type inferred from lambda expression + * Bug 423505 - [1.8] Implement "18.5.4 More Specific Method Inference" + * Bug 434483 - [1.8][compiler][inference] Type inference not picked up with method reference + * Harry Terkelsen - Bug 460491 - NPE in ParameterizedTypeBinding.collectSubstitutes + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import static java.lang.Math.abs; +import static java.util.stream.Collectors.toList; + +import java.io.File; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; +import java.util.function.IntFunction; +import java.util.stream.IntStream; + +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; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class GenericTypeTest extends AbstractComparableTest { + + public GenericTypeTest(String name) { + super(name); + } + + // 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[] { "test0593" }; +// TESTS_NUMBERS = new int[] { 470, 627 }; +// TESTS_RANGE = new int[] { 1097, -1 }; + } + public static Test suite() { + return buildComparableTestSuite(testClass()); + } + + public static Class testClass() { + return GenericTypeTest.class; + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedTypeParameter, CompilerOptions.IGNORE); + return options; + } + + public void test0001() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends XS {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Integer w = new X().get(new Integer(12));\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class XS {\n" + + " Txs get(Txs t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + + public void test0002() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends XS {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Integer w = new X().get(new Integer(12));\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " Xp2 get(Xp2 t){\n" + + " System.out.print(\"{X::get}\");\n" + + " return super.get(t);\n" + + " }\n" + + "}\n" + + "\n" + + "class XS {\n" + + " XSp1 get(XSp1 t) {\n" + + " System.out.print(\"{XS::get}\");\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + "{X::get}{XS::get}SUCCESS"); + } + + // check cannot bind superclass to type variable + public void test0003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends X {\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X extends X {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends X {\n" + + " ^\n" + + "Cannot refer to the type parameter X as a supertype\n" + + "----------\n"); + } + + // check cannot bind superinterface to type variable + public void test0004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements X {\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X implements X {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X implements X {\n" + + " ^\n" + + "Cannot refer to the type parameter X as a supertype\n" + + "----------\n"); + } + + // check cannot bind type variable in static context + public void test0005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " T t;\n" + + " static {\n" + + " T s;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " T s;\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n"); + } + + // check static references to type variables + public void test0006() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " T ok1;\n" + + " static {\n" + + " T wrong1;\n" + + " }\n" + + " static void foo(T wrong2) {\n" + + " T wrong3;\n" + + " }\n" + + " class MX extends T {\n" + + " T ok2;\n" + + " }\n" + + " static class SMX extends T {\n" + + " T wrong4;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " T wrong1;\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " static void foo(T wrong2) {\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " T wrong3;\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " class MX extends T {\n" + + " ^\n" + + "Cannot refer to the type parameter T as a supertype\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " static class SMX extends T {\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " T wrong4;\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n"); + } + + // check static references to type variables + public void test0007() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " T ok1;\n" + + " static class SMX {\n" + + " T wrong4;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " T wrong4;\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n"); + } + + // check static references to type variables + public void test0008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " T ok;\n" + + " static T wrong;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " static T wrong;\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n"); + } + + // Object cannot be generic + public void test0009() { + this.runNegativeTest( + new String[] { + "Object.java", + "package java.lang;\n" + + "public class Object {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Object.java (at line 2)\n" + + " public class Object {\n" + + " ^\n" + + "The type java.lang.Object cannot be declared as a generic\n" + + "----------\n"); + } + + public void test0010() { + this.runNegativeTest( + new String[] { + "X.java", + "class Foo {} \n" + + "public class X> {\n" + + " public static void main(String[] args) {\n" + + " new X();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new X();\n" + + " ^^^\n" + + "Bound mismatch: The type Foo is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n"); + } + + public void test0011() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " public static void main(String[] args) {\n" + + " new X();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X();\n" + + " ^^^\n" + + "Foo cannot be resolved to a type\n" + + "----------\n"); + } + + public void test0012() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " String s = new X().foo(\"SUCCESS\");\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0013() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().baz(\"SUCCESS\");\n" + + " }\n" + + " void baz(final T t) {\n" + + " new Object() {\n" + + " void print() {\n" + + " System.out.println(foo(t));\n" + + " }\n" + + " }.print();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0014() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(T t) throws T {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().baz(new EX());\n" + + " }\n" + + " void baz(final T t) {\n" + + " new Object() {\n" + + " void print() {\n" + + " System.out.println(foo(t));\n" + + " }\n" + + " }.print();\n" + + " }\n" + + "}\n" + + "class EX extends Exception {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " System.out.println(foo(t));\n" + + " ^^^^^^\n" + + "Unhandled exception type T\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " class EX extends Exception {\n" + + " ^^\n" + + "The serializable class EX does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); + } + public void test0015() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo() throws T {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().baz(new EX());\n" + + " }\n" + + " void baz(final T t) {\n" + + " new Object() {\n" + + " void print() {\n" + + " try {\n" + + " System.out.println(foo());\n" + + " } catch (Exception t) {\n" + + " }\n" + + " }\n" + + " }.print();\n" + + " }\n" + + "}\n" + + "class EX extends Exception {\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0016() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(E e) throws E {\n" + + " throw e;\n" + + " }\n" + + " void bar(E e) {\n" + + " try {\n" + + " foo(e);\n" + + " } catch(Exception ex) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar(new Exception());\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0017() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo(E e) throws E {\n" + + " throw e;\n" + + " }\n" + + " void bar(E e) {\n" + + " try {\n" + + " foo(e);\n" + + " } catch(Exception ex) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar(new Exception());\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " new X().bar(new Exception());\n" + + " ^^^\n" + + "The method bar(IOException) in the type X is not applicable for the arguments (Exception)\n" + + "----------\n"); + } + public void test0018() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(T t) {\n" + + " System.out.println(t);\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X() {\n" + + " void run() {\n" + + " foo(new XY());\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" + + "class XY {\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0019() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private T foo(T t) {\n" + + " System.out.println(t);\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X() {\n" + + " void run() {\n" + + " foo(new XY());\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" + + "class XY {\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " foo(new XY());\n" + + " ^^^\n" + + "The method foo(T) in the type X is not applicable for the arguments (XY)\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " public String toString() {\n" + + " ^^^^^^^^^^\n" + + "The method toString() of type XY should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); + } + public void test0020() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Y y) {\n" + + " System.out.print(\"SUCC\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " }\n" + + " void bar() {\n" + + " new Y() {\n" + + " @Override\n" + + " public void pre() {\n" + + " foo(this);\n" + + " }\n" + + " }.print(\"ESS\");\n" + + " }\n" + + "}\n" + + "class Y

{\n" + + " public void print(P p) {\n" + + " pre();\n" + + " System.out.println(p);\n" + + " }\n" + + " public void pre() {\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " }.print(\"ESS\");\n" + + " ^^^^^\n" + + "The method print(T) in the type Y is not applicable for the arguments (String)\n" + + "----------\n"); + } + public void test0021() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(T t) {\n" + + " }\n" + + " void bar(String x) {\n" + + " foo(x);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new Object());\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " foo(x);\n" + + " ^^^\n" + + "The method foo(T) in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " new X().foo(new Object());\n" + + " ^^^\n" + + "The method foo(String) in the type X is not applicable for the arguments (Object)\n" + + "----------\n"); + } + + public void test0022() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(T t) {\n" + + " System.out.println(t);\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0023() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(final T t) {\n" + + " new Object() {\n" + + " void print() {\n" + + " System.out.println(t);\n" + + " }\n" + + " }.print();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0024() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(final T t) throws T {\n" + + " new Object() {\n" + + " void print() {\n" + + " System.out.println(t);\n" + + " }\n" + + " }.print();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new EX());\n" + + " }\n" + + "}\n" + + "class EX extends Exception {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " new X(new EX());\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type EX\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " class EX extends Exception {\n" + + " ^^\n" + + "The serializable class EX does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); + } + + public void test0025() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo() throws T {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new EX());\n" + + " }\n" + + " X(final T t) {\n" + + " new Object() {\n" + + " void print() {\n" + + " try {\n" + + " System.out.println(foo());\n" + + " } catch (Exception t) {\n" + + " }\n" + + " }\n" + + " }.print();\n" + + " }\n" + + "}\n" + + "class EX extends Exception {\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0026() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(E e) throws E {\n" + + " throw e;\n" + + " }\n" + + " X(E e) {\n" + + " try {\n" + + " foo(e);\n" + + " } catch(Exception ex) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new Exception());\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0027() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo(E e) throws E {\n" + + " throw e;\n" + + " }\n" + + " X(E e) {\n" + + " try {\n" + + " foo(e);\n" + + " } catch(Exception ex) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new Exception());\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " new X(new Exception());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(Exception) is undefined\n" + + "----------\n"); + } + + public void test0028() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String s = new X(\"SU\").t;\n" + + " System.out.print(s);\n" + + " s = new X(\"failed\").t = \"CC\";\n" + + " System.out.print(s);\n" + + " s = new X(\"\").t += \"ESS\";\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0029() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X() {\n" + + " }\n" + + " T foo(T a, T b) {\n" + + " T s;\n" + + " s = t = a;\n" + + " s = t += b;\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(\"SUC\", \"CESS\"));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " s = t += b;\n" + + " ^^^^^^\n" + + "The operator += is undefined for the argument type(s) T, T\n" + + "----------\n"); + } + + public void test0030() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X() {\n" + + " }\n" + + " T foo(T a) {\n" + + " T s;\n" + + " s = t = a;\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(\"SUCCESS\"));\n" + + " }\n" + + "}\n" , + }, + "SUCCESS"); + } + + public void test0031() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(\"INNER\") {\n" + + " void run() {\n" + + " \n" + + " new Object() {\n" + + " void run() {\n" + + " String s = t = \"SUC\";\n" + + " s = t+= \"CESS\";\n" + + " System.out.println(t);\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" , + }, + "SUCCESS"); + } + + public void test0032() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(\"INNER\") {\n" + + " void run() {\n" + + " String s = t = \"SUC\";\n" + + " s = t+= \"CESS\";\n" + + " System.out.println(t);\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" , + }, + "SUCCESS"); + } + + public void test0033() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(E e){}\n" + + " void foo(T t){}\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(E e){}\n" + + " ^^^^^^^^\n" + + "Erasure of method foo(E) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " void foo(T t){}\n" + + " ^^^^^^^^\n" + + "Erasure of method foo(T) is the same as another method in type X\n" + + "----------\n"); + } + + public void test0034() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(E e){}\n" + + " void foo(T t){}\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(E e){}\n" + + " ^^^^^^^^\n" + + "Erasure of method foo(E) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " void foo(T t){}\n" + + " ^^^^^^^^\n" + + "Erasure of method foo(T) is the same as another method in type X\n" + + "----------\n"); + } + + public void test0035() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(E e, Thread t){}\n" + + " void foo(Exception e, T t){}\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(E e, Thread t){}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(E, Thread) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " void foo(Exception e, T t){}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(Exception, T) is the same as another method in type X\n" + + "----------\n"); + } + + public void test0036() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(E e){}\n" + + " void foo(T t){}\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" , + }, + "SUCCESS"); + } + + public void test0037() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(E e){}\n" + + " void foo(T t){}\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" , + }, + "SUCCESS"); + } + + public void test0038() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(E e){}\n" + + " void foo(T t){}\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.foo(new XY());\n" + + " }\n" + + "}\n" + + "class XY extends Thread implements Cloneable {\n" + + "}\n" , + }, "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x.foo(new XY());\n" + + " ^^^\n" + + "The method foo(XY) is ambiguous for the type X\n" + + "----------\n"); + } + + public void test0039() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(L l1){}\n" + + " void foo(L l2){}\n" + + " void foo(L l){}\n" + + "}\n" + + "\n" + + "class L {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(L l1){}\n" + + " ^^^^^^^^^^^^\n" + + "Erasure of method foo(L) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " void foo(L l2){}\n" + + " ^^^^^^^^^^^^\n" + + "Erasure of method foo(L) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " void foo(L l){}\n" + + " ^^^^^^^^\n" + + "Erasure of method foo(L) is the same as another method in type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " void foo(L l){}\n" + + " ^\n" + + "L is a raw type. References to generic type L should be parameterized\n" + + "----------\n"); + } + + public void test0040() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0041() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + "}\n", + }, + "SUCCESS"); + } + + // ** + public void test0042() { + String[] test = new String[] { + "X.java", + "public class X {}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + test, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "Illegal forward reference to type parameter U\n" + + "----------\n"); + } else { + this.runConformTest(test, ""); + } + } + + public void test0043() { + this.runConformTest( + new String[] { + "X.java", + "public class X , U extends T> {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class L{}\n", + }, + "SUCCESS"); + } + + public void test0044() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends L {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class L {}\n", + }, + "SUCCESS"); + } + + public void test0045() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public Z var;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public Z var;\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public Z var;\n" + + " ^\n" + + "T cannot be resolved to a type\n" + + "----------\n"); + } + public void test0046() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public Object var;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public Object var;\n" + + " ^^^^^^\n" + + "The type Object is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public Object var;\n" + + " ^\n" + + "T cannot be resolved to a type\n" + + "----------\n"); + } + public void test0047() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new MX(\"INNER\") {\n" + + " void run() {\n" + + " \n" + + " new Object() {\n" + + " void run() {\n" + + " String s = t = \"SUC\";\n" + + " s = t+= \"CESS\";\n" + + " System.out.println(t);\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" + + "class MX {\n" + + " MX(U u){}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " String s = t = \"SUC\";\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from T to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " String s = t = \"SUC\";\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from String to T\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " s = t+= \"CESS\";\n" + + " ^^^^^^^^^^\n" + + "The operator += is undefined for the argument type(s) T, String\n" + + "----------\n"); + } + // Access to enclosing 't' of type 'T' (not substituted from X as private thus non inherited) + public void test0048() { + this.runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " private T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(this) {\n" + + " void run() {\n" + + " new Object() {\n" + + " void run() {\n" + + " X x = t;\n" + + " System.out.println(x);\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n", + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 10)\n" + + " new X(this) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " X x = t;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " X x = t;\n" + + " ^\n" + + "Type mismatch: cannot convert from T to X\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + public void test0049() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(this) {\n" + + " void run() {\n" + + " new Object() {\n" + + " void run() {\n" + + " X x = t;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0050() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class N {}" + + "}\n" + + "class Y {\n" + + " static class N {}" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "N cannot be resolved to a type\n" + + "----------\n"); + } + public void test0050a() { + this.runNegativeTest( + new String[] { + "X.java", + "class Super {class M {}}\n" + + "public class X extends Super {}\n" + + "class Y extends Super {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X extends Super {}\n" + + " ^\n" + + "M cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=98504 + public void test0050b() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class M extends Y implements I {}\n" + + "}\n" + + "class Y {\n" + + " static interface I { void foo(); }\n" + + "}\n" + + "interface I {}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=98504 - variation + public void test0050c() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test implements Base {\n" + + " static class InnerTest implements Inner {}\n" + + "}\n"+ + "interface Base {\n" + + " interface Inner {}\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=101387 + public void test0050d() { + this.runConformTest( + new String[] { + "X.java", + "public class X {}\n" + + "class Y extends X {\n" + + " static class M {}\n" + + " static class N extends M {}\n" + + "}\n" + }, + ""); + } + public void test0051() { + this.runConformTest( + new String[] { + "X.java", + "class Super {class M {}}\n" + + "public class X extends Super {\n" + + " class N {}\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0052() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends p.A {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + "p/A.java", + "package p; \n" + + "public class A

{\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0053() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(this) {\n" + + " void run() {\n" + + " new Object() {\n" + + " void run() {\n" + + " print(t);\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n", + "p/A.java", + "package p; \n" + + "public class A

{\n" + + " protected void print(P p) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0054() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(this) {\n" + + " void run() {\n" + + " new Object() {\n" + + " void run() {\n" + + " print(X.this.t);\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n", + "p/A.java", + "package p; \n" + + "public class A

{\n" + + " protected void print(P p) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " new X(this) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " print(X.this.t);\n" + + " ^^^^^\n" + + "The method print(X) in the type A is not applicable for the arguments (T)\n" + + "----------\n"); + } + + public void test0055() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " super(t);\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X xs = new X(\"SUCCESS\");\n" + + " System.out.println(xs.t);\n" + + " }\n" + + "}\n", + "p/A.java", + "package p; \n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p; \n" + + " } \n" + + " protected void print(P p) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0056() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " super(t);\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X xs = new X(\"SUCCESS\");\n" + + " System.out.println((X)xs.t);\n" + + " }\n" + + "}\n", + "p/A.java", + "package p; \n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p; \n" + + " } \n" + + " protected void print(P p) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " System.out.println((X)xs.t);\n" + + " ^^^^^^^\n" + + "Cannot cast from String to X\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\A.java (at line 7)\n" + + " protected void print(P p) {\n" + + " ^\n" + + "The parameter p is hiding a field from type A

\n" + + "----------\n"); + } + + public void test0057() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " super(t);\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X> xs = new X>(new X(\"SUCCESS\"));\n" + + " System.out.println(xs.t.t);\n" + + " }\n" + + "}\n", + "p/A.java", + "package p; \n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p; \n" + + " } \n" + + " protected void print(P p) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + // JSR14-v10[2.1,2.2]: Valid multiple parameter types + public void test0058() { + this.runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "// Valid Parameterized Type Declaration\n" + + "public class X {\n" + + "}\n" + + "// Valid Type Syntax\n" + + "class Y {\n" + + " X x;\n" + + "}\n" + } + ); + } + // JSR14-v10[2.1,2.2]: Invalid multiple parameter types: more declared than referenced + public void test0059() { + this.runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "// Valid Parameterized Type Declaration\n" + + "public class X {\n" + + "}\n" + + "// Invalid Valid Type Syntax (not enough parameters)\n" + + "class Y {\n" + + " X x;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^\n" + + "Incorrect number of arguments for type X; it cannot be parameterized with arguments \n" + + "----------\n" + ); + } + // JSR14-v10[2.1,2.2]: Invalid multiple parameter types: more referenced than declared + public void test0060() { + this.runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "// Valid Parameterized Type Declaration\n" + + "public class X {\n" + + "}\n" + + "// Invalid Valid Type Syntax (too many parameters)\n" + + "class Y {\n" + + " X x;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^\n" + + "Incorrect number of arguments for type X; it cannot be parameterized with arguments \n" + + "----------\n" + ); + } + // JSR14-v10[2.1,2.2]: Invalid multiple parameter types: primitive types + public void test0061() { + this.runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "// Valid Parameterized Type Declaration\n" + + "public class X {\n" + + "}\n" + + "// Invalid Valid Type Syntax (primitive cannot be parameters)\n" + + "class Y {\n" + + " X x;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^^^\n" + + "Syntax error, insert \"Dimensions\" to complete TypeArgument\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^^^^^\n" + + "Syntax error, insert \"Dimensions\" to complete TypeArgument\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^^^^\n" + + "Syntax error, insert \"Dimensions\" to complete TypeArgument\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^^^^^\n" + + "Syntax error, insert \"Dimensions\" to complete TypeArgument\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^^^^^^\n" + + "Syntax error, insert \"Dimensions\" to complete TypeArgument\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^^^^^^^\n" + + "Syntax error, insert \"Dimensions\" to complete TypeArgument\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 7)\n" + + " X x;\n" + + " ^^^^\n" + + "Syntax error, insert \"Dimensions\" to complete ReferenceType\n" + + "----------\n"); + } + // JSR14-v10[2.1,2.2]: Valid multiple parameter types: primitive type arrays + public void test0062() { + this.runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "// Valid Parameterized Type Declaration\n" + + "public class X {\n" + + "}\n" + + "// Valid Type Syntax\n" + + "class Y {\n" + + " X x;\n" + + "}\n" + }, + "" + ); + } + public void test0063() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends p.A {\n" + + " \n" + + " X(T t) {\n" + + " super(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(args);\n" + + " X xs = new X(args);\n" + + " }\n" + + "}\n", + "p/A.java", + "package p; \n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p; \n" + + " } \n" + + " protected void print(P p) {\n" + + " System.out.println(\"SUCCESS\"+p);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X x = new X(args);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X x = new X(args);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " X x = new X(args);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " X xs = new X(args);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(String[]) is undefined\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\A.java (at line 7)\n" + + " protected void print(P p) {\n" + + " ^\n" + + "The parameter p is hiding a field from type A

\n" + + "----------\n"); + } + // raw type: variable map to its strict erasure + public void test0064() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " void bar(T t) {\n" + + " t.getMessage();\n" + + " t.foo();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + // raw type + " x.t.getMessage();\n" + // T is strictly exception ! + " x.t.foo();\n" + + " }\n" + + "}\n" + + "\n" + + "interface IX {\n" + + " void foo();\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void bar(T t) {\n" + + " ^\n" + + "The parameter t is hiding a field from type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " x.t.foo();\n" + + " ^^^\n" + + "The method foo() is undefined for the type Exception\n" + + "----------\n"); + } + // raw type: assignments + public void test0065() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " X xioe = new X(); // ok\n" + + " \n" + + " X x2 = xioe;\n" + + " X xioe2 = x; // unsafe\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " X x2 = xioe;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " X xioe2 = x; // unsafe\n" + + " ^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + + "----------\n", + null, + true, + customOptions); + } + + // JSR14-v10[2.1,2.2]: Invalid PT declaration (mix with reference) + public void test0066() { + this.runNegativeTest( + new String[] { + "test/X1.java", + "package test;\n" + + "// Valid Consecutive Parameterized Type Declaration\n" + + "public class X1> {\n" + + " A1 a1;\n" + + "}\n" + + "// Valid Parameterized Type Declaration\n" + + "class X2{\n" + + " A2 a2;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1> {\n" + + " ^^\n" + + "A2 cannot be resolved to a type\n" + + "----------\n" + ); + } + + // JSR14-v10[2.1,2.2]: Invalid PT declaration (mix with reference) + public void test0067() { + this.runNegativeTest( + new String[] { + "test/X1.java", + "package test;\n" + + "// Valid Consecutive Parameterized Type Declaration\n" + + "public class X1< A1 extends X2 < A2 > > {\n" + + " A1 a1;\n" + + "}\n" + + "// Valid Parameterized Type Declaration\n" + + "class X2{\n" + + " A2 a2;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1< A1 extends X2 < A2 > > {\n" + + " ^^\n" + + "A2 cannot be resolved to a type\n" + + "----------\n" + ); + } + + // JSR14-V10[2.4]: Not terminated consecutive declaration + // TODO (david) diagnosis message on error 3 sounds strange, doesn't it? + public void _test0068() { + this.runNegativeTest( + new String[] { + "test/X1.java", + "package test;\n" + + "// Invalid Consecutive Parameterized Type Declaration\n" + + "public class X1 {\n" + + " A1 a1;\n" + + "}\n" + + "// Invalid Parameterized Type Declaration\n" + + "class X2 {\n" + + " ^^\n" + + "A2 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in test\\X1.java (at line 3)\n" + + " public class X1 {\n" + + " ^\n" + + "Syntax error, insert \">\" to complete ReferenceType1\n" + + "----------\n" + + "3. ERROR in test\\X1.java (at line 7)\n" + + " class X2 expected after this token\n" + + "----------\n" + ); + } + + // JSR14-V10[2.4]: Not terminated consecutive declaration + public void test0069() { + this.runNegativeTest( + new String[] { + "test/X1.java", + "package test;\n" + + "// Invalid Consecutive Parameterized Type Declaration\n" + + "public class X1 {\n" + + " A2 a2;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1>\" to complete ReferenceType2\n" + + "----------\n" + ); + } + + // JSR14-v10[2.4]: Unexpected consecutive PT declaration (right-shift symbol) + // TODO (david) surround expected token with (double-)quotes + public void test0070() { + this.runNegativeTest( + new String[] { + "test/X1.java", + "package test;\n" + + "// Invalid Consecutive Parameterized Type Declaration\n" + + "public class X1> {\n" + + " A1 a1;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1> {\n" + + " ^^\n" + + "Syntax error on token \">>\", > expected\n" + + "----------\n" + ); + } + + // JSR14-v10[2.1,2.2]: Unexpected consecutive PT declaration (with spaces) + public void test0071() { + this.runNegativeTest( + new String[] { + "test/X1.java", + "package test;\n" + + "// Invalid Consecutive Parameterized Type Declaration\n" + + "public class X1 < A1 > > {\n" + + " A1 a1;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1 < A1 > > {\n" + + " ^\n" + + "Syntax error on token \">\", delete this token\n" + + "----------\n" + ); + } + + // JSR14-v10[2.4]: Unexpected consecutive PT declaration (unary right-shift symbol) + // TODO (david) surround expected token with (double-)quotes + public void test0072() { + this.runNegativeTest( + new String[] { + "test/X1.java", + "package test;\n" + + "// Invalid Consecutive Parameterized Type Declaration\n" + + "public class X1>> {\n" + + " A1 a1;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1>> {\n" + + " ^^^\n" + + "Syntax error on token \">>>\", > expected\n" + + "----------\n" + ); + } + + // JSR14-v10[2.4]: Unexpected consecutive PT declaration (right-shift symbol) + // TODO (david) surround expected token with (double-)quotes + public void test0073() { + this.runNegativeTest( + new String[] { + "test/X1.java", + "package test;\n" + + "// Invalid Consecutive Parameterized Type Declaration\n" + + "public class X1>> {\n" + + " A1 a1;\n" + + "}\n" + + "// Valid Parameterized Type Declaration\n" + + "class X2 {\n" + + " A2 a2;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1>> {\n" + + " ^^^\n" + + "Syntax error on token \">>>\", >> expected\n" + + "----------\n" + ); + } + + // JSR14-v10[2.1,2.2]: Unexpected consecutive PT declaration (with spaces) + public void test0074() { + this.runNegativeTest( + new String[] { + "test/X1.java", + "package test;\n" + + "// Invalid Consecutive Parameterized Type Declaration\n" + + "public class X1 < A1 > > > {\n" + + " A1 a1;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X1.java (at line 3)\n" + + " public class X1 < A1 > > > {\n" + + " ^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + ); + } + + // A is not an interface + public void test0075() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X > extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " super(t);\n" + + " this.t = t;\n" + + " }\n" + + "}", + "p/A.java", + "package p;\n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X > extends p.A {\n" + + " ^^^\n" + + "The type A is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n" + ); + } + + // A is not an interface + public void test0076() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends p.A {\n" + + " protected T t;\n" + + " X(T t) {\n" + + " super(t);\n" + + " this.t = t;\n" + + " }\n" + + "}", + "p/A.java", + "package p;\n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X extends p.A {\n" + + " ^^^\n" + + "A is a raw type. References to generic type A

should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends p.A {\n" + + " ^^^\n" + + "The type A is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n" + ); + } + // unsafe type operation: only for constructors with signature change + public void test0077() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends p.A {\n" + + " X() {\n" + + " super(null);\n" + + " }\n"+ + " X(T t) {\n" + + " super(t);\n" + + " }\n" + + " X(X xt) {\n" + + " super(xt.t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " X x1 = new X(args);\n" + + " X x2 = new X(x);\n" + + " X xs = new X(args);\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " super(xt.t);\n" + + " ^\n" + + "t cannot be resolved or is not a field\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " X x1 = new X(args);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " X x1 = new X(args);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 13)\n" + + " X x1 = new X(args);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 14)\n" + + " X x2 = new X(x);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 14)\n" + + " X x2 = new X(x);\n" + + " ^^^^^^^^\n" + + "Type safety: The constructor X(X) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 14)\n" + + " X x2 = new X(x);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "10. ERROR in X.java (at line 15)\n" + + " X xs = new X(args);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(String[]) is undefined\n" + + "----------\n"); + } + public void test0078() { + this.runNegativeTest( + new String[] { + "X.java", + "import p.A;\n" + + "public class X {\n" + + " X(A a, A b) {\n" + + " }\n" + + " void foo(A a) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X((A)null, (A)null);\n" + + " A a = new A((A)null);\n" + + " x.foo(a);\n" + + " a.print(x);\n" + + " A as = new A(null);\n" + + " as.print(\"hello\");\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A

{\n" + + " protected P p;\n" + + " protected A(P p) {\n" + + " this.p = p;\n" + + " }\n" + + " protected void print(P p) {\n" + + " System.out.println(\"SUCCESS\"+p);\n" + + " }\n" + + " protected void print(A

a) {\n" + + " print(a.p);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " X x = new X((A)null, (A)null);\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type A needs unchecked conversion to conform to A\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " X x = new X((A)null, (A)null);\n" + + " ^\n" + + "A is a raw type. References to generic type A

should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " X x = new X((A)null, (A)null);\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type A needs unchecked conversion to conform to A\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " X x = new X((A)null, (A)null);\n" + + " ^\n" + + "A is a raw type. References to generic type A

should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " A a = new A((A)null);\n" + + " ^\n" + + "A is a raw type. References to generic type A

should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " A a = new A((A)null);\n" + + " ^^^^^^^^^^^^^^\n" + + "The constructor A(P) is not visible\n" + + "----------\n" + + "7. WARNING in X.java (at line 9)\n" + + " A a = new A((A)null);\n" + + " ^\n" + + "A is a raw type. References to generic type A

should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 9)\n" + + " A a = new A((A)null);\n" + + " ^\n" + + "A is a raw type. References to generic type A

should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 10)\n" + + " x.foo(a);\n" + + " ^\n" + + "Type safety: The expression of type A needs unchecked conversion to conform to A\n" + + "----------\n" + + "10. ERROR in X.java (at line 11)\n" + + " a.print(x);\n" + + " ^^^^^\n" + + "The method print(P) from the type A is not visible\n" + + "----------\n" + + "11. ERROR in X.java (at line 12)\n" + + " A as = new A(null);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor A(P) is not visible\n" + + "----------\n" + + "12. ERROR in X.java (at line 13)\n" + + " as.print(\"hello\");\n" + + " ^^^^^\n" + + "The method print(P) from the type A is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\A.java (at line 7)\n" + + " protected void print(P p) {\n" + + " ^\n" + + "The parameter p is hiding a field from type A

\n" + + "----------\n"); + } + + // JSR14-v10[2.4]: Valid consecutive Type Parameters Brackets + public void test0079() { + this.runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X>>> {\n" + + " A a;\n" + + " public static void main(String[] args) {\n" + + " X>>> x = new X>>>();\n" + + " x.a = new X1>>();\n" + + " x.a.a1 = new X2>();\n" + + " x.a.a1.a2 = new X3();\n" + + " x.a.a1.a2.a3 = \"SUCCESS\";\n" + + " System.out.println(x.a.a1.a2.a3);\n" + + " }\n" + + "}\n" + + "class X1>> {\n" + + " A a1;\n" + + "}\n" + + "class X2> {\n" + + " A a2;\n" + + "}\n" + + "class X3 {\n" + + " A a3;\n" + + "}\n" + }, + "SUCCESS" + ); + } + // TODO (david) remove errors: insert dimension to complete array type + public void _test0080() { + this.runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X>> {}\n" + + "class X1> {}\n" + + "class X2 {}\n" + + "class X3>> {}\n" + + " ^^^\n" + + "Syntax error, insert \">\" to complete ReferenceType1\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 3)\n" + + " class X1> {}\n" + + " ^^\n" + + "Syntax error, insert \">\" to complete ReferenceType1\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 4)\n" + + " class X2 {}\n" + + " ^\n" + + "Syntax error, insert \">\" to complete ReferenceType1\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 5)\n" + + " class X3 expected after this token\n" + + "----------\n" + ); + } + // TODO (david) remove errors: insert dimension to complete array type + public void test0081() { + this.runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X> {}\n" + + "class X1 {}\n" + + "class X2 {}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 2)\n" + + " public class X> {}\n" + + " ^^\n" + + "Syntax error, insert \">>\" to complete ReferenceType2\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 3)\n" + + " class X1 {}\n" + + " ^\n" + + "Syntax error, insert \">>\" to complete ReferenceType2\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 4)\n" + + " class X2>\" to complete ReferenceType2\n" + + "----------\n" + ); + } + // TODO (david) remove error: insert dimension to complete array type + public void test0082() { + this.runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {}\n" + + "class X1> {}\n" + + "class X3 {}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 2)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, insert \">>>\" to complete ReferenceType3\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 3)\n" + + " class X1>>\" to complete ReferenceType3\n" + + "----------\n" + ); + } + // TODO (david) remove error: insert dimension to complete array type + public void _test0083() { + this.runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X>> {}\n" + + "class X2> {}\n" + + "class X3 {}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 2)\n" + + " public class X>>\" to complete ReferenceType3\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 2)\n" + + " public class X\" to complete ReferenceType1\n" + + "----------\n"); + } + public void test0084() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(AX a, AX b) {\n" + + " }\n" + + " void foo(AX a) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X((AX)null, (AX)null);\n" + + " AX a = new AX((AX)null);\n" + + " AX a2 = new AX(null);\n" + + " x.foo(a);\n" + + " a.foo(a);\n" + + " a.bar(a);\n" + + " AX as = new AX(null);\n" + + " as.print(a);\n" + + " as.bar(a);\n" + + " }\n" + + "}\n" + + "class AX

{\n" + + " AX(AX

ax){}\n" + + " AX(P p){}\n" + + " void print(P p){}\n" + + " void foo(AX rawAx){}\n" + + " void bar(AX

ax){}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X x = new X((AX)null, (AX)null);\n" + + " ^^^^^^^^\n" + + "Type safety: The expression of type AX needs unchecked conversion to conform to AX\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X x = new X((AX)null, (AX)null);\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " X x = new X((AX)null, (AX)null);\n" + + " ^^^^^^^^\n" + + "Type safety: The expression of type AX needs unchecked conversion to conform to AX\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " X x = new X((AX)null, (AX)null);\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " AX a = new AX((AX)null);\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 8)\n" + + " AX a = new AX((AX)null);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor AX(AX) belongs to the raw type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 8)\n" + + " AX a = new AX((AX)null);\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 8)\n" + + " AX a = new AX((AX)null);\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 9)\n" + + " AX a2 = new AX(null);\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "10. WARNING in X.java (at line 9)\n" + + " AX a2 = new AX(null);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The constructor AX(AX) belongs to the raw type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 9)\n" + + " AX a2 = new AX(null);\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "12. WARNING in X.java (at line 10)\n" + + " x.foo(a);\n" + + " ^\n" + + "Type safety: The expression of type AX needs unchecked conversion to conform to AX\n" + + "----------\n" + + "13. WARNING in X.java (at line 12)\n" + + " a.bar(a);\n" + + " ^^^^^^^^\n" + + "Type safety: The method bar(AX) belongs to the raw type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "14. ERROR in X.java (at line 13)\n" + + " AX as = new AX(null);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor AX(AX) is ambiguous\n" + + "----------\n" + + "15. ERROR in X.java (at line 14)\n" + + " as.print(a);\n" + + " ^^^^^\n" + + "The method print(String) in the type AX is not applicable for the arguments (AX)\n" + + "----------\n" + + "16. WARNING in X.java (at line 15)\n" + + " as.bar(a);\n" + + " ^\n" + + "Type safety: The expression of type AX needs unchecked conversion to conform to AX\n" + + "----------\n" + + "17. WARNING in X.java (at line 22)\n" + + " void foo(AX rawAx){}\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n"); + } + + public void test0085() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " X x = (X)ax.p;\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " \n" + + " P p;\n" + + "}\n", + }, + "null"); + } + + public void test0086() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX ax2 = ax.p;\n" + + " ax.p = new AX();\n" + + " System.out.println(ax2);\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

p;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " AX ax = new AX();\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " AX ax = new AX();\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " AX ax2 = ax.p;\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " ax.p = new AX();\n" + + " ^\n" + + "Type safety: The field p from the raw type AX is assigned a value of type AX. References to generic type AX

should be parameterized\n" + + "----------\n", + null, + true, + customOptions); + } + + public void test0087() { + Map customOptions = getCompilerOptions(); + // check no unsafe type operation problem is issued + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX ax2 = ax.p;\n" + + " AX ax3 = new AX();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

p;\n" + + "}\n", + }, + "SUCCESS", + null, + true, + null, + customOptions, + null/*no custom requestor*/); + } + + public void test0088() { + Map customOptions = getCompilerOptions(); + // check no unsafe type operation problem is issued + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " AX ax = new AX();\n" + + " AX ax2 = ax.p;\n" + + " AX ax3 = new AX();\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

p;\n" + + "}\n", + }, + "", + null, + true, + null, + customOptions, + null/*no custom requestor*/); + } + + public void test0089() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T q;\n" + + " public static void main(String[] args) {\n" + + " X xss = new X();\n" + + " X> xxs = new X>();\n" + + " xxs.q = xss;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + public void test0090() { + Map customOptions = getCompilerOptions(); + // check no unsafe type operation problem is issued + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T q;\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X xss = new X();\n" + + " X> xxs = new X>();\n" + + " xxs.q = xss;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void foo(X[] xs) {\n" + + " xs[0] = new X();\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + true, + null, + customOptions, + null/*no custom requestor*/); + } + + public void test0091() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X[] xs) {\n" + + " }\n" + + "}\n", + }, + ""); + } + + public void test0092() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " void foo() {\n" + + " X xs = new X(\"\");\n" + + " X xs2 = (X) xs;\n" + + " \n" + + " ((X)xs).t = this;\n" + + " \n" + + " System.out.prinln((T) this.t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"SUCCESS\").foo();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " X xs2 = (X) xs;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to X\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " ((X)xs).t = this;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " ((X)xs).t = this;\n" + + " ^\n" + + "Type safety: The field t from the raw type X is assigned a value of type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " System.out.prinln((T) this.t);\n" + + " ^^^^^^\n" + + "The method prinln(T) is undefined for the type PrintStream\n" + + "----------\n"); + } + + // ** + public void test0093() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX ax2 = new AX();\n" + + " ax.p = ax2.p;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class AX

{\n" + + " AX

p;\n" + + "}\n", + }, + "SUCCESS"); + } + + // same as test001, but every type is now a SourceTypeBinding + public void test0094() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends XS {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " I w = new X().get(new I());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class S {}\n" + + "class I implements C {}\n" + + "interface C {}\n" + + "class XS {\n" + + " Txs get(Txs t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0095() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends XS {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " I w = new X().get(new I());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class S {}\n" + + "class I implements C {}\n" + + "interface C {}\n" + + "class XS {\n" + + " Txs get(Txs t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0096() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends X {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends X {}\n" + + " ^\n" + + "Cycle detected: the type X cannot extend/implement itself or one of its own member types\n" + + "----------\n"); + } + public void test0097() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends X {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends X {}\n" + + " ^\n" + + "Cycle detected: the type X cannot extend/implement itself or one of its own member types\n" + + "----------\n"); + } + public void test0098() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX ax2 = ax.p;\n" + + " ax.p = new AX();\n" + + " ax.q = new AX();\n" + + " ax.r = new AX();\n" + + " ax.s = new AX();\n" + + " System.out.println(ax2);\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

p;\n" + + " AX q;\n" + + " AX r;\n" + + " BX s;\n" + + "}\n" + + "\n" + + "class BX {\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " AX ax = new AX();\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " AX ax = new AX();\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " AX ax2 = ax.p;\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " ax.p = new AX();\n" + + " ^\n" + + "Type safety: The field p from the raw type AX is assigned a value of type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " ax.q = new AX();\n" + + " ^\n" + + "Type safety: The field q from the raw type AX is assigned a value of type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " ax.r = new AX();\n" + + " ^\n" + + "Type safety: The field r from the raw type AX is assigned a value of type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "7. ERROR in X.java (at line 9)\n" + + " ax.s = new AX();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AX to BX\n" + + "----------\n", + null, + true, + customOptions); + } + // wildcard bound cannot be base type + // TODO (david) only syntax error should be related to wilcard bound being a base type. Ripple effect is severe here. + public void test0099() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X > {\n" + + " public static void main(String[] args) {\n" + + " AX ax;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void foo(X x) {\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X > {\n" + + " ^^^\n" + + "Syntax error, insert \"Dimensions\" to complete ArrayType\n" + + "----------\n" +); + } + + // type parameterized with wildcard cannot appear in allocation + public void test0100() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(new AX());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " P foo() { return null; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X x = new X(new AX());\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X x = new X(new AX());\n" + + " ^\n" + + "Cannot instantiate the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " X x = new X(new AX());\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n"); + } + + // wilcard may not pass parameter bound check + public void test0101() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X>(new AX());\n" + + " x.t.foo(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " void foo(P p) { \n" + + " System.out.println(p);\n" + + " }\n" + + "}\n" + + "\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends AX is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^\n" + + "Bound mismatch: The type AX is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " x.t.foo(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(Object) belongs to the raw type AX. References to generic type AX

should be parameterized\n" + + "----------\n"); + } + // unbound wildcard implicitly bound by matching parameter bounds + public void test0102() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X>(new BX());\n" + + " x.t.foo(\"SUCC\");\n" + + " x.t.bar(\"ESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " void foo(P p) { \n" + + " System.out.print(p);\n" + + " }\n" + + "}\n" + + "\n" + + "class BX extends AX {\n" + + " void bar(Q q) { \n" + + " System.out.println(q);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " x.t.foo(\"SUCC\");\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(Object) belongs to the raw type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " x.t.bar(\"ESS\");\n" + + " ^^^\n" + + "The method bar(String) is undefined for the type capture#2-of ?\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 + public void test0103() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X>(new BX());\n" + + " x.t.foo(\"SUCC\");\n" + + " x.t.bar(\"ESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " void foo(P p) { \n" + + " System.out.print(p);\n" + + " }\n" + + "}\n" + + "\n" + + "class BX extends AX {\n" + + " void bar(Q q) { \n" + + " System.out.println(q);\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + String expectedOutput = + " // Method descriptor #25 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 new BX [26]\n" + + " 7 dup\n" + + " 8 invokespecial BX() [28]\n" + + " 11 invokespecial X(AX) [29]\n" + + " 14 astore_1 [x]\n" + + " 15 aload_1 [x]\n" + + " 16 getfield X.t : AX [16]\n" + + " 19 checkcast BX [26]\n" + + " 22 ldc [31]\n" + + " 24 invokevirtual BX.foo(java.lang.Object) : void [33]\n" + + " 27 aload_1 [x]\n" + + " 28 getfield X.t : AX [16]\n" + + " 31 checkcast BX [26]\n" + + " 34 ldc [37]\n" + + " 36 invokevirtual BX.bar(java.lang.Object) : void [39]\n" + + " 39 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 27, line: 9]\n" + + " [pc: 39, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 40] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 15, pc: 40] local: x index: 1 type: X\n" + + " Local variable type table:\n" + + " [pc: 15, pc: 40] local: x index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + + // wildcard bound check + public void test0104() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X>(new AX());\n" + + " x.t.foo(\"SUCC\");\n" + + " x.t.bar(\"ESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " void foo(P p) { \n" + + " System.out.print(p);\n" + + " }\n" + + "}\n" + + "\n" + + "class BX extends AX {\n" + + " void bar(Q q) { \n" + + " System.out.println(q);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^\n" + + "BX is a raw type. References to generic type BX should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X> to X\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " x.t.foo(\"SUCC\");\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(Object) belongs to the raw type AX. References to generic type AX

should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " x.t.bar(\"ESS\");\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method bar(Object) belongs to the raw type BX. References to generic type BX should be parameterized\n" + + "----------\n"); + } + public void test0105() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X>(new AX());\n" + + " x.t.foo(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " void foo(P p) { \n" + + " System.out.println(p);\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0106() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X> x = new X>(new BX());\n" + + " x.t.foo(\"SUCC\");\n" + + " x.t.bar(\"ESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " void foo(P p) { \n" + + " System.out.print(p);\n" + + " }\n" + + "}\n" + + "\n" + + "class BX extends AX {\n" + + " void bar(Q q) { \n" + + " System.out.println(q);\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // unsafe assignment thru binaries + public void test0107() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " \n" + + " Iterable is = new ArrayList();\n" + + " is.iterator();\n" + + " }\n" + + "}\n" + + "\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " Iterable is = new ArrayList();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type ArrayList needs unchecked conversion to conform to Iterable\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " Iterable is = new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n", + null, + true, + customOptions); + } + // class literal: Integer.class of type Class + public void test0108() { + // also ensure no unsafe type operation problem is issued (assignment to variable of type raw) + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Class k;\n" + + " public static void main(String args[]) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " Class c = this.getClass();\n" + + " this.k = this.getClass();\n" + + " this.k = Integer.class;\n" + + " try {\n" + + " Integer i = Integer.class.newInstance();\n" + + " } catch (Exception e) {\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + true, + null, + customOptions, + null/*no custom requestor*/); + } + // parameterized interface cannot be implemented simultaneously with distinct arguments + public void test0109() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements AX {}\n" + + "class Y extends X implements AX {}\n" + + "interface AX

{}\n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X implements AX {}\n" + + " ^\n" + + "The interface AX cannot be implemented more than once with different arguments: AX and AX\n" + + "----------\n"); + } + public void test0110() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements AX {}\n" + + "class Y extends X implements AX {}\n" + + "interface AX

{}\n" + + "\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X implements AX {}\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " class Y extends X implements AX {}\n" + + " ^\n" + + "The interface AX cannot be implemented more than once with different arguments: AX and AX\n" + + "----------\n"); + } + public void test0111() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements AX {}\n" + + "class Y extends X implements AX {}\n" + + "interface AX

{}\n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X implements AX {}\n" + + " ^\n" + + "The interface AX cannot be implemented more than once with different arguments: AX and AX\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " class Y extends X implements AX {}\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n"); + } + // test member types + public void test0112() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X .MX.MMX>>{\n" + + " void foo(X.MX.MMX mx) {}\n" + + " class MX {\n" + + " class MMX {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " void foo(X.MX.MMX mx) {}\n" + + " ^^^^^^\n" + + "Bound mismatch: The type Thread is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 2)\n" + + " void foo(X.MX.MMX mx) {}\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X .MX.MMX>>{\n" + + " class MX {\n" + + " class MMX {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type Runnable is not a valid substitute for the bounded parameter of the type X.MX\n" + + "----------\n" + + "4. WARNING in X.java (at line 2)\n" + + " class MX {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X .MX.MMX>>{\n" + + " class MX {\n" + + " class MMX {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type Iterable is not a valid substitute for the bounded parameter of the type X.MX.MMX\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\n" + + " class MMX {}\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n"); + } + public void test0113() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void foo() {\n" + + " new X().new MX();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0114() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new X().new MX());\n" + + " }\n" + + " void foo(X.MX mx) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0115() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new X().new MX());\n" + + " }\n" + + " void foo(X.MX mx) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0116() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new X().new MX());\n" + + " }\n" + + " void foo(X.MX mx) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // test member types + public void test0117() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X .MX.MMX>>{\n" + + " public static void main(String [] args) {\n" + + " \n" + + " new X.MX.MMX>>().new MX();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void foo(X.MX.MMX mx) {\n" + + " }\n" + + " \n" + + " class MX {\n" + + " class MMX {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X .MX.MMX>>{\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " new X.MX.MMX>>().new MX();\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " new X.MX.MMX>>().new MX();\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " void foo(X.MX.MMX mx) {\n" + + " ^^^^^^^^\n" + + "X.MX.MMX is a raw type. References to generic type X.MX.MMX should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " void foo(X.MX.MMX mx) {\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The type X.MX.MMX is not a valid substitute for the bounded parameter .MX.MMX>> of the type X\n" + + "----------\n" + + "7. WARNING in X.java (at line 7)\n" + + " void foo(X.MX.MMX mx) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 7)\n" + + " void foo(X.MX.MMX mx) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); + } + // test generic method with recursive parameter bound > + public void test0118() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.Collections.sort(new java.util.LinkedList());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // test generic method + public void test0118a() { + this.runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class A {}\n" + + "\n" + + "public class X {\n" + + " static , U> void foo() {}\n" + + " void bar(A a) {\n" + + " foo();\n" + + " }\n" + + "}" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); + } + // test binary member types ** + public void _test0119() { + this.runConformTest( + new String[] { + "X.java", + "public class X .MX.MMX>>{\n" + + " public static void main(String [] args) {\n" + + " \n" + + " new X.MX.MMX>>().new MX();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void foo(X.MX.MMX mx) {\n" + + " }\n" + + " void foo2(X.MX.MMX mx) {\n" + + " }\n" + + " void foo3(X.MX.MMX>> mx) {\n" + + " }\n" + + " \n" + + " class MX {\n" + + " class MMX {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS" + ); + + // TODO (philippe) bounds checks are done before binaryType X is finished creating its type variables + this.runConformTest( + new String[] { + "Y.java", + "public class Y extends X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, // do not flush output + null); + } + // test generic method + public void test0120() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " \n" + + " String s = new X().foo(\"SUCCESS\");\n" + + " }\n" + + " T foo (U u) {\n" + + " System.out.println(u);\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // test generic method + public void test0120a() { + this.runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " > U foo() {\n" + + " return null;\n" + + " }\n" + + " > V bar() {\n" + + " return foo();\n" + + " }\n" + + "}" + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBug6302954 /* javac test options */); + } + // substitute array types + public void test0121() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().foo(args);\n" + + " }\n" + + " \n" + + " void foo(T[] ts) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // generic method with most specific common supertype: U --> String + public void test0122() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().foo(args, new X>());\n" + + " }\n" + + " void foo(U[] us, X> xxu) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // invalid parameterized type + public void test0123() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T ts;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T ts;\n" + + " ^\n" + + "The type T is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + } + // generic method with indirect type inference: BX --> AX + public void test0124() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(AX aw) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().foo(new BX());\n" + + " }\n" + + "}\n" + + "\n" + + "class AX {\n" + + "}\n" + + "class BX extends AX {\n" + + "}\n", + }, + "SUCCESS"); + } + // generic method with indirect type inference: CX --> AX + public void test0125() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(AX aw) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().foo(new CX());\n" + + " }\n" + + "}\n" + + "\n" + + "class AX {\n" + + "}\n" + + "class BX extends AX {\n" + + "}\n" + + "class CX extends BX {\n" + + "}\n", + }, + "SUCCESS"); + } + // variation on test0125 with typo: CX extends B instead of BX. + public void test0126() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(AX aw) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().foo(new CX());\n" + + " }\n" + + "}\n" + + "\n" + + "class AX {\n" + + "}\n" + + "class BX extends AX {\n" + + "}\n" + + "class CX extends B {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().foo(new CX());\n" + + " ^^^\n" + + "The method foo(AX) in the type X is not applicable for the arguments (CX)\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " class CX extends B {\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // 57784: test generic method + public void test0127() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.Arrays.asList(new Object[] {\"1\"});\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // 58666: special treatment for Object#getClass declared of type: Class + // but implicitly converted to Class for free. + public void test0128() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " Class c1 = x.getClass();\n" + + " Class c2 = x.getClass();\n" + + " String s = \"hello\";\n" + + " Class c3 = s.getClass();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Class c1 = x.getClass();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Class c3 = s.getClass();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); + } + // variation on test0128 + public void test0129() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + "\n" + + " public static void main(String[] args) {\n" + + " XY xy = new XY();\n" + + " Class c1 = xy.getClass();\n" + + " Class c2 = xy.getClass();\n" + + " String s = \"hello\";\n" + + " Class c3 = s.getClass();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "class XY extends X {\n" + + " public Class getClass() {\n" + + " return super.getClass();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Class c1 = xy.getClass();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Class c3 = s.getClass();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " public Class getClass() {\n" + + " ^^^^^^^^^^\n" + + "Cannot override the final method from Object\n" + + "----------\n" + + "4. WARNING in X.java (at line 14)\n" + + " public Class getClass() {\n" + + " ^^^^^^^^^^\n" + + "The method getClass() of type XY should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); + } + // getClass on array type + public void test0130() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + "\n" + + " public static void main(String[] args) {\n" + + " X[] x = new X[0];\n" + + " Class c = x.getClass();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // 58979 + public void test0131() { + this.runNegativeTest( + new String[] { + "ArrayList.java", + " interface List {\n" + + " List foo();\n" + + "}\n" + + "\n" + + " class ArrayList implements List {\n" + + " public List foo() {\n" + + " List lt = this;\n" + + " lt.bar();\n" + + " return this;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in ArrayList.java (at line 8)\n" + + " lt.bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type List\n" + + "----------\n"); + } + public void test0132() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " .Z> foo() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " .Z> foo() {}\n" + + " ^\n" + + "The type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " .Z> foo() {}\n" + + " ^\n" + + "W cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " .Z> foo() {}\n" + + " ^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n"); + } + // bridge method + public void test0133() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new Y();\n" + + " System.out.println(x.foo());\n" + + " }\n" + + " T foo() {return null;}\n" + + " void foo(T t) {}\n" + + "}\n" + + "class Y extends X {\n" + + " String foo() {return \"SUCCESS\";}\n" + + " void foo(String s) {}\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0134() { + this.runConformTest( + new String[] { + "Z.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class Z { \n" + + " T t;\n" + + " public static void main(String[] args) {\n" + + " foo(new Z().set(new ArrayList()));\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " Z set(T t) {\n" + + " this.t = t;\n" + + " return this;\n" + + " }\n" + + " T get() { \n" + + " return this.t; \n" + + " }\n" + + " \n" + + " static void foo(Z za) {\n" + + " za.get().isEmpty();\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0135() { + this.runNegativeTest( + new String[] { + "Z.java", + "public class Z { \n" + + " public static void main(String[] args) {\n" + + " foo(new Z());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " static void foo(Z zs) {\n" + + " }\n" + + "}\n" + + "\n" + + "class ZA {\n" + + " void foo() {}\n" + + "}\n" + + "\n" + + "class ZB extends ZA {\n" + + "}" + }, + "----------\n" + + "1. ERROR in Z.java (at line 3)\n" + + " foo(new Z());\n" + + " ^^^\n" + + "The method foo(Z) in the type Z is not applicable for the arguments (Z)\n" + + "----------\n" + + "2. ERROR in Z.java (at line 6)\n" + + " static void foo(Z zs) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super String is not a valid substitute for the bounded parameter of the type Z\n" + + "----------\n"); + } + public void test0136() { + this.runNegativeTest( + new String[] { + "Z.java", + "public class Z { \n" + + " public static void main(String[] args) {\n" + + " foo(new Z());\n" + + " }\n" + + " static void foo(Z zs) {\n" + + " zs.foo();\n" + + " }\n" + + "}\n" + + "class ZA {\n" + + "}\n" + + "class ZB extends ZA {\n" + + " void foo() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in Z.java (at line 3)\n" + + " foo(new Z());\n" + + " ^^^\n" + + "The method foo(Z) in the type Z is not applicable for the arguments (Z)\n" + + "----------\n" + + "2. ERROR in Z.java (at line 5)\n" + + " static void foo(Z zs) {\n" + + " ^^^^^^^^^^\n" + + "Bound mismatch: The type ? super ZA is not a valid substitute for the bounded parameter of the type Z\n" + + "----------\n" + + "3. ERROR in Z.java (at line 6)\n" + + " zs.foo();\n" + + " ^^^\n" + + "The method foo(Z) in the type Z is not applicable for the arguments ()\n" + + "----------\n"); + } + public void test0137() { + this.runConformTest( + new String[] { + "Z.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class Z { \n" + + " T t;\n" + + " public static void main(String[] args) {\n" + + " foo(new Z().set(new ArrayList()));\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " Z set(T t) {\n" + + " this.t = t;\n" + + " return this;\n" + + " }\n" + + " T get() { \n" + + " return this.t; \n" + + " }\n" + + " \n" + + " static void foo(Z za) {\n" + + " za.get().isEmpty();\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // unbound wildcard still remembers its variable bound: Z behaves like Z + public void test0138() { + this.runConformTest( + new String[] { + "Z.java", + "public class Z {\n" + + " T t;\n" + + " Z(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Z> zax = new Z>(new AX());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " void baz(Z zu){\n" + + " zu.t.foo(null);\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " void foo(P p) { \n" + + " System.out.print(p);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // extending wildcard considers its bound prior to its corresponding variable + public void test0139() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T get() {\n" + + " return this.t;\n" + + " }\n" + + " void bar(X x) {\n" + + " x.get().afoo();\n" + + " x.get().bfoo();\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " void afoo() {}\n" + + "}\n" + + "class BX {\n" + + " void bfoo() {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " void bar(X x) {\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends BX is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " x.get().afoo();\n" + + " ^^^^\n" + + "The method afoo() is undefined for the type capture#1-of ? extends BX\n" + + "----------\n"); + } + // extending wildcard considers its bound prior to its corresponding variable + public void test0140() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T get() {\n" + + " return this.t;\n" + + " }\n" + + " void bar(X x) {\n" + + " x.get().afoo();\n" + + " x.get().bfoo();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " void afoo() {}\n" + + "}\n" + + "class BX extends AX {\n" + + " void bfoo() {}\n" + + "}\n", + }, + "SUCCESS"); + } + // super wildcard considers its variable for lookups + public void test0141() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T get() {\n" + + " return this.t;\n" + + " }\n" + + " void bar(X x) {\n" + + " x.get().afoo();\n" + + " x.get().bfoo();\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " void afoo() {}\n" + + "}\n" + + "class BX extends AX {\n" + + " void bfoo() {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " x.get().bfoo();\n" + + " ^^^^\n" + + "The method bfoo() is undefined for the type capture#2-of ? super BX\n" + + "----------\n"); + } + public void test0142() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T get() {\n" + + " return this.t;\n" + + " }\n" + + " void bar(X x) {\n" + + " x = identity(x);\n" + + " }\n" + + "

X

identity(X

x) {\n" + + " return x;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " void afoo() {}\n" + + "}\n" + + "class BX extends AX {\n" + + " void bfoo() {}\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " void bar(X x) {\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends X is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " void bar(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " x = identity(x);\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The generic method identity(X

) of type X is not applicable for the arguments (X). The inferred type capture#2-of ? extends X is not a valid substitute for the bounded parameter

\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " void bar(X x) {\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends X is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " void bar(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " x = identity(x);\n" + + " ^^^^^^^^\n" + + "The method identity(X

) in the type X is not applicable for the arguments (X)\n" + + "----------\n"); + } + public void test0143() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class xx = null;\n" + + " Class xo = xx;\n" + + " Class xo2 = xx;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Class xo2 = xx;\n" + + " ^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); + } + public void test0144() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class xx = null;\n" + + " Class xo = xx;\n" + + " X x = get(xx);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " static

P get(Class

cp) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // 59641: check assign/invoke with wildcards + public void test0145() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " XList lx = new XList();\n" + + " X x = lx.get();\n" + + " lx.add(null);\n" + + " lx.add(x);\n" + + " lx.slot = x;\n" + + " lx.addAll(lx);\n" + + " } \n" + + "}\n" + + "class XList {\n" + + " E slot;\n" + + " void add(E e) {}\n" + + " E get() { return null; \n" + + " }\n" + + " void addAll(XList le) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lx.add(x);\n" + + " ^^^\n" + + "The method add(capture#3-of ?) in the type XList is not applicable for the arguments (X)\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " lx.slot = x;\n" + + " ^\n" + + "Type mismatch: cannot convert from X to capture#4-of ?\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " lx.addAll(lx);\n" + + " ^^^^^^\n" + + "The method addAll(XList) in the type XList is not applicable for the arguments (XList)\n" + + "----------\n"); + } + // 59628 + public void test0146() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.AbstractList;\n" + + "public class X extends AbstractList {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public int size() { return 0; }\n" + + " public Object get(int index) { return null; }\n" + + "}\n" + }, + "SUCCESS"); + } + // 59723 + public void test0147() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " char[][] tokens = new char[0][];\n" + + " ArrayList list = new ArrayList();\n" + + " list.toArray(tokens);\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + "}\n" + }, + "SUCCESS"); + } + // bridge method + public void test0148() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends AX{\n" + + " \n" + + " String foo(String s) {\n" + + " System.out.println(s);\n" + + " return s;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " T foo(T t) {\n" + + " return null;\n" + + " }\n" + + " void bar(T t) {\n" + + " foo(t);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // method compatibility + public void test0149() { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X implements java.util.Collection {\n" + + " public Object[] toArray(Object[] a) {\n" + + " return a;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X implements java.util.Collection {\n" + + " public Object[] toArray(Object[] a) {\n" + + " return a;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public Object[] toArray(Object[] a) {\n" + + " ^^^^^^^^\n" + + "Type safety: The return type Object[] for toArray(Object[]) from the type X needs unchecked conversion to conform to T[] from the type Collection\n" + + "----------\n"); + } + public void test0150() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " \n" + + " void foo(T[] ta, List lt) {\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().foo(args, new ArrayList());\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().foo(args, new ArrayList());\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(T[], List) of type X is not applicable for the arguments (String[], ArrayList). The inferred type String is not a valid substitute for the bounded parameter \n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().foo(args, new ArrayList());\n" + + " ^^^\n" + + "The method foo(T[], List) in the type X is not applicable for the arguments (String[], ArrayList)\n" + + "----------\n"); + } + public void test0151() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " \n" + + " X(T[] ta, List lt) {\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X(args, new ArrayList());\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " X(T[] ta, List lt) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " new X(args, new ArrayList());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic constructor X(T[], List) of type X is not applicable for the arguments (String[], ArrayList). The inferred type String is not a valid substitute for the bounded parameter \n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " X(T[] ta, List lt) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " new X(args, new ArrayList());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(String[], ArrayList) is undefined\n" + + "----------\n"); + } + // 60556 + public void test0152() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " List x(List list) {\n" + + " return Collections.unmodifiableList(list);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0153() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX a = bar(ax);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0154() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX a = bar(ax);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0155() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX a = bar(ax);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0156() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX a = bar(ax);\n" + + " }\n" + + " public static AX bar(AX a) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public static AX bar(AX a) {\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter of the type AX\n" + + "----------\n"); + } + public void test0157() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX as = new AX();\n" + + " AX a = bar(ax, as);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a, AX b) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " AX a = bar(ax, as);\n" + + " ^^^\n" + + "The method bar(AX, AX) in the type X is not applicable for the arguments (AX, AX)\n" + + "----------\n"); + } + public void test0158() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX as = new AX();\n" + + " AX a = bar(ax, as);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a, AX b) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0159() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX(new X());\n" + + " AX as = new AX(\"SUCCESS\");\n" + + " AX a = bar(ax, as);\n" + + " }\n" + + " public static T bar(AX a, AX b) {\n" + + " return a.get();\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? to T\n" + + "----------\n"); + } + public void test0160() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " String s = foo(new AX(\"aaa\"));\n" + + " }\n" + + " static V foo(AX a) {\n" + + " return a.get();\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to V\n" + + "----------\n"); + } + public void test0161() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " boolean b = foo(new AX(\"aaa\")).equals(args);\n" + + " }\n" + + " static V foo(AX a) {\n" + + " return a.get();\n" + + " }\n" + + " String bar() {\n" + + " return \"bbb\";\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to V\n" + + "----------\n"); + } + public void test0162() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " String s = foo(new AX(\"aaa\")).bar();\n" + + " }\n" + + " static V foo(AX a) {\n" + + " return a.get();\n" + + " }\n" + + " String bar() {\n" + + " return \"bbb\";\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " String s = foo(new AX(\"aaa\")).bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type Object\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to V\n" + + "----------\n"); + } + public void test0163() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " String s = foo(new AX(\"aaa\")).bar();\n" + + " }\n" + + " static V foo(AX a) {\n" + + " return a.get();\n" + + " }\n" + + " String bar() {\n" + + " return \"bbb\";\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " String s = foo(new AX(\"aaa\")).bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type Object\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to V\n" + + "----------\n"); + } + public void test0164() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo(new AX(\"SUCCESS\"));\n" + + " }\n" + + " static List foo(AX a) {\n" + + " System.out.println(a.get());\n" + + " List v = null;\n" + + " if (a == null) v = foo(a); \n" + + " return v;\n" + + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0165() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX();\n" + + " AX a = bar(ax);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static AX bar(AX a) {\n" + + " if (a == null) {\n" + + " AX as = bar(a);\n" + + " String s = as.get();\n" + + " }\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E get() { return null; }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0166() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX(new X());\n" + + " AX a = bar(ax, true);\n" + + " String s = a.get();\n" + + " System.out.println(s);\n" + + " }\n" + + " public static AX bar(AX a, boolean recurse) {\n" + + " if (recurse) {\n" + + " AX as = bar(a, false);\n" + + " String s = as.get();\n" + + " }\n" + + " return new AX(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0167() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX a = bar();\n" + + " String s = a.get();\n" + + " System.out.println(s);\n" + + " }\n" + + " public static AX bar() {\n" + + " return new AX(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "SUCCESS"); + } + // FAIL ERRMSG (type display) + public void test0168() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX a = bar();\n" + + " String s = a.get();\n" + + " System.out.println(s);\n" + + " }\n" + + " public static AX, U> bar() {\n" + + " return new AX(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AX a = bar();\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from AX,Thread> to AX\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor AX(Object) belongs to the raw type AX. References to generic type AX should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type AX needs unchecked conversion to conform to AX,U>\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX should be parameterized\n" + + "----------\n"); + } + public void test0169() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX a = bar(new X());\n" + + " String s = a.get();\n" + + " System.out.println(s);\n" + + " }\n" + + " public static AX bar(T t) {\n" + + " return new AX(\"SUCCESS\");\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AX a = bar(new X());\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AX to AX\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor AX(Object) belongs to the raw type AX. References to generic type AX should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type AX needs unchecked conversion to conform to AX\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " return new AX(\"SUCCESS\");\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX should be parameterized\n" + + "----------\n"); + } + // Expected type inference for cast operation + public void test0170() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX(new X());\n" + + " AX as = new AX(\"\");\n" + + " ax = (AX)bar(ax);\n" + // shouldn't complain about unnecessary cast + " }\n" + + " public static T bar(AX a) {\n" + + " return a.get();\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " ax = (AX)bar(ax);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: The expression of type AX needs unchecked conversion to conform to AX\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " ax = (AX)bar(ax);\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? to T\n" + + "----------\n"); + } + // Expected type inference for cast operation + public void test0171() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX(new X());\n" + + " AX as = new AX(\"\");\n" + + " ax = (AX)bar(ax);\n" + // shouldn't complain about unnecessary cast as return type inference do not + " }\n" + // work on cast conversion + " public static T bar(AX a) {\n" + + " return a.get();\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " ax = (AX)bar(ax);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to AX\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " return a.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? to T\n" + + "----------\n"); + } + // Expected type inference for cast operation + public void test0172() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " AX ax = new AX(new X());\n" + + " AX as = new AX(\"SUCCESS\");\n" + + " ax = (AX)bar(ax);\n" + // no warn for unsafe cast, since forbidden cast + " }\n" + + " public static String bar(AX a) {\n" + + " return null;\n" + + " } \n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " ax = (AX)bar(ax);\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot cast from String to AX\n" + + "----------\n"); + } + // Expected type inference for return statement + public void test0173() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static T bar(AX a) {\n" + + " return null;\n" + + " } \n" + + " public static AX foo() {\n" + + " AX ax = new AX(new X());\n" + + " return bar(ax);\n" + // use return type of enclosing method for type inference + " }\n" + + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + + "\n" + }, + "SUCCESS"); + } + // Expected type inference for field declaration + public void test0174() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " Object o = foo;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static T bar(AX a) {\n" + + " return null;\n" + + " } \n" + + " static AX foo = bar(new AX(new X()));\n" + // use field type for type inference + "}\n" + + "class AX {\n" + + " E e;\n" + + " AX(E e) { this.e = e; }\n" + + " E get() { return this.e; }\n" + + "}\n" + + "\n" + }, + "SUCCESS"); + } + // 60563 + public void test0175() { + this.runConformTest( + new String[] { + "X.java", + " interface A {\n" + + " T[] m1(T x); \n" + + " }\n" + + " public class X { \n" + + " public static void main(String[] args) {\n" + + " new X().m2(new A(){ \n" + + " public X[] m1(X x) { \n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " });\n" + + " }\n" + + " void m2(A x) { \n" + + " m3(x.m1(new X())); \n" + + " }\n" + + " void m3(X[] x) {\n" + + " } \n" + + " }\n" + }, + "SUCCESS"); + } + // unsafe raw return value + public void test0176() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Vector valuesOf(Hashtable h) {\n" + + " return new Vector();\n" + + " }\n" + + " Vector data;\n" + + " \n" + + " public void t() {\n" + + " Vector v = (Vector) data.elementAt(0);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " return new Vector();\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Vector needs unchecked conversion to conform to Vector\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " return new Vector();\n" + + " ^^^^^^\n" + + "Vector is a raw type. References to generic type Vector should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " Vector v = (Vector) data.elementAt(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Vector\n" + + "----------\n", + null, + true, + customOptions); + } + // cast to type variable allowed, can be diagnosed as unnecessary + public void test0177() { + Map options = getCompilerOptions(); + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " \n" + + " T foo(T t) {\n" + + " return (T) t;\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + options /* custom options - happen to be the default not changed by the test suite */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 4)\n" + + " return (T) t;\n" + + " ^^^^^\n" + + "Unnecessary cast from T to T\n" + + "----------\n", + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); + } + // reject instanceof type variable or parameterized type + public void test0178() { + if (this.complianceLevel >= ClassFileConstants.JDK16) + return; + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " T foo(T t) {\n" + + " if (t instanceof X) {\n" + + " return t;\n" + + " } else if (t instanceof X) {\n" + + " return t;\n" + + " } else if (t instanceof X) {\n" + // ok + " return t;\n" + + " } else if (t instanceof T) {\n" + + " return t;\n" + + " } else if (t instanceof X) {\n" + + " return t;\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (t instanceof X) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type X. Use the form X instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " } else if (t instanceof X) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type X. Use the form X instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " } else if (t instanceof T) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against type parameter T. Use its erasure Object instead since further generic type information will be erased at runtime\n" + + "----------\n", + null, + true, + customOptions); + } + public void test0178a() { + if (this.complianceLevel < ClassFileConstants.JDK17) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " T foo(T t) {\n" + + " boolean b = false;\n" + + " if (t instanceof X) {\n" + + " return t;\n" + + " } else if (t instanceof X) {\n" + + " return t;\n" + + " } else if (t instanceof X) {\n" + // ok + " return t;\n" + + " } else if (t instanceof T) {\n" + + " return t;\n" + + " } else if (t instanceof X) { // this is allowed since Java 15 as preview feature\n" + + " return t;\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (t instanceof X) {\n" + + " ^\n" + + "Type T cannot be safely cast to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " } else if (t instanceof X) {\n" + + " ^\n" + + "Type T cannot be safely cast to X\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " } else if (t instanceof T) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The expression of type T is already an instance of type T\n" + + "----------\n", + null, + true, + customOptions); + } + // 61507 + public void test0179() { + this.runConformTest( + new String[] { + "X.java", + "class U {\n" + + " static T notNull(T t) { return t; }\n" + + "}\n" + + "public class X {\n" + + " void t() {\n" + + " String s = U.notNull(null);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().t();\n" + + " System.out.println(\"SUCCESS\");\n" + + "}\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0180() { + this.runConformTest( + new String[] { + "X.java", + "class U {\n" + + " static T notNull(T t) { return t; }\n" + + "}\n" + + "public class X {\n" + + " void t() {\n" + + " String s = U.notNull(\"\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().t();\n" + + " System.out.println(\"SUCCESS\");\n" + + "}\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=61507 - variation computing most specific type with 'null' + public void test0181() { + this.runConformTest( + new String[] { + "X.java", + "class U {\n" + + " static T notNull(T t, V vt) { return t; }\n" + + "}\n" + + "class V {}\n" + + "\n" + + "public class X {\n" + + " void t() {\n" + + " String s = U.notNull(null, new V());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().t();\n" + + " System.out.println(\"SUCCESS\");\n" + + "}\n" + + "}\n", + }, + "SUCCESS"); + } + public void test0182() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X foo() {\n" + + " return (X) this;\n" + + " }\n" + + " X bar() {\n" + + " return (AX) new X();\n" + + " }\n" + + " X bar(Object o) {\n" + + " return (AX) o;\n" + + " }\n" + + " X foo(Object o) {\n" + + " return (AX) o;\n" + + " } \n" + + " X baz(Object o) {\n" + + " return (AX) null;\n" + + " }\n" + + " X baz2(BX bx) {\n" + + " return (X) bx;\n" + + " } \n" + + "}\n" + + "class AX extends X {}\n" + + "class BX extends AX {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return (X) this;\n" + + " ^^^^^^^^^^^\n" + + "Unnecessary cast from X to X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " return (AX) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to AX\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " return (AX) o;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to AX\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " return (AX) o;\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to AX\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " return (AX) null;\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from null to AX\n" + + "----------\n" + + "6. WARNING in X.java (at line 18)\n" + + " return (X) bx;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from BX to X\n" + + "----------\n"); + } + public void test0183() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " \n" + + " {\n" + + " Dictionary d;\n" + + " Object o;\n" + + " \n" + + " Object a1 = (Hashtable) d;\n" + + " Object a2 = (Hashtable) o;\n" + + "\n" + + " Object a3 = (Hashtable) d;\n" + + " Object a4 = (Hashtable) o;\n" + + " \n" + + " abstract class Z1 extends Hashtable {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " Z1 z1;\n" + + " Object a5 = (Hashtable) z1;\n" + + "\n" + + " abstract class Z2 extends Z1 {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " Object a6 = (Z2) z1;\n" + + "\n" + + " abstract class Z3 extends Hashtable {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " Z3 z3;\n" + + " Object a7 = (Hashtable) z3;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Object a1 = (Hashtable) d;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Dictionary to Hashtable\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " Object a2 = (Hashtable) o;\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to Hashtable\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " Object a2 = (Hashtable) o;\n" + + " ^^^^^^^^^\n" + + "Hashtable is a raw type. References to generic type Hashtable should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " Object a3 = (Hashtable) d;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Dictionary to Hashtable\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " Object a3 = (Hashtable) d;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Dictionary to Hashtable\n" + + "----------\n" + + "6. WARNING in X.java (at line 13)\n" + + " Object a4 = (Hashtable) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Hashtable\n" + + "----------\n" + + "7. WARNING in X.java (at line 13)\n" + + " Object a4 = (Hashtable) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to Hashtable\n" + + "----------\n" + + "8. WARNING in X.java (at line 19)\n" + + " Object a5 = (Hashtable) z1;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Z1 to Hashtable\n" + + "----------\n" + + "9. WARNING in X.java (at line 24)\n" + + " Object a6 = (Z2) z1;\n" + + " ^^^^^^^\n" + + "Unnecessary cast from Z1 to Z2\n" + + "----------\n" + + "10. WARNING in X.java (at line 26)\n" + + " abstract class Z3 extends Hashtable {\n" + + " ^^^^^^^^^\n" + + "Hashtable is a raw type. References to generic type Hashtable should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 30)\n" + + " Object a7 = (Hashtable) z3;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Z3 to Hashtable\n" + + "----------\n" + + "12. WARNING in X.java (at line 30)\n" + + " Object a7 = (Hashtable) z3;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Z3 to Hashtable\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62292 - parameterized message send + public void test0184() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " static T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // parameterized message send - variation on 184 with non-static generic method + public void test0185() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // message send parameterized with type not matching parameter bounds + public void test0186() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " T foo(T t, U u) {\n" + + " ^^^^^^\n" + + "The type parameter U should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(T, U) of type X is not applicable for the arguments (String, null). The inferred type X is not a valid substitute for the bounded parameter \n" + + "----------\n"); + } + // invalid type argument arity for parameterized message send + public void test0187() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " T foo(T t, U u) {\n" + + " ^^^^^^\n" + + "The type parameter U should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " ^^^\n" + + "Incorrect number of type arguments for generic method foo(T, U) of type X; it cannot be parameterized with arguments \n" + + "----------\n"); + } + // parameterized invocation of non generic method with incorrect argument count + public void test0188() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo() {\n" + + " return;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(new X().foo(\"SUCCESS\", null));\n" + + " ^^^\n" + + "The method foo() in the type X is not applicable for the arguments (String, null)\n" + + "----------\n"); + } + // parameterized invocation of non generic method + public void test0189() { + String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_7 + ? "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(new X().foo());\n" + + " ^^^\n" + + "The method foo() of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + : "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(new X().foo());\n" + + " ^^^^^^^\n" + + "The method println(boolean) in the type PrintStream is not applicable for the arguments (void)\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " System.out.println(new X().foo());\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foo() of type X; it should not be parameterized with arguments \n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo() {\n" + + " return;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo());\n" + + " }\n" + + "}\n", + }, + expectedOutput); + } + // parameterized allocation + public void test0190() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // parameterized allocation - wrong arity + public void test0191() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"FAILED\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incorrect number of type arguments for generic constructor X(T) of type X; it cannot be parameterized with arguments \n" + + "----------\n"); + } + // parameterized allocation - non generic target constructor + // ** + public void test0192() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"FAILED\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"FAILED\");\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " new X(\"FAILED\");\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X(String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // parameterized allocation - argument type mismatch + public void test0193() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new X(null));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X(new X(null));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The parameterized constructor X(String) of type X is not applicable for the arguments (X)\n" + + "----------\n"); + } + // parameterized invocation - argument type mismatch + public void test0194() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo(T t) {\n" + + " return;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(new X()));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(new X().foo(new X()));\n" + + " ^^^\n" + + "The parameterized method foo(String) of type X is not applicable for the arguments (X)\n" + + "----------\n"); + } + // parameterized qualified allocation + public void test0195() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public class MX {\n" + + " public MX(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new MX(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // parameterized qualified allocation - wrong arity + public void test0196() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class MX {\n" + + " public MX(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new MX(\"FAILED\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().new MX(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incorrect number of type arguments for generic constructor MX(T) of type X.MX; it cannot be parameterized with arguments \n" + + "----------\n"); + } + // parameterized qualified allocation - non generic target constructor + // ** + public void test0197() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class MX {\n" + + " public MX(String t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new MX(\"FAILED\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().new MX(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor MX(String) of type X.MX is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class MX {\n" + + " public MX(String t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new MX(\"FAILED\");\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " new X().new MX(\"FAILED\");\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X.MX(String) of type X.MX; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // parameterized qualified allocation - argument type mismatch + public void test0198() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class MX {\n" + + " public MX(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new MX(new X());\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().new MX(new X());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The parameterized constructor MX(String) of type X.MX is not applicable for the arguments (X)\n" + + "----------\n"); + } + // parameterized explicit constructor call + public void test0199() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"SUCCESS\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // parameterized explicit constructor call - wrong arity + public void test0200() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"FAILED\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Incorrect number of type arguments for generic constructor X(T) of type X; it cannot be parameterized with arguments \n" + + "----------\n"); + } + // parameterized explicit constructor call - non generic target constructor + // ** + public void test0201() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"FAILED\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The constructor X(String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " Zork z;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"FAILED\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " super(\"FAILED\");\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X(String) of type X; it should not be parameterized with arguments \n" + + "----------\n"); + } + // parameterized explicit constructor call - argument type mismatch + public void test0202() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(T t){\n" + + " System.out.println(t);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(new X(null));\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super(new X(null));\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The parameterized constructor X(String) of type X is not applicable for the arguments (X)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62822 - supertypes partially resolved during bound check + public void test0203() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " demo.AD ad;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + "demo/AD.java", + "package demo;\n" + + "public interface AD extends LIST {}\n", + "demo/ADXP.java", + "package demo;\n" + + "public interface ADXP extends BIN {}\n", + "demo/ANY.java", + "package demo;\n" + + "public interface ANY {}\n", + "demo/BL.java", + "package demo;\n" + + "public interface BL extends ANY {}\n", + "demo/LIST.java", + "package demo;\n" + + "public interface LIST extends ANY {}\n", + "demo/BIN.java", + "package demo;\n" + + "public interface BIN extends LIST {}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62806 + public void test0204() { + this.runConformTest( + new String[] { + "Function.java", + "public abstract class Function {\n" + + " public abstract Y eval(X x);\n" + + "\n" + + "}\n", + "FunctionMappedComparator.java", + "import java.util.*;\n" + + "public class FunctionMappedComparator implements Comparator {\n" + + " /*\n" + + " * \'Function\' is highlighted as an error here - the message is:\n" + + " * The type Function is not generic; it cannot be parameterized with arguments \n" + + " */\n" + + " protected Function function;\n" + + " protected Comparator comparator;\n" + + " public FunctionMappedComparator(Function function,Comparator comparator ) {\n" + + " this.function=function;\n" + + " this.comparator=comparator;\n" + + " }\n" + + "\n" + + " public int compare(X x1, X x2) {\n" + + " return comparator.compare(function.eval(x1),function.eval(x2));\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63555 - reference to static type parameter allowed inside type itself + public void test0205() { + this.runConformTest( + new String[] { + "Alpha.java", + "public class Alpha {\n" + + " static class Beta {\n" + + " T obj;\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63555 - variation on static method type parameter + public void test0206() { + this.runConformTest( + new String[] { + "Alpha.java", + "public class Alpha {\n" + + " static void Beta(T t) {\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63590 - disallow parameterized type in catch/throws clause + public void test0207() { + this.runNegativeTest( + new String[] { + "Alpha.java", + "public class Alpha extends RuntimeException {\n" + + " public static void main(String[] args) {\n" + + " new Object() {\n" + + " public void m() throws Alpha {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }.m();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Alpha.java (at line 1)\n" + + " public class Alpha extends RuntimeException {\n" + + " ^^^^^\n" + + "The serializable class Alpha does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in Alpha.java (at line 1)\n" + + " public class Alpha extends RuntimeException {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The generic class Alpha may not subclass java.lang.Throwable\n" + + "----------\n" + + "3. ERROR in Alpha.java (at line 4)\n" + + " public void m() throws Alpha {\n" + + " ^^^^^\n" + + "Cannot use the parameterized type Alpha either in catch block or throws clause\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63590 - disallow parameterized type in catch/throws clause + public void test0208() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends RuntimeException {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new X();\n" + + " } catch(X e) {\n" + + " System.out.println(\"X\");\n" + + " } catch(X> e) {\n" + + " System.out.println(\"X>\");\n" + + " } catch(RuntimeException e) {\n" + + " System.out.println(\"RuntimeException\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X extends RuntimeException {\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 extends RuntimeException {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The generic class X may not subclass java.lang.Throwable\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " } catch(X e) {\n" + + " ^\n" + + "Cannot use the parameterized type X either in catch block or throws clause\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " } catch(X> e) {\n" + + " ^\n" + + "Cannot use the parameterized type X> either in catch block or throws clause\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63556 - should resolve all occurrences of A to type variable + public void test0209() { + this.runConformTest( + new String[] { + "X.java", + "public class X> {}\n" + + "class X2, B> {}\n" + + "class X3> {}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68006 - Invalid modifier after parse + public void test0210() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Map m){\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Map m){\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n"); + } + // test compilation against binaries + public void test0211() { + this.runConformTest( + new String[] { + "p/Top.java", + "package p;\n" + + "public interface Top {}\n", + }, + ""); + + this.runConformTest( + new String[] { + "p/Super.java", + "package p;\n" + + "public class Super implements Top{\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, // do not flush output + null); + } + // check type variable equivalence + public void test0212() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X{\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " X _recurse; \n" + + " public List toList(){\n" + + " List result = new ArrayList();\n" + + " result.addAll(_recurse.toList()); // should be applicable\n" + + " return result;\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0213() { + this.runConformTest( + new String[] { + "X.java", + "public class X>{\n" + + " T test;\n" + + " public Comparable getThis(){\n" + + " return test;\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68133 - verify error + public void test0214() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " ArrayList l;\n" + + " switch (args.length) {\n" + + " case 1:\n" + + " l = new ArrayList();\n" + + " System.out.println(l);\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68133 variation + public void test0215() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.ArrayList i; \n" + + " outer: {\n" + + " if (args == null) {\n" + + " i = null;\n" + + " break outer;\n" + + " }\n" + + " return;\n" + + " }\n" + + " System.out.println(i); \n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + ""); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 aload_0 [args]\n" + + " 1 ifnonnull 9\n" + + " 4 aconst_null\n" + + " 5 astore_1 [i]\n" + + " 6 goto 10\n" + + " 9 return\n" + + " 10 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 13 aload_1 [i]\n" + + " 14 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [22]\n" + + " 17 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 20 ldc [28]\n" + + " 22 invokevirtual java.io.PrintStream.println(java.lang.String) : void [30]\n" + + " 25 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 4, line: 6]\n" + + " [pc: 6, line: 7]\n" + + " [pc: 9, line: 9]\n" + + " [pc: 10, line: 11]\n" + + " [pc: 17, line: 12]\n" + + " [pc: 25, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 26] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 6, pc: 9] local: i index: 1 type: java.util.ArrayList\n" + + " [pc: 10, pc: 26] local: i index: 1 type: java.util.ArrayList\n" + + " Local variable type table:\n" + + " [pc: 6, pc: 9] local: i index: 1 type: java.util.ArrayList\n" + + " [pc: 10, pc: 26] local: i index: 1 type: java.util.ArrayList\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68998 parameterized field constants + public void test0216() { + this.runConformTest( + new String[] { + "test/cheetah/NG.java", + "package test.cheetah;\n" + + "public class NG extends G {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + " public boolean test() {\n" + + " return o == null;\n" + + " }\n" + + "}\n", + "test/cheetah/G.java", + "package test.cheetah;\n" + + "public class G {\n" + + " protected Object o;\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69135 - unnecessary cast operation + public void test0217() { + Map customOptions = getCompilerOptions(); + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.ArrayList;\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " ArrayList l= new ArrayList();\n" + + " String string = (String) l.get(0);\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 5)\n" + + " String string = (String) l.get(0);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from String to String\n" + + "----------\n", + // runtime results + null /* do not check output string */, + "java.lang.IndexOutOfBoundsException" /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=64154 visibility issue due to invalid use of parameterized binding + public void test0218() { + this.runConformTest( + new String[] { + "X.java", + "public class X{\n" + + " private final T _data;\n" + + " private X(T data){\n" + + " _data = data;\n" + + " }\n" + + " public T getData(){\n" + + " return _data;\n" + + " }\n" + + " public static X create(E data) {\n" + + " return new X(data);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " create(new Object());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=64154 variation + public void test0219() { + this.runConformTest( + new String[] { + "X.java", + "public class X{\n" + + " private final T _data;\n" + + " private X(T data){\n" + + " _data = data;\n" + + " }\n" + + " public T getData(){\n" + + " return _data;\n" + + " }\n" + + " public static E create(E data) {\n" + + " return new X(data)._data;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " create(new Object());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69141 unsafe wildcard operation tolerates wildcard with lower bounds + public void test0220() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " ArrayList al = new ArrayList();\n" + + " al.add(Integer.valueOf(1)); // (1)\n" + + " Integer i = al.get(0); // (2)\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Integer i = al.get(0); // (2)\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? super Integer to Integer\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69141 variation + public void test0221() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " ArrayList al = new ArrayList();\n" + + " al.add(Integer.valueOf(1)); // (1)\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " al.add(Integer.valueOf(1)); // (1)\n" + + " ^^^\n" + + "The method add(capture#1-of ? extends Integer) in the type ArrayList is not applicable for the arguments (Integer)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69141: variation + public void test0222() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " XList lx = new XList();\n" + + " lx.slot = Integer.valueOf(1);\n" + + " Integer i = lx.slot;\n" + + " } \n" + + "}\n" + + "class XList {\n" + + " E slot;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Integer i = lx.slot;\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? super Integer to Integer\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69251- instantiating wildcards + public void test0223() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " static final Map> classes \n" + + " = new HashMap>();\n" + + " \n" + + " static final Map> classes2 \n" + + " = new HashMap();\n" + + " \n" + + " class MX {\n" + + " E get() { return null; }\n" + + " void foo(E e) {}\n" + + " }\n" + + " \n" + + " void foo() {\n" + + " MX> mx1 = new MX>();\n" + + " MX mx2 = new MX();\n" + + " mx1.foo(mx2.get());\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " = new HashMap();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from HashMap to Map>\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " = new HashMap();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " MX mx2 = new MX();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 17)\n" + + " MX mx2 = new MX();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 18)\n" + + " mx1.foo(mx2.get());\n" + + " ^^^^^^^^^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n", + null, + true, + customOptions); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=68998 variation + public void test0224() { + this.runNegativeTest( + new String[] { + "test/cheetah/NG.java", + "package test.cheetah;\n" + + "public class NG extends G {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + " public boolean test() {\n" + + " return o == null;\n" + + " }\n" + + "}\n", + "test/cheetah/G.java", + "package test.cheetah;\n" + + "public class G {\n" + + " protected final Object o;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in test\\cheetah\\NG.java (at line 2)\n" + + " public class NG extends G {\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. ERROR in test\\cheetah\\G.java (at line 3)\n" + + " protected final Object o;\n" + + " ^\n" + + "The blank final field o may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69353 - prevent using type parameter in catch block + public void test0225() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo() throws T {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().baz(new EX());\n" + + " }\n" + + " void baz(final T t) {\n" + + " new Object() {\n" + + " void print() {\n" + + " try {\n" + + " System.out.println(foo());\n" + + " } catch (T t) {\n" + + " }\n" + + " }\n" + + " }.print();\n" + + " }\n" + + "}\n" + + "class EX extends Exception {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " } catch (T t) {\n" + + " ^\n" + + "Cannot use the type parameter T in a catch block\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " } catch (T t) {\n" + + " ^\n" + + "The parameter t is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "3. WARNING in X.java (at line 19)\n" + + " class EX extends Exception {\n" + + " ^^\n" + + "The serializable class EX does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69170 - invalid generic array creation + public void test0226() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X{\n" + + " Object x1= new T[0];\n" + + " Object x2= new X[0]; \n" + + " Object x3= new X[0]; \n" + + " Object x4= new X[0]; \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Object x1= new T[0];\n" + + " ^^^^^^^^\n" + + "Cannot create a generic array of T\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Object x2= new X[0]; \n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Object x3= new X[0]; \n" + + " ^^^^^^^^^^^\n" + + "Cannot create a generic array of X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69359 - unsafe cast diagnosis + public void test0227() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.*;\n" + + " public class X {\n" + + " List list() { return null; }\n" + + " void m() { List l = (List)list(); } // unsafe cast\n" + + " void m0() { List l = list(); } // unsafe conversion\n" + + " void m1() { for (X a : list()); } // type mismatch\n" + + " void m2() { for (Iterator i = list().iterator(); i.hasNext();); } // unsafe conversion\n" + + " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + + " void m4() { Collection c = null; List l = (List)c; } // ok\n" + + " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + + "}\n" , + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " List list() { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " void m() { List l = (List)list(); } // unsafe cast\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " void m() { List l = (List)list(); } // unsafe cast\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " void m0() { List l = list(); } // unsafe conversion\n" + + " ^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " void m1() { for (X a : list()); } // type mismatch\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from element type Object to X\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " void m2() { for (Iterator i = list().iterator(); i.hasNext();); } // unsafe conversion\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator\n" + + "----------\n" + + "7. WARNING in X.java (at line 8)\n" + + " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 8)\n" + + " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 8)\n" + + " void m3() { Collection c = null; List l = (List)c; } // unsafe cast\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Collection to List\n" + + "----------\n" + + "10. WARNING in X.java (at line 9)\n" + + " void m4() { Collection c = null; List l = (List)c; } // ok\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 9)\n" + + " void m4() { Collection c = null; List l = (List)c; } // ok\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "12. WARNING in X.java (at line 10)\n" + + " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "13. WARNING in X.java (at line 10)\n" + + " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "14. WARNING in X.java (at line 10)\n" + + " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to Collection\n" + + "----------\n" + + "15. ERROR in X.java (at line 10)\n" + + " void m5() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Collection to List\n" + + "----------\n" + + "16. WARNING in X.java (at line 11)\n" + + " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "17. WARNING in X.java (at line 11)\n" + + " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "18. ERROR in X.java (at line 11)\n" + + " void m6() { List c = null; List l = (Collection)c; } // type mismatch\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Collection to List\n" + + "----------\n"); + } + // conversion from raw to X is safe (no unsafe warning) + public void test0228() { + this.runConformTest( + new String[] { + "X.java", + " import java.util.*;\n" + + " public class X {\n" + + " List list = new ArrayList();\n" + + " }\n", + }, + ""); + } + // can resolve member through type variable + public void test0229() { + runConformTest( + true, + new String[] { + "X.java", + " public class X {\n" + + " T.MXC f;\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " class XC {\n" + + " class MXC {}\n" + + " }\n", + }, + null, + "SUCCESS", + null, + JavacTestOptions.JavacHasABug.JavacBug6569404); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69375 - equivalence of wildcards + public void test0230() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " List li= null;\n" + + " List ln= null;\n" + + " ln = li;\n" + + " li= ln;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " li= ln;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69170 - variation + public void test0231() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X{\n" + + " Object x1= new X[0]; \n" + + " Object x2= new X[0]; \n" + + " Object x3= new X[0]; \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object x2= new X[0]; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Object x3= new X[0]; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - generic cast should be less strict + public void test0232() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " private T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(\"BAD\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Object someVal = cont.getVal(); // no cast \n" + + " System.out.println(cont.getVal()); // no cast \n" + + " }\n" + + "}\n", + }, + "BAD"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0233() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " private T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(new Long(0));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Number someVal = cont.getVal();// only cast to Number \n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0234() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(\"BAD\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Object someVal = cont.val; // no cast \n" + + " System.out.println(cont.val); // no cast \n" + + " }\n" + + "}\n", + }, + "BAD"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0235() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(new Long(0));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Number someVal = cont.val;// only cast to Number \n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0236() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(\"BAD\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Object someVal = (cont).val; // no cast \n" + + " System.out.println((cont).val); // no cast \n" + + " }\n" + + "}\n", + }, + "BAD"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0237() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(new Long(0));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont=new Container();\n" + + " cont.setVal(new Integer(0));\n" + + " badMethod(cont);\n" + + " Number someVal = (cont).val;// only cast to Number \n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0238() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " Container next;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(\"BAD\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont = new Container();\n" + + " cont.next = new Container();\n" + + " cont.next.setVal(new Integer(0));\n" + + " badMethod(cont.next);\n" + + " Object someVal = cont.next.val; // no cast \n" + + " System.out.println(cont.next.val); // no cast \n" + + " }\n" + + "}\n", + }, + "BAD"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69542 - variation + public void test0239() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Container{\n" + + " public T val;\n" + + " Container next;\n" + + " public T getVal() {\n" + + " return val;\n" + + " }\n" + + " public void setVal(T val) {\n" + + " this.val = val;\n" + + " }\n" + + " }\n" + + " public static void badMethod(Container param){\n" + + " Container x=param;\n" + + " x.setVal(new Long(0));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Container cont = new Container();\n" + + " cont.next = new Container();\n" + + " cont.next.setVal(new Integer(0));\n" + + " badMethod(cont.next);\n" + + " Number someVal = cont.next.val;// only cast to Number \n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69713 NPE due to length pseudo field + public void test0240() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String[] elements = null;\n" + + " \n" + + " public X() {\n" + + " String s = \"a, b, c, d\";\n" + + " elements = s.split(\",\");\n" + + " if(elements.length = 3) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if(elements.length = 3) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from int to boolean\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69776 - missing checkcast on cast operation + public void test0241() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " private static final Map classes = new HashMap();\n" + + " public static void main(String[] args) throws Exception {\n" + + " classes.put(\"test\", X.class);\n" + + " final Class clazz = (Class) classes.get(\"test\");\n" + + " Object o = clazz.newInstance();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // 69776 - variation + public void test0242() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "@SuppressWarnings({\"rawtypes\"})\n" + + "public class X {\n" + + " private static final Map classes = new HashMap();\n" + + " public static void main(String[] args) throws Exception {\n" + + " classes.put(\"test\", X.class);\n" + + " final Class clazz = (Class) classes.get(\"test\");\n" + + " final Class clazz2 = (Class) classes.get(\"test\");\n" + + " final Class clazz3 = (Class) classes.get(\"test\");\n" + + " Object o = clazz.newInstance();\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " final Class clazz = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " final Class clazz = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Class to Class\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " final Class clazz2 = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " final Class clazz2 = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Class to Class\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " final Class clazz3 = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " final Class clazz3 = (Class) classes.get(\"test\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Class to Class\n" + + "----------\n", + null, true, options ); + } + public void test0243() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X foo() {\n" + + " System.out.println(\"Did NOT add bridge method\");\n" + + " return this;\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " X x = new A();\n" + + " x.foo();\n" + + " System.out.print(\" + \");\n" + + " I i = new A();\n" + + " i.foo();\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public I foo();\n" + + "}\n" + + "class A extends X implements I {\n" + + " public A foo() {\n" + + " System.out.print(\"Added bridge method\");\n" + + " return this;\n" + + " }\n" + + "}\n" + }, + "Added bridge method + Added bridge method"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X foo() { return this; }\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + "SubTypes.java", + "class A extends X {\n" + + " @Override public A foo() { return this; }\n" + + "}\n" + + "class B extends X {\n" + + " @Override public X foo() { return new X(); }\n" + + " @Override public B foo() { return this; }\n" + + "}\n" + + "class C extends A {\n" + + " @Override public X foo() { return new X(); }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in SubTypes.java (at line 5)\n" + + " @Override public X foo() { return new X(); }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type B\n" + + "----------\n" + + "2. ERROR in SubTypes.java (at line 6)\n" + + " @Override public B foo() { return this; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type B\n" + + "----------\n" + + "3. ERROR in SubTypes.java (at line 9)\n" + + " @Override public X foo() { return new X(); }\n" + + " ^\n" + + "The return type is incompatible with A.foo()\n" + + "----------\n"); + } + // generic method of raw type + public void test0244() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " T foo(G g) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X rx = new X();\n" + + " rx.foo(\"hello\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X rx = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X rx = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " rx.foo(\"hello\");\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n"); + } + // generic method of raw type + public void test0245() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " T foo(G g) {\n" + + " return null;\n" + + " }\n" + + " T bar(T t) {\n" + + " return zork;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X rx = new X();\n" + + " rx.foo(\"hello\"); // Eclipse error here\n" + + " rx.bar(\"hello\"); // Eclipse error here\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return zork;\n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " X rx = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " X rx = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " rx.foo(\"hello\"); // Eclipse error here\n" + + " ^^^\n" + + "The method foo(Object) of raw type X is no longer generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "5. ERROR in X.java (at line 12)\n" + + " rx.bar(\"hello\"); // Eclipse error here\n" + + " ^^^\n" + + "The method bar(Object) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236242); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " T foo(G g) {\n" + + " return null;\n" + + " }\n" + + " T bar(T t) {\n" + + " return zork;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X rx = new X();\n" + + " rx.foo(\"hello\"); // Eclipse error here\n" + + " rx.bar(\"hello\"); // Eclipse error here\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return zork;\n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " X rx = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " X rx = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " rx.foo(\"hello\"); // Eclipse error here\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " rx.bar(\"hello\"); // Eclipse error here\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method bar(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " rx.bar(\"hello\"); // Eclipse error here\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method bar(Object) of type X; it should not be parameterized with arguments \n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236242); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69320 parameterized type compatibility + public void test0246() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " class MX {\n" + + " }\n" + + " void foo() {\n" + + " MX> mx2 = new MX();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " MX> mx2 = new MX();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.MX to X.MX>\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " MX> mx2 = new MX();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69320 variation + public void test0247() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " void foo() {\n" + + " MX> mx2 = new MX(); // wrong\n" + + " MX> mx3 = new MX>(); // wrong\n" + + " MX> mx4 = new MX>(); // wrong\n" + + " MX mx5 = new MX(); // ok\n" + + " MX mx6 = new MX(); // ok\n" + + " MX> mx7 = new MX>(); // wrong\n" + + " MX> mx8 = new MX>(); // wrong\n" + + " }\n" + + "}\n" + + "\n" + + "class MX {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " MX> mx2 = new MX(); // wrong\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MX to MX>\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " MX> mx2 = new MX(); // wrong\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " MX> mx3 = new MX>(); // wrong\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " MX> mx4 = new MX>(); // wrong\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " MX mx5 = new MX(); // ok\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 6)\n" + + " MX mx5 = new MX(); // ok\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 7)\n" + + " MX mx6 = new MX(); // ok\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 7)\n" + + " MX mx6 = new MX(); // ok\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 8)\n" + + " MX> mx7 = new MX>(); // wrong\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "10. ERROR in X.java (at line 8)\n" + + " MX> mx7 = new MX>(); // wrong\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "11. WARNING in X.java (at line 8)\n" + + " MX> mx7 = new MX>(); // wrong\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "12. WARNING in X.java (at line 9)\n" + + " MX> mx8 = new MX>(); // wrong\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "13. ERROR in X.java (at line 9)\n" + + " MX> mx8 = new MX>(); // wrong\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "14. WARNING in X.java (at line 9)\n" + + " MX> mx8 = new MX>(); // wrong\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70247 check type variable is bound during super type resolution + public void test0248() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X extends Vector>{}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X extends Vector>{}\n" + + " ^^^^^^\n" + + "The type X cannot extend or implement Vector>. A supertype may not specify any wildcard\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70247 variation + public void test0249() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X implements List>{}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X implements List>{}\n" + + " ^^^^\n" + + "The type X cannot extend or implement List>. A supertype may not specify any wildcard\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70295 Class is compatible with Class + public void test0250() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void test(Object o) {\n" + + " X.class.isAssignableFrom(o.getClass());\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69800 '? extends Object' is not compatible with A + public void test0251() { + this.runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"deprecation\")\n" + + "public class X { \n" + + " static class A {\n" + + " }\n" + + " A test() throws Exception {\n" + + " Class clazz = null;\n" + + " return clazz.newInstance(); // ? extends Object\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return clazz.newInstance(); // ? extends Object\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? extends Object to X.A\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69799 NPE in foreach checkcast + // effective result may change depending upon + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=148241 + // ** + public void test0252() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Set channel = channels.get(0);\n" + + " for (Iterator iter = channel.iterator(); iter.hasNext();) {\n" + + " Set element;\n" + + " element = (Set) iter.next();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Set channel = channels.get(0);\n" + + " ^^^^^^^^\n" + + "channels cannot be resolved\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " element = (Set) iter.next();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to Set\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70243 unsafe cast when wildcards + public void test0253() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List li= new ArrayList();\n" + + " List ls= li; \n" + + " List x2= (List)ls;//unsafe\n" + + " x2.add(Float.valueOf(1.0f));\n" + + " \n" + + " Integer i= li.get(0);//ClassCastException!\n" + + " \n" + + " List ls2 = (List)ls;\n" + + " List ls3 = (List) li;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " List x2= (List)ls;//unsafe\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " List ls2 = (List)ls;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " List ls3 = (List) li;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70053 missing checkcast in string concatenation + public void test0254() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " System.out.print(\"S\" + x.a() + \"U\" + x.b().get(0) + \"C\" + x.a() + \"C\");\n" + + " System.out.println(new StringBuilder(\"E\").append(x.a()).append(\"S\").append(x.b().get(0)).append(\"S\").append(x.a()).append(\"!\")); \n" + + " }\n" + + " String a() { return \"\"; }\n" + + " List b() { \n" + + " ArrayList als = new ArrayList(1);\n" + + " als.add(a());\n" + + " return als;\n" + + " }\n" + + "}\n" + }, + "SUCCESS!"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69351 generic type cannot extend Throwable + public void test0255() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Throwable {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X extends Throwable {\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 extends Throwable {\n" + + " ^^^^^^^^^\n" + + "The generic class X may not subclass java.lang.Throwable\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70616 - reference to binary Enum + public void test0256() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + "\n" + + " Enum ex = null;\n" + + " String s = ex.name();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Enum ex = null;\n" + + " ^\n" + + "Bound mismatch: The type X is not a valid substitute for the bounded parameter > of the type Enum\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70618 - reference to variable allowed in parameterized super type + public void test0257() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public abstract class M extends java.util.AbstractList {}\n" + + "}\n" + + "class Y extends T {}\n" + + "class Z {\n" + + " class M extends T {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " class Y extends T {}\n" + + " ^\n" + + "Cannot refer to the type parameter T as a supertype\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class M extends T {}\n" + + " ^\n" + + "Cannot refer to the type parameter T as a supertype\n" + + "----------\n"); + } + public void test0258() { + this.runConformTest( + new String[] { + "X.java", + "abstract class X implements java.util.Map {\n" + + " static abstract class M implements Entry {}\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70767 - NPE compiling code with explicit constructor invocation + public void test0259() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " X(E e) {\n" + + " this();\n" + + " }\n" + + " \n" + + " X() {\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0260() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "}\n" + + "\n" + + "class XC extends X {\n" + + " class MXC extends MX {\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0261() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " X xi = (X) new X();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X xi = (X) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n"); + } + public void test0262() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " X xe = (X) new X();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " X xe = (X) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n"); + } + public void test0263() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " XC xe = (XC) new X();\n" + + " }\n" + + "}\n" + + "class XC extends X {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " XC xe = (XC) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to XC\n" + + "----------\n"); + } + public void test0264() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " XC xe = (XC) new X();\n" + + " }\n" + + "}\n" + + "class XC extends X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " XC xe = (XC) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to XC\n" + + "----------\n"); + } + public void test0265() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " XC xcu = (XC) new X();\n" + + " XC xcu1 = (XC) new X(); \n" + + " XC xcu2 = (XC) new X(); \n" + + " }\n" + + "}\n" + + "class XC extends X {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " XC xcu = (XC) new X();\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to XC\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " XC xcu1 = (XC) new X(); \n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XC to XC\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " XC xcu2 = (XC) new X(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to XC\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " XC xcu2 = (XC) new X(); \n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); + } + public void test0266() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar() {\n" + + " X xe = new X();\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0267() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(X xany) { \n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0268() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {\n" + + " X[] foo() {\n" + + " ArrayList list = new ArrayList();\n" + + " return list.toArray(new X[list.size()]);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " X[] foo() {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " ArrayList list = new ArrayList();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " ArrayList list = new ArrayList();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type ArrayList needs unchecked conversion to conform to ArrayList\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " ArrayList list = new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70975 - test compilation against binary generic method + public void test0269() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " U[] bar(U[] u) { \n" + + " System.out.println(\"SUCCESS\");\n" + + " return null; }\n" + + "\n" + + " static String[] foo() {\n" + + " X xs = new X();\n" + + " return xs.bar(new String[0]);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + this.runConformTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String [] args) {\n" + + " X xs = new X();\n" + + " String[] s = xs.bar(new String[0]);\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, // do not flush output + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=70969 - lub(List, List) --> List + public void test0270() { + 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()\n" + + " : new ArrayList();\n" + + " \n" + + " X x = param ? new XY() : new XZ();\n" + + " XY y = (XY) new XZ();\n" + + " }\n" + + "}\n" + + "class XY extends X {}\n" + + "class XZ extends X {}\n" + }, + + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " XY y = (XY) new XZ();\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot cast from XZ to XY\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71080 - parameter bound > should be allowed + public void test0271() { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71080 - variation + public void test0272() { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + "}\n" + + "\n" + + "class XY implements Cloneable {\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71080 - variation + public void test0273() { + this.runConformTest( + new String[] { + "X.java", + "public class X & Cloneable> {\n" + + "}\n" + + "\n" + + "class XY {\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 + public void test0274() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public List useList(List l) {\n" + + " l.add(\"asdf\");\n" + + " return l;\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " public List useList(List l) {\n" + + " l.add(\"asdf\");\n" + + " return l;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public List useList(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " public List useList(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " l.add(\"asdf\");\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " public List useList(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method useList(List) of type Y has the same erasure as useList(List) of type X but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation + public void test0275() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public List useList(List l) {\n" + + " l.add(\"asdf\");\n" + + " return l;\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " public List useList(List l) {\n" + + " l.add(\"asdf\");\n" + + " return l;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " public List useList(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " public List useList(List l) {\n" + + " ^^^^\n" + + "Type safety: The return type List for useList(List) from the type Y needs unchecked conversion to conform to List from the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public List useList(List l) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method useList(List) of type Y should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " public List useList(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " l.add(\"asdf\");\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation + public void test0276() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public void useList(List l) {}\n" + + "}\n" + + "class Y extends X {\n" + + " public void useList(List l) {\n" + + " super.useList(l);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void useList(List l) {}\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public void useList(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method useList(List) of type Y has the same erasure as useList(List) of type X but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation + public void test0277() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public void useList(List l) {}\n" + + "}\n" + + "class Y extends X {\n" + + " public void useList(List l) {\n" + + " super.useList(l);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public void useList(List l) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method useList(List) of type Y should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public void useList(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " super.useList(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71241 - variation + public void test0278() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {\n" + + " public Class getDeclaringClass() { return null; }\n" + + "}\n" + + "class Y implements I {\n" + + " public Class getDeclaringClass() { return null; }\n" + + "}\n" + + "interface I {\n" + + " public Class getDeclaringClass();\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=69901 + public void test0279() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements ISomething {\n" + + " public Class getSomething() { return null; }\n" + + "}\n" + + "class Y {}\n" + + "interface ISomething {\n" + + " public Class getSomething();\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public Class getSomething() { return null; }\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " public Class getSomething() { return null; }\n" + + " ^^^^^\n" + + "Type safety: The return type Class for getSomething() from the type X needs unchecked conversion to conform to Class from the type ISomething\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=62822 + public void test0280() { + this.runConformTest( + new String[] { + "X.java", + "interface X, T2 extends Z> {}\n" + + "interface Y {}\n" + + "interface Z {}\n" + }, + ""); + } + public void test0281() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X, T2 extends Z> {}\n" + + "interface Y {}\n" + + "interface Z {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface X, T2 extends Z> {}\n" + + " ^^\n" + + "Bound mismatch: The type T2 is not a valid substitute for the bounded parameter of the type Y\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " interface Y {}\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n"); + } + public void test0282() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y.Member {}\n" + + "class Y { static class Member {} }\n" + }, + ""); + this.runConformTest( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X extends p1.Y.Member {}\n" + + "class Y { static class Member {} }\n" + }, + ""); + } + public void test0283() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y.Missing {}\n" + + "class Y { static class Member {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y.Missing {}\n" + + " ^^^^^^^^^\n" + + "Y.Missing cannot be resolved to a type\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X extends Y.Missing {}\n" + + "class Y { static class Member {} }\n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public class X extends Y.Missing {}\n" + + " ^^^^^^^^^\n" + + "Y.Missing cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72083 + public void test0284() { + this.runConformTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A , T2 extends B> {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + "p1/B.java", + "package p1;\n" + + "public class B , T4 extends B> {}\n" + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A , T2 extends A> {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + "p1/B.java", + "package p1;\n" + + "public class B , T4 extends A> {}\n" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73530 + public void test0285() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " public static void main(String[] args){\n" + + " Vector v = new Vector();\n" + + " Integer[] array1 = new Integer[5];\n" + + " array1[0] = new Integer(17);\n" + + " array1[1] = new Integer(42);\n" + + " v.add(array1);\n" + + " Integer twentyfour = v.get(0)[1]; // responsible for the crash\n" + + " System.out.println(twentyfour);\n" + + " }\n" + + "}" + }, + "42"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72644 + // TODO (philippe) we need a way to test these 2 methods & find them 'equivalent'... right isEquivalentTo return false + public void test0286() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(Class c) {return null;}\n" + + "}\n" + + "class Y extends X {\n" + + " T foo(Class c) {return null;}\n" + + "}" + }, + ""); + } + public void test0287() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public class A {\n" + + " \n" + + " public class B {\n" + + " \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " X.A.B bs;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X.A.B bs;\n" + + " ^^^^^\n" + + "The member type X.A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); + } + public void test0288() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static class A {\n" + + " \n" + + " public static class B {\n" + + " \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " X.A.B bs;\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0289() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public class A {\n" + + " \n" + + " public class B {\n" + + " \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " X.A.B bs;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X.A.B bs;\n" + + " ^^^^^^^^^^^\n" + + "The member type X.A must be parameterized, since it is qualified with a parameterized type\n" + + "----------\n"); + } + public void test0290() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static class A {\n" + + " \n" + + " public class B {\n" + + " \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " X.A.B bs;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X.A.B bs;\n" + + " ^^^^^^^^^^^\n" + + "The member type X.A cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + + "----------\n"); + } + // ensure bound check deals with supertype (and their enclosing type) + public void test0291() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class MX {\n" + + " }\n" + + "}\n" + + "class SX extends X.MX {\n" + + " SX(X x){\n" + + " x.super();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^^^\n" + + "Iterable is a raw type. References to generic type Iterable should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " class MX {\n" + + " ^^^^^^^^\n" + + "Iterable is a raw type. References to generic type Iterable should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " class SX extends X.MX {\n" + + " ^^^^^^\n" + + "Bound mismatch: The type Thread is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " class SX extends X.MX {\n" + + " ^^^^^^\n" + + "Bound mismatch: The type Object is not a valid substitute for the bounded parameter of the type X.MX\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " SX(X x){\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); + } + public void test0292() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " class Z {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y.Z zo;\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73837 + public void test0293() { + this.runConformTest( + new String[] { + "B.java", //--------------------------- + "public class B{\n"+ + " public B(X str,D dValue){}\n"+ + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" , + "D.java", //--------------------------- + "public class D{}\n", + }, + "SUCCESS"); + + this.runConformTest( + new String[] { + "C.java", //--------------------------- + "public class C {\n" + + " public B test(Z zValue,D yValue){ return new B(zValue,yValue); }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, // do not flush output + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73837 variation + public void test0294() { + this.runConformTest( + new String[] { + "B.java", //--------------------------- + "public class B{\n"+ + " public B(X str, B dValue){}\n"+ + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" , + "D.java", //--------------------------- + "public class D{}\n", + }, + "SUCCESS"); + + this.runNegativeTest( + new String[] { + "C.java", //--------------------------- + "public class C {\n" + + " public B test(Z zValue,B> yValue){ return new B(zValue,yValue); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in C.java (at line 2)\n" + + " public B test(Z zValue,B> yValue){ return new B(zValue,yValue); }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor B(Z, B>) is undefined\n" + + "----------\n", + null, + false, // do not flush output + null); + } + // non-static method #start() gets its type substituted when accessed through raw type + public void test0295() { + this.runNegativeTest( + new String[] { + "C.java", //--------------------------- + "public class C {\n" + + "\n" + + " void bar() {\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " }\n" + + "}\n", + "B.java", //--------------------------- + "public class B{\n" + + " X get(B bx) { return null; }\n" + + " B> start() { return null; }\n" + + "}", + "D.java", //--------------------------- + "public class D{}\n", + }, + "----------\n" + + "1. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method get(B) belongs to the raw type B. References to generic type B should be parameterized\n" + + "----------\n" + + "2. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "3. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "4. ERROR in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^\n" + + "The method get(B) is undefined for the type Object\n" + + "----------\n" + + "5. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in B.java (at line 3)\n" + + " B> start() { return null; }\n" + + " ^\n" + + "D is a raw type. References to generic type D should be parameterized\n" + + "----------\n"); + } + // static method #start() gets its type does not get substituted when accessed through raw type + public void test0296() { + this.runNegativeTest( + new String[] { + "C.java", //--------------------------- + "public class C {\n" + + "\n" + + " void bar() {\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " }\n" + + "}\n", + "B.java", //--------------------------- + "public class B{\n" + + " X get(B bx) { return null; }\n" + + " static B> start() { return null; }\n" + + "}", + "D.java", //--------------------------- + "public class D{}\n", + }, + "----------\n" + + "1. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^^^^^^^^^^^^^\n" + + "The static method start() from the type B should be accessed in a static way\n" + + "----------\n" + + "2. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "3. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^^^^^^^^^^^^^\n" + + "The static method start() from the type B should be accessed in a static way\n" + + "----------\n" + + "4. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "5. ERROR in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^\n" + + "The method get(B) in the type B is not applicable for the arguments (B>)\n" + + "----------\n" + + "6. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^^^^^^^^^^^^^^^\n" + + "The static method start() from the type B should be accessed in a static way\n" + + "----------\n" + + "7. WARNING in C.java (at line 4)\n" + + " new B().start().get(new B().start()).get(new B().start());\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in B.java (at line 3)\n" + + " static B> start() { return null; }\n" + + " ^\n" + + "D is a raw type. References to generic type D should be parameterized\n" + + "----------\n"); + } + public void test0297() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "import java.util.HashMap;\n" + + "import java.util.Iterator;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map map = new HashMap();\n" + + " \n" + + " map.put(\"foo\", \"bar\");\n" + + " \n" + + " // Error reported on the following line\n" + + " Iterator> i = map.entrySet().iterator();\n" + + " while (i.hasNext()) {\n" + + " Map.Entry entry = i.next();\n" + + " System.out.println(entry.getKey() + \", \" + entry.getValue());\n" + + " }\n" + + " }\n" + + "}\n", + }, + "foo, bar"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72644 + public void test0298() { + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X implements Map {\n" + + " private Map backingMap;\n" + + " public int size() { return 0; }\n" + + " public boolean isEmpty() { return false; }\n" + + " public boolean containsKey(Object key) { return false; }\n" + + " public boolean containsValue(Object value) { return false; }\n" + + " public V get(Object key) { return null; }\n" + + " public V put(String key, V value) { return null; }\n" + + " public V remove(Object key) { return null; }\n" + + " public void clear() { }\n" + + " public Set keySet() { return null; }\n" + + " public Collection values() { return null; }\n" + + " public void putAll(Map t) { }\n" + + " public Set> entrySet() {\n" + + " return this.backingMap.entrySet();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X implements Map {\n" + + " ^\n" + + "The type X must implement the inherited abstract method Map.putAll(Map)\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " public void putAll(Map t) { }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method putAll(Map) of type X has the same erasure as putAll(Map) of type Map but does not override it\n" + + "----------\n"); + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public abstract class X implements java.util.Map {\n" + + " public void putAll(java.util.Map t) { }\n" + + "}\n", + }, + ""); + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "public abstract class X implements java.util.Map {\n" + + " public void putAll(java.util.Map t) { }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void putAll(java.util.Map t) { }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method putAll(Map) of type X has the same erasure as putAll(Map) of type Map but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74244 + public void test0299() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(Boolean.class == boolean.class ? \"FAILED\" : \"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74119 + public void test0300() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " static interface I extends Visitible {\n" + + " }\n" + + " static interface Visitible {\n" + + " void acceptVisitor(Visitor visitor);\n" + + " }\n" + + " static interface Visitor {\n" + + " void visit(T t);\n" + + " }\n" + + " static class C implements I {\n" + + " public void acceptVisitor(Visitor visitor) {\n" + + " visitor.visit(this); // should be ok\n" + + " visitor.visit((I) this); // (2) This is a workaround\n" + + " }\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74320: check no complaint for unused private method + public void test0301() { + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "import java.util.List;\n" + + "public class X {\n" + + " public static void reverse(List list) { \n" + + " rev(list);\n" + + " }\n" + + " private static void rev(List list) {\n" + + " }\n" + + " Zork foo() {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Zork foo() {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74514 + public void test0302() { + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "import java.util.ArrayList;\n" + + "import java.util.Enumeration;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public void test02() {\n" + + " List l= new ArrayList();\n" + + " for (Iterator i= l.iterator(); i.next(); ) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " for (Iterator i= l.iterator(); i.next(); ) {\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from String to boolean\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74544 + public void test0303() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Y ys = new Y();\n" + + " Y.Member m = ys.new Member();\n" + + " m.foo();\n" + + " } \n" + + " }\n" + + " class Y {\n" + + " class Member {\n" + + " void foo(){\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " }\n" + + "\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74592 + public void test0304() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {}\n" + + "class Y extends X {}" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74420 + public void test0305() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " T x;\n" + + " T foo(U u) { return u; }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74096 + public void test0306() { + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "public class X> {\n" + + " static int CONSTANT = 1;\n" + + " private int i = 1;\n" + + " private int i() {return i;}\n" + + " private static class M { private static int j = 2; }\n" + + " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + + " public int foo2(T t) { return T.CONSTANT; }\n" + // why is this allowed? + "}\n" + + "class Y extends Zork {\n" + + "}\n" + }, + this.complianceLevel <= ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + + " ^\n" + + "Read access to enclosing field X.M.j is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " class Y extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + // 5: operator + cannot be applied to int,.j + // 5: incompatible type, found : , required: int + : + + // 1.7+ output, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + + " ^\n" + + "The field X.i is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + + " ^\n" + + "The method i() from the type X is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + + " ^^^\n" + + "The type T.M is not visible\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " class Y extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72583 + public void test0307() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " static T foo(T t1, T t2){ return t1; }\n" + + " public static void main(String[] args) {\n" + + " IX s = null;\n" + + " foo(new Object(), s);\n" + + " }\n" + + "}\n" + + "interface IX {}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73696 + public void test0308() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " class Member {}\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " p.X.Member m;\n" + + " p.X.Member ms = m;\n" + + "}\n" + }); + } + public void test0309() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " class Member {\n" + + " class Sub {}\n" + + " }\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " p.X.Member.Sub s;\n" + + " p.X.Member.Sub es = s;\n" + + "}\n" + }); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75156 - should report name clash + public void test0310() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X extends X2 {\n" + + " void foo(List lx) { }\n" + + "}\n" + + "\n" + + "abstract class X2 {\n" + + " void foo(List lo) { }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo(List lx) { }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(List) of type X has the same erasure as foo(List) of type X2 but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75156 variation - should report name clash and ambiguity + public void test0311() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X extends X2 {\n" + + " void foo(List lx) { }\n" + + " void bar(){\n" + + " this.foo((List)null);\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class X2 {\n" + + " void foo(List lo) { }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo(List lx) { }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(List) of type X has the same erasure as foo(List) of type X2 but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " this.foo((List)null);\n" + + " ^^^\n" + + "The method foo(List) is ambiguous for the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " this.foo((List)null);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); + } + // 75156 variation - should report name clash instead of final method override + public void test0312() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X extends X2 {\n" + + " void foo(List lx) { }\n" + + "}\n" + + "\n" + + "abstract class X2 {\n" + + " final void foo(List lo) { }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo(List lx) { }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(List) of type X has the same erasure as foo(List) of type X2 but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=73963 + public void test0313() { + this.runConformTest( + new String[] { + "X.java", + "import java.net.Inet6Address;\n" + + "import java.net.InetAddress;\n" + + "import java.util.AbstractList;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "void takeAbstract(AbstractList arg) { }\n" + + "\n" + + "void takeList(List arg) { }\n" + + "\n" + + "void construct() {\n" + + " AbstractList a= new ArrayList();\n" + + " takeAbstract(a);\n" + + " takeAbstract(new ArrayList()); // a inlined: error 1:\n" + + "//The method takeAbstract(AbstractList) in the type A\n" + + "// is not applicable for the arguments (ArrayList)\n" + + " \n" + + " List l= new ArrayList();\n" + + " takeList(l);\n" + + " takeList(new ArrayList()); // l inlined: ok\n" + + " \n" + + " ArrayList aw= new ArrayList();\n" + + " takeAbstract(aw);\n" + + " takeAbstract(new ArrayList()); // aw inlined: error 2:\n" + + "//The method takeAbstract(AbstractList) in the type A\n" + + "// is not applicable for the arguments (ArrayList)\n" + + "\n" + + " takeList(aw);\n" + + " takeList(new ArrayList()); //aw inlined: ok\n" + + "}\n" + + "}" + }, + ""); + } + public void test0314() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class XMember {}\n" + + "\n" + + " // with toplevel element type\n" + + " void foo() {\n" + + " XIter> iter = fooSet().iterator();\n" + + " }\n" + + " XSet> fooSet() { return null; }\n" + + "\n" + + " // with member element type\n" + + " void bar() {\n" + + " XIter> iter = barSet().iterator();\n" + + " }\n" + + " XSet> barSet() { return null; }\n" + + "\n" + + " \n" + + "}\n" + + "\n" + + "class XSet {\n" + + " XIter iterator() { return null; }\n" + + "}\n" + + "class XIter {\n" + + "}\n" + + "class XElement {\n" + + "}\n" + }, + ""); + } + public void test0315() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class XMember {}\n" + + "\n" + + " // with member element type\n" + + " void bar() {\n" + + " XIter> iter = barSet().iterator();\n" + + " }\n" + + " XSet> barSet() { return null; }\n" + + "\n" + + " \n" + + "}\n" + + "\n" + + "class XSet {\n" + + " XIter iterator() { return null; }\n" + + "}\n" + + "class XIter {\n" + + "}\n" + + "class XElement {\n" + + "}\n" + }, + ""); + } + public void test0316() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " \n" + + " E element() { return null; }\n" + + " \n" + + " void bar(X xe) {\n" + + " xe.element().add(this);\n" + + " xe.element().run();\n" + + " }\n" + + " void foo(X xe) {\n" + + " xe.element().add(this);\n" + + " xe.element().run();\n" + + " }\n" + + " void baz(X xe) {\n" + + " xe.element().add(this);\n" + + " xe.element().run();\n" + + " }\n" + + " abstract class XM implements List, Runnable {}\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " xe.element().add(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " xe.element().add(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 16)\n" + + " xe.element().add(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 19)\n" + + " abstract class XM implements List, Runnable {}\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 20)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0317() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " \n" + + " E element() { return null; }\n" + + " \n" + + " void foo(X xe) {\n" + + " xe.element().add(this);\n" + + " xe.element().run();\n" + + " }\n" + + " void baz(X xe) {\n" + + " xe.element().add(this);\n" + + " xe.element().run();\n" + + " }\n" + + " interface XI extends Runnable {}\n" + + " \n" + + " class XM {\n" + + " void foo() {}\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " xe.element().add(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " xe.element().add(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75548 + public void test0318() { + this.runConformTest( + new String[] { + "MyCache.java", + "class Cache {\n" + + "}\n" + + "\n" + + "class Index {\n" + + " public Index(Cache parentCache) {\n" + + " }\n" + + "}\n" + + "\n" + + "public class MyCache extends Cache {\n" + + " class AnIndex extends Index {\n" + + " public AnIndex() {\n" + + " super(MyCache.this); // <-- Eclipse cannot find the constructor!\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76729 + public void test0319() { + this.runConformTest( + new String[] { + "test/Test1.java", + "package test;\n" + + "\n" + + "class A\n" + + "{}\n" + + "\n" + + "class B\n" + + "{}\n" + + "\n" + + "public interface Test1, D extends A>\n" + + "{}\n" + + "\n" + + "class AbstractA extends A {};\n" + + "class AbstractB extends B {};\n" + + "\n" + + "class Test2 implements Test1\n" + + "{}" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74032 + public void test0320() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "class TestElement extends ArrayList implements Runnable {\n" + + " public void run() {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public X(E element) {\n" + + " element.run();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new TestElement());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74032 - variation with wildcard + public void test0321() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "class TestElement extends ArrayList implements Runnable {\n" + + " static final long serialVersionUID = 1l;\n" + + " public void run() {\n" + + " // empty\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " E element;\n" + + " public X(E element) {\n" + + " this.element = element;\n" + + " element.run();\n" + + " }\n" + + " public X(X x) {\n" + + " x.element.run();\n" + // should be able to bind to #run() + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new TestElement());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75134 + public void test0322() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + "\n" + + " A v2;\n" + + " X(A a) { v2 = a; }\n" + + " \n" + + " void func() {\n" + + " List> l = new ArrayList>();\n" + + " }\n" + + "\n" + + " class B {\n" + + " T v1;\n" + + " B(T b) { v1 = b; }\n" + + " }\n" + + " \n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76359 - also check warnings for raw conversion + public void test0323() { + this.runNegativeTest( + new String[] { + "X.java", + "class G {\n" + + " class Member {}\n" + + "}\n" + + "public class X {\n" + + " G g = new G();\n" + + " G.Member gsm = g.new Member();\n" + + " G.Member gm = null;\n" + + " G.Member gtm = gm;\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " G g = new G();\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type G needs unchecked conversion to conform to G\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " G g = new G();\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " G.Member gm = null;\n" + + " ^^^^^^^^\n" + + "G.Member is a raw type. References to generic type G.Member should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " G.Member gtm = gm;\n" + + " ^^\n" + + "Type safety: The expression of type G.Member needs unchecked conversion to conform to G.Member\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=72998 + public void test0324() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + " private TreeNode root;\n" + + "\n" + + " public void doSomething() {\n" + + " for (TreeNode child : root.children()) {\n" + + " // root.children() should work??\n" + + " }\n" + + " }\n" + + "\n" + + " public void doSomethingElse() {\n" + + " for (Iterator> it = root.children().iterator(); it.hasNext();) {\n" + + " // this also should work\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class TreeNode {\n" + + " private Set> children;\n" + + " \n" + + " public Set> children() {\n" + + " return children;\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0325() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo1() {\n" + + " X.Item i = new X().new Item();\n" + + " }\n" + + " void foo2() {\n" + + " X.Item j = new X.Item();\n" + // allowed per grammar + " }\n" + + " void foo3() {\n" + + " X.Item k = new X.Item();\n" + + " }\n" + + " static void foo4() {\n" + + " X.Item k = new X.Item();\n" + + " }\n" + + " class Item {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X.Item i = new X().new Item();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Item to X.Item\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X.Item j = new X.Item();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot allocate the member type X.Item using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " X.Item k = new X.Item();\n" + + " ^^^^^^\n" + + "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " X.Item k = new X.Item();\n" + + " ^^^^^^\n" + + "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " X.Item k = new X.Item();\n" + + " ^^^^^^\n" + + "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " X.Item k = new X.Item();\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" + + "7. WARNING in X.java (at line 12)\n" + + " X.Item k = new X.Item();\n" + + " ^^^^^^\n" + + "X.Item is a raw type. References to generic type X.Item should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75400 + public void test0326() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {\n" + + " public I.A foo() {\n" + + " return a;\n" + + " }\n" + + "} \n" + + "interface I {\n" + + " A a = new A();\n" + + " class A {\n" + + " }\n" + + "}\n" + + "\n" + + "class XM {\n" + + " A a = new A();\n" + + " class A {\n" + + " }\n" + + "} \n" + + "\n" + + "class XMSub extends XM {\n" + + " public XM.A foo() {\n" + + " return a;\n" + + " }\n" + + "} \n" + + "\n" + }, + ""); + } + // wildcard captures bound and variable superinterfaces + public void test0327() { + this.runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " \n" + + " T element() { return null; }\n" + + " void baz(X x) {\n" + + " x.element().foo();\n" + + " x.element().bar();\n" + + " }\n" + + "}\n" + + "interface IFoo {\n" + + " void foo();\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + // wildcard captures bound and variable superinterfaces + public void test0328() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { \n" + + " this.element = element; \n" + + " }\n" + + " static void baz(X x) {\n" + + " x.element.foo();\n" + + " x.element.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x1 = new X(new Foo());\n" + + " baz(x1);\n" + + " X x2 = new X(new Bar());\n" + + " baz(x2);\n" + + " X x3 = new X(new FooBar());\n" + + " baz(x3);\n" + + " }\n" + + "}\n" + + "interface IFoo {\n" + + " void foo();\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "class Foo implements IFoo {\n" + + " public void foo() {\n" + + " System.out.print(\"FOO\");\n" + + " }\n" + + "}\n" + + "class Bar implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n" + + "class FooBar extends Foo implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " baz(x1);\n" + + " ^^^\n" + + "The method baz(X) in the type X is not applicable for the arguments (X)\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " X x2 = new X(new Bar());\n" + + " ^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " X x2 = new X(new Bar());\n" + + " ^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n"); + } + // wildcard captures bound and variable superinterfaces + public void test0329() { + this.runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { \n" + + " this.element = element; \n" + + " }\n" + + " static void baz(X x) {\n" + + " x.element.foo();\n" + + " x.element.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x3 = new X(new FooBar());\n" + + " baz(x3);\n" + + " }\n" + + "}\n" + + "interface IFoo {\n" + + " void foo();\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "class FooBar implements IFoo, IBar {\n" + + " public void foo() {\n" + + " System.out.print(\"FOO\");\n" + + " }\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "FOOBAR" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + // wildcard captures bound superclass and variable superclass + public void test0330() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { \n" + + " this.element = element; \n" + + " }\n" + + " static void baz(X x) {\n" + + " x.element.foo();\n" + + " x.element.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x3 = new X(new FooBar());\n" + + " baz(x3);\n" + + " }\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "class Foo {\n" + + " public void foo() {\n" + + " System.out.print(\"FOO\");\n" + + " }\n" + + "}\n" + + "class FooBar extends Foo implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n", + }, + "FOOBAR"); + } + // wildcard captures bound superclass and variable superclass + public void test0331() { + this.runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { \n" + + " this.element = element; \n" + + " }\n" + + " static void baz(X x) {\n" + + " x.element.foo();\n" + + " x.element.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x3 = new X(new FooBar());\n" + + " baz(x3);\n" + + " }\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "class Foo {\n" + + " public void foo() {\n" + + " System.out.print(\"FOO\");\n" + + " }\n" + + "}\n" + + "class FooBar extends Foo implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "FOOBAR" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + // wildcard considers bound superclass or variable superclass + public void test0332() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { \n" + + " this.element = element; \n" + + " }\n" + + " static void baz(X x) {\n" + // captures Foo & IBar + " x.element.foo();\n" + + " x.element.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " baz(new X(new FooBar()));\n" + + " baz(new X(new Bar()));\n" + + " }\n" + + "}\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "\n" + + "class Bar implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n" + + "\n" + + "class Foo {\n" + + " public void foo() {\n" + + " System.out.print(\"FOO\");\n" + + " }\n" + + "}\n" + + "\n" + + "class FooBar extends Foo implements IBar {\n" + + " public void bar() {\n" + + " System.out.print(\"BAR\");\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " baz(new X(new Bar()));\n" + + " ^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n"); + } + // receveir generic cast matches receiver type (not declaring class) + public void test0333() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " X(T element) { this.element = element; }\n" + + " T element() { return this.element; }\n" + + " public static void main(String[] args) {\n" + + " new X(new XB()).element().afoo();\n" + + " }\n" + + "}\n" + + "\n" + + "class XA {\n" + + " void afoo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class XB extends XA {\n" + + " void bfoo() {}\n" + + "}\n" , + }, + "SUCCESS"); + } + // check cannot allocate type parameters + public void test0334() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X() {\n" + + " new E();\n" + + " new E() {\n" + + " void perform() {\n" + + " run();\n" + + " }\n" + + " }.perform();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new E();\n" + + " ^\n" + + "Cannot instantiate the type E\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " new E() {\n" + + " void perform() {\n" + + " run();\n" + + " }\n" + + " }.perform();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot refer to the type parameter E as a supertype\n" + + "----------\n"); + } + // variation - check cannot allocate type parameters + public void test0335() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + // firstBound is class, still cannot be instantiated + " public X() {\n" + + " new E();\n" + + " new E() {\n" + + " void perform() {\n" + + " run();\n" + + " }\n" + + " }.perform();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^\n" + + "The type parameter E should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " new E();\n" + + " ^\n" + + "Cannot instantiate the type E\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " new E() {\n" + + " void perform() {\n" + + " run();\n" + + " }\n" + + " }.perform();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot refer to the type parameter E as a supertype\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74669 + public void test0336() { + this.runNegativeTest( + new String[] { + "X.java", + "interface IMyInterface {\n" + + "}\n" + + "class MyClass {\n" + + "\n" + + " public Type myMethod(Object obj, Class type) {\n" + + " return null;\n" + + " }\n" + + " public static Type myStaticMethod(Object obj, Class type) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public IMyInterface getThis() {\n" + + " if (true)\n" + + " return new MyClass().myMethod(this, IMyInterface.class);\n" + + " else\n" + + " return MyClass.myStaticMethod(this, IMyInterface.class);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public Type myMethod(Object obj, Class type) {\n" + + " ^^^^\n" + + "The type parameter Type is hiding the type Type\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " public Type myMethod(Object obj, Class type) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " public static Type myStaticMethod(Object obj, Class type) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " return new MyClass().myMethod(this, IMyInterface.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to IMyInterface\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " return new MyClass().myMethod(this, IMyInterface.class);\n" + + " ^^^^^^^\n" + + "MyClass is a raw type. References to generic type MyClass should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77078 + public void test0337() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " public void foo() {\n" + + " Vector objectVector = new Vector() {\n" + + " protected void bar() {\n" + + " baz(this); /* ERROR */\n" + + " }\n" + + " };\n" + + " baz(objectVector);\n" + + " baz(new Vector());\n" + + " }\n" + + " public void baz(Vector mysteryVector) { }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77052 + public void test0338() { + this.runConformTest( + new String[] { + "X.java", + "interface M { }\n" + + "\n" + + "class N { \n" + + " M> pni = null;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " N var1 = null;\n" + + "\n" + + " M> var2 = var1.pni;\n" + + " // Above line reports as error in Eclipse. \n" + + " // \"var2\" is underlined and the error message is: \n" + + " // Type mismatch: cannot convert from M> to M>\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77052 - variation + public void test0339() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.Set;\n" + + "\n" + + "class X {\n" + + " static class Entry {}\n" + + " void foo() {\n" + + " Iterator> i = entrySet().iterator();\n" + + " }\n" + + " Set> entrySet() { return null; }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76313 + public void test0340() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private T data;\n" + + " private X(T data){ this.data=data; }\n" + + " public static X createObject(S data){\n" + + " System.out.println(data);\n" + + " return new X(data);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X res=X.createObject(\"Hallo\");\n" + + " }\n" + + "}\n", + }, + "Hallo"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77118 + public void test0341() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public Object getItem() { return null; }\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " public String getItem() { return null; }\n" + + "}\n", + "Z.java", + "public class Z extends X {\n" + + " public Comparable getItem() { return null; }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77142 - check no raw unsafe warning is issued when accessing generic method from raw type + public void test0342() { + this.runNegativeTest( + new String[] { + "Test.java", + "class MyClass {\n" + + " \n" + + " private T thing;\n" + + " { Zork z; }\n" + + " \n" + + " public\n" + + " MyClass(T thing) {\n" + + " this.thing = thing;\n" + + " }\n" + + " \n" + + " public static MyClass\n" + + " factoryMakeMyClass(U thing) {\n" + + " return new MyClass(thing);\n" + + " }\n" + + "}\n" + + "\n" + + "class External {\n" + + "\n" + + " public static MyClass\n" + + " factoryMakeMyClass(U thing) {\n" + + " return new MyClass(thing);\n" + + " }\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " public static void\n" + + " test()\n" + + " {\n" + + " // No problem with this line:\n" + + " MyClass foo = External.factoryMakeMyClass(\"hi\");\n" + + " \n" + + " // This line gives me an error:\n" + + " // Type mismatch: cannot convert from MyClass to MyClass\n" + + " MyClass bar = MyClass.factoryMakeMyClass(\"hi\");\n" + + " MyClass bar2 = MyClass.factoryMakeMyClass(\"hi\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Test.java (at line 4)\n" + + " { Zork z; }\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74588 + public void test0343() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T m;\n" + + "\n" + + " class Y {\n" + + " void test() {\n" + + " new Y() {\n" + + " void test() {\n" + + " System.out.println(X.this.m);\n" + + " }\n" + + " }.test();\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", + }, + ""); + } + // checking scenario where generic type and method share the same type parameter name + public void test0344() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public abstract class X {\n" + + " \n" + + " public abstract T bar(T t);\n" + + "\n" + + " static void foo(X x) {\n" + + " x.bar(null);\n" + + " \n" + + " class R implements Runnable {\n" + + " public void run() {\n" + + " }\n" + + " }\n" + + " X xr = new X(){ \n" + + " public T bar(T t) { \n" + + " return t; \n" + + " }\n" + + " };\n" + + " IOException e = xr.bar(new IOException());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract T bar(T t);\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " static void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " x.bar(null);\n" + + " ^^^\n" + + "The method bar(Exception) of raw type X is no longer generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " X xr = new X(){ \n" + + " ^^^^^^\n" + + "The type new X(){} must implement the inherited abstract method X.bar(T)\n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public abstract class X {\n" + + " \n" + + " public abstract T bar(T t);\n" + + "\n" + + " static void foo(X x) {\n" + + " x.bar(null);\n" + + " \n" + + " class R implements Runnable {\n" + + " public void run() {\n" + + " }\n" + + " }\n" + + " X xr = new X(){ \n" + + " public T bar(T t) { \n" + + " return t; \n" + + " }\n" + + " };\n" + + " IOException e = xr.bar(new IOException());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract T bar(T t);\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " static void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " x.bar(null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method bar(Exception) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " X xr = new X(){ \n" + + " ^^^^^^\n" + + "The type new X(){} must implement the inherited abstract method X.bar(T)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594 + public void test0345() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " X1 o1 = new X1();\n" + + " ((J)o1).get();\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 implements I {\n" + + " public X1 get() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return this;\n" + + " }\n" + + "}\n" + + "\n" + + "interface I extends J {\n" + + " I get();\n" + + "}\n" + + "\n" + + "interface J {\n" + + " J get();\n" + + "}", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594 + public void test0346() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " X1 o1 = new X1(new Integer(4));\n" + + " System.out.println(o1.get().t);\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 implements I {\n" + + " T t;\n" + + " X1(T arg) {\n" + + " t = arg;\n" + + " }\n" + + " public X1 get() {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "\n" + + "interface I extends J {\n" + + " I get();\n" + + "}\n" + + "\n" + + "interface J {\n" + + " J get();\n" + + "}" + , + }, + "4"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74594 + public void test0347() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " X1 o = new X1(new Integer(4));\n" + + " System.out.println(o.get().t);\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 implements I {\n" + + " T t;\n" + + " X1(T arg) {\n" + + " t = arg;\n" + + " }\n" + + " public X1 get() {\n" + + " return this;\n" + + " }\n" + + "} \n" + + "\n" + + "interface I extends K, L {\n" + + " I get();\n" + + "}\n" + + "\n" + + "interface J {\n" + + " J get();\n" + + "}\n" + + "\n" + + "interface K extends J {\n" + + "}\n" + + "\n" + + "interface L {\n" + + " K get();\n" + + "}", + }, + "4"); + } + // checking scenario where generic type and method share the same type parameter name + public void test0348() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public abstract class X {\n" + + " public abstract T bar(T t);\n" + + " static void foo(X x) {\n" + + " x.bar(null);\n" + + " class R implements Runnable {\n" + + " public void run() {}\n" + + " }\n" + + " X xr = new X(){ \n" + + " public T bar(T t) { return t; }\n" + + " };\n" + + " IOException e = xr.bar(new IOException());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public abstract T bar(T t);\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " static void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " x.bar(null);\n" + + " ^^^\n" + + "The method bar(Exception) of raw type X is no longer generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " public T bar(T t) { return t; }\n" + + " ^^^^^^^^\n" + + "The method bar(T) of type new X(){} should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236242); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public abstract class X {\n" + + " public abstract T bar(T t);\n" + + " static void foo(X x) {\n" + + " x.bar(null);\n" + + " class R implements Runnable {\n" + + " public void run() { zork = 0; }\n" + + " }\n" + + " X xr = new X(){ \n" + + " public T bar(T t) { return t; }\n" + + " };\n" + + " IOException e = xr.bar(new IOException());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public abstract T bar(T t);\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " static void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " x.bar(null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method bar(Exception) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public void run() { zork = 0; }\n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " public T bar(T t) { return t; }\n" + + " ^^^^^^^^\n" + + "The method bar(T) of type new X(){} should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236242); + } + // test wildcard compatibilities + public void test0349() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " static void foo(X out, X1 in) {\n" + + " out.element = in.element;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class X1{\n" + + " U element;\n" + + "}\n", + }, + "SUCCESS"); + } + // test wildcard compatibilities + public void test0350() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " static void foo(X out, X1 in) {\n" + + " out.element = in.element;\n" + + " }\n" + + "}\n" + + "class X1{\n" + + " U element;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " out.element = in.element;\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? to capture#1-of ?\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75328 + public void test0351() { + this.runConformTest( + new String[] { + "X.java", + "interface Intf, I extends Comparable> { \n" + + " public void f(Intf val);\n" + + "}\n" + + "\n" + + "public class X , P extends Comparable> implements Intf {\n" + + "\n" + + " public void f(Intf val) { } \n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77051 + public void test0352() { + this.runConformTest( + new String[] { + "X.java", + "interface C { }\n" + + "interface PC extends C { } \n" + + "interface PO { \n" + + " C proc1();\n" + + " C proc2();\n" + + " C proc3();\n" + + "}\n" + + "abstract class X implements PO {\n" + + " public C proc1() { return result1; }\n" + + " private final PC result1 = null;\n" + + " public C proc2() { return result2; }\n" + + " private final PC result2 = null;\n" + + " public C proc3() { return result3; }\n" + + " private final PC result3 = null;\n" + + "}\n", + }, + ""); + } + public void test0353() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " T foo(Class c) { return null; }\n" + + "}\n" + + "class Y {\n" + + " T foo(Class c) { return null; }\n" + + "}" + }, + ""); + } + public void test0354() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " S foo(Class c) { return null; }\n" + + "}\n" + + "class Y {\n" + + " T foo(Class c) { return null; }\n" + + "}" + }, + ""); + } + public void test0355() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " S foo(Class c) { return null; }\n" + + "}\n" + + "class Y {\n" + + " S foo(Class c) { return null; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " S foo(Class c) { return null; }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + + "----------\n"); + } + public void test0356() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " T foo(Class c) { return null; }\n" + + "}\n" + + "class Y {\n" + + " T foo(Class c) { return null; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T foo(Class c) { return null; }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + + "----------\n"); + } + public void test0357() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " T foo(Class c) { return null; }\n" + + "}\n" + + "class Y {\n" + + " T foo(Class c) { return null; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T foo(Class c) { return null; }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76720 + public void test0358() { + this.runConformTest( + new String[] { + "MyClass.java", + "public class MyClass {}\n", + "A.java", + "public interface A {}\n", + "B.java", + "public interface B extends A {}\n", + "C.java", + "public class C implements B {}\n", // compile against sources + "D.java", + "public class D implements A{}\n", // compile against sources + }, + ""); + // compile against generated binaries + this.runConformTest( + new String[] { + "C.java", + "public class C implements B {}\n", + "D.java", + "public class D implements A{}\n", + }, + "", + null, + false, + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76790 + public void test0359() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " class List1 extends LinkedList {};\n" + + " public static void main (String[] args) {\n" + + " Map> x = new HashMap>();\n" + + " Map> m = new HashMap>();\n" + + " }\n" + + "}" + } + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76786 + public void test0360() { + this.runConformTest( + new String[] { + "Test.java", + "import java.lang.Comparable;\n" + + "public class Test {\n" + + " private static final class X implements Comparable> {\n" + + " public int compareTo(X arg0) { return 0; }\n" + + " };\n" + + " private static class Y {};\n" + + " private static final class Z extends Y implements Comparable> {\n" + + " public int compareTo(Z arg0) { return 0; }\n" + + " };\n" + + " public static void doSomething(Comparable a, Comparable b) {}\n" + + " public static void doSomethingElse(Z a, Z b) {\n" + + " doSomething(a, b);\n" + + " }\n" + + " private static final class W { };\n" + + " public static void main(String[] args) {\n" + + " doSomething(new X(), new X());\n" + + " doSomething(new Z(), new Z());\n" + + " doSomethingElse(new Z(), new Z());\n" + + " doSomethingElse(new Z(), new Z());\n" + + " // The next line won\'t compile. It\'s the generic, String>(), new Z, String>());\n" + + " }\n" + + "}" + } + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75525 + public void test0361() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.AbstractSet;\n" + + "import java.util.Iterator;\n" + + "import java.util.Map.Entry;\n" + + "public class Test extends AbstractSet> {\n" + + " public Iterator> iterator() {\n" + + " return new Iterator>() {\n" + + " public boolean hasNext() {return false;}\n" + + " public Entry next() {return null;}\n" + + " public void remove() {} \n" + + " };\n" + + " }\n" + + " public int size() {return 0;}\n" + + "}" + } + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72643 + public void test0362() { + Map customOptions= getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Test {\n" + + " public void a() {\n" + + " List list1 = new ArrayList();\n" + + " List list2 = new ArrayList();\n" + + " compare(list1, list2);\n" + + " }\n" + + " private void compare(List list1, List list2) {\n" + + " // do some comparing logic...\n" + + " }\n" + + "}\n" + + "\n" + }, + "", + null, + true, + null, + customOptions, + null/*no custom requestor*/); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76434 + public void test0363() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "public class X {\n" + + " Set> m_values;\n" + + " X(Map values) {\n" + + " m_values = values.entrySet();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " m_values = values.entrySet();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Set> to Set>\n" + + "----------\n"); + } + // check param type equivalences + public void test0364() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " \n" + + " void bar1(MX> mxcs, MX> mxco) {\n" + + " mxco = mxcs;\n" + // wrong + " }\n" + + " void bar1(Class cs, Class co) {\n" + + " co = cs;\n" + // ok + " }\n" + + " \n" + + "}\n" + + "class MX {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " mxco = mxcs;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n"); + } + // check param type equivalences + public void test0365() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " class MX {\n" + + " }\n" + + " \n" + + " MX createMX() { return new MX(); }\n" + + "\n" + + " void foo(X x, MX mx) {\n" + + " mx = x.createMX();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " mx = x.createMX();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.MX to X.MX\n" + + "----------\n"); + } + // check param type equivalences + public void test0366() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " \n" + + " void foo1(MX> target, MX value) {\n" + + " target= value; // foo1 - wrong\n" + + " }\n" + + " void foo2(MX> target, MX> value) {\n" + + " target= value; // foo2 - wrong\n" + + " }\n" + + " void foo3(MX> target, MX> value) {\n" + + " target= value; // foo3 - wrong\n" + + " }\n" + + " void foo4(MX> target, MX> value) {\n" + + " target= value; // foo4 - wrong\n" + + " }\n" + + " void foo5(MX target, MX value) {\n" + + " target= value; // foo5\n" + + " }\n" + + " void foo6(MX target, MX value) {\n" + + " target= value; // foo6\n" + + " }\n" + + " void foo7(MX> target, MX> value) {\n" + + " target= value; // foo7 - wrong\n" + + " }\n" + + " void foo8(MX> target, MX> value) {\n" + + " target= value; // foo8 - wrong\n" + + " }\n" + + " void foo9(MX target, MX value) {\n" + + " target= value; // foo9\n" + + " }\n" + + " void foo10(MX target, MX value) {\n" + + " target= value; // foo10 - wrong\n" + + " }\n" + + " void foo11(MX target, MX value) {\n" + + " target= value; // foo11 - wrong\n" + + " }\n" + + " void foo12(MX target, MX value) {\n" + + " target= value; // foo12\n" + + " }\n" + + "}\n" + + "\n" + + "class MX {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo1(MX> target, MX value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " target= value; // foo1 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX to MX>\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " target= value; // foo2 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " target= value; // foo3 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " target= value; // foo4 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "6. WARNING in X.java (at line 15)\n" + + " void foo5(MX target, MX value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 15)\n" + + " void foo5(MX target, MX value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 18)\n" + + " void foo6(MX target, MX value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 18)\n" + + " void foo6(MX target, MX value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "10. WARNING in X.java (at line 21)\n" + + " void foo7(MX> target, MX> value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 21)\n" + + " void foo7(MX> target, MX> value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "12. ERROR in X.java (at line 22)\n" + + " target= value; // foo7 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "13. WARNING in X.java (at line 24)\n" + + " void foo8(MX> target, MX> value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "14. WARNING in X.java (at line 24)\n" + + " void foo8(MX> target, MX> value) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "15. ERROR in X.java (at line 25)\n" + + " target= value; // foo8 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX>\n" + + "----------\n" + + "16. ERROR in X.java (at line 31)\n" + + " target= value; // foo10 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX to MX\n" + + "----------\n" + + "17. ERROR in X.java (at line 34)\n" + + " target= value; // foo11 - wrong\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX to MX\n" + + "----------\n"); + } + // check param type equivalences + public void test0367() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " \n" + + " void foo1(MX target, MX> value) {\n" + + " target= value; // foo1\n" + + " }\n" + + " void foo2(MX target, MX> value) {\n" + + " target= value; // foo2\n" + + " }\n" + + " void foo3(MX target, MX> value) {\n" + + " target= value; // foo3\n" + + " }\n" + + "}\n" + + "\n" + + "class MX {\n" + + "}\n" , + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo1(MX target, MX> value) {\n" + + " ^^\n" + + "MX is a raw type. References to generic type MX should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " void foo3(MX target, MX> value) {\n" + + " ^^\n" + + "MX is a raw type. References to generic type MX should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " target= value; // foo3\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from MX> to MX\n" + + "----------\n"); + } + // check param type equivalences + public void test0368() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " static class MX {\n" + + " }\n" + + " \n" + + " MX createMX() { return new MX(); }\n" + + "\n" + + " void foo(X x, MX mx) {\n" + + " mx = x.createMX();\n" + + " }\n" + + "}\n" , + }, + ""); + } + // bound check for Enum + public void test0369() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " > T foo(T t) { return null; }\n" + + "}\n", + }, + ""); + } + // decoding raw binary type + public void test0370() { + this.runConformTest( + new String[] { + "p/B.java", + "package p;\n" + + "import java.util.Map;\n" + + "public class B {\n" + + " public static Map foo(byte[] byteArray, Object o, Class c) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + ""); + + this.runConformTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "import p.B;\n" + + "\n" + + "public class X {\n" + + " {\n" + + " Map map = B.foo(null, null, null);\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null); + } + // X is not compatible with X + public void test0371() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(XC target, XC value) {\n" + + " target = value;\n" + + " }\n" + + "}\n" + + "class XC {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " target = value;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from XC to XC\n" + + "----------\n"); + } + public void test0372() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void foo(Iterator> iter) {\n" + + " new XA.MXA(iter.next());\n" + + " }\n" + + "}\n" + + "class XA {\n" + + " static class MXA implements Entry {\n" + + " MXA(Entry e) {\n" + + " }\n" + + " public K getKey() {\n" + + " return null;\n" + + " }\n" + + " public V getValue() {\n" + + " return null;\n" + + " }\n" + + " public V setValue(V value) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" , + }, + ""); + } + public void test0373() { + this.runConformTest( + new String[] { + "XA.java", + "import java.util.Map.Entry;\n" + + "\n" + + "public class XA {\n" + + " static class MXA implements Entry {\n" + + " MXA(Entry e) {\n" + + " }\n" + + " public K getKey() {\n" + + " return null;\n" + + " }\n" + + " public V getValue() {\n" + + " return null;\n" + + " }\n" + + " public V setValue(V value) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" , + }, + ""); + // compile against binaries + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void foo(Iterator> iter) {\n" + + " new XA.MXA(iter.next());\n" + + " }\n" + + "}\n" , + }, + "", + null, + false, + null); + } + // wildcard with no upper bound uses type variable as upper bound + public void test0374() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo1(X target, X value) {\n" + + " target = value; // foo1\n" + + " }\n" + + " void foo2(X target, X value) {\n" + + " target = value; // foo2\n" + + " } \n" + + "}\n", + }, + ""); + } + public void test0375() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo1(X target, X value) {\n" + + " target = value; // foo1\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " target = value; // foo1\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n"); + } + public void test0376() { + this.runConformTest( + new String[] { + "XA.java", + "import java.util.Map.Entry;\n" + + "\n" + + "public class XA {\n" + + " XA self() { return this; } \n" + + " static class MXA implements Entry {\n" + + " MXA(Entry e) {\n" + + " }\n" + + " public K getKey() {\n" + + " return null;\n" + + " }\n" + + " public V getValue() {\n" + + " return null;\n" + + " }\n" + + " public V setValue(V value) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" , + }, + ""); + // compile against binaries + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void foo(Iterator> iter) {\n" + + " new XA.MXA(iter.next());\n" + + " }\n" + + "}\n" , + }, + "", + null, + false, + null); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76601 + public void test0377() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public static void main (String[] args) {\n" + + " final String val = (args == null||args.length==0 ? \"SUCC\" : args[0]) + \"ESS\";\n" + + " class AllegedBoundMismatch> {\n" + + " String field = val;\n" + + " }\n" + + " System.out.println(new Object() {\n" + + " AllegedBoundMismatch> trial = new AllegedBoundMismatch>();\n" + + " }.trial.field);\n" + + " }\n" + + "}\n" + + "class Q {}\n" + + "interface SubI extends SuperI> {}\n" + + "interface SuperI {}" + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76219 + public void test0378() { + this.runConformTest( + new String[] { + "BB.java", + "interface AA> { \n" + + " public boolean m(AA that); \n" + + " public Z z(); \n" + + " public boolean b(); \n" + + "}\n" + + "abstract class BB> implements AA { \n" + + " public boolean m(AA wht) { return wht.z().b(); } \n" + + "}\n"} + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=71612 + public void test0379() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.AbstractSet;\n" + + "import java.util.Iterator;\n" + + "public class Test extends AbstractSet{\n" + + " public static void main(String[] args) {\n" + + " Test t=new Test();\n" + + " t.add(null);\n" + + " }\n" + + " public boolean add(Runnable run) {\n" + + " System.out.println(\"success\");\n" + + " return true;\n" + + " }\n" + + " public Iterator iterator() {return null;}\n" + + " public int size() {return 0;}\n" + + "}" + } + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77327 + public void test0380() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.List;\n" + + "public class Test {\n" + + " List wsn= null; // Contravariance\n" + + " List wsi= wsn; // should work!\n" + + "}\n" + } + ); + } + + public void test0381() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " void foo(Class s) {}\n" + + "}\n" + + "class Y {\n" + + " void foo(Class s) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Class s) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " void foo(Class s) {}\n" + + "}\n" + + "class Y {\n" + + " void foo(Class s) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Class s) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type Y but does not override it\n" + + "----------\n"); + } + public void test0382() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y implements I {}\n" + + "interface I { void foo(Class s); }\n" + + "class Y { void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I {}\n" + + " ^\n" + + "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I {}\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.foo(Class)\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X extends Y implements I {}\n" + + "interface I { void foo(Class s); }\n" + + "class Y { void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public abstract class X extends Y implements I {}\n" + + " ^\n" + + "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n"); + } + public void test0383() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y implements I { public void foo(Class s) {} }\n" + + "interface I { void foo(Class s); }\n" + + "class Y { public void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I { public void foo(Class s) {} }\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.foo(Class)\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I { public void foo(Class s) {} }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n" + + "3. WARNING in X.java (at line 1)\n" + + " public class X extends Y implements I { public void foo(Class s) {} }\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method foo(Class) of type X should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); + /* + X.java:1: X is not abstract and does not override abstract method foo(java.lang.Class) in I + public class X extends Y implements I { public void foo(Class s) {} } + ^ + */ + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y implements I {}\n" + + "interface I { void foo(Class s); }\n" + + "class Y { public void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I {}\n" + + " ^\n" + + "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends Y implements I {}\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.foo(Class)\n" + + "----------\n"); + /* + X.java:1: X is not abstract and does not override abstract method foo(java.lang.Class) in I + public class X extends Y implements I {} + ^ + */ + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X extends Y implements I {}\n" + // NOTE: X is abstract + "interface I { void foo(Class s); }\n" + + "class Y { public void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public abstract class X extends Y implements I {}\n" + + " ^\n" + + "Name clash: The method foo(Class) of type Y has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n"); + /* + X.java:1: name clash: foo(java.lang.Class) in Y and foo(java.lang.Class) in I have the same erasure, yet neither overrides the other + public abstract class X extends Y implements I {} + ^ + */ + } + public void test0384a() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " java.util.List foo3(java.util.List t) { return t; }\n" + + " Class foo4() { return null; }\n" + + " Class[] foo5() { return null; }\n" + + "}\n" + + "class Y {\n" + + " java.util.List foo3(java.util.List t) { return t; }\n" + + " Class foo4() { return null; }\n" + + " Class[] foo5() { return null; }\n" + + "}\n" + }, + ""); + } + public void test0384b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " @Override Class foo() { return null; }\n" + + " @Override Class[] foo2() { return null; }\n" + + "}\n" + + "class Y {\n" + + " Class foo() { return null; }\n" + + " Class[] foo2() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Override Class foo() { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with Y.foo()\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " @Override Class[] foo2() { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with Y.foo2()\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77496 + public void test0385() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface IDoubles { List getList(); }\n" + + "class A implements IDoubles {\n" + + " public List getList() { return null; }\n" + + "}\n" + + "class B {\n" + + " public List getList() { return null; }\n" + + "}\n" + + "class C extends B implements IDoubles {\n" + + " void use() { List l= getList(); }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public List getList() { return null; }\n" + + " ^^^^^^^^^^^^\n" + + "The return type is incompatible with IDoubles.getList()\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " class C extends B implements IDoubles {\n" + + " ^\n" + + "The return types are incompatible for the inherited methods IDoubles.getList(), B.getList()\n" + + "----------\n"); + /* + X.java:3: A is not abstract and does not override abstract method getList() in IDoubles + class A implements IDoubles { + ^ + X.java:4: getList() in A cannot implement getList() in IDoubles; attempting to use incompatible return type + found : java.util.List + required: java.util.List + public List getList() { return null; } + ^ + X.java:9: C is not abstract and does not override abstract method getList() in IDoubles + class C extends B implements IDoubles { + */ + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77325 + public void test0386() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " private U u;\n" + + " private V v;\n" + + " public X(U u,V v) { this.u= u; this.v= v; }\n" + + " public R getU() { return (R)u; } // Warning\n" + + " public R getV() { return (R)v; } // Warning\n" + + " Object o;\n" + + " public T getT() { return (T)o; } // Warning\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public R getU() { return (R)u; } // Warning\n" + + " ^^^^\n" + + "Type safety: Unchecked cast from U to R\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public R getV() { return (R)v; } // Warning\n" + + " ^^^^\n" + + "Type safety: Unchecked cast from V to R\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " public T getT() { return (T)o; } // Warning\n" + + " ^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - generic varargs method + public void test0387() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X\n" + + "{\n" + + "\n" + + " public boolean test1()\n" + + " {\n" + + " test2(\"test\", null, 0);\n" + + " }\n" + + "\n" + + " public List test2(final List list, final String... strings)\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " test2(\"test\", null, 0);\n" + + " ^^^^^\n" + + "The method test2(List, String...) in the type X is not applicable for the arguments (String, null, int)\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation + public void test0388() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X\n" + + "{\n" + + "\n" + + " public boolean test01()\n" + + " {\n" + + " test02(null, null, \"test\");\n" + + " return false;\n" + + " }\n" + + "\n" + + " public List test02(final List list, final String... strings)\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation + public void test0389() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public boolean test01() {\n" + + " String s = foo(\"hello\");\n" + + " return s != null;\n" + + " }\n" + + "\n" + + " public F foo(F f, F... others) {\n" + + " return f;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation + public void test0390() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public boolean test01() {\n" + + " String s = foo(null, \"hello\");\n" + + " return s != null;\n" + + " }\n" + + "\n" + + " public F foo(F f, F... others) {\n" + + " return f;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation + public void test0391() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public boolean test01() {\n" + + " String[] s = foo(null, new String[]{ \"hello\" });\n" + + " return s != null;\n" + + " }\n" + + "\n" + + " public F foo(F f, F... others) {\n" + + " return f;\n" + + " }\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" + + "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 foo(F f, F... others) {\n" + + " ^^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter others\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77422 - variation + public void test0392() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public boolean test01() {\n" + + " foo(null, \"hello\");\n" + // no inference on expected type + " return true;\n" + + " }\n" + + "\n" + + " public F foo(F f, F... others) {\n" + + " return f;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78049 - chech invalid array initializer + public void test0393() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public boolean test01() {\n" + + " foo(null, \"hello\");\n" + // no inference on expected type + " return true;\n" + + " }\n" + + "\n" + + " public F foo(F f, F... others) {\n" + + " return f;\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78027 + public void test0394() { + this.runConformTest( + new String[] { + "X.java", + "public class X \n" + + "{\n" + + "}\n" + + "\n" + + "interface ITest\n" + + "{ \n" + + "}\n" + + "\n" + + "abstract class Test implements ITest\n" + + "{\n" + + " protected Manager m_manager;\n" + + " \n" + + " public ITest get()\n" + + " {\n" + + " return m_manager.getById(getClass(), new Integer(1));\n" + + " }\n" + + " \n" + + " public static class Manager\n" + + " {\n" + + " public > T getById(Class cls, Integer id)\n" + + " {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74119 - variation + public void test0395() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T element;\n" + + " \n" + + " void foo(X xnpe) {\n" + + " xnpe.element = new java.io.IOException();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " xnpe.element = new java.io.IOException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from IOException to capture#1-of ? super NullPointerException\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78139 - downcast generic method inference + public void test0396() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "\n" + + "public class X\n" + + "{\n" + + " public static List emptyList() {\n" + + " return new ArrayList();\n" + + " }\n" + + " public static Collection emptyCollection() {\n" + + " return new ArrayList();\n" + + " }\n" + + " public static Iterable emptyIterable() {\n" + + " return new ArrayList();\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " // generic inference using expected lhs type: T --> String\n" + + " final List lL = emptyList(); // 1\n" + + " \n" + + " // generic inference using expected cast type: T --> String\n" + + " final Collection cL = (Collection)emptyList(); // 2\n" + + " \n" + + " // generic inference using expected cast type: T --> String\n" + + " final Iterable iL = (Iterable)emptyList(); // 3\n" + + " \n" + + " // generic inference using expected lhs type: T --> String\n" + + " final Collection cC = emptyCollection(); // 4\n" + + " \n" + + " // generic inference using expected cast type: T --> String\n" + + " final Iterable iC = (Iterable)emptyCollection(); // 5\n" + + " \n" + + " // generic inference using expected lhs type: T --> String\n" + + " final Iterable iI = emptyIterable(); // 6\n" + + " \n" + + " // generic inference using expected lhs type: T --> String\n" + + " final Collection cL2 = emptyList(); // 7\n" + + " \n" + + " // generic inference using expected lhs type: T --> String\n" + + " final Iterable iC2 = emptyCollection(); // 8\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " final Collection cL = (Collection)emptyList(); // 2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to Collection\n" + + "----------\n" + + "2. ERROR in X.java (at line 25)\n" + + " final Iterable iL = (Iterable)emptyList(); // 3\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to Iterable\n" + + "----------\n" + + "3. ERROR in X.java (at line 31)\n" + + " final Iterable iC = (Iterable)emptyCollection(); // 5\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Collection to Iterable\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76132 + public void test0397() { + this.runNegativeTest( + new String[] { + "X.java", + "interface K1 { \n" + + " public void kk(K1 x); \n" + + "} \n" + + " \n" + + "class K2 implements K1 { \n" + + " public void kk(K1 y) { \n" + + " System.out.println(\"K2::kk(\" + y.toString() + \")\"); \n" + + " } \n" + + "} \n" + + " \n" + + "// --------------------------------------------------- \n" + + " \n" + + "interface L1 { \n" + + " public void ll(L1 a); \n" + + "} \n" + + " \n" + + "class L2 implements L1 { \n" + + " public void ll(L1 b) { \n" + + " ll2(b); \n" + + " } \n" + + " \n" + + " private void ll2(L1 c) { \n" + + " System.out.println(\"L2::ll2(\" + c.toString() + \")\"); \n" + + " } \n" + + "} \n" + + " \n" + + "// --------------------------------------------------- \n" + + " \n" + + "interface M1 { \n" + + " public void mm(M1 p); \n" + + "} \n" + + " \n" + + "class M2 implements M1 { \n" + + " public void mm(M1 q) { \n" + + " System.out.println(\"M2::mm(\" + q.toString() + \")\"); \n" + + " } \n" + + "} \n" + + " \n" + + "// =================================================== \n" + + " \n" + + "class XX { public String toString() { return \"XX\"; } } \n" + + "class YY extends XX { public String toString() { return \"YY\"; } } \n" + + "class ZZ extends YY { public String toString() { return \"ZZ\"; } } \n" + + " \n" + + "// --------------------------------------------------- \n" + + " \n" + + "public class X { \n" + + " public static void main(String arg[]) { \n" + + " goK(new K2()); \n" + + " goL(new L2()); \n" + + " goM(new M2()); \n" + + " } \n" + + " \n" + + " \n" + + " public static void goK(K1 k) { \n" + + " // k.kk(new K2()); // Would fail \n" + + " k.kk(new K2()); \n" + + " k.kk(new K2()); \n" + + " } \n" + + " \n" + + " \n" + + " public static void goL(L1 l) { \n" + + " // l.ll(new L2()); // Would fail \n" + + " l.ll(new L2()); \n" + + " l.ll(new L2()); \n" + + " } \n" + + " \n" + + " \n" + + " public static void goM(M1 m) { \n" + + " // m.mm(new M2()); // Would fail \n" + + " m.mm(new M2()); \n" + + " m.mm(new M2()); \n" + + " } \n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 33)\n" + + " class M2 implements M1 { \n" + + " ^^\n" + + "The type M2 must implement the inherited abstract method M1.mm(M1)\n" + + "----------\n" + + "2. ERROR in X.java (at line 34)\n" + + " public void mm(M1 q) { \n" + + " ^^^^^^^^^^^\n" + + "Name clash: The method mm(M1) of type M2 has the same erasure as mm(M1) of type M1 but does not override it\n" + + "----------\n" + + "3. WARNING in X.java (at line 41)\n" + + " class XX { public String toString() { return \"XX\"; } } \n" + + " ^^^^^^^^^^\n" + + "The method toString() of type XX should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "4. WARNING in X.java (at line 42)\n" + + " class YY extends XX { public String toString() { return \"YY\"; } } \n" + + " ^^^^^^^^^^\n" + + "The method toString() of type YY should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "5. WARNING in X.java (at line 43)\n" + + " class ZZ extends YY { public String toString() { return \"ZZ\"; } } \n" + + " ^^^^^^^^^^\n" + + "The method toString() of type ZZ should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); + } + // cannot allocate parameterized type with wildcards + public void test0398() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(){\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X();\n" + + " new X();\n" + + " new X(){};\n" + + " new X(){};\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new X();\n" + + " ^\n" + + "Cannot instantiate the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " new X();\n" + + " ^\n" + + "Cannot instantiate the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " new X(){};\n" + + " ^\n" + + "The type new X(){} cannot extend or implement X. A supertype may not specify any wildcard\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " new X(){};\n" + + " ^\n" + + "The type new X(){} cannot extend or implement X. A supertype may not specify any wildcard\n" + + "----------\n"); + } + + public void test0399() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X>(new AX());\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " P foo() { return null; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X x = new X>(new AX());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X>(AX) is undefined\n" + + "----------\n"); + } + + public void test0400() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(X xt){\n" + + " this.t = xt.t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X>(new X>(null));\n" + + " }\n" + + "}\n" + + "class AX

{\n" + + " P foo() { return null; }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X x = new X>(new X>(null));\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX

should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X x = new X>(new X>(null));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X>(X>) is undefined\n" + + "----------\n"); + } + + // legal to allocate/inherit from a type with wildcards, as long as non direct arguments + public void test0401() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " new X>();\n" + + " new X>();\n" + + " new X>(){};\n" + + " new X>(){};\n" + + " }\n" + + "}", + }, + ""); + } + + // legal to inherit from a type with wildcards, as long as non direct arguments + public void test0402() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y> {\n" + + "}\n" + + "class Y {}", + }, + ""); + } + // check cast between generic types + public void test0403() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(X> xs) {\n" + + " X> x = (X>) xs;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X> x = (X>) xs;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X> to X>\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + // check cast between generic types + public void test0404() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(X xs) {\n" + + " X x = (X) xs;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " X x = (X) xs;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + // check cast between generic types + public void test0405() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(X> xs) {\n" + + " X> x = (X>) xs;\n" + + " }\n" + + " void bar(X xs) {\n" + + " X x = (X) xs;\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X> x = (X>) xs;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X> to X>\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X x = (X) xs;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n"); + } + + public void test0406() { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X implements M {\n" + + " abstract M other();\n" + + " public S> entrySet() {\n" + + " return other().entrySet();\n" + + " }\n" + + "}\n" + + "interface M {\n" + + " interface E { }\n" + + " S> entrySet();\n" + + "}\n" + + "interface S {}", + }, + ""); + } + + public void test0407() { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X implements M {\n" + + " abstract M other();\n" + + " public S> entrySet() {\n" + // qualified M.E... + " return other().entrySet();\n" + + " }\n" + + "}\n" + + "interface M {\n" + + " interface E { }\n" + + " S> entrySet();\n" + + "}\n" + + "interface S {}", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78008 + public void test0408() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public Integer[] getTypes() {\n" + + " List list = new ArrayList();\n" + + " return list == null \n" + + " ? new Integer[0] \n" + + " : list.toArray(new Integer[list.size()]);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Class clazz = null;\n" + + " try {\n" + + " clazz = Class.forName(\"X\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78008 + public void test0409() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public Number getTypes() {\n" + + " List list = new ArrayList();\n" + + " return list == null \n" + + " ? Float.valueOf(0)\n" + + " : list.get(0);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Class clazz = null;\n" + + " try {\n" + + " clazz = Class.forName(\"X\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=74178 + public void test0410() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + "public void write(List list) {\n" + + " \n" + + " list.add(new RuntimeException()); // works\n" + + " list.add(new IllegalMonitorStateException()); // works\n" + + " Exception exc = new Exception();\n" + + " list.add(exc); // works\n" + + " list.add(new Object()); // should fail\n" + + " list.add(new Throwable()); // should fail\n" + + " list.add(new Exception()); // works\n" + + "}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " list.add(new Object()); // should fail\n" + + " ^^^\n" + + "The method add(capture#4-of ? super Exception) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " list.add(new Throwable()); // should fail\n" + + " ^^^\n" + + "The method add(capture#5-of ? super Exception) in the type List is not applicable for the arguments (Throwable)\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78015 + public void test0411() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void m1(T t);\n" + + " void m2(T t);\n" + + "}\n" + + "\n" + + "class A {};\n" + + "\n" + + "class B implements I {\n" + + " public void m1(A a) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void m2(A a) {}\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " m(new B());\n" + + " }\n" + + "\n" + + " public static void m(I x) {\n" + + " x.m1(null);\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78467 + public void test0412() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static T first(T... args) {\n" + + " return args[0];\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " if (false) { \n" + + " String s = first(); \n" + + " int i; \n" + + " i++; \n" + + " }\n" + + " System.out.println(first(\"SUCCESS\", \"List\"));\n" + + " }\n" + + " 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" + + "1. WARNING in X.java (at line 3)\n" + + " public static 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() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + "\n" + + " public static T first(T... args) {\n" + + " return args[0];\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " if (false) { \n" + + " List ls = first(); \n" + + " int i; \n" + + " i++; \n" + + " }\n" + + " System.out.println(first(\"SUCCESS\", \"List\"));\n" + + " }\n" + + " Zork z;\n" + + "}", + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " List ls = first(); \n" + + " ^^^^^^^\n" + + "Type safety: A generic array of List 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" + + "1. WARNING in X.java (at line 4)\n" + + " public static 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 ls = first(); \n" + + " ^^^^^^^\n" + + "Type safety: A generic array of List 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() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class TLM {\n" + + " }\n" + + " TLM getMap(TL t) {\n" + + " return t.tls;\n" + + " }\n" + + " static TLM createInheritedMap(TLM parentMap) {\n" + + " return new TLM();\n" + + " } \n" + + "}\n" + + "\n" + + "class TL {\n" + + " X.TLM tls = null;\n" + + "}", + }, + ""); + } + + public void test0414() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(L l, C c) {\n" + + " bar(l, c);\n" + + " }\n" + + " void bar(L l, C c) { \n" + + " } \n" + + "}\n" + + "class C {}\n" + + "class L {}", + }, + ""); + } + + public void test0415() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public S> foo(HM hm) {\n" + + " return C.bar(hm).foo();\n" + + " }\n" + + "}\n" + + "class C {\n" + + " public static M bar(M m) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class S {\n" + + "}\n" + + "abstract class HM implements M{\n" + + "}\n" + + "interface M {\n" + + " static class E {}\n" + + " S> foo(); \n" + + "}", + }, + ""); + } + + public void test0416() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public S> foo(HM hm) {\n" + + " M m = C.bar(hm);\n" + + " if (false) return m.foo();\n" + + " return C.bar(hm).foo();\n" + + " }\n" + + "}\n" + + "class C {\n" + + " public static M bar(M m) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class S {\n" + + "}\n" + + "abstract class HM implements M{\n" + + "}\n" + + "interface M {\n" + + " static class E {}\n" + + " S> foo(); \n" + + "}", + }, + ""); + } + + public void test0417() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " X foo(X xt) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x) {\n" + + " X xs = foo(x).identity();\n" + + " }\n" + + "}\n", + }, + ""); + } + + public void test0418() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " X foo(X xt, X xt2) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x, X xs) {\n" + + " X xs2 = foo(x, xs).identity();\n" + + " }\n" + + "}\n", + }, + ""); + } + + public void test0419() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " X foo(X xt, X xt2) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x, X xs) {\n" + + " X xs2 = foo(x, xs).identity();\n" + + " }\n" + + "}\n", + }, + ""); + } + + public void test0420() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " X foo(X xt, X xt2) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x, X xs) {\n" + + " X xs2 = foo(x, xs).identity();\n" + + " }\n" + + "}\n", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78863 + public void test0421() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.HashMap;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "\n" + + "public class Test\n" + + "{\n" + + " protected Map, List> m_test\n" + + " = new HashMap, List>();\n" + + "}\n", + "Test2.java", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "\n" + + "public class Test2 extends Test\n" + + "{\n" + + " public Map, List> test()\n" + + " {\n" + + " return m_test;\n" + + " }\n" + + "}\n", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78704 + public void test0422() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo() {\n" + + " return new X();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return new X();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from X to String\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " return new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); + } + + public void test0423() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " static T bar() {\n" + + " return null;\n" + + " }\n" + + " static U foo() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " bar();\n" + + " foo();\n" + + " }\n" + + "\n" + + "}", + }, + ""); + } + + public void test0424() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " }\n" + + " void bar() {\n" + + " B b = foo(new B());\n" + + " }\n" + + "}\n" + + "\n" + + "class A {}\n" + + "class B extends A {}\n" + + "\n", + }, + ""); + } + + // check tiebreak eliminates related generic methods which are less specific + public void test0425() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " static void m(E e) { System.out.println(\"A:\"+e.getClass()); }\n" + + " static void m(F f) throws Exception { System.out.println(\"B:\"+f.getClass()); }\n" + + " static void m(G g) throws IOException { System.out.println(\"C:\"+g.getClass()); }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " m(new A());\n" + + " m(new B());\n" + + " m(new C());\n" + + " }\n" + + "}\n" + + "\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends A {}\n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " m(new B());\n" + + " ^^^^^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " m(new C());\n" + + " ^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n"); + } + + // check inferred return types are truly based on arguments, and not on parameter erasures + public void test0426() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static E m(E e) { System.out.print(\"[A:\"+e.getClass()+\"]\"); return e; }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " A a = m(new A());\n" + + " B b = m(new B());\n" + + " C c = m(new C());\n" + + " }\n" + + "}\n" + + "\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends A {}\n", + }, + "[A:class A][A:class B][A:class C]"); + } + + // check inferred return types are truly based on arguments, and not on parameter erasures + public void test0427() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static E m(E e, E... e2) { System.out.print(\"[A:\"+e.getClass()+\"]\"); return e; }\n" + + " static F m(F f, F... f2) { System.out.print(\"[B:\"+f.getClass()+\"]\"); return f; }\n" + + " static G m(G g, G... g2) { System.out.print(\"[C:\"+g.getClass()+\"]\"); return g; }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " A a = m(new A(), new A());\n" + + " B b = m(new B(), new B());\n" + + " C c = m(new C(), new C());\n" + + " }\n" + + "}\n" + + "\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends A {}\n", + }, + "[A:class A][B:class B][C:class C]"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79390 + public void test0428() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " public static void foo() {\n" + + " class A {\n" + + " T t = null;\n" + + " T get() {\n" + + " return t;\n" + + " }\n" + + " }\n" + + " A a = new A() {\n" + + " @Override\n" + + " Long get() {\n" + + " return Long.valueOf(5);\n" + + " }\n" + + " };\n" + + " }\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"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429() { + this.runConformTest( + new String[] { + "X1.java", + "class X1 > {}\n" + + "abstract class Y implements Comparable {}", + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429a() { + this.runConformTest( + new String[] { + "X2.java", + "class X2 > {}\n" + + "abstract class Y extends Z {}\n" + + "abstract class Z implements Comparable {}", + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429b() { + this.runConformTest( + new String[] { + "X3.java", + "class X3 > {}\n" + + "abstract class Y extends Z {}\n" + + "abstract class Z implements Comparable {}", + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429c() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X4.java", + "class X4 & Comparable> {}\n" + + "abstract class Y extends Z {}\n" + + "abstract class Z implements Comparable {}", + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X4.java (at line 1)\n" + + " class X4 & Comparable> {}\n" + + " ^^^^^^^^^^\n" + + "Duplicate bound Comparable\n" + + "----------\n", + // no complaints about duplicates if they are both parameterized with same args + // but you cannot extend Comparable & Comparable so we'll report an error + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429d() { + this.runNegativeTest( + new String[] { + "X5.java", + "class X5 > {}\n" + + "abstract class Y implements Comparable {}", + }, + "----------\n" + + "1. ERROR in X5.java (at line 1)\n" + + " class X5 > {}\n" + + " ^^^^^^^^^^\n" + + "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + + "----------\n" + + "2. WARNING in X5.java (at line 1)\n" + + " class X5 > {}\n" + + " ^^\n" + + "X5 is a raw type. References to generic type X5 should be parameterized\n" + + "----------\n" + // Comparable cannot be inherited with different arguments: and + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429e() { + this.runNegativeTest( + new String[] { + "X6.java", + "class X6 > {}\n" + + "abstract class Y extends Z {}\n" + + "abstract class Z implements Comparable {}", + }, + "----------\n" + + "1. ERROR in X6.java (at line 1)\n" + + " class X6 > {}\n" + + " ^^^^^^^^^^\n" + + "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + + "----------\n" + + "2. WARNING in X6.java (at line 1)\n" + + " class X6 > {}\n" + + " ^^\n" + + "X6 is a raw type. References to generic type X6 should be parameterized\n" + + "----------\n" + // Comparable cannot be inherited with different arguments: and + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429f() { + this.runNegativeTest( + new String[] { + "X7.java", + "class X7 & Comparable> {}\n" + + "abstract class Y extends Z {}\n" + + "abstract class Z implements Comparable {}", + }, + "----------\n" + + "1. ERROR in X7.java (at line 1)\n" + + " class X7 & Comparable> {}\n" + + " ^^^^^^^^^^\n" + + "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + + "----------\n" + + "2. WARNING in X7.java (at line 1)\n" + + " class X7 & Comparable> {}\n" + + " ^^\n" + + "X7 is a raw type. References to generic type X7 should be parameterized\n" + + "----------\n" + // Comparable cannot be inherited with different arguments: and + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78293 + public void test0429g() { + this.runNegativeTest(new String[] { + "X.java", + "interface I {}\n" + + "\n" + + "class A implements I, I {}\n" + + "public class X & I> {\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class A implements I, I {}\n" + + " ^\n" + + "Duplicate interface I for the type A\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public class X & I> {\n" + + " ^\n" + + "The interface I cannot be implemented more than once with different arguments: I and I\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " public class X & I> {\n" + + " ^\n" + + "Duplicate bound I\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79797 + public void test0430() { + this.runConformTest( + new String[] { + "p/MMM.java", + "package p;\n" + + "public interface MMM< F extends MMM, G extends NNN> { } \n", + "p/NNN.java", + "package p;\n" + + "public interface NNN { } \n", + }, + ""); + + this.runConformTest( + new String[] { + "X.java", + "import p.MMM;\n" + + "import p.NNN;\n" + + "\n" + + "interface RRR< A extends MMM, B extends NNN> {}\n" + + "\n" + + "class J1 implements MMM { }\n" + + "class J2 implements NNN { }\n" + + "\n" + + "class J3 implements RRR {} \n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " J3 thing = null;\n" + + " }\n" + + "}\n", + }, + "", + null, + false, // do not flush output + null); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79891 + public void test0431() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private class Element {\n" + + " }\n" + + " public X() {\n" + + " Element[] eArray = new Element[10];\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Element[] eArray = new Element[10];\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X.Element\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=79891 + public void test0432() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private static class Element {\n" + + " }\n" + + " public X() {\n" + + " Element[] eArray = new Element[10];\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80144 + public void test0433() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "interface Alpha<\n" + + " A1 extends Alpha, \n" + + " B1 extends Beta> {\n" + + "}\n" + + "interface Beta<\n" + + " A2 extends Alpha, \n" + + " B2 extends Beta> {\n" + + "}\n" + + "interface Phi<\n" + + " A3 extends Alpha, \n" + + " B3 extends Beta> {\n" + + " \n" + + " public void latinize(A3 s);\n" + + "}\n" + + "\n" + + "public class X<\n" + + " A extends Alpha, \n" + + " B extends Beta, \n" + + " P extends Phi> extends ArrayList

implements Phi {\n" + + " \n" + + " public final void latinize(A a) {\n" + + " frenchify(this, a); // (X, A)\n" + + " }\n" + + " // -----------------------------------------------------------------\n" + + " public static final , BB extends Beta> \n" + + " void frenchify(Collection< ? extends Phi> phis, AA aa) {\n" + + " for (final Phi phi : phis)\n" + + " phi.latinize(aa);\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80083 + public void test0434() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X\n" + + "{\n" + + "\n" + + " public static void main(String[] args)\n" + + " {\n" + + " ArrayList l = new ArrayList();\n" + + " l.add(\"x\");\n" + + " String s = \"\";\n" + + " s += l.get(0); // X\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80765 + public void test0435() { + this.runNegativeTest( + new String[] { + "Test.java",//=============================== + "import java.lang.reflect.InvocationTargetException;\n" + + "import java.lang.reflect.Method;\n" + + "\n" + + "import orders.DiscreteOrder;\n" + + "import orders.impl.IntegerOrder;\n" + + "import orders.impl.IntegerOrder2;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " public static void main(String[] args) throws SecurityException,\n" + + " NoSuchMethodException, IllegalArgumentException,\n" + + " IllegalAccessException {\n" + + " Test test = new Test();\n" + + "\n" + + " for (String method : new String[] { \"test01\", \"test02\", \"test03\", \"test04\" }) {\n" + + " Method m = test.getClass().getMethod(method);\n" + + " try {\n" + + " m.invoke(test);\n" + + " System.out.print(\"*** \" + m + \": success\");\n" + + " } catch (InvocationTargetException e) {\n" + + " System.out.print(\"*** \" + m + \": failed, stacktrace follows\");\n" + + " e.getCause().printStackTrace(System.out);\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " public void test01() { // works\n" + + " new IntegerOrder().next(Integer.valueOf(0)); // works\n" + + " }\n" + + "\n" + + " public void test02() { // doesn\'t work\n" + + " final DiscreteOrder order = new IntegerOrder();\n" + + " order.next(Integer.valueOf(0));\n" + + " }\n" + + "\n" + + " public void test03() { // works\n" + + " new IntegerOrder2().next(Integer.valueOf(0)); // works\n" + + " }\n" + + "\n" + + " public void test04() { // doesn\'t work\n" + + " final DiscreteOrder order = new IntegerOrder2();\n" + + " order.next(Integer.valueOf(0));\n" + + " }\n" + + "}\n", + "orders/DiscreteOrder.java",//=============================== + "package orders;\n" + + "public interface DiscreteOrder> {\n" + + " /**\n" + + " * @return The element immediately before element in the\n" + + " * discrete ordered space.\n" + + " */\n" + + " public E previous(E element);\n" + + " /**\n" + + " * @return The element immediately after element in the\n" + + " * discrete ordered space.\n" + + " */\n" + + " public E next(E element);\n" + + "}\n", + "orders/impl/IntegerOrder.java",//=============================== + "package orders.impl;\n" + + "import orders.DiscreteOrder;\n" + + "\n" + + "public class IntegerOrder implements DiscreteOrder {\n" + + "\n" + + " public IntegerOrder() {\n" + + " super();\n" + + " }\n" + + "\n" + + " public Integer previous(Integer arg0) {\n" + + " return Integer.valueOf(arg0.intValue() - 1);\n" + + " }\n" + + "\n" + + " public Integer next(Integer arg0) {\n" + + " return Integer.valueOf(arg0.intValue() + 1);\n" + + " }\n" + + "}\n", + "orders/impl/IntegerOrder2.java",//=============================== + "package orders.impl;\n" + + "\n" + + "\n" + + "public class IntegerOrder2 extends IntegerOrder {\n" + + "\n" + + " public IntegerOrder2() {\n" + + " super();\n" + + " }\n" + + "\n" + + " public Comparable previous(Comparable arg0) {\n" + + " return previous((Integer) arg0);\n" + + " }\n" + + "\n" + + " public Comparable next(Comparable arg0) {\n" + + " return next((Integer) arg0);\n" + + " }\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in orders\\impl\\IntegerOrder2.java (at line 10)\n" + + " public Comparable previous(Comparable arg0) {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. ERROR in orders\\impl\\IntegerOrder2.java (at line 10)\n" + + " public Comparable previous(Comparable arg0) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method previous(Comparable) of type IntegerOrder2 has the same erasure as previous(E) of type DiscreteOrder but does not override it\n" + + "----------\n" + + "3. WARNING in orders\\impl\\IntegerOrder2.java (at line 10)\n" + + " public Comparable previous(Comparable arg0) {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "4. WARNING in orders\\impl\\IntegerOrder2.java (at line 14)\n" + + " public Comparable next(Comparable arg0) {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "5. ERROR in orders\\impl\\IntegerOrder2.java (at line 14)\n" + + " public Comparable next(Comparable arg0) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method next(Comparable) of type IntegerOrder2 has the same erasure as next(E) of type DiscreteOrder but does not override it\n" + + "----------\n" + + "6. WARNING in orders\\impl\\IntegerOrder2.java (at line 14)\n" + + " public Comparable next(Comparable arg0) {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + // "*** public void Test.test01(): success*** public void Test.test02(): success*** public void Test.test03(): success*** public void Test.test04(): success" + // name clash: next(java.lang.Comparable) in orders.impl.IntegerOrder2 and next(E) in orders.DiscreteOrder have the same erasure, yet neither overrides the other + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80028 + public void test0436() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public static void main(String[] args) {\n" + + " Number n= new Integer(1);\n" + + " X x = new X();\n" + + " x.m(n);\n" + + " x.m(new Integer(2));\n" + + " Y y= new Y();\n" + + " y.m(n);\n" + + " y.m(new Integer(2));\n" + + " }\n" + + "}\n", + "X.java", + "class X {\n" + + " public void m(Number num) { System.out.print(\"X.m(Number) = \" + num + ','); }\n" + + " public void m(T t) { System.out.print(\"X.m(T) = \" + t + ','); }\n" + + "}\n", + "Y.java", + "class Y extends X {\n" + + " public void m(Number num) { System.out.print(\"Y.m(Number) = \" + num + ','); }\n" + + "}\n", + }, + "X.m(Number) = 1,X.m(Number) = 2,Y.m(Number) = 1,Y.m(Number) = 2,"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80028 + public void test0437() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public static void main(String[] args) {\n" + + " Number n= new Integer(1);\n" + + " X x = new X();\n" + + " x.m(n);\n" + + " x.m(new Integer(2));\n" + + " Y y= new Y();\n" + + " y.m(n);\n" + + " y.m(new Integer(2));\n" + + " }\n" + + "}\n", + "X.java", + "class X {\n" + + " public void m(Number num) { System.out.print(\"X.m(Number) = \" + num + ','); }\n" + + " public void m(T t) { System.out.print(\"X.m(T) = \" + t + ','); }\n" + + "}\n", + "Y.java", + "class Y extends X {\n" + + " public void m(Number num) { System.out.print(\"Y.m(Number) = \" + num + ','); }\n" + + "}\n", + }, + "X.m(Number) = 1,X.m(Number) = 2,Y.m(Number) = 1,Y.m(Number) = 2,"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78591 + public void test0438() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " Zork z;\n" + + " List list;\n" + + " void add(Object abs) {\n" + + " list.add((T) list.get(0)); // checked cast\n" + + " list.add((T) abs); // unchecked cast\n" + + " }\n" + + " void bar(List other) {\n" + + " list.add((T) other.get(0)); // checked cast\n" + + " }\n" + + " void baz(List other) {\n" + + " list.add((T) other.get(0)); // unchecked cast\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " list.add((T) list.get(0)); // checked cast\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from T to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " list.add((T) abs); // unchecked cast\n" + + " ^^^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " list.add((T) other.get(0)); // checked cast\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from capture#1-of ? extends T to T\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " list.add((T) other.get(0)); // unchecked cast\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from capture#2-of ? super T to T\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78592 + public void test0439() { + this.runNegativeTest( + new String[] { + "X.java", + "class Node {\n" + + "}\n" + + "class Composite {\n" + + "}\n" + + "class Concrete extends Composite {\n" + + "}\n" + + "public class X {\n" + + " Composite comp = new Concrete(); // unchecked cast\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " class Concrete extends Composite {\n" + + " ^^^^^^^^^\n" + + "Composite is a raw type. References to generic type Composite should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " Composite comp = new Concrete(); // unchecked cast\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Concrete needs unchecked conversion to conform to Composite\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + public void test0440() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " public void foo(X xt) {\n" + + " U u = (U) xt;\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " U u = (U) xt;\n" + + " ^^^^^^\n" + + "Type safety: Unchecked cast from X to U\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + public void test0441() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T[] array;\n" + + " X(int s) {\n" + + " array = (T[]) new Number[s]; // Unnecessary cast from Number[] to T[]\n" + + " array = new Number[s]; // Type mismatch: cannot convert from Number[] to T[]\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " array = (T[]) new Number[s]; // Unnecessary cast from Number[] to T[]\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Number[] to T[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " array = new Number[s]; // Type mismatch: cannot convert from Number[] to T[]\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Number[] to T[]\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82053 + public void test0442() { + this.runConformTest( + new String[] { + "X.java", + "class Foo {\n" + + " public interface Model {\n" + + " }\n" + + " public interface View {\n" + + " M getTarget() ;\n" + + " }\n" + + "}\n" + + "class Bar {\n" + + " public interface Model extends Foo.Model {\n" + + " }\n" + + " public interface View extends Foo.View {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public void baz() {\n" + + " Bar.View bv = null ;\n" + + " Bar.Model m = bv.getTarget() ;\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81757 + public void test0443() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "public class X implements Iterator {\n" + + " public boolean hasNext() { return false; }\n" + + " public String next() { return null; }\n" + + " public void remove() {}\n" + + "}\n", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81824 + public void test0444() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I, I {}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements I, I {}\n" + + " ^\n" + + "The interface I cannot be implemented more than once with different arguments: I and I\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78810 + public void test0445() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " public abstract Object getProperty(final Object src, final String name);\n" + + " Zork z;\n" + + " public T getTheProperty(final Object src, final String name)\n" + + " {\n" + + " final T val = (T) getProperty(src, name); // this gives erroneous cast warning\n" + + " return val;\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " final T val = (T) getProperty(src, name); // this gives erroneous cast warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 + public void test0446() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Inner { }\n" + + "\n" + + " void method() {\n" + + " X.Inner a= new X().new Inner();\n" + + " Inner b= new X().new Inner();\n" + + " Inner c= new Inner();\n" + + " // OK\n" + + "\n" + + " X.Inner d= new X.Inner();\n" + + " //eclipse: OK\n" + + " //other: error: \'(\' or \'[\' expected\n" + + "\n" + + " X.Inner e= new X().new Inner();\n" + + " X.Inner f= new Inner();\n" + + " e= b;\n" + + " f= c;\n" + + " //other: OK\n" + + " //eclipse: Type mismatch: cannot convert from X.Inner to X.Inner\n" + + "\n" + + " }\n" + + "}\n" + + "\n" + + "class External {\n" + + " void m() {\n" + + " X.Inner x= new X().new Inner();\n" + + " // OK\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " X.Inner d= new X.Inner();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot allocate the member type X.Inner using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236243); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0447() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Inner { }\n" + + "\n" + + " void method() {\n" + + " X.Inner d1 = new X.Inner();\n" + + " X.Inner d2 = new X.Inner();\n" + + " X.Inner d3 = new X.Inner();\n" + + " d1 = d2;\n" + + " d2 = d1;\n" + + " d1 = d3;\n" + + " d3 = d1;\n" + + " d2 = d3;\n" + + " d3 = d2;\n" + + "\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X.Inner d1 = new X.Inner();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot allocate the member type X.Inner using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " X.Inner d2 = new X.Inner();\n" + + " ^^^^^^^\n" + + "X.Inner is a raw type. References to generic type X.Inner should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " X.Inner d2 = new X.Inner();\n" + + " ^^^^^^^\n" + + "X.Inner is a raw type. References to generic type X.Inner should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " X.Inner d3 = new X.Inner();\n" + + " ^^^^^^^\n" + + "The member type X.Inner must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " X.Inner d3 = new X.Inner();\n" + + " ^^^^^^^\n" + + "The member type X.Inner must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "6. WARNING in X.java (at line 8)\n" + + " d1 = d2;\n" + + " ^^\n" + + "Type safety: The expression of type X.Inner needs unchecked conversion to conform to X.Inner\n" + + "----------\n" + + "7. ERROR in X.java (at line 10)\n" + + " d1 = d3;\n" + + " ^^\n" + + "Type mismatch: cannot convert from X.Inner to X.Inner\n" + + "----------\n" + + "8. ERROR in X.java (at line 11)\n" + + " d3 = d1;\n" + + " ^^\n" + + "Type mismatch: cannot convert from X.Inner to X.Inner\n" + + "----------\n" + + "9. WARNING in X.java (at line 13)\n" + + " d3 = d2;\n" + + " ^^\n" + + "Type safety: The expression of type X.Inner needs unchecked conversion to conform to X.Inner\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0448() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Inner { }\n" + + "\n" + + " void method() {\n" + + " X.Inner d = new X.Inner(); \n" + + " }\n" + + "}\n", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0448a() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " class Y {}\n" + + " X.Y[] tab = new X.Y[] {};\n" + + "}" + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); + } + + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0449() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Inner { \n" + + " }\n" + + "\n" + + " void method() {\n" + + " X.Inner d4 = new X.Inner();\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.Inner d4 = new X.Inner();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Inner to X.Inner\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X.Inner d4 = new X.Inner();\n" + + " ^^^^^^^\n" + + "The member type X.Inner must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0450() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Inner { \n" + + " }\n" + + "\n" + + " void method() {\n" + + " X.Inner d4 = new X.Inner();\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.Inner d4 = new X.Inner();\n" + + " ^^^^^^^^^^^^^^^\n" + + "The member type X.Inner cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X.Inner d4 = new X.Inner();\n" + + " ^^^^^^^^^^^^^^^\n" + + "The member type X.Inner cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82159 - variation + public void test0451() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Inner { \n" + + " }\n" + + "\n" + + " void method() {\n" + + " X.Inner d4 = new X.Inner() {};\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.Inner d4 = new X.Inner() {};\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot allocate the member type X.Inner using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236243); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82187 + public void test0452() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public > S test01(S param){\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " \n" + + " public void test02() {\n" + + " test01(new Vector());\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X().test02();\n" + + " }\n" + + "}\n" , + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82250 + public void test0453() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {}\n" + + "interface I {}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "Duplicate bound I\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82504 + public void test0454() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object[] objectArr;\n" + + " void foo(T t) {\n" + + " T x1= (T) objectArr;\n" + + " U x2= (U) objectArr;\n" + + " int[] x= (int[]) t;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " T x1= (T) objectArr;\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to T\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " U x2= (U) objectArr;\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot cast from Object[] to U\n" + + "----------\n"); + } + + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81719 + public void test0455() { + this.runConformTest( + new String[] { + "AbstractTest.java", + "public abstract class AbstractTest {\n" + + " abstract void array(T[] a);\n" + + " abstract void type(T a);\n" + + " abstract T[] foo();\n" + + "}\n", + }, + ""); + + this.runConformTest( + new String[] { + "Test.java", + "public class Test extends AbstractTest {\n" + + " void array(T[] a) {}\n" + + " void type(T a) {}\n" + + " T[] foo() { return null; }\n" + + "}\n", + }, + "", + null, + false, // do not flush output + null); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81721 + public void test0456() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void doTest(S[] a);\n" + + "}\n" + + "\n" + + "abstract class AbstractTest implements I {\n" + + " public void doTest(V[] a) {}\n" + + "}\n" + + "\n" + + "public class X extends AbstractTest {}\n", + }, + ""); + } + + public void test0457() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " \n" + + " void add(List l) { \n" + + " l.add(new X()); \n" + + " }\n" + + " void add2(List l) { \n" + + " l.add(new X()); \n" + + " }\n" + + " \n" + + " static void add3(List l, List l2) { \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List lx = null;\n" + + " List ls = null;\n" + + " add3(lx, ls);\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " l.add(new X()); \n" + + " ^^^\n" + + "The method add(capture#2-of ? extends X) in the type List is not applicable for the arguments (X)\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " add3(lx, ls);\n" + + " ^^^^\n" + + "The method add3(List, List) in the type X is not applicable for the arguments (List, List)\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82243 + public void test0458() { + this.runNegativeTest( + new String[] { + "X.java", + "interface A{\n" + + " E getOne();\n" + + "}\n" + + "\n" + + "\n" + + "abstract class B implements A {\n" + + " Number getTwo() {\n" + + " return getOne(); // succeeds\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class C extends B {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void foo(A a, B b, C c){\n" + + " Object o= a.getOne();\n" + + " Number n1= b.getOne(); // fails\n" + + " Number n2= b.getTwo(); // succeeds, but inlining fails\n" + + " Integer i = c.getOne(); // succeeds\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 16)\n" + + " void foo(A a, B b, C c){\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " void foo(A a, B b, C c){\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " Number n1= b.getOne(); // fails\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Number\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78027 - variation (check unchecked warnings) + public void test0459() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X \n" + + "{\n" + + "Zork z;\n" + + "}\n" + + "\n" + + "interface ITest\n" + + "{ \n" + + "}\n" + + "\n" + + "abstract class Test implements ITest\n" + + "{\n" + + " protected Manager m_manager;\n" + + " \n" + + " public ITest get()\n" + + " {\n" + + " return m_manager.getById(getClass(), Integer.valueOf(1));\n" + + " }\n" + + " \n" + + " public static class Manager\n" + + " {\n" + + " public > T getById(Class cls, Integer id)\n" + + " {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " return m_manager.getById(getClass(), Integer.valueOf(1));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation getById(Class, Integer) of the generic method getById(Class, Integer) of type Test.Manager\n" + + "----------\n" + + "3. WARNING in X.java (at line 16)\n" + + " return m_manager.getById(getClass(), Integer.valueOf(1));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Test needs unchecked conversion to conform to ITest\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82439 + public void test0460() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public > S test(S param) {\n" + + " \n" + + " Class c = param.getClass(); // ok\n" + + " Class d = getClazz(); // ko\n" + + " return null;\n" + + " }\n" + + " Class getClazz() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "abstract class Z implements Collection {\n" + + " void foo() {\n" + + " Class c = getClass(); // ok\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " Class c = param.getClass(); // ok\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " Class d = getClazz(); // ko\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Class d = getClazz(); // ko\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n" + + "4. WARNING in X.java (at line 17)\n" + + " Class c = getClass(); // ok\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82844 + public void test0461() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^\n" + + "The array type int[] cannot be used as a type parameter bound\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79628 + public void test0462() { + this.runConformTest( + new String[] { + "PropertiedObject.java", + "interface PropertiedObject> {}\n" + + "interface Model extends PropertiedObject {}\n" + + "interface View extends PropertiedObject> {}\n" + }, + ""); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79144 + public void test0463() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Set;\n" + + "public class X {\n" + + " Zork z;\n" + + " public Set[] test() {\n" + + " Set[] sets = new Set[10];\n" + + " return sets;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " Set[] sets = new Set[10];\n" + + " ^^^\n" + + "Set is a raw type. References to generic type Set should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " return sets;\n" + + " ^^^^\n" + + "Type safety: The expression of type Set[] needs unchecked conversion to conform to Set[]\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=79144 + // SHOULD FAIL AT 1.8 (RET): Type mismatch: cannot convert from List to List + public void test0464() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Zork z;\n" + + " public static void main(String[] args) {\n" + + " List[] nums = new List[] {Collections.singletonList(\"Uh oh\")};\n" + + " System.out.println(nums[0].get(0).intValue());\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " List[] nums = new List[] {Collections.singletonList(\"Uh oh\")};\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List[] needs unchecked conversion to conform to List[]\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82547 + public void test0465() { + this.runNegativeTest( + new String[] { + "Cla.java", + "class Cla {\n" + + " T getT() {\n" + + " return null;\n" + + " }\n" + + " \n" + + " void m() {\n" + + " String s= new Cla.getT();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Cla.java (at line 7)\n" + + " String s= new Cla.getT();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cla.getT cannot be resolved to a type\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83096 + public void test0466() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X { }\n" + + " ^\n" + + "Duplicate type parameter A\n" + + "----------\n" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 + public void test0467() { + this.runConformTest( + new String[] { + "test/Foo.java", + "package test; \n" + + "public class Foo { \n" + + " protected String s; \n" + + " protected String dosomething(){ return \"done\"; } \n" + + " protected class Bar {} \n" + + "} \n", + "test02/FooBar.java", + "package test02; \n" + + "import test.Foo; \n" + + "public class FooBar extends Foo { \n" + + " void fail() { \n" + + " FooBar f = new FooBar(); \n" + + " f.s = \"foo\"; \n" + + " this.s = \"foo\";\n" + + " f.dosomething(); \n" + + " this.dosomething(); \n" + + " Bar b1; \n" + + " FooBar.Bar b2; \n" + + " Foo.Bar b3; \n" + + " } \n" + + "}\n" + }, + "" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 - variation + public void test0468() { + this.runConformTest( + new String[] { + "test/Foo.java", + "package test; \n" + + "public class Foo { \n" + + " String s; \n" + + " String dosomething(){ return \"done\"; } \n" + + " class Bar {} \n" + + "} \n", + "test/FooBar.java", + "package test; \n" + + "import test.Foo; \n" + + "public class FooBar extends Foo { \n" + + " void fail() { \n" + + " FooBar f = new FooBar(); \n" + + " f.s = \"foo\"; \n" + + " this.s = \"foo\";\n" + + " f.dosomething(); \n" + + " this.dosomething(); \n" + + " Bar b1; \n" + + " FooBar.Bar b2; \n" + + " Foo.Bar b3; \n" + + " } \n" + + "}\n" + }, + "" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83083 + public void test0469() { + this.runConformTest( + new String[] { + "a/C.java", + "package a; \n" + + "import p.B; \n" + + "public class C extends B { \n" + + " public void foo(Object obj) {} \n" + + "} \n", + "p/B.java", + "package p; \n" + + "public class B extends A {} \n", + "p/A.java", + "package p; \n" + + "public class A { \n" + + " public void foo(E e) {} \n" + + "}\n", + }, + "" + ); + this.runConformTest( + new String[] { + "a/C.java", + "package a; \n" + + "import p.B; \n" + + "public class C extends B { \n" + + " public void foo(Object obj) {} \n" + + "} \n", + "p/A.java", + "package p; \n" + + "public class A { \n" + + " public void foo(E e) {} \n" + + "}\n", + }, + "", + null, + false, // do not flush output + null); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83225 + public void test0470() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static T choose(boolean b, T t1, T t2) {\n" + + " if (b)\n" + + " return t1;\n" + + " return t2;\n" + + " }\n" + + "\n" + + " public static void foo() {\n" + + " Comparable s1 = choose(true, \"string\", Integer.valueOf(1));\n" + + " Number s2 = choose(true, Integer.valueOf(1), Float.valueOf(2));\n" + + " Comparable s3 = choose(true, Integer.valueOf(1), Float.valueOf(2));\n" + + " Cloneable s4 = choose(true, Integer.valueOf(1), Float.valueOf(2));\n" + + " Cloneable s5 = choose(true, \"string\", Integer.valueOf(1));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Comparable s1 = choose(true, \"string\", Integer.valueOf(1));\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " Comparable s3 = choose(true, Integer.valueOf(1), Float.valueOf(2));\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " Cloneable s4 = choose(true, Integer.valueOf(1), Float.valueOf(2));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from "+intersection("Number","Comparable")+" to Cloneable\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " Cloneable s5 = choose(true, \"string\", Integer.valueOf(1));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from "+intersection("Object","Serializable","Comparable")+" to Cloneable\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 - variation + public void test0471() { + this.runNegativeTest( + new String[] { + "test/Foo.java", + "package test; \n" + + "public class Foo { \n" + + " protected R s; \n" + + " protected R dosomething(){ return s; } \n" + + " protected class Bar {} \n" + + "} \n", + "test02/FooBar.java", + "package test02; \n" + + "import test.Foo; \n" + + "public class FooBar extends Foo { \n" + + " void fail() { \n" + + " FooBar f = new FooBar(); \n" + + " f.s = \"foo\"; \n" + + " this.s = \"foo\";\n" + + " f.dosomething(); \n" + + " this.dosomething(); \n" + + " Bar b1; \n" + + " FooBar.Bar b2; \n" + + " Foo.Bar b3; \n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test02\\FooBar.java (at line 7)\n" + + " this.s = \"foo\";\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from String to R\n" + + "----------\n" ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82671 - variation + public void test0472() { + this.runNegativeTest( + new String[] { + "test/Foo.java", + "package test; \n" + + "public class Foo { \n" + + " private R s; \n" + + " private R dosomething(){ return s; } \n" + + " private class Bar {} \n" + + "} \n", + "test02/FooBar.java", + "package test02; \n" + + "import test.Foo; \n" + + "public class FooBar extends Foo { \n" + + " void fail() { \n" + + " FooBar f = new FooBar(); \n" + + " f.s = \"foo\"; \n" + + " this.s = \"foo\";\n" + + " f.dosomething(); \n" + + " this.dosomething(); \n" + + " Bar b1; \n" + + " FooBar.Bar b2; \n" + + " Foo.Bar b3; \n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test02\\FooBar.java (at line 6)\n" + + " f.s = \"foo\"; \n" + + " ^\n" + + "The field Foo.s is not visible\n" + + "----------\n" + + "2. ERROR in test02\\FooBar.java (at line 7)\n" + + " this.s = \"foo\";\n" + + " ^\n" + + "The field Foo.s is not visible\n" + + "----------\n" + + "3. ERROR in test02\\FooBar.java (at line 7)\n" + + " this.s = \"foo\";\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from String to R\n" + + "----------\n" + + "4. ERROR in test02\\FooBar.java (at line 8)\n" + + " f.dosomething(); \n" + + " ^^^^^^^^^^^\n" + + "The method dosomething() from the type Foo is not visible\n" + + "----------\n" + + "5. ERROR in test02\\FooBar.java (at line 9)\n" + + " this.dosomething(); \n" + + " ^^^^^^^^^^^\n" + + "The method dosomething() from the type Foo is not visible\n" + + "----------\n" + + "6. ERROR in test02\\FooBar.java (at line 10)\n" + + " Bar b1; \n" + + " ^^^\n" + + "The type Bar is not visible\n" + + "----------\n" + + "7. ERROR in test02\\FooBar.java (at line 11)\n" + + " FooBar.Bar b2; \n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The type FooBar.Bar is not visible\n" + + "----------\n" + + "8. ERROR in test02\\FooBar.java (at line 12)\n" + + " Foo.Bar b3; \n" + + " ^^^^^^^^^^^^^^^\n" + + "The type Foo.Bar is not visible\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81594 + public void test0473() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X\n" + + "{\n" + + " List itsList;\n" + + " B itsB;\n" + + " MyTyped itsTyped;\n" + + " \n" + + " \n" + + " public void test()\n" + + " {\n" + + " method (itsList, itsB, itsTyped);\n" + + " }\n" + + " \n" + + " public void method (List arg1, T arg2, Typed arg3)\n" + + " {\n" + + " }\n" + + " \n" + + " interface A{}\n" + + " class B implements A{}\n" + + " class Typed{}\n" + + " class MyTyped extends Typed{}\n" + + "\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81594 - variation + public void test0474() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Typed itsList;\n" + + " Typed itsTyped;\n" + + " public void test() {\n" + + " method(itsList, itsTyped);\n" + + " }\n" + + " public void method(Typed arg1, Typed arg3) {\n" + + " }\n" + + " interface A {\n" + + " }\n" + + " class B implements A {\n" + + " }\n" + + " class Typed {\n" + + " }\n" + + "}\n" + }, + ""); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 + public void test0475() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void method(List list) {\n" + + " list.add(new Object()); // should fail\n" + + " list.add(Integer.valueOf(3)); // correct\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " list.add(new Object()); // should fail\n" + + " ^^^\n" + + "The method add(capture#1-of ? super Number) in the type List is not applicable for the arguments (Object)\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0476() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void method(List list, List lo) {\n" + + " list = lo;\n" + + " lo = list;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lo = list;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0477() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List lhs;\n" + + " List rhs;\n" + + " {\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ? super T) in the type List is not applicable for the arguments (capture#2-of ? extends Number)\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0478() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List lhs;\n" + + " List rhs;\n" + + " {\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ? super Number) in the type List is not applicable for the arguments (capture#2-of ? super U)\n" + + "----------\n"); + } + + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0479() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List lhs;\n" + + " List rhs;\n" + + " {\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n" + }, + ""); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0480() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List lhs;\n" + + " List rhs;\n" + + " {\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ? super Integer) in the type List is not applicable for the arguments (capture#2-of ? extends Number)\n" + + "----------\n"); + } + + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83398 - variation + public void test0481() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List lhs;\n" + + " List rhs;\n" + + " {\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ? super Number) in the type List is not applicable for the arguments (capture#2-of ? super Integer)\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83799 + public void test0482() { + this.runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + " public void testEquals(final String x, T one, T two) {\n" + + " }\n" + + "\n" + + " public void testEqualsAlt(final String x, T1 one, T2 two) {\n" + + " }\n" + + "\n" + + " public interface Fooey {\n" + + " }\n" + + "\n" + + " public interface Bar extends Fooey {\n" + + " }\n" + + "\n" + + " public interface GenericFooey {\n" + + " }\n" + + "\n" + + " public interface GenericBar extends GenericFooey {\n" + + " }\n" + + "\n" + + " public void testGeneric() {\n" + + " testEquals(\"Should work\", new GenericBar() {\n" + + " }, new GenericBar() {\n" + + " });\n" + + " final GenericBar child = new GenericBar() {\n" + + " };\n" + + " final GenericFooey parent = child;\n" + + " testEquals(\"Doesn\'t work but should\", child, parent); // this\n" + + " // fails\n" + + " // but should work it\'s identical to next line.\n" + + " testEquals(\"Doesn\'t work but should\", (GenericFooey) child, parent);\n" + + " testEqualsAlt(\"Should work\", child, parent);\n" + + " }\n" + + " public void test() {\n" + + " testEquals(\"Should work\", new Bar() {\n" + + " }, new Bar() {\n" + + " });\n" + + " final Bar child = new Bar() {\n" + + " };\n" + + " final Fooey parent = child;\n" + + " testEquals(\"Doesn\'t work but should\", child, parent);\n" + + " testEquals(\"Doesn\'t work but should\", (Fooey) child, parent);\n" + + " testEqualsAlt(\"Should work\", child, parent);\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83904 + public void test0483() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " m(new Y(), new Y());\n" + + " }\n" + + "\n" + + " public static void m(Y x, Y y) {\n" + + " }\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " m(new Y(), new Y());\n" + + " ^\n" + + "The method m(Y, Y) in the type X is not applicable for the arguments (Y, Y)\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82349 + public void test0484() { + this.runConformTest( + new String[] { + "X.java", + "class Base {\n" + + " public class Inner {\n" + + " }\n" + + " Inner a;\n" + + "}\n" + + "\n" + + "public class X extends Base {\n" + + " class DerivedInner extends Inner {\n" + + " }\n" + + " X() {\n" + + " a = new DerivedInner();\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82349 - variation + public void test0485() { + this.runConformTest( + new String[] { + "X.java", + "class Base {\n" + + " public class Inner {\n" + + " }\n" + + " Inner a;\n" + + "}\n" + + "\n" + + "public class X extends Base {\n" + + " class DerivedInner extends Inner {\n" + + " }\n" + + " X() {\n" + + " a = new DerivedInner();\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=82349 - variation + public void test0486() { + this.runConformTest( + new String[] { + "X.java", + "class Base {\n" + + " public class Inner {\n" + + " }\n" + + " Inner a;\n" + + "}\n" + + "\n" + + "public class X extends Base {\n" + + " class DerivedInner extends Inner {\n" + + " }\n" + + " X() {\n" + + " a = new DerivedInner();\n" + + " }\n" + + "}\n" + }, + ""); + } + public void test0487() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " void foo(List ls) {\n" + + " List l = ls;\n" + + " bar(l, \"\"); \n" + + " }\n" + + " void bar(List l, T t) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " bar(l, \"\"); \n" + + " ^^^\n" + + "The method bar(List, T) in the type X is not applicable for the arguments (List, String)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 + public void test0488() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " Foo f2 = new Foo();\n" + + " f1.bar = f2.bar;\n" + + " }\n" + + " static class Foo {\n" + + " Bar bar = new Bar();\n" + + " }\n" + + " static class Bar {\n" + + " T t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " f1.bar = f2.bar;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from X.Bar to X.Bar\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 + public void test0489() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " f1.bar = f1.bar;\n" + + " }\n" + + " static class Foo {\n" + + " Bar bar = new Bar();\n" + + " }\n" + + " static class Bar {\n" + + " T t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " f1.bar = f1.bar;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from X.Bar to X.Bar\n" + + "----------\n"); + } + public void test0490() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " void foo(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void bar(X> lhs, X> rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " lhs.t = rhs.t;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from capture#4-of ? to capture#3-of ?\n" + + "----------\n"); + } + + public void test0491() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " void foo(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void bar(X> lhs, X> rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void baz(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void baz2(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void baz3(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + " void baz4(X lhs, X rhs) {\n" + + " lhs = rhs;\n" + + " lhs.t = rhs.t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " lhs.t = rhs.t;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from capture#4-of ? to capture#3-of ?\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " lhs = rhs;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "3. ERROR in X.java (at line 17)\n" + + " lhs.t = rhs.t;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from capture#14-of ? extends Number to capture#13-of ? extends Number\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " lhs = rhs;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "5. ERROR in X.java (at line 21)\n" + + " lhs.t = rhs.t;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from capture#18-of ? super Number to capture#17-of ? extends Number\n" + + "----------\n" + + "6. ERROR in X.java (at line 25)\n" + + " lhs.t = rhs.t;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from capture#22-of ? super Number to capture#21-of ? super Number\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81576 + public void test0492() { + this.runConformTest( + new String[] { + "SuperType.java",//==================================== + "public class SuperType {\n" + + " protected InnerType valueWrapper;\n" + + " protected class InnerType {\n" + + " private T value;\n" + + " protected InnerType(T value) {\n" + + " this.value = value;\n" + + " }\n" + + " }\n" + + " public SuperType(T value) {\n" + + " /*\n" + + " * This constructor exists only to show that the usage of the inner\n" + + " * class within its enclosing class makes no problems\n" + + " */\n" + + " this.valueWrapper = new InnerType(value);\n" + + " }\n" + + " protected SuperType() {\n" + + " // Provided for the convenience of subclasses\n" + + " }\n" + + "}\n", + "SubType.java",//==================================== + "public class SubType extends SuperType {\n" + + "\n" + + " public SubType(T value) {\n" + + "\n" + + " /* The constructor SuperType .InnerType(T) is undefined */\n" + + " InnerType localValueWrapper = new InnerType(value);\n" + + "\n" + + " /*\n" + + " * Type mismatch: cannot convert from SuperType .InnerType to\n" + + " * SuperType .InnerType\n" + + " * \n" + + " * Type safety: The expression of raw type SuperType.InnerType is\n" + + " * converted to SuperType .InnerType. References to generic type\n" + + " * SuperType .InnerType should be parametrized.\n" + + " */\n" + + " localValueWrapper = super.valueWrapper;\n" + + " }\n" + + "\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83611 + public void test0493() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public class M { M(Class templateClass) {} }\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " void test() { M m = new M(X.class); }\n" + + "}\n" + }, + "" + ); + this.runConformTest( + new String[] { + "Y.java", + "public class Y extends X {\n" + + " void test() { M m = new M(X.class); }\n" + + "}\n" + }, + "", + null, + false, + null + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83615 + public void test0494() { + String xSource = + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Number n= null;\n" + + " Integer i= null;\n" + + " new X().nextTry(i, n);\n" + + " new X().nextTry2(n, i);\n" + + " } \n" + + " \n" + + " void nextTry(I i, N n) {}\n" + + " \n" + + " void nextTry2(N n, I i) {} \n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new X().nextTry(i, n);\n" + + " ^^^^^^^\n" + + "Bound mismatch: The generic method nextTry(I, N) of type X is not applicable for the arguments (Integer, Number). The inferred type Number is not a valid substitute for the bounded parameter \n" + + "----------\n"); + } else { + runConformTest(new String[] { "X.java", xSource }); + } + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84422 + public void test0495() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " List l= null; \n" + + "\n" + + " void add(String s) {\n" + + " l.add(s);\n" + + " }\n" + + " \n" + + " void addAll(String[] ss) {\n" + + " l.addAll(Arrays.asList(ss));\n" + + " }\n" + + " \n" + + " String[] get() {\n" + + " return (String[])l.toArray(new String[l.size()]);\n" + + " }\n" + + "}\n" + }, + ""); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84593 + public void test0496() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "class Super {\n" + + " class A { }\n" + + " void take(A o) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class Sub extends Super {\n" + + " void test() {\n" + + " take(new A());\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Sub().test();\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84593 - variation - uncheck warnings + public void test0497() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "class Super {\n" + + " class A { }\n" + + " void take(A o) {\n" + + " }\n" + + "}\n" + + "class Sub extends Super {\n" + + " void test() {\n" + + " take(new A());\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Sub().test();\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " take(new A());\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation take(Super.A) of the generic method take(Super.A) of type Super\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " take(new A());\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type Super.A needs unchecked conversion to conform to Super.A\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " take(new A());\n" + + " ^\n" + + "Super.A is a raw type. References to generic type Super.A should be parameterized\n" + + "----------\n" + + "4. 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=84743 - variation in -source 1.4 mode but 1.5 compliance (ignore covariance) +public void test0498(){ + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " Object foo();\n" + + "}\n" + + " \n" + + "public class X implements I {\n" + + " public String foo() {\n" + + " return \"\";\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = new X();\n" + + " try {\n" + + " J j = (J) i;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 15)\n" + + " J j = (J) i;\n" + + " ^^^^^\n" + + "Cannot cast from I to J\n" + + "----------\n", + // javac options + RUN_JAVAC ? /* javac test options */ + new JavacTestOptions("-source 1.4") : + JavacTestOptions.DEFAULT ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=85157 +public void test0499(){ + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " String[] tab1 = new String[0];\n" + + " Integer[] tab2 = new Integer[0];\n" + + " boolean cond = true;\n" + + " Integer[] var = cond ? tab1 : tab2;\n" + + " System.out.println(var);\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Integer[] var = cond ? tab1 : tab2;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object&Serializable&" + + "" + intersection("Comparable") + ">") + + "[] to Integer[]\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Integer[] var = cond ? tab1 : tab2;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from String[] to Integer[]\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=84251 +public void test0500(){ + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "\n" + + "interface Sink { \n" + + " void flush(T t);\n" + + "}\n" + + "class SimpleSinkImpl implements Sink {\n" + + " public void flush(T t) {}\n" + + "}\n" + + "public class X {\n" + + "\n" + + " private T writeAll(Collection coll, Sink snk) { \n" + + " T last = null;\n" + + " for (T t : coll) { \n" + + " last = t;\n" + + " snk.flush(last);\n" + + " }\n" + + " return last;\n" + + " }\n" + + "\n" + + " public void test01() {\n" + + " Sink s = new SimpleSinkImpl();\n" + + " Collection cs = new ArrayList();\n" + + " cs.add(\"hello!\");\n" + + " cs.add(\"goodbye\");\n" + + " cs.add(\"see you\");\n" + + " \n" + + " String str = this.writeAll(cs, s); \n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X test = new X();\n" + + " \n" + + " test.test01();\n" + + " }\n" + + "}\n" + }, + ""); +} + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation + public void test0501() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X>(new BX());\n" + + " System.out.print(x.t.ax);\n" + + " System.out.print(x.t.bx);\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " P ax;\n" + + "}\n" + + "\n" + + "class BX extends AX {\n" + + " Q bx;\n" + + "}\n", + }, + "nullnull"); + String expectedOutput = + " // Method descriptor #25 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 new BX [26]\n" + + " 7 dup\n" + + " 8 invokespecial BX() [28]\n" + + " 11 invokespecial X(AX) [29]\n" + + " 14 astore_1 [x]\n" + + " 15 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + + " 18 aload_1 [x]\n" + + " 19 getfield X.t : AX [16]\n" + + " 22 checkcast BX [26]\n" + + " 25 getfield BX.ax : java.lang.Object [37]\n" + + " 28 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [41]\n" + + " 31 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + + " 34 aload_1 [x]\n" + + " 35 getfield X.t : AX [16]\n" + + " 38 checkcast BX [26]\n" + + " 41 getfield BX.bx : java.lang.Object [47]\n" + + " 44 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [41]\n" + + " 47 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 31, line: 9]\n" + + " [pc: 47, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 48] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 15, pc: 48] local: x index: 1 type: X\n" + + " Local variable type table:\n" + + " [pc: 15, pc: 48] local: x index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation + public void test0502() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " X(T t){\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X>(new BX());\n" + + " System.out.print(x.self().t.ax);\n" + + " System.out.print(x.self().t.bx);\n" + + " }\n" + + " X self() {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " P ax;\n" + + "}\n" + + "\n" + + "class BX extends AX {\n" + + " Q bx;\n" + + "}\n", + }, + "nullnull"); + String expectedOutput = + " // Method descriptor #25 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 new BX [26]\n" + + " 7 dup\n" + + " 8 invokespecial BX() [28]\n" + + " 11 invokespecial X(AX) [29]\n" + + " 14 astore_1 [x]\n" + + " 15 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + + " 18 aload_1 [x]\n" + + " 19 invokevirtual X.self() : X [37]\n" + + " 22 getfield X.t : AX [16]\n" + + " 25 checkcast BX [26]\n" + + " 28 getfield BX.ax : java.lang.Object [41]\n" + + " 31 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [45]\n" + + " 34 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + + " 37 aload_1 [x]\n" + + " 38 invokevirtual X.self() : X [37]\n" + + " 41 getfield X.t : AX [16]\n" + + " 44 checkcast BX [26]\n" + + " 47 getfield BX.bx : java.lang.Object [51]\n" + + " 50 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [45]\n" + + " 53 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 34, line: 9]\n" + + " [pc: 53, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 54] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 15, pc: 54] local: x index: 1 type: X\n" + + " Local variable type table:\n" + + " [pc: 15, pc: 54] local: x index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation + public void test0503() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class XA {}\n" + + "interface XB {\n" + + " XB CONST = new XB(){ public String toString() { return \"SUCCESS\"; }};\n" + + "}\n" + + "class XAB extends XA implements XB {}\n" + + "\n" + + "public class X {\n" + + " E e;\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new X().e.CONST);\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " System.out.print(this.e.CONST);\n" + + " }\n" + + "}\n", + }, + "SUCCESSSUCCESS"); + String expectedOutput = + "// Signature: Ljava/lang/Object;\n" + + "public class X {\n" + + " \n" + + " // Field descriptor #6 LXA;\n" + + " // Signature: TE;\n" + + " XA e;\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #21 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 3 new X [1]\n" + + " 6 dup\n" + + " 7 invokespecial X() [28]\n" + + " 10 getfield X.e : XA [29]\n" + + " 13 checkcast XAB [31]\n" + + " 16 pop\n" + + " 17 getstatic XAB.CONST : XB [33]\n" + + " 20 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + + " 23 new X [1]\n" + + " 26 dup\n" + + " 27 invokespecial X() [28]\n" + + " 30 invokevirtual X.foo() : void [43]\n" + + " 33 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 23, line: 11]\n" + + " [pc: 33, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 34] local: args index: 0 type: java.lang.String[]\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public void foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 3 aload_0 [this]\n" + + " 4 getfield X.e : XA [29]\n" + + " 7 checkcast XB [48]\n" + + " 10 pop\n" + + " 11 getstatic XB.CONST : XB [50]\n" + + " 14 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 17, line: 15]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation + public void test0504() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class XA {}\n" + + "interface XB {\n" + + " XB CONST = new XB(){ public String toString() { return \"SUCCESS\"; }};\n" + + "}\n" + + "class XAB extends XA implements XB {}\n" + + "\n" + + "public class X {\n" + + " E e() { return null; }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new X().e().CONST);\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " System.out.print(this.e().CONST);\n" + + " }\n" + + "}\n", + }, + "SUCCESSSUCCESS"); + String expectedOutput = + "// Signature: Ljava/lang/Object;\n" + + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #17 ()LXA;\n" + + " // Signature: ()TE;\n" + + " // Stack: 1, Locals: 1\n" + + " XA e();\n" + + " 0 aconst_null\n" + + " 1 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 2] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 2] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #21 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 3 new X [1]\n" + + " 6 dup\n" + + " 7 invokespecial X() [28]\n" + + " 10 invokevirtual X.e() : XA [29]\n" + + " 13 checkcast XAB [31]\n" + + " 16 pop\n" + + " 17 getstatic XAB.CONST : XB [33]\n" + + " 20 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + + " 23 new X [1]\n" + + " 26 dup\n" + + " 27 invokespecial X() [28]\n" + + " 30 invokevirtual X.foo() : void [43]\n" + + " 33 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 23, line: 11]\n" + + " [pc: 33, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 34] local: args index: 0 type: java.lang.String[]\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public void foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 3 aload_0 [this]\n" + + " 4 invokevirtual X.e() : XA [29]\n" + + " 7 checkcast XB [48]\n" + + " 10 pop\n" + + " 11 getstatic XB.CONST : XB [50]\n" + + " 14 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [37]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 17, line: 15]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85303 - variation + public void test0505() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class XA {}\n" + + "interface XB {\n" + + " XB CONST = new XB(){ public String toString() { return \"SUCCESS\"; }};\n" + + "}\n" + + "class XAB extends XA implements XB {}\n" + + "\n" + + "public class X {\n" + + " E e;\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " new Object() {\n" + + " void run() {\n" + + " System.out.print(e.CONST);\n" + + " }\n" + + " }.run();\n" + + " System.out.print(e.CONST);\n" + + " }\n" + + "}\n", + }, + "SUCCESSSUCCESS"); + String expectedOutput = + "// Signature: Ljava/lang/Object;\n" + + "public class X {\n" + + " \n" + + " // Field descriptor #6 LXA;\n" + + " // Signature: TE;\n" + + " XA e;\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #21 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 invokespecial X() [22]\n" + + " 7 invokevirtual X.foo() : void [23]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 10, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: args index: 0 type: java.lang.String[]\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 3, Locals: 1\n" + + " public void foo();\n" + + " 0 new X$1 [28]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 invokespecial X$1(X) [30]\n" + + " 8 invokevirtual X$1.run() : void [33]\n" + + " 11 getstatic java.lang.System.out : java.io.PrintStream [36]\n" + + " 14 aload_0 [this]\n" + + " 15 getfield X.e : XA [42]\n" + + " 18 checkcast XB [44]\n" + + " 21 pop\n" + + " 22 getstatic XB.CONST : XB [46]\n" + + " 25 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [50]\n" + + " 28 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 8, line: 17]\n" + + " [pc: 11, line: 18]\n" + + " [pc: 28, line: 19]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 29] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 29] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85477 + public void test0506() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "import java.util.Collections;\n" + + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "\n" + + "public final class X {\n" + + " public void test(List list,final Comparator comparator, X x) {\n" + + " foo(list, comparator);\n" + + " bar(list, comparator);\n" + + " \n" + + " x.foo(list, comparator);\n" + + " x.bar(list, comparator);\n" + + " }\n" + + "\n" + + " void foo(List lt, Comparator ct) {\n" + + " }\n" + + " static void bar(List lt, Comparator ct) {\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public void test(List list,final Comparator comparator, X x) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public void test(List list,final Comparator comparator, X x) {\n" + + " ^^^^^^^^^^\n" + + "Comparator is a raw type. References to generic type Comparator should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " public void test(List list,final Comparator comparator, X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " foo(list, comparator);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List, Comparator) of the generic method foo(List, Comparator) of type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " foo(list, comparator);\n" + + " ^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " foo(list, comparator);\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator\n" + + "----------\n" + + "7. WARNING in X.java (at line 8)\n" + + " bar(list, comparator);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, Comparator) of the generic method bar(List, Comparator) of type X\n" + + "----------\n" + + "8. WARNING in X.java (at line 8)\n" + + " bar(list, comparator);\n" + + " ^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "9. WARNING in X.java (at line 8)\n" + + " bar(list, comparator);\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator\n" + + "----------\n" + + "10. WARNING in X.java (at line 10)\n" + + " x.foo(list, comparator);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(List, Comparator) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 11)\n" + + " x.bar(list, comparator);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The static method bar(List, Comparator) from the type X should be accessed in a static way\n" + + "----------\n" + + "12. WARNING in X.java (at line 11)\n" + + " x.bar(list, comparator);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, Comparator) of the generic method bar(List, Comparator) of type X\n" + + "----------\n" + + "13. WARNING in X.java (at line 11)\n" + + " x.bar(list, comparator);\n" + + " ^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "14. WARNING in X.java (at line 11)\n" + + " x.bar(list, comparator);\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator\n" + + "----------\n" + + "15. ERROR in X.java (at line 18)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // array bound for wildcard + public void test0507() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo1(List l) {\n" + + " int i = l.get(0).length;\n" + + " }\n" + + " void foo2(List l) {\n" + + " Object o = l.get(0).toString();\n" + + " }\n" + + " void foo3(List l, Serializable s) {\n" + + " boolean b = true;\n" + + " Serializable s2 = b ? l.get(0) : s;\n" + + " }\n" + + "}\n" + }, + ""); + } + // array bound for wildcard + public void test0508() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo1(List l) {\n" + + " int i = l.get(0).length;\n" + + " }\n" + + " void foo2(List l) {\n" + + " Object o = l.get(0).toString();\n" + + " }\n" + + " void foo3(List l, Serializable s) {\n" + + " boolean b = true;\n" + + " Serializable s2 = b ? l.get(0) : s;\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int i = l.get(0).length;\n" + + " ^^^^^^\n" + + "length cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " Serializable s2 = b ? l.get(0) : s;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Serializable\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int i = l.get(0).length;\n" + + " ^^^^^^\n" + + "length cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " Serializable s2 = b ? l.get(0) : s;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#3-of ? super int[] to Serializable\n" + + "----------\n"); + } + // type parameter hiding + public void test0509() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " list.add(new MyTigerSimpleObject(\"a\"));\n" + + " list.add(new MyTigerSimpleObject(\"b\"));\n" + + " \n" + + " for (MyTigerSimpleObject so : list)\n" + + " System.out.println(so.getSomeAttribute()); \n" + + " }\n" + + "}\n" + + "class MyTigerSimpleObject {\n" + + " MyTigerSimpleObject(String s) {}\n" + + " E getSomeAttribute() { return null; }\n" + + "}\n" + + "\n" + + "class TigerList extends ArrayList {\n" + + " public void listAll() {\n" + + " for (MyTigerSimpleObject so : this)\n" + + " System.out.println(so.getSomeAttribute());\n" + + " }\n" + + " \n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List list = new ArrayList();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " List list = new ArrayList();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " list.add(new MyTigerSimpleObject(\"a\"));\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " list.add(new MyTigerSimpleObject(\"b\"));\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " for (MyTigerSimpleObject so : list)\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "MyTigerSimpleObject is a raw type. References to generic type MyTigerSimpleObject should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 17)\n" + + " class TigerList extends ArrayList {\n" + + " ^^^^^^^^^\n" + + "The serializable class TigerList does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "7. WARNING in X.java (at line 17)\n" + + " class TigerList extends ArrayList {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type parameter MyTigerSimpleObject is hiding the type MyTigerSimpleObject\n" + + "----------\n" + + "8. ERROR in X.java (at line 20)\n" + + " System.out.println(so.getSomeAttribute());\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method getSomeAttribute() is undefined for the type MyTigerSimpleObject\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84355 + public void test0510() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " public X() {\n" + + " String[] strings = new String[]{\"test\"};\n" + + "\n" + + " // this fails\n" + + " Object obj = ClassB.doSomething((String) strings[0]);\n" + + "\n" + + " // this works fine\n" + + " String intermediate = ClassB.doSomething((String) strings[0]);\n" + + " Object obj1 = intermediate;\n" + + " }\n" + + "}\n" + + "\n" + + "class ClassB {\n" + + " public static T doSomething(String value) {\n" + + " return (T) value;\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82407 + public void test0511() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "import java.util.HashMap;\n" + + "\n" + + "public class X {\n" + + "\n" + + " static HashMap substitutionList(String s1, String s2) {\n" + + "\n" + + " HashMap subst = new HashMap();\n" + + "\n" + + " for (int i = 0; i < s1.length(); i++) {\n" + + " char key = s1.charAt(i);\n" + + " char value = s2.charAt(i);\n" + + " if (subst.containsKey(key)) {\n" + + " if (value != subst.get(key)) {\n" + + " return null;\n" + + " }\n" + + " } else if (subst.containsValue(value)) {\n" + + " return null;\n" + + " } else {\n" + + " subst.put(key, value);\n" + + " }\n" + + " }\n" + + "\n" + + " return subst;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0512() { + this.runConformTest( + new String[] { + "X.java",//==================================== + "public class X { \n" + + " public static void main(String argv[]) {\n" + + " \n" + + " new X().new M(null) {\n" + + " void run() {\n" + + " Exception e = ex;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " class M {\n" + + " E ex;\n" + + " M(E ex) {\n" + + " this.ex = ex;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0513() { + this.runNegativeTest( + new String[] { + "X.java",//==================================== + "public class X { \n" + + " public static void main(String argv[]) {\n" + + " \n" + + " new X().new M(null) {\n" + + " void run() {\n" + + " Exception e = ex;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " class M {\n" + + " E ex;\n" + + " M(E ex) {\n" + + " this.ex = ex;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new X().new M(null) {\n" + + " void run() {\n" + + " Exception e = ex;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }.run();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor X.M(Throwable) belongs to the raw type X.M. References to generic type X.M should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " new X().new M(null) {\n" + + " ^\n" + + "X.M is a raw type. References to generic type X.M should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " new X().new M(null) {\n" + + " ^^^^^^^\n" + + "Type safety: The constructor X.M(Throwable) belongs to the raw type X.M. References to generic type X.M should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Exception e = ex;\n" + + " ^^\n" + + "Type mismatch: cannot convert from Throwable to Exception\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82955 + public void test0514(){ + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static T infer( T t1, T t2 ) { return null; }\n" + + " public static void main( String [] args ) {\n" + + " Base base = infer( new Sub1(), new Sub2() );\n" + + " // Note: Eclipse 3.1 says this is an error, but it\'s not\n" + + " Runnable runnable = infer( new Sub1(), new Sub2() );\n" + + " }\n" + + "}\n" + + "class Base { }\n" + + "class Sub1 extends Base implements Runnable { public void run() { } }\n" + + "class Sub2 extends Base implements Runnable { public void run() { } }\n" + } + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84348 + public void test0515(){ + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public static void myMethod(final List fileList) {\n" + + " Collections.sort(fileList, new Comparator(){\n" + + " public int compare(File f1, File f2) { return 0; }\n" + + " });\n" + + " }\n" + + "}\n" + + "\n" + + "class List {}\n" + + "class File {}\n" + + "interface Comparator {}\n" + + "class Collections {\n" + + " static void sort(List list, Comparator c) {}\n" + + "}" + } + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84944 + public void test0516(){ + runConformTest( + new String[] { + "parser/AbstractParser.java", + "package parser;\n" + + "public abstract class AbstractParser implements ValueParser {\n" + + " public T parse( final String string ) {\n" + + " return valueOf(string); \n" + + " }\n" + + " protected abstract T valueOf(final String string); \n" + + "}\n" + + "interface ValueParser {\n" + + " T parse(final String string);\n" + + "}\n", + "parser/BooleanParser.java", + "package parser;\n" + + "public class BooleanParser extends AbstractParser {\n" + + " protected Boolean valueOf(final String string ) {\n" + + " return Boolean.valueOf(string); \n" + + " }\n" + + "}\n" + } + ); + runConformTest( + new String[] { + "test/BooleanParserTest.java", + "package test;\n" + + "import parser.BooleanParser;\n" + + "public class BooleanParserTest {\n" + + " static final boolean getBoolean(final String value) {\n" + + " return new BooleanParser().parse(value).booleanValue(); // The type Boolean is not visible\n" + + " }\n" + + "}\n" + }, + null, + null, + false, // do not flush output directory + null + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84944 - check no warning for using raw member + public void test0517(){ + runNegativeTest( + new String[] { + "X.java", + "class Base {\n" + + " class InnerBase {\n" + + " java.util.List list;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "\n" + + "public class X extends Base {\n" + + " class InnerDerived extends InnerBase {\n" + + " void method() {\n" + + " list.add(\"Hi\"); // Warning on this method call\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. 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=85930 - check no warning for using raw member + public void test0518(){ + runNegativeTest( + new String[] { + "X.java", + "interface Callable {\n" + + " public enum Result {\n" + + " GOOD, BAD\n" + + " };\n" + + " public Result call(T arg);\n" + + "}\n" + + "\n" + + "public class X implements Callable {\n" + + " public Result call(String arg) {\n" + + " return Result.GOOD;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85262 + public void test0519(){ + runConformTest( + new String[] { + "FooImpl.java", + "interface Bar> {} \n" + + " \n" + + "class BarImpl> implements Bar {} \n" + + " \n" + + "interface Foo> extends Bar {} \n" + + " \n" + + "public class FooImpl> extends BarImpl implements Foo {}\n" + + "\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85262 - variation + public void test0520(){ + runConformTest( + new String[] { + "Bar.java", + "public interface Bar> {} \n", + "BarImpl.java", + "public class BarImpl> implements Bar {} \n", + "Foo.java", + "public interface Foo> extends Bar {} \n", + }, + ""); + runConformTest( + new String[] { + "FooImpl.java", + "public class FooImpl> extends BarImpl implements Foo {}\n", + }, + "", + null, + false, // do not flush output directory + null); + } + public void test0521(){ + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " static public void addAll(T a, T b) {\n" + + " a.addAll(b);\n" + + " }\n" + + " static public void main(String[] args) {\n" + + " Collection a = new ArrayList();\n" + + " Collection b = new ArrayList();\n" + + " b.add(\"string\");\n" + + " addAll(a, b);\n" + + " try {\n" + + " System.out.println(a.iterator().next().intValue()); // ClassCastException\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + // variation on test0521, check issuing of unchecked warning ** + public void test0522(){ + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " static public void addAll(T a, T b) {\n" + + " a.addAll(b);\n" + + " }\n" + + " static public void main(String[] args) {\n" + + " Collection a = new ArrayList();\n" + + " Collection b = new ArrayList();\n" + + " b.add(\"string\");\n" + + " addAll(a, b);\n" + + " try {\n" + + " System.out.println(a.iterator().next().intValue()); // ClassCastException\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " static public void addAll(T a, T b) {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " a.addAll(b);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: The method addAll(Collection) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0523(){ + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public X() {\n" + + " M m = new M();\n" + + " List ls = m.list(); // rawified even though wasn\'t using T parameter\n" + + " }\n" + + " Zork z;\n" + + " static class M {\n" + + " List list() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " M m = new M();\n" + + " ^\n" + + "X.M is a raw type. References to generic type X.M should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " M m = new M();\n" + + " ^\n" + + "X.M is a raw type. References to generic type X.M should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " List ls = m.list(); // rawified even though wasn\'t using T parameter\n" + + " ^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ensure there is no unchecked warning ** + public void test0524(){ + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class MyList extends ArrayList {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List a = new MyList();\n" + + " List b = (MyList) a; \n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " class MyList extends ArrayList {\n" + + " ^^^^^^\n" + + "The serializable class MyList does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0525(){ + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " List list = new ArrayList();\n" + + " String s = \"this shouldn\'t work\";\n" + + " list.add(s);\n" + + " List listInt = list;\n" + + " int i = listInt.get(0);\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + public void test0526(){ + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " T f(Object o) {\n" + + " return (T) o; // OK\n" + + " }\n" + + "\n" + + " T g(Object o) {\n" + + " return (T) o; // bug???\n" + + " }\n" + + "\n" + + " T h(Object o) {\n" + + " return X.castTo(o); // workaround\n" + + " }\n" + + "\n" + + " private static T castTo(Object o) {\n" + + " return (T) o;\n" + + " }\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" + + "2. WARNING in X.java (at line 4)\n" + + " return (T) o; // OK\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " return (T) o; // bug???\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "4. WARNING in X.java (at line 16)\n" + + " return (T) o;\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n"); + } + // should not produce unchecked errors ** + public void test0527(){ + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo(U u, V v) {\n" + + " return this == null ? (T) u : (T)v;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. 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=86217 + public void test0528() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {}\n" + + "class Y { static class M {} }\n", + }, + "" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86463 + public void test0529() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void bar() {\n" + + " T t = new ArrayList(); // BUG!!!\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public class X {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " T t = new ArrayList(); // BUG!!!\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from ArrayList to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " T t = new ArrayList(); // BUG!!!\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86463 + public void test0530() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "abstract class Foo\n" + + " {\n" + + " abstract void foo(T t);\n" + + " void foo2()\n" + + " {\n" + + " List l = new LinkedList();\n" + + " foo(l); // BUG!!!\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends Foo\n" + + "{\n" + + " void foo(ArrayList l)\n" + + " {\n" + + " System.out.println(l);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " abstract class Foo\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " List l = new LinkedList();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " List l = new LinkedList();\n" + + " ^^^^^^^^^^\n" + + "LinkedList is a raw type. References to generic type LinkedList should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " foo(l); // BUG!!!\n" + + " ^^^\n" + + "The method foo(T) in the type Foo is not applicable for the arguments (List)\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " public class X extends Foo\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 15)\n" + + " void foo(ArrayList l)\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method foo(ArrayList) of type X should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "7. WARNING in X.java (at line 15)\n" + + " void foo(ArrayList l)\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86646 + public void test0531() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "\n" + + "public class X {\n" + + " public T f1(T l) {\n" + + " Vector v = new Vector();\n" + + " v.add(l);\n" + + " return (T) v.get(0); // Expect warning here\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " return (T) v.get(0); // Expect warning here\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from T to T\n" + + "----------\n" + + "2. 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=84944 + public void test0532() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X extends Z {\n" + + " @Override public Boolean value() { return true; }\n" + + "}\n" + + "abstract class Z {\n" + + " public T foo() { return value(); }\n" + + " public abstract T value();\n" + + "}\n", + }, + "" + ); + this.runConformTest( + new String[] { + "Y.java", + "import p.X;\n" + + "public class Y { boolean test() { return new X().foo().booleanValue(); } }\n", + }, + "", + null, + false, // do not flush output + null + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 + public void test0533() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Class c = Foo.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^^^^\n" + + "Bound mismatch: The type Enum is not a valid substitute for the bounded parameter > of the type EnumSet\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type EnumSet needs unchecked conversion to conform to EnumSet\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + : "Type safety: The expression of type Class needs unchecked conversion to conform to Class>>\n") + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0534() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " }\n" + + "}\n", + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0535() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " }\n" + + "}\n", + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0536() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet eSet = (EnumSet) EnumSet.allOf(c);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Class c = Foo.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = (EnumSet) EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from EnumSet to EnumSet\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = (EnumSet) EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = (EnumSet) EnumSet.allOf(c);\n" + + " ^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class>>\n" + + "----------\n" + + "5. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0537() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Class c = Foo.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " EnumSet eSet = EnumSet.allOf(c);\n" + + " ^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class>>\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0538() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.EnumSet;\n" + + "\n" + + "enum Foo {\n" + + " blargh, baz, boz;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Foo.class;\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Class c = Foo.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^^^^\n" + + "Bound mismatch: The type Enum is not a valid substitute for the bounded parameter > of the type EnumSet\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type EnumSet needs unchecked conversion to conform to EnumSet>\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class>\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Class c = Foo.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^^^^\n" + + "Bound mismatch: The type Enum is not a valid substitute for the bounded parameter > of the type EnumSet\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type EnumSet needs unchecked conversion to conform to EnumSet>\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " EnumSet> eSet = EnumSet.allOf(c);\n" + + " ^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class>>\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86838 - variation + public void test0539() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class B {\n" + + " public T willBe(Class c) {\n" + + " return (T)null;\n" + + " }\n" + + " }\n" + + " interface I1 {\n" + + " }\n" + + " interface I2 extends I1 {\n" + + " }\n" + + " \n" + + " public static void m1(String[] args) {\n" + + " B b = new B();\n" + + " I2 v = b.willBe(I2.class);\n" + + " }\n" + + " public static void m2(String[] args) {\n" + + " B b = new B();\n" + + " I2 v = b.willBe(I2.class);\n" + + " }\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return (T)null;\n" + + " ^^^^^^^\n" + + "Unnecessary cast from null to T\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " B b = new B();\n" + + " ^\n" + + "X.B is a raw type. References to generic type X.B should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 13)\n" + + " B b = new B();\n" + + " ^\n" + + "X.B is a raw type. References to generic type X.B should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 14)\n" + + " I2 v = b.willBe(I2.class);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method willBe(Class) belongs to the raw type X.B. References to generic type X.B should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " I2 v = b.willBe(I2.class);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.I1 to X.I2\n" + + "----------\n"); + } + // test paramtype argument compatibility + public void test0540() { + this.runNegativeTest( + new String[] { + "Baz.java", + "import java.util.*;\n" + + "interface Foo {}\n" + + "interface Bar extends Foo {\n" + + "}\n" + + "public class Baz {\n" + + " public R visit(Collection> trees, D d) {\n" + + " return null;\n" + + " }\n" + + " R test(Collection c, D d) {\n" + + " return visit(c, d);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Baz.java (at line 3)\n" + + " interface Bar extends Foo {\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" + + "2. ERROR in Baz.java (at line 10)\n" + + " return visit(c, d);\n" + + " ^^^^^\n" + + "The method visit(Collection>, D) in the type Baz is not applicable for the arguments (Collection, D)\n" + + "----------\n"); + } + public void test0541() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map m = null;\n" + + " try {\n" + + " Map m2 = m.getClass().newInstance();\n" + + " } catch(Exception e) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0542() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static boolean isOK(T x) {\n" + + " return isOK(x);\n" + + " }\n" + + "\n" + + " static boolean isStillOK(T x) {\n" + + " return true && isOK(x);\n" + + " }\n" + + "\n" + + " static boolean isNoMoreOK(T x) {\n" + + " return true && isNoMoreOK(x);\n" + + " }\n" + + "\n" + + " static boolean isOKAgain(T x) {\n" + + " boolean res;\n" + + " return true && (res = isOKAgain(x));\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0543() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object obj = null;\n" + + " List ls = (List) obj;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " List ls = (List) obj;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0544() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Vector a = new Vector();\n" + + " Vector b = new Vector();\n" + + " b.add(new Object());\n" + + " a = b;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Vector b = new Vector();\n" + + " ^^^^^^\n" + + "Vector is a raw type. References to generic type Vector should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " Vector b = new Vector();\n" + + " ^^^^^^\n" + + "Vector is a raw type. References to generic type Vector should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " b.add(new Object());\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type Vector. References to generic type Vector should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " a = b;\n" + + " ^\n" + + "Type safety: The expression of type Vector needs unchecked conversion to conform to Vector\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=86898 + public void test0545() { + this.runNegativeTest( + new String[] { + "X.java", + "class B extends A {\n" + + " void m2() {\n" + + " m3((X2) m()); // A.m() --> X - cannot cast to X2\n" + + " }\n" + + " void m3(X2 i) {}\n" + + "}\n" + + "class A {\n" + + " X m() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class X2 extends X {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void foo(X lhs, X rhs) {\n" + + " lhs = rhs; // cannot convert\n" + + " }\n" + + " void bar(X2 lhs, X rhs) {\n" + + " lhs = rhs; // cannot convert\n" + + " }\n" + + "}\n" + + "class C {\n" + + " void foo(X xo) {}\n" + + " void bar(X xs) {}\n" + + "}\n" + + "class D extends C {\n" + + " void foo(X xs) {}\n" + + " void bar(X xo) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " lhs = rhs; // cannot convert\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " lhs = rhs; // cannot convert\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X to X2\n" + + "----------\n" + + "3. ERROR in X.java (at line 29)\n" + + " void foo(X xs) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(X) of type D has the same erasure as foo(X) of type C but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 30)\n" + + " void bar(X xo) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method bar(X) of type D has the same erasure as bar(X) of type C but does not override it\n" + + "----------\n"); + } + // ensure no unsafe cast warning ** + public void test0546() { + this.runNegativeTest( + new String[] { + "X.java", + "class StringList extends java.util.LinkedList {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.List a = new StringList();\n" + + " java.util.List b = (StringList) a; // warned but safe.\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " class StringList extends java.util.LinkedList {\n" + + " ^^^^^^^^^^\n" + + "The serializable class StringList does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0547() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public TreeMap essai(K type) {\n" + + " TreeMap treeMap = new TreeMap();\n" + + " return treeMap;\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " X x = new X();\n" + + " TreeMap treeMap = x.essai(null);\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + public void test0548() { + this.runNegativeTest( + new String[] { + "X.java", + "interface DA {\n" + + "}\n" + + "interface DB extends DA {\n" + + "}\n" + + "interface DC extends DA {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Object o = (DC) (DA) null;\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Object o = (DC) (DA) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from DA to DC\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Object o = (DC) (DA) null;\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from null to DA\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ** + public void test0549() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean DEBUG = this instanceof Special;\n" + + "\n" + + " public static class Special extends X {\n" + + " }\n" + + "}\n", + }, + ""); + } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=148046 + public void test0550() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {}\n" + + "class B extends A {}\n" + + "\n" + + "public class X {\n" + + " public void foo(X param) {\n" + + " X foo = (X)param;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X foo = (X)param;\n" + + " ^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ensure no unchecked warning + public void test0551() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T cond1(boolean z, U x1, V x2) {\n" + + " return (z? (T) x1: x2);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " T cond1(boolean z, U x1, V x2) {\n" + + " ^\n" + + "The parameter z is hiding a field from type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0552() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " Comparable x;\n" + + "\n" + + " void put(Comparable c) {\n" + + " this.x = c;\n" + + " }\n" + + "\n" + + " Comparable get() {\n" + + " return x;\n" + + " }\n" + + "\n" + + " void test() {\n" + + " X ci = new X();\n" + + " ci.put(new Integer(3));\n" + + " Integer i = (Integer) ci.get();\n" + + " }\n" + + "\n" + + "}\n", + }, + ""); + } + public void test0553() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) throws Exception {\n" + + " doIt();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void doIt() {\n" + + " Holder association = new Holder(new Integer(0));\n" + + " Integer sizeHolder = (Integer)(association.getValue()); //Cast to Integer is redundant!!!\n" + + " System.out.print(sizeHolder.intValue());\n" + + " }\n" + + " static class Holder {\n" + + " V value;\n" + + " Holder(V value) {\n" + + " this.value = value;\n" + + " }\n" + + " V getValue() {\n" + + " return value;\n" + + " }\n" + + " }\n" + + "}\n" , + }, + "0SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86898 - variation + public void test0554() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.*;\n" + + " public class X {\n" + + " public static void main(String[] args) {\n" + + " X xo = null;\n" + + " X xs = null;\n" + + " X2 x2 = null;\n" + + " \n" + + " Object o1 = (X) xo;\n" + + " Object o2 = (X) xs;\n" + + " Object o3 = (X2) xo;\n" + + " Object o4 = (X) x2;\n" + + " Object o5 = (X3) xo;\n" + + " }\n" + + "}\n" + + "class X2 extends X {\n" + + "}\n" + + "class X3 extends X {\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " Object o1 = (X) xo;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " Object o1 = (X) xo;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " Object o2 = (X) xs;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to X\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " Object o3 = (X2) xo;\n" + + " ^^^^^^^\n" + + "Unnecessary cast from X to X2\n" + + "----------\n" + + "5. WARNING in X.java (at line 11)\n" + + " Object o4 = (X) x2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X2 to X\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " Object o5 = (X3) xo;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X3\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " Object o5 = (X3) xo;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to X3\n" + + "----------\n" + + "8. ERROR in X.java (at line 18)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0555() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.List;\n" + + " public class X {\n" + + " U u;\n" + + " void foo(X xn, X xu) {\n" + + " xn = xu;\n" + + " xu = xn;\n" + + " xu.u = xn.u; // ko\n" + + " xn.u = xu.u; // ko\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " xu = xn;\n" + + " ^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " xu.u = xn.u; // ko\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from capture#6-of ? extends Number to capture#5-of ? extends U\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " xn.u = xu.u; // ko\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from capture#8-of ? extends U to capture#7-of ? extends Number\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87273 + public void test0556() { + this.runConformTest( + new String[] { + "X.java", + "interface Foo {\n" + + " Object get();\n" + + "}\n" + + "\n" + + "interface MyList extends Foo {\n" + + " public F get();\n" + + "}\n" + + "\n" + + "class MyListImpl implements MyList {\n" + + " public G get() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface StringList extends MyList {\n" + + "}\n" + + "\n" + + "class StringListImpl extends MyListImpl implements StringList {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f = new StringListImpl();\n" + + " f.get();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83002 + public void test0557() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(T t) throws T {\n" + // ensure exception is properly encoded (...^ex) + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "Y.java", + "import java.io.*;\n" + + "public class Y {\n" + + " void foo() {\n" + + " try {\n" + + " X.foo(new IOException());\n" + + " } catch(IOException e){\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83002 + public void test0558() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(T t, U u) throws T, U {\n" + // ensure exception is properly encoded (...^ex) + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "Y.java", + "import java.io.*;\n" + + "public class Y {\n" + + " void foo() {\n" + + " try {\n" + + " X.foo(new IOException(), new ClassNotFoundException());\n" + + " } catch(IOException e){\n" + + " } catch(ClassNotFoundException e){\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=86902 + // ** + public void test0559() { + this.runNegativeTest( + new String[] { + "X.java", + "class Cell {\n" + + " T t;\n" + + " public void setT(T t) {\n" + + " this.t= t;\n" + + " }\n" + + " public T getT() {\n" + + " return t;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Zork z;\n" + + " public static void main(String[] args) {\n" + + " Cell c= new Cell();\n" + + " c.setT(Boolean.FALSE); // other: warning: [unchecked] unchecked\n" + + " // call to setT(T) as a member of the raw type p.Cell\n" + + " c.t= Boolean.TRUE; // other: warning: [unchecked] unchecked call\n" + + " // to setT(T) as a member of the raw type p.Cell\n" + + " boolean b1= (Boolean) c.getT();\n" + + " boolean b2= (Boolean) c.t;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " Cell c= new Cell();\n" + + " ^^^^\n" + + "Cell is a raw type. References to generic type Cell should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " Cell c= new Cell();\n" + + " ^^^^\n" + + "Cell is a raw type. References to generic type Cell should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " c.setT(Boolean.FALSE); // other: warning: [unchecked] unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method setT(Object) belongs to the raw type Cell. References to generic type Cell should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 17)\n" + + " c.t= Boolean.TRUE; // other: warning: [unchecked] unchecked call\n" + + " ^\n" + + "Type safety: The field t from the raw type Cell is assigned a value of type Boolean. References to generic type Cell should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85924 + public void test0560() { + this.runConformTest( + new String[] { + "X.java", + "interface IController> {\n" + + " public U getView() ;\n" + + "}\n" + + "interface IView {\n" + + "}\n" + + "class MatGroup {\n" + + " public abstract static class View implements IView {\n" + + " public void setTempAppearance() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " \n" + + " public abstract static class Ctrl implements IController {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String []args) {\n" + + " MatGroup.Ctrlchildren[] = { \n" + + " new MatGroup.Ctrl(){\n" + + " public MatGroup.View getView() { return new MatGroup.View(){}; } \n" + + " }} ;\n" + + " for(MatGroup.Ctrl glmat: children) {\n" + + " glmat.getView().setTempAppearance() ;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87956 + public void test0561() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo(A a) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Object foo(A a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(A a) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Object foo(A a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " void test(A a) { foo(a); }\n" + + " ^^^\n" + + "The method foo(A) in the type X is not applicable for the arguments (A)\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(A a) {}\n" + + " Object foo(A a) { return null; }\n" + + " void test(A a) { foo(a); }\n" + + "}\n" + + "class A {}\n", + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: foo(A) and foo(A) have the same erasure + Object foo(A a) { return null; } + ^ +X.java:4: method foo in class X cannot be applied to given types + void test(A a) { foo(a); } + ^ + required: A + found: A +2 errors + */ + String expectedCompilerLog2 = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " Number foo(A a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Integer foo(A a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Number foo(A a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Integer foo(A a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " void test(A a) { foo(a); }\n" + + " ^^^\n" + + "The method foo(A) in the type X is not applicable for the arguments (A)\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Number foo(A a) { return null; }\n" + + " Integer foo(A a) { return null; }\n" + + " void test(A a) { foo(a); }\n" + + "}\n" + + "class A {}\n", + }, + expectedCompilerLog2 +/* javac 7 +X.java:3: name clash: foo(A) and foo(A) have the same erasure + Integer foo(A a) { return null; } + ^ +X.java:4: method foo in class X cannot be applied to given types + void test(A a) { foo(a); } + ^ + required: A + found: A +2 errors + */ + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87550 + public void test0562() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface Inter {}\n" + + "public class X> extends ArrayList implements Inter {\n" + + " public final void foo(U u) {\n" + + " X.bar(this, u);\n" + + " }\n" + + " public static final void bar(Collection> c, Q q) {}\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87550 - variation + public void test0563() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface Inter {}\n" + + "public class X> extends ArrayList implements Inter {\n" + + " public final void foo(U u) {\n" + + " X.bar(this, u);\n" + + " }\n" + + " public static final void bar(Collection c, Q q) {}\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87550 - variation + // Awaiting clarification on http://mail.openjdk.java.net/pipermail/lambda-spec-experts/2013-November/000428.html + public void test0564() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface Inter {}\n" + + "public class X> extends ArrayList implements Inter {\n" + + " public final void foo(U u) {\n" + + " X.bar(this, u);\n" + + " }\n" + + " public static final void bar(Collection> c, Q q) {}\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87995 - check no warning + public void test0565() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "interface IFoo {\n" + + " public T get(Class clazz);\n" + + " Zork z;\n" + + "}\n" + + "\n" + + "class Bar implements IFoo {\n" + + " public Integer get(Class arg0) {\n" + + " return Integer.valueOf(3);\n" + + " }\n" + + "}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0566() { + String xSource = + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void bar2() {\n" + + " List le = new ArrayList(5);\n" + + " le = fill(le, new X2());\n" + + " }\n" + + " List fill(List lt, T t) { return null; }\n" + + "}\n" + + "class X1 {}\n" + + "class X2 extends X1 {\n" + + " void foo(){}\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " le = fill(le, new X2());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); + } else { + runConformTest(new String[]{ "X.java", xSource }); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89454 + public void test0567() { + this.runConformTest( + new String[] { + "Thrower.java", + "public interface Thrower {\n" + + " public void throwIt() throws E;\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "GenericsTest.java", + "public class GenericsTest {\n" + + " public static void main(String[] args) throws MyException {\n" + + " Thrower thrower = new Thrower() {\n" + + " public void throwIt() throws MyException {\n" + + " throw new MyException();\n" + + " }\n" + + " };\n" + + " try {\n" + + " thrower.throwIt();\n" + + " } catch(Exception e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + + "class MyException extends Exception {\n" + + "}\n", + }, + "SUCCESS", + null, + false, + null); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89448 + public void test0568() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + "\n" + + " ArrayList> n = new ArrayList>();\n" + + " ArrayList arr = new ArrayList();\n" + + " arr.add(new Long(5));\n" + + " n.add(arr);\n" + + " \n" + + " List> m = n; // Whoa!\n" + + " \n" + + " for(Long l : m.get(0)) {\n" + + " System.out.println(l);\n" + + " }\n" + + " }\n" + + "\n" + + "}\n", + }, + "5"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89778 + public void test0569() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " protected static void foo() throws T, Exce {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " protected static void foo() throws T, Exce {\n" + + " ^^^^\n" + + "Exce cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90147 + public void test0570() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class InnerClass implements Comparable {\n" + + " public int compareTo(T other) {\n" + + " return -1;\n" + + " }\n" + + " }\n" + + " \n" + + " public void foo() {\n" + + " InnerClass a = new InnerClass();\n" + + " InnerClass b = new InnerClass();\n" + + " // The following line does not compile (anymore):\n" + + " a.compareTo(b);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " a.compareTo(b);\n" + + " ^^^^^^^^^\n" + + "The method compareTo(T) in the type X.InnerClass is not applicable for the arguments (X.InnerClass)\n" + + "----------\n"); + } + public void test0571() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "interface IFoo {\n" + + " void foo();\n" + + "}\n" + + "class Box {\n" + + " T value() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface IBar {\n" + + " void bar();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void test01(Box box) {\n" + + " box.value().foo();\n" + + " }\n" + + " void test02(Box box) {\n" + + " box.value().foo();\n" + + " box.value().bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + null /* no custom options */, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90430 + // SHOULD FAIL AT 1.8 (18.2.3): The method doWithEnumClass(Class) in the type X is not applicable for the arguments (Class) + public void test0572() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public > void doWithEnumClass(Class enumClass) {\n" + + " }\n" + + "\n" + + " public void f() {\n" + + " Class cl = null; // Returned by Class.forName(\"xyz\");\n" + + " doWithEnumClass((Class) cl);\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90430 - check unchecked warnings + // SHOULD FAIL AT 1.8 (18.2.3): The method doWithEnumClass(Class) in the type X is not applicable for the arguments (Class) + public void test0573() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public > void doWithEnumClass(Class enumClass) {\n" + + " Zork z;\n" + + " }\n" + + "\n" + + " public void f() {\n" + + " Class cl = null; // Returned by Class.forName(\"xyz\");\n" + + " doWithEnumClass((Class) cl);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " doWithEnumClass((Class) cl);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doWithEnumClass(Class) of the generic method doWithEnumClass(Class) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " doWithEnumClass((Class) cl);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " doWithEnumClass((Class) cl);\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 - variation + public void test0574() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C2\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C2\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " new X().new C2().foo((List) null);\n" + + " ^^^\n" + + "The method foo(Object) is ambiguous for the type X.C2\n" + + "----------\n": + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C2\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C2\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " class C2 {\n" + + " T foo(Object o) { return null; } // ok\n" + + " T foo(Object o) { return null; } // ok\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new C2().foo((List) null);\n" + + " }\n" + + "}\n" + }, + expectedCompilerLog + ); +/* +X.java:6: name clash: foo(Object) and foo(Object) have the same erasure + T foo(Object o) { return null; } // ok + ^ + where T#1,T#2 are type-variables: + T#1 extends String declared in method foo(Object) + T#2 extends Integer declared in method foo(Object) +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation with field ref + public void test0575() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " (f1).bar = (f1).bar;\n" + + " }\n" + + " static class Foo {\n" + + " Bar bar = new Bar();\n" + + " }\n" + + " static class Bar {\n" + + " T t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (f1).bar = (f1).bar;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Bar to X.Bar\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation with single ref + public void test0576() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " Foo f2 = new Foo();\n" + + " f1 = f1;\n" + + " f1 = f2;\n" + + " }\n" + + " static class Foo {\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation with qualified name ref + public void test0577() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " (f1).bar = f1.bar;\n" + + " }\n" + + " static class Foo {\n" + + " Bar bar = new Bar();\n" + + " }\n" + + " static class Bar {\n" + + " T t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (f1).bar = f1.bar;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from X.Bar to X.Bar\n" + + "----------\n"); + } + // check array bound for wildcard + public void test0578() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Box box) {\n" + + " int[] ints = box.get();\n" + + " }\n" + + "}\n" + + "class Box {\n" + + " T get() { return null; }\n" + + "}\n" + }, + ""); + } + // check array bound for wildcard + public void test0579() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Box box) {\n" + + " int[] ints = box.get();\n" + + " }\n" + + "}\n" + + "class Box {\n" + + " T get() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int[] ints = box.get();\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? super int[] to int[]\n" + + "----------\n"); + } + // check array bound for wildcard + public void test0580() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Box box) {\n" + + " int[] ints = box.get();\n" + + " }\n" + + "}\n" + + "class Box {\n" + + " T get() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int[] ints = box.get();\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? to int[]\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 - variation + public void test0581() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {" + + " public static void main(String[] args) {\n" + + " Foo f1 = new Foo();\n" + + " f1.bar = f1.bar;\n" + + " }\n" + + " }\n" + + "class Foo {\n" + + " Bar bar = new Bar();\n" + + "}\n" + + "class Bar {\n" + + " T t;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " f1.bar = f1.bar;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from Bar to Bar\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84496 + public void test0582() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class X {\n" + + " void foo(List l1) {\n" + + " C1 c1 = (C1)l1.get(0);\n" + + " }\n" + + "}\n" + + "interface I1{}\n" + + "class C1{}\n" + }, + ""); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=91021 + public void test0583() { + this.runNegativeTest( + new String[] { + "X.java", + "class D {\n" + + " public D (D anotherD) {\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static class C {\n" + + " public C(C anotherC) {\n" + + " }\n" + + " }\n" + + "\n" + + " public void mD(D d) {\n" + + " //the following line is OK (no warning reported)\n" + + " new D(d);\n" + + " }\n" + + " \n" + + " public void mC(C c) {\n" + + " /* type safety warning\n" + + " * (The expression of type X.C\n" + + " * needs unchecked conversion to conform to\n" + + " * XSB.C)\n" + + " */\n" + + " new C(c);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 25)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=91017 + public void test0584() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List stringList = new ArrayList();\n" + + " stringList.add(\"foo\");\n" + + " List intList = new ArrayList();\n" + + " intList.add(1);\n" + + "\n" + + " List untypedList = stringList;\n" + + " List untypedList2 = intList;\n" + + "\n" + + " //correctly flagged as error: untypedList.add(new Object());\n" + + " //ditto: untypedList.add(untypedList2.get(0));\n" + + "\n" + + " //but this is not flagged at all by eclipse:\n" + + " untypedList.addAll(untypedList2);\n" + + "\n" + + " for(String s : stringList){\n" + + " //next line generates runtime ClassCastException\n" + + " Logger.log(\"Test_Lists.main: s: \" + s);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " untypedList.addAll(untypedList2);\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " Logger.log(\"Test_Lists.main: s: \" + s);\n" + + " ^^^^^^\n" + + "Logger cannot be resolved\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90881 + public void test0585() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Outer.Comparator i = new Outer.Comparator() {\n" + + "\n" + + " public boolean equals(String a, String b) {\n" + + " return false;\n" + + " }\n" + + "\n" + + " public int hashCode(String a) {\n" + + " return 0;\n" + + " }\n" + + " };\n" + + "\n" + + " }\n" + + "}\n" + + "\n" + + "class Outer {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Outer.Comparator i = new Outer.Comparator() {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Outer.Comparator cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Outer.Comparator i = new Outer.Comparator() {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Outer.Comparator cannot be resolved to a type\n" + + "----------\n"); + } + + // ** + // note: the test does not show the needed unchecked warning, since it is + // a conform test + public void test0586() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class BB { }\n" + + " static class BD extends BB { }\n" + + " void f() {\n" + + " BB bb = null;\n" + + " Object o = (BD) bb;\n" + + " }\n" + + "}\n", + }, + ""); + } + + public void test0587() { + this.runConformTest( + new String[] { + "X.java", + "interface DA {\n" + + "}\n" + + "interface DB extends DA {\n" + + "}\n" + + "interface DC extends DA {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Object o = (DC) (DA) null;\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90433 + // ** + public void test0588() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " public void f() {\n" + + " Class> cc = Long.class;\n" + + " Class currentClass = null;\n" + + " boolean b = currentClass == Long.class;\n" + + " boolean c = X.class == Long.class;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " boolean c = X.class == Long.class;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 + public void test0589() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void addAll(List target, List source) {\n" + + " target.addAll(source);\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " List ints = new ArrayList();\n" + + " ints.add(3);\n" + + "\n" + + " List floats = new ArrayList();\n" + + " floats.add(3f);\n" + + "\n" + + " new X().addAll(ints, floats);\n" + + "\n" + + " for (Integer integer : ints) {\n" + + " System.out.println(integer.intValue());\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " target.addAll(source);\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 - variation + public void test0590() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void assignAll(Class sup, Class ext) {\n" + + " Class superSup = sup.getSuperclass();\n" + + " Class superExt = ext.getSuperclass();\n" + + " Class superSup2 = ext.getSuperclass();\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Class superSup2 = ext.getSuperclass();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 - variation + public void test0591() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public Values foo(Box box) {\n" + + " return selectedValues(box.getValues());\n" + + " }\n" + + " public static Values selectedValues(Values v) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + ""); + } + public void test0592() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " List l;\n" + + " void m() {\n" + + " m2(l);\n" + + " }\n" + + " void m2(List l2) {\n" + + " l2.add(l2.remove(0));\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0593() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE); + String bounds = isJRE15Plus ? "Object&Serializable&Comparable&Constable" : "Object&Serializable&Comparable"; + String xSource = + "import java.util.*;\n" + + "public class X {\n" + + " List> classes1 = Arrays.asList(String.class, Boolean.class);\n" + + " List> classes2 = Arrays.asList(String.class, Boolean.class);\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " List> classes1 = Arrays.asList(String.class, Boolean.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n", + null, + true, + options); + } else { + runConformTest(new String[] { "X.java", xSource }, options); + } + } + public void test0594() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.*;\n" + + "import static java.util.Map.*;\n" + + "\n" + + "abstract class MyIterator implements Iterator {\n" + + " Set iteratedSet;\n" + + "}\n" + + "public class X {\n" + + " \n" + + " void foo() {\n" + + " Map map;\n" + + " Iterator> it = map.entrySet().iterator();\n" + + "\n" + + " Entry unrelatedEntry;\n" + + " MyIterator> mit = (MyIterator>) it;\n" + + " mit.iteratedSet.add(unrelatedEntry);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Iterator> it = map.entrySet().iterator();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator> to Iterator>\n" + + "----------\n"); + } + public void test0595() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.*;\n" + + "import static java.util.Map.*;\n" + + "\n" + + "abstract class MyIterator implements Iterator {\n" + + " Set iteratedSet;\n" + + "}\n" + + "public class X {\n" + + " \n" + + " void bar() {\n" + + " Map map;\n" + + " Iterator> it = map.entrySet().iterator();\n" + + "\n" + + " Entry unrelatedEntry;\n" + + " MyIterator> mit = (MyIterator>) it;\n" + + " mit.iteratedSet.add(unrelatedEntry);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Iterator> it = map.entrySet().iterator();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator> to Iterator>\n" + + "----------\n"); + } + public void test0596() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Set unmodifiableSet(Set set) {\n" + + " return set;\n" + + " }\n" + + " public void foo(Set s) {\n" + + " Set s2 = unmodifiableSet(s);\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0597() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Pair m() { \n" + + " return null; \n" + + " }\n" + + " void foo(X x) {\n" + + " x.m().first = x.m().second;\n" + + " }\n" + + "}\n" + + " \n" + + "class Pair {\n" + + " E first;\n" + + " F second;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x.m().first = x.m().second;\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? to capture#1-of ?\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90879 + // SHOULD FAIL AT 1.8 (18.2.3): The method sort(List) in the type Collections is not applicable for the arguments (List) + public void test0598() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "class X implements Comparable {\n" + + "\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "class Y {\n" + + " public static void main(String[] args) {\n" + + " List lx = null;\n" + + " Collections.sort(lx);\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90879 - variation + // SHOULD FAIL AT 1.8 (18.2.3): The method sort1(List) in the type X is not applicable for the arguments (List) + public void test0599() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X implements Comparable {\n" + + " public static void main(String[] args) {\n" + + " Zork z;\n" + + " \n" + + " List lx = null;\n" + + " sort1(lx);\n" + + " sort2(lx);\n" + + " sort3(lx);\n" + + " sort4(lx);\n" + + " sort5(lx);\n" + + " }\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + " static > void sort1(List list) {}\n" + + " static > void sort2(List list) {}\n" + + " static > void sort3(List list) {}\n" + + " static > void sort4(List list) {}\n" + + " static void sort5(List list) {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X implements Comparable {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " sort1(lx);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort1(List) of the generic method sort1(List) of type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " sort2(lx);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort2(List) of the generic method sort2(List) of type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 11)\n" + + " sort4(lx);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort4(List) of the generic method sort4(List) of type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 21)\n" + + " static void sort5(List list) {}\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90879 - variation + // SHOULD FAIL AT 1.8 (18.2.3): The method sort6(List) in the type X is not applicable for the arguments (List) + public void test0600() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X implements Comparable {\n" + + " public static void main(String[] args) {\n" + + " Zork z;\n" + + " \n" + + " List le = null;\n" + + " sort6(le);\n" + + " sort7(le);\n" + + " sort8(le);\n" + + " sort9(le);\n" + + " sort10(le);\n" + + " }\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + " static > void sort6(List list) {}\n" + + " static > void sort7(List list) {}\n" + + " static > void sort8(List list) {}\n" + + " static > void sort9(List list) {}\n" + + " static void sort10(List list) {}\n" + + "}\n" + + "class MyEnum> {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X implements Comparable {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " List le = null;\n" + + " ^^^^^^\n" + + "MyEnum is a raw type. References to generic type MyEnum should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " sort6(le);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort6(List) of the generic method sort6(List) of type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " sort7(le);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort7(List) of the generic method sort7(List) of type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 11)\n" + + " sort9(le);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort9(List) of the generic method sort9(List) of type X\n" + + "----------\n" + + "7. WARNING in X.java (at line 21)\n" + + " static void sort10(List list) {}\n" + + " ^^^^^^\n" + + "MyEnum is a raw type. References to generic type MyEnum should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=85281 - variation + public void test0601() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public Values foo(Box box) {\n" + + " return selectedValues(box.getValues());\n" + + " }\n" + + " public static Values selectedValues(Values v) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return selectedValues(box.getValues());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Values to Values\n" + + "----------\n"); + } + public void test0602() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo(Box box) {\n" + + " box.getValues()[0] = box.getValues()[1];\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values[] getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " box.getValues()[0] = box.getValues()[1];\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Values to Values\n" + + "----------\n"); + } + public void test0603() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo(Box[] boxes) {\n" + + " boxes[0] = boxes[1];\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values[] getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + ""); + } + // capture on array ref + public void test0604() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo(Box[] boxes) {\n" + + " bar(boxes[0], boxes[1]);\n" + + " }\n" + + " void bar(V v1, V v2) {}\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values[] getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + ""); + } + // capture on array ref + public void test0605() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo(Box box) {\n" + + " box.getValues()[1] = box.getValues()[2];\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values[] getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " box.getValues()[1] = box.getValues()[2];\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Values to Values\n" + + "----------\n"); + } + public void test0606() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo(Box box) {\n" + + " box.getValues()[1] = (Values) box.getValues()[2];\n" + + " }\n" + + " void bar(V v1, V v2) {}\n" + + "}\n" + + "\n" + + "abstract class Box {\n" + + " abstract Values[] getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " box.getValues()[1] = (Values) box.getValues()[2];\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Values to Values\n" + + "----------\n"); + } + public void test0607() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void test01() {\n" + + " List> lObj = new ArrayList> ();\n" + + " Collections.sort (lObj); \n" + + " }\n" + + " void test02() {\n" + + " List lComp = new ArrayList ();\n" + + " Collections.sort (lComp); \n" + + " }\n" + + " void test03() {\n" + + " List> lStr = new ArrayList> ();\n" + + " Collections.sort (lStr);\n" + + " }\n" + + " }\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " List lComp = new ArrayList ();\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " List lComp = new ArrayList ();\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " Collections.sort (lComp); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort(List) of the generic method sort(List) of type Collections\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " Collections.sort (lStr);\n" + + " ^^^^\n" + + "Bound mismatch: The generic method sort(List) of type Collections is not applicable for the arguments (List>). The inferred type Comparable is not a valid substitute for the bounded parameter >\n" + + "----------\n" : + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " Collections.sort (lStr);\n" + + " ^^^^\n" + + "The method sort(List) in the type Collections is not applicable for the arguments (List>)\n" + + "----------\n")); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84284 - check warnings + // SHOULD FAIL AT 1.8 (18.2.3): The method sort(List) in the type Collections is not applicable for the arguments (LinkedList) + public void test0608() { + this.runNegativeTest( + new String[] { + "Ball.java", + "import java.util.*;\n" + + "class Ball implements Comparable {\n" + + "\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " LinkedList foo = new LinkedList();\n" + + " Collections.sort(foo);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Ball.java (at line 2)\n" + + " class Ball implements Comparable {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. WARNING in Ball.java (at line 10)\n" + + " Collections.sort(foo);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort(LinkedList) of the generic method sort(List) of type Collections\n" + + "----------\n" + + "3. ERROR in Ball.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81831 + public void test0609() { + this.runConformTest( + new String[] { + "I.java", + "interface I> {}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89940 + public void test0610() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo(List objects, List raw) {\n" + + "\n" + + " List numbers;\n" + + " List ext;\n" + + " \n" + + " numbers= (List) objects; // correct - cast error\n" + + " ext= (List) objects; // wrong, should fail\n" + + "\n" + + " ext= raw; // correct - raw conversion warning issued\n" + + " numbers= raw; // correct - raw conversion warning issued\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(List objects, List raw) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " numbers= (List) objects; // correct - cast error\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " ext= (List) objects; // wrong, should fail\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " ext= raw; // correct - raw conversion warning issued\n" + + " ^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " numbers= raw; // correct - raw conversion warning issued\n" + + " ^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=91696 + public void test0611() { + this.runConformTest( + new String[] { + "C.java", + "import java.io.Serializable;\n" + + "\n" + + "interface A, S extends A.BS> {\n" + + " public interface BS extends Serializable {\n" + + " }\n" + + " public interface BK extends Serializable {\n" + + " public void put(SS a);\n" + + " }\n" + + "\n" + + " public P getP();\n" + + "}\n" + + "\n" + + "class P, S extends A.BS> {\n" + + " K k;\n" + + " S s;\n" + + "\n" + + " public void put() {\n" + + " k.put(s);\n" + + " }\n" + + "}\n" + + "\n" + + "public class C implements A {\n" + + " public static class K implements A.BK {\n" + + " public void put(S a) {\n" + + " }\n" + + " }\n" + + " protected static class S implements A.BS {\n" + + " }\n" + + "\n" + + " public P getP() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0612() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "class MPair {}\n" + + "\n" + + "public class X {\n" + + " private static class Bucket extends LinkedList> {}\n" + + " private Bucket[] buckets = new X.Bucket[100];\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " private static class Bucket extends LinkedList> {}\n" + + " ^\n" + + "Cannot make a static reference to the non-static type K\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " private static class Bucket extends LinkedList> {}\n" + + " ^\n" + + "Cannot make a static reference to the non-static type V\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 + public void test0613() { + this.runNegativeTest( + new String[] { + "Map.java", + "package xy;\n" + + "import xy.Map.Entry;\n" + + "\n" + + "class Map {\n" + + " class Entry { }\n" + + "}\n" + + "class User {\n" + + " void a(Entry e) { } // Entry is illegal (eclipse accepts)\n" + + " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + + " void b(Entry e) { } // OK\n" + + " void d(Map.Entry e) { } // OK\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Map.java (at line 8)\n" + + " void a(Entry e) { } // Entry is illegal (eclipse accepts)\n" + + " ^^^^^\n" + + "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "2. ERROR in Map.java (at line 9)\n" + + " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + + " ^^^^^^^^^\n" + + "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "3. WARNING in Map.java (at line 10)\n" + + " void b(Entry e) { } // OK\n" + + " ^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation + public void test0614() { + this.runNegativeTest( + new String[] { + "X1.java", + "class X1 {\n" + + " static class X2 {\n" + + " class X3 {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y1 {\n" + + " class Y2 extends X1.X2 {\n" + + " void foo() {\n" + + " X3 x;\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X1.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=84973 - variation + public void test0615() { + this.runNegativeTest( + new String[] { + "X1.java", + "class X1 {\n" + + " static class X2 {\n" + + " class X3 {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y1 {\n" + + " class Y2 extends X1.X2 {\n" + + " void foo() {\n" + + " X3 x;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X1.java (at line 8)\n" + + " class Y2 extends X1.X2 {\n" + + " ^^^^^\n" + + "X1.X2 is a raw type. References to generic type X1.X2 should be parameterized\n" + + "----------\n" + + "2. ERROR in X1.java (at line 10)\n" + + " X3 x;\n" + + " ^^\n" + + "The member type X1.X2.X3 must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation + public void test0616() { + this.runNegativeTest( + new String[] { + "Map.java", + "package xy;\n" + + "import xy.Map.Entry;\n" + + "\n" + + "class Map {\n" + + " class Entry { }\n" + + "}\n" + + "class User extends Map {\n" + + " void a(Entry e) { } // Entry is illegal (eclipse accepts)\n" + + " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + + " void b(Entry e) { } // OK\n" + + " void d(Map.Entry e) { } // OK\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Map.java (at line 9)\n" + + " void c(Map.Entry e) { } // illegal (correctly flagged)\n" + + " ^^^^^^^^^\n" + + "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "2. WARNING in Map.java (at line 10)\n" + + " void b(Entry e) { } // OK\n" + + " ^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n"); + } +public void test0617() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void foo() {\n" + + " String s = null;\n" + + " ZZZ1.ZZZ2.ZZZ3 var = null;\n" + + " s = var;\n" + + " }\n" + + "}\n" + + "\n" + + "class ZZZ1 {\n" + + " class ZZZ2 {\n" + + " class ZZZ3 {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " s = var;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from ZZZ1.ZZZ2.ZZZ3 to String\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84973 - variation + public void test0618() { + String expectedError = this.complianceLevel < ClassFileConstants.JDK16 ? + "----------\n" + + "1. ERROR in Map.java (at line 5)\n" + + " static void foo(Entry e) { } // invalid static ref\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The method foo cannot be declared static; static methods can only be declared in a static or top level type\n" + + "----------\n" + + "2. ERROR in Map.java (at line 5)\n" + + " static void foo(Entry e) { } // invalid static ref\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static type Entry\n" + + "----------\n" + + "3. ERROR in Map.java (at line 8)\n" + + " Entry entry; // invalid static ref\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static type Entry\n" + + "----------\n" + + "4. ERROR in Map.java (at line 11)\n" + + " void c(Map.Entry e) { } // illegal \n" + + " ^^^^^^^^^\n" + + "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "5. WARNING in Map.java (at line 12)\n" + + " void b(Entry e) { } // OK\n" + + " ^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in Map.java (at line 5)\n" + + " static void foo(Entry e) { } // invalid static ref\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static type Entry\n" + + "----------\n" + + "2. ERROR in Map.java (at line 8)\n" + + " Entry entry; // invalid static ref\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static type Entry\n" + + "----------\n" + + "3. ERROR in Map.java (at line 11)\n" + + " void c(Map.Entry e) { } // illegal \n" + + " ^^^^^^^^^\n" + + "The member type Map.Entry must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "4. WARNING in Map.java (at line 12)\n" + + " void b(Entry e) { } // OK\n" + + " ^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "Map.java", + "class Map {\n" + + " class Entry { }\n" + + " class Foo {\n" + + " Entry entry;\n" + + " static void foo(Entry e) { } // invalid static ref\n" + + " }\n" + + " static class Bar {\n" + + " Entry entry; // invalid static ref\n" + + " }\n" + + " void a(Entry e) { } // OK\n" + + " void c(Map.Entry e) { } // illegal \n" + + " void b(Entry e) { } // OK\n" + + " void d(Map.Entry e) { } // OK\n" + + "}\n", + }, + expectedError); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89440 + public void test0619() { + this.runConformTest( + new String[] { + "X.java", + "interface ISample {\n" + + " public static enum Stuff {\n" + + " FIRST, SECOND, THIRD\n" + + " };\n" + + "}\n" + + "\n" + + "class SampleClass {\n" + + " public void doSomething(ISample.Stuff thing) {\n" + + "\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public void doSomething() {\n" + + " SampleClass sample = new SampleClass();\n" + + " sample.doSomething(ISample.Stuff.FIRST);\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551 + public void test0620() { + this.runNegativeTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " class Inner { }\n" + + " \n" + + " static void test(Inner i) { }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Outer.java (at line 4)\n" + + " static void test(Inner i) { }\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static type Inner\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551- variation + public void test0621() { + this.runConformTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " class Inner { }\n" + + " \n" + + " static void test(Inner i) { }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551 - variation + public void test0622() { + this.runConformTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " static class Inner { }\n" + + " \n" + + " static void test(Inner i) { }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84551 - variation + public void test0623() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Outer {\n" + + " class Inner { }\n" + + " static void test(Inner i) { }\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83034 + public void test0624() { + this.runConformTest( + new String[] { + "X.java", + " interface IFoo> {\n" + + " V bar(int i);\n" + + "}\n" + + "\n" + + "public class X> {\n" + + " \n" + + " public boolean foo(X x) {\n" + + " return false;\n" + + " }\n" + + " public boolean baz(IFoo f) {\n" + + " return foo(f.bar(0));\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=83034 - variation + public void test0625() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo {\n" + + " public enum Mode {\n" + + " A\n" + + " };\n" + + " public void test(Mode mode) {\n" + + " }\n" + + "} \n", + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Keys {\n" + + " B\n" + + " };\n" + + " public void test() {\n" + + " Foo foo = new Foo();\n" + + " foo.test(Foo.Mode.A); // error\n" + + " }\n" + + "} \n", + }, + "", + null, + false, + null); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=92037 + public void test0626() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " private static class B {\n" + + " ^\n" + + "The type parameter A is hiding the type X.A\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " System.out.println(b instanceof C);\n" + + " ^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types X.B and X.C\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " private static class B {\n" + + " ^\n" + + "The type parameter A is hiding the type X.A\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " private static class AA extends A {\n" + + " ^^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " private static class C extends B {\n" + + " ^\n" + + "Access to enclosing constructor X.B() is emulated by a synthetic accessor method\n" + + "----------\n" + + "4. ERROR in X.java (at line 21)\n" + + " System.out.println(b instanceof C);\n" + + " ^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types X.B and X.C\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " private static class A {\n" + + "\n" + + " }\n" + + "\n" + + " private static class B {\n" + + "\n" + + " }\n" + + "\n" + + " private static class AA extends A {\n" + + "\n" + + " }\n" + + "\n" + + " private static class C extends B {\n" + + "\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " B b = new B();\n" + + " System.out.println(b instanceof C);\n" + + " }\n" + + "}\n", + }, errMessage); + } + + public void test0627() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " List foo(List l1, List l2) {\n" + + " return l1;\n" + + " }\n" + + " void bar(List l1, List l2) {\n" + + " String s = foo(l1, l2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s = foo(l1, l2);\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List")+"> to String\n" + + "----------\n"); + } + // check capture for conditional operator + public void test0628() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " List foo(List l1, List l2) {\n" + + " return l1;\n" + + " }\n" + + " void bar(List l1, List l2) {\n" + + " List l3 = null;\n" + + " String s = l1 != null ? foo(l1, l2) : l3;\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = l1 != null ? foo(l1, l2) : l3;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to String\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = l1 != null ? foo(l1, l2) : l3;\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List")+"> to String\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=92556 + public void test0629() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public abstract class Context {\n" + + " private Strategy> strategy;\n" + + " public void setStrategy(Strategy> strategy) {\n" + + " this.strategy = strategy;\n" + + " }\n" + + " // m?thode qui utilise la strat?gie\n" + + " public N call() throws Exception {\n" + + " return this.strategy.call(this);\n" + + " }\n" + + " }\n" + + " public interface Strategy> {\n" + + " public abstract N call(C context);\n" + + " }\n" + + "\n" + + "} \n", + }, + ""); + } + public void test0630() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "@SuppressWarnings(\"null\")\n" + + "public class X {\n" + + "\n" + + " void test0() {\n" + + " List arrays= new ArrayList();\n" + + " Number[] a= null;\n" + + " arrays.add(null);\n" + + " arrays.add(a); // Error: The method add(capture-of ? super Number[]) in the type List is not applicable for the arguments (Number[])\n" + + " }\n" + + "\n" + + " void test01() {\n" + + " List arrays= new ArrayList();\n" + + " Number[] a= null;\n" + + " arrays.add(null);\n" + + " arrays.add(a); // Error: The method add(capture-of ? extends Number[]) in the type List is not applicable for the arguments (Number[])\n" + + " }\n" + + " \n" + + " void test02() {\n" + + " List nums= null;\n" + + " Number n= null;\n" + + " nums.add(null);\n" + + " nums.add(n);\n" + + " }\n" + + "\n" + + " void test3() {\n" + + " List> nums= null;\n" + + " List n= null;\n" + + " nums.add(null);\n" + + " nums.add(n);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " arrays.add(a); // Error: The method add(capture-of ? extends Number[]) in the type List is not applicable for the arguments (Number[])\n" + + " ^^^\n" + + "The method add(capture#4-of ? extends Number[]) in the type List is not applicable for the arguments (Number[])\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93044 + public void test0631() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.RetentionPolicy;\n" + + "\n" + + "public class X\n" + + "{\n" + + " public static void main(String[] args)\n" + + " {\n" + + " Class> c = RetentionPolicy.class;\n" + + " System.out.println(Enum.valueOf(c, \"CLASS\"));\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(Enum.valueOf(c, \"CLASS\"));\n" + + " ^^^^^^^\n" + + "Bound mismatch: The generic method valueOf(Class, String) of type Enum is not applicable for the arguments (Class>, String). The inferred type capture#1-of ? extends Enum is not a valid substitute for the bounded parameter >\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(Enum.valueOf(c, \"CLASS\"));\n" + + " ^^^^^^^\n" + + "The method valueOf(Class, String) in the type Enum is not applicable for the arguments (Class>, String)\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=92982 + public void test0632() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "\n" + + "@SuppressWarnings(\"null\")\n" + + "public class X {\n" + + " void test01() {\n" + + " Vector lhs = null;\n" + + " Vector rhs = null;\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + " void test02() {\n" + + " Vector lhs = null;\n" + + " Vector rhs = null;\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + " void test3() {\n" + + " Vector lhs = null;\n" + + " Vector rhs = null;\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + " void test4() {\n" + + " Vector lhs = null;\n" + + " Vector rhs = null;\n" + + " lhs.add(rhs.get(0));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#3-of ? extends Object[]) in the type Vector is not applicable for the arguments (capture#4-of ? extends Object[])\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#5-of ? super Object[]) in the type Vector is not applicable for the arguments (capture#6-of ? super Object[])\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " lhs.add(rhs.get(0));\n" + + " ^^^\n" + + "The method add(capture#7-of ? extends Object[]) in the type Vector is not applicable for the arguments (capture#8-of ? super Object[])\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=92982 - variation + public void test0633() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.Vector;\n" + + "\n" + + "public class X {\n" + + " void test1() {\n" + + " Vector lhs = null;\n" + + " Vector rhs = null;\n" + + " lhs.add(rhs.get(0)); \n" + + " foo(rhs.get(0)); // ok #foo(Object[])\n" + + " }\n" + + " void foo(Object[] objs) {\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90775 + public void test0634() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.reflect.Array;\n" + + "\n" + + "public class X {\n" + + "\n" + + " T[] theArray;\n" + + "\n" + + " public X(Class clazz) {\n" + + " theArray = (T[]) Array.newInstance(clazz, 10); // Compiler warning\n" + + " }\n" + + "\n" + + " public T get(int i) {\n" + + " return theArray[i];\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X t = new X(Integer.class);\n" + + " // GenericsArray1 t = new GenericsArray1( int.class );\n" + + " Object[] o = t.theArray;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " theArray = (T[]) Array.newInstance(clazz, 10); // Compiler warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to T[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93298 + public void test0635() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "public class X {\n" + + " public static class Indexed {\n" + + " public Iterator foo() {\n" + + " return new IndexedIter();\n" + + " }\n" + + " class IndexedIter implements Iterator {\n" + + " public boolean hasNext() {\n" + + " return false;\n" + + " }\n" + + " public U next() {\n" + + " return null;\n" + + " }\n" + + " public void remove() {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=78084 + public void test0636() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " public final T element() {\n" + + " T result = (T) customElement(); // reports unnecessary cast\n" + + " return result;\n" + + " }\n" + + " protected abstract Object customElement();\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " T result = (T) customElement(); // reports unnecessary cast\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=84968 + public void test0637() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final class Ex1 extends Exception {\n" + + " private static final long serialVersionUID = 1;\n" + + " }\n" + + "\n" + + " private void a1() {\n" + + " try {\n" + + " a1_1();\n" + + " } catch (Ex1 si) {\n" + + " assert si != null;\n" + + " }\n" + + " }\n" + + "\n" + + " protected Object a1_1() throws Ex1 {\n" + + " return null;\n" + + " }\n" + + "\n" + + " private void a2() {\n" + + " try {\n" + + " a2_1();\n" + + " } catch (Ex2 si) {\n" + + " assert si != null;\n" + + " }\n" + + " }\n" + + "\n" + + " protected Object a2_1() throws Ex2 {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public final static class Ex3 extends Exception {\n" + + " private static final long serialVersionUID = 1;\n" + + " }\n" + + "\n" + + " private void a3() {\n" + + " try {\n" + + " a3_1();\n" + + " } catch (Ex3 si) {\n" + + " assert si != null;\n" + + " }\n" + + " }\n" + + "\n" + + " protected Object a3_1() throws Ex3 {\n" + + " return null;\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "final class Ex2 extends Exception {\n" + + " private static final long serialVersionUID = 1;\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93478 + public void test0638() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.concurrent.BlockingQueue;\n" + + "\n" + + "public class X {\n" + + " static interface IMX {\n" + + " void call(L a, S b);\n" + + " }\n" + + " static interface Y {\n" + + " void addX(final IMX a);\n" + + " void removeX(final IMX a);\n" + + " }\n" + + " static final class Pair {\n" + + " T first;\n" + + "\n" + + " V second;\n" + + " }\n" + + " static class Bar

{\n" + + " Bar(final BlockingQueue

a) {\n" + + "\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "final class Foo extends X.Bar> implements X.IMX {\n" + + " Foo(final BlockingQueue> in) {\n" + + " super(in);\n" + + " }\n" + + " public void call(L a, S b) {\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0639() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "import java.lang.reflect.*;\n" + + "\n" + + "@interface MyAnnotation {\n" + + "}\n" + + "public class X {\n" + + " void test() throws Exception {\n" + + " Class type = X.class;\n" + + " Method method = type.getMethod(\"test\");\n" + + " Constructor constructor = type.getConstructor();\n" + + " Field field = type.getField(\"field\");\n" + + " Package packge = type.getPackage();\n" + + " MyAnnotation typeAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation methodAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation constrAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation fieldAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation packgeAnnot = getAnnotation(MyAnnotation.class);\n" + + " }\n" + + "\n" + + " int field;\n" + + " \n" + + " U getAnnotation(Class annotatedType) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0640() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "import java.lang.reflect.*;\n" + + "\n" + + "@interface MyAnnotation {\n" + + "}\n" + + "public class X {\n" + + " void test() throws Exception {\n" + + " Class type = X.class;\n" + + " Method method = type.getMethod(\"test\");\n" + + " Constructor constructor = type.getConstructor();\n" + + " Field field = type.getField(\"field\");\n" + + " Package packge = type.getPackage();\n" + + " MyAnnotation typeAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation methodAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation constrAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation fieldAnnot = getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation packgeAnnot = getAnnotation(MyAnnotation.class);\n" + + " }\n" + + "\n" + + " int field;\n" + + " \n" + + " U getAnnotation(Class annotatedType) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0641() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.reflect.*;\n" + + "\n" + + "@interface MyAnnotation {\n" + + "}\n" + + "@SuppressWarnings(\"all\")\n" + + "public class X {\n" + + " void test() throws Exception {\n" + + " Class type = X.class;\n" + + " Method method = type.getMethod(\"test\");\n" + + " Constructor constructor = type.getConstructor();\n" + + " Field field = type.getField(\"field\");\n" + + " Package packge = type.getPackage();\n" + + " MyAnnotation typeAnnot = type.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation methodAnnot = method.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation constrAnnot = constructor.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation fieldAnnot = field.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation packgeAnnot = packge.getAnnotation(MyAnnotation.class);\n" + + " }\n" + + "\n" + + " int field;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " MyAnnotation typeAnnot = type.getAnnotation(MyAnnotation.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " MyAnnotation constrAnnot = constructor.getAnnotation(MyAnnotation.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + + "----------\n"); + } + public void test0642() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.*;\n" + + "\n" + + "@interface MyAnnotation {\n" + + "}\n" + + "@SuppressWarnings(\"all\")\n" + + "public class X {\n" + + " void test() throws Exception {\n" + + " Class type = X.class;\n" + + " Method method = type.getMethod(\"test\");\n" + + " Constructor constructor = type.getConstructor();\n" + + " Field field = type.getField(\"field\");\n" + + " Package packge = type.getPackage();\n" + + " MyAnnotation typeAnnot = type.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation methodAnnot = method.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation constrAnnot = constructor.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation fieldAnnot = field.getAnnotation(MyAnnotation.class);\n" + + " MyAnnotation packgeAnnot = packge.getAnnotation(MyAnnotation.class);\n" + + " }\n" + + "\n" + + " int field;\n" + + "}\n", + }, + ""); + } + public void test0643() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " static U foo(U u) {\n" + + " return u;\n" + + " }\n" + + " \n" + + " void bar(X x) {\n" + + " String str = x.foo(\"hello\");\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0644() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " U foo(U u) {\n" + + " return u;\n" + + " }\n" + + " \n" + + " void bar(X x) {\n" + + " String str = x.foo(\"hello\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " void bar(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " String str = x.foo(\"hello\");\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method foo(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " String str = x.foo(\"hello\");\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to String\n" + + "----------\n"); + } + public void test0645() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "\n" + + "@interface MyAnnotation {\n" + + "}\n" + + "\n" + + "class X {\n" + + " void bar(XClass arg) {\n" + + " XClass xc = new XClass();\n" + + " String str = xc.getConstructor().getAnnotation(arg);\n" + + " }\n" + + "}\n" + + "\n" + + "class XClass {\n" + + " XConstructor getConstructor() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class XConstructor {\n" + + " W getAnnotation(XClass cl) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " XClass xc = new XClass();\n" + + " ^^^^^^\n" + + "XClass is a raw type. References to generic type XClass should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " XClass xc = new XClass();\n" + + " ^^^^^^\n" + + "XClass is a raw type. References to generic type XClass should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " String str = xc.getConstructor().getAnnotation(arg);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(XClass) belongs to the raw type XConstructor. References to generic type XConstructor should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " String str = xc.getConstructor().getAnnotation(arg);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to String\n" + + "----------\n"); + } + public void test0646() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " X x = inner.setOuterT(new X());\n" + + " \n" + + " Outer.Inner innerS = inner;\n" + + " }\n" + + "}\n" + + "\n" + + "class Outer {\n" + + " T t;\n" + + " class Inner {\n" + + " T setOuterT(T t1) {\n" + + " t = t1;\n" + + " return t;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^^^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^\n" + + "Outer is a raw type. References to generic type Outer should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " X x = inner.setOuterT(new X());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method setOuterT(Object) belongs to the raw type Outer.Inner. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " X x = inner.setOuterT(new X());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + + "6. WARNING in X.java (at line 6)\n" + + " Outer.Inner innerS = inner;\n" + + " ^^^^^\n" + + "Type safety: The expression of type Outer.Inner needs unchecked conversion to conform to Outer.Inner\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94644 + public void test0647() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " X x = inner.set(new X());\n" + + " \n" + + " Outer.Inner innerS = inner;\n" + + " }\n" + + "}\n" + + "\n" + + "class Outer {\n" + + " T t;\n" + + " static class Inner {\n" + + " U set(U u) {\n" + + " return u;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^^^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^\n" + + "Outer is a raw type. References to generic type Outer should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Outer().new Inner();\n" + + " ^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " X x = inner.set(new X());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method set(Object) belongs to the raw type Outer.Inner. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " X x = inner.set(new X());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n" + + "6. ERROR in X.java (at line 6)\n" + + " Outer.Inner innerS = inner;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The member type Outer.Inner cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type Outer\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94644 - variation + public void test0648() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Outer.Inner inner = new Sub().get();\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class Outer {\n" + + " class Inner {\n" + + " }\n" + + "}\n" + + "class Sub extends Outer {\n" + + " Inner get() { return null; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Sub().get();\n" + + " ^^^^^^^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " class Sub extends Outer {\n" + + " ^^^^^\n" + + "Outer is a raw type. References to generic type Outer should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " Inner get() { return null; }\n" + + " ^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94644 - variation + public void test0649() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Outer.Inner inner = new Sub().get();\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class Outer {\n" + + " class Inner {\n" + + " }\n" + + "}\n" + + "class Sub extends Outer {\n" + + " Inner get() { return null; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Outer.Inner inner = new Sub().get();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Outer.Inner needs unchecked conversion to conform to Outer.Inner\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " class Sub extends Outer {\n" + + " ^^^^^\n" + + "Outer is a raw type. References to generic type Outer should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " Inner get() { return null; }\n" + + " ^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=89440 + public void test0650() { + this.runConformTest( + new String[] { + "p/A.java", + "package p;\n" + + "\n" + + "public interface A {\n" + + " public static enum Stuff {\n" + + " FIRST, SECOND, THIRD\n" + + " };\n" + + "}", + }, + ""); + this.runConformTest( + new String[] { + "q/SampleClass2.java", + "package q;\n" + + "\n" + + "import p.A.Stuff;\n" + + "\n" + + "public class SampleClass2 {\n" + + " public void doSomething(Stuff thing) {\n" + + " \n" + + " }\n" + + "}" + }, + "", + null, + false, + null); + this.runConformTest( + new String[] { + "q/SampleClass3.java", + "package q;\n" + + "\n" + + "import p.A;\n" + + "\n" + + "public class SampleClass3 {\n" + + " public void doSomething() {\n" + + " SampleClass2 sample = new SampleClass2();\n" + + " sample.doSomething(A.Stuff.FIRST);\n" + + " }\n" + + "}", + }, + "", + null, + false, + null); + } + public void test0651() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " int field;\n" + + " static int FIELD;\n" + + "\n" + + " {\n" + + " field = 1;\n" + + " }\n" + + " static {\n" + + " FIELD = 1;\n" + + " }\n" + + "\n" + + " public Values foo(Box box) {\n" + + " return selectedValues(box.getValues()); // 1\n" + + " }\n" + + " public static Values selectedValues(Values v) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "abstract class Box { // Added bound for V\n" + + " abstract Values getValues();\n" + + "}\n" + + "abstract class Values {\n" + + "}\n", + }, + JavacTestOptions.EclipseHasABug.EclipseBug236217); + } + public void test0652() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Collection c = new HashSet();\n" + + " Set s = (Set)c;\n" + + " }\n" + + "}\n", + }, + ""); + } + public void test0653() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " static public void workaround(T a, T b) {\n" + + " a.addAll(b);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " static public void workaround(T a, T b) {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " a.addAll(b);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: The method addAll(Collection) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test0654() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map myMap = new HashMap();\n" + + " myMap.put(\"key1\", \"1\");\n" + + "\n" + + " for (Map.Entry e : myMap.entrySet())\n" + + " System.out.println(\"Key = \" + e.getKey() + \" Value = \" + e.getValue());\n" + + " Set set = myMap.entrySet();\n" + + " for (Map.Entry e : set)\n" + + " System.out.println(\"Key = \" + e.getKey() + \" Value = \" + e.getValue());\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Map myMap = new HashMap();\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " Map myMap = new HashMap();\n" + + " ^^^^^^^\n" + + "HashMap is a raw type. References to generic type HashMap should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " myMap.put(\"key1\", \"1\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " for (Map.Entry e : myMap.entrySet())\n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " for (Map.Entry e : myMap.entrySet())\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from element type Object to Map.Entry\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " Set set = myMap.entrySet();\n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " Set set = myMap.entrySet();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Set needs unchecked conversion to conform to Set\n" + + "----------\n" + + "8. WARNING in X.java (at line 11)\n" + + " for (Map.Entry e : set)\n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n"); + } +// ** +public void test0655() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class BB { }\n" + + " static class BD extends BB { }\n" + + " void f() {\n" + + " BB bb = null;\n" + + " Object o = (BD) bb;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Object o = (BD) bb;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X.BB to X.BD\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " Object o = (BD) bb;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X.BB to X.BD\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test0656() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " protected Vector v = null;\n" + + "\n" + + " public void f() {\n" + + " ((String) (v.elementAt(0))).charAt(0);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +public void test0657() { + this.runConformTest( + new String[] { + "X.java", + "public class X{\n" + + " \n" + + " private static class GenericWrapper {\n" + + " private Elem theObject;\n" + + " public GenericWrapper(Elem arg) {\n" + + " theObject = arg;\n" + + " }\n" + + " public GenericWrapper (GenericWrapper other) {\n" + + " this.theObject = other.theObject;\n" + + " }\n" + + " public String toString() {\n" + + " return theObject.toString();\n" + + " }\n" + + " }\n" + + " private static GenericWrapper method (Object wrappedString) {\n" + + " return (GenericWrapper) wrappedString;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.print(method(new GenericWrapper(\"abc\")));\n" + + " System.out.println(method(new GenericWrapper(new Exception())));\n" + + " }\n" + + "}\n", + }, + "abcjava.lang.Exception"); +} +public void test0658() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X{\n" + + " \n" + + " private static class GenericWrapper {\n" + + " Zork z;\n" + + " private Elem theObject;\n" + + " public GenericWrapper(Elem arg) {\n" + + " theObject = arg;\n" + + " }\n" + + " public GenericWrapper (GenericWrapper other) {\n" + + " this.theObject = other.theObject;\n" + + " }\n" + + " public String toString() {\n" + + " return theObject.toString();\n" + + " }\n" + + " }\n" + + " private static GenericWrapper method (Object wrappedString) {\n" + + " return (GenericWrapper) wrappedString;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.print(method(new GenericWrapper(\"abc\")));\n" + + " System.out.println(method(new GenericWrapper(new Exception())));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " public String toString() {\n" + + " ^^^^^^^^^^\n" + + "The method toString() of type X.GenericWrapper should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " return (GenericWrapper) wrappedString;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to X.GenericWrapper\n" + + "----------\n"); +} +public void test0659() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.ref.*;\n" + + "\n" + + "@SuppressWarnings(\"unused\")\n" + + "public class X extends WeakReference {\n" + + " Zork z;\n" + + " static ReferenceQueue queue = new ReferenceQueue();\n" + + "\n" + + " private K key;\n" + + "\n" + + " public X(K key, V value, ReferenceQueue queue) {\n" + + " super(value, queue);\n" + + " }\n" + + "\n" + + " public K getKey() {\n" + + " return key;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"key:\" + key;\n" + + " }\n" + + "\n" + + " public static void main(String[] arg) throws Exception {\n" + + " X ref = new X(\"Dummy Key\", Integer.valueOf(5), queue);\n" + + " new Thread() {\n" + + " @Override\n" + + " public void run() {\n" + + " for (;;) {\n" + + " // force ref to be cleared\n" + + " System.gc();\n" + + " }\n" + + " }\n" + + " }.start();\n" + + "\n" + + " X fromQueue = (X) queue.remove();\n" + + " System.out.println(fromQueue);\n" + + " System.exit(0);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 34)\n" + + " X fromQueue = (X) queue.remove();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Reference to X\n" + + "----------\n"); +} +public void test0660() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " boolean run(X x) {\n" + + " return false;\n" + + " }\n" + + " void run(Class ct) {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " boolean b = new X().run(new X(){});\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 +public void test0661() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " public X() {\n" + + " S a = (S)(Integer)3;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " S a = (S)(Integer)3;\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Integer to S\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=95066 - variation +public void test0662() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " public X() {\n" + + " S a = (S)(Integer)3; // this should fail\n" + + " }\n" + + " Zork z;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " S a = (S)(Integer)3; // this should fail\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot cast from Integer to S\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=95066 - variation +public void test0663() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " Object foo(Comparable c) {\n" + + " return (Comparable) c;\n" + + " }\n" + + " void foo(List lv) {\n" + + " List l = (List) lv;\n" + + " }\n" + + " void foo2(List> lv) {\n" + + " List l = (List>) lv;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return (Comparable) c;\n" + + " ^\n" + + "S cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " List l = (List) lv;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " List l = (List) lv;\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " List l = (List) lv;\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 11)\n" + + " List l = (List>) lv;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " List l = (List>) lv;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List> to List>\n" + + "----------\n" + + "7. WARNING in X.java (at line 11)\n" + + " List l = (List>) lv;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List> to List>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 - variation +public void test0664() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " public X(X2 x2) {\n" + + " S a = (S)x2;\n" + + " }\n" + + "}\n" + + "abstract class X2 implements Comparable {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " S a = (S)x2;\n" + + " ^^^^^\n" + + "Cannot cast from X2 to S\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95066 - variation +public void test0665() { + this.runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void foo() {\n" + + " A a = new A();\n" + + " Comparable c = (Comparable) a; // Fails as expected\n" + + " Comparable c2 = (Comparable) a; // Should fail?\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "final class A implements Comparable {\n" + + " public int compareTo(A o) {\n" + + " return 0;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Test.java (at line 4)\n" + + " Comparable c = (Comparable) a; // Fails as expected\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from A to Comparable\n" + + "----------\n" + + "2. WARNING in Test.java (at line 5)\n" + + " Comparable c2 = (Comparable) a; // Should fail?\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from A to Comparable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=89940 +public void test0666() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo(List objects, List raw) {\n" + + "\n" + + " List numbers;\n" + + " List ext;\n" + + " \n" + + " numbers= (List) objects; // correct - cast error\n" + + " ext= (List) objects; // wrong, should fail\n" + + "\n" + + " ext= raw; // correct - raw conversion warning issued\n" + + " numbers= raw; // correct - raw conversion warning issued\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(List objects, List raw) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " numbers= (List) objects; // correct - cast error\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " ext= (List) objects; // wrong, should fail\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " ext= raw; // correct - raw conversion warning issued\n" + + " ^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " numbers= raw; // correct - raw conversion warning issued\n" + + " ^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +public void _test0667() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void foo(List l) { }\n" + + " \n" + + " public static void foo2(List l) { }\n" + + " \n" + + " public static void foo3(List l) { }\n" + + " \n" + + " public static void bar(List l) { }\n" + + " \n" + + " public static void bar2(List l) { }\n" + + " \n" + + " public static void bar3(List l) { }\n" + + " \n" + + " public static void bar4(List l) { }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " { // can be { Object, Object[] }\n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // illegal [01]\n" + + " l.add((Object) null); // illegal [02]\n" + + " l.add((Integer) null); // illegal [03]\n" + + " l.add((Object []) null); // illegal [04]\n" + + " l.add((Integer []) null); // illegal [05]\n" + + " l.add((Integer [][]) null); // illegal [06]\n" + + " \n" + + " foo(l); // List - legal [07]\n" + + " foo2(l); // List - illegal [08]\n" + + " foo3(l); // List - illegal [09]\n" + + " bar(l); // List - illegal [10]\n" + + " bar2(l); // List - illegal [11]\n" + + " bar3(l); // List - legal [12]\n" + + " bar4(l); // List - legal [13]\n" + + " }\n" + + " { // can be Object[] or (? extends Object)[]\n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // legal [14]\n" + + " l.add((Object) null); // illegal [15]\n" + + " l.add((Integer) null); // illegal [16]\n" + + " l.add((Object []) null); // legal [17]\n" + + " l.add((Integer []) null); // legal [18]\n" + + " l.add((Integer [][]) null); // legal [19]\n" + + " \n" + + " foo(l); // List - legal [20]\n" + + " foo2(l); // List - legal [21]\n" + + " foo3(l); // List - legal [22]\n" + + " bar(l); // List - illegal [23]\n" + + " bar2(l); // List - illegal [24]\n" + + " bar3(l); // List - legal [25]\n" + + " bar4(l); // List - legal [26]\n" + + " }\n" + + " { // Only allows wildcards, Object is illegal.\n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // illegal [27]\n" + + " l.add((Object) null); // illegal [28]\n" + + " l.add((Integer) null); // illegal [29]\n" + + " l.add((Object []) null); // illegal [30]\n" + + " l.add((Integer []) null); // illegal [31]\n" + + " l.add((Integer [][]) null); // illegal [32]\n" + + " \n" + + " foo(l); // List - illegal [33]\n" + + " foo2(l); // List - illegal [34]\n" + + " foo3(l); // List - legal [35]\n" + + " bar(l); // List - illegal [36]\n" + + " bar2(l); // List - illegal [37]\n" + + " bar3(l); // List - legal [38]\n" + + " bar4(l); // List - legal [39]\n" + + " }\n" + + " { // can add non-arrays but can only match ? super Object, ? super Object[], or ? extends Object, but not Object \n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // legal [40]\n" + + " l.add((Object) null); // legal [41]\n" + + " l.add((Integer) null); // legal [42]\n" + + " l.add((Object []) null); // illegal [43]\n" + + " l.add((Integer []) null); // illegal [44]\n" + + " l.add((Integer [][]) null); // illegal [45]\n" + + " \n" + + " foo(l); // legal [46]\n" + + " foo2(l); // illegal [47]\n" + + " foo3(l); // illegal [48]\n" + + " bar(l); // legal [49]\n" + + " bar2(l); // illegal [50]\n" + + " bar3(l); // legal [51]\n" + + " bar4(l); // legal [52]\n" + + " }\n" + + " { // can add array but cannot call a method which expects an array. 100% !\n" + + " List l = new ArrayList();\n" + + " l.get(0).toString();\n" + + " l.add(l.get(0)); // legal [53]\n" + + " l.add((Object) null); // legal [54]\n" + + " l.add((Integer) null); // legal [55]\n" + + " l.add((Object []) null); // legal [56]\n" + + " l.add((Integer []) null); // legal [57]\n" + + " l.add((Integer [][]) null); // legal [58]\n" + + " \n" + + " foo(l); // legal [59]\n" + + " foo2(l); // illegal [60]\n" + + " foo3(l); // illegal [61]\n" + + " bar(l); // legal [62]\n" + + " bar2(l); // legal [63]\n" + + " bar3(l); // legal [64]\n" + + " bar4(l); // legal [65]\n" + + " }\n" + + " { // cannot add any type but can match ? or ? extends Object.\n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // illegal [66]\n" + + " l.add((Object) null); // illegal [67]\n" + + " l.add((Integer) null); // illegal [68]\n" + + " l.add((Object []) null); // illegal [69]\n" + + " l.add((Integer []) null); // illegal [70]\n" + + " l.add((Integer [][]) null); // illegal [71]\n" + + " \n" + + " foo(l); // List - illegal [72]\n" + + " foo2(l); // List - illegal [73]\n" + + " foo3(l); // List - illegal [74]\n" + + " bar(l); // List - illegal [75]\n" + + " bar2(l); // List - illegal [76]\n" + + " bar3(l); // List - legal [77]\n" + + " bar4(l); // List - legal [78]\n" + + " }\n" + + " { // same as ? extends Object.\n" + + " List l = new ArrayList();\n" + + " l.add(l.get(0)); // illegal [79]\n" + + " l.add((Object) null); // illegal [80]\n" + + " l.add((Integer) null); // illegal [81]\n" + + " l.add((Object []) null); // illegal [82]\n" + + " l.add((Integer []) null); // illegal [83]\n" + + " l.add((Integer [][]) null); // illegal [84]\n" + + " \n" + + " foo(l); // List - illegal [85]\n" + + " foo2(l); // List - illegal [86]\n" + + " foo3(l); // List - illegal [87]\n" + + " bar(l); // List - illegal [88]\n" + + " bar2(l); // List - illegal [89]\n" + + " bar3(l); // List - legal [90]\n" + + " bar4(l); // List - legal [91]\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 21)\n" + + " l.add(l.get(0)); // illegal [01]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (capture-of ? super Object[])\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " l.add((Object) null); // illegal [02]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " l.add((Integer) null); // illegal [03]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Integer)\n" + + "----------\n" + + "4. ERROR in X.java (at line 24)\n" + + " l.add((Object []) null); // illegal [04]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Object[])\n" + + "----------\n" + + "5. ERROR in X.java (at line 25)\n" + + " l.add((Integer []) null); // illegal [05]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Integer[])\n" + + "----------\n" + + "6. ERROR in X.java (at line 26)\n" + + " l.add((Integer [][]) null); // illegal [06]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object[]) in the type List is not applicable for the arguments (Integer[][])\n" + + "----------\n" + + "7. ERROR in X.java (at line 28)\n" + + " foo(l); // List - legal [07]\n" + + " ^^^\n" + + "The method foo(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "8. ERROR in X.java (at line 29)\n" + + " foo2(l); // List - illegal [08]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "9. ERROR in X.java (at line 30)\n" + + " foo3(l); // List - illegal [09]\n" + + " ^^^^\n" + + "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "10. ERROR in X.java (at line 31)\n" + + " bar(l); // List - illegal [10]\n" + + " ^^^\n" + + "The method bar(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "11. ERROR in X.java (at line 32)\n" + + " bar2(l); // List - illegal [11]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "12. ERROR in X.java (at line 39)\n" + + " l.add((Object) null); // illegal [15]\n" + + " ^^^\n" + + "The method add(Object[]) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "13. ERROR in X.java (at line 40)\n" + + " l.add((Integer) null); // illegal [16]\n" + + " ^^^\n" + + "The method add(Object[]) in the type List is not applicable for the arguments (Integer)\n" + + "----------\n" + + "14. ERROR in X.java (at line 48)\n" + + " bar(l); // List - illegal [23]\n" + + " ^^^\n" + + "The method bar(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "15. ERROR in X.java (at line 49)\n" + + " bar2(l); // List - illegal [24]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "16. ERROR in X.java (at line 55)\n" + + " l.add(l.get(0)); // illegal [27]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (capture-of ? extends Object[])\n" + + "----------\n" + + "17. ERROR in X.java (at line 56)\n" + + " l.add((Object) null); // illegal [28]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "18. ERROR in X.java (at line 57)\n" + + " l.add((Integer) null); // illegal [29]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Integer)\n" + + "----------\n" + + "19. ERROR in X.java (at line 58)\n" + + " l.add((Object []) null); // illegal [30]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Object[])\n" + + "----------\n" + + "20. ERROR in X.java (at line 59)\n" + + " l.add((Integer []) null); // illegal [31]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Integer[])\n" + + "----------\n" + + "21. ERROR in X.java (at line 60)\n" + + " l.add((Integer [][]) null); // illegal [32]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object[]) in the type List is not applicable for the arguments (Integer[][])\n" + + "----------\n" + + "22. ERROR in X.java (at line 62)\n" + + " foo(l); // List - illegal [33]\n" + + " ^^^\n" + + "The method foo(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "23. ERROR in X.java (at line 63)\n" + + " foo2(l); // List - illegal [34]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "24. ERROR in X.java (at line 65)\n" + + " bar(l); // List - illegal [36]\n" + + " ^^^\n" + + "The method bar(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "25. ERROR in X.java (at line 66)\n" + + " bar2(l); // List - illegal [37]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "26. ERROR in X.java (at line 75)\n" + + " l.add((Object []) null); // illegal [43]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object) in the type List is not applicable for the arguments (Object[])\n" + + "----------\n" + + "27. ERROR in X.java (at line 76)\n" + + " l.add((Integer []) null); // illegal [44]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object) in the type List is not applicable for the arguments (Integer[])\n" + + "----------\n" + + "28. ERROR in X.java (at line 77)\n" + + " l.add((Integer [][]) null); // illegal [45]\n" + + " ^^^\n" + + "The method add(capture-of ? super Object) in the type List is not applicable for the arguments (Integer[][])\n" + + "----------\n" + + "29. ERROR in X.java (at line 79)\n" + + " foo(l); // legal [46]\n" + + " ^^^\n" + + "The method foo(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "30. ERROR in X.java (at line 80)\n" + + " foo2(l); // illegal [47]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "31. ERROR in X.java (at line 81)\n" + + " foo3(l); // illegal [48]\n" + + " ^^^^\n" + + "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "32. ERROR in X.java (at line 83)\n" + + " bar2(l); // illegal [50]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "33. ERROR in X.java (at line 98)\n" + + " foo2(l); // illegal [60]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "34. ERROR in X.java (at line 99)\n" + + " foo3(l); // illegal [61]\n" + + " ^^^^\n" + + "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "35. ERROR in X.java (at line 107)\n" + + " l.add(l.get(0)); // illegal [66]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (capture-of ? extends Object)\n" + + "----------\n" + + "36. ERROR in X.java (at line 108)\n" + + " l.add((Object) null); // illegal [67]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "37. ERROR in X.java (at line 109)\n" + + " l.add((Integer) null); // illegal [68]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Integer)\n" + + "----------\n" + + "38. ERROR in X.java (at line 110)\n" + + " l.add((Object []) null); // illegal [69]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Object[])\n" + + "----------\n" + + "39. ERROR in X.java (at line 111)\n" + + " l.add((Integer []) null); // illegal [70]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Integer[])\n" + + "----------\n" + + "40. ERROR in X.java (at line 112)\n" + + " l.add((Integer [][]) null); // illegal [71]\n" + + " ^^^\n" + + "The method add(capture-of ? extends Object) in the type List is not applicable for the arguments (Integer[][])\n" + + "----------\n" + + "41. ERROR in X.java (at line 114)\n" + + " foo(l); // List - illegal [72]\n" + + " ^^^\n" + + "The method foo(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "42. ERROR in X.java (at line 115)\n" + + " foo2(l); // List - illegal [73]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "43. ERROR in X.java (at line 116)\n" + + " foo3(l); // List - illegal [74]\n" + + " ^^^^\n" + + "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "44. ERROR in X.java (at line 117)\n" + + " bar(l); // List - illegal [75]\n" + + " ^^^\n" + + "The method bar(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "45. ERROR in X.java (at line 118)\n" + + " bar2(l); // List - illegal [76]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "46. ERROR in X.java (at line 124)\n" + + " l.add(l.get(0)); // illegal [79]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (capture-of ?)\n" + + "----------\n" + + "47. ERROR in X.java (at line 125)\n" + + " l.add((Object) null); // illegal [80]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (Object)\n" + + "----------\n" + + "48. ERROR in X.java (at line 126)\n" + + " l.add((Integer) null); // illegal [81]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (Integer)\n" + + "----------\n" + + "49. ERROR in X.java (at line 127)\n" + + " l.add((Object []) null); // illegal [82]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (Object[])\n" + + "----------\n" + + "50. ERROR in X.java (at line 128)\n" + + " l.add((Integer []) null); // illegal [83]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (Integer[])\n" + + "----------\n" + + "51. ERROR in X.java (at line 129)\n" + + " l.add((Integer [][]) null); // illegal [84]\n" + + " ^^^\n" + + "The method add(capture-of ?) in the type List is not applicable for the arguments (Integer[][])\n" + + "----------\n" + + "52. ERROR in X.java (at line 131)\n" + + " foo(l); // List - illegal [85]\n" + + " ^^^\n" + + "The method foo(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "53. ERROR in X.java (at line 132)\n" + + " foo2(l); // List - illegal [86]\n" + + " ^^^^\n" + + "The method foo2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "54. ERROR in X.java (at line 133)\n" + + " foo3(l); // List - illegal [87]\n" + + " ^^^^\n" + + "The method foo3(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "55. ERROR in X.java (at line 134)\n" + + " bar(l); // List - illegal [88]\n" + + " ^^^\n" + + "The method bar(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "56. ERROR in X.java (at line 135)\n" + + " bar2(l); // List - illegal [89]\n" + + " ^^^^\n" + + "The method bar2(List) in the type X is not applicable for the arguments (List)\n" + + "----------\n"); +} +public void test0668() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.List;\n" + + " \n" + + "public class X {\n" + + " void foo(List l) {\n" + + " l.add(new Object[0]);\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95289 +public void test0669() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "private static int indexOf(final T[] array,final T elem) {\n" + + " return 0;\n" + + "}\n" + + "public static void meth(AContainer ac, AInfo[] aiArray) {\n" + + " for(AInfo ai: aiArray) {\n" + + " int index1 = indexOf(ac.getAs(),ai.a);\n" + + " int index2 = indexOf(ac.getAs(),ai); // ai.class!=ai.a.class!!!\n" + + " }\n" + + "}\n" + + "}\n" + + "\n" + + "class AContainer {\n" + + " public A[] getAs(){ return null; }\n" + + "}\n" + + "\n" + + "class AInfo {\n" + + " public A a;\n" + + "}\n" + + "\n" + + "class A {\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 (ensure not even a warning) +public void test0670() { + runConformTest( + true, + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "interface MethodProperty> {\n" + + " public void copyFrom(ActualType other);\n" + + "}\n" + + "\n" + + "class MethodPropertyDatabase> {\n" + + " Map propertyMap;\n" + + " \n" + + " void read(String fileName) {\n" + + " }\n" + + "}\n" + + "\n" + + "class FooProperty implements MethodProperty {\n" + + " String value;\n" + + "\n" + + " public void copyFrom(FooProperty other) {\n" + + " this.value = other.value;\n" + + " }\n" + + "}\n" + + "\n" + + "class FooPropertyDatabase extends MethodPropertyDatabase {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " FooPropertyDatabase fooDatabase;\n" + + " \n" + + " public void readDatabase() {\n" + + " FooPropertyDatabase database = new FooPropertyDatabase();\n" + + " \n" + + " fooDatabase = readDatabase(database, \"foodatabase.db\"); // Bug reported on this line\n" + + " }\n" + + " \n" + + " private<\n" + + " Property extends MethodProperty,\n" + + " DatabaseType extends MethodPropertyDatabase\n" + + " > DatabaseType readDatabase(DatabaseType database, String fileName) {\n" + + " database.read(fileName);\n" + + " return database;\n" + + " }\n" + + " \n" + + "}\n", + }, + "", + null, + null, + JavacTestOptions.EclipseJustification.EclipseBug95021); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 - variation: ensure not even a warning +public void test0671() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "interface MethodProperty> {\n" + + " public void copyFrom(ActualType other);\n" + + "}\n" + + "\n" + + "class MethodPropertyDatabase> {\n" + + " Map propertyMap;\n" + + " \n" + + " void read(String fileName) {\n" + + " }\n" + + "}\n" + + "\n" + + "class FooProperty implements MethodProperty {\n" + + " String value;\n" + + "\n" + + " public void copyFrom(FooProperty other) {\n" + + " this.value = other.value;\n" + + " }\n" + + "}\n" + + "\n" + + "class FooPropertyDatabase extends MethodPropertyDatabase {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Zork z;\n" + + " FooPropertyDatabase fooDatabase;\n" + + " \n" + + " public void readDatabase() {\n" + + " FooPropertyDatabase database = new FooPropertyDatabase();\n" + + " \n" + + " fooDatabase = readDatabase(database, \"foodatabase.db\"); // Bug reported on this line\n" + + " }\n" + + " \n" + + " private<\n" + + " Property extends MethodProperty,\n" + + " DatabaseType extends MethodPropertyDatabase\n" + + " > DatabaseType readDatabase(DatabaseType database, String fileName) {\n" + + " database.read(fileName);\n" + + " return database;\n" + + " }\n" + + " \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 26)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 - variation: ensure not even a warning +// SHOULD FAIL AT 1.8 (18.2.3): The method read(D, String) in the type X is not applicable for the arguments (Bar, String) +public void test0672() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Foo> {\n" + + "}\n" + + "\n" + + "class Bar {\n" + + "}\n" + + "\n" + + "\n" + + "public class X {\n" + + " Zork z;\n" + + " void readDatabase() {\n" + + " Bar bar = new Bar();\n" + + " read(bar, \"sadasd\");\n" + + " }\n" + + " \n" + + "

, D extends Bar

> \n" + + " D read(D d, String s) {\n" + + " return d;\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" + + "2. WARNING in X.java (at line 11)\n" + + " Bar bar = new Bar();\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " Bar bar = new Bar();\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " read(bar, \"sadasd\");\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation read(Bar, String) of the generic method read(D, String) of type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 +public void test0673() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "class Key> {\n" + + "}\n" + + "\n" + + "class State {\n" + + "}\n" + + "\n" + + "class Type> {\n" + + "}\n" + + "\n" + + "class Store, C extends Key, D extends State> {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " List, ? extends State>> stores;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation +public void test0674() { + this.runConformTest( + new String[] { + "X.java", + "class Key> {}\n" + + "class Store> {}\n" + + "\n" + + "public class X> {\n" + + " Store> store;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation +public void test0675() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "class Key> {}\n" + + "class Store> {}\n" + + "\n" + + "public class X {\n" + + " Store> store1;\n" + + " Store> store2;\n" + + "}\n", + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " Store> store1;\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter > of the type Key\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Store> store2;\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends T is not a valid substitute for the bounded parameter > of the type Key\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//check fault tolerance, in spite of bound mismatch, still pass param type for further resolving message send +public void test0676() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " \n" + + " void foo(X xs) {\n" + + " xs.get().printStackTrace();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " void foo(X xs) {\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " xs.get().printStackTrace();\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method printStackTrace() is undefined for the type String\n" + + "----------\n"); +} +public void test0677() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " {\n" + + " ArrayList arrayList = new ArrayList(); // compile error\n" + + " Number number = arrayList.get(0);\n" + + " }\n" + + " {\n" + + " ArrayList arrayList = new ArrayList(); //correct\n" + + " Number number = arrayList.get(0);\n" + + " }\n" + + " {\n" + + " ArrayList arrayList = new ArrayList();\n" + + " Object number = arrayList.get(0); //returns java.lang.Object\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " ArrayList arrayList = new ArrayList(); // compile error\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from ArrayList to ArrayList\n" + + "----------\n"); +} +public void test0678() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " \n" + + " X right1;\n" + + " X wrong1;\n" + + " X right2;\n" + + " \n" + + " static class Y implements Serializable {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public class X {\n" + + " ^^^^^^^^^^^^\n" + + "Cannot specify any additional bound Serializable when first bound is a type parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X wrong1;\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type Serializable is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " static class Y implements Serializable {\n" + + " ^\n" + + "The serializable class Y does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation +public void test0679() { + this.runConformTest( + new String[] { + "X.java", + "class Key> {}\n" + + "class Store> {}\n" + + "\n" + + "public class X> {\n" + + " Store> store;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation +public void test0680() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "class Key, G extends Key, H extends State> {}\n" + + "class State {}\n" + + "class Type, V extends Key, W extends State> {}\n" + + "class Store, C extends Key, D extends State> {}\n" + + "\n" + + "public class X> {\n" + + " List, ? extends State>> stores;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95638 - variation +public void test0681() { + this.runConformTest( + new String[] { + "X.java", + "class Key> {\n" + + "}\n" + + "class Store> {\n" + + "}\n" + + "class X {\n" + + " Store store1;\n" + + " Store> store2;\n" + + "\n" + + " class StoreHolder > {\n" + + " Store store;\n" + + " }\n" + + "}\n" + + "class Y> {\n" + + " Y y;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95963 +public void test0682() { + this.runNegativeTest( + new String[] { + "X.java", + "class X extends A {}\n" + + "class A {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends A {}\n" + + " ^^^\n" + + "X.M cannot be resolved to a type\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96085 +public void test0683() { + this.runConformTest( + new String[] { + "P.java", + "public interface P {\n" + + " interface A {}\n" + + "}\n", + "P2.java", + "public class P2 implements P.A {\n" + + " P2(P.A problem) {}\n" + + "}\n", + "P3.java", + "public class P3 {\n" + + " void test() {P.A o = new P2((P.A) null);}\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "P3.java", + "class P3 {\n" + + " void test() {P.A o = new P2((P.A) null);}\n" + + "}\n", + }, + "", + null, + false, + null); +} +public void test0684() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " U foo(U u1, U u2) {\n" + + " return u1;\n" + + " }\n" + + " void bar(X x1, X x2) {\n" + + " X x = foo(x1, x2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X x = foo(x1, x2);\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n"); +} +public void test0685() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " U foo(U u1, U u2) {\n" + + " return u1;\n" + + " }\n" + + " void bar(X x1, X x2) {\n" + + " X x = foo(x1, x2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X x = foo(x1, x2);\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n"); +} +// check wildcard bounds wrt variable boundCheck +public void test0686() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Other> {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Other> other1;\n" + + " Other> other2; \n" + + " Other> other3; \n" + + " Other> other7 = other1;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Other> other2; \n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Other> other3; \n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n"); +} +// check wildcard bounds wrt variable boundCheck +public void test0687() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Other> {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Other> other2;\n" + + " Other> other3;\n" + + " Other> other4;\n" + + " Other> other5;\n" + + " Other> other6;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Other> other3;\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Other> other4;\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Other> other5;\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " Other> other6;\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n"); +} +// check wildcard bounds wrt variable boundCheck +public void test0688() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Other> {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Other> other5;\n" + + "}\n", + }, + ""); +} +// check wildcard bounds wrt variable boundCheck +public void test0689() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Other> {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " Other> other5;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Other> other5;\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super List is not a valid substitute for the bounded parameter > of the type Other\n" + + "----------\n"); +} +// check assignment rules across param types with wildcards +public void test0690() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void foo(List lr, List la) {\n" + + " lr = la;\n" + + " la = lr;\n" + + " }\n" + + "} \n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " lr = la;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); +} +// check that final class bound is more restrictive +public void test0691() { + this.runNegativeTest( + new String[] { + "XX.java", + "public class XX {\n" + + " void foo(XX lhs, XX rhs) {\n" + + " lhs = rhs;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in XX.java (at line 2)\n" + + " void foo(XX lhs, XX rhs) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends String is not a valid substitute for the bounded parameter of the type XX\n" + + "----------\n"); +} +// check wildcard bounds wrt variable boundCheck +public void test0692() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X> {\n" + + " \n" + + " void foo(X> x) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " void foo(X> x) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n"); +} +// bound checks +public void test0693() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X> x1;\n" + + " X x2;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X> x1;\n" + + " ^\n" + + "Bound mismatch: The type X is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " X> x1;\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " X x2;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends String is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n"); +} +// bound checks +public void test0694() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " X>> x1;\n" + + " X>> x2;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X>> x1;\n" + + " ^\n" + + "Bound mismatch: The type X> is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " X>> x1;\n" + + " ^\n" + + "Bound mismatch: The type X is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " X>> x1;\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " X>> x2;\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends X> is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 3)\n" + + " X>> x2;\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends X is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 3)\n" + + " X>> x2;\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n"); +} +// bound checks +public void test0695() { + this.runConformTest( + new String[] { + "I.java", + "interface I> {\n" + + "}\n", + }, + ""); +} +public void test0696() { + this.runNegativeTest( + new String[] { + "X.java", + "class Key> {}\n" + + "class Store> {}\n" + + "\n" + + "public class X {\n" + + " Store> store = new Store>();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Store> store = new Store>();\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter > of the type Key\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Store> store = new Store>();\n" + + " ^^^\n" + + "Bound mismatch: The type Key is not a valid substitute for the bounded parameter > of the type Store\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Store> store = new Store>();\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter > of the type Key\n" + + "----------\n"); +} +public void test0697() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X> {\n" + + " V v;\n" + + " \n" + + " void foo(X x1, X x2) {\n" + + " String s =x1.v.get(0);\n" + + " Object o = x2.v.get(0);\n" + + " \n" + + " }\n" + + "}\n", + }, + ""); +} +public void test0698() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X, V extends List> {\n" + + " \n" + + " X x;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X x;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super Exception is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X x;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? super Exception is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n"); +} +public void test0699() { + this.runNegativeTest( + new String[] { + "X2.java", + "import java.util.List;\n" + + "class Other2> {\n" + + "}\n" + + "\n" + + "class X2 {\n" + + " Other2> other1;\n" + + " Other2> other2; \n" + + " Other2> other3; \n" + + " Other2> other7 = other1;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X2.java (at line 6)\n" + + " Other2> other1;\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other2\n" + + "----------\n" + + "2. ERROR in X2.java (at line 7)\n" + + " Other2> other2; \n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other2\n" + + "----------\n" + + "3. ERROR in X2.java (at line 8)\n" + + " Other2> other3; \n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends List is not a valid substitute for the bounded parameter > of the type Other2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96646 +public void test0700() { + this.runConformTest( + new String[] { + "X.java", + "abstract class BaseFactory {\n" + + " public T create() throws Exception {\n" + + " return getType().newInstance();\n" + + " }\n" + + " public abstract Class getType();\n" + + "}\n" + + "interface StringFactory {\n" + + " public String create() throws Exception;\n" + + "}\n" + + "public class X extends BaseFactory implements StringFactory {\n" + + " @Override\n" + + " public Class getType() {\n" + + " return String.class;\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " String emptyString = new X().create();\n" + + " System.out.printf(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//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", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "class Deejay {\n" + + " class Counter {}\n" + + "\n" + + " Counter songCounter = new Counter();\n" + + " Counter genreCounter = new Counter();\n" + + "\n" + + " List> list1 = Arrays.asList(songCounter, genreCounter);\n" + + " List> list2 = Arrays.asList(songCounter, genreCounter);\n" + + " List> list3 = Arrays.>asList(songCounter, genreCounter);\n" + + " List> list4 = Arrays.asList(new Counter[] {songCounter, genreCounter});\n" + + " List> list5 = Arrays.asList(songCounter, genreCounter);\n" + + "}\n" + + "class Genre {}\n" + + "class Song {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " List> list5 = Arrays.asList(songCounter, genreCounter);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97303 - variation +public void test0702() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements Runnable {\n" + + " \n" + + " void foo0(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 0\n" + + " }\n" + + " void foo1(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 1\n" + // TODO (philippe) should be ok using capture rules for equivalence + " }\n" + + " void foo2(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 2\n" + + " }\n" + + " void foo3(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 3\n" + + " }\n" + + " void foo4(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 4\n" + + " }\n" + + " void foo5(X> lhs, X> rhs) {\n" + + " lhs = rhs; // 5\n" + + " }\n" + + " void foo6(X>>>> lhs, X>>>> rhs) {\n" + + " lhs = rhs; // 6\n" + + " } \n" + + " public void run() {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " lhs = rhs; // 1\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X> to X>\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " lhs = rhs; // 2\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X> to X>\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " lhs = rhs; // 3\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X> to X>\n" + + "----------\n" + + "4. ERROR in X.java (at line 19)\n" + + " lhs = rhs; // 5\n" + + " ^^^\n" + + "Type mismatch: cannot convert from X> to X>\n" + + "----------\n"); +} +public void test0703() { + this.runConformTest( + new String[] { + "X.java", + "public class X> {}\n" + + "class Y extends X {\n" + + " X p = (Y)null;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97800 +public void test0704() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List l = (List)Collections.emptyList();\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " List l = (List)Collections.emptyList();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97480 +public void test0705() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " void f(Object o){\n" + + " ((Map.Entry)o).setValue(\"bug\");\n" + + " \n" + + " Map.Entry me= (Map.Entry)o; \n" + + " me.setValue(\"ok\");\n" + + " \n" + + " ((Vector)o).add(\"ok\");\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " ((Map.Entry)o).setValue(\"bug\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method setValue(Object) belongs to the raw type Map.Entry. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " ((Map.Entry)o).setValue(\"bug\");\n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " Map.Entry me= (Map.Entry)o; \n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " Map.Entry me= (Map.Entry)o; \n" + + " ^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " me.setValue(\"ok\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method setValue(Object) belongs to the raw type Map.Entry. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " ((Vector)o).add(\"ok\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type Vector. References to generic type Vector should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " ((Vector)o).add(\"ok\");\n" + + " ^^^^^^\n" + + "Vector is a raw type. References to generic type Vector should be parameterized\n" + + "----------\n" + + "8. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97219 +public void test0706() { + String outputExpectedBelow17 = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " class BB extends AA { BB test() {return null;} }\n" + + " ^^^^^^\n" + + "Name clash: The method test() of type BB has the same erasure as test() of type AA but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " class BB extends AA { BB test() {return null;} }\n" + + " ^^^^^^\n" + + "Name clash: The method test() of type BB has the same erasure as test() of type AA but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " BB bb = new BB();\n" + + " bb.test();\n" + + " ((AA) bb).test();\n" + + " }\n" + + "}\n" + + "class AA { AA test() {return null;} }\n" + + "class BB extends AA { BB test() {return null;} }\n" + + "class CC {}\n", + }, + (this.complianceLevel < ClassFileConstants.JDK1_7) + ? outputExpectedBelow17 + : "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " class BB extends AA { BB test() {return null;} }\n" + + " ^^^^^^\n" + + "Name clash: The method test() of type BB has the same erasure as test() of type AA but does not override it\n" + + "----------\n" + ); +/* +X.java:4: reference to test is ambiguous, both method test() in AA and method test() in BB match + bb.test(); + ^ + where U is a type-variable: + U extends Object declared in method test() +X.java:9: name clash: test() in BB and test() in AA have the same erasure, yet neither overrides the other +class BB extends AA { BB test() {return null;} } + ^ + where U is a type-variable: + U extends Object declared in method test() +2 errors + */ +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97219 +public void test0706a() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AA res1 = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " AA res3 = bb.test();\n" + + " ^^\n" + + "AA is a raw type. References to generic type AA should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " AA res3 = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " class BB extends AA { BB test() {return null;} }\n" + + " ^^^^^^\n" + + "Name clash: The method test() of type BB has the same erasure as test() of type AA but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AA res1 = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " AA res3 = bb.test();\n" + + " ^^\n" + + "AA is a raw type. References to generic type AA should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " AA res3 = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " class BB extends AA { BB test() {return null;} }\n" + + " ^^^^^^\n" + + "Name clash: The method test() of type BB has the same erasure as test() of type AA but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " BB bb = new BB();\n" + + " AA res1 = bb.test();\n" + + " AA res3 = bb.test();\n" + + " }\n" + + "}\n" + + "class AA { AA test() {return null;} }\n" + + "class BB extends AA { BB test() {return null;} }\n" + + "class CC {}\n", + }, + expectedCompilerLog + ); +/* +X.java:4: reference to test is ambiguous, both method test() in AA and method test() in BB match + AA res1 = bb.test(); + ^ + where U is a type-variable: + U extends Object declared in method test() +X.java:5: reference to test is ambiguous, both method test() in AA and method test() in BB match + AA res3 = bb.test(); + ^ + where U is a type-variable: + U extends Object declared in method test() +X.java:9: name clash: test() in BB and test() in AA have the same erasure, yet neither overrides the other +class BB extends AA { BB test() {return null;} } + ^ + where U is a type-variable: + U extends Object declared in method test() +3 errors + */ +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97219 +public void test0706b() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AA res = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " BB res2 = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " class BB extends AA { BB test() {return null;} }\n" + + " ^^^^^^\n" + + "Name clash: The method test() of type BB has the same erasure as test() of type AA but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AA res = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " BB res2 = bb.test();\n" + + " ^^^^\n" + + "The method test() is ambiguous for the type BB\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " class BB extends AA { BB test() {return null;} }\n" + + " ^^^^^^\n" + + "Name clash: The method test() of type BB has the same erasure as test() of type AA but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " BB bb = new BB();\n" + + " AA res = bb.test();\n" + + " BB res2 = bb.test();\n" + + " }\n" + + "}\n" + + "class AA { AA test() {return null;} }\n" + + "class BB extends AA { BB test() {return null;} }\n" + + "class CC {}\n", + }, + expectedCompilerLog + ); +/* +X.java:4: reference to test is ambiguous, both method test() in AA and method test() in BB match + AA res = bb.test(); + ^ + where U is a type-variable: + U extends Object declared in method test() +X.java:4: incompatible types + AA res = bb.test(); + ^ + required: AA + found: AA +X.java:5: reference to test is ambiguous, both method test() in AA and method test() in BB match + BB res2 = bb.test(); + ^ + where U is a type-variable: + U extends Object declared in method test() +X.java:5: incompatible types + BB res2 = bb.test(); + ^ + required: BB + found: AA +X.java:9: name clash: test() in BB and test() in AA have the same erasure, yet neither overrides the other +class BB extends AA { BB test() {return null;} } + ^ + where U is a type-variable: + U extends Object declared in method test() +5 errors + */ + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " BB bb = new BB();\n" + + " AA res = bb.test();\n" + + " BB res2 = bb.test();\n" + + " }\n" + + "}\n" + + "class AA { AA test() {return null;} }\n" + + "class BB extends AA { }\n" + + "class CC {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " AA res = bb.test();\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from AA to AA\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " BB res2 = bb.test();\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from AA to BB\n" + + "----------\n" + ); +/* +X.java:4: incompatible types + AA res = bb.test(); + ^ + required: AA + found: AA +X.java:5: incompatible types + BB res2 = bb.test(); + ^ + required: BB + found: AA +2 errors + */ +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98079 +public void test0707() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " B b() {\n" + + " return a();\n" + + " }\n" + + " \n" + + " B a() {\n" + + " return null;\n" + + " }\n" + + " \n" + + " static class B { }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95684 +public void test0708() { + this.runConformTest( + new String[] { + "UserClass.java", + "public class UserClass {\n" + + " protected class DataHolder {}\n" + + " protected void loadHook(DataHolder data) {}\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "ChildClass.java", + "public class ChildClass extends UserClass {\n" + + " @Override protected void loadHook(DataHolder data) {}\n" + + "}\n", + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=95684 - variation +public void test0709() { + this.runConformTest( + new String[] { + "UserClass.java", + "public class UserClass {\n" + + " protected class DataHolder {}\n" + + " protected void loadHook(DataHolder[] data) {}\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "ChildClass.java", + "public class ChildClass extends UserClass {\n" + + " @Override protected void loadHook(DataHolder[] data) {}\n" + + "}\n", + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96713 +public void test0710() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static > P createDataObject(V value) {\n" + + " return null;\n" + + " }\n" + + " public static void testCreateDataObject(Object v) {\n" + + " Persistent d = createDataObject(v);\n" + + " }\n" + + "\n" + + " private interface Persistent {\n" + + " public V getValueObject();\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97108 +public void test0711(){ + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.HashMap;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + " static private Map m1 = new HashMap();\n" + + " private List m2 = new ArrayList();\n" + + " static protected XX foo()\n" + + " {\n" + + " return null;\n" + + " }\n" + + " static public abstract class XX\n" + + " {\n" + + " }\n" + + "}\n", + }, + ""); + + this.runConformTest( + new String[] { + "Y.java", + "public class Y extends X \n" + + "{ \n" + + "}\n" + }, + "", + null, + false, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97108 +// The case that works +public void test0712(){ + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.HashMap;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + " static private Map m1 = new HashMap();\n" + + " private List> m2 = new ArrayList>();\n" + + " static protected XX foo()\n" + + " {\n" + + " return null;\n" + + " }\n" + + " static public abstract class XX\n" + + " {\n" + + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "Y.java", + "public class Y extends X \n" + + "{ \n" + + "}\n" + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96713 +public void test0713() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int i = 0;\n" + + " interface Y {\n" + + " java.util.List lt = null;\n" + + " int j = i;\n" + + " void m1(T t); \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " java.util.List lt = null;\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int j = i;\n" + + " ^\n" + + "Cannot make a static reference to the non-static field i\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " void m1(T t); \n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98232 +public void test0714() { + this.runConformTest( + new String[] { + "B.java", + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "import java.util.SortedSet;\n" + + "\n" + + "public class B {\n" + + " static Set foo(SortedSet set) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n", + }, + ""); + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " A() {\n" + + " B.foo(null);\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98393 +public void test0715() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Comparable c = (java.util.List)bar(5, 5.0);\n" + + " }\n" + + " \n" + + " T bar(T t1, T t2) { return t1; }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Comparable c = (java.util.List)bar(5, 5.0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to Comparable\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Comparable c = (java.util.List)bar(5, 5.0);\n" + + " ^^^^^^^^^^^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98396 +// ** +public void test0716() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " void foo(T t) {\n" + + " Comparable ci = (Comparable) t; \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Comparable ci = (Comparable) t; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from T to Comparable\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=98396 - variation +public void test0717() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X & List> {\n" + + " void foo(T t) {\n" + + " Comparable ci = (Comparable) t; \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Comparable ci = (Comparable) t; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from T to Comparable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98478 +// SHOULD FAIL AT 1.8 (18.2.3): The method max(Collection) in the type Collections is not applicable for the arguments (Set) +public void test0718() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collections;\n" + + "import java.util.Set;\n" + + "import java.util.TreeSet;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public interface Base {\n" + + " }\n" + + " \n" + + " abstract class Action {\n" + + " }\n" + + "\n" + + " public class ActionImpl extends Action implements Comparable {\n" + + " public int compareTo(ActionImpl o) {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " public void test() {\n" + + " Set set = new TreeSet();\n" + + " Collections.max(set);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " public class ActionImpl extends Action implements Comparable {\n" + + " ^^^^^^^^^^\n" + + "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " public int compareTo(ActionImpl o) {\n" + + " ^^^^^^^^^^\n" + + "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 20)\n" + + " Set set = new TreeSet();\n" + + " ^^^^^^^^^^\n" + + "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 20)\n" + + " Set set = new TreeSet();\n" + + " ^^^^^^^^^^\n" + + "X.ActionImpl is a raw type. References to generic type X.ActionImpl should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 21)\n" + + " Collections.max(set);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation max(Set) of the generic method max(Collection) of type Collections\n" + + "----------\n" + + "6. ERROR in X.java (at line 23)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98364 +public void test0719() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.ListIterator;\n" + + "\n" + + "interface IntegerIterator extends Iterator {}\n" + + "interface IntegerListIterator extends ListIterator, IntegerIterator {}\n" + + "\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " interface IntegerIterator extends Iterator {}\n" + + " ^^^^^^^^\n" + + "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " interface IntegerListIterator extends ListIterator, IntegerIterator {}\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The interface Iterator cannot be implemented more than once with different arguments: Iterator and Iterator\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98364 - variation +public void test0720() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Foo {}\n" + + "interface Bar extends Foo {}\n" + + "interface Baz extends Bar, Foo {}\n" + + "\n" + + "class XSuper implements Foo {}\n" + + "class XSub extends XSuper implements Foo {}\n" + + "\n" + + "public class X implements Bar, Foo {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " interface Baz extends Bar, Foo {}\n" + + " ^^^\n" + + "The interface Foo cannot be implemented more than once with different arguments: Foo and Foo\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " interface Baz extends Bar, Foo {}\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " class XSuper implements Foo {}\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " class XSub extends XSuper implements Foo {}\n" + + " ^^^^\n" + + "The interface Foo cannot be implemented more than once with different arguments: Foo and Foo\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " public class X implements Bar, Foo {}\n" + + " ^\n" + + "The interface Foo cannot be implemented more than once with different arguments: Foo and Foo\n" + + "----------\n" + + "6. WARNING in X.java (at line 8)\n" + + " public class X implements Bar, Foo {}\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98561 +public void test0721() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo\n" + + "{\n" + + " protected abstract class InnerFoo\n" + + " {\n" + + " protected abstract void doSomething();\n" + + " }\n" + + " \n" + + " protected void run( InnerFoo innerFoo )\n" + + " {\n" + + " innerFoo.doSomething();\n" + + " }\n" + + "}", + }, + ""); + this.runConformTest( + new String[] { + "Bar.java", + "public class Bar extends Foo\n" + + "{\n" + + " public void go()\n" + + " {\n" + + " InnerFoo inner = new InnerFoo()\n" + + " {\n" + + " protected void doSomething()\n" + + " {\n" + + " System.out.println( \"hello\" );\n" + + " }\n" + + " };\n" + + " run( inner );\n" + + " }\n" + + "}" + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98364 - variation +public void test0722() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I1 {\n" + + "}\n" + + "\n" + + "interface I2 extends I1 {\n" + + "}\n" + + "\n" + + "public class X implements I1, I2 {\n" + + "}\n", + }, + ""); +} +public void test0723() { + this.runConformTest( + new String[] { + "X.java", + "interface IA {}\n" + + "interface IB extends IA {}\n" + + "class A implements IA {}\n" + + "class B implements IB {}\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " A x = new A();\n" + + " B y = new B();\n" + + " print(x);\n" + + " print(y);\n" + + " }\n" + + " public static > void print(T a) {\n" + + " System.out.print(\"A\");\n" + + " }\n" + + " public static > void print(T a) {\n" + + " System.out.println(\"B\");\n" + + " }\n" + + "}\n", + }, + "AB"); +} +public void test0724() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " HashMap subst = new HashMap();\n" + + " subst.put((byte)1, (byte)1);\n" + + " if (1 + subst.get((byte)1) > 0.f) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 +public void test0725() { + this.runNegativeTest( + new String[] { + "X.java", + "class AbsC {\n" + + " public T[] resize(T[] src, T[] dest) {\n" + + " return dest;\n" + + " }\n" + + "}\n" + + "\n" + + "class ConrC extends AbsC {\n" + + " T[][] data;\n" + + " protected void allocateChunkSlots(int maxChunkNo) {\n" + + " data = resize(data, new Object[maxChunkNo][]);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " data = resize(data, new Object[maxChunkNo][]);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object[][] to T[][]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 +public void test0726() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " \n" + + " Controller ctrl = null;\n" + + " foobar(ctrl.getView().getContent()); \n" + + " } \n" + + " \n" + + " static void foobar(X x) {\n" + + " }\n" + + "}\n" + + "interface Controller> {\n" + + " public T getView() ;\n" + + "}\n" + + "interface View {\n" + + " public U getContent();\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 - variation +public void test0727() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " \n" + + " Controller ctrl = null;\n" + + " foobar(ctrl.getView().getContent()); \n" + + " } \n" + + " \n" + + " static void foobar(X x) {\n" + + " }\n" + + "}\n" + + "interface Controller> {\n" + + " public T getView() ;\n" + + "}\n" + + "interface View> {\n" + + " public U getContent();\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98500 - variation +public void test0728() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " \n" + + " Controller ctrl = null;\n" + + " foobar(ctrl.getView().getContent()); \n" + + " } \n" + + " \n" + + " static void foobar(X x) {\n" + + " }\n" + + "}\n" + + "interface Controller> {\n" + + " public T getView() ;\n" + + "}\n" + + "interface View> {\n" + + " public U getContent();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " foobar(ctrl.getView().getContent()); \n" + + " ^^^^^^\n" + + "The method foobar(X) in the type X is not applicable for the arguments (capture#2-of ?)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=96586 +public void test0729() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {}\n" + + "interface I {}\n" + + "class Y extends X implements I {}\n" + }, + ""); + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I {}\n" + + "interface I> {}\n" + + "class Y extends X implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class Y extends X implements I {}\n" + + " ^\n" + + "The interface I cannot be implemented more than once with different arguments: I and I\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " class Y extends X implements I {}\n" + + " ^\n" + + "Bound mismatch: The type X is not a valid substitute for the bounded parameter > of the type I\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=90437 +public void test0730() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " Zork z;\n" + + " public interface SuperInterface {\n" + + " }\n" + + "\n" + + " public interface SubInterface extends SuperInterface {\n" + + " public String getString();\n" + + " }\n" + + "\n" + + " private SuperInterface< ? extends SuperInterface> x = null;\n" + + "\n" + + " public void f() {\n" + + " ((SubInterface) this.x).getString();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " private SuperInterface< ? extends SuperInterface> x = null;\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " ((SubInterface) this.x).getString();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X.SuperInterface to X.SubInterface\n" + + "----------\n" ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97440 +public void test0731() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X parent;\n" + + " X current;\n" + + "\n" + + " X parent2;\n" + + " X current2;\n" + + "\n" + + " void foo() {\n" + + " current = current.parent;\n" + + " }\n" + + "\n" + + " void bar() {\n" + + " current2 = current2.parent2;\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 +public void test0732() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "interface D extends B{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " D d = null;\n" + + " C c = (C)d; // illegal\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " C c = (C)d; // illegal\n" + + " ^^^^\n" + + "Cannot cast from D to C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0733() { + this.runConformTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "interface D extends B{}\n" + + "\n" + + "\n" + + "public class X {\n" + + " Object foo(C c) {\n" + + " return (D) c;\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0734() { + this.runConformTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "interface D extends B{}\n" + + "\n" + + "\n" + + "public class X {\n" + + " Object foo(C c, D d) {\n" + + " return c != null ? c : d; \n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0735() { + this.runConformTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "interface D extends B{}\n" + + "\n" + + "\n" + + "public class X {\n" + + " Object foo(C c, D d) {\n" + + " return c != null ? c : d; \n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0736() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "interface D extends B{}\n" + + "\n" + + "\n" + + "public class X {\n" + + " void bar(C c) {\n" + + " D d = (D) c;\n" + + " foo(d, c);\n" + + " }\n" + + " void foo(U u1, U u2) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " D d = (D) c;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from C to D\n" + + "----------\n"); +} +public void test0737() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "class Sup {\n" + + "}\n" + + "\n" + + "class Sub1 extends Sup {\n" + + "}\n" + + "\n" + + "class Sub2 extends Sup {\n" + + "\n" + + "}\n" + + "abstract class X {\n" + + " abstract S method(A la, B lb);\n" + + "\n" + + " void m2() {\n" + + " Sup Sup = method(new Sub1(), new Sub2());// <-- compiles?? ( A=Sub1, B=Sub2, S=Sup)\n" + + " Object obj = method(1, \"32\");// <--doesn\'t compile?? ( A=Integer, B=String, S=Object)\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0738() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "class C implements B{}\n" + + "interface D extends B{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " D d = null;\n" + + " C c = (C)d; // illegal\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " C c = (C)d; // illegal\n" + + " ^^^^\n" + + "Cannot cast from D to C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0739() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "interface C extends B{}\n" + + "class D implements B{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " D d = null;\n" + + " C c = (C)d; // illegal\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " C c = (C)d; // illegal\n" + + " ^^^^\n" + + "Cannot cast from D to C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0740() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "final class C implements B{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " B d = null;\n" + + " C c = (C)d; // illegal\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " C c = (C)d; // illegal\n" + + " ^^^^\n" + + "Cannot cast from B to C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98331 - variation +public void test0741() { + this.runNegativeTest( + new String[] { + "X.java", + "interface B {}\n" + + "final class D implements B{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " D d = null;\n" + + " B c = (B)d; // illegal\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " B c = (B)d; // illegal\n" + + " ^^^^^^^^^^^^\n" + + "Cannot cast from D to B\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=98538 +// ** +// FAIL ERRMSG +public void test0742() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + " public class X {\n" + + " \n" + + " static abstract class SelfType>{\n" + + " }\n" + + " \n" + + " static class SuperType extends SelfType{\n" + + " }\n" + + " \n" + + " static class SubType extends SuperType{}\n" + + " \n" + + " static > List makeSingletonList(T t){\n" + + " return Collections.singletonList(t);\n" + + " }\n" + + " \n" + + " static ,S extends T> List makeSingletonList2(S s){\n" + + " return Collections.singletonList((T)s); // #0\n" + + " }\n" + + " \n" + + " public static void main(String[] args){\n" + + " makeSingletonList(new SuperType()); // #1 - OK\n" + + " List lsup = makeSingletonList(new SuperType()); // #2 - OK\n" + + " List lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + + " makeSingletonList(new SubType()); // #4 - ERROR\n" + + " makeSingletonList2(new SubType()); // #5 - ERROR\n" + + " lsup = makeSingletonList2(new SubType()); // #6 - OK\n" + + " lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + + " makeSingletonList2(new SuperType()); // #8 - OK\n" + + " lsup = makeSingletonList2(new SuperType()); // #9 - OK\n" + + " }\n" + + "}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " List lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method makeSingletonList(T) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "2. ERROR in X.java (at line 25)\n" + + " makeSingletonList(new SubType()); // #4 - ERROR\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method makeSingletonList(T) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "3. ERROR in X.java (at line 26)\n" + + " makeSingletonList2(new SubType()); // #5 - ERROR\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method makeSingletonList2(S) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "4. ERROR in X.java (at line 28)\n" + + " lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method makeSingletonList2(S) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + + "----------\n" + : // ----- JDK1_8 + -----: #4 & #5 infer as argument type: SuperType. + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " List lsub = makeSingletonList(new SubType()); // #3 - ERROR\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method makeSingletonList(T) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "2. ERROR in X.java (at line 28)\n" + + " lsub = makeSingletonList2(new SubType()); // #7 - ERROR\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method makeSingletonList2(S) of type X is not applicable for the arguments (X.SubType). The inferred type X.SubType is not a valid substitute for the bounded parameter >\n" + + "----------\n")); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99553 +public void test0743() { + this.runNegativeTest( + new String[] { + "X.java", + "interface TestGeneric2 {\n" + + " Nested getNested2(); // super\n" + + "\n" + + " class Nested implements TestGeneric2 {\n" + + " public Nested getNested2() { // sub\n" + + " return this;//2\n" + + " }\n" + + " }\n" + + "}\n" + + " \n" + + "class TestGeneric3 {\n" + + " Nested getNested3() { return null; } // super\n" + + "\n" + + " class Nested extends TestGeneric3 {\n" + + " @Override public Nested getNested3() { // sub\n" + + " return this;//3\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " return this;//3\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from TestGeneric3.Nested to TestGeneric3.Nested\n" + + "----------\n"); +} +public void test0744() { + this.runNegativeTest( + new String[] { + "java/util/X.java", + "package java.util;\n" + + "\n" + + "import java.io.*;\n" + + "\n" + + "class Super {\n" + + " static class Entry {\n" + + " Entry(int i, U u, V v, Entry entry) {}\n" + + " void recordAccess(Super s) {\n" + + " }\n" + + " }\n" + + "}\n"+ + "public abstract class X extends Super {\n" + + "\n" + + " Entry h;\n" + + "\n" + + " private static class Entry extends Super.Entry {\n" + + "\n" + + " Entry() {\n" + + " super(0, null, null, null);\n" + + " }\n" + + "\n" + + " void ab(Entry e) {\n" + + " }\n" + + "\n" + + " @Override void recordAccess(Super m) {\n" + + " X x = (X) m;\n" + + " ab(x.h);\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in java\\util\\X.java (at line 30)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99922 +public void test0745() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void test() {\n" + + " java.util.Arrays.asList(3, 3.1);\n" + + " }\n" + + "}\n" + }, + ""); +} +//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", + "public class X {\n" + + " void test() {\n" + + " String s = java.util.Arrays.asList(3, 3.1);\n" + + " }\n" + + "}\n" + }, + "----------\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<"+intersection("Number","Comparable")+"> to String\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99983 +public void test0747() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface I {}\n" + + " class Y {\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class Y {\n" + + " ^\n" + + "Cannot specify any additional bound X.I when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100007 +public void test0748() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public byte[] create(Class cl) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method create(Class) of type X has the same erasure as create(Class) of type Factory but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public byte[] create(Class cl) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method create(Class) of type X has the same erasure as create(Class) of type Factory but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "interface Factory {\n" + + " U create(Class cl);\n" + + "}\n" + + "abstract class X implements Factory {\n" + + " public byte[] create(Class cl) { return null; }\n" + + "}\n", + }, + expectedCompilerLog + ); +// javac 7 reports the name clash when X subclasses another class or is a concrete type +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100149 +public void test0749() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X> {\n" + + " T get() { return null; }\n" + + " void foo(X x) {\n" + + " String s = x.get();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " String s = x.get();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from X to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100149 - variation +public void test0750() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X> {\n" + + " T get() { return null; }\n" + + " void foo(X x) {\n" + + " List l = x.get();\n" + + " }\n" + + " Zork z ;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " List l = x.get();\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "3. 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=100153 +public void test0751() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {\n" + + " \n" + + " void foo(X x) {\n" + + " X x2 = x;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X x2 = x;\n" + + " ^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n"); +} +public void test0752() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " X> parent;\n" + + " X> current;\n" + + " void foo() {\n" + + " current = current.parent;\n" + + " }\n" + + "}\n" + + "\n" + + "interface I {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " current = current.parent;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X>> to X>\n" + + "----------\n"); +} +public void test0753() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " X> parent;\n" + + " X> current;\n" + + " void foo() {\n" + + " current = current.parent;\n" + + " }\n" + + "}\n" + + "\n" + + "interface I {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X> parent;\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The type ? super I is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X> current;\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The type ? super I is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " current = current.parent;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X>> to X>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99578 +public void test0754() { + this.runNegativeTest( + new String[] { + "X.java", + "class bugSuper {\n" + + " public T getData(){\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class bugElement {\n" + + "}\n" + + "\n" + + "class bugClass extends bugSuper{\n" + + "}\n" + + "\n" + + "public class X{\n" + + " public void method(bugClass bc){\n" + + " bugElement be = bc.getData(); //<< here\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 14)\n" + + " public void method(bugClass bc){\n" + + " ^^^^^^^^\n" + + "bugClass is a raw type. References to generic type bugClass should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " bugElement be = bc.getData(); //<< here\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to bugElement\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99999 +public void test0755() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static class B {}\n" + + " public static void main (String... args) {\n" + + " X.B[] b = new X.B[1];\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X.B[] b = new X.B[1];\n" + + " ^^^^^^\n" + + "The member type X.B cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " X.B[] b = new X.B[1];\n" + + " ^^^^^^\n" + + "The member type X.B cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99999 - variation +public void test0756() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public class B {}\n" + + " public static void main (String... args) {\n" + + " X.B[] b = new X.B[1];\n" + + " }\n" + + "}", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100147 +public void test0757() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class EntryMap {\n" + + " class Entry {\n" + + " }\n" + + " }\n" + + "\n" + + " EntryMap.Entry internalGet(Object key) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " void foo(Object key) {\n" + + " EntryMap.Entry entry = internalGet(key);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " EntryMap.Entry internalGet(Object key) {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.EntryMap.Entry is a raw type. References to generic type X.EntryMap.Entry should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " EntryMap.Entry entry = internalGet(key);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.EntryMap.Entry needs unchecked conversion to conform to X.EntryMap.Entry\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=100147 - variation +public void test0758() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class EntryMap {\n" + + " class Entry {\n" + + " }\n" + + " }\n" + + "\n" + + " EntryMap.Entry internalGet(Object key) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " void foo(Object key) {\n" + + " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " EntryMap.Entry internalGet(Object key) {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.EntryMap.Entry is a raw type. References to generic type X.EntryMap.Entry should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X.EntryMap.Entry to X.EntryMap.Entry\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.EntryMap.Entry needs unchecked conversion to conform to X.EntryMap.Entry\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " EntryMap.Entry entry = (EntryMap.Entry) internalGet(key);\n" + + " ^^^^^^^^^^^^^^\n" + + "X.EntryMap.Entry is a raw type. References to generic type X.EntryMap.Entry should be parameterized\n" + + "----------\n" + + "5. 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=100128 +public void test0759() { + this.runConformTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " E[] m;\n" + + " public X()\n" + + " {\n" + + " X x = null;\n" + + " System.out.println(x.m.length);\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test0760() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static X make() {\n" + + " return null;\n" + + " }\n" + + " public static T itself(T t) {\n" + + " return t;\n" + + " }\n" + + "\n" + + " void foo() {\n" + + " X x1 = make();\n" + + " X x2 = itself(x1);\n" + + " }\n" + + " void bar() {\n" + + " X x2 = itself(make());\n" + + " }\n" + + " void baz() {\n" + + " X x2 = itself((X)make());\n" + + " } \n" + + "} \n", + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " X x2 = itself(make());\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " X x2 = itself((X)make());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " X x2 = itself((X)make());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n" + )); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100421 +public void test0761() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public abstract class ClassA {\n" + + " public abstract B method(A param);\n" + + " }\n" + + "\n" + + " public class ClassB {\n" + + " // the following field declaration causes an error\n" + + " ClassA classA;\n" + + "\n" + + " public D method(D d) {\n" + + " return classA.method(d);\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100421 - variation +public void test0762() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public abstract class ClassA {\n" + + " public abstract B method(A param);\n" + + " }\n" + + "\n" + + " public class ClassB {\n" + + " // the following field declaration causes an error\n" + + " ClassA classA;\n" + + "\n" + + " public D method(D d) {\n" + + " return classA.method(d);\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100519 +public void test0763() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static class InnerClass {\n" + + " public InnerClass() {\n" + + " System.out.println(\"class : \" + InnerClass.this);\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100527 +public void test0764() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + " \n" + + "interface IIfClosure {}\n" + + " \n" + + "public class X {\n" + + " public X(String label, HashMap bindings) {\n" + + " this(label, bindings, (List)Collections.emptyList());\n" + + " }\n" + + " \n" + + " public X(String label, HashMap bindings, Collection coll) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " this(label, bindings, (List)Collections.emptyList());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98379 +public void test0765() { + this.runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static T f1() throws Exception{\n" + + " return null;\n" + + " }\n" + + " static U f2() throws Exception {\n" + + " return f1();\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBug6302954 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99453 +public void test0766() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "interface Cloneable> {\n" + + " public T clone();\n" + + "}\n" + + "\n" + + "interface CloneableMap> extends Map, Cloneable> {\n" + + "}\n" + + "\n" + + "interface C> extends Cloneable {\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " CloneableMap> map = null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " CloneableMap> map = null;\n" + + " ^\n" + + "Bound mismatch: The type C is not a valid substitute for the bounded parameter > of the type CloneableMap\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99453 - variation +public void test0767() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "interface Cloneable> {\n" + + " public T clone();\n" + + "}\n" + + "\n" + + "interface CloneableMap> extends Map, Cloneable> {\n" + + "}\n" + + "\n" + + "interface C extends Cloneable {\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " CloneableMap map = null;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100619 +public void test0768() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T foo1() { return null; }\n" + + " , U extends Z & T> T foo2() { return null; }\n" + + " , U extends T & Z> T foo3() { return null; }\n" + + " , U extends W & Z> T foo4() { return null; }\n" + + "}\n" + + "\n" + + "interface Y {\n" + + "}\n" + + "\n" + + "interface Z extends Y {}\n" + + "interface W extends Y {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T foo1() { return null; }\n" + + " ^\n" + + "The type T is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " , U extends Z & T> T foo2() { return null; }\n" + + " ^\n" + + "The type T is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " , U extends T & Z> T foo3() { return null; }\n" + + " ^\n" + + "Cannot specify any additional bound Z when first bound is a type parameter\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " , U extends T & Z> T foo3() { return null; }\n" + + " ^\n" + + "The interface Y cannot be implemented more than once with different arguments: Y and Y\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " , U extends W & Z> T foo4() { return null; }\n" + + " ^\n" + + "The interface Y cannot be implemented more than once with different arguments: Y and Y\n" + + "----------\n"); +} +public void test0769() { + this.runConformTest( + new String[] { + "X.java", + "class XSuper {\n" + + " T value;\n" + + "}\n" + + "public class X extends XSuper{\n" + + " public void a() {\n" + + " value += 1;\n" + + " value = value + 1;\n" + + " System.out.println(value);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " X x = new X();\n" + + " x.value = \"[\";\n" + + " x.a();\n" + + " }\n" + + "}\n", + }, + "[11"); +} +public void test0770() { + this.runConformTest( + new String[] { + "X.java", + "class XSuper {\n" + + " T value;\n" + + "}\n" + + "public class X extends XSuper{\n" + + " public void a() {\n" + + " this.value += 1;\n" + + " this.value = this.value + 1;\n" + + " System.out.println(this.value);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " X x = new X();\n" + + " x.value = \"[\";\n" + + " x.a();\n" + + " }\n" + + "}\n", + }, + "[11"); +} +public void test0771() { + this.runConformTest( + new String[] { + "X.java", + "class XSuper {\n" + + " T value;\n" + + "}\n" + + "public class X extends XSuper{\n" + + " public static void a(X x) {\n" + + " x.value += 1;\n" + + " x.value = x.value + 1;\n" + + " System.out.println(x.value);\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " X x = new X();\n" + + " x.value = \"[\";\n" + + " a(x);\n" + + " }\n" + + "}\n", + }, + "[11"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101794 +public void test0772() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Foo {\n" + + " public T getIt();\n" + + "}\n" + + "\n" + + "class FooImpl implements Foo {\n" + + " public String getIt() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public void doIt() {\n" + + " Object s = new FooImpl().getIt();\n" + + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void doIt() {\n" + + " Object s = new FooImpl().getIt();\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null); + String expectedOutput = + " // Method descriptor #18 ()Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 1\n" + + " public bridge synthetic java.lang.Object getIt();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual FooImpl.getIt() : java.lang.String [19]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "FooImpl.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101794 - variation +public void test0773() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Foo {\n" + + " public T getIt() throws T;\n" + + "}\n" + + "\n" + + "class FooImpl implements Foo {\n" + + " public NullPointerException getIt() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public void doIt() {\n" + + " Object s = new FooImpl().getIt();\n" + + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void doIt() {\n" + + " Object s = new FooImpl().getIt();\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null); + String expectedOutput = + " // Method descriptor #18 ()Ljava/lang/Exception;\n" + + " // Stack: 1, Locals: 1\n" + + " public bridge synthetic java.lang.Exception getIt() throws java.lang.Exception;\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual FooImpl.getIt() : java.lang.NullPointerException [22]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "FooImpl.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98532 +public void test0774() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class StaticInnerNoParam {\n" + + " T x;\n" + + " }\n" + + " class NonStaticInnerParam {} \n" + + " static class StaticInnerParam { }\n" + + " void foo(T t) {}\n" + + " static void bar(T t) {}\n" + + " X(T t) {}\n" + + " \n" + + " class U {}\n" + + " void foo2(U t) {}\n" + + " static void bar2(U t) {}\n" + + " class NonStaticInnerParam2 {} \n" + + " static class StaticInnerParam2 {} \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " T x;\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " class NonStaticInnerParam {} \n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " void foo(T t) {}\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " X(T t) {}\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " void foo2(U t) {}\n" + + " ^\n" + + "The type parameter U is hiding the type X.U\n" + + "----------\n" + + "6. WARNING in X.java (at line 13)\n" + + " static void bar2(U t) {}\n" + + " ^\n" + + "The type parameter U is hiding the type X.U\n" + + "----------\n" + + "7. WARNING in X.java (at line 14)\n" + + " class NonStaticInnerParam2 {} \n" + + " ^\n" + + "The type parameter U is hiding the type X.U\n" + + "----------\n" + + "8. WARNING in X.java (at line 15)\n" + + " static class StaticInnerParam2 {} \n" + + " ^\n" + + "The type parameter U is hiding the type X.U\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100153 +public void test0775() { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + " void foo1(X x) {}\n" + + " void foo2(X x) {}\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103023 +public void test0776() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X> {\n" + + "\n" + + " abstract class Foo implements I> {}\n" + + "\n" + + " abstract class Bar implements I> {}\n" + + "\n" + + " public void bar(List> f, List> b) {\n" + + " foo(f, b);\n" + + " }\n" + + "\n" + + " void foo(List f, List b) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().bar(null, null);\n" + + " }\n" + + "}\n" + + "interface I {}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103472 +public void test0777() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public interface B {\n" + + " public T a();\n" + + " }\n" + + "\n" + + " public interface C extends B {\n" + + " }\n" + + "\n" + + " public class D implements B {\n" + + " public Integer a() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " // Illegal\n" + + " public class E implements B, C {\n" + + " public Integer a() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " // why is this allowed?\n" + + " public class F extends D implements C {\n" + + " public Integer a() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " public interface G {\n" + + " public void a(T pArg);\n" + + " }\n" + + "\n" + + " public interface H extends G {\n" + + " public Object b();\n" + + " }\n" + + "\n" + + " public class I implements G {\n" + + " public void a(Integer pInt) {\n" + + " }\n" + + " }\n" + + "\n" + + " // Illegal. Huh?\n" + + " public class J extends I implements G {\n" + + " public Integer a() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public interface C extends B {\n" + + " ^\n" + + "X.B is a raw type. References to generic type X.B should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " public class E implements B, C {\n" + + " ^\n" + + "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " public class F extends D implements C {\n" + + " ^\n" + + "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + + "----------\n" + + "4. WARNING in X.java (at line 24)\n" + + " public Integer a() {\n" + + " ^^^\n" + + "The method a() of type X.F should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "5. WARNING in X.java (at line 33)\n" + + " public interface H extends G {\n" + + " ^\n" + + "X.G is a raw type. References to generic type X.G should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 43)\n" + + " public class J extends I implements G {\n" + + " ^\n" + + "The interface G cannot be implemented more than once with different arguments: X.G and X.G\n" + + "----------\n" + + "7. WARNING in X.java (at line 43)\n" + + " public class J extends I implements G {\n" + + " ^\n" + + "X.G is a raw type. References to generic type X.G should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103472 - variation +public void test0778() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface B {}\n" + + "\n" + + " interface C extends B {}\n" + + "\n" + + " class D implements B {}\n" + + "\n" + + " class F extends D implements C {}\n" + + " \n" + + " class V {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " interface C extends B {}\n" + + " ^\n" + + "X.B is a raw type. References to generic type X.B should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " class F extends D implements C {}\n" + + " ^\n" + + "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " class V {}\n" + + " ^\n" + + "The interface B cannot be implemented more than once with different arguments: X.B and X.B\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103227 +public void test0779() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.AbstractList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " private static class Entry {\n" + + " public void doIt(final List args) {\n" + + " List list = new AbstractList() {\n" + + " @Override public int size() { return 0; }\n" + + " @Override public String get(int i) { return args.get(i); }\n" + + " };\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Entry().doIt(null);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #31 (I)Ljava/lang/Object;\n" + + " // Stack: 2, Locals: 2\n" + + " public bridge synthetic java.lang.Object get(int arg0);\n" + + " 0 aload_0 [this]\n" + + " 1 iload_1 [arg0]\n" + + " 2 invokevirtual X$Entry$1.get(int) : java.lang.String [36]\n" + + " 5 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n"; + + // check no unnecessary checkcast on bridge method for X$1 + File f = new File(OUTPUT_DIR + File.separator + "X$Entry$1.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103227 - variation +public void test0780() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " long foo(List list) {\n" + + " return list.get(0);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList();\n" + + " list.add(123L);\n" + + " System.out.println(new X().foo(list));\n" + + " }\n" + + "}\n", + }, + "123"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104109 +public void test0781() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static > Foo doIt(T t) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " interface Foo {\n" + + " boolean ok(E e);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public static > Foo doIt(T t) {\n" + + " ^^^^^^^^^^\n" + + "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104082 +public void test0782() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.*;\n" + + "import java.util.*;\n" + + "\n" + + "interface StoredObject {\n" + + " String getUid();\n" + + " String getName();\n" + + " String getDescription();\n" + + "}\n" + + "\n" + + "interface GraphDiagramNode // extends Comparable\n" + + "{\n" + + "}\n" + + "\n" + + "public class X implements GraphDiagramNode {\n" + + " private final JccsGraphDiagramModel model;\n" + + " private final X parent;\n" + + " private final ObjectType object;\n" + + "\n" + + " public class JccsGraphDiagramModel {\n" + + " }\n" + + "\n" + + " public interface GraphDiagramModel {\n" + + " }\n" + + "\n" + + " public class Dependency {\n" + + "\n" + + " }\n" + + "\n" + + " public X(JccsGraphDiagramModel argModel, X argParent, ObjectType argObject) {\n" + + " model = argModel;\n" + + " parent = argParent;\n" + + " object = argObject;\n" + + " }\n" + + "\n" + + " protected Collection> createChildren(\n" + + " Iterator argData, Class> argChildNodeClass,\n" + + " Class argInterface) {\n" + + " Collection> output = new LinkedList>();\n" + + "\n" + + " try {\n" + + " while (argData.hasNext()) {\n" + + " ChildType next = argData.next();\n" + + " Constructor> constructor = argChildNodeClass.getConstructor(\n" + + " JccsGraphDiagramModel.class, getClass(), argInterface);\n" + + "\n" + + " output.add(constructor.newInstance(model, this, next));\n" + + " }\n" + + " } catch (Exception x) {\n" + + " x.printStackTrace();\n" + + " }\n" + + "\n" + + " return output;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104167 +public void test0783() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static class B{\n" + + " private int foo; //incorrectly identified as unused\n" + + " }\n" + + " void bar(B b){\n" + + " if (b.foo == 0)\n" + + " return;\n" + + " }\n" + + " Zork z;\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=104082 - variation +public void test0784() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X parent;\n" + + "\n" + + " public X(X parent) {\n" + + " this.parent = parent;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103528 +public void test0785() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " > T getLonger(T t1, T t2) {\n" + + " return t1.size() > t2.size() ? t1 : t2;\n" + + " }\n" + + " \n" + + " void m(HashSet list, ArrayList set) {\n" + + " getLonger(list, set);\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " getLonger(list, set);\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The generic method getLonger(T, T) of type X is not applicable for the arguments (HashSet, ArrayList). The inferred type AbstractCollection&Cloneable&Serializable is not a valid substitute for the bounded parameter >\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " getLonger(list, set);\n" + + " ^^^^^^^^^\n" + + "The method getLonger(T, T) in the type X is not applicable for the arguments (HashSet, ArrayList)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103528 - variation +public void test0786() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " > T getLonger(T t1, T t2) {\n" + + " return t1.size() > t2.size() ? t1 : t2;\n" + + " }\n" + + " \n" + + " void m(HashSet list, ArrayList set) {\n" + + " getLonger(list, set);\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103528 - variation +public void test0787() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " > T getLonger(T t1, T t2) {\n" + + " return t1.size() > t2.size() ? t1 : t2;\n" + + " }\n" + + " \n" + + " void m(HashSet list, ArrayList set) {\n" + + " getLonger(list, set);\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " getLonger(list, set);\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The generic method getLonger(T, T) of type X is not applicable for the arguments (HashSet, ArrayList). The inferred type AbstractCollection&Cloneable&Serializable is not a valid substitute for the bounded parameter >\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " getLonger(list, set);\n" + + " ^^^^^^^^^\n" + + "The method getLonger(T, T) in the type X is not applicable for the arguments (HashSet, ArrayList)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103994 +public void test0788() { + this.runConformTest( + new String[] { + "test/A.java", + "package test;\n" + + "\n" + + "public class A\n" + + "{\n" + + " class B\n" + + " extends A\n" + + " {\n" + + " }\n" + + "}\n", + "java/nio/channels/spi/AbstractSelectableChannel.java", + "package java.nio.channels.spi;\n" + + "\n" + + "public abstract class AbstractSelectableChannel\n" + + " extends java.nio.channels.SelectableChannel\n" + + "{\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103994 - variation (change ordering of files should have no effect) +public void test0789() { + this.runConformTest( + new String[] { + "java/nio/channels/spi/AbstractSelectableChannel.java", + "package java.nio.channels.spi;\n" + + "\n" + + "public abstract class AbstractSelectableChannel\n" + + " extends java.nio.channels.SelectableChannel\n" + + "{\n" + + "}\n", + "test/A.java", + "package test;\n" + + "\n" + + "public class A\n" + + "{\n" + + " class B\n" + + " extends A\n" + + " {\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=103485 +public void test0790() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " > boolean isGreater(T t1, T t2) {\n" + + " return t1.compareTo(t2) > 0 ? true : false; \n" + + " }\n" + + "\n" + + " void method1(Integer i, Double d) {\n" + + " if (isGreater(i, d)) \n" + + " System.out.println(\"GREATER\");\n" + + " else\n" + + " System.out.println(\"LOWER\");\n" + + " }\n" + + " void method2(Integer i, Double d) {\n" + + " Comparable c1= i;\n" + + " Comparable c2= d;\n" + + " isGreater(c1, c2);\n" + + " } \n" + + " void method3(Integer i, Double d) {\n" + + " Comparable c1= i;\n" + + " Comparable c2= d;\n" + + " isGreater(c1, c2);\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " Integer i = 1;\n" + + " Double d = 2.0;\n" + + " new X().method1(i, d);\n" + + " new X().method2(i, d);\n" + + " new X().method3(i, d);\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (isGreater(i, d)) \n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The generic method isGreater(T, T) of type X is not applicable for the arguments (Integer, Double). The inferred type "+ intersection("Number", "Comparable") +" is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " isGreater(c1, c2);\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The generic method isGreater(T, T) of type X is not applicable for the arguments (Comparable, Comparable). The inferred type Comparable is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "3. WARNING in X.java (at line 18)\n" + + " Comparable c1= i;\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 19)\n" + + " Comparable c2= d;\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 20)\n" + + " isGreater(c1, c2);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation isGreater(Comparable, Comparable) of the generic method isGreater(T, T) of type X\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (isGreater(i, d)) \n" + + " ^^^^^^^^^\n" + + "The method isGreater(T, T) in the type X is not applicable for the arguments (Integer, Double)\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " isGreater(c1, c2);\n" + + " ^^^^^^^^^\n" + + "The method isGreater(T, T) in the type X is not applicable for the arguments (Comparable, Comparable)\n" + + "----------\n" + + "3. WARNING in X.java (at line 18)\n" + + " Comparable c1= i;\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 19)\n" + + " Comparable c2= d;\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 20)\n" + + " isGreater(c1, c2);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation isGreater(Comparable, Comparable) of the generic method isGreater(T, T) of type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104655 +public void test0791() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " Sup method1(boolean b, E1 e1, E2 e2) {\n" + + " if (b)\n" + + " return e1;\n" + + " else\n" + + " return e2;\n" + + " }\n" + + "\n" + + " Sup method2(boolean b, E1 e1, E2 e2) {\n" + + " return b ? e1 : e2;\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104649 +public void test0792() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void shouldcompile() {\n" + + " java.util.Collections.max(null);\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105635 +public void test0793() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public java.util.List i,j[],k;\n" + + " void m() {\n" + + " i[0] = null;\n" + + " j[0] = null;\n" + + " k[0] = null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " i[0] = null;\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " k[0] = null;\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105635 +public void test0794() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class X { \n" + + " public List i,j[],k;\n" + + " void m() {\n" + + " i[0] = null;\n" + + " j[0] = null;\n" + + " k[0] = null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " i[0] = null;\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " k[0] = null;\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106297 +public void test0795() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " class B {\n" + + " B() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " static { \n" + + " new X().new B() {};\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106297 - variation +public void test0796() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " class B {\n" + + " B(T t) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " static { \n" + + " new X().new B(12) {};\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new X().new B(12) {};\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X.B(int) is undefined\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106297 - variation +public void test0797() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " class B {\n" + + " B() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " static { \n" + + " new X().new B();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106284 +public void test0798() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.math.BigDecimal;\n" + + "\n" + + "public class X\n" + + "{\n" + + " private static > T max(T... elems)\n" + + " {\n" + + " T max=null;\n" + + " for (T elem : elems)\n" + + " if (max == null || max.compareTo(elem) < 0)\n" + + " max=elem;\n" + + " return max;\n" + + " }\n" + + "\n" + + " public static void main(String[] args)\n" + + " {\n" + + " System.out.println(max(1, 2.0, new BigDecimal(Math.PI)));\n" + + " }\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 >\n" + + "----------\n" : + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " private static > 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 >\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " private static > 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" + + "The method max(T...) in the type X is not applicable for the arguments (int, double, BigDecimal)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105531 +public void test0799() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Y first;\n" + + " Y first2;\n" + + "\n" + + " U foo(U u1, U u2) {\n" + + " return u1;\n" + + " }\n" + + " void bar2(Y ref) {\n" + + " String s = foo(ref, first);\n" + + " }\n" + + " \n" + + " void foo(Y ref) {\n" + + " ref.next = first == null ? ref : first;\n" + + " String s = first == null ? ref : first;\n" + + " ref.next = first2 == null ? ref : first2;\n" + + " }\n" + + " Y bar(Y ref) {\n" + + " return first == null ? ref : first;\n" + + " }\n" + + "}\n" + + "\n" + + "class Y {\n" + + " Y next;\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " Y first;\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Y first2;\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " String s = foo(ref, first);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to String\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " ref.next = first == null ? ref : first;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " String s = first == null ? ref : first;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to String\n" + + "----------\n" + + "6. WARNING in X.java (at line 15)\n" + + " ref.next = first2 == null ? ref : first2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n" + + "7. WARNING in X.java (at line 18)\n" + + " return first == null ? ref : first;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " Y first;\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Y first2;\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " String s = foo(ref, first);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to String\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " ref.next = first == null ? ref : first;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from Y to Y\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " ref.next = first == null ? ref : first;\n" + + " ^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " String s = first == null ? ref : first;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from Y to String\n" + + "----------\n" + + "7. ERROR in X.java (at line 14)\n" + + " String s = first == null ? ref : first;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from Y to String\n" + + "----------\n" + + "8. ERROR in X.java (at line 15)\n" + + " ref.next = first2 == null ? ref : first2;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from Y to Y\n" + + "----------\n" + + "9. WARNING in X.java (at line 15)\n" + + " ref.next = first2 == null ? ref : first2;\n" + + " ^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n" + + "10. WARNING in X.java (at line 18)\n" + + " return first == null ? ref : first;\n" + + " ^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 +public void test0800() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.lang.reflect.Constructor;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final Class AnnClass = Ann.class;\n" + + " Constructor[] constrs = X.class.getConstructors();\n" + + " for (Constructor constructor : constrs) {\n" + + " final String message = constructor.getAnnotation(AnnClass).message();\n" + + " System.out.println(message);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "@interface Ann {\n" + + " String message();\n" + + "}\n", + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 6)\n" + + " Constructor[] constrs = X.class.getConstructors();\n" + + " ^^^^^^^^^^^\n" + + "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " for (Constructor constructor : constrs) {\n" + + " ^^^^^^^^^^^\n" + + "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " final String message = constructor.getAnnotation(AnnClass).message();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " final String message = constructor.getAnnotation(AnnClass).message();\n" + + " ^^^^^^^\n" + + "The method message() is undefined for the type Annotation\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug6400189 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation +public void test0801() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " X.class.getConstructor(new Class[0]).getAnnotation(Ann.class).message();\n" + + " } catch(Exception e) {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "@interface Ann {\n" + + " String message();\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation +public void test0802() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar(Y y, X x) {\n" + + " y.foo(x).zz();\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " T foo(X x) { return null; }\n" + + "}\n" + + "\n" + + "class Z {\n" + + "}\n" + + "class ZZ extends Z {\n" + + " void zz() {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void bar(Y y, X x) {\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " y.foo(x).zz();\n" + + " ^^^^^^^^\n" + + "Type safety: The method foo(X) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " y.foo(x).zz();\n" + + " ^^\n" + + "The method zz() is undefined for the type Z\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=101831 +public void test0803() { + this.runNegativeTest( + false /* skipJavac */, + this.complianceLevel < ClassFileConstants.JDK1_8 ? null : JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " ArrayList list = new ArrayList();\n" + + " ArrayList superList = new ArrayList();\n" + + " ArrayList extendsList = new ArrayList();\n" + + "\n" + + " ArrayList getList() {\n" + + " return true ? list : list;\n" + + " }\n" + + "\n" + + " ArrayList getSuperList() {\n" + + " return true ? superList : superList;\n" + + " }\n" + + "\n" + + " ArrayList getExtendsList() {\n" + + " return true ? extendsList : extendsList;\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " return true ? list : list;\n" + + " ^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " return true ? superList : superList;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from ArrayList to ArrayList\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " return true ? extendsList : extendsList;\n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " return true ? list : list;\n" + + " ^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " return true ? superList : superList;\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " return true ? extendsList : extendsList;\n" + + " ^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106865 +public void test0804() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " void foo(E e) {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " void method1(Y y, Object[] os) {\n" + + " y.foo(os);\n" + + " }\n" + + " void method2(Y y, Cloneable c) {\n" + + " y.foo(c);\n" + + " } \n" + + " void method3(Y y, Object[] os) {\n" + + " y.foo(os);\n" + + " }\n" + + " void method4(Y y, Cloneable c) {\n" + + " y.foo(c);\n" + + " } \n" + + " \n" + + " void bar(Y y) {\n" + + " method2(y, null);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " y.foo(os);\n" + + " ^^^\n" + + "The method foo(capture#3-of ? extends Object[]) in the type Y is not applicable for the arguments (Object[])\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " y.foo(c);\n" + + " ^^^\n" + + "The method foo(capture#4-of ? extends Cloneable) in the type Y is not applicable for the arguments (Cloneable)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106936 +public void test0805() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static T foo(T t1, T t2) { return t1; }\n" + + " public static void main(String[] args) {\n" + + " Number[] numbers = {}, numbers2, numbers3;\n" + + " Float[] floats = {};\n" + + " Integer[] integers = {};\n" + + "\n" + + " numbers2 = foo(numbers, floats);\n" + + " numbers3 = numbers != null ? numbers : floats;\n" + + " String s = foo(numbers, floats); \n" + + "\n" + + " numbers2 = foo(integers, floats);\n" + + " numbers3 = integers != null ? integers : floats;\n" + + " String s2 = foo(integers, floats);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = foo(numbers, floats); \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Number[] to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " String s2 = foo(integers, floats);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from "+intersection("Number", + intersection("Comparable")+">") + )+"[] to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107079 +public void test0806() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "/**\n" + + " * This class demonstrates a generic program that Eclipse must not compile as it\n" + + " * can lead to a ClassCastException despite having no explicit type casts.\n" + + " */\n" + + "public class X {\n" + + " private static class ValueHolder {\n" + + " public T value;\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " List> multiList = new ArrayList>();\n" + + "\n" + + " ValueHolder intHolder = new ValueHolder();\n" + + " intHolder.value = 1;\n" + + "\n" + + " ValueHolder doubleHolder = new ValueHolder();\n" + + " doubleHolder.value = 1.5;\n" + + "\n" + + " multiList.add(intHolder);\n" + + " multiList.add(doubleHolder);\n" + + "\n" + + " // I believe this line is being erroneously treated as a capture\n" + + " // conversion under 3.1 JDT.\n" + + " // I believe the problem is that ? cannot be captured except in a first\n" + + " // level wildcard.\n" + + " swapFirstTwoValues(multiList);\n" + + "\n" + + " // this line causes a ClassCastException when checked.\n" + + " Integer value = intHolder.value;\n" + + " System.out.println(value);\n" + + " }\n" + + "\n" + + " private static void swapFirstTwoValues(List> multiList) {\n" + + " ValueHolder intHolder = multiList.get(0);\n" + + " ValueHolder doubleHolder = multiList.get(1);\n" + + "\n" + + " intHolder.value = doubleHolder.value;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 29)\n" + + " swapFirstTwoValues(multiList);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The method swapFirstTwoValues(List>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107756 +public void test0807() { + this.runConformTest( + new String[] { + "X.java", + "interface Prop {\n" + + " Unmarshaller.Handler createHandler();\n" + + "}\n" + + "\n" + + "abstract class Unmarshaller {\n" + + " public static abstract class Handler {}\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void foo(Prop p) {\n" + + " Unmarshaller.Handler h = p.createHandler(); \n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107756 - variation +public void test0808() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.ax = new AX();\n" + + " }\n" + + " \n" + + " AX ax;\n" + + "}\n" + + "\n" + + "class AX

{\n" + + " AX

p;\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106946 +public void test0809() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "\n" + + "class Node {}\n" + + "interface Set1 extends Iterable {}\n" + + "interface Set2 extends Iterable {}\n" + + "\n" + + "class SetIterator implements Iterator {\n" + + " public N next() {\n" + + " return null;\n" + + " }\n" + + " public boolean hasNext() {\n" + + " return true;\n" + + " }\n" + + " public void remove() {\n" + + " }\n" + + "}\n" + + "interface Set3 extends Iterable {\n" + + " SetIterator iterator();\n" + + "}\n" + + "public class X {\n" + + " void f1(Set1 s) {\n" + + " Node n_ = s.iterator().next();\n" + + " // ^Type mismatch: cannot convert from Object to Node\n" + + " // this was unexpected (s can only contain types derivered from Node)\n" + + " for (Node n : s) {\n" + + " // ^Type mismatch: cannot convert from Object to Node\n" + + " // this was unexpected\n" + + " }\n" + + " }\n" + + " void f2(Set2 s) {\n" + + " Node n_ = s.iterator().next();\n" + + " for (Node n : s) {\n" + + " }\n" + + " }\n" + + " void f3(Set3 s) {\n" + + " Node n_ = s.iterator().next();\n" + + " // (^ no error here)\n" + + " for (Node n : s) {\n" + + " // ^Type mismatch: cannot convert from Object to Node\n" + + " // this is even stranger as we already know that s.iterator().next()\n" + + " // have the right type\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 21)\n" + + " void f1(Set1 s) {\n" + + " ^^^^\n" + + "Set1 is a raw type. References to generic type Set1 should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " Node n_ = s.iterator().next();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Node\n" + + "----------\n" + + "3. ERROR in X.java (at line 25)\n" + + " for (Node n : s) {\n" + + " ^\n" + + "Type mismatch: cannot convert from element type Object to Node\n" + + "----------\n" + + "4. WARNING in X.java (at line 35)\n" + + " void f3(Set3 s) {\n" + + " ^^^^\n" + + "Set3 is a raw type. References to generic type Set3 should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 38)\n" + + " for (Node n : s) {\n" + + " ^\n" + + "Type mismatch: cannot convert from element type Object to Node\n" + + "----------\n"); +} +public void test0810() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class A {\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public A foo(K type) {\n" + + " return new A();\n" + + " }\n" + + "\n" + + " public static void main(String args[]) {\n" + + " X x = new X();\n" + + " A a = x.foo(null);\n" + + " System.out.println(a);\n" + + " }\n" + + "}", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108372 +public void test0811() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private T t;\n" + + " private X.Inner inner;\n" + + " private X.Inner[] inners;\n" + + " public X(T t, X.Inner in, X.Inner[] ins) {\n" + + " this.t = t;\n" + + " this.inner = in;\n" + + " this.inner = new X(null, null, null).new Inner();\n" + + " this.inners = ins;\n" + + " this.inners = new X.Inner[10];\n" + + " //Type mismatch: cannot convert from X.Inner[] to X.Inner[]\n" + + " }\n" + + " private class Inner {\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108372 - variation +public void test0812() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private T t;\n" + + " private X.Inner inner;\n" + + " private X.Inner[] inners;\n" + + " public X(T t) {\n" + + " this.t = t;\n" + + " this.inner = new X.Inner();\n" + + " this.inners = new X.Inner[10];\n" + + " Zork z;\n" + + " }\n" + + " private class Inner {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " this.inner = new X.Inner();\n" + + " ^^^^^^^\n" + + "X.Inner is a raw type. References to generic type X.Inner should be parameterized\n" + + "----------\n" + + "2. 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=108372 - variation +public void test0813() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " private T t;\n" + + " private X.Inner[] inners;\n" + + " public X(T t) {\n" + + " this.t = t;\n" + + " this.inners = new X.Inner[10];\n" + + " }\n" + + " private class Inner {\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 +public void test0814() { + if (this.complianceLevel >= ClassFileConstants.JDK16) + return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void method(Object o) {\n" + + " if (o instanceof E[]) { //incorrect: cannot test non-reifiable type\n" + + " E[] es = (E[]) o;\n" + + " }\n" + + " if (o instanceof List[]) { //incorrect too\n" + + " List[] es = (List[]) o; \n" + + " }\n" + + " if (o instanceof List[]) { // unbound is ok\n" + + " List[] es = (List[]) o;\n" + + " }\n" + + " }\n" + + " void method(ArrayList[] al) {\n" + + " if (al instanceof List[]) { //incorrect too\n" + + " List[] es = (List[]) al; \n" + + " } \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o instanceof E[]) { //incorrect: cannot test non-reifiable type\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against type parameter E[]. Use its erasure Object[] instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " E[] es = (E[]) o;\n" + + " ^^^^^^^\n" + + "Type safety: Unchecked cast from Object to E[]\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " if (o instanceof List[]) { //incorrect too\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use the form List[] instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " List[] es = (List[]) o; \n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List[]\n" + + "----------\n" + + "5. ERROR in X.java (at line 15)\n" + + " if (al instanceof List[]) { //incorrect too\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use the form List[] instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "6. WARNING in X.java (at line 16)\n" + + " List[] es = (List[]) al; \n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList[] to List[]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation +public void test0815() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object[][] e) {\n" + + " E[] o = (E[]) e;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " E[] o = (E[]) e;\n" + + " ^^^^^^^\n" + + "Type safety: Unchecked cast from Object[][] to E[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation +public void test0816() { + String expectedLog = this.complianceLevel >= ClassFileConstants.JDK16 ? + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o instanceof List[][]) { //incorrect too\n" + + " ^\n" + + "Type Object[] cannot be safely cast to List[][]\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " List[][] es = (List[][]) o; \n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to List[][]\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o instanceof List[][]) { //incorrect too\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[][]. Use the form List[][] instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " List[][] es = (List[][]) o; \n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to List[][]\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void method(Object[] o) {\n" + + " if (o instanceof List[][]) { //incorrect too\n" + + " List[][] es = (List[][]) o; \n" + + " }\n" + + " }\n" + + "}\n", + }, + expectedLog + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=104695 - variation +public void test0817() { + String log = this.complianceLevel >= ClassFileConstants.JDK16 ? + " ^\n" + + "Type List cannot be safely cast to List\n" + + "----------\n" + + "6. WARNING in X.java (at line 18)\n" + + " void foo(List[] ls) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 19)\n" + + " if (ls instanceof List[]) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type List[] is already an instance of type List\n" + + "----------\n" + + "8. ERROR in X.java (at line 20)\n" + + " if (ls instanceof List[]) {}\n" + + " ^^\n" + + "Type List[] cannot be safely cast to List[]\n" + : + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List. Use the form List instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "6. WARNING in X.java (at line 18)\n" + + " void foo(List[] ls) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 19)\n" + + " if (ls instanceof List[]) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type List[] is already an instance of type List\n" + + "----------\n" + + "8. ERROR in X.java (at line 20)\n" + + " if (ls instanceof List[]) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use the form List[] instead since further generic type information will be erased at runtime\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " private T t;\n" + + " private X.Inner inner;\n" + + " private X.Inner[] inners;\n" + + " public X(T t) {\n" + + " this.t = t;\n" + + " if (this.inner instanceof X.Inner) {}\n" + + " if (this.inners instanceof X.Inner[]) {}\n" + + " }\n" + + " private class Inner {\n" + + " }\n" + + " void foo(List l) {\n" + + " if (l instanceof List) {}\n" + + " if (l instanceof List) {}\n" + + " }\n" + + " void foo(List[] ls) {\n" + + " if (ls instanceof List[]) {}\n" + + " if (ls instanceof List[]) {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " if (this.inner instanceof X.Inner) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type X.Inner is already an instance of type X.Inner\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " if (this.inners instanceof X.Inner[]) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type X.Inner[] is already an instance of type X.Inner[]\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " void foo(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " if (l instanceof List) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The expression of type List is already an instance of type List\n" + + "----------\n" + + "5. ERROR in X.java (at line 16)\n" + + " if (l instanceof List) {}\n" + + log + + "----------\n"); +} +public void test0818() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b = this instanceof Y;\n" + + " static class Y extends X {\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101380 +public void test0819() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements MyInterface {\n" + + " public void myMethod(myEnum value) {\n" + + " System.out.println(\"value is \"+value);\n" + + " }\n" + + " public static void main(String[] args){\n" + + " new X().myMethod(myEnum.one); \n" + + " }\n" + + "}\n" + + "\n" + + "interface MyInterface {\n" + + " enum myEnum {one,two};\n" + + " public void myMethod(myEnum value); \n" + + "}\n", + }, + "value is one"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101380 - variation +public void test0820() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {\n" + + " public void x(M value) {}\n" + + "}\n" + + "interface I {\n" + + " class M {}\n" + + " void x(M value); \n" + + "}\n", + }, + ""); +} +public void test0821() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " void foo() {\n" + + " t.run();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new A()).foo();\n" + + " }\n" + + "}\n" + + "class A implements Serializable, Runnable {\n" + + " public void run() {\n" + + " System.out.println(\"AA\");\n" + + " }\n" + + "}\n", + }, + "AA"); + // ensure proper declaring class for #run() invocation + String expectedOutput = + " // Method descriptor #15 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield X.t : java.io.Serializable [16]\n" + + " 4 checkcast java.lang.Runnable [25]\n" + + " 7 invokeinterface java.lang.Runnable.run() : void [27] [nargs: 1]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 12, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 13] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test0822() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " void foo(T t) {\n" + + " t.run();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new A());\n" + + " }\n" + + "}\n" + + "class A implements Serializable, Runnable {\n" + + " public void run() {\n" + + " System.out.println(\"AA\");\n" + + " }\n" + + "}\n", + }, + "AA"); + // ensure proper declaring class for #run() invocation + String expectedOutput = + " // Method descriptor #17 (Ljava/io/Serializable;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(java.io.Serializable t);\n" + + " 0 aload_1 [t]\n" + + " 1 checkcast java.lang.Runnable [20]\n" + + " 4 invokeinterface java.lang.Runnable.run() : void [22] [nargs: 1]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 9, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " [pc: 0, pc: 10] local: t index: 1 type: java.io.Serializable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " [pc: 0, pc: 10] local: t index: 1 type: T\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test0823() throws Exception { + runConformTest( + true, + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " T t;\n" + + " X(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " void foo() {\n" + + " (this == null ? t : t).run();\n" + + " ((V) t).run();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(new A()).foo();\n" + + " }\n" + + "}\n" + + "class A implements Serializable, Runnable {\n" + + " public void run() {\n" + + " System.out.print(\"AA\");\n" + + " }\n" + + "}\n", + }, + null, + "AAAA", + null, + JavacTestOptions.JavacHasABug.JavacBug6531075); + // ensure proper declaring class for #run() invocation + String expectedOutput = + " // Method descriptor #15 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 ifnonnull 11\n" + + " 4 aload_0 [this]\n" + + " 5 getfield X.t : java.io.Serializable [16]\n" + + " 8 goto 15\n" + + " 11 aload_0 [this]\n" + + " 12 getfield X.t : java.io.Serializable [16]\n" + + " 15 checkcast java.lang.Runnable [25]\n" + + " 18 invokeinterface java.lang.Runnable.run() : void [27] [nargs: 1]\n" + + " 23 aload_0 [this]\n" + + " 24 getfield X.t : java.io.Serializable [16]\n" + + " 27 checkcast java.lang.Runnable [25]\n" + + " 30 invokeinterface java.lang.Runnable.run() : void [27] [nargs: 1]\n" + + " 35 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 23, line: 10]\n" + + " [pc: 35, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 36] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 36] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test0824() throws Exception { + runConformTest( + true, + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " void foo(T t) {\n" + + " (this == null ? t : t).run();\n" + + " ((V) t).run();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new A());\n" + + " }\n" + + "}\n" + + "class A implements Serializable, Runnable {\n" + + " public void run() {\n" + + " System.out.print(\"AA\");\n" + + " }\n" + + "}\n", + }, + null, + "AAAA", + null, + JavacTestOptions.JavacHasABug.JavacBug6531075); + // ensure proper declaring class for #run() invocation + String expectedOutput = + " // Method descriptor #17 (Ljava/io/Serializable;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(java.io.Serializable t);\n" + + " 0 aload_0 [this]\n" + + " 1 ifnonnull 8\n" + + " 4 aload_1 [t]\n" + + " 5 goto 9\n" + + " 8 aload_1 [t]\n" + + " 9 checkcast java.lang.Runnable [20]\n" + + " 12 invokeinterface java.lang.Runnable.run() : void [22] [nargs: 1]\n" + + " 17 aload_1 [t]\n" + + " 18 checkcast java.lang.Runnable [20]\n" + + " 21 invokeinterface java.lang.Runnable.run() : void [22] [nargs: 1]\n" + + " 26 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 17, line: 6]\n" + + " [pc: 26, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 27] local: this index: 0 type: X\n" + + " [pc: 0, pc: 27] local: t index: 1 type: java.io.Serializable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 27] local: this index: 0 type: X\n" + + " [pc: 0, pc: 27] local: t index: 1 type: T\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test0825() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " void foo(T t) {\n" + + " Runnable r1 = t;\n" + + " Runnable r2 = (this == null ? t : t);\n" + + " Runnable r3 = ((V) t);\n" + + " \n" + + " bar(t);\n" + + " bar(this == null ? t : t);\n" + + " bar((V)t);\n" + + " }\n" + + " void bar(Runnable r) {} \n" + + " public static void main(String[] args) {\n" + + " new X().foo(new A());\n" + + " }\n" + + "}\n" + + "class A implements Serializable, Runnable {\n" + + " public void run() {\n" + + " System.out.println(\"AA\");\n" + + " }\n" + + "}\n", + }, + ""); + // ensure proper declaring class for #run() invocation + String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_8 ? + " // Method descriptor #17 (Ljava/io/Serializable;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 2, Locals: 5\n" + + " void foo(java.io.Serializable t);\n" + + " 0 aload_1 [t]\n" + + " 1 checkcast java.lang.Runnable [20]\n" + + " 4 astore_2 [r1]\n" + + " 5 aload_0 [this]\n" + + " 6 ifnonnull 13\n" + + " 9 aload_1 [t]\n" + + " 10 goto 14\n" + + " 13 aload_1 [t]\n" + + " 14 astore_3 [r2]\n" + + " 15 aload_1 [t]\n" + + " 16 astore 4 [r3]\n" + + " 18 aload_0 [this]\n" + + " 19 aload_1 [t]\n" + + " 20 checkcast java.lang.Runnable [20]\n" + + " 23 invokevirtual X.bar(java.lang.Runnable) : void [22]\n" + + " 26 aload_0 [this]\n" + + " 27 aload_0 [this]\n" + + " 28 ifnonnull 35\n" + + " 31 aload_1 [t]\n" + + " 32 goto 36\n" + + " 35 aload_1 [t]\n" + + " 36 invokevirtual X.bar(java.lang.Runnable) : void [22]\n" + + " 39 aload_0 [this]\n" + + " 40 aload_1 [t]\n" + + " 41 invokevirtual X.bar(java.lang.Runnable) : void [22]\n" + + " 44 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 5, line: 6]\n" + + " [pc: 15, line: 7]\n" + + " [pc: 18, line: 9]\n" + + " [pc: 26, line: 10]\n" + + " [pc: 39, line: 11]\n" + + " [pc: 44, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 45] local: this index: 0 type: X\n" + + " [pc: 0, pc: 45] local: t index: 1 type: java.io.Serializable\n" + + " [pc: 5, pc: 45] local: r1 index: 2 type: java.lang.Runnable\n" + + " [pc: 15, pc: 45] local: r2 index: 3 type: java.lang.Runnable\n" + + " [pc: 18, pc: 45] local: r3 index: 4 type: java.lang.Runnable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 45] local: this index: 0 type: X\n" + + " [pc: 0, pc: 45] local: t index: 1 type: T\n" : + + " // Method descriptor #17 (Ljava/io/Serializable;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 2, Locals: 5\n" + + " void foo(java.io.Serializable t);\n" + + " 0 aload_1 [t]\n" + + " 1 checkcast java.lang.Runnable [20]\n" + + " 4 astore_2 [r1]\n" + + " 5 aload_0 [this]\n" + + " 6 ifnonnull 16\n" + + " 9 aload_1 [t]\n" + + " 10 checkcast java.lang.Runnable [20]\n" + + " 13 goto 20\n" + + " 16 aload_1 [t]\n" + + " 17 checkcast java.lang.Runnable [20]\n" + + " 20 astore_3 [r2]\n" + + " 21 aload_1 [t]\n" + + " 22 astore 4 [r3]\n" + + " 24 aload_0 [this]\n" + + " 25 aload_1 [t]\n" + + " 26 checkcast java.lang.Runnable [20]\n" + + " 29 invokevirtual X.bar(java.lang.Runnable) : void [22]\n" + + " 32 aload_0 [this]\n" + + " 33 aload_0 [this]\n" + + " 34 ifnonnull 44\n" + + " 37 aload_1 [t]\n" + + " 38 checkcast java.lang.Runnable [20]\n" + + " 41 goto 48\n" + + " 44 aload_1 [t]\n" + + " 45 checkcast java.lang.Runnable [20]\n" + + " 48 invokevirtual X.bar(java.lang.Runnable) : void [22]\n" + + " 51 aload_0 [this]\n" + + " 52 aload_1 [t]\n" + + " 53 invokevirtual X.bar(java.lang.Runnable) : void [22]\n" + + " 56 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 5, line: 6]\n" + + " [pc: 21, line: 7]\n" + + " [pc: 24, line: 9]\n" + + " [pc: 32, line: 10]\n" + + " [pc: 51, line: 11]\n" + + " [pc: 56, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 57] local: this index: 0 type: X\n" + + " [pc: 0, pc: 57] local: t index: 1 type: java.io.Serializable\n" + + " [pc: 5, pc: 57] local: r1 index: 2 type: java.lang.Runnable\n" + + " [pc: 21, pc: 57] local: r2 index: 3 type: java.lang.Runnable\n" + + " [pc: 24, pc: 57] local: r3 index: 4 type: java.lang.Runnable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 57] local: this index: 0 type: X\n" + + " [pc: 0, pc: 57] local: t index: 1 type: T\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110570 +public void test0826() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public void test(V1 p1, V2 p2) {}\n" + + " \n" + + " public static void main(String[] args) {\n" + + " XA a = new XA(){};\n" + + " XB b = new XB(){};\n" + + "\n" + + " X t1 = new X();\n" + + " t1.test(a, b); //this gives an error but should be OK\n" + + " \n" + + " X t2 = new X();\n" + + " t2.test(a, b); //this compiles OK\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "\n" + + "interface XA {}\n" + + "interface XB extends XA {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " X t1 = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " X t1 = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " t1.test(a, b); //this gives an error but should be OK\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The method test(Object, Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. 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=110570 - variation +// ensure variable V2 is substituted with upper bound erasure (List) and not just upperbound List +// for raw generic method invocation +public void test0827() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public > void test(V1 p1, V2 p2) {}\n" + + " public static void main(String[] args) {\n" + + " XA a = new XA(){};\n" + + " List b = null;\n" + + " X t1 = new X();\n" + + " t1.test(a, b); //this gives an error but should be OK\n" + + " X t2 = new X();\n" + + " t2.test(a, b); //this compiles OK\n" + + " }\n" + + "}\n" + + "interface XA {}\n" + + "\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X t1 = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X t1 = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " t1.test(a, b); //this gives an error but should be OK\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The method test(Object, List) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " t2.test(a, b); //this compiles OK\n" + + " ^^^^\n" + + "Bound mismatch: The generic method test(V1, V2) of type X is not applicable for the arguments (XA, List). The inferred type List is not a valid substitute for the bounded parameter >\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X t1 = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " X t1 = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " t1.test(a, b); //this gives an error but should be OK\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The method test(Object, List) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " t2.test(a, b); //this compiles OK\n" + + " ^^^^\n" + + "The method test(V1, V2) in the type X is not applicable for the arguments (XA, List)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109249 +public void test0828() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Transformable\n" + + "{\n" + + " public T transform();\n" + + "}\n" + + "interface Volume extends Transformable\n" + + "{\n" + + "// public V transform();\n" + + "}\n" + + "@SuppressWarnings(\"null\")\n" + + "public class X {\n" + + " void foo(){\n" + + " Volume v1 = null;\n" + + " Volume v2 = v1.transform();\n" + + " }\n" + + " void bar(){\n" + + " Volume v1 = null;\n" + + " Volume v2 = v1.transform();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " interface Transformable\n" + + " ^^^^^^^^^^^^^\n" + + "Transformable is a raw type. References to generic type Transformable should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " interface Volume extends Transformable\n" + + " ^^^^^^\n" + + "Volume is a raw type. References to generic type Volume should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " Volume v1 = null;\n" + + " ^^^^^^\n" + + "Volume is a raw type. References to generic type Volume should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " Volume v2 = v1.transform();\n" + + " ^^^^^^\n" + + "Volume is a raw type. References to generic type Volume should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " Volume v2 = v1.transform();\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Transformable to Volume\n" + + "----------\n" + + "6. WARNING in X.java (at line 16)\n" + + " Volume v1 = null;\n" + + " ^^^^^^\n" + + "Volume is a raw type. References to generic type Volume should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 17)\n" + + " Volume v2 = v1.transform();\n" + + " ^^^^^^\n" + + "Volume is a raw type. References to generic type Volume should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109249 - variation +public void test0829() { + this.runConformTest( + new String[] { + "X.java", + "interface Transformable\n" + + "{\n" + + " public T transform();\n" + + "}\n" + + "interface Volume extends Transformable\n" + + "{\n" + + " public V transform();\n" + + "}\n" + + "public class X {\n" + + " void foo(){\n" + + " Volume v1 = null;\n" + + " Volume v2 = v1.transform();\n" + + " }\n" + + " void bar(){\n" + + " Volume v1 = null;\n" + + " Volume v2 = v1.transform();\n" + + " }\n" + + "}\n", + }, + ""); +} + +public void test0830() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(Object o) {\n" + + " boolean b = o instanceof X;\n" + + " X x = (X) o;\n" + + " X xs = (X)o;\n" + + " Zork z;\n" + + " }\n" + + " void bar(ArrayList al) {\n" + + " List l = (List) al;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " X x = (X) o;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " X x = (X) o;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " X xs = (X)o;\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to X\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " List l = (List) al;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " List l = (List) al;\n" + + " ^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " List l = (List) al;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); +} +//unnecessary cast may be combined with unchecked cast warning +public void test0831() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(Object o1) {\n" + + " Object o2 = (List) o1;\n" + + " \n" + + " foo((List)o2);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Object o2 = (List) o1;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Object o2 = (List) o1;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " foo((List)o2);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " foo((List)o2);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to List\n" + + "----------\n" + + "5. 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=106010 +public void test0832() { + this.runNegativeTest( + new String[] { + "X.java", + "class C1 {\n" + + " class C11 { }\n" + + " class C12 {\n" + + " T t;\n" + + " C1.C11[] m() {\n" + + " C1.C11[] ts = (C1.C11[]) new C1.C11[5];\n" + + " return ts;\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " C1.C11[] ts = (C1.C11[]) new C1.C11[5];\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from C1.C11[] to C1.C11[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111014 +public void test0833() { + this.runConformTest( + new String[] { + "A.java", + "class A {}\n", + "B.java", + "class B extends A.Inner> { class Inner {} }\n", + "C.java", + "class C { B b; }\n", + }, + ""); + this.runConformTest( + new String[] { + "C.java", + "class C { B b; }\n", + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=100809 +public void test0834() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Set set = new HashSet();\n" + + " set.add(42);\n" + + " Collection collection;\n" + + " collection = (Collection) set;\n" + + " System.out.println(collection.iterator().next());\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " collection = (Collection) set;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Collection needs unchecked conversion to conform to Collection\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " collection = (Collection) set;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. 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=100809 - variation +public void test0835() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(List ls) {\n" + + " ArrayList als = (ArrayList) ls;\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " ArrayList als = (ArrayList) ls;\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "2. 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=111208 +public void test0836() { + this.runConformTest( + new String[] { + "X.java", + " import java.util.Iterator;\n" + + " import java.util.List;\n" + + "\n" + + " public class X {\n" + + "\n" + + " interface Factory {\n" + + " T invoke();\n" + + " }\n" + + "\n" + + " public static Iterator iterate(Iterable iterable) {\n" + + " return iterable.iterator();\n" + + " }\n" + + "\n" + + " public Factory> factory(final Factory> factory) {\n" + + " return new Factory>() {\n" + + " public Iterator invoke() {\n" + + " //String s = iterate(factory.invoke());\n" + + " return iterate(factory.invoke());\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111208 - variation +public void test0837() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public void foo(List> l) {\n" + + " bar(l.get(0));\n" + + " swap(l.get(0));\n" + + " }\n" + + " void bar(String s) {}\n" + + " private static void swap(List l) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " bar(l.get(0));\n" + + " ^^^\n" + + "The method bar(String) in the type X is not applicable for the arguments (capture#1-of ? extends List)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=111689 +public void test0838() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public class CClass> {\n" + + " }\n" + + "}\n", + "AClass.java", + "public interface AClass {\n" + + " public interface BClass extends AClass {\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109118 +public void test0839() { + this.runConformTest( + new String[] { + "com/test/Tester.java", + "package com.test;\n" + + "\n" + + "import com.test.TestClass.MyException;\n" + + "\n" + + "public class Tester {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " TestClass test = new TestClass();\n" + + " } catch (MyException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + "com/test/TestClass.java", + "package com.test;\n" + + "\n" + + "public class TestClass {\n" + + " \n" + + " public TestClass() throws MyException {\n" + + " throw new MyException();\n" + + " }\n" + + "\n" + + " public static class MyException extends Exception {\n" + + " \n" + + " public MyException() {\n" + + " super();\n" + + " }\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=109118 +public void test0840() { + this.runNegativeTest( + new String[] { + "generics/NodeList.java", + "package generics;\n" + + "public class NodeList {\n" + + " public class Cursor { }\n" + + "}", + "generics/user/User.java", + "package generics.user;\n" + + "import generics.NodeList;\n" + + "import generics.NodeList.Cursor;\n" + + "public class User {\n" + + " Cursor raw;\n" + + " NodeList.Cursor rawQualified;\n" + + " NodeList.Cursor parameterized;\n" + + "\n" + + " void foo() {\n" + + " parameterized= rawQualified; //unchecked warning (OK)\n" + + " rawQualified= parameterized;\n" + + "\n" + + " parameterized= raw; //should just give unchecked warning, but errors\n" + + " raw= parameterized; //should not error\n" + + "\n" + + " raw= rawQualified; //should not error\n" + + " rawQualified= raw;\n" + + " }\n" + + " Zork z;\n" + + "}", + }, + "----------\n" + + "1. WARNING in generics\\user\\User.java (at line 5)\n" + + " Cursor raw;\n" + + " ^^^^^^\n" + + "NodeList.Cursor is a raw type. References to generic type NodeList.Cursor should be parameterized\n" + + "----------\n" + + "2. WARNING in generics\\user\\User.java (at line 6)\n" + + " NodeList.Cursor rawQualified;\n" + + " ^^^^^^^^^^^^^^^\n" + + "NodeList.Cursor is a raw type. References to generic type NodeList.Cursor should be parameterized\n" + + "----------\n" + + "3. WARNING in generics\\user\\User.java (at line 10)\n" + + " parameterized= rawQualified; //unchecked warning (OK)\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type NodeList.Cursor needs unchecked conversion to conform to NodeList.Cursor\n" + + "----------\n" + + "4. WARNING in generics\\user\\User.java (at line 13)\n" + + " parameterized= raw; //should just give unchecked warning, but errors\n" + + " ^^^\n" + + "Type safety: The expression of type NodeList.Cursor needs unchecked conversion to conform to NodeList.Cursor\n" + + "----------\n" + + "5. ERROR in generics\\user\\User.java (at line 19)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112268 +public void test0841() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " List bar() {\n" + + " List l = foo();\n" + + " return foo();\n" + + " }\n" + + " List foo() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112500 +public void test0842() { + String expectedError = isJRE11Plus ? intersection("Object","Serializable","Comparable", "CharSequence") : + intersection("Object","Serializable","CharSequence"); + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static List merge(List a, List b) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list1 = null;\n" + + " List list2 = null;\n" + + " List result = merge(list1, list2);\n" + + " List result2 = merge(list1, list2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " List result2 = merge(list1, list2);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List<" + expectedError + "> to List\n" + + "----------\n"); +} +public void test0843() { + String expectedError = isJRE11Plus ? intersection("Object","Serializable","Comparable", "CharSequence") : + intersection("Object","Serializable","CharSequence"); + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static List merge(List a, List b) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List list1 = null;\n" + + " List list2 = null;\n" + + " Object result3 = (List)merge(list1, list2);\n" + + " Object result4 = (List)merge(list1, list2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " Object result3 = (List)merge(list1, list2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List<" + expectedError + "> to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " Object result4 = (List)merge(list1, list2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List<" + expectedError + "> to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " Object result4 = (List)merge(list1, list2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List<" + expectedError + "> to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112595 +public void test0844() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " public Set< ? extends X> getModifiers()\n" + + " {\n" + + " return Collections.emptySet();\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112595 +public void test0845() { + this.runConformTest( + new String[] { + "Generic.java", // ================= + "public class Generic {\n" + + " public int size() {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", // ================= + }, + "SUCCESS"); + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public void testList(ArrayList aList) {\n" + + " aList.size();\n" + + " }\n" + + " public void testGeneric(Generic aGeneric) {\n" + + " aGeneric.size();\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public void testList(ArrayList aList) {\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public void testGeneric(Generic aGeneric) {\n" + + " ^^^^^^^\n" + + "Generic cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112666 +public void test0846() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.Collection;\n" + + "public class X {\n" + + " void m() {\n" + + " Collection> col = null;\n" + + " java.util.List n = null;\n" + + " col.add(n);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112666 +public void test0847() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.Collection;\n" + + "\n" + + "public class X {\n" + + " void m() {\n" + + " Collection> col = null;\n" + + " java.util.List n = null;\n" + + " col.add(n);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " col.add(n);\n" + + " ^^^\n" + + "The method add(capture#1-of ? extends Collection) in the type Collection> is not applicable for the arguments (List)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106451 +public void test0848() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static List asList(T a) { return null; }\n" + + " Collection asList= asList(1);\n" + + " List nums= (List) asList; // correct warning\n" + + " List numz= (LinkedList) asList; // type safety warning missing\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " List nums= (List) asList; // correct warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Collection to List\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " List numz= (LinkedList) asList; // type safety warning missing\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Collection to LinkedList\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Collection asList= Arrays.asList(1, 2.2);\n" + + " List nums= (List) asList; // correct warning\n" + + " List numz= (LinkedList) asList; // type safety warning missing\n" + + "}\n", // ================= + }, + ""); + // ensure presence of: "checkcast java.util.LinkedList" before putfield X.numz + String expectedOutput = + " // Method descriptor #14 ()V\n" + + " // Stack: 6, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [16]\n" + + " 4 aload_0 [this]\n" + + " 5 iconst_2\n" + + " 6 anewarray java.lang.Number [18]\n" + + " 9 dup\n" + + " 10 iconst_0\n" + + " 11 iconst_1\n" + + " 12 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [20]\n" + + " 15 aastore\n" + + " 16 dup\n" + + " 17 iconst_1\n" + + " 18 ldc2_w [26]\n" + + " 21 invokestatic java.lang.Double.valueOf(double) : java.lang.Double [28]\n" + + " 24 aastore\n" + + " 25 invokestatic java.util.Arrays.asList(java.lang.Object[]) : java.util.List [33]\n" + + " 28 putfield X.asList : java.util.Collection [38]\n" + + " 31 aload_0 [this]\n" + + " 32 aload_0 [this]\n" + + " 33 getfield X.asList : java.util.Collection [38]\n" + + " 36 checkcast java.util.List [40]\n" + + " 39 putfield X.nums : java.util.List [42]\n" + + " 42 aload_0 [this]\n" + + " 43 aload_0 [this]\n" + + " 44 getfield X.asList : java.util.Collection [38]\n" + + " 47 checkcast java.util.LinkedList [44]\n" + + " 50 putfield X.numz : java.util.List [46]\n" + + " 53 return\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//ensure no unsafe cast is diagnosed +public void test0849() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " static T[] cast(U[] a) { return (T[]) a; }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " static T[] cast(U[] a) { return (T[]) a; }\n" + + " ^^^^^^^\n" + + "Unnecessary cast from U[] to T[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test0850() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " T f(Object o) {\n" + + " return (T) o; // OK\n" + + " }\n" + + "\n" + + " T g(Object o) {\n" + + " return (T) o; // bug???\n" + + " }\n" + + "\n" + + " T h(Object o) {\n" + + " return X.castTo(o); // workaround\n" + + " }\n" + + "\n" + + " private static T castTo(Object o) {\n" + + " return (T) o;\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return (T) o; // OK\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " return (T) o; // bug???\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " return (T) o;\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test0851() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "interface Foo {}\n" + + "interface Bar {}\n" + + "public class X {\n" + + " Object m(Foo f) {\n" + + " return (Bar)f;\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " return (Bar)f;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Foo to Bar\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " return (Bar)f;\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Foo to Bar\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106466 +public void test0852() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " T foo() { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T foo() { return null; }\n" + + " ^^^^^^^^\n" + + "Cannot specify any additional bound Runnable when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112109 +public void test0853() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void test(java.util.List list) { list.get(0).notify(null); }\n" + + "}\n" + + "interface I { Object notify(Object o); }", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113236 +public void test0854() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Field field = new Field();\n" + + " Form form = new Form(field);\n" + + " String result = form.getField().toString();\n" + + " System.out.print(result);\n" + + " }\n" + + "}", + "Form.java", + "public class Form {\n" + + " private final Field field;\n" + + " public Form(Field field) {\n" + + " this.field = field;\n" + + " }\n" + + " public T getField() {\n" + + " return (T) field;\n" + + " }\n" + + "}", + "Field.java", + "public class Field {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113218 +public void test0855() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " FieldManager manager = new FieldManagerImpl();\n" + + " FieldMeta meta = new FieldMeta(manager);\n" + + " Field field = new FieldImpl(meta);\n" + + " FieldMeta meta2 = field.getFieldMeta();\n" + + " System.out.print(meta2.getFieldManager() instanceof ExtFieldManager);\n" + + " }\n" + + "}", + "FieldMeta.java", + "public class FieldMeta {\n" + + " private final FieldManager fieldManager;\n" + + " public FieldMeta(FieldManager fieldManager) {\n" + + " this.fieldManager = fieldManager;\n" + + " }\n" + + " public > FB getFieldManager() {\n" + + " return (FB) fieldManager;\n" + + " }\n" + + "}", + "FieldManagerImpl.java", + "public class FieldManagerImpl extends FieldManager implements\n" + + " ExtFieldManager {\n" + + "}", + "FieldManager.java", + "public abstract class FieldManager {}", + "FieldImpl.java", + "public class FieldImpl extends Field {\n" + + " public FieldImpl(FieldMeta fieldMeta) {\n" + + " super(fieldMeta);\n" + + " }\n" + + "}", + "Field.java", + "public class Field {\n" + + " private final FieldManager fieldManager;\n" + + " private final FieldMeta fieldMeta;\n" + + " public FieldMeta getFieldMeta() {\n" + + " return fieldMeta;\n" + + " }\n" + + " public Field(FieldMeta fieldMeta) {\n" + + " this.fieldMeta = fieldMeta;\n" + + " this.fieldManager = fieldMeta.getFieldManager();\n" + + " }\n" + + " public FieldManager getFieldManager() {\n" + + " return fieldManager;\n" + + " }\n" + + "}", + "ExtFieldManager.java", + "public interface ExtFieldManager {}" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "true" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test0856() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static class MX {\n" + + " T t = null;\n" + + " }\n" + + " static T getT() {\n" + + " return (new MX()).t;\n" + + " }\n" + + " public static void test() {\n" + + " getT().getClass(); // error: java.lang.Object cannot be dereferenced\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113070 +public void test0857() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void m(T t) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void m(T t) {\n" + + " ^^^^^^^^^\n" + + "Cannot specify any additional bound Cloneable when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113560 +public void test0858() { + this.runConformTest( + new String[] { + "X.java", + "interface ExtCloneable extends Cloneable {\n" + + " public ExtCloneable clone( String arg) throws CloneNotSupportedException;\n" + + "}\n" + + "public class X {\n" + + " public static ExtCloneable cloneItem1( V value) throws CloneNotSupportedException {\n" + + " return value.clone( \"\");\n" + + " }\n" + + " public static ExtCloneable cloneItem2( ExtCloneable value) throws CloneNotSupportedException {\n" + + " return value.clone( \"\");\n" + + " }\n" + + " public static ExtCloneable cloneItem3( V value) throws CloneNotSupportedException {\n" + + " return ((ExtCloneable)value).clone( \"\");\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=113710 +public void test0859() { + this.runConformTest( + new String[] { + "X.java", + "import java.awt.Graphics2D;\n" + + "import java.awt.Shape;\n" + + "public class X {\n" + + " /** Base object for wrapping */\n" + + " protected V draw;\n" + + " /**\n" + + " * Draw the object with its attached text\n" + + " * \n" + + " * @param graphics the graphics object to draw into\n" + + " */\n" + + " public void draw( Graphics2D graphics ) {\n" + + " draw.draw(graphics);\n" + + " }\n" + + "}\n" + + "abstract class DrawObject implements Drawable {\n" + + " protected void draw( Graphics2D graphics, Shape shape ) {\n" + + " }\n" + + "}\n" + + "interface Drawable {\n" + + " void draw( Graphics2D graphics );\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 +public void test0860() { + this.runConformTest( + new String[] { + "A.java", + "interface A {\n" + + " A.I foo();\n" + + " interface I { }\n" + + "}\n" + + "\n" + + "interface B extends A { }\n" + + "\n" + + "interface C extends B {\n" + + " C.J foo();\n" + + " interface J extends B.I { }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation +public void test0861() { + this.runConformTest( + new String[] { + "A.java", + "interface A {\n" + + " A.I foo();\n" + + " interface I { }\n" + + "}\n" + + "\n" + + "interface B extends A { }\n" + + "\n" + + "interface C extends B {\n" + + " C.J foo();\n" + + " interface J extends A.I { }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation +public void test0862() { + this.runConformTest( + new String[] { + "A.java", + "interface A {\n" + + " interface I { }\n" + + "\n" + + " A.I foo();\n" + + "}\n" + + "\n" + + "interface B extends A { \n" + + " interface J extends B.I { }\n" + + "}\n" + + "\n" + + "interface C extends B {\n" + + " C.J foo();\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation +public void test0863() { + this.runConformTest( + new String[] { + "A.java", + "interface A {\n" + + " interface I { }\n" + + "\n" + + " A.I foo();\n" + + "}\n" + + "\n" + + "interface B extends A { \n" + + " interface J extends B.I { }\n" + + "}\n" + + "\n" + + "interface C extends B {\n" + + " B.J foo();\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation +public void test0864() { + this.runNegativeTest( + new String[] { + "A.java", + "interface A {\n" + + " interface I { }\n" + + "\n" + + " A.I foo();\n" + + "}\n" + + "\n" + + "interface B extends A { \n" + + " interface J extends B.I { }\n" + + "}\n" + + "\n" + + "interface C extends B {\n" + + " C.J foo();\n" + + " B.J bar();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in A.java (at line 13)\n" + + " B.J bar();\n" + + " ^^^^^^^^^^^\n" + + "The member type B.J cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type B\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114304 - variation +public void test0865() { + this.runConformTest( + new String[] { + "A.java", + "class A {\n" + + " interface I { }\n" + + "\n" + + " A.I foo() { return null; }\n" + + "}\n" + + "\n" + + "class B extends A { \n" + + " interface J extends B.I { }\n" + + "}\n" + + "\n" + + "class C extends B {\n" + + " @Override\n" + + " C.J foo() { return (B.J)super.foo(); }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114997 +public void test0866() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public interface Interface {\n" + + " // nothing\n" + + " }\n" + + " public List field = Collections.emptyList();\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114087 +// SHOULD FAIL AT 1.8 (RET): Type mismatch: cannot convert from List to List +public void test0867() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "class Foo {\n" + + "\n" + + " static List> foo1() {\n" + + " return null;\n" + + " }\n" + + " static void bar1(List> l) {\n" + + " }\n" + + " static List foo2() {\n" + + " return null;\n" + + " }\n" + + " static void bar2(List l) {\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + "\n" + + " {\n" + + " List o = Foo.foo1();\n" + + " Foo.bar1(o);\n" + + " }\n" + + " {\n" + + " List o = Foo.foo2();\n" + + " Foo.bar2(o);\n" + + " }\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 20)\n" + + " List o = Foo.foo1();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + " List o = Foo.foo1();\n" + + " ^^^^\n" + + "The method foo1() in the type Foo is not applicable for the arguments ()\n" + : + " List o = Foo.foo1();\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List\n" // TODO(stephan) more specific error message + )+ + "----------\n" + + "3. ERROR in X.java (at line 21)\n" + + " Foo.bar1(o);\n" + + " ^^^^\n" + + "The method bar1(List>) in the type Foo is not applicable for the arguments (List)\n" + + "----------\n" + + "4. WARNING in X.java (at line 24)\n" + + " List o = Foo.foo2();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 25)\n" + + " Foo.bar2(o);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar2(List) of the generic method bar2(List) of type Foo\n" + + "----------\n" + + "6. WARNING in X.java (at line 25)\n" + + " Foo.bar2(o);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114365 +public void test0868() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.Iterator;\n" + + "import java.io.Serializable;\n" + + "import java.lang.Cloneable;\n" + + "public class X implements Collection {\n" + + " public int size() {\n" + + " // TODO Auto-generated method stub\n" + + " return 0;\n" + + " }\n" + + " public boolean isEmpty() {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean contains(Object arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public Iterator iterator() {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + " public Object[] toArray() {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + " public Object[] toArray(Object[] arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + " public boolean add(Object arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean remove(Object arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean containsAll(Collection arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean addAll(Collection arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean removeAll(Collection arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public boolean retainAll(Collection arg0) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " public void clear() {\n" + + " // TODO Auto-generated method stub\n" + + " \n" + + " }" + + "}", + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115181 +public void test0869() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Comparator;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = Comparator.class;\n" + + " Zork z;\n" + + " }\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=113950 +public void test0870() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public interface I {\n" + + " public void foo(List ls);\n" + + " }\n" + + "\n" + + " public abstract class A implements I {\n" + + " public void foo(List ls) { }\n" + + " }\n" + + "\n" + + " public class C extends A> { }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=107788 +public void test0871() { + this.runConformTest( + new String[] { + "Lister.java", + "interface Lister {\n" + + " void endPacking(PackT p, BeanT b, Accessor acc);\n" + + "\n" + + " static class IDRefs implements\n" + + " Lister.Pack> {\n" + + " public void endPacking(Pack p, BeanT b, Accessor acc) {\n" + + " }\n" + + "\n" + + " private class Pack {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class Accessor {\n" + + "}\n", + }, + ""); +} +public void test0872() { + String expectedError = this.complianceLevel < ClassFileConstants.JDK16 ? + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " M3.N3 n = m.new N3();\n" + + " ^^^^^^^^\n" + + "The member type X.M3.N3 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.M3\n" + + "----------\n" + + "2. ERROR in X.java (at line 25)\n" + + " static class N3 {\n" + + " ^^\n" + + "The member type N3 cannot be declared static; static types can only be declared in static or top level types\n" + + "----------\n" + + "3. ERROR in X.java (at line 30)\n" + + " M4.N4 n = m.new N4();\n" + + " ^^^^^^^^\n" + + "The member type X.M4.N4 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.M4\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " M3.N3 n = m.new N3();\n" + + " ^^^^^^^^\n" + + "The member type X.M3.N3 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.M3\n" + + "----------\n" + + "2. ERROR in X.java (at line 30)\n" + + " M4.N4 n = m.new N4();\n" + + " ^^^^^^^^\n" + + "The member type X.M4.N4 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.M4\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.io.PrintStream;\n" + + "\n" + + "public class X {\n" + + " public void foo1(){\n" + + " M1 m = new M1();\n" + + " M1.N1 n = m.new N1();\n" + + " }\n" + + " static class M1 {\n" + + " class N1 {\n" + + " }\n" + + " }\n" + + " public void foo2(){\n" + + " M2 m = new M2();\n" + + " M2.N2 n = m.new N2();\n" + + " }\n" + + " class M2 {\n" + + " class N2 {\n" + + " }\n" + + " }\n" + + " public void foo3(){\n" + + " M3 m = new M3();\n" + + " M3.N3 n = m.new N3();\n" + + " }\n" + + " class M3 {\n" + + " static class N3 {\n" + + " }\n" + + " }\n" + + " public void foo4(){\n" + + " M4 m = new M4();\n" + + " M4.N4 n = m.new N4();\n" + + " }\n" + + " static class M4 {\n" + + " static class N4 {\n" + + " }\n" + + " }\n" + + "}\n", + }, + expectedError); +} +public void test0873() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " static class XMap {\n" + + " XEntry[] table;\n" + + " static class XEntry {} \n" + + " void foo() {\n" + + " XEntry e = table[0];\n" + + " } \n" + + " } \n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115693 +public void test0874() throws Exception { + this.runConformTest( + new String[] { + "X.java", // ================= + "class A {}\n" + + "abstract class B {\n" + + " public B label(String s) { return this; }\n" + + "}\n" + + "final class C extends B {\n" + + " public static C instance(String s) { return new C(); }\n" + + " @Override public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " C c = (C)C.instance(\"X\").label(\"Y\");\n" + + " System.out.println(c.toString());\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + // ensure only one checkcast C + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc [16]\n" + + " 2 invokestatic C.instance(java.lang.String) : C [17]\n" + + " 5 ldc [23]\n" + + " 7 invokevirtual C.label(java.lang.String) : B [25]\n" + + " 10 checkcast C [18]\n" + + " 13 astore_1 [c]\n" + + " 14 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + + " 17 aload_1 [c]\n" + + " 18 invokevirtual C.toString() : java.lang.String [35]\n" + + " 21 invokevirtual java.io.PrintStream.println(java.lang.String) : void [39]\n" + + " 24 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 14, line: 14]\n" + + " [pc: 24, line: 15]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 25] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 14, pc: 25] local: c index: 1 type: C\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119395 +public void test0875() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + "\n" + + " public static class DatabaseObject {}\n" + + " public static class ObjectFormUI {}\n" + + " private static final Map, Class> uiMap = new HashMap, Class>();\n" + + "\n" + + " public static Class> getUI(\n" + + " Class persistentClass) {\n" + + " return null != null \n" + + " ? uiMap.get(persistentClass)\n" + + " : (Class>) uiMap.get(persistentClass);\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " private static final Map, Class> uiMap = new HashMap, Class>();\n" + + " ^^^^^^^^^^^^\n" + + "X.ObjectFormUI is a raw type. References to generic type X.ObjectFormUI should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " private static final Map, Class> uiMap = new HashMap, Class>();\n" + + " ^^^^^^^^^^^^\n" + + "X.ObjectFormUI is a raw type. References to generic type X.ObjectFormUI should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " return null != null \n" + + " ? uiMap.get(persistentClass)\n" + + " : (Class>) uiMap.get(persistentClass);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " : (Class>) uiMap.get(persistentClass);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class>\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " private static final Map, Class> uiMap = new HashMap, Class>();\n" + + " ^^^^^^^^^^^^\n" + + "X.ObjectFormUI is a raw type. References to generic type X.ObjectFormUI should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " private static final Map, Class> uiMap = new HashMap, Class>();\n" + + " ^^^^^^^^^^^^\n" + + "X.ObjectFormUI is a raw type. References to generic type X.ObjectFormUI should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " ? uiMap.get(persistentClass)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " : (Class>) uiMap.get(persistentClass);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119395 - variation +public void test0876() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " void foo(){\n" + + " Class> cco = null;\n" + + " Class cc = cco; // ko\n" + + " Class> cco2 = cc; // ko\n" + + " \n" + + " Class> ceco = null;\n" + + " Class cec = ceco; // ok\n" + + " Class> ceco2 = cec; // ko\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Class cc = cco; // ko\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Class cc = cco; // ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from Class> to Class\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " Class> cco2 = cc; // ko\n" + + " ^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " Class cec = ceco; // ok\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " Class> ceco2 = cec; // ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119395 - variation +public void test0877() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " void bar(T t) {\n" + + " Class c = t; // ok - unchecked\n" + + " }\n" + + " void bar2(List let) {\n" + + " Class c = let.get(0); // ok - unchecked\n" + + " }\n" + + " void bar3(List lec) {\n" + + " Class c = lec.get(0); // ok - unchecked\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void bar(T t) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " void bar(T t) {\n" + + " ^^^^^\n" + + "The type parameter T should not be bounded by the final type Class. Final types cannot be further extended\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " Class c = t; // ok - unchecked\n" + + " ^\n" + + "Type safety: The expression of type T needs unchecked conversion to conform to Class\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " void bar2(List let) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " void bar2(List let) {\n" + + " ^^^^^\n" + + "The type parameter T should not be bounded by the final type Class. Final types cannot be further extended\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " Class c = let.get(0); // ok - unchecked\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type capture#1-of ? extends T needs unchecked conversion to conform to Class\n" + + "----------\n" + + "7. WARNING in X.java (at line 9)\n" + + " void bar3(List lec) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 10)\n" + + " Class c = lec.get(0); // ok - unchecked\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type capture#2-of ? extends Class needs unchecked conversion to conform to Class\n" + + "----------\n" + + "9. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115693 - variation +public void test0878() throws Exception { + this.runConformTest( + new String[] { + "X.java", // ================= + "class A {}\n" + + "class D extends A {}\n" + + "abstract class B {\n" + + " public T label(String s) { return null; }\n" + + "}\n" + + "final class C extends B {\n" + + " public static C instance(String s) { return new C(); }\n" + + " @Override public String toString() {\n" + + " return \"SUCCESS\"; \n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " D d = (D)C.instance(\"X\").label(\"Y\");\n" + + " System.out.println(d);\n" + + " }\n" + + "}\n", + }, + "null"); + // ensure only one checkcast D + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 ldc [16]\n" + + " 2 invokestatic C.instance(java.lang.String) : C [17]\n" + + " 5 ldc [23]\n" + + " 7 invokevirtual C.label(java.lang.String) : java.lang.Object [25]\n" + + " 10 checkcast D [29]\n" + + " 13 astore_1 [d]\n" + + " 14 getstatic java.lang.System.out : java.io.PrintStream [31]\n" + + " 17 aload_1 [d]\n" + + " 18 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [37]\n" + + " 21 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 14, line: 15]\n" + + " [pc: 21, line: 16]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 22] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 14, pc: 22] local: d index: 1 type: D\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122610 +public void test0879() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + "\n" + + " private class InnerClass1 {\n" + + " void foo() {\n" + + " X c = X.this;\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 +public void test0880() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "class Foo {\n" + + " static > U foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " {\n" + + " String s = (String) Foo.foo();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s = (String) Foo.foo();\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation +public void test0881() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "class Foo {\n" + + " static > U foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " {\n" + + " String s = (String) Foo.foo();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s = (String) Foo.foo();\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List> to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation +public void test0882() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static > U foo(U u) {\n" + + " String s = (String) foo(u);\n" + + " return u;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " String s = (String) foo(u);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot cast from U to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121369 - variation +public void test0883() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static > U foo(U u) {\n" + + " List listu = null;\n" + + " String s = (String)foo(listu);\n" + + " return u;\n" + + " }\n" + + " static > V bar(V v) {\n" + + " List listv = null;\n" + + " String s = (String)foo(listv);\n" + + " return v;\n" + + " }\n" + + "}\n", + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String s = (String)foo(listu);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " String s = (String)foo(listu);\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(U) of type X is not applicable for the arguments (List). The inferred type List is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " String s = (String)foo(listv);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to String\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " String s = (String)foo(listv);\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(U) of type X is not applicable for the arguments (List). The inferred type List is not a valid substitute for the bounded parameter >\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String s = (String)foo(listu);\n" + + " ^^^\n" + + "The method foo(U) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " String s = (String)foo(listv);\n" + + " ^^^\n" + + "The method foo(U) in the type X is not applicable for the arguments (List)\n" + + "----------\n" )); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=123078 +// SHOULD FAIL AT 1.8 (18.2.3): The method getDefault(Class) in the type X is not applicable for the arguments (Class) +public void test0884() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public abstract class X> {\n" + + " public static > T getDefault(Class clz) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public Object getDefault() {\n" + + " String s = getClass();\n" + + " return (String) getDefault(getClass());\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " String s = getClass();\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return (String) getDefault(getClass());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to String\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " return (String) getDefault(getClass());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation getDefault(Class) of the generic method getDefault(Class) of type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=125445 +public void test0885() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static > int m(\n" + + " A comparableNumberObj) {\n" + + " return comparableNumberObj.compareTo(comparableNumberObj);\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static > int m(\n" + + " ^^^^^^^^^^\n" + + "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=124943 +public void test0886() { + Map customOptions= getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", // ================= + "public class X {\n" + + " void test() {\n" + + " \"Hello\".compareTo((Object) \"Hello\");\n" + + " }\n" + + "}\n" , + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "" /* expected compiler log */, + // runtime results + "" /* expected output string */, + null /* do not check error string */, + // javac options + new JavacTestOptions("-source 1.4 -Xlint:-options") /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 +public void test0887() { + this.runNegativeTest( + new String[] { + "Bar.java", // ================= + "class Foo {}\n" + + "public class Bar>>{\n" + + " Bar(X x){\n" + + " Foo f = x;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Bar.java (at line 4)\n" + + " Foo f = x;\n" + + " ^\n" + + "Type mismatch: cannot convert from X to Foo\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation +public void test0888() { + this.runNegativeTest( + new String[] { + "Bar.java", // ================= + "class Foo {}\n" + + "public class Bar>>{\n" + + " Bar(X x){\n" + + " Foo f = x;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Bar.java (at line 4)\n" + + " Foo f = x;\n" + + " ^\n" + + "Type mismatch: cannot convert from X to Foo\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation +public void test0889() { + this.runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "Test.java", // ================= + "import java.util.*;\n" + + "\n" + + "class Group> extends ArrayList implements\n" + + " Comparable> {\n" + + " public int compareTo(Group o) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sequence> extends TreeSet implements\n" + + " Comparable> {\n" + + " public int compareTo(Sequence o) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "\n" + + "class Test> {\n" + + " > void foo(SortedSet setToCheck,\n" + + " SortedSet validSet) {\n" + + " }\n" + + "\n" + + " public void containsCombination(SortedSet> groups,\n" + + " SortedSet> sequences) {\n" + + " foo(groups, sequences);\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation +public void test0890() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "Simple.java", // ================= + "class A> {}\n" + + "class B extends A {}\n" + + "class C extends B {}\n" + + "class D {}\n" + + "\n" + + "public class Simple {\n" + + " , S extends T> D m(S s) {\n" + + " C c = null;\n" + + " D d = m(c);\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122775 - variation +public void test0891() { + String xSource = + "interface Function {\n" + + " B apply(A x);\n" + + "}\n" + + "class Id implements Function {\n" + + " public A apply(A x) {\n" + + " return x;\n" + + " }\n" + + "}\n" + + "class Test {\n" + + " Id identity() {\n" + + " return new Id();\n" + + " }\n" + + "\n" + + " B applyToString(Function f) {\n" + + " return f.apply(\"abc\");\n" + + " }\n" + + " void test() {\n" + + " String s = applyToString(identity());\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "Test.java", + xSource + }, + "----------\n" + + "1. ERROR in Test.java (at line 18)\n" + + " String s = applyToString(identity());\n" + + " ^^^^^^^^^^^^^\n" + + "The method applyToString(Function) in the type Test is not applicable for the arguments (Id)\n" + + "----------\n"); + } else { + runConformTest( + new String[] { + "Test.java", + xSource + }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126180 +public void test0892() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static void main(String[] args) {\n" + + " C2 c2 = null;\n" + + " C3 c3 = null;\n" + + " Object oc1 = m1(c2, c3).new C1Member();\n" + + " }\n" + + "\n" + + " public static T m1(T t1, T t2) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " class C1 {}\n" + + " interface I1 {}\n" + + " class C2 extends C1 implements I1 {}\n" + + " class C3 extends C1 implements I1 {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Object oc1 = m1(c2, c3).new C1Member();\n" + + " ^^^^^^^^\n" + + intersection("X.C1","X.I1.C1Member")+" cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126177 +public void test0893() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " static String foo;\n" + + "\n" + + " public static void main(String[] args) {\n" + + " C2 c2 = null;\n" + + " C3 c3 = null;\n" + + " // method access\n" + + " m1(c2, c3).c1m1();\n" + + " m1(c2, c3).i1m1();\n" + + " m1(c2, c3).i2m1();\n" + + "\n" + + " // field access\n" + + " int ic1 = m1(c2, c3).c1f1;\n" + + " int ii1 = m1(c2, c3).i1f1;\n" + + " int ii2 = m1(c2, c3).i2f1;\n" + + " \n" + + " // member type access\n" + + " Object oc1 = m1(c2, c3).new C1Member();\n" + + " Object oi1 = m1(c2, c3).new I1Member(); \n" + + " Object oi2 = m1(c2, c3).new I2Member();\n" + + " }\n" + + "\n" + + " public static T m1(T t1, T t2) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " class C1 {\n" + + " void c1m1() {}\n" + + " int c1f1 = 0;\n" + + " class C1Member {}\n" + + " }\n" + + "\n" + + " interface I1 {\n" + + " void i1m1();\n" + + " int i1f1 = 1;\n" + + " class I1Member {}\n" + + " }\n" + + "\n" + + " interface I2 {\n" + + " void i2m1();\n" + + " int i2f1 = 2;\n" + + " class I2Member {}\n" + + " }\n" + + "\n" + + " class C2 extends C1 implements I1, I2 {\n" + + " public void i1m1() {\n" + + " }\n" + + " public void i2m1() {\n" + + " }\n" + + " }\n" + + "\n" + + " class C3 extends C1 implements I1, I2 {\n" + + " public void i1m1() {\n" + + " }\n" + + " public void i2m1() {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 14)\n" + + " int ii1 = m1(c2, c3).i1f1;\n" + + " ^^^^\n" + + "The static field X.I1.i1f1 should be accessed in a static way\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " int ii2 = m1(c2, c3).i2f1;\n" + + " ^^^^\n" + + "The static field X.I2.i2f1 should be accessed in a static way\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " Object oi1 = m1(c2, c3).new I1Member(); \n" + + " ^^^^^^^^^^\n" + + "Illegal enclosing instance specification for type X.I1.I1Member\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " Object oi2 = m1(c2, c3).new I2Member();\n" + + " ^^^^^^^^^^\n" + + "Illegal enclosing instance specification for type X.I2.I2Member\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126177 - variation +public void test0894() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", // ================= + "public class X {\n" + + " static class C1 {\n" + + " void c1m1() {\n" + + " System.out.print(\"[c1m1]\");\n" + + " }\n" + + " }\n" + + " static interface I {}\n" + + " static class C2 extends C1 implements I {}\n" + + " static class C3 extends C1 implements I {}\n" + + "\n" + + " public T m1(T t1, T t2) {\n" + + " return t1;\n" + + " }\n" + + "\n" + + " public void test(C2 c2, C3 c3, T t) {\n" + + " m1(c2, c3).c1m1(); // 1\n" + + " t.c1m1(); // 2\n" + + " (t != null ? c2 : c3).c1m1(); // 3\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " X x = new X();\n" + + " x.test(new C2(), new C3(), new C2()); // 4\n" + + " System.out.println();\n" + + " }\n" + + "}\n", + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "[c1m1][c1m1][c1m1]" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test0895() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "interface I {}\n" + + "public class X {\n" + + " Object o = new I() {};\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new I() {};\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor Object() of type Object is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", // ================= + "interface I {}\n" + + "public class X {\n" + + " Object o = new I() {};\n" + + "}\n" , + "Y.java", + "class Y extends Zork {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object o = new I() {};\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor Object() of type Object; it should not be parameterized with arguments \n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " class Y extends Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test0896() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", // ================= + "public class X {\n" + + " interface I { void f(); }\n" + + " interface J { void g(); }\n" + + "\n" + + " static class A implements I, J {\n" + + " public void f() { System.out.print(\"[A#f()]\");}\n" + + " public void g() { System.out.print(\"[A#g()]\");}\n" + + " }\n" + + "\n" + + " static class B implements J, I {\n" + + " public void f() { System.out.print(\"[B#f()]\");}\n" + + " public void g() { System.out.print(\"[B#g()]\");}\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " f(true, new A(), new B());\n" + + " f(false, new A(), new B());\n" + + " System.out.println();\n" + + " }\n" + + "\n" + + " static void f(boolean cond, A a, B b) {\n" + + " (cond ? a : b).f();\n" + + " (cond ? a : b).g();\n" + + " }\n" + + "}\n", + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "[A#f()][A#g()][B#f()][B#g()]" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test0897() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "Test.java", // ================= + "interface I { }\n" + + "class X { }\n" + + "class A extends X implements I { }\n" + + "class B extends X implements I { }\n" + + "public class Test {\n" + + " void test(A a, B b) {\n" + + " X x = (a.hashCode() == b.hashCode()) ? a : b;\n" + + " }\n" + + "}\n" + + "\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test0898() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", // ================= + "interface I1 {\n" + + " void i1();\n" + + "}\n" + + "class G1 {\n" + + " T get() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "interface I2 {\n" + + " void i2();\n" + + "}\n" + + "public class X {\n" + + " void f1(G1 g1) {\n" + + " g1.get().i1();\n" + + " }\n" + + " void f2(G1 g1) {\n" + + " g1.get().i1();\n" + + " g1.get().i2();\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122331 +public void test0899() { + this.runConformTest( + new String[] { + "A.java", // ================= + "public class A> extends SomeArbitraryClass {\n" + + " public static class B {\n" + + " private C c;\n" + + " protected void set(C val) {\n" + + " c = val;\n" + + " }\n" + + " protected class C {\n" + + " }\n" + + " }\n" + + "}", + "C.java", + "public class C {\n" + + " \n" + + " public C() {\n" + + " //do nothing\n" + + " }\n" + + " \n" + + "}", + "ObjThatExtendsB.java", + "public class ObjThatExtendsB extends A.B {\n" + + " protected void doSomeSetting() {\n" + + " super.set(new ObjThatExtendsC());\n" + + " }\n" + + " protected class ObjThatExtendsC extends C {\n" + + " }\n" + + "}", + "ObjThatExtendsC.java", + "public class ObjThatExtendsC extends C {\n" + + " public ObjThatExtendsC() {\n" + + " //do nothing\n" + + " }\n" + + "}", + "SomeArbitraryClass.java", + "public class SomeArbitraryClass> {\n" + + " public SomeArbitraryClass() {\n" + + " //do nothing\n" + + " }\n" + + "}" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97693 +public void test0900() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " static interface Interface extends Comparable {}\n" + + "\n" + + " static final class Implements implements Interface {\n" + + " public int compareTo(String o) {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " void method() {\n" + + " ((Comparable) new Implements()).toString();\n" + + " ((Comparable) new Implements()).toString();\n" + + " ((Comparable) new Implements()).toString();\n" + + " ((Comparable) new Implements()).toString();\n" + + " ((Comparable) new Implements()).toString();\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " ((Comparable) new Implements()).toString();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X.Implements to Comparable\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " ((Comparable) new Implements()).toString();\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// Object array vs Object into generic method +public void test0901() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static T foo(T p1, T p2) {\n" + + " return p1;\n" + + " }\n" + + " static Object[] bar(int[] i, float[] f) {\n" + + " return foo(i, f);\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return foo(i, f);\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from "+intersection("Object","Serializable","Cloneable")+" to Object[]\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// circular references amongst generic interfaces with co-implementing classes +public void test0902() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "I.java", + "public interface I>> {\n" + + "}", + "J.java", + "public interface J>> {\n" + + "}", + "CI.java", + "class CI & J,\n" + + " T extends CI & I>\n" + + " implements I {\n" + + "}", + "CJ.java", + "class CJ & I,\n" + + " U extends CJ & J>\n" + + " implements J {\n" + + "}"}, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=126914 +public void test0903() { + this.runConformTest( + new String[] { + "X.java", + "interface I, U extends I> {\n" + + " // empty\n" + + "}\n" + + "interface J, U extends I> {\n" + + " // empty\n" + + "}\n" + + "final class Y extends X implements I, Y> {\n" + + " // empty\n" + + "}\n" + + "abstract class X implements J, Y> {\n" + + " // empty\n" + + "}\n" + }, + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=126914 +public void test0904() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "interface I, U extends I> {\n" + + " // empty\n" + + "}\n" + + "interface J, U extends I> {\n" + + " // empty\n" + + "}\n" + + "abstract class X implements J, Y> {\n" + + " // empty\n" + + "}\n" + + "final class Y extends X implements I, Y> {\n" + + " // empty\n" + + "}\n" + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// array in super bound +public void test0905() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.List;\n" + + " \n" + + "class X {\n" + + " void foo(List p) {\n" + + " p.add(new Object[0]);\n" + + " }\n" + + "}"}, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// raw types in casts +public void test0906() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " // empty\n" + + "} \n" + + "public class X implements I {\n" + + " I x1 = (I) (X) null;\n" + + " I x2 = (I) new X();\n" + + " I x3 = (I) null;\n" + + " X x4 = (X) (I) null;\n" + + "}"}, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public class X implements I {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " I x1 = (I) (X) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to I\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " I x1 = (I) (X) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to I\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " I x1 = (I) (X) null;\n" + + " ^^^^^^^^\n" + + "Unnecessary cast from null to X\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " I x2 = (I) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to I\n" + + "----------\n" + + "6. WARNING in X.java (at line 6)\n" + + " I x2 = (I) new X();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X to I\n" + + "----------\n" + + "7. WARNING in X.java (at line 7)\n" + + " I x3 = (I) null;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from null to I\n" + + "----------\n" + + "8. WARNING in X.java (at line 8)\n" + + " X x4 = (X) (I) null;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from null to I\n" + + "----------\n"); +} + +// parametrized method with array extends Object upper bound verification +public void test0907() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.Collections;\n" + + "public class X, V> {\n" + + " public void foo() {\n" + + " Y o = (new Z()). bar(Collections\n" + + " .singleton(new Y()));\n" + + " o.toString();\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " // empty\n" + + "}\n" + + "class Z {\n" + + " public , W extends V> U bar(Collection c) {\n" + + " return null;\n" + + " }\n" + + "}\n"}, + ""); +} + +// check capture for conditional operator - variant +public void test0908() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public abstract class X {\n" + + " protected void foo(Class clazz) {\n" + + " Class l = clazz.isInterface() ? bar(clazz) : clazz;\n" + + " }\n" + + " abstract public Class bar(Class p);\n" + + "}"}, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126105 +public void test0909() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static class B {\n" + + " private Object x;\n" + + "\n" + + " public B(T x) {\n" + + " this.x = x;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class C {\n" + + " private Object x;\n" + + "\n" + + " public C(Object x) {\n" + + " this.x = x;\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws Throwable {\n" + + " B b = new B(\"foo\");\n" + + " System.out.println(b.x);\n" + + "\n" + + " C c = new C(\"foo\");\n" + + " System.out.println(c.x);\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 +public void test0910() { + int[] capIds = this.complianceLevel < ClassFileConstants.JDK1_8 + ? new int[]{ 1, 3, 4, 6, 13} + : new int[]{ 1, 2, 3, 4, 8}; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void bar() {\n" + + " List lc1 = null;\n" + + " List> lc2 = null;\n" + + " List> lc3 = null;\n" + + " List lc4 = null;\n" + + " lc1 = lc2; //1 ko\n" + + " lc1 = lc3; //2 ko\n" + + " lc1 = lc4; //3 ko\n" + + " lc2 = lc1; //4 ko\n" + + " lc2 = lc3; //5 ko\n" + + " lc2 = lc4; //6 ko\n" + + " lc3 = lc1; //7 ko\n" + + " lc3 = lc2; //8 ok\n" + + " lc3 = lc4; //9 ko\n" + + " lc4 = lc1; //10 ok\n" + + " lc4 = lc2; //11 ok\n" + + " lc4 = lc3; //12 ok\n" + + " }\n" + + " private final List aList = new ArrayList();\n" + + " public void foo() {\n" + + " final List> listCopy = new ArrayList>(this.aList); // ko\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " List lc1 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " List lc4 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " lc1 = lc2; //1 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " lc1 = lc3; //2 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " lc1 = lc4; //3 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "6. ERROR in X.java (at line 15)\n" + + " lc2 = lc1; //4 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "7. ERROR in X.java (at line 16)\n" + + " lc2 = lc3; //5 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n" + + "8. ERROR in X.java (at line 17)\n" + + " lc2 = lc4; //6 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "9. ERROR in X.java (at line 18)\n" + + " lc3 = lc1; //7 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "10. ERROR in X.java (at line 20)\n" + + " lc3 = lc4; //9 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "11. WARNING in X.java (at line 25)\n" + + " private final List aList = new ArrayList();\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "12. WARNING in X.java (at line 25)\n" + + " private final List aList = new ArrayList();\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "13. ERROR in X.java (at line 27)\n" + + " final List> listCopy = new ArrayList>(this.aList); // ko\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor ArrayList>(List) is undefined\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation +public void test0911() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void bar() {\n" + + " List lc1 = null;\n" + + " List> lc2 = null;\n" + + " List> lc3 = null;\n" + + " List lc4 = null;\n" + + " lc1 = lc2; //1 ko\n" + + " lc1 = lc3; //2 ko\n" + + " lc1 = lc4; //3 ko\n" + + " lc2 = lc1; //4 ko\n" + + " lc2 = lc3; //5 ko\n" + + " lc2 = lc4; //6 ko\n" + + " lc3 = lc1; //7 ok\n" + + " lc3 = lc2; //8 ok\n" + + " lc3 = lc4; //9 ok\n" + + " lc4 = lc1; //10 ok\n" + + " lc4 = lc2; //11 ko\n" + + " lc4 = lc3; //12 ko\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " List lc1 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " List lc4 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " lc1 = lc2; //1 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " lc1 = lc3; //2 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " lc1 = lc4; //3 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " lc2 = lc1; //4 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "7. ERROR in X.java (at line 15)\n" + + " lc2 = lc3; //5 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n" + + "8. ERROR in X.java (at line 16)\n" + + " lc2 = lc4; //6 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "9. ERROR in X.java (at line 21)\n" + + " lc4 = lc2; //11 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "10. ERROR in X.java (at line 22)\n" + + " lc4 = lc3; //12 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation +public void test0912() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " void foo(List[]> l1, List l2) {\n" + + " l1 = l2;\n" + + " l2 = l1;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(List[]> l1, List l2) {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " l1 = l2;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " l2 = l1;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation +public void test0913() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void bar() {\n" + + " List lc1 = null;\n" + + " List[]> lc2 = null;\n" + + " List[]> lc3 = null;\n" + + " List lc4 = null;\n" + + " lc1 = lc2; //1 ko\n" + + " lc1 = lc3; //2 ko\n" + + " lc1 = lc4; //3 ko\n" + + " lc2 = lc1; //4 ko\n" + + " lc2 = lc3; //5 ko\n" + + " lc2 = lc4; //6 ko\n" + + " lc3 = lc1; //7 ko\n" + + " lc3 = lc2; //8 ok\n" + + " lc3 = lc4; //9 ko\n" + + " lc4 = lc1; //10 ok\n" + + " lc4 = lc2; //11 ok\n" + + " lc4 = lc3; //12 ok \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List lc1 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " List lc4 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " lc1 = lc2; //1 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " lc1 = lc3; //2 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " lc1 = lc4; //3 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " lc2 = lc1; //4 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " lc2 = lc3; //5 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List[]>\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " lc2 = lc4; //6 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "9. ERROR in X.java (at line 14)\n" + + " lc3 = lc1; //7 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "10. ERROR in X.java (at line 16)\n" + + " lc3 = lc4; //9 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127583 - variation +public void test0914() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void bar() {\n" + + " List lc1 = null;\n" + + " List[]> lc2 = null;\n" + + " List[]> lc3 = null;\n" + + " List lc4 = null;\n" + + " lc1 = lc2; //1 ko\n" + + " lc1 = lc3; //2 ko\n" + + " lc1 = lc4; //3 ko\n" + + " lc2 = lc1; //4 ko\n" + + " lc2 = lc3; //5 ko\n" + + " lc2 = lc4; //6 ko\n" + + " lc3 = lc1; //7 ok\n" + + " lc3 = lc2; //8 ok\n" + + " lc3 = lc4; //9 ok\n" + + " lc4 = lc1; //10 ok\n" + + " lc4 = lc2; //11 ko\n" + + " lc4 = lc3; //12 ko \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List lc1 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " List lc4 = null;\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " lc1 = lc2; //1 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " lc1 = lc3; //2 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " lc1 = lc4; //3 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " lc2 = lc1; //4 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " lc2 = lc3; //5 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List[]>\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " lc2 = lc4; //6 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List[]>\n" + + "----------\n" + + "9. ERROR in X.java (at line 18)\n" + + " lc4 = lc2; //11 ko\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n" + + "10. ERROR in X.java (at line 19)\n" + + " lc4 = lc3; //12 ko \n" + + " ^^^\n" + + "Type mismatch: cannot convert from List[]> to List\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128389 +public void test0915() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y1 extends Throwable {\n" + + " private static final long serialVersionUID = 1L;\n" + + " T t;\n" + + " }\n" + + " static class Y2 extends Throwable {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " class Y3 extends Throwable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "\n" + + " T t;\n" + + " }\n" + + "}\n" + + "class Y4 extends Throwable {}\n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y1 extends Throwable {\n" + + " ^^^^^^^^^\n" + + "The generic class X.Y1 may not subclass java.lang.Throwable\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " class Y3 extends Throwable {\n" + + " ^^^^^^^^^\n" + + "The generic class X.Y3 may not subclass java.lang.Throwable\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " class Y4 extends Throwable {}\n" + + " ^^\n" + + "The serializable class Y4 does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " class Y4 extends Throwable {}\n" + + " ^^^^^^^^^\n" + + "The generic class Y4 may not subclass java.lang.Throwable\n" + + "----------\n"); +} + +// synchronized inheritance for multiple generic types +public void test0916() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X> {\n" + + " T m2;\n" + + " T getX2() {\n" + + " return this.m2;\n" + + " }\n" + + "}\n" + + "class X2 {\n" + + " T m3;\n" + + " T getX3() {\n" + + " return this.m3;\n" + + " }\n" + + "}\n" + + "class X3 {\n" + + "}\n" + + "class Y1> extends X {\n" + + " public void foo() {\n" + + " getX2().getX3().bar(); // getX3 appropriately returns an Y3\n" + + " }\n" + + "}\n" + + "class Y2 extends X2 {\n" + + "}\n" + + "class Y3 extends X3 {\n" + + " public void bar() {\n" + + " }\n" + + "}\n"}, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 +// [1.5][compiler] ClassCastException on illegal code fragment +public void test0917() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends X2 { }\n" + + "class X2 { }\n" + + "class A { static class M {} }" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends X2 { }\n" + + " ^^^\n" + + "Illegal qualified access from the type parameter T\n" + + "----------\n" + // cannot select from a type variable + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 - variation +public void test0917a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends X2 { }\n" + + "class X2 { }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends X2 { }\n" + + " ^^^^^^^\n" + + "Illegal qualified access from the type parameter T\n" + + "----------\n" + // cannot select from a type variable + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 - variation +public void test0917b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { Class c = T.class; }" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X { Class c = T.class; }\n" + + " ^^^^^^^\n" + + "Illegal class literal for the type parameter T\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128423 - variation +public void test0917c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends X2 { }\n" + + "class X2 { }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends X2 { }\n" + + " ^^^^^\n" + + "Syntax error on token \"class\", Identifier expected\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128560 +public void test0918() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "BasicNode.java", + "class BasicEdge & Node, E extends BasicEdge & Edge>\n" + + " implements Edge {\n" + + "}\n" + + "\n" + + "public class BasicNode & Edge, N extends BasicNode & Node>\n" + + " implements Node {\n" + + "}\n" + + "\n" + + "interface Edge>> {\n" + + "}\n" + + "\n" + + "interface Node>> {\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +public void test0919() { + this.runConformTest( + new String[] { + "X.java", + "class Box {\n" + + " private E element;\n" + + " void put(E elem) {\n" + + " this.element = elem;\n" + + " }\n" + + " E get() {\n" + + " return this.element;\n" + + " }\n" + + " Pair asPair() {\n" + + " return new Pair(this.element, this.element);\n" + + " }\n" + + " Box> nest() {\n" + + " Box> wrapper = new Box>();\n" + + " wrapper.put(this);\n" + + " return wrapper;\n" + + " }\n" + + "}\n" + + "\n" + + "class Pair {\n" + + " Pair(U u, V v) {\n" + + " }\n" + + "}\n" + + "\n" + + "class PandoraBox> extends Box {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void test(PandoraBox pbox) {\n" + + " Box box = pbox.get();\n" + + " Pair pair = pbox.asPair();\n" + + " Box nbox = pbox.nest();\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test0920() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class Stack {\n" + + " private List contents = new ArrayList();\n" + + " void push(E e) {\n" + + " this.contents.add(e);\n" + + " }\n" + + " E pop() {\n" + + " int last = this.contents.size() - 1;\n" + + " if (last < 0) throw new EmptyStackException();\n" + + " return this.contents.remove(last);\n" + + " }\n" + + " private static void doSwap(Stack s) {\n" + + " T t1 = s.pop();\n" + + " T t2 = s.pop();\n" + + " s.push(t1);\n" + + " s.push(t2);\n" + + " }\n" + + " static void swap(Stack s) { doSwap(s); }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Stack si = new Stack();\n" + + " Integer[] ints = { 12, 13, 14, 15, };\n" + + " for (Integer i : ints) si.push(i);\n" + + " try {\n" + + " while(true) {\n" + + " System.out.print(\"[\"+si.pop()+\"]\");\n" + + " }\n" + + " } catch(EmptyStackException e) {\n" + + " System.out.println(\"[done]\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "[15][14][13][12][done]"); +} +// FIXME: javac8 rejects +public void test0921() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "Graph.java", + "class Node, E extends Edge> {\n" + + "}\n" + + "class Edge, E extends Edge> {\n" + + "}\n" + + "class Graph, E extends Edge>{\n" + + " N n;\n" + + " E e;\n" + + " private Graph(N n, E e) {\n" + + " this.n = n;\n" + + " this.e = e;\n" + + " }\n" + + " static , E extends Edge>\n" + + " Graph copy(Graph g) {\n" + + " return create(g.n,g.e);\n" + + " }\n" + + " static , E extends Edge>\n" + + " Graph create(N n, E e) {\n" + + " return new Graph(n,e);\n" + + " }\n" + + " Graph builder() {\n" + + " Graph g = null;\n" + + " return copy(g);\n" + + " }\n" + + "}\n", + }, + // javac options + this.complianceLevel < ClassFileConstants.JDK1_8 ? + (JavacTestOptions) JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 : + JavacTestOptions.DEFAULT/* javac test options */); +} +// Test case which comes from JDT/UI tests TypeEnvironmentTest.testWildcardAssignements +public void test0922() { + this.runNegativeTest( + new String[] { + "Test.java", + "import java.util.*;\n" + + "public class Test {\n" + + " List list_raw_list;\n" + + " {\n" + + " Collection> col = list_raw_list;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Test.java (at line 3)\n" + + " List list_raw_list;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in Test.java (at line 5)\n" + + " Collection> col = list_raw_list;\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to Collection>\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129129 +public void test0923() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " static void a(Class> c) {}\n" + + "\n" + + " static void b(X t) {\n" + + " X.a(t.getClass());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.a(t.getClass());\n" + + " ^\n" + + "The method a(Class>) in the type X is not applicable for the arguments (Class)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 +public void test0924() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "ExtendedOuter.java", + "class Outer {\n" + + " class Inner {\n" + + " }\n" + + "\n" + + " static void method(Outer.Inner x) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n" + + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new ExtendedOuter().new ExtendedInner();\n" + + " }\n" + + "}\n" + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test0925() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " private List toAdd;\n" + + "\n" + + " public X(List toAdd) {\n" + + " this.toAdd = toAdd;\n" + + " }\n" + + "\n" + + " private List getRelated(B b) {\n" + + " // some application logic\n" + + " // for demo\n" + + " return toAdd;\n" + + " }\n" + + "\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public , LF extends Factory> L addOrCreate4(\n" + + " B b, L l, LF lf) {\n" + + " if (l == null) {\n" + + " l = lf.create();\n" + + " }\n" + + " ((List) l).addAll(getRelated(b)); \n" + + " l.addAll(getRelated(b));\n" + + " return l;\n" + + " }\n" + + "\n" + + " public static class ListFactory implements Factory> {\n" + + " public List create() {\n" + + " return new ArrayList();\n" + + " }\n" + + " }\n" + + "\n" + + " public static interface Factory {\n" + + " public T create();\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " ListFactory lf = new ListFactory();\n" + + " List longs = new ArrayList();\n" + + " longs.add(new Long(1));\n" + + " X test = new X(longs);\n" + + " List ret4 = null;\n" + + " ret4 = test.addOrCreate4(1, ret4, lf);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10_b24 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 +public void test0926() { + String xSource = + "public class X {\n" + + " @SuppressWarnings(\"null\")\n" + + " public void foo() {\n" + + " NonTerminalSourcePart> RESULT = null;\n" + + " NonTerminalSourcePart> t = null;\n" + + " RESULT = NonTerminalSourcePart.create(Tuple.create(true, t.value().fst()));\n" + + " }\n" + + "}\n" + + "\n" + + "class Term {\n" + + "}\n" + + "\n" + + "class Formula {\n" + + "}\n" + + "\n" + + "final class NonTerminalSourcePart {\n" + + " static NonTerminalSourcePart create(final V _value) {\n" + + " return null;\n" + + " }\n" + + " final V value() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class Tuple {\n" + + " public static Tuple create(final A a, final B b) {\n" + + " return null;\n" + + " }\n" + + " public A fst() {\n" + + " return null;\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runNegativeTest( + new String[] { + "X.java", + xSource + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " RESULT = NonTerminalSourcePart.create(Tuple.create(true, t.value().fst()));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from NonTerminalSourcePart> to NonTerminalSourcePart>\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug6557661 /* javac test options */); + } else { + runConformTest( + new String[] { + "X.java", + xSource + }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0927() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "@SuppressWarnings(\"null\") public class X {\n" + + " public void foo() {\n" + + " List> RESULT = null;\n" + + " List lst = null;\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " }\n" + + " public void bar() {\n" + + " List> RESULT = null;\n" + + " List lst = null;\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " }\n" + + " public void baz() {\n" + + " List> RESULT = null;\n" + + " List lst = null;\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " }\n" + + " public void bar2(List lst) {\n" + + " List RESULT = null;\n" + + " RESULT = lst;\n" + + " RESULT = Collections.singletonList(lst.get(0));\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " List ls = new ArrayList();\n" + + " ls.add(\"str\");\n" + + " new X().bar2(ls);\n" + + " }\n" + + "}\n", + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " RESULT = Collections.singletonList(Collections.singletonList(lst.get(0)));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " RESULT = lst;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "5. ERROR in X.java (at line 21)\n" + + " RESULT = Collections.singletonList(lst.get(0));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " RESULT = lst;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n")); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0928() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " List x1 = new ArrayList();\n" + + " List x2 = new ArrayList();\n" + + " x1.addAll(x2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x1.addAll(x2);\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=117119 +// SHOULD FAIL AT 1.8 (18.2.3): The method allOf(Class) in the type X is not applicable for the arguments (Class) +public void test0929() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public static > void fails () {\n" + + " Class enumType = null;\n" + + " final Collection test = allOf(enumType);\n" + + "\n" + + " Collection colType = null;\n" + + " final Collection test2 = colType;\n" + + " }\n" + + " \n" + + " public static > Collection allOf(final Class enumType) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Class enumType = null;\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " final Collection test = allOf(enumType);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " final Collection test = allOf(enumType);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Collection needs unchecked conversion to conform to Collection\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " Collection colType = null;\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " final Collection test2 = colType;\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from Collection to Collection\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119238 +public void test0930() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int I;\n" + + " public void foo() {\n" + + " X.I= 10;\n" + + " }\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=119238 - variation +public void test0931() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int I;\n" + + " public void foo() {\n" + + " X.I= 10;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X.I= 10;\n" + + " ^\n" + + "Syntax error on token \"I\", VariableDeclaratorId expected after this token\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=119238 - variation +public void _test0932() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int Method() { return 0; }\n" + + " public void foo() {\n" + + " X.Method();\n" + + " }\n" + + " public void bar() {\n" + + " X.Method();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X.Method();\n" + + " ^^^^^^^^^^\n" + + "Syntax error on token(s), misplaced construct(s)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 +public void test0933() { + this.runNegativeTest( + new String[] { + "a/AbstractFoo.java", //================================ + "package a;\n" + + "public abstract class AbstractFoo> {\n" + + " protected static class Inner> {\n" + + " public Inner() {\n" + + " }\n" + + "\n" + + " public final void doSmth() {\n" + + " }\n" + + " }\n" + + "}\n", + "b/CustomFoo.java", //================================ + "package b;\n" + + "import a.AbstractFoo;\n" + + "public final class CustomFoo extends AbstractFoo {\n" + + " private Inner defaultInner;\n" + + "\n" + + " Inner getDefaultInner() {\n" + + " return (this.defaultInner == null)\n" + + " ? this.defaultInner = new Inner()\n" + + " : this.defaultInner;\n" + + " } \n" + + "\n" + + " private Inner customInner;\n" + + "\n" + + " Inner getCustomInner() {\n" + + " return (this.customInner == null)\n" + + " ? this.customInner = new Inner()\n" + + " : this.customInner;\n" + + " } \n" + + "}\n", + "b/DefaultFoo.java", //================================ + "package b;\n" + + "import a.AbstractFoo;\n" + + "public final class DefaultFoo extends AbstractFoo {\n" + + " private Inner defaultInner;\n" + + "\n" + + " Inner getDefaultInner() {\n" + + " return (this.defaultInner == null)\n" + + " ? this.defaultInner = new Inner()\n" + + " : this.defaultInner;\n" + + " } \n" + + "\n" + + " private Inner customInner;\n" + + "\n" + + " Inner getCustomInner() {\n" + + " return (this.customInner == null)\n" + + " ? this.customInner = new Inner()\n" + + " : this.customInner;\n" + + " }\n" + + "\n" + + " ///////////////////////////////////////////////////////////////////////\n" + + " public void testCompilationFailure(final CustomFoo foo) {\n" + + " final DefaultFoo foo1 = this;\n" + + " final CustomFoo foo2 = foo;\n" + + "\n" + + " // These get compiled w/o error:\n" + + " foo1.getCustomInner().doSmth();\n" + + " foo1.getDefaultInner().doSmth();\n" + + "\n" + + " // These do not (Eclipse 3.2.0 M4):\n" + + " foo2.getCustomInner().doSmth();\n" + + " foo2.getDefaultInner().doSmth();\n" + + "\n" + + " // Expect error\n" + + " String s11 = foo1.getCustomInner();\n" + + " String s12 = foo2.getDefaultInner();\n" + + " String s21 = foo2.getCustomInner();\n" + + " String s22 = foo2.getDefaultInner();\n" + + "\n" + + " // However, if we split statements, everything\'s ok: \n" + + " final Inner customInner2 = foo2.getCustomInner();\n" + + " customInner2.doSmth();\n" + + "\n" + + " final Inner defaultInner2 = foo2.getDefaultInner();\n" + + " defaultInner2.doSmth();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in b\\DefaultFoo.java (at line 34)\n" + + " String s11 = foo1.getCustomInner();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + + "----------\n" + + "2. ERROR in b\\DefaultFoo.java (at line 35)\n" + + " String s12 = foo2.getDefaultInner();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + + "----------\n" + + "3. ERROR in b\\DefaultFoo.java (at line 36)\n" + + " String s21 = foo2.getCustomInner();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + + "----------\n" + + "4. ERROR in b\\DefaultFoo.java (at line 37)\n" + + " String s22 = foo2.getDefaultInner();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from AbstractFoo.Inner to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 - variation +public void test0934() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " static class Inner {\n" + + " static class InInner {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " void foo() {\n" + + " Inner inner = null;\n" + + " String s = inner;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = inner;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from X.Inner to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 - variation +public void test0935() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " static class Inner {\n" + + " class InInner {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " void foo() {\n" + + " Inner.InInner inner = null;\n" + + " String s = inner;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = inner;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from X.Inner.InInner to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128063 - variation +public void test0936() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " class Inner {\n" + + " class InInner {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " void foo() {\n" + + " Inner inner = null;\n" + + " String s = inner;\n" + + " \n" + + " Inner.InInner inner2 = null;\n" + + " s = inner2;\n" + + "\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " String s = inner;\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from X.Inner to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " s = inner2;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from X.Inner.InInner to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 - variation +public void test0937() { + this.runNegativeTest( + new String[] { + "ExtendedOuter.java", //================================ + "class Outer {\n" + + " class Inner {}\n" + + "\n" + + " static void method(Outer.Inner x) {}\n" + + "}\n" + + "\n" + + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " Zork zk;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in ExtendedOuter.java (at line 4)\n" + + " static void method(Outer.Inner x) {}\n" + + " ^^^^^^^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "2. ERROR in ExtendedOuter.java (at line 14)\n" + + " Zork zk;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 - variation +public void test0938() { + this.runNegativeTest( + new String[] { + "ExtendedOuter.java", //================================ + "class Outer {\n" + + " class Inner {}\n" + + "\n" + + " static void method(Outer.Inner x) {}\n" + + "}\n" + + "\n" + + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " Zork zk;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in ExtendedOuter.java (at line 14)\n" + + " Zork zk;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 - variation +public void test0939() { + this.runNegativeTest( + new String[] { + "ExtendedOuter.java", //================================ + "class Outer {\n" + + " class Inner {}\n" + + "\n" + + " static void method(Outer.Inner x) {}\n" + + "}\n" + + "\n" + + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " Zork zk;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in ExtendedOuter.java (at line 14)\n" + + " Zork zk;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129190 - variation +// force check that I is inferred to E, not Object +public void test0939b() { + this.runNegativeTest( + new String[] { + "ExtendedOuter.java", //================================ + "class Outer {\n" + + " class Inner {}\n" + + "\n" + + " static I method(Outer.Inner x) { return null; }\n" + + "}\n" + + "\n" + + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this).bar();\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " Zork zk;\n" + + " }\n" + + "}\n" + + "class A { void bar() {} }\n", + }, + "----------\n" + + "1. ERROR in ExtendedOuter.java (at line 14)\n" + + " Zork zk;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0940() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "public class X {\n" + + " void bar3(List lst) {\n" + + " List RESULT = null;\n" + + " RESULT = lst; // 1\n" + + " RESULT = Collections.singletonList(lst.get(0)); // 2\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " RESULT = lst; // 1\n" + + " ^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "2. ERROR in X.java (at line 6)\n" + + " RESULT = Collections.singletonList(lst.get(0)); // 2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + : + "")); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0941() { + String xSource = + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Map foo(T t1, T t2) {\n" + + " return null;\n" + + " }\n" + + " void bar(U u, V v) {\n" + + " Map map1 = foo(u, v);\n" + + " Map map2 = foo(u, v);\n" + + " } \n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Map map1 = foo(u, v);\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from Map to Map\n" + + "----------\n"); + } else { + runConformTest(new String[] { "X.java", xSource }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0942() { + String xSource = + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Map foo(T t1, T t2, T t3) {\n" + + " return null;\n" + + " }\n" + + " void bar(U u, V v) {\n" + + " Map map1 = foo(u, v, null);\n" + + " Map map2 = foo(u, v, null);\n" + + " } \n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Map map1 = foo(u, v, null);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Map to Map\n" + + "----------\n"); + } else { + runConformTest(new String[] { "X.java", xSource }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0943() { + String xSource = + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Map foo(T t1, T t2, T t3) {\n" + + " return null;\n" + + " }\n" + + " void bar(U u, V v, List lv) {\n" + + " Map map1 = foo(u, v, lv.get(0));\n" + + " Map map2 = foo(u, v, lv.get(0));\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Map map1 = foo(u, v, lv.get(0));\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Map to Map\n" + + "----------\n"); + } else { + runConformTest(new String[] { "X.java", xSource }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129996 +public void test0944() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "public class X {\n" + + " public static Set method(List list) {\n" + + " return new HashSet();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " ArrayList l = new ArrayList();\n" + + " Set s1 = method(l);\n" + + " Set s2 = (Set) method(l);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Set s2 = (Set) method(l);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Set to Set\n" + + "----------\n"); +} +public void test0945() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args){\n" + + " Object[] objArray = {new Object()};\n" + + " ArrayList strList = new ArrayList();\n" + + " transferBug(objArray, strList);\n" + + " String str = strList.get(0);\n" + + "}\n" + + "public static void transferBug(Var[] src, Collection dest){\n" + + " dest.add(src[0]);\n" + + "}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " transferBug(objArray, strList);\n" + + " ^^^^^^^^^^^\n" + + "The method transferBug(Var[], Collection) in the type X is not applicable for the arguments (Object[], ArrayList)\n" + + "----------\n"); +} +public void test0946() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", //================================ + "public class X {\n" + + " public static void main(String[] args) {\n" + + " operate(Operations.create());\n" + + " }\n" + + " static > void operate(Operators operators) {\n" + + " System.out.println(operators.spawn());\n" + + " }\n" + + "}\n" + + "class Operations {\n" + + " static Operators create() {\n" + + " return new IntOperators();\n" + + " }\n" + + "}\n" + + "interface Num {\n" + + " public O spawn();\n" + + "}\n" + + "class Int implements Num {\n" + + " public Int spawn() {\n" + + " return new Int();\n" + + " }\n" + + " public String toString() {\n" + + " return \"Int\";\n" + + " }\n" + + "}\n" + + "interface Operators> {\n" + + " O spawn();\n" + + "}\n" + + "class IntOperators implements Operators {\n" + + " public Int spawn() {\n" + + " return new Int();\n" + + " }\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "Int" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0947() { + String xSource = + "public class X {\n" + + " public void bar2(Box b) {\n" + + " Box bx = box(b.element);\n" + + " box(b.element).element.run();\n" + + " }\n" + + " static Box box(U u) {\n" + + " return new Box(u);\n" + + " }\n" + + "}\n" + + "class Box {\n" + + " E element;\n" + + " Box(E element) {\n" + + " this.element = element;\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Box bx = box(b.element);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Box to Box\n" + + "----------\n", + JavacTestOptions.EclipseHasABug.EclipseBug236236); + } else { + runConformTest(new String[]{ "X.java", xSource }); + } + +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 - variation +public void test0948() { + this.runConformTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "public class X {\n" + + " public void bar2(Box b1, Box b2) {\n" + + " Pair blist = pair(b1.element, b2.element);\n" + + " }\n" + + " static Pair pair(U u1, U u2) {\n" + + " return new Pair(u1,u2);\n" + + " }\n" + + "}\n" + + "class Pair {\n" + + " Pair(E e, F f){}\n" + + "}\n" + + "class Box {\n" + + " E element;\n" + + " Box(E element) {\n" + + " this.element = element;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128418 +public void test0949() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " public Iterable m(T... ts) {\n" + + " return Arrays.asList(ts);\n" + + " }\n" + + " public void m3(Iterable... ts) {\n" + + " }\n" + + " public void m2() {\n" + + " m3(m(3, 3, 3));\n" + + " m3(m());\n" + + " m3(m(new Object[]{}));\n" + + " Zork z;\n" + + " }\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 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 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 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" + + "1. WARNING in X.java (at line 4)\n" + + " public Iterable 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 void m3(Iterable... 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 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 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 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() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " public Iterable m(T[]... ts) {\n" + + " return Arrays.asList(ts[0]);\n" + + " }\n" + + " public void m3(Iterable... ts) {\n" + + " }\n" + + " public void m2() {\n" + + " m3(m(new Integer[]{3, 3, 3}));\n" + + " m3(m());\n" + + " m3(m(new Object[][]{}));\n" + + " Zork z;\n" + + " }\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 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 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 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" + + "1. WARNING in X.java (at line 4)\n" + + " public Iterable 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 void m3(Iterable... 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" + + (this.complianceLevel == ClassFileConstants.JDK1_7? + "Type safety: A generic array of Iterable is created for a varargs parameter\n" + : + "Type safety: A generic array of Iterable 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 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 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() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " public Iterable m(T[]... ts) {\n" + + " return Arrays.asList(ts[0]);\n" + + " }\n" + + " public void m3(Iterable... ts) {\n" + + " }\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public void m2() {\n" + + " m3(m(new Integer[]{3, 3, 3}));\n" + + " m3(m());\n" + + " m3(m(new Object[][]{}));\n" + + " Zork z;\n" + + " }\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" + + "1. WARNING in X.java (at line 4)\n" + + " public Iterable 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 void m3(Iterable... 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() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public Iterable m(T... ts) {\n" + + " return null;\n" + + " }\n" + + " public void m3(Iterable... ts) {\n" + + " }\n" + + " public void m2() {\n" + + " m3(m(null));\n" + + " Zork z;\n" + + " }\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 is created for a varargs parameter\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " m3(m(null));\n" + + " ^^^^^^^\n" + + "Type null of the last argument to method m(Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public Iterable 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 void m3(Iterable... 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 is created for a varargs parameter\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " m3(m(null));\n" + + " ^^^^^^^\n" + + "Type null of the last argument to method m(Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type 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", //================================ + "import java.lang.ref.WeakReference;\n" + + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void m(WeakReference ref) {\n" + + " List> list= Arrays.asList(ref);\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " List> list= Arrays.asList(ref);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of WeakReference is created for a varargs parameter\n" + + "----------\n" + + "2. 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=130543 +public void test0954() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " class Member {}\n" + + " static class SMember {}\n" + + " void foo1() {\n" + + " X[] xs = new X[]{};//1\n" + + " for(X x : xs) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + " void bar1() {\n" + + " Member[] members = new Member[]{};//2\n" + + " for(Member m : members) {\n" + + " System.out.println(m);\n" + + " }\n" + + " }\n" + + " void bas1() {\n" + + " SMember[] members = new SMember[]{};//3\n" + + " for(SMember m : members) {\n" + + " System.out.println(m);\n" + + " }\n" + + " }\n" + + " void baz1() {\n" + + " class Local{}\n" + + " Local[] locals = new Local[]{};//4\n" + + " for(Local l : locals) {\n" + + " System.out.println(l);\n" + + " }\n" + + " }\n" + + " void foo2() {\n" + + " X[] xs = new X[5];//5\n" + + " for(X x : xs) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + " void bar2() {\n" + + " Member[] members = new Member[5];//6\n" + + " for(Member m : members) {\n" + + " System.out.println(m);\n" + + " }\n" + + " }\n" + + " void bas2() {\n" + + " SMember[] members = new SMember[5];//7\n" + + " for(SMember m : members) {\n" + + " System.out.println(m);\n" + + " }\n" + + " }\n" + + " void baz2() {\n" + + " class Local{}\n" + + " Local[] locals = new Local[5];//8\n" + + " for(Local l : locals) {\n" + + " System.out.println(l);\n" + + " }\n" + + " }\n" + + " void foo3() {\n" + + " X[] xs = new X[5];//9\n" + + " for(X x : xs) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + " void bar3() {\n" + + " X.Member[] members = new X.Member[5];//10\n" + + " for(X.Member m : members) {\n" + + " System.out.println(m);\n" + + " }\n" + + " }\n" + + " static void baz3() {\n" + + " class Local{}\n" + + " Local[] locals = new Local[5];//11\n" + + " for(Local l : locals) {\n" + + " System.out.println(l);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " Member[] members = new Member[]{};//2\n" + + " ^^\n" + + "Cannot create a generic array of X.Member\n" + + "----------\n" + + "2. ERROR in X.java (at line 26)\n" + + " Local[] locals = new Local[]{};//4\n" + + " ^^\n" + + "Cannot create a generic array of Local\n" + + "----------\n" + + "3. ERROR in X.java (at line 38)\n" + + " Member[] members = new Member[5];//6\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X.Member\n" + + "----------\n" + + "4. ERROR in X.java (at line 51)\n" + + " Local[] locals = new Local[5];//8\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of Local\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105049 +public void test0955() { + String errorlog = this.complianceLevel >= ClassFileConstants.JDK16 ? + " ^\n" + + "Type Object cannot be safely cast to List[]\n" + : + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List[]. Use the form List[] instead since further generic type information will be erased at runtime\n"; + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.List;\n" + + "public class X {\n" + + " void method(Object o) {\n" + + " if (o instanceof List[]) { //incorrect: bug 104695\n" + + " List[] es= (List[]) o; //unchecked\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o instanceof List[]) { //incorrect: bug 104695\n" + + errorlog + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " List[] es= (List[]) o; //unchecked\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List[]\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130128 +public void test0956() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + "\n" + + " public void printNickname(Person person) {\n" + + " Person.Nickname nickname = person.getNickname();\n" + + " System.out.println(nickname);\n" + + " }\n" + + "\n" + + " static class Person {\n" + + " private Nickname nickname;\n" + + "\n" + + " public Nickname getNickname() {\n" + + " return nickname;\n" + + " }\n" + + "\n" + + " public void setNickname(Nickname nickname) {\n" + + " this.nickname = nickname;\n" + + " }\n" + + "\n" + + " class Nickname {\n" + + " private String name;\n" + + " private boolean insulting;\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=132348 +public void test0957() { + this.runNegativeTest( + new String[] { + "AnyInterface.java", //================================ + "public interface AnyInterface {\n" + + " public void doSomething();\n" + + "}", + "UsingGenericsClass", + "public class UsingGenericsClass {\n" + + " public UsingGenericsClass(){\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in UsingGenericsClass (at line 1)\n" + + " public class UsingGenericsClass {\n" + + " ^^^^^^^^^^^^\n" + + "Cannot specify any additional bound AnyInterface when first bound is a type parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=131935 +public void test0958() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.lang.ref.ReferenceQueue;\n" + + "import java.lang.ref.SoftReference;\n" + + "import java.util.Hashtable;\n" + + "\n" + + "public class X {\n" + + " private static final Hashtable cache = new Hashtable();\n" + + "\n" + + " private static final ReferenceQueue trash = new ReferenceQueue();\n" + + "\n" + + " private static final class Soft extends SoftReference {\n" + + " int key;\n" + + "\n" + + " Soft() {\n" + + " super(null);\n" + + " }\n" + + " }\n" + + "\n" + + " final Thread clean = new Thread(\"BigTableModel cleaner\") {\n" + + " @Override\n" + + " public void run() {\n" + + " for (;;)\n" + + " try {\n" + + " cache.remove(((Soft) trash.remove()).key);\n" + + " } catch (final InterruptedException e) {\n" + + " return;\n" + + " }\n" + + " Zork z;\n" + + " }\n" + + " };\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 27)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133803 +public void test0959() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.lang.ref.*;\n" + + "\n" + + "class Soft extends SoftReference {\n" + + " Soft() { super(null); }\n" + + "}\n" + + "\n" + + "class Bug {\n" + + " void m(Reference remove) {\n" + + " Soft soft= (Soft) remove;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Soft soft= (Soft) remove;\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot cast from Reference to Soft\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118273 +// SHOULD FAIL AT 1.8 (RET): Type mismatch: cannot convert from X>> to X +public void test0960() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " > X newInstance() {\n" + + " return new X();\n" + + " }\n" + + "\n" + + " X[] bugDemo() {\n" + + " X x = newInstance();\n" + + " return new X[] { x };\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " X x = newInstance();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\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[]\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118273 - variation +public void test0961() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " > B newInstance2(X xb) {\n" + + " return null;\n" + + " }\n" + + " void foo() {\n" + + " X x = new X();\n" + + " Comparable c = newInstance2(x);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " Comparable c = newInstance2(x);\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " Comparable c = newInstance2(x);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation newInstance2(X) of the generic method newInstance2(X) of type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " Comparable c = newInstance2(x);\n" + + " ^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + : "Type safety: The expression of type X needs unchecked conversion to conform to X>>\n") + + "----------\n" + + "6. 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=134645 +public void test0962() { + runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public void bug() throws Exception {\n" + + " throw new Exception(\"Bug134645\") {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"Bug134645\";\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " throw new Exception(\"Bug134645\") {\n" + + " ^^^^^^^^^\n" + + "The generic class new Exception(){} may not subclass java.lang.Throwable\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " throw new Exception(\"Bug134645\") {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "The serializable class does not declare a static final serialVersionUID field of type long\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134645 - variation +public void test0963() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public void bug() throws Exception {\n" + + " throw new Exception(\"Bug134645\") {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"Bug134645\";\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134645 - variation +public void test0964() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public static void bug() throws Exception {\n" + + " throw new Exception(\"Bug134645\") {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"Bug134645\";\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=97494 +public void test0965() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " protected static final Class> theClass = (Class>) X.class;\n" + + " void foo(Class cx) {\n" + + " Class> cx1 = cx;\n" + + " Class> cx2 = (Class>) cx;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " protected static final Class> theClass = (Class>) X.class;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Class to Class>\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " void foo(Class cx) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Class> cx1 = cx;\n" + + " ^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Class> cx2 = (Class>) cx;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115918 +public void test0966() { + this.runConformTest( + new String[] { + "Child.java", //================================ + "public class Child extends Parent implements Comparable {\n" + + " public int compareTo(Child o) { return 0; }\n" + + "}\n" + + "class Parent extends Base {}\n" + + "class Base {}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=81949 +public void test0967() { + this.runConformTest( + new String[] { + "CSS.java", //================================ + "interface Ac,A extends Ac> {}\n" + + "interface St,A extends Ac> {}\n" + + "class CSN extends CSS implements Ac, CSN> {}\n" + + "public class CSS implements St, CSN> {}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108045 +public void test0968() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.*;\n" + + "public class X extends ArrayList implements I {\n" + + "}\n" + + "interface I extends Collection {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X extends ArrayList implements I {\n" + + " ^\n" + + "The interface Collection cannot be implemented more than once with different arguments: Collection and Collection\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " public class X extends ArrayList implements I {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " interface I extends Collection {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133071 +public void test0969() { + this.runConformTest( + new String[] { + "B.java", //================================ + "class B extends A {}\n" + + "class C extends B {}\n" + + "class A {}" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=136946 +public void test0970() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public interface X { \n" + + " interface I1 extends X {\n" + + " interface I2 extends I1 {\n" + + " }\n" + + "\n" + + " interface I3 extends I1 {\n" + + " }\n" + + "\n" + + " interface I4 extends I1.I2, I1.I3 { \n" + + " }\n" + + " }\n" + + "}\n" + + "class XSub implements X {\n" + + " I1 i1 = null;\n" + + " I1.I2 i2 = null;\n" + + " I1.I2 i1i2 = null;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " I1.I2 i1i2 = null;\n" + + " ^^^^^^^^\n" + + "The member type X.I1.I2 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.I1\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=136946 - variation +public void test0971() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public interface X { \n" + + " interface I1 extends X {\n" + + " interface I2 extends I1 {\n" + + " }\n" + + "\n" + + " interface I3 extends I1 {\n" + + " }\n" + + "\n" + + " interface I4 extends I1.I2, I1.I3 { \n" + + " }\n" + + " }\n" + + "}\n" + + "class XSub implements X {\n" + + " I1 i1 = null;\n" + + " I1.I2 i2 = null;\n" + + " I1.I2 i1i2 = null;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " interface I1 extends X {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " interface I2 extends I1 {\n" + + " ^^\n" + + "X.I1 is a raw type. References to generic type X.I1 should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " interface I3 extends I1 {\n" + + " ^^\n" + + "X.I1 is a raw type. References to generic type X.I1 should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " interface I4 extends I1.I2, I1.I3 { \n" + + " ^^^^^\n" + + "X.I1.I2 is a raw type. References to generic type X.I1.I2 should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " interface I4 extends I1.I2, I1.I3 { \n" + + " ^^^^^\n" + + "X.I1.I3 is a raw type. References to generic type X.I1.I3 should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 14)\n" + + " I1 i1 = null;\n" + + " ^^\n" + + "X.I1 is a raw type. References to generic type X.I1 should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 15)\n" + + " I1.I2 i2 = null;\n" + + " ^^^^^\n" + + "X.I1.I2 is a raw type. References to generic type X.I1.I2 should be parameterized\n" + + "----------\n" + + "8. ERROR in X.java (at line 16)\n" + + " I1.I2 i1i2 = null;\n" + + " ^^^^^^^^\n" + + "The member type X.I1.I2 cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type X.I1\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=137203 +// simulate incremental compile +public void test0972() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {}\n" + + "\n" + + " public static void method(Outer.Inner x) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner x = null;\n" + + " method(x);\n" + + " }\n" + + "}\n" + + "\n", + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + "}\n" + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + + this.runConformTest( + new String[] { + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {}\n" + + "\n" + + " public static void method(Outer.Inner x) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner x = null;\n" + + " method(x);\n" + + " }\n" + + "}\n" + + "\n", + }, + "SUCCESS", + null, + false, + null); + this.runConformTest( + new String[] { + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + }, + "SUCCESS", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=137203 - variation +//pure source scenario +public void test0973() { + this.runConformTest( + new String[] { + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {}\n" + + "\n" + + " public static void method(Outer.Inner x) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner x = null;\n" + + " method(x);\n" + + " }\n" + + "}\n" + + "\n", + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=137203 - variation +//simulate incremental compile +public void test0974() { + this.runConformTest( + new String[] { + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {}\n" + + "\n" + + " public static void method(Outer.Inner x) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner x = null;\n" + + " method(x);\n" + + " }\n" + + "}\n" + + "\n", + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " {\n" + + " Outer.Inner in;\n" + + " Outer.method(this);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + }, + "SUCCESS", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122999 +public void test0975() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "import java.util.ArrayList;\n" + + "\n" + + "public class X extends ArrayList {\n" + + " public static class Bean {}\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X extends ArrayList {\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 3)\n" + + " public class X extends ArrayList {\n" + + " ^^^^\n" + + "Bean cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139525 +public void test0976() { + this.runConformTest( + new String[] { + "S.java", // ================= + "import java.util.Collection;\n" + + "public class S {\n" + + " public static void cow(IDA s) {\n" + + " Collection ids = s.getIds(); // Error here\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + "ID.java", // ================= + "import java.util.Collection;\n" + + "public interface ID {\n" + + " Collection> getIds();\n" + + "}\n", // ================= + "IDA.java", // ================= + "import java.util.Collection;\n" + + "public interface IDA extends ID {\n" + + " enum Enum1 {\n" + + " ONE, TWO\n" + + " }\n" + + " Collection getIds();\n" + + "}\n", // ================= + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "S.java", // ================= + "import java.util.Collection;\n" + + "public class S {\n" + + " public static void cow(IDA s) {\n" + + " Collection ids = s.getIds(); // Error here\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS2\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS2", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139619 +public void test0977() { + this.runConformTest( + new String[] { + "MMTPProtocol.java", // ================= + "import java.io.InputStream;\n" + + "import java.util.HashSet;\n" + + "import bug.ProtocolManager;\n" + + "abstract class AbstractProtocol implements ProtocolManager {\n" + + " public AbstractProtocol(HashSet manager, String grp) {}\n" + + " AbstractProtocol(){} \n" + + " public void connect(ConnectType type) { }\n" + + "}\n" + + "public abstract class MMTPProtocol extends AbstractProtocol {\n" + + " public void connect(ConnectType type) {}\n" + + "}\n", // ================= + "bug/ProtocolManager.java", // ================= + "package bug;\n" + + "public interface ProtocolManager{\n" + + " public enum ConnectType {Client,Server}\n" + + " public void connect(ConnectType type) ;\n" + + " public boolean receive(R input) throws Exception;\n" + + "}", // ================= + }, + ""); + this.runConformTest( + new String[] { + "MMTPProtocol.java", // ================= + "import java.io.InputStream;\n" + + "import java.util.HashSet;\n" + + "import bug.ProtocolManager;\n" + + "abstract class AbstractProtocol implements ProtocolManager {\n" + + " public AbstractProtocol(HashSet manager, String grp) {}\n" + + " AbstractProtocol(){} \n" + + " public void connect(ConnectType type) { }\n" + + "}\n" + + "public abstract class MMTPProtocol extends AbstractProtocol {\n" + + " public void connect(ConnectType type) {}\n" + + "}\n", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139669 +public void test0978() { + this.runConformTest( + new String[] { + "B.java", // ================= + "public class B implements A {\n" + + " public void foo(A.C c) {}\n" + + "}", // ================= + "A.java", // ================= + "public interface A {\n" + + " void foo(A.C c);\n" + + " class C {}\n" + + "}", // ================= + }, + ""); + this.runConformTest( + new String[] { + "A.java", // ================= + "public interface A {\n" + + " void foo(A.C c);\n" + + " class C {}\n" + + "}", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139669 +public void test0979() { + this.runConformTest( + new String[] { + "B.java", // ================= + "public class B extends A {\n" + + " @Override\n" + + " public void foo(A.C c) {}\n" + + "}", // ================= + "A.java", // ================= + "public class A {\n" + + " public void foo(A.C c) {}\n" + + " public static class C {}\n" + + "}", // ================= + }, + ""); + this.runConformTest( + new String[] { + "A.java", // ================= + "public class A {\n" + + " public void foo(A.C c) {}\n" + + " public static class C {}\n" + + "}", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140772 +public void test0980() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.Collections;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + " public Set keySet() {\n" + + " return Collections. emptySet();\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140569 +//simulate incremental compile +public void test0981() { + this.runConformTest( + new String[] { + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {}\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n", + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " public void method(){\n" + + " Worker.method(this);\n" + + " }\n" + + " }\n" + + "}\n", + "Worker.java", //================================ + "public class Worker {\n" + + " public static void method(Outer.Inner i) {}\n" + + "}\n", //================================ + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " public void method(){\n" + + " Worker.method(this);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", //================================ + }, + "SUCCESS", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140569 +//simulate incremental compile +public void test0982() { + this.runConformTest( + new String[] { + "Outer.java", //================================ + "//Outer.java\n" + + "public class Outer {\n" + + " public class Inner {\n" + + " public class Inner2 {}\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "\n", + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " class ExtendedInner2 extends Inner2 {\n" + + " public void method(){\n" + + " Worker.method(this);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + "Worker.java", //================================ + "public class Worker {\n" + + " public static void method(Outer.Inner.Inner2 i) {}\n" + + "}\n", //================================ + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "ExtendedOuter.java", //================================ + "public class ExtendedOuter extends Outer {\n" + + " class ExtendedInner extends Inner {\n" + + " class ExtendedInner2 extends Inner2 {\n" + + " public void method(){\n" + + " Worker.method(this);\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", //================================ + }, + "SUCCESS", + null, + false, + null); +} +public void test0983() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " List l1 = new ArrayList();\n" + + " List l2 = new ArrayList();\n" + + " l1.addAll(l2);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " l1.addAll(l2);\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n"); +} +// generic inner class within a non generic one +public void test0984() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public class XX {}\n" + + "}", + "I.java", + "public interface I {\n" + + " X.XX foo();\n" + + "}", + "Y.java", + "public class Y extends X implements I {\n" + + " public XX foo() {\n" + + " return null;\n" + + " }\n" + + "}", + }, + // runtime results + "" /* expected output string */); + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "Y.java", + "public class Y extends X implements I {\n" + + " public XX foo() {\n" + + " return null;\n" + + " }\n" + + "}", + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//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", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " public void testBreak() {\n" + + " List> lco = Arrays.asList(String.class, Integer.class, Long.class);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " List> lco = Arrays.asList(String.class, Integer.class, Long.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List")+">> to List>\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=91709 +public void test0986() { + this.runConformTest( + new String[] { + "T.java", // ================= + "public class T {\n" + + " public T() {\n" + + " S s = new S();\n" + + " s.setObj(\"S\");\n" + + " System.out.print(s.getObj());\n" + + " S i = new S();\n" + + " i.setObj(new Integer(100));\n" + + " System.out.print(i.getObj());\n" + + " S m = new S();\n" + + " m.setObj(new MyClass(\"[Terry]\"));\n" + + " System.out.print(m.getObj());\n" + + " S x = new S(new MyClass(\"[Corbet]\"));\n" + + " System.out.print(x.getObj());\n" + + " } // End of Constructor for T.\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new T();\n" + + " System.out.println(\"SUCCESS\");\n" + + " } catch (Exception ex) {\n" + + " ex.printStackTrace();\n" + + " }\n" + + " } // End of main().\n" + + "\n" + + " class MyClass {\n" + + " private String str;\n" + + " public MyClass(String str) {\n" + + " this.str = str;\n" + + " } // End of Constructor for MyClass.\n" + + " @Override\n" + + " public String toString() {\n" + + " return (\"MyClass = \" + str);\n" + + " } // End of toString().\n" + + " } // End of Embedded MyClass Class.\n" + + "} // End of T Class.\n", // ================= + "S.java", // ================= + "public class S<$T> extends B<$T> {\n" + + " public S() {\n" + + " super();\n" + + " } // End of Constructor for S.\n" + + " public S($T obj) {\n" + + " super(obj);\n" + + " } // End of Constructor for S.\n" + + "} // End of S Class.\n", // ================= + "B.java", // ================= + "public abstract class B<$T> {\n" + + " $T obj;\n" + + " public B() {\n" + + " ;\n" + + " } // End of Constructor for B.\n" + + " public B($T obj) {\n" + + " this.obj = obj;\n" + + " } // End ofg Constructor of B.\n" + + " public $T getObj() {\n" + + " return (obj);\n" + + " } // End of getObj().\n" + + " public void setObj($T obj) {\n" + + " this.obj = obj;\n" + + " } // End of setObj().\n" + + "} // End of B Class.", // ================= + + }, + "S100MyClass = [Terry]MyClass = [Corbet]SUCCESS"); +} +// 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 7)\n" + + " abstract class GLinkElementView extends AbstractLinkView {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return types are incompatible for the inherited methods EditPart.getViewer(), AbstractLinkView.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 must override a superclass method\n" + + "----------\n" + : "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " abstract class GLinkElementView extends AbstractLinkView {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return types are incompatible for the inherited methods EditPart.getViewer(), AbstractLinkView.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[] { + "X.java",//=================== + "public class X {\n" + + " void bar(GLinkElementView g) {\n" + + " g.getViewer();\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class GLinkElementView extends AbstractLinkView {}\n" + + "\n" + + "abstract class AbstractLinkView extends AbstractConnectionEditPart implements ILinkViewElement {\n" + + " @Override\n" + + " public ISheetViewer getViewer() { return null; } \n" + + "}\n" + + "\n" + + "abstract class AbstractConnectionEditPart implements EditPart {}\n" + + "\n" + + "abstract class AbstractEditPart implements EditPart {\n" + + " public EditPartViewer getViewer() { return null; }\n" + + "}\n" + + "\n" + + "interface ILinkViewElement {\n" + + " public ISheetViewer getViewer();\n" + + "}\n" + + "\n" + + "interface ISheetViewer {}\n" + + "\n" + + "interface EditPart {\n" + + " EditPartViewer getViewer();\n" + + "}\n" + + "\n" + + "interface EditPartViewer {}\n", // ================= + }, + expectedOutput); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 - variation +public void test0988() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " void bar(GLinkElementView g) {\n" + + " g.getViewer();\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class GLinkElementView extends AbstractLinkView {}\n" + + "\n" + + "abstract class AbstractLinkView extends AbstractConnectionEditPart implements ILinkViewElement, IModelChangeListener {\n" + + " @Override\n" + + " public SheetViewer getViewer() { return null; } \n" + + "}\n" + + "\n" + + "abstract class AbstractConnectionEditPart extends AbstractGraphicalEditPart implements ConnectionEditPart {}\n" + + "\n" + + "abstract class AbstractGraphicalEditPart extends AbstractEditPart implements GraphicalEditPart {}\n" + + "\n" + + "abstract class AbstractEditPart implements EditPart {\n" + + " public EditPartViewer getViewer() { return null; }\n" + + "}\n" + + "\n" + + "interface ILinkViewElement extends INodeViewElement {\n" + + " public ISheetViewer getViewer();\n" + + "}\n" + + "\n" + + "class SheetViewer implements ISheetViewer {}\n" + + "\n" + + "interface ISheetViewer {}\n" + + "\n" + + "interface EditPart {\n" + + " EditPartViewer getViewer();\n" + + "}\n" + + "\n" + + "interface ConnectionEditPart extends GraphicalEditPart {}\n" + + "interface GraphicalEditPart extends EditPart {}\n" + + "interface EditPartViewer {}\n" + + "interface IModelChangeListener {}\n" + + "\n" + + "interface INodeViewElement {\n" + + " public ISheetViewer getViewer();\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " abstract class GLinkElementView extends AbstractLinkView {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return types are incompatible for the inherited methods EditPart.getViewer(), AbstractLinkView.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 +public void test0989() { + this.runNegativeTest( + new String[] { + "Child.java",//=================== + "public class Child extends Parent {}\n" + + "abstract class Parent extends Grandparent implements IParent {}\n" + + "interface IParent extends IGrandparent {}\n" + + "abstract class Grandparent implements IGrandparent {}\n" + + "interface IGrandparent {}", // =================, // ================= + }, + "----------\n" + + "1. ERROR in Child.java (at line 2)\n" + + " abstract class Parent extends Grandparent implements IParent {}\n" + + " ^^^^^^\n" + + "The interface IGrandparent cannot be implemented more than once with different arguments: IGrandparent and IGrandparent\n" + + "----------\n" + + "2. WARNING in Child.java (at line 2)\n" + + " abstract class Parent extends Grandparent implements IParent {}\n" + + " ^^^^^^^\n" + + "IParent is a raw type. References to generic type IParent should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation +public void test0990() { + this.runNegativeTest( + new String[] { + "Child.java",//=================== + "public class Child extends Parent {}\n" + + "abstract class Parent extends Grandparent implements IParent {}\n" + + "interface IParent extends IGrandparent {}\n" + + "abstract class Grandparent implements IGrandparent {}\n" + + "interface IGrandparent {}", // =================, // ================= + }, + "----------\n" + + "1. ERROR in Child.java (at line 1)\n" + + " public class Child extends Parent {}\n" + + " ^^^^^\n" + + "The hierarchy of the type Child is inconsistent\n" + + "----------\n" + + "2. ERROR in Child.java (at line 2)\n" + + " abstract class Parent extends Grandparent implements IParent {}\n" + + " ^^^^^^^\n" + + "The type Parent cannot extend or implement IParent. A supertype may not specify any wildcard\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation +public void test0991() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "public class X extends SX implements IX {}\n" + + "class SX extends TX implements IX {}\n" + + "class TX implements IX {}\n" + + "interface IX {}\n", // =================, // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends SX implements IX {}\n" + + " ^\n" + + "The interface IX cannot be implemented more than once with different arguments: IX and IX\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " class SX extends TX implements IX {}\n" + + " ^^\n" + + "The interface IX cannot be implemented more than once with different arguments: IX and IX\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation +public void test0992() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "import java.util.*;\n" + + "public abstract class X implements Collection, I {\n" + + " \n" + + " void foo() {\n" + + " this.add(new Object());\n" + + " this.add(null);\n" + + " }\n" + + "}\n" + + "interface I extends Collection {\n" + + "}\n", // =================, // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public abstract class X implements Collection, I {\n" + + " ^\n" + + "The interface Collection cannot be implemented more than once with different arguments: Collection and Collection\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " public abstract class X implements Collection, I {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " this.add(new Object());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " this.add(null);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type Collection. References to generic type Collection should be parameterized\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142897 +public void test0993() { + runConformTest( + true, + new String[] { + "X.java",//=================== + "public class X {\n" + + " public class Inner {\n" + + " Inner() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new ATest();\n" + + " }\n" + + "}\n" + + "\n" + + "class ATest {\n" + + " public ATest() {\n" + + " T instance = makeInstance();\n" + + " X.Inner peq = instance.new Inner(); //**\n" + + " }\n" + + "\n" + + " private T makeInstance() {\n" + + " return (T) new X();\n" + + " }\n" + + "}", // ================= + }, + null, + "SUCCESS", + null, + JavacTestOptions.JavacHasABug.JavacBug6569404); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142897 - variation +public void test0994() { + this.runConformTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " public class Inner {\n" + + " Inner() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " void foo(boolean b, X1 x1, X2 x2) {\n" + + " (b ? x1 : x2).new Inner();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(true, new X1(), new X2());\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 extends X implements Comparable {\n" + + " public int compareTo(X1 other) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class X2 extends X implements Comparable {\n" + + " public int compareTo(X2 other) {\n" + + " return 0;\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142964 +public void _test0995() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " public class Inner {\n" + + " }\n" + + " void foo(boolean b, X1 x1, X2 x2) {\n" + + " Comparable cx1 = b ? x1 : x2;\n" + + " Comparable cx2 = b ? x1 : x2;\n" + + " String s = b ? x1 : x2;\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class X1 extends X implements Comparable {}\n" + + "abstract class X2 extends X implements Comparable {}", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=143793 +public void test0996() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " private T aObject = null;\n" + + " public static List castList(final List pList, final Class pClass) {\n" + + " final List result = new ArrayList();\n" + + " for (Object o:pList) {\n" + + " if (pClass.isInstance(o)) {\n" + + " result.add(pClass.cast(o));\n" + + " }\n" + + " }\n" + + " return result;\n" + + " }\n" + + "\n" + + " public static void main(final String[] pArgs) {\n" + + " final List l1 = new ArrayList();\n" + + " l1.add(new X());\n" + + " l1.add(new X());\n" + + " final List> l2 = castList(l1, List.class);\n" + + " \n" + + " List l3 = l2;\n" + + " List> l4 = null;\n" + + " l3 = l4;\n" + + " }\n" + + "\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " final List> l2 = castList(l1, List.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List>\n" + + "----------\n" + + "2. WARNING in X.java (at line 22)\n" + + " List l3 = l2;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 22)\n" + + " List l3 = l2;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n" + + "4. ERROR in X.java (at line 24)\n" + + " l3 = l4;\n" + + " ^^\n" + + "Type mismatch: cannot convert from List> to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142897 - variation +public void test0997() { + runConformTest( + true, + new String[] { + "X.java",//=================== + "public class X implements Outer {\n" + + " public static void main(String[] args) {\n" + + " new ATest();\n" + + " }\n" + + "}\n" + + "interface Outer {\n" + + " public class Inner {\n" + + " Inner() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class ATest {\n" + + " public ATest() {\n" + + " Outer.Inner peq = new T.Inner(); //**\n" + + " }\n" + + "\n" + + " private T makeInstance() {\n" + + " return (T) new X();\n" + + " }\n" + + "}", // ================= + }, + null, + "SUCCESS", + null, + JavacTestOptions.JavacHasABug.JavacBug6569404); +} +//regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=144261 +public void test0998() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " static abstract class Generic {\n" + + " static class Inner {\n" + + " static class InnerInner { }\n" + + " InnerInner createTableModel() {\n" + + " return new InnerInner();\n" + + " }\n" + + " }\n" + + " }\n" + + " static class SubGeneric extends Generic {\n" + + " static class SubInner extends Inner {\n" + + " InnerInner createTableModel() {\n" + + " return super.createTableModel(); \n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144879 +// SHOULD FAIL AT 1.8 (18.2.3): The method chain(Iterator...) in the type X is not applicable for the arguments (Iterator[]) +public void test0999() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static final Iterator chain(Iterator... it) {\n" + + " return null;\n" + + " }\n" + + " void foo1() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " List l2 = Arrays.asList(4f, 5f, 6f);\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " }\n" + + " void foo2() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " List l2 = Arrays.asList(4f, 5f, 6f);\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " }\n" + + " void foo3() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " }\n" + + "}", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation chain(Iterator[]) of the generic method chain(Iterator...) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Iterator 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\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " Iterator 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[]\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^\n" + + "The method chain(Iterator...) in the type X is not applicable for the arguments (Iterator, Iterator)\n" + + "----------\n" + + "5. WARNING in X.java (at line 18)\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator is created for a varargs parameter\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static final Iterator chain(Iterator... it) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter it\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation chain(Iterator[]) of the generic method chain(Iterator...) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " Iterator 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\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Type safety: The expression of type Iterator[] needs unchecked conversion to conform to Iterator[]\n" + : "Type safety: The expression of type Iterator[] needs unchecked conversion to conform to Iterator[]\n") + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^\n" + + "The method chain(Iterator...) in the type X is not applicable for the arguments (Iterator, Iterator)\n" + + "----------\n" + + "6. WARNING in X.java (at line 18)\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator is created for a varargs parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144879 +public void test1000() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static final Iterator chain(Iterator... it) {\n" + + " return null;\n" + + " }\n" + + " void foo1() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " List l2 = Arrays.asList(4f, 5f, 6f);\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " }\n" + + " void foo2() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " List l2 = Arrays.asList(4f, 5f, 6f);\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " }\n" + + " void foo3() {\n" + + " List l1 = Arrays.asList(1, 2, 3);\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " }\n" + + "}", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation chain(Iterator[]) of the generic method chain(Iterator...) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Iterator 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\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " Iterator 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[]\n" + + "----------\n" + + "4. WARNING in X.java (at line 14)\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator") +"> is created for a varargs parameter\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator<"+ intersection("Number", "Comparable") +"> to Iterator\n" + + "----------\n" + + "6. WARNING in X.java (at line 18)\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator is created for a varargs parameter\n" + + "----------\n" + + "7. ERROR in X.java (at line 18)\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator to Iterator\n" + + "----------\n" : + (this.complianceLevel == ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static final Iterator chain(Iterator... it) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter it\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation chain(Iterator[]) of the generic method chain(Iterator...) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " Iterator 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\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " Iterator 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[]\n" + + "----------\n" + + "5. WARNING in X.java (at line 14)\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator") +"> is created for a varargs parameter\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator") +"> to Iterator\n" + + "----------\n" + + "7. WARNING in X.java (at line 18)\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator is created for a varargs parameter\n" + + "----------\n" + + "8. ERROR in X.java (at line 18)\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator to Iterator\n" + + "----------\n" + : // no more errors in JDK1_8+ + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static final Iterator chain(Iterator... it) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter it\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Iterator it1 = X.chain(new Iterator[] { l1.iterator(), l2.iterator() });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation chain(Iterator[]) of the generic method chain(Iterator...) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " Iterator 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\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " Iterator 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[]\n" + + "----------\n" + + "5. WARNING in X.java (at line 14)\n" + + " Iterator it2 = X.chain(l1.iterator(), l2.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator is created for a varargs parameter\n" + + "----------\n" + + "6. WARNING in X.java (at line 18)\n" + + " Iterator it2 = X.chain(l1.iterator(), l1.iterator());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Iterator is created for a varargs parameter\n" + + "----------\n" + ) + ); +} +public void test1001() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Box {}\n" + + " static class ABox {}\n" + + " static class A {}\n" + + " \n" + + " void foo(ABox a1, ABox a2) {\n" + + " a1 = a2; \n" + + " }\n" + + "}", // ================= + }, + ""); +} +public void test1002() { + this.runNegativeTest( + new String[] { + "Base.java", + "class Base {\n" + + "}\n" + + "class Foo>> {\n" + + " U u;\n" + + " V v;\n" + + "}\n" + + "class Bar>> {\n" + + " E e;\n" + + " F f;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in Base.java (at line 3)\n" + + " class Foo>> {\n" + + " ^^^\n" + + "Bound mismatch: The type Foo is not a valid substitute for the bounded parameter >> of the type Bar\n" + + "----------\n" + + "2. ERROR in Base.java (at line 7)\n" + + " class Bar>> {\n" + + " ^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter >> of the type Foo\n" + + "----------\n"); +} +public void test1003() { + this.runConformTest( + new String[] { + "B.java", + "class B {\n" + + "}\n" + + "class S, TT extends T> {\n" + + " BB b;\n" + + " TT t;\n" + + "}\n" + + "class T, TT extends T> {\n" + + " BB b;\n" + + " SS t;\n" + + "}\n", // ================= + }, + ""); +} +public void test1004() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " B getOtherValue() {\n" + + " return null;\n" + + " }\n" + + " A getValue() {\n" + + " return getOtherValue();\n" + + " }\n" + + "}", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=145420 +public void test1005() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + "\n" + + " private static final Object NULL_REF = new Object();\n" + + " private Object data;\n" + + "\n" + + " private static RT unwrap(Object obj) {\n" + + " return (RT)(obj == NULL_REF ? null : obj);\n" + + " }\n" + + "\n" + + " public T1 getAsT1() {\n" + + " return unwrap(data);\n" + + " }\n" + + "\n" + + " public T2 getAsT2() {\n" + + " return unwrap(data);\n" + + " }\n" + + "}", // ================= + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=145420 - variant +public void test1005b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " private static final Object NULL_REF = new Object();\n" + + " private Object data;\n" + + "\n" + + " private static RT unwrap(Object obj) {\n" + + " return (RT)(obj == NULL_REF ? null : obj);\n" + + " }\n" + + "\n" + + " public T1 getAsT1() {\n" + + " return unwrap(data);\n" + + " }\n" + + "\n" + + " public T2 getAsT2() {\n" + + " return unwrap(data);\n" + + " }\n" + + " Zork z;\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " return (RT)(obj == NULL_REF ? null : obj);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to RT\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1006() { + this.runConformTest( + new String[] { + "X.java", + "class Reference {\n" + + " T target;\n" + + " Reference(T target) {\n" + + " this.target = target;\n" + + " }\n" + + " T deref() {\n" + + " return this.target;\n" + + " }\n" + + " static Reference create(U u) {\n" + + " return new Reference(u);\n" + + " }\n" + + "}\n" + + "class BaseObject {}\n" + + "class Person extends BaseObject {}\n" + + "class Building extends BaseObject {}\n" + + "\n" + + "public class X {\n" + + " void foo(Building b, Person p) {\n" + + " Reference bRef = Reference.create(b);\n" + + " Reference pRef = Reference.create(p);\n" + + "\n" + + " final Building building = bRef.deref();\n" + + " final Person person = pRef.deref();\n" + + " }\n" + + "}", // ================= + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=147381 +public void test1007() { + this.runNegativeTest( + new String[] { + "GenericsProblem.java", + "public class GenericsProblem {\n" + + " public void test(T val) {\n" + + " GenericsProblem gp = new GenericsProblem();\n" + + " Class cl2 = gp.getClass();\n" + + " Class cl = val.getClass();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in GenericsProblem.java (at line 5)\n" + + " Class cl = val.getClass();\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 +// FAIL ERRMSG (type display) +public void test1008() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(L l, C c) {\n" + + " X x = bar(l, c);\n" + + " }\n" + + " T bar(L l, C c) { \n" + + " return zork;\n" + + " } \n" + + "}\n" + + "class C {}\n" + + "class L {}\n" + + "\n" + + "\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo(L l, C c) {\n" + + " ^\n" + + "L is a raw type. References to generic type L should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " X x = bar(l, c);\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(L, C) of the generic method bar(L, C) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " X x = bar(l, c);\n" + + " ^\n" + + "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " return zork;\n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1009() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + "\n" + + " void foo(Map map) {\n" + + " bar(map);\n" + + " }\n" + + " void bar(Map> map) {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(Map map) {\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " bar(map);\n" + + " ^^^\n" + + "The method bar(Map>) in the type X is not applicable for the arguments (Map)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1010() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + "\n" + + " void foo(Map map) {\n" + + " bar(map);\n" + + " }\n" + + " void bar(Map> map) {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo(Map map) {\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " bar(map);\n" + + " ^^^\n" + + "The method bar(Map>) in the type X is not applicable for the arguments (Map)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1011() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(HashMap map, String s, Map map2) {\n" + + " bar(map, s, map2); //1\n" + + " bar(map2, s, map2); //2\n" + + " bar2(map, s, map2); //3\n" + + " bar3(map, s, map2); //4\n" + + " }\n" + + " void bar(Map map, U u, Map map2) {}\n" + + " void bar2(Map map, String s, Map map2) {}\n" + + " void bar3(Map map, U s, Map map2) {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo(HashMap map, String s, Map map2) {\n" + + " ^^^^^^^\n" + + "HashMap is a raw type. References to generic type HashMap should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " bar(map, s, map2); //1\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(HashMap, String, Map) of the generic method bar(Map, U, Map) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " bar(map, s, map2); //1\n" + + " ^^^\n" + + "Type safety: The expression of type HashMap needs unchecked conversion to conform to Map\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " bar2(map, s, map2); //3\n" + + " ^^^\n" + + "Type safety: The expression of type HashMap needs unchecked conversion to conform to Map\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " bar3(map, s, map2); //4\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar3(HashMap, String, Map) of the generic method bar3(Map, U, Map) of type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " bar3(map, s, map2); //4\n" + + " ^^^\n" + + "Type safety: The expression of type HashMap needs unchecked conversion to conform to Map\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1012() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(L l, C c) {\n" + + " X x = bar1(l, c);\n" + + " L lx = bar2(l, c);\n" + + " C cx = bar3(l, c);\n" + + " }\n" + + " T bar1(L l, C c) {\n" + + " return null;\n" + + " }\n" + + " L bar2(L l, C c) {\n" + + " return null;\n" + + " }\n" + + " C bar3(L l, C c) {\n" + + " return zork;\n" + + " }\n" + + "}\n" + + "\n" + + "class C {}\n" + + "class L {}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo(L l, C c) {\n" + + " ^\n" + + "L is a raw type. References to generic type L should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " X x = bar1(l, c);\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar1(L, C) of the generic method bar1(L, C) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " X x = bar1(l, c);\n" + + " ^\n" + + "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " L lx = bar2(l, c);\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar2(L, C) of the generic method bar2(L, C) of type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 4)\n" + + " L lx = bar2(l, c);\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + + "----------\n" + + "6. WARNING in X.java (at line 4)\n" + + " L lx = bar2(l, c);\n" + + " ^\n" + + "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + + "----------\n" + + "7. WARNING in X.java (at line 5)\n" + + " C cx = bar3(l, c);\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar3(L, C) of the generic method bar3(L, C) of type X\n" + + "----------\n" + + "8. WARNING in X.java (at line 5)\n" + + " C cx = bar3(l, c);\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type C needs unchecked conversion to conform to C\n" + + "----------\n" + + "9. WARNING in X.java (at line 5)\n" + + " C cx = bar3(l, c);\n" + + " ^\n" + + "Type safety: The expression of type L needs unchecked conversion to conform to L\n" + + "----------\n" + + "10. ERROR in X.java (at line 14)\n" + + " return zork;\n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1013() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List ls = new ArrayList();\n" + + " ls.add(\"foo\");\n" + + " List lx = new ArrayList();\n" + + " lx.add(new X());\n" + + " new X().foo(ls, lx);\n" + + " }\n" + + " void done() {\n" + + " System.out.println(zork);\n" + + " }\n" + + " void foo(List l1, List l2) {\n" + + " X x = bar1(l1, l2);\n" + + " x.done();\n" + + " List lx = bar2(l1, l2);\n" + + " lx.get(0).done();\n" + + " }\n" + + " T bar1(List l1, List l2) {\n" + + " return l1.get(0);\n" + + " }\n" + + " List bar2(List l1, List l2) {\n" + + " return l1;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " System.out.println(zork);\n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " void foo(List l1, List l2) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " X x = bar1(l1, l2);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar1(List, List) of the generic method bar1(List, List) of type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " X x = bar1(l1, l2);\n" + + " ^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 17)\n" + + " List lx = bar2(l1, l2);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar2(List, List) of the generic method bar2(List, List) of type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 17)\n" + + " List lx = bar2(l1, l2);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "7. WARNING in X.java (at line 17)\n" + + " List lx = bar2(l1, l2);\n" + + " ^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1014() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " void foo1(List l, List ls) {\n" + + " Set> mss1 = bar(l, ls).entrySet();\n" + + " String s = bar(l, ls).entrySet();\n" + + " }\n" + + " Map bar(List lu, List lv) { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void foo1(List l, List ls) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " Set> mss1 = bar(l, ls).entrySet();\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " Set> mss1 = bar(l, ls).entrySet();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Set needs unchecked conversion to conform to Set>\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " Set> mss1 = bar(l, ls).entrySet();\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " String s = bar(l, ls).entrySet();\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 6)\n" + + " String s = bar(l, ls).entrySet();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Set to String\n" + + "----------\n" + + "7. WARNING in X.java (at line 6)\n" + + " String s = bar(l, ls).entrySet();\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +// FAIL SHOULD RAISE MORE WARNINGS? +public void test1015() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo1(List l, List ls) {\n" + + " List ls1 = bar(l, ls);\n" + + " String s = bar(l, ls);\n" + + " }\n" + + " List bar(List lu, List lv) { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo1(List l, List ls) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " List ls1 = bar(l, ls);\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " List ls1 = bar(l, ls);\n" + + " ^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " List ls1 = bar(l, ls);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 5)\n" + + " String s = bar(l, ls);\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation bar(List, List) of the generic method bar(List, List) of type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 5)\n" + + " String s = bar(l, ls);\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to String\n" + + "----------\n" + + "7. WARNING in X.java (at line 5)\n" + + " String s = bar(l, ls);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +// SHOULD FAIL AT 1.8 (RET): Type mismatch: cannot convert from List to List +public void test1016() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo1() {\n" + + " List ls1 = bar(null);\n" + + " List ls2 = bar(null);\n" + + " String s = bar(null);\n" + + " }\n" + + " List bar(List lu) { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List ls1 = bar(null);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " String s = bar(null);\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1017() { + this.runNegativeTest( + new String[] { + "SortedList.java", + "import java.util.*;\n" + + "\n" + + "public class SortedList extends LinkedList\n" + + "{\n" + + " public boolean add(E e){\n" + + " int index = Collections.binarySearch(this,e);\n" + + " if (index<0)\n" + + " super.add(-index-1,e);\n" + + " return true;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in SortedList.java (at line 3)\n" + + " public class SortedList extends LinkedList\n" + + " ^^^^^^^^^^\n" + + "The serializable class SortedList does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in SortedList.java (at line 3)\n" + + " public class SortedList extends LinkedList\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "3. WARNING in SortedList.java (at line 5)\n" + + " public boolean add(E e){\n" + + " ^^^^^^^^\n" + + "The method add(E) of type SortedList should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "4. ERROR in SortedList.java (at line 6)\n" + + " int index = Collections.binarySearch(this,e);\n" + + " ^^^^^^^^^^^^\n" + + "The method binarySearch(List>, T) in the type Collections is not applicable for the arguments (SortedList, E)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148061 - variation +public void test1018() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo(U u) {\n" + + " bar(u, new Exception());\n" + + " }\n" + + " T bar(U u, T t) { return null; }\n" + + "}", // ================= + }, + ""); +} +public void test1018a() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class A {}\n" + + "\n" + + "class B extends A> {}\n" + + "\n" + + "public class X extends B {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +public void test1019() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " double[] d1 = new double[] { 1.0, 2.0, 3.0, 4.0 };\n" + + " System.out.println(deepToString(d1));\n" + + "\n" + + " Double[] d2 = new Double[] { 1.0, 2.0, 3.0, 4.0 };\n" + + " System.out.println(deepToString(d2));\n" + + " \n" + + " }\n" + + "\n" + + " public static String deepToString(T[] array) {\n" + + " StringBuffer s = new StringBuffer();\n" + + " for (T t : array) {\n" + + " s.append(t.toString());\n" + + " s.append(\",\");\n" + + " }\n" + + " if (s.length() > 0) {\n" + + " s.setLength(s.length() - 1); // removes last \",\"\n" + + " }\n" + + " return s.toString();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " System.out.println(deepToString(d1));\n" + + " ^^^^^^^^^^^^\n" + + "The method deepToString(T[]) in the type X is not applicable for the arguments (double[])\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149573 +public void test1020() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo(List l1, List l2) {\n" + + " l1.add(l2.get(0));\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " l1.add(l2.get(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ? extends Exception) in the type List is not applicable for the arguments (capture#2-of ? extends Exception)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149376 +public void test1021() { + this.runConformTest( + new String[] { + "p/SomeClass.java", + "package p;\n" + + "import static p.SomeClass.SomeEnum.*;\n" + + "public abstract class SomeClass extends Object {\n" + + " public enum SomeEnum {\n" + + " A;\n" + + " };\n" + + "}\n", + }, + "" + ); +} +public void test1021b() { // should this case be allowed? + this.runNegativeTest( + new String[] { + "p/SomeClass2.java", + "package p;\n" + + "import static p.SomeClass2.M1.*;\n" + + "public abstract class SomeClass2 extends M {\n" + + " public static class M1 extends M2 {}\n" + + " public static class M2 extends M3 {}\n" + + " public static class M3 {\n" + + " public static class M {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\SomeClass2.java (at line 3)\n" + + " public abstract class SomeClass2 extends M {\n" + + " ^\n" + + "M cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in p\\SomeClass2.java (at line 4)\n" + + " public static class M1 extends M2 {}\n" + + " ^^\n" + + "Cycle detected: a cycle exists in the type hierarchy between SomeClass2.M1 and SomeClass2\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=151410 (duplicate of 149376) +public void test1021c() { + runConformTest( + new String[] { + "ccs/jdtbug/filters/NameRF.java", + "package ccs.jdtbug.filters;\n" + + "import static ccs.jdtbug.ResultFilter.Action.*;\n" + + "import ccs.jdtbug.*;\n" + + "public class NameRF implements ResultFilter {\n" + + " public NameRF() {}\n" + + " public Action getAction(String in, int ntotal, int naccept) {\n" + + " return YES;\n" + + " }\n" + + "} // end class\n", + "ccs/jdtbug/ResultFilter.java", + "package ccs.jdtbug;\n" + + "import java.io.*;\n" + + "public interface ResultFilter {\n" + + " public enum Action {\n" + + " YES, NO, CANCEL\n" + + " }\n" + + " public Action getAction(T in, int ntotal, int naccept) throws IOException;\n" + + "} // end interface\n" + } + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150294 +public void test1022() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String testString = \"test string\";\n" + + "\n" + + " testWithNonGeneric(testString);\n" + + " testWithGeneric(testString);\n" + + " }\n" + + "\n" + + " private static void testWithNonGeneric(String input) {\n" + + " Class clazz = input.getClass();\n" + + "\n" + + " System.out.println(clazz.getName());\n" + + " }\n" + + "\n" + + " private static void testWithGeneric(T input) {\n" + + " Class clazz = input.getClass();\n" + + "\n" + + " System.out.println(clazz.getName());\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " Class clazz = input.getClass();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150362 +public void test1023() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.Properties;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Properties props = new Properties();\n" + + " for (Map.Entry entry : props.entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " for (Map.Entry entry : props.entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " for (Map.Entry entry : props.entrySet()) {\n" + + " System.out.println(entry);\n" + + " }\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " for (Map.Entry entry : props.entrySet()) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from element type Map.Entry to Map.Entry\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " for (Map.Entry entry : ((Map) props).entrySet()) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Properties to Map\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=151275 +public void test1024() { + runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer castInteger = genericCast(1); // works\n" + + " int castInt1 = genericCast(1); // fails in javac but works in Eclipse\n" + + " int castInt2 = X. genericCast(1); // workaround for javac\n" + + " int castInt3 = (Integer) genericCast(1); // workaround for javac\n" + + " }\n" + + " private static T genericCast(Object input) {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " T castValue = (T) input;\n" + + " return castValue;\n" + + " }\n" + + "}", // =================, + }, + null, + "", + null, + JavacTestOptions.EclipseJustification.EclipseBug151275); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 +public void test1025() { + this.runConformTest( + new String[] { + "GenericBaseClass.java", + "public class GenericBaseClass {\n" + + " public GenericBaseClass() {\n" + + " if (!(this instanceof ASubGenericClass)) {\n" + + " System.out.println(\"I\'m not ASubClass\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class ASubGenericClass extends GenericBaseClass {\n" + + " public ASubGenericClass() {\n" + + " // This compiles with both\n" + + " GenericBaseClass hey = this;\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 +public void test1026() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "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 set = g.newSet(g.new B());\n" + + " }\n" + + " public Set newSet(V v) {\n" + + " Set set = new LinkedHashSet();\n" + + " set.add(v);\n" + + " return set;\n" + + " }\n" + + "}\n" // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 - variation +public void test1027() { + runConformTest( + // 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" + + "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 set = g.newSet(g.new B());\n" + + " }\n" + + " public Set newSet(V... objects) {\n" + + " Set set = new LinkedHashSet();\n" + + " for (T t : objects) {\n" + + " set.add(t);\n" + + " }\n" + + " return set;\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 set = g.newSet(g.new B());\n" + + " }\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public Set newSet(V... objects) {\n" + + " Set set = new LinkedHashSet();\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 */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=155753 - variation +public void test1028() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.LinkedHashSet;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X g = new X();\n" + + " Set set = g.newSet(new B());\n" + + " }\n" + + " public Set newSet(V v) {\n" + + " Set set = new LinkedHashSet();\n" + + " set.add(v);\n" + + " return set;\n" + + " }\n" + + "}\n" + + "\n" + + "class A {};\n" + + "class B extends A {};\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//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); + String xSource = + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static List makeNumberList(T a, T b) {\n" + + " return Arrays.asList(a, b);\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " List name = makeNumberList(5, 5D);\n" + + " }\n" + + "}"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " List name = makeNumberList(5, 5D);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List<"+ intersection("Number", "Comparable") +"> to List\n" + + "----------\n", + null, + true, + options); + } else { + runConformTest(new String[] { "X.java", xSource }); + } +} +public void test1030() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public class PointList extends Object implements Iterable {\n" + + " private List theList = new ArrayList();\n" + + "\n" + + " public Iterator iterator() {\n" + + " return theList.iterator();\n" + + " }\n" + + " }\n" + + "\n" + + " private PointList waypoints = new PointList();\n" + + "\n" + + " public void printWaypoints() {\n" + + " for (Waypoint waypoint : waypoints) { // ***** This line does not compile *****\n" + + " System.out.println(waypoint.toString());\n" + + " }\n" + + " for (Iterator it = waypoints.iterator(); it.hasNext();) {\n" + + " Waypoint waypoint = it.next();\n" + + " System.out.println(waypoint.toString());\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class Waypoint {}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156765 +// FAIL EXTRA ERR: outer non-generic invocation cannot yet feed expected type into inner inference +public void test1031() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "interface IValue extends Serializable {\n" + + " public > T getComparableValue();\n" + + "}\n" + + "\n" + + "@SuppressWarnings(\"null\")\n" + + "public class X {\n" + + " public static void foo0() {\n" + + " IValue val1 = null;\n" + + " Object o = val1.getComparableValue(); // 0\n" + + " }\n" + + " public static void foo1() {\n" + + " IValue val1 = null;\n" + + " String s = val1.getComparableValue(); // 1\n" + + " }\n" + + " public static int foo2() {\n" + + " IValue val1 = null;\n" + + " IValue val2 = null;\n" + + " return val1.getComparableValue().compareTo(val2.getComparableValue()); // 2\n" + + " } \n" + + " public static int foo3() {\n" + + " Comparable c = \"aaa\"; // 3\n" + + " Comparable o = new Object(); // 4\n" + + " return 0;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " Comparable o = new Object(); // 4\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Comparable\n" + + "----------\n"); +} +public void test1032() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " T test(String name) {\n" + + "\n" + + " try {\n" + + " InputStream in = new FileInputStream(name);\n" + + " return (T) new ObjectInputStream(in).readObject();\n" + + " } catch (Exception e) {\n" + + " }\n" + + " return null;\n" + + " }\n" + + "\n" + + " U text() {\n" + + " return test(\"data\");\n" + + " }\n" + + "}", // ================= + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +public void test1032a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " T test(String name) {\n" + + "\n" + + " try {\n" + + " InputStream in = new FileInputStream(name);\n" + + " return (T) new ObjectInputStream(in).readObject();\n" + + " } catch (Exception e) {\n" + + " }\n" + + " return null;\n" + + " }\n" + + "\n" + + " U text() {\n" + + " return test(\"data\");\n" + + " }\n" + + " Zork z;\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " return (T) new ObjectInputStream(in).readObject();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to T\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1033() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.bar1(Integer.TYPE);\n" + + " x.bar2(Integer.TYPE);\n" + + " x.bar2(\"\");\n" + + " } \n" + + " void bar1(Class... classes) {}\n" + + " void bar2(Class... classes) {}\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 should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " X x = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " x.bar1(Integer.TYPE);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method bar1(Class...) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " x.bar2(\"\");\n" + + " ^^^^\n" + + "The method bar2(Class...) in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " void bar2(Class... classes) {}\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158519 +// FAIL ERRMSG +public void test1034() { + this.runNegativeTest( + new String[] { + "ChainedClosure.java", + "interface Closure {\n" + + " public void execute(I input);\n" + + "}\n" + + "\n" + + "class ChainedClosure implements Closure {\n" + + " private final Closure[] iClosures;\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public static Closure getInstance(Closure closure1, Closure closure2) {\n" + + " if (closure1 == null || closure2 == null) {\n" + + " throw new IllegalArgumentException(\"Closures must not be null\");\n" + + " }\n" + + " Closure[] closures = new Closure[] { closure1, closure2 };\n" + + " return new ChainedClosure(closures);\n" + + " }\n" + + " public ChainedClosure(Closure[] closures) {\n" + + " super();\n" + + " iClosures = closures;\n" + + " }\n" + + " public void execute(I input) {\n" + + " for (int i = 0; i < iClosures.length; i++) {\n" + + " iClosures[i].execute(input);\n" + + " }\n" + + " }\n" + + "}\n" + + "class ClosureUtils {\n" + + " public static Closure chainedClosure(Closure closure1, Closure closure2) {\n" + + " return ChainedClosure.getInstance(closure1, closure2);\n" + + " }\n" + + " public static Closure chainedClosure2(Closure closure1, Closure closure2) {\n" + + " return ChainedClosure.getInstance(closure1, closure2);\n" + + " }\n" + + " public static Closure chainedClosure3(Closure closure1, Closure closure2) {\n" + + " return ChainedClosure.getInstance(closure1, closure2);\n" + + " }\n" + + "}", // ================= + + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in ChainedClosure.java (at line 33)\n" + + " return ChainedClosure.getInstance(closure1, closure2);\n" + + " ^^^^^^^^^^^\n" + + "The method getInstance(Closure, Closure) in the type ChainedClosure is not applicable for the arguments (Closure, Closure)\n" + + "----------\n" : + "----------\n" + + "1. ERROR in ChainedClosure.java (at line 33)\n" + + " return ChainedClosure.getInstance(closure1, closure2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Closure to Closure\n" + + "----------\n", + JavacTestOptions.DEFAULT); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158531 +public void test1035() { + this.runConformTest( + new String[] { + "ComparableComparator.java", + "import java.util.Comparator;\n" + + "\n" + + "@SuppressWarnings({\"unchecked\", \"rawtypes\"})\n" + + "class ComparableComparator> implements Comparator {\n" + + "\n" + + " static ComparableComparator instance = new ComparableComparator();\n" + + "\n" + + "public static > ComparableComparator getInstance() {\n" + + " return instance;\n" + + "}\n" + + "static > Comparator bar() {\n" + + " return null;\n" + + "}\n" + + "static Comparator baz() {\n" + + " return null;\n" + + "}\n" + + "public int compare(T obj1, T obj2) {\n" + + " return obj1.compareTo(obj2);\n" + + "}\n" + + "}\n" + + "\n" + + "@SuppressWarnings({\"unchecked\", \"rawtypes\"})\n" + + "class ComparatorUtils {\n" + + "\n" + + " static Comparator BAR = ComparableComparator.bar();//0\n" + + " static Comparator NATURAL_COMPARATOR = ComparableComparator.getInstance();//1\n" + + " static Object BAR2 = ComparableComparator.bar();//1a\n" + + " static Comparator BAR3 = ComparableComparator.baz();//1b\n" + + "\n" + + "public static > Comparator naturalComparator() {\n" + + " return NATURAL_COMPARATOR;\n" + + "}\n" + + "\n" + + "public static Comparator nullLowComparator(Comparator comparator) {\n" + + " if (comparator == null)\n" + + " comparator = (Comparator) naturalComparator();//2\n" + + " return new NullComparator(comparator, false);\n" + + "}\n" + + "}\n" + + "\n" + + "@SuppressWarnings(\"unchecked\")\n" + + "class NullComparator implements Comparator {\n" + + "\n" + + " Comparator nonNullComparator;\n" + + " boolean nullsAreHigh;\n" + + "\n" + + "public NullComparator() {\n" + + " this((Comparator) ComparableComparator.getInstance(), true);//3\n" + + "}\n" + + "\n" + + "public NullComparator(Comparator nonNullComparator) {\n" + + " this(nonNullComparator, true);\n" + + "}\n" + + "\n" + + "public NullComparator(boolean nullsAreHigh) {\n" + + " this((Comparator) ComparableComparator.getInstance(), nullsAreHigh);//4\n" + + "}\n" + + "\n" + + "public NullComparator(Comparator nonNullComparator, boolean nullsAreHigh) {\n" + + " this.nonNullComparator = nonNullComparator;\n" + + " this.nullsAreHigh = nullsAreHigh;\n" + + " if (nonNullComparator == null) {\n" + + " throw new NullPointerException(\"null nonNullComparator\");\n" + + " }\n" + + "}\n" + + "\n" + + "public int compare(V obj1, V obj2) {\n" + + " return 0;\n" + + "}\n" + + "}", // ================= + + }); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158548 +public void test1036() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " List list;\n" + + " Map.Entry,List> entry;\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " \n" + + " p.q.Map.Entry entry3;\n" + + " \n" + + " String.Y y; // wrong\n" + + " X.Y y1; // wrong\n" + + " X.Y y2;\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " List list;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " List list;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "9. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "10. ERROR in X.java (at line 4)\n" + + " Map.Entry,List> entry;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "11. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^^^\n" + + "jaavaa cannot be resolved to a type\n" + + "----------\n" + + "12. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "13. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "14. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "15. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "16. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "17. ERROR in X.java (at line 5)\n" + + " jaavaa.util.Map.Entry,List> entry2;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "18. ERROR in X.java (at line 7)\n" + + " p.q.Map.Entry entry3;\n" + + " ^\n" + + "p cannot be resolved to a type\n" + + "----------\n" + + "19. ERROR in X.java (at line 9)\n" + + " String.Y y; // wrong\n" + + " ^^^^^^\n" + + "The type String is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "20. ERROR in X.java (at line 10)\n" + + " X.Y y1; // wrong\n" + + " ^^^^^^^^^^^\n" + + "X.Y cannot be resolved to a type\n" + + "----------\n" + + "21. ERROR in X.java (at line 10)\n" + + " X.Y y1; // wrong\n" + + " ^^^^^^\n" + + "Bound mismatch: The type Object is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n" + + "22. ERROR in X.java (at line 10)\n" + + " X.Y y1; // wrong\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "23. ERROR in X.java (at line 11)\n" + + " X.Y y2;\n" + + " ^^^^^^^^^^^\n" + + "X.Y cannot be resolved to a type\n" + + "----------\n" + + "24. ERROR in X.java (at line 11)\n" + + " X.Y y2;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158548 - variation +public void test1037() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " List list;\n" + + " Map.Entry entry;\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " List list;\n" + + " ^^^^\n" + + "List cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " List list;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Map.Entry entry;\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " Map.Entry entry;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159021 - variation +public void test1038() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int CONST = A.foo();\n" + + "}\n" + + "\n" + + "class A {\n" + + " static int foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class B implements I {\n" + + " static int LOCAL_STATIC;\n" + + " int local_field;\n" + + " B(int param) {\n" + + " int i = CONST; // keep for possible \n" + + " int j = param; // may optimize out\n" + + " int k = LOCAL_STATIC; // may optimize out\n" + + " int l = local_field; // may optimize out\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new B(12);\n" + + " }\n" + + "}", // ================= + }, + "SUCCESS", + null, + false, + null, + options, + null); + // check the reference to I.CONST still got generated (for invocation side-effect) + String expectedOutput = + " // Method descriptor #10 (I)V\n" + + " // Stack: 1, Locals: 2\n" + + " B(int param);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 getstatic B.CONST : int [15]\n" + + " 7 pop\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 4, line: 15]\n" + + " [pc: 8, line: 19]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 9] local: this index: 0 type: B\n" + + " [pc: 0, pc: 9] local: param index: 1 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "B.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159021 - variation +public void test1039() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Value CONST = A.foo(\"[I.CONST]\");\n" + + "}\n" + + "class Value {\n" + + " static String NAME = \"\";\n" + + " V v;\n" + + " Value(V v) {\n" + + " this.v = v;\n" + + " }\n" + + "}\n" + + "class A {\n" + + " static Value foo(String str) {\n" + + " System.out.print(str);\n" + + " return new Value(\"str\");\n" + + " }\n" + + "}\n" + + "class B implements I {\n" + + " static Value LOCAL_STATIC = A.foo(\"[B.LOCAL_STATIC]\");\n" + + " Value local_field = A.foo(\"[B.local_field]\");\n" + + " B(Value param) {\n" + + " String i = CONST.NAME; // keep for possible \n" + + " String j = param.NAME; // may optimize out\n" + + " String k = LOCAL_STATIC.NAME; // may optimize out\n" + + " String l = local_field.NAME; // may optimize out\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new B(new Value(\"[PARAM]\"));\n" + + " }\n" + + "}", // ================= + }, + "[B.LOCAL_STATIC][B.local_field][I.CONST]", + null, + false, + null, + options, + null); + // check the reference to I.CONST still got generated (for invocation side-effect) + String expectedOutput = + " // Method descriptor #28 (LValue;)V\n" + + " // Signature: (LValue;)V\n" + + " // Stack: 2, Locals: 2\n" + + " B(Value param);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [30]\n" + + " 4 aload_0 [this]\n" + + " 5 ldc [32]\n" + + " 7 invokestatic A.foo(java.lang.String) : Value [17]\n" + + " 10 putfield B.local_field : Value [34]\n" + + " 13 getstatic B.CONST : Value [36]\n" + + " 16 pop\n" + + " 17 getstatic Value.NAME : java.lang.String [39]\n" + + " 20 pop\n" + + " 21 getstatic Value.NAME : java.lang.String [39]\n" + + " 24 pop\n" + + " 25 getstatic Value.NAME : java.lang.String [39]\n" + + " 28 pop\n" + + " 29 getstatic Value.NAME : java.lang.String [39]\n" + + " 32 pop\n" + + " 33 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 20]\n" + + " [pc: 4, line: 19]\n" + + " [pc: 13, line: 21]\n" + + " [pc: 21, line: 22]\n" + + " [pc: 25, line: 23]\n" + + " [pc: 29, line: 24]\n" + + " [pc: 33, line: 25]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 34] local: this index: 0 type: B\n" + + " [pc: 0, pc: 34] local: param index: 1 type: Value\n"; + + File f = new File(OUTPUT_DIR + File.separator + "B.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159021 - variation +public void test1040() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Value CONST = A.foo(\"[I.CONST]\");\n" + + "}\n" + + "class Value {\n" + + " static String NAME = \"\";\n" + + " V v;\n" + + " Value(V v) {\n" + + " this.v = v;\n" + + " }\n" + + "}\n" + + "class A {\n" + + " static Value foo(String str) {\n" + + " System.out.print(str);\n" + + " return new Value(\"str\");\n" + + " }\n" + + "}\n" + + "class B implements I {\n" + + " static Value LOCAL_STATIC = A.foo(\"[B.LOCAL_STATIC]\");\n" + + " Value local_field = A.foo(\"[B.local_field]\");\n" + + " B(Value param) {\n" + + " String i = this.CONST.NAME; // keep for possible \n" + + " String k = this.LOCAL_STATIC.NAME; // may optimize out\n" + + " String l = this.local_field.NAME; // may optimize out\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new B(new Value(\"[PARAM]\"));\n" + + " }\n" + + "}", // ================= + }, + "[B.LOCAL_STATIC][B.local_field][I.CONST]", + null, + false, + null, + options, + null); + // check the reference to I.CONST still got generated (for invocation side-effect) + String expectedOutput = + " // Method descriptor #28 (LValue;)V\n" + + " // Signature: (LValue;)V\n" + + " // Stack: 2, Locals: 2\n" + + " B(Value param);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [30]\n" + + " 4 aload_0 [this]\n" + + " 5 ldc [32]\n" + + " 7 invokestatic A.foo(java.lang.String) : Value [17]\n" + + " 10 putfield B.local_field : Value [34]\n" + + " 13 getstatic B.CONST : Value [36]\n" + + " 16 pop\n" + + " 17 getstatic Value.NAME : java.lang.String [39]\n" + + " 20 pop\n" + + " 21 getstatic Value.NAME : java.lang.String [39]\n" + + " 24 pop\n" + + " 25 getstatic Value.NAME : java.lang.String [39]\n" + + " 28 pop\n" + + " 29 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 20]\n" + + " [pc: 4, line: 19]\n" + + " [pc: 13, line: 21]\n" + + " [pc: 21, line: 22]\n" + + " [pc: 25, line: 23]\n" + + " [pc: 29, line: 24]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 30] local: this index: 0 type: B\n" + + " [pc: 0, pc: 30] local: param index: 1 type: Value\n"; + + File f = new File(OUTPUT_DIR + File.separator + "B.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159245 +public void test1041() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "\n" + + "public class X {\n" + + " {\n" + + " X rawx = null;\n" + + " X[] rawxs = { rawx };\n" + + " System.out.println(rawxs.length);\n" + + " }\n" + + " {\n" + + " p.X rawx = null;\n" + + " p.X[] rawxs = { rawx };\n" + + " System.out.println(rawxs.length);\n" + + " }\n" + + " Zork z;\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 5)\n" + + " X rawx = null;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 6)\n" + + " X[] rawxs = { rawx };\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in p\\X.java (at line 10)\n" + + " p.X rawx = null;\n" + + " ^^^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in p\\X.java (at line 11)\n" + + " p.X[] rawxs = { rawx };\n" + + " ^^^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "5. ERROR in p\\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=159818 +public void test1042() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(T x) {\n" + + " Class c = x.getClass();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Class c = x.getClass();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 +public void test1043() { + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " T t;\n" + + " S s;\n" + + " void test(A a) {\n" + + " this.t = this.s; //fine\n" + + " a.t = a.s;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in A.java (at line 6)\n" + + " a.t = a.s;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from capture#4-of ? extends S to capture#1-of ? extends Long\n" + + "----------\n", + JavacTestOptions.EclipseJustification.EclipseBug159214); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 - variation +public void test1044() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " X x;\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 - variation +public void test1045() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " X x;\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 +public void test1046() { + this.runConformTest( + new String[] { + "X.java", //======================== + "public interface X {\n" + + " interface Entry {\n" + + " interface Internal extends Entry {\n" + + " Internal createEntry();\n" + + " }\n" + + " }\n" + + "}\n", //======================== + "Y.java", + "public class Y implements X.Entry.Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + ""); + // compile Y against X binary + this.runConformTest( + new String[] { + "Y.java", //======================== + "public class Y implements X.Entry.Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 - variation +public void test1047() { + this.runConformTest( + new String[] { + "p/X.java", //======================== + "package p;\n" + + "public interface X {\n" + + " interface Entry {\n" + + " interface Internal extends Entry {\n" + + " Internal createEntry();\n" + + " }\n" + + " }\n" + + "}\n", //======================== + "Y.java", + "import p.X.Entry.Internal;\n" + + "public class Y implements Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + ""); + // compile Y against X binary + this.runConformTest( + new String[] { + "Y.java", //======================== + "import p.X.Entry.Internal;\n" + + "public class Y implements Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 - variation +public void test1048() { + this.runConformTest( + new String[] { + "X.java", //======================== + "public interface X {\n" + + " static class Entry {\n" + + " static abstract class Internal extends Entry {\n" + + " abstract Internal createEntry();\n" + + " }\n" + + " }\n" + + "}\n", //======================== + "Y.java", + "public class Y extends X.Entry.Internal {\n" + + " @Override public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + ""); + // compile Y against X binary + this.runConformTest( + new String[] { + "Y.java", //======================== + "public class Y extends X.Entry.Internal {\n" + + " @Override public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + "", + null, + false, + null); +} +public void test1049() { + this.runConformTest( + new String[] { + "X.java", //======================== + "import java.util.*;\n" + + "public class X {\n" + + "}\n" + + "\n" + + "//===================\n" + + "interface FooHandle> extends BarHandle {}\n" + + "interface Foo> extends FooHandle, Bar {\n" + + " FooHandle foo();\n" + + "}\n" + + "//===================\n" + + "interface EveHandle> extends SimpleHandle {}\n" + + "interface Eve> extends Simple, EveHandle {\n" + + " List foo();\n" + + " BazHandle handles();\n" + + "}\n" + + "\n" + + "//===================\n" + + "interface BobHandle extends BillHandle {}\n" + + "interface Bob extends BobHandle, Bill {}\n" + + "\n" + + "//===================\n" + + "interface BarHandle> extends BazHandle {\n" + + " boolean same(BarHandle o);\n" + + "}\n" + + "interface Bar> extends Baz, BarHandle {\n" + + " BarHandle handle();\n" + + "}\n" + + "\n" + + "//===================\n" + + "interface BazHandle> {\n" + + " T baz();\n" + + " boolean same(BazHandle o);\n" + + "}\n" + + "interface Baz> extends BazHandle {\n" + + " BazHandle handle();\n" + + " T baz();\n" + + "}\n" + + "\n" + + "//===================\n" + + "interface BillHandle extends FooHandle {}\n" + + "interface Bill extends BillHandle, Foo {}\n" + + "\n" + + "//===================\n" + + "interface SimpleHandle extends BazHandle {}\n" + + "interface Simple extends Baz, SimpleHandle {}\n" + + "\n" + + "//===================\n" + + "interface KeyHandle extends FooHandle {}\n" + + "interface Key extends Foo, KeyHandle {}\n" + + "\n" + + "//===================\n" + + "interface ClydeHandle extends BillHandle {}\n" + + "interface Clyde extends ClydeHandle, Bill {\n" + + " void add(BobHandle h);\n" + + " public List handles();\n" + + "}\n" + + "\n" + + "//===================\n" + + "interface FredHandle> extends BarHandle {}\n" + + "interface Fred> extends FredHandle, Bar {}\n" + + "\n", // ================= + }, + ""); +} +public void test1050() { + String expectedOutput = + "xxx\n" + + "true\n" + + "ClassCastException: Object[] cannot be cast to String[]\n" + + "ClassCastException: Object[] cannot be cast to String[]"; + + this.runConformTest( + new String[] { + "X.java", //======================== + "class Container {\n" + + " public Container() {\n" + + " data = (E[]) new Object[100];\n" + + " }\n" + + " protected E[] data;\n" + + " protected int size;\n" + + " E get(int index) {\n" + + " return data[index];\n" + + " }\n" + + " void add(E object) {\n" + + " data[size++] = object;\n" + + " }\n" + + " E[] data() {\n" + + " return data;\n" + + " }\n" + + "}\n" + + "class StringContainer extends Container {\n" + + " public StringContainer() {\n" + + " }\n" + + " public void doSomething() {\n" + + " add(\"xxx\");\n" + + " System.out.println(get(0));\n" + + " System.out.println((\"\" + data()).\n" + + " startsWith(\"[Ljava.lang.Object;@\"));\n" + + " try {\n" + + " System.out.println(data[0]);\n" + + " } catch (ClassCastException e) {\n" + + " System.out.println(\"ClassCastException: Object[] cannot be cast to String[]\");\n" + + " }\n" + + " try {\n" + + " System.out.println(data()[0]);\n" + + " } catch (ClassCastException e) {\n" + + " System.out.println(\"ClassCastException: Object[] cannot be cast to String[]\");\n" + + " }\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " StringContainer x = new StringContainer();\n" + + " x.doSomething();\n" + + " }\n" + + "}", // ================= + }, + expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114088 +public void test1051() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public interface Intf {\n" + + " void foo(List.Inner> ls);\n" + + " }\n" + + "\n" + + " public class Conc {\n" + + " Intf impl;\n" + + " public Conc(Intf impl) {\n" + + " this.impl = impl;\n" + + " }\n" + + " public class Inner { }\n" + + "\n" + + " public void bar(List.Inner> ls) {\n" + + " impl.foo(ls);\n" + + " }\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115691 +public void test1052() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X extends java.util.ArrayList {\n" + + " private static final long serialVersionUID = 713223190582506215L;\n" + + " static void test() {\n" + + " java.util.ArrayList a1 = new X();\n" + + " X b1 = (X) a1;\n" + + " X c1 = X.class.cast(a1);\n" + + " java.util.ArrayList a2 = new X();\n" + + " X b2 = (X) a2;\n" + + " }\n" + + "}", + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=122163 +public void test1053() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " class innerclass {\n" + + " void foo() {\n" + + " X c = X.this;\n" + + " }\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142935 +public void test1054() { + Map customOptions = getCompilerOptions(); + // check no unsafe type operation problem is issued + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + String expectedOutput = + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Bar bar= clazz.getAnnotation(Bar.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to Bar\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.reflect.Method;\n" + + "\n" + + "@Bar\n" + + "public class X {\n" + + "\n" + + " @Bar\n" + + " public void bar() throws Exception {\n" + + " Class clazz= X.class;\n" + + " Bar bar= clazz.getAnnotation(Bar.class);\n" + + " Method method= clazz.getMethod(\"bar\");\n" + + " Bar bar2= method.getAnnotation(Bar.class);\n" + + " }\n" + + "}\n" + + "\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Bar {\n" + + "}", + }, + expectedOutput, + null, + true, + customOptions); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=142935 +public void test1055() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.reflect.Method;\n" + + "\n" + + "@Bar\n" + + "public class X {\n" + + "\n" + + " @Bar\n" + + " public void bar() throws Exception {\n" + + " Class clazz= X.class;\n" + + " Bar bar= clazz.getAnnotation(Bar.class);\n" + + " Method method= clazz.getMethod(\"bar\");\n" + + " Bar bar2= method.getAnnotation(Bar.class);\n" + + " }\n" + + "}\n" + + "\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Bar {\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=162400 +public void test1056() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static T foo() {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String[] s = { foo() };\n" + + " } \n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159738 +public void test1057() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "class GenericType & Map.Entry> {\n" + + " public void doSomething(E e) {\n" + + " System.out.println(e.compareTo(e.getValue()));\n" + + " }\n" + + "}\n" + + "class ConcreteType {\n" + + " public void doSomething(Object obj) {\n" + + " System.out.println(((Comparable) obj).compareTo(((Map.Entry) obj).getValue()));\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new GenericType().doSomething(\"a1\");\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":1]\");\n" + + " }\n" + + " try {\n" + + " new ConcreteType().doSomething(\"a2\");\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":2]\");\n" + + " }\n" + + " }\n" + + "}\n", // =================, + }, + "[ClassCastException:1][ClassCastException:2]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141289 +public void test1058() throws Exception { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", // ================= + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " int foo = 0;\n" + + " String bar = \"zero\";\n" + + " System.out.println((foo != 0 ? foo : bar).compareTo(null));\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "SUCCESS" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [foo]\n" + + " 2 ldc [16]\n" + + " 4 astore_2 [bar]\n" + + " 5 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + + " 8 iload_1 [foo]\n" + + " 9 ifeq 19\n" + + " 12 iload_1 [foo]\n" + + " 13 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [24]\n" + + " 16 goto 20\n" + + " 19 aload_2 [bar]\n" + + " 20 aconst_null\n" + + " 21 invokeinterface java.lang.Comparable.compareTo(java.lang.Object) : int [30] [nargs: 2]\n" + + " 26 invokevirtual java.io.PrintStream.println(int) : void [36]\n" + + " 29 goto 41\n" + + " 32 astore_1 [e]\n" + + " 33 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + + " 36 ldc [42]\n" + + " 38 invokevirtual java.io.PrintStream.println(java.lang.String) : void [44]\n" + + " 41 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 29] -> 32 when : java.lang.NullPointerException\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 5, line: 6]\n" + + " [pc: 29, line: 7]\n" + + " [pc: 33, line: 8]\n" + + " [pc: 41, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 42] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 29] local: foo index: 1 type: int\n" + + " [pc: 5, pc: 29] local: bar index: 2 type: java.lang.String\n" + + " [pc: 33, pc: 41] local: e index: 1 type: java.lang.NullPointerException\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160795 +public void test1059() { + this.runNegativeTest( + new String[] { + "A.java", // ================= + "class A {\n" + + " S test(A a) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " void m() {\n" + + " A a = null;\n" + + " Number b = test(a);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in A.java (at line 8)\n" + + " Number b = test(a);\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? to Number\n" + + "----------\n"); +} +// See corresponding FIXME in TypeBinding.isTypeArgumentContainedBy(..) +public void test1060() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", // ================= + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void m(List list,Collection coll) {\n" + + " m(list,coll);\n" + + " }\n" + + "}", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159752 +public void test1061() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "predicate/Predicate.java", // ================= + "package predicate;\n" + + "public interface Predicate {\n" + + " public boolean evaluate(T object);\n" + + "}\n" + + "final class AndPredicate implements Predicate {\n" + + " private final Predicate iPredicate1;\n" + + " private final Predicate iPredicate2;\n" + + " public static Predicate getInstance(Predicate predicate1,\n" + + " Predicate predicate2) {\n" + + " if (predicate1 == null || predicate2 == null) {\n" + + " throw new IllegalArgumentException(\"Predicate must not be null\");\n" + + " }\n" + + " return new AndPredicate(predicate1, predicate2);\n" + + " }\n" + + " public AndPredicate(Predicate predicate1,\n" + + " Predicate predicate2) {\n" + + " super();\n" + + " iPredicate1 = predicate1;\n" + + " iPredicate2 = predicate2;\n" + + " }\n" + + " public boolean evaluate(T object) {\n" + + " return iPredicate1.evaluate(object) && iPredicate2.evaluate(object);\n" + + " }\n" + + "}\n" + + "class PredicateUtils {\n" + + "\n" + + " public static Predicate andPredicate(\n" + + " Predicate predicate1, Predicate predicate2) {\n" + + " return AndPredicate.getInstance(predicate1, predicate2);\n" + + " }\n" + + "}", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 +public void test1062() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.HashSet;\n" + + "import java.util.Iterator;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Set set = new HashSet();\n" + + " for (Iterator iterator = set.iterator(); iterator.hasNext();) {\n" + + " Set element1 = iterator.next();\n" + + " Set element2 = (Set) iterator.next(); // warning\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Set element1 = iterator.next();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to Set\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " Set element2 = (Set) iterator.next(); // warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to Set\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 - variation +public void test1063() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.HashSet;\n" + + "import java.util.Iterator;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Set set = new HashSet();\n" + + " for (Iterator iterator = set.iterator(); iterator.hasNext();) {\n" + + " Set element1 = iterator.next();\n" + + " Set element2 = (Set) iterator.next(); // warning\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Set element1 = iterator.next();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Cloneable to Set\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " Set element2 = (Set) iterator.next(); // warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Cloneable to Set\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148041 - variation +public void test1064() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.HashSet;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " HashSet set = new HashSet();\n" + + " for (Iterator iterator = set.iterator(); iterator.hasNext();) {\n" + + " HashSet element1 = iterator.next();\n" + + " HashSet element2 = (HashSet) iterator.next();\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " HashSet element1 = iterator.next();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to HashSet\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " HashSet element2 = (HashSet) iterator.next();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to HashSet\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141289 - variation +public void test1065() throws Exception { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", // ================= + "public class X {\n" + + " void testFoo(boolean t, A a, B b) {\n" + + " System.out.print((t ? a : b).foo());\n" + + " }\n" + + " void testBar(boolean t, A a, B b) {\n" + + " System.out.print((t ? a : b).bar());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " A a = new A();\n" + + " B b = new B();\n" + + " x.testFoo(true, a, b);\n" + + " x.testFoo(false, a, b);\n" + + " x.testBar(true, a, b);\n" + + " x.testBar(false, a, b);\n" + + " }\n" + + "}\n" + + "interface Foo { String foo(); }\n" + + "interface Bar { String bar(); }\n" + + "class A implements Foo, Bar {\n" + + " public String foo() { return \"[A#foo()]\"; }\n" + + " public String bar() { return \"[A#bar()]\"; }\n" + + "}\n" + + "class B implements Foo, Bar {\n" + + " public String foo() { return \"[B#foo()]\"; }\n" + + " public String bar() { return \"[B#bar()]\"; }\n" + + "}\n", // ================= + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "[A#foo()][B#foo()][A#bar()][B#bar()]" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); + // check presence of checkcast in #testFoo() and #testBar() + String expectedOutput = this.complianceLevel == ClassFileConstants.JDK1_5 + ? " // Method descriptor #15 (ZLA;LB;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void testFoo(boolean t, A a, B b);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 iload_1 [t]\n" + + " 4 ifeq 11\n" + + " 7 aload_2 [a]\n" + + " 8 goto 12\n" + + " 11 aload_3 [b]\n" + + " 12 invokeinterface Foo.foo() : java.lang.String [22] [nargs: 1]\n" + + " 17 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 20, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 21] local: this index: 0 type: X\n" + + " [pc: 0, pc: 21] local: t index: 1 type: boolean\n" + + " [pc: 0, pc: 21] local: a index: 2 type: A\n" + + " [pc: 0, pc: 21] local: b index: 3 type: B\n" + + " \n" + + " // Method descriptor #15 (ZLA;LB;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void testBar(boolean t, A a, B b);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 iload_1 [t]\n" + + " 4 ifeq 11\n" + + " 7 aload_2 [a]\n" + + " 8 goto 12\n" + + " 11 aload_3 [b]\n" + + " 12 checkcast Bar [41]\n" + + " 15 invokeinterface Bar.bar() : java.lang.String [43] [nargs: 1]\n" + + " 20 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + + " 23 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 23, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 24] local: this index: 0 type: X\n" + + " [pc: 0, pc: 24] local: t index: 1 type: boolean\n" + + " [pc: 0, pc: 24] local: a index: 2 type: A\n" + + " [pc: 0, pc: 24] local: b index: 3 type: B\n" + : " // Method descriptor #15 (ZLA;LB;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void testFoo(boolean t, A a, B b);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 iload_1 [t]\n" + + " 4 ifeq 11\n" + + " 7 aload_2 [a]\n" + + " 8 goto 12\n" + + " 11 aload_3 [b]\n" + + " 12 invokeinterface Foo.foo() : java.lang.String [22] [nargs: 1]\n" + + " 17 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 20, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 21] local: this index: 0 type: X\n" + + " [pc: 0, pc: 21] local: t index: 1 type: boolean\n" + + " [pc: 0, pc: 21] local: a index: 2 type: A\n" + + " [pc: 0, pc: 21] local: b index: 3 type: B\n" + + " Stack map table: number of frames 2\n" + + " [pc: 11, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + + " [pc: 12, full, stack: {java.io.PrintStream, Foo}, locals: {X, int, A, B}]\n" + + " \n" + + " // Method descriptor #15 (ZLA;LB;)V\n" + + " // Stack: 2, Locals: 4\n" + + " void testBar(boolean t, A a, B b);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 iload_1 [t]\n" + + " 4 ifeq 11\n" + + " 7 aload_2 [a]\n" + + " 8 goto 12\n" + + " 11 aload_3 [b]\n" + + " 12 checkcast Bar [46]\n" + + " 15 invokeinterface Bar.bar() : java.lang.String [48] [nargs: 1]\n" + + " 20 invokevirtual java.io.PrintStream.print(java.lang.String) : void [28]\n" + + " 23 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 23, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 24] local: this index: 0 type: X\n" + + " [pc: 0, pc: 24] local: t index: 1 type: boolean\n" + + " [pc: 0, pc: 24] local: a index: 2 type: A\n" + + " [pc: 0, pc: 24] local: b index: 3 type: B\n" + + " Stack map table: number of frames 2\n" + + " [pc: 11, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + + " [pc: 12, full, stack: {java.io.PrintStream, Foo}, locals: {X, int, A, B}]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=141289 - variation +public void test1066() throws Exception { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " List l = new ArrayList();\n" + + " l.add(\"zork\");\n" + + " List la = l;\n" + + " List lb = l;\n" + + " boolean t = true, f = false;\n" + + " try {\n" + + " System.out.print((t ? la.get(0) : lb.get(0)).foo());\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":foo(1)]\");\n" + + " } \n" + + " try {\n" + + " System.out.print((f ? la.get(0) : lb.get(0)).foo());\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":foo(2)]\");\n" + + " } \n" + + " try {\n" + + " System.out.print((t ? la.get(0) : lb.get(0)).bar());\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":bar(1)]\");\n" + + " } \n" + + " try {\n" + + " System.out.print((f ? la.get(0) : lb.get(0)).bar());\n" + + " } catch (Throwable e) {\n" + + " System.out.print(\"[\" + e.getClass().getSimpleName() + \":bar(2)]\");\n" + + " } \n" + + " }\n" + + "}\n" + + "interface Foo { String foo(); }\n" + + "interface Bar { String bar(); }\n" + + "abstract class A implements Foo, Bar { }\n" + + "abstract class B implements Foo, Bar { }\n", // ================= + }, + "[ClassCastException:foo(1)][ClassCastException:foo(2)][ClassCastException:bar(1)][ClassCastException:bar(2)]"); + // check presence of checkcast + String expectedOutput = this.complianceLevel == ClassFileConstants.JDK1_5 + ? " // Stack: 4, Locals: 8\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 invokespecial X() [16]\n" + + " 7 astore_1 [x]\n" + + " 8 new java.util.ArrayList [17]\n" + + " 11 dup\n" + + " 12 invokespecial java.util.ArrayList() [19]\n" + + " 15 astore_2 [l]\n" + + " 16 aload_2 [l]\n" + + " 17 ldc [20]\n" + + " 19 invokeinterface java.util.List.add(java.lang.Object) : boolean [22] [nargs: 2]\n" + + " 24 pop\n" + + " 25 aload_2 [l]\n" + + " 26 astore_3 [la]\n" + + " 27 aload_2 [l]\n" + + " 28 astore 4 [lb]\n" + + " 30 iconst_1\n" + + " 31 istore 5 [t]\n" + + " 33 iconst_0\n" + + " 34 istore 6 [f]\n" + + " 36 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 39 iload 5 [t]\n" + + " 41 ifeq 57\n" + + " 44 aload_3 [la]\n" + + " 45 iconst_0\n" + + " 46 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 51 checkcast Foo [38]\n" + + " 54 goto 68\n" + + " 57 aload 4 [lb]\n" + + " 59 iconst_0\n" + + " 60 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 65 checkcast Foo [38]\n" + + " 68 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + + " 73 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 76 goto 115\n" + + " 79 astore 7 [e]\n" + + " 81 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 84 new java.lang.StringBuilder [50]\n" + + " 87 dup\n" + + " 88 ldc [52]\n" + + " 90 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 93 aload 7 [e]\n" + + " 95 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 98 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 101 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 104 ldc [69]\n" + + " 106 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 109 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 112 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 115 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 118 iload 6 [f]\n" + + " 120 ifeq 136\n" + + " 123 aload_3 [la]\n" + + " 124 iconst_0\n" + + " 125 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 130 checkcast Foo [38]\n" + + " 133 goto 147\n" + + " 136 aload 4 [lb]\n" + + " 138 iconst_0\n" + + " 139 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 144 checkcast Foo [38]\n" + + " 147 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + + " 152 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 155 goto 194\n" + + " 158 astore 7 [e]\n" + + " 160 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 163 new java.lang.StringBuilder [50]\n" + + " 166 dup\n" + + " 167 ldc [52]\n" + + " 169 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 172 aload 7 [e]\n" + + " 174 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 177 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 180 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 183 ldc [74]\n" + + " 185 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 188 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 191 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 194 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 197 iload 5 [t]\n" + + " 199 ifeq 215\n" + + " 202 aload_3 [la]\n" + + " 203 iconst_0\n" + + " 204 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 209 checkcast Foo [38]\n" + + " 212 goto 226\n" + + " 215 aload 4 [lb]\n" + + " 217 iconst_0\n" + + " 218 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 223 checkcast Foo [38]\n" + + " 226 checkcast Bar [76]\n" + + " 229 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + + " 234 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 237 goto 276\n" + + " 240 astore 7 [e]\n" + + " 242 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 245 new java.lang.StringBuilder [50]\n" + + " 248 dup\n" + + " 249 ldc [52]\n" + + " 251 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 254 aload 7 [e]\n" + + " 256 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 259 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 262 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 265 ldc [81]\n" + + " 267 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 270 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 273 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 276 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 279 iload 6 [f]\n" + + " 281 ifeq 297\n" + + " 284 aload_3 [la]\n" + + " 285 iconst_0\n" + + " 286 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 291 checkcast Foo [38]\n" + + " 294 goto 308\n" + + " 297 aload 4 [lb]\n" + + " 299 iconst_0\n" + + " 300 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 305 checkcast Foo [38]\n" + + " 308 checkcast Bar [76]\n" + + " 311 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + + " 316 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 319 goto 358\n" + + " 322 astore 7 [e]\n" + + " 324 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 327 new java.lang.StringBuilder [50]\n" + + " 330 dup\n" + + " 331 ldc [52]\n" + + " 333 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 336 aload 7 [e]\n" + + " 338 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 341 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 344 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 347 ldc [83]\n" + + " 349 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 352 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 355 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 358 return\n" + + " Exception Table:\n" + + " [pc: 36, pc: 76] -> 79 when : java.lang.Throwable\n" + + " [pc: 115, pc: 155] -> 158 when : java.lang.Throwable\n" + + " [pc: 194, pc: 237] -> 240 when : java.lang.Throwable\n" + + " [pc: 276, pc: 319] -> 322 when : java.lang.Throwable\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " [pc: 25, line: 7]\n" + + " [pc: 27, line: 8]\n" + + " [pc: 30, line: 9]\n" + + " [pc: 36, line: 11]\n" + + " [pc: 76, line: 12]\n" + + " [pc: 81, line: 13]\n" + + " [pc: 115, line: 16]\n" + + " [pc: 155, line: 17]\n" + + " [pc: 160, line: 18]\n" + + " [pc: 194, line: 21]\n" + + " [pc: 237, line: 22]\n" + + " [pc: 242, line: 23]\n" + + " [pc: 276, line: 26]\n" + + " [pc: 319, line: 27]\n" + + " [pc: 324, line: 28]\n" + + " [pc: 358, line: 30]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 359] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 359] local: x index: 1 type: X\n" + + " [pc: 16, pc: 359] local: l index: 2 type: java.util.List\n" + + " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + + " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + + " [pc: 33, pc: 359] local: t index: 5 type: boolean\n" + + " [pc: 36, pc: 359] local: f index: 6 type: boolean\n" + + " [pc: 81, pc: 115] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 160, pc: 194] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 242, pc: 276] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 324, pc: 358] local: e index: 7 type: java.lang.Throwable\n" + + " Local variable type table:\n" + + " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + + " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + : " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 8\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 invokespecial X() [16]\n" + + " 7 astore_1 [x]\n" + + " 8 new java.util.ArrayList [17]\n" + + " 11 dup\n" + + " 12 invokespecial java.util.ArrayList() [19]\n" + + " 15 astore_2 [l]\n" + + " 16 aload_2 [l]\n" + + " 17 ldc [20]\n" + + " 19 invokeinterface java.util.List.add(java.lang.Object) : boolean [22] [nargs: 2]\n" + + " 24 pop\n" + + " 25 aload_2 [l]\n" + + " 26 astore_3 [la]\n" + + " 27 aload_2 [l]\n" + + " 28 astore 4 [lb]\n" + + " 30 iconst_1\n" + + " 31 istore 5 [t]\n" + + " 33 iconst_0\n" + + " 34 istore 6 [f]\n" + + " 36 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 39 iload 5 [t]\n" + + " 41 ifeq 57\n" + + " 44 aload_3 [la]\n" + + " 45 iconst_0\n" + + " 46 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 51 checkcast Foo [38]\n" + + " 54 goto 68\n" + + " 57 aload 4 [lb]\n" + + " 59 iconst_0\n" + + " 60 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 65 checkcast Foo [38]\n" + + " 68 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + + " 73 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 76 goto 115\n" + + " 79 astore 7 [e]\n" + + " 81 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 84 new java.lang.StringBuilder [50]\n" + + " 87 dup\n" + + " 88 ldc [52]\n" + + " 90 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 93 aload 7 [e]\n" + + " 95 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 98 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 101 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 104 ldc [69]\n" + + " 106 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 109 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 112 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 115 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 118 iload 6 [f]\n" + + " 120 ifeq 136\n" + + " 123 aload_3 [la]\n" + + " 124 iconst_0\n" + + " 125 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 130 checkcast Foo [38]\n" + + " 133 goto 147\n" + + " 136 aload 4 [lb]\n" + + " 138 iconst_0\n" + + " 139 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 144 checkcast Foo [38]\n" + + " 147 invokeinterface Foo.foo() : java.lang.String [40] [nargs: 1]\n" + + " 152 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 155 goto 194\n" + + " 158 astore 7 [e]\n" + + " 160 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 163 new java.lang.StringBuilder [50]\n" + + " 166 dup\n" + + " 167 ldc [52]\n" + + " 169 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 172 aload 7 [e]\n" + + " 174 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 177 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 180 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 183 ldc [74]\n" + + " 185 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 188 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 191 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 194 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 197 iload 5 [t]\n" + + " 199 ifeq 215\n" + + " 202 aload_3 [la]\n" + + " 203 iconst_0\n" + + " 204 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 209 checkcast Foo [38]\n" + + " 212 goto 226\n" + + " 215 aload 4 [lb]\n" + + " 217 iconst_0\n" + + " 218 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 223 checkcast Foo [38]\n" + + " 226 checkcast Bar [76]\n" + + " 229 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + + " 234 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 237 goto 276\n" + + " 240 astore 7 [e]\n" + + " 242 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 245 new java.lang.StringBuilder [50]\n" + + " 248 dup\n" + + " 249 ldc [52]\n" + + " 251 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 254 aload 7 [e]\n" + + " 256 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 259 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 262 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 265 ldc [81]\n" + + " 267 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 270 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 273 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 276 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 279 iload 6 [f]\n" + + " 281 ifeq 297\n" + + " 284 aload_3 [la]\n" + + " 285 iconst_0\n" + + " 286 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 291 checkcast Foo [38]\n" + + " 294 goto 308\n" + + " 297 aload 4 [lb]\n" + + " 299 iconst_0\n" + + " 300 invokeinterface java.util.List.get(int) : java.lang.Object [34] [nargs: 2]\n" + + " 305 checkcast Foo [38]\n" + + " 308 checkcast Bar [76]\n" + + " 311 invokeinterface Bar.bar() : java.lang.String [78] [nargs: 1]\n" + + " 316 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 319 goto 358\n" + + " 322 astore 7 [e]\n" + + " 324 getstatic java.lang.System.out : java.io.PrintStream [28]\n" + + " 327 new java.lang.StringBuilder [50]\n" + + " 330 dup\n" + + " 331 ldc [52]\n" + + " 333 invokespecial java.lang.StringBuilder(java.lang.String) [54]\n" + + " 336 aload 7 [e]\n" + + " 338 invokevirtual java.lang.Object.getClass() : java.lang.Class [56]\n" + + " 341 invokevirtual java.lang.Class.getSimpleName() : java.lang.String [60]\n" + + " 344 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 347 ldc [83]\n" + + " 349 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [65]\n" + + " 352 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [71]\n" + + " 355 invokevirtual java.io.PrintStream.print(java.lang.String) : void [44]\n" + + " 358 return\n" + + " Exception Table:\n" + + " [pc: 36, pc: 76] -> 79 when : java.lang.Throwable\n" + + " [pc: 115, pc: 155] -> 158 when : java.lang.Throwable\n" + + " [pc: 194, pc: 237] -> 240 when : java.lang.Throwable\n" + + " [pc: 276, pc: 319] -> 322 when : java.lang.Throwable\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " [pc: 25, line: 7]\n" + + " [pc: 27, line: 8]\n" + + " [pc: 30, line: 9]\n" + + " [pc: 36, line: 11]\n" + + " [pc: 76, line: 12]\n" + + " [pc: 81, line: 13]\n" + + " [pc: 115, line: 16]\n" + + " [pc: 155, line: 17]\n" + + " [pc: 160, line: 18]\n" + + " [pc: 194, line: 21]\n" + + " [pc: 237, line: 22]\n" + + " [pc: 242, line: 23]\n" + + " [pc: 276, line: 26]\n" + + " [pc: 319, line: 27]\n" + + " [pc: 324, line: 28]\n" + + " [pc: 358, line: 30]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 359] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 359] local: x index: 1 type: X\n" + + " [pc: 16, pc: 359] local: l index: 2 type: java.util.List\n" + + " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + + " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + + " [pc: 33, pc: 359] local: t index: 5 type: boolean\n" + + " [pc: 36, pc: 359] local: f index: 6 type: boolean\n" + + " [pc: 81, pc: 115] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 160, pc: 194] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 242, pc: 276] local: e index: 7 type: java.lang.Throwable\n" + + " [pc: 324, pc: 358] local: e index: 7 type: java.lang.Throwable\n" + + " Local variable type table:\n" + + " [pc: 27, pc: 359] local: la index: 3 type: java.util.List\n" + + " [pc: 30, pc: 359] local: lb index: 4 type: java.util.List\n" + + " Stack map table: number of frames 16\n" + + " [pc: 57, full, stack: {java.io.PrintStream}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + + " [pc: 68, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + + " [pc: 79, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 115, same]\n" + + " [pc: 136, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + + " [pc: 147, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + + " [pc: 158, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 194, same]\n" + + " [pc: 215, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + + " [pc: 226, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + + " [pc: 240, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 276, same]\n" + + " [pc: 297, same_locals_1_stack_item, stack: {java.io.PrintStream}]\n" + + " [pc: 308, full, stack: {java.io.PrintStream, Foo}, locals: {java.lang.String[], X, java.util.List, java.util.List, java.util.List, int, int}]\n" + + " [pc: 322, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 358, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162991 +// using only source types +public void test1067() { + this.runConformTest( + new String[] { + "Something.java", + "public interface Something {\n" + + "\n" + + "}", // ================= + "Doing.java", // ================= + "public interface Doing {\n" + + " public T get(Class clazz);\n" + + "}", // ================= + "DoingImpl.java", // ================= + "public class DoingImpl implements Doing {\n" + + " public T get(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}" // ================= + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162991 +// using source and binary types +public void test1068() { + this.runConformTest( + new String[] { + "Something.java", + "public interface Something {\n" + + "\n" + + "}", // ================= + "Doing.java", // ================= + "public interface Doing {\n" + + " public T get(Class clazz);\n" + + "}", // ================= + }, + ""); + this.runConformTest( + new String[] { + "DoingImpl.java", // ================= + "public class DoingImpl implements Doing {\n" + + " public T get(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}" // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163262 +public void test1069() { + this.runConformTest( + new String[] { + "Bug.java", // ================= + "public class Bug {\n" + + " void bug() {\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " Bug bug = Bug.this;\n" + + " }\n" + + " };\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163262 +public void test1070() { + this.runConformTest( + new String[] { + "Bug.java", // ================= + "public class Bug {\n" + + " Bug reproduce() {\n" + + " return Bug.this;\n" + + " }\n" + + "}", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 +public void test1071() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " List x = null;\n" + + " void[] y;\n" + + " void[] foo(void[] arg) {\n" + + " void[] local;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " List x = null;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " void[] y;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " void[] local;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 +public void test1072() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " List x = null;\n" + + " void[] y;\n" + + " void[] foo(void[] arg) {\n" + + " void[] local;\n" + + " Class c = void[].class;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " List x = null;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " void[] y;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " void[] local;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " Class c = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 +public void test1073() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " List x = null;\n" + + " void[] y;\n" + + " void[] foo(void[] arg) {\n" + + " try {\n" + + " void[] local;\n" + + " Class c = void[].class;\n" + + " } catch(void[] e) {\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " List x = null;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " void[] y;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " void[] local;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " Class c = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "7. ERROR in X.java (at line 9)\n" + + " } catch(void[] e) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159939 +public void test1074() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " List x = null;\n" + + " void[] y;\n" + + " void[] foo(void[] arg) {\n" + + " try {\n" + + " void[] local = new void[0];\n" + + " void[] local1 = new void[]{ null, null };\n" + + " void[] local2 = { null, null };\n" + + " System.out.println((void[]) null);\n" + + " Class c = void[].class;\n" + + " } catch(void[] e) {\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " List x = null;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " void[] y;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " void[] foo(void[] arg) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " void[] local = new void[0];\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " void[] local = new void[0];\n" + + " ^^^^^^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "7. ERROR in X.java (at line 8)\n" + + " void[] local1 = new void[]{ null, null };\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "8. ERROR in X.java (at line 8)\n" + + " void[] local1 = new void[]{ null, null };\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "9. ERROR in X.java (at line 9)\n" + + " void[] local2 = { null, null };\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "10. ERROR in X.java (at line 10)\n" + + " System.out.println((void[]) null);\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "11. ERROR in X.java (at line 11)\n" + + " Class c = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "12. ERROR in X.java (at line 12)\n" + + " } catch(void[] e) {\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n", + null, + true, + options); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163680 +public void test1075() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X .J>{\n" + + " public class J implements I{}\n" + + "}\n", + "I.java", + "public interface I {}\n", + "Y.java", + "public class Y extends X {}\n", + }, + // runtime results + "" /* expected output string */); + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { + "Y.java", + "public class Y extends X {}", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} + +// FAIL ERRMSG +public void test1076() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " List threads;\n" + + " void foo(String[] strings) {}\n" + + " void bar() {\n" + + " foo(this.threads.toArray(new String[this.threads.size()]));\n" + + " foo(myToArray(this.threads, new String[this.threads.size()]));\n" + + " foo(myToArray2(this.threads, new String[this.threads.size()]));\n" + + " }\n" + + " \n" + + " static T[] myToArray(List list, T[] a) {\n" + + " return list.toArray(a);\n" + + " }\n" + + " static T[] myToArray2(List list, T[] a) {\n" + + " return list.toArray(a);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " foo(myToArray2(this.threads, new String[this.threads.size()]));\n" + + " ^^^^^^^^^^\n" + + "Bound mismatch: The generic method myToArray2(List, T[]) of type X is not applicable for the arguments (List, String[]). The inferred type Thread is not a valid substitute for the bounded parameter \n" + + "----------\n"); +} +// check presence of field hiding warning +public void test1077() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Y {\n" + + " static int foo;\n" + + " }\n" + + " static class Z extends Y {\n" + + " int foo;\n" + + " {\n" + + " foo = 1;\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " int foo;\n" + + " ^^^\n" + + "The field X.Z.foo is hiding a field from type X.Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 +public void test1078() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X \n" + + "{\n" + + " public static void main(String[] args)\n" + + " {\n" + + " Object object = null;\n" + + "\n" + + " List list = (List)object;//[1]\n" + + "\n" + + " foo((List)object);//[2]\n" + + " foo((List)object);//[3]\n" + + " foo((List)object);//[4]unchecked cast\n" + + " foo((List)object);//[5]\n" + + "\n" + + " foo((Map)object);//[6]\n" + + " foo((Map)object);//[7]\n" + + " foo((Map)object);//[8]unchecked cast\n" + + " foo((Map)object);//[9]unchecked cast\n" + + " foo((Map)object);//[10]unchecked cast\n" + + " foo((Map)object);//[11]unchecked cast\n" + + " foo((Map)object);//[12]\n" + + " Zork z;\n" + + " }\n" + + "\n" + + " public static void foo(List list) {\n" + + " }\n" + + "\n" + + " public static void foo(Map map) {\n" + + " }\n" + + "}", // =================, + }, + // unchecked warnings on [4][5][8][9][10][11][12] + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " List list = (List)object;//[1]\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " List list = (List)object;//[1]\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " foo((List)object);//[2]\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 14)\n" + + " foo((List)object);//[4]unchecked cast\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " foo((List)object);//[5]\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "6. WARNING in X.java (at line 17)\n" + + " foo((Map)object);//[6]\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 19)\n" + + " foo((Map)object);//[8]unchecked cast\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map\n" + + "----------\n" + + "8. WARNING in X.java (at line 20)\n" + + " foo((Map)object);//[9]unchecked cast\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map\n" + + "----------\n" + + "9. WARNING in X.java (at line 21)\n" + + " foo((Map)object);//[10]unchecked cast\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map\n" + + "----------\n" + + "10. WARNING in X.java (at line 22)\n" + + " foo((Map)object);//[11]unchecked cast\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map\n" + + "----------\n" + + "11. WARNING in X.java (at line 23)\n" + + " foo((Map)object);//[12]\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map\n" + + "----------\n" + + "12. ERROR in X.java (at line 24)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation +public void test1079() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar(Object o) {\n" + + " return (AX) o;\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "class AX extends X {}\n", // =================, + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return (AX) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to AX\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation +public void test1080() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " CX foo(X x) {\n" + + " return (CX) x; // unchecked\n" + + " }\n" + + " BX bar(X x) {\n" + + " return (BX) x;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class AX extends X {}\n" + + "class BX extends AX {}\n" + + "class CX extends AX {}\n", // =================, + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return (CX) x; // unchecked\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to CX\n" + + "----------\n" + + "2. 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=165143 - variation +public void test1081() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " AX foo(X x) {\n" + + " return (BX) x;\n" + + " }\n" + + "}\n" + + "class AX extends X {}\n" + + "class BX extends AX {}\n", // =================, + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return (BX) x;\n" + + " ^^^^^^\n" + + "Cannot cast from X to BX\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165143 - variation +public void test1082() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " CX foo(X x) {\n" + + " return (CX) x; // unchecked\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "class AX extends X {}\n" + + "class CX extends AX {}\n", // =================, + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return (CX) x; // unchecked\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to CX\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " class CX extends AX {}\n" + + " ^^\n" + + "AX is a raw type. References to generic type AX should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106451 - variation +public void test1083() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.io.Serializable;\n" + + "import java.util.LinkedList;\n" + + "\n" + + "class SerializableList extends LinkedList {\n" + + " private static final long serialVersionUID = 1L; \n" + + "}\n" + + "public class X {\n" + + " @SuppressWarnings({\"nls\", \"unused\"})\n" + + " public static void main(String[] args) {\n" + + " LinkedList linkedList= new LinkedList();\n" + + " linkedList.add(\"Hello\");\n" + + " java.util.List a = linkedList;\n" + + " java.util.List b = (LinkedList) a; // unchecked\n" + + " java.util.List c = (LinkedList) a; // unchecked\n" + + " java.util.List d = (LinkedList) a; // inconvertible / unchecked ?\n" + + " c.get(0).intValue(); // fails at run time\n" + + " d.get(0).gc(); // fails at run time\n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " java.util.List b = (LinkedList) a; // unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to LinkedList\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " java.util.List c = (LinkedList) a; // unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to LinkedList\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " java.util.List d = (LinkedList) a; // inconvertible / unchecked ?\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to LinkedList\n" + + "----------\n" + + "4. ERROR in X.java (at line 18)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 +public void test1084() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + "}\n" + + "class Z {\n" + + "}\n" + + "class X {\n" + + " void foo() {\n" + + " Z> l1 = null;\n" + + " Z l2 = (Z) l1;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " Z l2 = (Z) l1;\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Z l2 = (Z) l1;\n" + + " ^^^^^^^^^\n" + + "Cannot cast from Z> to Z\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " Z l2 = (Z) l1;\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165291 +public void test1085() { + this.runNegativeTest( + new String[] { + "Y.java", + "class Z {\n" + + " Z z1 = z1;\n" + + " Z[] z2 = z2;\n" + + "}\n" + + "public class Y {\n" + + " E e0 = es[0];\n" + + " E e = e;\n" + + " E[] es = es;\n" + + " E e2 = e2.e;\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in Y.java (at line 2)\n" + + " Z z1 = z1;\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "2. ERROR in Y.java (at line 3)\n" + + " Z[] z2 = z2;\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "3. ERROR in Y.java (at line 6)\n" + + " E e0 = es[0];\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "4. ERROR in Y.java (at line 7)\n" + + " E e = e;\n" + + " ^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "5. ERROR in Y.java (at line 8)\n" + + " E[] es = es;\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "6. ERROR in Y.java (at line 9)\n" + + " E e2 = e2.e;\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "7. ERROR in Y.java (at line 9)\n" + + " E e2 = e2.e;\n" + + " ^\n" + + "e cannot be resolved or is not a field\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165645 +public void test1086() { + this.runNegativeTest( + new String[] { + "X.java", + "interface IFoo { void foo(); }\n" + + "interface IBar { void bar(); }\n" + + "public class X {\n" + + " class Bar implements IBar { public void bar(){} }\n" + + " void foo(Bar b) {\n" + + " b.foo(); // unbound (Bar is member type)\n" + + " b.bar(); // ok\n" + + " }\n" + + "}\n", // =================, + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " b.foo(); // unbound (Bar is member type)\n" + + " ^^^\n" + + "The method foo() is undefined for the type X.Bar\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165645 - variation +public void test1087() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static public class M {\n" + + " }\n" + + " static public class M2 extends M {\n" + + " }\n" + + "}\n" + + "\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165679 +public void test1088() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static public class M {}\n" + + " Zork z;\n" + + " void foo() {\n" + + " class M {} // hides member\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " class Local {}\n" + + " void foo() {\n" + + " class T {}; // hiding warning\n" + + " class Local {};\n" + + " }\n" + + " static void bar() {\n" + + " class T {}; // no hiding warning\n" + + " class Local {}; // no hiding warning\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " class M {} // hides member\n" + + " ^\n" + + "The type M is hiding the type X.M\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " class T {}; // hiding warning\n" + + " ^\n" + + "The nested type T is hiding the type parameter T of type Y\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " class Local {};\n" + + " ^^^^^\n" + + "The type Local is hiding the type Y.Local\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165679 - variation +public void test1089() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class U {}\n" + + " void foo(T t) {\n" + + " class T {\n" + + " T t = t;\n" + + " }\n" + + " class U {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class T {\n" + + " ^\n" + + "The nested type T is hiding the type parameter T of the generic method foo(T) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " T t = t;\n" + + " ^\n" + + "The field T.t is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " T t = t;\n" + + " ^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " class U {\n" + + " ^\n" + + "The type U is hiding the type X.U\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165679 - variation +public void _test1090() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class T {} // warn hiding type parameter\n" + + " class U {}// warn hiding type parameter+warn param hiding member type\n" + + " \n" + + " void foo() {\n" + + " class Local {\n" + + " class T {} // warn hiding type parameter\n" + + " class U {}// warn hiding type parameter+warn param hiding member type\n" + + " }\n" + + " }\n" + + " static void bar() {\n" + + " class Local {\n" + + " class T {} // no warn\n" + + " class U {} // no warn\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "???"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165909 +public void test1091() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " Object a = null;\n" + + " Map.Entry aa = (Map.Entry)a; \n" + + " }\n" + + " void bar() {\n" + + " Number a = null;\n" + + " Map.Entry aa = (Map.Entry)a; \n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Map.Entry aa = (Map.Entry)a; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Map.Entry\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " Map.Entry aa = (Map.Entry)a; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Number to Map.Entry\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=166490 +public void test1092() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "Class_01.java", + "public interface Class_01> extends\n" + + " Class_09 {\n" + + "}", + "Class_02.java", + "public interface Class_02> extends\n" + + " Class_10 {\n" + + "}", + "Class_03.java", + "public abstract class Class_03, H extends Class_02, P extends Class_06>\n" + + " extends Class_08 implements Class_05 {\n" + + "}", + "Class_04.java", + "public interface Class_04 extends Class_06, Class_19{\n" + + "}", + "Class_05.java", + "public interface Class_05{\n" + + "}", + "Class_06.java", + "public interface Class_06> extends\n" + + " Class_13, Class_17 {\n" + + "}", + "Class_07.java", + "public interface Class_07

> extends\n" + + " Class_14 {\n" + + "}", + "Class_08.java", + "public abstract class Class_08, H extends Class_10, P extends Class_06>\n" + + " extends Class_11 implements Class_05 {\n" + + "}", + "Class_09.java", + "public interface Class_09> extends\n" + + " Class_13, Class_17 {\n" + + "}", + "Class_10.java", + "public interface Class_10> extends\n" + + " Class_14 {\n" + + "}", + "Class_11.java", + "public abstract class Class_11, H extends Class_14, O>\n" + + " extends Class_15 implements Class_05 {\n" + + "}", + "Class_12.java", + "public final class Class_12 {\n" + + "}", + "Class_13.java", + "public interface Class_13, O>{\n" + + "}", + "Class_14.java", + "public interface Class_14, O>{\n" + + "}", + "Class_15.java", + "public abstract class Class_15, H extends Class_14, O>\n" + + " extends Class_16 {\n" + + "}", + "Class_16.java", + "public abstract class Class_16{\n" + + "}", + "Class_17.java", + "public interface Class_17{\n" + + "}", + "Class_18.java", + "public interface Class_18 extends Class_07{\n" + + "}", + "Class_19.java", + "public interface Class_19{\n" + + "}", + "MyClass.java", + "abstract class MyClass, H extends Class_02>\n" + + " extends Class_03 implements Class_05 {\n" + + "}" + }, + "", + null, + true, + null, + customOptions, + null); + + // incremental build + this.runConformTest( + new String[] { + "Class_01.java", + "public interface Class_01> extends\n" + + " Class_09 {\n" + + "}", + }, + "", + null, + false, + null, + customOptions, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=156952 +// invalid bug - regression test only +public void test1093() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " X foo() {\n" + + " return this;\n" + + " }\n" + + " T bar(T p) {\n" + + " return p;\n" + " }\n" + + " public static void main (String args) {\n" + + " X x1 = new X();\n" + + " System.out.println(x1.foo().bar(\"OK\"));\n" + // OK + " X x2 = new X();\n" + + " System.out.println(x2.foo().bar(\"OK\"));\n" + // KO: type safety issue + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 12)\n" + + " System.out.println(x2.foo().bar(\"OK\"));\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method bar(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + customOptions, + false /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + false /* do not perform statements recovery */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=167268 +public void test1094() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "Crazy.java", + "public interface Crazy {}", + "ExampleFactory.java", + "public interface ExampleFactory {\n" + + " Crazy createCrazy();\n" + + "}", + "Other.java", + "public interface Other {}", + "ExampleFactoryImpl.java", + "public class ExampleFactoryImpl implements ExampleFactory {\n" + + " public Crazy createCrazy() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null /* vm arguments*/, + customOptions, + null /* compiler requestor*/); + this.runConformTest( + new String[] { + "ExampleFactoryImpl.java", + "public class ExampleFactoryImpl implements ExampleFactory {\n" + + " public Crazy createCrazy() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + false /* flush output directory */, + null /* vm arguments*/, + customOptions, + null /* compiler requestor*/); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167952 +//invalid bug - regression test only +public void test1095() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.lang.reflect.Constructor;\n" + + "\n" + + "@interface Annot {\n" + + " String message() default \"\"; //$NON-NLS-1$\n" + + "}\n" + + "\n" + + "public class X {\n" + + " X() {\n" + + " }\n" + + " public String getAnnotationValue(Constructor constructor){\n" + + " Annot annotation = constructor.getAnnotation(Annot.class);\n" + + " return (annotation != null) ? annotation.message() : null;\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 11)\n" + + " Annot annotation = constructor.getAnnotation(Annot.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to Annot\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug6400189 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=167952 +//invalid bug - regression test only +public void test1096() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Constructor;\n" + + "\n" + + "@interface Annot {\n" + + " String message() default \"\"; //$NON-NLS-1$\n" + + "}\n" + + "\n" + + "public class X {\n" + + " X() {\n" + + " }\n" + + " public String getAnnotationValue(Constructor constructor){\n" + + " Annot annotation = constructor.getAnnotation(Annot.class);\n" + + " return (annotation != null) ? annotation.message() : null;\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null, + customOptions, + null/* do not perform statements recovery */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=168232 +public void _test1097() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " String[] foo = new String[] {};\n" + + "}" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " String[] foo = new String[] {};\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Syntax error on token(s), misplaced construct(s)\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " String[] foo = new String[] {};\n" + + " ^\n" + + "Syntax error on token \">\", , expected\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=152961 +public void test1098() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " class Y extends Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " private class Y extends A {\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " class Y extends Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest(new String[] { + "X.java", + "public class X { \n" + + " private class A {\n" + + " class B {}\n" + + " }\n" + + " private class Y extends A {\n" + + " }\n" + + " Y.B d = null;\n" + + "}\n" + + "class Y extends Zork {}\n" + }, + errMessage); +} +public void test1099() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public class A {};\n" + + " public class B extends A {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " List l = x.newList(x.new B());\n" + + " for (A a: l) {\n" + + " System.out.println(a);\n" + + " }\n" + + " }\n" + + "\n" + + " public List newList(V... values) {\n" + + " List l = new ArrayList();\n" + + " for (V v : values) {\n" + + " l.add(v);\n" + + " }\n" + + " return l;\n" + + " }\n" + + "\n" + + "}\n" + }, + // compiler results + this.complianceLevel < ClassFileConstants.JDK1_7 ? "" : + "----------\n" + + "1. WARNING in X.java (at line 21)\n" + + " public List 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 */, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170318 +public void test1100() { + this.runNegativeTest(new String[] { + "X.java", + "class X {\n" + + "}\n" + + "class Y {\n" + + " public void foo(final X x) {\n" + + " }\n" + + "}\n" + + "class Z extends Y {\n" + + " public void foo(final X x) {\n" + + " super.foo(x);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " class Z extends Y {\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public void foo(final X x) {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(X) of type Z has the same erasure as foo(X) of type Y but does not override it\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " super.foo(x);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The method foo(X) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=172189 +public void test1101() { + this.runNegativeTest(new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public final class X {\n" + + " public A a;\n" + + " public B b;\n" + + " public X(A pa, B pb) {\n" + + " a = pa;\n" + + " b = pb;\n" + + " }\n" + + " public static X create(A pa, B pb) {\n" + + " return new X(pa, pb);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List> list = new ArrayList>();\n" + + " list.add(X.create(\"\", \"\"));\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " list.add(X.create(\"\", \"\"));\n" + + " ^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174434 +public void test1102() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " X(T t) {\n" + + " }\n" + + "\n" + + " class A {\n" + + " A(T t) {\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X(null);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " new X(null);\n" + + " ^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174434 +public void test1103() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " X(T t) {\n" + + " }\n" + + " X(int i) {\n" + + " this(null);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " this(null);\n" + + " ^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174434 +public void test1104() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " X(T t) { }\n" + + " \n" + + " class A {\n" + + " A(T t) { }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X(null).new A(null);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " new X(null).new A(null);\n" + + " ^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174724 +public void test1105() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class foo = Class.forName(Integer.class.getName());\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Class foo = Class.forName(Integer.class.getName());\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=174766 +public void test1106() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public class Y extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}" + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " public class Y extends Exception {\n" + + " ^^^^^^^^^\n" + + "The generic class X.Y may not subclass java.lang.Throwable\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=172913 +public void test1107() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.HashMap;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " private void processLocks(HashMap locksMap, Object key) {\n" + + " for (Iterator iter = locksMap.keySet().iterator(); iter.hasNext();) {\n" + + " Object call = iter.next();\n" + + " List locks = externLocks((Collection) locksMap.get(call), call);\n" + + " // ...\n" + + " }\n" + + " }\n" + + " private List externLocks(Collection locks, Object call) {\n" + + " List result = new ArrayList();\n" + + " // ..\n" + + " return result;\n" + + " }\n" + + "}\n", + }, + ""); + // ensure only one instance of: checkcast java.util.Collection + String expectedOutput = + " // Method descriptor #15 (Ljava/util/HashMap;Ljava/lang/Object;)V\n" + + " // Stack: 3, Locals: 6\n" + + " private void processLocks(java.util.HashMap locksMap, java.lang.Object key);\n" + + " 0 aload_1 [locksMap]\n" + + " 1 invokevirtual java.util.HashMap.keySet() : java.util.Set [16]\n" + + " 4 invokeinterface java.util.Set.iterator() : java.util.Iterator [22] [nargs: 1]\n" + + " 9 astore_3 [iter]\n" + + " 10 goto 38\n" + + " 13 aload_3 [iter]\n" + + " 14 invokeinterface java.util.Iterator.next() : java.lang.Object [28] [nargs: 1]\n" + + " 19 astore 4 [call]\n" + + " 21 aload_0 [this]\n" + + " 22 aload_1 [locksMap]\n" + + " 23 aload 4 [call]\n" + + " 25 invokevirtual java.util.HashMap.get(java.lang.Object) : java.lang.Object [34]\n" + + " 28 checkcast java.util.Collection [38]\n" + + " 31 aload 4 [call]\n" + + " 33 " + + (isMinimumCompliant(ClassFileConstants.JDK11) ? "invokevirtual" : "invokespecial") + + " X.externLocks(java.util.Collection, java.lang.Object) : java.util.List [40]\n" + + " 36 astore 5\n" + + " 38 aload_3 [iter]\n" + + " 39 invokeinterface java.util.Iterator.hasNext() : boolean [44] [nargs: 1]\n" + + " 44 ifne 13\n" + + " 47 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 13, line: 10]\n" + + " [pc: 21, line: 11]\n" + + " [pc: 38, line: 9]\n" + + " [pc: 47, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 48] local: this index: 0 type: X\n" + + " [pc: 0, pc: 48] local: locksMap index: 1 type: java.util.HashMap\n" + + " [pc: 0, pc: 48] local: key index: 2 type: java.lang.Object\n" + + " [pc: 10, pc: 47] local: iter index: 3 type: java.util.Iterator\n" + + " [pc: 21, pc: 38] local: call index: 4 type: java.lang.Object\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test1108() { + this.runConformTest( + new String[] { + "X.java", + "interface UnaryFunction {\n" + + " public R invoke(A o) throws X;\n" + + "}\n" + + " \n" + + "public class X implements UnaryFunction {\n" + + " public Void invoke(String o) throws RuntimeException {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=176591 +//?: cuts assignment context +public void test1109() { + String xSource = + "class X {\n" + + " public Y foo()\n" + + " {\n" + + " return true ? Z.bar() : null;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + "}\n" + + "class Z {\n" + + " static Y bar() {\n" + + " return null;\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return true ? Z.bar() : null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to Y\n" + + "----------\n"); + } else { + runConformTest( + new String[] { + "X.java", + xSource + }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=176591 +//variant +public void test1110() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public Y foo()\n" + + " {\n" + + " return true ? Z.bar() : null;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + "}\n" + + "class Z {\n" + + " static Y bar() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 +public void test1111() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo(Object o) {\n" + + " return (T) o; // should get unchecked warning\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " try {\n" + + " X s = a.foo(new Object());\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1112() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " A ua = a;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " X s = a.foo;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1113() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X extends A{\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " A ua = this;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " X s = foo;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1114() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X extends A{\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " A ua = this;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " X s = this.foo;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1115() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " public T foo;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " static X ROOT;\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " A ua = a;\n" + + " ua.foo = new Object();\n" + + " try {\n" + + " X s = a.foo.ROOT;\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1116() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "interface I {\n" + + " int CONST = 1;\n" + + "}\n" + + "\n" + + "class Z {\n" + + " T c;\n" + + " Z(T c) {\n" + + " this.c = c;\n" + + " }\n" + + " int foo() {\n" + + " return c.CONST;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X implements Serializable, I {\n" + + " public static void main(String argv[]) {\n" + + " Z z = new Z(new X());\n" + + " Z rawz = z;\n" + + " rawz.c = new Serializable(){};\n" + + " try {\n" + + " z.foo();\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177194 - variation +public void test1117() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Value CONST = null;\n" + + "}\n" + + "class Value {\n" + + " String NAME = \"VALUE\";\n" + + "}\n" + + "class B implements I {\n" + + " B(Value param) {\n" + + " Value v0 = CONST;\n" + + " Value v1 = this.CONST;\n" + + " String s2 = CONST.NAME;\n" + + " Value v3 = I.CONST;\n" + + " Value v4 = B.CONST;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new B(new Value());\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS", + null, + false, + null, + options, + null); + // check the reference to I.CONST is generated as B.CONST, except for v3 still issuing I.CONST + String expectedOutput = + " // Method descriptor #8 (LValue;)V\n" + + " // Signature: (LValue;)V\n" + + " // Stack: 1, Locals: 2\n" + + " B(Value param);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 getstatic B.CONST : Value [15]\n" + + " 7 pop\n" + + " 8 getstatic B.CONST : Value [15]\n" + + " 11 pop\n" + + " 12 getstatic B.CONST : Value [15]\n" + + " 15 getfield Value.NAME : java.lang.String [19]\n" + + " 18 pop\n" + + " 19 getstatic I.CONST : Value [25]\n" + + " 22 pop\n" + + " 23 getstatic B.CONST : Value [15]\n" + + " 26 pop\n" + + " 27 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 4, line: 9]\n" + + " [pc: 8, line: 10]\n" + + " [pc: 12, line: 11]\n" + + " [pc: 19, line: 12]\n" + + " [pc: 23, line: 13]\n" + + " [pc: 27, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 28] local: this index: 0 type: B\n" + + " [pc: 0, pc: 28] local: param index: 1 type: Value\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 28] local: this index: 0 type: B\n" + + " [pc: 0, pc: 28] local: param index: 1 type: Value\n"; + + File f = new File(OUTPUT_DIR + File.separator + "B.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=177715 +public void test1118() { + String source = "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " X() {\n" + + " Class> cls = null;\n" + + " foo(cls);\n" + + " }\n" + + "\n" + + " > T foo(Class pClass) {\n" + + " return null;\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runConformTest( + new String[] { "X.java", source }, + JavacTestOptions.EclipseHasABug.EclipseBug177715 /* javac test options */); + } else { + runNegativeTest( + new String[] { "X.java", source }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " foo(cls);\n" + + " ^^^\n" + + "The method foo(Class) in the type X is not applicable for the arguments (Class>)\n" + + "----------\n"); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169728 +public void test1119() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X & Runnable> {\n" + + " T get() {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " \n" + + " X x1 = null; // error\n" + + " X x2 = null; // error\n" + + " X x3 = null; // ok\n" + + " X x4 = null; // ok\n" + + " \n" + + " foo1(x1); // ok\n" + + " foo1(x2); // ok\n" + + " foo1(x3); // ok\n" + + " foo1(x4); // ok\n" + + "\n" + + " foo2(x1); // error\n" + + " foo2(x2); // error\n" + + " foo2(x3); // error\n" + + " foo2(x4); // ok\n" + + " }\n" + + " \n" + + " static void foo1(X x) {\n" + + " x.get().run(); // ok\n" + + " x.get().compareTo(null); // ok\n" + + " x.get().compareTo(x.get()); // error\n" + + " }\n" + + " static void foo2(X x) {\n" + + " x.get().run(); // ok\n" + + " x.get().compareTo(null); // ok\n" + + " x.get().compareTo(x.get()); // error\n" + + " } \n" + + "}\n" + + "\n" + + "abstract class OnlyRunnable implements Runnable {}\n" + + "abstract class OnlyComparable implements Comparable {}\n" + + "abstract class ComparableRunnable implements Comparable, Runnable {}\n" + + "abstract class ComparableRunnableThrowable extends Throwable implements Comparable, Runnable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X x1 = null; // error\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The type OnlyRunnable is not a valid substitute for the bounded parameter & Runnable> of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " X x2 = null; // error\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type OnlyComparable is not a valid substitute for the bounded parameter & Runnable> of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " X x4 = null; // ok\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ComparableRunnableThrowable is not a valid substitute for the bounded parameter & Runnable> of the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " foo2(x1); // error\n" + + " ^^^^\n" + + "The method foo2(X) in the type X is not applicable for the arguments (X)\n" + + "----------\n" + + "5. ERROR in X.java (at line 18)\n" + + " foo2(x2); // error\n" + + " ^^^^\n" + + "The method foo2(X) in the type X is not applicable for the arguments (X)\n" + + "----------\n" + + "6. ERROR in X.java (at line 19)\n" + + " foo2(x3); // error\n" + + " ^^^^\n" + + "The method foo2(X) in the type X is not applicable for the arguments (X)\n" + + "----------\n" + + "7. ERROR in X.java (at line 26)\n" + + " x.get().compareTo(x.get()); // error\n" + + " ^^^^^^^^^\n" + + "The method compareTo(capture#3-of ?) in the type Comparable is not applicable for the arguments (capture#4-of ?)\n" + + "----------\n" + + "8. ERROR in X.java (at line 31)\n" + + " x.get().compareTo(x.get()); // error\n" + + " ^^^^^^^^^\n" + + "The method compareTo(capture#7-of ? extends Throwable) in the type Comparable is not applicable for the arguments (capture#8-of ? extends Throwable)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=166963 +public void test1120() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X() {\n" + + " System.out.println();\n" + + " this(zork);\n" + + " Zork.this.this();\n" + + " this();\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " this(zork);\n" + + " ^^^^^^^^^^^\n" + + "Constructor call must be the first statement in a constructor\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " this(zork);\n" + + " ^^^^\n" + + "zork cannot be resolved to a variable\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork.this.this();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Constructor call must be the first statement in a constructor\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Zork.this.this();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " this();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 6)\n" + + " this();\n" + + " ^^^^^^^\n" + + "Constructor call must be the first statement in a constructor\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=181270 +public void test1121() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " System.out.println(T[].class);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(T[].class);\n" + + " ^^^^^^^^^\n" + + "Illegal class literal for the type parameter T\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=181270 +public void test1122() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " System.out.println(T[].class);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(T[].class);\n" + + " ^^^^^^^^^\n" + + "Illegal class literal for the type parameter T\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=181270 - variation +public void test1123() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Class c1 = int.class;\n" + + " Class c2 = Integer.class;\n" + + " Class c3 = int[].class;\n" + + " Class c4 = int[].class;\n" + + " Class c5 = void.class;\n" + + " Class c6 = void[].class;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Class c3 = int[].class;\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Class c6 = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Class c6 = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=182192 +public void test1124() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " public static class InnerClassThatShowsBug extends X {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " super(null);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " for (Map.Entry entry : myMap().entrySet()) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from element type Object to Map.Entry\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " public static class InnerClassThatShowsBug extends X {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " super(null);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " super(null);\n" + + " ^^^^^^^^^^^^\n" + + "Access to enclosing constructor X(T) is emulated by a synthetic accessor method\n" + + "----------\n" + + "4. ERROR in X.java (at line 19)\n" + + " for (Map.Entry entry : myMap().entrySet()) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from element type Object to Map.Entry\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X {\n" + + "\n" + + " static protected final Map myMap = new HashMap();\n" + + " private final T theGenericThing;\n" + + "\n" + + " private X(T something) {\n" + + " this.theGenericThing = something;\n" + + " }\n" + + "\n" + + " public static class InnerClassThatShowsBug extends X {\n" + + " public InnerClassThatShowsBug() {\n" + + " super(null);\n" + + " }\n" + + "\n" + + " public void printMap() {\n" + + " for (Map.Entry entry : myMap().entrySet()) {\n" + + " System.out.println(entry.getKey() + \" => \" + entry.getValue());\n" + + " }\n" + + " }\n" + + " protected Map myMap2() {\n" + + " return myMap;\n" + + " }\n" + + " public void printMap2() {\n" + + " for (Map.Entry entry : myMap2().entrySet()) {\n" + + " System.out.println(entry.getKey() + \" => \" + entry.getValue());\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " protected Map myMap() {\n" + + " return myMap;\n" + + " }\n" + + "}", // ================= + }, errMessage); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 +public void test1125() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {\n" + + " class B {\n" + + " T t;\n" + + " T getValue() {\n" + + " return t;\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class C extends A {\n" + + " Zork z;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " static C.B c = new C().new B();\n" + + "\n" + + " public static void main(String[] args) {\n" + + " C.B temp = new C().new B();\n" + + " String s = temp.getValue();\n" + + " System.out.println(s);\n" + + " foo(bar());\n" + + " }\n" + + "\n" + + " static C.B bar() {\n" + + " return new C().new B();\n" + + " }\n" + + "\n" + + " static void foo(C.B arg) {\n" + + " Object o = arg.getValue();\n" + + " Double d = c.getValue();\n" + + " System.out.println(o);\n" + + " System.out.println(d);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " static C.B c = new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 18)\n" + + " C.B temp = new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 25)\n" + + " return new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation +public void test1126() { + this.runConformTest( + new String[] { + "X.java", + "class A {\n" + + " class B {\n" + + " T t;\n" + + " T getValue() {\n" + + " return t;\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " static A.B c = new A().new B();\n" + + "\n" + + " public static void main(String[] args) {\n" + + " A.B temp = new A().new B();\n" + + " String s = temp.getValue();\n" + + " System.out.print(s);\n" + + " foo(bar());\n" + + " }\n" + + "\n" + + " static A.B bar() {\n" + + " return new A().new B();\n" + + " }\n" + + "\n" + + " static void foo(A.B arg) {\n" + + " Object o = arg.getValue();\n" + + " Double d = c.getValue();\n" + + " System.out.print(o);\n" + + " System.out.print(d);\n" + + " }\n" + + "}\n", // ================= + }, + "nullnullnull"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation +public void test1127() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {\n" + + " class B {\n" + + " T t;\n" + + " T getValue() {\n" + + " return t;\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class C extends A {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " static C.B c = new C().new B();\n" + + "\n" + + " public static void main(String[] args) {\n" + + " C.B temp = new C().new B();\n" + + " String s = temp.getValue();\n" + + " System.out.println(s);\n" + + " foo(bar());\n" + + " }\n" + + "\n" + + " static C.B bar() {\n" + + " return new C().new B();\n" + + " }\n" + + "\n" + + " static void foo(C.B arg) {\n" + + " Object o = arg.getValue();\n" + + " Double d = c.getValue();\n" + + " System.out.println(o);\n" + + " System.out.println(d);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " static C.B c = new C().new B();\n" + + " ^^^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " static C.B c = new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " static C.B c = new C().new B();\n" + + " ^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " C.B temp = new C().new B();\n" + + " ^^^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "5. WARNING in X.java (at line 17)\n" + + " C.B temp = new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 17)\n" + + " C.B temp = new C().new B();\n" + + " ^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "7. ERROR in X.java (at line 23)\n" + + " static C.B bar() {\n" + + " ^^^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "8. WARNING in X.java (at line 24)\n" + + " return new C().new B();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "9. ERROR in X.java (at line 24)\n" + + " return new C().new B();\n" + + " ^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "10. ERROR in X.java (at line 27)\n" + + " static void foo(C.B arg) {\n" + + " ^^^\n" + + "The member type A.B must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=183216 - variation +public void test1128() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {\n" + + " class Member {}\n" + + "}\n" + + "\n" + + "public class X extends A {\n" + + " void foo() {\n" + + " new Member();\n" + + " new X().new Member();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public class X extends A {\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " new Member();\n" + + " ^^^^^^\n" + + "The member type A.Member must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " new X().new Member();\n" + + " ^^^^^^\n" + + "The member type A.Member must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); +} +public void test1129() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "abstract class Arg1 implements Comparable, Serializable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n" + + "abstract class Arg2 implements Serializable, Comparable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n" + + "\n" + + "interface IX {}\n" + + "\n" + + "public class X {\n" + + " void foo1(boolean b, IX arg2) {\n" + + " IX o = b ? null : arg2;\n" + + " IX o2 = b ? arg2 : null;\n" + + " }\n" + + " void foo2(boolean b, IX arg1, IX arg2) {\n" + + " String s = b ? arg1 : arg2;\n" + + " }\n" + + " void foo3(boolean b, Arg1 arg1, Arg2 arg2) {\n" + + " String s = b ? arg1 : arg2;\n" + + " }\n" + + "} ", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " String s = b ? arg1 : arg2;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from IX to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " String s = b ? arg1 : arg2;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object&Comparable&Serializable to String\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " String s = b ? arg1 : arg2;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from IX to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " String s = b ? arg1 : arg2;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from IX to String\n" + + "----------\n" + + "3. ERROR in X.java (at line 21)\n" + + " String s = b ? arg1 : arg2;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from Arg1 to String\n" + + "----------\n" + + "4. ERROR in X.java (at line 21)\n" + + " String s = b ? arg1 : arg2;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from Arg2 to String\n" + + "----------\n"); +} +public void test1130() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "\n" + + "interface IX&Serializable> {}\n" + + "\n" + + "public class X&Serializable> {\n" + + " void foo4(boolean b, List l1, List> l2) {\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " }\n" + + "}\n", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Comparable to String\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? extends T to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? extends Comparable to String\n" + + "----------\n"); +} +public void test1131() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "\n" + + "public class X&Serializable> {\n" + + " void foo4(boolean b, List l1, List> l2) {\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " }\n" + + "} \n", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Comparable to String\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#1-of ? extends V to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " String s = b ? l1.get(0) : l2.get(0);\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? extends Comparable to String\n" + + "----------\n"); +} +public void test1132() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public void thisDoesntCompile() {\n" + + " X myThing = new X();\n" + + " Integer i = myThing.getList().get(0); // Type Mismatch error - Since\n" + + " // myThing is unbounded, return\n" + + " // type List becomes unbounded\n" + + " }\n" + + "\n" + + " public List getList() {\n" + + " ArrayList l = new ArrayList();\n" + + " l.add(Integer.valueOf(0));\n" + + " return l;\n" + + " }\n" + + "\n" + + " public void thisMethodCompilesOk() {\n" + + " X myThing = new X();\n" + + " Integer i = myThing.getList().get(0);\n" + + " }\n" + + "\n" + + " public void thisMethodAlsoCompilesOk() {\n" + + " X myThing = new X();\n" + + " List l = myThing.getList();\n" + + " Integer i = l.get(0);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " X myThing = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Integer i = myThing.getList().get(0); // Type Mismatch error - Since\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Integer\n" + + "----------\n" + + "3. WARNING in X.java (at line 24)\n" + + " X myThing = new X();\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 25)\n" + + " List l = myThing.getList();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +public void test1133() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "class Y {\n" + + " List foo() { return null; }\n" + + "}\n" + + "\n" + + "public class X extends Y {\n" + + " List bar() { return null; }\n" + + " \n" + + " void m(X x) {\n" + + " List l1 = x.foo();\n" + + " List l2 = x.bar();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " void m(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " List l1 = x.foo();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " List l2 = x.bar();\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +public void test1134() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "class Y {\n" + + " List foo() { return null; }\n" + + "}\n" + + "\n" + + "public class X extends Y {\n" + + " List bar() { return null; }\n" + + " \n" + + " void m(X x) {\n" + + " List l1 = x.foo();\n" + + " List l2 = x.bar();\n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " void m(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " List l1 = x.foo();\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " List l2 = x.bar();\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "4. 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=185422 +public void test1135() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "class Foo {\n" + + " private T myT;\n" + + "\n" + + " public T getT() {\n" + + " return myT;\n" + + " }\n" + + "\n" + + " public void setT(T aT) {\n" + + " myT = aT;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends Foo {\n" + + " X.Baz baz;\n" + + " public static void main(String[] args) {\n" + + " X myBar = new X();\n" + + " myBar.setT(new Baz());\n" + + " System.out.println(myBar.getT().toString());\n" + + " }\n" + + "\n" + + " private static class Baz {\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"Baz\";\n" + + " }\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " public class X extends Foo {\n" + + " ^^^^^\n" + + "The type X.Baz is not visible\n" + + "----------\n"); +} +//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); + String xSource = + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List l1 = Arrays.asList(1, \"X\");\n" + + " \n" + + " B b = null;\n" + + " Cc = null;\n" + + " List l2 = Arrays.asList(b, c);\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "interface I {}\n" + + "class B extends A implements I {}\n" + + "class C extends A implements I {}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " List l1 = Arrays.asList(1, \"X\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List") +"&Serializable> to List\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " List l2 = Arrays.asList(b, c);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List&I> to List\n" + + "----------\n", + null, + true, + options); + } else { + runConformTest(new String[] { "X.java", xSource }, options); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=154267 +public void test1137() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.awt.Container;\n" + + "import java.util.Collection;\n" + + "\n" + + "abstract class Kollection implements Collection {}\n" + + "abstract class Kontainer extends Container {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " private Collection foo() {\n" + + " return null;\n" + + " }\n" + + " private Kollection bar() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " private void showProblem() {\n" + + " Collection result = foo();\n" + + " Collection result1 = foo();\n" + + " \n" + + " Collection result2 = (Collection)foo();\n" + + " String result3 = foo();\n" + + " String result4 = (String) foo(); \n" + + "\n" + + " Kollection result5 = bar();\n" + + " Kollection result6 = bar();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 21)\n" + + " Collection result2 = (Collection)foo();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Collection to Collection\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " String result3 = foo();\n" + + " ^^^^^\n" + + "Type mismatch: cannot convert from Collection to String\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " String result4 = (String) foo(); \n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot cast from Collection to String\n" + + "----------\n"); +} +public void test1138() { + // binary prerequisite + this.runConformTest( + new String[] { + "p/E.java", + "package p;\n" + + "public enum E {\n" + + "}\n", // ================= + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "import static p.E.*;\n" + + "public class X implements java.io.Serializable {\n" + + "}\n", // ================= + }, + "", + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186833 +public void test1139() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import p.X.Super;\n" + + "import static p.Top.*;\n" + + "\n" + + "class Top {\n" + + " static class A {}\n" + + "}\n" + + "\n" + + "public class X extends Super> {\n" + + " static class Super extends Top{\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 9)\n" + + " public class X extends Super> {\n" + + " ^^^^^\n" + + "Cycle detected: the type X cannot extend/implement itself or one of its own member types\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186788 +public void test1140() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.X.Super;\n" + + "import static p.Top.*;\n" + + "\n" + + "class Top {\n" + + " static class A {}\n" + + "}\n" + + "\n" + + "public class X extends Super> {\n" + + " class Super extends Top{\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " import static p.X.Super;\n" + + " ^^^^^^^^^\n" + + "The import p.X.Super cannot be resolved\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 9)\n" + + " public class X extends Super> {\n" + + " ^^^^^\n" + + "Super cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186833 - variation +public void test1141() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.Top.*;\n" + + "\n" + + "class Top {\n" + + " static class A {}\n" + + "}\n" + + "\n" + + "public class X extends p.X.Super> {\n" + + " static class Super extends Top{\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 8)\n" + + " public class X extends p.X.Super> {\n" + + " ^^^^^^^^^\n" + + "Cycle detected: the type X cannot extend/implement itself or one of its own member types\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 +public void test1142() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static Comparator compound(Comparator a, Comparator b) {\n" + + " return compound(asList(a, b));\n" + + " }\n" + + "\n" + + " public static Comparator compound(Iterable> comparators) {\n" + + " return null;\n" + + " }\n" + + " public static List asList(E a, E b) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " return compound(asList(a, b));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug6573446 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +public void test1143() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static Comparator compound(Comparator a, Comparator b) {\n" + + " int i = asList(a, b);\n" + + " }\n" + + "\n" + + " public static Comparator compound(Iterable> comparators) {\n" + + " return null;\n" + + " }\n" + + " public static List asList(E a, E b) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " int i = asList(a, b);\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +public void test1144() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " Iterable> itc1;\n" + + " Iterable> itc2 = itc1;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Iterable> itc2 = itc1;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from Iterable> to Iterable>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +public void test1145() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " Comparator compound(Comparator a, Comparator b) {\n" + + " return compound(asList(a));\n" + + " }\n" + + " Comparator compound(Iterable> c) {\n" + + " return null;\n" + + " }\n" + + " List asList(E a) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +public void test1146() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static Comparator compound(\n" + + " Comparator a,\n" + + " Comparator b, \n" + + " Comparator... rest) {\n" + + " int i = asList(a, b, rest);\n" + + " int j = asList2(a, b);\n" + + " return compound(asList(a, b, rest));\n" + + " }\n" + + " public static Comparator compound(Iterable> comparators) {\n" + + " return null;\n" + + " }\n" + + " public static List asList(E a, E b, E... rest) {\n" + + " return null;\n" + + " }\n" + + " public static List asList2(E a, E b) {\n" + + " return null;\n" + + " } \n" + + "}\n", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " int i = asList(a, b, rest);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " int j = asList2(a, b);\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to int\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " return compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n": + (this.complianceLevel == ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Comparator... 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> 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> 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>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "5. WARNING in X.java (at line 14)\n" + + " public static List asList(E a, E b, E... rest) {\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter rest\n" + + "----------\n" + : // 1.8 : one fewer error due to better type inference: + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Comparator... 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> 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> to int\n" + + "----------\n" + + "4. WARNING in X.java (at line 14)\n" + + " public static List 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() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(Comparator cx, Comparator[] cxs) {\n" + + " int i = cx;\n" + + " int j = cxs;\n" + + " int k = cxs[0];\n" + + " int l = asList2(cxs[0], cxs[1]);\n" + + " }\n" + + " public static List asList2(E a, E b) {\n" + + " return null;\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int i = cx;\n" + + " ^^\n" + + "Type mismatch: cannot convert from Comparator to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int j = cxs;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from Comparator[] to int\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " int k = cxs[0];\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from Comparator to int\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " int l = asList2(cxs[0], cxs[1]);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 - variation +// FAIL ERRMSG +public void test1148() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static Comparator compound(Comparator a, Comparator b, Comparator... rest) {\n" + + " int i = asList(a, b, rest);\n" + + " int j = compound(asList(a, b, rest));\n" + + " compound(asList(a, b, rest));\n" + + " if (true) return compound(asList(a, b, rest));\n" + + " \n" + + " List> c = null;\n" + + " compound(c);\n" + + " return compound(c);\n" + + " }\n" + + " public static Comparator compound(Iterable> comparators) {\n" + + " return null;\n" + + " }\n" + + " public static List asList(E a, E b, E... rest) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int i = asList(a, b, rest);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to int\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int j = compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " if (true) return compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " compound(c);\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " return compound(c);\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n": + this.complianceLevel == ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static Comparator compound(Comparator a, Comparator b, Comparator... 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> 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>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " compound(asList(a, b, rest));\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\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>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " compound(c);\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " return compound(c);\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "8. WARNING in X.java (at line 16)\n" + + " public static List asList(E a, E b, E... rest) {\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter rest\n" + + "----------\n" + : // fewer errors in 1.8+: + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static Comparator compound(Comparator a, Comparator b, Comparator... 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> 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>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " compound(c);\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " return compound(c);\n" + + " ^^^^^^^^\n" + + "The method compound(Iterable>) in the type X is not applicable for the arguments (List>)\n" + + "----------\n" + + "6. WARNING in X.java (at line 16)\n" + + " public static List 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() { + String bSource = + "public class B {\n" + + " void b() throws ClassNotFoundException {\n" + + " new A();\n" + + " }\n" + + "}\n"; + runConformTest( + // test directory preparation + new String[] { /* test files */ + "A.java", + "public class A {\n" + + " A() throws T {}\n" + + " void a() throws ClassNotFoundException {\n" + + " new A();\n" + + " }\n" + + "}\n", + "B.java", + bSource + }, + // javac options + JavacTestOptions.EclipseJustification.EclipseBug234815 /* javac test options */); + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "B.java", + bSource + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.EclipseJustification.EclipseBug234815 /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=234815 (invalid) +public void test1149b() { + runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " void foo() throws T {}\n" + + " void a() throws ClassNotFoundException {\n" + + " new A().foo();\n" + + " }\n" + + "}\n", + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 +public void test1150() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.ref.Reference;\n"+ + "public class X {\n" + + " static class Rather {\n" + + " static class Deeply {\n" + + " static class Inside {\n" + + " }\n" + + " }\n" + + " }\n" + + " Reference x;\n" + + " Reference y; \n" + + " Reference z; \n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.print(X.class.getDeclaredField(\"x\").getGenericType());\n" + + " System.out.print(\"##\");\n" + + " System.out.print(X.class.getDeclaredField(\"y\").getGenericType());\n" + + " System.out.print(\"##\");\n" + + " System.out.print(X.class.getDeclaredField(\"z\").getGenericType());\n" + + " System.out.println();\n" + + " }\n" + + "}\n" + }, + "java.lang.ref.Reference##java.lang.ref.Reference##java.lang.ref.Reference" + ); + String expectedOutput = + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference;\n" + + " java.lang.ref.Reference x;\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference;\n" + + " java.lang.ref.Reference y;\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference;\n" + + " java.lang.ref.Reference z;\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation +public void test1151() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.ref.Reference;\n"+ + "public class X {\n" + + " class Other {\n" + + " class Deeply {\n" + + " class Inside {\n" + + " } \n" + + " }\n" + + " }\n" + + " Reference.Other.Deeply> t;\n" + + " Reference.Other.Deeply.Inside> u;\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.print(X.class.getDeclaredField(\"t\").getGenericType());\n" + + " //System.out.print(\"##\");\n" + + " //System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) + " System.out.println();\n" + + " }\n" + + "}\n" + }, + //"java.lang.ref.Reference.Other.Deeply>##java.lang.ref.Reference.Other.Deeply$Inside>" + (reflectNestedClassUseDollar + ? "java.lang.ref.Reference$Other$Deeply>" + : "java.lang.ref.Reference.Other.Deeply>") + ); + String expectedOutput = + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Other.Deeply;>;\n" + + " java.lang.ref.Reference t;\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Other.Deeply.Inside;>;\n" + + " java.lang.ref.Reference u;\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation +public void test1152() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.ref.Reference;\n"+ + "public class X {\n" + + " class Other {\n" + + " class Deeply {\n" + + " class Inside {\n" + + " } \n" + + " }\n" + + " }\n" + + " Reference.Other.Deeply.Inside> u;\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + + " System.out.println();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Reference.Other.Deeply.Inside> u;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The member type X.Other.Deeply.Inside must be parameterized, since it is qualified with a parameterized type\n" + + "----------\n" ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation +public void test1153() { + // check proper decoding of binary signatures, by compiling against generated binary + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import java.lang.ref.Reference;\n" + + "public class X {\n" + + " public static class Rather {\n" + + " public static class Deeply {\n" + + " public static class Inside {\n" + + " }\n" + + " }\n" + + " }\n" + + " public class Other {\n" + + " public class Deeply {\n" + + " public class Inside {\n" + + " } \n" + + " }\n" + + " }\n" + + " public Reference x;\n" + + " public Reference y; \n" + + " public Reference z; \n" + + " public Reference.Other.Deeply> t;\n" + + " public Reference.Other.Deeply.Inside> u;\n" + + "}\n", + }, + "" + ); + this.runConformTest( + new String[] { + "Y.java", + "import java.lang.ref.Reference;\n" + + "import p.X;\n" + + "public class Y {\n" + + " Reference x;\n" + + " Reference y; \n" + + " Reference z; \n" + + " Reference.Other.Deeply> t;\n" + + " Reference.Other.Deeply.Inside> u;\n" + + " Y(X someX) {\n" + + " this.x = someX.x;\n" + + " this. y = someX.y; \n" + + " this.z = someX.z; \n" + + " this.t = someX.t;\n" + + " this.u = someX.u; \n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.print(Y.class.getDeclaredField(\"x\").getGenericType());\n" + + " System.out.print(\"##\");\n" + + " System.out.print(Y.class.getDeclaredField(\"y\").getGenericType());\n" + + " System.out.print(\"##\");\n" + + " System.out.print(Y.class.getDeclaredField(\"z\").getGenericType());\n" + + " System.out.print(\"##\");\n" + + " System.out.print(Y.class.getDeclaredField(\"t\").getGenericType());\n" + + " //System.out.print(\"##\");\n" + + " //System.out.print(Y.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) + " System.out.println();\n" + + " }\n" + + "}\n" + }, + "java.lang.ref.Reference##java.lang.ref.Reference##java.lang.ref.Reference##"+ + (reflectNestedClassUseDollar + ? "java.lang.ref.Reference$Other$Deeply>" + : "java.lang.ref.Reference.Other.Deeply>"), + null, + false, // do not flush output + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation +public void test1154() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.ref.Reference;\n" + + "public class X {\n" + + " class Other {\n" + + " class Deeply {\n" + + " class Deeper {\n" + + " class Inside {\n" + + " } \n" + + " }\n" + + " }\n" + + " }\n" + + " Reference.Deeply> t;\n" + + " Reference.Deeply.Deeper.Inside> u;\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " //System.out.print(X.class.getDeclaredField(\"t\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) + " //System.out.print(\"##\");\n" + + " //System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) + " System.out.println();\n" + + " }\n" + + "}\n" + }, + ""); + + String expectedOutput = + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Deeply;>;\n" + + " java.lang.ref.Reference t;\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Deeply.Deeper.Inside;>;\n" + + " java.lang.ref.Reference u;\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=189158 - variation +public void test1155() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.ref.Reference;\n" + + "public class X {\n" + + " class Other {\n" + + " class Deeply {\n" + + " class Deeper {\n" + + " class Inside {\n" + + " } \n" + + " }\n" + + " }\n" + + " }\n" + + " Reference.Other.Deeply> t;\n" + + " Reference.Other.Deeply.Deeper.Inside> u;\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.print(X.class.getDeclaredField(\"t\").getGenericType());\n" + + " //System.out.print(\"##\");\n" + + " //System.out.print(X.class.getDeclaredField(\"u\").getGenericType());\n" + // TODO disabled due to bug in libs (unable to re-read the generated signature) + " System.out.println();\n" + + " }\n" + + "}\n" + }, + (reflectNestedClassUseDollar + ? "java.lang.ref.Reference$Other$Deeply>" + : "java.lang.ref.Reference.Other.Deeply>") ); + + String expectedOutput = + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Other.Deeply;>;\n" + + " java.lang.ref.Reference t;\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/ref/Reference;\n" + + " // Signature: Ljava/lang/ref/Reference.Other.Deeply.Deeper.Inside;>;\n" + + " java.lang.ref.Reference u;\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196253 +public void test1156() { + this.runConformTest( + new String[] { + "C.java", + "public class C {\n" + + " R>> xx = D.r;\n" + + "}", + "D.java", + "public class D {\n" + + " public static R>> r;\n" + + "}", + "R.java", + "public class R {}", + "X.java", + "public class X {\n" + + " public static class N {}\n" + + "}" + }, + "" + ); + this.runConformTest( + new String[] { + "C.java", + "public class C {\n" + + " R>> xx = D.r;\n" + + "}", + }, + "", + null, + false, // do not flush output + null + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202624 +public void test1157() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void func(Class> cls) {}\n" + + " public void func() {\n" + + " func(XX.class);\n" + + " \n" + + " Class> c = XX.class;\n" + + " }\n" + + " class XX {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " func(XX.class);\n" + + " ^^^^\n" + + "The method func(Class>) in the type X is not applicable for the arguments (Class)\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Class> c = XX.class;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 +public void test1158() { + this.runNegativeTest( + new String[] { + "X.java", + " class A {}\n" + + " class B extends A {}\n" + + " class C extends A{}\n" + + " \n" + + " class D {}\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " D d1 = null;\n" + + " D d2 = null;\n" + + " D d3 = null;\n" + + " D d4 = null;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " D d3 = null;\n" + + " ^\n" + + "Bound mismatch: The type C is not a valid substitute for the bounded parameter of the type D\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation +public void test1159() { + this.runConformTest( + new String[] { + "X.java", + "class Y> {}\n" + + "public class X> extends Y{\n" + + " void foo(X x) {}\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation +public void test1160() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y> {}\n" + + "class Z> {}\n" + + "public class X> extends Z{\n" + + " void foo(X x) {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public class X> extends Z{\n" + + " ^\n" + + "Bound mismatch: The type V is not a valid substitute for the bounded parameter > of the type Z\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public class X> extends Z{\n" + + " ^\n" + + "Bound mismatch: The type V is not a valid substitute for the bounded parameter > of the type Z\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation +public void test1161() { + this.runConformTest( + new String[] { + "X.java", + "class Y> {}\n" + + "class Z> extends Y {}\n" + + "public class X> extends Z {\n" + + " void foo(X x) {}\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation +public void test1162() { + this.runConformTest( + new String[] { + "X.java", + "class Y> {}\n" + + "class Z> extends Y {}\n" + + "public class X> extends Z{\n" + + " void foo(Y y) {}\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203061 - variation +public void test1163() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Object o1 = mObj;\n" + + " ^^^^\n" + + "The blank final field mObj may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Object o2 = mObj;\n" + + " ^^^^\n" + + "The blank final field mObj may not have been initialized\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Object o1 = mObj;\n" + + " ^^^^\n" + + "Read access to enclosing field X.mObj is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Object o1 = mObj;\n" + + " ^^^^\n" + + "The blank final field mObj may not have been initialized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " Object o2 = mObj;\n" + + " ^^^^\n" + + "Read access to enclosing field X.mObj is emulated by a synthetic accessor method\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Object o2 = mObj;\n" + + " ^^^^\n" + + "The blank final field mObj may not have been initialized\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " Object o3 = mObj;\n" + + " ^^^^\n" + + "Read access to enclosing field X.mObj is emulated by a synthetic accessor method\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public final class X {\n" + + " private final Object mObj;\n" + + " private final Object mDependent = new Object() {\n" + + " {\n" + + " Object o1 = mObj;\n" + + " }\n" + + " Object o2 = mObj;\n" + + " void foo() {\n" + + " Object o3 = mObj;\n" + + " }\n" + + " };\n" + + " public X() {\n" + + " mObj = \"\";\n" + + " }\n" + + "}\n", // ================= + }, + errMessage); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203061 - variation +public void test1164() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Object o1 = mObj;\n" + + " ^^^^\n" + + "The blank final field mObj may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " mObj = \"1\";\n" + + " ^^^^\n" + + "The final field X.mObj cannot be assigned\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Object o2 = mObj = \"2\";\n" + + " ^^^^\n" + + "The final field X.mObj cannot be assigned\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " mObj = \"3\";\n" + + " ^^^^\n" + + "The final field X.mObj cannot be assigned\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Object o1 = mObj;\n" + + " ^^^^\n" + + "Read access to enclosing field X.mObj is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Object o1 = mObj;\n" + + " ^^^^\n" + + "The blank final field mObj may not have been initialized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " mObj = \"1\";\n" + + " ^^^^\n" + + "Write access to enclosing field X.mObj is emulated by a synthetic accessor method\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " mObj = \"1\";\n" + + " ^^^^\n" + + "The final field X.mObj cannot be assigned\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " Object o2 = mObj = \"2\";\n" + + " ^^^^\n" + + "Write access to enclosing field X.mObj is emulated by a synthetic accessor method\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " Object o2 = mObj = \"2\";\n" + + " ^^^^\n" + + "The final field X.mObj cannot be assigned\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " Object o3 = mObj;\n" + + " ^^^^\n" + + "Read access to enclosing field X.mObj is emulated by a synthetic accessor method\n" + + "----------\n" + + "8. WARNING in X.java (at line 11)\n" + + " mObj = \"3\";\n" + + " ^^^^\n" + + "Write access to enclosing field X.mObj is emulated by a synthetic accessor method\n" + + "----------\n" + + "9. ERROR in X.java (at line 11)\n" + + " mObj = \"3\";\n" + + " ^^^^\n" + + "The final field X.mObj cannot be assigned\n" + + "----------\n"; this.runNegativeTest( + new String[] { + "X.java", + "public final class X {\n" + + " private final Object mObj;\n" + + " private final Object mDependent = new Object() {\n" + + " {\n" + + " Object o1 = mObj;\n" + + " mObj = \"1\";\n" + + " }\n" + + " Object o2 = mObj = \"2\";\n" + + " void foo() {\n" + + " Object o3 = mObj;\n" + + " mObj = \"3\";\n" + + " }\n" + + " };\n" + + " public X() {\n" + + " mObj = \"\";\n" + + " }\n" + + "}\n" + }, errMessage); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202404 - variation +public void test1165() { + this.runNegativeTest( + new String[] { + "X.java", + " interface A {}\n" + + " class B implements A {}\n" + + " class C implements A{}\n" + + " \n" + + " class D {}\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " D d1 = null;\n" + + " D d2 = null;\n" + + " D d3 = null;\n" + + " D d4 = null;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " D d3 = null;\n" + + " ^\n" + + "Bound mismatch: The type C is not a valid substitute for the bounded parameter of the type D\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203318 +public void test1166() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; };\n" + + " void foo(X x) {\n" + + " x.get().intValue(); \n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=179902 +public void test1167() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public class Foo> {\n" + + " class Bar {\n" + + " Bar(Foo bar) {}\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in Foo.java (at line 3)\n" + + " Bar(Foo bar) {}\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends B is not a valid substitute for the bounded parameter > of the type Foo\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 +public void test1168() { + this.runNegativeTest( + new String[] { + "example/Container.java", + "package example;\n" + + "class A {}\n" + + "class B extends A {}\n" + + "\n" + + "public interface Container> {\n" + + " > void f(\n" + + " Container a, \n" + + " Container b, \n" + + " Container c, \n" + + " Container d, \n" + + " Container e, \n" + + " Container> f, \n" + + " Container> g,\n" + + " Container> h);\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in example\\Container.java (at line 12)\n" + + " Container> f, \n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container\n" + + "----------\n" + + "2. ERROR in example\\Container.java (at line 13)\n" + + " Container> g,\n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 - variation +public void test1169() { + this.runNegativeTest( + new String[] { + "example/Container2.java", + "package example;\n" + + "class A {}\n" + + "class B extends A {}\n" + + "\n" + + "public interface Container2> {\n" + + " > void g(\n" + + " Container2 a, \n" + + " Container2 b, \n" + + " Container2 c, \n" + + " Container2 d, \n" + + " Container2 e, \n" + + " Container2> f, \n" + + " Container2> g, \n" + + " Container2 h);\n" + + "\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in example\\Container2.java (at line 12)\n" + + " Container2> f, \n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=169049 - variation +public void test1170() { + this.runNegativeTest( + new String[] { + "example/Container3.java", + "package example;\n" + + "class A {}\n" + + "class B extends A {}\n" + + "\n" + + "public interface Container3> {\n" + + " > void g(\n" + + " Container3 a, \n" + + " Container3 b, \n" + + " Container3 c, \n" + + " Container3 d, \n" + + " Container3 e, \n" + + " Container3> f, \n" + + " Container3> g, \n" + + " Container3 h, \n" + + " Container3> i, \n" + + " Container3 j);\n" + + "\n" + + " > void h(\n" + + " Container3 a, \n" + + " Container3 b, \n" + + " Container3 c, \n" + + " Container3 d, \n" + + " Container3 e, \n" + + " Container3> f, \n" + + " Container3> g, \n" + + " Container3 h, \n" + + " Container3> i, \n" + + " Container3 j);\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in example\\Container3.java (at line 12)\n" + + " Container3> f, \n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "2. ERROR in example\\Container3.java (at line 13)\n" + + " Container3> g, \n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "3. ERROR in example\\Container3.java (at line 15)\n" + + " Container3> i, \n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "4. WARNING in example\\Container3.java (at line 16)\n" + + " Container3 j);\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "5. ERROR in example\\Container3.java (at line 16)\n" + + " Container3 j);\n" + + " ^\n" + + "Bound mismatch: The type A is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "6. ERROR in example\\Container3.java (at line 24)\n" + + " Container3> f, \n" + + " ^\n" + + "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "7. ERROR in example\\Container3.java (at line 25)\n" + + " Container3> g, \n" + + " ^\n" + + "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "8. ERROR in example\\Container3.java (at line 27)\n" + + " Container3> i, \n" + + " ^\n" + + "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n" + + "9. WARNING in example\\Container3.java (at line 28)\n" + + " Container3 j);\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "10. ERROR in example\\Container3.java (at line 28)\n" + + " Container3 j);\n" + + " ^\n" + + "Bound mismatch: The type B is not a valid substitute for the bounded parameter > of the type Container3\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203905 +public void test1171() { + this.runConformTest( + new String[] { + "Function.java", + "public abstract class Function {\n" + + " public abstract B apply(A a);\n" + + "\n" + + " /** (f andThen g)(x) = g(f(x)) */\n" + + " public Function andThen(final Function g) {\n" + + " return new Function() {\n" + + " @Override\n" + + " public C1 apply(A a) {\n" + + " return g.apply(Function.this.apply(a));\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " /** (f compose g)(x) = f(g(x)) */\n" + + " public Function compose(final Function g) {\n" + + " return g.andThen(this);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +public void test1172() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T field;\n" + + " void foo(X xs, X xn, boolean b) {\n" + + " (b ? xs : xn).field = xs.field;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (b ? xs : xn).field = xs.field;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from String to capture#1-of ? extends Serializable\n" + + "----------\n"); +} +public void test1173() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T field;\n" + + " void foo(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).field = x1.field;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (b ? x1 : x2).field = x1.field;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from Integer to capture#1-of ? extends "+intersection("Number","Comparable")+"\n" + + "----------\n"); +} +public void test1174() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T field;\n" + + " void foo(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).field = (b ? x1 : x2).field;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (b ? x1 : x2).field = (b ? x1 : x2).field;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#2-of ? extends "+intersection("Number","Comparable")+" to capture#1-of ? extends "+intersection("Number","Comparable")+"\n" + + "----------\n"); +} +public void test1175() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T field;\n" + + " void foo(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).field = new C();\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "interface B {}\n" + + "class C extends A implements B {}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (b ? x1 : x2).field = new C();\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from C to capture#3-of ? extends C\n" + + "----------\n"); +} +public void test1176() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " void method(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).get().foo();\n" + + " (b ? x1 : x2).get().bar();\n" + + " }\n" + + "}\n" + + "class Foo {\n" + + " void foo() {/**/}\n" + + "}\n" + + "interface Bar {\n" + + " void bar();\n" + + "}\n" + + "abstract class C extends Foo implements Bar {/**/}\n" + + "\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test1177() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " void method(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).get().foo();\n" + + " (b ? x1 : x2).get().bar();\n" + + " }\n" + + "}\n" + + "class Foo {\n" + + " void foo() {/**/}\n" + + "}\n" + + "interface Bar {\n" + + " void bar();\n" + + "}\n" + + "\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test1178() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " void method(X x1, X x2, boolean b) {\n" + + " (b ? x1 : x2).get().baz();\n" + + " }\n" + + "}\n" + + "class Foo {\n" + + " void foo() {/**/}\n" + + "}\n" + + "interface Bar {\n" + + " void bar();\n" + + "}\n" + + "abstract class C extends Foo implements Bar {\n" + + " void baz() {/**/}\n" + + "}\n" + + "abstract class D extends C {/**/}\n" + + "abstract class E extends C {/**/}\n" + + "\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test1179() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {}\n" + + "\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "The type V is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n"); +} +public void test1180() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static , R extends S & T> R max1(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + "\n" + + " public static , S, R extends S & Comparable> R max2(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + "\n" + + " public static , S, R extends Comparable> R max3(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static , R extends S & T> R max1(T arg1, S arg2) {\n" + + " ^\n" + + "Cannot specify any additional bound T when first bound is a type parameter\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public static , S, R extends S & Comparable> R max2(T arg1, S arg2) {\n" + + " ^^^^^^^^^^\n" + + "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n" + + "5. WARNING in X.java (at line 11)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204534 +public void test1181() { + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static , R extends S & T> R max(T arg1, S arg2) {\n" + + " ^\n" + + "Cannot specify any additional bound T when first bound is a type parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public static , R extends S & T> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method max(T, S) is the same as another method in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^\n" + + "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method max(T, S) is the same as another method in type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 6)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n" + + "7. WARNING in X.java (at line 8)\n" + + " public static , S, R extends Comparable> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method max(T, S) is the same as another method in type X\n" + + "----------\n" + + "8. WARNING in X.java (at line 9)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static , R extends S & T> R max(T arg1, S arg2) {\n" + + " ^\n" + + "Cannot specify any additional bound T when first bound is a type parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public static , R extends S & T> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method max(T, S) is the same as another method in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^\n" + + "Cannot specify any additional bound Comparable when first bound is a type parameter\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method max(T, S) is the same as another method in type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 6)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n" + + "7. ERROR in X.java (at line 8)\n" + + " public static , S, R extends Comparable> R max(T arg1, S arg2) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method max(T, S) is the same as another method in type X\n" + + "----------\n" + + "8. WARNING in X.java (at line 9)\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to R\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static , R extends S & T> R max(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + " public static , S, R extends S & Comparable> R max(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + " public static , S, R extends Comparable> R max(T arg1, S arg2) {\n" + + " return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2);\n" + + " }\n" + + " public static void main(String[] args) {}\n" + + "}\n", // ================= + }, + expectedCompilerLog + ); +/* +X.java:2: a type variable may not be followed by other bounds + public static , R extends S & T> R max(T arg1, S arg2) { + ^ +X.java:5: a type variable may not be followed by other bounds + public static , S, R extends S & Comparable> +R max(T arg1, S arg2) { + ^ +X.java:5: name clash: max(T#1,S#2) and max(T#5,S#4) have the same erasure + public static , S, R extends S & Comparable> +R max(T arg1, S arg2) { + + ^ + where T#1,S#2,R#3,S#4,T#5,R#6 are type-variables: + T#1 extends Comparable declared in method max(T#1,S#2) + S#2 extends Object declared in method max(T#1,S#2) + R#3 extends S#2 declared in method max(T#1,S#2) + S#4 extends Object declared in method max(T#5,S#4) + T#5 extends Comparable declared in method max(T#5,S#4) + R#6 extends S#4 declared in method max(T#5,S#4) +X.java:8: name clash: max(T#1,S#2) and max(T#5,S#4) have the same erasure + public static , S, R extends Comparable> R max(T arg1, S arg2) { + ^ + where T#1,S#2,R#3,S#4,T#5,R#6 are type-variables: + T#1 extends Comparable declared in method max(T#1,S#2) + S#2 extends Object declared in method max(T#1,S#2) + R#3 extends Comparable declared in method max(T#1,S#2) + S#4 extends Object declared in method max(T#5,S#4) + T#5 extends Comparable declared in method max(T#5,S#4) + R#6 extends S#4 declared in method max(T#5,S#4) +X.java:3: warning: [unchecked] unchecked cast + return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2); + ^ + required: R + found: Object + where R,S,T are type-variables: + R extends S declared in method max(T,S) + S extends Object declared in method max(T,S) + T extends Comparable declared in method max(T,S) +X.java:6: warning: [unchecked] unchecked cast + return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2); + ^ + required: R + found: Object + where R,T,S are type-variables: + R extends S declared in method max(T,S) + T extends Comparable declared in method max(T,S) + S extends Object declared in method max(T,S) +X.java:9: warning: [unchecked] unchecked cast + return (R) ((arg1.compareTo(arg2) > 0) ? arg1 : arg2); + ^ + required: R + found: Object + where R,T,S are type-variables: + R extends Comparable declared in method max(T,S) + T extends Comparable declared in method max(T,S) + S extends Object declared in method max(T,S) +4 errors +3 warnings + */ +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 +public void test1182() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^\n" + + "The type Object is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 - variation +public void test1183() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(T t) {\n" + + " t.run();\n" + + " }\n" + + " \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204536 - variation +public void test1184() { + // check that unresolved first bound got erased into Object (and not Runnable) + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " void foo(X x) {\n" + + " Runnable r = x.get();\n" + + " }\n" + + " \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " void foo(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Runnable r = x.get();\n" + + " ^^^\n" + + "The method get() from the type X refers to the missing type Zork\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203587 +public void test1185() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Class c) {};\n" + + " void foo(Class> c) {}\n" + + " void foo2(Class> c) {};\n" + + " void foo2(Class> c) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Class c) {};\n" + + " ^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(Class) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " void foo(Class c) {};\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " void foo(Class> c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(Class>) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " void foo2(Class> c) {};\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method foo2(Class>) in type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " void foo2(Class> c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method foo2(Class>) in type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1186() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " void foo1(X x1, X x2) {\n" + + " x1 = (X) x2;\n" + + " }\n" + + " void foo2(X x1, X x2) {\n" + + " x1 = (X) x2;\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " x1 = (X) x2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " x1 = (X) x2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1187() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X {\n" + + " void foo3(X x1, X x2) {\n" + + " x1 = (X) x2;\n" + + " } \n" + + " void foo4(X x1, X x2) {\n" + + " x1 = (X) x2;\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " x1 = (X) x2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " x1 = (X) x2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1188() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " > void foo(Integer i) {\n" + + " S a = (S) i; // error?\n" + + " }\n" + + " > void bar(Integer i) {\n" + + " U a = (U) i; // unchecked?\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " > void foo(Integer i) {\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " S a = (S) i; // error?\n" + + " ^^^^^\n" + + "Cannot cast from Integer to S\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " U a = (U) i; // unchecked?\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Integer to U\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1189() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " > void foo(Number n) {\n" + + " S a = (S) n; // unchecked?\n" + + " }\n" + + " > void bar(Number n) {\n" + + " U a = (U) n; // unchecked?\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " > void foo(Number n) {\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " S a = (S) n; // unchecked?\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Number to S\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " U a = (U) n; // unchecked?\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Number to U\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1190() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " > void foo2(Integer i) {\n" + + " S a = (S) i; // unchecked1?\n" + + " Comparable b = (Comparable) i; // unchecked2?\n" + + " } \n" + + " > void foo3(Integer i) {\n" + + " S a = (S) i; // error?\n" + + " Comparable b = (Comparable) i; // error3?\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " > void foo2(Integer i) {\n" + + " ^^^^^^^\n" + + "The type parameter U should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " S a = (S) i; // unchecked1?\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from Integer to S\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " Comparable b = (Comparable) i; // unchecked2?\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Integer to Comparable\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " > void foo3(Integer i) {\n" + + " ^^^^^^\n" + + "The type parameter U should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " S a = (S) i; // error?\n" + + " ^^^^^\n" + + "Cannot cast from Integer to S\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " Comparable b = (Comparable) i; // error3?\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Integer to Comparable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=158870 - variation +public void test1191() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(SomeEnum en) {\n" + + " Enum myvar = en;\n" + + " SomeEnum en2 = (SomeEnum) myvar;\n" + + " if (myvar instanceof SomeEnum) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "enum SomeEnum {\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=165352 +public void test1192() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo(ArrayList a) {\n" + + " Object o = (List) a; // ko\n" + + " }\n" + + " void bar(List a) {\n" + + " Object o = (ArrayList) a; // ko\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Object o = (List) a; // ko\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from ArrayList to List\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Object o = (List) a; // ko\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from ArrayList to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Object o = (ArrayList) a; // ko\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to ArrayList\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " Object o = (ArrayList) a; // ko\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to ArrayList\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148046 - variation +public void test1193() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {}\n" + + "class B extends A {}\n" + + "public class X {\n" + + " public void foo(X param) {\n" + + " X bar = (X) param; // unchecked warning vs error\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X bar = (X) param; // unchecked warning vs error\n" + + " ^^^^^^^^^^^^\n" + + "Cannot cast from X to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=120088 +public void test1194() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X t = new X();\n" + + " if (t.getClass() == Object.class)\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (t.getClass() == Object.class)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n"); +} +public void test1195() { + this.runConformTest( + new String[] { + "java/lang/Class.java", + "package java.lang;\n" + + "public class Class {\n" + + " Class getSuperclass() { return null; }\n" + + " void foo() {\n" + + " boolean foo = getSuperclass() == Enum.class;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +public void test1196() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " Class getSuperclass() { return null; }\n" + + " void foo() {\n" + + " boolean foo = getSuperclass() == Enum.class;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " void bar() {\n" + + " boolean bar = this.getClass().getSuperclass() == Enum.class;\n" + + " } \n" + + "}\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +public void test1197() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test() {\n" + + " B b = new C();\n" + + " Class cb = C.class;\n" + + " YYY y = new XXX();\n" + + " Class> cy = XXX.class;\n" + + " YYY yb = new XXX();\n" + + " Class> ybc = XXX.class;\n" + + " Class ybb = yb.getClass();\n" + + " Class> ybb2 = yb.getClass();\n" + + " Class> ybb3 = yb.getClass();\n" + + " }\n" + + "}\n" + + "\n" + + "class Obj {}\n" + + "class B extends Obj {}\n" + + "class C extends B {}\n" + + "class ZZZ {}\n" + + "class YYY extends ZZZ {}\n" + + "class XXX extends YYY {} \n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " Class ybb = yb.getClass();\n" + + " ^^^\n" + + "YYY is a raw type. References to generic type YYY should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Class> ybb2 = yb.getClass();\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " Class> ybb3 = yb.getClass();\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 - variation +public void test1198() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Listener {}\n" + + " interface ErrorListener {} \n" + + " static Object createParser(Listener l) {\n" + + " System.out.println(\"FAILED\");\n" + + " return null;\n" + + " }\n" + + " static Object createParser(L l) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class A implements Listener, ErrorListener {\n" + + " }\n" + + " createParser(new A()); // error here\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 - variation +public void test1198a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Listener {}\n" + + " interface ErrorListener {} \n" + + " static Object createParser(Listener l) {\n" + + " System.out.println(\"FAILED\");\n" + + " return null;\n" + + " }\n" + + " static Object createParser(L l) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class A implements Listener, ErrorListener {\n" + + " }\n" + + " createParser(new A()); // error here\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=121024 - variation +public void test1199() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Listener {}\n" + + " interface ErrorListener {} \n" + + " static Object createParser(Listener l) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " static Object createParser(L l) {\n" + + " System.out.println(\"FAILED\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class A implements Listener {\n" + + " }\n" + + " createParser(new A()); // error here\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=205594 +public void test1200() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class Map {\n" + + " }\n" + + "\n" + + " public Map make(K key, V value) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public Map, X> method1() {\n" + + " X value = new X();\n" + + " Class type = X.class;\n" + + " return make(type, value);//1\n" + + " }\n" + + " public Map, X> method2() {\n" + + " X value = new X();\n" + + " Class type = X.class;\n" + + " return (Map, X>) make(type, value);//2\n" + + " }\n" + + " public Map, X> method3() {\n" + + " X value = new X();\n" + + " return make(X.class, value);//3\n" + + " }\n" + + " public Map, X> method4() {\n" + + " X value = new X();\n" + + " return (Map, X>) make(X.class, value);//4\n" + + " } \n" + + "}\n", // ================= + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " return make(type, value);//1\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Map,X> to X.Map,X>\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " return (Map, X>) make(type, value);//2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X.Map,X> to X.Map,X>\n" + + "----------\n" + + "3. ERROR in X.java (at line 21)\n" + + " return make(X.class, value);//3\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Map,X> to X.Map,X>\n" + + "----------\n" + + "4. ERROR in X.java (at line 25)\n" + + " return (Map, X>) make(X.class, value);//4\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X.Map,X> to X.Map,X>\n" + + "----------\n" + : // fewer errors in 1.8+: + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " return (Map, X>) make(type, value);//2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X.Map,X> to X.Map,X>\n" + // FIXME: javac8 only reports a warning here + "----------\n" + + "2. ERROR in X.java (at line 25)\n" + + " return (Map, X>) make(X.class, value);//4\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X.Map,X> to X.Map,X>\n" + + "----------\n")); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174282 +public void test1201() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public MyClass f() {\n" + + " SuperClass val = null;\n" + + " return (MyClass) val;\n" + + " }\n" + + "}\n" + + "class MyClass extends SuperClass {\n" + + "}\n" + + "class MyDataModel extends SuperDataModel {\n" + + "}\n" + + "class SuperClass {\n" + + "}\n" + + "class SuperDataModel {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230 +public void test1202() { + String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_7 + ? "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X.foo();\n" + + " ^^^\n" + + "The method foo() of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X.foo();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " X.foo();\n" + + " ^^^\n" + + "The method foo() of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + : "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " X.foo();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foo() of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X.foo();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " X.foo();\n" + + " ^^^^\n" + + "Unused type arguments for the non generic method foo() of type X; it should not be parameterized with arguments \n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo() {}\n" + + " public static void bar() {\n" + + " X.foo();\n" + + " X.foo();\n" + + " }\n" + + "}\n", // ================= + }, + expectedOutput); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230 - variation +// split because of https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 +public void test1203a() { + String[] sources = + new String[] { + "X.java", + "public class X {\n" + + " public static String foo(String one, String two) {\n" + + " return X.foo(one, two);\n" + + " }\n" + + " public String bar(String one, String two) {\n" + + " return this.bar(one, two);\n" + + " }\n" + + "}\n", // ================= + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return X.foo(one, two);\n" + + " ^^^\n" + + "The method foo(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " return this.bar(one, two);\n" + + " ^^^\n" + + "The method bar(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + } else { + runConformTest( + true, + sources, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " return X.foo(one, two);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foo(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " return this.bar(one, two);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method bar(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 +// this case is not solved as expected in 1.5 and 1.6 mode; keeping the 1.7 mode +// activated test in all modes so we can track any changes +public void test1203b() { + String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_7 + ? "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return this.foobar(one, two);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foobar(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return this.foobar2(one, two);// silenced\n" + + " ^^^^^^^\n" + + "The method foobar2(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " this.foobar(one, two);\n" + + " ^^^^^^\n" + + "Incorrect number of type arguments for generic method foobar(String, String) of type Y; it cannot be parameterized with arguments \n" + + "----------\n" + : "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return this.foobar(one, two);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foobar(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " this.foobar(one, two);\n" + + " ^^^^^^\n" + + "Incorrect number of type arguments for generic method foobar(String, String) of type Y; it cannot be parameterized with arguments \n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " @Override\n" + + " public String foobar(String one, String two) {\n" + + " return this.foobar(one, two);\n" + + " }\n" + + " @SuppressWarnings(\"unused\")\n" + + " public String foobar2(String one, String two) {\n" + + " return this.foobar2(one, two);// silenced\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public String foobar(String one, String two) {\n" + + " return null;\n" + + " }\n" + + " void test(String one, String two) {\n" + + " this.foobar(one, two);\n" + + " }\n" + + "}\n", // ================= + }, + expectedOutput); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 +public void test1203c() { + String[] sources = + new String[] { + "X.java", + "public class X extends Y {\n" + + " public static void main(String[] args) {\n" + + " String s = \"\";\n" + + " new X(). a(s);\n" + // fails before 7 + " new X(). b(s, s);\n" + // fails before 7 + " new X(). c(s, s);\n" + // works in 1.5, 6.0 & 7.0 + " new X(). d(s, s);\n" + // works in 1.5, 6.0 & 7.0 + " }\n" + + " @Override void a(String one) {}\n" + + " void b(String one, Object two) {}\n" + + " @Override void c(String one, String two) {}\n" + + " @Override void d(String one, Object two) {}\n" + + "}\n" + + "class Y extends Z {\n" + + " void a(String one) {}\n" + + " void b(String one) {}\n" + + " @Override void c(String one, String two) {}\n" + + "}\n" + + "class Z {\n" + + " void c(String one, String two) {}\n" + + " void d(String one, U u) {}\n" + + "}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new X(). a(s);\n" + + " ^\n" + + "The method a(String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " new X(). b(s, s);\n" + + " ^\n" + + "The method b(String, Object) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " new X(). c(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method c(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " new X(). d(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method d(String, Object) of type X; it should not be parameterized with arguments \n" + + "----------\n"); + } else { + runConformTest( + true, + sources, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new X(). a(s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method a(String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " new X(). b(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method b(String, Object) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " new X(). c(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method c(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " new X(). d(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method d(String, Object) of type X; it should not be parameterized with arguments \n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 +public void test1203d() { + String[] sources = + new String[] { + "X.java", + "public class X implements I {\n" + + " public static void main(String[] args) {\n" + + " String s = \"\";\n" + + " new X(). a(s);\n" + // fails before 7 + " new X(). b(s, s);\n" + // fails before 7 + " new X(). c(s, s);\n" + // fails before 7 + " new X(). d(s, s);\n" + // fails before 7 + " }\n" + + " public void a(String one) {}\n" + + " public void b(String one, Object two) {}\n" + + " public void c(String one, String two) {}\n" + + " public void d(String one, Object two) {}\n" + + "}\n" + + "interface I extends J {\n" + + " void a(String one);\n" + + " void c(String one, String two);\n" + + "}\n" + + "interface J {\n" + + " void c(String one, String two);\n" + + " void d(String one, U u);\n" + + "}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new X(). a(s);\n" + + " ^\n" + + "The method a(String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " new X(). b(s, s);\n" + + " ^\n" + + "The method b(String, Object) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " new X(). c(s, s);\n" + + " ^\n" + + "The method c(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " new X(). d(s, s);\n" + + " ^\n" + + "The method d(String, Object) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + } else { + runConformTest( + true, + sources, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new X(). a(s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method a(String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " new X(). b(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method b(String, Object) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " new X(). c(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method c(String, String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " new X(). d(s, s);\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method d(String, Object) of type X; it should not be parameterized with arguments \n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207299 +public void test1204() { + this.runConformTest( + new String[] { + "ExpressionGraph.java", + "import java.util.*;\n" + + "public class ExpressionGraph, V extends IVertex> {\n" + + " void foo(Set set, Collection col) {\n" + + " if (set == col) return;\n" + + " }\n" + + "}\n" + + "interface IVertex, V extends IVertex> { \n" + + " // empty\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207299 - variation +public void test1205() { + this.runConformTest( + new String[] { + "ExpressionGraph.java", + "import java.util.*;\n" + + "\n" + + "public class ExpressionGraph, V extends ExpressionVertex, L> extends AbstractGraph {\n" + + " void foo(Set set, Collection col) {\n" + + " if (set == col) return;\n" + + " }\n" + + "\n" + + " interface IVertex, V extends IVertex, L> extends ExpressionVertex { \n" + + " // empty\n" + + " }\n" + + " static abstract class Vertex, V extends IVertex, L> /*extends TaggableVertex*/ implements IVertex { \n" + + " // empty\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class AbstractGraph, V extends Vertex> implements Graph {\n" + + " // empty\n" + + "}\n" + + "interface Graph, V extends Vertex> { \n" + + " // empty\n" + + "}\n" + + "interface Vertex, V extends Vertex> {\n" + + " // empty\n" + + "}\n" + + "interface ExpressionVertex, V extends ExpressionVertex, L> extends Vertex {\n" + + " // empty\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 +public void test1206() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public final E throwE(E ex, Object... args) throws E {\n" + + " Object[] oar = new Object[0];\n" + + " return throwE(oar, ex, args);\n" + + " }\n" + + "\n" + + " public final E throwE(Object[] oar, E ex, Object... args) throws E {\n" + + " throw ex;\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation +public void test1207() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public final E throwE (E ex) throws E {\n" + + " throw ex;\n" + + " }\n" + + " void foo(Object[] objs) {\n" + + " throwE(objs);\n" + + " }\n" + + "}\n", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " throwE(objs);\n" + + " ^^^^^^\n" + + "Bound mismatch: The generic method throwE(E) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter \n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " throwE(objs);\n" + + " ^^^^^^\n" + + "The method throwE(E) in the type X is not applicable for the arguments (Object[])\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation +public void test1208() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public final E throwE2(E ex, Object... args) throws E {\n" + + " Object[] oar = new Object[0];\n" + + " return throwE(oar, ex, args);\n" + + " }\n" + + "\n" + + " public final E throwE(Object[] oar, E ex, Object... args) throws E {\n" + + " throw ex;\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation +public void test1209() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public final E throwE (E ex, Object ... args) throws E {\n" + + " throw ex;\n" + + " }\n" + + " void foo(Object[] objs) {\n" + + " throwE(objs);\n" + + " }\n" + + "}", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " throwE(objs);\n" + + " ^^^^^^\n" + + "Bound mismatch: The generic method throwE(E, Object...) of type X is not applicable for the arguments (Object[]). The inferred type Object[] is not a valid substitute for the bounded parameter \n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " throwE(objs);\n" + + " ^^^^^^\n" + + "The method throwE(E, Object...) in the type X is not applicable for the arguments (Object[])\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207573 - variation +// FAIL ERRMSG +public void test1210() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public final E throwE (Object ... args) throws E {\n" + + " return null;\n" + + " }\n" + + " void foo(Object[] objs) {\n" + + " Object[] o = throwE(objs);\n" + + " }\n" + + "}\n", // ================= + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\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 \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" + : + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Object[] o = throwE(objs);\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from RuntimeException to Object[]\n" + + "----------\n")); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208030 +public void test1211() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " Zork z;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"FAILED\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " new Local(){};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " super(\"FAILED\");\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The constructor X(String) of type X is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " new Local();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor Local() of type Local is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " new Local(){};\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor Local() of type Local is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String t){\n" + + " System.out.println(t);\n" + + " Zork z;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " class Local extends X {\n" + + " Local() {\n" + + " super(\"FAILED\");\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " new Local(){};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " super(\"FAILED\");\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X(String) of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " new Local();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor Local() of type Local; it should not be parameterized with arguments \n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " new Local(){};\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor Local() of type Local; it should not be parameterized with arguments \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 +// generic variants +public void test1212() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X implements I {}\n" + + "class Y extends X implements I, J {}\n" + + "class Z {}" + + "interface I {}\n" + + "interface J {}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X implements I, J {}\n" + + " ^\n" + + "Redundant superinterface I for the type Y, already defined by X\n" + + "----------\n", + // javac options + JavacTestOptions.SKIP /* skip javac tests - configured eclipse specific warning as error */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 +// generic variants - the 'different arguments' error overrides the +// redundant error +public void test1213() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I {}\n" + + "class Y extends X implements I, J {}\n" + + "class Z {}" + + "interface I {}\n" + + "interface J {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X implements I, J {}\n" + + " ^\n" + + "The interface I cannot be implemented more than once with different arguments: I and I\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + customOptions); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 +public void test1214() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public interface Loader {\n" + + " public T load(final K key);\n" + + " }\n" + + " Loader loader;\n" + + " public T get(final K key) {\n" + + " T data = this.loader.load(key);\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBug5042462 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 - variation +public void test1215() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " T cond1(boolean z, U x1, V x2) {\n" + + " return (z? x1: x2);\n" + + " }\n" + + "}\n", + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBug5042462 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 +public void test1216() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " p.A myA = new p.A();\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static class Box {\n" + + " public T t;\n" + + " public void set(T t) { this.t = t; }\n" + + " public T get() { return this.t; }\n" + + " }\n" + + " private class P {\n" + + " public int pval;\n" + + " }\n" + + " public P p;\n" + + " public Box

box;\n" + + " public Box

getBox() { return this.box; }\n" + + " public A next;\n" + + " public A getNext() { return this;} \n" + + " public A() {\n" + + " this.box = new Box

();\n" + + " this.box.set(new P());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " ^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " ^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + (isMinimumCompliant(ClassFileConstants.JDK11) ? "" : + "----------\n" + + "1. WARNING in p\\A.java (at line 18)\n" + + " this.box.set(new P());\n" + + " ^^^^^^^\n" + + "Access to enclosing constructor A.P() is emulated by a synthetic accessor method\n" + + "----------\n")); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation +public void test1217() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " p.A myA = new p.A();\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static class Box {\n" + + " public T t;\n" + + " public void set(T t) { this.t = t; }\n" + + " public T get() { return this.t; }\n" + + " }\n" + + " protected class P {\n" + + " public int pval;\n" + + " }\n" + + " public P p;\n" + + " public Box

box;\n" + + " public Box

getBox() { return this.box; }\n" + + " public A next;\n" + + " public A getNext() { return this;} \n" + + " public A() {\n" + + " this.box = new Box

();\n" + + " this.box.set(new P());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " ^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " ^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209153 - variation +public void test1218() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " p.A myA = new p.A();\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " Object o = myA.box.get(); // ok, since no generic cast actually inserted\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static class Box {\n" + + " public T t;\n" + + " public void set(T t) { this.t = t; }\n" + + " public T get() { return this.t; }\n" + + " }\n" + + " class P {\n" + + " public int pval;\n" + + " }\n" + + " public P p;\n" + + " public Box

box;\n" + + " public Box

getBox() { return this.box; }\n" + + " public A next;\n" + + " public A getNext() { return this;} \n" + + " public A() {\n" + + " this.box = new Box

();\n" + + " this.box.set(new P());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " myA.p = myA.box.get(); // [msgSend] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " myA.p = myA.getBox().t;// [fieldRef] generic cast to P -> error\n" + + " ^^^^^^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " myA.p = myA.box.t;// [qName] generic cast to P -> error\n" + + " ^^^\n" + + "The type A.P is not visible\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " int pval = myA.box.t.pval;// intermediate access through P already flagged as error\n" + + " ^^^^^^^^^\n" + + "The type A.P is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209779 +public void test1219() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final List stringList = new ArrayList();\n" + + " stringList.add(\"test1\");\n" + + " stringList.add(\"test2\");\n" + + " ((List) stringList).add(new Integer(1000));\n" + + " try {\n" + + " Object o = stringList.get(2);\n" + + " } catch (ClassCastException e) {\n" + + " System.out.print(\"[ClassCastException1]\");\n" + + " }\n" + + " try {\n" + + " String s = stringList.get(2);\n" + + " } catch (ClassCastException e) {\n" + + " System.out.print(\"[ClassCastException2]\");\n" + + " } \n" + + " try {\n" + + " for (Object obj : stringList) {\n" + + " System.out.print(obj);\n" + + " }\n" + + " } catch (ClassCastException e) {\n" + + " System.out.print(\"[ClassCastException3]\");\n" + + " } \n" + + " try {\n" + + " for (String str : stringList) {\n" + + " System.out.print(str);\n" + + " }\n" + + " } catch (ClassCastException e) {\n" + + " System.out.print(\"[ClassCastException4]\");\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + "}\n" + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "[ClassCastException2]test1test21000test1test2[ClassCastException4]" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.JavacHasABug.JavacBug6500701 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209152 +public void test1220() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void doIt(List list) {\n" + + " list.add(list.remove(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " list.add(list.remove(0));\n" + + " ^^^\n" + + "The method add(capture#1-of ?) in the type List is not applicable for the arguments (capture#2-of ?)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209071 +public void test1221() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo() {\n" + + " Set listSet = new HashSet();\n" + + " Set otherListSet = new HashSet();\n" + + " otherListSet.add((List) listSet); \n" + + " }\n" + + " void bar() {\n" + + " Set stringSet = new HashSet();\n" + + " Set otherStringSet = new HashSet();\n" + + " otherStringSet.add((String) stringSet); \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " new X().bar();\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Set listSet = new HashSet();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Set listSet = new HashSet();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " Set otherListSet = new HashSet();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " Set otherListSet = new HashSet();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " otherListSet.add((List) listSet); \n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " otherStringSet.add((String) stringSet); \n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Set to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207959 +public void test1222() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " void foo2(X x2) {\n" + + " Runnable r = x2.get();\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=211718 +public void test1223() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static enum IsABug {\n" + + " TRUE,\n" + + " FALSE;\n" + + " } \n" + + " public List getPossibleBugStates() {\n" + + " String s1 = IsABug.values();\n" + + " String s2 = IsABug.valueOf(s1);\n" + + " return Arrays.asList(IsABug.values());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s1 = IsABug.values();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.IsABug[] to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " String s2 = IsABug.valueOf(s1);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.IsABug to String\n" + + "----------\n"); +} +public void test1224() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.Collections;\n" + + "public class X {\n" + + " class Request,V> {}\n" + + " class RequestMap {\n" + + " public ,W> R intersection (Collection c) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " class DeltaRequest extends Request {}\n" + + " public void test () {\n" + + " RequestMap m = new RequestMap ();\n" + + " Collection c = Collections.singleton (new DeltaRequest ());\n" + + " DeltaRequest o = m.intersection (c);\n" + + " }\n" + + "}\n" + }, + ""); +} +public void test1225() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " static void m(List list, Collection coll) {\n" + + " m(list, coll);\n" + + " }\n" + + "}\n" + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +public void test1226() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class M {\n" + + " X foo() { return null; }\n" + + " }\n" + + " void bar(M m) {\n" + + " X xt = m.foo();\n" + // no unchecked warning + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1227() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n" + + " void foo() {\n" + + " Arrays.asList(String.class, Integer.class);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Arrays.asList(String.class, Integer.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Class") +"> 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"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 +public void test1228() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(Y b1, U b2) {\n" + + " }\n" + + " public class Binner {\n" + + " public class BinnerInner {\n" + + " public BinnerInner $new$() {\n" + + " return new BinnerInner();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); + // check $new$ method generic signature + String expectedOutput = + " // Method descriptor #22 ()LX$Binner$BinnerInner;\n" + + " // Signature: ()LX.Binner.BinnerInner;\n" + + " // Stack: 3, Locals: 1\n" + + " public X.Binner.BinnerInner $new$();\n" + + " 0 new X$Binner$BinnerInner [1]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 getfield X$Binner$BinnerInner.this$1 : X.Binner [10]\n" + + " 8 invokespecial X$Binner$BinnerInner(X$Binner) [25]\n" + + " 11 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X.Binner.BinnerInner\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X.Binner.BinnerInner\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X$Binner$BinnerInner.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 - variation +public void test1229() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(Y b1, U b2) {\n" + + " }\n" + + " public class Binner {\n" + + " public class BinnerInner {\n" + + " public BinnerInner $new$() {\n" + + " return new BinnerInner();\n" + + " }\n" + + " X root() {\n" + + " return X.this;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " public static void main(String[] args) {\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " String s = binString.$new$().root();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^\n" + + "The type parameter U should not be bounded by the final type Class. Final types cannot be further extended\n" + + "----------\n" + + "----------\n" + + "1. WARNING in Z.java (at line 3)\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in Z.java (at line 3)\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. ERROR in Z.java (at line 4)\n" + + " String s = binString.$new$().root();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 - variation +public void test1230() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(Y b1, U b2) {\n" + + " }\n" + + " public class Binner {\n" + + " public class BinnerInner {\n" + + " public BinnerInner $new$() {\n" + + " return new BinnerInner();\n" + + " }\n" + + " X root() {\n" + + " return X.this;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + this.runNegativeTest( + new String[] { + "Z.java", + "public class Z {\n" + + " public static void main(String[] args) {\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " String s = binString.$new$().root();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Z.java (at line 3)\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in Z.java (at line 3)\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "3. ERROR in Z.java (at line 4)\n" + + " String s = binString.$new$().root();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to String\n" + + "----------\n", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=214972 - variation +public void test1231() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(Y b1, U b2) {\n" + + " }\n" + + " public class Binner {\n" + + " public class BinnerInner {\n" + + " public BinnerInner $new$() {\n" + + " return new BinnerInner();\n" + + " }\n" + + " X root() {\n" + + " return X.this;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + this.runConformTest( + new String[] { + "Z.java", + "public class Z {\n" + + " public static void main(String[] args) {\n" + + " X.Binner.BinnerInner binString = new X(null, null).new Binner().new BinnerInner();\n" + + " X.Binner.BinnerInner binNumber = binString.$new$();\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 +public void test1232() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface {\n" + + " public Integer getNumber();\n" + + " public SubInterface and(SuperInterface s);\n" + + " }\n" + + "}\n", + }, + ""); + +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1233() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface {\n" + + " public Integer getNumber();\n" + + " public SubInterface and(SuperInterface s);\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1234() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.EclipseHasABug.EclipseBug427719, + new String[] { + "X.java", + "public class X { \n" + + " void a3(G x) {} \n" + + " > void a3(T x) {}\n" + + "\n" + + " public static void ambiguousCases() { \n" + + " H hx = null;\n" + + " H hraw = null;\n" + + " new X().a3(hx);\n" + + " new X().a3(hraw);\n" + + " } \n" + + "}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void a3(G x) {} \n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " H hraw = null;\n" + + " ^\n" + + "H is a raw type. References to generic type H should be parameterized\n" + + "----------\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "3. ERROR in X.java (at line 8)\n" + + " new X().a3(hx);\n" + + " ^^\n" + + "The method a3(G) is ambiguous for the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " new X().a3(hraw);\n" + + " ^^\n" + + "The method a3(G) is ambiguous for the type X\n" + + "----------\n" + : // not ambiguous in 1.8 + "")); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1235() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " > void a3(T x) {}\n" + + " > void a3(T x) {}\n" + + "\n" + + " public static void ambiguousCases() { \n" + + " H hx = null;\n" + + " H hraw = null;\n" + + " new X().a3(hx);\n" + + " new X().a3(hraw);\n" + + " } \n" + + "}\n" + + "class F {} \n" + + "class G extends F {}\n" + + "class H extends G {}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1236() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " public Integer getNumber();\n" + + " public SubInterface and(SuperInterface s);\n" + + " }\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1237() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " }\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method and(X.SuperInterface) belongs to the raw type X.OtherSubInterface. References to generic type X.OtherSubInterface should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.OtherSubInterface to X.SubInterface\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "X.OtherSubInterface is a raw type. References to generic type X.OtherSubInterface should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1238() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(SubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " }\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.OtherSubInterface to X.SubInterface\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " public interface SubInterface extends SuperInterface, OtherSubInterface {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1239() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(CombinedSubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface {\n" + + " public Integer getNumber();\n" + + " public SubInterface and(SuperInterface s);\n" + + " }\n" + + " public interface CombinedSubInterface extends SubInterface, OtherSubInterface {}\n" + + " \n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " ^^^\n" + + "The method and(X.SuperInterface) is ambiguous for the type X.CombinedSubInterface\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " public interface SubInterface extends SuperInterface {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " public SubInterface and(SuperInterface s);\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " public interface CombinedSubInterface extends SubInterface, OtherSubInterface {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The return types are incompatible for the inherited methods X.SubInterface.and(X.SuperInterface), X.OtherSubInterface.and(X.SuperInterface)\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 16)\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " ^^^^^^^^^^^^^^\n" + + "X.SuperInterface is a raw type. References to generic type X.SuperInterface should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1240() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(CombinedSubInterface sub1, SubInterface sub2) {\n" + + " SubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public Number getNumber();\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface {\n" + + " public Integer getNumber();\n" + + " public SubInterface and(SuperInterface s);\n" + + " }\n" + + " public interface OtherSubInterface extends SubInterface {\n" + + " public OtherSubInterface and(SuperInterface a);\n" + + " }\n" + + " public interface CombinedSubInterface extends OtherSubInterface {}\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=215843 - variation +public void test1241() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void testCovariant(CombinedSubInterface sub1, SubInterface sub2) {\n" + + " CombinedSubInterface sub3 = sub1.and(sub2);\n" + + " }\n" + + " public interface SuperInterface {\n" + + " public SuperInterface and(SuperInterface a);\n" + + " }\n" + + " public interface SubInterface extends SuperInterface {\n" + + " }\n" + + " public interface OtherSubInterface extends SuperInterface {\n" + + " public CombinedSubInterface and(SuperInterface a);\n" + + " }\n" + + " public interface CombinedSubInterface extends SubInterface, OtherSubInterface {}\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=164665 +public void test1242() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.LinkedList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public void testCase() {\n" + + " TypedCollection collection = TypedCollectionFactory.createTypedCollection(SubTypeClass.class);\n" + + " collection.add(new SubTypeClass());\n" + + " List list = collection.list();\n" + + " assert (list.size() > 0);\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class SuperTypeAbstractClass {\n" + + "}\n" + + "\n" + + "class SubTypeClass extends SuperTypeAbstractClass {\n" + + "}\n" + + "\n" + + "interface TypedCollection {\n" + + " TypedCollection add(T object);\n" + + " List list();\n" + + "}\n" + + "\n" + + "class TypedCollectionFactory {\n" + + " public static TypedCollection createTypedCollection(Class c) {\n" + + " return new TypedCollectionImpl();\n" + + " }\n" + + "}\n" + + "\n" + + "class TypedCollectionImpl implements TypedCollection {\n" + + " private List list = new LinkedList();\n" + + " public TypedCollection add(T object) {\n" + + " list.add(object);\n" + + " return (this);\n" + + " }\n" + + " public List list() {\n" + + " return list;\n" + + " }\n" + + "}\n", // ================= + }, + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_7 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 +public void test1243() { + this.runConformTest( + new String[] { + "eclipse/modifier/impl/EclipseModifierBug.java", + "package eclipse.modifier.impl;\n" + + "import eclipse.modifier.Pool;\n" + + "public class EclipseModifierBug {\n" + + " static class MyEntry extends Pool.AbstractEntry { } \n" + + " static final Pool pool=new Pool() {\n" + + " @Override\n" + + " protected MyEntry delegate() {\n" + + " return new MyEntry();\n" + + " } \n" + + " };\n" + + " public static void main(String[] args) {\n" + + " MyEntry entry=pool.m(); \n" + + " }\n" + + "}", // ================= + "eclipse/modifier/Pool.java", + "package eclipse.modifier;\n" + + "public abstract class Pool> {\n" + + " static abstract class Entry> {\n" + + " E next;\n" + + " }\n" + + " static public class AbstractEntry> extends Entry {\n" + + " }\n" + + " public E m() {\n" + + " return delegate();\n" + + " }\n" + + " protected abstract E delegate();\n" + + " }\n" + + "\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 - variation +public void test1244() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static class MyEntry extends Pool.AbstractEntry { } \n" + + " static final Pool pool=new Pool() {\n" + + " @Override\n" + + " protected MyEntry delegate() {\n" + + " return new MyEntry();\n" + + " } \n" + + " };\n" + + " public static void main(String[] args) {\n" + + " MyEntry entry=pool.m();\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Pool> {\n" + + " private static abstract class Entry> {\n" + + " E next;\n" + + " }\n" + + " static public class AbstractEntry> extends Entry {\n" + + " }\n" + + " public E m() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return delegate();\n" + + " }\n" + + " protected abstract E delegate();\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " abstract class Pool> {\n" + + " ^^^^^^^^^^\n" + + "The type Pool.Entry is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 - variation +public void test1245() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "}\n" + + "class Secondary {\n" + + " static private class Private {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The type Secondary.Private is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216100 - variation +public void test1246() { + runNegativeTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " static private class Private {}\n" + + " void foo(U u) {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^^^^^^\n" + + "The type X.Private is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 +public void test1247() { + String xSource = + "public class X {\n" + + "\n" + + " public static void test() {\n" + + " Foo foo = null;\n" + + " eval(foo); // fails\n" + + " X.> eval(foo);\n" + + " }\n" + + "\n" + + " public static > void eval(T x) {\n" + + " }\n" + + " public static interface Foo extends Iterable> {\n" + + " }\n" + + "}"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " eval(foo); // fails\n" + + " ^^^^\n" + + "Bound mismatch: The generic method eval(T) of type X is not applicable for the arguments (X.Foo). The inferred type X.Foo is not a valid substitute for the bounded parameter >\n" + + "----------\n"); + } else { + runConformTest(new String[] { "X.java", xSource }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 - variation +public void test1248() { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "public class X {\n" + + "\n" + + " public static void test() {\n" + + " Foo foo = null;\n" + + " eval(foo); // fails\n" + + " X.> eval(foo);\n" + + " }\n" + + "\n" + + " public static > void eval(T x) {\n" + + " }\n" + + " public static interface Foo extends Iterable> {\n" + + " }\n" + + "}", // ================= + }, + // javac options + JavacTestOptions.EclipseHasABug.EclipseBug216558 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 - variation +public void test1249() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void test() {\n" + + " Foo foo = null;\n" + + " eval(foo, foo);\n" + + " X.> eval(foo, foo);\n" + + " }\n" + + " public static > void eval(T t1, T t2) {\n" + + " }\n" + + " public static interface Foo extends Iterable> {\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 +public void test1250() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " static List asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static List> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1251() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static T asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static Sub LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216608 +public void test1252() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " @SuppressWarnings({\"unchecked\", \"rawtypes\"})\n" + + " public B getB() {\n" + + " return new B();\n" + + " }\n" + + "\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void test() {\n" + + " C c = getB().getC();\n" + + " String s = getB().toString();\n" + + " }\n" + + "}\n" + + "class B {\n" + + " public C getC() {\n" + + " return new C();\n" + + " }\n" + + "}\n" + + "class C {\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" + + "2. WARNING in X.java (at line 10)\n" + + " C c = getB().getC();\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type C needs unchecked conversion to conform to C\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216608 - variation +public void test1253() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public B getB() {\n" + + " return new B();\n" + + " }\n" + + "\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void test() {\n" + + " C c = getB().getC();\n" + + " String s = getB().toString();\n" + + " }\n" + + "}\n" + + "class B {\n" + + " public C getC() {\n" + + " return new C();\n" + + " }\n" + + "}\n" + + "class C {\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"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1254() { + this.runConformTest( + new String[] { + "X.java", + " import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1255() { + String xSource = + " import java.util.List;\n" + + "\n" + + "public class X {\n" + + " static XList asList(T x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " static Sub ARRAY = new Sub() { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " static XList> LIST = asList(ARRAY); \n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XList> to XList>\n" + + "----------\n"); + } else { + runConformTest(new String[]{ "X.java", xSource }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1256() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1257() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1258() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1259() { + String xSource = + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static XList> LIST = asList(ARRAY); \n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XList> to XList>\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + + "----------\n"); + } else { + runConformTest(new String[]{ "X.java", xSource }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1260() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1261() { + String xSource = + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static XList> LIST = asList(ARRAY); \n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XList> to XList>\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + + "----------\n"); + } else { + runConformTest(new String[]{ "X.java", xSource }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1262() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static XList> LIST = asList(ARRAY); \n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XList> to XList>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1263() { + String xSource = + "public class X {\n" + + " static XList asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static XList> LIST = asList(ARRAY); \n" + + " }\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}\n" + + "\n" + + "class XList {\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static XList> LIST = asList(ARRAY); \n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from XList> to XList>\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo.Sub[] needs unchecked conversion to conform to X.Foo.Sub[]\n" + + "----------\n"); + } else { + runConformTest(new String[]{ "X.java", xSource }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1264() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " static List asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static List> LIST = asList(ARRAY); \n" + + " }\n" + + " static X.Foo.Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1265() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " static List asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static List> LIST = asList(ARRAY); \n" + + " }\n" + + " static Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216565 - variation +public void test1266() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " static List asList(T[] x) { return null; }\n" + + " static interface Foo {\n" + + " static interface Sub extends Foo {\n" + + " static List> LIST = asList(ARRAY); \n" + + " }\n" + + " static Foo.Sub[] ARRAY = new Sub[] { };\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216705 +public void test1267() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " static interface Foo {\n" + + " }\n" + + " static interface SubFoo extends Foo {\n" + + " }\n" + + " static abstract class AbstractTest {\n" + + " protected static class Bar {\n" + + " }\n" + + " protected abstract List> get();\n" + + " }\n" + + " static class Test extends AbstractTest {\n" + + " @Override\n" + + " protected List> get() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216692 +public void test1268() { + this.runConformTest( + new String[] { + "pkg1/Foo.java", + "package pkg1;\n" + + "import java.util.Map;\n" + + "public class Foo {\n" + + " protected final Map fields = null;\n" + + " protected static class Field { }\n" + + "}\n", + "pkg2/SubFoo.java", + "package pkg2;\n" + + "import pkg1.Foo;\n" + + "public class SubFoo extends Foo {\n" + + " private Field field = null;\n" + + " private void test() {\n" + + " Field field = fields.get(\"test\");\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 +public void test1269() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1270() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#2#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1271() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " ^^^\n" + + "The method put(Class, X.TO) in the type X is not applicable for the arguments (Class, X.OO)\n" + + "----------\n" + : // ATM, in 1.8+ we generate an extra error due to inner poly expression resolution after the target type is known. + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " ^^^\n" + + "The method put(Class, X.TO) in the type X is not applicable for the arguments (Class, X.OO)\n" + + "----------\n" + + "2. ERROR in X.java (at line 24)\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.OO to X.TO\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1272() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.print(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " put(Integer.class, (TO)combine(FUNC2, FUNC1));\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"#CLASSCAST#\");\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "#3##CLASSCAST#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1273() { + String sourceX = + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runConformTest( + new String[] { + "X.java", + sourceX, + }, + "#1#"); + } else { + runNegativeTest( + new String[] { + "X.java", + sourceX + }, + "----------\n" + + "1. ERROR in X.java (at line 28)\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " ^^^^^^^\n" + + "The method combine(X.TT, X.TO) is ambiguous for the type X\n" + + "----------\n" ); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1274() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, X.combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1275() { + String[] input = + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runConformTest( + input, + "#1#"); + } else { + runNegativeTest( + input, + "----------\n" + + "1. ERROR in X.java (at line 28)\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " ^^^^^^^\n" + + "The method combine(X.TT, X.TO) is ambiguous for the type X\n" + + "----------\n"); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1276() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, X.combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1277() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#2#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1278() { + String[] input = + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runConformTest( + input, + "#1#"); + } else { + runNegativeTest( + input, + "----------\n" + + "1. ERROR in X.java (at line 32)\n" + + " put(Integer.class, combine(FUNC2, FUNC1));\n" + + " ^^^^^^^\n" + + "The method combine(X.TT, X.TO) is ambiguous for the type X\n" + + "----------\n"); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1279() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " // some functor and functor instances definitions\n" + + " static interface OO { \n" + + " public T eval(E x);\n" + + " }\n" + + " static interface TO extends OO {\n" + + " public String eval(T x);\n" + + " }\n" + + " static interface TT extends TO {\n" + + " public String eval(String x);\n" + + " }\n" + + " static final TO FUNC1 = null;\n" + + " static final TT FUNC2 = null;\n" + + "\n" + + " // some functor combinators\n" + + " static TO combine(final TT x, final TO y) { // # 1\n" + + " System.out.println(\"#1#\");\n" + + " return new TO() { public String eval(E o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static TO combine(final TO x, final OO y) { // # 2\n" + + " System.out.println(\"#2#\");\n" + + " return new TO() { public String eval(T o) { return x.eval(y.eval(o)); } }; \n" + + " }\n" + + " static OO combine(final OO x, final OO y) { // # 3\n" + + " System.out.println(\"#3#\");\n" + + " return new OO() { public E eval(V o) { return x.eval(y.eval(o)); } };\n" + + " }\n" + + " // body of the test\n" + + " static void put(Class type, TO func) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " put(Integer.class, X.combine(FUNC2, FUNC1));\n" + + " }\n" + + "}\n", // ================= + }, + "#1#"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1280() { + this.runConformTest( + new String[] { + "X.java", + "interface OO {}\n" + + "interface TO extends OO {}\n" + + "interface TT extends TO {}\n" + + "\n" + + "public class X {\n" + + " TO combine(final TO x, final OO y) { return null; }\n" + + " void foo(TT tt, TO too) {\n" + + " combine(tt, too);\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +// FAIL EXTRA ERR, see http://mail.openjdk.java.net/pipermail/lambda-spec-experts/2013-December/000444.html +public void test1281() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + this.runConformTest( + new String[] { + "X.java", + "interface OO {}\n" + + "interface TO extends OO {}\n" + + "interface TT extends TO {}\n" + + "\n" + + "public class X {\n" + + " TO combine(final TO x, final OO[] y) { return null; }\n" + + " void foo(TT tt, TO[] too) {\n" + + " combine(tt, too);\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1282() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static interface OO {}\n" + + " static interface TO extends OO {}\n" + + " static interface TT extends TO {}\n" + + " \n" + + " TO combine(TT x, TO y) { return null; }\n" + + " void foo(TO too, OO oo) {\n" + + " combine(too, oo);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " combine(too, oo);\n" + + " ^^^^^^^\n" + + "The method combine(X.TT, X.TO) in the type X is not applicable for the arguments (X.TO, X.OO)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216686 - variation +public void test1283() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static interface OO {}\n" + + " static interface TO extends OO {}\n" + + " static interface TT extends TO {}\n" + + " \n" + + " TO combine(TT[] x, TO[] y) { return null; }\n" + + " void foo(TO[] too, OO[] oo) {\n" + + " combine(too, oo);\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " combine(too, oo);\n" + + " ^^^^^^^\n" + + "The method combine(X.TT[], X.TO[]) in the type X is not applicable for the arguments (X.TO[], X.OO[])\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 +public void test1284() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1 i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {\n" + + "}\n" + + "interface I2 extends I1 {\n" + + " U get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\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" + + "2. WARNING in X.java (at line 14)\n" + + " return (I2) i;\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from I1 to I2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1285() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup();\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1 i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {\n" + + "}\n" + + "interface I2 extends I1 {\n" + + " U get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " y.foo(z2).get().getThreadGroup();\n" + + " ^^^\n" + + "The method foo(I1) in the type Y is not applicable for the arguments (Z)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1286() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1 i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {}\n" + + "interface I2 extends I1 {\n" + + " U get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\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" + + "2. WARNING in X.java (at line 14)\n" + + " return (I2) i;\n" + + " ^^^^^^^^^\n" + + "Type safety: Unchecked cast from I1 to I2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1287() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1 i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {}\n" + + "interface I2 extends I1 {\n" + + " G get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\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" + + "2. WARNING in X.java (at line 14)\n" + + " return (I2) i;\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from I1 to I2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1288() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1> i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {}\n" + + "interface I2 extends I1> {\n" + + " G get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " return (I2) i;\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from I1> to I2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1289() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Thread th = Thread.currentThread();\n" + + " Z z1 = new Z(th);\n" + + " Z z2 = new Z(new Exception());\n" + + " Y y = new Y() {};\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " I2 foo(I1> i) {\n" + + " return (I2) i;\n" + + " }\n" + + "}\n" + + "interface I1 {}\n" + + "interface I2 extends I1> {\n" + + " G get();\n" + + "}\n" + + "class Z implements I2 {\n" + + " W w;\n" + + " Z(W w) {\n" + + " this.w = w;\n" + + " }\n" + + " public W get() {\n" + + " return this.w;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " y.foo(z1).get().getThreadGroup();\n" + + " ^^^\n" + + "The method foo(I1>) in the type Y is not applicable for the arguments (Z)\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " y.foo(z2).get().getThreadGroup(); // heap pollution: we get a CCE because we return a U2\n" + + " ^^^\n" + + "The method foo(I1>) in the type Y is not applicable for the arguments (Z)\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " return (I2) i;\n" + + " ^^^^^^^^^^^\n" + + "Cannot cast from I1> to I2\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210425 - variation +public void test1290() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " K foo(I i) {\n" + + " return (K) i;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "interface I {\n" + + "}\n" + + "interface J extends I {\n" + + "}\n" + + "interface K extends J {\n" + + "}", // ================= + }, + "----------\n" + + "1. 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=218677 +// FAIL ERRMSG +public void test1291() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static List moreGeneric(List list) {\n" + + " List result = new ArrayList();\n" + + " result.addAll( list );\n" + + " return result;\n" + + " }\n" + + " class A {}\n" + + " class B extends A {}\n" + + " class C extends B {}\n" + + " public static void main( String[] args ) {\n" + + " List b = new ArrayList();\n" + + " List a = moreGeneric(b);\n" + + " List c = moreGeneric(b);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " List c = moreGeneric(b);\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The generic method moreGeneric(List) of type X is not applicable for the arguments (List). The inferred type X.B is not a valid substitute for the bounded parameter \n" + + "----------\n", + JavacTestOptions.EclipseJustification.EclipseBug218677); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=218677 - variation +// FAIL ERRMSG +public void test1292() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static List moreSpecific(List list) {\n" + + " List result = new ArrayList();\n" + + " result.addAll( (List)list );\n" + + " return result;\n" + + " }\n" + + " class A {}\n" + + " class B extends A {}\n" + + " class C extends B {}\n" + + " public static void main( String[] args ) {\n" + + " List b = new ArrayList();\n" + + " List a = moreSpecific(b);\n" + + " List c = moreSpecific(b);\n" + + " }\n" + + "}\n", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " result.addAll( (List)list );\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " List a = moreSpecific(b);\n" + + " ^^^^^^^^^^^^\n" + + "Bound mismatch: The generic method moreSpecific(List) of type X is not applicable for the arguments (List). The inferred type X.A is not a valid substitute for the bounded parameter \n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " result.addAll( (List)list );\n" + + " ^^^^^^\n" + + "The method addAll(Collection) in the type List is not applicable for the arguments (List)\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " List a = moreSpecific(b);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 +public void test1293() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Table {\n" + + " State s;\n" + + " Table() {\n" + + " this.s = new State();\n" + + " }\n" + + " class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation +public void test1294() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Table {\n" + + " State s;\n" + + " Table() {\n" + + " this.s = new State();\n" + + " }\n" + + " class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//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", + "class Deejay {\n" + + " class Counter {}\n" + + "\n" + + " Deejay.Counter songCounter = new Deejay.Counter();\n" + + " Deejay.Counter genreCounter = new Deejay.Counter();\n" + + "\n" + + " java.util.List> list1 = java.util.Arrays.asList(songCounter, genreCounter);\n" + + " java.util.List> list2 = java.util.Arrays.asList(songCounter, genreCounter);\n" + + " java.util.List> list3 = java.util.Arrays.>asList(songCounter, genreCounter);\n" + + " java.util.List> list4 = java.util.Arrays.asList(new Deejay.Counter[] {songCounter, genreCounter});\n" + + " java.util.List> list5 = java.util.Arrays.asList(songCounter, genreCounter);\n" + + "}\n" + + "class Genre {}\n" + + "class Song {}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " java.util.List> list5 = java.util.Arrays.asList(songCounter, genreCounter);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation +public void test1296() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Table {\n" + + " Table.State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new Table.State();\n" + + " }\n" + + "\n" + + " class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation +public void test1297() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Table {\n" + + " X.Table.State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new X().new Table().new State();\n" + + " }\n" + + "\n" + + " class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220111 - variation +public void test1298() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Table {\n" + + " X.Table.State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new X.Table().new State();\n" + + " }\n" + + "\n" + + " class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 +public void test1299() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Table {\n" + + " X.Table.State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new X.Table.State();\n" + + " }\n" + + "\n" + + " static class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 - variation +public void test1300() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Table {\n" + + " State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new State();\n" + + " }\n" + + "\n" + + " static class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 - variation +public void test1301() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class Table {\n" + + " Table.State s;\n" + + "\n" + + " Table() {\n" + + " this.s = new Table.State();\n" + + " }\n" + + "\n" + + " static class State {\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220361 - variation +public void test1302() { + runConformTest( + true, + new String[] { + "EMap.java", + "import java.util.ArrayList;\n" + + "import java.util.Map;\n" + + "\n" + + "public abstract class EMap implements Map {\n" + + " public abstract static class Unsettable extends EMap {\n" + + " protected class UnsettableEList> extends EList {\n" + + " }\n" + + " }\n" + + " protected class EList> extends ArrayList{\n" + + " }\n" + + "}\n", // ================= + }, + null, + "", + null, + JavacTestOptions.EclipseHasABug.EclipseBug159851); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=219625 +public void test1303() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Foo {\n" + + " T getValue();\n" + + " void doSomething(T o);\n" + + " }\n" + + " public static abstract class AbstractFoo implements Foo {\n" + + " /**\n" + + " * If this is removed ConcreteFoo no longer compiles.\n" + + " */\n" + + " public void doSomething(final String o) {\n" + + " }\n" + + " }\n" + + " public static final class ConcreteFoo extends AbstractFoo {\n" + + " public String getValue() {\n" + + " return \"I am a string\";\n" + + " }\n" + + " }\n" + + " /**\n" + + " * We lose the type infomation here so try but fail to call the doSomething(Object) method.\n" + + " */\n" + + " private static void feedFoosValueIntoFoo(final Foo foo) {\n" + + " foo.doSomething(foo.getValue());\n" + + " }\n" + + " private static void testTypedString() {\n" + + " final ConcreteFoo foo = new ConcreteFoo();\n" + + " foo.doSomething(foo.getValue());\n" + + " }\n" + + " private static void testGenericString() {\n" + + " feedFoosValueIntoFoo(new ConcreteFoo());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " testTypedString();\n" + + " testGenericString();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=219625 - variation +public void test1304() { + this.runConformTest( + new String[] { + "X.java", + "interface Foo {\n" + + " T get();\n" + + " void doSomething(T t);\n" + + "}\n" + + "abstract class XSuper implements Foo {\n" + + " public void doSomething(String s) { System.out.println(s); }\n" + + "}\n" + + "public class X extends XSuper {\n" + + " public String get() { return \"SUCCESS\"; }\n" + + " static void doIt(Foo f) {\n" + + " f.doSomething(f.get());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " doIt(new X());\n" + + " }\n" + + "}\n", // ================= + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223334 +public void test1305() { + this.runConformTest( + new String[] { + "bug/ConflictManager.java",// ================= + "package bug;\n" + + "import java.util.*;\n" + + "public class ConflictManager {\n" + + " public List>> getConflictsSortedBySize() {\n" + + " return null;\n" + + " }\n" + + "}\n", + "bug/LayoutOrganizable.java",// ================= + "package bug;\n" + + "public class LayoutOrganizable {\n" + + " private T t;\n" + + "\n" + + " public LayoutOrganizable(T t) {\n" + + " this.t = t;\n" + + "\n" + + " }\n" + + "}\n", + "bug/LayoutOrganizer.java", + "package bug;\n" + + "import java.util.*;\n" + + "public class LayoutOrganizer {\n" + + " ConflictManager> conflictManager = new ConflictManager>();\n" + + " private boolean optimizeEqual() {\n" + + " List>>> list;\n" + + " ListIterator>>> i;\n" + + " // create sorted list of pairs\n" + + " // (#conflicts, list of LayoutOrganizable sharing this #conflicts)\n" + + " // Here is the problem...\n" + + " list = conflictManager.getConflictsSortedBySize();\n" + + " return null == list;\n" + + " }\n" + + "}\n", // ================= + }, + ""); + this.runConformTest( + new String[] { + "bug/LayoutOrganizer.java", + "package bug;\n" + + "import java.util.*;\n" + + "public class LayoutOrganizer {\n" + + " ConflictManager> conflictManager = new ConflictManager>();\n" + + " private boolean optimizeEqual() {\n" + + " List>>> list;\n" + + " ListIterator>>> i;\n" + + " // create sorted list of pairs\n" + + " // (#conflicts, list of LayoutOrganizable sharing this #conflicts)\n" + + " // Here is the problem...\n" + + " list = conflictManager.getConflictsSortedBySize();\n" + + " return null == list;\n" + + " }\n" + + "}\n", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation +public void test1306() { + runNegativeTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.lang.reflect.Constructor;\n" + + "import java.lang.annotation.Documented;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " Constructor c = null;\n" + + " Documented d = c.getAnnotation(Documented.class);\n" + + "}\n", // ================= + }, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 6)\n" + + " Constructor c = null;\n" + + " ^^^^^^^^^^^\n" + + "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " Documented d = c.getAnnotation(Documented.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Documented d = c.getAnnotation(Documented.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to Documented\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBug6400189 /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation +public void test1307() { + this.runNegativeTest( + new String[] { + "Y.java", + "import java.util.List;\n" + + "public class Y {\n" + + " Zork z;\n" + + " Y itself() { return this; }\n" + + " List list() { return null; }\n" + + " Y someY() { return null; }\n" + + "}\n" + + "class Z {\n" + + " void foo(Y y) {\n" + + " Z z = y.itself(); // Y cannot be converted to Z (itself() return type got erased)\n" + + " List l = y.list(); // unchecked conversion from List to List\n" + + " Y ys = y.someY(); // unchecked conversion from Y to Y\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in Y.java (at line 9)\n" + + " void foo(Y y) {\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. ERROR in Y.java (at line 10)\n" + + " Z z = y.itself(); // Y cannot be converted to Z (itself() return type got erased)\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to Z\n" + + "----------\n" + + "4. WARNING in Y.java (at line 11)\n" + + " List l = y.list(); // unchecked conversion from List to List\n" + + " ^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in Y.java (at line 12)\n" + + " Y ys = y.someY(); // unchecked conversion from Y to Y\n" + + " ^^^^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 - variation +public void test1308() { + this.runNegativeTest( + new String[] { + "Y.java", + "@interface MyAnnotation {\n" + + "}\n" + + "class MyAccessibleObject {\n" + + " Object getAnnotation(Class c) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class MyConstructor extends MyAccessibleObject {\n" + + " T getAnnotation(Class c) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class X {\n" + + " void bar1(java.lang.reflect.Constructor constr, Class ann) {\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 1\n" + + " }\n" + + " void bar2(MyConstructor constr, Class ann) {\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 2\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in Y.java (at line 9)\n" + + " T getAnnotation(Class c) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method getAnnotation(Class) of type MyConstructor should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. WARNING in Y.java (at line 14)\n" + + " void bar1(java.lang.reflect.Constructor constr, Class ann) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Constructor is a raw type. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "3. WARNING in Y.java (at line 15)\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 1\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type Constructor. References to generic type Constructor should be parameterized\n" + + "----------\n" + + "4. ERROR in Y.java (at line 15)\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 1\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + + "----------\n" + + "5. WARNING in Y.java (at line 17)\n" + + " void bar2(MyConstructor constr, Class ann) {\n" + + " ^^^^^^^^^^^^^\n" + + "MyConstructor is a raw type. References to generic type MyConstructor should be parameterized\n" + + "----------\n" + + "6. WARNING in Y.java (at line 18)\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method getAnnotation(Class) belongs to the raw type MyConstructor. References to generic type MyConstructor should be parameterized\n" + + "----------\n" + + "7. ERROR in Y.java (at line 18)\n" + + " MyAnnotation a = constr.getAnnotation(ann); // 2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Annotation to MyAnnotation\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=226145 +public void test1309() { + this.runNegativeTest( + new String[] { + "EclipseGenericBug.java", + "public class EclipseGenericBug {\n" + + " static class ParametricClass {\n" + + " static interface NonParametricInterface {\n" + + " static interface ParametricInterface {\n" + + " }\n" + + " }\n" + + " }\n" + + " \n" + + " static class ParametricInstance extends ParametricClass {\n" + + " NonParametricInterface.ParametricInterface instance = null;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=224855 +public void test1310() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Set;\n" + + "public class X {\n" + + " public void testCast(){\n" + + " Set classes = (Set)getClasses();\n" + + " }\n" + + " public Set> getClasses() {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Set classes = (Set)getClasses();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Set classes = (Set)getClasses();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from Set> to Set\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " Set classes = (Set)getClasses();\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=209149 +public void test1311() { + String[] test = new String[] { + "X.java", + "class X {}\n" + + "class Y {}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + test, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y {}\n" + + " ^\n" + + "Illegal forward reference to type parameter D\n" + + "----------\n"); + } else { + this.runConformTest(test, ""); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=226535 +public void test1312() { + this.runConformTest( + new String[] { + "X.java", + " class Tuple3f> {\n" + + " private float x, y, z;\n" + + " float getX() { return this.x; }\n" + + " float getY() { return this.y; }\n" + + " float getZ() { return this.z; }\n" + + " void set(float newX, float newY, float newZ) {\n" + + " this.x = newX;\n" + + " this.y = newY;\n" + + " this.z = newZ;\n" + + " }\n" + + " public T add(Tuple3f t) {\n" + + " this.set(this.getX() + t.getX(), this.getY() + t.getY(), this.getZ() + t.getZ());\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " T result = (T) this;\n" + + " return result;\n" + + " }\n" + + "}\n" + + "\n" + + "class Vector3f extends Tuple3f {\n" + + " float magnitude () {\n" + + " float x = this.getX(), y = this.getY(), z = this.getZ();\n" + + " return (float) Math.sqrt((x*x) + (y*y) + (z*z));\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Vector3f v = new Vector3f();\n" + + " float magn = v.add(v).add(v).magnitude();\n" + + " System.out.println((int)magn);\n" + + " }\n" + + "}\n", // ================= + }, + "0"); +} +public void test1313() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List[] l1 = new List[1];\n" + + " List[] l2 = new List[2];\n" + + " List l3 = new List[3];\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " List[] l2 = new List[2];\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of List\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " List l3 = new List[3];\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List[] to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=230070 +public void test1314() { + this.runNegativeTest( + new String[] { + "X.java", + "class B {\n" + + "}\n" + + "class Y {\n" + + " Y(K k) {\n" + + " System.out.println(k);\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " static final B b = new B();\n" + + " Object foo(K toKey) {\n" + + " if (false) return new Y(b);//1\n" + + " if (false) return new Y((K) b);//2\n" + + " return new Y((K) (Object) b);//3\n" + + " }\n" + + " Object bar(K toKey) {\n" + + " if (false) return new Y(b);//4\n" + + " if (false) return new Y((K) b);//5\n" + + " return new Y((K) (Object) b);//6\n" + + " } \n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " if (false) return new Y(b);//1\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " if (false) return new Y(b);//1\n" + + " ^^^^^^^^\n" + + "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " if (false) return new Y(b);//1\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from B to K\n" + + "----------\n" + + "8. WARNING in X.java (at line 12)\n" + + " if (false) return new Y((K) b);//2\n" + + " ^^^^^\n" + + "Unnecessary cast from B to K\n" + + "----------\n" + + "9. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor Y(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "10. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to K\n" + + "----------\n" + + "12. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to K\n" + + "----------\n" + + "13. WARNING in X.java (at line 13)\n" + + " return new Y((K) (Object) b);//3\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from B to Object\n" + + "----------\n" + + "14. ERROR in X.java (at line 16)\n" + + " if (false) return new Y(b);//4\n" + + " ^^^^^^^^^^^\n" + + "The constructor Y(B) is undefined\n" + + "----------\n" + + "15. WARNING in X.java (at line 17)\n" + + " if (false) return new Y((K) b);//5\n" + + " ^^^^^\n" + + "Type safety: Unchecked cast from B to K\n" + + "----------\n" + + "16. WARNING in X.java (at line 18)\n" + + " return new Y((K) (Object) b);//6\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to K\n" + + "----------\n" + + "17. WARNING in X.java (at line 18)\n" + + " return new Y((K) (Object) b);//6\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from B to Object\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228291 +public void test1315() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X extends Vector> {\n" + + " private static final long serialVersionUID = 1L;\n" + + " public Vector cast(List in) {\n" + + " return (Vector) in;\n" + + " }\n" + + " public X castSilly(Vector> in) {\n" + + " return (X) in;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=230466 +public void test1316() { + this.runConformTest( + new String[] { + "e/AbstractClass.java", // ================= + "package e;\n" + + "public abstract class AbstractClass {\n" + + " protected abstract void method1();\n" + + "}\n", + "q/AbstractTest.java", // ================= + "package q;\n" + + "import java.util.Map;\n" + + "import e.AbstractClass;\n" + + "public abstract class AbstractTest {\n" + + " protected class InnerClass extends AbstractClass{\n" + + " public void innerMethod() {\n" + + " System.out.println(\"innerMethod\");\n" + + " }\n" + + " @Override\n" + + " protected void method1() {\n" + + " System.out.println(\"method1\");\n" + + " }\n" + + " }\n" + + " protected Map records;\n" + + " public abstract void method(); \n" + + "}\n", + "w/Test.java", // ================= + "package w;\n" + + "import q.AbstractTest;\n" + + "public class Test extends AbstractTest {\n" + + " @Override\n" + + " public void method() {\n" + + " // Error here\n" + + " InnerClass inner = records.get(\"1\");\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 +public void test1317() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void foo(String name, String value) {}\n" + + " void foo(String name, T value) {}\n" + + "\n" + + " void foo2(String name, String value) {}\n" + + " > void foo2(String name, T value) {}\n" + + "\n" + + " > T foo3(String name, T value) {}\n" + + "}\n" + + "class M {}\n" + + "class N {}\n" + + "\n" + + "class Test {\n" + + " void test() {\n" + + " new X().foo(\"HI\", null); // correctly report error\n" + + " new X().foo2(\"HI\", null); // miss ambiguous error\n" + + " \n" + + " Thread t1 = foo3(\"HI\", null);\n" + + " Thread t2 = (Thread)foo3(\"HI\", null);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " > 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 +public void test1318() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " > void foo2(String name, T value) {}\n" + + "}\n" + + "class N {}\n" + + "\n" + + "class Test {\n" + + " void test() {\n" + + " new X().foo2(\"HI\", null);\n" + + " new X().>foo2(\"HI\", null);\n" + + " new X().>>foo2(\"HI\", null);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\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 is not a valid substitute for the bounded parameter >\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\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> is not a valid substitute for the bounded parameter >\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation +public void test1319() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "public class X {\n" + + " , U extends List, W extends List> void foo2(String name, U u, T t, W w) {}\n" + + "}\n" + + "\n" + + "class Test {\n" + + " void test() {\n" + + " new X().foo2(\"HI\", null, null, null);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation +public void test1320() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "public class X {\n" + + " , U extends List, W extends List> void foo2(String name, U u, T t, W w) {}\n" + + "}\n" + + "\n" + + "class Test {\n" + + " void test() {\n" + + " new X().foo2(\"HI\", null, null, null);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=229928 - variation +public void test1321() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "public class X {\n" + + " , W extends List> void foo2(String name, U u, T t, W w) {}\n" + + "}\n" + + "\n" + + "class Test {\n" + + " void test() {\n" + + " new X().foo2(\"HI\", null, null, null);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 +public void test1322() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + "\n" + + " /** OK: Bob.class is correct. No idea about the Thingy */\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + "\n" + + " /**\n" + + " * This line will fail when compiled with the Java 5 SDK: Test.java:25:\n" + + " * doStuff(java.lang.Class,Thingy) in Test cannot be applied to\n" + + " * (java.lang.Class,Thingy) test.doStuff(Bill.class, new\n" + + " * Thingy()); ^ Note: Test.java uses unchecked or unsafe operations.\n" + + " * Note: Recompile with -Xlint:unchecked for details. 1 error\n" + + " */\n" + + " x.doStuff(Jim.class, new Thingy());\n" + + " }\n" + + " void doStuff(Class klass, Thingy thingy) {\n" + + " }\n" + + "}\n" + + "class Jim {}\n" + + "class Bob {}\n" + + "class Bob2 extends Bob {}\n" + + "class Thingy {}\n", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doStuff(Class, Thingy) of the generic method doStuff(Class, Thingy) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Thingy needs unchecked conversion to conform to Thingy\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " x.doStuff(Jim.class, new Thingy());\n" + + " ^^^^^^^\n" + + "Bound mismatch: The generic method doStuff(Class, Thingy) of type X is not applicable for the arguments (Class, Thingy). The inferred type Jim is not a valid substitute for the bounded parameter \n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " x.doStuff(Jim.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doStuff(Class, Thingy) of the generic method doStuff(Class, Thingy) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Thingy needs unchecked conversion to conform to Thingy\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " x.doStuff(Jim.class, new Thingy());\n" + + " ^^^^^^^\n" + + "The method doStuff(Class, Thingy) in the type X is not applicable for the arguments (Class, Thingy)\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " x.doStuff(Jim.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +// FAIL ERRMSG and MISSING WARNINGS(?) +public void test1323() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return; + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.doStuff2(Jim.class, new Thingy());\n" + + " String s = x.doStuff2(Bob2.class, new Thingy());\n" + + " }\n" + + " T doStuff2(Class klass, Thingy thingy) { return null; }\n" + + "}\n" + + "class Jim {}\n" + + "class Bob {}\n" + + "class Bob2 extends Bob {}\n" + + "class Thingy {}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " x.doStuff2(Jim.class, new Thingy());\n" + + " ^^^^^^^^\n" + + "Bound mismatch: The generic method doStuff2(Class, Thingy) of type X is not applicable for the arguments (Class, Thingy). The inferred type Jim is not a valid substitute for the bounded parameter \n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " x.doStuff2(Jim.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " String s = x.doStuff2(Bob2.class, new Thingy());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doStuff2(Class, Thingy) of the generic method doStuff2(Class, Thingy) of type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " String s = x.doStuff2(Bob2.class, new Thingy());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Bob2 to String\n" + + "----------\n" + + "5. WARNING in X.java (at line 5)\n" + + " String s = x.doStuff2(Bob2.class, new Thingy());\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Thingy needs unchecked conversion to conform to Thingy\n" + + "----------\n" + + "6. WARNING in X.java (at line 5)\n" + + " String s = x.doStuff2(Bob2.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +public void test1324() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + "\n" + + " /** OK: Bob.class is correct. No idea about the Thingy */\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " x.doStuff(Bob.class, new Thingy()); // second invocation is NOT unchecked\n" + + " Zork z;\n" + + " }\n" + + " T doStuff(Class klass, Thingy thingy) { return null; }\n" + + "}\n" + + "class Jim {}\n" + + "class Bob {}\n" + + "class Thingy {}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doStuff(Class, Thingy) of the generic method doStuff(Class, Thingy) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The expression of type Thingy needs unchecked conversion to conform to Thingy\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " x.doStuff(Bob.class, new Thingy());\n" + + " ^^^^^^\n" + + "Thingy is a raw type. References to generic type Thingy should be parameterized\n" + + "----------\n" + + "4. 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=231094 - variation +public void test1325() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " U foo(X xt) {\n" + + " return null;\n" + + " }\n" + + " void bar(X x) {\n" + + " X xs2 = foo(x);\n" + + " }\n" + + "}\n", // ================= + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void bar(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " X xs2 = foo(x);\n" + + " ^^^^^^\n" + + "Type safety: Unchecked invocation foo(X) of the generic method foo(X) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " X xs2 = foo(x);\n" + + " ^^^^^^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " X xs2 = foo(x);\n" + + " ^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + + "----------\n" + : // 1.8 is stricter: + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void bar(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X xs2 = foo(x);\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + + "----------\n")); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +public void test1326() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " X foo(X xt, X xt2) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x, X xs) {\n" + + " X xs2 = foo(xs, x).identity();\n" + + " }\n" + + "}\n", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " void bar(X x, X xs) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " X xs2 = foo(xs, x).identity();\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(X, X) of type X is not applicable for the arguments (X, X). The inferred type String is not a valid substitute for the bounded parameter \n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " void bar(X x, X xs) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " X xs2 = foo(xs, x).identity();\n" + + " ^^^\n" + + "The method foo(X, X) in the type X is not applicable for the arguments (X, X)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +public void test1327() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " X foo(X xt, X xt2) {\n" + + " return null;\n" + + " }\n" + + " X identity() {\n" + + " return this;\n" + + " }\n" + + " void bar(X x, X xs) {\n" + + " X xs2 = foo(x, xs).identity();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " void bar(X x, X xs) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " X xs2 = foo(x, xs).identity();\n" + + " ^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(X, X) of the generic method foo(X, X) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " X xs2 = foo(x, xs).identity();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " X xs2 = foo(x, xs).identity();\n" + + " ^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231094 - variation +public void test1328() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " \n" + + " void bar(List lb, List lc) {\n" + + " String s = foo(lb, lc);\n" + + " }\n" + + " U foo(List u, List v) { return null; }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C extends A {}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String s = foo(lb, lc);\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from A to String\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232174 +public void test1329() { + this.runConformTest( + new String[] { + "com/b/p1/A.java", // ================= + "package com.b.p1;\n" + + "public class A {\n" + + " protected final class Inner {}\n" + + "}\n", + "com/b/p1/ADerivedSamePkg.java", // ================= + "package com.b.p1;\n" + + "import java.util.Map;\n" + + "public class ADerivedSamePkg extends A {\n" + + " protected void someMethod() {\n" + + " Map.Entry some = null;\n" + + " Inner x = some.getValue();\n" + + " }\n" + + "}\n", + "com/b/p2/ADerivedDifferentPkg.java", // ================= + "package com.b.p2;\n" + + "import java.util.Map;\n" + + "import com.b.p1.A;\n" + + "public class ADerivedDifferentPkg extends A {\n" + + " protected void someMethod() {\n" + + " Map.Entry some = null;\n" + + " Inner x = some.getValue(); // <-- error in this line\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231861 +public void test1330() { + this.runConformTest( + new String[] { + "p/BaseValue.java", // ================= + "package p;\n" + + "interface Value {}\n" + + "public class BaseValue implements Value {}\n", + "p/Model.java", // ================= + "package p;\n" + + "public class Model {\n" + + " public java.util.Map map = new java.util.LinkedHashMap();\n" + + "}\n", // ================= + }, + ""); + this.runConformTest( + new String[] { + "p2/Person.java", // ================= + "package p2;\n" + + "public class Person extends p.Model {\n" + + " void test() {\n" + + " this.map.put(\"name\", new p.BaseValue());\n" + + " }\n" + + "}\n", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=231861 - variation +public void test1331() { + this.runConformTest( + new String[] { + "p/BaseValue.java", // ================= + "package p;\n" + + "interface Value {}\n" + + "public class BaseValue implements Value {}\n", + "p/Model.java", // ================= + "package p;\n" + + "public class Model {\n" + + " public java.util.Map map = new java.util.LinkedHashMap();\n" + + "}\n", + "p2/Person.java", // ================= + "package p2;\n" + + "public class Person extends p.Model {\n" + + " void test() {\n" + + " this.map.put(\"name\", new p.BaseValue());\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232487 +public void test1332() throws Exception { + runConformTest( + // test directory preparation + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X implements Runnable {\n" + + " public void run() {/**/}\n" + + " void foo() {\n" + + " List runnables = new ArrayList();\n" + + " for (Runnable r : runnables) {\n" + + " r.run();\n" + + " }\n" + + " Object o = runnables.get(0);\n" + + " Runnable r = runnables.get(1);\n" + + " }\n" + + "} \n", + }, + // runtime results + "" /* expected output string */); + String expectedOutput = + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 4\n" + + " void foo();\n" + + " 0 new java.util.ArrayList [18]\n" + + " 3 dup\n" + + " 4 invokespecial java.util.ArrayList() [20]\n" + + " 7 astore_1 [runnables]\n" + + " 8 aload_1 [runnables]\n" + + " 9 invokeinterface java.util.List.iterator() : java.util.Iterator [21] [nargs: 1]\n" + + " 14 astore_3\n" + + " 15 goto 34\n" + + " 18 aload_3\n" + + " 19 invokeinterface java.util.Iterator.next() : java.lang.Object [27] [nargs: 1]\n" + + " 24 checkcast java.lang.Runnable [5]\n" + + " 27 astore_2 [r]\n" + + " 28 aload_2 [r]\n" + + " 29 invokeinterface java.lang.Runnable.run() : void [33] [nargs: 1]\n" + + " 34 aload_3\n" + + " 35 invokeinterface java.util.Iterator.hasNext() : boolean [35] [nargs: 1]\n" + + " 40 ifne 18\n" + + " 43 aload_1 [runnables]\n" + + " 44 iconst_0\n" + + " 45 invokeinterface java.util.List.get(int) : java.lang.Object [39] [nargs: 2]\n" + + " 50 astore_2 [o]\n" + + " 51 aload_1 [runnables]\n" + + " 52 iconst_1\n" + + " 53 invokeinterface java.util.List.get(int) : java.lang.Object [39] [nargs: 2]\n" + + " 58 checkcast java.lang.Runnable [5]\n" + + " 61 astore_3 [r]\n" + + " 62 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 8, line: 7]\n" + + " [pc: 28, line: 8]\n" + + " [pc: 34, line: 7]\n" + + " [pc: 43, line: 10]\n" + + " [pc: 51, line: 11]\n" + + " [pc: 62, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 63] local: this index: 0 type: X\n" + + " [pc: 8, pc: 63] local: runnables index: 1 type: java.util.List\n" + + " [pc: 28, pc: 34] local: r index: 2 type: java.lang.Runnable\n" + + " [pc: 51, pc: 63] local: o index: 2 type: java.lang.Object\n" + + " [pc: 62, pc: 63] local: r index: 3 type: java.lang.Runnable\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=225737 +public void test1333() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X extends AbstractProject {\n" + + " public void testBug() {\n" + + " // javac compiles the following line without complaining\n" + + " BuildStepDescriptor.filter(BuildStep.PUBLISHERS, getClass());\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().testBug();\n" + + " }\n" + + "}\n" + + "interface BuildStep {\n" + + " public static final PublisherList PUBLISHERS = new PublisherList();\n" + + "}\n" + + "\n" + + "@SuppressWarnings(\"serial\")\n" + + "class PublisherList extends ArrayList> {\n" + + "}\n" + + "abstract class Publisher implements BuildStep, Describable {\n" + + "}\n" + + "interface Describable> {\n" + + "}\n" + + "abstract class Descriptor> {\n" + + "}\n" + + "abstract class BuildStepDescriptor> extends Descriptor {\n" + + " \n" + + " public static > List> filter(\n" + + " List> base,\n" + + " Class> type) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "abstract class AbstractProject

, R> {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=225737 - variation +public void test1334() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X extends AbstractProject {\n" + + " public void testBug() {\n" + + " filter(getClass());//1\n" + + " filter(this.getClass());//2\n" + + " filter(X.class);//3\n" + + " }\n" + + " public static void filter(Class> type) {\n" + + " }\n" + + "}\n" + + "abstract class AbstractProject

, R> {\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 +public void test1335() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public void doesNotCompile(SomeInterface i) {\n" + + " T t = ((SomeDerivedInterface) i).getItem();\n" + + " }\n" + + " static interface SomeInterface {\n" + + " }\n" + + " static interface SomeDerivedInterface extends SomeInterface {\n" + + " T getItem();\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " T t = ((SomeDerivedInterface) i).getItem();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X.SomeInterface to X.SomeDerivedInterface\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 - variation +public void test1336() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void foo(Other2.Member2 om2) {\n" + + " Other.Member m = (Other.Member) om2;\n" + + " }\n" + + "}\n" + + "class Other {\n" + + " class Member {}\n" + + "}\n" + + "class Other2 extends Other {\n" + + " class Member2 extends Other.Member {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Other.Member m = (Other.Member) om2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Other2.Member2 to Other.Member\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 - variation +public void test1337() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void foo(Other2.Member2 om2) {\n" + + " Other.Member m = (Other.Member) om2;\n" + + " }\n" + + "}\n" + + "class Other {\n" + + " class Member {}\n" + + "}\n" + + "class Other2 extends Other {\n" + + " class Member2 extends Other.Member {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Other.Member m = (Other.Member) om2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Other2.Member2 to Other.Member\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619 +public void test1338() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void m(Object someObject, Integer intObject) {\n" + + " Exception class1 = someObject.getClass();\n" + + " Exception class2 = intObject.getClass();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Exception class1 = someObject.getClass();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Exception\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Exception class2 = intObject.getClass();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Exception\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619 - variation +public void test1339() { + this.runNegativeTest( + new String[] { + "java/lang/Object.java", // ================= + "package java.lang;\n" + + "\n" + + "public class Object {\n" + + " void foo() {\n" + + " Exception e1 = getClass();\n" + + " Exception e2 = this.getClass();\n" + + " }\n" + + " public Class getClass() { return null; }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in java\\lang\\Object.java (at line 5)\n" + + " Exception e1 = getClass();\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Exception\n" + + "----------\n" + + "2. ERROR in java\\lang\\Object.java (at line 6)\n" + + " Exception e2 = this.getClass();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Exception\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235460 +public void test1340() { + this.runConformTest( + new String[] { + "Derived_A.java", // ================= + "import java.util.Map;\n" + + "import java.util.HashMap;\n" + + "class Base_A {}\n" + + "public class Derived_A extends Base_A {\n" + + " public Map getMap() {\n" + + " return new HashMap();\n" + + " }\n" + + "}\n", // ================= + "Derived_B.java", // ================= + "class Base_B {\n" + + "}\n" + + "public class Derived_B extends Base_B {\n" + + "}\n", // ================= + }, + ""); + this.runConformTest( + new String[] { + "InternalCompilerError_Main.java", // ================= + "public class InternalCompilerError_Main {\n" + + " public static void main(String args[]) {\n" + + " Derived_A dummy = new Derived_A();\n" + + " Derived_B propPrice = (Derived_B)dummy.getMap().get(null); \n" + + " }\n" + + "}\n", // ================= + }, + "", + null, + false, + null); +} +//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", // ================= + "import java.util.*;\n" + + "public class X {\n" + + " void bar() {\n" + + " Integer i = 0;\n" + + " Double d = 0.0;\n" + + " foo((Collection) Arrays.asList(i, d));\n" + + " }\n" + + " void foo(Collection c) {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " foo((Collection) Arrays.asList(i, d));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List<"+intersection("Number","Comparable")+"> to Collection\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation +public void test1342() throws Exception { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "interface Adapter {\n" + + " interface Setter {}\n" + + " public Setter makeSetter();\n" + + "}\n" + + "\n" + + "public class X implements Adapter {\n" + + " public X.Setter makeSetter() {\n" + + " return new X.Setter() {};\n" + + " }\n" + + " void foo() {\n" + + " List> l = new ArrayList>();\n" + + " }\n" + + "}\n", // ================= + }, + ""); + // check X$1 + String expectedOutput = + "// Signature: Ljava/lang/Object;LAdapter$Setter;\n" + + "class X$1 implements Adapter$Setter {\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X$1.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + + // check X + expectedOutput = + " // Signature: ()LAdapter$Setter;\n" + + " // Stack: 3, Locals: 1\n" + + " public Adapter.Setter makeSetter();\n"; + + f = new File(OUTPUT_DIR + File.separator + "X.class"); + classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation +public void test1343() throws Exception { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "class Adapter {\n" + + " class Setter {}\n" + + " public Setter makeSetter() { return null; }\n" + + "}\n" + + "\n" + + "public class X extends Adapter {\n" + + " public X.Setter makeSetter() {\n" + + " return new X().new Setter() {};\n" + + " }\n" + + " void foo() {\n" + + " List.Setter> l = new ArrayList.Setter>();\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation +public void test1344() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "class Adapter {\n" + + " class Setter {}\n" + + " public Setter makeSetter() { return null; }\n" + + "}\n" + + "\n" + + "public class X extends Adapter {\n" + + " public X.Setter makeSetter() {\n" + + " return new X().new Setter() {};\n" + + " }\n" + + " void foo() {\n" + + " List l = new ArrayList();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " public class X extends Adapter {\n" + + " ^^^^^^^\n" + + "Adapter is a raw type. References to generic type Adapter should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " public X.Setter makeSetter() {\n" + + " ^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " public X.Setter makeSetter() {\n" + + " ^^^^^^^^^^^^\n" + + "Name clash: The method makeSetter() of type X has the same erasure as makeSetter() of type Adapter but does not override it\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " return new X().new Setter() {};\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " return new X().new Setter() {};\n" + + " ^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " List l = new ArrayList();\n" + + " ^^^^^^^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " List l = new ArrayList();\n" + + " ^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation +public void test1345() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "class Adapter {\n" + + " class Setter {}\n" + + " public Setter makeSetter() { return null; }\n" + + "}\n" + + "\n" + + "public class X extends Adapter {\n" + + " public X.Setter makeSetter() {\n" + + " return (String) new X().new Setter() {};\n" + + " }\n" + + " void foo() {\n" + + " List l = new ArrayList();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " public class X extends Adapter {\n" + + " ^^^^^^^\n" + + "Adapter is a raw type. References to generic type Adapter should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " public X.Setter makeSetter() {\n" + + " ^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " public X.Setter makeSetter() {\n" + + " ^^^^^^^^^^^^\n" + + "Name clash: The method makeSetter() of type X has the same erasure as makeSetter() of type Adapter but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " return (String) new X().new Setter() {};\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from new Adapter.Setter(){} to String\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " return (String) new X().new Setter() {};\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from String to Adapter.Setter\n" + + "----------\n" + + "6. WARNING in X.java (at line 9)\n" + + " return (String) new X().new Setter() {};\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 9)\n" + + " return (String) new X().new Setter() {};\n" + + " ^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 12)\n" + + " List l = new ArrayList();\n" + + " ^^^^^^^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 12)\n" + + " List l = new ArrayList();\n" + + " ^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=235921 - variation +public void test1346() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "class Adapter {\n" + + " class Setter {}\n" + + "}\n" + + "\n" + + "public class X extends Adapter {\n" + + " public Adapter.Setter makeSetter() {\n" + + " return (X.Setter) \"a\";\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public class X extends Adapter {\n" + + " ^^^^^^^\n" + + "Adapter is a raw type. References to generic type Adapter should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " public Adapter.Setter makeSetter() {\n" + + " ^^^^^^^^^^^^^^\n" + + "Adapter.Setter is a raw type. References to generic type Adapter.Setter should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " return (X.Setter) \"a\";\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot cast from String to Adapter.Setter\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236220 +public void test1347() throws Exception { + this.runNegativeTest( + new String[] { + "DeprecatedType.java", // ================= + "class Base {\n" + + " class Member {\n" + + " }\n" + + "}\n" + + "\n" + + "@Deprecated\n" + + "public class DeprecatedType extends Base {\n" + + "}\n", + "X.java", // ================= + "public class X {\n" + + " DeprecatedType.Member m1; // DeprecatedType and Member are raw + indirect access to Member\n" + + " DeprecatedType.Member m2; // DeprecatedType is raw + indirect access to Member\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " DeprecatedType.Member m1; // DeprecatedType and Member are raw + indirect access to Member\n" + + " ^^^^^^^^^^^^^^\n" + + "The type DeprecatedType is deprecated\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " DeprecatedType.Member m1; // DeprecatedType and Member are raw + indirect access to Member\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Base.Member is a raw type. References to generic type Base.Member should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " DeprecatedType.Member m2; // DeprecatedType is raw + indirect access to Member\n" + + " ^^^^^^^^^^^^^^\n" + + "The type DeprecatedType is deprecated\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=174282 - variation +public void test1348() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "abstract class AbstractOBOverlaySettings extends AbstractOverlaySettings implements RefSymbolTypeSettings {/*empty*/}\n" + + "abstract class AbstractOverlaySettings implements SymbolTypeSettings {/*empty*/}\n" + + "interface DAFDataController {/*empty*/}\n" + + "interface ReferenceableData {/*empty*/}\n" + + "enum SymbolTypes {/*empty*/}\n" + + "interface SymbolTypeSettings {/*empty*/}\n" + + "interface AllOverlaySettingsController {/*empty*/}\n" + + "interface DAFDataWithRefController extends DAFDataController {/*empty*/}\n" + + "class OBAreaOverlaySettings extends AbstractOBOverlaySettings {/*empty*/}\n" + + "interface RefSymbolTypeSettings extends SymbolTypeSettings, ReferenceableData {/*empty*/}\n" + + "public class X {\n" + + " public X() {\n" + + " DAFDataController controller00 = null;\n" + + " DAFDataWithRefController controller01 = \n" + + " (DAFDataWithRefController) controller00;\n" + + " }\n" + + " Zork z;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 15)\n" + + " (DAFDataWithRefController) controller00;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from DAFDataController to DAFDataWithRefController\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236707 +public void test1349() { + this.runNegativeTest( + new String[] { + "Scratch.java", // ================= + "public class Scratch {\n" + + " private Y rawObject = new Y();\n" + + " public void caller() {\n" + + " method(new X>(), rawObject); // compile error in javac, unchecked conversion in Eclipse\n" + + " this.>method(new X>(), rawObject); // unchecked warning in both\n" + + " }\n" + + " public void method(X x, T t) {}\n" + + "}\n" + + "class X {}\n" + + "class Y {}\n" + + "class Z { Zork z; }\n", // ================= + }, + "----------\n" + + "1. WARNING in Scratch.java (at line 2)\n" + + " private Y rawObject = new Y();\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. WARNING in Scratch.java (at line 2)\n" + + " private Y rawObject = new Y();\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. WARNING in Scratch.java (at line 4)\n" + + " method(new X>(), rawObject); // compile error in javac, unchecked conversion in Eclipse\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation method(X>, Y) of the generic method method(X, T) of type Scratch\n" + + "----------\n" + + "4. WARNING in Scratch.java (at line 4)\n" + + " method(new X>(), rawObject); // compile error in javac, unchecked conversion in Eclipse\n" + + " ^^^^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n" + + "5. WARNING in Scratch.java (at line 5)\n" + + " this.>method(new X>(), rawObject); // unchecked warning in both\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation method(X>, Y) of the generic method method(X, T) of type Scratch\n" + + "----------\n" + + "6. WARNING in Scratch.java (at line 5)\n" + + " this.>method(new X>(), rawObject); // unchecked warning in both\n" + + " ^^^^^^^^^\n" + + "Type safety: The expression of type Y needs unchecked conversion to conform to Y\n" + + "----------\n" + + "7. ERROR in Scratch.java (at line 11)\n" + + " class Z { Zork z; }\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 +public void test1350() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "interface TreeVisitor {\n" + + " public T visit(U location);\n" + + "}\n" + + "\n" + + "interface TreeVisitable {\n" + + " public T visit(TreeVisitor visitor) throws IOException;\n" + + "}\n" + + "\n" + + "abstract class Param implements TreeVisitable {\n" + + " public final Param lookforParam(final String name) {\n" + + " TreeVisitor visitor = new TreeVisitor() {\n" + + " public Param visit(Param location) {\n" + + " return null;\n" + + " }\n" + + " };\n" + + " return visit(visitor);\n" + + " }\n" + + "\n" + + " public abstract T visit(TreeVisitor visitor);\n" + + "}\n" + + "\n" + + "class StructParam extends Param {\n" + + " public T visit(TreeVisitor visitor) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " StructParam p = new StructParam();\n" + + " p.lookforParam(\"abc\");\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}\n", // ================= + }, + "done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 - variation +public void test1351() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "interface IFoo {\n" + + " T foo(T t) throws IOException;\n" + + "}\n" + + "interface JFoo {\n" + + " T foo(T t) throws Exception;\n" + + "}\n" + + "abstract class Foo implements IFoo, JFoo {}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f = createFoo();\n" + + " try {\n" + + " f.foo(null);\n" + + " } catch(IOException e) {\n" + + " }\n" + + " System.out.println(\"done\");\n" + + " }\n" + + " static Foo createFoo() {\n" + + " return new Foo() {\n" + + " public T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n", // ================= + }, + "done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 - variation +public void test1352() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "interface IFoo {\n" + + " T foo(T t) throws IOException;\n" + + "}\n" + + "interface JFoo {\n" + + " T foo(T t) throws Exception;\n" + + "}\n" + + "abstract class Foo implements IFoo, JFoo {}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f = createFoo();\n" + + " try {\n" + + " f.foo(null);\n" + + " } catch(IOException e) {\n" + + " }\n" + + " System.out.println(\"done\"); //dd\n" + + " }\n" + + " static Foo createFoo() {\n" + + " return new Foo() {\n" + + " public T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n", // ================= + }, + "done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238484 - variation +public void test1353() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "interface IFoo {\n" + + " T foo(T t) throws IOException;\n" + + "}\n" + + "interface JFoo {\n" + + " T foo(T t);\n" + + "}\n" + + "abstract class Foo implements IFoo, JFoo {}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Foo f = createFoo();\n" + + " try {\n" + + " f.foo(null);\n" + + " } catch(IOException e) {\n" + + " }\n" + + " System.out.println(\"done\"); //dd\n" + + " }\n" + + " static Foo createFoo() {\n" + + " return new Foo() {\n" + + " public T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " } catch(IOException e) {\n" + + " ^^^^^^^^^^^\n" + + "Unreachable catch block for IOException. This exception is never thrown from the try statement body\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=237912 +public void test1354() { + this.runConformTest( + new String[] { + "X.java", // ================= + "interface Operation extends CheckedOperation {\n" + + " void op(In o);\n" + + "}\n" + + "\n" + + "interface CheckedOperation {\n" + + " void op(In o) throws E;\n" + + "}\n" + + "\n" + + "class ToUpper implements Operation {\n" + + " public void op(String o) {\n" + + " System.out.print(\"[\"+o.toUpperCase()+\"]\");\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new ToUpper().op(\"hello world 1\"); // Works\n" + + " Operation t = new ToUpper();\n" + + " t.op(\"hello world 2\"); // Doesn\'t work: Exception in thread \"main\" java.lang.NoSuchMethodError: Operation.op(Ljava/lang/String;)V\n" + + " }\n" + + "}\n", // ================= + }, + "[HELLO WORLD 1][HELLO WORLD 2]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=237912 - variation +public void test1355() { + this.runConformTest( + new String[] { + "X.java", // ================= + "interface Operation extends CheckedOperation {\n" + + " void op(In o) throws RuntimeException;\n" + + "}\n" + + "\n" + + "interface CheckedOperation {\n" + + " void op(In o) throws E;\n" + + "}\n" + + "\n" + + "class ToUpper implements Operation {\n" + + " public void op(String o) {\n" + + " System.out.print(\"[\"+o.toUpperCase()+\"]\");\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new ToUpper().op(\"hello world 1\"); // Works\n" + + " Operation t = new ToUpper();\n" + + " t.op(\"hello world 2\"); // Doesn\'t work: Exception in thread \"main\" java.lang.NoSuchMethodError: Operation.op(Ljava/lang/String;)V\n" + + " }\n" + + "}\n", // ================= + }, + "[HELLO WORLD 1][HELLO WORLD 2]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=237912 - variation +public void test1356() { + this.runConformTest( + new String[] { + "X.java", // ================= + "class Activator {\n" + + "}\n" + + "interface Child extends Parent {\n" + + " Activator get(T value);\n" + + "}\n" + + "interface Parent {\n" + + " Activator get(T value) throws RuntimeException;\n" + + "}\n" + + "public class X {\n" + + " static class Impl implements Child {\n" + + " public Activator get(T value) {\n" + + " System.out.println(\"done\");\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Child c = new Impl();\n" + + " try {\n" + + " c.get(true);\n" + + " } catch (Throwable t) { \n" + + " t.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 +public void test1357() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "@interface Ann { Class value(); }\n" + + "\n" + + "/**\n" + + " * @see Private - Private is not visible here\n" + + " */\n" + + "@Ann(X.Private.class) // Private is not visible here\n" + + "public abstract class X implements Map {\n" + + " /**\n" + + " * @see Private - Private is visible here\n" + + " */\n" + + " private static interface Private {}\n" + + " Private field;\n" + + "}\n" + + "class Secondary {\n" + + " private static interface SecondaryPrivate {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " public abstract class X implements Map {\n" + + " ^^^^^^^^^\n" + + "The type X.Private is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public abstract class X implements Map {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type Secondary.SecondaryPrivate is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 - variation +public void test1358() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "public abstract class X implements List {\n" + + " /**\n" + + " * @see Inter.Private - Private is visible here\n" + + " */\n" + + " class Inter {\n" + + " private class Private {}\n" + + " }\n" + + " Inter.Private field;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public abstract class X implements List {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The type X.Inter.Private is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 - variation +public void test1359() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " class M1 {\n" + + " private class Private {\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " M1.Private p;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 +public void test1360() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static T getValue(final Object bean, final String property) {\n" + + " return (T)new Object();\n" + + " }\n" + + " public void testGenerics() {\n" + + " int value = getValue(new Object(), \"\");\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 - variation +public void test1361() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static T getValue(T t) {\n" + + " return t;\n" + + " }\n" + + " public void testGenerics() {\n" + + " int value = getValue(0);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 - variation +public void test1362() { + this.runConformTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static T getValue(T t1, T t2) {\n" + + " return t1;\n" + + " }\n" + + " public void testGenerics() {\n" + + " getValue(0, this);\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239118 - variation +public void test1363() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static T getValue(T t1, T t2) {\n" + + " return t1;\n" + + " }\n" + + "\n" + + " public void testGenerics(Comparable s) {\n" + + " int i = getValue(0, s);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " int i = getValue(0, s);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Comparable","Serializable")+"> to int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239225 +public void test1364() { + this.runNegativeTest( + new String[] { + "Status.java", // ================= + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "public enum Status {\n" + + " GOOD((byte) 0x00), BAD((byte) 0x02);\n" + + "\n" + + " private static Map mapping;\n" + + "\n" + + " private Status(final byte newValue) {\n" + + "\n" + + " if (Status.mapping == null) {\n" + + " Status.mapping = new HashMap();\n" + + " }\n" + + "\n" + + " Status.mapping.put(newValue, this);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in Status.java (at line 11)\n" + + " if (Status.mapping == null) {\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n" + + "2. ERROR in Status.java (at line 12)\n" + + " Status.mapping = new HashMap();\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n" + + "3. ERROR in Status.java (at line 15)\n" + + " Status.mapping.put(newValue, this);\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239203 +public void test1365() { + this.runConformTest( + new String[] { + "C.java", // ================= + "class A {\n" + + "}\n" + + "\n" + + "class B {\n" + + "}\n" + + "\n" + + "public class C {\n" + + " > A foo(Class clazz) {\n" + + " A ret = bar(\"bla\");\n" + + " return ret;\n" + + " }\n" + + "\n" + + " > A bar(String clazzName) {\n" + + " return null;\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 +public void test1366() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.io.IOException;\n" + + "\n" + + "interface IServiceAction {\n" + + " Response execute(Request parameter) throws Fault;\n" + + "}\n" + + "\n" + + "interface IServiceOperation extends IServiceAction {\n" + + " Response execute(Request parameter) throws Fault;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public String execute(String parameter) throws IOException {\n" + + " return serviceOperation.execute(parameter);\n" + + " }\n" + + "\n" + + " private final IServiceOperation serviceOperation = null;\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239439 +public void test1367() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " private static Map var;\n" + + " static {\n" + + " var= new HashMap();\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private static Map var;\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " var= new HashMap();\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " var= new HashMap();\n" + + " ^^^^^^^\n" + + "HashMap cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=244164 +public void test1368() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " private static Map map = new HashMap();\n" + + " public static X foo(String s) {\n" + + " return map.get(s);\n" + + " }\n" + + "}",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " private static Map map = new HashMap();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " return map.get(s);\n" + + " ^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=244164 +public void test1369() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class X {\n" + + " A a; // E is undefined on purpose\n" + + " X() { a = new A(); } // causes Missing code implementation\n" + + "}", + "A.java", + "class A {}",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " A a; // E is undefined on purpose\n" + + " ^\n" + + "E cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " X() { a = new A(); } // causes Missing code implementation\n" + + " ^\n" + + "E cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " X() { a = new A(); } // causes Missing code implementation\n" + + " ^\n" + + "E cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 +public void test1370() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public NonPublicInterfaceImplementor selfCall() {\n" + + " return this;\n" + + " }\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().selfCall());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1371() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public E selfCall() {\n" + + " return null;\n" + + " }\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().selfCall());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1372() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public E selfCall() {\n" + + " return null;\n" + + " }\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().selfCall());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1373() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public NonPublicInterfaceImplementor next;\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(new NonPublicInterfaceImplementor().next);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1374() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public NonPublicInterfaceImplementor next;\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " NonPublicInterfaceImplementor impl = new NonPublicInterfaceImplementor();\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(impl.next);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1375() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {\n" + + " public NonPublicInterfaceImplementor next;\n" + + "}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public static void main(String[] args) {\n" + + " NonPublicInterfaceImplementor impl = new NonPublicInterfaceImplementor();\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(impl.next.next);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=242448 - variation +public void test1376() { + this.runConformTest( + new String[] { + "restricted/NonPublicInterface.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "interface NonPublicInterface {}\n", + "restricted/NonPublicInterfaceImplementor.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class NonPublicInterfaceImplementor implements NonPublicInterface {}\n", + "restricted/UnuseableOutsideRestrictedWithECJ.java", //----------------------------------------------------------------------- + "package restricted;\n" + + "public class UnuseableOutsideRestrictedWithECJ {\n" + + " public void ecjDoesNotLikeGenericizedParameter(NonPublicInterface notVisible) { }\n" + + "}\n", + "usesrestricted/CannotCompileInEcj.java", //----------------------------------------------------------------------- + "package usesrestricted;\n" + + "import restricted.UnuseableOutsideRestrictedWithECJ;\n" + + "import restricted.NonPublicInterfaceImplementor;\n" + + "public class CannotCompileInEcj {\n" + + " public NonPublicInterfaceImplementor next;\n" + + " public void foo() {\n" + + " new UnuseableOutsideRestrictedWithECJ().ecjDoesNotLikeGenericizedParameter(next);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=245453 +public void test1377() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.rmi.RemoteException;\n" + + "public class X {\n" + + " private static T foo() throws T {\n" + + " throw (T) new InterruptedException();\n" + + " }\n" + + " private static void foo2() {\n" + + " try {\n" + + " RemoteException ex = foo();\n" + + " } catch (RemoteException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " public static void main( String[] args) {\n" + + " foo2();\n" + + " Zork z;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " throw (T) new InterruptedException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from InterruptedException to T\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=241502 +public void test1378() { + this.runConformTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "//the remote-usable interface\n" + + "class RemoteException extends Throwable {}\n" + + " \n" + + "interface RemoteStore {\n" + + " public abstract

P get(Class

c) throws RemoteException;\n" + + "}\n" + + "\n" + + "//the interface for local use\n" + + "interface Store extends RemoteStore{\n" + + " public

P get(Class

c) ;\n" + + "}\n" + + "\n" + + "//the implementation\n" + + "class StoreImpl implements Store {\n" + + " public

P get(Class

c) {\n" + + " System.out.print(\"[get]\");\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class Persistent {\n" + + "}\n" + + "\n" + + "public class X {\n" + + "public static void main(String[] args) {\n" + + " try {\n" + + " RemoteStore t = new StoreImpl();\n" + + " t.get(Object.class); //works\n" + + " t.get(Persistent.class); //works\n" + + " } catch (RemoteException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " Store t = new StoreImpl();\n" + + " t.get(Object.class); //works\n" + + " t.get(Persistent.class); //NoSuchMethodError\n" + + "} \n" + + "}\n",//----------------------------------------------------------------------- + }, + "[get][get][get][get]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=245453 - variation +public void test1379() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.rmi.RemoteException;\n" + + "public class X{\n" + + " private static T foo() {\n" + + " return (T)new InterruptedException();\n" + + " }\n" + + " public static void main( String[] args) {\n" + + " RemoteException ex = foo();\n" + + " Zork z;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return (T)new InterruptedException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from InterruptedException to T\n" + + "----------\n" + + "2. 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=174447 +public void test1380() { + this.runConformTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public static > void f() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " f();\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953 +// FIXME javac8 rejects (why?) +public void test1381() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " void foo() {\n" + + " this.t.baz();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X xcc = new X();\n" + + " xcc.t = new CC();\n" + + " xcc.foo();\n" + + " }\n" + + "}\n" + + "class AA {\n" + + " void bar() {}\n" + + "}\n" + + "class CC extends AA implements p.IB {\n" + + " public void baz() {\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}\n", + "p/IB.java", // ===================== + "package p;\n" + + "interface IA {\n" + // non visible + " void baz();\n" + + "}\n" + + "public interface IB extends IA {\n" + + "}\n", + }, + "done"); + // check #baz() invocation declaring class is IB + String expectedOutput = + " // Method descriptor #10 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield X.t : AA [21]\n" + + " 4 checkcast p.IB [23]\n" + + " 7 invokeinterface p.IB.baz() : void [25] [nargs: 1]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 12, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953 - variation +public void test1382() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " \n" + + " void foo() {\n" + + " X xbb = new X();\n" + + " xbb.get().bar();\n" + + " }\n" + + "}\n" + + "class AA {\n" + + " void bar() {}\n" + + "}\n" + + "class BB extends AA {}\n" + }, + ""); + // check #bar() invocation declaring class is BB + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " void foo();\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 invokespecial X() [21]\n" + + " 7 astore_1 [xbb]\n" + + " 8 aload_1 [xbb]\n" + + " 9 invokevirtual X.get() : java.lang.Object [22]\n" + + " 12 checkcast BB [24]\n" + + " 15 invokevirtual BB.bar() : void [26]\n" + + " 18 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 18, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: this index: 0 type: X\n" + + " [pc: 8, pc: 19] local: xbb index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953 - variation +public void test1383() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " \n" + + " void foo() {\n" + + " X xbb = new X();\n" + + " int j = xbb.get().bar;\n" + + " }\n" + + "}\n" + + "class AA {\n" + + " int bar;\n" + + "}\n" + + "class BB extends AA {}\n" + }, + ""); + // check #bar field read declaring class is BB + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 3\n" + + " void foo();\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 invokespecial X() [21]\n" + + " 7 astore_1 [xbb]\n" + + " 8 aload_1 [xbb]\n" + + " 9 invokevirtual X.get() : java.lang.Object [22]\n" + + " 12 checkcast BB [24]\n" + + " 15 getfield BB.bar : int [26]\n" + + " 18 istore_2 [j]\n" + + " 19 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 19, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 20] local: this index: 0 type: X\n" + + " [pc: 8, pc: 20] local: xbb index: 1 type: X\n" + + " [pc: 19, pc: 20] local: j index: 2 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953 - variation +public void test1384() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " \n" + + " void foo() {\n" + + " X xbb = new X();\n" + + " xbb.get().bar = 12;\n" + + " }\n" + + "}\n" + + "class AA {\n" + + " int bar;\n" + + "}\n" + + "class BB extends AA {}\n" + }, + ""); + // check #bar field store declaring class is BB + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " void foo();\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 invokespecial X() [21]\n" + + " 7 astore_1 [xbb]\n" + + " 8 aload_1 [xbb]\n" + + " 9 invokevirtual X.get() : java.lang.Object [22]\n" + + " 12 checkcast BB [24]\n" + + " 15 bipush 12\n" + + " 17 putfield BB.bar : int [26]\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 20, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 21] local: this index: 0 type: X\n" + + " [pc: 8, pc: 21] local: xbb index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953 - variation +public void test1385() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " \n" + + " void foo(X xt) {\n" + + " xt.get().baz();\n" + + " }\n" + + "}\n" + + "class AA {\n" + + " void bar() {}\n" + + "}\n" + + "interface IA {\n" + + " void baz();\n" + + "}\n" + + "interface IB extends IA {\n" + + "}\n" + }, + ""); + // check #baz() invocation declaring class is not IA + String expectedOutput = + " // Method descriptor #21 (LX;)V\n" + + " // Signature: (LX;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(X xt);\n" + + " 0 aload_1 [xt]\n" + + " 1 invokevirtual X.get() : AA [23]\n" + + " 4 checkcast IB [25]\n" + + " 7 invokeinterface IB.baz() : void [27] [nargs: 1]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 12, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: this index: 0 type: X\n" + + " [pc: 0, pc: 13] local: xt index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953 - variation +//FIXME javac8 rejects (why?) +public void test1386() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T get() { return null; }\n" + + " \n" + + " void foo(X xt) {\n" + + " xt.get().baz();\n" + + " }\n" + + "}\n" + + "class AA {\n" + + " void bar() {}\n" + + "}\n", + "p/IB.java", // ===================== + "package p;\n" + + "interface IA {\n" + + " void baz();\n" + + "}\n" + + "public interface IB extends IA {\n" + + "}\n", + }, + ""); + // check #baz() invocation declaring class is not IA + String expectedOutput = + " // Method descriptor #21 (LX;)V\n" + + " // Signature: (LX;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(X xt);\n" + + " 0 aload_1 [xt]\n" + + " 1 invokevirtual X.get() : AA [23]\n" + + " 4 checkcast p.IB [25]\n" + + " 7 invokeinterface p.IB.baz() : void [27] [nargs: 1]\n" + + " 12 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 12, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: this index: 0 type: X\n" + + " [pc: 0, pc: 13] local: xt index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953 - variation +//FIXME javac8 rejects (why?) +public void test1387() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " void foo() {\n" + + " System.out.println(this.t.baz);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X xcc = new X();\n" + + " xcc.t = new CC();\n" + + " xcc.foo();\n" + + " }\n" + + "}\n" + + "class AA {\n" + + " void bar() {}\n" + + "}\n" + + "class CC extends AA implements p.IB {\n" + + "}\n", + "p/IB.java", // ===================== + "package p;\n" + + "interface IA {\n" + + " Object baz = \"done\";\n" + + "}\n" + + "public interface IB extends IA {\n" + + "}\n", + }, + "done"); + // check #baz declaring class is not IA + String expectedOutput = + " // Method descriptor #10 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " void foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 3 aload_0 [this]\n" + + " 4 getfield X.t : AA [27]\n" + + " 7 checkcast p.IB [29]\n" + + " 10 pop\n" + + " 11 getstatic p.IB.baz : java.lang.Object [31]\n" + + " 14 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [35]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 17, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953 - variation +//FIXME javac8 rejects (why?) +public void test1388() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " T t;\n" + + " void foo() {\n" + + " System.out.println(t.baz);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X xcc = new X();\n" + + " xcc.t = new CC();\n" + + " xcc.foo();\n" + + " }\n" + + "}\n" + + "class AA {\n" + + " void bar() {}\n" + + "}\n" + + "class CC extends AA implements p.IB {\n" + + "}\n", + "p/IB.java", // ===================== + "package p;\n" + + "interface IA {\n" + + " Object baz = \"done\";\n" + + "}\n" + + "public interface IB extends IA {\n" + + "}\n", + }, + "done"); + // check #baz declaring class is not IA + String expectedOutput = + " // Method descriptor #10 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " void foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [21]\n" + + " 3 aload_0 [this]\n" + + " 4 getfield X.t : AA [27]\n" + + " 7 checkcast p.IB [29]\n" + + " 10 pop\n" + + " 11 getstatic p.IB.baz : java.lang.Object [31]\n" + + " 14 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [35]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 17, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247953 - variation +public void test1389() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X extends AA implements p.IB {\n" + + " void foo() {\n" + + " System.out.println(baz);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + + "class AA {\n" + + " void bar() {}\n" + + "}\n", + "p/IB.java", // ===================== + "package p;\n" + + "interface IA {\n" + + " Object baz = \"done\";\n" + + "}\n" + + "public interface IB extends IA {\n" + + "}\n", + }, + "done"); + // check #baz declaring class is not IA + String expectedOutput = + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " void foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [17]\n" + + " 3 getstatic X.baz : java.lang.Object [23]\n" + + " 6 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [27]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 9, line: 4]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test1390() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //================================= + "public class X>> {\n" + + " T sx1() { return null; }\n" + + " void foo(X x0) {\n" + + " x0.sx1().sx2().t().getClass();\n" + + " }\n" + + "}\n" + + "interface X1> {\n" + + " T sx2();\n" + + "}\n" + + "abstract class SubX1> implements X1 {\n" + + "}\n" + + "interface X2 {\n" + + " T t();\n" + + "}\n" + + "abstract class SubX2 implements X2 {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X>> {\n" + + " ^^^^^\n" + + "Bound mismatch: The type SubX2 is not a valid substitute for the bounded parameter > of the type SubX1\n" + + "----------\n"); +} +public void test1391() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + " T sx1() { return null; }\n" + + " void foo(X x0) {\n" + + " x0.sx1().sx2().t().getClass();\n" + + " }\n" + + "}\n" + + "interface X1> {\n" + + " T sx2();\n" + + "}\n" + + "abstract class SubX1> implements X1 {\n" + + "}\n" + + "interface X2 {\n" + + " T t();\n" + + "}\n" + + "abstract class SubX2> implements X1, X2 {\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #21 (LX;)V\n" + + " // Signature: (LX;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(X x0);\n" + + " 0 aload_1 [x0]\n" + + " 1 invokevirtual X.sx1() : SubX2 [23]\n" + + " 4 invokevirtual SubX2.sx2() : SubX2 [25]\n" + + " 7 invokevirtual SubX2.t() : java.lang.Object [30]\n" + + " 10 checkcast SubX2 [26]\n" + + " 13 invokevirtual java.lang.Object.getClass() : java.lang.Class [34]\n" + + " 16 pop\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 17, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n" + + " [pc: 0, pc: 18] local: x0 index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test1392() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + " T sx1;\n" + + " void foo(X x0) {\n" + + " x0.sx1.sx2.t.getClass();\n" + + " }\n" + + "}\n" + + "class X1> {\n" + + " T sx2;\n" + + "}\n" + + "abstract class SubX1> extends X1 {\n" + + "}\n" + + "class X2> extends X1{\n" + + " T t;\n" + + "}\n" + + "abstract class SubX2> extends X2 {\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #21 (LX;)V\n" + + " // Signature: (LX;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(X x0);\n" + + " 0 aload_1 [x0]\n" + + " 1 getfield X.sx1 : SubX2 [23]\n" + + " 4 getfield SubX2.sx2 : SubX2 [25]\n" + + " 7 getfield SubX2.t : SubX2 [30]\n" + + " 10 invokevirtual java.lang.Object.getClass() : java.lang.Class [33]\n" + + " 13 pop\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 14, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: X\n" + + " [pc: 0, pc: 15] local: x0 index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test1393() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + " T sx1;\n" + + " void foo(X x0) {\n" + + " x0.sx1.sx2.t.getClass();\n" + + " }\n" + + "}\n" + + "interface X1> {\n" + + "}\n" + + "abstract class SubX1> implements X1 {\n" + + " T sx2;\n" + + "}\n" + + "interface X2> extends X1{\n" + + "}\n" + + "abstract class SubX2> extends SubX1 implements X2 {\n" + + " T t;\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #21 (LX;)V\n" + + " // Signature: (LX;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(X x0);\n" + + " 0 aload_1 [x0]\n" + + " 1 getfield X.sx1 : SubX2 [23]\n" + + " 4 getfield SubX2.sx2 : X2 [25]\n" + + " 7 checkcast SubX2 [26]\n" + + " 10 getfield SubX2.t : X2 [31]\n" + + " 13 checkcast SubX2 [26]\n" + + " 16 invokevirtual java.lang.Object.getClass() : java.lang.Class [34]\n" + + " 19 pop\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 20, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 21] local: this index: 0 type: X\n" + + " [pc: 0, pc: 21] local: x0 index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test1394() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + " T sx1(){return null;}\n" + + " void foo(X x0) {\n" + + " x0.sx1().sx2().t().getClass();\n" + + " }\n" + + "}\n" + + "interface X1> {\n" + + "}\n" + + "abstract class SubX1> implements X1 {\n" + + " T sx2(){return null;}\n" + + "}\n" + + "interface X2> extends X1{\n" + + "}\n" + + "abstract class SubX2> extends SubX1 implements X2 {\n" + + " T t(){return null;}\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #21 (LX;)V\n" + + " // Signature: (LX;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(X x0);\n" + + " 0 aload_1 [x0]\n" + + " 1 invokevirtual X.sx1() : SubX2 [23]\n" + + " 4 invokevirtual SubX2.sx2() : X2 [25]\n" + + " 7 checkcast SubX2 [26]\n" + + " 10 invokevirtual SubX2.t() : X2 [31]\n" + + " 13 checkcast SubX2 [26]\n" + + " 16 invokevirtual java.lang.Object.getClass() : java.lang.Class [34]\n" + + " 19 pop\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 20, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 21] local: this index: 0 type: X\n" + + " [pc: 0, pc: 21] local: x0 index: 1 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test1395() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + " T sx1(){return null;}\n" + + " void foo() {\n" + + " this.sx1().sx2().t().getClass();\n" + + " }\n" + + "}\n" + + "interface X1> {\n" + + "}\n" + + "abstract class SubX1> implements X1 {\n" + + " T sx2(){return null;}\n" + + "}\n" + + "interface X2> extends X1{\n" + + "}\n" + + "abstract class SubX2> extends SubX1 implements X2 {\n" + + " T t(){return null;}\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.sx1() : SubX2 [21]\n" + + " 4 invokevirtual SubX2.sx2() : X2 [23]\n" + + " 7 checkcast SubX2 [24]\n" + + " 10 invokevirtual SubX2.t() : X2 [29]\n" + + " 13 checkcast SubX2 [24]\n" + + " 16 invokevirtual java.lang.Object.getClass() : java.lang.Class [32]\n" + + " 19 pop\n" + + " 20 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 20, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 21] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 21] local: this index: 0 type: X\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test1396() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X> {\n" + + " T sx1;\n" + + " void foo(T t) {\n" + + " t.sx2.t.getClass();\n" + + " }\n" + + "}\n" + + "interface X1> {\n" + + "}\n" + + "abstract class SubX1> implements X1 {\n" + + " T sx2;\n" + + "}\n" + + "interface X2> extends X1{\n" + + "}\n" + + "abstract class SubX2> extends SubX1 implements X2 {\n" + + " T t;\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #21 (LSubX2;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo(SubX2 t);\n" + + " 0 aload_1 [t]\n" + + " 1 getfield SubX2.sx2 : X2 [23]\n" + + " 4 checkcast SubX2 [24]\n" + + " 7 getfield SubX2.t : X2 [29]\n" + + " 10 checkcast SubX2 [24]\n" + + " 13 invokevirtual java.lang.Object.getClass() : java.lang.Class [32]\n" + + " 16 pop\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 17, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n" + + " [pc: 0, pc: 18] local: t index: 1 type: SubX2\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=172672 +public void _test1397() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class A { }\n" + + "class B { }\n" + + "class C extends B>>> {\n" + + " B> foo(C c) { return c; }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 +public void test1398() throws Exception { + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " void f() {\n" + + " boolean b=null instanceof A; \n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in A.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 - variation +public void test1399() throws Exception { + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " void f() {\n" + + " boolean b=null instanceof A; \n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in A.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 - variation +public void test1400() throws Exception { + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " void f() {\n" + + " Object o = (A)this; \n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in A.java (at line 3)\n" + + " Object o = (A)this; \n" + + " ^^^^^^^\n" + + "Unnecessary cast from A to A\n" + + "----------\n" + + "2. WARNING in A.java (at line 3)\n" + + " Object o = (A)this; \n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "3. ERROR in A.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 - variation +public void test1401() throws Exception { + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " void f() {\n" + + " Object o = (A)this; \n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in A.java (at line 3)\n" + + " Object o = (A)this; \n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from A to A\n" + + "----------\n" + + "2. ERROR in A.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 - variation +public void test1402() throws Exception { + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " void f() {\n" + + " Class c = A.class; \n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in A.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252120 - variation +public void test1403() throws Exception { + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " void f() {\n" + + " Class c = A.class; \n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in A.java (at line 3)\n" + + " Class c = A.class; \n" + + " ^\n" + + "Syntax error on token \"A\", . expected after this token\n" + + "----------\n" + + "2. ERROR in A.java (at line 3)\n" + + " Class c = A.class; \n" + + " ^^^\n" + + "Syntax error on token(s), misplaced construct(s)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=242159 +// SHOULD FAIL AT 1.8 (RET): Type mismatch: cannot convert from X>> to X +public void test1404() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " A get() { return null; }\n" + + " > X bar() {\n" + + " return null;\n" + + " }\n" + + " void foo() {\n" + + " bar(); // 0 rejected\n" + + " X raw = bar(); // 1 accepted\n" + + " X wild = bar(); // 2 rejected\n" + + " }\n" + + "}\n", + }); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=240807 +public void test1405() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " X(List rawList, List unboundList) {\n" + + " Throwable t0 = (Throwable) Collections.emptyList();\n" + + " Throwable t1 = (Throwable) rawList;\n" + + " Throwable t2 = (Throwable) unboundList;\n" + + " Map m0 = (Map) Collections.emptyList();\n" + + " Map m1 = (Map) rawList;\n" + + " Map m2 = (Map) unboundList;\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " X(List rawList, List unboundList) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " Map m0 = (Map) Collections.emptyList();\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " Map m0 = (Map) Collections.emptyList();\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " Map m1 = (Map) rawList;\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " Map m1 = (Map) rawList;\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 9)\n" + + " Map m2 = (Map) unboundList;\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 9)\n" + + " Map m2 = (Map) unboundList;\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "8. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1406() { + this.runNegativeTest( + new String[] { + "GenericTest.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "\n" + + "public class GenericTest {\n" + + " public static void test() {\n" + + " Set testList = GenericTest.method1(new Class[] { ArrayList.class });\n" + + " }\n" + + " \n" + + " public static I method1(Class[] params) {\n" + + " return null;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in GenericTest.java (at line 5)\n" + + " Set testList = GenericTest.method1(new Class[] { ArrayList.class });\n" + + " ^^^\n" + + "Set is a raw type. References to generic type Set should be parameterized\n" + + "----------\n" + + "2. WARNING in GenericTest.java (at line 5)\n" + + " Set testList = GenericTest.method1(new Class[] { ArrayList.class });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation method1(Class[]) of the generic method method1(Class[]) of type GenericTest\n" + + "----------\n" + + "3. WARNING in GenericTest.java (at line 5)\n" + + " Set testList = GenericTest.method1(new Class[] { ArrayList.class });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Class[] needs unchecked conversion to conform to Class[]\n" + + "----------\n" + + "4. WARNING in GenericTest.java (at line 8)\n" + + " public static I method1(Class[] params) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" : + "----------\n" + + "1. WARNING in GenericTest.java (at line 5)\n" + + " Set testList = GenericTest.method1(new Class[] { ArrayList.class });\n" + + " ^^^\n" + + "Set is a raw type. References to generic type Set should be parameterized\n" + + "----------\n" + + "2. ERROR in GenericTest.java (at line 5)\n" + + " Set testList = GenericTest.method1(new Class[] { ArrayList.class });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Set\n" + + "----------\n" + + "3. WARNING in GenericTest.java (at line 8)\n" + + " public static I method1(Class[] params) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); +} +public void test1407() { + this.runNegativeTest( + new String[] { + "Foo.java", //----------------------------------------------------------------------- + "public class Foo {\n" + + " public static I m1(Class c) { return null; }\n" + + " void bar() {\n" + + " Foo l1 = m1((Class)Foo.class);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in Foo.java (at line 4)\n" + + " Foo l1 = m1((Class)Foo.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation m1(Class) of the generic method m1(Class) of type Foo\n" + + "----------\n" + + "2. WARNING in Foo.java (at line 4)\n" + + " Foo l1 = m1((Class)Foo.class);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n" + + "3. WARNING in Foo.java (at line 4)\n" + + " Foo l1 = m1((Class)Foo.class);\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" : + "----------\n" + + "1. WARNING in Foo.java (at line 4)\n" + + " Foo l1 = m1((Class)Foo.class);\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in Foo.java (at line 4)\n" + + " Foo l1 = m1((Class)Foo.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Foo\n" + + "----------\n"); +} +public void test1408() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "public class X {\n" + + " void foo(Collection i) {\n" + + " Zork z = (List) i;\n" + + " }\n" + + " void bar(List i) {\n" + + " Zork z = (ArrayList) i;\n" + + " } \n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z = (List) i;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork z = (ArrayList) i;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1409() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "public class X {\n" + + " void foo(List lx, List lw) {\n" + + " LinkedList lo = (LinkedList) lx;\n" + + " LinkedList ls = (LinkedList) lw;\n" + + " }\n" + + " void bar(List lx, List li) {\n" + + " LinkedList lo = (LinkedList) lx;\n" + + " LinkedList ln = (LinkedList) li; \n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " LinkedList lo = (LinkedList) lx;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from List to LinkedList\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " LinkedList ls = (LinkedList) lw;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to LinkedList\n" + + "----------\n"); +} +public void test1410() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "interface I {}\n" + + "class Y implements I {}\n" + + "public class X {\n" + + " I[] x = null;\n" + + " Y[] y1 = (Y[]) x;\n" + + " Y y2 = (Y) x[0];\n" + + " Y[] y3 = (Y[]) x;\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Y[] y3 = (Y[]) x;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from I[] to Y[]\n" + + "----------\n"); +} +public void test1411() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " static class Child extends X { }\n" + + " static X create() {\n" + + " Child child = new Child();\n" + + " child.set(new Object());\n" + + " return (X) child;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X c = create();\n" + + " Number n = c.get();\n" + + " }\n" + + " T t;\n" + + " void set(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " T get() {\n" + + " return t;\n" + + " }\n" + + " static X willWarn = new X();\n" + + " static X raisesTheWarning() {\n" + + " return (X) willWarn;\n" + + " }\n" + + " Zork z;\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " return (X) child;\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X.Child to X\n" + + "----------\n" + + "2. WARNING in X.java (at line 21)\n" + + " return (X) willWarn;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from X to X\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1412() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.List;\n" + + "class A {\n" + + " List foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class B {\n" + + " A a1 = new A();\n" + + " A a2 = new A();\n" + + "}\n" + + "class X {\n" + + " void bar() {\n" + + " B bx = new B();\n" + + " List s1 = bx.a1.foo();\n" + + " List s2 = bx.a2.foo();\n" + + " Zork z;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " A a1 = new A();\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " List s1 = bx.a1.foo();\n" + + " ^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\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 test1413() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "public class X {\n" + + " HashMap m = new HashMap();\n" + + " ArrayList ax = m.get(\"\");\n" + + " Zork z;\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " HashMap m = new HashMap();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " HashMap m = new HashMap();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " ArrayList ax = m.get(\"\");\n" + + " ^^^^^^^^^\n" + + "Type safety: The expression of type ArrayList needs unchecked conversion to conform to ArrayList\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1414() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "interface A {}\n" + + "class B {}\n" + + "public class X {\n" + + " A a = null;\n" + + " B y = (B)a;\n" + + " Zork z;\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " B y = (B)a;\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " B y = (B)a;\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1415() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " T foo(boolean b, U u, V v) {\n" + + " return b ? (T) u: v;\n" + + " }\n" + + " Zork z;\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test1416() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "interface A {}\n" + + "interface B extends A {}\n" + + "interface C extends B {}\n" + + "interface D> extends C {}\n" + + "interface E, SOURCE extends RELATED> extends C {}\n" + + "public class X {\n" + + " C,C> ok;\n" + + " C,B> wrong;\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " interface D> extends C {}\n" + + " ^^^^^^\n" + + "Bound mismatch: The type SOURCE is not a valid substitute for the bounded parameter of the type C\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " C,B> wrong;\n" + + " ^\n" + + "Bound mismatch: The type B is not a valid substitute for the bounded parameter of the type C\n" + + "----------\n"); +} +public void test1417() { + this.runConformTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class XSuper {\n" + + " protected void bar() {}\n" + + "}\n" + + "interface I {\n" + + " void baz();\n" + + "}\n" + + "public class X extends XSuper implements I{\n" + + " public void baz() {}\n" + + " public static void main(String argv[]) {\n" + + " testMethod(new X());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " static void testMethod(U u) {\n" + + " u.baz();\n" + + " u.bar();\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257434 +public void test1418() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class Box, V extends U> {\n" + + " V value;\n" + + " Box next;\n" + + " Box(V value) {\n" + + " this.value = value;\n" + + " }\n" + + " Box() {}\n" + + "}\n" + + "class A extends Box {}\n" + + "class B extends Box {}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Box, Box> a = new Box, Box>(new Box(new A()));\n" + + " Box b = a;\n" + + " b.value.next = new Box(new B());\n" + + " A c = a.value.next.value;\n" + + " String s = b.value;\n" + + " b.value.next.next = new Box(new B());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " b.value.next = new Box(new B());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Box to Box\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " String s = b.value;\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from capture#6-of ? to String\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " b.value.next.next = new Box(new B());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Box to Box\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257434 - variation +public void test1419() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class Box, V extends U> {\n" + + " private V value;\n" + + " Box next;\n" + + " Box(V value) {\n" + + " this.value = value;\n" + + " }\n" + + " Box() {}\n" + + " V getValue() { return this.value; }\n" + + "}\n" + + "class A extends Box {}\n" + + "class B extends Box {}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Box, Box> a = new Box, Box>(new Box(new A()));\n" + + " Box b = a;\n" + + " b.getValue().next = new Box(new B());\n" + + " A c = a.getValue().next.getValue();\n" + + " String s = b.getValue();\n" + + " b.getValue().next.next = new Box(new B());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " b.getValue().next = new Box(new B());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Box to Box\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " String s = b.getValue();\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from capture#6-of ? to String\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " b.getValue().next.next = new Box(new B());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Box to Box\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257434 - variation +public void test1420() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class Box, V extends U> {\n" + + " V value;\n" + + " Box next(V v) { return new Box(v); }\n" + + " Box(V value) {\n" + + " this.value = value;\n" + + " }\n" + + " Box() {/**/}\n" + + "}\n" + + "class A extends Box {/**/}\n" + + "class B extends Box {/**/}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Box, Box> a = new Box, Box>(new Box(new A()));\n" + + " Box b = a;\n" + + " b.value.next(new Box(new B()));\n" + + " b.value.next(b.value);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " b.value.next(new Box(new B()));\n" + + " ^^^^\n" + + "The method next(capture#4-of ?) in the type Box is not applicable for the arguments (Box)\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " b.value.next(b.value);\n" + + " ^^^^\n" + + "The method next(capture#10-of ?) in the type Box is not applicable for the arguments (capture#8-of ?)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 +// FIXME javac8 doesn't find the error +public void test1421() { + this.runNegativeTest( + false /* skipJavac */, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + null : JavacTestOptions.Excuse.JavacCompilesIncorrectSource, + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public interface ID { };\n" + + " public abstract class DomainObject {};\n" + + " public interface DAO> { };\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type parameter DomainObject is hiding the type X.DomainObject\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 - variation +public void test1422() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public interface ID { };\n" + + " public abstract class DomainObject {};\n" + + " public interface DAO> { };\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type parameter DomainObject is hiding the type X.DomainObject\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 +public void test1423() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public interface ID { };\n" + + " public abstract class DomainObject {};\n" + + " public interface DAO> { };\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type parameter DomainObject is hiding the type X.DomainObject\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO> {};\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257849 - variation +public void test1424() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public interface ID { };\n" + + " public abstract class DomainObject {};\n" + + " public interface DAO> { };\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type parameter DomainObject is hiding the type X.DomainObject\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + " ^^^^^^^^^^^^\n" + + "The type DomainObject is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public abstract class HibernateDAOBase implements DAO.Zork> {};\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=206123 +public void test1425() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void test() {\n" + + " B b = new C();\n" + + " Class cb = C.class;\n" + + " \n" + + " YYY y = new XXX();\n" + + " Class> cy = XXX.class;\n" + + " \n" + + " YYY yb = new XXX();\n" + + " Class> ybc = XXX.class;\n" + + " \n" + + " Class ybb = yb.getClass();\n" + + " Class> ybb2 = yb.getClass();\n" + + " Class> ybb3 = yb.getClass();\n" + + " }\n" + + "}\n" + + "class Obj {}\n" + + "class B extends Obj {}\n" + + "class C extends B {}\n" + + "class ZZZ {}\n" + + "class YYY extends ZZZ {}\n" + + "class XXX extends YYY {}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 12)\n" + + " Class ybb = yb.getClass();\n" + + " ^^^\n" + + "YYY is a raw type. References to generic type YYY should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " Class> ybb2 = yb.getClass();\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " Class> ybb3 = yb.getClass();\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258039 +public void test1426() { + if (this.complianceLevel >= ClassFileConstants.JDK16) + return; + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "public class X {\n" + + " boolean foo() {\n" + + " return null instanceof List;\n" + + " }\n" + + " > boolean foo2() {\n" + + " return null instanceof T;\n" + + " }\n" + + " boolean foo3() {\n" + + " return null instanceof Map;\n" + + " }\n" + + " > boolean foo4() {\n" + + " return null instanceof T;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return null instanceof List;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List. Use the form List instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " return null instanceof T;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against type parameter T. Use its erasure List instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " return null instanceof Map;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type Map. Use the form Map instead since further generic type information will be erased at runtime\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " return null instanceof T;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against type parameter T. Use its erasure Map instead since further generic type information will be erased at runtime\n" + + "----------\n"); +} +public void test1427() { + String xSource = + "import java.util.List;\n" + + "public class X {\n" + + " public List nil() { return null; }\n" + + " public T getHead(List x) { return null; }\n" + + " X() {\n" + + " String s = getHead(nil());\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String s = getHead(nil());\n" + + " ^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to String\n" + + "----------\n"); + } else { + runConformTest( + new String[] { + "X.java", + xSource + }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239203 +public void test1428() { + this.runConformTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class A {}\n" + + "class B {}\n" + + "public class X {\n" + + " public > A foo(Class clazz) {\n" + + " A ret = bar(\"bla\");\n" + + " return ret;\n" + + " }\n" + + " public > A bar(String clazzName) {\n" + + " return null;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 +public void test1429() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class Foo {}\n" + + "public class X {\n" + + " public void test() {\n" + + " Integer i = m(new Foo>(), new Foo());\n" + + " }\n" + + " public T m(Foo x, T t) {\n" + + " return t;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Integer i = m(new Foo>(), new Foo());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation m(Foo>, Foo) of the generic method m(Foo, T) of type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Integer i = m(new Foo>(), new Foo());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Foo to Integer\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " Integer i = m(new Foo>(), new Foo());\n" + + " ^^^^^^^^^\n" + + "Type safety: The expression of type Foo needs unchecked conversion to conform to Foo\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " Integer i = m(new Foo>(), new Foo());\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Integer i = m(new Foo>(), new Foo());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Foo to Integer\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Integer i = m(new Foo>(), new Foo());\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation +public void test1430() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class Foo {}\n" + + "public class X {\n" + + " public void test() {\n" + + " m(new Foo>(), new Foo());\n" + + " }\n" + + " public void m(Foo x, T t) {}\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " m(new Foo>(), new Foo());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation m(Foo>, Foo) of the generic method m(Foo, T) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " m(new Foo>(), new Foo());\n" + + " ^^^^^^^^^\n" + + "Type safety: The expression of type Foo needs unchecked conversion to conform to Foo\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " m(new Foo>(), new Foo());\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258039 +public void test1431() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //================================= + "public class X {\n" + + " void foo() {\n" + + " class M {}\n" + + " class N extends M {}\n" + + " class O implements I, I {}\n" + + " }\n" + + " class MM {}\n" + + " class NN extends MM {}\n" + + " class OO implements I, I {}\n" + + "}\n" + + "interface I {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " class N extends M {}\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter of the type M\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " class O implements I, I {}\n" + + " ^\n" + + "The interface I cannot be implemented more than once with different arguments: I and I\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " class NN extends MM {}\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter of the type X.MM\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " class OO implements I, I {}\n" + + " ^^\n" + + "The interface I cannot be implemented more than once with different arguments: I and I\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation +public void test1432() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "class Foo {\n" + + " T bar(Foo ft, T t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public void test() {\n" + + " Foo> ffi = new Foo>();\n" + + " Integer j = ffi.bar(ffi, new Foo());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Integer j = ffi.bar(ffi, new Foo());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Type mismatch: cannot convert from Foo to Integer\n" + : "Type mismatch: cannot convert from Foo to Integer\n") + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " Integer j = ffi.bar(ffi, new Foo());\n" + + " ^^^^^^^^^\n" + + "Type safety: The expression of type Foo needs unchecked conversion to conform to Foo\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " Integer j = ffi.bar(ffi, new Foo());\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation +public void test1433() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "public class X {\n" + + " Zork z;\n" + + " void foo(X xu) {}\n" + + " void bar(X x) {\n" + + " foo(x);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " void bar(X x) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " foo(x);\n" + + " ^^^^^^\n" + + "Type safety: Unchecked invocation foo(X) of the generic method foo(X) of type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " foo(x);\n" + + " ^\n" + + "Type safety: The expression of type X needs unchecked conversion to conform to X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation +public void test1434() { + this.runNegativeTest( + new String[] { + "Foo.java", //----------------------------------------------------------------------- + "public class Foo {\n" + + " public static I m2(Class c) { return null; } \n" + + " void bar() {\n" + + " Foo l2 = m2((Class)Foo.class);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in Foo.java (at line 4)\n" + + " Foo l2 = m2((Class)Foo.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation m2(Class) of the generic method m2(Class) of type Foo\n" + + "----------\n" + + "2. WARNING in Foo.java (at line 4)\n" + + " Foo l2 = m2((Class)Foo.class);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n" + + "3. WARNING in Foo.java (at line 4)\n" + + " Foo l2 = m2((Class)Foo.class);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Class to Class\n" + + "----------\n" + + "4. WARNING in Foo.java (at line 4)\n" + + " Foo l2 = m2((Class)Foo.class);\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + : // 1.8 is stricter: + "----------\n" + + "1. ERROR in Foo.java (at line 4)\n" + + " Foo l2 = m2((Class)Foo.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Foo\n" + + "----------\n" + + "2. WARNING in Foo.java (at line 4)\n" + + " Foo l2 = m2((Class)Foo.class);\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n")); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation +public void test1435() { + String xSource = + "public class X {\n" + + " > T min(T x, T y) { return x; }\n" + + " \n" + + " void foo(Foo f, Bar b) {\n" + + " min(f, f);\n" + + " min(b, b);\n" + + " }\n" + + "}\n" + + "abstract class Foo implements Comparable {\n" + + "}\n" + + "abstract class Bar extends Foo {}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + xSource, + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " min(b, b);\n" + + " ^^^\n" + + "Bound mismatch: The generic method min(T, T) of type X is not applicable for the arguments (Bar, Bar). The inferred type Bar is not a valid substitute for the bounded parameter >\n" + + "----------\n"); + } else { + runConformTest(new String[]{ "X.java", xSource }); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation +public void test1436() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "public class X {\n" + + " , T extends Throwable> void foo(List lu, T t) throws T {\n" + + " if (lu.isEmpty()) throw t;\n" + + " }\n" + + " void bar(List l, IllegalArgumentException iae) {\n" + + " try {\n" + + " foo(l, iae);\n" + + " } catch (IllegalArgumentException e) {\n" + + " }\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " void bar(List l, IllegalArgumentException iae) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " foo(l, iae);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List, IllegalArgumentException) of the generic method foo(List, T) of type X\n" + + "----------\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? + "3. WARNING in X.java (at line 8)\n" + + " foo(l, iae);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List>\n" + : + "3. ERROR in X.java (at line 8)\n" + + " foo(l, iae);\n" + + " ^^^^^^^^^^^\n" + + "Unhandled exception type Throwable\n" + // new error since 1.8 (bug 473657) + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " foo(l, iae);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List>\n" + ) + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation +public void test1437() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "public class X {\n" + + " , T extends Throwable> X(List lu, T t) throws T {\n" + + " if (lu.isEmpty()) throw t;\n" + + " }\n" + + " void bar(List l, IllegalArgumentException iae) {\n" + + " try {\n" + + " new X(l, iae);\n" + + " } catch (IllegalArgumentException e) {\n" + + " }\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " void bar(List l, IllegalArgumentException iae) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " new X(l, iae);\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List, IllegalArgumentException) of the generic constructor X(List, T) of type X\n" + + "----------\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? + "3. WARNING in X.java (at line 8)\n" + + " new X(l, iae);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List>\n" + : + "3. ERROR in X.java (at line 8)\n" + + " new X(l, iae);\n" + + " ^^^^^^^^^^^^^\n" + + "Unhandled exception type Throwable\n" + // new error since 1.8 (bug 473657) + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " new X(l, iae);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List>\n" + ) + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation +public void test1438() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "public class X {\n" + + " , T extends Throwable> X(List lu, T t) throws T {\n" + + " if (lu.isEmpty()) throw t;\n" + + " }\n" + + " void bar(List l, IllegalArgumentException iae) {\n" + + " try {\n" + + " new X(l, iae){};\n" + + " } catch (IllegalArgumentException e) {\n" + + " }\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " void bar(List l, IllegalArgumentException iae) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " new X(l, iae){};\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List, IllegalArgumentException) of the generic constructor X(List, T) of type X\n" + + "----------\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? + "3. WARNING in X.java (at line 8)\n" + + " new X(l, iae){};\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List>\n" + : + "3. ERROR in X.java (at line 8)\n" + + " new X(l, iae){};\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Throwable\n" + // new error since 1.8 (bug 473657) + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " new X(l, iae){};\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List>\n" + ) + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798 - variation +public void test1439() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "public class X {\n" + + " , T extends Throwable> X(List lu, T t) throws T {\n" + + " if (lu.isEmpty()) throw t;\n" + + " }\n" + + " X() { \n" + + " this((List) null, null);\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " , T extends Throwable> Y(List lu, T t) {\n" + + " super((List)lu, t);\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " this((List) null, null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List, null) of the generic constructor X(List, T) of type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " this((List) null, null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Throwable\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " this((List) null, null);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List>\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " this((List) null, null);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " super((List)lu, t);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List, T) of the generic constructor X(List, T) of type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " super((List)lu, t);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Throwable\n" + + "----------\n" + + "7. WARNING in X.java (at line 12)\n" + + " super((List)lu, t);\n" + + " ^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List>\n" + + "----------\n" + + "8. WARNING in X.java (at line 12)\n" + + " super((List)lu, t);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=260567 +public void test1440() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.*;\n" + + "interface GenricInterface {}\n" + + "class NewMapType> extends HashMap, V> {}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class NewMapType> extends HashMap, V> {}\n" + + " ^\n" + + "The type R is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); +} +public void test1441() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void bar(T t) {}\n" + + " void foo(X x1, X x2) {\n" + + " (x1 != null ? x1 : x2).bar(new Object());\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (x1 != null ? x1 : x2).bar(new Object());\n" + + " ^^^\n" + + "The method bar(capture#4-of ? extends "+intersection("Object","Serializable","Comparable")+">")+") in the type X")+">")+"> is not applicable for the arguments (Object)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=221253 +public void test1442() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X> {\n" + + " T[] array;\n" + + "\n" + + " @Override public boolean equals(Object o) {\n" + + " X> x;\n" + + " if (array.length == ((X>) o).array.length) {\n" + + " return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X> x;\n" + + " ^^^^^^^^^^\n" + + "Bound mismatch: The type Comparable is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " if (array.length == ((X>) o).array.length) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to X>\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " if (array.length == ((X>) o).array.length) {\n" + + " ^^^^^^^^^^\n" + + "Bound mismatch: The type Comparable is not a valid substitute for the bounded parameter > of the type X\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=254627 +public void test1443() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.List;\n" + + "public class X {\n" + + " private static class C {}\n" + + " private static class B {}\n" + + " private static class A> {}\n" + + " void bar (List a) {\n" + + " baz((List)a);\n" + + " // Neither of these two following statements compile under javac\n" + + " buz(a);\n" + + " buz((List)a);\n" + + " // Side note: the following statement is correctly identified as an error\n" + + " // by Eclipse, but it does not suggest casting as a Quick Fix.\n" + + " baz(a);\n" + + " }\n" + + " > void baz(List> a) {}\n" + + " > void buz(List a) {}\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " void bar (List a) {\n" + + " ^\n" + + "X.A is a raw type. References to generic type X.A should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " baz((List)a);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation baz(List) of the generic method baz(List>) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " baz((List)a);\n" + + " ^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List>>\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " baz((List)a);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " buz((List)a);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " baz(a);\n" + + " ^^^\n" + + "The method baz(List>) in the type X is not applicable for the arguments (List)\n" + + "----------\n" + + "7. WARNING in X.java (at line 16)\n" + + " > void buz(List a) {}\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=263215 +public void test1444() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.ArrayList;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " @SuppressWarnings(\"all\") public static T[] asArray(Iterator it, Class clazz) {\n" + + " List lst = new ArrayList();\n" + + " while (it.hasNext()) {\n" + + " lst.add(it.next());\n" + + " }\n" + + " return lst.toArray((T[]) java.lang.reflect.Array.newInstance(clazz, lst.size()));\n" + + " }\n" + + " public void test() {\n" + + " String[] asString = null;\n" + + " // eclipse 3.5M4 this worked in build I20090129-1200 it doesnt anymore\n" + + " asString = X. asArray(getIterator(), String.class);\n" + + " // now i have to do this:\n" + + " Iterator iterator = getIterator();\n" + + " asString = X. asArray(iterator, String.class);\n" + + " // this also works except if i have remove unnecessary cast enabled then\n" + + " // the cast is removed and i get a compile error\n" + + " asString = X. asArray((Iterator) getIterator(), String.class);\n" + + " }\n" + + " @SuppressWarnings(\"all\") public Iterator getIterator() {\n" + + " return new Iterator() {\n" + + " public void remove() {\n" + + " }\n" + + " public Object next() {\n" + + " return null;\n" + + " }\n" + + " public boolean hasNext() {\n" + + " return false;\n" + + " }\n" + + " };\n" + + " }\n" + + " Zork z;\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. WARNING in X.java (at line 16)\n" + + " asString = X. asArray(getIterator(), String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation asArray(Iterator, Class) of the generic method asArray(Iterator, Class) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " asString = X. asArray(getIterator(), String.class);\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator\n" + + "----------\n" + + "3. WARNING in X.java (at line 18)\n" + + " Iterator iterator = getIterator();\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Iterator needs unchecked conversion to conform to Iterator\n" + + "----------\n" + + "4. WARNING in X.java (at line 22)\n" + + " asString = X. asArray((Iterator) getIterator(), String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Iterator to Iterator\n" + + "----------\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "5. WARNING in X.java (at line 22)\n" + + " asString = X. asArray((Iterator) getIterator(), String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Iterator to Iterator\n" + + "----------\n" + + "6. ERROR in X.java (at line 36)\n" + : // secondary error no longer reported at 1.8+ + "5. ERROR in X.java (at line 36)\n" + ) + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=263215 - variation +public void test1445() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.io.IOException;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " X(List lt) throws T { }\n" + + " List foo(List t) throws T { return t; }\n" + + "\n" + + " static void bar(List l) {\n" + + " new X(l).foo(l);\n" + + " }\n" + + " static void baz(List l) throws IOException {\n" + + " new X(l). foo(l);\n" + + " }\n" + + " \n" + + " X(List l, long l2) throws IOException {\n" + + " this(l);\n" + + " }\n" + + "\n" + + " static void baz2(List l) throws IOException {\n" + + " new X(l){}. foo(l);\n" + + " }\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " static void bar(List l) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " new X(l).foo(l);\n" + + " ^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List) of the generic constructor X(List) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " new X(l).foo(l);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List) of the generic method foo(List) of type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " new X(l).foo(l);\n" + + " ^^^^^^^^\n" + + "Unhandled exception type Throwable\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " new X(l).foo(l);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Throwable\n" + + "----------\n" + + "6. WARNING in X.java (at line 9)\n" + + " new X(l).foo(l);\n" + + " ^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + : "Type safety: The expression of type List needs unchecked conversion to conform to List\n" ) + + "----------\n" + + "7. WARNING in X.java (at line 9)\n" + + " new X(l).foo(l);\n" + + " ^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + : "Type safety: The expression of type List needs unchecked conversion to conform to List\n" ) + + "----------\n" + + "8. WARNING in X.java (at line 11)\n" + + " static void baz(List l) throws IOException {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 12)\n" + + " new X(l). foo(l);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List) of the generic constructor X(List) of type X\n" + + "----------\n" + + "10. WARNING in X.java (at line 12)\n" + + " new X(l). foo(l);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List) of the generic method foo(List) of type X\n" + + "----------\n" + + "11. WARNING in X.java (at line 12)\n" + + " new X(l). foo(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "12. WARNING in X.java (at line 12)\n" + + " new X(l). foo(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "13. WARNING in X.java (at line 15)\n" + + " X(List l, long l2) throws IOException {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "14. WARNING in X.java (at line 16)\n" + + " this(l);\n" + + " ^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List) of the generic constructor X(List) of type X\n" + + "----------\n" + + "15. WARNING in X.java (at line 16)\n" + + " this(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "16. WARNING in X.java (at line 19)\n" + + " static void baz2(List l) throws IOException {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "17. WARNING in X.java (at line 20)\n" + + " new X(l){}. foo(l);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation X(List) of the generic constructor X(List) of type X\n" + + "----------\n" + + "18. WARNING in X.java (at line 20)\n" + + " new X(l){}. foo(l);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation foo(List) of the generic method foo(List) of type X\n" + + "----------\n" + + "19. WARNING in X.java (at line 20)\n" + + " new X(l){}. foo(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "20. WARNING in X.java (at line 20)\n" + + " new X(l){}. foo(l);\n" + + " ^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202393 +public void test1446() { + this.runConformTest( + new String[] { + "Bug202393.java", + "public class Bug202393 {\n" + + " static T id(T in) { return in; }\n" + + " public static void main(String[] args) {\n" + + " try {" + + " bad();" + + " } catch (Throwable t) {\n" + + " System.out.print(\"CAUGHT\");\n" + + " }\n" + + " }\n" + + " static void bad() throws Throwable {\n" + + " throw id(new Exception());\n" + + " }\n" + + "}\n"}, + "CAUGHT" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=263633 +public void test1447() { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X implements Visitable {\n" + + " public > T accept(U v) {\n" + + " return null;\n" + + " }\n" + + " public > T accept2(U v) {\n" + + " if (v == null)\n" + + " return this.accept(v);\n" + + " else \n" + + " return this. accept(v);\n" + + " }\n" + + "}\n" + + "interface Visitable {\n" + + " > T accept(U v);\n" + + "}\n" + + "interface Visitor {\n" + + "}\n", + }, + "" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=263633 - variation +public void test1448() { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X implements Visitable {\n" + + " public T accept(U v) {\n" + + " return null;\n" + + " }\n" + + " public T accept2(U v) {\n" + + " if (v == null)\n" + + " return this.accept(v);\n" + + " else \n" + + " return this. accept(v);\n" + + " }\n" + + "}\n" + + "interface Visitable {\n" + + " T accept(U v);\n" + + "}\n" + + "interface Visitor{\n" + + "}\n", + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=263633 - variation +public void test1449() { + this.runConformTest( + new String[] { + "X.java", + "interface Visitor {\n" + + "}\n" + + "public class X {\n" + + " public > T accept(U v) {\n" + + " throw new UnsupportedOperationException();\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " public > T accept(U v) {\n" + + " if (v == null)\n" + + " return super.accept(v);\n" + + " else\n" + + " return super. accept(v);\n" + + " }\n" + + "}\n", + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159851 +public void test1450() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class A {}\n" + + "class B {}\n" + + "class X>> extends TreeMap> {}\n" + + "\n" + + "class D {}\n" + + "class E {}\n" + + "class Y extends E> {}", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class X>> extends TreeMap> {}\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 4)\n" + + " class X>> extends TreeMap> {}\n" + + " ^^^^^^^\n" + + "Bound mismatch: The type Integer is not a valid substitute for the bounded parameter of the type B\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " class X>> extends TreeMap> {}\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter of the type B\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " class Y extends E> {}\n" + + " ^\n" + + "Bound mismatch: The type D is not a valid substitute for the bounded parameter of the type E\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159851 +public void test1451() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {}\n" + + "class B {}\n" + + "class C {}\n" + + "class X extends C>>, A>> {}\n" + + "class Y extends A>> {}\n" + + "class Z extends C, A>> {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " class X extends C>>, A>> {}\n" + + " ^^\n" + + "Bound mismatch: The type T1 is not a valid substitute for the bounded parameter of the type B\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " class X extends C>>, A>> {}\n" + + " ^^\n" + + "Bound mismatch: The type T2 is not a valid substitute for the bounded parameter of the type B\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " class Y extends A>> {}\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter of the type B\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " class Z extends C, A>> {}\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter of the type B\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " class Z extends C, A>> {}\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter of the type B\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=273751 +public void test1452() { + this.runNegativeTest( + new String[] { + "A.java", + "class A {}\n" + + "class B extends A {\n" + + " private class Secret {};\n" + + " B.Secret s;\n" + + " A a;\n" + + "}\n" + + "class C extends B.Secret {}\n" + + "class D {\n" + + " class M { private class Secret {}; }\n" + + " class N extends A {}\n" + + "}\n" + + "class E {\n" + + " class M extends A {\n" + + " private class Secret {};\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " class B extends A {\n" + + " ^^^^^^^^\n" + + "The type B.Secret is not visible\n" + + "----------\n" + + "2. ERROR in A.java (at line 7)\n" + + " class C extends B.Secret {}\n" + + " ^^^^^^^^\n" + + "The type B.Secret is not visible\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=278305 +public void test1453() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " I i = new I() {};\n" + + "}\n" + + "class Y implements I {}\n" + + "interface I {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " I i = new I() {};\n" + + " ^\n" + + "The type new I(){} cannot extend or implement I. A supertype may not specify any wildcard\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " class Y implements I {}\n" + + " ^\n" + + "The type Y cannot extend or implement I. A supertype may not specify any wildcard\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=289538 +public void test1454() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Node first;\n" + + " public void add(T e) {\n" + + " first = new Node(e);\n" + + " System.out.print(true);\n" + + " }\n" + + " private class Node {\n" + + " private Node next;\n" + + " private Node(T d) {}\n" + + " private Node(T d, Node n) { next = n; }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.add(\"\");\n" + + " }\n" + + "}" + }, + "true" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=287607 +public void test1455() { + this.runNegativeTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " Inner inner;\n" + + " class Inner {\n" + + " E e;\n" + + " E getOtherElement(Object other) {\n" + + " if (!(other instanceof Outer.Inner))\n" + + " throw new IllegalArgumentException(String.valueOf(other));\n" + + " Inner that = (Inner) other;\n" + + " return that.e;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer s = new Outer();\n" + + " s.inner = s.new Inner();\n" + + " s.inner.e = \"hello\";\n" + + " Outer i = new Outer();\n" + + " i.inner = i.new Inner();\n" + + " i.inner.e = 1234;\n" + + " s.inner.getOtherElement(i.inner);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in Outer.java (at line 8)\n" + + " Inner that = (Inner) other;\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Outer.Inner\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=292428 +public void test1456() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " interface E {}\n" + + " class S implements E {\n" + + " V value;\n" + + " }\n" + + " class M implements E {\n" + + " ArrayList list = new ArrayList();\n" + + " M(E se) {\n" + + " list.add(((S)se).value);\n" + + " }\n" + + " }\n" + + "}" + }, + "" + ); +} +// Test to verify that partial types in a parameterized qualified reference are +// demarcated correctly while annotating an arity problem in case of wrong number of arguments. +// Related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=292510 +public void test1457() { + this.runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "// Valid Parameterized Type Declaration\n" + + "public class X {\n" + + " public class Y {\n" + + " public class Z {\n" + + " }\n" + + " }\n" + + "}\n" + + "// Invalid Valid Type Syntax (too many parameters)\n" + + "class Y {\n" + + " X.Y.Z x;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 11)\n" + + " X.Y.Z x;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Incorrect number of arguments for type X.Y; it cannot be parameterized with arguments \n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002 (visibility error for package private method) +public void test1458() { + this.runNegativeTest( + new String[] { + "CompilerBug.java", + "@SuppressWarnings(\"deprecation\")\n" + + "public class CompilerBug {\n" + + " public T newInstance( Class c ) throws InstantiationException, IllegalAccessException {\n" + + " return c.newInstance();\n" + + " }\n" + + " protected void protectedMethod() {}\n" + + " void packagePrivateMethod() {}\n" + + " private void privateMethod() {}\n" + + " private int privateInt = 0;\n" + + " int packagePrivateInt = 0;\n" + + " protected int protectedInt = 0;\n" + + " private void isThisBuggy() throws InstantiationException, IllegalAccessException {\n" + + " CompilerBug c = getClass().newInstance();\n" + + " c.privateMethod();\n" + + " c.packagePrivateMethod();\n" + + " c.protectedMethod();\n" + + " getClass().newInstance().packagePrivateMethod();\n" + + " getClass().newInstance().privateMethod();\n" + + " getClass().newInstance().protectedMethod();\n" + + " getClass().newInstance().privateInt = 10;\n" + + " getClass().newInstance().packagePrivateInt = 10;\n" + + " getClass().newInstance().protectedInt = 10;\n" + + " Zork z;\n" + + " }\n" + + " }\n", + }, + this.complianceLevel <= ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. ERROR in CompilerBug.java (at line 23)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" : + + // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 + "----------\n" + + "1. ERROR in CompilerBug.java (at line 18)\n" + + " getClass().newInstance().privateMethod();\n" + + " ^^^^^^^^^^^^^\n" + + "The method privateMethod() from the type CompilerBug is not visible\n" + + "----------\n" + + "2. ERROR in CompilerBug.java (at line 20)\n" + + " getClass().newInstance().privateInt = 10;\n" + + " ^^^^^^^^^^\n" + + "The field CompilerBug.privateInt is not visible\n" + + "----------\n" + + "3. ERROR in CompilerBug.java (at line 23)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=295698 +public void test1459() { + this.runConformTest( + new String[] { + "B.java", + "import java.util.Collection;\n" + + "public class B extends X> {\n" + + " public B(Collection> c, I i) {\n" + + " super(c, i);\n" + + " }\n" + + "}", + "I.java", + "public interface I{}", + "X.java", + "public class X {\n" + + " public X(V v, I i, Object... o) {}\n" + + "}" + }, + ""); // no specific success output string +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=277643 +// SHOULD FAIL AT 1.8 (18.2.3): The method get(Class, T) in the type Test is not applicable for the arguments (Class, Object) +// FIXME: javac rejects (correctly? how?), see http://mail.openjdk.java.net/pipermail/lambda-spec-experts/2013-December/000443.html +public void test277643() { + this.runNegativeTest( + false /* skipJavac */, + this.complianceLevel < ClassFileConstants.JDK1_8 ? null : + JavacTestOptions.EclipseHasABug.EclipseBug428061, + new String[] { + "Test.java", + "public class Test {\n" + + "public final void addShortDescription(Object object, StringBuffer buf) {\n" + + " try {\n" + + " W_Description wdescription = get(W_Description.class, object);\n" + + " } catch (Exception e) {\n" + + " }\n" + + "}\n" + + "public abstract class W_Description extends WrapperLogic {}\n" + + "public > W get(Class wrapperClass, T entity) {\n" + + " return getLogicFactory().get(wrapperClass, entity);\n" + + "}\n" + + "private LogicFactory logicFactory;\n" + + "public final LogicFactory getLogicFactory() {\n" + + " return logicFactory;\n" + + "}\n" + + "public interface LogicFactory {\n" + + " LOGIC get(Class logicClass);\n" + + " > WRAPPER_LOGIC get(Class wrapperLogicClass, WRAPPED entityToWrap);\n" + + "}\n" + + "public abstract class WrapperLogic extends AbstractLogic implements Wrapper {}\n" + + "public abstract class AbstractLogic {}\n" + + "public interface Wrapper {\n" + + " WRAPPED getWrapped();\n" + + "}\n" + + "public abstract class Logic extends AbstractLogic {}\n" + + "}" + }, + "----------\n" + + "1. WARNING in Test.java (at line 4)\n" + + " W_Description wdescription = get(W_Description.class, object);\n" + + " ^^^^^^^^^^^^^\n" + + "Test.W_Description is a raw type. References to generic type Test.W_Description should be parameterized\n" + + "----------\n" + + "2. WARNING in Test.java (at line 4)\n" + + " W_Description wdescription = get(W_Description.class, object);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation get(Class, Object) of the generic method get(Class, T) of type Test\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=280054 +// SHOULD FAIL AT 1.8 (18.2.3): The method get(Class, Class) in the type X.L is not applicable for the arguments (Class, Class) +public void test280054() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "static class A {\n" + + "L l;\n" + + "public Class vtype() {\n" + + " return null;\n" + + "}\n" + + "public A method1() {\n" + + " return l.get(vtype(), B.class);\n" + + "}\n" + + "}\n" + + "static class L {\n" + + "public > S get(Class vtype, Class stype) {\n" + + " return null;\n" + + "}\n" + + "}\n" + + "static class B extends A {\n" + + "public B method2() {\n" + + " return l.get(vtype(), B.class);\n" + + "}\n" + + "}\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " return l.get(vtype(), B.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation get(Class, Class) of the generic method get(Class, Class) of type X.L\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " return l.get(vtype(), B.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.B needs unchecked conversion to conform to X.A\n" + + "----------\n" + + "3. WARNING in X.java (at line 18)\n" + + " return l.get(vtype(), B.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation get(Class, Class) of the generic method get(Class, Class) of type X.L\n" + + "----------\n" + + "4. WARNING in X.java (at line 18)\n" + + " return l.get(vtype(), B.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.B needs unchecked conversion to conform to X.B\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=283306 +// SHOULD FAIL AT 1.8 (18.2.3): The method get(Class, Class) in the type X.L is not applicable for the arguments (Class, Class) +// FIXME: javac rejects (correctly? how?), see http://mail.openjdk.java.net/pipermail/lambda-spec-experts/2013-December/000443.html +public void test283306() { + this.runNegativeTest( + false /* skipJavac */, + this.complianceLevel < ClassFileConstants.JDK1_8 ? null : + JavacTestOptions.EclipseHasABug.EclipseBug428061, + new String[] { + "Test.java", + "public class Test {\n" + + " public WWorkflow getMainWorkflow(){\n" + + " return get(WWorkflow.class, null);\n" + + " }\n" + + " public > W get(Class wrapperClass, T entity) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class Workflow {}\n" + + "class WWorkflow extends WrapperLogic {}\n" + + "abstract class WrapperLogic {}\n" + }, + "----------\n" + + "1. WARNING in Test.java (at line 3)\n" + + " return get(WWorkflow.class, null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation get(Class, null) of the generic method get(Class, T) of type Test\n" + + "----------\n" + + "2. WARNING in Test.java (at line 3)\n" + + " return get(WWorkflow.class, null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type WWorkflow needs unchecked conversion to conform to WWorkflow\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=294724 +// Test extracted from bug submission code by kabir.khan@jboss.com (Kabir Khan) +// SHOULD FAIL AT 1.8 (18.2.3): The method cloneCollection(T, Class, Class) in the type SimpleExample is not applicable for the arguments (Set, Class, Class) +public void test294724() { + this.runNegativeTest( + new String[] { + "SimpleExample.java", + "import java.util.Collection;\n" + + "import java.util.HashSet;\n" + + "import java.util.Set;\n" + + "public class SimpleExample {\n" + + " Set data;\n" + + " public void setData(Set data) {\n" + + " this.data = data;\n" + + " }\n" + + " public void copy(SimpleExample clone) {\n" + + " clone.setData(cloneCollection(data, HashSet.class, Data.class));\n" + + " }\n" + + " public static > T cloneCollection(T collection, Class expectedClass, Class componentType) {\n" + + " return null;\n" + + " }\n" + + " private interface Interface {}\n" + + " private class Data implements Interface {}\n" + + "}" + }, + "----------\n" + + "1. WARNING in SimpleExample.java (at line 10)\n" + + " clone.setData(cloneCollection(data, HashSet.class, Data.class));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation cloneCollection(Set, Class, Class) of the generic method cloneCollection(T, Class, Class) of type SimpleExample\n" + + "----------\n" + + "2. WARNING in SimpleExample.java (at line 10)\n" + + " clone.setData(cloneCollection(data, HashSet.class, Data.class));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Set needs unchecked conversion to conform to Set\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=268798 +// SHOULD FAIL AT 1.8 (18.2.3): The method min(Collection) in the type Collections is not applicable for the arguments (List) +public void test268798() { + this.runNegativeTest( + new String[] { + "GenericDemo.java", + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "public class GenericDemo {\n" + + " static class A implements Comparable {\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + " void someCode(List list) {\n" + + " A min = Collections.min(list); \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in GenericDemo.java (at line 4)\n" + + " static class A implements Comparable {\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. WARNING in GenericDemo.java (at line 10)\n" + + " A min = Collections.min(list); \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation min(List) of the generic method min(Collection) of type Collections\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=268798 +// SHOULD FAIL AT 1.8 (18.2.3): Type mismatch: cannot convert from Bug268798.SomeInterface> to Bug268798.A +public void test268798a() { + this.runNegativeTest( + new String[] { + "Bug268798.java", + "public class Bug268798 {\n" + + " interface SomeInterface {\n" + + " }\n" + + " class A implements SomeInterface {\n" + + " }\n" + + " > T someMethod() {\n" + + " return null;\n" + + " }\n" + + " void someCode() {\n" + + " A a = someMethod();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Bug268798.java (at line 4)\n" + + " class A implements SomeInterface {\n" + + " ^^^^^^^^^^^^^\n" + + "Bug268798.SomeInterface is a raw type. References to generic type Bug268798.SomeInterface should be parameterized\n" + + "----------\n" + + "2. WARNING in Bug268798.java (at line 10)\n" + + " A a = someMethod();\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation someMethod() of the generic method someMethod() of type Bug268798\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=307885 +public void test1460() { + String log = this.complianceLevel < ClassFileConstants.JDK16 ? + "----------\n" + + "1. ERROR in Test.java (at line 9)\n" + + " if(!(o instanceof MyEntry))\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type Test.MyEntry. Use the form Test.MyEntry instead since further generic type information will be erased at runtime\n" + + "----------\n" : + "----------\n" + + "1. ERROR in Test.java (at line 9)\n" + + " if(!(o instanceof MyEntry))\n" + + " ^\n" + + "Type Object cannot be safely cast to Test.MyEntry\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "Test.java", + "class Test {\n" + + " interface MyInt {\n" + + " K getKey();\n" + + " }\n" + + " class MyEntry implements MyInt {\n" + + " public A getKey() { return null; }\n" + + " @Override\n" + + " public boolean equals(Object o) {\n" + + " if(!(o instanceof MyEntry))\n" + + " return false;\n" + + " return true;\n" + + " }\n" + + " }\n" + + "}" + }, log + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=306464 +public void test1461() { + this.runNegativeTest( + new String[] { + "JoinImpl.java", + "import javax.persistence.criteria.Expression;\n" + + "import javax.persistence.criteria.Fetch;\n" + + "import javax.persistence.criteria.From;\n" + + "import javax.persistence.criteria.Join;\n" + + "import javax.persistence.criteria.JoinType;\n" + + "import javax.persistence.criteria.Path;\n" + + "import javax.persistence.metamodel.Attribute;\n" + + "import javax.persistence.metamodel.Bindable;\n" + + "import javax.persistence.metamodel.ManagedType;\n" + + "import javax.persistence.metamodel.Metamodel;\n" + + "public class JoinImpl extends FromImpl implements Join, Fetch {\n" + + "}", + "FromImpl.java", + "import java.util.ArrayList;\n" + + "import java.util.HashSet;\n" + + "import java.util.List;\n" + + "import java.util.Set;\n" + + "import java.util.Stack;\n" + + "\n" + + "import javax.persistence.criteria.CollectionJoin;\n" + + "import javax.persistence.criteria.Expression;\n" + + "import javax.persistence.criteria.Fetch;\n" + + "import javax.persistence.criteria.From;\n" + + "import javax.persistence.criteria.Join;\n" + + "import javax.persistence.criteria.JoinType;\n" + + "import javax.persistence.criteria.ListJoin;\n" + + "import javax.persistence.criteria.MapJoin;\n" + + "import javax.persistence.criteria.Path;\n" + + "import javax.persistence.criteria.SetJoin;\n" + + "import javax.persistence.metamodel.Attribute;\n" + + "import javax.persistence.metamodel.Bindable;\n" + + "import javax.persistence.metamodel.CollectionAttribute;\n" + + "import javax.persistence.metamodel.ListAttribute;\n" + + "import javax.persistence.metamodel.ManagedType;\n" + + "import javax.persistence.metamodel.MapAttribute;\n" + + "import javax.persistence.metamodel.Metamodel;\n" + + "import javax.persistence.metamodel.PluralAttribute;\n" + + "import javax.persistence.metamodel.SingularAttribute;\n" + + "import javax.persistence.metamodel.Attribute.PersistentAttributeType;\n" + + "import javax.persistence.metamodel.PluralAttribute.CollectionType;\n" + + "import javax.persistence.metamodel.Type.PersistenceType;\n" + + "\n" + + "import org.eclipse.persistence.internal.helper.ClassConstants;\n" + + "import org.eclipse.persistence.internal.localization.ExceptionLocalization;\n" + + "\n" + + "public class FromImpl extends PathImpl implements javax.persistence.criteria.From {\n" + + "\n" + + " protected Set> joins;\n" + + " \n" + + " public Set> getJoins() {\n" + + " return joins;\n" + + " }\n" + + "\n" + + " public void findJoins(AbstractQueryImpl query){\n" + + " Stack stack = new Stack();\n" + + " stack.push(this);\n" + + " while(!stack.isEmpty()){\n" + + " FromImpl currentJoin = (FromImpl) stack.pop();\n" + + " stack.addAll(currentJoin.getJoins());\n" + + " if (currentJoin.isLeaf){\n" + + " query.addJoin(currentJoin);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in JoinImpl.java (at line 1)\n" + + " import javax.persistence.criteria.Expression;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "2. ERROR in JoinImpl.java (at line 2)\n" + + " import javax.persistence.criteria.Fetch;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "3. ERROR in JoinImpl.java (at line 3)\n" + + " import javax.persistence.criteria.From;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "4. ERROR in JoinImpl.java (at line 4)\n" + + " import javax.persistence.criteria.Join;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "5. ERROR in JoinImpl.java (at line 5)\n" + + " import javax.persistence.criteria.JoinType;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "6. ERROR in JoinImpl.java (at line 6)\n" + + " import javax.persistence.criteria.Path;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "7. ERROR in JoinImpl.java (at line 7)\n" + + " import javax.persistence.metamodel.Attribute;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "8. ERROR in JoinImpl.java (at line 8)\n" + + " import javax.persistence.metamodel.Bindable;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "9. ERROR in JoinImpl.java (at line 9)\n" + + " import javax.persistence.metamodel.ManagedType;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "10. ERROR in JoinImpl.java (at line 10)\n" + + " import javax.persistence.metamodel.Metamodel;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "11. ERROR in JoinImpl.java (at line 11)\n" + + " public class JoinImpl extends FromImpl implements Join, Fetch {\n" + + " ^^^^\n" + + "Join cannot be resolved to a type\n" + + "----------\n" + + "12. ERROR in JoinImpl.java (at line 11)\n" + + " public class JoinImpl extends FromImpl implements Join, Fetch {\n" + + " ^^^^^\n" + + "Fetch cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. ERROR in FromImpl.java (at line 7)\n" + + " import javax.persistence.criteria.CollectionJoin;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "2. ERROR in FromImpl.java (at line 8)\n" + + " import javax.persistence.criteria.Expression;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "3. ERROR in FromImpl.java (at line 9)\n" + + " import javax.persistence.criteria.Fetch;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "4. ERROR in FromImpl.java (at line 10)\n" + + " import javax.persistence.criteria.From;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "5. ERROR in FromImpl.java (at line 11)\n" + + " import javax.persistence.criteria.Join;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "6. ERROR in FromImpl.java (at line 12)\n" + + " import javax.persistence.criteria.JoinType;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "7. ERROR in FromImpl.java (at line 13)\n" + + " import javax.persistence.criteria.ListJoin;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "8. ERROR in FromImpl.java (at line 14)\n" + + " import javax.persistence.criteria.MapJoin;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "9. ERROR in FromImpl.java (at line 15)\n" + + " import javax.persistence.criteria.Path;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "10. ERROR in FromImpl.java (at line 16)\n" + + " import javax.persistence.criteria.SetJoin;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "11. ERROR in FromImpl.java (at line 17)\n" + + " import javax.persistence.metamodel.Attribute;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "12. ERROR in FromImpl.java (at line 18)\n" + + " import javax.persistence.metamodel.Bindable;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "13. ERROR in FromImpl.java (at line 19)\n" + + " import javax.persistence.metamodel.CollectionAttribute;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "14. ERROR in FromImpl.java (at line 20)\n" + + " import javax.persistence.metamodel.ListAttribute;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "15. ERROR in FromImpl.java (at line 21)\n" + + " import javax.persistence.metamodel.ManagedType;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "16. ERROR in FromImpl.java (at line 22)\n" + + " import javax.persistence.metamodel.MapAttribute;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "17. ERROR in FromImpl.java (at line 23)\n" + + " import javax.persistence.metamodel.Metamodel;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "18. ERROR in FromImpl.java (at line 24)\n" + + " import javax.persistence.metamodel.PluralAttribute;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "19. ERROR in FromImpl.java (at line 25)\n" + + " import javax.persistence.metamodel.SingularAttribute;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "20. ERROR in FromImpl.java (at line 26)\n" + + " import javax.persistence.metamodel.Attribute.PersistentAttributeType;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "21. ERROR in FromImpl.java (at line 27)\n" + + " import javax.persistence.metamodel.PluralAttribute.CollectionType;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "22. ERROR in FromImpl.java (at line 28)\n" + + " import javax.persistence.metamodel.Type.PersistenceType;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import javax.persistence cannot be resolved\n" + + "----------\n" + + "23. ERROR in FromImpl.java (at line 30)\n" + + " import org.eclipse.persistence.internal.helper.ClassConstants;\n" + + " ^^^^^^^^^^^\n" + + "The import org.eclipse cannot be resolved\n" + + "----------\n" + + "24. ERROR in FromImpl.java (at line 31)\n" + + " import org.eclipse.persistence.internal.localization.ExceptionLocalization;\n" + + " ^^^^^^^^^^^\n" + + "The import org.eclipse cannot be resolved\n" + + "----------\n" + + "25. ERROR in FromImpl.java (at line 33)\n" + + " public class FromImpl extends PathImpl implements javax.persistence.criteria.From {\n" + + " ^^^^^^^^\n" + + "PathImpl cannot be resolved to a type\n" + + "----------\n" + + "26. ERROR in FromImpl.java (at line 33)\n" + + " public class FromImpl extends PathImpl implements javax.persistence.criteria.From {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "javax.persistence cannot be resolved to a type\n" + + "----------\n" + + "27. ERROR in FromImpl.java (at line 35)\n" + + " protected Set> joins;\n" + + " ^^^^\n" + + "Join cannot be resolved to a type\n" + + "----------\n" + + "28. ERROR in FromImpl.java (at line 37)\n" + + " public Set> getJoins() {\n" + + " ^^^^\n" + + "Join cannot be resolved to a type\n" + + "----------\n" + + "29. ERROR in FromImpl.java (at line 38)\n" + + " return joins;\n" + + " ^^^^^\n" + + "Join cannot be resolved to a type\n" + + "----------\n" + + "30. ERROR in FromImpl.java (at line 41)\n" + + " public void findJoins(AbstractQueryImpl query){\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "AbstractQueryImpl cannot be resolved to a type\n" + + "----------\n" + + "31. WARNING in FromImpl.java (at line 42)\n" + + " Stack stack = new Stack();\n" + + " ^^^^^\n" + + "Stack is a raw type. References to generic type Stack should be parameterized\n" + + "----------\n" + + "32. WARNING in FromImpl.java (at line 42)\n" + + " Stack stack = new Stack();\n" + + " ^^^^^\n" + + "Stack is a raw type. References to generic type Stack should be parameterized\n" + + "----------\n" + + "33. WARNING in FromImpl.java (at line 43)\n" + + " stack.push(this);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The method push(Object) belongs to the raw type Stack. References to generic type Stack should be parameterized\n" + + "----------\n" + + "34. WARNING in FromImpl.java (at line 45)\n" + + " FromImpl currentJoin = (FromImpl) stack.pop();\n" + + " ^^^^^^^^\n" + + "FromImpl is a raw type. References to generic type FromImpl should be parameterized\n" + + "----------\n" + + "35. WARNING in FromImpl.java (at line 45)\n" + + " FromImpl currentJoin = (FromImpl) stack.pop();\n" + + " ^^^^^^^^\n" + + "FromImpl is a raw type. References to generic type FromImpl should be parameterized\n" + + "----------\n" + + "36. WARNING in FromImpl.java (at line 46)\n" + + " stack.addAll(currentJoin.getJoins());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method addAll(Collection) belongs to the raw type Vector. References to generic type Vector should be parameterized\n" + + "----------\n" + + "37. ERROR in FromImpl.java (at line 47)\n" + + " if (currentJoin.isLeaf){\n" + + " ^^^^^^\n" + + "isLeaf cannot be resolved or is not a field\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316889 +public void test1462() { + this.runNegativeTest( + new String[] { + "AnotherClass.java", + "public class AnotherClass> {}\n" + + "class ImplementingClass implements IRecursiveInterface, IReferencedInterface {\n" + + " private AnotherClass m_var;\n" + + " public void setAnother(final AnotherClass a) {\n" + + " m_var = a;\n" + + " }\n" + + "}\n" + + "interface IRecursiveInterface> {\n" + + " void setAnother(final AnotherClass a);\n" + + "}\n" + + "interface IReferencedInterface extends IRecursiveInterface {}\n" + }, + "----------\n" + + "1. ERROR in AnotherClass.java (at line 5)\n" + + " m_var = a;\n" + + " ^\n" + + "Type mismatch: cannot convert from AnotherClass to AnotherClass\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=314556 +public void test1463() { + this.runNegativeTest( + new String[] { + "BaseType.java", + "public interface BaseType {\n" + + " BaseType clone() throws CloneNotSupportedException;\n" + + "}\n" + + "interface SubType extends BaseType {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in BaseType.java (at line 4)\n" + + " interface SubType extends BaseType {\n" + + " ^\n" + + "The inherited method Object.clone() cannot hide the public abstract method in BaseType\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319603 +public void test1464() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public Collection m(Collection a) {\n" + + " return null;\n" + + " }\n" + + " public Set m(Set a) {\n" + + " return m(a); \n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=320275 +public void _test1465() { + this.runConformTest( + new String[] { + "AbstractSubClass.java", + "public abstract class AbstractSubClass extends AbstractClass {}", + }, + new String[] { + "AbstractClass.java", + "public abstract class AbstractClass implements BaseInterface {}", + "AbstractSubClass.java", + "public abstract class AbstractSubClass extends AbstractClass {}", + "BaseInterface.java", + "public interface BaseInterface extends GenericInterface {}", + "ConcreteClass.java", + "public class ConcreteClass extends AbstractSubClass {}", + "GenericInterface.java", + "public interface GenericInterface {}", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320463 +public void test1466() { + this.runNegativeTest( + new String[] { + "Outer.java", + "public class Outer {\n"+ + " class Cell {\n"+ + " final T value;\n"+ + " Cell(T value) {\n"+ + " this.value = value;\n"+ + " }\n"+ + " }\n"+ + " Class.Cell> cellClass = Cell.class;\n"+ + " {\n"+ + " this.cellClass = Cell.class;\n"+ + " this.cellClass = Outer.Cell.class;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " Outer.Cell intCell = new Outer().new Cell(314);\n"+ + " Outer.Cell strCell = new Outer().cellClass.cast(intCell);\n"+ + " String val = strCell.value; // ClassCastException\n"+ + " System.out.println(val);\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in Outer.java (at line 8)\n" + + " Class.Cell> cellClass = Cell.class;\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class.Cell>\n" + + "----------\n" + + "2. ERROR in Outer.java (at line 10)\n" + + " this.cellClass = Cell.class;\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class.Cell>\n" + + "----------\n" + + "3. ERROR in Outer.java (at line 11)\n" + + " this.cellClass = Outer.Cell.class;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class.Cell>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312076 +public void test1467() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public abstract static class Base> {\n" + + " public Base(Class sClass) {\n" + + " Class theClass = sClass;\n" + + " System.out.println(theClass);\n" + + " System.out.println(sClass);\n" + + " }\n" + + " }\n" + + " public class Arr extends Base {\n" + + " public Arr() { \n" + + " super(Arr.class);\n" + + " System.out.println(Arr.class);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " X.Arr a = x.new Arr();\n" + + " System.out.println(a);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " super(Arr.class);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The constructor X.Base.Arr>(Class) is undefined\n" + + "----------\n"); +} +public void testBug401783() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void foo() {\n" + + " Iterable> iterables = Arrays.asList(Arrays.asList(1,2,3,4),Arrays.asList(5,6,7));\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433989 +public void testBug433989() { + this.runConformTest( + new String[] { + "A.java", + "class A {\n" + + " public static class Container {\n" + + " public static class In {\n" + + " public static class Inner {}\n" + + " }\n" + + " public static void doit() {\n" + + " new In.Inner();\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433989 +public void testBug433989a() { + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " public static class Nested {\n" + + " public class In {\n" + + " public class Inner {}\n" + + " }\n" + + " public void create() {\n" + + " new In.Inner();\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 7)\n" + + " new In.Inner();\n" + + " ^^^^^^^^\n" + + "The member type A.Nested.In.Inner must be qualified with a parameterized type, since it is not static\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=433989 +public void testBug433989b() { + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " public class Nested {\n" + + " public class In {\n" + + " public class Inner {}\n" + + " }\n" + + " public void create() {\n" + + " new In.Inner();\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 7)\n" + + " new In.Inner();\n" + + " ^^\n" + + "The member type A.Nested.In must be parameterized, since it is qualified with a parameterized type\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=469201 +public void testBug469201_A(){ + this.runConformTest( + new String[]{ + "T2.java", + "import java.util.*;\n" + + "\n" + + "class Bar { }\n" + + "\n" + + "class FooPrime extends Bar {\n" + + " void bar(Bar bar) { }\n" + + "}\n" + + "\n" + + "class Foo extends FooPrime { }\n" + + "\n" + + "public class T2 {\n" + + "\n" + + " public static void someMethod(List foos ) {\n" + + " Bar bar = new Bar(); \n" + + " foos.get(0).bar(bar);\n" + + " }\n" + + " public static void main(String... args) {\n" + + " List foos = new ArrayList();\n" + + " foos.add(new Foo());\n" + + " someMethod(foos);\n" + + " }\n" + + "}" + }); +} + +public void testBug469201_B(){ + this.runNegativeTest( + new String[]{ + "A.java", + "package bug469201.p1;\n" + + "public class A {\n" + + " void bar(Bar bar) { }\n" + + "}\n" + + "class Bar {}\n", + "D.java", + "package bug469201.p1;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import bug469201.p2.B;\n" + + "public class D{\n" + + " public static void main(String... args) {\n" + + " List foos = new ArrayList();\n" + + " Bar bar = new Bar();\n" + + " foos.get(0).bar(bar);\n" + + " }\n" + + "}", + "B.java", + "package bug469201.p2;\n" + + "import bug469201.p1.A;\n" + + "public class B extends A {}\n" + }, + "----------\n" + + "1. ERROR in D.java (at line 9)\n" + + " foos.get(0).bar(bar);\n" + + " ^^^\n" + + "The method bar(Bar) from the type A is not visible\n" + + "----------\n"); + } +public void testBug460491() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "A.java", + "class A {\n" + + " private static final B.C c = new B.D();\n" + + "}", + "B.java", + "class B {\n" + + " public interface C {}\n" + + " public static class D implements C {}\n" + + "}" + }, + customOptions); + } +} +public void testBug492450_comment0() { + if (this.complianceLevel >= ClassFileConstants.JDK1_6) { + runConformTest( + new String[] { + "DocumentObject.java", + "\n" + + "import java.util.ArrayList;\n" + + "\n" + + "interface IDocumentElementNode {\n" + + " public ArrayList getChildNodesList();\n" + + "}\n" + + "\n" + + "abstract class DocumentElementNode implements IDocumentElementNode {\n" + + " @Override\n" + + " public ArrayList getChildNodesList() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface IDocumentObject extends IDocumentElementNode {\n" + + " public ArrayList getChildNodesList(Class[] classes, boolean match);\n" + + "}\n" + + "\n" + + "public abstract class DocumentObject extends DocumentElementNode implements IDocumentObject {\n" + + " @Override\n" + + " public ArrayList getChildNodesList(Class[] classes, boolean match) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); + } +} +public void testBug532653() { + if (this.complianceLevel >= ClassFileConstants.JDK1_6) { + runConformTest( + new String[] { + "Builder.java", + "public interface Builder {\n" + + " T build();\n" + + "}\n", + "ConcreteBuilder.java", + "public class ConcreteBuilder> implements Builder {\n" + + " private String s = \"\";\n" + + " protected B b;\n" + + " @Override\n" + + " public String build() {\n" + + " return s;\n" + + " }\n" + + " public B append(String s) {\n" + + " this.s += s;\n" + + " return b;\n" + + " }\n" + + " public static ConcreteBuilder create() {\n" + + " class ConcreteStringBuilder extends ConcreteBuilder {\n" + + " public ConcreteStringBuilder() {\n" + + " b = this;\n" + + " }\n" + + " }\n" + + " return new ConcreteStringBuilder();\n" + + " }\n" + + "}", + "ConcreteSubBuilder.java", + "public class ConcreteSubBuilder> extends ConcreteBuilder{\n" + + " public B appendTwice(String s) {\n" + + " return super.append(s).append(s);\n" + + " }\n" + + " public static ConcreteSubBuilder create() {\n" + + " class ConcreteSubStringBuilder extends ConcreteSubBuilder {\n" + + " public ConcreteSubStringBuilder() {\n" + + " b = this;\n" + + " }\n" + + " }\n" + + " return new ConcreteSubStringBuilder();\n" + + " }\n" + + "}\n" + }); + } +} +public void testBug541772() { + runConformTest( + new String[] { + "bug541772Runtime/GeneratedMessage.java", + "package bug541772Runtime;\n" + + "\n" + + "public class GeneratedMessage {\n" + + " public class Builder {\n" + + " }\n" + + "}\n" + + "", + }, + "", + getCompilerOptions() + ); + + runConformTest( + new String[] { + "token/Token.java", + "package token;\n" + + "\n" + + "public class Token {\n" + + " \n" + + " public Token() {\n" + + " }\n" + + "\n" + + " public Token(TokenProto tokenPB) {\n" + + " tokenPB.hashCode();\n" + + " }\n" + + " public Token(String x) {\n" + + " x.hashCode();\n" + + " }\n" + + "}\n" + + "", + "token/TokenProto.java", + "package token;\n" + + "\n" + + "import bug541772Runtime.GeneratedMessage;\n" + + "\n" + + "public class TokenProto {\n" + + "\n" + + " public TokenProto(GeneratedMessage.Builder builder) {\n" + + " builder.hashCode();\n" + + " }\n" + + "}\n" + + "", + }, + "", + null /*classLibraries*/, + false /*shouldFlushOutputDirectory*/, + null /*vmArguments*/, + getCompilerOptions(), + null /*customRequestor*/); + + Util.flushDirectoryContent(new File(OUTPUT_DIR + File.separator + "bug541772Runtime")); + + runConformTest( + new String[] { + "pkg/Example.java", + "package pkg;\n" + + "\n" + + "import token.Token;\n" + + "\n" + + "public abstract class Example {\n" + + " public static void setConnectorInfo() {\n" + + " new Token(\"\");\n" + + " }\n" + + "}\n" + + "", + }, + "", + null /*classLibraries*/, + false /*shouldFlushOutputDirectory*/, + null /*vmArguments*/, + getCompilerOptions(), + null /*customRequestor*/); +} +public void testBug541772_typeannotations() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + runConformTest( + new String[] { + "bug541772Runtime/GeneratedMessage.java", + "package bug541772Runtime;\n" + + "\n" + + "public class GeneratedMessage {\n" + + " public class Builder {\n" + + " }\n" + + "}\n" + + "", + }, + "", + getCompilerOptions() + ); + + runConformTest( + new String[] { + "token/Ann.java", + "package token;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface Ann {}\n", + "token/Token.java", + "package token;\n" + + "\n" + + "public class Token {\n" + + " \n" + + " public Token() {\n" + + " }\n" + + "\n" + + " public Token(TokenProto tokenPB) {\n" + + " tokenPB.hashCode();\n" + + " }\n" + + " public Token(String x) {\n" + + " x.hashCode();\n" + + " }\n" + + "}\n" + + "", + "token/TokenProto.java", + "package token;\n" + + "\n" + + "import bug541772Runtime.GeneratedMessage;\n" + + "\n" + + "public class TokenProto {\n" + + "\n" + + " public TokenProto(GeneratedMessage.@Ann Builder builder) {\n" + + " builder.hashCode();\n" + + " }\n" + + "}\n" + + "", + }, + "", + null /*classLibraries*/, + false /*shouldFlushOutputDirectory*/, + null /*vmArguments*/, + getCompilerOptions(), + null /*customRequestor*/); + + Util.flushDirectoryContent(new File(OUTPUT_DIR + File.separator + "bug541772Runtime")); + + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + runConformTest( + new String[] { + "pkg/Example.java", + "package pkg;\n" + + "\n" + + "import token.Token;\n" + + "\n" + + "public abstract class Example {\n" + + " public static void setConnectorInfo() {\n" + + " new Token(\"\");\n" + + " }\n" + + "}\n" + + "", + }, + "", + null /*classLibraries*/, + false /*shouldFlushOutputDirectory*/, + null /*vmArguments*/, + compilerOptions, + null /*customRequestor*/); +} +/** + * This test targets the optimization for parameterized dependencies in {@code BoundSet.combineSameSameWithProperType(...)}. + */ +public void testBug543480BasedOnTest2FromComment4ToSameSameOptimization() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) { + final List durationsFor2TypeParameters = compileTimesAfterWarmup(() -> runConformTest( + new String[] { + "Test2_2.java", + "public class Test2_2 {\n" + + " void test() {\n" + + " m(s(\n" + + " f(1),\n" + + " f(2)\n" + + " ));\n" + + " }\n" + + "\n" + + " static R m(S s) { return null; }\n" + + " static F f(T t) { return null; }\n" + + " static S> s(F t1) { return null; }\n" + + " static S> s(F t1, F t2) { return null; }\n" + + "}\n" + + "interface F {}\n" + + "interface S {}\n" + + "interface R1 {}\n" + + "interface R2 {}\n" + })); + final List durationsFor11TypeParameters = compileTimesAfterWarmup(() -> runConformTest( + new String[] { + "Test2_11.java", + "public class Test2_11 {\n" + + " void test() {\n" + + " m(s(\n" + + " f(1),\n" + + " f(2),\n" + + " f(3),\n" + + " f(4),\n" + + " f(5),\n" + + " f(6),\n" + + " f(7),\n" + + " f(8),\n" + + " f(9),\n" + + " f(10),\n" + + " f(11)\n" + + " ));\n" + + " }\n" + + "\n" + + " static R m(S s) { return null; }\n" + + " static F f(T t) { return null; }\n" + + " static S> s(F t1) { return null; }\n" + + " static S> s(F t1, F t2) { return null; }\n" + + " static S> s(F t1, F t2, F t3) { return null; }\n" + + " static S> s(F t1, F t2, F t3, F t4) { return null; }\n" + + " static S> s(F t1, F t2, F t3, F t4, F t5) { return null; }\n" + + " static S> s(F t1, F t2, F t3, F t4, F t5, F t6) { return null; }\n" + + " static S> s(F t1, F t2, F t3, F t4, F t5, F t6, F t7) { return null; }\n" + + " static S> s(F t1, F t2, F t3, F t4, F t5, F t6, F t7, F t8) { return null; }\n" + + " static S> s(F t1, F t2, F t3, F t4, F t5, F t6, F t7, F t8, F t9) { return null; }\n" + + " static S> s(F t1, F t2, F t3, F t4, F t5, F t6, F t7, F t8, F t9, F t10) { return null; }\n" + + " static S> s(F t1, F t2, F t3, F t4, F t5, F t6, F t7, F t8, F t9, F t10, F t11) { return null; }\n" + + "}\n" + + "interface F {}\n" + + "interface S {}\n" + + "interface R1 {}\n" + + "interface R2 {}\n" + + "interface R3 {}\n" + + "interface R4 {}\n" + + "interface R5 {}\n" + + "interface R6 {}\n" + + "interface R7 {}\n" + + "interface R8 {}\n" + + "interface R9 {}\n" + + "interface R10 {}\n" + + "interface R11 {}\n" + })); + // Time complexity should grow roughly linearly, not O(2^n) + // To make the test robust, it tests for the same order of magnitude only, i.e. factor 10. + assertCompileTimes(durationsFor2TypeParameters, 10, durationsFor11TypeParameters); + } +} +/** + * This test targets the optimization for parameterized dependencies in {@code BoundSet.combineSameSubSuperWithProperType(...)}. + */ +public void testBug543480WithSameSubSuperOptimization() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) { + final List durationsFor2TypeParameters = compileTimesAfterWarmup(() -> runConformTest( + new String[] { + "WithParameterizedDependencies_2.java", + "abstract class WithParameterizedDependencies_2 {\n" + + " \n" + + " Type1\n" + + " s1(Type1 t) {\n" + + // This line causes the optimization in BoundSet.combineSameSubSuperWithProperType(...) to be effective. + " return s2(new Type1<>(t));\n" + + " }\n" + + " abstract E s2(E e);\n" + + "}\n" + + "class Type1 {\n" + + " Type1(final Type1 l) {}" + + "}\n" + })); + final List durationsFor12TypeParameters = compileTimesAfterWarmup(() -> runConformTest( + new String[] { + "WithParameterizedDependencies_12.java", + "abstract class WithParameterizedDependencies_12 {\n" + + " \n" + + " Type1\n" + + " s1(Type1 t) {\n" + + // This line causes the optimization in BoundSet.combineSameSubSuperWithProperType(...) to be effective. + " return s2(new Type1<>(t));\n" + + " }\n" + + " abstract E s2(E e);\n" + + "}\n" + + "class Type1 {\n" + + " Type1(final Type1 l) {}" + + "}\n" + })); + // Time complexity should grow roughly linearly, not O(2^n). + // To make the test robust, it tests for the same order of magnitude only, i.e. factor 10. + assertCompileTimes(durationsFor2TypeParameters, 10, durationsFor12TypeParameters); + } +} +/** + * An earlier version of the fix for bug 543480 causes a NullPointerException when compiling this code. + */ +public void testBug543480WithoutNullPointerExceptionDuringBytecodeGeneration() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) { + runConformTest( + new String[] { + "Test.java", + "import java.util.function.BiConsumer;\n" + + "\n" + + "public class Test {\n" + + " \n" + + " interface I0> {}\n" + + "\n" + + " class Type, D> {\n" + + " // TODO: The problem might be that BiConsumer is not declared in the same file?\n" + + " public Type(final BiConsumer b) { }\n" + + " }\n" + + "\n" + + " public void foo() {\n" + + " new Type<>((unused0, unused1) -> {});\n" + + " }\n" + + "}" + }); + } +} + +public void testBugBug571785_001() { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) { + runConformTest( + new String[] { + "Test.java", + "import java.util.Collection;\n"+ + "\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " new testclass();\n" + + " }\n" + + "}\n" + + "class testclass {\n" + + " public void update(final Collection inputs) {\n" + + " inputs.forEach(this::update);\n" + + " }\n" + + " public void update(final byte[] input) {\n" + + " }\n" + + "}\n" + }); + } +} + +protected void assertCompileTimes(final List shortTimes, final double factor, final List longTimes) { + final double shortTimesAverage = minExcludingBoundaries(shortTimes); + final double longTimesAverage = minExcludingBoundaries(longTimes); + final String message = "Potential fluctuation of a performance test: minimum long compile time " + + longTimesAverage + "ms should be less than " + factor + "x the minimum short compile time " + shortTimesAverage +"ms\n" + + "long compile times: "+longTimes+"\n" + + "short compile times: "+shortTimes; + if (PERFORMANCE_ASSERTS) { + assertTrue(message,longTimesAverage < factor*shortTimesAverage); + System.out.println(message); + } else if (longTimesAverage >= factor*shortTimesAverage) { + System.out.println(message); + } +} + +protected double minExcludingBoundaries(final List durations) { + return durations.stream() + .filter(duration -> !duration.isExcluded) + .mapToLong(duration -> duration.durationMs) + .min().orElse(-1); +} + +protected List compileTimesAfterWarmup(final Runnable compileTask) { + // warm up + duration(compileTask); + runGarbageCollection(); + // draw samples, exclude boundaries i.e. exclude potential outliers + final int numberOfSamples = 10; + final int boundarySize = 2; + return IntStream.rangeClosed(1, numberOfSamples) + .mapToObj(duration(compileTask)) + .sorted() + .peek(markExcludedBoundaries(boundarySize, numberOfSamples)) + .collect(toList()); +} + +protected static IntFunction duration(final Runnable runnable) { + return index -> { + java.time.Duration s00 = ProcessHandle.current().info().totalCpuDuration().get(); + // wait for a OS scheduler slice begin to increase probability to finish within a single slice: + java.time.Duration s0; + java.lang.Thread.yield(); + do { + java.lang.Thread.onSpinWait(); + s0 = ProcessHandle.current().info().totalCpuDuration().get(); + } while (s0.equals(s00)); + long t0 = System.nanoTime(); + runnable.run(); + long t1 = System.nanoTime(); + long tdiff = (t1 - t0) / 1000_000; + java.time.Duration s1 = ProcessHandle.current().info().totalCpuDuration().get(); + java.time.Duration diff = s1.minus(s0); + long duration = diff.toMillis(); + // if more then one slice we better take the OS value: + duration = duration == 0 ? tdiff : Math.min(duration, tdiff); + return new Duration(index, duration); + }; +} + +protected static Consumer markExcludedBoundaries(final int boundarySize, final int numberOfSamples) { + final AtomicInteger seenSamples = new AtomicInteger(0); + return duration -> { + final int indexFromBottom = seenSamples.get(); + final int indexFromTop = abs(seenSamples.get() - numberOfSamples); + if(indexFromBottom < boundarySize) { + // a sample within the lower boundary + duration.isExcluded = true; + } else if(indexFromTop <= boundarySize) { + // a sample within the upper boundary + duration.isExcluded = true; + } + seenSamples.incrementAndGet(); + }; +} + +protected static class Duration implements Comparable { + protected final int index; + protected final long durationMs; + protected boolean isExcluded = false; + + public Duration(final int index, final long durationMs) { + this.index = index; + this.durationMs = durationMs; + } + + @Override + public int compareTo(Duration other) { + return (int)(this.durationMs - other.durationMs); + } + + @Override + public String toString() { + return "#"+this.index + " " + this.durationMs + "ms" + (this.isExcluded?" (excluded)":""); + } +} + +} + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java new file mode 100644 index 0000000000..f71d4bdd4b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java @@ -0,0 +1,6661 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 282152 - [1.5][compiler] Generics code rejected by Eclipse but accepted by javac + * bug 395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation. + * bug 401456 - Code compiles from javac/intellij, but fails from eclipse + * bug 405706 - Eclipse compiler fails to give compiler error when return type is a inferred generic + * Bug 408441 - Type mismatch using Arrays.asList with 3 or more implementations of an interface with the interface type as the last parameter + * Bug 413958 - Function override returning inherited Generic Type + * Bug 415734 - Eclipse gives compilation error calling method with an inferred generic return type + * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) + * Bug 423496 - [1.8] Implement new incorporation rule once it becomes available + * Bug 426590 - [1.8][compiler] Compiler error with tenary operator + * Bug 427216 - [Java8] array to varargs regression + * Bug 425031 - [1.8] nondeterministic inference for GenericsRegressionTest.test283353 + * Bug 430686 - [1.8][compiler] Generics: erroneously reports 'method not applicable for the arguments' + * Bug 430759 - [1.8][compiler] SourceTypeBinding cannot be cast to ParameterizedTypeBinding + * Bug 431408 - Java 8 (1.8) generics bug + * Bug 432603 - [compile][1.7] ecj reports an Error while javac doesn't + * Bug 399527 - Type inference problem + * Bug 434570 - Generic type mismatch for parametrized class annotation attribute with inner class + * Bug 434044 - Java 8 generics thinks single method is ambiguous + * Bug 434793 - [1.8][null][compiler] AIOOBE in ParameterizedGenericMethodBinding.substitute when inlining a method + * Bug 438337 - StackOverflow after update from Kepler to Luna + * Bug 452194 - Code no longer compiles in 4.4.1, but with confusing error + * Bug 456459 - Discrepancy between Eclipse compiler and javac - Enums, interfaces, and generics + * Bug 456924 - StackOverflowError during compilation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class GenericsRegressionTest extends AbstractComparableTest { + + public GenericsRegressionTest(String name) { + super(name); + } + + // 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[] { "testBug456459" }; +// TESTS_NUMBERS = new int[] { 1465 }; +// TESTS_RANGE = new int[] { 1097, -1 }; + } + public static Test suite() { + return buildComparableTestSuite(testClass()); + } + + public static Class testClass() { + return GenericsRegressionTest.class; + } + + @Override + protected Map getCompilerOptions() { + Map compilerOptions = super.getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedTypeParameter,CompilerOptions.IGNORE); + return compilerOptions; + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322531 + public void test322531b() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "public class X implements I {\n" + + " void main(Class clazz) {\n" + + " boolean b = \n" + + " clazz == clazz || \n" + + " X.class == X.class || \n" + + " I.class == I.class || \n" + + " clazz == X.class || \n" + + " X.class == clazz || \n" + + " clazz == I.class || \n" + + " I.class == clazz || \n" + + " I.class == X.class ||\n" + + " X.class == I.class;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " clazz == clazz || \n" + + " ^^^^^^^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " I.class == X.class ||\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " X.class == I.class;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322531 + public void test322531c() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "public class X {\n" + + " void main(Class clazz, X x) {\n" + + " boolean b = \n" + + " x.getClass() == clazz || \n" + + " clazz == x.getClass(); \n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322531 + public void test322531d() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "public final class X {\n" + + " void main(Class clazz, X x) {\n" + + " boolean b = \n" + + " x.getClass() == clazz || \n" + + " clazz == x.getClass(); \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " x.getClass() == clazz || \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " clazz == x.getClass(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322531 + public void test322531e() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "public final class X implements I {\n" + + " void main(Class clazz, X x) {\n" + + " boolean b = \n" + + " x.getClass() == clazz || \n" + + " clazz == x.getClass(); \n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322531 + public void test322531f() { + this.runNegativeTest( + new String[] { + "X.java", + "class I {}\n" + + "public class X {\n" + + " void main(Class clazz, X x) {\n" + + " boolean b = \n" + + " x.getClass() == clazz || \n" + + " clazz == x.getClass(); \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " x.getClass() == clazz || \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " clazz == x.getClass(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322531 + public void test322531i() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {};\n" + + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public void test(Class clazz) {\n" + + " Class ci = I.class;\n" + + " Class ti = X.class;\n" + + " boolean b = ci == X.class ||\n" + + " X.class == ci ||\n" + + " I.class == X.class ||\n" + + " X.class == I.class ||\n" + + " ti == I.class ||\n" + + " I.class == ti ||\n" + + " ti == ci ||\n" + + " ci == ti;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " boolean b = ci == X.class ||\n" + + " ^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " X.class == ci ||\n" + + " ^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " I.class == X.class ||\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " X.class == I.class ||\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n" + + "5. ERROR in X.java (at line 12)\n" + + " ti == I.class ||\n" + + " ^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " I.class == ti ||\n" + + " ^^^^^^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n" + + "7. ERROR in X.java (at line 14)\n" + + " ti == ci ||\n" + + " ^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n" + + "8. ERROR in X.java (at line 15)\n" + + " ci == ti;\n" + + " ^^^^^^^^\n" + + "Incompatible operand types Class and Class\n" + + "----------\n"); + } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152 +public void test282152() { + this.runConformTest( + new String[] { + "Test.java", + "public interface Test {\n" + + " public void test(Test t, U value);\n" + + " public void setValue(T v);" + + "}", + "Impl.java", + "public class Impl implements Test{\n" + + " T val;" + + " public void test(Test t, U value) {\n" + + " t.setValue(value);\n" + + " }\n" + + " public void setValue(T v) {\n" + + " this.val = v;\n" + + " }\n" + + "}", + "Client.java", + "public class Client {\n" + + " void test() {\n" + + " Impl t1 = new Impl();\n" + + " Double n = Double.valueOf(3.14);\n" + + " t1.test(new Impl(), n);\n" + + " }\n" + + "}\n" + }, + ""); // no specific success output string +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152 +// violating lower bound +public void test282152b() { + this.runNegativeTest( + new String[] { + "Test.java", + "public interface Test {\n" + + " public void test(Test t, U value);\n" + + " public void setValue(T v);" + + "}", + "Impl.java", + "public class Impl implements Test{\n" + + " T val;" + + " public void test(Test t, U value) {\n" + + " t.setValue(value);\n" + + " }\n" + + " public void setValue(T v) {\n" + + " this.val = v;\n" + + " }\n" + + "}", + "Client.java", + "public class Client {\n" + + " void test() {\n" + + " Impl t1 = new Impl();\n" + + " Number n = Double.valueOf(3.14);\n" + + " t1.test(new Impl(), n);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Client.java (at line 5)\n" + + " t1.test(new Impl(), n);\n" + + " ^^^^\n" + + "The method test(Test, U) in the type Impl is not applicable for the arguments (Impl, Number)\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152 +// contradictory bounds +public void test282152c() { + this.runNegativeTest( + new String[] { + "Test.java", + "public interface Test {\n" + + " public void test(Test t, U value);\n" + + " public void setValue(T v);" + + "}" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " public void test(Test t, U value);\n" + + " ^^^^^^^^^\n" + + "Bound mismatch: The type ? super U is not a valid substitute for the bounded parameter of the type Test\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152 +// compatible constraints +public void test282152d() { + this.runConformTest( + new String[] { + "Test.java", + "public interface Test {\n" + + " public void test(Test t, U value);\n" + + " public void setValue(T v);" + + "}", + "Impl.java", + "public class Impl implements Test{\n" + + " T val;" + + " public void test(Test t, U value) {\n" + + " t.setValue(value);\n" + + " }\n" + + " public void setValue(T v) {\n" + + " this.val = v;\n" + + " }\n" + + "}", + "Client.java", + "public class Client {\n" + + " void test() {\n" + + " Impl t1 = new Impl();\n" + + " Integer i = Integer.valueOf(3);\n" + + " t1.test(new Impl(), i);\n" + + " }\n" + + "}\n" + }, + ""); // no specific success output string +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=282152 +// direct use of type variable does not involve capture, thus no merging of constraints happens +public void test282152e() { + this.runNegativeTest( + new String[] { + "Test.java", + "public interface Test {\n" + + " public void test(Test t, U value);\n" + + " public void setValue(T v);" + + "}" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " public void test(Test t, U value);\n" + + " ^\n" + + "Bound mismatch: The type U is not a valid substitute for the bounded parameter of the type Test\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=330869 +public void test330869() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public T getAdapter(Class adapterType) {\n" + + " T result = null;\n" + + " if (adapterType == Foo.class) {\n" + + " }\n" + + " else if (adapterType == Bar.class) {\n" + + " }\n" + + " return result;\n" + + " }\n" + + " public class Foo {\n" + + " }\n" + + " public interface Bar {\n" + + " }\n" + + "}\n" + }, + ""); // no specific success output string +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 +public void test322817() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "interface Adaptable {\n" + + " public Object getAdapter(Class clazz); \n" + + "}\n" + + "public class X implements Adaptable {\n" + + " public Object getAdapter(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public Object getAdapter(Class clazz); \n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 +public void test322817b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "X.java", + "interface Adaptable {\n" + + " public Object getAdapter(Class clazz); \n" + + "}\n" + + "public class X implements Adaptable {\n" + + " public Object getAdapter(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public Object getAdapter(Class clazz); \n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " public Object getAdapter(Class clazz) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 +public void test322817c() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "interface Adaptable {\n" + + " public Object getAdapter(Class clazz); \n" + + "}\n" + + "public class X implements Adaptable {\n" + + " public Object getAdapter(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public Object getAdapter(Class clazz) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 +public void test322817d() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "interface Adaptable {\n" + + " public Object getAdapter(Class clazz); \n" + + "}\n" + + "public class X implements Adaptable {\n" + + " public Object getAdapter(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " @Override\n" + + " public Object getAdapter(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public Object getAdapter(Class clazz) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 +public void test322817e() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Top {\n" + + " public void set(List arg) { } // OK to warn in 1.5 code\n" + + " public List get() { return null; } // OK to warn in 1.5 code\n" + + "}\n" + + "class Sub extends Top {\n" + + " @Override\n" + + " public void set(List arg) { // should not warn (overrides)\n" + + " }\n" + + " @Override\n" + + " public List get() { // should not warn (overrides)\n" + + " return super.get();\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void set(List arg) { } // OK to warn in 1.5 code\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public List get() { return null; } // OK to warn in 1.5 code\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 +public void test322817f() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Top {\n" + + " public void set(List arg) { } // OK to warn in 1.5 code\n" + + " public List get() { return null; }\n" + + "}\n" + + "class Sub extends Top {\n" + + " @Override\n" + + " public void set(List arg) { // should not warn (overrides)\n" + + " }\n" + + " @Override\n" + + " public List get() { // should warn (super's return type is not raw)\n" + + " return super.get();\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void set(List arg) { } // OK to warn in 1.5 code\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " public List get() { // should warn (super\'s return type is not raw)\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " public List get() { // should warn (super\'s return type is not raw)\n" + + " ^^^^\n" + + "Type safety: The return type List for get() from the type Sub needs unchecked conversion to conform to List from the type Top\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (Disable reporting of unavoidable problems) +public void test322817g() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "Top.java", + "import java.util.List;\n" + + "public class Top {\n" + + " public void set(List arg) { } // OK to warn in 1.5 code\n" + + " public List get() { return null; } // OK to warn in 1.5 code\n" + + " List list; // OK to warn in 1.5 code\n" + + "}\n", + "Sub.java", + "import java.util.List;\n" + + "public class Sub extends Top {\n" + + " @Override\n" + + " public void set(List arg) { // should not warn (overrides)\n" + + " super.set(arg);\n" + + " arg.set(0, \"A\"); // should not warn ('arg' is forced raw)\n" + + " }\n" + + " @Override\n" + + " public List get() { // should not warn (overrides)\n" + + " return super.get();\n" + + " }\n" + + "}\n", + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void run() {\n" + + " new Top().list.add(\"arg\"); // should not warn (uses raw field declared elsewhere)\n" + + " new Top().get().add(\"arg\"); // should not warn (uses raw API)\n" + + " List raw= new Top().get(); // OK to warn ('raw' declared here)\n" + + " raw.add(\"arg\"); // OK to warn ('raw' declared here)\n" + + " // When Top#get() is generified, both of the following will fail\n" + + " // with a compile error if type arguments don't match:\n" + + " List unchecked= new Top().get(); // should not warn (forced)\n" + + " unchecked.add(\"x\");\n" + + " // Should not warn about unchecked cast, but should warn about\n" + + " // unnecessary cast:\n" + + " List cast= (List) new Top().get();\n" + + " cast.add(\"x\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Top.java (at line 3)\n" + + " public void set(List arg) { } // OK to warn in 1.5 code\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in Top.java (at line 4)\n" + + " public List get() { return null; } // OK to warn in 1.5 code\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in Top.java (at line 5)\n" + + " List list; // OK to warn in 1.5 code\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " List raw= new Top().get(); // OK to warn (\'raw\' declared here)\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " raw.add(\"arg\"); // OK to warn (\'raw\' declared here)\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " List cast= (List) new Top().get();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (Enable reporting of unavoidable problems) +public void test322817h() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "Top.java", + "import java.util.List;\n" + + "public class Top {\n" + + " public void set(List arg) { }\n" + + " public List get() { return null; }\n" + + " List list;\n" + + "}\n", + "Sub.java", + "import java.util.List;\n" + + "public class Sub extends Top {\n" + + " @Override\n" + + " public void set(List arg) {\n" + + " super.set(arg);\n" + + " arg.set(0, \"A\");\n" + + " }\n" + + " @Override\n" + + " public List get() {\n" + + " return super.get();\n" + + " }\n" + + "}\n", + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void run() {\n" + + " new Top().list.add(\"arg\");\n" + + " new Top().get().add(\"arg\");\n" + + " List raw= new Top().get();\n" + + " raw.add(\"arg\");\n" + + " List unchecked= new Top().get();\n" + + " unchecked.add(\"x\");\n" + + " List cast= (List) new Top().get();\n" + + " cast.add(\"x\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Top.java (at line 3)\n" + + " public void set(List arg) { }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in Top.java (at line 4)\n" + + " public List get() { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in Top.java (at line 5)\n" + + " List list;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in Sub.java (at line 4)\n" + + " public void set(List arg) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in Sub.java (at line 6)\n" + + " arg.set(0, \"A\");\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method set(int, Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in Sub.java (at line 9)\n" + + " public List get() {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Top().list.add(\"arg\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " new Top().get().add(\"arg\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " List raw= new Top().get();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " raw.add(\"arg\");\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " List unchecked= new Top().get();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " List cast= (List) new Top().get();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to List\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " List cast= (List) new Top().get();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (Default options) +public void test322817i() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "Top.java", + "import java.util.List;\n" + + "public class Top {\n" + + " public void set(List arg) { }\n" + + " public List get() { return null; }\n" + + " List list;\n" + + "}\n", + "Sub.java", + "import java.util.List;\n" + + "public class Sub extends Top {\n" + + " @Override\n" + + " public void set(List arg) {\n" + + " super.set(arg);\n" + + " arg.set(0, \"A\");\n" + + " }\n" + + " @Override\n" + + " public List get() {\n" + + " return super.get();\n" + + " }\n" + + "}\n", + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void run() {\n" + + " new Top().list.add(\"arg\");\n" + + " new Top().get().add(\"arg\");\n" + + " List raw= new Top().get();\n" + + " raw.add(\"arg\");\n" + + " List unchecked= new Top().get();\n" + + " unchecked.add(\"x\");\n" + + " List cast= (List) new Top().get();\n" + + " cast.add(\"x\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Top.java (at line 3)\n" + + " public void set(List arg) { }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in Top.java (at line 4)\n" + + " public List get() { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in Top.java (at line 5)\n" + + " List list;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in Sub.java (at line 4)\n" + + " public void set(List arg) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in Sub.java (at line 6)\n" + + " arg.set(0, \"A\");\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method set(int, Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in Sub.java (at line 9)\n" + + " public List get() {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Top().list.add(\"arg\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " new Top().get().add(\"arg\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " List raw= new Top().get();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " raw.add(\"arg\");\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " List unchecked= new Top().get();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " List cast= (List) new Top().get();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to List\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " List cast= (List) new Top().get();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (all in same file) +public void test322817j() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class Top {\n" + + " public void set(List arg) { } // OK to warn in 1.5 code\n" + + " public List get() { return null; } // OK to warn in 1.5 code\n" + + "}\n" + + "class Sub extends Top {\n" + + " @Override\n" + + " public void set(List arg) { // should not warn (overrides)\n" + + " super.set(arg);\n" + + " arg.set(0, \"A\"); // should not warn ('arg' is forced raw)\n" + + " }\n" + + " @Override\n" + + " public List get() { // should not warn (overrides)\n" + + " return super.get();\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " void run() {\n" + + " new Top().get().add(\"arg\");\n" + + " List raw= new Top().get(); // OK to warn ('raw' declared here)\n" + + " raw.add(\"arg\"); // OK to warn ('raw' declared here)\n" + + " List unchecked= new Top().get();\n" + + " unchecked.add(\"x\");\n" + + " List cast= (List) new Top().get();\n" + + " cast.add(\"x\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void set(List arg) { } // OK to warn in 1.5 code\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public List get() { return null; } // OK to warn in 1.5 code\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 19)\n" + + " new Top().get().add(\"arg\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 20)\n" + + " List raw= new Top().get(); // OK to warn (\'raw\' declared here)\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 21)\n" + + " raw.add(\"arg\"); // OK to warn (\'raw\' declared here)\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 22)\n" + + " List unchecked= new Top().get();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "7. WARNING in X.java (at line 24)\n" + + " List cast= (List) new Top().get();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to List\n" + + "----------\n" + + "8. WARNING in X.java (at line 24)\n" + + " List cast= (List) new Top().get();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from List to List\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322817 (make sure there is no NPE when receiver is null) +public void test322817k() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.Set;\n" + + "import java.util.HashSet;\n" + + "public class X {\n" + + " public void foo(String[] elements) {\n" + + " Set set= new HashSet(Arrays.asList(elements));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Set set= new HashSet(Arrays.asList(elements));\n" + + " ^^^\n" + + "Set is a raw type. References to generic type Set should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " Set set= new HashSet(Arrays.asList(elements));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor HashSet(Collection) belongs to the raw type HashSet. References to generic type HashSet should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " Set set= new HashSet(Arrays.asList(elements));\n" + + " ^^^^^^^\n" + + "HashSet is a raw type. References to generic type HashSet should be parameterized\n" + + "----------\n", + null, + true, + customOptions); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=338350 (unchecked cast - only unavoidable on raw expression) +public void test338350() { + String[] testFiles = new String[] { + "Try.java", + "import java.lang.reflect.Array;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Try {\n" + + " void fooObj() {\n" + + " takeObj((E) Bar.getObject());\n" + + " takeObj((E) Bar.getArray());\n" + + " takeObj((E) Array.newInstance(Integer.class, 2));\n" + + " }\n" + + " void takeObj(E obj) { }\n" + + " void fooArray() {\n" + + " takeArray((E[]) Bar.getArray());\n" + + " takeArray((E[]) Array.newInstance(Integer.class, 2));\n" + + " }\n" + + " void takeArray(E[] array) { }\n" + + " void foo(List list) {\n" + + " list.toArray((L[]) Bar.getArray());\n" + + " list.toArray((L[]) Array.newInstance(Integer.class, 2));\n" + + " }\n" + + " void bar() {\n" + + " List l = (List) Bar.getObject();\n" + + " List l2 = Bar.getRawList();\n" + + " ArrayList l3 = (ArrayList) Bar.getRawList();\n" + + " }\n" + + "}\n", + "Bar.java", + "import java.lang.reflect.Array;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Bar {\n" + + " public static Object getObject() {\n" + + " return new Object();\n" + + " }\n" + + " public static Object[] getArray() {\n" + + " return (Object[]) Array.newInstance(Integer.class, 2);\n" + + " }\n" + + " public static List getRawList() {\n" + + " return new ArrayList();\n" + + " }\n" + + "}\n" + }; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); + this.runNegativeTest( + testFiles, + "----------\n" + + "1. WARNING in Try.java (at line 6)\n" + + " takeObj((E) Bar.getObject());\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to E\n" + + "----------\n" + + "2. WARNING in Try.java (at line 7)\n" + + " takeObj((E) Bar.getArray());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to E\n" + + "----------\n" + + "3. WARNING in Try.java (at line 8)\n" + + " takeObj((E) Array.newInstance(Integer.class, 2));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to E\n" + + "----------\n" + + "4. WARNING in Try.java (at line 12)\n" + + " takeArray((E[]) Bar.getArray());\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to E[]\n" + + "----------\n" + + "5. WARNING in Try.java (at line 13)\n" + + " takeArray((E[]) Array.newInstance(Integer.class, 2));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to E[]\n" + + "----------\n" + + "6. WARNING in Try.java (at line 17)\n" + + " list.toArray((L[]) Bar.getArray());\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to L[]\n" + + "----------\n" + + "7. WARNING in Try.java (at line 18)\n" + + " list.toArray((L[]) Array.newInstance(Integer.class, 2));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to L[]\n" + + "----------\n" + + "8. WARNING in Try.java (at line 21)\n" + + " List l = (List) Bar.getObject();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "9. WARNING in Try.java (at line 22)\n" + + " List l2 = Bar.getRawList();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "10. WARNING in Try.java (at line 23)\n" + + " ArrayList l3 = (ArrayList) Bar.getRawList();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to ArrayList\n" + + "----------\n" + + "----------\n" + + "1. WARNING in Bar.java (at line 11)\n" + + " public static List getRawList() {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in Bar.java (at line 12)\n" + + " return new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n", + null, + true, + customOptions); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + testFiles, + "----------\n" + + "1. WARNING in Try.java (at line 6)\n" + + " takeObj((E) Bar.getObject());\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to E\n" + + "----------\n" + + "2. WARNING in Try.java (at line 7)\n" + + " takeObj((E) Bar.getArray());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to E\n" + + "----------\n" + + "3. WARNING in Try.java (at line 8)\n" + + " takeObj((E) Array.newInstance(Integer.class, 2));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to E\n" + + "----------\n" + + "4. WARNING in Try.java (at line 12)\n" + + " takeArray((E[]) Bar.getArray());\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to E[]\n" + + "----------\n" + + "5. WARNING in Try.java (at line 13)\n" + + " takeArray((E[]) Array.newInstance(Integer.class, 2));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to E[]\n" + + "----------\n" + + "6. WARNING in Try.java (at line 17)\n" + + " list.toArray((L[]) Bar.getArray());\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object[] to L[]\n" + + "----------\n" + + "7. WARNING in Try.java (at line 18)\n" + + " list.toArray((L[]) Array.newInstance(Integer.class, 2));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to L[]\n" + + "----------\n" + + "8. WARNING in Try.java (at line 21)\n" + + " List l = (List) Bar.getObject();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to List\n" + + "----------\n" + + "----------\n" + + "1. WARNING in Bar.java (at line 11)\n" + + " public static List getRawList() {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in Bar.java (at line 12)\n" + + " return new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n", + null, + true, + customOptions); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (private access - different packages) +public void test334622a() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " private Object foo;\n" + + "}\n", + "q/Y.java", + "package q;\n" + + "import p.X;\n" + + "public class Y {\n" + + " public void test(T t) {\n" + + " System.out.println(t.foo);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 3)\n" + + " private Object foo;\n" + + " ^^^\n" + + "The value of the field X.foo is not used\n" + + "----------\n" + + "----------\n" + + "1. ERROR in q\\Y.java (at line 5)\n" + + " System.out.println(t.foo);\n" + + " ^^^\n" + + "The field X.foo is not visible\n" + + "----------\n" + + "2. ERROR in q\\Y.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (private access - same package) +public void test334622b() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " private Object foo;\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " public void test(T t) {\n" + + " System.out.println(t.foo);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 3)\n" + + " private Object foo;\n" + + " ^^^\n" + + "The value of the field X.foo is not used\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p\\Y.java (at line 4)\n" + + " System.out.println(t.foo);\n" + + " ^^^\n" + + "The field X.foo is not visible\n" + + "----------\n" + + "2. ERROR in p\\Y.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=334622 (member of type variable shouldn't contain private members of class constituting intersection type) +public void test334622c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private Object foo;\n" + + " public void test(T t) {\n" + + " System.out.println(t.foo);\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + this.complianceLevel <= ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" : + + // 1.7+ output. + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " private Object foo;\n" + + " ^^^\n" + + "The value of the field X.foo is not used\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " System.out.println(t.foo);\n" + + " ^^^\n" + + "The field X.foo is not visible\n" + + "----------\n" + + "3. 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=334622 (member of type variable shouldn't contain private members of class constituting intersection type) +public void test334622d() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private Object foo() { return null; }\n" + + " public void test(T t) {\n" + + " t.foo();\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + this.complianceLevel <= ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" : + + // 1.7+ output. + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " t.foo();\n" + + " ^^^\n" + + "The method foo() from the type X is not visible\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=335751 ([1.7][compiler] Cycle inheritance in type arguments is not detected) +public void test335751() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {}\n" + }, + this.complianceLevel <= ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "Illegal forward reference to type parameter B\n" + + "----------\n" : + + // 1.7+ output. + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between B and A\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=334121 ([1.7][compiler] Stackoverflow error if compiled in 1.7 compliance mode) +public void test334121() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {}\n" + }, + this.complianceLevel <= ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "Illegal forward reference to type parameter A\n" + + "----------\n" : + + // 1.7+ output. + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "Cycle detected: the type A cannot extend/implement itself or one of its own member types\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=337751 +public void test337751() { + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + this.runConformTest( + new String[] { + "Project.java", + "import java.util.Map;\n" + + "public class Project {\n" + + " public Map getOptions(boolean b) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions14, + null); + + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "Y.java", + "import java.util.Map;\n" + + "public class Y {\n" + + " void foo(Project project) {\n" + + " Map options=\n" + + " project != null ? project.getOptions(true) : null;\n" + + " options = project.getOptions(true);\n" + + " options = project == null ? null : project.getOptions(true);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Y.java (at line 5)\n" + + " project != null ? project.getOptions(true) : null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Map needs unchecked conversion to conform to Map\n" + + "----------\n" + + "2. WARNING in Y.java (at line 6)\n" + + " options = project.getOptions(true);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Map needs unchecked conversion to conform to Map\n" + + "----------\n" + + "3. WARNING in Y.java (at line 7)\n" + + " options = project == null ? null : project.getOptions(true);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Map needs unchecked conversion to conform to Map\n" + + "----------\n", + null, + false, + compilerOptions15, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=337751 +public void test337751a() { + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + this.runConformTest( + new String[] { + "Project.java", + "import java.util.Map;\n" + + "public class Project {\n" + + " public Map getOptions(boolean b) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions14, + null); + + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "Y.java", + "import java.util.Map;\n" + + "public class Y {\n" + + " void foo(Project project) {\n" + + " Map options=\n" + + " project != null ? project.getOptions(true) : null;\n" + + " options = project.getOptions(true);\n" + + " options = project == null ? null : project.getOptions(true);\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + compilerOptions15, + null, + JavacTestOptions.Excuse.JavacHasWarningsEclipseNotConfigured); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962 +public void test337962() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "class Super {\n" + + " protected List fList;\n" + + "}\n" + + "public class X extends Super {\n" + + " protected List fSubList; // raw type warning (good)\n" + + " {\n" + + " fSubList = new ArrayList();\n " + + " fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + + " super.fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + + " fSubList.add(null); // type safety warning (good, should not be hidden)\n" + + " }\n" + + " void foo(String s) {\n" + + " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + + " }\n" + + " X(String s) {\n" + + " fSubList = new ArrayList();\n " + + " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " protected List fList;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " protected List fSubList; // raw type warning (good)\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " fSubList = new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 11)\n" + + " super.fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 12)\n" + + " fSubList.add(null); // type safety warning (good, should not be hidden)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 15)\n" + + " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "8. WARNING in X.java (at line 16)\n" + + " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "9. WARNING in X.java (at line 17)\n" + + " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "10. WARNING in X.java (at line 20)\n" + + " fSubList = new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "11. WARNING in X.java (at line 21)\n" + + " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "12. WARNING in X.java (at line 22)\n" + + " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "13. WARNING in X.java (at line 23)\n" + + " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n", + null, + false, + compilerOptions15, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=337962 +public void test337962b() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "class Super {\n" + + " protected List fList;\n" + + "}\n" + + "public class X extends Super {\n" + + " protected List fSubList; // raw type warning (good)\n" + + " {\n" + + " fSubList = new ArrayList();\n " + + " fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + + " super.fList.add(null); // type safety warning (TODO: bad, should be hidden)\n" + + " fSubList.add(null); // type safety warning (good, should not be hidden)\n" + + " }\n" + + " void foo(String s) {\n" + + " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + + " }\n" + + " X(String s) {\n" + + " fSubList = new ArrayList();\n " + + " fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " super.fList.add(s); // type safety warning (TODO: bad, should be hidden)\n" + + " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " protected List fList;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " protected List fSubList; // raw type warning (good)\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " fSubList = new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " fSubList.add(null); // type safety warning (good, should not be hidden)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 17)\n" + + " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 20)\n" + + " fSubList = new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 23)\n" + + " fSubList.add(s); // type safety warning (good, should not be hidden)\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method add(Object) belongs to the raw type List. References to generic type List should be parameterized\n" + + "----------\n", + null, + false, + compilerOptions15, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338011 +public void test338011() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X extends A {\n" + + " public X(Map m) { // should warn about raw type m\n" + + " super(m);\n" + + " m.put(\"one\", 1); // warns about raw method invocation (good)\n" + + " }\n" + + " public X(Map m, boolean b) {\n" + + " super(m); // shows that parametrizing the parameter type is no problem \n" + + " new A(m);\n" + + " m.put(\"one\", 1);\n" + + " }\n" + + "}\n" + + "class A {\n" + + " public A (Map m) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public X(Map m) { // should warn about raw type m\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " m.put(\"one\", 1); // warns about raw method invocation (good)\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " public A (Map m) {\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n", + null, + false, + compilerOptions15, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338011 +public void test338011b() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + compilerOptions15.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X extends A {\n" + + " public X(Map m) { // should warn about raw type m\n" + + " super(m);\n" + + " m.put(\"one\", 1); // warns about raw method invocation (good)\n" + + " }\n" + + " public X(Map m, boolean b) {\n" + + " super(m); // shows that parametrizing the parameter type is no problem \n" + + " new A(m);\n" + + " m.put(\"one\", 1);\n" + + " }\n" + + "}\n" + + "class A {\n" + + " public A (Map m) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public X(Map m) { // should warn about raw type m\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " m.put(\"one\", 1); // warns about raw method invocation (good)\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " public A (Map m) {\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n", + null, + false, + compilerOptions15, + null); +} +// 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 {\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. 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"); +} +// 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 {\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; 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; 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; 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; 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; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478e() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " X.Y<> [] y = null; \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X.Y<> [] y = null; \n" + + " ^^^^^^^^^^^\n" + + "Incorrect number of arguments for type X.Y; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478f() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " X.Y<> y = null; \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X.Y<> y = null; \n" + + " ^^^^^^^^^^^\n" + + "Incorrect number of arguments for type X.Y; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478g() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478h() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Object x) throws X.Y<>.LException {\n" + + " }\n" + + " static class Y {\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 {\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; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478j() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478k() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478l() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478m() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478n() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +public void test339478o() { + String log_18 = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X<>(){\n" + + " ^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n"; + String log_9 = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " void newMethod(){\n" + + " ^^^^^^^^^^^\n" + + "The method newMethod() of type new X(){} must override or implement a supertype method\n" + + "----------\n"; + String errorMsg = this.complianceLevel < ClassFileConstants.JDK9 ? log_18 : log_9; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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": + errorMsg); +} +public void test339478p() { + String log_18 = + "----------\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 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"; + String log_9 = + "----------\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 should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " X Test = new X<>(){\n" + + " void newMethod(){\n" + + " }\n" + + " }.testFunction(\"SUCCESS\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from void to X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " void newMethod(){\n" + + " ^^^^^^^^^^^\n" + + "The method newMethod() of type new X(){} must override or implement a supertype method\n" + + "----------\n"; + String errorMsg = this.complianceLevel < ClassFileConstants.JDK9 ? log_18 : log_9; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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 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" : + errorMsg); +} +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

{}\n" + + "class Y implements Super{}\n" + + "interface II extends Super{}\n" + + "class S extends Y {}\n" + + "interface T extends II{}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " S s = null;\n" + + " T 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" + + " ^^^^^\n" + + "Cannot cast from S to T\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " t = (T) s; //casting to raw type, no error\n" + + " ^^^^^\n" + + "Type safety: The expression of type T needs unchecked conversion to conform to T\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " t = (T) s; //casting to raw type, no error\n" + + " ^^^^^\n" + + "Type safety: The expression of type T needs unchecked conversion to conform to T\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " t = (T) s; //casting to raw type, no error\n" + + " ^\n" + + "T is a raw type. References to generic type T 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 {\n" + + " public abstract Object foo(T x);\n" + + " public Integer foo(String x){ return 1; }\n" + + "}\n" + + "public class X extends C {\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 {\n" + + " public abstract Integer foo(T x);\n" + + " public Object foo(String x){ return 1; }\n" + + "}\n" + + "public class X extends C {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X extends C {\n" + + " ^\n" + + "The type X must implement the inherited abstract method C.foo(String) to override C.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 {\n" + + " public abstract Object foo(T x);\n" + + "}\n" + + "abstract class C extends B {\n" + + " public Integer foo(String x){ return 1; }\n" + + "}\n" + + "public class X extends C {\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 {\n" + + " public abstract Integer foo(T x);\n" + + "}\n" + + "abstract class C extends B {\n" + + " public Object foo(String x){ return 1; }\n" + + "}\n" + + "public class X extends C {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public class X extends C {\n" + + " ^\n" + + "The type X must implement the inherited abstract method B.foo(String) to override C.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 {\n" + + " public abstract Object foo(T x);\n" + + " public static Integer foo(String x){ return 1; }\n" + + "}\n" + + "public class X extends C {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X extends C {\n" + + " ^\n" + + "The static method foo(String) conflicts with the abstract method in C\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 extends A {} \n" + + "class F> {\n" + + " static > F g() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " F> f011 = F.g();\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " F> f011 = F.g();\n" + + " ^\n" + + "B is a raw type. References to generic type B should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " F> f011 = F.g();\n" + + " ^\n" + + "B is a raw type. References to generic type B 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> { }\n" + + " class B> {\n" + + " D> x;\n" + + " }\n" + + " class D> {}\n" + + " > X(E x, D>> 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 {\n" + + " class A> {\n" + + " B> x;\n" + + " }\n" + + " class B> {}\n" + + " boolean b = ((A)null).x == ((B>>)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 {\n" + + " class A> {\n" + + " B> x;\n" + + " }\n" + + " class B> {}\n" + + " boolean b = ((A>)null).x == ((B>>)null); \n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=283353 +public void test283353() { + String source = + "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" + + " , K extends EntityKey> void condense(K entityKey) {\n" + + " }\n" + + " }\n" + + " public class EntityKey {}\n" + + " public interface EntityType<\n" + + " I,\n" + + " E extends EntityType,\n" + + " K extends EntityKey> {\n" + + " }\n" + + "}\n"; + + runNegativeTest( + new String[] { "X.java", source }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " EntityKey entityKey = null;\n" + + " ^^^^^^^^^\n" + + "X.EntityKey is a raw type. References to generic type X.EntityKey should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " new EntityCondenser().condense(entityKey); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation condense(X.EntityKey) of the generic method condense(K) of type X.EntityCondenser\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 extends A {} \n" + + "class D extends B {}\n" + + "class E extends B {}\n" + + "public class X, U extends B> { \n" + + " public static , U1 extends B> X getX() {\n" + + " return null;\n" + + " }\n" + + " X f = getX(); \n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " X f = getX(); \n" + + " ^\n" + + "B is a raw type. References to generic type B 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> {}\n" + + " class B> extends D {}\n" + + " class C {}\n" + + " class D {}\n" + + " class E>> {}\n" + + " , V extends B, W extends A> W foo(E e) {\n" + + " return goo(e);\n" + + " }\n" + + "

, Q extends B, R extends A> R goo(E

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 {\n" + + " class X2 {}\n" + + " public static void main(String[] args) {\n" + + " X.X2<> x = new X().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.X2<> x = new X().new X2<>();\n" + + " ^^^^^^^^^^^^\n" + + "Incorrect number of arguments for type X.X2; it cannot be parameterized with arguments <>\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " X.X2<> x = new X().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 {\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; 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"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=366131 +public void test366131() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class Range> {\n" + + " public boolean containsNC(T value) {\n" + + " return false;\n" + + " }\n" + + "}\n" + + "class NumberRange> extends Range {\n" + + " public boolean contains(Comparable value) {\n" + + " return castTo((Class) null).containsNC((Comparable) null);\n" + + " }\n" + + " public > NumberRange\n" + + "castTo(Class type) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=366131 +public void test366131b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "class Range> {\n" + + " public boolean containsNC(T value) {\n" + + " return false;\n" + + " }\n" + + "}\n" + + "class NumberRange> extends Range {\n" + + " public boolean contains(Comparable value) {\n" + + " return castTo((Class) null).containsNC((Comparable) null);\n" + + " }\n" + + " public > NumberRange\n" + + "castTo(Class type) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " return castTo((Class) null).containsNC((Comparable) null);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation castTo(Class) of the generic method castTo(Class) of type NumberRange\n" + + "----------\n" + + "3. WARNING in X.java (at line 13)\n" + + " return castTo((Class) null).containsNC((Comparable) null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method containsNC(Comparable) belongs to the raw type Range. References to generic type Range should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " return castTo((Class) null).containsNC((Comparable) null);\n" + + " ^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type safety: The expression of type Class needs unchecked conversion to conform to Class>>\n" + : + "Type safety: The expression of type Class needs unchecked conversion to conform to Class&Number>&Number>\n" + ) + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " return castTo((Class) null).containsNC((Comparable) null);\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 13)\n" + + " return castTo((Class) null).containsNC((Comparable) null);\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375394 +public void test375394() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "public class X {\n" + + " static > boolean foo(C1 c, C2 c2) {\n" + + " return foo(c2,c); \n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return foo(c2,c); \n" + + " ^^^\n" + + "Bound mismatch: The generic method foo(C1, C2) of type X is not applicable for the arguments (C2, C1). The inferred type C1 is not a valid substitute for the bounded parameter >\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return foo(c2,c); \n" + + " ^^^\n" + + "The method foo(C1, C2) in the type X is not applicable for the arguments (C2, C1)\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=385780 +public void test385780() { + Map customOptions = getCompilerOptions(); + customOptions.put( + CompilerOptions.OPTION_ReportUnusedTypeParameter, + CompilerOptions.ERROR); + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError, + new String[] { + "X.java", + "public class X {\n"+ + "public X() {\n"+ + "}\n"+ + "public void ph(int t) {\n"+ + "}\n"+ + "}\n"+ + "interface doNothingInterface {\n"+ + "}\n"+ + "class doNothing {\n"+ + "public void doNothingMethod() {"+ + "}\n"+ + "}\n"+ + "class noerror {\n"+ + "public void doNothing(T t) {"+ + "}"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "Unused type parameter T\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public X() {\n" + + " ^\n" + + "Unused type parameter S\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " interface doNothingInterface {\n" + + " ^\n" + + "Unused type parameter T\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " public void doNothingMethod() {}\n" + + " ^\n" + + "Unused type parameter T\n" + + "----------\n", + null, true, customOptions); +} + +// https://bugs.eclipse.org/395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation. +// version with intermediate assignment, always worked +public void testBug395002_1() { + runConformTest(new String[] { + "Client.java", + "interface SelfBound, T> {\n" + + "}\n" + + "public class Client {\n" + + " > void foo3(A arg3) {\n" + + " SelfBound var3 = arg3;\n" + + " SelfBound, ?> var4 = var3;\n" + + " }\n" + + "}\n" + }); +} + +// https://bugs.eclipse.org/395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation. +// version with direct assignment to local +public void testBug395002_2() { + runConformTest(new String[] { + "Client.java", + "interface SelfBound, T> {\n" + + "}\n" + + "public class Client {\n" + + " > void foo2(A arg2) {\n" + + " SelfBound, ?> var2 = arg2;\n" + + " }\n" + + "}\n" + }); +} + +// https://bugs.eclipse.org/395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation. +// version with direct assignment to field +public void testBug395002_3() { + runConformTest(new String[] { + "Client.java", + "interface SelfBound, T> {\n" + + "}\n" + + "public class Client> {\n" + + " SelfBound, ?> field2;\n" + + " void foo2(A arg2) {\n" + + " field2 = arg2;\n" + + " }\n" + + "}\n" + }); +} + +// https://bugs.eclipse.org/395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation. +// version with argument passing +public void testBug395002_4() { + runConformTest(new String[] { + "Client.java", + "interface SelfBound, T> {\n" + + "}\n" + + "public class Client> {\n" + + " void bar(SelfBound, ?> argBar) {};\n" + + " void foo2(A arg2) {\n" + + " bar(arg2);\n" + + " }\n" + + "}\n" + }); +} + +// https://bugs.eclipse.org/395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation. +// original problem with invocation of generic type +public void testBug395002_full() { + runConformTest(new String[] { + "Bug.java", + "interface SelfBound, T> {\n" + + "}\n" + + "class Test, Y> {\n" + + "}\n" + + "public class Bug> {\n" + + " public Bug() {\n" + + " new Test>();\n" + + " }\n" + + "}\n" + }); +} + +// https://bugs.eclipse.org/395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation. +// combined version with direct assignment to local + original problem w/ invocation of generic type +public void testBug395002_combined() { + runConformTest(new String[] { + "Client.java", + "interface SelfBound, T> {\n" + + "}\n" + + "class Test, Y> {\n" + + "}\n" + + "public class Client {\n" + + " > void foo2(A arg2) {\n" + + " Object o = new Test>();\n" + + " SelfBound, ?> var2 = arg2;\n" + + " }\n" + + "}\n" + }); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=397888 +public void test397888a() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedTypeParameter, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, + CompilerOptions.ENABLED); + + this.runNegativeTest( + false /*skipJavac */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError, + new String[] { + "X.java", + "/***\n" + + " * @param \n" + + " */\n" + + "public class X {\n"+ + "/***\n" + + " * @param \n" + + " */\n" + + " public void ph(int i) {\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " public void ph(int i) {\n" + + " ^\n" + + "The value of the parameter i is not used\n" + + "----------\n", + null, true, customOptions); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=397888 +public void test397888b() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedTypeParameter, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, + CompilerOptions.DISABLED); + + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError, + new String[] { + "X.java", + "/***\n" + + " * @param \n" + + " */\n" + + "public class X {\n"+ + "/***\n" + + " * @param \n" + + " */\n" + + "public void ph() {\n"+ + "}\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X {\n" + + " ^\n" + + "Unused type parameter T\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public void ph() {\n" + + " ^\n" + + "Unused type parameter S\n" + + "----------\n", + null, true, customOptions); +} +// Bug 401456 - Code compiles from javac/intellij, but fails from eclipse +public void test401456() { + runConformTest( + new String[] { + "App.java", + "import java.util.List;\n" + + "\n" + + "public class App {\n" + + "\n" + + " public interface Command_1 {\n" + + " public void execute(T o);\n" + + " }\n" + + " public static class ObservableEventWithArg {\n" + + " public class Monitor {\n" + + " public Object addListener(final Command_1 l) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " }\n" + + " public static class Context {\n" + + " public ObservableEventWithArg.Monitor getSubmissionErrorEventMonitor() {\n" + + " return new ObservableEventWithArg().new Monitor();\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " compileError(new Context>());\n" + + " }\n" + + "\n" + + " private static void compileError(Context context) {\n" + + " context.getSubmissionErrorEventMonitor().addListener(\n" + // here the inner message send bogusly resolved to ObservableEventWithArg#RAW.Monitor + " new Command_1() {\n" + + " public void execute(String o) {\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/405706 - Eclipse compiler fails to give compiler error when return type is a inferred generic +// original test +public void testBug405706a() { + runNegativeTest( + new String[] { + "TypeUnsafe.java", + "import java.util.Collection;\n" + + "\n" + + "public class TypeUnsafe {\n" + + " public static >\n" + + " CollectionType\n" + + " nullAsCollection(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Collection integers = nullAsCollection(String.class);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in TypeUnsafe.java (at line 12)\n" + + " Collection integers = nullAsCollection(String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Collection to Collection\n" + + "----------\n"); +} +// https://bugs.eclipse.org/405706 - Eclipse compiler fails to give compiler error when return type is a inferred generic +// include compatibility List <: Collection +public void testBug405706b() { + runNegativeTest( + new String[] { + "TypeUnsafe.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "\n" + + "public class TypeUnsafe {\n" + + " public static >\n" + + " CollectionType\n" + + " nullAsList(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Collection integers = nullAsList(String.class);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in TypeUnsafe.java (at line 13)\n" + + " Collection integers = nullAsList(String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to Collection\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/408441 - Type mismatch using Arrays.asList with 3 or more implementations of an interface with the interface type as the last parameter +public void testBug408441() { + runConformTest( + new String[] { + "TypeMistmatchIssue.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "\n" + + "public class TypeMistmatchIssue {\n" + + " static interface A {\n" + + " }\n" + + " static class B implements A {\n" + + " }\n" + + " static class C implements A {\n" + + " }\n" + + " static class D implements A {\n" + + " }\n" + + " \n" + + " void illustrate() {\n" + + " List> no1= Arrays.asList(B.class, A.class); // compiles\n" + + " List> no2= Arrays.asList(C.class, B.class, A.class); // compiles\n" + + " List> no3= Arrays.asList(D.class, B.class, A.class); // compiles\n" + + " \n" + + " List> no4= Arrays.asList(D.class, C.class, B.class, A.class); // cannot convert error !!!\n" + + "\n" + + " List> no5= Arrays.asList(A.class, B.class, C.class, D.class); // compiles\n" + + " List> no6= Arrays.asList(A.class, D.class, C.class, B.class); // compiles\n" + + " }\n" + + "}\n" + }); +} + +// https://bugs.eclipse.org/413958 - Function override returning inherited Generic Type +public void testBug413958_1() { + runConformTest( + new String[] { + "TestA.java", + "public class TestA { }\n", + "TestB.java", + "public class TestB { }\n", + "ReadOnlyWrapper.java", + "@SuppressWarnings(\"unchecked\")\n" + + "public class ReadOnlyWrapper {\n" + + " protected A a;\n" + + " protected B b;\n" + + " public ReadOnlyWrapper(A ax,B bx){\n" + + " this.a = ax;\n" + + " this.b = bx;\n" + + " }\n" + + " public > X copy() {\n" + + " return (X) new ReadOnlyWrapper(a,b);\n" + + " }\n" + + " public > X icopy() {\n" + + " return (X) new ReadOnlyWrapper(a,b);\n" + + " }\n" + + " public A getA() {\n" + + " return this.a;\n" + + " }\n" + + " public B getB() {\n" + + " return this.b;\n" + + " }\n" + + "}", + "WritableWrapper.java", + "@SuppressWarnings(\"unchecked\")\n" + + "public class WritableWrapper extends ReadOnlyWrapper {\n" + + " public WritableWrapper(A ax,B bx){\n" + + " super(ax,bx);\n" + + " }\n" + + " @Override\n" + + " public > X copy() {\n" + + " return (X) new WritableWrapper(a,b);\n" + + " }\n" + + " @Override\n" + + " public > X icopy() {\n" + + " // Works in Indigo, Fails in Kepler\n" + + " return (X) new WritableWrapper(a,b);\n" + + " }\n" + + " public void setA(A ax) {\n" + + " this.a = ax;\n" + + " }\n" + + " public void setB(B bx) {\n" + + " this.b = bx;\n" + + " }\n" + + "}\n", + "TestGenerics.java", + "public class TestGenerics {\n" + + " public static void main(String [] args) {\n" + + " final WritableWrapper v1 = new WritableWrapper(new TestA(), new TestB());\n" + + " final WritableWrapper v2 = v1.copy();\n" + + " final WritableWrapper v3 = v1.icopy();\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/413958 - Function override returning inherited Generic Type +// Passing since https://bugs.eclipse.org/423496 +public void testBug413958_2() { + String[] sourceFiles = + new String[] { + "TestA.java", + "public class TestA { }\n", + "TestB.java", + "public class TestB { }\n", + "TestA2.java", + "public class TestA2 extends TestA { }\n", + "ReadOnlyWrapper.java", + "@SuppressWarnings(\"unchecked\")\n" + + "public class ReadOnlyWrapper {\n" + + " protected A a;\n" + + " protected B b;\n" + + " public ReadOnlyWrapper(A ax,B bx){\n" + + " this.a = ax;\n" + + " this.b = bx;\n" + + " }\n" + + " public > X copy() {\n" + + " return (X) new ReadOnlyWrapper(a,b);\n" + + " }\n" + + " public > X icopy() {\n" + + " return (X) new ReadOnlyWrapper(a,b);\n" + + " }\n" + + " public > X icopy2(TA in) {\n" + + " return (X) new ReadOnlyWrapper(a,b);\n" + + " }\n" + + " public A getA() {\n" + + " return this.a;\n" + + " }\n" + + " public B getB() {\n" + + " return this.b;\n" + + " }\n" + + "}", + "WritableWrapper.java", + "@SuppressWarnings(\"unchecked\")\n" + + "public class WritableWrapper extends ReadOnlyWrapper {\n" + + " public WritableWrapper(A ax,B bx){\n" + + " super(ax,bx);\n" + + " }\n" + + " @Override\n" + + " public > X copy() {\n" + + " return (X) new WritableWrapper(a,b);\n" + + " }\n" + + " @Override\n" + + " public > X icopy() {\n" + + " return (X) new WritableWrapper(a,b);\n" + + " }\n" + + " @Override\n" + + " public > X icopy2(TA in) {\n" + + " return (X) new WritableWrapper(a,b);\n" + + " }\n" + + " public void setA(A ax) {\n" + + " this.a = ax;\n" + + " }\n" + + " public void setB(B bx) {\n" + + " this.b = bx;\n" + + " }\n" + + "}\n", + "TestGenerics.java", + "public class TestGenerics {\n" + + " public static void main(String [] args) {\n" + + " final WritableWrapper v1 = new WritableWrapper(new TestA(), new TestB());\n" + + " final WritableWrapper v2 = v1.copy();\n" + + " final WritableWrapper v3 = v1.icopy();\n" + + " final WritableWrapper v4 = v1.icopy();\n" + + " final WritableWrapper v5 = v1.icopy2(new TestA2());\n" + + " }\n" + + "}\n" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_8) + runNegativeTest( + sourceFiles, + "----------\n" + + "1. ERROR in TestGenerics.java (at line 6)\n" + + " final WritableWrapper v4 = v1.icopy();\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from ReadOnlyWrapper to WritableWrapper\n" + + "----------\n"); + else + runConformTest(sourceFiles); +} +public void testBug415734() { + String compileSrc = + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class Compile {\n" + + "\n" + + " public > Exp typedNull() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public void call() {\n" + + " ArrayList list = typedNull();\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runNegativeTest( + false /* skipJavac */, + JavacTestOptions.EclipseHasABug.EclipseBug428061, + new String[] { + "Compile.java", + compileSrc + }, + "----------\n" + + "1. ERROR in Compile.java (at line 11)\n" + + " ArrayList list = typedNull();\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to ArrayList\n" + + "----------\n"); + } else { + runConformTest( + new String[] { + "Compile.java", + compileSrc + }); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426534, [1.8][compiler] Accessibility of vararg element type not checked for generic methods. +public void test426534() { + runNegativeTest( + new String[] { + "p/B.java", + "package p;\n" + + "class A {\n" + + "}\n" + + "public class B extends A {\n" + + " public void foo(T ... o) { }\n" + + "}\n", + + "X.java", + "import p.*;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new B().foo(null, null);\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new B().foo(null, null);\n" + + " ^^^\n" + + "The method foo(T...) of type B is not applicable as the formal varargs element type T is not accessible here\n" + + "----------\n" : + "----------\n" + + "1. WARNING in p\\B.java (at line 5)\n" + + " public void foo(T ... o) { }\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter o\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new B().foo(null, null);\n" + + " ^^^\n" + + "The method foo(T...) of type B is not applicable as the formal varargs element type T is not accessible here\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426589, [1.8][compiler] Compiler error with generic method/constructor invocation as vargs argument +public void test426589() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void take(String... strings) {\n" + + " }\n" + + " void test() {\n" + + " take(getString());\n" + + " }\n" + + " private String getString() {\n" + + " return \"hi\";\n" + + " }\n" + + "}\n" + }, + ""); +} +public void testBug426590() { + runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " \n" + + " }\n" + + " \n" + + " class B extends A {\n" + + " \n" + + " }\n" + + " \n" + + " class C extends B {\n" + + " \n" + + " }\n" + + " \n" + + " class D {\n" + + " D(A a) {\n" + + " \n" + + " }\n" + + " \n" + + " D(boolean b) {\n" + + " this(b ? new B() : new C());\n" + + " }\n" + + " }\n" + }); +} +public void testBug426590b() { + runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " \n" + + " }\n" + + " \n" + + " class B extends A {\n" + + " \n" + + " }\n" + + " \n" + + " class C extends B {\n" + + " \n" + + " }\n" + + " \n" + + " class D {\n" + + " void bla(boolean b) {\n" + + " test(b ? new B() : new C());\n" + + " }\n" + + " \n" + + " void test(A a) {\n" + + " \n" + + " }\n" + + " }\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426633, [1.8][compiler] Compiler generates code that invokes inapplicable method. +public void test426633() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo (T... p);\n" + + "}\n" + + "abstract class A implements I {\n" + + " public void foo(Object [] p) {}\n" + + "}\n" + + "public class X extends A {\n" + + " public static void main(String[] args) {\n" + + " A a = new X();\n" + + " a.foo(\"hello\", \"world\");\n" + + " }\n" + + "}\n" + + }, + this.complianceLevel >= ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo (T... p);\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter p\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " public void foo(Object [] p) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " a.foo(\"hello\", \"world\");\n" + + " ^^^\n" + + "The method foo(Object[]) in the type A is not applicable for the arguments (String, String)\n" + + "----------\n" : + this.complianceLevel >= ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo (T... p);\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter p\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " public void foo(Object [] p) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public void foo(Object [] p) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426633, [1.8][compiler] Compiler generates code that invokes inapplicable method. +public void test426633a() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo (T... p);\n" + + "}\n" + + "abstract class A {\n" + + " public void foo(Object [] p) {\n" + + " System.out.println(\"A.foo\");\n" + + " }\n" + + "}\n" + + "abstract class B extends A implements I {\n" + + "}\n" + + "public class X extends B implements I {\n" + + " public static void main(String[] args) {\n" + + " B b = new X();\n" + + " b.foo(\"hello\", \"world\");\n" + + " }\n" + + "}\n" + }, + this.complianceLevel >= ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo (T... p);\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter p\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " abstract class B extends A implements I {\n" + + " ^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " public class X extends B implements I {\n" + + " ^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " b.foo(\"hello\", \"world\");\n" + + " ^^^\n" + + "The method foo(T...) of type I cannot be invoked as it is overridden by an inapplicable method\n" + + "----------\n" : + this.complianceLevel >= ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo (T... p);\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter p\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " abstract class B extends A implements I {\n" + + " ^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " public class X extends B implements I {\n" + + " ^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n" : + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " abstract class B extends A implements I {\n" + + " ^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " public class X extends B implements I {\n" + + " ^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426633, [1.8][compiler] Compiler generates code that invokes inapplicable method. +public void test426633b() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo (T... p);\n" + + "}\n" + + "abstract class A {\n" + + " public abstract void foo(Object [] p);\n" + + "}\n" + + "abstract class B extends A implements I {\n" + + "}\n" + + "public abstract class X extends B implements I {\n" + + " public static void main(B b) {\n" + + " b.foo(\"hello\", \"world\");\n" + + " }\n" + + "}\n" + }, + this.complianceLevel >= ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo (T... p);\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter p\n" + + "----------\n" : ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426678, [1.8][compiler] Another issue with vararg type element accessibility +public void test426678() { + runNegativeTest( + new String[] { + "X.java", + "import p.*;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new B().foo(null, null);\n" + + " }\n" + + "}\n", + + "p/B.java", + "package p;\n" + + "class A {\n" + + "}\n" + + "public class B extends A {\n" + + " public void foo(T ... o) { System.out.println(\"PGMB\"); }\n" + + " public void foo(Object... o) { System.out.println(\"MB\"); }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new B().foo(null, null);\n" + + " ^^^\n" + + "The method foo(T...) of type B is not applicable as the formal varargs element type T is not accessible here\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new B().foo(null, null);\n" + + " ^^^\n" + + "The method foo(T...) of type B is not applicable as the formal varargs element type T is not accessible here\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\B.java (at line 5)\n" + + " public void foo(T ... o) { System.out.println(\"PGMB\"); }\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter o\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426678, [1.8][compiler] Another issue with vararg type element accessibility +public void test426678a() { + runConformTest( + new String[] { + "X.java", + "import p.*;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new B().foo(null, null);\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + "}\n", + "p/B.java", + "package p;\n" + + "public class B extends A {\n" + + " public void foo(T ... o) { System.out.println(\"PGMB\"); }\n" + + " public void foo(Object... o) { System.out.println(\"MB\"); }\n" + + "}\n", + }, + "PGMB"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421922, [1.8][compiler] Varargs & Overload - Align to JLS8 +public void test421922() { + runNegativeTest( + new String[] { + "X.java", + "import p.*;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new B().foo(null, null);\n" + + " }\n" + + "}\n", + + "p/B.java", + "package p;\n" + + "interface A {\n" + + "}\n" + + "public class B implements A {\n" + + " public void foo(T ... o) { System.out.println(\"PGMB\"); }\n" + + " public void foo(Object... o) { System.out.println(\"MB\"); }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new B().foo(null, null);\n" + + " ^^^\n" + + "The method foo(T...) of type B is not applicable as the formal varargs element type T is not accessible here\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new B().foo(null, null);\n" + + " ^^^\n" + + "The method foo(T...) of type B is not applicable as the formal varargs element type T is not accessible here\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\B.java (at line 5)\n" + + " public void foo(T ... o) { System.out.println(\"PGMB\"); }\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter o\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425719, [1.8][compiler] Bogus ambiguous call error from compiler. +public void test425719() { + String interfaceMethod = this.complianceLevel < ClassFileConstants.JDK1_8 ? + " void foo(List list);\n" : + " default void foo(List list) {\n" + + " System.out.println(\"interface method\");\n" + + " }\n"; + + runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "interface I {\n" + + interfaceMethod + + "}\n" + + "class Base {\n" + + " public void foo(List list) {\n" + + " System.out.println(\"class method\");\n" + + " }\n" + + "}\n" + + "public class X extends Base implements I {\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(new ArrayList());\n" + + " }\n" + + "}\n", + }, + "class method"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425719, [1.8][compiler] Bogus ambiguous call error from compiler. +public void test425719a() { + String interfaceMethod = this.complianceLevel < ClassFileConstants.JDK1_8 ? + " void foo(List list);\n\n\n" : + " default void foo(List list) {\n" + + " System.out.println(\"interface method\");\n" + + " }\n"; + + runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "interface I {\n" + + interfaceMethod + + "}\n" + + "abstract class Base {\n" + + " public abstract void foo(List list);\n" + + "}\n" + + "public abstract class X extends Base implements I {\n" + + " public static void main(String argv[]) {\n" + + " X x = new Y();\n" + + " x.foo(new ArrayList());\n" + + " }\n" + + "}\n" + + "class Y extends X {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " class Y extends X {}\n" + + " ^\n" + + "The type Y must implement the inherited abstract method Base.foo(List)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425719, [1.8][compiler] Bogus ambiguous call error from compiler. +public void test425719b() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + String interfaceMethod = this.complianceLevel < ClassFileConstants.JDK1_8 ? + " void foo(List list);\n\n\n" : + " default void foo(List list) {\n" + + " System.out.println(\"interface method\");\n" + + " }\n"; + + runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "interface I {\n" + + interfaceMethod + + "}\n" + + "abstract class Base {\n" + + " public abstract void foo(List list);\n" + + "}\n" + + "public abstract class X extends Base implements I {\n" + + " public static void main(String argv[]) {\n" + + " X x = new Y();\n" + + " x.foo(new ArrayList());\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " public void foo(List list) {\n" + + " System.out.println(\"Y.foo\");\n" + + " }\n" + + "}\n", + }, + "Y.foo"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427282, Internal compiler error: java.lang.ArrayIndexOutOfBoundsException: -1 at org.eclipse.jdt.internal.compiler.ClassFile.traverse +public void test427282() { + runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "import java.util.Collection;\n" + + "public class X {\n" + + " public X(String... a) {\n" + + " }\n" + + " public static T[] a(T[] a, T[] b) {\n" + + " return null;\n" + + " }\n" + + " public static void error() {\n" + + " final Collection as = null;\n" + + " for (X a : as) {\n" + + " new X(X.a(new String[0], new String[0]));\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " for (X a : as) {\n" + + " ^^\n" + + "Null pointer access: The variable as can only be null at this location\n" + + "----------\n"); +} +public void testBug427216() { + runConformTest( + new String[] { + "Test.java", + "public class Test\n" + + "{\n" + + " public static void main(String[] args)\n" + + " {\n" + + " foo(args); // ok in 1.7 and 1.8\n" + + " foo(java.util.Arrays.asList(\"1\").toArray(new String[0]));\n" + + " System.out.println(\"good\");\n" + + " }\n" + + "\n" + + " private static void foo(String... args) { }\n" + + "}\n" + }, + "good"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427433, NPE at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:4755) +public void testBug427433() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void testError() {\n" + + " assertEquals(A.e(null, null, null), null);\n" + + " }\n" + + " public static boolean assertEquals(String a, String b) {\n" + + " return false;\n" + + " }\n" + + " public static boolean assertEquals(Object a, Object b) {\n" + + " return false;\n" + + " }\n" + + "}\n" + + "class A {\n" + + " public static V e(T[] t, V[] v, T object) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427433, NPE at org.eclipse.jdt.internal.compiler.lookup.Scope.parameterCompatibilityLevel(Scope.java:4755) +// variant to challenge a varargs invocation +public void testBug427433b() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void testError() {\n" + + " assertEquals(A.e(null, null, null), null);\n" + + " }\n" + + " public static boolean assertEquals(String a, String b, X... xs) {\n" + + " return false;\n" + + " }\n" + + " public static boolean assertEquals(Object a, Object b, X... xs) {\n" + + " return false;\n" + + " }\n" + + "}\n" + + "class A {\n" + + " public static V e(T[] t, V[] v, T object) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427438#c3, [1.8][compiler] NPE at org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.generateCode +public void testBug427438c3() { + runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " boolean b;\n" + + " public List getLignes() {\n" + + " return (List) data(b ? (Serializable) get() : null);\n" + + " }\n" + + " public List get() {\n" + + " return null;\n" + + " }\n" + + " public T data(T data) {\n" + + " return data;\n" + + " }\n" + + " public class A implements Serializable {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " return (List) data(b ? (Serializable) get() : null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Serializable to List\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " public class A implements Serializable {\n" + + " ^\n" + + "The serializable class A does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427411, [1.8][generics] JDT reports type mismatch when using method that returns generic type +public void test427411() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + "\n" + + " public static void main() {\n" + + + " List list = null;\n" + + " Object o = null;\n" + + + " genericMethod(list, genericClassTransformer(genericClassFactory(o)));\n" + + + " genericMethod(list, genericClassFactory(o)); // works\n" + + + " GenericClass> tempVariable = genericClassTransformer(genericClassFactory(o));\n" + + + " GenericClass> tempVariable2 = genericClassFactory(o); // works\n" + + + " }\n" + + + " private static void genericMethod(T param1, GenericClass param2) {\n" + + " throw new UnsupportedOperationException();\n" + + " }\n" + + + " public static GenericClass> genericClassFactory(T item) {\n" + + " throw new UnsupportedOperationException();\n" + + " }\n" + + + " public static GenericClass genericClassTransformer(GenericClass matcher) {\n" + + " throw new UnsupportedOperationException();\n" + + " }\n" + + + " private static class GenericClass {\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427728, [1.8] Type Inference rejects calls requiring boxing/unboxing +public void test427728() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int foo(T t) {\n" + + " return 1234;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(foo(10));\n" + + " }\n" + + " static void goo(Integer i) {\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n" + }, + "1234"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427728, [1.8] Type Inference rejects calls requiring boxing/unboxing +public void test427728a() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.Collections;\n" + + "public class X {\n" + + " public static void mai(String[] args) {\n" + + " Math.max(2345, java.util.Collections.max(Collections.emptySet()));\n" + + " Math.max(0, java.util.Collections.max(Collections.emptySet()));\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427736, [1.8][generics] Method not applicable error with identical parameter types +public void test427736() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + runNegativeTest( + new String[] { + "Test1.java", + "class Test1 {\n" + + " static class Node {}\n" + + " void keySet(V v) {}\n" + + " /**\n" + + " * See {@link #keySet() keySet()},\n" + + " */\n" + + " class KeySetView {}\n" + + " static void untree0(Node hi) {} \n" + + " void untreesomething(Node n) {\n" + + " untree0(n); \n" + + " }\n" + + "}\n" + }, + "", null, true, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426836, [1.8] special handling for return type in references to method getClass() ? +public void test426836() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static T id(T t) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Class id = id(new X().getClass());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Class id = id(new X().getClass());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428071, [1.8][compiler] Bogus error about incompatible return type during override +public void test428071() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + runNegativeTest( + new String[] { + "K1.java", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "interface K1 {\n" + + " public Map get();\n" + + "}\n", + "K.java", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "public class K implements K1 {\n" + + " public Map get() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in K1.java (at line 4)\n" + + " public Map get();\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in K.java (at line 4)\n" + + " public Map get() {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n", + null, + true, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428019, [1.8][compiler] Type inference failures with nested generic invocation. +public void test428019() { + runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + " static class Obj {}\n" + + " static class Dial {}\n" + + " static void foo(Dial dial, X context) {\n" + + " context.put(Dial.class, wrap(dial));\n" + + " }\n" + + " void put(Class clazz, T data) {\n" + + " System.out.println(\"put\");\n" + + " }\n" + + " static Dial wrap(Dial dl) {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.foo(new Dial(), new X());\n" + + " }\n" + + "}\n" + }, + "put"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428285, [1.8][compiler] ECJ fails to recognize ? super Object == { Object } +public void test428285() { + runConformTest( + new String[] { + "X.java", + "class Reference {\n" + + " ReferenceQueue queue;\n" + + "}\n" + + "class ReferenceQueue {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Reference r = new Reference();\n" + + " ReferenceQueue q = r.queue;\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK"); +} +public void testBug428366() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void m(String s, int i) {}\n" + + " void m(String s1, String s2) {}\n" + + " void test() {\n" + + " m(\"1\", null);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test429733b() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " test(id(1.1d));\n" + + " }\n" + + " static void test(S value) {\n" + + " System.out.println(value);\n" + + " }\n" + + " static T id(T t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + "1.1"); +} +public void test429733c() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X();\n" + + " }\n" + + " X(S value) {\n" + + " System.out.println(value);\n" + + " }\n" + + " static T id(T t) {\n" + + " return t;\n" + + " }\n" + + " X() {\n" + + " this(id(1.1d));\n" + + " }\n" + + "}\n" + }, + "1.1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426537, [1.8][inference] Eclipse compiler thinks I is compatible with I> - raw type J involved +public void testBug426537() { // non generic case + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(J[] list, I> i) {\n" + + " sort(list, i);\n" + + " }\n" + + " J[] sort(J[] list, I i) {\n" + + " return list;\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo(J[] list, I> i) {\n" + + " ^\n" + + "J is a raw type. References to generic type J should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " sort(list, i);\n" + + " ^^^^\n" + + "The method sort(J[], I) in the type X is not applicable for the arguments (J[], I>)\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " J[] sort(J[] list, I i) {\n" + + " ^\n" + + "J is a raw type. References to generic type J should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " J[] sort(J[] list, I i) {\n" + + " ^\n" + + "J is a raw type. References to generic type J should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 5)\n" + + " J[] sort(J[] list, I i) {\n" + + " ^\n" + + "J is a raw type. References to generic type J should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426537, [1.8][inference] Eclipse compiler thinks I is compatible with I> - raw type J involved +public void testBug426537_generic() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(J[] list, I> i) {\n" + + " sort(list, i);\n" + + " }\n" + + " T[] sort(T[] list, I i) {\n" + + " return list;\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo(J[] list, I> i) {\n" + + " ^\n" + + "J is a raw type. References to generic type J should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " sort(list, i);\n" + + " ^^^^\n" + + "The method sort(T[], I) in the type X is not applicable for the arguments (J[], I>)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427957, [1.8] Type inference incorrect when a wildcard is missing +public void testBug427957() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void sort(T[] a, I c) { }\n" + + " void foo(I[] e, I> comp) {\n" + + " sort(e, comp);\n" + + " }\n" + + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo(I[] e, I> comp) {\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " sort(e, comp);\n" + + " ^^^^\n" + + "The method sort(T[], I) in the type X is not applicable for the arguments (I[], I>)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427992, [1.8] compiler difference to javac involving a raw array +public void test427992() { + if (this.complianceLevel < ClassFileConstants.JDK1_6) + return; // uses @Override + runNegativeTest( + new String[] { + "X.java", + "import static org.junit.Assert.assertArrayEquals;\n" + + "import java.util.Arrays;\n" + + "import org.junit.Test;\n" + + "public class X {\n" + + " @Test(expected = IllegalArgumentException.class)\n" + + " public void shouldThrowExceptionWhenClassesAreNotInSameInheritanceTree() {\n" + + " Arrays.sort(new Class[] {Chimp.class, Cat.class}, ClassInheritanceDepthComparator.INSTANCE);\n" + + " }\n" + + " public static class Animal {\n" + + " }\n" + + " public static class Monkey extends Animal {\n" + + " }\n" + + " public static class Chimp extends Monkey {\n" + + " }\n" + + " public static class Cat extends Animal {\n" + + " }\n" + + "public static class ClassInheritanceDepthComparator implements Comparator> {\n" + + " public static final ClassInheritanceDepthComparator INSTANCE = new ClassInheritanceDepthComparator();\n" + + " @Override\n" + + " public int compare(Class c1, Class c2) {\n" + + " if(c1.equals(c2)) {\n" + + " return 0;\n" + + " }\n" + + " if(c1.isAssignableFrom(c2)) {\n" + + " return -1;\n" + + " }\n" + + " if(c2.isAssignableFrom(c1)) {\n" + + " return 1;\n" + + " }\n" + + " throw new IllegalArgumentException(\"classes to compare must be in the same inheritance tree: \" + c1 + \"; \" + c2);\n" + + " }\n" + + "}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static org.junit.Assert.assertArrayEquals;\n" + + " ^^^^^^^^^\n" + + "The import org.junit cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " import org.junit.Test;\n" + + " ^^^^^^^^^\n" + + "The import org.junit cannot be resolved\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " @Test(expected = IllegalArgumentException.class)\n" + + " ^^^^\n" + + "Test cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Arrays.sort(new Class[] {Chimp.class, Cat.class}, ClassInheritanceDepthComparator.INSTANCE);\n" + + " ^^^^\n" + + "The method sort(T[], Comparator) in the type Arrays is not applicable for the arguments (Class[], X.ClassInheritanceDepthComparator)\n" + + "----------\n" + + "5. ERROR in X.java (at line 17)\n" + + " public static class ClassInheritanceDepthComparator implements Comparator> {\n" + + " ^^^^^^^^^^\n" + + "Comparator cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 20)\n" + + " public int compare(Class c1, Class c2) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method compare(Class, Class) of type X.ClassInheritanceDepthComparator must override or implement a supertype method\n" + + "----------\n"); +} +public void testBug430987() { + String source = + "public class X {\n" + + "\n" + + " public static interface Foo {\n" + + " // no content\n" + + " }\n" + + "\n" + + " public void compileError() {\n" + + " doSomethingWithFoo( any( Foo.class ), any( Foo.class ) );\n" + + " }\n" + + "\n" + + " public void noCompileError() {\n" + + " Foo foo = any( Foo.class );\n" + + " doSomethingWithFoo( foo, foo );\n" + + " }\n" + + "\n" + + " public void fix() {\n" + + " this.doSomethingWithFoo( any( Foo.class ), any( Foo.class ) );\n" + + " }\n" + + "\n" + + " public void doSomethingWithFoo( Foo foo, Foo foo2 ) {\n" + + " // do something\n" + + " }\n" + + "\n" + + " public static T any(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "\n" + + "}\n"; + runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " doSomethingWithFoo( any( Foo.class ), any( Foo.class ) );\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doSomethingWithFoo(X.Foo, X.Foo) of the generic method doSomethingWithFoo(X.Foo, X.Foo) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " doSomethingWithFoo( any( Foo.class ), any( Foo.class ) );\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo needs unchecked conversion to conform to X.Foo\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " doSomethingWithFoo( any( Foo.class ), any( Foo.class ) );\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo needs unchecked conversion to conform to X.Foo\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " Foo foo = any( Foo.class );\n" + + " ^^^\n" + + "X.Foo is a raw type. References to generic type X.Foo should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " doSomethingWithFoo( foo, foo );\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doSomethingWithFoo(X.Foo, X.Foo) of the generic method doSomethingWithFoo(X.Foo, X.Foo) of type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 13)\n" + + " doSomethingWithFoo( foo, foo );\n" + + " ^^^\n" + + "Type safety: The expression of type X.Foo needs unchecked conversion to conform to X.Foo\n" + + "----------\n" + + "7. WARNING in X.java (at line 13)\n" + + " doSomethingWithFoo( foo, foo );\n" + + " ^^^\n" + + "Type safety: The expression of type X.Foo needs unchecked conversion to conform to X.Foo\n" + + "----------\n" + + "8. WARNING in X.java (at line 17)\n" + + " this.doSomethingWithFoo( any( Foo.class ), any( Foo.class ) );\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doSomethingWithFoo(X.Foo, X.Foo) of the generic method doSomethingWithFoo(X.Foo, X.Foo) of type X\n" + + "----------\n" + + "9. WARNING in X.java (at line 17)\n" + + " this.doSomethingWithFoo( any( Foo.class ), any( Foo.class ) );\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo needs unchecked conversion to conform to X.Foo\n" + + "----------\n" + + "10. WARNING in X.java (at line 17)\n" + + " this.doSomethingWithFoo( any( Foo.class ), any( Foo.class ) );\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type X.Foo needs unchecked conversion to conform to X.Foo\n" + + "----------\n"); +} +public void testBug430686() { + runConformTest( + new String[] { + "TestClass.java", + "\n" + + "public class TestClass\n" + + "{\n" + + " private static class Alice, B extends Bob>\n" + + " {\n" + + " }\n" + + "\n" + + " public static class Bob\n" + + " {\n" + + " }\n" + + "\n" + + " public void callingMethod()\n" + + " {\n" + + " calledMethod(); // error: The method calledMethod() in the type TestClass is not applicable for the arguments ()\n" + + " }\n" + + "\n" + + " private , B extends Bob> A calledMethod()\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug430759() { + runConformTest( + new String[] { + "A.java", + "class CriteriaBuilder {\n" + + "\n" + + "}\n" + + "\n" + + "class CriteriaQuery {\n" + + "\n" + + "}\n" + + "\n" + + "class Root {\n" + + "\n" + + "}\n" + + "\n" + + "public class A {\n" + + "\n" + + " protected abstract class CustomGenericQuery {\n" + + " }\n" + + "\n" + + " protected T executeCustomSingleQuery(CustomGenericQuery customQuery, Class resultClass) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public Long getCount() {\n" + + " return executeCustomSingleQuery(\n" + + "\n" + + " new CustomGenericQuery() {\n" + + " public void customizeQuery(final Root root, final CriteriaBuilder cb,\n" + + " CriteriaQuery cq) {\n" + + " }\n" + + " }, Long.class);\n" + + " }\n" + + "}\n" + }); +} +public void testBug431408() { + runConformTest( + new String[] { + "EclipseJava8Generics.java", + "public class EclipseJava8Generics {\n" + + "\n" + + " public interface Foo {\n" + + " }\n" + + "\n" + + " public static class FooBar> {\n" + + " }\n" + + "\n" + + " public static class BaseClass {\n" + + " protected FooBar> doSomething() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static class DerivedClass extends BaseClass {\n" + + " @Override\n" + + " protected FooBar> doSomething() {\n" + + " //Eclipse 4.3.2 with Java 8 can't compile the next line \n" + + " FooBar> prop = super.doSomething();\n" + + " return prop;\n" + + " }\n" + + " }\n" + + "}\n" + }); +} + +public void testBug431581() { + runNegativeTest( + new String[] { + "BugEclipse.java", + "public class BugEclipse\n" + + "{\n" + + " static Dog dog = new Dog();\n" + + " public static void main(String[] args)\n" + + " {\n" + + " System.out.println(\"bug compile eclipse\");\n" + + " Cat cat = getDog(); // <- error here, eclipse compile this line but the execution print ClassCastException\n" + + " }\n" + + " public static T getDog()\n" + + " {\n" + + " return (T) dog;\n" + + " }\n" + + " static class Cat {\n" + + " }\n" + + " static class Dog {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in BugEclipse.java (at line 7)\n" + + " Cat cat = getDog(); // <- error here, eclipse compile this line but the execution print ClassCastException\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + " ^^^^^^\n" + + "Bound mismatch: The generic method getDog() of type BugEclipse is not applicable for the arguments (). The inferred type BugEclipse.Cat&BugEclipse.Dog is not a valid substitute for the bounded parameter \n" + : + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from BugEclipse.Dog to BugEclipse.Cat\n" + ) + + "----------\n" + + "2. WARNING in BugEclipse.java (at line 11)\n" + + " return (T) dog;\n" + + " ^^^^^^^\n" + + "Type safety: Unchecked cast from BugEclipse.Dog to T\n" + + "----------\n"); +} +public void testBug432603() { + runNegativeTest( + new String[] { + "Test.java", + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "abstract class Optional {\n" + + " public static Optional fromNullable(T t) { return null; }\n" + + " abstract Optional or(Optional secondChoice);\n" + + " abstract T or(Supplier supplier);\n" + + " abstract T or(T defaultValue);\n" + + "}\n" + + "\n" + + "interface Supplier { T get(); }\n" + + "\n" + + "public class Test {\n" + + "\n" + + " private static final Object NO_VALUE = new Object();\n" + + "\n" + + " public void method(Map map) {\n" + + " for (Entry entry : map.entrySet()) {\n" + + " Optional.fromNullable(entry.getValue()).or(NO_VALUE);\n" + + "// ^^ error here\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 19)\n" + + " Optional.fromNullable(entry.getValue()).or(NO_VALUE);\n" + + " ^^\n" + + "The method or(Optional) in the type Optional is not applicable for the arguments (Object)\n" + + "----------\n", + JavacTestOptions.Excuse.JavacCompilesIncorrectSource); +} +public void testBug432603a() { + runConformTest( + new String[] { + "Test.java", + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "abstract class Optional {\n" + + " public static Optional fromNullable(T t) { return null; }\n" + + " abstract Optional or(Optional secondChoice);\n" + + " abstract T or(Supplier supplier);\n" + + " abstract T or(T defaultValue);\n" + + "}\n" + + "\n" + + "interface Supplier { T get(); }\n" + + "\n" + + "public class Test {\n" + + "\n" + + " private static final Object NO_VALUE = new Object();\n" + + "\n" + + " public void method(Map map) {\n" + + " for (Entry entry : map.entrySet()) {\n" + + " Optional.fromNullable(entry.getValue()).or(NO_VALUE);\n" + + "// ^^ error here\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +public void testBug399527() { + runNegativeTest( + false /*skipJavac */, + JavacTestOptions.Excuse.JavacCompilesIncorrectSource, + new String[] { + "TypeInferenceProblem.java", + "\n" + + "public class TypeInferenceProblem {\n" + + " interface HeaderAccess {\n" + + " T getHeader();\n" + + " }\n" + + "\n" + + " interface IExpectationSetters {\n" + + " IExpectationSetters andReturn(T value);\n" + + " }\n" + + "\n" + + " static class MocksControl implements IExpectationSetters {\n" + + " public IExpectationSetters andReturn(Object value) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public static IExpectationSetters expect(final T value) {\n" + + " return (IExpectationSetters) new MocksControl();\n" + + " }\n" + + "\n" + + " private HeaderAccess mockHeaderAccess;\n" + + " private HeaderAccess unboundedMockHeaderAccess;\n" + + "\n" + + " public void test() {\n" + + " // No error\n" + + " expect(mockHeaderAccess.getHeader()).andReturn(new Object());\n" + + " /*\n" + + " * Error: The method andReturn(capture#1-of ?) in the type\n" + + " * TypeInferenceProblem.IExpectationSetters \n" + + " * is not applicable for the arguments (Object)\n" + + " */\n" + + " expect(unboundedMockHeaderAccess.getHeader()).andReturn(new Object());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in TypeInferenceProblem.java (at line 33)\n" + + " expect(unboundedMockHeaderAccess.getHeader()).andReturn(new Object());\n" + + " ^^^^^^^^^\n" + + "The method andReturn(capture#1-of ?) in the type TypeInferenceProblem.IExpectationSetters is not applicable for the arguments (Object)\n" + + "----------\n"); +} +public void testBug399527_corrected() { + runConformTest( + new String[] { + "TypeInferenceProblem.java", + "\n" + + "public class TypeInferenceProblem {\n" + + " interface HeaderAccess {\n" + + " T getHeader();\n" + + " }\n" + + "\n" + + " interface IExpectationSetters {\n" + + " IExpectationSetters andReturn(T value);\n" + + " }\n" + + "\n" + + " static class MocksControl implements IExpectationSetters {\n" + + " public IExpectationSetters andReturn(Object value) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public static IExpectationSetters expect(final T value) {\n" + + " return (IExpectationSetters) new MocksControl();\n" + + " }\n" + + "\n" + + " private HeaderAccess mockHeaderAccess;\n" + + " private HeaderAccess unboundedMockHeaderAccess;\n" + + "\n" + + " public void test() {\n" + + " // No error\n" + + " expect(mockHeaderAccess.getHeader()).andReturn(new Object());\n" + + " this.expect(unboundedMockHeaderAccess.getHeader()).andReturn(new Object());\n" + + " }\n" + + "}\n" + }); +} +public void testBug399527_comment1() { + String sourceString = + "public class TypeInferenceProblemMin {\n" + + " interface HeaderAccess {\n" + + " T getHeader();\n" + + " }\n" + + "\n" + + " interface IExpectationSetters {\n" + + " }\n" + + "\n" + + " public static IExpectationSetters expect(final T value) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " private HeaderAccess unboundedMockHeaderAccess;\n" + + " \n" + + " public void test() {\n" + + " // no error:\n" + + " Object header = unboundedMockHeaderAccess.getHeader();\n" + + " IExpectationSetters exp1 = expect(header);\n" + + "\n" + + " // Type mismatch: cannot convert from TypeInferenceProblemMin.IExpectationSetters to TypeInferenceProblemMin.IExpectationSetters\n" + + " IExpectationSetters exp2 = expect(unboundedMockHeaderAccess.getHeader());\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) + runNegativeTest( + new String[] { + "TypeInferenceProblemMin.java", + sourceString + }, + "----------\n" + + "1. ERROR in TypeInferenceProblemMin.java (at line 21)\n" + + " IExpectationSetters exp2 = expect(unboundedMockHeaderAccess.getHeader());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from TypeInferenceProblemMin.IExpectationSetters to TypeInferenceProblemMin.IExpectationSetters\n" + + "----------\n"); + else + // conform due to target typing + runConformTest( + new String[] { + "TypeInferenceProblemMin.java", + sourceString + }); +} +public void testBug434570() { + runConformTest( + new String[] { + "example/Example.java", + "package example;\n" + + "\n" + + "import example.Example.Config;\n" + + "import example.Example.CustomInitializer;\n" + + "\n" + + "@Config(initializers = CustomInitializer.class)\n" + + "public class Example {\n" + + "\n" + + " static interface Context {\n" + + " }\n" + + "\n" + + " static interface ConfigurableContext extends Context {\n" + + " }\n" + + "\n" + + " static abstract class AbstractContext implements ConfigurableContext {\n" + + " }\n" + + "\n" + + " static class GenericContext extends AbstractContext {\n" + + " }\n" + + "\n" + + " static interface Initializer {\n" + + " }\n" + + "\n" + + " static @interface Config {\n" + + " Class>[] initializers() default {};\n" + + " }\n" + + "\n" + + " static class CustomInitializer implements Initializer {\n" + + " }\n" + + "\n" + + " @Config(initializers = CustomInitializer.class)\n" + + " static class CompilationSuccess {\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug434630() { + runConformTest( + new String[] { + "Foo.java", + "interface Provider {}\n" + + "@interface ProvidedBy {\n" + + " Class> value();" + + "}\n" + + "\n" + + "@ProvidedBy(Foo.SomeProvider.class)\n" + + "public interface Foo {\n" + + " \n" + + " public static class SomeProvider implements Provider {\n" + + "\n" + + " public Foo get() {\n" + + " return null;\n" + + " }\n" + + " \n" + + " }\n" + + "}\n" + }); +} +public void testBug434570_comment3() { + runConformTest( + new String[] { + "TestWontCompile.java", + "import org.bug.AnnotationWithClassParameter;\n" + + "import org.bug.CustomHandler;\n" + + "import org.bug.Handler;\n" + + "\n" + + "\n" + + "@AnnotationWithClassParameter(CustomHandler.class)\n" + + "public class TestWontCompile extends ATest {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " Class> h = CustomHandler.class;\n" + + " }\n" + + "\n" + + "}\n", + "ATest.java", + "public abstract class ATest {\n" + + "\n" + + "}\n", + "org/bug/Item.java", + "package org.bug;\n" + + "\n" + + "public interface Item {\n" + + "\n" + + "}\n", + "org/bug/CustomItem.java", + "package org.bug;\n" + + "\n" + + "public class CustomItem implements Item {\n" + + "\n" + + "}\n", + "org/bug/Handler.java", + "package org.bug;\n" + + "\n" + + "public abstract class Handler {\n" + + "\n" + + "}\n", + "org/bug/CustomHandler.java", + "package org.bug;\n" + + "\n" + + "public class CustomHandler extends Handler {\n" + + "\n" + + "}\n", + "org/bug/AnnotationWithClassParameter.java", + "package org.bug;\n" + + "\n" + + "import java.lang.annotation.Documented;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Documented\n" + + "public @interface AnnotationWithClassParameter {\n" + + " \n" + + " Class> value();\n" + + "\n" + + "}\n" + }); +} +// same test but with null annotations analysis enabled +public void testBug434570_comment3b() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + runConformTest( + new String[] { + "TestWontCompile.java", + "import org.bug.AnnotationWithClassParameter;\n" + + "import org.bug.CustomHandler;\n" + + "import org.bug.Handler;\n" + + "\n" + + "\n" + + "@AnnotationWithClassParameter(CustomHandler.class)\n" + + "public class TestWontCompile extends ATest {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " Class> h = CustomHandler.class;\n" + + " }\n" + + "\n" + + "}\n", + "ATest.java", + "public abstract class ATest {\n" + + "\n" + + "}\n", + "org/bug/Item.java", + "package org.bug;\n" + + "\n" + + "public interface Item {\n" + + "\n" + + "}\n", + "org/bug/CustomItem.java", + "package org.bug;\n" + + "\n" + + "public class CustomItem implements Item {\n" + + "\n" + + "}\n", + "org/bug/Handler.java", + "package org.bug;\n" + + "\n" + + "public abstract class Handler {\n" + + "\n" + + "}\n", + "org/bug/CustomHandler.java", + "package org.bug;\n" + + "\n" + + "public class CustomHandler extends Handler {\n" + + "\n" + + "}\n", + "org/bug/AnnotationWithClassParameter.java", + "package org.bug;\n" + + "\n" + + "import java.lang.annotation.Documented;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Documented\n" + + "public @interface AnnotationWithClassParameter {\n" + + " \n" + + " Class> value();\n" + + "\n" + + "}\n" + }, + options); +} +public void testBug434630_comment7() { + runConformTest( + new String[] { + "test/FooImpl.java", + "package test;\n" + + "\n" + + "public class FooImpl implements Foo {\n" + + "\n" + + "}\n", + "test/Foo.java", + "package test;\n" + + "interface Provider {}\n" + + "@interface ProvidedBy {\n" + + " Class> value();" + + "}\n" + + "\n" + + "@ProvidedBy(Foo.SomeProvider.class)\n" + + "public interface Foo {\n" + + " \n" + + " public static class SomeProvider implements Provider {\n" + + "\n" + + " public Foo get() {\n" + + " return null;\n" + + " }\n" + + " \n" + + " }\n" + + "}\n" + }); +} +public void testBug434044() { + runConformTest( + new String[] { + "EclipseJava8Generics.java", + "public class EclipseJava8Generics {\n" + + "\n" + + " public interface Foo {\n" + + " public V doFoo();\n" + + " }\n" + + "\n" + + " public static class FooBar> {\n" + + " public T getBar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static class Factory {\n" + + "\n" + + " public static > FooBar createFooBar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static void test() {\n" + + " final FooBar> typedProperty = Factory.createFooBar();\n" + + " //TODO Eclipse Bug 434044\n" + + " final Object propertyValue = typedProperty.getBar().doFoo();\n" + + "\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug434044_comment20() { + runConformTest( + new String[] { + "EclipseJava8Generics.java", + "public class EclipseJava8Generics {\n" + + "\n" + + " public interface Foo {\n" + + " public V doFoo();\n" + + " }\n" + + "\n" + + " public static class FooBar> {\n" + + " public T getBar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static abstract class AbstractFoo implements Foo {\n" + + " }\n" + + "\n" + + " public static class Factory {\n" + + " public static > FooBar createFooBar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static void test() {\n" + + " final FooBar> typedProperty = Factory.createFooBar();\n" + + " //TODO Eclipse Bug 434044 still exists\n" + + " final Object propertyValue = typedProperty.getBar().doFoo();\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug434044_comment36() { + runNegativeTest( + new String[] { + "EclipseJava8Generics.java", + "public class EclipseJava8Generics {\n" + + "\n" + + " public interface Nasty {\n" + + " public Object doFoo(Integer a);\n" + + " }\n" + + " public interface Foo {\n" + + " public V doFoo(String a);\n" + + " }\n" + + "\n" + + " public static class FooBar> {\n" + + " public T getBar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static abstract class AbstractFoo implements Foo, Nasty {\n" + + " }\n" + + "\n" + + " public static class Factory {\n" + + " public static > FooBar createFooBar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static void test() {\n" + + " final FooBar> typedProperty = Factory.createFooBar();\n" + + " //TODO Eclipse Bug 434044 still exists\n" + + " final Object propertyValue = typedProperty.getBar().doFoo(null);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in EclipseJava8Generics.java (at line 28)\n" + + " final Object propertyValue = typedProperty.getBar().doFoo(null);\n" + + " ^^^^^\n" + + "The method doFoo(String) is ambiguous for the type capture#2-of ? extends EclipseJava8Generics.AbstractFoo\n" + + "----------\n"); +} +public void testBug434793() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + runConformTest( + new String[] { + "Outer.java", + "import java.util.*;\n" + + "\n" + + "public class Outer {\n" + + " private static class SingletonList\n" + + " extends AbstractList\n" + + " implements java.util.RandomAccess, java.io.Serializable {\n" + + " public E get(int i) { throw new RuntimeException(); }\n" + + " public int size() { return 0; }\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug435643() { + runConformTest( + new String[] { + "test/Main.java", + "package test;\n" + + "abstract class ASTNode implements Iterable {\n" + + " public T getChild(int i) { return null; }\n" + + "} \n" + + "abstract class List extends ASTNode { }\n" + + "class Joiner {\n" + + " public static Joiner on(String separator) {\n" + + " return null;\n" + + " }\n" + + " String join(Iterable parts) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" + + "class AstFunctions {\n" + + " public static > Function prettyPrint() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class Iterables {\n" + + " public static Iterable transform(final Iterable fromIterable,\n" + + " final Function function) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "interface Function {\n" + + " T apply(F input);\n" + + "}\n" + + "public class Main {\n" + + "\n" + + " String test(ASTNode node, ASTNode rawNode) {\n" + + " rawNode.getChild(0); \n" + + " \n" + + " @SuppressWarnings(\"unchecked\")\n" + + " List> list = (List>) node;\n" + + " return Joiner.on(\", \").join(Iterables.transform(list, AstFunctions.prettyPrint()));\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug438337comment5() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void test() {\n" + + " I18nResource i18nResource = null;\n" + + " }\n" + + "}\n", + "I18nResource.java", + "public interface I18nResource>> extends BusinessObject {}\n", + "Internationalized.java", + "public interface Internationalized>>\n" + + " extends BusinessObject {}\n", + "BusinessObject.java", + "public interface BusinessObject {}\n" + }); +} +public void testBug438337comment3() { + runConformTest( + new String[] { + "PermissionDrivenPresenter.java", + "public abstract class PermissionDrivenPresenter>> extends BasePresenter {\n" + + "\n" + + " public void updatePermissions() {\n" + + " getView().setReadOnly(true);\n" + + " }\n" + + "}\n", + "View.java", + "public interface View

>> { }\n", + "Presenter.java", + "public interface Presenter>> { }\n", + "BaseView.java", + "public abstract class BaseView

>> implements View

{\n" + + " void setReadOnly(boolean f) {}\n" + + "}\n", + "BasePresenter.java", + "public abstract class BasePresenter>> implements Presenter {\n" + + " public V getView() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422832, Class file triggers StackOverflowError when creating type hierarchy +public void testBug422832() { + String path = getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + + "Bug422832ClassFile" + File.separator + "aspose.pdf.jar"; + String[] libs = getDefaultClassPaths(); + int len = libs.length; + System.arraycopy(libs, 0, libs = new String[len+1], 0, len); + libs[len] = path; + runNegativeTest( + new String[] { + "ExampleClass.java", + "public class ExampleClass extends aspose.b.a.a {}\n", + }, + "----------\n" + + "1. ERROR in ExampleClass.java (at line 1)\n" + + " public class ExampleClass extends aspose.b.a.a {}\n" + + " ^^^^^^^^^^^^\n" + + "The hierarchy of the type ExampleClass is inconsistent\n" + + "----------\n", + libs, false); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=416480, Error in bytecode generated by ECJ compiler leads to IncompatibleClassChangeError +public void test416480() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private Runnable cast(T obj) {\n" + + " return obj;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " Runnable runnable = new X().cast(new Object());\n" + + " } catch (ClassCastException c) {\n" + + " System.out.println(\"CCE\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "CCE"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=444024, Type mismatch error in annotation generics assignment which happens "sometimes" +public void test444024() { + this.runConformTest( + new String[] { + "ViewpointOrganisationEntity.java", + "abstract public class ViewpointOrganisationEntity {\n" + + "}\n", + "MetaCombo.java", + "public @interface MetaCombo {\n" + + " Class< ? extends IComboDataSet< ? >> dataSet();\n" + + "}\n", + "IComboDataSet.java", + "public interface IComboDataSet {\n" + + "}\n", + "ContractantTypeLister.java", + "public class ContractantTypeLister implements IComboDataSet {\n" + + "}\n", + "ContractantType.java", + "@MetaCombo(dataSet = ContractantTypeLister.class)\n" + + "public class ContractantType extends ViewpointOrganisationEntity {\n" + + "}\n", + "Contractant.java", + "public class Contractant extends ViewpointOrganisationEntity {\n" + + " @MetaCombo(dataSet = ContractantTypeLister.class)\n" + + " public ContractantType getContractantType() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=440019, [1.8][compiler] Type mismatch error with autoboxing/scalar types (works with 1.6) +public void test440019() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " T get(String name, T defaultValue) { return defaultValue; }\n" + + " void x() {\n" + + " long a1 = get(\"key\", 0);\n" + + " long a3 = get(\"key\", 0L);\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=443596, [1.8][compiler] Failure for overload resolution in case of Generics and Varags +public void test443596() { + this.runNegativeTest( + new String[] { + "X.java", + "public final class X {\n" + + " static interface Predicate { boolean test(T object); }\n" + + " public static Predicate in(Predicate arg) { return null; }\n" + + " public static Predicate and(Predicate... arg) { return null; }\n" + + " public static Predicate and(Predicate arg0, Predicate arg1) { return null; }\n" + + " static class FilteredCollection {\n" + + " Predicate predicate;\n" + + " public void error(Predicate arg) { and(predicate, in(arg)); } // no compile\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "" : + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public static Predicate and(Predicate... arg) { return null; }\n" + + " ^^^\n" + + "Type safety: Potential heap pollution via varargs parameter arg\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=446235, Java8 generics and boxing +public void test446235() { + this.runConformTest( + new String[] { + "IntegerLongBug.java", + "public class IntegerLongBug {\n" + + " public static void main(String ar[]) {\n" + + " Integer number = 1000;\n" + + " long numberLong = number; //compiles fine\n" + + " long num = getNumber(5000); // compilation error\n" + + " }\n" + + " public static T getNumber(T num) {\n" + + " return num;\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=440019, [1.8][compiler] Type mismatch error with autoboxing/scalar types (works with 1.6) +public void test440019_c9() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final int CORE_POOL_SIZE = 3;\n" + + " public static final int KEEP_ALIVE_TIME = 60; // seconds\n" + + " X(final int size, final long ttl){\n" + + " System.out.println(\"size: \" + size + \" \" + \" ttl: \" + ttl);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(CORE_POOL_SIZE, get(KEEP_ALIVE_TIME)); // [1]\n" + + " }\n" + + " public static T get(T value) {\n" + + " return value;\n" + + " }\n" + + "}\n", + }, + "size: 3 ttl: 60"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=446223, [1.8][compiler] Java8 generics eclipse doesn't compile +public void test446223() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String ar[]) {\n" + + " System.out.println(\"hi\");\n" + + " DoNothing();\n" + + " }\n" + + " public interface Interface1 {\n" + + " public void go();\n" + + " }\n" + + " public interface Interface2 {\n" + + " public X go2();\n" + + " }\n" + + " private static & Interface1> void DoNothing() {\n" + + " return;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " public interface Interface2 {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " private static & Interface1> void DoNothing() {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=444334, [1.8][compiler] Compiler generates error instead of warning on unchecked conversion +public void test444334() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static void Main(String[] args) {\n" + + " doSomething(returnClassType(Class.class));\n" + + " doSomething(returnListType(new ArrayList()));\n" + + " }\n" + + " public static void doSomething(Class clazz) {\n" + + " System.out.println(clazz.getSimpleName());\n" + + " }\n" + + " public static T returnClassType(Class clazz) {\n" + + " return null;\n" + + " }\n" + + " public static void doSomething(List list) {\n" + + " System.out.println(list.getClass().getSimpleName());\n" + + " }\n" + + " public static T returnListType(List list) {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " doSomething(returnClassType(Class.class));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doSomething(Class) of the generic method doSomething(Class) of type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " doSomething(returnClassType(Class.class));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " doSomething(returnListType(new ArrayList()));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation doSomething(List) of the generic method doSomething(List) of type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " doSomething(returnListType(new ArrayList()));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " doSomething(returnListType(new ArrayList()));\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=438246, [1.8][compiler] Java 8 static methods compilation error +public void test438246() { + this.runNegativeTest( + new String[] { + "Foo.java", + "import java.util.List;\n" + + "public abstract class Foo\n" + + "{\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public static void doit( List> workers )\n" + + " {\n" + + " doit( workers.toArray( new Foo[workers.size()] ) );\n" + + " }\n" + + " public static void doit( Foo... workers )\n" + + " {\n" + + " }\n" + + "}\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "" : + "----------\n" + + "1. WARNING in Foo.java (at line 9)\n" + + " public static void doit( Foo... workers )\n" + + " ^^^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter workers\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448795, [1.8][compiler] Inference should discriminate between strict and loose modes +public void test448795() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static T element(T [] ta) {\n" + + " return ta[0];\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int x = element(new int [] { 1234 });\n" + // check that autoboxing does not kick in for arrays, i.e engine should not slip into loose mode. + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int x = element(new int [] { 1234 });\n" + + " ^^^^^^^\n" + + "The method element(T[]) in the type X is not applicable for the arguments (int[])\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448795, [1.8][compiler] Inference should discriminate between strict and loose modes +public void test448795a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static T element(int x, T t) {\n" + + " System.out.println(\"Strict\");\n" + + " return t;\n" + + " }\n" + + " static T element(T t1, T t2) {\n" + + " System.out.println(\"Loose\");\n" + + " return t2;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int x = element(10, new Integer(20));\n" + + " }\n" + + "}\n", + }, + "Strict"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448795, [1.8][compiler] Inference should discriminate between strict and loose modes +public void test448795b() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int element(int x, Integer t) {\n" + + " System.out.println(\"non-generic\");\n" + + " return t;\n" + + " }\n" + + " static T element(int t1, T t2) {\n" + + " System.out.println(\"generic\");\n" + + " return t2;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int x = element(10, new Integer(20));\n" + + " }\n" + + "}\n", + }, + "non-generic"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448795, [1.8][compiler] Inference should discriminate between strict and loose modes +public void test448795c() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int element(Integer x, Integer t) {\n" + + " System.out.println(\"non-generic\");\n" + + " return t;\n" + + " }\n" + + " static T element(int t1, T t2) {\n" + + " System.out.println(\"generic\");\n" + + " return t2;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int x = element(10, new Integer(20));\n" + + " }\n" + + "}\n", + }, + "generic"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=434118, [1.8][compiler] Compilation error on generic capture/type inference +public void test434118() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public Object convertFails(Class clazz, String value) {\n" + + " return Enum.valueOf(clazz.asSubclass(Enum.class), value);\n" + + " }\n" + + " public Object convertCompiles(Class clazz, String value) {\n" + + " return Enum.valueOf(clazz.asSubclass(Enum.class), value);\n" + + " }\n" + + " public Object convertCompiles2(Class clazz, String value) {\n" + + " Class enumType = clazz.asSubclass(Enum.class);\n" + + " return Enum.valueOf(enumType, value);\n" + + " }\n" + + "}\n", + }, + ""); +} +public void testBug452194() { + runNegativeTest( + new String[]{ + "test/Main.java", + "package test;\n" + + "\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " EcoreEMap map = new EcoreEMap();\n" + + " map.addUnique(new Object()); //Error here ONLY in 4.4\n" + + " }\n" + + "}\n" + + "\n" + + "interface InternalEList {\n" + + " public void addUnique(E object);\n" + + "}\n" + + "\n" + + "class EcoreEMap implements InternalEList> {\n" + + " public void addUnique(Entry object) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in test\\Main.java (at line 7)\n" + + " EcoreEMap map = new EcoreEMap();\n" + + " ^^^^^^^^^\n" + + "EcoreEMap is a raw type. References to generic type EcoreEMap should be parameterized\n" + + "----------\n" + + "2. WARNING in test\\Main.java (at line 7)\n" + + " EcoreEMap map = new EcoreEMap();\n" + + " ^^^^^^^^^\n" + + "EcoreEMap is a raw type. References to generic type EcoreEMap should be parameterized\n" + + "----------\n" + + "3. ERROR in test\\Main.java (at line 8)\n" + + " map.addUnique(new Object()); //Error here ONLY in 4.4\n" + + " ^^^^^^^^^\n" + + "The method addUnique(Map.Entry) in the type EcoreEMap is not applicable for the arguments (Object)\n" + + "----------\n"); +} +public void testBug454644() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runNegativeTest( + new String[] { + "example/CollectionFactory.java", + "/*\n" + + " * Copyright 2002-2014 the original author or authors.\n" + + " *\n" + + " * Licensed under the Apache License, Version 2.0 (the \"License\");\n" + + " * you may not use this file except in compliance with the License.\n" + + " * You may obtain a copy of the License at\n" + + " *\n" + + " * http://www.apache.org/licenses/LICENSE-2.0\n" + + " *\n" + + " * Unless required by applicable law or agreed to in writing, software\n" + + " * distributed under the License is distributed on an \"AS IS\" BASIS,\n" + + " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + + " * See the License for the specific language governing permissions and\n" + + " * limitations under the License.\n" + + " */\n" + + "\n" + + "package example;\n" + + "\n" + + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.EnumSet;\n" + + "import java.util.LinkedHashSet;\n" + + "import java.util.LinkedList;\n" + + "import java.util.List;\n" + + "import java.util.NavigableSet;\n" + + "import java.util.Set;\n" + + "import java.util.SortedSet;\n" + + "import java.util.TreeSet;\n" + + "\n" + + "/**\n" + + " * The code in this class is taken directly from the Spring Framework for the purpose\n" + + " * of reproducing a bug.\n" + + " *

\n" + + " * Specifically, the code comes from {@code org.springframework.core.CollectionFactory}.\n" + + " *\n" + + " * @author Juergen Hoeller\n" + + " * @author Arjen Poutsma\n" + + " * @author Sam Brannen\n" + + " */\n" + + "public abstract class CollectionFactory {\n" + + "\n" + + " @SuppressWarnings({ \"unchecked\", \"cast\" })\n" + + " public static Collection createApproximateCollection(Object collection, int capacity) {\n" + + " if (collection instanceof LinkedList) {\n" + + " return new LinkedList();\n" + + " }\n" + + " else if (collection instanceof List) {\n" + + " return new ArrayList(capacity);\n" + + " }\n" + + " else if (collection instanceof EnumSet) {\n" + + " // superfluous cast necessary for bug in Eclipse 4.4.1.\n" + + " // return (Collection) EnumSet.copyOf((EnumSet) collection);\n" + + "\n" + + " // Original code which compiles using OpenJDK 1.8.0_40-ea-b11 and IntelliJ IDEA\n" + + " return EnumSet.copyOf((EnumSet) collection);\n" + + " }\n" + + " else if (collection instanceof SortedSet) {\n" + + " return new TreeSet(((SortedSet) collection).comparator());\n" + + " }\n" + + " else {\n" + + " return new LinkedHashSet(capacity);\n" + + " }\n" + + " }\n" + + "\n" + + " public static Collection createCollection(Class collectionClass, Class elementType, int capacity) {\n" + + " if (collectionClass.isInterface()) {\n" + + " if (Set.class.equals(collectionClass) || Collection.class.equals(collectionClass)) {\n" + + " return new LinkedHashSet(capacity);\n" + + " }\n" + + " else if (List.class.equals(collectionClass)) {\n" + + " return new ArrayList(capacity);\n" + + " }\n" + + " else if (SortedSet.class.equals(collectionClass) || NavigableSet.class.equals(collectionClass)) {\n" + + " return new TreeSet();\n" + + " }\n" + + " else {\n" + + " throw new IllegalArgumentException(\"Unsupported Collection interface: \" + collectionClass.getName());\n" + + " }\n" + + " }\n" + + " else if (EnumSet.class.equals(collectionClass)) {\n" + + " // Assert.notNull(elementType, \"Cannot create EnumSet for unknown element type\");\n" + + "\n" + + " // superfluous cast necessary for bug in Eclipse 4.4.1.\n" + + " // return (Collection) EnumSet.noneOf((Class) elementType);\n" + + "\n" + + " // Original code which compiles using OpenJDK 1.8.0_40-ea-b11 and IntelliJ IDEA\n" + + " return EnumSet.noneOf((Class) elementType);\n" + + " }\n" + + " else {\n" + + " if (!Collection.class.isAssignableFrom(collectionClass)) {\n" + + " throw new IllegalArgumentException(\"Unsupported Collection type: \" + collectionClass.getName());\n" + + " }\n" + + " try {\n" + + " return (Collection) collectionClass.newInstance();\n" + + " }\n" + + " catch (Exception ex) {\n" + + " throw new IllegalArgumentException(\n" + + " \"Could not instantiate Collection type: \" + collectionClass.getName(), ex);\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in example\\CollectionFactory.java (at line 42)\n" + + " @SuppressWarnings({ \"unchecked\", \"cast\" })\n" + + " ^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"cast\")\n" + + "----------\n" + + "2. WARNING in example\\CollectionFactory.java (at line 55)\n" + + " return EnumSet.copyOf((EnumSet) collection);\n" + + " ^^^^^^^\n" + + "EnumSet is a raw type. References to generic type EnumSet should be parameterized\n" + + "----------\n" + + "3. WARNING in example\\CollectionFactory.java (at line 87)\n" + + " return EnumSet.noneOf((Class) elementType);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation noneOf(Class) of the generic method noneOf(Class) of type EnumSet\n" + + "----------\n" + + "4. WARNING in example\\CollectionFactory.java (at line 87)\n" + + " return EnumSet.noneOf((Class) elementType);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type EnumSet needs unchecked conversion to conform to Collection\n" + + "----------\n" + + "5. WARNING in example\\CollectionFactory.java (at line 87)\n" + + " return EnumSet.noneOf((Class) elementType);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + : "Type safety: The expression of type Class needs unchecked conversion to conform to Class>>\n") + + "----------\n" + + "6. WARNING in example\\CollectionFactory.java (at line 87)\n" + + " return EnumSet.noneOf((Class) elementType);\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "7. WARNING in example\\CollectionFactory.java (at line 94)\n" + + " return (Collection) collectionClass.newInstance();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from capture#13-of ? to Collection\n" + + "----------\n", + null, true, options); +} +// original test case, documenting existing compiler behavior +public void testBug456459a() { + runNegativeTest( + new String[] { + "EnumTest.java", + "import java.util.EnumSet;\n" + + "public class EnumTest {\n" + + " \n" + + " static enum Cloneables implements Cloneable {\n" + + " One, Two, Three;\n" + + " }\n" + + " \n" + + " public T getOne(Class enumType) {\n" + + " EnumSet set = EnumSet.allOf(enumType);\n" + + " return set.iterator().next();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in EnumTest.java (at line 8)\n" + + " public T getOne(Class enumType) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in EnumTest.java (at line 9)\n" + + " EnumSet set = EnumSet.allOf(enumType);\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends T is not a valid substitute for the bounded parameter > of the type EnumSet\n" + + "----------\n" + + "3. WARNING in EnumTest.java (at line 9)\n" + + " EnumSet set = EnumSet.allOf(enumType);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation allOf(Class) of the generic method allOf(Class) of type EnumSet\n" + + "----------\n" + + "4. WARNING in EnumTest.java (at line 9)\n" + + " EnumSet set = EnumSet.allOf(enumType);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type EnumSet needs unchecked conversion to conform to EnumSet\n" + + "----------\n" + + "5. WARNING in EnumTest.java (at line 9)\n" + + " EnumSet set = EnumSet.allOf(enumType);\n" + + " ^^^^^^^^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class>>\n" + + "----------\n"); +} +// simple conflict introduced by additional wildcard bound +public void testBug456459b() { + runNegativeTest( + new String[] { + "EnumTest.java", + "import java.util.EnumSet;\n" + + "public class EnumTest {\n" + + " \n" + + " static enum Cloneables implements Cloneable {\n" + + " One, Two, Three;\n" + + " }\n" + + " \n" + + " public void getOne(Class enumType) {\n" + + " EnumSet set = null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in EnumTest.java (at line 8)\n" + + " public void getOne(Class enumType) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in EnumTest.java (at line 9)\n" + + " EnumSet set = null;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends EnumTest is not a valid substitute for the bounded parameter > of the type EnumSet\n" + + "----------\n"); +} +// indirect conflict via wildcard's bound's bound. +public void testBug456459c() { + runNegativeTest( + new String[] { + "X.java", + "class A {};\n" + + "class B {};\n" + + "public class X {\n" + + " void m() {\n" + + " X l = null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X l = null;\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends U is not a valid substitute for the bounded parameter of the type X\n" + + "----------\n"); +} +public void testBug456924() { + runConformTest( + new String[] { + "Test1.java", + "class Test1 {\n" + + " > void method1(Class t) {\n" + + " Test2 test2 = getTest2(t);\n" + + " // getTest2(t); // --> no error\n" + + " }\n" + + " > Test2 getTest2(Class t){\n" + + " return null;\n" + + " }\n" + + " \n" + + "}\n" + + "\n", + "Test2.java", + "class Test2>{}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425203, [compiler][1.7][inference] ECJ rejects valid code using bounded wildcards +public void test425203() { + String source = + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "interface MyFunction {\n" + + " Output apply(Input input);\n" + + "}\n" + + "public class Test {\n" + + " public List wrap(MyFunction function, Input input) {\n" + + " return Arrays.asList(function.apply(input));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}"; + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "Test.java", + source, + }, + "----------\n" + + "1. WARNING in Test.java (at line 8)\n" + + " return Arrays.asList(function.apply(input));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of capture#2-of ? extends Output is created for a varargs parameter\n" + + "----------\n" + + "2. ERROR in Test.java (at line 8)\n" + + " return Arrays.asList(function.apply(input));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); + } else { + runConformTest(new String[]{ "Test.java", source }, "Done"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=489636, [1.8] "Bound mismatch" for a generic method parameter +public void test489636() { + this.runConformTest( + new String[] { + "Test.java", + "interface I {\n" + + " I get();\n" + + "}\n" + + "public class Test {\n" + + "\n" + + " @SuppressWarnings(\"unused\")\n" + + " private static > void test(S p) {\n" + + " I i = p.get();\n" + + " test(i); // Bound mismatch\n" + + " }\n" + + "}" + }); +} + +public void testBug498057() { + runConformTest( + new String[] { + "scanner/AbstractScanner.java", + "package scanner;\n" + + "import scanner.AbstractScanner.ScannerModel;\n" + + "public abstract class AbstractScanner> implements Scanner {\n" + + " public void scan(ScanListener listener) {\n" + + " }\n" + + "\n" + + " public static interface ScannerModel extends ScanListener {\n" + + " }\n" + + "}\n" + + "", + "scanner/AbstractSubScanner.java", + "package scanner;\n" + + "import scanner.AbstractScanner.ScannerModel;\n" + + "public abstract class AbstractSubScanner extends AbstractScanner> {\n" + + " @Override\n" + + " public void scan(ScanListener listener) {\n" + + " }\n" + + "}\n" + + "\n" + + "", + "scanner/ScanListener.java", + "package scanner;\n" + + "public interface ScanListener {\n" + + "}\n" + + "\n" + + "", + "scanner/Scanner.java", + "package scanner;\n" + + "\n" + + "public interface Scanner {\n" + + " void scan(ScanListener listener);\n" + + "}\n" + + "", + "scanner/StringScanner.java", + "package scanner;\n" + + "\n" + + "public interface StringScanner extends Scanner {\n" + + "}\n" + + "", + } + ); + runConformTest( + false, + new String[] { + "scanner/ModifyMe.java", + "package scanner;\n" + + "\n" + + "public class ModifyMe extends AbstractSubScanner implements StringScanner {\n" + + "}\n" + + "", + }, + "", + "", + "", + null + ); +} +public void testBug460491_comment23() { + runConformTest( + new String[] { + "PM.java", + "public class PM> {\n" + + " public PM(Class clazz) {\n" + + " }\n" + + "\n" + + " enum MyEnum {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new PM(MyEnum.class);\n" + + " }\n" + + "}\n" + }); +} +public void testBug498486() { + runConformTest( + new String[] { + "t/Ab.java", + "package t;\n" + + "public interface Ab> {}\n" + + "", + "t/At.java", + "package t;\n" + + "public interface At, O extends Ob> {\n" + + "}\n" + + "", + "t/Ob.java", + "package t;\n" + + "public interface Ob, O extends Ob> extends At {\n" + + " interface Id {}\n" + + "}\n" + + "", + } + ); + runConformTest( + false, + new String[] { + "i/Test.java", + "package i;\n" + + "\n" + + "import t.Ab;\n" + + "import t.Ob;\n" + + "\n" + + "\n" + + "public class Test {\n" + + " , O extends Ob, A extends Ab> A // Erroneous compiler error here on the last O\n" + + " m() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "", + }, + null, + null, + null, + null + ); +} +public void testBug499048() { + runConformTest( + new String[] { + "p/Outer.java", + "package p;\n" + + "public class Outer {\n" + + " private static class Inner {}\n" + + " Inner test() {\n" + + " Outer.Inner inner = new Outer.Inner();\n" + + " return inner;\n" + + " }\n" + + "}\n" + }); +} +public void testBug499126() { + runConformTest( + new String[] { + "bug_ise_immutablelist/$Immutable.java", + "package bug_ise_immutablelist;\n" + + "\n" + + "public class $Immutable {\n" + + "}\n" + + "", + "bug_ise_immutablelist/Test.java", + "package bug_ise_immutablelist;\n" + + "\n" + + "public class Test {\n" + + " public static $Immutable f;\n" + + "}\n" + + "", + } + ); + runConformTest( + false, + new String[] { + "Usage.java", + "public class Usage {\n" + + " Object f() {return bug_ise_immutablelist.Test.f;}\n" + + "}\n" + + "", + }, + null, + null, + null, + null + ); +} +public void testBug441905() { + runConformTest( + new String[] { + "EclipseJava8Generics.java", + "import java.util.List;\n" + + "\n" + + "public class EclipseJava8Generics {\n" + + "\n" + + " public interface Foo {\n" + + " }\n" + + "\n" + + " public static class FooBar> {\n" + + " }\n" + + "\n" + + " protected void doFoos(List>> fooBars) {\n" + + " FooBar> fooBar = fooBars.iterator().next();\n" + + " doFoo(fooBar);\n" + + " }\n" + + "\n" + + " protected static void doFoo(FooBar> fooBar) {\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug469297() { + String source = " import java.util.List;\n" + + " \n" + + " public class Test {\n" + + " \n" + + " static final void a(Class> type) {\n" + + " b(newList(type));\n" + + " }\n" + + " \n" + + " static final List b(List list) {\n" + + " return list;\n" + + " }\n" + + " \n" + + " @SuppressWarnings(\"deprecation\")\n" + + " static final > L newList(Class type) {\n" + + " try {\n" + + " return type.newInstance();\n" + + " }\n" + + " catch (Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + " }\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runConformTest(new String[] { "Test.java", source }); + } else { + runNegativeTest(new String[] { "Test.java", source }, + "----------\n" + + "1. ERROR in Test.java (at line 6)\n" + + " b(newList(type));\n" + + " ^\n" + + "The method b(List) in the type Test is not applicable for the arguments (capture#1-of ? extends List)\n" + + "----------\n"); + } +} +public void testBug508799() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.IGNORE); + runConformTest( + new String[] { + "test/A.java", + "package test;\n" + + "\n" + + "public interface A {\n" + + " void a();\n" + + "}\n" + + "", + "test/B1.java", + "package test;\n" + + "\n" + + "public interface B1 extends A {\n" + + " void b1();\n" + + "}\n" + + "", + "test/B2.java", + "package test;\n" + + "\n" + + "public interface B2 extends A {\n" + + " void b2();\n" + + "}\n" + + "", + }, + customOptions + ); + runConformTest(false, + new String[] { + "test/C.java", + "package test;\n" + + "\n" + + "public class C implements B1, B2 {\n" + + " public void a() {\n" + + " }\n" + + "\n" + + " public void b1() {\n" + + " }\n" + + "\n" + + " public void b2() {\n" + + " }\n" + + "}\n" + + "", + }, null, customOptions, "", "", "", null + ); +} +public void testBug515614() { + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "abstract class Generic {\n" + + " interface NestedInterface {\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class X {\n" + + " public static X create(Class vclass) {\n" + + " return vclass == null ? null : null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " X x = X.create(Generic.NestedInterface[].class);\n" + + "}\n" + + "", + } + ); +} +public void testBug518157A() { + runConformTest( + new String[] { + "RawClassParameterizationBug.java", + "class RawClassParameterizationBug {\n" + + "\n" + + " public interface Example {\n" + + " }\n" + + " \n" + + " public static class DefaultExample implements Example {\n" + + " }\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " static final Class fails = DefaultExample.class;\n" + + "}\n" + + "", + } + ); +} +public void testBug518157B() { + runConformTest( + new String[] { + "AlternateRawClassParameterizationBug.java", + "import java.util.Map;\n" + + "\n" + + "class AlternateRawClassParameterizationBug {\n" + + "\n" + + " abstract static class MapEntry implements Map.Entry {\n" + + " }\n" + + "\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " static final Class mapFails = MapEntry.class;\n" + + "\n" + + "}\n" + + "", + } + ); +} +public void testBug521212() { + runNegativeTest( + new String[] { + "X.java", + "class Y {}\n" + + "class Z {}\n" + + "public class X {\n" + + " public static Y one() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public static Y one() {\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type ? extends V is not a valid substitute for the bounded parameter of the type Y\n" + + "----------\n"); +} +public void testBug526423() { + runConformTest( + new String[] { + "test/compileBug/TestCompileBug.java", + "package test.compileBug;\n" + + "\n" + + "import java.util.ArrayList;\n" + + "import java.util.LinkedHashMap;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class TestCompileBug {\n" + + " @SuppressWarnings({ \"rawtypes\" })\n" + + " private static void cannotCompile(Object token) {\n" + + " // change the type to List and ArrayList and it compiles\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " List identityServicesToTokensMap = new ArrayList(((LinkedHashMap) token).entrySet());\n" + + " }\n" + + "}" + } + ); +} +public void testBug526132() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, CompilerOptions.DISABLED); + runNegativeTest( + new String[] { + "Test.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class Test {\n" + + " private Map field = new HashMap();\n" + + " private void method() {\n" + + " field.put(\"key\", \"value\");\n" + + " }\n" + + " private void method() {\n" + + " field.put(\"key\", \"value\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Test.java (at line 4)\n" + + " private Map field = new HashMap();\n" + + " ^^^\n" + + "Map is a raw type. References to generic type Map should be parameterized\n" + + "----------\n" + + "2. WARNING in Test.java (at line 4)\n" + + " private Map field = new HashMap();\n" + + " ^^^^^^^\n" + + "HashMap is a raw type. References to generic type HashMap should be parameterized\n" + + "----------\n" + + "3. ERROR in Test.java (at line 5)\n" + + " private void method() {\n" + + " ^^^^^^^^\n" + + "Duplicate method method() in type Test\n" + + "----------\n" + + "4. WARNING in Test.java (at line 5)\n" + + " private void method() {\n" + + " ^^^^^^^^\n" + + "The method method() from the type Test is never used locally\n" + + "----------\n" + + "5. WARNING in Test.java (at line 6)\n" + + " field.put(\"key\", \"value\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map should be parameterized\n" + + "----------\n" + + "6. ERROR in Test.java (at line 8)\n" + + " private void method() {\n" + + " ^^^^^^^^\n" + + "Duplicate method method() in type Test\n" + + "----------\n" + + "7. WARNING in Test.java (at line 9)\n" + + " field.put(\"key\", \"value\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map should be parameterized\n" + + "----------\n", + null, + true, + customOptions); +} +public void testBug520482() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS, JavaCore.DISABLED); + runConformTest( + new String[] { + "test/A.java", + "package test;\n" + + "\n" + + "import java.util.List;\n" + + "\n" + + "public class A {\n" + + " static List f;\n" + + "}\n", + }, + customOptions + ); + runNegativeTest(false, + new String[] { + "test/B.java", + "package test;\n" + + "\n" + + "public class B extends A {\n" + + " public static test() {\n" + + " f.add(new B());\n" + + " }\n" + + "}\n" + }, + null, + customOptions, + "----------\n" + + "1. ERROR in test\\B.java (at line 4)\n" + + " public static test() {\n" + + " ^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n", + "", "", null + ); +} +public void testBug532137() { + runConformTest( + new String[] { + "subtypes/A.java", + "package subtypes;\n" + + "\n" + + "\n" + + "public abstract class A {\n" + + "\n" + + " public A() {\n" + + "\n" + + " }\n" + + "\n" + + "}\n" + + "", + "subtypes/B.java", + "package subtypes;\n" + + "\n" + + "public abstract class B {\n" + + "\n" + + " public B() {\n" + + "\n" + + " }\n" + + "\n" + + "}\n" + + "", + "subtypes/GenericType.java", + "package subtypes;\n" + + "public abstract class GenericType, RES extends B> {\n" + + "\n" + + "}\n" + + "", + "subtypes/TestBase.java", + "package subtypes;\n" + + "\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "public abstract class TestBase {\n" + + "\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " protected List> giveMeAListOfTypes() {\n" + + " return Collections.emptyList();\n" + + " }\n" + + "\n" + + "}\n" + + "", + } + ); + runNegativeTest( + new String[] { + "subtypes/TestImpl.java", + "package subtypes;\n" + + "\n" + + "import java.util.List;\n" + + "\n" + + "public class TestImpl extends TestBase{\n" + + "\n" + + " @Override\n" + + " protected List> giveMeAListOfTypes() {\n" + + " return super.giveMeAListOfTypes();\n" + + " }\n" + + "}\n" + + "", + }, + "----------\n" + + "1. WARNING in subtypes\\TestImpl.java (at line 8)\n" + + " protected List> giveMeAListOfTypes() {\n" + + " ^^^^^^^^^^^\n" + + "GenericType is a raw type. References to generic type GenericType should be parameterized\n" + + "----------\n", + null, + false + ); +} + +public void testBug540313() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "X/C120644mr.java", + "package X;\n" + + "\n" + + "public class C120644mr extends X.C16280iv {\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X\\C120644mr.java (at line 3)\n" + + " public class C120644mr extends X.C16280iv {\n" + + " ^^^^^^^^^^\n" + + "X.C16280iv cannot be resolved to a type\n" + + "----------\n"; + runner.runNegativeTest(); +} + +public void testBug540313a() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "X/C120644mr.java", + "package X;\n" + + "\n" + + "class Outer {\n" + + " class Inner {}\n" + + "}\n" + + "public class C120644mr extends X.Inner {\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X\\C120644mr.java (at line 6)\n" + + " public class C120644mr extends X.Inner {\n" + + " ^^^^^^^\n" + + "X.Inner cannot be resolved to a type\n" + + "----------\n"; + runner.runNegativeTest(); +} + +public void testBug540313b() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "X/C120644mr.java", + "package X;\n" + + "\n" + + "class Outer {\n" + + " class Inner {}\n" + + "}\n" + + "public class C120644mr {\n" + + " X.Inner inner;\n" + // is this backed by JLS? + "}\n" + }; + runner.runConformTest(); +} +public void testBug478708() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "bug/IInterface.java", + "package bug;\n" + + "\n" + + "public class IInterface {\n" + + "\n" + + "}\n", + "bug/AbstractA.java", + "package bug;\n" + + "\n" + + "public abstract class AbstractA {\n" + + "\n" + + " public abstract class AbstractD {\n" + + "\n" + + " }\n" + + "}\n", + "bug/AbstractC.java", + "package bug;\n" + + "\n" + + "\n" + + "public abstract class AbstractC extends T.AbstractD {\n" + + "\n" + + " public AbstractC(AbstractA a) {\n" + + " a.super();\n" + + " }\n" + + "}\n", + "bug/E.java", + "package bug;\n" + + "\n" + + "public class E {\n" + + "\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in bug\\AbstractC.java (at line 4)\n" + + " public abstract class AbstractC extends T.AbstractD {\n" + + " ^^^^^^^^^^^\n" + + "T.AbstractD cannot be resolved to a type\n" + + "----------\n"; + runner.runNegativeTest(); +} +public void testBug543526() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "C.java", + "class C {\n" + + " > boolean m(T x) {\n" + + " return x instanceof String;\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in C.java (at line 3)\n" + + " return x instanceof String;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types T and String\n" + + "----------\n"; + runner.runNegativeTest(); +} +public void testBug543526b() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "C.java", + "class C {\n" + + " > boolean m(T x) {\n" + + " return x instanceof Comparable;\n" + // no problem casting to an interface + " }\n" + + "}\n" + }; + runner.runConformTest(); +} +public void testBug552388() { + runNegativeTest( + new String[] { + "A.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class A {\n" + + " protected List list = new ArrayList();\n" + + "\n" + + " class C {}\n" + + "\n" + + " public void createIO() {\n" + + " A x = null;\n" + + " List.C> y = x.list;\n" + + " }\n" + + "}\n" + + "\n" + + "class B {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 11)\n" + + " List.C> y = x.list;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from List.C> to List.C>\n" + + "----------\n"); +} +public void testBug552388b() { + String output = this.complianceLevel > ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. ERROR in A.java (at line 17)\n" + + " foo(l);\n" + + " ^^^\n" + + "The method foo(List.C>) in the type A is not applicable for the arguments (List.C>)\n" + + "----------\n" + + "2. ERROR in A.java (at line 33)\n" + + " foo2(l); \n" + + " ^^^^\n" + + "The method foo2(List>) in the type A is not applicable for the arguments (List>)\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in A.java (at line 16)\n" + + " List l = new ArrayList<>();\n" + + " ^^^^^^^^^\n" + + "\'<>\' operator is not allowed for source level below 1.7\n" + + "----------\n" + + "2. ERROR in A.java (at line 17)\n" + + " foo(l);\n" + + " ^^^\n" + + "The method foo(List.C>) in the type A is not applicable for the arguments (List.C>)\n" + + "----------\n" + + "3. ERROR in A.java (at line 32)\n" + + " List> l = new ArrayList<>();\n" + + " ^^^^^^^^^\n" + + "\'<>\' operator is not allowed for source level below 1.7\n" + + "----------\n" + + "4. ERROR in A.java (at line 33)\n" + + " foo2(l); \n" + + " ^^^^\n" + + "The method foo2(List>) in the type A is not applicable for the arguments (List>)\n" + + "----------\n"; + runNegativeTest( + new String[] { + "A.java", + "import java.util.*;\n" + + "class A {\n" + + " class C {\n" + + " T f;\n" + + " }\n" + + " C c = new C();\n" + + " A(T t) {\n" + + " c = new C();\n" + + " c.f = t;\n" + + " }\n" + + " void foo(List.C> list) {\n" + + " list.add(new A(\"\").c);\n" + + " list.add(new A(3).c);\n" + + " }\n" + + " T test() {\n" + + " List l = new ArrayList<>();\n" + + " foo(l);\n" + + " return l.get(0).f;\n" + + " }\n" + + " public static void main(String... args) {\n" + + "// Number n = new A(1).test();\n" + + "// System.out.print(n.intValue());\n" + + " Number n = new A(1).test2();\n" + + " System.out.print(n.intValue());\n" + + " }\n" + + " \n" + + " void foo2(List> list) {\n" + + " list.add(new A(\"\"));\n" + + " list.add(new A(3));\n" + + " }\n" + + " T test2() {\n" + + " List> l = new ArrayList<>();\n" + + " foo2(l); \n" + + " return l.get(0).c.f;\n" + + " }\n" + + " \n" + + "}\n" + }, + output); +} +public void testBug561544() { + if (this.complianceLevel < ClassFileConstants.JDK11) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNAVOIDABLE_GENERIC_TYPE_PROBLEMS, JavaCore.DISABLED); + runNegativeTest(false, + new String[] { + "com/bsbportal/music/C2193c.java", + "package com.bsbportal.music;\n" + + "\n" + + "public class C2193c {\n" + + " java.util.List f6088b;\n" + + " public void onResponse(p594x.C14183r rVar) {\n" + + " mo12821b((java.util.List) this.f6088b);\n" + + " }\n" + + "}\n" + }, + null, + customOptions, + "----------\n" + + "1. WARNING in com\\bsbportal\\music\\C2193c.java (at line 4)\n" + + " java.util.List f6088b;\n" + + " ^^^^^^^^^^^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in com\\bsbportal\\music\\C2193c.java (at line 5)\n" + + " public void onResponse(p594x.C14183r rVar) {\n" + + " ^^^^^\n" + + "p594x cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in com\\bsbportal\\music\\C2193c.java (at line 6)\n" + + " mo12821b((java.util.List) this.f6088b);\n" + + " ^^^^^^^^\n" + + "The method mo12821b(List) is undefined for the type C2193c\n" + + "----------\n" + + "4. WARNING in com\\bsbportal\\music\\C2193c.java (at line 6)\n" + + " mo12821b((java.util.List) this.f6088b);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from List to List\n" + + "----------\n", + "", "", null + ); +} +} + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java new file mode 100644 index 0000000000..de2acc8891 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java @@ -0,0 +1,3087 @@ +/******************************************************************************* + * Copyright (c) 2011, 2016 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) + * Bug 424205 - [1.8] Cannot infer type for diamond type with lambda on method invocation + * Bug 429203 - [1.8][compiler] NPE in AllocationExpression.binding + * Bug 456508 - Unexpected RHS PolyTypeBinding for: + * Bug 462083 - [1.8][inference] Java 8 generic return type mismatch with interface involving type parameter. + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class GenericsRegressionTest_1_7 extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "testBug456508" }; +// 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 {\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" + + "}", + }, + "SUCCESS"); +} +public void test001a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X 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 is not applicable for the arguments (int)\n" + + "----------\n"); +} +public void test001b() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.ArrayList 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 {\n" + + " static java.util.ArrayList 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 {\n" + + " public static void main(String[] args) {\n" + + " java.util.ArrayList 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 is not applicable for the arguments (int)\n" + + "----------\n"); +} +// fields +public void test001c_1() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static java.util.ArrayList 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 is not applicable for the arguments (int)\n" + + "----------\n"); +} +public void test001d() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {" + + " public void ab(ArrayList al){\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X 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) in the type X is not applicable for the arguments (ArrayList)\n" + + "----------\n"); + } else { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {" + + " public void ab(ArrayList al){\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X<>();\n" + + " x.ab(new ArrayList<>());\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } +} +public void test001e() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {" + + " public void ab(ArrayList al){\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X 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) in the type X is not applicable for the arguments (ArrayList)\n" + + "----------\n"); + } else { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "public class X {" + + " public void ab(ArrayList al){\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X<>();\n" + + " x.ab(new ArrayList<>());\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } +} +public void test001f() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class X2{\n" + + " void methodx(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.X2 x = new X<>().new X2<>();\n" + + " x.methodx(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " class X2{\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " X.X2 x = new X<>().new X2<>();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.X2 to X.X2\n" + : + "Cannot infer type arguments for X2<>\n" + ) + + "----------\n"); +} +// fields +public void test001f_1() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class X2{\n" + + " void methodx(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " X.X2 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 {\n" + + " class X2{\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.X2 x = new X<>().new X2<>();\n" + + " x.methodx(\"SUCCESS\",1);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " X.X2 x = new X<>().new X2<>();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.X2 to X.X2\n" + : + "Cannot infer type arguments for X2<>\n" + ) + + "----------\n"); +} +public void test001g_1() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class X2{\n" + + " void methodx(T param, K param2){\n" + + " System.out.println(param);\n" + + " System.out.println(param2);\n" + + " }\n" + + " }\n" + + " X.X2 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 {\n" + + " class X2{\n" + + " void methodx(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.X2 x = new X<>().new X2<>();\n" + + " x.methodx(1);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " class X2{\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " X.X2 x = new X<>().new X2<>();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.X2 to X.X2\n" + : + "Cannot infer type arguments for X2<>\n" + ) + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " x.methodx(1);\n" + + " ^^^^^^^\n" + + "The method methodx(String) in the type X.X2 is not applicable for the arguments (int)\n" + + "----------\n"); +} +public void test001h_1() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class X2{\n" + + " void methodx(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " X.X2 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{\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 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 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.X2. References to generic type X 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.X2 should be parameterized\n" + + "----------\n"); +} +public void test001h_2() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class X2{\n" + + " void methodx(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " }\n" + + " X.X2 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 {\n" + + " class X2{\n" + + " class X22{\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 test = new X<>();" + + " X.X2.X22> 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 test = new X<>(); X.X2.X22> x = new X<>().new X2<>().new X22<>();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.X2.X22> to X.X2.X22>\n" + : + "Cannot infer type arguments for X22<>\n" + ) + + "----------\n"); +} +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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 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 should be parameterized\n" + + "----------\n"); +} +public void test003() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\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 {\n" + + " class X2 {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X<>().new X2<>(){\n" + + " void newMethod(){\n" + + " }\n" + + " };\n" + + " }\n" + + "}", + }, + this.complianceLevel < ClassFileConstants.JDK9 ? + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new X<>().new X2<>(){\n" + + " ^^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " void newMethod(){\n" + + " ^^^^^^^^^^^\n" + + "The method newMethod() of type new X.X2(){} must override or implement a supertype method\n" + + "----------\n"); +} +public void test004c() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class X2 {\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(){\n" + + " void newMethod(){\n" + + " }\n" + + " }.setF(1);\n" + + " }\n" + + "}", + }, + "1"); +} + +public void test006() { + this.runConformTest( + new String[] { + "X.java", + "class X1 {\n" + + " int abc = 1;\n" + + " public void testFunction(T param){\n" + + " System.out.println(param + \"X1\");\n" + + " }\n" + + "}\n" + + "public class X extends X1 {\n" + + " public static void main(String[] args) {\n" + + " X1 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 {\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() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(){\n" + + " }\n" + + " public X(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " public static void testFunction(X 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) in the type X is not applicable for the arguments (X)\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 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\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 should be parameterized\n" + + "----------\n"); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(){\n" + + " }\n" + + " public X(T param){\n" + + " System.out.println(param);\n" + + " }\n" + + " public static void testFunction(X 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" + + "}", + }, + "SUCCESS\n" + + "hello\n" + + "SUCCESS"); + } +} +//shows the difference between using <> and the raw type - different semantics +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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 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 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 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 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 is not applicable for the arguments (String)\n" + + "----------\n"); +} + +public void test0014() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X 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 {\n" + + " public static void main(String[] args) {\n" + + " X 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 is not applicable for the arguments (int, String)\n" + + "----------\n"); +} +public void test0015() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\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 x = new X<>();\n" + + " X 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 {\n" + + " X(){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " X (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" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " X x = new 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 x2 = new 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 {\n" + + " X(){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " X (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 <> cannot be used with explicit type arguments to a generic constructor. +public void test0016b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X x;\n" + + " X x2;\n" + + " X(){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " X (Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X test = new X<>();\n" + + " test.x = new X<>();\n" + + " test.x2 = new X<>(1);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X test = new 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 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 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 {\n" + + " X x;\n" + + " X x2;\n" + + " X(){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " X (Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X 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 {\n" + + " X(int i){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " X (Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X<>(1);\n" + + " X x2 = new X<>(1);\n" + + " Integer i = 1;\n" + + " X x3 = new X<>(i);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " X x2 = new 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 x3 = new 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 {\n" + + " X(int i){\n" + + " System.out.println(\"const.1\");\n" + + " }\n" + + " X (Integer i) {\n" + + " System.out.println(\"const.2\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X<>(1);\n" + + " X x2 = new X<>(1);\n" + + " Integer i = 1;\n" + + " X 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 {\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 {\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 {\n" + + " Zork z;\n" + + " public X(T t) {}\n" + + " int f(X 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() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "class X {\n" + + " public X(T t) {}\n" + + " int f(List 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) in the type X is not applicable for the arguments (ArrayList)\n" + + "----------\n"); + } else { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "class X {\n" + + " public X(T t) {}\n" + + " int f(List p) {return 0;}\n" + + " int x = f(new ArrayList<>());\n" + + "}\n", + }, + ""); + } +} +public void test0022() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "class StringKeyHashMap extends HashMap { \n" + + "}\n" + + "\n" + + "class IntegerValueHashMap extends HashMap { \n" + + "}\n" + + "\n" + + "public class X {\n" + + " Map m1 = new StringKeyHashMap<>();\n" + + " Map 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 extends HashMap { \n" + + "}\n" + + "\n" + + "class IntegerValueHashMap extends HashMap { \n" + + "}\n" + + "\n" + + "public class X {\n" + + " Map m1 = new StringKeyHashMap<>(10);\n" + + " Map m2 = new IntegerValueHashMap<>();\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class StringKeyHashMap extends HashMap { \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 extends HashMap { \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 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 {\n" + + " public X() {}\n" + + " X f(List 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 {\n" + + " public X() {}\n" + + " void f(List p) { Object o = (X) new X<>();}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " void f(List p) { Object o = (X) new X<>();}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot cast from X to X\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 {\n" + + " X(T t) {}\n" + + " X(String s) {}\n" + + " X(List l) {}\n" + + " X idem() { return this; }\n" + + " X x = new X<>(1);\n" + + " X x2 = new X<>(1);\n" + + " List list = new ArrayList<>();\n" + + " X x3 = new X<>(1);\n" + + " X x4 = new X<>(1).idem();\n" + + " X x5 = new X<>(1);\n" + + " int m(X xs) { return 0; }\n" + + " int i = m(new X<>(\"\"));\n" + + " X x6 = new X<>(list);\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " X x = new X<>(1);\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " X x4 = new X<>(1).idem();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " X x5 = new X<>(1);\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " int i = m(new X<>(\"\"));\n" + + " ^\n" + + "The method m(X) in the type X is not applicable for the arguments (X)\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " X x4 = new X<>(1).idem();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X to X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=344655 +public void test0027() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " Y (Integer i) {\n" + + " }\n" + + " }\n" + + "\n" + + " X (Integer i) {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X x = new X<>(1);\n" + + " X x2 = x.new Y<>(1);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X x = new 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 x2 = x.new 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() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " X x = new X<> () {}\n;" + + " class Y {\n" + + " }\n" + + " X.Y y = x.new Y<>() {};\n" + + "}\n" + }; + if (this.complianceLevel < ClassFileConstants.JDK9) { + this.runNegativeTest( + testFiles, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X x = new X<> () {}\n" + + " ^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X.Y y = x.new Y<>() {};\n" + + " ^\n" + + "\'<>\' cannot be used with anonymous classes\n" + + "----------\n"); + } else { + this.runConformTest(testFiles); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345359 +public void test0029() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(T t) {}\n" + + " X f2 = new X<>(new Y()); \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X 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 {\n" + + " I(T t) {}\n" + + " }\n" + + " X.I f = new X().new I<>(new Y()); \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X.I 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 {\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 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 {\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 {\n" + + " static X 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 {\n" + + " static X 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 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 {\n" + + " X(T t) {}\n" + + " X() {}\n" + + " void foo(T a) {\n" + + " System.out.println(a);\n" + + " }\n" + + " class Y{\n" + + " Y(T t,K k) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x1 = new X<>(1,1);\n" + + " X x2 = new X<>(1);\n" + + " X x3 = new X<>();\n" + + " X.Y y1 = new X<>(1,1).new Y<>();\n" + + " X.Y y2 = new X<>(1,1).new Y<>(1);\n" + + " X.Y y3 = new X<>(1).new Y<>(1);\n" + + " X.Y y4 = new X<>(1).new Y<>(\"\",\"\");\n" + + " X.Y y5 = new X<>(1).new Y<>(1,\"\");\n" + + " X.Y y6 = new X<>().new Y<>(1,\"\");\n" + + " X.Y y7 = new X<>().new Y<>(1,1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X 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.Y 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.Y 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.Y 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.Y 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.Y y6 = new X<>().new Y<>(1,\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.Y to X.Y\n" + : + "Cannot infer type arguments for Y<>\n" + ) + + "----------\n" + + "7. ERROR in X.java (at line 20)\n" + + " X.Y y7 = new X<>().new Y<>(1,1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.Y to X.Y\n" + : + "Cannot infer type arguments for Y<>\n" + ) + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0034b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(T t) {}\n" + + " X() {}\n" + + " void foo(T a) {\n" + + " System.out.println(a);\n" + + " }\n" + + " class Y{\n" + + " Y(T t,K k) {}\n" + + " Y(K k) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y y42 = new X<>(\"\").new Y<>(\"\");\n" + + " X.Y y41 = new X<>(\"\").new Y<>(\"\",\"\");\n" + + " X.Y y4 = new X<>(1).new Y<>(\"\",\"\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " X.Y y4 = new X<>(1).new Y<>(\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for Y<>\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0035() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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{\n" + + " @SafeVarargs\n" + + " Y(T t,String abc, K... k) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x1 = new X<>(1,1);\n" + + " X x2 = new X<>(1);\n" + + " X x3 = new X<>();\n" + + " X x4 = new X<>(\"\",\"\");\n" + + " X x5 = new X<>(\"\",\"\",\"\");\n" + + " X x6 = new X<>(\"\",\"\",1);\n" + + " X.Y y1 = new X<>(1,1).new Y<>();\n" + + " X.Y y2 = new X<>(\"\",1).new Y<>(\"\");\n" + + " X.Y y3 = new X<>(1).new Y<>(1);\n" + + " X.Y y4 = new X<>(1).new Y<>(1,\"\");\n" + + " X.Y y5 = new X<>(1).new Y<>(1,\"\",\"\");\n" + + " X.Y y6 = new X<>().new Y<>(1,\"\",1);\n" + + " X.Y y7 = new X<>().new Y<>(\"\",\"\",1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " X 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 x5 = new X<>(\"\",\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X to X\n" + : + "Cannot infer type arguments for X<>\n" + ) + + "----------\n" + + "3. ERROR in X.java (at line 20)\n" + + " X.Y 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.Y 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.Y 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.Y y6 = new X<>().new Y<>(1,\"\",1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.Y to X.Y\n" + : + "Cannot infer type arguments for Y<>\n" + ) + + "----------\n" + + "7. ERROR in X.java (at line 26)\n" + + " X.Y y7 = new X<>().new Y<>(\"\",\"\",1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.Y to X.Y\n" + : + "Cannot infer type arguments for Y<>\n" + ) + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0036() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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{\n" + + " @SafeVarargs\n" + + " Y(T t,String abc, K... k) {}\n" + + " }\n" + + " X x1 = new X<>(1,1);\n" + + " X x2 = new X<>(1);\n" + + " X x3 = new X<>();\n" + + " X x4 = new X<>(\"\",\"\");\n" + + " X x5 = new X<>(\"\",\"\",\"\");\n" + + " X x6 = new X<>(\"\",\"\",1);\n" + + " X.Y y1 = new X<>(1,1).new Y<>();\n" + + " X.Y y2 = new X<>(\"\",1).new Y<>(\"\");\n" + + " X.Y y3 = new X<>(1).new Y<>(1);\n" + + " X.Y y4 = new X<>(1).new Y<>(1,\"\");\n" + + " X.Y y5 = new X<>(1).new Y<>(1,\"\",\"\");\n" + + " X.Y y6 = new X<>().new Y<>(1,\"\",1);\n" + + " X.Y y7 = new X<>().new Y<>(\"\",\"\",1);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " X 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 x5 = new X<>(\"\",\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X to X\n" + : + "Cannot infer type arguments for X<>\n" + ) + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " X.Y 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.Y 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.Y 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.Y y6 = new X<>().new Y<>(1,\"\",1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.Y to X.Y\n" + : + "Cannot infer type arguments for Y<>\n" + ) + + "----------\n" + + "7. ERROR in X.java (at line 25)\n" + + " X.Y y7 = new X<>().new Y<>(\"\",\"\",1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.Y to X.Y\n" + : + "Cannot infer type arguments for Y<>\n" + ) + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0034a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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 x1 = new X<>(1,1);\n" + + " X x2 = new X<>(1);\n" + + " X x3 = new X<>();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " X 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 {\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 x1 = new X<>(1,1);\n" + + " X x2 = new X<>(1);\n" + + " X x3 = new X<>();\n" + + " X x4 = new X<>(\"\",\"\");\n" + + " X x5 = new X<>(\"\",\"\",\"\");\n" + + " X x6 = new X<>(\"\",\"\",1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " X 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 x5 = new X<>(\"\",\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X to X\n" + : + "Cannot infer type arguments for X<>\n" + ) + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0036a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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 x1 = new X<>(1,1);\n" + + " X x2 = new X<>(1);\n" + + " X x3 = new X<>();\n" + + " X x4 = new X<>(\"\",\"\");\n" + + " X x5 = new X<>(\"\",\"\",\"\");\n" + + " X x6 = new X<>(\"\",\"\",1);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " X 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 x5 = new X<>(\"\",\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X to X\n" + : + "Cannot infer type arguments for X<>\n" + ) + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=345559 +public void test0037() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\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{\n" + + " @SafeVarargs\n" + + " Y(T t,String abc, K... k) {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y y1 = new X<>().new Y<>(1);\n" + + " X.Y y2 = new X<>(1).new Y<>(1);\n" + + " X.Y y3 = new X<>(\"\",\"\",1).new Y<>(1);\n" + + " X.Y y4 = new X<>(1,\"\").new Y<>(1,\"\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " X.Y 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.Y 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.Y 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.Y 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 getaMethod();\n" + + " 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 & Serializable> T createObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + ""); +} +public void test0042() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "public class X {\n" + + " > 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 {\n" + + " class Y {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y x1 = new X().new Y(\"\",\"\");\n" + + " X.Y x2 = 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 test0044() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y x = new X<>().new Y<>(\"\",\"\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X.Y x = new X<>().new Y<>(\"\",\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "Type mismatch: cannot convert from X.Y to X.Y\n" + : + "Cannot infer type arguments for Y<>\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 {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y 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 {\n" + + " class Y {\n" + + " Y(T a, Z b) { \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y 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 test0047() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y x1 = new X().new Y(\"\",\"\"); \n" + + " X.Y x2 = new X().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 {\n" + + " X(T t) {\n" + + " }\n" + + " X x = new X<>(\"\"); \n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " 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 {\n" + + " class Y {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y x1 = new X().new Y(new Object(),\"\");\n" + + " X.Y x2 = new X<>().new Y(new Object(),\"\");\n" + + " X.Y x3 = new X().new Y<>(new Object(),\"\");\n" + + " X.Y 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> {\n" + + " class Y {\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y x1 = new X().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> {\n" + + " class Y {\n" + + " Y(Integer a, Z b) {\n" + + " }\n" + + " Y(T a, Z b) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y x1 = new X().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 {\n" + + " X(E e) {}\n" + + " X() {}\n" + + " public static void main(String[] args) {\n" + + " X x = new X(1);\n" + + " X x2 = new X(\"SUCCESS\");\n" + + " X x3 = new X(1);\n" + + " X x4 = new X(new AX());\n" + + " X x5 = new X>(new AX());\n" + + " X x6 = new X>(new AX());\n" + + " X> x7 = new X>();\n" + + " }\n" + + "}\n" + + "class AX{}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X x2 = new X(\"SUCCESS\");\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X x3 = new X(1);\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " X x4 = new X(new AX());\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " X x5 = new X>(new AX());\n" + + " ^\n" + + "Redundant specification of type arguments >\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " X x6 = new X>(new AX());\n" + + " ^\n" + + "Redundant specification of type arguments >\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " X> x7 = new X>();\n" + + " ^\n" + + "Redundant specification of type arguments >\n" + + "----------\n" + : // additional error at line 5 due to better inference: + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X x = new X(1);\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X x2 = new X(\"SUCCESS\");\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " X x3 = new X(1);\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " X x4 = new X(new AX());\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " X x5 = new X>(new AX());\n" + + " ^\n" + + "Redundant specification of type arguments >\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " X x6 = new X>(new AX());\n" + + " ^\n" + + "Redundant specification of type arguments >\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " X> x7 = new X>();\n" + + " ^\n" + + "Redundant specification of type arguments >\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 {\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 x = new X(1);\n" + + " X x2 = new X(\"SUCCESS\");\n" + + " X x22 = new X(1,\"SUCCESS\");\n" + + " X x3 = new X(1);\n" + + " String s = foo(new X(\"aaa\"));\n" + + " String s2 = foo(new X(1,\"aaa\"));\n" + + " }\n" + + " static String foo(X x) {\n" + + " return x.get();\n" + + " }\n" + + "}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " X x2 = new X(\"SUCCESS\");\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " X x22 = new X(1,\"SUCCESS\");\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " X x3 = new X(1);\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " String s = foo(new X(\"aaa\"));\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + : // additional error at line 7 due to better inference + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X x = new X(1);\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " X x2 = new X(\"SUCCESS\");\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " X x22 = new X(1,\"SUCCESS\");\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " X x3 = new X(1);\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " String s = foo(new X(\"aaa\"));\n" + + " ^\n" + + "Redundant specification of type arguments \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 {\n" + + " X(String abc, String def) {}\n" + + " void foo() {\n" + + " X x = new X(\"\",\"\");\n" + + " foo3(new X(\"\",\"\"));\n" + + " }\n" + + " X foo2() {\n" + + " return new X(\"\",\"\");\n" + + " }\n" + + " void foo3(X x) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X x = new X(\"\",\"\");\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return new X(\"\",\"\");\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340747 +public void test0052d() { + 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" + + " X(E e) {}\n" + + " X() {}\n" + + " public static void main(String[] args) {\n" + + " X x = new X(1);\n" + + " }\n" + + "}\n" + + "class AX{}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "" : + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X x = new X(1);\n" + + " ^\n" + + "Redundant specification of type arguments \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 { \n" + + " public static void main(String[] args) {\n" + + " foo(new Z());\n" + + " }\n" + + " static void foo(Z z) {\n" + + " }\n" + + "}\n" + + "class ZB {\n" + + "}" + }, + "----------\n" + + "1. ERROR in Z.java (at line 3)\n" + + " foo(new Z());\n" + + " ^\n" + + "Redundant specification of type arguments \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 {\n" + + " public static Y make(Class clazz) {\n" + + " return new Y();\n" + + " }\n" + + "}\n" + + "class ABC{}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " return new Y();\n" + + " ^\n" + + "Redundant specification of type arguments \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 {\n" + + " class Inner { }\n" + + " static class Inner2 { }\n" + + "\n" + + " void method() {\n" + + " X.Inner a= new X().new Inner();\n" + + " X.Inner a1= new X().new Inner<>();\n" + // do not warn. Removing String from X not possible + " Inner b= new X().new Inner();\n" + + " Inner c= new Inner();\n" + + " X.Inner e= new X().new Inner();\n" + + " X.Inner f= new Inner();\n" + + " X.Inner2 d3 = new X.Inner2();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.Inner a= new X().new Inner();\n" + + " ^^^^^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Inner b= new X().new Inner();\n" + + " ^^^^^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Inner c= new Inner();\n" + + " ^^^^^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " X.Inner e= new X().new Inner();\n" + + " ^^^^^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " X.Inner f= new Inner();\n" + + " ^^^^^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " X.Inner2 d3 = new X.Inner2();\n" + + " ^^^^^^\n" + + "Redundant specification of type arguments \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 {\n" + + " void foo1() {\n" + + " X.Item i = new X().new Item();\n" + + " }\n" + + " void foo2() {\n" + + " X.Item j = new X.Item();\n" + + " }\n" + + " class Item {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X.Item i = new X().new Item();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from X.Item to X.Item\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " X.Item i = new X().new Item();\n" + + " ^^^^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " X.Item j = new X.Item();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Cannot allocate the member type X.Item using a parameterized compound name; use its simple name and an enclosing instance of type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " X.Item j = new X.Item();\n" + + " ^^^^\n" + + "Redundant specification of type arguments \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 {\n" + + " static class X1 {\n" + + " X1(Z z){}\n" + + " }\n" + + " X1 x1 = new X.X1(1);\n" + + " X1 x2 = new X.X1(1);\n" + + "}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X1 x1 = new X.X1(1);\n" + + " ^^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + : // additional error at line 6 due to better inference: + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X1 x1 = new X.X1(1);\n" + + " ^^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X1 x2 = new X.X1(1);\n" + + " ^^\n" + + "Redundant specification of type arguments \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 {\n" + + " X(T t){}\n" + + " class X1 {\n" + + " X1(Z z){}\n" + + " }\n" + + " X.X1 x1 = new X(1).new X1(1);\n" + + "}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.X1 x1 = new X(1).new X1(1);\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + : // additional error (2.) at inner allocation due to better inference: + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X.X1 x1 = new X(1).new X1(1);\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " X.X1 x1 = new X(1).new X1(1);\n" + + " ^^\n" + + "Redundant specification of type arguments \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 p = new InvertedPair();\n" + + " }\n" + + "}\n" + + "class Pair {\n" + + "}\n" + + "class InvertedPair extends Pair {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Pair p = new InvertedPair();\n" + + " ^^^^^^^^^^^^\n" + + "Redundant specification of type arguments \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()\n" + + " : new ArrayList();\n" + + " \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " : new ArrayList();\n" + + " ^^^^^^^^^\n" + + "Redundant specification of type arguments \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 {\n" + + " X(List p) {}\n" + + " Object x = new X((ArrayList) 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; 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; it cannot be parameterized with arguments <>\n" + + "----------\n", + null, + false, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=361441 +public void test0061() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.net.URI;" + + "import java.nio.file.FileSystems;" + + "import java.util.Collections;\n" + + "public class X {\n" + + " public static void foo() {\n" + + " URI uri = URI.create(\"http://www.eclipse.org\");\n" + + " FileSystems.newFileSystem(uri, Collections.emptyMap());\n" + + " }\n" + + "}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " FileSystems.newFileSystem(uri, Collections.emptyMap());\n" + + " ^^^^^^^^^^^^^\n" + + "The method newFileSystem(URI, Map) in the type FileSystems is not applicable for the arguments (URI, Map)\n" + + "----------\n" + : // with better inference, method is applicable, but then we have another problem: + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " FileSystems.newFileSystem(uri, Collections.emptyMap());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " FileSystems.newFileSystem(uri, Collections.emptyMap());\n" + + " ^^^^^^^^^^^^^^\n" + + "Unused type arguments for the non generic method newFileSystem(URI, Map) of type FileSystems; it should not be parameterized with arguments \n" + + "----------\n" + )); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428220, [1.8][compiler] Javadoc processing interferes with type inference. +public void test428220() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + runNegativeTest( + new String[] { + "X.java", + "public class HashMap {\n" + + " static class Node {\n" + + " Node(int hash, K key, V value, Node next) {}\n" + + " }\n" + + " /** @see #put(Object, Object) */\n" + + " public V put(K key, V value) { return null; }\n" + + "\n" + + " Node newNode(int hash, K key, V value, Node next) {\n" + + " return new Node<>(hash, key, value, next); // Error\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class HashMap {\n" + + " ^^^^^^^\n" + + "The public type HashMap must be defined in its own file\n" + + "----------\n", null, true, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428220, [1.8][compiler] Javadoc processing interferes with type inference. +public void test428220a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + runNegativeTest( + new String[] { + "X.java", + "public class HashMap {\n" + + " static class Node {\n" + + " Node(int hash, K key, V value, Node next) {}\n" + + " }\n" + + " /** @see #put(Object, Object) */\n" + + " public V put(K key, V value) { return null; }\n" + + "\n" + + " Node newNode(int hash, K key, V value, Node next) {\n" + + " return new Node<>(hash, key, value, next); // Error\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class HashMap {\n" + + " ^^^^^^^\n" + + "The public type HashMap must be defined in its own file\n" + + "----------\n", null, true, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=442929, [1.8][compiler] ClassCastException during runtime where is no cast +public void test442929() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " shouldNotThrow();\n" + + " }\n" + + " static void shouldNotThrow() {\n" + + " final String[] array = { \"\" };\n" + + " final String[] expected = { \"\" };\n" + + " // throws\n" + + " try {\n" + + " assertThat(op(array, \"\")).isEqualTo(expected);\n" + + " } catch (ClassCastException c) {\n" + + " System.out.println(\"Expected CCE\");\n" + + " }\n" + + " }\n" + + " static T[] op(T[] array, T element) {\n" + + " return asArray(element);\n" + + " }\n" + + " @SafeVarargs\n" + + " static T[] asArray(T... elements) {\n" + + " return elements;\n" + + " }\n" + + " static ObjectArrayAssert assertThat(T actual) {\n" + + " return new ObjectArrayAssert<>(actual);\n" + + " }\n" + + " static class ObjectArrayAssert {\n" + + " ObjectArrayAssert(T actual) {\n" + + " }\n" + + " void isEqualTo(T expected) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "Expected CCE"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448028, [1.8] 1.8 cannot infer type arguments where 1.7 does +public void test448028() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static interface I {/*empty*/}\n" + + "\n" + + " public static class C\n" + + " implements I {/*empty*/}\n" + + "\n" + + " public static class W\n" + + " implements I {\n" + + "\n" + + " // --- problem is triggered only, when there is a vararg-parameter\n" + + " public W(final T t, final Object... o) {\n" + + " super();\n" + + " }\n" + + " }\n" + + "\n" + + " // --- needed to trigger problem\n" + + " public static final T inspect(final T t) {\n" + + " return t;\n" + + " }\n" + + "\n" + + " // --- this compiles ok when having JDK Compilance set to 1.7 !\n" + + " public static final W err1() {\n" + + " final C c = new C();\n" + + " final Object o = new Object();\n" + + " return inspect(new W<>(c, o)); // - ERROR: Cannot infer type arguments for W<> F.java\n" + + " }\n" + + "\n" + + " public static final W wrn1() {\n" + + " final C c = new C();\n" + + " final Object o = new Object();\n" + + " // --- giving the type-parameter yields a warning\n" + + " // --- comparing that to the error of method err1() it does not make much sense\n" + + " return inspect(new W(c, o)); // - WARNING: Redundant specification of type arguments F.java\n" + + " }\n" + + "\n" + + " public static final W ok1() {\n" + + " final C c = new C();\n" + + " // --- no extra vararg-paramaeter\n" + + " return inspect(new W<>(c)); // - OK\n" + + " }\n" + + "\n" + + " public static final W ok2() {\n" + + " final C c = new C();\n" + + " final Object o = new Object();\n" + + " // --- no check-method\n" + + " return new W<>(c, o); // - OK\n" + + " }\n" + + "\n" + + " public static final W ok3() {\n" + + " final C c = new C();\n" + + " // --- no check-method\n" + + " return new W<>(c); // - OK\n" + + " }\n" + + "\n" + + " public static final W ok4() {\n" + + " final C c = new C();\n" + + " final Object o = new Object();\n" + + " // --- this also compiles (my solution for now)\n" + + " final W w = new W<>(c, o);\n" + + " return inspect(w);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 34)\n" + + " return inspect(new W(c, o)); // - WARNING: Redundant specification of type arguments F.java\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n", + null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449619, [1.8][compiler] Qualified <> allocation fails to compile. +public void test449619() { + String source = "public class X {\n" + + " public class Y {\n" + + " }\n" + + " static void foo(Y ys) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X().new Y<>());\n" + + " }\n" + + "}\n"; + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + this.runConformTest( + new String[] { + "X.java", + source, + }, + ""); + else + this.runNegativeTest( + new String[] { + "X.java", + source, + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " foo(new X().new Y<>());\n" + + " ^^^\n" + + "The method foo(X.Y) in the type X is not applicable for the arguments (X.Y)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429733, [1.8][bytecode] Bad type on operand stack +public void test429733() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " test(new Some<>(1.1d));\n" + + " }\n" + + " static void test(Option value) {\n" + + " }\n" + + " static interface Option {\n" + + " }\n" + + " static class Some implements Option {\n" + + " Some(T value) {\n" + + " System.out.println(value);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "1.1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429733, [1.8][bytecode] Bad type on operand stack +public void test429733a() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " test(new Some(1.1d));\n" + + " }\n" + + " static void test(Option value) {\n" + + " }\n" + + " static interface Option {\n" + + " }\n" + + " static class Some implements Option {\n" + + " Some(T value) {\n" + + " System.out.println(value);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "1.1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375394 +public void test375394a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " B, ? extends C> b = new B<>();\n" + + "}\n" + + "class B , V extends U>{}\n" + + "class C {}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " B, ? extends C> b = new B<>();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " B, ? extends C> b = new B<>();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 2)\n" + + " B, ? extends C> b = new B<>();\n" + + " ^\n" + + "C is a raw type. References to generic type C should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427728, [1.8] Type Inference rejects calls requiring boxing/unboxing +public void test427728b() { + runConformTest( + new String[] { + "X.java", + "import java.util.Collections;\n" + + "import java.util.LinkedHashMap;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map map = new LinkedHashMap<>();\n" + + " map.put(null, X.getInt());\n" + + " map.put(null, X.getint());\n" + + " }\n" + + " private static int getInt() {\n" + + " return 0;\n" + + " }\n" + + " private static int getint() {\n" + + " return 0;\n" + + " }\n" + + "}\n" + }, + ""); +} +public void testBug456508() { + runNegativeTest( + new String[] { + "QueryAtom.java", + "public class QueryAtom {\n" + + " public QueryAtom(SingularAttribute path) {\n" + + " }\n" + + "}\n", + "SubqueryIn.java", + "public class SubqueryIn {\n" + + " public SubqueryIn(QueryAtom... subqueryAtoms) {\n" + + " }\n" + + "}\n", + "Test.java", + "class PAccount {}\n" + + "class PGroepAccount {}\n" + + "interface SingularAttribute {}\n" + + "\n" + + "public class Test {\n" + + " public static volatile SingularAttribute account;\n" + + "\n" + + " public void nietInGroep() {\n" + + " recordFilter(new SubqueryIn<>(new QueryAtom<>(account)));\n" + + " }\n" + + "\n" + + " protected

void recordFilter(SubqueryIn atom) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in SubqueryIn.java (at line 2)\n" + + " public SubqueryIn(QueryAtom... subqueryAtoms) {\n" + + " ^^^^^^^^^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter subqueryAtoms\n" + + "----------\n" + + "----------\n" + + "1. WARNING in Test.java (at line 9)\n" + + " recordFilter(new SubqueryIn<>(new QueryAtom<>(account)));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of QueryAtom is created for a varargs parameter\n" + + "----------\n"); +} +public void testBug462083() { + runConformTest( + new String[] { + "Java8InterfaceTest.java", + "public abstract class Java8InterfaceTest\n" + + "{\n" + + " public static interface Entity {}\n" + + "\n" + + " public static interface Service {}\n" + + "\n" + + " public static interface ServiceLocator {}\n" + + "\n" + + " public static class ConcreteClass> implements ServiceLocator {}\n" + + "\n" + + " protected abstract ConcreteClass getParameterized(T4 entity);\n" + + "\n" + + " protected ServiceLocator getInterface(T5 entity)\n" + + " {\n" + + " return getParameterized(entity);\n" + + " }\n" + + "}\n" + }); +} +public void testBug469653() { + String codeContent = + "import java.util.*;\n" + + "\n" + + "class ImmutableList {\n" + + " static ImmutableList copyOf(Iterable in) { return null; }\n" + + " ImmutableList reverse() { return this; }\n" + + " Iterator iterator() { return null; }\n" + + "}\n" + + "public class Code {\n" + + " public static void test() {\n" + + " Iterable services = null;\n" + + " Iterator reverseServices = ImmutableList.copyOf(services).reverse().iterator();\n" + + " }\n" + + "}"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runConformTest( + new String[] { "Code.java", codeContent }); + } else { + runNegativeTest( + new String[] { "Code.java", codeContent }, + "----------\n" + + "1. ERROR in Code.java (at line 11)\n" + + " Iterator reverseServices = ImmutableList.copyOf(services).reverse().iterator();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Iterator to Iterator\n" + + "----------\n"); + } +} +public void testBug488649_JDK6791481_ex1() { + int count = 1; + runNegativeTest( + new String[] { + "Test.java", + "class Test {\n" + + " X m(Class c) {return null;}\n" + + " X x = m((Class)String.class);\n" + + "}\n" + }, + "----------\n" + + (this.complianceLevel >= ClassFileConstants.JDK1_8 + ? + (count++)+". ERROR in Test.java (at line 3)\n" + + " X x = m((Class)String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to X\n" + // <- want to see this error, but at 1.7- we keep javac compatibility + "----------\n" + : + "" + )+ + (count++)+". WARNING in Test.java (at line 3)\n" + + " X x = m((Class)String.class);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Class needs unchecked conversion to conform to Class\n" + + "----------\n" + + (count++)+". WARNING in Test.java (at line 3)\n" + + " X x = m((Class)String.class);\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); +} +public static Class testClass() { + return GenericsRegressionTest_1_7.class; +} +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java new file mode 100644 index 0000000000..bf28ff22a2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_8.java @@ -0,0 +1,10328 @@ +/******************************************************************************* + * Copyright (c) 2013, 2020 GK Software AG, and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + * IBM Corporation - additional tests + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class GenericsRegressionTest_1_8 extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "testBug496574_small" }; +// TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public GenericsRegressionTest_1_8(String name) { + super(name); +} +public static Class testClass() { + return GenericsRegressionTest_1_8.class; +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} + +public void testBug423070() { + this.runConformTest( + new String[] { + "junk/Junk3.java", + "package junk;\n" + + "\n" + + "import java.util.ArrayList;\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "class ZZObject extends Object {\n" + + "}\n" + + "\n" + + "public class Junk3 {\n" + + "\n" + + " public static final List EMPTY_LIST = new ArrayList<>();\n" + + " public static final List emptyList() {\n" + + " return (List) EMPTY_LIST;\n" + + " }\n" + + " \n" + + " public Junk3(List list) {\n" + + " }\n" + + " \n" + + " //FAILS - if passed as argument\n" + + " public Junk3() {\n" + + " this(emptyList());\n" + + " }\n" + + " \n" + + "\n" + + " //WORKS - if you assign it (and lose type info?)\n" + + " static List works = emptyList();\n" + + " public Junk3(boolean bogus) {\n" + + " this(works);\n" + + " }\n" + + "}", + }); +} + +public void testConditionalExpression1() { + runConformTest( + new String[] { + "X.java", + "class A {}\n" + + "class B extends A {}\n" + + "public class X {\n" + + " T combine(T x, T y) { return x; }\n" + + " A test(A a, B b, boolean flag) {\n" + + " return combine(flag ? a : b, a);\n" + + " }\n" + + "}\n" + }); +} + +public void testConditionalExpression2() { + runConformTest( + new String[] { + "X.java", + "class A{/**/}\n" + + "class B extends A {/**/}\n" + + "class C extends B {/**/}\n" + + "class G {/**/}\n" + + "\n" + + "public class X {\n" + + "G ga=null;\n" + + "G gb=null;\n" + + "G gc=null;\n" + + "G gsa=null;\n" + + "G gsb=null;\n" + + "G gsc=null;\n" + + "\n" + + "@SuppressWarnings(\"unused\")\n" + + " public void test(boolean f) {\n" + + " G l1 = (f) ? gsa : gb;\n" + + " G l2 = (f) ? gsb : gb;\n" + + " G l3 = (f) ? gsc : gb;\n" + + " G l4 = (f) ? gsb : gsb;\n" + + " }\n" + + "}" + }); +} +public void testBug423839() { + runConformTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " public T randomElement(Collection list) {\n" + + " return randomElement(list instanceof List ? list : new ArrayList<>(list));\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug418807() { + runConformTest( + new String[] { + "Word.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + " \n" + + "public class Word {\n" + + " private final String str;\n" + + "\n" + + " public Word(String s) {\n" + + " str = s;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String toString() {\n" + + " return str;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List names = Arrays.asList(\"Aaron\", \"Jack\", \"Ben\");\n" + + " Stream ws = names.stream().map(Word::new);\n" + + " List words = ws.collect(Collectors.toList());\n" + + " words.forEach(System.out::println);\n" + + " }\n" + + "}\n" + }); +} +public void testBug414631() { + runConformTest( + new String[] { + "test/Y.java", + "package test;\n" + + "import java.util.function.Supplier;\n" + + "public abstract class Y {\n" + + " public static Y empty() { return null;}\n" + + " public static Y cons(E head, Supplier> tailFun) {return null;}\n" + + "}", + "test/X.java", + "package test;\n" + + "import static test.Y.*;\n" + + "public class X {\n" + + " public void foo() {\n" + + " Y generated = cons(\"a\", () -> cons(\"b\", Y::empty));\n" + + " }\n" + + "}\n" + }); +} +public void testBug424038() { + runNegativeTest( + new String[] { + "Foo.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "public class Foo {\n" + + "\n" + + " public void gather() {\n" + + " StreamLike stream = null;\n" + + " List> list1 = stream.gather(() -> new Stuff<>()).toList();\n" + + " List> list2 = stream.gather(() -> new Stuff<>()).toList(); // ERROR\n" + + " }\n" + + "\n" + + " interface StreamLike {\n" + + " > StreamLike gather(Supplier gatherer);\n" + + "\n" + + " List toList();\n" + + " }\n" + + "\n" + + " static class Stuff implements Consumer {\n" + + " public void accept(T t) {}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 8)\n" + + " List> list2 = stream.gather(() -> new Stuff<>()).toList(); // ERROR\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List> to List>\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/423504 - [1.8] Implement "18.5.3 Functional Interface Parameterization Inference" +public void testBug423504() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " I> sorter = (List m) -> { /* sort */ };\n" + + " }\n" + + "} \n" + + "\n" + + "interface I { \n" + + " public void sort(T col);\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/420525 - [1.8] [compiler] Incorrect error "The type Integer does not define sum(Object, Object) that is applicable here" +public void testBug420525() { + runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.concurrent.CompletableFuture;\n" + + "import java.util.concurrent.ExecutionException;\n" + + "public class X {\n" + + " void test(List> futures) {\n" + + " CompletableFuture.allOf(futures.toArray(new CompletableFuture[]{})).thenApplyAsync( (Void v) -> {\n" + + " Integer finalResult = futures.stream().map( (CompletableFuture f) -> {\n" + + " try {\n" + + " return f.get();\n" + + " } catch (InterruptedException | ExecutionException e) {\n" + + " return 0;\n" + + " }\n" + + " }).reduce(0, Integer::sum);\n" + + " \n" + + " log(\"final result is \" + finalResult);\n" + + " if (finalResult != 50){\n" + + " throw new RuntimeException(\"FAILED\");\n" + + " } else{\n" + + " log(\"SUCCESS\");\n" + + " }\n" + + " \n" + + " return null;\n" + + " });\n" + + "\n" + + " }\n" + + " void log(String msg) {}\n" + + "}\n" + }); +} +//https://bugs.eclipse.org/420525 - [1.8] [compiler] Incorrect error "The type Integer does not define sum(Object, Object) that is applicable here" +public void testBug420525_mini() { + runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.concurrent.CompletableFuture;\n" + + "import java.util.concurrent.ExecutionException;\n" + + "public class X {\n" + + " void test(List> futures, boolean b) {\n" + + " Integer finalResult = futures.stream().map( (CompletableFuture f) -> {\n" + + " if (b) \n" + + " return 1;\n" + + " else\n" + + " return Integer.valueOf(13);" + + " }).reduce(0, Integer::sum);\n" + + " }\n" + + "}\n" + }); +} + +// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=420525#c7 +public void testBug420525a() { + runNegativeTest( + new String[] { + "Main.java", + "interface I {\n" + + " T bold(T t);\n" + + "}\n" + + "\n" + + "class Main { \n" + + " public String foo(String x) { return \"\" + x + \"\"; }\n" + + " String bar() {\n" + + " I i = this::foo;\n" + + " return i.bold(\"1\");\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Main.java (at line 9)\n" + + " return i.bold(\"1\");\n" + + " ^^^^\n" + + "The method bold(capture#1-of ? extends String) in the type I is not applicable for the arguments (String)\n" + + "----------\n"); +} + +public void testBug424415() { + runConformTest( + new String[] { + "X.java", + "\n" + + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "\n" + + "interface Functional {\n" + + " T apply();\n" + + "}\n" + + "\n" + + "class X {\n" + + " void foo(Object o) { }\n" + + "\n" + + " > Q goo(Functional s) {\n" + + " return null;\n" + + " } \n" + + "\n" + + " void test() {\n" + + " foo(goo(ArrayList::new));\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424415#c6 +public void testBug424415b() { + runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "\n" + + "interface Functional {\n" + + " T apply();\n" + + "}\n" + + "\n" + + "class X {\n" + + " void foo(Object o) { }\n" + + " void foo(String str) {} \n" + + "\n" + + " > Q goo(Functional s) {\n" + + " return null;\n" + + " } \n" + + "\n" + + " void test() {\n" + + " foo(goo(ArrayList::new));\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424415#c8 +public void testBug424415c() { + runConformTest( + new String[] { + "com/example/MyEmployee.java", + "package com.example;\n" + + "class MyEmployee {\n" + + " \n" + + " public enum Gender { MALE, FEMALE, OTHERS }\n" + + "\n" + + " private int age = 0;\n" + + " private Gender gender = Gender.MALE;\n" + + " \n" + + " public MyEmployee(int age, Gender gender) {\n" + + " this.age = age;\n" + + " this.gender = gender;\n" + + " } \n" + + " \n" + + " public int getAge() {\n" + + " return age;\n" + + " }\n" + + " \n" + + " public Gender getGender() {\n" + + " return gender;\n" + + " }\n" + + "}", + "com/example/Test.java", + "package com.example;\n" + + "\n" + + "import java.util.List;\n" + + "import java.util.concurrent.ConcurrentMap;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " ConcurrentMap> test(List el) {\n" + + " return el.parallelStream()\n" + + " .collect(\n" + + " Collectors.groupingByConcurrent(MyEmployee::getGender)\n" + + " );\n" + + " }\n" + + " \n" + + "}" + }); +} +public void testBug424631() { + runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "\n" + + "interface Functional {\n" + + " T apply();\n" + + "}\n" + + "\n" + + "class X {\n" + + " void foo(Collection o) { }\n" + + "\n" + + " > Q goo(Functional s) {\n" + + " return null;\n" + + " } \n" + + "\n" + + " void test() { \n" + + " foo(goo(ArrayList::new));\n" + + " }\n" + + "}\n" + }); +} + +public void testBug424403() { + runConformTest( + new String[] { + "X.java", + "interface Functional { int foo(); }\n" + + "\n" + + "public class X {\n" + + " static int bar() {\n" + + " return -1;\n" + + " }\n" + + " static T consume(T t) { return null; }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Functional f = consume(X::bar);\n" + + " } \n" + + "}\n" + }); +} +public void testBug401850a() { + runNegativeTest( + false /* skipJavac */, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + null : JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "public class X {\n" + + " X(T t) {}\n" + + " X(String s) {}\n" + + " int m(X xs) { return 0; }\n" + + " int i = m(new X<>(\"\"));\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " import java.util.List;\n" + + " ^^^^^^^^^^^^^^\n" + + "The import java.util.List is never used\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " import java.util.ArrayList;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The import java.util.ArrayList is never used\n" + + "----------\n"); +} +public void testBug401850b() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "public class X {\n" + + " X(T t) {}\n" + + " X(String s) {}\n" + + " int m(X xs) { return 0; }\n" + + " int i = m(new X(\"\"));\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " int i = m(new X(\"\"));\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The constructor X(String) is ambiguous\n" + + "----------\n"); +} + +public void testBug424710() { + runConformTest( + new String[] { + "MapperTest.java", + "import java.util.ArrayList;\n" + + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.regex.Matcher;\n" + + "import java.util.regex.Pattern;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class MapperTest {\n" + + "\n" + + " public static void main( String... argv ){\n" + + " List data = Arrays.asList(\"abc\", \"123\", \"1a\", \"?!?\");\n" + + " List patterns = Arrays.asList(Pattern.compile(\"[a-z]+\"), Pattern.compile(\"[0-9]+\"));\n" + + " patterns.stream()\n" + + " .flatMap(\n" + + " p -> {\n" + + " Stream map = data.stream().map(p::matcher);\n" + + " Stream filter = map.filter(Matcher::find);\n" + + " Function mapper = Matcher::group;\n" + + " mapper = matcher -> matcher.group();\n" + + " return filter.map(mapper);\n" + + " })\n" + + " .forEach(System.out::println);\n" + + " }\n" + + "}\n" + }); +} + +public void testBug424075() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Consumer c = null;\n" + + " Arrays.asList(pred(), c);\n" + + " }\n" + + "\n" + + " static Predicate pred() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug424205a() { + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void bar(String t);\n" + + "}\n" + + "class X implements I {\n" + + " public void bar(String t) {}\n" + + " X(String x) {}\n" + + " X(T x) {}\n" + + " public void one(X c){}\n" + + " public void two() {\n" + + " X i = new X<>((String s) -> { });\n" + + " one (i);\n" + + " }\n" + + "}\n" + }); +} +public void testBug424205b() { + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void bar(String t);\n" + + "}\n" + + "public class X implements I {\n" + + " public void bar(String t) {}\n" + + " X(String x) {}\n" + + " X(T x) {}\n" + + " public void one(X c){}\n" + + " public void two() {\n" + + " one(new X<>((String s) -> { })); // 1. Three errors\n" + + " X i = new X<>((String s) -> { }); // 2. Error - Comment out the previous line to see this error go away.\n" + + " one (i);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"main\");\n" + + " new X(\"one\").two();\n" + + " }\n" + + "}\n" + }, + "main"); +} +public void testBug424712a() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + " public static , DEST extends Collection>\n" + + " DEST foo(SOURCE sourceCollection, DEST collectionFactory) {\n" + + " return null;\n" + + " } \n" + + " \n" + + " public static void main(String... args) {\n" + + " Set rosterSet = (Set) foo(null, Set::new);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Set rosterSet = (Set) foo(null, Set::new);\n" + + " ^\n" + + "Y cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " Set rosterSet = (Set) foo(null, Set::new);\n" + + " ^\n" + + "Y cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " Set rosterSet = (Set) foo(null, Set::new);\n" + + " ^^^\n" + + "Cannot instantiate the type Set\n" + + "----------\n"); +} +public void testBug424712b() { + runConformTest( + new String[] { + "X.java", + "import java.util.Comparator;\n" + + "public class X {\n" + + " void test() {\n" + + " Comparator comparator = (Comparator) Comparator.naturalOrder();\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().test();\n" + + " }\n" + + "}\n" + }, + "OK"); +} +public void testBug425142_minimal() { + runNegativeTest( + new String[] { + "SomethingBreaks.java", + "import java.io.IOException;\n" + + "import java.nio.file.Files;\n" + + "import java.nio.file.Paths;\n" + + "import java.util.function.Consumer;\n" + + "\n" + + "@FunctionalInterface interface Use { void accept(T t) throws E; }\n" + + "\n" + + "@SuppressWarnings(\"unused\") public class SomethingBreaks {\n" + + " protected static SomethingBreaks stream() { return null; }\n" + + "\n" + + " public void forEach(Consumer use) throws E {}\n" + + "\n" + + " public void forEach(Use use) throws E, E2 {}\n" + + "\n" + + " private static void methodReference(String s) throws IOException {\n" + + " System.out.println(Files.size(Paths.get(s)));\n" + + " }\n" + + " \n" + + " public static void useCase9() throws IOException {\n" + + " stream().forEach((String s) -> System.out.println(Files.size(Paths.get(s))));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in SomethingBreaks.java (at line 20)\n" + + " stream().forEach((String s) -> System.out.println(Files.size(Paths.get(s))));\n" + + " ^^^^^^^\n" + + "The method forEach(Consumer) is ambiguous for the type SomethingBreaks\n" + + "----------\n"); +} +public void testBug425142_full() { + runNegativeTest( + new String[] { + "SomethingBreaks.java", + "import java.io.IOException;\n" + + "import java.nio.file.Files;\n" + + "import java.nio.file.Paths;\n" + + "import java.util.function.Consumer;\n" + + "\n" + + "@FunctionalInterface interface Use { void accept(T t) throws E; }\n" + + "\n" + + "@SuppressWarnings(\"unused\") public class SomethingBreaks {\n" + + " protected static SomethingBreaks stream() { return null; }\n" + + "\n" + + " public void forEach(Consumer use) throws E {}\n" + + "\n" + + " public void forEach(Use use) throws E, E2 {}\n" + + "\n" + + " private static void methodReference(String s) throws IOException {\n" + + " System.out.println(Files.size(Paths.get(s)));\n" + + " }\n" + + " \n" + + " public static void useCase1() throws IOException {\n" + + " Use c =\n" + + " (String s) -> System.out.println(Files.size(Paths.get(s)));\n" + + " stream().forEach(c);\n" + + " }\n" + + " \n" + + " public static void useCase2() throws IOException {\n" + + " Use c = SomethingBreaks::methodReference;\n" + + " stream().forEach(c);\n" + + " }\n" + + " \n" + + " public static void useCase3() throws IOException {\n" + + " stream().forEach((Use) (String s) -> System.out.println(Files.size(Paths.get(s))));\n" + + " }\n" + + " \n" + + " public static void useCase4() throws IOException {\n" + + " stream().forEach((Use) SomethingBreaks::methodReference);\n" + + " }\n" + + " \n" + + " public static void useCase5() throws IOException {\n" + + " stream(). forEach((String s) -> System.out.println(Files.size(Paths.get(s))));\n" + + " }\n" + + " \n" + + " public static void useCase6() throws IOException {\n" + + " stream(). forEach(SomethingBreaks::methodReference);\n" + + " }\n" + + " \n" + + " public static void useCase7() throws IOException {\n" + + " stream().> forEach((String s) -> System.out.println(Files.size(Paths.get(s))));\n" + + " }\n" + + " \n" + + " public static void useCase8() throws IOException {\n" + + " stream().> forEach(SomethingBreaks::methodReference);\n" + + " }\n" + + " \n" + + " public static void useCase9() throws IOException {\n" + + " stream().forEach((String s) -> System.out.println(Files.size(Paths.get(s))));\n" + + " }\n" + + " \n" + + " public static void useCase10() throws IOException {\n" + + " stream().forEach(SomethingBreaks::methodReference);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in SomethingBreaks.java (at line 39)\n" + + " stream(). forEach((String s) -> System.out.println(Files.size(Paths.get(s))));\n" + + " ^^^^^^^\n" + + "The method forEach(Consumer) is ambiguous for the type SomethingBreaks\n" + + "----------\n" + + "2. ERROR in SomethingBreaks.java (at line 43)\n" + + " stream(). forEach(SomethingBreaks::methodReference);\n" + + " ^^^^^^^\n" + + "The method forEach(Consumer) is ambiguous for the type SomethingBreaks\n" + + "----------\n" + + "3. ERROR in SomethingBreaks.java (at line 43)\n" + + " stream(). forEach(SomethingBreaks::methodReference);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n" + + "4. ERROR in SomethingBreaks.java (at line 47)\n" + + " stream().> forEach((String s) -> System.out.println(Files.size(Paths.get(s))));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n" + + "5. ERROR in SomethingBreaks.java (at line 51)\n" + + " stream().> forEach(SomethingBreaks::methodReference);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n" + + "6. ERROR in SomethingBreaks.java (at line 55)\n" + + " stream().forEach((String s) -> System.out.println(Files.size(Paths.get(s))));\n" + + " ^^^^^^^\n" + + "The method forEach(Consumer) is ambiguous for the type SomethingBreaks\n" + + "----------\n" + + "7. ERROR in SomethingBreaks.java (at line 59)\n" + + " stream().forEach(SomethingBreaks::methodReference);\n" + + " ^^^^^^^\n" + + "The method forEach(Consumer) is ambiguous for the type SomethingBreaks\n" + + "----------\n" + + "8. ERROR in SomethingBreaks.java (at line 59)\n" + + " stream().forEach(SomethingBreaks::methodReference);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n"); +} +public void testBug424195a() { + runNegativeTestMultiResult( + new String[] { + "NPEOnCollector.java", + "import java.io.IOException;\n" + + "import java.nio.file.Path;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.Predicate;\n" + + "import java.util.jar.JarEntry;\n" + + "import java.util.jar.JarFile;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "\n" + + "public class NPEOnCollector {\n" + + " static void processJar(Path plugin) throws IOException {\n" + + " \n" + + " try(JarFile jar = new JarFile(plugin.toFile())) {\n" + + " try(Stream entries = jar.stream()) {\n" + + " Stream stream = entries\n" + + " .distinct().collect(Collectors.toCollection(ArrayList::new));\n" + + " \n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + null, + new String[] { + "----------\n" + + "1. ERROR in NPEOnCollector.java (at line 17)\n" + + " Stream stream = entries\n" + + " .distinct().collect(Collectors.toCollection(ArrayList::new));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Collection to Stream\n" + + "----------\n", + "----------\n" + + "1. ERROR in NPEOnCollector.java (at line 18)\n" + + " .distinct().collect(Collectors.toCollection(ArrayList::new));\n" + + " ^^^^^^^^^^^^^^\n" + + "The constructed object of type ArrayList is incompatible with the descriptor\'s return type: Stream&Collection&Collection\n" + + "----------\n" + }); +} +public void testBug424195b() { + runConformTest( + new String[] { + "NPEOnCollector.java", + "import java.io.IOException;\n" + + "import java.nio.file.Path;\n" + + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.Predicate;\n" + + "import java.util.jar.JarEntry;\n" + + "import java.util.jar.JarFile;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "\n" + + "public class NPEOnCollector {\n" + + " static void processJar(Path plugin) throws IOException {\n" + + " \n" + + " try(JarFile jar = new JarFile(plugin.toFile())) {\n" + + " try(Stream entries = jar.stream()) {\n" + + " Collection collection = entries\n" + + " .distinct().collect(Collectors.toCollection(ArrayList::new));\n" + + " \n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +public void testBug424195_comment2() { + runConformTest( + new String[] { + "X.java", + "import java.io.PrintStream;\n" + + "import java.util.ArrayList;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.*;\n" + + "public class X {\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " ArrayList al = IntStream\n" + + " .range(0, 10_000)\n" + + " .boxed()\n" + + " .collect(Collectors.toCollection(ArrayList::new));\n" + + "\n" + + " }\n" + + "}\n" + }); +} +public void testBug425153() { + runNegativeTest( + new String[] { + "Main.java", + "class C1 {}\n" + + "class C2 {}\n" + + "\n" + + "interface I {\n" + + " P2 foo(P1 p1);\n" + + "}\n" + + "\n" + + "public class Main {\n" + + " public static void main(String argv[]) {\n" + + " I i = (C1 c1) -> { return new C2(); };\n" + + " Object c2 = i.foo(null);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Main.java (at line 10)\n" + + " I i = (C1 c1) -> { return new C2(); };\n" + + " ^^^^^^^^^^\n" + + "The target type of this expression is not a well formed parameterized type due to bound(s) mismatch\n" + + "----------\n"); +} +public void testBug424845() { + runConformTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.Collections;\n" + + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "\n" + + "public class Test {\n" + + " \n" + + "\n" + + " interface Function{\n" + + " public V apply(K orig);\n" + + " }\n" + + " \n" + + " \n" + + " static class Ordering {\n" + + "\n" + + " public Comparator onResultOf(Function function) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " \n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " List list = new ArrayList<>();\n" + + " Function function = new Function() {\n" + + " public String apply(Object arg0) {\n" + + " return arg0.toString();\n" + + " }\n" + + " };\n" + + " Ordering> natural = new Ordering<>();\n" + + " Collections.sort(list, natural.onResultOf(function));\n" + + " }\n" + + " \n" + + "}\n" + }); +} +public void testBug425278() { + runConformTest( + new String[] { + "X.java", + "interface I> { \n" + + " T foo(S p);\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public void bar() {\n" + + " I> f = (p) -> p; // Error\n" + + " }\n" + + "}\n" + }); +} +public void testBug425783() { + runConformTest( + new String[] { + "Test.java", + "class MyType> {\n" + + " S myself() { return (S)this; }\n" + + "}\n" + + "public class Test {\n" + + " MyType test() {\n" + + " return newInstance().myself();\n" + + " }\n" + + " MyType test2() {\n" + + " return newInstance().myself();\n" + + " }\n" + + " public T newInstance() {\n" + + " return (T) new MyType();\n" + + " }" + + "}\n" + }); +} +public void testBug425798() { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import java.util.stream.*;\n" + + "interface MyCollector extends Collector {\n" + + "}\n" + + "public abstract class X {\n" + + " abstract >\n" + + " MyCollector toMap(Function km,\n" + + " BinaryOperator mf);" + + " void test(Stream annotations) {\n" + + " annotations\n" + + " .collect(toMap(Annotation::annotationType,\n" + + " (first, second) -> first));\n" + + " }\n" + + "}\n" + }, + ""); +} +public void testBug425798a() { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import java.util.stream.*;\n" + + "interface MyCollector extends Collector {\n" + + "}\n" + + "public abstract class X {\n" + + " abstract >\n" + + " MyCollector toMap(Function km,\n" + + " BinaryOperator mf);" + + " void test(Stream annotations) {\n" + + " annotations\n" + + " .collect(toMap(true ? Annotation::annotationType : Annotation::annotationType,\n" + + " (first, second) -> first));\n" + + " }\n" + + "}\n" + }, + ""); +} +// witness for NPE mentioned in https://bugs.eclipse.org/bugs/show_bug.cgi?id=425798#c2 +public void testBug425798b() { + runConformTest( + new String[] { + "X.java", + "import java.util.Objects;\n" + + "import java.util.PrimitiveIterator;\n" + + "import java.util.Spliterator;\n" + + "import java.util.Spliterator.OfInt;\n" + + "import java.util.function.Consumer;\n" + + "import java.util.function.IntConsumer;\n" + + "\n" + + "class IntIteratorSpliterator implements OfInt {\n" + + " public IntIteratorSpliterator(PrimitiveIterator.OfInt arg) { }\n" + + " public void forEachRemaining(IntConsumer action) { }\n" + + " public boolean tryAdvance(Consumer action) { return false; }\n" + + " public long estimateSize() { return 0; }\n" + + " public int characteristics() { return 0; }\n" + + " public OfInt trySplit() { return null; }\n" + + " public boolean tryAdvance(IntConsumer action) { return false; }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public Spliterator.OfInt spliterator(PrimitiveIterator.OfInt iterator) {\n" + + " return new IntIteratorSpliterator(id(iterator));\n" + + " }\n" + + " T id(T e) { return e; }\n" + + "}\n" + }); +} +public void testBug425460orig() { + runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n" + + " final Integer[] boom =\n" + + " Arrays.asList(\"1\", \"22\", \"333\")\n" + + " .stream()\n" + + " .map(str -> str.length())\n" + + " .toArray(i -> new Integer[i]);\n" + + "}\n" + }); +} +public void testBug425460variant() { + runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n" + + " final Integer[] boom =\n" + + " Arrays.asList(\"1\", \"22\", \"333\")\n" + + " .stream()\n" + + " .map(str -> str.length())\n" + + " .toArray((int i) -> new Integer[i]);\n" + + "}\n" + }); +} +public void testBug425951() { + runNegativeTest( + new String[] { + "Test.java", + "import java.util.List;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " index(new A().test());\n" + + " }\n" + + "\n" + + " public static void index(Iterable collection)\n" + + " {\n" + + " }\n" + + " \n" + + " public class A>\n" + + " {\n" + + " protected A() {}\n" + + " \n" + + " public List test()\n" + + " {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Test.java (at line 6)\n" + + " index(new A().test());\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation index(List) of the generic method index(Iterable) of type Test\n" + + "----------\n" + + "2. WARNING in Test.java (at line 6)\n" + + " index(new A().test());\n" + + " ^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type List needs unchecked conversion to conform to Iterable\n" + + "----------\n" + + "3. ERROR in Test.java (at line 6)\n" + + " index(new A().test());\n" + + " ^^^^^^^\n" + + "No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).\n" + + "----------\n" + + "4. WARNING in Test.java (at line 6)\n" + + " index(new A().test());\n" + + " ^\n" + + "Test.A is a raw type. References to generic type Test.A should be parameterized\n" + + "----------\n"); +} +public void testBug425951a() { + runConformTest( + new String[] { + "Test.java", + "import java.util.List;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " public void test() {\n" + + " index(new A().test());\n" + + " }\n" + + "\n" + + " public static void index(Iterable collection)\n" + + " {\n" + + " }\n" + + " \n" + + " public class A>\n" + + " {\n" + + " protected A() {}\n" + + " \n" + + " public List test()\n" + + " {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +public void testBug424906() { + runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public void test(Result r) {}\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Main().test(r -> System.out.println(\"Hmmm...\" + r));\n" + + " }\n" + + "}\n" + + "\n" + + "interface Result {\n" + + " public void result(Object object);\n" + + "}" + }); +} +public void testBug425156() { + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(T t);\n" + + "}\n" + + "public class X {\n" + + " void bar(I i) {\n" + + " i.foo(null);\n" + + " }\n" + + " void run() {\n" + + " bar((X x) -> {}); // Incompatible error reported\n" + + " }\n" + + "}\n" + }); +} +public void testBug425493() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public void addAttributeBogus(Attribute attribute) {\n" + + " addAttribute(java.util.Objects.requireNonNull(attribute, \"\"),\n" + + " attribute.getDefault());\n" + + " addAttribute(attribute, attribute.getDefault());\n" + + " }\n" + + " public void addAttributeOK(Attribute attribute) {\n" + + " addAttribute(java.util.Objects.requireNonNull(attribute, \"\"),\n" + + " attribute.getDefault());\n" + + " addAttribute(attribute, attribute.getDefault());\n" + + " }\n" + + "\n" + + " private void addAttribute(Attribute attribute, T defaultValue) {}\n" + + "\n" + + " static class Attribute {\n" + + "\n" + + " T getDefault() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 3)\n" + + " addAttribute(java.util.Objects.requireNonNull(attribute, \"\"),\n" + + " ^^^^^^^^^^^^\n" + + "The method addAttribute(Test.Attribute, T) in the type Test is not applicable for the arguments (Test.Attribute, capture#2-of ?)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 5)\n" + + " addAttribute(attribute, attribute.getDefault());\n" + + " ^^^^^^^^^^^^\n" + + "The method addAttribute(Test.Attribute, T) in the type Test is not applicable for the arguments (Test.Attribute, capture#4-of ?)\n" + + "----------\n"); +} +public void testBug426366() { + runConformTest( + new String[] { + "a/Test.java", + "package a;\n" + + "\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "/**\n" + + " * @author tomschindl\n" + + " *\n" + + " */\n" + + "public class Test {\n" + + " public static class A {\n" + + " public A(B newSelectedObject, String editorController) {\n" + + " }\n" + + "\n" + + " public A(List newSelectedObjects, String editorController) {\n" + + " }\n" + + " }\n" + + " \n" + + " public static class B {\n" + + " \n" + + " }\n" + + " \n" + + " public static class C extends A {\n" + + " public C() {\n" + + " super(Collections.emptyList(), \"\");\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +public void testBug426290() { + runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " goo(foo());\n" + + " }\n" + + "\n" + + " static List foo() {\n" + + " return new ArrayList();\n" + + " }\n" + + "\n" + + " static void goo(Object p1) {\n" + + " System.out.println(\"goo(Object)\");\n" + + " }\n" + + "\n" + + " static void goo(List p1) {\n" + + " System.out.println(\"goo(List)\");\n" + + " }\n" + + "}\n" + }, + "goo(List)"); +} +public void testBug425152() { + runConformTest( + new String[] { + "packDown/SorterNew.java", + "package packDown;\n" + + "\n" + + "import java.util.ArrayList;\n" + + "import java.util.Collections;\n" + + "import java.util.Comparator;\n" + + "\n" + + "public class SorterNew {\n" + + " void sort() {\n" + + " Collections.sort(new ArrayList(),\n" + + " Comparator.comparing((Person p) -> p.getName()));\n" + + " }\n" + + "}\n" + + "\n" + + "class Person {\n" + + " public String getName() {\n" + + " return \"p\";\n" + + " }\n" + + "}\n" + }); +} +public void testBug426048() { + runNegativeTest( + new String[] { + "MyFunction.java", + "import java.lang.annotation.Annotation;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Throws {\n" + + " Class[] value() default Throwable.class;\n" + + " Returns method() default @Returns(Annotation.class);\n" + + "}\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Returns {\n" + + " Class value() default Annotation.class;\n" + + "}\n" + + "\n" + + "@FunctionalInterface public interface MyFunction {\n" + + " @Returns R apply(T t);\n" + + "\n" + + " default @Throws(((MyFunction) before::apply) @Returns MyFunction\n" + + " compose(MyFunction before) {\n" + + "\n" + + " return (V v) -> apply(before.apply(v));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in MyFunction.java (at line 19)\n" + + " default @Throws(((MyFunction) before::apply) @Returns MyFunction\n" + + " ^\n" + + "Syntax error, insert \"Type Identifier (\" to complete MethodHeaderName\n" + + "----------\n" + + "2. ERROR in MyFunction.java (at line 19)\n" + + " default @Throws(((MyFunction) before::apply) @Returns MyFunction\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from MyFunction to Class[]\n" + + "----------\n" + + "3. ERROR in MyFunction.java (at line 19)\n" + + " default @Throws(((MyFunction) before::apply) @Returns MyFunction\n" + + " ^^^^^^\n" + + "before cannot be resolved\n" + + "----------\n" + + "4. ERROR in MyFunction.java (at line 19)\n" + + " default @Throws(((MyFunction) before::apply) @Returns MyFunction\n" + + " ^\n" + + "Syntax error, insert \")\" to complete Modifiers\n" + + "----------\n" + + "5. ERROR in MyFunction.java (at line 20)\n" + + " compose(MyFunction before) {\n" + + " ^\n" + + "Syntax error on token \"(\", , expected\n" + + "----------\n"); +} +public void testBug426540() { + runConformTest( + new String[] { + "X.java", + "import java.util.stream.Stream;\n" + + "import java.util.Collections;\n" + + "import static java.util.stream.Collectors.collectingAndThen;\n" + + "import static java.util.stream.Collectors.toList;\n" + + "public class X {\n" + + " Object o = ((Stream) null).collect(collectingAndThen(toList(), Collections::unmodifiableList));\n" + + "}\n" + }); +} +public void testBug426671_ok() { + runConformTest( + new String[] { + "X.java", + "import java.util.stream.Stream;\n" + + "import java.util.*;\n" + + "import static java.util.stream.Collectors.collectingAndThen;\n" + + "import static java.util.stream.Collectors.toList;\n" + + "public class X {\n" + + " void test(Stream> stream) {\n" + + " stream.collect(collectingAndThen(toList(), Collections::>unmodifiableList))\n" + + " .remove(0);\n" + + " }\n" + + "}\n" + }); +} +public void testBug426671_medium() { + runConformTest( + new String[] { + "X.java", + "import java.util.stream.Stream;\n" + + "import java.util.*;\n" + + "import static java.util.stream.Collectors.collectingAndThen;\n" + + "import static java.util.stream.Collectors.toList;\n" + + "public class X {\n" + + " void test(Stream> stream) {\n" + + " stream.collect(collectingAndThen(toList(), Collections::unmodifiableList))\n" + + " .remove(0);\n" + + " }\n" + + "}\n" + }); +} +public void testBug426671_full() { + runConformTest( + new String[] { + "X.java", + "import java.util.stream.Stream;\n" + + "import java.util.*;\n" + + "import static java.util.stream.Collectors.collectingAndThen;\n" + + "import static java.util.stream.Collectors.toList;\n" + + "public class X {\n" + + " void test() {\n" + + " Arrays.asList((List) null).stream().collect(collectingAndThen(toList(), Collections::unmodifiableList))\n" + + " .remove(0);\n" + + " }\n" + + "}\n" + }); +} +public void testBug426671b() { + runNegativeTest( + new String[] { + "Test.java", + "interface I {\n" + + " Y fun(X y);\n" + + "}\n" + + "public class Test {\n" + + " static S id(S s) { return s; }\n" + + " void test() {\n" + + " m1(Test::id, \"Hi\");\n" + + " m2(Test::id, \"Hi\").toUpperCase();\n" + + " m3(Test::id, \"Hi\").toUpperCase();\n" + + " }\n" + + "\n" + + " void m1(I i, U u) { }\n" + + " V m2(I i, U u) {\n" + + " return null;\n" + + " }\n" + + " V m3(I i, U u) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Test.java (at line 8)\n" + + " m2(Test::id, \"Hi\").toUpperCase();\n" + + " ^^^^^^^^^^^\n" + + "The method toUpperCase() is undefined for the type Object\n" + + "----------\n"); +} +public void testBug426652() { + runConformTest( + new String[] { + "X.java", + "import static java.util.stream.Collectors.toList;\n" + + "public class X {\n" + + " Object o = toList();\n" + + "}\n" + }); +} +public void testBug426778() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void test(List result) {\n" + + " Collections.sort( result, \n" + + " Comparator.comparingInt(\n" + + " (CourseProviderEmploymentStatistics stat) -> stat.doneTrainingsTotal\n" + + " )\n" + + " .reversed()\n" + + " .thenComparing(\n" + + " (CourseProviderEmploymentStatistics stat) -> stat.courseProviderName ) );\n" + + " }\n" + + "}\n" + + "class CourseProviderEmploymentStatistics {\n" + + " int doneTrainingsTotal;\n" + + " String courseProviderName;\n" + + "}\n" + }); +} +public void testBug426676() { + runConformTest( + new String[] { + "Test.java", + "import java.util.Arrays;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "\n" + + "public class Test {\n" + + " public static void main(String[] args) throws Exception {\n" + + " // Type inference works on map call.\n" + + " Stream s1 =\n" + + " Arrays.stream(new Integer[] { 1, 2 })\n" + + " .map(i -> i.toString());\n" + + " \n" + + " // Type inference doesn't work on map call.\n" + + " Stream s2 =\n" + + " Arrays.stream(new Integer[] { 1, 2 })\n" + + " .map(i -> i.toString())\n" + + " .distinct();\n" + + " }\n" + + "}\n" + }); +} +public void testBug424591_comment20() { + runConformTest( + new String[] { + "MyList.java", + "import java.util.Arrays;\n" + + "public class MyList {\n" + + " protected Object[] elements;\n" + + " private int size;\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public A[] toArray(A[] a) {\n" + + " return (A[]) Arrays.copyOf(elements, size, a.getClass());\n" + + " }\n" + + "}\n" + }); +} +public void testBug424591_comment20_variant() { + runNegativeTest( + new String[] { + "MyList.java", + "import java.util.Arrays;\n" + + "public class MyList {\n" + + " protected Object[] elements;\n" + + " private int size;\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public A[] toArray(A[] a) {\n" + + " return (A[]) Arrays.copyOf(elements, size, getClass());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in MyList.java (at line 7)\n" + + " return (A[]) Arrays.copyOf(elements, size, getClass());\n" + + " ^^^^^^\n" + + "The method copyOf(U[], int, Class) in the type Arrays is not applicable for the arguments (Object[], int, Class)\n" + + "----------\n"); +} +public void testBug424591_comment22() { + runConformTest( + new String[] { + "Test.java", + "import java.util.*;\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " Test.forObject(new HashSet<>());\n" + + " }\n" + + " public static Test forObject(Object o) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug425063() { + runConformTest( + new String[] { + "ComparatorUse.java", + "import java.util.Comparator;\n" + + "public class ComparatorUse {\n" + + " Comparator c =\n" + + " Comparator.comparing((String s)->s.toString())\n" + + " .thenComparing(s -> s.length());\n" + + "}\n" + }); +} +public void testBug426764() { + runConformTest( + new String[] { + "X.java", + "interface I {}\n" + + "class C1 implements I {}\n" + + "class C2 implements I {}\n" + + "public class X {\n" + + " void foo(T p1, I p2) {}\n" + + " void foo(T p1, I p2) {}\n" + + " void bar() {\n" + + " foo(true ? new C1(): new C2(), false ? new C2(): new C1());\n" + + " foo(new C1(), false ? new C2(): new C1());\n" + + " }\n" + + "}\n" + }); +} +// simplest: avoid any grief concerning dequeCapacity: +public void testBug424930a() { + runConformTest( + new String[] { + "X.java", + "import java.util.ArrayDeque;\n" + + "import java.util.Deque;\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "public class X> {\n" + + " private final Supplier supplier;\n" + + "\n" + + " public X(Supplier supplier) {\n" + + " this.supplier = supplier;\n" + + " }\n" + + " \n" + + " int dequeCapacity;\n" + + " public static X> newDefaultMap() {\n" + + " return new X<>(() -> new ArrayDeque<>(13));\n" + + " }\n" + + "}\n" + }); +} +// original test: +public void testBug424930b() { + runConformTest( + new String[] { + "X.java", + "import java.util.ArrayDeque;\n" + + "import java.util.Deque;\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "public class X> {\n" + + " private final Supplier supplier;\n" + + "\n" + + " public X(Supplier supplier) {\n" + + " this.supplier = supplier;\n" + + " }\n" + + " \n" + + " public static X> newDefaultMap(int dequeCapacity) {\n" + + " return new X<>(() -> new ArrayDeque<>(dequeCapacity));\n" + + " }\n" + + "}\n" + }); +} +// witness for an NPE during experiments +public void testBug424930c() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayDeque;\n" + + "import java.util.Deque;\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "public class X> {\n" + + " private final Supplier supplier;\n" + + "\n" + + " public X(Supplier supplier) {\n" + + " this.supplier = supplier;\n" + + " }\n" + + " \n" + + " int dequeCapacity;\n" + + " public static X> newDefaultMap() {\n" + + " return new X<>(() -> new ArrayDeque<>(dequeCapacity));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " return new X<>(() -> new ArrayDeque<>(dequeCapacity));\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot make a static reference to the non-static field dequeCapacity\n" + + "----------\n"); +} +public void testBug426998a() { + runConformTest( + new String[] { + "Snippet.java", + "public class Snippet {\n" + + " static void call(Class type, long init) {\n" + + " String string = new String();\n" + + " method(type, init == 0 ? new String() : string);\n" + + " }\n" + + " private static void method(Class type, String s) {}\n" + + "}\n" + }); +} +// from https://bugs.eclipse.org/bugs/show_bug.cgi?id=426764#c5 +public void testBug426998b() { + runConformTest( + new String[] { + "Snippet.java", + "public class Snippet {\n" + + " private static final String PLACEHOLDER_MEMORY = new String();\n" + + "\n" + + " static void newInstance(Class type, long init) {\n" + + " method(type, init == 0 ? new String() : PLACEHOLDER_MEMORY);\n" + + " }\n" + + "\n" + + " private static void method(Class type, String str) {}\n" + + "}\n" + }); +} +public void testBug427164() { + runNegativeTest( + new String[] { + "NNLambda.java", + "import java.util.*;\n" + + "\n" + + "@FunctionalInterface\n" + + "interface FInter {\n" + + " String allToString(List input);\n" + + "}\n" + + "\n" + + "public abstract class NNLambda {\n" + + " abstract void printem(FInter conv, INP single);\n" + + " \n" + + " void test() {\n" + + " printem((i) -> {\n" + + " Collections.singletonList(\"const\")\n" + + " }, \n" + + " \"single\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in NNLambda.java (at line 12)\n" + + " printem((i) -> {\n" + + " ^^^^^^^\n" + + "The method printem(FInter, INP) in the type NNLambda is not applicable for the arguments (( i) -> {}, String)\n" + + "----------\n" + + "2. ERROR in NNLambda.java (at line 13)\n" + + " Collections.singletonList(\"const\")\n" + + " ^\n" + + "Syntax error, insert \";\" to complete BlockStatements\n" + + "----------\n", + true); // statement recovery +} +public void testBug427168() { + runNegativeTest( + new String[] { + "X.java", + "interface Producer {\n" + + "

P produce();\n" + + "}\n" + + "public class X {\n" + + " void perform(Producer r) { }\n" + + " void test() {\n" + + " perform(() -> 13); \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " perform(() -> 13); \n" + + " ^^^^^^^\n" + + "The method perform(Producer) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " perform(() -> 13); \n" + + " ^^^^^^^^\n" + + "Illegal lambda expression: Method produce of type Producer is generic \n" + + "----------\n"); +} +public void testBug427196() { + runConformTest( + new String[] { + "MainTest.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class MainTest {\n" + + " public static List copyOf (Collection c) {\n" + + " return new ArrayList<>(c);\n" + + " }\n" + + " \n" + + " public static List copyOf (Iterable c) {\n" + + " return new ArrayList<>();\n" + + " }\n" + + " \n" + + " public static void main (String[] args) {\n" + + " Function, List> function1 = c -> MainTest.copyOf(c); //OK\n" + + " Function, List> function2 = MainTest::copyOf; //error\n" + + " }\n" + + "}\n" + }); +} +public void testBug427224() { + runConformTest( + new String[] { + "Test2.java", + "import java.util.*;\n" + + "public class Test2 {\n" + + " public static native T applyToSet(java.util.Set s);\n" + + "\n" + + " public static void applyToList(java.util.List s) {\n" + + " applyToSet(new java.util.HashSet<>(s));\n" + + " }\n" + + "}\n" + }); +} +// comment 12 +public void testBug424637() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(X x, String s2);\n" + + "}\n" + + "\n" + + "public class X {\n" + + " String goo(String ...ts) {\n" + + " System.out.println(ts[0]); \n" + + " return ts[0];\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = X::goo;\n" + + " String s = i.foo(new X(), \"world\");\n" + + " System.out.println(s); \n" + + " }\n" + + "}\n" + }, + "world\n" + + "world", + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=427218, [1.8][compiler] Verify error varargs + inference +public void test427218_reduced() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " match(getLast(\"a\"), null);\n" + + " }\n" + + " public static T getLast(T... array) { return null; } // same with T[]\n" + + " public static void match(boolean b, Object foo) { }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " match(getLast(\"a\"), null);\n" + + " ^^^^^\n" + + "The method match(boolean, Object) in the type X is not applicable for the arguments (String, null)\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " match(getLast(\"a\"), null);\n" + + " ^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from String to boolean\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " public static T getLast(T... array) { return null; } // same with T[]\n" + + " ^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter array\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=427218, [1.8][compiler] Verify error varargs + inference +public void test427218() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " match(getLast(\"a\"), null);\n" + + " }\n" + + " public static T getLast(T... array) { return null; } // same with T[]\n" + + " public static void match(boolean b, Object foo) { }\n" + + " public static void match(Object o, A foo) { }\n" + + "}\n", + }, + ""); +} +public void testBug427223() { + runConformTest( + new String[] { + "Test.java", + "import java.util.*;\n" + + "public class Test {\n" + + "\n" + + " List toList(Object o) {\n" + + " if (o instanceof Optional) {\n" + + " return Arrays.asList(((Optional) o).orElse(null));\n" + + " } else {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug425183_comment8() { + // similar to what triggered the NPE, but it never did trigger + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String... args) {\n" + + " java.util.Comparator.reverseOrder().thenComparingLong(X::toLong);\n" + + " System.out.println(\"ok\");\n" + + " }\n" + + " static long toLong(T in) { return 0L; }\n" + + "}\n" + }, + "ok"); +} +public void testBug427483() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void test() {\n" + + " new TreeSet<>((String qn1, String qn2) -> {\n" + + " boolean b = true;\n" + + " System.out.println(b); // ok\n" + + " if(b) { }\n" + + " return qn1.compareTo(qn2);\n" + + " });\n" + + " }\n" + + "}\n" + }); +} +public void testBug427504() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + "\n" + + " public static Tree model(T o) {\n" + + " return Node(Leaf(o), Leaf(o));\n" + + " }\n" + + " \n" + + " interface Tree {}\n" + + " static Tree Node(Tree... children) { return null; }\n" + + " static Tree Leaf(T o) { return null; }\n" + + " \n" + + "}\n" + }); +} +public void testBug427479() { + runConformTest( + new String[] { + "Bug.java", + "import java.util.*;\n" + + "import java.util.function.BinaryOperator; \n" + + "import java.util.stream.*;\n" + + "\n" + + "public class Bug {\n" + + " \n" + + " static List names = Arrays.asList(\n" + + " \"ddd\",\n" + + " \"s\",\n" + + " \"sdfs\",\n" + + " \"sfdf d\"); \n" + + " \n" + + " public static void main(String[] args) {\n" + + " BinaryOperator> merge = (List first, List second) -> {\n" + + " first.addAll(second);\n" + + " return first;\n" + + " };\n" + + " \n" + + " Collector>> collector= Collectors.toMap(\n" + + " s -> s.length(), \n" + + " Arrays::asList,\n" + + " merge); \n" + + " Map> lengthToStrings = names.stream().collect(collector);\n" + + " \n" + + " lengthToStrings.forEach((Integer i, List l)-> {\n" + + " System.out.println(i + \" : \" + Arrays.deepToString(l.toArray()));\n" + + " });\n" + + "\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug427479b() { + runNegativeTest( + new String[] { + "Bug419048.java", + "import java.util.List;\n" + + "import java.util.Map;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "\n" + + "public class Bug419048 {\n" + + " void test1(List roster) {\n" + + " Map map = \n" + + " roster\n" + + " .stream()\n" + + " .collect(\n" + + " Collectors.toMap(\n" + + " p -> p.getLast(),\n" + + " p -> p.getLast()\n" + + " ));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug419048.java (at line 9)\n" + + " roster\n" + + " .stream()\n" + + " .collect(\n" + + " Collectors.toMap(\n" + + " p -> p.getLast(),\n" + + " p -> p.getLast()\n" + + " ));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Map to Map\n" + + "----------\n" + + "2. ERROR in Bug419048.java (at line 13)\n" + + " p -> p.getLast(),\n" + + " ^^^^^^^\n" + + "The method getLast() is undefined for the type Object\n" + + "----------\n" + + "3. ERROR in Bug419048.java (at line 14)\n" + + " p -> p.getLast()\n" + + " ^^^^^^^\n" + + "The method getLast() is undefined for the type Object\n" + + "----------\n"); +} +public void testBug427626() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void m() {\n" + + " List ss = Arrays.asList(\"1\", \"2\", \"3\");\n" + + " \n" + + " ss.stream().map(s -> {\n" + + " class L1 {};\n" + + " class L2 {\n" + + " void mm(L1 l) {}\n" + + " }\n" + + " return new L2().mm(new L1());\n" + + " }).forEach(e -> System.out.println(e));\n" + + " }\n" + + "}" + }, + // 8u20 emits just one message inferred type not conforming to upper bound. + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " ss.stream().map(s -> {\n" + + " class L1 {};\n" + + " class L2 {\n" + + " void mm(L1 l) {}\n" + + " }\n" + + " return new L2().mm(new L1());\n" + + " }).forEach(e -> System.out.println(e));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type argument(s) for map(Function)\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " return new L2().mm(new L1());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot return a void result\n" + + "----------\n"); +} +public void testBug426542() { + runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X {\n" + + " \n" + + " void foo(T o1) {\n" + + " }\n" + + "\n" + + " void foo(T o1) {\n" + + " }\n" + + "\n" + + " void bar() {\n" + + " foo((Comparable & Serializable)0);\n" + + " foo(0);\n" + + " }\n" + + "}\n" + }); +} +public void testBug426836() { + runConformTest( + new String[] { + "ReferenceToGetClass.java", + "import java.util.function.Supplier;\n" + + "\n" + + "\n" + + "public class ReferenceToGetClass {\n" + + " T extract(Supplier s) {\n" + + " return s.get();\n" + + " }\n" + + " Class test() {\n" + + " Class c = extract(this::getClass);\n" + + " return c;\n" + + " }\n" + + "}\n" + } ); +} +public void testBug428019() { + runConformTest( + new String[] { + "X.java", + "final public class X {\n" + + " static class Obj {}\n" + + " static class Dial {}\n" + + "\n" + + " void put(Class clazz, T data) {\n" + + " }\n" + + "\n" + + " static Dial wrap(Dial dl) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " static void foo(Dial dial, X context) {\n" + + " context.put(Dial.class, wrap(dial));\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X.foo(new Dial(), new X());\n" + + " }\n" + + "}\n" + }); +} +public void testBug428198() { + runConformTest( + new String[] { + "Snippet.java", + "import java.util.*;\n" + + "interface BundleRevision {}\n" + + "interface BundleDescription extends BundleRevision {}\n" + + "public class Snippet {\n" + + " static Collection test(BundleDescription[] triggers) {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " Collection triggerRevisions =\n" + + " //Type mismatch: cannot convert from Collection to Collection\n" + + " Collections\n" + + " .unmodifiableCollection(triggers == null ? Collections.EMPTY_LIST\n" + + " : Arrays.asList((BundleRevision[]) triggers));\n" + + " return triggerRevisions;\n" + + " }\n" + + "}\n" + }); +} +public void testBug428198b() { + runConformTest( + new String[] { + "Snippet.java", + "import java.util.*;\n" + + "interface BundleRevision {}\n" + + "interface BundleDescription extends BundleRevision {}\n" + + "public class Snippet {\n" + + " static Collection test(BundleDescription[] triggers) {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " Collection triggerRevisions =\n" + + " Collections\n" + + " .unmodifiableCollection(triggers == null ? Collections.emptyList()\n" + + " : Arrays.asList((BundleRevision[]) triggers));\n" + + " return triggerRevisions;\n" + + " }\n" + + "}\n" + }); +} +public void testBug428264() { + runConformTest( + new String[] { + "Y.java", + "import java.util.function.*;\n" + + "import java.util.Optional;\n" + + "\n" + + "interface I {}\n" + + "class A implements I> {}\n" + + "\n" + + "public class Y {\n" + + " Y(T o, Predicate p, Supplier> s) {}\n" + + "\n" + + " static Y> m() {\n" + + " return new Y<>(Optional.empty(), Optional::isPresent, A::new);\n" + + " }\n" + + "}\n" + }); +} +public void testBug428294() { + runConformTest( + new String[] { + "Junk5.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "\n" + + "public class Junk5 {\n" + + "\n" + + " class TestTouchDevice {\n" + + " public Object [] points;\n" + + " }\n" + + " \n" + + " public static List getTouchDevices() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static Collection getTouchDeviceParameters2(int minPoints) {\n" + + " Collection c = getTouchDevices().stream()\n" + + " .filter(d -> d.points.length >= minPoints)\n" + + " .map(d -> new Object[] { d })\n" + + " .collect(Collectors.toList());\n" + + " return c;\n" + + " }\n" + + " \n" + + " public static Collection getTouchDeviceParameters3(int minPoints) {\n" + + " return getTouchDevices().stream()\n" + + " .filter(d -> d.points.length >= minPoints)\n" + + " .map(d -> new Object[] { d })\n" + + " .collect(Collectors.toList());\n" + + " }\n" + + "}\n" + }); +} +public void testBug428291() { + runConformTest( + new String[] { + "AC3.java", + "import java.util.List;\n" + + "\n" + + "interface I0 { }\n" + + "\n" + + "interface I1 { }\n" + + "interface I1List extends List, I1 {}\n" + + "interface I2 extends I1 {\n" + + " void foo(I0 arg1);\n" + + " void bar(I0 arg2);\n" + + "}\n" + + "interface I3 extends I2 {}\n" + + "interface I4 extends I2 { }\n" + + "interface I3List extends I3>, I1List {}\n" + + "abstract class AC1 implements I3List { }\n" + + "\n" + + "abstract class AC2 {\n" + + " public static AC2 bork(AC2 f1, I3List i3l, I0> i1l) {\n" + + " return null;\n" + + " }\n" + + " public static AC2 garp(AC2 f2, I0> i1l) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public abstract class AC3 extends AC1 implements I4> {\n" + + "\n" + + " AC2 f = null;\n" + + "\n" + + " @Override\n" + + " public void foo(I0> arg1) {\n" + + " f = AC2.bork(f, this, arg1);\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void bar(I0> arg2) {\n" + + " f = AC2.garp(f, arg2);\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428275, [1.8][compiler] CCE in InferenceContext18.varArgTypes +public void testBug428275() { + runConformTest( + new String[] { + "p1/C1.java", + "package p1;\n" + + "\n" + + "import java.util.List;\n" + + "\n" + + "public class C1 {\n" + + "\n" + + " public static class CInner {\n" + + " public CInner(T2A a, T2B b) {}\n" + + " }\n" + + " \n" + + " public static class CInner2 {\n" + + " public CInner2(String n, List> arg) {}\n" + + " }\n" + + " \n" + + " public static List getList1(E... items) {\n" + + " return null;\n" + + " }\n" + + "}\n", + "Test.java", + "import java.util.List;\n" + + "\n" + + "import p1.C1;\n" + + "\n" + + "public class Test {\n" + + " void test2(List l) {\n" + + " l.add(\n" + + " new C1.CInner2<>(\"a\",\n" + + " C1.getList1(new C1.CInner<>(\"b\", 13))\n" + + " )\n" + + " );\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428352, [1.8][compiler] NPE in AllocationExpression.analyseCode when trying to pass Consumer as Function +public void test428352() { + runNegativeTest( + new String[] { + "OperationsPile.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.util.function.Consumer;\n" + + "import java.util.function.Function;\n" + + "\n" + + "class OperationsPile {\n" + + " OperationsPile(Function handler) {}\n" + + "\n" + + " private static void addAll3(Collection c, T t) {}\n" + + "\n" + + " static void adaad3(List> combined, Consumer handler) {\n" + + " addAll3(combined, new OperationsPile<>(null));\n" + + " addAll3(combined, new OperationsPile<>(handler));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in OperationsPile.java (at line 13)\n" + + " addAll3(combined, new OperationsPile<>(handler));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for OperationsPile<>\n" + + "----------\n"); +} +public void test428352b() { + runConformTest( + new String[] { + "OperationsPile.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.util.function.Consumer;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class OperationsPile {\n" + + " OperationsPile(Function handler) {}\n" + + "\n" + + " private static void addAll3(Collection c, T t) {}\n" + + "\n" + + " static void adaad3(List> combined, Consumer handler) {\n" + + " addAll3(combined, new OperationsPile<>(null));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " adaad3(null, null);\n" + + " System.out.println(13);\n" + + " }\n" + + "}\n" + }, + "13"); +} +public void testBug428307() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.*;\n" + + "\n" + + "interface Bar {\n" + + " Class type();\n" + + "}\n" + + "public class X {\n" + + " \n" + + " T[] test(Class barClass, Stream bars) {\n" + + " return get(bars.\n" + + " collect(Collectors.toMap(Bar::type,\n" + + " Function.identity(),\n" + + " ((first,second) -> first),\n" + + " HashMap::new)),\n" + + " barClass);\n" + + " }\n" + + " \n" + + " A[] get(Map,Bar> m, Class c) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428524, [1.8][compiler] NPE when using JSE8 Class Constructor ref "TheClass::new" and "TheClass" is using default no-arg constructor +public void test428524() { + runConformTest( + new String[] { + "X.java", + "import java.util.function.Supplier;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Supplier works = WithNoArgConstructor::new;\n" + + " System.out.println(works.get());\n" + + " Supplier error = WithoutNoArgConstructor::new;\n" + + " System.out.println(error.get());\n" + + " \n" + + " }\n" + + " private static class WithNoArgConstructor {\n" + + " public WithNoArgConstructor() {\n" + + " }\n" + + " public String toString() {\n" + + " return(\"WithNoArgConstructor\");\n" + + " }\n" + + " }\n" + + " private static class WithoutNoArgConstructor {\n" + + " public String toString() {\n" + + " return(\"WithOutNoArgConstructor\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "WithNoArgConstructor\n" + + "WithOutNoArgConstructor"); +} +public void testBug428786() { + runConformTest( + new String[] { + "Junk9.java", + "import java.util.*;\n" + + "public class Junk9 {\n" + + " class Node {\n" + + " public double getLayoutY() {return 12;}\n" + + " }\n" + + " class Node2 extends Node {\n" + + " }\n" + + " void junk() {\n" + + " List visibleCells = new ArrayList<>(20);\n" + + " Collections.sort(visibleCells, (Node o1, Node o2) -> Double.compare(o1.getLayoutY(), o2.getLayoutY()));\n" + + " }\n" + + "}\n" + }); +} +public void testBug429090_comment1() { + runNegativeTest( + new String[] { + "Junk10.java", + "\n" + + "public class Junk10 {\n" + + " class Observable {}\n" + + " interface InvalidationListener {\n" + + " public void invalidated(Observable observable);\n" + + " }\n" + + " public static abstract class Change {}\n" + + " interface SetChangeListener {\n" + + " void onChanged(Change change);\n" + + " }\n" + + " class SetListenerHelper {}\n" + + " public static SetListenerHelper addListener(\n" + + " SetListenerHelper helper, SetChangeListener listener) {\n" + + " return helper;\n" + + " }\n" + + " void junk() {\n" + + " addListener(null, (SetChangeListener.Change c) -> {});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Junk10.java (at line 17)\n" + + " addListener(null, (SetChangeListener.Change c) -> {});\n" + + " ^^^^^^^^^^^\n" + + "The method addListener(Junk10.SetListenerHelper, Junk10.SetChangeListener) in the type Junk10 is not applicable for the arguments (null, (SetChangeListener.Change c) -> {})\n" + + "----------\n" + + "2. ERROR in Junk10.java (at line 17)\n" + + " addListener(null, (SetChangeListener.Change c) -> {});\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "SetChangeListener.Change cannot be resolved to a type\n" + + "----------\n"); +} +public void testBug429090() { + runConformTest( + new String[] { + "Junk10.java", + "public class Junk10 {\n" + + " class Observable {}\n" + + " interface InvalidationListener {\n" + + " public void invalidated(Observable observable);\n" + + " }\n" + + " interface SetChangeListener {\n" + + " public static abstract class Change {}\n" + + " void onChanged(Change change);\n" + + " }\n" + + " class SetListenerHelper {}\n" + + " public static SetListenerHelper addListener(SetListenerHelper helper, InvalidationListener listener) {\n" + + " return helper;\n" + + " }\n" + + " public static SetListenerHelper addListener(SetListenerHelper helper, SetChangeListener listener) {\n" + + " return helper;\n" + + " }\n" + + " void junk() {\n" + + " addListener(null, new SetChangeListener () {\n" + + " public void onChanged(SetChangeListener.Change change) {}\n" + + " });\n" + + " addListener(null, (SetChangeListener.Change c) -> {});\n" + // original was without "extends Object" + " }\n" + + "}\n" + }); +} +public void testBug429490_comment33() { + runConformTest( + new String[] { + "Junk12.java", + "public class Junk12 {\n" + + " class Observable {}\n" + + " class ObservableValue {}\n" + + " interface InvalidationListener {\n" + + " public void invalidated(Observable observable);\n" + + " }\n" + + " public interface ChangeListener {\n" + + " void changed(ObservableValue observable, T oldValue, T newValue);\n" + + " }\n" + + " class ExpressionHelper {}\n" + + " public static ExpressionHelper addListener(ExpressionHelper helper, ObservableValue observable, InvalidationListener listener) {\n" + + " return helper;\n" + + " }\n" + + " public static ExpressionHelper addListener(ExpressionHelper helper, ObservableValue observable, ChangeListener listener) {\n" + + " return helper;\n" + + " }\n" + + " void junk() {\n" + + " addListener(null, null, new ChangeListener () {\n" + + " public void changed(ObservableValue observable, Object oldValue, Object newValue) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " addListener(null, null, (value, o1, o2) -> {throw new RuntimeException();});\n" + + " }\n" + + "}\n" + }); +} +public void testBug428811() { + runConformTest( + new String[] { + "MoreCollectors.java", + "import java.util.AbstractList;\n" + + "import java.util.ArrayList;\n" + + "import java.util.Arrays;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.util.stream.Collector;\n" + + "\n" + + "public class MoreCollectors {\n" + + " public static void main (String[] args) {\n" + + " ImmutableList list = Arrays.asList(\"a\", \"b\", \"c\").stream().collect(toImmutableList());\n" + + " \n" + + " System.out.println(list);\n" + + " }\n" + + " \n" + + " public static Collector> toImmutableList () {\n" + + " return Collector.of(ArrayList::new,\n" + + " List::add,\n" + + " (left, right) -> { left.addAll(right); return left; },\n" + + " ImmutableList::copyOf);\n" + + " }\n" + + " \n" + + " private static class ImmutableList extends AbstractList {\n" + + " public static ImmutableList copyOf (Collection c) {\n" + + " return new ImmutableList<>(c.toArray());\n" + + " }\n" + + "\n" + + " private Object[] array;\n" + + " \n" + + " private ImmutableList (Object[] array) {\n" + + " this.array = array;\n" + + " }\n" + + "\n" + + " @Override @SuppressWarnings(\"unchecked\")\n" + + " public T get(int index) {\n" + + " return (T)array[index];\n" + + " }\n" + + "\n" + + " @Override\n" + + " public int size() {\n" + + " return array.length;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "[a, b, c]"); +} +// all exceptions can be inferred to match +public void testBug429430() { + runConformTest( + new String[] { + "Main.java", + "import java.io.*;\n" + + "public class Main {\n" + + " public static interface Closer {\n" + + " void closeIt(T it) throws X;\n" + + " }\n" + + "\n" + + " public static void close( Closer closer, T it ) throws X {\n" + + " closer.closeIt(it);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws IOException {\n" + + " InputStream in = new ByteArrayInputStream(\"hello\".getBytes());\n" + + " close( x -> x.close(), in );\n" + + " close( InputStream::close, in );\n" + + " close( (Closer)InputStream::close, in );\n" + + " }\n" + + "}\n" + }); +} +// incompatible exceptions prevent suitable inference of exception type +public void testBug429430a() { + runNegativeTest( + new String[] { + "Main.java", + "import java.io.*;\n" + + "@SuppressWarnings(\"serial\") class EmptyStream extends Exception {}\n" + + "public class Main {\n" + + " public static interface Closer {\n" + + " void closeIt(T it) throws X;\n" + + " }\n" + + "\n" + + " public static void close( Closer closer, T it ) throws X {\n" + + " closer.closeIt(it);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws IOException, EmptyStream {\n" + + " InputStream in = new ByteArrayInputStream(\"hello\".getBytes());\n" + + " close( x -> { if (in.available() == 0) throw new EmptyStream(); x.close(); }, in );\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Main.java (at line 14)\n" + + " close( x -> { if (in.available() == 0) throw new EmptyStream(); x.close(); }, in );\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n"); +} +// one of two incompatible exceptions is caught +public void testBug429430b() { + runConformTest( + new String[] { + "Main.java", + "import java.io.*;\n" + + "@SuppressWarnings(\"serial\") class EmptyStream extends Exception {}\n" + + "public class Main {\n" + + " public static interface Closer {\n" + + " void closeIt(T it) throws X;\n" + + " }\n" + + "\n" + + " public static void close( Closer closer, T it ) throws X {\n" + + " closer.closeIt(it);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws EmptyStream {\n" + + " InputStream in = new ByteArrayInputStream(\"hello\".getBytes());\n" + + " close( x -> {\n" + + " try {\n" + + " x.close();\n" + + " } catch (IOException ioex) { throw new EmptyStream(); } \n" + + " }," + + " in);\n" + + " }\n" + + "}\n" + }); +} +public void testBug429430b2() { + runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "@SuppressWarnings(\"serial\") class EmptyStream extends Exception {}\n" + + "public class X {\n" + + " public static interface Closer {\n" + + " void closeIt(T it) throws V;\n" + + " }\n" + + "\n" + + " public static void close( Closer closer, InputStream it ) throws EmptyStream {\n" + + " closer.closeIt(it);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws EmptyStream {\n" + + " InputStream in = new ByteArrayInputStream(\"hello\".getBytes());\n" + + " close( x -> {\n" + + " if (x == null)\n" + + " throw new IOException();\n" + + " else \n" + + " throw new EmptyStream(); \n" + + " },\n" + + " in);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " throw new IOException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n" + + "2. WARNING in X.java (at line 18)\n" + + " throw new EmptyStream(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +// ensure type annotation on exception doesn't confuse the inference +public void testBug429430c() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + runConformTest( + new String[] { + "Main.java", + "import java.io.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE) @interface Severe {}\n" + + "public class Main {\n" + + " public static interface Closer {\n" + + " void closeIt(T it) throws X;\n" + + " }\n" + + "\n" + + " public static void close( Closer closer, T it ) throws X {\n" + + " closer.closeIt(it);\n" + + " }\n" + + "\n" + + " static @Severe IOException getException() { return new IOException(\"severe\"); }\n" + + " public static void main(String[] args) throws IOException {\n" + + " InputStream in = new ByteArrayInputStream(\"hello\".getBytes());\n" + + " close( x -> {\n" + + " if (in.available() > 0)\n" + + " x.close();\n" + + " else\n" + + " throw getException();\n" + + " },\n" + + " in);\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug429490() { + runConformTest( + new String[] { + "Junk11.java", + "public class Junk11 {\n" + + " class Observable {}\n" + + " class ObservableValue {}\n" + + " interface InvalidationListener {\n" + + " public void invalidated(Observable observable);\n" + + " }\n" + + " public interface ChangeListener {\n" + + " void changed(ObservableValue observable, T oldValue, T newValue);\n" + + " }\n" + + " class ExpressionHelper {}\n" + + " public static ExpressionHelper addListener(ExpressionHelper helper, ObservableValue observable, InvalidationListener listener) {\n" + + " return helper;\n" + + " }\n" + + " public static ExpressionHelper addListener(ExpressionHelper helper, ObservableValue observable, ChangeListener listener) {\n" + + " return helper;\n" + + " }\n" + + " void junk() {\n" + + " addListener(null, null, new InvalidationListener () {\n" + + " public void invalidated(Observable o) {throw new RuntimeException();}\n" + + " });\n" + + " addListener(null, null, (o) -> {throw new RuntimeException();});\n" + + " }\n" + + "}\n" + }); +} +public void testBug429424() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " List list = new ArrayList<>();\n" + + " list.addAll(X.newArrayList());\n" + + " System.out.println(list);\n" + + " }\n" + + " \n" + + " public static List newArrayList () {\n" + + " return new ArrayList();\n" + + " }\n" + + "}\n" + + "\n" + }); +} +public void testBug426537() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(J[] list, I> i) {\n" + + " sort(list, i);\n" + + " }\n" + + " \n" + + " T[] sort(T[] list, I i) {\n" + + " return list;\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo(J[] list, I> i) {\n" + + " ^\n" + + "J is a raw type. References to generic type J should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " sort(list, i);\n" + + " ^^^^\n" + + "The method sort(T[], I) in the type X is not applicable for the arguments (J[], I>)\n" + + "----------\n"); +} +public void testBug426537b() { + runConformTest( + new String[] { + "Test.java", + "interface C {}\n" + + "\n" + + "class MImpl {}\n" + + "\n" + + "interface S { T get(); }\n" + + "\n" + + "public class Test {\n" + + " static C> m1() {\n" + + " return m2(MImpl::new);\n" + + " }\n" + + " \n" + + " static > C m2(S s) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + }); +} +public void testBug426537c() { + // touching MImpl#RAW before type inference we got undesired results from #typeArguments() + runConformTest( + new String[] { + "Ups.java", + "public class Ups {\n" + + " static Object innocent(MImpl o) {\n" + + " return o.remove(\"nice\");\n" + // method lookup triggers initialization of the RawTypeBinding. + " }\n" + + "}\n", + "Test.java", + "interface S { T get(); }\n" + + "interface F { R apply(T t); }\n" + + "interface C { }\n" + + "interface IM {}\n" + + "class MImpl implements IM { \n" + + " public V remove(Object key) { return null; } \n" + + "}\n" + + "public final class Test {\n" + + "\n" + + " static \n" + + " C> m1(F f, C c) {\n" + + " return m2(f, MImpl::new, c);\n" + + " }\n" + + "\n" + + " static >\n" + + " C m2(F classifier,\n" + + " S mapFactory,\n" + + " C downstream) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug429203() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + runNegativeTest( + false /*skipJavac */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError, + new String[] { + "DTest.java", + "import java.util.function.Function;\n" + + "\n" + + "\n" + + "public class DTest {\n" + + " public DTest(Function func) { }\n" + + " \n" + + " public DTest(DTest dti) {}\n" + + " public DTest() {}\n" + + " \n" + + " public static void main(String[] args) {\n" + + " DTest t1 = new DTest(new DTest());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in DTest.java (at line 11)\n" + + " DTest t1 = new DTest(new DTest());\n" + + " ^^^^^\n" + + "Redundant specification of type arguments \n" + + "----------\n", + null, true, customOptions); +} +public void testBug430296() { + runNegativeTest( + new String[] { + "AnnotationCollector.java", + "import java.lang.annotation.*;\n" + + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import java.util.stream.*;\n" + + "\n" + + "public abstract class AnnotationCollector {\n" + + " \n" + + " Map test2(Stream persons) {\n" + + " return persons.collect(Collectors.toMap((Person p) -> p.getLastName(),\n" + + " Function::identity,\n" + + " (p1, p2) -> p1));\n" + + " }\n" + + "}\n" + + "\n" + + "class Person {\n" + + " String getLastName() { return \"\"; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in AnnotationCollector.java (at line 9)\n" + + " return persons.collect(Collectors.toMap((Person p) -> p.getLastName(),\n" + + " ^^^^^\n" + + "The method toMap(Function, Function, BinaryOperator) in the type Collectors is not applicable for the arguments ((Person p) -> {}, Function::identity, ( p1, p2) -> {})\n" + + "----------\n" + + "2. ERROR in AnnotationCollector.java (at line 9)\n" + + " return persons.collect(Collectors.toMap((Person p) -> p.getLastName(),\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Function to Function\n" + + "----------\n" + + "3. ERROR in AnnotationCollector.java (at line 10)\n" + + " Function::identity,\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The type Function does not define identity(T) that is applicable here\n" + + "----------\n"); +} +public void testBug430759() { + runConformTest( + new String[] { + "Test.java", + "import java.beans.*;\n" + + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "\n" + + "public abstract class Test implements Function {\n" + + "\n" + + " public static final Test getTest() {\n" + + " return new Test() {\n" + + " protected final Map results = Collections.synchronizedMap(new HashMap());\n" + + " @Override\n" + + " public R apply(final T t) {\n" + + " ResultSupplier result = results.get(t);\n" + + " return result.get();\n" + + " }\n" + + " class ResultSupplier implements Supplier {\n" + + " @Override\n" + + " public synchronized R get() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=431577 [1.8][bytecode] Bad type on operand stack (different than Bug 429733) +public void testBug431577() { + runConformTest( + new String[] { + "Test.java", + "import java.util.function.Function;\n" + + "import java.util.function.IntFunction;\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " new Test<>().test((Integer i) -> null);\n" + + " }\n" + + " void test(Function f) {\n" + + " }\n" + + " void test(int i, IntFunction f) {\n" + + " new State<>(new Val<>(i));\n" + + " }\n" + + " static class State {\n" + + " State(Val o) {\n" + + " }\n" + + " }\n" + + " static class Val {\n" + + " Val(T t) {}\n" + + " }\n" + + "}" + }); +} +public void testBug432110() { + runConformTest( + new String[] { + "Bug.java", + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "class Bug\n" + + "{\n" + + " // fully inline\n" + + " // compiles successfully\n" + + " Stream flatten1(\n" + + " final Stream> input)\n" + + " {\n" + + " return input.flatMap(item -> item.stream().map(value -> value));\n" + + " }\n" + + "\n" + + " // lambda using braces\n" + + " // compiles with error in eclipse, successfully with javac\n" + + " Stream flatten2(\n" + + " final Stream> input)\n" + + " {\n" + + " return input.flatMap(item -> {\n" + + " return item.stream().map(value -> value);\n" + + " });\n" + + " }\n" + + "\n" + + " // without map step\n" + + " // compiles successfully\n" + + " Stream flatten3(\n" + + " final Stream> input)\n" + + " {\n" + + " return input.flatMap(item -> {\n" + + " return item.stream();\n" + + " });\n" + + " }\n" + + "\n" + + " // with map step, but not inline\n" + + " // compiles successfully\n" + + " Stream flatten4(\n" + + " final Stream> input)\n" + + " {\n" + + " return input.flatMap(item -> {\n" + + " final Function mapper = value -> value;\n" + + " return item.stream().map(mapper);\n" + + " });\n" + + " }\n" + + "\n" + + " // with map step, but outer lambda is not inline\n" + + " // compiles successfully\n" + + " Stream flatten5(\n" + + " final Stream> input)\n" + + " {\n" + + " final Function, ? extends Stream> func = item -> {\n" + + " return item.stream().map(value -> value);\n" + + " };\n" + + " return input.flatMap(func);\n" + + " }\n" + + "}\n"}); +} +public void testBug433158() { + runNegativeTest( + new String[] { + "CollectorsMaps.java", + "\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "import static java.util.stream.Collectors.*;\n" + + "\n" + + "public class CollectorsMaps {/*Q*/\n" + + " private static class Pair {\n" + + " public final L lhs; public final R rhs;\n" + + " public Pair(L lhs, R rhs) { this.lhs = lhs; this.rhs = rhs; }\n" + + " public R rhs() { return rhs; }\n" + + " public L lhs() { return lhs; }\n" + + " public Pair keepingRhs(N newLhs) { return new Pair<>(newLhs, rhs); }\n" + + " /*E*/}\n" + + "\n" + + " static Map> invert(Map> packages) {\n" + + " return packages.entrySet().stream().map(e -> new Pair<>(e.getValue(), e.getKey())).flatMap(\n" + + " //The method collect(Collector) in the type Stream\n" + + " //is not applicable for the arguments \n" + + " //(Collector,capture#3-of ?,Map>>)\n" + + " p -> p.lhs.stream().map(p::keepingRhs)).collect(\n" + + " groupingBy(Pair::lhs, mapping(Pair::rhs, toList())));\n" + + " }\n" + + "}\n" + }, + ""); +} +public void testBug432626() { + runConformTest( + new String[] { + "StreamInterface2.java", + "import java.util.ArrayList;\n" + + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.stream.Collector;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public interface StreamInterface2 {\n" + + "\n" + + " static Map> terminalAsMapToList(\n" + + " Function classifier,\n" + + " Supplier> supplier,\n" + + " Class classOfE) throws E {\n" + + " return terminalAsCollected(classOfE, Collectors.groupingBy(\n" + + " classifier,\n" + + " //This is OK:\n" + + " //Redundant specification of type arguments >\n" + + " () -> new HashMap>(),\n" + + " Collector.> of(\n" + + " () -> new ArrayList<>(),\n" + + " (left, value) -> left.add(value),\n" + + " (left, right) -> combined(left, right))), supplier);\n" + + " }\n" + + " static Map> terminalAsMapToList2(\n" + + " Function classifier,\n" + + " Supplier> supplier,\n" + + " Class classOfE) throws E {\n" + + " //After removing type arguments, ECJ shows error, javac doesn't:\n" + + " //Type mismatch: cannot convert from HashMap> to Map>\n" + + " return terminalAsCollected(classOfE, Collectors.groupingBy(\n" + + " classifier,\n" + + " () -> new HashMap<>(),\n" + + " Collector.> of(\n" + + " () -> new ArrayList<>(),\n" + + " (left, value) -> left.add(value),\n" + + " (left, right) -> combined(left, right))), supplier);\n" + + " }\n" + + " static M terminalAsCollected(\n" + + " Class classOfE,\n" + + " Collector collector,\n" + + " Supplier> supplier) throws E {\n" + + " try(Stream s = supplier.get()) {\n" + + " return s.collect(collector);\n" + + " } catch(RuntimeException e) {\n" + + " throw unwrapCause(classOfE, e);\n" + + " }\n" + + " }\n" + + " static E unwrapCause(Class classOfE, RuntimeException e) throws E {\n" + + " Throwable cause = e.getCause();\n" + + " if(classOfE.isInstance(cause) == false) {\n" + + " throw e;\n" + + " }\n" + + " throw classOfE.cast(cause);\n" + + " }\n" + + " static ArrayList combined(ArrayList left, ArrayList right) {\n" + + " left.addAll(right);\n" + + " return left;\n" + + " }\n" + + "}\n" + }); +} +public void testBug432626_reduced() { + runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collector;\n" + + "import java.util.stream.Collectors;\n" + + "public interface X {\n" + + " static Map> terminalAsMapToList(Function classifier) {\n" + + " return terminalAsCollected(Collectors.groupingBy(\n" + + " classifier,\n" + + " () -> new HashMap<>(),\n" + + " (Collector,ArrayList>) null));\n" + + " }\n" + + " static M terminalAsCollected(Collector collector) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433825 [1.8][compiler] Internal compiler error: NullPointerException in AllocationExpression#resolvePart3 +public void testBug433825() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public void bla() {\n" + + " boolean b = Boolean.TRUE.booleanValue();\n" + + " List c1 = new ArrayList<>();\n" + + " new Bar(b ? c1 : new ArrayList<>()); // this line crashes ecj (4.4 I20140429-0800), but not ecj (eclipse 3.8.2) and javac\n" + + " }\n" + + " private static class Bar {\n" + + " public Bar(Collection col) { }\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433825 [1.8][compiler] Internal compiler error: NullPointerException in AllocationExpression#resolvePart3 +public void testBug433825a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public void bla() {\n" + + " boolean b = Boolean.TRUE.booleanValue();\n" + + " new Bar(b ? 0 : new ArrayList<>());\n" + + " }\n" + + " private static class Bar {\n" + + " public Bar(Collection col) { }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " new Bar(b ? 0 : new ArrayList<>());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X.Bar((b ? 0 : new ArrayList<>())) is undefined\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " new Bar(b ? 0 : new ArrayList<>());\n" + + " ^\n" + + "Type mismatch: cannot convert from int to Collection\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " public Bar(Collection col) { }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X.Bar(Collection) is never used locally\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=435462 [1.8] NPE in codegen with nested conditional and allocation expressions +public void testBug435462() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public void bla() {\n" + + " boolean b = Boolean.TRUE.booleanValue();\n" + + " List c1 = new ArrayList<>();\n" + + " new Bar(b ? new ArrayList<>(b ? new ArrayList<>() : c1) : c1);\n" + + " }\n" + + " private static class Bar {\n" + + " public Bar(Collection col) { }\n" + + " }\n" + + "}" + }); +} +public void testBug437007() { + runConformTest( + new String[] { + "ExecutorTests.java", + "import java.util.*;\n" + + "\n" + + "public class ExecutorTests {\n" + + " List tasks = Arrays.asList(\n" + + " () -> {\n" + + " System.out.println(\"task1 start\");\n" + + " }\n" + + " );\n" + + "\n" + + " public void executeInSync(){\n" + + " tasks.stream().forEach(Runnable::run);\n" + + " }\n" + + "}\n" + }); +} +public void testBug435689() { + runConformTest( + new String[] { + "Test.java", + "import java.util.function.*;\n" + + "class Foo {\n" + + " void apply(Function> bar) {}\n" + + "}\n" + + "\n" + + "class Bar {\n" + + " void setBar(String bar){}\n" + + "}\n" + + "public class Test {\n" + + " void test() {\n" + + " new Foo().apply(bar -> bar::setBar);\n" + + " }\n" + + "}\n" + }); +} +public void testBug433845() { + runNegativeTest( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "\n" + + "public abstract class Test {\n" + + " public interface MUIElement {\n" + + " \n" + + " }\n" + + "\n" + + " private interface Listener> {\n" + + " public void call(Event event);\n" + + " }\n" + + " \n" + + " public static class Event> {\n" + + " \n" + + " }\n" + + " \n" + + " public interface WWidget {\n" + + " public void set(Listener> handler);\n" + + " }\n" + + " \n" + + " public static abstract class A> {\n" + + " \n" + + " public final W createWidget(final M element) {\n" + + " W w = get(); \n" + + " // works\n" + + " w.set((Evente) -> call(e));\n" + + " // fails\n" + + " w.set(this::call);\n" + + " // fails\n" + + " w.set((e) -> call(e));\n" + + " return w;\n" + + " }\n" + + " \n" + + " private W get() {\n" + + " return null;\n" + + " }\n" + + " \n" + + " private void call(Event event) {\n" + + " \n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\Test.java (at line 28)\n" + + " w.set(this::call);\n" + + " ^^^\n" + + "The method set(Test.Listener>) in the type Test.WWidget is not applicable for the arguments (this::call)\n" + + "----------\n" + + "2. ERROR in test\\Test.java (at line 28)\n" + + " w.set(this::call);\n" + + " ^^^^^^^^^^\n" + + "The type Test.A does not define call(Test.Event>) that is applicable here\n" + + "----------\n" + + "3. ERROR in test\\Test.java (at line 30)\n" + + " w.set((e) -> call(e));\n" + + " ^^^^\n" + + "The method call(Test.Event) in the type Test.A is not applicable for the arguments (Test.Event>)\n" + + "----------\n"); +} +public void testBug435187() { + runNegativeTest( + false /*skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "ExtractLocalLambda.java", + "\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collector;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class ExtractLocalLambda {\n" + + " static Stream, String>> map;\n" + + " static Collector, ?, Map>> groupingBy;\n" + + " private static Stream stream(Entry, String> p) { return null; }\n" + + " private static Entry keep(Entry, String> p, String leftHS2) { return null; }\n" + + "\n" + + " static Map> beforeRefactoring() {\n" + + " // Extract local variable from the parameter to flatMap:\n" + + " return map.flatMap(\n" + + " p -> stream(p).map(leftHS -> {\n" + + " String leftHS2 = leftHS;\n" + + " return keep(p, leftHS2);\n" + + " })\n" + + " ).collect(groupingBy);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in ExtractLocalLambda.java (at line 5)\n" + + " import java.util.function.Function;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import java.util.function.Function is never used\n" + + "----------\n"); +} +public void testBug435767() { + runConformTest( + new String[] { + "DummyClass.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import java.util.stream.*;\n" + + "public class DummyClass {\n" + + "\n" + + " public void method() {\n" + + "\n" + + " // Cases where there is no error\n" + + " final Supplier> suppliers = this.memoize(() -> new HashSet<>());\n" + + "\n" + + " final Supplier> noMemoize = () -> suppliers.get().stream()\n" + + " .filter(path -> path.startsWith(\"\"))\n" + + " .collect(Collectors.toMap(path -> this.getKey(path), path -> this.getValue(path)));\n" + + "\n" + + " // Case where there is errors.\n" + + " final Supplier> memoize = this.memoize(() -> suppliers.get().stream()\n" + + " .filter(path -> path.startsWith(\"\"))\n" + + " .collect(Collectors.toMap(path -> this.getKey(path), path -> this.getValue(path))));\n" + + "\n" + + " // Error message are : Description\n" + + " // Resource Path Location Type\n" + + " // The method getKey(String) in the type DummyClass is not applicable for the arguments (Object) DummyClass.java line 23 Java Problem\n" + + " // The method getValue(String) in the type DummyClass is not applicable for the arguments (Object) DummyClass.java line 23 Java Problem\n" + + "\n" + + " }\n" + + "\n" + + " private Supplier memoize(final Supplier delegate) {\n" + + " return delegate;\n" + + " }\n" + + "\n" + + " private Object getKey(final String path) {\n" + + " return path;\n" + + " }\n" + + "\n" + + " private Object getValue(final String path) {\n" + + " return path;\n" + + " }\n" + + "}\n" + }, + ""); +} +public void testBug434483() { + runConformTest( + new String[] { + "Foo.java", + "import java.util.*;\n" + + "public class Foo {\n" + + " \n" + + " // Similar to Guava's newLinkedList()\n" + + " public static LinkedList newLinkedList() {\n" + + " return new LinkedList();\n" + + " }\n" + + " \n" + + " private final ThreadLocal> brokenQueue = ThreadLocal.withInitial(Foo::newLinkedList);\n" + + " \n" + + " private final ThreadLocal> workingQueue1 = ThreadLocal.withInitial(Foo::newLinkedList);\n" + + " \n" + + " private final ThreadLocal> workingQueue2 = ThreadLocal.withInitial(() -> Foo.newLinkedList());\n" + + "\n" + + "}\n" + }); +} +public void testBug441734() { + runConformTest( + new String[] { + "Example.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "class Example {\n" + + " void foo(Iterable x) { }\n" + + "\n" + + " void bar(Consumer> f) { }\n" + + "\n" + + " void test() {\n" + + " //call 1: lambda w/argument type - OK\n" + + " bar((Iterable x) -> foo(x));\n" + + "\n" + + " //call 2: lambda w/explicit type - OK\n" + + " this. bar(x -> foo(x));\n" + + "\n" + + " //call 3: method ref w/explicit type - OK\n" + + " this. bar(this::foo);\n" + + "\n" + + " //call 4: lambda w/implicit type - correctly(?) fails*\n" + + " //bar(x -> foo(x));\n" + + "\n" + + " //call 5: method ref w/implicit type - BUG!\n" + + " bar(this::foo); // errors!\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=442245, [1.8][compiler?] These source files lead eclipse to hang (even just on copy/paste) +public void testBug442245() { + runConformTest( + new String[] { + "test/Pattern.java", + "package test;\n" + + "import test.Tuples.Tuple;\n" + + "import test.Tuples.Tuple1;\n" + + "import test.Tuples.Tuple10;\n" + + "import test.Tuples.Tuple11;\n" + + "import test.Tuples.Tuple12;\n" + + "import test.Tuples.Tuple13;\n" + + "import test.Tuples.Tuple2;\n" + + "import test.Tuples.Tuple3;\n" + + "import test.Tuples.Tuple4;\n" + + "import test.Tuples.Tuple5;\n" + + "import test.Tuples.Tuple6;\n" + + "import test.Tuples.Tuple7;\n" + + "import test.Tuples.Tuple8;\n" + + "import test.Tuples.Tuple9;\n" + + "\n" + + "public interface Pattern {\n" + + "\n" + + " boolean isApplicable(Object o);\n" + + "\n" + + " R apply(Object o);\n" + + "\n" + + " static Pattern of(Decomposition decomposition, R prototype) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " static Pattern> of(Decomposition> decomposition, E1 e1) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1));\n" + + " }\n" + + "\n" + + " static Pattern> of(Decomposition> decomposition, E1 e1, E2 e2) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2));\n" + + " }\n" + + "\n" + + " static Pattern> of(Decomposition> decomposition, E1 e1,\n" + + " E2 e2, E3 e3) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3));\n" + + " }\n" + + "\n" + + " static Pattern> of(\n" + + " Decomposition> decomposition, E1 e1, E2 e2, E3 e3, E4 e4) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3, e4));\n" + + " }\n" + + "\n" + + " static Pattern> of(\n" + + " Decomposition> decomposition, E1 e1, E2 e2, E3 e3, E4 e4, E5 e5) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3, e4, e5));\n" + + " }\n" + + "\n" + + " static Pattern> of(\n" + + " Decomposition> decomposition, E1 e1, E2 e2, E3 e3, E4 e4, E5 e5, E6 e6) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3, e4, e5, e6));\n" + + " }\n" + + "\n" + + " static Pattern> of(\n" + + " Decomposition> decomposition, E1 e1, E2 e2, E3 e3, E4 e4, E5 e5,\n" + + " E6 e6, E7 e7) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3, e4, e5, e6, e7));\n" + + " }\n" + + "\n" + + " static Pattern> of(\n" + + " Decomposition> decomposition, E1 e1, E2 e2, E3 e3, E4 e4, E5 e5,\n" + + " E6 e6, E7 e7, E8 e8) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3, e4, e5, e6, e7, e8));\n" + + " }\n" + + "\n" + + " static Pattern> of(\n" + + " Decomposition> decomposition, E1 e1, E2 e2, E3 e3, E4 e4,\n" + + " E5 e5, E6 e6, E7 e7, E8 e8, E9 e9) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3, e4, e5, e6, e7, e8, e9));\n" + + " }\n" + + "\n" + + " static Pattern> of(\n" + + " Decomposition> decomposition, E1 e1, E2 e2, E3 e3,\n" + + " E4 e4, E5 e5, E6 e6, E7 e7, E8 e8, E9 e9, E10 e10) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10));\n" + + " }\n" + + "\n" + + " static Pattern> of(\n" + + " Decomposition> decomposition, E1 e1, E2 e2, E3 e3,\n" + + " E4 e4, E5 e5, E6 e6, E7 e7, E8 e8, E9 e9, E10 e10, E11 e11) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11));\n" + + " }\n" + + "\n" + + " static Pattern> of(\n" + + " Decomposition> decomposition, E1 e1, E2 e2,\n" + + " E3 e3, E4 e4, E5 e5, E6 e6, E7 e7, E8 e8, E9 e9, E10 e10, E11 e11, E12 e12) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12));\n" + + " }\n" + + "\n" + + " static Pattern> of(\n" + + " Decomposition> decomposition, E1 e1,\n" + + " E2 e2, E3 e3, E4 e4, E5 e5, E6 e6, E7 e7, E8 e8, E9 e9, E10 e10, E11 e11, E12 e12, E13 e13) {\n" + + " return Pattern.of(decomposition, Tuples.of(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13));\n" + + " }\n" + + "\n" + + " static interface Decomposition {\n" + + "\n" + + " R apply(T t);\n" + + " }\n" + + "}\n", + "test/Tuples.java", + "package test;\n"+ + "\n"+ + "import java.io.Serializable;\n"+ + "import java.util.Objects;\n"+ + "import java.util.stream.Collectors;\n"+ + "import java.util.stream.Stream;\n"+ + "\n"+ + "public final class Tuples {\n"+ + "\n"+ + " private Tuples() {\n"+ + " throw new AssertionError(Tuples.class.getName() + \" is not intended to be instantiated.\");\n"+ + " }\n"+ + "\n"+ + " public static Tuple0 of() {\n"+ + " return Tuple0.instance();\n"+ + " }\n"+ + "\n"+ + " public static Tuple1 of(T t) {\n"+ + " return new Tuple1<>(t);\n"+ + " }\n"+ + "\n"+ + " public static Tuple2 of(T1 t1, T2 t2) {\n"+ + " return new Tuple2<>(t1, t2);\n"+ + " }\n"+ + "\n"+ + " public static Tuple3 of(T1 t1, T2 t2, T3 t3) {\n"+ + " return new Tuple3<>(t1, t2, t3);\n"+ + " }\n"+ + "\n"+ + " public static Tuple4 of(T1 t1, T2 t2, T3 t3, T4 t4) {\n"+ + " return new Tuple4<>(t1, t2, t3, t4);\n"+ + " }\n"+ + "\n"+ + " public static Tuple5 of(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) {\n"+ + " return new Tuple5<>(t1, t2, t3, t4, t5);\n"+ + " }\n"+ + "\n"+ + " public static Tuple6 of(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) {\n"+ + " return new Tuple6<>(t1, t2, t3, t4, t5, t6);\n"+ + " }\n"+ + "\n"+ + " public static Tuple7 of(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5,\n"+ + " T6 t6, T7 t7) {\n"+ + " return new Tuple7<>(t1, t2, t3, t4, t5, t6, t7);\n"+ + " }\n"+ + "\n"+ + " public static Tuple8 of(T1 t1, T2 t2, T3 t3,\n"+ + " T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) {\n"+ + " return new Tuple8<>(t1, t2, t3, t4, t5, t6, t7, t8);\n"+ + " }\n"+ + "\n"+ + " public static Tuple9 of(T1 t1, T2 t2,\n"+ + " T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) {\n"+ + " return new Tuple9<>(t1, t2, t3, t4, t5, t6, t7, t8, t9);\n"+ + " }\n"+ + "\n"+ + " public static Tuple10 of(T1 t1,\n"+ + " T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10) {\n"+ + " return new Tuple10<>(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10);\n"+ + " }\n"+ + "\n"+ + " public static Tuple11 of(\n"+ + " T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11) {\n"+ + " return new Tuple11<>(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11);\n"+ + " }\n"+ + "\n"+ + " public static Tuple12 of(\n"+ + " T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12) {\n"+ + " return new Tuple12<>(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12);\n"+ + " }\n"+ + "\n"+ + " public static Tuple13 of(\n"+ + " T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13) {\n"+ + " return new Tuple13<>(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13);\n"+ + " }\n"+ + "\n"+ + " private static String stringify(Object... objects) {\n"+ + " return Stream\n"+ + " .of(objects)\n"+ + " .map(o -> (o == null) ? \"null\" : o.toString())\n"+ + " .collect(Collectors.joining(\", \", \"(\", \")\"));\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple0 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = -8715576573413569748L;\n"+ + "\n"+ + " private static final Tuple0 INSTANCE = new Tuple0();\n"+ + "\n"+ + " private Tuple0() {\n"+ + " }\n"+ + "\n"+ + " public static Tuple0 instance() {\n"+ + " return INSTANCE;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 0;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify();\n"+ + " }\n"+ + "\n"+ + " private Object readResolve() {\n"+ + " return INSTANCE;\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple1 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = -8005498887610699234L;\n"+ + "\n"+ + " public final T _1;\n"+ + "\n"+ + " public Tuple1(T t) {\n"+ + " this._1 = t;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 1;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple1)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple1 that = (Tuple1) o;\n"+ + " return Objects.equals(this._1, that._1);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple2 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = -1359843718617881431L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + "\n"+ + " public Tuple2(T1 t1, T2 t2) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 2;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple2)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple2 that = (Tuple2) o;\n"+ + " return Objects.equals(this._1, that._1) && Objects.equals(this._2, that._2);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple3 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = 1353320010987934190L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + "\n"+ + " public Tuple3(T1 t1, T2 t2, T3 t3) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 3;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple3)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple3 that = (Tuple3) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple4 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = -835853771811712181L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + " public final T4 _4;\n"+ + "\n"+ + " public Tuple4(T1 t1, T2 t2, T3 t3, T4 t4) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " this._4 = t4;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 4;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple4)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple4 that = (Tuple4) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3)\n"+ + " && Objects.equals(this._4, that._4);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3, _4);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3, _4);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple5 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = 8365094604388856720L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + " public final T4 _4;\n"+ + " public final T5 _5;\n"+ + "\n"+ + " public Tuple5(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " this._4 = t4;\n"+ + " this._5 = t5;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 5;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple5)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple5 that = (Tuple5) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3)\n"+ + " && Objects.equals(this._4, that._4)\n"+ + " && Objects.equals(this._5, that._5);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3, _4, _5);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3, _4, _5);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple6 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = -5282391675740552818L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + " public final T4 _4;\n"+ + " public final T5 _5;\n"+ + " public final T6 _6;\n"+ + "\n"+ + " public Tuple6(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " this._4 = t4;\n"+ + " this._5 = t5;\n"+ + " this._6 = t6;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 6;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple6)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple6 that = (Tuple6) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3)\n"+ + " && Objects.equals(this._4, that._4)\n"+ + " && Objects.equals(this._5, that._5)\n"+ + " && Objects.equals(this._6, that._6);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3, _4, _5, _6);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3, _4, _5, _6);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple7 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = 6913366542759921153L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + " public final T4 _4;\n"+ + " public final T5 _5;\n"+ + " public final T6 _6;\n"+ + " public final T7 _7;\n"+ + "\n"+ + " public Tuple7(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " this._4 = t4;\n"+ + " this._5 = t5;\n"+ + " this._6 = t6;\n"+ + " this._7 = t7;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 7;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple7)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple7 that = (Tuple7) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3)\n"+ + " && Objects.equals(this._4, that._4)\n"+ + " && Objects.equals(this._5, that._5)\n"+ + " && Objects.equals(this._6, that._6)\n"+ + " && Objects.equals(this._7, that._7);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3, _4, _5, _6, _7);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3, _4, _5, _6, _7);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple8 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = 117641715065938183L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + " public final T4 _4;\n"+ + " public final T5 _5;\n"+ + " public final T6 _6;\n"+ + " public final T7 _7;\n"+ + " public final T8 _8;\n"+ + "\n"+ + " public Tuple8(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " this._4 = t4;\n"+ + " this._5 = t5;\n"+ + " this._6 = t6;\n"+ + " this._7 = t7;\n"+ + " this._8 = t8;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 8;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple8)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple8 that = (Tuple8) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3)\n"+ + " && Objects.equals(this._4, that._4)\n"+ + " && Objects.equals(this._5, that._5)\n"+ + " && Objects.equals(this._6, that._6)\n"+ + " && Objects.equals(this._7, that._7)\n"+ + " && Objects.equals(this._8, that._8);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3, _4, _5, _6, _7, _8);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3, _4, _5, _6, _7, _8);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple9 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = -1578540921124551840L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + " public final T4 _4;\n"+ + " public final T5 _5;\n"+ + " public final T6 _6;\n"+ + " public final T7 _7;\n"+ + " public final T8 _8;\n"+ + " public final T9 _9;\n"+ + "\n"+ + " public Tuple9(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " this._4 = t4;\n"+ + " this._5 = t5;\n"+ + " this._6 = t6;\n"+ + " this._7 = t7;\n"+ + " this._8 = t8;\n"+ + " this._9 = t9;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 9;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple9)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple9 that = (Tuple9) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3)\n"+ + " && Objects.equals(this._4, that._4)\n"+ + " && Objects.equals(this._5, that._5)\n"+ + " && Objects.equals(this._6, that._6)\n"+ + " && Objects.equals(this._7, that._7)\n"+ + " && Objects.equals(this._8, that._8)\n"+ + " && Objects.equals(this._9, that._9);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3, _4, _5, _6, _7, _8, _9);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3, _4, _5, _6, _7, _8, _9);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple10 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = 7991284808329690986L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + " public final T4 _4;\n"+ + " public final T5 _5;\n"+ + " public final T6 _6;\n"+ + " public final T7 _7;\n"+ + " public final T8 _8;\n"+ + " public final T9 _9;\n"+ + " public final T10 _10;\n"+ + "\n"+ + " public Tuple10(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " this._4 = t4;\n"+ + " this._5 = t5;\n"+ + " this._6 = t6;\n"+ + " this._7 = t7;\n"+ + " this._8 = t8;\n"+ + " this._9 = t9;\n"+ + " this._10 = t10;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 10;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple10)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple10 that = (Tuple10) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3)\n"+ + " && Objects.equals(this._4, that._4)\n"+ + " && Objects.equals(this._5, that._5)\n"+ + " && Objects.equals(this._6, that._6)\n"+ + " && Objects.equals(this._7, that._7)\n"+ + " && Objects.equals(this._8, that._8)\n"+ + " && Objects.equals(this._9, that._9)\n"+ + " && Objects.equals(this._10, that._10);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple11 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = 3493688489700741360L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + " public final T4 _4;\n"+ + " public final T5 _5;\n"+ + " public final T6 _6;\n"+ + " public final T7 _7;\n"+ + " public final T8 _8;\n"+ + " public final T9 _9;\n"+ + " public final T10 _10;\n"+ + " public final T11 _11;\n"+ + "\n"+ + " public Tuple11(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " this._4 = t4;\n"+ + " this._5 = t5;\n"+ + " this._6 = t6;\n"+ + " this._7 = t7;\n"+ + " this._8 = t8;\n"+ + " this._9 = t9;\n"+ + " this._10 = t10;\n"+ + " this._11 = t11;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 11;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple11)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple11 that = (Tuple11) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3)\n"+ + " && Objects.equals(this._4, that._4)\n"+ + " && Objects.equals(this._5, that._5)\n"+ + " && Objects.equals(this._6, that._6)\n"+ + " && Objects.equals(this._7, that._7)\n"+ + " && Objects.equals(this._8, that._8)\n"+ + " && Objects.equals(this._9, that._9)\n"+ + " && Objects.equals(this._10, that._10)\n"+ + " && Objects.equals(this._11, that._11);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple12 implements Tuple, Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = -175212910367376967L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + " public final T4 _4;\n"+ + " public final T5 _5;\n"+ + " public final T6 _6;\n"+ + " public final T7 _7;\n"+ + " public final T8 _8;\n"+ + " public final T9 _9;\n"+ + " public final T10 _10;\n"+ + " public final T11 _11;\n"+ + " public final T12 _12;\n"+ + "\n"+ + " public Tuple12(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " this._4 = t4;\n"+ + " this._5 = t5;\n"+ + " this._6 = t6;\n"+ + " this._7 = t7;\n"+ + " this._8 = t8;\n"+ + " this._9 = t9;\n"+ + " this._10 = t10;\n"+ + " this._11 = t11;\n"+ + " this._12 = t12;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 12;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple12)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple12 that = (Tuple12) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3)\n"+ + " && Objects.equals(this._4, that._4)\n"+ + " && Objects.equals(this._5, that._5)\n"+ + " && Objects.equals(this._6, that._6)\n"+ + " && Objects.equals(this._7, that._7)\n"+ + " && Objects.equals(this._8, that._8)\n"+ + " && Objects.equals(this._9, that._9)\n"+ + " && Objects.equals(this._10, that._10)\n"+ + " && Objects.equals(this._11, that._11)\n"+ + " && Objects.equals(this._12, that._12);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static final class Tuple13 implements Tuple,\n"+ + " Serializable {\n"+ + "\n"+ + " private static final long serialVersionUID = 2027952127515234777L;\n"+ + "\n"+ + " public final T1 _1;\n"+ + " public final T2 _2;\n"+ + " public final T3 _3;\n"+ + " public final T4 _4;\n"+ + " public final T5 _5;\n"+ + " public final T6 _6;\n"+ + " public final T7 _7;\n"+ + " public final T8 _8;\n"+ + " public final T9 _9;\n"+ + " public final T10 _10;\n"+ + " public final T11 _11;\n"+ + " public final T12 _12;\n"+ + " public final T13 _13;\n"+ + "\n"+ + " public Tuple13(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10, T11 t11, T12 t12, T13 t13) {\n"+ + " this._1 = t1;\n"+ + " this._2 = t2;\n"+ + " this._3 = t3;\n"+ + " this._4 = t4;\n"+ + " this._5 = t5;\n"+ + " this._6 = t6;\n"+ + " this._7 = t7;\n"+ + " this._8 = t8;\n"+ + " this._9 = t9;\n"+ + " this._10 = t10;\n"+ + " this._11 = t11;\n"+ + " this._12 = t12;\n"+ + " this._13 = t13;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int arity() {\n"+ + " return 13;\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public boolean equals(Object o) {\n"+ + " if (o == this) {\n"+ + " return true;\n"+ + " } else if (o == null || !(o instanceof Tuple13)) {\n"+ + " return false;\n"+ + " } else {\n"+ + " final Tuple13 that = (Tuple13) o;\n"+ + " return Objects.equals(this._1, that._1)\n"+ + " && Objects.equals(this._2, that._2)\n"+ + " && Objects.equals(this._3, that._3)\n"+ + " && Objects.equals(this._4, that._4)\n"+ + " && Objects.equals(this._5, that._5)\n"+ + " && Objects.equals(this._6, that._6)\n"+ + " && Objects.equals(this._7, that._7)\n"+ + " && Objects.equals(this._8, that._8)\n"+ + " && Objects.equals(this._9, that._9)\n"+ + " && Objects.equals(this._10, that._10)\n"+ + " && Objects.equals(this._11, that._11)\n"+ + " && Objects.equals(this._12, that._12)\n"+ + " && Objects.equals(this._13, that._13);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public int hashCode() {\n"+ + " return Objects.hash(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13);\n"+ + " }\n"+ + "\n"+ + " @Override\n"+ + " public String toString() {\n"+ + " return Tuples.stringify(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static interface Tuple {\n"+ + "\n"+ + " int arity();\n"+ + "\n"+ + " @Override\n"+ + " boolean equals(Object obj);\n"+ + "\n"+ + " @Override\n"+ + " int hashCode();\n"+ + "\n"+ + " @Override\n"+ + " String toString();\n"+ + " }\n"+ + "\n"+ + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=439594 [1.8][compiler] nested lambda type incorrectly inferred vs javac +public void test439594() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.Predicate;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + " protected static interface IListEntry {\n" + + " public T visitRecordsWithResult(Function,T> func); \n" + + " }\n" + + " protected static final class ImmutableRecord {\n" + + " public ImmutableRecord(Record r) { }\n" + + " }\n" + + " protected static final class Record {}\n" + + " public List compilesWithEclipseAndJavac() \n" + + " {\n" + + " return visitEntriesWithResult( stream -> {\n" + + " return stream.map( entry -> {\n" + + " final List result1 = entry.visitRecordsWithResult( stream2 -> stream2\n" + + " .filter( somePredicate() )\n" + + " .map( ImmutableRecord::new )\n" + + " .collect( Collectors.toList() )\n" + + " ); \n" + + " return result1;\n" + + " }).flatMap( List::stream ).collect( Collectors.toCollection( ArrayList::new ) );\n" + + " }); \n" + + " } \n" + + " public List compilesWithJavacButNotEclipse1() \n" + + " {\n" + + " return visitEntriesWithResult( stream -> {\n" + + " return stream.map( entry -> {\n" + + " return entry.visitRecordsWithResult( stream2 -> stream2\n" + + " .filter( somePredicate() )\n" + + " .map( ImmutableRecord::new )\n" + + " .collect( Collectors.toList() )\n" + + " ); \n" + + " }).flatMap( List::stream ).collect( Collectors.toCollection( ArrayList::new ) );\n" + + " }); \n" + + " } \n" + + " public List compilesWithJavacButNotEclipse2() \n" + + " {\n" + + " return visitEntriesWithResult( stream -> {\n" + + " return stream.map( entry -> entry.visitRecordsWithResult( stream2 -> stream2\n" + + " .filter( somePredicate() )\n" + + " .map( ImmutableRecord::new )\n" + + " .collect( Collectors.toList() ) )\n" + + " ).flatMap( List::stream ).collect( Collectors.toCollection( ArrayList::new ) );\n" + + " }); \n" + + " } \n" + + " public List compilesWithJavacButNotEclipse3() \n" + + " {\n" + + " return visitEntriesWithResult( stream -> stream.map( entry -> entry.visitRecordsWithResult( stream2 -> stream2\n" + + " .filter( somePredicate() )\n" + + " .map( ImmutableRecord::new )\n" + + " .collect( Collectors.toList() ) )\n" + + " )\n" + + " .flatMap( List::stream )\n" + + " .collect( Collectors.toCollection( ArrayList::new ) )\n" + + " ); \n" + + " } \n" + + " private static Predicate somePredicate() {\n" + + " return record -> true;\n" + + " } \n" + + " private T visitEntriesWithResult(Function,T> func) {\n" + + " return func.apply( new ArrayList().stream() );\n" + + " }\n" + + "}\n" + }, + ""); +} +// reduced version for analysis (no need to run during normal tests) +public void _test439594_small() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.Predicate;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + " protected static interface IListEntry {\n" + + " public T visitRecordsWithResult(Function,T> func); \n" + + " }\n" + + " protected static final class ImmutableRecord {\n" + + " public ImmutableRecord(Record r) { }\n" + + " }\n" + + " protected static final class Record {}\n" + + " public List compilesWithJavacButNotEclipse1() \n" + + " {\n" + + " return visitEntriesWithResult( stream -> {\n" + + " return stream.map( entry -> {\n" + + " return entry.visitRecordsWithResult( stream2 -> stream2\n" + + " .filter( somePredicate() )\n" + + " .map( ImmutableRecord::new )\n" + + " .collect( Collectors.toList() )\n" + + " ); \n" + + " }).flatMap( List::stream ).collect( Collectors.toCollection( ArrayList::new ) );\n" + + " }); \n" + + " } \n" + + " private static Predicate somePredicate() {\n" + + " return record -> true;\n" + + " } \n" + + " private T visitEntriesWithResult(Function,T> func) {\n" + + " return func.apply( new ArrayList().stream() );\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=433852, [1.8][compiler] Javac rejects type inference results that ECJ accepts +public void test433852() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Optional;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(test(Stream.of(Stream.of(\"3\"))));\n" + + " System.out.println(test2(Stream.of(Stream.of(\"1\")).skip(1)));\n" + + " System.out.println(test31(Stream.of(Stream.of(\"2\")).skip(1)));\n" + + " }\n" + + " static Optional> test(Stream> s31) {\n" + + " return s31.map(s2 -> s2.map(s1 -> Integer.parseInt(s1))).findAny();\n" + + " }\n" + + " static Object test2(Stream> s3) {\n" + + " return s3.map(s2 -> s2.map(s1 -> Integer.parseInt(s1))).flatMap(Function.identity()).findAny().orElse(\n" + + " X.class);\n" + + " }\n" + + " static Stream test31(Stream> s3) {\n" + + " return s3.map(s2 -> s2.map(s1 -> Integer.parseInt(s1))).findAny().orElse(Stream.of(new Object()));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " return s31.map(s2 -> s2.map(s1 -> Integer.parseInt(s1))).findAny();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Optional> to Optional>\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " return s3.map(s2 -> s2.map(s1 -> Integer.parseInt(s1))).flatMap(Function.identity()).findAny().orElse(\n" + + " ^^^^^^\n" + + "The method orElse(Integer) in the type Optional is not applicable for the arguments (Class)\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " return s3.map(s2 -> s2.map(s1 -> Integer.parseInt(s1))).findAny().orElse(Stream.of(new Object()));\n" + + " ^^^^^^\n" + + "The method orElse(Stream) in the type Optional> is not applicable for the arguments (Stream)\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=442916, [1.8][inference] Type Inference is broken for CompletableFuture then-methods +public void test442916() { + this.runConformTest( + new String[] { + "X.java", + "import static java.util.concurrent.CompletableFuture.completedFuture;\n" + + "import java.util.Arrays;\n" + + "import java.util.concurrent.CompletableFuture;\n" + + "public class X {\n" + + " public static CompletableFuture cf(int value) {\n" + + " return completedFuture(value);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " cf(1).thenCompose((xInt) -> cf(2).thenApply((zInt) -> Arrays.asList(xInt, zInt)))\n" + + " .thenAccept((ints) -> {\n" + + " /* !!!! ints is incorrectly inferred to be an Object, but it is List */\n" + + " System.out.println(ints.get(0) + ints.get(1)); // should print 3;\n" + + " });\n" + + " }\n" + + "}\n" + }, + "3"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=442769, [1.8][compiler] Invalid type inference using Stream +public void test442769() { + this.runConformTest( + new String[] { + "X.java", + "import java.nio.file.Path;\n" + + "import java.nio.file.Paths;\n" + + "import java.util.Arrays;\n" + + "import java.util.HashMap;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "import java.util.stream.Collector;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "import java.io.Serializable;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map allocated = new HashMap<>();\n" + + " Arrays.asList(\"a\", \"b\", \"c\", \"d\", \"e\") // List\n" + + " .stream() // Stream\n" + + " .map(Paths::get) // Stream\n" + + " .flatMap(path -> allocated.keySet() // Set\n" + + " .stream() // Stream\n" + + " .map(group -> Pair.of(group, path) /*Pair*/) // Stream>\n" + + " ) // Stream [FAIL]\n" + + " .collect(Collectors.toList()) // List\n" + + " .forEach(item -> System.out.println(item.getKey() + \": \" + item.getValue())); // Consumer\n" + + " // with explicit type\n" + + " Arrays.asList(\"a\", \"b\", \"c\", \"d\", \"e\") // List\n" + + " .stream() // Stream\n" + + " .map(Paths::get) // Stream\n" + + " .flatMap(path -> allocated.keySet() // Set\n" + + " .stream() // Stream\n" + + " .>map(group -> Pair.of(group, path) /*Pair*/) // Stream>\n" + + " ) // Stream>\n" + + " .collect(Collectors.toList()) // List>\n" + + " .forEach(item -> System.out.println(item.getKey() + \": \" + item.getValue())); // Consumer>\n" + + " }\n" + + "}\n" + + "abstract class Pair implements Map.Entry, Comparable>, Serializable {\n" + + " public static Pair of(final L left, final R right) {\n" + + " return null;\n" + + " }\n" + + " public final L getKey() {\n" + + " return null;\n" + + " }\n" + + " public R getValue() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + ""); +} +// Test allocation expression boxing compatibility +public void testAllocationBoxingCompatibility() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int m(T o1, byte o2) {return 1;} \n" + + " static boolean call() {\n" + + " return m(new Long(12l), new Byte((byte)1)) == 1;\n" + + " }\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(call());\n" + + " }\n" + + "}\n", + }, "true"); +} +// NPE while building JRE8: https://bugs.eclipse.org/bugs/show_bug.cgi?id=437444#c113 +public void test437444_c113() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " final List[] ls = Util.cast(new List<>[] { null });\n" + + " \n" + + "}\n" + + "class Util {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public static T cast(Object x) {\n" + + " return (T) x;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " final List[] ls = Util.cast(new List<>[] { null });\n" + + " ^^^^\n" + + "Incorrect number of arguments for type List; it cannot be parameterized with arguments <>\n" + + "----------\n"); +} +// Error while building JRE8: https://bugs.eclipse.org/bugs/show_bug.cgi?id=437444#c113 +public void test437444_c113a() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " final List[] ls = Util.cast(new List[] { null });\n" + + " \n" + + "}\n" + + "class Util {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public static T cast(Object x) {\n" + + " return (T) x;\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=434394, [1.8] inference fails in some cases when conditional expression is involved +public void test434394() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collections;\n" + + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public void bla() {\n" + + " boolean b = Boolean.TRUE.booleanValue();\n" + + " List c1 = new ArrayList<>();\n" + + " Collections.sort(c1, new Foo(new State<>((b ? new Val<>(\"AAAA\") : new Val<>(\"BBBB\"))))); // Cannot infer type arguments for State\n" + + " Collections.sort(c1,new Foo(b ? new State<>(new Val<>(\"AAAA\")) : new State<>(new Val<>(\"BBBB\")))); // this is fine\n" + + " }\n" + + " static class Foo implements Comparator{\n" + + " public Foo(State st) {\n" + + " //\n" + + " }\n" + + " @Override\n" + + " public int compare(String o1, String o2) {\n" + + " // TODO Auto-generated method stub\n" + + " return 0;\n" + + " }\n" + + " }\n" + + " static class State {\n" + + " State(Val o) {\n" + + " }\n" + + " }\n" + + " static class Val {\n" + + " Val(T t) {}\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=445725, [1.8][inference] Type inference not occurring with lambda expression and constructor reference +public void test445725() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Arrays;\n" + + "import java.util.Collection;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + "/**\n" + + " * Takes a collection, applies a mapper to it, and then passes the result into the finishing\n" + + " * function\n" + + " */\n" + + " public static RESULT mapped(Collection collection,\n" + + " Function mapper,\n" + + " Function, RESULT> finisher)\n" + + " {\n" + + " return mapped(collection.stream(), mapper, finisher);\n" + + " }\n" + + " /**\n" + + " * Takes a stream, applies a mapper to it, and then passes the result into the finishing function\n" + + " */\n" + + " public static RESULT mapped(Stream stream,\n" + + " Function mapper,\n" + + " Function, RESULT> finisher)\n" + + " {\n" + + " return finisher.apply(stream.map(mapper).collect(Collectors.toList()));\n" + + " }\n" + + " public static void example()\n" + + " {\n" + + " mapped(Stream.of(\"1, 2, 3\"), Integer::parseInt, ArrayList::new);\n" + + " mapped(Arrays.asList(\"1, 2, 3\"), Integer::parseInt, ArrayList::new);\n" + + "\n" + + " mapped(Stream.of(\"1, 2, 3\"), Integer::parseInt, IntCollection::new);\n" + + " mapped(Arrays.asList(\"1, 2, 3\"), Integer::parseInt, IntCollection::new);\n" + + " }\n" + + " public static class IntCollection extends ArrayList\n" + + " {\n" + + " public IntCollection(Collection numbers)\n" + + " {\n" + + " super(numbers);\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +public void test447767() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void bar(String t);\n" + + "}\n" + + "public class X {\n" + + " X(String x) {}\n" + + " X(T x) { \n" + + " System.out.println(\"Here\");\n" + + " }\n" + + " X(T x, String ...strings) {}\n" + + " public void one(X c){}\n" + + " public void two() {\n" + + " one(new X<>((String s) -> { }));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"\").two();\n" + + " }\n" + + "}\n", + }, + "Here"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426633, [1.8][compiler] Compiler generates code that invokes inapplicable method. +public void test426633c() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " default void foo (T... p) {}\n" + + "}\n" + + "abstract class A {\n" + + " public abstract void foo(Object [] p);\n" + + "}\n" + + "abstract class B extends A implements I {\n" + + "}\n" + + "public abstract class X extends B implements I {\n" + + " public static void main(B b) {\n" + + " b.foo(\"hello\", \"world\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " default void foo (T... p) {}\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter p\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426633, [1.8][compiler] Compiler generates code that invokes inapplicable method. +public void test426633d() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " default void foo (T... p) {}\n" + + "}\n" + + "abstract class A {\n" + + " public void foo(Object [] p) {}\n" + + "}\n" + + "abstract class B extends A implements I {\n" + + "}\n" + + "public abstract class X extends B implements I {\n" + + " public static void main(B b) {\n" + + " b.foo(\"hello\", \"world\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " default void foo (T... p) {}\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter p\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " abstract class B extends A implements I {\n" + + " ^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public abstract class X extends B implements I {\n" + + " ^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike A.foo(Object[]) and I.foo(Object...)\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " b.foo(\"hello\", \"world\");\n" + + " ^^^\n" + + "The method foo(T...) of type I cannot be invoked as it is overridden by an inapplicable method\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426633, [1.8][compiler] Compiler generates code that invokes inapplicable method. +public void test426633e() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " default void foo (T... p) {}\n" + + "}\n" + + "abstract class A {\n" + + " public void foo(String [] p) {}\n" + + "}\n" + + "abstract class B extends A implements I {\n" + + "}\n" + + "public abstract class X extends B implements I {\n" + + " public static void main(B b) {\n" + + " b.foo(\"hello\", \"world\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " default void foo (T... p) {}\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter p\n" + + "----------\n"); +} +// original: +public void testBug452788a() { + runConformTest( + new String[] { + "Test.java", + "import java.util.function.Function;\n" + + "\n" + + "interface Test {\n" + + "\n" + + " Test create(B3 b);\n" + + "\n" + + " Test transform(Function> f);\n" + + "\n" + + " default Test wrap(Function f) {\n" + + " return transform(a -> create(f.apply(a)));\n" + + " }\n" + + "}\n" + }); +} +// variants: +public void testBug452788b() { + runConformTest( + new String[] { + "Test.java", + "import java.util.function.Function;\n" + + "\n" + + "interface Test {\n" + + "\n" + + " Test create(B3 b);\n" + + "\n" + + " Test transform(Function> f);\n" + + "\n" + + " default Test wrap(Function f) {\n" + + " return transform((A a) -> create(f.apply(a)));\n" + // explicitly typed lambda + " }\n" + + " default Function> test1(Function f) {\n" + + " return a -> create(f.apply(a));\n" + // remove outer invocation + " }\n" + + " default Function>> test2(Function f) {\n" + + " return a1 -> a2 -> create(f.apply(a2));\n" + // outer lambda instead of outer invocation + " }\n" + + "}\n" + }); +} +// diamond allocation instead of method (was OK before the patch). +public void testBug452788c() { + runConformTest( + new String[] { + "Test2.java", + "import java.util.function.Function;\n" + + "\n" + + "\n" + + "public interface Test2 {\n" + + " Test2 transform(Function> f);\n" + + "\n" + + " default Test2 wrap(Function f) {\n" + + " return transform(a -> new TestImpl<>(f.apply(a)));\n" + + " }\n" + + "}\n" + + "\n" + + "class TestImpl implements Test2 {\n" + + "\n" + + " public TestImpl(A a) { }\n" + + "\n" + + " @Override\n" + + " public Test2 transform(Function> f) {\n" + + " return null;\n" + + " } \n" + + "}\n" + }); +} +public void testBug457079() { + runConformTest( + new String[] { + "Foo.java", + "import java.util.Collections;\n" + + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "import java.util.function.Function;\n" + + "\n" + + "class Foo {\n" + + " static Map foo(K value, Function function) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " static void bar(Set set) {\n" + + " Map> map = foo(\"\", e -> Collections.emptySet());\n" + + " }\n" + + "}\n" + }); +} +public void testBug458396() { + runNegativeTest( + new String[] { + "Main.java", + "import java.util.List;\n" + + "\n" + + "interface MyTickContext { }\n" + + "abstract class MyEntity {\n" + + " abstract void tick(MyTickContext ctx);\n" + + "}\n" + + "\n" + + "public class Main {\n" + + "\n" + + " protected static final MyTickContext tickContext = new MyTickContext() {\n" + + " public void method1(MyEntity e) {\n" + + " removeEntity( e );\n" + + " }\n" + + " };\n" + + "\n" + + " public static final class Game {\n" + + " public void method2(List ents) {\n" + + " ents.forEach( e -> e.tick(tickContext) );\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Main.java (at line 12)\n" + + " removeEntity( e );\n" + + " ^^^^^^^^^^^^\n" + + "The method removeEntity(MyEntity) is undefined for the type new MyTickContext(){}\n" + + "----------\n"); +} +public void testBug455945() { + runConformTest( + new String[] { + "Test.java", + "import java.util.function.BiFunction;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.Predicate;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " static Tuple2, Seq> splitAtDoesntCompile(Stream stream, long position) {\n" + + " return seq(stream)\n" + + " .zipWithIndex()\n" + + " .partition(t -> t.v2 < position)\n" + + " .map((v1, v2) -> tuple(\n" + + " v1.map(t -> t.v1),\n" + + " v2.map(t -> t.v1)\n" + + " ));\n" + + " }\n" + + "\n" + + " static Tuple2, Seq> splitAtCompiles(Stream stream, long position) {\n" + + " return seq(stream)\n" + + " .zipWithIndex()\n" + + " .partition(t -> t.v2 < position)\n" + + " .map((v1, v2) -> Test., Seq>tuple(\n" + + " v1.map(t -> t.v1),\n" + + " v2.map(t -> t.v1)\n" + + " ));\n" + + " }\n" + + "\n" + + " static Seq seq(Stream stream) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " static Tuple2 tuple(T1 v1, T2 v2) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface I {\n" + + " T get();\n" + + " I map(Function f);\n" + + "}\n" + + "\n" + + "interface Seq {\n" + + " Seq> zipWithIndex();\n" + + " Tuple2, Seq> partition(Predicate predicate);\n" + + " Seq map(Function mapper);\n" + + "}\n" + + "\n" + + "class Tuple2 {\n" + + " T1 v1;\n" + + " T2 v2;\n" + + " \n" + + " R map(BiFunction function) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=445231, [compiler] IllegalAccessError running Eclipse-compiled class +// This is a bug in Oracle JREs. Workaround in ECJ: https://bugs.eclipse.org/bugs/show_bug.cgi?id=466675 +public void testBug445231() { + runConformTest( + true, + new String[] { + "com/n/Bug.java", + "package com.n;\n" + + "public class Bug {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new Bug().go();\n" + + " System.err.println(\"Ok\");\n" + + " } catch (IllegalAccessError e) {\n" + + " System.err.println(\"Error\");\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " public void go() {\n" + + " Class clazz = Buggered.Foo.class;\n" + + " System.err.println(\"Here we go\");\n" + + " if (clazz.isAnonymousClass()) {\n" + + " System.err.println(\"is anon\");\n" + + " } else {\n" + + " System.err.println(\"not anon\");\n" + + " }\n" + + " }\n" + + "}\n", + "com/g/Base.java", + "package com.g;\n" + + "class Base2{}\n" + + "class Base {\n" + + " class A {}\n" + + " static class Builder> {\n" + + " public B setJobName() {\n" + + " return null;\n" + + " }\n" + + " public Base2 setJobName2(B b) {\n" + + " return null;\n" + + " }\n" + + + // Wildcard + " public void foo(H> h) {\n" + + " return;\n" + + " }\n" + + " private class H {}\n" + + " }\n" + + " static class Builder2 {\n" + + " public > B setJobName3() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " static class R {}\n" + + " public static class Builder3 {\n" + + " public B setJobName() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public static class Builder4 {\n" + + " public Builder3 setJobName() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + + // Testing Parameters + " static class Builder5 {\n" + + " public > void foo(B b) {}\n" + + " }\n" + + + "}\n" + + + "class Base3 {\n" + + " static class A{}\n" + + "}\n" + , + + "com/g/Child.java", + "package com.g;\n" + + "import com.g.Base.R;\n" + + "public final class Child {\n" + + " public static class Builder extends Base.Builder> {\n" + + " public void setDummyName(){}\n" + + " }\n" + + " public static class Builder2 extends Base.Builder2 {}\n" + + " public static class Builder3 extends Base.Builder3 {}\n" + + " public static class Builder4 extends Base.Builder4 {}\n" + + + " public static class Builder5 extends Base.Builder5 {} \n" + + "}\n", + "com/n/Buggered.java", + "package com.n;\n" + + "import com.g.Child;\n" + + "class Z{}\n" + + "public final class Buggered {\n" + + " public static final class Foo {}\n" + + " void unused() {\n" + + " Child.Builder c = new Child.Builder();\n" + + " c.setJobName();\n" + + " c.setJobName2(new Child.Builder());\n" + + " Child.Builder cb = new Child.Builder();\n" + + " cb.setJobName();\n" + + " cb.setJobName2(new Child.Builder());\n" + + " Child.Builder2 cb2 = new Child.Builder2();\n" + + " cb2.setJobName3();\n" + + " Child.Builder3 cb3 = new Child.Builder3();\n" + + " cb3.setJobName();\n" + + " Child.Builder4 cb4 = new Child.Builder4();\n" + + " cb4.setJobName();\n" + + + " Child.Builder5 cb5 = new Child.Builder5();\n" + + " cb5.foo(null);\n" + + + // Wildcard + " c.foo(null);\n" + + " }\n" + + "}\n" + }, + null, null, + "Here we go\n" + + "not anon\n" + + "Ok", null); +} +public void testBug463728() { + runConformTest( + new String[] { + "Main.java", + "import java.util.function.Function;\n" + + "\n" + + "\n" + + "class Color {\n" + + " \n" + + "}\n" + + "\n" + + "class TypeMapper {\n" + + "\n" + + " public TypeMapper() {\n" + + " }\n" + + " public R orElse(R result) {\n" + + " return result;\n" + + " }\n" + + "}\n" + + "\n" + + "public class Main {\n" + + " Color A;\n" + + " Color B;\n" + + "\n" + + " public static TypeMapper mapType(Function mapper) {\n" + + " return new TypeMapper();\n" + + " }\n" + + "\n" + + " public Color getForeground(Object element) {\n" + + " return mapType(library -> {\n" + + " return (element != null ? A : B);\n" + + " }).orElse(null);\n" + + " }\n" + + "}\n" + }); +} +public void testBug470942() { + runConformTest( + new String[] { + "EclipeMarsLamdaIssueWontBuild.java", + "import java.util.function.Supplier;\n" + + "\n" + + "public class EclipeMarsLamdaIssueWontBuild {\n" + + " class MyClass {\n" + + " long getNumber() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " private interface VoidSupplier {\n" + + " void perform();\n" + + " }\n" + + "\n" + + " long processTxContent() {\n" + + " return withLogging(() -> new MyClass().getNumber());\n" + + " }\n" + + "\n" + + " private static void withLogging(final VoidSupplier supplier) {\n" + + " // Do some logging\n" + + " }\n" + + "\n" + + " private static T withLogging(final Supplier supplier) {\n" + + " // Do some logging\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug468999() { + runConformTest( + new String[] { + "Main.java", + "interface ExceptionAction\n" + + "{\n" + + " T run() throws Exception;\n" + + "}\n" + + "\n" + + "interface Action extends ExceptionAction\n" + + "{\n" + + " @Override\n" + + " U run();\n" + + "}\n" + + "\n" + + "public class Main\n" + + "{\n" + + " public static void main(String[] args) {\n" + + " runAction(() -> { // ERROR HERE\n" + + " return \"\";\n" + + " });\n" + + " }\n" + + "\n" + + " static void runAction(ExceptionAction action) {\n" + + " System.out.println(\"run with exceptions\");\n" + + " }\n" + + "\n" + + " static void runAction(Action action) {\n" + + " System.out.println(\"run without exceptions\");\n" + + " }\n" + + "}\n" + }); +} +public void testBug470826() { + runConformTest( + new String[] { + "EcjVsCollect.java", + "import java.util.ArrayList;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class EcjVsCollect {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try (final Stream> stream = getStream()) {\n" + + " stream.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);\n" + + "// ArrayList> foo = stream.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);\n" + + " }\n" + + " }\n" + + "\n" + + " private static Stream> getStream() {\n" + + " return Stream.empty();\n" + + " }\n" + + "\n" + + " private interface Record {\n" + + " K getKey();\n" + + " }\n" + + "}\n" + }); +} +public void testBug466487() { + runConformTest( + new String[] { + "C.java", + "import java.util.*;\n" + + "import java.util.stream.*;\n" + + "import static java.util.Arrays.asList;\n" + + "\n" + + "public class C {\n" + + " static final List DIGITS = Collections.unmodifiableList(asList(0,1,2,3,4,5,6,7,8,9));\n" + + " \n" + + " Collection flatMapSolutions(final boolean b) {\n" + + " Collection solutions = \n" + + " DIGITS.stream().flatMap( s -> {\n" + + " return b ? Stream.empty() : Stream.of(\"\");\n" + + " }) .collect(Collectors.toList());\n" + + " return solutions;\n" + + " }\n" + + "}\n" + }); +} +public void testBug472426() { + runConformTest( + new String[] { + "InferenceBug.java", + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "import java.util.function.BiFunction;\n" + + "\n" + + "public class InferenceBug {\n" + + "\n" + + " public static void main(String[] args) {\n" + + "\n" + + " // compiles\n" + + " List l = Collections.singletonList(\"foo\");\n" + + " apply(Foo::foo, l);\n" + + "\n" + + " // won't compile\n" + + " apply(Foo::foo, Collections.singletonList(\"foo\"));\n" + + " }\n" + + "\n" + + " static void apply(BiFunction fun, T value) {\n" + + " }\n" + + "\n" + + " static class Foo {\n" + + " public Foo foo(List i) {\n" + + " return this;\n" + + " }\n" + + "\n" + + " public Foo foo(String... i) {\n" + + " return this;\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug469753() { + runConformTest( + new String[] { + "LambdaBug.java", + "import java.util.AbstractMap;\n" + + "import java.util.Iterator;\n" + + "import java.util.Map.Entry;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class LambdaBug {\n" + + "\n" + + " class Item {\n" + + " String foo;\n" + + " }\n" + + "\n" + + " public void bug(String catalogKey, Iterator items) {\n" + + " go(transform(items, i -> pair(i.foo, i)));\n" + + " }\n" + + "\n" + + " public static Entry pair(K key, V value) {\n" + + " return new AbstractMap.SimpleImmutableEntry(key, value);\n" + + " }\n" + + "\n" + + " void go(Iterator> items) {\n" + + " }\n" + + "\n" + + " public static Iterator transform(Iterator fromIterator, Function function) {\n" + + " return null;\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug470958() { + runConformTest( + new String[] { + "Bug470958.java", + "import java.time.*;\n" + + "import java.util.*;\n" + + "import java.util.concurrent.*;\n" + + "import static java.util.concurrent.CompletableFuture.*;\n" + + "import static java.util.stream.Collectors.*;\n" + + "\n" + + "class Hotel {}\n" + + "\n" + + "class Bug470958 {\n" + + " public Map>> asyncLoadMany(List codes, LocalDate begin, LocalDate end) {\n" + + " return loadMany(codes, begin, end)\n" + + " .entrySet()\n" + + " .stream()\n" + + " .collect(toMap(Map.Entry::getKey, entry -> completedFuture(entry.getValue())));\n" + + " }\n" + + "\n" + + " public Map> loadMany(List codes, LocalDate begin, LocalDate end) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug470542() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "\n" + + "public class X {\n" + + " void test() {\n" + + " process(missing::new);\n" + + " }\n" + + " \n" + + " void process(Consumer c) { }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " process(missing::new);\n" + + " ^^^^^^^\n" + + "missing cannot be resolved to a type\n" + + "----------\n"); +} +public void testBug471280_comment0() { + runConformTest( + new String[] { + "Test0.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import java.util.concurrent.*;\n" + + "\n" + + "public class Test0 {\n" + + " public CompletableFuture> does_not_compile() throws Exception {\n" + + " CompletableFuture> firstAsync = new CompletableFuture<>();\n" + + " firstAsync.complete(Collections.singletonList(\"test\"));\n" + + " // The following line gives error \"Type mismatch: cannot convert from CompletableFuture to CompletableFuture>\"\n" + + " return transform(firstAsync, first -> Collections.singletonList(first.get(0)));\n" + + " }\n" + + "\n" + + " public CompletableFuture> does_compile() throws Exception {\n" + + " CompletableFuture> firstAsync = new CompletableFuture<>();\n" + + " firstAsync.complete(Collections.singletonList(\"test\"));\n" + + " return transform(firstAsync, first -> {\n" + + " return Collections.singletonList(first.get(0));\n" + + " });\n" + + " }\n" + + "\n" + + " public CompletableFuture transform(CompletableFuture future, Function fun) throws Exception {\n" + + " return future.thenApply(fun);\n" + + " }\n" + + "}\n" + }); +} +public void testBug471280_comment3() { + runConformTest( + new String[] { + "Test3.java", + "import java.util.*;\n" + + "import java.util.stream.*;\n" + + "\n" + + "public class Test3 {\n" + + " public T generic(T value) {\n" + + " return value;\n" + + " }\n" + + "\n" + + " public void mapExample(Map input) {\n" + + " // does not compile with ejc: Type mismatch: cannot convert from Map to Map\n" + + " Map mapped = input.entrySet()\n" + + " .stream()\n" + + " .collect(Collectors.toMap(e -> e.getKey(), e -> generic(e.getValue())));\n" + + " }\n" + + "}\n" + }); +} +public void testBug464496() { + runConformTest( + new String[] { + "Value.java", + "public class Value {\n" + + " private final V value;\n" + + " public Value(V value) {\n" + + " this.value = value;\n" + + " }\n" + + " public V get() {\n" + + " return value;\n" + + " }\n" + + " public static V getValue(Value value) {\n" + + " return value.get();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Value intValue = new Value<>(42);\n" + + " long longPrimitive = getValue(intValue); // fails in 1.8 compiler \n" + + " System.out.println(longPrimitive);\n" + + " }\n" + + "}\n" + }, + "42"); +} +public void testBug473657() { + runConformTest( + new String[] { + "T2.java", + "interface I {\n" + + "}\n" + + "\n" + + "@SuppressWarnings({\"unchecked\", \"rawtypes\"})\n" + + "abstract class T1 implements I {\n" + + " public I t(I l2) {\n" + + " return T2.m((I) this, (I) l2);\n" + + " }\n" + + " public I t(Number l2) {\n" + + " return T2.m((I) this, (I) T2.t(l2));\n" + + " }\n" + + "}\n" + + "\n" + + "public abstract class T2 {\n" + + " public static I t(T t) {\n" + + " return null;\n" + + " }\n" + + " public static I m(I l1, I l2) {\n" + + " return null;\n" + + " }\n" + + " public static I m(T l1, Number l2) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug478848() { + runConformTest( + new String[] { + "InferenceBug.java", + "import java.util.*;\n" + + "public class InferenceBug {\n" + + " \n" + + " static class Wrapper {\n" + + " T value;\n" + + " public T getValue() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " \n" + + " static class C1 {\n" + + " //an optional array of String wrappers\n" + + " public Optional[]> optionalArrayOfStringWrappers() {\n" + + " return Optional.empty();\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " C1 c1 = new C1();\n" + + " try {\n" + + " for (Wrapper attribute: c1.optionalArrayOfStringWrappers().get()) {\n" + + " // error in previous line:\n" + + " // Can only iterate over an array or an instance of java.lang.Iterable\n" + + " }\n" + + " } catch (NoSuchElementException nsee) {\n" + + " System.out.print(\"No such element\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "No such element"); +} +public void testBug479167() { + runConformTest( + new String[] { + "ToArray.java", + "import java.io.Serializable;\n" + + "interface ArrayFunction {\n" + + " E[] apply(@SuppressWarnings(\"unchecked\") S... es);\n" + + "}\n" + + "public class ToArray implements ArrayFunction {\n" + + " public final @SafeVarargs @Override E[] apply(S... es) {\n" + + " return es;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " ArrayFunction toArray = new ToArray<>();\n" + + " String[][] array = toArray.apply(args);\n" + + " System.out.print(array.getClass().getName());\n" + + " }\n" + + "}\n" + }, + "[[Ljava.lang.String;"); +} +public void testBug477751() { + runConformTest( + new String[] { + "Test.java", + "import java.util.function.Function;\n" + + "class Test {\n" + + " public static U map(T value, Function mapper) {\n" + + " if (value != null)\n" + + " return mapper.apply(value);\n" + + " return null;\n" + + " }\n" + + "\n" + + " String value;\n" + + " \n" + + " void test() {\n" + + " map(map(value, nnVal1 -> nnVal1.toLowerCase()),\n" + + " nnVal2 -> nnVal2.length());\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug482416() { + runConformTest( + new String[] { + "CompilerRegression.java", + "import java.util.Comparator;\n" + + "import java.util.concurrent.Callable;\n" + + "\n" + + "public class CompilerRegression {\n" + + " private ObjectProperty>> comparator = new ObjectProperty>>();\n" + + "\n" + + " void sample() {\n" + + " //Fails in Mars.1 succeeds in Mars.0\n" + + " {\n" + + " ObjectBinding>> b = Bindings.createObjectBinding(() -> {\n" + + " if (this.comparator.get() == null)\n" + + " return null;\n" + + " return (o1, o2) -> this.comparator.get().compare(o1, o2);\n" + + " }, this.comparator);\n" + + " }\n" + + "\n" + + " // Succeeds in both\n" + + " {\n" + + " ObjectBinding>> b = Bindings.createObjectBinding(() -> {\n" + + " if (this.comparator.get() == null)\n" + + " return null;\n" + + " Comparator> cp = (o1, o2) -> this.comparator.get().compare(o1, o2);\n" + + " return cp;\n" + + " }, this.comparator);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class Bindings {\n" + + " public static ObjectBinding createObjectBinding(final Callable func, final Observable... dependencies) { return null; }\n" + + "}\n" + + "class ObjectBinding { }\n" + + "class TreeItem { }\n" + + "class ObjectProperty implements Observable {\n" + + " W get() { return null; }\n" + + "}\n" + + "interface Observable {}\n" + }); +} +public void testBug483019() { + runConformTest( + new String[] { + "Test.java", + "import sub.B;\n" + + "import sub.Marker;\n" + + "\n" + + "public class Test {\n" + + " public int test(B b) {\n" + + " return (((B & Marker) b).getValue());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new Test().test(new B()));\n" + + " }\n" + + "}", + "sub/A.java", + "package sub;\n" + + "class A {\n" + + " public int getValue() {\n" + + " return 1;\n" + + " }\n" + + "}\n", + "sub/B.java", + "package sub;\n" + + "public class B extends A implements Marker{ }\n", + "sub/Marker.java", + "package sub;\n" + + "public interface Marker{ }\n" + }, + "1"); +} +public void testBug483019a() { + runConformTest( + false /*skipJavac */, + JavacTestOptions.Excuse.JavacHasErrorsEclipseHasNone, + new String[] { + "Test.java", + "import sub.J;\n" + + "import sub.Marker;\n" + + "\n" + + "public class Test {\n" + + " public int test(J j) {\n" + + " return (((Marker & J) j).getValue());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new Test().test((J & Marker)() -> 0));\n" + + " }\n" + + "}", + "sub/I.java", + "package sub;\n" + + "interface I {\n" + + " int getValue();\n" + + "}\n", + "sub/J.java", + "package sub;\n" + + "public interface J extends I{ }\n", + "sub/Marker.java", + "package sub;\n" + + "public interface Marker{ }\n" + }, + "0"); +} + +public void testBug484448() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "public final class Test {\n" + + " /**\n" + + " * @see #g(T, Class)\n" + + " */\n" + + " public static T f(T t, Class c1) {\n" + + " return g(t, c1);\n" + + " }\n" + + "\n" + + " public static U g(U u, Class c2) {\n" + + " return u;\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug485593() { + runConformTest( + new String[] { + "Test.java", + "import java.util.*;\n" + + "\n" + + "public class Test {\n" + + " void test() {\n" + + " double[][] d = new double[][]{{1,2},{3,4},{5,6}};\n" + + " double[][] e = Arrays.stream(d).map(double[]::clone).toArray(double[][]::new);\n" + + " }\n" + + "}\n" + }); +} +public void testBug483228a() { + runNegativeTest( + new String[] { + "X.java", + "interface UnaryOp { T apply(T arg); }\n" + + "interface IntegerToNumber { Number apply(Integer arg); }\n" + + "\n" + + "public class X {\n" + + "\n" + + " void m(UnaryOp f) {}\n" + + " void m(IntegerToNumber f) {}\n" + + "\n" + + " void test() {\n" + + " m((Integer i) -> i);\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " m((Integer i) -> i);\n" + + " ^\n" + + "The method m(UnaryOp) is ambiguous for the type X\n" + + "----------\n"); +} +public void testBug449824a() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface FI1 {\n" + + " public T get(X x, T n);\n" + + " }\n" + + " interface FI2 {\n" + + " public Integer get(X x, Integer t);\n" + + " }\n" + + " void m(FI1 fi) { }\n" + + " void m(FI2 fi) { }\n" + + " Integer id(Number n) {\n" + + " return null;\n" + + " }\n" + + " void test() {\n" + + " m(X::id);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " m(X::id);\n" + + " ^\n" + + "The method m(X.FI1) is ambiguous for the type X\n" + + "----------\n"); +} +public void testBug449824b() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface FI1 {\n" + + " public T get(T... n);\n" + + " }\n" + + " interface FI2 {\n" + + " public Integer get(Integer... t);\n" + + " }\n" + + " void m(FI1 fi) { }\n" + + " void m(FI2 fi) { }\n" + + " Integer id(Number[] n) {\n" + + " return null;\n" + + " }\n" + + " void test() {\n" + + " m(this::id);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public T get(T... n);\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter n\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " m(this::id);\n" + + " ^\n" + + "The method m(X.FI1) is ambiguous for the type X\n" + + "----------\n"); +} +public void testBug487746_comment2() { + runConformTest( + new String[] { + "Example.java", + "\n" + + "import java.time.Instant;\n" + + "import java.util.Comparator;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class Example {\n" + + " public void test1() {\n" + + " // Returns Collector - CORRECT\n" + + " Collectors.collectingAndThen(\n" + + " Collectors.toList(),\n" + + " list -> list.stream().sorted(Comparator.comparing(Something::getTime)).limit(1).findAny().orElse(null)\n" + + " );\n" + + " }\n" + + " \n" + + " public void test2() {\n" + + " Collectors.collectingAndThen(\n" + + " Collectors.toList(),\n" + + " list -> list.stream().collect(Collectors.groupingBy(Something::getSize,\n" + + " // Returns Collector - INCORRECT!\n" + + " Collectors.collectingAndThen(\n" + + " Collectors.toList(),\n" + + " list2 -> list2.stream().sorted(Comparator.comparing(Something::getTime)).limit(1).findAny().orElse(null)\n" + + " )\n" + + " )));\n" + + " }\n" + + " private interface Something {\n" + + " public int getSize();\n" + + " public Instant getTime();\n" + + " }\n" + + "}\n" + }); +} +public void _testBug487746_comment9() { // FIXME: still reports an unexpected error + runConformTest( + new String[] { + "Example.java", + "\n" + + "import java.time.Instant;\n" + + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class Example {\n" + + " public void doesntCompile(List things) {\n" + + " things.stream()\n" + + " .filter(thing -> thing.getSize() > 100)\n" + + " .collect(Collectors.collectingAndThen(\n" + + " Collectors.toList(),\n" + + " list -> list.stream().collect(Collectors.groupingBy(Something::getSize,\n" + + " Collectors.collectingAndThen(\n" + + " Collectors.toList(),\n" + + " list2 -> list2.stream().sorted(Comparator.comparing(Something::getTime)).limit(1).findAny().orElse(null)\n" + + " )\n" + + " ))))\n" + + " .forEach((size, thing) -> {\n" + + " System.out.println(thing.getSize()); // Compile error because Eclipse thinks 'thing' is Object\n" + + " });\n" + + " }\n" + + " private interface Something {\n" + + " public int getSize();\n" + + " public Instant getTime();\n" + + " }\n" + + "}\n" + }); +} +public void testBug480075() { + runConformTest( + new String[] { + "X.java", + "import java.util.stream.*;\n" + + "public class X {\n" + + " void test() {\n" + + " IntStream.of(42).mapToObj(i -> i > 42 ? \"gt\" : i < 42 ? \"lt\" : \"42\").findFirst();\n" + + "\n" + + " Stream.generate(Object::new).map(o -> o != null ? o : o == null ? o : o).findAny();\n" + + "\n" + + " }\n" + + "}\n" + }); +} +public void testBug488649() { + runNegativeTest( + new String[] { + "X.java", + "class A {}\n" + + "public class X {\n" + + " static U get(A a) { return null; }\n" + + " void test(A a) {\n" + + " get(a).missing();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void test(A a) {\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " get(a).missing();\n" + + " ^^^^^^\n" + + "Type safety: Unchecked invocation get(A) of the generic method get(A) of type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " get(a).missing();\n" + + " ^\n" + + "Type safety: The expression of type A needs unchecked conversion to conform to A\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " get(a).missing();\n" + + " ^^^^^^^\n" + + "The method missing() is undefined for the type Object\n" + + "----------\n"); +} +public void testBug488672() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " void foo(Manager manager) {\n" + + " HashSet activeBindings = new HashSet<>(manager.getActiveBindingsDisregardingContextFlat());\n" + + " }\n" + + "}\n" + + "\n" + + "class Manager {\n" + + " Collection getActiveBindingsDisregardingContextFlat() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug488795() { + runConformTest( + new String[] { + "X.java", + "interface Parameter {}\n" + + "interface Parameters, T extends Parameter> extends Iterable {\n" + + " S get();\n" + + "}\n" + + "public class X {\n" + + " void test(Parameters parameters) {\n" + + " for(Parameter p : parameters.get())\n" + + " System.out.println(p);\n" + + " }\n" + + "}\n" + }); +} +public void testBug489976() { + runConformTest( + new String[] { + "Test.java", + "import java.util.*;\n" + + "import static java.util.stream.Collectors.*;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "class Key {}\n" + + "class Value {}\n" + + "public class Test {\n" + + " void test (List> maps) {\n" + + " maps.stream().flatMap(s->s.entrySet().stream()).collect(\n" + + " groupingBy(e -> e.getKey(), \n" + + " mapping(e -> e.getValue(), collectingAndThen(toList(),x->x))\n" + + " )\n" + + " );\n" + + " }\n" + + "}\n" + }); +} +public void testBug491934() { + runConformTest( + new String[] { + "Main.java", + "import java.util.Arrays;\n" + + "import java.util.HashSet;\n" + + "import java.util.Set;\n" + + "\n" + + "public class Main {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " // gives compile error in Neon\n" + + " // was warning \"unchecked\" in Mars\n" + + " Set genericSet = new HashSet<>(oldApiReturningUntypedSet());\n" + + " }\n" + + "\n" + + " @SuppressWarnings({ \"rawtypes\", \"unchecked\" })\n" + + " private static Set oldApiReturningUntypedSet() {\n" + + " HashSet set = new HashSet();\n" + + " set.add(\"one\");\n" + + " return set;\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug491485() { + runNegativeTest( + new String[] { + "Tester.java", + "interface SAM {\n" + + " Z bar(X a, Y b);\n" + + "}\n" + + "interface I {\n" + + " \n" + + "}\n" + + "class X3 {\n" + + " \n" + + "}\n" + + "public class Tester {\n" + + "\n" + + " X3 method(SAM s) {\n" + + " return s.bar(null, null);\n" + + " }\n" + + " \n" + + " Object foo(Object a, Object b) {\n" + + " return null;\n" + + " }\n" + + " X3 junk() {\n" + + " return method((SAM & I ) this::foo);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Tester.java (at line 20)\n" + + " return method((SAM & I ) this::foo);\n" + + " ^^^^^^^^^\n" + + "The type of foo(Object, Object) from the type Tester is Object, this is incompatible with the descriptor\'s return type: X3\n" + + "----------\n"); +} + +public void testBug485057() { + runNegativeTest( + new String[] { + "Task.java", + "public class Task {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " foo(rt -> true); // PROBLEM HERE\n" + + " }\n" + + "\n" + + " public static Task foo(T serialiable) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static Task foo(java.util.function.Predicate predicate) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Task.java (at line 4)\n" + + " foo(rt -> true); // PROBLEM HERE\n" + + " ^^^\n" + + "The method foo(Serializable) is ambiguous for the type Task\n" + + "----------\n" + + "2. ERROR in Task.java (at line 4)\n" + + " foo(rt -> true); // PROBLEM HERE\n" + + " ^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} + +public void testBug485373() { + runNegativeTest( + new String[] { + "TestGenericsFunctional.java", + "import java.util.Collection;\n" + + "import java.util.function.Consumer;\n" + + "\n" + + "public class TestGenericsFunctional {\n" + + "\n" + + " public static void doStuff(String str, Consumer consumer) {\n" + + " consumer.accept(str);\n" + + " }\n" + + " \n" + + " public static > C doStuff(String str, C collection) {\n" + + " doStuff(str, st -> collection.add(st));\n" + + " return collection;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in TestGenericsFunctional.java (at line 11)\n" + + " doStuff(str, st -> collection.add(st));\n" + + " ^^^^^^^\n" + + "The method doStuff(String, Consumer) is ambiguous for the type TestGenericsFunctional\n" + + "----------\n"); +} + +public void testBug487563() { + runNegativeTest( + new String[] { + "Java8TypeInferenceProblem.java", + "\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "\n" + + "public class Java8TypeInferenceProblem {\n" + + "\n" + + " public ValueObjectImpl myTestMethod() {\n" + + " return copyToValueObject(loadBusinessObject(), ValueObjectImpl.class);\n" + + " }\n" + + "\n" + + " public T copyToValueObject(BusinessObject param, Class voClass) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public List copyToValueObject(Iterator params, Class voClass) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public T loadBusinessObject() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " private interface BusinessObject { }\n" + + "\n" + + " private interface ValueObject { }\n" + + "\n" + + " private class ValueObjectImpl implements ValueObject { }\n" + + "\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Java8TypeInferenceProblem.java (at line 8)\n" + + " return copyToValueObject(loadBusinessObject(), ValueObjectImpl.class);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The method copyToValueObject(Java8TypeInferenceProblem.BusinessObject, Class) is ambiguous for the type Java8TypeInferenceProblem\n" + + "----------\n"); +} +public void testBug492939a() { + runConformTest( + new String[] { + "EclipseInference.java", + "import java.lang.reflect.Type;\n" + + "import java.sql.ResultSet;\n" + + "import java.sql.SQLException;\n" + + "import java.util.List;\n" + + "import java.util.Optional;\n" + + "import java.util.concurrent.ConcurrentHashMap;\n" + + "import java.util.concurrent.CopyOnWriteArrayList;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class EclipseInference {\n" + + "\n" + + " private final List rowFactories = new CopyOnWriteArrayList<>();\n" + + " private final ConcurrentHashMap> rowCache = new ConcurrentHashMap<>();\n" + + "\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public Optional> findRowMapperFor(Type type) {\n" + + " return Optional.ofNullable(rowCache.computeIfAbsent(type, t ->\n" + + " findFirstPresent(\n" + + " () -> rowFactories.stream()\n" + + " .flatMap(factory -> toStream(factory.build(t)))\n" + + " .findFirst(),\n" + + " () -> findColumnMapperFor(t)\n" + + " .map(SingleColumnMapper::new))\n" + // HERE: ReferenceExpression had a bug + " .orElse(null)));\n" + + " }\n" + + "\n" + + " private Optional> findColumnMapperFor(Type t) {\n" + + " return Optional.empty();\n" + + " }\n" + + "\n" + + " @SafeVarargs\n" + + " static Optional findFirstPresent(Supplier>... suppliers) {\n" + + " return Stream.of(suppliers)\n" + + " .flatMap(supplier -> toStream(supplier.get()))\n" + + " .findFirst();\n" + + " }\n" + + " static Stream toStream(Optional optional) {\n" + + " return optional.isPresent() ? Stream.of(optional.get()) : Stream.empty();\n" + + " }\n" + + "}\n" + + "\n" + + "class SingleColumnMapper implements RowMapper {\n" + + " SingleColumnMapper(ColumnMapper mapper) {\n" + + " }\n" + + " @Override\n" + + " public T map(ResultSet r) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "@FunctionalInterface\n" + + "interface RowMapper\n" + + "{\n" + + " T map(ResultSet r);\n" + + "}\n" + + "\n" + + "@FunctionalInterface\n" + + "interface ColumnMapper\n" + + "{\n" + + " T map(ResultSet r, int columnNumber) throws SQLException;\n" + + "}\n" + + "\n" + + "@FunctionalInterface\n" + + "interface RowMapperFactory\n" + + "{\n" + + " Optional> build(Type type);\n" + + "}\n" + + "\n" + + "@FunctionalInterface\n" + + "interface ColumnMapperFactory\n" + + "{\n" + + " Optional> build(Type type);\n" + + "}\n" + }); +} +public void testBug492939b() { + runConformTest( + new String[] { + "EclipseInference.java", + "import java.lang.reflect.Type;\n" + + "import java.sql.ResultSet;\n" + + "import java.sql.SQLException;\n" + + "import java.util.List;\n" + + "import java.util.Optional;\n" + + "import java.util.concurrent.ConcurrentHashMap;\n" + + "import java.util.concurrent.CopyOnWriteArrayList;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class EclipseInference {\n" + + "\n" + + " private final List rowFactories = new CopyOnWriteArrayList<>();\n" + + " private final ConcurrentHashMap> rowCache = new ConcurrentHashMap<>();\n" + + "\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public Optional> findRowMapperFor(Type type) {\n" + + " return Optional.ofNullable(rowCache.computeIfAbsent(type, t ->\n" + + " findFirstPresent(\n" + + " () -> rowFactories.stream()\n" + + " .flatMap(factory -> toStream(factory.build(t)))\n" + + " .findFirst(),\n" + + " () -> findColumnMapperFor(t)\n" + + " .map(c -> new SingleColumnMapper<>(c)))\n" + // HERE: LambdaExpression already worked + " .orElse(null)));\n" + + " }\n" + + "\n" + + " private Optional> findColumnMapperFor(Type t) {\n" + + " return Optional.empty();\n" + + " }\n" + + "\n" + + " @SafeVarargs\n" + + " static Optional findFirstPresent(Supplier>... suppliers) {\n" + + " return Stream.of(suppliers)\n" + + " .flatMap(supplier -> toStream(supplier.get()))\n" + + " .findFirst();\n" + + " }\n" + + " static Stream toStream(Optional optional) {\n" + + " return optional.isPresent() ? Stream.of(optional.get()) : Stream.empty();\n" + + " }\n" + + "}\n" + + "\n" + + "class SingleColumnMapper implements RowMapper {\n" + + " SingleColumnMapper(ColumnMapper mapper) {\n" + + " }\n" + + " @Override\n" + + " public T map(ResultSet r) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "@FunctionalInterface\n" + + "interface RowMapper\n" + + "{\n" + + " T map(ResultSet r);\n" + + "}\n" + + "\n" + + "@FunctionalInterface\n" + + "interface ColumnMapper\n" + + "{\n" + + " T map(ResultSet r, int columnNumber) throws SQLException;\n" + + "}\n" + + "\n" + + "@FunctionalInterface\n" + + "interface RowMapperFactory\n" + + "{\n" + + " Optional> build(Type type);\n" + + "}\n" + + "\n" + + "@FunctionalInterface\n" + + "interface ColumnMapperFactory\n" + + "{\n" + + " Optional> build(Type type);\n" + + "}\n" + }); +} +public void testBug496942() { + runConformTest( + new String[] { + "ProductManager.java", + "import java.util.Set;\n" + + "import java.util.concurrent.Callable;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "class Product { }\n" + + "class ItineraryDTO { }\n" + + "class Result {\n" + + " public static Function>> \n" + + " asyncCall(Function> asyncMethod)\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "interface ListeningExecutorService {\n" + + " ListenableFuture submit(Callable c);\n" + + " ListenableFuture submit(Runnable r);\n" + + "}\n" + + "interface ListenableFuture {}\n" + + "\n" + + "public class ProductManager {\n" + + " public Stream>> \n" + + " test(ListeningExecutorService executor, Set productsSet)\n" + + " {\n" + + " return productsSet.stream().map(Result.asyncCall(product ->\n" + + " executor.submit(() -> new ItineraryDTO()\n" + + " )));\n" + + " }\n" + + "}\n" + }); +} +public void testBug496574() { + runConformTest( + new String[] { + "EclipseNeonBug.java", + "import java.util.ArrayList;\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "import java.util.Optional;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class EclipseNeonBug {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " List keyValObjs = new ArrayList<>();\n" + + " Map mses = Optional.ofNullable(keyValObjs)\n" + + " .filter(ms -> !ms.isEmpty())\n" + + " .map(ms -> ms.stream().collect(Collectors.toMap(\n" + + " metafield -> metafield.getKey(),\n" + + " metafield -> metafield.getValue())))\n" + + " .orElseGet(() -> Collections.emptyMap());\n" + + " }\n" + + "\n" + + " public static class KeyValueObj {\n" + + " private String key;\n" + + " private String value;\n" + + "\n" + + " public String getKey() {\n" + + " return key;\n" + + " }\n" + + "\n" + + " public void setKey(String key) {\n" + + " this.key = key;\n" + + " }\n" + + "\n" + + " public String getValue() {\n" + + " return value;\n" + + " }\n" + + "\n" + + " public void setValue(String value) {\n" + + " this.value = value;\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +public void testBug496574_small() { + runConformTest( + new String[] { + "Small.java", + "import java.util.*;\n" + + "import java.util.stream.*;\n" + + "\n" + + "interface KeyValueObj {\n" + + " String getKey();\n" + + " String getValue();\n" + + "}\n" + + "\n" + + "public class Small {\n" + + "\n" + + " public void test(Optional> optList) {\n" + + " Optional> mses = optList\n" + + " .map(ms -> ms.stream().collect(Collectors.toMap(\n" + + " metafield -> metafield.getKey(),\n" + + " metafield -> metafield.getValue())));\n" + + " }\n" + + "}\n" + }); +} +public void testBug496579() { + runConformTest( + new String[] { + "EclipseNeonBug2.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class EclipseNeonBug2 {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Map> stuff = new HashMap<>();\n" + + " Map> result = stuff.entrySet().stream()\n" + + " .collect(Collectors.toMap(\n" + + " k -> k.getKey(), \n" + + " o -> {\n" + + " Map child = o.getValue();\n" + + " return child.entrySet().stream().collect(Collectors.toMap(\n" + + " k -> k.getKey(), \n" + + " v -> Integer.parseInt(v.getValue().toString())));\n" + + " }));\n" + + " }\n" + + " \n" + + "}\n" + }); +} +public void testBug496761() { + runConformTest( + new String[] { + "RepoCase.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "import java.util.Optional;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class RepoCase {\n" + + " private Map> dependencyMap = new HashMap<>();\n" + + " \n" + + " void compilerNPE() {\n" + + "// Leads to NPE in compiler\n" + + " Map map = Optional.ofNullable(this.dependencyMap)\n" + + " .map(m -> m.entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> (Object) e.getValue().get())))\n" + + " .orElse(new HashMap<>());\n" + + " \n" + + "// Compiler error (might be the real cause for the above NPE) \n" + + " Optional> o = Optional.ofNullable(this.dependencyMap)\n" + + " .map(m -> m.entrySet().stream().collect(Collectors.toMap(Entry::getKey, e -> (Object) e.getValue().get())));\n" + + " }\n" + + "}\n" + }); +} +public void testBug496624() { + runConformTest( + new String[] { + "JDTNPETest.java", + "import java.util.*;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "interface HttpSession{\n" + + " Enumeration getAttributeNames();\n" + + " Object getAttribute(String name);\n" + + "}\n" + + "public class JDTNPETest {\n" + + " \n" + + " public static void main(String[] args){\n" + + " Map sessionAttributes = Optional.ofNullable(null)\n" + + " .map(s -> Collections.list(s.getAttributeNames()).stream()\n" + + " .collect(Collectors.toMap(name -> name, name -> s.getAttribute(name))))\n" + + " .orElse(null);\n" + + " }\n" + + "\n" + + "}\n" + }); +} +public void testBug497193() { + runConformTest( + new String[] { + "EclipseBug.java", + "import java.util.function.Function;\n" + + "\n" + + "public class EclipseBug {\n" + + " public static class Class1 {\n" + + " public Class1( Function arg ) {}\n" + + " }\n" + + "\n" + + " public static R method1( T object, Function function ) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static class Class2 {\n" + + " public static Class2 method1( String arg ) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " String method2() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private final Class1 member = new Class1<>( arg -> method1( Class2.method1( arg ), class2 -> class2.method2() ) );\n" + + "}\n" + }); +} +public void testBug496578() { + runConformTest( + new String[] { + "Test.java", + "import java.util.function.BinaryOperator;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class Test {\n" + + " private Long[] v, v_small;\n" + + " public Long method(String[] args) {\n" + + " ExecPushFactory alg = new ExecPushFactory();\n" + + " Long value = Id.prj(\n" + + " alg.reduce(0L, Long::sum,\n" + + " alg.flatMap(x ->\n" + + " alg.map(y -> x * y,\n" + + " alg.source(v_small)),\n" + + " alg.source(v)))).value;\n" + + " return value;\n" + + " }\n" + + "}\n" + + "class ExecPushFactory {\n" + + " public App flatMap(Function> mapper, App app) {\n" + + " return null;\n" + + " }\n" + + " public App source(T[] array) {\n" + + " return null;\n" + + " }\n" + + " public App map(Function mapper, App app) {\n" + + " return null;\n" + + " }\n" + + " public App reduce(T identity, BinaryOperator accumulator, App app) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class Id implements App{\n" + + " public T value;\n" + + " public static class t {\n" + + " \n" + + " }\n" + + " public static Id prj(App app) {\n" + + " return (Id) app;\n" + + " }\n" + + "}\n" + + "interface App {\n" + + " \n" + + "}\n" + }); +} +public void testBug496675() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public class B {\n" + + " public class C {}\n" + + " }\n" + + " public class D extends B {}\n" + + " \n" + + " /* This fails with an internal ArrayIndexOutOfBoundsException in \n" + + " * ParameterizedTypeBinding.boundCheck. */\n" + + " public class E.C> {}\n" + + "}\n" + }); +} +public void testBug496675_comment4() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public class B {\n" + + " public class C {}\n" + + " }\n" + + " public class D extends B {}\n" + + " \n" + + " /* This fails with an internal ArrayIndexOutOfBoundsException in \n" + + " * ParameterizedTypeBinding.boundCheck. */\n" + + " public class E.C> {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 9)\n" + + " public class E.C> {}\n" + + " ^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter of the type Test.D\n" + + "----------\n"); +} +public void testBug496675_problem() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " .C> void m() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " .C> void m() {}\n" + + " ^^^^^\n" + + "wrong cannot be resolved to a type\n" + + "----------\n"); +} +public void testBug496886() { + runConformTest( + new String[] { + "Outer.java", + "public interface Outer {\n" + + " public interface Inner {\n" + + " }\n" + + "}\n", + "SubInterface.java", + "public interface SubInterface extends Outer {}\n" + }); + runConformTest( + new String[] { + "ProblemClass.java", + "class ProblemClass implements SubInterface.Inner {}\n" + }, + "", + null, + false, // don't flush + null); +} +public void testBug497603() { + runConformTest( + new String[] { + "InferBug.java", + "import java.util.Iterator;\n" + + "import java.util.Map.Entry;\n" + + "import java.util.function.BiPredicate;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class InferBug {\n" + + " public static void main(String[] args) {\n" + + " Iterator>> x = null;\n" + + " Iterator> p = foo(x, i -> foo(i, Entry::getValue));\n" + + " }\n" + + " static Iterator foo(Iterator a, Function b) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug498113a() { + runConformTest( + new String[] { + "NPETest.java", + "import java.util.*;\n" + + "public class NPETest {\n" + + "\n" + + " public void test(\n" + + " final Set set,\n" + + " final List> dummies) {\n" + + " set.stream()\n" + + " .map(Dummy::new)\n" + // true varargs invocation + " .forEach(dummies::add);\n" + + " }\n" + + " \n" + + " class Dummy {\n" + + " \n" + + " public Dummy(T... args) {\n" + + " \n" + + " }\n" + + " }\n" + + "}\n" + }); +} +public void testBug498113b() { + runConformTest( + new String[] { + "NPETest.java", + "import java.util.*;\n" + + "public class NPETest {\n" + + "\n" + + " public void test(\n" + + " final Set set,\n" + + " final List> dummies) {\n" + + " set.stream()\n" + + " .map(Dummy::new)\n" + // pass String[] for a strict invocation + " .forEach(dummies::add);\n" + + " }\n" + + " \n" + + " class Dummy {\n" + + " \n" + + " public Dummy(T... args) {\n" + + " \n" + + " }\n" + + " }\n" + + "}\n" + }); +} +public void testBug498362_comment0() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " static final byte[] EMPTY_BYTE_ARRAY = new byte[0];\n" + + " private byte[] stream;\n" + + " void test() {\n" + + " this.stream = Optional.ofNullable(stream)\n" + + " .map(byte[]::clone)\n" + + " .orElse(EMPTY_BYTE_ARRAY);" + + " }\n" + + "}\n" + }); +} +public void testBug498362_comment5() { + runConformTest( + new String[] { + "CloneVerifyError.java", + "public class CloneVerifyError {\n" + + " public interface PublicCloneable extends Cloneable {\n" + + " public T clone();\n" + + " }\n" + + "\n" + + " public static T[] clone0(T[] input) {\n" + + " return input == null ? null : input.clone();\n" + + " }\n" + + "\n" + + " public static > T clone0(T input) {\n" + + " if (input == null) {\n" + + " return null;\n" + + " } else {\n" + + " return input.clone();\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Object[] array = null;\n" + + " clone0(array);\n" + + " }\n" + + "}\n" + }); +} +public void testBug470667() { + runNegativeTest( + new String[] { + "Test.java", + "import java.math.BigInteger;\n" + + "import java.util.function.Function;\n" + + "public class Test {\n" + + " protected T m(Class c, String s, Function f) {\n" + + " return f.apply(s);\n" + + " }\n" + + " protected T m(Class c, BigInteger i, Function f) {\n" + + " return f.apply(i);\n" + + " }\n" + + " protected Data createData() {\n" + + " return new Data() {\n" + + " };\n" + + " }\n" + + " private Data doA(BigInteger i) {\n" + + " String str = \"titi \";\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " Data r = m(Data.class, \"toto \",\n" + + " (x) -> m(Data.class, str, (y) -> m(Data.class, BigInteger.ZERO, (z) -> createData(i, x, y, z))));\n" + + " return r;\n" + + " }\n" + + "}\n" + + "interface Data { }\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 18)\n" + + " (x) -> m(Data.class, str, (y) -> m(Data.class, BigInteger.ZERO, (z) -> createData(i, x, y, z))));\n" + + " ^^^^^^^^^^\n" + + "The method createData() in the type Test is not applicable for the arguments (BigInteger, String, String, BigInteger)\n" + + "----------\n"); +} +public void testBug497239() { + runConformTest( + new String[] { + "FunctionUtils.java", + "import java.util.stream.Collector;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class FunctionUtils {\n" + + " public static T[] concat(T[] array1, T[] array2) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static T[] concat(T[][] arrays) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public Collector on(InputElement[] inputElements) {\n" + + " return Collectors.collectingAndThen(Collectors.reducing(FunctionUtils::concat), r -> r.get());\n" + + " }\n" + + "}\n" + + "", + } + ); +} +public void testBug472851() { + runNegativeTest( + new String[] { + "Test.java", + "import java.util.*;\n" + + "\n" + + "public class Test {\n" + + " public static void main(String... arg) {\n" + + " List l1=Arrays.asList(0, 1, 2);\n" + + " List l2=Arrays.asList(\"0\", \"1\", \"2\");\n" + + " a(Arrays.asList(l1, l2));\n" + + "}\n" + + "static final void a(List> type) {\n" + + " test(type);\n" + + "}\n" + + "static final > void test(List type) {\n" + + " L l1=type.get(0), l2=type.get(1);\n" + + " l2.set(0, l1.get(0));\n" + + "}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 10)\n" + + " test(type);\n" + + " ^^^^\n" + + "The method test(List) in the type Test is not applicable for the arguments (List>)\n" + + "----------\n"); +} +public void testBug502350() { + runNegativeTest( + new String[] { + "makeCompilerFreeze/EclipseJava8Bug.java", + "package makeCompilerFreeze;\n" + + "\n" + + "interface Comparable {} \n" + + "\n" + + "interface Comparator {\n" + + " public static > Comparator naturalOrder() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "\n" + + "class Stuff {\n" + + " public static Object func(Comparator comparator) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class EclipseJava8Bug {\n" + + " static final Object BORKED =\n" + + " Stuff.func(Comparator.naturalOrder());\n" + + "}\n" + + "\n" + + "", + }, + "----------\n" + + "1. ERROR in makeCompilerFreeze\\EclipseJava8Bug.java (at line 20)\n" + + " Stuff.func(Comparator.naturalOrder());\n" + + " ^^^^\n" + + "The method func(Comparator) in the type Stuff is not applicable for the arguments (Comparator>>)\n" + + "----------\n" + ); +} +public void testBug499351() { + runConformTest( + new String[] { + "Bug.java", + "import java.util.HashMap;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class Bug {\n" + + " private static final Validator VALIDATOR = new Validator();\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Map> promotions = new HashMap<>();\n" + + "\n" + + " Set cvs = promotions.entrySet().stream()\n" + + " .flatMap(e -> e.getValue().stream()\n" + + " .flatMap(promotion -> VALIDATOR.validate(promotion).stream())\n" + + " )\n" + + " .collect(Collectors.toSet());\n" + + "\n" + + " Set ecvs = promotions.entrySet().stream()\n" + + " .flatMap(e -> e.getValue().stream()\n" + + " .map(constraintViolation -> new ExtendedConstraintViolation(\"\", null))\n" + + " )\n" + + " .collect(Collectors.toSet());\n" + + "\n" + + " Set ecvs2 = promotions.entrySet().stream()\n" + + " .flatMap(e -> e.getValue().stream())\n" + + " .flatMap(promotion -> VALIDATOR.validate(promotion).stream())\n" + + " .map(constraintViolation -> new ExtendedConstraintViolation(\"promotions/2\", constraintViolation))\n" + + " .collect(Collectors.toSet());\n" + + "\n" + + " // Below does not compile with 4.7M1, but worked fine in 4.5 (also compiles fine with Oracle/JDK8)\n" + + " //\n" + + " // --> Type mismatch: cannot convert from Set to Set\n" + + " //\n" + + " Set ecvs3 = promotions.entrySet().stream()\n" + + " .flatMap(e -> e.getValue().stream()\n" + + " .flatMap(promotion -> VALIDATOR.validate(promotion).stream()\n" + + " .map(constraintViolation -> new ExtendedConstraintViolation(\"promotions/\" + e.getKey(), constraintViolation))\n" + + " )\n" + + " )\n" + + " .collect(Collectors.toSet());\n" + + " }\n" + + "\n" + + " private static class ExtendedConstraintViolation {\n" + + " public ExtendedConstraintViolation(String key, ConstraintViolation cv) {\n" + + " }\n" + + " }\n" + + "\n" + + " private static class ConstraintViolation {\n" + + " }\n" + + "\n" + + " private static class Promotion {\n" + + " }\n" + + "\n" + + " private static class Validator {\n" + + " public Set validate(Object o) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +// reduced version for analysis (no need to run during normal tests) +public void _testBug499351_small() { + runConformTest( + new String[] { + "Small.java", + "import java.util.*;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class Small {\n" + + "\n" + + " public static void test(Map> promotions, Validator validator) {\n" + + "\n" + + " Set ecvs = promotions.entrySet().stream()\n" + + " .flatMap(e -> e.getValue().stream()\n" + + " .flatMap(promotion -> validator.validate(promotion).stream()\n" + + " .map(constraintViolation -> new ExtendedConstraintViolation(\"promotions/\" + e.getKey(), constraintViolation))\n" + + " )\n" + + " )\n" + + " .collect(Collectors.toSet());\n" + + " }\n" + + "\n" + + "}\n" + + "class ExtendedConstraintViolation {\n" + + " public ExtendedConstraintViolation(String key, ConstraintViolation cv) { }\n" + + "}\n" + + "\n" + + "class ConstraintViolation { }\n" + + "class Promotion { }\n" + + "class Validator {\n" + + " public Set validate(Object o) { return null; }\n" + + "}\n" + }); +} +public void test499351_extra1() { + runConformTest( + new String[] { + "Example.java", + "import java.util.function.Function;\n" + + "\n" + + "public class Example {\n" + + " static T id(T t) { return t; }\n" + + " static T f1 (X x) { return null; }\n" + + " \n" + + " String test() {\n" + + " return f3(y -> y.f2(Example::f1, id(y)));\n" + + " }\n" + + " V f2(Function f, U u) {return f.apply(null);}\n" + + " R f3(Function f) { return null; }\n" + + "}\n" + }); +} +public void test499351_extra2() { + runConformTest( + new String[] { + "BadInferenceMars451.java", + "import java.util.*;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collectors;\n" + + "public class BadInferenceMars451 {\n" + + " public static Map> BadInferenceMars451Casus1() {\n" + + " List stuff = new ArrayList<>();\n" + + " return stuff.stream().collect(Collectors.toMap(Function.identity(), t -> Arrays.asList(t), BadInferenceMars451::sum));\n" + + " }\n" + + " public static List sum(List l1, List l2) {\n" + + " return null;\n" + + " }\n" + + " public static class X {\n" + + " }\n" + + "}" + }); +} +public void testBug501949() { + runConformTest( + new String[] { + "DefaultClientRequestsV2.java", + "import java.io.IOException;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "\n" + + "interface Flux extends Publisher {\n" + + " Flux flatMap(Function> f);\n" + + " Flux map(Function mapper);\n" + + " Mono> collectList();\n" + + "}\n" + + "abstract class Mono implements Publisher {\n" + + " abstract T block();\n" + + " abstract Flux flatMap(Function> f);\n" + + "}\n" + + "interface Publisher {}\n" + + "interface CloudFoundryOperations {\n" + + " Flux list();\n" + + "}\n" + + "class SpaceSummary { }\n" + + "class OrganizationSummary {\n" + + " String getId() { return \"\"; }\n" + + "}\n" + + "interface CFSpace {}\n" + + "public class DefaultClientRequestsV2 {\n" + + "\n" + + " private Flux _orglist;\n" + + "\n" + + " private Mono operationsFor(OrganizationSummary org) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public List getSpaces() {\n" + + " return get(\n" + + " _orglist\n" + + " .flatMap((OrganizationSummary org) -> {\n" + + " return operationsFor(org).flatMap((operations) ->\n" + + " operations\n" + + " .list()\n" + + " .map((space) -> wrap(org, space)\n" + + " )\n" + + " );\n" + + " })\n" + + " .collectList()\n" + + " );\n" + + " }\n" + + " public static T get(Mono mono) {\n" + + " return mono.block();\n" + + " }\n" + + " public static CFSpace wrap(OrganizationSummary org, SpaceSummary space) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug502568() { + runConformTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Optional;\n" + + "import java.util.UUID;\n" + + "import java.util.concurrent.CompletableFuture;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " \n" + + " public CompletableFuture test() {\n" + + " UUID id = UUID.randomUUID();\n" + + " \n" + + " return transaction(conn -> {\n" + + " return query().thenCompose(rs1 -> {\n" + + " return query().thenCompose(rs2 -> {\n" + + " return query();\n" + + " });\n" + + " });\n" + + " })\n" + + " .thenApply(rs -> id);\n" + + " }\n" + + " \n" + + " public CompletableFuture transaction(Function> param1) {\n" + + " return param1.apply(\"test\");\n" + + " }\n" + + " \n" + + " public CompletableFuture>> query() {\n" + + " return CompletableFuture.completedFuture(Optional.of(new ArrayList()));\n" + + " }\n" + + "}\n" + }); +} +public void testBug499725() { + runConformTest( + new String[] { + "Try22.java", + "import java.rmi.RemoteException;\n" + + "import java.util.Arrays;\n" + + "import java.util.Collection;\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "\n" + + "public class Try22 {\n" + + " public static class RemoteExceptionWrapper {\n" + + " @FunctionalInterface\n" + + " public static interface FunctionRemote {\n" + + " R apply(T t) throws RemoteException;\n" + + " }\n" + + " \n" + + " public static Function wrapFunction(FunctionRemote f) {\n" + + " return x -> {\n" + + " try {\n" + + " return f.apply(x);\n" + + " }\n" + + " catch(RemoteException e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + "\n" + + "\n" + + " private static class ThrowingThingy {\n" + + " public Collection listStuff(String in) throws RemoteException {\n" + + " return Collections.emptyList();\n" + + " }\n" + + " }\n" + + "\n" + + " \n" + + " public static void main(String[] args) {\n" + + " List stagedNodes = Arrays.asList(\"a\", \"b\", \"c\");\n" + + " ThrowingThingy remoteThing = new ThrowingThingy(); // simulation of a rmi remote, hence the exceptio\n" + + " \n" + + " List resultingStuff = stagedNodes.stream()\n" + + " .flatMap(RemoteExceptionWrapper.wrapFunction(\n" + + " node -> remoteThing.listStuff(node) // HERE\n" + + " .stream()\n" + + " .map(sub -> node + \"/\" + sub)))\n" + + " .collect(Collectors.toList());\n" + + " \n" + + " System.out.println(resultingStuff);\n" + + " }\n" + + "}\n" + }); +} + +// Redundant type argument specification error for anonymous types should not occur below source level 9 +public void testBug488663() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + String[] testFiles = new String[] { + "C.java", + "import java.util.Comparator;\n" + + "public class C {\n" + + " Comparator comparator = new Comparator() { //\n" + + " @Override\n" + + " public int compare(String o1, String o2) {\n" + + " return 0;\n" + + " }\n" + + " };\n" + + "}" + }; + if (this.complianceLevel < ClassFileConstants.JDK9) { + this.runConformTest( + testFiles, + "", options); + } else { + this.runNegativeTest( + testFiles, + "----------\n" + + "1. ERROR in C.java (at line 3)\n" + + " Comparator comparator = new Comparator() { //\n" + + " ^^^^^^^^^^\n" + + "Redundant specification of type arguments \n" + + "----------\n", + null, true, options); + } +} + +public void testBug499725a() { + runConformTest( + new String[] { + "Try22.java", + "import java.rmi.RemoteException;\n" + + "import java.util.Arrays;\n" + + "import java.util.Collection;\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "\n" + + "public class Try22 {\n" + + " public static class RemoteExceptionWrapper {\n" + + " @FunctionalInterface\n" + + " public static interface FunctionRemote {\n" + + " R apply(T t) throws RemoteException;\n" + + " }\n" + + " \n" + + " public static Function wrapFunction(FunctionRemote f) {\n" + + " return x -> {\n" + + " try {\n" + + " return f.apply(x);\n" + + " }\n" + + " catch(RemoteException e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + "\n" + + "\n" + + " private static class ThrowingThingy {\n" + + " public Collection listStuff(String in) throws RemoteException {\n" + + " return Collections.emptyList();\n" + + " }\n" + + " }\n" + + "\n" + + " \n" + + " public static void main(String[] args) {\n" + + " List stagedNodes = Arrays.asList(\"a\", \"b\", \"c\");\n" + + " ThrowingThingy remoteThing = new ThrowingThingy(); // simulation of a rmi remote, hence the exceptio\n" + + " \n" + + " List resultingStuff = stagedNodes.stream()\n" + + " .flatMap(RemoteExceptionWrapper.wrapFunction(\n" + + " (String node) -> remoteThing.listStuff(node) // HERE\n" + + " .stream()\n" + + " .map(sub -> node + \"/\" + sub)))\n" + + " .collect(Collectors.toList());\n" + + " \n" + + " System.out.println(resultingStuff);\n" + + " }\n" + + "}\n" + }); +} +public void testBug508834() { + runConformTest( + new String[] { + "FlatMapper.java", + "import java.util.stream.Stream;\n" + + "public class FlatMapper {\n" + + "\n" + + " private String[] stuff;\n" + + " \n" + + " public static void main(String[] args) {\n" + + " Stream.of(new FlatMapper[]{})\n" + + " .flatMap(fl -> Stream.of(fl.stuff)) //\n" + + " .filter(st -> !st.isEmpty()); //\n" + + " }\n" + + "}\n" + }, + ""); +} +public void testBug508834_comment0() { + runConformTest( + new String[] { + "test/TypeB.java", + "package test;\n" + + "public class TypeB {\n" + + " public String getText() {\n" + + " return \"\";\n" + + " }\n" + + "\n" + + "}\n", + "test/TypeA.java", + "package test;\n" + + "public class TypeA {\n" + + " public TypeB[] getArrayOfB() {\n" + + " return null;\n" + + " }\n" + + " public TypeB getB() {\n" + + " return null;\n" + + " }\n" + + "}\n", + "test/Test1.java", + "package test;\n" + + "import java.util.stream.Stream;\n" + + "public class Test1 {\n" + + " private TypeA[] arrayOfType() {\n" + + " return null;\n" + + " }\n" + + " private String[] test1() {\n" + + " return Stream\n" + + " .of(arrayOfType())\n" + + " .filter(a -> a.getB() != null)\n" + + " .flatMap(a -> Stream.of(a.getB()))\n" + + " .map(TypeB::getText)\n" + + " .sorted()\n" + + " .toArray(String[]::new);\n" + + " }\n" + + " private String[] test2() {\n" + + " return Stream\n" + + " .of(arrayOfType())\n" + + " .filter(a -> a.getArrayOfB() != null)\n" + + " .flatMap(a -> Stream.of(a.getArrayOfB()))\n" + + " .map(TypeB::getText)\n" + + " .sorted()\n" + + " .toArray(String[]::new);\n" + + " }\n" + + "}\n" + }, + ""); + } + public void testBug509694() { + runConformTest( + new String[] { + "NfaUtil.java", + "/*******************************************************************************\n" + + " * Copyright (c) 2011 itemis AG (http://www.itemis.eu) and others.\n" + + " * All rights reserved. This program and the accompanying materials\n" + + " * are made available under the terms of the Eclipse Public License v1.0\n" + + " * which accompanies this distribution, and is available at\n" + + " * http://www.eclipse.org/legal/epl-v10.html\n" + + " *******************************************************************************/\n" + + "import java.util.*;\n" + + "\n" + + "class Lists {\n" + + " public static LinkedList newLinkedList() {\n" + + " return new LinkedList();\n" + + " }\n" + + "\n" + + " public static LinkedList newLinkedList(Iterable elements) {\n" + + " return newLinkedList();\n" + + " }\n" + + "}\n" + + "\n" + + "class Maps {\n" + + " public static HashMap newHashMap() {\n" + + " return new HashMap();\n" + + " }\n" + + "\n" + + " public static LinkedHashMap newLinkedHashMap() {\n" + + " return new LinkedHashMap();\n" + + " }\n" + + "\n" + + " public static LinkedHashMap newLinkedHashMap(Map map) {\n" + + " return new LinkedHashMap(map);\n" + + " }\n" + + "}\n" + + "\n" + + "class Sets {\n" + + " public static HashSet newHashSet(Iterable elements) {\n" + + " return new HashSet();\n" + + " }\n" + + "\n" + + " public static HashSet newHashSet(E... elements) {\n" + + " HashSet set = new HashSet<>();\n" + + " Collections.addAll(set, elements);\n" + + " return set;\n" + + " }\n" + + "}\n" + + "\n" + + "interface IAcceptor {\n" + + " void accept(T t);\n" + + "}\n" + + "\n" + + "interface Nfa extends DirectedGraph {\n" + + " STATE getStop();\n" + + " STATE getStart();\n" + + "}\n" + + "interface DirectedGraph {\n" + + " Iterable getFollowers(NODE state);\n" + + "}\n" + + "\n" + + "/**\n" + + " * @author Moritz Eysholdt - Initial contribution and API\n" + + " */\n" + + "public class NfaUtil {\n" + + "\n" + + " public Map> findCycles(Nfa nfa) {\n" + + " Map> cycles = Maps.newLinkedHashMap();\n" + + " findCycles(nfa, nfa.getStart(), (List t) -> {\n" + + " Set cycle = Sets.newHashSet(t);\n" + + " for (S cycleNode : t) {\n" + + " // We have two cycles that are connected via at least\n" + + " // one node. Treat them as one cycle.\n" + + " Set existingCycle = cycles.get(cycleNode);\n" + + " if (existingCycle != null) {\n" + + " cycle.addAll(existingCycle);\n" + + " }\n" + + " }\n" + + " for (S n : cycle) {\n" + + " cycles.put(n, cycle);\n" + + " }\n" + + " }, Maps.newHashMap(), Lists.newLinkedList());\n" + + " return cycles;\n" + + " }\n" + + "\n" + + " public void findCycles(Nfa nfa, IAcceptor> cycleAcceptor) {\n" + + " findCycles(nfa, nfa.getStart(), cycleAcceptor, Maps.newHashMap(), Lists.newLinkedList());\n" + + " }\n" + + "\n" + + " private static final int DFS_VISITED = 1;\n" + + " private static final int DFS_ON_STACK = 2;\n" + + "\n" + + " protected void findCycles(Nfa nfa, S node, IAcceptor> cycleAcceptor, Map dfsMark,\n" + + " LinkedList dfsStack) {\n" + + " dfsStack.push(node);\n" + + " dfsMark.put(node, DFS_ON_STACK);\n" + + " for (S follower : nfa.getFollowers(node)) {\n" + + " Integer followerMark = dfsMark.get(follower);\n" + + " if (followerMark == null) {\n" + + " findCycles(nfa, follower, cycleAcceptor, dfsMark, dfsStack);\n" + + " } else if (followerMark == DFS_ON_STACK) {\n" + + " LinkedList cycle = Lists.newLinkedList();\n" + + " Iterator stackIter = dfsStack.iterator();\n" + + " S cycleNode;\n" + + " do {\n" + + " cycleNode = stackIter.next();\n" + + " cycle.addFirst(cycleNode);\n" + + " } while (cycleNode != follower && stackIter.hasNext());\n" + + " cycleAcceptor.accept(cycle);\n" + + " }\n" + + " }\n" + + " dfsStack.pop();\n" + + " dfsMark.put(node, DFS_VISITED);\n" + + " }\n" + + "}\n" + }); + } + public void testBug479802() { + runConformTest( + new String[] { + "CompilerBugUncheckedCast.java", + "public class CompilerBugUncheckedCast {\n" + + " public static void main(String[] args) {\n" + + " Create(true);\n" + + " Create(false);\n" + + " }\n" + + " public interface Base {\n" + + " default String def() { return \"Base\"; }\n" + + " }\n" + + " public interface Intermediate extends Base {\n" + + " @Override default String def() { return \"Intermediate\"; }\n" + + " }\n" + + " public interface Derived extends Intermediate { }\n" + + " public static class MyObject implements Base { }\n" + + " public static final class OldObject extends MyObject implements Derived { }\n" + + " public static final class NewObject extends MyObject implements Derived { }\n" + + " public static void Make(OBJECT o) { }\n" + + " public static MyObject Create(boolean old) {\n" + + " MyObject f;\n" + + " if (old) {\n" + + " f = new OldObject();\n" + + " } else {\n" + + " f = new NewObject();\n" + + " }\n" + + " Make(uncheckedCast(f));\n" + + " System.out.println(old);\n" + + " return f;\n" + + " }\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " private static T uncheckedCast(MyObject f) {\n" + + " return (T) f;\n" + + " }\n" + + "}" + }, + "true\n" + + "false"); + } + public void testBug510004_a() { + runConformTest( + new String[] { + "BrokenTypeInference.java", + "import java.util.Optional;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class BrokenTypeInference {\n" + + " public static void main(String[] args) {\n" + + " Optional.of(\"42,43\").map(s -> Stream.of(s.split(\",\")));\n" + + " }\n" + + "}\n" + }); + } + public void testBug510004_b() { + runConformTest( + new String[] { + "BrokenTypeInference.java", + "import java.util.List;\n" + + "import java.util.Optional;\n" + + "\n" + + "public class BrokenTypeInference {\n" + + " public static void main(String[] args) {\n" + + " Optional.of(\"42,43\").map(s -> x(s.split(\",\")));\n" + + " }\n" + + "\n" + + " private static List x(X ... xs) {\n" + + " return java.util.Collections.emptyList();\n" + + " }\n" + + "\n" + + " private static List x(X x) {\n" + + " return java.util.Collections.emptyList();\n" + + " }\n" + + "}\n" + }); + } + public void testBug509324() { + runConformTest( + new String[] { + "testgenerics/TestGenerics.java", + "package testgenerics;\n" + + "\n" + + "import java.time.Duration;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "interface Publisher {}\n" + + "\n" + + "abstract class Mono implements Publisher {\n" + + " public static Mono just(T data) { return null; }\n" + + " public static Mono empty() { return null; }\n" + + " public final Mono then(Function> transformer) {\n" + + " return null;\n" + + " }\n" + + " public T block() { return null; }\n" + + " public final T block(Duration timeout) { return null; }\n" + + "}\n" + + "class Info {\n" + + " public String getApplicationSshEndpoint() { return null; }\n" + + "}\n" + + "class SshHost {\n" + + " public SshHost(String host, int port, String fingerPrint) { }\n" + + "}\n" + + "\n" + + "public class TestGenerics {\n" + + "\n" + + " private Mono info = Mono.just(new Info());\n" + + "\n" + + " public static T ru_get(Mono mono) throws Exception {\n" + + " return mono.block();\n" + + " }\n" + + "\n" + + " public SshHost getSshHost() throws Exception {\n" + + " return ru_get(\n" + + " info.then((i) -> {\n" + + " String host = i.getApplicationSshEndpoint();\n" + + " if (host!=null) {\n" + + " return Mono.just(new SshHost(host, 0, host));\n" + + " }\n" + + " return Mono.empty();\n" + + " })\n" + + " );\n" + + " }\n" + + "}\n" + }); + } + public void testBug469014() { + runNegativeTest( + new String[] { + "Test.java", + "import java.util.stream.Stream;\n" + + "\n" + + "public class Test {\n" + + " public static Field coalesce(T value, T... values) {\n" + + " return coalesce(field(value), fields(values));\n" + + " }\n" + + " public static Field coalesce(Field field, T value) {\n" + + " return coalesce(field, field(value));\n" + + " }\n" + + "\n" + + " public static Field coalesce(Field field, Field... fields) {\n" + + " // irrelevant\n" + + " return null;\n" + + " }\n" + + "\n" + + " static Field field(T value) {\n" + + " return new Field(value);\n" + + " }\n" + + "\n" + + " static Field[] fields(T... values) {\n" + + " return Stream.of(values).map(Test::field).toArray(Field[]::new);\n" + + " }\n" + + "\n" + + " static class Field {\n" + + " public Field(T t) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Test.java (at line 4)\n" + + " public static Field coalesce(T value, T... values) {\n" + + " ^^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter values\n" + + "----------\n" + + "2. ERROR in Test.java (at line 5)\n" + + " return coalesce(field(value), fields(values));\n" + + " ^^^^^^^^\n" + + "The method coalesce(Test.Field, Test.Field[]) is ambiguous for the type Test\n" + + "----------\n" + + "3. WARNING in Test.java (at line 20)\n" + + " static Field[] fields(T... values) {\n" + + " ^^^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter values\n" + + "----------\n" + + "4. WARNING in Test.java (at line 21)\n" + + " return Stream.of(values).map(Test::field).toArray(Field[]::new);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Test.Field[] needs unchecked conversion to conform to Test.Field[]\n" + + "----------\n"); + } + + public void testBug511876() { + runConformTest( + new String[] { + "util/ClasspathScanner.java", + "package util;\n" + + "\n" + + "import java.io.*;\n" + + "import java.lang.reflect.Method;\n" + + "import java.util.*;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "class ClassPath {\n" + + " public static ClassPath from(ClassLoader classloader) throws IOException {\n" + + " return new ClassPath();\n" + + " }\n" + + " public Set getTopLevelClasses() {\n" + + " return Collections.emptySet();\n" + + " }\n" + + "}\n" + + "class ClassInfo {\n" + + " public Class load() { return null; }\n" + + " public String getPackageName() { return \"\"; }\n" + + "}\n" + + "\n" + + "/**\n" + + " * @see https://blog.jooq.org/2016/04/21/the-parameterless-generic-method-antipattern/\n" + + " */\n" + + "public class ClasspathScanner {\n" + + " /**\n" + + " * This will produce all the generic, parameterless methods on your class path.\n" + + " */\n" + + " public static void main(String[] args) throws Exception {\n" + + " ClassPath.from(Thread.currentThread().getContextClassLoader())\n" + + " .getTopLevelClasses()\n" + + " .stream()\n" + + " .filter(info -> !info.getPackageName().startsWith(\"akka\") && !info.getPackageName().startsWith(\"scala\") && !info.getPackageName().startsWith(\"java\"))\n" + + " .flatMap(info -> {\n" + + " try {\n" + + " return Stream.of(info.load());\n" + + " }\n" + + " catch (Throwable ignore) {\n" + + " return Stream.empty();\n" + + " }\n" + + " }).flatMap(c -> {\n" + + " try {\n" + + " return Stream.of(c.getMethods());\n" + + " }\n" + + " catch (Throwable ignore) {\n" + + " return Stream. of();\n" + + " }\n" + + " })\n" + + " .filter(m -> m.getTypeParameters().length > 0 && m.getParameterCount() == 0)\n" + + " .sorted(Comparator.comparing(Method::toString))\n" + + " .map(Method::toGenericString)\n" + + " .forEach(System.out::println);\n" + + " }\n" + + "}\n" + }); + } + + public void testBug510111() { + runConformTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.Collections;\n" + + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " public static final class Entity {\n" + + "\n" + + " public int getIndex() {\n" + + " return 1;\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + "\n" + + " final List list = new ArrayList<>();\n" + + " // Eclipse fails to compile the next line with error\n" + + " // Type mismatch: cannot convert from int to Comparable>\n" + + " Collections.sort( list , Comparator.comparing( a -> a.getIndex() ) ); \n" + + " }\n" + + "}" + }); + } + + public void testBug511750() { + runConformTest( + new String[] { + "SomeClass.java", + "import java.util.Collections;\n" + + "import java.util.Set;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class SomeClass {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo().iterator().next().getBaz());\n" + + " }\n" + + "\n" + + " public interface Baz {\n" + + " public String getBaz();\n" + + " }\n" + + "\n" + + " public static Set foo() {\n" + + " Set stringSet = Collections.singleton(\"someString\");\n" + + " return stringSet.stream().map(s -> new Baz() {\n" + + "\n" + + " @Override\n" + + " public String getBaz() {\n" + + " return s;\n" + + " }\n" + + "\n" + + " }).collect(Collectors.toSet());\n" + + " }\n" + + "}\n" + }); + } + public void testBug511071() { + runNegativeTest( + new String[] { + "test/ATestClass.java", + "package test;\n" + + "\n" + + "interface Functional {\n" + + " void test(T t);\n" + + "}\n" + + "\n" + + "public abstract class ATestClass {\n" + + " abstract void f(Functional predicate);\n" + + "\n" + + " public void m() {\n" + + " f(e -> e.matches(\"\"));\n" + + " }\n" + + "}\n" + + "", + "test/ClassWithMethodWithMissingArgType.java", + "package test;\n" + + "\n" + + "import java.util.List;\n" + + "\n" + + "import missing.Type;\n" + + "\n" + + "public class ClassWithMethodWithMissingArgType {\n" + + " public void matches(Type arg) {\n" + + " arg.hashCode();\n" + + " }\n" + + "}\n" + + "", + }, + "----------\n" + + "1. ERROR in test\\ATestClass.java (at line 11)\n" + + " f(e -> e.matches(\"\"));\n" + + " ^^^^^^^\n" + + "The method matches(Type) from the type ClassWithMethodWithMissingArgType refers to the missing type Type\n" + + "----------\n" + + "----------\n" + + "1. ERROR in test\\ClassWithMethodWithMissingArgType.java (at line 5)\n" + + " import missing.Type;\n" + + " ^^^^^^^\n" + + "The import missing cannot be resolved\n" + + "----------\n" + + "2. ERROR in test\\ClassWithMethodWithMissingArgType.java (at line 8)\n" + + " public void matches(Type arg) {\n" + + " ^^^^\n" + + "Type cannot be resolved to a type\n" + + "----------\n" + ); + } + + public void testBug511252orig() { + runConformTest( + new String[] { + "ConfigurationServiceLocator.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import java.util.concurrent.*;\n" + + "import java.net.URI;\n" + + "public class ConfigurationServiceLocator {\n" + + "\n" + + " private final Map services = new HashMap<>();\n" + + "\n" + + " public CompletionStage> doWithService(String name, Function> block) {\n" + + " return Optional.ofNullable(services.get(name))\n" + + " .map(block.andThen(cs -> cs.thenApply(Optional::ofNullable)))\n" + + " .orElse(CompletableFuture.completedFuture(Optional.empty()));\n" + + " }\n" + + "\n" + + "}\n" + }); + } + + public void testBug511252simplified() { + runConformTest( + new String[] { + "ConfigurationServiceLocator.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import java.util.concurrent.*;\n" + + "import java.net.URI;\n" + + "public class ConfigurationServiceLocator {\n" + + "\n" + + " public CompletionStage> doWithService(Optional uriopt, Function> block) {\n" + + " return uriopt\n" + + " .map(block.andThen(cs -> cs.thenApply(Optional::ofNullable)))\n" + + " .orElse(CompletableFuture.completedFuture(Optional.empty()));\n" + + " }\n" + + "\n" + + "}\n" + }); + } + + public void testBug511878() { + // note: type variables renamed to facilitate debugging + runConformTest( + new String[] { + "SimpleParser.java", + "import java.util.function.Function;\n" + + "\n" + + "\n" + + "public interface SimpleParser {\n" + + "\n" + + " static class Tuple {\n" + + " }\n" + + " \n" + + " /** the type of the functional interface: Parser :: CharSequence -> Tuple> */\n" + + " abstract Tuple parse(CharSequence cs);\n" + + " \n" + + " default SimpleParser andThenBinding(Function> f) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " default SimpleParser andThen(SimpleParser p) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " static SimpleParser output(X v) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " static SimpleParser space() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " static SimpleParser token(SimpleParser p) {\n" + + " return space().andThen(p.andThenBinding(v -> space().andThen(output(v))));\n" + + " }\n" + + "\n" + + "}\n" + }); + } + public void testBug506021() { + runConformTest( + new String[] { + "test/__.java", + "package test;\n" + + "\n" + + "interface Result {}\n" + + "\n" + + "interface Property {}\n" + + "\n" + + "interface GraphTraversal {}\n" + + "\n" + + "public class __ {\n" + + " public static GraphTraversal> properties2() {\n" + + " return null;\n" + + " }\n" + + " public static GraphTraversal> properties() {\n" + + " return properties2();\n" + + " }\n" + + "}\n" + + "", + }); + } + + public void testBug506022() { + // extracted from problem compiling org.apache.tinkerpop.gremlin.giraph.structure.io.GiraphVertexOutputFormat + // changing the return type of getClass to Class fixes the problem + runConformTest( + new String[] { + "test2/Test2.java", + "package test2;\n" + + "\n" + + "abstract class OutputFormat {\n" + + " public abstract int getOutputCommitter();\n" + + "}\n" + + "\n" + + "public abstract class Test2 {\n" + + " public static T newInstance(Class theClass) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " abstract Class getClass(Class xface);\n" + + "\n" + + " int f() {\n" + + " return newInstance(getClass(OutputFormat.class)).getOutputCommitter();\n" + + " }\n" + + "}\n" + + "", + } + ); + } + + public void testBug506022b() { + // extracted from a problem in org.apache.tinkerpop.gremlin.process.computer.util.ComputerGraph + // replacing this.properties() by this.properties() fixes the problem + runNegativeTest( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "interface Iterator {\n" + + "}\n" + + "\n" + + "interface Function {\n" + + " C applyTo(B b);\n" + + "}\n" + + "\n" + + "interface Property {\n" + + "}\n" + + "\n" + + "class ComputerProperty implements Property {\n" + + " public ComputerProperty(final Property property) {\n" + + " }\n" + + "}\n" + + "\n" + + "public abstract class Test {\n" + + " public abstract Iterator map(final Iterator iterator, final Function function);\n" + + "\n" + + " public abstract Iterator> properties();\n" + + "\n" + + " public Iterator> test() {\n" + + " return map(this.properties(), property -> new ComputerProperty(property));\n" + + " }\n" + + "}\n" + + "", + }, + "----------\n" + + "1. WARNING in test\\Test.java (at line 24)\n" + + " return map(this.properties(), property -> new ComputerProperty(property));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor ComputerProperty(Property) belongs to the raw type ComputerProperty. References to generic type ComputerProperty should be parameterized\n" + + "----------\n" + + "2. WARNING in test\\Test.java (at line 24)\n" + + " return map(this.properties(), property -> new ComputerProperty(property));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type ComputerProperty needs unchecked conversion to conform to Property\n" + + "----------\n" + + "3. WARNING in test\\Test.java (at line 24)\n" + + " return map(this.properties(), property -> new ComputerProperty(property));\n" + + " ^^^^^^^^^^^^^^^^\n" + + "ComputerProperty is a raw type. References to generic type ComputerProperty should be parameterized\n" + + "----------\n" + ); + } + public void testBug514884() { + runConformTest( + new String[] { + "Minimal.java", + "import java.io.*;\n" + + "public class Minimal {\n" + + " public void iCrash() throws IOException {\n" + + " try (Closeable o = consumes(sneaky()::withVarargs)) {\n" + + " }\n" + + " }\n" + + "\n" + + " private Minimal sneaky() { return this; }\n" + + "\n" + + " private void withVarargs(String... test) {}\n" + + "\n" + + " private Closeable consumes(Runnable r) { return null; }\n" + + "}\n" + }); + } + + public void testBug494733_comment0() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List integerList = new ArrayList<>();\n" + + " Set> numbetListSet = Collections.singleton(toWildcardGeneric(integerList));\n" + + " numbetListSet.iterator().next().add(Float.valueOf(1.0f));\n" + + " Integer i = integerList.get(0); // Throws ClassCastException\n" + + " }\n" + + " \n" + + " static List toWildcardGeneric(List l) {\n" + + " return l;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Set> numbetListSet = Collections.singleton(toWildcardGeneric(integerList));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Set> to Set>\n" + + "----------\n"); + } + + public void testBug494733_comment1() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + "public static void main(String[] args) {\n" + + " List integerList = new ArrayList<>();\n" + + " List objectList = id(toWildcardGeneric(integerList));\n" + + " objectList.add(\"Woo?\");\n" + + " Integer i = integerList.get(0);\n" + + "}\n" + + "\n" + + "static T id(T o) {\n" + + " return o;\n" + + "}\n" + + "\n" + + "static List toWildcardGeneric(List l) {\n" + + " return l;\n" + + "}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " List objectList = id(toWildcardGeneric(integerList));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to List\n" + + "----------\n"); + } + + public void test483952_bare () { + runNegativeTest( + new String[] { + "test/Test.java", + "package test;\n" + + "import java.util.function.Function;\n" + + "public class Test {\n" + + " void test1() {\n" + + " Function function = x -> x;\n" + + " String [] z = test2(function, \"\");\n" + + " }\n" + + " T [] test2(Function function, T t) {\n" + + " return null;\n" + + " }\n" + + "}" + + }, + "----------\n" + + "1. WARNING in test\\Test.java (at line 5)\n" + + " Function function = x -> x;\n" + + " ^^^^^^^^\n" + + "Function is a raw type. References to generic type Function should be parameterized\n" + + "----------\n" + + "2. WARNING in test\\Test.java (at line 6)\n" + + " String [] z = test2(function, \"\");\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation test2(Function, String) of the generic method test2(Function, T) of type Test\n" + + "----------\n" + + "3. WARNING in test\\Test.java (at line 6)\n" + + " String [] z = test2(function, \"\");\n" + + " ^^^^^^^^\n" + + "Type safety: The expression of type Function needs unchecked conversion to conform to Function\n" + + "----------\n"); + } + public void testBug517710() { + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "public class Test {\n" + + " public static class Foo {\n" + + " }\n" + + "\n" + + " public static class Bar {\n" + + " }\n" + + "\n" + + " public V foo(Foo f) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public Foo bar(Bar b) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public Object baz() {\n" + + " Bar b = null;\n" + + " return foo(bar(b));\n" + + " }\n" + + "\n" + + "}\n" + + "", + } + ); + } + public void testBug513567() { + runConformTest( + new String[] { + "Foo.java", + "import java.util.Collection;\n" + + "import java.util.Optional;\n" + + "\n" + + "public class Foo {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new Foo().test();\n" + + " }\n" + + "\n" + + " private Collection createCollection(Optional foo) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " private void consumeCollection(Collection bar) {\n" + + " // no-op\n" + + " }\n" + + "\n" + + " @SuppressWarnings({\"rawtypes\", \"unchecked\"})\n" + + " public void test() {\n" + + " consumeCollection(createCollection((Optional) null));\n" + + " }\n" + + "\n" + + "}\n" + + "", + } + ); + } + + public void testBug521159() { + runConformTest( + new String[] { + "Test.java", + "import java.util.*;\n" + + "import java.util.stream.*;\n" + + "\n" + + "interface JarEntry {\n" + + " boolean isDirectory();\n" + + " String getName();\n" + + "}\n" + + "class VersionedStream {\n" + + " static Stream stream() { return null; }" + + "}\n" + + "public class Test {\n" + + " static final String SERVICES_PREFIX = \"META-INF/services/\";\n" + + " Map> test() {\n" + + " return VersionedStream.stream()\n" + + " .filter(e -> (! e.isDirectory()))\n" + + " .map(JarEntry::getName)\n" + + " .filter(e -> \n(e.endsWith(\".class\") ^ e.startsWith(SERVICES_PREFIX)))\n" + + " .collect(Collectors.partitioningBy(e -> e.startsWith(SERVICES_PREFIX), Collectors.toSet()));" + + " }\n" + + "}\n" + }); + } + + public void testBug521822() { + runConformTest( + new String[] { + "Test.java", + "import java.util.List;\n" + + "interface I {\n" + + " List foo(int i);\n" + + "}\n" + + "class X {\n" + + " List t;\n" + + " X(I i) {\n" + + " this.t = i.foo(0);\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " Y(I t) {super(t);}\n" + + "}\n" + + "class Z {\n" + + " static List method(int ... i) {return null;}\n" + + "}\n" + + "public class Test {\n" + + " static X x = new Y<>(Z::method);\n" + + "}\n" + }); + } + + public void testBug521185() { + this.runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " private static class Inner {" + + " public Inner(){}\n" + + " }\n" + + " public Inner get() {\n" + + " return new Inner();\n" + + " }\n" + + "}\n", + "Z.java", + "class Z implements I {\n" + + " public Z(Runnable r, T... t1) {}\n" + + " public String toString (T t) {\n" + + " return t.toString();\n" + + " }\n" + + "}", + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test t = new Test<>();\n" + + " Z z = new Z<>(()->{System.out.println(\"asdad\");}, t.get());\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " String toString();\n" + + "}" + }, + "----------\n" + + "1. WARNING in Z.java (at line 2)\n" + + " public Z(Runnable r, T... t1) {}\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter t1\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " Z z = new Z<>(()->{System.out.println(\"asdad\");}, t.get());\n" + + " ^\n" + + "Z is a raw type. References to generic type Z should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Z z = new Z<>(()->{System.out.println(\"asdad\");}, t.get());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type Test.Inner is not visible\n" + + "----------\n"); + } + + public void testBug521185a() { + this.runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " private static class Inner {" + + " public Inner(){}\n" + + " }\n" + + " public Inner get() {\n" + + " return new Inner();\n" + + " }\n" + + "}\n", + "Z.java", + "class Z implements I {\n" + + " public class Q {\n" + + " public Q(Runnable r, TT... ts) {}\n" + + " }\n" + + " public Z(Runnable r, T... t1) {}\n" + + " public String toString (T t) {\n" + + " return t.toString();\n" + + " }\n" + + "}", + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test t = new Test<>();\n" + + " Z zr = new Z<>(null, new Object[0]);\n" + + " Z.Q zq = zr.new Q<>(null, t.get());\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " String toString();\n" + + "}" + }, + "----------\n" + + "1. WARNING in Z.java (at line 3)\n" + + " public Q(Runnable r, TT... ts) {}\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter ts\n" + + "----------\n" + + "2. WARNING in Z.java (at line 5)\n" + + " public Z(Runnable r, T... t1) {}\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter t1\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Z.Q zq = zr.new Q<>(null, t.get());\n" + + " ^^^\n" + + "Z.Q is a raw type. References to generic type Z.Q should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Z.Q zq = zr.new Q<>(null, t.get());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type Test.Inner is not visible\n" + + "----------\n"); + } + + public void testBug521978() { + this.runNegativeTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "class Foo {\n" + + " public Foo(T a1, List a2){ }\n" + + "}\n" + + "class Bar {\n" + + " Bar(T item) { }\n" + + "}\n" + + "public class Test {\n" + + " static Bar getBar(T item) {\n" + + " return new Bar<>(item);\n" + + " }\n" + + " static Foo method(Bar> f) {\n" + + " return null;\n" + + " }\n" + + " static void test() {\n" + + " method(getBar(\n" + + " new Foo<>(\"str\", new ArrayList())\n" + + " ));\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Test.java (at line 17)\n" + + " method(getBar(\n" + + " ^^^^^^\n" + + "The method method(Bar>) in the type Test is not applicable for the arguments (Bar)\n" + + "----------\n" + + "2. WARNING in Test.java (at line 18)\n" + + " new Foo<>(\"str\", new ArrayList())\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The constructor Foo(Object, List) belongs to the raw type Foo. References to generic type Foo should be parameterized\n" + + "----------\n" + + "3. WARNING in Test.java (at line 18)\n" + + " new Foo<>(\"str\", new ArrayList())\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"); + } + public void testBug525576() { + this.runNegativeTest( + new String[] { + "test/Action.java", + "package test;\n" + + "\n" + + "public class Action {\n" + + " void setService(S2 s) {\n" + + " }\n" + + "}\n" + + "", + "test/Device.java", + "package test;\n" + + "\n" + + "public abstract class Device {\n" + + " private DI identity;\n" + + "\n" + + " protected void find(Service service) {\n" + + " service.getDevice();\n" + + " }\n" + + "\n" + + " public Object equals(Device obj) {\n" + + " return obj.identity;\n" + + " }\n" + + "}\n" + + "", + "test/Service.java", + "package test;\n" + + "\n" + + "import java.util.Collection;\n" + + "\n" + + "public abstract class Service {\n" + + " public Service(Action[] actionArr) {\n" + + " for (Action action : actionArr) {\n" + + " action.setService(this);\n" + + " }\n" + + " }\n" + + "\n" + + " public Action[] getActions(Collection actions) {\n" + + " return actions.toArray(new Action[actions.size()]);\n" + + " }\n" + + "\n" + + " public D1 getDevice() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. WARNING in test\\Action.java (at line 3)\n" + + " public class Action {\n" + + " ^^^^^^^\n" + + "Service is a raw type. References to generic type Service should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in test\\Device.java (at line 3)\n" + + " public abstract class Device {\n" + + " ^^^^^^^\n" + + "Service is a raw type. References to generic type Service should be parameterized\n" + + "----------\n" + + "2. WARNING in test\\Device.java (at line 6)\n" + + " protected void find(Service service) {\n" + + " ^^^^^^^\n" + + "Service is a raw type. References to generic type Service should be parameterized\n" + + "----------\n" + + "3. WARNING in test\\Device.java (at line 10)\n" + + " public Object equals(Device obj) {\n" + + " ^^^^^^\n" + + "Device is a raw type. References to generic type Device should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in test\\Service.java (at line 5)\n" + + " public abstract class Service {\n" + + " ^^^^^^\n" + + "Device is a raw type. References to generic type Device should be parameterized\n" + + "----------\n" + + "2. WARNING in test\\Service.java (at line 5)\n" + + " public abstract class Service {\n" + + " ^^^^^^^\n" + + "Service is a raw type. References to generic type Service should be parameterized\n" + + "----------\n" + + "3. WARNING in test\\Service.java (at line 7)\n" + + " for (Action action : actionArr) {\n" + + " ^^^^^^\n" + + "Action is a raw type. References to generic type Action should be parameterized\n" + + "----------\n" + + "4. WARNING in test\\Service.java (at line 8)\n" + + " action.setService(this);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method setService(Service) belongs to the raw type Action. References to generic type Action should be parameterized\n" + + "----------\n" + + "5. WARNING in test\\Service.java (at line 12)\n" + + " public Action[] getActions(Collection actions) {\n" + + " ^^^^^^\n" + + "Action is a raw type. References to generic type Action should be parameterized\n" + + "----------\n" + + "6. WARNING in test\\Service.java (at line 13)\n" + + " return actions.toArray(new Action[actions.size()]);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type Action[] needs unchecked conversion to conform to Action[]\n" + + "----------\n"); + } + public void testBug515600() { + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "interface Publisher

{\n" + + " void subscribe(Subscriber s);\n" + + "}\n" + + "\n" + + "interface Subscriber {\n" + + "}\n" + + "\n" + + "class Flux {\n" + + " public static void from(Publisher source) {\n" + + " }\n" + + "}\n" + + "\n" + + "public abstract class Test {\n" + + " abstract void assertThat2(Boolean actual);\n" + + "\n" + + " abstract void assertThat2(String actual);\n" + + "\n" + + " abstract S scan(Class type);\n" + + "\n" + + " public void test() {\n" + + " Flux.from(s -> {\n" + + " assertThat2(scan(Boolean.class));\n" + + " });\n" + + " }\n" + + "}\n" + + "", + } + ); + } + public void testBug527742() { + runConformTest(new String[] { + "test/Test.java", + "package test;\n" + + "import java.util.stream.*;\n" + + "import java.util.*;\n" + + "\n" + + "class Test {\n" + + "\n" + + " public void f() {\n" + + "\n" + + " Map map = new HashMap<>();\n" + + " map.put(1, \"x\");\n" + + " map.put(2, \"y\");\n" + + " map.put(3, \"x\");\n" + + " map.put(4, \"z\");\n" + + "\n" + + " //the following line has error\n" + + " Map> reverseMap = new java.util.HashMap<>(map.entrySet().stream()\n" + + " .collect(Collectors.groupingBy(Map.Entry::getValue)).values().stream()\n" + + " .collect(Collectors.toMap(item -> item.get(0).getValue(),\n" + + " item -> new ArrayList<>(item.stream().map(Map.Entry::getKey).collect(Collectors.toList()))))); \n" + + " System.out.println(reverseMap);\n" + + "\n" + + " }\n" + + "\n" + + "}", + + }); + } + public void testBug528045() { + runConformTest(new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "interface List {\n" + + " List append(List other);\n" + + "}\n" + + "\n" + + "interface Function {\n" + + " B1 f(A1 a);\n" + + "}\n" + + "\n" + + "interface BiFunction {\n" + + " C2 f(A2 a, B2 b);\n" + + "}\n" + + "\n" + + "interface Stream {\n" + + " B3 foldLeft(Function> f, B3 b);\n" + + "\n" + + " C3 foldLeft(BiFunction f, C3 b);\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " List f(Stream> map, List nil) {\n" + + " return map.foldLeft(List::append, nil);\n" + + " }\n" + + "}\n" + + "" + }); + } + public void testBug528046() { + runConformTest(new String[] { + "test2/Test.java", + "package test2;\n" + + "\n" + + "interface Supplier {\n" + + " A0 f();\n" + + "}\n" + + "\n" + + "interface Function {\n" + + " B2 f(A1 a);\n" + + "}\n" + + "\n" + + "interface P {\n" + + " void lazy(Supplier f);\n" + + "\n" + + " void lazy(Function f);\n" + + "}\n" + + "\n" + + "class Nil {\n" + + "}\n" + + "\n" + + "class Test {\n" + + " static void test(P p) {\n" + + " p.lazy(Nil::new);\n" + + " }\n" + + "}\n" + + "" + }); + } + public void testBug519380() { + runConformTest( + new String[] { + "TestLambda.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "public class TestLambda {\n" + + "\n" + + " protected static Map newMap(final Function loader) {\n" + + " return new HashMap<>();\n" + + " }\n" + + "\n" + + " private final Map working = newMap(key -> {\n" + + "\n" + + " final List strings = new ArrayList<>();\n" + + "\n" + + " final String[] array = strings.toArray(new String[strings.size()]);\n" + + " foo(array);\n" + + "\n" + + " return null;\n" + + " });\n" + + "\n" + + " private final Map notWorking = newMap(key -> {\n" + + "\n" + + " final List strings = new ArrayList<>();\n" + + "\n" + + " // This line seems to be the root of all evils\n" + + " foo(strings.toArray(new String[strings.size()]));\n" + + "\n" + + " return null;\n" + + " });\n" + + "\n" + + " private void foo(final String[] x) {}\n" + + "\n" + + " private void foo(final Integer[] x) {}\n" + + "\n" + + "}\n" + }); + } + public void testBug519147() { + runConformTest( + new String[] { + "Main.java", + "import java.util.HashMap;\n" + + "import java.util.HashSet;\n" + + "import java.util.Set;\n" + + "\n" + + "public class Main {\n" + + "\n" + + " static class MyMap extends HashMap {\n" + + " public MyMap putAllReturning(MyMap c) { putAll(c); return this; }\n" + + " public MyMap putReturning(K key, V value) { put(key, value); return this; }\n" + + " }\n" + + "\n" + + " public Main() {\n" + + " Set values = new HashSet<>(); // actually something better\n" + + " final MyMap myMap =\n" + + " values.stream()\n" + + " .reduce(\n" + + " new MyMap(),\n" + + " (map, value) -> {\n" + + " Set keys = new HashSet<>(); // actually something better\n" + + "\n" + + " return keys.stream()\n" + + " .reduce(\n" + + " map, // this would work syntactically: new MyMap(),\n" + + " (map2, key) -> map2.putReturning(key, value),\n" + + " MyMap::putAllReturning);\n" + + " },\n" + + " MyMap::putAllReturning\n" + + " );\n" + + " }\n" + + "}\n" + }); + } + // no change + public void testBug521982_comment1() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T test(T a, Integer x) { return a; }\n" + + " T test(T a, int x) { return a; }\n" + + " void doit1(Number nIn) {\n" + + " // in assignment context, primitive or boxed target type does not influence overloading\n" + + " Number n1 = test(nIn, 3);\n" + + " int n2 = test(Integer.valueOf(2), Integer.valueOf(3)); // not ambiguous because one inferences succeeds in strict mode\n" + + " }\n" + + " void fun(int i) {}\n" + + " void doit2() {\n" + + " // unboxing allowed if outer invocation is unambiguous\n" + + " fun(test(Integer.valueOf(2), 3));\n" + + " }\n" + + " void fun2(int i, T t) {} // not picked, requires loose mode\n" + + " void fun2(Integer i, T t) {}\n" + + " void doit3() {\n" + + " // primitive arg puts inference to loose mode, then losing during overload resolution\n" + + " fun2(test(Integer.valueOf(2), 3), this);\n" + + " }\n" + + " void fun3(int i, int j) {} // requires loose mode for param 1\n" + + " void fun3(Integer i, T t) {} // requires loose mode for param 2\n" + + " void doit4() {\n" + + " // ambiguous because both candidates require loose mode\n" + + " fun3(test(Integer.valueOf(2), 3), 4);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " fun3(test(Integer.valueOf(2), 3), 4);\n" + + " ^^^^\n" + + "The method fun3(int, int) is ambiguous for the type X\n" + + "----------\n"); + } + + public void testBug529518() { + Runner run = new Runner(); + run.testFiles = new String[] { + "Try.java", + "import java.util.function.*;\n" + + "public class Try {\n" + + " @FunctionalInterface\n" + + " interface CheckedSupplier {\n" + + " R get() throws Throwable;\n" + + " }\n" + + " static Try of(CheckedSupplier supplier) {\n" + + " return null;\n" + + " }\n" + + " T getOrElseGet(Function other) { return null; }\n" + + "}\n", + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " byte[] decode(byte[] base64Bytes) {\n" + + " return Try.of(() -> Base64.getDecoder().decode(base64Bytes))\n" + + " .getOrElseGet(t -> null);\n" + + " }\n" + + "}\n" + + "" + }; + run.runConformTest(); + } + public void testBug528970() throws Exception { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "import java.util.concurrent.atomic.*;\n" + + "public class X {\n" + + " public static List returnNull(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main( String[] args )\n" + + " {\n" + + " List> l = returnNull(AtomicReference.class);\n" + + " }" + + "}\n" + }); + } + public void testBug530235() { + runNegativeTest( + new String[] { + "X.java", + "interface MySupplier {\n" + + " V get(Object x) throws Exception;\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public S getSmth() {\n" + + " return exec(s -> {return X.getType(Integer.class);}); /*here the error*/\n" + + " }\n" + + " \n" + + " public static T getType(Class class1) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public U exec(MySupplier supplier) {\n" + + " throw new RuntimeException(\"Not implemented yet\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return exec(s -> {return X.getType(Integer.class);}); /*here the error*/\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to S\n" + + "----------\n"); + } + public void testBug531681() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "\n" + + "import java.util.Arrays;\n" + + "import java.util.function.IntFunction;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final long[][] someData = new long[0][];\n" + + "\n" + + " IntFunction function1 = long[][]::new;\n" + + " IntFunction function2 = new IntFunction() {\n" + + " @Override\n" + + " public long[][] apply(int value) { return new long[value][]; }\n" + + " };\n" + + "\n" + + " long[][] array1 = Arrays.stream(someData).toArray(long[][]::new); // works\n" + + " long[][] array2 = Arrays.stream(someData).toArray(function2); // compile error in ecj at compliance 1.8\n" + + " long[][] array3 = Arrays.stream(someData).toArray(function1); // compile error in ecj at compliance 1.8\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); + } + public void testBug488328_001() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static class A {\n" + + " class I {\n" + + " }\n" + + " }\n" + + "\n" + + " public static void m(A.I instance, R generic) {\n" + + " System.out.println(\"called with A.I\");\n" + + " }\n" + + "\n" + + " public static void m(long l, Object o) {\n" + + " System.out.println(\"called with long\");\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " Long l = new Long(3);\n" + + " m(l, l);\n" + + " }\n" + + "}" + }); + } + public void testBug488328_002() { + runConformTest( + new String[] { + "Test.java", + "class A1 {\n"+ + " class I1 {}\n"+ + "}\n"+ + "public class Test extends A1{\n" + + " class A2 {\n" + + " class I2 extends A1.I1 {}\n" + + " }\n" + + "\n" + + " public static void m(A1.I1 instance) {\n" + + " System.out.println(\"called with A1.I1\");\n" + + " }\n" + + " public static void main(String... args) {\n" + + " Test.A2.I2 l = new Test().new A2().new I2();\n" + + " m(l);\n" + + " }\n" + + "}" + }); + } + public void testBug535969() { + runConformTest( + new String[] { + "Test.java", + "import java.util.List;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " List strings = Stream.of(1, 2, 3).map(i -> {\n" + + " return new Object() {\n" + + " final Integer myInt = i;\n" + + " };\n" + + " }).map(o -> {\n" + + " return o.myInt.toString();\n" + + " }).collect(Collectors.toList());\n" + + " }\n" + + "}\n" + }); + } + public void testBug535969b() { + runConformTest( + new String[] { + "B.java", + "\n" + + "import java.util.Optional;\n" + + "import java.util.function.Supplier;\n" + + "import java.io.Serializable;\n" + + "\n" + + "public class B {\n" + + " public static void main(String[] args) {\n" + + "\n" + + " // This works fine:\n" + + " System.out.println(new Object() {\n" + + " int j = 5;\n" + + " }.j);\n" + + "\n" + + " // This also\n" + + " System.out.println(trace(new Object() {\n" + + " int j = 5;\n" + + " }).j);\n" + + "\n" + + " // Also no problem\n" + + " System.out.println(unwrapAndTrace(Optional.of(new Object() {\n" + + " int j = 5;\n" + + " })).j);\n" + + "\n" + + " // Lambdas work:\n" + + " System.out.println(((Supplier & Serializable) () -> new Object()).get()); \n" + + "\n" + + " // This doesn't work.\n" + + " System.out.println(invokeAndTrace(() -> new Object() {\n" + + " int j = 5;\n" + + " }).j);\n" + + " }\n" + + "\n" + + " public static T trace(T obj) {\n" + + " System.out.println(obj);\n" + + " return obj;\n" + + " }\n" + + "\n" + + " public static T invokeAndTrace(Supplier supplier) {\n" + + " T result = supplier.get();\n" + + " System.out.println(result);\n" + + " return result;\n" + + " }\n" + + "\n" + + " public static T unwrapAndTrace(Optional optional) {\n" + + " T result = optional.get();\n" + + " System.out.println(result);\n" + + " return result;\n" + + " }\n" + + "}\n" + }); + } + public void testBug477894() { + runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " static class Foo {\n" + + " private final T arg;\n" + + " public Foo(T arg) {\n" + + " this.arg = arg;\n" + + " }\n" + + " Foo select(java.util.function.Function transformer) {\n" + + " return new Foo<>(transformer.apply(this.arg));\n" + + " }\n" + + " R select2(java.util.function.Function transformer) {\n" + + " return transformer.apply(this.arg);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String out = new Foo(null)\n" + + " .select(x -> new Object() {\n" + + " String alias = \"anonymous#1\";\n" + + " })\n" + + " .select2(x -> x.alias);\n" + + " System.out.println(out);\n" + + " }\n" + + "}\n" + }); + } + public void testBug427265() { + runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List ss = Arrays.asList(\"1\", \"2\", \"3\");\n" + + " ss.stream().map(s -> new Object() { });\n" + + " }\n" + + "}\n" + }); + } + public void testBug427265_comment6() { + runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void m() {\n" + + " List ss = Arrays.asList(\"1\", \"2\", \"3\");\n" + + " \n" + + " ss.stream().map(s -> {\n" + + " class L1 {};\n" + + " class L2 {\n" + + " L1 mm(L1 l) { return l;}\n" + + " }\n" + + " return new L2().mm(new L1());\n" + + " }).forEach(e -> System.out.println(e));\n" + + " }\n" + + "}\n" + }); + } + public void testBug525580() { + Runner runner = new Runner(); + runner.customOptions = new HashMap(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, JavaCore.IGNORE); + runner.testFiles = + new String[] { + "org/a/a/g/d.java", + "package org.a.a.g;\n" + + "\n" + + "public class d {\n" + + "\n" + + " public T a(Class cls) {\n" + + " T t = (e) cls.newInstance();\n" + + " while (size >= 0) {\n" + + " T a = ((b) this.e.m.get(size)).a();\n" + + " t = a;\n" + + " }\n" + + " return t;\n" + + " }\n" + + "\n" + + " public interface b {\n" + + " T a();\n" + + "\n" + + " T b();\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in org\\a\\a\\g\\d.java (at line 5)\n" + + " public T a(Class cls) {\n" + + " ^\n" + + "e cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in org\\a\\a\\g\\d.java (at line 6)\n" + + " T t = (e) cls.newInstance();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "e cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in org\\a\\a\\g\\d.java (at line 6)\n" + + " T t = (e) cls.newInstance();\n" + + " ^\n" + + "e cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in org\\a\\a\\g\\d.java (at line 7)\n" + + " while (size >= 0) {\n" + + " ^^^^\n" + + "size cannot be resolved to a variable\n" + + "----------\n" + + "5. ERROR in org\\a\\a\\g\\d.java (at line 8)\n" + + " T a = ((b) this.e.m.get(size)).a();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from e to T\n" + + "----------\n" + + "6. ERROR in org\\a\\a\\g\\d.java (at line 8)\n" + + " T a = ((b) this.e.m.get(size)).a();\n" + + " ^\n" + + "e cannot be resolved or is not a field\n" + + "----------\n" + + "7. ERROR in org\\a\\a\\g\\d.java (at line 8)\n" + + " T a = ((b) this.e.m.get(size)).a();\n" + + " ^^^^\n" + + "size cannot be resolved to a variable\n" + + "----------\n" + + "8. ERROR in org\\a\\a\\g\\d.java (at line 15)\n" + + " T a();\n" + + " ^\n" + + "e cannot be resolved to a type\n" + + "----------\n" + + "9. ERROR in org\\a\\a\\g\\d.java (at line 17)\n" + + " T b();\n" + + " ^\n" + + "j cannot be resolved to a type\n" + + "----------\n" + + "10. WARNING in org\\a\\a\\g\\d.java (at line 17)\n" + + " T b();\n" + + " ^^^\n" + + "This method has a constructor name\n" + + "----------\n"; + runner.runNegativeTest(); + } + public void testBug525580_comment28() { + Runner runner = new Runner(); + runner.customOptions = new HashMap(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, JavaCore.IGNORE); + runner.testFiles = + new String[] { + "xxxxxx/iiibii.java", + "package xxxxxx;\n" + + "\n" + + "public class iiibii {\n" + + "\n" + + " public T b041D041D041D041DН041DН(xxxxxx.jjajaa jjajaa) {\n" + + " }\n" + + "\n" + + " public xxxxxx.jajaja bН041D041D041DН041DН(byte b, byte b2) {\n" + + " return b041D041D041D041DН041DН(new xxxxxx.jjajaa(b, b2));\n" + + " }\n" + + "}\n", + "xxxxxx/jjajaa.java", + "package xxxxxx;\n" + + "\n" + + "public class jjajaa implements java.io.Serializable, java.lang.Comparable {\n" + + " private byte b0445х0445хх04450445;\n" + + " private byte bхх0445хх04450445;\n" + + "\n" + + " public jjajaa(byte b, byte b2) {\n" + + " this.bхх0445хх04450445 = b;\n" + + " this.b0445х0445хх04450445 = b2;\n" + + " }\n" + + "\n" + + " public int b043704370437з04370437з(xxxxxx.jjajaa jjajaa) {\n" + + " int i = this.bхх0445хх04450445 - jjajaa.bхх0445хх04450445;\n" + + " return i != 0 ? i : this.b0445х0445хх04450445 - jjajaa.b0445х0445хх04450445;\n" + + " }\n" + + "\n" + + " public byte[] bззз043704370437з() {\n" + + " return new byte[]{this.bхх0445хх04450445, this.b0445х0445хх04450445};\n" + + " }\n" + + "\n" + + " public /* synthetic */ int compareTo(java.lang.Object obj) {\n" + + " return b043704370437з04370437з((xxxxxx.jjajaa) obj);\n" + + " }\n" + + "\n" + + " public boolean equals(java.lang.Object obj) {\n" + + " if (obj == null || getClass() != obj.getClass()) {\n" + + " return false;\n" + + " }\n" + + " xxxxxx.jjajaa jjajaa = (xxxxxx.jjajaa) obj;\n" + + " return this.bхх0445хх04450445 == jjajaa.bхх0445хх04450445 && this.b0445х0445хх04450445 == jjajaa.b0445х0445хх04450445;\n" + + " }\n" + + "\n" + + " public int hashCode() {\n" + + " return ((this.bхх0445хх04450445 + 427) * 61) + this.b0445х0445хх04450445;\n" + + " }\n" + + "\n" + + " public java.lang.String toString() {\n" + + " return xxxxxx.ttotoo.bг04330433г04330433г(this.bхх0445хх04450445) + xxxxxx.ttotoo.bг04330433г04330433г(this.b0445х0445хх04450445);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in xxxxxx\\iiibii.java (at line 5)\n" + + " public T b041D041D041D041DН041DН(xxxxxx.jjajaa jjajaa) {\n" + + " ^^^^^^^^^^^^^\n" + + "xxxxxx.jajaja cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in xxxxxx\\iiibii.java (at line 8)\n" + + " public xxxxxx.jajaja bН041D041D041DН041DН(byte b, byte b2) {\n" + + " ^^^^^^^^^^^^^\n" + + "xxxxxx.jajaja cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in xxxxxx\\iiibii.java (at line 9)\n" + + " return b041D041D041D041DН041DН(new xxxxxx.jjajaa(b, b2));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from jajaja to jajaja\n" + + "----------\n" + + "----------\n" + + "1. ERROR in xxxxxx\\jjajaa.java (at line 3)\n" + + " public class jjajaa implements java.io.Serializable, java.lang.Comparable {\n" + + " ^^^^^^\n" + + "The type jjajaa must implement the inherited abstract method Comparable.compareTo(jjajaa)\n" + + "----------\n" + + "2. WARNING in xxxxxx\\jjajaa.java (at line 3)\n" + + " public class jjajaa implements java.io.Serializable, java.lang.Comparable {\n" + + " ^^^^^^\n" + + "The serializable class jjajaa does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. ERROR in xxxxxx\\jjajaa.java (at line 21)\n" + + " public /* synthetic */ int compareTo(java.lang.Object obj) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method compareTo(Object) of type jjajaa has the same erasure as compareTo(T) of type Comparable but does not override it\n" + + "----------\n" + + "4. ERROR in xxxxxx\\jjajaa.java (at line 38)\n" + + " return xxxxxx.ttotoo.bг04330433г04330433г(this.bхх0445хх04450445) + xxxxxx.ttotoo.bг04330433г04330433г(this.b0445х0445хх04450445);\n" + + " ^^^^^^^^^^^^^\n" + + "xxxxxx.ttotoo cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in xxxxxx\\jjajaa.java (at line 38)\n" + + " return xxxxxx.ttotoo.bг04330433г04330433г(this.bхх0445хх04450445) + xxxxxx.ttotoo.bг04330433г04330433г(this.b0445х0445хх04450445);\n" + + " ^^^^^^^^^^^^^\n" + + "xxxxxx.ttotoo cannot be resolved to a type\n" + + "----------\n"; + runner.runNegativeTest(); + } + public void testBug340506() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public void setValue(Parameter parameter, T value) {\n" + + " System.out.println(\"Object\");\n" + + " }\n" + + "\n" + + " public void setValue(Parameter parameter, Field value) {\n" + + " System.out.println(\"Field\");\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Test().test();\n" + + " }\n" + + "\n" + + " private void test() {\n" + + " Parameter p1 = p1();\n" + + " Field f1 = f1();\n" + + " setValue(p1, f1);\n" + + " setValue(p1, null);\n" + + "\n" + + " Parameter p2 = p2();\n" + + " Field f2 = f2();\n" + + " setValue(p2, f2);\n" + + " setValue(p2, null);" + + " }\n" + + "\n" + + " private Field f1() {\n" + + " Field f1 = null;\n" + + " return f1;\n" + + " }\n" + + "\n" + + " private Parameter p1() {\n" + + " Parameter p1 = null;\n" + + " return p1;\n" + + " }\n" + + "\n" + + " private Parameter p2() {\n" + + " Parameter p2 = null;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " private Field f2() {\n" + + " Field f2 = null;\n" + + " return f2;\n" + + " }\n" + + "}\n" + + "\n" + + "interface Field {}\n" + + "interface Parameter {}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 18)\n" + + " setValue(p1, null);\n" + + " ^^^^^^^^\n" + + "The method setValue(Parameter, String) is ambiguous for the type Test\n" + + "----------\n" + + "2. ERROR in Test.java (at line 22)\n" + + " setValue(p2, f2);\n" + + " ^^^^^^^^\n" + + "The method setValue(Parameter, Object) is ambiguous for the type Test\n" + + "----------\n" + + "3. ERROR in Test.java (at line 23)\n" + + " setValue(p2, null); }\n" + + " ^^^^^^^^\n" + + "The method setValue(Parameter, Object) is ambiguous for the type Test\n" + + "----------\n"); + } + public void testBug333011() { + runNegativeTest( + new String[] { + "Example.java", + "import java.util.ArrayList;\n" + + "public class Example {\n" + + " public static void doSomething() {\n" + + " DoJobMr bean = getOnlyElement(new ArrayList());\n" + + " }\n" + + " public static T getOnlyElement(Iterable iterable) { \n" + + " return null;\n" + + " }\n" + + " public static class DoJobMr {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Example.java (at line 4)\n" + + " DoJobMr bean = getOnlyElement(new ArrayList());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Example.DoJobMr\n" + + "----------\n" + + "2. WARNING in Example.java (at line 4)\n" + + " DoJobMr bean = getOnlyElement(new ArrayList());\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"); + } + public void testBug537089() { + runConformTest( + new String[] { + "EclipseBug.java", + "public class EclipseBug {\n" + + " public static void foo(T p1, T p2) {}\n" + + "\n" + + " public void shouldCompile() {\n" + + " foo(new int[0], new byte[0]);\n" + + " }\n" + + "}\n" + }); + } + public void testBug539329() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "Bug539329.java", + " import java.util.*;\n" + + " \n" + + " public class Bug539329 {\n" + + "\n" + + " public static Collection> getClasses() {\n" + + " // This yields a compile error in 2018-09, but works in Photon.\n" + + " return Arrays.asList(One.class, Two.class, Three.class);\n" + + " }\n" + + "\n" + + " public static Collection> getClassesThatWorks() {\n" + + " // This works surprisinly in both versions\n" + + " return Arrays.asList(One.class, Two.class);\n" + + " }\n" + + " }\n" + + "\n" + + " class One extends Parent implements Interface { }\n" + + "\n" + + " class Two extends Parent implements Interface { }\n" + + "\n" + + " class Three extends Parent implements Interface { }\n" + + "\n" + + " class Parent { }\n" + + "\n" + + " interface Interface { }\n" + }; + runner.runConformTest(); + } + public void testBug543128() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "Bug543128.java", + "public class Bug543128 {\n" + + " static class A {}\n" + + " static class B extends A {}\n" + + " static class C {}\n" + + " \n" + + " public static void test(C> test)\n" + + " {\n" + + " test(test); // fails compilation (incorrect)\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); + } + public void testBug543820() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "A.java", + "import java.util.concurrent.atomic.AtomicReference;\n" + + "import java.util.Optional;\n" + + "public class A {\n" + + " private final ThreadLocal>> var =\n" + + " ThreadLocal.withInitial(() -> new AtomicReference<>(Optional.empty()));" + + "}\n" + }; + runner.runConformTest(); + } + public void testBug540846() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "Test.java", + "import java.util.*;\n" + + "import java.util.stream.*;\n" + + "import java.math.*;\n" + + "\n" + + "public class Test {\n" + + " private List getRowValues(Map record, Stream factors) {\n" + + " return Stream.concat(\n" + + " factors.map(f -> {\n" + + " if (f.equals(\"x\")) {\n" + + " return record.get(f);\n" + + " } else {\n" + + " return \"NM\";\n" + + " }\n" + + " }),\n" + + " Stream.of(BigDecimal.ONE)\n" + + " )\n" + + " .map(v -> (v instanceof BigDecimal) ? ((BigDecimal) v).setScale(10, BigDecimal.ROUND_HALF_UP) : v)\n" + + " .collect(Collectors.toList());\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); + } + public void testBug538192() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "Test.java", + "import java.util.*;\n" + + "import java.util.function.Function;\n" + + "interface ListFunc extends Function, T> {}\n" + + "interface MapFunc extends Function, T> {}\n" + + "class DTT {\n" + + " public DTT(Class c, ListFunc f) {}\n" + + " public DTT(Class c, MapFunc f) {} \n" + + "}\n" + + "public class Test {\n" + + " void test() {\n" + + " new DTT(Integer.class, (Map row) -> Integer.valueOf(0));\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); + } + public void testBug536860() { + runConformTest( + new String[] { + "Snippet.java", + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "import java.nio.file.Path;\n" + + "import java.util.Map;\n" + + "import java.util.concurrent.Callable;\n" + + "import java.util.function.Function;\n" + + "\n" + + "interface EntityReader { }\n" + + "class ExtraIOUtils {\n" + + " public static Callable getInputStreamProvider() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class Snippet {\n" + + " public EntityReader createEntityReader(\n" + + " Function colNameMapper,\n" + + " Function instantiator,\n" + + " Map runtimeValues)\n" + + " throws IOException {\n" + + " EntityReader streamReader =\n" + + " createEntityStreamReader(\n" + + " ExtraIOUtils.getInputStreamProvider(),\n" + + " colNameMapper, instantiator, runtimeValues);\n" + + " return null;\n" + + " }\n" + + " public EntityReader> createEntityStreamReader(\n" + + " Callable streamProvider,\n" + + " Function colNameMapper, Function instantiator,\n" + + " Map runtimeValues)\n" + + " throws IOException {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); + } + public void testBug545121() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(U arg1, T arg2, V arg3) {}\n" + + "\n" + + " void check() {\n" + + " foo((Long) 0l, 0d, \"\");\n" + + " }\n" + + "}\n" + }); + } + public void testBug545082a() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "Test.java", + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class Test {\n" + + " public static void main(String[] args)\n" + + " {\n" + + " println(Stream.of(42).collect(Collectors.summingDouble(d -> d))); \n" + + " }\n" + + " public static void println(double x) {}\n" + + " public static void println(char[] x) {}\n" + + " public static void println(String x) {}\n" + + " public static void println(Object x) {} \n" + + "}\n" + }; + runner.runConformTest(); + } + public void testBug545082b() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "Test.java", + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class Test {\n" + + " char[] f;" + + " public void test() {\n" + + " f = Stream.of(42).collect(Collectors.summingDouble(d -> d)); \n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in Test.java (at line 6)\n" + + " f = Stream.of(42).collect(Collectors.summingDouble(d -> d)); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Double to char[]\n" + + "----------\n"; + runner.runNegativeTest(); + } + public void testBug512156_3() { + runConformTest( + new String[] { + "TestFor3TypeParameters.java", + "import java.util.Objects;\n" + + "import java.util.stream.Stream;\n" + + "import java.util.stream.StreamSupport;\n" + + "\n" + + "/**\n" + + " * For comprehension for 3 iterables. Adapted from the http://javaslang.io library to help finding JDT performance bottlenecks.\n" + + " *\n" + + " */\n" + + "public class TestFor3TypeParameters {\n" + + "\n" + + " public interface Function3 {\n" + + " R apply(T1 t1, T2 t2, T3 t3);\n" + + " } \n" + + " \n" + + " public static class For3 {\n" + + "\n" + + " private final Iterable ts1;\n" + + " private final Iterable ts2;\n" + + " private final Iterable ts3;\n" + + "\n" + + " private For3(Iterable ts1, Iterable ts2, Iterable ts3) {\n" + + " this.ts1 = ts1;\n" + + " this.ts2 = ts2;\n" + + " this.ts3 = ts3;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Yields a result for elements of the cross product of the underlying Iterables.\n" + + " *\n" + + " * @param f\n" + + " * a function that maps an element of the cross product to a result\n" + + " * @param \n" + + " * type of the resulting {@code Iterator} elements\n" + + " * @return an {@code Iterator} of mapped results\n" + + " */\n" + + " public Stream yield(\n" + + " Function3 f) {\n" + + " Objects.requireNonNull(f, \"f is null\");\n" + + " return this.stream(ts1)\n" + + " .flatMap(t1 ->\n" + + " stream(ts2).flatMap(t2 -> \n" + + " stream(ts3).map(t3 ->\n" + + " f.apply(t1, t2, t3)\n" + + " )\n" + + " )\n" + + " );\n" + + " }\n" + + "\n" + + " private Stream stream(Iterable iterable) {\n" + + " return StreamSupport.stream(iterable.spliterator(), false);\n" + + " }\n" + + "\n" + + " }\n" + + "}\n" + }); + } + public void testBug512156_10() { + runConformTest( + new String[] { + "Test10.java", + "import java.util.Objects;\n" + + "import java.util.stream.Stream;\n" + + "import java.util.stream.StreamSupport;\n" + + "\n" + + "/**\n" + + " * For comprehension for 10 iterables. Adapted from the http://javaslang.io library to help finding JDT performance bottlenecks.\n" + + " *\n" + + " */\n" + + "public class Test10 {\n" + + "\n" + + " public interface Function10 {\n" + + " R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9, T10 t10);\n" + + " } \n" + + " \n" + + " public static class For10 {\n" + + "\n" + + " private final Iterable ts1;\n" + + " private final Iterable ts2;\n" + + " private final Iterable ts3;\n" + + " private final Iterable ts4;\n" + + " private final Iterable ts5;\n" + + " private final Iterable ts6;\n" + + " private final Iterable ts7;\n" + + " private final Iterable ts8;\n" + + " private final Iterable ts9;\n" + + " private final Iterable ts10;\n" + + "\n" + + " private For10(Iterable ts1, Iterable ts2, Iterable ts3, Iterable ts4, Iterable ts5, Iterable ts6,\n" + + " Iterable ts7, Iterable ts8, Iterable ts9, Iterable ts10) {\n" + + " this.ts1 = ts1;\n" + + " this.ts2 = ts2;\n" + + " this.ts3 = ts3;\n" + + " this.ts4 = ts4;\n" + + " this.ts5 = ts5;\n" + + " this.ts6 = ts6;\n" + + " this.ts7 = ts7;\n" + + " this.ts8 = ts8;\n" + + " this.ts9 = ts9;\n" + + " this.ts10 = ts10;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Yields a result for elements of the cross product of the underlying Iterables.\n" + + " *\n" + + " * @param f\n" + + " * a function that maps an element of the cross product to a result\n" + + " * @param \n" + + " * type of the resulting {@code Iterator} elements\n" + + " * @return an {@code Iterator} of mapped results\n" + + " */\n" + + " public Stream yield(\n" + + " Function10 f) {\n" + + " Objects.requireNonNull(f, \"f is null\");\n" + + " return this.stream(ts1)\n" + + " .flatMap(t1 ->\n" + + " stream(ts2).flatMap(t2 -> \n" + + " stream(ts3).flatMap(t3 -> \n" + + " stream(ts4).flatMap(t4 -> \n" + + " stream(ts5).flatMap(t5 -> \n" + + " stream(ts6).flatMap(t6 -> \n" + + " stream(ts7).flatMap(t7 -> \n" + + " stream(ts8).flatMap(t8 ->\n" + + " stream(ts9).flatMap(t9 ->\n" + + " stream(ts10).map(t10 -> /**/\n" + + " f.apply(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)\n" + + " )\n" + + " )\n" + + " )\n" + + " )\n" + + " )\n" + + " )\n" + + " )\n" + + " )\n" + + " )\n" + + " );\n" + + " }\n" + + "\n" + + " private Stream stream(Iterable iterable) {\n" + + " return StreamSupport.stream(iterable.spliterator(), false);\n" + + " }\n" + + "\n" + + " }\n" + + "}\n" + }); + } + public void testBug547061() { + runConformTest( + new String[] { + "test2/Problematic.java", + "package test2;\n" + + "\n" + + "import java.io.IOException;\n" + + "import java.util.Collections;\n" + + "import java.util.Set;\n" + + "import java.util.function.Consumer;\n" + + "\n" + + "public class Problematic {\n" + + "\n" + + " @FunctionalInterface\n" + + " private interface ThrowingConsumer {\n" + + " void accept(T t) throws E;\n" + + " }\n" + + "\n" + + " private class FileAsset {\n" + + " public FileAsset move(String path) throws IOException {\n" + + " System.out.println(path);\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " static void process(Consumer> code, ThrowingConsumer throwingConsumer)\n" + + " throws E {\n" + + " code.accept(t -> {\n" + + " try {\n" + + " throwingConsumer.accept(t);\n" + + " } catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " });\n" + + " }\n" + + "\n" + + " public void execute(String path) throws IOException {\n" + + " Set set = Collections.singleton(new FileAsset());\n" + + " process(set::forEach, (asset) -> {\n" + + " process(set::forEach, (asset2) -> {\n" + + " asset2.move(path);\n" + + " });\n" + + " });\n" + + "\n" + + " }\n" + + "}\n" + }); + } + public void testBug545420() { + runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) { \n" + + " System.out.println(new Main().getDetailCellCssFactory().getReturn());\n" + + " }\n" + + "\n" + + " public FIReturnType getDetailCellCssFactory() {\n" + + " \n" + + " return method1(()-> {\n" + + " return () ->{\n" + + " return \"something\";\n" + + " };\n" + + " });\n" + + " }\n" + + " \n" + + " public X method1(FIWithGenerics init) {\n" + + " return init.init(); \n" + + " }\n" + + "}\n" + + "interface FIReturnType {\n" + + " String getReturn();\n" + + "}\n" + + "interface FIWithGenerics {\n" + + " X init();\n" + + "}\n" + }); + } + public void testBug525822() { + runNegativeTest( + new String[] { + "ECJTest.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "\n" + + "public class ECJTest {\n" + + "\n" + + " static {\n" + + " final List list = new ArrayList<>();\n" + + " accept(list::add);\n" + + " }\n" + + "\n" + + " static void accept(Consumer yay) {};\n" + + " static void accept(BiConsumer nooo) {};\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in ECJTest.java (at line 8)\n" + + " accept(list::add);\n" + + " ^^^^^^\n" + + "The method accept(Consumer) is ambiguous for the type ECJTest\n" + + "----------\n"); + } + public void testBug502327() { + runConformTest( + new String[] { + "Bug.java", + "public class Bug {\n" + + "\n" + + " public void execute() {\n" + + " foo(bar(new ExampleType()));\n" + + " }\n" + + "\n" + + " public void foo(ClassB a) {}\n" + + "\n" + + " public ClassC bar(T t) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public class ClassC extends ClassB.NestedClassC> {\n" + + " public class NestedClassC {}\n" + + " }\n" + + "\n" + + " public abstract static class ClassB {}\n" + + "\n" + + " public class ExampleType {}\n" + + "}\n" + }); + } + public void testBug547807() { + runConformTest( + new String[] { + "DslStep1.java", + "public interface DslStep1 {\n" + + " DslStep2 nextStep();\n" + + "}\n", + "DslStep2.java", + "public interface DslStep2> {\n" + + " S doSomething();\n" + + "}\n", + "CallBug.java", + "public class CallBug {\n" + + " public void doesNotCompileWithEcj(DslStep1 step1) {\n" + + " // Note we need three chained calls for the problem to show up. Two is not enough.\n" + + " step1.nextStep().doSomething().doSomething().doSomething();\n" + + " }\n" + + "}\n" + }); + } + public void testBug548589() { + runConformTest( + new String[] { + "InferenceCheck.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "\n" + + "public class InferenceCheck {\n" + + "\n" + + " public interface P {\n" + + "\n" + + " public boolean apply(T value); \n" + + " }\n" + + "\n" + + " public static P compilation_failed(P predicate) {\n" + + " List> list = Collections.emptyList();\n" + + " list.stream().map(InferenceCheck::compilation_failed);\n" + + " return null;\n" + + " } \n" + + "\n" + + " public static P compilation_ok(P predicate) {\n" + + " List> list = Collections.emptyList();\n" + + " Function, P> f = InferenceCheck::compilation_ok;\n" + + " list.stream().map(f);\n" + + " return null;\n" + + " } \n" + + "}\n" + }); + } + + public void testBug534466() { + runNegativeTest( + new String[] { + "test/TODO.java", + "package test;\n" + + "public interface TODO {\n" + + " boolean test();\n" + + "}\n", + "test/FuncN.java", + "package test;\n" + + "\n" + + "@FunctionalInterface\n" + + "public interface FuncN {\n" + + " State zip(State ...states);\n" + + "}\n", + "test/Test.java", + "package test;\n" + + "public class Test {\n" + + "\n" + + " public static Test define(FuncN zipperFunc,TODO... tasks) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static Test define(TODO... tasks) {\n" + + " return null;\n" + + " }\n" + + "}\n", + "test/State.java", + "package test;\n" + + "public class State {\n" + + " public static State mergeStates(State ...states) {\n" + + " return null;\n" + + " }\n" + + "}\n", + "test/Main.java", + "package test;\n" + + "\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " Test.define(State::mergeStates,()->true);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\Main.java (at line 5)\n" + + " Test.define(State::mergeStates,()->true);\n" + + " ^^^^^^\n" + + "The method define(FuncN, TODO[]) is ambiguous for the type Test\n" + + "----------\n"); + } + + public void testBug534223() { + Runner runner = new Runner(); + String sourceX = + "package p;\n" + + "public class X {\n" + + " void m() {\n" + + " Runnable r = () -> {\n" + + " IFC i = new IFC() {\n" + + " public void n(S s) {}\n" + + " };\n" + + " if (i != null)\n" + + " System.out.println(i);\n" + + " };\n" + + " r.run();\n" + + " }\n" + + "}\n"; + runner.testFiles = new String[] { + "p/IFC.java", + "package p;\n" + + "public interface IFC {\n" + + " void n(T t);\n" + + "}\n", + "p/X.java", + sourceX + }; + runner.runConformTest(); + runner.shouldFlushOutputDirectory = false; + runner.testFiles = new String[] { + "p/X.java", + sourceX + }; + runner.runConformTest(); // don't use pre-compiled p/X$1.class + } + + public void testBug559449() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " class $$$ {}\n" + + " void m() {\n" + + " Runnable r = () -> {\n" + + " $$$ ddd = new $$$();\n" + + " if (ddd != null)\n" + + " System.out.println(ddd);\n" + + " };\n" + + " r.run();\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); + } + public void testBug559677() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "MyClass.java", + "public class MyClass {\n" + + " private void myRun() {\n" + + " }\n" + + " private void myMethod(final Runnable r) {\n" + + " }\n" + + " public void test() {\n" + + " // second opening brace causes endless loop while saving\n" + + " myMethod((this::myRun);\n" + + " }\n" + + "}\n" + }; + runner.performStatementsRecovery = true; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in MyClass.java (at line 8)\n" + + " myMethod((this::myRun);\n" + + " ^\n" + + "Syntax error, insert \")\" to complete Expression\n" + + "----------\n"; + runner.runNegativeTest(); + } + public void testBug559951() { + if (this.complianceLevel < ClassFileConstants.JDK10) return; // uses 'var' + runConformTest( + new String[] { + "no/Demo.java", + "package no;\n" + + "public class Demo {\n" + + " static void broken_method_dispatch_on_bounded_type_in_lambda_argument_with_Eclipse_compiler() {\n" + + " WithMessageRecipients withRecipients = new Message(new EmailRecipient(\"Jane\", \"jane@example.com\"), new EmailRecipient(\"Joe\", \"joe@example.com\"));\n" + + "\n" + + " withRecipients.getMessageRecipients()\n" + + " .stream()\n" + + " .forEach(recipient -> System.out.println(recipient.getName() + \" <\" + recipient.getEmailAddress() + \">\"));\n" + + " }\n" + + " static void works_fine_in_for_loop() {\n" + + " WithMessageRecipients withRecipients = new Message(new EmailRecipient(\"Jane\", \"jane@example.com\"), new EmailRecipient(\"Joe\", \"joe@example.com\"));\n" + + "\n" + + " for (var recipient : withRecipients.getMessageRecipients()) {\n" + + " System.out.println(recipient.getName() + \" <\" + recipient.getEmailAddress() + \">\");\n" + + " }\n" + + " }\n" + + " public static void main(String... args) {\n" + + " works_fine_in_for_loop();\n" + + " broken_method_dispatch_on_bounded_type_in_lambda_argument_with_Eclipse_compiler();\n" + + " }\n" + + "}\n", + "no/WithName.java", + "package no;\n" + + "public interface WithName {\n" + + " String getName();\n" + + "}", + "no/WithEmailAddress.java", + "package no;\n" + + "public interface WithEmailAddress {\n" + + " String getEmailAddress();\n" + + "}\n", + "no/WithMessageRecipients.java", + "package no;\n" + + "import java.util.List;\n" + + "public interface WithMessageRecipients {\n" + + " List getMessageRecipients();\n" + + "}", + "no/EmailRecipient.java", + "package no;\n" + + "public class EmailRecipient implements WithName, WithEmailAddress {\n" + + " private final String name;\n" + + " private final String emailAddress;\n" + + " public EmailRecipient(String name, String emailAddress) {\n" + + " this.name = name;\n" + + " this.emailAddress = emailAddress;\n" + + " }\n" + + " @Override\n" + + " public String getEmailAddress() {\n" + + " return emailAddress;\n" + + " }\n" + + " @Override\n" + + " public String getName() {\n" + + " return name;\n" + + " }\n" + + "}", + "no/Message.java", + "package no;\n" + + "import java.util.List;\n" + + "public class Message implements WithMessageRecipients {\n" + + " private final List recipients;\n" + + " public Message(EmailRecipient ... recipients) {\n" + + " this.recipients = List.of(recipients);\n" + + " }\n" + + " @Override\n" + + " public List getMessageRecipients() {\n" + + " return recipients;\n" + + " }\n" + + "}" + }, + "Jane \n" + + "Joe \n" + + "Jane \n" + + "Joe "); + } + public void testBug560566() { + runNegativeTest( + new String[] { + "Tester.java", + "import java.util.ArrayList;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class Tester {\n" + + " {\n" + + " Stream.empty().collect(Collectors.toList(ArrayList::new));\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Tester.java (at line 7)\n" + + " Stream.empty().collect(Collectors.toList(ArrayList::new));\n" + + " ^^^^^^\n" + + "The method toList() in the type Collectors is not applicable for the arguments (ArrayList::new)\n" + + "----------\n"); + } + public void testBug568259() { + runNegativeTest( + new String[] { + "Main.java", + "public final class Main {\n" + + " public static Main invoke(Object o) {\n" + + " return null;\n" + + " }\n" + + " public void test() {\n" + + " invoke(new Main.Inner());\n" + + " } \n" + + "}" + }, + "----------\n" + + "1. ERROR in Main.java (at line 6)\n" + + " invoke(new Main.Inner());\n" + + " ^^^^^^^^^^\n" + + "Main.Inner cannot be resolved to a type\n" + + "----------\n"); + } + public void testBug562324comment31() { + runConformTest( + new String[] { + "X.java", + "import static java.util.stream.Collectors.*;\n" + + "import static java.util.stream.Stream.*;\n" + + "\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public void hello() {\n" + + " Runnable r = new Runnable () {\n" + + " @Override\n" + + " public void run() {\n" + + " }\n" + + " };\n" + + " r.run();\n" + + " }\n" + + "\n" + + " static void bug() {\n" + + " Stream stream = of(\"\"); // error here\n" + + " }\n" + + "}\n" + }); + } + public void testBug573933() { + runConformTest( + new String[] { + "B.java", + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collectors;\n" + + "public class B {\n" + + " List r;\n" + + " B(final RC c) {\n" + + " r = m(c.getRI(), i -> t(i, x -> new M(x))); // no error\n" + + " r = m(c.getRI(), i -> t(i, M::new)); \n" + + " } \n" + + " static U m(T t, Function f) {\n" + + " return f.apply(t);\n" + + " }\n" + + " static List t(final List list, final Function function) {\n" + + " return list.stream().map(function).collect(Collectors.toList());\n" + + " }\n" + + "}\n" + + "class RC {\n" + + " List getRI() { return null; }\n" + + "}\n" + + "class M {\n" + + " Integer r;\n" + + " public M(final Integer r) {\n" + + " this.r = r;\n" + + " }\n" + + + // Removing this constructor makes the problem go away + " public M(final RC i) {\n" + + " this.r = 3;\n" + + " }\n" + + "}" + }); + + } + + public void testBug573378() { + runNegativeTest( + new String[] { + "TypeInferenceError.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import java.util.stream.*;\n" + + "\n" + + "public class TypeInferenceError {\n" + + " void test() {\n" + + " Optional> s = Optional.empty();\n" + + " map(s, Stream::count);\n" + + " assertThat(map(s, Stream::count));\n" + + " }\n" + + " private OptionalInt map(Optional o, ToIntFunction mapper) {\n" + + " return OptionalInt.empty();\n" + + " }\n" + + " private void assertThat(OptionalInt o) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in TypeInferenceError.java (at line 8)\n" + + " map(s, Stream::count);\n" + + " ^^^^^^^^^^^^^\n" + + "The type of count() from the type Stream is long, this is incompatible with the descriptor\'s return type: int\n" + + "----------\n" + + "2. ERROR in TypeInferenceError.java (at line 9)\n" + + " assertThat(map(s, Stream::count));\n" + + " ^^^^^^^^^^^^^\n" + + "The type of count() from the type Stream is long, this is incompatible with the descriptor\'s return type: int\n" + + "----------\n"); + } + public void testBug549446() { + if (this.complianceLevel < ClassFileConstants.JDK12) + return; // uses interface Constable + runConformTest( + new String[] { + "TestFile.java", + "import java.lang.constant.Constable;\n" + + "public class TestFile {\n" + + "\n" + + " @SafeVarargs\n" + + " public final E elements(E... args) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public void test1() {\n" + + " var v = elements(\"a\", 1);\n" + + " }\n" + + "\n" + + " public void test2() {\n" + + " var v = elements(\"a\", (Comparable & Constable) null);\n" + + " }\n" + + "}\n" + }); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_9.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_9.java new file mode 100644 index 0000000000..9469484856 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_9.java @@ -0,0 +1,729 @@ +/******************************************************************************* + * Copyright (c) 2016, 2021 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class GenericsRegressionTest_9 extends AbstractRegressionTest9 { + +static { +// TESTS_NAMES = new String[] { "testBug551913_001", "testBug551913_002" }; +// TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public GenericsRegressionTest_9(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); +} + +// vanilla test case +public void testBug488663_001() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public Y bar() {\n" + + " Y y = new Y<>() {\n" + + " @Override\n" + + " public void foo(String s) {\n" + + " this.s = s;\n" + + " }\n" + + " };\n" + + " return y;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Y y = new X().bar();\n" + + " y.foo(\"Done\");\n" + + " y.print();\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " String s;\n" + + " public abstract void foo(String s);\n" + + " public void print() {\n" + + " System.out.println(this.s);\n" + + " }\n" + + "}\n", + }, + "Done"); +} + +// negative test case for diamond operator instantiation of denotable anonymous type but with parameterized method +public void testBug488663_002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public Y bar() {\n" + + " Y y = new Y<>() {\n" + + " @Override\n" + + " public void foo(T t) {\n" + + " this.s = t;\n" + + " }\n" + + " };\n" + + " return y;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Y y = new X().bar();\n" + + " y.foo(\"Done\");\n" + + " y.print();\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " T s;\n" + + " public abstract void foo(T t);\n" + + " public void print() {\n" + + " System.out.println(this.s);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y y = new Y<>() {\n" + + " ^^^^^\n" + + "The type new Y(){} must implement the inherited abstract method Y.foo(String)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public void foo(T t) {\n" + + " ^\n" + + "T cannot be resolved to a type\n" + + "----------\n"); +} + +// diamond operator instantiation of denotable anonymous types with different type params +public void testBug488663_003() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + "@SuppressWarnings(\"unused\") \n" + + " public static void main(String[] args) {\n" + + " Y y1 = new Y<>(){};\n" + + " Y y2 = new Y<>(){};\n" + + " Y y3 = new Y<>() {};\n" + + " Y y4 = new Y<>() {};\n" + + " }\n" + + "}\n" + + "class Y {}\n", + }, + ""); +} + +// inner classes with diamond operator and anonymous classes +public void testBug488663_004() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + "@SuppressWarnings(\"unused\") \n" + + " public static void main(String[] args) {\n" + + " Y y1 = new X().new Y<>(){};\n" + + " Y y2 = new X().new Y<>(){};\n" + + " Y y3 = new X().new Y<>() {};\n" + + " Y y4 = new X().new Y<>() {};\n" + + " }\n" + + "\n" + + " class Y {}\n" + + "}\n", + }, + ""); +} + +// compiler error for non-denotable anonymous type with diamond operator - negative test +public void testBug488663_005() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "interface J{}\n" + + "class Y {}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Y y = new Y<>() {};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Y y = new Y<>() {};\n" + + " ^\n" + + "Type Y inferred for Y<>, is not valid for an anonymous class with '<>'\n" + + "----------\n"); + +} + +//compiler error for non-denotable anonymous type with diamond operator - negative test +public void testBug488663_006() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " Y(T x) {}\n" + + "}\n" + + "\n" + + "class X {\n" + + " public static void main(String[] args) {\n" + + " Y fi = null;\n" + + " Y f = new Y<>(fi){};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Y f = new Y<>(fi){};\n" + + " ^\n" + + "Type Y> inferred for Y<>, is not valid for an anonymous class with '<>'\n" + + "----------\n"); + +} +// instantiate an interface using the anonymous diamond +public void testBug488663_007() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String name;\n" + + " public X(String name) {\n" + + " this.name = name;\n" + + " }\n" + + " String name() {\n" + + " return this.name;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(\"Success\");\n" + + " I i = new I<>() {\n" + + " public String toString(X x1) {\n" + + " return x1.name();\n" + + " }\n" + + " };\n" + + " System.out.println(i.toString(x));\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " String toString(T t);\n" + + "}" + }, + "Success"); +} +// anonymous diamond instantiating interface as argument to an invocation +public void testBug488663_008() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String name;\n" + + " public X(String name) {\n" + + " this.name = name;\n" + + " }\n" + + " void print(T o, I converter) {\n" + + " System.out.println(converter.toString(o));\n" + + " }\n" + + " String name() {\n" + + " return this.name;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(\"Success\");\n" + + " x.print(x, new I<>() {\n" + + " public String toString(X x1) {\n" + + " return x1.name();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " String toString(T t);\n" + + "}" + }, + "Success"); +} +// anonymous diamond instantiating an abstract class as argument to an invocation +public void testBug488663_009() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String name;\n" + + " public X(String name) {\n" + + " this.name = name;\n" + + " }\n" + + " void print(T o, I converter) {\n" + + " System.out.println(converter.toString(o));\n" + + " }\n" + + " String name() {\n" + + " return this.name;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(\"Success\");\n" + + " x.print(x, new Z<>() {\n" + + " public String toString(X x1) {\n" + + " return x1.name();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " String toString(T t);\n" + + "}\n" + + "abstract class Z implements I {}\n" + }, + "Success"); +} +// anonymous diamond with polytype argument +public void testBug488663_010() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String name;\n" + + " public X(String name) {\n" + + " this.name = name;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Y y = new Y<>(() -> System.out.println(\"Done\")) {\n" + + " };\n" + + " }\n" + + "}\n" + + "interface J {\n" + + " void doSomething();\n" + + "}\n" + + "class Y {\n" + + " public Y(J j) {\n" + + " j.doSomething();\n" + + " }\n" + + "}", + }, + "Done"); +} +// anonymous diamond with polytype argument +public void testBug488663_011() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String name;\n" + + " public X(String name) {\n" + + " this.name = name;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Y y = new Y<>(Y::foo) {\n" + + " };\n" + + " }\n" + + "}\n" + + "interface J {\n" + + " void doSomething();\n" + + "}\n" + + "class Y {\n" + + " public Y(J j) {\n" + + " j.doSomething();\n" + + " }\n" + + " static void foo() {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}", + }, + "Done"); +} +// Nested anonymous diamonds - TODO - confirm that this is indeed correct as per spec +public void testBug488663_012() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String name;\n" + + " public X(String name) {\n" + + " this.name = name;\n" + + " }\n" + + " String name() {\n" + + " return this.name;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Y y = new Y<>(\"Done\", new I<>() {\n" + + " public void doSomething(String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }){\n" + + " };\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void doSomething(T t);\n" + + "}\n" + + "class Y {\n" + + " public Y(T t, I i) {\n" + + " i.doSomething(t);\n" + + " }\n" + + "}", + }, + "Done"); +} +// Redundant type argument specification - TODO - confirm that this is correct +public void testBug488663_013() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String name;\n" + + " public X(String name) {\n" + + " this.name = name;\n" + + " }\n" + + " String name() {\n" + + " return this.name;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(\"Success\");\n" + + " I i = new I() {\n" + + " public String toString(X x1) {\n" + + " return x1.name();\n" + + " }\n" + + " };\n" + + " System.out.println(i.toString(x));\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " String toString(T t);\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " I i = new I() {\n" + + " ^\n" + + "Redundant specification of type arguments \n" + + "----------\n", + null, true, options); +} +// All non-private methods of an anonymous class instantiated with '<>' must be treated as being annotated with @override +public void testBug488663_014() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String name;\n" + + " public X(String name) {\n" + + " this.name = name;\n" + + " }\n" + + " void print(T o, I converter) {\n" + + " System.out.println(converter.toString(o));\n" + + " }\n" + + " String name() {\n" + + " return this.name;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(\"asdasfd\");\n" + + " x.print(x, new Z<>() {\n" + + " public String toString(String s) {\n" + + " return s;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " String toString(T t);\n" + + "}\n" + + "class Z implements I {\n" + + " public String toString(T t) {\n" + + " return \"\";\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " public String toString(String s) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The method toString(String) of type new Z(){} must override or implement a supertype method\n" + + "----------\n"); +} +// Inaccessible type inferred for anonymous diamond is an error +public void testBug488663_015() { + this.runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " private static class Inner {" + + " public Inner(){}\n" + + " }\n" + + " void print(I i) {}\n" + + " public Inner get() {\n" + + " return new Inner();\n" + + " }\n" + + "}\n", + "Z.java", + "class Z implements I {\n" + + " public Z(T t1) {}\n" + + " public String toString (T t) {\n" + + " return t.toString();\n" + + " }\n" + + "}", + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test t = new Test<>();\n" + + " t.print(new Z<>(t.get()) {\n" + + " \n" + + " });\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " String toString();\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " t.print(new Z<>(t.get()) {\n" + + " ^^^^^^^^^^^^\n" + + "The type Test$Inner is not visible\n" + + "----------\n"); +} +// Inaccessible type inferred for anonymous diamond is an error - interface case +public void testBug488663_016() { + this.runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " private static class Inner {" + + " public Inner(){}\n" + + " }\n" + + " void print(I i) {}\n" + + " public Inner get() {\n" + + " return new Inner();\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test t = new Test<>();\n" + + " t.print(new I<>() {\n" + + " public String toString() {\n" + + " return \"\";\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " String toString();\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " t.print(new I<>() {\n" + + " ^^^^^\n" + + "The type Test$Inner is not visible\n" + + "----------\n"); +} +// All non-private methods of an anonymous class instantiated with '<>' must be treated as being annotated with @override +public void testBug517926() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String name;\n" + + " public X(String name) {\n" + + " this.name = name;\n" + + " }\n" + + " void print(T o, I converter) {\n" + + " System.out.println(converter.toString(o));\n" + + " }\n" + + " String name() {\n" + + " return this.name;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X(\"asdasfd\");\n" + + " x.print(x, new I<>() {\n" + + " public String name() {return null;}\n" + + " public String toString(X xx) {\n" + + " return xx.toString();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + + "interface I {\n" + + "private String name() {return null;}" + + " String toString(T t);\n" + + "default String getName() {return name();}" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " public String name() {return null;}\n" + + " ^^^^^^\n" + + "The method name() of type new I(){} must override or implement a supertype method\n" + + "----------\n"); +} +public void testBug521815a() { + runNegativeTest( + new String[] { + "a/b/X.java", + "package a.b;\n" + + "interface I{\n" + + " public static class Inner { }\n" + + "}\n" + + "class Cl {\n" + + " public static class Inner {}\n" + + "}\n" + + "public class X extends Cl implements I {}\n", + "a/Y.java", + "package p;\n" + + "import static a.b.X.Inner;\n" + + "public class Y {;\n" + + " Inner t;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in a\\Y.java (at line 4)\n" + + " Inner t;\n" + + " ^^^^^\n" + + "The type Inner is ambiguous\n" + + "----------\n"); +} +public void testBug521815b() { + if (this.complianceLevel <= ClassFileConstants.JDK1_8) { + return; + } + runNegativeTest( + new String[] { + "a/b/X.java", + "package a.b;\n" + + "interface I{\n" + + " public static class Inner { }\n" + + "}\n" + + "class Cl {\n" + + " public static class Inner {}\n" + + "}\n" + + "public class X extends Cl implements I {}\n", + "a/Y.java", + "package p;\n" + + "import static a.b.X.Inner;\n" + + "public class Y {;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in a\\Y.java (at line 2)\n" + + " import static a.b.X.Inner;\n" + + " ^^^^^^^^^^^\n" + + "The import a.b.X.Inner is never used\n" + + "----------\n"); +} +public void testBug533644() { + runConformTest( + new String[] { + "q/JobDetail.java", + "package q;\n" + + "import java.io.Serializable;\n" + + "public interface JobDetail extends Serializable, Cloneable { }\n", + "q/Scheduler.java", + "package q;\n" + + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "public interface Scheduler {\n" + + " void scheduleJobs(Map> triggersAndJobs, boolean replace) throws SchedulerException;\n" + + "}\n", + "q/SchedulerException.java", + "package q;\n" + + "public class SchedulerException extends Exception {\n" + + " private static final long serialVersionUID = 174841398690789156L;\n" + + "}\n", + "q/Trigger.java", + "package q;\n" + + "import java.io.Serializable;\n" + + "public interface Trigger extends Serializable, Cloneable, Comparable {\n" + + " public static final long serialVersionUID = -3904243490805975570L;\n" + + "}\n" + }); + Runner runner = new Runner(); + runner.shouldFlushOutputDirectory = false; + runner.testFiles = new String[] { + "ForwardingScheduler.java", + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "\n" + + "import q.JobDetail;\n" + + "import q.Scheduler;\n" + + "import q.SchedulerException;\n" + + "import q.Trigger;\n" + + "\n" + + "public class ForwardingScheduler implements Scheduler {\n" + + " @Override\n" + + " public void scheduleJobs(Map> triggersAndJobs, boolean replace)\n" + + " throws SchedulerException {\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); +} +//As All non-private methods of an anonymous class instantiated with '<>' must be treated as being annotated with @override, +//"Remove redundant type arguments" error should be reported if all the non-private methods defined in the anonymous class +//are also present in the parent class. +public void testBug551913_001() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int foo() {\n" + + " java.util.HashSet a = new java.util.HashSet<>();\n" + + " java.util.HashSet b = new java.util.HashSet(a) {\n" + + " private static final long serialVersionUID = 1L;\n" + + " public int x() {return 10;}\n" + + " };\n" + + " return 10;\n" + + " }\n\n" + + " public static void main(String[] args) {\n" + + " X abc= new X();\n" + + " System.out.println(abc.foo());" + + " }" + + "}", + },"10", options); +} +// As All non-private methods of an anonymous class instantiated with '<>' must be treated as being annotated with @override, +// "Remove redundant type arguments" error should be reported if all the non-private methods defined in the anonymous class +// are also present in the parent class. +public void testBug551913_002() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " java.util.HashSet a = new java.util.HashSet<>();\n" + + " java.util.HashSet b = new java.util.HashSet(a) {\n" + + " private static final long serialVersionUID = 1L;\n" + + " public String toString() {return null;}\n" + + " };\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " java.util.HashSet b = new java.util.HashSet(a) {\n" + + " ^^^^^^^\n" + + "Redundant specification of type arguments \n" + + "----------\n", + null, true, options); +} +public static Class testClass() { + return GenericsRegressionTest_9.class; +} + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GrammarCoverageTests308.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GrammarCoverageTests308.java new file mode 100644 index 0000000000..585f42d122 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GrammarCoverageTests308.java @@ -0,0 +1,1629 @@ +/******************************************************************************* + * Copyright (c) 2011, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * bug 392099 - [1.8][compiler][null] Apply null annotation on types for null analysis + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class GrammarCoverageTests308 extends AbstractRegressionTest { + + static { +// TESTS_NUMBERS = new int [] { 35 }; +// TESTS_NAMES = new String [] { "testnew" }; + } + public static Class testClass() { + return GrammarCoverageTests308.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + public GrammarCoverageTests308(String testName){ + super(testName); + } + // Lone test to verify that multiple annotations of all three kinds are accepted. All other tests will use only marker annotations + public void test000() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends @Marker @SingleMember(0) @Normal(Value = 0) Object {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends @Marker @SingleMember(0) @Normal(Value = 0) Object {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends @Marker @SingleMember(0) @Normal(Value = 0) Object {\n" + + " ^^^^^^^^^^^^\n" + + "SingleMember cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X extends @Marker @SingleMember(0) @Normal(Value = 0) Object {\n" + + " ^^^^^^\n" + + "Normal cannot be resolved to a type\n" + + "----------\n"); + } + // FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';' + public void test001() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @Marker int x;\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n"+ + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Marker int x;\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // TYPE: MethodHeaderName ::= Modifiersopt TypeParameters Type 'Identifier' '(' + public void test002() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @Marker @Marker int x() { return 10; };\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n"+ + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Marker @Marker int x() { return 10; };\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " @Marker @Marker int x() { return 10; };\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // TYPE: MethodHeaderName ::= Modifiersopt Type 'Identifier' '(' + public void test003() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @Marker int x() { return 10; };\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n"+ + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Marker int x() { return 10; };\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // FormalParameter ::= Modifiersopt Type VariableDeclaratorIdOrThis + public void test004() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int x(@Marker int p) { return 10; };\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n"+ + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int x(@Marker int p) { return 10; };\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // FormalParameter ::= Modifiersopt Type PushZeroTypeAnnotations '...' VariableDeclaratorIdOrThis + public void test005() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int x(@Marker int ... p) { return 10; };\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n"+ + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int x(@Marker int ... p) { return 10; };\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // FormalParameter ::= Modifiersopt Type @308... TypeAnnotations '...' VariableDeclaratorIdOrThis + public void test006() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int x(@Marker int [] @Marker ... p) { return 10; };\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int x(@Marker int [] @Marker ... p) { return 10; };\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " int x(@Marker int [] @Marker ... p) { return 10; };\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // UnionType ::= Type + // UnionType ::= UnionType '|' Type + public void test007() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int x() {\n" + + " try {\n" + + " } catch (@Marker NullPointerException | @Marker ArrayIndexOutOfBoundsException e) {\n" + + " }\n" + + " return 10;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " } catch (@Marker NullPointerException | @Marker ArrayIndexOutOfBoundsException e) {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " } catch (@Marker NullPointerException | @Marker ArrayIndexOutOfBoundsException e) {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // LocalVariableDeclaration ::= Type PushModifiers VariableDeclarators + // LocalVariableDeclaration ::= Modifiers Type PushRealModifiers VariableDeclarators + public void test008() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int x() {\n" + + " @Marker int p;\n" + + " final @Marker int q;\n" + + " @Marker final int r;\n" + + " return 10;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n"+ + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @Marker int p;\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " final @Marker int q;\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " @Marker final int r;\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // Resource ::= Type PushModifiers VariableDeclaratorId EnterVariable '=' ForceNoDiet VariableInitializer RestoreDiet ExitVariableWithInitialization + // Resource ::= Modifiers Type PushRealModifiers VariableDeclaratorId EnterVariable '=' ForceNoDiet VariableInitializer RestoreDiet ExitVariableWithInitialization + public void test009() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int x() {\n" + + " try (@Marker Integer p = null; final @Marker Integer q = null; @Marker final Integer r = null) {\n" + + " }\n" + + " return 10;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n"+ + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (@Marker Integer p = null; final @Marker Integer q = null; @Marker final Integer r = null) {\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " try (@Marker Integer p = null; final @Marker Integer q = null; @Marker final Integer r = null) {\n" + + " ^^^^^^^\n" + + "The resource type Integer does not implement java.lang.AutoCloseable\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " try (@Marker Integer p = null; final @Marker Integer q = null; @Marker final Integer r = null) {\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " try (@Marker Integer p = null; final @Marker Integer q = null; @Marker final Integer r = null) {\n" + + " ^^^^^^^\n" + + "The resource type Integer does not implement java.lang.AutoCloseable\n" + + "----------\n" + + "5. ERROR in X.java (at line 3)\n" + + " try (@Marker Integer p = null; final @Marker Integer q = null; @Marker final Integer r = null) {\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "6. ERROR in X.java (at line 3)\n" + + " try (@Marker Integer p = null; final @Marker Integer q = null; @Marker final Integer r = null) {\n" + + " ^^^^^^^\n" + + "The resource type Integer does not implement java.lang.AutoCloseable\n" + + "----------\n" + + "7. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // EnhancedForStatementHeaderInit ::= 'for' '(' Type PushModifiers Identifier Dimsopt + // EnhancedForStatementHeaderInit ::= 'for' '(' Modifiers Type PushRealModifiers Identifier Dimsopt + public void test010() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int x() {\n" + + " for (@Marker int i: new int[3]) {}\n" + + " for (final @Marker int i: new int[3]) {}\n" + + " for (@Marker final int i: new int[3]) {}\n" + + " return 10;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n"+ + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (@Marker int i: new int[3]) {}\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " for (final @Marker int i: new int[3]) {}\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " for (@Marker final int i: new int[3]) {}\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // AnnotationMethodHeaderName ::= Modifiersopt TypeParameters Type 'Identifier' '(' + // AnnotationMethodHeaderName ::= Modifiersopt Type 'Identifier' '(' + public void test011() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public @interface X { \n" + + " public @Marker String value(); \n" + + " @Marker String value2(); \n" + + " @Marker public String value3(); \n" + + " public @Marker @Marker String value4(); \n" + + " @Marker @Marker String value5(); \n" + + " @Marker public @Marker String value6(); \n" + + "}\n" + + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n"+ + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public @Marker String value(); \n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " @Marker String value2(); \n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " @Marker public String value3(); \n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " public @Marker @Marker String value4(); \n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " public @Marker @Marker String value4(); \n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "6. ERROR in X.java (at line 5)\n" + + " public @Marker @Marker String value4(); \n" + + " ^^^^^^^^\n" + + "Annotation attributes cannot be generic\n" + + "----------\n" + + "7. ERROR in X.java (at line 6)\n" + + " @Marker @Marker String value5(); \n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "8. ERROR in X.java (at line 6)\n" + + " @Marker @Marker String value5(); \n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "9. ERROR in X.java (at line 6)\n" + + " @Marker @Marker String value5(); \n" + + " ^^^^^^^^\n" + + "Annotation attributes cannot be generic\n" + + "----------\n" + + "10. ERROR in X.java (at line 7)\n" + + " @Marker public @Marker String value6(); \n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "11. ERROR in X.java (at line 7)\n" + + " @Marker public @Marker String value6(); \n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "12. ERROR in X.java (at line 7)\n" + + " @Marker public @Marker String value6(); \n" + + " ^^^^^^^^\n" + + "Annotation attributes cannot be generic\n" + + "----------\n"); + } + // PrimaryNoNewArray ::= PrimitiveType Dims '.' 'class' + // PrimaryNoNewArray ::= PrimitiveType '.' 'class' + public void test012() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public void value() {\n" + + " Object o = @Marker int.class;\n" + + " Object o2 = @Marker int @Marker[] [] @Marker[].class;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = @Marker int.class;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Object o2 = @Marker int @Marker[] [] @Marker[].class;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Object o2 = @Marker int @Marker[] [] @Marker[].class;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Object o2 = @Marker int @Marker[] [] @Marker[].class;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // ReferenceExpression ::= PrimitiveType Dims '::' NonWildTypeArgumentsopt IdentifierOrNew + public void test013() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Object copy(int [] ia);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = @Marker int @Marker []::clone;\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = @Marker int @Marker []::clone;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " I i = @Marker int @Marker []::clone;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " I i = @Marker int @Marker []::clone;\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method clone() of type Object; it should not be parameterized with arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ArrayCreationWithoutArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs + // ArrayCreationWithArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs ArrayInitializer + public void test014() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " int i [] = new @Marker int @Marker [4];\n" + + " int j [] = new @Marker int @Marker [] { 10 };\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int i [] = new @Marker int @Marker [4];\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " int i [] = new @Marker int @Marker [4];\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " int j [] = new @Marker int @Marker [] { 10 };\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " int j [] = new @Marker int @Marker [] { 10 };\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // CastExpression ::= PushLPAREN PrimitiveType Dimsopt PushRPAREN InsideCastExpression UnaryExpression + public void test015() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " int i = (@Marker int) 0;\n" + + " int j [] = (@Marker int @Marker []) null;\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int i = (@Marker int) 0;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " int j [] = (@Marker int @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " int j [] = (@Marker int @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // InstanceofExpression ::= InstanceofExpression 'instanceof' ReferenceType + public void test016() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " if (args instanceof @Readonly String) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (args instanceof @Readonly String) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types String[] and String\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " if (args instanceof @Readonly String) {\n" + + " ^^^^^^^^\n" + + "Readonly cannot be resolved to a type\n" + + "----------\n"); + } + // TypeArgument ::= ReferenceType + public void test017() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y<@Marker Integer, String> {}\n" + + "class Y {\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y<@Marker Integer, String> {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ReferenceType1 ::= ReferenceType '>' + public void test018() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y<@Marker Integer> {}\n" + + "class Y {\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y<@Marker Integer> {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + // ReferenceType2 ::= ReferenceType '>>' + public void test019() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X> {}\n" + + "class Y {\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X> {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ReferenceType3 ::= ReferenceType '>>>' + public void test020() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X>>> {}\n" + + "class Y {\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X>>> {}\n" + + " ^\n" + + "Bound mismatch: The type X> is not a valid substitute for the bounded parameter >>> of the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X>>> {}\n" + + " ^\n" + + "Bound mismatch: The type X is not a valid substitute for the bounded parameter >>> of the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X>>> {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Bound mismatch: The type String is not a valid substitute for the bounded parameter >>> of the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 1)\n" + + " public class X>>> {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // WildcardBounds ::= 'extends' ReferenceType + // WildcardBounds ::= 'super' ReferenceType + public void test021() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Map<@Marker ? super @Marker Object, @Marker ? extends @Marker String> m){}\n" + + " void goo(Map<@Marker ? extends @Marker Object, @Marker ? super @Marker String> m){}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Map<@Marker ? super @Marker Object, @Marker ? extends @Marker String> m){}\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " void foo(Map<@Marker ? super @Marker Object, @Marker ? extends @Marker String> m){}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " void foo(Map<@Marker ? super @Marker Object, @Marker ? extends @Marker String> m){}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 2)\n" + + " void foo(Map<@Marker ? super @Marker Object, @Marker ? extends @Marker String> m){}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 2)\n" + + " void foo(Map<@Marker ? super @Marker Object, @Marker ? extends @Marker String> m){}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 3)\n" + + " void goo(Map<@Marker ? extends @Marker Object, @Marker ? super @Marker String> m){}\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 3)\n" + + " void goo(Map<@Marker ? extends @Marker Object, @Marker ? super @Marker String> m){}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 3)\n" + + " void goo(Map<@Marker ? extends @Marker Object, @Marker ? super @Marker String> m){}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "9. ERROR in X.java (at line 3)\n" + + " void goo(Map<@Marker ? extends @Marker Object, @Marker ? super @Marker String> m){}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "10. ERROR in X.java (at line 3)\n" + + " void goo(Map<@Marker ? extends @Marker Object, @Marker ? super @Marker String> m){}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // TypeParameter ::= TypeParameterHeader 'extends' ReferenceType + public void test022() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" + + "}\n" + + "class Y {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 1)\n" + + " public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "5. WARNING in X.java (at line 1)\n" + + " public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The type parameter Q should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "6. ERROR in X.java (at line 1)\n" + + " public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // TypeParameter ::= TypeParameterHeader 'extends' ReferenceType AdditionalBoundList + // AdditionalBound ::= '&' ReferenceType + // TypeParameter1 ::= TypeParameterHeader 'extends' ReferenceType AdditionalBoundList1 + public void test023() throws Exception { + this.runNegativeTest( + new String[] { + "I.java", + "public interface I>> {\n" + + "}\n" + + "interface J>> {\n" + + "}\n" + + "class CI & @Marker J<@Marker T>,\n" + + " T extends CI & @Marker I>\n" + + " implements I {\n" + + "}\n" + + "class CJ & @Marker I<@Marker U>,\n" + + " U extends CJ & J>\n" + + " implements J {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 5)\n" + + " class CI & @Marker J<@Marker T>,\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in I.java (at line 5)\n" + + " class CI & @Marker J<@Marker T>,\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in I.java (at line 6)\n" + + " T extends CI & @Marker I>\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in I.java (at line 9)\n" + + " class CJ & @Marker I<@Marker U>,\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in I.java (at line 9)\n" + + " class CJ & @Marker I<@Marker U>,\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // InstanceofExpression_NotName ::= Name 'instanceof' ReferenceType + public void test024() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " E e;\n" + + " E getOtherElement(Object other) {\n" + + " if (!(other instanceof @Marker X.Y)) {};\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (!(other instanceof @Marker X.Y)) {};\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // InstanceofExpression_NotName ::= InstanceofExpression_NotName 'instanceof' ReferenceType + public void test025() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X() {\n" + + " if (!(this instanceof @Marker X)) {}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (!(this instanceof @Marker X)) {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // ReferenceExpressionTypeArgumentsAndTrunk ::= OnlyTypeArguments '.' ClassOrInterfaceType Dimsopt + public void test026() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(Y.Z z, int x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y.@Marker Z::foo;\n" + + " i.foo(new Y().new Z(), 10); \n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " class Z {\n" + + " void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = Y.@Marker Z::foo;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ArrayCreationWithoutArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs + // ArrayCreationWithArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs ArrayInitializer + public void test027() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " X [] x = new @Marker X @Marker [5];\n" + + " X [] x2 = new @Marker X @Marker [] { null };\n" + + " Zork z;\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X [] x = new @Marker X @Marker [5];\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " X [] x = new @Marker X @Marker [5];\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " X [] x2 = new @Marker X @Marker [] { null };\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " X [] x2 = new @Marker X @Marker [] { null };\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // CastExpression ::= PushLPAREN Name OnlyTypeArgumentsForCastExpression '.' ClassOrInterfaceType Dimsopt PushRPAREN InsideCastExpressionWithQualifiedGenerics UnaryExpressionNotPlusMinus + public void test028() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " java.util.Map.Entry [] e = (java.util.Map.@Marker Entry []) null;\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " java.util.Map.Entry [] e = (java.util.Map.@Marker Entry []) null;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Map.Entry is a raw type. References to generic type Map.Entry should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " java.util.Map.Entry [] e = (java.util.Map.@Marker Entry []) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The member type Map.Entry cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type Map\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " java.util.Map.Entry [] e = (java.util.Map.@Marker Entry []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // ReferenceType1 ::= ClassOrInterface '<' TypeArgumentList2 + public void test029() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "public class X & Serializable> {\n" + + " void foo(List> p) {} \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " void foo(List> p) {} \n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // ReferenceType2 ::= ClassOrInterface '<' TypeArgumentList3 + public void test030() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class Base {\n" + + "}\n" + + "class Foo>> {\n" + + "}\n" + + "class Bar>> {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class Foo>> {\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type Foo is not a valid substitute for the bounded parameter >> of the type Bar\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " class Foo>> {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " class Bar>> {\n" + + " ^^^^^^^^^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter >> of the type Foo\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " class Bar>> {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // ClassHeaderExtends ::= 'extends' ClassType + public void test031() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends @Marker Object {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends @Marker Object {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // ClassInstanceCreationExpression ::= 'new' OnlyTypeArguments ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' UnqualifiedClassBodyopt + // ClassInstanceCreationExpression ::= 'new' ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' UnqualifiedClassBodyopt + public void test032() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X x = new @Marker X();\n" + + " X y = new @Marker X();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X x = new @Marker X();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " X y = new @Marker X();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X() of type X; it should not be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " X y = new @Marker X();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // ClassInstanceCreationExpression ::= Primary '.' 'new' OnlyTypeArguments ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' QualifiedClassBodyopt + // ClassInstanceCreationExpression ::= Primary '.' 'new' ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' QualifiedClassBodyopt + public void test033() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " }\n" + + " Y y1 = new @Marker X().new @Marker Y();\n" + + " Y y2 = new @Marker X().new @Marker Y();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Y y1 = new @Marker X().new @Marker Y();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Y y1 = new @Marker X().new @Marker Y();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Y y2 = new @Marker X().new @Marker Y();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " Y y2 = new @Marker X().new @Marker Y();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X.Y() of type X.Y; it should not be parameterized with arguments \n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " Y y2 = new @Marker X().new @Marker Y();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // ClassInstanceCreationExpression ::= ClassInstanceCreationExpressionName 'new' ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' QualifiedClassBodyopt + // ClassInstanceCreationExpression ::= ClassInstanceCreationExpressionName 'new' OnlyTypeArguments ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' QualifiedClassBodyopt + public void test034() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X x;\n" + + " class Y {\n" + + " }\n" + + " Y y1 = @Marker x.new @Marker Y();\n" + + " Y y2 = @Marker x.new @Marker Y();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Y y1 = @Marker x.new @Marker Y();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Y y1 = @Marker x.new @Marker Y();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " Y y2 = @Marker x.new @Marker Y();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " Y y2 = @Marker x.new @Marker Y();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X.Y() of type X.Y; it should not be parameterized with arguments \n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " Y y2 = @Marker x.new @Marker Y();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // MethodHeaderThrowsClause ::= 'throws' ClassTypeList + // ClassTypeList -> ClassTypeElt + // ClassTypeList ::= ClassTypeList ',' ClassTypeElt + // ClassTypeElt ::= ClassType + public void test035() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() throws @Marker NullPointerException, @Marker ArrayIndexOutOfBoundsException {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo() throws @Marker NullPointerException, @Marker ArrayIndexOutOfBoundsException {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " void foo() throws @Marker NullPointerException, @Marker ArrayIndexOutOfBoundsException {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // ClassHeaderImplements ::= 'implements' InterfaceTypeList + // InterfaceHeaderExtends ::= 'extends' InterfaceTypeList + // InterfaceTypeList -> InterfaceType + // InterfaceTypeList ::= InterfaceTypeList ',' InterfaceType + // InterfaceType ::= ClassOrInterfaceType + public void test036() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "interface J {}\n" + + "interface K extends @Marker I, @Marker J {}\n" + + "interface L {}\n" + + "public class X implements @Marker K, @Marker L {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " interface K extends @Marker I, @Marker J {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " interface K extends @Marker I, @Marker J {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public class X implements @Marker K, @Marker L {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " public class X implements @Marker K, @Marker L {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // ReferenceExpression ::= Name Dimsopt '::' NonWildTypeArgumentsopt IdentifierOrNew + public void test037() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = @Marker Y. @Marker Z @Marker [] [] @Marker [] ::foo;\n" + + " i.foo(10); \n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " public static void foo(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = @Marker Y. @Marker Z @Marker [] [] @Marker [] ::foo;\n" + + " ^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " I i = @Marker Y. @Marker Z @Marker [] [] @Marker [] ::foo;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type Y.Z[][][] does not define foo(int) that is applicable here\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " I i = @Marker Y. @Marker Z @Marker [] [] @Marker [] ::foo;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " I i = @Marker Y. @Marker Z @Marker [] [] @Marker [] ::foo;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " I i = @Marker Y. @Marker Z @Marker [] [] @Marker [] ::foo;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 6)\n" + + " I i = @Marker Y. @Marker Z @Marker [] [] @Marker [] ::foo;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // ReferenceExpression ::= Name BeginTypeArguments ReferenceExpressionTypeArgumentsAndTrunk '::' NonWildTypeArgumentsopt IdentifierOrNew + public void test038() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Y foo(int x);\n" + + "}\n" + + "public class X {\n" + + " class Z extends Y {\n" + + " public Z(int x) {\n" + + " super(x);\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " i = @Marker W<@Marker Integer>::<@Marker String> new;\n" + + " }\n" + + "}\n" + + "class W extends Y {\n" + + " public W(T x) {\n" + + " super(0);\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public Y(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + + + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " i = @Marker W<@Marker Integer>::<@Marker String> new;\n" + + " ^\n" + + "i cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " i = @Marker W<@Marker Integer>::<@Marker String> new;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " i = @Marker W<@Marker Integer>::<@Marker String> new;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " i = @Marker W<@Marker Integer>::<@Marker String> new;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 12)\n" + + " i = @Marker W<@Marker Integer>::<@Marker String> new;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // CastExpression ::= PushLPAREN Name PushRPAREN InsideCastExpressionLL1 UnaryExpressionNotPlusMinus + // CastExpression ::= PushLPAREN Name Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus + // CastExpression ::= PushLPAREN Name OnlyTypeArgumentsForCastExpression Dimsopt PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus + // CastExpression ::= PushLPAREN Name OnlyTypeArgumentsForCastExpression '.' ClassOrInterfaceType Dimsopt PushRPAREN InsideCastExpressionWithQualifiedGenerics UnaryExpressionNotPlusMinus + public void test039() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o = (@Marker X) null;\n" + + " Object p = (@Marker X @Marker []) null;\n" + + " Object q = (@Marker java. @Marker util. @Marker List<@Marker String> []) null;\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Object o = (@Marker X) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Object p = (@Marker X @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Object p = (@Marker X @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Object q = (@Marker java. @Marker util. @Marker List<@Marker String> []) null;\n" + + " ^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " Object q = (@Marker java. @Marker util. @Marker List<@Marker String> []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " Object q = (@Marker java. @Marker util. @Marker List<@Marker String> []) null;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "7. ERROR in X.java (at line 4)\n" + + " Object q = (@Marker java. @Marker util. @Marker List<@Marker String> []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 4)\n" + + " Object q = (@Marker java. @Marker util. @Marker List<@Marker String> []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "9. ERROR in X.java (at line 5)\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + " ^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "10. ERROR in X.java (at line 5)\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The member type Map.Entry cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type Map\n" + + "----------\n" + + "11. ERROR in X.java (at line 5)\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "12. ERROR in X.java (at line 5)\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "13. ERROR in X.java (at line 5)\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + " ^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "14. ERROR in X.java (at line 5)\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "15. ERROR in X.java (at line 5)\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "16. ERROR in X.java (at line 5)\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "17. ERROR in X.java (at line 5)\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "18. ERROR in X.java (at line 5)\n" + + " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InMemoryNameEnvironment.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InMemoryNameEnvironment.java new file mode 100644 index 0000000000..8f7020bf9e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InMemoryNameEnvironment.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2000, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.env.*; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; + +public class InMemoryNameEnvironment implements INameEnvironment { + INameEnvironment[] classLibs; + HashtableOfObject compilationUnits = new HashtableOfObject(); +public InMemoryNameEnvironment(String[] compilationUnits, INameEnvironment[] classLibs) { + this.classLibs = classLibs; + for (int i = 0, length = compilationUnits.length - 1; i < length; i += 2) { + String fileName = compilationUnits[i]; + char[] contents = compilationUnits[i + 1].toCharArray(); + String dirName = ""; + int lastSlash = -1; + if ((lastSlash = fileName.lastIndexOf('/')) != -1) { + dirName = fileName.substring(0, lastSlash); + } + char[] packageName = dirName.replace('/', '.').toCharArray(); + char[] cuName = fileName.substring(lastSlash == -1 ? 0 : lastSlash + 1, fileName.length() - 5).toCharArray(); // remove ".java" + HashtableOfObject cus = (HashtableOfObject)this.compilationUnits.get(packageName); + if (cus == null) { + cus = new HashtableOfObject(); + this.compilationUnits.put(packageName, cus); + } + CompilationUnit unit = new CompilationUnit(contents, fileName, null); + cus.put(cuName, unit); + } +} +public NameEnvironmentAnswer findType(char[][] compoundTypeName) { + return findType( + compoundTypeName[compoundTypeName.length - 1], + CharOperation.subarray(compoundTypeName, 0, compoundTypeName.length - 1)); +} +public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) { + HashtableOfObject cus = (HashtableOfObject)this.compilationUnits.get(CharOperation.concatWith(packageName, '.')); + if (cus == null) { + return findTypeFromClassLibs(typeName, packageName); + } + CompilationUnit unit = (CompilationUnit)cus.get(typeName); + if (unit == null) { + return findTypeFromClassLibs(typeName, packageName); + } + return new NameEnvironmentAnswer(unit, null /*no access restriction*/); +} +private NameEnvironmentAnswer findTypeFromClassLibs(char[] typeName, char[][] packageName) { + for (int i = 0; i < this.classLibs.length; i++) { + NameEnvironmentAnswer answer = this.classLibs[i].findType(typeName, packageName); + if (answer != null) { + return answer; + } + } + return null; +} +public boolean isPackage(char[][] parentPackageName, char[] packageName) { + char[] pkg = CharOperation.concatWith(parentPackageName, packageName, '.'); + return + this.compilationUnits.get(pkg) != null || + isPackageFromClassLibs(parentPackageName, packageName); +} +public boolean isPackageFromClassLibs(char[][] parentPackageName, char[] packageName) { + for (int i = 0; i < this.classLibs.length; i++) { + if (this.classLibs[i].isPackage(parentPackageName, packageName)) { + return true; + } + } + return false; +} +public void cleanup() { + for (int i = 0, max = this.classLibs.length; i < max; i++) { + this.classLibs[i].cleanup(); + } + this.compilationUnits = new HashtableOfObject(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InMemoryNameEnvironment9.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InMemoryNameEnvironment9.java new file mode 100644 index 0000000000..e5eb6f3ef8 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InMemoryNameEnvironment9.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2017 GK Software AG, and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; + +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.IModuleAwareNameEnvironment; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; + +public class InMemoryNameEnvironment9 extends InMemoryNameEnvironment implements IModuleAwareNameEnvironment { + + Map moduleMap = new HashMap<>(); + + public InMemoryNameEnvironment9(String[] compilationUnits, Map moduleMap, INameEnvironment[] classLibs) { + super(compilationUnits, classLibs); + this.moduleMap = moduleMap; + } + + protected T fromFirstClassLib(Function function) { + for (int i = 0; i < this.classLibs.length; i++) { + INameEnvironment env = this.classLibs[i]; + if (env instanceof IModuleAwareNameEnvironment) { + T answer = function.apply(((IModuleAwareNameEnvironment) env)); + if (answer != null) + return answer; + } + } + return null; + } + + protected T[] collect(Function function, Function arraySupplier) { + Set mods = new HashSet<>(); + for (int i = 0; i < this.classLibs.length; i++) { + INameEnvironment env = this.classLibs[i]; + if (env instanceof IModuleAwareNameEnvironment) { + T[] someMods = function.apply((IModuleAwareNameEnvironment) env); + if (someMods != null) { + mods.addAll(Arrays.asList(someMods)); + } + } + } + return mods.toArray(arraySupplier.apply(mods.size())); + } + + @Override + public NameEnvironmentAnswer findType(char[][] compoundName, char[] moduleName) { + return fromFirstClassLib(env -> env.findType(compoundName, moduleName)); + } + + @Override + public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName, char[] moduleName) { + return fromFirstClassLib(env -> env.findType(typeName, packageName, moduleName)); + } + + @Override + public char[][] getModulesDeclaringPackage(char[][] packageName, char[] moduleName) { + return collect(env -> env.getModulesDeclaringPackage(packageName, moduleName), char[][]::new); + } + + @Override + public char[][] listPackages(char[] moduleName) { + return collect(env -> env.listPackages(moduleName), char[][]::new); + } + + @Override + public boolean hasCompilationUnit(char[][] qualifiedPackageName, char[] moduleName, boolean checkCUs) { + return Boolean.TRUE.equals(fromFirstClassLib(env -> env.hasCompilationUnit(qualifiedPackageName, moduleName, checkCUs) ? Boolean.TRUE : null)); + } + + @Override + public IModule getModule(char[] moduleName) { + IModule mod = this.moduleMap.get(String.valueOf(moduleName)); + if (mod != null) + return mod; + return fromFirstClassLib(env -> env.getModule(moduleName)); + } + + @Override + public char[][] getAllAutomaticModules() { + return collect(env -> env.getAllAutomaticModules(), char[][]::new); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InitializationTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InitializationTests.java new file mode 100644 index 0000000000..66feafc4cc --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InitializationTests.java @@ -0,0 +1,498 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - contributions for + * bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself + * bug 383690 - [compiler] location of error re uninitialized final field should be aligned + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class InitializationTests extends AbstractRegressionTest { + +public InitializationTests(String name) { + super(name); +} + +public static Test suite() { + Test suite = buildAllCompliancesTestSuite(testClass()); + return suite; +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020a() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public void foo() throws Exception{\n" + + " String temp;\n" + + " Object temp2= new String(\"test\");\n" + + " if(temp2 instanceof String) {\n" + + " temp = (String) temp2;\n" + + " } else {\n" + + " if (true) {\n" + + " throw new Exception(\"not a string\");\n" + + " }\n" + + " }\n" + + " temp.trim();\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020b() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " {\n" + + " if (true)\n" + + " throw new NullPointerException();\n" + + " }\n" + + " public X(){}\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020c() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public int a;" + + " public X (int a) {\n" + + " this.a = a;\n" + + " }\n" + + " public int returnA () {\n" + + " return a;\n" + + " }\n" + + " public void foo() {\n" + + " final X abc;" + + " if (true || (abc = new X(2)).returnA() == 2) {\n" + + " System.out.println(\"Hello\");\n" + + " } else { \n" + + " abc = new X(1);\n" + + " }\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " abc = new X(1);\n" + + " ^^^\n" + + "The final local variable abc may already have been assigned\n" + + "----------\n", + null, false, options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020d() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private int a;" + + " public X (int a) {\n" + + " this.a = a;\n" + + " }\n" + + " public int returnA () {\n" + + " return a;\n" + + " }\n" + + " public static boolean comparison (X x, int val) {\n" + + " return (x.returnA() == val);\n" + + " }\n" + + " public void foo() {\n" + + " final X abc;\n" + + " boolean comp = X.comparison((abc = new X(2)), (abc = new X(1)).returnA());\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " boolean comp = X.comparison((abc = new X(2)), (abc = new X(1)).returnA());\n" + + " ^^^\n" + + "The final local variable abc may already have been assigned\n" + + "----------\n", + null, false, options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020e() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private int a;" + + " public X (int a) {\n" + + " this.a = a;\n" + + " }\n" + + " public int returnA () {\n" + + " return a;\n" + + " }\n" + + " public void foo() {\n" + + " final X abc;\n" + + " boolean comp = ((abc = new X(2)).returnA() == 1 || (abc = new X(1)).returnA() == 1);\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " boolean comp = ((abc = new X(2)).returnA() == 1 || (abc = new X(1)).returnA() == 1);\n" + + " ^^^\n" + + "The final local variable abc may already have been assigned\n" + + "----------\n", + null, false, options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020f() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private int a;" + + " public X (int a) {\n" + + " this.a = a;\n" + + " }\n" + + " public int returnA () {\n" + + " return a;\n" + + " }\n" + + " public void foo() {\n" + + " final X abc;\n" + + " int val;\n" + + " if (true || (abc = new X(1)).returnA() == 1)\n" + + " val = (abc = new X(2)).returnA();\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " val = (abc = new X(2)).returnA();\n" + + " ^^^\n" + + "The final local variable abc may already have been assigned\n" + + "----------\n", + null, false, options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020g() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private int a;" + + " public X (int a) {\n" + + " this.a = a;\n" + + " }\n" + + " public int returnA () {\n" + + " return a;\n" + + " }\n" + + " public void foo() {\n" + + " final X abc;\n" + + " int val;\n" + + " if (true) {\n" + + " val = 0;\n" + + " } else {\n" + + " val = (abc = new X(1)).returnA();\n" + + " }\n" + + " abc = new X(2);\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " abc = new X(2);\n" + + " ^^^\n" + + "The final local variable abc may already have been assigned\n" + + "----------\n", + null, false, options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020h() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " final static X[] abc;\n" + + " static {\n" + + " for (Object[] j = new Object[1]; !(((abc = new X[10]).length) == 10); ){\n" + + " break;\n" + + " }\n" + + " }\n" + + " //Zork z;\n" + + "}\n" + + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020i() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private int a;" + + " class Inner {\n" + + " public int aInner;\n" + + " public Inner(int a){\n" + + " this.aInner = a;\n" + + " }\n" + + " }\n" + + " public X (int a) {\n" + + " this.a = a;\n" + + " }\n" + + " public int returnA () {\n" + + " return a;\n" + + " }\n" + + " public void foo() {\n" + + " int val;" + + " final int int1;\n" + + " final int int2;\n" + + " val = new X(int1 = 1).new Inner(int2 = int1).aInner;\n" + + " System.out.println(int1 + int2);\n" + + " }\n" + + "}\n" + + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020j() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private int a;" + + " public X (int a) {\n" + + " this.a = a;\n" + + " }\n" + + " public int returnA () {\n" + + " return a;\n" + + " }\n" + + " public void foo() {\n" + + " final int abc;\n" + + " abc = new X(abc = 2).returnA();\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " abc = new X(abc = 2).returnA();\n" + + " ^^^\n" + + "The final local variable abc may already have been assigned\n" + + "----------\n", + null, false, options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318020 +public void test318020k() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private int a;\n" + + " final int x;\n" + + " {\n" + + " x = new X(x = 2).returnA();" + + " }\n" + + " public X (int a) {\n" + + " this.a = a;\n" + + " }\n" + + " public int returnA () {\n" + + " return a;\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " x = new X(x = 2).returnA(); }\n" + + " ^\n" + + "The final field x may already have been assigned\n" + + "----------\n", + null, false, options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=325567 +public void test325567() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " bar(3);\n" + + " }\n" + + " public static void bar(int i) {\n" + + " final String before;\n" + + " try {\n" + + " before = foo();\n" + + " } catch (IOException e) {\n" + + " // ignore\n" + + " }\n" + + " B b = new B(new I() {\n" + + " public String bar() {\n" + + " return new String(before);\n" + + " }\n" + + " });\n" + + " try {\n" + + " b.i.bar();\n" + + " } catch(Exception e) {\n" + + " // ignore\n" + + " }\n" + + " }\n" + + "\n" + + " private static String foo() throws IOException {\n" + + " return null;\n" + + " }\n" + + " \n" + + " static class B {\n" + + " I i;\n" + + " B(I i) {\n" + + " this.i = i;\n" + + " }\n" + + " }\n" + + " static interface I {\n" + + " String bar();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " return new String(before);\n" + + " ^^^^^^\n" + + "The local variable before may not have been initialized\n" + + "----------\n", + null, false, options); +} + +// Bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself +// definite assignment along all true-yielding paths is sufficient +public void testBug324178b() { + this.runConformTest( + new String[] { + "Bug324178.java", + "public class Bug324178 {\n" + + " boolean foo(boolean b) {\n" + + " boolean v;\n" + + " if (b ? false : (true && (v = true)))\n" + + " return v;\n" + // OK to read v! + " return false;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new Bug324178().foo(false));\n" + + " }\n" + + "}\n" + }, + "true"); +} + +// Bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself +// definite assignment along all true-yielding paths is sufficient +public void testBug324178c() { + this.runConformTest( + new String[] { + "Bug324178.java", + "public class Bug324178 {\n" + + " boolean foo() {\n" + + " boolean r=false;" + + " boolean v;\n" + + " if ((true && (v = true)) ? true : true && (v = false)) r = v;\n" + + " return r;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new Bug324178().foo());\n" + + " }\n" + + "}\n" + }, + "true"); +} +// Bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself +// must detect that b2 may be uninitialized, no special semantics for Boolean +public void testBug324178d() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runNegativeTest( + new String[] { + "Bug324178.java", + "public class Bug324178 {\n" + + " boolean foo(boolean b1) {\n" + + " Boolean b2;\n" + + " if (b1 ? (b2 = Boolean.TRUE) : null)\n" + + " return b2;\n" + + " return false;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new Bug324178().foo(true));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug324178.java (at line 5)\n" + + " return b2;\n" + + " ^^\n" + + "The local variable b2 may not have been initialized\n" + + "----------\n"); +} +// Bug 383690 - [compiler] location of error re uninitialized final field should be aligned +public void testBug383690() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " final Object o; // report here!\n" + + " final static Object oStatic; // report here!\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " final Object o; // report here!\n" + + " ^\n" + + "The blank final field o may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " final static Object oStatic; // report here!\n" + + " ^^^^^^^\n" + + "The blank final field oStatic may not have been initialized\n" + + "----------\n"); +} +public static Class testClass() { + return InitializationTests.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java new file mode 100644 index 0000000000..fca62f6f3b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java @@ -0,0 +1,766 @@ +/******************************************************************************* + * Copyright (c) 2010, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +public class InnerClass15Test extends AbstractRegressionTest { +public InnerClass15Test(String name) { + super(name); +} +static { +// TESTS_NUMBERS = new int[] { 2 }; + //TESTS_NAMES = new String[] {"testBug520874"}; +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); +} +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return options; +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312989 +public void test001() { + this.runNegativeTest(new String[] { + "X.java", + "class X {\n" + + " void foo() {\n" + + " class X {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo() {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " class X {}\n" + + " ^\n" + + "The nested type X is hiding the type parameter X of the generic method foo() of type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " class X {}\n" + + " ^\n" + + "The nested type X cannot hide an enclosing type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312989 +public void test002() { + this.runNegativeTest(new String[] { + "X.java", + "class X {\n" + + " void foo() {\n" + + " class X {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " class X {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " class X {}\n" + + " ^\n" + + "The nested type X is hiding the type parameter X of type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " class X {}\n" + + " ^\n" + + "The nested type X cannot hide an enclosing type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312989 +// note javac reports an error for this test, but that is +// incorrect, compare and contrast javac behavior with +// test004. +public void test003() { + this.runNegativeTest(new String[] { + "Y.java", + "class Y {\n" + + "class X {}\n" + + " void foo() {\n" + + " class X {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in Y.java (at line 3)\n" + + " void foo() {\n" + + " ^\n" + + "The type parameter X is hiding the type Y.X\n" + + "----------\n" + + "2. WARNING in Y.java (at line 4)\n" + + " class X {}\n" + + " ^\n" + + "The nested type X is hiding the type parameter X of the generic method foo() of type Y\n" + + "----------\n" + + "3. WARNING in Y.java (at line 4)\n" + + " class X {}\n" + + " ^\n" + + "The type X is never used locally\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=312989 +public void test004() { + this.runNegativeTest(new String[] { + "Y.java", + "class Y {\n" + + "class X {}\n" + + " void foo() {\n" + + " class X {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in Y.java (at line 4)\n" + + " class X {}\n" + + " ^\n" + + "The type X is hiding the type Y.X\n" + + "----------\n" + + "2. WARNING in Y.java (at line 4)\n" + + " class X {}\n" + + " ^\n" + + "The type X is never used locally\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test005() { + this.runNegativeTest(new String[] { + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "public interface GreenBox {\n" + + " public static class Cat extends Object {}\n" + + "}\n", + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in p1\\GreenBox.java (at line 2)\n" + + " import static p1.BrownBox.*;\n" + + " ^^^^^^^^^^^\n" + + "The import p1.BrownBox is never used\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test006() { + this.runNegativeTest(new String[] { + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "public interface GreenBox {\n" + + " public static class Cat extends Object {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in p1\\GreenBox.java (at line 2)\n" + + " import static p1.BrownBox.*;\n" + + " ^^^^^^^^^^^\n" + + "The import p1.BrownBox is never used\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test007() { + this.runNegativeTest(new String[] { + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "public interface GreenBox {\n" + + " public static class Cat extends java.lang.Object {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in p1\\GreenBox.java (at line 2)\n" + + " import static p1.BrownBox.*;\n" + + " ^^^^^^^^^^^\n" + + "The import p1.BrownBox is never used\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test008() { + this.runNegativeTest(new String[] { + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "public interface GreenBox {\n" + + " public static class Cat extends BlackCat {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\BrownBox.java (at line 4)\n" + + " public static class BlackCat extends Cat {}\n" + + " ^^^^^^^^\n" + + "The hierarchy of the type BlackCat is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\GreenBox.java (at line 4)\n" + + " public static class Cat extends BlackCat {}\n" + + " ^^^^^^^^\n" + + "Cycle detected: a cycle exists in the type hierarchy between GreenBox.Cat and BrownBox.BlackCat\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test009() { + this.runNegativeTest(new String[] { + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "public interface GreenBox {\n" + + " public static class Cat extends BlackCat {}\n" + + "}\n", + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\GreenBox.java (at line 4)\n" + + " public static class Cat extends BlackCat {}\n" + + " ^^^\n" + + "The hierarchy of the type Cat is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\BrownBox.java (at line 4)\n" + + " public static class BlackCat extends Cat {}\n" + + " ^^^\n" + + "Cycle detected: a cycle exists in the type hierarchy between BrownBox.BlackCat and GreenBox.Cat\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test0010() { + this.runNegativeTest(new String[] { + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "interface SuperInterface {\n" + + " public static class Cat extends BlackCat {}\n" + + "}\n" + + "public interface GreenBox {\n" + + "}\n", + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\GreenBox.java (at line 4)\n" + + " public static class Cat extends BlackCat {}\n" + + " ^^^\n" + + "The hierarchy of the type Cat is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\BrownBox.java (at line 4)\n" + + " public static class BlackCat extends Cat {}\n" + + " ^^^\n" + + "Cat cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test0011() { + this.runNegativeTest(new String[] { + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "interface SuperInterface {\n" + + " public static class Cat extends BlackCat {}\n" + + "}\n" + + "public interface GreenBox extends SuperInterface {\n" + + "}\n", + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends Cat {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\GreenBox.java (at line 4)\n" + + " public static class Cat extends BlackCat {}\n" + + " ^^^\n" + + "The hierarchy of the type Cat is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\BrownBox.java (at line 4)\n" + + " public static class BlackCat extends Cat {}\n" + + " ^^^\n" + + "Cycle detected: a cycle exists in the type hierarchy between BrownBox.BlackCat and SuperInterface.Cat\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test0012() { + this.runNegativeTest(new String[] { + "p1/GreenBox.java", + "package p1;\n" + + "import static p1.BrownBox.*;\n" + + "interface SuperInterface {\n" + + " public static class Cat extends BlackCat {}\n" + + "}\n" + + "public interface GreenBox extends SuperInterface {\n" + + "}\n", + "p1/BrownBox.java", + "package p1;\n" + + "import static p1.GreenBox.*;\n" + + "public interface BrownBox {\n" + + " public static class BlackCat extends GreenBox.Cat {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\GreenBox.java (at line 4)\n" + + " public static class Cat extends BlackCat {}\n" + + " ^^^\n" + + "The hierarchy of the type Cat is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\BrownBox.java (at line 4)\n" + + " public static class BlackCat extends GreenBox.Cat {}\n" + + " ^^^^^^^^^^^^\n" + + "Cycle detected: a cycle exists in the type hierarchy between BrownBox.BlackCat and SuperInterface.Cat\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test0013() { + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "class X extends Y {}\n" + + "class Y extends X {}\n", + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 2)\n" + + " class X extends Y {}\n" + + " ^\n" + + "The hierarchy of the type X is inconsistent\n" + + "----------\n" + + "2. ERROR in cycle\\X.java (at line 3)\n" + + " class Y extends X {}\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between Y and X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 +public void test0014() { + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "class X extends Y {}\n" + + "class Y extends Z {}\n" + + "class Z extends A {}\n" + + "class A extends B {}\n" + + "class B extends C {}\n" + + "class C extends X {}\n" + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 2)\n" + + " class X extends Y {}\n" + + " ^\n" + + "The hierarchy of the type X is inconsistent\n" + + "----------\n" + + "2. ERROR in cycle\\X.java (at line 3)\n" + + " class Y extends Z {}\n" + + " ^\n" + + "The hierarchy of the type Y is inconsistent\n" + + "----------\n" + + "3. ERROR in cycle\\X.java (at line 4)\n" + + " class Z extends A {}\n" + + " ^\n" + + "The hierarchy of the type Z is inconsistent\n" + + "----------\n" + + "4. ERROR in cycle\\X.java (at line 5)\n" + + " class A extends B {}\n" + + " ^\n" + + "The hierarchy of the type A is inconsistent\n" + + "----------\n" + + "5. ERROR in cycle\\X.java (at line 6)\n" + + " class B extends C {}\n" + + " ^\n" + + "The hierarchy of the type B is inconsistent\n" + + "----------\n" + + "6. ERROR in cycle\\X.java (at line 7)\n" + + " class C extends X {}\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between C and X\n" + + "----------\n"); +} +public void testBug520874a() { + if (this.complianceLevel < ClassFileConstants.JDK9) + return; // Limit the new tests to newer levels + this.runNegativeTest(new String[] { + "cycle/A.java", + "package p;\n" + + "class A extends C {\n" + + " static class B {}\n" + + "}\n", + "cycle/X.java", + "package p;\n" + + "import p.A.B;\n" + + "class C extends B {}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new C();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in cycle\\A.java (at line 2)\n" + + " class A extends C {\n" + + " ^\n" + + "The hierarchy of the type A is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in cycle\\X.java (at line 3)\n" + + " class C extends B {}\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between C and A\n" + + "----------\n"); +} +public void testBug520874b() { + if (this.complianceLevel < ClassFileConstants.JDK9) + return; // Limit the new tests to newer levels + this.runNegativeTest(new String[] { + "cycle/X.java", + "package p;\n" + + "import p.A.*;\n" + + "class C extends B {}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new C();\n" + + " }\n" + + "}\n", + "cycle/A.java", + "package p;\n" + + "class A extends C {\n" + + " static class B {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 3)\n" + + " class C extends B {}\n" + + " ^\n" + + "The hierarchy of the type C is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in cycle\\A.java (at line 2)\n" + + " class A extends C {\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between A and C\n" + + "----------\n"); +} +public void testBug520874c() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // Limit the new tests to newer levels + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "import cycle.A.B;\n" + + "class C implements B {}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new C();\n" + + " }\n" + + "}\n", + "cycle/A.java", + "package cycle;\n" + + "class A extends C {\n" + + " static interface B {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 3)\n" + + " class C implements B {}\n" + + " ^\n" + + "The hierarchy of the type C is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in cycle\\A.java (at line 2)\n" + + " class A extends C {\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between A and C\n" + + "----------\n"); +} +public void testBug520874d() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // Limit the new tests to newer levels + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "import cycle.A.*;\n" + + "class C implements B {}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new C();\n" + + " }\n" + + "}\n", + "cycle/A.java", + "package cycle;\n" + + "class A extends C {\n" + + " static interface B {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 3)\n" + + " class C implements B {}\n" + + " ^\n" + + "The hierarchy of the type C is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in cycle\\A.java (at line 2)\n" + + " class A extends C {\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between A and C\n" + + "----------\n"); +} +public void testBug520874e() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // Limit the new tests to newer levels + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "import cycle.A.B;\n" + + "interface C extends B {}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " }\n" + + "}\n", + "cycle/A.java", + "package cycle;\n" + + "class A extends C {\n" + + " static interface B {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 3)\n" + + " interface C extends B {}\n" + + " ^\n" + + "The hierarchy of the type C is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in cycle\\A.java (at line 2)\n" + + " class A extends C {\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between A and C\n" + + "----------\n"); +} +public void testBug520874f() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // Limit the new tests to newer levels + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "import cycle.A.*;\n" + + "interface C extends B {}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " }\n" + + "}\n", + "cycle/A.java", + "package cycle;\n" + + "class A extends C {\n" + + " static interface B {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 3)\n" + + " interface C extends B {}\n" + + " ^\n" + + "The hierarchy of the type C is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in cycle\\A.java (at line 2)\n" + + " class A extends C {\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between A and C\n" + + "----------\n"); +} +public void testBug520874g() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // Limit the new tests to newer levels + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "import cycle.A.B;\n" + + "interface C extends B {}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " }\n" + + "}\n", + "cycle/A.java", + "package cycle;\n" + + "interface A extends C {\n" + + " static interface B {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 3)\n" + + " interface C extends B {}\n" + + " ^\n" + + "The hierarchy of the type C is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in cycle\\A.java (at line 2)\n" + + " interface A extends C {\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between A and C\n" + + "----------\n"); +} +public void testBug520874h() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // Limit the new tests to newer levels + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "import cycle.A.*;\n" + + "interface C extends B {}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " }\n" + + "}\n", + "cycle/A.java", + "package cycle;\n" + + "interface A extends C {\n" + + " static interface B {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 3)\n" + + " interface C extends B {}\n" + + " ^\n" + + "The hierarchy of the type C is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in cycle\\A.java (at line 2)\n" + + " interface A extends C {\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between A and C\n" + + "----------\n"); +} +public void testBug520874i() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // Limit the new tests to newer levels + this.runNegativeTest(new String[] { + "cycle/X.java", + "package cycle;\n" + + "import cycle.A.*;\n" + + "interface C extends A {}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " }\n" + + "}\n", + "cycle/A.java", + "package cycle;\n" + + "interface A extends C {\n" + + " static interface B {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in cycle\\X.java (at line 3)\n" + + " interface C extends A {}\n" + + " ^\n" + + "The hierarchy of the type C is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in cycle\\A.java (at line 2)\n" + + " interface A extends C {\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between A and C\n" + + "----------\n"); +} +public void testBug526681() { + runNegativeTest( + new String[] { + "p/A.java", + "package p;\n" + + "import p.B;\n" + + "public class A extends B {\n" + + " public static abstract class C {}\n" + + "}\n", + "p/B.java", + "package p;\n" + + "import p.A.C;\n" + + "public abstract class B extends C {}" + }, + "----------\n" + + "1. ERROR in p\\A.java (at line 3)\n" + + " public class A extends B {\n" + + " ^\n" + + "The hierarchy of the type A is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p\\B.java (at line 3)\n" + + " public abstract class B extends C {}\n" + + " ^\n" + + "Cycle detected: a cycle exists in the type hierarchy between B and A\n" + + "----------\n"); +} +public void testBug527731() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // uses diamond, 1.7-inference fails, only 1.8 is good + runConformTest( + new String[] { + "OuterClass.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class OuterClass extends ArrayList> {\n" + + " \n" + + " public static interface InnerInterface {}\n" + + " \n" + + " public static class InnerTypedClass implements InnerInterface {}\n" + + " \n" + + " public static void main(String[] args) {\n" + + " OuterClass outerClass = new OuterClass<>();\n" + + " outerClass.add(new InnerTypedClass<>());\n" + + " System.out.println(outerClass);\n" + + " }\n" + + "}\n" + }); +} +public static Class testClass() { + return InnerClass15Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java new file mode 100644 index 0000000000..9a72c73058 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java @@ -0,0 +1,7178 @@ +/******************************************************************************* + * Copyright (c) 2006, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 388800 - [1.8] adjust tests to 1.8 JRE + * Keigo Imai - Contribution for bug 388903 - Cannot extend inner class as an anonymous class when it extends the outer class + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.Flags; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class InnerEmulationTest extends AbstractRegressionTest { +static { +// TESTS_NAMES = new String[] { "Bug58069" }; +// TESTS_NUMBERS = new int[] { 173, 174 }; +// TESTS_RANGE = new int[] { 144, -1 }; +} +public InnerEmulationTest(String name) { + super(name); +} +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + return options; +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} +/** + * Protected access emulation : should be performed onto implicit field and method accesses + */ +public void test001() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "import p2.*; \n"+ + "public class A { \n"+ + " protected int value = 0; \n"+ + " protected A delegatee; \n"+ + " public A(A del, int val) { \n"+ + " this.delegatee = del; \n"+ + " this.value = val; \n"+ + " } \n"+ + " protected void foo() { \n"+ + " value += 3; \n"+ + " } \n"+ + " public static void main(String[] argv){ \n"+ + " int result = new B( \n"+ + " new B(null, 10), 20) \n"+ + " .value; \n"+ + " int expected = 30; \n"+ + " System.out.println( \n"+ + " result == expected \n"+ + " ? \"SUCCESS\" \n"+ + " : \"FAILED : got \"+result+\" instead of \"+ expected); \n"+ + " } \n"+ + "} \n", + /* p2.B */ + "p2/B.java", + "package p2; \n"+ + "import p1.*; \n"+ + "public class B extends A { \n"+ + " public B(B del, int val){ \n"+ + " super(del, val); \n"+ + " Runnable r = new Runnable () { \n"+ + " public void run() { \n"+ + " foo(); \n"+ + " if (delegatee != null) \n"+ + " value += 7; \n"+ + " } \n"+ + " }; \n"+ + " r.run(); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} +/** + * 1FN4S4Z: The compiler doesn't detect a illegal constructor invocation which leads to a VerifyError + */ +public void test002() { + this.runNegativeTest( + new String[] { + /* A.java */ + "A.java", + "class B { \n"+ + "} \n"+ + "public class A { \n"+ + " B b; \n"+ + " class C extends B { \n"+ + " public C() { \n"+ + " } \n"+ + " } \n"+ + " public A() { \n"+ + " this(new C()); \n"+ + " } \n"+ + " public A(C c) { \n"+ + " this.b = c; \n"+ + " } \n"+ + " public static void main(String[] args) { \n"+ + " A a = new A(); \n"+ + " System.out.println(a); \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in A.java (at line 10)\n" + + " this(new C()); \n" + + " ^^^^^^^\n" + + "No enclosing instance of type A is available due to some intermediate constructor invocation\n" + + "----------\n" + + ); +} +/** + * 1FZ2G7R: use of non static inner class in constuctor + */ +public void test003() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in A.java (at line 8)\n" + + " super(getRunnable(), new B().toString()); \n" + + " ^^^^^^^\n" + + "No enclosing instance of type A is available due to some intermediate constructor invocation\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in A.java (at line 8)\n" + + " super(getRunnable(), new B().toString()); \n" + + " ^^^^^^^\n" + + "Access to enclosing constructor A.B() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in A.java (at line 8)\n" + + " super(getRunnable(), new B().toString()); \n" + + " ^^^^^^^\n" + + "No enclosing instance of type A is available due to some intermediate constructor invocation\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + /* A.java */ + "A.java", + "public class A extends Thread { \n" + + " private class B { \n" + + " } \n" + + " private static Runnable getRunnable() { \n" + + " return null; \n" + + " } \n" + + " public A() { \n" + + " super(getRunnable(), new B().toString()); \n" + + " } \n" + + "} \n" + }, + errMessage); +} +/** + * 1F995V9: Walkback in innerclass emulation when mixing source and binaries + */ +public void test004() { + + + /* first compile A3.java */ + + this.runConformTest( + new String[] { + /* A3.java */ + "A3.java", + "class A3 { \n"+ + " class B {} \n"+ + "} \n" + }); // no specific success output string + + /* then compile with previous input */ + + this.runConformTest( + new String[] { + /* A4.java */ + "A4.java", + "class A4 { \n"+ + " void foo(){ \n"+ + " new A3().new B(){}; \n"+ + " } \n"+ + "} \n" + }, + null, // no specific success output string + null, // use default class-path + false, + null); // do not flush previous output dir content + +} +/** + * 1FK9ALJ: Cannot invoke private super constructor ... + */ +public void test005() { + this.runConformTest( + new String[] { + /* X.java */ + "X.java", + "public class X { \n"+ + " private X(){} \n"+ + " class Y extends X { \n"+ + " } \n"+ + " public static void main(String[] argv){ \n"+ + " new X().new Y(); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} +/** + * 1FKLXDL: Verification error due to incorrect private access emulation + */ +public void test006() { + this.runConformTest( + new String[] { + /* X.java */ + "X.java", + "public class X { \n"+ + " public static void main(String[] argv){ \n"+ + " new B(); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " private static void foo(int i, int j) { \n"+ + " System.out.println(\"private foo\"); \n"+ + " } \n"+ + " static class B { \n"+ + " { \n"+ + " foo(1, 2); \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + "private foo\n" + + "SUCCESS" + ); +} +/** + * 1PQCT5T: Missing emulation for access to sibling local types + */ +public void test007() { + this.runConformTest( + new String[] { + /* Y.java */ + "Y.java", + "public class Y { \n" + + " public static void main(String[] argv){ \n" + + " if (new Y().bar() == 3) \n" + + " System.out.println(\"SUCCESS\"); \n" + + " else \n" + + " System.out.println(\"FAILED\"); \n" + + " } \n" + + " int bar() { \n" + + " final int i = \"xxx\".length(); \n" + + " class X { \n" + + " class AX { \n" + + " int foo() { \n" + + " return new BX().foo(); \n" + + " } \n" + + " } \n" + + " class BX { \n" + + " int foo() { \n" + + " return new CX().foo(); \n" + + " } \n" + + " } \n" + + " class CX { \n" + + " int foo() { \n" + + " return i; \n" + + " } \n" + + " } \n" + + " } \n" + + " return new X().new AX().foo(); \n" + + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} +/** + * 1PQCT5T: Missing emulation for access to sibling local types + */ +public void test008() { + this.runConformTest( + new String[] { + /* Y2.java */ + "Y2.java", + "public class Y2 { \n" + + " public static void main(String[] argv){ \n" + + " if (new Y2().foo(45) == 45) \n" + + " System.out.println(\"SUCCESS\"); \n" + + " else \n" + + " System.out.println(\"FAILED\"); \n" + + " } \n" + + " int foo(final int i){ \n"+ + " class B { \n"+ + " int foo(){ \n"+ + " return new C().foo(); \n"+ + " } \n"+ + " class C { \n"+ + " int foo(){ return i; } \n"+ + " } \n"+ + " }; \n"+ + " return new B().foo(); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} +/** + * 1PQCT5T: Missing emulation for access to sibling local types + */ +public void test009() { + this.runConformTest( + new String[] { + /* Y3.java */ + "Y3.java", + "public class Y3 { \n" + + " public static void main(String[] argv){ \n" + + " if (new Y3().bar() == 8) \n" + + " System.out.println(\"SUCCESS\"); \n" + + " else \n" + + " System.out.println(\"FAILED\"); \n" + + " } \n" + + " int bar() { \n" + + " final int i = \"xxx\".length(); \n" + + " final String s = this.toString(); \n" + + " class X { \n" + + " class AX { \n" + + " int foo() { \n" + + " return i + new CX().foo(); \n" + + " } \n" + + " } \n" + + " class BX { \n" + + " int foo() { \n" + + " return new AX().foo(); \n" + + " } \n" + + " } \n" + + " class CX { \n" + + " int foo() { \n" + + " return 5; \n" + + " } \n" + + " } \n" + + " } \n" + + " return new X().new AX().foo(); \n" + + " } \n" + + "} \n" + }, + "SUCCESS" + ); +} +/** + * 1PQCT5T: Missing emulation for access to sibling local types + */ +public void test010() { + this.runConformTest( + new String[] { + /* Y4.java */ + "Y4.java", + "public class Y4 { \n" + + " public static void main(String[] argv){ \n" + + " if (new Y4().bar() == 3) \n" + + " System.out.println(\"SUCCESS\"); \n" + + " else \n" + + " System.out.println(\"FAILED\"); \n" + + " } \n" + + " int bar() { \n" + + " final int i = \"xxx\".length(); \n" + + " final String s = this.toString(); \n" + + " class X { \n" + + " class AX { \n" + + " int bar() { \n" + + " class BX { \n" + + " int foo() { \n" + + " return new AX().foo(); \n" + + " } \n" + + " } \n" + + " return new BX().foo(); \n" + + " } \n" + + " int foo() { \n" + + " return i; \n" + + " } \n" + + " } \n" + + " } \n" + + " return new X().new AX().bar(); \n" + + " } \n" + + "} \n" + }, + "SUCCESS" + ); +} +/** + * 1PQCT5T: Missing emulation for access to sibling local types + */ +public void test011() { + this.runConformTest( + new String[] { + /* Y5.java */ + "Y5.java", + "public class Y5 { \n" + + " public static void main(String[] argv){ \n" + + " if (new Y5().bar(5) == 5) \n" + + " System.out.println(\"SUCCESS\"); \n" + + " else \n" + + " System.out.println(\"FAILED\"); \n" + + " } \n" + + " int bar(final int i) { \n" + + " class X { \n" + + " int bar() { \n" + + " return new Object(){ \n" + + " int foo(){ \n" + + " return i; \n" + + " } \n" + + " }.foo(); \n" + + " } \n" + + " } \n" + + " return new X().bar(); \n" + + " } \n" + + "} \n" + }, + "SUCCESS" + ); +} +/** + * 1F3AH7N: GPF on innerclass emulation for double anonymous type + */ +public void test012() { + this.runConformTest( + new String[] { + /* A.java */ + "A.java", + "public class A { \n" + + " public static void main(String[] argv){ \n" + + " if (new A().foo() == 5) \n" + + " System.out.println(\"SUCCESS\"); \n" + + " else \n" + + " System.out.println(\"FAILED\"); \n" + + " } \n" + + " int foo() { \n" + + " return new A() { \n" + + " int foo() { \n" + + " final int i = \"hello\".length(); \n" + + " return new A() { \n" + + " int foo() { \n" + + " return i; \n" + + " } \n" + + " } \n" + + " .foo(); \n" + + " } \n" + + " } \n" + + " .foo(); \n" + + " } \n" + + "} \n" + }, + "SUCCESS" + ); +} +/** + * 1F26XE2: Bug in inner class emulation + */ +public void test013() { + this.runConformTest( + new String[] { + /* Inner.java */ + "Inner.java", + "public class Inner { \n" + + " public static void main(String[] argv){ \n" + + " new B().new C(\"hello\"); \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " class A { \n"+ + " public A(String s){ this.s=s; } \n"+ + " String s; \n"+ + " } \n"+ + "} \n"+ + "class B { \n"+ + " class C extends Inner.A { \n"+ + " public C(String s){ B.this.inner.super(s); } \n"+ + " } \n"+ + " Inner inner=new Inner(); \n"+ + "} \n" + }, + "SUCCESS" + ); +} +/** + * 1EX5I8Z: Inner class emulation bug + */ +public void test014() { + this.runConformTest( + new String[] { + /* Z1.java */ + "Z1.java", + "public class Z1 { \n" + + " public static void main(String[] argv){ \n" + + " new Z1().new W(); \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " class W extends Y { \n" + + " W() { \n" + + " super(new Object(), foo()); \n" + + " } \n" + + " } \n" + + " String foo() { \n" + + " return \"\"; \n" + + " } \n" + + "} \n" + + "class Y { \n" + + " Y(Object o, String s) { \n" + + " } \n" + + "} \n" + }, + "SUCCESS" + ); +} +/** + * 1EUC39Y: Incorrect Synthetic Emulation + */ +public void test015() { + this.runConformTest( + new String[] { + /* AAA.java */ + "AAA.java", + "public class AAA { \n"+ + " public static void main(String argv[]){ \n"+ + " if (new AAA().foo(5) == 15); \n"+ + " System.out.println(\"SUCCESS\"); \n" + + " } \n"+ + " int foo(final int loc){ \n"+ + " class I { \n"+ + " int i = loc; \n"+ + " { \n"+ + " System.out.println(\"loc=\"+ loc ); \n"+ + " } \n"+ + " int foo(){ \n"+ + " System.out.println(\"I:i=\"+ i ); \n"+ + " return i;} \n"+ + " } \n"+ + " class J extends I { \n"+ + " I obj = new I(){ \n"+ + " int foo() { \n"+ + " System.out.println(\"J\"); \n"+ + " return super.foo() + 10; }}; \n"+ + " } \n"+ + " return new J().obj.foo(); \n"+ + " } \n"+ + " } \n" + }, + "loc=5\n" + + "loc=5\n" + + "J\n" + + "I:i=5\n" + + "SUCCESS" + ); +} +/** + * 1EUC39Y: Incorrect Synthetic Emulation + */ +public void test016() { + this.runConformTest( + new String[] { + /* AAA.java */ + "AAA.java", + "public class AAA { \n"+ + " public static void main(String argv[]){ \n"+ + " if (new AAA().foo(5) == 15); \n"+ + " System.out.println(\"SUCCESS\"); \n" + + " } \n"+ + " class B{} \n"+ + " int foo(final int loc){ \n"+ + " class I extends B { \n"+ + " int i = loc; \n"+ + " { \n"+ + " System.out.println(\"loc=\"+ loc ); \n"+ + " } \n"+ + " int foo(){ \n"+ + " System.out.println(\"I:i=\"+ i ); \n"+ + " return i;} \n"+ + " } \n"+ + " class J extends I { \n"+ + " I obj = new I(){ \n"+ + " int foo() { \n"+ + " System.out.println(\"J\"); \n"+ + " return super.foo() + 10; }}; \n"+ + " } \n"+ + " return new J().obj.foo(); \n"+ + " } \n"+ + " } \n" + }, + "loc=5\n" + + "loc=5\n" + + "J\n" + + "I:i=5\n" + + "SUCCESS" + ); +} +/** + * Complex multi-threaded test involving inner classes + */ +public void test017() { + this.runConformTest( + new String[] { + /* MultiComplex.java */ + "MultiComplex.java", + "public class MultiComplex {\n" + + " // should just be an interface, once supported...\n" + + " abstract class AbstractTask implements Runnable {\n" + + " public void run() {\n" + + " MultiComplex.this.notifyCompletion(this,0); \n" + + " }\n" + + " abstract public String taskName(); \n" + + " }\n" + + " public static void main(String argv[]){\n" + + " try {\n" + + " new MultiComplex().performTasks(3);\n" + + " }\n" + + " catch(InterruptedException e){};\n" + + " } \n" + + " void notifyCompleted(AbstractTask task) {\n" + + " }\n" + + " void notifyCompletion(AbstractTask task, int percentage) {\n" + + " }\n" + + " void notifyExecutionEnd() {\n" + + " System.out.println(\"EXECUTION FINISHED\");\n" + + " }\n" + + " void notifyExecutionStart() {\n" + + " System.out.println(\"EXECUTION STARTING\");\n" + + " }\n" + + " void performTasks(final int maxTasks) throws InterruptedException {\n" + + " Thread workers[] = new Thread[maxTasks];\n" + + " AbstractTask tasks[] = new AbstractTask[maxTasks];\n" + + " final int maxIteration = 5;\n" + + " \n" + + " // Local Task \n" + + " class Task extends AbstractTask { \n" + + " String taskName; \n" + + " Task(String aName) {\n" + + " taskName = aName;\n" + + " }\n" + + " public String taskName() { \n" + + " return taskName; \n" + + " }\n" + + " \n" + + " public void run() {\n" + + " super.run();\n" + + " for(int j = 0; j < maxIteration; j++)\n" + + " MultiComplex.this.notifyCompletion(this, (int)((float) (j + 1) / maxIteration * 100));\n" + + " }\n" + + " };\n" + + " notifyExecutionStart();\n" + + " \n" + + " // Creating and launching the tasks\n" + + " for (int ii = 0; ii < maxTasks; ii++) {\n" + + " final int i = ii;\n" + + " tasks[i] = new Task(String.valueOf(i + 1)) { \n" + + " public String taskName() { \n" + + " return super.taskName() + \" of \" + maxTasks; }\n" + + " public void run() {\n" + + " super.run();\n" + + " MultiComplex.this.notifyCompleted(this);\n" + + " } \n" + + " };\n" + + " workers[i] = new Thread(tasks[i],tasks[i].taskName());\n" + + " workers[i].start();\n" + + " }\n" + + " // Waiting for *all* tasks to be ended\n" + + " for (int i = 0; i < tasks.length; i++)\n" + + " workers[i].join();\n" + + " notifyExecutionEnd();\n" + + " }\n" + + "}\n" + }, + "EXECUTION STARTING\n" + + "EXECUTION FINISHED" + ); +} +/** + * Complex multi-threaded test involving inner classes + */ +public void test018() { + this.runConformTest( + new String[] { + /* MultiAnonymous.java */ + "MultiAnonymous.java", + "public class MultiAnonymous {\n" + + " public static void main(String argv[]){\n" + + " try {\n" + + " new MultiAnonymous().performTasks(3);\n" + + " }\n" + + " catch(InterruptedException e){};\n" + + " }\n" + + " void notifyExecutionEnd() {\n" + + " System.out.println(\"EXECUTION FINISHED\");\n" + + " }\n" + + " void notifyExecutionStart() {\n" + + " System.out.println(\"EXECUTION STARTING\");\n" + + " }\n" + + " void performTasks(final int maxTasks) throws java.lang.InterruptedException {\n" + + " Thread workers[] = new Thread[maxTasks];\n" + + " Runnable tasks[] = new Runnable[maxTasks];\n" + + " final int maxIteration = 5;\n" + + " notifyExecutionStart();\n" + + " \n" + + " // Creating and launching the tasks\n" + + " for (int ii = 0; ii < maxTasks; ii++) {\n" + + " final int i = ii;\n" + + " tasks[i] = new Runnable() { \n" + + " public String toString() { return ((i + 1) + \" of \" + maxTasks); }\n" + + " public void run() {\n" + + " for(int j = 0; j < maxIteration; j++)\n" + + " notifyCompletion( (int)((float) (j + 1) / maxIteration * 100));\n" + + " } \n" + + " \n" + + " void notifyCompletion(int percentage) {\n" + + " }\n" + + " };\n" + + " workers[i] = new Thread(tasks[i],\"Running task(\"+(tasks[i].toString())+\")\");\n" + + " workers[i].start();\n" + + " }\n" + + " // Waiting for *all* tasks to be ended\n" + + " for (int i = 0; i < tasks.length; i++)\n" + + " workers[i].join();\n" + + " notifyExecutionEnd();\n" + + " }\n" + + "}\n" + }, + "EXECUTION STARTING\n" + + "EXECUTION FINISHED" + ); +} +/** + * Complex multi-threaded test involving inner classes + */ +public void test019() { + this.runConformTest( + new String[] { + /* MultiComplex2.java */ + "MultiComplex2.java", + "public class MultiComplex2 {\n" + + " public interface AbstractTask extends Runnable {\n" + + " public void run();\n" + + " public String taskName(); \n" + + " }\n" + + " \n" + + " public static void main(String argv[]){\n" + + " try {\n" + + " new MultiComplex2().performTasks(3);\n" + + " }\n" + + " catch(InterruptedException e){};\n" + + " }\n" + + " void notifyCompleted(AbstractTask task) {\n" + + " }\n" + + " void notifyCompletion(AbstractTask task, int percentage) {\n" + + " }\n" + + " void notifyExecutionEnd() {\n" + + " System.out.println(\"EXECUTION FINISHED\");\n" + + " }\n" + + " void notifyExecutionStart() {\n" + + " System.out.println(\"EXECUTION STARTING\");\n" + + " }\n" + + " void performTasks(final int maxTasks) throws java.lang.InterruptedException {\n" + + " Thread workers[] = new Thread[maxTasks];\n" + + " AbstractTask tasks[] = new AbstractTask[maxTasks];\n" + + " final int maxIteration = 5;\n" + + " // Local Task\n" + + " class Task implements AbstractTask {\n" + + " String taskName;\n" + + " Task(String aName) {\n" + + " taskName = aName;\n" + + " }\n" + + " public String taskName() { \n" + + " return taskName; \n" + + " }\n" + + " \n" + + " public void run() {\n" + + " MultiComplex2.this.notifyCompletion(this,0); \n" + + " for(int j = 0; j < maxIteration; j++)\n" + + " MultiComplex2.this.notifyCompletion(this, (int)((float) (j + 1) / maxIteration * 100));\n" + + " }\n" + + " };\n" + + " notifyExecutionStart();\n" + + " \n" + + " // Creating and launching the tasks\n" + + " for (int ii = 0; ii < maxTasks; ii++) {\n" + + " final int i = ii;\n" + + " tasks[i] = new Task(String.valueOf(i + 1)) { \n" + + " public String taskName() { \n" + + " return super.taskName() + \" of \" + maxTasks; }\n" + + " public void run() {\n" + + " super.run();\n" + + " MultiComplex2.this.notifyCompleted(this);\n" + + " } \n" + + " };\n" + + " workers[i] = new Thread(tasks[i],tasks[i].taskName());\n" + + " workers[i].start();\n" + + " }\n" + + " // Waiting for *all* tasks to be ended\n" + + " for (int i = 0; i < tasks.length; i++)\n" + + " workers[i].join();\n" + + " notifyExecutionEnd();\n" + + " }\n" + + "}\n" + }, + "EXECUTION STARTING\n" + + "EXECUTION FINISHED" + ); +} +/** + * Complex multi-threaded test involving inner classes + */ +public void test020() { + this.runConformTest( + new String[] { + /* MultiLocal.java */ + "MultiLocal.java", + "public class MultiLocal {\n" + + " public static void main(String argv[]){\n" + + " class Task implements Runnable {\n" + + " private String taskName;\n" + + " private int maxIteration; \n" + + " public Task(String name, int value) {\n" + + " taskName = name; \n" + + " maxIteration = value;\n" + + " }\n" + + " \n" + + " public String toString() { return taskName; }\n" + + " public void run() {\n" + + " for(int i = 0; i < maxIteration; i++)\n" + + " notifyCompletion( (int)((float) (i + 1) / maxIteration * 100));\n" + + " } \n" + + " \n" + + " void notifyCompletion(int percentage) {\n" + + " }\n" + + " };\n" + + " MultiLocal multi = new MultiLocal();\n" + + " int maxTasks = 3;\n" + + " Task tasks[] = new Task[maxTasks];\n" + + " for (int i = 0; i < maxTasks; i++) \n" + + " tasks[i] = new Task(String.valueOf(i),5);\n" + + " try {\n" + + " multi.performTasks(tasks);\n" + + " }\n" + + " catch(InterruptedException e){};\n" + + " }\n" + + " void notifyExecutionEnd() {\n" + + " System.out.println(\"EXECUTION FINISHED\");\n" + + " }\n" + + " void notifyExecutionStart() {\n" + + " System.out.println(\"EXECUTION STARTING\");\n" + + " }\n" + + " void performTasks(Runnable tasks[]) throws java.lang.InterruptedException {\n" + + " Thread workers[] = new Thread[tasks.length];\n" + + " notifyExecutionStart();\n" + + " \n" + + " // Launching the tasks\n" + + " for (int i = 0; i < tasks.length; i++) {\n" + + " workers[i] = new Thread(tasks[i],\"Running task(\"+(tasks[i].toString())+\")\");\n" + + " workers[i].start();\n" + + " }\n" + + " // Waiting for *all* tasks to be ended\n" + + " for (int i = 0; i < tasks.length; i++)\n" + + " workers[i].join();\n" + + " notifyExecutionEnd();\n" + + " }\n" + + "}\n" + }, + "EXECUTION STARTING\n" + + "EXECUTION FINISHED" + ); +} +/** + * Complex multi-threaded test involving inner classes + */ +public void test021() { + this.runConformTest( + new String[] { + /* MultiLocal2.java */ + "MultiLocal2.java", + "public class MultiLocal2 {\n" + + " public static void main(String argv[]){\n" + + " final int maxTasks = 3;\n" + + " class Task implements Runnable {\n" + + " private String taskName;\n" + + " private int maxIteration;\n" + + " public Task(String name, int value) {\n" + + " taskName = name; \n" + + " maxIteration = value;\n" + + " }\n" + + " \n" + + " public String toString() { return taskName + \" of \" + String.valueOf(maxTasks); }\n" + + " public void run() {\n" + + " for(int i = 0; i < maxIteration; i++)\n" + + " notifyCompletion( (int)((float) (i + 1) / maxIteration * 100));\n" + + " } \n" + + " \n" + + " void notifyCompletion(int percentage) {\n" + + " }\n" + + " };\n" + + " MultiLocal2 multi = new MultiLocal2();\n" + + " Task tasks[] = new Task[maxTasks];\n" + + " for (int i = 0; i < maxTasks; i++) \n" + + " tasks[i] = new Task(String.valueOf(i+1),5);\n" + + " try {\n" + + " multi.performTasks(tasks);\n" + + " }\n" + + " catch(InterruptedException e){};\n" + + " }\n" + + " void notifyExecutionEnd() {\n" + + " System.out.println(\"EXECUTION FINISHED\");\n" + + " }\n" + + " void notifyExecutionStart() {\n" + + " System.out.println(\"EXECUTION STARTING\");\n" + + " }\n" + + " void performTasks(Runnable tasks[]) throws java.lang.InterruptedException {\n" + + " Thread workers[] = new Thread[tasks.length];\n" + + " notifyExecutionStart();\n" + + " \n" + + " // Launching the tasks\n" + + " for (int i = 0; i < tasks.length; i++) {\n" + + " workers[i] = new Thread(tasks[i],\"Running task(\"+(tasks[i].toString())+\")\");\n" + + " workers[i].start();\n" + + " }\n" + + " // Waiting for *all* tasks to be ended\n" + + " for (int i = 0; i < tasks.length; i++)\n" + + " workers[i].join();\n" + + " notifyExecutionEnd();\n" + + " }\n" + + "}\n" + }, + "EXECUTION STARTING\n" + + "EXECUTION FINISHED" + ); +} +/** + * Complex multi-threaded test involving inner classes + */ +public void test022() { + this.runConformTest( + new String[] { + /* MultiMember.java */ + "MultiMember.java", + "public class MultiMember {\n" + + " class Task implements Runnable {\n" + + " private String taskName; \n" + + " private int maxIteration;\n" + + " public Task(String name, int value) {\n" + + " taskName = name; \n" + + " maxIteration = value;\n" + + " }\n" + + " public String toString() { return taskName; }\n" + + " public void run() {\n" + + " for(int i = 0; i < maxIteration; i++)\n" + + " notifyCompletion( (int)((float) (i + 1) / maxIteration * 100));\n" + + " } \n" + + " \n" + + " void notifyCompletion(int percentage) {\n" + + " }\n" + + " }\n" + + " public static void main(String argv[]){\n" + + " MultiMember multi = new MultiMember();\n" + + " int maxTasks = 3;\n" + + " Task tasks[] = new Task[maxTasks];\n" + + " for (int i = 0; i < maxTasks; i++) \n" + + " tasks[i] = multi.new Task(String.valueOf(i),5);\n" + + " try {\n" + + " multi.performTasks(tasks);\n" + + " }\n" + + " catch(InterruptedException e){};\n" + + " }\n" + + " void notifyExecutionEnd() {\n" + + " System.out.println(\"EXECUTION FINISHED\");\n" + + " }\n" + + " void notifyExecutionStart() {\n" + + " System.out.println(\"EXECUTION STARTING\");\n" + + " }\n" + + " void performTasks(Task tasks[]) throws java.lang.InterruptedException {\n" + + " Thread workers[] = new Thread[tasks.length];\n" + + " notifyExecutionStart();\n" + + " \n" + + " // Launching the tasks\n" + + " for (int i = 0; i < tasks.length; i++) {\n" + + " workers[i] = new Thread(tasks[i],\"Running task(\"+(tasks[i].toString())+\")\");\n" + + " workers[i].start();\n" + + " }\n" + + " // Waiting for *all* tasks to be ended\n" + + " for (int i = 0; i < tasks.length; i++)\n" + + " workers[i].join();\n" + + " notifyExecutionEnd();\n" + + " }\n" + + "}\n" + }, + "EXECUTION STARTING\n" + + "EXECUTION FINISHED" + ); +} +/** + * No need for protected access emulation + */ +public void test023() { + this.runConformTest( + new String[] { + /* X.java */ + "p/X.java", + "package p; \n" + + "public class X extends q.Y { \n" + + " void bar(){ Object o = someObject; } \n"+ + " public static void main(String[] argv){ \n" + + " new X().bar();\n"+ + " System.out.println(\"SUCCESS\");\n"+ + " }\n"+ + "}\n", + /* Y.java */ + "q/Y.java", + "package q; \n" + + "public class Y { \n" + + " protected Object someObject; \n" + + "}\n" + }, + "SUCCESS" + ); +} +/** + * No need for protected access emulation + */ +public void test024() { + this.runConformTest( + new String[] { + /* X.java */ + "p/X.java", + "package p; \n" + + "public class X extends q.Y { \n" + + " void bar(){ foo(); } \n"+ + " public static void main(String[] argv){ \n" + + " new X().bar();\n"+ + " System.out.println(\"SUCCESS\");\n"+ + " }\n"+ + "}\n", + /* Y.java */ + "q/Y.java", + "package q; \n" + + "public class Y { \n" + + " protected Object foo(){ return null;} \n" + + "}\n" + }, + "SUCCESS" + ); +} + +public void test025() { + this.runConformTest( + new String[] { + /* PortReport.java */ + "PortReport.java", + "import java.util.*; \n"+ + "public class PortReport { \n"+ + " public static void main(String[] args) { \n"+ + " Portfolio port = new Portfolio(\"foobar\"); \n"+ + " System.out.println(\"SUCCESS\"); \n" + + " } \n"+ + "} \n", + /* Portfolio.java */ + "Portfolio.java", + "import java.util.*; \n"+ + "public class Portfolio { \n"+ + " String name; \n"+ + " public Portfolio(String buf) { \n"+ + " TokenBuffer tbuf = new TokenBuffer(); \n"+ + " switch (1) { \n"+ + " case TokenBuffer.T_NAME : \n"+ + " name = \"figi\"; \n"+ + " } \n"+ + " } \n"+ + " String getName() { \n"+ + " return name; \n"+ + " } \n"+ + " class TokenBuffer { \n"+ + " static final int T_NAME = 3; \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} +/** + * Compatability - Compiler does not comply with 1.1 standard. + */ +public void test026() { + this.runConformTest( + new String[] { + /* Test.java */ + "p2/Test.java", + "package p2; \n"+ + "public class Test { \n"+ + " public static void main (String args[]){ \n"+ + " new c2(); \n"+ + " } \n"+ + "} \n", + /* c1.java */ + "p1/c1.java", + "package p1; \n"+ + "public class c1 { \n"+ + " protected class c1a{ \n"+ + " public c1a(){} \n"+ + " public void foo(){ System.out.println(\"Foo called\"); \n"+ + " } \n"+ + " }; \n"+ + "} \n", + /* c2.java */ + "p2/c2.java", + "package p2; \n"+ + "import p1.*; \n"+ + "public class c2 extends c1 { \n"+ + " public c1a myC1a; \n"+ + " { \n"+ + " myC1a = new c1a(); \n"+ + " myC1a.foo(); \n"+ + " } \n"+ + "} \n" + }, + "Foo called" + ); +} +/** + * Compatability - Compiler does not comply with 1.1 standard. + */ +public void test027() { + this.runNegativeTest( + new String[] { + /* Test.java */ + "p2/Test.java", + "package p2; \n"+ + "public class Test { \n"+ + " public static void main (String args[]){ \n"+ + " new c2(); \n"+ + " } \n"+ + "} \n", + /* c1.java */ + "p1/c1.java", + "package p1; \n"+ + "public class c1 { \n"+ + " public class c1m { \n"+ + " protected class c1a{ \n"+ + " public c1a(){} \n"+ + " public void foo(){ System.out.println(\"Foo called\"); \n"+ + " } \n"+ + " }; \n"+ + " }; \n"+ + "} \n", + /* c2.java */ + "p2/c2.java", + "package p2; \n"+ + "import p1.*; \n"+ + "public class c2 extends c1 { \n"+ + " public c1m.c1a myC1a; \n"+ + " { \n"+ + " myC1a = new c1m().new c1a(); \n"+ + " myC1a.foo(); \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p2\\c2.java (at line 4)\n" + + " public c1m.c1a myC1a; \n" + + " ^^^^^^^\n" + + "The type c1m.c1a is not visible\n" + + "----------\n" + + "2. ERROR in p2\\c2.java (at line 6)\n" + + " myC1a = new c1m().new c1a(); \n" + + " ^^^\n" + + "The type c1.c1m.c1a is not visible\n" + + "----------\n" + + "3. ERROR in p2\\c2.java (at line 7)\n" + + " myC1a.foo(); \n" + + " ^^^^^\n" + + "The type c1.c1m.c1a is not visible\n" + + "----------\n"); +} +/** + * Compatability - Compiler does not comply with 1.1 standard. + */ +public void test028() { + this.runNegativeTest( + new String[] { + /* Test.java */ + "p2/Test.java", + "package p2; \n"+ + "public class Test { \n"+ + " public static void main (String args[]){ \n"+ + " new c2(); \n"+ + " } \n"+ + "} \n", + /* c1.java */ + "p1/c1.java", + "package p1; \n"+ + "public class c1 { \n"+ + " protected class c1m { \n"+ + " protected class c1a{ \n"+ + " public c1a(){} \n"+ + " public void foo(){ System.out.println(\"Foo called\"); \n"+ + " } \n"+ + " }; \n"+ + " }; \n"+ + "} \n", + /* c2.java */ + "p2/c2.java", + "package p2; \n"+ + "import p1.*; \n"+ + "public class c2 extends c1 { \n"+ + " public c1m.c1a myC1a; \n"+ + " { \n"+ + " myC1a = new c1m().new c1a(); \n"+ + " myC1a.foo(); \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p2\\c2.java (at line 4)\n" + + " public c1m.c1a myC1a; \n" + + " ^^^^^^^\n" + + "The type c1m.c1a is not visible\n" + + "----------\n" + + "2. ERROR in p2\\c2.java (at line 6)\n" + + " myC1a = new c1m().new c1a(); \n" + + " ^^^^^^^^^\n" + + "The constructor c1.c1m() is not visible\n" + + "----------\n" + + "3. ERROR in p2\\c2.java (at line 6)\n" + + " myC1a = new c1m().new c1a(); \n" + + " ^^^\n" + + "The type c1.c1m.c1a is not visible\n" + + "----------\n" + + "4. ERROR in p2\\c2.java (at line 7)\n" + + " myC1a.foo(); \n" + + " ^^^^^\n" + + "The type c1.c1m.c1a is not visible\n" + + "----------\n"); +} +/** + * Compatability - Compiler does not comply with 1.1 standard. + */ +public void test029() { + this.runConformTest( + new String[] { + /* Test.java */ + "p2/Test.java", + "package p2; \n"+ + "public class Test { \n"+ + " public static void main (String args[]){ \n"+ + " new c2(); \n"+ + " } \n"+ + "} \n", + /* c1.java */ + "p1/c1.java", + "package p1; \n"+ + "public class c1 { \n"+ + " protected class c1a{ \n"+ + " public c1a(){} \n"+ + " public void foo(){ System.out.println(\"Foo called\"); \n"+ + " } \n"+ + " }; \n"+ + "} \n", + /* c2.java */ + "p2/c2.java", + "package p2; \n"+ + "import p1.*; \n"+ + "public class c2 extends c1 { \n"+ + " public c1.c1a myC1a;\n"+ + " { \n"+ + " myC1a = new c1a(); \n"+ + " myC1a.foo(); \n"+ + " } \n"+ + "} \n" + }, + "Foo called"); +} +/** + * Compatability - Compiler does not comply with 1.1 standard. + */ +public void test030() { + this.runNegativeTest( + new String[] { + /* Test.java */ + "p2/Test.java", + "package p2; \n"+ + "public class Test { \n"+ + " public static void main (String args[]){ \n"+ + " new c2(); \n"+ + " } \n"+ + "} \n", + /* c1.java */ + "p1/c1.java", + "package p1; \n"+ + "public class c1 { \n"+ + " protected class c1a{ \n"+ + " public c1a(){} \n"+ + " public void foo(){ System.out.println(\"Foo called\"); \n"+ + " } \n"+ + " }; \n"+ + "} \n", + /* c2.java */ + "p2/c2.java", + "package p2; \n"+ + "import p1.*; \n"+ + "public class c2 extends c1.c1a {// qualified acces does not work \n"+ + " public c1a myC1a; \n"+ + " { \n"+ + " myC1a = new c1a(); \n"+ + " myC1a.foo(); \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p2\\c2.java (at line 3)\n" + + " public class c2 extends c1.c1a {// qualified acces does not work \n" + + " ^^^^^^\n" + + "The type c1.c1a is not visible\n" + + "----------\n" + + "2. ERROR in p2\\c2.java (at line 4)\n" + + " public c1a myC1a; \n" + + " ^^^\n" + + "c1a cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in p2\\c2.java (at line 6)\n" + + " myC1a = new c1a(); \n" + + " ^^^^^\n" + + "c1a cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in p2\\c2.java (at line 6)\n" + + " myC1a = new c1a(); \n" + + " ^^^\n" + + "c1a cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in p2\\c2.java (at line 7)\n" + + " myC1a.foo(); \n" + + " ^^^^^\n" + + "c1a cannot be resolved to a type\n" + + "----------\n"); +} +/** + * Compatibility - Compiler does not comply with 1.1 standard. + */ +public void test031() { + this.runNegativeTest( + new String[] { + /* Test.java */ + "p2/Test.java", + "package p2; \n"+ + "public class Test { \n"+ + " public static void main (String args[]){ \n"+ + " new c2(); \n"+ + " } \n"+ + "} \n", + /* c1.java */ + "p1/c1.java", + "package p1; \n"+ + "public class c1 { \n"+ + " protected class c1a{ \n"+ + " public c1a(){} \n"+ + " public void foo(){ System.out.println(\"Foo called\"); \n"+ + " } \n"+ + " }; \n"+ + "} \n", + /* c2.java */ + "p2/c2.java", + "package p2; \n"+ + "import p1.c1.*; \n"+ + "public class c2 extends c1a { \n"+ + " public c1a myC1a; \n"+ + " { \n"+ + " myC1a = new c1a(); \n"+ + " myC1a.foo(); \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in p2\\c2.java (at line 3)\n" + + " public class c2 extends c1a { \n" + + " ^^^\n" + + "The type c1a is not visible\n" + + "----------\n" + + "2. ERROR in p2\\c2.java (at line 4)\n" + + " public c1a myC1a; \n" + + " ^^^\n" + + "The type c1a is not visible\n" + + "----------\n" + + "3. ERROR in p2\\c2.java (at line 6)\n" + + " myC1a = new c1a(); \n" + + " ^^^\n" + + "The type c1a is not visible\n" + + "----------\n" + + "4. ERROR in p2\\c2.java (at line 7)\n" + + " myC1a.foo(); \n" + + " ^^^^^\n" + + "The type c1.c1a is not visible\n" + + "----------\n"); +} +/** + * VerifyError using .class literal inside inner classes + */ +public void test032() { + this.runConformTest( + new String[] { + "p/A.java", + "package p; \n"+ + "public class A {\n" + + " public class B {\n" + + " public B() {\n" + + " }\n" + + " public Class getCls() {\n" + + " return A.class;\n" + + " }\n" + + " }\n" + + " public A() {\n" + + " super();\n" + + " B b = new B();\n" + + " System.out.println(\"Class: \" + b.getCls());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " A a = new A();\n" + + " }\n" + + "}\n" + }, + "Class: class p.A"); +} +/** + * Missing implementation in the compiler compiling invalid code + */ +public void test033() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in p1\\A2.java (at line 20)\n" + + " (new D.E(null, null, null, new F(get()) {}) {}).execute(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type D is accessible. Must qualify the allocation with an enclosing instance of type D (e.g. x.new A() where x is an instance of D).\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in p1\\A2.java (at line 18)\n" + + " private class C extends B { \n" + + " ^\n" + + "Access to enclosing constructor A2.B() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in p1\\A2.java (at line 20)\n" + + " (new D.E(null, null, null, new F(get()) {}) {}).execute(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type D is accessible. Must qualify the allocation with an enclosing instance of type D (e.g. x.new A() where x is an instance of D).\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + /* A2.java */ + "p1/A2.java", + "package p1; \n"+ + "class D { \n"+ + " class E { \n"+ + " E(Object o, Object o1, Object o2, F f) {} \n"+ + " void execute() {} \n"+ + " } \n"+ + "} \n"+ + "class F { \n"+ + " F(Object o) { \n"+ + " } \n"+ + "} \n"+ + "public class A2 { \n"+ + " private abstract class B { \n"+ + " public Object get() { \n"+ + " return null; \n"+ + " } \n"+ + " } \n"+ + " private class C extends B { \n"+ + " public void foo() { \n"+ + " (new D.E(null, null, null, new F(get()) {}) {}).execute(); \n"+ + " } \n"+ + " } \n"+ + "}\n" + }, + errMessage); +} +/** + * Missing implementation in the compiler compiling invalid code + */ +public void test034() { + this.runConformTest( + new String[] { + /* A2.java */ + "p1/A2.java", + "package p1; \n"+ + "class D { \n"+ + " class E { \n"+ + " E(Object o, Object o1, Object o2, F f) {} \n"+ + " void execute() {} \n"+ + " } \n"+ + "} \n"+ + "class F { \n"+ + " F(Object o) { \n"+ + " } \n"+ + "} \n"+ + "public class A2 { \n"+ + " private abstract class B { \n"+ + " public Object get() { \n"+ + " return null; \n"+ + " } \n"+ + " } \n"+ + " private class C extends B { \n"+ + " public void foo() { \n"+ + " (new D().new E(null, null, null, new F(get()) {}) {}).execute(); \n"+ + " } \n"+ + " } \n"+ + " public static void main(String[] argv){ \n"+ + " new A2().new C().foo(); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} +/** + * Missing implementation in the compiler compiling invalid code + */ +public void test035() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in p1\\A2.java (at line 20)\n" + + " (new D.E(null, null, null, new F(get()) {})).execute(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type D is accessible. Must qualify the allocation with an enclosing instance of type D (e.g. x.new A() where x is an instance of D).\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in p1\\A2.java (at line 18)\n" + + " private class C extends B { \n" + + " ^\n" + + "Access to enclosing constructor A2.B() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in p1\\A2.java (at line 20)\n" + + " (new D.E(null, null, null, new F(get()) {})).execute(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type D is accessible. Must qualify the allocation with an enclosing instance of type D (e.g. x.new A() where x is an instance of D).\n" + + "----------\n"; + this.runNegativeTest(new String[] { + /* A2.java */ + "p1/A2.java", + "package p1; \n"+ + "class D { \n"+ + " class E { \n"+ + " E(Object o, Object o1, Object o2, F f) {} \n"+ + " void execute() {} \n"+ + " } \n"+ + "} \n"+ + "class F { \n"+ + " F(Object o) { \n"+ + " } \n"+ + "} \n"+ + "public class A2 { \n"+ + " private abstract class B { \n"+ + " public Object get() { \n"+ + " return null; \n"+ + " } \n"+ + " } \n"+ + " private class C extends B { \n"+ + " public void foo() { \n"+ + " (new D.E(null, null, null, new F(get()) {})).execute(); \n"+ + " } \n"+ + " } \n"+ + "}\n"}, + errMessage); +} +/** + * ClassCastException during inner class emulation + */ +public void test036() { + this.runConformTest( + new String[] { + /* A.java */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " public static void main(String[] argv){ \n"+ + " new A().foo(); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " public Object foo() { \n"+ + " B b = new B() { \n"+ + " protected Object bar() { \n"+ + " return new B.C() {}; \n"+ + " } \n"+ + " }; \n"+ + " return b; \n"+ + " } \n"+ + "} \n"+ + "class B { \n"+ + " class C { \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} +/** + * ClassCastException during inner class emulation + */ +public void test037() { + this.runConformTest( + new String[] { + /* A.java */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " public static void main(String[] argv){ \n"+ + " new A().foo(); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " public Object foo() { \n"+ + " I i = new I() { \n"+ + " protected Object bar() { \n"+ + " return new I.C() {}; \n"+ + " } \n"+ + " }; \n"+ + " return i; \n"+ + " } \n"+ + "} \n"+ + "interface I { \n"+ + " class C { \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} + +/** + * Enclosing instance comparison + */ +public void test038() { + this.runConformTest( + new String[] { + /* X.java */ + "X.java", + "public class X { \n"+ + " public static void main(String argv[]) { \n"+ + " if (new X().foo()) \n"+ + " System.out.println(\"FAILED\"); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " boolean bar() { \n"+ + " return false; \n"+ + " } \n"+ + " boolean foo() { \n"+ + " X x = new X() { \n"+ + " boolean test() { \n"+ + " return (X.this == this); \n"+ + " } \n"+ + " }; \n"+ + " return x.bar(); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test039() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected void foo() { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " Y.this.foo(); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test040() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected void foo() { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " new Y().foo(); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test041() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected void foo() { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " Y.super.foo(); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test042() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"SUCCESS\"; \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.println(Y.super.foo); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test043() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"SUCCESS\"; \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.println(Y.this.foo); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test044() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"SUCCESS\"; \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.println(new Y().foo); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test045() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"SUCCESS\"; \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.println(foo); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test046() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"SUCCESS\"; \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " Y someY; \n"+ + " public void bar() { \n"+ + " someY = this; \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.println(someY.foo); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test047() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"FAILED\"; \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.println(Y.super.foo = \"SUCCESS\"); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test048() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"FAILED\"; \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.println(Y.this.foo = \"SUCCESS\"); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test049() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"FAILED\"; \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.println(new Y().foo = \"SUCCESS\"); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test050() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"FAILED\"; \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.println(foo = \"SUCCESS\"); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=6456 + * Invalid error when compiling access to protected member inside innerclass + */ +public void test051() { + this.runConformTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"FAILED\"; \n"+ + " public static void main(String argv[]) { \n"+ + " new p2.Y().bar(); \n"+ + " } \n"+ + "} \n", + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y extends p1.X { \n"+ + " Y someY; \n"+ + " public void bar() { \n"+ + " someY = this; \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.println(someY.foo = \"SUCCESS\"); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + + +public void test052() { + this.runConformTest( + new String[] { + /* p2/Y.java */ + "p2/Y.java", + "package p2; \n"+ + "public class Y { \n"+ + " void bar(final int someVal){ \n"+ + " class Local { \n"+ + " void localDo(final int localVal){ \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " System.out.print(someVal + localVal); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + " }; \n"+ + " Local loc = new Local(); \n"+ + " loc.localDo(8); \n"+ + " class SubLocal extends Local { \n"+ + " void localDo(final int localVal){ \n"+ + " super.localDo(localVal + 1); \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n"+ + " SubLocal.super.localDo(localVal + 2); \n"+ + " System.out.print(someVal + localVal + 3); \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + " }; \n"+ + " SubLocal subloc = new SubLocal(); \n"+ + " subloc.localDo(8); \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new Y().bar(4); \n"+ + " System.out.println(); \n"+ + " } \n"+ + "} \n", + }, + "12131415" + ); +} + +public void test053() { + this.runConformTest( + new String[] { + /* p2/Z.java */ + "p2/Z.java", + "package p2; \n"+ + "import p1.X; \n"+ + "public class Z { \n"+ + " class ZMember extends X { \n"+ + " ZMember(Object o){} \n"+ + " Z bar(){ \n"+ + " System.out.println(foo = \"FAILED\"); \n"+ + " return Z.this; \n"+ + " } \n"+ + " } \n"+ + " Z(final Object foo){ \n"+ + " Object obj2 = new Object(){ \n"+ + " Object doSomething(){ \n"+ + " ZMember obj3 = new ZMember(foo){ \n"+ + " Z bar(){ \n"+ + " System.out.println(this.foo); \n"+ + " return Z.this; \n"+ + " } \n"+ + " }; \n"+ + " obj3.bar(); \n"+ + " return this; \n"+ + " } \n"+ + " }.doSomething(); \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new Z(new Object()); \n"+ + " } \n"+ + "} \n", + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected String foo = \"SUCCESS\"; \n"+ + "} \n" + }, + "SUCCESS" + ); +} +public void test055() { + this.runNegativeTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " void foo() { \n"+ + " class L1 { \n"+ + " class LM1 { \n"+ + " } \n"+ + " } \n"+ + " class L2 extends L1.LM1 { \n"+ + " } \n"+ + " new L2(); \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().foo(); \n"+ + " } \n"+ + "} \n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 8)\n" + + " class L2 extends L1.LM1 { \n" + + " ^^\n" + + "No enclosing instance of type L1 is accessible to invoke the super constructor. Must define a constructor and explicitly qualify its super constructor invocation with an instance of L1 (e.g. x.super() where x is an instance of L1).\n" + + "----------\n" + + ); +} + +public void test056() { + this.runNegativeTest( + new String[] { + /* p1/X.java */ + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " void foo() { \n"+ + " class L1 { \n"+ + " class LM1 { \n"+ + " } \n"+ + " } \n"+ + " new L1().new LM1(){}; //ok\n"+ + " new L1.LM1(){}; //ko\n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().foo(); \n"+ + " } \n"+ + "} \n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 9)\n" + + " new L1.LM1(){}; //ko\n" + + " ^^^^^^^^^^^^^^\n" + + "No enclosing instance of type L1 is accessible. Must qualify the allocation with an enclosing instance of type L1 (e.g. x.new A() where x is an instance of L1).\n" + + "----------\n" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=9813 + * VerifyError with Inner Class having private constructor + */ +public void test057() { + this.runConformTest( + new String[] { + /* VE_Test.java */ + "VE_Test.java", + "public class VE_Test { \n"+ + " class VE_Inner { \n"+ + " private VE_Inner() {} \n"+ + " } \n"+ + " private static void test(){ \n"+ + " VE_Test ve_test = new VE_Test(); \n"+ + " VE_Inner pi = ve_test.new VE_Inner(); \n"+ + " } \n"+ + " public static void main(String[] args){ \n"+ + " new VE_Test(); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=11845 + * NPE during emulation + */ +public void test058() { + this.runConformTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "import p2.A; \n"+ + "public class Test { \n"+ + " public static void main(String[] args){ \n"+ + " new Test().a.bar(); \n"+ + " } \n"+ + " private A a = new A() { \n"+ + " public void bar() { \n"+ + " new Object() { \n"+ + " protected void foo() { \n"+ + " init(); \n"+ + " } \n"+ + " }.foo(); \n"+ + " } \n"+ + " }; \n"+ + " private void init() { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n" + + "} \n", + "p2/A.java", + "package p2; \n"+ + "public class A { \n"+ + " public void bar() { \n"+ + " } \n"+ + " private void init() { \n"+ + " System.out.println(\"FAILED\"); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=11845 + * variant for single name ref + */ +public void test059() { + this.runConformTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "import p2.A; \n"+ + "public class Test { \n"+ + " public static void main(String[] args){ \n"+ + " new Test().a.bar(); \n"+ + " } \n"+ + " private A a = new A() { \n"+ + " public void bar() { \n"+ + " new Object() { \n"+ + " protected void foo() { \n"+ + " System.out.println(init); \n"+ + " } \n"+ + " }.foo(); \n"+ + " } \n"+ + " }; \n"+ + " private String init = \"SUCCESS\"; \n"+ + "} \n", + "p2/A.java", + "package p2; \n"+ + "public class A { \n"+ + " public void bar() { \n"+ + " } \n"+ + " private String init = \"FAILED\"; \n"+ + "} \n" + }, + "SUCCESS" + ); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=11845 + * variant for qualified name ref + */ +public void test060() { + this.runConformTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "import p2.A; \n"+ + "public class Test { \n"+ + " public static void main(String[] args){ \n"+ + " new Test().a.bar(); \n"+ + " } \n"+ + " private A a = new A() { \n"+ + " public void bar() { \n"+ + " class L { \n"+ + " Test next = Test.this; \n"+ + " protected void foo() { \n"+ + " System.out.println(next.init); \n"+ + " } \n"+ + " }; \n" + + " new L().foo(); \n"+ + " } \n"+ + " }; \n"+ + " private String init = \"SUCCESS\"; \n"+ + "} \n", + "p2/A.java", + "package p2; \n"+ + "public class A { \n"+ + " public void bar() { \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=11845 + * variant for field name ref + */ +public void test061() { + this.runConformTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "import p2.A; \n"+ + "public class Test { \n"+ + " public static void main(String[] args){ \n"+ + " new Test().a.bar(); \n"+ + " } \n"+ + " private A a = new A() { \n"+ + " public void bar() { \n"+ + " class L { \n"+ + " protected void foo() { \n"+ + " System.out.println(Test.this.init); \n"+ + " } \n"+ + " }; \n" + + " new L().foo(); \n"+ + " } \n"+ + " }; \n"+ + " private String init = \"SUCCESS\"; \n"+ + "} \n", + "p2/A.java", + "package p2; \n"+ + "public class A { \n"+ + " public void bar() { \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} + +public void test062() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " public static void main(String args[]) { \n"+ + " final String s = args.length == 0 ? \"SUCCESS\" : null; \n"+ + " final class Local { \n"+ + " private Local() { \n"+ + " new LocalMember(); \n"+ + " } \n"+ + " class LocalMember { \n"+ + " { \n"+ + " new LocalMemberMember(); \n"+ + " } \n"+ + " class LocalMemberMember { \n"+ + " { \n"+ + " System.out.println(s); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + " new Local(); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} + +public void test062a() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " public static void main(String args[]) { \n"+ + " final String s = \"SUCCESS\";\n"+ + " final class Local { \n"+ + " Local() { \n"+ + " new LocalMember(); \n"+ + " } \n"+ + " class LocalMember { \n"+ + " { \n"+ + " new LocalMemberMember(); \n"+ + " } \n"+ + " class LocalMemberMember { \n"+ + " { \n"+ + " System.out.println(s); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + " new Local(); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} + +public void test063() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " String a = new Object(){ \n"+ + " class LocalMember { \n"+ + " String s = \"SUCCESS\"; \n"+ + " }; \n"+ + " String get_a(){ \n"+ + " return new LocalMember().s; \n"+ + " } \n"+ + " }.get_a(); \n"+ + " public static void main(String argv[]) { \n"+ + " System.out.println(new X().a); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=21447 + * should invoke Y.foo() at runtime + */ +public void test064(){ + this.runConformTest( + new String[] { + "p2/Y.java", + "package p2; \n"+ + "public class Y extends T { \n"+ + " public static void main(String argv[]) { \n"+ + " new Y().bar(); \n"+ + " } \n"+ + " protected void foo() { \n"+ + " System.out.println(\"Y.foo()\"); \n"+ + " } \n"+ + "} \n", + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected void foo() { \n"+ + " System.out.println(\"X.foo()\"); \n"+ + " } \n"+ + "} \n", + "p2/T.java", + "package p2; \n"+ + "public class T extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n" + + " T.this.foo(); \n"+ + " } \n" + + " }.doSomething(); \n" + + " } \n"+ + "} \n", + }, + "Y.foo()" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=21447 + * variation - if T.foo() is defined + */ +public void test065(){ + this.runConformTest( + new String[] { + "p2/Y.java", + "package p2; \n"+ + "public class Y extends T { \n"+ + " public static void main(String argv[]) { \n"+ + " new Y().bar(); \n"+ + " } \n"+ + " protected void foo() { \n"+ + " System.out.println(\"Y.foo()\"); \n"+ + " } \n"+ + "} \n", + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected void foo() { \n"+ + " System.out.println(\"X.foo()\"); \n"+ + " } \n"+ + "} \n", + "p2/T.java", + "package p2; \n"+ + "public class T extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n" + + " T.this.foo(); \n"+ + " } \n" + + " }.doSomething(); \n" + + " } \n"+ + " protected void foo() { \n"+ + " System.out.println(\"T.foo()\"); \n"+ + " } \n"+ + "} \n", + }, + "Y.foo()" + ); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=21447 + * should invoke Y.foo() and X.foo() at runtime (through 2 separate access methods) + */ +public void test066(){ + this.runConformTest( + new String[] { + "p2/Y.java", + "package p2; \n"+ + "public class Y extends T { \n"+ + " public static void main(String argv[]) { \n"+ + " new Y().bar(); \n"+ + " } \n"+ + " protected void foo() { \n"+ + " System.out.print(\"Y.foo()-\"); \n"+ + " } \n"+ + "} \n", + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " protected void foo() { \n"+ + " System.out.println(\"X.foo()\"); \n"+ + " } \n"+ + "} \n", + "p2/T.java", + "package p2; \n"+ + "public class T extends p1.X { \n"+ + " public void bar() { \n"+ + " new Object(){ \n"+ + " void doSomething(){ \n" + + " T.this.foo(); \n"+ + " T.super.foo(); //need extra access method \n"+ + " } \n" + + " }.doSomething(); \n" + + " } \n"+ + "} \n", + }, + "Y.foo()-X.foo()" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=22093 + * test collision check for synthetic accessors to constructors + */ +public void test067(){ + this.runConformTest( + new String[] { + "p/Test.java", + "package p; \n"+ + "public class Test { \n"+ + " class Member { \n"+ + " private Member(){ \n"+ + " } \n"+ + " private Member(Member other){ \n"+ + " } \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " Test t = new Test(); \n"+ + " Member m1 = t.new Member(); \n"+ + " t.new Member(m1); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=25229 +public void test068(){ + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new X2().foo(); \n"+ + " } \n"+ + " class X1 { \n"+ + " void baz1() { \n"+ + " System.out.print(\"-X1.baz1()\"); \n"+ + " } \n"+ + " } \n"+ + " class X2 { \n"+ + " void foo(){ \n"+ + " X.this.new X1(){ \n"+ + " void bar(){ \n"+ + " baz(); \n"+ + " baz1(); \n"+ + " baz2(); \n"+ + " } \n"+ + " }.bar(); \n"+ + " } \n"+ + " void baz2() { \n"+ + " System.out.println(\"-X2.baz2()\"); \n"+ + " } \n"+ + " } \n"+ + " void baz() { \n"+ + " System.out.print(\"X.baz()\"); \n"+ + " } \n"+ + "} \n" + }, + "X.baz()-X1.baz1()-X2.baz2()"); +} + +// http://bugs.eclipse.org/bugs/show_bug.cgi?id=26122 +// synthetic outer local variables must be appended after user arguments +public void test069() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " X(String s, int j) {} \n"+ + " public static void main(String[] args) { \n"+ + " final int i; \n"+ + " new X(\"hello\", i = 1) { \n"+ // val$i must be appended after i got assigned + " { \n"+ + " System.out.print(\"SUCCESS:\"+i); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS:1"); +} +// variation on test069 +public void test070() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " X() {} \n"+ + " public static void main(String[] args) { \n"+ + " final int i; \n"+ + " new X().new Y(\"hello\", i = 1) { \n"+ // val$i must be appended after i got assigned + " { \n"+ + " System.out.print(\"SUCCESS:\"+i); \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " class Y { \n" + + " Y(String s, int j) {} \n" + + " } \n" + + "} \n" + }, + "SUCCESS:1"); +} + +// test too many synthetic arguments +public void test071() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " void foo(int i) { \n"+ + " final long v0 = i, v1 = i, v2 = i, v3 = i, v4 = i, v5 = i, v6 = i; \n"+ + " final long v7 = i, v8 = i, v9 = i, v10 = i, v11 = i, v12 = i, v13 = i; \n"+ + " final long v14 = i, v15 = i, v16 = i, v17 = i, v18 = i, v19 = i, v20 = i; \n"+ + " final long v21 = i, v22 = i, v23 = i, v24 = i, v25 = i, v26 = i, v27 = i; \n"+ + " final long v28 = i, v29 = i, v30 = i, v31 = i, v32 = i, v33 = i, v34 = i; \n"+ + " final long v35 = i, v36 = i, v37 = i, v38 = i, v39 = i, v40 = i, v41 = i; \n"+ + " final long v42 = i, v43 = i, v44 = i, v45 = i, v46 = i, v47 = i, v48 = i; \n"+ + " final long v49 = i, v50 = i, v51 = i, v52 = i, v53 = i, v54 = i, v55 = i; \n"+ + " final long v56 = i, v57 = i, v58 = i, v59 = i, v60 = i, v61 = i, v62 = i; \n"+ + " final long v63 = i, v64 = i, v65 = i, v66 = i, v67 = i, v68 = i, v69 = i; \n"+ + " final long v70 = i, v71 = i, v72 = i, v73 = i, v74 = i, v75 = i, v76 = i; \n"+ + " final long v77 = i, v78 = i, v79 = i, v80 = i, v81 = i, v82 = i, v83 = i; \n"+ + " final long v84 = i, v85 = i, v86 = i, v87 = i, v88 = i, v89 = i, v90 = i; \n"+ + " final long v91 = i, v92 = i, v93 = i, v94 = i, v95 = i, v96 = i, v97 = i; \n"+ + " final long v98 = i, v99 = i, v100 = i, v101 = i, v102 = i, v103 = i, v104 = i; \n"+ + " final long v105 = i, v106 = i, v107 = i, v108 = i, v109 = i, v110 = i, v111 = i; \n"+ + " final long v112 = i, v113 = i, v114 = i, v115 = i, v116 = i, v117 = i, v118 = i; \n"+ + " final long v119 = i, v120 = i, v121 = i, v122 = i, v123 = i, v124 = i, v125 = i; \n"+ + " final long v126 = i; \n"+ + " final int v127 = i; // int is already too many arg \n"+ + " new X() { \n"+ + " { \n"+ + " System.out.println( \n"+ + " v0 + v1 + v2 + v3 + v4 + v5 + v6 \n" + + " + v7 + v8 + v9 + v10 + v11 + v12 + v13 \n" + + " + v14 + v15 + v16 + v17 + v18 + v19 + v20 \n" + + " + v21 + v22 + v23 + v24 + v25 + v26 + v27 \n" + + " + v28 + v29 + v30 + v31 + v32 + v33 + v34 \n" + + " + v35 + v36 + v37 + v38 + v39 + v40 + v41 \n" + + " + v42 + v43 + v44 + v45 + v46 + v47 + v48 \n" + + " + v49 + v50 + v51 + v52 + v53 + v54 + v55 \n" + + " + v56 + v57 + v58 + v59 + v60 + v61 + v62 \n" + + " + v63 + v64 + v65 + v66 + v67 + v68 + v69 \n" + + " + v70 + v71 + v72 + v73 + v74 + v75 + v76 \n" + + " + v77 + v78 + v79 + v80 + v81 + v82 + v83 \n" + + " + v84 + v85 + v86 + v87 + v88 + v89 + v90 \n" + + " + v91 + v92 + v93 + v94 + v95 + v96 + v97 \n" + + " + v98 + v99 + v100 + v101 + v102 + v103 + v104 \n" + + " + v105 + v106 + v107 + v108 + v109 + v110 + v111 \n" + + " + v112 + v113 + v114 + v115 + v116 + v117 + v118 \n" + + " + v119 + v120 + v121 + v122 + v123 + v124 + v125 \n" + + " + v126); \n"+ + " } \n"+ + " }; \n"+ + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 23)\n" + + " new X() { \n" + + " ^^^\n" + + "Too many synthetic parameters, emulated parameter val$v126 is exceeding the limit of 255 words eligible for method parameters\n" + + "----------\n", + JavacTestOptions.SKIP /* javac simply does not catch this case */); +} + +// test too many synthetic arguments +public void test072() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " void foo(int i) { \n"+ + " final long v0 = i, v1 = i, v2 = i, v3 = i, v4 = i, v5 = i, v6 = i; \n"+ + " final long v7 = i, v8 = i, v9 = i, v10 = i, v11 = i, v12 = i, v13 = i; \n"+ + " final long v14 = i, v15 = i, v16 = i, v17 = i, v18 = i, v19 = i, v20 = i; \n"+ + " final long v21 = i, v22 = i, v23 = i, v24 = i, v25 = i, v26 = i, v27 = i; \n"+ + " final long v28 = i, v29 = i, v30 = i, v31 = i, v32 = i, v33 = i, v34 = i; \n"+ + " final long v35 = i, v36 = i, v37 = i, v38 = i, v39 = i, v40 = i, v41 = i; \n"+ + " final long v42 = i, v43 = i, v44 = i, v45 = i, v46 = i, v47 = i, v48 = i; \n"+ + " final long v49 = i, v50 = i, v51 = i, v52 = i, v53 = i, v54 = i, v55 = i; \n"+ + " final long v56 = i, v57 = i, v58 = i, v59 = i, v60 = i, v61 = i, v62 = i; \n"+ + " final long v63 = i, v64 = i, v65 = i, v66 = i, v67 = i, v68 = i, v69 = i; \n"+ + " final long v70 = i, v71 = i, v72 = i, v73 = i, v74 = i, v75 = i, v76 = i; \n"+ + " final long v77 = i, v78 = i, v79 = i, v80 = i, v81 = i, v82 = i, v83 = i; \n"+ + " final long v84 = i, v85 = i, v86 = i, v87 = i, v88 = i, v89 = i, v90 = i; \n"+ + " final long v91 = i, v92 = i, v93 = i, v94 = i, v95 = i, v96 = i, v97 = i; \n"+ + " final long v98 = i, v99 = i, v100 = i, v101 = i, v102 = i, v103 = i, v104 = i; \n"+ + " final long v105 = i, v106 = i, v107 = i, v108 = i, v109 = i, v110 = i, v111 = i; \n"+ + " final long v112 = i, v113 = i, v114 = i, v115 = i, v116 = i, v117 = i, v118 = i; \n"+ + " final long v119 = i, v120 = i, v121 = i, v122 = i, v123 = i, v124 = i, v125 = i; \n"+ + " new X() { \n"+ + " { \n"+ + " System.out.println( \n"+ + " v0 + v1 + v2 + v3 + v4 + v5 + v6 \n" + + " + v7 + v8 + v9 + v10 + v11 + v12 + v13 \n" + + " + v14 + v15 + v16 + v17 + v18 + v19 + v20 \n" + + " + v21 + v22 + v23 + v24 + v25 + v26 + v27 \n" + + " + v28 + v29 + v30 + v31 + v32 + v33 + v34 \n" + + " + v35 + v36 + v37 + v38 + v39 + v40 + v41 \n" + + " + v42 + v43 + v44 + v45 + v46 + v47 + v48 \n" + + " + v49 + v50 + v51 + v52 + v53 + v54 + v55 \n" + + " + v56 + v57 + v58 + v59 + v60 + v61 + v62 \n" + + " + v63 + v64 + v65 + v66 + v67 + v68 + v69 \n" + + " + v70 + v71 + v72 + v73 + v74 + v75 + v76 \n" + + " + v77 + v78 + v79 + v80 + v81 + v82 + v83 \n" + + " + v84 + v85 + v86 + v87 + v88 + v89 + v90 \n" + + " + v91 + v92 + v93 + v94 + v95 + v96 + v97 \n" + + " + v98 + v99 + v100 + v101 + v102 + v103 + v104 \n" + + " + v105 + v106 + v107 + v108 + v109 + v110 + v111 \n" + + " + v112 + v113 + v114 + v115 + v116 + v117 + v118 \n" + + " + v119 + v120 + v121 + v122 + v123 + v124 + v125); \n" + + " } \n"+ + " }; \n"+ + " } \n" + + " public static void main(String[] args) { \n"+ + " System.out.print(\"SUCCESS\"); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS"); +} + +/** + * verify error in synthetic access to constructor + * (ordering of parameters after moving outerlocals after user args) + */ +public void test073() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(final String[] args) { \n" + + " class Local { \n" + + " private Local(String str){ \n" + + " Object o = args; \n" + + " System.out.println(str); \n" + + " } \n" + + " }; \n" + + " new Local(\"SUCCESS\"); \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); +} + +/** + * verify error in synthetic access to constructor - test collisions + * (ordering of parameters after moving outerlocals after user args) + */ +public void test074() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(final String[] args) { \n" + + " class Local { \n" + + " public Local(String str, Local loc, String str2){ \n" + // collision + " } \n" + + " public Local(String str, Local loc){ \n" + // collision + " } \n" + + " private Local(String str){ \n" + + " Object o = args; \n" + + " System.out.println(str); \n" + + " } \n" + + " }; \n" + + " new Local(\"SUCCESS\"); \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); +} + +/** + * should not consider synthetic methods on binary types + */ +public void test075() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(final String[] args) { \n" + + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + " private static void foo() { \n" + + " } \n" + + " A a = new A(); \n" + + " class A { \n" + + " private A() {} \n" + + " A(String s) { \n" + + " foo(); \n" + + " } \n" + + " A(int s) { \n" + + " foo(); \n" + + " } \n" + + " } \n" + + " class B extends A { \n" + + " B(){ \n" + + " super(); \n" + + " } \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); + + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y { \n" + + " void foo(){ \n" + + " new X().new A(null); \n" + + " new X().access$0(); \n" + + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 4)\n" + + " new X().access$0(); \n" + + " ^^^^^^^^\n" + + "The method access$0() is undefined for the type X\n" + + "----------\n", + null, // use default class-path + false); // do not flush previous output dir content + +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=27413 + * implicit enclosing instances + */ +public void test076() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel <= ClassFileConstants.JDK1_3) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " X(Object o){ \n"+ + " class A { \n"+ + " private A() { \n"+ // implicit enclosing instance in non-static context + " } \n"+ + " } \n"+ + " class B extends X { \n"+ + " B() { \n"+ + " super(new A(){ \n"+ + " }); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " super(new A(){ \n" + + " }); \n" + + " ^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " super(new A(){ \n" + + " ^^^\n" + + "Access to enclosing constructor A() is emulated by a synthetic accessor method\n" + + "----------\n"); + return; + } + if (options.sourceLevel <= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " X(Object o){ \n"+ + " class A { \n"+ + " private A() { \n"+ // implicit enclosing instance in non-static context + " } \n"+ + " } \n"+ + " class B extends X { \n"+ + " B() { \n"+ + " super(new A(){ \n"+ + " }); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " super(new A(){ \n" + + " }); \n" + + " ^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " X(Object o){ \n"+ + " class A { \n"+ + " private A() { \n"+ // implicit enclosing instance in non-static context + " } \n"+ + " } \n"+ + " class B extends X { \n"+ + " B() { \n"+ + " super(new A(){ \n"+ + " }); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + ""); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=27413 + * implicit enclosing instances + */ +public void test077() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] args){ \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n" + + " X(Object o){ \n"+ + " } \n" + + " static void foo() { \n"+ + " class A { \n"+ // no implicit enclosing in STATIC context + " private A() { \n"+ + " } \n"+ + " } \n"+ + " class B extends X { \n"+ + " B() { \n"+ + " super(new A(){ \n"+ + " }); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=27413 + * implicit enclosing instances + */ +public void test078() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel <= ClassFileConstants.JDK1_3) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " X(Object o){ \n"+ + " class A { \n"+ + " private A() { \n"+ // implicit enclosing instance in non-static context + " } \n"+ + " } \n"+ + " class B extends X { \n"+ + " B() { \n"+ + " super(new A(){ \n"+ + " void foo() { System.out.println(X.this); } \n"+ + " }); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " super(new A(){ \n" + + " void foo() { System.out.println(X.this); } \n" + + " }); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " super(new A(){ \n" + + " ^^^\n" + + "Access to enclosing constructor A() is emulated by a synthetic accessor method\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " void foo() { System.out.println(X.this); } \n" + + " ^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); + return; + } + if (options.sourceLevel <= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " X(Object o){ \n"+ + " class A { \n"+ + " private A() { \n"+ // implicit enclosing instance in non-static context + " } \n"+ + " } \n"+ + " class B extends X { \n"+ + " B() { \n"+ + " super(new A(){ \n"+ + " void foo() { System.out.println(X.this); } \n"+ + " }); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " super(new A(){ \n" + + " void foo() { System.out.println(X.this); } \n" + + " }); \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 10)\n" + + " void foo() { System.out.println(X.this); } \n" + + " ^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " X(Object o){ \n"+ + " class A { \n"+ + " private A() { \n"+ // implicit enclosing instance in non-static context + " } \n"+ + " } \n"+ + " class B extends X { \n"+ + " B() { \n"+ + " super(new A(){ \n"+ + " void foo() { System.out.println(X.this); } \n"+ + " }); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + ""); +} + +/* + * Check that X.this is actually bound to an X, and not innermost compatible type (Z) + */ +public void test079() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new Y().new Z().bar(); \n"+ + " } \n"+ + " String foo() { return \"X-foo\"; } \n"+ + " class Y extends X { \n"+ + " String foo() { return \"Y-foo\"; } \n"+ + " class Z extends Y { \n"+ + " Z(){ \n"+ + " X.this.super(); \n"+ + " } \n"+ + " String foo() { return \"Z-foo\"; } \n"+ + " void bar () { \n"+ + " System.out.println(X.this.foo()); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + "X-foo"); +} + +public void test080() { // verified as conform + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new C(); \n"+ + " } \n"+ + " int m() { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " return 1; \n"+ + " } \n"+ + " class C extends B { \n"+ + " C(int j){} \n"+ + " C(){ \n"+ + " this(X.this.m()); \n"+ + " } \n"+ + " } \n"+ + "} \n"+ + "class B extends X { \n"+ + "} \n" + }, + "SUCCESS"); +} + +public void test081() { + this.runConformTest( + new String[] { + "p/X.java", + "package p; \n"+ + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new C(); \n"+ + " } \n"+ + " int m() { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " return 1; \n"+ + " } \n"+ + " class C extends q.B { \n"+ + " C(int j){} \n"+ + " C(){ \n"+ + " this(m()); \n"+ // only X.this can see m() + " } \n"+ + " } \n"+ + "} \n", + "q/B.java", + "package q; \n"+ + "public class B extends p.X { \n"+ + "} \n" + }, + "SUCCESS"); +} + +/* + * Default constructor for Z, will use enclosing 'this' as default-value for enclosing instance for super(). + */ +public void test083() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new Y().new Z().bar(); \n"+ + " } \n"+ + " String foo() { return \"X-foo\"; } \n"+ + " class Y extends X { \n"+ + " String foo() { return \"Y-foo\"; } \n"+ + " class Z { \n"+ + " Z(){ \n"+ + " //X.this.super(); \n"+ + " } \n"+ + " String foo() { return \"Z-foo\"; } \n"+ + " void bar () { \n"+ + " System.out.println(X.this.foo()); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + "} \n" + }, + "X-foo"); +} + +public void test084() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Foo(null); \n"+ + " } \n"+ + " Foo(int i){} \n"+ + " Foo(Object o){ \n"+ + " class A { \n"+ + " private A() { \n"+ + " } \n"+ + " } \n"+ + " class B extends Foo { \n"+ + " B() { \n"+ + " super(0); \n"+ + " new A(){ \n"+ + " void foo() { \n"+ + " System.out.println(Foo.this.getClass().getName()); \n"+ + " } \n"+ + " }.foo(); \n"+ + " } \n"+ + " } \n"+ + " new B(); \n"+ + " } \n"+ + "} \n", + }, + "Foo"); +} + +public void test085() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " int m() { \n"+ + " return 1; \n"+ + " } \n"+ + " class C extends B { \n"+ + " C(int j){} \n"+ + " C(){ \n"+ + " this( \n"+ + " new B(){ \n"+ + " X x = X.this; \n"+ + " int m(){ \n"+ + " return 1; \n"+ + " } \n"+ + " }.m()); \n"+ + " } \n"+ + " } \n"+ + "} \n"+ + "class B extends X { \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " X x = X.this; \n" + + " ^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " int m() { \n"+ + " return 1; \n"+ + " } \n"+ + " class C extends B { \n"+ + " C(int j){} \n"+ + " C(){ \n"+ + " this( \n"+ + " new B(){ \n"+ + " X x = X.this; \n"+ + " int m(){ \n"+ + " return 1; \n"+ + " } \n"+ + " }.m()); \n"+ + " } \n"+ + " } \n"+ + "} \n"+ + "class B extends X { \n"+ + "} \n" + }, + ""); +} + +public void test086() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new C(); \n"+ + " } \n"+ + " int m() { \n"+ + " return 1; \n"+ + " } \n"+ + " class C extends B { \n"+ + " C(int j){} \n"+ + " C(){ \n"+ + " this( \n"+ + " new B(){ \n"+ + " int m(){ \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " return 1; \n"+ + " } \n"+ + " }.m()); \n"+ + " } \n"+ + " } \n"+ + "} \n"+ + "class B extends X { \n"+ + "} \n" + }, + "SUCCESS"); +} + +public void test087() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.complianceLevel <= ClassFileConstants.JDK1_4) { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().f(); \n"+ + " } \n"+ + " void f () { \n"+ + " class C { \n"+ + " C() { \n"+ + " System.out.println(\"[\"+X.this.getClass().getName()+\"]\"); \n"+ + " } \n"+ + " } \n"+ + " class N extends X { \n"+ + " { new C(); } // selects N.this, not O.this \n"+ + " } \n"+ + " new N(); \n"+ + " } \n"+ + "} \n" + }, + "[X$1$N]"); + return; + } + this.runConformTest( + true, + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] arguments) {\n"+ + " new X().f();\n"+ + " }\n"+ + " void f () {\n"+ + " class C {\n"+ + " C() {\n"+ + " System.out.println(\"[\"+X.this.getClass().getName()+\"]\"); \n"+ + " }\n"+ + " }\n"+ + " class N extends X {\n"+ + " { new C(); } // selects N.this, not O.this \n"+ + " }\n"+ + " new N();\n"+ + " } \n"+ + "}\n" + }, + "", + "[X$1N]", // should be [X] indeed + "", + JavacTestOptions.EclipseHasABug.EclipseBug235809); +} + +public void test088() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " class Middle { \n"+ + " class Inner { \n"+ + " } \n"+ + " } \n"+ + " class M extends Middle.Inner { \n"+ + " } \n"+ + "} \n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " class M extends Middle.Inner { \n" + + " ^\n" + + "No enclosing instance of type X.Middle is accessible to invoke the super constructor. Must define a constructor and explicitly qualify its super constructor invocation with an instance of X.Middle (e.g. x.super() where x is an instance of X.Middle).\n" + + "----------\n"); +} + +public void test089() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " static class Middle { \n"+ + " static class Inner { \n"+ + " } \n"+ + " } \n"+ + " class M extends Middle.Inner { \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().new M(); \n" + + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS"); +} + +public void test090() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " void foo() { \n"+ + " class Middle { \n"+ + " class Inner { \n"+ + " } \n"+ + " } \n"+ + " class M extends Middle.Inner { \n"+ + " M() { \n"+ + " new Middle().super(); \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().foo(); \n" + + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "} \n" + }, + "SUCCESS"); +} + +// ensure that local member empty constructor gets implicit constructor call +public void test091() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " Object o = new Object() { \n"+ + " class Inner { \n"+ + " private Inner() {} \n"+ + " } \n"+ + " }.new Inner(){}; \n"+ + " public static void main(String[] arguments) { \n"+ + " new X(); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=29636 + * ensure first anonymous is X$1(extends X), last is X$2(extends A) + */ +public void test092() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " class A { \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " System.out.println(\"[\"+new X(){}.new A(){}.getClass().getName()+\"]\"); \n"+ + " } \n"+ + "} \n", + }, + "[X$2]"); +} + +public void test093() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] arguments) { \n"+ + " System.out.println(X.this); \n"+ + " } \n"+ + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(X.this); \n" + + " ^^^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n"); +} + +public void test094() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " class Y {} \n"+ + " public static void main(String[] arguments) { \n"+ + " int i = 0; \n"+ + " i.new Y(); \n"+ + " } \n"+ + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " i.new Y(); \n" + + " ^\n" + + "Cannot use an expression of the type int as a valid enclosing instance\n" + + "----------\n"); +} +//http://bugs.eclipse.org/bugs/show_bug.cgi?id=30280 +public void test095() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " class Y {} \n"+ + " public static void main(String[] arguments) { \n"+ + " int i = 0; \n"+ + " i.new Y(){}; \n"+ + " } \n"+ + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " i.new Y(){}; \n" + + " ^\n" + + "Cannot use an expression of the type int as a valid enclosing instance\n" + + "----------\n"); +} +public void test096() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " static class Y {} \n"+ + " void foo() { \n"+ + " new X().new Y(){}; \n"+ + " } \n"+ + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new X().new Y(){}; \n" + + " ^^^^^^^\n" + + "Illegal enclosing instance specification for type X.Y\n" + + "----------\n"); +} +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=35456 + */ +public void test097() { + this.runConformTest( + new String[] { + "apples/Base.java", + "package apples; \n" + + "public class Base { \n"+ + " protected String foo = \"SUCCESS\"; \n" + + " public static void main(String[] args){ \n"+ + " new oranges.Derived().new Inner(new oranges.Derived()).bug(); \n"+ + " } \n"+ + "} \n", + "oranges/Derived.java", + "package oranges; \n"+ + "import apples.*; \n"+ + "public class Derived extends Base { \n"+ + " public class Inner { \n"+ + " Derived c = null; \n"+ + " public Inner(Derived c) { \n"+ + " this.c = c; \n"+ + " } \n"+ + " public void bug() { \n"+ + " // The following reference to Base.foo causes the \n"+ + " // VerifyError \n"+ + " System.out.println(c.foo); \n"+ + " } \n"+ + " } \n"+ + "} \n", + }, + "SUCCESS"); +} + +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33751 + */ +public void test098() { + this.runConformTest( + true, + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] args) { \n"+ + " System.out.println(\"first inner class = \" + new Object() {}.getClass()); \n"+ + " if (true) { \n"+ + " System.out.println(\"Always true\"); \n"+ + " } else { \n"+ + " System.out.println(\"unreachable inner class = \" + new Object() {}.getClass()); \n"+ + " } \n"+ + " System.out.println(\"last inner class = \" + new Object() {}.getClass()); \n"+ + " } \n"+ + "} \n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " } else { \n" + + " System.out.println(\"unreachable inner class = \" + new Object() {}.getClass()); \n" + + " } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + "first inner class = class X$1\n" + + "Always true\n" + + "last inner class = class X$2", + "", + JavacTestOptions.SKIP /* optimization that we chose deliberately */); +} + +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40240 + */ +public void test099() { + this.runConformTest( + new String[] { + "Y.java", + "public class Y { \n" + + " public static void main(String[] args) { \n" + + " class Local {} \n"+ + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + "} \n", + }, + "SUCCESS"); + + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.complianceLevel <= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String argv[]) { \n" + + " Object a = new Y$1$Local(); // compile-time error \n" + + " } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object a = new Y$1$Local(); // compile-time error \n" + + " ^^^^^^^^^\n" + + "The nested type Y$1$Local cannot be referenced using its binary name\n" + + "----------\n", + null, + false); + return; + } + this.runNegativeTest( + false, + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String argv[]) { \n" + + " Object a = new Y$1Local(); // compile-time error \n" + + " } \n" + + "} \n", + }, + null, + null, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object a = new Y$1Local(); // compile-time error \n" + + " ^^^^^^^^\n" + + "The nested type Y$1Local cannot be referenced using its binary name\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBug4094180); +} + +/* + * Check that member type allocation is granted access to compatible enclosing instance available as constructor argument + */ +public void test101() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(Object o) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(null).new M(null);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " class M extends Top {\n" + // no issue if M is unrelated to X + " M() {\n" + + " super(null);\n" + + " }\n" + + " M(Object o) {\n" + + " super(new M(){});\n" + + " }\n" + + " }\n" + + " class Top {\n" + + " Top(Object o) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} + +/* + * Check that direct member type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test102() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(Object o) {\n" + + " }\n" + + " class M extends X {\n" + + " M() {\n" + + " super(null); //1\n" + + " }\n" + + " M(Object o) {\n" + + " super(new M());//2\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " super(new M());//2\n" + + " ^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); +} + + +/* + * Check that indirect member type allocation is denied access to compatible enclosing instance available as constructor argument + */ +public void test104() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(Object o) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(null).new M(null);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " class N extends X {\n" + + " N() {\n" + + " super(null); //1\n" + + " }\n" + + " N(Object o) {\n" + + " super(new M());//2\n" + + " }\n" + + " }\n" + + " class M extends X {\n" + + " M() {\n" + + " super(null); //3\n" + + " }\n" + + " M(Object o) {\n" + + " super(new M());//4\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " super(new M());//2\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 21)\n" + + " super(new M());//4\n" + + " ^^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); +} + +public void test107() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static class Y { \n" + + " public Y(Z z) {} \n" + + " } \n" + + " public interface Z {} \n" + + "} \n" + + "\n" + + "class A { \n" + + " private static class B extends X.Y implements X.Z { \n" + + " B(A a) { \n" + + " super(B.this); \n" + + " } \n" + + " } \n" + + "} ", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " super(B.this); \n" + + " ^^^^^^\n" + + "Cannot refer to \'this\' nor \'super\' while explicitly invoking a constructor\n" + + "----------\n"); +} + + // javac 1.4.2 incorrectly accepts it, jikes rejects it as we do +public void test108() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel == ClassFileConstants.JDK1_4) { // 1.3 and 1.5 both accept it + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " {\n" + + " class Local1 extends X {\n" + + " }\n" + + " class Local2 extends Local1 {\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " class Local2 extends Local1 {\n" + + " ^^^^^^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " {\n" + + " class Local1 extends X {\n" + + " }\n" + + " class Local2 extends Local1 {\n" + + " }\n" + + " }\n" + + "}", + }, + ""); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=44538 +public void test109() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel == ClassFileConstants.JDK1_4) { // 1.3 and 1.5 both accept it + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void bar() {\n" + + " class C extends X {\n" + + " public void foo() {\n" + + " \n" + + " }\n" + + " }\n" + + " X a= new X() {\n" + + " public void foo() {\n" + + " \n" + + " }\n" + + " };\n" + + " class D extends C {\n" + + " \n" + + " };\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " class D extends C {\n" + + " ^\n" + + "No enclosing instance of type X is available due to some intermediate constructor invocation\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void bar() {\n" + + " class C extends X {\n" + + " public void foo() {\n" + + " \n" + + " }\n" + + " }\n" + + " X a= new X() {\n" + + " public void foo() {\n" + + " \n" + + " }\n" + + " };\n" + + " class D extends C {\n" + + " \n" + + " };\n" + + " }\n" + + "}" + }, + ""); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=44715 - NPE when generating fake reachable local type +public void test110() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (true) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " class ShouldNotBeGenerated {\n" + + " }\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=44715 - variation with anonymous type +public void test111() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " if (true) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " new Object() {}; \n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +public void test112() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private Object t;\n" + + " X(Object t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(this) {\n" + + " void run() {\n" + + " new Object() {\n" + + " void run() {\n" + + " System.out.println(t);\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" + }, + "OUTER"); +} +public void test113() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private Object t;\n" + + " X(Object t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"OUTER\").bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(this) {\n" + + " void run() {\n" + + " new Object() {\n" + + " void run() {\n" + + " try { \n" + + " X x = (X) t; \n" + + " } catch(ClassCastException e){ \n" + + " System.out.println(\"SUCCESS\");\n" + + " } \n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +public void test114() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String s;\n" + + " X(String s) {\n" + + " this.s = s;\n" + + " }\n" + + " void foo() {\n" + + " class L extends X {\n" + + " L() {\n" + + " super(s);\n" + + " System.out.println(s); \n" + + " }\n" + + " }\n" + + " new L();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"SUCCESS\").foo(); \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " super(s);\n" + + " ^\n" + + "Cannot refer to an instance field s while explicitly invoking a constructor\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=58606 +public void test115() { + this.runConformTest( + new String[] { + "p2/X2.java", + "package p2;\n" + + "public class X2 extends p1.X1 {\n" + + " private void foo() {\n" + + " new p1.X1.M1() {\n" + + " public void bar() {\n" + + " System.out.print(X2.this.field);\n" + + " X2.this.doit();\n" + + " }\n" + + " }.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X2 t2 = new X2();\n" + + " t2.foo();\n" + + " }\n" + + "}", + "p1/X1.java", + "package p1;\n" + + "public class X1 {\n" + + " public abstract class M1 {\n" + + " public abstract void bar();\n" + + " }\n" + + " protected static String field = \"SUCC\";\n" + + " protected static void doit() {\n" + + " System.out.println(\"ESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=68698 +public void test116() { + this.runNegativeTest( + new String[] { + "X.java", + "class Display {\n" + + " public interface Bla {\n" + + " void a();\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " void aMethod() {\n" + + " Display display = null;\n" + + " display.new Bla() {\n" + + " };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " display.new Bla() {\n" + + " ^^^^^^^\n" + + "Illegal enclosing instance specification for type Display.Bla\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " display.new Bla() {\n" + + " ^^^^^\n" + + "The type new Display.Bla(){} must implement the inherited abstract method Display.Bla.a()\n" + + "----------\n"); +} + +public void test117() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " }\n" + + " void bar() {\n" + + " new X(){\n" + + " void baz() {\n" + + " new M();\n" + + " }\n" + + " }.baz();\n" + + " }\n" + + " class M {\n" + + " M() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} + +public void test118() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {}\n" + + " class M {\n" + + " M(Object o) {}\n" + + " M() {\n" + + " this(new Object() {\n" + + " void baz() {\n" + + " foo();\n" + + " bar();\n" + + " }\n" + + " });\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo();\n" + + " bar();\n" + + " }\n" + + " };\n" + + " }\n" + + " void bar() {}\n" + + " void baz() {\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo();\n" + + " bar();\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " bar();\n" + + " ^^^\n" + + "Cannot refer to an instance method while explicitly invoking a constructor\n" + + "----------\n"); +} +public void test119() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().new M();\n" + + " }\n" + + " void foo(String s) { System.out.print(\"\"); }\n" + + " class M {\n" + + " M(Runnable r) { r.run(); }\n" + + " M() {\n" + + " this(new Runnable() {\n" + + " public void run() {\n" + + " foo(\"0\");\n" + + " new Object() {\n" + + " void baz() {\n" + + "// foo(\"1\");\n" + + " }\n" + + " };\n" + + " class Local {\n" + + " void baz() {\n" + + "// foo(\"2\");\n" + + " }\n" + + " } \n" + + " new Local();\n" + + " }\n" + + " });\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo(\"3\");\n" + + " bar(\"3\");\n" + + " }\n" + + " }.baz();\n" + + " }\n" + + " void bar(String s) { System.out.print(\"\"); }\n" + + " void baz() {\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo(\"4\");\n" + + " bar(\"4\");\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " foo(\"0\");\n" + + " ^^^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().new M();\n" + + " }\n" + + " void foo(String s) { System.out.print(\"\"); }\n" + + " class M {\n" + + " M(Runnable r) { r.run(); }\n" + + " M() {\n" + + " this(new Runnable() {\n" + + " public void run() {\n" + + " foo(\"0\");\n" + + " new Object() {\n" + + " void baz() {\n" + + "// foo(\"1\");\n" + + " }\n" + + " };\n" + + " class Local {\n" + + " void baz() {\n" + + "// foo(\"2\");\n" + + " }\n" + + " } \n" + + " new Local();\n" + + " }\n" + + " });\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo(\"3\");\n" + + " bar(\"3\");\n" + + " }\n" + + " }.baz();\n" + + " }\n" + + " void bar(String s) { System.out.print(\"\"); }\n" + + " void baz() {\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo(\"4\");\n" + + " bar(\"4\");\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test120() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {}\n" + + " class M {\n" + + " M(Object o) {}\n" + + " M() {\n" + + " this(new Object() {\n" + + " void baz() {\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo(); //0\n" + + " }\n" + + " };\n" + + " class Local {\n" + + " void baz() {\n" + + " foo(); //1\n" + + " }\n" + + " }\n" + + " new Local();\n" + + " foo();//2\n" + + " }\n" + + " });\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo();//3\n" + + " bar();\n" + + " }\n" + + " };\n" + + " }\n" + + " void bar() {}\n" + + " void baz() {\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo();//4\n" + + " bar();\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " foo(); //0\n" + + " ^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " foo(); //1\n" + + " ^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " foo();//2\n" + + " ^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {}\n" + + " class M {\n" + + " M(Object o) {}\n" + + " M() {\n" + + " this(new Object() {\n" + + " void baz() {\n" + + " class Local {\n" + + " void baz() {\n" + + " foo(); //1\n" + + " }\n" + + " }\n" + + " new Local();\n" + + " foo();//2\n" + + " }\n" + + " });\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo();//3\n" + + " bar();\n" + + " }\n" + + " };\n" + + " }\n" + + " void bar() {}\n" + + " void baz() {\n" + + " new Object() {\n" + + " void baz() {\n" + + " foo();//4\n" + + " bar();\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " foo(); //1\n" + + " ^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); +} +public void test121() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(Object o) {\n" + + " }\n" + + " class M extends X {\n" + + " M() {\n" + + " super(null); //1\n" + + " }\n" + + " M(Object o) {\n" + + " super(new X(null){});//2\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +public void _test122() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().new M();\n" + + " }\n" + + " void foo(String s) { System.out.print(\"\"); }\n" + + " class M {\n" + + " M(Runnable r) { r.run(); }\n" + + " M() {\n" + + " this(new Runnable() {\n" + + " {\n" + + " foo(\"0\");\n" + + " bar(\"0\");\n" + + " }\n" + + " public void run() {\n" + + " }\n" + + " });\n" + + " }\n" + + " void bar(String s) { System.out.print(\"\"); }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "cannot access foo(0)\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " bar(\"0\");\n" + + " ^^^\n" + + "Cannot refer to an instance method while explicitly invoking a constructor\n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().new M();\n" + + " }\n" + + " void foo(String s) { System.out.print(\"\"); }\n" + + " class M {\n" + + " M(Runnable r) { r.run(); }\n" + + " M() {\n" + + " this(new Runnable() {\n" + + " {\n" + + " foo(\"0\");\n" + + " bar(\"0\");\n" + + " }\n" + + " public void run() {\n" + + " }\n" + + " });\n" + + " }\n" + + " void bar(String s) { System.out.print(\"\"); }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " bar(\"0\");\n" + + " ^^^\n" + + "Cannot refer to an instance method while explicitly invoking a constructor\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110182 - variation +public void test123() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class Y {\n" + + " public static final boolean b = false;\n" + + "}\n" + + "public class X {\n" + + " private static Y y = new Y(); \n" + + " private static Object o = new Object(); \n" + + "\n" + + " static class Z {\n" + + " Z() {\n" + + " if (y.b) {\n" + + " System.out.println(\"dead code\");\n" + + " }\n" + + " }\n" + + " public int bar() {\n" + + " if (y.b) {\n" + + " System.out.println(\"dead code\");\n" + + " }\n" + + " System.out.println(\"bar\");\n" + + " return 0;\n" + + " }\n" + + " }\n" + + " static int foo() {\n" + + " synchronized(o) { \n" + + " Z z = new Z();\n" + + " return z.bar();\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + "}\n", + }, + "bar"); + String nestHost = ""; + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.complianceLevel >= ClassFileConstants.JDK11) { + nestHost = "\n" + + "Nest Host: #32 X\n"; + } + // ensure synthetic access method got generated for enclosing field + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X$Z();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 4, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X.Z\n" + + " \n" + + " // Method descriptor #15 ()I\n" + + " // Stack: 2, Locals: 1\n" + + " public int bar();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 ldc [22]\n" + + " 5 invokevirtual java.io.PrintStream.println(java.lang.String) : void [23]\n" + + " 8 iconst_0\n" + + " 9 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 18]\n" + + " [pc: 8, line: 19]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X.Z\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #1 X$Z, outer class info: #32 X\n" + + " inner name: #34 Z, accessflags: 8 static]\n" + + nestHost + + "}"; + + File f = new File(OUTPUT_DIR + File.separator + "X$Z.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=77473 +public void test124() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " Foo foo = new Foo();\n" + + " try {\n" + + " foo.frob(Baz.class);\n" + + " System.out.println(\"FAILED\");\n" + + " } catch(IllegalAccessException e){\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " private static class Baz {\n" + + " }\n" + + "}\n" + + "class Foo {\n" + + " public void frob(Class cls) throws Exception {\n" + + " Object o = cls.newInstance();\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + // ensure synthetic access method got generated for enclosing field + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " private X$Baz();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X.Baz\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X$Baz.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=77473 - variation +public void test125() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(final String s) {\n" + + " class Local {\n" + + " private Local() {}\n" + + " void bar() {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " new Local().bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + // check private constructor outcome (if >= 1.4 modifier change, if 1.3 synthetic emulation) + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + String expectedOutput = options.complianceLevel <= ClassFileConstants.JDK1_3 + ? "class X$1$Local {\n" + + " \n" + + " // Field descriptor #6 LX;\n" + + " final synthetic X this$0;\n" + + " \n" + + " // Field descriptor #9 Ljava/lang/String;\n" + + " private final synthetic java.lang.String val$s;\n" + + " \n" + + " // Method descriptor #11 (LX;Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " private X$1$Local(X arg0, java.lang.String arg1);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [13]\n" + + " 4 aload_0 [this]\n" + + " 5 aload_1 [arg0]\n" + + " 6 putfield X$1$Local.this$0 : X [16]\n" + + " 9 aload_0 [this]\n" + + " 10 aload_2 [arg1]\n" + + " 11 putfield X$1$Local.val$s : java.lang.String [18]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: new X(){}.Local\n" + + " \n" + + " // Method descriptor #15 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " void bar();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [25]\n" + + " 3 aload_0 [this]\n" + + " 4 getfield X$1$Local.val$s : java.lang.String [18]\n" + + " 7 invokevirtual java.io.PrintStream.println(java.lang.String) : void [31]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 10, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: this index: 0 type: new X(){}.Local\n" + + " \n" + + " // Method descriptor #37 (LX;Ljava/lang/String;LX$1$Local;)V\n" + + " // Stack: 3, Locals: 4\n" + + " synthetic X$1$Local(X arg0, java.lang.String arg1, new X(){}.Local arg2);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 aload_2 [arg1]\n" + + " 3 invokespecial X$1$Local(X, java.lang.String) [38]\n" + + " 6 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #1 X$1$Local, outer class info: #0\n" + + " inner name: #43 Local, accessflags: 0 default]\n" + + "}" + : options.complianceLevel == ClassFileConstants.JDK1_4 + ? "class X$1$Local {\n" + + " \n" + + " // Field descriptor #6 LX;\n" + + " final synthetic X this$0;\n" + + " \n" + + " // Field descriptor #9 Ljava/lang/String;\n" + + " private final synthetic java.lang.String val$s;\n" + + " \n" + + " // Method descriptor #11 (LX;Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " X$1$Local(X arg0, java.lang.String arg1);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 putfield X$1$Local.this$0 : X [13]\n" + + " 5 aload_0 [this]\n" + + " 6 aload_2 [arg1]\n" + + " 7 putfield X$1$Local.val$s : java.lang.String [15]\n" + + " 10 aload_0 [this]\n" + + " 11 invokespecial java.lang.Object() [17]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: new X(){}.Local\n" + + " \n" + + " // Method descriptor #19 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " void bar();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [25]\n" + + " 3 aload_0 [this]\n" + + " 4 getfield X$1$Local.val$s : java.lang.String [15]\n" + + " 7 invokevirtual java.io.PrintStream.println(java.lang.String) : void [31]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 10, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: this index: 0 type: new X(){}.Local\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #1 X$1$Local, outer class info: #0\n" + + " inner name: #40 Local, accessflags: 0 default]\n" + + "}" + : "class X$1Local {\n" + + " \n" + + " // Field descriptor #6 LX;\n" + + " final synthetic X this$0;\n" + + " \n" + + " // Field descriptor #8 Ljava/lang/String;\n" + + " private final synthetic java.lang.String val$s;\n" + + " \n" + + " // Method descriptor #10 (LX;Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + (isMinimumCompliant(ClassFileConstants.JDK11) ? " private " :" ") + + "X$1Local(X arg0, java.lang.String arg1);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 putfield X$1Local.this$0 : X [12]\n" + + " 5 aload_0 [this]\n" + + " 6 aload_2 [arg1]\n" + + " 7 putfield X$1Local.val$s : java.lang.String [14]\n" + + " 10 aload_0 [this]\n" + + " 11 invokespecial java.lang.Object() [16]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: new X(){}\n" + + " \n" + + " // Method descriptor #18 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " void bar();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [24]\n" + + " 3 aload_0 [this]\n" + + " 4 getfield X$1Local.val$s : java.lang.String [14]\n" + + " 7 invokevirtual java.io.PrintStream.println(java.lang.String) : void [30]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 10, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: this index: 0 type: new X(){}\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #1 X$1Local, outer class info: #0\n" + + " inner name: #44 Local, accessflags: 0 default]\n" + + (isMinimumCompliant(ClassFileConstants.JDK11) ? + " Enclosing Method: #39 #41 X.foo(Ljava/lang/String;)V\n" + + "\n" + + "Nest Host: #39 X\n" : ""); + + File f = new File(OUTPUT_DIR + File.separator + (options.complianceLevel >= ClassFileConstants.JDK1_5 ? "X$1Local.class" : "X$1$Local.class")); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=130117 +public void test126() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel < ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public interface X {\n" + + " private class Inner {}\n" + + " private interface IInner {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private class Inner {}\n" + + " ^^^^^\n" + + "The interface member type Inner can only be public\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " private interface IInner {}\n" + + " ^^^^^^\n" + + "The interface member type IInner can only be public\n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public interface X {\n" + + " private class Inner {}\n" + + " private interface IInner {}\n" + + " private enum EInner {}\n" + + " private @interface AInner {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private class Inner {}\n" + + " ^^^^^\n" + + "The interface member type Inner can only be public\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " private interface IInner {}\n" + + " ^^^^^^\n" + + "The interface member type IInner can only be public\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " private enum EInner {}\n" + + " ^^^^^^\n" + + "The interface member type EInner can only be public\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " private @interface AInner {}\n" + + " ^^^^^^\n" + + "The interface member type AInner can only be public\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=89347 +public void test127() { + this.runConformTest( + new String[] { + "p/BugContainer.java", + "package p;\n" + + "\n" + + "public abstract class BugContainer {\n" + + " protected static class InternalInfo$ {\n" + + " public InternalInfo$() {}\n" + + " }\n" + + " abstract protected InternalInfo$ getInfo();\n" + + "}\n", // ================= + }, + ""); + this.runConformTest( + new String[] { + "q/BugUser.java", // ================= + "package q;\n" + + "\n" + + "import p.BugContainer;\n" + + "\n" + + "public class BugUser extends BugContainer{\n" + + " protected InternalInfo$ getInfo() {\n" + + " return new InternalInfo$();\n" + + " }\n" + + "}", // ================= + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=89347 - variation +public void test128() { + this.runConformTest( + new String[] { + "p/BugContainer.java", + "package p;\n" + + "\n" + + "public abstract class BugContainer {\n" + + " protected static class InternalInfo$ {\n" + + " public InternalInfo$() {}\n" + + " }\n" + + " abstract protected InternalInfo$ getInfo();\n" + + "}\n", // ================= + "q/BugUser.java", // ================= + "package q;\n" + + "\n" + + "import p.BugContainer;\n" + + "\n" + + "public class BugUser extends BugContainer{\n" + + " protected InternalInfo$ getInfo() {\n" + + " return new InternalInfo$();\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=160132 - variation +public void test129() { + this.runConformTest( + new String[] { + "X.java", //======================== + "public interface X {\n" + + " interface Entry {\n" + + " interface Internal extends Entry {\n" + + " Internal createEntry();\n" + + " }\n" + + " }\n" + + "}\n", //======================== + "Y.java", + "public class Y implements X.Entry.Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + ""); + // compile Y against X binary + this.runConformTest( + new String[] { + "Y.java", //======================== + "public class Y implements X.Entry.Internal {\n" + + " public Internal createEntry() {\n" + + " return null;\n" + + " }\n" + + "}\n" , //======================== + }, + "", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=164497 +public void test130() { + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.sourceLevel <= ClassFileConstants.JDK1_3) { + runConformTest( + true /* flush output directory */, + new String[] { /* test files */ + "X.java", //======================== + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new M().foo2();\n" + + " }\n" + + "}\n"+ + "class M {\n" + + " String name;\n" + + " \n" + + " M() {\n" + + " this.name = \"SUCCESS\";\n" + + " }\n" + + "\n" + + " private class Y extends N {\n" + + " private Y() {\n" + + " super();\n" + + " }\n" + + " protected void foo(Z z) {\n" + + " z.bar(new A());\n" + + " }\n" + + " }\n" + + " \n" + + " public class A implements I {\n" + + " public void configure() {\n" + + " new B().foo();\n" + + " }\n" + + " public class B {\n" + + " public void foo() {\n" + + " try {\n" + + " System.out.println(M.this.name);\n" + + " } catch(NullPointerException e) {\n" + + " System.err.println(\"NPE THROWN\");\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " \n" + + " public void foo2() {\n" + + " new Y();\n" + + " }\n" + + "}\n" + + "class Z {\n" + + " void bar(I i) {\n" + + " i.configure();\n" + + " }\n" + + "}\n" + + "\n" + + "interface I {\n" + + " void configure();\n" + + "}\n" + + "\n" + + "class N {\n" + + " protected void foo(Z z) {\n" + + " }\n" + + " N() {\n" + + " this.foo(new Z());\n" + + " }\n" + + "}\n" + }, + null /* do not check compiler log */, + "" /* expected output string */, + "NPE THROWN" /* expected error string */, + JavacTestOptions.DEFAULT /* default javac test options */); + return; + } + this.runConformTest( + new String[] { + "X.java", //======================== + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new M().foo2();\n" + + " }\n" + + "}\n"+ + "class M {\n" + + " String name;\n" + + " \n" + + " M() {\n" + + " this.name = \"SUCCESS\";\n" + + " }\n" + + "\n" + + " private class Y extends N {\n" + + " private Y() {\n" + + " super();\n" + + " }\n" + + " protected void foo(Z z) {\n" + + " z.bar(new A());\n" + + " }\n" + + " }\n" + + " \n" + + " public class A implements I {\n" + + " public void configure() {\n" + + " new B().foo();\n" + + " }\n" + + " public class B {\n" + + " public void foo() {\n" + + " System.out.println(M.this.name);\n" + + " }\n" + + " }\n" + + " }\n" + + " \n" + + " public void foo2() {\n" + + " new Y();\n" + + " }\n" + + "}\n" + + "class Z {\n" + + " void bar(I i) {\n" + + " i.configure();\n" + + " }\n" + + "}\n" + + "\n" + + "interface I {\n" + + " void configure();\n" + + "}\n" + + "\n" + + "class N {\n" + + " protected void foo(Z z) {\n" + + " }\n" + + " N() {\n" + + " this.foo(new Z());\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165662 +public void test131() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " class Local {\n" + + " void foo() {\n" + + " }\n" + + " }\n" + + " {\n" + + " class Local {\n" + + " Local(int i) {\n" + + " this.init(i);\n" + + " this.bar(); // should detect error\n" + + " }\n" + + " void init(int i) {\n" + + " }\n" + + " }\n" + + " Local l = new Local(0); // should be fine\n" + + " }\n" + + " Local l = new Local();\n" + + " l.foo();\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " class Local {\n" + + " ^^^^^\n" + + "Duplicate nested type Local\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " this.bar(); // should detect error\n" + + " ^^^\n" + + "The method bar() is undefined for the type Local\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=165662 +public void test132() { + this.runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " class Local {}\n" + + " class Foo {\n" + + " void foo() {\n" + + " class Local {}\n" + + " }\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " class Local {}\n" + + " ^^^^^\n" + + "The type Local is hiding the type Local\n" + + "----------\n", + "", + "", + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=168331 +public void test133() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "X.java", //=================== + "public class X {\n" + + " public static interface I {\n" + + " }\n" + + " public static interface IE extends I {\n" + + " }\n" + + " public static interface J {\n" + + " I getI(int i);\n" + + " }\n" + + " public static interface JE extends J {\n" + + " IE getI(int i);\n" + + " }\n" + + " public static class Y implements JE {\n" + + " public IE getI(int i) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " private J j = new Y();\n" + + " public void foo() {\n" + + " j.getI(0);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}", // ================= + }, + "SUCCESS"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=168331 +public void test134() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "X.java", //=================== + "public class X {\n" + + " public interface I {\n" + + " public String foo();\n" + + " }\n" + + " public interface J {\n" + + " public I getI();\n" + + " }\n" + + " public static class XI implements I {\n" + + " public String foo() {\n" + + " return \"XI\";\n" + + " }\n" + + " }\n" + + " public interface K extends J {\n" + + " public XI getI();\n" + + " }\n" + + " public static abstract class XK implements K {\n" + + " public XI getI() {\n" + + " return new XI();\n" + + " }\n" + + " }\n" + + " public static class Y extends XK {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " K k = new Y();\n" + + " System.out.println(k.getI().foo());\n" + + " J j = k;\n" + + " System.out.println(j.getI().foo());\n" + + " }\n" + + "}", // ================= + }, + "XI\nXI"); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=152961 +public void test135() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import p.A;\n" + + "public class X {\n" + + " \n" + + " void foo(Object o, Object [] os) {\n" + + " A.M2.MM1 mm1 = (A.M2.MM1) o;\n" + + " A.M2.MM1[] mm1s = (A.M2.MM1[]) os;\n" + + " }\n" + + " private interface Outer {\n" + + " interface Inner {\n" + + " String variable = \"my testing\";\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Outer.Inner.variable);\n" + + " Zork z;\n" + + " }\n" + + "}", // =================, + "p/A.java", + "package p;\n" + + "/** @deprecated */\n" + + "public class A {\n" + + " public class M1 {\n" + + " public class MM1 {\n" + + " }\n" + + " }\n" + + " public class M2 extends M1 {\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 2)\n" + + " import p.A;\n" + + " ^^^\n" + + "The type A is deprecated\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 6)\n" + + " A.M2.MM1 mm1 = (A.M2.MM1) o;\n" + + " ^\n" + + "The type A is deprecated\n" + + "----------\n" + + "3. WARNING in p\\X.java (at line 6)\n" + + " A.M2.MM1 mm1 = (A.M2.MM1) o;\n" + + " ^^\n" + + "The type A.M2 is deprecated\n" + + "----------\n" + + "4. WARNING in p\\X.java (at line 6)\n" + + " A.M2.MM1 mm1 = (A.M2.MM1) o;\n" + + " ^^^\n" + + "The type A.M1.MM1 is deprecated\n" + + "----------\n" + + "5. WARNING in p\\X.java (at line 6)\n" + + " A.M2.MM1 mm1 = (A.M2.MM1) o;\n" + + " ^\n" + + "The type A is deprecated\n" + + "----------\n" + + "6. WARNING in p\\X.java (at line 6)\n" + + " A.M2.MM1 mm1 = (A.M2.MM1) o;\n" + + " ^^\n" + + "The type A.M2 is deprecated\n" + + "----------\n" + + "7. WARNING in p\\X.java (at line 6)\n" + + " A.M2.MM1 mm1 = (A.M2.MM1) o;\n" + + " ^^^\n" + + "The type A.M1.MM1 is deprecated\n" + + "----------\n" + + "8. WARNING in p\\X.java (at line 7)\n" + + " A.M2.MM1[] mm1s = (A.M2.MM1[]) os;\n" + + " ^\n" + + "The type A is deprecated\n" + + "----------\n" + + "9. WARNING in p\\X.java (at line 7)\n" + + " A.M2.MM1[] mm1s = (A.M2.MM1[]) os;\n" + + " ^^\n" + + "The type A.M2 is deprecated\n" + + "----------\n" + + "10. WARNING in p\\X.java (at line 7)\n" + + " A.M2.MM1[] mm1s = (A.M2.MM1[]) os;\n" + + " ^^^\n" + + "The type A.M1.MM1 is deprecated\n" + + "----------\n" + + "11. WARNING in p\\X.java (at line 7)\n" + + " A.M2.MM1[] mm1s = (A.M2.MM1[]) os;\n" + + " ^\n" + + "The type A is deprecated\n" + + "----------\n" + + "12. WARNING in p\\X.java (at line 7)\n" + + " A.M2.MM1[] mm1s = (A.M2.MM1[]) os;\n" + + " ^^\n" + + "The type A.M2 is deprecated\n" + + "----------\n" + + "13. WARNING in p\\X.java (at line 7)\n" + + " A.M2.MM1[] mm1s = (A.M2.MM1[]) os;\n" + + " ^^^\n" + + "The type A.M1.MM1 is deprecated\n" + + "----------\n" + + "14. ERROR in p\\X.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=152961 - variation +public void test136() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " private interface Outer {\n" + + " interface Inner {\n" + + " String variable = \"my testing\";\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer.Inner variable = null;\n" + + " System.out.println(variable);\n" + + " Zork z;\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=152961 - variation +public void test137() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " private interface Outer {\n" + + " interface Inner {\n" + + " String variable = \"my testing\";\n" + + " }\n" + + " }\n" + + " private interface Outer2 extends Outer {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Outer2.Inner.variable);\n" + + " Zork z;\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=152961 - variation +public void test138() { + this.runNegativeTest( + new String[] { + "p/X.java", + "public class X {\n" + + " private interface Outer {\n" + + " interface Inner {\n" + + " String variable = \"my testing\";\n" + + " }\n" + + " }\n" + + " private interface Outer2 extends Outer {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Outer2.Inner variable = null;\n" + + " System.out.println(variable);\n" + + " Zork z;\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=152961 - variation +public void test139() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " class Y extends Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " private class Y extends A {\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " class Y extends Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " private class A {\n" + + " class B {}\n" + + " }\n" + + " private class Y extends A {\n" + + " }\n" + + " Y.B d = null;\n" + + "}\n" + + "class Y extends Zork {}\n", // ================= + }, + errMessage); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=171184 +public void test140() throws Exception { + this.runConformTest(new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static interface I {\n" + + " void foo();\n" + + " }\n" + + "}", + "p1/X.java", + "package p1;\n" + + "import p.A;\n" + + "public class X implements A.I {\n" + + " public void foo() { /* dummy */ }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #5 p/A$I, outer class info: #20 p/A\n" + + " inner name: #22 I, accessflags: 1545 public abstract static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p1" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=171184 +public void test141() throws Exception { + this.runConformTest(new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static class B {\n" + + " void foo() { /* dummy */ }\n" + + " }\n" + + "}", + "p1/X.java", + "package p1;\n" + + "import p.A;\n" + + "public class X extends A.B {\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #3 p/A$B, outer class info: #17 p/A\n" + + " inner name: #19 B, accessflags: 9 public static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p1" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=171184 +public void test142() throws Exception { + this.runConformTest(new String[] { + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public class B {\n" + + " void foo() { /* dummy */ }\n" + + " }\n" + + "}", + "p1/X.java", + "package p1;\n" + + "import p.A;\n" + + "public class X {\n" + + " Object foo() {\n" + + " return new A().new B();\n" + + " }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #16 p/A$B, outer class info: #18 p/A\n" + + " inner name: #31 B, accessflags: 1 public]\n"; + if (new CompilerOptions(getCompilerOptions()).targetJDK == ClassFileConstants.JDK1_1) { + expectedOutput = + " Inner classes:\n" + + " [inner class info: #16 p/A$B, outer class info: #18 p/A\n" + + " inner name: #27 B, accessflags: 1 public]\n"; + } + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p1" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=171184 +public void test143() throws Exception { + this.runConformTest(new String[] { + "X.java", + "class A {\n" + + " public class B {\n" + + " void foo() { /* dummy */ }\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " Object foo() {\n" + + " return A.B.class;\n" + + " }\n" + + "}" + }); + if (new CompilerOptions(getCompilerOptions()).targetJDK >= ClassFileConstants.JDK1_5) { + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #16 A$B, outer class info: #21 A\n" + + " inner name: #23 B, accessflags: 1 public]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=171184 +public void test144() throws Exception { + this.runConformTest(new String[] { + "X.java", + "class A {\n" + + " public static class B {\n" + + " public static int CONST = 0;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " int foo() {\n" + + " return A.B.CONST;\n" + + " }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #17 A$B, outer class info: #25 A\n" + + " inner name: #27 B, accessflags: 9 public static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=171184 +public void test145() throws Exception { + this.runConformTest(new String[] { + "X.java", + "class A {\n" + + " public static class B {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " A.B field;\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #19 A$B, outer class info: #21 A\n" + + " inner name: #23 B, accessflags: 9 public static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=171184 +public void test146() throws Exception { + this.runConformTest(new String[] { + "X.java", + "class A {\n" + + " public static class B {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " int foo(A.B o) {\n" + + " return 0;\n" + + " }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #21 A$B, outer class info: #23 A\n" + + " inner name: #25 B, accessflags: 9 public static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=171184 +public void test147() throws Exception { + this.runConformTest(new String[] { + "X.java", + "class A {\n" + + " public static class B {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " A.B foo() {\n" + + " return null;\n" + + " }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #19 A$B, outer class info: #21 A\n" + + " inner name: #23 B, accessflags: 9 public static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=171184 +public void test148() throws Exception { + this.runConformTest(new String[] { + "X.java", + "class A {\n" + + " public static class B extends Exception {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " void foo() throws A.B{\n" + + " }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #16 A$B, outer class info: #21 A\n" + + " inner name: #23 B, accessflags: 9 public static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=171749 +public void test149() throws Exception { + this.runConformTest(new String[] { + "X.java", + "public final class X implements A.Foo1 {\n" + + " public void foo() {}\n" + + " public A.Foo2 foo2() { return null; }\n" + + " public void foo3( A.Foo3 foo ) {}\n" + + " public void foo4() { A.Foo4 foo = null; }\n" + + " public void foo5() {\n" + + " new A.Foo5() {\n" + + " public void foo() {}\n" + + " }.foo();\n" + + " }\n" + + " public static class Foo6 implements A.Foo6 {\n" + + " public void foo() {}\n" + + " }\n" + + " public void foo7() { Bar2.foo7().foo(); }\n" + + "}", + "A.java", + "class A {\n" + + " public static interface Foo1 { void foo(); }\n" + + " public static interface Foo2 { void foo(); }\n" + + " public static interface Foo3 { void foo(); }\n" + + " public static interface Foo4 { void foo(); }\n" + + " public static interface Foo5 { void foo(); }\n" + + " public static interface Foo6 { void foo(); }\n" + + " public static interface Foo7 { void foo(); }\n" + + "}", + "Bar2.java", + "class Bar2 {\n" + + " public static A.Foo7 foo7() { return null; }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #5 A$Foo1, outer class info: #44 A\n" + + " inner name: #46 Foo1, accessflags: 1545 public abstract static],\n" + + " [inner class info: #47 A$Foo2, outer class info: #44 A\n" + + " inner name: #49 Foo2, accessflags: 1545 public abstract static],\n" + + " [inner class info: #50 A$Foo3, outer class info: #44 A\n" + + " inner name: #52 Foo3, accessflags: 1545 public abstract static],\n" + + " [inner class info: #39 A$Foo7, outer class info: #44 A\n" + + " inner name: #53 Foo7, accessflags: 1545 public abstract static],\n" + + " [inner class info: #25 X$1, outer class info: #0\n" + + " inner name: #0, accessflags: 0 default],\n" + + " [inner class info: #54 X$Foo6, outer class info: #1 X\n" + + " inner name: #56 Foo6, accessflags: 9 public static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=210422 +public void test150() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public final class X implements Serializable {\n" + + "\n" + + " void bar() {}\n" + + "\n" + + " interface IM {}\n" + + " class SMember extends String {}\n" + + "\n" + + " class Member extends X { \n" + + " ZorkMember z;\n" + + " void foo() {\n" + + " this.bar();\n" + + " Zork1 z;\n" + + " } \n" + + " }\n" + + "\n" + + " void foo() {\n" + + " new X().new IM();\n" + + " class Local extends X { \n" + + " ZorkLocal z;\n" + + " void foo() {\n" + + " this.bar();\n" + + " Zork3 z;\n" + + " }\n" + + " }\n" + + " new X() {\n" + + " ZorkAnonymous2 z; \n" + + " void foo() {\n" + + " this.bar();\n" + + " Zork4 z;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public final class X implements Serializable {\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 8)\n" + + " class SMember extends String {}\n" + + " ^^^^^^\n" + + "The type SMember cannot subclass the final class String\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " class Member extends X { \n" + + " ^\n" + + "The type Member cannot subclass the final class X\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " ZorkMember z;\n" + + " ^^^^^^^^^^\n" + + "ZorkMember cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " this.bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type X.Member\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " Zork1 z;\n" + + " ^^^^^\n" + + "Zork1 cannot be resolved to a type\n" + + "----------\n" + + "7. WARNING in X.java (at line 14)\n" + + " Zork1 z;\n" + + " ^\n" + + "The local variable z is hiding a field from type X.Member\n" + + "----------\n" + + "8. ERROR in X.java (at line 19)\n" + + " new X().new IM();\n" + + " ^^\n" + + "Cannot instantiate the type X.IM\n" + + "----------\n" + + "9. ERROR in X.java (at line 20)\n" + + " class Local extends X { \n" + + " ^\n" + + "The type Local cannot subclass the final class X\n" + + "----------\n" + + "10. ERROR in X.java (at line 21)\n" + + " ZorkLocal z;\n" + + " ^^^^^^^^^\n" + + "ZorkLocal cannot be resolved to a type\n" + + "----------\n" + + "11. ERROR in X.java (at line 23)\n" + + " this.bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type Local\n" + + "----------\n" + + "12. ERROR in X.java (at line 24)\n" + + " Zork3 z;\n" + + " ^^^^^\n" + + "Zork3 cannot be resolved to a type\n" + + "----------\n" + + "13. WARNING in X.java (at line 24)\n" + + " Zork3 z;\n" + + " ^\n" + + "The local variable z is hiding a field from type Local\n" + + "----------\n" + + "14. ERROR in X.java (at line 27)\n" + + " new X() {\n" + + " ^\n" + + "An anonymous class cannot subclass the final class X\n" + + "----------\n" + + "15. ERROR in X.java (at line 28)\n" + + " ZorkAnonymous2 z; \n" + + " ^^^^^^^^^^^^^^\n" + + "ZorkAnonymous2 cannot be resolved to a type\n" + + "----------\n" + + "16. ERROR in X.java (at line 30)\n" + + " this.bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type new X(){}\n" + + "----------\n" + + "17. ERROR in X.java (at line 31)\n" + + " Zork4 z;\n" + + " ^^^^^\n" + + "Zork4 cannot be resolved to a type\n" + + "----------\n" + + "18. WARNING in X.java (at line 31)\n" + + " Zork4 z;\n" + + " ^\n" + + "The local variable z is hiding a field from type new X(){}\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216683 +public void test151() { + long compliance = new CompilerOptions(getCompilerOptions()).complianceLevel; + if (compliance <= ClassFileConstants.JDK1_3) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static interface Foo { }\n" + + " public static interface Bar { }\n" + + "\n" + + " private static class B2F extends X { }\n" + + " private static class F2B extends X { }\n" + + "\n" + + " public static abstract class Key {\n" + + "\n" + + " public abstract Key flip();\n" + + "\n" + + " private static class B2F extends Key {\n" + + " private static B2F create() { return new B2F(); }\n" + + " public Key flip() { return F2B.create(); }\n" + + " }\n" + + "\n" + + " private static class F2B extends Key {\n" + + " private static F2B create() { return new F2B(); }\n" + + " public Key flip() { return B2F.create(); }\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " public Key flip() { return F2B.create(); }\n" + + " ^^^\n" + + "The type F2B is defined in an inherited type and an enclosing scope\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " public Key flip() { return B2F.create(); }\n" + + " ^^^\n" + + "The type B2F is defined in an inherited type and an enclosing scope\n" + + "----------\n"); + } else if (compliance == ClassFileConstants.JDK1_4) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static interface Foo { }\n" + + " public static interface Bar { }\n" + + "\n" + + " private static class B2F extends X { }\n" + + " private static class F2B extends X { }\n" + + "\n" + + " public static abstract class Key {\n" + + "\n" + + " public abstract Key flip();\n" + + "\n" + + " private static class B2F extends Key {\n" + + " private static B2F create() { return new B2F(); }\n" + + " public Key flip() { return F2B.create(); }\n" + + " }\n" + + "\n" + + " private static class F2B extends Key {\n" + + " private static F2B create() { return new F2B(); }\n" + + " public Key flip() { return B2F.create(); }\n" + + " }\n" + + " }\n" + + "}", // ================= + + }, + ""); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static interface Foo { }\n" + + " public static interface Bar { }\n" + + "\n" + + " private static class B2F extends X { }\n" + + " private static class F2B extends X { }\n" + + "\n" + + " public static abstract class Key {\n" + + "\n" + + " public abstract Key flip();\n" + + "\n" + + " private static class B2F extends Key {\n" + + " private static B2F create() { return new B2F(); }\n" + + " public Key flip() { return F2B.create(); }\n" + + " }\n" + + "\n" + + " private static class F2B extends Key {\n" + + " private static F2B create() { return new F2B(); }\n" + + " public Key flip() { return B2F.create(); }\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + ""); + } +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=216683 - variation +public void test152() { + long compliance = new CompilerOptions(getCompilerOptions()).complianceLevel; + if (compliance <= ClassFileConstants.JDK1_3) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static interface Foo { }\n" + + " public static interface Bar { }\n" + + "\n" + + " public static class B2F extends X { }\n" + + " public static class F2B extends X { }\n" + + "\n" + + " public static abstract class Key {\n" + + "\n" + + " public abstract Key flip();\n" + + "\n" + + " public static class B2F extends Key {\n" + + " private static B2F create() { return new B2F(); }\n" + + " public Key flip() { return F2B.create(); }\n" + + " }\n" + + "\n" + + " public static class F2B extends Key {\n" + + " private static F2B create() { return new F2B(); }\n" + + " public Key flip() { return B2F.create(); }\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " public Key flip() { return F2B.create(); }\n" + + " ^^^\n" + + "The type F2B is defined in an inherited type and an enclosing scope\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " public Key flip() { return B2F.create(); }\n" + + " ^^^\n" + + "The type B2F is defined in an inherited type and an enclosing scope\n" + + "----------\n"); + } else if (compliance == ClassFileConstants.JDK1_4) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static interface Foo { }\n" + + " public static interface Bar { }\n" + + "\n" + + " private static class B2F extends X { }\n" + + " private static class F2B extends X { }\n" + + "\n" + + " public static abstract class Key {\n" + + "\n" + + " public abstract Key flip();\n" + + "\n" + + " private static class B2F extends Key {\n" + + " private static B2F create() { return new B2F(); }\n" + + " public Key flip() { return F2B.create(); }\n" + + " }\n" + + "\n" + + " private static class F2B extends Key {\n" + + " private static F2B create() { return new F2B(); }\n" + + " public Key flip() { return B2F.create(); }\n" + + " }\n" + + " }\n" + + "}", // ================= + + }, + ""); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static interface Foo { }\n" + + " public static interface Bar { }\n" + + "\n" + + " private static class B2F extends X { }\n" + + " private static class F2B extends X { }\n" + + "\n" + + " public static abstract class Key {\n" + + "\n" + + " public abstract Key flip();\n" + + "\n" + + " private static class B2F extends Key {\n" + + " private static B2F create() { return new B2F(); }\n" + + " public Key flip() { return F2B.create(); }\n" + + " }\n" + + "\n" + + " private static class F2B extends Key {\n" + + " private static F2B create() { return new F2B(); }\n" + + " public Key flip() { return B2F.create(); }\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + ""); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=201487 +public void _test153() { + long compliance = new CompilerOptions(getCompilerOptions()).complianceLevel; + if (compliance <= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class Test3 {\n" + + " protected void load() {\n" + + " }\n" + + " }\n" + + " public class Test2 {\n" + + " public Test2(String string, Test3 test3) {\n" + + " }\n" + + " }\n" + + " private String var1;\n" + + "private class Test5 {\n" + + " private class Test4 extends Test2 {\n" + + " public Test4() {\n" + + " super(\"available\", new Test3() {\n" + + " protected void load() {\n" + + " System.out.println(X.this.var1.trim());\n" + + " System.out.println(var1.trim());\n" + + " }\n" + + " });\n" + + " }\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " System.out.println(X.this.var1.trim());\n" + + " ^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " System.out.println(X.this.var1.trim());\n" + + " ^^^^\n" + + "Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " System.out.println(var1.trim());\n" + + " ^^^^\n" + + "Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " System.out.println(var1.trim());\n" + + " ^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public class Test3 {\n" + + " protected void load() {\n" + + " }\n" + + " }\n" + + " public class Test2 {\n" + + " public Test2(String string, Test3 test3) {\n" + + " }\n" + + " }\n" + + " private String var1;\n" + + "private class Test5 {\n" + + " private class Test4 extends Test2 {\n" + + " public Test4() {\n" + + " super(\"available\", new Test3() {\n" + + " protected void load() {\n" + + " System.out.println(X.this.var1.trim());\n" + + " System.out.println(var1.trim());\n" + + " }\n" + + " });\n" + + " }\n" + + " }\n" + + " }\n" + + "}", // ================= + }, + ""); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=201487 - variation +public void test154() { + long compliance = new CompilerOptions(getCompilerOptions()).complianceLevel; + if (compliance <= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class Test3 {\n" + + " protected void load() {\n" + + " }\n" + + " }\n" + + " public class Test2 {\n" + + " public Test2(String string, Test3 test3) {\n" + + " }\n" + + " }\n" + + " private String var1;\n" + + "// private class Test5 {\n" + + " private class Test4 extends Test2 {\n" + + " public Test4() {\n" + + " super(\"available\", new Test3() {\n" + + " protected void load() {\n" + + " System.out.println(X.this.var1.trim());\n" + + " System.out.println(var1.trim());\n" + + " }\n" + + " });\n" + + " }\n" + + " }\n" + + "// }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " System.out.println(X.this.var1.trim());\n" + + " ^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " System.out.println(X.this.var1.trim());\n" + + " ^^^^\n" + + "Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" + + "----------\n" + + "3. WARNING in X.java (at line 17)\n" + + " System.out.println(var1.trim());\n" + + " ^^^^\n" + + "Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " System.out.println(var1.trim());\n" + + " ^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public class Test3 {\n" + + " protected void load() {\n" + + " }\n" + + " }\n" + + " public class Test2 {\n" + + " public Test2(String string, Test3 test3) {\n" + + " }\n" + + " }\n" + + " private String var1;\n" + + "// private class Test5 {\n" + + " private class Test4 extends Test2 {\n" + + " public Test4() {\n" + + " super(\"available\", new Test3() {\n" + + " protected void load() {\n" + + " System.out.println(X.this.var1.trim());\n" + + " System.out.println(var1.trim());\n" + + " }\n" + + " });\n" + + " }\n" + + " }\n" + + "// }\n" + + "}", // ================= + }, + ""); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id= +public void test155() throws Exception { + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " Object foo() {\n" + + " return new X() {};\n" + + " }\n" + + "}" + }); + File fileX = new File(OUTPUT_DIR + File.separator +"X$1.class"); + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.CONSTANT_POOL); + assertFalse("Should not be final", Flags.isFinal(reader.getAccessFlags())); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128563 +public void test156() throws Exception { + this.runConformTest(new String[] { + "package1/A.java",//======================= + "package package1;\n" + + "abstract class A {\n" + + " protected final void outerMethod() {\n" + + " }\n" + + "}\n", + "package1/B.java",//======================= + "package package1;\n" + + "public class B extends A {\n" + + "}\n", + "package2/C.java",//======================= + "package package2;\n" + + "import package1.B;\n" + + "public class C extends B {\n" + + " private final MyInner myInner = new MyInner();\n" + + " private class MyInner {\n" + + " public void innerMethod() {\n" + + " C.this.outerMethod();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final C c = new C();\n" + + " c.myInner.innerMethod();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " static synthetic void access$0(package2.C arg0);\n" + + " 0 aload_0 [arg0]\n" + + " 1 invokevirtual package2.C.outerMethod() : void"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "package2" + File.separator + "C.class", "C", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 +public void test157() throws Exception { + this.runConformTest(new String[] { + "package1/A.java",//======================= + "package package1;\n" + + "abstract class A {\n" + + " protected int outerField; {\n" + + " }\n" + + "}\n", + "package1/B.java",//======================= + "package package1;\n" + + "public class B extends A {\n" + + "}\n", + "package2/C.java",//======================= + "package package2;\n" + + "import package1.B;\n" + + "public class C extends B {\n" + + " private final MyInner myInner = new MyInner();\n" + + " private class MyInner {\n" + + " public void innerMethod() {\n" + + " int j = C.this.outerField;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final C c = new C();\n" + + " c.myInner.innerMethod();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #33 (Lpackage2/C;)I\n" + + " // Stack: 1, Locals: 1\n" + + " static synthetic int access$0(package2.C arg0);\n" + + " 0 aload_0 [arg0]\n" + + " 1 getfield package2.C.outerField : int"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "package2" + File.separator + "C.class", "C", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test158() throws Exception { + this.runConformTest(new String[] { + "package1/A.java",//======================= + "package package1;\n" + + "abstract class A {\n" + + " protected int outerField; {\n" + + " }\n" + + "}\n", + "package1/B.java",//======================= + "package package1;\n" + + "public class B extends A {\n" + + "}\n", + "package2/C.java",//======================= + "package package2;\n" + + "import package1.B;\n" + + "public class C extends B {\n" + + " private final MyInner myInner = new MyInner();\n" + + " private class MyInner {\n" + + " public void innerMethod() {\n" + + " C.this.outerField = 12;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final C c = new C();\n" + + " c.myInner.innerMethod();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #33 (Lpackage2/C;I)V\n" + + " // Stack: 2, Locals: 2\n" + + " static synthetic void access$0(package2.C arg0, int arg1);\n" + + " 0 aload_0 [arg0]\n" + + " 1 iload_1 [arg1]\n" + + " 2 putfield package2.C.outerField : int"; + + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "package2" + File.separator + "C.class", "C", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test159() throws Exception { + this.runConformTest(new String[] { + "package1/A.java",//======================= + "package package1;\n" + + "abstract class A {\n" + + " protected int outerField; {\n" + + " }\n" + + "}\n", + "package1/B.java",//======================= + "package package1;\n" + + "public class B extends A {\n" + + "}\n", + "package2/C.java",//======================= + "package package2;\n" + + "import package1.B;\n" + + "public class C extends B {\n" + + " private final MyInner myInner = new MyInner();\n" + + " private class MyInner {\n" + + " public void innerMethod() {\n" + + " int j = outerField;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final C c = new C();\n" + + " c.myInner.innerMethod();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #33 (Lpackage2/C;)I\n" + + " // Stack: 1, Locals: 1\n" + + " static synthetic int access$0(package2.C arg0);\n" + + " 0 aload_0 [arg0]\n" + + " 1 getfield package2.C.outerField : int"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "package2" + File.separator + "C.class", "C", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test160() throws Exception { + this.runConformTest(new String[] { + "package1/A.java",//======================= + "package package1;\n" + + "abstract class A {\n" + + " protected int outerField; {\n" + + " }\n" + + "}\n", + "package1/B.java",//======================= + "package package1;\n" + + "public class B extends A {\n" + + "}\n", + "package2/C.java",//======================= + "package package2;\n" + + "import package1.B;\n" + + "public class C extends B {\n" + + " private final MyInner myInner = new MyInner();\n" + + " private class MyInner {\n" + + " public void innerMethod() {\n" + + " outerField = 12;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final C c = new C();\n" + + " c.myInner.innerMethod();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #33 (Lpackage2/C;I)V\n" + + " // Stack: 2, Locals: 2\n" + + " static synthetic void access$0(package2.C arg0, int arg1);\n" + + " 0 aload_0 [arg0]\n" + + " 1 iload_1 [arg1]\n" + + " 2 putfield package2.C.outerField : int"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "package2" + File.separator + "C.class", "C", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test161() throws Exception { + this.runConformTest(new String[] { + "package1/A.java",//======================= + "package package1;\n" + + "abstract class A {\n" + + " static protected int outerField; {\n" + + " }\n" + + "}\n", + "package1/B.java",//======================= + "package package1;\n" + + "public class B extends A {\n" + + "}\n", + "package2/C.java",//======================= + "package package2;\n" + + "import package1.B;\n" + + "public class C extends B {\n" + + " private final MyInner myInner = new MyInner();\n" + + " private class MyInner {\n" + + " public void innerMethod() {\n" + + " int j = C.this.outerField;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final C c = new C();\n" + + " c.myInner.innerMethod();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #33 ()I\n" + + " // Stack: 1, Locals: 0\n" + + " static synthetic int access$0();\n" + + " 0 getstatic package2.C.outerField : int"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "package2" + File.separator + "C.class", "C", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test162() throws Exception { + this.runConformTest(new String[] { + "package1/A.java",//======================= + "package package1;\n" + + "abstract class A {\n" + + " static protected int outerField; {\n" + + " }\n" + + "}\n", + "package1/B.java",//======================= + "package package1;\n" + + "public class B extends A {\n" + + "}\n", + "package2/C.java",//======================= + "package package2;\n" + + "import package1.B;\n" + + "public class C extends B {\n" + + " private final MyInner myInner = new MyInner();\n" + + " private class MyInner {\n" + + " public void innerMethod() {\n" + + " C.this.outerField = 12;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final C c = new C();\n" + + " c.myInner.innerMethod();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #33 (I)V\n" + + " // Stack: 1, Locals: 1\n" + + " static synthetic void access$0(int arg0);\n" + + " 0 iload_0 [arg0]\n" + + " 1 putstatic package2.C.outerField : int"; + + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "package2" + File.separator + "C.class", "C", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test163() throws Exception { + this.runConformTest(new String[] { + "package1/A.java",//======================= + "package package1;\n" + + "abstract class A {\n" + + " static protected int outerField; {\n" + + " }\n" + + "}\n", + "package1/B.java",//======================= + "package package1;\n" + + "public class B extends A {\n" + + "}\n", + "package2/C.java",//======================= + "package package2;\n" + + "import package1.B;\n" + + "public class C extends B {\n" + + " private final MyInner myInner = new MyInner();\n" + + " private class MyInner {\n" + + " public void innerMethod() {\n" + + " int j = outerField;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final C c = new C();\n" + + " c.myInner.innerMethod();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #33 ()I\n" + + " // Stack: 1, Locals: 0\n" + + " static synthetic int access$0();\n" + + " 0 getstatic package2.C.outerField : int"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "package2" + File.separator + "C.class", "C", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test164() throws Exception { + this.runConformTest(new String[] { + "package1/A.java",//======================= + "package package1;\n" + + "abstract class A {\n" + + " static protected int outerField; {\n" + + " }\n" + + "}\n", + "package1/B.java",//======================= + "package package1;\n" + + "public class B extends A {\n" + + "}\n", + "package2/C.java",//======================= + "package package2;\n" + + "import package1.B;\n" + + "public class C extends B {\n" + + " private final MyInner myInner = new MyInner();\n" + + " private class MyInner {\n" + + " public void innerMethod() {\n" + + " outerField = 12;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final C c = new C();\n" + + " c.myInner.innerMethod();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #33 (I)V\n" + + " // Stack: 1, Locals: 1\n" + + " static synthetic void access$0(int arg0);\n" + + " 0 iload_0 [arg0]\n" + + " 1 putstatic package2.C.outerField : int"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "package2" + File.separator + "C.class", "C", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128563 - variation +public void test165() throws Exception { + this.runConformTest(new String[] { + "package1/A.java",//======================= + "package package1;\n" + + "abstract class A {\n" + + " static protected final void outerMethod() {\n" + + " }\n" + + "}\n", + "package1/B.java",//======================= + "package package1;\n" + + "public class B extends A {\n" + + "}\n", + "package2/C.java",//======================= + "package package2;\n" + + "import package1.B;\n" + + "public class C extends B {\n" + + " private final MyInner myInner = new MyInner();\n" + + " private class MyInner {\n" + + " public void innerMethod() {\n" + + " C.this.outerMethod();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final C c = new C();\n" + + " c.myInner.innerMethod();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #8 ()V\n" + + " // Stack: 0, Locals: 0\n" + + " static synthetic void access$0();\n" + + " 0 invokestatic package2.C.outerMethod() : void"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "package2" + File.separator + "C.class", "C", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test166() throws Exception { + this.runConformTest(new String[] { + "X.java",//======================= + "class XSuper {\n" + + " protected String field = \"[XSuper#field]\";//$NON-NLS-1$\n" + + "}\n" + + "public class X extends XSuper {\n" + + " protected String field = \"[X#field]\";//$NON-NLS-1$\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " new Object() {\n" + + " void bar() {\n" + + " System.out.print(\"X.this.field=\" + X.this.field);\n" + + " System.out.print(\"X.super.field=\" + X.super.field);\n" + + " }\n" + + " }.bar();\n" + + " }\n" + + "}\n", + }, + "X.this.field=[X#field]X.super.field=[XSuper#field]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test167() throws Exception { + this.runConformTest(new String[] { + "X.java",//======================= + "class XSuper {\n" + + " protected String method() { return \"[XSuper#method()]\"; }//$NON-NLS-1$\n" + + "}\n" + + "public class X extends XSuper {\n" + + " protected String method() { return \"[X#method()]\"; }//$NON-NLS-1$\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " new Object() {\n" + + " void bar() {\n" + + " System.out.print(\"X.this.method()=\" + X.this.method());\n" + + " System.out.print(\"X.super.method()=\" + X.super.method());\n" + + " }\n" + + " }.bar();\n" + + " }\n" + + "}\n", + }, + "X.this.method()=[X#method()]X.super.method()=[XSuper#method()]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test168() throws Exception { + this.runConformTest(new String[] { + "X.java",//======================= + "class XSuper {\n" + + " protected String field;\n" + + "}\n" + + "public class X extends XSuper {\n" + + " protected String field;\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " new Object() {\n" + + " void bar() {\n" + + " X.this.field = \"[X#field]\";\n" + + " X.super.field = \"[XSuper#field]\";\n" + + " System.out.print(\"X.this.field=\" + X.this.field);\n" + + " System.out.print(\"X.super.field=\" + X.super.field);\n" + + " }\n" + + " }.bar();\n" + + " }\n" + + "}\n", + }, + "X.this.field=[X#field]X.super.field=[XSuper#field]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test169() throws Exception { + this.runConformTest(new String[] { + "X.java",//======================= + "import p.XSuper;\n" + + "public class X extends XSuper {\n" + + " protected String method() { return \"[X#method()]\"; }//$NON-NLS-1$\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " new Object () {\n" + + " void bar() {\n" + + " System.out.print(\"X.this.method()=\" + X.this.method());\n" + + " System.out.print(\"X.super.method()=\" + X.super.method());\n" + + " }\n" + + " }.bar();\n" + + " }\n" + + "}\n", + "p/XSuper.java",//======================= + "package p;\n" + + "class XInternal {\n" + + " protected String method() { return \"[XInternal#method()]\"; }//$NON-NLS-1$\n" + + "}\n" + + "public class XSuper extends XInternal {\n" + + "}\n", + }, + "X.this.method()=[X#method()]X.super.method()=[XInternal#method()]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test170() throws Exception { + this.runConformTest(new String[] { + "X.java",//======================= + "public class X {\n" + + " class Member {\n" + + " private String field = \"SUCCESS\";\n" + + " }\n" + + " class SubMember extends Member {\n" + + " void foo() {\n" + + " System.out.println(super.field);\n" + + " }\n" + + " } \n" + + " public static void main(String argv[]) {\n" + + " new X().new SubMember().foo(); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249107 - variation +public void test171() throws Exception { + this.runConformTest(new String[] { + "X.java",//======================= + "public class X {\n" + + " class Member {\n" + + " private String method() { return \"SUCCESS\"; }\n" + + " }\n" + + " class SubMember extends Member {\n" + + " void foo() {\n" + + " System.out.println(super.method());\n" + + " }\n" + + " } \n" + + " public static void main(String argv[]) {\n" + + " new X().new SubMember().foo(); \n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=197271 +public void test172() throws Exception { + String[] files = new String[] { + "X.java", + "public class X {\n" + + " void a() {}\n" + + " private static void a(String s) {}\n" + + " private void c() {}\n" + + " private static void c(String s) {}\n" + + " static class M1 extends X {\n" + + " public void x() {\n" + + " a(null);\n" + + " c(null);\n" + + " }\n" + + " }\n" + + " static class M2 {\n" + + " public void x() {\n" + + " a(null);\n" + + " c(null);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n", + }; + if (this.complianceLevel < ClassFileConstants.JDK11) { + this.runNegativeTest( + files, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " a(null);\n" + + " ^^^^^^^\n" + + "Access to enclosing method a(String) from the type X is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " c(null);\n" + + " ^^^^^^^\n" + + "Access to enclosing method c(String) from the type X is emulated by a synthetic accessor method\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " a(null);\n" + + " ^^^^^^^\n" + + "Access to enclosing method a(String) from the type X is emulated by a synthetic accessor method\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " c(null);\n" + + " ^^^^^^^\n" + + "Access to enclosing method c(String) from the type X is emulated by a synthetic accessor method\n" + + "----------\n" + ); + } else { + this.runConformTest(files, ""); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=308245 +public void test173() throws Exception { + this.runConformTest( + new String[] { + "X.java",//======================= + "import java.util.ArrayList;\n" + + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final List yourList = new ArrayList();\n" + + " final List myList = new ArrayList();\n" + + " new Comparator() {\n" + + " public int compare(Object o1, Object o2) {\n" + + " compare(yourList != null ? yourList : myList, yourList);\n" + + " return 0;\n" + + " }\n" + + " };\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=308245 +public void test174() throws Exception { + this.runConformTest( + new String[] { + "X.java",//======================= + "import java.util.Comparator;\n" + + "public class X {\n" + + " public static class MyList {\n" + + " int size;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final MyList yourList = new MyList();\n" + + " final MyList myList = new MyList();\n" + + " new Comparator() {\n" + + " public int compare(Object o1, Object o2) {\n" + + " return compare((MyList) o1, (MyList) o2);\n" + + " }\n" + + " public int compare(MyList o1, MyList o2) {\n" + + " return foo(yourList != null ? yourList.size : myList.size, yourList.size);\n" + + " }\n" + + " private int foo(int i, int j) {\n" + + " return i - j;\n" + + " }\n" + + " };\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=388903 +public void test175() throws Exception { + this.runConformTest( + new String[] { + "X.java",//======================= + "public class X {\n" + + " class Inner extends X {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new Inner(){};\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + this.runConformTest( + new String[] { + "X.java",//======================= + "public class X {\n" + + " String which;\n" + + " X(String s) {\n" + + " this.which = s;\n" + + " }\n" + + " class Inner extends X {\n" + + " Inner() {\n" + + " super(\"Inner\");\n" + + " System.out.print( X.this.which + \",\" ); // will output 'Enclosing,'\n" + + " }\n" + + " }\n" + + " void check() {\n" + + " new X(\"Enclosing\").new Inner() {\n" + + " {\n" + + " System.out.print( X.this.which + \",\" ); // will output 'Context,'\n" + + " }\n" + + " void f() {\n" + + " System.out.println( X.this.which ); // will output 'Context'\n" + + " }\n" + + " }.f();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X(\"Context\").check();\n" + + " }\n" + + "}", + }, + "Enclosing,Context,Context"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=435419 Instantiating needs outer constructor +public void test176() { + this.runConformTest( + new String[] { + "Demo.java", + "import java.util.ArrayList;\n" + + "public class Demo {\n" + + " static class ExprFactoryList extends ArrayList {\n" + + " class Expr {}\n" + + " class Expr2 extends Expr {}\n" + + " }\n" + + " final static ExprFactoryList arith = new ExprFactoryList() {\n" + + " {\n" + + " add(new Object() {public Expr generate() {return new Expr() {};} }); // OK\n" + + " add(new Object() {public Expr generate() {return new Expr2() {};} }); // Ok\n" + + " }\n" + + " };\n" + + " final static ExprFactoryList statementFactory = new ExprFactoryList() {\n" + + " class Statement extends Expr {}\n" + + " void m() {\n" + + " add(new Object() {\n" + + " public void generate() {\n" + + " new Statement(){}; // OK\n" + + " }\n" + + " });\n" + + " }\n" + + " {\n" + + " add (new Statement()); // OK\n" + + " add(new Object() {\n" + + " public void generate() {\n" + + " new Statement(); // OK\n" + + " new Statement(){}; // cannot compile\n" + + " }\n" + + " });\n" + + " }\n" + + " };\n" + + " public static void main(String[] args) {\n" + + " Demo demo = new Demo();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " \n" + + "}" + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=484546 "IncompatibleClassChangeError: Expected static method[...]" with inner classes +public void testbug484546() { + this.runConformTest( + new String[] { + "inner/test/InnerTest.java", + "package inner.test;\n" + + "class Inner029SuperSuper {\n" + + " public int getValue() {\n" + + " return 10;\n" + + " }\n" + + "}\n" + + "class Inner029Super extends Inner029SuperSuper {\n" + + "}\n" + + "class InnerSuper extends Inner029Super {\n" + + " public int getValue() {\n" + + " return 20;\n" + + " }\n" + + "}\n" + + "public class InnerTest extends Inner029Super {\n" + + " public int result = new Inner().getInner2().test();\n" + + " class Inner extends InnerSuper {\n" + + " Inner2 getInner2() {\n" + + " return new Inner2();\n" + + " }\n" + + " class Inner2 {\n" + + " public int test() {\n" + + " return InnerTest.super.getValue();\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new InnerTest().result);\n" + + "}\n" + + "}\n" + }, + "10"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=373371 [compiler] JDT Compiler reports an error whereas javac compiles without problem +public void testbug373371() { + String[] sources = new String[] { + "Outer.java", + "class Outer {\n" + + " class Inner extends Outer { }\n" + + " class SubInner extends Inner {\n" + + " public SubInner() {\n" + + " // Outer.this.super(); // (1)\n" + + " }\n" + + " }\n" + + "}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_4 || this.complianceLevel > ClassFileConstants.JDK1_6) { + this.runConformTest(sources); + } else { + this.runNegativeTest( + sources, + "----------\n" + + "1. ERROR in Outer.java (at line 4)\n" + + " public SubInner() {\n" + + " ^^^^^^^^^^\n" + + "No enclosing instance of type Outer is available due to some intermediate constructor invocation\n" + + "----------\n"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=522061 EJC 4.8M1 does not compile a class that javac 1.8.0_112 compiles +public void testbug522061() { + String[] sources = new String[] { + "ztest/Foo.java", + "package ztest;\n" + + "import java.io.File;\n" + + "import javax.swing.Action;\n" + + "public abstract class Foo {\n" + + " public FilteredFileTree matching(final Action filterConfigAction) {\n" + + " return new FilteredFileTree() {\n" + + " //@Override\n" + + " protected File filter(File set) {\n" + + " return null;\n" + + " }\n" + + " };\n" + + " }\n" + + " public String getDisplayName() {\n" + + " return null;\n" + + " }\n" + + " private abstract class FilteredFileTree extends Foo {\n" + + " protected abstract File filter(File set);\n" + + " public String getDisplayName() {\n" + + " return Foo.this.toString();\n" + + " }\n" + + " }\n" + + "}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_4 || this.complianceLevel > ClassFileConstants.JDK1_6) { + this.runConformTest(sources); + } else { + this.runNegativeTest( + sources, + "----------\n" + + "1. WARNING in ztest\\Foo.java (at line 6)\n" + + " return new FilteredFileTree() {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Access to enclosing constructor Foo.FilteredFileTree() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in ztest\\Foo.java (at line 6)\n" + + " return new FilteredFileTree() {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "No enclosing instance of type Foo is available due to some intermediate constructor invocation\n" + + "----------\n"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=481793 Compilation error when trying to compile nested inner classes +public void testbug481793() { + String[] sources = new String[] { + "A.java", + "public class A {\n" + + " public class B extends A {\n" + + " public class C extends B {}\n" + + " }\n" + + "}" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_4 || this.complianceLevel > ClassFileConstants.JDK1_6) { + this.runConformTest(sources); + } else { + this.runNegativeTest( + sources, + "----------\n" + + "1. ERROR in A.java (at line 3)\n" + + " public class C extends B {}\n" + + " ^\n" + + "No enclosing instance of type A is available due to some intermediate constructor invocation\n" + + "----------\n"); + } +} +public static Class testClass() { + return InnerEmulationTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest_1_5.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest_1_5.java new file mode 100644 index 0000000000..ccba29102a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest_1_5.java @@ -0,0 +1,351 @@ +/******************************************************************************* + * Copyright (c) 2009, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for Bug 343713 - [compiler] bogus line number in constructor of inner class in 1.5 compliance + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class InnerEmulationTest_1_5 extends AbstractRegressionTest { +static { +// TESTS_NAMES = new String[] { "Bug58069" }; +// TESTS_NUMBERS = new int[] { 13 }; +// TESTS_RANGE = new int[] { 144, -1 }; +} +public InnerEmulationTest_1_5(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test1() throws Exception { + this.runConformTest(new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " public void foo(Collection args) { /* dummy */ }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #25 java/util/Map$Entry, outer class info: #27 java/util/Map\n" + + " inner name: #29 Entry, accessflags: 1545 public abstract static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test2() throws Exception { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " public void foo(Map.Entry args) { /* dummy */ }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #21 java/util/Map$Entry, outer class info: #23 java/util/Map\n" + + " inner name: #25 Entry, accessflags: 1545 public abstract static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test3() throws Exception { + this.runConformTest(new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " , T extends Map.Entry> X(List lu, T t) {\n" + + " }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #27 java/util/Map$Entry, outer class info: #29 java/util/Map\n" + + " inner name: #31 Entry, accessflags: 1545 public abstract static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test4() throws Exception { + this.runConformTest(new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.List;\n" + + "public class X> {}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #21 java/util/Map$Entry, outer class info: #23 java/util/Map\n" + + " inner name: #25 Entry, accessflags: 1545 public abstract static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test5() throws Exception { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " public void foo(Map.Entry args) { /* dummy */ }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #25 java/util/Map$Entry, outer class info: #27 java/util/Map\n" + + " inner name: #29 Entry, accessflags: 1545 public abstract static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test6() throws Exception { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " Map.Entry f;\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #21 java/util/Map$Entry, outer class info: #23 java/util/Map\n" + + " inner name: #25 Entry, accessflags: 1545 public abstract static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test7() throws Exception { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "public class X> {\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #21 java/util/Map$Entry, outer class info: #23 java/util/Map\n" + + " inner name: #25 Entry, accessflags: 1545 public abstract static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test8() throws Exception { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "class A {\n" + + " static class B{}\n" + + "}\n" + + "public class X> {\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #21 java/util/Map$Entry, outer class info: #23 java/util/Map\n" + + " inner name: #25 Entry, accessflags: 1545 public abstract static],\n" + + " [inner class info: #26 p/A$B, outer class info: #28 p/A\n" + + " inner name: #30 B, accessflags: 8 static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test9() throws Exception { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "class A {\n" + + " static class B{}\n" + + "}\n" + + "public class X {\n" + + " > void foo(E e) {}\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #25 java/util/Map$Entry, outer class info: #27 java/util/Map\n" + + " inner name: #29 Entry, accessflags: 1545 public abstract static],\n" + + " [inner class info: #30 p/A$B, outer class info: #32 p/A\n" + + " inner name: #34 B, accessflags: 8 static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test10() throws Exception { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "class A {\n" + + " static interface B{}\n" + + "}\n" + + "class C {\n" + + " static class D{}\n" + + "}\n" + + "public class X {\n" + + " >> void foo(E e) {}\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #25 java/util/Map$Entry, outer class info: #27 java/util/Map\n" + + " inner name: #29 Entry, accessflags: 1545 public abstract static],\n" + + " [inner class info: #30 p/A$B, outer class info: #32 p/A\n" + + " inner name: #34 B, accessflags: 1544 abstract static],\n" + + " [inner class info: #35 p/C$D, outer class info: #37 p/C\n" + + " inner name: #39 D, accessflags: 8 static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test11() throws Exception { + this.runConformTest(new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + " public class X {\n" + + " \n" + + " static abstract class SelfType>{\n" + + " }\n" + + " \n" + + " static class SuperType extends SelfType{\n" + + " }\n" + + " \n" + + " static class SubType extends SuperType{}\n" + + " \n" + + " static > List makeSingletonList(T t){\n" + + " return Collections.singletonList(t);\n" + + " }\n" + + " \n" + + " static ,S extends T> List makeSingletonList2(S s){\n" + + " return Collections.singletonList((T)s); // #0\n" + + " }\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #35 X$SelfType, outer class info: #1 X\n" + + " inner name: #37 SelfType, accessflags: 1032 abstract static],\n" + + " [inner class info: #38 X$SubType, outer class info: #1 X\n" + + " inner name: #40 SubType, accessflags: 8 static],\n" + + " [inner class info: #41 X$SuperType, outer class info: #1 X\n" + + " inner name: #43 SuperType, accessflags: 8 static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test12() throws Exception { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " Collection field;\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #21 java/util/Map$Entry, outer class info: #23 java/util/Map\n" + + " inner name: #25 Entry, accessflags: 1545 public abstract static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p" + File.separator + "X.class", "X", expectedOutput); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=275381 +public void test13() throws Exception { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "class A {\n" + + " static interface B{}\n" + + "}\n" + + "class C {\n" + + " static class D{}\n" + + "}\n" + + "public class X extends C.D implements A.B {\n" + + "}" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #5 p/A$B, outer class info: #19 p/A\n" + + " inner name: #21 B, accessflags: 1544 abstract static],\n" + + " [inner class info: #3 p/C$D, outer class info: #22 p/C\n" + + " inner name: #24 D, accessflags: 8 static]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "p" + File.separator + "X.class", "X", expectedOutput); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=343713 +// [compiler] bogus line number in constructor of inner class in 1.5 compliance +public void test14() throws Exception { + runConformTest(new String[] { + "LineNumberBug.java", + "public class LineNumberBug {\n" + + " class Inner {\n" + + " public Inner() {\n" + + " System.out.println(\"Inner()\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new LineNumberBug().new Inner();\n" + + " }\n" + + "}\n" + }); + String expectedOutput = + " // Method descriptor #8 (LLineNumberBug;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public LineNumberBug$Inner(LineNumberBug arg0);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 putfield LineNumberBug$Inner.this$0 : LineNumberBug [10]\n" + + " 5 aload_0 [this]\n" + + " 6 invokespecial java.lang.Object() [12]\n" + + " 9 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 12 ldc [21]\n" + + " 14 invokevirtual java.io.PrintStream.println(java.lang.String) : void [23]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 9, line: 4]\n" + + " [pc: 17, line: 5]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "LineNumberBug$Inner.class", "LineNumberBug$Inner", expectedOutput); +} +public void testBug546362() throws Exception { + runConformTest(new String[] { + "Schema.java", + "import java.util.HashMap;\n" + + "\n" + + "public class Schema {\n" + + " public Integer[] getElements(HashMap map) {\n" + + " return map.entrySet().toArray(new Integer[0]);\n" + + " }\n" + + "}\n" + + "" + }); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #41 java/util/Map$Entry, outer class info: #43 java/util/Map\n" + + " inner name: #45 Entry, accessflags: 1545 public abstract static]\n" + + ""; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "Schema.class", "X", expectedOutput); +} +public static Class testClass() { + return InnerEmulationTest_1_5.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InstanceofExpressionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InstanceofExpressionTest.java new file mode 100644 index 0000000000..c375427518 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InstanceofExpressionTest.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * + *******************************************************************************/ + +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class InstanceofExpressionTest extends AbstractRegressionTest { + + public InstanceofExpressionTest(String name) { + super(name); + } + + public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); + } + + public static Class testClass() { + return InstanceofExpressionTest.class; + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=341828 + public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.InputStream;\n" + + "public class X {\n" + + " void foo(InputStream is) {\n" + + " if (is instanceof FileInputStream)\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (is instanceof FileInputStream)\n" + + " ^^^^^^^^^^^^^^^\n" + + "FileInputStream cannot be resolved to a type\n" + + "----------\n" + ); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InstanceofPrimaryPatternTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InstanceofPrimaryPatternTest.java new file mode 100644 index 0000000000..b150bcd168 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InstanceofPrimaryPatternTest.java @@ -0,0 +1,271 @@ +/******************************************************************************* + * Copyright (c) 2021 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class InstanceofPrimaryPatternTest extends AbstractRegressionTest { + + private static final JavacTestOptions JAVAC_OPTIONS = new JavacTestOptions("-source 17 --enable-preview -Xlint:-preview"); + static { +// TESTS_NUMBERS = new int [] { 40 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] { "test005" }; + } + + public static Class testClass() { + return InstanceofPrimaryPatternTest.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_17); + } + public InstanceofPrimaryPatternTest(String testName){ + super(testName); + } + // Enables the tests to run individually + protected Map getCompilerOptions(boolean preview) { + Map defaultOptions = super.getCompilerOptions(); + if (this.complianceLevel >= ClassFileConstants.getLatestJDKLevel() + && preview) { + defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + } + return defaultOptions; + } + + protected Map getCompilerOptions() { + return getCompilerOptions(true); + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { + if(!isJRE17Plus) + return; + runConformTest(testFiles, expectedOutput, customOptions, new String[] {"--enable-preview"}, JAVAC_OPTIONS); + } + protected void runNegativeTest( + String[] testFiles, + String expectedCompilerLog, + String javacLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + Map customOptions) { + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedCompilerLog; + runner.javacTestOptions = JAVAC_OPTIONS; + runner.customOptions = customOptions; + runner.expectedJavacOutputString = javacLog; + runner.runNegativeTest(); + } + public void test001() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof String s) {\n" + + " System.out.println(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"Hello World!\");\n" + + " }\n" + + "}\n", + }, + "Hello World!", + options); + } + public void test002() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof (String s)) {\n" + + " System.out.println(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"Hello World!\");\n" + + " }\n" + + "}\n", + }, + "Hello World!", + options); + } + public void test003() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof ((String s))) {\n" + + " System.out.println(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"Hello World!\");\n" + + " }\n" + + "}\n", + }, + "Hello World!", + options); + } + public void test004() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof ((((String s))))) {\n" + + " System.out.println(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"Hello World!\");\n" + + " }\n" + + "}\n", + }, + "Hello World!", + options); + } + public void test005() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof (String s) && (s.length() > 0)) {\n" + + " System.out.println(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"Hello World!\");\n" + + " }\n" + + "}\n", + }, + "Hello World!", + options); + } + public void test006() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof (String s && s.length() > 0)) {\n" + + " System.out.println(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"Hello World!\");\n" + + " Zork();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void test007() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof var s) {\n" + + " System.out.println(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"Hello World!\");\n" + + " Zork();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (obj instanceof var s) {\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void test008() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof (((var s)))) {\n" + + " System.out.println(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"Hello World!\");\n" + + " Zork();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (obj instanceof (((var s)))) {\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void test009() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(String s) {\n" + + " if (s instanceof Object o) {\n" + + " System.out.println(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"Hello World!\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (s instanceof Object o) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Expression type cannot be a subtype of the Pattern type\n" + + "----------\n"); + } +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java new file mode 100644 index 0000000000..b2a4d295e5 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java @@ -0,0 +1,3244 @@ +/******************************************************************************* + * Copyright (c) 2013, 2021 GK Software AG, IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + * Jesper S Moller - realigned with bug 399695 + *******************************************************************************/ +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.tests.junit.extension.TestCase; +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; + +import junit.framework.Test; + +// See https://bugs.eclipse.org/380501 +// Bug 380501 - [1.8][compiler] Add support for default methods (JSR 335) +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class InterfaceMethodsTest extends AbstractComparableTest { + +// Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which do not belong to the class are skipped... + static { +// TESTS_NAMES = new String[] { "testBug421543" }; +// TESTS_NUMBERS = new int[] { 561 }; +// TESTS_RANGE = new int[] { 1, 2049 }; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + + public static Test setUpTest(Test test) throws Exception { + TestCase.setUpTest(test); + RegressionTestSetup suite = new RegressionTestSetup(ClassFileConstants.JDK1_8); + suite.addTest(test); + return suite; + } + + public static Class testClass() { + return InterfaceMethodsTest.class; + } + + public InterfaceMethodsTest(String name) { + super(name); + } + + // default methods with various modifiers, positive cases + public void testModifiers1() { + runConformTest( + new String[] { + "I.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.METHOD) @interface Annot{}\n" + + "public interface I {\n" + + " default void foo1() {}\n" + + " public default void foo2() { System.exit(0); }\n" + + " strictfp default void foo3() {}\n" + + " public default strictfp void foo4() {}\n" + + " public default strictfp @Annot void foo5() {}\n" + + "}\n", + }, + ""); + } + + + // default methods with various modifiers, negative cases + public void testModifiers1a() { + String infMod = this.complianceLevel >= ClassFileConstants.JDK9 ? " private," : ""; + String op = this.complianceLevel < ClassFileConstants.JDK17 ? + "----------\n" + + "1. ERROR in I.java (at line 5)\n" + + " public default synchronized void foo2() { System.exit(0); }\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo2; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "2. ERROR in I.java (at line 7)\n" + + " public default strictfp synchronized void foo4() {}\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo4; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "3. ERROR in I.java (at line 8)\n" + + " public default strictfp synchronized @Annot void foo5() {}\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo5; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" + + "----------\n" : + "----------\n" + + "1. ERROR in I.java (at line 5)\n" + + " public default synchronized void foo2() { System.exit(0); }\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo2; only public, private, abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "2. WARNING in I.java (at line 6)\n" + + " strictfp default void foo3() {}\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" + + "----------\n" + + "3. WARNING in I.java (at line 7)\n" + + " public default strictfp synchronized void foo4() {}\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" + + "----------\n" + + "4. ERROR in I.java (at line 7)\n" + + " public default strictfp synchronized void foo4() {}\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo4; only public, private, abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "5. WARNING in I.java (at line 8)\n" + + " public default strictfp synchronized @Annot void foo5() {}\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" + + "----------\n" + + "6. ERROR in I.java (at line 8)\n" + + " public default strictfp synchronized @Annot void foo5() {}\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo5; only public, private, abstract, default, static and strictfp are permitted\n" + + "----------\n"; + runNegativeTest( + new String[] { + "I.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.METHOD) @interface Annot{}\n" + + "public interface I {\n" + + " default void foo1() {}\n" + + " public default synchronized void foo2() { System.exit(0); }\n" + + " strictfp default void foo3() {}\n" + + " public default strictfp synchronized void foo4() {}\n" + + " public default strictfp synchronized @Annot void foo5() {}\n" + + "}\n"}, + op); + } + + // default methods with various modifiers, simple syntax error blows the parser + public void testModifiers1b() { + runNegativeTest( + new String[] { + "I.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.METHOD) @interface Annot{}\n" + + "public interface I {\n" + + " default void foo1() { System.out.println(3); }\n" + + " public default void foo2() {}\n" + + " stritfp default void foo3() {}\n" + // typo in strictfp + " default public strictfp void foo4() {}\n" + + " public strictfp default @Annot void foo5() {}\n" + + " public default T foo6(T t) { return t; }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in I.java (at line 6)\n" + + " stritfp default void foo3() {}\n" + + " ^^^^^^^\n" + + "Syntax error, insert \"Identifier (\" to complete MethodHeaderName\n" + + "----------\n" + + "2. ERROR in I.java (at line 6)\n" + + " stritfp default void foo3() {}\n" + + " ^^^^^^^\n" + + "Syntax error, insert \")\" to complete MethodDeclaration\n" + + "----------\n" + + "3. ERROR in I.java (at line 6)\n" + + " stritfp default void foo3() {}\n" + + " ^^^^^^^\n" + + "Syntax error, insert \";\" to complete MethodDeclaration\n" + + "----------\n" + + (this.complianceLevel >= ClassFileConstants.JDK17 ? + "4. WARNING in I.java (at line 7)\n" + + " default public strictfp void foo4() {}\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" + + "----------\n" + + "5. WARNING in I.java (at line 8)\n" + + " public strictfp default @Annot void foo5() {}\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" + + "----------\n" : "") + ); + } + + // regular interface with illegal modifiers + public void testModifiers2() { + String infMod = this.complianceLevel >= ClassFileConstants.JDK9 ? " private," : ""; + String op = this.complianceLevel < ClassFileConstants.JDK17 ? + "----------\n" + + "1. ERROR in I.java (at line 5)\n" + + " public synchronized void foo2();\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo2; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "2. ERROR in I.java (at line 6)\n" + + " strictfp void foo3();\n" + + " ^^^^^^\n" + + "strictfp is not permitted for abstract interface method foo3\n" + + "----------\n" + + "3. ERROR in I.java (at line 7)\n" + + " public strictfp synchronized void foo4();\n" + + " ^^^^^^\n" + + "strictfp is not permitted for abstract interface method foo4\n" + + "----------\n" + + "4. ERROR in I.java (at line 7)\n" + + " public strictfp synchronized void foo4();\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo4; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "5. ERROR in I.java (at line 8)\n" + + " public strictfp synchronized @Annot void foo5();\n" + + " ^^^^^^\n" + + "strictfp is not permitted for abstract interface method foo5\n" + + "----------\n" + + "6. ERROR in I.java (at line 8)\n" + + " public strictfp synchronized @Annot void foo5();\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo5; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" + + "----------\n" : + "----------\n" + + "1. ERROR in I.java (at line 5)\n" + + " public synchronized void foo2();\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo2; only public, private, abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "2. WARNING in I.java (at line 6)\n" + + " strictfp void foo3();\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" + + "----------\n" + + "3. ERROR in I.java (at line 6)\n" + + " strictfp void foo3();\n" + + " ^^^^^^\n" + + "strictfp is not permitted for abstract interface method foo3\n" + + "----------\n" + + "4. WARNING in I.java (at line 7)\n" + + " public strictfp synchronized void foo4();\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" + + "----------\n" + + "5. ERROR in I.java (at line 7)\n" + + " public strictfp synchronized void foo4();\n" + + " ^^^^^^\n" + + "strictfp is not permitted for abstract interface method foo4\n" + + "----------\n" + + "6. ERROR in I.java (at line 7)\n" + + " public strictfp synchronized void foo4();\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo4; only public, private, abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "7. WARNING in I.java (at line 8)\n" + + " public strictfp synchronized @Annot void foo5();\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" + + "----------\n" + + "8. ERROR in I.java (at line 8)\n" + + " public strictfp synchronized @Annot void foo5();\n" + + " ^^^^^^\n" + + "strictfp is not permitted for abstract interface method foo5\n" + + "----------\n" + + "9. ERROR in I.java (at line 8)\n" + + " public strictfp synchronized @Annot void foo5();\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo5; only public, private, abstract, default, static and strictfp are permitted\n" + + "----------\n"; + runNegativeTest( + new String[] { + "I.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.METHOD) @interface Annot{}\n" + + "public interface I {\n" + + " void foo1();\n" + + " public synchronized void foo2();\n" + + " strictfp void foo3();\n" + + " public strictfp synchronized void foo4();\n" + + " public strictfp synchronized @Annot void foo5();\n" + + "}\n"}, + op); + } + + // default & regular methods with modifiers that are illegal even for default methods + public void testModifiers3() { + String infMod = this.complianceLevel >= ClassFileConstants.JDK9 ? " private," : ""; + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " native void foo1();\n" + + " static void foo2();\n" + + " native default void foo3() {}\n" + + " default native void foo4() {}\n" + + " static default void foo5() {}\n" + + " default static void foo6() {}\n" + + "}\n"}, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " native void foo1();\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo1; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "2. ERROR in I.java (at line 3)\n" + + " static void foo2();\n" + + " ^^^^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n" + + "3. ERROR in I.java (at line 4)\n" + + " native default void foo3() {}\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo3; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "4. ERROR in I.java (at line 5)\n" + + " default native void foo4() {}\n" + + " ^^^^^^\n" + + "Illegal modifier for the interface method foo4; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "5. ERROR in I.java (at line 6)\n" + + " static default void foo5() {}\n" + + " ^^^^^^\n" + + "Illegal combination of modifiers for the interface method foo5; only one of abstract, default, or static permitted\n" + + "----------\n" + + "6. ERROR in I.java (at line 7)\n" + + " default static void foo6() {}\n" + + " ^^^^^^\n" + + "Illegal combination of modifiers for the interface method foo6; only one of abstract, default, or static permitted\n" + + "----------\n"); + } + + // if an interface methods is explicitly "abstract" it cannot have a (default) body + public void testModifiers4() { + runNegativeTest( + new String[] { + "I.java", + "import java.lang.annotation.*;\n" + + "public interface I {\n" + + " abstract void foo1();\n" + // OK + " public abstract default void foo2() {}\n" + + " default abstract void foo3() {}\n" + + " void foo4() { }\n" + // implicit "abstract" without "default" doesn't allow a body, either + " abstract static default void foo5() {}\n" + // double fault + "}\n"}, + "----------\n" + + "1. ERROR in I.java (at line 4)\n" + + " public abstract default void foo2() {}\n" + + " ^^^^^^\n" + + "Illegal combination of modifiers for the interface method foo2; only one of abstract, default, or static permitted\n" + + "----------\n" + + "2. ERROR in I.java (at line 5)\n" + + " default abstract void foo3() {}\n" + + " ^^^^^^\n" + + "Illegal combination of modifiers for the interface method foo3; only one of abstract, default, or static permitted\n" + + "----------\n" + + "3. ERROR in I.java (at line 6)\n" + + " void foo4() { }\n" + + " ^^^^^^\n" + + "Abstract methods do not specify a body\n" + + "----------\n" + + "4. ERROR in I.java (at line 7)\n" + + " abstract static default void foo5() {}\n" + + " ^^^^^^\n" + + "Illegal combination of modifiers for the interface method foo5; only one of abstract, default, or static permitted\n" + + "----------\n"); + } + + // class implements interface with default method. + // - no need to implement this interface method as it is not abstract + public void testModifiers5() { + runConformTest( + new String[] { + "C.java", + "public class C implements I {\n" + + " public static void main(String[] args) {\n" + + " new C().foo();\n" + + " }\n" + + "}\n", + "I.java", + "public interface I {\n" + + " default void foo() {\n" + + " System.out.println(\"default\");\n" + + " }\n" + + "}\n" + }, + "default" + ); + } + + // class implements interface with default method. + // - no need to implement this interface method as it is not abstract, but other abstract method exists + public void testModifiers6() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " default void foo() {}\n" + + " void bar();\n" + + "}\n", + "C.java", + "public class C implements I {}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 1)\n" + + " public class C implements I {}\n" + + " ^\n" + + "The type C must implement the inherited abstract method I.bar()\n" + + "----------\n"); + } + + // a default method has a semicolon body / an undocumented empty body + public void testModifiers7() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNDOCUMENTED_EMPTY_BLOCK, JavaCore.ERROR); + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " default void foo();\n" + + " default void bar() {}\n" + + " default void zork() { /* nop */ }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " default void foo();\n" + + " ^^^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n" + + "2. ERROR in I.java (at line 3)\n" + + " default void bar() {}\n" + + " ^^\n" + + "Empty block should be documented\n" + + "----------\n", + null/*classLibs*/, + true/*shouldFlush*/, + options); + } + + // JLS 9.4.2 - default method cannot override method from Object + // Bug 382355 - [1.8][compiler] Compiler accepts erroneous default method + // new error message + public void testObjectMethod1() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " public default String toString () { return \"\";}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " public default String toString () { return \"\";}\n" + + " ^^^^^^^^^^^\n" + + "A default method cannot override a method from java.lang.Object \n" + + "----------\n"); + } + + // JLS 9.4.2 - default method cannot override method from Object + // Bug 382355 - [1.8][compiler] Compiler accepts erroneous default method + // when using a type variable this is already reported as a name clash + public void testObjectMethod2() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " public default boolean equals (T other) { return false;}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " public default boolean equals (T other) { return false;}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method equals(T) of type I has the same erasure as equals(Object) of type Object but does not override it\n" + + "----------\n"); + } + + // JLS 9.4.2 - default method cannot override method from Object + // Bug 382355 - [1.8][compiler] Compiler accepts erroneous default method + // one error for final method is enough + public void testObjectMethod3() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " @Override\n" + + " default public Class getClass() { return null;}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 3)\n" + + " default public Class getClass() { return null;}\n" + + " ^^^^^^^^^^\n" + + "Cannot override the final method from Object\n" + + "----------\n"); + } + + // JLS 9.4.1 + // Bug 382347 - [1.8][compiler] Compiler accepts incorrect default method inheritance + // an inherited default methods clashes with another inherited method + // simple case + public void testInheritedDefaultOverrides01() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " String foo();\n" + + "}\n", + "I2.java", + "public interface I2 {\n" + + " default String foo() { return \"\"; }\n" + + "}\n", + "I3.java", + "public interface I3 extends I1, I2 {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in I3.java (at line 1)\n" + + " public interface I3 extends I1, I2 {\n" + + " ^^\n" + + "The default method foo() inherited from I2 conflicts with another method inherited from I1\n" + + "----------\n"); + } + + // JLS 9.4.1 + // Bug 382347 - [1.8][compiler] Compiler accepts incorrect default method inheritance + // an inherited default methods clashes with another inherited method + // indirect inheritance + public void testInheritedDefaultOverrides02() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " String foo();\n" + + "}\n", + "I2.java", + "public interface I2 {\n" + + " default String foo() { return \"\"; }\n" + + "}\n", + "I1A.java", + "public interface I1A extends I1 {\n" + + "}\n", + "I2A.java", + "public interface I2A extends I2 {\n" + + "}\n", + "I3.java", + "public interface I3 extends I1A, I2A {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in I3.java (at line 1)\n" + + " public interface I3 extends I1A, I2A {\n" + + " ^^\n" + + "The default method foo() inherited from I2 conflicts with another method inherited from I1\n" + + "----------\n"); + } + + // JLS 9.4.1 + // Bug 382347 - [1.8][compiler] Compiler accepts incorrect default method inheritance + // Parameterized case is already reported as a clash + public void testInheritedDefaultOverrides03() { + runNegativeTest( + new String[] { + "I1.java", + "import java.util.List;\n" + + "public interface I1 {\n" + + " String foo(List l);\n" + + "}\n", + "I2.java", + "import java.util.List;\n" + + "public interface I2 {\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " default String foo(List l) { return \"\"; }\n" + + "}\n", + "I3.java", + "import java.util.List;\n" + + "public interface I3 extends I1, I2 {\n" + + " @Override\n" + + " String foo(List l);\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in I3.java (at line 4)\n" + + " String foo(List l);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(List) of type I3 has the same erasure as foo(List) of type I2 but does not override it\n" + + "----------\n"); + } + + // JLS 9.4.1 + // Bug 382347 - [1.8][compiler] Compiler accepts incorrect default method inheritance + // Parameterized case is already reported as a clash - inverse case of previous + public void testInheritedDefaultOverrides04() { + runNegativeTest( + new String[] { + "I1.java", + "import java.util.List;\n" + + "public interface I1 {\n" + + " default String foo(List l) { return \"\"; }\n" + + "}\n", + "I2.java", + "import java.util.List;\n" + + "public interface I2 {\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " String foo(List l);\n" + + "}\n", + "I3.java", + "import java.util.List;\n" + + "public interface I3 extends I1, I2 {\n" + + " @Override\n" + + " String foo(List l);\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in I3.java (at line 4)\n" + + " String foo(List l);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(List) of type I3 has the same erasure as foo(List) of type I2 but does not override it\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=390761 + public void testDefaultNonclash() { + runNegativeTest( + new String[] { + "X.java", + "public interface X extends Map {\n" + + " Zork z;\n" + + "}\n" + + "\n" + + "interface Map extends MapStream {\n" + + " @Override\n" + + " default Iterable> asIterable() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "interface MapStream {\n" + + " Iterable> asIterable();\n" + + "}\n" + + "\n" + + "interface BiValue {\n" + + " T getKey();\n" + + " U getValue();\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"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=390761 + public void testDefaultNonclash2() { + runNegativeTest( + new String[] { + "X.java", + "public interface X extends Map {\n" + + " Zork z;\n" + + "}\n" + + "\n" + + "interface Map extends MapStream {\n" + + " @Override\n" + + " Iterable> asIterable();\n" + + "}\n" + + "interface MapStream {\n" + + " default Iterable> asIterable() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface BiValue {\n" + + " T getKey();\n" + + " U getValue();\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"); + } + + public void testDefaultNonclash3() { + runNegativeTest( + new String[] { + "X.java", + "public interface X extends Map {\n" + + " Zork z;\n" + + "}\n" + + "\n" + + "interface Map extends MapStream {\n" + + " @Override\n" + + " default Iterable> asIterable() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "interface MapStream {\n" + + " default Iterable> asIterable() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface BiValue {\n" + + " T getKey();\n" + + " U getValue();\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"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=390761 + public void testDefaultNonclash4() { + runNegativeTest( + new String[] { + "X.java", + "public interface X extends Map {\n" + + " Zork z;\n" + + "}\n" + + "\n" + + "interface Map extends MapStream {\n" + + " @Override\n" + + " Iterable> asIterable();\n" + + "}\n" + + "interface MapStream {\n" + + " Iterable> asIterable();\n" + + "}\n" + + "\n" + + "interface BiValue {\n" + + " T getKey();\n" + + " U getValue();\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"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=420080 + public void testDefaultNonclash5() { + runConformTest( + new String[] { + "X.java", + "public class X extends G implements I {\n" + + "}\n" + + "\n" + + "interface I {\n" + + " default int foo (){\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "\n" + + "class G {\n" + + " public int foo() {\n" + + " return 0;\n" + + " }\n" + + "}\n" + }); + } + + // JLS 9.4.1 + // Bug 382347 - [1.8][compiler] Compiler accepts incorrect default method inheritance + // Don't report conflict between the same method inherited on two paths. + public void testInheritedDefaultOverrides05() { + runConformTest( + new String[] { + "StringList.java", + "import java.util.Collection;\n" + + "public abstract class StringList implements Collection {\n" + + "}\n" + }, + ""); + } + + // JLS 9.4.1 + // Bug 382347 - [1.8][compiler] Compiler accepts incorrect default method inheritance + // extract from SuperTypeTest.test013(): + public void testInheritedDefaultOverrides06() { + runConformTest( + new String[] { + "IterableList.java", + "import java.util.*;\n" + + "public interface IterableList extends Iterable, List {}\n" + + "interface ListIterable extends Iterable, List {}\n" + + "\n" + }, + ""); + } + + // JLS 8.1.1.1 abstract Classes + // Default method overrides an abstract method from its super interface + public void testAbstract01() { + runConformTest( + new String[] { + "I2.java", + "public interface I2 {\n" + + " void test();\n" + + "}\n", + "I1.java", + "public interface I1 extends I2 {\n" + + " default void test() {}\n" + + "}\n", + "C.java", + "public class C implements I1 {\n" + + "}\n" + }); + } + + // JLS 8.1.1.1 abstract Classes + // Default method conflicts with independent interface method + public void testAbstract02() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " void test();\n" + + "}\n", + "I2.java", + "public interface I2 {\n" + + " default void test() {}\n" + + "}\n", + "C.java", + "public class C implements I1, I2 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 1)\n" + + " public class C implements I1, I2 {\n" + + " ^\n" + + "The default method test() inherited from I2 conflicts with another method inherited from I1\n" + + "----------\n"); + // Note: javac first complains: C is not abstract and does not override abstract method test() in I1 + // only when C is marked abstract does the conflict between abstract and default method surface + } + + // JLS 8.1.1.1 abstract Classes + // Default method conflicts independent interface method + // same as above except for order of implements list + public void testAbstract02a() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " void test();\n" + + "}\n", + "I2.java", + "public interface I2 {\n" + + " default void test() {}\n" + + "}\n", + "C.java", + "public class C implements I2, I1 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 1)\n" + + " public class C implements I2, I1 {\n" + + " ^\n" + + "The default method test() inherited from I2 conflicts with another method inherited from I1\n" + + "----------\n"); + // Note: javac first complains: C is not abstract and does not override abstract method test() in I1 + // only when C is marked abstract does the conflict between abstract and default method surface + } + + // JLS 8.1.1.1 abstract Classes + // Default method does not override independent abstract method + // class is abstract + public void testAbstract02b() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " void test();\n" + + "}\n", + "I2.java", + "public interface I2 {\n" + + " default void test() {}\n" + + "}\n", + "C.java", + "public abstract class C implements I2, I1 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 1)\n" + + " public abstract class C implements I2, I1 {\n" + + " ^\n" + + "The default method test() inherited from I2 conflicts with another method inherited from I1\n" + + "----------\n"); + } + + // same as above but only interfaces + public void testAbstract02c() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " void test();\n" + + "}\n", + "I2.java", + "public interface I2 {\n" + + " default void test() {}\n" + + "}\n", + "I3.java", + "public interface I3 extends I1, I2 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I3.java (at line 1)\n" + + " public interface I3 extends I1, I2 {\n" + + " ^^\n" + + "The default method test() inherited from I2 conflicts with another method inherited from I1\n" + + "----------\n"); + } + + // JLS 8.1.1.1 abstract Classes + // Default method overrides an abstract method from its super interface - class implements both + public void testAbstract03() { + runConformTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " void test();\n" + + "}\n", + "I2.java", + "public interface I2 extends I1 {\n" + + " @Override\n" + + " default void test() {}\n" + + "}\n", + "C.java", + "public class C implements I1, I2 {\n" + + "}\n" + }); + } + + // JLS 8.1.1.1 abstract Classes + // Default method overrides an abstract method from its super interface - class implements both + // same as above except for order of implements list + public void testAbstract03a() { + runConformTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " void test();\n" + + "}\n", + "I2.java", + "public interface I2 extends I1 {\n" + + " @Override\n" + + " default void test() {}\n" + + "}\n", + "C.java", + "public class C implements I2, I1 {\n" + + "}\n" + }); + } + + // JLS 8.1.1.1 abstract Classes + // default method is not inherited because a more specific abstract method is. + public void testAbstract04() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " default void test() {}\n" + + "}\n", + "I2.java", + "public interface I2 extends I1 {\n" + + " @Override\n" + + " void test();\n" + + "}\n", + "C.java", + "public class C implements I2, I1 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 1)\n" + + " public class C implements I2, I1 {\n" + + " ^\n" + + "The type C must implement the inherited abstract method I2.test()\n" + + "----------\n"); + } + + // JLS 8.1.1.1 abstract Classes + // default method is not inherited because a more specific abstract method is. + // same as above except for order of implements list + public void testAbstract04a() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " default void test() {}\n" + + "}\n", + "I2.java", + "public interface I2 extends I1 {\n" + + " @Override\n" + + " void test();\n" + + "}\n", + "C.java", + "public class C implements I2, I1 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 1)\n" + + " public class C implements I2, I1 {\n" + + " ^\n" + + "The type C must implement the inherited abstract method I2.test()\n" + + "----------\n"); + } + + // abstract class method trumps otherwise conflicting default methods: the conflict scenario + public void testAbstract05() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " default String value1() { return null; }\n" + + "}\n", + "I2.java", + "public interface I2 {\n" + + " default String value1() { return \"\"; }\n" + // conflicts with other default method + "}\n", + "C2.java", + "public abstract class C2 implements I1, I2 {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in C2.java (at line 1)\n" + + " public abstract class C2 implements I1, I2 {\n" + + " ^^\n" + + "Duplicate default methods named value1 with the parameters () and () are inherited from the types I2 and I1\n" + + "----------\n"); + } + + // abstract class method trumps otherwise conflicting default methods: conflict resolved + public void testAbstract06() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " default String value1() { return null; }\n" + + "}\n", + "I2.java", + "public interface I2 {\n" + + " default String value1() { return \"\"; }\n" + // conflicts with other default method + "}\n", + "C1.java", + "public abstract class C1 {\n" + + " abstract Object value1();\n" + // trumps the conflicting methods (without overriding) + "}\n", + "C2.java", + "public abstract class C2 extends C1 implements I1, I2 {\n" + + "}\n", + "C3.java", + "public class C3 extends C2 {\n" + + " @Override\n" + + " public Object value1() { return this; } // too week, need a method returning String\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C3.java (at line 3)\n" + + " public Object value1() { return this; } // too week, need a method returning String\n" + + " ^^^^^^\n" + + "The return type is incompatible with I1.value1()\n" + + "----------\n" + + "2. ERROR in C3.java (at line 3)\n" + + " public Object value1() { return this; } // too week, need a method returning String\n" + + " ^^^^^^\n" + + "The return type is incompatible with I2.value1()\n" + + "----------\n"); + } + + // abstract class method trumps otherwise conflicting default methods: conflict resolved + // variant: second method is not a default method + public void testAbstract06a() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " default String value1() { return null; }\n" + + "}\n", + "I2.java", + "public interface I2 {\n" + + " String value1();\n" + // conflicts with other default method + "}\n", + "C1.java", + "public abstract class C1 {\n" + + " abstract Object value1();\n" + // trumps the conflicting methods (without overriding) + "}\n", + "C2.java", + "public abstract class C2 extends C1 implements I1, I2 {\n" + + "}\n", + "C3.java", + "public class C3 extends C2 {\n" + + " @Override\n" + + " public Object value1() { return this; } // too week, need a method returning String\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C3.java (at line 3)\n" + + " public Object value1() { return this; } // too week, need a method returning String\n" + + " ^^^^^^\n" + + "The return type is incompatible with I2.value1()\n" + + "----------\n" + + "2. ERROR in C3.java (at line 3)\n" + + " public Object value1() { return this; } // too week, need a method returning String\n" + + " ^^^^^^\n" + + "The return type is incompatible with I1.value1()\n" + + "----------\n"); + } + + // abstract class method trumps otherwise conflicting default methods: conflict not resolved due to insufficient visibility + public void testAbstract6b() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " default String value1() { return null; }\n" + + "}\n", + "I2.java", + "public interface I2 {\n" + + " default String value1() { return \"\"; }\n" + // conflicts with other default method + "}\n", + "p1/C1.java", + "package p1;\n" + + "public abstract class C1 {\n" + + " abstract Object value1();\n" + // trump with package visibility doesn't work + "}\n", + "C2.java", + "public abstract class C2 extends p1.C1 implements I1, I2 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C2.java (at line 1)\n" + + " public abstract class C2 extends p1.C1 implements I1, I2 {\n" + + " ^^\n" + + "Duplicate default methods named value1 with the parameters () and () are inherited from the types I2 and I1\n" + + "----------\n"); + } + + // abstract class method trumps otherwise conflicting default method: only one default method + public void testAbstract07() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " default String value1() { return null; }\n" + + "}\n", + "C1.java", + "public abstract class C1 {\n" + + " abstract Object value1();\n" + // trumps the conflicting method (without overriding) + "}\n", + "C2.java", + "public abstract class C2 extends C1 implements I1 {\n" + + "}\n", + "C3.java", + "public class C3 extends C2 {\n" + + " @Override\n" + + " public Object value1() { return this; } // too week, need a method returning String\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C3.java (at line 3)\n" + + " public Object value1() { return this; } // too week, need a method returning String\n" + + " ^^^^^^\n" + + "The return type is incompatible with I1.value1()\n" + + "----------\n"); + } + + // class inherits two override equivalent methods, + // must be declared abstract, although one of the methods is a default method. + public void testAbstract08() { + runNegativeTest( + new String[] { + "I1.java", + "public interface I1 {\n" + + " default String value() { return null; }\n" + + "}\n", + "C1.java", + "public abstract class C1 {\n" + + " public abstract String value();" + + "}\n", + "C2.java", + "public class C2 extends C1 implements I1 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C2.java (at line 1)\n" + + " public class C2 extends C1 implements I1 {\n" + + " ^^\n" + + "The type C2 must implement the inherited abstract method C1.value()\n" + + "----------\n"); + } + + // an annotation type cannot have default methods + public void testAnnotation1() { + runNegativeTest( + new String[] { + "I.java", + "public @interface I {\n" + + " default String id() { return \"1\"; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " default String id() { return \"1\"; }\n" + + " ^^^^^^^\n" + + "Syntax error on token \"default\", @ expected\n" + + "----------\n"); + } + + // basic situation similar to AmbiguousMethodTest.test009() + public void testSuperCall1() throws Exception { + this.runConformTest( + new String[] { + "OrderedSet.java", + "import java.util.*;\n" + + "import java.util.stream.Stream;\n" + + "public interface OrderedSet extends List, Set {\n" + + " @Override\n" + + " boolean add(E o);\n" + + " @Override\n" + + " default Spliterator spliterator() { if (true) return List.super.spliterator(); else return Set.super.spliterator(); }\n" + + "}\n" + }, + "" + ); + String expectedOutput = + " // Method descriptor #14 ()Ljava/util/Spliterator;\n" + + " // Signature: ()Ljava/util/Spliterator;\n" + + " // Stack: 1, Locals: 1\n" + + " public java.util.Spliterator spliterator();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.util.List.spliterator() : java.util.Spliterator [17]\n" + + " 4 areturn\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "OrderedSet.class", "OrderedSet", expectedOutput); + } + + // some illegal cases + // - call to indirect super + // - call to super of outer + // - target method is not a default method + // - attempt to use this syntax for a super-ctor call + public void testSuperCall2() { + this.runNegativeTest( + new String[] { + "T.java", + "import java.util.*;\n" + + "import java.util.stream.Stream;\n" + + "public abstract class T implements OrderedSet {\n" + + " @Override\n" + + " public Stream stream() {\n" + + " return List.super.stream(); // List is not a direct super interface\n" + + " }\n" + + " @Override\n" + + " public Stream parallelStream() { return OrderedSet.super.parallelStream();}\n" + // OK + " class Inner {\n" + + " public Stream stream() {\n" + + " return OrderedSet.super.stream(); // not a super interface of the direct enclosing class\n" + + " }\n" + + " }\n" + + " @Override\n" + + " public boolean add(E o) {\n" + + " OrderedSet.super.add(o); // target not a default method\n" + + " }\n" + + " T() {\n" + + " OrderedSet.super(); // not applicable for super ctor call\n" + + " }\n" + + "}\n" + + "interface OrderedSet extends List, Set {\n" + + " @Override\n" + + " boolean add(E o);\n" + + " @Override\n" + + " default Spliterator spliterator() { return List.super.spliterator(); }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in T.java (at line 6)\n" + + " return List.super.stream(); // List is not a direct super interface\n" + + " ^^^^^^^^^^\n" + + "Illegal reference to super type List, cannot bypass the more specific direct super type OrderedSet\n" + + "----------\n" + + "2. ERROR in T.java (at line 12)\n" + + " return OrderedSet.super.stream(); // not a super interface of the direct enclosing class\n" + + " ^^^^^^^^^^^^^^^^\n" + + "No enclosing instance of the type OrderedSet is accessible in scope\n" + + "----------\n" + + "3. ERROR in T.java (at line 17)\n" + + " OrderedSet.super.add(o); // target not a default method\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot directly invoke the abstract method add(E) for the type OrderedSet\n" + + "----------\n" + + "4. ERROR in T.java (at line 20)\n" + + " OrderedSet.super(); // not applicable for super ctor call\n" + + " ^^^^^^^^^^\n" + + "Illegal enclosing instance specification for type Object\n" + + "----------\n" + ); + } + + // with execution + public void testSuperCall3() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I2 {\n" + + " @Override\n" + + " public void print() {\n" + + " I2.super.print();\n" + + " System.out.print(\"!\");" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().print();\n" + + " }\n" + + "}\n" + + "interface I1 {\n" + + " default void print() {\n" + + " System.out.print(\"O\");\n" + + " }\n" + + "}\n" + + "interface I2 extends I1 {\n" + + " default void print() {\n" + + " I1.super.print();\n" + + " System.out.print(\"K\");\n" + + " }\n" + + "}\n" + }, + "OK!" + ); + } + + // 15.12.1 + // https://bugs.eclipse.org/404649 - [1.8][compiler] detect illegal reference to indirect or redundant super + public void testSuperCall4() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I2, I1 {\n" + + " @Override\n" + + " public void print() {\n" + + " I1.super.print(); // illegal attempt to skip I2.print()\n" + + " System.out.print(\"!\");" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().print();\n" + + " }\n" + + "}\n" + + "interface I1 {\n" + + " default void print() {\n" + + " System.out.print(\"O\");\n" + + " }\n" + + "}\n" + + "interface I2 extends I1 {\n" + + " @Override default void print() {\n" + + " System.out.print(\"K\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " I1.super.print(); // illegal attempt to skip I2.print()\n" + + " ^^^^^^^^\n" + + "Illegal reference to super type I1, cannot bypass the more specific direct super type I2\n" + + "----------\n" + ); + } + + // 15.12.1 + // https://bugs.eclipse.org/404649 - [1.8][compiler] detect illegal reference to indirect or redundant super + public void testSuperCall5() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I2, I1 {\n" + + " @Override\n" + + " public void print() {\n" + + " I1.super.print(); // illegal attempt to skip I2.print()\n" + + " System.out.print(\"!\");" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().print();\n" + + " }\n" + + "}\n" + + "interface I1 {\n" + + " default void print() {\n" + + " System.out.print(\"O\");\n" + + " }\n" + + "}\n" + + "interface I2 extends I1 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " I1.super.print(); // illegal attempt to skip I2.print()\n" + + " ^^^^^^^^\n" + + "Illegal reference to super type I1, cannot bypass the more specific direct super type I2\n" + + "----------\n" + ); + } + + // 15.12.3 + // https://bugs.eclipse.org/404649 - [1.8][compiler] detect illegal reference to indirect or redundant super + public void testSuperCall6() { + this.runNegativeTest( + new String[] { + "SuperOverride.java", + "interface I0 {\n" + + " default void foo() { System.out.println(\"I0\"); }\n" + + "}\n" + + "\n" + + "interface IA extends I0 {}\n" + + "\n" + + "interface IB extends I0 {\n" + + " @Override default void foo() {\n" + + " System.out.println(\"IB\");\n" + + " }\n" + + "}\n" + + "interface IX extends IA, IB {\n" + + " @Override default void foo() {\n" + + " IA.super.foo(); // illegal attempt to skip IB.foo()\n" + + " }\n" + + "}\n" + + "public class SuperOverride implements IX {\n" + + " public static void main(String[] args) {\n" + + " new SuperOverride().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in SuperOverride.java (at line 14)\n" + + " IA.super.foo(); // illegal attempt to skip IB.foo()\n" + + " ^^^^^^^^^^^^^^\n" + + "Illegal reference to super method foo() from type I0, cannot bypass the more specific override from type IB\n" + + "----------\n" + ); + } + + // Bug 401235 - [1.8][compiler] 'this' reference must be allowed in default methods and local classes + public void testThisReference1() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I1, I2 {\n" + + " @Override\n" + + " public String s1() { return \"O\"; }\n" + + " @Override\n" + + " public String s2() { return \"K\"; }\n" + + " public static void main(String... args) {\n" + + " X x = new X();\n" + + " x.print1();\n" + + " x.print2();\n" + + " }\n" + + "}\n" + + "interface I1 {\n" + + " String s1();" + + " default void print1() {\n" + + " System.out.print(this.s1());\n" + // 'this' as a receiver + " }\n" + + "}\n" + + "interface I2 {\n" + + " String s2();\n" + + " default void print2() {\n" + + " class Inner {\n" + + " String value() { return I2.this.s2(); }\n" + // qualified 'this' refering to the enclosing interface type + " }\n" + + " System.out.print(new Inner().value());\n" + + " }\n" + + "}\n" + }, + "OK" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + // Test for different legal and illegal keywords for static and default methods in interfaces + public void testStaticMethod01() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " static void foo() {}\n" + + " static void foo1();\n" + + " public static default void foo2 () {};\n" + + " abstract static void foo3();\n" + + " abstract static void foo4() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in I.java (at line 3)\n" + + " static void foo1();\n" + + " ^^^^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n" + + "2. ERROR in I.java (at line 4)\n" + + " public static default void foo2 () {};\n" + + " ^^^^^^^\n" + + "Illegal combination of modifiers for the interface method foo2; only one of abstract, default, or static permitted\n" + + "----------\n" + + "3. ERROR in I.java (at line 5)\n" + + " abstract static void foo3();\n" + + " ^^^^^^\n" + + "Illegal combination of modifiers for the interface method foo3; only one of abstract, default, or static permitted\n" + + "----------\n" + + "4. ERROR in I.java (at line 6)\n" + + " abstract static void foo4() {}\n" + + " ^^^^^^\n" + + "Illegal combination of modifiers for the interface method foo4; only one of abstract, default, or static permitted\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + // Test invocation of static methods with different contexts - negative tests + public void testStaticMethod02() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " public static void foo() {\n" + + " bar();\n" + + " this.bar();\n" + + " }\n" + + " public default void bar () {\n" + + " this.foo();\n" + + " }\n" + + "}\n" + + "interface II extends I{\n" + + " public static void foobar() {\n" + + " super.bar();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 3)\n" + + " bar();\n" + + " ^^^\n" + + "Cannot make a static reference to the non-static method bar() from the type I\n" + + "----------\n" + + "2. ERROR in I.java (at line 4)\n" + + " this.bar();\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n" + + "3. ERROR in I.java (at line 7)\n" + + " this.foo();\n" + + " ^^^\n" + + "This static method of interface I can only be accessed as I.foo\n" + + "----------\n" + + "4. ERROR in I.java (at line 12)\n" + + " super.bar();\n" + + " ^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + // Test invocation of static methods with different contexts - positive tests + public void testStaticMethod03() throws Exception { + runConformTest( + new String[] { + "C.java", + "interface I {\n" + + " public static void foo() {\n" + + " System.out.println(\"I#foo() invoked\");\n" + + " }\n" + + "}\n" + + "interface J extends I {\n" + + " public static void foo() {\n" + + " System.out.println(\"J#foo() invoked\");\n" + + " }\n" + + " public default void bar () {\n" + + " foo();\n" + + " }\n" + + "}\n" + + "public class C implements J {\n" + + " public static void main(String[] args) {\n" + + " C c = new C();\n" + + " c.bar();\n" + + " J.foo();\n" + + " I.foo();\n" + + " }\n" + + "}" + }, + "J#foo() invoked\n" + + "J#foo() invoked\n" + + "I#foo() invoked"); + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new C [1]\n" + + " 3 dup\n" + + " 4 invokespecial C() [18]\n" + + " 7 astore_1 [c]\n" + + " 8 aload_1 [c]\n" + + " 9 invokevirtual C.bar() : void [19]\n" + + " 12 invokestatic J.foo() : void [22]\n" + + " 15 invokestatic I.foo() : void [25]\n" + + " 18 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 16]\n" + + " [pc: 8, line: 17]\n" + + " [pc: 12, line: 18]\n" + + " [pc: 15, line: 19]\n" + + " [pc: 18, line: 20]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 19] local: c index: 1 type: C\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "C.class", "C", expectedOutput); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + // Test invocation of static methods with different contexts - negative tests + public void testStaticMethod04() { + runNegativeTest( + new String[] { + "X.java", + "public class X implements II {\n" + + " @Override" + + " public void foo() {\n" + + " bar();\n" + + " bar2();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " bar();\n" + + " II.bar();\n" + + " (new X()).bar();\n" + + " II.bar();\n" + + " II ii = new X();\n" + + " ii.bar();\n" + + " ii.bar2();\n" + + " I i = new X();\n" + + " i.bar();\n" + + " new I() {}.foo();\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public static void bar() {\n" + + " bar2();\n" + + " }\n" + + " public default void bar2() {\n" + + " bar();\n" + + " }\n" + + "}\n" + + "interface II extends I {\n" + + " public default void foo() {\n" + + " bar();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " II.bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type II\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " (new X()).bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " II.bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type II\n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " ii.bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type II\n" + + "----------\n" + + "7. ERROR in X.java (at line 15)\n" + + " i.bar();\n" + + " ^^^\n" + + "This static method of interface I can only be accessed as I.bar\n" + + "----------\n" + + "8. ERROR in X.java (at line 16)\n" + + " new I() {}.foo();\n" + + " ^^^\n" + + "The method foo() is undefined for the type new I(){}\n" + + "----------\n" + + "9. ERROR in X.java (at line 21)\n" + + " bar2();\n" + + " ^^^^\n" + + "Cannot make a static reference to the non-static method bar2() from the type I\n" + + "----------\n" + + "10. ERROR in X.java (at line 29)\n" + + " bar();\n" + + " ^^^\n" + + "The method bar() is undefined for the type II\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + public void testStaticMethod05() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " static void foo(int x) { }\n" + + "}\n" + + "interface II extends I {\n" + + " static void goo(int x) {} // No Error.\n" + + "}\n" + + "interface III extends II {\n" + + " default void foo(int x, int y) {} // No Error.\n" + + " default void goo() {} // No Error.\n" + + " default void foo(int x) {} // No Error.\n" + + " default void goo(int x) {} // No Error.\n" + + "}\n" + + "class Y {\n" + + " static void goo(int x) {}\n" + + "}\n" + + "class X extends Y {\n" + + " void foo(int x) {} // No error.\n" + + " void goo() {} // No Error.\n" + + " void goo(int x) {} // Error.\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " void goo(int x) {} // Error.\n" + + " ^^^^^^^^^^\n" + + "This instance method cannot override the static method from Y\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + // Test that extending interfaces inherit visible fields and inner types. + public void testStaticMethod06() { + runConformTest( + new String[] { + "C.java", + "interface I {\n" + + " public static String CONST = \"CONSTANT\";\n" + + " public static void foo(String[] args) {\n" + + " System.out.println(args[0]);\n" + + " }\n" + + " public interface Inner {}\n" + + "}\n" + + "interface J extends I {\n" + + " public static void foo() {\n" + + " I.foo(new String[]{CONST});\n" + + " }\n" + + " public interface InnerInner extends Inner {}\n" + + "}\n" + + "public class C implements J {\n" + + " public static void main(String[] args) {\n" + + " J.foo();\n" + + " I.foo(new String[]{\"LITERAL\"});\n" + + " }\n" + + "}" + }, + "CONSTANT\n" + + "LITERAL"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + // Test that type parameter from enclosing type is not allowed to be referred to in static interface methods + public void testStaticMethod07() { + runNegativeTest( + new String[] { + "C.java", + "interface I {\n" + + " public static T foo(T t) {\n" + + " return t;" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 2)\n" + + " public static T foo(T t) {\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "2. ERROR in C.java (at line 2)\n" + + " public static T foo(T t) {\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + public void testStaticMethod08() { + runNegativeTest( + new String[] { + "C.java", + "@interface A {\n" + + " static String foo() default \"Blah\";\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 2)\n" + + " static String foo() default \"Blah\";\n" + + " ^^^^^\n" + + "Illegal modifier for the annotation attribute A.foo; only public & abstract are permitted\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + public void testStaticMethod09() { + runNegativeTest( + new String[] { + "C.java", + "interface A {\n" + + " static void foo() {}\n" + + " default void goo(A a) {\n" + + " a.foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 4)\n" + + " a.foo();\n" + + " ^^^\n" + + "This static method of interface A can only be accessed as A.foo\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + public void testStaticMethod10() { + runNegativeTest( + new String[] { + "C.java", + "interface A {\n" + + " static void foo(long x) {}\n" + + " static void foo(int x) {}\n" + + " default void goo(A a) {\n" + + " a.foo(10);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 5)\n" + + " a.foo(10);\n" + + " ^^^\n" + + "This static method of interface A can only be accessed as A.foo\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + public void testStaticMethod11() { + runNegativeTest( + new String[] { + "C.java", + "interface A {\n" + + " void foo(X x);\n" + + "}\n" + + "interface B extends A {\n" + + " static void foo(String s) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 5)\n" + + " static void foo(String s) {}\n" + + " ^^^^^^^^^^^^^\n" + + "This static method cannot hide the instance method from A\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + public void testStaticMethod12() { + runNegativeTest( + new String[] { + "C.java", + "interface A {\n" + + " static void foo(String x) {}\n" + + "}\n" + + "interface B extends A {\n" + + " static void foo(String s) {}\n" + + "}\n" + + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in C.java (at line 1)\n" + + " interface A {\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. ERROR in C.java (at line 7)\n" + + " public class X {\n" + + " ^\n" + + "The public type X must be defined in its own file\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399780 + public void testStaticMethod13() { + runNegativeTest( + new String[] { + "C.java", + "interface A {\n" + + " static void foo(String x) {\n" + + " System.out.println(this);\n"+ + " System.out.println(super.hashCode());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 3)\n" + + " System.out.println(this);\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n" + + "2. ERROR in C.java (at line 4)\n" + + " System.out.println(super.hashCode());\n" + + " ^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=406619, [1.8][compiler] Incorrect suggestion that method can be made static. + public void test406619() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n" + + " default int foo() {\n" + + " return 10;\n" + + " }\n" + + "}\n" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); + } + + // class implements interface with default method. + // - witness for NoSuchMethodError in synthetic method (SuperMethodAccess) - turned out to be a JVM bug + public void testSuperAccess01() { + runConformTest( + new String[] { + "C.java", + "interface I {\n" + + " public default void foo() {\n" + + " System.out.println(\"default\");\n" + + " }\n" + + "}\n" + + "public class C implements I {\n" + + " public static void main(String[] args) {\n" + + " C c = new C();\n" + + " c.foo();\n" + + " }\n" + + "}\n" + }, + "default" + ); + } + + // class implements interface with default method. + // - intermediate public interface + public void testSuperAccess02() { + runConformTest( + new String[] { + "p1/C.java", + "package p1;\n" + + "public class C implements p2.J {\n" + + " public static void main(String[] args) {\n" + + " C c = new C();\n" + + " c.foo();\n" + + " }\n" + + "}\n", + "p2/J.java", + "package p2;\n" + + "interface I {\n" + + " public default void foo() {\n" + + " System.out.println(\"default\");\n" + + " }\n" + + "}\n" + + "public interface J extends I {}\n" + }, + "default"); + } + + // https://bugs.eclipse.org/421796 - Bug 421796 - [1.8][compiler] java.lang.AbstractMethodError executing default method code. + public void testSuperAccess03() { + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(); \n" + + "}\n" + + "\n" + + "interface J extends I {\n" + + " default void foo() {\n" + + " }\n" + + "}\n" + + "\n" + + "interface K extends J {\n" + + "}\n" + + "\n" + + "public class X implements K {\n" + + " public static void main(String argv[]) {\n" + + " X test = new X();\n" + + " ((J)test).foo();\n" + + " test.foo();\n" + + " }\n" + + "}\n" + }); + } + + // Variant of test MethodVerifyTest.test144() from https://bugs.eclipse.org/bugs/show_bug.cgi?id=194034 + public void testBridge01() { + this.runNegativeTest( + new String[] { + "PurebredCatShopImpl.java", + "import java.util.List;\n" + + "interface Pet {}\n" + + "interface Cat extends Pet {}\n" + + "interface PetShop { default List getPets() { return null; } }\n" + + "interface CatShop extends PetShop {\n" + + " default List getPets() { return null; }\n" + + "}\n" + + "interface PurebredCatShop extends CatShop {}\n" + + "class CatShopImpl implements CatShop {\n" + + " @Override public List getPets() { return null; }\n" + + "}\n" + + "class PurebredCatShopImpl extends CatShopImpl implements PurebredCatShop {}" + }, + "----------\n" + + "1. ERROR in PurebredCatShopImpl.java (at line 6)\n" + + " default List getPets() { return null; }\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" + + " @Override public List getPets() { return null; }\n" + + " ^^^^\n" + + "Type safety: The return type List for getPets() from the type CatShopImpl needs unchecked conversion to conform to List from the type CatShop\n" + + "----------\n" + ); + } + // yet another variant, checking that exactly one bridge method is created, so that + // the most specific method is dynamically invoked via all declared types. + public void testBridge02() { + this.runConformTest( + new String[] { + "PurebredCatShopImpl.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "interface Pet {}\n" + + "interface Cat extends Pet {}\n" + + "interface PetShop { default List getPets() { return null; } }\n" + + "interface CatShop extends PetShop {\n" + + " @Override default ArrayList getPets() { return null; }\n" + + "}\n" + + "interface PurebredCatShop extends CatShop {}\n" + + "class CatShopImpl implements CatShop {\n" + + " @Override public ArrayList getPets() { return new ArrayList<>(); }\n" + + "}\n" + + "public class PurebredCatShopImpl extends CatShopImpl implements PurebredCatShop {\n" + + " public static void main(String... args) {\n" + + " PurebredCatShopImpl pcsi = new PurebredCatShopImpl();\n" + + " System.out.print(pcsi.getPets().size());\n" + + " CatShopImpl csi = pcsi;\n" + + " System.out.print(csi.getPets().size());\n" + + " CatShop cs = csi;\n" + + " System.out.print(cs.getPets().size());\n" + + " PetShop ps = cs;\n" + + " System.out.print(ps.getPets().size());\n" + + " }\n" + + "}\n" + }, + "0000" + ); + } + + // modeled after org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest.test081() + // see https://bugs.eclipse.org/391376 - [1.8] check interaction of default methods with bridge methods and generics + // see https://bugs.eclipse.org/404648 - [1.8][compiler] investigate differences between compilers re AmbiguousMethodTest + public void _testBridge03() { + runConformTest( + new String[] { + "C.java", + "interface A extends\n" + + " I {\n" + + "\n" + + " @Override\n" + + " public default void doSet(ModelType valueGetter) {\n" + + " this.set((ValueType) valueGetter.getObject());\n" + + " }\n" + + "\n" + + " @Override\n" + + " public default void set(Object object) {\n" + + " System.out.println(\"In A.set(Object)\");\n" + + " }\n" + + "}\n" + + "\n" + + "class B implements A {\n" + + "\n" + + " public void set(CharSequence string) {\n" + + " System.out.println(\"In B.set(CharSequence)\");\n" + + " }\n" + + "}\n" + + "\n" + + "public class C extends B {\n" + + "\n" + + " static public void main(String[] args) {\n" + + " C c = new C();\n" + + " c.run();\n" + + " }\n" + + "\n" + + " public void run() {\n" + + " E e = new E(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class E extends D {\n" + + "\n" + + " private Class typeClass;\n" + + "\n" + + " public E(Class typeClass) {\n" + + " this.typeClass = typeClass;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public Type getObject() {\n" + + " try {\n" + + " return (Type) typeClass.newInstance();\n" + + " } catch (Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "interface I {\n" + + "\n" + + " public void doSet(ModelType model);\n" + + "\n" + + " public void set(ValueType value);\n" + + "\n" + + "}\n" + }, + "In B.set(CharSequence)"); + } + + + // modeled after org.eclipse.jdt.core.tests.compiler.regression.AmbiguousMethodTest.test081() + // see https://bugs.eclipse.org/391376 - [1.8] check interaction of default methods with bridge methods and generics + // see https://bugs.eclipse.org/404648 - [1.8][compiler] investigate differences between compilers re AmbiguousMethodTest + public void _testBridge04() { + runConformTest( + new String[] { + "C.java", + "interface A extends\n" + + " I {\n" + + "\n" + + " @Override\n" + + " public default void doSet(ModelType valueGetter) {\n" + + " this.set((ValueType) valueGetter.getObject());\n" + + " }\n" + + "\n" + + " @Override\n" + + " public default void set(Object object) {\n" + + " System.out.println(\"In A.set(Object)\");\n" + + " }\n" + + "}\n" + + "\n" + + "interface B extends A {\n" + + "\n" + + " public default void set(CharSequence string) {\n" + + " System.out.println(\"In B.set(CharSequence)\");\n" + + " }\n" + + "}\n" + + "\n" + + "public class C implements B {\n" + + "\n" + + " static public void main(String[] args) {\n" + + " C c = new C();\n" + + " c.run();\n" + + " }\n" + + "\n" + + " public void run() {\n" + + " E e = new E(String.class);\n" + + " this.doSet(e);\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "class D {\n" + + " public Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class E extends D {\n" + + "\n" + + " private Class typeClass;\n" + + "\n" + + " public E(Class typeClass) {\n" + + " this.typeClass = typeClass;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public Type getObject() {\n" + + " try {\n" + + " return (Type) typeClass.newInstance();\n" + + " } catch (Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "interface I {\n" + + "\n" + + " public void doSet(ModelType model);\n" + + "\n" + + " public void set(ValueType value);\n" + + "\n" + + "}\n" + }, + "In B.set(CharSequence)"); + } + + // test for different error messages in modifiers. + public void test400977() { + String infMod = this.complianceLevel >= ClassFileConstants.JDK9 ? " private," : ""; + String extra = this.complianceLevel >= ClassFileConstants.JDK17 ? + "----------\n" + + "2. WARNING in I.java (at line 3)\n" + + " public abstract default strictfp final void bar();}\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n" : ""; + int offset = this.complianceLevel >= ClassFileConstants.JDK17 ? 1 : 0; + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " default abstract void foo();\n" + + " public abstract default strictfp final void bar();" + + "}\n"}, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " default abstract void foo();\n" + + " ^^^^^\n" + + "Illegal combination of modifiers for the interface method foo; only one of abstract, default, or static permitted\n" + + extra + + "----------\n" + + (2 + offset) + ". ERROR in I.java (at line 3)\n" + + " public abstract default strictfp final void bar();}\n" + + " ^^^^^\n" + + "strictfp is not permitted for abstract interface method bar\n" + + "----------\n" + + (3 + offset) + ". ERROR in I.java (at line 3)\n" + + " public abstract default strictfp final void bar();}\n" + + " ^^^^^\n" + + "Illegal combination of modifiers for the interface method bar; only one of abstract, default, or static permitted\n" + + "----------\n" + + (3 + offset) + ". ERROR in I.java (at line 3)\n" + + " public abstract default strictfp final void bar();}\n" + + " ^^^^^\n" + + "Illegal modifier for the interface method bar; only public,"+ infMod +" abstract, default, static and strictfp are permitted\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=420084, [1.8] static interface method cannot be resolved without receiver when imported statically + public void testBug420084() { + runNegativeTest( + new String[] { + "p/J.java", + "package p;\n" + + "public interface J {\n" + + " static int foo(){return 0;}\n" + + "}\n", + "I.java", + "import static p.J.foo;\n" + + "public interface I {\n" + + " static int call() {\n" + + " return foo();\n" + + " }\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421543, [1.8][compiler] Compiler fails to recognize default method being turned into abstract by subtytpe + public void testBug421543() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " default void foo() {}\n" + + "}\n" + + "interface J extends I {\n" + + " void foo();\n" + + "}\n" + + "public class X implements J {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void foo();\n" + + " ^^^^^\n" + + "The method foo() of type J should be tagged with @Override since it actually overrides a superinterface method\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public class X implements J {\n" + + " ^\n" + + "The type X must implement the inherited abstract method J.foo()\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421543, [1.8][compiler] Compiler fails to recognize default method being turned into abstract by subtytpe + public void testBug421543a() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " default void foo(T t) {}\n" + + "}\n" + + "interface J extends I {\n" + + " void foo(J t);\n" + + "}\n" + + "public class X implements J {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void foo(J t);\n" + + " ^^^^^^^^\n" + + "The method foo(J) of type J should be tagged with @Override since it actually overrides a superinterface method\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public class X implements J {\n" + + " ^\n" + + "The type X must implement the inherited abstract method J.foo(J)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421543, [1.8][compiler] Compiler fails to recognize default method being turned into abstract by subtytpe + public void testBug421543b() { + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(T t);\n" + + "}\n" + + "@SuppressWarnings(\"override\")\n" + + "interface J extends I {\n" + + " default void foo(J t) {}\n" + + "}\n" + + "public class X implements J {\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421797, [1.8][compiler] ClassFormatError with default methods & I.super.foo() syntax + public void testBug421797() { + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int m(String s, int val);\n" + + " public default int foo(String s, int val) {\n" + + " System.out.print(s + \" from I.foo:\");\n" + + " return val * val; \n" + + " }\n" + + "}\n" + + "interface T extends I {\n" + + " public default int m(String s, int value) { \n" + + " I i = I.super::foo; \n" + + " return i.foo(s, value);\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) { \n" + + " System.out.println(new T(){}.m(\"Hello\", 1234));\n" + + " }\n" + + "}\n" + }, + "Hello from I.foo:1522756"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=422731, [1.8] Ambiguous method not reported on overridden default method + public void test422731() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Base implements I {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.foo((short)5, (short)10);\n" + + " x.bar((short)5, (short)10);\n" + + " }\n" + + " public void foo(short s, int i) {} // No error, but should have been\n" + + " public void bar(short s, int i) {} // Correctly reported\n" + + "\n" + + "}\n" + + "interface I {\n" + + " public default void foo(int i, short s) {}\n" + + "}\n" + + "class Base {\n" + + " public void bar(int i, short s) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " x.foo((short)5, (short)10);\n" + + " ^^^\n" + + "The method foo(short, int) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " x.bar((short)5, (short)10);\n" + + " ^^^\n" + + "The method bar(short, int) is ambiguous for the type X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=425719, [1.8][compiler] Bogus ambiguous call error from compiler + public void test425719() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " default void foo(Object obj) {\n" + + " System.out.println(\"interface method\");\n" + + " }\n" + + "}\n" + + "class Base {\n" + + " public void foo(Object obj) {\n" + + " System.out.println(\"class method\");\n" + + " }\n" + + "}\n" + + "public class X extends Base implements I {\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(null);\n" + + " }\n" + + "}\n", + }, + "class method"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=425718, [1.8] default method changes access privilege of protected overridden method from Object + public void test425718() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " default Object clone() { return null; };\n" + + "}\n" + + "public class X {\n" + + " public void foo() {\n" + + " I x = new I(){};\n" + + " System.out.println(x.clone());\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I x = new I(){};\n" + + " ^^^\n" + + "The inherited method Object.clone() cannot hide the public abstract method in I\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " I x = new I(){};\n" + + " ^^^\n" + + "Exception CloneNotSupportedException in throws clause of Object.clone() is not compatible with I.clone()\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=426318, [1.8][compiler] Bogus name clash error in the presence of default methods and varargs + public void test426318() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "abstract class Y { \n" + + " public abstract void foo(Object[] x);\n" + + " public abstract void goo(Object[] x);\n" + + "}\n" + + "interface I {\n" + + " default public void foo(T... x) {};\n" + + " public abstract void goo(T ... x);\n" + + "}\n" + + "public abstract class X extends Y implements I { \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " default public void foo(T... x) {};\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter x\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " public abstract void goo(T ... x);\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter x\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=424914, [1.8][compiler] No error shown for method reference with super enclosed in an interface + public void test424914() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface A {\n" + + " String foo();\n" + + " String b = super.toString();\n" + + " default void fun1() {\n" + + " System.out.println((A) super::toString);\n" + + " super.toString();\n" + + " Object.super.toString();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " String b = super.toString();\n" + + " ^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.println((A) super::toString);\n" + + " ^^^^^\n" + + "super reference is illegal in interface context\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " super.toString();\n" + + " ^^^^^\n" + + "super reference is illegal in interface context\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Object.super.toString();\n" + + " ^^^^^^^^^^^^\n" + + "No enclosing instance of the type Object is accessible in scope\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=424914, [1.8][compiler] No error shown for method reference with super enclosed in an interface + public void test424914a() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface B {\n" + + " default void foo() {\n" + + " System.out.println(\"B.foo\");\n" + + " }\n" + + "}\n" + + "interface A extends B {\n" + + " default void foo() {\n" + + " System.out.println(\"A.foo\");\n" + + " B.super.foo();\n" + + " }\n" + + "}\n" + + "public class X implements A {\n" + + " public static void main(String[] args) {\n" + + " A a = new X();\n" + + " a.foo();\n" + + " }\n" + + "}\n", + }, + "A.foo\n" + + "B.foo"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427478, [1.8][compiler] Wrong "Duplicate default methods" error on AbstractDoubleSpliterator + public void test427478() throws Exception { // extracted smaller test case. + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "import java.util.function.DoubleConsumer;\n" + + "public interface X {\n" + + " default void forEachRemaining(Consumer action) {\n" + + " }\n" + + " public interface OfPrimitive> extends X {\n" + + " default void forEachRemaining(T_CONS action) {\n" + + " }\n" + + " }\n" + + " public interface OfDouble extends OfPrimitive {\n" + + " default void forEachRemaining(Consumer action) {\n" + + " }\n" + + " default void forEachRemaining(DoubleConsumer action) {\n" + + " }\n" + + " }\n" + + "}\n" + + "abstract class AbstractDoubleSpliterator implements X.OfDouble {\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427478, [1.8][compiler] Wrong "Duplicate default methods" error on AbstractDoubleSpliterator + public void test427478a() throws Exception { // full test case. + this.runConformTest( + new String[] { + "Spliterator.java", + "import java.util.function.Consumer;\n" + + "import java.util.function.DoubleConsumer;\n" + + "public interface Spliterator {\n" + + " default void forEachRemaining(Consumer action) {\n" + + " }\n" + + " public interface OfPrimitive>\n" + + " extends Spliterator {\n" + + " // overloads Spliterator#forEachRemaining(Consumer)\n" + + " default void forEachRemaining(T_CONS action) {\n" + + " }\n" + + " }\n" + + " public interface OfDouble extends OfPrimitive {\n" + + " @Override // the method from Spliterator\n" + + " default void forEachRemaining(Consumer action) {\n" + + " }\n" + + " \n" + + " @Override // the method from OfPrimitive\n" + + " default void forEachRemaining(DoubleConsumer action) {\n" + + " }\n" + + " }\n" + + "}\n" + + "class Spliterators {\n" + + " /* Error on class: Duplicate default methods named forEachRemaining with\n" + + " * the parameters (Consumer) and (Consumer) are\n" + + " * inherited from the types Spliterator.OfDouble and Spliterator\n" + + " */\n" + + " public abstract static class AbstractDoubleSpliterator implements Spliterator.OfDouble {\n" + + " /* Implementation that prevents the compile error: */\n" + + "// @Override // the method from Spliterator\n" + + "// public void forEachRemaining(Consumer action) {\n" + + "// }\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=423467, [1.8][compiler] wrong error for functional interface with @Override default method + public void test423467() throws Exception { // full test case. + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo(String s);\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface A extends I { // wrong compile error (A *is* a functional interface)\n" + + " @Override\n" + + " default int foo(String s) {\n" + + " return -1;\n" + + " }\n" + + " Integer foo(java.io.Serializable s);\n" + + "}\n" + + "public class X {\n" + + " A a = (s) -> 10;\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface B { // OK\n" + + " default int foo(String s) {\n" + + " return -1;\n" + + " }\n" + + " Integer foo(java.io.Serializable s);\n" + + "}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=438471, Java 1.8 functional interface rejected if it extends an interface which overrides another interface's method + public void test438471() throws Exception { + this.runConformTest( + new String[] { + "Bar.java", + "@FunctionalInterface\n" + + "public interface Bar extends Overridden {\n" + + " void foo();\n" + + " @Override\n" + + " default void close() {\n" + + " System.out.println(\"bar\");\n" + + " }\n" + + "}\n" + + "\n" + + "interface Overridden extends AutoCloseable {\n" + + " // Works without this overridden method\n" + + " @Override\n" + + " void close();\n" + + "}" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=436350, [1.8][compiler] Missing bridge method in interface results in AbstractMethodError + public void test436350() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " }\n" + + "}\n" + + "interface GenericInterface {\n" + + " T reduce(Integer i);\n" + + "}\n" + + "interface DoubleInterface extends GenericInterface {\n" + + " default Double reduce(Integer i) {\n" + + " return 0.0;\n" + + " }\n" + + " double reduce(String s);\n" + + "}\n", // ================= + }, + ""); + // ensure bridge methods are generated in interfaces. + String expectedOutput = + " public bridge synthetic java.lang.Object reduce(java.lang.Integer arg0);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 invokeinterface DoubleInterface.reduce(java.lang.Integer) : java.lang.Double [24] [nargs: 2]\n" + + " 7 areturn\n"; + + File f = new File(OUTPUT_DIR + File.separator + "DoubleInterface.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=436350, [1.8][compiler] Missing bridge method in interface results in AbstractMethodError + public void test436350a() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "import java.util.PrimitiveIterator;\n" + + "import java.util.PrimitiveIterator.OfDouble;\n" + + "/**\n" + + " * @author Tobias Grasl\n" + + " */\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final double[] doubles = new double[]{1,2,3};\n" + + " OfDouble doubleIterator = new DoubleArrayIterator(doubles);\n" + + " Double value = new Reducer().reduce(doubleIterator, new DoubleInterface() {\n" + + " @Override\n" + + " public double reduce(OfDouble iterator_) {\n" + + " double sum = 0;\n" + + " while(iterator_.hasNext()) {\n" + + " sum += iterator_.nextDouble();\n" + + " }\n" + + " return sum;\n" + + " }\n" + + " });\n" + + " System.out.println(\"Anonymous class value: \"+value);\n" + + " doubleIterator = new DoubleArrayIterator(doubles);\n" + + " value = new Reducer().reduce(doubleIterator, (DoubleInterface) iterator_ -> {\n" + + " double sum = 0;\n" + + " while(iterator_.hasNext()) {\n" + + " sum += iterator_.nextDouble();\n" + + " }\n" + + " return sum;\n" + + " });\n" + + " System.out.println(\"Lambda expression value: \"+value);\n" + + " }\n" + + " private static class DoubleArrayIterator implements PrimitiveIterator.OfDouble {\n" + + " int index = 0;\n" + + " private double[] _doubles;\n" + + " public DoubleArrayIterator(double[] doubles_) {\n" + + " _doubles = doubles_;\n" + + " }\n" + + " @Override\n" + + " public boolean hasNext() {\n" + + " return index < _doubles.length;\n" + + " }\n" + + " @Override\n" + + " public double nextDouble() {\n" + + " return _doubles[index++];\n" + + " }\n" + + " };\n" + + " interface GenericInterface {\n" + + " T reduce(Iterator iterator_);\n" + + " }\n" + + " interface DoubleInterface extends GenericInterface {\n" + + " default Double reduce(Iterator iterator_) {\n" + + " if(iterator_ instanceof PrimitiveIterator.OfDouble) {\n" + + " return reduce((PrimitiveIterator.OfDouble)iterator_);\n" + + " }\n" + + " return Double.NaN;\n" + + " };\n" + + " double reduce(PrimitiveIterator.OfDouble iterator_);\n" + + " }\n" + + " static class Reducer {\n" + + " T reduce(Iterator iterator_, GenericInterface reduction_) {\n" + + " return reduction_.reduce(iterator_);\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "Anonymous class value: 6.0\n" + + "Lambda expression value: 6.0"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=437522, [1.8][compiler] Missing compile error in Java 8 mode for Interface.super.field access + public void testBug437522() throws Exception { + runNegativeTest( + new String[] { + "X.java", + "interface T {\n" + + " int f = 0;\n" + + " void foo();\n" + + " default String def() { return \"T.def\"; }\n" + + "}\n" + + "class S {\n" + + " public static final int f = 0;\n" + + "}\n" + + "class C extends S implements T {\n" + + " @Override\n" + + " public void foo() {\n" + + " System.out.println(T.super.f); // no error in Java 8 (wrong) without fix\n" + + " System.out.println(T.super.def()); // new JLS8 15.12.1 form (OK)\n" + + " System.out.println(S.super.f); // compile error (correct)\n" + + " }\n" + + "}\n" + + "class X {\n" + + " T f = new T() {\n" + + " @Override\n" + + " public void foo() {\n" + + " System.out.println(T.super.f); // no error in Java 8 (wrong) without fix\n" + + " }\n" + + " };\n" + + "}\n" + + "class Y { int f = 1;}\n" + + "class Z extends Y {\n" + + " int foo2() { return super.f;}\n" + + " static int foo() { return super.f;}\n" + + "}\n" + + "interface T2 { int f = 0; }\n" + + "class X2 implements T2 { \n" + + " int i = T2.super.f;\n" + + "}\n" + + "interface T3 { int f = 0; }\n" + + "interface T4 extends T3 { int f = 0; }\n" + + "class X3 implements T4 { \n" + + " int i = T4.super.f;\n" + + "}\n" + + "interface T5 { int f = 0; }\n" + + "class X5 implements T5 { \n" + + " static int i = T5.super.f;\n" + + "}\n" + + "interface T6 { int f = 0; }\n" + + "class X6 implements T6 { \n" + + " static int i = T6.super.f;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " System.out.println(T.super.f); // no error in Java 8 (wrong) without fix\n" + + " ^^^^^^^\n" + + "No enclosing instance of the type T is accessible in scope\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " System.out.println(S.super.f); // compile error (correct)\n" + + " ^^^^^^^\n" + + "No enclosing instance of the type S is accessible in scope\n" + + "----------\n" + + "3. ERROR in X.java (at line 21)\n" + + " System.out.println(T.super.f); // no error in Java 8 (wrong) without fix\n" + + " ^^^^^^^\n" + + "No enclosing instance of the type T is accessible in scope\n" + + "----------\n" + + "4. ERROR in X.java (at line 28)\n" + + " static int foo() { return super.f;}\n" + + " ^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n" + + "5. ERROR in X.java (at line 32)\n" + + " int i = T2.super.f;\n" + + " ^^^^^^^^\n" + + "No enclosing instance of the type T2 is accessible in scope\n" + + "----------\n" + + "6. ERROR in X.java (at line 37)\n" + + " int i = T4.super.f;\n" + + " ^^^^^^^^\n" + + "No enclosing instance of the type T4 is accessible in scope\n" + + "----------\n" + + "7. ERROR in X.java (at line 41)\n" + + " static int i = T5.super.f;\n" + + " ^^^^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n" + + "8. ERROR in X.java (at line 41)\n" + + " static int i = T5.super.f;\n" + + " ^^^^^^^^\n" + + "No enclosing instance of the type T5 is accessible in scope\n" + + "----------\n" + + "9. ERROR in X.java (at line 45)\n" + + " static int i = T6.super.f;\n" + + " ^^^^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n" + + "10. ERROR in X.java (at line 45)\n" + + " static int i = T6.super.f;\n" + + " ^^^^^^^^\n" + + "No enclosing instance of the type T6 is accessible in scope\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=437522, [1.8][compiler] Missing compile error in Java 8 mode for Interface.super.field access + // Example JLS: 15.11.2-1. + public void testBug437522a() throws Exception { + runConformTest( + true, + new String[] { + "X.java", + "interface I { int x = 0; }\n" + + "class T1 implements I { int x = 1; }\n" + + "class T2 extends T1 { int x = 2; }\n" + + "class T3 extends T2 {\n" + + " int x = 3;\n" + + " void test() {\n" + + " System.out.println(\"x= \" + x);\n" + + " System.out.println(\"super.x= \" + super.x);\n" + + " System.out.println(\"((T2)this).x= \" + ((T2)this).x);\n" + + " System.out.println(\"((T1)this).x= \" + ((T1)this).x);\n" + + " System.out.println(\"((I)this).x= \" + ((I)this).x);\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new T3().test();\n" + + " }\n" + + "}\n", + }, + null, null, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class T2 extends T1 { int x = 2; }\n" + + " ^\n" + + "The field T2.x is hiding a field from type T1\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " int x = 3;\n" + + " ^\n" + + "The field T3.x is hiding a field from type T2\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " System.out.println(\"((I)this).x= \" + ((I)this).x);\n" + + " ^\n" + + "The static field I.x should be accessed in a static way\n" + + "----------\n", + "x= 3\n" + + "super.x= 2\n" + + "((T2)this).x= 2\n" + + "((T1)this).x= 1\n" + + "((I)this).x= 0", + "", JavacTestOptions.DEFAULT); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=453552, Invalid '@FunctionalInterface error when two interfaces extend the same functional interface. + public void test453552() throws Exception { + this.runConformTest( + new String[] { + "FunctionalInterface1.java", + "@FunctionalInterface\n" + + "interface FunctionalInterface1 {\n" + + " void methodWithoutDefault();\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface FunctionalInterface2 extends FunctionalInterface1{}\n" + + "@FunctionalInterface\n" + + "interface FunctionalInterface3 extends FunctionalInterface1{}\n" + + "@FunctionalInterface\n" + + "interface FunctionalInterface4 extends FunctionalInterface2, FunctionalInterface3{}\n" + + "@FunctionalInterface\n" + + "interface RunnableFunctionalInterface extends Runnable, FunctionalInterface4{\n" + + " default void methodWithoutDefault(){\n" + + " // implements methodWithoutDefault\n" + + " }\n" + + "}\n" + }); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=453552, Invalid '@FunctionalInterface error when two interfaces extend the same functional interface. + public void test453552_comment2() throws Exception { + this.runConformTest( + new String[] { + "FI1.java", + "interface FI1 {\n" + + " R call(T input);\n" + + "}\n" + + "interface FI2 {\n" + + " V call(U input);\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface FI3 extends FI1, FI2 {\n" + + " Y apply(X input);\n" + + "\n" + + " @Override\n" + + " default Y call(X input) {\n" + + " return apply(input);\n" + + " }\n" + + "}" + }); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=477891, [1.8] regression caused by the fix for bug 438812: order dependencies in analysis of default method inheritance + public void test477891_comment0() throws Exception { + this.runNegativeTest( + new String[] { + "D.java", + "interface A {\n" + + " public default void display() {\n" + + " System.out.println(\"Display from A\");\n" + + " }\n" + + "}\n" + + "interface B extends A {\n" + + " @Override\n" + + " public default void display() {\n" + + " System.out.println(\"Display from B\");\n" + + " }\n" + + "}\n" + + "interface C extends A {\n" + + " @Override\n" + + " public void display();\n" + + "}\n" + + "public interface D extends B, C {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in D.java (at line 16)\n" + + " public interface D extends B, C {\n" + + " ^\n" + + "The default method display() inherited from B conflicts with another method inherited from C\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=477891, [1.8] regression caused by the fix for bug 438812: order dependencies in analysis of default method inheritance + public void test477891_comment0_a() throws Exception { + this.runNegativeTest( + new String[] { + "D.java", + "interface A {\n" + + " public default void display() {\n" + + " System.out.println(\"Display from A\");\n" + + " }\n" + + "}\n" + + "interface B extends A {\n" + + " @Override\n" + + " public default void display() {\n" + + " System.out.println(\"Display from B\");\n" + + " }\n" + + "}\n" + + "interface C extends A {\n" + + " @Override\n" + + " public void display();\n" + + "}\n" + + "public interface D extends C, B {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in D.java (at line 16)\n" + + " public interface D extends C, B {\n" + + " ^\n" + + "The default method display() inherited from B conflicts with another method inherited from C\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=477891, [1.8] regression caused by the fix for bug 438812: order dependencies in analysis of default method inheritance + public void test477891_comment3_a() throws Exception { + this.runNegativeTest( + new String[] { + "Z.java", + "import java.util.*;\n" + + "interface Z extends X, Y {\n" + + "}\n" + + "interface Y extends AB {\n" + + " @Override\n" + + " default Spliterator spliterator() { return null; };\n" + + "}\n" + + "interface X extends AB {\n" + + " @Override\n" + + " Spliterator spliterator();\n" + + "}\n" + + "interface AB {\n" + + " default Spliterator spliterator() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Z.java (at line 2)\n" + + " interface Z extends X, Y {\n" + + " ^\n" + + "The default method spliterator() inherited from Y conflicts with another method inherited from X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=477891, [1.8] regression caused by the fix for bug 438812: order dependencies in analysis of default method inheritance + public void test477891_comment3_b() throws Exception { + this.runNegativeTest( + new String[] { + "Z.java", + "import java.util.*;\n" + + "interface Z extends Y, X {\n" + + "}\n" + + "interface Y extends AB {\n" + + " @Override\n" + + " default Spliterator spliterator() { return null; };\n" + + "}\n" + + "interface X extends AB {\n" + + " @Override\n" + + " Spliterator spliterator();\n" + + "}\n" + + "interface AB {\n" + + " default Spliterator spliterator() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Z.java (at line 2)\n" + + " interface Z extends Y, X {\n" + + " ^\n" + + "The default method spliterator() inherited from Y conflicts with another method inherited from X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=477891, [1.8] regression caused by the fix for bug 438812: order dependencies in analysis of default method inheritance + public void test477891_comment3_c() throws Exception { + this.runNegativeTest( + new String[] { + "Z.java", + "import java.util.*;\n" + + "interface Z extends X, Y {\n" + + "}\n" + + "interface Y extends AB {\n" + + " @Override\n" + + " default Spliterator spliterator() { return null; };\n" + + "}\n" + + "interface X {\n" + + " Spliterator spliterator();\n" + + "}\n" + + "interface AB {\n" + + " default Spliterator spliterator() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Z.java (at line 2)\n" + + " interface Z extends X, Y {\n" + + " ^\n" + + "The default method spliterator() inherited from Y conflicts with another method inherited from X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=477891, [1.8] regression caused by the fix for bug 438812: order dependencies in analysis of default method inheritance + public void test477891_comment3_d() throws Exception { + this.runNegativeTest( + new String[] { + "Z.java", + "import java.util.*;\n" + + "interface Z extends Y, X {\n" + + "}\n" + + "interface Y extends AB {\n" + + " @Override\n" + + " default Spliterator spliterator() { return null; };\n" + + "}\n" + + "interface X {\n" + + " Spliterator spliterator();\n" + + "}\n" + + "interface AB {\n" + + " default Spliterator spliterator() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Z.java (at line 2)\n" + + " interface Z extends Y, X {\n" + + " ^\n" + + "The default method spliterator() inherited from Y conflicts with another method inherited from X\n" + + "----------\n"); + } + public void test458547_comment0_a() throws Exception { + this.runNegativeTest( + new String[] { + "JavaTest.java", + "public class JavaTest {\n" + + " interface A {\n" + + " default void foo() { }\n" + + " }\n" + + " interface B {\n" + + " void foo();\n" + + " }\n" + + " interface C {\n" + + " void foo();\n" + + " }\n" + + " interface D extends A, B {\n" + + " @Override default void foo() { }\n" + + " }\n" + + " class E implements A, B, C, D {\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in JavaTest.java (at line 14)\n" + + " class E implements A, B, C, D {\n" + + " ^\n" + + "The default method foo() inherited from JavaTest.D conflicts with another method inherited from JavaTest.C\n" + + "----------\n"); + } + public void test458547_comment0_b() throws Exception { + this.runNegativeTest( + new String[] { + "JavaTest.java", + "public class JavaTest {\n" + + " interface A {\n" + + " default void foo() { }\n" + + " }\n" + + " interface B {\n" + + " void foo();\n" + + " }\n" + + " interface C {\n" + + " void foo();\n" + + " }\n" + + " interface D extends A, B {\n" + + " @Override default void foo() { }\n" + + " }\n" + + " class E implements B, C, A, D {\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in JavaTest.java (at line 14)\n" + + " class E implements B, C, A, D {\n" + + " ^\n" + + "The default method foo() inherited from JavaTest.D conflicts with another method inherited from JavaTest.C\n" + + "----------\n"); + } + + public void testBug539743() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static void m(V v) {\n" + + "\n" + + " }\n" + + "\n" + + " interface Foo {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " default U f() {\n" + + " return (U) new Object();\n" + + " }\n" + + " }\n" + + "\n" + + " static class Bar implements Foo {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " @Override\n" + + " public Object f() {\n" + + " m(Foo.super.f());\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}", + }, + ""); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest_9.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest_9.java new file mode 100644 index 0000000000..c6da4bca41 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest_9.java @@ -0,0 +1,418 @@ +/******************************************************************************* + * Copyright (c) 2016, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.core.tests.junit.extension.TestCase; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; + +// Bug 488662 - [1.9] Allow private methods in interfaces +@SuppressWarnings({ "rawtypes" }) +public class InterfaceMethodsTest_9 extends AbstractComparableTest { + +// Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which do not belong to the class are skipped... + static { +// TESTS_NAMES = new String[] { "testBug488662_001" }; +// TESTS_NUMBERS = new int[] { 561 }; +// TESTS_RANGE = new int[] { 1, 2049 }; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); + } + + public static Test setUpTest(Test test) throws Exception { + TestCase.setUpTest(test); + RegressionTestSetup suite = new RegressionTestSetup(ClassFileConstants.JDK9); + suite.addTest(test); + return suite; + } + + public static Class testClass() { + return InterfaceMethodsTest_9.class; + } + + public InterfaceMethodsTest_9(String name) { + super(name); + } + + // private method - positive test + public void testBug488662_001() { + runConformTest( + new String[] { + "I.java", + "public interface I {\n" + + "@SuppressWarnings(\"unused\")\n" + + " private void foo() {}\n" + + "}\n", + }, + ""); + } + // private method legal combination of modifiers - positive test + public void testBug488662_002() { + runConformTest( + new String[] { + "I.java", + "public interface I {\n" + + "@SuppressWarnings(\"unused\")\n" + + " private static void foo() {}\n" + + "}\n", + }, + ""); + } + // private method legal combination of modifiers - positive test + public void testBug488662_003() { + runConformTest( + new String[] { + "I.java", + "public interface I {\n" + + "@SuppressWarnings(\"unused\")\n" + + " private strictfp void foo() {}\n" + + "}\n", + }, + ""); + } + + // missing method body - negative test + public void testBug488662_004() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + "@SuppressWarnings(\"unused\")\n" + + " private void foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 3)\n" + + " private void foo();\n" + + " ^^^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n"); + } + + // illegal modifier combination - negative test + public void testBug488662_005() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + "@SuppressWarnings(\"unused\")\n" + + " private default void foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 3)\n" + + " private default void foo();\n" + + " ^^^^^\n" + + "Illegal combination of modifiers for the private interface method foo; additionally only one of static and strictfp is permitted\n" + + "----------\n" + + "2. ERROR in I.java (at line 3)\n" + + " private default void foo();\n" + + " ^^^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n"); + } + // illegal modifier combination - negative test + public void testBug488662_006() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " private abstract void foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " private abstract void foo();\n" + + " ^^^^^\n" + + "Illegal combination of modifiers for the private interface method foo; additionally only one of static and strictfp is permitted\n" + + "----------\n"); + } + + // illegal modifier combination - negative test + public void testBug488662_007() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " private synchronized void foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " private synchronized void foo();\n" + + " ^^^^^\n" + + "Illegal modifier for the interface method foo; only public, private, abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "2. ERROR in I.java (at line 2)\n" + + " private synchronized void foo();\n" + + " ^^^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n"); + } + + // reduced visibility modifier - negative test + public void testBug488662_008() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n"+ + " public default void foo() {}\n"+ + "}\n"+ + "public class X implements I{\n"+ + "@SuppressWarnings(\"unused\")\n" + + "@Override\n" + + " private void foo() {}\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " private void foo() {}\n"+ + " ^^^^^\n" + + "Cannot reduce the visibility of the inherited method from I\n" + + "----------\n"); + } + + + // No unimplemented method error - positive test + public void testBug488662_009() { + runConformTest( + new String[] { + "X.java", + "interface I {\n"+ + " private void foo() {\n"+ + " }\n"+ + " public default void bar() {\n"+ + " foo();\n"+ + " }\n"+ + "}\n"+ + "public class X implements I{\n"+ + " public static void main(String[] args) {\n"+ + " new X().bar();\n"+ + " }\n"+ + "}\n" + }, + ""); + } + // illegal modifier combination - multiple errors - negative test + public void testBug488662_010() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " private public void foo(){}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " private public void foo(){}\n" + + " ^^^^^\n" + + "Illegal combination of modifiers for the private interface method foo; additionally only one of static and strictfp is permitted\n" + + "----------\n"); + } + // illegal modifier combination - negative test + public void testBug488662_011() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " private protected void foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " private protected void foo();\n" + + " ^^^^^\n" + + "Illegal modifier for the interface method foo; only public, private, abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "2. ERROR in I.java (at line 2)\n" + + " private protected void foo();\n" + + " ^^^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n"); + } + // illegal modifier combination - multiple errors - negative test + public void testBug488662_012() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " private private public default protected void foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in I.java (at line 2)\n" + + " private private public default protected void foo();\n" + + " ^^^^^\n" + + "Duplicate modifier for the method foo in type I\n" + + "----------\n" + + "2. ERROR in I.java (at line 2)\n" + + " private private public default protected void foo();\n" + + " ^^^^^\n" + + "Illegal modifier for the interface method foo; only public, private, abstract, default, static and strictfp are permitted\n" + + "----------\n" + + "3. ERROR in I.java (at line 2)\n" + + " private private public default protected void foo();\n" + + " ^^^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n"); + } + public void testBug517926() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " private String name(T t){return null;}\n" + + " default String getName() { return name(null);}\n" + + "}\n", + "A.java", + "public class A implements I {\n" + + " @Override\n" + + " public String name(String s) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 3)\n" + + " public String name(String s) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The method name(String) of type A must override or implement a supertype method\n" + + "----------\n"); + } + public void testBug521743() { + runConformTest( + new String[] { + "FI.java", + "interface FI {\n" + + " private void foo(Class c){}\n" + + "}\n" + + "interface FI2 extends FI {\n" + + " default void foo(Class c) {}\n" + + "}" + }, + ""); + } + public void testBug520795() { + runNegativeTest( + new String[] { + "I.java", + "public interface I {\n" + + " private static void foo(){};\n" + + " default void bar() {\n" + + " foo();\n" + + " }" + + "}\n", + "X.java", + "public class X {\n" + + "public static void main(String[] args) {\n" + + " I.foo();\n" + + "}" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I.foo();\n" + + " ^^^\n" + + "The method foo() from the type I is not visible\n" + + "----------\n" ); + } + public void testBug520795a() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "interface I {\n" + + " private static void foo(){};\n" + + " default void bar() {\n" + + " foo();\n" + + " }" + + "}\n" + + "public static void main(String[] args) {\n" + + " I.foo();\n" + + "}" + + "}\n" + }); + } + public void testBug520795b() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "public interface I {\n" + + " private static void foo(){};\n" + + " void bar();" + + "}\n" + + "public static void main(String[] args) {\n" + + " I i = () -> {};\n" + + " i.foo();\n" + + "}" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " i.foo();\n" + + " ^^^\n" + + "This static method of interface X.I can only be accessed as X.I.foo\n" + + "----------\n" ); + } + public void testBug520795c() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "public interface I {\n" + + " private static void foo(){};\n" + + "}\n" + + "public interface J extends I {\n" + + " default void goo(){I.super.foo();};\n" + + " void baz();" + + "}\n" + + "public static void main(String[] args) {\n" + + " J j = () -> {};\n" + + " j.goo();\n" + + "}" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " default void goo(){I.super.foo();};\n" + + " ^^^\n" + + "This static method of interface X.I can only be accessed as X.I.foo\n" + + "----------\n" ); + } + public void testBug518272() { + runConformTest( + new String[] { + "GeneratedAccessorBug.java", + "public interface GeneratedAccessorBug {\n" + + " void hello();\n" + + " private static void foo() {}\n" + + " public static void bar() {\n" + + " new GeneratedAccessorBug() {\n" + + " public void hello() {\n" + + " foo();\n" + + " }\n" + + " }.hello();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " GeneratedAccessorBug.bar();\n" + + " }\n" + + "}" + }); + } +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InternalHexFloatTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InternalHexFloatTest.java new file mode 100644 index 0000000000..c3ba04082b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InternalHexFloatTest.java @@ -0,0 +1,413 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.util.FloatUtil; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class InternalHexFloatTest extends AbstractRegressionTest { + static class DoubleTest { + String input; + long output; + public DoubleTest(String input, long output) { + this.input = input; + this.output = output; + } + } + + static class FloatTest { + String input; + int output; + public FloatTest(String input, int output) { + this.input = input; + this.output = output; + } + } + + public InternalHexFloatTest(String name) { + super(name); + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); + } + + public static Class testClass() { + return InternalHexFloatTest.class; + } + + /** + */ + public void test001() { + List x = new ArrayList(); + + // various forms of zero + x.add(new DoubleTest("0x0p0", 0x0L)); + x.add(new DoubleTest("0x0p0d", 0x0L)); + x.add(new DoubleTest("0x0p0D", 0x0L)); + x.add(new DoubleTest("0x0.0p0D", 0x0L)); + x.add(new DoubleTest("0x.0p0D", 0x0L)); + x.add(new DoubleTest("0x0.p0D", 0x0L)); + x.add(new DoubleTest("0x00000.00000000000p0D", 0x0L)); + x.add(new DoubleTest("0x0p99D", 0x0L)); + x.add(new DoubleTest("0x0p-99D", 0x0L)); + x.add(new DoubleTest("0x0p9999999D", 0x0L)); + x.add(new DoubleTest("0x0p-9999999D", 0x0L)); + + // small doubles + x.add(new DoubleTest("0x0.8p0D", 0x3fe0000000000000L)); + x.add(new DoubleTest("0x0.4p0D", 0x3fd0000000000000L)); + x.add(new DoubleTest("0x0.2p0D", 0x3fc0000000000000L)); + x.add(new DoubleTest("0x0.1p0D", 0x3fb0000000000000L)); + x.add(new DoubleTest("0x0.08p0D", 0x3fa0000000000000L)); + x.add(new DoubleTest("0x0.04p0D", 0x3f90000000000000L)); + x.add(new DoubleTest("0x0.02p0D", 0x3f80000000000000L)); + x.add(new DoubleTest("0x0.01p0D", 0x3f70000000000000L)); + x.add(new DoubleTest("0x0.010p0D", 0x3f70000000000000L)); + x.add(new DoubleTest("0x1p0D", 0x3ff0000000000000L)); + x.add(new DoubleTest("0x2p0D", 0x4000000000000000L)); + x.add(new DoubleTest("0x4p0D", 0x4010000000000000L)); + x.add(new DoubleTest("0x8p0D", 0x4020000000000000L)); + x.add(new DoubleTest("0x10p0D", 0x4030000000000000L)); + x.add(new DoubleTest("0x20p0D", 0x4040000000000000L)); + x.add(new DoubleTest("0x40p0D", 0x4050000000000000L)); + x.add(new DoubleTest("0x80p0D", 0x4060000000000000L)); + x.add(new DoubleTest("0x80.p0D", 0x4060000000000000L)); + x.add(new DoubleTest("0x80.8p0D", 0x4060100000000000L)); + x.add(new DoubleTest("0x80.80p0D", 0x4060100000000000L)); + x.add(new DoubleTest("0x123456789p0D", 0x41f2345678900000L)); + x.add(new DoubleTest("0xabcedfp0D", 0x416579dbe0000000L)); + x.add(new DoubleTest("0xABCDEFp0D", 0x416579bde0000000L)); + + x.add(new DoubleTest("0x0.0100000000000000000000000000000000000000000000000p0d", 0x3f70000000000000L)); + x.add(new DoubleTest("0x0.0000000000000000000000000000000000000000000000001p0d", 0x33b0000000000000L)); + x.add(new DoubleTest("0x10000000000000000000000000000000000000000000000000000p0d", 0x4cf0000000000000L)); + + // rounding to 53 bits + x.add(new DoubleTest("0x823456789012380p0d", 0x43a0468acf120247L)); + x.add(new DoubleTest("0xFFFFFFFFFFFFF80p0d", 0x43afffffffffffffL)); + x.add(new DoubleTest("0xFFFFFFFFFFFFFC0p0d", 0x43b0000000000000L)); + x.add(new DoubleTest("0xFFFFFFFFFFFFFA0p0d", 0x43afffffffffffffL)); + x.add(new DoubleTest("0xFFFFFFFFFFFFF81p0d", 0x43afffffffffffffL)); + x.add(new DoubleTest("0x123456789abcd10p0d", 0x43723456789abcd1L)); + x.add(new DoubleTest("0x123456789abcd18p0d", 0x43723456789abcd2L)); + x.add(new DoubleTest("0x7FFFFFFFFFFFFC0p0d", 0x439fffffffffffffL)); + x.add(new DoubleTest("0x7FFFFFFFFFFFFE0p0d", 0x43a0000000000000L)); + x.add(new DoubleTest("0x3FFFFFFFFFFFFE0p0d", 0x438fffffffffffffL)); + x.add(new DoubleTest("0x3FFFFFFFFFFFFF0p0d", 0x4390000000000000L)); + x.add(new DoubleTest("0x1FFFFFFFFFFFFF0p0d", 0x437fffffffffffffL)); + x.add(new DoubleTest("0x1FFFFFFFFFFFFF8p0d", 0x4380000000000000L)); + + // rounding to overflow at +1024; denormalized at -1022; underflow at -1075 + x.add(new DoubleTest("0x1p5000D", 0x7ff0000000000000L)); + x.add(new DoubleTest("0x1p-5000D", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x1.0p1022d", 0x7fd0000000000000L)); + x.add(new DoubleTest("0x1.0p1023d", 0x7fe0000000000000L)); + x.add(new DoubleTest("0x1.0p1024d", 0x7ff0000000000000L)); + x.add(new DoubleTest("0x1.0p-1022d", 0x0010000000000000L)); + x.add(new DoubleTest("0x1.0p-1023d", 0x0008000000000000L)); + x.add(new DoubleTest("0x1.0p-1024d", 0x0004000000000000L)); + x.add(new DoubleTest("0x1.0p-1074d", 0x0000000000000001L)); + x.add(new DoubleTest("0x1.0p-1075d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x1.0p-1076d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x1.0p-1077d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x1.0p-1078d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.8p1023d", 0x7fd0000000000000L)); + x.add(new DoubleTest("0x0.8p1024d", 0x7fe0000000000000L)); + x.add(new DoubleTest("0x0.8p1025d", 0x7ff0000000000000L)); + x.add(new DoubleTest("0x0.8p-1021d", 0x0010000000000000L)); + x.add(new DoubleTest("0x0.8p-1022d", 0x0008000000000000L)); + x.add(new DoubleTest("0x0.8p-1023d", 0x0004000000000000L)); + x.add(new DoubleTest("0x0.8p-1024d", 0x0002000000000000L)); + x.add(new DoubleTest("0x0.8p-1074d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.8p-1075d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.8p-1076d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.4p-1021d", 0x0008000000000000L)); + x.add(new DoubleTest("0x0.4p-1022d", 0x0004000000000000L)); + x.add(new DoubleTest("0x0.4p-1023d", 0x0002000000000000L)); + x.add(new DoubleTest("0x0.4p-1073d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.4p-1074d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.4p-1075d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.2p-1020d", 0x0008000000000000L)); + x.add(new DoubleTest("0x0.2p-1021d", 0x0004000000000000L)); + x.add(new DoubleTest("0x0.2p-1022d", 0x0002000000000000L)); + x.add(new DoubleTest("0x0.2p-1072d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.2p-1073d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.2p-1074d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.1p-1019d", 0x0008000000000000L)); + x.add(new DoubleTest("0x0.1p-1020d", 0x0004000000000000L)); + x.add(new DoubleTest("0x0.1p-1021d", 0x0002000000000000L)); + x.add(new DoubleTest("0x0.1p-1071d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.1p-1072d", 0x7ff8000000000000L)); + x.add(new DoubleTest("0x0.1p-1073d", 0x7ff8000000000000L)); + + for (Iterator it = x.iterator(); it.hasNext();) { + DoubleTest t = (DoubleTest) it.next(); + String s = t.input; + long expectedBits = t.output; + double libExpected = 0.0d; + boolean isJ2SE5; + try { + // note that next line only works with a 1.5 J2SE + libExpected = Double.parseDouble(s); + isJ2SE5 = true; + } catch(NumberFormatException e) { + isJ2SE5 = false; + } + double dActual = FloatUtil.valueOfHexDoubleLiteral(s.toCharArray()); + long actualBits = Double.doubleToLongBits(dActual); + if (isJ2SE5) { + // cross-check bits computed by J2SE 1.5 library + long libExpectedBits = Double.doubleToRawLongBits(libExpected); + if (expectedBits != libExpectedBits) { + if (Double.isNaN(Double.longBitsToDouble(expectedBits)) && libExpected == 0.0d) { + // this is ok - we return NaN where lib quietly underflows to 0 + } else { + assertEquals("Test has wrong table value for " + s, libExpectedBits, expectedBits); + } + } + } + assertEquals("Wrong double value for " + s, expectedBits, actualBits); + } + } + + /** + */ + public void test002() { + List x = new ArrayList(); + // various forms of zero + x.add(new FloatTest("0x0p0f", 0x0)); + x.add(new FloatTest("0x0p0F", 0x0)); + x.add(new FloatTest("0x0.0p0F", 0x0)); + x.add(new FloatTest("0x.0p0F", 0x0)); + x.add(new FloatTest("0x0.p0F", 0x0)); + x.add(new FloatTest("0x00000.00000000000p0F", 0x0)); + x.add(new FloatTest("0x0p99F", 0x0)); + x.add(new FloatTest("0x0p-99F", 0x0)); + x.add(new FloatTest("0x0p9999999F", 0x0)); + x.add(new FloatTest("0x0p-9999999F", 0x0)); + + // small floats + x.add(new FloatTest("0x0.8p0F", 0x3f000000)); + x.add(new FloatTest("0x0.4p0F", 0x3e800000)); + x.add(new FloatTest("0x0.2p0F", 0x3e000000)); + x.add(new FloatTest("0x0.1p0F", 0x3d800000)); + x.add(new FloatTest("0x0.08p0F", 0x3d000000)); + x.add(new FloatTest("0x0.04p0F", 0x3c800000)); + x.add(new FloatTest("0x0.02p0F", 0x3c000000)); + x.add(new FloatTest("0x0.01p0F", 0x3b800000)); + x.add(new FloatTest("0x0.010p0F", 0x3b800000)); + x.add(new FloatTest("0x1p0F", 0x3f800000)); + x.add(new FloatTest("0x2p0F", 0x40000000)); + x.add(new FloatTest("0x4p0F", 0x40800000)); + x.add(new FloatTest("0x8p0F", 0x41000000)); + x.add(new FloatTest("0x10p0F", 0x41800000)); + x.add(new FloatTest("0x20p0F", 0x42000000)); + x.add(new FloatTest("0x40p0F", 0x42800000)); + x.add(new FloatTest("0x80p0F", 0x43000000)); + x.add(new FloatTest("0x80.p0F", 0x43000000)); + x.add(new FloatTest("0x80.8p0F", 0x43008000)); + x.add(new FloatTest("0x80.80p0F", 0x43008000)); + x.add(new FloatTest("0x123456789p0F", 0x4f91a2b4)); + x.add(new FloatTest("0xabcedfp0F", 0x4b2bcedf)); + x.add(new FloatTest("0xABCDEFp0F", 0x4b2bcdef)); + + x.add(new FloatTest("0x0.000000000000000000000000000001p0f", 0x3800000)); + x.add(new FloatTest("0x10000000000000000000000000000000p0f", 0x7d800000)); + + // rounding to 24 bits + x.add(new FloatTest("0x823456p0f", 0x4b023456)); + x.add(new FloatTest("0xFFFFFF80p0f", 0x4f800000)); + x.add(new FloatTest("0xFFFFFF40p0f", 0x4f7fffff)); + x.add(new FloatTest("0xFFFFFF20p0f", 0x4f7fffff)); + x.add(new FloatTest("0x123456p0f", 0x4991a2b0)); + x.add(new FloatTest("0x7890abp0f", 0x4af12156)); + x.add(new FloatTest("0xcdefABp0f", 0x4b4defab)); + x.add(new FloatTest("0xCDEFdep0f", 0x4b4defde)); + x.add(new FloatTest("0x123456p0f", 0x4991a2b0)); + x.add(new FloatTest("0x7FFFFF8p0f", 0x4cffffff)); + x.add(new FloatTest("0x3FFFFFCp0f", 0x4c7fffff)); + x.add(new FloatTest("0x1FFFFFEp0f", 0x4bffffff)); + + // rounding to overflow at +128; denormalized at -126; underflow at -150 + x.add(new FloatTest("0x1p5000F", 0x7f800000)); + x.add(new FloatTest("0x1p-5000F", 0x7fc00000)); + x.add(new FloatTest("0x1.0p126f", 0x7e800000)); + x.add(new FloatTest("0x1.0p127f", 0x7f000000)); + x.add(new FloatTest("0x1.0p128f", 0x7f800000)); + x.add(new FloatTest("0x1.0p129f", 0x7f800000)); + x.add(new FloatTest("0x1.0p-127f", 0x00400000)); + x.add(new FloatTest("0x1.0p-128f", 0x00200000)); + x.add(new FloatTest("0x1.0p-129f", 0x00100000)); + x.add(new FloatTest("0x1.0p-149f", 0x00000001)); + x.add(new FloatTest("0x1.0p-150f", 0x7fc00000)); + x.add(new FloatTest("0x1.0p-151f", 0x7fc00000)); + x.add(new FloatTest("0x0.8p127f", 0x7e800000)); + x.add(new FloatTest("0x0.8p128f", 0x7f000000)); + x.add(new FloatTest("0x0.8p129f", 0x7f800000)); + x.add(new FloatTest("0x0.8p-125f", 0x00800000)); + x.add(new FloatTest("0x0.8p-126f", 0x00400000)); + x.add(new FloatTest("0x0.8p-127f", 0x00200000)); + x.add(new FloatTest("0x0.8p-128f", 0x00100000)); + x.add(new FloatTest("0x0.8p-148f", 0x00000001)); + x.add(new FloatTest("0x0.8p-149f", 0x7fc00000)); + x.add(new FloatTest("0x0.8p-150f", 0x7fc00000)); + x.add(new FloatTest("0x0.4p-124f", 0x00800000)); + x.add(new FloatTest("0x0.4p-125f", 0x00400000)); + x.add(new FloatTest("0x0.4p-126f", 0x00200000)); + x.add(new FloatTest("0x0.4p-147f", 0x00000001)); + x.add(new FloatTest("0x0.4p-148f", 0x7fc00000)); + x.add(new FloatTest("0x0.4p-149f", 0x7fc00000)); + x.add(new FloatTest("0x0.4p-150f", 0x7fc00000)); + x.add(new FloatTest("0x0.2p-123f", 0x00800000)); + x.add(new FloatTest("0x0.2p-124f", 0x00400000)); + x.add(new FloatTest("0x0.2p-125f", 0x00200000)); + x.add(new FloatTest("0x0.2p-126f", 0x00100000)); + x.add(new FloatTest("0x0.2p-146f", 0x00000001)); + x.add(new FloatTest("0x0.2p-147f", 0x7fc00000)); + x.add(new FloatTest("0x0.2p-148f", 0x7fc00000)); + x.add(new FloatTest("0x0.2p-149f", 0x7fc00000)); + x.add(new FloatTest("0x0.1p-122f", 0x00800000)); + x.add(new FloatTest("0x0.1p-123f", 0x00400000)); + x.add(new FloatTest("0x0.1p-124f", 0x00200000)); + x.add(new FloatTest("0x0.1p-145f", 0x00000001)); + x.add(new FloatTest("0x0.1p-146f", 0x7fc00000)); + x.add(new FloatTest("0x0.1p-147f", 0x7fc00000)); + x.add(new FloatTest("0x0.1p-148f", 0x7fc00000)); + + for (Iterator it = x.iterator(); it.hasNext();) { + FloatTest t = (FloatTest) it.next(); + String s = t.input; + int expectedBits = t.output; + float libExpected = 0.0f; + boolean isJ2SE5; + try { + // note that next line only works with a 1.5 J2SE + libExpected = Float.parseFloat(s); + isJ2SE5 = true; + } catch(NumberFormatException e) { + isJ2SE5 = false; + } + float dActual = FloatUtil.valueOfHexFloatLiteral(s.toCharArray()); + long actualBits = Float.floatToIntBits(dActual); + if (isJ2SE5) { + // cross-check bits computed by J2SE 1.5 library + int libExpectedBits = Float.floatToRawIntBits(libExpected); + if (expectedBits != libExpectedBits) { + if (Float.isNaN(Float.intBitsToFloat(expectedBits)) && libExpected == 0.0f) { + // this is ok - we return NaN where lib quietly underflows to 0 + } else { + assertEquals("Test has wrong table value for " + s, libExpectedBits, expectedBits); + } + } + } + assertEquals("Wrong float value for " + s, expectedBits, actualBits); + } + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test003() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " System.out.println(-0Xf.aP1F);\n" + + " }\n" + + "}" + }, + "-31.25"); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test004() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " System.out.println(0X000.0000P5000);\n" + + " }\n" + + "}" + }, + "0.0"); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test005() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " System.out.println(-0X000.0000P5000F);\n" + + " }\n" + + "}" + }, + "-0.0"); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " System.out.println(0X000.eP-5000F);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " System.out.println(0X000.eP-5000F);\r\n" + + " ^^^^^^^^^^^^^^\n" + + "The literal 0X000.eP-5000F of type float is out of range \n" + + "----------\n"); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " System.out.println(0X000.eP5000F);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " System.out.println(0X000.eP5000F);\r\n" + + " ^^^^^^^^^^^^^\n" + + "The literal 0X000.eP5000F of type float is out of range \n" + + "----------\n"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InternalScannerTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InternalScannerTest.java new file mode 100644 index 0000000000..21ebb1e467 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InternalScannerTest.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +import org.eclipse.jdt.core.compiler.InvalidInputException; +import org.eclipse.jdt.internal.compiler.parser.Scanner; +import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; +@SuppressWarnings({ "rawtypes" }) +public class InternalScannerTest extends AbstractRegressionTest { + + public InternalScannerTest(String name) { + super(name); + } + public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); + } + + public static Class testClass() { + return InternalScannerTest.class; + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23181 + */ + public void test001() { + String source = "//Comment"; + Scanner scanner = new Scanner(); + scanner.setSource(source.toCharArray()); + int token = 0; + try { + token = scanner.getNextToken(); + } catch (InvalidInputException e) { + // ignore + } + assertEquals("Wrong token type", TerminalTokens.TokenNameEOF, token); + assertEquals("Wrong comment start", 0, scanner.commentStarts[0]); + assertEquals("Wrong comment start", -9, scanner.commentStops[0]); + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=73762 + */ + public void test002() throws InvalidInputException { + Scanner scanner = new Scanner(); + scanner.recordLineSeparator = true; + scanner.setSource("a\nb\nc\n".toCharArray()); + int token = 0; + while (token != TerminalTokens.TokenNameEOF) { + token = scanner.getNextToken(); + } + scanner.setSource("a\nb\n".toCharArray()); + token = 0; + while (token != TerminalTokens.TokenNameEOF) { + token = scanner.getNextToken(); + } + assertEquals("Wrong number of line ends", 2, scanner.getLineEnds().length); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP181NestTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP181NestTest.java new file mode 100644 index 0000000000..e7cbc7f44b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP181NestTest.java @@ -0,0 +1,1508 @@ +/******************************************************************************* + * Copyright (c) 2018, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import junit.framework.Test; + +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.core.util.ClassFormatException; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "rawtypes" }) +public class JEP181NestTest extends AbstractComparableTest { + + String versionString = null; + +public JEP181NestTest(String name) { + super(name); +} +// No need for a tearDown() +@Override +protected void setUp() throws Exception { + super.setUp(); + this.versionString = AbstractCompilerTest.getVersionString(this.complianceLevel); +} + +/* + * Toggle compiler in mode -11 + */ +// Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which do not belong to the class are skipped... +static { +// TESTS_NAMES = new String[] { "testBug572190" }; +// TESTS_NUMBERS = new int[] { 50, 51, 52, 53 }; +// TESTS_RANGE = new int[] { 34, 38 }; +} +private static final String[] source_classic = JEP181NestTest.getTestSeriesClassic(); + +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_11); +} +private static String[] getTestSeriesClassic() { + return new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public class Y {\n" + + " class Z {}\n" + + " }\n" + + " public static class A {\n" + + " public static class B {}\n" + + " public class C {}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void foo() {\n" + + " System.out.println(\"foo\");\n" + + " }\n" + + "}\n", + }; +} +private void verifyClassFile(String expectedOutput, String classFileName, int mode, boolean positive) throws IOException, ClassFormatException { + String result = getClassFileContents(classFileName, mode); + verifyOutput(result, expectedOutput, positive); +} +private String getClassFileContents( String classFileName, int mode) throws IOException, +ClassFormatException { + File f = new File(OUTPUT_DIR + File.separator + classFileName); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", mode); + return result; +} +private void verifyOutputPositive(String result, String expectedOutput) { + verifyOutput(result, expectedOutput, true); +} +private void verifyOutputNegative(String result, String expectedOutput) { + verifyOutput(result, expectedOutput, false); +} +private void verifyOutput(String result, String expectedOutput, boolean positive) { + int index = result.indexOf(expectedOutput); + if (positive) { + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + System.out.println("..."); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } else { + if (index != -1) { + assertEquals("Unexpected contents", "", result); + } + } +} +private void verifyClassFile(String expectedOutput, String classFileName, int mode) throws IOException, + ClassFormatException { + verifyClassFile(expectedOutput, classFileName, mode, true); +} +private void verifyNegativeClassFile(String unExpectedOutput, String classFileName, int mode) throws IOException, +ClassFormatException { + verifyClassFile(unExpectedOutput, classFileName, mode, false); +} +public void testBug535851_001() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + + this.runConformTest( + JEP181NestTest.source_classic, + "SUCCESS", + options + ); + + String expectedPartialOutput = + "Nest Members:\n" + + " #37 pack1/X$A,\n" + + " #44 pack1/X$A$B,\n" + + " #46 pack1/X$A$C,\n" + + " #40 pack1/X$Y,\n" + + " #48 pack1/X$Y$Z\n"; + verifyClassFile(expectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug535851_002() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + + this.runConformTest( + JEP181NestTest.source_classic, + "SUCCESS", + options + ); + + String expectedPartialOutput = + "Nest Host: #17 pack1/X\n"; + verifyClassFile(expectedPartialOutput, "pack1/X$A.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug535851_003() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + + this.runConformTest( + JEP181NestTest.source_classic, + "SUCCESS", + options + ); + + String unExpectedPartialOutput = + "NestMembers:"; + verifyNegativeClassFile(unExpectedPartialOutput, "pack1/X$A.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug535851_004() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + + this.runConformTest( + JEP181NestTest.source_classic, + "SUCCESS", + options + ); + + String expectedPartialOutput = + "Nest Host: #24 pack1/X\n"; + verifyClassFile(expectedPartialOutput, "pack1/X$Y$Z.class", ClassFileBytesDisassembler.SYSTEM); +} +// vanilla anonymous declaration +public void testBug535851_005() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + String[] files = new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void foo() {\n" + + " Y y = new Y() {\n" + + " void bar() {}\n" + + " };\n" + + " System.out.println(y.toString());\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " abstract void bar();\n" + + "}\n", + }; + this.runConformTest( + files, + "SUCCESS", + options + ); + + String expectedPartialOutput = + "Nest Members:\n" + + " #33 pack1/X$1\n"; + verifyClassFile(expectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + + expectedPartialOutput = "Nest Host: #23 pack1/X\n"; + verifyClassFile(expectedPartialOutput, "pack1/X$1.class", ClassFileBytesDisassembler.SYSTEM); + verifyNegativeClassFile(expectedPartialOutput, "pack1/Y.class", ClassFileBytesDisassembler.SYSTEM); +} +// anonymous declaration inside another anonymous declaration +public void testBug535851_006() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + String[] files = new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void foo() {\n" + + " Y y = new Y() {\n" + + " void bar() {\n" + + " Y y1 = new Y() {\n" + + " void bar() {}\n" + + " };\n" + + " System.out.println(y1.toString());\n" + + " }\n" + + " };\n" + + " System.out.println(y.toString());\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " abstract void bar();\n" + + "}\n", + }; + this.runConformTest( + files, + "SUCCESS", + options + ); + + String expectedPartialOutput = + "Nest Members:\n" + + " #33 pack1/X$1,\n" + + " #48 pack1/X$1$1\n"; + verifyClassFile(expectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + + expectedPartialOutput = "Nest Host: #48 pack1/X\n"; + verifyClassFile(expectedPartialOutput, "pack1/X$1.class", ClassFileBytesDisassembler.SYSTEM); + expectedPartialOutput = "Nest Host: #28 pack1/X\n"; + verifyClassFile(expectedPartialOutput, "pack1/X$1$1.class", ClassFileBytesDisassembler.SYSTEM); + verifyNegativeClassFile(expectedPartialOutput, "pack1/Y.class", ClassFileBytesDisassembler.SYSTEM); +} + +// lambda with anonymous inside anonymous +public void testBug535851_007() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + String[] files = new String[] { + "pack1/X.java", + "package pack1;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void foo() {\n" + + " I i = ()->{\n" + + " Y y = new Y() { \n" + + " @Override\n" + + " void bar() {\n" + + " Y y1 = new Y() {\n" + + " @Override\n" + + " void bar() {}\n" + + " };\n" + + " System.out.println(y1);\n" + + " }\n" + + " };\n" + + " System.out.println(y.toString());\n" + + " };\n" + + " i.apply();\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void apply();\n" + + "}\n" + + "abstract class Y {\n" + + " abstract void bar();\n" + + "}\n", + }; + this.runConformTest( + files, + "SUCCESS", + options + ); + + String expectedPartialOutput = + "Nest Members:\n" + + " #44 pack1/X$1,\n" + + " #77 pack1/X$1$1\n"; + verifyClassFile(expectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + + expectedPartialOutput = "Nest Host: #42 pack1/X\n"; + verifyClassFile(expectedPartialOutput, "pack1/X$1.class", ClassFileBytesDisassembler.SYSTEM); + expectedPartialOutput = "Nest Host: #28 pack1/X\n"; + verifyClassFile(expectedPartialOutput, "pack1/X$1$1.class", ClassFileBytesDisassembler.SYSTEM); + verifyNegativeClassFile(expectedPartialOutput, "pack1/Y.class", ClassFileBytesDisassembler.SYSTEM); +} +// type declaration in method +public void testBug535851_008() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + String[] files = new String[] { + "pack1/X.java", + "package pack1;\n" + + "\n" + + "public class X {\n"+ + " public void foo() {\n"+ + " class Y {\n"+ + " // nothing\n"+ + " }\n"+ + " Y y = new Y();\n"+ + " System.out.println(\"SUCCESS\");\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo();\n"+ + " }\n"+ + "}\n", + }; + this.runConformTest( + files, + "SUCCESS", + options + ); + + String expectedPartialOutput = + "Nest Members:\n" + + " #15 pack1/X$1Y\n"; + verifyClassFile(expectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + + expectedPartialOutput = "Nest Host: #22 pack1/X\n"; + verifyClassFile(expectedPartialOutput, "pack1/X$1Y.class", ClassFileBytesDisassembler.SYSTEM); +} +// testing the inner private instance field access from enclosing type +public void testBug535918_001a() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y {\n" + + " private int priv_int = 100;\n" + + " public int pub_int = 200;\n" + + " \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = foo();\n" + + " System.out.println(\"SUCCESS:\" + sum);\n" + + " }\n" + + " public static int foo() {\n" + + " Y y = new Y();\n" + + " int i = y.priv_int;\n" + + " int j = y.pub_int;\n" + + " return i + j;\n" + + " }\n" + + " public void bar() {\n" + + " System.out.println(\"bar\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS:300", + options + ); + + String expectedPartialOutput = + "getfield pack1.X$Y.priv_in"; + verifyClassFile(expectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String unExpectedPartialOutput = + "access$"; + verifyNegativeClassFile(unExpectedPartialOutput, "pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); +} +//testing the inner private static field access from enclosing type +public void testBug535918_001b() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y {\n" + + " private static int priv_int = 100;\n" + + " public int pub_int = 200;\n" + + " \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = foo();\n" + + " System.out.println(\"SUCCESS:\" + sum);\n" + + " }\n" + + " public static int foo() {\n" + + " Y y = new Y();\n" + + " int i = y.priv_int;\n" + + " int j = y.pub_int;\n" + + " return i + j;\n" + + " }\n" + + " public void bar() {\n" + + " System.out.println(\"bar\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS:300", + options + ); + + String expectedPartialOutput = "getstatic pack1.X$Y.priv_int"; + verifyClassFile(expectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + expectedPartialOutput = "Nest Members:\n" + + " #50 pack1/X$Y\n"; + verifyClassFile(expectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + expectedPartialOutput = "Nest Host: #25 pack1/X\n"; + verifyClassFile(expectedPartialOutput, "pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String unExpectedPartialOutput = "invokestatic pack1.X$Y.access$"; + verifyNegativeClassFile(unExpectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + unExpectedPartialOutput = "access$"; + verifyNegativeClassFile(unExpectedPartialOutput, "pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); +} +//testing the nested private field access from enclosing type +public void testBug535918_001c() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y {\n" + + " private int priv_int = 100;\n" + + " public int pub_int = 200;\n" + + " \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = foo();\n" + + " System.out.println(\"SUCCESS:\" + sum);\n" + + " }\n" + + " public static int foo() {\n" + + " Y y = new Y();\n" + + " int i = y.priv_int;\n" + + " int j = y.pub_int;\n" + + " return i + j;\n" + + " }\n" + + " public void bar() {\n" + + " System.out.println(\"bar\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS:300", + options + ); + + String unExpectedPartialOutput = + "access$"; + verifyNegativeClassFile(unExpectedPartialOutput, "pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); +} +//testing the nested private method access from same type (implicit nesting/nest host) +public void testBug535918_002() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " private int priv_non_static_method() {\n" + + " return 100;\n" + + " }\n" + + " public int pub_non_static_method() {\n" + + " return priv_non_static_method();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " int result =x.pub_non_static_method();\n" + + " System.out.println(result);\n" + + " }\n" + + "}\n", + }, + "100", + options + ); + + String expectedPartialOutput = + "invokevirtual pack1.X.priv_non_static_method()"; + verifyClassFile(expectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); +} + +// sibling access: private static field +public void testBug535918_003a() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y {\n" + + " private static int priv_int = 100;\n" + + " }\n" + + " public static class Z {\n" + + " public static int foo() {\n" + + " int i = Y.priv_int;\n" + + " return i;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = Z.foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + "}\n", + }, + "SUCCESS:100", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XZFile = getClassFileContents("pack1/X$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #55 pack1/X$Y,\n" + + " #17 pack1/X$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #22 pack1/X"); + verifyOutputPositive(XZFile, "Nest Host: #26 pack1/X"); + verifyOutputPositive(XZFile, "getstatic pack1.X$Y.priv_int"); + + verifyOutputNegative(XYFile, "access$"); + verifyOutputNegative(XZFile, "invokestatic pack1.X$Y.access$0"); +} +//sibling access: private instance field +public void testBug535918_003b() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y {\n" + + " private int priv_int = 100;\n" + + " }\n" + + " public static class Z {\n" + + " public static int foo() {\n" + + " Y y = new Y();\n" + + " int i = y.priv_int;\n" + + " return i;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = Z.foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + "}\n", + }, + "SUCCESS:100", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XZFile = getClassFileContents("pack1/X$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #55 pack1/X$Y,\n" + + " #17 pack1/X$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #21 pack1/X"); + verifyOutputPositive(XZFile, "Nest Host: #29 pack1/X"); + verifyOutputPositive(XZFile, "getfield pack1.X$Y.priv_int"); + + verifyOutputNegative(XYFile, "access$"); + verifyOutputNegative(XZFile, "invokestatic pack1.X$Y.access$0"); +} +//sibling access: private instance field via Allocation Expression Field reference +// note: internally this follows a different code path +public void testBug535918_003c() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y {\n" + + " private int priv_int = 100;\n" + + " }\n" + + " public static class Z {\n" + + " public static int foo() {\n" + + " int i = new Y().priv_int;\n" + + " return i;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = Z.foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + "}\n", + }, + "SUCCESS:100", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XZFile = getClassFileContents("pack1/X$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #55 pack1/X$Y,\n" + + " #17 pack1/X$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #21 pack1/X"); + verifyOutputPositive(XZFile, "Nest Host: #27 pack1/X"); + verifyOutputPositive(XZFile, "getfield pack1.X$Y.priv_int"); + + verifyOutputNegative(XYFile, "access$"); + verifyOutputNegative(XZFile, "invokestatic pack1.X$Y.access$0"); +} +//sibling and super: private static field access of a super-type is accessed from a sub-type with +//both super-type and sub-type being nestmates. +public void testBug535918_003d() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y {\n" + + " private static int priv_int = 100;\n" + + " }\n" + + " public static class Z extends Y {\n" + + " public static int foo() {\n" + + " int i = Y.priv_int;\n" + + " return i;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = Z.foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + "}\n", + }, + "SUCCESS:100", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XZFile = getClassFileContents("pack1/X$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #55 pack1/X$Y,\n" + + " #17 pack1/X$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #22 pack1/X"); + verifyOutputPositive(XZFile, "Nest Host: #24 pack1/X"); + verifyOutputPositive(XZFile, "getstatic pack1.X$Y.priv_int"); + + verifyOutputNegative(XYFile, "access$"); + verifyOutputNegative(XZFile, "invokestatic pack1.X$Y.access$0"); +} +//sibling and super: private instance field of a super-type is accessed from a sub-type with +//both super-type and sub-type being nestmates. +public void testBug535918_003e() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y{\n" + + " private int priv_int = 100;\n" + + " }\n" + + " public static class Z extends Y {\n" + + " public static int foo() {\n" + + " Y y = new Y();\n" + + " int i = y.priv_int;\n" + + " return i;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = Z.foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + "}\n", + }, + "SUCCESS:100", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XZFile = getClassFileContents("pack1/X$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #55 pack1/X$Y,\n" + + " #17 pack1/X$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #21 pack1/X"); + verifyOutputPositive(XZFile, "Nest Host: #26 pack1/X"); + verifyOutputPositive(XZFile, "getfield pack1.X$Y.priv_int"); + + verifyOutputNegative(XYFile, "access$"); + verifyOutputNegative(XZFile, "invokestatic pack1.X$Y.access$0"); +} +//sibling and super with super keyword: private instance field of a super-type is accessed from a sub-type +// user keyword super with both super-type and sub-type being nestmates. +public void testBug535918_003f() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y{\n" + + " private int priv_int = 100;\n" + + " }\n" + + " public static class Z extends Y {\n" + + " public int foo() {\n" + + " int i = super.priv_int;\n" + + " return i;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = new Z().foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + "}\n", + }, + "SUCCESS:100", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XZFile = getClassFileContents("pack1/X$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #56 pack1/X$Y,\n" + + " #16 pack1/X$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #21 pack1/X"); + verifyOutputPositive(XZFile, "Nest Host: #24 pack1/X"); + verifyOutputPositive(XZFile, "getfield pack1.X$Y.priv_int"); + + verifyOutputNegative(XYFile, "access$"); + verifyOutputNegative(XZFile, "invokestatic pack1.X$Y.access$0"); +} +//vanilla field access of enclosing type: private static field of enclosing type accessed in inner type +public void testBug535918_004a() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " private static int priv_int = 100;\n" + + " public static class Y {\n" + + " public static int foo() {\n" + + " return priv_int;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = Y.foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + "}\n", + }, + "SUCCESS:100", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #22 pack1/X$Y\n"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #17 pack1/X"); + verifyOutputPositive(XYFile, "getstatic pack1.X.priv_int"); + + verifyOutputNegative(XFile, "access$"); + verifyOutputNegative(XFile, "invokestatic pack1.X.access$0()"); + +} +//vanilla field access of enclosing type: private instance field of enclosing type accessed in inner type +public void testBug535918_004b() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " private int priv_int = 100;\n" + + " public class Y {\n" + + " public int foo() {\n" + + " return priv_int;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = new X().new Y().foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + "}\n", + }, + "SUCCESS:100", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #20 pack1/X$Y\n"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #22 pack1/X"); + verifyOutputPositive(XYFile, "getfield pack1.X.priv_int"); + + verifyOutputNegative(XFile, "access$"); + verifyOutputNegative(XYFile, "invokestatic pack1.X.access$0()"); + +} +//nestmate inner constructor call from outer - no synthetic and appropriate call site params +public void testBug535918_005a() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " class Y {\n" + + " class Z {\n" + + " private Z() {\n" + + " }\n" + + " }\n" + + " Z d;\n" + + " private Y() {\n" + + " this.d = new Z();\n" + + " }\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(new X());\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XYZFile = getClassFileContents("pack1/X$Y$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #38 pack1/X$Y,\n" + + " #42 pack1/X$Y$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #31 pack1/X"); + verifyOutputPositive(XYZFile, "Nest Host: #24 pack1/X"); + verifyOutputPositive(XYFile, "invokespecial pack1.X$Y$Z(pack1.X$Y)"); //only one param + + verifyOutputNegative(XYZFile, "synthetic X$Y$Z"); + verifyOutputNegative(XYFile, "invokespecial pack1.X$Y$Z(pack1.X$Y, pack1.X$Y$Z)"); +} +//nestmate sibling constructor call - no synthetic and appropriate call site params +public void testBug535918_005b() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " class Z {\n" + + " private Z() {\n" + + " }\n" + + " }\n" + + " class Y {\n" + + " Z d;\n" + + " private Y() {\n" + + " this.d = new Z();\n" + + " }\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(new X());\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XZFile = getClassFileContents("pack1/X$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #38 pack1/X$Y,\n" + + " #41 pack1/X$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #30 pack1/X"); + verifyOutputPositive(XZFile, "Nest Host: #22 pack1/X"); + verifyOutputPositive(XYFile, "invokespecial pack1.X$Z(pack1.X)"); //only one param + + verifyOutputNegative(XZFile, "synthetic X$Z"); + verifyOutputNegative(XYFile, "invokespecial pack1.X$Z(pack1.X$Y, pack1.X$Z)"); +} +//nestmate outer constructor call from inner - no synthetic and appropriate call site params +public void testBug535918_005c() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " class Y {\n" + + " private Y() {\n" + + " }\n" + + " class Z {\n" + + " Y y;\n" + + " private Z() {\n" + + " this.y = new Y();\n" + + " }\n" + + " }\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(new X());\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XYZFile = getClassFileContents("pack1/X$Y$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #38 pack1/X$Y,\n" + + " #42 pack1/X$Y$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #24 pack1/X"); + verifyOutputPositive(XYZFile, "Nest Host: #34 pack1/X"); + verifyOutputPositive(XYZFile, "invokespecial pack1.X$Y(pack1.X)"); //only one param + + verifyOutputNegative(XYFile, "synthetic X$Y"); + verifyOutputNegative(XYZFile, "invokespecial pack1.X$Y(pack1.X, pack1.X$Y)"); +} +//nestmate super call to private constructor from sibling nestmate which is a subtype - no synthetic and appropriate call site params +public void testBug535918_005d() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " private class Y {\n" + + " private Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " private class Z extends Y {\n" + + " private Z() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XZFile = getClassFileContents("pack1/X$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #35 pack1/X$Y,\n" + + " #38 pack1/X$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #22 pack1/X"); + verifyOutputPositive(XZFile, "Nest Host: #21 pack1/X"); + verifyOutputPositive(XZFile, "invokespecial pack1.X$Y(pack1.X)"); //only one param + + verifyOutputNegative(XYFile, "synthetic X$Y"); + verifyOutputNegative(XZFile, "invokespecial pack1.X$Y(pack1.X, pack1.X$Y)"); +} +// nestmate super call to private constructor from sibling nestmate which is a subtype +// super is a parameterized type +public void testBug535918_005e() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " private static class Y implements AutoCloseable {\n" + + " private Y() {\n" + + " super();\n" + + " }\n" + + " public void close() {\n" + + " }\n" + + " }\n" + + " @SuppressWarnings(\"unused\")\n" + + "private static class Z extends Y {\n" + + " private Z() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XZFile = getClassFileContents("pack1/X$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #35 pack1/X$Y,\n" + + " #38 pack1/X$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #24 pack1/X"); + verifyOutputPositive(XZFile, "Nest Host: #19 pack1/X"); + verifyOutputPositive(XZFile, "invokespecial pack1.X$Y()"); //only one param + + verifyOutputNegative(XYFile, "synthetic pack1.X$Y(pack1.X.Y arg0)"); + verifyOutputNegative(XZFile, "2 invokespecial pack1.X$Y(pack1.X$Y)"); +} +//nestmate constructor reference +public void testBug535918_005f() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X makeX(int x);\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " class Y {\n" + + " void f() {\n" + + " I i = X::new;\n" + + " i.makeX(123456);\n" + + " }\n" + + " }\n" + + " new Y().f();\n" + + " }\n" + + " private X(int x) {\n" + + " super();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " X() {\n" + + " super();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + options + ); + + String XFile = getClassFileContents("X.class", ClassFileBytesDisassembler.SYSTEM); + String X1YFile = getClassFileContents("X$1Y.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #8 X$1Y\n"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(X1YFile, "Nest Host: #33 X"); + + verifyOutputNegative(X1YFile, "synthetic X$Y(pack1.X.Y arg0)"); +} +//testing the nested private method access from enclosing type +public void testBug535918_005g() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y {\n" + + " private int priv_instance_method() {\n" + + " return 100;\n" + + " }\n" + + " public int pub_instance_method() {\n" + + " int pri = priv_instance_method();\n" + + " return 200 + pri;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + " public static int foo() {\n" + + " Y y = new Y();\n" + + " int i = y.priv_instance_method();\n" + + " int j = y.pub_instance_method();\n" + + " return i + j;\n" + + " }\n" + + " public void bar() {\n" + + " System.out.println(\"bar\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS:400", + options + ); + + String expectedPartialOutput = + "invokevirtual pack1.X$Y.priv_instance_method()"; + verifyClassFile(expectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); +} +//negative testing the nested private method access from enclosing type is not via invokespecial +public void testBug535918_005h() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y {\n" + + " private int priv_instance_method() {\n" + + " return 100;\n" + + " }\n" + + " public int pub_instance_method() {\n" + + " int pri = priv_instance_method();\n" + + " return 200 + pri;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + " public static int foo() {\n" + + " Y y = new Y();\n" + + " int i = y.priv_instance_method();\n" + + " int j = y.pub_instance_method();\n" + + " return i + j;\n" + + " }\n" + + " public void bar() {\n" + + " System.out.println(\"bar\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS:400", + options + ); + + String unExpectedPartialOutput = + "invokespecial pack1.X$Y.priv_instance_method()"; + verifyNegativeClassFile(unExpectedPartialOutput, "pack1/X.class", ClassFileBytesDisassembler.SYSTEM); +} +//negative testing the synthetic method - access - not present in nested class +public void testBug535918_005i() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "public class X {\n" + + " public static class Y {\n" + + " private int priv_instance_method() {\n" + + " return 100;\n" + + " }\n" + + " public int pub_instance_method() {\n" + + " int pri = priv_instance_method();\n" + + " return 200 + pri;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " int sum = foo();\n" + + " System.out.println(\"SUCCESS:\"+sum);\n" + + " }\n" + + " public static int foo() {\n" + + " Y y = new Y();\n" + + " int i = y.priv_instance_method();\n" + + " int j = y.pub_instance_method();\n" + + " return i + j;\n" + + " }\n" + + " public void bar() {\n" + + " System.out.println(\"bar\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS:400", + options + ); + + String unExpectedPartialOutput = + "access$"; + verifyNegativeClassFile(unExpectedPartialOutput, "pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); +} +//private interface method invoked from a method inside the same interface should be invokeinterface +public void testBug535918_005j() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "interface I {\n" + + " private void foo() {}\n" + + " public default void apply() {\n" + + " foo();\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n", + }, + "", + options + ); + + String IFile = getClassFileContents("pack1/I.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "invokeinterface pack1.I.foo"; + verifyOutputPositive(IFile, partialOutput); +} +//private interface method invoked from a nestmate interface should be invokeinterface +public void testBug535918_005k() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n" + + "interface I {" + + " private void foo() {}" + + " " + + " interface J {" + + " public default void apply() {" + + " I i = new X();" + + " i.foo();" + + " } " + + " }" + + "}" + + "public class X implements I{\n" + + "}\n", + }, + "", + options + ); + + String IFile = getClassFileContents("pack1/I$J.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "invokeinterface pack1.I.foo"; + verifyOutputPositive(IFile, partialOutput); +} +//test for SyntheticMethodBinding.SuperField*Access +public void testBug535918_0056a() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n"+ + "public class X {\n"+ + " private int priv_int;\n"+ + "\n"+ + " class Y extends X {\n"+ + " class Z extends Y {\n"+ + " public void foo() {\n"+ + " X.Y.super.priv_int = 0;\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " new X().new Y().new Z().foo();\n"+ + " }\n"+ + "}\n", + }, + "", + options + ); + + String XFile = getClassFileContents("pack1/X.class", ClassFileBytesDisassembler.SYSTEM); + String XYFile = getClassFileContents("pack1/X$Y.class", ClassFileBytesDisassembler.SYSTEM); + String XYZFile = getClassFileContents("pack1/X$Y$Z.class", ClassFileBytesDisassembler.SYSTEM); + String partialOutput = "Nest Members:\n" + + " #20 pack1/X$Y,\n" + + " #18 pack1/X$Y$Z"; + verifyOutputPositive(XFile, partialOutput); + verifyOutputPositive(XYFile, "Nest Host: #3 pack1/X"); + verifyOutputPositive(XYZFile, "Nest Host: #22 pack1/X"); + verifyOutputPositive(XYZFile, "putfield pack1.X.priv_int"); //direct access + + verifyOutputNegative(XYFile, "synthetic X$Y"); + verifyOutputNegative(XYZFile, "invokestatic X.access$0(X, int)"); +} + +public void testBug545387_01() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n"+ + "public class X {\n"+ + " public class Inner1 {\n"+ + " private void foo() {\n"+ + " System.out.println(\"hello\");;\n"+ + " }\n"+ + " }\n"+ + " public class Sub1 extends Inner1 {\n"+ + " public class Sub2 {\n"+ + " void testFoo() {\n"+ + " Sub1.super.foo();\n"+ + " }\n"+ + " }\n"+ + " void testFoo() {\n"+ + " (new Sub2()).testFoo();\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " Sub1 s1 = getS1();\n"+ + " s1.testFoo();\n"+ + " }\n"+ + " public static Sub1 getS1() {\n"+ + " return new X().new Sub1();\n"+ + " }\n"+ + "}\n", + }, + "hello", + options + ); + + String XSub1Sub2 = getClassFileContents("pack1/X$Sub1$Sub2.class", ClassFileBytesDisassembler.SYSTEM); + verifyOutputPositive(XSub1Sub2, "Nest Host: #29 pack1/X"); +} + +public void testBug572190_01() throws Exception { + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public void foo() {\n"+ + " new Thread(() -> {\n"+ + " new Object() {\n"+ + " };\n"+ + " });\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}", + }, + "0" + ); + + String XFile = getClassFileContents("X.class", ClassFileBytesDisassembler.SYSTEM); + String expected = "Nest Members:\n" + + " #41 X$1\n" + + "Bootstrap methods:\n" ; + String unexpectedOutput = "Nest Members:\n" + + " #41 X$1,\n" + + " #68 X$2\n" + + "Bootstrap methods:\n"; + verifyOutputPositive(XFile, expected); + + verifyOutputNegative(XFile, unexpectedOutput); +} + +public void testBug572190_02() throws Exception { + + this.runConformTest( + new String[] { + "pack1/X.java", + "package pack1;\n"+ + "\n"+ + "import pack1.XB.EF;\n"+ + "\n"+ + "public class X {\n"+ + " private static int foo() {\n"+ + " return EF.values().length;\n"+ + " }\n"+ + " public static void main(String argv[]) {\n"+ + " System.out.println(X.foo());\n"+ + " }\n"+ + " public enum ch { }\n"+ + "}\n", + "pack1/XA.java", + "package pack1;\n"+ + "public class XA {\n"+ + " public enum EC {}\n"+ + "}", + "pack1/XB.java", + "package pack1;\n"+ + "public class XB {\n"+ + " protected enum EF {}\n"+ + "}", + }, + "0" + ); + + String XFile = getClassFileContents("pack1/XB.class", ClassFileBytesDisassembler.SYSTEM); + String expected = "Nest Members:\n" + + " #17 pack1/XB$EF\n" + + "}"; + verifyOutputPositive(XFile, expected); + +} + +public static Class testClass() { + return JEP181NestTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286ReservedWordTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286ReservedWordTest.java new file mode 100644 index 0000000000..bbdc19e519 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286ReservedWordTest.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * Copyright (c) 2018 Jesper Steen Møller and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jesper Steen Møller - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.IOException; + +import org.eclipse.jdt.core.tests.util.CompilerTestSetup; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class JEP286ReservedWordTest extends AbstractRegressionTest { + +public static Class testClass() { + return JEP286ReservedWordTest.class; +} +@Override +public void initialize(CompilerTestSetup setUp) { + super.initialize(setUp); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} + +public JEP286ReservedWordTest(String testName){ + super(testName); +} + +public void test0001_class_var_warning() throws IOException { + String classVar = + " public class var { public int a; };\n"; + + String classX = + "public class X {\n" + + classVar + + " +\n" + + "}\n"; + String errorTail = + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " +\n" + + " ^\n" + + "Syntax error on token \"+\", delete this token\n" + + "----------\n"; + + if (Long.compare(this.complianceLevel, ClassFileConstants.JDK10) >= 0) { + this.runNegativeTest( + new String[] { + "X.java", + classX + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + classVar + + " ^^^\n" + + "'var' is not a valid type name\n" + + errorTail); + } else { + this.runNegativeTest( + new String[] { + "X.java", + classX + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + classVar + + " ^^^\n" + + "'var' should not be used as an type name, since it is a reserved word from source level 10 on\n" + + errorTail); + } +} +public void test0002_interface_var_warning() throws IOException { + String interfaceVar = + " interface var { };\n"; + + String classX = + "public class X {\n" + + interfaceVar + + " +\n" + + "}\n"; + String errorTail = + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " +\n" + + " ^\n" + + "Syntax error on token \"+\", delete this token\n" + + "----------\n"; + + if (Long.compare(this.complianceLevel, ClassFileConstants.JDK10) >= 0) { + this.runNegativeTest( + new String[] { + "X.java", + classX + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + interfaceVar + + " ^^^\n" + + "'var' is not a valid type name\n" + + errorTail); + } else { + this.runNegativeTest( + new String[] { + "X.java", + classX + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + interfaceVar + + " ^^^\n" + + "'var' should not be used as an type name, since it is a reserved word from source level 10 on\n" + + errorTail); + } +} +public void testBug530920() throws IOException { + String classX = "public class X { }\n"; + this.runNegativeTest( + new String[] { + "X.java", + classX + }, + Long.compare(this.complianceLevel, ClassFileConstants.JDK10) >= 0 ? + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X { }\n" + + " ^^^\n" + + "'var' is not allowed here\n" + : + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X { }\n" + + " ^^^\n" + + "'var' should not be used as an type name, since it is a reserved word from source level 10 on\n" + ); +} +public void testBug530920a() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " var getNumber() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + Long.compare(this.complianceLevel, ClassFileConstants.JDK10) >= 0 ? + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " var getNumber() {\n" + + " ^^^\n" + + "'var' is not allowed here\n" + : + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " var getNumber() {\n" + + " ^^^\n" + + "'var' should not be used as an type name, since it is a reserved word from source level 10 on\n" + ); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java new file mode 100644 index 0000000000..d36fd4f334 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP286Test.java @@ -0,0 +1,1398 @@ +/******************************************************************************* + * Copyright (c) 2018, 2020 Jesper Steen Møller and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jesper Steen Møller - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.CompilerTestSetup; +import org.eclipse.jdt.internal.compiler.ASTVisitor; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.BlockScope; +import org.eclipse.jdt.internal.compiler.lookup.ClassScope; +import org.junit.Assert; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JEP286Test extends AbstractRegressionTest { + +public static Class testClass() { + return JEP286Test.class; +} +@Override +public void initialize(CompilerTestSetup setUp) { + super.initialize(setUp); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_10); +} + +public JEP286Test(String testName){ + super(testName); +} +static { +// TESTS_NAMES = new String[] { "test0018_project_variable_types" }; +} +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_10); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_10); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); + return options; +} +private static final Map simpleTypeNames = new HashMap<>(); +static { + // Below call forces the init when the test is run independently. + AbstractCompilerTest.getPossibleComplianceLevels(); + simpleTypeNames.put("String", "java.lang.String"); + simpleTypeNames.put("Object", "java.lang.Object"); + simpleTypeNames.put("Bar", "X.Bar"); + + simpleTypeNames.put("AnonymousObjectSubclass", "new java.lang.Object(){}"); + simpleTypeNames.put("AnonymousRunnableSubclass", "new java.lang.Runnable(){}"); + simpleTypeNames.put("CollectionOfExtString", "Collection"); + simpleTypeNames.put("CollectionOfSuperString", "Collection"); + simpleTypeNames.put("CollectionAny", "Collection"); + simpleTypeNames.put("ComparableAny", "Comparable"); + simpleTypeNames.put("CollectionExt_ComparableAny", "Collection>"); + simpleTypeNames.put("CollectionSuperComparableAny", "Collection>"); + if (isJRE12Plus) + simpleTypeNames.put("IntLongFloat", "java.lang.Number & Comparable & java.lang.constant.Constable & java.lang.constant.ConstantDesc"); + else + simpleTypeNames.put("IntLongFloat", "java.lang.Number & Comparable"); + simpleTypeNames.put("ListTestAndSerializable", "List"); + simpleTypeNames.put("TestAndSerializable", "Z & java.io.Serializable"); +} + +static void assertInferredType(LocalDeclaration varDecl) { + String varName = new String(varDecl.name); + int underscoreIndex = varName.indexOf('_'); + Assert.assertNotEquals(-1, underscoreIndex); + String typeNamePart = varName.substring(underscoreIndex+1); + typeNamePart = typeNamePart.replaceAll("ARRAY", "[]"); // So that we assume that x_intARRAY is of type int[] + String expectedTypeName = simpleTypeNames.getOrDefault(typeNamePart, typeNamePart); + String actualTypeName = varDecl.binding.type.debugName(); + // System.out.println("For " + varName + ", we expect " + expectedTypeName + ", the type was: " + // + actualTypeName + " - " + (expectedTypeName.equals(actualTypeName) ? "❤️" : "🤡")); + Assert.assertEquals("Type of variable " + varName, expectedTypeName, actualTypeName); +} + +// This visitor visits the 'testXxx' method in the visited classes, checking for expected types of local variables (using the debug name) +private final static class InferredTypeVerifier extends ASTVisitor { + public int localsChecked = 0; + public InferredTypeVerifier() { } + + @Override + public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { + return false; // Don't check Foo itself + } + + @Override + public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { + if (! new String(methodDeclaration.selector).startsWith("test")) return false; + return super.visit(methodDeclaration, scope); + } + + @Override + public boolean visit(LocalDeclaration localDeclaration, BlockScope scope) { + assertInferredType(localDeclaration); + this.localsChecked++; + return super.visit(localDeclaration, scope); + } + } + +public void test0001_local_variable_inference() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " var x = \"SUCCESS\";\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +public void test0002_inferred_for() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " int sum = 0;\n" + + " for(var n = 1; n <= 2; ++n) {\n" + + " sum += n;\n" + + " }\n" + + " System.out.println(\"SUCCESS \" + sum);\n" + + " }\n" + + "}\n" + }, + "SUCCESS 3"); +} +public void test0003_inferred_enhanced_for() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " int sum = 0;\n" + + " for(var n : java.util.List.of(1, 2)) {\n" + + " sum += n;\n" + + " }\n" + + " System.out.println(\"SUCCESS \" + sum);\n" + + " }\n" + + "}\n" + }, + "SUCCESS 3"); +} +public void test0004_try_with_resources() throws IOException { + try(java.io.Writer w = new java.io.StringWriter()) { + w.write("SUCCESS!\n"); + System.out.println(w.toString()); + } + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " try(var w = new java.io.StringWriter()) {\n" + + " w.write(\"SUCCESS\\n\");" + + " System.out.println(w.toString());\n" + + " }\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +public void test0005_no_initializer() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] argv) {\n" + + " var a;\n" + + " for(var b;;);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a;\n" + + " ^\n" + + "Cannot use 'var' on variable without initializer\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " for(var b;;);\n" + + " ^\n" + + "Cannot use 'var' on variable without initializer\n" + + "----------\n"); +} +public void test0006_multiple_declarators() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] argv) {\n" + + " var a = 1, b = 2;\n" + + " for(var c = 1, d = 20; c)(() -> true ? 1 : a)).call(); + // The cases are tested. a is a simple case, with plain usage in the same scope. b is used in a nested scope. + // c and d are shadowed by the nested definitions. + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String [] args) {\n" + + " var a = 42 + a;\n" + + " var b = ((java.util.concurrent.Callable)(() -> true ? 1 : b)).call();\n" + + " var c = new java.util.concurrent.Callable() {\n" + + " public Integer call() {\n" + + " int c = 42; return c;\n" + + " }\n" + + " }.call();" + + " var d = new java.util.concurrent.Callable() {\n" + + " int d = 42;\n" + + " public Integer call() {\n" + + " return d;\n" + + " }\n" + + " }.call();" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a = 42 + a;\n" + + " ^\n" + + "Declaration using 'var' may not contain references to itself\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " var b = ((java.util.concurrent.Callable)(() -> true ? 1 : b)).call();\n" + + " ^\n" + + "Declaration using 'var' may not contain references to itself\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " int c = 42; return c;\n" + + " ^\n" + + "The local variable c is hiding another local variable defined in an enclosing scope\n" + + "----------\n"+ + "3. WARNING in X.java (at line 10)\n" + + " int d = 42;\n" + + " ^\n" + + "The field new Callable(){}.d is hiding another local variable defined in an enclosing scope\n" + + "----------\n"); +} +public void test0013_lambda() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String [] args) {\n" + + " var a = (int i) -> 42;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a = (int i) -> 42;\n" + + " ^\n" + + "Lambda expression needs an explicit target-type\n" + + "----------\n"); +} +public void test0014_method_reference() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String [] args) {\n" + + " var a = X::main;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a = X::main;\n" + + " ^\n" + + "Method reference needs an explicit target-type\n" + + "----------\n"); +} +public void test0015_complain_over_first_poly_encountered() throws Exception { + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void main(String [] args) {\n" + + " var a = args.length > 1 ? X::main : (int i) -> 42;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " var a = args.length > 1 ? X::main : (int i) -> 42;\n" + + " ^\n" + + "Method reference needs an explicit target-type\n" + + "----------\n"); +} +public void test0016_dont_capture_deep_poly_expressions() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " var z = ((java.util.concurrent.Callable)(() -> \"SUCCESS\"));\n" + + " var x = args.length > 1 ? \"FAILURE\" : z.call();\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +//static , E extends List> void doSomething(T[] e) { +// e[0] = null; +//} + +public void test0017_simple_variable_types() throws Exception { + InferredTypeVerifier typeVerifier = new InferredTypeVerifier(); + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void test() {\n" + + " var i_String = \"\";\n" + + " for (var i2_String = \"\" ; ; ) { break; }\n" + + " for (var i2_String : iterableOfString()) { break; }\n" + + " for (var i2_String : arrayOfString()) { break; }\n" + + " try (var i2_Bar = new Bar()) { } finally { }\n" + + " try (var i2_Bar = new Bar(); var i3_Bar = new Bar()) { } finally { }\n" + + " }\n" + + "\n" + + " Iterable iterableOfString() { return null; }\n" + + " String[] arrayOfString() { return null; }\n" + + "\n" + + " static class Bar implements AutoCloseable {\n" + + " @Override\n" + + " public void close() { }\n" + + " }\n" + + "}\n" + + "\n" + }, + typeVerifier); + Assert.assertEquals(7, typeVerifier.localsChecked); +} +public void test0018_primitive_variable_types() throws Exception { + InferredTypeVerifier typeVerifier = new InferredTypeVerifier(); + this.runConformTest( + new String[] { + "Y.java", + "class Y {\n" + + " boolean[] booleanArray = { true };\n" + + " byte[] byteArray = { 1 };\n" + + " char[] charArray = { 'c' };\n" + + " short[] shortArray = { 42 };\n" + + " int[] intArray = { 42 };\n" + + " long[] longArray = { 42L };\n" + + " float[] floatArray = { 0.1f };\n" + + " double[] doubleArray = { 0.2d };\n" + + "\n" + + " void testBuiltins() {\n" + + " var z_boolean = false;\n" + + " var b_byte = (byte)0xff;\n" + + " var c_char = 'c';\n" + + " var s_short = (short)42;\n" + + " var i_int = 42;\n" + + " var l_long = 42L;\n" + + " var f_float = 0.25f;\n" + + " var d_double = 0.35d;\n" + + " }\n" + + "\n" + + " void testBuiltinsForEach() {\n" + + " for (var z_boolean : booleanArray) { System.out.print(\".\"); }\n" + + " for (var b_byte : byteArray) { System.out.print(\".\"); }\n" + + " for (var c_char : charArray) { System.out.print(\".\"); }\n" + + " for (var s_short : shortArray) { System.out.print(\".\"); }\n" + + " for (var i_int : intArray) { System.out.print(\".\"); }\n" + + " for (var l_long : longArray) { System.out.print(\".\"); }\n" + + " for (var f_float : floatArray) { System.out.print(\".\"); }\n" + + " for (var d_double : doubleArray) { System.out.print(\".\"); }\n" + + " }\n" + + " void testBuiltinsArray() {\n" + + " var z_booleanARRAY = booleanArray;\n" + + " var b_byteARRAY = byteArray;\n" + + " var c_charARRAY = charArray;\n" + + " var s_shortARRAY = shortArray;\n" + + " var i_intARRAY = intArray;\n" + + " var l_longARRAY = longArray;\n" + + " var f_floatARRAY = floatArray;\n" + + " var d_doubleARRAY = doubleArray;\n" + + " }\n" + + "\n" + + "}\n" + }, + typeVerifier); + Assert.assertEquals(24, typeVerifier.localsChecked); +} +public void test0018_project_variable_types() throws Exception { + InferredTypeVerifier typeVerifier = new InferredTypeVerifier(); + this.runConformTest( + new String[] { + "Z.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.io.Serializable;\n" + + "\n" + + "class Z {\n" + + "\n" + + " void testExtends() {\n" + + " var l1_CollectionOfExtString = extendsString();\n" + + " for (var l2_CollectionOfExtString = extendsString() ; ; ) { break; }\n" + + " for (var l3_CollectionOfExtString : extendsStringArr()) { break; }\n" + + " for (var l4_CollectionOfExtString : extendsCollectionIterable()) { break; }\n" + + " for (var l5_String : extendsString()) { break; }\n" + + " }\n" + + "\n" + + " void testExtendsFbound() { \n" + + " var l1_CollectionExt_ComparableAny = extendsTBound();\n" + + " for (var l2_CollectionExt_ComparableAny = extendsTBound() ; ; ) { break; }\n" + + " for (var l3_CollectionExt_ComparableAny : extendsTBoundArray()) { break; }\n" + + " for (var l3_CollectionExt_ComparableAny : extendsTBoundIter()) { break; }\n" + + " for (var l4_ComparableAny : extendsTBound()) { break; }\n" + + " }\n" + + "\n" + + " void testSuperTBound() {\n" + + " var s_CollectionAny = superTBound();\n" + + " for (var s2_CollectionAny = superTBound() ; ; ) { break; }\n" + + " for (var s2_CollectionAny : superTBoundArray()) { break; }\n" + + " for (var s2_CollectionAny : superTBoundIter()) { break; }\n" + + " for (var s2_Object : superTBound()) { break; }\n" + + " }\n" + + "\n" + + " void testCollectSuper() {\n" + + " var s_CollectionOfSuperString = superString();\n" + + " for (var s2_CollectionOfSuperString = superString() ; ; ) { break; }\n" + + " for (var s2_CollectionOfSuperString : superStringArray()) { break; }\n" + + " for (var s2_CollectionOfSuperString : superCollectionIterable()) { break; }\n" + + " for (var s2_Object : superString()) { break; }\n" + + " }\n" + + "\n" + + " void testUnbound() {\n" + + " var s_CollectionAny = unboundedString();\n" + + " for (var s2_CollectionAny = unboundedString() ; ; ) { break; }\n" + + " for (var s2_CollectionAny : unboundedStringArray()) { break; }\n" + + " for (var s2_CollectionAny : unboundedCollectionIterable()) { break; }\n" + + " for (var s2_Object : unboundedString()) { break; }\n" + + " }\n" + + "\n" + + " void testTypeOfAnAnonymousClass() {\n" + + " var o_AnonymousObjectSubclass = new Object() { };\n" + + " for (var s2_AnonymousObjectSubclass = new Object() { } ; ; ) { break; }\n" + + " for (var s2_AnonymousObjectSubclass : arrayOf(new Object() { })) { break; }\n" + + " for (var s2_AnonymousObjectSubclass : listOf(new Object() { })) { break; }\n" + + " }\n" + + "\n" + + " void testTypeOfAnAnonymousInterface() {\n" + + " var r_AnonymousRunnableSubclass = new Runnable() { public void run() { } };\n" + + " for (var s2_AnonymousRunnableSubclass = new Runnable() { public void run() { } } ; ; ) { break; }\n" + + " for (var s2_AnonymousRunnableSubclass : arrayOf(new Runnable() { public void run() { } })) { break; }\n" + + " for (var s2_AnonymousRunnableSubclass : listOf(new Runnable() { public void run() { } })) { break; }\n" + + " }\n" + + "\n" + + " void testTypeOfIntersectionType() {\n" + + " var c_IntLongFloat = choose(1, 1L);\n" + + " for (var s2_IntLongFloat = choose(1, 1L) ; ;) { break; }\n" + + " for (var s2_IntLongFloat : arrayOf(choose(1, 1L))) { break; }\n" + + " for (var s2_IntLongFloat : listOf(choose(1, 1L))) { break; }\n" + + " }\n" + + "\n" + + " public void testProjections() {\n" + + " var inter_ListTestAndSerializable = getIntersections();\n" + + " var r_TestAndSerializable = inter_ListTestAndSerializable.get(0);\n" + + " }\n" + + "\n" + + " Collection extendsString() { return null; }\n" + + " Collection superString() { return null; }\n" + + " Collection unboundedString() { return null; }\n" + + "\n" + + " Collection[] extendsStringArr() { return null; }\n" + + " Collection[] superStringArray() { return null; }\n" + + " Collection[] unboundedStringArray() { return null; }\n" + + "\n" + + " Iterable> extendsCollectionIterable() { return null; }\n" + + " Iterable> superCollectionIterable() { return null; }\n" + + " Iterable> unboundedCollectionIterable() { return null; }\n" + + "\n" + + " > Collection extendsTBound() { return null; }\n" + + " > Collection superTBound() { return null; }\n" + + "\n" + + " > Collection[] extendsTBoundArray() { return null; }\n" + + " > Collection[] superTBoundArray() { return null; }\n" + + "\n" + + " > Iterable> extendsTBoundIter() { return null; }\n" + + " > Iterable> superTBoundIter() { return null; }\n" + + "\n" + + " Collection listOf(TBound b) { return null; }\n" + + " TBound[] arrayOf(TBound b) { return null; }\n" + + "\n" + + " TBound choose(TBound b1, TBound b2) { return b1; }\n" + + " List getIntersections() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + typeVerifier); + Assert.assertEquals(39, typeVerifier.localsChecked); +} +public void testBug531832() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " for (var[] v : args) { }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (var[] v : args) { }\n" + + " ^\n" + + "'var' is not allowed as an element type of an array\n" + + "----------\n"); +} +public void testBug530879() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo() { }\n" + + " public static void main(String [] args) {\n" + + " for (var v : foo()) { }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for (var v : foo()) { }\n" + + " ^\n" + + "Variable initializer is 'void' -- cannot infer variable type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " for (var v : foo()) { }\n" + + " ^^^^^\n" + + "Can only iterate over an array or an instance of java.lang.Iterable\n" + + "----------\n"); +} +public void testBug530879a() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " for (var v : null) { }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (var v : null) { }\n" + + " ^\n" + + "Cannot infer type for local variable initialized to 'null'\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " for (var v : null) { }\n" + + " ^^^^\n" + + "Can only iterate over an array or an instance of java.lang.Iterable\n" + + "----------\n"); +} +public void testBug532349() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Boolean p) {\n" + + " Y y = new Y<>();\n" + + " var v = y;\n" + + " Y tmp = v;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + "}" + }); +} +public void testBug532349a() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "public class X {\n" + + " public static void foo(Boolean p) {\n" + + " List> l = new ArrayList<>();\n" + + " var dlv = l;\n" + + " for (var iv : dlv) {\n" + + " Y id = iv;\n" + + " }" + + " }\n" + + "}\n" + + "class Y {}" + }); +} +public void testBug532349b() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Boolean p) {\n" + + " Y y = new Y<>();\n" + + " try (var v = y) {\n" + + " Y tmp = v;\n" + + " } catch (Exception e) { }\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " @Override\n" + + " public void close() throws Exception {}\n" + + "}" + }); +} +public void testBug532351() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Boolean p) {\n" + + " Y y = new Y(); // Javac reports, ECJ accepts\n" + + " var v = y;\n" + + " Y tmp = v;\n" + + " }\n" + + " class Y {\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y y = new Y(); // Javac reports, ECJ accepts\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"); +} +public void testBug531025() { + runNegativeTest( + new String[] { + "a/Ann.java", + "package a;\n" + + "public @interface Ann {}\n", + "a/AnnM.java", + "package a;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.METHOD)\n" + + "public @interface AnnM {}\n", + "a/AnnD.java", + "package a;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.LOCAL_VARIABLE)\n" + + "public @interface AnnD {}\n", + "a/AnnT.java", + "package a;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface AnnT {}\n", + "a/AnnDT.java", + "package a;\n" + + "import java.lang.annotation.*;\n" + + "@Target({ElementType.LOCAL_VARIABLE, ElementType.TYPE_USE})\n" + + "public @interface AnnDT {}\n", + "X.java", + "import a.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " void test(List strings) {\n" + + " @Ann var v = strings;\n" + + " @AnnM var vm = strings;\n" + + " @AnnD var vd = strings;\n" + + " @AnnT var vt = \"\";\n" + + " @AnnDT var vdt = this;\n" + + " for (@AnnD var fvd : strings) {}\n" + + " for (@AnnT var fvt : strings) {}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " @AnnM var vm = strings;\n" + + " ^^^^^\n" + + "The annotation @AnnM is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " @AnnT var vt = \"\";\n" + + " ^^^^^\n" + + "The annotation @AnnT is disallowed for this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " for (@AnnT var fvt : strings) {}\n" + + " ^^^^^\n" + + "The annotation @AnnT is disallowed for this location\n" + + "----------\n"); +} +public void testBug532349_001() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public static void foo() {\n" + + " Y y = new Y<>();\n" + + " var v = y.t;\n" + + " Integer dsbType0 = v;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public T t;\n" + + "}" + }); +} +public void testBug532349_002() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public static void foo() {\n" + + " Y y = new Y<>();\n" + + " var v = y.t;\n" + + " Integer dsbType0 = v;\n" + + " }\n" + + "}\n" + + "interface I { }\n" + + "class Y {\n" + + " public T t;\n" + + "}" + }); +} +public void testBug532349_003() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public static void foo(Y y) {\n" + + " var v = y.t;\n" + + " Integer dsbType0 = v;\n" + + " I i = v;\n" + + " }\n" + + "}\n" + + "interface I { }\n" + + "class Y {\n" + + " public T t;\n" + + "}" + }); +} +public void testBug532349_004() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "class X {\n" + + " public static void foo() {\n" + + " Y y = new Y<>();\n" + + " var v = y.t;\n" + + " Integer dsbType0 = v;\n" + + " Serializable s = v;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public T t;\n" + + "}" + }); +} +public void testBug532349_005() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "class X {\n" + + " public static void foo() {\n" + + " Y y = new Y<>();\n" + + " var v = y.t;\n" + + " I i = v;\n" + + " Serializable s = v;\n" + + " }\n" + + "}\n" + + "interface I { }\n" + + "class Y {\n" + + " public T t;\n" + + "}" + }); +} +public void testBug532349_006() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "class X {\n" + + " public static void foo() {\n" + + " Y y = new Y<>();\n" + + " var v = y.t;\n" + + " I i = v;\n" + + " Serializable s = v;\n" + + " }\n" + + "}\n" + + "interface I { }\n" + + "class Y {\n" + + " public T t;\n" + + "}", + }); +} +public void testBug532349_007() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public static void foo() {\n" + + " Z z = new Z<>();\n" + + " var v = z.t;\n" + + " X x = v.t;\n" + + " v.doSomething();\n" + + " }\n" + + "}\n" + + "interface I { void doSomething();}\n" + + "class Z> {\n" + + " public T t;\n" + + "}\n" + + "class Y {\n" + + " public T t;\n" + + "}", + }); +} +public void testBug532349_008() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public static void foo() {\n" + + " Z> z = new Z<>();\n" + + " var v = z.t;\n" + + " C c = v.t;\n" + + " v.doSomething();\n" + + " }\n" + + "}\n" + + "interface I { void doSomething();}\n" + + "class C extends X{ }\n" + + "class Z {\n" + + " public T t;\n" + + "}\n" + + "class Y {\n" + + " public T t;\n" + + "}", + }); +} +public void testBug532349_009() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "class X {\n" + + " public static void foo() {\n" + + " Y y = new Y<>();\n" + + " var v = y.t;\n" + + " I i = v;\n" + + " Serializable s = v;\n" + + " }\n" + + "}\n" + + "interface I { }\n" + + "interface J extends I{}" + + "class Y {\n" + + " public T t;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Serializable s = v;\n" + + " ^\n" + + "Type mismatch: cannot convert from I to Serializable\n" + + "----------\n"); +} +public void testBug532349_010() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "class X {\n" + + " public static void foo(C c) {\n" + + " var v = c.t;\n" + + " v = (I&Serializable) new D();\n" + + " v.doSomething();\n" + + " }\n" + + "}\n" + + "interface I { void doSomething();}\n" + + "class C{ T t;}\n" + + "class D implements I, Serializable { public void doSomething() {} }\n" + }); +} +public void testBug532349_11() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " static > W boo() {\n" + + " return null;\n" + + " }\n" + + " public static void foo() {\n" + + " var v = boo();\n" + + " var var = v.t;\n" + + " Y y = var.r;\n" + + " }\n" + + "}\n" + + "class Y extends X { }\n" + + "class D{ R r;}\n" + + "class W> { T t; }\n" + }); +} +public void testBug532349_12() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public static void foo(D d) {\n" + + " var v = d;\n" + + " D dy = v;\n" + + " D dx = v;\n" + + " }\n" + + "}\n" + + "class Y extends X{ }\n" + + "class D{ R r;}\n" + }); +} +public void testBug532349_13() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public static void foo(D> d) {\n" + + " var v = d.r;\n" + + " Y yn = v;\n" + + " Y yi = v;\n" + + " }\n" + + "}\n" + + "class Y{ }\n" + + "class D>{ R r;}\n" + }); +} +public void testBug532349_14() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public static void foo(A ac) {\n" + + " C c = new C(100);\n" + + " var c1 = ac;\n" + + " A a1 = c1;\n" + + " A a2 = new A(new B());\n" + + " a2 = c1;\n" + + " }\n" + + "}\n" + + "class C extends B{\n" + + " T t;\n" + + " C(T t) {\n" + + " this.t = t;\n" + + " }\n" + + "}\n" + + "class B { }\n" + + "class A {\n" + + " A(Q e) {}\n" + + "}" + }); +} +public void testBug532349_15() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static A m(T t) {\n" + + " return new A(t);\n" + + " }\n" + + " public static > A m2(A u) {\n" + + " return new A(u);\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " A checkValue1 = new C(10);\n" + + " var varValue = m2(m(checkValue1));\n" + + " if(!varValue.t.t.equals(10)) {\n" + + " System.out.println(\"Error:\");\n" + + " }\n" + + " if(varValue.t.methodOnI1() != true) {\n" + + " System.out.println(\"Error:\");\n" + + " }\n" + + " }" + + "}\n" + + "class A {\n" + + " E t;\n" + + " A(E t) {\n" + + " this.t = t;\n" + + " }\n" + + " A u;\n" + + " A (A u) {\n" + + " this(u.t);\n" + + " this.u = u;\n" + + " }\n" + + "}\n" + + "interface I1 {\n" + + " default boolean methodOnI1() {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "class C extends A implements I1 {\n" + + " C(T t) {\n" + + " super(t);\n" + + " }\n" + + "}" + }, ""); +} +public void testBug532349_0016() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " public static void foo() {\n" + + " Y yi = new Y<>();\n" + + " var vi = yi.t;\n" + + " Y yj = new Y<>();\n" + + " vi = yj.t;\n" + + " }\n" + + "}\n" + + "interface I { }\n" + + "class Y {\n" + + " public T t;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " vi = yj.t;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from Integer to Number & I\n" + + "----------\n"); +} +public void testBug532349_0017() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " public static void foo(Y y) {\n" + + " var vy = y;\n" + + " Y yi = new Y<>();\n" + + " vy = yi;\n" + + " }\n" + + "}\n" + + "interface I { }\n" + + "class Y {\n" + + " public T t;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " vy = yi;\n" + + " ^^\n" + + "Type mismatch: cannot convert from Y to Y\n" + + "----------\n"); +} +public void testBug532920() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "public class X {\n" + + " static void foo(Z ef) { \n" + + " for (var l : ef.t) {\n" + + " l = new Object();\n" + + " }\n" + + " }\n" + + "}\n" + + "class I {// implements Iterable {\n" + + " T t;\n" + + "}\n" + + "class Q {}\n" + + "class Y extends Q{ }\n" + + "class Z> {\n" + + " I t;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for (var l : ef.t) {\n" + + " ^^^^\n" + + "Can only iterate over an array or an instance of java.lang.Iterable\n" + + "----------\n"); +} +public void testBug567183_1() { + this.runNegativeTest( + new String[] { + "p/Item.java", + "package p;\n" + + "class Item {\n" + + "}", + "p/Container.java", + "package p;\n" + + "import java.util.List;\n" + + "\n" + + "public class Container {\n" + + " public final List items = null;\n" + + "}", + "p/PublicItem.java", + "package p;\n" + + "public class PublicItem extends Item {\n" + + "}", + "p1/X.java", + "package p1;\n" + + "import p.Container;\n" + + "import p.PublicItem;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var container = new Container();\n" + + " for (var item : container.items) {\n" + + " if (item instanceof PublicItem) {\n" + + " var publicItem = (PublicItem) item;\n" + + " System.out.println(publicItem);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 7)\n" + + " for (var item : container.items) {\n" + + " ^^^^\n" + + "The type Item is not visible\n" + + "----------\n"); +} +public void testBug567183_2() { + this.runNegativeTest( + new String[] { + "p/Item.java", + "package p;\n" + + "class Item {\n" + + "}", + "p/Container.java", + "package p;\n" + + "import java.util.List;\n" + + "\n" + + "public class Container {\n" + + " public final List> items = null;\n" + + "}", + "p/PublicItem.java", + "package p;\n" + + "public class PublicItem extends Item {\n" + + "}", + "p1/X.java", + "package p1;\n" + + "import java.util.List;\n" + + "import p.Container;\n" + + "import p.PublicItem;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var container = new Container();\n" + + " for (var item : container.items) {\n" + + " if (item instanceof PublicItem) {\n" + + " var publicItem = (PublicItem) item;\n" + + " System.out.println(publicItem);\n" + + " } else if (item instanceof List) {\n" + + " for (var item2 : item) {}\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 13)\n" + + " for (var item2 : item) {}\n" + + " ^^^^^\n" + + "The type Item is not visible\n" + + "----------\n"); +} +public void testBug567183_3() { + this.runNegativeTest( + new String[] { + "p/Item.java", + "package p;\n" + + "class Item {\n" + + "}", + "p/Container.java", + "package p;\n" + + "import java.util.List;\n" + + "\n" + + "public class Container {\n" + + " public final List> items = null;\n" + + "}", + "p/PublicItem.java", + "package p;\n" + + "public class PublicItem extends Item {\n" + + "}", + "p1/X.java", + "package p1;\n" + + "import p.Container;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var container = new Container();\n" + + " for (var item : container.items) { // Javac over-eagerly reports this\n" + + " }\n" + + " }\n" + + "}\n" + + "" + }, + ""); +} +public void testBug567183_4() { + this.runNegativeTest( + new String[] { + "p/Item.java", + "package p;\n" + + "class Item {\n" + + "}", + "p/Container.java", + "package p;\n" + + "import java.util.List;\n" + + "\n" + + "public class Container {\n" + + " public final List> items = null;\n" + + "}", + "p/PublicItem.java", + "package p;\n" + + "public class PublicItem extends Item {\n" + + "}", + "p1/X.java", + "package p1;\n" + + "import p.Container;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var container = new Container();\n" + + " var item1 = container.items.get(0).get(0);\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 6)\n" + + " var item1 = container.items.get(0).get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type Item is not visible\n" + + "----------\n"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP323VarLambdaParamsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP323VarLambdaParamsTest.java new file mode 100644 index 0000000000..7cc99e38ff --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JEP323VarLambdaParamsTest.java @@ -0,0 +1,346 @@ +/******************************************************************************* + * Copyright (c) 2018, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.IOException; +import java.util.Map; + +import org.eclipse.jdt.core.tests.util.CompilerTestSetup; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JEP323VarLambdaParamsTest extends AbstractRegressionTest { + +public static Class testClass() { + return JEP323VarLambdaParamsTest.class; +} +@Override +public void initialize(CompilerTestSetup setUp) { + super.initialize(setUp); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_11); +} + +public JEP323VarLambdaParamsTest(String testName){ + super(testName); +} +static { +// TESTS_NUMBERS = new int[] { 1 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] { "testBug534787_positive_001" }; +} +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_11); + return options; +} + +public void testBug534787_positive_001() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = (var x) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " lam.apply(20);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k);\n" + + "}\n" + }, + "SUCCESS 20"); +} +public void testBug534787_positive_002() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = (var x, var y) -> {System.out.println(\"SUCCESS \" + (x+y));};\n" + + " lam.apply(20, 200);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k, Integer l);\n" + + "}\n" + }, + "SUCCESS 220"); +} +public void testBug534787_positive_003() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = var -> {System.out.println(\"SUCCESS \" + var);};\n" + + " lam.apply(10);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k);\n" + + "}\n" + }, + "SUCCESS 10"); +} +public void testBug534787_positive_004() throws IOException { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = (var var) -> {System.out.println(\"SUCCESS \" + var);};\n" + + " lam.apply(10);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k);\n" + + "}\n" + }, + "SUCCESS 10"); +} +public void testBug534787_negative_001() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = (var x, y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k, Integer z);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I lam = (var x, y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^^^\n" + + "Syntax error on token \"var\", ( expected after this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I lam = (var x, y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^\n" + + "Syntax error on token \")\", delete this token\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " I lam = (var x, y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^\n" + + "Syntax error, insert \")\" to complete Expression\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " I lam = (var x, y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^\n" + + "Syntax error, insert \")\" to complete Expression\n" + + "----------\n"); +} +public void testBug534787_negative_002() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = (var x, Integer y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " lam.apply(20, 200);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k, Integer z);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I lam = (var x, Integer y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^\n" + + "\'var\' cannot be mixed with non-var parameters\n" + + "----------\n"); +} +public void testBug534787_negative_003() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = (Integer x, var y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " lam.apply(20, 200);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k, Integer z);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I lam = (Integer x, var y) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^\n" + + "'var' cannot be mixed with non-var parameters\n" + + "----------\n"); +} +public void testBug534787_negative_004() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = (var x, var y, var...s) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " lam.apply(20, 200, \"hello\");\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k, Integer z, String s);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I lam = (var x, var y, var...s) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^\n" + + "'var' is not allowed as an element type of an array\n" + + "----------\n"); +} +public void testBug534787_negative_005() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = (var x, Integer y, var...s) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " lam.apply(20, 200, \"hello\");\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k, Integer z, String s);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I lam = (var x, Integer y, var...s) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^\n" + + "'var' cannot be mixed with non-var parameters\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I lam = (var x, Integer y, var...s) -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^\n" + + "'var' is not allowed as an element type of an array\n" + + "----------\n"); +} + +public void testBug534787_negative_006() throws IOException { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I lam = var x -> {System.out.println(\"SUCCESS \" + x);};\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void apply(Integer k);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I lam = var x -> {System.out.println(\"SUCCESS \" + x);};\n" + + " ^\n" + + "Syntax error on token \"x\", delete this token\n" + + "----------\n"); +} +public void testBug536159_01() throws IOException { + runConformTest(new String[] { + "X.java", + "public class X {\n" + + "public static void main(String[] args) {\n" + + " FI x = (int i []) -> 5;\n" + + " }\n" + + "}\n" + + "interface FI {\n" + + " public int foo (int i []);\n" + + "}" + }); +} +public void testBug536159_02() throws IOException { + runConformTest(new String[] { + "X.java", + "public class X {\n" + + "public static void main(String[] args) {\n" + + " FI x = (int[] i []) -> 5;\n" + + " }\n" + + "}\n" + + "interface FI {\n" + + " public int foo (int i [][]);\n" + + "}" + }); +} +public void testBug536159_03() throws IOException { + runConformTest(new String[] { + "X.java", + "public class X {\n" + + "public static void main(String[] args) {\n" + + " FI x = (int i [][]) -> 5;\n" + + " }\n" + + "}\n" + + "interface FI {\n" + + " public int foo (int i [][]);\n" + + "}" + }); +} +public void testBug536159_04() throws IOException { + runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + "public static void main(String[] args) {\n" + + " FI x = (var i []) -> 5;\n" + + " }\n" + + "}\n" + + "interface FI {\n" + + " public int foo (int i []);\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " FI x = (var i []) -> 5;\n" + + " ^\n" + + "\'var\' is not allowed as an element type of an array\n" + + "----------\n"); +} +public void testBug541532_01() throws IOException { + runConformTest(new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void foo(List list) {\n" + + " list.stream()\n" + + " .map((var s) -> s.toLowerCase())\n" + + " .forEach(System.out::println);\n" + + "\n" + + " list.stream()\n" + + " .filter((var s) -> s.length() == 1)\n" + + " .forEach(System.out::println);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String[] greetings = {\"hello\", \"world\"};\n" + + " X.foo(Arrays.asList(greetings));\n" + + " }\n" + + "}\n" + }, + "hello\nworld"); +} +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java new file mode 100644 index 0000000000..62e23d7697 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR308SpecSnippetTests.java @@ -0,0 +1,2911 @@ +/******************************************************************************* + * Copyright (c) 2011, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for + * Bug 415541 - [1.8][compiler] Type annotations in the body of static initializer get dropped + * Bug 415543 - [1.8][compiler] Incorrect bound index in RuntimeInvisibleTypeAnnotations attribute + * Bug 415397 - [1.8][compiler] Type Annotations on wildcard type argument dropped + * Bug 415399 - [1.8][compiler] Type annotations on constructor results dropped by the code generator + * Bug 415470 - [1.8][compiler] Type annotations on class declaration go vanishing + * Bug 414384 - [1.8] type annotation on abbreviated inner class is not marked as inner type + * Jesper S Moller - Contributions for + * Bug 416885 - [1.8][compiler]IncompatibleClassChange error (edit) + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JSR308SpecSnippetTests extends AbstractRegressionTest { + + static { +// TESTS_NUMBERS = new int [] { 19 }; +// TESTS_NAMES = new String [] { "test033" }; + } + public static Class testClass() { + return JSR308SpecSnippetTests.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + public JSR308SpecSnippetTests(String testName){ + super(testName); + } + + // Enables the tests to run individually + @Override + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); + defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + return defaultOptions; + } + + public void test001() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.List;\n" + + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface NonNull {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "class Document {}\n" + + "public class X {\n" + + " Map<@NonNull String, @NonEmpty List<@Readonly Document>> files;\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @NonNull(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #11 @NonEmpty(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n" + + " #12 @Readonly(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // note, javac 8b100 emits offset incorrectly. + public void test002() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface NonNull {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "class Document {}\n" + + "public class X {\n" + + " static void foo(X o) {\n" + + " o.<@NonNull String>m(\"...\");\n" + + " }\n" + + " void m(String s) {}\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #24 @NonNull(\n" + + " target type = 0x49 METHOD_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 3\n" + + " type argument index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test003() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.Collection;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Existing {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "class File {}\n" + + "class X { \n" + + " Collection c;\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @Existing(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), WILDCARD]\n" + + " )\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [14]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + "\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @Existing(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test004() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.List;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Existing {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "class File {}\n" + + "abstract class X implements @Readonly List<@Readonly T> { }\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #23 @Readonly(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " )\n" + + " #23 @Readonly(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test005() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.List;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Critical {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "class TemperatureException extends RuntimeException{}\n" + + "class X {\n" + + " void monitorTemperature() throws @Critical TemperatureException {}\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #19 @Critical(\n" + + " target type = 0x17 THROWS\n" + + " throws index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test006() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Interned {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Tainted {}\n" + + "class MyObject {\n" + + " class NestedClass {}\n" + + "}\n" + + "class List {}\n" + + "class X {\n" + + " static void monitorTemperature(MyObject myVar) {\n" + + " new @Interned MyObject();\n" + + " new @NonEmpty @Readonly List();\n" + + " myVar.new @Tainted NestedClass();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #33 @Interned(\n" + + " target type = 0x44 NEW\n" + + " offset = 0\n" + + " )\n" + + " #34 @NonEmpty(\n" + + " target type = 0x44 NEW\n" + + " offset = 6\n" + + " )\n" + + " #35 @Readonly(\n" + + " target type = 0x44 NEW\n" + + " offset = 6\n" + + " )\n" + + " #36 @Tainted(\n" + + " target type = 0x44 NEW\n" + + " offset = 12\n" + + " location = [INNER_TYPE]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test007() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.Map;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface NonNull {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Tainted {}\n" + + "class MyObject {\n" + + " class NestedClass {}\n" + + "}\n" + + "class List {}\n" + + "class X {\n" + + " Map.@NonNull Entry e;\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @NonNull(\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test008() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface NonNull {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface A {}\n" + + "@Target(TYPE_USE)\n" + + "@interface B {}\n" + + "class MyObject {\n" + + " class NestedClass {}\n" + + "}\n" + + "class List {}\n" + + "class Type1 {}\n" + + "interface Type2 {}\n" + + "class X {\n" + + " static void monitorTemperature(Object myObject) {\n" + + " String myString = (@NonNull String) myObject;\n" + + " Type1 x = (@A Type1 & @B Type2) null;\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #29 @NonNull(\n" + + " target type = 0x47 CAST\n" + + " offset = 1\n" + + " type argument index = 0\n" + + " )\n" + + " #30 @B(\n" + + " target type = 0x47 CAST\n" + + " offset = 6\n" + + " type argument index = 1\n" + + " )\n" + + " #31 @A(\n" + + " target type = 0x47 CAST\n" + + " offset = 9\n" + + " type argument index = 0\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test009() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface NonNull {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface A {}\n" + + "@Target(TYPE_USE)\n" + + "@interface B {}\n" + + "class MyObject {\n" + + " class NestedClass {}\n" + + "}\n" + + "class List {}\n" + + "class Type1 {}\n" + + "interface Type2 {}\n" + + "class X {\n" + + " static void monitorTemperature(Object myObject) {\n" + + " boolean isNonNull = myObject instanceof @NonNull String;\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #23 @NonNull(\n" + + " target type = 0x43 INSTANCEOF\n" + + " offset = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test010() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.Arrays;\n" + + "import java.util.Date;\n" + + "import java.util.List;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface NonNull {}\n" + + "@Target(TYPE_USE)\n" + + "@interface English {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Vernal {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonNegative {}\n" + + "class MyObject {\n" + + " class NestedClass {}\n" + + "}\n" + + "class Type1 {}\n" + + "interface I {\n" + + " int f(Date d);\n" + + "}\n" + + "interface J {\n" + + " int f(List l);\n" + + "}\n" + + "interface K {\n" + + " void s(int [] ia);\n" + + "}\n" + + "class X {\n" + + " static void monitorTemperature(Object myObject) {\n" + + " I i = @Vernal Date::getDay;\n" + + " J j = List<@English String>::size;\n" + + " K k = Arrays::<@NonNegative Integer>sort;\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #36 @Vernal(\n" + + " target type = 0x46 METHOD_REFERENCE\n" + + " offset = 0\n" + + " )\n" + + " #37 @English(\n" + + " target type = 0x46 METHOD_REFERENCE\n" + + " offset = 6\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #38 @NonNegative(\n" + + " target type = 0x4b METHOD_REFERENCE_TYPE_ARGUMENT\n" + + " offset = 12\n" + + " type argument index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test011() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.*;\n" + + "import java.io.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Immutable { int value() default 0; }\n" + + "class X {\n" + + " List<@Immutable ? extends Comparable> a;\n" + + " List> b;\n" + + " List<@Immutable(1) ? extends @Immutable(2) Comparable> c;\n" + + " Map<@Immutable(1) ? extends Comparable,@Immutable(2) ? extends @Immutable(3) Serializable> d;\n" + + "}\n", + }, + ""); + // javac b100 + // Field a: + // RuntimeInvisibleTypeAnnotations: + // 0: #9(): FIELD, location=[TYPE_ARGUMENT(0)] + // Field b: + // RuntimeInvisibleTypeAnnotations: + // 0: #9(): FIELD, location=[TYPE_ARGUMENT(0), WILDCARD] + // Field c: + // RuntimeInvisibleTypeAnnotations: + // 0: #9(#12=I#13): FIELD, location=[TYPE_ARGUMENT(0)] + // 1: #9(#12=I#14): FIELD, location=[TYPE_ARGUMENT(0), WILDCARD] + // Field d: + // RuntimeInvisibleTypeAnnotations: + // 0: #9(#12=I#13): FIELD, location=[TYPE_ARGUMENT(0)] + // 1: #9(#12=I#14): FIELD, location=[TYPE_ARGUMENT(1)] + // 2: #9(#12=I#18): FIELD, location=[TYPE_ARGUMENT(1), WILDCARD] + String expectedOutput = + "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" + + "class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"a\"\n" + + " constant #6 utf8: \"Ljava/util/List;\"\n" + + " constant #7 utf8: \"Signature\"\n" + + " constant #8 utf8: \"Ljava/util/List<+Ljava/lang/Comparable;>;\"\n" + + " constant #9 utf8: \"RuntimeInvisibleTypeAnnotations\"\n" + + " constant #10 utf8: \"LImmutable;\"\n" + + " constant #11 utf8: \"b\"\n" + + " constant #12 utf8: \"c\"\n" + + " constant #13 utf8: \"value\"\n" + + " constant #14 integer: 1\n" + + " constant #15 integer: 2\n" + + " constant #16 utf8: \"d\"\n" + + " constant #17 utf8: \"Ljava/util/Map;\"\n" + + " constant #18 utf8: \"Ljava/util/Map<+Ljava/lang/Comparable;+Ljava/io/Serializable;>;\"\n" + + " constant #19 integer: 3\n" + + " constant #20 utf8: \"\"\n" + + " constant #21 utf8: \"()V\"\n" + + " constant #22 utf8: \"Code\"\n" + + " constant #23 method_ref: #3.#24 java/lang/Object. ()V\n" + + " constant #24 name_and_type: #20.#21 ()V\n" + + " constant #25 utf8: \"LineNumberTable\"\n" + + " constant #26 utf8: \"LocalVariableTable\"\n" + + " constant #27 utf8: \"this\"\n" + + " constant #28 utf8: \"LX;\"\n" + + " constant #29 utf8: \"SourceFile\"\n" + + " constant #30 utf8: \"X.java\"\n" + + " \n" + + " // Field descriptor #6 Ljava/util/List;\n" + + " // Signature: Ljava/util/List<+Ljava/lang/Comparable;>;\n" + + " java.util.List a;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @Immutable(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " \n" + + " // Field descriptor #6 Ljava/util/List;\n" + + " // Signature: Ljava/util/List<+Ljava/lang/Comparable;>;\n" + + " java.util.List b;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @Immutable(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), WILDCARD]\n" + + " )\n" + + " \n" + + " // Field descriptor #6 Ljava/util/List;\n" + + " // Signature: Ljava/util/List<+Ljava/lang/Comparable;>;\n" + + " java.util.List c;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @Immutable(\n" + + " #13 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #10 @Immutable(\n" + + " #13 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), WILDCARD]\n" + + " )\n" + + " \n" + + " // Field descriptor #17 Ljava/util/Map;\n" + + " // Signature: Ljava/util/Map<+Ljava/lang/Comparable;+Ljava/io/Serializable;>;\n" + + " java.util.Map d;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @Immutable(\n" + + " #13 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #10 @Immutable(\n" + + " #13 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n" + + " #10 @Immutable(\n" + + " #13 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1), WILDCARD]\n" + + " )\n" + + " \n" + + " // Method descriptor #21 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [23]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test012() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "class Document {}\n" + + "class X {\n" + + " @Readonly Document [][] docs1 = new @Readonly Document [2][12]; // array of arrays of read-only documents\n" + + " Document @Readonly [][] docs2 = new Document @Readonly [2][12]; // read-only array of arrays of documents\n" + + " Document[] @Readonly [] docs3 = new Document[2] @Readonly [12]; // array of read-only arrays of documents\n" + + "}\n", + }, + ""); + String expectedOutput = + " Document[][] docs1;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Readonly(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " \n" + + " // Field descriptor #6 [[LDocument;\n" + + " Document[][] docs2;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Readonly(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n" + + " // Field descriptor #6 [[LDocument;\n" + + " Document[][] docs3;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Readonly(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 3, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [14]\n" + + " 4 aload_0 [this]\n" + + " 5 iconst_2\n" + + " 6 bipush 12\n" + + " 8 multianewarray Document[][] [16]\n" + + " 12 putfield X.docs1 : Document[][] [17]\n" + + " 15 aload_0 [this]\n" + + " 16 iconst_2\n" + + " 17 bipush 12\n" + + " 19 multianewarray Document[][] [16]\n" + + " 23 putfield X.docs2 : Document[][] [19]\n" + + " 26 aload_0 [this]\n" + + " 27 iconst_2\n" + + " 28 bipush 12\n" + + " 30 multianewarray Document[][] [16]\n" + + " 34 putfield X.docs3 : Document[][] [21]\n" + + " 37 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 4, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 26, line: 9]\n" + + " [pc: 37, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 38] local: this index: 0 type: X\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Readonly(\n" + + " target type = 0x44 NEW\n" + + " offset = 8\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #8 @Readonly(\n" + + " target type = 0x44 NEW\n" + + " offset = 19\n" + + " )\n" + + " #8 @Readonly(\n" + + " target type = 0x44 NEW\n" + + " offset = 30\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test013() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Immutable {}\n" + + "class Document {}\n" + + "class X {\n" + + " @Immutable X() {\n" + + " }\n" + + "}\n", + }, + ""); + // javac b100 gives: + // RuntimeInvisibleTypeAnnotations: + // 0: #9(): METHOD_RETURN + String expectedOutput = + "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" + + "class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #5.#6 ()V\n" + + " constant #10 utf8: \"LineNumberTable\"\n" + + " constant #11 utf8: \"LocalVariableTable\"\n" + + " constant #12 utf8: \"this\"\n" + + " constant #13 utf8: \"LX;\"\n" + + " constant #14 utf8: \"RuntimeInvisibleTypeAnnotations\"\n" + + " constant #15 utf8: \"LImmutable;\"\n" + + " constant #16 utf8: \"SourceFile\"\n" + + " constant #17 utf8: \"X.java\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 4, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #15 @Immutable(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test014() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Immutable {}\n" + + "class Document {}\n" + + "interface I {\n" + + " void foo();\n" + + "}\n" + + "class X {\n" + + " void foo (X this, X this) {\n" + + " }\n" + + " static void foo (X this) {\n" + + " }\n" + + " I i = (X this) -> {};\n" + + "}\n" + + "class Y {\n" + + " void foo(X this) {}\n" + + " void foo(Y this, int x) {}\n" + + " class Z {\n" + + " void foo(Y.Z this) {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " void foo (X this, X this) {\n" + + " ^^^^\n" + + "Only the first formal parameter may be declared explicitly as \'this\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " static void foo (X this) {\n" + + " ^^^^\n" + + "Explicit \'this\' parameter is allowed only in instance methods of non-anonymous classes and inner class constructors\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " I i = (X this) -> {};\n" + + " ^^^^^^^^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method foo()\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " I i = (X this) -> {};\n" + + " ^^^^\n" + + "Lambda expressions cannot declare a this parameter\n" + + "----------\n" + + "5. ERROR in X.java (at line 17)\n" + + " void foo(X this) {}\n" + + " ^\n" + + "The declared type of the explicit \'this\' parameter is expected to be Y\n" + + "----------\n" + + "6. WARNING in X.java (at line 18)\n" + + " void foo(Y this, int x) {}\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "7. ERROR in X.java (at line 18)\n" + + " void foo(Y this, int x) {}\n" + + " ^\n" + + "The declared type of the explicit \'this\' parameter is expected to be Y\n" + + "----------\n"); + } + public void test015() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Immutable {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "class Document {}\n" + + "interface I {\n" + + " void foo();\n" + + "}\n" + + "class X {\n" + + " class Y {\n" + + " void foo(@Immutable X.@Readonly Y this) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @Immutable(\n" + + " target type = 0x15 METHOD_RECEIVER\n" + + " )\n" + + " #22 @Readonly(\n" + + " target type = 0x15 METHOD_RECEIVER\n" + + " location = [INNER_TYPE]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$Y.class", "Y", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test016() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface A {}\n" + + "@Target(TYPE_USE)\n" + + "@interface B {}\n" + + "@Target(TYPE_USE)\n" + + "@interface C {}\n" + + "public class X {}\n" + + "class Outer {\n" + + " class Middle {\n" + + " class Inner {\n" + + " void innerMethod(@A Outer.@B Middle.@C Inner this) { }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @A(\n" + + " target type = 0x15 METHOD_RECEIVER\n" + + " )\n" + + " #22 @B(\n" + + " target type = 0x15 METHOD_RECEIVER\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " #23 @C(\n" + + " target type = 0x15 METHOD_RECEIVER\n" + + " location = [INNER_TYPE, INNER_TYPE]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "Outer$Middle$Inner.class", "Inner", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test017() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Result {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Receiver {}\n" + + "class Document {}\n" + + "interface I {\n" + + " void foo();\n" + + "}\n" + + "class X {\n" + + " class Y {\n" + + " Y(@Receiver X X.this, boolean b) { }\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #22 @Receiver(\n" + + " target type = 0x15 METHOD_RECEIVER\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$Y.class", "Y", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test018() throws Exception { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "@interface Receiver {}\n" + + "class Document {}\n" + + "interface I {\n" + + " void foo();\n" + + "}\n" + + "class X {\n" + + " void foo(@Receiver X this) {}\n" + + " class Y {\n" + + " Y(@Receiver X X.this, boolean b) { }\n" + + " }\n" + + "}\n", + }; + runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8231436; + runner.runConformTest(); + } + public void test019() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "class X<@Readonly T> {\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @Readonly(\n" + + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test020() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.@NotAllowed Date; // illegal!\n" + + "import @IllegalSyntax java.util.Date; // illegal syntax\n" + + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Even {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NotAllowed {}\n" + + "@Target(TYPE_USE)\n" + + "@interface IllegalSyntax {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Legal {}\n" + + "class X {\n" + + " static int staticField;\n" + + " static class StaticNestedClass {}\n" + + " void foo() {\n" + + " Object o = @Even int.class; // illegal!\n" + + " o = int @NonEmpty [].class; // illegal!\n" + + " int x = @IllegalSyntax X.staticField;\n" + + " StaticNestedClass snc = (@IllegalSyntax X.StaticNestedClass) null;\n" + + " X.@Legal StaticNestedClass lsnc = (X.@Legal StaticNestedClass) null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import java.util.@NotAllowed Date; // illegal!\n" + + " ^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " import @IllegalSyntax java.util.Date; // illegal syntax\n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. WARNING in X.java (at line 2)\n" + + " import @IllegalSyntax java.util.Date; // illegal syntax\n" + + " ^^^^^^^^^^^^^^\n" + + "The import java.util.Date is never used\n" + + "----------\n" + + "4. ERROR in X.java (at line 19)\n" + + " Object o = @Even int.class; // illegal!\n" + + " ^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "5. ERROR in X.java (at line 20)\n" + + " o = int @NonEmpty [].class; // illegal!\n" + + " ^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "6. ERROR in X.java (at line 21)\n" + + " int x = @IllegalSyntax X.staticField;\n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "7. ERROR in X.java (at line 22)\n" + + " StaticNestedClass snc = (@IllegalSyntax X.StaticNestedClass) null;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + public void test021() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.@NotAllowed Date; // illegal!\n" + + "import @IllegalSyntax java.util.Date; // illegal syntax\n" + + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Even {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NonEmpty {}\n" + + "@Target(TYPE_USE)\n" + + "@interface NotAllowed {}\n" + + "@Target(TYPE_USE)\n" + + "@interface IllegalSyntax {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Legal {}\n" + + "interface I {\n" + + " int f(Y y);\n" + + "}\n" + + "class Y {\n" + + " int f;\n" + + " int x(Y y) {}\n" + + "}\n" + + "class X extends Y {\n" + + " static int staticField;\n" + + " static class StaticNestedClass {}\n" + + " void foo() {\n" + + " Object o = @Even int.class; // illegal!\n" + + " o = int @NonEmpty [].class; // illegal!\n" + + " int x = @IllegalSyntax X.staticField;\n" + + " StaticNestedClass snc = (@IllegalSyntax X.StaticNestedClass) null;\n" + + " X.@Legal StaticNestedClass lsnc = (X.@Legal StaticNestedClass) null;\n" + + " int x2 = @IllegalSyntax X.super.f;\n" + + " I i = @IllegalSyntax X.super::x;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import java.util.@NotAllowed Date; // illegal!\n" + + " ^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " import @IllegalSyntax java.util.Date; // illegal syntax\n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. WARNING in X.java (at line 2)\n" + + " import @IllegalSyntax java.util.Date; // illegal syntax\n" + + " ^^^^^^^^^^^^^^\n" + + "The import java.util.Date is never used\n" + + "----------\n" + + "4. ERROR in X.java (at line 26)\n" + + " Object o = @Even int.class; // illegal!\n" + + " ^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "5. ERROR in X.java (at line 27)\n" + + " o = int @NonEmpty [].class; // illegal!\n" + + " ^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "6. ERROR in X.java (at line 28)\n" + + " int x = @IllegalSyntax X.staticField;\n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "7. ERROR in X.java (at line 29)\n" + + " StaticNestedClass snc = (@IllegalSyntax X.StaticNestedClass) null;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "8. ERROR in X.java (at line 31)\n" + + " int x2 = @IllegalSyntax X.super.f;\n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "9. ERROR in X.java (at line 32)\n" + + " I i = @IllegalSyntax X.super::x;\n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + public void test022() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "class X {\n" + + " @Readonly int foo() @Readonly [] {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #17 @Readonly(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " location = [ARRAY]\n" + + " )\n" + + " #17 @Readonly(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test023() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "interface X {\n" + + " default @Readonly int foo() @Readonly [] {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #13 @Readonly(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " location = [ARRAY]\n" + + " )\n" + + " #13 @Readonly(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test024() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Critical {}\n" + + "class X {\n" + + " void foo() {\n" + + " try {\n" + + " System.out.println();\n" + + " } catch (@Readonly NullPointerException | @Critical ArrayIndexOutOfBoundsException e) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #34 @Readonly(\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n" + + " #35 @Critical(\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test025() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Critical {}\n" + + "class X {\n" + + " void foo(@Readonly int [] [] @Critical ... x) {\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #19 @Readonly(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #20 @Critical(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test026() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Readonly {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Critical {}\n" + + "class X {\n" + + " void foo(@Readonly int [] [] @Critical ... x) {\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #19 @Readonly(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #20 @Critical(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test027() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface NonNull {}\n" + + "class X {\n" + + " @NonNull String var1, arr2[];\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @NonNull(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n" + + " // Field descriptor #10 [Ljava/lang/String;\n" + + " java.lang.String[] arr2;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @NonNull(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test028() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.List;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface NonNull {}\n" + + "class X<@NonNull T> {\n" + + " <@NonNull K> void foo() {}\n" + + " List<@NonNull ?> l;\n" + + "}\n", + }, + ""); + // javac b100 + // On the type declaration: + // RuntimeInvisibleTypeAnnotations: + // 0: #9(): CLASS_TYPE_PARAMETER, param_index=0 + // On the method: + // RuntimeInvisibleTypeAnnotations: + // 0: #9(): METHOD_TYPE_PARAMETER, param_index=0 + // On the field: + // RuntimeInvisibleTypeAnnotations: + // 0: #9(): FIELD, location=[TYPE_ARGUMENT(0)] + String expectedOutput = + "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" + + "// Signature: Ljava/lang/Object;\n" + + "class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"l\"\n" + + " constant #6 utf8: \"Ljava/util/List;\"\n" + + " constant #7 utf8: \"Signature\"\n" + + " constant #8 utf8: \"Ljava/util/List<*>;\"\n" + + " constant #9 utf8: \"RuntimeInvisibleTypeAnnotations\"\n" + + " constant #10 utf8: \"LNonNull;\"\n" + + " constant #11 utf8: \"\"\n" + + " constant #12 utf8: \"()V\"\n" + + " constant #13 utf8: \"Code\"\n" + + " constant #14 method_ref: #3.#15 java/lang/Object. ()V\n" + + " constant #15 name_and_type: #11.#12 ()V\n" + + " constant #16 utf8: \"LineNumberTable\"\n" + + " constant #17 utf8: \"LocalVariableTable\"\n" + + " constant #18 utf8: \"this\"\n" + + " constant #19 utf8: \"LX;\"\n" + + " constant #20 utf8: \"LocalVariableTypeTable\"\n" + + " constant #21 utf8: \"LX;\"\n" + + " constant #22 utf8: \"foo\"\n" + + " constant #23 utf8: \"()V\"\n" + + " constant #24 utf8: \"SourceFile\"\n" + + " constant #25 utf8: \"X.java\"\n" + + " constant #26 utf8: \"Ljava/lang/Object;\"\n" + + " \n" + + " // Field descriptor #6 Ljava/util/List;\n" + + " // Signature: Ljava/util/List<*>;\n" + + " java.util.List l;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @NonNull(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [14]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Signature: ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @NonNull(\n" + + " target type = 0x1 METHOD_TYPE_PARAMETER\n" + + " type parameter index = 0\n" + + " )\n" + + "\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @NonNull(\n" + + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 0\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test029() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target({TYPE_USE}) @interface TAnno { }\n" + + "@Target({METHOD}) @interface MAnno { }\n" + + "@Target({METHOD, TYPE_USE}) @interface MTAnno { }\n" + + "@Target({FIELD}) @interface FAnno { }\n" + + "@Target({FIELD, TYPE_USE}) @interface FTAnno { }\n" + + "class X {\n" + + "@FAnno Object field4; // legal, one field annotation\n" + + "@TAnno Object field5; // legal, one type annotation\n" + + "@FTAnno Object field6; // legal, one field annotation and one type annotation\n" + + "@FAnno java.lang.Object field7; // legal, one field annotation\n" + + "@TAnno java.lang.Object field8; // illegal\n" + + "@FTAnno java.lang.Object field9; // legal, one field annotation\n" + + "java.lang. @FAnno Object field10; // illegal\n" + + "java.lang. @TAnno Object field11; // legal, one type annotation\n" + + "java.lang. @FTAnno Object field12; // legal, one type annotation\n" + + "@MAnno void myMethod1() { } // legal, one method annotation\n" + + "@TAnno void myMethod2() { } // illegal\n" + + "@MTAnno void myMethod3() { } // legal, one method annotation\n" + + "@MAnno Object myMethod4() { } // legal, one method annotation\n" + + "@TAnno Object myMethod5() { } // legal, one type annotation\n" + + "@MTAnno Object myMethod6() { } // legal, one method annotation and one type annotation\n" + + "@MAnno java.lang.Object myMethod7() { } // legal, one method annotation\n" + + "@TAnno java.lang.Object myMethod8() { } // illegal\n" + + "@MTAnno java.lang.Object myMethod9() { } // legal, one method annotation\n" + + "java.lang. @MAnno Object myMethod10() { } // illegal\n" + + "java.lang. @TAnno Object myMethod11() { } // legal, one type annotation\n" + + "java.lang. @MTAnno Object myMethod12() { } // legal, one type annotation\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " @TAnno java.lang.Object field8; // illegal\n" + + " ^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " java.lang. @FAnno Object field10; // illegal\n" + + " ^^^^^^\n" + + "The annotation @FAnno is disallowed for this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " @TAnno void myMethod2() { } // illegal\n" + + " ^^^^^^\n" + + "Type annotation is illegal for a method that returns void\n" + + "----------\n" + + "4. ERROR in X.java (at line 25)\n" + + " @TAnno java.lang.Object myMethod8() { } // illegal\n" + + " ^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "5. ERROR in X.java (at line 27)\n" + + " java.lang. @MAnno Object myMethod10() { } // illegal\n" + + " ^^^^^^\n" + + "The annotation @MAnno is disallowed for this location\n" + + "----------\n"); + } + public void test030() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target({TYPE_USE}) @interface TypeAnnotation { }\n" + + "@Target({TYPE}) @interface Annotation { }\n" + + "@Annotation @TypeAnnotation class X {\n" + + "}\n", + }, + ""); + // javac b100 produces: + // RuntimeInvisibleAnnotations: + // 0: #11() LAnnotation; + // 1: #12() LTypeAnnotation; + String expectedOutput = + "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" + + "class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #5.#6 ()V\n" + + " constant #10 utf8: \"LineNumberTable\"\n" + + " constant #11 utf8: \"LocalVariableTable\"\n" + + " constant #12 utf8: \"this\"\n" + + " constant #13 utf8: \"LX;\"\n" + + " constant #14 utf8: \"SourceFile\"\n" + + " constant #15 utf8: \"X.java\"\n" + + " constant #16 utf8: \"RuntimeInvisibleAnnotations\"\n" + + " constant #17 utf8: \"LAnnotation;\"\n" + + " constant #18 utf8: \"LTypeAnnotation;\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + "\n" + + " RuntimeInvisibleAnnotations: \n" + + " #17 @Annotation(\n" + + " )\n" + + " #18 @TypeAnnotation(\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test030a() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Target({TYPE_USE}) @interface TypeAnnotation { }\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Target({TYPE}) @interface Annotation { }\n" + + "@Annotation @TypeAnnotation class X {\n" + + "}\n", + }, + ""); + String expectedOutput = + "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" + + "class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #5.#6 ()V\n" + + " constant #10 utf8: \"LineNumberTable\"\n" + + " constant #11 utf8: \"LocalVariableTable\"\n" + + " constant #12 utf8: \"this\"\n" + + " constant #13 utf8: \"LX;\"\n" + + " constant #14 utf8: \"SourceFile\"\n" + + " constant #15 utf8: \"X.java\"\n" + + " constant #16 utf8: \"RuntimeVisibleAnnotations\"\n" + + " constant #17 utf8: \"LAnnotation;\"\n" + + " constant #18 utf8: \"LTypeAnnotation;\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + "\n" + + " RuntimeVisibleAnnotations: \n" + + " #17 @Annotation(\n" + + " )\n" + + " #18 @TypeAnnotation(\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test030b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + // Only TYPE_USE annotations get this special treatment + "@Target({TYPE_PARAMETER}) @interface TypeAnnotation { }\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Target({TYPE}) @interface Annotation { }\n" + + "@Annotation @TypeAnnotation class X {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " @Annotation @TypeAnnotation class X {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The annotation @TypeAnnotation is disallowed for this location\n" + + "----------\n"); + } + public void test030c() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Target({TYPE_USE,TYPE_PARAMETER}) @interface TypeAnnotation { }\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Target({TYPE}) @interface Annotation { }\n" + + "@Annotation @TypeAnnotation class X {\n" + + "}\n", + }, + ""); + String expectedOutput = + "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" + + "class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #5.#6 ()V\n" + + " constant #10 utf8: \"LineNumberTable\"\n" + + " constant #11 utf8: \"LocalVariableTable\"\n" + + " constant #12 utf8: \"this\"\n" + + " constant #13 utf8: \"LX;\"\n" + + " constant #14 utf8: \"SourceFile\"\n" + + " constant #15 utf8: \"X.java\"\n" + + " constant #16 utf8: \"RuntimeVisibleAnnotations\"\n" + + " constant #17 utf8: \"LAnnotation;\"\n" + + " constant #18 utf8: \"LTypeAnnotation;\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + "\n" + + " RuntimeVisibleAnnotations: \n" + + " #17 @Annotation(\n" + + " )\n" + + " #18 @TypeAnnotation(\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // Test that annotations in initializer code are not attached to the field. + public void test031() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target({TYPE_USE}) @interface NonNull { }\n" + + "class X {\n" + + " X x = new @NonNull X();\n" + + "}\n", + }, + ""); + String expectedOutput = + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 new X [1]\n" + + " 8 dup\n" + + " 9 invokespecial X() [12]\n" + + " 12 putfield X.x : X [13]\n" + + " 15 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 15, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 16] local: this index: 0 type: X\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #19 @NonNull(\n" + + " target type = 0x44 NEW\n" + + " offset = 5\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // Test co-existence of parameter annotations and type annotations. + public void test032() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target({TYPE_USE}) @interface NonNull { }\n" + + "@Target({PARAMETER}) @interface ParameterAnnot { }\n" + + "class X {\n" + + " void foo(@NonNull X this, @ParameterAnnot @NonNull X x) {\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " void foo(X x);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: x index: 1 type: X\n" + + " RuntimeInvisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #17 @ParameterAnnot(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #20 @NonNull(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " #20 @NonNull(\n" + + " target type = 0x15 METHOD_RECEIVER\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // Test type annotations in initializer code. + public void test033() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target({TYPE_USE}) @interface NonNull { }\n" + + "class X {\n" + + " static {\n" + + " Object o = (@NonNull Object) new @NonNull Object();\n" + + " }\n" + + " {\n" + + " new @NonNull Object();\n" + + " }\n" + + " X() {\n" + + " }\n" + + " X (int x) {\n" + + " }\n" + + "}\n", + }, + ""); + // javac b100 + // For the annotations in the static {...} the clinit has: + // RuntimeInvisibleTypeAnnotations: + // 0: #11(): CAST, offset=0, type_index=0 + // 1: #11(): NEW, offset=0 + // javac is skipping production of the cast so offset is 0. JDT is currently always producing the + // checkcast for an annotated cast so the offset is 7. + + // For the annotations in the initializer {...} the constructors both have: + // RuntimeInvisibleTypeAnnotations: + // 0: #11(): NEW, offset=4 + + String expectedOutput = + "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" + + "class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #10.#6 ()V\n" + + " constant #10 utf8: \"\"\n" + + " constant #11 utf8: \"LineNumberTable\"\n" + + " constant #12 utf8: \"LocalVariableTable\"\n" + + " constant #13 utf8: \"RuntimeInvisibleTypeAnnotations\"\n" + + " constant #14 utf8: \"LNonNull;\"\n" + + " constant #15 utf8: \"this\"\n" + + " constant #16 utf8: \"LX;\"\n" + + " constant #17 utf8: \"(I)V\"\n" + + " constant #18 utf8: \"x\"\n" + + " constant #19 utf8: \"I\"\n" + + " constant #20 utf8: \"SourceFile\"\n" + + " constant #21 utf8: \"X.java\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " static {};\n" + + " 0 new java.lang.Object [3]\n" + + " 3 dup\n" + + " 4 invokespecial java.lang.Object() [8]\n" + + " 7 checkcast java.lang.Object [3]\n" + + " 10 astore_0\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 11, line: 7]\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #14 @NonNull(\n" + + " target type = 0x44 NEW\n" + + " offset = 0\n" + + " )\n" + + " #14 @NonNull(\n" + + " target type = 0x47 CAST\n" + + " offset = 7\n" + + " type argument index = 0\n" + + " )\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 new java.lang.Object [3]\n" + + " 7 invokespecial java.lang.Object() [8]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " [pc: 4, line: 9]\n" + + " [pc: 10, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: this index: 0 type: X\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #14 @NonNull(\n" + + " target type = 0x44 NEW\n" + + " offset = 4\n" + + " )\n" + + " \n" + + " // Method descriptor #17 (I)V\n" + + " // Stack: 1, Locals: 2\n" + + " X(int x);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 new java.lang.Object [3]\n" + + " 7 invokespecial java.lang.Object() [8]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 4, line: 9]\n" + + " [pc: 10, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: this index: 0 type: X\n" + + " [pc: 0, pc: 11] local: x index: 1 type: int\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #14 @NonNull(\n" + + " target type = 0x44 NEW\n" + + " offset = 4\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test034() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target({TYPE_USE}) @interface NonNull { }\n" + + "class X {\n" + + "}\n", + }, + ""); + // javac b100 + // RuntimeInvisibleTypeAnnotations: + // 0: #13(): CLASS_TYPE_PARAMETER_BOUND, param_index=0, bound_index=1 + // bound_index is 1 because the bound is an interface, not a class + String expectedOutput = + "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" + + "// Signature: Ljava/lang/Object;\n" + + "class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #5.#6 ()V\n" + + " constant #10 utf8: \"LineNumberTable\"\n" + + " constant #11 utf8: \"LocalVariableTable\"\n" + + " constant #12 utf8: \"this\"\n" + + " constant #13 utf8: \"LX;\"\n" + + " constant #14 utf8: \"LocalVariableTypeTable\"\n" + + " constant #15 utf8: \"LX;\"\n" + + " constant #16 utf8: \"SourceFile\"\n" + + " constant #17 utf8: \"X.java\"\n" + + " constant #18 utf8: \"Signature\"\n" + + " constant #19 utf8: \"Ljava/lang/Object;\"\n" + + " constant #20 utf8: \"RuntimeInvisibleTypeAnnotations\"\n" + + " constant #21 utf8: \"LNonNull;\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + "\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @NonNull(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 1\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + // Bug 415543 - Incorrect bound index in RuntimeInvisibleTypeAnnotations attribute + public void test034b() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.io.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target({TYPE_USE}) @interface NonNull { }\n" + + "\n" + + "class X {\n" + + " void one(T t) {}\n" + + " void two(T t) {}\n" + + " void three(T t) {}\n" + + " void four(T t) {}\n" + + " void five(T t) {}\n" + + "}\n", + }, + ""); + String expectedOutput = + "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" + + "// Signature: Ljava/lang/Object;\n" + + "class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #5.#6 ()V\n" + + " constant #10 utf8: \"LineNumberTable\"\n" + + " constant #11 utf8: \"LocalVariableTable\"\n" + + " constant #12 utf8: \"this\"\n" + + " constant #13 utf8: \"LX;\"\n" + + " constant #14 utf8: \"LocalVariableTypeTable\"\n" + + " constant #15 utf8: \"LX;\"\n" + + " constant #16 utf8: \"one\"\n" + + " constant #17 utf8: \"(Ljava/lang/Comparable;)V\"\n" + + " constant #18 utf8: \"Signature\"\n" + + " constant #19 utf8: \"(TT;)V\"\n" + + " constant #20 utf8: \"t\"\n" + + " constant #21 utf8: \"Ljava/lang/Comparable;\"\n" + + " constant #22 utf8: \"TT;\"\n" + + " constant #23 utf8: \"RuntimeInvisibleTypeAnnotations\"\n" + + " constant #24 utf8: \"LNonNull;\"\n" + + " constant #25 utf8: \"two\"\n" + + " constant #26 utf8: \"(TT;)V\"\n" + + " constant #27 utf8: \"three\"\n" + + " constant #28 utf8: \"four\"\n" + + " constant #29 utf8: \"(Ljava/lang/Object;)V\"\n" + + " constant #30 utf8: \"(TT;)V\"\n" + + " constant #31 utf8: \"Ljava/lang/Object;\"\n" + + " constant #32 utf8: \"five\"\n" + + " constant #33 utf8: \"(TT;)V\"\n" + + " constant #34 utf8: \"SourceFile\"\n" + + " constant #35 utf8: \"X.java\"\n" + + " constant #36 utf8: \"Ljava/lang/Object;\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #17 (Ljava/lang/Comparable;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 0, Locals: 2\n" + + " void one(java.lang.Comparable t);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: t index: 1 type: java.lang.Comparable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: t index: 1 type: T\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #24 @NonNull(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 1\n" + + " )\n" + + " \n" + + " // Method descriptor #17 (Ljava/lang/Comparable;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 0, Locals: 2\n" + + " void two(java.lang.Comparable t);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: t index: 1 type: java.lang.Comparable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: t index: 1 type: T\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #24 @NonNull(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 2\n" + + " )\n" + + " \n" + + " // Method descriptor #17 (Ljava/lang/Comparable;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 0, Locals: 2\n" + + " void three(java.lang.Comparable t);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: t index: 1 type: java.lang.Comparable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: t index: 1 type: T\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #24 @NonNull(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 1\n" + + " )\n" + + " #24 @NonNull(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 2\n" + + " )\n" + + " \n" + + " // Method descriptor #29 (Ljava/lang/Object;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 0, Locals: 2\n" + + " void four(java.lang.Object t);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: t index: 1 type: java.lang.Object\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: t index: 1 type: T\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #24 @NonNull(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 1\n" + + " )\n" + + " \n" + + " // Method descriptor #29 (Ljava/lang/Object;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 0, Locals: 2\n" + + " void five(java.lang.Object t);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: t index: 1 type: java.lang.Object\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: t index: 1 type: T\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #24 @NonNull(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 1\n" + + " )\n" + + " #24 @NonNull(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 2\n" + + " )\n" + + "\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #24 @NonNull(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 2\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test035() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target({TYPE_USE}) @interface NonNull { }\n" + + "\n" + + "class X {\n" + + " void foo() {\n" + + " @NonNull X [] x = new X[10];\n" + + " System.out.println(x);\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " void foo();\n" + + " 0 bipush 10\n" + + " 2 anewarray X [1]\n" + + " 5 astore_1 [x]\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 9 aload_1 [x]\n" + + " 10 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [21]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 6, line: 8]\n" + + " [pc: 13, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " [pc: 6, pc: 14] local: x index: 1 type: X[]\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #30 @NonNull(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 6, pc: 14] index: 1\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // test that parameter index does not include explicit this parameter. + public void test036() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target({TYPE_USE}) @interface NonNull { }\n" + + "class X {\n" + + " void foo(@NonNull X this, @NonNull X x) {\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " void foo(X x);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: x index: 1 type: X\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #18 @NonNull(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " #18 @NonNull(\n" + + " target type = 0x15 METHOD_RECEIVER\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test037() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Readonly {\n" + + " String value() default \"default\";\n" + + "}\n" + + "public class X {\n" + + " X [] x = new @Readonly X @Readonly [10];\n" + + "}\n", + }, + ""); + String expectedOutput = + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 bipush 10\n" + + " 7 anewarray X [1]\n" + + " 10 putfield X.x : X[] [12]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 13, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #19 @Readonly(\n" + + " target type = 0x44 NEW\n" + + " offset = 7\n" + + " location = [ARRAY]\n" + + " )\n" + + " #19 @Readonly(\n" + + " target type = 0x44 NEW\n" + + " offset = 7\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // test anonymous class, the class itself should have class_extends target ? + public void test038() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Readonly {\n" + + " String value() default \"default\";\n" + + "}\n" + + "public class X {\n" + + " X x = new @Readonly X() {\n" + + " };\n" + + "}\n", + }, + ""); + String expectedOutput = + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 new X$1 [12]\n" + + " 8 dup\n" + + " 9 aload_0 [this]\n" + + " 10 invokespecial X$1(X) [14]\n" + + " 13 putfield X.x : X [17]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 4, line: 8]\n" + + " [pc: 16, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: this index: 0 type: X\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #23 @Readonly(\n" + + " target type = 0x44 NEW\n" + + " offset = 5\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test039() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.List;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Readonly {\n" + + " String value() default \"default\";\n" + + "}\n" + + "public class X { \n" + + " void foo(List<@Readonly ?> l) {\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " void foo(java.util.List l);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: l index: 1 type: java.util.List\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 1] local: l index: 1 type: java.util.List\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #23 @Readonly(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test040() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Readonly {\n" + + " String value() default \"default\";\n" + + "}\n" + + "class X {\n" + + " class Y {}\n" + + " void foo() {\n" + + " @Readonly X x = new X();\n" + + " x.new @Readonly Y();\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #27 @Readonly(\n" + + " target type = 0x44 NEW\n" + + " offset = 8\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " #27 @Readonly(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 8, pc: 21] index: 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test041() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface B {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface C {\n" + + " String value() default \"default\";\n" + + "}\n" + + "class X {\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @A(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 0\n" + + " )\n" + + " #22 @B(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 1\n" + + " )\n" + + " #23 @C(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 1 type parameter bound index = 1\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // type path tests. + public void test042() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.Map;\n" + + "import java.util.List;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface B {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface C {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface D {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface E {\n" + + " String value() default \"default\";\n" + + "}\n" + + "class X {\n" + + " @A Map <@B ? extends @C String, @D List<@E Object>> f;\n" + + "}\n", + }, + ""); + String expectedOutput = + " java.util.Map f;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @A(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #11 @B(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #12 @C(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), WILDCARD]\n" + + " )\n" + + " #13 @D(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n" + + " #14 @E(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]\n" + + " )\n" + + " \n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + // Bug 414384 - [1.8] type annotation on abbreviated inner class is not marked as inner type + public void test043() throws Exception { + this.runConformTest( + new String[] { + "pkg/Clazz.java", + "package pkg;\n" + + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "\n" + + "@Target({TYPE_USE}) @interface P { }\n" + + "@Target({TYPE_USE}) @interface O { }\n" + + "@Target({TYPE_USE}) @interface I { }\n" + + "\n" + + "public abstract class Clazz {\n" + + " public class Inner {}\n" + + " public abstract void n1(@I Inner i1);\n" + + " public abstract void n2(@O Clazz.@I Inner i2);\n" + + " public abstract void n3(pkg.@O Clazz.@I Inner i3);\n" + + "}\n", + }, + ""); + // javac b100 produces for the methods: + // public abstract void n1(pkg.Clazz$Inner); + // RuntimeInvisibleTypeAnnotations: + // 0: #14(): METHOD_FORMAL_PARAMETER, param_index=0, location=[INNER_TYPE] + // + // public abstract void n2(pkg.Clazz$Inner); + // RuntimeInvisibleTypeAnnotations: + // 0: #14(): METHOD_FORMAL_PARAMETER, param_index=0, location=[INNER_TYPE] + // 1: #16(): METHOD_FORMAL_PARAMETER, param_index=0 + // + // public abstract void n3(pkg.Clazz$Inner); + // RuntimeInvisibleTypeAnnotations: + // 0: #14(): METHOD_FORMAL_PARAMETER, param_index=0, location=[INNER_TYPE] + // 1: #16(): METHOD_FORMAL_PARAMETER, param_index=0 + String expectedOutput = + " // Method descriptor #15 (Lpkg/Clazz$Inner;)V\n" + + " public abstract void n1(pkg.Clazz.Inner arg0);\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #17 @pkg.I(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " \n" + + + " // Method descriptor #15 (Lpkg/Clazz$Inner;)V\n" + + " public abstract void n2(pkg.Clazz.Inner arg0);\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #19 @pkg.O(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " #17 @pkg.I(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " \n" + + + " // Method descriptor #15 (Lpkg/Clazz$Inner;)V\n" + + " public abstract void n3(pkg.Clazz.Inner arg0);\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #19 @pkg.O(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " #17 @pkg.I(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #24 pkg/Clazz$Inner, outer class info: #1 pkg/Clazz\n" + + " inner name: #26 Inner, accessflags: 1 public]\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "pkg" + File.separator + "Clazz.class", "pkg.Clazz", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // More type path tests + public void test044() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface I {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface F {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface G {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface H {\n" + + " String value() default \"default\";\n" + + "}\n" + + "class X {\n" + + " @I String @F [] @G [] @H [] f;\n" + + "}\n", + }, + ""); + + String expectedOutput = + " // Field descriptor #6 [[[Ljava/lang/String;\n" + + " java.lang.String[][][] f;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @I(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #9 @F(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #10 @G(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n" + + " #11 @H(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " \n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "Z", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // More type path tests + public void test045() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface M {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface L {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface K {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface J {\n" + + " String value() default \"default\";\n" + + "}\n" + + "class O1 {\n" + + " class O2 {\n" + + " class O3 {\n" + + " class Nested {}\n" + + " }\n" + + " }\n" + + "}\n" + + "class X {\n" + + " @M O1.@L O2.@K O3.@J Nested f = null;\n" + + "}\n", + }, + ""); + + String expectedOutput = + " // Field descriptor #6 LO1$O2$O3$Nested;\n" + + " O1$O2$O3$Nested f;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @M(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #9 @L(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " #10 @K(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE, INNER_TYPE]\n" + + " )\n" + + " #11 @J(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE, INNER_TYPE, INNER_TYPE]\n" + + " )\n" + + " \n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "Z", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // More type path tests + public void test046() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.Map;\n" + + "import java.util.List;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface B {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface C {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface D {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface E {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface F {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface G {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface H {\n" + + " String value() default \"default\";\n" + + "}\n" + + "class Document {}\n" + + "class X {\n" + + " @A Map<@B Comparable<@F Object @C [] @D [] @E[]>, @G List<@H Document>> f;\n" + + "}\n", + }, + ""); + + String expectedOutput = + " java.util.Map f;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @A(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #11 @B(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #12 @F(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #13 @C(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #14 @D(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY]\n" + + " )\n" + + " #15 @E(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), TYPE_ARGUMENT(0), ARRAY, ARRAY]\n" + + " )\n" + + " #16 @G(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n" + + " #17 @H(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]\n" + + " )\n" + + " \n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "Z", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // More type path tests + public void test047() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface B {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface C {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface D {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface E {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface F {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface G {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface H {\n" + + " String value() default \"default\";\n" + + "}\n" + + "class O1 {\n" + + " class O2 {\n" + + " class O3 {\n" + + " class Nested {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + " class S {}\n" + + " class T {}\n" + + " class U {}\n" + + " class V {}\n" + + "class X {\n" + + " @H O1.@E O2<@F S, @G T>.@D O3.@A Nested<@B U, @C V> f;\n" + + "}\n", + }, + ""); + + String expectedOutput = + " // Field descriptor #6 LO1$O2$O3$Nested;\n" + + " // Signature: LO1$O2.O3.Nested;\n" + + " O1$O2$O3$Nested f;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @H(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #11 @E(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " #12 @D(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE, INNER_TYPE]\n" + + " )\n" + + " #13 @A(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE, INNER_TYPE, INNER_TYPE]\n" + + " )\n" + + " #14 @F(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE, TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #15 @G(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE, TYPE_ARGUMENT(1)]\n" + + " )\n" + + " #16 @B(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE, INNER_TYPE, INNER_TYPE, TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #17 @C(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE, INNER_TYPE, INNER_TYPE, TYPE_ARGUMENT(1)]\n" + + " )\n" + + " \n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "Z", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test048() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Readonly {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface NonNull {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface NonEmpty {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface D {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface E {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface F {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface G {\n" + + " String value() default \"default\";\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface H {\n" + + " String value() default \"default\";\n" + + "}\n" + + "\n" + + "abstract class X implements @Readonly Map<@NonNull String, @NonEmpty List<@NonNull @Readonly String>> {}\n", + }, + ""); + + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @Readonly(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " )\n" + + " #22 @NonNull(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #23 @NonEmpty(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n" + + " #22 @NonNull(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #21 @Readonly(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "Z", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test049() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n" + + "public class X {\n" + + " class Y {\n" + + " }\n" + + " @B(1) X. @B(2) Y xy;\n" + + " void foo(@B(3) X. @B(4) Y xy) {\n" + + " @B(5) X. @B(6) Y local = null; \n" + + " }\n" + + "}\n", + }, + ""); + + String expectedOutput = + " // Field descriptor #6 LX$Y;\n" + + " X$Y xy;\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #8 @B(\n" + + " #9 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " \n" + + " // Method descriptor #13 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [15]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #22 (LX$Y;)V\n" + + " // Stack: 1, Locals: 3\n" + + " void foo(X.Y xy);\n" + + " 0 aconst_null\n" + + " 1 astore_2 [local]\n" + + " 2 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 2, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 3] local: this index: 0 type: X\n" + + " [pc: 0, pc: 3] local: xy index: 1 type: X.Y\n" + + " [pc: 2, pc: 3] local: local index: 2 type: X.Y\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 5 (constant type)\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 2, pc: 3] index: 2\n" + + " )\n" + + " #8 @B(\n" + + " #9 value=(int) 6 (constant type)\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 2, pc: 3] index: 2\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 3 (constant type)\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " #8 @B(\n" + + " #9 value=(int) 4 (constant type)\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + "\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "Z", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR335ClassFileTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR335ClassFileTest.java new file mode 100644 index 0000000000..05068c6abf --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JSR335ClassFileTest.java @@ -0,0 +1,3260 @@ +/******************************************************************************* + * Copyright (c) 2013, 2018 Jesper Steen Moller, IBM and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jesper Steen Moller - initial API and implementation + * Bug 416885 - [1.8][compiler]IncompatibleClassChange error (edit) + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import junit.framework.Test; + +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.core.util.ClassFormatException; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JSR335ClassFileTest extends AbstractComparableTest { + + String versionString = null; + +public JSR335ClassFileTest(String name) { + super(name); +} +// No need for a tearDown() +@Override +protected void setUp() throws Exception { + super.setUp(); + this.versionString = AbstractCompilerTest.getVersionString(this.complianceLevel); +} + +/* + * Toggle compiler in mode -1.8 + */ +// Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which do not belong to the class are skipped... +static { +// TESTS_NAMES = new String[] { "test055" }; +// TESTS_NUMBERS = new int[] { 50, 51, 52, 53 }; +// TESTS_RANGE = new int[] { 34, 38 }; +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} +private void verifyClassFile(String expectedOutput, String classFileName, int mode) throws IOException, + ClassFormatException { + File f = new File(OUTPUT_DIR + File.separator + classFileName); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", mode); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + System.out.println("..."); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test001() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " new X().referenceExpression.run();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public Runnable referenceExpression = Thread::yield;\n" + + "}\n", + }, + "SUCCESS" + ); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"referenceExpression\"\n" + + " constant #6 utf8: \"Ljava/lang/Runnable;\"\n" + + " constant #7 utf8: \"\"\n" + + " constant #8 utf8: \"()V\"\n" + + " constant #9 utf8: \"Code\"\n" + + " constant #10 method_ref: #3.#11 java/lang/Object. ()V\n" + + " constant #11 name_and_type: #7.#8 ()V\n" + + " constant #12 invoke dynamic: #0 #13 run ()Ljava/lang/Runnable;\n" + + " constant #13 name_and_type: #14.#15 run ()Ljava/lang/Runnable;\n" + + " constant #14 utf8: \"run\"\n" + + " constant #15 utf8: \"()Ljava/lang/Runnable;\"\n" + + " constant #16 field_ref: #1.#17 X.referenceExpression Ljava/lang/Runnable;\n" + + " constant #17 name_and_type: #5.#6 referenceExpression Ljava/lang/Runnable;\n" + + " constant #18 utf8: \"LineNumberTable\"\n" + + " constant #19 utf8: \"LocalVariableTable\"\n" + + " constant #20 utf8: \"this\"\n" + + " constant #21 utf8: \"LX;\"\n" + + " constant #22 utf8: \"SourceFile\"\n" + + " constant #23 utf8: \"X.java\"\n" + + " constant #24 utf8: \"BootstrapMethods\"\n" + + " constant #25 method_ref: #26.#28 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #26 class: #27 java/lang/invoke/LambdaMetafactory\n" + + " constant #27 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #28 name_and_type: #29.#30 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #29 utf8: \"metafactory\"\n" + + " constant #30 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #31 method handle: invokestatic (6) #25 \n" + + " constant #32 method type: #8 ()V\n" + + " constant #33 method_ref: #34.#36 java/lang/Thread.yield ()V\n" + + " constant #34 class: #35 java/lang/Thread\n" + + " constant #35 utf8: \"java/lang/Thread\"\n" + + " constant #36 name_and_type: #37.#8 yield ()V\n" + + " constant #37 utf8: \"yield\"\n" + + " constant #38 method handle: invokestatic (6) #33 \n" + + " constant #39 method type: #8 ()V\n" + + " constant #40 utf8: \"InnerClasses\"\n" + + " constant #41 class: #42 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #42 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #43 class: #44 java/lang/invoke/MethodHandles\n" + + " constant #44 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #45 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/Runnable;\n" + + " public java.lang.Runnable referenceExpression;\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 invokedynamic 0 run() : java.lang.Runnable [12]\n" + + " 10 putfield X.referenceExpression : java.lang.Runnable [16]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 13, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #41 java/lang/invoke/MethodHandles$Lookup, outer class info: #43 java/lang/invoke/MethodHandles\n" + + " inner name: #45 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 31 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #32 ()V\n" + + " #38 invokestatic java/lang/Thread.yield:()V\n" + + " #39 ()V\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test002() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " new X().referenceExpression.consume(\"SUCCESS\");\n" + + " }\n" + + " public static void printIt(Object o) {\n" + + " System.out.println(o.toString());\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public ObjectConsumer referenceExpression = Main::printIt;\n" + + "}\n", + "ObjectConsumer.java", + "public interface ObjectConsumer {\n" + + " void consume(Object obj);\n" + + "}\n", + }, + "SUCCESS" + ); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"referenceExpression\"\n" + + " constant #6 utf8: \"LObjectConsumer;\"\n" + + " constant #7 utf8: \"\"\n" + + " constant #8 utf8: \"()V\"\n" + + " constant #9 utf8: \"Code\"\n" + + " constant #10 method_ref: #3.#11 java/lang/Object. ()V\n" + + " constant #11 name_and_type: #7.#8 ()V\n" + + " constant #12 invoke dynamic: #0 #13 consume ()LObjectConsumer;\n" + + " constant #13 name_and_type: #14.#15 consume ()LObjectConsumer;\n" + + " constant #14 utf8: \"consume\"\n" + + " constant #15 utf8: \"()LObjectConsumer;\"\n" + + " constant #16 field_ref: #1.#17 X.referenceExpression LObjectConsumer;\n" + + " constant #17 name_and_type: #5.#6 referenceExpression LObjectConsumer;\n" + + " constant #18 utf8: \"LineNumberTable\"\n" + + " constant #19 utf8: \"LocalVariableTable\"\n" + + " constant #20 utf8: \"this\"\n" + + " constant #21 utf8: \"LX;\"\n" + + " constant #22 utf8: \"SourceFile\"\n" + + " constant #23 utf8: \"X.java\"\n" + + " constant #24 utf8: \"BootstrapMethods\"\n" + + " constant #25 method_ref: #26.#28 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #26 class: #27 java/lang/invoke/LambdaMetafactory\n" + + " constant #27 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #28 name_and_type: #29.#30 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #29 utf8: \"metafactory\"\n" + + " constant #30 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #31 method handle: invokestatic (6) #25 \n" + + " constant #32 utf8: \"(Ljava/lang/Object;)V\"\n" + + " constant #33 method type: #32 (Ljava/lang/Object;)V\n" + + " constant #34 method_ref: #35.#37 Main.printIt (Ljava/lang/Object;)V\n" + + " constant #35 class: #36 Main\n" + + " constant #36 utf8: \"Main\"\n" + + " constant #37 name_and_type: #38.#32 printIt (Ljava/lang/Object;)V\n" + + " constant #38 utf8: \"printIt\"\n" + + " constant #39 method handle: invokestatic (6) #34 \n" + + " constant #40 method type: #32 (Ljava/lang/Object;)V\n" + + " constant #41 utf8: \"InnerClasses\"\n" + + " constant #42 class: #43 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #43 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #44 class: #45 java/lang/invoke/MethodHandles\n" + + " constant #45 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #46 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 LObjectConsumer;\n" + + " public ObjectConsumer referenceExpression;\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 invokedynamic 0 consume() : ObjectConsumer [12]\n" + + " 10 putfield X.referenceExpression : ObjectConsumer [16]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 13, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #42 java/lang/invoke/MethodHandles$Lookup, outer class info: #44 java/lang/invoke/MethodHandles\n" + + " inner name: #46 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 31 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup" + + ";Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #33 (Ljava/lang/Object;)V\n" + + " #39 invokestatic Main.printIt:(Ljava/lang/Object;)V\n" + + " #40 (Ljava/lang/Object;)V\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test003() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().referenceExpression.makeString(new Main()));\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public ObjectToString referenceExpression = Object::toString;\n" + + "}\n", + "ObjectToString.java", + "public interface ObjectToString {\n" + + " String makeString(Object obj);\n" + + "}\n", + }, + "SUCCESS" + ); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"referenceExpression\"\n" + + " constant #6 utf8: \"LObjectToString;\"\n" + + " constant #7 utf8: \"\"\n" + + " constant #8 utf8: \"()V\"\n" + + " constant #9 utf8: \"Code\"\n" + + " constant #10 method_ref: #3.#11 java/lang/Object. ()V\n" + + " constant #11 name_and_type: #7.#8 ()V\n" + + " constant #12 invoke dynamic: #0 #13 makeString ()LObjectToString;\n" + + " constant #13 name_and_type: #14.#15 makeString ()LObjectToString;\n" + + " constant #14 utf8: \"makeString\"\n" + + " constant #15 utf8: \"()LObjectToString;\"\n" + + " constant #16 field_ref: #1.#17 X.referenceExpression LObjectToString;\n" + + " constant #17 name_and_type: #5.#6 referenceExpression LObjectToString;\n" + + " constant #18 utf8: \"LineNumberTable\"\n" + + " constant #19 utf8: \"LocalVariableTable\"\n" + + " constant #20 utf8: \"this\"\n" + + " constant #21 utf8: \"LX;\"\n" + + " constant #22 utf8: \"SourceFile\"\n" + + " constant #23 utf8: \"X.java\"\n" + + " constant #24 utf8: \"BootstrapMethods\"\n" + + " constant #25 method_ref: #26.#28 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #26 class: #27 java/lang/invoke/LambdaMetafactory\n" + + " constant #27 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #28 name_and_type: #29.#30 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #29 utf8: \"metafactory\"\n" + + " constant #30 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #31 method handle: invokestatic (6) #25 \n" + + " constant #32 utf8: \"(Ljava/lang/Object;)Ljava/lang/String;\"\n" + + " constant #33 method type: #32 (Ljava/lang/Object;)Ljava/lang/String;\n" + + " constant #34 method_ref: #3.#35 java/lang/Object.toString ()Ljava/lang/String;\n" + + " constant #35 name_and_type: #36.#37 toString ()Ljava/lang/String;\n" + + " constant #36 utf8: \"toString\"\n" + + " constant #37 utf8: \"()Ljava/lang/String;\"\n" + + " constant #38 method handle: invokevirtual (5) #34 \n" + + " constant #39 method type: #32 (Ljava/lang/Object;)Ljava/lang/String;\n" + + " constant #40 utf8: \"InnerClasses\"\n" + + " constant #41 class: #42 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #42 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #43 class: #44 java/lang/invoke/MethodHandles\n" + + " constant #44 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #45 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 LObjectToString;\n" + + " public ObjectToString referenceExpression;\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 invokedynamic 0 makeString() : ObjectToString [12]\n" + + " 10 putfield X.referenceExpression : ObjectToString [16]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 13, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #41 java/lang/invoke/MethodHandles$Lookup, outer class info: #43 java/lang/invoke/MethodHandles\n" + + " inner name: #45 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 31 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #33 (Ljava/lang/Object;)Ljava/lang/String;\n" + + " #38 java/lang/Object.toString:()Ljava/lang/String;\n" + + " #39 (Ljava/lang/Object;)Ljava/lang/String;\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test004() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().referenceExpression.produce());\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " String s = \"SUCCESS\";\n"+ + " public StringProducer referenceExpression = s::toString;\n" + + "}\n", + "StringProducer.java", + "public interface StringProducer {\n" + + " String produce();\n" + + "}\n", + }, + "SUCCESS" + ); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"s\"\n" + + " constant #6 utf8: \"Ljava/lang/String;\"\n" + + " constant #7 utf8: \"referenceExpression\"\n" + + " constant #8 utf8: \"LStringProducer;\"\n" + + " constant #9 utf8: \"\"\n" + + " constant #10 utf8: \"()V\"\n" + + " constant #11 utf8: \"Code\"\n" + + " constant #12 method_ref: #3.#13 java/lang/Object. ()V\n" + + " constant #13 name_and_type: #9.#10 ()V\n" + + " constant #14 string: #15 \"SUCCESS\"\n" + + " constant #15 utf8: \"SUCCESS\"\n" + + " constant #16 field_ref: #1.#17 X.s Ljava/lang/String;\n" + + " constant #17 name_and_type: #5.#6 s Ljava/lang/String;\n" + + " constant #18 method_ref: #3.#19 java/lang/Object.getClass ()Ljava/lang/Class;\n" + + " constant #19 name_and_type: #20.#21 getClass ()Ljava/lang/Class;\n" + + " constant #20 utf8: \"getClass\"\n" + + " constant #21 utf8: \"()Ljava/lang/Class;\"\n" + + " constant #22 invoke dynamic: #0 #23 produce (Ljava/lang/String;)LStringProducer;\n" + + " constant #23 name_and_type: #24.#25 produce (Ljava/lang/String;)LStringProducer;\n" + + " constant #24 utf8: \"produce\"\n" + + " constant #25 utf8: \"(Ljava/lang/String;)LStringProducer;\"\n" + + " constant #26 field_ref: #1.#27 X.referenceExpression LStringProducer;\n" + + " constant #27 name_and_type: #7.#8 referenceExpression LStringProducer;\n" + + " constant #28 utf8: \"LineNumberTable\"\n" + + " constant #29 utf8: \"LocalVariableTable\"\n" + + " constant #30 utf8: \"this\"\n" + + " constant #31 utf8: \"LX;\"\n" + + " constant #32 utf8: \"SourceFile\"\n" + + " constant #33 utf8: \"X.java\"\n" + + " constant #34 utf8: \"BootstrapMethods\"\n" + + " constant #35 method_ref: #36.#38 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #36 class: #37 java/lang/invoke/LambdaMetafactory\n" + + " constant #37 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #38 name_and_type: #39.#40 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #39 utf8: \"metafactory\"\n" + + " constant #40 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #41 method handle: invokestatic (6) #35 \n" + + " constant #42 utf8: \"()Ljava/lang/String;\"\n" + + " constant #43 method type: #42 ()Ljava/lang/String;\n" + + " constant #44 method_ref: #45.#47 java/lang/String.toString ()Ljava/lang/String;\n" + + " constant #45 class: #46 java/lang/String\n" + + " constant #46 utf8: \"java/lang/String\"\n" + + " constant #47 name_and_type: #48.#42 toString ()Ljava/lang/String;\n" + + " constant #48 utf8: \"toString\"\n" + + " constant #49 method handle: invokevirtual (5) #44 \n" + + " constant #50 method type: #42 ()Ljava/lang/String;\n" + + " constant #51 utf8: \"InnerClasses\"\n" + + " constant #52 class: #53 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #53 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #54 class: #55 java/lang/invoke/MethodHandles\n" + + " constant #55 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #56 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/String;\n" + + " java.lang.String s;\n" + + " \n" + + " // Field descriptor #8 LStringProducer;\n" + + " public StringProducer referenceExpression;\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 3, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 aload_0 [this]\n" + + " 5 ldc [14]\n" + + " 7 putfield X.s : java.lang.String [16]\n" + + " 10 aload_0 [this]\n" + + " 11 aload_0 [this]\n" + + " 12 getfield X.s : java.lang.String [16]\n" + + " 15 dup\n" + + " 16 invokevirtual java.lang.Object.getClass() : java.lang.Class [18]\n" + + " 19 pop\n" + + " 20 invokedynamic 0 produce(java.lang.String) : StringProducer [22]\n" + + " 25 putfield X.referenceExpression : StringProducer [26]\n" + + " 28 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 10, line: 3]\n" + + " [pc: 28, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 29] local: this index: 0 type: X\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #52 java/lang/invoke/MethodHandles$Lookup, outer class info: #54 java/lang/invoke/MethodHandles\n" + + " inner name: #56 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 41 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #43 ()Ljava/lang/String;\n" + + " #49 java/lang/String.toString:()Ljava/lang/String;\n" + + " #50 ()Ljava/lang/String;\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test005() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.allocatorExpression.produce());\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public static MainProducer allocatorExpression = Main::new;\n" + + "}\n", + "MainProducer.java", + "public interface MainProducer {\n" + + " Main produce();\n" + + "}\n", + }, + "SUCCESS" + ); + verifyClassFile("// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"allocatorExpression\"\n" + + " constant #6 utf8: \"LMainProducer;\"\n" + + " constant #7 utf8: \"\"\n" + + " constant #8 utf8: \"()V\"\n" + + " constant #9 utf8: \"Code\"\n" + + " constant #10 invoke dynamic: #0 #11 produce ()LMainProducer;\n" + + " constant #11 name_and_type: #12.#13 produce ()LMainProducer;\n" + + " constant #12 utf8: \"produce\"\n" + + " constant #13 utf8: \"()LMainProducer;\"\n" + + " constant #14 field_ref: #1.#15 X.allocatorExpression LMainProducer;\n" + + " constant #15 name_and_type: #5.#6 allocatorExpression LMainProducer;\n" + + " constant #16 utf8: \"LineNumberTable\"\n" + + " constant #17 utf8: \"LocalVariableTable\"\n" + + " constant #18 utf8: \"\"\n" + + " constant #19 method_ref: #3.#20 java/lang/Object. ()V\n" + + " constant #20 name_and_type: #18.#8 ()V\n" + + " constant #21 utf8: \"this\"\n" + + " constant #22 utf8: \"LX;\"\n" + + " constant #23 utf8: \"SourceFile\"\n" + + " constant #24 utf8: \"X.java\"\n" + + " constant #25 utf8: \"BootstrapMethods\"\n" + + " constant #26 method_ref: #27.#29 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #27 class: #28 java/lang/invoke/LambdaMetafactory\n" + + " constant #28 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #29 name_and_type: #30.#31 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #30 utf8: \"metafactory\"\n" + + " constant #31 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #32 method handle: invokestatic (6) #26 \n" + + " constant #33 utf8: \"()LMain;\"\n" + + " constant #34 method type: #33 ()LMain;\n" + + " constant #35 method_ref: #36.#20 Main. ()V\n" + + " constant #36 class: #37 Main\n" + + " constant #37 utf8: \"Main\"\n" + + " constant #38 method handle: newinvokespecial (8) #35 \n" + + " constant #39 method type: #33 ()LMain;\n" + + " constant #40 utf8: \"InnerClasses\"\n" + + " constant #41 class: #42 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #42 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #43 class: #44 java/lang/invoke/MethodHandles\n" + + " constant #44 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #45 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 LMainProducer;\n" + + " public static MainProducer allocatorExpression;\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 1, Locals: 0\n" + + " static {};\n" + + " 0 invokedynamic 0 produce() : MainProducer [10]\n" + + " 5 putstatic X.allocatorExpression : MainProducer [14]\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [19]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #41 java/lang/invoke/MethodHandles$Lookup, outer class info: #43 java/lang/invoke/MethodHandles\n" + + " inner name: #45 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 32 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #34 ()LMain;\n" + + " #38 Main.:()V\n" + + " #39 ()LMain;\n" + + "}", "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test006() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " String s1, s2;\n" + + " public Main(String val1, String val2) {" + + " s1 = val1;\n" + + " s2 = val2;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Main m = X.producer.apply(\"SUCC\", \"ESS\");\n" + + " System.out.println(m);\n" + + " }\n" + + " public String toString() {\n" + + " return s1 + s2;" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public static Function2 producer = Main::new;\n" + + "}\n", + "Function2.java", + "public interface Function2 {\n" + + " R apply(T1 a1, T2 a2);\n" + + "}\n", + }, + "SUCCESS" + ); + String expected = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"producer\"\n" + + " constant #6 utf8: \"LFunction2;\"\n" + + " constant #7 utf8: \"Signature\"\n" + + " constant #8 utf8: \"LFunction2;\"\n" + + " constant #9 utf8: \"\"\n" + + " constant #10 utf8: \"()V\"\n" + + " constant #11 utf8: \"Code\"\n" + + " constant #12 invoke dynamic: #0 #13 apply ()LFunction2;\n" + + " constant #13 name_and_type: #14.#15 apply ()LFunction2;\n" + + " constant #14 utf8: \"apply\"\n" + + " constant #15 utf8: \"()LFunction2;\"\n" + + " constant #16 field_ref: #1.#17 X.producer LFunction2;\n" + + " constant #17 name_and_type: #5.#6 producer LFunction2;\n" + + " constant #18 utf8: \"LineNumberTable\"\n" + + " constant #19 utf8: \"LocalVariableTable\"\n" + + " constant #20 utf8: \"\"\n" + + " constant #21 method_ref: #3.#22 java/lang/Object. ()V\n" + + " constant #22 name_and_type: #20.#10 ()V\n" + + " constant #23 utf8: \"this\"\n" + + " constant #24 utf8: \"LX;\"\n" + + " constant #25 utf8: \"SourceFile\"\n" + + " constant #26 utf8: \"X.java\"\n" + + " constant #27 utf8: \"BootstrapMethods\"\n" + + " constant #28 method_ref: #29.#31 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #29 class: #30 java/lang/invoke/LambdaMetafactory\n" + + " constant #30 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #31 name_and_type: #32.#33 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #32 utf8: \"metafactory\"\n" + + " constant #33 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #34 method handle: invokestatic (6) #28 \n" + + " constant #35 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\"\n" + + " constant #36 method type: #35 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" + + " constant #37 method_ref: #38.#40 Main. (Ljava/lang/String;Ljava/lang/String;)V\n" + + " constant #38 class: #39 Main\n" + + " constant #39 utf8: \"Main\"\n" + + " constant #40 name_and_type: #20.#41 (Ljava/lang/String;Ljava/lang/String;)V\n" + + " constant #41 utf8: \"(Ljava/lang/String;Ljava/lang/String;)V\"\n" + + " constant #42 method handle: newinvokespecial (8) #37 \n" + + " constant #43 utf8: \"(Ljava/lang/String;Ljava/lang/String;)LMain;\"\n" + + " constant #44 method type: #43 (Ljava/lang/String;Ljava/lang/String;)LMain;\n" + + " constant #45 utf8: \"InnerClasses\"\n" + + " constant #46 class: #47 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #47 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #48 class: #49 java/lang/invoke/MethodHandles\n" + + " constant #49 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #50 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 LFunction2;\n" + + " // Signature: LFunction2;\n" + + " public static Function2 producer;\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 1, Locals: 0\n" + + " static {};\n" + + " 0 invokedynamic 0 apply() : Function2 [12]\n" + + " 5 putstatic X.producer : Function2 [16]\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [21]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #46 java/lang/invoke/MethodHandles$Lookup, outer class info: #48 java/lang/invoke/MethodHandles\n" + + " inner name: #50 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 34 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #36 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" + + " #42 Main.:(Ljava/lang/String;Ljava/lang/String;)V\n" + + " #44 (Ljava/lang/String;Ljava/lang/String;)LMain;\n" + + "}"; + verifyClassFile(expected, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test007() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " new X().referenceExpression.run();\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public Runnable referenceExpression = () -> {" + + " System.out.println(\"SUCCESS\");\n" + + " };\n" + + "}\n", + }, + "SUCCESS" + ); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"referenceExpression\"\n" + + " constant #6 utf8: \"Ljava/lang/Runnable;\"\n" + + " constant #7 utf8: \"\"\n" + + " constant #8 utf8: \"()V\"\n" + + " constant #9 utf8: \"Code\"\n" + + " constant #10 method_ref: #3.#11 java/lang/Object. ()V\n" + + " constant #11 name_and_type: #7.#8 ()V\n" + + " constant #12 invoke dynamic: #0 #13 run ()Ljava/lang/Runnable;\n" + + " constant #13 name_and_type: #14.#15 run ()Ljava/lang/Runnable;\n" + + " constant #14 utf8: \"run\"\n" + + " constant #15 utf8: \"()Ljava/lang/Runnable;\"\n" + + " constant #16 field_ref: #1.#17 X.referenceExpression Ljava/lang/Runnable;\n" + + " constant #17 name_and_type: #5.#6 referenceExpression Ljava/lang/Runnable;\n" + + " constant #18 utf8: \"LineNumberTable\"\n" + + " constant #19 utf8: \"LocalVariableTable\"\n" + + " constant #20 utf8: \"this\"\n" + + " constant #21 utf8: \"LX;\"\n" + + " constant #22 utf8: \"lambda$0\"\n" + + " constant #23 field_ref: #24.#26 java/lang/System.out Ljava/io/PrintStream;\n" + + " constant #24 class: #25 java/lang/System\n" + + " constant #25 utf8: \"java/lang/System\"\n" + + " constant #26 name_and_type: #27.#28 out Ljava/io/PrintStream;\n" + + " constant #27 utf8: \"out\"\n" + + " constant #28 utf8: \"Ljava/io/PrintStream;\"\n" + + " constant #29 string: #30 \"SUCCESS\"\n" + + " constant #30 utf8: \"SUCCESS\"\n" + + " constant #31 method_ref: #32.#34 java/io/PrintStream.println (Ljava/lang/String;)V\n" + + " constant #32 class: #33 java/io/PrintStream\n" + + " constant #33 utf8: \"java/io/PrintStream\"\n" + + " constant #34 name_and_type: #35.#36 println (Ljava/lang/String;)V\n" + + " constant #35 utf8: \"println\"\n" + + " constant #36 utf8: \"(Ljava/lang/String;)V\"\n" + + " constant #37 utf8: \"SourceFile\"\n" + + " constant #38 utf8: \"X.java\"\n" + + " constant #39 utf8: \"BootstrapMethods\"\n" + + " constant #40 method_ref: #41.#43 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #41 class: #42 java/lang/invoke/LambdaMetafactory\n" + + " constant #42 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #43 name_and_type: #44.#45 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #44 utf8: \"metafactory\"\n" + + " constant #45 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #46 method handle: invokestatic (6) #40 \n" + + " constant #47 method type: #8 ()V\n" + + " constant #48 method_ref: #1.#49 X.lambda$0 ()V\n" + + " constant #49 name_and_type: #22.#8 lambda$0 ()V\n" + + " constant #50 method handle: invokestatic (6) #48 \n" + + " constant #51 method type: #8 ()V\n" + + " constant #52 utf8: \"InnerClasses\"\n" + + " constant #53 class: #54 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #54 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #55 class: #56 java/lang/invoke/MethodHandles\n" + + " constant #56 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #57 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/Runnable;\n" + + " public java.lang.Runnable referenceExpression;\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 invokedynamic 0 run() : java.lang.Runnable [12]\n" + + " 10 putfield X.referenceExpression : java.lang.Runnable [16]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 13, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 0\n" + + " private static synthetic void lambda$0();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [23]\n" + + " 3 ldc [29]\n" + + " 5 invokevirtual java.io.PrintStream.println(java.lang.String) : void [31]\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " [pc: 8, line: 3]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #53 java/lang/invoke/MethodHandles$Lookup, outer class info: #55 java/lang/invoke/MethodHandles\n" + + " inner name: #57 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 46 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #47 ()V\n" + + " #50 invokestatic X.lambda$0:()V\n" + + " #51 ()V\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test007a() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " new X().referenceExpression.run();\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public Runnable referenceExpression = () -> System.out.println(\"SUCCESS\");\n" + + "}\n", + }, + "SUCCESS" + ); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"referenceExpression\"\n" + + " constant #6 utf8: \"Ljava/lang/Runnable;\"\n" + + " constant #7 utf8: \"\"\n" + + " constant #8 utf8: \"()V\"\n" + + " constant #9 utf8: \"Code\"\n" + + " constant #10 method_ref: #3.#11 java/lang/Object. ()V\n" + + " constant #11 name_and_type: #7.#8 ()V\n" + + " constant #12 invoke dynamic: #0 #13 run ()Ljava/lang/Runnable;\n" + + " constant #13 name_and_type: #14.#15 run ()Ljava/lang/Runnable;\n" + + " constant #14 utf8: \"run\"\n" + + " constant #15 utf8: \"()Ljava/lang/Runnable;\"\n" + + " constant #16 field_ref: #1.#17 X.referenceExpression Ljava/lang/Runnable;\n" + + " constant #17 name_and_type: #5.#6 referenceExpression Ljava/lang/Runnable;\n" + + " constant #18 utf8: \"LineNumberTable\"\n" + + " constant #19 utf8: \"LocalVariableTable\"\n" + + " constant #20 utf8: \"this\"\n" + + " constant #21 utf8: \"LX;\"\n" + + " constant #22 utf8: \"lambda$0\"\n" + + " constant #23 field_ref: #24.#26 java/lang/System.out Ljava/io/PrintStream;\n" + + " constant #24 class: #25 java/lang/System\n" + + " constant #25 utf8: \"java/lang/System\"\n" + + " constant #26 name_and_type: #27.#28 out Ljava/io/PrintStream;\n" + + " constant #27 utf8: \"out\"\n" + + " constant #28 utf8: \"Ljava/io/PrintStream;\"\n" + + " constant #29 string: #30 \"SUCCESS\"\n" + + " constant #30 utf8: \"SUCCESS\"\n" + + " constant #31 method_ref: #32.#34 java/io/PrintStream.println (Ljava/lang/String;)V\n" + + " constant #32 class: #33 java/io/PrintStream\n" + + " constant #33 utf8: \"java/io/PrintStream\"\n" + + " constant #34 name_and_type: #35.#36 println (Ljava/lang/String;)V\n" + + " constant #35 utf8: \"println\"\n" + + " constant #36 utf8: \"(Ljava/lang/String;)V\"\n" + + " constant #37 utf8: \"SourceFile\"\n" + + " constant #38 utf8: \"X.java\"\n" + + " constant #39 utf8: \"BootstrapMethods\"\n" + + " constant #40 method_ref: #41.#43 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #41 class: #42 java/lang/invoke/LambdaMetafactory\n" + + " constant #42 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #43 name_and_type: #44.#45 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #44 utf8: \"metafactory\"\n" + + " constant #45 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #46 method handle: invokestatic (6) #40 \n" + + " constant #47 method type: #8 ()V\n" + + " constant #48 method_ref: #1.#49 X.lambda$0 ()V\n" + + " constant #49 name_and_type: #22.#8 lambda$0 ()V\n" + + " constant #50 method handle: invokestatic (6) #48 \n" + + " constant #51 method type: #8 ()V\n" + + " constant #52 utf8: \"InnerClasses\"\n" + + " constant #53 class: #54 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #54 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #55 class: #56 java/lang/invoke/MethodHandles\n" + + " constant #56 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #57 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 Ljava/lang/Runnable;\n" + + " public java.lang.Runnable referenceExpression;\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 invokedynamic 0 run() : java.lang.Runnable [12]\n" + + " 10 putfield X.referenceExpression : java.lang.Runnable [16]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 13, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 0\n" + + " private static synthetic void lambda$0();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [23]\n" + + " 3 ldc [29]\n" + + " 5 invokevirtual java.io.PrintStream.println(java.lang.String) : void [31]\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #53 java/lang/invoke/MethodHandles$Lookup, outer class info: #55 java/lang/invoke/MethodHandles\n" + + " inner name: #57 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 46 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #47 ()V\n" + + " #50 invokestatic X.lambda$0:()V\n" + + " #51 ()V\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test008() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().lambda.get());\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public java.util.function.Supplier lambda = () -> { return \"SUCCESS\"; }; \n" + + "}\n", + }, + "SUCCESS" + ); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"lambda\"\n" + + " constant #6 utf8: \"Ljava/util/function/Supplier;\"\n" + + " constant #7 utf8: \"Signature\"\n" + + " constant #8 utf8: \"Ljava/util/function/Supplier;\"\n" + + " constant #9 utf8: \"\"\n" + + " constant #10 utf8: \"()V\"\n" + + " constant #11 utf8: \"Code\"\n" + + " constant #12 method_ref: #3.#13 java/lang/Object. ()V\n" + + " constant #13 name_and_type: #9.#10 ()V\n" + + " constant #14 invoke dynamic: #0 #15 get ()Ljava/util/function/Supplier;\n" + + " constant #15 name_and_type: #16.#17 get ()Ljava/util/function/Supplier;\n" + + " constant #16 utf8: \"get\"\n" + + " constant #17 utf8: \"()Ljava/util/function/Supplier;\"\n" + + " constant #18 field_ref: #1.#19 X.lambda Ljava/util/function/Supplier;\n" + + " constant #19 name_and_type: #5.#6 lambda Ljava/util/function/Supplier;\n" + + " constant #20 utf8: \"LineNumberTable\"\n" + + " constant #21 utf8: \"LocalVariableTable\"\n" + + " constant #22 utf8: \"this\"\n" + + " constant #23 utf8: \"LX;\"\n" + + " constant #24 utf8: \"lambda$0\"\n" + + " constant #25 utf8: \"()Ljava/lang/String;\"\n" + + " constant #26 string: #27 \"SUCCESS\"\n" + + " constant #27 utf8: \"SUCCESS\"\n" + + " constant #28 utf8: \"SourceFile\"\n" + + " constant #29 utf8: \"X.java\"\n" + + " constant #30 utf8: \"BootstrapMethods\"\n" + + " constant #31 method_ref: #32.#34 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #32 class: #33 java/lang/invoke/LambdaMetafactory\n" + + " constant #33 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #34 name_and_type: #35.#36 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #35 utf8: \"metafactory\"\n" + + " constant #36 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #37 method handle: invokestatic (6) #31 \n" + + " constant #38 utf8: \"()Ljava/lang/Object;\"\n" + + " constant #39 method type: #38 ()Ljava/lang/Object;\n" + + " constant #40 method_ref: #1.#41 X.lambda$0 ()Ljava/lang/String;\n" + + " constant #41 name_and_type: #24.#25 lambda$0 ()Ljava/lang/String;\n" + + " constant #42 method handle: invokestatic (6) #40 \n" + + " constant #43 method type: #25 ()Ljava/lang/String;\n" + + " constant #44 utf8: \"InnerClasses\"\n" + + " constant #45 class: #46 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #46 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #47 class: #48 java/lang/invoke/MethodHandles\n" + + " constant #48 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #49 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 Ljava/util/function/Supplier;\n" + + " // Signature: Ljava/util/function/Supplier;\n" + + " public java.util.function.Supplier lambda;\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 aload_0 [this]\n" + + " 5 invokedynamic 0 get() : java.util.function.Supplier [14]\n" + + " 10 putfield X.lambda : java.util.function.Supplier [18]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 13, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #25 ()Ljava/lang/String;\n" + + " // Stack: 1, Locals: 0\n" + + " private static synthetic java.lang.String lambda$0();\n" + + " 0 ldc [26]\n" + + " 2 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #45 java/lang/invoke/MethodHandles$Lookup, outer class info: #47 java/lang/invoke/MethodHandles\n" + + " inner name: #49 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 37 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #39 ()Ljava/lang/Object;\n" + + " #42 invokestatic X.lambda$0:()Ljava/lang/String;\n" + + " #43 ()Ljava/lang/String;\n" + + "}" +; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test009() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().concat.apply(\"SUCC\",\"ESS\"));\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public Function2 concat = (s1, s2) -> { return s1 + s2; }; \n" + + "}\n", + "Function2.java", + "public interface Function2 {\n" + + " R apply(T1 a1, T2 a2);\n" + + "}\n", + + }, + "SUCCESS" + ); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"concat\"\n" + + " constant #6 utf8: \"LFunction2;\"\n" + + " constant #7 utf8: \"Signature\"\n" + + " constant #8 utf8: \"LFunction2;\"\n" + + " constant #9 utf8: \"\"\n" + + " constant #10 utf8: \"()V\"\n" + + " constant #11 utf8: \"Code\"\n" + + " constant #12 method_ref: #3.#13 java/lang/Object. ()V\n" + + " constant #13 name_and_type: #9.#10 ()V\n" + + " constant #14 invoke dynamic: #0 #15 apply ()LFunction2;\n" + + " constant #15 name_and_type: #16.#17 apply ()LFunction2;\n" + + " constant #16 utf8: \"apply\"\n" + + " constant #17 utf8: \"()LFunction2;\"\n" + + " constant #18 field_ref: #1.#19 X.concat LFunction2;\n" + + " constant #19 name_and_type: #5.#6 concat LFunction2;\n" + + " constant #20 utf8: \"LineNumberTable\"\n" + + " constant #21 utf8: \"LocalVariableTable\"\n" + + " constant #22 utf8: \"this\"\n" + + " constant #23 utf8: \"LX;\"\n" + + " constant #24 utf8: \"lambda$0\"\n" + + " constant #25 utf8: \"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\"\n" + + " constant #26 class: #27 java/lang/StringBuilder\n" + + " constant #27 utf8: \"java/lang/StringBuilder\"\n" + + " constant #28 method_ref: #29.#31 java/lang/String.valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" + + " constant #29 class: #30 java/lang/String\n" + + " constant #30 utf8: \"java/lang/String\"\n" + + " constant #31 name_and_type: #32.#33 valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" + + " constant #32 utf8: \"valueOf\"\n" + + " constant #33 utf8: \"(Ljava/lang/Object;)Ljava/lang/String;\"\n" + + " constant #34 method_ref: #26.#35 java/lang/StringBuilder. (Ljava/lang/String;)V\n" + + " constant #35 name_and_type: #9.#36 (Ljava/lang/String;)V\n" + + " constant #36 utf8: \"(Ljava/lang/String;)V\"\n" + + " constant #37 method_ref: #26.#38 java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" + + " constant #38 name_and_type: #39.#40 append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" + + " constant #39 utf8: \"append\"\n" + + " constant #40 utf8: \"(Ljava/lang/String;)Ljava/lang/StringBuilder;\"\n" + + " constant #41 method_ref: #26.#42 java/lang/StringBuilder.toString ()Ljava/lang/String;\n" + + " constant #42 name_and_type: #43.#44 toString ()Ljava/lang/String;\n" + + " constant #43 utf8: \"toString\"\n" + + " constant #44 utf8: \"()Ljava/lang/String;\"\n" + + " constant #45 utf8: \"s1\"\n" + + " constant #46 utf8: \"Ljava/lang/String;\"\n" + + " constant #47 utf8: \"s2\"\n" + + " constant #48 utf8: \"SourceFile\"\n" + + " constant #49 utf8: \"X.java\"\n" + + " constant #50 utf8: \"BootstrapMethods\"\n" + + " constant #51 method_ref: #52.#54 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #52 class: #53 java/lang/invoke/LambdaMetafactory\n" + + " constant #53 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #54 name_and_type: #55.#56 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #55 utf8: \"metafactory\"\n" + + " constant #56 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #57 method handle: invokestatic (6) #51 \n" + + " constant #58 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\"\n" + + " constant #59 method type: #58 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" + + " constant #60 method_ref: #1.#61 X.lambda$0 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " constant #61 name_and_type: #24.#25 lambda$0 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " constant #62 method handle: invokestatic (6) #60 \n" + + " constant #63 method type: #25 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " constant #64 utf8: \"InnerClasses\"\n" + + " constant #65 class: #66 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #66 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #67 class: #68 java/lang/invoke/MethodHandles\n" + + " constant #68 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #69 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 LFunction2;\n" + + " // Signature: LFunction2;\n" + + " public Function2 concat;\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 aload_0 [this]\n" + + " 5 invokedynamic 0 apply() : Function2 [14]\n" + + " 10 putfield X.concat : Function2 [18]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 13, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #25 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " // Stack: 3, Locals: 2\n" + + " private static synthetic java.lang.String lambda$0(java.lang.String s1, java.lang.String s2);\n" + + " 0 new java.lang.StringBuilder [26]\n" + + " 3 dup\n" + + " 4 aload_0 [s1]\n" + + " 5 invokestatic java.lang.String.valueOf(java.lang.Object) : java.lang.String [28]\n" + + " 8 invokespecial java.lang.StringBuilder(java.lang.String) [34]\n" + + " 11 aload_1 [s2]\n" + + " 12 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [37]\n" + + " 15 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [41]\n" + + " 18 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: s1 index: 0 type: java.lang.String\n" + + " [pc: 0, pc: 19] local: s2 index: 1 type: java.lang.String\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #65 java/lang/invoke/MethodHandles$Lookup, outer class info: #67 java/lang/invoke/MethodHandles\n" + + " inner name: #69 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 57 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #59 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" + + " #62 invokestatic X.lambda$0:(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " #63 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test010() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().concat.apply(\"UCC\",\"ESS\"));\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public Function2 concat; \n" + + " {\n" + + " String s0 = new String(\"S\");\n" + + " concat = (s1, s2) -> { return s0 + s1 + s2; }; \n" + + " }\n" + + "}\n", + "Function2.java", + "public interface Function2 {\n" + + " R apply(T1 a1, T2 a2);\n" + + "}\n", + + }, + "SUCCESS" + ); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"concat\"\n" + + " constant #6 utf8: \"LFunction2;\"\n" + + " constant #7 utf8: \"Signature\"\n" + + " constant #8 utf8: \"LFunction2;\"\n" + + " constant #9 utf8: \"\"\n" + + " constant #10 utf8: \"()V\"\n" + + " constant #11 utf8: \"Code\"\n" + + " constant #12 method_ref: #3.#13 java/lang/Object. ()V\n" + + " constant #13 name_and_type: #9.#10 ()V\n" + + " constant #14 class: #15 java/lang/String\n" + + " constant #15 utf8: \"java/lang/String\"\n" + + " constant #16 string: #17 \"S\"\n" + + " constant #17 utf8: \"S\"\n" + + " constant #18 method_ref: #14.#19 java/lang/String. (Ljava/lang/String;)V\n" + + " constant #19 name_and_type: #9.#20 (Ljava/lang/String;)V\n" + + " constant #20 utf8: \"(Ljava/lang/String;)V\"\n" + + " constant #21 invoke dynamic: #0 #22 apply (Ljava/lang/String;)LFunction2;\n" + + " constant #22 name_and_type: #23.#24 apply (Ljava/lang/String;)LFunction2;\n" + + " constant #23 utf8: \"apply\"\n" + + " constant #24 utf8: \"(Ljava/lang/String;)LFunction2;\"\n" + + " constant #25 field_ref: #1.#26 X.concat LFunction2;\n" + + " constant #26 name_and_type: #5.#6 concat LFunction2;\n" + + " constant #27 utf8: \"LineNumberTable\"\n" + + " constant #28 utf8: \"LocalVariableTable\"\n" + + " constant #29 utf8: \"this\"\n" + + " constant #30 utf8: \"LX;\"\n" + + " constant #31 utf8: \"s0\"\n" + + " constant #32 utf8: \"Ljava/lang/String;\"\n" + + " constant #33 utf8: \"lambda$0\"\n" + + " constant #34 utf8: \"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\"\n" + + " constant #35 class: #36 java/lang/StringBuilder\n" + + " constant #36 utf8: \"java/lang/StringBuilder\"\n" + + " constant #37 method_ref: #14.#38 java/lang/String.valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" + + " constant #38 name_and_type: #39.#40 valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" + + " constant #39 utf8: \"valueOf\"\n" + + " constant #40 utf8: \"(Ljava/lang/Object;)Ljava/lang/String;\"\n" + + " constant #41 method_ref: #35.#19 java/lang/StringBuilder. (Ljava/lang/String;)V\n" + + " constant #42 method_ref: #35.#43 java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" + + " constant #43 name_and_type: #44.#45 append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" + + " constant #44 utf8: \"append\"\n" + + " constant #45 utf8: \"(Ljava/lang/String;)Ljava/lang/StringBuilder;\"\n" + + " constant #46 method_ref: #35.#47 java/lang/StringBuilder.toString ()Ljava/lang/String;\n" + + " constant #47 name_and_type: #48.#49 toString ()Ljava/lang/String;\n" + + " constant #48 utf8: \"toString\"\n" + + " constant #49 utf8: \"()Ljava/lang/String;\"\n" + + " constant #50 utf8: \"s1\"\n" + + " constant #51 utf8: \"s2\"\n" + + " constant #52 utf8: \"SourceFile\"\n" + + " constant #53 utf8: \"X.java\"\n" + + " constant #54 utf8: \"BootstrapMethods\"\n" + + " constant #55 method_ref: #56.#58 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #56 class: #57 java/lang/invoke/LambdaMetafactory\n" + + " constant #57 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #58 name_and_type: #59.#60 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #59 utf8: \"metafactory\"\n" + + " constant #60 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #61 method handle: invokestatic (6) #55 \n" + + " constant #62 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\"\n" + + " constant #63 method type: #62 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" + + " constant #64 method_ref: #1.#65 X.lambda$0 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " constant #65 name_and_type: #33.#34 lambda$0 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " constant #66 method handle: invokestatic (6) #64 \n" + + " constant #67 utf8: \"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\"\n" + + " constant #68 method type: #67 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " constant #69 utf8: \"InnerClasses\"\n" + + " constant #70 class: #71 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #71 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #72 class: #73 java/lang/invoke/MethodHandles\n" + + " constant #73 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #74 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 LFunction2;\n" + + " // Signature: LFunction2;\n" + + " public Function2 concat;\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 3, Locals: 2\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 new java.lang.String [14]\n" + + " 7 dup\n" + + " 8 ldc [16]\n" + + " 10 invokespecial java.lang.String(java.lang.String) [18]\n" + + " 13 astore_1 [s0]\n" + + " 14 aload_0 [this]\n" + + " 15 aload_1 [s0]\n" + + " 16 invokedynamic 0 apply(java.lang.String) : Function2 [21]\n" + + " 21 putfield X.concat : Function2 [25]\n" + + " 24 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 14, line: 5]\n" + + " [pc: 24, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 25] local: this index: 0 type: X\n" + + " [pc: 14, pc: 24] local: s0 index: 1 type: java.lang.String\n" + + " \n" + + " // Method descriptor #34 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " // Stack: 3, Locals: 3\n" + + " private static synthetic java.lang.String lambda$0(java.lang.String arg0, java.lang.String s1, java.lang.String s2);\n" + + " 0 new java.lang.StringBuilder [35]\n" + + " 3 dup\n" + + " 4 aload_0 [arg0]\n" + + " 5 invokestatic java.lang.String.valueOf(java.lang.Object) : java.lang.String [37]\n" + + " 8 invokespecial java.lang.StringBuilder(java.lang.String) [41]\n" + + " 11 aload_1 [s1]\n" + + " 12 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [42]\n" + + " 15 aload_2 [s2]\n" + + " 16 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [42]\n" + + " 19 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [46]\n" + + " 22 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 23] local: s1 index: 1 type: java.lang.String\n" + + " [pc: 0, pc: 23] local: s2 index: 2 type: java.lang.String\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #70 java/lang/invoke/MethodHandles$Lookup, outer class info: #72 java/lang/invoke/MethodHandles\n" + + " inner name: #74 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 61 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #63 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" + + " #66 invokestatic X.lambda$0:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " #68 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + "}" +; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test011() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().concat.apply(\"UCC\",\"ESS\"));\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public Function2 concat; \n" + + " {\n" + + " String s0 = new String(\"S\");\n" + + " concat = (s1, s2) -> s0 + s1 + s2; \n" + + " }\n" + + "}\n", + "Function2.java", + "public interface Function2 {\n" + + " R apply(T1 a1, T2 a2);\n" + + "}\n", + + }, + "SUCCESS" + ); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"concat\"\n" + + " constant #6 utf8: \"LFunction2;\"\n" + + " constant #7 utf8: \"Signature\"\n" + + " constant #8 utf8: \"LFunction2;\"\n" + + " constant #9 utf8: \"\"\n" + + " constant #10 utf8: \"()V\"\n" + + " constant #11 utf8: \"Code\"\n" + + " constant #12 method_ref: #3.#13 java/lang/Object. ()V\n" + + " constant #13 name_and_type: #9.#10 ()V\n" + + " constant #14 class: #15 java/lang/String\n" + + " constant #15 utf8: \"java/lang/String\"\n" + + " constant #16 string: #17 \"S\"\n" + + " constant #17 utf8: \"S\"\n" + + " constant #18 method_ref: #14.#19 java/lang/String. (Ljava/lang/String;)V\n" + + " constant #19 name_and_type: #9.#20 (Ljava/lang/String;)V\n" + + " constant #20 utf8: \"(Ljava/lang/String;)V\"\n" + + " constant #21 invoke dynamic: #0 #22 apply (Ljava/lang/String;)LFunction2;\n" + + " constant #22 name_and_type: #23.#24 apply (Ljava/lang/String;)LFunction2;\n" + + " constant #23 utf8: \"apply\"\n" + + " constant #24 utf8: \"(Ljava/lang/String;)LFunction2;\"\n" + + " constant #25 field_ref: #1.#26 X.concat LFunction2;\n" + + " constant #26 name_and_type: #5.#6 concat LFunction2;\n" + + " constant #27 utf8: \"LineNumberTable\"\n" + + " constant #28 utf8: \"LocalVariableTable\"\n" + + " constant #29 utf8: \"this\"\n" + + " constant #30 utf8: \"LX;\"\n" + + " constant #31 utf8: \"s0\"\n" + + " constant #32 utf8: \"Ljava/lang/String;\"\n" + + " constant #33 utf8: \"lambda$0\"\n" + + " constant #34 utf8: \"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\"\n" + + " constant #35 class: #36 java/lang/StringBuilder\n" + + " constant #36 utf8: \"java/lang/StringBuilder\"\n" + + " constant #37 method_ref: #14.#38 java/lang/String.valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" + + " constant #38 name_and_type: #39.#40 valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" + + " constant #39 utf8: \"valueOf\"\n" + + " constant #40 utf8: \"(Ljava/lang/Object;)Ljava/lang/String;\"\n" + + " constant #41 method_ref: #35.#19 java/lang/StringBuilder. (Ljava/lang/String;)V\n" + + " constant #42 method_ref: #35.#43 java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" + + " constant #43 name_and_type: #44.#45 append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" + + " constant #44 utf8: \"append\"\n" + + " constant #45 utf8: \"(Ljava/lang/String;)Ljava/lang/StringBuilder;\"\n" + + " constant #46 method_ref: #35.#47 java/lang/StringBuilder.toString ()Ljava/lang/String;\n" + + " constant #47 name_and_type: #48.#49 toString ()Ljava/lang/String;\n" + + " constant #48 utf8: \"toString\"\n" + + " constant #49 utf8: \"()Ljava/lang/String;\"\n" + + " constant #50 utf8: \"s1\"\n" + + " constant #51 utf8: \"s2\"\n" + + " constant #52 utf8: \"SourceFile\"\n" + + " constant #53 utf8: \"X.java\"\n" + + " constant #54 utf8: \"BootstrapMethods\"\n" + + " constant #55 method_ref: #56.#58 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #56 class: #57 java/lang/invoke/LambdaMetafactory\n" + + " constant #57 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #58 name_and_type: #59.#60 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #59 utf8: \"metafactory\"\n" + + " constant #60 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #61 method handle: invokestatic (6) #55 \n" + + " constant #62 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\"\n" + + " constant #63 method type: #62 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" + + " constant #64 method_ref: #1.#65 X.lambda$0 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " constant #65 name_and_type: #33.#34 lambda$0 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " constant #66 method handle: invokestatic (6) #64 \n" + + " constant #67 utf8: \"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\"\n" + + " constant #68 method type: #67 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " constant #69 utf8: \"InnerClasses\"\n" + + " constant #70 class: #71 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #71 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #72 class: #73 java/lang/invoke/MethodHandles\n" + + " constant #73 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #74 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 LFunction2;\n" + + " // Signature: LFunction2;\n" + + " public Function2 concat;\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 3, Locals: 2\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 new java.lang.String [14]\n" + + " 7 dup\n" + + " 8 ldc [16]\n" + + " 10 invokespecial java.lang.String(java.lang.String) [18]\n" + + " 13 astore_1 [s0]\n" + + " 14 aload_0 [this]\n" + + " 15 aload_1 [s0]\n" + + " 16 invokedynamic 0 apply(java.lang.String) : Function2 [21]\n" + + " 21 putfield X.concat : Function2 [25]\n" + + " 24 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 14, line: 5]\n" + + " [pc: 24, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 25] local: this index: 0 type: X\n" + + " [pc: 14, pc: 24] local: s0 index: 1 type: java.lang.String\n" + + " \n" + + " // Method descriptor #34 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " // Stack: 3, Locals: 3\n" + + " private static synthetic java.lang.String lambda$0(java.lang.String arg0, java.lang.String s1, java.lang.String s2);\n" + + " 0 new java.lang.StringBuilder [35]\n" + + " 3 dup\n" + + " 4 aload_0 [arg0]\n" + + " 5 invokestatic java.lang.String.valueOf(java.lang.Object) : java.lang.String [37]\n" + + " 8 invokespecial java.lang.StringBuilder(java.lang.String) [41]\n" + + " 11 aload_1 [s1]\n" + + " 12 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [42]\n" + + " 15 aload_2 [s2]\n" + + " 16 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [42]\n" + + " 19 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [46]\n" + + " 22 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 23] local: s1 index: 1 type: java.lang.String\n" + + " [pc: 0, pc: 23] local: s2 index: 2 type: java.lang.String\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #70 java/lang/invoke/MethodHandles$Lookup, outer class info: #72 java/lang/invoke/MethodHandles\n" + + " inner name: #74 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 61 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #63 (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" + + " #66 invokestatic X.lambda$0:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + " #68 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406627, [1.8][compiler][codegen] Annotations on lambda parameters go the way of /dev/null +public void test012() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "interface I {\n" + + " void doit (Object o, Object p);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " int local1 = 0, local2 = 1;\n" + + " I i = (@Annotation Object o, @Annotation Object p) -> {\n" + + " int j = args.length + local1 + local2;\n" + + " };\n" + + "}\n" + + "}\n" + + "@Target(ElementType.PARAMETER)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Annotation {\n" + + "}\n", + }, + ""); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #5.#6 ()V\n" + + " constant #10 utf8: \"LineNumberTable\"\n" + + " constant #11 utf8: \"LocalVariableTable\"\n" + + " constant #12 utf8: \"this\"\n" + + " constant #13 utf8: \"LX;\"\n" + + " constant #14 utf8: \"main\"\n" + + " constant #15 utf8: \"([Ljava/lang/String;)V\"\n" + + " constant #16 invoke dynamic: #0 #17 doit ([Ljava/lang/String;II)LI;\n" + + " constant #17 name_and_type: #18.#19 doit ([Ljava/lang/String;II)LI;\n" + + " constant #18 utf8: \"doit\"\n" + + " constant #19 utf8: \"([Ljava/lang/String;II)LI;\"\n" + + " constant #20 utf8: \"args\"\n" + + " constant #21 utf8: \"[Ljava/lang/String;\"\n" + + " constant #22 utf8: \"local1\"\n" + + " constant #23 utf8: \"I\"\n" + + " constant #24 utf8: \"local2\"\n" + + " constant #25 utf8: \"i\"\n" + + " constant #26 utf8: \"LI;\"\n" + + " constant #27 utf8: \"lambda$0\"\n" + + " constant #28 utf8: \"([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\"\n" + + " constant #29 utf8: \"RuntimeVisibleParameterAnnotations\"\n" + + " constant #30 utf8: \"LAnnotation;\"\n" + + " constant #31 utf8: \"o\"\n" + + " constant #32 utf8: \"Ljava/lang/Object;\"\n" + + " constant #33 utf8: \"p\"\n" + + " constant #34 utf8: \"SourceFile\"\n" + + " constant #35 utf8: \"X.java\"\n" + + " constant #36 utf8: \"BootstrapMethods\"\n" + + " constant #37 method_ref: #38.#40 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #38 class: #39 java/lang/invoke/LambdaMetafactory\n" + + " constant #39 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #40 name_and_type: #41.#42 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #41 utf8: \"metafactory\"\n" + + " constant #42 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #43 method handle: invokestatic (6) #37 \n" + + " constant #44 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)V\"\n" + + " constant #45 method type: #44 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #46 method_ref: #1.#47 X.lambda$0 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #47 name_and_type: #27.#28 lambda$0 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #48 method handle: invokestatic (6) #46 \n" + + " constant #49 method type: #44 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #50 utf8: \"InnerClasses\"\n" + + " constant #51 class: #52 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #52 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #53 class: #54 java/lang/invoke/MethodHandles\n" + + " constant #54 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #55 utf8: \"Lookup\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [local1]\n" + + " 2 iconst_1\n" + + " 3 istore_2 [local2]\n" + + " 4 aload_0 [args]\n" + + " 5 iload_1 [local1]\n" + + " 6 iload_2 [local2]\n" + + " 7 invokedynamic 0 doit(java.lang.String[], int, int) : I [16]\n" + + " 12 astore_3 [i]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 4, line: 11]\n" + + " [pc: 13, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 14] local: local1 index: 1 type: int\n" + + " [pc: 4, pc: 14] local: local2 index: 2 type: int\n" + + " [pc: 13, pc: 14] local: i index: 3 type: I\n" + + " \n" + + " // Method descriptor #28 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" + + " // Stack: 2, Locals: 6\n" + + " private static synthetic void lambda$0(java.lang.String[] arg0, int arg1, int arg2, java.lang.Object o, java.lang.Object p);\n" + + " 0 aload_0 [arg0]\n" + + " 1 arraylength\n" + + " 2 iload_1 [arg1]\n" + + " 3 iadd\n" + + " 4 iload_2 [arg2]\n" + + " 5 iadd\n" + + " 6 istore 5\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 12]\n" + + " [pc: 8, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 9] local: o index: 3 type: java.lang.Object\n" + + " [pc: 0, pc: 9] local: p index: 4 type: java.lang.Object\n" + + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 0\n" + + " Number of annotations for parameter 1: 0\n" + + " Number of annotations for parameter 2: 0\n" + + " Number of annotations for parameter 3: 1\n" + + " #30 @Annotation(\n" + + " )\n" + + " Number of annotations for parameter 4: 1\n" + + " #30 @Annotation(\n" + + " )\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #51 java/lang/invoke/MethodHandles$Lookup, outer class info: #53 java/lang/invoke/MethodHandles\n" + + " inner name: #55 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 43 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #45 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " #48 invokestatic X.lambda$0:([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" + + " #49 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + "}" +; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406627, [1.8][compiler][codegen] Annotations on lambda parameters go the way of /dev/null +public void test013() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "interface I {\n" + + " void doit (Object o, Object p);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = (@Annotation Object o, @Annotation Object p) -> {\n" + + " };\n" + + "}\n" + + "}\n" + + "@Target(ElementType.PARAMETER)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Annotation {\n" + + "}\n", + }, + ""); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #5.#6 ()V\n" + + " constant #10 utf8: \"LineNumberTable\"\n" + + " constant #11 utf8: \"LocalVariableTable\"\n" + + " constant #12 utf8: \"this\"\n" + + " constant #13 utf8: \"LX;\"\n" + + " constant #14 utf8: \"main\"\n" + + " constant #15 utf8: \"([Ljava/lang/String;)V\"\n" + + " constant #16 invoke dynamic: #0 #17 doit ()LI;\n" + + " constant #17 name_and_type: #18.#19 doit ()LI;\n" + + " constant #18 utf8: \"doit\"\n" + + " constant #19 utf8: \"()LI;\"\n" + + " constant #20 utf8: \"args\"\n" + + " constant #21 utf8: \"[Ljava/lang/String;\"\n" + + " constant #22 utf8: \"i\"\n" + + " constant #23 utf8: \"LI;\"\n" + + " constant #24 utf8: \"lambda$0\"\n" + + " constant #25 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)V\"\n" + + " constant #26 utf8: \"RuntimeVisibleParameterAnnotations\"\n" + + " constant #27 utf8: \"LAnnotation;\"\n" + + " constant #28 utf8: \"o\"\n" + + " constant #29 utf8: \"Ljava/lang/Object;\"\n" + + " constant #30 utf8: \"p\"\n" + + " constant #31 utf8: \"SourceFile\"\n" + + " constant #32 utf8: \"X.java\"\n" + + " constant #33 utf8: \"BootstrapMethods\"\n" + + " constant #34 method_ref: #35.#37 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #35 class: #36 java/lang/invoke/LambdaMetafactory\n" + + " constant #36 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #37 name_and_type: #38.#39 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #38 utf8: \"metafactory\"\n" + + " constant #39 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #40 method handle: invokestatic (6) #34 \n" + + " constant #41 method type: #25 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #42 method_ref: #1.#43 X.lambda$0 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #43 name_and_type: #24.#25 lambda$0 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #44 method handle: invokestatic (6) #42 \n" + + " constant #45 method type: #25 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #46 utf8: \"InnerClasses\"\n" + + " constant #47 class: #48 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #48 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #49 class: #50 java/lang/invoke/MethodHandles\n" + + " constant #50 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #51 utf8: \"Lookup\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 invokedynamic 0 doit() : I [16]\n" + + " 5 astore_1 [i]\n" + + " 6 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 6, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 7] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 6, pc: 7] local: i index: 1 type: I\n" + + " \n" + + " // Method descriptor #25 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " // Stack: 0, Locals: 2\n" + + " private static synthetic void lambda$0(java.lang.Object o, java.lang.Object p);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: o index: 0 type: java.lang.Object\n" + + " [pc: 0, pc: 1] local: p index: 1 type: java.lang.Object\n" + + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #27 @Annotation(\n" + + " )\n" + + " Number of annotations for parameter 1: 1\n" + + " #27 @Annotation(\n" + + " )\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #47 java/lang/invoke/MethodHandles$Lookup, outer class info: #49 java/lang/invoke/MethodHandles\n" + + " inner name: #51 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 40 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #41 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " #44 invokestatic X.lambda$0:(Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " #45 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void test014() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "interface I {\n" + + " void doit (Object o, Object p);\n" + + "}\n" + + "public class X {\n" + + " I i = (@Annotation Object o, @Annotation Object p) -> {\n" + + " };\n" + + " public static void main(String [] args) {\n" + + " int local1 = 0, local2 = 1;\n" + + " I i = (@Annotation Object o, @Annotation Object p) -> {\n" + + " int j = args.length + local1 + local2;\n" + + " };\n" + + "}\n" + + "}\n" + + "@Target(ElementType.PARAMETER)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Annotation {\n" + + "}\n", + }, + ""); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"i\"\n" + + " constant #6 utf8: \"LI;\"\n" + + " constant #7 utf8: \"\"\n" + + " constant #8 utf8: \"()V\"\n" + + " constant #9 utf8: \"Code\"\n" + + " constant #10 method_ref: #3.#11 java/lang/Object. ()V\n" + + " constant #11 name_and_type: #7.#8 ()V\n" + + " constant #12 invoke dynamic: #0 #13 doit ()LI;\n" + + " constant #13 name_and_type: #14.#15 doit ()LI;\n" + + " constant #14 utf8: \"doit\"\n" + + " constant #15 utf8: \"()LI;\"\n" + + " constant #16 field_ref: #1.#17 X.i LI;\n" + + " constant #17 name_and_type: #5.#6 i LI;\n" + + " constant #18 utf8: \"LineNumberTable\"\n" + + " constant #19 utf8: \"LocalVariableTable\"\n" + + " constant #20 utf8: \"this\"\n" + + " constant #21 utf8: \"LX;\"\n" + + " constant #22 utf8: \"main\"\n" + + " constant #23 utf8: \"([Ljava/lang/String;)V\"\n" + + " constant #24 invoke dynamic: #1 #25 doit ([Ljava/lang/String;II)LI;\n" + + " constant #25 name_and_type: #14.#26 doit ([Ljava/lang/String;II)LI;\n" + + " constant #26 utf8: \"([Ljava/lang/String;II)LI;\"\n" + + " constant #27 utf8: \"args\"\n" + + " constant #28 utf8: \"[Ljava/lang/String;\"\n" + + " constant #29 utf8: \"local1\"\n" + + " constant #30 utf8: \"I\"\n" + + " constant #31 utf8: \"local2\"\n" + + " constant #32 utf8: \"lambda$0\"\n" + + " constant #33 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)V\"\n" + + " constant #34 utf8: \"RuntimeVisibleParameterAnnotations\"\n" + + " constant #35 utf8: \"LAnnotation;\"\n" + + " constant #36 utf8: \"o\"\n" + + " constant #37 utf8: \"Ljava/lang/Object;\"\n" + + " constant #38 utf8: \"p\"\n" + + " constant #39 utf8: \"lambda$1\"\n" + + " constant #40 utf8: \"([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\"\n" + + " constant #41 utf8: \"SourceFile\"\n" + + " constant #42 utf8: \"X.java\"\n" + + " constant #43 utf8: \"BootstrapMethods\"\n" + + " constant #44 method_ref: #45.#47 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #45 class: #46 java/lang/invoke/LambdaMetafactory\n" + + " constant #46 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #47 name_and_type: #48.#49 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #48 utf8: \"metafactory\"\n" + + " constant #49 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #50 method handle: invokestatic (6) #44 \n" + + " constant #51 method type: #33 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #52 method_ref: #1.#53 X.lambda$0 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #53 name_and_type: #32.#33 lambda$0 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #54 method handle: invokestatic (6) #52 \n" + + " constant #55 method type: #33 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #56 method type: #33 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #57 method_ref: #1.#58 X.lambda$1 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #58 name_and_type: #39.#40 lambda$1 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #59 method handle: invokestatic (6) #57 \n" + + " constant #60 method type: #33 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " constant #61 utf8: \"InnerClasses\"\n" + + " constant #62 class: #63 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #63 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #64 class: #65 java/lang/invoke/MethodHandles\n" + + " constant #65 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #66 utf8: \"Lookup\"\n" + + " \n" + + " // Field descriptor #6 LI;\n" + + " I i;\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 invokedynamic 0 doit() : I [12]\n" + + " 10 putfield X.i : I [16]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 4, line: 9]\n" + + " [pc: 13, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #23 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [local1]\n" + + " 2 iconst_1\n" + + " 3 istore_2 [local2]\n" + + " 4 aload_0 [args]\n" + + " 5 iload_1 [local1]\n" + + " 6 iload_2 [local2]\n" + + " 7 invokedynamic 1 doit(java.lang.String[], int, int) : I [24]\n" + + " 12 astore_3 [i]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 12]\n" + + " [pc: 4, line: 13]\n" + + " [pc: 13, line: 16]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 14] local: local1 index: 1 type: int\n" + + " [pc: 4, pc: 14] local: local2 index: 2 type: int\n" + + " [pc: 13, pc: 14] local: i index: 3 type: I\n" + + " \n" + + " // Method descriptor #33 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " // Stack: 0, Locals: 2\n" + + " private static synthetic void lambda$0(java.lang.Object o, java.lang.Object p);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: o index: 0 type: java.lang.Object\n" + + " [pc: 0, pc: 1] local: p index: 1 type: java.lang.Object\n" + + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #35 @Annotation(\n" + + " )\n" + + " Number of annotations for parameter 1: 1\n" + + " #35 @Annotation(\n" + + " )\n" + + " \n" + + " // Method descriptor #40 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" + + " // Stack: 2, Locals: 6\n" + + " private static synthetic void lambda$1(java.lang.String[] arg0, int arg1, int arg2, java.lang.Object o, java.lang.Object p);\n" + + " 0 aload_0 [arg0]\n" + + " 1 arraylength\n" + + " 2 iload_1 [arg1]\n" + + " 3 iadd\n" + + " 4 iload_2 [arg2]\n" + + " 5 iadd\n" + + " 6 istore 5\n" + + " 8 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 8, line: 15]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 9] local: o index: 3 type: java.lang.Object\n" + + " [pc: 0, pc: 9] local: p index: 4 type: java.lang.Object\n" + + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 0\n" + + " Number of annotations for parameter 1: 0\n" + + " Number of annotations for parameter 2: 0\n" + + " Number of annotations for parameter 3: 1\n" + + " #35 @Annotation(\n" + + " )\n" + + " Number of annotations for parameter 4: 1\n" + + " #35 @Annotation(\n" + + " )\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #62 java/lang/invoke/MethodHandles$Lookup, outer class info: #64 java/lang/invoke/MethodHandles\n" + + " inner name: #66 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 50 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;" + + "Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #51 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " #54 invokestatic X.lambda$0:(Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " #55 (Ljava/lang/Object;Ljava/lang/Object;)V,\n" + + " 1 : # 50 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;" + + "Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #56 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + " #59 invokestatic X.lambda$1:([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" + + " #60 (Ljava/lang/Object;Ljava/lang/Object;)V\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406641, [1.8][compiler][codegen] Code generation for intersection cast. +public void test015() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main( String [] args) { \n" + + " I i = (I & java.io.Serializable) () -> {};\n" + + " }\n" + + "}\n", + }, + ""); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #5.#6 ()V\n" + + " constant #10 utf8: \"LineNumberTable\"\n" + + " constant #11 utf8: \"LocalVariableTable\"\n" + + " constant #12 utf8: \"this\"\n" + + " constant #13 utf8: \"LX;\"\n" + + " constant #14 utf8: \"main\"\n" + + " constant #15 utf8: \"([Ljava/lang/String;)V\"\n" + + " constant #16 invoke dynamic: #0 #17 foo ()LI;\n" + + " constant #17 name_and_type: #18.#19 foo ()LI;\n" + + " constant #18 utf8: \"foo\"\n" + + " constant #19 utf8: \"()LI;\"\n" + + " constant #20 utf8: \"args\"\n" + + " constant #21 utf8: \"[Ljava/lang/String;\"\n" + + " constant #22 utf8: \"i\"\n" + + " constant #23 utf8: \"LI;\"\n" + + " constant #24 utf8: \"lambda$0\"\n" + + " constant #25 utf8: \"$deserializeLambda$\"\n" + + " constant #26 utf8: \"(Ljava/lang/invoke/SerializedLambda;)Ljava/lang/Object;\"\n" + + " constant #27 method_ref: #28.#30 java/lang/invoke/SerializedLambda.getImplMethodName ()Ljava/lang/String;\n" + + " constant #28 class: #29 java/lang/invoke/SerializedLambda\n" + + " constant #29 utf8: \"java/lang/invoke/SerializedLambda\"\n" + + " constant #30 name_and_type: #31.#32 getImplMethodName ()Ljava/lang/String;\n" + + " constant #31 utf8: \"getImplMethodName\"\n" + + " constant #32 utf8: \"()Ljava/lang/String;\"\n" + + " constant #33 method_ref: #34.#36 java/lang/String.hashCode ()I\n" + + " constant #34 class: #35 java/lang/String\n" + + " constant #35 utf8: \"java/lang/String\"\n" + + " constant #36 name_and_type: #37.#38 hashCode ()I\n" + + " constant #37 utf8: \"hashCode\"\n" + + " constant #38 utf8: \"()I\"\n" + + " constant #39 string: #24 \"lambda$0\"\n" + + " constant #40 method_ref: #34.#41 java/lang/String.equals (Ljava/lang/Object;)Z\n" + + " constant #41 name_and_type: #42.#43 equals (Ljava/lang/Object;)Z\n" + + " constant #42 utf8: \"equals\"\n" + + " constant #43 utf8: \"(Ljava/lang/Object;)Z\"\n" + + " constant #44 method_ref: #28.#45 java/lang/invoke/SerializedLambda.getImplMethodKind ()I\n" + + " constant #45 name_and_type: #46.#38 getImplMethodKind ()I\n" + + " constant #46 utf8: \"getImplMethodKind\"\n" + + " constant #47 method_ref: #28.#48 java/lang/invoke/SerializedLambda.getFunctionalInterfaceClass ()Ljava/lang/String;\n" + + " constant #48 name_and_type: #49.#32 getFunctionalInterfaceClass ()Ljava/lang/String;\n" + + " constant #49 utf8: \"getFunctionalInterfaceClass\"\n" + + " constant #50 string: #51 \"I\"\n" + + " constant #51 utf8: \"I\"\n" + + " constant #52 method_ref: #3.#41 java/lang/Object.equals (Ljava/lang/Object;)Z\n" + + " constant #53 method_ref: #28.#54 java/lang/invoke/SerializedLambda.getFunctionalInterfaceMethodName ()Ljava/lang/String;\n" + + " constant #54 name_and_type: #55.#32 getFunctionalInterfaceMethodName ()Ljava/lang/String;\n" + + " constant #55 utf8: \"getFunctionalInterfaceMethodName\"\n" + + " constant #56 string: #18 \"foo\"\n" + + " constant #57 method_ref: #28.#58 java/lang/invoke/SerializedLambda.getFunctionalInterfaceMethodSignature ()Ljava/lang/String;\n" + + " constant #58 name_and_type: #59.#32 getFunctionalInterfaceMethodSignature ()Ljava/lang/String;\n" + + " constant #59 utf8: \"getFunctionalInterfaceMethodSignature\"\n" + + " constant #60 string: #6 \"()V\"\n" + + " constant #61 method_ref: #28.#62 java/lang/invoke/SerializedLambda.getImplClass ()Ljava/lang/String;\n" + + " constant #62 name_and_type: #63.#32 getImplClass ()Ljava/lang/String;\n" + + " constant #63 utf8: \"getImplClass\"\n" + + " constant #64 string: #2 \"X\"\n" + + " constant #65 method_ref: #28.#66 java/lang/invoke/SerializedLambda.getImplMethodSignature ()Ljava/lang/String;\n" + + " constant #66 name_and_type: #67.#32 getImplMethodSignature ()Ljava/lang/String;\n" + + " constant #67 utf8: \"getImplMethodSignature\"\n" + + " constant #68 class: #69 java/lang/IllegalArgumentException\n" + + " constant #69 utf8: \"java/lang/IllegalArgumentException\"\n" + + " constant #70 string: #71 \"Invalid lambda deserialization\"\n" + + " constant #71 utf8: \"Invalid lambda deserialization\"\n" + + " constant #72 method_ref: #68.#73 java/lang/IllegalArgumentException. (Ljava/lang/String;)V\n" + + " constant #73 name_and_type: #5.#74 (Ljava/lang/String;)V\n" + + " constant #74 utf8: \"(Ljava/lang/String;)V\"\n" + + " constant #75 utf8: \"StackMapTable\"\n" + + " constant #76 utf8: \"SourceFile\"\n" + + " constant #77 utf8: \"X.java\"\n" + + " constant #78 utf8: \"BootstrapMethods\"\n" + + " constant #79 method_ref: #80.#82 java/lang/invoke/LambdaMetafactory.altMetafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n" + + " constant #80 class: #81 java/lang/invoke/LambdaMetafactory\n" + + " constant #81 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #82 name_and_type: #83.#84 altMetafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n" + + " constant #83 utf8: \"altMetafactory\"\n" + + " constant #84 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #85 method handle: invokestatic (6) #79 \n" + + " constant #86 method type: #6 ()V\n" + + " constant #87 method_ref: #1.#88 X.lambda$0 ()V\n" + + " constant #88 name_and_type: #24.#6 lambda$0 ()V\n" + + " constant #89 method handle: invokestatic (6) #87 \n" + + " constant #90 method type: #6 ()V\n" + + " constant #91 integer: 1\n" + + " constant #92 utf8: \"InnerClasses\"\n" + + " constant #93 class: #94 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #94 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #95 class: #96 java/lang/invoke/MethodHandles\n" + + " constant #96 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #97 utf8: \"Lookup\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 invokedynamic 0 foo() : I [16]\n" + + " 5 astore_1 [i]\n" + + " 6 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 6, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 7] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 6, pc: 7] local: i index: 1 type: I\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 0\n" + + " private static synthetic void lambda$0();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " \n" + + " // Method descriptor #26 (Ljava/lang/invoke/SerializedLambda;)Ljava/lang/Object;\n" + + " // Stack: 3, Locals: 3\n" + + " private static synthetic java.lang.Object $deserializeLambda$(java.lang.invoke.SerializedLambda arg0);\n" + + " 0 aload_0 [arg0]\n" + + " 1 invokevirtual java.lang.invoke.SerializedLambda.getImplMethodName() : java.lang.String [27]\n" + + " 4 astore_1\n" + + " 5 iconst_m1\n" + + " 6 istore_2\n" + + " 7 aload_1\n" + + " 8 invokevirtual java.lang.String.hashCode() : int [33]\n" + + " 11 lookupswitch default: 39\n" + + " case -1647345005: 28\n" + + " 28 aload_1\n" + + " 29 ldc [39]\n" + + " 31 invokevirtual java.lang.String.equals(java.lang.Object) : boolean [40]\n" + + " 34 ifeq 39\n" + + " 37 iconst_0\n" + + " 38 istore_2\n" + + " 39 iload_2\n" + + " 40 lookupswitch default: 135\n" + + " case 0: 60\n" + + " 60 aload_0 [arg0]\n" + + " 61 invokevirtual java.lang.invoke.SerializedLambda.getImplMethodKind() : int [44]\n" + + " 64 bipush 6\n" + + " 66 if_icmpne 135\n" + + " 69 aload_0 [arg0]\n" + + " 70 invokevirtual java.lang.invoke.SerializedLambda.getFunctionalInterfaceClass() : java.lang.String [47]\n" + + " 73 ldc [50]\n" + + " 75 invokevirtual java.lang.Object.equals(java.lang.Object) : boolean [52]\n" + + " 78 ifeq 135\n" + + " 81 aload_0 [arg0]\n" + + " 82 invokevirtual java.lang.invoke.SerializedLambda.getFunctionalInterfaceMethodName() : java.lang.String [53]\n" + + " 85 ldc [56]\n" + + " 87 invokevirtual java.lang.Object.equals(java.lang.Object) : boolean [52]\n" + + " 90 ifeq 135\n" + + " 93 aload_0 [arg0]\n" + + " 94 invokevirtual java.lang.invoke.SerializedLambda.getFunctionalInterfaceMethodSignature() : java.lang.String [57]\n" + + " 97 ldc [60]\n" + + " 99 invokevirtual java.lang.Object.equals(java.lang.Object) : boolean [52]\n" + + " 102 ifeq 135\n" + + " 105 aload_0 [arg0]\n" + + " 106 invokevirtual java.lang.invoke.SerializedLambda.getImplClass() : java.lang.String [61]\n" + + " 109 ldc [64]\n" + + " 111 invokevirtual java.lang.Object.equals(java.lang.Object) : boolean [52]\n" + + " 114 ifeq 135\n" + + " 117 aload_0 [arg0]\n" + + " 118 invokevirtual java.lang.invoke.SerializedLambda.getImplMethodSignature() : java.lang.String [65]\n" + + " 121 ldc [60]\n" + + " 123 invokevirtual java.lang.Object.equals(java.lang.Object) : boolean [52]\n" + + " 126 ifeq 135\n" + + " 129 invokedynamic 0 foo() : I [16]\n" + + " 134 areturn\n" + + " 135 new java.lang.IllegalArgumentException [68]\n" + + " 138 dup\n" + + " 139 ldc [70]\n" + + " 141 invokespecial java.lang.IllegalArgumentException(java.lang.String) [72]\n" + + " 144 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Stack map table: number of frames 4\n" + + " [pc: 28, append: {java.lang.String, int}]\n" + + " [pc: 39, same]\n" + + " [pc: 60, same]\n" + + " [pc: 135, chop 2 local(s)]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #93 java/lang/invoke/MethodHandles$Lookup, outer class info: #95 java/lang/invoke/MethodHandles\n" + + " inner name: #97 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 85 invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #86 ()V\n" + + " #89 invokestatic X.lambda$0:()V\n" + + " #90 ()V\n" + + " #91 1\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406392, [1.8][compiler][codegen] Improve identification of lambdas that must capture enclosing instance +public void test016() throws Exception { + // This test proves that when a lambda body references a type variable of an enclosing method, it can still be emitted as a static method. + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " class Y {\n" + + " T goo() {\n" + + " ((I) () -> {\n" + + " T t = null;\n" + + " System.out.println(\"Lambda\");\n" + + " }).doit();\n" + + " return null;\n" + + " }\n" + + " }\n" + + " new Y().goo();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(); \n" + + " }\n" + + "}\n", + }, + "Lambda"); + + String nestConstant = ""; + String nestHost = ""; + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.complianceLevel >= ClassFileConstants.JDK11) { + nestConstant = " constant #77 utf8: \"NestHost\"\n"; + nestHost = "\n" + + "Nest Host: #53 X\n"; + } + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "class X$1Y {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X$1Y\n" + + " constant #2 utf8: \"X$1Y\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"this$0\"\n" + + " constant #6 utf8: \"LX;\"\n" + + " constant #7 utf8: \"\"\n" + + " constant #8 utf8: \"(LX;)V\"\n" + + " constant #9 utf8: \"Code\"\n" + + " constant #10 field_ref: #1.#11 X$1Y.this$0 LX;\n" + + " constant #11 name_and_type: #5.#6 this$0 LX;\n" + + " constant #12 method_ref: #3.#13 java/lang/Object. ()V\n" + + " constant #13 name_and_type: #7.#14 ()V\n" + + " constant #14 utf8: \"()V\"\n" + + " constant #15 utf8: \"LineNumberTable\"\n" + + " constant #16 utf8: \"LocalVariableTable\"\n" + + " constant #17 utf8: \"this\"\n" + + " constant #18 utf8: \"LX$1Y;\"\n" + + " constant #19 utf8: \"goo\"\n" + + " constant #20 utf8: \"()Ljava/lang/Object;\"\n" + + " constant #21 utf8: \"Signature\"\n" + + " constant #22 utf8: \"()TT;\"\n" + + " constant #23 invoke dynamic: #0 #24 doit ()LI;\n" + + " constant #24 name_and_type: #25.#26 doit ()LI;\n" + + " constant #25 utf8: \"doit\"\n" + + " constant #26 utf8: \"()LI;\"\n" + + " constant #27 interface_method_ref: #28.#30 I.doit ()V\n" + + " constant #28 class: #29 I\n" + + " constant #29 utf8: \"I\"\n" + + " constant #30 name_and_type: #25.#14 doit ()V\n" + + " constant #31 utf8: \"lambda$0\"\n" + + " constant #32 field_ref: #33.#35 java/lang/System.out Ljava/io/PrintStream;\n" + + " constant #33 class: #34 java/lang/System\n" + + " constant #34 utf8: \"java/lang/System\"\n" + + " constant #35 name_and_type: #36.#37 out Ljava/io/PrintStream;\n" + + " constant #36 utf8: \"out\"\n" + + " constant #37 utf8: \"Ljava/io/PrintStream;\"\n" + + " constant #38 string: #39 \"Lambda\"\n" + + " constant #39 utf8: \"Lambda\"\n" + + " constant #40 method_ref: #41.#43 java/io/PrintStream.println (Ljava/lang/String;)V\n" + + " constant #41 class: #42 java/io/PrintStream\n" + + " constant #42 utf8: \"java/io/PrintStream\"\n" + + " constant #43 name_and_type: #44.#45 println (Ljava/lang/String;)V\n" + + " constant #44 utf8: \"println\"\n" + + " constant #45 utf8: \"(Ljava/lang/String;)V\"\n" + + " constant #46 utf8: \"t\"\n" + + " constant #47 utf8: \"Ljava/lang/Object;\"\n" + + " constant #48 utf8: \"LocalVariableTypeTable\"\n" + + " constant #49 utf8: \"TT;\"\n" + + " constant #50 utf8: \"SourceFile\"\n" + + " constant #51 utf8: \"X.java\"\n" + + " constant #52 utf8: \"EnclosingMethod\"\n" + + " constant #53 class: #54 X\n" + + " constant #54 utf8: \"X\"\n" + + " constant #55 name_and_type: #56.#14 foo ()V\n" + + " constant #56 utf8: \"foo\"\n" + + " constant #57 utf8: \"BootstrapMethods\"\n" + + " constant #58 method_ref: #59.#61 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #59 class: #60 java/lang/invoke/LambdaMetafactory\n" + + " constant #60 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #61 name_and_type: #62.#63 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #62 utf8: \"metafactory\"\n" + + " constant #63 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #64 method handle: invokestatic (6) #58 \n" + + " constant #65 method type: #14 ()V\n" + + " constant #66 method_ref: #1.#67 X$1Y.lambda$0 ()V\n" + + " constant #67 name_and_type: #31.#14 lambda$0 ()V\n" + + " constant #68 method handle: invokestatic (6) #66 \n" + + " constant #69 method type: #14 ()V\n" + + " constant #70 utf8: \"InnerClasses\"\n" + + " constant #71 utf8: \"Y\"\n" + + " constant #72 class: #73 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #73 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #74 class: #75 java/lang/invoke/MethodHandles\n" + + " constant #75 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #76 utf8: \"Lookup\"\n" + + nestConstant + + " \n" + + " // Field descriptor #6 LX;\n" + + " final synthetic X this$0;\n" + + " \n" + + " // Method descriptor #8 (LX;)V\n" + + " // Stack: 2, Locals: 2\n" + + " X$1Y(X arg0);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 putfield X$1Y.this$0 : X [10]\n" + + " 5 aload_0 [this]\n" + + " 6 invokespecial java.lang.Object() [12]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: new X(){}\n" + + " \n" + + " // Method descriptor #20 ()Ljava/lang/Object;\n" + + " // Signature: ()TT;\n" + + " // Stack: 1, Locals: 1\n" + + " java.lang.Object goo();\n" + + " 0 invokedynamic 0 doit() : I [23]\n" + + " 5 invokeinterface I.doit() : void [27] [nargs: 1]\n" + + " 10 aconst_null\n" + + " 11 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 5, line: 11]\n" + + " [pc: 10, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: new X(){}\n" + + " \n" + + " // Method descriptor #14 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " private static synthetic void lambda$0();\n" + + " 0 aconst_null\n" + + " 1 astore_0 [t]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [32]\n" + + " 5 ldc [38]\n" + + " 7 invokevirtual java.io.PrintStream.println(java.lang.String) : void [40]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 2, line: 10]\n" + + " [pc: 10, line: 11]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 10] local: t index: 0 type: java.lang.Object\n" + + " Local variable type table:\n" + + " [pc: 2, pc: 10] local: t index: 0 type: T\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #1 X$1Y, outer class info: #0\n" + + " inner name: #71 Y, accessflags: 0 default],\n" + + " [inner class info: #72 java/lang/invoke/MethodHandles$Lookup, outer class info: #74 java/lang/invoke/MethodHandles\n" + + " inner name: #76 Lookup, accessflags: 25 public static final]\n" + + " Enclosing Method: #53 #55 X.foo()V\n" + + nestHost + + "Bootstrap methods:\n" + + " 0 : # 64 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;" + + "Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #65 ()V\n" + + " #68 invokestatic X$1Y.lambda$0:()V\n" + + " #69 ()V\n" + + "}"; + + verifyClassFile(expectedOutput, "X$1Y.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406392, [1.8][compiler][codegen] Improve identification of lambdas that must capture enclosing instance +public void test017() throws Exception { + // This test proves that when a lambda body references a type variable of an enclosing class, it can still be emitted as a static method. + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " class Y {\n" + + " T goo() {\n" + + " ((I) () -> {\n" + + " T t = null;\n" + + " System.out.println(\"Lambda\"); \n" + + " }).doit();\n" + + " return null;\n" + + " }\n" + + " }\n" + + " new Y().goo();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(); \n" + + " }\n" + + "}\n", + }, + "Lambda"); + + String nestConstant = ""; + String nestHost = ""; + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.complianceLevel >= ClassFileConstants.JDK11) { + nestConstant = " constant #77 utf8: \"NestHost\"\n"; + nestHost = "\n" + + "Nest Host: #53 X\n"; + } + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "class X$1Y {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X$1Y\n" + + " constant #2 utf8: \"X$1Y\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"this$0\"\n" + + " constant #6 utf8: \"LX;\"\n" + + " constant #7 utf8: \"\"\n" + + " constant #8 utf8: \"(LX;)V\"\n" + + " constant #9 utf8: \"Code\"\n" + + " constant #10 field_ref: #1.#11 X$1Y.this$0 LX;\n" + + " constant #11 name_and_type: #5.#6 this$0 LX;\n" + + " constant #12 method_ref: #3.#13 java/lang/Object. ()V\n" + + " constant #13 name_and_type: #7.#14 ()V\n" + + " constant #14 utf8: \"()V\"\n" + + " constant #15 utf8: \"LineNumberTable\"\n" + + " constant #16 utf8: \"LocalVariableTable\"\n" + + " constant #17 utf8: \"this\"\n" + + " constant #18 utf8: \"LX$1Y;\"\n" + + " constant #19 utf8: \"goo\"\n" + + " constant #20 utf8: \"()Ljava/lang/Object;\"\n" + + " constant #21 utf8: \"Signature\"\n" + + " constant #22 utf8: \"()TT;\"\n" + + " constant #23 invoke dynamic: #0 #24 doit ()LI;\n" + + " constant #24 name_and_type: #25.#26 doit ()LI;\n" + + " constant #25 utf8: \"doit\"\n" + + " constant #26 utf8: \"()LI;\"\n" + + " constant #27 interface_method_ref: #28.#30 I.doit ()V\n" + + " constant #28 class: #29 I\n" + + " constant #29 utf8: \"I\"\n" + + " constant #30 name_and_type: #25.#14 doit ()V\n" + + " constant #31 utf8: \"lambda$0\"\n" + + " constant #32 field_ref: #33.#35 java/lang/System.out Ljava/io/PrintStream;\n" + + " constant #33 class: #34 java/lang/System\n" + + " constant #34 utf8: \"java/lang/System\"\n" + + " constant #35 name_and_type: #36.#37 out Ljava/io/PrintStream;\n" + + " constant #36 utf8: \"out\"\n" + + " constant #37 utf8: \"Ljava/io/PrintStream;\"\n" + + " constant #38 string: #39 \"Lambda\"\n" + + " constant #39 utf8: \"Lambda\"\n" + + " constant #40 method_ref: #41.#43 java/io/PrintStream.println (Ljava/lang/String;)V\n" + + " constant #41 class: #42 java/io/PrintStream\n" + + " constant #42 utf8: \"java/io/PrintStream\"\n" + + " constant #43 name_and_type: #44.#45 println (Ljava/lang/String;)V\n" + + " constant #44 utf8: \"println\"\n" + + " constant #45 utf8: \"(Ljava/lang/String;)V\"\n" + + " constant #46 utf8: \"t\"\n" + + " constant #47 utf8: \"Ljava/lang/Object;\"\n" + + " constant #48 utf8: \"LocalVariableTypeTable\"\n" + + " constant #49 utf8: \"TT;\"\n" + + " constant #50 utf8: \"SourceFile\"\n" + + " constant #51 utf8: \"X.java\"\n" + + " constant #52 utf8: \"EnclosingMethod\"\n" + + " constant #53 class: #54 X\n" + + " constant #54 utf8: \"X\"\n" + + " constant #55 name_and_type: #56.#14 foo ()V\n" + + " constant #56 utf8: \"foo\"\n" + + " constant #57 utf8: \"BootstrapMethods\"\n" + + " constant #58 method_ref: #59.#61 java/lang/invoke/LambdaMetafactory.metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #59 class: #60 java/lang/invoke/LambdaMetafactory\n" + + " constant #60 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #61 name_and_type: #62.#63 metafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " constant #62 utf8: \"metafactory\"\n" + + " constant #63 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #64 method handle: invokestatic (6) #58 \n" + + " constant #65 method type: #14 ()V\n" + + " constant #66 method_ref: #1.#67 X$1Y.lambda$0 ()V\n" + + " constant #67 name_and_type: #31.#14 lambda$0 ()V\n" + + " constant #68 method handle: invokestatic (6) #66 \n" + + " constant #69 method type: #14 ()V\n" + + " constant #70 utf8: \"InnerClasses\"\n" + + " constant #71 utf8: \"Y\"\n" + + " constant #72 class: #73 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #73 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #74 class: #75 java/lang/invoke/MethodHandles\n" + + " constant #75 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #76 utf8: \"Lookup\"\n" + + nestConstant + + " \n" + + " // Field descriptor #6 LX;\n" + + " final synthetic X this$0;\n" + + " \n" + + " // Method descriptor #8 (LX;)V\n" + + " // Stack: 2, Locals: 2\n" + + " X$1Y(X arg0);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 putfield X$1Y.this$0 : X [10]\n" + + " 5 aload_0 [this]\n" + + " 6 invokespecial java.lang.Object() [12]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: new X(){}\n" + + " \n" + + " // Method descriptor #20 ()Ljava/lang/Object;\n" + + " // Signature: ()TT;\n" + + " // Stack: 1, Locals: 1\n" + + " java.lang.Object goo();\n" + + " 0 invokedynamic 0 doit() : I [23]\n" + + " 5 invokeinterface I.doit() : void [27] [nargs: 1]\n" + + " 10 aconst_null\n" + + " 11 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 5, line: 11]\n" + + " [pc: 10, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: new X(){}\n" + + " \n" + + " // Method descriptor #14 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " private static synthetic void lambda$0();\n" + + " 0 aconst_null\n" + + " 1 astore_0 [t]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [32]\n" + + " 5 ldc [38]\n" + + " 7 invokevirtual java.io.PrintStream.println(java.lang.String) : void [40]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 2, line: 10]\n" + + " [pc: 10, line: 11]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 10] local: t index: 0 type: java.lang.Object\n" + + " Local variable type table:\n" + + " [pc: 2, pc: 10] local: t index: 0 type: T\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #1 X$1Y, outer class info: #0\n" + + " inner name: #71 Y, accessflags: 0 default],\n" + + " [inner class info: #72 java/lang/invoke/MethodHandles$Lookup, outer class info: #74 java/lang/invoke/MethodHandles\n" + + " inner name: #76 Lookup, accessflags: 25 public static final]\n" + + " Enclosing Method: #53 #55 X.foo()V\n" + + nestHost + + "Bootstrap methods:\n" + + " 0 : # 64 invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;" + + "Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #65 ()V\n" + + " #68 invokestatic X$1Y.lambda$0:()V\n" + + " #69 ()V\n" + + "}"; + + verifyClassFile(expectedOutput, "X$1Y.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424444, [1.8] VerifyError when constructor reference used with array +public void test424444() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Functional {\n" + + " T foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = goo(10);\n" + + " Functional contr = int[]::new;\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " static int [] goo(int x) {\n" + + " return new int [x];\n" + + " }\n" + + "}\n", + }, + "Done"); + + String expectedOutput = + " // Method descriptor #19 (I)[I\n" + + " // Stack: 1, Locals: 1\n" + + " private static synthetic int[] lambda$0(int arg0);\n" + + " 0 iload_0 [arg0]\n" + + " 1 newarray int [10]\n" + + " 3 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + "\n"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424444, [1.8] VerifyError when constructor reference used with array +public void test424444a() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Functional {\n" + + " T foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = goo(10);\n" + + " Functional contr = int[][]::new;\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " static int [] goo(int x) {\n" + + " return new int [x];\n" + + " }\n" + + "}\n", + }, + "Done"); + + String expectedOutput = + " // Method descriptor #49 (I)[[I\n" + + " // Stack: 1, Locals: 1\n" + + " private static synthetic int[][] lambda$0(int arg0);\n" + + " 0 iload_0 [arg0]\n" + + " 1 anewarray int[] [50]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + "\n"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424444, [1.8] VerifyError when constructor reference used with array +public void test424444b() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Functional {\n" + + " T foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = goo(10);\n" + + " Functional contr = String[]::new;\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " static int [] goo(int x) {\n" + + " return new int [x];\n" + + " }\n" + + "}\n", + }, + "Done"); + + String expectedOutput = + " // Method descriptor #49 (I)[Ljava/lang/String;\n" + + " // Stack: 1, Locals: 1\n" + + " private static synthetic java.lang.String[] lambda$0(int arg0);\n" + + " 0 iload_0 [arg0]\n" + + " 1 anewarray java.lang.String [50]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + "\n"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424444, [1.8] VerifyError when constructor reference used with array +public void test424444c() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Functional {\n" + + " T foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = goo(10);\n" + + " Functional contr = String[][]::new;\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " static int [] goo(int x) {\n" + + " return new int [x];\n" + + " }\n" + + "}\n", + }, + "Done"); + + String expectedOutput = + " // Method descriptor #49 (I)[[Ljava/lang/String;\n" + + " // Stack: 1, Locals: 1\n" + + " private static synthetic java.lang.String[][] lambda$0(int arg0);\n" + + " 0 iload_0 [arg0]\n" + + " 1 anewarray java.lang.String[] [50]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + "\n"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424444, [1.8] VerifyError when constructor reference used with array +public void test424444d() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Functional {\n" + + " T foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = goo(10);\n" + + " Functional contr = String[][]::new;\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " static int [] goo(int x) {\n" + + " return new int [x];\n" + + " }\n" + + "}\n", + }, + "Done"); + + String expectedOutput = + " // Method descriptor #49 (I)[[Ljava/lang/String;\n" + + " // Stack: 1, Locals: 1\n" + + " private static synthetic java.lang.String[][] lambda$0(int arg0);\n" + + " 0 iload_0 [arg0]\n" + + " 1 anewarray java.lang.String[] [50]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + "\n"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430015, [1.8] NPE trying to disassemble classfile with lambda method and MethodParameters +public void test430015() throws IOException, ClassFormatException { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Parameter;\n" + + "import java.util.Arrays;\n" + + "import java.util.function.IntConsumer;\n" + + "public class X {\n" + + " IntConsumer xx(int a) {\n" + + " return i -> { };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Method[] methods = X.class.getDeclaredMethods();\n" + + " for (Method method : methods) {\n" + + " if (method.getName().contains(\"lambda\")) {\n" + + " Parameter[] parameters = method.getParameters();\n" + + " System.out.println(Arrays.asList(parameters));\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "[int arg0]"); + + String expectedOutput = + " // Method descriptor #78 (I)V\n" + + " // Stack: 0, Locals: 1\n" + + " private static synthetic void lambda$0(int i);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: i index: 0 type: int\n" + + "\n"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430015, [1.8] NPE trying to disassemble classfile with lambda method and MethodParameters +public void test430015a() throws IOException, ClassFormatException { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE); + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Parameter;\n" + + "import java.util.Arrays;\n" + + "import java.util.function.IntConsumer;\n" + + "public class X {\n" + + " IntConsumer xx(int a) {\n" + + " return i -> { };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n" + }, + "", + customOptions); + + String expectedOutput = + " // Method descriptor #28 (I)V\n" + + " // Stack: 0, Locals: 1\n" + + " private static synthetic void lambda$0(int i);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: i index: 0 type: int\n" + + "\n"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430035, [1.8][compiler][codegen] Bridge methods are not generated for lambdas/method references +public void test430035() throws IOException, ClassFormatException { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String t, T u);\n" + + "}\n" + + "interface J {\n" + + " void foo(T t, String u);\n" + + "}\n" + + "interface K extends I, J {\n" + + " void foo(String t, String u);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String... x) {\n" + + " K k = (s, u) -> System.out.println(\"m(\"+ s + u + ')');\n" + + " k.foo(\"direct\", \" call\");\n" + + " J j = k;\n" + + " j.foo(\"bridge\", \" method(j)\");\n" + + " I i = k;\n" + + " i.foo(\"bridge\", \" method(i)\");\n" + + " }\n" + + "}\n" + }, + "m(direct call)\n" + + "m(bridge method(j))\n" + + "m(bridge method(i))"); + + String expectedOutput = + "// Compiled from X.java (" + this.versionString + ", super bit)\n" + + "public class X {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 utf8: \"\"\n" + + " constant #6 utf8: \"()V\"\n" + + " constant #7 utf8: \"Code\"\n" + + " constant #8 method_ref: #3.#9 java/lang/Object. ()V\n" + + " constant #9 name_and_type: #5.#6 ()V\n" + + " constant #10 utf8: \"LineNumberTable\"\n" + + " constant #11 utf8: \"LocalVariableTable\"\n" + + " constant #12 utf8: \"this\"\n" + + " constant #13 utf8: \"LX;\"\n" + + " constant #14 utf8: \"main\"\n" + + " constant #15 utf8: \"([Ljava/lang/String;)V\"\n" + + " constant #16 invoke dynamic: #0 #17 foo ()LK;\n" + + " constant #17 name_and_type: #18.#19 foo ()LK;\n" + + " constant #18 utf8: \"foo\"\n" + + " constant #19 utf8: \"()LK;\"\n" + + " constant #20 string: #21 \"direct\"\n" + + " constant #21 utf8: \"direct\"\n" + + " constant #22 string: #23 \" call\"\n" + + " constant #23 utf8: \" call\"\n" + + " constant #24 interface_method_ref: #25.#27 K.foo (Ljava/lang/String;Ljava/lang/String;)V\n" + + " constant #25 class: #26 K\n" + + " constant #26 utf8: \"K\"\n" + + " constant #27 name_and_type: #18.#28 foo (Ljava/lang/String;Ljava/lang/String;)V\n" + + " constant #28 utf8: \"(Ljava/lang/String;Ljava/lang/String;)V\"\n" + + " constant #29 string: #30 \"bridge\"\n" + + " constant #30 utf8: \"bridge\"\n" + + " constant #31 string: #32 \" method(j)\"\n" + + " constant #32 utf8: \" method(j)\"\n" + + " constant #33 interface_method_ref: #34.#36 J.foo (Ljava/lang/Object;Ljava/lang/String;)V\n" + + " constant #34 class: #35 J\n" + + " constant #35 utf8: \"J\"\n" + + " constant #36 name_and_type: #18.#37 foo (Ljava/lang/Object;Ljava/lang/String;)V\n" + + " constant #37 utf8: \"(Ljava/lang/Object;Ljava/lang/String;)V\"\n" + + " constant #38 string: #39 \" method(i)\"\n" + + " constant #39 utf8: \" method(i)\"\n" + + " constant #40 interface_method_ref: #41.#43 I.foo (Ljava/lang/String;Ljava/lang/Object;)V\n" + + " constant #41 class: #42 I\n" + + " constant #42 utf8: \"I\"\n" + + " constant #43 name_and_type: #18.#44 foo (Ljava/lang/String;Ljava/lang/Object;)V\n" + + " constant #44 utf8: \"(Ljava/lang/String;Ljava/lang/Object;)V\"\n" + + " constant #45 utf8: \"x\"\n" + + " constant #46 utf8: \"[Ljava/lang/String;\"\n" + + " constant #47 utf8: \"k\"\n" + + " constant #48 utf8: \"LK;\"\n" + + " constant #49 utf8: \"j\"\n" + + " constant #50 utf8: \"LJ;\"\n" + + " constant #51 utf8: \"i\"\n" + + " constant #52 utf8: \"LI;\"\n" + + " constant #53 utf8: \"LocalVariableTypeTable\"\n" + + " constant #54 utf8: \"LJ;\"\n" + + " constant #55 utf8: \"LI;\"\n" + + " constant #56 utf8: \"lambda$0\"\n" + + " constant #57 field_ref: #58.#60 java/lang/System.out Ljava/io/PrintStream;\n" + + " constant #58 class: #59 java/lang/System\n" + + " constant #59 utf8: \"java/lang/System\"\n" + + " constant #60 name_and_type: #61.#62 out Ljava/io/PrintStream;\n" + + " constant #61 utf8: \"out\"\n" + + " constant #62 utf8: \"Ljava/io/PrintStream;\"\n" + + " constant #63 class: #64 java/lang/StringBuilder\n" + + " constant #64 utf8: \"java/lang/StringBuilder\"\n" + + " constant #65 string: #66 \"m(\"\n" + + " constant #66 utf8: \"m(\"\n" + + " constant #67 method_ref: #63.#68 java/lang/StringBuilder. (Ljava/lang/String;)V\n" + + " constant #68 name_and_type: #5.#69 (Ljava/lang/String;)V\n" + + " constant #69 utf8: \"(Ljava/lang/String;)V\"\n" + + " constant #70 method_ref: #63.#71 java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" + + " constant #71 name_and_type: #72.#73 append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" + + " constant #72 utf8: \"append\"\n" + + " constant #73 utf8: \"(Ljava/lang/String;)Ljava/lang/StringBuilder;\"\n" + + " constant #74 method_ref: #63.#75 java/lang/StringBuilder.append (C)Ljava/lang/StringBuilder;\n" + + " constant #75 name_and_type: #72.#76 append (C)Ljava/lang/StringBuilder;\n" + + " constant #76 utf8: \"(C)Ljava/lang/StringBuilder;\"\n" + + " constant #77 method_ref: #63.#78 java/lang/StringBuilder.toString ()Ljava/lang/String;\n" + + " constant #78 name_and_type: #79.#80 toString ()Ljava/lang/String;\n" + + " constant #79 utf8: \"toString\"\n" + + " constant #80 utf8: \"()Ljava/lang/String;\"\n" + + " constant #81 method_ref: #82.#84 java/io/PrintStream.println (Ljava/lang/String;)V\n" + + " constant #82 class: #83 java/io/PrintStream\n" + + " constant #83 utf8: \"java/io/PrintStream\"\n" + + " constant #84 name_and_type: #85.#69 println (Ljava/lang/String;)V\n" + + " constant #85 utf8: \"println\"\n" + + " constant #86 utf8: \"s\"\n" + + " constant #87 utf8: \"Ljava/lang/String;\"\n" + + " constant #88 utf8: \"u\"\n" + + " constant #89 utf8: \"SourceFile\"\n" + + " constant #90 utf8: \"X.java\"\n" + + " constant #91 utf8: \"BootstrapMethods\"\n" + + " constant #92 method_ref: #93.#95 java/lang/invoke/LambdaMetafactory.altMetafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n" + + " constant #93 class: #94 java/lang/invoke/LambdaMetafactory\n" + + " constant #94 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" + + " constant #95 name_and_type: #96.#97 altMetafactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n" + + " constant #96 utf8: \"altMetafactory\"\n" + + " constant #97 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\"\n" + + " constant #98 method handle: invokestatic (6) #92 \n" + + " constant #99 method type: #28 (Ljava/lang/String;Ljava/lang/String;)V\n" + + " constant #100 method_ref: #1.#101 X.lambda$0 (Ljava/lang/String;Ljava/lang/String;)V\n" + + " constant #101 name_and_type: #56.#28 lambda$0 (Ljava/lang/String;Ljava/lang/String;)V\n" + + " constant #102 method handle: invokestatic (6) #100 \n" + + " constant #103 method type: #28 (Ljava/lang/String;Ljava/lang/String;)V\n" + + " constant #104 integer: 4\n" + // flag bridge + " constant #105 integer: 2\n" + // two bridges + " constant #106 method type: #44 (Ljava/lang/String;Ljava/lang/Object;)V\n" + // first bridge + " constant #107 method type: #37 (Ljava/lang/Object;Ljava/lang/String;)V\n" + // next bridge. + " constant #108 utf8: \"InnerClasses\"\n" + + " constant #109 class: #110 java/lang/invoke/MethodHandles$Lookup\n" + + " constant #110 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" + + " constant #111 class: #112 java/lang/invoke/MethodHandles\n" + + " constant #112 utf8: \"java/lang/invoke/MethodHandles\"\n" + + " constant #113 utf8: \"Lookup\"\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 4\n" + + " public static void main(java.lang.String... x);\n" + + " 0 invokedynamic 0 foo() : K [16]\n" + + " 5 astore_1 [k]\n" + + " 6 aload_1 [k]\n" + + " 7 ldc [20]\n" + + " 9 ldc [22]\n" + + " 11 invokeinterface K.foo(java.lang.String, java.lang.String) : void [24] [nargs: 3]\n" + + " 16 aload_1 [k]\n" + + " 17 astore_2 [j]\n" + + " 18 aload_2 [j]\n" + + " 19 ldc [29]\n" + + " 21 ldc [31]\n" + + " 23 invokeinterface J.foo(java.lang.Object, java.lang.String) : void [33] [nargs: 3]\n" + + " 28 aload_1 [k]\n" + + " 29 astore_3 [i]\n" + + " 30 aload_3 [i]\n" + + " 31 ldc [29]\n" + + " 33 ldc [38]\n" + + " 35 invokeinterface I.foo(java.lang.String, java.lang.Object) : void [40] [nargs: 3]\n" + + " 40 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 12]\n" + + " [pc: 6, line: 13]\n" + + " [pc: 16, line: 14]\n" + + " [pc: 18, line: 15]\n" + + " [pc: 28, line: 16]\n" + + " [pc: 30, line: 17]\n" + + " [pc: 40, line: 18]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 41] local: x index: 0 type: java.lang.String[]\n" + + " [pc: 6, pc: 41] local: k index: 1 type: K\n" + + " [pc: 18, pc: 41] local: j index: 2 type: J\n" + + " [pc: 30, pc: 41] local: i index: 3 type: I\n" + + " Local variable type table:\n" + + " [pc: 18, pc: 41] local: j index: 2 type: J\n" + + " [pc: 30, pc: 41] local: i index: 3 type: I\n" + + " \n" + + " // Method descriptor #28 (Ljava/lang/String;Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 2\n" + + " private static synthetic void lambda$0(java.lang.String s, java.lang.String u);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [57]\n" + + " 3 new java.lang.StringBuilder [63]\n" + + " 6 dup\n" + + " 7 ldc [65]\n" + + " 9 invokespecial java.lang.StringBuilder(java.lang.String) [67]\n" + + " 12 aload_0 [s]\n" + + " 13 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [70]\n" + + " 16 aload_1 [u]\n" + + " 17 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [70]\n" + + " 20 bipush 41\n" + + " 22 invokevirtual java.lang.StringBuilder.append(char) : java.lang.StringBuilder [74]\n" + + " 25 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [77]\n" + + " 28 invokevirtual java.io.PrintStream.println(java.lang.String) : void [81]\n" + + " 31 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 32] local: s index: 0 type: java.lang.String\n" + + " [pc: 0, pc: 32] local: u index: 1 type: java.lang.String\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #109 java/lang/invoke/MethodHandles$Lookup, outer class info: #111 java/lang/invoke/MethodHandles\n" + + " inner name: #113 Lookup, accessflags: 25 public static final]\n" + + "Bootstrap methods:\n" + + " 0 : # 98 invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #99 (Ljava/lang/String;Ljava/lang/String;)V\n" + + " #102 invokestatic X.lambda$0:(Ljava/lang/String;Ljava/lang/String;)V\n" + + " #103 (Ljava/lang/String;Ljava/lang/String;)V\n" + + " #104 4\n" + + " #105 2\n" + + " #106 (Ljava/lang/String;Ljava/lang/Object;)V\n" + + " #107 (Ljava/lang/Object;Ljava/lang/String;)V\n" + + "}"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430571, [1.8][compiler] Lambda parameter names and annotations don't make it to class files. +public void test430571() throws IOException, ClassFormatException { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE); + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE) @interface A {}\n" + + "\n" + + "interface I { int foo(int x); }\n" + + "\n" + + "class X {\n" + + " I x = (@A int x) -> x + 1;\n" + + "}" + }, customOptions); + + String expectedOutput = + " // Method descriptor #23 (I)I\n" + + " // Stack: 2, Locals: 1\n" + + " private static synthetic int lambda$0(int x);\n" + + " 0 iload_0 [x]\n" + + " 1 iconst_1\n" + + " 2 iadd\n" + + " 3 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: x index: 0 type: int\n" + + " RuntimeInvisibleTypeAnnotations: \n" + // Annotations + " #26 @A(\n" + // <--- + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )"; + + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=435869, [1.8][compiler]AIOOB with annotated intersection cast +public void test435869() throws IOException, ClassFormatException { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.io.Serializable;\n" + + "\n" + + "public class X {\n" + + " Object o = (@Marker1 @Marker2 Serializable & I & @Marker3 @Marker1 J) () -> {};\n" + + " public void foo(Object o) {\n" + + " Serializable oo = (Serializable & @Marker3 @Marker1 @Marker2 I & J) o;\n" + + " I i = (@Marker1 @Marker2 Serializable & I & @Marker3 @Marker1 J) () -> {};\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public void foo(); \n" + + "}\n" + + "interface J {\n" + + " public void foo();\n" + + " public default void bar() {}\n" + + "}\n" + + "interface K {\n" + + " public void foo();\n" + + " public void bar();\n" + + "}\n" + + "@java.lang.annotation.Target (ElementType.TYPE_USE)\n" + + "@interface Marker1 {}\n" + + "@java.lang.annotation.Target (ElementType.TYPE_USE)\n" + + "@interface Marker2 {}\n" + + "@java.lang.annotation.Target (ElementType.TYPE_USE)\n" + + "@interface Marker3 {}\n" + }); +} +public static Class testClass() { + return JSR335ClassFileTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java new file mode 100644 index 0000000000..3f8d433821 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java @@ -0,0 +1,9263 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.parser.JavadocTagConstants; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocBugsTest extends JavadocTest { + + String docCommentSupport = CompilerOptions.ENABLED; + String reportInvalidJavadoc = CompilerOptions.ERROR; + String reportMissingJavadocDescription = CompilerOptions.RETURN_TAG; + String reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + String reportMissingJavadocTags = CompilerOptions.ERROR; + String reportMissingJavadocComments = null; + String reportMissingJavadocCommentsVisibility = null; + String reportDeprecation = CompilerOptions.ERROR; + String reportJavadocDeprecation = null; + String processAnnotations = null; + +public JavadocBugsTest(String name) { + super(name); +} + +public static Class javadocTestClass() { + return JavadocBugsTest.class; +} + +// Use this static initializer to specify subset for tests +// All specified tests which does not belong to the class are skipped... +static { +// TESTS_PREFIX = "testBug96237"; +// TESTS_NAMES = new String[] { "testBug382606" }; +// TESTS_NUMBERS = new int[] { 129241 }; +// TESTS_RANGE = new int[] { 21, 50 }; +} + +public static Test suite() { + return buildAllCompliancesTestSuite(javadocTestClass()); +} + +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, this.docCommentSupport); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, this.reportInvalidJavadoc); + if (!CompilerOptions.IGNORE.equals(this.reportInvalidJavadoc)) { + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, this.reportInvalidJavadocVisibility); + } + if (this.reportJavadocDeprecation != null) { + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef, this.reportJavadocDeprecation); + } + if (this.reportMissingJavadocComments != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsOverriding, CompilerOptions.ENABLED); + if (this.reportMissingJavadocCommentsVisibility != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsVisibility, this.reportMissingJavadocCommentsVisibility); + } + } else { + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportInvalidJavadoc); + } + if (this.reportMissingJavadocTags != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportMissingJavadocTags); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsOverriding, CompilerOptions.ENABLED); + } else { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportInvalidJavadoc); + } + if (this.reportMissingJavadocDescription != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagDescription, this.reportMissingJavadocDescription); + } + if (this.processAnnotations != null) { + options.put(CompilerOptions.OPTION_Process_Annotations, this.processAnnotations); + } + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportDeprecation, this.reportDeprecation); + options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + return options; +} +/* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ +@Override +protected void setUp() throws Exception { + super.setUp(); + this.docCommentSupport = CompilerOptions.ENABLED; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PUBLIC; + this.reportDeprecation = CompilerOptions.ERROR; +} + +/** + * Bug 45596. + * When this bug happened, compiler wrongly complained on missing parameter javadoc + * entries for method declaration in anonymous class. + * @see 45596 + */ +public void testBug45596() { + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "class X {\n" + + " void foo(int x, String str) {}\n" + + "}\n", + "test/Y.java", + "package test;\n" + + "class Y {\n" + + " /** */\n" + + " protected X field = new X() {\n" + + " void foo(int x, String str) {}\n" + + " };\n" + + "}\n"}); +} + +/** + * Additional test for bug 45596. + * Verify correct complain about missing parameter javadoc entries in anonymous class. + * Since bug 47132, @param, @return and @throws tags are not resolved in javadoc of anonymous + * class... + */ +public void testBug45596a() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(int x, String str) {}\n" + + "}\n", + "Y1.java", + "public class Y1 {\n" + + " /** */\n" + + " protected X field = new X() {\n" + + " /** Invalid javadoc comment in anonymous class */\n" + + " void foo(String str) {}\n" + + " };\n" + + "}\n", + "Y2.java", + "public class Y2 {\n" + + " /** */\n" + + " void foo() {\n" + + " X x = new X() {\n" + + " /** Invalid javadoc comment in anonymous class */\n" + + " void foo(String str) {}\n" + + " };\n" + + " x.foo(0, \"\");\n" + + " }\n" + + "}\n", + "Y3.java", + "public class Y3 {\n" + + " static X x;\n" + + " static {\n" + + " x = new X() {\n" + + " /** Invalid javadoc comment in anonymous class */\n" + + " void foo(String str) {}\n" + + " };\n" + + " }\n" + + "}\n" } + ); +} + +/** + * Additional test for bug 45596. + * Verify no complain about missing parameter javadoc entries. + */ +public void testBug45596b() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(int x, String str) {}\n" + + "}\n", + "Y1.java", + "public class Y1 {\n" + + " /** */\n" + + " protected X field = new X() {\n" + + " /**\n" + + " * Valid javadoc comment in anonymous class.\n" + + " * @param str String\n" + + " * @return int\n" + + " */\n" + + " int bar(String str) {\n" + + " return 10;\n" + + " }\n" + + " };\n" + + "}\n", + "Y2.java", + "public class Y2 {\n" + + " /** */\n" + + " void foo() {\n" + + " X x = new X() {\n" + + " /**\n" + + " * Valid javadoc comment in anonymous class.\n" + + " * @param str String\n" + + " * @return int\n" + + " */\n" + + " int bar(String str) {\n" + + " return 10;\n" + + " }\n" + + " };\n" + + " x.foo(0, \"\");\n" + + " }\n" + + "}\n", + "Y3.java", + "public class Y3 {\n" + + " static X x;\n" + + " static {\n" + + " x = new X() {\n" + + " /**\n" + + " * Valid javadoc comment in anonymous class.\n" + + " * @param str String\n" + + " * @return int\n" + + " */\n" + + " int bar(String str) {\n" + + " return 10;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n"} + ); +} + +/** + * Bug 45592. + * When this bug happened, a NullPointerException occured during the compilation. + * @see 45592 + */ +public void testBug45592() { + runConformTest( + new String[] { + "a/Y.java", + "package a;\n" + + "\n" + + "/** */\n" + + "public class Y {\n" + + " protected boolean bar(Object obj) {\n" + + " return obj == null;\n" + + " }\n" + + "}\n", + "test/X.java", + "package test;\n" + + "public class X {\n" + + " public static Boolean valueOf(boolean bool) {\n" + + " if (bool) {\n" + + " return Boolean.TRUE;\n" + + " } else {\n" + + " return Boolean.FALSE;\n" + + " }\n" + + " }\n" + + "}\n", + "test/YY.java", + "package test;\n" + + "\n" + + "import a.Y;\n" + + "\n" + + "/** */\n" + + "public class YY extends Y {\n" + + " /**\n" + + " * Returns a Boolean.\n" + + " * @param key\n" + + " * @return A Boolean telling whether the key is null or not.\n" + + " * @see #bar(Object)\n" + + " */\n" + + " protected Boolean foo(Object key) {\n" + + " return X.valueOf(bar(key));\n" + + " }\n" + + "}\n" + } + ); +} + +/** + * Bug 45737. + * When this bug happened, compiler complains on return type and argument of method bar. + * @see 45737 + */ +public void testBug45737() { + runConformTest( + new String[] { + "Y.java", + "class Y {\n" + + " void foo() {\n" + + " X x = new X() {\n" + + " /**\n" + + " * Valid javadoc comment in anonymous class.\n" + + " * @param str String\n" + + " * @return int\n" + + " */\n" + + " int bar(String str) {\n" + + " return 10;\n" + + " }\n" + + " };\n" + + " x.foo();\n" + + " }\n" + + "}\n", + "X.java", + "class X {\n" + + " void foo() {}\n" + + "}\n" + } + ); +} + +/** + * Bug 45669. + * @see 45669 + */ +public void testBug45669() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid javadoc comment with tags mixed order\n" + + " * @param str first param\n" + + " * @see String\n" + + " * @param dbl second param\n" + + " * @see Double\n" + + " * also\n" + + " * @see \"String ref\"\n" + + " * @return int\n" + + " * @throws InterruptedException\n" + + " * \n" + + " */\n" + + " int foo(String str, Double dbl) throws InterruptedException {\n" + + " return 0;\n" + + " }\n" + + "}\n" + } + ); +} +/* + * Additional test for bug 45669. + * Verify that compiler complains when @throws tag is between @param tags. + */ +public void testBug45669a() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Javadoc comment with tags invalid mixed order\n" + + " * @param str first param\n" + + " * @see String\n" + + " * @throws InterruptedException\n" + + " * @param dbl second param\n" + + " * @see Double\n" + + " * also\n" + + " * @see \"String ref\"\n" + + " * @return int\n" + + " * \n" + + " */\n" + + " public int foo(String str, Double dbl) throws InterruptedException {\n" + + " return 0;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " * @param dbl second param\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " public int foo(String str, Double dbl) throws InterruptedException {\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter dbl\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 45958. + * @see 45958 + */ +public void testBug45958() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int x;\n" + + " public X(int i) {\n" + + " x = i;\n" + + " }\n" + + " /**\n" + + " * @see #X(int)\n" + + " */\n" + + " void foo() {\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug45958a() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int x;\n" + + " public X(int i) {\n" + + " x = i;\n" + + " }\n" + + " /**\n" + + " * @see #X(String)\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " * @see #X(String)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor X(String) is undefined\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug45958b() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int x;\n" + + " public X(int i) {\n" + + " x = i;\n" + + " }\n" + + " /**\n" + + " * @see #X(int)\n" + + " */\n" + + " public void foo() {\n" + + " }\n" + + "}\n", + "XX.java", + "public class XX extends X {\n" + + " /**\n" + + " * @param i\n" + + " * @see #X(int)\n" + + " */\n" + + " public XX(int i) {\n" + + " super(i);\n" + + " x++;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in XX.java (at line 4)\n" + + " * @see #X(int)\n" + + " ^\n" + + "Javadoc: The method X(int) is undefined for the type XX\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug45958c() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int x;\n" + + " public X(int i) {\n" + + " x = i;\n" + + " }\n" + + " /**\n" + + " * @see #X(String)\n" + + " */\n" + + " void foo() {\n" + + " }\n" + + " void X(String str) {}\n" + + "}\n" + } + ); +} + +/** + * Bug 46901. + * @see 46901 + */ +public void testBug46901() { + runConformTest( + new String[] { + "A.java", + "public abstract class A {\n" + + " public A() { super(); }\n" + + "}\n", + "X.java", + "/**\n" + + " * @see A#A()\n" + + " */\n" + + "public class X extends A {\n" + + " public X() { super(); }\n" + + "}\n" + } + ); +} + +/** + * Bug 47215. + * @see 47215 + */ +public void testBug47215() { + runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * @see X\n" + + " * @see X#X(int)\n" + + " * @see X(double)\n" + + " * @see X (double)\n" + + " * @see X[double]\n" + + " * @see X!=}}\n" + + " * @see foo()\n" + + " * @see foo ()\n" + + " */\n" + + " public class X {\n" + + " public X(int i){}\n" + + " public void foo() {}\n" + + " }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see X(double)\n" + + " ^^^^^^^^^\n" + + "Javadoc: Missing #: \"X(double)\"\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see X[double]\n" + + " ^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see X!=}}\n" + + " ^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see foo()\n" + + " ^^^^^\n" + + "Javadoc: Missing #: \"foo()\"\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " * @see foo ()\n" + + " ^^^\n" + + "Javadoc: foo cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 47341. + * @see 47341 + */ +public void testBug47341() { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " void foo_package() {}\n" + + " protected void foo_protected() {}\n" + + "}\n", + "p1/Y.java", + "package p1;\n" + + "public class Y extends X {\n" + + " /**\n" + + " * @see #foo_package()\n" + + " */\n" + + " protected void bar() {\n" + + " foo_package();\n" + + " }\n" + + "}\n", + "p2/Y.java", + "package p2;\n" + + "import p1.X;\n" + + "\n" + + "public class Y extends X {\n" + + " /**\n" + + " * @see X#foo_protected()\n" + + " */\n" + + " protected void bar() {\n" + + " foo_protected();\n" + + " }\n" + + "}\n" + } + ); +} + +/** + * Bug 47132. + * @see 47132 + */ +public void testBug47132() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + " /** */\n" + + " public void foo(){\n" + + " new Object(){\n" + + " public int x;\n" + + " public void bar(){}\n" + + " };\n" + + " }\n" + + "}\n" + } + ); +} + +/** + * Bug 47339. + * @see 47339 + */ +public void testBug47339() { + runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X implements Comparable {\n" + + " /**\n" + + " * @see java.lang.Comparable#compareTo(java.lang.Object)\n" + + " */\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + " /** @see Object#toString() */\n" + + " public String toString(){\n" + + " return \"\";\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug47339a() { + runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X extends RuntimeException {\n" + + " \n" + + " /**\n" + + " * @see RuntimeException#RuntimeException(java.lang.String)\n" + + " */\n" + + " public X(String message) {\n" + + " super(message);\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug47339b() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "/** */\n" + + "public class X implements Comparable {\n" + + " /** */\n" + + " public int compareTo(Object o) {\n" + + " return 0;\n" + + " }\n" + + " /** */\n" + + " public String toString(){\n" + + " return \"\";\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public int compareTo(Object o) {\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public int compareTo(Object o) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter o\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " public String toString(){\n" + + " ^^^^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug47339c() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "/** */\n" + + "public class X extends RuntimeException {\n" + + " \n" + + " /** */\n" + + " public X(String message) {\n" + + " super(message);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public X(String message) {\n" + + " ^^^^^^^\n" + + "Javadoc: Missing tag for parameter message\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 48064. + * @see 48064 + */ +public void testBug48064() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(String str) {}\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " /**\n" + + " * @see X#X(STRING)\n" + + " */\n" + + " public Y(String str) {super(str);}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " * @see X#X(STRING)\n" + + " ^^^^^^\n" + + "Javadoc: STRING cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in Y.java (at line 5)\n" + + " public Y(String str) {super(str);}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter str\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug48064a() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String str) {}\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " /**\n" + + " * @see X#foo(STRING)\n" + + " */\n" + + " public void foo(String str) {super.foo(str);}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " * @see X#foo(STRING)\n" + + " ^^^^^^\n" + + "Javadoc: STRING cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in Y.java (at line 5)\n" + + " public void foo(String str) {super.foo(str);}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter str\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 48523. + * @see 48523 + */ +public void testBug48523() { + runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public void foo() throws IOException {}\n" + + "}\n", + "Y.java", + "import java.io.IOException;\n" + + "public class Y extends X {\n" + + " /**\n" + + " * @throws IOException\n" + + " * @see X#foo()\n" + + " */\n" + + " public void foo() throws IOException {}\n" + + "}\n" + } + ); +} + +/** + * Bug 48711. + * @see 48711 + */ +public void testBug48711() { + runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @throws IOException\n" + + " * @throws EOFException\n" + + " * @throws FileNotFoundException\n" + + " */\n" + + " public void foo() throws IOException {}\n" + + "}\n" + } + ); +} + +/** + * Bug 45782. + * When this bug happened, compiler wrongly complained on missing parameters declaration + * @see 45782 + */ +public void testBug45782() { + runConformTest( + new String[] { + "X.java", + "public class X implements Comparable {\n" + + "\n" + + " /**\n" + + " * Overridden method with return value and parameters.\n" + + " * {@inheritDoc}\n" + + " */\n" + + " public boolean equals(Object obj) {\n" + + " return super.equals(obj);\n" + + " }\n" + + "\n" + + " /**\n" + + " * Overridden method with return value and thrown exception.\n" + + " * {@inheritDoc}\n" + + " */\n" + + " public Object clone() throws CloneNotSupportedException {\n" + + " return super.clone();\n" + + " }\n" + + "\n" + + " /**\n" + + " * Implemented method (Comparable) with return value and parameters.\n" + + " * {@inheritDoc}\n" + + " */\n" + + " public int compareTo(Object o) { return 0; }\n" + + "}\n" + }); +} +public void testBug45782a() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Unefficient inheritDoc tag on a method which is neither overridden nor implemented...\n" + + " * {@inheritDoc}\n" + + " */\n" + + " public int foo(String str) throws IllegalArgumentException { return 0; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public int foo(String str) throws IllegalArgumentException { return 0; }\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public int foo(String str) throws IllegalArgumentException { return 0; }\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter str\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " public int foo(String str) throws IllegalArgumentException { return 0; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalArgumentException\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 49260. + * When this bug happened, compiler wrongly complained on Invalid parameters declaration + * @see 49260 + */ +public void testBug49260() { + runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public final class X {\n" + + " int bar(String str, int var, Vector list, char[] array) throws IllegalAccessException { return 0; }\n" + + " /**\n" + + " * Valid method reference on several lines\n" + + " * @see #bar(String str,\n" + + " * int var,\n" + + " * Vector list,\n" + + " * char[] array)\n" + + " */\n" + + " void foo() {}\n" + + "}\n" }); +} + +/** + * Bug 48385. + * When this bug happened, compiler does not complain on CharOperation references in @link tags + * @see 48385 + */ +public void testBug48385() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Method outside javaDoc Comment\n" + + " * 1) {@link String} tag description not empty\n" + + " * 2) {@link CharOperation Label not empty} tag description not empty\n" + + " * @param str\n" + + " * @param var tag description not empty\n" + + " * @param list third param with embedded tag: {@link Vector}\n" + + " * @param array fourth param with several embedded tags on several lines:\n" + + " * 1) {@link String} tag description not empty\n" + + " * 2) {@linkplain CharOperation Label not empty} tag description not empty\n" + + " * @throws IllegalAccessException\n" + + " * @throws NullPointerException tag description not empty\n" + + " * @return an integer\n" + + " * @see String\n" + + " * @see Vector tag description not empty\n" + + " * @see Object tag description includes embedded tags and several lines:\n" + + " * 1) {@link String} tag description not empty\n" + + " * 2) {@link CharOperation Label not empty} tag description not empty\n" + + " */\n" + + " int foo(String str, int var, Vector list, char[] array) throws IllegalAccessException { return 0; }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * 2) {@link CharOperation Label not empty} tag description not empty\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: CharOperation cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " * 2) {@linkplain CharOperation Label not empty} tag description not empty\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: CharOperation cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 20)\n" + + " * 2) {@link CharOperation Label not empty} tag description not empty\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: CharOperation cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +public void testBug48385And49620() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Method outside javaDoc Comment\n" + + " * 1) {@link\n" + + " * String} tag description not empty\n" + + " * 2) {@link\n" + + " * CharOperation Label not empty} tag description not empty\n" + + " * @param\n" + + " * str\n" + + " * @param\n" + + " * var tag description not empty\n" + + " * @param list third param with embedded tag: {@link\n" + + " * Vector} but also on several lines: {@link\n" + + " * CharOperation}\n" + + " * @param array fourth param with several embedded tags on several lines:\n" + + " * 1) {@link String} tag description not empty\n" + + " * 2) {@link CharOperation Label not empty} tag description not empty\n" + + " * @throws\n" + + " * IllegalAccessException\n" + + " * @throws\n" + + " * NullPointerException tag description not empty\n" + + " * @return\n" + + " * an integer\n" + + " * @see\n" + + " * String\n" + + " * @see\n" + + " * Vector\n" + + " * tag description not empty\n" + + " * @see Object tag description includes embedded tags and several lines:\n" + + " * 1) {@link String} tag description not empty\n" + + " * 2) {@link CharOperation Label not empty} tag description not empty\n" + + " */\n" + + " int foo(String str, int var, Vector list, char[] array) throws IllegalAccessException { return 0; }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " * CharOperation Label not empty} tag description not empty\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: CharOperation cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " * CharOperation}\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: CharOperation cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " * 2) {@link CharOperation Label not empty} tag description not empty\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: CharOperation cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 32)\n" + + " * 2) {@link CharOperation Label not empty} tag description not empty\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: CharOperation cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug48385a() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Method outside javaDoc Comment\n" + + " * 1) {@link } Missing reference\n" + + " * 2) {@link Unknown} Cannot be resolved\n" + + " * 3) {@link *} Missing reference\n" + + " * 4) {@link #} Invalid reference\n" + + " * 5) {@link String } } Valid reference\n" + + " * 6) {@link String {} Invalid tag\n" + + " * @return int\n" + + " */\n" + + " int foo() {return 0;}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * 1) {@link } Missing reference\n" + + " ^^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * 2) {@link Unknown} Cannot be resolved\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * 3) {@link *} Missing reference\n" + + " ^^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " * 4) {@link #} Invalid reference\n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " * 6) {@link String {} Invalid tag\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 49491. + * When this bug happened, compiler complained on duplicated throws tag + * @see 49491 + */ +public void testBug49491() { + runConformTest( + new String[] { + "X.java", + "public final class X {\n" + + " /**\n" + + " * Now valid duplicated throws tag\n" + + " * @throws IllegalArgumentException First comment\n" + + " * @throws IllegalArgumentException Second comment\n" + + " * @throws IllegalArgumentException Last comment\n" + + " */\n" + + " void foo() throws IllegalArgumentException {}\n" + + "}\n" }); +} +public void testBug49491a() { + runNegativeTest( + new String[] { + "X.java", + "public final class X {\n" + + " /**\n" + + " * Duplicated param tags should be still flagged\n" + + " * @param str First comment\n" + + " * @param str Second comment\n" + + " * @param str Last comment\n" + + " */\n" + + " void foo(String str) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param str Second comment\n" + + " ^^^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param str Last comment\n" + + " ^^^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 48376. + * When this bug happened, compiler complained on duplicated throws tag + * @see 48376 + */ +public void testBug48376() { + runConformTest( + new String[] { + "X.java", + "/**\n" + + " * @see IBM Home Page\n" + + " * @see \n" + + " * IBM Home Page\n" + + " * @see \n" + + " * IBM Home Page\n" + + " * \n" + + " * @see \n" + + " *\n" + + " * IBM\n" + + " *\n" + + " * Home Page\n" + + " *\n" + + " *\n" + + " * \n" + + " * @see Object\n" + + " */\n" + + "public class X {\n" + + "}\n" + }); +} +public void testBug48376a() { + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @see IBM Home Page\n" + + " * @see \n" + + " * IBM Home Page\n" + + " * @see \n" + + " * IBM Home Page<\n" + + " * /a>\n" + + " * @see \n" + + " *\n" + + " * IBM\n" + + " *\n" + + " * Home Page\n" + + " *\n" + + " *\n" + + " * \n" + + " * @see Unknown\n" + + " */\n" + + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " * @see IBM Home Page\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " * @see \n" + + " * IBM Home Page\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * IBM Home Page<\n" + + " ^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see \n" + + " *\n" + + " * IBM\n" + + " *\n" + + " * Home Page\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "5. ERROR in X.java (at line 16)\n" + + " * @see Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 50644. + * When this bug happened, compiler complained on duplicated throws tag + * @see 50644 + */ +public void testBug50644() { + this.reportInvalidJavadoc = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " /**\n" + + " * Should not be @deprecated\n" + + " */\n" + + " public void foo() {}\n" + + "}\n", + "p2/Y.java", + "package p2;\n" + + "import p1.X;\n" + + "public class Y {\n" + + " public void foo() {\n" + + " X x = new X();\n" + + " x.foo();\n" + + " }\n" + + "}\n" + }); +} + +/** + * Bug 50695. + * @see 50695 + */ +public void testBug50695() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see java\n" + + " * @see java.util\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + }); +} +public void testBug50695b() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see java.unknown\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @see java.unknown\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: java.unknown cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 51626. + * @see 51626 + */ +public void testBug51626() { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " /**\n" + + " * @see String\n" + + " * toto @deprecated\n" + + " */\n" + + " public void foo() {}\n" + + "}\n", + "p2/Y.java", + "package p2;\n" + + "import p1.*;\n" + + "public class Y {\n" + + " void foo() {\n" + + " X x = new X(); \n" + + " x.foo();\n" + + " }\n" + + "}\n" + }); +} + +/** + * Bug 52216. + * @see 52216 + */ +public void testBug52216() { + runConformTest( + new String[] { + "X.java", + "/**\n" + + " * Valid ref with white spaces at the end\n" + + "* @see RFC 2045 - Section 6.8 \n" + + "*/\n" + + "public class X {\n" + + "}\n" + }); +} +public void testBug52216a() { + runConformTest( + new String[] { + "X.java", + "/**\n" + + "* @see \"Valid ref with white spaces at the end\" \n" + + "*/\n" + + "public class X {\n" + + "}\n" + }); +} +public void testBug52216b() { + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + "* @see RFC 2045 - Section 6.8 \n" + + "* @see RFC 2045 - Section 6.8\n" + + "* @see RFC 2045 - Section 6.8 ,\n" + + "* @see \"Valid ref with white spaces at the end\"\n" + + "* @see \"Valid ref with white spaces at the end\" \n" + + "* @see \"Invalid ref\" .\n" + + "*/\n" + + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see RFC 2045 - Section 6.8 ,\n" + + " ^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @see \"Invalid ref\" .\n" + + " ^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 51529. + * @see 51529 + */ +public void testBug51529() { + runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * @see Vector\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + }); +} +public void testBug51529a() { + this.reportInvalidJavadoc = CompilerOptions.IGNORE; + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * @see Vector\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + } + ); +} +public void testBug51529b() { + this.docCommentSupport = CompilerOptions.DISABLED; + runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * @see Vector\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import java.util.Vector;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The import java.util.Vector is never used\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * @bug 51911: [Javadoc] @see method w/out () + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=51911" + */ +// Conform since bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=191322 has been fixed +public void testBug51911() { + // Warn an ambiguous method reference + runConformTest( + new String[] { + "X.java", + "/**\n" + + " * @see #foo\n" + + " */\n" + + "public class X {\n" + + " public void foo(int i, float f) {}\n" + + " public void foo(String str) {}\n" + + "}\n" + } + ); +} +public void testBug51911a() { + // Accept unambiguous method reference + runConformTest( + new String[] { + "X.java", + "/**\n" + + " * @see #foo\n" + + " */\n" + + "public class X {\n" + + " public void foo(String str) {}\n" + + "}\n" + } + ); +} +public void testBug51911b() { + // Accept field reference with method name + runConformTest( + new String[] { + "X.java", + "/**\n" + + " * @see #foo\n" + + " */\n" + + "public class X {\n" + + " public int foo;\n" + + " public void foo(String str) {}\n" + + "}\n" + } + ); +} +public void testBug51911c() { + // Accept field reference with ambiguous method name + runConformTest( + new String[] { + "X.java", + "/**\n" + + " * @see #foo\n" + + " */\n" + + "public class X {\n" + + " public int foo;\n" + + " public void foo() {}\n" + + " public void foo(String str) {}\n" + + "}\n" + } + ); +} + +/** + * Bug 53279: [Javadoc] Compiler should complain when inline tag is not terminated + * @see 53279 + */ +public void testBug53279() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Unterminated inline tags\n" + + " * {@link Object\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * {@link Object\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug53279a() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Unterminated inline tags\n" + + " * {@link Object\n" + + " * @return int\n" + + " */\n" + + " int foo() {return 0;}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * {@link Object\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug53279b() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Unterminated inline tags\n" + + " * {@link \n" + + " */\n" + + " void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * {@link \n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * {@link \n" + + " ^^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug53279c() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Unterminated inline tags\n" + + " * {@link\n" + + " * @return int\n" + + " */\n" + + " int foo() {return 0;}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * {@link\n" + + " ^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * {@link\n" + + " ^^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 53290: [Javadoc] Compiler should complain when tag name is not correct + * @see 53290 + */ +public void testBug53290() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * See as inline tag\n" + + " * {@see Object}\n" + + " * @see Object\n" + + " * @link Object\n" + + " * {@link Object}\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * {@see Object}\n" + + " ^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @link Object\n" + + " ^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 62812: Some malformed javadoc tags are not reported as malformed + * @see 62812 + */ +public void testBug62812() { + runNegativeTest( + new String[] { + "Test.java", + "/**\n" + + " * @see Object#clone())\n" + + " * @see Object#equals(Object)}\n" + + " * @see Object#equals(Object))\n" + + " * @see Object#equals(Object)xx\n" + + " */\n" + + "public class Test {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Object#clone())\n" + + " ^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Object#equals(Object)}\n" + + " ^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "3. ERROR in Test.java (at line 4)\n" + + " * @see Object#equals(Object))\n" + + " ^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "4. ERROR in Test.java (at line 5)\n" + + " * @see Object#equals(Object)xx\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug62812a() { + runNegativeTest( + new String[] { + "Test.java", + "/**\n" + + " * {@link Object#clone())}\n" + + " * {@link Object#equals(Object)}\n" + + " * {@link Object#equals(Object))}\n" + + " * {@link Object#equals(Object)xx}\n" + + " */\n" + + "public class Test {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * {@link Object#clone())}\n" + + " ^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 4)\n" + + " * {@link Object#equals(Object))}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "3. ERROR in Test.java (at line 5)\n" + + " * {@link Object#equals(Object)xx}\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 51606: [Javadoc] Compiler should complain when tag name is not correct + * @see 51606 + */ +// Cleaned up this test as part of fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=247037 +// We should not complain about the missing @param tag for Y.foo at all, since the comments are +// automatically inherited. +public void testBug51606() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @param a aaa\n" + + " * @param b bbb\n" + + " */\n" + + " public void foo(int a, int b) {\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " /**\n" + + " * @param a {@inheritDoc}\n" + + " */\n" + + " public void foo(int a, int b) {\n" + + " }\n" + + "}\n" + }, + "" + ); +} +public void testBug51606a() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @param a aaa\n" + + " * @param b bbb\n" + + " */\n" + + " public void foo(int a, int b) {\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " /**\n" + + " * {@inheritDoc}\n" + + " * @param a aaaaa\n" + + " */\n" + + " public void foo(int a, int b) {\n" + + " }\n" + + "}\n" + }, + "" + ); +} +public void testBug51606b() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @param a aaa\n" + + " * @param b bbb\n" + + " */\n" + + " public void foo(int a, int b) {\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " /**\n" + + " * Text before inherit tag\n" + + " * {@inheritDoc}\n" + + " * @param a aaaaa\n" + + " */\n" + + " public void foo(int a, int b) {\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug51606c() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @param a aaa\n" + + " * @param b bbb\n" + + " */\n" + + " public void foo(int a, int b) {\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " /**\n" + + " * Text before inherit tag {@inheritDoc}\n" + + " * @param a aaaaa\n" + + " */\n" + + " public void foo(int a, int b) {\n" + + " }\n" + + "}\n" + } + ); +} + +/** + * Bug 65174: Spurious "Javadoc: Missing reference" error + * @see 65174 + */ +public void testBug65174() { + runConformTest( + new String[] { + "Test.java", + "/**\n" + + " * Comment with no error: {@link\n" + + " * Object valid} because it\'s not on first line\n" + + " */\n" + + "public class Test {\n" + + " /** Comment previously with error: {@link\n" + + " * Object valid} because tag is on comment very first line\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + } + ); +} +public void testBug65174a() { + runConformTest( + new String[] { + "Test.java", + "/**\n" + + " * Comment with no error: {@link \n" + + " * Object valid} because it\'s not on first line\n" + + " */\n" + + "public class Test {\n" + + " /** Comment previously with error: {@link \n" + + " * Object valid} because tag is on comment very first line\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + } + ); +} +public void testBug65174b() { + runNegativeTest( + new String[] { + "Test.java", + "/**\n" + + " * Comment with no error: {@link java.lang.\n" + + " * Object valid} because it\'s not on first line\n" + + " */\n" + + "public class Test {\n" + + " /** Comment previously with error: {@link java.lang.\n" + + " * Object valid} because tag is on comment very first line\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\r\n" + + " * Comment with no error: {@link java.lang.\r\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in Test.java (at line 6)\r\n" + + " /** Comment previously with error: {@link java.lang.\r\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + ); +} +public void testBug65174c() { + runConformTest( + new String[] { + "Test.java", + "/**\n" + + " * Comment with no error: {@link Object\n" + + " * valid} because it\'s not on first line\n" + + " */\n" + + "public class Test {\n" + + " /** Comment previously with no error: {@link Object\n" + + " * valid} because tag is on comment very first line\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + } + ); +} +public void testBug65174d() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " /** Comment previously with no error: {@link Object valid} comment on one line */\n" + + " void foo1() {}\n" + + " /** Comment previously with no error: {@link Object valid} */\n" + + " void foo2() {}\n" + + " /** Comment previously with no error: {@link Object valid}*/\n" + + " void foo3() {}\n" + + " /** {@link Object valid} comment on one line */\n" + + " void foo4() {}\n" + + " /**{@link Object valid} comment on one line */\n" + + " void foo5() {}\n" + + " /** {@link Object valid} */\n" + + " void foo6() {}\n" + + " /**{@link Object valid} */\n" + + " void foo7() {}\n" + + " /** {@link Object valid}*/\n" + + " void foo8() {}\n" + + " /**{@link Object valid}*/\n" + + " void foo9() {}\n" + + "}\n" + } + ); +} + +/** + * @bug 65180: Spurious "Javadoc: xxx cannot be resolved or is not a field" error with inner classes + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=65180" + */ + // Conform since bug "http://bugs.eclipse.org/bugs/show_bug.cgi?id=191322" has been fixed +public void testBug65180() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * Does something.\n" + + " * \n" + + " * @see #testFunc\n" + + " */\n" + + " public void innerFunc() {\n" + + " testFunc();\n" + + " }\n" + + " }\n" + + " \n" + + " public void testFunc() {}\n" + + "}\n" + + "\n" + } + ); +} +public void testBug65180a() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * Does something.\n" + + " * \n" + + " * @see #testFunc()\n" + + " */\n" + + " public void innerFunc() {\n" + + " testFunc();\n" + + " }\n" + + " }\n" + + " \n" + + " public void testFunc() {}\n" + + "}\n" + } + ); +} +public void testBug65180b() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * Does something.\n" + + " * \n" + + " * @see Test#testFunc\n" + + " * @see Test#testFunc()\n" + + " */\n" + + " public void innerFunc() {\n" + + " testFunc();\n" + + " }\n" + + " }\n" + + " \n" + + " public void testFunc() {}\n" + + "}\n" + } + ); +} + // Conform since bug "http://bugs.eclipse.org/bugs/show_bug.cgi?id=191322" has been fixed +public void testBug65180c() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * Does something.\n" + + " * \n" + + " * @see #testFunc\n" + + " */\n" + + " public void innerFunc() {\n" + + " testFunc();\n" + + " }\n" + + " }\n" + + " \n" + + " public void testFunc() {}\n" + + " public void testFunc(String str) {}\n" + + "}\n" + } + ); +} +public void testBug65180d() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " int testField;\n" + + " public class Inner {\n" + + " /**\n" + + " * Does something.\n" + + " * \n" + + " * @see #testField\n" + + " * @see #testFunc(int)\n" + + " */\n" + + " public void innerFunc() {\n" + + " testFunc(testField);\n" + + " }\n" + + " }\n" + + " \n" + + " public void testFunc(int test) {\n" + + " testField = test; \n" + + " }\n" + + "}\n" + } + ); +} +public void testBug65180e() { + runConformTest( + new String[] { + "ITest.java", + "public interface ITest {\n" + + " /**\n" + + " * @see #foo() \n" + + " */\n" + + " public static int field = 0;\n" + + " /**\n" + + " * @see #field\n" + + " */\n" + + " public void foo();\n" + + "}\n" + } + ); +} +public void testBug65180f() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static class SuperInner {\n" + + " public int field;\n" + + " public void foo() {}\n" + + " }\n" + + " \n" + + " public static class Inner extends SuperInner {\n" + + " /**\n" + + " * @see #field\n" + + " */\n" + + " public static int f;\n" + + " /**\n" + + " * @see #foo()\n" + + " */\n" + + " public static void bar() {}\n" + + " }\n" + + " \n" + + " public void foo() {}\n" + + "}" + } + ); +} + +/** + * @bug 65253: [Javadoc] @@tag is wrongly parsed as @tag + * @test Verify that @@return is not interpreted as a return tag
+ * Note that since fix for bug 237742, the '@' in a tag name does no longer + * flag it as invalid... + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=65253" + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=237742" + */ +public void testBug65253() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "Test.java", + "/**\n" + + " * Comment \n" + + " * @@@@see Unknown Should not complain on ref\n" + + " */\n" + + "public class Test {\n" + + " /**\n" + + " * Comment\n" + + " * @@@param xxx Should not complain on param\n" + + " * @@return int\n" + + " */\n" + + " int foo() { // should warn on missing tag for return type\n" + + " return 0;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 11)\n" + + " int foo() { // should warn on missing tag for return type\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 66551: Error in org.eclipse.swt project on class PrinterData + * @see 66551 + */ +public void testBug66551() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " int field;\n" + + " /**\n" + + " * @see #field\n" + + " */\n" + + " void foo(int field) {\n" + + " }\n" + + "\n" + + "}\n" + } + ); +} +public void testBug66551a() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static int field;\n" + + " /**\n" + + " * @see #field\n" + + " */\n" + + " static void foo(int field) {\n" + + " }\n" + + "\n" + + "}\n" + } + ); +} +public void testBug66551b() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " int field;\n" + + " /**\n" + + " * {@link #field}\n" + + " */\n" + + " void foo(int field) {\n" + + " }\n" + + "\n" + + "}\n" + } + ); +} +public void testBug66551c() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static int field;\n" + + " /**\n" + + " * {@link #field}\n" + + " */\n" + + " static void foo(int field) {\n" + + " }\n" + + "\n" + + "}\n" + } + ); +} + +/** + * Bug 66573: Shouldn't bind to local constructs + * @see 66573 + */ +public void testBug66573() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " /**\n" + + " * @see Local\n" + + " */\n" + + " void foo() {\n" + + " class Local { \n" + + " // shouldn\'t be seen from javadoc\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 3)\n" + + " * @see Local\n" + + " ^^^^^\n" + + "Javadoc: Local cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 68017: Javadoc processing does not detect missing argument to @return + * @see 68017 + */ +public void testBug68017conform() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**@return valid integer*/\n" + + " public int foo1() {return 0; }\n" + + " /**\n" + + " * @return #\n" + + " */\n" + + " public int foo2() {return 0; }\n" + + "}\n", + } + ); +} +public void testBug68017negative() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**@return*/\n" + + " public int foo1() {return 0; }\n" + + " /**@return */\n" + + " public int foo2() {return 0; }\n" + + " /**@return****/\n" + + " public int foo3() {return 0; }\n" + + " /**\n" + + " * @return\n" + + " */\n" + + " public int foo4() {return 0; }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " /**@return*/\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " /**@return */\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " /**@return****/\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +// Javadoc issue a warning on following tests +public void testBug68017javadocWarning1() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @return* */\n" + + " public int foo1() {return 0; }\n" + + " /**@return** **/\n" + + " public int foo2() {return 0; }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @return* */\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " /**@return** **/\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug68017javadocWarning2() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @return #\n" + + " */\n" + + " public int foo1() {return 0; }\n" + + " /**\n" + + " * @return @\n" + + " */\n" + + " public int foo2() {return 0; }\n" + + "}\n" + } + ); +} +public void testBug68017javadocWarning3() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @return#\n" + + " * @return#text\n" + + " */\n" + + " public int foo() {return 0; }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @return#\n" + + " ^^^^^^^\n" + + "Javadoc: Invalid tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @return#text\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Invalid tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 68025: Javadoc processing does not detect some wrong links + * @see 68025 + */ +public void testBug68025conform() { + runConformTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public int field;\n" + + " public void foo() {}\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /**\n" + + " * @see Y#field #valid\n" + + " * @see Y#foo #valid\n" + + " */\n" + + " public void foo1() {}\n" + + " /**@see Y#field # valid*/\n" + + " public void foo2() {}\n" + + " /**@see Y#foo # valid*/\n" + + " public void foo3() {}\n" + + " /**@see Y#foo()\n" + + " *# valid*/\n" + + " public void foo4() {}\n" + + "}\n" + } + ); +} +public void testBug68025negative() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public int field;\n" + + " public void foo() {}\n" + + " /**\n" + + " * @see #field#invalid\n" + + " * @see #foo#invalid\n" + + " */\n" + + " public void foo1() {}\n" + + " /**@see Y#field# invalid*/\n" + + " public void foo2() {}\n" + + " /**@see Y#foo# invalid*/\n" + + " public void foo3() {}\n" + + " /**@see Y#foo()#\n" + + " *valid*/\n" + + " public void foo4() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #field#invalid\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see #foo#invalid\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " /**@see Y#field# invalid*/\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " /**@see Y#foo# invalid*/\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " /**@see Y#foo()#\n" + + " ^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 68726: [Javadoc] Target attribute in @see link triggers warning + * @see 68726 + */ +public void testBug68726conform1() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see Object Eclipse\n" + + " */\n" + + " void foo1() {}\n" + + " /**@see Object Eclipse*/\n" + + " void foo2() {}\n" + + "}\n" + } + ); +} +public void testBug68726conform2() { + runConformTest( + new String[] { + "X.java", + "/**\n" + + " * @see IBM Home Page\n" + + " * @see \n" + + " * IBM Home Page\n" + + " * @see \n" + + " * IBM Home Page\n" + + " * \n" + + " * @see \n" + + " *\n" + + " * IBM\n" + + " *\n" + + " * Home Page\n" + + " *\n" + + " *\n" + + " * \n" + + " * @see Object\n" + + " */\n" + + "public class X {\n" + + "}\n" + } + ); +} +public void testBug68726negative1() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid URL link references\n" + + " *\n" + + " * @see \n" + + " * @see \n" + + " * @see invalid\n" + + " * @see invalid<\n" + + " * @see invalidinvalidinvalid no text allowed after the href\n" + + " */\n" + + " void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " * @see \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "8. ERROR in X.java (at line 12)\n" + + " * @see invalid\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "9. ERROR in X.java (at line 13)\n" + + " * @see invalid<\n" + + " ^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "10. ERROR in X.java (at line 14)\n" + + " * @see invalidinvalidinvalid no text allowed after the href\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug68726negative2() { + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @see IBM Home Page\n" + + " * @see \n" + + " * IBM Home Page\n" + + " * @see \n" + + " * IBM Home Page<\n" + + " * /a>\n" + + " * @see \n" + + " *\n" + + " * IBM\n" + + " *\n" + + " * Home Page\n" + + " *\n" + + " *\n" + + " * \n" + + " * @see Unknown\n" + + " */\n" + + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " * @see IBM Home Page\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " * @see \n" + + " * IBM Home Page\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * IBM Home Page<\n" + + " ^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see \n" + + " *\n" + + " * IBM\n" + + " *\n" + + " * Home Page\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "5. ERROR in X.java (at line 16)\n" + + " * @see Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 69272: [Javadoc] Invalid malformed reference (missing separator) + * @see 69272 + */ +public void testBug69272classValid() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**@see Object*/\n" + + " public void foo1() {}\n" + + " /**@see Object\n" + + " */\n" + + " public void foo2() {}\n" + + " /**@see Object */\n" + + " public void foo3() {}\n" + + " /**@see Object****/\n" + + " public void foo4() {}\n" + + " /**@see Object ****/\n" + + " public void foo5() {}\n" + + "}\n" + } + ); +} +public void testBug69272classInvalid() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**@see Object* */\n" + + " public void foo1() {}\n" + + " /**@see Object*** ***/\n" + + " public void foo2() {}\n" + + " /**@see Object***\n" + + " */\n" + + " public void foo3() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " /**@see Object* */\n" + + " ^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " /**@see Object*** ***/\n" + + " ^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " /**@see Object***\n" + + " ^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug69272fieldValid() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int field;\n" + + " /**@see #field*/\n" + + " public void foo1() {}\n" + + " /**@see #field\n" + + " */\n" + + " public void foo2() {}\n" + + " /**@see #field */\n" + + " public void foo3() {}\n" + + " /**@see #field****/\n" + + " public void foo4() {}\n" + + " /**@see #field ********/\n" + + " public void foo5() {}\n" + + "}\n" + } + ); +} +public void testBug69272fieldInvalid() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int field;\n" + + " /**@see #field* */\n" + + " public void foo1() {}\n" + + " /**@see #field*** ***/\n" + + " public void foo2() {}\n" + + " /**@see #field***\n" + + " */\n" + + " public void foo3() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " /**@see #field* */\n" + + " ^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " /**@see #field*** ***/\n" + + " ^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " /**@see #field***\n" + + " ^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug69272methodValid() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**@see Object#wait()*/\n" + + " public void foo1() {}\n" + + " /**@see Object#wait()\n" + + " */\n" + + " public void foo2() {}\n" + + " /**@see Object#wait() */\n" + + " public void foo3() {}\n" + + " /**@see Object#wait()****/\n" + + " public void foo4() {}\n" + + " /**@see Object#wait() ****/\n" + + " public void foo5() {}\n" + + "}\n" + } + ); +} +public void testBug69272methodInvalid() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**@see Object#wait()* */\n" + + " public void foo1() {}\n" + + " /**@see Object#wait()*** ***/\n" + + " public void foo2() {}\n" + + " /**@see Object#wait()***\n" + + " */\n" + + " public void foo3() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " /**@see Object#wait()* */\n" + + " ^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " /**@see Object#wait()*** ***/\n" + + " ^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " /**@see Object#wait()***\n" + + " ^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 69275: [Javadoc] Invalid warning on @see link + * @see 69275 + */ +public void testBug69275conform() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**@see text*/\n" + + " void foo1() {}\n" + + " /**@see text\n" + + " */\n" + + " void foo2() {}\n" + + " /**@see text */\n" + + " void foo3() {}\n" + + " /**@see text**/\n" + + " void foo4() {}\n" + + " /**@see text *****/\n" + + " void foo5() {}\n" + + "}\n" + } + ); +} +public void testBug69275negative() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**@see text* */\n" + + " void foo1() {}\n" + + " /**@see text ** **/\n" + + " void foo2() {}\n" + + " /**@see text**\n" + + " */\n" + + " void foo3() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " /**@see text* */\n" + + " ^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " /**@see text ** **/\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 69302: [Javadoc] Invalid reference warning inconsistent with javadoc tool + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=69302" + */ +public void testBug69302conform1() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see Object Eclipse\n" + + " */\n" + + " void foo1() {}\n" + + " /**\n" + + " * @see Object \"Valid string reference\"\n" + + " */\n" + + " void foo2() {}\n" + + "}\n" + } + ); +} +public void testBug69302negative1() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see Unknown Eclipse\n" + + " */\n" + + " void foo1() {}\n" + + " /**\n" + + " * @see Unknown \"Valid string reference\"\n" + + " */\n" + + " void foo2() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @see Unknown Eclipse\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @see Unknown \"Valid string reference\"\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug69302negative2() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**@see Unknown blabla text*/\n" + + " void foo1() {}\n" + + " /**@see Unknown blabla \"Valid string reference\"*/\n" + + " void foo2() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " /**@see Unknown blabla text*/\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " /**@see Unknown blabla \"Valid string reference\"*/\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * @bug 70892: [1.5][Javadoc] Compiler should parse reference for inline tag @value + * @test Ensure that reference in tag 'value' is only verified when source level >= 1.5 + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=70892" + */ +public void testBug70892a() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * {@value}\n" + + " */\n" + + " static int field1;\n" + + " /**\n" + + " * {@value }\n" + + " */\n" + + " static int field2;\n" + + " /**\n" + + " * {@value #field}\n" + + " */\n" + + " static int field;\n" + + "}\n" + } + ); +} +public void testBug70892b() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * {@value \"invalid\"}\n" + + " */\n" + + " final static int field1 = 1;\n" + + " /**\n" + + " * {@value invalid} invalid\n" + + " */\n" + + " final static int field2 = 2;\n" + + " /**\n" + + " * {@value #field}\n" + + " */\n" + + " final static int field3 = 3;\n" + + " /**\n" + + " * {@value #foo}\n" + + " */\n" + + " final static int field4 = 4;\n" + + " /**\n" + + " * {@value #foo()}\n" + + " */\n" + + " final static int field5 = 5;\n" + + " void foo() {}\n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runConformTest(testFiles); + } else { + runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " * {@value \"invalid\"}\r\n" + + " ^^^^^^^^^\n" + + "Javadoc: Only static field reference is allowed for @value tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\r\n" + + " * {@value invalid} invalid\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Only static field reference is allowed for @value tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\r\n" + + " * {@value #field}\r\n" + + " ^^^^^\n" + + "Javadoc: field cannot be resolved or is not a field\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\r\n" + + " * {@value #foo}\r\n" + + " ^^^\n" + + "Javadoc: Only static field reference is allowed for @value tag\n" + + "----------\n" + + "5. ERROR in X.java (at line 19)\r\n" + + " * {@value #foo()}\r\n" + + " ^^^^^\n" + + "Javadoc: Only static field reference is allowed for @value tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } +} + +/** + * Bug 73348: [Javadoc] Missing description for return tag is not always warned + * @see 73348 + */ +public void testBug73348conform() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @return \n" + + " * int\n" + + " */\n" + + " public int foo1() {return 0; }\n" + + " /**\n" + + " * @return \n" + + " * int\n" + + " * @see Object\n" + + " */\n" + + " public int foo2() {return 0; }\n" + + "}\n", + } + ); +} +public void testBug73348negative() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @return\n" + + " * @see Object\n" + + " */\n" + + " public int foo1() {return 0; }\n" + + " /**\n" + + " * @return \n" + + " * @see Object\n" + + " */\n" + + " public int foo2() {return 0; }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " * @return \n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * @bug 73352: [Javadoc] Missing description should be warned for all tags + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=73352" + */ +public void testBug73352a() { + String[] units = new String[] { + "X.java", + "/**\n" + + "* @since\n" + + "* @author\n" + + "* @version\n" + + "*/\n" + + "public class X {\n" + + " /**\n" + + " * @param aParam\n" + + " * @return\n" + + " * @see\n" + + " * @since\n" + + " * @throws NullPointerException\n" + + " * @exception NullPointerException\n" + + " * @serial\n" + + " * @serialData\n" + + " * @serialField\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(String aParam) {\n" + + " return new String();\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformTest( + true, + units, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " * @since\n" + + " ^^^^^\n" + + "Javadoc: Description expected after @since\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " * @author\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @author\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " * @version\n" + + " ^^^^^^^\n" + + "Javadoc: Description expected after @version\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " * @param aParam\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after this reference\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " * @see\n" + + " ^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n" + + "7. WARNING in X.java (at line 11)\n" + + " * @since\n" + + " ^^^^^\n" + + "Javadoc: Description expected after @since\n" + + "----------\n" + + "8. WARNING in X.java (at line 12)\n" + + " * @throws NullPointerException\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Description expected after this reference\n" + + "----------\n" + + "9. WARNING in X.java (at line 13)\n" + + " * @exception NullPointerException\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Description expected after this reference\n" + + "----------\n" + + "10. WARNING in X.java (at line 14)\n" + + " * @serial\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @serial\n" + + "----------\n" + + "11. WARNING in X.java (at line 15)\n" + + " * @serialData\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Description expected after @serialData\n" + + "----------\n" + + "12. WARNING in X.java (at line 16)\n" + + " * @serialField\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Description expected after @serialField\n" + + "----------\n" + + "13. WARNING in X.java (at line 17)\n" + + " * @deprecated\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Description expected after @deprecated\n" + + "----------\n", + null, + null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings + ); +} +public void testBug73352b() { + String[] units = new String[] { + "X.java", + "/**\n" + + "* @since 1.0\n" + + "* @author John Doe\n" + + "* @version 1.1\n" + + "*/\n" + + "public class X {\n" + + " /**\n" + + " * @param aParam comment\n" + + " * @return String\n" + + " * @see String\n" + + " * @since 1.1\n" + + " * @throws NullPointerException an exception\n" + + " * @exception NullPointerException an exception\n" + + " * @serial aSerial\n" + + " * @serialData aSerialData\n" + + " * @serialField aSerialField\n" + + " * @deprecated use another method\n" + + " */\n" + + " public String foo(String aParam) {\n" + + " return new String();\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformTest(units); +} +public void testBug73352c() { + String[] units = new String[] { + "X.java", + "/**\n" + + "* @since\n" + + "* @author\n" + + "* @version\n" + + "*/\n" + + "public class X {\n" + + " /**\n" + + " * @param aParam\n" + + " * @return\n" + + " * @see\n" + + " * @since\n" + + " * @throws NullPointerException\n" + + " * @exception NullPointerException\n" + + " * @serial\n" + + " * @serialData\n" + + " * @serialField\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(String aParam) {\n" + + " return new String();\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + this.reportMissingJavadocDescription = CompilerOptions.RETURN_TAG; + runConformTest( + true, + units, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " * @see\n" + + " ^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n", + null, + null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings + ); +} + +public void testBug73352d() { + String[] units = new String[] { + "X.java", + "/**\n" + + "* @since\n" + + "* @author\n" + + "* @version\n" + + "*/\n" + + "public class X {\n" + + " /**\n" + + " * @param aParam\n" + + " * @return\n" + + " * @see\n" + + " * @since\n" + + " * @throws NullPointerException\n" + + " * @exception NullPointerException\n" + + " * @serial\n" + + " * @serialData\n" + + " * @serialField\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(String aParam) {\n" + + " return new String();\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + this.reportMissingJavadocDescription = CompilerOptions.NO_TAG; + runConformTest(units); +} + +/** + * Bug 73479: [Javadoc] Improve error message for invalid link in @see tags + * @see 73479 + */ +public void testBug73479() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see Java Spec\n" + + " */\n" + + " public void foo() {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @see Java Spec\n" + + " ^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 73995: [Javadoc] Wrong warning for missing return type description for @return {@inheritdoc} + * @see 73995 + */ +public void testBug73995() { + runConformTest( + new String[] { + "X.java", + "public class X extends Base {\n" + + " /**\n" + + " * @return {@link Object} \n" + + " */\n" + + " public int foo1() {return 0; }\n" + + " /** @return {@inheritDoc} */\n" + + " public int foo2() {return 0; }\n" + + " /**\n" + + " * @return\n" + + " * {@unknown_tag}\n" + + " */\n" + + " public int foo3() {return 0; }\n" + + "}\n" + + "class Base {\n" + + "/** return \"The foo2 value\" */" + + "public int foo2(){return 0;}\n" + + "}" + }); +} + +/** + * Bug 74369: [Javadoc] incorrect javadoc in local class + * @see 74369 + */ +public void testBug74369() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public void method() {\n" + + " /**\n" + + " * @see #hsgdfdj\n" + + " */\n" + + " System.out.println(\"println\");\n" + + " class Local {}\n" + + " }\n" + + "}" + } + ); +} +public void testBug74369deprecated() { + runNegativeTest( + new String[] { + "p/Y.java", + "package p;\n" + + "\n" + + "\n" + + "public class Y {\n" + + " /**\n" + + " * @deprecated\n" + + " */\n" + + " public void bar() {}\n" + + "}\n", + "X.java", + "import p.Y;\n" + + "\n" + + "public class X {\n" + + " Object obj = new Object() {\n" + + " public boolean equals(Object o) {\n" + + " /**\n" + + " * @deprecated\n" + + " */\n" + + " System.out.println(\"println\");\n" + + " class Local {\n" + + " void bar() {\n" + + " new Y().bar();\n" + + " }\n" + + " }\n" + + " return super.equals(o);\n" + + " }\n" + + " };\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " new Y().bar();\n" + + " ^^^^^\n" + + "The method bar() from the type Y is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 76324: [Javadoc] Wrongly reports invalid link format in @see and @link + * @see 76324 + */ +public void testBug76324() { + runConformTest( + new String[] { + "X.java", + "\n" + + "/**\n" + + " * Subclasses perform GUI-related work in a dedicated thread. For instructions\n" + + " * on using this class, see\n" + + " * {@link Swing tutorial }\n" + + " * \n" + + " * @see \n" + + " * EDU.oswego.cs.dl.util.concurrent \n" + + " * @see \n" + + " * JDK 6.0 \n" + + " * @author {@link Doug Lea}\n" + + " * @author {@link J?rgen Failenschmid}\n" + + " *\n" + + " * It is assumed that you have read the introductory document\n" + + " * {@link \n" + + " * Internationalization}\n" + + " * and are familiar with \n" + + " */\n" + + "public class X {\n" + + "\n" + + "}\n" + } + ); +} +// URL Link references +public void testBug76324url() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid inline URL link references \n" + + " *\n" + + " * {@link <}\n" + + " * {@link }\n" + + " * {@link invalid}\n" + + " * {@link invalid<}\n" + + " * {@link invalidinvalidinvalid no text allowed after}\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * {@link <}\n" + + " ^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * {@link }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "10. ERROR in X.java (at line 14)\n" + + " * {@link invalid}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "11. ERROR in X.java (at line 15)\n" + + " * {@link invalid<}\n" + + " ^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "12. ERROR in X.java (at line 16)\n" + + " * {@link invalidinvalidinvalid no text allowed after}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +// String references +public void testBug76324string() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Inline string references \n" + + " *\n" + + " * {@link \"}\n" + + " * {@link \"unterminated string}\n" + + " * {@link \"invalid string\"\"}\n" + + " * {@link \"valid string\"}\n" + + " * {@link \"invalid\" no text allowed after the string}\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * {@link \"}\n" + + " ^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * {@link \"unterminated string}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * {@link \"invalid string\"\"}\n" + + " ^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " * {@link \"invalid\" no text allowed after the string}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 77510: [javadoc] compiler wrongly report deprecation when option "process javadoc comments" is not set + * @see 77510 + */ +public void testBug77510enabled() { + runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " /** \\u0009 @deprecated */\n" + + " static int i0009;\n" + + " /** \\u000a @deprecated */\n" + + " static int i000a;\n" + + " /** \\u000b @deprecated */\n" + + " static int i000b;\n" + + " /** \\u000c @deprecated */\n" + + " static int i000c;\n" + + " /** \\u001c @deprecated */\n" + + " static int i001c;\n" + + " /** \\u001d @deprecated */\n" + + " static int i001d;\n" + + " /** \\u001e @deprecated */\n" + + " static int i001e;\n" + + " /** \\u001f @deprecated */\n" + + " static int i001f;\n" + + " /** \\u2007 @deprecated */\n" + + " static int i2007;\n" + + " /** \\u202f @deprecated */\n" + + " static int i202f;\n" + + "}\n", + "X.java", + "public class X {\n" + + " int i0 = A.i0009;\n" + + " int i1 = A.i000a;\n" + + " int i2 = A.i000b;\n" + + " int i3 = A.i000c;\n" + + " int i4 = A.i001c;\n" + + " int i5 = A.i001d;\n" + + " int i6 = A.i001e;\n" + + " int i7 = A.i001f;\n" + + " int i8 = A.i2007;\n" + + " int i9 = A.i202f;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int i0 = A.i0009;\n" + + " ^^^^^\n" + + "The field A.i0009 is deprecated\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " int i1 = A.i000a;\n" + + " ^^^^^\n" + + "The field A.i000a is deprecated\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " int i3 = A.i000c;\n" + + " ^^^^^\n" + + "The field A.i000c is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug77510disabled() { + this.docCommentSupport = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " /** \\u0009 @deprecated */\n" + + " static int i0009;\n" + + " /** \\u000a @deprecated */\n" + + " static int i000a;\n" + + " /** \\u000b @deprecated */\n" + + " static int i000b;\n" + + " /** \\u000c @deprecated */\n" + + " static int i000c;\n" + + " /** \\u001c @deprecated */\n" + + " static int i001c;\n" + + " /** \\u001d @deprecated */\n" + + " static int i001d;\n" + + " /** \\u001e @deprecated */\n" + + " static int i001e;\n" + + " /** \\u001f @deprecated */\n" + + " static int i001f;\n" + + " /** \\u2007 @deprecated */\n" + + " static int i2007;\n" + + " /** \\u202f @deprecated */\n" + + " static int i202f;\n" + + "}\n", + "X.java", + "public class X {\n" + + " int i0 = A.i0009;\n" + + " int i1 = A.i000a;\n" + + " int i2 = A.i000b;\n" + + " int i3 = A.i000c;\n" + + " int i4 = A.i001c;\n" + + " int i5 = A.i001d;\n" + + " int i6 = A.i001e;\n" + + " int i7 = A.i001f;\n" + + " int i8 = A.i2007;\n" + + " int i9 = A.i202f;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int i0 = A.i0009;\n" + + " ^^^^^\n" + + "The field A.i0009 is deprecated\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " int i1 = A.i000a;\n" + + " ^^^^^\n" + + "The field A.i000a is deprecated\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " int i3 = A.i000c;\n" + + " ^^^^^\n" + + "The field A.i000c is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Test bug 77260: [Javadoc] deprecation warning should not be reported when @deprecated tag is set + */ +public void testBug77260() { + runConformTest( + new String[] { + "X.java", + "/** @deprecated */\n" + + "public class X {\n" + + " public int x;\n" + + " public void foo() {}\n" + + "}\n", + "Y.java", + "/**\n" + + " * @see X\n" + + " * @deprecated\n" + + " */\n" + + "public class Y {\n" + + " /** @see X#x */\n" + + " public int x;\n" + + " /** @see X#foo() */\n" + + " public void foo() {}\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * @see X#x\n" + + " * @deprecated\n" + + " */\n" + + " public int x;\n" + + " /**\n" + + " * @see X#foo()\n" + + " * @deprecated\n" + + " */\n" + + " public void foo() {}\n" + + "}\n" } + ); +} +public void testBug77260nested() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ENABLED); + runNegativeTest( + true, + new String[] { + "X.java", + "/** @deprecated */\n" + + "public class X {\n" + + " public int x;\n" + + " public void foo() {}\n" + + "}\n", + "Y.java", + "/**\n" + + " * @see X\n" + + " * @deprecated\n" + + " */\n" + + "public class Y {\n" + + " /** @see X#x */\n" + + " public int x;\n" + + " /** @see X#foo() */\n" + + " public void foo() {}\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * @see X#x\n" + + " * @deprecated\n" + + " */\n" + + " public int x;\n" + + " /**\n" + + " * @see X#foo()\n" + + " * @deprecated\n" + + " */\n" + + " public void foo() {}\n" + + "}\n" }, + null, + options, + "----------\n" + + "1. ERROR in Y.java (at line 2)\n" + + " * @see X\n" + + " ^\n" + + "Javadoc: The type X is deprecated\n" + + "----------\n" + + "2. ERROR in Y.java (at line 6)\n" + + " /** @see X#x */\n" + + " ^\n" + + "Javadoc: The type X is deprecated\n" + + "----------\n" + + "3. ERROR in Y.java (at line 6)\n" + + " /** @see X#x */\n" + + " ^\n" + + "Javadoc: The field X.x is deprecated\n" + + "----------\n" + + "4. ERROR in Y.java (at line 8)\n" + + " /** @see X#foo() */\n" + + " ^\n" + + "Javadoc: The type X is deprecated\n" + + "----------\n" + + "5. ERROR in Y.java (at line 8)\n" + + " /** @see X#foo() */\n" + + " ^^^^^\n" + + "Javadoc: The method foo() from the type X is deprecated\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Z.java (at line 3)\n" + + " * @see X#x\n" + + " ^\n" + + "Javadoc: The type X is deprecated\n" + + "----------\n" + + "2. ERROR in Z.java (at line 3)\n" + + " * @see X#x\n" + + " ^\n" + + "Javadoc: The field X.x is deprecated\n" + + "----------\n" + + "3. ERROR in Z.java (at line 8)\n" + + " * @see X#foo()\n" + + " ^\n" + + "Javadoc: The type X is deprecated\n" + + "----------\n" + + "4. ERROR in Z.java (at line 8)\n" + + " * @see X#foo()\n" + + " ^^^^^\n" + + "Javadoc: The method foo() from the type X is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug77260nested_disabled() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef, CompilerOptions.DISABLED); + runConformTest( + new String[] { + "X.java", + "/** @deprecated */\n" + + "public class X {\n" + + " public int x;\n" + + " public void foo() {}\n" + + "}\n", + "Y.java", + "/**\n" + + " * @see X\n" + + " * @deprecated\n" + + " */\n" + + "public class Y {\n" + + " /** @see X#x */\n" + + " public int x;\n" + + " /** @see X#foo() */\n" + + " public void foo() {}\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * @see X#x\n" + + " * @deprecated\n" + + " */\n" + + " public int x;\n" + + " /**\n" + + " * @see X#foo()\n" + + " * @deprecated\n" + + " */\n" + + " public void foo() {}\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null + ); +} + +/** + * Bug 77602: [javadoc] "Only consider members as visible as" is does not work for syntax error + */ +public void testBug77602() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see\n" + + " * @see UnknownClass\n" + + " */\n" + + " protected void foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @see\n" + + " ^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @see UnknownClass\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: UnknownClass cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug77602_Public() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see\n" + + " * @see UnknownClass\n" + + " */\n" + + " protected void foo() {\n" + + " }\n" + + "}\n" + } + ); +} + +/** + * Bug 78091: [1.5][javadoc] Compiler should accept new 1.5 syntax for @param + * @see 78091 + */ +public void testBug78091() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param xxx.yyy invalid\n" + + " * @param obj(x) invalid\n" + + " */\n" + + " public void foo(int xxx, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param xxx.yyy invalid\n" + + " ^^^^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param obj(x) invalid\n" + + " ^^^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " public void foo(int xxx, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter xxx\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public void foo(int xxx, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 80910: [javadoc] Invalid missing reference warning on @see or @link tags + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=80910" + */ +public void testBug80910() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " int field;\n" + + "\n" + + " /**\n" + + " * @param key\'s toto\n" + + " * @see #field\n" + + " */\n" + + " public void foo(int x) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 5)\n" + + " * @param key\'s toto\n" + + " ^^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 82088: [search][javadoc] Method parameter types references not found in @see/@link tags + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=82088" + */ +public void testBug82088() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " int field;\n" + + "\n" + + " /**\n" + + " * @param key\'s toto\n" + + " * @see #field\n" + + " */\n" + + " public void foo(int x) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 5)\n" + + " * @param key\'s toto\n" + + " ^^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 83285: [javadoc] Javadoc reference to constructor of secondary type has no binding / not found by search + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83285" + */ +public void testBug83285a() { + runConformTest( + new String[] { + "p/A.java", + "package p;\n" + + "class A { }\n" + + "class C {\n" + + " /**\n" + + " * Link {@link #C(String)} was also wrongly warned...\n" + + " */\n" + + " private String fGerman;\n" + + " public C(String german) {\n" + + " fGerman = german;\n" + + " }\n" + + "}" + } + ); +} +public void testBug83285b() { + runConformTest( + new String[] { + "p/A.java", + "package p;\n" + + "class A {\n" + + " A(char c) {}\n" + + "}\n" + + "class B {\n" + + " B(Exception ex) {}\n" + + " void foo() {} \n" + + " class C { \n" + + " /**\n" + + " * Link {@link #B(Exception)} OK\n" + + " * Link {@link #B.C(String)} OK\n" + + " * Link {@link #foo()} OK\n" + + " * Link {@link #bar()} OK\n" + + " */\n" + + " public C(String str) {}\n" + + " void bar() {}\n" + + " }\n" + + "}" + } + ); +} +public void testBug83285c() { + runNegativeTest( + new String[] { + "p/A.java", + "package p;\n" + + "class A {\n" + + " A(char c) {}\n" + + "}\n" + + "class B {\n" + + " B(Exception ex) {}\n" + + " void foo() {}\n" + + " class C { \n" + + " /**\n" + + " * Link {@link #A(char)} KO\n" + + " * Link {@link #B(char)} KO\n" + + " * Link {@link #C(char)} KO\n" + + " * Link {@link #foo(int)} KO\n" + + " * Link {@link #bar(int)} KO\n" + + " */\n" + + " public C(String str) {}\n" + + " void bar() {}\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p\\A.java (at line 10)\n" + + " * Link {@link #A(char)} KO\n" + + " ^\n" + + "Javadoc: The method A(char) is undefined for the type B.C\n" + + "----------\n" + + "2. ERROR in p\\A.java (at line 11)\n" + + " * Link {@link #B(char)} KO\n" + + " ^\n" + + "Javadoc: The method B(char) is undefined for the type B.C\n" + + "----------\n" + + "3. ERROR in p\\A.java (at line 12)\n" + + " * Link {@link #C(char)} KO\n" + + " ^^^^^^^\n" + + "Javadoc: The constructor B.C(char) is undefined\n" + + "----------\n" + + "4. ERROR in p\\A.java (at line 13)\n" + + " * Link {@link #foo(int)} KO\n" + + " ^^^\n" + + "Javadoc: The method foo(int) is undefined for the type B.C\n" + + "----------\n" + + "5. ERROR in p\\A.java (at line 14)\n" + + " * Link {@link #bar(int)} KO\n" + + " ^^^\n" + + "Javadoc: The method bar() in the type B.C is not applicable for the arguments (int)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 86769: [javadoc] Warn/Error for 'Missing javadoc comments' doesn't recognize private inner classes + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=86769" + */ +public void testBug86769_Classes1() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PROTECTED; + runNegativeTest( + new String[] { + "A.java", + "/**\n" + + " * Test bug 86769 \n" + + " */\n" + + "public class A {\n" + + " private class Level1Private {\n" + + " private class Level2_PrivPriv {}\n" + + " class Level2_PrivDef {}\n" + + " protected class Level2_PrivPro {}\n" + + " public class Level2_PrivPub {}\n" + + " }\n" + + " class Level1Default{\n" + + " private class Level2_DefPriv {}\n" + + " class Level2_DefDef {}\n" + + " protected class Level2_DefPro {}\n" + + " public class Level2_DefPub {}\n" + + " }\n" + + " protected class Level1Protected {\n" + + " private class Level2_ProtPriv {}\n" + + " class Level2_ProDef {}\n" + + " protected class Level2_ProPro {}\n" + + " public class Level2_ProPub {} \n" + + " }\n" + + " public class Level1Public {\n" + + " private class Level2_PubPriv {}\n" + + " class Level2_PubDef {}\n" + + " protected class Level2_PubPro {}\n" + + " public class Level2_PubPub {}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 17)\n" + + " protected class Level1Protected {\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n" + + "2. ERROR in A.java (at line 20)\n" + + " protected class Level2_ProPro {}\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n" + + "3. ERROR in A.java (at line 21)\n" + + " public class Level2_ProPub {} \n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n" + + "4. ERROR in A.java (at line 23)\n" + + " public class Level1Public {\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "5. ERROR in A.java (at line 26)\n" + + " protected class Level2_PubPro {}\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n" + + "6. ERROR in A.java (at line 27)\n" + + " public class Level2_PubPub {}\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug86769_Classes2() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.DEFAULT; + runNegativeTest( + new String[] { + "B.java", + "/**\n" + + " * Test bug 86769\n" + + " */\n" + + "public class B {\n" + + " class Level0_Default {\n" + + " private class Level1Private {\n" + + " private class Level2_PrivPriv {}\n" + + " class Level2_PrivDef {}\n" + + " protected class Level2_PrivPro {}\n" + + " public class Level2_PrivPub {}\n" + + " }\n" + + " }\n" + + " public class Level0_Public {\n" + + " class Level1Default{\n" + + " private class Level2_DefPriv {}\n" + + " class Level2_DefDef {}\n" + + " protected class Level2_DefPro {}\n" + + " public class Level2_DefPub {}\n" + + " }\n" + + " }\n" + + " protected class Level0_Protected {\n" + + " protected class Level1Protected {\n" + + " private class Level2_ProtPriv {}\n" + + " class Level2_ProDef {}\n" + + " protected class Level2_ProPro {}\n" + + " public class Level2_ProPub {} \n" + + " }\n" + + " }\n" + + " private class Level0_Private {\n" + + " public class Level1Public {\n" + + " private class Level2_PubPriv {}\n" + + " class Level2_PubDef {}\n" + + " protected class Level2_PubPro {}\n" + + " public class Level2_PubPub {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in B.java (at line 5)\n" + + " class Level0_Default {\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "2. ERROR in B.java (at line 13)\n" + + " public class Level0_Public {\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "3. ERROR in B.java (at line 14)\n" + + " class Level1Default{\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "4. ERROR in B.java (at line 16)\n" + + " class Level2_DefDef {}\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "5. ERROR in B.java (at line 17)\n" + + " protected class Level2_DefPro {}\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "6. ERROR in B.java (at line 18)\n" + + " public class Level2_DefPub {}\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "7. ERROR in B.java (at line 21)\n" + + " protected class Level0_Protected {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n" + + "8. ERROR in B.java (at line 22)\n" + + " protected class Level1Protected {\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n" + + "9. ERROR in B.java (at line 24)\n" + + " class Level2_ProDef {}\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "10. ERROR in B.java (at line 25)\n" + + " protected class Level2_ProPro {}\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n" + + "11. ERROR in B.java (at line 26)\n" + + " public class Level2_ProPub {} \n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug86769_Field1() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "A.java", + "/**\n" + + " * Test bug 86769\n" + + " */\n" + + "public class A {\n" + + " private class InnerPrivate {\n" + + " private int pri_pri;\n" + + " int pri_def;\n" + + " protected int pri_pro;\n" + + " public int pri_pub;\n" + + " }\n" + + " class InnerDefault{\n" + + " private int def_pri;\n" + + " int def_def;\n" + + " protected int def_pro;\n" + + " public int def_pub;\n" + + " }\n" + + " protected class InnerProtected {\n" + + " private int pro_pri;\n" + + " int pro_def;\n" + + " protected int pro_pro;\n" + + " public int pro_pub; \n" + + " }\n" + + " public class InnerPublic {\n" + + " private int pub_pri;\n" + + " int pub_def;\n" + + " protected int pub_pro;\n" + + " public int pub_pub;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 23)\n" + + " public class InnerPublic {\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "2. ERROR in A.java (at line 27)\n" + + " public int pub_pub;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug86769_Fields2() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PRIVATE; + runNegativeTest( + new String[] { + "B.java", + "/**\n" + + " * Test bug 86769\n" + + " */\n" + + "public class B {\n" + + " private class Level1 {\n" + + " private class InnerPrivate {\n" + + " private int pri_pri;\n" + + " int pri_def;\n" + + " protected int pri_pro;\n" + + " public int pri_pub;\n" + + " }\n" + + " class InnerDefault{\n" + + " private int def_pri;\n" + + " int def_def;\n" + + " protected int def_pro;\n" + + " public int def_pub;\n" + + " }\n" + + " protected class InnerProtected {\n" + + " private int pro_pri;\n" + + " int pro_def;\n" + + " protected int pro_pro;\n" + + " public int pro_pub; \n" + + " }\n" + + " public class InnerPublic {\n" + + " private int pub_pri;\n" + + " int pub_def;\n" + + " protected int pub_pro;\n" + + " public int pub_pub;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in B.java (at line 5)\n" + + " private class Level1 {\n" + + " ^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "2. ERROR in B.java (at line 6)\n" + + " private class InnerPrivate {\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "3. ERROR in B.java (at line 7)\n" + + " private int pri_pri;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "4. ERROR in B.java (at line 8)\n" + + " int pri_def;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "5. ERROR in B.java (at line 9)\n" + + " protected int pri_pro;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "6. ERROR in B.java (at line 10)\n" + + " public int pri_pub;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "7. ERROR in B.java (at line 12)\n" + + " class InnerDefault{\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "8. ERROR in B.java (at line 13)\n" + + " private int def_pri;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "9. ERROR in B.java (at line 14)\n" + + " int def_def;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "10. ERROR in B.java (at line 15)\n" + + " protected int def_pro;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "11. ERROR in B.java (at line 16)\n" + + " public int def_pub;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "12. ERROR in B.java (at line 18)\n" + + " protected class InnerProtected {\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "13. ERROR in B.java (at line 19)\n" + + " private int pro_pri;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "14. ERROR in B.java (at line 20)\n" + + " int pro_def;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "15. ERROR in B.java (at line 21)\n" + + " protected int pro_pro;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "16. ERROR in B.java (at line 22)\n" + + " public int pro_pub; \n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "17. ERROR in B.java (at line 24)\n" + + " public class InnerPublic {\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "18. ERROR in B.java (at line 25)\n" + + " private int pub_pri;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "19. ERROR in B.java (at line 26)\n" + + " int pub_def;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "20. ERROR in B.java (at line 27)\n" + + " protected int pub_pro;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "21. ERROR in B.java (at line 28)\n" + + " public int pub_pub;\n" + + " ^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug86769_Metthods1() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "A.java", + "/**\n" + + " * Test bug 86769\n" + + " */\n" + + "public class A {\n" + + " private class InnerPrivate {\n" + + " private void pri_pri() {}\n" + + " void pri_def() {}\n" + + " protected void pri_pro() {}\n" + + " public void pri_pub() {}\n" + + " }\n" + + " class InnerDefault{\n" + + " private void def_pri() {}\n" + + " void def_def() {}\n" + + " protected void def_pro() {}\n" + + " public void def_pub() {}\n" + + " }\n" + + " protected class InnerProtected {\n" + + " private void pro_pri() {}\n" + + " void pro_def() {}\n" + + " protected void pro_pro() {}\n" + + " public void pro_pub() {} \n" + + " }\n" + + " public class InnerPublic {\n" + + " private void pub_pri() {}\n" + + " void pub_def() {}\n" + + " protected void pub_pro() {}\n" + + " public void pub_pub() {}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 23)\n" + + " public class InnerPublic {\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "2. ERROR in A.java (at line 27)\n" + + " public void pub_pub() {}\n" + + " ^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug86769_Methods2() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PROTECTED; + runConformTest( + new String[] { + "B.java", + "/**\n" + + " * Test bug 86769\n" + + " */\n" + + "public class B {\n" + + " private class Level1 {\n" + + " private class InnerPrivate {\n" + + " private void pri_pri() {}\n" + + " void pri_def() {}\n" + + " protected void pri_pro() {}\n" + + " public void pri_pub() {}\n" + + " }\n" + + " class InnerDefault{\n" + + " private void def_pri() {}\n" + + " void def_def() {}\n" + + " protected void def_pro() {}\n" + + " public void def_pub() {}\n" + + " }\n" + + " protected class InnerProtected {\n" + + " private void pro_pri() {}\n" + + " void pro_def() {}\n" + + " protected void pro_pro() {}\n" + + " public void pro_pub() {} \n" + + " }\n" + + " public class InnerPublic {\n" + + " private void pub_pri() {}\n" + + " void pub_def() {}\n" + + " protected void pub_pro() {}\n" + + " public void pub_pub() {}\n" + + " }\n" + + " }\n" + + "}\n" + } + ); +} + +/** + * Bug 87404: [javadoc] Unexpected not defined warning on constructor + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=87404" + */ +public void testBug87404() { + runConformTest( + new String[] { + "p/A.java", + "package p;\n" + + "class A {\n" + + " A(char c) {}\n" + + " class B {\n" + + " B(Exception ex) {}\n" + + " }\n" + + " void foo() {}\n" + + " /**\n" + + " * Link {@link #A(char)} OK \n" + + " * Link {@link #A(String)} OK\n" + + " * Link {@link #foo()} OK\n" + + " * Link {@link #bar()} OK\n" + + " */\n" + + " public A(String str) {}\n" + + " void bar() {}\n" + + "}" + } + ); +} + +/** + * Bug 90302: [javadoc] {@inheritDoc} should be inactive for non-overridden method + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=90302" + */ +public void testBug90302() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @see #foo(String)\n" + + " */\n" + + "public class X {\n" + + " /**\n" + + " * Static method\n" + + " * @param str\n" + + " * @return int\n" + + " * @throws NumberFormatException\n" + + " */\n" + + " static int foo(String str) throws NumberFormatException{\n" + + " return Integer.parseInt(str);\n" + + " }\n" + + "}\n", + "Y.java", + "/**\n" + + " * @see #foo(String)\n" + + " */\n" + + "public class Y extends X { \n" + + " /**\n" + + " * Static method: does not override super\n" + + " * {@inheritDoc}\n" + + " */\n" + + " static int foo(String str) throws NumberFormatException{\n" + + " return Integer.parseInt(str);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 7)\n" + + " * {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in Y.java (at line 9)\n" + + " static int foo(String str) throws NumberFormatException{\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "3. ERROR in Y.java (at line 9)\n" + + " static int foo(String str) throws NumberFormatException{\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter str\n" + + "----------\n" + + "4. ERROR in Y.java (at line 9)\n" + + " static int foo(String str) throws NumberFormatException{\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception NumberFormatException\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug90302b() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}\n", + "Y.java", + "/**\n" + + " * @see #foo(String)\n" + + " */\n" + + "public class Y extends X { \n" + + " /**\n" + + " * Simple method: does not override super\n" + + " * {@inheritDoc}\n" + + " */\n" + + " static int foo(String str) throws NumberFormatException{\n" + + " return Integer.parseInt(str);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 7)\n" + + " * {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in Y.java (at line 9)\n" + + " static int foo(String str) throws NumberFormatException{\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "3. ERROR in Y.java (at line 9)\n" + + " static int foo(String str) throws NumberFormatException{\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter str\n" + + "----------\n" + + "4. ERROR in Y.java (at line 9)\n" + + " static int foo(String str) throws NumberFormatException{\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception NumberFormatException\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 103304: [Javadoc] Wrong reference proposal for inner classes. + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=103304" + */ +public void testBug103304a_public() { + String[] units = new String[] { + "boden/IAFAState.java", + "package boden;\n" + + "public interface IAFAState {\n" + + " public class ValidationException extends Exception {\n" + + " public ValidationException(String variableName, IAFAState subformula) {\n" + + " super(\"Variable \'\"+variableName+\"\' may be unbound in \'\"+subformula+\"\'\");\n" + + " }\n" + + " public void method() {}\n" + + " }\n" + + " /**\n" + + " * Validates a formula for consistent bindings. Bindings are consistent, when at each point in time,\n" + + " * the set of povided variables can be guaranteed to be a superset of the set of required variables.\n" + + " * @throws ValidationException Thrown if a variable is unbound. \n" + + " * @see ValidationException#IAFAState.ValidationException(String, IAFAState)\n" + + " * @see IAFAState.ValidationException#method()\n" + + " * @see ValidationException\n" + + " * {@link ValidationException}\n" + + " */\n" + + " public void validate() throws ValidationException;\n" + + "}\n", + "boden/TestValid.java", + "package boden;\n" + + "import boden.IAFAState.ValidationException;\n" + + "/**\n" + + " * @see ValidationException\n" + + " * @see IAFAState.ValidationException\n" + + " */\n" + + "public class TestValid {\n" + + " /** \n" + + " * @see ValidationException#IAFAState.ValidationException(String, IAFAState)\n" + + " */\n" + + " IAFAState.ValidationException valid1;\n" + + " /**\n" + + " * @see IAFAState.ValidationException#IAFAState.ValidationException(String, IAFAState)\n" + + " */\n" + + " IAFAState.ValidationException valid2;\n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units, + //boden\TestValid.java:8: warning - Tag @see: reference not found: ValidationException + "----------\n" + + "1. ERROR in boden\\TestValid.java (at line 4)\n" + + " * @see ValidationException\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in boden\\TestValid.java (at line 9)\n" + + " * @see ValidationException#IAFAState.ValidationException(String, IAFAState)\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } else { + runConformTest(units); + } +} + +public void testBug103304a_private() { + String[] units = new String[] { + "boden/IAFAState.java", + "package boden;\n" + + "public interface IAFAState {\n" + + " public class ValidationException extends Exception {\n" + + " public ValidationException(String variableName, IAFAState subformula) {\n" + + " super(\"Variable \'\"+variableName+\"\' may be unbound in \'\"+subformula+\"\'\");\n" + + " }\n" + + " public void method() {}\n" + + " }\n" + + " /**\n" + + " * Validates a formula for consistent bindings. Bindings are consistent, when at each point in time,\n" + + " * the set of povided variables can be guaranteed to be a superset of the set of required variables.\n" + + " * @throws ValidationException Thrown if a variable is unbound. \n" + + " * @see ValidationException#IAFAState.ValidationException(String, IAFAState)\n" + + " * @see IAFAState.ValidationException#method()\n" + + " * @see ValidationException\n" + + " * {@link ValidationException}\n" + + " */\n" + + " public void validate() throws ValidationException;\n" + + "}\n", + "boden/TestValid.java", + "package boden;\n" + + "import boden.IAFAState.ValidationException;\n" + + "/**\n" + + " * @see ValidationException\n" + + " * @see IAFAState.ValidationException\n" + + " */\n" + + "public class TestValid {\n" + + " /** \n" + + " * @see ValidationException#IAFAState.ValidationException(String, IAFAState)\n" + + " */\n" + + " IAFAState.ValidationException valid1;\n" + + " /**\n" + + " * @see IAFAState.ValidationException#IAFAState.ValidationException(String, IAFAState)\n" + + " */\n" + + " IAFAState.ValidationException valid2;\n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units, + //boden\TestValid.java:8: warning - Tag @see: reference not found: ValidationException + //boden\TestValid.java:12: warning - Tag @see: reference not found: ValidationException#IAFAState.ValidationException(String, IAFAState) + "----------\n" + + "1. ERROR in boden\\TestValid.java (at line 4)\n" + + " * @see ValidationException\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in boden\\TestValid.java (at line 9)\n" + + " * @see ValidationException#IAFAState.ValidationException(String, IAFAState)\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } else { + runConformTest(units); + } +} + +public void testBug103304b() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + String[] units = new String[] { + "boden/IAFAState.java", + "package boden;\n" + + "public interface IAFAState {\n" + + " public class ValidationException extends Exception {\n" + + " public ValidationException(String variableName, IAFAState subformula) {\n" + + " super(\"Variable \'\"+variableName+\"\' may be unbound in \'\"+subformula+\"\'\");\n" + + " }\n" + + " public void method() {}\n" + + " }\n" + + "}\n", + "boden/TestInvalid1.java", + "package boden;\n" + + "import boden.IAFAState.ValidationException;\n" + + "public class TestInvalid1 {\n" + + " /** \n" + + " * @see ValidationException#ValidationException(String, IAFAState)\n" + + " * @see ValidationException#IAFAState.ValidationException(String, IAFAState)\n" + + " */ \n" + + " IAFAState.ValidationException invalid;\n" + + "}\n", + "boden/TestInvalid2.java", + "package boden;\n" + + "public class TestInvalid2 {\n" + + " /**\n" + + " * @see IAFAState.ValidationException#ValidationException(String, IAFAState)\n" + + " */\n" + + " IAFAState.ValidationException invalid;\n" + + "}\n", + "boden/TestInvalid3.java", + "package boden;\n" + + "import boden.IAFAState.ValidationException;\n" + + "public class TestInvalid3 {\n" + + " /**\n" + + " * @see IAFAState.ValidationException#IAFA.State.ValidationException(String, IAFAState)\n" + + " */\n" + + " IAFAState.ValidationException invalid;\n" + + "}\n", + "boden/TestInvalid4.java", + "package boden;\n" + + "import boden.IAFAState.ValidationException;\n" + + "public class TestInvalid4 {\n" + + " /**\n" + + " * @see IAFAState.ValidationException#IAFAState .ValidationException(String, IAFAState)\n" + + " */\n" + + " IAFAState.ValidationException invalid;\n" + + "}\n" + }; + String errors_14 = new String ( + //boden\TestInvalid1.java:7: warning - Tag @see: reference not found: ValidationException#ValidationException(String, IAFAState) + //boden\TestInvalid1.java:8: warning - Tag @see: reference not found: ValidationException#IAFAState.ValidationException(String, IAFAState) + //boden\TestInvalid2.java:6: warning - Tag @see: can't find ValidationException(String, IAFAState) in boden.IAFAState.ValidationException => bug ID: 4288720 + //boden\TestInvalid3.java:6: warning - Tag @see: can't find IAFA.State.ValidationException(String, IAFAState) in boden.IAFAState.ValidationException + //boden\TestInvalid4.java:6: warning - Tag @see: can't find IAFAState in boden.IAFAState.ValidationException + "----------\n" + + "1. ERROR in boden\\TestInvalid1.java (at line 5)\n" + + " * @see ValidationException#ValidationException(String, IAFAState)\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in boden\\TestInvalid1.java (at line 6)\n" + + " * @see ValidationException#IAFAState.ValidationException(String, IAFAState)\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in boden\\TestInvalid3.java (at line 2)\n"+ + " import boden.IAFAState.ValidationException;\n"+ + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import boden.IAFAState.ValidationException is never used\n"+ + "----------\n"+ + "2. ERROR in boden\\TestInvalid3.java (at line 5)\n" + + " * @see IAFAState.ValidationException#IAFA.State.ValidationException(String, IAFAState)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in boden\\TestInvalid4.java (at line 2)\n"+ + " import boden.IAFAState.ValidationException;\n"+ + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import boden.IAFAState.ValidationException is never used\n"+ + "----------\n"+ + "2. ERROR in boden\\TestInvalid4.java (at line 5)\n" + + " * @see IAFAState.ValidationException#IAFAState .ValidationException(String, IAFAState)\n" + + " ^^^^^^^^^\n" + + "Javadoc: IAFAState cannot be resolved or is not a field\n" + + "----------\n" + ); + String errors_50 = new String ( + //boden\TestInvalid1.java:7: warning - Tag @see: reference not found: ValidationException#ValidationException(String, IAFAState) + //boden\TestInvalid2.java:6: warning - Tag @see: can't find ValidationException(String, IAFAState) in boden.IAFAState.ValidationException => bug ID: 4288720 + //boden\TestInvalid3.java:6: warning - Tag @see: can't find IAFA.State.ValidationException(String, IAFAState) in boden.IAFAState.ValidationException + //boden\TestInvalid4.java:6: warning - Tag @see: can't find IAFAState in boden.IAFAState.ValidationException + "----------\n" + + "1. ERROR in boden\\TestInvalid3.java (at line 2)\n"+ + " import boden.IAFAState.ValidationException;\n"+ + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import boden.IAFAState.ValidationException is never used\n"+ + "----------\n"+ + "2. ERROR in boden\\TestInvalid3.java (at line 5)\n" + + " * @see IAFAState.ValidationException#IAFA.State.ValidationException(String, IAFAState)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in boden\\TestInvalid4.java (at line 2)\n"+ + " import boden.IAFAState.ValidationException;\n"+ + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import boden.IAFAState.ValidationException is never used\n"+ + "----------\n"+ + "2. ERROR in boden\\TestInvalid4.java (at line 5)\n" + + " * @see IAFAState.ValidationException#IAFAState .ValidationException(String, IAFAState)\n" + + " ^^^^^^^^^\n" + + "Javadoc: IAFAState cannot be resolved or is not a field\n" + + "----------\n" + ); + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units, errors_14); + } else { + runNegativeTest(units, errors_50, JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + +} +public void testBug103304c() { + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "public interface Test {\n" + + " public class Level0 {\n" + + " public Level0() {}\n" + + " }\n" + + " public interface Member {\n" + + " public class Level1 {\n" + + " public Level1() {}\n" + + " }\n" + + " }\n" + + "}\n", + "test/C.java", + "package test;\n" + + "public class C {\n" + + " /**\n" + + " * @see Test.Level0#Test.Level0()\n" + + " */\n" + + " Test.Level0 valid = new Test.Level0();\n" + + " /**\n" + + " * @see Test.Level0#Level0()\n" + + " */\n" + + " Test.Level0 invalid = new Test.Level0();\n" + + "}\n" + } + //test\C.java:10: warning - Tag @see: can't find Level0() in test.Test.Level0 => bug ID: 4288720 + ); +} +public void testBug103304d() { + runNegativeTest( + new String[] { + "test/Test.java", + "package test;\n" + + "public interface Test {\n" + + " public class Level0 {\n" + + " public Level0() {}\n" + + " }\n" + + " public interface Member {\n" + + " public class Level1 {\n" + + " public Level1() {}\n" + + " }\n" + + " }\n" + + "}\n", + "test/C2.java", + "package test;\n" + + "public class C2 {\n" + + " /**\n" + + " * @see Test.Member.Level1#Test.Member.Level1()\n" + + " */\n" + + " Test.Member.Level1 valid = new Test.Member.Level1();\n" + + " /**\n" + + " * @see Test.Member.Level1#Level1()\n" + + " */\n" + + " Test.Member.Level1 invalid = new Test.Member.Level1();\n" + + " /**\n" + + " * @see Test.Member.Level1#Test.Level1()\n" + + " */\n" + + " Test.Member.Level1 wrong = new Test.Member.Level1();\n" + + "}\n" + }, + //test\C2.java:10: warning - Tag @see: can't find Level1() in test.Test.Member.Level1 => Bug ID: 4288720 + //test\C2.java:14: warning - Tag @see: can't find Test.Level1() in test.Test.Member.Level1 + "----------\n" + + "1. ERROR in test\\C2.java (at line 12)\n" + + " * @see Test.Member.Level1#Test.Level1()\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug103304e() { + runConformTest( + new String[] { + "implicit/Valid.java", + "package implicit;\n" + + "public interface Valid {\n" + + " public class Level0 {\n" + + " /**\n" + + " * @see #Valid.Level0() Valid\n" + + " */\n" + + " public Level0() {}\n" + + " /**\n" + + " * @see #Valid.Level0(String) Valid\n" + + " */\n" + + " public Level0(String str) {}\n" + + " }\n" + + " public interface Member {\n" + + " public class Level1 {\n" + + " /**\n" + + " * @see #Valid.Member.Level1() Valid\n" + + " */\n" + + " public Level1() {}\n" + + " /**\n" + + " * @see #Valid.Member.Level1(int) Valid\n" + + " */\n" + + " public Level1(int x) {}\n" + + " }\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug103304f() { + runNegativeTest( + new String[] { + "implicit/Invalid.java", + "package implicit;\n" + + "public interface Invalid {\n" + + " public class Level0 {\n" + + " /**\n" + + " * @see #Level0() Invalid\n" + + " */\n" + + " public Level0() {}\n" + + " /**\n" + + " * @see #Level0(String) Invalid\n" + + " */\n" + + " public Level0(String str) {}\n" + + " }\n" + + " public interface Member {\n" + + " public class Level1 {\n" + + " /**\n" + + " * @see #Level1() Invalid\n" + + " * @see #Member.Level1() Invalid\n" + + " * @see #Invalid.Level1() Invalid\n" + + " */\n" + + " public Level1() {}\n" + + " /**\n" + + " * @see #Level1(int) Invalid\n" + + " * @see #Invalid.Level1(int) Invalid\n" + + " * @see #Member.Level1(int) Invalid\n" + + " */\n" + + " public Level1(int x) {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + //implicit\Invalid.java:7: warning - Tag @see: can't find Level0() in implicit.Invalid.Level0 => bug ID: 4288720 + //implicit\Invalid.java:11: warning - Tag @see: can't find Level0(String) in implicit.Invalid.Level0 => bug ID: 4288720 + //implicit\Invalid.java:20: warning - Tag @see: can't find Level1() in implicit.Invalid.Member.Level1 => bug ID: 4288720 + //implicit\Invalid.java:20: warning - Tag @see: can't find Member.Level1() in implicit.Invalid.Member.Level1 + //implicit\Invalid.java:20: warning - Tag @see: can't find Invalid.Level1() in implicit.Invalid.Member.Level1 + //implicit\Invalid.java:26: warning - Tag @see: can't find Level1(int) in implicit.Invalid.Member.Level1 => bug ID: 4288720 + //implicit\Invalid.java:26: warning - Tag @see: can't find Invalid.Level1(int) in implicit.Invalid.Member.Level1 + //implicit\Invalid.java:26: warning - Tag @see: can't find Member.Level1(int) in implicit.Invalid.Member.Level1 + "----------\n" + + "1. ERROR in implicit\\Invalid.java (at line 17)\n" + + " * @see #Member.Level1() Invalid\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in implicit\\Invalid.java (at line 18)\n" + + " * @see #Invalid.Level1() Invalid\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "3. ERROR in implicit\\Invalid.java (at line 23)\n" + + " * @see #Invalid.Level1(int) Invalid\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "4. ERROR in implicit\\Invalid.java (at line 24)\n" + + " * @see #Member.Level1(int) Invalid\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 116464: [javadoc] Unicode tag name are not correctly parsed + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=116464" + */ +public void testBug116464() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @\\u0070\\u0061\\u0072\\u0061\\u006d str xxx\n" + + " */\n" + + " void foo(String str) {}\n" + + "}\n" + } + ); +} + +/** + * @bug 125518: [javadoc] Embedding html in a link placed in a @see JavaDoc tag causes a warning + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=125518" + */ +public void testBug125518a() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see invalid>invalid>invalid>invalid>invalid>\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(true, units, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 5)\n" + + " * @see invalid>\n" + + " ^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +public void testBug125518d() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see invalid>\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(true, units, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 5)\n" + + " * @see invalid>\n" + + " ^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +public void testBug125518e() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see value\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(units); +} + +/** + * Bug 125903: [javadoc] Treat whitespace in javadoc tags as invalid tags + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=125903" + */ +public void testBug125903() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * {@ link java.lang.String}\n" + + " * @ since 2.1\n" + + " */\n" + + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " * {@ link java.lang.String}\n" + + " ^^\n" + + "Javadoc: Invalid tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " * @ since 2.1\n" + + " ^^\n" + + "Javadoc: Invalid tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * Bug 128954: Javadoc problems with category CAT_INTERNAL + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=128954" + */ +public void testBug128954() { + this.reportInvalidJavadoc = CompilerOptions.WARNING; + this.reportDeprecation = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "X.java", //======================== + "public class X {\n" + + " /**\n" + + " * @see p.A#bar()\n" + + " */\n" + + " void foo() {\n" + + " Zork z;\n" + + " }\n" + + "}\n", + "p/A.java", //======================== + "package p;\n" + + "public class A {\n" + + " /** @deprecated */\n" + + " public void bar() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " * @see p.A#bar()\n" + + " ^^^^^\n" + + "[@cat:javadoc] [@sup:javadoc] Javadoc: The method bar() from the type A is deprecated\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "[@cat:type] Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, + null, + false, + true, + true); +} + +/** + * Bug 128954: Javadoc problems with category CAT_INTERNAL - variation + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=128954" + */ +public void testBug128954a() { + this.reportInvalidJavadoc = CompilerOptions.WARNING; + this.reportDeprecation = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " /**\n" + + " * @see p.A#bar()\n" + + " */\n" + + " void foo() {\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " * @see p.A#bar()\n" + + " ^^^\n" + + "[@cat:javadoc] [@sup:javadoc] Javadoc: p cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "[@cat:type] Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, + null, + false, + true, + true); +} + +/** + * Bug 129241: [Javadoc] deprecation warning wrongly reported when ignoring Malformed Javadoc comments + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=129241" + */ +public void testBug129241a() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see p.A#bar\n" + + " */\n" + + " void foo() {}\n" + + "}\n", + "p/A.java", + "package p;\n" + + "/** @deprecated */\n" + + "public class A {\n" + + " void bar() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @see p.A#bar\n" + + " ^^^\n" + + "Javadoc: The type A is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug129241b() { + this.reportDeprecation = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see p.A#bar\n" + + " */\n" + + " void foo() {}\n" + + "}\n", + "p/A.java", + "package p;\n" + + "/** @deprecated */\n" + + "public class A {\n" + + " void bar() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @see p.A#bar\n" + + " ^^^\n" + + "Javadoc: The type A is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug129241c() { + this.reportJavadocDeprecation = CompilerOptions.DISABLED; + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see p.A#bar\n" + + " */\n" + + " void foo() {}\n" + + "}\n", + "p/A.java", + "package p;\n" + + "/** @deprecated */\n" + + "public class A {\n" + + " void bar() {}\n" + + "}\n" + } + ); +} +public void testBug129241d() { + this.reportInvalidJavadoc = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see p.A#bar\n" + + " */\n" + + " void foo() {}\n" + + "}\n", + "p/A.java", + "package p;\n" + + "/** @deprecated */\n" + + "public class A {\n" + + " void bar() {}\n" + + "}\n" + } + ); +} + +/** + * Bug 132813: NPE in Javadoc.resolve(Javadoc.java:196) + log swamped + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=132813" + */ +public void testBug132813() { + runNegativeTest( + new String[] { + "Test.java", + "public class X { \n" + + " /** */ \n" + + " public Test() {}\n" + + " /** */\n" + + " public test() {}\n" + + "}\n" }, + "----------\n" + + "1. ERROR in Test.java (at line 1)\n" + + " public class X { \n" + + " ^\n" + + "The public type X must be defined in its own file\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " public Test() {}\n" + + " ^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "3. ERROR in Test.java (at line 5)\n" + + " public test() {}\n" + + " ^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + ); +} + +/** + * Bug 149013: [javadoc] In latest 3.3 build, there is a javadoc error in org.eclipse.core.resources + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=149013" + */ +public void testBug149013_Private01() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "test1/X.java", + "package test1;\n" + + "public class X {\n" + + " class Inner {\n" + + " class Level2 {\n" + + " class Level3 {}\n" + + " }\n" + + " }\n" + + "}\n", + "test1/Test.java", + "package test1;\n" + + "/**\n" + + " * @see X.Inner\n" + + " * @see X.Inner.Level2\n" + + " * @see X.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {}\n", + } + ); +} +public void testBug149013_Public01() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test1/X.java", + "package test1;\n" + + "public class X {\n" + + " class Inner {\n" + + " class Level2 {\n" + + " class Level3 {}\n" + + " }\n" + + " }\n" + + "}\n", + "test1/Test.java", + "package test1;\n" + + "/**\n" + + " * @see X.Inner\n" + + " * @see X.Inner.Level2\n" + + " * @see X.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {\n" + + "}\n" + }, + //test1\Test.java:7: warning - Tag @see: reference not found: X.Inner + //test1\Test.java:7: warning - Tag @see: reference not found: X.Inner.Level2 + //test1\Test.java:7: warning - Tag @see: reference not found: X.Inner.Level2.Level3 + "----------\n" + + "1. ERROR in test1\\Test.java (at line 3)\n" + + " * @see X.Inner\n" + + " ^^^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + + "----------\n" + + "2. ERROR in test1\\Test.java (at line 4)\n" + + " * @see X.Inner.Level2\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + + "----------\n" + + "3. ERROR in test1\\Test.java (at line 5)\n" + + " * @see X.Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug149013_Private02() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "test1/X.java", + "package test1;\n" + + "public class X {\n" + + " class Inner {\n" + + " class Level2 {\n" + + " class Level3 {}\n" + + " }\n" + + " }\n" + + "}\n", + "test2/Test.java", + "package test2;\n" + + "import test1.X;\n" + + "/**\n" + + " * @see X.Inner\n" + + " * @see X.Inner.Level2\n" + + " * @see X.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {}\n", + }, + //test2\Test.java:10: warning - Tag @see: reference not found: X.Inner + //test2\Test.java:10: warning - Tag @see: reference not found: X.Inner.Level2 + //test2\Test.java:10: warning - Tag @see: reference not found: X.Inner.Level2.Level3 + "----------\n" + + "1. ERROR in test2\\Test.java (at line 4)\r\n" + + " * @see X.Inner\r\n" + + " ^^^^^^^\n" + + "Javadoc: The type X.Inner is not visible\n" + + "----------\n" + + "2. ERROR in test2\\Test.java (at line 5)\r\n" + + " * @see X.Inner.Level2\r\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: The type X.Inner is not visible\n" + + "----------\n" + + "3. ERROR in test2\\Test.java (at line 6)\r\n" + + " * @see X.Inner.Level2.Level3\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type X.Inner is not visible\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug149013_Public02() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test1/X.java", + "package test1;\n" + + "public class X {\n" + + " class Inner {\n" + + " class Level2 {\n" + + " class Level3 {}\n" + + " }\n" + + " }\n" + + "}\n", + "test2/Test.java", + "package test2;\n" + + "import test1.X;\n" + + "/**\n" + + " * @see X.Inner\n" + + " * @see X.Inner.Level2\n" + + " * @see X.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {}\n", + }, + //test2\Test.java:10: warning - Tag @see: reference not found: X.Inner + //test2\Test.java:10: warning - Tag @see: reference not found: X.Inner.Level2 + //test2\Test.java:10: warning - Tag @see: reference not found: X.Inner.Level2.Level3 + "----------\n" + + "1. ERROR in test2\\Test.java (at line 4)\r\n" + + " * @see X.Inner\r\n" + + " ^^^^^^^\n" + + "Javadoc: The type X.Inner is not visible\n" + + "----------\n" + + "2. ERROR in test2\\Test.java (at line 5)\r\n" + + " * @see X.Inner.Level2\r\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: The type X.Inner is not visible\n" + + "----------\n" + + "3. ERROR in test2\\Test.java (at line 6)\r\n" + + " * @see X.Inner.Level2.Level3\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type X.Inner is not visible\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug149013_Private03() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "test1/X.java", + "package test1;\n" + + "public class X {\n" + + " class Inner {\n" + + " class Level2 {\n" + + " class Level3 {}\n" + + " }\n" + + " }\n" + + "}\n", + "test3/Test.java", + "package test3;\n" + + "/**\n" + + " * @see test1.X.Inner\n" + + " * @see test1.X.Inner.Level2\n" + + " * @see test1.X.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {}\n" + }, + // no warning + "----------\n" + + "1. ERROR in test3\\Test.java (at line 3)\r\n" + + " * @see test1.X.Inner\r\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: The type test1.X.Inner is not visible\n" + + "----------\n" + + "2. ERROR in test3\\Test.java (at line 4)\r\n" + + " * @see test1.X.Inner.Level2\r\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test1.X.Inner is not visible\n" + + "----------\n" + + "3. ERROR in test3\\Test.java (at line 5)\r\n" + + " * @see test1.X.Inner.Level2.Level3\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test1.X.Inner is not visible\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug149013_Public03() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test1/X.java", + "package test1;\n" + + "public class X {\n" + + " class Inner {\n" + + " class Level2 {\n" + + " class Level3 {}\n" + + " }\n" + + " }\n" + + "}\n", + "test3/Test.java", + "package test3;\n" + + "/**\n" + + " * @see test1.X.Inner\n" + + " * @see test1.X.Inner.Level2\n" + + " * @see test1.X.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {}\n" + }, + // no warning + "----------\n" + + "1. ERROR in test3\\Test.java (at line 3)\r\n" + + " * @see test1.X.Inner\r\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: The type test1.X.Inner is not visible\n" + + "----------\n" + + "2. ERROR in test3\\Test.java (at line 4)\r\n" + + " * @see test1.X.Inner.Level2\r\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test1.X.Inner is not visible\n" + + "----------\n" + + "3. ERROR in test3\\Test.java (at line 5)\r\n" + + " * @see test1.X.Inner.Level2.Level3\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test1.X.Inner is not visible\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * @bug 153399: [javadoc] JDT Core should warn if the @value tag is not used correctly + * @test Ensure that 'value' tag is well warned when not used correctly + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=153399" + */ +public void testBug153399a() { + String[] testFiles = new String[] { + "X.java", + "public class X { \n" + + " /**\n" + + " * {@value #MY_VALUE}\n" + + " */\n" + + " public final static int MY_VALUE = 0; \n" + + " /**\n" + + " * {@value #MY_VALUE}\n" + + " */\n" + + " public void foo() {}\n" + + " /**\n" + + " * {@value #MY_VALUE}\n" + + " */\n" + + " class Sub {} \n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " * {@value #MY_VALUE}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " * {@value #MY_VALUE}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + ); + } else { + runConformTest(testFiles); + } +} +public void testBug153399b() { + String[] testFiles = new String[] { + "X.java", + "public class X { \n" + + " /**\n" + + " * {@value}\n" + + " */\n" + + " public final static int MY_VALUE = 0; \n" + + " /**\n" + + " * {@value}\n" + + " */\n" + + " public void foo() {}\n" + + " /**\n" + + " * {@value}\n" + + " */\n" + + " class Sub {} \n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " * {@value}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " * {@value}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + ); + } else { + runConformTest(testFiles); + } +} +public void testBug153399c() { + String[] testFiles = new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " /**\n" + + " * @return a\n" + + " */\n" + + " boolean get() {\n" + + " return false;\n" + + " }\n" + + "}\n" + }; + runConformTest(testFiles); +} +public void testBug153399d() { + String[] testFiles = new String[] { + "X.java", + "public class X { \n" + + " /**\n" + + " * {@value #MY_VALUE}\n" + + " * {@value}\n" + + " * {@value Invalid}\n" + + " */\n" + + " public final static int MY_VALUE = 0; \n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * {@value #MY_VALUE}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * {@value}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + ); + } else { + runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * {@value Invalid}\n" + + " ^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } +} +public void testBug153399e() { + String[] testFiles = new String[] { + "X.java", + "public class X { \n" + + " /**\n" + + " * {@value Invalid}\n" + + " * {@value #MY_VALUE}\n" + + " */\n" + + " public final static int MY_VALUE = 0; \n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * {@value Invalid}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + ); + } else { + runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * {@value Invalid}\n" + + " ^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } +} + +/** + * @bug 160015: [1.5][javadoc] Missing warning on autoboxing compatible methods + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=160015" + */ +public void testBug160015() { + runNegativeTest(new String[] { + "Test.java", + "/**\n" + + " * @see #method(Long) Warning!\n" + + " */\n" + + "public class Test {\n" + + " public void method(long l) {}\n" + + " /**\n" + + " * @see #method(Long) Warning!\n" + + " */\n" + + " void bar() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see #method(Long) Warning!\n" + + " ^^^^^^\n" + + "Javadoc: The method method(long) in the type Test is not applicable for the arguments (Long)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 7)\n" + + " * @see #method(Long) Warning!\n" + + " ^^^^^^\n" + + "Javadoc: The method method(long) in the type Test is not applicable for the arguments (Long)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * @bug 163659: [javadoc] Compiler should warn when method parameters are not identical + * @test Ensure that a warning is raised when method parameter types are not identical + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=163659" + */ +public void testBug163659() { + runNegativeTest( + new String[] { + "Test.java", + "/**\n" + + " * @see #foo(MyInterface)\n" + + " * @see #foo(MySubInterface)\n" + + " */\n" + + "public class Test {\n" + + " public void foo(MyInterface mi) {\n" + + " }\n" + + "}\n" + + "interface MyInterface {}\n" + + "interface MySubInterface extends MyInterface {} \n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 3)\n" + + " * @see #foo(MySubInterface)\n" + + " ^^^\n" + + "Javadoc: The method foo(MyInterface) in the type Test is not applicable for the arguments (MySubInterface)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * @bug 165794: [javadoc] Should not report ambiguous on method with parameterized types as parameters + * @test Ensure that no warning are raised when ambiguous parameterized methods are present in javadoc comments + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=165794" + */ +public void _testBug165794() { + String[] testFiles = new String[] { + "X.java", + "/**\n" + + " * No reasonable hint for resolving the {@link #getMax(A)}.\n" + + " */\n" + + "public class X {\n" + + " /**\n" + + " * Extends Number method.\n" + + " * @see #getMax(A ipZ)\n" + + " */\n" + + " public T getMax(final A ipY) {\n" + + " return ipY.t();\n" + + " }\n" + + " \n" + + " /**\n" + + " * Extends Exception method.\n" + + " * @see #getMax(A ipY)\n" + + " */\n" + + " public T getMax(final A ipZ) {\n" + + " return ipZ.t();\n" + + " }\n" + + "}\n" + + "class A {\n" + + " T t() { return null; }\n" + + "}\n" + + "class Y {}\n" + + "class Z {}" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4 + || this.complianceLevel >= ClassFileConstants.JDK1_7) { + return; + } + runConformTest(testFiles); +} +/** + * @bug 166365: [javadoc] severity level of malformed javadoc comments did not work properly + * @test Ensure that no warning is raised when visibility is lower than the javadoc option one + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=166365" + */ +public void testBug166365() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @return\n" + + " */\n" + + " private String getSomePrivate() {\n" + + " return \"SomePrivate\";\n" + + " }\n" + + " /**\n" + + " * @return\n" + + " */\n" + + " protected String getSomeProtected() {\n" + + " return \"SomeProtected\";\n" + + " }\n" + + " /**\n" + + " * @return\n" + + " */\n" + + " String getSomeDefault() {\n" + + " return \"SomeDefault\";\n" + + " }\n" + + " /**\n" + + " * @return\n" + + " */\n" + + " public String getSomePublic() {\n" + + " return \"SomePublic\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in X.java (at line 21)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * @bug 166436: [javadoc] Potentially wrong javadoc warning for unexpected duplicate tag value + * @test Ensure that no duplicate warning is raised for value tag + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=166436" + */ +public void testBug166436() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static final String PUBLIC_CONST = \"public\";\n" + + " protected static final String PROTECTED_CONST = \"protected\";\n" + + " static final String DEFAULT_CONST = \"default\"; \n" + + " private static final String PRIVATE_CONST = \"private\"; \n" + + " /**\n" + + " * Values:\n" + + " *
    \n" + + " *
  • {@value #PUBLIC_CONST}
  • \n" + + " *
  • {@value #PROTECTED_CONST}
  • \n" + + " *
  • {@value #DEFAULT_CONST}
  • \n" + + " *
  • {@value #PRIVATE_CONST}
  • \n" + + " *
\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " *
  • {@value #PUBLIC_CONST}
  • \n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " *
  • {@value #PROTECTED_CONST}
  • \n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " *
  • {@value #DEFAULT_CONST}
  • \n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " *
  • {@value #PRIVATE_CONST}
  • \n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + ); + } else { + runNegativeTest(testFiles, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " *
  • {@value #PROTECTED_CONST}
  • \n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'protected\' reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " *
  • {@value #DEFAULT_CONST}
  • \n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " *
  • {@value #PRIVATE_CONST}
  • \n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'private\' reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } +} + +/** + * @bug 168849: [javadoc] Javadoc warning on @see reference in class level docs. + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=168849" + */ +public void testBug168849a() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see http://www.eclipse.org/\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(true, units, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 5)\n" + + " * @see http://www.eclipse.org/\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid URL reference. Double quote the reference or use the href syntax\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +public void testBug168849b() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see http://ftp.eclipse.org/\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(true, units, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 5)\n" + + " * @see http://ftp.eclipse.org/\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid URL reference. Double quote the reference or use the href syntax\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +public void testBug168849c() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see ://\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest( + true, units, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 5)\n" + + " * @see ://\n" + + " ^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +public void testBug168849d() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see http\u003A\u002F\u002Fwww.eclipse.org\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(true, units, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 5)\n" + + " * @see http://www.eclipse.org\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid URL reference. Double quote the reference or use the href syntax\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +public void testBug168849e() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see \"http\u003A\u002F\u002Fwww.eclipse.org\"\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(units); +} + +public void testBug168849f() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see \"http://www.eclipse.org/\"\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(units); +} + +public void testBug168849g() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see http:/ invalid reference\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(true, units, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 5)\n" + + " * @see http:/ invalid reference\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +public void testBug168849h() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see Object:/ invalid reference\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(true, units, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 5)\n" + + " * @see Object:/ invalid reference\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +public void testBug168849i() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see http\u003A\u002F invalid reference\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(true, units, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 5)\n" + + " * @see http:/ invalid reference\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +public void testBug168849j() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see Object\u003A\u002F invalid reference\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + runConformTest(true, units, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 5)\n" + + " * @see Object:/ invalid reference\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed reference (missing end space separator)\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +/** + * @bug 170637: [javadoc] incorrect warning about missing parameter javadoc when using many links + * @test Verify that javadoc parser is not blown-up when there's a lot of inline tags + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=170637" + */ +public void testBug170637() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runConformTest( + new String[] { + "JavaDocTest.java", + "public interface JavaDocTest\n" + + "{\n" + + " /**\n" + + " * This is some stupid test...\n" + + " * \n" + + " * {@link JavaDocTest}\n" + + " * \n" + + " * @param bar1 {@link JavaDocTest}\n" + + " * @param bar2 {@link JavaDocTest}\n" + + " * @param bar3 {@link JavaDocTest}\n" + + " * @param bar4 {@link JavaDocTest}\n" + + " * @param bar5 {@link JavaDocTest}\n" + + " * @param bar6 {@link JavaDocTest}\n" + + " * @param bar7 {@link JavaDocTest}\n" + + " * @param bar8 {@link JavaDocTest}\n" + + " * @param bar9 {@link JavaDocTest}\n" + + " * @param bar10 {@link JavaDocTest}\n" + + " * @param bar11 {@link JavaDocTest}\n" + + " * @param bar12 {@link JavaDocTest}\n" + + " * @param bar13 {@link JavaDocTest}\n" + + " * \n" + + " * @return A string!\n" + + " */\n" + + " public String foo(String bar1,\n" + + " String bar2,\n" + + " String bar3,\n" + + " String bar4,\n" + + " String bar5,\n" + + " String bar6,\n" + + " String bar7,\n" + + " String bar8,\n" + + " String bar9,\n" + + " String bar10,\n" + + " String bar11,\n" + + " String bar12,\n" + + " String bar13\n" + + " );\n" + + "\n" + + " /**\n" + + " * This is some more stupid test...\n" + + " * \n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * {@link JavaDocTest}\n" + + " * \n" + + " * @param bar1 \n" + + " * @param bar2 \n" + + " * @param bar3 \n" + + " * @param bar4 \n" + + " * @param bar5 \n" + + " * @param bar6 \n" + + " * @param bar7 \n" + + " * @param bar8 \n" + + " * @param bar9 \n" + + " * @param bar10 \n" + + " * @param bar11 \n" + + " * @param bar12 \n" + + " * @param bar13 \n" + + " * \n" + + " * @return A string!\n" + + " */\n" + + " public String foo2(String bar1,\n" + + " String bar2,\n" + + " String bar3,\n" + + " String bar4,\n" + + " String bar5,\n" + + " String bar6,\n" + + " String bar7,\n" + + " String bar8,\n" + + " String bar9,\n" + + " String bar10,\n" + + " String bar11,\n" + + " String bar12,\n" + + " String bar13\n" + + " );\n" + + "}\n" + } + ); +} +public void testBug170637a() { + // conform test: verify we can handle a large number of tags + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "public interface X\n" + + "{\n" + + " /**\n" + + " * Test for bug {@link \"https://bugs.eclipse.org/bugs/show_bug.cgi?id=170637\"}\n" + + " * \n" + + " * \n" + + " * @param bar1 {@link X}\n" + + " * @param bar2 {@link X}\n" + + " * @param bar3 {@link X}\n" + + " * @param bar4 {@link X}\n" + + " * @param bar5 {@link X}\n" + + " * @param bar6 {@link X}\n" + + " * @param bar7 {@link X}\n" + + " * @param bar8 {@link X}\n" + + " * @param bar9 {@link X}\n" + + " * @param bar10 {@link X}\n" + + " * @param bar11 {@link X}\n" + + " * @param bar12 {@link X}\n" + + " * @param bar13 {@link X}\n" + + " * @param bar14 {@link X}\n" + + " * @param bar15 {@link X}\n" + + " * @param bar16 {@link X}\n" + + " * @param bar17 {@link X}\n" + + " * @param bar18 {@link X}\n" + + " * @param bar19 {@link X}\n" + + " * @param bar20 {@link X}\n" + + " * @param bar21 {@link X}\n" + + " * @param bar22 {@link X}\n" + + " * @param bar23 {@link X}\n" + + " * @param bar24 {@link X}\n" + + " * @param bar25 {@link X}\n" + + " * @param bar26 {@link X}\n" + + " * @param bar27 {@link X}\n" + + " * @param bar28 {@link X}\n" + + " * @param bar29 {@link X}\n" + + " * @param bar30 {@link X}\n" + + " * \n" + + " * @return A string\n" + + " */\n" + + " public String foo(String bar1,\n" + + " String bar2,\n" + + " String bar3,\n" + + " String bar4,\n" + + " String bar5,\n" + + " String bar6,\n" + + " String bar7,\n" + + " String bar8,\n" + + " String bar9,\n" + + " String bar10,\n" + + " String bar11,\n" + + " String bar12,\n" + + " String bar13,\n" + + " String bar14,\n" + + " String bar15,\n" + + " String bar16,\n" + + " String bar17,\n" + + " String bar18,\n" + + " String bar19,\n" + + " String bar20,\n" + + " String bar21,\n" + + " String bar22,\n" + + " String bar23,\n" + + " String bar24,\n" + + " String bar25,\n" + + " String bar26,\n" + + " String bar27,\n" + + " String bar28,\n" + + " String bar29,\n" + + " String bar30\n" + + " );\n" + + "}\n" + }; + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runConformTest(units); +} +public void testBug170637b() { + // conform test: verify we are able to raise warnings when dealing with a large number of tags + String[] units = new String[] { + "X.java", + "public interface X\n" + + "{\n" + + " /**\n" + + " * Test for bug {@link \"https://bugs.eclipse.org/bugs/show_bug.cgi?id=170637\"}\n" + + " * \n" + + " * \n" + + " * @param bar1 {@link X}\n" + + " * @param bar2 {@link X}\n" + + " * @param bar3 {@link X}\n" + + " * @param bar4 {@link X}\n" + + " * @param bar5 {@link X}\n" + + " * @param bar6 {@link X}\n" + + " * @param bar7 {@link X}\n" + + " * @param bar8 {@link X}\n" + + " * @param bar9 {@link X}\n" + + " * @param bar10 {@link X}\n" + + " * @param bar11 {@link X}\n" + + " * @param bar12 {@link X}\n" + + " * @param bar13 {@link X}\n" + + " * @param bar14 {@link X}\n" + + " * @param bar15 {@link X}\n" + + " * @param bar16 {@link X}\n" + + " * @param bar17 {@link X}\n" + + " * @param bar18 {@link X}\n" + + " * @param bar19 {@link X}\n" + + " * @param bar20 {@link X}\n" + + " * @param bar21 {@link X}\n" + + " * @param bar22 {@link X}\n" + + " * @param bar23 {@link X}\n" + + " * @param bar24 {@link X}\n" + + " * @param bar25 {@link X}\n" + + " * @param bar26 {@link X}\n" + + " * @param bar27 {@link X}\n" + + " * @param bar28 {@link X}\n" + + " * @param bar29 {@link X}\n" + + " * @param bar30 {@link X}\n" + + " * \n" + + " * @return A string\n" + + " */\n" + + " public String foo(String bar1,\n" + + " String bar2,\n" + + " String bar3,\n" + + " String bar4,\n" + + " String bar5,\n" + + " String bar6,\n" + + " String bar7,\n" + + " String bar8,\n" + + " String bar9,\n" + + " String bar10,\n" + + " String bar11,\n" + + " String bar12,\n" + + " String bar13,\n" + + " String bar14,\n" + + " String bar15,\n" + + " String bar16,\n" + + " String bar17,\n" + + " String bar18,\n" + + " String bar19,\n" + + " String bar20,\n" + + " String bar21,\n" + + " String bar22,\n" + + " String bar23,\n" + + " String bar24,\n" + + " String bar25,\n" + + " String bar26,\n" + + " String bar27,\n" + + " String bar28,\n" + + " String bar29,\n" + + " String bar30,\n" + + " String bar31\n" + + " );\n" + + "}\n" + }; + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest(units, + "----------\n" + + "1. ERROR in X.java (at line 70)\n" + + " String bar31\n" + + " ^^^^^\n" + + "Javadoc: Missing tag for parameter bar31\n" + + "----------\n"); +} + +/** + * Bug 176027: [javadoc] @link to member type handled incorrectly + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=176027" + */ +public void testBug176027a() { + // case1 class X static class Inner + String[] units = new String[] { + "otherpkg/C.java", + "package otherpkg;\n" + + "public class C {\n" + + " public static class Inner { }\n" + + "}\n" + , + "somepkg/MemberTypeDocTest.java", + "package somepkg;\n" + + "import otherpkg.C.Inner;\n" + + "/**\n" + + " * {@link Inner} -- error/warning \n" + + " */\n" + + "public class MemberTypeDocTest {\n" + + " void m() { }\n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units, + //somepkg/MemberTypeDocTest.java:6: warning - Tag @link: reference not found: Inner + "----------\n" + + "1. ERROR in somepkg\\MemberTypeDocTest.java (at line 4)\n" + + " * {@link Inner} -- error/warning \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + else { + runConformTest(units); + } +} + +public void testBug176027b() { + // case3 class X class Inner + String[] units = new String[] { + "otherpkg/C.java", + "package otherpkg;\n" + + "public class C {\n" + + " public class Inner { }\n" + + "}\n" + , + "somepkg/MemberTypeDocTest.java", + "package somepkg;\n" + + "import otherpkg.C.Inner;\n" + + "/**\n" + + " * {@link Inner} -- error/warning \n" + + " */\n" + + "public class MemberTypeDocTest {\n" + + " void m() { }\n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units, + //somepkg/MemberTypeDocTest.java:6: warning - Tag @link: reference not found: Inner + "----------\n" + + "1. ERROR in somepkg\\MemberTypeDocTest.java (at line 4)\n" + + " * {@link Inner} -- error/warning \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + else { + runConformTest(units); + } +} + +public void testBug176027c() { + // case3 class X interface Inner + String[] units = new String[] { + "otherpkg/C.java", + "package otherpkg;\n" + + "public class C {\n" + + " public interface Inner { }\n" + + "}\n" + , + "somepkg/MemberTypeDocTest.java", + "package somepkg;\n" + + "import otherpkg.C.Inner;\n" + + "/**\n" + + " * {@link Inner} -- error/warning \n" + + " */\n" + + "public class MemberTypeDocTest {\n" + + " void m() { }\n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units, + //somepkg/MemberTypeDocTest.java:6: warning - Tag @link: reference not found: Inner + "----------\n" + + "1. ERROR in somepkg\\MemberTypeDocTest.java (at line 4)\n" + + " * {@link Inner} -- error/warning \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + else { + runConformTest(units); + } +} + +public void testBug176027d() { + // case4 interface X static class Inner + String[] units = new String[] { + "otherpkg/C.java", + "package otherpkg;\n" + + "public interface C {\n" + + " public static class Inner { }\n" + + "}\n" + , + "somepkg/MemberTypeDocTest.java", + "package somepkg;\n" + + "import otherpkg.C.Inner;\n" + + "/**\n" + + " * {@link Inner} -- error/warning \n" + + " */\n" + + "public class MemberTypeDocTest {\n" + + " void m() { }\n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units, + //somepkg/MemberTypeDocTest.java:6: warning - Tag @link: reference not found: Inner + "----------\n" + + "1. ERROR in somepkg\\MemberTypeDocTest.java (at line 4)\n" + + " * {@link Inner} -- error/warning \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + else { + runConformTest(units); + } +} + +public void testBug176027f() { + // case5 interface X class Inner + String[] units = new String[] { + "otherpkg/C.java", + "package otherpkg;\n" + + "public interface C {\n" + + " public class Inner { }\n" + + "}\n" + , + "somepkg/MemberTypeDocTest.java", + "package somepkg;\n" + + "import otherpkg.C.Inner;\n" + + "/**\n" + + " * {@link Inner} -- error/warning \n" + + " */\n" + + "public class MemberTypeDocTest {\n" + + " void m() { }\n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units, + //somepkg/MemberTypeDocTest.java:6: warning - Tag @link: reference not found: Inner + "----------\n" + + "1. ERROR in somepkg\\MemberTypeDocTest.java (at line 4)\n" + + " * {@link Inner} -- error/warning \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + else { + runConformTest(units); + } +} + +public void testBug176027g() { + // case6 interface X interface Inner + String[] units = new String[] { + "otherpkg/C.java", + "package otherpkg;\n" + + "public interface C {\n" + + " public interface Inner { }\n" + + "}\n" + , + "somepkg/MemberTypeDocTest.java", + "package somepkg;\n" + + "import otherpkg.C.Inner;\n" + + "/**\n" + + " * {@link Inner} -- error/warning \n" + + " */\n" + + "public class MemberTypeDocTest {\n" + + " void m() { }\n" + + "}\n" + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units, + //somepkg/MemberTypeDocTest.java:6: warning - Tag @link: reference not found: Inner + "----------\n" + + "1. ERROR in somepkg\\MemberTypeDocTest.java (at line 4)\n" + + " * {@link Inner} -- error/warning \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + else { + runConformTest(units); + } +} + +public void testBug176027h_public() { + // test embedded inner classes + String[] units = new String[] { + "mainpkg/Outer.java", + "package mainpkg;\n" + + "public class Outer {\n" + + " public class Inner {\n" + + " public class MostInner{\n" + + " \n" + + " }\n" + + " } \n" + + "}\n" + , + "pkg1/Valid1.java", + "package pkg1; \n" + + "import mainpkg.Outer.Inner.MostInner;\n" + + "// valid import - no error in 5.0\n" + + "\n" + + "/** \n" + + " * {@link MostInner}\n" + + " * \n" + + " */ \n" + + "public class Valid1 { \n" + + " /** \n" + + " * {@link MostInner} \n" + + " * \n" + + " */ \n" + + " void m() { } \n" + + "}\n" + , + "pkg2/Valid2.java", + "package pkg2; \n" + + "import mainpkg.Outer.Inner.*;\n" + + "//valid import - no error in 5.0\n" + + "\n" + + "/** \n" + + " * {@link MostInner}\n" + + " * \n" + + " */ \n" + + "public class Valid2 { \n" + + " void m() { } \n" + + "}\n" + , + "pkg3/Invalid3.java", + "package pkg3; \n" + + "import mainpkg.Outer.*;\n" + + "//invalid import: expecting warning / error\n" + + "\n" + + "/** \n" + + " * {@link MostInner} -- error/warning \n" + + " * \n" + + " */ \n" + + "public class Invalid3 { \n" + + " void m() { } \n" + + "}\n" + }; + + String error14 = new String ( + //pkg1\Valid1.java:12: warning - Tag @link: reference not found: MostInner + //pkg2\Valid2.java:12: warning - Tag @link: reference not found: MostInner + //pkg3\Invalid3.java:12: warning - Tag @link: reference not found: MostInner + "----------\n" + + "1. ERROR in pkg1\\Valid1.java (at line 6)\n" + + " * {@link MostInner}\n" + + " ^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in pkg2\\Valid2.java (at line 6)\n" + + " * {@link MostInner}\n" + + " ^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in pkg3\\Invalid3.java (at line 2)\n" + + " import mainpkg.Outer.*;\n"+ + " ^^^^^^^^^^^^^\n"+ + "The import mainpkg.Outer is never used\n" + + "----------\n" + + "2. ERROR in pkg3\\Invalid3.java (at line 6)\n" + + " * {@link MostInner} -- error/warning \n" + + " ^^^^^^^^^\n" + + "Javadoc: MostInner cannot be resolved to a type\n" + + "----------\n"); + + String error50 = new String ( + //pkg3\Invalid3.java:12: warning - Tag @link: reference not found: MostInner + "----------\n" + + "1. ERROR in pkg3\\Invalid3.java (at line 2)\n" + + " import mainpkg.Outer.*;\n"+ + " ^^^^^^^^^^^^^\n"+ + "The import mainpkg.Outer is never used\n" + + "----------\n" + + "2. ERROR in pkg3\\Invalid3.java (at line 6)\n" + + " * {@link MostInner} -- error/warning \n" + + " ^^^^^^^^^\n" + + "Javadoc: MostInner cannot be resolved to a type\n" + + "----------\n"); + + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units,error14); + } + else { + runNegativeTest(units,error50, JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +public void testBug176027h_private() { + // test embedded inner classes + String[] units = new String[] { + "mainpkg/Outer.java", + "package mainpkg;\n" + + "public class Outer {\n" + + " public class Inner {\n" + + " public class MostInner{\n" + + " \n" + + " }\n" + + " } \n" + + "}\n" + , + "pkg1/Valid1.java", + "package pkg1; \n" + + "import mainpkg.Outer.Inner.MostInner;\n" + + "// valid import - no error in 5.0\n" + + "\n" + + "/** \n" + + " * {@link MostInner}\n" + + " * \n" + + " */ \n" + + "public class Valid1 { \n" + + " /** \n" + + " * {@link MostInner} \n" + + " * \n" + + " */ \n" + + " void m() { } \n" + + "}\n" + , + "pkg2/Valid2.java", + "package pkg2; \n" + + "import mainpkg.Outer.Inner.*;\n" + + "//valid import - no error in 5.0\n" + + "\n" + + "/** \n" + + " * {@link MostInner}\n" + + " * \n" + + " */ \n" + + "public class Valid2 { \n" + + " void m() { } \n" + + "}\n" + , + "pkg3/Invalid3.java", + "package pkg3; \n" + + "import mainpkg.Outer.*;\n" + + "//invalid import: expecting warning / error\n" + + "\n" + + "/** \n" + + " * {@link MostInner} -- error/warning \n" + + " * \n" + + " */ \n" + + "public class Invalid3 { \n" + + " void m() { } \n" + + "}\n" + }; + + String error14 = new String( + //pkg1\Valid1.java:12: warning - Tag @link: reference not found: MostInner + //pkg1\Valid1.java:17: warning - Tag @link: reference not found: MostInner + //pkg2\Valid2.java:12: warning - Tag @link: reference not found: MostInner + //pkg3\Invalid3.java:12: warning - Tag @link: reference not found: MostInner + "----------\n" + + "1. ERROR in pkg1\\Valid1.java (at line 6)\n" + + " * {@link MostInner}\n" + + " ^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in pkg1\\Valid1.java (at line 11)\n" + + " * {@link MostInner} \n" + + " ^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in pkg2\\Valid2.java (at line 6)\n" + + " * {@link MostInner}\n" + + " ^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in pkg3\\Invalid3.java (at line 2)\n" + + " import mainpkg.Outer.*;\n"+ + " ^^^^^^^^^^^^^\n"+ + "The import mainpkg.Outer is never used\n" + + "----------\n" + + "2. ERROR in pkg3\\Invalid3.java (at line 6)\n" + + " * {@link MostInner} -- error/warning \n" + + " ^^^^^^^^^\n" + + "Javadoc: MostInner cannot be resolved to a type\n" + + "----------\n"); + + String error50 = new String( + //pkg3\Invalid3.java:12: warning - Tag @link: reference not found: MostInner + "----------\n" + + "1. ERROR in pkg3\\Invalid3.java (at line 2)\n" + + " import mainpkg.Outer.*;\n"+ + " ^^^^^^^^^^^^^\n"+ + "The import mainpkg.Outer is never used\n" + + "----------\n" + + "2. ERROR in pkg3\\Invalid3.java (at line 6)\n" + + " * {@link MostInner} -- error/warning \n" + + " ^^^^^^^^^\n" + + "Javadoc: MostInner cannot be resolved to a type\n" + + "----------\n"); + + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units,error14); + } + else { + runNegativeTest(units,error50, JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +/** + * @bug 177009: [javadoc] Missing Javadoc tag not reported + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=177009" + */ +public void testBug177009a() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " public X(String str, int anInt) {\n" + + " }\n" + + "}\n", + "pkg/Y.java", + "package pkg;\n" + + "\n" + + "public class Y extends X {\n" + + " private static int myInt = 0;\n" + + " /**\n" + + " * @see X#X(String, int)\n" + // case1 potential AIOOBE + " */\n" + + " public Y(String str) {\n" + + " super(str, myInt);\n" + + " }\n" + + "}\n" + }; + this.reportMissingJavadocTags = CompilerOptions.WARNING; + runConformTest( + true, + units, + "----------\n" + + "1. WARNING in pkg\\Y.java (at line 8)\n" + + " public Y(String str) {\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter str\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +public void testBug177009b() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " public X(String str, int anInt) {\n" + + " }\n" + + "}\n", + "pkg/Y.java", + "package pkg;\n" + + "\n" + + "public class Y extends X {\n" + + " /**\n" + + " * @param str\n" + + " * @param anInt\n" + + " * @see X#X(String, int)\n" + // case2 find super ref + " */\n" + + " public Y(String str, int anInt, int anotherInt) {\n" + + " super(str, anInt);\n" + + " }\n" + + "}\n" + }; + this.reportMissingJavadocTags = CompilerOptions.WARNING; + runConformTest(true, units, + "----------\n" + + "1. WARNING in pkg\\Y.java (at line 9)\n" + + " public Y(String str, int anInt, int anotherInt) {\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Missing tag for parameter anotherInt\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +/** + * @bug 190970: [javadoc] "field never read locally" analysis should not consider javadoc + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=190970" + */ +public void testBug190970a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + "private int unused1;\n" + + "\n" + + "/**\n" + + " * Same value as {@link #unused1}\n" + + " */\n" + + "private int unused2;\n" + + "}\n", + }, + null, + customOptions, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " private int unused1;\n" + + " ^^^^^^^\n" + + "The value of the field X.unused1 is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " private int unused2;\n" + + " ^^^^^^^\n" + + "The value of the field X.unused2 is not used\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings + ); +} +// test unused methods +public void testBug190970b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + "private void unused1() {}\n" + + "/**\n" + + " * Same value as {@link #unused1()}\n" + + " */\n" + + "private void unused2() {}\n" + + "}\n", + }, + null, + customOptions, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 4)\n" + + " private void unused1() {}\n" + + " ^^^^^^^^^\n" + + "The method unused1() from the type X is never used locally\n" + + "----------\n" + + "2. WARNING in pkg\\X.java (at line 8)\n" + + " private void unused2() {}\n" + + " ^^^^^^^^^\n" + + "The method unused2() from the type X is never used locally\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings + ); +} +// test unused types +public void testBug190970c() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); + runConformTest( + true, + new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + "private class unused1 {}\n" + + "/**\n" + + " * {@link X.unused1}\n" + + " */\n" + + "private class unused2 {}\n" + + "}\n", + }, + null, + customOptions, + "----------\n" + + "1. WARNING in pkg\\X.java (at line 4)\n" + + " private class unused1 {}\n" + + " ^^^^^^^\n" + + "The type X.unused1 is never used locally\n" + + "----------\n" + + "2. WARNING in pkg\\X.java (at line 8)\n" + + " private class unused2 {}\n" + + " ^^^^^^^\n" + + "The type X.unused2 is never used locally\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings + ); +} + +// static { TESTS_PREFIX = "testBug191322"; } +/** + * @bug 191322: [javadoc] @see or @link reference to method without signature fails to resolve to base class method + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=191322" + */ +public void testBug191322() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {}\n" + + " /**\n" + + " * {@link #foo}.\n" + + " * @see #foo\n" + + " */\n" + + " void goo() {}\n" + + "}\n", + "Y.java", + "class Y extends X {\n" + + " /**\n" + + " * {@link #foo}\n" + + " * @see #foo\n" + + " */\n" + + " void hoo() {}\n" + + "}" + } + ); +} +public void testBug191322b() { + runConformTest( + new String[] { + "b/X.java", + "package b;\n" + + "public class X {\n" + + " void foo() {}\n" + + "}\n" + + "class Y extends X {}\n" + + "class W extends Y {}\n" + + "class Z extends W {\n" + + " /**\n" + + " * {@link #foo}\n" + + " * @see #foo\n" + + " */\n" + + " void hoo() {}\n" + + "}\n" + } + ); +} +public void testBug191322c() { + runConformTest( + new String[] { + "c/X.java", + "package c;\n" + + "public interface X {\n" + + " void foo();\n" + + "}\n" + + "interface Y extends X {\n" + + " /**\n" + + " * {@link #foo}\n" + + " * @see #foo\n" + + " */\n" + + " void hoo();\n" + + "}\n" + } + ); +} +public void testBug191322d() { + runConformTest( + new String[] { + "d/X.java", + "package d;\n" + + "public interface X {\n" + + " void foo();\n" + + "}\n" + + "interface Y extends X {}\n" + + "abstract class W implements Y {}\n" + + "abstract class Z extends W {\n" + + " /**\n" + + " * {@link #foo}\n" + + " * @see #foo\n" + + " */\n" + + " void hoo() {}\n" + + "}\n" + } + ); +} +public void testBug191322e() { + runConformTest( + new String[] { + "e/X.java", + "package e;\n" + + "public class X {\n" + + " void foo() {}\n" + + " class Y {\n" + + " /**\n" + + " * {@link #foo}\n" + + " * @see #foo\n" + + " */\n" + + " void hoo() {}\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug191322f() { + runConformTest( + new String[] { + "f/X.java", + "package f;\n" + + "public class X {\n" + + " void foo() {}\n" + + " void foo(String str) {}\n" + + "}\n" + + "class Y extends X {\n" + + " /**\n" + + " * {@link #foo}\n" + + " * @see #foo\n" + + " */\n" + + " void hoo() {}\n" + + "}\n" + } + ); +} +public void testBug191322g() { + runConformTest( + new String[] { + "g/X.java", + "package g;\n" + + "public class X {\n" + + " void foo(String str) {}\n" + + " void foo(int x) {}\n" + + "}\n" + + "class Y extends X {\n" + + " /**\n" + + " * {@link #foo}\n" + + " * @see #foo\n" + + " */\n" + + " void hoo() {}\n" + + "}\n" + } + ); +} +public void testBug191322h() { + runConformTest( + new String[] { + "h/X.java", + "package h;\n" + + "public class X {\n" + + " void foo(String str) {}\n" + + "}\n" + + "class Y extends X {\n" + + " /**\n" + + " * {@link #foo}\n" + + " * @see #foo\n" + + " */\n" + + " void hoo() {}\n" + + "}\n" + } + ); +} +public void testBug191322i() { + runConformTest( + new String[] { + "i/X.java", + "package i;\n" + + "interface X {\n" + + " void foo();\n" + + "}\n" + + "interface Y {\n" + + " void foo(int i);\n" + + "}\n" + + "abstract class Z implements X, Y {\n" + + " /**\n" + + " * @see #foo\n" + + " */\n" + + " void bar() {\n" + + " }\n" + + "}" + } + ); +} + +/** + * @bug 195374: [javadoc] Missing Javadoc warning for required qualification for inner types at 1.4 level + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=195374" + */ +public void testBug195374() { + String[] units = new String[] { + "X.java", + "public class X {\n" + + " public static class Param {\n" + + " /**\n" + + " * warning expected when compliance < 1.5 {@link X#setParams(Param[])}\n" + + " * no warning expected {@link X#setParams(X.Param[])}\n" + + " */\n" + + " public int getIndex() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + " public void setParams(Param[] params) {\n" + + " }\n" + + "}\n" + }; + + String error14 = new String( + // warning - Tag @link: can't find setParams(Param[]) in X + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * warning expected when compliance < 1.5 {@link X#setParams(Param[])}\n" + + " ^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n"); + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + runNegativeTest(units,error14); + } + else { + runConformTest(units); + } +} + +/** + * @bug 207765: [javadoc] Javadoc warning on @see reference could be improved + * @test Ensure we have different message depending on tag value + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=207765" + */ +public void testBug207765() { + runNegativeTest( + new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * {@link \"http://www.eclipse.org/}\n" + + " * @see \"http://www.eclipse.org/\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in pkg\\X.java (at line 5)\n" + + " * {@link \"http://www.eclipse.org/}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in pkg\\X.java (at line 6)\n" + + " * @see \"http://www.eclipse.org/\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid URL reference. Double quote the reference or use the href syntax\n" + + "----------\n" + ); +} + +/** + * @bug 222900: [Javadoc] Missing description is warned if valid description is on a new line + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=222900" + */ +public void testBug222900a() { + String[] units = new String[] { + "X.java", + "/**\n" + + "* @since\n" + + "* description\n" + + "* @author\n" + + "* description\n" + + "* @version\n" + + "* description\n" + + "*/\n" + + "public class X {\n" + + " /**\n" + + " * @param aParam\n" + + " * description\n" + + " * @return\n" + + " * description\n" + + " * @since\n" + + " * description\n" + + " * @throws NullPointerException\n" + + " * description\n" + + " * @exception NullPointerException\n" + + " * description\n" + + " * @serial\n" + + " * description\n" + + " * @serialData\n" + + " * description\n" + + " * @serialField\n" + + " * description\n" + + " * @deprecated\n" + + " * description\n" + + " */\n" + + " public String foo(String aParam) {\n" + + " return new String();\n" + + " }\n" + + "}\n" + }; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformTest(units); +} +public void testBug222900b() { + String[] units = new String[] { + "X.java", + "/**\n" + + " * {@code\n" + + " * description}\n" + + " * {@literal\n" + + " * description}\n" + + "*/\n" + + "public class X {\n" + + "}\n" + }; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformTest(units); +} +public void testBug222900c() { + String[] units = new String[] { + "X.java", + "/**\n" + + " * Test the {@code} missing description\n" + + " * Test the {@code\n" + + " * } missing description\n" + + " * Test the {@code X} with description\n" + + " * Test the {@code\n" + + " * public class X} with description\n" + + "*/\n" + + "public class X {\n" + + "}\n" + }; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " * Test the {@code} missing description\n" + + " ^^^^\n" + + "Javadoc: Description expected after @code\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " * Test the {@code\n" + + " ^^^^\n" + + "Javadoc: Description expected after @code\n" + + "----------\n" + ); +} + +/** + * @bug 222902: [Javadoc] Missing description should not be warned in some cases + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=222902" + */ +public void testBug222902() { + String[] units = new String[] { + "X.java", + "/**\n" + + " * {@code}\n" + + " * {@literal}\n" + + " * @author\n" + + " * @deprecated\n" + + " * @since\n" + + " * @version\n" + + " * @generated\n" + // should not get a warning for missing description on non-standard tag + " * @code\n" + // should not get a warning for non-inlined tag @code + " * @literal\n" + // should not get a warning for non-inlined tag @literal + "*/\n" + + "public class X {\n" + + " /**\n" + + " * @param aParam\n" + + " * @return\n" + + " * @throws NullPointerException\n" + + " * @exception NullPointerException\n" + + " */\n" + + " public String foo(String aParam) {\n" + + " return new String();\n" + + " }\n" + + " /**\n" + + " * @serial\n" + + " * @serialData\n" + + " * @serialField\n" + + " */\n" + + " Object field;\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.WARNING; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformTest(true, units, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " * {@code}\n" + + " ^^^^\n" + + "Javadoc: Description expected after @code\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " * {@literal}\n" + + " ^^^^^^^\n" + + "Javadoc: Description expected after @literal\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " * @author\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @author\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " * @deprecated\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Description expected after @deprecated\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " * @since\n" + + " ^^^^^\n" + + "Javadoc: Description expected after @since\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " * @version\n" + + " ^^^^^^^\n" + + "Javadoc: Description expected after @version\n" + + "----------\n" + + "7. WARNING in X.java (at line 14)\n" + + " * @param aParam\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after this reference\n" + + "----------\n" + + "8. WARNING in X.java (at line 15)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n" + + "9. WARNING in X.java (at line 16)\n" + + " * @throws NullPointerException\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Description expected after this reference\n" + + "----------\n" + + "10. WARNING in X.java (at line 17)\n" + + " * @exception NullPointerException\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Description expected after this reference\n" + + "----------\n" + + "11. WARNING in X.java (at line 23)\n" + + " * @serial\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @serial\n" + + "----------\n" + + "12. WARNING in X.java (at line 24)\n" + + " * @serialData\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Description expected after @serialData\n" + + "----------\n" + + "13. WARNING in X.java (at line 25)\n" + + " * @serialField\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Description expected after @serialField\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings + ); +} + +/** + * @bug 227730: [Javadoc] Missing description should not be warned for @inheritDoc + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=227730" + */ +public void testBug227730a() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * {@inheritDoc}\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformTest(units); +} + +public void testBug227730b() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * {@docRoot}\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformTest(units); +} + +/** + * @bug 233187: [javadoc] partially qualified inner types should be warned + * @test verify that partial inner class qualification are warned as javadoc tools does + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=233187" + */ +public void testBug233187a() { + String[] units = new String[] { + "test/a/X.java", + "package test.a;\n" + + "\n" + + "public class X {\n" + + " public static class Y {\n" + + " public static class Z { \n" + + " /**\n" + + " * The position in the new method signature depends on\n" + + " * the position in the array passed to\n" + + " * {@link X.Y#foo(test.a.X.Y.Z[])} OK for javadoc tool\n" + + " * {@link X.Y#foo(test.a.X.Y.Z)} KO for javadoc tool\n" + + " * {@link X.Y#foo(no_test.a.X.Y.Z[])} KO for javadoc tool\n" + + " * {@link X.Y#foo(Y.Z[])} KO for javadoc tool\n" + + " * {@link test.a.X.Y#foo(Y.Z[])} KO for javadoc tool\n" + + " */\n" + + " public int bar() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " public void foo(Z[] params) {\n" + + " }\n" + + " }\n" + + "}\n" + }; + runNegativeTest(units, + // warning - Tag @link: can't find foo(test.a.X.Y.Z) in test.a.X.Y + // warning - Tag @link: can't find foo(no_test.a.X.Y.Z[]) in test.a.X.Y + // warning - Tag @link: can't find foo(Y.Z[]) in test.a.X.Y + // warning - Tag @link: can't find foo(Y.Z[]) in test.a.X.Y + "----------\n" + + "1. ERROR in test\\a\\X.java (at line 10)\n" + + " * {@link X.Y#foo(test.a.X.Y.Z)} KO for javadoc tool\n" + + " ^^^\n" + + "Javadoc: The method foo(X.Y.Z[]) in the type X.Y is not applicable for the arguments (X.Y.Z)\n" + + "----------\n" + + "2. ERROR in test\\a\\X.java (at line 11)\n" + + " * {@link X.Y#foo(no_test.a.X.Y.Z[])} KO for javadoc tool\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: no_test[] cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in test\\a\\X.java (at line 12)\n" + + " * {@link X.Y#foo(Y.Z[])} KO for javadoc tool\n" + + " ^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "4. ERROR in test\\a\\X.java (at line 13)\n" + + " * {@link test.a.X.Y#foo(Y.Z[])} KO for javadoc tool\n" + + " ^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); +} +public void testBug233187b() { + runNegativeTest( + new String[] { + "test/b/X.java", + "package test.b;\n" + + "\n" + + "public class X {\n" + + " public static class Y {\n" + + " public static class Z { \n" + + " /**\n" + + " * The position in the new method signature depends on\n" + + " * the position in the array passed to\n" + + " * {@link X.Y#foo(test.b.X.Y.Z)} OK for javadoc tool\n" + + " * {@link X.Y#foo(test.b.X.Y.Z[])} KO for javadoc tool\n" + + " * {@link X.Y#foo(no_test.b.X.Y.Z)} KO for javadoc tool\n" + + " * {@link X.Y#foo(Y.Z)} KO for javadoc tool\n" + + " * {@link test.b.X.Y#foo(Y.Z)} KO for javadoc tool\n" + + " */\n" + + " public int bar() {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "\n" + + " public void foo(Z params) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + // warning - Tag @link: can't find foo(test.b.X.Y.Z[]) in test.b.X.Y + // warning - Tag @link: can't find foo(no_test.b.X.Y.Z) in test.b.X.Y + // warning - Tag @link: can't find foo(Y.Z) in test.b.X.Y + // warning - Tag @link: can't find foo(Y.Z) in test.b.X.Y + "----------\n" + + "1. ERROR in test\\b\\X.java (at line 10)\n" + + " * {@link X.Y#foo(test.b.X.Y.Z[])} KO for javadoc tool\n" + + " ^^^\n" + + "Javadoc: The method foo(X.Y.Z) in the type X.Y is not applicable for the arguments (X.Y.Z[])\n" + + "----------\n" + + "2. ERROR in test\\b\\X.java (at line 11)\n" + + " * {@link X.Y#foo(no_test.b.X.Y.Z)} KO for javadoc tool\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: no_test cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in test\\b\\X.java (at line 12)\n" + + " * {@link X.Y#foo(Y.Z)} KO for javadoc tool\n" + + " ^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "4. ERROR in test\\b\\X.java (at line 13)\n" + + " * {@link test.b.X.Y#foo(Y.Z)} KO for javadoc tool\n" + + " ^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); +} +public void testBug233187c() { + runConformTest( + new String[] { + "test/c/X.java", + "package test.c;\n" + + "\n" + + "public class X {\n" + + " static class Y { \n" + + " }\n" + + " void foo(Y y) {}\n" + + " /**\n" + + " * @see #foo(X.Y)\n" + + " */\n" + + " void bar() {}\n" + + "}\n" + } + ); +} + +/** + * @bug 233887: Build of Eclipse project stop by NullPointerException and will not continue on Eclipse version later than 3.4M7 + * @test Ensure that no NPE is raised when a 1.5 param tag syntax is incorrectly used on a fiel with an initializer + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=233887" + */ +public void testBug233887() { + String expectedError = this.complianceLevel <= ClassFileConstants.JDK1_4 ? + "----------\n" + + "1. ERROR in NPETest.java (at line 5)\n" + + " * @param \n" + + " ^^^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in NPETest.java (at line 5)\n" + + " * @param \n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n"; + runNegativeTest( + new String[] { + "NPETest.java", + "public class NPETest {\n" + + " public NPETest() {\n" + + " }\n" + + " /**\n" + + " * @param \n" + + " */\n" + + " private static final int MAX = 50;\n" + + "\n" + + "}\n" + }, + expectedError, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * @bug 237937: [javadoc] Wrong "Javadoc: Malformed link reference" if href label contains // + * @test Ensure that no warning is raised when href label contains '//' + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=237937" + */ +public void testBug237937() { + runConformTest( + new String[] { + "Link.java", + "/**\n" + + " * @see http://www.eclipse.org\n" + + " * @see //\n" + + " */\n" + + "public class Link {}\n" + } + ); +} + +/** + * @bug 246712: [javadoc] Unexpected warning about missing parameter doc in case of @inheritDoc + * @test Ensure inline tag are considered as description + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=246712" + */ +public void testBug246712() { + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * Do something more.\n" + + " * \n" + + " * @param monitor The monitor\n" + + " * @return {@link String X}\n" + + " */\n" + + " String foo(Object monitor) {\n" + + " return \"X\";\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + "\n" + + " /**\n" + + " * Do something more.\n" + + " * \n" + + " * {@inheritDoc}\n" + + " * \n" + + " * @param monitor {@inheritDoc}\n" + + " * @return {@link String Y}\n" + + " */\n" + + " String foo(Object monitor) {\n" + + " return \"Y\";\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug246712b() { + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformTest( + new String[] { + "X.java", + "/**\n" + + " * @author {@link String}\n" + + " * @since {@link String}\n" + + " * @version {@link String}\n" + + " * @deprecated {@link String}\n" + + "*/\n" + + "public class X {\n" + + " /**\n" + + " * @return {@link String}\n" + + " * @since {@link String}\n" + + " * @throws Exception {@link String}\n" + + " * @exception Exception {@link String}\n" + + " * @serial {@link String}\n" + + " * @serialData {@link String}\n" + + " * @serialField {@link String}\n" + + " * @deprecated {@link String}\n" + + " */\n" + + " public String foo(String aParam) throws Exception {\n" + + " return new String();\n" + + " }\n" + + "}" + } + ); +} +// duplicate +public void testBug246715() { + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " final static int WAIT_YES = 0;\n" + + " final static int WAIT_NO = 1;\n" + + " \n" + + " /**\n" + + " * Do something more.\n" + + " * \n" + + " * @param waitFlag {@link #WAIT_YES} or {@link #WAIT_NO}\n" + + " */\n" + + " String foo(int waitFlag) {\n" + + " return \"X\";\n" + + " }\n" + + "}\n" + } + ); +} + +/** + * @bug 254825: [javadoc] compile error when referencing outer param from inner class javadoc + * @test Ensure that local variable reference does not imply missing compiler implementation error + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=254825" + */ +public void testBug254825() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " public Object foo(Object o) { \n" + + " return new Object() {\n" + + " /** @see #o */\n" + + " public void x() {}\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " /** @see #o */\n" + + " ^\n" + + "Javadoc: o cannot be resolved or is not a field\n" + + "----------\n" + ); +} +public void testBug254825b() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " /** @see #o */\n" + + " public Object foo(Object o) { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " /** @see #o */\n" + + " ^\n" + + "Javadoc: o cannot be resolved or is not a field\n" + + "----------\n" + ); +} + + +/** + * @bug 258798: [1.5][compiler] Return type should be erased after unchecked conversion during inference + * @test Fix for this bug had side effects while reporting missing tags in javadoc comments.
    + * Following tests have been written to verify that noticed issues have been solved: + *
      + *
    1. missing tags should be reported even when the method/constructor has + * a @see reference on itself
    2. + *
    3. missing tag should be reported when superclass constructor has different + * arguments (even if they are compatible)
    4. + *
    5. missing tag should not be reported when method arguments are the same + * even when the type argument is not the same
    6. + *
    + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=258798" + */ +public void testBug258798_1() { + this.reportMissingJavadocTags = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "/**\n" + + "* @see #X(int)\n" + + "*/\n" + + "X(int i) {\n" + + "}\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " X(int i) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter i\n" + + "----------\n" + ); +} +public void testBug258798_2a() { + this.reportMissingJavadocTags = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "X(int i) {}\n" + + "}\n" + + "class Y extends X {\n" + + "/** @see X#X(int) */\n" + + "Y(double d) { super(0); }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " Y(double d) { super(0); }\n" + + " ^\n" + + "Javadoc: Missing tag for parameter d\n" + + "----------\n" + ); +} +public void testBug258798_2b() { + this.reportMissingJavadocTags = CompilerOptions.WARNING; + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + "X(ArrayList alt) {}\n" + + "}\n" + + "class Y extends X {\n" + + "/** @see X#X(ArrayList) */\n" + + "Y(List lu) { super(null); }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " Y(List lu) { super(null); }\n" + + " ^^\n" + + "Javadoc: Missing tag for parameter lu\n" + + "----------\n" + ); + } +} +public void testBug258798_2c() { + this.reportMissingJavadocTags = CompilerOptions.WARNING; + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + "X(Object o) {}\n" + + "}\n" + + "class Y extends X {\n" + + "/** @see X#X(Object) */\n" + + "Y(List lu) { super(lu); }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " Y(List lu) { super(lu); }\n" + + " ^^\n" + + "Javadoc: Missing tag for parameter lu\n" + + "----------\n" + ); + } +} +public void testBug258798_3() { + this.reportMissingJavadocTags = CompilerOptions.WARNING; + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + "X(List lt) {}\n" + + "}\n" + + "class Y extends X {\n" + + "/** @see X#X(List) */\n" + + "Y(List lu) { super(null); }\n" + + "}\n" + } + ); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=247037, make sure that we complain when @inheritdoc +// is used where it is outlawed by the specs. This test verifies that we complain when @inheritDoc +// is used with classes and interfaces. +public void testBug247037() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * {@inheritDoc}\n" + // error, cannot be applied to a class + " */\n" + + "public class X {\n" + + "}\n" + + "/**\n" + + " * {@inheritDoc}\n" + // error, cannot be applied to interfaces. + " */" + + "interface Blah {\n" + + " void BlahBlah();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " * {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247037, make sure that we complain when @inheritdoc +//is used where it is outlawed by the specs. Here we test that when @inheritDoc is applied to a +// field or constructor, we complain. +public void testBug247037b() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "}\n" + + "class Y extends X {\n" + + " /**\n" + + " * {@inheritDoc}\n" + // error, cannot be applied to a field + " */\n" + + " public int field = 10;\n" + + " /**\n" + + " * @param x {@inheritDoc}\n" + // error, cannot be applied to a constructor + " */\n" + + " Y(int x) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " * @param x {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247037, make sure that we complain when @inheritdoc +//is used where it is outlawed by the specs. In this test we test the use of @inheritedDoc in some +// block tags. +public void testBug247037c() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @since 1.0\n" + + " * @return Blah\n" + + " * @param blah Blah Blah\n" + + " * @throws Exception When something is wrong\n" + + " */\n" + + " public int m(int blah) throws Exception {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " /**\n" + + " * @param blah {@inheritDoc}\n" + + " * @return {@inheritDoc}\n" + + " * @since {@inheritDoc}\n" + // error, cannot be used in @since + " * @author {@inheritDoc}\n" + // error, cannot be used in @author + " * @see {@inheritDoc}\n" + // error, cannot be used in @see + " * @throws Exception {@inheritDoc}\n" + + " * @exception Exception {@inheritDoc}\n" + + " */\n" + + " public int m(int blah) throws Exception {\n" + + " return 1;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " * @since {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " * @author {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " * @see {@inheritDoc}\n" + + " ^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n" + + "4. ERROR in X.java (at line 18)\n" + + " * @see {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=247037, make sure that we complain when @inheritdoc +// is used where it is outlawed by the specs. Test to verify that every bad use of @inheritDoc triggers +// a message from the compiler +public void testBug247037d() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "}\n" + + "class Y extends X {\n" + + " /**\n" + + " * @param blah {@inheritDoc}\n" + // error n() doesn't override anything. + " * @return {@inheritDoc}\n" + // error, n() doesn't override anything + " * @author {@inheritDoc}\n" + // error, cannot be used in @author + " */\n" + + " public int n(int blah) {\n" + + " return 1;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param blah {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @return {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @author {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +/** + * @bug 267833:[javadoc] Custom tags should not be allowed for inline tags + * @test Ensure that a warning is raised when customs tags are used as inline tags + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=267833" + */ +public void testBug267833() { + runConformTest( + new String[] { + "X.java", + "/**\n" + + "* Invalid custom tag {@custom \"Invalid\"} \n" + + "* @custom \"Valid\"\n" + + "*/\n" + + "public class X {\n" + + "}" + }); +} +/** + * Additional test for bug 267833 + * @test Ensure that the JavadocTagConstants.JAVADOC_TAG_TYPE array is up to date with the other arrays, such as + * JavadocTagConstants.TAG_NAMES, JavadocTagConstants.INLINE_TAGS and JavadocTagConstants.BLOCK_TAGS + */ +public void testBug267833_2() { + + assertEquals(JavadocTagConstants.TAG_NAMES.length,JavadocTagConstants.JAVADOC_TAG_TYPE.length); + + int tagsLength = JavadocTagConstants.TAG_NAMES.length; + nextTag:for (int index=0; index < tagsLength; index++) { + char[] tagName = JavadocTagConstants.TAG_NAMES[index]; + if (tagName.length > 0) { + for (int i=0; i < JavadocTagConstants.BLOCK_TAGS_LENGTH; i++) { + int length = JavadocTagConstants.BLOCK_TAGS[i].length; + for (int j=0; j < length; j++) { + if (tagName == JavadocTagConstants.BLOCK_TAGS[i][j]) { + assertEquals(JavadocTagConstants.JAVADOC_TAG_TYPE[index], JavadocTagConstants.TAG_TYPE_BLOCK); + continue nextTag; + } + } + } + for (int i=0; i < JavadocTagConstants.INLINE_TAGS_LENGTH; i++) { + int length = JavadocTagConstants.INLINE_TAGS[i].length; + for (int j=0; j < length; j++) { + if (tagName == JavadocTagConstants.INLINE_TAGS[i][j]) { + assertEquals(JavadocTagConstants.JAVADOC_TAG_TYPE[index], JavadocTagConstants.TAG_TYPE_INLINE); + continue nextTag; + } + } + } + } + assertEquals(JavadocTagConstants.JAVADOC_TAG_TYPE[index], JavadocTagConstants.TAG_TYPE_NONE); + } +} +/** + * Additional test for bug 267833 + * @test Ensure that a warning is raised when block tags are used as inline tags. + */ +public void testBug267833_3() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "/** \n" + + "* Description {@see String} , {@return int}, {@since 1.0}, {@param i}, {@throws NullPointerException}\n" + + "* and more {@author jay}, {@category cat}, {@deprecated}, {@exception NullPointerException}, {@version 1.1}\n" + + "* and more {@since 1.0}, {@serial 0L}, {@serialData data}, {@serialField field}\n" + + "* @param i\n" + + "* @return value\n" + + "* @throws NullPointerException \n" + + "*/\n" + + "public int foo(int i) {\n" + + " return 0;\n" + + "}\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * Description {@see String} , {@return int}, {@since 1.0}, {@param i}, {@throws NullPointerException}\n" + + " ^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " * Description {@see String} , {@return int}, {@since 1.0}, {@param i}, {@throws NullPointerException}\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " * Description {@see String} , {@return int}, {@since 1.0}, {@param i}, {@throws NullPointerException}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " * Description {@see String} , {@return int}, {@since 1.0}, {@param i}, {@throws NullPointerException}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "5. ERROR in X.java (at line 3)\n" + + " * Description {@see String} , {@return int}, {@since 1.0}, {@param i}, {@throws NullPointerException}\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " * and more {@author jay}, {@category cat}, {@deprecated}, {@exception NullPointerException}, {@version 1.1}\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "7. ERROR in X.java (at line 4)\n" + + " * and more {@author jay}, {@category cat}, {@deprecated}, {@exception NullPointerException}, {@version 1.1}\n" + + " ^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "8. ERROR in X.java (at line 4)\n" + + " * and more {@author jay}, {@category cat}, {@deprecated}, {@exception NullPointerException}, {@version 1.1}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "9. ERROR in X.java (at line 4)\n" + + " * and more {@author jay}, {@category cat}, {@deprecated}, {@exception NullPointerException}, {@version 1.1}\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "10. ERROR in X.java (at line 4)\n" + + " * and more {@author jay}, {@category cat}, {@deprecated}, {@exception NullPointerException}, {@version 1.1}\n" + + " ^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "11. ERROR in X.java (at line 5)\n" + + " * and more {@since 1.0}, {@serial 0L}, {@serialData data}, {@serialField field}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "12. ERROR in X.java (at line 5)\n" + + " * and more {@since 1.0}, {@serial 0L}, {@serialData data}, {@serialField field}\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "13. ERROR in X.java (at line 5)\n" + + " * and more {@since 1.0}, {@serial 0L}, {@serialData data}, {@serialField field}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "14. ERROR in X.java (at line 5)\n" + + " * and more {@since 1.0}, {@serial 0L}, {@serialData data}, {@serialField field}\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n"); +} + +/** + * @bug 281609: [javadoc] "Javadoc: Invalid reference" warning for @link to Java package + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=281609" + */ +public void testBug281609a() { + runNegativeTest( + new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see java\n" + + " * @see java.lang\n" + + " * @see PKG\n" + + " * @see pkg\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }, + // warning - Tag @see: reference not found: PKG + "----------\n" + + "1. ERROR in pkg\\X.java (at line 7)\n" + + " * @see PKG\n" + + " ^^^\n" + + "Javadoc: PKG cannot be resolved to a type\n" + + "----------\n" + ); +} +public void testBug281609b() { + runConformTest( + new String[] { + "x/y/z/X.java", + "package x.y.z;\n" + + "\n" + + "public class X {\n" + + " /**\n" + + " * @see java\n" + + " * @see java.lang\n" + + " * @see x\n" + + " * @see x.y\n" + + " * @see x.y.z\n" + + " */\n" + + " public void foo() { \n" + + " \n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292510 +// Test to verify that partial types are demarcated correctly while +// annotating a deprecated type error in javadoc. +public void testBug292510() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ENABLED); + runNegativeTest( + true, + new String[] { + "X.java", + "/** @deprecated */\n" + + "public class X {\n" + + " public class XX {\n" + + " public class XXX {\n" + + " }\n" + + " }\n" + + "}\n", + "Y.java", + "/**\n" + + " * @see X.XX.XXX\n" + + " */\n" + + "public class Y {\n" + + "}\n"}, + null, + options, + "----------\n" + + "1. ERROR in Y.java (at line 2)\n" + + " * @see X.XX.XXX\n" + + " ^\n" + + "Javadoc: The type X is deprecated\n" + + "----------\n" + + "2. ERROR in Y.java (at line 2)\n" + + " * @see X.XX.XXX\n" + + " ^^^^\n" + + "Javadoc: The type X.XX is deprecated\n" + + "----------\n" + + "3. ERROR in Y.java (at line 2)\n" + + " * @see X.XX.XXX\n" + + " ^^^^^^^^\n" + + "Javadoc: The type X.XX.XXX is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316782 +// Test to verify that turning on process annotations doesn't turn on javadoc check +public void testBug316782() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + this.processAnnotations = CompilerOptions.ENABLED; + this.docCommentSupport = CompilerOptions.DISABLED; + runConformTest( + new String[] { + "X.java", + "/** @see X.XX.XXX */\n" + + "public class X {\n" + + "/** @see X.XX.XXX */\n" + + " public void foo() { }\n" + + "}\n" + }); +} +/** + * @bug 222188: [javadoc] Incorrect usage of inner type not reported + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=222188" + */ +public void testBug222188a() { + // case 1: partially qualified reference in another package + String[] units = new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " public interface Inner { }\n" + + "}\n" + , + "pack2/X.java", + "package pack2;\n" + + "import pack.Test;\n" + + "public class X {\n" + + "/**\n" + + " * See also {@link Test.Inner} -- error/warning \n" + + " */\n" + + " public void m() { }\n" + + "}\n" + }; + runNegativeTest(units, + // warning - Tag @link: reference not found: Test.Inner + "----------\n" + + "1. ERROR in pack2\\X.java (at line 5)\n" + + " * See also {@link Test.Inner} -- error/warning \n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug222188b() { + // case 2: fully but invalid qualified reference in another package + String[] units = new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " public interface Inner { }\n" + + "}\n" + , + "pack2/X.java", + "package pack2;\n" + + "public class X {\n" + + "/**\n" + + " * See also {@link pack.Test.Inners} -- error/warning \n" + + " */\n" + + " public void m() { }\n" + + "}\n" + }; + runNegativeTest(units, + // warning - Tag @link: reference not found: Test.Inner + "----------\n" + + "1. ERROR in pack2\\X.java (at line 4)\n" + + " * See also {@link pack.Test.Inners} -- error/warning \n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: pack.Test.Inners cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +/** + * @bug 221539: [javadoc] doesn't detect non visible inner class + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=221539" + */ +public void testBug221539a() { + // partially qualified reference in the same package + String[] units = new String[] { + "p/Test.java", + "package p;\n" + + "/**\n" + + " * {@link Test.Inner} not ok for Javadoc\n" + + " * {@link Foo.Inner} ok for Javadoc\n" + + " */\n" + + "public class Test extends Foo {\n" + + "}\n" + , + "p/Foo.java", + "package p;\n" + + "public class Foo {\n" + + " static class Inner {}\n" + + "}\n" + }; + runNegativeTest(units, + // warning - Tag @link: reference not found: Test.Inner + "----------\n" + + "1. ERROR in p\\Test.java (at line 3)\n" + + " * {@link Test.Inner} not ok for Javadoc\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void testBug221539b() { + // partially qualified reference in different package + String[] units = new String[] { + "p1/Test.java", + "package p1;\n" + + "import p2.Foo;\n" + + "/**\n" + + " * {@link Test.Inner} not ok for Javadoc\n" + + " * {@link Foo.Inner} not ok Javadoc\n" + + " * {@link p2.Foo.Inner} ok for Javadoc as fully qualified\n" + + " */\n" + + "public class Test extends Foo {\n" + + "}\n" + , + "p2/Foo.java", + "package p2;\n" + + "public class Foo {\n" + + " public static class Inner {}\n" + + "}\n" + }; + runNegativeTest(units, + // warning - Tag @link: reference not found: Test.Inner + // warning - Tag @link: reference not found: Foo.Inner + "----------\n" + + "1. ERROR in p1\\Test.java (at line 4)\n" + + " * {@link Test.Inner} not ok for Javadoc\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in p1\\Test.java (at line 5)\n" + + " * {@link Foo.Inner} not ok Javadoc\n" + + " ^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} + +public void testBug221539c() { + // case 3: partially qualified references are valid within the same CU + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "pack/Test.java", + "package pack;\n" + + "/**\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * @see Level3\n" + + " * @see Level2.Level3\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + " public class Level2 {\n" + + " class Level3 {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + } + ); +} + +public void testBug382606() { + runConformTest( + new String[] { + "pack/A.java", + "package pack;\n" + + "/**\n"+ + "* @see A\n" + + "*/\n" + + "public interface A {\n"+ + "}\n"+ + "/**\n"+ + "* @see #B()\n"+ + "*/\n"+ + "class B {\n"+ + " B() {}\n"+ + "\n"+ + " public void foo(){\n"+ + " new B();\n"+ + " }\n"+ + "}\n" + } + ); +} + +/** + * @bug 206345: [javadoc] compiler should not interpret contents of {@literal} + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=206345" + */ +public void testBug206345a() { + // @litteral tags display text without interpreting the text as HTML markup or nested javadoc tags + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@literal raw text:\n" + + " * {@link BadLink} is just text}\n" + + " * {@link expected_error}\n" + + " * }\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + //warning - Tag @link: reference not found: expected_error + "----------\n" + + "1. ERROR in pkg\\X.java (at line 7)\r\n" + + " * {@link expected_error}\r\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: expected_error cannot be resolved to a type\n" + + "----------\n"); +} +public void testBug206345b() { + // same for @code tags + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@code raw text:\n" + + " * {@link BadLink} is just text}\n" + + " * {@link expected_error}\n" + + " * }\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + // warning - Tag @link: reference not found: expected_error + "----------\n" + + "1. ERROR in pkg\\X.java (at line 7)\r\n" + + " * {@link expected_error}\r\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: expected_error cannot be resolved to a type\n" + + "----------\n"); +} +public void testBug206345c() { + // verify we still validate other syntax + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@link raw text:\n" + + " * {@link BadLink} is just text}\n" + + " * {@link expected_error}\n" + + " * }\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + // warning - Tag @link: reference not found: raw text: {@link BadLink} is just text + // warning - Tag @link: reference not found: expected_error + // + "----------\n" + + "1. ERROR in pkg\\X.java (at line 5)\n" + + " * This is {@link raw text:\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n" + + "2. ERROR in pkg\\X.java (at line 5)\n" + + " * This is {@link raw text:\n" + + " ^^^\n" + + "Javadoc: raw cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in pkg\\X.java (at line 6)\n" + + " * {@link BadLink} is just text}\n" + + " ^^^^^^^\n" + + "Javadoc: BadLink cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in pkg\\X.java (at line 7)\n" + + " * {@link expected_error}\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: expected_error cannot be resolved to a type\n" + + "----------\n"); +} +public void testBug206345d() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@literal raw text:\n" + + " * {@link BadLink}}}} is just text}\n" + + " * {@link expected_error}\n" + + " * }\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + // warning - Tag @link: reference not found: expected_error + "----------\n" + + "1. ERROR in pkg\\X.java (at line 7)\n" + + " * {@link expected_error}\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: expected_error cannot be resolved to a type\n" + + "----------\n"); +} +public void testBug206345e() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@code raw text:\n" + + " * {{{{{{@link BadLink}}} is just text}\n" + + " * @since 4.2\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + // warning - End Delimiter } missing for possible See Tag in comment string: "This is {@code raw text: {{{{{{@link BadLink}}} is just text}" + "----------\n" + + "1. ERROR in pkg\\X.java (at line 5)\r\n" + + " * This is {@code raw text:\n" + + " * {{{{{{@link BadLink}}} is just text}\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n"); +} +public void testBug206345f() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@code raw text:\n" + + " * {@link BadLink}\n" + + " * @since 4.2\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + // warning - End Delimiter } missing for possible See Tag in comment string: "This is {@code raw text: {@link BadLink}" + "----------\n" + + "1. ERROR in pkg\\X.java (at line 5)\r\n" + + " * This is {@code raw text:\n" + + " * {@link BadLink}\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n"); + } +public void testBug206345g() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@code raw text:\n" + + " * {@link BadLink\n" + + " * @since 4.2\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + "----------\n" + + "1. ERROR in pkg\\X.java (at line 5)\n" + + " * This is {@code raw text:\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n"); +} +public void testBug206345h() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@code raw text:\n" + + " * @since 4.2\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + "----------\n" + + "1. ERROR in pkg\\X.java (at line 5)\r\n" + + " * This is {@code raw text:\r\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n"); +} +public void testBug206345i() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@code raw text:\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + "----------\n" + + "1. ERROR in pkg\\X.java (at line 5)\r\n" + + " * This is {@code raw text:\r\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n"); +} +public void testBug206345j() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@literal raw text:\n" + + " * {@link BadLink} is just text}\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformReferenceTest(units); +} +public void testBug206345k() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@code raw text:\n" + + " * {@link BadLink} is just text}\n" + + " * }\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runConformReferenceTest(units); +} +public void testBug206345l() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@literal raw text:\n" + + " * {@link BadLink}\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + // warning - End Delimiter } missing for possible See Tag in comment string: "This is {@literal raw text: {@link BadLink}" + "----------\n" + + "1. ERROR in pkg\\X.java (at line 5)\n" + + " * This is {@literal raw text:\n" + + " * {@link BadLink}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n"); +} +public void testBug206345m() { + String[] units = new String[] { + "pkg/X.java", + "package pkg;\n" + + "\n" + + "public class X extends Object {\n" + + " /**\n" + + " * This is {@code raw text:\n" + + " * {@link BadLink}\n" + + " */\n" + + " public String toString() { \n" + + " return \"foo\";\n" + + " }\n" + + "}\n" + }; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS; + runNegativeTest(units, + // warning - End Delimiter } missing for possible See Tag in comment string: "This is {@code raw text: {@link BadLink}" + "----------\n" + + "1. ERROR in pkg\\X.java (at line 5)\n" + + " * This is {@code raw text:\n" + + " * {@link BadLink}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing closing brace for inline tag\n" + + "----------\n"); +} +} + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java new file mode 100644 index 0000000000..aa44a2d748 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java @@ -0,0 +1,654 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.ArrayList; +import java.util.Map; +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.jdt.core.tests.junit.extension.TestCase; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public abstract class JavadocTest extends AbstractRegressionTest { + + boolean useLibrary = false; + static String ZIP_FILE = "/TestJavadocVisibility.zip"; + static final String LINE_SEPARATOR = System.getProperty("line.separator"); + public static ArrayList ALL_CLASSES = null; + static final String DOC_COMMENT_SUPPORT = System.getProperty("doc.support"); + + // Javadoc execution + protected static final String JAVADOC_NAME = + File.pathSeparatorChar == ':' ? "javadoc" : "javadoc.exe"; + protected static String javadocCommandLineHeader; + + static { + ALL_CLASSES = new ArrayList(); + ALL_CLASSES.add(JavadocBugsTest.class); + ALL_CLASSES.add(JavadocTestForMethod.class); + ALL_CLASSES.add(JavadocTestMixed.class); + ALL_CLASSES.add(JavadocTestForClass.class); + ALL_CLASSES.add(JavadocTestForConstructor.class); + ALL_CLASSES.add(JavadocTestForField.class); + ALL_CLASSES.add(JavadocTestForInterface.class); + ALL_CLASSES.add(JavadocTestOptions.class); + } + + + public static void addTest(TestSuite suite, Class testClass) { + TestSuite innerSuite = new TestSuite(testClass); + suite.addTest(innerSuite); + } + + public static Test suite() { + TestSuite testSuite = new TestSuite(JavadocTest.class.getName()); + + // Reset forgotten subsets of tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS = null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + + for (int i = 0, size=ALL_CLASSES.size(); i < size; i++) { + Class testClass = (Class) ALL_CLASSES.get(i); + Test suite = buildAllCompliancesTestSuite(testClass); + testSuite.addTest(suite); + } + int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels(); + if ((complianceLevels & AbstractCompilerTest.F_1_3) != 0) { + testSuite.addTest(buildUniqueComplianceTestSuite(JavadocTest_1_3.class, ClassFileConstants.JDK1_3)); + } + if ((complianceLevels & AbstractCompilerTest.F_1_4) != 0) { + testSuite.addTest(buildUniqueComplianceTestSuite(JavadocTest_1_4.class, ClassFileConstants.JDK1_4)); + } + if ((complianceLevels & AbstractCompilerTest.F_1_5) != 0) { + testSuite.addTest(buildUniqueComplianceTestSuite(JavadocTest_1_5.class, ClassFileConstants.JDK1_5)); + } + if ((complianceLevels & AbstractCompilerTest.F_9) != 0) { + testSuite.addTest(buildUniqueComplianceTestSuite(JavadocTestForModule.class, ClassFileConstants.JDK9)); + } + if ((complianceLevels & AbstractCompilerTest.F_14) != 0) { + testSuite.addTest(buildUniqueComplianceTestSuite(JavadocTestForRecord.class, ClassFileConstants.JDK14)); + } + if ((complianceLevels & AbstractCompilerTest.F_15) != 0) { + testSuite.addTest(buildUniqueComplianceTestSuite(JavadocTest_15.class, ClassFileConstants.JDK15)); + } + if ((complianceLevels & AbstractCompilerTest.F_16) != 0) { + testSuite.addTest(buildUniqueComplianceTestSuite(JavadocTest_15.class, ClassFileConstants.JDK16)); + } + return testSuite; + } + + public static Test suiteForComplianceLevel(long level, Class testClass) { + TestSuite suite = new RegressionTestSetup(level); + buildAllCompliancesTestSuite(suite, testClass); + return suite; + } + + public JavadocTest(String name) { + super(name); + } + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + // Set default before bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=110964 changes + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsNotVisibleRef, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + return options; + } + + @Override + protected String[] getDefaultClassPaths() { + if (this.useLibrary) { + String[] classLibs = super.getDefaultClassPaths(); + final int length = classLibs.length; + String[] newClassPaths = new String[length + 1]; + System.arraycopy(classLibs, 0, newClassPaths, 0, length); + newClassPaths[length] = getClass().getResource(ZIP_FILE).getPath(); + return newClassPaths; + } + return super.getDefaultClassPaths(); + } + + static String[] referencedClasses = null; + static { + referencedClasses = + new String[] { + "test/AbstractVisibility.java", + "package test;\n" + + "public abstract class AbstractVisibility {\n" + + " private class AvcPrivate {\n" + + " private int avf_private = 10;\n" + + " public int avf_public = avf_private;\n" + + " private int avm_private() {\n" + + " avf_private = (new AvcPrivate()).avf_private;\n" + + " return avf_private;\n" + + " }\n" + + " public int avm_public() {\n" + + " return avm_private();\n" + + " }\n" + + " }\n" + + " public class AvcPublic {\n" + + " private int avf_private = 10;\n" + + " public int avf_public = avf_private;\n" + + " private int avm_private() {\n" + + " avf_private = (new AvcPrivate()).avf_private;\n" + + " return avf_private;\n" + + " }\n" + + " public int avm_public() {\n" + + " return avm_private();\n" + + " }\n" + + " }\n" + + " private int avf_private = 100;\n" + + " public int avf_public = avf_private;\n" + + " \n" + + " private int avm_private() {\n" + + " avf_private = (new AvcPrivate()).avf_private;\n" + + " return avf_private;\n" + + " }\n" + + " public int avm_public() {\n" + + " return avm_private();\n" + + " }\n" + + "}\n", + "test/Visibility.java", + "package test;\n" + + "public class Visibility extends AbstractVisibility {\n" + + " private class VcPrivate {\n" + + " private int vf_private = 10;\n" + + " public int vf_public = vf_private;\n" + + " private int vm_private() {\n" + + " vf_private = (new VcPrivate()).vf_private;\n" + + " avf_private = vf_private;\n" + + " return vf_private+avf_private;\n" + + " }\n" + + " public int vm_public() {\n" + + " return vm_private();\n" + + " }\n" + + " };\n" + + " public class VcPublic {\n" + + " private int vf_private = 10;\n" + + " public int vf_public = vf_private;\n" + + " private int vm_private() {\n" + + " vf_private = (new VcPrivate()).vf_private;\n" + + " avf_private = vf_private;\n" + + " return vf_private+avf_private;\n" + + " }\n" + + " public int vm_public() {\n" + + " return vm_private();\n" + + " }\n" + + " };\n" + + " private int vf_private = 100;\n" + + " private int avf_private = 100;\n" + + " public int vf_public = vf_private;\n" + + " public int avf_public = vf_private;\n" + + " \n" + + " private int vm_private() {\n" + + " vf_private = (new VcPrivate()).vf_private;\n" + + " avf_private = vf_private;\n" + + " return vf_private+avf_private;\n" + + " }\n" + + " public int vm_public() {\n" + + " return vm_private();\n" + + " }\n" + + "}\n", + "test/copy/VisibilityPackage.java", + "package test.copy;\n" + + "class VisibilityPackage {\n" + + " private class VpPrivate {\n" + + " private int vf_private = 10;\n" + + " public int vf_public = vf_private;\n" + + " private int vm_private() {\n" + + " vf_private = (new VpPrivate()).vf_private;\n" + + " return vf_private;\n" + + " }\n" + + " public int vm_public() {\n" + + " return vm_private();\n" + + " }\n" + + " }\n" + + " public class VpPublic {\n" + + " private int vf_private = 10;\n" + + " public int vf_public = vf_private;\n" + + " private int vm_private() {\n" + + " vf_private = (new VpPrivate()).vf_private;\n" + + " return vf_private;\n" + + " }\n" + + " public int vm_public() {\n" + + " return vm_private();\n" + + " }\n" + + " }\n" + + " private int vf_private = 100;\n" + + " public int vf_public = vf_private;\n" + + " \n" + + " private int vm_private() {\n" + + " vf_private = (new VpPrivate()).vf_private;\n" + + " return vf_private;\n" + + " }\n" + + " public int vm_public() {\n" + + " return vm_private();\n" + + " }\n" + + "}\n", + "test/copy/VisibilityPublic.java", + "package test.copy;\n" + + "public class VisibilityPublic {\n" + + " private class VpPrivate {\n" + + " private int vf_private = 10;\n" + + " public int vf_public = vf_private;\n" + + " private int vm_private() {\n" + + " vf_private = (new VpPrivate()).vf_private;\n" + + " return vf_private;\n" + + " }\n" + + " public int vm_public() {\n" + + " return vm_private();\n" + + " }\n" + + " }\n" + + " public class VpPublic {\n" + + " private int vf_private = 10;\n" + + " public int vf_public = vf_private;\n" + + " private int vm_private() {\n" + + " vf_private = (new VpPrivate()).vf_private;\n" + + " return vf_private;\n" + + " }\n" + + " public int vm_public() {\n" + + " return vm_private();\n" + + " }\n" + + " }\n" + + " private int vf_private = 100;\n" + + " public int vf_public = vf_private;\n" + + " \n" + + " private int vm_private() {\n" + + " vf_private = (new VpPrivate()).vf_private;\n" + + " return vf_private;\n" + + " }\n" + + " public int vm_public() {\n" + + " return vm_private();\n" + + " }\n" + + "}\n" }; + } + // The fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=201912 results in these additional + // diagnostics to be generated. Just as we arrange for the ``referencedClasses'' to be compiled + // automatically, we need to include these diagnostics automatically in the expected messages. + static String expectedDiagnosticsFromReferencedClasses = + "----------\n" + + "1. WARNING in test\\AbstractVisibility.java (at line 5)\n" + + " public int avf_public = avf_private;\n" + + " ^^^^^^^^^^\n" + + "The value of the field AbstractVisibility.AvcPrivate.avf_public is not used\n" + + "----------\n" + + "2. WARNING in test\\AbstractVisibility.java (at line 10)\n" + + " public int avm_public() {\n" + + " ^^^^^^^^^^^^\n" + + "The method avm_public() from the type AbstractVisibility.AvcPrivate is never used locally\n" + + "----------\n" + + "----------\n" + + "1. WARNING in test\\Visibility.java (at line 5)\n" + + " public int vf_public = vf_private;\n" + + " ^^^^^^^^^\n" + + "The value of the field Visibility.VcPrivate.vf_public is not used\n" + + "----------\n" + + "2. WARNING in test\\Visibility.java (at line 11)\n" + + " public int vm_public() {\n" + + " ^^^^^^^^^^^\n" + + "The method vm_public() from the type Visibility.VcPrivate is never used locally\n" + + "----------\n" + + "----------\n" + + "1. WARNING in test\\copy\\VisibilityPackage.java (at line 5)\n" + + " public int vf_public = vf_private;\n" + + " ^^^^^^^^^\n" + + "The value of the field VisibilityPackage.VpPrivate.vf_public is not used\n" + + "----------\n" + + "2. WARNING in test\\copy\\VisibilityPackage.java (at line 10)\n" + + " public int vm_public() {\n" + + " ^^^^^^^^^^^\n" + + "The method vm_public() from the type VisibilityPackage.VpPrivate is never used locally\n" + + "----------\n" + + "----------\n" + + "1. WARNING in test\\copy\\VisibilityPublic.java (at line 5)\n" + + " public int vf_public = vf_private;\n" + + " ^^^^^^^^^\n" + + "The value of the field VisibilityPublic.VpPrivate.vf_public is not used\n" + + "----------\n" + + "2. WARNING in test\\copy\\VisibilityPublic.java (at line 10)\n" + + " public int vm_public() {\n" + + " ^^^^^^^^^^^\n" + + "The method vm_public() from the type VisibilityPublic.VpPrivate is never used locally\n" + + "----------\n"; + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + if (RUN_JAVAC) { + javadocCommandLineHeader = + jdkRootDirPath.append("bin").append(JAVADOC_NAME).toString(); // PREMATURE replace JAVA_NAME and JAVAC_NAME with locals? depends on potential reuse + } +// SHIFT = true; +// INDENT = 3; + } + + /* (non-Javadoc) + * @see junit.framework.TestCase#tearDown() + */ + @Override + protected void tearDown() throws Exception { +// SHIFT = false; +// INDENT = 2; + super.tearDown(); + } + + protected void runConformReferenceTest(String[] testFiles) { + String[] completedFiles = testFiles; + if (!this.useLibrary) { + completedFiles = new String[testFiles.length + referencedClasses.length]; + System.arraycopy(referencedClasses, 0, completedFiles, 0, referencedClasses.length); + System.arraycopy(testFiles, 0, completedFiles, referencedClasses.length, testFiles.length); + } + runConformTest(completedFiles); + } + protected void runNegativeReferenceTest(String[] testFiles, String expected) { + runNegativeReferenceTest(testFiles, expected, JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + protected void runNegativeReferenceTest(String[] testFiles, String expected, + JavacTestOptions javacTestOptions) { + String[] completedFiles = testFiles; + if (!this.useLibrary) { + completedFiles = new String[testFiles.length + referencedClasses.length]; + System.arraycopy(referencedClasses, 0, completedFiles, 0, referencedClasses.length); + System.arraycopy(testFiles, 0, completedFiles, referencedClasses.length, testFiles.length); + expected = expectedDiagnosticsFromReferencedClasses + expected; + } + runNegativeTest(completedFiles, expected, javacTestOptions); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest#runConformTest(java.lang.String[], java.lang.String, java.lang.String[], boolean, java.lang.String[], java.util.Map, org.eclipse.jdt.internal.compiler.ICompilerRequestor) + * + protected void runConformTest(String[] testFiles, + String expectedSuccessOutputString, + String[] classLib, + boolean shouldFlushOutputDirectory, + String[] vmArguments, + Map customOptions, + ICompilerRequestor clientRequestor) { + if (TESTS_NAMES != null || TESTS_PREFIX != null || TESTS_NUMBERS != null || TESTS_RANGE != null) { + writeFiles(testFiles); + } + super.runConformTest(testFiles, + expectedSuccessOutputString, + classLib, + shouldFlushOutputDirectory, + vmArguments, + customOptions, + clientRequestor); + } + /* (non-Javadoc) + * @see org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest#runNegativeTest(java.lang.String[], java.lang.String, java.lang.String[], boolean, java.util.Map, boolean) + * + protected void runNegativeTest(String[] testFiles, + String expectedProblemLog, + String[] classLib, + boolean shouldFlushOutputDirectory, + Map customOptions, + boolean generateOutput) { + if (TESTS_NAMES != null || TESTS_PREFIX != null || TESTS_NUMBERS != null || TESTS_RANGE != null) { + writeFiles(testFiles); + } + super.runNegativeTest(testFiles, + expectedProblemLog, + classLib, + shouldFlushOutputDirectory, + customOptions, + generateOutput); + } + */ + @Override + protected void writeFiles(String[] testFiles) { + String classDirName = getClass().getName().substring(getClass().getName().lastIndexOf('.')+1); //.substring(11); + String testName = getName(); + int idx = testName.indexOf(" - "); + if (idx > 0) { + testName = testName.substring(idx+3); + } + + // File dir = new File("d:/usr/OTI/tests/javadoc/"); + // non portable + createOutputTestDirectory(classDirName); + createOutputTestDirectory(Character.toUpperCase(testName.charAt(0)) + + testName.substring(1)); + System.out.println("Write test file to " + + this.outputTestDirectory.getPath() + "..."); + for (int i=0, length=testFiles.length; i0) { + continue; + } else { + int index = fileName.lastIndexOf('/'); + if (index > 0) { + String subdirs = fileName.substring(0, index); + String packName = subdirs.replace('/', '.'); + contents = "package "+packName+";"+contents.substring(contents.indexOf(';')+1); + File dir = new File(dirFileName, subdirs); + if (!dir.exists()) dir.mkdirs(); + if (RUN_JAVAC) { + Util.writeToFile(contents, dirFileName+"/"+fileName); + // PREMATURE this results into a duplicate file. + } + fileName = fileName.substring(index+1); + } + } + Util.writeToFile(contents, dirFileName+"/"+fileName); + // REVIEW don't know why this is created at the default package level + } + } + + /* + * Run Sun compilation using javadoc. + * See implementation in parent for details. + */ + @Override + protected void runJavac( + String[] testFiles, + final String expectedProblemLog, + final String expectedSuccessOutputString, + boolean shouldFlushOutputDirectory) { + String testName = null; + Process compileProcess = null; + try { + // Init test name + testName = testName(); + + // Cleanup javac output dir if needed + File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR_NAME); + if (shouldFlushOutputDirectory) { + Util.delete(javacOutputDirectory); + } + + // Write files in dir + writeFiles(testFiles); + + // Prepare command line + StringBuilder cmdLine = new StringBuilder(javadocCommandLineHeader); + // compute extra classpath + String[] classpath = Util.concatWithClassLibs(JAVAC_OUTPUT_DIR_NAME, false); + StringBuilder cp = new StringBuilder(" -classpath "); + int length = classpath.length; + for (int i = 0; i < length; i++) { + if (i > 0) + cp.append(File.pathSeparatorChar); + if (classpath[i].indexOf(" ") != -1) { + cp.append("\"" + classpath[i] + "\""); + } else { + cp.append(classpath[i]); + } + } + cmdLine.append(cp); + // add source files + for (int i = 0; i < testFiles.length; i += 2) { + // *.java is not enough (p1/X.java, p2/Y.java) + cmdLine.append(' '); + cmdLine.append(testFiles[i]); + } + + // Launch process + compileProcess = Runtime.getRuntime().exec( + cmdLine.toString(), null, this.outputTestDirectory); + + // Log errors + Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR"); + + // Log output + Logger outputLogger = new Logger(compileProcess.getInputStream(), "OUTPUT"); + + // start the threads to run outputs (standard/error) + errorLogger.start(); + outputLogger.start(); + + // Wait for end of process + int exitValue = compileProcess.waitFor(); + errorLogger.join(); // make sure we get the whole output + outputLogger.join(); + + // Report raw javadoc results + if (! testName.equals(javacTestName)) { + javacTestName = testName; + javacTestErrorFlag = false; + javacFullLog.println("-----------------------------------------------------------------"); + javacFullLog.println(CURRENT_CLASS_NAME + " " + testName); + } + if (exitValue != 0) { + javacTestErrorFlag = true; + } + if (errorLogger.buffer.length() > 0) { + javacFullLog.println("--- javac err: ---"); + javacFullLog.println(errorLogger.buffer.toString()); + } + if (outputLogger.buffer.length() > 0) { + javacFullLog.println("--- javac out: ---"); + javacFullLog.println(outputLogger.buffer.toString()); + } + + // Compare compilation results + if (expectedProblemLog == null || expectedProblemLog.length() == 0) { + // Eclipse found no error and no warning + if (exitValue != 0) { + // Javac found errors + System.out.println("----------------------------------------"); + System.out.println(testName + " - Javadoc has found error(s) but Eclipse expects conform result:\n"); + javacFullLog.println("JAVAC_MISMATCH: Javadoc has found error(s) but Eclipse expects conform result"); + System.out.println(errorLogger.buffer.toString()); + printFiles(testFiles); + DIFF_COUNTERS[0]++; + } + else { + // Javac found no error - may have found warnings + if (errorLogger.buffer.length() > 0) { + System.out.println("----------------------------------------"); + System.out.println(testName + " - Javadoc has found warning(s) but Eclipse expects conform result:\n"); + javacFullLog.println("JAVAC_MISMATCH: Javadoc has found warning(s) but Eclipse expects conform result"); + System.out.println(errorLogger.buffer.toString()); + printFiles(testFiles); + DIFF_COUNTERS[0]++; + } + } + } + else { + // Eclipse found errors or warnings + if (errorLogger.buffer.length() == 0) { + System.out.println("----------------------------------------"); + System.out.println(testName + " - Eclipse has found error(s)/warning(s) but Javadoc did not find any:"); + javacFullLog.println("JAVAC_MISMATCH: Eclipse has found error(s)/warning(s) but Javadoc did not find any"); + dualPrintln("eclipse:"); + dualPrintln(expectedProblemLog); + printFiles(testFiles); + DIFF_COUNTERS[1]++; + } else if (expectedProblemLog.indexOf("ERROR") > 0 && exitValue == 0){ + System.out.println("----------------------------------------"); + System.out.println(testName + " - Eclipse has found error(s) but Javadoc only found warning(s):"); + javacFullLog.println("JAVAC_MISMATCH: Eclipse has found error(s) but Javadoc only found warning(s)"); + dualPrintln("eclipse:"); + dualPrintln(expectedProblemLog); + System.out.println("javadoc:"); + System.out.println(errorLogger.buffer.toString()); + printFiles(testFiles); + DIFF_COUNTERS[1]++; + } else { + // PREMATURE refine comparison + // TODO (frederic) compare warnings in each result and verify they are similar... +// System.out.println(testName+": javac has found warnings :"); +// System.out.print(errorLogger.buffer.toString()); +// System.out.println(testName+": we're expecting warning results:"); +// System.out.println(expectedProblemLog); + } + } + } + catch (InterruptedException e1) { + if (compileProcess != null) compileProcess.destroy(); + System.out.println(testName+": Sun javadoc compilation was aborted!"); + javacFullLog.println("JAVAC_WARNING: Sun javadoc compilation was aborted!"); + e1.printStackTrace(javacFullLog); + } + catch (Throwable e) { + System.out.println(testName+": could not launch Sun javadoc compilation!"); + e.printStackTrace(); + javacFullLog.println("JAVAC_ERROR: could not launch Sun javac compilation!"); + e.printStackTrace(javacFullLog); + // PREMATURE failing the javac pass or comparison could also fail + // the test itself + } + finally { + Util.delete(this.outputTestDirectory); + } + } + + @Override + protected void printJavacResultsSummary() { + if (RUN_JAVAC) { + Integer count = (Integer)TESTS_COUNTERS.get(CURRENT_CLASS_NAME); + if (count != null) { + int newCount = count.intValue()-1; + TESTS_COUNTERS.put(CURRENT_CLASS_NAME, Integer.valueOf(newCount)); + if (newCount == 0) { + if (DIFF_COUNTERS[0]!=0 || DIFF_COUNTERS[1]!=0 || DIFF_COUNTERS[2]!=0) { + dualPrintln("==========================================================================="); + dualPrintln("Results summary:"); + } + if (DIFF_COUNTERS[0]!=0) + dualPrintln(" - "+DIFF_COUNTERS[0]+" test(s) where Javadoc found errors/warnings but Eclipse did not"); + if (DIFF_COUNTERS[1]!=0) + dualPrintln(" - "+DIFF_COUNTERS[1]+" test(s) where Eclipse found errors/warnings but Javadoc did not"); + System.out.println("\n"); + } + } + javacFullLog.flush(); + } + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForClass.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForClass.java new file mode 100644 index 0000000000..03ca7b4c41 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForClass.java @@ -0,0 +1,1142 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTestForClass extends JavadocTest { + + public static Test suite() { + return buildAllCompliancesTestSuite(javadocTestClass()); + } + public JavadocTestForClass(String name) { + super(name); + } + public static Class javadocTestClass() { + return JavadocTestForClass.class; + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return options; + } + + /* (non-Javadoc) + * Test unexpected tags + */ + public void test001() { + this.runConformTest( + new String[] { + "X.java", + " /**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " */\n" + + "public class X {\n" + + " public void foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid class javadoc\n" + + " * @param x Invalid tag\n" + + " */\n" + + "public class X {\n" + + " public void foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param x Invalid tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid class javadoc\n" + + " * @throws NullPointerException Invalid tag\n" + + " */\n" + + "public class X {\n" + + " public void foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @throws NullPointerException Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid class javadoc\n" + + " * @exception NullPointerException Invalid tag\n" + + " */\n" + + "public class X {\n" + + " public void foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @exception NullPointerException Invalid tag\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid class javadoc\n" + + " * @return Invalid tag\n" + + " */\n" + + "public class X {\n" + + " public void foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @return Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid class javadoc\n" + + " * @exception NullPointerException Invalid tag\n" + + " * @throws NullPointerException Invalid tag\n" + + " * @return Invalid tag\n" + + " * @param x Invalid tag\n" + + " */\n" + + "public class X {\n" + + " public void foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @exception NullPointerException Invalid tag\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @throws NullPointerException Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @return Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param x Invalid tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test007() { + this.runConformTest( + new String[] { + "X.java", + " /**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " */\n" + + "public class X {\n" + + " public void foo() {}\n" + + " /**\n" + + " * Invalid javadoc comment\n" + + " */\n" + + "}\n" } + ); + } + + public void test008() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {}\n" + + " /**\n" + + " * Invalid javadoc comment\n" + + " */\n" + + "}\n" } + ); + } + + public void test009() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid javadoc comment\n" + + " */\n" + + "}\n" } + ); + } + + /* + * (non-Javadoc) Test @see tag + */ + // String references + public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid string references \n" + + " *\n" + + " * @see \"\n" + + " * @see \"unterminated string\n" + + " * @see \"invalid string\"\"\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see \"\n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @see \"unterminated string\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @see \"invalid string\"\"\n" + +" ^\n" + + "Javadoc: Unexpected text\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test011() { + this.runConformTest( + new String[] { + "X.java", + " /**\n" + + " * Valid string references \n" + + " *\n" + + " * @see \"Valid normal string\"\n" + + " * @see \"Valid \\\"string containing\\\" \\\"double-quote\\\"\"\n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + // URL Link references + public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid URL link references \n" + + " *\n" + + " * @see invalid no text allowed after the href\n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see invalid no text allowed after the href\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test013() { + this.runConformTest( + new String[] { + "X.java", + " /**\n" + + " * Valid URL link references \n" + + " *\n" + + " * @see Valid URL link reference\n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + // @see Classes references + public void test020() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + " /**\n" + + " * Valid local classes references \n" + + " *\n" + + " * @see Visibility Valid ref: local class \n" + + " * @see Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see AbstractVisibility.AvcPublic Valid ref: visible inner class of local class \n" + + " * @see test.Visibility Valid ref: local class \n" + + " * @see test.Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see test.AbstractVisibility.AvcPublic Valid ref: visible inner class of local class \n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test021() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + " /**\n" + + " * Invalid local classes references \n" + + " *\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see Unknown Invalid ref: unknown class \n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 5)\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 7)\n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.VcPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 8)\n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 9)\n" + + " * @see Unknown Invalid ref: unknown class \n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test022() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + // Inner classes are not visible in generated documentation + //" * @see VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test023() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + " /**\n" + + " * Invalid external classes references \n" + + " *\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n"); + } + + public void test024() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see test.copy.VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + // Inner classes are not visible in generated documentation + //" * @see test.copy.VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + } + ); + } + + // @see Field references + public void test030() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + " /**\n" + + " * Valid local class field references\n" + + " *\n" + + " * @see #x Valid ref: accessible field\n" + + " * @see Visibility#vf_public Valid ref: visible field\n" + + " * @see Visibility.VcPublic#vf_public Valid ref: visible field in visible inner class\n" + + " */\n" + + "public class X {\n" + + " int x;\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test031() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + " /**\n" + + " * Invalid local class field references\n" + + " *\n" + + " * @see #x Invalid ref: non existent field\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 5)\n" + + " * @see #x Invalid ref: non existent field\n" + + " ^\n" + + "Javadoc: x cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 10)\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + public void test032() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + " /**\n" + + " * Valid other package visible class fields references\n" + + " *\n" + + " * @see VisibilityPublic#vf_public Valid ref to visible field of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vf_public Valid ref to visible field of other package public inner class\n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test033() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPackage#unknown Invalid ref to non existent field of other package non visible class\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see VisibilityPackage#unknown Invalid ref to non existent field of other package non visible class\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + // @see method references + public void test040() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + " /**\n" + + " * Valid local methods references with array\n" + + " * \n" + + " * @see #smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) Valid local method reference\n" + + " * @see #smr_foo(char[], int[][], String[][][], Vector[][][][]) Valid local method reference\n" + + " * @see #smr_foo(char[],int[][],java.lang.String[][][],java.util.Vector[][][][]) Valid local method reference\n" + + " */ \n" + + "public class X {\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) {\n" + + " }\n" + + "}\n" }); + } + + public void test041() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + " /**\n" + + " * Invalid local methods references with array (non applicable arrays)\n" + + " * \n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][]) Invalid ref: invalid arguments declaration\n" + + " */ \n" + + "public class X {\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int[][], String[][][], Vector[][][])\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test042() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see #smr_foo() Valid local method reference\n" + + " * @see #smr_foo(boolean a1,int a2,byte a3,short a4,char a5,long a6,float a7,double a8) Valid local method reference\n" + + " * @see #smr_foo(java.lang.String, java.lang.String, int) Valid local method reference \n" + + " * @see #smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test043() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " */ \n" + + "public class X {\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test044() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(float, long, char, short, byte, int, boolean) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(String, String, int, String) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " */ \n" + + "public class X {\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see #smr_foo(float, long, char, short, byte, int, boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (float, long, char, short, byte, int, boolean)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @see #smr_foo(String, String, int, String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (String, String, int, String)\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (boolean)\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^^^^\n" + + "Javadoc: Hashtable cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^\n" + + "Javadoc: Vector cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test045() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see X#smr_foo() Valid local method reference\n" + + " * @see X#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see X#smr_foo(String x, java.lang.String y, int z) Valid local method reference \n" + + " * @see X#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + "public class X {\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test046() { + this.runConformTest( + new String[] { + "test/deep/qualified/name/p/X.java", + "package test.deep.qualified.name.p;\n" + + "import java.util.Vector;\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see test.deep.qualified.name.p.X#smr_foo() Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String x, java.lang.String y, int z) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + "public class X {\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test047() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + " /**\n" + + " * Valid package class methods references\n" + + " * \n" + + " * @see Visibility#vm_public() Valid ref: visible method\n" + + " * @see Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " * @see test.Visibility#vm_public() Valid ref: visible method\n" + + " * @see test.Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " */ \n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test048() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + " /**\n" + + " * Invalid package class methods references (non-existence)\n" + + " * \n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " */ \n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 5)\n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility.VcPublic\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 7)\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Visibility.Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test049() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + " /**\n" + + " * Invalid package class methods references (non-visible)\n" + + " * \n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " */ \n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 5)\n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility.VcPublic is not visible\n" + + "----------\n"); + } + + public void test050() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + " /**\n" + + " * Invalid package class methods references (non-applicable)\n" + + " * \n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " */ \n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 5)\n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility is not applicable for the arguments (String)\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility.VcPublic is not applicable for the arguments (Integer, byte)\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility.VcPublic is not applicable for the arguments (Double, Boolean)\n" + + "----------\n"); + } + + public void test051() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + " /**\n" + + " * Invalid other package non visible class methods references (non existent/visible arguments)\n" + + " * \n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " */ \n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in test\\X.java (at line 2)\n"+ + " import test.copy.*;\n"+ + " ^^^^^^^^^\n"+ + "The import test.copy is never used\n"+ + "----------\n"+ + "2. ERROR in test\\X.java (at line 6)\n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 7)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n"); + } + + public void test052() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test053() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see test.copy.VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + "public class X {\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=253750 + public void test054() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "/**\n" + + " *
      \n" + + " *
    • {@link Entry}
    • \n" + + " *
    \n" + + " */\n" + + "public interface X extends Map {\n" + + " int i = 0;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n"+ + " import java.util.Map.Entry;\n"+ + " ^^^^^^^^^^^^^^^^^^^\n"+ + "The import java.util.Map.Entry is never used\n"+ + "----------\n"+ + "2. ERROR in X.java (at line 6)\n" + + " *
  • {@link Entry}
  • \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n"); + return; + } + runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "/**\n" + + " *
      \n" + + " *
    • {@link Entry}
    • \n" + + " *
    \n" + + " */\n" + + "public interface X extends Map {\n" + + " int i;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " int i;\n" + + " ^\n" + + "The blank final field i may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=253750 - variation + public void test055() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "/**\n" + + " *
      \n" + + " *
    • {@link Entry}
    • \n" + + " *
    \n" + + " */\n" + + "public interface X extends Map {\n" + + " Entry e = null;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " *
  • {@link Entry}
  • \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=253750 + public void test056() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "/**\n" + + " *
      \n" + + " *
    • {@link Entry}
    • \n" + + " *
    \n" + + " */\n" + + "public interface X extends Map {\n" + + " Entry e = null;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n"+ + " import java.util.Map.Entry;\n"+ + " ^^^^^^^^^^^^^^^^^^^\n"+ + "The import java.util.Map.Entry is never used\n"+ + "----------\n"+ + "2. ERROR in X.java (at line 6)\n" + + " *
  • {@link Entry}
  • \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n"); + return; + } + runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "/**\n" + + " *
      \n" + + " *
    • {@link Entry}
    • \n" + + " *
    \n" + + " */\n" + + "public interface X extends Map {\n" + + " Entry e;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Entry e;\n" + + " ^\n" + + "The blank final field e may not have been initialized\n" + + "----------\n"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForConstructor.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForConstructor.java new file mode 100644 index 0000000000..cacdd04c1a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForConstructor.java @@ -0,0 +1,964 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTestForConstructor extends JavadocTest { + public JavadocTestForConstructor(String name) { + super(name); + } + public static Class javadocTestClass() { + return JavadocTestForConstructor.class; + } + + public static Test suite() { + return buildAllCompliancesTestSuite(javadocTestClass()); + } + static { // Use this static to initialize TESTS_NAMES (String[]) , TESTS_RANGE (int[2]), TESTS_NUMBERS (int[]) + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return options; + } + + /* (non-Javadoc) + * Test @deprecated tag + */ + public void test001() { + this.runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " {\n" + + " new Z();\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * \n" + + " * ** ** ** ** @deprecated */\n" + + " public Z() { \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Z();\n" + + " ^^^\n" + + "The constructor Z() is deprecated\n" + + "----------\n", + null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + + public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " {\n" + + " new Z(2);\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * Valid tags with deprecation at end\n" + + " *\n" + + " * @param value Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public Z(int value) { \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Z(2);\n" + + " ^^^^\n" + + "The constructor Z(int) is deprecated\n" + + "----------\n"); + } + + public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " {\n" + + " new Z();\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * Invalid javadoc tags with valid deprecation at end\n" + + " *\n" + + " * @param\n" + + " * @return\n" + + " * @throws Unknown\n" + + " * @see \"Invalid\n" + + " * @see Unknown\n" + + " * @param x\n" + + " * @deprecated\n" + + " */\n" + + " public Z() { \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Z();\n" + + " ^^^\n" + + "The constructor Z() is deprecated\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Z.java (at line 5)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "2. ERROR in Z.java (at line 6)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in Z.java (at line 7)\n" + + " * @throws Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in Z.java (at line 8)\n" + + " * @see \"Invalid\n" + + " ^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "5. ERROR in Z.java (at line 9)\n" + + " * @see Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in Z.java (at line 10)\n" + + " * @param x\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + /* + * (non-Javadoc) Test @see tag + */ + // String references + public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid string references \n" + + " *\n" + + " * @see \"unterminated string\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see \"unterminated string\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test011() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid string references \n" + + " *\n" + + " * @see \"Valid normal string\"\n" + + " * @see \"Valid \\\"string containing\\\" \\\"double-quote\\\"\"\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }); + } + + // URL Link references + public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid URL link references \n" + + " *\n" + + " * @see invalid no text allowed after the href\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see invalid no text allowed after the href\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test013() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid URL link references \n" + + " *\n" + + " * @see Valid URL link reference\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }); + } + + // @see Classes references + public void test020() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local classes references \n" + + " *\n" + + " * @see Visibility Valid ref: local class \n" + + " * @see Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see AbstractVisibility.AvcPublic Valid ref: visible inner class of local class \n" + + " * @see test.Visibility Valid ref: local class \n" + + " * @see test.Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see test.AbstractVisibility.AvcPublic Valid ref: visible inner class of local class \n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }); + } + + public void test021() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local classes references \n" + + " *\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see Unknown Invalid ref: unknown class \n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.VcPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see Unknown Invalid ref: unknown class \n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test022() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + // Inner classes are not visible in generated documentation + //" * @see VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test023() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid external classes references \n" + + " *\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n"); + } + + public void test024() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see test.copy.VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + // Inner classes are not visible in generated documentation + //" * @see test.copy.VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" + } + ); + } + + // @see Field references + public void test030() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " int x;\n" + + " /**\n" + + " * Valid local class field references\n" + + " *\n" + + " * @see #x Valid ref: accessible field\n" + + " * @see Visibility#vf_public Valid ref: visible field\n" + + " * @see Visibility.VcPublic#vf_public Valid ref: visible field in visible inner class\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }); + } + + public void test031() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local class field references\n" + + " *\n" + + " * @see #x Invalid ref: non existent field\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see #x Invalid ref: non existent field\n" + + " ^\n" + + "Javadoc: x cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + public void test032() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Valid other package visible class fields references\n" + + " *\n" + + " * @see VisibilityPublic#vf_public Valid ref to not visible field of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vf_public Valid ref to not visible field of other package public inner class\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test033() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPackage#unknown Invalid ref to non existent field of other package non visible class\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPackage#unknown Invalid ref to non existent field of other package non visible class\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 11)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 12)\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + // @see method references + public void test040() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references with array\n" + + " * \n" + + " * @see #smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) Valid local method reference\n" + + " * @see #smr_foo(char[], int[][], String[][][], Vector[][][][]) Valid local method reference\n" + + " * @see #smr_foo(char[],int[][],java.lang.String[][][],java.util.Vector[][][][]) Valid local method reference\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) {\n" + + " }\n" + + "}\n" }); + } + + public void test041() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references with array (non applicable arrays)\n" + + " * \n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][]) Invalid ref: invalid arguments declaration\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int[][], String[][][], Vector[][][])\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test042() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see #smr_foo() Valid local method reference\n" + + " * @see #smr_foo(boolean a1,int a2,byte a3,short a4,char a5,long a6,float a7,double a8) Valid local method reference\n" + + " * @see #smr_foo(java.lang.String, java.lang.String, int) Valid local method reference \n" + + " * @see #smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test043() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test044() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(float, long, char, short, byte, int, boolean) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(String, String, int, String) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #smr_foo(float, long, char, short, byte, int, boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (float, long, char, short, byte, int, boolean)\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(String, String, int, String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (String, String, int, String)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (boolean)\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^^^^\n" + + "Javadoc: Hashtable cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^\n" + + "Javadoc: Vector cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test045() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see X#smr_foo() Valid local method reference\n" + + " * @see X#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see X#smr_foo(String x, java.lang.String y, int z) Valid local method reference \n" + + " * @see X#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test046() { + this.runConformTest( + new String[] { + "test/deep/qualified/name/p/X.java", + "package test.deep.qualified.name.p;\n" + + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see test.deep.qualified.name.p.X#smr_foo() Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String x, java.lang.String y, int z) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test047() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid package class methods references\n" + + " * \n" + + " * @see Visibility#vm_public() Valid ref: visible method\n" + + " * @see Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " * @see test.Visibility#vm_public() Valid ref: visible method\n" + + " * @see test.Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + "}\n" }); + } + + public void test048() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package class methods references (non-existence)\n" + + " * \n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility.VcPublic\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Visibility.Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test049() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package class methods references (non-visible)\n" + + " * \n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility.VcPublic is not visible\n" + + "----------\n"); + } + + public void test050() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package class methods references (non-applicable)\n" + + " * \n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility is not applicable for the arguments (String)\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility.VcPublic is not applicable for the arguments (Integer, byte)\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility.VcPublic is not applicable for the arguments (Double, Boolean)\n" + + "----------\n"); + } + + public void test051() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class methods references (non existent/visible arguments)\n" + + " * \n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " */ \n" + + " public X() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in test\\X.java (at line 2)\n"+ + " import test.copy.*;\n"+ + " ^^^^^^^^^\n"+ + "The import test.copy is never used\n"+ + "----------\n"+ + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n"); + } + + public void test052() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + "public class X {\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test053() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see test.copy.VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + " public X() {\n" + + " }\n" + + "}\n" }); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForField.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForField.java new file mode 100644 index 0000000000..5a964eb4ed --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForField.java @@ -0,0 +1,1061 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTestForField extends JavadocTest { + public JavadocTestForField(String name) { + super(name); + } + public static Class javadocTestClass() { + return JavadocTestForField.class; + } + public static Test suite() { + return buildAllCompliancesTestSuite(javadocTestClass()); + } + static { // Use this static to initialize testNames (String[]) , testRange (int[2]), testNumbers (int[]) + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return options; + } + + /* + * (non-Javadoc) Test @param tag + */ + public void test001() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "/**\n" + + " * Valid field javadoc\n" + + " * @author ffr\n" + + " */\n" + + " public int x;\n" + + "}\n" }); + } + + public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid field javadoc\n" + + " * @param x Invalid tag\n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param x Invalid tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid field javadoc\n" + + " * @throws NullPointerException Invalid tag\n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @throws NullPointerException Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid field javadoc\n" + + " * @exception NullPointerException Invalid tag\n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @exception NullPointerException Invalid tag\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid class javadoc\n" + + " * @return Invalid tag\n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @return Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid class javadoc\n" + + " * @exception NullPointerException Invalid tag\n" + + " * @throws NullPointerException Invalid tag\n" + + " * @return Invalid tag\n" + + " * @param x Invalid tag\n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @exception NullPointerException Invalid tag\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @throws NullPointerException Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @return Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " * @param x Invalid tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + /* + * (non-Javadoc) + * Test @deprecated tag + */ + public void test007() { + this.runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " int x;\n" + + " {\n" + + " x=(new Z()).z;\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * \n" + + " * ** ** ** ** @deprecated */\n" + + " public int z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " x=(new Z()).z;\n" + + " ^\n" + + "The field Z.z is deprecated\n" + + "----------\n", + null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + + public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int x;\n" + + " {\n" + + " x=(new Z()).z;\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * Invalid tags with deprecation\n" + + " *\n" + + " * @param x\n" + + " * @return\n" + + " * @throws NullPointerException\n" + + " * @exception IllegalArgumentException\n" + + " * @see X\n" + + " * @deprecated\n" + + " */\n" + + " public int z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " x=(new Z()).z;\n" + + " ^\n" + + "The field Z.z is deprecated\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Z.java (at line 5)\n" + + " * @param x\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in Z.java (at line 6)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in Z.java (at line 7)\n" + + " * @throws NullPointerException\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in Z.java (at line 8)\n" + + " * @exception IllegalArgumentException\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + /* + * (non-Javadoc) + * Test @see tag + */ + // String references + public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid string references \n" + + " *\n" + + " * @see \"unterminated string\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see \"unterminated string\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test011() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid string references \n" + + " *\n" + + " * @see \"Valid normal string\"\n" + + " * @see \"Valid \\\"string containing\\\" \\\"double-quote\\\"\"\n" + + " */\n" + + " public int x;\n" + + "}\n" }); + } + + // URL Link references + public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid URL link references \n" + + " *\n" + + " * @see invalidinvalid no text allowed after the href\n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see invalidinvalid no text allowed after the href\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test013() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid URL link references \n" + + " *\n" + + " * @see Valid URL link reference\n" + + " */\n" + + " public int x;\n" + + "}\n" }); + } + + // @see Classes references + public void test020() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local classes references \n" + + " *\n" + + " * @see Visibility Valid ref: local class \n" + + " * @see Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see AbstractVisibility.AvcPublic Valid ref: visible inherited inner class of local class \n" + + " * @see test.Visibility Valid ref: local class \n" + + " * @see test.Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see test.AbstractVisibility.AvcPublic Valid ref: visible inherited inner class of local class \n" + + " */\n" + + " public int x;\n" + + "}\n" }); + } + + public void test021() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local classes references \n" + + " *\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see Unknown Invalid ref: unknown class \n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.VcPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see Unknown Invalid ref: unknown class \n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test022() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + // Inner classes are not visible in generated documentation + //" * @see VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + " public int x;\n" + + "}\n" + } + ); + } + + public void test023() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid external classes references \n" + + " *\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n"); + } + + public void test024() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see test.copy.VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + // Inner classes are not visible in generated documentation + //" * @see test.copy.VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + " public int x;\n" + + "}\n" + } + ); + } + + // @see Field references + public void test030() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local class field references\n" + + " *\n" + + " * @see #str Valid ref: accessible field\n" + + " * @see Visibility#vf_public Valid ref: visible field\n" + + " * @see Visibility.VcPublic#vf_public Valid ref: visible field in visible inner class\n" + + " */\n" + + " public int x;\n" + + " public String str;\n" + + "}\n" }); + } + + public void test031() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local class field references\n" + + " *\n" + + " * @see #str Invalid ref: non existent field\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see #str Invalid ref: non existent field\n" + + " ^^^\n" + + "Javadoc: str cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + public void test032() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPublic#vf_public Valid ref to not visible field of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vf_public Valid ref to not visible field of other package public inner class\n" + + " */\n" + + " public int x;\n" + + "}\n" + } + ); + } + + public void test033() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPackage#unknown Invalid ref: non visible class (non existent field)\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " */\n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPackage#unknown Invalid ref: non visible class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 11)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 12)\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + // @see method references + public void test040() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references with array\n" + + " * \n" + + " * @see #smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) Valid local method reference\n" + + " * @see #smr_foo(char[], int[][], String[][][], Vector[][][][]) Valid local method reference\n" + + " * @see #smr_foo(char[],int[][],java.lang.String[][][],java.util.Vector[][][][]) Valid local method reference\n" + + " */ \n" + + " public int x;\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) {\n" + + " }\n" + + "}\n" }); + } + + public void test041() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references with array (non applicable arrays)\n" + + " * \n" + + " * @see #smr_foo(char , int[][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " */ \n" + + " public int x;\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(char , int[][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char, int[][], String[][][], Vector[][][][])\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test042() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see #smr_foo() Valid local method reference\n" + + " * @see #smr_foo(boolean a1,int a2,byte a3,short a4,char a5,long a6,float a7,double a8) Valid local method reference\n" + + " * @see #smr_foo(java.lang.String, java.lang.String, int) Valid local method reference \n" + + " * @see #smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public int x;\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test043() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " */ \n" + + " public int x;\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test044() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(float, long, char, short, byte, int, boolean) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(String, String, int, String) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " */ \n" + + " public int x;\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #smr_foo(float, long, char, short, byte, int, boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (float, long, char, short, byte, int, boolean)\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(String, String, int, String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (String, String, int, String)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (boolean)\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^^^^\n" + + "Javadoc: Hashtable cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^\n" + + "Javadoc: Vector cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test045() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see X#smr_foo() Valid local method reference\n" + + " * @see X#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see X#smr_foo(String x, java.lang.String y, int z) Valid local method reference \n" + + " * @see X#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public int x;\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test046() { + this.runConformTest( + new String[] { + "test/deep/qualified/name/p/X.java", + "package test.deep.qualified.name.p;\n" + + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see test.deep.qualified.name.p.X#smr_foo() Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String x, java.lang.String y, int z) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public int x;\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test047() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid package class methods references\n" + + " * \n" + + " * @see Visibility#vm_public() Valid ref: visible method\n" + + " * @see Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " * @see test.Visibility#vm_public() Valid ref: visible method\n" + + " * @see test.Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " */ \n" + + " public int x;\n" + + "}\n" }); + } + + public void test048() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package class methods references (non-existence)\n" + + " * \n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " */ \n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility.VcPublic\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Visibility.Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test049() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package class methods references (non-visible)\n" + + " * \n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " */ \n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility.VcPublic is not visible\n" + + "----------\n"); + } + + public void test050() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package class methods references (non-applicable)\n" + + " * \n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " */ \n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility is not applicable for the arguments (String)\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility.VcPublic is not applicable for the arguments (Integer, byte)\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility.VcPublic is not applicable for the arguments (Double, Boolean)\n" + + "----------\n"); + } + + public void test051() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class methods references (non existent/visible arguments)\n" + + " * \n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " */ \n" + + " public int x;\n" + + "}\n" }, + "----------\n" + + "1. WARNING in test\\X.java (at line 2)\n"+ + " import test.copy.*;\n"+ + " ^^^^^^^^^\n"+ + "The import test.copy is never used\n"+ + "----------\n"+ + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n"); + } + + public void test052() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + "public class X {\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + " public int x;\n" + + "}\n" + } + ); + } + + public void test053() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see test.copy.VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + " public int x;\n" + + "}\n" }); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=451418, [1.8][compiler] NPE at ParameterizedGenericMethodBinding.computeCompatibleMethod18 + public void test451418() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + + runNegativeTest( + new String[] { + "X.java", + "class Repro {\n" + + " public static FieldSet emptySet() { return null; }\n" + + " /**\n" + + " * {@link #emptySet} \n" + + " */\n" + + " public int i;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static FieldSet emptySet() { return null; }\n" + + " ^^^^^^^^\n" + + "FieldSet cannot be resolved to a type\n" + + "----------\n"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForInterface.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForInterface.java new file mode 100644 index 0000000000..8205e09b41 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForInterface.java @@ -0,0 +1,2262 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTestForInterface extends JavadocTest { + public JavadocTestForInterface(String name) { + super(name); + } + public static Class javadocTestClass() { + return JavadocTestForInterface.class; + } + + public static Test suite() { + return buildAllCompliancesTestSuite(javadocTestClass()); + } + static { // Use this static to initialize testNames (String[]) , testRange (int[2]), testNumbers (int[]) + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return options; + } + + /* + * (non-Javadoc) + * Javadoc comment of Interface + */ + // Unexpected tag + public void test001() { + this.runConformTest( + new String[] { + "IX.java", + " /**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }); + } + + public void test002() { + this.runNegativeTest( + new String[] { + "IX.java", + " /**\n" + + " * Invalid class javadoc\n" + + " * @param x Invalid tag\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 3)\n" + + " * @param x Invalid tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test003() { + this.runNegativeTest( + new String[] { + "IX.java", + " /**\n" + + " * Invalid class javadoc\n" + + " * @throws NullPointerException Invalid tag\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 3)\n" + + " * @throws NullPointerException Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test004() { + this.runNegativeTest( + new String[] { + "IX.java", + " /**\n" + + " * Invalid class javadoc\n" + + " * @exception NullPointerException Invalid tag\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 3)\n" + + " * @exception NullPointerException Invalid tag\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test005() { + this.runNegativeTest( + new String[] { + "IX.java", + " /**\n" + + " * Invalid class javadoc\n" + + " * @return Invalid tag\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 3)\n" + + " * @return Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test006() { + this.runNegativeTest( + new String[] { + "IX.java", + " /**\n" + + " * Invalid class javadoc\n" + + " * @exception NullPointerException Invalid tag\n" + + " * @throws NullPointerException Invalid tag\n" + + " * @return Invalid tag\n" + + " * @param x Invalid tag\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 3)\n" + + " * @exception NullPointerException Invalid tag\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in IX.java (at line 4)\n" + + " * @throws NullPointerException Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in IX.java (at line 5)\n" + + " * @return Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in IX.java (at line 6)\n" + + " * @param x Invalid tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test007() { + this.runConformTest( + new String[] { + "IX.java", + " /**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + " /**\n" + + " * Invalid javadoc comment\n" + + " */\n" + + "}\n" } + ); + } + + public void test008() { + this.runConformTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " public void foo();\n" + + " /**\n" + + " * Invalid javadoc comment\n" + + " */\n" + + "}\n" } + ); + } + + public void test009() { + this.runConformTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid javadoc comment\n" + + " */\n" + + "}\n" } + ); + } + + + // @see tag + public void test010() { + this.runNegativeTest( + new String[] { + "IX.java", + " /**\n" + + " * Invalid string references \n" + + " *\n" + + " * @see \"unterminated string\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 4)\n" + + " * @see \"unterminated string\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in IX.java (at line 5)\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test011() { + this.runConformTest( + new String[] { + "IX.java", + " /**\n" + + " * Valid string references \n" + + " *\n" + + " * @see \"Valid normal string\"\n" + + " * @see \"Valid \\\"string containing\\\" \\\"double-quote\\\"\"\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }); + } + + public void test012() { + this.runNegativeTest( + new String[] { + "IX.java", + " /**\n" + + " * Invalid URL link references \n" + + " *\n" + + " * @see invalidinvalid no text allowed after the href\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 4)\n" + + " * @see invalidinvalid no text allowed after the href\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test013() { + this.runConformTest( + new String[] { + "IX.java", + " /**\n" + + " * Valid URL link references \n" + + " *\n" + + " * @see Valid URL link reference\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }); + } + + // @see Classes references + public void test020() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + " /**\n" + + " * Valid local classes references \n" + + " *\n" + + " * @see Visibility Valid ref: local class \n" + + " * @see Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see AbstractVisibility.AvcPublic Valid ref: visible inner class of local class \n" + + " * @see test.Visibility Valid ref: local class \n" + + " * @see test.Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see test.AbstractVisibility.AvcPublic Valid ref: visible inner class of local class \n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }); + } + + public void test021() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + " /**\n" + + " * Invalid local classes references \n" + + " *\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see Unknown Invalid ref: unknown class \n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 5)\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 6)\n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 7)\n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.VcPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\IX.java (at line 8)\n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\IX.java (at line 9)\n" + + " * @see Unknown Invalid ref: unknown class \n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test022() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.*;\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + // Inner classes are not visible in generated documentation + //" * @see VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" + } + ); + } + + public void test023() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.*;\n" + + " /**\n" + + " * Invalid external classes references \n" + + " *\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 6)\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 7)\n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n"); + } + + public void test024() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see test.copy.VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + // Inner classes are not visible in generated documentation + //" * @see test.copy.VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" + } + ); + } + + // @see Field references + public void test030() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + " /**\n" + + " * Valid local class field references\n" + + " *\n" + + " * @see Visibility#vf_public Valid ref: visible field\n" + + " * @see Visibility.VcPublic#vf_public Valid ref: visible field in visible inner class\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }); + } + + public void test031() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + " /**\n" + + " * Invalid local class field references\n" + + " *\n" + + " * @see #x Invalid ref: non existent field\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 5)\n" + + " * @see #x Invalid ref: non existent field\n" + + " ^\n" + + "Javadoc: x cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 6)\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 7)\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "4. ERROR in test\\IX.java (at line 8)\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\IX.java (at line 9)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "6. ERROR in test\\IX.java (at line 10)\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + public void test032() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.*;\n" + + " /**\n" + + " * Valid other package visible class fields references\n" + + " *\n" + + " * @see VisibilityPublic#vf_public Valid ref to not visible field of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vf_public Valid ref to not visible field of other package public inner class\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" + } + ); + } + + public void test033() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.*;\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPackage#unknown Invalid ref to non existent field of other package non visible class\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 6)\n" + + " * @see VisibilityPackage#unknown Invalid ref to non existent field of other package non visible class\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 7)\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 8)\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "4. ERROR in test\\IX.java (at line 9)\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\IX.java (at line 10)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "6. ERROR in test\\IX.java (at line 11)\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + // @see method references + public void test040() { + this.runConformTest( + new String[] { + "IX.java", + "import java.util.Vector;\n" + + " /**\n" + + " * Valid local methods references with array\n" + + " * \n" + + " * @see #smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) Valid local method reference\n" + + " * @see #smr_foo(char[], int[][], String[][][], Vector[][][][]) Valid local method reference\n" + + " * @see #smr_foo(char[],int[][],java.lang.String[][][],java.util.Vector[][][][]) Valid local method reference\n" + + " */ \n" + + "public interface IX {\n" + + " public void foo();\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra);\n" + + "}\n" }); + } + + public void test041() { + this.runNegativeTest( + new String[] { + "IX.java", + "import java.util.Vector;\n" + + " /**\n" + + " * Invalid local methods references with array (non applicable arrays)\n" + + " * \n" + + " * @see #smr_foo(char[] , int[][], String[][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " */ \n" + + "public interface IX {\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra);\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " * @see #smr_foo(char[] , int[][], String[][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type IX is not applicable for the arguments (char[], int[][], String[][], Vector[][][][])\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test042() { + this.runConformTest( + new String[] { + "IX.java", + "import java.util.Vector;\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see #smr_foo() Valid local method reference\n" + + " * @see #smr_foo(boolean a1,int a2,byte a3,short a4,char a5,long a6,float a7,double a8) Valid local method reference\n" + + " * @see #smr_foo(java.lang.String, java.lang.String, int) Valid local method reference \n" + + " * @see #smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + "public interface IX {\n" + + " public void foo();\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo();\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d);\n" + + " public void smr_foo(String str1, java.lang.String str2, int i);\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b);\n" + + "}\n" }); + } + + public void test043() { + this.runNegativeTest( + new String[] { + "IX.java", + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " */ \n" + + "public interface IX {\n" + + " public void foo();\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 4)\n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type IX\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test044() { + this.runNegativeTest( + new String[] { + "IX.java", + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(int) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(float, long, char, short, byte, int, boolean) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(String, String, int, String) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " */ \n" + + "public interface IX {\n" + + " public void foo();\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo();\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d);\n" + + " public void smr_foo(String str1, java.lang.String str2, int i);\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b);\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 4)\n" + + " * @see #smr_foo(int) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo() in the type IX is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in IX.java (at line 5)\n" + + " * @see #smr_foo(float, long, char, short, byte, int, boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type IX is not applicable for the arguments (float, long, char, short, byte, int, boolean)\n" + + "----------\n" + + "3. ERROR in IX.java (at line 6)\n" + + " * @see #smr_foo(String, String, int, String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type IX is not applicable for the arguments (String, String, int, String)\n" + + "----------\n" + + "4. ERROR in IX.java (at line 7)\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type IX is not applicable for the arguments (boolean)\n" + + "----------\n" + + "5. ERROR in IX.java (at line 8)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^^^^\n" + + "Javadoc: Hashtable cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in IX.java (at line 8)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^\n" + + "Javadoc: Vector cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test045() { + this.runConformTest( + new String[] { + "IX.java", + "import java.util.Vector;\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see IX#smr_foo() Valid local method reference\n" + + " * @see IX#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see IX#smr_foo(String x, java.lang.String y, int z) Valid local method reference \n" + + " * @see IX#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + "public interface IX {\n" + + " public void smr_foo();\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d);\n" + + " public void smr_foo(String str1, java.lang.String str2, int i);\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b);\n" + + "}\n" }); + } + + public void test046() { + this.runConformTest( + new String[] { + "test/deep/qualified/name/p/IX.java", + "package test.deep.qualified.name.p;\n" + + "import java.util.Vector;\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see test.deep.qualified.name.p.IX#smr_foo() Valid local method reference\n" + + " * @see test.deep.qualified.name.p.IX#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.IX#smr_foo(String x, java.lang.String y, int z) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.IX#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + "public interface IX {\n" + + " public void smr_foo();\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d);\n" + + " public void smr_foo(String str1, java.lang.String str2, int i);\n" + + " public void smr_foo(java.util.Hashtable h, Vector v, boolean b);\n" + + "}\n" }); + } + + public void test047() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + " /**\n" + + " * Valid package class methods references\n" + + " * \n" + + " * @see Visibility#vm_public() Valid ref: visible method\n" + + " * @see Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " * @see test.Visibility#vm_public() Valid ref: visible method\n" + + " * @see test.Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " */ \n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }); + } + + public void test048() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + " /**\n" + + " * Invalid package class methods references (non-existence)\n" + + " * \n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " */ \n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 5)\n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 6)\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility.VcPublic\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 7)\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in test\\IX.java (at line 8)\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Visibility.Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test049() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + " /**\n" + + " * Invalid package class methods references (non-visible)\n" + + " * \n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " */ \n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 5)\n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility is not visible\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 6)\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 7)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility.VcPublic is not visible\n" + + "----------\n"); + } + + public void test050() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + " /**\n" + + " * Invalid package class methods references (non-applicable)\n" + + " * \n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " */ \n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 5)\n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 6)\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility is not applicable for the arguments (String)\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 7)\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility.VcPublic is not applicable for the arguments (Integer, byte)\n" + + "----------\n" + + "4. ERROR in test\\IX.java (at line 8)\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility.VcPublic is not applicable for the arguments (Double, Boolean)\n" + + "----------\n"); + } + + public void test051() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.*;\n" + + " /**\n" + + " * Invalid other package non visible class methods references (non existent/visible arguments)\n" + + " * \n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. WARNING in test\\IX.java (at line 2)\n"+ + " import test.copy.*;\n"+ + " ^^^^^^^^^\n"+ + "The import test.copy is never used\n"+ + "----------\n"+ + "2. ERROR in test\\IX.java (at line 6)\n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 7)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n"); + } + + public void test052() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" + } + ); + } + + public void test053() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see test.copy.VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }); + } + + /* + * (non-Javadoc) + * Javadoc method comment in Interface + */ + // @deprecated tag + public void test060() { + this.runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public void foo(IX x) {\n" + + " x.foo();\n" + + " }\n" + + "}\n", + "IX.java", + "public interface IX {\n" + + " /** \n" + + " * \n" + + " * ** ** ** ** @deprecated */\n" + + " public void foo();\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " x.foo();\n" + + " ^^^^^\n" + + "The method foo() from the type IX is deprecated\n" + + "----------\n", + null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + + public void test061() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /** @deprecated */\n" + + " int x=0;\n" + + " /**\n" + + " * @see #x\n" + + " */\n" + + " void foo();\n" + + "}\n", + "IY.java", + "/** @deprecated */\n" + + "public interface IY {\n" + + " int y=0;\n" + + " /**\n" + + " * @see IX#x\n" + + " * @see IY\n" + + " * @see IY#y\n" + + " */\n" + + " void foo();\n" + + "}\n", + "X.java", + "public class X {\n" + + " int x;\n" + + " /**\n" + + " * @see IX#x\n" + + " * @see IY\n" + + " * @see IY#y\n" + + " */\n" + + " void foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see IX#x\n" + + " ^\n" + + "Javadoc: The field IX.x is deprecated\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @see IY\n" + + " ^^\n" + + "Javadoc: The type IY is deprecated\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @see IY#y\n" + + " ^^\n" + + "Javadoc: The type IY is deprecated\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @see IY#y\n" + + " ^\n" + + "Javadoc: The field IY.y is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test062() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(IX x) {\n" + + " x.foo(2);\n" + + " }\n" + + "}\n", + "IX.java", + "public interface IX {\n" + + " /** \n" + + " * Valid tags with deprecation\n" + + " *\n" + + " * @param x Valid param tag\n" + + " * @return Valid return tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(int x);\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " x.foo(2);\n" + + " ^^^^^^\n" + + "The method foo(int) from the type IX is deprecated\n" + + "----------\n"); + } + + public void test063() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo(IX x) {\n" + + " x.foo(2);\n" + + " }\n" + + "}\n", + "IX.java", + "public interface IX {\n" + + " /** \n" + + " * Invalid javadoc tags with valid deprecation\n" + + " *\n" + + " * @param\n" + + " * @return String\n" + + " * @throws Unknown\n" + + " * @see \"Invalid\n" + + " * @see Unknown\n" + + " * @param x\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(int x);\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " x.foo(2);\n" + + " ^^^^^^\n" + + "The method foo(int) from the type IX is deprecated\n" + + "----------\n" + + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "2. ERROR in IX.java (at line 7)\n" + + " * @throws Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in IX.java (at line 8)\n" + + " * @see \"Invalid\n" + + " ^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "4. ERROR in IX.java (at line 9)\n" + + " * @see Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in IX.java (at line 10)\n" + + " * @param x\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "6. ERROR in IX.java (at line 13)\n" + + " public String foo(int x);\n" + + " ^\n" + + "Javadoc: Missing tag for parameter x\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // @param tag + public void test064() { + this.runConformTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Valid @param: no tags, no args\n" + + " * Valid @throws/@exception: no tags, no thrown exception\n" + + " */\n" + + " public void foo();\n" + + "}\n" }); + } + + public void test065() { + this.runConformTest(new String[] { + "IX.java", + "public interface IX {\n" + + " public void foo();\n" + + "}\n" }); + } + + public void test066() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid @param declaration: no arguments, 2 declared tags\n" + + " * @param x\n" + + " * Invalid param: not an argument on 2 lines\n" + + " * @param x Invalid param: not an argument\n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 4)\n" + + " * @param x\n" + + " ^\n" + + "Javadoc: Parameter x is not declared\n" + + "----------\n" + + "2. ERROR in IX.java (at line 6)\n" + + " * @param x Invalid param: not an argument\n" + + " ^\n" + + "Javadoc: Parameter x is not declared\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test067() { + this.runConformTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " \n" + + " /**\n" + + " * Valid @param declaration: 3 arguments, 3 tags in right order\n" + + " * @param a Valid param\n" + + " * @param b Valid param \n" + + " * @param c Valid param\n" + + " */\n" + + " public void foo(int a, int b, int c);\n" + + "}\n" }); + } + + public void test068() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid @param declaration: 3 arguments, 3 correct tags in right order + 2 additional\n" + + " * @param a Valid param\n" + + " * @param x Invalid param: not an argument\n" + + " * @param b Valid param \n" + + " * @param y Invalid param: not an argument\n" + + " * @param c Valid param\n" + + " */\n" + + " public void foo(char a, char b, char c);\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " * @param x Invalid param: not an argument\n" + + " ^\n" + + "Javadoc: Parameter x is not declared\n" + + "----------\n" + + "2. ERROR in IX.java (at line 7)\n" + + " * @param y Invalid param: not an argument\n" + + " ^\n" + + "Javadoc: Parameter y is not declared\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test069() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid @param: all arguments are not documented\n" + + " */\n" + + " public void foo(double a, double b, double c);\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " public void foo(double a, double b, double c);\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n" + + "2. ERROR in IX.java (at line 5)\n" + + " public void foo(double a, double b, double c);\n" + + " ^\n" + + "Javadoc: Missing tag for parameter b\n" + + "----------\n" + + "3. ERROR in IX.java (at line 5)\n" + + " public void foo(double a, double b, double c);\n" + + " ^\n" + + "Javadoc: Missing tag for parameter c\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test070() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid @param: mix of all possible errors (missing a, not argument tag and duplicated)\n" + + " * @param c Valid param\n" + + " * @param x Invalid param: not an argument\n" + + " * @param b Valid param\n" + + " * @param c Invalid param: duplicated\n" + + " * @param\n" + + " */\n" + + " public void foo(double a, long b, int c);\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " * @param x Invalid param: not an argument\n" + + " ^\n" + + "Javadoc: Parameter x is not declared\n" + + "----------\n" + + "2. ERROR in IX.java (at line 7)\n" + + " * @param c Invalid param: duplicated\n" + + " ^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "3. ERROR in IX.java (at line 8)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "4. ERROR in IX.java (at line 10)\n" + + " public void foo(double a, long b, int c);\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // @throws/@exception tag + public void test071() { + this.runConformTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Valid @throws tags: documented exception are unchecked\n" + + " * @throws IllegalArgumentException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @exception NullPointerException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @throws java.awt.AWTError Valid unchecked exception (java.lang.Error subclass)\n" + + " * @exception OutOfMemoryError Valid unchecked exception (java.lang.Runtime subclass)\n" + + " */\n" + + " public void foo();\n" + + "}\n" }); + } + + public void test072() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * @throws java.awt.AWTexception Invalid exception: unknown type\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 3)\n" + + " * @throws java.awt.AWTexception Invalid exception: unknown type\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: java.awt.AWTexception cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in IX.java (at line 4)\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: IOException cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test073() { + this.runNegativeTest( + new String[] { + "IX.java", + "import java.io.FileNotFoundException;\n" + + "public interface IX {\n" + + " /**\n" + + " * @throws java.io.EOFException Invalid exception: known exception but neither thrown nor unchecked\n" + + " * @throws FileNotFoundException Invalid exception: known exception but neither thrown nor unchecked\n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 4)\n" + + " * @throws java.io.EOFException Invalid exception: known exception but neither thrown nor unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception EOFException is not declared\n" + + "----------\n" + + "2. ERROR in IX.java (at line 5)\n" + + " * @throws FileNotFoundException Invalid exception: known exception but neither thrown nor unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception FileNotFoundException is not declared\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test074() { + this.runNegativeTest( + new String[] { + "IX.java", + "import java.io.FileNotFoundException;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid @throws tags: documented exception are unchecked but some thrown exception are invalid\n" + + " * @throws IllegalAccessException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @throws IllegalArgumentException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @exception NullPointerException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @throws java.awt.AWTError Valid unchecked exception (java.lang.Error subclass)\n" + + " * @exception OutOfMemoryError Valid unchecked exception (java.lang.Runtime subclass)\n" + + " */\n" + + " public void foo() throws\n" + + " IllegalAccessException, \n" + + " InvalidException, \n" + + " String, \n" + + " java.io.EOFException, \n" + + " FileNotFoundException, \n" + + " IOException;\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 13)\n" + + " InvalidException, \n" + + " ^^^^^^^^^^^^^^^^\n" + + "InvalidException cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in IX.java (at line 14)\n" + + " String, \n" + + " ^^^^^^\n" + + "No exception of type String can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "3. ERROR in IX.java (at line 15)\n" + + " java.io.EOFException, \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception EOFException\n" + + "----------\n" + + "4. ERROR in IX.java (at line 16)\n" + + " FileNotFoundException, \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception FileNotFoundException\n" + + "----------\n" + + "5. ERROR in IX.java (at line 17)\n" + + " IOException;\n" + + " ^^^^^^^^^^^\n" + + "IOException cannot be resolved to a type\n" + + "----------\n"); + } + + // @return tag + public void test080() { + this.runConformTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Valid return declaration\n" + + " *\n" + + " * @return Return an int\n" + + " */\n" + + " public int foo();\n" + + "}\n" }); + } + + public void test081() { + this.runConformTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Valid empty return declaration\n" + + " *\n" + + " * @return string\n" + + " */\n" + + " public String foo();\n" + + "}\n" }); + } + + public void test082() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Missing return declaration\n" + + " */\n" + + " public Object[] foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " public Object[] foo();\n" + + " ^^^^^^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test083() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid return declaration\n" + + " *\n" + + " * @return Dimension\n" + + " * @return Duplicated\n" + + " */\n" + + " public double foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 6)\n" + + " * @return Duplicated\n" + + " ^^^^^^\n" + + "Javadoc: Duplicate tag for return type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test084() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid return declaration\n" + + " *\n" + + " * @return Invalid return on void method\n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " * @return Invalid return on void method\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // @see tag: string + public void test090() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid string references \n" + + " *\n" + + " * @see \"unterminated string\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " * @see \"unterminated string\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in IX.java (at line 6)\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test091() { + this.runConformTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Valid string references \n" + + " *\n" + + " * @see \"Valid normal string\"\n" + + " * @see \"Valid \\\"string containing\\\" \\\"double-quote\\\"\"\n" + + " */\n" + + " public void foo();\n" + + "}\n" }); + } + + // @see tag: URL + public void test092() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid URL link references \n" + + " *\n" + + " * @see invalid no text allowed after the href\n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " * @see invalid no text allowed after the href\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // @see tag: class references + public void test095() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "public interface IX {\n" + + " /**\n" + + " * Valid local classes references \n" + + " *\n" + + " * @see Visibility Valid ref: local class \n" + + " * @see Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see AbstractVisibility.AvcPublic Valid ref: visible inner class of local class \n" + + " * @see test.Visibility Valid ref: local class \n" + + " * @see test.Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see test.AbstractVisibility.AvcPublic Valid ref: visible inner class of local class \n" + + " */\n" + + " public void foo();\n" + + "}\n" }); + } + + public void test096() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid local classes references \n" + + " *\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see Unknown Invalid ref: unknown class \n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 6)\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 7)\n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 8)\n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.VcPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\IX.java (at line 9)\n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\IX.java (at line 10)\n" + + " * @see Unknown Invalid ref: unknown class \n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test097() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.*;\n" + + "public interface IX {\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + // Inner classes are not visible in generated documentation + //" * @see VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + " public void foo();\n" + + "}\n" + } + ); + } + + public void test098() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.*;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid external classes references \n" + + " *\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 7)\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 8)\n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n"); + } + + public void test099() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "public interface IX {\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see test.copy.VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + // Inner classes are not visible in generated documentation + //" * @see test.copy.VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + " public void foo();\n" + + "}\n" + } + ); + } + + // @see tag: field references + public void test105() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "public interface IX {\n" + + " /**\n" + + " * Valid local class field references\n" + + " *\n" + + " * @see Visibility#vf_public Valid ref: visible field\n" + + " * @see Visibility.VcPublic#vf_public Valid ref: visible field in visible inner class\n" + + " */\n" + + " public void foo();\n" + + "}\n" }); + } + + public void test106() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid local class field references\n" + + " *\n" + + " * @see #x Invalid ref: non existent field\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 6)\n" + + " * @see #x Invalid ref: non existent field\n" + + " ^\n" + + "Javadoc: x cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 7)\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 8)\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "4. ERROR in test\\IX.java (at line 9)\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\IX.java (at line 10)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "6. ERROR in test\\IX.java (at line 11)\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + public void test107() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.*;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPublic#vf_public Valid ref to not visible field of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vf_public Valid ref to not visible field of other package public inner class\n" + + " */\n" + + " public void foo();\n" + + "}\n" + } + ); + } + + public void test108() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.*;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPackage#unknown Invalid ref to non existent field of other package non visible class\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 7)\n" + + " * @see VisibilityPackage#unknown Invalid ref to non existent field of other package non visible class\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 8)\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 9)\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "4. ERROR in test\\IX.java (at line 10)\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\IX.java (at line 11)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "6. ERROR in test\\IX.java (at line 12)\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + // @see method references + public void test110() { + this.runConformTest( + new String[] { + "IX.java", + "import java.util.Vector;\n" + + "public interface IX {\n" + + " /**\n" + + " * Valid local methods references with array\n" + + " * \n" + + " * @see #smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) Valid local method reference\n" + + " * @see #smr_foo(char[], int[][], String[][][], Vector[][][][]) Valid local method reference\n" + + " * @see #smr_foo(char[],int[][],java.lang.String[][][],java.util.Vector[][][][]) Valid local method reference\n" + + " */ \n" + + " public void foo();\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra);\n" + + "}\n" }); + } + + public void test111() { + this.runNegativeTest( + new String[] { + "IX.java", + "import java.util.Vector;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid local methods references with array (non applicable arrays)\n" + + " * \n" + + " * @see #smr_foo(char[] , int[][], String[][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " */ \n" + + " public void foo();\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra);\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 6)\n" + + " * @see #smr_foo(char[] , int[][], String[][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type IX is not applicable for the arguments (char[], int[][], String[][], Vector[][][][])\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test112() { + this.runConformTest( + new String[] { + "IX.java", + "import java.util.Vector;\n" + + "public interface IX {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see #smr_foo() Valid local method reference\n" + + " * @see #smr_foo(boolean a1,int a2,byte a3,short a4,char a5,long a6,float a7,double a8) Valid local method reference\n" + + " * @see #smr_foo(java.lang.String, java.lang.String, int) Valid local method reference \n" + + " * @see #smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public void foo();\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo();\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d);\n" + + " public void smr_foo(String str1, java.lang.String str2, int i);\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b);\n" + + "}\n" }); + } + + public void test113() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " */ \n" + + " public void foo();\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type IX\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test114() { + this.runNegativeTest( + new String[] { + "IX.java", + "public interface IX {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(int) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(float, long, char, short, byte, int, boolean) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(String, String, int, String) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " */ \n" + + " public void foo();\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo();\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d);\n" + + " public void smr_foo(String str1, java.lang.String str2, int i);\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b);\n" + + "}\n" }, + "----------\n" + + "1. ERROR in IX.java (at line 5)\n" + + " * @see #smr_foo(int) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo() in the type IX is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in IX.java (at line 6)\n" + + " * @see #smr_foo(float, long, char, short, byte, int, boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type IX is not applicable for the arguments (float, long, char, short, byte, int, boolean)\n" + + "----------\n" + + "3. ERROR in IX.java (at line 7)\n" + + " * @see #smr_foo(String, String, int, String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type IX is not applicable for the arguments (String, String, int, String)\n" + + "----------\n" + + "4. ERROR in IX.java (at line 8)\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type IX is not applicable for the arguments (boolean)\n" + + "----------\n" + + "5. ERROR in IX.java (at line 9)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^^^^\n" + + "Javadoc: Hashtable cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in IX.java (at line 9)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^\n" + + "Javadoc: Vector cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test115() { + this.runConformTest( + new String[] { + "IX.java", + "import java.util.Vector;\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see IX#smr_foo() Valid local method reference\n" + + " * @see IX#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see IX#smr_foo(String x, java.lang.String y, int z) Valid local method reference \n" + + " * @see IX#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + "public interface IX {\n" + + " public void smr_foo();\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d);\n" + + " public void smr_foo(String str1, java.lang.String str2, int i);\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b);\n" + + "}\n" }); + } + + public void test116() { + this.runConformTest( + new String[] { + "test/deep/qualified/name/p/IX.java", + "package test.deep.qualified.name.p;\n" + + "import java.util.Vector;\n" + + "public interface IX {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see test.deep.qualified.name.p.IX#smr_foo() Valid local method reference\n" + + " * @see test.deep.qualified.name.p.IX#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.IX#smr_foo(String x, java.lang.String y, int z) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.IX#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public void smr_foo();\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d);\n" + + " public void smr_foo(String str1, java.lang.String str2, int i);\n" + + " public void smr_foo(java.util.Hashtable h, Vector v, boolean b);\n" + + "}\n" }); + } + + public void test117() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "public interface IX {\n" + + " /**\n" + + " * Valid package class methods references\n" + + " * \n" + + " * @see Visibility#vm_public() Valid ref: visible method\n" + + " * @see Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " * @see test.Visibility#vm_public() Valid ref: visible method\n" + + " * @see test.Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " */ \n" + + " public void foo();\n" + + "}\n" }); + } + + public void test118() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid package class methods references (non-existence)\n" + + " * \n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " */ \n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 6)\n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 7)\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility.VcPublic\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 8)\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in test\\IX.java (at line 9)\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Visibility.Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test119() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid package class methods references (non-visible)\n" + + " * \n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " */ \n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 6)\n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility is not visible\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 7)\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 8)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility.VcPublic is not visible\n" + + "----------\n"); + } + + public void test120() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid package class methods references (non-applicable)\n" + + " * \n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " */ \n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\IX.java (at line 6)\n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in test\\IX.java (at line 7)\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility is not applicable for the arguments (String)\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 8)\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility.VcPublic is not applicable for the arguments (Integer, byte)\n" + + "----------\n" + + "4. ERROR in test\\IX.java (at line 9)\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility.VcPublic is not applicable for the arguments (Double, Boolean)\n" + + "----------\n"); + } + + public void test121() { + this.runNegativeReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.*;\n" + + "public interface IX {\n" + + " /**\n" + + " * Invalid other package non visible class methods references (non existent/visible arguments)\n" + + " * \n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " */\n" + + " public void foo();\n" + + "}\n" }, + "----------\n" + + "1. WARNING in test\\IX.java (at line 2)\n"+ + " import test.copy.*;\n"+ + " ^^^^^^^^^\n"+ + "The import test.copy is never used\n"+ + "----------\n"+ + "2. ERROR in test\\IX.java (at line 7)\n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\IX.java (at line 8)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n"); + } + + public void test122() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + "public interface IX {\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + " public void foo();\n" + + "}\n" + } + ); + } + + public void test123() { + runConformReferenceTest( + new String[] { + "test/IX.java", + "package test;\n" + + "public interface IX {\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see test.copy.VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + " public void foo();\n" + + "}\n" }); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForMethod.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForMethod.java new file mode 100644 index 0000000000..99c0af5c46 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForMethod.java @@ -0,0 +1,4982 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTestForMethod extends JavadocTest { + public JavadocTestForMethod(String name) { + super(name); + } + public static Class javadocTestClass() { + return JavadocTestForMethod.class; + } + public static Test suite() { + return buildAllCompliancesTestSuite(javadocTestClass()); + } + + // Use this static initializer to specify subset for tests + // All specified tests which does not belong to the class are skipped... + static { + // Names of tests to run: can be "testBugXXXX" or "BugXXXX") +// TESTS_NAMES = new String[] { "Bug51529a", "Bug51529b" }; + // Numbers of tests to run: "test" will be run for each number of this array +// TESTS_NUMBERS = new int[] { 117, 124, 132, 137 }; + // Range numbers of tests to run: all tests between "test" and "test" will be run for { first, last } +// TESTS_RANGE = new int[] { 21, 50 }; +// TESTS_RANGE = new int[] { -1, 50 }; // run all tests with a number less or equals to 50 +// TESTS_RANGE = new int[] { 10, -1 }; // run all tests with a number greater or equals to 10 + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return options; + } + + /* (non-Javadoc) + * Test @deprecated tag + */ + public void test001() { + this.runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " {\n" + + " new Z().foo();\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * \n" + + " * ** ** ** ** @deprecated */\n" + + " public void foo() { \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Z().foo();\n" + + " ^^^^^\n" + + "The method foo() from the type Z is deprecated\n" + + "----------\n", + null, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + + public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /** @deprecated */\n" + + " int x;\n" + + " /**\n" + + " * @see #x\n" + + " */\n" + + " void foo() {\n" + + " }\n" + + "}\n", + "Y.java", + "/** @deprecated */\n" + + "public class Y {\n" + + " int y;\n" + + " /**\n" + + " * @see X#x\n" + + " * @see Y\n" + + " * @see Y#y\n" + + " */\n" + + " void foo() {\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " int z;\n" + + " /**\n" + + " * @see X#x\n" + + " * @see Y\n" + + " * @see Y#y\n" + + " */\n" + + " void foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in Z.java (at line 4)\n" + + " * @see X#x\n" + + " ^\n" + + "Javadoc: The field X.x is deprecated\n" + + "----------\n" + + "2. ERROR in Z.java (at line 5)\n" + + " * @see Y\n" + + " ^\n" + + "Javadoc: The type Y is deprecated\n" + + "----------\n" + + "3. ERROR in Z.java (at line 6)\n" + + " * @see Y#y\n" + + " ^\n" + + "Javadoc: The type Y is deprecated\n" + + "----------\n" + + "4. ERROR in Z.java (at line 6)\n" + + " * @see Y#y\n" + + " ^\n" + + "Javadoc: The field Y.y is deprecated\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " {\n" + + " new Z().foo(2);\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * Valid tags with deprecation at end\n" + + " *\n" + + " * @param x Valid param tag\n" + + " * @return Valid return tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(int x) { \n" + + " return \"\";\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Z().foo(2);\n" + + " ^^^^^^\n" + + "The method foo(int) from the type Z is deprecated\n" + + "----------\n" + ); + } + + public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " {\n" + + " new Z().foo(2);\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * Invalid javadoc tags with valid deprecation at end\n" + + " *\n" + + " * @param\n" + + " * @return String\n" + + " * @throws Unknown\n" + + " * @see \"Invalid\n" + + " * @see Unknown\n" + + " * @param x\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(int x) { \n" + + " return \"\";\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Z().foo(2);\n" + + " ^^^^^^\n" + + "The method foo(int) from the type Z is deprecated\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Z.java (at line 5)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "2. ERROR in Z.java (at line 7)\n" + + " * @throws Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in Z.java (at line 8)\n" + + " * @see \"Invalid\n" + + " ^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "4. ERROR in Z.java (at line 9)\n" + + " * @see Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in Z.java (at line 10)\n" + + " * @param x\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "6. ERROR in Z.java (at line 13)\n" + + " public String foo(int x) { \n" + + " ^\n" + + "Javadoc: Missing tag for parameter x\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " {\n" + + " new Z().foo(2);\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * Valid tags with deprecation at beginning\n" + + " *\n" + + " * @deprecated\n" + + " * @param x Valid param tag\n" + + " * @return Valid return tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " */\n" + + " public String foo(int x) { \n" + + " return \"\";\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Z().foo(2);\n" + + " ^^^^^^\n" + + "The method foo(int) from the type Z is deprecated\n" + + "----------\n" + ); + } + + public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " {\n" + + " new Z().foo(2);\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * Invalid javadoc tags with valid deprecation at beginning\n" + + " *\n" + + " * @deprecated\n" + + " * @param\n" + + " * @return String\n" + + " * @throws Unknown\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see \"Invalid\n" + + " * @see Unknown\n" + + " * @param x\n" + + " */\n" + + " public String foo(int x) { \n" + + " return \"\";\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Z().foo(2);\n" + + " ^^^^^^\n" + + "The method foo(int) from the type Z is deprecated\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Z.java (at line 6)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "2. ERROR in Z.java (at line 8)\n" + + " * @throws Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in Z.java (at line 10)\n" + + " * @see \"Invalid\n" + + " ^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "4. ERROR in Z.java (at line 11)\n" + + " * @see Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in Z.java (at line 12)\n" + + " * @param x\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "6. ERROR in Z.java (at line 14)\n" + + " public String foo(int x) { \n" + + " ^\n" + + "Javadoc: Missing tag for parameter x\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " {\n" + + " new Z().foo(2);\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * Valid tags with deprecation in the middle\n" + + " *\n" + + " * @param x Valid param tag\n" + + " * @return Valid return tag\n" + + " * @deprecated\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " */\n" + + " public String foo(int x) { \n" + + " return \"\";\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Z().foo(2);\n" + + " ^^^^^^\n" + + "The method foo(int) from the type Z is deprecated\n" + + "----------\n" + ); + } + + public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " {\n" + + " new Z().foo(2);\n" + + " }\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " /** \n" + + " * Invalid javadoc tags with valid deprecation in the middle\n" + + " *\n" + + " * @param\n" + + " * @return String\n" + + " * @throws Unknown\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see \"Invalid\n" + + " * @deprecated\n" + + " * @see Unknown\n" + + " */\n" + + " public String foo(int x) { \n" + + " return \"\";\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " new Z().foo(2);\n" + + " ^^^^^^\n" + + "The method foo(int) from the type Z is deprecated\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Z.java (at line 5)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "2. ERROR in Z.java (at line 7)\n" + + " * @throws Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in Z.java (at line 9)\n" + + " * @see \"Invalid\n" + + " ^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "4. ERROR in Z.java (at line 11)\n" + + " * @see Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in Z.java (at line 13)\n" + + " public String foo(int x) { \n" + + " ^\n" + + "Javadoc: Missing tag for parameter x\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + /* (non-Javadoc) + * Test @param tag + */ + public void test011() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid @param: no tags, no args\n" + + " * Valid @throws/@exception: no tags, no thrown exception\n" + + " */\n" + + " public void p_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test012() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void p_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param declaration: no arguments, 2 declared tags\n" + + " * @param x\n" + + " * Invalid param: not an argument on 2 lines\n" + + " * @param x Invalid param: not an argument\n" + + " */\n" + + " public void p_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param x\n" + + " ^\n" + + "Javadoc: Parameter x is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param x Invalid param: not an argument\n" + + " ^\n" + + "Javadoc: Parameter x is not declared\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test014() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " /**\n" + + " * Valid @param declaration: 3 arguments, 3 tags in right order\n" + + " * @param a Valid param\n" + + " * @param b Valid param \n" + + " * @param c Valid param\n" + + " */\n" + + " public void p_foo(int a, int b, int c) {\n" + + " }\n" + + "}\n" }); + } + + public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param declaration: 3 arguments, 3 correct tags in right order + 2 additional\n" + + " * @param a Valid param\n" + + " * @param x Invalid param: not an argument\n" + + " * @param b Valid param \n" + + " * @param x Invalid param: not an argument\n" + + " * @param c Valid param\n" + + " */\n" + + " public void p_foo(char a, char b, char c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param x Invalid param: not an argument\n" + + " ^\n" + + "Javadoc: Parameter x is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @param x Invalid param: not an argument\n" + + " ^\n" + + "Javadoc: Parameter x is not declared\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test016() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid @param declaration: 3 arguments, 3 tags in wrong order\n" + + " * @param c Valid param, not well placed\n" + + " * @param b Valid param, not well placed \n" + + " * @param a Valid param, not well placed\n" + + " */\n" + + " public void p_foo(long a, long b, long c) {\n" + + " }\n" + + "}\n" }); + } + + public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param declaration: 3 arguments, 3 correct tags in wrong order + 1 duplicate tag + 1 additional\n" + + " * @param c Valid param, not well placed\n" + + " * @param a Valid param, not well placed\n" + + " * @param b Valid param, not well placed \n" + + " * @param a Invalid param: duplicated\n" + + " * @param x Invalid param: not an argument\n" + + " */\n" + + " public void p_foo(float a, float b, float c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " * @param a Invalid param: duplicated\n" + + " ^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " * @param x Invalid param: not an argument\n" + + " ^\n" + + "Javadoc: Parameter x is not declared\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: all arguments are not documented\n" + + " */\n" + + " public void p_foo(double a, double b, double c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public void p_foo(double a, double b, double c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public void p_foo(double a, double b, double c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter b\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public void p_foo(double a, double b, double c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter c\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test021() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: b and c arguments are not documented\n" + + " * @param a Valid param\n" + + " */\n" + + " public void p_foo(int a, char b, long c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public void p_foo(int a, char b, long c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter b\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public void p_foo(int a, char b, long c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter c\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: a and c arguments are not documented\n" + + " * @param b Valid param\n" + + " */\n" + + " public void p_foo(int a, char b, long c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public void p_foo(int a, char b, long c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public void p_foo(int a, char b, long c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter c\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test023() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: a and b arguments are not documented\n" + + " * @param c Valid param\n" + + " */\n" + + " public void p_foo(int a, char b, long c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public void p_foo(int a, char b, long c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public void p_foo(int a, char b, long c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter b\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: c argument is not documented\n" + + " * @param a Valid param\n" + + " * @param b Valid param\n" + + " */\n" + + " public void p_foo(int a, char b, long c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public void p_foo(int a, char b, long c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter c\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test025() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: a argument is not documented + b and c are not well placed\n" + + " * @param c Valid param\n" + + " * @param b Valid param\n" + + " */\n" + + " public void p_foo(int a, char b, long c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public void p_foo(int a, char b, long c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: b argument is not documented + a and c are not well placed\n" + + " * @param c Valid param\n" + + " * @param a Valid param\n" + + " */\n" + + " public void p_foo(int a, char b, long c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public void p_foo(int a, char b, long c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter b\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test030() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: mix of all possible errors (missing a, not argument tag and duplicated)\n" + + " * @param c Valid param\n" + + " * @param x Invalid param: not an argument\n" + + " * @param b Valid param\n" + + " * @param c Invalid param: duplicated\n" + + " */\n" + + " public void p_foo(double a, long b, int c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param x Invalid param: not an argument\n" + + " ^\n" + + "Javadoc: Parameter x is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @param c Invalid param: duplicated\n" + + " ^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " public void p_foo(double a, long b, int c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test031() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: missing parameter name\n" + + " * @param\n" + + " */\n" + + " public void p_foo(String a) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public void p_foo(String a) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test032() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: missing parameter name + valid param \n" + + " * @param\n" + + " * @param x\n" + + " */\n" + + " public void p_foo(int x) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test033() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: missing parameter names + valid params \n" + + " * @param h\n" + + " * @param\n" + + " * @param h\n" + + " * @param\n" + + " */\n" + + " public void p_foo(java.util.Hashtable h, float f) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param h\n" + + " ^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " public void p_foo(java.util.Hashtable h, float f) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter f\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test034() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: missing parameter name + valid param \n" + + " * @param *\n" + + " * @param ?\n" + + " */\n" + + " public void p_foo(int x) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param *\n" + + " ^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param ?\n" + + " ^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " public void p_foo(int x) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter x\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void test035() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid @param but compiler errors\n" + + " * @param a Valid param\n" + + " * @param b Valid param\n" + + " * @param c Valid param\n" + + " */\n" + + " public void p_foo(inr a, int b, int c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " public void p_foo(inr a, int b, int c) {\n" + + " ^^^\n" + + "inr cannot be resolved to a type\n" + + "----------\n"); + } + + public void test036() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param + compiler errors\n" + + " * @param b Valid param\n" + + " * @param b Valid param\n" + + " * @param c Valid param\n" + + " */\n" + + " public void p_foo(inr a, inx b, inq c) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param b Valid param\n" + + " ^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public void p_foo(inr a, inx b, inq c) {\n" + + " ^^^\n" + + "inr cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " public void p_foo(inr a, inx b, inq c) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " public void p_foo(inr a, inx b, inq c) {\n" + + " ^^^\n" + + "inx cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " public void p_foo(inr a, inx b, inq c) {\n" + + " ^^^\n" + + "inq cannot be resolved to a type\n" + + "----------\n"); + } + + public void test037() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @param: class reference instead of param name\n" + + " * @param java.lang.Hashtable\n" + + " */\n" + + " public void p_foo(int x) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param java.lang.Hashtable\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public void p_foo(int x) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter x\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void test038() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Hashtable;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid @param: class reference instead of param name + unused import\n" + + " * @param Hashtable\n" + + " */\n" + + " public void p_foo(int x) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n"+ + " import java.util.Hashtable;\n"+ + " ^^^^^^^^^^^^^^^^^^^\n"+ + "The import java.util.Hashtable is never used\n"+ + "----------\n"+ + "2. ERROR in X.java (at line 5)\n" + + " * @param Hashtable\n" + + " ^^^^^^^^^\n" + + "Javadoc: Parameter Hashtable is not declared\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " public void p_foo(int x) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter x\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + /* (non-Javadoc) + * Test @throws/@exception tag + */ + public void test050() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid @throws tags: documented exception are unchecked\n" + + " * @throws IllegalArgumentException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @exception NullPointerException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @throws java.awt.AWTError Valid unchecked exception (java.lang.Error subclass)\n" + + " * @exception OutOfMemoryError Valid unchecked exception (java.lang.Runtime subclass)\n" + + " */\n" + + " public void t_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test051() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @throws IllegalArgumenException.. Invalid exception: invalid class name\n" + + " * @exception IllegalArgumen..Exception.. Invalid exception: invalid class name\n" + + " */\n" + + " public void t_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @throws IllegalArgumenException.. Invalid exception: invalid class name\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid class name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @exception IllegalArgumen..Exception.. Invalid exception: invalid class name\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid class name\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test052() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @throws java.awt.AWTexception Invalid exception: unknown type\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " */\n" + + " public void t_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @throws java.awt.AWTexception Invalid exception: unknown type\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: java.awt.AWTexception cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: IOException cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test053() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.FileNotFoundException;\n" + + "public class X {\n" + + " /**\n" + + " * @throws java.io.EOFException Invalid exception: known exception but neither thrown nor unchecked\n" + + " * @throws FileNotFoundException Invalid exception: known exception but neither thrown nor unchecked\n" + + " */\n" + + " public void t_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @throws java.io.EOFException Invalid exception: known exception but neither thrown nor unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception EOFException is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @throws FileNotFoundException Invalid exception: known exception but neither thrown nor unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception FileNotFoundException is not declared\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test055() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid @throws tags: documented exception are unchecked but method throws an unknown exception\n" + + " * @throws IllegalArgumentException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @exception NullPointerException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @throws java.awt.AWTError Valid unchecked exception (java.lang.Error subclass)\n" + + " * @exception OutOfMemoryError Valid unchecked exception (java.lang.Runtime subclass)\n" + + " */\n" + + " public void t_foo() throws InvalidException {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " public void t_foo() throws InvalidException {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "InvalidException cannot be resolved to a type\n" + + "----------\n"); + } + + public void test056() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @throws IllegalArgumenException._ Invalid exception: invalid class name\n" + + " * @exception IllegalArgumen.*.Exception.. Invalid exception: invalid class name\n" + + " */\n" + + " public void t_foo() throws InvalidException {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @throws IllegalArgumenException._ Invalid exception: invalid class name\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: IllegalArgumenException cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @exception IllegalArgumen.*.Exception.. Invalid exception: invalid class name\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid class name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public void t_foo() throws InvalidException {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "InvalidException cannot be resolved to a type\n" + + "----------\n"); + } + + public void test057() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @throws java.awt.AWTexception Invalid exception: unknown type\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " */\n" + + " public void t_foo() throws InvalidException {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @throws java.awt.AWTexception Invalid exception: unknown type\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: java.awt.AWTexception cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: IOException cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public void t_foo() throws InvalidException {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "InvalidException cannot be resolved to a type\n" + + "----------\n"); + } + + public void test058() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.FileNotFoundException;\n" + + "public class X {\n" + + " /**\n" + + " * @throws java.io.EOFException Invalid exception: known exception but neither thrown nor unchecked\n" + + " * @throws FileNotFoundException Invalid exception: known exception but neither thrown nor unchecked\n" + + " */\n" + + " public void t_foo() throws InvalidException {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @throws java.io.EOFException Invalid exception: known exception but neither thrown nor unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception EOFException is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @throws FileNotFoundException Invalid exception: known exception but neither thrown nor unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception FileNotFoundException is not declared\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " public void t_foo() throws InvalidException {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "InvalidException cannot be resolved to a type\n" + + "----------\n"); + } + + public void test060() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @throws tags: documented exception are unchecked but thrown exception is not documented\n" + + " * @throws IllegalArgumentException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @exception NullPointerException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @throws java.awt.AWTError Valid unchecked exception (java.lang.Error subclass)\n" + + " * @exception OutOfMemoryError Valid unchecked exception (java.lang.Runtime subclass)\n" + + " */\n" + + " public void t_foo() throws IllegalAccessException {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " public void t_foo() throws IllegalAccessException {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalAccessException\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test061() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @throws /IllegalArgumenException.. Invalid exception: invalid class name\n" + + " * @exception .IllegalArgumen..Exception.. Invalid exception: invalid class name\n" + + " */\n" + + " public void t_foo() throws IllegalAccessException {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @throws /IllegalArgumenException.. Invalid exception: invalid class name\n" + + " ^^^^^^\n" + + "Javadoc: Missing class name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @exception .IllegalArgumen..Exception.. Invalid exception: invalid class name\n" + + " ^^\n" + + "Javadoc: Invalid class name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public void t_foo() throws IllegalAccessException {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalAccessException\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test062() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @throws java.awt.AWTexception Invalid exception: unknown type\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " */\n" + + " public void t_foo() throws IllegalAccessException {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @throws java.awt.AWTexception Invalid exception: unknown type\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: java.awt.AWTexception cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: IOException cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public void t_foo() throws IllegalAccessException {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalAccessException\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test063() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.FileNotFoundException;\n" + + "public class X {\n" + + " /**\n" + + " * @throws java.io.EOFException Invalid exception: known exception but neither thrown nor unchecked\n" + + " * @throws FileNotFoundException Invalid exception: known exception but neither thrown nor unchecked\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " */\n" + + " public void t_foo() throws IllegalAccessException {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @throws java.io.EOFException Invalid exception: known exception but neither thrown nor unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception EOFException is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @throws FileNotFoundException Invalid exception: known exception but neither thrown nor unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception FileNotFoundException is not declared\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: IOException cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " public void t_foo() throws IllegalAccessException {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalAccessException\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test065() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid @throws tags: documented exception are unchecked but some thrown exception are invalid\n" + + " * @throws IllegalAccessException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @throws IllegalArgumentException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @exception NullPointerException Valid unchecked exception (java.lang.Runtime subclass)\n" + + " * @throws java.awt.AWTError Valid unchecked exception (java.lang.Error subclass)\n" + + " * @exception OutOfMemoryError Valid unchecked exception (java.lang.Runtime subclass)\n" + + " */\n" + + " public void t_foo() throws\n" + + " IllegalAccessException, \n" + + " InvalidException, \n" + + " String, \n" + + " IllegalArgumentException\n" + + " {}\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " InvalidException, \n" + + " ^^^^^^^^^^^^^^^^\n" + + "InvalidException cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " String, \n" + + " ^^^^^^\n" + + "No exception of type String can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n"); + } + + public void test066() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @throws %IllegalArgumenException Invalid exception: invalid class name\n" + + " * @exception (IllegalArgumen Invalid exception: invalid class name\n" + + " * @exception \"IllegalArgumen Invalid exception: invalid class name\n" + + " */\n" + + " public void t_foo() throws\n" + + " IllegalAccessException, \n" + + " InvalidException, \n" + + " String, \n" + + " IllegalArgumentException\n" + + " {}\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @throws %IllegalArgumenException Invalid exception: invalid class name\n" + + " ^^^^^^\n" + + "Javadoc: Missing class name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @exception (IllegalArgumen Invalid exception: invalid class name\n" + + " ^^^^^^^^^\n" + + "Javadoc: Missing class name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @exception \"IllegalArgumen Invalid exception: invalid class name\n" + + " ^^^^^^^^^\n" + + "Javadoc: Missing class name\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " IllegalAccessException, \n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalAccessException\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " InvalidException, \n" + + " ^^^^^^^^^^^^^^^^\n" + + "InvalidException cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " String, \n" + + " ^^^^^^\n" + + "No exception of type String can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " IllegalArgumentException\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalArgumentException\n" + + "----------\n"); + } + + public void test067() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @throws java.awt.AWTexception Invalid exception: unknown type\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " */\n" + + " public void t_foo() throws\n" + + " IllegalAccessException, \n" + + " InvalidException, \n" + + " String, \n" + + " IllegalArgumentException\n" + + " {}\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @throws java.awt.AWTexception Invalid exception: unknown type\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: java.awt.AWTexception cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @throws IOException Invalid exception: unknown type\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: IOException cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " IllegalAccessException, \n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalAccessException\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " InvalidException, \n" + + " ^^^^^^^^^^^^^^^^\n" + + "InvalidException cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " String, \n" + + " ^^^^^^\n" + + "No exception of type String can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " IllegalArgumentException\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalArgumentException\n" + + "----------\n"); + } + + public void test068() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.FileNotFoundException;\n" + + "public class X {\n" + + " /**\n" + + " * @throws java.io.EOFException Invalid exception: known exception but neither thrown nor unchecked\n" + + " * @throws FileNotFoundException Invalid exception: known exception but neither thrown nor unchecked\n" + + " */\n" + + " public void t_foo() throws\n" + + " IllegalAccessException, \n" + + " InvalidException, \n" + + " String, \n" + + " IllegalArgumentException\n" + + " {}\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @throws java.io.EOFException Invalid exception: known exception but neither thrown nor unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception EOFException is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @throws FileNotFoundException Invalid exception: known exception but neither thrown nor unchecked\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception FileNotFoundException is not declared\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " IllegalAccessException, \n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalAccessException\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " InvalidException, \n" + + " ^^^^^^^^^^^^^^^^\n" + + "InvalidException cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " String, \n" + + " ^^^^^^\n" + + "No exception of type String can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " IllegalArgumentException\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalArgumentException\n" + + "----------\n"); + } + + public void test069() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.FileNotFoundException;\n" + + "public class X {\n" + + " /**\n" + + " */\n" + + " public void t_foo() throws\n" + + " IllegalAccessException, \n" + + " InvalidException, \n" + + " String, \n" + + " java.io.EOFException, \n" + + " FileNotFoundException, \n" + + " IOException, \n" + + " IllegalArgumentException\n" + + " {}\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " IllegalAccessException, \n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalAccessException\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " InvalidException, \n" + + " ^^^^^^^^^^^^^^^^\n" + + "InvalidException cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " String, \n" + + " ^^^^^^\n" + + "No exception of type String can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " java.io.EOFException, \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception EOFException\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " FileNotFoundException, \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception FileNotFoundException\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " IOException, \n" + + " ^^^^^^^^^^^\n" + + "IOException cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " IllegalArgumentException\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IllegalArgumentException\n" + + "----------\n"); + } + + /* (non-Javadoc) + * Test @return tag + */ + public void test070() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid return declaration\n" + + " *\n" + + " * @return Return an int\n" + + " */\n" + + " public int s_foo() {\n" + + " return 0;\n" + + " }\n" + + "}\n" }); + } + + public void test071() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid empty return declaration\n" + + " *\n" + + " * @return string\n" + + " */\n" + + " public String s_foo() {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }); + } + + public void test072() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid return declaration\n" + + " *\n" + + " * @return Vector A list of things\n" + + " */\n" + + " public java.util.Vector s_foo() {\n" + + " return new java.util.Vector();\n" + + " }\n" + + "}\n" }); + } + + public void test073() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Missing return declaration\n" + + " */\n" + + " public Object[] s_foo() {\n" + + " return new Object[0];\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public Object[] s_foo() {\n" + + " ^^^^^^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test074() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid return declaration\n" + + " *\n" + + " * @return double\n" + + " * @return Dimension\n" + + " */\n" + + " public double s_foo() {\n" + + " return 3.14;\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @return Dimension\n" + + " ^^^^^^\n" + + "Javadoc: Duplicate tag for return type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test075() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid return declaration\n" + + " *\n" + + " * @return Invalid return on void method\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @return Invalid return on void method\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test076() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid return declaration\n" + + " *\n" + + " * @return Invalid return on void method\n" + + " * @return\n" + + " * @return Invalid return on void method\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @return Invalid return on void method\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Duplicate tag for return type\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @return Invalid return on void method\n" + + " ^^^^^^\n" + + "Javadoc: Duplicate tag for return type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + /* (non-Javadoc) + * Test @see tag + */ + // String references + public void test080() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid string references \n" + + " *\n" + + " * @see \"\n" + + " * @see \"unterminated string\n" + + " * @see \"invalid string\"\"\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see \"\n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see \"unterminated string\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see \"invalid string\"\"\n" + + " ^\n" + + "Javadoc: Unexpected text\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test081() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid string references \n" + + " *\n" + + " * @see \"Valid normal string\"\n" + + " * @see \"Valid \\\"string containing\\\" \\\"double-quote\\\"\"\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + // URL Link references + public void test085() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid URL link references \n" + + " *\n" + + " * @see <\n" + + " * @see \n" + + " * @see invalid\n" + + " * @see invalid<\n" + + " * @see invalidinvalidinvalid no text allowed after the href\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see <\n" + + " ^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see \n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "10. ERROR in X.java (at line 14)\n" + + " * @see invalid\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "11. ERROR in X.java (at line 15)\n" + + " * @see invalid<\n" + + " ^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "12. ERROR in X.java (at line 16)\n" + + " * @see invalidinvalidinvalid no text allowed after the href\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test086() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Valid URL references \n" + + " *\n" + + " * @see Valid URL link reference\n" + + " * @see Valid URL link reference\n" + + " * @see Valid URL link reference\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test087() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid URL references \n" + + " *\n" + + " * @see Invalid URL link reference\n" + + " * @see Invalid URL link reference\n" + + " * @see Invalid URL link reference\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see Invalid URL link reference\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see Invalid URL link reference\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see Invalid URL link reference\n" + + " ^^^^\n" + + "Javadoc: Malformed link reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // @see Classes references + public void test090() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local classes references \n" + + " *\n" + + " * @see Visibility Valid ref: local class \n" + + " * @see Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see AbstractVisibility.AvcPublic Valid ref: visible inner class of local class \n" + + " * @see test.Visibility Valid ref: local class \n" + + " * @see test.Visibility.VcPublic Valid ref: visible inner class of local class \n" + + " * @see test.AbstractVisibility.AvcPublic Valid ref: visible inner class of local class \n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test091() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local classes references \n" + + " *\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " * @see Unknown Invalid ref: unknown class \n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.Visibility.VcPrivate Invalid ref: non visible inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.VcPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see test.Visibility.AvcPrivate Invalid ref: non visible inherited inner class of local class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see Unknown Invalid ref: unknown class \n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test092() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + " * @see test.copy.VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test093() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid external classes references \n" + + " *\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " * @see VisibilityPackage.VpPrivate Invalid ref: non visible inner class in non visible class \n" + + " * @see VisibilityPackage.VpPublic Invalid ref: visible inner class in non visible class \n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPackage Invalid ref: non visible class \n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPackage.VpPrivate Invalid ref: non visible inner class in non visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPackage.VpPublic Invalid ref: visible inner class in non visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n"); + } + + public void test094() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid external classes references \n" + + " *\n" + + " * @see test.copy.VisibilityPublic Valid ref: visible class through import => no warning on import\n" + + " * @see test.copy.VisibilityPublic.VpPublic Valid ref: visible inner class in visible class \n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test095() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid external classes references \n" + + " *\n" + + " * @see test.copy.VisibilityPackage Invalid ref: non visible class \n" + + " * @see test.copy.VisibilityPackage.VpPrivate Invalid ref: non visible inner class in non visible class \n" + + " * @see test.copy.VisibilityPackage.VpPublic Invalid ref: visible inner class in non visible class \n" + + " * @see test.copy.VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see test.copy.VisibilityPackage Invalid ref: non visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate Invalid ref: non visible inner class in non visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.copy.VisibilityPackage.VpPublic Invalid ref: visible inner class in non visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate Invalid ref: non visible inner class in visible class \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPublic.VpPrivate is not visible\n" + + "----------\n"); + } + + // @see Field references + public void test100() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " int x;\n" + + " /**\n" + + " * Valid local class field references\n" + + " *\n" + + " * @see #x Valid ref: visible field\n" + + " * @see Visibility#vf_public Valid ref: visible field\n" + + " * @see Visibility.VcPublic#vf_public Valid ref: visible field in visible inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test101() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local class field references\n" + + " *\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " * @see Visibility.VcPrivate#vf_private Invalid ref: non visible inner class (non visible field)\n" + + " * @see Visibility.VcPrivate#vf_public Invalid ref: non visible inner class (public field)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#unknown Invalid ref: non existent field\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility#vf_private Invalid ref: non visible field\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.VcPrivate#unknown Invalid ref: non visible inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.VcPrivate#vf_private Invalid ref: non visible inner class (non visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see Visibility.VcPrivate#vf_public Invalid ref: non visible inner class (public field)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see Visibility.VcPublic#unknown Invalid ref: non existent field in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see Visibility.VcPublic#vf_private Invalid ref: non visible field in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n"); + } + + public void test102() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid super class field references in the same package\n" + + " *\n" + + " * @see Visibility#avf_public Valid ref: visible inherited field\n" + + " * @see AbstractVisibility.AvcPublic#avf_public Valid ref: visible field of visible inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test103() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid super class field references in the same package\n" + + " *\n" + + " * @see Visibility#avf_private Invalid ref: non visible inherited field\n" + + " * @see Visibility.AvcPrivate#avf_private Invalid ref: inherited non visible inner class (non visible field)\n" + + " * @see Visibility.AvcPrivate#avf_public Invalid ref: inherited non visible inner class (visible field)\n" + + " * @see Visibility.AvcPublic#avf_private Invalid ref: non visible field of inherited visible inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#avf_private Invalid ref: non visible inherited field\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: The field avf_private is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.AvcPrivate#avf_private Invalid ref: inherited non visible inner class (non visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.AvcPrivate#avf_public Invalid ref: inherited non visible inner class (visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.AvcPublic#avf_private Invalid ref: non visible field of inherited visible inner class\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: The field avf_private is not visible\n" + + "----------\n"); + } + + public void test104() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPackage#unknown Invalid ref: non visible class (non existent field)\n" + + " * @see VisibilityPackage#vf_private Invalid ref: non visible class (non existent field)\n" + + " * @see VisibilityPackage#vf_public Invalid ref: non visible class (visible field)\n" + + " * @see VisibilityPackage.VpPrivate#unknown Invalid ref: non visible class and non visible inner class (non existent field)\n" + + " * @see VisibilityPackage.VpPrivate#vf_private Invalid ref: non visible class and non visible inner class (non visible field)\n" + + " * @see VisibilityPackage.VpPrivate#vf_public Invalid ref: non visible class and non visible inner class (visible field)\n" + + " * @see VisibilityPackage.VpPublic#unknown Invalid ref: non visible class and visible inner class (non existent field)\n" + + " * @see VisibilityPackage.VpPublic#vf_private Invalid ref: non visible class and visible inner class (non visible field)\n" + + " * @see VisibilityPackage.VpPublic#vf_public Invalid ref: non visible class and visible inner class (visible field)\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in test\\X.java (at line 2)\n"+ + " import test.copy.*;\n"+ + " ^^^^^^^^^\n"+ + "The import test.copy is never used\n"+ + "----------\n"+ + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPackage#unknown Invalid ref: non visible class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPackage#vf_private Invalid ref: non visible class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPackage#vf_public Invalid ref: non visible class (visible field)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPackage.VpPrivate#unknown Invalid ref: non visible class and non visible inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see VisibilityPackage.VpPrivate#vf_private Invalid ref: non visible class and non visible inner class (non visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see VisibilityPackage.VpPrivate#vf_public Invalid ref: non visible class and non visible inner class (visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "8. ERROR in test\\X.java (at line 13)\n" + + " * @see VisibilityPackage.VpPublic#unknown Invalid ref: non visible class and visible inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "9. ERROR in test\\X.java (at line 14)\n" + + " * @see VisibilityPackage.VpPublic#vf_private Invalid ref: non visible class and visible inner class (non visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "10. ERROR in test\\X.java (at line 15)\n" + + " * @see VisibilityPackage.VpPublic#vf_public Invalid ref: non visible class and visible inner class (visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n"); + } + + public void test105() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see test.copy.VisibilityPackage#unknown Invalid ref: non visible class (non existent field)\n" + + " * @see test.copy.VisibilityPackage#vf_private Invalid ref: non visible class (non existent field)\n" + + " * @see test.copy.VisibilityPackage#vf_public Invalid ref: non visible class (visible field)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#unknown Invalid ref: non visible class and non visible inner class (non existent field)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vf_private Invalid ref: non visible class and non visible inner class (non visible field)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vf_public Invalid ref: non visible class and non visible inner class (visible field)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#unknown Invalid ref: non visible class and visible inner class (non existent field)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vf_private Invalid ref: non visible class and visible inner class (non visible field)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vf_public Invalid ref: non visible class and visible inner class (visible field)\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see test.copy.VisibilityPackage#unknown Invalid ref: non visible class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see test.copy.VisibilityPackage#vf_private Invalid ref: non visible class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.copy.VisibilityPackage#vf_public Invalid ref: non visible class (visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#unknown Invalid ref: non visible class and non visible inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vf_private Invalid ref: non visible class and non visible inner class (non visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vf_public Invalid ref: non visible class and non visible inner class (visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#unknown Invalid ref: non visible class and visible inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "8. ERROR in test\\X.java (at line 13)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vf_private Invalid ref: non visible class and visible inner class (non visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "9. ERROR in test\\X.java (at line 14)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vf_public Invalid ref: non visible class and visible inner class (visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n"); + } + + public void test106() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " * @see VisibilityPublic#vf_public Valid ref to not visible field of other package class\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " * @see VisibilityPublic.VpPrivate#vf_private Invalid ref to a non visible other package private inner class (non visible field)\n" + + " * @see VisibilityPublic.VpPrivate#vf_public Invalid ref to a non visible other package private inner class (public field)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " * @see VisibilityPublic.VpPublic#vf_public Valid ref to not visible field of other package public inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: VisibilityPublic cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: VisibilityPublic cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPublic#vf_public Valid ref to not visible field of other package class\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: VisibilityPublic cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: VisibilityPublic cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPublic.VpPrivate#vf_private Invalid ref to a non visible other package private inner class (non visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: VisibilityPublic cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see VisibilityPublic.VpPrivate#vf_public Invalid ref to a non visible other package private inner class (public field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: VisibilityPublic cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: VisibilityPublic cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in test\\X.java (at line 13)\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: VisibilityPublic cannot be resolved to a type\n" + + "----------\n" + + "9. ERROR in test\\X.java (at line 14)\n" + + " * @see VisibilityPublic.VpPublic#vf_public Valid ref to not visible field of other package public inner class\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: VisibilityPublic cannot be resolved to a type\n" + + "----------\n"); + } + + public void test107() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPublic#vf_public Valid ref to visible field of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vf_public Fully Qualified valid ref to visible field of other package public inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test108() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " * @see VisibilityPublic.VpPrivate#vf_private Invalid ref to a non visible other package private inner class (non visible field)\n" + + " * @see VisibilityPublic.VpPrivate#vf_public Invalid ref to a non visible other package private inner class (public field)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPublic.VpPrivate#vf_private Invalid ref to a non visible other package private inner class (non visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 11)\n" + + " * @see VisibilityPublic.VpPrivate#vf_public Invalid ref to a non visible other package private inner class (public field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 12)\n" + + " * @see VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 13)\n" + + " * @see VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + ); + } + + public void test109() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see test.copy.VisibilityPublic#vf_public Valid ref to not visible field of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vf_public Valid ref to not visible field of other package public inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test110() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class fields references\n" + + " *\n" + + " * @see test.copy.VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " * @see test.copy.VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vf_private Invalid ref to a non visible other package private inner class (non visible field)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vf_public Invalid ref to a non visible other package private inner class (public field)\n" + + " * @see test.copy.VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see test.copy.VisibilityPublic#unknown Invalid ref to non existent field of other package class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see test.copy.VisibilityPublic#vf_private Invalid ref to not visible field of other package class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#unknown Invalid ref to a non visible other package private inner class (non existent field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vf_private Invalid ref to a non visible other package private inner class (non visible field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vf_public Invalid ref to a non visible other package private inner class (public field)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see test.copy.VisibilityPublic.VpPublic#unknown Invalid ref to non existent field of other package public inner class\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vf_private Invalid ref to not visible field of other package public inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The field vf_private is not visible\n" + + "----------\n" + ); + } + + // @see local method references + public void test115() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references with array\n" + + " * \n" + + " * @see #smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) Valid local method reference\n" + + " * @see #smr_foo(char[], int[][], String[][][], Vector[][][][]) Valid local method reference\n" + + " * @see #smr_foo(char[],int[][],java.lang.String[][][],java.util.Vector[][][][]) Valid local method reference\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) {\n" + + " }\n" + + "}\n" }); + } + + public void test116() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references with array (wrong brackets peer)\n" + + " * \n" + + " * @see #smr_foo(char[ , int[][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char] , int[][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][, String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[]], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[[], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][, Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][]], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][[], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[]][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[[][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][][) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][]]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][[]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][]][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][[][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[]][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[[][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector][][][]) Invalid ref: invalid arguments declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(char[ , int[][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(char] , int[][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(char[] , int[][, String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " * @see #smr_foo(char[] , int[]], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " * @see #smr_foo(char[] , int[[], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " * @see #smr_foo(char[] , int][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " * @see #smr_foo(char[] , int[][], String[][][, Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " * @see #smr_foo(char[] , int[][], String[][]], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "9. ERROR in X.java (at line 14)\n" + + " * @see #smr_foo(char[] , int[][], String[][[], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "10. ERROR in X.java (at line 15)\n" + + " * @see #smr_foo(char[] , int[][], String[]][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "11. ERROR in X.java (at line 16)\n" + + " * @see #smr_foo(char[] , int[][], String[[][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "12. ERROR in X.java (at line 17)\n" + + " * @see #smr_foo(char[] , int[][], String][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "13. ERROR in X.java (at line 18)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][][) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "14. ERROR in X.java (at line 19)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][]]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "15. ERROR in X.java (at line 20)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][[]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "16. ERROR in X.java (at line 21)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][]][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "17. ERROR in X.java (at line 22)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][[][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "18. ERROR in X.java (at line 23)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[]][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "19. ERROR in X.java (at line 24)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[[][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "20. ERROR in X.java (at line 25)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test117() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references with array (non applicable arrays)\n" + + " * \n" + + " * @see #smr_foo(char , int[][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int, String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String, Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector) Invalid ref: invalid arguments declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(char , int[][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char, int[][], String[][][], Vector[][][][])\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(char[] , int[], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int[], String[][][], Vector[][][][])\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(char[] , int, String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int, String[][][], Vector[][][][])\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " * @see #smr_foo(char[] , int[][], String[][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int[][], String[][], Vector[][][][])\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " * @see #smr_foo(char[] , int[][], String[], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int[][], String[], Vector[][][][])\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " * @see #smr_foo(char[] , int[][], String, Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int[][], String, Vector[][][][])\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int[][], String[][][], Vector[][][])\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int[][], String[][][], Vector[][])\n" + + "----------\n" + + "9. ERROR in X.java (at line 14)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int[][], String[][][], Vector[])\n" + + "----------\n" + + "10. ERROR in X.java (at line 15)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(char[], int[][], String[][][], Vector[][][][]) in the type X is not applicable for the arguments (char[], int[][], String[][][], Vector)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test118() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references with array (non applicable arrays)\n" + + " * \n" + + " * @see #smr_foo(char[1] , int[][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[2][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][3], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[4][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][5][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][6], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[7][][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][8][][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][9][]) Invalid ref: invalid arguments declaration\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][][10]) Invalid ref: invalid arguments declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(char[] array, int[][] matrix, String[][][] dim, Vector[][][][] extra) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(char[1] , int[][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(char[] , int[2][], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(char[] , int[][3], String[][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " * @see #smr_foo(char[] , int[][], String[4][][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " * @see #smr_foo(char[] , int[][], String[][5][], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " * @see #smr_foo(char[] , int[][], String[][][6], Vector[][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[7][][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][8][][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "9. ERROR in X.java (at line 14)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][9][]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "10. ERROR in X.java (at line 15)\n" + + " * @see #smr_foo(char[] , int[][], String[][][], Vector[][][][10]) Invalid ref: invalid arguments declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void test120() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see #smr_foo() Valid local method reference\n" + + " * @see #smr_foo(boolean, int, byte, short, char, long, float, double) Valid local method reference\n" + + " * @see #smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see #smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) Valid local method reference\n" + + " * @see #smr_foo(boolean a1,int a2,byte a3,short a4,char a5,long a6,float a7,double a8) Valid local method reference\n" + + " * @see #smr_foo(String, String, int) Valid local method reference\n" + + " * @see #smr_foo(java.lang.String, String, int) Valid local method reference \n" + + " * @see #smr_foo(String, java.lang.String, int) Valid local method reference \n" + + " * @see #smr_foo(java.lang.String, java.lang.String, int) Valid local method reference \n" + + " * @see #smr_foo(String x,String y,int z) Valid local method reference \n" + + " * @see #smr_foo(java.lang.String x,String y, int z) Valid local method reference \n" + + " * @see #smr_foo(String x,java.lang.String y,int z) Valid local method reference \n" + + " * @see #smr_foo(java.lang.String x,java.lang.String y,int z) Valid local method reference \n" + + " * @see #smr_foo(java.util.Hashtable,java.util.Vector,boolean) Valid local method reference\n" + + " * @see #smr_foo(java.util.Hashtable,Vector,boolean) Valid local method reference\n" + + " * @see #smr_foo(java.util.Hashtable a, java.util.Vector b, boolean c) Valid local method reference\n" + + " * @see #smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test121() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " * @see #smrfoo() Invalid ref: undefined local method reference\n" + + " * @see #smr_FOO() Invalid ref: undefined local method reference\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #unknown() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see #smrfoo() Invalid ref: undefined local method reference\n" + + " ^^^^^^\n" + + "Javadoc: The method smrfoo() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see #smr_FOO() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_FOO() is undefined for the type X\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test122() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(boolean, int, byte, short, char, long, float) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean, int, byte, short, char, long) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean, int, byte, short, char) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean, int, byte, short) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean, int, byte) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean, int) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #smr_foo(boolean, int, byte, short, char, long, float) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (boolean, int, byte, short, char, long, float)\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(boolean, int, byte, short, char, long) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (boolean, int, byte, short, char, long)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(boolean, int, byte, short, char) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (boolean, int, byte, short, char)\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(boolean, int, byte, short) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (boolean, int, byte, short)\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " * @see #smr_foo(boolean, int, byte) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (boolean, int, byte)\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " * @see #smr_foo(boolean, int) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (boolean, int)\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " * @see #smr_foo(boolean) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (boolean)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test123() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(int, String, String) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(String, int, String) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(String, String) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(String) Invalid ref: local method not applicable\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #smr_foo(int, String, String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (int, String, String)\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(String, int, String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (String, int, String)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(String, String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (String, String)\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (String)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test124() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(java.util.Hashtable,java.util.Vector) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(java.util.Hashtable,boolean,java.util.Vector) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(boolean,java.util.Hashtable,java.util.Vector) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(java.util.Hashtable) Invalid ref: local method not applicable\n" + + " * @see #smr_foo(java.util.Vector) Invalid ref: local method not applicable\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #smr_foo(java.util.Hashtable,java.util.Vector) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(Hashtable, Vector, boolean) in the type X is not applicable for the arguments (Hashtable, Vector)\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(java.util.Hashtable,boolean,java.util.Vector) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(Hashtable, Vector, boolean) in the type X is not applicable for the arguments (Hashtable, boolean, Vector)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(boolean,java.util.Hashtable,java.util.Vector) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(Hashtable, Vector, boolean) in the type X is not applicable for the arguments (boolean, Hashtable, Vector)\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(java.util.Hashtable) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(Hashtable, Vector, boolean) in the type X is not applicable for the arguments (Hashtable)\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " * @see #smr_foo(java.util.Vector) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(Hashtable, Vector, boolean) in the type X is not applicable for the arguments (Vector)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test125() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(boolean,int i,byte y,short s,char c,long l,float f,double d) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(boolean b,int, byte y, short s, char c, long l, float f, double d) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(boolean b,int i,byte,short s,char c,long l,float f,double d) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(boolean b,int i,byte y,short,char c,long l,float f,double d) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(boolean b,int i,byte y,short s,char,long l,float f,double d) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(boolean b,int i,byte y,short s,char c,long,float f,double d) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(boolean b,int i,byte y,short s,char c,long l,float,double d) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(boolean b,int i,byte y,short s,char c,long l,float f,double) Invalid reference: mixed argument declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #smr_foo(boolean,int i,byte y,short s,char c,long l,float f,double d) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(boolean b,int, byte y, short s, char c, long l, float f, double d) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(boolean b,int i,byte,short s,char c,long l,float f,double d) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(boolean b,int i,byte y,short,char c,long l,float f,double d) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " * @see #smr_foo(boolean b,int i,byte y,short s,char,long l,float f,double d) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " * @see #smr_foo(boolean b,int i,byte y,short s,char c,long,float f,double d) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " * @see #smr_foo(boolean b,int i,byte y,short s,char c,long l,float,double d) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "8. ERROR in X.java (at line 12)\n" + + " * @see #smr_foo(boolean b,int i,byte y,short s,char c,long l,float f,double) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test126() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(String,String y,int z) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(java.lang.String x,String, int z) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(String x,java.lang.String y,int) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(java.lang.String,java.lang.String,int z) Invalid reference: mixed argument declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see #smr_foo(String,String y,int z) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(java.lang.String x,String, int z) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(String x,java.lang.String y,int) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(java.lang.String,java.lang.String,int z) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test127() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see #smr_foo(Hashtable,java.util.Vector,boolean) Invalid reference: unresolved argument type\n" + + " * @see #smr_foo(Hashtable,Vector,boolean) Invalid reference: unresolved argument type\n" + + " * @see #smr_foo(Hashtable a, java.util.Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " * @see #smr_foo(java.util.Hashtable a, java.util.Vector b, boolean) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(java.util.Hashtable, Vector, boolean c) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(Hashtable a, java.util.Vector, boolean c) Invalid reference: mixed argument declaration\n" + + " * @see #smr_foo(Hashtable, Vector b, boolean c) Invalid reference: mixed argument declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @see #smr_foo(Hashtable,java.util.Vector,boolean) Invalid reference: unresolved argument type\n" + + " ^^^^^^^^^\n" + + "Javadoc: Hashtable cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @see #smr_foo(Hashtable,Vector,boolean) Invalid reference: unresolved argument type\n" + + " ^^^^^^^^^\n" + + "Javadoc: Hashtable cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " * @see #smr_foo(Hashtable a, java.util.Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^^^^\n" + + "Javadoc: Hashtable cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " * @see #smr_foo(Hashtable a, Vector b, boolean c) Invalid reference: unresolved argument type\n" + + " ^^^^^^^^^\n" + + "Javadoc: Hashtable cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " * @see #smr_foo(java.util.Hashtable a, java.util.Vector b, boolean) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " * @see #smr_foo(java.util.Hashtable, Vector, boolean c) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " * @see #smr_foo(Hashtable a, java.util.Vector, boolean c) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " * @see #smr_foo(Hashtable, Vector b, boolean c) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test130() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see X#smr_foo() Valid local method reference\n" + + " * @see X#smr_foo(boolean, int, byte, short, char, long, float, double) Valid local method reference\n" + + " * @see X#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see X#smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) Valid local method reference\n" + + " * @see X#smr_foo(boolean a1,int a2,byte a3,short a4,char a5,long a6,float a7,double a8) Valid local method reference\n" + + " * @see X#smr_foo(String, String, int) Valid local method reference\n" + + " * @see X#smr_foo(java.lang.String, String, int) Valid local method reference \n" + + " * @see X#smr_foo(String, java.lang.String, int) Valid local method reference \n" + + " * @see X#smr_foo(java.lang.String, java.lang.String, int) Valid local method reference \n" + + " * @see X#smr_foo(String x,String y,int z) Valid local method reference \n" + + " * @see X#smr_foo(java.lang.String x,String y, int z) Valid local method reference \n" + + " * @see X#smr_foo(String x,java.lang.String y,int z) Valid local method reference \n" + + " * @see X#smr_foo(java.lang.String x,java.lang.String y,int z) Valid local method reference \n" + + " * @see X#smr_foo(java.util.Hashtable,java.util.Vector,boolean) Valid local method reference\n" + + " * @see X#smr_foo(java.util.Hashtable,Vector,boolean) Valid local method reference\n" + + " * @see X#smr_foo(java.util.Hashtable a, java.util.Vector b, boolean c) Valid local method reference\n" + + " * @see X#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test131() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see X#unknown() Invalid ref: undefined local method reference\n" + + " * @see X#smrfoo() Invalid ref: undefined local method reference\n" + + " * @see X#smr_FOO() Invalid ref: undefined local method reference\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see X#unknown() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see X#smrfoo() Invalid ref: undefined local method reference\n" + + " ^^^^^^\n" + + "Javadoc: The method smrfoo() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @see X#smr_FOO() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_FOO() is undefined for the type X\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test132() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see X#smr_foo(Object) Invalid ref: local method not applicable\n" + + " * @see X#smr_foo(int, byte, short, char, long, float, double) Invalid ref: local method not applicable\n" + + " * @see X#smr_foo(String, int) Invalid ref: local method not applicable\n" + + " * @see X#smr_foo(String) Invalid ref: local method not applicable\n" + + " * @see X#smr_foo(java.util.Hashtable,Vector) Invalid ref: local method not applicable\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @see X#smr_foo(Object) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo() in the type X is not applicable for the arguments (Object)\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @see X#smr_foo(int, byte, short, char, long, float, double) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (int, byte, short, char, long, float, double)\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " * @see X#smr_foo(String, int) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (String, int)\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " * @see X#smr_foo(String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " * @see X#smr_foo(java.util.Hashtable,Vector) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(Hashtable, Vector, boolean) in the type X is not applicable for the arguments (Hashtable, Vector)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test133() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see X#smr_foo(boolean,int i,byte,short s,char,long l,float,double d) Invalid reference: mixed argument declaration\n" + + " * @see X#smr_foo(String,String y,int) Invalid reference: mixed argument declaration\n" + + " * @see X#smr_foo(Hashtable,Vector,boolean) Invalid reference: unresolved argument type\n" + + " * @see X#smr_foo(Hashtable,Vector,boolean b) Invalid reference: mixed argument declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @see X#smr_foo(boolean,int i,byte,short s,char,long l,float,double d) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @see X#smr_foo(String,String y,int) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " * @see X#smr_foo(Hashtable,Vector,boolean) Invalid reference: unresolved argument type\n" + + " ^^^^^^^^^\n" + + "Javadoc: Hashtable cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " * @see X#smr_foo(Hashtable,Vector,boolean b) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test135() { + this.runConformTest( + new String[] { + "test/deep/qualified/name/p/X.java", + "package test.deep.qualified.name.p;\n" + + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Valid local methods references\n" + + " * \n" + + " * @see test.deep.qualified.name.p.X#smr_foo() Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(boolean, int, byte, short, char, long, float, double) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(boolean,int,byte,short,char,long,float,double) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(boolean a1,int a2,byte a3,short a4,char a5,long a6,float a7,double a8) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String, String, int) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.lang.String, String, int) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String, java.lang.String, int) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.lang.String, java.lang.String, int) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String x,String y,int z) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.lang.String x,String y, int z) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String x,java.lang.String y,int z) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.lang.String x,java.lang.String y,int z) Valid local method reference \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.util.Hashtable,java.util.Vector,boolean) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.util.Hashtable,Vector,boolean) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.util.Hashtable a, java.util.Vector b, boolean c) Valid local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.util.Hashtable a, Vector b, boolean c) Valid local method reference\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }); + } + + public void test136() { + this.runNegativeTest( + new String[] { + "test/deep/qualified/name/p/X.java", + "package test.deep.qualified.name.p;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see test.deep.qualified.name.p.X#unknown() Invalid ref: undefined local method reference\n" + + " * @see test.deep.qualified.name.p.X#smrfoo() Invalid ref: undefined local method reference\n" + + " * @see test.deep.qualified.name.p.X#smr_FOO() Invalid ref: undefined local method reference\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 6)\n" + + " * @see test.deep.qualified.name.p.X#unknown() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n" + + "2. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 7)\n" + + " * @see test.deep.qualified.name.p.X#smrfoo() Invalid ref: undefined local method reference\n" + + " ^^^^^^\n" + + "Javadoc: The method smrfoo() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 8)\n" + + " * @see test.deep.qualified.name.p.X#smr_FOO() Invalid ref: undefined local method reference\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_FOO() is undefined for the type X\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test137() { + this.runNegativeTest( + new String[] { + "test/deep/qualified/name/p/X.java", + "package test.deep.qualified.name.p;\n" + + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(Object) Invalid ref: local method not applicable\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(int, byte, short, char, long, float, double) Invalid ref: local method not applicable\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String, int) Invalid ref: local method not applicable\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String) Invalid ref: local method not applicable\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.util.Hashtable,Vector) Invalid ref: local method not applicable\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo() {\n" + + " }\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 7)\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(Object) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo() in the type X is not applicable for the arguments (Object)\n" + + "----------\n" + + "2. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 8)\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(int, byte, short, char, long, float, double) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(boolean, int, byte, short, char, long, float, double) in the type X is not applicable for the arguments (int, byte, short, char, long, float, double)\n" + + "----------\n" + + "3. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 9)\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String, int) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (String, int)\n" + + "----------\n" + + "4. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 10)\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(String, String, int) in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "5. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 11)\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(java.util.Hashtable,Vector) Invalid ref: local method not applicable\n" + + " ^^^^^^^\n" + + "Javadoc: The method smr_foo(Hashtable, Vector, boolean) in the type X is not applicable for the arguments (Hashtable, Vector)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test138() { + this.runNegativeTest( + new String[] { + "test/deep/qualified/name/p/X.java", + "package test.deep.qualified.name.p;\n" + + "import java.util.Vector;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid local methods references\n" + + " * \n" + + " * @see test.deep.qualified.name.p.X#smr_foo(boolean,int i,byte,short s,char,long l,float,double d) Invalid reference: mixed argument declaration\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String,String y,int) Invalid reference: mixed argument declaration\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(Hashtable,Vector,boolean b) Invalid reference: mixed argument declaration\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(Hashtable,Vector,boolean b) Invalid reference: mixed argument declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "\n" + + " // Empty methods definition for reference\n" + + " public void smr_foo(boolean b, int i, byte y, short s, char c, long l, float f, double d) {\n" + + " }\n" + + " public void smr_foo(String str1, java.lang.String str2, int i) {\n" + + " }\n" + + " public void smr_foo(java.util.Hashtable h, java.util.Vector v, boolean b) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in test\\deep\\qualified\\name\\p\\X.java (at line 2)\n"+ + " import java.util.Vector;\n"+ + " ^^^^^^^^^^^^^^^^\n"+ + "The import java.util.Vector is never used\n"+ + "----------\n"+ + "2. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 7)\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(boolean,int i,byte,short s,char,long l,float,double d) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 8)\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(String,String y,int) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 9)\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(Hashtable,Vector,boolean b) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "5. ERROR in test\\deep\\qualified\\name\\p\\X.java (at line 10)\n" + + " * @see test.deep.qualified.name.p.X#smr_foo(Hashtable,Vector,boolean b) Invalid reference: mixed argument declaration\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test140() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid package class methods references\n" + + " * \n" + + " * @see Visibility#vm_public() Valid ref: visible method\n" + + " * @see Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " * @see test.Visibility#vm_public() Valid ref: visible method\n" + + " * @see test.Visibility.VcPublic#vm_public() Valid ref: visible method in visible inner class\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test141() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package class methods references (non-existence)\n" + + " * \n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#unknown() Invalid ref: non-existent method\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.VcPublic#unknown() Invalid ref: non existent method in visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Visibility.VcPublic\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Unknown#vm_public() Invalid ref: non-existent class\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.Unknown#vm_public() Invalid ref: non existent inner class\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Visibility.Unknown cannot be resolved to a type\n" + + "----------\n"); + } + + public void test142() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package class methods references (non-visible)\n" + + " * \n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " * @see Visibility.VcPrivate#vm_private() Invalid ref: non visible inner class (non visible method)\n" + + " * @see Visibility.VcPrivate#vm_private(boolean, String) Invalid ref: non visible inner class (non applicable method)\n" + + " * @see Visibility.VcPrivate#vm_public() Invalid ref: non visible inner class (visible method)\n" + + " * @see Visibility.VcPrivate#vm_public(Object, float) Invalid ref: non visible inner class (non applicable visible method)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#vm_private() Invalid ref: non-visible method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.VcPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.VcPrivate#vm_private() Invalid ref: non visible inner class (non visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.VcPrivate#vm_private(boolean, String) Invalid ref: non visible inner class (non applicable method)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see Visibility.VcPrivate#vm_public() Invalid ref: non visible inner class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see Visibility.VcPrivate#vm_public(Object, float) Invalid ref: non visible inner class (non applicable visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.VcPrivate is not visible\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see Visibility.VcPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type Visibility.VcPublic is not visible\n" + + "----------\n"); + } + + public void test143() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package class methods references (non-applicable)\n" + + " * \n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#vm_private(int) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility#vm_public(String) Invalid ref: non-applicable method\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility is not applicable for the arguments (String)\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.VcPublic#vm_private(Integer, byte) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type Visibility.VcPublic is not applicable for the arguments (Integer, byte)\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.VcPublic#vm_public(Double z, Boolean x) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type Visibility.VcPublic is not applicable for the arguments (Double, Boolean)\n" + + "----------\n"); + } + + public void test144() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package class methods references (invalid arguments)\n" + + " * \n" + + " * @see Visibility#vm_private(,) Invalid ref: invalid argument declaration\n" + + " * @see Visibility#vm_public(,String) Invalid ref: invalid argument declaration\n" + + " * @see Visibility.VcPrivate#vm_private(char, double d) Invalid ref: invalid argument declaration\n" + + " * @see Visibility.VcPrivate#vm_public(#) Invalid ref: invalid argument declaration\n" + + " * @see Visibility.VcPublic#vm_private(a a a) Invalid ref: invalid argument declaration\n" + + " * @see Visibility.VcPublic#vm_public(####) Invalid ref: Invalid ref: invalid argument declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#vm_private(,) Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility#vm_public(,String) Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.VcPrivate#vm_private(char, double d) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.VcPrivate#vm_public(#) Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see Visibility.VcPublic#vm_private(a a a) Invalid ref: invalid argument declaration\n" + + " ^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see Visibility.VcPublic#vm_public(####) Invalid ref: Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n"); + } + + public void test145() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid package super class methods references\n" + + " * \n" + + " * @see Visibility#avm_public() Valid ref: visible inherited method\n" + + " * @see AbstractVisibility.AvcPublic#avm_public() Valid ref: visible method in visible inner class\n" + + " * @see test.Visibility#avm_public() Valid ref: visible inherited method\n" + + " * @see test.AbstractVisibility.AvcPublic#avm_public() Valid ref: visible method in visible inner class\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test146() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package super class methods references (non-visible)\n" + + " * \n" + + " * @see Visibility#avm_private() Invalid ref: non-visible inherited method\n" + + " * @see Visibility.AvcPrivate#unknown() Invalid ref: non visible inherited inner class (non existent method)\n" + + " * @see Visibility.AvcPrivate#avm_private() Invalid ref: non visible inherited inner class (non visible method)\n" + + " * @see Visibility.AvcPrivate#avm_private(boolean, String) Invalid ref: non visible inherited inner class (non applicable method)\n" + + " * @see Visibility.AvcPrivate#avm_public() Invalid ref: non visible inherited inner class (visible method)\n" + + " * @see Visibility.AvcPrivate#avm_public(Object, float) Invalid ref: non visible inherited inner class (non applicable visible method)\n" + + " * @see Visibility.AvcPublic#avm_private() Invalid ref: non visible inherited method in visible inherited inner class\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#avm_private() Invalid ref: non-visible inherited method\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: The method avm_private() from the type AbstractVisibility is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility.AvcPrivate#unknown() Invalid ref: non visible inherited inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.AvcPrivate#avm_private() Invalid ref: non visible inherited inner class (non visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.AvcPrivate#avm_private(boolean, String) Invalid ref: non visible inherited inner class (non applicable method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see Visibility.AvcPrivate#avm_public() Invalid ref: non visible inherited inner class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see Visibility.AvcPrivate#avm_public(Object, float) Invalid ref: non visible inherited inner class (non applicable visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type Visibility.AvcPrivate is not visible\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see Visibility.AvcPublic#avm_private() Invalid ref: non visible inherited method in visible inherited inner class\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: The method avm_private() from the type AbstractVisibility.AvcPublic is not visible\n" + + "----------\n"); + } + + public void test147() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package super class methods references (non-applicable)\n" + + " * \n" + + " * @see Visibility#avm_private(int) Invalid ref: non-applicable inherited method\n" + + " * @see Visibility#avm_public(String) Invalid ref: non-applicable inherited method\n" + + " * @see Visibility.AvcPublic#avm_private(Integer, byte) Invalid ref: non applicable inherited method in visible inner class\n" + + " * @see Visibility.AvcPublic#avm_public(Double z, Boolean x) Invalid ref: non applicable inherited method in visible inner class\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#avm_private(int) Invalid ref: non-applicable inherited method\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: The method avm_private() in the type AbstractVisibility is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility#avm_public(String) Invalid ref: non-applicable inherited method\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method avm_public() in the type AbstractVisibility is not applicable for the arguments (String)\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.AvcPublic#avm_private(Integer, byte) Invalid ref: non applicable inherited method in visible inner class\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: The method avm_private() in the type AbstractVisibility.AvcPublic is not applicable for the arguments (Integer, byte)\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.AvcPublic#avm_public(Double z, Boolean x) Invalid ref: non applicable inherited method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method avm_public() in the type AbstractVisibility.AvcPublic is not applicable for the arguments (Double, Boolean)\n" + + "----------\n"); + } + + public void test148() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid package super class methods references (invalid arguments)\n" + + " * \n" + + " * @see Visibility#avm_private(,,,,) Invalid ref: invalid argument declaration\n" + + " * @see Visibility#avm_public(String,,,) Invalid ref: invalid argument declaration\n" + + " * @see Visibility.AvcPrivate#avm_private(char c, double) Invalid ref: invalid argument declaration\n" + + " * @see Visibility.AvcPrivate#avm_public(*) Invalid ref: invalid argument declaration\n" + + " * @see Visibility.AvcPublic#avm_private(a a a) Invalid ref: invalid argument declaration\n" + + " * @see Visibility.AvcPublic#avm_public(*****) Invalid ref: invalid argument declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see Visibility#avm_private(,,,,) Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see Visibility#avm_public(String,,,) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see Visibility.AvcPrivate#avm_private(char c, double) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see Visibility.AvcPrivate#avm_public(*) Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see Visibility.AvcPublic#avm_private(a a a) Invalid ref: invalid argument declaration\n" + + " ^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see Visibility.AvcPublic#avm_public(*****) Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n"); + } + + public void test150() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.*;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class methods references (non existent/visible arguments)\n" + + " * \n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " * @see VisibilityPackage#vm_private() Invalid ref: non visible class (non visible method)\n" + + " * @see VisibilityPackage#vm_private(boolean) Invalid ref: non visible class (non existent method)\n" + + " * @see VisibilityPackage#vm_public() Invalid ref: non visible class (visible method)\n" + + " * @see VisibilityPackage#vm_public(long,long,long,int) Invalid ref: non visible class (visible method)\n" + + " * @see VisibilityPackage.VpPrivate#unknown() Invalid ref: non visible class and non visible inner class (non existent method)\n" + + " * @see VisibilityPackage.VpPrivate#vm_private() Invalid ref: non visible class and non visible inner class (non visible method)\n" + + " * @see VisibilityPackage.VpPrivate#vm_private(boolean, String) Invalid ref: non visible class and non visible inner class (non applicable method)\n" + + " * @see VisibilityPackage.VpPrivate#vm_public() Invalid ref: non visible class and non visible inner class (visible method)\n" + + " * @see VisibilityPackage.VpPrivate#vm_public(Object, float) Invalid ref: non visible class and non visible inner class (non applicable visible method)\n" + + " * @see VisibilityPackage.VpPublic#unknown() Invalid ref: non visible class and visible inner class (non existent method)\n" + + " * @see VisibilityPackage.VpPublic#vm_private() Invalid ref: non visible class and visible inner class (non visible method)\n" + + " * @see VisibilityPackage.VpPublic#vm_private(boolean, String) Invalid ref: non visible class and visible inner class (non applicable method)\n" + + " * @see VisibilityPackage.VpPublic#vm_public() Invalid ref: non visible class and visible inner class (visible method)\n" + + " * @see VisibilityPackage.VpPublic#vm_public(Object, float) Invalid ref: non visible class and visible inner class (non applicable visible method)\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in test\\X.java (at line 2)\n"+ + " import test.copy.*;\n"+ + " ^^^^^^^^^\n"+ + "The import test.copy is never used\n"+ + "----------\n"+ + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPackage#vm_private() Invalid ref: non visible class (non visible method)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPackage#vm_private(boolean) Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPackage#vm_public() Invalid ref: non visible class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see VisibilityPackage#vm_public(long,long,long,int) Invalid ref: non visible class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see VisibilityPackage.VpPrivate#unknown() Invalid ref: non visible class and non visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "8. ERROR in test\\X.java (at line 13)\n" + + " * @see VisibilityPackage.VpPrivate#vm_private() Invalid ref: non visible class and non visible inner class (non visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "9. ERROR in test\\X.java (at line 14)\n" + + " * @see VisibilityPackage.VpPrivate#vm_private(boolean, String) Invalid ref: non visible class and non visible inner class (non applicable method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "10. ERROR in test\\X.java (at line 15)\n" + + " * @see VisibilityPackage.VpPrivate#vm_public() Invalid ref: non visible class and non visible inner class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "11. ERROR in test\\X.java (at line 16)\n" + + " * @see VisibilityPackage.VpPrivate#vm_public(Object, float) Invalid ref: non visible class and non visible inner class (non applicable visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "12. ERROR in test\\X.java (at line 17)\n" + + " * @see VisibilityPackage.VpPublic#unknown() Invalid ref: non visible class and visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "13. ERROR in test\\X.java (at line 18)\n" + + " * @see VisibilityPackage.VpPublic#vm_private() Invalid ref: non visible class and visible inner class (non visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "14. ERROR in test\\X.java (at line 19)\n" + + " * @see VisibilityPackage.VpPublic#vm_private(boolean, String) Invalid ref: non visible class and visible inner class (non applicable method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "15. ERROR in test\\X.java (at line 20)\n" + + " * @see VisibilityPackage.VpPublic#vm_public() Invalid ref: non visible class and visible inner class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n" + + "16. ERROR in test\\X.java (at line 21)\n" + + " * @see VisibilityPackage.VpPublic#vm_public(Object, float) Invalid ref: non visible class and visible inner class (non applicable visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPackage is not visible\n" + + "----------\n"); + } + + public void test151() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.VisibilityPackage;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package non visible class methods references (invalid arguments)\n" + + " * \n" + + " * @see VisibilityPackage#vm_private(boolean-) Invalid ref: invalid argument declaration\n" + + " * @see VisibilityPackage#vm_public(long, int() Invalid ref: invalid argument declaration\n" + + " * @see VisibilityPackage.VpPrivate#vm_private(char, a double d()) Invalid ref: invalid argument declaration\n" + + " * @see VisibilityPackage.VpPrivate#vm_public(()) Invalid ref: invalid argument declaration\n" + + " * @see VisibilityPackage.VpPublic#vm_private(char double) Invalid ref: invalid argument declaration\n" + + " * @see VisibilityPackage.VpPublic#vm_public((((() Invalid ref: invalid argument declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 2)\n" + + " import test.copy.VisibilityPackage;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPackage#vm_private(boolean-) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPackage#vm_public(long, int() Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPackage.VpPrivate#vm_private(char, a double d()) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPackage.VpPrivate#vm_public(()) Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see VisibilityPackage.VpPublic#vm_private(char double) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see VisibilityPackage.VpPublic#vm_public((((() Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n", + JavacTestOptions.DEFAULT); + } + + public void test152() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other fully qualified name package non visible class methods references (non existent/visible arguments)\n" + + " * \n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " * @see test.copy.VisibilityPackage#vm_private() Invalid ref: non visible class (non visible method)\n" + + " * @see test.copy.VisibilityPackage#vm_private(boolean) Invalid ref: non visible class (non existent method)\n" + + " * @see test.copy.VisibilityPackage#vm_public() Invalid ref: non visible class (visible method)\n" + + " * @see test.copy.VisibilityPackage#vm_public(long,long,long,int) Invalid ref: non visible class (visible method)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#unknown() Invalid ref: non visible class and non visible inner class (non existent method)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_private() Invalid ref: non visible class and non visible inner class (non visible method)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_private(boolean, String) Invalid ref: non visible class and non visible inner class (non applicable method)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_public() Invalid ref: non visible class and non visible inner class (visible method)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_public(Object, float) Invalid ref: non visible class and non visible inner class (non applicable visible method)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#unknown() Invalid ref: non visible class and visible inner class (non existent method)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_private() Invalid ref: non visible class and visible inner class (non visible method)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_private(boolean, String) Invalid ref: non visible class and visible inner class (non applicable method)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_public() Invalid ref: non visible class and visible inner class (visible method)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_public(Object, float) Invalid ref: non visible class and visible inner class (non applicable visible method)\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see test.copy.VisibilityPackage#unknown() Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see test.copy.VisibilityPackage#vm_private() Invalid ref: non visible class (non visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.copy.VisibilityPackage#vm_private(boolean) Invalid ref: non visible class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see test.copy.VisibilityPackage#vm_public() Invalid ref: non visible class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see test.copy.VisibilityPackage#vm_public(long,long,long,int) Invalid ref: non visible class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#unknown() Invalid ref: non visible class and non visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_private() Invalid ref: non visible class and non visible inner class (non visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "8. ERROR in test\\X.java (at line 13)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_private(boolean, String) Invalid ref: non visible class and non visible inner class (non applicable method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "9. ERROR in test\\X.java (at line 14)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_public() Invalid ref: non visible class and non visible inner class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "10. ERROR in test\\X.java (at line 15)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_public(Object, float) Invalid ref: non visible class and non visible inner class (non applicable visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "11. ERROR in test\\X.java (at line 16)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#unknown() Invalid ref: non visible class and visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "12. ERROR in test\\X.java (at line 17)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_private() Invalid ref: non visible class and visible inner class (non visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "13. ERROR in test\\X.java (at line 18)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_private(boolean, String) Invalid ref: non visible class and visible inner class (non applicable method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "14. ERROR in test\\X.java (at line 19)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_public() Invalid ref: non visible class and visible inner class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n" + + "15. ERROR in test\\X.java (at line 20)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_public(Object, float) Invalid ref: non visible class and visible inner class (non applicable visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPackage is not visible\n" + + "----------\n"); + } + + public void test153() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other fully qualified name package non visible class methods references (invalid arguments)\n" + + " * \n" + + " * @see test.copy.VisibilityPackage#vm_private(boolean-) Invalid ref: invalid argument declaration\n" + + " * @see test.copy.VisibilityPackage#vm_public(long, int() Invalid ref: invalid argument declaration\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_private(char, a double d()) Invalid ref: invalid argument declaration\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_public(()) Invalid ref: invalid argument declaration\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_private(char double) Invalid ref: invalid argument declaration\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_public((((() Invalid ref: invalid argument declaration\n" + + " */ \n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see test.copy.VisibilityPackage#vm_private(boolean-) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see test.copy.VisibilityPackage#vm_public(long, int() Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_private(char, a double d()) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see test.copy.VisibilityPackage.VpPrivate#vm_public(()) Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_private(char double) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see test.copy.VisibilityPackage.VpPublic#vm_public((((() Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n"); + } + + public void test154() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + "public class X {\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" + } + ); + } + + public void test155() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package visible class methods references (non-existent)\n" + + " * \n" + + " * @see VisibilityPublic#unknown() Invalid ref: non existent method\n" + + " * @see VisibilityPublic.VpPublic#unknown() Invalid ref: non existent method of visible inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPublic#unknown() Invalid ref: non existent method\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type VisibilityPublic\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPublic.VpPublic#unknown() Invalid ref: non existent method of visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type VisibilityPublic.VpPublic\n" + + "----------\n"); + } + + public void test156() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package visible class methods references (non-visible)\n" + + " * \n" + + " * @see VisibilityPublic#vm_private() Invalid ref: non visible method in visible class\n" + + " * @see VisibilityPublic#vm_public() Valid ref: visible method in visible class\n" + + " * @see VisibilityPublic.VpPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " * @see VisibilityPublic.VpPrivate#vm_private() Invalid ref: non visible inner class in visible class and (non visible method)\n" + + " * @see VisibilityPublic.VpPrivate#vm_private(boolean, String) Invalid ref: non visible inner class in visible class (non applicable method)\n" + + " * @see VisibilityPublic.VpPrivate#vm_public() Invalid ref: non visible inner class in visible class (visible method)\n" + + " * @see VisibilityPublic.VpPrivate#vm_public(Object, float) Invalid ref: non visible inner class in visible class (non applicable visible method)\n" + + " * @see VisibilityPublic.VpPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPublic#vm_private() Invalid ref: non visible method in visible class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type VisibilityPublic is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPublic.VpPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPublic.VpPrivate#vm_private() Invalid ref: non visible inner class in visible class and (non visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 11)\n" + + " * @see VisibilityPublic.VpPrivate#vm_private(boolean, String) Invalid ref: non visible inner class in visible class (non applicable method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 12)\n" + + " * @see VisibilityPublic.VpPrivate#vm_public() Invalid ref: non visible inner class in visible class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 13)\n" + + " * @see VisibilityPublic.VpPrivate#vm_public(Object, float) Invalid ref: non visible inner class in visible class (non applicable visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 14)\n" + + " * @see VisibilityPublic.VpPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type VisibilityPublic.VpPublic is not visible\n" + + "----------\n"); + } + + public void test157() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package visible class methods references (non-applicable)\n" + + " * \n" + + " * @see VisibilityPublic#vm_private(boolean) Invalid ref: non applicable method in visible class\n" + + " * @see VisibilityPublic#vm_public(long,long,long,int) Invalid ref: non applicable method in visible class\n" + + " * @see VisibilityPublic.VpPublic#vm_private(boolean, String) Invalid ref: non applicable method in visible inner class\n" + + " * @see VisibilityPublic.VpPublic#vm_public(Object, float) Invalid ref: visible inner class (non applicable visible method)\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPublic#vm_private(boolean) Invalid ref: non applicable method in visible class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type VisibilityPublic is not applicable for the arguments (boolean)\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPublic#vm_public(long,long,long,int) Invalid ref: non applicable method in visible class\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type VisibilityPublic is not applicable for the arguments (long, long, long, int)\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPublic.VpPublic#vm_private(boolean, String) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type VisibilityPublic.VpPublic is not applicable for the arguments (boolean, String)\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPublic.VpPublic#vm_public(Object, float) Invalid ref: visible inner class (non applicable visible method)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type VisibilityPublic.VpPublic is not applicable for the arguments (Object, float)\n" + + "----------\n"); + } + + public void test158() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package visible class methods references (non-existent)\n" + + " * \n" + + " * @see VisibilityPublic#vm_private(\"boolean\") Invalid ref: invalid argument declaration\n" + + " * @see VisibilityPublic#vm_public(long, \"int) Invalid ref: invalid argument definition\n" + + " * @see VisibilityPublic.VpPrivate#vm_private(double d()) Invalid ref: invalid argument declaration\n" + + " * @see VisibilityPublic.VpPrivate#vm_public(\") Invalid ref: invalid argument declaration\n" + + " * @see VisibilityPublic.VpPublic#vm_private(d()) Invalid ref: invalid argument declaration\n" + + " * @see VisibilityPublic.VpPublic#vm_public(205) Invalid ref: invalid argument declaration\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in test\\X.java (at line 2)\n"+ + " import test.copy.VisibilityPublic;\n"+ + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n"+ + "The import test.copy.VisibilityPublic is never used\n"+ + "----------\n"+ + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see VisibilityPublic#vm_private(\"boolean\") Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see VisibilityPublic#vm_public(long, \"int) Invalid ref: invalid argument definition\n" + + " ^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see VisibilityPublic.VpPrivate#vm_private(double d()) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see VisibilityPublic.VpPrivate#vm_public(\") Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see VisibilityPublic.VpPublic#vm_private(d()) Invalid ref: invalid argument declaration\n" + + " ^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see VisibilityPublic.VpPublic#vm_public(205) Invalid ref: invalid argument declaration\n" + + " ^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n"); + } + + public void test159() { + runConformReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Valid other package visible class methods references \n" + + " * \n" + + " * @see test.copy.VisibilityPublic#vm_public() Valid ref to not visible method of other package class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public() Valid ref to visible method of other package public inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }); + } + + public void test160() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package visible class methods references (non-existent)\n" + + " * \n" + + " * @see test.copy.VisibilityPublic#unknown() Invalid ref: non existent method\n" + + " * @see test.copy.VisibilityPublic.VpPublic#unknown() Invalid ref: non existent method of visible inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see test.copy.VisibilityPublic#unknown() Invalid ref: non existent method\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type VisibilityPublic\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see test.copy.VisibilityPublic.VpPublic#unknown() Invalid ref: non existent method of visible inner class\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type VisibilityPublic.VpPublic\n" + + "----------\n"); + } + + public void test161() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package visible class methods references (non-visible)\n" + + " * \n" + + " * @see test.copy.VisibilityPublic#vm_private() Invalid ref: non visible method in visible class\n" + + " * @see test.copy.VisibilityPublic#vm_public() Valid ref: visible method in visible class\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_private() Invalid ref: non visible inner class in visible class and (non visible method)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_private(boolean, String) Invalid ref: non visible inner class in visible class (non applicable method)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_public() Invalid ref: non visible inner class in visible class (visible method)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_public(Object, float) Invalid ref: non visible inner class in visible class (non applicable visible method)\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see test.copy.VisibilityPublic#vm_private() Invalid ref: non visible method in visible class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type VisibilityPublic is not visible\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 8)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#unknown() Invalid ref: non visible inner class (non existent method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 9)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_private() Invalid ref: non visible inner class in visible class and (non visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 10)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_private(boolean, String) Invalid ref: non visible inner class in visible class (non applicable method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 11)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_public() Invalid ref: non visible inner class in visible class (visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 12)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_public(Object, float) Invalid ref: non visible inner class in visible class (non applicable visible method)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type test.copy.VisibilityPublic.VpPrivate is not visible\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 13)\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_private() Invalid ref: non visible method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() from the type VisibilityPublic.VpPublic is not visible\n" + + "----------\n"); + } + + public void test162() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package visible class methods references (non-applicable)\n" + + " * \n" + + " * @see test.copy.VisibilityPublic#vm_private(boolean) Invalid ref: non applicable method in visible class\n" + + " * @see test.copy.VisibilityPublic#vm_public(long,long,long,int) Invalid ref: non applicable method in visible class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_private(boolean, String) Invalid ref: non applicable method in visible inner class\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public(Object, float) Invalid ref: visible inner class (non applicable visible method)\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @see test.copy.VisibilityPublic#vm_private(boolean) Invalid ref: non applicable method in visible class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type VisibilityPublic is not applicable for the arguments (boolean)\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see test.copy.VisibilityPublic#vm_public(long,long,long,int) Invalid ref: non applicable method in visible class\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type VisibilityPublic is not applicable for the arguments (long, long, long, int)\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_private(boolean, String) Invalid ref: non applicable method in visible inner class\n" + + " ^^^^^^^^^^\n" + + "Javadoc: The method vm_private() in the type VisibilityPublic.VpPublic is not applicable for the arguments (boolean, String)\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public(Object, float) Invalid ref: visible inner class (non applicable visible method)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method vm_public() in the type VisibilityPublic.VpPublic is not applicable for the arguments (Object, float)\n" + + "----------\n"); + } + + public void test163() { + this.runNegativeReferenceTest( + new String[] { + "test/X.java", + "package test;\n" + + "import test.copy.VisibilityPublic;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid other package visible class methods references (non-existent)\n" + + " * \n" + + " * @see test.copy.VisibilityPublic#vm_private(\"\") Invalid ref: invalid argument declaration\n" + + " * @see test.copy.VisibilityPublic#vm_public(\"\"\") Invalid ref: invalid argument definition\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_private(String d()) Invalid ref: invalid argument declaration\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_public([) Invalid ref: invalid argument declaration\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_private([]) Invalid ref: invalid argument declaration\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public(char[], int[],]) Invalid ref: invalid argument declaration\n" + + " */\n" + + " public void s_foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in test\\X.java (at line 2)\n"+ + " import test.copy.VisibilityPublic;\n"+ + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n"+ + "The import test.copy.VisibilityPublic is never used\n"+ + "----------\n"+ + "2. ERROR in test\\X.java (at line 7)\n" + + " * @see test.copy.VisibilityPublic#vm_private(\"\") Invalid ref: invalid argument declaration\n" + + " ^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 8)\n" + + " * @see test.copy.VisibilityPublic#vm_public(\"\"\") Invalid ref: invalid argument definition\n" + + " ^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 9)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_private(String d()) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 10)\n" + + " * @see test.copy.VisibilityPublic.VpPrivate#vm_public([) Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 11)\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_private([]) Invalid ref: invalid argument declaration\n" + + " ^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 12)\n" + + " * @see test.copy.VisibilityPublic.VpPublic#vm_public(char[], int[],]) Invalid ref: invalid argument declaration\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid parameters declaration\n" + + "----------\n"); + } + + public void test164() { + this.runNegativeReferenceTest( + new String[] { + "X.java", + "package test;\n" + + "public class X {\n" + + " /**\n" + + " * Invalid param and throws tags\n" + + " * \n" + + " * @param\n" + + " * @throws\n" + + " */\n" + + " public void s_foo(int a) throws Exception {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " * @throws\n" + + " ^^^^^^\n" + + "Javadoc: Missing class name\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " public void s_foo(int a) throws Exception {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " public void s_foo(int a) throws Exception {\n" + + " ^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception Exception\n" + + "----------\n"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForModule.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForModule.java new file mode 100644 index 0000000000..941d268c1b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForModule.java @@ -0,0 +1,990 @@ +/******************************************************************************* + * Copyright (c) 2019, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Red Hat Inc. - copied from ModuleCompilationTests and used for Javadoc + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.DirectoryNotEmptyException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; + +public class JavadocTestForModule extends AbstractBatchCompilerTest { + + static { +// TESTS_NAMES = new String[] { "testBug549855a" }; + // TESTS_NUMBERS = new int[] { 1 }; + // TESTS_RANGE = new int[] { 298, -1 }; + } + + public JavadocTestForModule(String name) { + super(name); + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); + } + + public static Class testClass() { + return JavadocTestForModule.class; + } + + protected void writeFileCollecting(List collectedFiles, String directoryName, String fileName, String source) { + writeFile(directoryName, fileName, source); + collectedFiles.add(directoryName+File.separator+fileName); + } + + protected void writeFile(String directoryName, String fileName, String source) { + File directory = new File(directoryName); + if (!directory.exists()) { + if (!directory.mkdirs()) { + System.out.println("Could not create " + directoryName); + return; + } + } + String filePath = directory.getAbsolutePath() + File.separator + fileName; + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(filePath)); + writer.write(source); + writer.flush(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + class Runner extends AbstractRegressionTest.Runner { + StringBuffer commandLine = new StringBuffer(); + String outputDir = OUTPUT_DIR + File.separator + "javac"; + List fileNames = new ArrayList<>(); + /** will replace any -8, -9 ... option for javac */ + String javacVersionOptions; + + Runner() { + this.javacTestOptions = JavacTestOptions.DEFAULT; + this.expectedOutputString = ""; + this.expectedErrorString = ""; + } + /** Create a source file and add the filename to the compiler command line. */ + void createFile(String directoryName, String fileName, String source) { + writeFileCollecting(this.fileNames, directoryName, fileName, source); + } + Set runConformModuleTest() { + if (!this.fileNames.isEmpty()) { + this.shouldFlushOutputDirectory = false; + if (this.testFiles == null) + this.testFiles = new String[0]; + for (String fileName : this.fileNames) { + this.commandLine.append(" \"").append(fileName).append("\""); + } + } + String commandLineString = this.commandLine.toString(); + String javacCommandLine = adjustForJavac(commandLineString, this.javacVersionOptions); + return JavadocTestForModule.this.runConformModuleTest(this.testFiles, commandLineString, + this.expectedOutputString, this.expectedErrorString, + this.shouldFlushOutputDirectory, this.outputDir, + this.javacTestOptions, javacCommandLine); + } + } + + void runConformModuleTest(List testFileNames, StringBuffer commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory) + { + runConformModuleTest(testFileNames, commandLine, + expectedFailureOutOutputString, expectedFailureErrOutputString, shouldFlushOutputDirectory, OUTPUT_DIR + File.separator + "javac"); + } + + void runConformModuleTest(List testFileNames, StringBuffer commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String output) + { + for (String file : testFileNames) + commandLine.append(" \"").append(file).append("\""); + runConformModuleTest(new String[0], commandLine.toString(), + expectedFailureOutOutputString, expectedFailureErrOutputString, shouldFlushOutputDirectory, + output, JavacTestOptions.DEFAULT, null); + } + + Set runConformModuleTest(String[] testFiles, String commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory) + { + return runConformModuleTest(testFiles, commandLine, expectedFailureErrOutputString, expectedFailureErrOutputString, + shouldFlushOutputDirectory, OUTPUT_DIR, JavacTestOptions.DEFAULT, null); + } + + Set runConformModuleTest(String[] testFiles, String commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String output, JavacTestOptions options, String javacCommandLine) + { + this.runConformTest(testFiles, commandLine, expectedFailureOutOutputString, expectedFailureErrOutputString, shouldFlushOutputDirectory); + if (RUN_JAVAC) { + File outputDir = new File(output); + final Set outFiles = new HashSet<>(); + walkOutFiles(output, outFiles, true); + String[] testFileNames = new String[testFiles.length/2]; + for (int i = 0; i < testFileNames.length; i++) { + testFileNames[i] = testFiles[i*2]; + } + if (javacCommandLine == null) { + javacCommandLine = adjustForJavac(commandLine, null); + } + for (JavacCompiler javacCompiler : javacCompilers) { + if (javacCompiler.compliance < ClassFileConstants.JDK9) + continue; + if (options.skip(javacCompiler)) { + System.err.println("Skip testing javac in "+testName()); + continue; + } + StringBuffer log = new StringBuffer(); + try { + long compileResult = javacCompiler.compile( + outputDir, /* directory */ + javacCommandLine /* options */, + testFileNames /* source file names */, + log, + false); // don't repeat filenames on the command line + if (compileResult != 0) { + System.err.println("Previous error was from "+testName()); + fail("Unexpected error from javac"); + } + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + throw new AssertionFailedError(e.getMessage()); + } + final Set expectedFiles = new HashSet<>(outFiles); + walkOutFiles(output, expectedFiles, false); + for (String missingFile : expectedFiles) + System.err.println("Missing output file from javac: "+missingFile); + } + return outFiles; + } + return null; + } + + void runNegativeModuleTest(List testFileNames, StringBuffer commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String javacErrorMatch) { + runNegativeModuleTest(testFileNames, commandLine, expectedFailureOutOutputString, + expectedFailureErrOutputString, shouldFlushOutputDirectory, javacErrorMatch, OUTPUT_DIR + File.separator + "javac"); + } + + void runNegativeModuleTest(List testFileNames, StringBuffer commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String javacErrorMatch, String output) + { + runNegativeModuleTest(testFileNames, commandLine, expectedFailureOutOutputString, expectedFailureErrOutputString, + shouldFlushOutputDirectory, javacErrorMatch, output, JavacTestOptions.DEFAULT); + } + void runNegativeModuleTest(List testFileNames, StringBuffer commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String javacErrorMatch, String output, JavacTestOptions options) + { + for (String file : testFileNames) + commandLine.append(" \"").append(file).append("\""); + runNegativeModuleTest(new String[0], commandLine.toString(), + expectedFailureOutOutputString, expectedFailureErrOutputString, shouldFlushOutputDirectory, javacErrorMatch, output, + options); + } + void runNegativeModuleTest(String[] testFiles, String commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String javacErrorMatch) { + runNegativeModuleTest(testFiles, commandLine, expectedFailureOutOutputString, expectedFailureErrOutputString, + shouldFlushOutputDirectory, javacErrorMatch, OUTPUT_DIR, JavacTestOptions.DEFAULT); + } + + void runNegativeModuleTest(String[] testFiles, String commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String javacErrorMatch, String output, JavacTestOptions options) + { + this.runNegativeTest(testFiles, commandLine, expectedFailureOutOutputString, expectedFailureErrOutputString, shouldFlushOutputDirectory); + if (RUN_JAVAC) { + String[] testFileNames = new String[testFiles.length/2]; + for (int i = 0; i < testFileNames.length; i++) { + testFileNames[i] = testFiles[i*2]; + } + File outputDir = new File(OUTPUT_DIR); + final Set outFiles = new HashSet<>(); + walkOutFiles(output, outFiles, true); + for (JavacCompiler javacCompiler : javacCompilers) { + if (javacCompiler.compliance < ClassFileConstants.JDK9) + continue; + JavacTestOptions.Excuse excuse = options.excuseFor(javacCompiler); + + commandLine = adjustForJavac(commandLine, null); + StringBuffer log = new StringBuffer(); + int mismatch = 0; + try { + long compileResult = javacCompiler.compile( + outputDir, /* directory */ + commandLine /* options */, + testFileNames /* source file names */, + log); + if (compileResult == 0) { + mismatch = JavacTestOptions.MismatchType.EclipseErrorsJavacNone; + javacErrorMatch = expectedFailureErrOutputString; + System.err.println("Previous error was from "+testName()); + } else if (!log.toString().contains(javacErrorMatch)) { + mismatch = JavacTestOptions.MismatchType.CompileErrorMismatch; + System.err.println(testName()+": Error match " + javacErrorMatch + " not found in \n"+log.toString()); + } + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + throw new AssertionFailedError(e.getMessage()); + } + handleMismatch(javacCompiler, testName(), testFiles, javacErrorMatch, + "", "", log, "", "", + excuse, mismatch); + final Set expectedFiles = new HashSet<>(outFiles); + walkOutFiles(output, expectedFiles, false); + for (String missingFile : expectedFiles) + System.err.println("Missing output file from javac: "+missingFile); + } + } + } + + /** + * @param commandLine command line arguments as used for ecj + * @param versionOptions if non-null use this to replace any ecj-specific -8, -9 etc. arg. + * If ecj-specific arg is not found, append anyway + * @return commandLine adjusted for javac + */ + String adjustForJavac(String commandLine, String versionOptions) { + String[] tokens = commandLine.split(" "); + StringBuilder buf = new StringBuilder(); + boolean skipNext = false; + for (int i = 0; i < tokens.length; i++) { + if (skipNext) { + skipNext = false; + continue; + } + if (tokens[i].trim().equals("-9")) { + if (versionOptions == null) + buf.append(' ').append(" --release 9 "); + continue; + } + if (tokens[i].trim().equals("-8")) { + if (versionOptions == null) + buf.append(' ').append(" --release 8 "); + continue; + } + if (tokens[i].startsWith("-warn") || tokens[i].startsWith("-err") || tokens[i].startsWith("-info")) { + if (tokens[i].contains("exports") && !tokens[i].contains("-exports")) + buf.append(" -Xlint:exports "); + continue; + } + if (tokens[i].trim().equals("-classNames")) { + skipNext = true; + continue; + } + if (tokens[i].trim().equals("-enableJavadoc")) { + buf.append(" -Xdoclint:all "); + continue; + } + buf.append(tokens[i]).append(' '); + } + if (versionOptions != null) { + buf.append(versionOptions); + } + return buf.toString(); + } + + private void walkOutFiles(final String outputLocation, final Set fileNames, boolean add) { + if (!(new File(outputLocation)).exists()) + return; + try { + Files.walkFileTree(FileSystems.getDefault().getPath(outputLocation), new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (file.toString().endsWith(".class")) { + if (add) { + fileNames.add(file.toString()); + } else { + if (!fileNames.remove(file.toString())) + System.err.println("Unexpected output file from javac: "+file.toString()); + } + Files.delete(file); + } + return FileVisitResult.CONTINUE; + } + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (!dir.toString().equals(outputLocation)) { + try { + Files.delete(dir); + } catch (DirectoryNotEmptyException ex) { + // expected + } + } + return FileVisitResult.CONTINUE; + } + }); + } catch (IOException e) { + e.printStackTrace(); + throw new AssertionFailedError(e.getMessage()); + } + } + + public void testBug549855a() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + " provides p.I1 with p.P1;\n" + + " uses java.util.Currency;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "I1.java", + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " */\n" + + "public interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "P1.java", + "package p;\n" + + "/**\n" + + " * class P1\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -enableJavadoc ") + .append(" -err:allJavadoc ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "I1.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "P1.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 5)\n" + + " provides p.I1 with p.P1;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing provides tag\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 6)\n" + + " uses java.util.Currency;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing uses tag\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "missing tags", + OUTPUT_DIR, + JavacTestOptions.JavacHasABug.NoWarningForMissingJavadocTag); + } + + public void testBug549855b() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "/**\n" + + " @provides p.I\n" + + " @uses java.util.Currenc\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + " provides p.I1 with p.P1;\n" + + " uses java.util.Currency;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "I1.java", + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " */\n" + + "public interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "P1.java", + "package p;\n" + + "/**\n" + + " * class P1\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -enableJavadoc ") + .append(" -err:allJavadoc ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "I1.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "P1.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 7)\n" + + " provides p.I1 with p.P1;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing provides tag\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 8)\n" + + " uses java.util.Currency;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing uses tag\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "service-type not found"); + } + + public void testBug549855c() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "/**\n" + + " @provides p.I1\n" + + " @uses java.util.Currency\n" + + " @provides p.I1\n" + + " @uses java.util.Currency\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + " provides p.I1 with p.P1;\n" + + " uses java.util.Currency;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "I1.java", + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " */\n" + + "public interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "P1.java", + "package p;\n" + + "/**\n" + + " * class P1\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -enableJavadoc ") + .append(" -err:allJavadoc ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "I1.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "P1.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 4)\n" + + " @provides p.I1\n" + + " ^^^^\n" + + "Javadoc: Duplicate provides tag\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 5)\n" + + " @uses java.util.Currency\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Duplicate uses tag\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "duplicate tags", + OUTPUT_DIR, + JavacTestOptions.JavacHasABug.NoWarningForDuplicateJavadocTag); + } + + public void testBug549855d() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "/**\n" + + " @provides p.I1\n" + + " @uses java.util.Currency\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + " provides p.I1 with p.P1;\n" + + " uses java.util.Currency;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "I1.java", + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " */\n" + + "public interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "P1.java", + "package p;\n" + + "/**\n" + + " * class P1\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -enableJavadoc ") + .append(" -err:allJavadoc ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" "); + + runConformModuleTest(files, buffer, "", "", false); + } + + public void testBug549855e() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "/**\n" + + " @provides p.I1\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + " provides p.I1 with p.P1;\n" + + " uses java.util.Currency;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "I1.java", + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " */\n" + + "public interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "P1.java", + "package p;\n" + + "/**\n" + + " * class P1\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -enableJavadoc ") + .append(" -err:allJavadoc ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "I1.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "P1.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 7)\n" + + " uses java.util.Currency;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing uses tag\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "missing tags", + OUTPUT_DIR, + JavacTestOptions.JavacHasABug.NoWarningForMissingJavadocTag); + } + + public void testBug549855f() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "/**\n" + + " @uses java.util.Currency\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + " provides p.I1 with p.P1;\n" + + " uses java.util.Currency;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "I1.java", + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " */\n" + + "public interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "P1.java", + "package p;\n" + + "/**\n" + + " * class P1\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -enableJavadoc ") + .append(" -err:allJavadoc ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "I1.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "P1.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 6)\n" + + " provides p.I1 with p.P1;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing provides tag\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "missing tags", + OUTPUT_DIR, + JavacTestOptions.JavacHasABug.NoWarningForMissingJavadocTag); + } + + public void testBug549855g() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + " provides p.I1 with p.P1;\n" + + " uses java.util.Currency;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "I1.java", + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " */\n" + + "public interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "P1.java", + "package p;\n" + + "/**\n" + + " * class P1\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -enableJavadoc ") + .append(" -err:allJavadoc ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "I1.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "P1.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 5)\n" + + " provides p.I1 with p.P1;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing provides tag\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 6)\n" + + " uses java.util.Currency;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing uses tag\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "missing tags", + OUTPUT_DIR, + JavacTestOptions.JavacHasABug.NoWarningForMissingJavadocTag); + } + + public void testBug549855h() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "/**\n" + + " * @provides p.I\n" + + " * @uses java.util.Currenc\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + " provides p.I1 with p.P1;\n" + + " uses java.util.Currency;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "I1.java", + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " */\n" + + "public interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "P1.java", + "package p;\n" + + "/**\n" + + " * class P1\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -enableJavadoc ") + .append(" -err:allJavadoc ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "I1.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "P1.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 7)\n" + + " provides p.I1 with p.P1;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing provides tag\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 8)\n" + + " uses java.util.Currency;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing uses tag\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "reference not found"); + } + + public void testBug549855i() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one {\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -enableJavadoc ") + .append(" -err:allJavadoc ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java "); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 1)\n" + + " module mod.one {\n" + + " ^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for module declaration\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "no comment"); + } + + public void testBug562960() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String options = + "-d " + OUTPUT_DIR + File.separator + out + + " -9 " + + " -enableJavadoc " + + " -err:allJavadoc " + + " -classpath \"" + Util.getJavaClassLibsAsString() + "\" " + + directory + File.separator + "Test.java"; + + runNegativeModuleTest( + new String[] { + "src/Test.java", + "/**\n" + + " * {@link sun.security.ssl.X509TrustManagerImpl}\n" + + " */\n" + + "public class Test {}\n" + }, + options, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/Test.java (at line 2)\n" + + " * {@link sun.security.ssl.X509TrustManagerImpl}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The type sun.security.ssl.X509TrustManagerImpl is not accessible\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "reference not found"); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForRecord.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForRecord.java new file mode 100644 index 0000000000..aa346b595c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestForRecord.java @@ -0,0 +1,273 @@ +/******************************************************************************* + * Copyright (c) 2020 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class JavadocTestForRecord extends JavadocTest { + + static { +// TESTS_NAMES = new String[] { "testBug549855a" }; + // TESTS_NUMBERS = new int[] { 1 }; + // TESTS_RANGE = new int[] { 298, -1 }; + } + + public JavadocTestForRecord(String name) { + super(name); + } + + String docCommentSupport = CompilerOptions.ENABLED; + String reportInvalidJavadoc = CompilerOptions.ERROR; + String reportInvalidJavadocTags = CompilerOptions.ENABLED; + String reportInavlidJavadocTagsVisibility = CompilerOptions.PRIVATE; + String reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + String reportMissingJavadocTags = CompilerOptions.ERROR; + String reportMissingJavadocTagsOverriding = CompilerOptions.ENABLED; + String reportMissingJavadocComments = CompilerOptions.ERROR; + String reportMissingJavadocCommentsVisibility = CompilerOptions.PROTECTED; + + @SuppressWarnings("rawtypes") + public static Class testClass() { + return JavadocTestForRecord.class; + } + + // Use this static initializer to specify subset for tests + // All specified tests which does not belong to the class are skipped... + static { +// TESTS_PREFIX = "testBug95521"; +// TESTS_NAMES = new String[] { "testBug331872d" }; +// TESTS_NUMBERS = new int[] { 101283 }; +// TESTS_RANGE = new int[] { 23, -1 }; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_16); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, this.docCommentSupport); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, this.reportInvalidJavadoc); + if (!CompilerOptions.IGNORE.equals(this.reportInvalidJavadoc)) { + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, this.reportInvalidJavadocVisibility); + } + if (this.reportMissingJavadocComments != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + else + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportInvalidJavadoc); + if (this.reportMissingJavadocCommentsVisibility != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsVisibility, + this.reportMissingJavadocCommentsVisibility); + if (this.reportMissingJavadocTags != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportMissingJavadocTags); + if (this.reportMissingJavadocTagsOverriding != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsOverriding, + this.reportMissingJavadocTagsOverriding); + } + } else { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportInvalidJavadoc); + } + if (this.reportMissingJavadocComments != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, this.reportInvalidJavadocTags); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, this.reportInavlidJavadocTagsVisibility); + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_Release, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16); // FIXME + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + return options; + } + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + + @Override + protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) { + runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("16")); + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput) { + runConformTest(testFiles, expectedOutput, getCompilerOptions()); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedOutputString = expectedOutput; + runner.vmArguments = new String[] { "--enable-preview" }; + runner.customOptions = customOptions; + runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("16"); + runner.runConformTest(); + } + + protected void setUp() throws Exception { + super.setUp(); + this.docCommentSupport = CompilerOptions.ENABLED; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocTagsOverriding = CompilerOptions.ENABLED; + this.reportMissingJavadocComments = CompilerOptions.ERROR; + } + + public void test001() { + if(this.complianceLevel < ClassFileConstants.JDK14) { + return; + } + this.runNegativeTest(new String[] { "X.java", "public record X() {\n" + "}\n" }, + "----------\n" + "1. ERROR in X.java (at line 1)\n" + " public record X() {\n" + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test002() { + if(this.complianceLevel < ClassFileConstants.JDK14) { + return; + } + this.runNegativeTest( + new String[] { "X.java", + " /**\n" + " * @param radius radius of X\n" + " */\n" + "public record X(int radius) {\n" + + " public void foo() {\n" + " }\n" + "}\n" }, + "----------\n" + "1. ERROR in X.java (at line 5)\n" + " public void foo() {\n" + " ^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test003() { + if(this.complianceLevel < ClassFileConstants.JDK14) { + return; + } + runConformTest(new String[] { "X.java", + " /** \n" + " * \n" + " */ \n" + "public record X() {\n" + " /** \n" + + " * @param args \n" + " */ \n" + " public static void main(String[] args){\n" + + " System.out.println(0);\n" + " }\n" + "}" }, + "0"); + } + + public void test004() { + if(this.complianceLevel < ClassFileConstants.JDK14) { + return; + } + runConformTest(new String[] { "X.java", + " /** \n" + + " * @param a\n" + + " */ \n" + + " public record X(int a) {\n" + + " /** \n" + + " * @param args \n" + " */ \n" + + " public static void main(String[] args){\n" + + " System.out.println(0);\n" + + " }\n" + + " }" }, + "0"); + } + + public void test005() { + if(this.complianceLevel < ClassFileConstants.JDK14) { + return; + } + runNegativeTest(new String[] { "X.java", + " /** \n" + + " */ \n" + + " public record X(int a) {\n" + + " /** \n" + + " * @param args \n" + + " */ \n" + + " public static void main(String[] args){\n" + + " System.out.println(0);\n" + + " }\n" + + " }" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public record X(int a) {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter a\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test006() { + if(this.complianceLevel < ClassFileConstants.JDK14) { + return; + } + runNegativeTest(new String[] { "X.java", + " /** \n" + + " * @param a\n" + + " * @param a\n" + + " */ \n" + + " public record X(int a) {\n" + + " /** \n" + + " * @param args \n" + + " */ \n" + + " public static void main(String[] args){\n" + + " System.out.println(0);\n" + + " }\n" + + " }" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param a\n" + + " ^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test007() { + if(this.complianceLevel < ClassFileConstants.JDK14) { + return; + } + runNegativeTest(new String[] { "X.java", + " /** \n" + + " * @param a\n" + + " * @param b\n" + + " */ \n" + + " public record X(int a) {\n" + + " /** \n" + + " * @param args \n" + + " */ \n" + + " public static void main(String[] args){\n" + + " System.out.println(0);\n" + + " }\n" + + " }" }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param b\n" + + " ^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestMixed.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestMixed.java new file mode 100644 index 0000000000..07438b58b0 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestMixed.java @@ -0,0 +1,877 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTestMixed extends JavadocTest { + + String docCommentSupport = CompilerOptions.ENABLED; + String reportInvalidJavadoc = CompilerOptions.ERROR; + String reportMissingJavadocTags = CompilerOptions.ERROR; + String reportMissingJavadocComments = null; + + public JavadocTestMixed(String name) { + super(name); + } + + public static Class javadocTestClass() { + return JavadocTestMixed.class; + } + + // Use this static initializer to specify subset for tests + // All specified tests which does not belong to the class are skipped... + static { +// TESTS_PREFIX = "testBug77602"; +// TESTS_NAMES = new String[] { "testBug80910" }; +// TESTS_NUMBERS = new int[] { 31, 32, 33 }; +// TESTS_RANGE = new int[] { 21, 50 }; + } + public static Test suite() { + return buildAllCompliancesTestSuite(javadocTestClass()); + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, this.docCommentSupport); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, this.reportInvalidJavadoc); + if (this.reportMissingJavadocComments != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + else + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportInvalidJavadoc); + if (this.reportMissingJavadocTags != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportMissingJavadocTags); + else + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportInvalidJavadoc); + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return options; + } + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.docCommentSupport = CompilerOptions.ENABLED; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocComments = null; + } + + /* + * Test missing javadoc + */ + public void test001() { + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "/** */\n" + + "public class X {\n" + + " /** */\n" + + " public int x;\n" + + " /** */\n" + + " public X() {}\n" + + " /** */\n" + + " public void foo() {}\n" + + "}\n" }); + } + + public void test002() { + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "/** */\n" + + "class X {\n" + + " /** */\n" + + " int x;\n" + + " /** */\n" + + " X() {}\n" + + " /** */\n" + + " void foo() {}\n" + + "}\n" }); + } + + public void test003() { + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "/** */\n" + + "class X {\n" + + " /** */\n" + + " protected int x;\n" + + " /** */\n" + + " protected X() {}\n" + + " /** */\n" + + " protected void foo() {}\n" + + "}\n" }); + } + + public void test004() { + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "/** */\n" + + "class X {\n" + + " /** */\n" + + " private int x;\n" + + " /** */\n" + + " private X() {}\n" + + " /** */\n" + + " private void foo() {}\n" + + "}\n" }); + } + + public void test005() { + this.reportInvalidJavadoc = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " public int x;\n" + + "\n" + + " public X() {}\n" + + "\n" + + " public void foo() {}\n" + + "}\n" }); + } + + public void test006() { + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String s1 = \"non-terminated;\n" + + " void foo() {}\n" + + " String s2 = \"terminated\";\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " String s1 = \"non-terminated;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "String literal is not properly closed by a double-quote\n" + + "----------\n" + ); + } + + public void test010() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " /** Field javadoc comment */\n" + + " public int x;\n" + + "\n" + + " /** Constructor javadoc comment */\n" + + " public X() {\n" + + " }\n" + + " /** Method javadoc comment */\n" + + " public void foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 2)\n" + + " public class X {\n" + + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test011() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/** Class javadoc comment */\n" + + "public class X {\n" + + " public int x;\n" + + "\n" + + " /** Constructor javadoc comment */\n" + + " public X() {\n" + + " }\n" + + " /** Method javadoc comment */\n" + + " public void foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 4)\n" + + " public int x;\n" + + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test012() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/** Class javadoc comment */\n" + + "public class X {\n" + + " /** Field javadoc comment */\n" + + " public int x;\n" + + "\n" + + " public X() {\n" + + " }\n" + + " /** Method javadoc comment */\n" + + " public void foo() {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " public X() {\n" + + " ^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test013() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/** Class javadoc comment */\n" + + "public class X {\n" + + " /** Field javadoc comment */\n" + + " public int x;\n" + + "\n" + + " /** Constructor javadoc comment */\n" + + " public X() {\n" + + " }\n" + + " public void foo(int a) {\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 10)\n" + + " public void foo(int a) {\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + /* + * Test mixing javadoc comments + */ + public void test021() { + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "/**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " * @see \"Test class X\"\n" + + " */\n" + + "public class X {\n" + + "/**\n" + + " * Valid field javadoc\n" + + " * @see Valid URL\n" + + " */\n" + + " public int x;\n" + + "\n" + + "/**\n" + + " * Valid constructor javadoc\n" + + " * @param str Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public X(String str) {\n" + + " }\n" + + "/**\n" + + " * Valid method javadoc\n" + + " * @param list Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @return Valid return tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(java.util.Vector list) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }); + } + + public void test022() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/**\n" + + " * Unexpected tag in class javadoc\n" + + " * @author ffr\n" + + " * @see \"Test class X\"\n" + + " * @param x\n" + + " */\n" + + "public class X {\n" + + "/**\n" + + " * Valid field javadoc\n" + + " * @see Valid URL\n" + + " */\n" + + " public int x;\n" + + "\n" + + "/**\n" + + " * Valid constructor javadoc\n" + + " * @param str Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public X(String str) {\n" + + " }\n" + + "/**\n" + + " * Valid method javadoc\n" + + " * @param list Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @return Valid return tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(java.util.Vector list) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @param x\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test023() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " * @see \"Test class X\"\n" + + " */\n" + + "public class X {\n" + + "/**\n" + + " * Unexpected tag in field javadoc\n" + + " * @throws InvalidException\n" + + " * @see Valid URL\n" + + " */\n" + + " public int x;\n" + + "\n" + + "/**\n" + + " * Valid constructor javadoc\n" + + " * @param str Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public X(String str) {\n" + + " }\n" + + "/**\n" + + " * Valid method javadoc\n" + + " * @param list Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @return Valid return tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(java.util.Vector list) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 10)\n" + + " * @throws InvalidException\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test024() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " * @see \"Test class X\"\n" + + " */\n" + + "public class X {\n" + + "/**\n" + + " * Valid field javadoc\n" + + " * @see Valid URL\n" + + " */\n" + + " public int x;\n" + + "\n" + + "/**\n" + + " * Wrong tags order in constructor javadoc\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @param str Valid param tag\n" + + " * @deprecated\n" + + " */\n" + + " public X(String str) {\n" + + " }\n" + + "/**\n" + + " * Valid method javadoc\n" + + " * @param list Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @return Valid return tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(java.util.Vector list) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 19)\n" + + " * @param str Valid param tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 22)\n" + + " public X(String str) {\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter str\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test025() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " * @see \"Test class X\"\n" + + " */\n" + + "public class X {\n" + + "/**\n" + + " * Valid field javadoc\n" + + " * @see Valid URL\n" + + " */\n" + + " public int x;\n" + + "\n" + + "/**\n" + + " * Valid constructor javadoc\n" + + " * @param str Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public X(String str) {\n" + + " }\n" + + "/**\n" + + " * Wrong param tag in method javadoc\n" + + " * @param vector Invalid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @return Valid return tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(java.util.Vector list) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 26)\n" + + " * @param vector Invalid param tag\n" + + " ^^^^^^\n" + + "Javadoc: Parameter vector is not declared\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 33)\n" + + " public String foo(java.util.Vector list) {\n" + + " ^^^^\n" + + "Javadoc: Missing tag for parameter list\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + public void test026() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/**\n" + + " * Invalid see tag in class javadoc\n" + + " * @author ffr\n" + + " * @see \"Test class X\n" + + " */\n" + + "public class X {\n" + + "/**\n" + + " * Invalid field javadoc\n" + + " * @see Valid URLunexpected text\n" + + " */\n" + + " public int x;\n" + + "\n" + + "/**\n" + + " * Missing throws tag in constructor javadoc\n" + + " * @param str Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public X(String str) throws java.io.IOException {\n" + + " }\n" + + "/**\n" + + " * Missing return tag in method javadoc\n" + + " * @param list Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(java.util.Vector list) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 5)\n" + + " * @see \"Test class X\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 10)\n" + + " * @see Valid URLunexpected text\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 22)\n" + + " public X(String str) throws java.io.IOException {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing tag for declared exception IOException\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 32)\n" + + " public String foo(java.util.Vector list) {\n" + + " ^^^^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + /* + * Javadoc on invalid syntax + */ + public void test030() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/**\n" + + " * Valid class javadoc on invalid declaration\n" + + " * @author ffr\n" + + " * @see \"Test class X\"\n" + + " */\n" + + "protected class X {\n" + + "/**\n" + + " * Valid field javadoc\n" + + " * @see Valid URL\n" + + " */\n" + + " public int x;\n" + + "\n" + + "/**\n" + + " * Valid constructor javadoc\n" + + " * @param str Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public X(String str) {\n" + + " }\n" + + "/**\n" + + " * Valid method javadoc\n" + + " * @param list Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @return Valid return tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(java.util.Vector list) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 7)\n" + + " protected class X {\n" + + " ^\n" + + "Illegal modifier for the class X; only public, abstract & final are permitted\n" + + "----------\n"); + } + + public void test031() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " * @see \"Test class X\"\n" + + " */\n" + + "public class X {\n" + + "/**\n" + + " * Valid field javadoc on invalid declaration\n" + + " * @see Valid URL\n" + + " */\n" + + " public int x\n" + + "\n" + + "/**\n" + + " * Valid constructor javadoc\n" + + " * @param str Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public X(String str) {\n" + + " }\n" + + "/**\n" + + " * Valid method javadoc\n" + + " * @param list Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @return Valid return tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(java.util.Vector list) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 12)\n" + + " public int x\n" + + " ^\n" + + "Syntax error, insert \";\" to complete ClassBodyDeclarations\n" + + "----------\n"); + } + + public void test032() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " * @see \"Test class X\"\n" + + " */\n" + + "public class X {\n" + + "/**\n" + + " * Valid field javadoc\n" + + " * @see Valid URL\n" + + " */\n" + + " public int x;\n" + + "\n" + + "/**\n" + + " * Valid constructor javadoc on invalid declaration\n" + + " * @param str Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public X(String str) \n" + + " }\n" + + "/**\n" + + " * Valid method javadoc\n" + + " * @param list Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @return Valid return tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(java.util.Vector list) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. ERROR in test\\X.java (at line 22)\n" + + " public X(String str) \n" + + " ^\n" + + "Syntax error on token \")\", { expected after this token\n" + + "----------\n"); + } + + public void _test033() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "/**\n" + + " * Valid class javadoc\n" + + " * @author ffr\n" + + " * @see \"Test class X\"\n" + + " */\n" + + "public class X {\n" + + "/**\n" + + " * Valid field javadoc\n" + + " * @see Valid URL\n" + + " */\n" + + " public int x;\n" + + "\n" + + "/**\n" + + " * Valid constructor javadoc\n" + + " * @param str Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public X(String str) {\n" + + " }\n" + + "/**\n" + + " * Valid method javadoc on invalid declaration\n" + + " * @param list Valid param tag\n" + + " * @throws NullPointerException Valid throws tag\n" + + " * @exception IllegalArgumentException Valid throws tag\n" + + " * @return Valid return tag\n" + + " * @see X Valid see tag\n" + + " * @deprecated\n" + + " */\n" + + " public String foo(java.util.Vector ) {\n" + + " return \"\";\n" + + " }\n" + + "}\n" }, + this.complianceLevel < ClassFileConstants.JDK1_5 + ? "----------\n" + + "1. ERROR in test\\X.java (at line 23)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 26)\n" + + " * @param list Valid param tag\n" + + " ^^^^\n" + + "Javadoc: Parameter list is not declared\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 33)\n" + + " public String foo(java.util.Vector ) {\n" + + " ^^^^^^\n" + + "Syntax error on token \"Vector\", VariableDeclaratorId expected after this token\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 36)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n" + : "----------\n" + + "1. ERROR in test\\X.java (at line 23)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 26)\n" + + " * @param list Valid param tag\n" + + " ^^^^\n" + + "Javadoc: Parameter list is not declared\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 33)\n" + + " public String foo(java.util.Vector ) {\n" + + " ^\n" + + "Syntax error on token \".\", ... expected\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 36)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n"); + } + + public void test040() { + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " /**\n" + + " /**\n" + + " /** \n" + + " * @param str\n" + + " * @param x\n" + + " */\n" + + " public void bar(String str, int x) {\n" + + " }\n" + + " public void foo() {\n" + + " bar(\"toto\", 0 /* block comment inline */);\n" + + " }\n" + + "}\n" }); + } + + public void test041() { + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /**\n" + + " * @see String\n" + + " * @see #\n" + + " * @return String\n" + + " */\n" + + " String bar() {return \"\";}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see #\n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestOptions.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestOptions.java new file mode 100644 index 0000000000..806e6e705a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTestOptions.java @@ -0,0 +1,2223 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 425721 - [1.8][compiler] Nondeterministic results in GenericsRegressionTest_1_8.testBug424195a + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; +import java.util.StringTokenizer; + +import junit.framework.Test; + +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +/** + * Tests to verify that Compiler options work well for Javadoc. + * This class does not tests syntax error option as it's considered already + * tested by other JavadocTest* classes. + * + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=46854" + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=46976" + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTestOptions extends JavadocTest { + + /** + * When failures occur in this file due to changes in error messages, + * then uncomment following static initializer. + * This will output in the console the changes which must be done + * on {@link #CLASSES_ERRORS} and/or {@link #METHODS_ERRORS} + * arrays to make the failing tests pass. + */ +// static { +// TESTS_NAMES = new String[] { +// "testInvalidTagsClassErrorTagsPrivate", +// "testInvalidTagsFieldErrorTagsPrivate", +// "testInvalidTagsMethodErrorTagsPrivate", +// "testInvalidTagsConstructorErrorTagsPrivate", +// }; +// } + + String docCommentSupport = null; + String reportInvalidJavadoc = null; + String reportInvalidJavadocTagsVisibility = null; + String reportInvalidJavadocTags = null; + String reportInvalidJavadocTagsDeprecatedRef= null; + String reportInvalidJavadocTagsNotVisibleRef = null; + String reportMissingJavadocTags = null; + String reportMissingJavadocTagsVisibility = null; + String reportMissingJavadocTagsOverriding = null; + String reportMissingJavadocComments = null; + String reportMissingJavadocCommentsVisibility = null; + String reportMissingJavadocCommentsOverriding = null; + + private final int PUBLIC_VISIBILITY = 0; + private final int PROTECTED_VISIBILITY = 1; + private final int DEFAULT_VISIBILITY = 2; + private final int PRIVATE_VISIBILITY = 3; + + private static final String INVALID_CLASS_JAVADOC_REF = " /**\n" + + " * @see X_dep\n" + + " * @see X.X_priv\n" + + " * @see X.Unknown\n" + + " * @see X#X(int)\n" + + " * @see X#X(String)\n" + + " * @see X#X()\n" + + " * @see X#x_dep\n" + + " * @see X#x_priv\n" + + " * @see X#unknown\n" + + " * @see X#foo_dep()\n" + + " * @see X#foo_priv()\n" + + " * @see X#foo_dep(String)\n" + + " * @see X#unknown()\n" + + " */\n"; + private static final String INVALID_METHOD_JAVADOC_REF = " /**\n" + + " * @param str\n" + + " * @param str\n" + + " * @param xxx\n" + + " * @throws IllegalArgumentException\n" + + " * @throws IllegalArgumentException\n" + + " * @throws java.io.IOException\n" + + " * @throws Unknown\n" + + " * @see X_dep\n" + + " * @see X.X_priv\n" + + " * @see X.Unknown\n" + + " * @see X#X(int)\n" + + " * @see X#X(String)\n" + + " * @see X#X()\n" + + " * @see X#x_dep\n" + + " * @see X#x_priv\n" + + " * @see X#unknown\n" + + " * @see X#foo_dep()\n" + + " * @see X#foo_priv()\n" + + " * @see X#foo_dep(String)\n" + + " * @see X#unknown()\n" + + " */\n"; + private static final String DEP_CLASS = + "/** @deprecated */\n" + + "public class X_dep {}\n"; + private static final String REF_CLASS = + "public class X {\n" + +// Deprecated class must be a top level to avoid visibility issue +// " /** @deprecated */\n" + +// " class X_dep{}\n" + + " private class X_priv{}\n" + + " /** @deprecated */\n" + + " public int x_dep;\n" + + " private int x_priv;\n" + + " /** @deprecated */\n" + + " public X() {}\n" + + " private X(int x) {}\n" + + " /** @deprecated */\n" + + " public void foo_dep() {}\n" + + " private void foo_priv() {}\n" + + " }\n"; + private static final String[] CLASSES_INVALID_COMMENT = { + "X.java", + REF_CLASS, + "X_dep.java", + DEP_CLASS, + "Y.java", + "public class Y {\n" + + INVALID_CLASS_JAVADOC_REF + + " public class X_pub {}\n" + + INVALID_CLASS_JAVADOC_REF + + " protected class X_prot {}\n" + + INVALID_CLASS_JAVADOC_REF + + " class X_pack {}\n" + + INVALID_CLASS_JAVADOC_REF + + " private class X_priv {}\n" + + "}\n" + + "\n" + }; + private static final String[] FIELDS_INVALID_COMMENT = { + "X.java", + REF_CLASS, + "X_dep.java", + DEP_CLASS, + "Y.java", + "public class Y {\n" + + INVALID_CLASS_JAVADOC_REF + + " public int x_pub;\n" + + INVALID_CLASS_JAVADOC_REF + + " protected int x_prot;\n" + + INVALID_CLASS_JAVADOC_REF + + " int x_pack;\n" + + INVALID_CLASS_JAVADOC_REF+ + " private int x_priv;\n" + + "}\n" + + "\n" + }; + private static final String[] METHODS_INVALID_COMMENT = { + "X.java", + REF_CLASS, + "X_dep.java", + DEP_CLASS, + "Y.java", + "public class Y {\n" + + INVALID_METHOD_JAVADOC_REF + + " public void foo_pub(String str) throws IllegalArgumentException {}\n" + + INVALID_METHOD_JAVADOC_REF + + " protected void foo_pro(String str) throws IllegalArgumentException {}\n" + + INVALID_METHOD_JAVADOC_REF + + " void foo_pack(String str) throws IllegalArgumentException {}\n" + + INVALID_METHOD_JAVADOC_REF + + " private void foo_priv(String str) throws IllegalArgumentException {}\n" + + "}\n" + + "\n" + }; + private static final String[] CONSTRUCTORS_INVALID_COMMENT = { + "X.java", + REF_CLASS, + "X_dep.java", + DEP_CLASS, + "Y.java", + "public class Y {\n" + + INVALID_METHOD_JAVADOC_REF + + " public Y(int str) {}\n" + + INVALID_METHOD_JAVADOC_REF + + " protected Y(long str) {}\n" + + INVALID_METHOD_JAVADOC_REF + + " Y(float str) {}\n" + + INVALID_METHOD_JAVADOC_REF + + " private Y(double str) {}\n" + + "}\n" + + "\n" + }; + private static final String[] MISSING_TAGS = { + "X.java", + "public class X {\n" + + " // public\n" + + " /** */\n" + + " public class PublicClass {}\n" + + " /** */\n" + + " public int publicField;\n" + + " /** */\n" + + " public X(int i) {}\n" + + " /** */\n" + + " public int publicMethod(long l) { return 0;}\n" + + " // protected\n" + + " /** */\n" + + " protected class ProtectedClass {}\n" + + " /** */\n" + + " protected int protectedField;\n" + + " /** */\n" + + " protected X(long l) {}\n" + + " /** */\n" + + " protected int protectedMethod(long l) { return 0; }\n" + + " // default\n" + + " /** */\n" + + " class PackageClass {}\n" + + " /** */\n" + + " int packageField;\n" + + " /** */\n" + + " X(float f) {}\n" + + " /** */\n" + + " int packageMethod(long l) { return 0;}\n" + + " // private\n" + + " /** */\n" + + " private class PrivateClass {}\n" + + " /** */\n" + + " private int privateField;\n" + + " /** */\n" + + " private X(double d) {}\n" + + " /** */\n" + + " private int privateMethod(long l) { return 0;}\n" + + "}\n" + + "\n", + "Y.java", + "/** */\n" + + "public class Y extends X {\n" + + " public Y(int i) { super(i); }\n" + + " //methods\n" + + " /** */\n" + + " public int publicMethod(long l) { return 0;}\n" + + " /** */\n" + + " protected int protectedMethod(long l) { return 0;}\n" + + " /** */\n" + + " int packageMethod(long l) { return 0;}\n" + + " /** */\n" + + " private int privateMethod(long l) { return 0;}\n" + + "}\n" + }; + private static final String[] MISSING_COMMENTS = { + "X.java", + "/** */\n" + + "public class X {\n" + + " // public\n" + + " public class PublicClass {}\n" + + " public int publicField;\n" + + " public X(int i) {}\n" + + " public int publicMethod(long l) { return 0;}\n" + + " // protected\n" + + " protected class ProtectedClass {}\n" + + " protected int protectedField;\n" + + " protected X(long l) {}\n" + + " protected int protectedMethod(long l) { return 0; }\n" + + " // default\n" + + " class PackageClass {}\n" + + " int packageField;\n" + + " X(float f) {}\n" + + " int packageMethod(long l) { return 0;}\n" + + " // private\n" + + " private class PrivateClass {}\n" + + " private int privateField;\n" + + " private X(double d) {}\n" + + " private int privateMethod(long l) { return 0;}\n" + + "}\n" + + "\n", + "Y.java", + "/** */\n" + + "public class Y extends X {\n" + + " /** */\n" + + " public Y(int i) { super(i); }\n" + + " public int publicMethod(long l) { return 0;}\n" + + " protected int protectedMethod(long l) { return 0;}\n" + + " int packageMethod(long l) { return 0;}\n" + + " private int privateMethod(long l) { return 0;}\n" + + "}\n" + }; + + private static final String[] CLASSES_ERRORS = { + "1. ERROR in Y.java (at line 3)\n" + + " * @see X_dep\n" + + " ^^^^^\n" + + "Javadoc: The type X_dep is deprecated\n" + + "----------\n" + + "2. ERROR in Y.java (at line 4)\n" + + " * @see X.X_priv\n" + + " ^^^^^^^^\n" + + "Javadoc: The type X.X_priv is not visible\n" + + "----------\n" + + "3. ERROR in Y.java (at line 5)\n" + + " * @see X.Unknown\n" + + " ^^^^^^^^^\n" + + "Javadoc: X.Unknown cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in Y.java (at line 6)\n" + + " * @see X#X(int)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor X(int) is not visible\n" + + "----------\n" + + "5. ERROR in Y.java (at line 7)\n" + + " * @see X#X(String)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor X(String) is undefined\n" + + "----------\n" + + "6. ERROR in Y.java (at line 8)\n" + + " * @see X#X()\n" + + " ^^^\n" + + "Javadoc: The constructor X() is deprecated\n" + + "----------\n" + + "7. ERROR in Y.java (at line 9)\n" + + " * @see X#x_dep\n" + + " ^^^^^\n" + + "Javadoc: The field X.x_dep is deprecated\n" + + "----------\n" + + "8. ERROR in Y.java (at line 10)\n" + + " * @see X#x_priv\n" + + " ^^^^^^\n" + + "Javadoc: The field x_priv is not visible\n" + + "----------\n" + + "9. ERROR in Y.java (at line 11)\n" + + " * @see X#unknown\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "10. ERROR in Y.java (at line 12)\n" + + " * @see X#foo_dep()\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method foo_dep() from the type X is deprecated\n" + + "----------\n" + + "11. ERROR in Y.java (at line 13)\n" + + " * @see X#foo_priv()\n" + + " ^^^^^^^^\n" + + "Javadoc: The method foo_priv() from the type X is not visible\n" + + "----------\n" + + "12. ERROR in Y.java (at line 14)\n" + + " * @see X#foo_dep(String)\n" + + " ^^^^^^^\n" + + "Javadoc: The method foo_dep() in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "13. ERROR in Y.java (at line 15)\n" + + " * @see X#unknown()\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n", + "14. ERROR in Y.java (at line 19)\n" + + " * @see X_dep\n" + + " ^^^^^\n" + + "Javadoc: The type X_dep is deprecated\n" + + "----------\n" + + "15. ERROR in Y.java (at line 20)\n" + + " * @see X.X_priv\n" + + " ^^^^^^^^\n" + + "Javadoc: The type X.X_priv is not visible\n" + + "----------\n" + + "16. ERROR in Y.java (at line 21)\n" + + " * @see X.Unknown\n" + + " ^^^^^^^^^\n" + + "Javadoc: X.Unknown cannot be resolved to a type\n" + + "----------\n" + + "17. ERROR in Y.java (at line 22)\n" + + " * @see X#X(int)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor X(int) is not visible\n" + + "----------\n" + + "18. ERROR in Y.java (at line 23)\n" + + " * @see X#X(String)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor X(String) is undefined\n" + + "----------\n" + + "19. ERROR in Y.java (at line 24)\n" + + " * @see X#X()\n" + + " ^^^\n" + + "Javadoc: The constructor X() is deprecated\n" + + "----------\n" + + "20. ERROR in Y.java (at line 25)\n" + + " * @see X#x_dep\n" + + " ^^^^^\n" + + "Javadoc: The field X.x_dep is deprecated\n" + + "----------\n" + + "21. ERROR in Y.java (at line 26)\n" + + " * @see X#x_priv\n" + + " ^^^^^^\n" + + "Javadoc: The field x_priv is not visible\n" + + "----------\n" + + "22. ERROR in Y.java (at line 27)\n" + + " * @see X#unknown\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "23. ERROR in Y.java (at line 28)\n" + + " * @see X#foo_dep()\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method foo_dep() from the type X is deprecated\n" + + "----------\n" + + "24. ERROR in Y.java (at line 29)\n" + + " * @see X#foo_priv()\n" + + " ^^^^^^^^\n" + + "Javadoc: The method foo_priv() from the type X is not visible\n" + + "----------\n" + + "25. ERROR in Y.java (at line 30)\n" + + " * @see X#foo_dep(String)\n" + + " ^^^^^^^\n" + + "Javadoc: The method foo_dep() in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "26. ERROR in Y.java (at line 31)\n" + + " * @see X#unknown()\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n", + "27. ERROR in Y.java (at line 35)\n" + + " * @see X_dep\n" + + " ^^^^^\n" + + "Javadoc: The type X_dep is deprecated\n" + + "----------\n" + + "28. ERROR in Y.java (at line 36)\n" + + " * @see X.X_priv\n" + + " ^^^^^^^^\n" + + "Javadoc: The type X.X_priv is not visible\n" + + "----------\n" + + "29. ERROR in Y.java (at line 37)\n" + + " * @see X.Unknown\n" + + " ^^^^^^^^^\n" + + "Javadoc: X.Unknown cannot be resolved to a type\n" + + "----------\n" + + "30. ERROR in Y.java (at line 38)\n" + + " * @see X#X(int)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor X(int) is not visible\n" + + "----------\n" + + "31. ERROR in Y.java (at line 39)\n" + + " * @see X#X(String)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor X(String) is undefined\n" + + "----------\n" + + "32. ERROR in Y.java (at line 40)\n" + + " * @see X#X()\n" + + " ^^^\n" + + "Javadoc: The constructor X() is deprecated\n" + + "----------\n" + + "33. ERROR in Y.java (at line 41)\n" + + " * @see X#x_dep\n" + + " ^^^^^\n" + + "Javadoc: The field X.x_dep is deprecated\n" + + "----------\n" + + "34. ERROR in Y.java (at line 42)\n" + + " * @see X#x_priv\n" + + " ^^^^^^\n" + + "Javadoc: The field x_priv is not visible\n" + + "----------\n" + + "35. ERROR in Y.java (at line 43)\n" + + " * @see X#unknown\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "36. ERROR in Y.java (at line 44)\n" + + " * @see X#foo_dep()\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method foo_dep() from the type X is deprecated\n" + + "----------\n" + + "37. ERROR in Y.java (at line 45)\n" + + " * @see X#foo_priv()\n" + + " ^^^^^^^^\n" + + "Javadoc: The method foo_priv() from the type X is not visible\n" + + "----------\n" + + "38. ERROR in Y.java (at line 46)\n" + + " * @see X#foo_dep(String)\n" + + " ^^^^^^^\n" + + "Javadoc: The method foo_dep() in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "39. ERROR in Y.java (at line 47)\n" + + " * @see X#unknown()\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n", + "40. ERROR in Y.java (at line 51)\n" + + " * @see X_dep\n" + + " ^^^^^\n" + + "Javadoc: The type X_dep is deprecated\n" + + "----------\n" + + "41. ERROR in Y.java (at line 52)\n" + + " * @see X.X_priv\n" + + " ^^^^^^^^\n" + + "Javadoc: The type X.X_priv is not visible\n" + + "----------\n" + + "42. ERROR in Y.java (at line 53)\n" + + " * @see X.Unknown\n" + + " ^^^^^^^^^\n" + + "Javadoc: X.Unknown cannot be resolved to a type\n" + + "----------\n" + + "43. ERROR in Y.java (at line 54)\n" + + " * @see X#X(int)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor X(int) is not visible\n" + + "----------\n" + + "44. ERROR in Y.java (at line 55)\n" + + " * @see X#X(String)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor X(String) is undefined\n" + + "----------\n" + + "45. ERROR in Y.java (at line 56)\n" + + " * @see X#X()\n" + + " ^^^\n" + + "Javadoc: The constructor X() is deprecated\n" + + "----------\n" + + "46. ERROR in Y.java (at line 57)\n" + + " * @see X#x_dep\n" + + " ^^^^^\n" + + "Javadoc: The field X.x_dep is deprecated\n" + + "----------\n" + + "47. ERROR in Y.java (at line 58)\n" + + " * @see X#x_priv\n" + + " ^^^^^^\n" + + "Javadoc: The field x_priv is not visible\n" + + "----------\n" + + "48. ERROR in Y.java (at line 59)\n" + + " * @see X#unknown\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "49. ERROR in Y.java (at line 60)\n" + + " * @see X#foo_dep()\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method foo_dep() from the type X is deprecated\n" + + "----------\n" + + "50. ERROR in Y.java (at line 61)\n" + + " * @see X#foo_priv()\n" + + " ^^^^^^^^\n" + + "Javadoc: The method foo_priv() from the type X is not visible\n" + + "----------\n" + + "51. ERROR in Y.java (at line 62)\n" + + " * @see X#foo_dep(String)\n" + + " ^^^^^^^\n" + + "Javadoc: The method foo_dep() in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "52. ERROR in Y.java (at line 63)\n" + + " * @see X#unknown()\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n" + }; + + private static final String[] METHODS_ERRORS = { + "1. ERROR in Y.java (at line 4)\n" + + " * @param str\n" + + " ^^^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "2. ERROR in Y.java (at line 5)\n" + + " * @param xxx\n" + + " ^^^\n" + + "Javadoc: Parameter xxx is not declared\n" + + "----------\n" + + "3. ERROR in Y.java (at line 8)\n" + + " * @throws java.io.IOException\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception IOException is not declared\n" + + "----------\n" + + "4. ERROR in Y.java (at line 9)\n" + + " * @throws Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in Y.java (at line 10)\n" + + " * @see X_dep\n" + + " ^^^^^\n" + + "Javadoc: The type X_dep is deprecated\n" + + "----------\n" + + "6. ERROR in Y.java (at line 11)\n" + + " * @see X.X_priv\n" + + " ^^^^^^^^\n" + + "Javadoc: The type X.X_priv is not visible\n" + + "----------\n" + + "7. ERROR in Y.java (at line 12)\n" + + " * @see X.Unknown\n" + + " ^^^^^^^^^\n" + + "Javadoc: X.Unknown cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in Y.java (at line 13)\n" + + " * @see X#X(int)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor X(int) is not visible\n" + + "----------\n" + + "9. ERROR in Y.java (at line 14)\n" + + " * @see X#X(String)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor X(String) is undefined\n" + + "----------\n" + + "10. ERROR in Y.java (at line 15)\n" + + " * @see X#X()\n" + + " ^^^\n" + + "Javadoc: The constructor X() is deprecated\n" + + "----------\n" + + "11. ERROR in Y.java (at line 16)\n" + + " * @see X#x_dep\n" + + " ^^^^^\n" + + "Javadoc: The field X.x_dep is deprecated\n" + + "----------\n" + + "12. ERROR in Y.java (at line 17)\n" + + " * @see X#x_priv\n" + + " ^^^^^^\n" + + "Javadoc: The field x_priv is not visible\n" + + "----------\n" + + "13. ERROR in Y.java (at line 18)\n" + + " * @see X#unknown\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "14. ERROR in Y.java (at line 19)\n" + + " * @see X#foo_dep()\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method foo_dep() from the type X is deprecated\n" + + "----------\n" + + "15. ERROR in Y.java (at line 20)\n" + + " * @see X#foo_priv()\n" + + " ^^^^^^^^\n" + + "Javadoc: The method foo_priv() from the type X is not visible\n" + + "----------\n" + + "16. ERROR in Y.java (at line 21)\n" + + " * @see X#foo_dep(String)\n" + + " ^^^^^^^\n" + + "Javadoc: The method foo_dep() in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "17. ERROR in Y.java (at line 22)\n" + + " * @see X#unknown()\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n", + "18. ERROR in Y.java (at line 27)\n" + + " * @param str\n" + + " ^^^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "19. ERROR in Y.java (at line 28)\n" + + " * @param xxx\n" + + " ^^^\n" + + "Javadoc: Parameter xxx is not declared\n" + + "----------\n" + + "20. ERROR in Y.java (at line 31)\n" + + " * @throws java.io.IOException\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception IOException is not declared\n" + + "----------\n" + + "21. ERROR in Y.java (at line 32)\n" + + " * @throws Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "22. ERROR in Y.java (at line 33)\n" + + " * @see X_dep\n" + + " ^^^^^\n" + + "Javadoc: The type X_dep is deprecated\n" + + "----------\n" + + "23. ERROR in Y.java (at line 34)\n" + + " * @see X.X_priv\n" + + " ^^^^^^^^\n" + + "Javadoc: The type X.X_priv is not visible\n" + + "----------\n" + + "24. ERROR in Y.java (at line 35)\n" + + " * @see X.Unknown\n" + + " ^^^^^^^^^\n" + + "Javadoc: X.Unknown cannot be resolved to a type\n" + + "----------\n" + + "25. ERROR in Y.java (at line 36)\n" + + " * @see X#X(int)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor X(int) is not visible\n" + + "----------\n" + + "26. ERROR in Y.java (at line 37)\n" + + " * @see X#X(String)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor X(String) is undefined\n" + + "----------\n" + + "27. ERROR in Y.java (at line 38)\n" + + " * @see X#X()\n" + + " ^^^\n" + + "Javadoc: The constructor X() is deprecated\n" + + "----------\n" + + "28. ERROR in Y.java (at line 39)\n" + + " * @see X#x_dep\n" + + " ^^^^^\n" + + "Javadoc: The field X.x_dep is deprecated\n" + + "----------\n" + + "29. ERROR in Y.java (at line 40)\n" + + " * @see X#x_priv\n" + + " ^^^^^^\n" + + "Javadoc: The field x_priv is not visible\n" + + "----------\n" + + "30. ERROR in Y.java (at line 41)\n" + + " * @see X#unknown\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "31. ERROR in Y.java (at line 42)\n" + + " * @see X#foo_dep()\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method foo_dep() from the type X is deprecated\n" + + "----------\n" + + "32. ERROR in Y.java (at line 43)\n" + + " * @see X#foo_priv()\n" + + " ^^^^^^^^\n" + + "Javadoc: The method foo_priv() from the type X is not visible\n" + + "----------\n" + + "33. ERROR in Y.java (at line 44)\n" + + " * @see X#foo_dep(String)\n" + + " ^^^^^^^\n" + + "Javadoc: The method foo_dep() in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "34. ERROR in Y.java (at line 45)\n" + + " * @see X#unknown()\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n", + "35. ERROR in Y.java (at line 50)\n" + + " * @param str\n" + + " ^^^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "36. ERROR in Y.java (at line 51)\n" + + " * @param xxx\n" + + " ^^^\n" + + "Javadoc: Parameter xxx is not declared\n" + + "----------\n" + + "37. ERROR in Y.java (at line 54)\n" + + " * @throws java.io.IOException\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception IOException is not declared\n" + + "----------\n" + + "38. ERROR in Y.java (at line 55)\n" + + " * @throws Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "39. ERROR in Y.java (at line 56)\n" + + " * @see X_dep\n" + + " ^^^^^\n" + + "Javadoc: The type X_dep is deprecated\n" + + "----------\n" + + "40. ERROR in Y.java (at line 57)\n" + + " * @see X.X_priv\n" + + " ^^^^^^^^\n" + + "Javadoc: The type X.X_priv is not visible\n" + + "----------\n" + + "41. ERROR in Y.java (at line 58)\n" + + " * @see X.Unknown\n" + + " ^^^^^^^^^\n" + + "Javadoc: X.Unknown cannot be resolved to a type\n" + + "----------\n" + + "42. ERROR in Y.java (at line 59)\n" + + " * @see X#X(int)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor X(int) is not visible\n" + + "----------\n" + + "43. ERROR in Y.java (at line 60)\n" + + " * @see X#X(String)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor X(String) is undefined\n" + + "----------\n" + + "44. ERROR in Y.java (at line 61)\n" + + " * @see X#X()\n" + + " ^^^\n" + + "Javadoc: The constructor X() is deprecated\n" + + "----------\n" + + "45. ERROR in Y.java (at line 62)\n" + + " * @see X#x_dep\n" + + " ^^^^^\n" + + "Javadoc: The field X.x_dep is deprecated\n" + + "----------\n" + + "46. ERROR in Y.java (at line 63)\n" + + " * @see X#x_priv\n" + + " ^^^^^^\n" + + "Javadoc: The field x_priv is not visible\n" + + "----------\n" + + "47. ERROR in Y.java (at line 64)\n" + + " * @see X#unknown\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "48. ERROR in Y.java (at line 65)\n" + + " * @see X#foo_dep()\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method foo_dep() from the type X is deprecated\n" + + "----------\n" + + "49. ERROR in Y.java (at line 66)\n" + + " * @see X#foo_priv()\n" + + " ^^^^^^^^\n" + + "Javadoc: The method foo_priv() from the type X is not visible\n" + + "----------\n" + + "50. ERROR in Y.java (at line 67)\n" + + " * @see X#foo_dep(String)\n" + + " ^^^^^^^\n" + + "Javadoc: The method foo_dep() in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "51. ERROR in Y.java (at line 68)\n" + + " * @see X#unknown()\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n", + "52. ERROR in Y.java (at line 73)\n" + + " * @param str\n" + + " ^^^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "53. ERROR in Y.java (at line 74)\n" + + " * @param xxx\n" + + " ^^^\n" + + "Javadoc: Parameter xxx is not declared\n" + + "----------\n" + + "54. ERROR in Y.java (at line 77)\n" + + " * @throws java.io.IOException\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Exception IOException is not declared\n" + + "----------\n" + + "55. ERROR in Y.java (at line 78)\n" + + " * @throws Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "56. ERROR in Y.java (at line 79)\n" + + " * @see X_dep\n" + + " ^^^^^\n" + + "Javadoc: The type X_dep is deprecated\n" + + "----------\n" + + "57. ERROR in Y.java (at line 80)\n" + + " * @see X.X_priv\n" + + " ^^^^^^^^\n" + + "Javadoc: The type X.X_priv is not visible\n" + + "----------\n" + + "58. ERROR in Y.java (at line 81)\n" + + " * @see X.Unknown\n" + + " ^^^^^^^^^\n" + + "Javadoc: X.Unknown cannot be resolved to a type\n" + + "----------\n" + + "59. ERROR in Y.java (at line 82)\n" + + " * @see X#X(int)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor X(int) is not visible\n" + + "----------\n" + + "60. ERROR in Y.java (at line 83)\n" + + " * @see X#X(String)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor X(String) is undefined\n" + + "----------\n" + + "61. ERROR in Y.java (at line 84)\n" + + " * @see X#X()\n" + + " ^^^\n" + + "Javadoc: The constructor X() is deprecated\n" + + "----------\n" + + "62. ERROR in Y.java (at line 85)\n" + + " * @see X#x_dep\n" + + " ^^^^^\n" + + "Javadoc: The field X.x_dep is deprecated\n" + + "----------\n" + + "63. ERROR in Y.java (at line 86)\n" + + " * @see X#x_priv\n" + + " ^^^^^^\n" + + "Javadoc: The field x_priv is not visible\n" + + "----------\n" + + "64. ERROR in Y.java (at line 87)\n" + + " * @see X#unknown\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "65. ERROR in Y.java (at line 88)\n" + + " * @see X#foo_dep()\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method foo_dep() from the type X is deprecated\n" + + "----------\n" + + "66. ERROR in Y.java (at line 89)\n" + + " * @see X#foo_priv()\n" + + " ^^^^^^^^\n" + + "Javadoc: The method foo_priv() from the type X is not visible\n" + + "----------\n" + + "67. ERROR in Y.java (at line 90)\n" + + " * @see X#foo_dep(String)\n" + + " ^^^^^^^\n" + + "Javadoc: The method foo_dep() in the type X is not applicable for the arguments (String)\n" + + "----------\n" + + "68. ERROR in Y.java (at line 91)\n" + + " * @see X#unknown()\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type X\n" + + "----------\n", + }; + + private String resultForInvalidTagsClassOrField(int visibility) { + String[] errors = errorsForInvalidTagsClassOrField(visibility); + int length = errors.length; + StringBuilder buffer = new StringBuilder("----------\n"); + for (int i=0; i 0) { + buffer.append("----------\n"); + } + buffer.append(errors[idx++]); + } + buffer.append("----------\n"); + System.out.print(Util.displayString(buffer.toString(), INDENT, true)); + System.out.println(','); + } + for (int k = 0; k < INDENT-1; k++) System.out.print('\t'); + System.out.println("};"); + } + if (exception == null) { + assertEquals("Invalid problem log ", expectedLog, computedProblemLog); + } + } + + private static final String[] X_MISSING_TAGS_ERRORS = { + "1. ERROR in X.java (at line 8)\n" + + " public X(int i) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter i\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " public int publicMethod(long l) { return 0;}\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " public int publicMethod(long l) { return 0;}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter l\n" + + "----------\n", + "4. ERROR in X.java (at line 17)\n" + + " protected X(long l) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter l\n" + + "----------\n" + + "5. ERROR in X.java (at line 19)\n" + + " protected int protectedMethod(long l) { return 0; }\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "6. ERROR in X.java (at line 19)\n" + + " protected int protectedMethod(long l) { return 0; }\n" + + " ^\n" + + "Javadoc: Missing tag for parameter l\n" + + "----------\n", + "7. ERROR in X.java (at line 26)\n" + + " X(float f) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter f\n" + + "----------\n" + + "8. ERROR in X.java (at line 28)\n" + + " int packageMethod(long l) { return 0;}\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "9. ERROR in X.java (at line 28)\n" + + " int packageMethod(long l) { return 0;}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter l\n" + + "----------\n", + "10. ERROR in X.java (at line 35)\n" + + " private X(double d) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter d\n" + + "----------\n" + + "11. ERROR in X.java (at line 37)\n" + + " private int privateMethod(long l) { return 0;}\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "12. ERROR in X.java (at line 37)\n" + + " private int privateMethod(long l) { return 0;}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter l\n" + + "----------\n" + }; + private static final String[] Y_MISSING_TAGS_ERRORS = { + "1. ERROR in Y.java (at line 6)\n" + + " public int publicMethod(long l) { return 0;}\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "2. ERROR in Y.java (at line 6)\n" + + " public int publicMethod(long l) { return 0;}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter l\n" + + "----------\n", + "3. ERROR in Y.java (at line 8)\n" + + " protected int protectedMethod(long l) { return 0;}\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "4. ERROR in Y.java (at line 8)\n" + + " protected int protectedMethod(long l) { return 0;}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter l\n" + + "----------\n", + "5. ERROR in Y.java (at line 10)\n" + + " int packageMethod(long l) { return 0;}\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "6. ERROR in Y.java (at line 10)\n" + + " int packageMethod(long l) { return 0;}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter l\n" + + "----------\n", + "7. ERROR in Y.java (at line 12)\n" + + " private int privateMethod(long l) { return 0;}\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "8. ERROR in Y.java (at line 12)\n" + + " private int privateMethod(long l) { return 0;}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter l\n" + + "----------\n", + "----------\n" + + "1. ERROR in Y.java (at line 12)\n" + + " private int privateMethod(long l) { return 0;}\n" + + " ^^^\n" + + "Javadoc: Missing tag for return type\n" + + "----------\n" + + "2. ERROR in Y.java (at line 12)\n" + + " private int privateMethod(long l) { return 0;}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter l\n" + + "----------\n" + }; + + private String resultForMissingTags(int visibility) { + StringBuilder result = new StringBuilder("----------\n"); + for (int i=0; i<=visibility; i++) { + result.append(X_MISSING_TAGS_ERRORS[i]); + } + if (CompilerOptions.ENABLED.equals(this.reportMissingJavadocTagsOverriding)) { + result.append("----------\n"); + result.append(Y_MISSING_TAGS_ERRORS[this.PUBLIC_VISIBILITY]); + if (visibility >= this.PROTECTED_VISIBILITY) { + result.append(Y_MISSING_TAGS_ERRORS[this.PROTECTED_VISIBILITY]); + if (visibility >= this.DEFAULT_VISIBILITY) { + result.append(Y_MISSING_TAGS_ERRORS[this.DEFAULT_VISIBILITY]); + if (visibility == this.PRIVATE_VISIBILITY) { + result.append(Y_MISSING_TAGS_ERRORS[this.PRIVATE_VISIBILITY]); + } + } + } + } + // Private level is always reported as it never overrides... + else if (visibility == this.PRIVATE_VISIBILITY) { + result.append(Y_MISSING_TAGS_ERRORS[this.PRIVATE_VISIBILITY+1]); + } + return result.toString(); + } + + private static final String[] X_MISSING_COMMENTS_ERRORS = { + "1. ERROR in X.java (at line 4)\n" + + " public class PublicClass {}\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public int publicField;\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public X(int i) {}\n" + + " ^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public int publicMethod(long l) { return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + "5. ERROR in X.java (at line 9)\n" + + " protected class ProtectedClass {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " protected int protectedField;\n" + + " ^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " protected X(long l) {}\n" + + " ^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n" + + "8. ERROR in X.java (at line 12)\n" + + " protected int protectedMethod(long l) { return 0; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n", + "9. ERROR in X.java (at line 14)\n" + + " class PackageClass {}\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "10. ERROR in X.java (at line 15)\n" + + " int packageField;\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "11. ERROR in X.java (at line 16)\n" + + " X(float f) {}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "12. ERROR in X.java (at line 17)\n" + + " int packageMethod(long l) { return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n", + "13. ERROR in X.java (at line 19)\n" + + " private class PrivateClass {}\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "14. ERROR in X.java (at line 20)\n" + + " private int privateField;\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "15. ERROR in X.java (at line 21)\n" + + " private X(double d) {}\n" + + " ^^^^^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + + "16. ERROR in X.java (at line 22)\n" + + " private int privateMethod(long l) { return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + }; + private static final String[] Y_MISSING_COMMENTS_ERRORS = { + "1. ERROR in Y.java (at line 5)\n" + + " public int publicMethod(long l) { return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + "2. ERROR in Y.java (at line 6)\n" + + " protected int protectedMethod(long l) { return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for protected declaration\n" + + "----------\n", + "3. ERROR in Y.java (at line 7)\n" + + " int packageMethod(long l) { return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n", + "4. ERROR in Y.java (at line 8)\n" + + " private int privateMethod(long l) { return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n", + "----------\n" + + "1. ERROR in Y.java (at line 8)\n" + + " private int privateMethod(long l) { return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for private declaration\n" + + "----------\n" + }; + + private String resultForMissingComments(int visibility) { + StringBuilder result = new StringBuilder("----------\n"); + for (int i=0; i<=visibility; i++) { + result.append(X_MISSING_COMMENTS_ERRORS[i]); + } + if (CompilerOptions.ENABLED.equals(this.reportMissingJavadocCommentsOverriding)) { + result.append("----------\n"); + result.append(Y_MISSING_COMMENTS_ERRORS[this.PUBLIC_VISIBILITY]); + if (visibility >= this.PROTECTED_VISIBILITY) { + result.append(Y_MISSING_COMMENTS_ERRORS[this.PROTECTED_VISIBILITY]); + if (visibility >= this.DEFAULT_VISIBILITY) { + result.append(Y_MISSING_COMMENTS_ERRORS[this.DEFAULT_VISIBILITY]); + if (visibility == this.PRIVATE_VISIBILITY) { + result.append(Y_MISSING_COMMENTS_ERRORS[this.PRIVATE_VISIBILITY]); + } + } + } + } + // Private level is always reported for as it never overrides... + else if (visibility == this.PRIVATE_VISIBILITY) { + result.append(Y_MISSING_COMMENTS_ERRORS[this.PRIVATE_VISIBILITY+1]); + } + return result.toString(); + } + + public JavadocTestOptions(String name) { + super(name); + } + public static Class javadocTestClass() { + return JavadocTestOptions.class; + } + public static Test suite() { + return buildAllCompliancesTestSuite(javadocTestClass()); + } + static { // Use this static to initialize testNames (String[]) , testRange (int[2]), testNumbers (int[]) + } + /** + * @return Returns the docCommentSupport. + * + public String getNamePrefix() { + if (this.localDocCommentSupport == null) { + return super.getNamePrefix(); + } else { + return this.localDocCommentSupport; + } + } + */ + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + // Set javadoc options if non null + if (this.docCommentSupport != null) + options.put(CompilerOptions.OPTION_DocCommentSupport, this.docCommentSupport); + if (this.reportInvalidJavadoc != null) + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, this.reportInvalidJavadoc); + if (this.reportInvalidJavadocTagsVisibility != null) + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, this.reportInvalidJavadocTagsVisibility); + if (this.reportInvalidJavadocTags != null) + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, this.reportInvalidJavadocTags); + if (this.reportInvalidJavadocTagsDeprecatedRef != null) + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef, this.reportInvalidJavadocTagsDeprecatedRef); + if (this.reportInvalidJavadocTagsNotVisibleRef!= null) + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsNotVisibleRef, this.reportInvalidJavadocTagsNotVisibleRef); + if (this.reportMissingJavadocTags != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportMissingJavadocTags); + if (this.reportMissingJavadocTagsVisibility != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, this.reportMissingJavadocTagsVisibility); + if (this.reportMissingJavadocTagsOverriding != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsOverriding, this.reportMissingJavadocTagsOverriding); + if (this.reportMissingJavadocComments != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + if (this.reportMissingJavadocCommentsVisibility != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsVisibility, this.reportMissingJavadocCommentsVisibility); + if (this.reportMissingJavadocCommentsOverriding != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsOverriding, this.reportMissingJavadocCommentsOverriding); + + // Ignore other options to avoid polluting warnings + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + return options; + } + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.reportInvalidJavadoc = null; + this.reportInvalidJavadocTagsVisibility = null; + this.reportInvalidJavadocTags = null; + this.reportInvalidJavadocTagsDeprecatedRef = null; + this.reportInvalidJavadocTagsNotVisibleRef = null; + this.reportMissingJavadocTags = null; + this.reportMissingJavadocTagsVisibility = null; + this.reportMissingJavadocTagsOverriding = null; + this.reportMissingJavadocComments = null; + this.reportMissingJavadocCommentsVisibility = null; + this.reportMissingJavadocCommentsOverriding = null; + } + + /* + * Tests for 'invalid javadoc' options when no doc support is set + */ + public void testInvalidTagsClassNoSupport() { + this.docCommentSupport = CompilerOptions.DISABLED; + runConformTest(CLASSES_INVALID_COMMENT); + } + public void testInvalidTagsFieldNoSupport() { + this.docCommentSupport = CompilerOptions.DISABLED; + runConformTest(FIELDS_INVALID_COMMENT); + } + public void testInvalidTagsMethodNoSupport() { + this.docCommentSupport = CompilerOptions.DISABLED; + runConformTest(METHODS_INVALID_COMMENT); + } + public void testInvalidTagsConstructorNoSupport() { + this.docCommentSupport = CompilerOptions.DISABLED; + runConformTest(CONSTRUCTORS_INVALID_COMMENT); + } + + /* + * Tests for 'invalid javadoc' options + */ + // Test default invalid javadoc (means "ignore" with tags"disabled" and visibility "public") + public void testInvalidTagsClassDefaults() { + runConformTest(CLASSES_INVALID_COMMENT); + } + public void testInvalidTagsFieldDefaults() { + runConformTest(FIELDS_INVALID_COMMENT); + } + public void testInvalidTagsMethodDefaults() { + runConformTest(METHODS_INVALID_COMMENT); + } + public void testInvalidTagsConstructorDefaults() { + runConformTest(CONSTRUCTORS_INVALID_COMMENT); + } + + // Test invalid javadoc "error" + tags "disabled" and visibility "public" + public void testInvalidTagsClassErrorNotags() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.DISABLED; + runConformTest(CLASSES_INVALID_COMMENT); + } + public void testInvalidTagsFieldErrorNotags() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.DISABLED; + runConformTest(FIELDS_INVALID_COMMENT); + } + public void testInvalidTagsMethodErrorNotags() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.DISABLED; + runConformTest(METHODS_INVALID_COMMENT); + } + public void testInvalidTagsConstructorErrorNotags() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.DISABLED; + runConformTest(CONSTRUCTORS_INVALID_COMMENT); + } + + // Test invalid javadoc "error" + tags "enabled" and visibility "public" + public void testInvalidTagsClassErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsFieldErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsMethodErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsConstructorErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" and visibility "protected" + public void testInvalidTagsClassErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsFieldErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsMethodErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsConstructorErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" and visibility "default" + public void testInvalidTagsClassErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsFieldErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsMethodErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsConstructorErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" and visibility "private" + public void testInvalidTagsClassErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + runErrorsTest(CLASSES_INVALID_COMMENT, this.PRIVATE_VISIBILITY, false); + } + public void testInvalidTagsFieldErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + runErrorsTest(FIELDS_INVALID_COMMENT, this.PRIVATE_VISIBILITY, false); + } + public void testInvalidTagsMethodErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + runErrorsTest(METHODS_INVALID_COMMENT, this.PRIVATE_VISIBILITY, true); + } + public void testInvalidTagsConstructorErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + runErrorsTest(CONSTRUCTORS_INVALID_COMMENT, this.PRIVATE_VISIBILITY, true); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid deprecated references "disabled" and visibility "public" + public void testInvalidTagsDeprecatedRefClassErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefFieldErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefMethodErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefConstructorErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid deprecated references "disabled" visibility "protected" + public void testInvalidTagsDeprecatedRefClassErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefFieldErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefMethodErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefConstructorErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid deprecated references "disabled" and visibility "default" + public void testInvalidTagsDeprecatedRefClassErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefFieldErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefMethodErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefConstructorErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid deprecated references "disabled" and visibility "private" + public void testInvalidTagsDeprecatedRefClassErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefFieldErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefMethodErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedRefConstructorErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid not visible references "disabled" and visibility "public" + public void testInvalidTagsNotVisibleRefClassErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefFieldErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefMethodErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefConstructorErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid not visible references "disabled" visibility "protected" + public void testInvalidTagsNotVisibleRefClassErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefFieldErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefMethodErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefConstructorErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid not visible references "disabled" and visibility "default" + public void testInvalidTagsNotVisibleRefClassErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefFieldErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefMethodErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefConstructorErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid not visible references "disabled" and visibility "private" + public void testInvalidTagsNotVisibleRefClassErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefFieldErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefMethodErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsNotVisibleRefConstructorErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid deprecated or not visible references "disabled" and visibility "public" + public void testInvalidTagsDeprecatedAndNotVisibleRefClassErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefFieldErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefMethodErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefConstructorErrorTagsPublic() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PUBLIC; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid deprecated or not visible references "disabled" visibility "protected" + public void testInvalidTagsDeprecatedAndNotVisibleRefClassErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefFieldErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefMethodErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefConstructorErrorTagsProtected() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PROTECTED; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid deprecated or not visible references "disabled" and visibility "default" + public void testInvalidTagsDeprecatedAndNotVisibleRefClassErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefFieldErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefMethodErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefConstructorErrorTagsPackage() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.DEFAULT; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test invalid javadoc "error" + tags "enabled" but invalid deprecated or not visible references "disabled" and visibility "private" + public void testInvalidTagsDeprecatedAndNotVisibleRefClassErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + runNegativeTest(CLASSES_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefFieldErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + runNegativeTest(FIELDS_INVALID_COMMENT, resultForInvalidTagsClassOrField(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefMethodErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + runNegativeTest(METHODS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + public void testInvalidTagsDeprecatedAndNotVisibleRefConstructorErrorTagsPrivate() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTagsDeprecatedRef = CompilerOptions.DISABLED; + this.reportInvalidJavadocTagsNotVisibleRef = CompilerOptions.DISABLED; + runNegativeTest(CONSTRUCTORS_INVALID_COMMENT, resultForInvalidTagsMethodOrConstructor(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + /* + * Tests for 'missing javadoc tags' options + */ + // Test default missing javadoc tags (means "ignore" with visibility "public" and overriding="enabled") + public void testMissingTagsDefaults() { + runConformTest(MISSING_TAGS); + } + + // Test missing javadoc tags "error" + "public" visibility + "enabled" overriding + public void testMissingTagsErrorPublicOverriding() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.PUBLIC; + this.reportMissingJavadocTagsOverriding = CompilerOptions.ENABLED; + runNegativeTest(MISSING_TAGS, resultForMissingTags(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc tags "error" + "public" visibility + "disabled" overriding + public void testMissingTagsErrorPublic() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.PUBLIC; + this.reportMissingJavadocTagsOverriding = CompilerOptions.DISABLED; + runNegativeTest(MISSING_TAGS, resultForMissingTags(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc tags "error" + "protected" visibility + "enabled" overriding + public void testMissingTagsErrorProtectedOverriding() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.PROTECTED; + this.reportMissingJavadocTagsOverriding = CompilerOptions.ENABLED; + runNegativeTest(MISSING_TAGS, resultForMissingTags(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc tags "error" + "protected" visibility + "disabled" overriding + public void testMissingTagsErrorProtected() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.PROTECTED; + this.reportMissingJavadocTagsOverriding = CompilerOptions.DISABLED; + runNegativeTest(MISSING_TAGS, resultForMissingTags(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc tags "error" + "default" visibility + "enabled" overriding + public void testMissingTagsErrorPackageOverriding() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.DEFAULT; + this.reportMissingJavadocTagsOverriding = CompilerOptions.ENABLED; + runNegativeTest(MISSING_TAGS, resultForMissingTags(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc tags "error" + "default" visibility + "disabled" overriding + public void testMissingTagsErrorPackage() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.DEFAULT; + this.reportMissingJavadocTagsOverriding = CompilerOptions.DISABLED; + runNegativeTest(MISSING_TAGS, resultForMissingTags(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc tags "error" + "private" visibility + "enabled" overriding + public void testMissingTagsErrorPrivateOverriding() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.PRIVATE; + this.reportMissingJavadocTagsOverriding = CompilerOptions.ENABLED; + runNegativeTest(MISSING_TAGS, resultForMissingTags(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc tags "error" + "private" visibility + "disabled" overriding + public void testMissingTagsErrorPrivate() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.PRIVATE; + this.reportMissingJavadocTagsOverriding = CompilerOptions.DISABLED; + runNegativeTest(MISSING_TAGS, resultForMissingTags(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + /* + * Tests for 'missing javadoc comments' options + */ + // Test default missing javadoc comments (means "ignore" with visibility "public" and overriding="enabled") + public void testMissingCommentsDefaults() { + runConformTest(MISSING_COMMENTS); + } + + // Test missing javadoc comments "error" + "public" visibility + "enabled" overriding + public void testMissingCommentsErrorPublicOverriding() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PUBLIC; + this.reportMissingJavadocCommentsOverriding = CompilerOptions.ENABLED; + runNegativeTest(MISSING_COMMENTS, resultForMissingComments(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc comments "error" + "public" visibility + "disabled" overriding + public void testMissingCommentsErrorPublic() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PUBLIC; + this.reportMissingJavadocCommentsOverriding = CompilerOptions.DISABLED; + runNegativeTest(MISSING_COMMENTS, resultForMissingComments(this.PUBLIC_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc comments "error" + "protected" visibility + "enabled" overriding + public void testMissingCommentsErrorProtectedOverriding() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PROTECTED; + this.reportMissingJavadocCommentsOverriding = CompilerOptions.ENABLED; + runNegativeTest(MISSING_COMMENTS, resultForMissingComments(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc comments "error" + "protected" visibility + "disabled" overriding + public void testMissingCommentsErrorProtected() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PROTECTED; + this.reportMissingJavadocCommentsOverriding = CompilerOptions.DISABLED; + runNegativeTest(MISSING_COMMENTS, resultForMissingComments(this.PROTECTED_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc comments "error" + "default" visibility + "enabled" overriding + public void testMissingCommentsErrorPackageOverriding() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.DEFAULT; + this.reportMissingJavadocCommentsOverriding = CompilerOptions.ENABLED; + runNegativeTest(MISSING_COMMENTS, resultForMissingComments(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc comments "error" + "default" visibility + "disabled" overriding + public void testMissingCommentsErrorPackage() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.DEFAULT; + this.reportMissingJavadocCommentsOverriding = CompilerOptions.DISABLED; + runNegativeTest(MISSING_COMMENTS, resultForMissingComments(this.DEFAULT_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc comments "error" + "private" visibility + "enabled" overriding + public void testMissingCommentsErrorPrivateOverriding() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PRIVATE; + this.reportMissingJavadocCommentsOverriding = CompilerOptions.ENABLED; + runNegativeTest(MISSING_COMMENTS, resultForMissingComments(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + // Test missing javadoc comments "error" + "private" visibility + "disabled" overriding + public void testMissingCommentsErrorPrivate() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PRIVATE; + this.reportMissingJavadocCommentsOverriding = CompilerOptions.DISABLED; + runNegativeTest(MISSING_COMMENTS, resultForMissingComments(this.PRIVATE_VISIBILITY), + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + /* + * Crossed tests + */ + public void testInvalidTagsClassWithMissingTagsOption() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.PRIVATE; + runConformTest(CLASSES_INVALID_COMMENT); + } + public void testInvalidTagsFieldWithMissingTagsOption() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.PRIVATE; + runConformTest(FIELDS_INVALID_COMMENT); + } + public void testInvalidTagsMethodWithMissingTagsOption() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.PRIVATE; + runConformTest(METHODS_INVALID_COMMENT); + } + public void testInvalidTagsConstructorWithMissingTagsOption() { + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsVisibility = CompilerOptions.PRIVATE; + runConformTest(CONSTRUCTORS_INVALID_COMMENT); + } + public void testMissingTagsWithInvalidTagsOption() { + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ENABLED; + this.reportInvalidJavadocTagsVisibility = CompilerOptions.PRIVATE; + runConformTest(MISSING_TAGS); + } + + /** + * Test fix for bug 52264. + * @see 52264 + */ + // Test invalid javadoc "error" with javadoc comment support disabled + public void testInvalidTagsJavadocSupportDisabled() { + this.docCommentSupport = CompilerOptions.DISABLED; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocTags = CompilerOptions.ERROR; + runConformTest(CLASSES_INVALID_COMMENT); + runConformTest(FIELDS_INVALID_COMMENT); + runConformTest(METHODS_INVALID_COMMENT); + runConformTest(CONSTRUCTORS_INVALID_COMMENT); + } + + // Test missing javadoc comments "error" with javadoc comment support disabled + public void testMissingCommentsJavadocSupportDisabled() { + this.docCommentSupport = CompilerOptions.DISABLED; + this.reportMissingJavadocComments = CompilerOptions.ERROR; + runConformReferenceTest(MISSING_COMMENTS); + } + + // Test missing javadoc tags "error" with javadoc comment support disabled + public void testMissingTagsJavadocSupportDisabled() { + this.docCommentSupport = CompilerOptions.DISABLED; + this.reportMissingJavadocTags = CompilerOptions.ERROR; + runConformReferenceTest(MISSING_TAGS); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_15.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_15.java new file mode 100644 index 0000000000..3932bbe7ef --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_15.java @@ -0,0 +1,474 @@ +/******************************************************************************* + * Copyright (c) 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTest_15 extends JavadocTest { + + String docCommentSupport = CompilerOptions.ENABLED; + String reportInvalidJavadoc = CompilerOptions.ERROR; + String reportMissingJavadocDescription = CompilerOptions.RETURN_TAG; + String reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + String reportMissingJavadocTags = CompilerOptions.ERROR; + String reportMissingJavadocComments = null; + String reportMissingJavadocCommentsVisibility = null; + String reportDeprecation = CompilerOptions.ERROR; + String reportJavadocDeprecation = null; + String processAnnotations = null; + +public JavadocTest_15(String name) { + super(name); +} + +public static Class javadocTestClass() { + return JavadocTest_15.class; +} + +// Use this static initializer to specify subset for tests +// All specified tests which does not belong to the class are skipped... +static { + +} + +public static Test suite() { + return buildMinimalComplianceTestSuite(javadocTestClass(), F_15); +} + +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, this.docCommentSupport); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, this.reportInvalidJavadoc); + if (!CompilerOptions.IGNORE.equals(this.reportInvalidJavadoc)) { + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, this.reportInvalidJavadocVisibility); + } + if (this.reportJavadocDeprecation != null) { + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef, this.reportJavadocDeprecation); + } + if (this.reportMissingJavadocComments != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsOverriding, CompilerOptions.ENABLED); + if (this.reportMissingJavadocCommentsVisibility != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsVisibility, this.reportMissingJavadocCommentsVisibility); + } + } else { + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportInvalidJavadoc); + } + if (this.reportMissingJavadocTags != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportMissingJavadocTags); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsOverriding, CompilerOptions.ENABLED); + } else { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportInvalidJavadoc); + } + if (this.reportMissingJavadocDescription != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagDescription, this.reportMissingJavadocDescription); + } + if (this.processAnnotations != null) { + options.put(CompilerOptions.OPTION_Process_Annotations, this.processAnnotations); + } + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportDeprecation, this.reportDeprecation); + options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + return options; +} +/* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ +@Override +protected void setUp() throws Exception { + super.setUp(); + this.docCommentSupport = CompilerOptions.ENABLED; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PUBLIC; + this.reportDeprecation = CompilerOptions.ERROR; +} + +public void test001() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + + String moduleInfo = "" + + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + "}"; + String I1 = "" + + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " * @see mod.one/\n" + + " */\n" + + "interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"; + + String P1 = "" + + "package p;\n" + + "/**\n" + + " * class P1\n" + + " * @see mod.one/p.I1\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"; + + this.runConformTest(new String[] {"p/I1.java", I1 ,"p/P1.java" , P1 } , + new String[] {"module-info.java", moduleInfo }, "" ); +} + +public void test002() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + + String moduleInfo = "" + + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + "}"; + String I1 = "" + + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " * {@link mod.one/}\n" + + " */\n" + + "interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"; + + String P1 = "" + + "package p;\n" + + "/**\n" + + " * class P1\n" + + " * {@link mod.one/p.I1}\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"; + + this.runConformTest(new String[] {"p/I1.java", I1 ,"p/P1.java" , P1 } , + new String[] {"module-info.java", moduleInfo }, "" ); +} + +public void test003() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + + String moduleInfo = "" + + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + "}"; + String I1 = "" + + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " * {@linkplain mod.one/}\n" + + " */\n" + + "interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"; + + String P1 = "" + + "package p;\n" + + "/**\n" + + " * class P1\n" + + " * {@linkplain mod.one/p.I1}\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"; + + this.runConformTest(new String[] {"p/I1.java", I1 ,"p/P1.java" , P1 } , + new String[] {"module-info.java", moduleInfo }, "" ); +} + +public void test004() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + + String moduleInfo = "" + + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + "}"; + String I1 = "" + + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " * {@linkplain mod.one/}\n" + + " */\n" + + "interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"; + + String P1 = "" + + "package p;\n" + + "/**\n" + + " * class P1\n" + + " * {@linkplain mod.one/p.P1#foo()}\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"; + + this.runConformTest(new String[] {"p/I1.java", I1 ,"p/P1.java" , P1 } , + new String[] {"module-info.java", moduleInfo }, "" ); +} + +public void test005() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + + String moduleInfo = "" + + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + "}"; + String I1 = "" + + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " * {@linkplain mod.one/}\n" + + " */\n" + + "interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"; + + String P1 = "" + + "package p;\n" + + "/**\n" + + " * class P1\n" + + " * {@linkplain mod.one/p.P1#abc}\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " public int abc;\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"; + + this.runConformTest(new String[] {"p/I1.java", I1 ,"p/P1.java" , P1 } , + new String[] {"module-info.java", moduleInfo }, "" ); +} + +public void test006() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + + String moduleInfo = "" + + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + "}"; + String I1 = "" + + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " * {@linkplain mod.one/}\n" + + " */\n" + + "interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"; + + String P1 = "" + + "package p;\n" + + "/**\n" + + " * class P1\n" + + " * {@linkplain mod.one/p.P1#abd}\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " public int abc;\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"; + String errorMsg = "" + + "----------\n" + + "1. ERROR in p\\P1.java (at line 4)\n" + + " * {@linkplain mod.one/p.P1#abd}\n" + + " ^^^\n" + + "Javadoc: abd cannot be resolved or is not a field\n" + + "----------\n"; + + this.runNegativeTest(new String[] {"p/I1.java", I1 ,"p/P1.java" , P1 } , + new String[] {"module-info.java", moduleInfo }, errorMsg, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test007() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + + String moduleInfo = "" + + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + "}"; + String I1 = "" + + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " * @see mod.one/ abc\n" + + " */\n" + + "interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"; + + String P1 = "" + + "package p;\n" + + "/**\n" + + " * class P1\n" + + " * @see mod.one/p.I1 xyz\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"; + + this.runConformTest(new String[] {"p/I1.java", I1 ,"p/P1.java" , P1 } , + new String[] {"module-info.java", moduleInfo }, "" ); +} + +public void test008() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + + String moduleInfo = "" + + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + "}"; + String I1 = "" + + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " * {@link mod.one/ abc}\n" + + " */\n" + + "interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"; + + String P1 = "" + + "package p;\n" + + "/**\n" + + " * class P1\n" + + " * {@link mod.one/p.I1 xyz}\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"; + + this.runConformTest(new String[] {"p/I1.java", I1 ,"p/P1.java" , P1 } , + new String[] {"module-info.java", moduleInfo }, "" ); +} + +public void test009() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + + String moduleInfo = "" + + "/**\n" + + " */\n" + + "module mod.one { \n" + + " exports p;\n" + + "}"; + String I1 = "" + + "package p;\n" + + "/**\n" + + " * interface I1\n" + + " * {@linkplain mod.one/ abc}\n" + + " */\n" + + "interface I1 {\n" + + " /**\n" + + " * Method foo\n" + + " * @return int\n" + + " */\n" + + " public int foo();\n" + + "}"; + + String P1 = "" + + "package p;\n" + + "/**\n" + + " * class P1\n" + + " * {@linkplain mod.one/p.I1 xyz}\n" + + " */\n" + + "public class P1 implements I1 {\n" + + " @Override\n" + + " public int foo() { return 0; }\n" + + "}"; + + this.runConformTest(new String[] {"p/I1.java", I1 ,"p/P1.java" , P1 } , + new String[] {"module-info.java", moduleInfo }, "" ); +} + +} + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_3.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_3.java new file mode 100644 index 0000000000..bdb553db75 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_3.java @@ -0,0 +1,3581 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTest_1_3 extends JavadocTest { + + String docCommentSupport = CompilerOptions.ENABLED; + String reportInvalidJavadoc = CompilerOptions.ERROR; + String reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + String reportMissingJavadocTags = CompilerOptions.ERROR; + String reportMissingJavadocComments = null; + String reportMissingJavadocCommentsVisibility = null; + + public JavadocTest_1_3(String name) { + super(name); + } + + public static Class testClass() { + return JavadocTest_1_3.class; + } + + // Use this static initializer to specify subset for tests + // All specified tests which does not belong to the class are skipped... + static { +// TESTS_NAMES = new String[] { +// "testBug70892conform1", "testBug70892conform2" +// }; +// TESTS_NUMBERS = new int[] { 101283 }; +// TESTS_RANGE = new int[] { 21, 50 }; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_3); + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, this.docCommentSupport); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, this.reportInvalidJavadoc); + if (!CompilerOptions.IGNORE.equals(this.reportInvalidJavadoc)) { + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, this.reportInvalidJavadocVisibility); + } + if (this.reportMissingJavadocComments != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + else + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportInvalidJavadoc); + if (this.reportMissingJavadocCommentsVisibility != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsVisibility, this.reportMissingJavadocCommentsVisibility); + if (this.reportMissingJavadocTags != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportMissingJavadocTags); + else + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportInvalidJavadoc); + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + return options; + } + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.docCommentSupport = CompilerOptions.ENABLED; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + } + + + /** + * Test fix for bug 70891: [1.5][javadoc] Compiler should accept new 1.5 syntax for @param + * @see 70891 + * These two tests fail for 1.5 source level but should pass for 1.3 or 1.4 + * @see JavadocTest_1_3 + */ + /* (non-Javadoc) + * Test @param for generic class type parameter + */ + public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " * @param Type\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\r\n" + + " public class X {}\r\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type extends RuntimeException\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " * @param Type extends RuntimeException\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\r\n" + + " public class X {}\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + + ); + } + public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " * @param Type parameter 1\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\r\n" + + " * @param Type parameter 2\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\r\n" + + " * @param Type parameter 3\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\r\n" + + " public class X {}\r\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter\n" + + " */\n" + + " public class X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + ); + } + public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter\n" + + " */\n" + + " public class X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " * @param Type parameter 3\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\r\n" + + " * @param Type parameter 2\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\r\n" + + " * @param Type parameter 1\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\r\n" + + " public class X {}\r\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test019() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 2\n" + + " * @param\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test021() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, insert \"ClassBody\" to complete CompilationUnit\n" + + "----------\n" + ); + } + public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, insert \"ClassBody\" to complete CompilationUnit\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^^^^^^\n" + + "extend cannot be resolved to a type\n" + + "----------\n" + ); + } + + /* (non-Javadoc) + * Test @param for generic method type parameter + */ + public void test023() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type\n" + + " */\n" + + " public void foo() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " * @param Type\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\r\n" + + " public void foo() {}\r\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type extends RuntimeException\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " * @param Type extends RuntimeException\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\r\n" + + " public void foo(int val, Object obj) {}\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test025() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\r\n" + + " * @param Type parameter 1\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\r\n" + + " * @param Type parameter 2\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\r\n" + + " * @param Type parameter 3\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\r\n" + + " public void foo(int val, Object obj) {}\r\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param val int\n" + + " * @param Type parameter\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param Type parameter\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + ); + } + public void test027() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + public void test028() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " * @param xxx int\n" + + " * @param Obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " * @param xxx int\n" + + " ^^^\n" + + "Javadoc: Parameter xxx is not declared\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " * @param Obj Object\n" + + " ^^^\n" + + "Javadoc: Parameter Obj is not declared\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "8. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + public void test029() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param val int\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param obj Object\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test030() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param obj Object\n" + + " * @param Type parameter 2\n" + + " * @param val int\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " * @param Type parameter 3\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\r\n" + + " * @param Type parameter 2\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\r\n" + + " * @param Type parameter 1\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\r\n" + + " public void foo(int val, Object obj) {}\r\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test031() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + public void test032() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param val int\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + public void test033() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param obj Object\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + ); + } + public void test034() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param val int\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param Object obj\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param val int\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @param Object obj\n" + + " ^^^^^^\n" + + "Javadoc: Parameter Object is not declared\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " * @param val int\n" + + " ^^^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + public void test035() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 2\n" + + " * @param\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + // TODO (david) recovery seems not to work properly here: + // we should have type parameters in method declaration. + public void test036() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + ); + } + public void test037() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^^^^^^^^\n" + + "Exceptions cannot be resolved to a type\n" + + "----------\n" + ); + } + public void test038() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param < Type\n" + + " * @param < Type for parameterization\n" + + " * @param <> Type\n" + + " * @param Type\n" + + " * @param <*> Type\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param < Type\n" + + " ^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param < Type for parameterization\n" + + " ^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param <> Type\n" + + " ^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param Type\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param <*> Type\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type\n" + + " * @param < Type\n" + + " * @param << Type\n" + + " * @param > Type\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type\n" + + " ^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param < Type\n" + + " ^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param << Type\n" + + " ^^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param > Type\n" + + " ^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + + public void test040() { + runConformReferenceTest( + new String[] { + "X.java", + "/**\n" + + " * @category\n" + + " */\n" + + "public class X {\n" + + "}\n" + } + ); + } + + /** + * Test fix for bug 80257: [javadoc] Invalid missing reference warning on @see or @link tags + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=80257" + */ + public void testBug80257() { + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @see G#G(Object)\n" + + " * @see G#G(Exception)\n" + + " */\n" + + "public class X extends G {\n" + + " X(Exception exc) { super(exc);}\n" + + "}\n" + + "class G {\n" + + " G(E e) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " * @see G#G(Object)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor G(Object) is undefined\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X extends G {\n" + + " ^^^^^^^^^\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 {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + + /** + * Test fix for bug 82514: [1.5][javadoc] Problem with generics in javadoc + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=82514" + */ + public void testBug82514() { + this.runNegativeTest( + new String[] { + "X.java", + "class ComparableUtils {\n" + + " public static > int compareTo(final Object first, final Object firstPrime, final Class type) throws ClassCastException\n" + + " {\n" + + " return 0;\n" + + " }\n" + + " public static > int compareTo(final X first, final X firstPrime)\n" + + " throws ClassCastException\n" + + " {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public final class X { \n" + + " /** Tests the method{@link ComparableUtils#compareTo(Object, Object, Class)} and\n" + + " * {@link ComparableUtils#compareTo(Object, Object)}.\n" + + " */\n" + + " public void testCompareTo() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static > int compareTo(final Object first, final Object firstPrime, final Class type) throws ClassCastException\n" + + " ^^^^^^^^^^^^^^^^^^^^\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 > int compareTo(final Object first, final Object firstPrime, final Class type) throws ClassCastException\n" + + " ^\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 > int compareTo(final X first, final X firstPrime)\n" + + " ^^^^^^^^^^^^^^^^^^^^\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 > int compareTo(final X first, final X firstPrime)\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " * {@link ComparableUtils#compareTo(Object, Object)}.\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method compareTo(Object, Object, Class) in the type ComparableUtils is not applicable for the arguments (Object, Object)\n" + + "----------\n"); + } + + /** + * Test fix for bug 83127: [1.5][javadoc][dom] Wrong / strange bindings for references in javadoc to methods with type variables as parameter types + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83127" + */ + public void testBug83127a() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Test.java", + "/** \n" + + " * @see Test#add(T) \n" + + " * @see #add(T)\n" + + " * @see Test#Test(T)\n" + + " * @see #Test(T)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (T)\"\n" + + " * - method binding = Test.add(Object)\n" + + " * - parameter binding = T of A\n" + + " */\n" + + "public class Test {\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Test#add(T) \n" + + " ^^^\n" + + "Javadoc: The method add(Object) in the type Test is not applicable for the arguments (T)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see #add(T)\n" + + " ^^^\n" + + "Javadoc: The method add(Object) in the type Test is not applicable for the arguments (T)\n" + + "----------\n" + + "3. ERROR in Test.java (at line 4)\n" + + " * @see Test#Test(T)\n" + + " ^^^^^^^\n" + + "Javadoc: The constructor Test(T) is undefined\n" + + "----------\n" + + "4. ERROR in Test.java (at line 5)\n" + + " * @see #Test(T)\n" + + " ^^^^^^^\n" + + "Javadoc: The constructor Test(T) is undefined\n" + + "----------\n" + + "5. ERROR in Test.java (at line 11)\n" + + " public class Test {\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127b() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Test.java", + "/** \n" + + " * @see Sub#add(T)\n" + + " * @see Sub#Sub(T)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (T)\"\n" + + " * - method binding = Test.add(Object)\n" + + " * - parameter binding = T of A\n" + + " * -> Do we need to change this as T natually resolved to TypeVariable?\n" + + " * As compiler raises a warning, it\'s perhaps not a problem now...\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Sub#add(T)\n" + + " ^^^\n" + + "Javadoc: The method add(Object) in the type Test is not applicable for the arguments (T)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Sub#Sub(T)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor Sub(T) is undefined\n" + + "----------\n" + + "3. ERROR in Test.java (at line 11)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127c() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Test.java", + "/** \n" + + " * @see Sub#add(E) \n" + + " * @see Sub#Sub(E)\n" + + " * - warning = \"E cannot be resolved to a type\"\n" + + " * - method binding = null\n" + + " * - parameter binding = null\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Sub#add(E) \n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Sub#Sub(E)\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in Test.java (at line 8)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127d() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(E)\n" + + " * @see Unrelated1#Unrelated1(E)\n" + + " * - warning = \"E cannot be resolved to a type\"\n" + + " * - method binding = null\n" + + " * - parameter binding = null\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unrelated1.java (at line 1)\n" + + " public class Unrelated1 {\n" + + " ^^^^^^^^^^^^^^^^\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" + + " * @see Unrelated1#add(E)\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Unrelated1#Unrelated1(E)\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in Test.java (at line 8)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127e() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(Object)\n" + + " * @see Unrelated1#Unrelated1(Object)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (Object)\"\n" + + " * - method binding = Unrelated1.add(Number)\n" + + " * - parameter binding = java.lang.Object\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unrelated1.java (at line 1)\n" + + " public class Unrelated1 {\n" + + " ^^^^^^^^^^^^^^^^\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" + + " * @see Unrelated1#add(Object)\n" + + " ^^^\n" + + "Javadoc: The method add(Number) in the type Unrelated1 is not applicable for the arguments (Object)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Unrelated1#Unrelated1(Object)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The constructor Unrelated1(Object) is undefined\n" + + "----------\n" + + "3. ERROR in Test.java (at line 9)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127f() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(Number)\n" + + " * @see Unrelated1#Unrelated1(Number)\n" + + " * - no warning\n" + + " * - method binding = Unrelated1.add(Number)\n" + + " * - parameter binding = java.lang.Number\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unrelated1.java (at line 1)\n" + + " public class Unrelated1 {\n" + + " ^^^^^^^^^^^^^^^^\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{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug83127g() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(Integer)\n" + + " * @see Unrelated1#Unrelated1(Integer)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (Integer)\"\n" + + " * - method binding = Unrelated1.add(Number)\n" + + " * - parameter binding = java.lang.Integer\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unrelated1.java (at line 1)\n" + + " public class Unrelated1 {\n" + + " ^^^^^^^^^^^^^^^^\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" + + " * @see Unrelated1#add(Integer)\n" + + " ^^^\n" + + "Javadoc: The method add(Number) in the type Unrelated1 is not applicable for the arguments (Integer)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Unrelated1#Unrelated1(Integer)\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The constructor Unrelated1(Integer) is undefined\n" + + "----------\n" + + "3. ERROR in Test.java (at line 9)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug83127h() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated2.java", + "public interface Unrelated2 {\n" + + " boolean add(E e);\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated2#add(T)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (T)\"\n" + + " * - method binding = Unrelated2.add(Object)\n" + + " * - parameter binding = T of A\n" + + " * -> Do we need to change this as T natually resolved to TypeVariable?\n" + + " * As compiler raises a warning, it\'s perhaps not a problem now...\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unrelated2.java (at line 1)\n" + + " public interface Unrelated2 {\n" + + " ^\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" + + " * @see Unrelated2#add(T)\n" + + " ^^^\n" + + "Javadoc: The method add(Object) in the type Unrelated2 is not applicable for the arguments (T)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 10)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + + /** + * Bug 83393: [1.5][javadoc] reference to vararg method also considers non-array type as correct + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83393" + */ + public void testBug83393a() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public void foo(int a, int b) {} \n" + + " public void foo(int a, int... args) {}\n" + + " public void foo(String... args) {}\n" + + " public void foo(Exception str, boolean... args) {}\n" + + "}\n", + "Valid.java", + "/**\n" + + " * @see Test#foo(int, int)\n" + + " * @see Test#foo(int, int[])\n" + + " * @see Test#foo(int, int...)\n" + + " * @see Test#foo(String[])\n" + + " * @see Test#foo(String...)\n" + + " * @see Test#foo(Exception, boolean[])\n" + + " * @see Test#foo(Exception, boolean...)\n" + + " */\n" + + "public class Valid {}\n" + }, + "----------\n" + + "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 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 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 or greater\n" + + "----------\n" + ); + } + public void testBug83393b() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public void foo(int a, int b) {} \n" + + " public void foo(int a, int... args) {}\n" + + " public void foo(String... args) {}\n" + + " public void foo(Exception str, boolean... args) {}\n" + + "}\n", + "Invalid.java", + "/**\n" + + " * @see Test#foo(int)\n" + + " * @see Test#foo(int, int, int)\n" + + " * @see Test#foo()\n" + + " * @see Test#foo(String)\n" + + " * @see Test#foo(String, String)\n" + + " * @see Test#foo(Exception)\n" + + " * @see Test#foo(Exception, boolean)\n" + + " * @see Test#foo(Exception, boolean, boolean)\n" + + " */\n" + + "public class Invalid {}\n" + }, + "----------\n" + + "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 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 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 or greater\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Invalid.java (at line 2)\n" + + " * @see Test#foo(int)\n" + + " ^^^\n" + + "Javadoc: The method foo(int, int) in the type Test is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in Invalid.java (at line 3)\n" + + " * @see Test#foo(int, int, int)\n" + + " ^^^\n" + + "Javadoc: The method foo(int, int) in the type Test is not applicable for the arguments (int, int, int)\n" + + "----------\n" + + "3. ERROR in Invalid.java (at line 4)\n" + + " * @see Test#foo()\n" + + " ^^^\n" + + "Javadoc: The method foo(String[]) in the type Test is not applicable for the arguments ()\n" + + "----------\n" + + "4. ERROR in Invalid.java (at line 5)\n" + + " * @see Test#foo(String)\n" + + " ^^^\n" + + "Javadoc: The method foo(String[]) in the type Test is not applicable for the arguments (String)\n" + + "----------\n" + + "5. ERROR in Invalid.java (at line 6)\n" + + " * @see Test#foo(String, String)\n" + + " ^^^\n" + + "Javadoc: The method foo(int, int) in the type Test is not applicable for the arguments (String, String)\n" + + "----------\n" + + "6. ERROR in Invalid.java (at line 7)\n" + + " * @see Test#foo(Exception)\n" + + " ^^^\n" + + "Javadoc: The method foo(Exception, boolean[]) in the type Test is not applicable for the arguments (Exception)\n" + + "----------\n" + + "7. ERROR in Invalid.java (at line 8)\n" + + " * @see Test#foo(Exception, boolean)\n" + + " ^^^\n" + + "Javadoc: The method foo(Exception, boolean[]) in the type Test is not applicable for the arguments (Exception, boolean)\n" + + "----------\n" + + "8. ERROR in Invalid.java (at line 9)\n" + + " * @see Test#foo(Exception, boolean, boolean)\n" + + " ^^^\n" + + "Javadoc: The method foo(Exception, boolean[]) in the type Test is not applicable for the arguments (Exception, boolean, boolean)\n" + + "----------\n" + ); + } + + /** + * Bug 86769: [javadoc] Warn/Error for 'Missing javadoc comments' doesn't recognize private inner classes + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=86769" + */ + public void testBug86769() { + + /* Deleted a completely meaningless test that could only serve as a torture test for the parser. + The test is still run in 1.5+ modes where it makes sense to run it - The test here was a nuisance + failing every time there is some serious grammar change that alters the semi-random behavior in + Diagnose Parser. + */ + return; + } + + /** + * Bug 83804: [1.5][javadoc] Missing Javadoc node for package declaration + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83804" + */ + public void testBug83804() { + runNegativeTest( + new String[] { + "pack/package-info.java", + "/**\n" + + " * Valid javadoc.\n" + + " * @see Test\n" + + " * @see Unknown\n" + + " * @see Test#foo()\n" + + " * @see Test#unknown()\n" + + " * @see Test#field\n" + + " * @see Test#unknown\n" + + " * @param unexpected\n" + + " * @throws unexpected\n" + + " * @return unexpected \n" + + " * @deprecated accepted by javadoc.exe although javadoc 1.5 spec does not say that's a valid tag\n" + + " * @other-tags are valid\n" + + " */\n" + + "package pack;\n", + "pack/Test.java", + "/**\n" + + " * Invalid javadoc\n" + + " */\n" + + "package pack;\n" + + "public class Test {\n" + + " public int field;\n" + + " public void foo() {}\n" + + "}\n" + }, + "" + ); + } + /** + * Bug 96237: [javadoc] Inner types must be qualified + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=96237" + */ + public void testBug96237_Public01() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runConformTest( + new String[] { + "comment6/Valid.java", + "package comment6;\n" + + "public class Valid {\n" + + " /**\n" + + " * @see Valid.Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Valid.Inner}\n" + + " */\n" + + "class Sub2 extends Valid { }" + } + ); + } + public void testBug96237_Public02() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "comment6/Invalid.java", + "package comment6;\n" + + "public class Invalid {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Inner} \n" + + " */\n" + + "class Sub1 extends Invalid { }\n" + }, + //comment6\Invalid.java:6: warning - Tag @see: reference not found: Inner + "----------\n" + + "1. ERROR in comment6\\Invalid.java (at line 4)\r\n" + + " * @see Inner\r\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Public03() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "comment6a/def/Test.java", + "package comment6a.def;\n" + + "public class Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6a/test/Invalid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * See also {@link Inner}\n" + + " */\n" + + "public class Invalid extends Test { \n" + + "}", + "comment6a/test/Invalid2.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Invalid2 extends Test { \n" + + "}", + "comment6a/test/Valid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see comment6a.def.Test.Inner\n" + + " */\n" + + "public class Valid extends Test { \n" + + "}" + }, + //comment6a\def\Test.java:6: warning - Tag @see: reference not found: Inner + //comment6a\test\Invalid.java:8: warning - Tag @link: reference not found: Inner + //comment6a\test\Invalid2.java:8: warning - Tag @see: reference not found: Test.Inner => bug ID: 4464323 + "----------\n" + + "1. ERROR in comment6a\\def\\Test.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid.java (at line 4)\n" + + " * See also {@link Inner}\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid2.java (at line 4)\n" + + " * @see Test.Inner\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Public04() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "comment6b/Invalid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Inner\n" + + " */\n" + + "public class Invalid implements Test { \n" + + "}", + "comment6b/Test.java", + "package comment6b;\n" + + "public interface Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6b/Valid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Valid implements Test { \n" + + "}" + }, + //comment6b\Test.java:6: warning - Tag @see: reference not found: Inner + //comment6b\Invalid.java:6: warning - Tag @see: reference not found: Inner + "----------\n" + + "1. ERROR in comment6b\\Invalid.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6b\\Test.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Public05() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/a/Test.java", + "package test.a;\n" + + "/**\n" + + " * @see Inner\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Test {\n" + + " class Inner {}\n" + + "}\n" + }, + //test\a\Test.java:6: warning - Tag @see: reference not found: Inner + //test\a\Test.java:6: warning - Tag @see: reference not found: Test.Inner + "----------\n" + + "1. ERROR in test\\a\\Test.java (at line 3)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\a\\Test.java (at line 4)\n" + + " * @see Test.Inner\n" + + " ^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + ); + } + public void testBug96237_Public06() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/b/Test.java", + "package test.b;\n" + + "/** \n" + + " * @see Inner.Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + "public class Test {\n" + + " /** \n" + + " * @see Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + " public class Inner {\n" + + " class Level2 {}\n" + + " }\n" + + "}\n" + }, + //test\b\Test.java:6: warning - Tag @see: reference not found: Inner.Level2 + //test\b\Test.java:6: warning - Tag @see: reference not found: Test.Inner.Level2 + //test\b\Test.java:11: warning - Tag @see: reference not found: Level2 + //test\b\Test.java:11: warning - Tag @see: reference not found: Test.Inner.Level2 + "----------\n" + + "1. ERROR in test\\b\\Test.java (at line 3)\n" + + " * @see Inner.Level2\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\b\\Test.java (at line 4)\n" + + " * @see Test.Inner.Level2\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "3. ERROR in test\\b\\Test.java (at line 8)\n" + + " * @see Level2\n" + + " ^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "4. ERROR in test\\b\\Test.java (at line 9)\n" + + " * @see Test.Inner.Level2\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + ); + } + public void testBug96237_Public07() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/c/Test.java", + "package test.c;\n" + + "/**\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * @see Level3\n" + + " * @see Level2.Level3\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + " public class Level2 {\n" + + " class Level3 {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + //test\c\Test.java:6: warning - Tag @see: reference not found: Inner.Level2.Level3 + //test\c\Test.java:6: warning - Tag @see: reference not found: Test.Inner.Level2.Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Level2.Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Inner.Level2.Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Test.Inner.Level2.Level3 + "----------\n" + + "1. ERROR in test\\c\\Test.java (at line 3)\n" + + " * @see Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\c\\Test.java (at line 4)\n" + + " * @see Test.Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "3. ERROR in test\\c\\Test.java (at line 9)\n" + + " * @see Level3\n" + + " ^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "4. ERROR in test\\c\\Test.java (at line 10)\n" + + " * @see Level2.Level3\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "5. ERROR in test\\c\\Test.java (at line 11)\n" + + " * @see Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "6. ERROR in test\\c\\Test.java (at line 12)\n" + + " * @see Test.Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + ); + } + public void testBug96237_Public08() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/d/Reference.java", + "package test.d;\n" + + "class Reference {\n" + + "}\n", + "test/d/Test.java", + "package test.d;\n" + + "/**\n" + + " * @see Secondary\n" + + " * @see Reference\n" + + " */\n" + + "public class Test {\n" + + "}\n" + + "class Secondary {}" + }, + "----------\n" + + "1. ERROR in test\\d\\Test.java (at line 3)\n" + + " * @see Secondary\n" + + " ^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\d\\Test.java (at line 4)\n" + + " * @see Reference\n" + + " ^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + ); + } + public void testBug96237_Private01() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "comment6/Valid.java", + "package comment6;\n" + + "public class Valid {\n" + + " /**\n" + + " * @see Valid.Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Valid.Inner}\n" + + " */\n" + + "class Sub2 extends Valid { }" + } + ); + } + public void testBug96237_Private02() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runNegativeTest( + new String[] { + "comment6/Invalid.java", + "package comment6;\n" + + "public class Invalid {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Inner} \n" + + " */\n" + + "class Sub1 extends Invalid { }\n" + }, + //comment6\Invalid.java:6: warning - Tag @see: reference not found: Inner + //comment6\Invalid.java:11: warning - Tag @link: reference not found: Inner + "----------\n" + + "1. ERROR in comment6\\Invalid.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in comment6\\Invalid.java (at line 9)\n" + + " * See also {@link Inner} \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Private03() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runNegativeTest( + new String[] { + "comment6a/def/Test.java", + "package comment6a.def;\n" + + "public class Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6a/test/Invalid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * See also {@link Inner}\n" + + " */\n" + + "public class Invalid extends Test { \n" + + "}", + "comment6a/test/Invalid2.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Invalid2 extends Test { \n" + + "}", + "comment6a/test/Valid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see comment6a.def.Test.Inner\n" + + " */\n" + + "public class Valid extends Test { \n" + + "}" + }, + //comment6a\def\Test.java:6: warning - Tag @see: reference not found: Inner + //comment6a\test\Invalid.java:8: warning - Tag @link: reference not found: Inner + //comment6a\test\Invalid2.java:8: warning - Tag @see: reference not found: Test.Inner => bug ID: 4464323 + "----------\n" + + "1. ERROR in comment6a\\def\\Test.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid.java (at line 4)\n" + + " * See also {@link Inner}\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid2.java (at line 4)\n" + + " * @see Test.Inner\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Private04() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runNegativeTest( + new String[] { + "comment6b/Invalid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Inner\n" + + " */\n" + + "public class Invalid implements Test { \n" + + "}", + "comment6b/Test.java", + "package comment6b;\n" + + "public interface Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6b/Valid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Valid implements Test { \n" + + "}" + }, + //comment6b\Invalid.java:6: warning - Tag @see: reference not found: Inner + //comment6b\Test.java:6: warning - Tag @see: reference not found: Inner + "----------\n" + + "1. ERROR in comment6b\\Invalid.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6b\\Test.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Private05() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/a/Test.java", + "package test.a;\n" + + "/**\n" + + " * @see Inner\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Test {\n" + + " class Inner {}\n" + + "}\n" + } + ); + } + public void testBug96237_Private06() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/b/Test.java", + "package test.b;\n" + + "/** \n" + + " * @see Inner.Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + "public class Test {\n" + + " /** \n" + + " * @see Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + " public class Inner {\n" + + " class Level2 {}\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug96237_Private07() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/c/Test.java", + "package test.c;\n" + + "/**\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * @see Level3\n" + + " * @see Level2.Level3\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + " public class Level2 {\n" + + " class Level3 {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug96237_Private08() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/d/Reference.java", + "package test.d;\n" + + "class Reference {\n" + + "}\n", + "test/d/Test.java", + "package test.d;\n" + + "/**\n" + + " * @see Secondary\n" + + " * @see Reference\n" + + " */\n" + + "public class Test {\n" + + "}\n" + + "class Secondary {}" + } + ); + } + + /** + * Bug 95286: [1.5][javadoc] package-info.java incorrectly flags "Missing comment for public declaration" + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=95286" + */ + public void testBug95286_Default() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.DEFAULT; + runConformTest( + new String[] { + "test/package-info.java", + "/**\n" + + " * Javadoc for all package \n" + + " */\n" + + "package test;\n" + } + ); + } + public void testBug95286_Private() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/package-info.java", + "/**\n" + + " * Javadoc for all package \n" + + " */\n" + + "package test;\n" + } + ); + } + + /** + * Bug 95521: [1.5][javadoc] validation with @see tag not working for generic method + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=95521" + */ + public void testBug95521() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "/** Test */\n" + + "public class X implements I {\n" + + " /**\n" + + " * @see test.I#foo(java.lang.Class)\n" + + " */\n" + + " public G foo(Class stuffClass) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "/** Interface */\n" + + "interface I {\n" + + " /**\n" + + " * @param \n" + + " * @param stuffClass \n" + + " * @return stuff\n" + + " */\n" + + " public G foo(Class stuffClass);\n" + + "}\n" + + "/** \n" + + " * @param \n" + + " */\n" + + "class G {}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 8)\n" + + " public G foo(Class stuffClass) {\n" + + " ^\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 G foo(Class stuffClass) {\n" + + " ^\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 G foo(Class stuffClass) {\n" + + " ^\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 \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 19)\n" + + " public G foo(Class stuffClass);\n" + + " ^^^^^^^^^^^^^^^^\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 G foo(Class stuffClass);\n" + + " ^\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 G foo(Class stuffClass);\n" + + " ^\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 \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "9. ERROR in test\\X.java (at line 24)\n" + + " class G {}\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug95521b() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "/** Test */\n" + + "public class X {\n" + + " /**\n" + + " * @param \n" + + " * @param classT \n" + + " */\n" + + " public X(Class classT) {\n" + + " }\n" + + " /**\n" + + " * @param \n" + + " * @param classT\n" + + " * @return classT\n" + + " */\n" + + " public Class foo(Class classT) {\n" + + " return classT;\n" + + " }\n" + + "}\n" + + "/** Super class */\n" + + "class Y extends X {\n" + + " /**\n" + + " * @see X#X(java.lang.Class)\n" + + " */\n" + + " public Y(Class classT) {\n" + + " super(classT);\n" + + " }\n" + + "\n" + + " /**\n" + + " * @see X#foo(java.lang.Class)\n" + + " */\n" + + " public Class foo(Class stuffClass) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @param \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 9)\n" + + " public X(Class classT) {\n" + + " ^\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 X(Class classT) {\n" + + " ^\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 \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 16)\n" + + " public Class foo(Class classT) {\n" + + " ^\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 Class foo(Class classT) {\n" + + " ^\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 Class foo(Class classT) {\n" + + " ^\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 Y(Class classT) {\n" + + " ^\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 Y(Class classT) {\n" + + " ^\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 Y(Class classT) {\n" + + " ^^^^^^\n" + + "Javadoc: Missing tag for parameter classT\n" + + "----------\n" + + "11. ERROR in test\\X.java (at line 32)\n" + + " public Class foo(Class stuffClass) {\n" + + " ^^^^^^^^^^^^^^^^\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 Class foo(Class stuffClass) {\n" + + " ^\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 Class foo(Class stuffClass) {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + + /** + * Bug 101283: [1.5][javadoc] Javadoc validation raises missing implementation in compiler + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=101283" + */ + public void testBug101283a() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @param \n" + + " * @param \n" + + " */\n" + + " static class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\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 \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " static class Entry {\n" + + " ^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug101283b() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @see T Variable \n" + + " * @see F Variable\n" + + " */\n" + + " static class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\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" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @see F Variable\n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " static class Entry {\n" + + " ^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug101283c() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @param \n" + + " * @param \n" + + " */\n" + + " class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\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 \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " class Entry {\n" + + " ^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug101283d() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @see T Variable \n" + + " * @see F Variable\n" + + " */\n" + + " class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\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" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @see F Variable\n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " class Entry {\n" + + " ^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug101283e() { + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @see #foo()\n" + + " */\n" + + "public interface X {\n" + + "\n" + + " public T foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public interface X {\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + // Verify that ProblemReasons.InheritedNameHidesEnclosingName is not reported as Javadoc error + public void testBug101283g() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " int foo() { return 0; }\n" + + " class XX extends X2 {\n" + + " int bar() {\n" + + " return foo();\n" + + " }\n" + + " }\n" + + "}\n" + + "class X2 {\n" + + " int foo() {\n" + + " return 0;\n" + + " }\n" + + "}\n", + "test/Y.java", + "package test;\n" + + "public class Y {\n" + + " int foo;\n" + + " class YY extends Y2 {\n" + + " /**\n" + + " * @see #foo\n" + + " */\n" + + " int bar() {\n" + + " return foo;\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y2 {\n" + + " int foo;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\r\n" + + " return foo();\r\n" + + " ^^^\n" + + "The method foo is defined in an inherited type and an enclosing scope\n" + + "----------\n" + + "----------\n" + + "1. ERROR in test\\Y.java (at line 9)\r\n" + + " return foo;\r\n" + + " ^^^\n" + + "The field foo is defined in an inherited type and an enclosing scope \n" + + "----------\n" + ); + } + + /** + * Bug 112346: [javadoc] {@inheritedDoc} should be inactive for non-overridden method + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=112346" + */ + public void testBug112346() { + runNegativeTest( + new String[] { + "Test.java", + "/**\n" + + " * Test references\n" + + " * @see Test#field\n" + + " * @see Test#foo()\n" + + " */\n" + + "public class Test {\n" + + " T field;\n" + + " T foo() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 6)\n" + + " public class Test {\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + + /** + * Bug 119857: [javadoc] Some inner class references should be flagged as unresolved + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=119857" + */ + public void testBug119857() { + runNegativeTest( + new String[] { + "DefaultInformationControl.java", + "public class DefaultInformationControl {\n" + + " public interface IInformationPresenter {\n" + + " /**\n" + + " * Updates the given presentation of the given information and\n" + + " * thereby may manipulate the information to be displayed. The manipulation\n" + + " * could be the extraction of textual encoded style information etc. Returns the\n" + + " * manipulated information.\n" + + " *\n" + + " * @param hoverInfo the information to be presented\n" + + " * @param maxWidth the maximal width in pixels\n" + + " * @param maxHeight the maximal height in pixels\n" + + " *\n" + + " * @return the manipulated information\n" + + " * @deprecated As of 3.2, replaced by {@link IInformationPresenterExtension#updatePresentation(String, int, int)}\n" + + " * see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38528 for details.\n" + + " */\n" + + " String updatePresentation(String hoverInfo, int maxWidth, int maxHeight);\n" + + " }\n" + + " /**\n" + + " * An information presenter determines the style presentation\n" + + " * of information displayed in the default information control.\n" + + " * The interface can be implemented by clients.\n" + + " * \n" + + " * @since 3.2\n" + + " */\n" + + " public interface IInformationPresenterExtension {\n" + + " \n" + + " /**\n" + + " * Updates the given presentation of the given information and\n" + + " * thereby may manipulate the information to be displayed. The manipulation\n" + + " * could be the extraction of textual encoded style information etc. Returns the\n" + + " * manipulated information.\n" + + " *

    \n" + + " * Replaces {@link IInformationPresenter#updatePresentation(String, int, int)}\n" + + " * Make sure that you do not pass in a Display until\n" + + " * https://bugs.eclipse.org/bugs/show_bug.cgi?id=38528 is fixed.\n" + + " *

    \n" + + " *\n" + + " * @param hoverInfo the information to be presented\n" + + " * @param maxWidth the maximal width in pixels\n" + + " * @param maxHeight the maximal height in pixels\n" + + " *\n" + + " * @return the manipulated information\n" + + " */\n" + + " String updatePresentation(String hoverInfo, int maxWidth, int maxHeight);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in DefaultInformationControl.java (at line 14)\n" + + " * @deprecated As of 3.2, replaced by {@link IInformationPresenterExtension#updatePresentation(String, int, int)}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in DefaultInformationControl.java (at line 34)\n" + + " * Replaces {@link IInformationPresenter#updatePresentation(String, int, int)}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug119857_Fields() { + runNegativeTest( + new String[] { + "TestFields.java", + "/**\n" + + " * @see MyInnerClass#foo\n" + + " */\n" + + "public class TestFields {\n" + + " /**\n" + + " * @see MyInnerClass#foo\n" + + " */\n" + + " public class MyInnerClass {\n" + + " Object foo;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in TestFields.java (at line 6)\n" + + " * @see MyInnerClass#foo\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug119857_Methods() { + runNegativeTest( + new String[] { + "TestMethods.java", + "/**\n" + + " * @see MyInnerClass#foo()\n" + + " * @see MyInnerInterface#foo()\n" + + " */\n" + + "public class TestMethods {\n" + + " /**\n" + + " * @see MyInnerInterface#foo()\n" + + " */\n" + + " public class MyInnerClass {\n" + + " public void foo() {}\n" + + " }\n" + + " /**\n" + + " * @see MyInnerClass#foo()\n" + + " */\n" + + " public interface MyInnerInterface {\n" + + " public void foo();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in TestMethods.java (at line 7)\n" + + " * @see MyInnerInterface#foo()\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in TestMethods.java (at line 13)\n" + + " * @see MyInnerClass#foo()\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug119857_Types() { + runNegativeTest( + new String[] { + "TestTypes.java", + "/**\n" + + " * @see MyInnerClass\n" + + " * @see MyInnerInterface\n" + + " */\n" + + "public class TestTypes {\n" + + " /**\n" + + " * @see MyInnerInterface\n" + + " */\n" + + " public class MyInnerClass {\n" + + " public void foo() {}\n" + + " }\n" + + " /**\n" + + " * @see MyInnerClass\n" + + " */\n" + + " public interface MyInnerInterface {\n" + + " public void foo();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in TestTypes.java (at line 7)\n" + + " * @see MyInnerInterface\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in TestTypes.java (at line 13)\n" + + " * @see MyInnerClass\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug119857_Private01() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " static class Inner {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " public Inner field;\n" + + " /** \n" + + " * @see Inner#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug119857_Public01() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " static class Inner {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " public Inner field;\n" + + " /** \n" + + " * @see Inner#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + "}\n" + }, + //pack/Test.java:13: warning - Tag @see: reference not found: Inner1#foo() + "----------\n" + + "1. ERROR in pack\\Test.java (at line 8)\r\n" + + " * @see Inner#foo()\r\n" + + " ^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + + "----------\n" + ); + } + public void testBug119857_Private02() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "test/Test.java", + "package test;\n" + + "public class Test {\n" + + " static class Inner1 {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " static class Inner2 {\n" + + " public Inner1 field;\n" + + " /** \n" + + " * @see Inner1#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + " }\n" + + "}\n" + }, + //pack\Test2.java:11: warning - Tag @see: reference not found: Inner1#foo() + "----------\n" + + "1. ERROR in test\\Test.java (at line 9)\r\n" + + " * @see Inner1#foo()\r\n" + + " ^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug119857_Public02() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "public class Test {\n" + + " static class Inner1 {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " static class Inner2 {\n" + + " public Inner1 field;\n" + + " /** \n" + + " * @see Inner1#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug119857_Public03() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " static class Inner1 {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " public static class Inner2 {\n" + + " public Inner1 field;\n" + + " /** \n" + + " * @see Inner1#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + " }\n" + + "}\n" + }, + //pack/Test.java:13: warning - Tag @see: reference not found: Inner1#foo() + "----------\n" + + "1. ERROR in pack\\Test.java (at line 9)\n" + + " * @see Inner1#foo()\n" + + " ^^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + + "----------\n" + ); + } + + /** + * Bug 145007: [1.5][javadoc] Generics + Inner Class -> Javadoc "missing @throws" warning + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=145007" + */ + public void testBug145007() { + runNegativeTest( + new String[] { + "TestClass.java", + "class TestClass {\n" + + " static class Test1 {\n" + + " /**\n" + + " * A simple method that demonstrates tag problems\n" + + " * \n" + + " * @return a string\n" + + " * @throws MyException\n" + + " * if something goes wrong\n" + + " */\n" + + " public String getString() throws MyException {\n" + + " throw new MyException();\n" + + " }\n" + + " }\n" + + "\n" + + " static class MyException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in TestClass.java (at line 1)\r\n" + + " class TestClass {\r\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_4.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_4.java new file mode 100644 index 0000000000..62950975b4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_4.java @@ -0,0 +1,3570 @@ +/******************************************************************************* + * Copyright (c) 2000, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTest_1_4 extends JavadocTest { + + String docCommentSupport = CompilerOptions.ENABLED; + String reportInvalidJavadoc = CompilerOptions.ERROR; + String reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + String reportMissingJavadocTags = CompilerOptions.ERROR; + String reportMissingJavadocComments = null; + String reportMissingJavadocCommentsVisibility = null; + + public JavadocTest_1_4(String name) { + super(name); + } + + public static Class testClass() { + return JavadocTest_1_4.class; + } + + // Use this static initializer to specify subset for tests + // All specified tests which does not belong to the class are skipped... + static { +// TESTS_PREFIX = "testBug95521"; +// TESTS_NAMES = new String[] { +// "testBug70892conform1", "testBug70892conform2" +// }; +// TESTS_NUMBERS = new int[] { 101283 }; +// TESTS_RANGE = new int[] { 21, 50 }; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_4); + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, this.docCommentSupport); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, this.reportInvalidJavadoc); + if (!CompilerOptions.IGNORE.equals(this.reportInvalidJavadoc)) { + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, this.reportInvalidJavadocVisibility); + } + if (this.reportMissingJavadocComments != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + else + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportInvalidJavadoc); + if (this.reportMissingJavadocCommentsVisibility != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsVisibility, this.reportMissingJavadocCommentsVisibility); + if (this.reportMissingJavadocTags != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportMissingJavadocTags); + else + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportInvalidJavadoc); + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + return options; + } + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.docCommentSupport = CompilerOptions.ENABLED; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + } + + + /** + * Test fix for bug 70891: [1.5][javadoc] Compiler should accept new 1.5 syntax for @param + * @see 70891 + * These two tests fail for 1.5 source level but should pass for 1.3 or 1.4 + * @see JavadocTest_1_4 + */ + /* (non-Javadoc) + * Test @param for generic class type parameter + */ + public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " * @param Type\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\r\n" + + " public class X {}\r\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type extends RuntimeException\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " * @param Type extends RuntimeException\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\r\n" + + " public class X {}\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + + ); + } + public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " * @param Type parameter 1\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\r\n" + + " * @param Type parameter 2\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\r\n" + + " * @param Type parameter 3\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\r\n" + + " public class X {}\r\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter\n" + + " */\n" + + " public class X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + ); + } + public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter\n" + + " */\n" + + " public class X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\r\n" + + " * @param Type parameter 3\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\r\n" + + " * @param Type parameter 2\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\r\n" + + " * @param Type parameter 1\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\r\n" + + " public class X {}\r\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test019() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 2\n" + + " * @param\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test021() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, insert \"ClassBody\" to complete CompilationUnit\n" + + "----------\n" + ); + } + public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, insert \"ClassBody\" to complete CompilationUnit\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^^^^^^\n" + + "extend cannot be resolved to a type\n" + + "----------\n" + ); + } + + /* (non-Javadoc) + * Test @param for generic method type parameter + */ + public void test023() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type\n" + + " */\n" + + " public void foo() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " * @param Type\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\r\n" + + " public void foo() {}\r\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type extends RuntimeException\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " * @param Type extends RuntimeException\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\r\n" + + " public void foo(int val, Object obj) {}\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test025() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\r\n" + + " * @param Type parameter 1\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\r\n" + + " * @param Type parameter 2\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\r\n" + + " * @param Type parameter 3\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\r\n" + + " public void foo(int val, Object obj) {}\r\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param val int\n" + + " * @param Type parameter\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param Type parameter\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + ); + } + public void test027() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + public void test028() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " * @param xxx int\n" + + " * @param Obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " * @param xxx int\n" + + " ^^^\n" + + "Javadoc: Parameter xxx is not declared\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " * @param Obj Object\n" + + " ^^^\n" + + "Javadoc: Parameter Obj is not declared\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "8. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + public void test029() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param val int\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param obj Object\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test030() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param obj Object\n" + + " * @param Type parameter 2\n" + + " * @param val int\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " * @param Type parameter 3\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\r\n" + + " * @param Type parameter 2\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\r\n" + + " * @param Type parameter 1\r\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\r\n" + + " public void foo(int val, Object obj) {}\r\n" + + " ^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test031() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + public void test032() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param val int\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + public void test033() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param obj Object\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 3\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + ); + } + public void test034() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param val int\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param Object obj\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param val int\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @param Object obj\n" + + " ^^^^^^\n" + + "Javadoc: Parameter Object is not declared\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " * @param val int\n" + + " ^^^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + public void test035() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 2\n" + + " * @param\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n" + ); + } + // TODO (david) recovery seems not to work properly here: + // we should have type parameters in method declaration. + public void test036() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + ); + } + public void test037() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 1\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\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 void foo(int val, Object obj) {}\n" + + " ^^^^^^^^^^\n" + + "Exceptions cannot be resolved to a type\n" + + "----------\n" + ); + } + public void test038() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param < Type\n" + + " * @param < Type for parameterization\n" + + " * @param <> Type\n" + + " * @param Type\n" + + " * @param <*> Type\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param < Type\n" + + " ^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param < Type for parameterization\n" + + " ^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param <> Type\n" + + " ^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param Type\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param <*> Type\n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type\n" + + " * @param < Type\n" + + " * @param << Type\n" + + " * @param > Type\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type\n" + + " ^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param < Type\n" + + " ^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param << Type\n" + + " ^^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param > Type\n" + + " ^^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + + public void test040() { + runConformReferenceTest( + new String[] { + "X.java", + "/**\n" + + " * @category\n" + + " */\n" + + "public class X {\n" + + "}\n" + } + ); + } + + /** + * Test fix for bug 80257: [javadoc] Invalid missing reference warning on @see or @link tags + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=80257" + */ + public void testBug80257() { + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @see G#G(Object)\n" + + " * @see G#G(Exception)\n" + + " */\n" + + "public class X extends G {\n" + + " X(Exception exc) { super(exc);}\n" + + "}\n" + + "class G {\n" + + " G(E e) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " * @see G#G(Object)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor G(Object) is undefined\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X extends G {\n" + + " ^^^^^^^^^\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 {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + + /** + * Test fix for bug 82514: [1.5][javadoc] Problem with generics in javadoc + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=82514" + */ + public void testBug82514() { + this.runNegativeTest( + new String[] { + "X.java", + "class ComparableUtils {\n" + + " public static > int compareTo(final Object first, final Object firstPrime, final Class type) throws ClassCastException\n" + + " {\n" + + " return 0;\n" + + " }\n" + + " public static > int compareTo(final X first, final X firstPrime)\n" + + " throws ClassCastException\n" + + " {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public final class X { \n" + + " /** Tests the method{@link ComparableUtils#compareTo(Object, Object, Class)} and\n" + + " * {@link ComparableUtils#compareTo(Object, Object)}.\n" + + " */\n" + + " public void testCompareTo() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static > int compareTo(final Object first, final Object firstPrime, final Class type) throws ClassCastException\n" + + " ^^^^^^^^^^^^^^^^^^^^\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 > int compareTo(final Object first, final Object firstPrime, final Class type) throws ClassCastException\n" + + " ^\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 > int compareTo(final X first, final X firstPrime)\n" + + " ^^^^^^^^^^^^^^^^^^^^\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 > int compareTo(final X first, final X firstPrime)\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " * {@link ComparableUtils#compareTo(Object, Object)}.\n" + + " ^^^^^^^^^\n" + + "Javadoc: The method compareTo(Object, Object, Class) in the type ComparableUtils is not applicable for the arguments (Object, Object)\n" + + "----------\n"); + } + + /** + * Test fix for bug 83127: [1.5][javadoc][dom] Wrong / strange bindings for references in javadoc to methods with type variables as parameter types + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83127" + */ + public void testBug83127a() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Test.java", + "/** \n" + + " * @see Test#add(T) \n" + + " * @see #add(T)\n" + + " * @see Test#Test(T)\n" + + " * @see #Test(T)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (T)\"\n" + + " * - method binding = Test.add(Object)\n" + + " * - parameter binding = T of A\n" + + " */\n" + + "public class Test {\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Test#add(T) \n" + + " ^^^\n" + + "Javadoc: The method add(Object) in the type Test is not applicable for the arguments (T)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see #add(T)\n" + + " ^^^\n" + + "Javadoc: The method add(Object) in the type Test is not applicable for the arguments (T)\n" + + "----------\n" + + "3. ERROR in Test.java (at line 4)\n" + + " * @see Test#Test(T)\n" + + " ^^^^^^^\n" + + "Javadoc: The constructor Test(T) is undefined\n" + + "----------\n" + + "4. ERROR in Test.java (at line 5)\n" + + " * @see #Test(T)\n" + + " ^^^^^^^\n" + + "Javadoc: The constructor Test(T) is undefined\n" + + "----------\n" + + "5. ERROR in Test.java (at line 11)\n" + + " public class Test {\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127b() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Test.java", + "/** \n" + + " * @see Sub#add(T)\n" + + " * @see Sub#Sub(T)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (T)\"\n" + + " * - method binding = Test.add(Object)\n" + + " * - parameter binding = T of A\n" + + " * -> Do we need to change this as T natually resolved to TypeVariable?\n" + + " * As compiler raises a warning, it\'s perhaps not a problem now...\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Sub#add(T)\n" + + " ^^^\n" + + "Javadoc: The method add(Number) in the type Sub is not applicable for the arguments (T)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Sub#Sub(T)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor Sub(T) is undefined\n" + + "----------\n" + + "3. ERROR in Test.java (at line 11)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127c() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Test.java", + "/** \n" + + " * @see Sub#add(E) \n" + + " * @see Sub#Sub(E)\n" + + " * - warning = \"E cannot be resolved to a type\"\n" + + " * - method binding = null\n" + + " * - parameter binding = null\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Sub#add(E) \n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Sub#Sub(E)\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in Test.java (at line 8)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127d() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(E)\n" + + " * @see Unrelated1#Unrelated1(E)\n" + + " * - warning = \"E cannot be resolved to a type\"\n" + + " * - method binding = null\n" + + " * - parameter binding = null\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unrelated1.java (at line 1)\n" + + " public class Unrelated1 {\n" + + " ^^^^^^^^^^^^^^^^\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" + + " * @see Unrelated1#add(E)\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Unrelated1#Unrelated1(E)\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in Test.java (at line 8)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127e() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(Object)\n" + + " * @see Unrelated1#Unrelated1(Object)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (Object)\"\n" + + " * - method binding = Unrelated1.add(Number)\n" + + " * - parameter binding = java.lang.Object\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unrelated1.java (at line 1)\n" + + " public class Unrelated1 {\n" + + " ^^^^^^^^^^^^^^^^\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" + + " * @see Unrelated1#add(Object)\n" + + " ^^^\n" + + "Javadoc: The method add(Number) in the type Unrelated1 is not applicable for the arguments (Object)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Unrelated1#Unrelated1(Object)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The constructor Unrelated1(Object) is undefined\n" + + "----------\n" + + "3. ERROR in Test.java (at line 9)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127f() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(Number)\n" + + " * @see Unrelated1#Unrelated1(Number)\n" + + " * - no warning\n" + + " * - method binding = Unrelated1.add(Number)\n" + + " * - parameter binding = java.lang.Number\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unrelated1.java (at line 1)\n" + + " public class Unrelated1 {\n" + + " ^^^^^^^^^^^^^^^^\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{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127g() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(Integer)\n" + + " * @see Unrelated1#Unrelated1(Integer)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (Integer)\"\n" + + " * - method binding = Unrelated1.add(Number)\n" + + " * - parameter binding = java.lang.Integer\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unrelated1.java (at line 1)\n" + + " public class Unrelated1 {\n" + + " ^^^^^^^^^^^^^^^^\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" + + " * @see Unrelated1#add(Integer)\n" + + " ^^^\n" + + "Javadoc: The method add(Number) in the type Unrelated1 is not applicable for the arguments (Integer)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Unrelated1#Unrelated1(Integer)\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The constructor Unrelated1(Integer) is undefined\n" + + "----------\n" + + "3. ERROR in Test.java (at line 9)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + public void testBug83127h() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated2.java", + "public interface Unrelated2 {\n" + + " boolean add(E e);\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated2#add(T)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (T)\"\n" + + " * - method binding = Unrelated2.add(Object)\n" + + " * - parameter binding = T of A\n" + + " * -> Do we need to change this as T natually resolved to TypeVariable?\n" + + " * As compiler raises a warning, it\'s perhaps not a problem now...\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unrelated2.java (at line 1)\n" + + " public interface Unrelated2 {\n" + + " ^\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" + + " * @see Unrelated2#add(T)\n" + + " ^^^\n" + + "Javadoc: The method add(Object) in the type Unrelated2 is not applicable for the arguments (T)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 10)\n" + + " public class Test{\n" + + " ^\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 extends Test {\n" + + " ^^^^^^^^^^^^^^^^\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 extends Test {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + + /** + * Bug 83393: [1.5][javadoc] reference to vararg method also considers non-array type as correct + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83393" + */ + public void testBug83393a() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public void foo(int a, int b) {} \n" + + " public void foo(int a, int... args) {}\n" + + " public void foo(String... args) {}\n" + + " public void foo(Exception str, boolean... args) {}\n" + + "}\n", + "Valid.java", + "/**\n" + + " * @see Test#foo(int, int)\n" + + " * @see Test#foo(int, int[])\n" + + " * @see Test#foo(int, int...)\n" + + " * @see Test#foo(String[])\n" + + " * @see Test#foo(String...)\n" + + " * @see Test#foo(Exception, boolean[])\n" + + " * @see Test#foo(Exception, boolean...)\n" + + " */\n" + + "public class Valid {}\n" + }, + "----------\n" + + "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 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 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 or greater\n" + + "----------\n" + ); + } + public void testBug83393b() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public void foo(int a, int b) {} \n" + + " public void foo(int a, int... args) {}\n" + + " public void foo(String... args) {}\n" + + " public void foo(Exception str, boolean... args) {}\n" + + "}\n", + "Invalid.java", + "/**\n" + + " * @see Test#foo(int)\n" + + " * @see Test#foo(int, int, int)\n" + + " * @see Test#foo()\n" + + " * @see Test#foo(String)\n" + + " * @see Test#foo(String, String)\n" + + " * @see Test#foo(Exception)\n" + + " * @see Test#foo(Exception, boolean)\n" + + " * @see Test#foo(Exception, boolean, boolean)\n" + + " */\n" + + "public class Invalid {}\n" + }, + "----------\n" + + "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 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 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 or greater\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Invalid.java (at line 2)\n" + + " * @see Test#foo(int)\n" + + " ^^^\n" + + "Javadoc: The method foo(int, int) in the type Test is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in Invalid.java (at line 3)\n" + + " * @see Test#foo(int, int, int)\n" + + " ^^^\n" + + "Javadoc: The method foo(int, int) in the type Test is not applicable for the arguments (int, int, int)\n" + + "----------\n" + + "3. ERROR in Invalid.java (at line 4)\n" + + " * @see Test#foo()\n" + + " ^^^\n" + + "Javadoc: The method foo(String[]) in the type Test is not applicable for the arguments ()\n" + + "----------\n" + + "4. ERROR in Invalid.java (at line 5)\n" + + " * @see Test#foo(String)\n" + + " ^^^\n" + + "Javadoc: The method foo(String[]) in the type Test is not applicable for the arguments (String)\n" + + "----------\n" + + "5. ERROR in Invalid.java (at line 6)\n" + + " * @see Test#foo(String, String)\n" + + " ^^^\n" + + "Javadoc: The method foo(int, int) in the type Test is not applicable for the arguments (String, String)\n" + + "----------\n" + + "6. ERROR in Invalid.java (at line 7)\n" + + " * @see Test#foo(Exception)\n" + + " ^^^\n" + + "Javadoc: The method foo(Exception, boolean[]) in the type Test is not applicable for the arguments (Exception)\n" + + "----------\n" + + "7. ERROR in Invalid.java (at line 8)\n" + + " * @see Test#foo(Exception, boolean)\n" + + " ^^^\n" + + "Javadoc: The method foo(Exception, boolean[]) in the type Test is not applicable for the arguments (Exception, boolean)\n" + + "----------\n" + + "8. ERROR in Invalid.java (at line 9)\n" + + " * @see Test#foo(Exception, boolean, boolean)\n" + + " ^^^\n" + + "Javadoc: The method foo(Exception, boolean[]) in the type Test is not applicable for the arguments (Exception, boolean, boolean)\n" + + "----------\n" + ); + } + + /** + * Bug 83804: [1.5][javadoc] Missing Javadoc node for package declaration + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83804" + */ + public void testBug83804() { + runNegativeTest( + new String[] { + "pack/package-info.java", + "/**\n" + + " * Valid javadoc.\n" + + " * @see Test\n" + + " * @see Unknown\n" + + " * @see Test#foo()\n" + + " * @see Test#unknown()\n" + + " * @see Test#field\n" + + " * @see Test#unknown\n" + + " * @param unexpected\n" + + " * @throws unexpected\n" + + " * @return unexpected \n" + + " * @deprecated accepted by javadoc.exe although javadoc 1.5 spec does not say that's a valid tag\n" + + " * @other-tags are valid\n" + + " */\n" + + "package pack;\n", + "pack/Test.java", + "/**\n" + + " * Invalid javadoc\n" + + " */\n" + + "package pack;\n" + + "public class Test {\n" + + " public int field;\n" + + " public void foo() {}\n" + + "}\n" + }, + "" + ); + } + + /** + * Bug 86769: [javadoc] Warn/Error for 'Missing javadoc comments' doesn't recognize private inner classes + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=86769" + */ + public void testBug86769() { + + /* Deleted a completely meaningless test that could only serve as a torture test for the parser. + The test is still run in 1.5+ modes where it makes sense to run it - The test here was a nuisance + failing every time there is some serious grammar change that alters the semi-random behavior in + Diagnose Parser. + */ + return; + } + + /** + * Bug 95286: [1.5][javadoc] package-info.java incorrectly flags "Missing comment for public declaration" + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=95286" + */ + public void testBug95286_Default() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.DEFAULT; + runConformTest( + new String[] { + "test/package-info.java", + "/**\n" + + " * Javadoc for all package \n" + + " */\n" + + "package test;\n" + } + ); + } + public void testBug95286_Private() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/package-info.java", + "/**\n" + + " * Javadoc for all package \n" + + " */\n" + + "package test;\n" + } + ); + } + + /** + * Bug 95521: [1.5][javadoc] validation with @see tag not working for generic method + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=95521" + */ + public void testBug95521() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "/** Test */\n" + + "public class X implements I {\n" + + " /**\n" + + " * @see test.I#foo(java.lang.Class)\n" + + " */\n" + + " public G foo(Class stuffClass) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "/** Interface */\n" + + "interface I {\n" + + " /**\n" + + " * @param \n" + + " * @param stuffClass \n" + + " * @return stuff\n" + + " */\n" + + " public G foo(Class stuffClass);\n" + + "}\n" + + "/** \n" + + " * @param \n" + + " */\n" + + "class G {}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 8)\n" + + " public G foo(Class stuffClass) {\n" + + " ^\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 G foo(Class stuffClass) {\n" + + " ^\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 G foo(Class stuffClass) {\n" + + " ^\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 \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 19)\n" + + " public G foo(Class stuffClass);\n" + + " ^^^^^^^^^^^^^^^^\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 G foo(Class stuffClass);\n" + + " ^\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 G foo(Class stuffClass);\n" + + " ^\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 \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "9. ERROR in test\\X.java (at line 24)\n" + + " class G {}\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug95521b() { + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "/** Test */\n" + + "public class X {\n" + + " /**\n" + + " * @param \n" + + " * @param classT \n" + + " */\n" + + " public X(Class classT) {\n" + + " }\n" + + " /**\n" + + " * @param \n" + + " * @param classT\n" + + " * @return classT\n" + + " */\n" + + " public Class foo(Class classT) {\n" + + " return classT;\n" + + " }\n" + + "}\n" + + "/** Super class */\n" + + "class Y extends X {\n" + + " /**\n" + + " * @see X#X(java.lang.Class)\n" + + " */\n" + + " public Y(Class classT) {\n" + + " super(classT);\n" + + " }\n" + + "\n" + + " /**\n" + + " * @see X#foo(java.lang.Class)\n" + + " */\n" + + " public Class foo(Class stuffClass) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " * @param \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 9)\n" + + " public X(Class classT) {\n" + + " ^\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 X(Class classT) {\n" + + " ^\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 \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 16)\n" + + " public Class foo(Class classT) {\n" + + " ^\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 Class foo(Class classT) {\n" + + " ^\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 Class foo(Class classT) {\n" + + " ^\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 Y(Class classT) {\n" + + " ^\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 Y(Class classT) {\n" + + " ^\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 Y(Class classT) {\n" + + " ^^^^^^\n" + + "Javadoc: Missing tag for parameter classT\n" + + "----------\n" + + "11. ERROR in test\\X.java (at line 32)\n" + + " public Class foo(Class stuffClass) {\n" + + " ^^^^^^^^^^^^^^^^\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 Class foo(Class stuffClass) {\n" + + " ^\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 Class foo(Class stuffClass) {\n" + + " ^\n" + + "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + + /** + * Bug 96237: [javadoc] Inner types must be qualified + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=96237" + */ + public void testBug96237_Public01() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runConformTest( + new String[] { + "comment6/Valid.java", + "package comment6;\n" + + "public class Valid {\n" + + " /**\n" + + " * @see Valid.Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Valid.Inner}\n" + + " */\n" + + "class Sub2 extends Valid { }" + } + ); + } + public void testBug96237_Public02() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "comment6/Invalid.java", + "package comment6;\n" + + "public class Invalid {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Inner} \n" + + " */\n" + + "class Sub1 extends Invalid { }\n" + }, + //comment6\Invalid.java:6: warning - Tag @see: reference not found: Inner + "----------\n" + + "1. ERROR in comment6\\Invalid.java (at line 4)\r\n" + + " * @see Inner\r\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Public03() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "comment6a/def/Test.java", + "package comment6a.def;\n" + + "public class Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6a/test/Invalid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * See also {@link Inner}\n" + + " */\n" + + "public class Invalid extends Test { \n" + + "}", + "comment6a/test/Invalid2.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Invalid2 extends Test { \n" + + "}", + "comment6a/test/Valid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see comment6a.def.Test.Inner\n" + + " */\n" + + "public class Valid extends Test { \n" + + "}" + }, + //comment6a\def\Test.java:6: warning - Tag @see: reference not found: Inner + //comment6a\test\Invalid.java:8: warning - Tag @link: reference not found: Inner + //comment6a\test\Invalid2.java:8: warning - Tag @see: reference not found: Test.Inner => bug ID: 4464323 + "----------\n" + + "1. ERROR in comment6a\\def\\Test.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid.java (at line 4)\n" + + " * See also {@link Inner}\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid2.java (at line 4)\n" + + " * @see Test.Inner\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Public04() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "comment6b/Invalid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Inner\n" + + " */\n" + + "public class Invalid implements Test { \n" + + "}", + "comment6b/Test.java", + "package comment6b;\n" + + "public interface Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6b/Valid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Valid implements Test { \n" + + "}" + }, + //comment6b\Test.java:6: warning - Tag @see: reference not found: Inner + //comment6b\Invalid.java:6: warning - Tag @see: reference not found: Inner + "----------\n" + + "1. ERROR in comment6b\\Invalid.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6b\\Test.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Public05() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/a/Test.java", + "package test.a;\n" + + "/**\n" + + " * @see Inner\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Test {\n" + + " class Inner {}\n" + + "}\n" + }, + //test\a\Test.java:6: warning - Tag @see: reference not found: Inner + //test\a\Test.java:6: warning - Tag @see: reference not found: Test.Inner + "----------\n" + + "1. ERROR in test\\a\\Test.java (at line 3)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\a\\Test.java (at line 4)\n" + + " * @see Test.Inner\n" + + " ^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + ); + } + public void testBug96237_Public06() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/b/Test.java", + "package test.b;\n" + + "/** \n" + + " * @see Inner.Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + "public class Test {\n" + + " /** \n" + + " * @see Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + " public class Inner {\n" + + " class Level2 {}\n" + + " }\n" + + "}\n" + }, + //test\b\Test.java:6: warning - Tag @see: reference not found: Inner.Level2 + //test\b\Test.java:6: warning - Tag @see: reference not found: Test.Inner.Level2 + //test\b\Test.java:11: warning - Tag @see: reference not found: Level2 + //test\b\Test.java:11: warning - Tag @see: reference not found: Test.Inner.Level2 + "----------\n" + + "1. ERROR in test\\b\\Test.java (at line 3)\n" + + " * @see Inner.Level2\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\b\\Test.java (at line 4)\n" + + " * @see Test.Inner.Level2\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "3. ERROR in test\\b\\Test.java (at line 8)\n" + + " * @see Level2\n" + + " ^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "4. ERROR in test\\b\\Test.java (at line 9)\n" + + " * @see Test.Inner.Level2\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + ); + } + public void testBug96237_Public07() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/c/Test.java", + "package test.c;\n" + + "/**\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * @see Level3\n" + + " * @see Level2.Level3\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + " public class Level2 {\n" + + " class Level3 {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + //test\c\Test.java:6: warning - Tag @see: reference not found: Inner.Level2.Level3 + //test\c\Test.java:6: warning - Tag @see: reference not found: Test.Inner.Level2.Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Level2.Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Inner.Level2.Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Test.Inner.Level2.Level3 + "----------\n" + + "1. ERROR in test\\c\\Test.java (at line 3)\n" + + " * @see Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\c\\Test.java (at line 4)\n" + + " * @see Test.Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "3. ERROR in test\\c\\Test.java (at line 9)\n" + + " * @see Level3\n" + + " ^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "4. ERROR in test\\c\\Test.java (at line 10)\n" + + " * @see Level2.Level3\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "5. ERROR in test\\c\\Test.java (at line 11)\n" + + " * @see Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "6. ERROR in test\\c\\Test.java (at line 12)\n" + + " * @see Test.Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + ); + } + public void testBug96237_Public08() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/d/Reference.java", + "package test.d;\n" + + "class Reference {\n" + + "}\n", + "test/d/Test.java", + "package test.d;\n" + + "/**\n" + + " * @see Secondary\n" + + " * @see Reference\n" + + " */\n" + + "public class Test {\n" + + "}\n" + + "class Secondary {}" + }, + "----------\n" + + "1. ERROR in test\\d\\Test.java (at line 3)\n" + + " * @see Secondary\n" + + " ^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\d\\Test.java (at line 4)\n" + + " * @see Reference\n" + + " ^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + ); + } + public void testBug96237_Private01() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "comment6/Valid.java", + "package comment6;\n" + + "public class Valid {\n" + + " /**\n" + + " * @see Valid.Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Valid.Inner}\n" + + " */\n" + + "class Sub2 extends Valid { }" + } + ); + } + public void testBug96237_Private02() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runNegativeTest( + new String[] { + "comment6/Invalid.java", + "package comment6;\n" + + "public class Invalid {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Inner} \n" + + " */\n" + + "class Sub1 extends Invalid { }\n" + }, + //comment6\Invalid.java:6: warning - Tag @see: reference not found: Inner + //comment6\Invalid.java:11: warning - Tag @link: reference not found: Inner + "----------\n" + + "1. ERROR in comment6\\Invalid.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in comment6\\Invalid.java (at line 9)\n" + + " * See also {@link Inner} \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Private03() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runNegativeTest( + new String[] { + "comment6a/def/Test.java", + "package comment6a.def;\n" + + "public class Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6a/test/Invalid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * See also {@link Inner}\n" + + " */\n" + + "public class Invalid extends Test { \n" + + "}", + "comment6a/test/Invalid2.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Invalid2 extends Test { \n" + + "}", + "comment6a/test/Valid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see comment6a.def.Test.Inner\n" + + " */\n" + + "public class Valid extends Test { \n" + + "}" + }, + //comment6a\def\Test.java:6: warning - Tag @see: reference not found: Inner + //comment6a\test\Invalid.java:8: warning - Tag @link: reference not found: Inner + //comment6a\test\Invalid2.java:8: warning - Tag @see: reference not found: Test.Inner => bug ID: 4464323 + "----------\n" + + "1. ERROR in comment6a\\def\\Test.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid.java (at line 4)\n" + + " * See also {@link Inner}\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid2.java (at line 4)\n" + + " * @see Test.Inner\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Private04() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runNegativeTest( + new String[] { + "comment6b/Invalid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Inner\n" + + " */\n" + + "public class Invalid implements Test { \n" + + "}", + "comment6b/Test.java", + "package comment6b;\n" + + "public interface Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6b/Valid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Valid implements Test { \n" + + "}" + }, + //comment6b\Invalid.java:6: warning - Tag @see: reference not found: Inner + //comment6b\Test.java:6: warning - Tag @see: reference not found: Inner + "----------\n" + + "1. ERROR in comment6b\\Invalid.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6b\\Test.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug96237_Private05() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/a/Test.java", + "package test.a;\n" + + "/**\n" + + " * @see Inner\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Test {\n" + + " class Inner {}\n" + + "}\n" + } + ); + } + public void testBug96237_Private06() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/b/Test.java", + "package test.b;\n" + + "/** \n" + + " * @see Inner.Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + "public class Test {\n" + + " /** \n" + + " * @see Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + " public class Inner {\n" + + " class Level2 {}\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug96237_Private07() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/c/Test.java", + "package test.c;\n" + + "/**\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * @see Level3\n" + + " * @see Level2.Level3\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + " public class Level2 {\n" + + " class Level3 {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug96237_Private08() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/d/Reference.java", + "package test.d;\n" + + "class Reference {\n" + + "}\n", + "test/d/Test.java", + "package test.d;\n" + + "/**\n" + + " * @see Secondary\n" + + " * @see Reference\n" + + " */\n" + + "public class Test {\n" + + "}\n" + + "class Secondary {}" + } + ); + } + + /** + * Bug 101283: [1.5][javadoc] Javadoc validation raises missing implementation in compiler + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=101283" + */ + public void testBug101283a() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @param \n" + + " * @param \n" + + " */\n" + + " static class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\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 \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " static class Entry {\n" + + " ^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug101283b() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @see T Variable \n" + + " * @see F Variable\n" + + " */\n" + + " static class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\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" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @see F Variable\n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " static class Entry {\n" + + " ^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug101283c() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @param \n" + + " * @param \n" + + " */\n" + + " class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\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 \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param \n" + + " ^^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " class Entry {\n" + + " ^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug101283d() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @see T Variable \n" + + " * @see F Variable\n" + + " */\n" + + " class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^^^^\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" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @see F Variable\n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " class Entry {\n" + + " ^^^^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + public void testBug101283e() { + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @see #foo()\n" + + " */\n" + + "public interface X {\n" + + "\n" + + " public T foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public interface X {\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } + // Verify that ProblemReasons.InheritedNameHidesEnclosingName is not reported as Javadoc error + public void testBug101283g() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " int foo() { return 0; }\n" + + " class XX extends X2 {\n" + + " int bar() {\n" + + " return foo();\n" + + " }\n" + + " }\n" + + "}\n" + + "class X2 {\n" + + " int foo() {\n" + + " return 0;\n" + + " }\n" + + "}\n", + "test/Y.java", + "package test;\n" + + "public class Y {\n" + + " int foo;\n" + + " class YY extends Y2 {\n" + + " /**\n" + + " * @see #foo\n" + + " */\n" + + " int bar() {\n" + + " return foo;\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y2 {\n" + + " int foo;\n" + + "}\n" + } + ); + } + + /** + * Bug 112346: [javadoc] {@inheritedDoc} should be inactive for non-overridden method + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=112346" + */ + public void testBug112346() { + runNegativeTest( + new String[] { + "Test.java", + "/**\n" + + " * Test references\n" + + " * @see Test#field\n" + + " * @see Test#foo()\n" + + " */\n" + + "public class Test {\n" + + " T field;\n" + + " T foo() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 6)\n" + + " public class Test {\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n"); + } + + /** + * Bug 119857: [javadoc] Some inner class references should be flagged as unresolved + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=119857" + */ + public void testBug119857() { + runNegativeTest( + new String[] { + "DefaultInformationControl.java", + "public class DefaultInformationControl {\n" + + " public interface IInformationPresenter {\n" + + " /**\n" + + " * Updates the given presentation of the given information and\n" + + " * thereby may manipulate the information to be displayed. The manipulation\n" + + " * could be the extraction of textual encoded style information etc. Returns the\n" + + " * manipulated information.\n" + + " *\n" + + " * @param hoverInfo the information to be presented\n" + + " * @param maxWidth the maximal width in pixels\n" + + " * @param maxHeight the maximal height in pixels\n" + + " *\n" + + " * @return the manipulated information\n" + + " * @deprecated As of 3.2, replaced by {@link IInformationPresenterExtension#updatePresentation(String, int, int)}\n" + + " * see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38528 for details.\n" + + " */\n" + + " String updatePresentation(String hoverInfo, int maxWidth, int maxHeight);\n" + + " }\n" + + " /**\n" + + " * An information presenter determines the style presentation\n" + + " * of information displayed in the default information control.\n" + + " * The interface can be implemented by clients.\n" + + " * \n" + + " * @since 3.2\n" + + " */\n" + + " public interface IInformationPresenterExtension {\n" + + " \n" + + " /**\n" + + " * Updates the given presentation of the given information and\n" + + " * thereby may manipulate the information to be displayed. The manipulation\n" + + " * could be the extraction of textual encoded style information etc. Returns the\n" + + " * manipulated information.\n" + + " *

    \n" + + " * Replaces {@link IInformationPresenter#updatePresentation(String, int, int)}\n" + + " * Make sure that you do not pass in a Display until\n" + + " * https://bugs.eclipse.org/bugs/show_bug.cgi?id=38528 is fixed.\n" + + " *

    \n" + + " *\n" + + " * @param hoverInfo the information to be presented\n" + + " * @param maxWidth the maximal width in pixels\n" + + " * @param maxHeight the maximal height in pixels\n" + + " *\n" + + " * @return the manipulated information\n" + + " */\n" + + " String updatePresentation(String hoverInfo, int maxWidth, int maxHeight);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in DefaultInformationControl.java (at line 14)\n" + + " * @deprecated As of 3.2, replaced by {@link IInformationPresenterExtension#updatePresentation(String, int, int)}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in DefaultInformationControl.java (at line 34)\n" + + " * Replaces {@link IInformationPresenter#updatePresentation(String, int, int)}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug119857_Fields() { + runNegativeTest( + new String[] { + "TestFields.java", + "/**\n" + + " * @see MyInnerClass#foo\n" + + " */\n" + + "public class TestFields {\n" + + " /**\n" + + " * @see MyInnerClass#foo\n" + + " */\n" + + " public class MyInnerClass {\n" + + " Object foo;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in TestFields.java (at line 6)\n" + + " * @see MyInnerClass#foo\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug119857_Methods() { + runNegativeTest( + new String[] { + "TestMethods.java", + "/**\n" + + " * @see MyInnerClass#foo()\n" + + " * @see MyInnerInterface#foo()\n" + + " */\n" + + "public class TestMethods {\n" + + " /**\n" + + " * @see MyInnerInterface#foo()\n" + + " */\n" + + " public class MyInnerClass {\n" + + " public void foo() {}\n" + + " }\n" + + " /**\n" + + " * @see MyInnerClass#foo()\n" + + " */\n" + + " public interface MyInnerInterface {\n" + + " public void foo();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in TestMethods.java (at line 7)\n" + + " * @see MyInnerInterface#foo()\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in TestMethods.java (at line 13)\n" + + " * @see MyInnerClass#foo()\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug119857_Types() { + runNegativeTest( + new String[] { + "TestTypes.java", + "/**\n" + + " * @see MyInnerClass\n" + + " * @see MyInnerInterface\n" + + " */\n" + + "public class TestTypes {\n" + + " /**\n" + + " * @see MyInnerInterface\n" + + " */\n" + + " public class MyInnerClass {\n" + + " public void foo() {}\n" + + " }\n" + + " /**\n" + + " * @see MyInnerClass\n" + + " */\n" + + " public interface MyInnerInterface {\n" + + " public void foo();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in TestTypes.java (at line 7)\n" + + " * @see MyInnerInterface\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in TestTypes.java (at line 13)\n" + + " * @see MyInnerClass\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug119857_Private01() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " static class Inner {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " public Inner field;\n" + + " /** \n" + + " * @see Inner#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug119857_Public01() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " static class Inner {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " public Inner field;\n" + + " /** \n" + + " * @see Inner#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + "}\n" + }, + //pack/Test.java:13: warning - Tag @see: reference not found: Inner1#foo() + "----------\n" + + "1. ERROR in pack\\Test.java (at line 8)\r\n" + + " * @see Inner#foo()\r\n" + + " ^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + + "----------\n" + ); + } + public void testBug119857_Private02() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "test/Test.java", + "package test;\n" + + "public class Test {\n" + + " static class Inner1 {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " static class Inner2 {\n" + + " public Inner1 field;\n" + + " /** \n" + + " * @see Inner1#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + " }\n" + + "}\n" + }, + //pack\Test2.java:11: warning - Tag @see: reference not found: Inner1#foo() + "----------\n" + + "1. ERROR in test\\Test.java (at line 9)\r\n" + + " * @see Inner1#foo()\r\n" + + " ^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + ); + } + public void testBug119857_Public02() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "public class Test {\n" + + " static class Inner1 {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " static class Inner2 {\n" + + " public Inner1 field;\n" + + " /** \n" + + " * @see Inner1#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug119857_Public03() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " static class Inner1 {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " public static class Inner2 {\n" + + " public Inner1 field;\n" + + " /** \n" + + " * @see Inner1#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + " }\n" + + "}\n" + }, + //pack/Test.java:13: warning - Tag @see: reference not found: Inner1#foo() + "----------\n" + + "1. ERROR in pack\\Test.java (at line 9)\n" + + " * @see Inner1#foo()\n" + + " ^^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + + "----------\n" + ); + } + + /** + * Bug 145007: [1.5][javadoc] Generics + Inner Class -> Javadoc "missing @throws" warning + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=145007" + */ + public void testBug145007() { + runNegativeTest( + new String[] { + "TestClass.java", + "class TestClass {\n" + + " static class Test1 {\n" + + " /**\n" + + " * A simple method that demonstrates tag problems\n" + + " * \n" + + " * @return a string\n" + + " * @throws MyException\n" + + " * if something goes wrong\n" + + " */\n" + + " public String getString() throws MyException {\n" + + " throw new MyException();\n" + + " }\n" + + " }\n" + + "\n" + + " static class MyException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in TestClass.java (at line 1)\r\n" + + " class TestClass {\r\n" + + " ^\n" + + "Syntax error, type parameters are only available if source level is 1.5 or greater\n" + + "----------\n" + ); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_5.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_5.java new file mode 100644 index 0000000000..4044835051 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest_1_5.java @@ -0,0 +1,4363 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JavadocTest_1_5 extends JavadocTest { + + String docCommentSupport = CompilerOptions.ENABLED; + String reportInvalidJavadoc = CompilerOptions.ERROR; + String reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + String reportMissingJavadocTags = CompilerOptions.ERROR; + String reportMissingJavadocTagsOverriding = CompilerOptions.ENABLED; + String reportMissingJavadocComments = null; + String reportMissingJavadocCommentsVisibility = null; + + public JavadocTest_1_5(String name) { + super(name); + } + + public static Class testClass() { + return JavadocTest_1_5.class; + } + + // Use this static initializer to specify subset for tests + // All specified tests which does not belong to the class are skipped... + static { +// TESTS_PREFIX = "testBug95521"; +// TESTS_NAMES = new String[] { "testBug331872d" }; +// TESTS_NUMBERS = new int[] { 101283 }; +// TESTS_RANGE = new int[] { 23, -1 }; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, this.docCommentSupport); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, this.reportInvalidJavadoc); + if (!CompilerOptions.IGNORE.equals(this.reportInvalidJavadoc)) { + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, this.reportInvalidJavadocVisibility); + } + if (this.reportMissingJavadocComments != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + else + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportInvalidJavadoc); + if (this.reportMissingJavadocCommentsVisibility != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocCommentsVisibility, this.reportMissingJavadocCommentsVisibility); + if (this.reportMissingJavadocTags != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportMissingJavadocTags); + if (this.reportMissingJavadocTagsOverriding != null) { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsOverriding, this.reportMissingJavadocTagsOverriding); + } + } else { + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, this.reportInvalidJavadoc); + } + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, CompilerOptions.ENABLED); + return options; + } + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.docCommentSupport = CompilerOptions.ENABLED; + this.reportInvalidJavadoc = CompilerOptions.ERROR; + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + this.reportMissingJavadocTags = CompilerOptions.ERROR; + this.reportMissingJavadocTagsOverriding = CompilerOptions.ENABLED; + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + } + + /** + * Test fix for bug 70891: [1.5][javadoc] Compiler should accept new 1.5 syntax for @param + * @see 70891 + * These two tests fail for 1.5 source level but should pass for 1.3 or 1.4 + * @see JavadocTest_1_4 + */ + /* (non-Javadoc) + * Test @param for generic class type parameter + */ + public void test003() { + this.runConformTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type\n" + + " */\n" + + " public class X {}" + } + ); + } + public void test004() { + this.runConformTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type extends RuntimeException\n" + + " */\n" + + " public class X {}" + } + ); + } + public void test005() { + this.runConformTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + } + ); + } + public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter\n" + + " */\n" + + " public class X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type parameter\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter\n" + + " */\n" + + " public class X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter F\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: U cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 3\n" + + " ^\n" + + "Javadoc: V cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: Parameter X is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test010() { + this.runConformTest( + new String[] { + "X.java", + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + } + ); + } + public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter T\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter U\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter V\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter U\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter V\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter T\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter V\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter T\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter U\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter V\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter T\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter U\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test019() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: Parameter X is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter T\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 2\n" + + " * @param\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter T\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test021() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: V cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 1\n" + + " ^\n" + + "Javadoc: U cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^\n" + + "Syntax error on token \",\", delete this token\n" + + "----------\n" + ); + } + public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^^^^^^\n" + + "Syntax error on token \"extend\", extends expected\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public class X {}\n" + + " ^^^^^^\n" + + "extend cannot be resolved to a type\n" + + "----------\n" + ); + } + + /* (non-Javadoc) + * Test @param for generic method type parameter + */ + public void test023() { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type\n" + + " */\n" + + " public void foo() {}\n" + + "}" + } + ); + } + public void test024() { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type extends RuntimeException\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + } + ); + } + public void test025() { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + } + ); + } + public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param val int\n" + + " * @param Type parameter\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param Type parameter\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test027() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter F\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test028() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 3\n" + + " * @param xxx int\n" + + " * @param Obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: U cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 3\n" + + " ^\n" + + "Javadoc: V cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @param xxx int\n" + + " ^^^\n" + + "Javadoc: Parameter xxx is not declared\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @param Obj Object\n" + + " ^^^\n" + + "Javadoc: Parameter Obj is not declared\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test029() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 1\n" + + " * @param Type parameter 2\n" + + " * @param val int\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param obj Object\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: Parameter X is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test030() { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Valid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param obj Object\n" + + " * @param Type parameter 2\n" + + " * @param val int\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + } + ); + } + public void test031() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter T\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter U\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter V\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test032() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 3\n" + + " * @param val int\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter U\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter V\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test033() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param obj Object\n" + + " * @param Type parameter 3\n" + + " * @param Type parameter 3\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter T\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test034() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param val int\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param Object obj\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param val int\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: Parameter X is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " * @param Object obj\n" + + " ^^^^^^\n" + + "Javadoc: Parameter Object is not declared\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " * @param Type parameter 2\n" + + " ^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " * @param val int\n" + + " ^^^\n" + + "Javadoc: Duplicate tag for parameter\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter T\n" + + "----------\n" + + "7. ERROR in X.java (at line 13)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test035() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type parameter 2\n" + + " * @param\n" + + " * @param Type parameter 1\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @param\n" + + " ^^^^^\n" + + "Javadoc: Missing parameter name\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter T\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + // TODO (david) recovery seems not to work properly here: + // we should have type parameters in method declaration. + public void test036() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param Type parameter 2\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param Type parameter 2\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @param Type parameter 1\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^\n" + + "Syntax error on token \",\", delete this token\n" + + "----------\n" + ); + } + public void test037() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * Invalid type parameter reference: compile error\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 2\n" + + " * @param Type parameter 1\n" + + " * @param val int\n" + + " * @param obj Object\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^^^^^^^^\n" + + "Exceptions cannot be resolved to a type\n" + + "----------\n" + ); + } + public void test038() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param < Type\n" + + " * @param < Type for parameterization\n" + + " * @param <> Type\n" + + " * @param Type\n" + + " * @param <*> Type\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param < Type\n" + + " ^^^^^^\n" + + "Javadoc: Invalid param tag type parameter name\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " * @param < Type for parameterization\n" + + " ^^^^^^\n" + + "Javadoc: Invalid param tag type parameter name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param <> Type\n" + + " ^^\n" + + "Javadoc: Invalid param tag type parameter name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param Type\n" + + " ^^^\n" + + "Javadoc: Invalid param tag type parameter name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param <*> Type\n" + + " ^^^\n" + + "Javadoc: Invalid param tag type parameter name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter E\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + " /**\n" + + " * Invalid type parameter reference\n" + + " * @param Type\n" + + " * @param < Type\n" + + " * @param << Type\n" + + " * @param > Type\n" + + " */\n" + + " public class X {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " * @param Type\n" + + " ^^\n" + + "Javadoc: Invalid param tag name\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " * @param < Type\n" + + " ^^^^\n" + + "Javadoc: Invalid param tag type parameter name\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " * @param << Type\n" + + " ^^^^^\n" + + "Javadoc: Invalid param tag type parameter name\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " * @param > Type\n" + + " ^^^^\n" + + "Javadoc: Invalid param tag type parameter name\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " public class X {}\n" + + " ^\n" + + "Javadoc: Missing tag for parameter E\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void test040() { + runConformReferenceTest( + new String[] { + "X.java", + "/**\n" + + " * @category\n" + + " */\n" + + "public class X {\n" + + "}\n" + } + ); + } + + /** + * Test fix for bug 80257: [javadoc] Invalid missing reference warning on @see or @link tags + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=80257" + */ + public void testBug80257() { + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @see G#G(Object)\n" + + " * @see G#G(Exception)\n" + + " */\n" + + "public class X extends G {\n" + + " X(Exception exc) { super(exc);}\n" + + "}\n" + + "class G {\n" + + " G(E e) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " * @see G#G(Object)\n" + + " ^^^^^^^^^\n" + + "Javadoc: The constructor G(Object) is undefined\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + /** + * Test fix for bug 82514: [1.5][javadoc] Problem with generics in javadoc + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=82514" + */ + // FAIL ERRMSG + public void _testBug82514() { + this.runNegativeTest( + new String[] { + "X.java", + "class ComparableUtils {\n" + + " public static > int compareTo(final Object first, final Object firstPrime, final Class type) throws ClassCastException\n" + + " {\n" + + " return 0;\n" + + " }\n" + + " public static > int compareTo(final X first, final X firstPrime)\n" + + " throws ClassCastException\n" + + " {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public final class X { \n" + + " /** Tests the method{@link ComparableUtils#compareTo(Object, Object, Class)} and\n" + + " * {@link ComparableUtils#compareTo(Object, Object)}.\n" + + " */\n" + + " public void testCompareTo() {}\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public static > int compareTo(final X first, final X firstPrime)\n" + + " ^\n" + + "The type parameter X is hiding the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " * {@link ComparableUtils#compareTo(Object, Object)}.\n" + + " ^^^^^^^^^\n" + + "Javadoc: Bound mismatch: The generic method compareTo(X, X) of type ComparableUtils is not applicable for the arguments (Object, Object). The inferred type Object is not a valid substitute for the bounded parameter >\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } + + /** + * Test fix for bug 83127: [1.5][javadoc][dom] Wrong / strange bindings for references in javadoc to methods with type variables as parameter types + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83127" + */ + public void testBug83127a() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Test.java", + "/** \n" + + " * @see Test#add(T) \n" + + " * @see #add(T)\n" + + " * @see Test#Test(T)\n" + + " * @see #Test(T)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (T)\"\n" + + " * - method binding = Test.add(Object)\n" + + " * - parameter binding = T of A\n" + + " */\n" + + "public class Test {\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Test#add(T) \n" + + " ^^^\n" + + "Javadoc: The method add(Object) in the type Test is not applicable for the arguments (T)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see #add(T)\n" + + " ^^^\n" + + "Javadoc: The method add(Object) in the type Test is not applicable for the arguments (T)\n" + + "----------\n" + + "3. ERROR in Test.java (at line 4)\n" + + " * @see Test#Test(T)\n" + + " ^^^^^^^\n" + + "Javadoc: The constructor Test(T) is undefined\n" + + "----------\n" + + "4. ERROR in Test.java (at line 5)\n" + + " * @see #Test(T)\n" + + " ^^^^^^^\n" + + "Javadoc: The constructor Test(T) is undefined\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug83127b() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Test.java", + "/** \n" + + " * @see Sub#add(T)\n" + + " * @see Sub#Sub(T)\n" + + " * - warning = \"The method add(Number) in the type Sub is not applicable for\n" + + " * the arguments (T)\"\n" + + " * - method binding = Sub.add(Number)\n" + + " * - parameter binding = T of A\n" + + " * -> Do we need to change this as T natually resolved to TypeVariable?\n" + + " * As compiler raises a warning, it\'s perhaps not a problem now...\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Sub#add(T)\n" + + " ^^^\n" + + "Javadoc: The method add(Number) in the type Sub is not applicable for the arguments (T)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Sub#Sub(T)\n" + + " ^^^^^^\n" + + "Javadoc: The constructor Sub(T) is undefined\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug83127c() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Test.java", + "/** \n" + + " * @see Sub#add(E) \n" + + " * @see Sub#Sub(E)\n" + + " * - warning = \"E cannot be resolved to a type\"\n" + + " * - method binding = null\n" + + " * - parameter binding = null\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Sub#add(E) \n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Sub#Sub(E)\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug83127d() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(E)\n" + + " * @see Unrelated1#Unrelated1(E)\n" + + " * - warning = \"E cannot be resolved to a type\"\n" + + " * - method binding = null\n" + + " * - parameter binding = null\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Unrelated1#add(E)\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Unrelated1#Unrelated1(E)\n" + + " ^\n" + + "Javadoc: E cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug83127e() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(Object)\n" + + " * @see Unrelated1#Unrelated1(Object)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (Object)\"\n" + + " * - method binding = Unrelated1.add(Number)\n" + + " * - parameter binding = java.lang.Object\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Unrelated1#add(Object)\n" + + " ^^^\n" + + "Javadoc: The method add(Number) in the type Unrelated1 is not applicable for the arguments (Object)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Unrelated1#Unrelated1(Object)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The constructor Unrelated1(Object) is undefined\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug83127f() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(Number)\n" + + " * @see Unrelated1#Unrelated1(Number)\n" + + " * - no warning\n" + + " * - method binding = Unrelated1.add(Number)\n" + + " * - parameter binding = java.lang.Number\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug83127g() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated1.java", + "public class Unrelated1 {\n" + + " public Unrelated1(E e) {}\n" + + " public boolean add(E e) { return false; }\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated1#add(Integer)\n" + + " * @see Unrelated1#Unrelated1(Integer)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (Integer)\"\n" + + " * - method binding = Unrelated1.add(Number)\n" + + " * - parameter binding = java.lang.Integer\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Unrelated1#add(Integer)\n" + + " ^^^\n" + + "Javadoc: The method add(Number) in the type Unrelated1 is not applicable for the arguments (Integer)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 3)\n" + + " * @see Unrelated1#Unrelated1(Integer)\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: The constructor Unrelated1(Integer) is undefined\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug83127h() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runNegativeTest( + new String[] { + "Unrelated2.java", + "public interface Unrelated2 {\n" + + " boolean add(E e);\n" + + "}\n", + "Test.java", + "/** \n" + + " * @see Unrelated2#add(T)\n" + + " * - warning = \"The method add(Object) in the type Test is not applicable for\n" + + " * the arguments (T)\"\n" + + " * - method binding = Unrelated2.add(Object)\n" + + " * - parameter binding = T of A\n" + + " * -> Do we need to change this as T natually resolved to TypeVariable?\n" + + " * As compiler raises a warning, it\'s perhaps not a problem now...\n" + + " */\n" + + "public class Test{\n" + + " Test(T t) {}\n" + + " public boolean add(T t) {\n" + + " return true;\n" + + " }\n" + + "}\n" + + "\n" + + "class Sub extends Test {\n" + + " Sub (E e) {super(null);}\n" + + " public boolean add(E e) {\n" + + " if (e.doubleValue() > 0)\n" + + " return false;\n" + + " return super.add(e);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " * @see Unrelated2#add(T)\n" + + " ^^^\n" + + "Javadoc: The method add(Object) in the type Unrelated2 is not applicable for the arguments (T)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + /** + * Bug 83393: [1.5][javadoc] reference to vararg method also considers non-array type as correct + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83393" + */ + public void testBug83393a() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public void foo(int a, int b) {} \n" + + " public void foo(int a, int... args) {}\n" + + " public void foo(String... args) {}\n" + + " public void foo(Exception str, boolean... args) {}\n" + + "}\n", + "Valid.java", + "/**\n" + + " * @see Test#foo(int, int)\n" + + " * @see Test#foo(int, int[])\n" + + " * @see Test#foo(int, int...)\n" + + " * @see Test#foo(String[])\n" + + " * @see Test#foo(String...)\n" + + " * @see Test#foo(Exception, boolean[])\n" + + " * @see Test#foo(Exception, boolean...)\n" + + " */\n" + + "public class Valid {}\n" + } + ); + } + public void testBug83393b() { + runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public void foo(int a, int b) {} \n" + + " public void foo(int a, int... args) {}\n" + + " public void foo(String... args) {}\n" + + " public void foo(Exception str, boolean... args) {}\n" + + "}\n", + "Invalid.java", + "/**\n" + + " * @see Test#foo(int)\n" + + " * @see Test#foo(int, int, int)\n" + + " * @see Test#foo()\n" + + " * @see Test#foo(String)\n" + + " * @see Test#foo(String, String)\n" + + " * @see Test#foo(Exception)\n" + + " * @see Test#foo(Exception, boolean)\n" + + " * @see Test#foo(Exception, boolean, boolean)\n" + + " */\n" + + "public class Invalid {}\n" + }, + "----------\n" + + "1. ERROR in Invalid.java (at line 2)\n" + + " * @see Test#foo(int)\n" + + " ^^^\n" + + "Javadoc: The method foo(int, int...) in the type Test is not applicable for the arguments (int)\n" + + "----------\n" + + "2. ERROR in Invalid.java (at line 3)\n" + + " * @see Test#foo(int, int, int)\n" + + " ^^^\n" + + "Javadoc: The method foo(int, int...) in the type Test is not applicable for the arguments (int, int, int)\n" + + "----------\n" + + "3. ERROR in Invalid.java (at line 4)\n" + + " * @see Test#foo()\n" + + " ^^^\n" + + "Javadoc: The method foo(String...) in the type Test is not applicable for the arguments ()\n" + + "----------\n" + + "4. ERROR in Invalid.java (at line 5)\n" + + " * @see Test#foo(String)\n" + + " ^^^\n" + + "Javadoc: The method foo(String...) in the type Test is not applicable for the arguments (String)\n" + + "----------\n" + + "5. ERROR in Invalid.java (at line 6)\n" + + " * @see Test#foo(String, String)\n" + + " ^^^\n" + + "Javadoc: The method foo(String...) in the type Test is not applicable for the arguments (String, String)\n" + + "----------\n" + + "6. ERROR in Invalid.java (at line 7)\n" + + " * @see Test#foo(Exception)\n" + + " ^^^\n" + + "Javadoc: The method foo(Exception, boolean...) in the type Test is not applicable for the arguments (Exception)\n" + + "----------\n" + + "7. ERROR in Invalid.java (at line 8)\n" + + " * @see Test#foo(Exception, boolean)\n" + + " ^^^\n" + + "Javadoc: The method foo(Exception, boolean...) in the type Test is not applicable for the arguments (Exception, boolean)\n" + + "----------\n" + + "8. ERROR in Invalid.java (at line 9)\n" + + " * @see Test#foo(Exception, boolean, boolean)\n" + + " ^^^\n" + + "Javadoc: The method foo(Exception, boolean...) in the type Test is not applicable for the arguments (Exception, boolean, boolean)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + /** + * Bug 83804: [1.5][javadoc] Missing Javadoc node for package declaration + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83804" + */ + public void testBug83804() { + runNegativeTest( + new String[] { + "pack/package-info.java", + "/**\n" + + " * Valid javadoc.\n" + + " * @see pack.Test\n" + + " * @see Unknown\n" + + " * @see pack.Test#foo()\n" + + " * @see pack.Test#unknown()\n" + + " * @see pack.Test#field\n" + + " * @see pack.Test#unknown\n" + + " * @param unexpected\n" + + " * @throws unexpected\n" + + " * @return unexpected \n" + + " * @deprecated accepted by javadoc.exe although javadoc 1.5 spec does not say that's a valid tag\n" + + " * @other-tags are valid\n" + + " */\n" + + "package pack;\n", + "pack/Test.java", + "/**\n" + + " * Invalid javadoc\n" + + " */\n" + + "package pack;\n" + + "public class Test {\n" + + " public int field;\n" + + " public void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in pack\\package-info.java (at line 4)\n" + + " * @see Unknown\n" + + " ^^^^^^^\n" + + "Javadoc: Unknown cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in pack\\package-info.java (at line 6)\n" + + " * @see pack.Test#unknown()\n" + + " ^^^^^^^\n" + + "Javadoc: The method unknown() is undefined for the type Test\n" + + "----------\n" + + "3. ERROR in pack\\package-info.java (at line 8)\n" + + " * @see pack.Test#unknown\n" + + " ^^^^^^^\n" + + "Javadoc: unknown cannot be resolved or is not a field\n" + + "----------\n" + + "4. ERROR in pack\\package-info.java (at line 9)\n" + + " * @param unexpected\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "5. ERROR in pack\\package-info.java (at line 10)\n" + + " * @throws unexpected\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "6. ERROR in pack\\package-info.java (at line 11)\n" + + " * @return unexpected \n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + /** + * Bug 86769: [javadoc] Warn/Error for 'Missing javadoc comments' doesn't recognize private inner classes + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=86769" + */ + public void _testBug86769() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + runNegativeTest( + new String[] { + "E.java", + "public enum E {\n" + + " A,\n" + + " DC{\n" + + " public void foo() {}\n" + + " };\n" + + " E() {}\n" + + " public void foo() {}\n" + + " private enum Epriv {\n" + + " Apriv,\n" + + " Cpriv {\n" + + " public void foo() {}\n" + + " };\n" + + " Epriv() {}\n" + + " public void foo() {}\n" + + " }\n" + + " enum Edef {\n" + + " Adef,\n" + + " Cdef {\n" + + " public void foo() {}\n" + + " };\n" + + " Edef() {}\n" + + " public void foo() {}\n" + + " }\n" + + " protected enum Epro {\n" + + " Apro,\n" + + " Cpro {\n" + + " public void foo() {}\n" + + " };\n" + + " Epro() {}\n" + + " public void foo() {}\n" + + " }\n" + + " public enum Epub {\n" + + " Apub,\n" + + " Cpub {\n" + + " public void foo() {}\n" + + " };\n" + + " Epub() {}\n" + + " public void foo() {}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in E.java (at line 1)\n" + + " public enum E {\n" + + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "2. ERROR in E.java (at line 2)\n" + + " A,\n" + + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "3. ERROR in E.java (at line 3)\n" + + " DC{\n" + + " ^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "4. ERROR in E.java (at line 7)\n" + + " public void foo() {}\n" + + " ^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "5. ERROR in E.java (at line 32)\n" + + " public enum Epub {\n" + + " ^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "6. ERROR in E.java (at line 33)\n" + + " Apub,\n" + + " ^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "7. ERROR in E.java (at line 34)\n" + + " Cpub {\n" + + " ^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "8. ERROR in E.java (at line 38)\n" + + " public void foo() {}\n" + + " ^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + /** + * Bug 95286: [1.5][javadoc] package-info.java incorrectly flags "Missing comment for public declaration" + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=95286" + */ + public void testBug95286_Default() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.DEFAULT; + runConformTest( + new String[] { + "test/package-info.java", + "/**\n" + + " * Javadoc for all package \n" + + " */\n" + + "package test;\n" + } + ); + } + public void testBug95286_Private() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/package-info.java", + "/**\n" + + " * Javadoc for all package \n" + + " */\n" + + "package test;\n" + } + ); + } + + /** + * Bug 95521: [1.5][javadoc] validation with @see tag not working for generic method + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=95521" + */ + public void testBug95521() { + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "/** Test */\n" + + "public class X implements I {\n" + + " /**\n" + + " * @see test.I#foo(java.lang.Class)\n" + + " */\n" + + " public G foo(Class stuffClass) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "/** Interface */\n" + + "interface I {\n" + + " /**\n" + + " * @param \n" + + " * @param stuffClass \n" + + " * @return stuff\n" + + " */\n" + + " public G foo(Class stuffClass);\n" + + "}\n" + + "/** \n" + + " * @param \n" + + " */\n" + + "class G {}\n" + } + ); + } + public void testBug95521b() { + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "/** Test */\n" + + "public class X {\n" + + " /**\n" + + " * @param \n" + + " * @param classT \n" + + " */\n" + + " public X(Class classT) {\n" + + " }\n" + + " /**\n" + + " * @param \n" + + " * @param classT\n" + + " * @return classT\n" + + " */\n" + + " public Class foo(Class classT) {\n" + + " return classT;\n" + + " }\n" + + "}\n" + + "/** Super class */\n" + + "class Y extends X {\n" + + " /**\n" + + " * @see X#X(java.lang.Class)\n" + + " */\n" + + " public Y(Class classT) {\n" + + " super(classT);\n" + + " }\n" + + "\n" + + " /**\n" + + " * @see X#foo(java.lang.Class)\n" + + " */\n" + + " public Class foo(Class stuffClass) {\n" + + " return null;\n" + + " }\n" + + "}\n" + } + ); + } + + /** + * Bug 96237: [javadoc] Inner types must be qualified + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=96237" + */ + public void testBug96237_Public01() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runConformTest( + new String[] { + "comment6/Valid.java", + "package comment6;\n" + + "public class Valid {\n" + + " /**\n" + + " * @see Valid.Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Valid.Inner}\n" + + " */\n" + + "class Sub2 extends Valid { }" + } + ); + } + public void testBug96237_Public02() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runConformTest( + new String[] { + "comment6/Invalid.java", + "package comment6;\n" + + "public class Invalid {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Inner} \n" + + " */\n" + + "class Sub1 extends Invalid { }\n" + } + ); + } + public void testBug96237_Public03() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "comment6a/def/Test.java", + "package comment6a.def;\n" + + "public class Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6a/test/Invalid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * See also {@link Inner}\n" + + " */\n" + + "public class Invalid extends Test { \n" + + "}", + "comment6a/test/Invalid2.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Invalid2 extends Test { \n" + + "}", + "comment6a/test/Valid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see comment6a.def.Test.Inner\n" + + " */\n" + + "public class Valid extends Test { \n" + + "}" + }, + //comment6a\test\Invalid.java:8: warning - Tag @link: reference not found: Inner + //comment6a\test\Invalid2.java:8: warning - Tag @see: reference not found: Test.Inner => bug ID: 4464323 + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid.java (at line 4)\n" + + " * See also {@link Inner}\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid2.java (at line 4)\n" + + " * @see Test.Inner\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug96237_Public04() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "comment6b/Invalid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Inner\n" + + " */\n" + + "public class Invalid implements Test { \n" + + "}", + "comment6b/Test.java", + "package comment6b;\n" + + "public interface Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6b/Valid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Valid implements Test { \n" + + "}" + }, + //comment6b\Invalid.java:6: warning - Tag @see: reference not found: Inner + "----------\n" + + "1. ERROR in comment6b\\Invalid.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug96237_Public05() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/a/Test.java", + "package test.a;\n" + + "/**\n" + + " * @see Inner\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Test {\n" + + " class Inner {}\n" + + "}\n" + }, + //test\a\Test.java:6: warning - Tag @see: reference not found: Inner + //test\a\Test.java:6: warning - Tag @see: reference not found: Test.Inner + "----------\n" + + "1. ERROR in test\\a\\Test.java (at line 3)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\a\\Test.java (at line 4)\n" + + " * @see Test.Inner\n" + + " ^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug96237_Public06() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/b/Test.java", + "package test.b;\n" + + "/** \n" + + " * @see Inner.Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + "public class Test {\n" + + " /** \n" + + " * @see Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + " public class Inner {\n" + + " class Level2 {}\n" + + " }\n" + + "}\n" + }, + //test\b\Test.java:6: warning - Tag @see: reference not found: Inner.Level2 + //test\b\Test.java:6: warning - Tag @see: reference not found: Test.Inner.Level2 + //test\b\Test.java:11: warning - Tag @see: reference not found: Level2 + //test\b\Test.java:11: warning - Tag @see: reference not found: Test.Inner.Level2 + "----------\n" + + "1. ERROR in test\\b\\Test.java (at line 3)\n" + + " * @see Inner.Level2\n" + + " ^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\b\\Test.java (at line 4)\n" + + " * @see Test.Inner.Level2\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "3. ERROR in test\\b\\Test.java (at line 8)\n" + + " * @see Level2\n" + + " ^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "4. ERROR in test\\b\\Test.java (at line 9)\n" + + " * @see Test.Inner.Level2\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug96237_Public07() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/c/Test.java", + "package test.c;\n" + + "/**\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * @see Level3\n" + + " * @see Level2.Level3\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + " public class Level2 {\n" + + " class Level3 {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + //test\c\Test.java:6: warning - Tag @see: reference not found: Inner.Level2.Level3 + //test\c\Test.java:6: warning - Tag @see: reference not found: Test.Inner.Level2.Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Level2.Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Inner.Level2.Level3 + //test\c\Test.java:14: warning - Tag @see: reference not found: Test.Inner.Level2.Level3 + "----------\n" + + "1. ERROR in test\\c\\Test.java (at line 3)\n" + + " * @see Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\c\\Test.java (at line 4)\n" + + " * @see Test.Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "3. ERROR in test\\c\\Test.java (at line 9)\n" + + " * @see Level3\n" + + " ^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "4. ERROR in test\\c\\Test.java (at line 10)\n" + + " * @see Level2.Level3\n" + + " ^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "5. ERROR in test\\c\\Test.java (at line 11)\n" + + " * @see Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "6. ERROR in test\\c\\Test.java (at line 12)\n" + + " * @see Test.Inner.Level2.Level3\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug96237_Public08() { + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "test/d/Reference.java", + "package test.d;\n" + + "class Reference {\n" + + "}\n", + "test/d/Test.java", + "package test.d;\n" + + "/**\n" + + " * @see Secondary\n" + + " * @see Reference\n" + + " */\n" + + "public class Test {\n" + + "}\n" + + "class Secondary {}" + }, + "----------\n" + + "1. ERROR in test\\d\\Test.java (at line 3)\n" + + " * @see Secondary\n" + + " ^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n" + + "2. ERROR in test\\d\\Test.java (at line 4)\n" + + " * @see Reference\n" + + " ^^^^^^^^^\n" + + "Javadoc: 'public' visibility for malformed doc comments hides this 'default' reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug96237_Private01() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "comment6/Valid.java", + "package comment6;\n" + + "public class Valid {\n" + + " /**\n" + + " * @see Valid.Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Valid.Inner}\n" + + " */\n" + + "class Sub2 extends Valid { }" + } + ); + } + public void testBug96237_Private02() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runNegativeTest( + new String[] { + "comment6/Invalid.java", + "package comment6;\n" + + "public class Invalid {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n" + + "/**\n" + + " * See also {@link Inner} \n" + + " */\n" + + "class Sub1 extends Invalid { }\n" + }, + //comment6\Invalid.java:11: warning - Tag @link: reference not found: Inner + "----------\n" + + "1. ERROR in comment6\\Invalid.java (at line 9)\n" + + " * See also {@link Inner} \n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug96237_Private03() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runNegativeTest( + new String[] { + "comment6a/def/Test.java", + "package comment6a.def;\n" + + "public class Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6a/test/Invalid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * See also {@link Inner}\n" + + " */\n" + + "public class Invalid extends Test { \n" + + "}", + "comment6a/test/Invalid2.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Invalid2 extends Test { \n" + + "}", + "comment6a/test/Valid.java", + "package comment6a.test;\n" + + "import comment6a.def.Test;\n" + + "/**\n" + + " * @see comment6a.def.Test.Inner\n" + + " */\n" + + "public class Valid extends Test { \n" + + "}" + }, + //comment6a\test\Invalid.java:8: warning - Tag @link: reference not found: Inner + //comment6a\test\Invalid2.java:8: warning - Tag @see: reference not found: Test.Inner => bug ID: 4464323 + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid.java (at line 4)\n" + + " * See also {@link Inner}\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "----------\n" + + "1. ERROR in comment6a\\test\\Invalid2.java (at line 4)\n" + + " * @see Test.Inner\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug96237_Private04() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runNegativeTest( + new String[] { + "comment6b/Invalid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Inner\n" + + " */\n" + + "public class Invalid implements Test { \n" + + "}", + "comment6b/Test.java", + "package comment6b;\n" + + "public interface Test {\n" + + " /**\n" + + " * @see Inner\n" + + " */\n" + + " public class Inner { }\n" + + "}\n", + "comment6b/Valid.java", + "package comment6b;\n" + + "\n" + + "/**\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Valid implements Test { \n" + + "}" + }, + //comment6b\Invalid.java:6: warning - Tag @see: reference not found: Inner + "----------\n" + + "1. ERROR in comment6b\\Invalid.java (at line 4)\n" + + " * @see Inner\n" + + " ^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug96237_Private05() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/a/Test.java", + "package test.a;\n" + + "/**\n" + + " * @see Inner\n" + + " * @see Test.Inner\n" + + " */\n" + + "public class Test {\n" + + " class Inner {}\n" + + "}\n" + } + ); + } + public void testBug96237_Private06() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/b/Test.java", + "package test.b;\n" + + "/** \n" + + " * @see Inner.Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + "public class Test {\n" + + " /** \n" + + " * @see Level2\n" + + " * @see Test.Inner.Level2\n" + + " */\n" + + " public class Inner {\n" + + " class Level2 {}\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug96237_Private07() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/c/Test.java", + "package test.c;\n" + + "/**\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + "public class Test {\n" + + " public class Inner {\n" + + " /**\n" + + " * @see Level3\n" + + " * @see Level2.Level3\n" + + " * @see Inner.Level2.Level3\n" + + " * @see Test.Inner.Level2.Level3\n" + + " */\n" + + " public class Level2 {\n" + + " class Level3 {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug96237_Private08() { + this.reportInvalidJavadocVisibility = CompilerOptions.PRIVATE; + runConformTest( + new String[] { + "test/d/Reference.java", + "package test.d;\n" + + "class Reference {\n" + + "}\n", + "test/d/Test.java", + "package test.d;\n" + + "/**\n" + + " * @see Secondary\n" + + " * @see Reference\n" + + " */\n" + + "public class Test {\n" + + "}\n" + + "class Secondary {}" + } + ); + } + + /** + * Bug 101283: [1.5][javadoc] Javadoc validation raises missing implementation in compiler + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=101283" + */ + public void testBug101283a() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @param \n" + + " * @param \n" + + " */\n" + + " static class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param \n" + + " ^\n" + + "Javadoc: Parameter T is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param \n" + + " ^\n" + + "Javadoc: Parameter F is not declared\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " static class Entry {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter L\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " static class Entry {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter R\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug101283b() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @see T Variable \n" + + " * @see F Variable\n" + + " */\n" + + " static class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see T Variable \n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @see F Variable\n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " static class Entry {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter L\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " static class Entry {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter R\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug101283c() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @param \n" + + " * @param \n" + + " */\n" + + " class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @param \n" + + " ^\n" + + "Javadoc: Parameter T is not declared\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @param \n" + + " ^\n" + + "Javadoc: Parameter F is not declared\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " class Entry {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter L\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " class Entry {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter R\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug101283d() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " /**\n" + + " * @see T Variable \n" + + " * @see F Variable\n" + + " */\n" + + " class Entry {\n" + + " // empty\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see T Variable \n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @see F Variable\n" + + " ^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " class Entry {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter L\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " class Entry {\n" + + " ^\n" + + "Javadoc: Missing tag for parameter R\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + // Verify duplicate test case: bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=102735 + public void testBug101283e() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + runNegativeTest( + new String[] { + "Test.java", + "public interface Test, C extends\n" + + "Test> extends Control, C>\n" + + "{\n" + + " public interface ValueRepresentationStrategy> extends ComponentFactory\n" + + " {\n" + + " /**This value must be equal to the ID of the component returned by the {@link\n" + + " ComponentFactory#createComponent(V)} method.*/\n" + + " public String getID(final VV value);\n" + + " }\n" + + "}\n" + + "class Component {}\n" + + "interface Control {}\n" + + "class SelectModel {}\n" + + "interface ComponentFactory {\n" + + " public void createComponent(V v);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 7)\n" + + " ComponentFactory#createComponent(V)} method.*/\n" + + " ^\n" + + "Javadoc: Cannot make a static reference to the non-static type variable V\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug101283f() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + runConformTest( + new String[] { + "Test.java", + "public interface Test, C extends\n" + + "Test> extends Control, C>\n" + + "{\n" + + " public interface ValueRepresentationStrategy> extends ComponentFactory\n" + + " {\n" + + " /**This value must be equal to the ID of the component returned by the {@link\n" + + " ComponentFactory#createComponent(Object)} method.*/\n" + + " public String getID(final VV value);\n" + + " }\n" + + "}\n" + + "class Component {}\n" + + "interface Control {}\n" + + "class SelectModel {}\n" + + "interface ComponentFactory {\n" + + " public void createComponent(V v);\n" + + "}\n" + } + ); + } + // Verify that ProblemReasons.InheritedNameHidesEnclosingName is not reported as Javadoc error + public void testBug101283g() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + runConformTest( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " int foo() { return 0; }\n" + + " class XX extends X2 {\n" + + " int bar() {\n" + + " return foo();\n" + + " }\n" + + " }\n" + + "}\n" + + "class X2 {\n" + + " int foo() {\n" + + " return 0;\n" + + " }\n" + + "}\n", + "test/Y.java", + "package test;\n" + + "public class Y {\n" + + " int foo;\n" + + " class YY extends Y2 {\n" + + " /**\n" + + " * @see #foo\n" + + " */\n" + + " int bar() {\n" + + " return foo;\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y2 {\n" + + " int foo;\n" + + "}\n" + } + ); + } + + /** + * Bug 112346: [javadoc] {@inheritedDoc} should be inactive for non-overridden method + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=112346" + */ + public void testBug112346() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "Test.java", + "/**\n" + + " * Test references\n" + + " * @see Test#field\n" + + " * @see Test#foo()\n" + + " */\n" + + "public class Test {\n" + + " T field;\n" + + " T foo() { return null; }\n" + + "}\n" + } + ); + } + + /** + * Bug 119857: [javadoc] Some inner class references should be flagged as unresolved + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=119857" + */ + public void testBug119857() { + runConformTest( + new String[] { + "DefaultInformationControl.java", + "public class DefaultInformationControl {\n" + + " public interface IInformationPresenter {\n" + + " /**\n" + + " * Updates the given presentation of the given information and\n" + + " * thereby may manipulate the information to be displayed. The manipulation\n" + + " * could be the extraction of textual encoded style information etc. Returns the\n" + + " * manipulated information.\n" + + " *\n" + + " * @param hoverInfo the information to be presented\n" + + " * @param maxWidth the maximal width in pixels\n" + + " * @param maxHeight the maximal height in pixels\n" + + " *\n" + + " * @return the manipulated information\n" + + " * @deprecated As of 3.2, replaced by {@link IInformationPresenterExtension#updatePresentation(String, int, int)}\n" + + " * see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=38528 for details.\n" + + " */\n" + + " String updatePresentation(String hoverInfo, int maxWidth, int maxHeight);\n" + + " }\n" + + " /**\n" + + " * An information presenter determines the style presentation\n" + + " * of information displayed in the default information control.\n" + + " * The interface can be implemented by clients.\n" + + " * \n" + + " * @since 3.2\n" + + " */\n" + + " public interface IInformationPresenterExtension {\n" + + " \n" + + " /**\n" + + " * Updates the given presentation of the given information and\n" + + " * thereby may manipulate the information to be displayed. The manipulation\n" + + " * could be the extraction of textual encoded style information etc. Returns the\n" + + " * manipulated information.\n" + + " *

    \n" + + " * Replaces {@link IInformationPresenter#updatePresentation(String, int, int)}\n" + + " * Make sure that you do not pass in a Display until\n" + + " * https://bugs.eclipse.org/bugs/show_bug.cgi?id=38528 is fixed.\n" + + " *

    \n" + + " *\n" + + " * @param hoverInfo the information to be presented\n" + + " * @param maxWidth the maximal width in pixels\n" + + " * @param maxHeight the maximal height in pixels\n" + + " *\n" + + " * @return the manipulated information\n" + + " */\n" + + " String updatePresentation(String hoverInfo, int maxWidth, int maxHeight);\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug119857_Fields() { + runConformTest( + new String[] { + "TestFields.java", + "/**\n" + + " * @see MyInnerClass#foo\n" + + " */\n" + + "public class TestFields {\n" + + " /**\n" + + " * @see MyInnerClass#foo\n" + + " */\n" + + " public class MyInnerClass {\n" + + " Object foo;\n" + + " }\n" + + "}" + } + ); + } + public void testBug119857_Methods() { + runConformTest( + new String[] { + "TestMethods.java", + "/**\n" + + " * @see MyInnerClass#foo()\n" + + " * @see MyInnerInterface#foo()\n" + + " */\n" + + "public class TestMethods {\n" + + " /**\n" + + " * @see MyInnerInterface#foo()\n" + + " */\n" + + " public class MyInnerClass {\n" + + " public void foo() {}\n" + + " }\n" + + " /**\n" + + " * @see MyInnerClass#foo()\n" + + " */\n" + + " public interface MyInnerInterface {\n" + + " public void foo();\n" + + " }\n" + + "}" + } + ); + } + public void testBug119857_Types() { + runConformTest( + new String[] { + "TestTypes.java", + "/**\n" + + " * @see MyInnerClass\n" + + " * @see MyInnerInterface\n" + + " */\n" + + "public class TestTypes {\n" + + " /**\n" + + " * @see MyInnerInterface\n" + + " */\n" + + " public class MyInnerClass {\n" + + " public void foo() {}\n" + + " }\n" + + " /**\n" + + " * @see MyInnerClass\n" + + " */\n" + + " public interface MyInnerInterface {\n" + + " public void foo();\n" + + " }\n" + + "}" + } + ); + } + public void testBug119857_Private01() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " static class Inner {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " public Inner field;\n" + + " /** \n" + + " * @see Inner#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug119857_Public01() { + this.reportMissingJavadocTags = CompilerOptions.DISABLED; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " static class Inner {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " public Inner field;\n" + + " /** \n" + + " * @see Inner#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + "}\n" + }, + //pack/Test.java:13: warning - Tag @see: reference not found: Inner1#foo() + "----------\n" + + "1. ERROR in pack\\Test.java (at line 8)\r\n" + + " * @see Inner#foo()\r\n" + + " ^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + public void testBug119857_Private02() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "public class Test {\n" + + " static class Inner1 {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " static class Inner2 {\n" + + " public Inner1 field;\n" + + " /** \n" + + " * @see Inner1#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug119857_Public02() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "public class Test {\n" + + " static class Inner1 {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " static class Inner2 {\n" + + " public Inner1 field;\n" + + " /** \n" + + " * @see Inner1#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug119857_Public03() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportInvalidJavadocVisibility = CompilerOptions.PUBLIC; + runNegativeTest( + new String[] { + "pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " static class Inner1 {\n" + + " public Object foo() { return null; }\n" + + " }\n" + + " public static class Inner2 {\n" + + " public Inner1 field;\n" + + " /** \n" + + " * @see Inner1#foo()\n" + + " */\n" + + " public Object foo() {\n" + + " return field.foo();\n" + + " }\n" + + " }\n" + + "}\n" + }, + //pack/Test.java:13: warning - Tag @see: reference not found: Inner1#foo() + "----------\n" + + "1. ERROR in pack\\Test.java (at line 9)\n" + + " * @see Inner1#foo()\n" + + " ^^^^^^\n" + + "Javadoc: \'public\' visibility for malformed doc comments hides this \'default\' reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + /** + * Bug 132430: [1.5][javadoc] Unwanted missing tag warning for overridden method with parameter containing type variable + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=132430" + */ + public void testBug132430() { + runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " /**\n" + + " * @param object\n" + + " */\n" + + " public void aMethod(E object) {}\n" + + "}", + "B.java", + "public class B extends A {\n" + + " /**\n" + + " * @see A#aMethod(java.lang.Object)\n" + + " */\n" + + " @Override\n" + + " public void aMethod(E object) {\n" + + " super.aMethod(object);\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug132430b() { + runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " /**\n" + + " * @param object\n" + + " */\n" + + " public void aMethod(E object) {}\n" + + "}", + "B.java", + "public class B extends A {\n" + + " /**\n" + + " * @see A#aMethod(java.lang.Object)\n" + + " */\n" + + " public void aMethod(E object) {\n" + + " super.aMethod(object);\n" + + " }\n" + + "}\n" + } + ); + } + public void testBug132430c() { + runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " /**\n" + + " * @param object\n" + + " */\n" + + " public void aMethod(E object) {}\n" + + "}", + "B.java", + "public class B extends A {\n" + + " /**\n" + + " * Empty comment\n" + + " */\n" + + " @Override\n" + + " public void aMethod(E object) {\n" + + " super.aMethod(object);\n" + + " }\n" + + "}\n" + } + ); + } + + /** + * Bug 145007: [1.5][javadoc] Generics + Inner Class -> Javadoc "missing @throws" warning + * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=145007" + */ + public void testBug145007() { + runConformTest( + new String[] { + "TestClass.java", + "class TestClass {\n" + + " static class Test1 {\n" + + " /**\n" + + " * A simple method that demonstrates tag problems\n" + + " * \n" + + " * @return a string\n" + + " * @throws MyException\n" + + " * if something goes wrong\n" + + " */\n" + + " public String getString() throws MyException {\n" + + " throw new MyException();\n" + + " }\n" + + " }\n" + + " static class MyException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}" + } + ); + } + + + /** + * Bug 87500: [1.5][javadoc][options] Add a 'Consider enum values' option to warn/error on 'Missing javadoc comments'. + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=87500" + */ + public void testBug87500a() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.DEFAULT; + runNegativeTest( + new String[] { + "A.java", + "enum A {\n" + + " clubs,\n" + + " diamonds,\n" + + " hearts,\n" + + " spades\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 1)\n" + + " enum A {\n" + + " ^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "2. ERROR in A.java (at line 2)\n" + + " clubs,\n" + + " ^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "3. ERROR in A.java (at line 3)\n" + + " diamonds,\n" + + " ^^^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "4. ERROR in A.java (at line 4)\n" + + " hearts,\n" + + " ^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n" + + "5. ERROR in A.java (at line 5)\n" + + " spades\n" + + " ^^^^^^\n" + + "Javadoc: Missing comment for default declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug87500b() { + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "A.java", + "enum A {\n" + + " clubs,\n" + + " diamonds,\n" + + " hearts,\n" + + " spades\n" + + "}\n" + }); + } + + /** + * Bug 204749 [1.5][javadoc] NPE in JavadocQualifiedTypeReference + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=204749" + */ + public void testBug204749a() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /** @see T.R */\n" + + " void foo() {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " /** @see T.R */\n" + + " ^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug204749b() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocComments = CompilerOptions.IGNORE; + this.reportInvalidJavadoc = CompilerOptions.IGNORE; + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " /** @see T.R */\n" + + " void foo() {}\n" + + "}" + } + ); + } + + /** + * Bug 209936 Missing code implementation in the compiler on inner classes + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=209936" + */ + public void testBug209936a() { + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public abstract class X extends Y {\n" + + " protected class A extends Member {\n" + + " /**\n" + + " * @see Member#foo(Object, Object)\n" + + " */\n" + + " public void foo(Object source, Object data) {}\n" + + " }\n" + + "}", + "p/Y.java", + "package p;\n" + + "import p1.Z;\n" + + "public abstract class Y extends Z {\n" + + "}", + "p1/Z.java", + "package p1;\n" + + "public abstract class Z {\n" + + " protected class Member {\n" + + " protected void foo(Object source, Object data) {\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " * @see Member#foo(Object, Object)\n" + + " ^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936b() { + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public abstract class X extends Y {\n" + + " protected class A extends Member {\n" + + " /**\n" + + " * @see Member#foo(Object, Object)\n" + + " */\n" + + " public void foo(Object source, Object data) {}\n" + + " }\n" + + "}", + "p/Y.java", + "package p;\n" + + "\n" + + "import p1.Z;\n" + + "public abstract class Y extends Z {}", + "p1/Z.java", + "package p1;\n" + + "public abstract class Z {\n" + + " protected class Member {\n" + + " protected void foo(Object source, Object data) {}\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " * @see Member#foo(Object, Object)\n" + + " ^^^^^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936_GenericMemberImplicitReference() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(V v) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // implicit type reference + " * @see #foo(Object)\n" + + " * @see #foo(V)\n" + + " */\n" + + " public void foo(V v) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p2\\X.java (at line 10)\n" + + " * @see #foo(V)\n" + + " ^^^\n" + + "Javadoc: The method foo(Object) in the type X.X1.X2.X3.X4 is not applicable for the arguments (V)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936_GenericMemberSingleReference() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(V v) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // single type reference + " * @see A4#foo(V)\n" + + " * @see A4#foo(Object)\n" + + " */\n" + + " public void myFoo(V v) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p2\\X.java (at line 9)\n" + + " * @see A4#foo(V)\n" + + " ^^^\n" + + "Javadoc: The method foo(Object) in the type A.A1.A2.A3.A4 is not applicable for the arguments (V)\n" + + "----------\n" + + "2. ERROR in p2\\X.java (at line 10)\n" + + " * @see A4#foo(Object)\n" + + " ^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936_GenericMemberQualifiedSingleReference() { + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(V v) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // qualified single type reference + " * @see A3.A4#foo(V)\n" + + " * @see p1.A.A1.A2.A3.A4#foo(Object)\n" + + " */\n" + + " public void foo(V v) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p2\\X.java (at line 9)\n" + + " * @see A3.A4#foo(V)\n" + + " ^^^\n" + + "Javadoc: The method foo(Object) in the type A.A1.A2.A3.A4 is not applicable for the arguments (V)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936_GenericMemberFullyQualifiedSingleReference() { + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(V v) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // fully qualified type reference + " * @see p1.A.A1.A2.A3.A4#foo(V)\n" + + " * @see p1.A.A1.A2.A3.A4#foo(Object)\n" + + " */\n" + + " public void foo(V v) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p2\\X.java (at line 9)\n" + + " * @see p1.A.A1.A2.A3.A4#foo(V)\n" + + " ^^^\n" + + "Javadoc: The method foo(Object) in the type A.A1.A2.A3.A4 is not applicable for the arguments (V)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936_MemberImplicitReference() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(U u) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // implicit reference + " * @see #foo(Object)\n" + + " * @see #foo(U u)\n" + + " */\n" + + " public void foo(U u) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p2\\X.java (at line 10)\r\n" + + " * @see #foo(U u)\r\n" + + " ^^^\n" + + "Javadoc: The method foo(Object) in the type X.X1.X2.X3.X4 is not applicable for the arguments (U)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936_MemberSingleReference1(){ + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(T t) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // single type reference + " * @see A4#foo(Object)\n" + + " * @see A4#foo(T)\n" + + " */\n" + + " public void foo(T t) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p2\\X.java (at line 9)\n" + + " * @see A4#foo(Object)\n" + + " ^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in p2\\X.java (at line 10)\n" + + " * @see A4#foo(T)\n" + + " ^^^\n" + + "Javadoc: The method foo(Object) in the type A.A1.A2.A3.A4 is not applicable for the arguments (T)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936_MemberSingleReference2(){ + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(S s) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // single type reference + " * @see A4#foo(Object)\n" + + " * @see A4#foo(S)\n" + + " */\n" + + " public void foo(S s) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p2\\X.java (at line 9)\n" + + " * @see A4#foo(Object)\n" + + " ^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in p2\\X.java (at line 10)\n" + + " * @see A4#foo(S)\n" + + " ^^^\n" + + "Javadoc: The method foo(Object) in the type A.A1.A2.A3.A4 is not applicable for the arguments (S)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936_MemberSingleReference3(){ + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(T t) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // single type reference + " * @see A4#foo(Object)\n" + + " * @see A4#foo(T)\n" + + " */\n" + + " public void foo(T t) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p2\\X.java (at line 9)\n" + + " * @see A4#foo(Object)\n" + + " ^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in p2\\X.java (at line 10)\n" + + " * @see A4#foo(T)\n" + + " ^^^\n" + + "Javadoc: The method foo(Object) in the type A.A1.A2.A3.A4 is not applicable for the arguments (T)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936_MemberSingleReference4(){ + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(T t) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // single type reference + " * @see A4#foo(Object)\n" + + " * @see A4#foo(T)\n" + + " */\n" + + " public void foo(T t) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p2\\X.java (at line 9)\n" + + " * @see A4#foo(Object)\n" + + " ^^\n" + + "Javadoc: Invalid member type qualification\n" + + "----------\n" + + "2. ERROR in p2\\X.java (at line 10)\n" + + " * @see A4#foo(T)\n" + + " ^^^\n" + + "Javadoc: The method foo(Object) in the type A.A1.A2.A3.A4 is not applicable for the arguments (T)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + + public void testBug209936_MemberQualifiedSingleReference1() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runConformTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(S s) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // qualified single type reference + " * @see p1.A.A1.A2.A3.A4#foo(Object)\n" + + " */\n" + + " public void foo(S s) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + } + ); + } + + public void testBug209936_MemberQualifiedSingleReference2() { + this.reportMissingJavadocTags = CompilerOptions.IGNORE; + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runConformTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public class A5 {\n" + + " public class A6 {\n" + + " public void foo(S s) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " public class X5 extends A5 {\n" + + " public class X6 extends A6 {\n" + + " /**\n" + + // qualified single type reference + " * @see p1.A.A1.A2.A3.A4.A5.A6#foo(Object)\n" + + " */\n" + + " public void foo(S s) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + } + ); + } + + public void testBug209936_MemberFullyQualifiedSingleReference() { + this.reportMissingJavadocCommentsVisibility = CompilerOptions.WARNING; + runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "\n" + + "public class A {\n" + + " public class A1 {\n" + + " public class A2 {\n" + + " public class A3 {\n" + + " public class A4 {\n" + + " public void foo(R r) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + "p2/X.java", + "package p2;\n" + + "import p1.A;\n" + + "public class X extends A {\n" + + " public class X1 extends A1 {\n" + + " public class X2 extends A2 {\n" + + " public class X3 extends A3 {\n" + + " public class X4 extends A4 {\n" + + " /**\n" + + // fully qualified type reference + " * @see p1.A.A1.A2.A3.A4#foo(Object)\n" + + " * @see p1.A.A1.A2.A3.A4#foo(R)\n" + + " */\n" + + " public void foo(R r) {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p2\\X.java (at line 10)\r\n" + + " * @see p1.A.A1.A2.A3.A4#foo(R)\r\n" + + " ^^^\n" + + "Javadoc: The method foo(Object) in the type A.A1.A2.A3.A4 is not applicable for the arguments (R)\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=247037, verify that we complain about @inheritDoc + // being used in package level javadoc. + public void testBug247037a() { + runNegativeTest( + new String[] { + "pack/package-info.java", + "/**\n" + + " * {@inheritDoc}\n" + + " * @since {@inheritDoc}\n" + + " * @blah {@inheritDoc}\n" + + " */\n" + + "package pack;\n" + }, + "----------\n" + + "1. ERROR in pack\\package-info.java (at line 2)\n" + + " * {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in pack\\package-info.java (at line 3)\n" + + " * @since {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in pack\\package-info.java (at line 4)\n" + + " * @blah {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=247037, verify that we complain about @inheritDoc + // being used in package level javadoc (variation) + public void testBug247037b() { + runNegativeTest( + new String[] { + "pack/package-info.java", + "/**\n" + + " * @return {@inheritDoc}\n" + + " * @param blah {@inheritDoc}\n" + + " */\n" + + "package pack;\n" + }, + "----------\n" + + "1. ERROR in pack\\package-info.java (at line 2)\n" + + " * @return {@inheritDoc}\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in pack\\package-info.java (at line 2)\n" + + " * @return {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in pack\\package-info.java (at line 3)\n" + + " * @param blah {@inheritDoc}\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in pack\\package-info.java (at line 3)\n" + + " * @param blah {@inheritDoc}\n" + + " ^^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + ); + } + /** + * @bug 286918:[javadoc] Compiler should warn when @see and @link tag references in package-info.java don't have fully qualified names + * @test that in a package-info.java file + * 1. References to valid packages are ACCEPTED without any warnings or errors + * 2. References to valid Java elements (including the ones in the same package) without qualified names are REPORTED as errors + * 3. References to valid Java elements with qualified names are ACCEPTED + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=286918" + */ + public void testBug284333() { + runNegativeTest(new String[]{ + "goo/bar/package-info.java", + "/**\n" + + "*/\n" + + "package goo.bar;\n", + "foo/bar/ClassInSamePackage.java", + "package foo.bar;\n" + + "public class ClassInSamePackage {\n" + + " public static int SOME_FIELD; \n" + + "}\n", + "foo/bar/goo/ClassInSubPackage.java", + "package foo.bar.goo;\n" + + "public class ClassInSubPackage {\n" + + " public static void foo() { \n" + + " }\n" + + "}\n", + "foo/ClassInEnclosingPackage.java", + "package foo;\n" + + "public class ClassInEnclosingPackage {\n" + + " public static int SOME_FIELD; \n" + + "}\n", + "foo/bar/package-info.java", + "/**\n" + + " * @see ClassInSamePackage#SOME_FIELD\n" + + " * @see foo.bar.ClassInSamePackage#SOME_FIELD\n" + + " * @see ClassInSamePackage#SOME_FIELD\n" + + " * @see ClassInSubPackage#foo\n" + + " * @see foo.bar.goo.ClassInSubPackage#foo\n" + + " * @see ClassInSubPackage#foo\n" + + " * @see ClassInEnclosingPackage\n" + + " * @see foo.ClassInEnclosingPackage\n" + + " * @see ClassInEnclosingPackage\n" + + " * @see foo.bar\n" + + " * @see goo.bar\n" + + " * @see foo.bar.goo\n" + + " */\n" + + "package foo.bar;\n" + }, + "----------\n" + + "1. ERROR in foo\\bar\\package-info.java (at line 2)\n" + + " * @see ClassInSamePackage#SOME_FIELD\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "2. ERROR in foo\\bar\\package-info.java (at line 4)\n" + + " * @see ClassInSamePackage#SOME_FIELD\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Invalid reference\n" + + "----------\n" + + "3. ERROR in foo\\bar\\package-info.java (at line 5)\n" + + " * @see ClassInSubPackage#foo\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: ClassInSubPackage cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in foo\\bar\\package-info.java (at line 7)\n" + + " * @see ClassInSubPackage#foo\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: ClassInSubPackage cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in foo\\bar\\package-info.java (at line 8)\n" + + " * @see ClassInEnclosingPackage\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: ClassInEnclosingPackage cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in foo\\bar\\package-info.java (at line 10)\n" + + " * @see ClassInEnclosingPackage\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: ClassInEnclosingPackage cannot be resolved to a type\n" + + "----------\n"); + } + + /** + * Additional tests for "https://bugs.eclipse.org/bugs/show_bug.cgi?id=286918" + * @test that in a non package-info.java file + * 2. References without qualified names to valid Java elements in the same package are ACCEPTED + * 2. References without qualified names to valid Java elements in other packages are REPORTED + * 3. References with qualified names to valid Java elements are accepted + */ + public void testBug284333a() { + runNegativeTest(new String[]{ + "goo/bar/package-info.java", + "/**\n" + + "*/\n" + + "package goo.bar;\n", + "foo/bar/ClassInSamePackage.java", + "package foo.bar;\n" + + "public class ClassInSamePackage {\n" + + " public static int SOME_FIELD; \n" + + "}\n", + "foo/bar/goo/ClassInSubPackage.java", + "package foo.bar.goo;\n" + + "public class ClassInSubPackage {\n" + + " public static void foo() { \n" + + " }\n" + + "}\n", + "foo/ClassInEnclosingPackage.java", + "package foo;\n" + + "public class ClassInEnclosingPackage {\n" + + " public static int SOME_FIELD; \n" + + "}\n", + "foo/bar/NotAPackageInfo.java", + "package foo.bar;\n" + + "/**\n" + + " * @see ClassInSamePackage#SOME_FIELD\n" + + " * @see foo.bar.ClassInSamePackage#SOME_FIELD\n" + + " * @see ClassInSamePackage#SOME_FIELD\n" + + " */\n" + + " public class NotAPackageInfo {\n" + + "/**\n" + + " * @see ClassInSubPackage#foo\n" + + " * @see foo.bar.goo.ClassInSubPackage#foo\n" + + " * @see ClassInSubPackage#foo\n" + + " */\n" + + " public static int SOME_FIELD = 0;\n" + + "/**\n" + + " * @see ClassInEnclosingPackage\n" + + " * @see foo.ClassInEnclosingPackage\n" + + " * @see ClassInEnclosingPackage\n" + + " */\n" + + " public static void foo() {\n" + + " }\n" + + " " + + " }\n" + }, + "----------\n" + + "1. ERROR in foo\\bar\\NotAPackageInfo.java (at line 9)\n" + + " * @see ClassInSubPackage#foo\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: ClassInSubPackage cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in foo\\bar\\NotAPackageInfo.java (at line 11)\n" + + " * @see ClassInSubPackage#foo\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Javadoc: ClassInSubPackage cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in foo\\bar\\NotAPackageInfo.java (at line 15)\n" + + " * @see ClassInEnclosingPackage\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: ClassInEnclosingPackage cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in foo\\bar\\NotAPackageInfo.java (at line 17)\n" + + " * @see ClassInEnclosingPackage\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: ClassInEnclosingPackage cannot be resolved to a type\n" + + "----------\n"); + } + /** + * Additional tests for "https://bugs.eclipse.org/bugs/show_bug.cgi?id=284333" + * @test that in a non package-info.java file + * 2. References without qualified names to imported Java elements in other packages are ACCEPTED + * 3. References with qualified names to valid Java elements are ACCEPTED + */ + public void testBug284333b() { + runConformTest(new String[] { + "goo/bar/package-info.java", + "/**\n" + + "*/\n" + + "package goo.bar;\n", + "foo/bar/ClassInSamePackage.java", + "package foo.bar;\n" + + "public class ClassInSamePackage {\n" + + " public static int SOME_FIELD; \n" + + "}\n", + "foo/bar/goo/ClassInSubPackage.java", + "package foo.bar.goo;\n" + + "public class ClassInSubPackage {\n" + + " public static void foo() { \n" + + " }\n" + + "}\n", + "foo/ClassInEnclosingPackage.java", + "package foo;\n" + + "public class ClassInEnclosingPackage {\n" + + " public static int SOME_FIELD; \n" + + "}\n", + "foo/bar/NotAPackageInfo.java", + "package foo.bar;\n" + + "import foo.*;\n" + + "import foo.bar.goo.*;\n" + + "/**\n" + + " * @see ClassInSamePackage#SOME_FIELD\n" + + " * @see foo.bar.ClassInSamePackage#SOME_FIELD\n" + + " * @see ClassInSamePackage#SOME_FIELD\n" + + " * @see goo.bar\n" + + " */\n" + + " public class NotAPackageInfo {\n" + + "/**\n" + + " * @see ClassInSubPackage#foo\n" + + " * @see foo.bar.goo.ClassInSubPackage#foo\n" + + " * @see ClassInSubPackage#foo\n" + + " * @see goo.bar\n" + + " */\n" + + " public static int SOME_FIELD = 0;\n" + + "/**\n" + + " * @see ClassInEnclosingPackage\n" + + " * @see foo.ClassInEnclosingPackage\n" + + " * @see ClassInEnclosingPackage\n" + + " * @see goo.bar\n" + + " */\n" + + " public static void foo() {\n" + + " }\n" + + " " + + " }\n" + }); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322581 + // To test the javadoc option CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters + public void testBug322581a() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, CompilerOptions.DISABLED); + this.runNegativeTest( + true, + new String[] { + "X.java", + " public class X {\n" + + " /**\n" + + " * javadoc\n" + + " */\n" + + " public void foo(int val, Object obj) {}\n" + + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter val\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public void foo(int val, Object obj) {}\n" + + " ^^^\n" + + "Javadoc: Missing tag for parameter obj\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=322581 + // To test the javadoc option CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters + public void testBug322581b() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, CompilerOptions.DISABLED); + this.runNegativeTest( + true, + new String[] { + "ListCallable.java", + " import java.util.Collections;\n" + + " import java.util.List;\n" + + " import java.util.concurrent.Callable;\n" + + "/**\n" + + " * Callable that returns a list.\n" + + " */\n" + + "public abstract class ListCallable implements Callable> { // good warning\n" + + " public abstract List call() throws Exception;\n" + + " /**\n" + + " * Returns a {@link ListCallable} that wraps the result from calling callable.\n" + + " * @param callable the {@link Callable} to wrap\n" + + " * @return the wrapper\n" + + " */\n" + + " public static ListCallable from(final Callable callable) { // don't warn\n" + + " return new ListCallable() {\n" + + " @Override\n" + + " public List call() throws Exception {\n" + + " return Collections.singletonList(callable.call());\n" + + " }\n" + + " };\n" + + " }\n" + + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in ListCallable.java (at line 7)\n" + + " public abstract class ListCallable implements Callable> { // good warning\n" + + " ^\n" + + "Javadoc: Missing tag for parameter V\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=331872 + public void testBug331872() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, CompilerOptions.DISABLED); + this.runNegativeTest( + true, + new String[] { + "X.java", + "/**\n" + + " * @param

    the given type parameter\n" + + " */\n" + + "public class X

    {\n" + + " /**\n" + + " * @param o the given object\n" + + " * @see #foo(p.O[])\n" + + " */\n" + + " public void foo(Object o) {\n" + + " }\n" + + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " * @see #foo(p.O[])\n" + + " ^^^\n" + + "Illegal qualified access from the type parameter p\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=331872 + public void testBug331872b() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, CompilerOptions.DISABLED); + this.runNegativeTest( + true, + new String[] { + "X.java", + "/**\n" + + " * @param

    the given type parameter\n" + + " */\n" + + "public class X

    {\n" + + " /**\n" + + " * @param o the given object\n" + + " * @see #foo(O[])\n" + + " */\n" + + " public void foo(Object o) {\n" + + " }\n" + + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " * @see #foo(O[])\n" + + " ^\n" + + "Javadoc: O[] cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=331872 + public void testBug331872c() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, CompilerOptions.DISABLED); + this.runNegativeTest( + true, + new String[] { + "X.java", + "/**\n" + + " * @param

    the given type parameter\n" + + " */\n" + + "public class X

    {\n" + + " /**\n" + + " * @param o the given object\n" + + " * @see #foo(test.O[])\n" + + " */\n" + + " public void foo(Object o) {\n" + + " }\n" + + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " * @see #foo(test.O[])\n" + + " ^^^^^^\n" + + "Javadoc: test[] cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=331872 + public void testBug331872d() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, CompilerOptions.DISABLED); + this.runNegativeTest( + true, + new String[] { + "X.java", + "/**\n" + + " * @param

    the given type parameter\n" + + " */\n" + + "public class X

    {\n" + + " /**\n" + + " * @param o the given object\n" + + " * @see #foo(test.O)\n" + + " */\n" + + " public void foo(Object o) {\n" + + " }\n" + + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " * @see #foo(test.O)\n" + + " ^^^^^^\n" + + "Javadoc: test cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Jsr14Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Jsr14Test.java new file mode 100644 index 0000000000..308c972c96 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Jsr14Test.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Jsr14Test extends AbstractRegressionTest { + +public Jsr14Test(String name) { + super(name); +} +@Override +protected Map getCompilerOptions() { + Map options = super.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_4); + return options; +} +// 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[] { "test000" }; +// TESTS_NUMBERS = new int[] { 15 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_4); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277450 +public void test1() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.class);\n" + + " }\n" + + "}", + }, + "class X"); + String expectedOutput = + " // Method descriptor #18 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 3 getstatic X.class$0 : java.lang.Class [25]\n" + + " 6 dup\n" + + " 7 ifnonnull 35\n" + + " 10 pop\n" + + " 11 ldc [27]\n" + + " 13 invokestatic java.lang.Class.forName(java.lang.String) : java.lang.Class [28]\n" + + " 16 dup\n" + + " 17 putstatic X.class$0 : java.lang.Class [25]\n" + + " 20 goto 35\n" + + " 23 new java.lang.NoClassDefFoundError [34]\n" + + " 26 dup_x1\n" + + " 27 swap\n" + + " 28 invokevirtual java.lang.Throwable.getMessage() : java.lang.String [36]\n" + + " 31 invokespecial java.lang.NoClassDefFoundError(java.lang.String) [42]\n" + + " 34 athrow\n" + + " 35 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [45]\n" + + " 38 return\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +public static Class testClass() { + return Jsr14Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java new file mode 100644 index 0000000000..bffc9f25c3 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java @@ -0,0 +1,7318 @@ +/******************************************************************************* + * Copyright (c) 2011, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) + * Bug 423504 - [1.8] Implement "18.5.3 Functional Interface Parameterization Inference" + * Bug 424742 - [1.8] NPE in LambdaExpression.isCompatibleWith + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.EclipseHasABug; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.EclipseJustification; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.JavacHasABug; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.IAttributeNamesConstants; +import org.eclipse.jdt.core.util.IClassFileAttribute; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.IMethodInfo; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.core.util.BootstrapMethodsAttribute; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class LambdaExpressionsTest extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test056"}; +// TESTS_NUMBERS = new int[] { 50 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public LambdaExpressionsTest(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} + +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int add(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (x, y) -> {\n" + + " return x + y;\n" + + " };\n" + + " System.out.println(i.add(1234, 5678));\n" + + " }\n" + + "}\n", + }, + "6912" + ); +} +public void test002() { + this.runConformTest( + new String[] { + "X.java", + "interface Greetings {\n" + + " void greet(String head, String tail);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Greetings g = (x, y) -> {\n" + + " System.out.println(x + y);\n" + + " };\n" + + " g.greet(\"Hello, \", \"World!\");\n" + + " }\n" + + "}\n", + }, + "Hello, World!" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406178, [1.8][compiler] Some functional interfaces are wrongly rejected +public void test003() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " BinaryOperator binOp = (x,y) -> { return x+y; };\n" + + " System.out.println(\"SUCCESS\");\n" + + " // System.out.println(binOp.apply(\"SUCC\", \"ESS\")); // when lambdas run\n" + + " }\n" + + "}\n", + "BiFunction.java", + "@FunctionalInterface\n" + + "public interface BiFunction {\n" + + " R apply(T t, U u);\n" + + "}", + "BinaryOperator.java", + "@FunctionalInterface\n" + + "public interface BinaryOperator extends BiFunction {\n" + + "}" + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406178, [1.8][compiler] Some functional interfaces are wrongly rejected +public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " BinaryOperator binOp = (x,y) -> { return x+y; };\n" + + " System.out.println(\"SUCCESS\");\n" + + " // System.out.println(binOp.apply(\"SUCC\", \"ESS\")); // when lambdas run\n" + + " }\n" + + "}\n", + "BiFunction.java", + "@FunctionalInterface\n" + + "public interface BiFunction {\n" + + " R apply(T t, U u);\n" + + "}", + "BinaryOperator.java", + "@FunctionalInterface\n" + + "public interface BinaryOperator extends BiFunction {\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " BinaryOperator binOp = (x,y) -> { return x+y; };\n" + + " ^^^^^^^^^^^^^^\n" + + "BinaryOperator is a raw type. References to generic type BinaryOperator should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " BinaryOperator binOp = (x,y) -> { return x+y; };\n" + + " ^^^\n" + + "The operator + is undefined for the argument type(s) java.lang.Object, java.lang.Object\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body. +public void test005() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String id(String s);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (s) -> s;\n" + + " System.out.println(i.id(\"Hello\"));\n" + + " }\n" + + "}\n" + }, + "Hello"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body. +public void test006() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String id(String s);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (s) -> s + s;\n" + + " System.out.println(i.id(\"Hello\"));\n" + + " }\n" + + "}\n" + }, + "HelloHello"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body. +public void test007() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void print(String s);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (s) -> System.out.println(s);\n" + + " i.print(\"Hello\");\n" + + " }\n" + + "}\n" + }, + "Hello"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body. +public void test008() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String print(String s);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (s) -> new String(s).toUpperCase();\n" + + " System.out.println(i.print(\"Hello\"));\n" + + " }\n" + + "}\n" + }, + "HELLO"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body. +public void test009() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String print(String s);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (s) -> new String(s);\n" + + " System.out.println(i.print(\"Hello\"));\n" + + " }\n" + + "}\n" + }, + "Hello"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body. +public void test010() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int unbox(Integer i);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (s) -> s;\n" + + " System.out.println(i.unbox(new Integer(1234)));\n" + + " }\n" + + "}\n" + }, + "1234"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body. +public void test011() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer box(int i);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (s) -> s;\n" + + " System.out.println(i.box(1234));\n" + + " }\n" + + "}\n" + }, + "1234"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body. +public void test012() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X subType();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = () -> new Y();\n" + + " System.out.println(i.subType());\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " public String toString() {\n" + + " return \"Some Y\";\n" + + " }\n" + + "}" + }, + "Some Y"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body. +public void test013() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String s);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " int in = 12345678;\n" + + " I i = (s) -> {\n" + + " I j = (s2) -> {\n" + + " System.out.println(s + s2 + in); \n" + + " };\n" + + " j.foo(\"Number=\");\n" + + " };\n" + + " i.foo(\"The \");\n" + + " }\n" + + "}\n" + }, + "The Number=12345678"); +} +public void test014() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void nonmain(String[] args) {\n" + + " int var = 2;\n" + + " I x2 = () -> {\n" + + " System.out.println(\"Argc = \" + args.length);\n" + + " for (int i = 0; i < args.length; i++) {\n" + + " System.out.println(\"Argv[\" + i + \"] = \" + args[i]);\n" + + " }\n" + + " };\n" + + " x2.doit();\n" + + " var=2;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " nonmain(new String[] {\"Hello! \", \"World!\" });\n" + + " }\n" + + "}" , + }, + "Argc = 2\n" + + "Argv[0] = Hello! \n" + + "Argv[1] = World!"); +} +public void test015() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new java.io.File((String) null).getCanonicalPath();\n" + + " } catch (NullPointerException | java.io.IOException ioe) {\n" + + " I x2 = () -> {\n" + + " System.out.println(ioe.getMessage()); // OK: args is not re-assignment since declaration/first assignment\n" + + " };\n" + + " x2.doit();\n" + + " };\n"+ + " }\n" + + "}\n" + }, + "null"); +} +public void test016() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.List list = new java.util.ArrayList<>();\n" + + " list.add(\"SomeString\");\n" + + " for (String s : list) {\n" + + " I x2 = () -> {\n" + + " System.out.println(s); // OK: args is not re-assignment since declaration/first assignment\n" + + " };\n" + + " x2.doit();\n" + + " };\n" + + " }\n" + + "\n" + + "}\n" , + }, + "SomeString"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406181, [1.8][compiler][codegen] IncompatibleClassChangeError when running code with lambda method +public void test017() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " BinaryOperator binOp = (x,y) -> { return x+y; }; \n" + + " System.out.println(binOp.apply(\"SUCC\", \"ESS\")); // when lambdas run\n" + + " }\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface BiFunction { \n" + + " R apply(T t, U u);\n" + + "}\n" + + "@FunctionalInterface \n" + + "interface BinaryOperator extends BiFunction { \n" + + "}\n", + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405071, [1.8][compiler][codegen] Generate code for array constructor references +public void test018() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X [][][] copy (short x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = X[][][]::new;\n" + + " I j = X[][][]::new;\n" + + " X[][][] x = i.copy((short) 631);\n" + + " System.out.println(x.length);\n" + + " x = j.copy((short) 136);\n" + + " System.out.println(x.length);\n" + + " }\n" + + "}\n", + }, + "631\n" + + "136"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405071, [1.8][compiler][codegen] Generate code for array constructor references +public void test019() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X [][][] copy (int x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = X[][][]::new;\n" + + " I j = X[][][]::new;\n" + + " X[][][] x = i.copy(631);\n" + + " System.out.println(x.length);\n" + + " x = j.copy(136);\n" + + " System.out.println(x.length);\n" + + " }\n" + + "}\n", + }, + "631\n" + + "136"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405071, [1.8][compiler][codegen] Generate code for array constructor references +public void test020() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X [][][] copy (Integer x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = X[][][]::new;\n" + + " I j = X[][][]::new;\n" + + " X[][][] x = i.copy(631);\n" + + " System.out.println(x.length);\n" + + " x = j.copy(136);\n" + + " System.out.println(x.length);\n" + + " }\n" + + "}\n", + }, + "631\n" + + "136"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405071, [1.8][compiler][codegen] Generate code for array constructor references +public void test021() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X [][][] copy (Integer x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = X[][][]::new;\n" + + " I j = X[][][]::new;\n" + + " X[][][] x = i.copy(new Integer(631));\n" + + " System.out.println(x.length);\n" + + " x = j.copy(new Integer((short)136));\n" + + " System.out.println(x.length);\n" + + " }\n" + + "}\n", + }, + "631\n" + + "136"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406388, [1.8][compiler][codegen] Runtime evaluation of method reference produces "BootstrapMethodError: call site initialization exception" +public void test022() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object copy(int [] ia);\n" + + "}\n" + + "interface J {\n" + + " int [] copy(int [] ia);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = int[]::clone;\n" + + " int [] x = new int [] { 10, 20, 30 };\n" + + " int [] y = (int []) i.copy(x);\n" + + " if (x == y || x.length != y.length || x[0] != y[0] || x[1] != y[1] || x[2] != y[2]) {\n" + + " System.out.println(\"Broken\");\n" + + " } else {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + " J j = int []::clone;\n" + + " y = null;\n" + + " y = j.copy(x);\n" + + " if (x == y || x.length != y.length || x[0] != y[0] || x[1] != y[1] || x[2] != y[2]) {\n" + + " System.out.println(\"Broken\");\n" + + " } else {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + " }\n" + + "}\n" , + }, + "OK\n" + + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406388, [1.8][compiler][codegen] Runtime evaluation of method reference produces "BootstrapMethodError: call site initialization exception" +public void test023() { +this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object copy(int [] ia);\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = int[]::clone;\n" + + " int [] ia = (int []) i.copy(new int[10]);\n" + + " System.out.println(ia.length);\n" + + " }\n" + + "}\n", + }, + "10"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406388, [1.8][compiler][codegen] Runtime evaluation of method reference produces "BootstrapMethodError: call site initialization exception" +public void test024() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " YBase copy(Y ia);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y::copy;\n" + + " YBase yb = i.copy(new Y());\n" + + " System.out.println(yb.getClass());\n" + + " }\n" + + "}\n" + + "class YBase {\n" + + " public YBase copy() {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "class Y extends YBase {\n" + + "}\n", + }, + "class Y"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406388, [1.8][compiler][codegen] Runtime evaluation of method reference produces "BootstrapMethodError: call site initialization exception" +public void test025() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo(int [] ia);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = int[]::hashCode;\n" + + " i.foo(new int[10]);\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406589, [1.8][compiler][codegen] super call misdispatched +public void test026() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo(int x, int y);\n" + + "}\n" + + "class Y {\n" + + " int foo(int x, int y) {\n" + + " System.out.println(\"Y.foo(\" + x + \",\" + y + \")\");\n" + + " return foo(x, y);\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " int foo(int x, int y) {\n" + + " System.out.println(\"X.foo(\" + x + \",\" + y + \")\");\n" + + " return x + y;\n" + + " }\n" + + " void goo() {\n" + + " I i = super::foo;\n" + + " System.out.println(i.foo(1234, 4321));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().goo();\n" + + " }\n" + + "}\n", + }, + "Y.foo(1234,4321)\n" + + "X.foo(1234,4321)\n" + + "5555"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406589, [1.8][compiler][codegen] super call misdispatched +public void test027() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo(int x, int y);\n" + + "}\n" + + "interface J {\n" + + " default int foo(int x, int y) {\n" + + " System.out.println(\"I.foo(\" + x + \",\" + y + \")\");\n" + + " return x + y;\n" + + " }\n" + + "}\n" + + "public class X implements J {\n" + + " public static void main(String[] args) {\n" + + " I i = new X().f();\n" + + " System.out.println(i.foo(1234, 4321));\n" + + " i = new X().g();\n" + + " try {\n" + + " System.out.println(i.foo(1234, 4321));\n" + + " } catch (Throwable e) {\n" + + " System.out.println(e.getMessage());\n" + + " }\n" + + " }\n" + + " I f() {\n" + + " return J.super::foo;\n" + + " }\n" + + " I g() {\n" + + " return new X()::foo;\n" + + " }\n" + + " public int foo(int x, int y) {\n" + + " throw new RuntimeException(\"Exception\");\n" + + " }\n" + + "}\n", + }, + "I.foo(1234,4321)\n" + + "5555\n" + + "Exception"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406584, Bug 406584 - [1.8][compiler][codegen] ClassFormatError: Invalid method signature +public void test028() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object copy();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " int [] x = new int[] { 0xdeadbeef, 0xfeedface };\n" + + " I i = x::clone;\n" + + " System.out.println(Integer.toHexString(((int []) i.copy())[0]));\n" + + " System.out.println(Integer.toHexString(((int []) i.copy())[1]));\n" + + " }\n" + + "}\n", + }, + "deadbeef\n" + + "feedface"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial +public void test029() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X.Y.Z makexyz(int val);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String args []) {\n" + + " new X().new Y().new Z().new P().goo();\n" + + " }\n" + + " class Y {\n" + + " class Z {\n" + + " Z(int val) {\n" + + " System.out.println(Integer.toHexString(val));\n" + + " } \n" + + " Z() {\n" + + " }\n" + + " class P {\n" + + " void goo() {\n" + + " I i = Z::new;\n" + + " i.makexyz(0xdeadbeef);\n" + + " }\n" + + " I i = Z::new;\n" + + " { i.makexyz(0xfeedface); }\n" + + " }\n" + + " }\n" + + " I i = Z::new;\n" + + " { i.makexyz(0xbeeffeed); }\n" + + " }\n" + + "}\n", + }, + "beeffeed\n" + + "feedface\n" + + "deadbeef"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial +public void test030() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X.Y makeY();\n" + + "}\n" + + "public class X {\n" + + " public class Y {\n" + + " public String toString() {\n" + + " return \"class Y\";\n" + + " }\n" + + " }\n" + + " void foo() {\n" + + " I i = Y::new;\n" + + " System.out.println(i.makeY());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n", + }, + "class Y"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial +public void test031() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X.Y makeY(int x);\n" + + "}\n" + + "public class X {\n" + + " class Y {\n" + + " String state; \n" + + " Y(int x) {\n" + + " state = Integer.toHexString(x);\n" + + " }\n" + + " public String toString() {\n" + + " return state;\n" + + " }\n" + + " }\n" + + " class Z extends Y {\n" + + " Z(int x) {\n" + + " super(x);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().f();\n" + + " }\n" + + " void f() {\n" + + " I i = Y::new;\n" + + " System.out.println(i.makeY(0xdeadbeef));\n" + + " }\n" + + "}\n", + }, + "deadbeef"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial +public void test032() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X.Y makeY(int x);\n" + + "}\n" + + "public class X {\n" + + " class Y {\n" + + " String state; \n" + + " Y(int x) {\n" + + " state = Integer.toHexString(x);\n" + + " }\n" + + " public String toString() {\n" + + " return state;\n" + + " }\n" + + " }\n" + + " class Z extends Y {\n" + + " Z(int x) {\n" + + " super(x);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().f();\n" + + " }\n" + + " void f() {\n" + + " I i = Z::new;\n" + + " System.out.println(i.makeY(0xdeadbeef));\n" + + " }\n" + + "}\n", + }, + "deadbeef"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial +public void test033() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X.Y.Z makeY(int x);\n" + + "}\n" + + "public class X {\n" + + " class Y {\n" + + " Y() {\n" + + " }\n" + + " class Z {\n" + + " String state;\n" + + " Z(int x) {\n" + + " state = Integer.toHexString(x);\n" + + " }\n" + + " public String toString() {\n" + + " return state;\n" + + " }\n" + + " }\n" + + " }\n" + + " class YS extends Y {\n" + + " YS() {\n" + + " }\n" + + " void f() {\n" + + " I i = Z::new;\n" + + " System.out.println(i.makeY(0xbeefface));\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new YS().f();\n" + + " }\n" + + "}\n", + }, + "beefface"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406319, [1.8][compiler][codegen] Generate code for enclosing instance capture in lambda methods. +public void test034() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " int f = 1234;\n" + + " void foo() {\n" + + " int x = 4321;\n" + + " I i = () -> x + f;\n" + + " System.out.println(i.foo());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n", + }, + "5555"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406319, [1.8][compiler][codegen] Generate code for enclosing instance capture in lambda methods. +public void test035() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " class Local {\n" + + " void foo() {\n" + + " }\n" + + " };\n" + + " new Local();\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406319, [1.8][compiler][codegen] Generate code for enclosing instance capture in lambda methods. +public void test036() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(String x, String y);\n" + + "}\n" + + "public class X {\n" + + " String xf = \"Lambda \";\n" + + " String x() {\n" + + " String xl = \"code \";\n" + + " class Y {\n" + + " String yf = \"generation \";\n" + + " String y () {\n" + + " String yl = \"with \";\n" + + " class Z {\n" + + " String zf = \"instance \";\n" + + " String z () {\n" + + " String zl = \"and \";\n" + + " class P {\n" + + " String pf = \"local \";\n" + + " String p () {\n" + + " String pl = \"capture \";\n" + + " I i = (x1, y1) -> {\n" + + " return (((I) ((x2, y2) -> {\n" + + " return ( ((I) ((x3, y3) -> {\n" + + " return xf + xl + yf + yl + zf + zl + pf + pl + x3 + y3;\n" + + " })).foo(\"works \", \"fine \") + x2 + y2);\n" + + " })).foo(\"in \", \"the \") + x1 + y1);\n" + + " };\n" + + " return i.foo(\"eclipse \", \"compiler \");\n" + + " }\n" + + " }\n" + + " return new P().p();\n" + + " }\n" + + " }\n" + + " return new Z().z();\n" + + " }\n" + + " }\n" + + " return new Y().y();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().x());\n" + + " }\n" + + "}\n", + }, + "Lambda code generation with instance and local capture works fine in the eclipse compiler"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406319, [1.8][compiler][codegen] Generate code for enclosing instance capture in lambda methods. +public void test037() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(String x, String y);\n" + + "}\n" + + "public class X {\n" + + " String xf = \"Lambda \";\n" + + " String x() {\n" + + " String xl = \"code \";\n" + + " class Y {\n" + + " String yf = \"generation \";\n" + + " String y () {\n" + + " String yl = \"with \";\n" + + " class Z {\n" + + " String zf = \"instance \";\n" + + " String z () {\n" + + " String zl = \"and \";\n" + + " class P {\n" + + " String pf = \"local \";\n" + + " String p () {\n" + + " String pl = \"capture \";\n" + + " I i = (x1, y1) -> {\n" + + " return (((I) ((x2, y2) -> {\n" + + " return ( ((I) ((x3, y3) -> {\n" + + " String exclaim = \"!\";\n" + + " return xf + xl + yf + yl + zf + zl + pf + pl + x3 + y3 + x2 + y2 + x1 + y1 + exclaim;\n" + + " })).foo(\"works \", \"fine \"));\n" + + " })).foo(\"in \", \"the \"));\n" + + " };\n" + + " return i.foo(\"eclipse \", \"compiler \");\n" + + " }\n" + + " }\n" + + " return new P().p();\n" + + " }\n" + + " }\n" + + " return new Z().z();\n" + + " }\n" + + " }\n" + + " return new Y().y();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().x());\n" + + " }\n" + + "}\n", + }, + "Lambda code generation with instance and local capture works fine in the eclipse compiler !"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406641, [1.8][compiler][codegen] Code generation for intersection cast. +public void test038() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + "}\n" + + "interface J {\n" + + "}\n" + + "public class X implements I, J {\n" + + " public static void main( String [] args) { \n" + + " f(new X());\n" + + " }\n" + + " static void f(Object o) {\n" + + " X x = (X & I & J) o;\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406641, [1.8][compiler][codegen] Code generation for intersection cast. +public void test039() { + String errMsg = isJRE11Plus + ? "class X cannot be cast to class I (X and I are in unnamed module of loader" + : "X cannot be cast to I"; + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + "}\n" + + "interface J {\n" + + "}\n" + + "public class X implements J {\n" + + " public static void main( String [] args) { \n" + + " f(new X());\n" + + " }\n" + + " static void f(Object o) {\n" + + " try {\n" + + " X x = (X & I & J) o;\n" + + " } catch (ClassCastException e) {\n" + + " System.out.println(e.getMessage());\n" + + " }\n" + + " }\n" + + "}\n", + }, + errMsg); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor +public void test041() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X makeX(int x);\n" + + "}\n" + + "public class X {\n" + + " class Z {\n" + + " void f() {\n" + + " I i = X::new;\n" + + " i.makeX(123456);\n" + + " }\n" + + " }\n" + + " private X(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new Z().f();\n" + + " }\n" + + "}\n", + }, + "123456"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor +public void test042() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X makeX(int x);\n" + + "}\n" + + "public class X {\n" + + " class Y extends X {\n" + + " class Z {\n" + + " void f() {\n" + + " I i = X::new;\n" + + " i.makeX(123456);\n" + + " i = Y::new;\n" + + " i.makeX(987654);\n" + + " }\n" + + " }\n" + + " private Y(int y) {\n" + + " System.out.println(\"Y(\" + y + \")\");\n" + + " }\n" + + " private Y() {\n" + + " \n" + + " }\n" + + " }\n" + + " private X(int x) {\n" + + " System.out.println(\"X(\" + x + \")\");\n" + + " }\n" + + "\n" + + " X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new Y().new Z().f();\n" + + " }\n" + + "\n" + + "}\n", + }, + "X(123456)\n" + + "Y(987654)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor +public void test043() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X makeX(int x);\n" + + "}\n" + + "public class X {\n" + + " class Y extends X {\n" + + " class Z extends X {\n" + + " void f() {\n" + + " I i = X::new;\n" + + " i.makeX(123456);\n" + + " i = Y::new;\n" + + " i.makeX(987654);\n" + + " i = Z::new;\n" + + " i.makeX(456789);\n" + + " }\n" + + " private Z(int z) {\n" + + " System.out.println(\"Z(\" + z + \")\");\n" + + " }\n" + + " Z() {\n" + + " }\n" + + " }\n" + + " private Y(int y) {\n" + + " System.out.println(\"Y(\" + y + \")\");\n" + + " }\n" + + " private Y() {\n" + + " \n" + + " }\n" + + " }\n" + + " private X(int x) {\n" + + " System.out.println(\"X(\" + x + \")\");\n" + + " }\n" + + "\n" + + " X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new Y().new Z().f();\n" + + " }\n" + + "\n" + + "}\n", + }, + "X(123456)\n" + + "Y(987654)\n" + + "Z(456789)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor +public void test044() { + this.runConformTest( + false, + JavacHasABug.JavacBugFixed_901, + new String[] { + "X.java", + "interface I {\n" + + " X makeX(int x);\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " int local;\n" + + " class Y extends X {\n" + + " class Z extends X {\n" + + " void f() {\n" + + " I i = X::new;\n" + + " i.makeX(123456);\n" + + " i = Y::new;\n" + + " i.makeX(987654);\n" + + " i = Z::new;\n" + + " i.makeX(456789);\n" + + " }\n" + + " private Z(int z) {\n" + + " System.out.println(\"Z(\" + z + \")\");\n" + + " }\n" + + " Z() {}\n" + + " }\n" + + " private Y(int y) {\n" + + " System.out.println(\"Y(\" + y + \")\");\n" + + " }\n" + + " private Y() {\n" + + " }\n" + + " }\n" + + " new Y().new Z().f();\n" + + " }\n" + + " private X(int x) {\n" + + " System.out.println(\"X(\" + x + \")\");\n" + + " }\n" + + "\n" + + " X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n", + }, + "X(123456)\n" + + "Y(987654)\n" + + "Z(456789)"); +} +public void test045() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " X makeX(int x);\n" + + "}\n" + + "public class X {\n" + + " I i = (x) -> {\n" + + " class Y extends X {\n" + + " private Y (int y) {\n" + + " System.out.println(y);\n" + + " }\n" + + " Y() {\n" + + " }\n" + + " void f() {\n" + + " I i = X::new;\n" + + " i.makeX(123456);\n" + + " i = X.Y::new;\n" + + " i.makeX(987654);\n" + + " }\n" + + " }\n" + + " return null; \n" + + " };\n" + + " private X(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new Y().f();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " class Y extends X {\n" + + " ^\n" + + "The type Y is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " private Y (int y) {\n" + + " ^^^^^^^^^\n" + + "The constructor Y(int) is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " Y() {\n" + + " ^^^\n" + + "The constructor Y() is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " I i = X::new;\n" + + " ^\n" + + "The local variable i is hiding a field from type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 15)\n" + + " i = X.Y::new;\n" + + " ^^^\n" + + "X.Y cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 27)\n" + + " new X().new Y().f();\n" + + " ^\n" + + "X.Y cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406760, [1.8][compiler][codegen] "VerifyError: Bad type on operand stack" with qualified super method references +public void test046() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String doit();\n" + + "}\n" + + "public class X extends B {\n" + + " class Y {\n" + + " class Z {\n" + + " void f() {\n" + + " \n" + + " I i = X.super::toString; // Verify error\n" + + " System.out.println(i.doit());\n" + + " i = X.this::toString; // This call gets dispatched OK.\n" + + " System.out.println(i.doit());\n" + + " }\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().new Y().new Z().f(); \n" + + " }\n" + + " \n" + + " public String toString() {\n" + + " return \"X's toString\";\n" + + " }\n" + + "}\n" + + "class B {\n" + + " public String toString() {\n" + + " return \"B's toString\";\n" + + " }\n" + + "}\n", + }, + "B\'s toString\n" + + "X\'s toString"); +} +public void test047() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " long lng = 1234;\n" + + " double d = 1234.5678;\n" + + " I i = (x, y) -> {\n" + + " System.out.println(\"long = \" + lng);\n" + + " System.out.println(\"args length = \" + args.length);\n" + + " System.out.println(\"double = \" + d);\n" + + " System.out.println(\"x = \" + x);\n" + + " System.out.println(\"y = \" + y);\n" + + " };\n" + + " i.foo(9876, 4321);\n" + + " }\n" + + "}\n", + }, + "long = 1234\n" + + "args length = 0\n" + + "double = 1234.5678\n" + + "x = 9876\n" + + "y = 4321"); +} +public void test048() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(T x, J y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " long lng = 1234;\n" + + " double d = 1234.5678;\n" + + " I i = (x, y) -> {\n" + + " System.out.println(\"long = \" + lng);\n" + + " System.out.println(\"args length = \" + args.length);\n" + + " System.out.println(\"double = \" + d);\n" + + " System.out.println(\"x = \" + x);\n" + + " System.out.println(\"y = \" + y);\n" + + " };\n" + + " i.foo(9876, 4321);\n" + + " \n" + + " I i2 = (x, y) -> {\n" + + " System.out.println(x);\n" + + " System.out.println(y);\n" + + " };\n" + + " i2.foo(\"Hello !\", \"World\");\n" + + " }\n" + + "}\n", + }, + "long = 1234\n" + + "args length = 0\n" + + "double = 1234.5678\n" + + "x = 9876\n" + + "y = 4321\n" + + "Hello !\n" + + "World"); +} +public void test049() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(X x, T t, J j);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = X::foo;\n" + + " i.foo(new X(), \"Hello\", \"World!\");\n" + + " }\n" + + " void foo(String s, String t) {\n" + + " System.out.println(s);\n" + + " System.out.println(t);\n" + + " }\n" + + "}\n", + }, + "Hello\n" + + "World!"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor +public void test050() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " static private void add(int x, int y) {\n" + + " System.out.println(x + y);\n" + + " }\n" + + " private void multiply(int x, int y) {\n" + + " System.out.println(x * y);\n" + + " }\n" + + " static class Y {\n" + + " static private void subtract(int x, int y) {\n" + + " System.out.println(x - y);\n" + + " }\n" + + " private void divide (int x, int y) {\n" + + " System.out.println(x / y);\n" + + " }\n" + + " static void doy() {\n" + + " I i = X::add;\n" + + " i.foo(1234, 12);\n" + + " i = new X()::multiply;\n" + + " i.foo(12, 20);\n" + + " i = Y::subtract;\n" + + " i.foo(123, 13);\n" + + " i = new Y()::divide;\n" + + " i.foo(99, 9);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = X::add;\n" + + " i.foo(1234, 12);\n" + + " i = new X()::multiply;\n" + + " i.foo(12, 20);\n" + + " i = Y::subtract;\n" + + " i.foo(123, 13);\n" + + " i = new Y()::divide;\n" + + " i.foo(99, 9);\n" + + " Y.subtract(10, 7);\n" + + " Y.doy();\n" + + " }\n" + + "}\n", + }, + "1246\n" + + "240\n" + + "110\n" + + "11\n" + + "3\n" + + "1246\n" + + "240\n" + + "110\n" + + "11"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor +public void test051() { + this.runConformTest( + false /* skipJavac*/, + JavacHasABug.JavacBugFixed_901, + new String[] { + "p2/B.java", + "package p2;\n" + + "import p1.*;\n" + + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class B extends A {\n" + + " class Y {\n" + + " void g() {\n" + + " I i = B::foo;\n" + + " i.foo();\n" + + " J j = new B()::goo;\n" + + " j.foo();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new B().new Y().g();\n" + + " }\n" + + "}\n", + "p1/A.java", + "package p1;\n" + + "import p2.*;\n" + + "public class A {\n" + + " protected static void foo() {\n" + + " System.out.println(\"A's static foo\");\n" + + " }\n" + + " protected void goo() {\n" + + " System.out.println(\"A's instance goo\");\n" + + " }\n" + + "}" + }, + "A\'s static foo\n" + + "A\'s instance goo"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor +public void test052() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " int local = 10;\n" + + " class Y {\n" + + " void foo(int x) {\n" + + " System.out.println(local);\n" + + " }\n" + + " void goo() {\n" + + " I i = this::foo;\n" + + " i.foo(10);\n" + + " }\n" + + " }\n" + + " new Y().goo();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "10"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406847, [1.8] lambda code compiles but then produces IncompatibleClassChangeError when run +public void test053() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void printItem(E value, int index) {\n" + + " String output = String.format(\"%d -> %s\", index, value);\n" + + " System.out.println(output);\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " List list = Arrays.asList(\"A\",\"B\",\"C\");\n" + + " eachWithIndex(list,X::printItem);\n" + + " }\n" + + " interface ItemWithIndexVisitor {\n" + + " public void visit(E item, int index);\n" + + " }\n" + + " public static void eachWithIndex(List list, ItemWithIndexVisitor visitor) {\n" + + " for (int i = 0; i < list.size(); i++) {\n" + + " visitor.visit(list.get(i), i);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "0 -> A\n" + + "1 -> B\n" + + "2 -> C"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406847, [1.8] lambda code compiles but then produces IncompatibleClassChangeError when run +public void test054() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void printItem(E value) {}\n" + + " public static void main(String[] argv) {\n" + + " List list = null;\n" + + " eachWithIndex(list, X::printItem);\n" + + " }\n" + + " interface ItemWithIndexVisitor {\n" + + " public void visit(E item);\n" + + " }\n" + + " public static void eachWithIndex(List list, ItemWithIndexVisitor visitor) {}\n" + + "}\n" + }, + ""); +} +public void test055() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int i);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " I i = x::foo;\n" + + " }\n" + + " int foo(int x) {\n" + + " return x;\n" + + " }\n" + + "}\n" + }, + ""); +} +public void test056() { + String expected = isJRE15Plus ? "Cannot invoke \"Object.getClass()\" because \"x\" is null" : "null"; + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int i);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = null;\n" + + " try {\n" + + " I i = x::foo;\n" + + " i.foo(10);\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(npe.getMessage());\n" + + " }\n" + + " }\n" + + " int foo(int x) {\n" + + " return x;\n" + + " }\n" + + "}\n" + }, + expected); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=410114, [1.8] CCE when trying to parse method reference expression with inappropriate type arguments +public void test057() { + String source = "interface I {\n" + + " void foo(Y y);\n" + + "}\n" + + "public class Y {\n" + + " class Z {\n" + + " Z(Y y) {\n" + + " System.out.println(\"Y.Z:: new\");\n" + + " }\n" + + " public void bar() {\n" + + " I i = Y.Z:: new;\n" + + " i.foo(new Y());\n" + + " i = Y.Z:: new;\n" + + " i.foo(new Y());\n" + + " i = Y.Z:: new;\n" + + " i.foo(new Y());\n" + + " }\n" + + " }\n" + + " public void foo() {\n" + + " Z z = new Z(null);\n" + + " z.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Y y = new Y();\n" + + " y.foo();\n" + + " }\n" + + "}\n"; +this.runConformTest( + new String[]{"Y.java", + source}, + "Y.Z:: new\n" + + "Y.Z:: new\n" + + "Y.Z:: new\n" + + "Y.Z:: new"); +} +// Bug 411273 - [1.8][compiler] Bogus error about unhandled exceptions for unchecked exceptions thrown by method reference. +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=411273 +public void test058() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " F1 f = X::foo;\n" + + " System.out.println(\"Hello, World\");\n" + + " }\n" + + " static int foo (int x) throws NumberFormatException { return 0; }\n" + + "}\n" + + "interface F1 { int X(int x);}\n" + }, + "Hello, World" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=420582, [1.8][compiler] Compiler should allow creation of generic array creation with unbounded wildcard type arguments +public void testGenericArrayCreation() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X[] makeArray(int i);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = X[]::new; // OK.\n" + + " System.out.println(i.makeArray(1024).length);\n" + + " }\n" + + "}\n" + + "" + }, + "1024" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421536, [1.8][compiler] Verify error with small program when preserved unused variables is off. +public void test421536() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " I foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " I i = () -> null;\n" + + " } catch (NullPointerException npe) {}\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK", + customOptions); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421536, [1.8][compiler] Verify error with small program when preserved unused variables is off. +public void test421536a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " public static void foo() {}\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " I i = X::foo;\n" + + " } catch (NullPointerException npe) {}\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK", + customOptions); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421607, [1.8][compiler] Verify Error with intersection casts +public void test421607() { + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " public void foo();\n" + + "}\n" + + "class C implements I {\n" + + " public void foo() {\n" + + " System.out.println(\"You will get here\");\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " ((C & I) (I) new C()).foo();\n" + + " }\n" + + "}\n" + }, + "You will get here"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421712, [1.8][compiler] java.lang.NoSuchMethodError with lambda expression in interface default method. +public void test421712() { + runConformTest( + new String[] { + "X.java", + "interface F {\n" + + " void foo();\n" + + "}\n" + + "interface I {\n" + + " default void foo() {\n" + + " F f = () -> {\n" + + " };\n" + + " System.out.println(\"Lambda instantiated\");\n" + + " }\n" + + "}\n" + + "public class X implements I {\n" + + " public static void main(String argv[]) {\n" + + " X x = new X();\n" + + " x.foo();\n" + + " }\n" + + "}\n" + }, + "Lambda instantiated"); +} + + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=422515, [1.8][compiler] "Missing code implementation in the compiler" when lambda body accesses array variable +public void test422515() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws InterruptedException {\n" + + " final int[] result = { 0 };\n" + + " Thread t = new Thread(() -> result[0] = 42);\n" + + " t.start();\n" + + " t.join();\n" + + " System.out.println(result[0]);\n" + + " }\n" + + "}\n" + }, + "42" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422515, [1.8][compiler] "Missing code implementation in the compiler" when lambda body accesses array variable +public void test422515a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws InterruptedException {\n" + + " final int[] result= { 0 };\n" + + " final int x = args.length + 42;\n" + + " Thread t = new Thread(() -> {\n" + + " result[0]= x;\n" + + " });\n" + + " t.start();\n" + + " t.join();\n" + + " System.out.println(result[0]);\n" + + " }\n" + + "}\n" + }, + "42" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422800, [1.8][compiler] "Missing code implementation in the compiler" 2 +public void test422800() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private String fField; // must be here; can be used or unused\n" + + " public void foo(Integer arg) {\n" + + " new Thread(() -> {\n" + + " arg.intValue();\n" + + " });\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421927, [1.8][compiler] Bad diagnostic: Unnecessary cast from I to I for lambdas. +public void test421927() { + this.runConformTest( + new String[] { + "X.java", + "interface I { \n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static I i = (I & java.io.Serializable) () -> 42;\n" + + " public static void main(String args[]) {\n" + + " System.out.println(i.foo());\n" + + " }\n" + + "}\n" + }, + "42"); +} + +public void testReferenceExpressionInference1() { + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " E foo(E e);\n" + + "}\n" + + "public class X {\n" + + " T print(I i) { return null; }\n" + + " void test() {\n" + + " String s = print(this::bar);" + + " }\n" + + " S bar(S s) { return s; }\n" + + "}\n" + }); +} + +public void testReferenceExpressionInference2() { + runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " F foo(E e);\n" + + "}\n" + + "public class X {\n" + + " I compose(I i1, I i2) { return null; }\n" + + " void test() {\n" + + " I x2s = compose(this::bar, this::i2s);" + + " }\n" + + " String i2s (Integer i) { return i.toString(); }\n" + + " W bar(V v) { return null; }\n" + + "}\n" + }); +} + +public void testReferenceExpressionInference3a() { + runConformTest( + false /* skipJavac*/, + JavacTestOptions.Excuse.JavacDoesNotCompileCorrectSource, + new String[] { + "X.java", + "interface I {\n" + + " F foo(E e);\n" + + "}\n" + + "public class X {\n" + + " I compose(I i1, I i2) { return null; }\n" + + " void test() {\n" + + " I x2s = compose(this::bar, this::i2s);" + // help inference with an explicit type argument + " }\n" + + " Z i2s (Integer i) { return null; }\n" + + " W bar(V v) { return null; }\n" + + "}\n" + }, null); +} + +// previous test demonstrates that a solution exists, just inference doesn't find it. +public void testReferenceExpressionInference3b() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " F foo(E e);\n" + + "}\n" + + "public class X {\n" + + " I compose(I i1, I i2) { return null; }\n" + + " void test() {\n" + + " I x2s = compose(this::bar, this::i2s);\n" + + " }\n" + + " Z i2s (Integer i) { return null; }\n" + + " W bar(V v) { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I x2s = compose(this::bar, this::i2s);\n" + + " ^^^^^^^^^\n" + + "The type X does not define i2s(Object) that is applicable here\n" + + "----------\n"); +} +public void testLambdaInference1() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] argv) {\n" + + " List list = null;\n" + + " eachWithIndex(list, s -> print(s));\n" + + " }\n" + + " static void print(String s) {}\n" + + " interface ItemWithIndexVisitor {\n" + + " public void visit(E item);\n" + + " }\n" + + " public static void eachWithIndex(List list, ItemWithIndexVisitor visitor) {}\n" + + "}\n" + }, + ""); +} + +public void testLambdaInference2() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class A {}\n" + + "class B extends A {\n" + + " void bar() {}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] argv) {\n" + + " someWithIndex(getList(), (B b) -> b.bar());\n" + + " }\n" + + " interface ItemWithIndexVisitor {\n" + + " public void visit(E item);\n" + + " }\n" + + " public static void someWithIndex(List list, ItemWithIndexVisitor visitor) {}\n" + + " static List getList() { return null; }\n" + + "}\n" + }, + ""); +} + +public void testBug419048_1() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "import java.util.stream.*;\n" + + "public class X {\n" + + " public void test() {\n" + + " List roster = new ArrayList<>();\n" + + " \n" + + " Map map = \n" + + " roster\n" + + " .stream()\n" + + " .collect(\n" + + " Collectors.toMap(\n" + + " p -> p.getLast(),\n" + + " p -> p\n" + + " ));\n" + + " }\n" + + "}\n" + + "class Person {\n" + + " public String getLast() { return null; }\n" + + "}\n" + }); +} + +public void testBug419048_2() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import java.util.stream.*;\n" + + "public class X {\n" + + " public void test() {\n" + + " List roster = new ArrayList<>();\n" + + " \n" + + " Map map = \n" + + " roster\n" + + " .stream()\n" + + " .collect(\n" + + " Collectors.toMap(\n" + + " Person::getLast,\n" + + " Function.identity()\n" + + " ));\n" + + " }\n" + + "}\n" + + "class Person {\n" + + " public String getLast() { return null; }\n" + + "}\n" + }); +} + +public void testBug419048_3() { + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import java.util.stream.*;\n" + + "public class X {\n" + + " public void test() {\n" + + " List roster = new ArrayList<>();\n" + + " \n" + + " Map map = \n" + + " roster\n" + + " .stream()\n" + + " .collect(\n" + + " Collectors.toMap(\n" + + " new Function() {\n" + + " public String apply(Person p) { \n" + + " return p.getLast(); \n" + + " } \n" + + " },\n" + + " Function.identity()\n" + + " ));\n" + + " }\n" + + "}\n" + + "class Person {\n" + + " public String getLast() { return null; }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424226, [1.8] Cannot use static method from an interface in static method reference +public void test424226() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void fun1() {\n" + + " FI fi = I::staticMethod; \n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface FI {\n" + + " void foo(); \n" + + "}\n" + + "interface I {\n" + + " static FI staticMethod() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=423684, [1.8][compiler] IllegalAccessError using functional consumer calling inherited method +public void test423684() { + runConformTest( + new String[] { + "Test.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import mypackage.MyPublicClass;\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " doesWork();\n" + + " doesNotWork();\n" + + " }\n" + + " public static void doesNotWork() {\n" + + " MyPublicClass victim = new MyPublicClass();\n" + + " List items = Arrays.asList(\"first\", \"second\", \"third\");\n" + + " items.forEach(victim::doSomething); //illegal access error here\n" + + " }\n" + + " public static void doesWork() {\n" + + " MyPublicClass victim = new MyPublicClass();\n" + + " List items = Arrays.asList(\"first\", \"second\", \"third\");\n" + + " for (String item : items) {\n" + + " victim.doSomething(item);\n" + + " }\n" + + " }\n" + + "}\n", + "mypackage/MyPublicClass.java", + "package mypackage;\n" + + "class MyPackagePrivateBaseClass {\n" + + " public void doSomething(String input) {\n" + + " System.out.println(input);\n" + + " }\n" + + "}\n" + + "public class MyPublicClass extends MyPackagePrivateBaseClass {\n" + + "}\n" + }, + "first\n" + + "second\n" + + "third\n" + + "first\n" + + "second\n" + + "third"); +} +public void testBug424742() { + runNegativeTest( + new String[] { + "TestInlineLambdaArray.java", + "package two.test;\n" + + "\n" + + "class TestInlineLambdaArray {\n" + + " TestInlineLambdaArray h = new TestInlineLambdaArray(x -> x++); // [9]\n" + + " public TestInlineLambda(FI fi) {}\n" + + "}\n" + + "\n" + + "interface FI {\n" + + " void foo();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in TestInlineLambdaArray.java (at line 4)\n" + + " TestInlineLambdaArray h = new TestInlineLambdaArray(x -> x++); // [9]\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor TestInlineLambdaArray(( x) -> {}) is undefined\n" + + "----------\n" + + "2. ERROR in TestInlineLambdaArray.java (at line 5)\n" + + " public TestInlineLambda(FI fi) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424589, [1.8][compiler] NPE in TypeSystem.getUnannotatedType +public void test424589() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.Collection;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.Set;\n" + + "public class X {\n" + + " public static >\n" + + " Y foo(Supplier y) {\n" + + " return null;\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " Set x = foo(Set::new);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Set x = foo(Set::new);\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " Set x = foo(Set::new);\n" + + " ^^^\n" + + "Cannot instantiate the type Set\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425152, [1.8] [compiler] NPE in LambdaExpression.analyzeCode +public void test425152() { + runConformTest( + new String[] { + "Main.java", + "interface Base { \n" + + " Base get(int x);\n" + + "}\n" + + "class Main {\n" + + " Base foo(Base b) { \n" + + " return null; \n" + + " }\n" + + " void bar(Base b) { }\n" + + " void testCase() {\n" + + " bar(foo((int p)->null));\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425512, [1.8][compiler] Arrays should be allowed in intersection casts +public void test425512() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = (int [] & Cloneable & Serializable) new int[5];\n" + + " System.out.println(a.length);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int [] a = (int [] & Cloneable & Serializable) new int[5];\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Arrays are not allowed in intersection cast operator\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424628, [1.8][compiler] Multiple method references to inherited method throws LambdaConversionException +public void test424628() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static interface Consumer {\n" + + " void accept(T t);\n" + + " }\n" + + " \n" + + " public static class Base {\n" + + " public void method () { System.out.println(123); }\n" + + " }\n" + + " public static class Foo extends Base {}\n" + + " public static class Bar extends Base {}\n" + + "\n" + + " public static void main (String[] args) {\n" + + " Consumer foo = Foo::method;\n" + + " Consumer bar = Bar::method;\n" + + " foo.accept(new Foo());\n" + + " bar.accept(new Bar());\n" + + " }\n" + + "}\n", + }, + "123\n123"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425712, [1.8][compiler] Valid program rejected by the compiler. +public void test425712() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " {\n" + + " bar( () -> (char) 0); // [1]\n" + + " }\n" + + " void bar(FB fb) { }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + + "interface FB {\n" + + " byte foo();\n" + + "}\n", + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426074, [1.8][compiler] 18.5.2 Functional interface parameterization inference problem with intersection types. +public void test426074() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Functional {\n" + + " void foo(T t);\n" + + "}\n" + + "interface I { }\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Functional f = (Functional & I) (X c) -> {\n" + + " System.out.println(\"main\");\n" + + " };\n" + + " f.foo(null);\n" + + " }\n" + + "}\n", + }, + "main"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426411, [1.8][compiler] NoSuchMethodError at runtime due to emission order of casts in intersection casts +public void test426411() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X {\n" + + " public static void main(String argv[]) throws Exception {\n" + + " ((Serializable & AutoCloseable) (() -> {})).close();\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426411, [1.8][compiler] NoSuchMethodError at runtime due to emission order of casts in intersection casts +public void test426411b() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "interface AnotherAutoCloseable extends AutoCloseable {}\n" + + "public class X {\n" + + " public static void main(String argv[]) throws Exception {\n" + + " ((Serializable & AnotherAutoCloseable) (() -> {})).close();\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426411, [1.8][compiler] NoSuchMethodError at runtime due to emission order of casts in intersection casts +public void test426411c() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X {\n" + + " public static void main(String argv[]) throws Exception {\n" + + " ((AutoCloseable & Serializable) (() -> {})).close();\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426411, [1.8][compiler] NoSuchMethodError at runtime due to emission order of casts in intersection casts +public void test426411d() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "interface AnotherAutoCloseable extends AutoCloseable {}\n" + + "public class X {\n" + + " public static void main(String argv[]) throws Exception {\n" + + " ((AnotherAutoCloseable & Serializable) (() -> {})).close();\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426411, [1.8][compiler] NoSuchMethodError at runtime due to emission order of casts in intersection casts +public void test426411e() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "interface I {}\n" + + "interface J extends I {\n" + + " static final int xyz = 99;\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) throws Exception {\n" + + " J j = new J() {};\n" + + " System.out.println(((I & J) j).xyz);\n" + + " }\n" + + "}\n", + }, + "99"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426411, [1.8][compiler] NoSuchMethodError at runtime due to emission order of casts in intersection casts +public void test426411f() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "interface I {}\n" + + "interface J extends I {\n" + + " final int xyz = 99;\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) throws Exception {\n" + + " J j = new J() {};\n" + + " System.out.println(((I & J) j).xyz);\n" + + " }\n" + + "}\n", + }, + "99"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426086, [1.8] LambdaConversionException when method reference to an inherited method is invoked from sub class +public void test426086() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Functional {\n" + + " Long square(Integer a);\n" + + "}\n" + + "public class X {\n" + + " static class Base {\n" + + " private Long square(Integer a) {\n" + + " return Long.valueOf(a*a);\n" + + " } \n" + + " }\n" + + " static class SubClass extends Base {\n" + + " public Long callSquare(Integer i) {\n" + + " Functional fi = SubClass.super::square;\n" + + " return fi.square(i);\n" + + " }\n" + + " }\n" + + " public static void main(String argv[]) throws Exception {\n" + + " System.out.println(new SubClass().callSquare(-3));\n" + + " }\n" + + "}\n", + }, + "9"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426086, [1.8] LambdaConversionException when method reference to an inherited method is invoked from sub class +public void test426086a() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "interface Functional {\n" + + " Long square(Integer a);\n" + + "}\n" + + "public class X {\n" + + " static class Base {\n" + + " private Long square(Integer a) {\n" + + " return Long.valueOf(a*a);\n" + + " } \n" + + " }\n" + + " static class SubClass extends Base {\n" + + " public Long callSquare(Integer i) {\n" + + " Functional fi = super::square;\n" + + " return fi.square(i);\n" + + " }\n" + + " }\n" + + " public static void main(String argv[]) throws Exception {\n" + + " System.out.println(new SubClass().callSquare(-3));\n" + + " }\n" + + "}\n", + }, + "9"); +} +// Bug 406744 - [1.8][compiler][codegen] LambdaConversionException seen when method reference targets a varargs method. +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406744 +public void test406744a() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(Integer a1, Integer a2, String a3);\n" + + "}\n" + + "class Y {\n" + + " static void m(Number a1, Object... rest) {\n" + + " System.out.println(a1);\n" + + " print(rest);\n" + + " }\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y::m;\n" + + " i.foo(10, 20, \"10, 20\");\n" + + " }\n" + + "}\n", + }, + "10\n" + + "20\n" + + "10, 20" + ); +} +public void test406744b() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo(Integer a1, Integer a2, String a3);\n" + + "}\n" + + "class Y {\n" + + " static int m(Number a1, Object... rest) {\n" + + " System.out.println(a1);\n" + + " print(rest);\n" + + " return 1;\n" + + " }\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y::m;\n" + + " i.foo(10, 20, \"10, 20\");\n" + + " }\n" + + "}\n", + }, + "10\n" + + "20\n" + + "10, 20" + ); +} +public void test406744c() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(Integer a1, Integer a2, String a3);\n" + + "}\n" + + "class Y {\n" + + " Y(Number a1, Object... rest) {\n" + + " System.out.println(a1);\n" + + " print(rest);\n" + + " }\n" + + " static void m(Number a1, Object... rest) {\n" + + " System.out.println(a1);\n" + + " print(rest);\n" + + " }\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = Y::new;\n" + + " i.foo(10, 20, \"10, 20\");\n" + + " }\n" + + "}\n", + }, + "10\n" + + "20\n" + + "10, 20" + ); +} +public void test406744d() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int a1, Integer a2, String a3);\n" + + "}\n" + + "interface Y {\n" + + " static void m(float a1, Object... rest) {\n" + + " System.out.println(a1);\n" + + " print(rest);\n" + + " }\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + "}\n" + + "public interface X extends Y{\n" + + " public static void main(String [] args) {\n" + + " I i = Y::m;\n" + + " i.foo(10, 20, \"10, 20\");\n" + + " }\n" + + "}\n", + }, + "10.0\n" + + "20\n" + + "10, 20" + ); +} +public void test406744e() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String method(int a);\n" + + "}\n" + + "class C {\n" + + " static String foo(Integer... i) {\n" + + " return \"foo\";\n" + + " }\n" + + " static String goo(Integer bi, Integer... i) {\n" + + " return \"bar\";\n" + + " }\n" + + " public void foo() {\n" + + " I i;\n" + + " i = C::foo;\n" + + " System.out.println(i.method(0));\n" + + " i = C::goo;\n" + + " System.out.println(i.method(0));\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new C().foo();\n" + + " }\n" + + "}\n", + }, + "foo\n" + + "bar" + ); +} +public void test406744f() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(Integer a1, Integer a2, String a3);\n" + + "}\n" + + "class Y {\n" + + " void m(Number a1, Object... rest) {\n" + + " System.out.println(a1);\n" + + " print(rest);\n" + + " }\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " I i = super::m;\n" + + " i.foo(10, 20, \"10, 20\");\n" + + " }\n" + + "}\n", + }, + "10\n" + + "20\n" + + "10, 20" + ); +} +public void test406744g() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(Integer a1, Integer a2, String a3);\n" + + "}\n" + + "class Y {\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " private void m(Number a1, Object... rest) {\n" + + " System.out.println(a1);\n" + + " print(rest);\n" + + " }\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " I i = this::m;\n" + + " i.foo(10, 20, \"10, 20\");\n" + + " }\n" + + "}\n", + }, + "10\n" + + "20\n" + + "10, 20" + ); +} +public void test406744h() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int [] ia);\n" + + "}\n" + + "class Y {\n" + + " void m(Object... rest) {\n" + + " System.out.println(\"Hello \" + rest.length);\n" + + " }\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " public static void main(String [] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " I i = super::m;\n" + + " i.foo(new int [0]);\n" + + " }\n" + + "}\n", + }, + "Hello 1" + ); +} +public void test406744i() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int [] ia);\n" + + "}\n" + + "interface I1 {\n" + + " void foo(int [] ia);\n" + + "}\n" + + "class Y {\n" + + " void m(Object... rest) {\n" + + " System.out.println(\"Hello \" + rest.length);\n" + + " }\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " public static void main(String [] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " I i = super::m;\n" + + " i.foo(new int [0]);\n" + + " I1 i1 = super::m;\n" + + " i1.foo(new int [0]);\n" + + " }\n" + + "}\n", + }, + "Hello 1\n" + + "Hello 1" + ); +} +public void test406744j() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int [] ia);\n" + + "}\n" + + "class Y {\n" + + " void m(Object... rest) {\n" + + " I i = this::n;\n" + + " i.foo(new int [0]);\n" + + " }\n" + + " void n(Object... rest) {\n" + + " System.out.println(\"Hello \" + rest.length);\n" + + " }\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " public static void main(String [] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " I i = super::m;\n" + + " i.foo(new int [0]);\n" + + " }\n" + + "}\n", + }, + "Hello 1" + ); +} +public void test406744k() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int [] ia);\n" + + "}\n" + + "class Y {\n" + + " static void m(Object... rest) {\n" + + " System.out.println(\"Hello \" + rest.length);\n" + + " }\n" + + " static void print (Object [] o) {\n" + + " for (int i = 0; i < o.length; i++)\n" + + " System.out.println(o[i]);\n" + + " }\n" + + "}\n" + + "class Y1 extends Y { }\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " I i = Y::m;\n" + + " i.foo(new int [0]);\n" + + " i = Y1::m;\n" + + " i.foo(new int [0]);\n" + + " }\n" + + "}\n", + }, + "Hello 1\n" + + "Hello 1" + ); +} +public void test406744l() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(Integer i);\n" + + "}\n" + + "public class X {\n" + + " static void foo(int ... x) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = X::foo;\n" + + " i.foo(1);\n" + + " System.out.println(\"Hello\");\n" + + "}\n" + + "}\n", + }, + "Hello" + ); +} +public void test406744m() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int i);\n" + + "}\n" + + "public class X {\n" + + " static void foo(int ... x) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = X::foo;\n" + + " i.foo(1);\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + "}\n", + }, + "Hello" + ); +} +public void test406744n() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(Integer i);\n" + + "}\n" + + "class Base {\n" + + " void foo(Object ...objects) {\n" + + " System.out.println(\"Ok\");\n" + + " }\n" + + "}\n" + + "public class X extends Base {\n" + + " void foo(Object... objects) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().goo();\n" + + " }\n" + + " void goo() {\n" + + " I i = super::foo;\n" + + " i.foo(10);\n" + + " }\n" + + "}\n", + }, + "Ok" + ); +} +public void test406744o() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "class Base {\n" + + " public void foo(int ...is) {\n" + + " System.out.println(\"foo\");\n" + + " }\n" + + "}\n" + + "public class X extends Base {\n" + + " public static void main( String[] args ) {\n" + + " I i = new X()::foo;\n" + + " i.foo(10);\n" + + " }\n" + + "}\n", + }, + "foo" + ); +} +public void test406744p() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X {\n" + + " private void foo(int ...is) {\n" + + " System.out.println(\"foo\");\n" + + " }\n" + + " public static void main(String[] args ) {\n" + + " new X().new Y().foo();\n" + + " }\n" + + " class Y extends X {\n" + + " void foo() {\n" + + " I i = new X()::foo;\n" + + " i.foo(10);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "foo" + ); +} +public void test406744q() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "class Y {\n" + + " public static void foo(int ...is) {\n" + + " System.out.println(\"Y.foo\");\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void foo(int ...is) {\n" + + " System.out.println(\"X.foo\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = X::foo;\n" + + " i.foo(10);\n" + + " i = Y::foo;\n" + + " i.foo(20);\n" + + " }\n" + + "}\n", + }, + "X.foo\n" + + "Y.foo" + ); +} +public void test406744r() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int t, int [] ia);\n" + + "}\n" + + "public class X {\n" + + " public static void foo(Integer i, int ...is) {\n" + + " System.out.println(\"Y.foo\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = X::foo;\n" + + " i.foo(10, null);\n" + + " }\n" + + "}\n", + }, + "Y.foo" + ); +} +public void test406744s() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X foo(int x);\n" + + "}\n" + + "public class X {\n" + + " class Y extends X {\n" + + " Y(int ... x) {\n" + + " System.out.println(\"Y::Y\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args ) {\n" + + " new X().goo();\n" + + " }\n" + + " void goo() {\n" + + " I i = Y::new;\n" + + " i.foo(10);\n" + + " }\n" + + "}\n", + }, + "Y::Y" + ); +} +public void test406744t() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X foo(int x);\n" + + "}\n" + + "public class X {\n" + + " class Y extends X {\n" + + " Y(int ... x) {\n" + + " System.out.println(\"Y::Y\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args ) {\n" + + " System.out.println(\"Hello\");\n" + + " new X().goo();\n" + + " }\n" + + " void goo() {\n" + + " I i = Y::new;\n" + + " i.foo(10);\n" + + " }\n" + + "}\n", + }, + "Hello\n" + + "Y::Y" + ); +} +public void test406744u() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X foo(int x);\n" + + "}\n" + + "public class X { \n" + + " class Y extends X {\n" + + " Y(int ... x) {\n" + + " System.out.println(\"Y::Y\"); \n" + + " }\n" + + " }\n" + + " public static void main(String[] args ) {\n" + + " System.out.println(\"Hello\");\n" + + " new X().goo(); \n" + + " }\n" + + " void goo() {\n" + + " I i = Y::new;\n" + + " i.foo(10); \n" + + " }\n" + + "}\n", + }, + "Hello\n" + + "Y::Y" + ); +} +public void test406744v() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X foo();\n" + + "}\n" + + "public class X {\n" + + " private X(int ... is) {\n" + + " System.out.println(\"X::X\");\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().new Y().goo();\n" + + " }\n" + + " public class Y {\n" + + " public void goo() {\n" + + " I i = X::new; \n" + + " i.foo();\n" + + " } \n" + + " }\n" + + "}\n", + }, + "X::X\n" + + "X::X" + ); +} +public void test406744w() { + this.runConformTest( + new String[] { + "p2/B.java", + "package p2;\n" + + "import p1.*;\n" + + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " void foo(int x);\n" + + "}\n" + + "public class B extends A {\n" + + " class Y {\n" + + " void g() {\n" + + " I i = B::foo;\n" + + " i.foo(10);\n" + + " J j = new B()::goo;\n" + + " j.foo(10);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new B().new Y().g();\n" + + " }\n" + + "}\n", + "p1/A.java", + "package p1;\n" + + "import p2.*;\n" + + "public class A {\n" + + " protected static void foo(int ... is) {\n" + + " System.out.println(\"A's static foo\");\n" + + " }\n" + + " protected void goo(int ... is) {\n" + + " System.out.println(\"A's instance goo\");\n" + + " }\n" + + "}\n" + }, + "A\'s static foo\n" + + "A\'s instance goo" + ); +} +public void test406744x() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X {\n" + + " class Y {\n" + + " void goo() {\n" + + " I i = X::goo;\n" + + " i.foo(10);\n" + + " }\n" + + " }\n" + + " private static void goo(Integer i) {\n" + + " System.out.println(i);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().new Y().goo(); \n" + + " }\n" + + "}\n" + }, + "10" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427483, [Java 8] Variables in lambdas sometimes can't be resolved +public void test427483() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.TreeSet;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new TreeSet<>((String qn1, String qn2) -> {\n" + + " boolean b = true;\n" + + " System.out.println(b); // ok\n" + + " if (b) {\n" + + " } // Eclipse says: b cannot be resolved or is not a field\n" + + " return qn1.compareTo(qn2);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427627, [1.8] List.toArray not compiled correctly (NoSuchMethodError) within Lambda +public void test427627() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Runnable r = () -> {\n" + + " List keys = new ArrayList<>();\n" + + "\n" + + " associate(\"Test\", keys.toArray(new SourceKey[keys.size()]));\n" + + " };\n" + + " r.run();\n" + + " }\n" + + " private static void associate(String o, SourceKey... keys) {\n" + + " System.out.println(o);\n" + + " System.out.println(keys.length);\n" + + " }\n" + + " public class SourceKey {\n" + + " public SourceKey(Object source, Object key) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "Test\n0" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427744, [1.8][compiler][regression] Issue with boxing compatibility in poly conditional +public void test427744() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String argv[]) {\n" + + " int i = ((I) (x) -> { return 999; }).foo(true ? 0 : (Comparable) null);\n" + + " System.out.println(i);\n" + + " }\n" + + " interface I {\n" + + " int foo (Comparable arg); \n" + + " default int foo (Object arg) { \n" + + " return 0;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "999" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427962, [1.8][compiler] Stream#toArray(String[]::new) not inferred without help +public void test427962() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "import java.util.function.IntFunction;\n" + + "import java.util.stream.Stream;\n" + + "import java.util.stream.IntStream;\n" + + "public class X {\n" + + " static Stream objmap(Function p1, A[] p2) {return Stream.of(p2).map(p1);}\n" + + " static Stream intmap(IntFunction p1, int[] p2) {return IntStream.of(p2).mapToObj(p1);}\n" + + " public static void main(String[] args) {\n" + + " Integer[] p12 = {1, 2, 3};\n" + + " int[] p22 = {1, 2, 3};\n" + + " //works\n" + + " String[] a11 = objmap(String::valueOf, p12). toArray(String[]::new);\n" + + " String[] a21 = intmap(String::valueOf, p22). toArray(String[]::new);\n" + + " //does not work\n" + + " String[] a12 = objmap(String::valueOf, p12).toArray(String[]::new);\n" + + " String[] a22 = intmap(String::valueOf, p22).toArray(String[]::new);\n" + + " }\n" + + "}\n" + }, + "" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428112, [1.8][compiler] ClassCastException in ReferenceExpression.generateCode +public void test428112() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.Locale;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Locale.lookup(Stream.of( \"de\", \"*-CH\" ).map(Locale.LanguageRange::new).collect(Collectors.toList()), \n" + + " Arrays.asList(Locale.getAvailableLocales())));\n" + + " }\n" + + "}\n" + }, + "de" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428003, [1.8][compiler] Incorrect error on lambda expression when preceded by another explicit lambda expression +public void test428003() { // extracted small test + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Arrays.sort(args, (String x, String y) -> x.length() - y.length());\n" + + " Arrays.sort(args, (x, y) -> Integer.compare(x.length(), y.length()));\n" + + " }\n" + + "}\n" + }, + "" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428003, [1.8][compiler] Incorrect error on lambda expression when preceded by another explicit lambda expression +public void test428003a() { // full test case + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String[] words = {\"java\", \"interface\", \"lambda\", \"expression\" };\n" + + " Arrays.sort(words, (String word1, String word2) -> {\n" + + " if (word1.length() < word2.length())\n" + + " return -1;\n" + + " else if (word1.length() > word2.length())\n" + + " return 1;\n" + + " else\n" + + " return 0;\n" + + " });\n" + + " for (String word : words)\n" + + " System.out.println(word);\n" + + " words = new String [] {\"java\", \"interface\", \"lambda\", \"expression\" };\n" + + " Arrays.sort(words, (word1, word2) -> Integer.compare(word1.length(), word2.length()));\n" + + " for (String word : words)\n" + + " System.out.println(word);\n" + + " words = new String [] {\"java\", \"interface\", \"lambda\", \"expression\" };\n" + + " Arrays.sort(words, (String word1, String word2) -> Integer.compare(word1.length(), word2.length()));\n" + + " for (String word : words)\n" + + " System.out.println(word);\n" + + " }\n" + + " }\n" + }, + "java\n" + + "lambda\n" + + "interface\n" + + "expression\n" + + "java\n" + + "lambda\n" + + "interface\n" + + "expression\n" + + "java\n" + + "lambda\n" + + "interface\n" + + "expression" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428261, [1.8][compiler] Incorrect error: No enclosing instance of the type X is accessible in scope +public void test428261() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X foo(int a);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = \"Blah\";\n" + + " class Local extends X {\n" + + " Local(int a) {\n" + + " System.out.println(a);\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " I i = Local::new; // Incorrect error here.\n" + + " i.foo(10);\n" + + " }\n" + + "}\n" + }, + "10\n" + + "Blah" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428261, [1.8][compiler] Incorrect error: No enclosing instance of the type X is accessible in scope +public void test428261a() { + this.runConformTest( + false, + JavacHasABug.JavacBugFixed_901, + new String[] { + "X.java", + "interface I {\n" + + " X foo(int a);\n" + + "}\n" + + "public class X {\n" + + " void goo() {\n" + + " class Local extends X {\n" + + " Local(int a) {\n" + + " System.out.println(a);\n" + + " }\n" + + " }\n" + + " I i = Local::new;\n" + + " i.foo(10);\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " new X().goo();\n" + + " }\n" + + "}\n" + }, + "10"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428552, [1.8][compiler][codegen] Serialization does not work for method references +public void test428552() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " interface Example extends Serializable {\n" + + " String convert(Object o);\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " Example e=Object::toString;\n" + + " try(ObjectOutputStream os=new ObjectOutputStream(new ByteArrayOutputStream())) {\n" + + " os.writeObject(e);\n" + + " }\n" + + " System.out.println(\"No exception !\");\n" + + " }\n" + + "}\n" + }, + "No exception !", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution.); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428642, [1.8][compiler] java.lang.IllegalArgumentException: Invalid lambda deserialization exception +public void test428642() { + this.runConformTest( + new String[] { + "QuickSerializedLambdaTest.java", + "import java.io.*;\n" + + "import java.util.function.IntConsumer;\n" + + "public class QuickSerializedLambdaTest {\n" + + " interface X extends IntConsumer,Serializable{}\n" + + " public static void main(String[] args) throws IOException, ClassNotFoundException {\n" + + " X x1 = i -> System.out.println(i);// lambda expression\n" + + " X x2 = System::exit; // method reference\n" + + " ByteArrayOutputStream debug=new ByteArrayOutputStream();\n" + + " try(ObjectOutputStream oo=new ObjectOutputStream(debug))\n" + + " {\n" + + " oo.writeObject(x1);\n" + + " oo.writeObject(x2);\n" + + " }\n" + + " try(ObjectInputStream oi=new ObjectInputStream(new ByteArrayInputStream(debug.toByteArray())))\n" + + " {\n" + + " X x=(X)oi.readObject();\n" + + " x.accept(42);// shall print 42\n" + + " x=(X)oi.readObject();\n" + + " x.accept(0);// shall exit\n" + + " }\n" + + " throw new AssertionError(\"should not reach this point\");\n" + + " }\n" + + "}\n" + }, + "42", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution.); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429112, [1.8][compiler] Exception when compiling Serializable array constructor reference +public void test429112() { + this.runConformTest( + new String[] { + "ArrayConstructorReference.java", + "import java.io.Serializable;\n" + + "import java.util.function.IntFunction;\n" + + "public class ArrayConstructorReference {\n" + + " interface IF extends IntFunction, Serializable {}\n" + + " public static void main(String[] args) {\n" + + " IF factory=String[][][]::new;\n" + + " Object o = factory.apply(10);\n" + + " System.out.println(o.getClass());\n" + + " String [][][] sa = (String [][][]) o;\n" + + " System.out.println(sa.length);\n" + + " }\n" + + "}\n" + }, + "class [[[Ljava.lang.String;\n" + + "10"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429112, [1.8][compiler] Exception when compiling Serializable array constructor reference +public void test429112a() { + this.runConformTest( + new String[] { + "ArrayConstructorReference.java", + "import java.io.Serializable;\n" + + "import java.util.function.IntFunction;\n" + + "public class ArrayConstructorReference {\n" + + " interface IF extends IntFunction, Serializable {}\n" + + " public static void main(String[] args) {\n" + + " IF factory=java.util.function.IntFunction[][][]::new;\n" + + " Object o = factory.apply(10);\n" + + " System.out.println(o.getClass());\n" + + " java.util.function.IntFunction[][][] sa = (java.util.function.IntFunction[][][]) o;\n" + + " System.out.println(sa.length);\n" + + " }\n" + + "}\n" + }, + "class [[[Ljava.util.function.IntFunction;\n" + + "10"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429112, [1.8][compiler] Exception when compiling Serializable array constructor reference +public void test429112b() { + this.runConformTest( + new String[] { + "ArrayConstructorReference.java", + "import java.io.Serializable;\n" + + "import java.util.function.IntFunction;\n" + + "public class ArrayConstructorReference {\n" + + " interface IF extends IntFunction, Serializable {}\n" + + " public static void main(String[] args) {\n" + + " IF factory=java.util.function.IntFunction[]::new;\n" + + " Object o = factory.apply(10);\n" + + " System.out.println(o.getClass());\n" + + " java.util.function.IntFunction[] sa = (java.util.function.IntFunction[]) o;\n" + + " System.out.println(sa.length);\n" + + " }\n" + + "}\n" + }, + "class [Ljava.util.function.IntFunction;\n" + + "10"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429112, [1.8][compiler] Exception when compiling Serializable array constructor reference +public void test429112c() { + this.runConformTest( + new String[] { + "ArrayConstructorReference.java", + "import java.io.Serializable;\n" + + "import java.util.function.IntFunction;\n" + + "public class ArrayConstructorReference {\n" + + " interface IF extends IntFunction, Serializable {}\n" + + " public static void main(String[] args) {\n" + + " IF factory=String[]::new;\n" + + " Object o = factory.apply(10);\n" + + " System.out.println(o.getClass());\n" + + " String [] sa = (String []) o;\n" + + " System.out.println(sa.length);\n" + + " }\n" + + "}\n" + }, + "class [Ljava.lang.String;\n" + + "10"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " Function, String> func = List::toString;\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " }\n" + + "}\n" + }, + "[a, b]", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, - [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "interface I {\n" + + " List getList();\n" + + "}\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " I i = ArrayList::new;\n" + + " System.out.println(i.getList());\n" + + " }\n" + + "}\n" + }, + "[]", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, - [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "interface I {\n" + + " ArrayList getList();\n" + + "}\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " I i = ArrayList::new;\n" + + " System.out.println(i.getList());\n" + + " }\n" + + "}\n" + }, + "[]", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857c() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.ArrayList;\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " Function, String> func = List::toString;\n" + + " System.out.println(func.apply(new ArrayList<>(Arrays.asList(\"a\", \"b\"))));\n" + + " }\n" + + "}\n" + }, + "[a, b]", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429763, [1.8][compiler] Incompatible type specified for lambda expression's parameter +public void test429763() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " final int i = new Test().test((Byte b) -> (int) b);\n" + + " } catch (NullPointerException e) {\n" + + " System.out.println(\"NPE\");\n" + + " }\n" + + " }\n" + + " static class Test {\n" + + " R test(Function f) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "NPE"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429763, [1.8][compiler] Incompatible type specified for lambda expression's parameter +public void test429763a() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " // does not compile\n" + + " new Test().test((Byte b) -> (int) b);\n" + + " }\n" + + " static class Test {\n" + + " void test(Function f) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429759, [1.8][compiler] Lambda expression's signature matching error +public void test429759() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "import java.util.function.Supplier;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final int i = new Test().test(\"\", (String s) -> 1);\n" + + " }\n" + + " static class Test {\n" + + " R test(T t, Supplier s) {\n" + + " return s.get();\n" + + " }\n" + + " R test(T t, Function f) {\n" + + " return f.apply(t);\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429948, Unhandled event loop exception is thrown when a lambda expression is nested +public void test429948() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Supplier;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " execute(() -> {\n" + + " executeInner(() -> {\n" + + " });\n" + + " return null;\n" + + " });\n" + + " System.out.println(\"done\");\n" + + " }\n" + + " static R execute(Supplier supplier) {\n" + + " return null;\n" + + " }\n" + + " static void executeInner(Runnable callback) {\n" + + " }\n" + + "}\n" + }, + "done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429969, [1.8][compiler] Possible RuntimeException in Lambda tangles ECJ +public void test429969() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.Optional;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final String s = Arrays.asList(\"done\").stream().reduce(null, (s1,s2) -> {\n" + + " // THE FOLLOWING LINE CAUSES THE PROBLEM\n" + + " require(s1 != null || s2 != null, \"both strings are null\");\n" + + " return (s1 != null) ? s1 : s2;\n" + + " }, (s1,s2) -> (s1 != null) ? s1 : s2);\n" + + " \n" + + " System.out.println(s);\n" + + " }\n" + + " static void require(boolean condition, String msg) throws RuntimeException {\n" + + " if (!condition) {\n" + + " throw new RuntimeException(msg);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430015, [1.8] NPE trying to disassemble classfile with lambda method and MethodParameters +public void test430015() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Parameter;\n" + + "import java.util.Arrays;\n" + + "import java.util.function.IntConsumer;\n" + + "public class X {\n" + + " IntConsumer xx(int a) {\n" + + " return i -> { };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Method[] methods = X.class.getDeclaredMethods();\n" + + " for (Method method : methods) {\n" + + " if (method.getName().contains(\"lambda\")) {\n" + + " Parameter[] parameters = method.getParameters();\n" + + " System.out.println(Arrays.asList(parameters));\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "[int arg0]"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430040, [1.8] [compiler] Type Type mismatch: cannot convert from Junk13.ExpressionHelper to Junk13.ExpressionHelper +public void test430040() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + " class Observable {}\n" + + " class ObservableValue {}\n" + + " interface InvalidationListener {\n" + + " public void invalidated(Observable observable);\n" + + " }\n" + + " public interface ChangeListener {\n" + + " void changed(ObservableValue observable, T oldValue, T newValue);\n" + + " }\n" + + " static class ExpressionHelper {}\n" + + " public static ExpressionHelper addListener(ExpressionHelper helper, ObservableValue observable, InvalidationListener listener) {\n" + + " return helper;\n" + + " }\n" + + " public static ExpressionHelper addListener(ExpressionHelper helper, ObservableValue observable, ChangeListener listener) {\n" + + " return helper;\n" + + " }\n" + + " private ExpressionHelper helper;\n" + + " public void junk() {\n" + + " helper = (ExpressionHelper) addListener(helper, null, (Observable o) -> {throw new RuntimeException();});\n" + + " helper = addListener(helper, null, (Observable o) -> {throw new RuntimeException();});\n" + + " }\n" + + "}\n" + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430043, [1.8][compiler] Cannot infer type arguments for Junk14<> +public void test430043() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.IOException;\n" + + "import java.io.StringReader;\n" + + "import java.nio.file.Files;\n" + + "import java.text.MessageFormat;\n" + + "import java.util.*;\n" + + "import java.util.function.Function;\n" + + "import java.util.jar.Attributes;\n" + + "import java.util.jar.JarFile;\n" + + "import java.util.jar.Manifest;\n" + + "public class X {\n" + + " public X(String name, String description, String id, Class valueType, String[] fallbackIDs, Function, T> defaultValueFunction, boolean requiresUserSetting, Function stringConverter) {\n" + + " }\n" + + " public static final X NAME =\n" + + " new X<>(\n" + + " null,\n" + + " null,\n" + + " null,\n" + + " String.class,\n" + + " null,\n" + + " params -> {throw new IllegalArgumentException(\"junk14\");},\n" + + " true,\n" + + " s -> s\n" + + " );\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430035, [1.8][compiler][codegen] Bridge methods are not generated for lambdas/method references +public void test430035() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "public class X {\n" + + " interface StringConsumer extends Consumer {\n" + + " void accept(String t);\n" + + " }\n" + + " public static void main(String... x) {\n" + + " StringConsumer c = s->System.out.println(\"m(\"+s+')');\n" + + " c.accept(\"direct call\");\n" + + " Consumer c4b=c;\n" + + " c4b.accept(\"bridge method\");\n" + + " }\n" + + "}\n" + }, + "m(direct call)\n" + + "m(bridge method)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430035, [1.8][compiler][codegen] Bridge methods are not generated for lambdas/method references +public void test430035a() { // test reference expressions requiring bridges. + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "public class X {\n" + + " interface StringConsumer extends Consumer {\n" + + " void accept(String t);\n" + + " }\n" + + " static void m(String s) { System.out.println(\"m(\"+s+\")\"); } \n" + + " public static void main(String... x) {\n" + + " StringConsumer c = X::m;\n" + + " c.accept(\"direct call\");\n" + + " Consumer c4b=c;\n" + + " c4b.accept(\"bridge method\");\n" + + " }\n" + + "}\n" + }, + "m(direct call)\n" + + "m(bridge method)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430035, [1.8][compiler][codegen] Bridge methods are not generated for lambdas/method references +public void test430035b() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(T t);\n" + + "}\n" + + "interface J {\n" + + " void foo(T t);\n" + + "}\n" + + "interface K extends I, J {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String... x) {\n" + + " K k = s -> System.out.println(\"m(\"+s+')');\n" + + " k.foo(\"direct call\");\n" + + " J j = k;\n" + + " j.foo(\"bridge method\");\n" + + " I i = k;\n" + + " i.foo(\"bridge method\");\n" + + " }\n" + + "}\n" + }, + "m(direct call)\n" + + "m(bridge method)\n" + + "m(bridge method)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430035, [1.8][compiler][codegen] Bridge methods are not generated for lambdas/method references +public void test430035c() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String t, T u);\n" + + "}\n" + + "interface J {\n" + + " void foo(T t, String u);\n" + + "}\n" + + "interface K extends I, J {\n" + + " void foo(String t, String u);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String... x) {\n" + + " K k = (s, u) -> System.out.println(\"m(\"+ s + u + ')');\n" + + " k.foo(\"direct\", \" call\");\n" + + " J j = k;\n" + + " j.foo(\"bridge\", \" method(j)\");\n" + + " I i = k;\n" + + " i.foo(\"bridge\", \" method(i)\");\n" + + " }\n" + + "}\n" + }, + "m(direct call)\n" + + "m(bridge method(j))\n" + + "m(bridge method(i))"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430035, [1.8][compiler][codegen] Bridge methods are not generated for lambdas/method references +public void test430035d() { // 8b131 complains of ambiguity. + this.runConformTest( + false, + EclipseHasABug.EclipseBug510528, + new String[] { + "X.java", + "interface I {\n" + + " void foo(String t, T u);\n" + + "}\n" + + "interface J {\n" + + " void foo(T t, String u);\n" + + "}\n" + + "interface K extends I, J {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String... x) {\n" + + " K k = (s, u) -> System.out.println(\"m(\"+ s + u + ')');\n" + + " k.foo(\"direct\", \" call\");\n" + + " J j = k;\n" + + " j.foo(\"bridge\", \" method(j)\");\n" + + " I i = k;\n" + + " i.foo(\"bridge\", \" method(i)\");\n" + + " }\n" + + "}\n" + }, + "m(direct call)\n" + + "m(bridge method(j))\n" + + "m(bridge method(i))"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430035, [1.8][compiler][codegen] Bridge methods are not generated for lambdas/method references +public void test430035e() { // 8b131 complains of ambiguity in call. + this.runConformTest( + false, + EclipseHasABug.EclipseBug510528, + new String[] { + "X.java", + "interface I {\n" + + " Object foo(String t, T u);\n" + + "}\n" + + "interface J {\n" + + " String foo(T t, String u);\n" + + "}\n" + + "interface K extends I, J {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String... x) {\n" + + " K k = (s, u) -> s + u;\n" + + " System.out.println(k.foo(\"direct\", \" call\"));\n" + + " J j = k;\n" + + " System.out.println(j.foo(\"bridge\", \" method(j)\"));\n" + + " I i = k;\n" + + " System.out.println(i.foo(\"bridge\", \" method(i)\"));\n" + + " }\n" + + "}\n" + }, + "direct call\n" + + "bridge method(j)\n" + + "bridge method(i)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430035, [1.8][compiler][codegen] Bridge methods are not generated for lambdas/method references +public void test430035f() { // ensure co-variant return emits a bridge request. + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo(String t, String u);\n" + + "}\n" + + "interface J {\n" + + " String foo(String t, String u);\n" + + "}\n" + + "interface K extends I, J {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String... x) {\n" + + " K k = (s, u) -> s + u;\n" + + " System.out.println(k.foo(\"direct\", \" call\"));\n" + + " J j = k;\n" + + " System.out.println(j.foo(\"bridge\", \" method(j)\"));\n" + + " I i = k;\n" + + " System.out.println(i.foo(\"bridge\", \" method(i)\"));\n" + + " }\n" + + "}\n" + }, + "direct call\n" + + "bridge method(j)\n" + + "bridge method(i)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430241, [1.8][compiler] Raw return type results in incorrect covariant return bridge request to LambdaMetaFactory +public void test430241() { // ensure raw return type variant does not emit a bridge request. + this.runConformTest( + new String[] { + "X.java", + "interface K extends I, J {\n" + + "}\n" + + "interface I {\n" + + " Comparable foo();\n" + + "}\n" + + "interface J {\n" + + " Comparable foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " K k = () -> null;\n" + + " System.out.println(k.foo());\n" + + " }\n" + + "}\n" + }, + "null"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430310, [1.8][compiler] Functional interface incorrectly rejected as not being. +public void test430310() { + this.runConformTest( + new String[] { + "X.java", + "interface Func1 {\n" + + " R apply(T1 v1);\n" + + " void other();\n" + + "}\n" + + "@FunctionalInterface // spurious error: F1 is not a functional interface\n" + + "public interface X extends Func1 {\n" + + " default void other() {}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430310, [1.8][compiler] Functional interface incorrectly rejected as not being. +public void test430310a() { + this.runConformTest( + new String[] { + "X.java", + "@FunctionalInterface\n" + + "public interface X {\n" + + " R apply(T1 v1, T2 v2);\n" + + " default void other() {}\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430310, [1.8][compiler] Functional interface incorrectly rejected as not being. +public void test430310b() { + this.runConformTest( + new String[] { + "X.java", + "interface I1 {\n" + + " int foo(String s);\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface A1 extends I1 {\n" + + " @Override\n" + + " default int foo(String s) {\n" + + " return -1;\n" + + " }\n" + + " int foo(java.io.Serializable s);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430310, [1.8][compiler] Functional interface incorrectly rejected as not being. +public void test430310c() { + this.runConformTest( + new String[] { + "X.java", + "interface I2 {\n" + + " int foo(String s);\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface A2 extends I2 {\n" + + " @Override\n" + + " default int foo(String s) {\n" + + " return -1;\n" + + " }\n" + + " int bar(java.io.Serializable s);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432619, [1.8] Bogus error from method reference: "should be accessed in a static way" +public void test432619() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.BiConsumer;\n" + + "public interface X {\n" + + " static void foo() {\n" + + " BiConsumer biConsumer2 = Re2::accumulate;\n" + + " }\n" + + " static class Re2 {\n" + + " static void accumulate(double[][] container, Double value) {}\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432619, [1.8] Bogus error from method reference: "should be accessed in a static way" +public void test432619a() throws Exception { + this.runConformTest( + new String[] { + "StreamInterface.java", + "import java.util.Map;\n" + + "import java.util.stream.Collector;\n" + + "public interface StreamInterface {\n" + + " static class DoubleCo {\n" + + " private static class Re2 {\n" + + " static Map internalToMapToList2() {\n" + + " Collector toContainer1 = Collector.of(\n" + + " //The method supply() from the type StreamInterface.DoubleCo.Re2 should be accessed in a static way\n" + + " StreamInterface.DoubleCo.Re2::supply,\n" + + " //The method accumulate(double[][], Double) from the type StreamInterface.DoubleCo.Re2 should be accessed in a static way\n" + + " StreamInterface.DoubleCo.Re2::accumulate,\n" + + " //The method combine(double[][], double[][]) from the type StreamInterface.DoubleCo.Re2 should be accessed in a static way\n" + + " StreamInterface.DoubleCo.Re2::combine);\n" + + " Collector toContainer2 =\n" + + " //All 3 from above:\n" + + " Collector.of(DoubleCo.Re2::supply, DoubleCo.Re2::accumulate, DoubleCo.Re2::combine);\n" + + " return null;\n" + + " }\n" + + " private static double[][] supply() {\n" + + " return new double[64][];\n" + + " }\n" + + " private static void accumulate(double[][] container, Double value) {}\n" + + " private static double[][] combine(double[][] container, double[][] containerRight) {\n" + + " return new double[container.length + containerRight.length][];\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432682, [1.8][compiler] Type mismatch error with lambda expression +public void test432682() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Optional;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Optional userName = Optional.of(\"sa\");\n" + + " Optional password = Optional.of(\"sa\");\n" + + " boolean isValid = userName.flatMap(u -> {\n" + + " return password.map(p -> {\n" + + " return u.equals(\"sa\") && p.equals(\"sa\");\n" + + " });\n" + + " }).orElse(false);\n" + + " System.out.println(isValid);\n" + + " }\n" + + "}\n" + }, + "true"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432520, compiler "duplicate method" bug with lamdas and generic interfaces +public void test432520() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void withProvider(Provider provider) { }\n" + + " public static void main(String [] args) {\n" + + " withProvider(() -> \"user\");\n" + + " }\n" + + "}\n" + + "interface ParentProvider {\n" + + " T get();\n" + + "}\n" + + "// if you remove the extends clause everything works fine\n" + + "interface Provider extends ParentProvider {\n" + + " T get();\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432625, [1.8] VerifyError with lambdas and wildcards +public void test432625() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.stream.Stream;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Stream stream = Stream.of(\"A\");\n" + + " stream.map(x -> (String) x);\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430766, [1.8] Internal compiler error. +public void test430766() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " static class Person {\n" + + " private String email;\n" + + " public Person(String email) {\n" + + " this.email = email;\n" + + " }\n" + + " public String getEmail() {\n" + + " return email;" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List persons = new ArrayList();\n" + + " persons.add(new Person(\"joe.smith@gmail.com\"));\n" + + " persons.add(new Person(\"alice.smith@gmail.com\"));\n" + + " persons.sort(Comparator.comparing(Comparator.nullsLast(Person::getEmail)));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " persons.sort(Comparator.comparing(Comparator.nullsLast(Person::getEmail)));\n" + + " ^^^^^^^^^\n" + + "The method nullsLast(Comparator) in the type Comparator is not applicable for the arguments (Person::getEmail)\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " persons.sort(Comparator.comparing(Comparator.nullsLast(Person::getEmail)));\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type X.Person does not define getEmail(T, T) that is applicable here\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430766, [1.8] Internal compiler error. +public void test430766a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "import java.io.Serializable;\n" + + "public class X {\n" + + " static class Person {\n" + + " private String email;\n" + + " public Person(String email) {\n" + + " this.email = email;\n" + + " }\n" + + " public String getEmail() {\n" + + " return email;" + + " }\n" + + " public static int isRunnable(T first, V second) {\n" + + " return (second instanceof Runnable) ? 1 : 0;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List persons = new ArrayList();\n" + + " persons.add(new Person(\"joe.smith@gmail.com\"));\n" + + " persons.add(new Person(\"alice.smith@gmail.com\"));\n" + + " persons.sort(Comparator.comparing(Comparator.nullsLast(Person::isRunnable)));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 21)\n" + + " persons.sort(Comparator.comparing(Comparator.nullsLast(Person::isRunnable)));\n" + + " ^^^^^^^^^\n" + + "The method nullsLast(Comparator) in the type Comparator is not applicable for the arguments (Person::isRunnable)\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " persons.sort(Comparator.comparing(Comparator.nullsLast(Person::isRunnable)));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type X.Person does not define isRunnable(T, T) that is applicable here\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=431190, [1.8] VerifyError when using a method reference +public void test431190() throws Exception { + this.runConformTest( + new String[] { + "Java8VerifyError.java", + "public class Java8VerifyError {\n" + + " public static class Foo {\n" + + " public Object get() {\n" + + " return new Object();\n" + + " }\n" + + " }\n" + + " @FunctionalInterface\n" + + " public static interface Provider {\n" + + " public T get();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Provider f = () -> new Foo();\n" + + " Provider> meta = () -> f.get()::get;\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=431514 [1.8] Incorrect compilation error in lambda expression +public void test431514() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " void fun1(int x) {\n" + + " class Local {\n" + + " FI test= () -> {\n" + + " try {\n" + + " } catch (Exception e) {\n" + + " int x;\n" + + " };\n" + + " };\n" + + " }\n" + + " }\n" + + "}\n" + + "interface FI {\n" + + " void foo();\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=431514 [1.8] Incorrect compilation error in lambda expression +public void test431514a() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " void fun1(int x) {\n" + + " class Local {\n" + + " class L1 { }\n" + + " int y;\n" + + " FI test= () -> {\n" + + " class L1 { } \n" + + " int y; \n" + + " };\n" + + " }\n" + + " }\n" + + " \n" + + "}\n" + + "interface FI {\n" + + " void foo();\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432531 [1.8] VerifyError with anonymous subclass inside of lambda expression in the superclass constructor call +public void test432531() { + this.runConformTest( + new String[] { + "Y.java", + "import java.util.function.Supplier;\n" + + "class E {\n" + + " E(Supplier factory) { }\n" + + "}\n" + + "public class Y extends E {\n" + + " Y() {\n" + + " super(() -> new Object() {\n" + + " });\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Y();\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=434297 [1.8] NPE in LamdaExpression.analyseCode with lamda expression nested in a conditional expression +public void test434297() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.Collections;\n" + + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public void bla() {\n" + + " boolean b = Boolean.TRUE.booleanValue();\n" + + " List c1 = new ArrayList<>();\n" + + " Collections.sort(c1, b ? null : new Bar(new ArrayList<>(),Comparator.nullsLast((a,e) -> {return 0;})));\n" + + " }\n" + + " private static class Bar implements Comparator{\n" + + " public Bar(Collection col, Comparator comp) { }\n" + + " @Override\n" + + " public int compare(String o1, String o2) {\n" + + " return 0;\n" + + " }\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=436542 : Eclipse 4.4 compiler generates "bad class file" according to javac +public void test436542() throws Exception { + this.runConformTest( + new String[] { + "Utility.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collectors;\n" + + "public class Utility {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + " public static List mapList(Collection original, Function func) {\n" + + " return original.stream().map(func).collect(Collectors.toList());\n" + + " }\n" + + " public static void bindMap(List dest, ObservableList src, Function func) {\n" + + " dest.addAll(mapList(src, func));\n" + + " src.addListener((ListChangeListener) changes -> {\n" + + " for (int i = changes.getFrom(); i < changes.getTo(); i++)\n" + + " dest.set(i, func.apply(src.get(i)));\n" + + " });\n" + + " }\n" + + " public interface ObservableList extends List {\n" + + " public void addListener(ListChangeListener listener);\n" + + " }\n" + + " @FunctionalInterface\n" + + " public interface ListChangeListener {\n" + + " public abstract static class Change {\n" + + " public abstract int getFrom();\n" + + " public abstract int getTo();\n" + + " }\n" + + " public void onChanged(Change c);\n" + + " }\n" + + "}", + }, + "Success", + Util.concatWithClassLibs(new String[]{OUTPUT_DIR}, false), + true, + null); + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "Utility.class", IClassFileReader.ALL); + IMethodInfo lambdaMethod = null; + IMethodInfo[] methodInfos = classFileReader.getMethodInfos(); + int length = methodInfos.length; + for (int i = 0; i < length; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if ("lambda$0".equals(new String(methodInfo.getName()))) { + lambdaMethod = methodInfo; + break; + } + } + assertNotNull("Could not find lambda method",lambdaMethod); + IClassFileAttribute signature = org.eclipse.jdt.internal.core.util.Util.getAttribute(lambdaMethod, IAttributeNamesConstants.SIGNATURE); + assertNull("Found generic signature for lambda method", signature); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=439515 [1.8] ECJ reports error at method reference to overloaded instance method +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=440643, Eclipse compiler doesn't like method references with overloaded varargs method +public void test439515() { + this.runConformTest( + new String[] { + "X.java", + "interface Fun {\n" + + " R apply(T arg);\n" + + "}\n" + + "public class X {\n" + + " int size() {\n" + + " return -1;\n" + + " }\n" + + " int size(Object arg) {\n" + + " return 0;\n" + + " }\n" + + " int size(X arg) {\n" + + " return 1;\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " Fun f1 = X::size;\n" + + " System.out.println(f1.apply(new X()));\n" + + " }\n" + + "}\n" + }, + "-1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=439515 [1.8] ECJ reports error at method reference to overloaded instance method +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=440643, Eclipse compiler doesn't like method references with overloaded varargs method +public void test439515a() { + this.runConformTest( + new String[] { + "X.java", + "interface Fun {\n" + + " R apply(T arg);\n" + + "}\n" + + "public class X {\n" + + " static int size() {\n" + + " return -1;\n" + + " }\n" + + " static int size(Object arg) {\n" + + " return 0;\n" + + " }\n" + + " static int size(X arg) {\n" + + " return 1;\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " Fun f1 = X::size;\n" + + " System.out.println(f1.apply(new X()));\n" + + " }\n" + + "}\n" + }, + "1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=438534 Java8 java.lang.Method.getGeneric* methods fail with java.lang.reflect.GenericSignatureFormatError: Signature Parse error: Expected Field Type Signature +public void test438534() { + this.runConformTest( + new String[] { + "ByteCodeTest.java", + "import java.lang.reflect.Method;\n" + + "import java.security.AccessController;\n" + + "import java.security.PrivilegedAction;\n" + + "import java.util.Collections;\n" + + "import java.util.Comparator;\n" + + "public class ByteCodeTest {\n" + + " public static class BrokenByteCode {\n" + + " public void hello() {\n" + + " Collections.sort(Collections. emptyList(), Comparator.comparing((String data) -> data.length()));\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " for (Method method : AccessController.doPrivileged((PrivilegedAction) () -> BrokenByteCode.class.getDeclaredMethods())) {\n" + + " method.getGenericExceptionTypes();\n" + + " method.getGenericParameterTypes();\n" + + " method.getGenericReturnType();\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=440152 [codegen]"Missing code implementation in the compiler" on cascaded inner class references +public void test440152() { + this.runConformTest( + new String[] { + "Foo.java", + "import java.util.function.Function;\n" + + "interface Foo {void alpha(Bar pBar);}\n" + + "class Bar {Object bravo() {return null;}}\n" + + "class Test {\n" + + " Test(Function pFunction) {\n" + + " class Baz {public Baz(Object pObj) {pFunction.apply(pObj);}}\n" + + " delta(pBar -> charlie(new Baz(pBar.bravo())));\n" + + " }\n" + + " void charlie(Object pRemovals) {}\n" + + " void delta(Foo pListener) {}\n" + + "}" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=440152 [codegen]"Missing code implementation in the compiler" on cascaded inner class references +public void test440152a() { + this.runConformTest( + new String[] { + "Foo.java", + "import java.util.function.Function;\n" + + "interface Foo {void alpha(Bar pBar);}\n" + + "class Bar {Object bravo() {return null;}}\n" + + "class Test {\n" + + " Test(Function pFunction) {\n" + + " class Baz {\n" + + " public Baz(Object pObj) {\n" + + " }\n" + + " class NestedBaz extends Baz {\n" + + " NestedBaz(Object pObj) {\n" + + " super(pObj);\n" + + " pFunction.apply(pObj);\n" + + " }\n" + + " }\n" + + " }\n" + + " delta(pBar -> charlie(new Baz(pBar).new NestedBaz(pBar.bravo())));\n" + + " }\n" + + " void charlie(Object pRemovals) {}\n" + + " void delta(Foo pListener) {}\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432110, [1.8][compiler] nested lambda type incorrectly inferred vs javac +public void test432110() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "public interface X {\n" + + " default void test() {\n" + + " testee().flatMap(_warning_ -> {\n" + + " return result().map(s -> 0);\n" + + " });\n" + + " }\n" + + " Either testee();\n" + + " Either result();\n" + + " static interface Either {\n" + + " Either flatMap(Function> mapper);\n" + + " Either map(Function mapper);\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=441929, [1.8][compiler] @SuppressWarnings("unchecked") not accepted on local variable +public void test441929() { + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " @FunctionalInterface\n" + + " interface X {\n" + + " public void x();\n" + + " }\n" + + " public void z(X x) {\n" + + " }\n" + + " public void test() {\n" + + " z(() -> {\n" + + " try {\n" + + " @SuppressWarnings(\"unchecked\") // (1)\n" + + " Class klass = (Class) Class.forName(\"java.lang.Object\"); // (2)\n" + + " System.out.println(klass.getName());\n" + + " } catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=437781, [1.8][compiler] Eclipse accepts code rejected by javac because of ambiguous method reference +public void test437781() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().visit( System.out::println );\n" + + " }\n" + + " public boolean visit(Function func) {\n" + + " System.out.println(\"Function\");\n" + + " return true;\n" + + " }\n" + + " public void visit(Consumer func) {\n" + + " System.out.println(\"Consumer\");\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new X().visit( System.out::println );\n" + + " ^^^^^\n" + + "The method visit(Function) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " new X().visit( System.out::println );\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type of println(Object) from the type PrintStream is void, this is incompatible with the descriptor\'s return type: Boolean\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=443889, [1.8][compiler] Lambdas get compiled to duplicate methods +public void test443889() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.BiConsumer;\n" + + "import java.util.function.Consumer;\n" + + "public class X {\n" + + " public interface CurryBiConsumer extends BiConsumer {\n" + + " default public CurryConsumer curryFirst(T t) {\n" + + " return (u) -> accept(t, u);\n" + + " }\n" + + " default public CurryConsumer currySecond(U u) {\n" + + " return (t) -> accept(t, u);\n" + + " }\n" + + " }\n" + + " public interface CurryConsumer extends Consumer {\n" + + " default public Runnable curry(T t) {\n" + + " return () -> accept(t);\n" + + " }\n" + + " }\n" + + " static void execute(Runnable r) {\n" + + " System.out.println(\"BEFORE\");\n" + + " r.run();\n" + + " System.out.println(\"AFTER\");\n" + + " }\n" + + " static void display(String str, int count) {\n" + + " System.out.println(\"DISP: \" + str + \" \" + count);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " CurryBiConsumer bc = X::display;\n" + + " execute(bc.curryFirst(\"Salomon\").curry(42));\n" + + " }\n" + + "}\n" + }, + "BEFORE\n" + + "DISP: Salomon 42\n" + + "AFTER"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=441907, [1.8][compiler] Eclipse 4.4.x compiler generics bugs with streams and lambdas +public void test441907() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "import java.util.function.Predicate;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + " public static class FooBar {\n" + + " }\n" + + " public interface FooBarred {\n" + + " public boolean hasFooBar(final FooBar fooBar);\n" + + " }\n" + + " public interface Widget extends FooBarred {\n" + + " }\n" + + " public static void test() {\n" + + " Set> foobars = new HashSet<>();\n" + + " Set widgets = new HashSet<>();\n" + + " Stream> s = null;\n" + + " FooBarred fb = null;\n" + + " fb.hasFooBar((FooBar) null);\n" + + " boolean anyWidgetHasFooBar = widgets.stream().anyMatch(\n" + + " widget -> foobars.stream().anyMatch(widget::hasFooBar)\n" + + " );\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=444773, [1.8][compiler] NullPointerException in LambdaExpression.analyseCode +public void test444773() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Optional;\n" + + " \n" + + "public class X {\n" + + " static class Container {\n" + + " final private String s;\n" + + " public Container(String s) { this.s = s; }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " final List list = new ArrayList<>();\n" + + " final Optional optStr = Optional.of(\"foo\");\n" + + " list.add(new Container(optStr.orElseThrow(() -> new IllegalStateException()))); // Error here\n" + + " \n" + + " // This will work:\n" + + " final String s = optStr.orElseThrow(IllegalStateException::new);\n" + + " list.add(new Container(s)); \n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=444772, [1.8][compiler] NullPointerException in ReferenceExpression.shouldGenerateImplicitLambda +public void test444772() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Optional;\n" + + " \n" + + "public class X {\n" + + " static class Container {\n" + + " final private String s;\n" + + " public Container(String s) { this.s = s; }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " final List list = new ArrayList<>();\n" + + " final Optional optStr = Optional.of(\"foo\");\n" + + " list.add(new Container(optStr.orElseThrow(IllegalStateException::new))); // Error here\n" + + " \n" + + " // This will work:\n" + + " final String s = optStr.orElseThrow(IllegalStateException::new);\n" + + " list.add(new Container(s)); \n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=444803, [1.8][compiler] Exception in thread "main" java.lang.VerifyError: Bad local variable type +public void test444803() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " X abc = null;\n" + + " public static void main(String[] args) {\n" + + " new X();\n" + + " }\n" + + " private void doSth() {\n" + + " final List l = new ArrayList<>();\n" + + " try {\n" + + " System.out.println(\"ok\");\n" + + //" Runnable r = () -> abc.terminateInstances(abc.withInstanceIds(l));\n" + + " } finally {\n" + + " Runnable r = () -> abc.terminateInstances(abc.withInstanceIds(l));\n" + + " }\n" + + " }\n" + + " public void terminateInstances(X abc) {\n" + + " }\n" + + " public X withInstanceIds(Collection arg0) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "interface FI {\n" + + " public void foo(Collection arg0);\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=444785, [1.8] Error in JDT Core during reconcile +public void test444785() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.function.Function;\n" + + "public interface X {\n" + + " @FunctionalInterface\n" + + " static interface Function1 extends Function, Serializable {\n" + + " @Override\n" + + " R apply(T1 t1);\n" + + " }\n" + + " @FunctionalInterface\n" + + " static interface Function6 extends Serializable {\n" + + " R apply(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6);\n" + + " default Function1>>>>> curried() {\n" + + " return t1 -> t2 -> t3 -> t4 -> t5 -> t6 -> apply(t1, t2, t3, t4, t5, t6);\n" + + " }\n" + + " default Function1, R> tupled() {\n" + + " return t -> apply(t._1, t._2, t._3, t._4, t._5, t._6);\n" + + " }\n" + + " }\n" + + " static final class Tuple6 {\n" + + " public final T1 _1;\n" + + " public final T2 _2;\n" + + " public final T3 _3;\n" + + " public final T4 _4;\n" + + " public final T5 _5;\n" + + " public final T6 _6;\n" + + " public Tuple6(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) {\n" + + " this._1 = t1;\n" + + " this._2 = t2;\n" + + " this._3 = t3;\n" + + " this._4 = t4;\n" + + " this._5 = t5;\n" + + " this._6 = t6;\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447119, [1.8][compiler] method references lost generic type information (4.4 -> 4.4.1 regression) +public void test447119() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Parameter;\n" + + "import java.util.Arrays;\n" + + "import java.util.function.Function;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " private static List foo(List x){return x;}\n" + + " public static void main(String[] args) {\n" + + " Function,List> f = i -> { return i; };\n" + + " Method[] methods = X.class.getDeclaredMethods();\n" + + " for (Method m : methods) {\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(\"- \" + m.getGenericReturnType() + \" \" + m.getName() + \"(\" + Arrays.asList(m.getGenericParameterTypes()) + \")\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.expectedOutputString = + "- interface java.util.List lambda$0([interface java.util.List])"; + runner.expectedJavacOutputString = + "- interface java.util.List lambda$main$0([interface java.util.List])"; + runner.runConformTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447119, [1.8][compiler] method references lost generic type information (4.4 -> 4.4.1 regression) +public void test447119a() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Parameter;\n" + + "import java.util.Arrays;\n" + + "import java.util.function.Function;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " private static List foo(List x){return x;}\n" + + " public static void main(String[] args) {\n" + + " Function,List> f = X::foo;\n" + + " Method[] methods = X.class.getDeclaredMethods();\n" + + " for (Method m : methods) {\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(\"- \" + m.getGenericReturnType() + \" \" + m.getName() + \"(\" + Arrays.asList(m.getGenericParameterTypes()) + \")\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447119, [1.8][compiler] method references lost generic type information (4.4 -> 4.4.1 regression) +public void test447119b() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Parameter;\n" + + "import java.util.Arrays;\n" + + "import java.util.function.Function;\n" + + "import java.util.List;\n" + + "import java.io.Serializable;" + + "public class X {\n" + + " private static interface SerializableFunction extends Function, Serializable { }" + + " private static List foo(List x){return x;}\n" + + " public static void main(String[] args) {\n" + + " SerializableFunction, List> f = i -> { return i; };\n" + + " Method[] methods = X.class.getDeclaredMethods();\n" + + " for (Method m : methods) {\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(\"- \" + m.getGenericReturnType() + \" \" + m.getName() + \"(\" + Arrays.asList(m.getGenericParameterTypes()) + \")\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.expectedOutputString = + "- interface java.util.List lambda$0([interface java.util.List])"; + runner.expectedJavacOutputString = + "- interface java.util.List lambda$main$7796d039$1([interface java.util.List])"; + runner.runConformTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447119, [1.8][compiler] method references lost generic type information (4.4 -> 4.4.1 regression) +public void test447119c() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Parameter;\n" + + "import java.util.Arrays;\n" + + "import java.util.function.Function;\n" + + "import java.util.List;\n" + + "import java.io.Serializable;" + + "public class X {\n" + + " private static interface SerializableFunction extends Function, Serializable { }" + + " private static List foo(List x){return x;}\n" + + " public static void main(String[] args) {\n" + + " SerializableFunction, List> f = X::foo;\n" + + " Method[] methods = X.class.getDeclaredMethods();\n" + + " for (Method m : methods) {\n" + + " if (m.getName().contains(\"foo\")) {\n" + + " System.out.println(\"- \" + m.getGenericReturnType() + \" \" + m.getName() + \"(\" + Arrays.asList(m.getGenericParameterTypes()) + \")\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "- java.util.List foo([java.util.List])"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447119, [1.8][compiler] method references lost generic type information (4.4 -> 4.4.1 regression) +public void test447119d() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.ObjectStreamClass;\n" + + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.ArrayList;\n" + + "import java.util.Collections;\n" + + "import java.util.Comparator;\n" + + "public class X {\n" + + " private static interface SerializableFunction extends Function, Serializable { }\n" + + " private static List noop(List l) { return l; }\n" + + " public static void main(String[] args) throws Exception {\n" + + " SerializableFunction, List> f = X::noop;\n" + + " Method invokeWriteReplaceMethod = ObjectStreamClass.class.getDeclaredMethod(\"invokeWriteReplace\", Object.class);\n" + + " invokeWriteReplaceMethod.setAccessible(true);\n" + + " SerializedLambda l = (SerializedLambda)invokeWriteReplaceMethod.invoke(ObjectStreamClass.lookupAny(f.getClass()), f);\n" + + " System.out.println(\"Lambda binds to: \" + l.getImplClass() + \".\" + l.getImplMethodName());\n" + + " System.out.println(\"Methods (with generics):\");\n" + + " List list = new ArrayList();\n" + + " for(Method m : X.class.getDeclaredMethods()) {\n" + + " if(m.getName().equals(\"main\")) continue;\n" + + " if(m.getName().contains(\"deserializeLambda\")) continue;\n" + + " list.add(\"- \" + m.getGenericReturnType() + \" \" + m.getName() + \"(\" + m.getGenericParameterTypes()[0] + \")\");\n" + + " }\n" + + " Collections.sort(list, new Comparator() {\n" + + " public int compare(String s1, String s2) {\n" + + " return s1.compareTo(s2);\n" + + " }\n" + + " });\n" + + " System.out.println(list.toString());\n" + + " }\n" + + "}\n" + }, + "Lambda binds to: X.noop\n" + + "Methods (with generics):\n" + + "[- java.util.List noop(java.util.List)]", + null, + true, + (isJRE9Plus + ? new String[] { "--add-opens", "java.base/java.io=ALL-UNNAMED" } + : new String [] { "-Ddummy" }) // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447119, [1.8][compiler] method references lost generic type information (4.4 -> 4.4.1 regression) +public void test447119e() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Parameter;\n" + + "import java.util.Arrays;\n" + + "import java.util.function.Function;\n" + + "import java.util.List;\n" + + "public class X implements java.io.Serializable {\n" + + " private static List foo(List x){return x;}\n" + + " public static void main(String[] args) {\n" + + " Function,List> f = X::foo;\n" + + " Method[] methods = X.class.getDeclaredMethods();\n" + + " for (Method m : methods) {\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(\"- \" + m.getGenericReturnType() + \" \" + m.getName() + \"(\" + Arrays.asList(m.getGenericParameterTypes()) + \")\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432605, [1.8] Incorrect error "The type ArrayList does not define add(ArrayList, Object) that is applicable here" +public void test432605() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.HashMap;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.stream.Collector;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + "static M terminalAsMapToList(\n" + + " Function classifier,\n" + + " Function, M> intoMap,\n" + + " Function, L> intoList,\n" + + " Supplier> supplier,\n" + + " Class classOfE) throws E {\n" + + " return terminalAsCollected(\n" + + " classOfE,\n" + + " Collectors.collectingAndThen(\n" + + " Collectors.groupingBy(\n" + + " classifier,\n" + + " HashMap::new,\n" + + " Collectors.collectingAndThen(\n" + + " // The type ArrayList does not define add(ArrayList, Object) that is applicable here\n" + + " // from ArrayList::add:\n" + + " Collector.of(ArrayList::new, ArrayList::add, (ArrayList left, ArrayList right) -> { \n" + + " left.addAll(right);\n" + + " return left;\n" + + " }),\n" + + " intoList)),\n" + + " intoMap),\n" + + " supplier);\n" + + " }\n" + + " static M terminalAsCollected(\n" + + " Class class1,\n" + + " Collector collector,\n" + + " Supplier> supplier) throws E {\n" + + " try(Stream s = supplier.get()) {\n" + + " return s.collect(collector);\n" + + " } catch(RuntimeException e) {\n" + + " throw unwrapCause(class1, e);\n" + + " }\n" + + " }\n" + + " static E unwrapCause(Class classOfE, RuntimeException e) throws E {\n" + + " Throwable cause = e.getCause();\n" + + " if(classOfE.isInstance(cause) == false) {\n" + + " throw e;\n" + + " }\n" + + " throw classOfE.cast(cause);\n" + + "}\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432605, [1.8] Incorrect error "The type ArrayList does not define add(ArrayList, Object) that is applicable here" +public void testreduced432605() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.HashMap;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collector;\n" + + "import java.util.stream.Collectors;\n" + + "public class X {\n" + + " static void foo() {\n" + + " Collector cat = \n" + + " Collectors.collectingAndThen(\n" + + " Collectors.groupingBy((Function) null, \n" + + " HashMap::new, \n" + + " (Collector, L>) null), \n" + + " (Function, M>) null);\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448802, [1.8][compiler] Poly invocations interleaved by a impertinent lambda may need some more changes, +public void test448802() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Optional;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Optional userName = Optional.of(\"sa\");\n" + + " Optional password = Optional.of(\"sa\");\n" + + " boolean isValid = userName.flatMap((String u) -> {\n" + + " return password.map((String p) -> {\n" + + " return u.equals(\"sa\") && p.equals(\"sa\");\n" + + " });\n" + + " }).orElse(false);\n" + + " System.out.println(isValid);\n" + + " }\n" + + "}\n" + }, + "true"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.GENERATE); + this.runConformTest( + false, + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static class Tuple {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map, Tuple> map = (in) -> new Tuple<>();\n" + + " for(Method m : Test.class.getDeclaredMethods()) {\n" + + " // Use the type information stored in signature\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + null, + customOptions, + null, + (reflectNestedClassUseDollar + ? "Test$Tuple\n" + + "Test$Tuple" + : "Test.Test$Tuple\n" + + "Test.Test$Tuple"), + null, + EclipseJustification.EclipseBug449063); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.GENERATE); + this.runConformTest( + false, + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map extends Serializable {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static class Tuple {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map, Tuple> map = (in) -> new Tuple<>();\n" + + " SerializedLambda sl = getSerializedLambda(map); \n" + + " Method m = getLambdaMethod(sl);\n" + + " // Use the type information stored in signature\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static Method getLambdaMethod(SerializedLambda lambda) throws Exception {\n" + + " String implClassName = lambda.getImplClass().replace(\'/\', \'.\');\n" + + " Class implClass = Class.forName(implClassName);\n" + + " String lambdaName = lambda.getImplMethodName();\n" + + " for (Method m : implClass.getDeclaredMethods()) {\n" + + " if (m.getName().equals(lambdaName)) {\n" + + " return m;\n" + + " }\n" + + " }\n" + + " throw new Exception(\"Lambda Method not found\");\n" + + " }\n" + + " public static SerializedLambda getSerializedLambda(Object function) throws Exception {\n" + + " if (function == null || !(function instanceof java.io.Serializable)) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " for (Class clazz = function.getClass(); clazz != null; clazz = clazz.getSuperclass()) {\n" + + " try {\n" + + " Method replaceMethod = clazz.getDeclaredMethod(\"writeReplace\");\n" + + " replaceMethod.setAccessible(true);\n" + + " Object serializedForm = replaceMethod.invoke(function);\n" + + " if (serializedForm instanceof SerializedLambda) {\n" + + " return (SerializedLambda) serializedForm;\n" + + " }\n" + + " }\n" + + " catch (NoSuchMethodError e) {\n" + + " // fall through the loop and try the next class\n" + + " }\n" + + " catch (Throwable t) {\n" + + " throw new RuntimeException(\"Error while extracting serialized lambda\", t);\n" + + " }\n" + + " }\n" + + " throw new Exception(\"writeReplace method not found\");\n" + + " }\n" + + "}" + }, + null, + customOptions, + null, + (reflectNestedClassUseDollar + ? "Test$Tuple\n" + + "Test$Tuple" + : "Test.Test$Tuple\n" + + "Test.Test$Tuple"), + null, + EclipseJustification.EclipseBug449063); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.DO_NOT_GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static class Tuple {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map, Tuple> map = (in) -> new Tuple<>();\n" + + " for(Method m : Test.class.getDeclaredMethods()) {\n" + + " // Use the type information stored in signature\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "class Test$Tuple\n" + + "class Test$Tuple", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063c() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.DO_NOT_GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map extends Serializable {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static class Tuple {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map, Tuple> map = (in) -> new Tuple<>();\n" + + " SerializedLambda sl = getSerializedLambda(map); \n" + + " Method m = getLambdaMethod(sl);\n" + + " // Use the type information stored in signature\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static Method getLambdaMethod(SerializedLambda lambda) throws Exception {\n" + + " String implClassName = lambda.getImplClass().replace(\'/\', \'.\');\n" + + " Class implClass = Class.forName(implClassName);\n" + + " String lambdaName = lambda.getImplMethodName();\n" + + " for (Method m : implClass.getDeclaredMethods()) {\n" + + " if (m.getName().equals(lambdaName)) {\n" + + " return m;\n" + + " }\n" + + " }\n" + + " throw new Exception(\"Lambda Method not found\");\n" + + " }\n" + + " public static SerializedLambda getSerializedLambda(Object function) throws Exception {\n" + + " if (function == null || !(function instanceof java.io.Serializable)) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " for (Class clazz = function.getClass(); clazz != null; clazz = clazz.getSuperclass()) {\n" + + " try {\n" + + " Method replaceMethod = clazz.getDeclaredMethod(\"writeReplace\");\n" + + " replaceMethod.setAccessible(true);\n" + + " Object serializedForm = replaceMethod.invoke(function);\n" + + " if (serializedForm instanceof SerializedLambda) {\n" + + " return (SerializedLambda) serializedForm;\n" + + " }\n" + + " }\n" + + " catch (NoSuchMethodError e) {\n" + + " // fall through the loop and try the next class\n" + + " }\n" + + " catch (Throwable t) {\n" + + " throw new RuntimeException(\"Error while extracting serialized lambda\", t);\n" + + " }\n" + + " }\n" + + " throw new Exception(\"writeReplace method not found\");\n" + + " }\n" + + "}" + }, + "class Test$Tuple\n" + + "class Test$Tuple", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063d() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static Tuple noop(Tuple t){return null;}\n" + + " public static class Tuple {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map, Tuple> map = Test::noop;\n" + + " for(Method m : Test.class.getDeclaredMethods()) {\n" + + " // Use the type information stored in signature\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063e() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.DO_NOT_GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test {\n" + + " public static interface Map extends Serializable {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static Tuple noop(Tuple t){return null;}\n" + + " public static class Tuple {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map, Tuple> map = Test::noop;\n" + + " SerializedLambda sl = getSerializedLambda(map); \n" + + " Method m = getLambdaMethod(sl);\n" + + " // Use the type information stored in signature\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " public static Method getLambdaMethod(SerializedLambda lambda) throws Exception {\n" + + " String implClassName = lambda.getImplClass().replace(\'/\', \'.\');\n" + + " Class implClass = Class.forName(implClassName);\n" + + " String lambdaName = lambda.getImplMethodName();\n" + + " for (Method m : implClass.getDeclaredMethods()) {\n" + + " if (m.getName().equals(lambdaName)) {\n" + + " return m;\n" + + " }\n" + + " }\n" + + " throw new Exception(\"Lambda Method not found\");\n" + + " }\n" + + " public static SerializedLambda getSerializedLambda(Object function) throws Exception {\n" + + " if (function == null || !(function instanceof java.io.Serializable)) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " for (Class clazz = function.getClass(); clazz != null; clazz = clazz.getSuperclass()) {\n" + + " try {\n" + + " Method replaceMethod = clazz.getDeclaredMethod(\"writeReplace\");\n" + + " replaceMethod.setAccessible(true);\n" + + " Object serializedForm = replaceMethod.invoke(function);\n" + + " if (serializedForm instanceof SerializedLambda) {\n" + + " return (SerializedLambda) serializedForm;\n" + + " }\n" + + " }\n" + + " catch (NoSuchMethodError e) {\n" + + " // fall through the loop and try the next class\n" + + " }\n" + + " catch (Throwable t) {\n" + + " throw new RuntimeException(\"Error while extracting serialized lambda\", t);\n" + + " }\n" + + " }\n" + + " throw new Exception(\"writeReplace method not found\");\n" + + " }\n" + + "}" + }, + (reflectNestedClassUseDollar + ? "Test$Tuple\n" + + "Test$Tuple" + : "Test.Test$Tuple\n" + + "Test.Test$Tuple"), + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449063, [1.8][compiler] Bring back generic signatures for Lambda Expressions +public void test449063f() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_LambdaGenericSignature, CompilerOptions.GENERATE); + this.runConformTest( + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Type;\n" + + "public class Test implements Serializable{\n" + + " public static interface Map {\n" + + " public OUT map(IN in);\n" + + " }\n" + + " public static Tuple noop(Tuple t){return null;}\n" + + " public static class Tuple {\n" + + " private T1 field1;\n" + + " private T2 field2;\n" + + " }\n" + + " public static void main(String[] strings) throws Exception {\n" + + " Map, Tuple> map = Test::noop;\n" + + " for(Method m : Test.class.getDeclaredMethods()) {\n" + + " // Use the type information stored in signature\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " System.out.println(m.getGenericReturnType());\n" + + " for (Type t : m.getGenericParameterTypes()) {\n" + + " System.out.println(t);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + customOptions); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=445949, Lambda parameter not shadowing in nested scope producing non-existent compilation error +public void test445949() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "public class X {\n" + + " void methodInFirstLevel(int y) {\n" + + " class Second {\n" + + " int t = y;\n" + + " Consumer myConsumer1 = (z) -> {\n" + + " System.out.println(\"z = \" + z);\n" + + " System.out.println(\"y = \" + y);\n" + + " System.out.println(\"t = \" + t);\n" + + " };\n" + + " Consumer myConsumer2 = (y) -> {\n" + + " System.out.println(\"y = \" + y);\n" + + " System.out.println(\"t = \" + t);\n" + + " };\n" + + " void foo( int y) {\n" + + " System.out.println(\"y = \" + y);\n" + + " }\n" + + " class Third {\n" + + " Consumer myConsumer3 = (y) -> {\n" + + " System.out.println(\"y = \" + y);\n" + + " };\n" + + " }\n" + + " void bar(int y) {\n" + + " new Third().myConsumer3.accept(y);\n" + + " }\n" + + " }\n" + + " new Second().myConsumer1.accept(10);\n" + + " new Second().myConsumer2.accept(20);\n" + + " new Second().foo(30);\n" + + " new Second().bar(40);\n" + + " \n" + + " }\n" + + " void foo() {\n" + + " Consumer myConsumer2 = (y) -> {\n" + + " class Inner {\n" + + " Consumer myConsumer4 = (y) -> { \n" + + " class InnerMost {\n" + + " Consumer myConsumer3 = (y /*error without fix*/) -> {};\n" + + " }\n" + + " };\n" + + " }\n" + + " new Inner().myConsumer4.accept(10);\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().methodInFirstLevel(5);\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "z = 10\ny = 5\nt = 5\ny = 20\nt = 5\ny = 30\ny = 40"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=445949, Lambda parameter not shadowing in nested scope producing non-existent compilation error +public void test445949a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "class X {\n" + + " void foo(int y) {\n" + + " Consumer c1 = (y)-> {};\n" + + " }\n" + + " void foo2() {\n" + + " int y;\n" + + " Consumer c1 = (y)-> {};\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Consumer c1 = (y)-> {};\n" + + " ^\n" + + "Lambda expression's parameter y cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Consumer c1 = (y)-> {};\n" + + " ^\n" + + "Lambda expression's parameter y cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=456395, can't compile the Java8 code +public void test456395() { + this.runConformTest( + new String[] { + "Test.java", + "import java.io.*;\n" + + "import java.util.*;\n" + + "import java.util.stream.*;\n" + + "import static java.util.stream.Collectors.*;\n" + + "public class Test {\n" + + " public static void main(String[] args) throws IOException {\n" + + " Stream locales = Stream.of(Locale.getAvailableLocales());\n" + + " locales = Stream.of(Locale.getAvailableLocales());\n" + + " Map> countryToLanguages = locales.collect(\n" + + " groupingBy(Locale::getDisplayCountry, \n" + + " mapping(Locale::getDisplayLanguage,\n" + + " toSet())));\n" + + " }\n" + + "}\n"}); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=459305 +public void test459305() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.function.BiConsumer;\n" + + "import java.util.function.Consumer;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo(arg1 -> bar(X::baz));\n" + + " }\n" + + " private static void foo(Consumer c) { c.accept(null); }\n" + + " private static void baz(String s1, String s2) { System.out.println(s1 + \"::\" + s2); }\n" + + " private static void bar(VoidMethodRef2 mr2) { mr2.accept(\"one\", \"two\"); }\n" + + " private static interface VoidMethodRef2 extends BiConsumer, Serializable {}\n" + + "}\n"}, + "one::two"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=467825 Missing code implementation in the compiler +public void test467825() { + this.runConformTest( + new String[] { + "Main.java", + "import java.util.function.Function;\n" + + "public class Main {\n" + + " public Function f(int x) {\n" + + " class A {\n" + + " void g() {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + " return s -> {\n" + + " A a = new A();\n" + + " return s;\n" + + " };\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=467825 Missing code implementation in the compiler +public void test467825a() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.function.Function;\n" + + "interface Foo {void alpha(Bar pBar);}\n" + + "class Bar {Object bravo() {return null;}}\n" + + "class Test {\n" + + " Foo foo(Function pFunction) {\n" + + " class Baz {\n" + + " public Baz(Object pObj) {\n" + + " }\n" + + " class NestedBaz extends Baz {\n" + + " NestedBaz(Object pObj) {\n" + + " super(pObj);\n" + + " pFunction.apply(pObj);\n" + + " }\n" + + " }\n" + + " }\n" + + " return pBar -> {\n" + + " Object o = new Baz(pBar).new NestedBaz(pBar.bravo());\n" + + " };\n" + + " }\n" + + " void charlie(Object pRemovals) {}\n" + + " void delta(Foo pListener) {}\n" + + "}\n" + }); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=461004 Multiple spurious errors compiling FunctionalJava project +public void test461004() { + this.runConformTest( + false /* skipJavac */, + JavacHasABug.JavacBugFixed_901, + new String[] { + "Ice.java", + "import java.util.function.BiPredicate;\n" + + "import java.util.function.Function;\n" + + "class Ice {\n" + + " static BiPredicate create(BiPredicate fn) {\n" + + " return null;\n" + + " }\n" + + " static BiPredicate create(Function map) {\n" + + " return null;\n" + + " }\n" + + " void someMethod(BiPredicate b) {}\n" + + " void method() {\n" + + " BiPredicate eq = String::equalsIgnoreCase;\n" + + " // these all compile:\n" + + " BiPredicate ok1 = create( eq );\n" + + " BiPredicate ok2 = create( (a, b) -> true );\n" + + " BiPredicate ok3 = create( String::valueOf );\n" + + " // this causes an internal compiler error, ArrayIndexOutOfBoundsException: 1\n" + + " someMethod(create( String::equalsIgnoreCase ));\n" + + " }\n" + + "}\n" + }, null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=478533 [compiler][1.8][lambda] check visibility of target context is broken +public void test478533() { + this.runConformTest( + new String[] { + "test/BugDemonstrator.java", + "package test;\n" + + "import test.subpackage.B;\n" + + "public class BugDemonstrator {\n" + + " public static void main(String[] args) {\n" + + " // OK\n" + + " invoke(new B() {\n" + + " public String invoke(Integer input) {\n" + + " return null;\n" + + " }\n" + + " });\n" + + " // ERROR\n" + + " invoke((Integer i) -> { // Error is here: The type A from the descriptor computed for the target context is not visible here.\n" + + " return null;\n" + + " });\n" + + " }\n" + + " private static String invoke(B b) {\n" + + " return b.invoke(1);\n" + + " }\n" + + "}\n", + "test/subpackage/A.java", + "package test.subpackage;\n" + + "interface A {\n" + + " String invoke(I input);\n" + + "}\n", + "test/subpackage/B.java", + "package test.subpackage;\n" + + "public interface B extends A {}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=478533 [compiler][1.8][lambda] check visibility of target context is broken +public void test478533a() { + this.runNegativeTest( + new String[] { + "test/BugDemonstrator.java", + "package test;\n" + + "import test.subpackage.C;\n" + + "public class BugDemonstrator {\n" + + " public static void main(String[] args) {\n" + + " C c = new C();\n" + + " c.invoke((Integer i) -> { \n" + + " return null;\n" + + " }, 2);\n" + + " }\n" + + "}\n", + "test/subpackage/A.java", + "package test.subpackage;\n" + + "public interface A {\n" + + " String invoke(I input);\n" + + "}\n", + "test/subpackage/B.java", + "package test.subpackage;\n" + + "interface B extends A {}\n" , + "test/subpackage/C.java", + "package test.subpackage;\n" + + "public class C {\n" + + " public String invoke(B b, Integer input) {\n" + + " return b.invoke(input);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\BugDemonstrator.java (at line 6)\n" + + " c.invoke((Integer i) -> { \n" + + " ^^^^^^^^^^^^^^\n" + + "The type B from the descriptor computed for the target context is not visible here. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=477263 [1.8][compiler] No enclosing instance of the type Outer is accessible in scope for method reference +public void test477263() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.function.Function;\n" + + "public interface Test {\n" + + " static void test(Function function) {\n" + + " class Outer {\n" + + " Outer(K k) {}\n" + + " class Inner {\n" + + " public Inner(K k) {}\n" + + " private void method(K k) {\n" + + " System.out.println(function.apply(null));\n" + + " Function f = Inner::new;\n" + + " Function f2 = Outer::new;\n" + + " }\n" + + " }\n" + + " }\n" + + " new Outer(null).new Inner(null).method(null);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Test.test((k) -> \"Success\");\n" + + " }\n" + + "}" + }, + "Success"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=477263 [1.8][compiler] No enclosing instance of the type Outer is accessible in scope for method reference +public void test477263a() { + this.runConformTest( + false, + JavacHasABug.JavacBug8144673, + new String[] { + "X.java", + "interface I {\n" + + " X makeX(int x);\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " int local = 10;\n" + + " class Y extends X {\n" + + " class Z extends X {\n" + + " private Z(int z) {\n" + + " }\n" + + " private Z() {}\n" + + " }\n" + + " private Y(int y) {\n" + + " System.out.println(y);\n" + + " }\n" + + " Y() {\n" + + " }\n" + + " }\n" + + " I i = Y :: new;\n" + + " i.makeX(local);\n" + + " }\n" + + " private X(int x) {\n" + + " }\n" + + " X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}" + }, + "10"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=477263 [1.8][compiler] No enclosing instance of the type Outer is accessible in scope for method reference +public void test477263b() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X makeX(int x);\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " int local = 10;\n" + + " class Y extends X {\n" + + " class Z extends X {\n" + + " private Z(int z) {\n" + + " System.out.println(local);\n" + + " }\n" + + " void f(int in) {\n" + + " I i2 = Z::new;\n" + + " i2.makeX(in);\n" + + " }\n" + + " private Z() {}\n" + + " }\n" + + " private Y(int y) {\n" + + " System.out.println(\"Y\");\n" + + " }\n" + + " Y() {\n" + + " }\n" + + " }\n" + + " new Y().new Z().f(0);\n" + + " }\n" + + " private X(int x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}" + }, + "10"); +} +public void testBug487586() { + runNegativeTest( + new String[] { + "X.java", + "\n" + + "interface Calculator {\n" + + " public int calculate(int a, int b);\n" + + "}\n" + + "\n" + + "interface Sumator {\n" + + " public int test();\n" + + "\n" + + " public int test3(int a, int b);\n" + + "}\n" + + "\n" + + "// intersection of both types\n" + + "interface Both extends Sumator, Calculator {\n" + + "\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Calculator test = (Calculator & Sumator) (a, b) -> a + b;\n" + + " System.out.println(test.calculate(2, 3));\n" + + "\n" + + " Sumator sumator = (Calculator & Sumator) (a, b) -> a + b; // does compile, but throws an Exception\n" + + " sumator.test();\n" + + "\n" + + " Both both = (Both) (a, b) -> a + b; // does not compile\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " Calculator test = (Calculator & Sumator) (a, b) -> a + b;\n" + + " ^^^^^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " Sumator sumator = (Calculator & Sumator) (a, b) -> a + b; // does compile, but throws an Exception\n" + + " ^^^^^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "3. ERROR in X.java (at line 24)\n" + + " Both both = (Both) (a, b) -> a + b; // does not compile\n" + + " ^^^^^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=452587 Java 8: Method references to the same method do not share BootstrapMethod +public void testBug452587() { + this.runConformTest( + new String[] { + "Test.java", + " public class Test {\n" + + " public static void main(String[] args) {\n" + + " Runnable m = Test::m;\n" + + " Runnable n = Test::m;\n" + + " Runnable o = Test::m;\n" + + " Runnable p = Test::m;\n" + + " Runnable q = Test::m;\n" + + " }\n" + + " public static void m() {}\n" + + " }\n" + }); + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "Test.class", IClassFileReader.ALL); + BootstrapMethodsAttribute bootstrapMethodsAttribute = null; + IClassFileAttribute[] attrs = classFileReader.getAttributes(); + for (int i=0,max=attrs.length;i> BadInferenceMars451Casus1() {\n" + + " List stuff = new ArrayList<>();\n" + + " return stuff.stream().collect(Collectors.toMap(Function.identity(), t -> Arrays.asList(t), BadInferenceMars451::sum));\n" + + " }\n" + + " public static Map> BadInferenceMars451Casus1Fixed1() {\n" + + " List stuff = new ArrayList<>();\n" + + " return stuff.stream().collect(Collectors.toMap(Function.identity(), t -> Arrays.asList(t), (BinaryOperator>) BadInferenceMars451::sum));\n" + + " }\n" + + " public static Map> BadInferenceMars451Casus1Fixed2() {\n" + + " List stuff = new ArrayList<>();\n" + + " return stuff.stream().collect(Collectors.toMap(Function.identity(), t -> Arrays. asList(t), BadInferenceMars451::sum));\n" + + " }\n" + + " /* \n" + + " * Uncomment this to see eclipse crash at build\n" + + " * this doesnt work but it should not crash the ide\n" + + " */ \n" + + " public static Map> BadInferenceMars451Casus1Crash() {\n" + + " List stuff = new ArrayList<>();\n" + + " return stuff.stream().collect(Collectors.toMap(Function.identity(), t -> Arrays.asList(t), BadInferenceMars451::sum));\n" + + " }\n" + + " public static List sum(List l1, List l2) {\n" + + " return null;\n" + + " }\n" + + " public static class X {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in BadInferenceMars451.java (at line 31)\n" + + " return stuff.stream().collect(Collectors.toMap(Function.identity(), t -> Arrays.asList(t), BadInferenceMars451::sum));\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type BadInferenceMars451 is not generic; it cannot be parameterized with arguments \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=491139 Lambda that redefines a default method with generics +public void testBug491139() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " interface Foo {\n" + + " default String bar(String s) {\n" + + " return (\"default : \" + s);\n" + + " }\n" + + " String bar(T t);\n" + + " }\n" + + " public String testLambdaRedefiningADefault() {\n" + + " Foo foo =\n" + + " (t) -> {\n" + + " return \"lambda : \" + t;\n" + + " };\n" + + " return (((Foo)foo).bar(\"String\"));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new Test().testLambdaRedefiningADefault());\n" + + " }\n" + + "}\n" + }, + "lambda : String"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=489631 [1.8] "java.lang.VerifyError: Bad type on operand stack" with lamba and type defined in method +public void test489631() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "interface I { int getLength(); }\n" + + "public class Test {\n" + + " public void test() {\n" + + " class A {\n" + + " List l;\n" + + " public A(List l) {\n" + + " this.l = l;\n" + + " }\n" + + " }\n" + + " List list = new ArrayList<>();\n" + + " I i = () -> new A<>(list).l.size();\n" + + " System.out.println(i.getLength());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Test().test();\n" + + " }\n" + + "}" + }, + "0"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=489631 [1.8] "java.lang.VerifyError: Bad type on operand stack" with lamba and type defined in method +public void test489631a() { + this.runConformTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "interface I { int getLength(); }\n" + + "public class Test {\n" + + " public void test() {\n" + + " class A {\n" + + " List l;\n" + + " public A(List l) {\n" + + " this.l = l;\n" + + " }\n" + + " class B {\n" + + " List iL;\n" + + " public B(List l) {\n" + + " // super(l);\n" + + " this.iL = l;\n" + + " }\n" + + " }\n" + + " }\n" + + " List list = new ArrayList<>();\n" + + " I i = () -> new A<>(list).new B(list).iL.size();\n" + + " System.out.println(i.getLength());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Test().test();\n" + + " }\n" + + "}" + }, + "0"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=476859 enclosing method not found error when EJC compiled, works fine with oracle jdk compiler +public void test476859() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Test.java", + "import java.lang.reflect.Method;\n" + + "import java.util.function.Function;\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " final Function f = __ -> {\n" + + " class Dummy{}\n" + + " return new Dummy(){}.getClass().getEnclosingMethod();\n" + + " };\n" + + " System.out.println(f.apply(null));\n" + + " }\n" + + "}" + }; + runner.expectedOutputString = + "private static java.lang.reflect.Method Test.lambda$0(java.lang.Void)"; + runner.expectedJavacOutputString = + "private static java.lang.reflect.Method Test.lambda$main$0(java.lang.Void)"; + runner.runConformTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=476859 enclosing method not found error when EJC compiled, works fine with oracle jdk compiler +public void test476859a() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Test.java", + "import java.lang.reflect.Method;\n" + + "import java.util.function.Function;\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " \n" + + " final Function f = __ -> {\n" + + " class Dummy{}\n" + + " return new Dummy(){}.getClass().getEnclosingMethod();\n" + + " };\n" + + " System.out.println(f.apply(null));\n" + + " new AnotherClass().foo();\n" + + " }\n" + + "}\n" + + "class AnotherClass {\n" + + " void foo() {\n" + + " final Function f = __ -> {\n" + + " class Dummy{}\n" + + " return new Dummy(){}.getClass().getEnclosingMethod();\n" + + " };\n" + + " System.out.println(f.apply(null));\n" + + " }\n" + + "}\n" + }; + runner.expectedOutputString = + "private static java.lang.reflect.Method Test.lambda$0(java.lang.Void)\n" + + "private java.lang.reflect.Method AnotherClass.lambda$0(java.lang.Void)"; + runner.expectedJavacOutputString = + "private static java.lang.reflect.Method Test.lambda$main$0(java.lang.Void)\n" + + "private java.lang.reflect.Method AnotherClass.lambda$foo$0(java.lang.Void)"; + runner.runConformTest(); +} +public void testBug499258() { + runConformTest( + new String[] { + "bug499258/ShellTab.java", + "package bug499258;\n" + + "class Controller {\n" + + " public void newTerminal(Object... path) {\n" + + " }\n" + + "}\n" + + "\n" + + "interface EventHandler {\n" + + " void handle();\n" + + "}\n" + + "\n" + + "public class ShellTab {\n" + + " private final Controller controller;\n" + + "\n" + + " public ShellTab(Controller controller) {\n" + + " this.controller = controller;\n" + + " EventHandler h = this.controller::newTerminal;\n" + + " }\n" + + "}\n" + + "", + } + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=500374 Using a method reference to a generic method in a Base class gives me NoSuchMethodError +public void test500374() { + this.runConformTest( + new String[] { + "client/Client.java", + "package client;\n" + + "import lib.Sub;\n" + + "public class Client {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " Sub s1 = new Sub();\n" + + " doSomething(() -> s1.m());\n" + + " doSomething(s1::m);\n" + + " }\n" + + " interface Aaa {\n" + + " Object f() throws Throwable;\n" + + " }\n" + + " public static void doSomething(Aaa a) throws Throwable {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}\n", + "lib/Sub.java", + "package lib;\n" + + "public class Sub extends Base {}", + "lib/Base.java", + "package lib;\n" + + "class Base {\n" + + " public T m() {\n" + + " System.out.println(\"m\");\n" + + " return thisInstance();\n" + + " }\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " T thisInstance() {\n" + + " return (T) this;\n" + + " }\n" + + "}" + }, + "Done\n" + + "Done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=500374 Using a method reference to a generic method in a Base class gives me NoSuchMethodError +public void test500374a() { + this.runConformTest( + new String[] { + "client/Client.java", + "package client;\n" + + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.invoke.MethodType;\n" + + "import lib.Sub;\n" + + "public class Client {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " MethodHandle mh = MethodHandles.lookup().findVirtual(Sub.class, \"m\", MethodType.methodType(Object.class));\n" + + " doSomething(mh::invoke);\n" + + " }\n" + + " interface Aaa {\n" + + " Object f() throws Throwable;\n" + + " }\n" + + " public static void doSomething(Aaa a) throws Throwable {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}\n", + "lib/Sub.java", + "package lib;\n" + + "public class Sub extends Base {}", + "lib/Base.java", + "package lib;\n" + + "class Base {\n" + + " public T m() {\n" + + " System.out.println(\"m\");\n" + + " return thisInstance();\n" + + " }\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " T thisInstance() {\n" + + " return (T) this;\n" + + " }\n" + + "}" + }, + "Done"); +} +public void testBug502871() { + runNegativeTest( + new String[] { + "test/GryoMapper.java", + "package test;\n" + + "\n" + + "interface Generic {\n" + + "}\n" + + "\n" + + "interface SAM {\n" + + " B m();\n" + + "}\n" + + "\n" + + "public final class GryoMapper {\n" + + " public void addCustom(Generic c) {\n" + + " addOrOverrideRegistration(() -> GryoTypeReg.of(c));\n" + + " }\n" + + "\n" + + " private void addOrOverrideRegistration(SAM> newRegistrationBuilder) {\n" + + " }\n" + + "\n" + + " static class GryoTypeReg {\n" + + " static GryoTypeReg of(Generic clazz) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + "----------\n" + + "1. WARNING in test\\GryoMapper.java (at line 11)\n" + + " public void addCustom(Generic c) {\n" + + " ^^^^^^^\n" + + "Generic is a raw type. References to generic type Generic should be parameterized\n" + + "----------\n" + + "2. WARNING in test\\GryoMapper.java (at line 12)\n" + + " addOrOverrideRegistration(() -> GryoTypeReg.of(c));\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation of(Generic) of the generic method of(Generic) of type GryoMapper.GryoTypeReg\n" + + "----------\n" + + "3. WARNING in test\\GryoMapper.java (at line 12)\n" + + " addOrOverrideRegistration(() -> GryoTypeReg.of(c));\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type GryoMapper.GryoTypeReg needs unchecked conversion to conform to GryoMapper.GryoTypeReg\n" + + "----------\n" + + "4. WARNING in test\\GryoMapper.java (at line 12)\n" + + " addOrOverrideRegistration(() -> GryoTypeReg.of(c));\n" + + " ^\n" + + "Type safety: The expression of type Generic needs unchecked conversion to conform to Generic\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=490469 Internal compiler error: java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.ast.LambdaExpression.analyseCode(LambdaExpression.java:512) +public void testBUg490469() { + this.runConformTest( + new String[] { + "AbstractClientProxy.java", + "import java.util.function.Supplier;\n" + + "public abstract class AbstractClientProxy {\n" + + " protected T getRemoteObject(String url, Class responseType, Object... urlVariables) {\n" + + " return handleException(this.bindGet(REST::getForObject, url, responseType, urlVariables));\n" + + " }\n" + + " private T handleException(Supplier s){\n" + + " T t = null;\n" + + " try{\n" + + " t= s.get();\n" + + " }catch(Exception e){\n" + + " }\n" + + " return t;\n" + + " }\n" + + " private Supplier bindGet(GetFunc fn, String url, Class responseType, Object... uriVariables) {\n" + + " return () -> fn.invoke(url, responseType, uriVariables);\n" + + " }\n" + + "}\n" + + "class REST {\n" + + " static T getForObject(String url, Class respType, Object... vars) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "interface GetFunc {\n" + + " T invoke(String url, Class responseType, Object... uriVariables);\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=509804 Incorrect Enclosing Method Attribute generated for anonymous class in lambda after method reference +public void test509804() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Test.java", + "import java.lang.reflect.Method;\n" + + "import java.util.function.Supplier;\n" + + "public enum Test {\n" + + " A(Object::new),\n" + + " B(() -> new Object(){}),\n" + + " ;\n" + + " private final Supplier s;\n" + + " Test(Supplier e){\n" + + " this.s = e;\n" + + " }\n" + + " public static void main(String[] args) throws NoSuchMethodException, SecurityException {\n" + + " System.out.println(B.s.get().getClass().getEnclosingMethod());\n" + + " }\n" + + "}\n" + }; + runner.expectedOutputString = + "private static java.lang.Object Test.lambda$1()"; + runner.expectedJavacOutputString = + "private static java.lang.Object Test.lambda$static$0()"; + runner.runConformTest(); +} +public void testBug514105() { + runConformTest( + new String[] { + "FunctionalInterfaceBug.java", + "import java.util.function.Function;\n" + + "import java.util.function.UnaryOperator;\n" + + "\n" + + "@FunctionalInterface\n" + + "interface BaseFunction extends Function {\n" + + "\n" + + " T foo(final S s);\n" + + "\n" + + " default T apply(final S s) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "@FunctionalInterface\n" + + "interface SubFunction extends UnaryOperator, BaseFunction {\n" + + "}\n" + + "public class FunctionalInterfaceBug {}\n" + }); +} +public void testBug515473() { + runConformTest( + new String[] { + "test/LambdaResourceLeak.java", + "package test;\n" + + "\n" + + "class X implements AutoCloseable {\n" + + " @Override\n" + + " public void close() {\n" + + " }\n" + + "}\n" + + "\n" + + "interface SAM {\n" + + " Object m();\n" + + "}\n" + + "\n" + + "public class LambdaResourceLeak {\n" + + " void f() {\n" + + " X x1 = new X();\n" + + " SAM sam = () -> {\n" + + " return \"\";\n" + + " };\n" + + " sam.m();\n" + + " x1.close();\n" + + " }\n" + + "}\n" + + "", + } + ); +} +public void testBug517299() { + runConformTest( + new String[] { + "example/FooTest.java", + "package example;\n" + + "import java.util.function.Consumer;\n" + + "import foo.Foo;\n" + + "public class FooTest {\n" + + " public void test() {\n" + + " Foo.Bar foo = new Foo.Bar();\n" + + " foo.print(\"direct\");\n" + + " invoke(foo::print, \"methodReference\");\n" + + " }\n" + + " private static void invoke(Consumer method, String name) {\n" + + " method.accept(name);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new FooTest().test();\n" + + " }\n" + + "}", + "foo/Foo.java", + "package foo;\n" + + "public abstract class Foo {\n" + + " public static class Bar extends Baz {}\n" + + " static class Baz {\n" + + " public final void print(String name) {\n" + + " System.out.println(\"Baz.print called - \"+name);\n" + + " }\n" + + " }\n" + + "}" + }, + "Baz.print called - direct\n" + + "Baz.print called - methodReference" + ); +} +public void testBug521808() { + runConformTest( + new String[] { + "Z.java", + "interface FI1 {\n" + + " Object m(Integer... s);\n" + + "}\n" + + "interface FI2 {\n" + + " Object m(T... arg);\n" + + "}\n" + + "public class Z {\n" + + " static Object m(FI1 fi, Integer v1, Integer v2) {\n" + + " return fi.m(v1, v2);\n" + + " }\n" + + " static Object m(FI2 fi, V v1, V v2) {\n" + + " return null;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " Object obj = m((FI1) (Integer... is) -> is[0] + is[1], 3, 4);\n" + + " obj = m((Integer... is) -> is[0] + is[1], 3, 4); // Javac compiles, ECJ won't\n" + + " }\n" + + "}", + } + ); +} +public void testBug522469() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " I i = (X x) -> \"\";\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " String m(X x);\n" + + "}\n" + } + ); +} +public void testBug517951() { + runConformTest( + new String[] { + "Minimal.java", + "public class Minimal {\n" + + " public void iCrash() {\n" + + " try {\n" + + " System.out.println(\"Body can't be empty\");\n" + + " } finally {\n" + + " consumes(sneaky()::withVarargs);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Minimal().iCrash();\n" + + " }\n" + + " private Minimal sneaky() { return this; }\n" + + " private void withVarargs(String... test) {}\n" + + " private void consumes(Runnable r) {}\n" + + "}" + }, + "Body can't be empty" + ); +} +public void testBug517951a() { + runConformTest( + new String[] { + "Snippet.java", + "import java.nio.file.Files;\n" + + "import java.nio.file.Paths;\n" + + "import java.util.function.Consumer;\n" + + "public class Snippet {\n" + + " void postError( String fmt, Object ... args ) {\n" + + " }\n" + + " public boolean test(Consumer postError ) {\n" + + " return false;\n" + + " }\n" + + " void func() {\n" + + " try( java.io.InputStream istr = Files.newInputStream( Paths.get( \"\" ) )){\n" + + " } catch( Exception e ) {\n" + + " } finally {\n" + + " test( this::postError);\n" + + " }\n" + + " }\n" + + "}" + } + ); +} +public void testBug517951b() { + runConformTest( + new String[] { + "Element.java", + "public class Element\n" + + "{\n" + + " Operation operation = new Operation(Element::new);\n" + + " public Element(Integer matrix)\n" + + " {\n" + + " //...\n" + + " }\n" + + " public Element(Operation... operation)\n" + + " {\n" + + " //...\n" + + " }\n" + + "}\n" + + "class Operation\n" + + "{\n" + + " public Operation(Factory factory)\n" + + " {\n" + + " //...\n" + + " }\n" + + "}\n" + + "interface Factory\n" + + "{\n" + + " Element create(Operation... operations);\n" + + "}" + } + ); +} +public void testBug517951c() { + runConformTest( + new String[] { + "npetest/NpeTest.java", + "package npetest;\n" + + "public class NpeTest {\n" + + " public NpeTestScheduler scheduler;\n" + + " private void doIt(Object... params) {\n" + + " try {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " finally {\n" + + " scheduler.schedule(this::doIt);\n" + + " }\n" + + " }\n" + + "}", + "npetest/NpeTestIf.java", + "package npetest;\n" + + "@FunctionalInterface\n" + + "public interface NpeTestIf {\n" + + " void doSomething(Object... params);\n" + + "}", + "npetest/NpeTestScheduler.java", + "package npetest;\n" + + "public class NpeTestScheduler {\n" + + " public void schedule(NpeTestIf what) {\n" + + " what.doSomething();\n" + + " }\n" + + "}" + } + ); +} +public void testBug521818() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "test/Main.java", + "package test;\n" + + "class C {}\n" + + "class D {\n" + + " D(int i, T t) {" + + " System.out.println(\"D\");\n" + + "}\n" + + "}\n" + + "interface Goo {\n" + + " String m(T p);\n" + + "}\n" + + "class A {\n" + + " public static String bar(K a) {\n" + + " System.out.println(\"Bar\");\n" + + " return null;\n" + + " }\n" + + " public static D baz(int i, K a) {\n" + + " System.out.println(\"Baz\");\n" + + " return null;\n" + + " }\n"+ + "}\n" + + "interface Foo {\n" + + " D get(int i, Z z);\n" + + "}\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " Foo h = A::baz;\n" + + " h.get(0, null);\n" + + " Foo h2 = D::new;\n" + + " h2.get(0, null);\n" + + " Goo g = A::bar;\n" + + " g.m(null);\n" + + " } \n" + + "}" + }; + runner.expectedOutputString = + "Baz\n" + + "D\n" + + "Bar"; + runner.javacTestOptions = + JavacTestOptions.Excuse.JavacGeneratesIncorrectCode; // similar to fixed https://bugs.openjdk.java.net/browse/JDK-8058112 + runner.runConformTest(); +} +public void testBug522469a() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (X x) -> \"\";\n" + + " J j = (C y) -> \"\";\n" + + " J j2 = (C y) -> \"\";\n" + + " J j3 = (C y) -> \"\";\n" + + " J j4 = (C y) -> \"\";\n" + + " J j5 = (C y) -> \"\";\n" + + " K> k = (D> d) -> \"\";\n" + + " }\n" + + "}\n" + + "class C {}\n" + + "class D> {}\n" + + "class Z {}\n" + + "class Y extends Z {}\n" + + "interface I {\n" + + " String m(X x);\n" + + "}\n" + + "interface J {\n" + + " String m(C ya);\n" + + "}\n" + + "interface K> {\n" + + " String m(D d);\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " J j5 = (C y) -> \"\";\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from J to J\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " K> k = (D> d) -> \"\";\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The target type of this expression is not a well formed parameterized type due to bound(s) mismatch\n" + + "----------\n"); +} +public void testBug522469b() { + runNegativeTest( + new String[] { + "X.java", + "class C {}\n" + + "public class X {\n" + + " interface I {\n" + + " void foo(C l);\n" + + " }\n" + + " public static void run() {\n" + + " I i = (C l) -> {};\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i = (C l) -> {};\n" + + " ^\n" + + "Lambda expression's parameter l is expected to be of type C\n" + + "----------\n"); +} +public void testBug529199() { + runConformTest( + new String[] { + "p2/Test.java", + "package p2;\n" + + "public class Test {\n" + + " public static void main(String... args) {\n" + + " p1.B.m(); // ok\n" + + " Runnable r = p1.B::m; r.run(); // runtime error\n" + + " }\n" + + "}", + "p1/A.java", + "package p1;\n" + + "class A {\n" + + " public static void m() { System.out.println(\"A.m\"); }\n" + + "}\n", + "p1/B.java", + "package p1;\n" + + "public class B extends A {\n" + + "}\n" + }, + "A.m\n" + + "A.m" + ); +} +public void testBug553885a() { + runConformTest( + new String[] { + "p2/Test.java", + "package p2;\n" + + "import java.util.Optional;\n" + + "import p1.B;\n" + + "import p1.BImpl;\n" + + "\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " Optional map = Optional.of(new BImpl()).map(B::amount);\n" + + " System.out.print(map);\n" + + " }\n" + + "}", + "p1/A.java", + "package p1;\n" + + "interface A {\n" + + " default int amount() {\n" + + " return 0;\n" + + " }\n" + + "}\n", + "p1/B.java", + "package p1;\n" + + "public interface B extends A {}\n" + + "\n", + "p1/BImpl.java", + "package p1;\n" + + "public class BImpl implements B {}\n", + }, + "Optional[0]" + ); +} +public void testBug553885b() { + runConformTest( + new String[] { + "p2/Test.java", + "package p2;\n" + + "import java.util.Optional;\n" + + "import p1.B;\n" + + "import p1.BImpl;\n" + + "\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " B b = new BImpl();\n" + // lead inference towards Optional instead of Optional + " Optional map = Optional.of(b).map(B::amount);\n" + + " System.out.print(map);\n" + + " }\n" + + "}", + "p1/A.java", + "package p1;\n" + + "interface A {\n" + + " default int amount() {\n" + + " return 0;\n" + + " }\n" + + "}\n", + "p1/B.java", + "package p1;\n" + + "public interface B extends A {}\n" + + "\n", + "p1/BImpl.java", + "package p1;\n" + + "public class BImpl implements B {}\n", + }, + "Optional[0]" + ); +} +public void testBug553885c() { + // classes instead of interface with default method + runConformTest( + new String[] { + "p2/Test.java", + "package p2;\n" + + "import java.util.Optional;\n" + + "import p1.B;\n" + + "import p1.BImpl;\n" + + "\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " B b = new BImpl();\n" + + " Optional map = Optional.of(b).map(B::amount);\n" + + " System.out.print(map);\n" + + " }\n" + + "}", + "p1/A.java", + "package p1;\n" + + "class A {\n" + + " public int amount() {\n" + + " return 0;\n" + + " }\n" + + "}\n", + "p1/B.java", + "package p1;\n" + + "public class B extends A {}\n" + + "\n", + "p1/BImpl.java", + "package p1;\n" + + "public class BImpl extends B {}\n", + }, + "Optional[0]" + ); +} + +public void testBug521182() { + runConformTest( + new String[] { + "MethodRef.java", + "import java.util.function.Supplier;\n" + + "public class MethodRef {\n" + + " public static void m(Supplier s) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Object ref = null;\n" + + " try {\n" + + " m(ref::toString);\n" + + " System.out.println(\"A NPE should have been thrown !!!!!\");\n" + + " } catch (NullPointerException e) {\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + " }\n" + + "}" + }, + "Success"); +} +public void testBug521182a() { + runConformTest( + new String[] { + "MethodRef.java", + "import java.util.function.Supplier;\n" + + "public class MethodRef {\n" + + " Object field = null;\n" + + " public static void m(Supplier s) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " MethodRef ref = new MethodRef();\n" + + " m(ref.field::toString);\n" + + " System.out.println(\"A NPE should have been thrown !!!!!\");\n" + + " } catch (NullPointerException e) {\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + " }\n" + + "}" + }, + "Success"); +} +public void testBug521182b() { + runConformTest( + new String[] { + "MethodRef.java", + "import java.util.function.Supplier;\n" + + "public class MethodRef {\n" + + " public static void m(Supplier s) {\n" + + " }\n" + + " public static Object get() {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " m(get()::toString);\n" + + " System.out.println(\"A NPE should have been thrown !!!!!\");\n" + + " } catch (NullPointerException e) {\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + " }\n" + + "}" + }, + "Success"); +} +public void testBug516833() { + Map options = new HashMap<>(2); + options.put(CompilerOptions.OPTION_MethodParametersAttribute, "generate"); + this.runConformTest( + new String[] { + "ParameterTest.java", + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.Parameter;\n" + + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class ParameterTest {\n" + + " void foo(String s, List s1) {\n" + + " s1.stream().filter(p -> p.equals(s));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " for (Method m : ParameterTest.class.getDeclaredMethods()) {\n" + + " if (m.getName().contains(\"lambda\")) {\n" + + " Parameter[] params = m.getParameters();\n" + + " System.out.println(Arrays.asList(params));\n" + + " }\n" + + " \n" + + " }\n" + + " }\n" + + "}\n" + }, + "[java.lang.String arg0, java.lang.String arg1]", options); +} +public void testBug531093comment1() { + runConformTest( + new String[] { + "bug/Bug.java", + "package bug;\n" + + "\n" + + "import java.lang.reflect.Method;\n" + + "import java.util.Arrays;\n" + + "import java.util.Optional;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class Bug {\n" + + " public static Function> useMethodRef() {\n" + + " return Bug::getMapper;\n" + + " }\n" + + "\n" + + " private static Optional getMapper(Number event) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Method[] methods = Bug.class.getDeclaredMethods();\n" + + " for (Method method : methods) {\n" + + " Arrays.asList(method.getParameters()).toString();\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + "" + ); +} +public void testBug531093() { + runConformTest( + new String[] { + "bug/Bug.java", + "package bug;\n" + + "import java.io.Serializable;\n" + + "import java.lang.reflect.Method;\n" + + "import java.util.Arrays;\n" + + "import java.util.Optional;\n" + + "import java.util.function.Function;\n" + + "\n" + + "public class Bug {\n" + + " public Function> useMethodRef() {\n" + + " return Bug::getMapper;\n" + + " }\n" + + "\n" + + " private static Optional getMapper(Number event) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Method[] methods = Bug.class.getDeclaredMethods();\n" + + " for (Method method : methods) {\n" + + " String.valueOf(Arrays.asList(method.getParameters()));\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + "" + ); +} +public void testBug540520() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "Run.java", + "import java.util.ArrayList;\n" + + "import java.util.HashMap;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "import java.util.stream.Collectors;\n" + + "\n" + + "public class Run {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " \n" + + " List list = new ArrayList<>();\n" + + " for(int i=0;i<10;i++) {\n" + + " TypeDeptCount ty = new TypeDeptCount();\n" + + " ty.setCykbbm(\"10\"+i);\n" + + " ty.setCount(i);\n" + + " }\n" + + " List> datas = list.stream().collect(Collectors.groupingBy(TypeDeptCount::getType))\n" + + " .entrySet().stream().map(item -> item.getValue().stream().reduce(new HashMap() {\n" + + " private static final long serialVersionUID = 1L;\n" + + " {\n" + + " put(\"count\", 0);\n" + + " put(\"type\", item.getKey());\n" + + " }\n" + + " }, (data1, val) -> {\n" + + " data1.put(val.getCykbbm(), val.getCount());\n" + + " data1.put(\"count\", (Integer) data1.get(\"count\") + val.getCount());\n" + + " return data1;\n" + + " }, (data1, data2) -> {\n" + + " data2.put(\"count\", (Integer) data1.get(\"count\") + (Integer) data2.get(\"count\"));\n" + + " data1.putAll(data2);\n" + + " return data1;\n" + + " })).sorted((item1, item2) -> (Integer) item2.get(\"count\") - (Integer) item1.get(\"count\"))\n" + + " .collect(Collectors.toList());\n" + + " System.out.println(datas);\n" + + " }\n" + + "}\n", + "TypeDeptCount.java", + "public class TypeDeptCount {\n" + + "\n" + + " private String type;\n" + + " private String cykbbm;\n" + + " private Integer count;\n" + + " \n" + + " public String getType() {\n" + + " return type;\n" + + " }\n" + + " public void setType(String type) {\n" + + " this.type = type;\n" + + " }\n" + + " public String getCykbbm() {\n" + + " return cykbbm;\n" + + " }\n" + + " public void setCykbbm(String cykbbm) {\n" + + " this.cykbbm = cykbbm;\n" + + " }\n" + + " public Integer getCount() {\n" + + " return count;\n" + + " }\n" + + " public void setCount(Integer count) {\n" + + " this.count = count;\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); +} +public void testBug540631() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "EclipseCompileBug.java", + "public enum EclipseCompileBug {\n" + + " /*\n" + + " * Next line fails with these errors in Eclipse, works with javac:\n" + + " *
  • Test cannot be resolved to a type\n" + + " *
  • Cannot reference a field before it is defined\n" + + " */\n" + + " Test(Test::new);\n" + + "\n" + + " @FunctionalInterface\n" + + " public interface IConstructor {\n" + + " T apply();\n" + + " }\n" + + "\n" + + " private final IConstructor constructor;\n" + + " private EclipseCompileBug (IConstructor newObj) {\n" + + " constructor = newObj;\n" + + " }\n" + + " \n" + + " public static class Test {\n" + + " \n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); +} +public void testBug562324() { + if (this.complianceLevel < ClassFileConstants.JDK11) + return; // uses 'var' + runConformTest( + new String[] { + "X.java", + "\n" + + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.Set;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collector;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " List taskNames = Arrays.asList(\"First\", \"Second\", \"Third\");\n" + + " \n" + + " // To avoid the ClassFormatError at run-time, declare this variable with type 'Set'\n" + + " var services = taskNames.stream().collect(X.toSet(name -> new Y(){}));\n" + + "\n" + + " String[] names = services.stream().map(e -> e).toArray(String[] :: new);\n" + + " } catch (RuntimeException re) {\n" + + " System.out.print(re.getMessage());\n" + + " }\n" + + " }\n" + + " public static \n" + + " Collector> toSet(Function valueMapper) {\n" + + " throw new RuntimeException(\"it runs\");\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "abstract class Y{}\n" + }, + "it runs"); +} +public void testBug562324b() { + runConformTest( + new String[] { + "X.java", + "\n" + + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.Set;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collector;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " List taskNames = Arrays.asList(\"First\", \"Second\", \"Third\");\n" + + " \n" + + " // To avoid the ClassFormatError at run-time, declare this variable with type 'Set'\n" + + " ;\n" + + "\n" + + " String[] names = taskNames.stream().collect(X.toSet(name -> new Y(){}))\n" + + " .stream().map(e -> e).toArray(String[] :: new);\n" + + " } catch (RuntimeException re) {\n" + + " System.out.print(re.getMessage());\n" + + " }\n" + + " }\n" + + " public static \n" + + " Collector> toSet(Function valueMapper) {\n" + + " throw new RuntimeException(\"it runs\");\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "abstract class Y{}\n" + }, + "it runs"); +} +public void testBug576152() { + runConformTest( + new String[] { + "Example.java", + "\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "public class Example {\n" + + " Example() {\n" + + " inspect(this::singleMethod);\n" + + " inspect(this::overloadedMethod);\n" + + " }\n" + + " void inspect(Inspector... inspectors) { }\n" + + " void singleMethod(byte[] input, int offset, int len) { }\n" + + " void overloadedMethod() { }\n" + + " void overloadedMethod(byte[] input, int offset, int len) { }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " String s1 = hoge1(String::new);\n" + + " String s2 = hoge2(String::new); // Error. See the attached file.\n" + + " }\n" + + " static T hoge1(Supplier sup) {\n" + + " return null;\n" + + " }\n" + + " static T hoge2(Supplier... sup) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "@FunctionalInterface\n" + + "interface Inspector {\n" + + " void update(byte[] input, int offset, int len);\n" + + "}" + } + ); +} +public static Class testClass() { + return LambdaExpressionsTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaRegressionTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaRegressionTest.java new file mode 100644 index 0000000000..1e1b83443b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaRegressionTest.java @@ -0,0 +1,1223 @@ +/******************************************************************************* + * Copyright (c) 2015, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 446691 - [1.8][null][compiler] NullPointerException in SingleNameReference.analyseCode + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.EclipseHasABug; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.JavacHasABug; + +import junit.framework.Test; +@SuppressWarnings({ "rawtypes" }) +public class LambdaRegressionTest extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test572873a", "test572873b"}; +// TESTS_NUMBERS = new int[] { 50 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public LambdaRegressionTest(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=446317, java.lang.VerifyError: Bad type on operand stack with Lambdas and/or inner classes +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().run();\n" + + " }\n" + + " public void run() {\n" + + " class Inner {\n" + + " public Inner() {\n" + + " System.out.println(\"miep\");\n" + + " }\n" + + " }\n" + + " Map map = new HashMap<>();\n" + + " Function function = (name) -> {\n" + + " Inner i = map.get(name);\n" + + " if (i == null) {\n" + + " i = new Inner();\n" + + " map.put(name, i);\n" + + " }\n" + + " return i;\n" + + "\n" + + " };\n" + + " function.apply(\"test\");\n" + + " }\n" + + "}\n", + }, + "miep" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=446317, java.lang.VerifyError: Bad type on operand stack with Lambdas and/or inner classes +public void test002() { + this.runNegativeTest( + false, + EclipseHasABug.EclipseBug529197, + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "@SuppressWarnings(\"all\")\n" + + "public class X {\n" + + " private final String text = \"Bug?\";\n" + + " public static void main(String[] args) {\n" + + " new X().doIt();\n" + + " }\n" + + " private void doIt() {\n" + + " new Sub();\n" + + " }\n" + + " private class Super {\n" + + " public Super(Consumer consumer) {\n" + + " }\n" + + " }\n" + + " private class Sub extends Super {\n" + + " public Sub() {\n" + + " super(s -> System.out.println(text));\n" + + " // super(s -> System.out.println(\"miep\"));\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " super(s -> System.out.println(text));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot refer to \'this\' nor \'super\' while explicitly invoking a constructor\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=446317, java.lang.VerifyError: Bad type on operand stack with Lambdas and/or inner classes +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "@SuppressWarnings(\"all\")\n" + + "public class X {\n" + + " private final String text = \"Bug?\";\n" + + " public static void main(String[] args) {\n" + + " new X().doIt();\n" + + " }\n" + + " private void doIt() {\n" + + " new Sub();\n" + + " }\n" + + " private class Super {\n" + + " public Super(Consumer consumer) {\n" + + " }\n" + + " }\n" + + " private class Sub extends Super {\n" + + " public Sub() {\n" + + " super(s -> System.out.println(\"miep\"));\n" + + " }\n" + + " }\n" + + "}\n", + }, + "" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=446317, java.lang.VerifyError: Bad type on operand stack with Lambdas and/or inner classes +public void test004() { + this.runConformTest( + false, + JavacHasABug.JavacThrowsAnException, + new String[] { + "Y.java", + "import java.util.function.Supplier;\n" + + "class E {\n" + + " E(Supplier factory) { }\n" + + "}\n" + + "public class Y extends E {\n" + + " Y() {\n" + + " super( () -> {\n" + + " class Z extends E {\n" + + " Z() {\n" + + " super(() -> new Object());\n" + + " }\n" + + " }\n" + + " return null;\n" + + " });\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Y();\n" + + " }\n" + + "}" + }, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448724, [1.8] [compiler] Wrong resolution of overloaded method when irrelevant type parameter is present and lambda is used as parameter +public void test448724() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.concurrent.Callable;\n" + + "public class X {\n" + + " public void mismatchRunnableCallable() throws Exception {\n" + + " //Resolves to case1(Runnable) method invocation; lambda with block\n" + + " case1(() -> {\"abc\".length();});\n" + + " //Resolves to case1(Callable) method invocation, resulting in type mismatch; block removed - lambda with expression\n" + + " case1(() -> \"abc\".length());\n" + + " }\n" + + " public void noSuchMismatch() throws Exception {\n" + + " //no difference to case1 \n" + + " case2(() -> {\"abc\".length();});\n" + + " //the only difference to case 1 is the missing irrelevant type parameter. Properly resolves to case2(Runnable) here\n" + + " case2(() -> \"abc\".length());\n" + + " }\n" + + " public void case1(final Runnable r) {\n" + + " System.out.println(\"case1: Runnable\");\n" + + " }\n" + + " public void case1(Callable c) {\n" + + " System.out.println(\"case1: Callable\");\n" + + " }\n" + + " public void case2(final Runnable supplier) {\n" + + " System.out.println(\"case2: Runnable\");\n" + + " }\n" + + " public void case2(Callable conditionEvaluator) {\n" + + " System.out.println(\"case2: Callable\");\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " new X().mismatchRunnableCallable();\n" + + " new X().noSuchMismatch();\n" + + " }\n" + + "}\n" + }, + "case1: Runnable\n" + + "case1: Runnable\n" + + "case2: Runnable\n" + + "case2: Runnable"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +public void test447767() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " T goo(U u, V v);\n" + + "}\n" + + "public class X {\n" + + " static T foo(T t, U u, V v) {\n" + + " System.out.println(\"Wrong!\");\n" + + " return null;\n" + + " }\n" + + " static V foo(T t, U u, I i) {\n" + + " System.out.println(\"Right!\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String s = goo(foo(\"String\", \"String\", (u, v) -> v));\n" + + " }\n" + + " static T goo(T t) {\n" + + " return t; \n" + + " }\n" + + "}\n" + }, + "Right!"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +public void test447767a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " T goo(U u, V v);\n" + + "}\n" + + "public class X {\n" + + " static T foo(T t, U u, I i) {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String s = goo(foo(\"String\", \"String\", (u, v) -> v));\n" + + " }\n" + + " static T goo(T t) {\n" + + " return t; \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " String s = goo(foo(\"String\", \"String\", (u, v) -> v));\n" + + " ^\n" + + "Type mismatch: cannot convert from Object to String\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +public void test447767b() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " T goo(U u, V v);\n" + + "}\n" + + "public class X {\n" + + " static String goo(String s, String s2) {\n" + + " return null;\n" + + " }\n" + + " static V foo(T t, U u, I i) {\n" + + " System.out.println(\"Right!\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String s = goo(foo(\"String\", \"String\", X::goo));\n" + + " }\n" + + " static T goo(T t) {\n" + + " return t; \n" + + " }\n" + + "}\n" + }, + "Right!"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +public void test447767c() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " T goo(U u, V v);\n" + + "}\n" + + "public class X {\n" + + " static String goo(String s, String s2) {\n" + + " return null;\n" + + " }\n" + + " static T foo(T t, U u, V v) {\n" + + " System.out.println(\"Wrong!\");\n" + + " return null;\n" + + " }\n" + + " static V foo(T t, U u, I i) {\n" + + " System.out.println(\"Right!\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String s = goo(foo(\"String\", \"String\", X::goo));\n" + + " }\n" + + " static T goo(T t) {\n" + + " return t; \n" + + " }\n" + + "}\n" + }, + "Right!"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=447767, [1.8][compiler] Spurious method not applicable error due to interaction between overload resolution and type inference +public void test447767d() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " T goo(U u, V v);\n" + + "}\n" + + "public class X {\n" + + " static String goo(String s, String s2) {\n" + + " return null;\n" + + " }\n" + + " static T foo(T t, U u, V v) {\n" + + " System.out.println(\"Wrong!\");\n" + + " return null;\n" + + " }\n" + + " static V foo(T t, U u, I i) {\n" + + " System.out.println(\"Right!\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String s = goo(foo(\"String\", \"String\", X::goo));\n" + + " }\n" + + " static T goo(T t) {\n" + + " return t; \n" + + " }\n" + + "}\n" + }, + "Right!"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449410, [1.8][compiler] Eclipse java compiler does not detect a bad return type in lambda expression +public void test449410() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collections;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Collections.emptyMap()\n" + + " .entrySet()\n" + + " .forEach(entry -> test() ? bad() : returnType());\n" + + " }\n" + + " private static boolean test() {\n" + + " return (System.currentTimeMillis() & 0x1) == 0;\n" + + " }\n" + + " private static void returnType() {\n" + + " }\n" + + " private static void bad() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " .forEach(entry -> test() ? bad() : returnType());\n" + + " ^^^^^^^\n" + + "The method forEach(Consumer>) in the type Iterable> is not applicable for the arguments (( entry) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " .forEach(entry -> test() ? bad() : returnType());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Invalid expression as statement\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=449824, [1.8] Difference in behaviour with method references and lambdas +// Captures present behavior - may not be correct. +public void test449824() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Concrete fl = new Concrete();\n" + + " fl.call(each -> each.doSomething()); // fails\n" + + " fl.call((Target each) -> each.doSomething()); // fails\n" + + " fl.call(Target::doSomething); // succeeds in Eclipse 4.5M3 and 4.4.1\n" + + " // but fails in Java 8 1.8.0_11\n" + + " }\n" + + " public static class Target {\n" + + " public void doSomething() {\n" + + " }\n" + + " }\n" + + " public static class Concrete implements Left, Right {\n" + + " public void call(RightHand p) {\n" + + " }\n" + + " }\n" + + " public interface Left {\n" + + " default void call(LeftHand p) {\n" + + " }\n" + + " }\n" + + " public interface LeftHand {\n" + + " public void left(T t);\n" + + " }\n" + + " public interface Right {\n" + + " public void call(RightHand p);\n" + + " }\n" + + " public interface RightHand {\n" + + " public void right(T t);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " fl.call(each -> each.doSomething()); // fails\n" + + " ^^^^\n" + + "The method call(X.RightHand) is ambiguous for the type X.Concrete\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " fl.call(Target::doSomething); // succeeds in Eclipse 4.5M3 and 4.4.1\n" + + " ^^^^\n" + + "The method call(X.RightHand) is ambiguous for the type X.Concrete\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448954, [1.8][compiler] Suspect error: "The method foo(String, String, X::goo) is undefined for the type X" +public void test448954() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " T goo(U u, V v);\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static String goo(String s, String s2) {\n" + + " return null;\n" + + " }\n" + + " static T foo(T t, U u, J j) {\n" + + " System.out.println(\"Wrong!\");\n" + + " return null;\n" + + " }\n" + + " static V foo(T t, U u, I i) {\n" + + " System.out.println(\"Right!\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " String s = goo(foo(\"String\", \"String\", X::goo));\n" + + " }\n" + + " static T goo(T t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + "Right!"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=450380, [1.8][compiler] NPE in Scope.getExactConstructor(..) for bad constructor reference +public void test450380() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.function.IntFunction;\n" + + "public class X {\n" + + " IntFunction> noo() {\n" + + " return System::new;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return System::new;\n" + + " ^^^^^^^^^^^\n" + + "The type System does not define System(int) that is applicable here\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=450604, [1.8] CCE at InferenceContext18.getParameter line 1377 +public void test450604() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static List of(T one) { return null; }\n" + + " public @SafeVarargs static List of(T... items) { return null; }\n" + + " public static void printDependencyLoops() throws IOException {\n" + + " Function> mapping = X::of;\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=450604, [1.8] CCE at InferenceContext18.getParameter line 1377 +public void test450604a() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " public static List of() { return null; }\n" + + " public static @SafeVarargs List of(T... values) { return null; }\n" + + " static void walkAll() {\n" + + " X. of();\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=451677, [1.8][compiler] missing type inference +public void _test451677() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void test() {\n" + + " operationOnCreated(create(123, size -> new ArrayList(size)), l -> l.size()); // works with: (ArrayList l) -> l.size()\n" + + " }\n" + + " public static R create(A arg, Function factory) {\n" + + " return factory.apply(arg);\n" + + " }\n" + + " public static R operationOnCreated(A created, Function function) {\n" + + " return function.apply(created);\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=451840 +// [1.8] java.lang.BootstrapMethodError when running code with constructor reference +public void testBug451840() { + runNegativeTest(new String [] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X test = new X();\n" + + " MySupplier s = test::new; // incorrect\n" + + " }\n" + + " public interface MySupplier {\n" + + " T create();\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " MySupplier s = test::new; // incorrect\n" + + " ^^^^\n" + + "test cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448556 +// [1.8][compiler] Invalid compiler error about effectively final variable outside the context of a lambda. +public void testBug4448556() { + this.runConformTest(new String [] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " private static final List INTEGERS = Arrays.asList(1, 2, 3, 4);\n" + + " public static void main(String[] args) {\n" + + " for (int i = 0; i < INTEGERS.size(); i++) {\n" + + " MyPredicate predicate = INTEGERS.get(i)::equals;\n" + + " }\n" + + " } \n" + + " public interface MyPredicate extends Serializable {\n" + + " boolean accept(T each);\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448556 +// [1.8][compiler] Invalid compiler error about effectively final variable outside the context of a lambda. +public void testBug4448556a() { + this.runConformTest(new String [] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " int value = 0; \n" + + " private static final List INTEGERS = Arrays.asList(1, 2, 3, 4);\n" + + " public Integer next() {\n" + + " return new Integer(++value);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X t = new X();\n" + + " MyPredicate predicate = t.next()::equals;\n" + + " System.out.println(\"Value \" + t.value + \" accept \" + predicate.accept(t.value));\n" + + " }\n" + + " public interface MyPredicate extends Serializable {\n" + + " boolean accept(T each);\n" + + " }\n" + + "}" + }, + "Value 1 accept true"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=453687 +// [1.8][compiler]Incorrect errors when compiling code with Method References +public void testBug453687() { + this.runConformTest(new String [] { + "X.java", + "import static java.util.stream.Collectors.groupingBy;\n" + + "import static java.util.stream.Collectors.mapping;\n" + + "import static java.util.stream.Collectors.toSet;\n" + + "import java.util.Locale;\n" + + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map> countryLanguagesMap = Stream.of(Locale.getAvailableLocales()).collect(\n" + + " groupingBy(Locale::getDisplayCountry, mapping(Locale::getDisplayLanguage, toSet())));\n" + + " }\n" + + "} " + }, + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=456481 - [1.8] VerifyError on constructor reference inside lambda +public void testBug456481() { + this.runConformTest(new String [] { + "Test.java", + "public class Test {\n" + + " interface Constructor {\n" + + " MyTest execute();\n" + + " }\n" + + " interface ArrayConstructor {\n" + + " MyTest[] execute(int no);\n" + + " }\n" + + " interface ParameterizedConstructor {\n" + + " MyParameterizedTest execute();\n" + + " }\n" + + " class MyTest {\n" + + " MyTest() { System.out.println(\"Constructor executed\"); }\n" + + " }\n" + + " class MyParameterizedTest {\n" + + " MyParameterizedTest() {\n" + + " System.out.println(\"Parameterized Constructor executed\");\n" + + " }\n" + + " }\n" + + " public Constructor getConstructor() {\n" + + " return getConstructor(() -> { return MyTest::new; });\n" + + " }\n" + + " public MyTest[] getArray(int no) {\n" + + " return new MyTest[no];\n" + + " }\n" + + " ArrayConstructor getArrayConstructor() {\n" + + " return getArrayConstructor(() -> {return MyTest[]::new;});\n" + + " }\n" + + " ParameterizedConstructor getParameterizedConstructor() {\n" + + " return getParameterizedConstructor(() -> {return MyParameterizedTest::new;});\n" + + " }\n" + + " ArrayConstructor getArrayConstructor(ArrayWrapper w) {\n" + + " return w.unwrap();\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " Test t = new Test();\n" + + " MyTest mytest = t.getConstructor().execute();\n" + + " MyTest[] array = t.getArrayConstructor().execute(2);\n" + + " MyParameterizedTest pt = t.getParameterizedConstructor().execute();\n" + + " }\n" + + " ParameterizedConstructor getParameterizedConstructor(PTWrapper ptw) {\n" + + " return ptw.unwrap();\n" + + " }\n" + + " Constructor getConstructor(Wrapper arg) {\n" + + " return arg.unwrap();\n" + + " }\n" + + " interface PTWrapper {\n" + + " ParameterizedConstructor unwrap();\n" + + " }\n" + + " interface ArrayWrapper {\n" + + " ArrayConstructor unwrap();\n" + + " }\n" + + " interface Wrapper {\n" + + " Constructor unwrap();\n" + + " }\n" + + "}" + }, + "Constructor executed\n" + + "Parameterized Constructor executed"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=457007, VerifyError +public void testBug457007() { + this.runConformTest(new String [] { + "Test.java", + "public class Test {\n" + + " void method() {\n" + + " class Bar {}\n" + + " java.util.function.Function f = str -> new Bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}" + }, + "done"); +} +public void testBug446691_comment5() { + runConformTest(new String [] { + "Test.java", + "import java.util.*;\n" + + "\n" + + "public class Test {\n" + + " protected final Integer myInt;\n" + + "\n" + + " public Test() {\n" + + " myInt = Integer.valueOf(0);\n" + + " try {\n" + + " Optional.empty().orElseThrow(() -> new IllegalArgumentException(myInt.toString()));\n" + + " } catch (IllegalArgumentException e) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " return;\n" + + " }\n" + + "}\n" + }); +} +public void testBug446691_comment8() { + runConformTest(new String [] { + "Boom.java", + "public class Boom {\n" + + " private final String field;\n" + + " public Boom(String arg) {\n" + + " this.field = arg;\n" + + " try {\n" + + " java.util.function.Supplier supplier = () -> field;\n" + + " } catch (Exception e) {\n" + + " \n" + + " }\n" + + " }\n" + + "}\n" + }); +} +public void testBug446691_comment14() { + runNegativeTest(new String [] { + "test/Main.java", + "package test;\n" + + "\n" + + "import java.util.logging.Logger;\n" + + "\n" + + "public class Main {\n" + + "\n" + + " private static final Logger LOG = Logger.getLogger(\"test\");\n" + + " private final static String value;\n" + + "\n" + + " static {\n" + + " try {\n" + + " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + + " } catch (final Exception ex) {\n" + + " throw new ExceptionInInitializerError(ex);\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in test\\Main.java (at line 8)\n" + + " private final static String value;\n" + + " ^^^^^\n" + + "The blank final field value may not have been initialized\n" + + "----------\n" + + "2. ERROR in test\\Main.java (at line 12)\n" + + " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + + " ^^^^^\n" + + "The blank final field value may not have been initialized\n" + + "----------\n"); +} +// error in lambda even if field is assigned later +public void testBug446691_comment14b() { + runNegativeTest(new String [] { + "test/Main.java", + "package test;\n" + + "\n" + + "import java.util.logging.Logger;\n" + + "\n" + + "public class Main {\n" + + "\n" + + " private static final Logger LOG = Logger.getLogger(\"test\");\n" + + " private final static String value;\n" + + "\n" + + " static {\n" + + " try {\n" + + " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + + " } catch (final Exception ex) {\n" + + " throw new ExceptionInInitializerError(ex);\n" + + " }\n" + + " value = \"\";" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in test\\Main.java (at line 12)\n" + + " LOG.info(() -> String.format(\"Value is: %s\", value));\n" + + " ^^^^^\n" + + "The blank final field value may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=463526 +// Parenthesis are incorrectly allowed in lambda when LambdaBody is an expression statement +public void testBug463526() { + runNegativeTest(new String [] { + "Test.java", + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " Receiver r = new Receiver();\n" + + " r.accept((l) -> (doItOnTheClass(new Object())));\n" + + " }\n" + + " public static void doItOnTheClass(Object o) {\n" + + " System.out.println(\"done it\");\n" + + " }\n" + + " public static class Receiver {\n" + + " public void accept(Listener l) {\n" + + " l.doIt(new Object());\n" + + " }\n" + + " }\n" + + " public static interface Listener {\n" + + " public void doIt(Object o);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Test.java (at line 4)\n" + + " r.accept((l) -> (doItOnTheClass(new Object())));\n" + + " ^^^^^^\n" + + "The method accept(Test.Listener) in the type Test.Receiver is not applicable for the arguments (( l) -> {})\n" + + "----------\n" + + "2. ERROR in Test.java (at line 4)\n" + + " r.accept((l) -> (doItOnTheClass(new Object())));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Invalid expression as statement\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=463526 +// Parenthesis are incorrectly allowed in lambda when LambdaBody is an expression statement +public void testBug463526b() { + runNegativeTest(new String [] { + "Test.java", + "import java.util.function.Consumer;\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " Receiver r = new Receiver();\n" + + " r.process((o) -> (new Object()));\n" + + " }\n" + + " public static class Receiver {\n" + + " public void process(Consumer p) {\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Test.java (at line 5)\n" + + " r.process((o) -> (new Object()));\n" + + " ^^^^^^^\n" + + "The method process(Consumer) in the type Test.Receiver is not applicable for the arguments (( o) -> {})\n" + + "----------\n" + + "2. ERROR in Test.java (at line 5)\n" + + " r.process((o) -> (new Object()));\n" + + " ^^^^^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=463526 +// Parenthesis are incorrectly allowed in lambda when LambdaBody is an expression statement +public void testBug463526c() { + runNegativeTest(new String [] { + "Test.java", + "import java.util.function.Consumer;\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " Receiver r = new Receiver();\n" + + " r.assign((o) -> (o = new Object()));\n" + + " }\n" + + " public static class Receiver {\n" + + " public void assign(Consumer a) {\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Test.java (at line 5)\n" + + " r.assign((o) -> (o = new Object()));\n" + + " ^^^^^^\n" + + "The method assign(Consumer) in the type Test.Receiver is not applicable for the arguments (( o) -> {})\n" + + "----------\n" + + "2. ERROR in Test.java (at line 5)\n" + + " r.assign((o) -> (o = new Object()));\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=464408 +public void testBug464408() { + runNegativeTest(new String[]{ + "test/X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " void x() {\n" + + " List> list = new ArrayList<>();\n" + + " list.stream().toArray(List[]::new);\n" + + " }" + + "}" + }, "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " list.stream().toArray(List[]::new);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of List\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=465900 +// Internal compiler error: java.lang.IllegalArgumentException: info cannot be null at org.eclipse.jdt.internal.compiler.codegen.StackMapFrame.addStackItem(StackMapFrame.java:81) +public void testBug465900() { + this.runConformTest(new String [] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Supplier;\n" + + "public class X {\n" + + " private static final long serialVersionUID = 1L;\n" + + " protected void x() {\n" + + " String str = \"groep.koppeling.\" + (\"\".isEmpty() ? \"toevoegen\" : \"bewerken\");\n" + + " List bean = new ArrayList<>();\n" + + " test(bean.get(0)::isEmpty);\n" + + " }\n" + + " private void test(SerializableSupplier test) {}\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface SerializableSupplier extends Supplier, Serializable {}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=477888 +// [1.8][compiler] Compiler silently produces garbage but editor shows no errors +public void testBug477888() { + runNegativeTest(new String [] { + "Test.java", + "import java.io.IOException;\n" + + "import java.nio.file.Files;\n" + + "import java.nio.file.Paths;\n" + + "import java.util.function.Consumer;\n" + + "public class Test {\n" + + " public static void main(String[] args) throws IOException {\n" + + " Files.lines(Paths.get(args[0])).filter(x -> {return !x.startsWith(\".\");}).forEach(printMe());\n" + + " }\n" + + " private static Consumer printMe() {\n" + + " return x -> x.isEmpty() ? System.out.println() : System.out.println(getIndex() + \" \" + x); // error must be reported here!\n" + + " }\n" + + " static int idx;\n" + + "\n" + + " private static int getIndex() {\n" + + " return ++idx;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 10)\n" + + " return x -> x.isEmpty() ? System.out.println() : System.out.println(getIndex() + \" \" + x); // error must be reported here!\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Invalid expression as statement\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=472648 +// [compiler][1.8] Lambda expression referencing method with generic type has incorrect compile errors +public void testBug472648() { + runNegativeTest( + false, + JavacHasABug.JavacBugFixed_901, + new String [] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Consumer;\n" + + "public class Test {\n" + + " public static void main(String argv[]) {\n" + + " new Test();\n" + + " }\n" + + " public Test() {\n" + + " List numList = new ArrayList<>();\n" + + " numList.add(1);\n" + + " numList.add(1.5);\n" + + " numList.add(2);\n" + + " numList.add(2.5);\n" + + " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + + " }\n" + + " private void forEachValueOfType(List list, Class type, Consumer action) {\n" + + " \n" + + " for (Object o : list) {\n" + + " if (type.isAssignableFrom(o.getClass())) {\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " T convertedObject = (T) o;\n" + + " action.accept(convertedObject);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Test.java (at line 14)\n" + + " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The method forEachValueOfType(List, Class, Consumer) in the type Test is not applicable for the arguments (List, Class, (Integer i) -> {})\n" + + "----------\n" + + "2. ERROR in Test.java (at line 14)\n" + + " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + + " ^^^^^^^\n" + + "Incompatible type specified for lambda expression's parameter i\n" + + "----------\n" + + "3. ERROR in Test.java (at line 14)\n" + + " forEachValueOfType(numList, Integer.class, (Integer i) -> (System.out.println(Integer.toString(i))));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Invalid expression as statement\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=473432 +// Internal compiler error: java.lang.IllegalArgumentException: info cannot be null at org.eclipse.jdt.internal.compiler.codegen.StackMapFrame.addStackItem(StackMapFrame.java:81) +public void testBug473432() { + this.runConformTest(new String [] { + "Tester.java", + "import java.util.function.Function;\n" + + "public class Tester {\n" + + " private static class ValueWrapper {\n" + + " private O val_;\n" + + " public ValueWrapper(O val) {\n" + + " val_ = val;\n" + + " }\n" + + " public R mapOrElse(Function func, R defaultValue) {\n" + + " if(val_ != null) {\n" + + " return func.apply(val_);\n" + + " }\n" + + " return defaultValue;\n" + + " }\n" + + " }\n" + + " private static void handleObject(Object object) {\n" + + " System.out.println(\"Handled: \" + object);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " ValueWrapper wrapper = new ValueWrapper<>(\"value\");\n" + + " boolean skipMethod = false;\n" + + " // works on both JDT 3.9.2 and 3.11.0\n" + + " Boolean result = skipMethod ? true : wrapper.mapOrElse(v -> false, null);\n" + + " System.out.println(result);\n" + + " wrapper = new ValueWrapper<>(null);\n" + + " // works on JDT 3.9.2\n" + + " handleObject(skipMethod ?\n" + + " true :\n" + + " wrapper.mapOrElse(v -> false, null));\n" + + " wrapper = new ValueWrapper<>(null);\n" + + " // works on neither version\n" + + " result = skipMethod ?\n" + + " true :\n" + + " wrapper.mapOrElse(v -> false, null);\n" + + " System.out.println(result);\n" + + " }\n" + + "}\n" + }, + "false\n" + + "Handled: null\n" + + "null"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=511676 [1.8] Lambda with inner class defs causes java.lang.VerifyError: Bad type on operand stack +public void testBug511676() { + this.runConformTest(new String [] { + "A.java", + "import java.util.function.Function;\n" + + "public class A {\n" + + " interface C { }\n" + + " interface O {\n" + + " Object r(C s);\n" + + " }\n" + + " static O m(O source, Function> mapper) {\n" + + " return o -> {\n" + + " class D {\n" + + " class E {\n" + + " }\n" + + " E e = new E();\n" + + " }\n" + + " D d = new D();\n" + + " return d.e;\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " m(null, null);\n" + + " System.out.println(\" Done\");\n" + + " }\n" + + "}\n" + }, + "Done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=511676 [1.8] Lambda with inner class defs causes java.lang.VerifyError: Bad type on operand stack +public void testBug511676a() { + this.runConformTest(new String [] { + "A.java", + "public class A {\n" + + " interface C { }\n" + + " interface O {\n" + + " Object r(C s);\n" + + " }\n" + + " static O def = o -> {\n" + + " class D {\n" + + " class E {\n" + + " }\n" + + " E e = new E();\n" + + " }\n" + + " D d = new D();\n" + + " return d.e;\n" + + " };\n" + + " public static void main(String[] args) {\n" + + " O o = A.def;\n" + + " System.out.println(\" Done\");\n" + + " }\n" + + "}\n" + }, + "Done"); +} +public void testBug543778() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Sandbox.java", + "import java.util.function.Supplier;\n" + + "\n" + + "public class Sandbox {\n" + + "\n" + + " R get(Supplier<@NonNull R> impl) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " Object getter() {\n" + + " return get(() -> new Object() {\n" + + "\n" + + " @Override\n" + + " public String toString() {\n" + + " return super.toString();\n" + + " }\n" + + "\n" + + " });\n" + + " }\n" + + "\n" + + "}\n", + "NonNull.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ ElementType.TYPE_USE })\n" + + "public @interface NonNull {\n" + + " // marker annotation with no members\n" + + "}\n", + }; + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); // bug happens due to type annotation handling + runner.runConformTest(); +} +public void test572873a() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Iterator;\n" + + "\n" + + "public class X {\n" + + " static Iterable iterable() {\n" + + " return () -> new Iterator() {\n" + + " @Override\n" + + " public boolean hasNext() {\n" + + " return false;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public T next() {\n" + + " return null;\n" + + " }\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"test T\");\n" + + " }\n" + + "}", + }, + "test T" + ); +} +public void test572873b() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Consumer;\n" + + "\n" + + "public class X {\n" + + " public static void build(T element) {\n" + + " new Thread(() -> {\n" + + " new Consumer() {\n" + + "\n" + + " @Override\n" + + " public void accept(T t) {" + + "\n" + + " }\n" + + " };\n" + + " });\n" + + " }" + + " public static void main(String[] args) {\n" + + " System.out.println(\"test T\");\n" + + " }\n" + + "}", + }, + "test T" + ); +} +public static Class testClass() { + return LambdaRegressionTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaShapeTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaShapeTests.java new file mode 100644 index 0000000000..97c50dfff0 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaShapeTests.java @@ -0,0 +1,3287 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class LambdaShapeTests extends AbstractRegressionTest { +static { +// TESTS_NAMES = new String[] { "test016"}; +// TESTS_NUMBERS = new int[] { 50 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public LambdaShapeTests(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "interface VoidI {\n" + + " void foo(String s);\n" + + "}\n" + + "class Test {\n" + + " public String gooVoid(VoidI i){return \"\";}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test test = new Test();\n" + + " test.gooVoid((x) -> {\n" + + " if (false) {\n" + + " x += \"a\";\n" + + " }\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " if (true);\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " if (true) {\n" + + " x += \"a\";\n" + + " }\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " final boolean val = true;\n" + + " if (val) {\n" + + " x += \"a\";\n" + + " }\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " final boolean val = true;\n" + + " if (val);\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " final boolean val = false;\n" + + " if (val) {\n" + + " x += \"a\";\n" + + " }\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " if (x != null) {\n" + + " x += \"a\";\n" + + " }\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " final boolean val = true;\n" + + " if (x != null);\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " if (false) {\n" + + " x += \"a\";\n" + + " } else {\n" + + " x += \"b\";\n" + + " }\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " if (false) {\n" + + " x += \"a\";\n" + + " } else;\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " final boolean val = false;\n" + + " if (val) {\n" + + " x += \"a\";\n" + + " } else {\n" + + " x += \"b\";\n" + + " }\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " final boolean val = false;\n" + + " if (val) {\n" + + " x += \"a\";\n" + + " } else;\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " if (x != null) {\n" + + " x += \"a\";\n" + + " } else {\n" + + " x += \"b\";\n" + + " }\n" + + " });\n" + + " test.gooVoid((x) -> {\n" + + " if (x != null) {\n" + + " x += \"a\";\n" + + " } else;\n" + + " });\n" + + " }\n" + + "}\n", + }); +} +public void test002() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x); \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " final boolean FALSE = false;\n" + + " goo((x) -> {\n" + + " if(true) return \"\";\n" + + " else return null;\n" + + " });\n" + + " goo((x) -> {\n" + + " if(false) return \"\";\n" + + " else return null;\n" + + " });\n" + + " goo((x) -> {\n" + + " if(x > 0) return \"\";\n" + + " else return null;\n" + + " });\n" + + " goo((x) -> {\n" + + " if(FALSE) return \"\";\n" + + " else return null;\n" + + " });\n" + + " goo((x) -> {\n" + + " if(!FALSE) return \"\";\n" + + " else return null;\n" + + " });\n" + + " goo((x) -> {\n" + + " if(!FALSE) return \"\";\n" + + " else return null;\n" + + " });\n" + + " }\n" + + "}\n" + }); +} +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "interface VoidI {\n" + + " void foo(String s);\n" + + "}\n" + + "class Test {\n" + + " public String gooVoid(VoidI i){return \"\";}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test test = new Test();\n" + + " test.gooVoid((x) -> {\n" + + " if (true) {\n" + + " return 0;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " test.gooVoid((x) -> {\n" + + " ^^^^^^^\n" + + "The method gooVoid(VoidI) in the type Test is not applicable for the arguments (( x) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " return 0;\n" + + " ^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "interface VoidI {\n" + + " void foo(String s);\n" + + "}\n" + + "class Test {\n" + + " public String gooVoid(VoidI i){return \"\";}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test test = new Test();\n" + + " test.gooVoid((x) -> {\n" + + " final boolean val = true;\n" + + " if (val) {\n" + + " return x;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " test.gooVoid((x) -> {\n" + + " ^^^^^^^\n" + + "The method gooVoid(VoidI) in the type Test is not applicable for the arguments (( x) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " return x;\n" + + " ^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "interface VoidI {\n" + + " void foo(String s);\n" + + "}\n" + + "class Test {\n" + + " public String gooVoid(VoidI i){return \"\";}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test test = new Test();\n" + + " test.gooVoid((x) -> {\n" + + " if (x != null) {\n" + + " return 0;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " test.gooVoid((x) -> {\n" + + " ^^^^^^^\n" + + "The method gooVoid(VoidI) in the type Test is not applicable for the arguments (( x) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " return 0;\n" + + " ^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "interface VoidI {\n" + + " void foo(String s);\n" + + "}\n" + + "class Test {\n" + + " public String gooVoid(VoidI i){return \"\";}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test test = new Test();\n" + + " test.gooVoid((x) -> {\n" + + " if (false) {\n" + + " x += \"a\";\n" + + " } else {\n" + + " return 0;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " test.gooVoid((x) -> {\n" + + " ^^^^^^^\n" + + "The method gooVoid(VoidI) in the type Test is not applicable for the arguments (( x) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " return 0;\n" + + " ^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + "interface VoidI {\n" + + " void foo(String s);\n" + + "}\n" + + "class Test {\n" + + " public String gooVoid(VoidI i){return \"\";}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test test = new Test();\n" + + " test.gooVoid((x) -> {\n" + + " final boolean val = false;\n" + + " if (val) {\n" + + " x += \"a\";\n" + + " } else {\n" + + " return 0;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " test.gooVoid((x) -> {\n" + + " ^^^^^^^\n" + + "The method gooVoid(VoidI) in the type Test is not applicable for the arguments (( x) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " return 0;\n" + + " ^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "interface VoidI {\n" + + " void foo(String s);\n" + + "}\n" + + "class Test {\n" + + " public String gooVoid(VoidI i){return \"\";}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test test = new Test();\n" + + " test.gooVoid((x) -> {\n" + + " if (x != null) {\n" + + " x += \"a\";\n" + + " } else {\n" + + " return 0;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " test.gooVoid((x) -> {\n" + + " ^^^^^^^\n" + + "The method gooVoid(VoidI) in the type Test is not applicable for the arguments (( x) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " return 0;\n" + + " ^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x); \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " final boolean FALSE = false;\n" + + " goo((x) -> {\n" + + " if(FALSE) return \"\";\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x); \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {\n" + + " if(true);\n" + + " else return \"\";\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " else return \"\";\n" + + " ^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x); \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {\n" + + " if(false) return null;\n" + + " else;\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " if(false) return null;\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " else;\n" + + " ^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x); \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {\n" + + " if(x > 0) return \"\";\n" + + " else;\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " else;\n" + + " ^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x); \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {\n" + + " if(x > 0);\n" + + " else return \"\";\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x); \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {\n" + + " if(x < 0) return null;\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x); \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " final boolean FALSE = false;\n" + + " goo((x) -> {\n" + + " if(!FALSE) return \"\";\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " final boolean FALSE = false;\n" + + " goo((x) -> {while (FALSE) throw new Exception();});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " goo((x) -> {while (FALSE) throw new Exception();});\n" + + " ^^^^^^\n" + + "This lambda expression must return a result of type String\n" + + "----------\n"); +} +public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {while (false) return \"\";});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {while (false) return \"\";});\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " goo((x) -> {while (false) return \"\";});\n" + + " ^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {while (x > 0) {\n" + + " if(x > 0) {return \"\";} else {break;}\n" + + " }});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {while (x > 0) {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " if(x > 0) {return \"\";} else {break;}\n" + + " ^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +public void test019() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {while (x > 0) {\n" + + " if(x > 0) {return \"\";}\n" + + " }});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {while (x > 0) {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test020() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " final boolean TRUE = true;\n" + + " goo((x) -> {while (TRUE) {\n" + + " if(x > 0) {System.out.println();}\n" + + " }});\n" + + " goo((x) -> {while (true) {\n" + + " if(x > 0) {System.out.println();}\n" + + " }});\n" + + " }\n" + + "}\n" + }); +} +public void test021() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {\n" + + " int i = 100;\n" + + " outer: while(x > 0) {\n" + + " inner: while(i > 0) {\n" + + " if(--i > 50) {\n" + + " return \"\";\n" + + " }\n" + + " if(i > 90) {\n" + + " break outer;\n" + + " }\n" + + " return \"\";\n" + + " }\n" + + " }});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " inner: while(i > 0) {\n" + + " ^^^^^\n" + + "The label inner is never explicitly referenced\n" + + "----------\n"); +} +public void test022() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String s) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void zoo(I i) {}\n" + + " void test() {\n" + + " final boolean FALSE = false;\n" + + " final boolean TRUE = true;\n" + + " zoo((x) -> {while (TRUE) throw new Exception();});\n" + + " zoo((x) -> {while (!FALSE) return ;});\n" + + " zoo((x) -> {while (x.length() > 0) {\n" + + " if(x.length() > 0) {return ;} else {break;}\n" + + " }});\n" + + " zoo((x) -> {while (x.length() > 0) {\n" + + " if(x.length() > 0) {return ;}\n" + + " }});\n" + + " zoo((x) -> {while (true) {\n" + + " if(x.length() > 0) {System.out.println();}\n" + + " }});\n" + + " zoo((x) -> {while (TRUE) {\n" + + " if(x.length() > 0) {System.out.println();}\n" + + " }});\n" + + " zoo((x) -> {\n" + + " int i = 100;\n" + + " outer: while(x.length() > 0) {\n" + + " inner: while(i > 0) {\n" + + " if(--i > 50) {\n" + + " break inner ;\n" + + " }\n" + + " if(i > 90) {\n" + + " break outer;\n" + + " }\n" + + " return ;\n" + + " }\n" + + " }});\n" + + " }\n" + + "}\n" + }); +} +public void test023() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " final boolean FALSE = false;\n" + + " final boolean TRUE = true;\n" + + " goo((x) -> {do {throw new Exception();}while (FALSE);});\n" + + " goo((x) -> {do { return \"\";}while (false);});\n" + + " goo((x) -> {do {\n" + + " if(x > 0) {System.out.println();}\n" + + " }while (true);});\n" + + " goo((x) -> {do {\n" + + " if(x > 0) {System.out.println();}\n" + + " }while (TRUE);});\n" + + " }\n" + + "}\n" + }); +} +public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {do {\n" + + " if(x > 0) {return \"\";} else {break;}\n" + + " }while (x > 0);});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {do {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " if(x > 0) {return \"\";} else {break;}\n" + + " ^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +public void test025() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {do {\n" + + " if(x > 0) {return \"\";}\n" + + " }while (x > 0);});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {do {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(int x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {\n" + + " int i = 100;\n" + + " outer: do {\n" + + " inner: do {\n" + + " if(--i > 50) {\n" + + " return \"\";\n" + + " }\n" + + " if(i > 90) {\n" + + " break outer;\n" + + " }\n" + + " return \"\";\n" + + " }while(i > 0);\n" + + " }while(x > 0);});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " inner: do {\n" + + " ^^^^^\n" + + "The label inner is never explicitly referenced\n" + + "----------\n"); +} +public void test027() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String s) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void zoo(I i) {}\n" + + " void test() {\n" + + " zoo((x) -> {do {\n" + + " if(x.length() > 0) {System.out.println();}\n" + + " }while (true);});\n" + + " zoo((x) -> {do {throw new Exception();}while (false);});\n" + + " zoo((x) -> {do { return ;}while (false);});\n" + + " zoo((x) -> {do { continue ;}while (true);});\n" + + " zoo((x) -> {do {\n" + + " if(x.length() > 0) {return ;} else {break;}\n" + + " }while (x.length() > 0);\n" + + " });\n" + + " zoo((x) -> {do {\n" + + " if(x.length() > 0) {return ;}\n" + + " }while (x.length() > 0);\n" + + " });\n" + + " zoo((x) -> {\n" + + " int i = 100;\n" + + " outer: do {\n" + + " inner: do {\n" + + " if(--i > 50) {\n" + + " break inner ;\n" + + " }\n" + + " if(i > 90) {\n" + + " break outer;\n" + + " }\n" + + " return ;\n" + + " }while(i > 0);\n" + + " }while(x.length() > 0);});\n" + + " }\n" + + "}\n" + }); +} +public void test028() { + this.runConformTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " final boolean FALSE = false; \n" + + " final boolean TRUE = true; \n" + + " goo((x) -> {\n" + + " for(;TRUE;){\n" + + " }});\n" + + " goo((x) -> {\n" + + " for(int i = 0;i < 100; i+= 10){\n" + + " switch(i) {\n" + + " case 90: {\n" + + " System.out.println();\n" + + " break;\n" + + " }\n" + + " case 80: {\n" + + " if(x > 10) return null;\n" + + " break;\n" + + " }\n" + + " default:\n" + + " return \"\";\n" + + " }\n" + + " }\n" + + " return \"\";\n" + + " });\n" + + " \n" + + " goo((x) -> {\n" + + " for(;TRUE;){\n" + + " if(x < 100) return \"\";\n" + + " else return null;\n" + + " }});\n" + + " goo((x) -> {\n" + + " for(;x > 0;){\n" + + " if(x < 100) return \"\";\n" + + " else return null;\n" + + " }\n" + + " return null;\n" + + " });\n" + + " }\n" + + "}\n" + }); +} +public void test029() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " final boolean FALSE = false; \n" + + " goo((x) -> {\n" + + " for(;FALSE;){\n" + + " }});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This lambda expression must return a result of type String\n" + + "----------\n"); +} +public void test030() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {\n" + + " for(;x > 0;){\n" + + " if(x < 100) return \"\";\n" + + " else return null;\n" + + " }});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " else return null;\n" + + " ^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +public void test031() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {\n" + + " for(int i = 0;i < 100; i+= 10){\n" + + " switch(i) {\n" + + " case 90: {\n" + + " System.out.println();\n" + + " break;\n" + + " }\n" + + " case 80: {\n" + + " if(x > 10) return null;\n" + + " break;\n" + + " }\n" + + " default:\n" + + " return \"\";\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test032() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test() {\n" + + " goo((x) -> {\n" + + " outer: for(int i = 0;i < 100; i+= 10){\n" + + " inner : for(int j = x; j > 0; j--) {\n" + + " switch(i) {\n" + + " case 90: {\n" + + " System.out.println();\n" + + " break inner;\n" + + " }\n" + + " case 80: {\n" + + " if(x > 10) return null;\n" + + " break outer;\n" + + " }\n" + + " default:\n" + + " return \"\";\n" + + " }\n" + + " }\n" + + " \n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " inner : for(int j = x; j > 0; j--) {\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n"); +} +public void test033() { + this.runConformTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " for(String str : strs){\n" + + " if(str.length() > 0) {\n" + + " return \"yes\";\n" + + " } else {\n" + + " return \"no\";\n" + + " }\n" + + " }\n" + + " return null;\n" + + " });\n" + + " goo((x) -> {\n" + + " for(String str : strs){\n" + + " return \"no\";\n" + + " }\n" + + " return \"\";\n" + + " });\n" + + " \n" + + " goo((x) -> {\n" + + " for(String str : strs){\n" + + " if(str.length() > 0) break;\n" + + " System.out.println();\n" + + " }\n" + + " return \"\";\n" + + " });\n" + + " }\n" + + "}\n" + }); +} +public void test034() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " for(String str : strs){\n" + + " if(str.length() > 0) {\n" + + " return \"yes\";\n" + + " } else {\n" + + " return \"no\";\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 11)\n" + + " } else {\n" + + " return \"no\";\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +public void test035() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " for(String str : strs){\n" + + " return \"no\";\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test036() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " for(String str : strs){\n" + + " switch(str.length()) {\n" + + " case 9: {\n" + + " System.out.println();\n" + + " return \"nine\";\n" + + " }\n" + + " case 1: {\n" + + " if(x > 10) return null;\n" + + " return \"one\";\n" + + " }\n" + + " default:\n" + + " return \"\";\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test037() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " outer: for(String str : strs){\n" + + " inner : for(int j = x; j > 0; j--) {\n" + + " switch(str.length()) {\n" + + " case 9: {\n" + + " System.out.println();\n" + + " break inner;\n" + + " }\n" + + " case 8: {\n" + + " if(x > 10) return null;\n" + + " break outer;\n" + + " }\n" + + " default:\n" + + " return \"\";\n" + + " }\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " inner : for(int j = x; j > 0; j--) {\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n"); +} +public void test038() { + this.runConformTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " switch(x) {\n" + + " case 0 : if(x > 10) return \">10\";\n" + + " case 1: return \"1\";\n" + + " default: return \"-1\";\n" + + " }\n" + + " });\n" + + " goo((x) -> {\n" + + " String str = \"\";\n" + + " switch(x) {\n" + + " case 0 : if(x > 10) break; else {str = \"0\"; break;}\n" + + " case 1: str = \"1\";break;\n" + + " default: break;\n" + + " }\n" + + " return str;\n" + + " });\n" + + " goo((x) -> {\n" + + " String str = \"\";\n" + + " switch(x){}\n" + + " return str;\n" + + " });\n" + + " }\n" + + "}\n" + }); +} +public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " switch(x) {\n" + + " case 0 : if(x > 10) return \">10\";\n" + + " case 1: return \"1\";\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test040() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " String str = \"\";\n" + + " switch(x) {\n" + + " case 0 : if(x > 10) break; else {str = \"0\"; break;}\n" + + " case 1: str = \"1\";break;\n" + + " default: break;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (( x) -> {})\n" + + "----------\n"); +} +public void test041() { + this.runConformTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " try {\n" + + " return \"\";\n" + + " } finally {\n" + + " \n" + + " }\n" + + " });\n" + + " goo((x) -> {\n" + + " try {\n" + + " throw new Exception();\n" + + " } finally {\n" + + " }\n" + + " });\n" + + " goo((x) -> {\n" + + " try {\n" + + " if(x > 0) \n" + + " throw new RuntimeException();\n" + + " } catch (NullPointerException e) {return null;} \n" + + " catch(ClassCastException c) {\n" + + " }\n" + + " finally {\n" + + " return \"\";\n" + + " }\n" + + " });\n" + + " \n" + + " }\n" + + "}\n" + }); +} +public void test042() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " try {\n" + + " if(x > 0) {\n" + + " return \"\";\n" + + " }\n" + + " } finally {}\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test043() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " try {\n" + + " return \"\";\n" + + " }catch (Exception e) {}\n" + + " finally {\n" + + " \n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test044() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " try {\n" + + " //if(x > 0) \n" + + " throw new RuntimeException();\n" + + " } catch (NullPointerException e) {return null;} \n" + + " catch(ClassCastException c) {\n" + + " }\n" + + " });\n" + + " goo((x) -> {\n" + + " try {\n" + + " if(x > 0) \n" + + " throw new RuntimeException();\n" + + " } catch (NullPointerException e) {return null;} \n" + + " catch(ClassCastException c) {\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test045() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " try {\n" + + " if(x > 0) \n" + + " throw new RuntimeException();\n" + + " } catch (NullPointerException e) {return null;} \n" + + " catch(ClassCastException c) {\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +public void test046() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " String foo(int x) throws Exception; \n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {}\n" + + " void test(String[] strs) {\n" + + " goo((x) -> {\n" + + " if (true) {\n" + + " try {\n" + + " if(x > 0)\n" + + " throw new Exception();\n" + + " } finally {\n" + + " return \"\";\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo((x) -> {\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " } finally {\n" + + " return \"\";\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "finally block does not complete normally\n" + + "----------\n"); +} +public void testSwitch() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " switch (args.length) {\n" + + " case 0:\n" + + " System.out.println(0);\n" + + " throw new RuntimeException();\n" + + " case 1:\n" + + " System.out.println(1);\n" + + " throw new RuntimeException();\n" + + " case 2:\n" + + " System.out.println(2);\n" + + " throw new RuntimeException();\n" + + " default: \n" + + " System.out.println(\"default\");\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testSwitch2() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " switch (args.length) {\n" + + " case 0:\n" + + " System.out.println(0);\n" + + " break;\n" + + " case 1:\n" + + " System.out.println(1);\n" + + " throw new RuntimeException();\n" + + " case 2:\n" + + " System.out.println(2);\n" + + " throw new RuntimeException();\n" + + " default: \n" + + " System.out.println(\"default\");\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testSwitch3() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " switch (args.length) {\n" + + " case 0:\n" + + " System.out.println(0);\n" + + " throw new RuntimeException();\n" + + " case 1:\n" + + " System.out.println(1);\n" + + " throw new RuntimeException();\n" + + " case 2:\n" + + " System.out.println(2);\n" + + " throw new RuntimeException();\n" + + " default: \n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testSwitch4() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " switch (args.length) {\n" + + " case 0:\n" + + " System.out.println(0);\n" + + " throw new RuntimeException();\n" + + " case 1:\n" + + " System.out.println(1);\n" + + " throw new RuntimeException();\n" + + " case 2:\n" + + " System.out.println(2);\n" + + " throw new RuntimeException();\n" + + " default: \n" + + " break;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testSwitch5() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {}\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " switch (args.length){\n" + + " case 1:\n" + + " if (args == null)\n" + + " break;\n" + + " else\n" + + " break;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testSwitch6() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {}\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " switch (args.length){\n" + + " case 1:\n" + + " if (args == null)\n" + + " break;\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testWhileThis() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " boolean t = true;\n" + + " while (t) {\n" + + " System.out.println();\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testWhile2() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " while (t) {\n" + + " System.out.println();\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testWhile3() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " while (t && !!t) {\n" + + " System.out.println();\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testWhile4() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " while (t && !!!t) {\n" + + " System.out.println();\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " boolean t = true;\n" + + " do {\n" + + " System.out.println();\n" + + " throw new RuntimeException();\n" + + " } while (t);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testDo2() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " do {\n" + + " System.out.println();\n" + + " throw new RuntimeException();\n" + + " } while (t);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testDo3() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " do { \n" + + " System.out.println();\n" + + " throw new RuntimeException();\n" + + " } while (t && !!t);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testDo4() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " do {\n" + + " System.out.println();\n" + + " } while (t && !!!t);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo5() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " break;\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo6() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " if (args == null) break;\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo7() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " if (args == null) throw new RuntimeException();\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo8() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " throw new RuntimeException();\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testDo9() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " continue;\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "J"); +} +public void testDo10() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " if (true) \n" + + " continue;\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo11() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " if (true) \n" + + " continue;\n" + + " else \n" + + " continue;\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo12() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " if (true) \n" + + " continue;\n" + + " else \n" + + " throw new RuntimeException();\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo13() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " if (true) \n" + + " throw new RuntimeException();\n" + + " else \n" + + " throw new RuntimeException();\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "I"); +} +public void testDo14() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " if (true) { \n" + + " System.out.println();\n" + + " continue;\n" + + " }\n" + + " else {\n" + + " continue;\n" + + " }\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo15() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " label:\n" + + " do {\n" + + " continue label;\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo16() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " blah:\n" + + " continue;\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo17() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " synchronized(args) {\n" + + " continue;\n" + + " }\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testDo18() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " try {\n" + + " continue;\n" + + " } finally {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "I"); +} +public void testDo19() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " try {\n" + + " continue;\n" + + " } finally {\n" + + " }\n" + + " } while (false); \n" + + " });\n" + + " }\n" + + "}\n" + }, + "J"); +} +public void testDo20() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " switch (args.length){\n" + + " default:\n" + + " continue;\n" + + " }\n" + + " } while (false); \n" + + " });\n" + + " }\n" + + "}\n" + }, + "J"); +} +public void testDo21() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " while (true) {\n" + + " continue;\n" + + " }\n" + + " } while (false); \n" + + " });\n" + + " }\n" + + "}\n" + }, + "I"); +} +public void testDo22() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " label:\n" + + " do {\n" + + " while (true) {\n" + + " continue label;\n" + + " }\n" + + " } while (false); \n" + + " });\n" + + " }\n" + + "}\n" + }, + "J"); +} +public void testDo23() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " label:\n" + + " while (true) {\n" + + " while (true) {\n" + + " continue label;\n" + + " }\n" + + " } \n" + + " });\n" + + " }\n" + + "}\n" + }, + "I"); +} +public void testDo24() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " label:\n" + + " do {\n" + + " for (;;) {\n" + + " continue label;\n" + + " }\n" + + " } while (false); \n" + + " });\n" + + " }\n" + + "}\n" + }, + "J"); +} +public void testDo25() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " label:\n" + + " do {\n" + + " do {\n" + + " continue label;\n" + + " } while (true);\n" + + " } while (false); \n" + + " });\n" + + " }\n" + + "}\n" + }, + "J"); +} +public void testDo26() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " do {\n" + + " label:\n" + + " while (true) {\n" + + " continue label;\n" + + " }\n" + + " } while (false);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "I"); +} +public void testForeach() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " for (String s: args) {\n" + + " System.out.println();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testForeach2() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " for (String s: args) {\n" + + " System.out.println();\n" + + " do {\n" + + " System.out.println();\n" + + " switch (args.length) {\n" + + " case 0:\n" + + " System.out.println(0);\n" + + " break;\n" + + " case 1:\n" + + " System.out.println(1);\n" + + " throw new RuntimeException();\n" + + " case 2:\n" + + " System.out.println(2);\n" + + " throw new RuntimeException();\n" + + " default: \n" + + " System.out.println(\"default\");\n" + + " throw new RuntimeException();\n" + + " }\n" + + " } while (t);\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testForeach3() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " for (String s: args) {\n" + + " System.out.println();\n" + + " do {\n" + + " System.out.println();\n" + + " switch (args.length) {\n" + + " case 0:\n" + + " System.out.println(0);\n" + + " throw new RuntimeException();\n" + + " case 1:\n" + + " System.out.println(1);\n" + + " throw new RuntimeException();\n" + + " case 2:\n" + + " System.out.println(2);\n" + + " throw new RuntimeException();\n" + + " default: \n" + + " System.out.println(\"default\");\n" + + " throw new RuntimeException();\n" + + " }\n" + + " } while (t);\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testForeach4() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " for (String s: args) {\n" + + " System.out.println();\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testIf() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " if (t) \n" + + " throw new RuntimeException();\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testIf2() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " if (true) \n" + + " throw new RuntimeException();\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testIf3() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " if (true) \n" + + " throw new RuntimeException();\n" + + " else \n" + + " throw new RuntimeException();\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testCFor() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " boolean t = true;\n" + + " for (; t ;) { \n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testCFor2() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " final boolean t = true;\n" + + " for (; t ;) { \n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testTry() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " try {\n" + + " } finally {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testTry2() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " try {\n" + + " } finally {\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testTry3() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " try {\n" + + " } catch (RuntimeException e) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testTry4() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " try {\n" + + " throw new RuntimeException();\n" + + " } catch (RuntimeException e) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testWhileTrue() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " while (true) {\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testWhileTrue2() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " while (true) {\n" + + " while (true) {\n" + + " if (args == null) break;\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "goo(I)"); +} +public void testWhileTrue3() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " while (true) {\n" + + " if (args == null) break;\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(() -> {\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void testLabeledStatement() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " label: \n" + + " while (true) {\n" + + " while (true) {\n" + + " break label;\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "J"); +} +public void testLabeledStatement2() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " outerlabel: \n" + + " label: \n" + + " while (true) {\n" + + " while (true) {\n" + + " break outerlabel;\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "J"); +} +public void testLabeledStatement3() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " outerlabel: \n" + + " label: \n" + + " while (true) {\n" + + " while (true) {\n" + + " break outerlabel;\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "J"); +} +public void testLabeledStatement4() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " outerlabel: \n" + + " label: \n" + + " while (true) {\n" + + " while (true) {\n" + + " break label;\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "J"); +} +public void testLabeledStatement5() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " static void goo(J i) {\n" + + " System.out.println(\"J\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(() -> {\n" + + " outerlabel: \n" + + " label: \n" + + " while (true) {\n" + + " while (true) {\n" + + " break;\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + }, + "I"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=470232 NPE at org.eclipse.jdt.internal.compiler.ast.WhileStatement.doesNotCompleteNormally +public void testBug470232_While() { + this.runConformTest( + new String[] { + "While.java", + "import java.util.function.Consumer;\n" + + "class While {\n" + + " void m() {\n" + + " t(Long.class, value -> {\n" + + " int x = 1;\n" + + " while (--x >= 0)\n" + + " ;\n" + + " });\n" + + " }\n" + + " void t(Class clazz, Consumer object) {\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=470232 NPE at org.eclipse.jdt.internal.compiler.ast.WhileStatement.doesNotCompleteNormally +public void testBug470232_Do() { + this.runConformTest( + new String[] { + "While.java", + "import java.util.function.Consumer;\n" + + "class While {\n" + + " void m() {\n" + + " t(Long.class, value -> {\n" + + " int x = 1;\n" + + " do {\n" + + " }while (--x >= 0);\n" + + " });\n" + + " }\n" + + " void t(Class clazz, Consumer object) {\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=470232 NPE at org.eclipse.jdt.internal.compiler.ast.WhileStatement.doesNotCompleteNormally +public void testBug470232_For() { + this.runConformTest( + new String[] { + "While.java", + "import java.util.function.Consumer;\n" + + "class While {\n" + + " void m() {\n" + + " t(Long.class, value -> {\n" + + " int x = 1;\n" + + " for(;--x >= 0;)\n" + + " ;\n" + + " });\n" + + " }\n" + + " void t(Class clazz, Consumer object) {\n" + + " }\n" + + "}\n" + }); +} +public static Class testClass() { + return LambdaShapeTests.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LineNumberAttributeTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LineNumberAttributeTest.java new file mode 100644 index 0000000000..07ae720954 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LineNumberAttributeTest.java @@ -0,0 +1,313 @@ +/******************************************************************************* + * Copyright (c) 2007, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; + +@SuppressWarnings({ "rawtypes" }) +public class LineNumberAttributeTest extends AbstractRegressionTest { + +public LineNumberAttributeTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=173800 +public void test001() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X next;\n" + + "\n" + + " X(X next) {\n" + + " this.next = next;\n" + + " }\n" + + "\n" + + " public static void main(String args[]) {\n" + + " try {\n" + + " X x = new X(new X(new X(null)));\n" + + " x.\n" + + " next.\n" + + " next.\n" + + " next.\n" + + " next.\n" + + " next.\n" + + " toString();\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #19 ([Ljava/lang/String;)V\n" + + " // Stack: 7, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new X [1]\n" + + " 3 dup\n" + + " 4 new X [1]\n" + + " 7 dup\n" + + " 8 new X [1]\n" + + " 11 dup\n" + + " 12 aconst_null\n" + + " 13 invokespecial X(X) [20]\n" + + " 16 invokespecial X(X) [20]\n" + + " 19 invokespecial X(X) [20]\n" + + " 22 astore_1 [x]\n" + + " 23 aload_1 [x]\n" + + " 24 getfield X.next : X [13]\n" + + " 27 getfield X.next : X [13]\n" + + " 30 getfield X.next : X [13]\n" + + " 33 getfield X.next : X [13]\n" + + " 36 getfield X.next : X [13]\n" + + " 39 invokevirtual java.lang.Object.toString() : java.lang.String [22]\n" + + " 42 pop\n" + + " 43 goto 55\n" + + " 46 astore_1 [e]\n" + + " 47 getstatic java.lang.System.out : java.io.PrintStream [26]\n" + + " 50 ldc [32]\n" + + " 52 invokevirtual java.io.PrintStream.println(java.lang.String) : void [34]\n" + + " 55 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 43] -> 46 when : java.lang.NullPointerException\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 23, line: 11]\n" + + " [pc: 24, line: 12]\n" + + " [pc: 27, line: 13]\n" + + " [pc: 30, line: 14]\n" + + " [pc: 33, line: 15]\n" + + " [pc: 36, line: 16]\n" + + " [pc: 39, line: 17]\n" + + " [pc: 43, line: 18]\n" + + " [pc: 47, line: 19]\n" + + " [pc: 55, line: 21]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 56] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 23, pc: 43] local: x index: 1 type: X\n" + + " [pc: 47, pc: 55] local: e index: 1 type: java.lang.NullPointerException\n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=173800 +public void test002() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X x;\n" + + "\n" + + " X next;\n" + + "\n" + + " X(X next) {\n" + + " this.next = next;\n" + + " }\n" + + "\n" + + " public static void main(String args[]) {\n" + + " X x = new X(new X(new X(null)));\n" + + " x.x = x;\n" + + " x.foo();\n" + + " }\n" + + "\n" + + " public void foo() {\n" + + " try {\n" + + " this.\n" + + " x.\n" + + " next.\n" + + " next.\n" + + " next.\n" + + " next.\n" + + " next.\n" + + " toString();\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #13 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " public void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield X.x : X [23]\n" + + " 4 getfield X.next : X [14]\n" + + " 7 getfield X.next : X [14]\n" + + " 10 getfield X.next : X [14]\n" + + " 13 getfield X.next : X [14]\n" + + " 16 getfield X.next : X [14]\n" + + " 19 invokevirtual java.lang.Object.toString() : java.lang.String [30]\n" + + " 22 pop\n" + + " 23 goto 35\n" + + " 26 astore_1 [e]\n" + + " 27 getstatic java.lang.System.out : java.io.PrintStream [34]\n" + + " 30 ldc [40]\n" + + " 32 invokevirtual java.io.PrintStream.println(java.lang.String) : void [42]\n" + + " 35 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 23] -> 26 when : java.lang.NullPointerException\n" + + " Line numbers:\n" + + " [pc: 0, line: 18]\n" + + " [pc: 1, line: 19]\n" + + " [pc: 4, line: 20]\n" + + " [pc: 7, line: 21]\n" + + " [pc: 10, line: 22]\n" + + " [pc: 13, line: 23]\n" + + " [pc: 16, line: 24]\n" + + " [pc: 19, line: 25]\n" + + " [pc: 23, line: 26]\n" + + " [pc: 27, line: 27]\n" + + " [pc: 35, line: 29]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 36] local: this index: 0 type: X\n" + + " [pc: 27, pc: 35] local: e index: 1 type: java.lang.NullPointerException\n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=509027 +public void testBug509027() throws Exception { + runConformTest( + new String[] { + "linenumber/Test.java", + "package linenumber;\n" + + "\n" + + "public class Test {\n" + + " int[] f = { 1, // linebreak\n" + + " 2 };\n" + + "}\n" + + "" + } + ); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator + "linenumber"+ File.separator +"Test.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #8 ()V\n" + + " // Stack: 5, Locals: 1\n" + + " public Test();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 iconst_2\n" + + " 6 newarray int [10]\n" + + " 8 dup\n" + + " 9 iconst_0\n" + + " 10 iconst_1\n" + + " 11 iastore\n" + + " 12 dup\n" + + " 13 iconst_1\n" + + " 14 iconst_2\n" + + " 15 iastore\n" + + " 16 putfield linenumber.Test.f : int[] [12]\n" + + " 19 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 14, line: 5]\n" + + " [pc: 19, line: 3]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 20] local: this index: 0 type: linenumber.Test\n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=520714 +public void testBug520714() throws Exception { + runConformTest( + new String[] { + "TestAnon.java", + "public class TestAnon {\n" + + " void f1() {\n" + + " new Object() {\n" + + " };\n" + + " }\n" + + "}" + } + ); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"TestAnon$1.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " Local variable table:\n" + + ""; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +public static Class testClass() { + return LineNumberAttributeTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalEnumTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalEnumTest.java new file mode 100644 index 0000000000..bca0b94c71 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalEnumTest.java @@ -0,0 +1,7844 @@ +/******************************************************************************* + * Copyright (c) 2020, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * Bug 365519 - editorial cleanup after bug 186342 and bug 365387 + * Bug 265744 - Enum switch should warn about missing default + * Bug 374605 - Unreasonable warning for enum-based switch statements + * bug 388739 - [1.8][compiler] consider default methods when detecting whether a class needs to be declared abstract + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +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; +import org.eclipse.jdt.core.util.ClassFormatException; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class LocalEnumTest extends AbstractComparableTest { + + String reportMissingJavadocComments = null; + + public LocalEnumTest(String name) { + super(name); + } + + // 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[] { "test004" }; +// TESTS_NUMBERS = new int[] { 185 }; +// TESTS_RANGE = new int[] { 21, 50 }; + } + public static Test suite() { +// return buildComparableTestSuite(testClass()); + return buildMinimalComplianceTestSuite(testClass(), F_16); + } + + public static Class testClass() { + return LocalEnumTest.class; + } + + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16); // FIXME + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTags, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, CompilerOptions.PRIVATE); + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + if (this.reportMissingJavadocComments != null) + options.put(CompilerOptions.OPTION_ReportMissingJavadocComments, this.reportMissingJavadocComments); + return options; + } + /* (non-Javadoc) + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.reportMissingJavadocComments = null; + } + + @Override + protected void runConformTest(String[] testFiles) { + runConformTest(testFiles, "", getCompilerOptions()); + } + @Override + protected void runConformTest(String[] testFiles, String expectedOutput) { + runConformTest(testFiles, expectedOutput, getCompilerOptions()); + } +// @Override +// protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { +// Runner runner = new Runner(); +// runner.testFiles = testFiles; +// runner.expectedOutputString = expectedOutput; +// runner.vmArguments = new String[] {"--enable-preview"}; +// runner.customOptions = customOptions; +// runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("16"); +// runner.runConformTest(); +// } +// +// @Override +// protected void runConformTest( +// // test directory preparation +// boolean shouldFlushOutputDirectory, +// String[] testFiles, +// //compiler options +// String[] classLibraries /* class libraries */, +// Map customOptions /* custom options */, +// // compiler results +// String expectedCompilerLog, +// // runtime results +// String expectedOutputString, +// String expectedErrorString, +// // javac options +// JavacTestOptions javacTestOptions) { +// Runner runner = new Runner(); +// runner.testFiles = testFiles; +// runner.expectedOutputString = expectedOutputString; +// runner.expectedCompilerLog = expectedCompilerLog; +// runner.expectedErrorString = expectedErrorString; +// runner.vmArguments = new String[] {"--enable-preview"}; +// runner.customOptions = customOptions; +// runner.javacTestOptions = javacTestOptions == null ? JavacTestOptions.forReleaseWithPreview("16") : javacTestOptions; +// runner.runConformTest(); +// } +// +// @Override +// protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) { +// runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("16")); +// } +// protected void runWarningTest(String[] testFiles, String expectedCompilerLog) { +// runWarningTest(testFiles, expectedCompilerLog, null); +// } +// protected void runWarningTest(String[] testFiles, String expectedCompilerLog, Map customOptions) { +// runWarningTest(testFiles, expectedCompilerLog, customOptions, null); +// } +// protected void runWarningTest(String[] testFiles, String expectedCompilerLog, +// Map customOptions, String javacAdditionalTestOptions) { +// +// Runner runner = new Runner(); +// runner.testFiles = testFiles; +// runner.expectedCompilerLog = expectedCompilerLog; +// runner.customOptions = customOptions; +// runner.vmArguments = new String[] {"--enable-preview"}; +// runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forReleaseWithPreview("15") : +// JavacTestOptions.forReleaseWithPreview("16", javacAdditionalTestOptions); +// runner.runWarningTest(); +// } + + private void verifyClassFile(String expectedOutput, String classFileName, int mode, boolean positive) throws IOException, ClassFormatException { + String result = getClassFileContents(classFileName, mode); + verifyOutput(result, expectedOutput, positive); + } + private String getClassFileContents( String classFileName, int mode) throws IOException, + ClassFormatException { + File f = new File(OUTPUT_DIR + File.separator + classFileName); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", mode); + return result; + } + private void verifyOutput(String result, String expectedOutput, boolean positive) { + int index = result.indexOf(expectedOutput); + if (positive) { + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + System.out.println("..."); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } else { + if (index != -1) { + assertEquals("Unexpected contents", "", result); + } + } + } + +// test simple valid enum and its usage +public void test000() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " enum Role { M, D }\n"+ + " enum T {\n"+ + " PHILIPPE(37) {\n"+ + " public boolean isManager() {\n"+ + " return true;\n"+ + " }\n"+ + " },\n"+ + " DAVID(27),\n"+ + " JEROME(33),\n"+ + " OLIVIER(35),\n"+ + " KENT(40),\n"+ + " YODA(41),\n"+ + " FREDERIC;\n"+ + " final static int OLD = 41;\n"+ + "\n"+ + "\n"+ + " int age;\n"+ + " Role role;\n"+ + "\n"+ + " T() { this(OLD); }\n"+ + " T(int age) {\n"+ + " this.age = age;\n"+ + " }\n"+ + " public int age() { return this.age; }\n"+ + " public boolean isManager() { return false; }\n"+ + " void setRole(boolean mgr) {\n"+ + " this.role = mgr ? Role.M : Role.D;\n"+ + " }\n"+ + "}\n"+ + " System.out.print(\"JDTCore team:\");\n"+ + " T oldest = null;\n"+ + " int maxAge = Integer.MIN_VALUE;\n"+ + " for (T t : T.values()) {\n"+ + " if (t == T.YODA) continue;// skip YODA\n"+ + " t.setRole(t.isManager());\n"+ + " if (t.age() > maxAge) {\n"+ + " oldest = t;\n"+ + " maxAge = t.age();\n"+ + " }\n"+ + " Location l = switch(t) {\n"+ + " case PHILIPPE, DAVID, JEROME, FREDERIC-> Location.SNZ;\n"+ + " case OLIVIER, KENT -> Location.OTT;\n"+ + " default-> throw new AssertionError(\"Unknown team member: \" + t);\n"+ + " };\n"+ + "\n"+ + " System.out.print(\" \"+ t + ':'+t.age()+':'+l+':'+t.role);\n"+ + " }\n"+ + " System.out.println(\" WINNER is:\" + T.valueOf(oldest.name()));\n"+ + " }\n"+ + "\n"+ + " private enum Location { SNZ, OTT }\n"+ + "}" + }, + "JDTCore team: PHILIPPE:37:SNZ:M DAVID:27:SNZ:D JEROME:33:SNZ:D OLIVIER:35:OTT:D KENT:40:OTT:D FREDERIC:41:SNZ:D WINNER is:FREDERIC" + ); +} +// check assignment to enum constant is disallowed +public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " BLEU, \n" + + " BLANC, \n" + + " ROUGE;\n" + + " static {\n" + + " BLEU = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " BLEU = null;\n" + + " ^^^^\n" + + "The final field Y.BLEU cannot be assigned\n" + + "----------\n"); +} +// check diagnosis for duplicate enum constants +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU, \n" + + " BLANC, \n" + + " ROUGE,\n" + + " BLEU;\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " BLEU, \n" + + " ^^^^\n" + + "Duplicate field Y.BLEU\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " BLEU;\n" + + " ^^^^\n" + + "Duplicate field Y.BLEU\n" + + "----------\n"); +} +// check properly rejecting enum constant modifiers +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " public BLEU, \n" + + " transient BLANC, \n" + + " ROUGE, \n" + + " abstract RED {\n" + + " void _test() {}\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public BLEU, \n" + + " ^^^^\n" + + "Illegal modifier for the enum constant BLEU; no modifier is allowed\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " transient BLANC, \n" + + " ^^^^^\n" + + "Illegal modifier for the enum constant BLANC; no modifier is allowed\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " abstract RED {\n" + + " ^^^\n" + + "Illegal modifier for the enum constant RED; no modifier is allowed\n" + + "----------\n"); +} +// check using an enum constant +public void test004() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " public static void main(String[] a) {\n" + + " System.out.println(BLEU);\n" + + " }\n" + + " \n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}\n" + }, + "BLEU"); +} +// check method override diagnosis (with no enum constants) +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " ;\n" + + " protected Object clone() { return this; }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " protected Object clone() { return this; }\n" + + " ^^^^^^^\n" + + "Cannot override the final method from Enum\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " protected Object clone() { return this; }\n" + + " ^^^^^^^\n" + + "The method clone() of type Y should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); +} +// check generated #values() method +public void test006() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " public static void main(String[] args) {\n" + + " for(Y y: Y.values()) {\n" + + " System.out.print(y);\n" + + " }\n" + + " }\n" + + " \n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}\n" + }, + "BLEUBLANCROUGE"); +} +// tolerate user definition for $VALUES +public void test007() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " int $VALUES;\n" + + " public static void main(String[] args) {\n" + + " for(Y y: Y.values()) {\n" + + " System.out.print(y);\n" + + " }\n" + + " }\n" + + " \n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}\n" + }, + "BLEUBLANCROUGE"); +} +// reject user definition for #values() +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " void dup() {} \n" + + " void values() {} \n" + + " void dup() {} \n" + + " void values() {} \n" + + " Missing dup() {} \n" + + " public static void main(String[] args) {\n" + + " for(Y y: Y.values()) {\n" + + " System.out.print(y);\n" + + " }\n" + + " }\n" + + " \n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " void dup() {} \n" + + " ^^^^^\n" + + "Duplicate method dup() in type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " void values() {} \n" + + " ^^^^^^^^\n" + + "The enum Y already defines the method values() implicitly\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " void dup() {} \n" + + " ^^^^^\n" + + "Duplicate method dup() in type Y\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " void values() {} \n" + + " ^^^^^^^^\n" + + "The enum Y already defines the method values() implicitly\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " Missing dup() {} \n" + + " ^^^^^^^\n" + + "Missing cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " Missing dup() {} \n" + + " ^^^^^\n" + + "Duplicate method dup() in type Y\n" + + "----------\n" + + "7. WARNING in X.java (at line 14)\n" + + " public static void main(String[] args) {\n" + + " ^^^^\n" + + "The parameter args is hiding another local variable defined in an enclosing scope\n" + + "----------\n"); +} +// switch on enum +public void test009() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " //void values() {}\n" + + " \n" + + " public static void main(String[] args) {\n" + + " Y y = BLEU;\n" + + " switch(y) {\n" + + " case BLEU :\n" + + " System.out.println(\"SUCCESS\");\n" + + " break;\n" + + " case BLANC :\n" + + " case ROUGE :\n" + + " System.out.println(\"FAILED\");\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + " \n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +// duplicate switch case +public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " //void values() {}\n" + + " \n" + + " public static void main(String[] args) {\n" + + " Y y = BLEU;\n" + + " switch(y) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLEU :\n" + + " case BLANC :\n" + + " case ROUGE :\n" + + " System.out.println(\"FAILED\");\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + " \n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " public static void main(String[] args) {\n" + + " ^^^^\n" + + "The parameter args is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " case BLEU :\n" + + " ^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " case BLEU :\n" + + " ^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n"); +} +// reject user definition for #values() +public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " \n" + + " void values() {} \n" + + " void values() {} \n" + + " public static void main(String[] args) {\n" + + " for(Y y: Y.values()) {\n" + + " System.out.print(y);\n" + + " }\n" + + " }\n" + + " \n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " void values() {} \n" + + " ^^^^^^^^\n" + + "The enum Y already defines the method values() implicitly\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " void values() {} \n" + + " ^^^^^^^^\n" + + "The enum Y already defines the method values() implicitly\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " public static void main(String[] args) {\n" + + " ^^^^\n" + + "The parameter args is hiding another local variable defined in an enclosing scope\n" + + "----------\n"); +} +// check abstract method diagnosis +public void testNPE012() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y implements Runnable { \n" + + " \n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " enum Y implements Runnable { \n" + + " ^\n" + + "The type Y must implement the inherited abstract method Runnable.run()\n" + + "----------\n"); +} +// check enum constants with wrong arguments +public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU(10),\n" + + " BLANC(20),\n" + + " ROUGE(30);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " BLEU(10),\n" + + " ^^^^\n" + + "The constructor Y(int) is undefined\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " BLANC(20),\n" + + " ^^^^^\n" + + "The constructor Y(int) is undefined\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " ROUGE(30);\n" + + " ^^^^^\n" + + "The constructor Y(int) is undefined\n" + + "----------\n"); +} +// check enum constants with extra arguments +public void test014() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU(10),\n" + + " BLANC(20),\n" + + " ROUGE(30);\n" + + "\n" + + " int val;\n" + + " Y(int val) {\n" + + " this.val = val;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " for(Y y: values()) {\n" + + " System.out.print(y.val);\n" + + " }\n" + + " }\n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}\n" + }, + "102030"); +} +// check enum constants with wrong arguments +public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU(10),\n" + + " BLANC(),\n" + + " ROUGE(30);\n" + + "\n" + + " int val;\n" + + " Y(int val) {\n" + + " this.val = val;\n" + + " }\n" + + "\n" + + " public static void main(String[] a) {\n" + + " for(Y y: values()) {\n" + + " System.out.print(y.val);\n" + + " }\n" + + " }\n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " BLANC(),\n" + + " ^^^^^\n" + + "The constructor Y() is undefined\n" + + "----------\n"); +} +// check enum constants with wrong arguments +public void test016() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU(10) {\n" + + " String foo() { // inner\n" + + " return super.foo() + this.val;\n" + + " }\n" + + " },\n" + + " BLANC(20),\n" + + " ROUGE(30);\n" + + "\n" + + " int val;\n" + + " Y(int val) {\n" + + " this.val = val;\n" + + " }\n" + + " String foo() { // outer\n" + + " return this.name();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " for(Y y: values()) {\n" + + " System.out.print(y.foo());\n" + + " }\n" + + " }\n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}\n" + }, + "BLEU10BLANCROUGE"); +} +// check enum constants with empty arguments +public void test017() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " \n" + + " BLEU()\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +// cannot extend enums +public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y { \n" + + " BLEU()\n" + + " }\n" + + " \n" + + " class XX extends Y implements Y {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " class XX extends Y implements Y {\n" + + " ^\n" + + "The type Y cannot be the superclass of XX; a superclass must be a class\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " class XX extends Y implements Y {\n" + + " ^\n" + + "The type Y cannot be a superinterface of XX; a superinterface must be an interface\n" + + "----------\n"); +} +// 74851 +public void test019() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum MonthEnum {\n" + + " JANUARY (30),\n" + + " FEBRUARY (28),\n" + + " MARCH (31),\n" + + " APRIL (30),\n" + + " MAY (31),\n" + + " JUNE (30),\n" + + " JULY (31),\n" + + " AUGUST (31),\n" + + " SEPTEMBER (31),\n" + + " OCTOBER (31),\n" + + " NOVEMBER (30),\n" + + " DECEMBER (31);\n" + + " \n" + + " private final int days;\n" + + " \n" + + " MonthEnum(int days) {\n" + + " this.days = days;\n" + + " }\n" + + " \n" + + " public int getDays() {\n" + + " boolean leapYear = true;\n" + + " switch(this) {\n" + + " case FEBRUARY: if(leapYear) return days+1;\n" + + " default: return days;\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.println(JANUARY.getDays());\n" + + " }\n" + + " \n" + + " }\n" + + " MonthEnum.main(args);\n" + + " }\n" + + "}\n", + }, + "30"); +} +// 74226 +public void test020() { + this.runConformTest( + new String[] { + "Foo.java", + "public class Foo{\n" + + " public static void main(String[] args) {\n" + + " enum Rank {FIRST,SECOND,THIRD}\n" + + " }\n" + + "}\n", + }, + ""); +} +// 74226 variation - check nested enum is implicitly static +public void test021() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public class Foo {\n" + + " public static void main(String[] args) {\n" + + " enum Rank {FIRST,SECOND,THIRD;\n" + + " void bar() { foo(); } \n" + + " }\n" + + " }\n" + + " void foo() {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Foo.java (at line 4)\n" + + " void bar() { foo(); } \n" + + " ^^^\n" + + "Cannot make a static reference to the non-static method foo() from the type Foo\n" + + "----------\n"); +} +// 77151 - cannot use qualified name to denote enum constants in switch case label +public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " \n" + + " void foo() {\n" + + " enum MX { BLEU, BLANC, ROUGE }\n" + + " MX e = MX.BLEU; \n" + + " switch(e) {\n" + + " case MX.BLEU : break;\n" + + " case MX.BLANC : break;\n" + + " case MX.ROUGE : break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " case MX.BLEU : break;\n" + + " ^^^^^^^\n" + + "The qualified case label MX.BLEU must be replaced with the unqualified enum constant BLEU\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " case MX.BLANC : break;\n" + + " ^^^^^^^^\n" + + "The qualified case label MX.BLANC must be replaced with the unqualified enum constant BLANC\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " case MX.ROUGE : break;\n" + + " ^^^^^^^^\n" + + "The qualified case label MX.ROUGE must be replaced with the unqualified enum constant ROUGE\n" + + "----------\n"); +} + +// 77212 +public void test023() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum RuleType{ SUCCESS, FAILURE }\n" + + " System.out.print(RuleType.valueOf(RuleType.SUCCESS.name()));\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} + +// 77244 - cannot declare final enum +public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final enum Y {\n" + + " FOO() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " final enum Y {\n" + + " ^\n" + + "Illegal modifier for local enum Y; no explicit modifier is permitted\n" + + "----------\n"); +} + +// values is using arraycopy instead of clone +public void test025() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " SUC, CESS;\n" + + " public static void main(String[] args) {\n" + + " for (Y y : values()) {\n" + + " System.out.print(y.name());\n" + + " }\n" + + " }\n" + + " }\n" + + " Y.main(args);\n" + + "}\n" + + "}", + }, + "SUCCESS"); +} + +// check enum name visibility +public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Couleur { BLEU, BLANC, ROUGE }\n" + + " }\n" + + " class Y {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " void foo(Couleur c) {\n" + + " ^^^^^^^\n" + + "Couleur cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " case BLEU :\n" + + " ^^^^\n" + + "BLEU cannot be resolved to a variable\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " case BLANC :\n" + + " ^^^^^\n" + + "BLANC cannot be resolved to a variable\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " case ROUGE :\n" + + " ^^^^^\n" + + "ROUGE cannot be resolved to a variable\n" + + "----------\n"); +} +// check enum name visibility +public void test027() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Couleur { BLEU, BLANC, ROUGE }\n" + + " class Y {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " } \n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +// check enum name visibility +public void test028() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Couleur { \n" + + " BLEU, BLANC, ROUGE;\n" + + " static int C = 0;\n" + + " static void FOO() {}\n" + + " }\n" + + " class Y {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " FOO();\n" + + " C++;\n" + + " } \n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " FOO();\n" + + " ^^^\n" + + "The method FOO() is undefined for the type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " C++;\n" + + " ^\n" + + "C cannot be resolved to a variable\n" + + "----------\n"); +} +// check enum name visibility +public void test029() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Couleur { \n" + + " BLEU, BLANC, ROUGE; // take precedence over toplevel BLEU type\n" + + " }\n" + + " class Y {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " } \n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class BLEU {}\n", + }, + ""); +} +// check enum name visibility +public void test030() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Couleur { \n" + + " BLEU, BLANC, ROUGE; // take precedence over sibling constant from Color\n" + + " }\n" + + " enum Color { \n" + + " BLEU, BLANC, ROUGE;\n" + + " }\n" + + " class Y {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " } \n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class BLEU {}\n", + }, + ""); +} +// check enum name visibility +public void test031() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Couleur { \n" + + " BLEU, BLANC, ROUGE; // take precedence over toplevel BLEU type\n" + + " }\n" + + " class Y implements IX, JX {\n" + + " void foo(Couleur c) {\n" + + " switch (c) {\n" + + " case BLEU :\n" + + " break;\n" + + " case BLANC :\n" + + " break;\n" + + " case ROUGE :\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " } \n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "interface IX {\n" + + " int BLEU = 1;\n" + + "}\n" + + "interface JX {\n" + + " int BLEU = 2;\n" + + "}\n" + + "class BLEU {}\n" + + "\n", + }, + ""); +} + +// check Enum cannot be used as supertype (explicitly) +public void test032() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " class Y extends Enum {\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class Y extends Enum {\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " class Y extends Enum {\n" + + " ^^^^\n" + + "The type Y may not subclass Enum explicitly\n" + + "----------\n"); +} + +// Javadoc in enum (see bug 78018) +public void test033() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " /**\n" + + " * Valid javadoc\n" + + " * @author ffr\n" + + " */\n" + + " enum E {\n" + + " /** Valid javadoc */\n" + + " TEST,\n" + + " /** Valid javadoc */\n" + + " VALID;\n" + + " /** Valid javadoc */\n" + + " public void foo() {}\n" + + " }\n" + + " }\n" + + "}\n" + } + ); +} +public void test034() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " /**\n" + + " * Invalid javadoc\n" + + " * @exception NullPointerException Invalid tag\n" + + " * @throws NullPointerException Invalid tag\n" + + " * @return Invalid tag\n" + + " * @param x Invalid tag\n" + + " */\n" + + " enum E { TEST, VALID }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @exception NullPointerException Invalid tag\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @throws NullPointerException Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @return Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @param x Invalid tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void test035() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " /**\n" + + " * @see \"Valid normal string\"\n" + + " * @see Valid URL link reference\n" + + " * @see Object\n" + + " * @see #TEST\n" + + " * @see E\n" + + " * @see E#TEST\n" + + " */\n" + + " enum E { TEST, VALID }\n" + + " }\n" + + "}" + } + ); +} +public void test036() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " /**\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " * @see invalid no text allowed after the href\n" + + " * @see\n" + + " * @see #VALIDE\n" + + " */\n" + + " enum E { TEST, VALID }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " * @see \"invalid\" no text allowed after the string\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " * @see invalid no text allowed after the href\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Unexpected text\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " * @see\n" + + " ^^^\n" + + "Javadoc: Missing reference\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " * @see #VALIDE\n" + + " ^^^^^^\n" + + "Javadoc: VALIDE cannot be resolved or is not a field\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void test037() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " /**\n" + + " * Value test: {@value #TEST}\n" + + " * or: {@value E#TEST}\n" + + " */\n" + + " enum E { TEST, VALID }\n" + + " }\n" + + "}" + } + ); +} +public void test038() { + this.reportMissingJavadocComments = CompilerOptions.ERROR; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum E { TEST, VALID;\n" + + " public void foo() {}\n" + + " }\n" + + "}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public static void main(String[] args) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: Missing comment for public declaration\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum E {\n" + + " /**\n" + + " * @exception NullPointerException Invalid tag\n" + + " * @throws NullPointerException Invalid tag\n" + + " * @return Invalid tag\n" + + " * @param x Invalid tag\n" + + " */\n" + + " TEST,\n" + + " VALID;\n" + + " }\n" + + "}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @exception NullPointerException Invalid tag\n" + + " ^^^^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @throws NullPointerException Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " * @return Invalid tag\n" + + " ^^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " * @param x Invalid tag\n" + + " ^^^^^\n" + + "Javadoc: Unexpected tag\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void test040() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum E {\n" + + " /**\n" + + " * @see E\n" + + " * @see #VALID\n" + + " */\n" + + " TEST,\n" + + " /**\n" + + " * @see E#TEST\n" + + " * @see E\n" + + " */\n" + + " VALID;\n" + + " /**\n" + + " * @param x the object\n" + + " * @return String\n" + + " * @see Object\n" + + " */\n" + + " public String val(Object x) { return x.toString(); }\n" + + " }\n" + + "}\n" + + "}\n" + } + ); +} +public void test041() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum E {\n" + + " /**\n" + + " * @see e\n" + + " * @see #VALIDE\n" + + " */\n" + + " TEST,\n" + + " /**\n" + + " * @see E#test\n" + + " * @see EUX\n" + + " */\n" + + " VALID;\n" + + " /**\n" + + " * @param obj the object\n" + + " * @return\n" + + " * @see Objet\n" + + " */\n" + + " public String val(Object x) { return x.toString(); }\n" + + " }\n" + + "}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " * @see e\n" + + " ^\n" + + "Javadoc: e cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " * @see #VALIDE\n" + + " ^^^^^^\n" + + "Javadoc: VALIDE cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " * @see E#test\n" + + " ^^^^\n" + + "Javadoc: test cannot be resolved or is not a field\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " * @see EUX\n" + + " ^^^\n" + + "Javadoc: EUX cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 15)\n" + + " * @param obj the object\n" + + " ^^^\n" + + "Javadoc: Parameter obj is not declared\n" + + "----------\n" + + "6. ERROR in X.java (at line 16)\n" + + " * @return\n" + + " ^^^^^^\n" + + "Javadoc: Description expected after @return\n" + + "----------\n" + + "7. ERROR in X.java (at line 17)\n" + + " * @see Objet\n" + + " ^^^^^\n" + + "Javadoc: Objet cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +public void test042() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum E {\n" + + " /**\n" + + " * Test value: {@value #TEST}\n" + + " */\n" + + " TEST,\n" + + " /**\n" + + " * Valid value: {@value E#VALID}\n" + + " */\n" + + " VALID;\n" + + " /**\n" + + " * Test value: {@value #TEST}\n" + + " * Valid value: {@value E#VALID}\n" + + " * @param x the object\n" + + " * @return String\n" + + " */\n" + + " public String val(Object x) { return x.toString(); }\n" + + " }\n" + + "}\n" + + "}\n" + } + ); +} + +// External javadoc references to enum +public void _NAtest043() { + this.runConformTest( + new String[] { + "test/E.java", + "package test;\n" + + "public enum E { TEST, VALID }\n", + "test/X.java", + "import static test.E.TEST;\n" + + " /**\n" + + " * @see test.E\n" + + " * @see test.E#VALID\n" + + " * @see #TEST\n" + + " */\n" + + "public class X {}\n" + } + ); +} +public void _NAtest044() { + this.runConformTest( + new String[] { + "test/E.java", + "package test;\n" + + "public enum E { TEST, VALID }\n", + "test/X.java", + "import static test.E.TEST;\n" + + " /**\n" + + " * Valid value = {@value test.E#VALID}\n" + + " * Test value = {@value #TEST}\n" + + " */\n" + + "public class X {}\n" + } + ); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78321 + */ +public void test045() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " FIRST,\n" + + " SECOND,\n" + + " THIRD;\n" + + "\n" + + " static {\n" + + " for (Y t : values()) {\n" + + " System.out.print(t.name());\n" + + " }\n" + + " }\n" + + "\n" + + " Y() {}\n" + + " static void foo(){}\n" + + "\n" + + " }\n" + + " Y.foo();\n" + // trigger the static block with a static method invocation + " }\n" + + "}" + }, + "FIRSTSECONDTHIRD" + ); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78464 + */ +public void test046() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y{\n" + + " a(1);\n" + + " Y(int i) {\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78914 + */ +public void test047() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y{ \n" + + " ;\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " super();\n" + + " ^^^^^^^^\n" + + "Cannot invoke super constructor from enum constructor Y()\n" + + "----------\n" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77211 + */ +public void test048() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum StopLight {\n" + + " RED{\n" + + " public StopLight next(){ return GREEN; }\n" + + " },\n" + + " GREEN{\n" + + " public StopLight next(){ return YELLOW; }\n" + + " },\n" + + " YELLOW{\n" + + " public StopLight next(){ return RED; }\n" + + " };\n" + + "\n" + + " public abstract StopLight next();\n" + + " }\n" + + " }\n" + + "}" + }, + "" + ); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78915 + */ +public void test049() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " public abstract enum Y {}\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public abstract enum Y {}\n" + + " ^\n" + + "Illegal modifier for local enum Y; no explicit modifier is permitted\n" + + "----------\n" + ); +} + +public void test050() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {}\n" + + " }\n" + + "}" + }, + "" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78914 - variation + */ +public void test051() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " BLEU (0) {\n" + + " }\n" + + " ;\n" + + " Y() {\n" + + " this(0);\n" + + " }\n" + + " Y(int i) {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78916 + */ +public void test052() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " A\n" + + " ;\n" + + " \n" + + " public abstract void foo();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A\n" + + " ^\n" + + "The enum constant A must implement the abstract method foo()\n" + + "----------\n" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78916 - variation + */ +public void test053() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " A () { public void foo() {} }\n" + + " ;\n" + + " \n" + + " public abstract void foo();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78916 - variation + */ +public void test054() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " A() {}\n" + + " ;\n" + + " \n" + + " public abstract void foo();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A() {}\n" + + " ^\n" + + "The enum constant A must implement the abstract method foo()\n" + + "----------\n" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78916 - variation + */ +public void test055() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " ;\n" + + " \n" + + " public abstract void foo();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public abstract void foo();\n" + + " ^^^^^\n" + + "The enum Y can only define the abstract method foo() if it also defines enum constants with corresponding implementations\n" + + "----------\n" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78914 - variation + */ +public void test056() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " PLUS {\n" + + " double eval(double x, double y) { return x + y; }\n" + + " };\n" + + "\n" + + " // Perform the arithmetic X represented by this constant\n" + + " abstract double eval(double x, double y);\n" + + " }\n" + + " }\n" + + "}" + }, + "" + ); + String expectedOutput = + "// Signature: Ljava/lang/Enum;\n" + + "abstract static enum X$1Y {\n" ; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X$1Y.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77430 + */ +public void test057() { + this.runConformTest( + new String[] { + "Enum2.java", + "public class Enum2 {\n" + + " public static void main(String[] args) {\n" + + " enum Color { RED, GREEN };\n" + + " Color c= Color.GREEN;\n" + + " switch (c) {\n" + + " case RED:\n" + + " System.out.println(Color.RED);\n" + + " break;\n" + + " case GREEN:\n" + + " System.out.println(c);\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + "}\n" + }, + "GREEN" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77430 - variation + */ +public void test058() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {\n" + + " public static void main(String[] args) {\n" + + " enum X { a }\n" + + " class B {\n" + + " void _test(X x, int a) {\n" + + " if (x == a) a++; // incomparable types: X and int\n" + + " switch(x) {\n" + + " case a : System.out.println(a); // prints \'9\'\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + " void _test2(X x, final int aa) {\n" + + " switch(x) {\n" + + " case aa : // unqualified enum constant error\n" + + " System.out.println(a); // cannot find a\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + " }\n" + + " new B()._test(X.a, 9);\n" + + " new B()._test2(X.a, 3);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (x == a) a++; // incomparable types: X and int\n" + + " ^^^^^^\n" + + "Incompatible operand types X and int\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " case aa : // unqualified enum constant error\n" + + " ^^\n" + + "aa cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " System.out.println(a); // cannot find a\n" + + " ^\n" + + "a cannot be resolved to a variable\n" + + "----------\n" + ); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=81262 + */ +public void test059() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " MONDAY {\n" + + " public void foo() {\n" + + " }\n" + + " };\n" + + " private Y() {}\n" + + " public static void main(String[] ags) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=81589 + */ +public void _NAtest060() { + this.runNegativeTest( + new String[] { + "com/flarion/test/a/MyEnum.java", + "package com.flarion.test.a;\n" + + "public enum MyEnum {\n" + + "\n" + + " First, Second;\n" + + " \n" + + "}\n", + "com/flarion/test/b/MyClass.java", + "package com.flarion.test.b;\n" + + "import com.flarion.test.a.MyEnum;\n" + + "import static com.flarion.test.a.MyEnum.First;\n" + + "import static com.flarion.test.a.MyEnum.Second;\n" + + "public class MyClass {\n" + + "\n" + + " public void myMethod() {\n" + + " MyEnum e = MyEnum.First;\n" + + " switch (e) {\n" + + " case First:\n" + + " break;\n" + + " case Second:\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " throw new Exception();\n" + // fake error to cause dump of unused import warnings + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in com\\flarion\\test\\b\\MyClass.java (at line 3)\n" + + " import static com.flarion.test.a.MyEnum.First;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import com.flarion.test.a.MyEnum.First is never used\n" + + "----------\n" + + "2. WARNING in com\\flarion\\test\\b\\MyClass.java (at line 4)\n" + + " import static com.flarion.test.a.MyEnum.Second;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import com.flarion.test.a.MyEnum.Second is never used\n" + + "----------\n" + + "3. ERROR in com\\flarion\\test\\b\\MyClass.java (at line 16)\n" + + " throw new Exception();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82217 + */ +public void test061() { + this.runNegativeTest( + new String[] { + "X.java", + "\n" + + "class A {\n" + + " public void foo() {\n" + + " enum X {\n" + + " A, B, C;\n" + + " public static final X D = null;\n" + + " }\n" + + " X x = X.A;\n" + + " switch (x) {\n" + + " case D:\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant A needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant B needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant C needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " case D:\n" + + " ^\n" + + "The field X.D cannot be referenced from an enum case label; only enum constants can be used in enum switch\n" + + "----------\n"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82217 - variation with qualified name + */ +public void test062() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE, JavaCore.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "\n" + + "class A {\n" + + " private void foo() {\n" + + " enum X {\n" + + " A, B, C;\n" + + " public static final X D = null;\n" + + " }\n" + + " X x = X.A;\n" + + " switch (x) {\n" + + " case X.D:\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " switch (x) {\n" + + " ^\n" + + "The switch over the enum type X should have a default case\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant A needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant B needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant C needs a corresponding case label in this enum switch on X\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " case X.D:\n" + + " ^\n" + + "The field X.D cannot be referenced from an enum case label; only enum constants can be used in enum switch\n" + + + "----------\n", + null, // classlibs + true, // flush + options); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=81945 + */ +public void test063() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Option { ALPHA, BRAVO };\n" + + " Option item = Option.ALPHA;\n" + + " switch (item) {\n" + + " case ALPHA: break;\n" + + " case BRAVO: break;\n" + + " default: break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82590 + */ +public void test064() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + "interface B {\n" + + " public void _test();\n" + + " \n" + + " }\n" + + " enum Y implements B {\n" + + "\n" + + " C1 {\n" + + " public void _test() {};\n" + + " },\n" + + " C2 {\n" + + " public void _test() {};\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "}\n", + }, + ""); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83847 + */ +public void test065() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " A;\n" + + " private void foo() {\n" + + " Y e= new Y() {\n" + + " };\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Y e= new Y() {\n" + + " ^\n" + + "Cannot instantiate the type Y\n" + + "----------\n"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83860 + */ +public void test066() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " SUCCESS (0) {};\n" + + " private Y(int i) {}\n" + + " public static void main(String[] args) {\n" + + " for (Y y : values()) {\n" + + " System.out.print(y);\n" + + " }\n" + + " }\n" + + " }\n" + + " Y.main(args);\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83219 + */ +public void test067() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " ONE, TWO, THREE;\n" + + " abstract int getSquare();\n" + + " abstract int getSquare();\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " ONE, TWO, THREE;\n" + + " ^^^\n" + + "The enum constant ONE must implement the abstract method getSquare()\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " ONE, TWO, THREE;\n" + + " ^^^\n" + + "The enum constant TWO must implement the abstract method getSquare()\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " ONE, TWO, THREE;\n" + + " ^^^^^\n" + + "The enum constant THREE must implement the abstract method getSquare()\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " abstract int getSquare();\n" + + " ^^^^^^^^^^^\n" + + "Duplicate method getSquare() in type Y\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " abstract int getSquare();\n" + + " ^^^^^^^^^^^\n" + + "Duplicate method getSquare() in type Y\n" + + "----------\n"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83648 + */ +public void test068() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " A(1, 3), B(1, 3), C(1, 3) { }\n" + + " ;\n" + + " public Y(int i, int j) { }\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public Y(int i, int j) { }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal modifier for the enum constructor; only private is permitted.\n" + + "----------\n"); +} + +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83648 + */ +public void test069() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " A(1, 3), B(1, 3), C(1, 3) { }\n" + + " ;\n" + + " protected Y(int i, int j) { }\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " protected Y(int i, int j) { }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal modifier for the enum constructor; only private is permitted.\n" + + "----------\n"); +} + +public void test070() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " PLUS {\n" + + " double eval(double x, double y) { return x + y; }\n" + + " };\n" + + "\n" + + " // Perform the arithmetic X represented by this constant\n" + + " abstract double eval(double x, double y);\n" + + " }\n" + + " }\n" + + "}" + }, + "" + ); + String expectedOutput = + " // Method descriptor #18 (Ljava/lang/String;I)V\n" + + " // Stack: 3, Locals: 3\n" + + " private X$1Y(java.lang.String arg0, int arg1);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 iload_2 [arg1]\n" + + " 3 invokespecial java.lang.Enum(java.lang.String, int) [25]\n" + + " 6 return\n"; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X$1Y.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83901 +public void test071() { + this.runConformTest( // no methods to implement + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X1 implements I {\n" + + " ;\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I {}\n" + }, + "" + ); + this.runConformTest( // no methods to implement with constant + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X1a implements I {\n" + + " A;\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I {}\n" + }, + "" + ); + this.runConformTest( // no methods to implement with constant body + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X1b implements I {\n" + + " A() { void random() {} };\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I {}\n" + }, + "" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83901 +public void test072() { + this.runConformTest( // implement inherited method + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X2 implements I {\n" + + " ;\n" + + " public void _test() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "" + ); + this.runConformTest( // implement inherited method with constant + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X2a implements I {\n" + + " A;\n" + + " public void _test() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "" + ); + this.runConformTest( // implement inherited method with constant body + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X2b implements I {\n" + + " A() { public void _test() {} };\n" + + " public void _test() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "" + ); + this.runConformTest( // implement inherited method with random constant body + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X2c implements I {\n" + + " A() { void random() {} };\n" + + " public void _test() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83901 +public void test073() { + this.runNegativeTest( // implement inherited method but as abstract + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X3 implements I {\n" + + " ;\n" + + " public abstract void _test();\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public abstract void _test();\n" + + " ^^^^^^^\n" + + "The enum X3 can only define the abstract method _test() if it also defines enum constants with corresponding implementations\n" + + "----------\n" + // X3 is not abstract and does not override abstract method test() in X3 + ); + this.runNegativeTest( // implement inherited method as abstract with constant + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X3a implements I {\n" + + " A;\n" + + " public abstract void _test();\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A;\n" + + " ^\n" + + "The enum constant A must implement the abstract method _test()\n" + + "----------\n" + // X3a is not abstract and does not override abstract method test() in X3a + ); + this.runConformTest( // implement inherited method as abstract with constant body + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X3b implements I {\n" + + " A() { public void _test() {} };\n" + + " public abstract void _test();\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "" + ); + this.runNegativeTest( // implement inherited method as abstract with random constant body + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X3c implements I {\n" + + " A() { void random() {} };\n" + + " public abstract void _test();\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A() { void random() {} };\n" + + " ^\n" + + "The enum constant A must implement the abstract method _test()\n" + + "----------\n" + // is not abstract and does not override abstract method test() in X3c + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83901 +public void test074() { + this.runNegativeTest( // define abstract method + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X4 {\n" + + " ;\n" + + " public abstract void _test();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public abstract void _test();\n" + + " ^^^^^^^\n" + + "The enum X4 can only define the abstract method _test() if it also defines enum constants with corresponding implementations\n" + + "----------\n" + // X4 is not abstract and does not override abstract method test() in X4 + ); + this.runNegativeTest( // define abstract method with constant + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X4a {\n" + + " A;\n" + + " public abstract void _test();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A;\n" + + " ^\n" + + "The enum constant A must implement the abstract method _test()\n" + + "----------\n" + // X4a is not abstract and does not override abstract method test() in X4a + ); + this.runConformTest( // define abstract method with constant body + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X4b {\n" + + " A() { public void _test() {} };\n" + + " public abstract void _test();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "" + ); + this.runNegativeTest( // define abstract method with random constant body + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X4c {\n" + + " A() { void random() {} };\n" + + " public abstract void _test();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A() { void random() {} };\n" + + " ^\n" + + "The enum constant A must implement the abstract method _test()\n" + + "----------\n" + // is not abstract and does not override abstract method test() in X4c + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83901 +public void testNPE075() { + this.runNegativeTest( // do not implement inherited method + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X5 implements I {\n" + + " ;\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " enum X5 implements I {\n" + + " ^^\n" + + "The type X5 must implement the inherited abstract method I._test()\n" + + "----------\n" + // X5 is not abstract and does not override abstract method test() in I + ); + this.runNegativeTest( // do not implement inherited method & have constant with no body + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X5a implements I {\n" + + " A;\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " enum X5a implements I {\n" + + " ^^^\n" + + "The type X5a must implement the inherited abstract method I._test()\n" + + "----------\n" + // X5a is not abstract and does not override abstract method test() in I + ); + this.runConformTest( // do not implement inherited method & have constant with body + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X5b implements I {\n" + + " A() { public void _test() {} };\n" + + " ;\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "" + ); + this.runNegativeTest( // do not implement inherited method & have constant with random body + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum X5c implements I {\n" + + " A() { void random() {} };\n" + + " ;\n" + + " private X5c() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void _test(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A() { void random() {} };\n" + + " ^\n" + + "The enum constant A must implement the abstract method _test()\n" + + "----------\n" + // is not abstract and does not override abstract method test() in I + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 +public void test076() { // bridge method needed + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "enum E implements I {\n" + + " A;\n" + + " public E foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + "}\n" + + " public static void main(String[] args) { ((I) E.A).foo(); }\n" + + "}\n" + + "interface I { I foo(); }\n" + }, + "SUCCESS" + ); +} + +public void test077() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + "enum E {\n" + + " A {\n" + + " void bar() {\n" + + " new M();\n" + + " }\n" + + " };\n" + + " abstract void bar();\n" + + " \n" + + " class M {\n" + + " M() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + + " E.A.bar();\n" + + " }\n" + + "}\n" + }, + "SUCCESS" + ); +} + +public void test078() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + "enum E {\n" + + " A {\n" + + " void bar() {\n" + + " new X(){\n" + + " void baz() {\n" + + " new M();\n" + + " }\n" + + " }.baz();\n" + + " }\n" + + " };\n" + + " abstract void bar();\n" + + " \n" + + " class M {\n" + + " M() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n" + + " E.A.bar();\n" + + " }\n" + + "}\n" + }, + "SUCCESS" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=85397 +public void test079() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " A, B;\n" + + " private strictfp Y() {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " private strictfp Y() {}\n" + + " ^^^\n" + + "Illegal modifier for the constructor in type Y; only public, protected & private are permitted\n" + + "----------\n" + ); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " strictfp enum Y {\n" + + " A, B;\n" + + " private Y() {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + "" + ); + + String[] expectedOutputs = new String[] { + " private strictfp X$1Y(java.lang.String arg0, int arg1);\n", + " public static strictfp new X(){}[] values();\n", + " public static strictfp new X(){} valueOf(java.lang.String arg0);\n" + }; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X$1Y.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + for (int i = 0, max = expectedOutputs.length; i < max; i++) { + String expectedOutput = expectedOutputs[i]; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=87064 +public void test080() { + this.runConformTest( + new String[] { + "X.java", + "interface TestInterface {\n" + + " int test();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y implements TestInterface {\n" + + " TEST {\n" + + " public int test() {\n" + + " return 42;\n" + + " }\n" + + " },\n" + + " ENUM {\n" + + " public int test() {\n" + + " return 37;\n" + + " }\n" + + " };\n" + + " }\n" + + " }\n" + + "} \n" + }, + "" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=87818 +public void test081() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {}\n" + + " void foo() {\n" + + " enum E {}\n" + + " }\n" + + "}" + }, + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88223 +public void test082() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " class Y {\n" + + " enum E {}\n" + + " }\n" + + " }\n" + + "}" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " class Y {\n" + + " enum E {}\n" + + " }\n" + + "}\n" + + "}" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {}\n" + + " void foo() {\n" + + " class Local {\n" + + " enum E {}\n" + + " }\n" + + " }\n" + + "}" + }, + ""); +} + + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=87998 - check no emulation warning +public void test083() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " INPUT {\n" + + " @Override\n" + + " public Y getReverse() {\n" + + " return OUTPUT;\n" + + " }\n" + + " },\n" + + " OUTPUT {\n" + + " @Override\n" + + " public Y getReverse() {\n" + + " return INPUT;\n" + + " }\n" + + " },\n" + + " INOUT {\n" + + " @Override\n" + + " public Y getReverse() {\n" + + " return INOUT;\n" + + " }\n" + + " };\n" + + " Y(){}\n" + + " Zork z;\n" + + " public abstract Y getReverse();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 23)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=87998 - check private constructor generation +public void test084() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " INPUT {\n" + + " @Override\n" + + " public Y getReverse() {\n" + + " return OUTPUT;\n" + + " }\n" + + " },\n" + + " OUTPUT {\n" + + " @Override\n" + + " public Y getReverse() {\n" + + " return INPUT;\n" + + " }\n" + + " },\n" + + " INOUT {\n" + + " @Override\n" + + " public Y getReverse() {\n" + + " return INOUT;\n" + + " }\n" + + " };\n" + + " Y(){}\n" + + " public abstract Y getReverse();\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X$1Y.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #20 (Ljava/lang/String;I)V\n" + + " // Stack: 3, Locals: 3\n" + + " private X$1Y(java.lang.String arg0, int arg1);\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88625 +public void test085() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Test1 {\n" + + " test11, test12\n" + + " };\n" + + " enum Test2 {\n" + + " test21, test22\n" + + " };\n" + + "\n" + + " class Y {\n" + + " void foo1(Test1 t1, Test2 t2) {\n" + + " boolean b = t1 == t2;\n" + + " }\n" + + " void foo2(Test1 t1, Object t2) {\n" + + " boolean b = t1 == t2;\n" + + " }\n" + + " void foo3(Test1 t1, Enum t2) {\n" + + " boolean b = t1 == t2;\n" + + " }\n" + + " public void foo() {\n" + + " boolean booleanTest = (Test1.test11 == Test2.test22);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " boolean b = t1 == t2;\n" + + " ^^^^^^^^\n" + + "Incompatible operand types Test1 and Test2\n" + + "----------\n" + + "2. WARNING in X.java (at line 17)\n" + + " void foo3(Test1 t1, Enum t2) {\n" + + " ^^^^\n" + + "Enum is a raw type. References to generic type Enum should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 21)\n" + + " boolean booleanTest = (Test1.test11 == Test2.test22);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible operand types Test1 and Test2\n" + + "----------\n"); +} +public void test086() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Test1 {\n" + + " V;\n" + + " static int foo = 0;\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +public void _test087_more_meaningful_error_msg_required() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Test1 {\n" + + " V;\n" + + " interface Foo {}\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test088() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + "\n" + + " enum Test1 {\n" + + " V;\n" + + " }\n" + + " }\n" + + " Object foo() {\n" + + " return this;\n" + + " }\n" + + "\n" + + "}\n", + }, + ""); +} +public void test089() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + "\n" + + " enum Test1 {\n" + + " V;\n" + + " protected final Test1 clone() { return V; }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " protected final Test1 clone() { return V; }\n" + + " ^^^^^^^\n" + + "Cannot override the final method from Enum\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " protected final Test1 clone() { return V; }\n" + + " ^^^^^^^\n" + + "The method clone() of type Test1 should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n"); +} +public void test090() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " enum Test1 {\n" + + " V;\n" + + " public Test1 foo() { return V; }\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n", + "java/lang/Object.java", + "package java.lang;\n" + + "public class Object {\n" + + " public Object foo() { return this; }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public Test1 foo() { return V; }\n" + + " ^^^^^\n" + + "The method foo() of type Test1 should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +public void test091() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " enum Test1 {\n" + + " V;\n" + + " void foo() {}\n" + + " }\n" + + " class Member {\n" + + " void bar(E e) {\n" + + " e.foo();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test092() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " enum Test1 {\n" + + " V;\n" + + " void foo() {}\n" + + " }\n" + + " class Member {\n" + + " void bar(E e) {\n" + + " e.foo();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " class Member {\n" + + " ^^^^^\n" + + "The type Test1 is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " e.foo();\n" + + " ^^^\n" + + "The method foo() is undefined for the type E\n" + + "----------\n"); +} +// check wildcard can extend Enum superclass +public void test093() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " enum Test1 {\n" + + " V;\n" + + " void foo() {}\n" + + " }\n" + + " class Member {\n" + + " E e;\n" + + " void bar(Member me) {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +// check super bit is set +public void test094() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {}\n" + + " }\n" + + "}\n", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X$1Y.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "// Signature: Ljava/lang/Enum;\n" + + "static final enum X$1Y {\n" + + " \n" + + " // Field descriptor #6 [LX$1Y;\n" + + " private static final synthetic X$1Y[] ENUM$VALUES;\n" + + " \n" + + " // Method descriptor #8 ()V\n" + + " // Stack: 1, Locals: 0\n" + + " static {};\n" + + " 0 iconst_0\n" + + " 1 anewarray X$1Y [1]\n" + + " 4 putstatic X$1Y.ENUM$VALUES : new X(){}[] [10]\n" + + " 7 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " \n" + + " // Method descriptor #15 (Ljava/lang/String;I)V\n" + + " // Stack: 3, Locals: 3\n" + + " private X$1Y(java.lang.String arg0, int arg1);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 iload_2 [arg1]\n" + + " 3 invokespecial java.lang.Enum(java.lang.String, int) [16]\n" + + " 6 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 7] local: this index: 0 type: new X(){}\n" + + " \n" + + " // Method descriptor #21 ()[LX$1Y;\n" + + " // Stack: 5, Locals: 3\n" + + " public static new X(){}[] values();\n" + + " 0 getstatic X$1Y.ENUM$VALUES : new X(){}[] [10]\n" + + " 3 dup\n" + + " 4 astore_0\n" + + " 5 iconst_0\n" + + " 6 aload_0\n" + + " 7 arraylength\n" + + " 8 dup\n" + + " 9 istore_1\n" + + " 10 anewarray X$1Y [1]\n" + + " 13 dup\n" + + " 14 astore_2\n" + + " 15 iconst_0\n" + + " 16 iload_1\n" + + " 17 invokestatic java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int) : void [22]\n" + + " 20 aload_2\n" + + " 21 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " \n" + + " // Method descriptor #29 (Ljava/lang/String;)LX$1Y;\n" + + " // Stack: 2, Locals: 1\n" + + " public static new X(){} valueOf(java.lang.String arg0);\n" + + " 0 ldc [1]\n" + + " 2 aload_0 [arg0]\n" + + " 3 invokestatic java.lang.Enum.valueOf(java.lang.Class, java.lang.String) : java.lang.Enum [30]\n" + + " 6 checkcast X$1Y [1]\n" + + " 9 areturn\n" ; + + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} +public void testNPE095() { // check missing abstract cases from multiple interfaces + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y implements I, J { \n" + + " ROUGE;\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void foo(); }\n" + + "interface J { void foo(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " enum Y implements I, J { \n" + + " ^\n" + + "The type Y must implement the inherited abstract method J.foo()\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y implements I, J { \n" + + " ROUGE;\n" + + " public void foo() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void foo(int i); }\n" + + "interface J { void foo(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " enum Y implements I, J { \n" + + " ^\n" + + "The type Y must implement the inherited abstract method I.foo(int)\n" + + "----------\n"); +} +public void testNPE096() { // check for raw vs. parameterized parameter types + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y implements I { \n" + + " ROUGE;\n" + + " public void foo(A a) {}\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void foo(A a); }\n" + + "class A {}\n" + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y implements I { \n" + + " ROUGE { public void foo(A a) {} }\n" + + " ;\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void foo(A a); }\n" + + "class A {}\n" + }, + ""); + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y implements I { \n" + + " ROUGE;\n" + + " public void foo(A a) {}\n" + + " }\n" + + " }\n" + + "}\n" + + "interface I { void foo(A a); }\n" + + "class A {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " enum Y implements I { \n" + + " ^\n" + + "The type Y must implement the inherited abstract method I.foo(A)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public void foo(A a) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) of type Y has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " interface I { void foo(A a); }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=89982 +public void test097() { + this.runNegativeTest( + new String[] { + "E.java", + "public class E {\n" + + " enum Numbers { ONE, TWO, THREE }\n" + + " static final String BLANK = \" \";\n" + + " void foo() {\n" + + " /**\n" + + " * Enumeration of some basic colors.\n" + + " */\n" + + " enum Colors {\n" + + " BLACK,\n" + + " WHITE,\n" + + " RED \n" + + " }\n" + + " Colors color = Colors.BLACK;\n" + + " switch (color) {\n" + + " case BLUE:\n" + + " case RED:\n" + + " break;\n" + + " default: // nop\n" + + " } \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in E.java (at line 15)\n" + + " case BLUE:\n" + + " ^^^^\n" + + "BLUE cannot be resolved or is not a field\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=89982 - variation +public void test098() { + this.runNegativeTest( + new String[] { + "E.java", + "public class E {\n" + + " enum Numbers { ONE, TWO, THREE }\n" + + " static final String BLANK = \" \";\n" + + " void foo() {\n" + + " /**\n" + + " * Enumeration of some basic colors.\n" + + " */\n" + + " enum Colors {\n" + + " BLACK,\n" + + " WHITE,\n" + + " RED; \n" + + " Zork z;\n" + + " }\n"+ + " Colors color = Colors.BLACK;\n" + + " switch (color) {\n" + + " } \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in E.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in E.java (at line 15)\n" + + " switch (color) {\n" + + " ^^^^^\n" + + "The enum constant BLACK needs a corresponding case label in this enum switch on Colors\n" + + "----------\n" + + "3. WARNING in E.java (at line 15)\n" + + " switch (color) {\n" + + " ^^^^^\n" + + "The enum constant RED needs a corresponding case label in this enum switch on Colors\n" + + "----------\n" + + "4. WARNING in E.java (at line 15)\n" + + " switch (color) {\n" + + " ^^^^^\n" + + "The enum constant WHITE needs a corresponding case label in this enum switch on Colors\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=89274 +public void _NAtest099() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {\n" + + " public static void main(String[] args) {\n" + + " enum E {\n" + + " v1, v2;\n" + + " }\n" + + " public class X extends A {\n" + + " void a(A.E e) {\n" + + " b(e); // no unchecked warning\n" + + " }\n" + + "\n" + + " void b(E e) {\n" + + " A.E e1 = e;\n" + + " }\n" + + " }\n"+ + "}\n" + + "}\n" + + "\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " A.E e1 = e;\n" + + " ^^^^^^^^^^^^\n" + + "The member type A.E cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type A\n" + + "----------\n"); +} +/* from JLS +"It is a compile-time error to reference a static field of an enum type +that is not a compile-time constant (15.28) from constructors, instance +initializer blocks, or instance variable initializer expressions of that +type. It is a compile-time error for the constructors, instance initializer +blocks, or instance variable initializer expressions of an enum constant e1 +to refer to itself or an enum constant of the same type that is declared to +the right of e1." + */ +public void testNPE100() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + "\n" + + " anEnumValue {\n" + + " private final Y thisOne = anEnumValue;\n" + + "\n" + + " @Override String getMessage() {\n" + + " return \"Here is what thisOne gets assigned: \" + thisOne;\n" + + " }\n" + + " };\n" + + "\n" + + " abstract String getMessage();\n" + + "\n" + + " public static void main(String[] arguments) {\n" + + " System.out.println(anEnumValue.getMessage());\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " private final Y thisOne = anEnumValue;\n" + + " ^^^^^^^^^^^\n" + + "Cannot refer to the static enum field Y.anEnumValue within an initializer\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=91761 +public void test101() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Foo {\n" + + " public boolean bar();\n" + + "}\n" + + "public class X { \n" + + " public static void main(String[] args) {\n" + + "enum BugDemo {\n" + + " CONSTANT(new Foo() {\n" + + " public boolean bar() {\n" + + " Zork z;\n" + + " return true;\n" + + " }\n" + + " });\n" + + " BugDemo(Foo foo) {\n" + + " }\n" + + " }\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=90775 +public void test102() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum SomeEnum {\n" + + " A, B;\n" + + " static SomeEnum foo() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " Enum e = SomeEnum.A;\n" + + " \n" + + " Set set1 = EnumSet.of(SomeEnum.A);\n" + + " Set set2 = EnumSet.of(SomeEnum.foo());\n" + + " \n" + + " Foo foo = null;\n" + + "}\n" + + "}\n" + + "class Foo > {\n" + + "}\n" + + "class Bar extends Foo {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " Foo foo = null;\n" + + " ^^^\n" + + "Bound mismatch: The type Bar is not a valid substitute for the bounded parameter > of the type Foo\n" + + "----------\n" + + "2. WARNING in X.java (at line 21)\n" + + " class Bar extends Foo {\n" + + " ^^^\n" + + "Foo is a raw type. References to generic type Foo should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=93396 +public void test103() { + this.runNegativeTest( + new String[] { + "BadEnum.java", + "public class BadEnum {\n" + + " public interface EnumInterface {\n" + + " public T getMethod();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " enum EnumClass implements EnumInterface {\n" + + " ENUM1 { public String getMethod() { return \"ENUM1\";} },\n" + + " ENUM2 { public String getMethod() { return \"ENUM2\";} };\n" + + " }\n" + + "}\n" + + "}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in BadEnum.java (at line 12)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=90215 +public void _NA_test104() { + this.runConformTest( + new String[] { + "p/Placeholder.java", + "package p;\n" + + "\n" + + "public class Placeholder {\n" + + " public static void main(String... argv) {\n" + + " ClassWithBadEnum.EnumClass constant = ClassWithBadEnum.EnumClass.ENUM1;\n" + // forward ref + " ClassWithBadEnum.main(argv);\n" + + " }\n" + + "} \n" + + "\n", + "p/ClassWithBadEnum.java", + "package p;\n" + + "\n" + + "public class ClassWithBadEnum {\n" + + " public interface EnumInterface {\n" + + " public T getMethod();\n" + + " }\n" + + "\n" + + " public enum EnumClass implements EnumInterface {\n" + + " ENUM1 { public String getMethod() { return \"ENUM1\";} },\n" + + " ENUM2 { public String getMethod() { return \"ENUM2\";} };\n" + + " }\n" + + " private EnumClass enumVar; \n" + + " public EnumClass getEnumVar() {\n" + + " return enumVar;\n" + + " }\n" + + " public void setEnumVar(EnumClass enumVar) {\n" + + " this.enumVar = enumVar;\n" + + " }\n" + + "\n" + + " public static void main(String... argv) {\n" + + " int a = 1;\n" + + " ClassWithBadEnum badEnum = new ClassWithBadEnum();\n" + + " badEnum.setEnumVar(ClassWithBadEnum.EnumClass.ENUM1);\n" + + " // Should fail if bug manifests itself because there will be two getInternalValue() methods\n" + + " // one returning an Object instead of a String\n" + + " String s3 = badEnum.getEnumVar().getMethod();\n" + + " System.out.println(s3);\n" + + " }\n" + + "} \n", + }, + "ENUM1"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void _NA_test105() { + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "Black" + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {BLACK, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "Black", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void _NA_test106() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " }\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "SUCCESS", + null, + true, + null, + options, + null + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {BLACK, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "SUCCESS", + null, + false, + null, + null, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void _NA_test107() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "BlackBlack", + null, + true, + null, + options, + null + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color { BLACK }" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "BlackBlack", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void _NA_test108() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " default:\n" + + " System.out.print(\"Error\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "Black", + null, + true, + null, + options, + null + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {RED, GREEN, YELLOW, BLACK, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "Black", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void _NA_test109() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Color c = null;\n" + + " try {\n" + + " c = BLACK;\n" + + " } catch(NoSuchFieldError e) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "Black", + null, + true, + null, + options, + null + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {RED, GREEN, YELLOW, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "SUCCESS", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void _NAtest110() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "public class X {\n" + + " public int[] $SWITCH_TABLE$pack$Color;\n" + + " public int[] $SWITCH_TABLE$pack$Color() { return null; }\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "Black", + null, + true, + null, + options, + null + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {BLACK, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "Black", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=88395 +public void _NA_test111() { + this.runConformTest( + new String[] { + "pack/X.java", + "package pack;\n" + + "import static pack.Color.*;\n" + + "@SuppressWarnings(\"incomplete-switch\")\n" + + "public class X {\n" + + " public int[] $SWITCH_TABLE$pack$Color;\n" + + " public int[] $SWITCH_TABLE$pack$Color() { return null; }\n" + + " public static void main(String[] args) {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " Color c = BLACK;\n" + + " switch(c) {\n" + + " case BLACK:\n" + + " System.out.print(\"Black\");\n" + + " break;\n" + + " case WHITE:\n" + + " System.out.print(\"White\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + "pack/Color.java", + "package pack;\n" + + "enum Color {WHITE, BLACK}" + }, + "BlackBlack" + ); + + this.runConformTest( + new String[] { + "pack/Color.java", + "package pack;\n" + + "enum Color {BLACK, WHITE}" + }, + "", + null, + false, + null + ); + + executeClass( + "pack/X.java", + "BlackBlack", + null, + false, + null, + null, + null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=97247 +public void _NA_test112() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.IGNORE); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "com/annot/X.java", + "package com.annot;\n" + + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "\n"+ + "public class X {\n"+ + " public static void main(String[] args) {\n" + + " enum TestType {\n"+ + " CORRECTNESS,\n"+ + " PERFORMANCE\n"+ + " }\n"+ + " @Target(ElementType.METHOD)\n"+ + " @interface Test {\n"+ + " TestType type() default TestType.CORRECTNESS;\n"+ + " }\n"+ + " @Test(type=TestType.PERFORMANCE)\n"+ + " public void _testBar() throws Exception {\n"+ + " Test annotation = this.getClass().getMethod(\"testBar\").getAnnotation(Test.class);\n"+ + " switch (annotation.type()) {\n"+ + " case PERFORMANCE:\n"+ + " System.out.println(TestType.PERFORMANCE);\n"+ + " break;\n"+ + " case CORRECTNESS:\n"+ + " System.out.println(TestType.CORRECTNESS);\n"+ + " break;\n"+ + " } \n"+ + " }\n"+ + " }\n"+ + "}" + }, + "", + null, + true, + new String[] {"--enable-preview"}, + options, + null + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=93789 +public void _test113() { + if (this.complianceLevel >= ClassFileConstants.JDK16) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n" + + " enum BugDemo {\n" + + " FOO() {\n" + + " static int bar;\n" + + " }\n" + + " }\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static int bar;\n" + + " ^^^\n" + + "The field bar cannot be declared static in a non-static inner type, unless initialized with a constant expression\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=99428 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=99655 +public void test114() { + this.runConformTest( + new String[] { + "LocalEnumTest.java", + "import java.lang.reflect.*;\n" + + "import java.lang.annotation.*;\n" + + "interface I {\n" + + " void foo();\n" + + "}\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface ExpectedModifiers {\n" + + " int value();\n" + + "}\n" + + "@ExpectedModifiers(Modifier.FINAL)\n" + + "public enum LocalEnumTest {\n" + + " X(255);\n" + + " LocalEnumTest(int r) {}\n" + + " public static void main(String argv[]) throws Exception {\n" + + " test(\"LocalEnumTest\");\n" + + " test(\"LocalEnumTest$1EnumA\");\n" + + " test(\"LocalEnumTest$1EnumB\");\n" + + " test(\"LocalEnumTest$1EnumB2\");\n" + + " test(\"LocalEnumTest$1EnumB3\");\n" + + // TODO (kent) need verifier to detect when an Enum should be tagged as abstract + //" test(\"LocalEnumTest$EnumC\");\n" + + //" test(\"LocalEnumTest$EnumC2\");\n" + + " test(\"LocalEnumTest$1EnumC3\");\n" + + " test(\"LocalEnumTest$1EnumD\");\n" + + " @ExpectedModifiers(Modifier.FINAL|Modifier.STATIC)\n" + + " enum EnumA {\n" + + " A;\n" + + " }\n" + + " @ExpectedModifiers(Modifier.STATIC)\n" + + " enum EnumB {\n" + + " B {\n" + + " int value() { return 1; }\n" + + " };\n" + + " int value(){ return 0; }\n" + + " }\n" + + " @ExpectedModifiers(Modifier.STATIC)\n" + + " enum EnumB2 {\n" + + " B2 {};\n" + + " int value(){ return 0; }\n" + + " }\n" + + " @ExpectedModifiers(Modifier.FINAL|Modifier.STATIC)\n" + + " enum EnumB3 {\n" + + " B3;\n" + + " int value(){ return 0; }\n" + + " }\n" + + " @ExpectedModifiers(Modifier.STATIC)\n" + + " enum EnumC implements I {\n" + + " C {\n" + + " int value() { return 1; }\n" + + " };\n" + + " int value(){ return 0; }\n" + + " public void foo(){}\n" + + " }\n" + + " @ExpectedModifiers(Modifier.STATIC)\n" + + " enum EnumC2 implements I {\n" + + " C2 {};\n" + + " int value(){ return 0; }\n" + + " public void foo(){}\n" + + " }\n" + + " @ExpectedModifiers(Modifier.FINAL|Modifier.STATIC)\n" + + " enum EnumC3 implements I {\n" + + " C3;\n" + + " int value(){ return 0; }\n" + + " public void foo(){}\n" + + " }\n" + + " @ExpectedModifiers(Modifier.ABSTRACT|Modifier.STATIC)\n" + + " enum EnumD {\n" + + " D {\n" + + " int value() { return 1; }\n" + + " };\n" + + " abstract int value();\n" + + " }\n" + + " }\n" + + " static void test(String className) throws Exception {\n" + + " Class c = Class.forName(className);\n" + + " ExpectedModifiers em = (ExpectedModifiers) c.getAnnotation(ExpectedModifiers.class);\n" + + " if (em != null) {\n" + + " int classModifiers = c.getModifiers();\n" + + " int expected = em.value();\n" + + " if (expected != (classModifiers & (Modifier.ABSTRACT|Modifier.FINAL|Modifier.STATIC))) {\n" + + " if ((expected & Modifier.ABSTRACT) != (classModifiers & Modifier.ABSTRACT))\n" + + " System.out.println(\"FAILED ABSTRACT: \" + className);\n" + + " if ((expected & Modifier.FINAL) != (classModifiers & Modifier.FINAL))\n" + + " System.out.println(\"FAILED FINAL: \" + className);\n" + + " if ((expected & Modifier.STATIC) != (classModifiers & Modifier.STATIC))\n" + + " System.out.println(\"FAILED STATIC: \" + className);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101713 +public void test115() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " enum Y {\n" + + " VALUE;\n" + + "\n" + + " static int ASD;\n" + + " final static int CST = 0;\n" + + " \n" + + " private Y() {\n" + + " VALUE = null;\n" + + " ASD = 5;\n" + + " Y.VALUE = null;\n" + + " Y.ASD = 5;\n" + + " \n" + + " System.out.println(CST);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " VALUE = null;\n" + + " ^^^^^\n" + + "Cannot refer to the static enum field Y.VALUE within an initializer\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " ASD = 5;\n" + + " ^^^\n" + + "Cannot refer to the static enum field Y.ASD within an initializer\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " Y.VALUE = null;\n" + + " ^^^^^\n" + + "Cannot refer to the static enum field Y.VALUE within an initializer\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " Y.ASD = 5;\n" + + " ^^^\n" + + "Cannot refer to the static enum field Y.ASD within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101713 - variation +public void test116() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " enum Y {\n" + + " BLEU, \n" + + " BLANC, \n" + + " ROUGE;\n" + + " {\n" + + " BLEU = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " BLEU = null;\n" + + " ^^^^\n" + + "Cannot refer to the static enum field Y.BLEU within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101713 - variation +public void test117() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " enum Y {\n" + + " BLEU, \n" + + " BLANC, \n" + + " ROUGE;\n" + + " {\n" + + " Y x = BLEU.BLANC; // ko\n" + + " Y x2 = BLEU; // ko\n" + + " }\n" + + " static {\n" + + " Y x = BLEU.BLANC; // ok\n" + + " Y x2 = BLEU; // ok\n" + + " } \n" + + " Y dummy = BLEU; // ko\n" + + " static Y DUMMY = BLANC; // ok\n" + + " Y() {\n" + + " Y x = BLEU.BLANC; // ko\n" + + " Y x2 = BLEU; // ko\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Y x = BLEU.BLANC; // ko\n" + + " ^^^^\n" + + "Cannot refer to the static enum field Y.BLEU within an initializer\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Y x = BLEU.BLANC; // ko\n" + + " ^^^^^\n" + + "Cannot refer to the static enum field Y.BLANC within an initializer\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " Y x = BLEU.BLANC; // ko\n" + + " ^^^^^\n" + + "The static field Y.BLANC should be accessed in a static way\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " Y x2 = BLEU; // ko\n" + + " ^^^^\n" + + "Cannot refer to the static enum field Y.BLEU within an initializer\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " Y x = BLEU.BLANC; // ok\n" + + " ^^^^^\n" + + "The static field Y.BLANC should be accessed in a static way\n" + + "----------\n" + + "6. ERROR in X.java (at line 15)\n" + + " Y dummy = BLEU; // ko\n" + + " ^^^^\n" + + "Cannot refer to the static enum field Y.BLEU within an initializer\n" + + "----------\n" + + "7. ERROR in X.java (at line 18)\n" + + " Y x = BLEU.BLANC; // ko\n" + + " ^^^^\n" + + "Cannot refer to the static enum field Y.BLEU within an initializer\n" + + "----------\n" + + "8. ERROR in X.java (at line 18)\n" + + " Y x = BLEU.BLANC; // ko\n" + + " ^^^^^\n" + + "Cannot refer to the static enum field Y.BLANC within an initializer\n" + + "----------\n" + + "9. WARNING in X.java (at line 18)\n" + + " Y x = BLEU.BLANC; // ko\n" + + " ^^^^^\n" + + "The static field Y.BLANC should be accessed in a static way\n" + + "----------\n" + + "10. ERROR in X.java (at line 19)\n" + + " Y x2 = BLEU; // ko\n" + + " ^^^^\n" + + "Cannot refer to the static enum field Y.BLEU within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=102265 +public void test118() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " enum Y {\n" + + " one,\n" + + " two;\n" + + " \n" + + " static ArrayList someList;\n" + + " \n" + + " private Y() {\n" + + " if (someList == null) {\n" + + " someList = new ArrayList();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " static ArrayList someList;\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " if (someList == null) {\n" + + " ^^^^^^^^\n" + + "Cannot refer to the static enum field Y.someList within an initializer\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " someList = new ArrayList();\n" + + " ^^^^^^^^\n" + + "Cannot refer to the static enum field Y.someList within an initializer\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " someList = new ArrayList();\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"); +} +public void test119() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " enum Y {\n" + + " BLEU, BLANC, ROUGE;\n" + + " final static int CST = 0;\n" + + " enum Member {\n" + + " ;\n" + + " Object obj1 = CST;\n" + + " Object obj2 = BLEU;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=102213 +public void test120() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " enum Y {\n" + + "\n" + + " A() {\n" + + " final Y a = A;\n" + + " final Y a2 = B.A;\n" + + " @Override void foo() {\n" + + " System.out.println(String.valueOf(a));\n" + + " System.out.println(String.valueOf(a2));\n" + + " }\n" + + " },\n" + + " B() {\n" + + " @Override void foo(){}\n" + + " };\n" + + " abstract void foo();\n" + + " \n" + + " public static void main(String[] args) {\n" + + " A.foo();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " final Y a = A;\n" + + " ^\n" + + "Cannot refer to the static enum field Y.A within an initializer\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " final Y a2 = B.A;\n" + + " ^\n" + + "Cannot refer to the static enum field Y.B within an initializer\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " final Y a2 = B.A;\n" + + " ^\n" + + "Cannot refer to the static enum field Y.A within an initializer\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " final Y a2 = B.A;\n" + + " ^\n" + + "The static field Y.A should be accessed in a static way\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=92165 +public void test121() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { \n" + + " public static void main(String[] args) {\n" + + "enum Y {\n" + + "\n" + + " UNKNOWN();\n" + + "\n" + + " private static String error;\n" + + "\n" + + " {\n" + + " error = \"error\";\n" + + " }\n" + + "}\n" + + "}\n" + + "\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " error = \"error\";\n" + + " ^^^^^\n" + + "Cannot refer to the static enum field Y.error within an initializer\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=105592 +public void test122() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " enum State {\n" + + " NORMAL\n" + + "}\n" + + " State state = State.NORMAL;\n" + + " switch (state) {\n" + + " case (NORMAL) :\n" + + " System.out.println(State.NORMAL);\n" + + " break;\n" + + " default: // nop\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " case (NORMAL) :\n" + + " ^^^^^^^^\n" + + "Enum constants cannot be surrounded by parenthesis\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=110403 +public void test123() { + this.runNegativeTest( + new String[] { + "Foo.java", + "public class Foo { \n" + + " public static void main(String[] args) {\n" + + "enum Y {\n" + + " A(0);\n" + + " Y(int x) {\n" + + " t[0]=x;\n" + + " }\n" + + " private static final int[] t = new int[12];\n" + + "}\n" + + "}\n" + + "\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 6)\n" + + " t[0]=x;\n" + + " ^\n" + + "Cannot refer to the static enum field Y.t within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=1101417 +public void test124() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n" + + " public void foo() {\n" + + " enum Y {\n" + + " max {\n" + + " { \n" + + " val=3; \n" + + " } \n" + + " @Override public String toString() {\n" + + " return Integer.toString(val);\n" + + " }\n" + + " }; \n" + + " {\n" + + " val=2;\n" + + " }\n" + + " private int val; \n" + + " }\n" + + "}\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " val=3; \n" + + " ^^^\n" + + "Cannot make a static reference to the non-static field val\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " return Integer.toString(val);\n" + + " ^^^\n" + + "Cannot make a static reference to the non-static field val\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=112231 +public void test125() { + this.runNegativeTest( + new String[] { + "X.java", + "\n" + + "public class X {\n" + + " interface I {\n" + + " default int values(){\n" + + " enum E implements I {\n" + + " A, B, C;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " enum E implements I {\n" + + " ^\n" + + "This static method cannot hide the instance method from X.I\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126087 +public void test126() { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " public static void main(String[] args) {\n" + + " enum NoValues {}\n" + + " System.out.println(\"[\"+NoValues.values().length+\"]\");\n" + + " }\n" + + " }\n" + }, + "[0]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126087 +// Commented and created https://bugs.eclipse.org/bugs/show_bug.cgi?id=570106 +public void test127() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " VALUE {\n" + + " void foo() {\n" + + " };\n" + + " };\n" + + " abstract void foo();\n" + + " }\n" + + " System.out.println(\"[\"+Y.values().length+\"]\");\n" + + " }\n" + + "}" + }, + "[1]"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 new java.lang.StringBuilder [22]\n" + + " 6 dup\n" + + " 7 ldc [24]\n" + + " 9 invokespecial java.lang.StringBuilder(java.lang.String) [26]\n" + + " 12 invokestatic X$1Y.values() : X$1Y[] [29]\n" + + " 15 arraylength\n" + + " 16 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [35]\n" + + " 19 ldc [39]\n" + + " 21 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [41]\n" + + " 24 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [44]\n" + + " 27 invokevirtual java.io.PrintStream.println(java.lang.String) : void [48]\n" + + " 30 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 10]\n" + + " [pc: 30, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 31] local: args index: 0 type: java.lang.String[]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #30 X$1Y, outer class info: #0\n" + + " inner name: #58 Y, accessflags: 17416 abstract static]\n" + + "\n" + + "Nest Members:\n" + + " #30 X$1Y,\n" + + " #60 X$1Y$1\n" + + "}"; + + int index = actualOutput.indexOf(expectedOutput); + + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } + + disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X$1Y$1.class")); + actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + expectedOutput = + "ENUM$VALUES"; + + index = actualOutput.indexOf(expectedOutput); + if (index != -1) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index != -1) { + assertTrue("Must not have field ENUM$VALUES", false); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127766 +public void test128() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main( String[] args) {\n" + + " Enum e = new Enum(\"foo\", 2) {\n" + + " public int compareTo( Object o) {\n" + + " return 0;\n" + + " }\n" + + " };\n" + + " System.out.println(e);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Enum e = new Enum(\"foo\", 2) {\n" + + " ^^^^\n" + + "The type new Enum(){} may not subclass Enum explicitly\n" + + "----------\n", + null, + true, + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=141155 +public void test129() throws Exception { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " public void foo(){\n" + + " enum Y {\n" + + " A, B, C;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " public void foo();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #16 ([Ljava/lang/String;)V\n" + + " // Stack: 0, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: args index: 0 type: java.lang.String[]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #22 X$1Y, outer class info: #0\n" + + " inner name: #24 Y, accessflags: 16408 static final]\n" + + "\n" + + "Nest Members:\n" + + " #22 X$1Y\n" + + "}"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=141810 +public void test130() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Action {ONE, TWO}\n" + + " for(Action a : Action.values()) {\n" + + " switch(a) {\n" + + " case ONE:\n" + + " System.out.print(\"1\");\n" + + " break;\n" + + " case TWO:\n" + + " System.out.print(\"2\");\n" + + " break;\n" + + " default:\n" + + " System.out.print(\"default\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + "12" + ); + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Action {ONE, TWO, THREE}\n" + + " for(Action a : Action.values()) {\n" + + " switch(a) {\n" + + " case ONE:\n" + + " System.out.print(\"1\");\n" + + " break;\n" + + " case TWO:\n" + + " System.out.print(\"2\");\n" + + " break;\n" + + " default:\n" + + " System.out.print(\"default\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + "12default" + ); + + +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=145732 +public void test131() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " //A,B\n" + + " ;\n" + + " public static void main(String[] args) {\n" + + " enum Y { }\n " + + " try {\n" + + " System.out.println(Y.valueOf(null));\n" + + " } catch (NullPointerException e) {\n" + + " System.out.println(\"NullPointerException\");\n" + + " } catch (IllegalArgumentException e) {\n" + + " System.out.println(\"IllegalArgumentException\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "NullPointerException"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=145732 - variation +public void test132() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " A,B\n" + + " ;\n" + + " }\n" + + " try {\n" + + " System.out.println(Y.valueOf(null));\n" + + " } catch (NullPointerException e) {\n" + + " System.out.println(\"NullPointerException\");\n" + + " } catch (IllegalArgumentException e) {\n" + + " System.out.println(\"IllegalArgumentException\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "NullPointerException"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=147747 +public void test133() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " A, B, C;\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "public class X {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 0, Locals: 1\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: args index: 0 type: java.lang.String[]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #21 X$1Y, outer class info: #0\n" + + " inner name: #23 Y, accessflags: 16408 static final]\n" + + "\n" + + "Nest Members:\n" + + " #21 X$1Y\n" + + "}"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("unexpected bytecode sequence", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=149042 +public void test134() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " INITIAL ,\n" + + " OPENED {\n" + + " {\n" + + " System.out.printf(\"After the %s constructor\\n\",INITIAL);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.printf(\"After the %s constructor\\n\",INITIAL);\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Y.INITIAL within an initializer\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149562 +// a default case is required to consider that b is initialized (in case E +// takes new values in the future) +public void test135() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean foo() {\n" + + " enum E {\n" + + " A,\n" + + " B\n" + + " }\n" + + " E e = E.A;\n" + + " boolean b;\n" + + " switch (e) {\n" + + " case A:\n" + + " b = true;\n" + + " break;\n" + + " case B:\n" + + " b = false;\n" + + " break;\n" + + " }\n" + + " return b;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " return b;\n" + + " ^\n" + + "The local variable b may not have been initialized. Note that a problem regarding missing 'default:' on 'switch' has been suppressed, which is perhaps related to this problem\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=151368 +public void test136() { + this.runConformTest( + new String[] { + "X.java", + "import p.BeanName;\n" + + "public class X {\n" + + " Object o = BeanName.CreateStepApiOperation;\n" + + "}", + "p/BeanName.java", + "package p;\n" + + "public enum BeanName {\n" + + "\n" + + " //~ Enum constants ---------------------------------------------------------\n" + + "\n" + + " AbortAllJobsOperation,\n" + + " AbortJobApiOperation,\n" + + " AbortStepOperation,\n" + + " AclVoter,\n" + + " AcquireNamedLockApiOperation,\n" + + " AuthenticationManager,\n" + + " BeginStepOperation,\n" + + " CloneApiOperation,\n" + + " CommanderDao,\n" + + " CommanderServer,\n" + + " ConfigureQuartzOperation,\n" + + " CreateAclEntryApiOperation,\n" + + " CreateActualParameterApiOperation,\n" + + " CreateFormalParameterApiOperation,\n" + + " CreateProcedureApiOperation,\n" + + " CreateProjectApiOperation,\n" + + " CreateResourceApiOperation,\n" + + " CreateScheduleApiOperation,\n" + + " CreateStepApiOperation,\n" + + " DeleteAclEntryApiOperation,\n" + + " DeleteActualParameterApiOperation,\n" + + " DeleteFormalParameterApiOperation,\n" + + " DeleteJobApiOperation,\n" + + " DeleteProcedureApiOperation,\n" + + " DeleteProjectApiOperation,\n" + + " DeletePropertyApiOperation,\n" + + " DeleteResourceApiOperation,\n" + + " DeleteScheduleApiOperation,\n" + + " DeleteStepApiOperation,\n" + + " DispatchApiRequestOperation,\n" + + " DumpStatisticsApiOperation,\n" + + " ExpandJobStepAction,\n" + + " ExportApiOperation,\n" + + " FinishStepOperation,\n" + + " GetAccessApiOperation,\n" + + " GetAclEntryApiOperation,\n" + + " GetActualParameterApiOperation,\n" + + " GetActualParametersApiOperation,\n" + + " GetFormalParameterApiOperation,\n" + + " GetFormalParametersApiOperation,\n" + + " GetJobDetailsApiOperation,\n" + + " GetJobInfoApiOperation,\n" + + " GetJobStatusApiOperation,\n" + + " GetJobStepDetailsApiOperation,\n" + + " GetJobStepStatusApiOperation,\n" + + " GetJobsApiOperation,\n" + + " GetProcedureApiOperation,\n" + + " GetProceduresApiOperation,\n" + + " GetProjectApiOperation,\n" + + " GetProjectsApiOperation,\n" + + " GetPropertiesApiOperation,\n" + + " GetPropertyApiOperation,\n" + + " GetResourceApiOperation,\n" + + " GetResourcesApiOperation,\n" + + " GetResourcesInPoolApiOperation,\n" + + " GetScheduleApiOperation,\n" + + " GetSchedulesApiOperation,\n" + + " GetStepApiOperation,\n" + + " GetStepsApiOperation,\n" + + " GetVersionsApiOperation,\n" + + " GraphWorkflowApiOperation,\n" + + " HibernateFlushListener,\n" + + " ImportApiOperation,\n" + + " IncrementPropertyApiOperation,\n" + + " InvokeCommandOperation,\n" + + " InvokePostProcessorOperation,\n" + + " LoginApiOperation,\n" + + " LogManager,\n" + + " LogMessageApiOperation,\n" + + " ModifyAclEntryApiOperation,\n" + + " ModifyActualParameterApiOperation,\n" + + " ModifyFormalParameterApiOperation,\n" + + " ModifyProcedureApiOperation,\n" + + " ModifyProjectApiOperation,\n" + + " ModifyPropertyApiOperation,\n" + + " ModifyResourceApiOperation,\n" + + " ModifyScheduleApiOperation,\n" + + " ModifyStepApiOperation,\n" + + " MoveStepApiOperation,\n" + + " PauseSchedulerApiOperation,\n" + + " QuartzQueue,\n" + + " QuartzScheduler,\n" + + " ReleaseNamedLockApiOperation,\n" + + " ResourceInvoker,\n" + + " RunProcedureApiOperation,\n" + + " RunQueryApiOperation,\n" + + " SaxReader,\n" + + " ScheduleStepsOperation,\n" + + " SessionCache,\n" + + " SetJobNameApiOperation,\n" + + " SetPropertyApiOperation,\n" + + " SetStepStatusAction,\n" + + " StartWorkflowOperation,\n" + + " StateRefreshOperation,\n" + + " StepCompletionPrecondition,\n" + + " StepOutcomePrecondition,\n" + + " StepScheduler,\n" + + " TemplateOperation,\n" + + " TimeoutWatchdog,\n" + + " UpdateConfigurationOperation,\n" + + " Workspace,\n" + + " XmlRequestHandler;\n" + + "\n" + + " //~ Static fields/initializers ---------------------------------------------\n" + + "\n" + + " public static final int MAX_BEAN_NAME_LENGTH = 33;\n" + + "\n" + + " //~ Methods ----------------------------------------------------------------\n" + + "\n" + + " /**\n" + + " * Get this bean name as a property name, i.e. uncapitalized.\n" + + " *\n" + + " * @return String\n" + + " */\n" + + " public String getPropertyName()\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n", // =================, + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156540 +public void test137() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " interface Interface {\n" + + " public int value();\n" + + " }\n" + + "\n" + + "\n" + + " public static void main(String[] args) {\n" + + " enum MyEnum implements Interface {\n" + + " ;\n" + + "\n" + + " MyEnum(int value) { this.value = value; } \n" + + " public int value() { return this.value; }\n" + + " private int value;\n" + + " }\n" + + " System.out.println(MyEnum.values().length);\n" + + " }\n" + + "}", // =================, + }, + "0"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156591 +public void test138() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " PLUS {\n" + + " double eval(double x, double y) {\n" + + " return x + y;\n" + + " }\n" + + " },\n" + + " MINUS {\n" + + " @Override\n" + + " abstract double eval(double x, double y);\n" + + " };\n" + + " abstract double eval(double x, double y);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " double eval(double x, double y) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method eval(double, double) of type new Y(){} should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " MINUS {\n" + + " ^^^^^\n" + + "The enum constant MINUS cannot define abstract methods\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " abstract double eval(double x, double y);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method eval cannot be abstract in the enum constant MINUS\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156591 - variation +public void test139() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " PLUS {\n" + + " double eval(double x, double y) {\n" + + " return x + y;\n" + + " }\n" + + " },\n" + + " MINUS {\n" + + " abstract double eval2(double x, double y);\n" + + " };\n" + + "\n" + + " abstract double eval(double x, double y);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " double eval(double x, double y) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method eval(double, double) of type new Y(){} should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " MINUS {\n" + + " ^^^^^\n" + + "The enum constant MINUS cannot define abstract methods\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " MINUS {\n" + + " ^^^^^\n" + + "The enum constant MINUS must implement the abstract method eval(double, double)\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " abstract double eval2(double x, double y);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method eval2 cannot be abstract in the enum constant MINUS\n" + + "----------\n" + ); +} +//check final modifier +public void test140() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar(X x) {\n" + + " enum Y {\n" + + " PLUS {/*ANONYMOUS*/}, MINUS;\n" + + " }\n" + + " Y y = Y.PLUS;\n" + + " Runnable r = (Runnable)y;\n" + + " }\n" + + "}", // ================= + }, + ""); +} +//check final modifier +public void test141() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar(X x) {\n" + + " enum Y {\n" + + " PLUS, MINUS;\n" + + " }\n" + + " Y y = Y.PLUS;\n" + + + " Runnable r = (Runnable)y;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Runnable r = (Runnable)y;\n" + + " ^^^^^^^^^^^\n" + + "Cannot cast from Y to Runnable\n" + + "----------\n"); +} +public void test142() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Week {\n" + + " Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday\n" + + " }\n" + + " for (Week w : Week.values())\n" + + " System.out.print(w + \" \");\n" + + " for (Week w : java.util.EnumSet.range(Week.Monday, Week.Friday)) {\n" + + " System.out.print(w + \" \");\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "Monday Tuesday Wednesday Thursday Friday Saturday Sunday Monday Tuesday Wednesday Thursday Friday"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=166866 +public void test143() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " A {\n" + + " @Override\n" + + " public String toString() {\n" + + " return a();\n" + + " }\n" + + " public abstract String a();\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A {\n" + + " ^\n" + + "The enum constant A cannot define abstract methods\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " public abstract String a();\n" + + " ^^^\n" + + "The method a cannot be abstract in the enum constant A\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186822 +public void test144() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X{\n" + + " enum Y {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " enum Y {}\n" + + " ^\n" + + "Syntax error, enum declaration cannot have type parameters\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=186822 +public void test145() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "ClassC.java", + "public class ClassC {\n" + + " void bar() {\n" + + " enum EnumA {\n" + + " B1,\n" + + " B2;\n" + + " public void foo(){}\n" + + " }\n" + + " EnumA.B1.B1.foo();\n" + + " EnumA.B1.B2.foo();\n" + + " }\n" + + "}", + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in ClassC.java (at line 8)\n" + + " EnumA.B1.B1.foo();\n" + + " ^^\n" + + "The static field EnumA.B1 should be accessed in a static way\n" + + "----------\n" + + "2. ERROR in ClassC.java (at line 9)\n" + + " EnumA.B1.B2.foo();\n" + + " ^^\n" + + "The static field EnumA.B2 should be accessed in a static way\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=207915 +public void test146() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " final String test;\n" + + " public X() { // error\n" + + " enum MyEnum {\n" + + " A, B\n" + + " }\n" + + " MyEnum e = MyEnum.A;\n" + + " switch (e) {\n" + + " case A:\n" + + " test = \"a\";\n" + + " break;\n" + + " case B:\n" + + " test = \"a\";\n" + + " break;\n" + + " // default: test = \"unknown\"; // enabling this line fixes above error\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public X() { // error\n" + + " ^^^\n" + + "The blank final field test may not have been initialized. Note that a problem regarding missing 'default:' on 'switch' has been suppressed, which is perhaps related to this problem\n" + + "----------\n"); +} +// normal error when other warning is enabled +public void test146b() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE, JavaCore.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " final String test;\n" + + " public X() { // error\n" + + " enum MyEnum {\n" + + " A, B\n" + + " }\n" + + " MyEnum e = MyEnum.A;\n" + + " switch (e) {\n" + + " case A:\n" + + " test = \"a\";\n" + + " break;\n" + + " case B:\n" + + " test = \"a\";\n" + + " break;\n" + + " // default: test = \"unknown\"; // enabling this line fixes above error\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public X() { // error\n" + + " ^^^\n" + + "The blank final field test may not have been initialized\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " switch (e) {\n" + + " ^\n" + + "The switch over the enum type MyEnum should have a default case\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 +public void test147() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " public abstract enum E {\n" + + " SUCCESS;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 4)\n" + + " public abstract enum E {\n" + + " ^\n" + + "Illegal modifier for local enum E; no explicit modifier is permitted\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation +public void test148() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " abstract enum E implements Runnable {\n" + + " SUCCESS;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 4)\n" + + " abstract enum E implements Runnable {\n" + + " ^\n" + + "Illegal modifier for local enum E; no explicit modifier is permitted\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation +public void _NA_test149() throws Exception { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public enum E implements Runnable {\n" + + " SUCCESS;\n" + + " public void run(){}\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Class c = E.class;\n" + + " System.out.println(c.getName() + \":\" + X.E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + "p.X$E:SUCCESS"); + + String expectedOutput = + "// Signature: Ljava/lang/Enum;Ljava/lang/Runnable;\n" + + "public static final enum p.X$E implements java.lang.Runnable {\n"; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"p" + File.separator + "X$E.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation +public void test150() throws Exception { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum E implements Runnable {\n" + + " SUCCESS;\n" + + " public void run(){}\n" + + " }\n" + + " Class c = E.class;\n" + + " System.out.println(c.getName() + \":\" + E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + "p.X$1E:SUCCESS"); + +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation +public void test151() throws Exception { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " enum E implements Runnable {\n" + + " SUCCESS {};\n" + + " public void run(){}\n" + + " }\n" + + " Class c = E.class;\n" + + " System.out.println(c.getName() + \":\" + E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + "p.X$1E:SUCCESS"); + + String expectedOutput = + "// Signature: Ljava/lang/Enum;Ljava/lang/Runnable;\n" + + "abstract static enum p.X$1E implements java.lang.Runnable {\n" + + " \n" + + " // Field descriptor #8 Lp/X$1E;\n" + + " public static final enum p.X$1E SUCCESS;\n" + + " \n" + + " // Field descriptor #10 [Lp/X$1E;\n" + + " private static final synthetic p.X$1E[] ENUM$VALUES;\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 4, Locals: 0\n" + + " static {};\n" + + " 0 new p.X$1E$1 [14]\n" + + " 3 dup\n" + + " 4 ldc [16]\n" + + " 6 iconst_0\n" + + " 7 invokespecial p.X$1E$1(java.lang.String, int) [17]\n" + + " 10 putstatic p.X$1E.SUCCESS : new p.X(){} [21]\n" + + " 13 iconst_1\n" + + " 14 anewarray p.X$1E [1]\n" + + " 17 dup\n" + + " 18 iconst_0\n" + + " 19 getstatic p.X$1E.SUCCESS : new p.X(){} [21]\n" + + " 22 aastore\n" + + " 23 putstatic p.X$1E.ENUM$VALUES : new p.X(){}[] [23]\n" + + " 26 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 13, line: 4]\n" + + " \n" + + " // Method descriptor #20 (Ljava/lang/String;I)V\n" + + " // Stack: 3, Locals: 3\n" + + " private X$1E(java.lang.String arg0, int arg1);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 iload_2 [arg1]\n" + + " 3 invokespecial java.lang.Enum(java.lang.String, int) [27]\n" + + " 6 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 7] local: this index: 0 type: new p.X(){}\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " public void run();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: new p.X(){}\n" + + " \n" + + " // Method descriptor #31 ()[Lp/X$1E;\n" + + " // Stack: 5, Locals: 3\n" + + " public static new p.X(){}[] values();\n" + + " 0 getstatic p.X$1E.ENUM$VALUES : new p.X(){}[] [23]\n" + + " 3 dup\n" + + " 4 astore_0\n" + + " 5 iconst_0\n" + + " 6 aload_0\n" + + " 7 arraylength\n" + + " 8 dup\n" + + " 9 istore_1\n" + + " 10 anewarray p.X$1E [1]\n" + + " 13 dup\n" + + " 14 astore_2\n" + + " 15 iconst_0\n" + + " 16 iload_1\n" + + " 17 invokestatic java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int) : void [32]\n" + + " 20 aload_2\n" + + " 21 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " \n" + + " // Method descriptor #39 (Ljava/lang/String;)Lp/X$1E;\n" + + " // Stack: 2, Locals: 1\n" + + " public static new p.X(){} valueOf(java.lang.String arg0);\n" + + " 0 ldc [1]\n" + + " 2 aload_0 [arg0]\n" + + " 3 invokestatic java.lang.Enum.valueOf(java.lang.Class, java.lang.String) : java.lang.Enum [40]\n" + + " 6 checkcast p.X$1E [1]\n" + + " 9 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #1 p/X$1E, outer class info: #0\n" + + " inner name: #54 E, accessflags: 17416 abstract static],\n" + + " [inner class info: #14 p/X$1E$1, outer class info: #0\n" + + " inner name: #0, accessflags: 16384 default]\n" + + " Enclosing Method: #48 #50 p/X.main([Ljava/lang/String;)V\n" + + "\n" + + "Nest Host: #48 p/X\n" + + "}"; + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"p" + File.separator + "X$1E.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation +public void test152() { + this.runConformTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum E implements Runnable {\n" + + " SUCCESS {};\n" + + " public void run(){}\n" + + " }\n" + + " System.out.println(E.SUCCESS);\n" + + " }\n" + + "}\n" + }, + "SUCCESS", + null, + false, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 +public void test153() { + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum TestEnum {\n" + + " RED, GREEN, BLUE; \n" + + " static int test = 0; \n" + + "\n" + + " TestEnum() {\n" + + " TestEnum.test=10;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 8)\n" + + " TestEnum.test=10;\n" + + " ^^^^\n" + + "Cannot refer to the static enum field TestEnum.test within an initializer\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test154() { + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum TestEnum2 {\n" + + " ; \n" + + " static int test = 0; \n" + + " TestEnum2() {\n" + + " TestEnum2.test=11;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + "class X {\n" + + " static int test = 0;\n" + + " X() {\n" + + " X.test = 13;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 7)\n" + + " TestEnum2.test=11;\n" + + " ^^^^\n" + + "Cannot refer to the static enum field TestEnum2.test within an initializer\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test155() { + this.runConformTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum TestEnum {\n" + + " RED, GREEN, BLUE; \n" + + " static int test = 0; \n" + + " }\n" + + "\n" + + " enum TestEnum2 {\n" + + " ; \n" + + " TestEnum2() {\n" + + " TestEnum.test=12;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test156() { + this.runConformTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum TestEnum {\n" + + " RED, GREEN, BLUE; \n" + + " static int test = 0; \n" + + "\n" + + " TestEnum() {\n" + + " new Object() {\n" + + " { TestEnum.test=10; }\n" + + " };\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test157() { + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum Foo {\n" + + " ONE, TWO, THREE;\n" + + " static int val = 10;\n" + + " Foo () {\n" + + " this(Foo.val);\n" + + " System.out.println(Foo.val);\n" + + " }\n" + + " Foo(int i){}\n" + + " {\n" + + " System.out.println(Foo.val);\n" + + " }\n" + + " int field = Foo.val;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 7)\n" + + " this(Foo.val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "2. ERROR in Y.java (at line 8)\n" + + " System.out.println(Foo.val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "3. ERROR in Y.java (at line 12)\n" + + " System.out.println(Foo.val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "4. ERROR in Y.java (at line 14)\n" + + " int field = Foo.val;\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test158() { + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum Foo {\n" + + " ONE, TWO, THREE;\n" + + " static int val = 10;\n" + + " Foo () {\n" + + " this(val);\n" + + " System.out.println(val);\n" + + " }\n" + + " Foo(int i){}\n" + + " {\n" + + " System.out.println(val);\n" + + " }\n" + + " int field = val;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 7)\n" + + " this(val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "2. ERROR in Y.java (at line 8)\n" + + " System.out.println(val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "3. ERROR in Y.java (at line 12)\n" + + " System.out.println(val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "4. ERROR in Y.java (at line 14)\n" + + " int field = val;\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test159() { + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum Foo {\n" + + " ONE, TWO, THREE;\n" + + " static int val = 10;\n" + + " Foo () {\n" + + " this(get().val);\n" + + " System.out.println(get().val);\n" + + " }\n" + + " Foo(int i){}\n" + + " {\n" + + " System.out.println(get().val);\n" + + " }\n" + + " int field = get().val;\n" + + " Foo get() { return ONE; }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 7)\n" + + " this(get().val);\n" + + " ^^^\n" + + "Cannot refer to an instance method while explicitly invoking a constructor\n" + + "----------\n" + + "2. WARNING in Y.java (at line 7)\n" + + " this(get().val);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "3. ERROR in Y.java (at line 7)\n" + + " this(get().val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "4. WARNING in Y.java (at line 8)\n" + + " System.out.println(get().val);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "5. ERROR in Y.java (at line 8)\n" + + " System.out.println(get().val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "6. WARNING in Y.java (at line 12)\n" + + " System.out.println(get().val);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "7. ERROR in Y.java (at line 12)\n" + + " System.out.println(get().val);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "8. WARNING in Y.java (at line 14)\n" + + " int field = get().val;\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "9. ERROR in Y.java (at line 14)\n" + + " int field = get().val;\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void test160() { + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum Foo {\n" + + " ONE, TWO, THREE;\n" + + " static int val = 10;\n" + + " Foo () {\n" + + " this(get().val = 1);\n" + + " System.out.println(get().val = 2);\n" + + " }\n" + + " Foo(int i){}\n" + + " {\n" + + " System.out.println(get().val = 3);\n" + + " }\n" + + " int field = get().val = 4;\n" + + " Foo get() { return ONE; }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 7)\n" + + " this(get().val = 1);\n" + + " ^^^\n" + + "Cannot refer to an instance method while explicitly invoking a constructor\n" + + "----------\n" + + "2. WARNING in Y.java (at line 7)\n" + + " this(get().val = 1);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "3. ERROR in Y.java (at line 7)\n" + + " this(get().val = 1);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "4. WARNING in Y.java (at line 8)\n" + + " System.out.println(get().val = 2);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "5. ERROR in Y.java (at line 8)\n" + + " System.out.println(get().val = 2);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "6. WARNING in Y.java (at line 12)\n" + + " System.out.println(get().val = 3);\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "7. ERROR in Y.java (at line 12)\n" + + " System.out.println(get().val = 3);\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n" + + "8. WARNING in Y.java (at line 14)\n" + + " int field = get().val = 4;\n" + + " ^^^\n" + + "The static field Foo.val should be accessed in a static way\n" + + "----------\n" + + "9. ERROR in Y.java (at line 14)\n" + + " int field = get().val = 4;\n" + + " ^^^\n" + + "Cannot refer to the static enum field Foo.val within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=228109 - variation +public void _NA_test161() { + this.runConformTest( + new String[] { + "LocalEnumTest1.java", + "enum LocalEnumTest1 {\n" + + " ;\n" + + " static int foo = LocalEnumTest2.bar;\n" + + "}\n" + + "enum LocalEnumTest2 {\n" + + " ;\n" + + " static int bar = LocalEnumTest1.foo;\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239225 +public void test162() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Status {\n" + + " GOOD((byte) 0x00), BAD((byte) 0x02);\n" + + "\n" + + " private static Map mapping;\n" + + "\n" + + " private Status(final byte newValue) {\n" + + "\n" + + " if (Status.mapping == null) {\n" + + " Status.mapping = new HashMap();\n" + + " }\n" + + "\n" + + " Status.mapping.put(newValue, this);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " if (Status.mapping == null) {\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " Status.mapping = new HashMap();\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n" + + "3. ERROR in X.java (at line 17)\n" + + " Status.mapping.put(newValue, this);\n" + + " ^^^^^^^\n" + + "Cannot refer to the static enum field Status.mapping within an initializer\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239225 - variation +public void test163() { + this.runConformTest( + new String[] { + "X.java", // ================= + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Status {\n" + + " GOOD((byte) 0x00), BAD((byte) 0x02);\n" + + " private byte value;\n" + + " private static Map mapping;\n" + + " private Status(final byte newValue) {\n" + + " this.value = newValue;\n" + + " }\n" + + " static {\n" + + " Status.mapping = new HashMap();\n" + + " for (Status s : values()) {\n" + + " Status.mapping.put(s.value, s);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251523 +public void test164() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " ;\n" + + " private Y valueOf(String arg0) { return null; }\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " private Y valueOf(String arg0) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum Y already defines the method valueOf(String) implicitly\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251523 - variation +public void test165() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "class Other {\n" + + " int dupField;//1\n" + + " int dupField;//2\n" + + " int dupField;//3\n" + + " int dupField;//4\n" + + " void dupMethod(int i) {}//5\n" + + " void dupMethod(int i) {}//6\n" + + " void dupMethod(int i) {}//7\n" + + " void dupMethod(int i) {}//8\n" + + " void foo() {\n" + + " int i = dupMethod(dupField);\n" + + " }\n" + + "}\n" + + "\n" + + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " ;\n" + + " private Y valueOf(String arg0) { return null; }//9\n" + + " private Y valueOf(String arg0) { return null; }//10\n" + + " private Y valueOf(String arg0) { return null; }//11\n" + + " void foo() {\n" + + " int i = valueOf(\"\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int dupField;//1\n" + + " ^^^^^^^^\n" + + "Duplicate field Other.dupField\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " int dupField;//2\n" + + " ^^^^^^^^\n" + + "Duplicate field Other.dupField\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " int dupField;//3\n" + + " ^^^^^^^^\n" + + "Duplicate field Other.dupField\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " int dupField;//4\n" + + " ^^^^^^^^\n" + + "Duplicate field Other.dupField\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " void dupMethod(int i) {}//5\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Duplicate method dupMethod(int) in type Other\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " void dupMethod(int i) {}//6\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Duplicate method dupMethod(int) in type Other\n" + + "----------\n" + + "7. ERROR in X.java (at line 8)\n" + + " void dupMethod(int i) {}//7\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Duplicate method dupMethod(int) in type Other\n" + + "----------\n" + + "8. ERROR in X.java (at line 9)\n" + + " void dupMethod(int i) {}//8\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Duplicate method dupMethod(int) in type Other\n" + + "----------\n" + + "9. ERROR in X.java (at line 11)\n" + + " int i = dupMethod(dupField);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from void to int\n" + + "----------\n" + + "10. ERROR in X.java (at line 19)\n" + + " private Y valueOf(String arg0) { return null; }//9\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum Y already defines the method valueOf(String) implicitly\n" + + "----------\n" + + "11. ERROR in X.java (at line 20)\n" + + " private Y valueOf(String arg0) { return null; }//10\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum Y already defines the method valueOf(String) implicitly\n" + + "----------\n" + + "12. ERROR in X.java (at line 21)\n" + + " private Y valueOf(String arg0) { return null; }//11\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum Y already defines the method valueOf(String) implicitly\n" + + "----------\n" + + "13. ERROR in X.java (at line 23)\n" + + " int i = valueOf(\"\");\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to int\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251814 +public void test166() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " ;\n" + + " private int valueOf(String arg0) { return 0; }//11\n" + + " void foo() {\n" + + " int i = valueOf(\"\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " private int valueOf(String arg0) { return 0; }//11\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum Y already defines the method valueOf(String) implicitly\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " int i = valueOf(\"\");\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to int\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + // check for presence of #valueOf(...) in problem type + String expectedPartialOutput = + " public static void main(java.lang.String[] arg0);\n" + + " 0 new java.lang.Error [16]\n" + + " 3 dup\n" + + " 4 ldc [18]\n" + + " 6 invokespecial java.lang.Error(java.lang.String) [20]\n" + + " 9 athrow\n" ; + verifyClassFile(expectedPartialOutput, "X.class", ClassFileBytesDisassembler.SYSTEM, true); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251814 - variation +public void test167() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Y {\n" + + " ;\n" + + " static int valueOf(String arg0) { return 0; }//9\n" + + " void foo() {\n" + + " int i = Y.valueOf(\"\");\n" + + " }\n" + + " }\n" + + " class Other {\n" + + " void foo() {\n" + + " int i = Y.valueOf(\"\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static int valueOf(String arg0) { return 0; }//9\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The enum Y already defines the method valueOf(String) implicitly\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " int i = Y.valueOf(\"\");\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to int\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " int i = Y.valueOf(\"\");\n" + + " ^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Y to int\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255452 +public void test168() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum BadEnum {\n" + + " CRAZY(CRAZY), // <-- illegal forward reference reported by all compilers\n" + + " IMPOSSIBLE(BadEnum.IMPOSSIBLE); // <-- illegal forward reference (javac 1.6 only)\n" + + " private BadEnum(BadEnum self) {\n" + + " }\n" + + " }\n" + + " class A {\n" + + " A x1 = new A(x1);//1 - WRONG\n" + + " static A X2 = new A(A.X2);//2 - OK\n" + + " A x3 = new A(this.x3);//3 - OK\n" + + " A(A x) {}\n" + + " A(int i) {}\n" + + " int VALUE() { return 13; }\n" + + " int value() { return 14; }\n" + + " }\n" + + " class Y extends A {\n" + + " A x1 = new A(x1);//6 - WRONG\n" + + " static A X2 = new A(Y.X2);//7 - OK\n" + + " A x3 = new A(this.x3);//8 - OK\n" + + " Y(Y y) { super(y); }\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " CRAZY(CRAZY), // <-- illegal forward reference reported by all compilers\n" + + " ^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " IMPOSSIBLE(BadEnum.IMPOSSIBLE); // <-- illegal forward reference (javac 1.6 only)\n" + + " ^^^^^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " A x1 = new A(x1);//1 - WRONG\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "4. WARNING in X.java (at line 19)\n" + + " A x1 = new A(x1);//6 - WRONG\n" + + " ^^\n" + + "The field Y.x1 is hiding a field from type A\n" + + "----------\n" + + "5. ERROR in X.java (at line 19)\n" + + " A x1 = new A(x1);//6 - WRONG\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "6. WARNING in X.java (at line 20)\n" + + " static A X2 = new A(Y.X2);//7 - OK\n" + + " ^^\n" + + "The field Y.X2 is hiding a field from type A\n" + + "----------\n" + + "7. WARNING in X.java (at line 21)\n" + + " A x3 = new A(this.x3);//8 - OK\n" + + " ^^\n" + + "The field Y.x3 is hiding a field from type A\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255452 - variation +public void test169() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum BadEnum {\n" + + " NOWAY(BadEnum.NOWAY.CONST),\n" + + " INVALID(INVALID.CONST),\n" + + " WRONG(WRONG.VALUE()),\n" + + " ILLEGAL(ILLEGAL.value());\n" + + " final static int CONST = 12;\n" + + " private BadEnum(int i) {\n" + + " }\n" + + " int VALUE() { return 13; }\n" + + " int value() { return 14; }\n" + + " }\n" + + " class Y {\n" + + " final static int CONST = 12;\n" + + " Y x4 = new Y(x4.CONST);//4 - WRONG\n" + + " Y x5 = new Y(x5.value());//5 - WRONG\n" + + " Y(int i) {}\n" + + " int VALUE() { return 13; }\n" + + " int value() { return 14; }\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " NOWAY(BadEnum.NOWAY.CONST),\n" + + " ^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " NOWAY(BadEnum.NOWAY.CONST),\n" + + " ^^^^^\n" + + "The static field BadEnum.CONST should be accessed in a static way\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " INVALID(INVALID.CONST),\n" + + " ^^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " INVALID(INVALID.CONST),\n" + + " ^^^^^\n" + + "The static field BadEnum.CONST should be accessed in a static way\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " WRONG(WRONG.VALUE()),\n" + + " ^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " ILLEGAL(ILLEGAL.value());\n" + + " ^^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "7. ERROR in X.java (at line 16)\n" + + " Y x4 = new Y(x4.CONST);//4 - WRONG\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "8. WARNING in X.java (at line 16)\n" + + " Y x4 = new Y(x4.CONST);//4 - WRONG\n" + + " ^^^^^\n" + + "The static field Y.CONST should be accessed in a static way\n" + + "----------\n" + + "9. ERROR in X.java (at line 17)\n" + + " Y x5 = new Y(x5.value());//5 - WRONG\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=263877 +public void test170() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " public static final int FOO = X.OFFSET + 0;\n" + + " public static final int BAR = OFFSET + 1;\n" + + " public static final int OFFSET = 0; // cannot move this above, else more errors\n" + + " public static void main(String[] args) {\n" + + " enum Days {\n" + + " Monday(\"Mon\", Days.OFFSET + 0), // should not complain\n" + + " Tuesday(\"Tue\", Days.Wednesday.hashCode()), // should complain since enum constant\n" + + " Wednesday(\"Wed\", OFFSET + 2); // should complain since unqualified\n" + + " public static final int OFFSET = 0; // cannot move this above, else more errors\n" + + " Days(String abbr, int index) {\n" + + " }\n" + + " }\n" + + "\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public static final int BAR = OFFSET + 1;\n" + + " ^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Tuesday(\"Tue\", Days.Wednesday.hashCode()), // should complain since enum constant\n" + + " ^^^^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Wednesday(\"Wed\", OFFSET + 2); // should complain since unqualified\n" + + " ^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " public static final int OFFSET = 0; // cannot move this above, else more errors\n" + + " ^^^^^^\n" + + "The field Days.OFFSET is hiding a field from type X\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=267670. Make sure we don't emit any unused +// warnings about enumerators. Since these could be used in indirect ways not obvious. +public void test171() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Colors {\n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE\n" + + " }\n" + + " for (Colors c: Colors.values()) {\n" + + " System.out.print(c);\n" + + " }\n" + + " }\n" + + "}\n" + }, + null, options, + "", + "BLEUBLANCROUGE", null, null); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=267670. Make sure we don't emit any unused +// warnings about enumerators. Since these could be used in indirect ways not obvious. This +// test also verifies that while we don't complain about individual enumerators not being used +// we DO complain if the enumeration type itself is not used. +public void test172() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum Greet {\n" + + " HELLO, HOWDY, BONJOUR; \n" + + " }\n" + + " enum Colors {\n" + + " RED, BLACK, BLUE;\n"+ + " }\n" + + " enum Complaint {" + + " WARNING, ERROR, FATAL_ERROR, PANIC;\n" + + " }\n" + + " Greet g = Greet.valueOf(\"HELLO\");\n" + + " System.out.print(g);\n" + + " Colors c = Enum.valueOf(Colors.class, \"RED\");\n" + + " System.out.print(c);\n" + + " }\n" + + "}\n" + }, + null, customOptions, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " enum Complaint { WARNING, ERROR, FATAL_ERROR, PANIC;\n" + + " ^^^^^^^^^\n" + + "The type Complaint is never used locally\n" + + "----------\n", + "HELLORED", null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=273990 +public void test173() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public static void main(String[] args) {\n" + + " enum E {\n" + + " A(E.STATIK);\n" + + " private static int STATIK = 1;\n" + + " private E(final int i) {}\n" + + " }\n" + + " enum E2 {\n" + + " A(E2.STATIK);\n" + + " static int STATIK = 1;\n" + + " private E2(final int i) {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A(E.STATIK);\n" + + " ^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " A(E2.STATIK);\n" + + " ^^^^^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=278562 +public void test174() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " interface S {}\n" + + " enum A implements S {\n" + + " L;\n" + + " }\n" + + " Enum enumConstant = A.L;\n" + + " Map m = new HashMap<>();\n" + + " for (Enum e : enumConstant.getDeclaringClass().getEnumConstants()) {\n" + + " m.put(e.name(), e);\n" + + " }\n" + + " System.out.print(1);\n" + + " }\n" + + "}\n" + }, + "1" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=278562 +public void test175() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " interface S {}\n" + + " enum A implements S {\n" + + " L, M, N, O;\n" + + " }\n" + + " Enum[] tab = new Enum[] {A.L, A.M, A.N, A.O};\n" + + " Map m = new HashMap();\n" + + " for (Enum s : tab) {\n" + + " m.put(s.name(), s);\n" + + " }\n" + + " System.out.print(1);\n" + + " }\n" + + "}\n" + }, + "1" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285701 +public void test176() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " enum Y {\n" + + " A(\"\"), B(\"SUCCESS\"), C(\"Hello\");\n" + + "\n" + + " String message;\n" + + "\n" + + " Y(@Deprecated String s) {\n" + + " this.message = s;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return this.message;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "" + ); + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + false, + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " enum Y {\n" + + " A(\"\"), B(\"SUCCESS\"), C(\"Hello\");\n" + + "\n" + + " String message;\n" + + "\n" + + " Y(@Deprecated String s) {\n" + + " this.message = s;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return this.message;\n" + + " }\n" + + " }\n" + + " System.out.println(Y.B);\n" + + " }\n" + + "}\n" + }, + null, + options, + "", + "SUCCESS", + "", + JavacTestOptions.Excuse.JavacHasWarningsEclipseNotConfigured); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285701 +public void test177() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " enum Y {\n" + + " A(\"\", 0, \"A\"), B(\"SUCCESS\", 0, \"B\"), C(\"Hello\", 0, \"C\");\n" + + "\n" + + " private String message;\n" + + " private int index;\n" + + " private String name;\n" + + "\n" + + " Y(@Deprecated String s, int i, @Deprecated String name) {\n" + + " this.message = s;\n" + + " this.index = i;\n" + + " this.name = name;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return this.message + this.name;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "" + ); + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + false, + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " enum Y {\n" + + " A(\"\", 0, \"A\"), B(\"SUCCESS\", 0, \"B\"), C(\"Hello\", 0, \"C\");\n" + + "\n" + + " private String message;\n" + + " private int index;\n" + + " private String name;\n" + + "\n" + + " Y(@Deprecated String s, int i, @Deprecated String name) {\n" + + " this.message = s;\n" + + " this.index = i;\n" + + " this.name = name;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return this.message + this.name;\n" + + " }\n" + + " }\n" + + " System.out.println(Y.B);\n" + + " }\n" + + "}\n" + }, + null, + options, + "", + "SUCCESSB", + "", + JavacTestOptions.Excuse.JavacHasWarningsEclipseNotConfigured); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285701 +// static local enums are not allowed. Removing static is the same as test177 +public void _NA_test178() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static enum Y {\n" + + " A(\"\", 0, \"A\"), B(\"SUCCESS\", 0, \"B\"), C(\"Hello\", 0, \"C\");\n" + + " \n" + + " private String message;\n" + + " private int index;\n" + + " private String name;\n" + + " Y(@Deprecated String s, int i, @Deprecated String name) {\n" + + " this.message = s;\n" + + " this.index = i;\n" + + " this.name = name;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return this.message + this.name;\n" + + " }\n" + + " }\n" + + "}" + }, + "" + ); + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + false, + new String[] { + "Z.java", + "public class Z {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.Y.B);\n" + + " }\n" + + "}" + }, + null, + options, + "", + "SUCCESSB", + "", + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285701 +public void test179() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + false, + new String[] { + "Z.java", + "public class Z {\n" + + " public static void main(String[] args) {\n" + + " class X {\n" + + " enum Y {\n" + + " A(\"\", 0, \"A\"), B(\"SUCCESS\", 0, \"B\"), C(\"Hello\", 0, \"C\");\n" + + " \n" + + " private String message;\n" + + " private int index;\n" + + " private String name;\n" + + " Y(@Deprecated String s, int i, @Deprecated String name) {\n" + + " this.message = s;\n" + + " this.index = i;\n" + + " this.name = name;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return this.message + this.name;\n" + + " }\n" + + " }\n" + + " }\n" + + " System.out.println(X.Y.B);\n" + + " }\n" + + "}" + }, + null, + options, + "", + "SUCCESSB", + "", + JavacTestOptions.Excuse.JavacHasWarningsEclipseNotConfigured); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=289892 +public void test180() { + this.runConformTest( + new String[] { + "p/package-info.java", + "@p.Annot(state=p.MyEnum.BROKEN)\n" + + "package p;", + "p/Annot.java", + "package p;\n" + + "@Annot(state=MyEnum.KO)\n" + + "public @interface Annot {\n" + + " MyEnum state() default MyEnum.KO;\n" + + "}", + "p/MyEnum.java", + "package p;\n" + + "@Annot(state=MyEnum.KO)\n" + + "public enum MyEnum {\n" + + " WORKS, OK, KO, BROKEN, ;\n" + + "}", + }, + "" + ); + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + false, + new String[] { + "X.java", + "import p.MyEnum;\n" + + "import p.Annot;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " @Annot(state=MyEnum.KO)\n" + + " enum LocalEnum {\n" + + " A, B, ;\n" + + " }\n" + + " System.out.print(LocalEnum.class);\n" + + " }\n" + + "}" + }, + null, + options, + "", + "class X$1LocalEnum", + "", + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=289892 +// in interaction with null annotations +// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=365519#c4 item (6) +public void test180a() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + this.runConformTest( + new String[] { + "p/package-info.java", + "@p.Annot(state=p.MyEnum.BROKEN)\n" + + "package p;", + "p/Annot.java", + "package p;\n" + + "@Annot(state=MyEnum.KO)\n" + + "public @interface Annot {\n" + + " MyEnum state() default MyEnum.KO;\n" + + "}", + "p/MyEnum.java", + "package p;\n" + + "@Annot(state=MyEnum.KO)\n" + + "public enum MyEnum {\n" + + " WORKS, OK, KO, BROKEN, ;\n" + + "}", + }, + "", + null, + true, + null, + options, + null + ); + options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + this.runConformTest( + false, + new String[] { + "X.java", + "import p.MyEnum;\n" + + "import p.Annot;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " @Annot(state=MyEnum.OK)\n" + + " enum LocalEnum {\n" + + " A, B, ;\n" + + " }\n" + + " System.out.print(LocalEnum.class);\n" + + " }\n" + + "}" + }, + null, + options, + "", + "class X$1LocalEnum", + "", + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=300133 +public void test181() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest( + new String[] { + "B.java", + "public class B {\n" + + " enum X {\n" + + " A {\n" + + " @Override\n" + + " public Object foo(final String s) {\n" + + " class Local {\n" + + " public String toString() {\n" + + " return s;\n" + + " }\n" + + " }\n" + + " return new Local();\n" + + " }\n" + + " };\n" + + " public abstract Object foo(String s);\n" + + " }\n" + + " public static void main(String... args) {\n" + + " System.out.println(X.A.foo(\"SUCCESS\"));\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test182() throws Exception { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " enum E {\n" + + " a1(1), a2(2);\n" + + " static int[] VALUES = { 1, 2 };\n" + + " private int value;\n" + + " E(int v) {\n" + + " this.value = v;\n" + + " }\n" + + " public int val() {\n" + + " return this.value;\n" + + " }\n" + + " }\n" + + " int n = 0;\n" + + " for (E e : E.values()) {\n" + + " if (e.val() == E.VALUES[n++] ) {\n" + + " System.out.print(e.val());\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "12", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test183() throws Exception { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " }\n" + + " static {\n" + + " enum E {\n" + + " a1(1), a2(2);\n" + + " static int[] VALUES = { 1, 2 };\n" + + " private int value;\n" + + " E(int v) {\n" + + " this.value = v;\n" + + " }\n" + + " public int val() {\n" + + " return this.value;\n" + + " }\n" + + " }\n" + + " int n = 0;\n" + + " for (E e : E.values()) {\n" + + " if (e.val() == E.VALUES[n++] ) {\n" + + " System.out.print(e.val());\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + + }, + "12", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test184() throws Exception { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new X();\n" + + " }\n" + + " X() {\n" + + " enum E {\n" + + " a1(1), a2(2);\n" + + " static int[] VALUES = { 1, 2 };\n" + + " private int value;\n" + + " E(int v) {\n" + + " this.value = v;\n" + + " }\n" + + " public int val() {\n" + + " return this.value;\n" + + " }\n" + + " }\n" + + " int n = 0;\n" + + " for (E e : E.values()) {\n" + + " if (e.val() == E.VALUES[n++] ) {\n" + + " System.out.print(e.val());\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "12", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id= +public void test185() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X{\n" + + " public static void main(String argv[]) {\n" + + " enum Y{\n" + + " A, B;\n" + + " private Y() throws Exception {\n" + + " }\n" + + " }\n"+ + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " A, B;\n" + + " ^\n" + + "Unhandled exception type Exception\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " A, B;\n" + + " ^\n" + + "Unhandled exception type Exception\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test186() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_MISSING_ENUM_CASE_DESPITE_DEFAULT, JavaCore.ENABLED); + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " void _test(boolean val) {\n" + + " enum X {\n" + + " A, B;\n" + + " }\n" + + " X x= val? X.A : X.B;\n" + + " switch (x) {\n" + + " case A: System.out.println(\"A\"); break;\n" + + " default : System.out.println(\"unknown\"); break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 7)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant B should have a corresponding case label in this enum switch on X. To suppress this problem, add a comment //$CASES-OMITTED$ on the line above the 'default:'\n" + + "----------\n", + null, // classlibs + true, // flush + options, // customOptions + false /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + false /* performStatementsRecovery */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test187() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_MISSING_ENUM_CASE_DESPITE_DEFAULT, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_INCOMPLETE_ENUM_SWITCH, JavaCore.ERROR); + this.runConformTest( + new String[] { + "Y.java", + "public class Y {\n" + + " void _test(boolean val) {\n" + + " enum X {\n" + + " A, B;\n" + + " }\n" + + " X x= val? X.A : X.B;\n" + + " switch (x) {\n" + + " case A: System.out.println(\"A\");\n" + + " //$FALL-THROUGH$\n" + + " //$CASES-OMITTED$\n" + + " default : System.out.println(\"unknown\"); break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, // classlibs + true, // flush + null, // vmArgs + options, + null /*requestor*/); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test187a() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_MISSING_ENUM_CASE_DESPITE_DEFAULT, JavaCore.ENABLED); + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " void _test(boolean val) {\n" + + " enum X {\n" + + " A, B;\n" + + " }\n" + + " X x= val? X.A : X.B;\n" + + " switch (x) {\n" + + " case A: System.out.println(\"A\"); break;\n" + + " //$CASES-OMITTED$\n" + // not strong enough to suppress the warning if default: is missing + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 7)\n" + + " switch (x) {\n" + + " ^\n" + + "The enum constant B needs a corresponding case label in this enum switch on X\n" + + "----------\n", + null, // classlibs + true, // flush + options, // customOptions + false /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + false /* performStatementsRecovery */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test187b() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + this.runConformTest( + new String[] { + "Y.java", + "public class Y {\n" + + " @SuppressWarnings(\"incomplete-switch\")\n" + + " void _test(boolean val) {\n" + + " enum X {\n" + + " A, B;\n" + + " }\n" + + " X x= val? X.A : X.B;\n" + + " switch (x) {\n" + + " case A: System.out.println(\"A\"); break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, // classlibs + true, // flush + null, // vmArgs + options, + null /*requestor*/); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test188() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE, JavaCore.WARNING); + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " void _test(boolean val) {\n" + + " enum X {\n" + + " A, B;\n" + + " }\n" + + " X x= val? X.A : X.B;\n" + + " switch (x) {\n" + + " case A: System.out.println(\"A\"); break;\n" + + " case B: System.out.println(\"B\"); break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in Y.java (at line 7)\n" + + " switch (x) {\n" + + " ^\n" + + "The switch over the enum type X should have a default case\n" + + "----------\n", + null, // classlibs + true, // flush + options, // customOptions + false /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + false /* performStatementsRecovery */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=374605 +public void test189() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map options = getCompilerOptions(); + //options.put(JavaCore.COMPILER_PB_MISSING_DEFAULT_CASE, JavaCore.WARNING); + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {\n" + + " public int test(boolean val) {\n" + + " enum X {\n" + + " A, B;\n" + + " }\n" + + " X x= val? X.A : X.B;\n" + + " switch (x) {\n" + + " case A: return 1;\n" + + " case B: return 2;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Y.java (at line 2)\n" + + " public int test(boolean val) {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "This method must return a result of type int. Note that a problem regarding missing 'default:' on 'switch' has been suppressed, which is perhaps related to this problem\n" + + "----------\n", + null, // classlibs + true, // flush + options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433060 [1.8][compiler] enum E{I;} causes NPE in AllocationExpression.checkTypeArgumentRedundancy +public void test433060() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_REDUNDANT_TYPE_ARGUMENTS, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y{\n" + + " public static void main(String argv[]) {\n" + + " enum X {\n" + + " OBJ;\n" + + " }\n" + + " }\n" + + "}" + + }, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " enum X {\n" + + " ^\n" + + "Syntax error, enum declaration cannot have type parameters\n" + + "----------\n", + null, + true, + options); +} +public void test434442() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest(new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum Letter {\n" + + " A, B;\n" + + " }\n" + + " interface I {\n" + + " public default void test(Letter letter) {\n" + + " switch (letter) {\n" + + " case A:\n" + + " System.out.print(\"A\");\n" + + " break;\n" + + " case B:\n" + + " System.out.print(\"B\");\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + " class X implements I {\n" + + " }\n" + + " try{\n" + + " X x = new X();\n" + + " x.test(Letter.A);\n" + + " }\n" + + " catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "} \n" + + "\n" + }, "A"); +} +public void test476281() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest(new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum LambdaEnumLocalClassBug {\n" + + " A(() -> {\n" + + " class Foo {\n" + + " }\n" + + " new Foo();\n" + + " System.out.println(\"Success\");\n" + + " })\n" + + " ;\n" + + " private final Runnable runnable;\n" + + " private LambdaEnumLocalClassBug(Runnable runnable) {\n" + + " this.runnable = runnable;\n" + + " }\n" + + " }\n" + + " LambdaEnumLocalClassBug.A.runnable.run();\n" + + " }\n" + + "} \n" + }, + "Success"); +} +public void test476281a() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runConformTest(new String[] { + "Y.java", + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " enum Test {\n" + + " B(new Runnable() {\n" + + " public void run() {\n" + + " //\n" + + " class Foo {\n" + + " \n" + + " }\n" + + " new Foo();\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + " });\n" + + " private final Runnable runnable;\n" + + " private Test(Runnable runnable) {\n" + + " this.runnable = runnable;\n" + + " }\n" + + " }\n" + + " Test.B.runnable.run();\n" + + " }\n" + + "} \n" + }, + "Success"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=566758 +public void test566758() { + if(this.complianceLevel < ClassFileConstants.JDK1_6) { + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void m(T t) {\n" + + " interface Y {\n" + + " T foo(); // T should not be allowed\n" + + " }\n" + + " }\n" + + " \n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " T foo(); // T should not be allowed\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n", + null, + true); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest.java new file mode 100644 index 0000000000..ef3cf01d7f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest.java @@ -0,0 +1,1710 @@ +/******************************************************************************* + * Copyright (c) 2020, 2021 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.core.util.ClassFormatException; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class LocalStaticsTest extends AbstractRegressionTest { + + static { +// TESTS_NUMBERS = new int [] { 40 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] { "testBug569444_001"}; + } + + public static Class testClass() { + return LocalStaticsTest.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_16); + } + public LocalStaticsTest(String testName){ + super(testName); + } + + // Enables the tests to run individually + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16); // FIXME + defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16); + defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16); + defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + return defaultOptions; + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput) { + runConformTest(testFiles, expectedOutput, getCompilerOptions()); + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedOutputString = expectedOutput; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.customOptions = customOptions; + runner.runConformTest(); + } + @Override + protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) { + runNegativeTest(testFiles, expectedCompilerLog, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog) { + runWarningTest(testFiles, expectedCompilerLog, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, Map customOptions) { + runWarningTest(testFiles, expectedCompilerLog, customOptions, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, + Map customOptions, String javacAdditionalTestOptions) { + + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedCompilerLog; + runner.customOptions = customOptions; + runner.runWarningTest(); + } + + private static void verifyClassFile(String expectedOutput, String classFileName) + throws IOException, ClassFormatException { + String result = getClassfileContent(classFileName); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + System.out.println("..."); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + private static String getClassfileContent(String classFileName) throws IOException, ClassFormatException { + File f = new File(OUTPUT_DIR + File.separator + classFileName); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.SYSTEM); + return result; + } + + public void testBug566284_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo() {\n"+ + " interface F {\n"+ + " static int create(int lo) {\n"+ + " I myI = s -> lo;\n"+ + " return myI.bar(0);\n"+ + " }\n"+ + " }\n"+ + " System.out.println(F.create(0));\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo();\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "interface I {\n"+ + " int bar(int l);\n"+ + "}" + }, + "0"); + } + + + public void testBug566284_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo() {\n"+ + " record R() {\n"+ + " static int create(int lo) {\n"+ + " I myI = s -> lo;\n"+ + " return myI.bar(0);\n"+ + " }\n"+ + " }\n"+ + " System.out.println(R.create(0));\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo();\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "interface I {\n"+ + " int bar(int l);\n"+ + "}" + }, + "0"); + } + public void testBug566284_003() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " static int si;\n"+ + " int nsi;\n"+ + "\n"+ + " void m() {\n"+ + " int li;\n"+ + "\n"+ + " interface F {\n"+ + " static int fi = 0;\n"+ + "\n"+ + " default void foo(int i) {\n"+ + " System.out.println(li); // error, local variable of method of outer enclosing class\n"+ + " System.out.println(nsi); // error, non-static member\n"+ + " System.out.println(fi); // ok, static member of current class\n"+ + " System.out.println(si); // ok, static member of enclosing class\n"+ + " System.out.println(i); // ok, local variable of current method\n"+ + " }\n"+ + "\n"+ + " static void bar(int lo) {\n"+ + " int k = lo; // ok\n"+ + " int j = fi; // ok\n"+ + " I myI = s -> lo; // ok, local var of method\n"+ + " }\n"+ + "\n"+ + " static void bar2(int lo) {\n"+ + " I myI = s -> li; // error - local var of outer class\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "interface I {\n"+ + " int bar(int l);\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " System.out.println(li); // error, local variable of method of outer enclosing class\n" + + " ^^\n" + + "Cannot make a static reference to the non-static variable li\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " System.out.println(nsi); // error, non-static member\n" + + " ^^^\n" + + "Cannot make a static reference to the non-static field nsi\n" + + "----------\n" + + "3. ERROR in X.java (at line 26)\n" + + " I myI = s -> li; // error - local var of outer class\n" + + " ^^\n" + + "Cannot make a static reference to the non-static variable li\n" + + "----------\n" + ); + } + + public void testBug566518_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo() {\n"+ + " int f = switch (5) {\n"+ + " case 5: {\n"+ + " interface I{\n"+ + " \n"+ + " }\n"+ + " class C implements I{\n"+ + " public int j = 5;\n"+ + " }\n"+ + " \n"+ + " yield new C().j;\n"+ + " }\n"+ + " default:\n"+ + " throw new IllegalArgumentException(\"Unexpected value: \" );\n"+ + " };\n"+ + " System.out.println(f);\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo();\n"+ + " }\n"+ + "}" + }, + "5"); + } + + public void testBug566518_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo() {\n"+ + " class F {\n"+ + " int create(int lo) {\n"+ + " I myI = s -> lo;\n"+ + " return myI.bar(0);\n"+ + " }\n"+ + " }\n"+ + " System.out.println(new F().create(0));\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo();\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "interface I {\n"+ + " int bar(int l);\n"+ + "}" + }, + "0"); + } + + public void testBug566518_003() { + runConformTest( + new String[] { + "X.java", + "public interface X {\n"+ + " static void foo() {\n"+ + " class F {\n"+ + " int create(int lo) {\n"+ + " I myI = s -> lo;\n"+ + " return myI.bar(0);\n"+ + " }\n"+ + " }\n"+ + " System.out.println(new F().create(0));\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo();\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "interface I {\n"+ + " int bar(int l);\n"+ + "}" + }, + "0"); + } + + public void testBug566518_004() { + runConformTest( + new String[] { + "X.java", + "public interface X {\n"+ + " static void foo() {\n"+ + " interface F {\n"+ + " static int create(int lo) {\n"+ + " I myI = s -> lo;\n"+ + " return myI.bar(0);\n"+ + " }\n"+ + " }\n"+ + " System.out.println(F.create(0));\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo();\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "interface I {\n"+ + " int bar(int l);\n"+ + "}" + }, + "0"); + } + + public void testBug566518_005() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo() {\n"+ + " int f = switch (5) {\n"+ + " case 5: {\n"+ + " interface I{\n"+ + " \n"+ + " }\n"+ + " class C implements I{\n"+ + " public int j = 5;\n"+ + " }\n"+ + " \n"+ + " yield new C().j;\n"+ + " }\n"+ + " default:\n"+ + " throw new IllegalArgumentException(\"Unexpected value: \" );\n"+ + " };\n"+ + " System.out.println(f);\n"+ + " class C1 implements I{\n"+ + " public int j = 5;\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo();\n"+ + " }\n"+ + "}\n" + }, + "----------\n"+ + "1. ERROR in X.java (at line 18)\n"+ + " class C1 implements I{\n"+ + " ^\n" + + "I cannot be resolved to a type\n"+ + "----------\n" + ); + } + + public void testBug566518_006() { + runConformTest( + new String[] { + "X.java", + "public enum X {\n"+ + " A, B, C;\n"+ + " public void foo() {\n"+ + " int f = switch (5) {\n"+ + " case 5: {\n"+ + " interface I{\n"+ + " \n"+ + " }\n"+ + " class C implements I{\n"+ + " public int j = 5;\n"+ + " }\n"+ + " \n"+ + " yield new C().j;\n"+ + " }\n"+ + " default:\n"+ + " throw new IllegalArgumentException(\"Unexpected value: \" );\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X x = X.A;\n"+ + " System.out.println();\n"+ + " }\n"+ + "}" + }, + ""); + } + // 6.5.5.1 + public void testBug566715_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo() {\n"+ + " interface I {\n"+ + " X supply();\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "----------\n"+ + "1. WARNING in X.java (at line 3)\n" + + " interface I {\n" + + " ^\n" + + "The type I is never used locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " X supply();\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + ); + } + // 6.5.5.1 + public void testBug566715_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " void foo() {\n"+ + " interface I {\n"+ + " X supply();\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "----------\n"+ + "1. WARNING in X.java (at line 3)\n" + + " interface I {\n" + + " ^\n" + + "The type I is never used locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " X supply();\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + ); + } + // 6.5.5.1 + public void testBug566715_003() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " void foo() {\n"+ + " record R(X x) {}\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " record R(X x) {}\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + ); + } + // 9.1.1/14.3 + public void testBug566720_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " void foo() {\n"+ + " public interface I {}\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public interface I {}\n" + + " ^\n" + + "Illegal modifier for the local interface I; abstract and strictfp are the only modifiers allowed explicitly \n" + + "----------\n" + ); + } + // 9.1.1/14.3 + public void testBug566720_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " void foo() {\n"+ + " private interface I {}\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private interface I {}\n" + + " ^\n" + + "Illegal modifier for the local interface I; abstract and strictfp are the only modifiers allowed explicitly \n" + + "----------\n" + ); + } + // 9.1.1 + public void testBug566720_003() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " void foo() {\n"+ + " protected interface I {}\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " protected interface I {}\n" + + " ^\n" + + "Illegal modifier for the local interface I; abstract and strictfp are the only modifiers allowed explicitly \n" + + "----------\n" + ); + } + // 9.1.1 + public void testBug566720_004() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " void foo() {\n"+ + " final interface I {}\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " final interface I {}\n" + + " ^\n" + + "Illegal modifier for the local interface I; abstract and strictfp are the only modifiers allowed explicitly \n" + + "----------\n" + ); + } + // 9.1.1 + public void testBug566720_005() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " static interface I {}\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " static interface I {}\n" + + " ^\n" + + "Illegal modifier for the local interface I; abstract and strictfp are the only modifiers allowed explicitly \n" + + "----------\n"); + } + public void testBug566748_001() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " int count;\n"+ + " void doNothing() {}\n"+ + " void foo1(String s) {\n"+ + " int i;\n"+ + " interface I {\n"+ + " default X bar() {\n"+ + " if (count > 0 || i > 0 || s == null)\n"+ + " return null;\n"+ + " doNothing();\n"+ + " return null;\n"+ + " }\n"+ + " } \n"+ + " }\n"+ + " void foo2(String s) {\n"+ + " try {\n"+ + " throw new Exception();\n"+ + " } catch (Exception e) {\n"+ + " interface I {\n"+ + " default int bar() {\n"+ + " return e != null ? 0 : 1;\n"+ + " }\n"+ + " } \n"+ + " \n"+ + " }\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " interface I {\n" + + " ^\n" + + "The type I is never used locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " default X bar() {\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " if (count > 0 || i > 0 || s == null)\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static field count\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " if (count > 0 || i > 0 || s == null)\n" + + " ^\n" + + "Cannot make a static reference to the non-static variable i\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " if (count > 0 || i > 0 || s == null)\n" + + " ^\n" + + "Cannot make a static reference to the non-static variable s\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " doNothing();\n" + + " ^^^^^^^^^\n" + + "Cannot make a static reference to the non-static method doNothing() from the type X\n" + + "----------\n" + + "7. WARNING in X.java (at line 19)\n" + + " interface I {\n" + + " ^\n" + + "The type I is never used locally\n" + + "----------\n" + + "8. ERROR in X.java (at line 21)\n" + + " return e != null ? 0 : 1;\n" + + " ^\n" + + "Cannot make a static reference to the non-static variable e\n" + + "----------\n" + ); + } + public void testBug566748_002() { + runNegativeTest( + new String[] { + "X.java", + "interface X {\n"+ + " int count = 0;\n"+ + "\n"+ + " default void doNothing() {}\n"+ + "\n"+ + " default void foo1(String s) {\n"+ + " int i;\n"+ + " interface I {\n"+ + " default X bar() {\n"+ + " if (count > 0 || i > 0 || s == null)\n"+ + " return null;\n"+ + " doNothing();\n"+ + " return null;\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " default void foo2(String s) {\n"+ + " try {\n"+ + " throw new Exception();\n"+ + " } catch (Exception e) {\n"+ + " interface I { \n"+ + " default int bar() {\n"+ + " return e != null ? 0 : 1;\n"+ + " } \n"+ + " } \n"+ + " \n"+ + " } \n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " interface I {\n" + + " ^\n" + + "The type I is never used locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " default X bar() {\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " if (count > 0 || i > 0 || s == null)\n" + + " ^\n" + + "Cannot make a static reference to the non-static variable i\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " if (count > 0 || i > 0 || s == null)\n" + + " ^\n" + + "Cannot make a static reference to the non-static variable s\n" + + "----------\n" + + "5. ERROR in X.java (at line 12)\n" + + " doNothing();\n" + + " ^^^^^^^^^\n" + + "Cannot make a static reference to the non-static method doNothing() from the type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 22)\n" + + " interface I { \n" + + " ^\n" + + "The type I is never used locally\n" + + "----------\n" + + "7. ERROR in X.java (at line 24)\n" + + " return e != null ? 0 : 1;\n" + + " ^\n" + + "Cannot make a static reference to the non-static variable e\n" + + "----------\n" + ); + } + // 9.6 + public void testBug564557AnnotInterface_001() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() {\n"+ + " class I {\n"+ + " @interface Annot {\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @interface Annot {\n" + + " ^^^^^\n" + + "The member annotation Annot can only be defined inside a top-level class or interface or in a static context\n" + + "----------\n" + ); + } + // 9.6 + public void testBug564557AnnotInterface_002() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() {\n"+ + " interface I {\n"+ + " @interface Annot {\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @interface Annot {\n" + + " ^^^^^\n" + + "The member annotation Annot can only be defined inside a top-level class or interface or in a static context\n" + + "----------\n" + ); + } + // 9.4 && 15.12.3 + public void testBug564557MethodInvocation_003() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() {\n"+ + " Zork();\n"+ + " interface I {\n"+ + " default void bar() {}\n"+ + " default void b1() {\n"+ + " class J {\n"+ + " void jb2() {\n"+ + " bar();\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + ); + } + // 9.4 && 15.12.3 + public void testBug564557MethodInvocation_004() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() {\n"+ + " interface I {\n"+ + " default void bar() {}\n"+ + " default void b1() {\n"+ + " interface J {\n"+ + " default void jb2() {\n"+ + " bar();\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " interface I {\n" + + " ^\n" + + "The type I is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " default void b1() {\n" + + " ^^^^\n" + + "The method b1() from the type I is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " interface J {\n" + + " ^\n" + + "The type J is never used locally\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " bar();\n" + + " ^^^\n" + + "Cannot make a static reference to the non-static method bar() from the type I\n" + + "----------\n" + ); + } + // 13.1 + public void testBug564557BinaryForm_005() throws Exception { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"\");\n"+ + " }\n"+ + " void foo() {\n"+ + " interface I {\n"+ + " }\n"+ + " }\n"+ + "}" + }, + ""); + String expectedOutput = "abstract static interface X$1I {\n"; + LocalStaticsTest.verifyClassFile(expectedOutput, "X$1I.class"); + } + // 14.3 for enum + public void testBug564557BinaryForm_006() throws Exception { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"\");\n"+ + " }\n"+ + " void foo() {\n"+ + " enum I {\n"+ + " }\n"+ + " }\n"+ + "}" + }, + ""); + String expectedOutput = "static final enum X$1I {\n"; + LocalStaticsTest.verifyClassFile(expectedOutput, "X$1I.class"); + } + // 15.8.3 + public void testBug564557thisInStatic_007() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() {\n"+ + " interface I {\n"+ + " int count = 0;\n"+ + " static void bar() {\n"+ + " int i = this.count;\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " interface I {\n" + + " ^\n" + + "The type I is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " int count = 0;\n" + + " ^^^^^\n" + + "The value of the field I.count is not used\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " int i = this.count;\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n" + ); + } + // 15.8.3 + public void testBug564557thisInStatic_008() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " int count = 0;\n"+ + " void foo() {\n"+ + " interface I {\n"+ + " static void bar() {\n"+ + " int i = X.this.count;\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " interface I {\n" + + " ^\n" + + "The type I is never used locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " int i = X.this.count;\n" + + " ^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n" + ); + } + public void testBug568514LocalEnums_001() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo() {\n" + + " public enum I {}\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public enum I {}\n" + + " ^\n" + + "Illegal modifier for local enum I; no explicit modifier is permitted\n" + + "----------\n" + ); + } + public void testBug568514LocalEnums_002() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo() {\n" + + " public enum I {}\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public enum I {}\n" + + " ^\n" + + "Illegal modifier for local enum I; no explicit modifier is permitted\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug568514LocalEnums_003() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo() {\n" + + " public enum I {}\n"+ + " Zork;\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork;\n" + + " ^^^^\n" + + "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration\n" + + "----------\n" + ); + } + + public void testBug568514LocalEnums_004() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo() {\n" + + " public strictfp enum I {}\n"+ + " Zork;\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork;\n" + + " ^^^^\n" + + "Syntax error, insert \"VariableDeclarators\" to complete LocalVariableDeclaration\n" + + "----------\n" + ); + } + + public void testBug566579_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private String I=null;\n"+ + " public void foo() {\n"+ + " int f = switch (5) {\n"+ + " case 5: {\n"+ + " interface I{\n"+ + " public int getVal();\n"+ + " }\n"+ + " class C implements I{\n"+ + " private int j=5;\n"+ + " @Override\n"+ + " public int getVal() {\n"+ + " return j;\n"+ + " }\n"+ + " }\n"+ + " \n"+ + " I abc= new C();"+ + " yield abc.getVal();\n"+ + " }\n"+ + " default:\n"+ + " yield (I==null ? 0 : I.length());\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X x = new X();\n"+ + " x.I = \"abc\";\n"+ + " System.out.println();\n"+ + " }\n"+ + "}" + }, + ""); + } + public void testBug566579_002() { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public void main5(int i) {\n"+ + " interface i{\n"+ + " public static int i=0;\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println();\n"+ + " }\n"+ + "}" + }, + ""); + } + public void testBug566579_003() { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public void main5() {\n"+ + " int i=10;\n"+ + " interface i{\n"+ + " public static int i=0;\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println();\n"+ + " }\n"+ + "}" + }, + ""); + } + public void testBug566579_004() { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public void main5() {\n"+ + " try {\n"+ + " int i=10;\n"+ + " } catch(NullPointerException npe) {\n"+ + " interface i{\n"+ + " public static int npe=0;\n"+ + " }\n"+ + " }"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println();\n"+ + " }\n"+ + "}" + }, + ""); + } + public void testBug569444_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"hello\");\n"+ + " class Y{\n"+ + " static int field;\n"+ + " public static void foo() {}\n"+ + " }\n"+ + " record R() {}\n"+ + " }\n"+ + " class Z {\n"+ + " static int f2;\n"+ + " static {};\n"+ + " }\n"+ + "}" + }, + "hello"); + } + public void testBug569444_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private void foo() {\n"+ + " class Y {\n"+ + " static record R() {}\n"+ + " static class Z{}\n"+ + " interface I{}\n"+ + " static interface II{}\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"hello\");\n"+ + " }\n"+ + "}" + }, + "hello"); + } + public void testBug569444_003() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public void foo() {\n"+ + " @SuppressWarnings(\"unused\")\n"+ + " class Y {\n"+ + " static record R() {}\n"+ + " class Z{\n"+ + " static class zz{}\n"+ + " }\n"+ + " interface I{\n"+ + " abstract int bar();\n"+ + " }\n"+ + " }\n"+ + " new Y.I() {\n"+ + " @Override\n"+ + " public int bar() {\n"+ + " return 0;\n"+ + " }\n"+ + " \n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"hello\");\n"+ + " }\n"+ + "}" + }, + "hello"); + } + public void testBug569444_004() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public void foo() {\n"+ + " @SuppressWarnings(\"unused\")\n"+ + " static class zzz{}\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"hello\");\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " static class zzz{}\n" + + " ^^^\n" + + "Illegal modifier for the local class zzz; only abstract or final is permitted\n" + + "----------\n"); + } + public void testBug569444_005() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public void foo() {\n"+ + " static class Z{} // static not allowed\n"+ + " class Y{\n"+ + " static class ZZ{} // static allowed\n"+ + " }\n"+ + " static record R() {} // explicit static not allowed\n"+ + " static interface I {} // explicit static not allowed\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " static class Z{} // static not allowed\n" + + " ^\n" + + "Illegal modifier for the local class Z; only abstract or final is permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " static record R() {} // explicit static not allowed\n" + + " ^\n" + + "A local class or interface R is implicitly static; cannot have explicit static declaration\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " static interface I {} // explicit static not allowed\n" + + " ^\n" + + "Illegal modifier for the local interface I; abstract and strictfp are the only modifiers allowed explicitly \n" + + "----------\n"); + } + public void testBug569444_006() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public void foo() {\n"+ + " for (;;) {\n"+ + " static class Y {}\n"+ + " static record R() {}\n"+ + " static interface I{}\n"+ + " break;\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " static class Y {}\n" + + " ^\n" + + "Illegal modifier for the local class Y; only abstract or final is permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " static record R() {}\n" + + " ^\n" + + "A local class or interface R is implicitly static; cannot have explicit static declaration\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " static interface I{}\n" + + " ^\n" + + "Illegal modifier for the local interface I; abstract and strictfp are the only modifiers allowed explicitly \n" + + "----------\n"); + } + public void testBug571163_001() { + runNegativeTest( + new String[] { + "X.java", + " class X {\n"+ + " public void foo() {\n"+ + " class Y {\n"+ + " static Y y;\n"+ + " static {\n"+ + " y = Y.this;\n"+ + " }\n"+ + " class Z {\n"+ + " static Y yy;\n"+ + " static {\n"+ + " yy = Y.this; //error not flagged here\n"+ + " }\n"+ + " }\n"+ + " } \n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " y = Y.this;\n" + + " ^^^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " yy = Y.this; //error not flagged here\n" + + " ^^^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n"); + } + public void testBug571300_001() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo(); \n"+ + " }\n"+ + " public void foo() {\n"+ + " interface I {\n"+ + " class Z {}\n"+ + " }\n"+ + " I.Z z = new I.Z() { // error flagged incorrectly\n"+ + " public String toString() {\n"+ + " return \"I.Z\";\n"+ + " }\n"+ + " };\n"+ + " System.out.println(z.toString());\n"+ + " }\n"+ + "}" + }, + "I.Z"); + } + public void testBug571274_001() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void m() {\n"+ + " interface Y {\n"+ + " class Z {\n"+ + " T foo() {// T should not be allowed\n"+ + " return null;\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " }" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " interface Y {\n" + + " ^\n" + + "The type Y is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " class Z {\n" + + " ^\n" + + "The type Y.Z is never used locally\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " T foo() {// T should not be allowed\n" + + " ^\n" + + "Cannot make a static reference to the non-static type T\n" + + "----------\n"); + } + public void testBug566774_001() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " static String a;\n"+ + " String b;\n"+ + " static String concat() {\n"+ + " return a + b;\n"+ + " }\n"+ + " }" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return a + b;\n" + + " ^\n" + + "Cannot make a static reference to the non-static field b\n" + + "----------\n"); + } + public void testBug566774_002() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " static String a;\n"+ + " String b;\n"+ + " int index() {\n"+ + " interface I {\n"+ + " class Matcher {\n" + + " void check() {\n" + + " if (a == null || b == null) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " I.Matcher matcher = new I.Matcher();\n" + + " matcher.check();\n" + + " return 0;\n" + + " }\n"+ + " }" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " if (a == null || b == null) {\n" + + " ^\n" + + "Cannot make a static reference to the non-static field b\n" + + "----------\n"); + } + + public void testBug566774_003() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " class Checker1 {\n"+ + " void checkWhitespace(int x) {\n"+ + " String arg = args[x];\n"+ + " if (!arg.trim().equals(arg)) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " }\n" + + " }\n" + + " final Checker1 c1 = new Checker1();\n" + + " for (int i = 1; i < args.length; i++) {\n" + + " Runnable r = () -> {\n" + + " c1.checkWhitespace(i);\n" + + " };\n" + + " }\n" + + " }\n"+ + " }" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " c1.checkWhitespace(i);\n" + + " ^\n" + + "Local variable i defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); + } + public void testBug566774_004() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " interface I {\n"+ + " class Checker2 {\n"+ + " void checkFlag(int x) {\n"+ + " String arg = args[x];\n"+ + " if (!arg.startsWith(\"-\")) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " I.Checker2 c2 = new I.Checker2();\n" + + " for (int i = 1; i < args.length; i++) {\n" + + " Runnable r = () -> {\n" + + " c2.checkFlag(i);\n" + + " };\n" + + " }\n" + + " }\n"+ + " }" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String arg = args[x];\n" + + " ^^^^\n" + + "Cannot make a static reference to the non-static variable args\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " c2.checkFlag(i);\n" + + " ^\n" + + "Local variable i defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); + } + public void testBug572994_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " public class Singleton {\n"+ + " private static Singleton pinstance = new Singleton();\n"+ + " public static Singleton instance() {\n"+ + " return pinstance;\n"+ + " }\n"+ + " public String message() {\n"+ + " return \"Hello world!\";\n"+ + " }\n"+ + " }\n"+ + " \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(Singleton.instance().message());\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " private static Singleton pinstance = new Singleton();\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"); + } + public void testBug572994_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " public class Singleton {\n"+ + " private static Singleton pinstance = this;\n"+ + " public static Singleton instance() {\n"+ + " return pinstance;\n"+ + " }\n"+ + " public String message() {\n"+ + " return \"Hello world!\";\n"+ + " }\n"+ + " }\n"+ + " \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(Singleton.instance().message());\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " private static Singleton pinstance = this;\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n"); + } + public void testBug572994_003() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " public class Singleton {\n"+ + " private static Y pinstance = new Y();\n"+ + " public static Y instance() {\n"+ + " return pinstance;\n"+ + " }\n"+ + " public String message() {\n"+ + " return \"Hello world!\";\n"+ + " }\n"+ + " }\n"+ + " \n"+ + " public static void main(String[] args) {\n"+ + " }\n"+ + " class Y {}\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " private static Y pinstance = new Y();\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"); + } + // Test that static field inside inner types are properly initialized + public void testBug574791_1() { + runConformTest( + new String[] { + "EnumTester.java", + "public class EnumTester {\n" + + " public static void main(String[] args) {\n" + + " Test e = Test.ONE;\n" + + " System.out.println(e.value());\n" + + " System.out.println(MyTest.TWO.value());\n" + + " I TWO = new I() {\n" + + " private static final String value = getString();\n" + + " @Override\n" + + " public String value() {\n" + + " return value;\n" + + " }\n" + + " };\n" + + " System.out.println(TWO.value());\n" + + " }\n" + + " private static String getString() {\n" + + " return \"Hi from EnumTester\";\n" + + " }\n" + + " class MyTest {\n" + + " public static final String value = getString();\n" + + " private static String getString() {\n" + + " return \"Hi from MyTest\";\n" + + " }\n" + + " public static I TWO = new I() {\n" + + " private static final String value = getString();\n" + + " @Override\n" + + " public String value() {\n" + + " return value;\n" + + " }\n" + + " };\n" + + " }\n" + + " interface I {\n" + + " public String value();\n" + + " }\n" + + "}\n" + + "enum Test {\n" + + " ONE {\n" + + " private static final String value = getString();\n" + + " @Override\n" + + " String value() {\n" + + " return value;\n" + + " }\n" + + " };\n" + + " abstract String value();\n" + + " private static String getString() {\n" + + " return \"Hi from Test\";\n" + + " }\n" + + "}" + }, + "Hi from Test\n" + + "Hi from MyTest\n" + + "Hi from EnumTester"); + } + // Test that the static initializer is generated only when required + // i.e., when the (anonymous) inner class contains a static field + public void testBug574791_2() throws Exception { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}\n" + + "enum Test {\n" + + " ONE {\n" + + " private static final String value = getString();\n" + + " @Override\n" + + " String value() {\n" + + " return value;\n" + + " }\n" + + " },\n" + + " TWO {\n" + + " String value() {\n" + + " return \"TWO\";\n" + + " }\n" + + " },\n" + + " ;\n" + + " abstract String value();\n" + + " private static String getString() {\n" + + " return \"default\";\n" + + " }\n" + + "}" + }, + ""); + String expectedOutput = + " // Method descriptor #17 ()V\n" + + " // Stack: 1, Locals: 0\n" + + " static {};\n" + + " 0 invokestatic Test.getString() : java.lang.String [18]\n" + + " 3 putstatic Test$1.value : java.lang.String [22]\n" + + " 6 return"; + String content = getClassfileContent("Test$1.class"); + assertTrue("Expected code not found", content.indexOf(expectedOutput) != -1); + expectedOutput = " static {};"; + content = getClassfileContent("Test$2.class"); + assertTrue("Unexpected code found", content.indexOf(expectedOutput) == -1); + } + public void testBug574791_3() { + runConformTest( + new String[] { + "EnumTester.java", + "public class EnumTester {\n" + + " public static void main(String[] args) {\n" + + " Test e = Test.ONE;\n" + + " System.out.println(e.value());\n" + + " System.out.println(MyTest.TWO.value());\n" + + " I TWO = new I() {\n" + + " private static final String value = getString();\n" + + " @Override\n" + + " public String value() {\n" + + " return value;\n" + + " }\n" + + " };\n" + + " System.out.println(TWO.value());\n" + + " }\n" + + " private static String getString() {\n" + + " return \"Hi from EnumTester\";\n" + + " }\n" + + " class MyTest {\n" + + " public static String value;\n" + + " static {\n" + + " value = getString();\n" + + " }\n" + + " private static String getString() {\n" + + " return \"Hi from MyTest\";\n" + + " }\n" + + " public static I TWO = new I() {\n" + + " private static final String value = getString();\n" + + " @Override\n" + + " public String value() {\n" + + " return value;\n" + + " }\n" + + " };\n" + + " }\n" + + " interface I {\n" + + " public String value();\n" + + " }\n" + + "}\n" + + "enum Test {\n" + + " ONE {\n" + + " public static String value;\n" + + " static {\n" + + " value = getString();\n" + + " }\n" + + " @Override\n" + + " String value() {\n" + + " return value;\n" + + " }\n" + + " };\n" + + " abstract String value();\n" + + " private static String getString() {\n" + + " return \"Hi from Test\";\n" + + " }\n" + + "}" + }, + "Hi from Test\n" + + "Hi from MyTest\n" + + "Hi from EnumTester"); + } +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java new file mode 100644 index 0000000000..5f7992e802 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalVariableTest.java @@ -0,0 +1,924 @@ +/******************************************************************************* + * Copyright (c) 2005, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class LocalVariableTest extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "testBug537033" }; +} +public LocalVariableTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public void test001() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " int foo(){\n" + + " int i;\n" + + " return 1;\n" + + " }\n" + + "}\n", + }); +} +public void test002() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " void foo() {\n" + + " String temp;\n" + + " try {\n" + + " return;\n" + + " }\n" + + " catch (Exception e){\n" + + " }\n" + + " }\n" + + "}\n", + }); +} +public void test003() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " void foo() {\n" + + " String temp;\n" + + " try {\n" + + " return;\n" + + " }\n" + + " catch (Exception e) {\n" + + " }\n" + + " }\n" + + "}\n", + }); +} +public void test004() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " {\n" + + " int i = 1;\n" + + " System.out.println(i);\n" + + " }\n" + + " X(int j){\n" + + " }\n" + + "}\n", + }); +} +public void test005() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " int j;\n" + + " void f1() {\n" + + " int l;\n" + + " switch (j) {\n" + + " case 0 :\n" + + " l = 10;\n" + + " l++;\n" + // at least one read usage + " break;\n" + + " case 1 :\n" + + " l = 20;\n" + + " break;\n" + + " case 2 :\n" + + " l = 30;\n" + + " break;\n" + + " default :\n" + + " l = 10;\n" + + " break;\n" + + " }\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " }\n" + + "}\n", + }); +} + +public void test006() { + this.runConformTest(new String[] { + "p/Truc.java", + "package p;\n" + + "public class Truc{\n" + + " void foo(){\n" + + " final int i; \n" + + " i = 1;\n" + + " if (false) i = 2;\n" + + " } \n" + + " public static void main(java.lang.String[] args) {\n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + "}", + }, + "SUCCESS"); +} + +public void test007() { + this.runConformTest(new String[] { + "p/A.java", + "package p;\n" + + "import p.helper.Y;\n" + + "class A extends Y {\n" + + " class Y {\n" + + " int j = i;// i is a protected member inherited from Y\n" + + " }\n" + + "}", + + "p/helper/Y.java", + "package p.helper;\n" + + "public class Y {\n" + + " protected int i = 10;\n" + + " public inner in = new inner();\n" + + " \n" + + " protected class inner {\n" + + " public int f() {\n" + + " return 20;\n" + + " }\n" + + " }\n" + + "}", + + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127078 +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " class Y {\n" + + " Y innerY;\n" + + "\n" + + " int longMemberName;\n" + + " }\n" + + "\n" + + " static public void main(String args[]) {\n" + + " Y y;\n" + + " System.out.println(y.innerY.longMemberName);\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " System.out.println(y.innerY.longMemberName);\n" + + " ^\n" + + "The local variable y may not have been initialized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127078 +public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " class Y {\n" + + " int longMemberName;\n" + + " }\n" + + "\n" + + " static public void main(String args[]) {\n" + + " Y y;\n" + + " System.out.println(y.longMemberName);\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(y.longMemberName);\n" + + " ^\n" + + "The local variable y may not have been initialized\n" + + "----------\n"); +} +public void test010() { + Map options = getCompilerOptions(); + options.put( + CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "/**\n" + + " * @see Y\n" + + " */\n" + + "public class X {\n" + + "}", + "p/Y.java", + "package p;\n" + + "class Z {\n" + + "}", + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144426 +public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int x = 2;\n" + + " if (true) {\n" + + " int x = 4;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " int x = 4;\n" + + " ^\n" + + "Duplicate local variable x\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144858 +public void test012() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int x = x = 0;\n" + + " if (true) {\n" + + " int x = x = 1;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " int x = x = 0;\n" + + " ^^^^^^^^^\n" + + "The assignment to variable x has no effect\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int x = x = 1;\n" + + " ^\n" + + "Duplicate local variable x\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " int x = x = 1;\n" + + " ^^^^^^^^^\n" + + "The assignment to variable x has no effect\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144858 - variation +//check variable collision resiliance (catch argument) +// variable collision should not interfere with exception collision +public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int x = 2;\n" + + " try {\n" + + " \n" + + " } catch(Exception x) {\n" + + " } catch(Exception e) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " } catch(Exception x) {\n" + + " ^\n" + + "Duplicate parameter x\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " } catch(Exception e) {\n" + + " ^^^^^^^^^\n" + + "Unreachable catch block for Exception. It is already handled by the catch block for Exception\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=144858 - variation +public void test014() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(){\n" + + " int x = 0;\n" + + " String x = \"\";\n" + + " x.toString();\n" + + " }\n" + + " }\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " String x = \"\";\n" + + " ^\n" + + "Duplicate local variable x\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=157379 +public void test015() { + Map options = getCompilerOptions(); + if (this.complianceLevel == ClassFileConstants.JDK1_3) return; + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static boolean test() {\n" + + " boolean b = false;\n" + + " assert b = true;\n" + + " return false;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " test();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118217 +public void test016() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, CompilerOptions.DISABLED); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X extends Parent implements Doable {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void foo(int value) { // X#foo(...)\n" + + " }\n" + + " void bar(int value) { // X#bar(...)\n" + + " }\n" + + "\n" + + " void top(int value) { /* X#top(...)*/}\n" + + " void parent(int value) { /* X#parent(...) */}\n" + + " public void doit(int value) { /* X#doit(...) */}\n" + + "}\n" + + "abstract class Top {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " abstract void top(int value); // Top#top(...)\n" + + "}\n" + + "abstract class Parent extends Top {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void parent(int value) { /* Parent#parent(...) */}\n" + + "}\n" + + "interface Doable {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void doit (int value); // Doable#doit(...)\n" + + "}", // ================= + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 7)\n" + + " void bar(int value) { // X#bar(...)\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118217 - variation +public void test017() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, CompilerOptions.DISABLED); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X extends Parent implements Doable {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void foo(int value) { // X#foo(...)\n" + + " }\n" + + " void bar(int value) { // X#bar(...)\n" + + " }\n" + + "\n" + + " void top(int value) { /* X#top(...)*/}\n" + + " void parent(int value) { /* X#parent(...) */}\n" + + " public void doit(int value) { /* X#doit(...) */}\n" + + "}\n" + + "abstract class Top {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " abstract void top(int value); // Top#top(...)\n" + + "}\n" + + "abstract class Parent extends Top {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void parent(int value) { /* Parent#parent(...) */}\n" + + "}\n" + + "interface Doable {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void doit (int value); // Doable#doit(...)\n" + + "}", // ================= + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " void foo(int value) { // X#foo(...)\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " void bar(int value) { // X#bar(...)\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "3. ERROR in X.java (at line 24)\n" + + " void parent(int value) { /* Parent#parent(...) */}\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118217 - variation +public void test018() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, CompilerOptions.DISABLED); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X extends Parent implements Doable {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void foo(int value) { // X#foo(...)\n" + + " }\n" + + " void bar(int value) { // X#bar(...)\n" + + " }\n" + + "\n" + + " void top(int value) { /* X#top(...)*/}\n" + + " void parent(int value) { /* X#parent(...) */}\n" + + " public void doit(int value) { /* X#doit(...) */}\n" + + "}\n" + + "abstract class Top {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " abstract void top(int value); // Top#top(...)\n" + + "}\n" + + "abstract class Parent extends Top {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void parent(int value) { /* Parent#parent(...) */}\n" + + "}\n" + + "interface Doable {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void doit (int value); // Doable#doit(...)\n" + + "}", // ================= + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " void foo(int value) { // X#foo(...)\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " void bar(int value) { // X#bar(...)\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "3. ERROR in X.java (at line 24)\n" + + " void parent(int value) { /* Parent#parent(...) */}\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118217 - variation +public void test019() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, CompilerOptions.ENABLED); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X extends Parent implements Doable {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void foo(int value) { // X#foo(...)\n" + + " }\n" + + " void bar(int value) { // X#bar(...)\n" + + " }\n" + + "\n" + + " void top(int value) { /* X#top(...)*/}\n" + + " void parent(int value) { /* X#parent(...) */}\n" + + " public void doit(int value) { /* X#doit(...) */}\n" + + "}\n" + + "abstract class Top {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " abstract void top(int value); // Top#top(...)\n" + + "}\n" + + "abstract class Parent extends Top {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void parent(int value) { /* Parent#parent(...) */}\n" + + "}\n" + + "interface Doable {\n" + + " /**\n" + + " * @param value\n" + + " */\n" + + " void doit (int value); // Doable#doit(...)\n" + + "}", // ================= + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 5)\n" + + " void foo(int value) { // X#foo(...)\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " void bar(int value) { // X#bar(...)\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " void top(int value) { /* X#top(...)*/}\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " void parent(int value) { /* X#parent(...) */}\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "5. ERROR in X.java (at line 12)\n" + + " public void doit(int value) { /* X#doit(...) */}\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "6. ERROR in X.java (at line 24)\n" + + " void parent(int value) { /* Parent#parent(...) */}\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=118217 - variation +public void test020() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, CompilerOptions.DISABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, CompilerOptions.ENABLED); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X extends Parent implements Doable {\n" + + " /** @param value */\n" + + " void foo(int value) { // X#foo(...)\n" + + " }\n" + + " void bar(int value) { // X#bar(...)\n" + + " }\n" + + "\n" + + " /** @param value */\n" + + " void top(int value) { /* X#top(...)*/}\n" + + " /** @param value */\n" + + " void parent(int value) { /* X#parent(...) */}\n" + + " /** @param value */\n" + + " public void doit(int value) { /* X#doit(...) */}\n" + + "}\n" + + "abstract class Top {\n" + + " /** @param value */\n" + + " abstract void top(int value); // Top#top(...)\n" + + "}\n" + + "abstract class Parent extends Top {\n" + + " /** @param value */\n" + + " void parent(int value) { /* Parent#parent(...) */}\n" + + "}\n" + + "interface Doable {\n" + + " /** @param value */\n" + + " void doit (int value); // Doable#doit(...)\n" + + "}", // ================= + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " void foo(int value) { // X#foo(...)\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " void bar(int value) { // X#bar(...)\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " void top(int value) { /* X#top(...)*/}\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " void parent(int value) { /* X#parent(...) */}\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " public void doit(int value) { /* X#doit(...) */}\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n" + + "6. ERROR in X.java (at line 21)\n" + + " void parent(int value) { /* Parent#parent(...) */}\n" + + " ^^^^^\n" + + "The value of the parameter value is not used\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=412119, Optional warning for unused throwable variable in catch block +//No error message for exception parameter not being used. +public void test412119a() { + runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "class X {\n" + + " \n" + + " void somethingDangerous() {}\n" + + " void foo() {\n" + + " try {\n" + + " somethingDangerous();\n" + + " } catch(Exception e) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " }\n" + + "}\n", + }); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=412119, Optional warning for unused throwable variable in catch block +//Error message for exception parameter not being used. +public void test412119b() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedExceptionParameter, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "p/X.java", + "package p;\n" + + "class X {\n" + + " void somethingDangerous() {}\n" + + " void foo() {\n" + + " try {\n" + + " somethingDangerous();\n" + + " } catch(Exception e) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " try {\n" + + " somethingDangerous();\n" + + + // Exception thrown under a true boolean expression + " } catch(Exception e1) {\n" + + " if (true)\n" + + " throw new RuntimeException(e1);\n" + + " }\n" + + + // Catch clause parameter used. + " try {\n" + + " somethingDangerous();\n" + + " } catch(Exception e2) {\n" + + " throw new RuntimeException(e2);\n" + + " }\n" + + " }\n" + + "}\n", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in p\\X.java (at line 7)\n" + + " } catch(Exception e) {\n" + + " ^\n" + + "The value of the exception parameter e is not used\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=412119, Optional warning for unused throwable variable in catch block +//Multi-catch parameters. +public void test412119c() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedExceptionParameter, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "p/X.java", + "package p;\n" + + "class X {\n" + + "class Z2 extends Exception {\n" + + " private static final long serialVersionUID = 1L;}\n" + + "class Z1 extends Exception {\n" + + " private static final long serialVersionUID = 1L;}\n" + + " void somethingDangerous(int x, int y) throws Z1, Z2 {\n" + + " if (x < 1)\n" + + " throw new Z1();\n" + + " if (y > 1) \n" + + " throw new Z2();\n" + + " }\n" + + " void foo(int x, int y) {\n" + + " try {\n" + + " somethingDangerous(x, y);\n" + + " } catch(Z2|Z1 z) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " try {\n" + + " somethingDangerous(x, y);\n" + + " } catch(Z2|Z1 z2) {\n" + + " throw new RuntimeException(z2);\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in p\\X.java (at line 16)\n" + + " } catch(Z2|Z1 z) {\n" + + " ^\n" + + "The value of the exception parameter z is not used\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=412119, Optional warning for unused throwable variable in catch block +//Suppress Warnings. +public void test412119d() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportUnusedExceptionParameter, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " void foo(int x) {}\n" + + " void somethingDangerous() {}\n" + + " @SuppressWarnings(\"unused\")\n" + + " void foo3() {\n" + + " try {\n" + + " somethingDangerous();\n" + + " } catch(Exception e) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "" , + null, + true, + options); +} +public void testBug537033() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runNegativeTest( + new String[] { + "ShowBug.java", + "import java.util.concurrent.Callable;\n" + + "\n" + + "public class ShowBug {\n" + + " private static abstract class X {\n" + + " abstract void x(int val);\n" + + " }\n" + + "\n" + + " public ShowBug() {\n" + + " final X x = new X() {\n" + + " void x(int val) {\n" + + " if (val > 0) {\n" + + " // (1) The local variable x may not have been initialized\n" + + " x.x(val - 1);\n" + + " }\n" + + " }\n" + + " };\n" + + "\n" + + " new Callable() {\n" + + " public Void call() {\n" + + " // (2) Missing code implementation in the compiler\n" + + " x.x(10); \n" + + " return null;\n" + + " }\n" + + " }.call();\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK11 + ? + "----------\n" + + "1. WARNING in ShowBug.java (at line 9)\n" + + " final X x = new X() {\n" + + " ^^^\n" + + "Access to enclosing constructor ShowBug.X() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in ShowBug.java (at line 13)\n" + + " x.x(val - 1);\n" + + " ^\n" + + "The local variable x may not have been initialized\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in ShowBug.java (at line 13)\n" + + " x.x(val - 1);\n" + + " ^\n" + + "The local variable x may not have been initialized\n" + + "----------\n"); +} +public static Class testClass() { + return LocalVariableTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java new file mode 100644 index 0000000000..4df27ef0e4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java @@ -0,0 +1,3636 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * bug 185682 - Increment/decrement operators mark local variables as read + * bug 388800 - [1.8] adjust tests to 1.8 JRE + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Hashtable; +import java.util.Map; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.ICompilerRequestor; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; + +import junit.framework.Test; +/** + * Name Lookup within Inner Classes + * Creation date: (8/2/00 12:04:53 PM) + * @author Dennis Conway + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class LookupTest extends AbstractRegressionTest { +public LookupTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +static { +// TESTS_NAMES = new String [] { "test096" }; +} +/** + * Non-static member class + */ +public void test001() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " private static int value = 23; \n"+ + " class B { \n"+ + " private int value; \n"+ + " B (int val) { \n"+ + " value = (A.value * 2) + val; \n"+ + " } \n"+ + " } \n"+ + " public static void main (String args[]) { \n"+ + " int result = new A().new B(12).value; \n"+ + " int expected = 58; \n"+ + " System.out.println( \n"+ + " result == expected \n"+ + " ? \"SUCCESS\" \n"+ + " : \"FAILED : got \"+result+\" instead of \"+ expected); \n"+ + " } \n"+ + "}" + }, + "SUCCESS" + ); +} +/** + * Attempt to access non-static field from static inner class (illegal) + */ +public void test002() { + this.runNegativeTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "class A { \n"+ + " private int value; \n"+ + " static class B { \n"+ + " B () { \n"+ + " value = 2; \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " B result = new B(); \n"+ + " } \n"+ + "}" + }, + "----------\n" + + "1. WARNING in p1\\A.java (at line 3)\n" + + " private int value; \n" + + " ^^^^^\n" + + "The value of the field A.value is not used\n" + + "----------\n" + + "2. ERROR in p1\\A.java (at line 6)\n" + + " value = 2; \n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static field value\n" + + "----------\n"); +} +/** + * Access static field from static inner class + */ +public void test003() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " private static int value; \n"+ + " static class B { \n"+ + " B () { \n"+ + " value = 2; \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " B result = new B(); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "}", + }, + "SUCCESS" + ); +} +/** + * + */ +public void test004() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " private String value; \n"+ + " private A (String strIn) { \n"+ + " value = new B(strIn, \"E\").str; \n"+ + " } \n"+ + " class B { \n"+ + " String str; \n"+ + " private B (String strFromA, String strIn) {\n"+ + " str = strFromA + strIn + new C(\"S\").str;\n"+ + " } \n"+ + " class C { \n"+ + " String str; \n"+ + " private C (String strIn) { \n"+ + " str = strIn + new D(\"S\").str; \n"+ + " } \n"+ + " class D { \n"+ + " String str; \n"+ + " private D (String strIn) { \n"+ + " str = strIn; \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " System.out.println(new A(\"SUCC\").value); \n"+ + " } \n"+ + "}" + }, + "SUCCESS" + ); +} +/** + * + */ +public void test005() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " private static void doSomething(String showThis) {\n"+ + " System.out.print(showThis); \n"+ + " return; \n"+ + " } \n"+ + " class B { \n"+ + " void aMethod () { \n"+ + " p1.A.doSomething(\"SUCC\"); \n"+ + " A.doSomething(\"ES\"); \n"+ + " doSomething(\"S\"); \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " B foo = new A().new B(); \n"+ + " foo.aMethod(); \n"+ + " } \n"+ + "}" + }, + "SUCCESS" + ); +} +/** + * jdk1.2.2 reports: No variable sucess defined in nested class p1.A. B.C. + * jdk1.3 reports: success has private access in p1.A + */ +public void test006() { + this.runNegativeTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "class A { \n"+ + " private static String success = \"SUCCESS\"; \n"+ + " public interface B { \n"+ + " public abstract void aTask(); \n"+ + " class C extends A implements B { \n"+ + " public void aTask() {System.out.println(this.success);}\n"+ + " } \n"+ + " } \n"+ + " public static void main (String[] argv) { \n"+ + " } \n"+ + "}" + }, + "----------\n" + + "1. ERROR in p1\\A.java (at line 7)\n" + + " public void aTask() {System.out.println(this.success);}\n" + + " ^^^^^^^\n" + + "The field A.success is not visible\n" + + "----------\n" + + "2. WARNING in p1\\A.java (at line 7)\n" + + " public void aTask() {System.out.println(this.success);}\n" + + " ^^^^^^^\n" + + "The static field A.success should be accessed in a static way\n" + + "----------\n"); +} +/** + * No errors in jdk1.2.2, jdk1.3 + */ +public void test007() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " private static String success = \"SUCCESS\"; \n"+ + " public interface B { \n"+ + " public abstract void aTask(); \n"+ + " class C extends A implements B { \n"+ + " public void aTask() {System.out.println(A.success);}\n"+ + " } \n"+ + " } \n"+ + " public static void main (String[] argv) { \n"+ + " } \n"+ + "}" + } + ); +} +/** + * jdk1.2.2 reports: Undefined variable: A.this + * jdk1.3 reports: non-static variable this cannot be referenced from a static context + */ +public void test008() { + this.runNegativeTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "class A { \n"+ + " private static String success = \"SUCCESS\"; \n"+ + " public interface B { \n"+ + " public abstract void aTask(); \n"+ + " class C extends A implements B { \n"+ + " public void aTask() {System.out.println(A.this.success);}\n"+ + " } \n"+ + " } \n"+ + " public static void main (String[] argv) { \n"+ + " } \n"+ + "}" + }, + "----------\n" + + "1. ERROR in p1\\A.java (at line 7)\n" + + " public void aTask() {System.out.println(A.this.success);}\n" + + " ^^^^^^\n" + + "No enclosing instance of the type A is accessible in scope\n" + + "----------\n" + + "2. WARNING in p1\\A.java (at line 7)\n" + + " public void aTask() {System.out.println(A.this.success);}\n" + + " ^^^^^^^\n" + + "The static field A.success should be accessed in a static way\n" + + "----------\n" + ); +} +/** + * jdk1.2.2 reports: No variable success defined in nested class p1.A. B.C + * jdk1.3 reports: success has private access in p1.A + */ +public void test009() { + this.runNegativeTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "class A { \n"+ + " private String success = \"SUCCESS\"; \n"+ + " public interface B { \n"+ + " public abstract void aTask(); \n"+ + " class C extends A implements B { \n"+ + " public void aTask() {System.out.println(this.success);}\n"+ + " } \n"+ + " } \n"+ + " public static void main (String[] argv) { \n"+ + " } \n"+ + "}" + }, + "----------\n" + + "1. ERROR in p1\\A.java (at line 7)\n" + + " public void aTask() {System.out.println(this.success);}\n" + + " ^^^^^^^\n" + + "The field A.success is not visible\n" + + "----------\n"); +} +/** + * jdk1.2.2 reports: Can't make a static reference to nonstatic variable success in class p1.A + * jdk1.3 reports: non-static variable success cannot be referenced from a static context + */ +public void test010() { + this.runNegativeTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "class A { \n"+ + " private String success = \"SUCCESS\"; \n"+ + " public interface B { \n"+ + " public abstract void aTask(); \n"+ + " class C extends A implements B { \n"+ + " public void aTask() {System.out.println(A.success);}\n"+ + " } \n"+ + " } \n"+ + " public static void main (String[] argv) { \n"+ + " } \n"+ + "}" + }, + "----------\n" + + "1. WARNING in p1\\A.java (at line 3)\n" + + " private String success = \"SUCCESS\"; \n" + + " ^^^^^^^\n" + + "The value of the field A.success is not used\n" + + "----------\n" + + "2. ERROR in p1\\A.java (at line 7)\n" + + " public void aTask() {System.out.println(A.success);}\n" + + " ^^^^^^^^^\n" + + "Cannot make a static reference to the non-static field A.success\n" + + "----------\n"); +} +/** + * + */ +public void test011() { + this.runNegativeTest( + new String[] { + /* p2.Aa */ + "p2/Aa.java", + "package p2; \n"+ + "class Aa extends p1.A{ \n"+ + " class B implements p1.A.C { \n"+ + " } \n"+ + " public static void main (String args[]) { \n"+ + " } \n"+ + "}", + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " public A() { \n"+ + " } \n"+ + " class B implements C { \n"+ + " public int sMethod() { \n"+ + " return 23; \n"+ + " } \n"+ + " } \n"+ + " public interface C { \n"+ + " public abstract int sMethod(); \n"+ + " } \n"+ + "}", + + }, + "----------\n" + + "1. ERROR in p2\\Aa.java (at line 3)\n" + + " class B implements p1.A.C { \n" + + " ^\n" + + "The type Aa.B must implement the inherited abstract method A.C.sMethod()\n" + + "----------\n" + ); +} +/** + * + */ +public void test012() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " public interface B { \n"+ + " public abstract void aMethod (int A); \n"+ + " public interface C { \n"+ + " public abstract void anotherMethod(); \n"+ + " } \n"+ + " } \n"+ + " public class aClass implements B, B.C { \n"+ + " public void aMethod (int A) { \n"+ + " } \n"+ + " public void anotherMethod(){} \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "}" + }, + "SUCCESS" + ); +} +/** + * + */ +public void test013() { + this.runNegativeTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " public interface B { \n"+ + " public abstract void aMethod (int A); \n"+ + " public interface C { \n"+ + " public abstract void anotherMethod(int A);\n"+ + " } \n"+ + " } \n"+ + " public class aClass implements B, B.C { \n"+ + " public void aMethod (int A) { \n"+ + " public void anotherMethod(int A) {}; \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "}" + }, + "----------\n" + + "1. ERROR in p1\\A.java (at line 9)\n" + + " public class aClass implements B, B.C { \n" + + " ^^^^^^\n" + + "The type A.aClass must implement the inherited abstract method A.B.C.anotherMethod(int)\n" + + "----------\n" + + (this.complianceLevel < ClassFileConstants.JDK14 + ? + "2. ERROR in p1\\A.java (at line 11)\n" + + " public void anotherMethod(int A) {}; \n" + + " ^\n" + + "Syntax error on token \"(\", ; expected\n" + + "----------\n" + + "3. ERROR in p1\\A.java (at line 11)\n" + + " public void anotherMethod(int A) {}; \n" + + " ^\n" + + "Syntax error on token \")\", ; expected\n" + : + "1. ERROR in p1\\A.java (at line 9)\n" + + " public class aClass implements B, B.C { \n" + + " ^^^^^^\n" + + "The type A.aClass must implement the inherited abstract method A.B.C.anotherMethod(int)\n" + + "----------\n" + + "2. ERROR in p1\\A.java (at line 11)\n" + + " public void anotherMethod(int A) {}; \n" + + " ^^^^\n" + + "Syntax error on token \"void\", record expected\n" + ) + + "----------\n" + ); +} +/** + * + */ +public void test014() { + this.runNegativeTest( + new String[] { + /* pack1.First */ + "pack1/First.java", + "package pack1; \n"+ + "public class First { \n"+ + " public static void something() {} \n"+ + " class Inner {} \n"+ + " public static void main (String argv[]) { \n"+ + " First.Inner foo = new First().new Inner(); \n"+ + " foo.something(); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "}" + }, + "----------\n" + + "1. ERROR in pack1\\First.java (at line 7)\n" + + " foo.something(); \n" + + " ^^^^^^^^^\n" + + "The method something() is undefined for the type First.Inner\n" + + "----------\n" + ); +} +/** + * + */ +public void test015() { + this.runConformTest( + new String[] { + /* pack1.First */ + "pack1/First.java", + "package pack1; \n"+ + "public class First { \n"+ + " class Inner { \n"+ + " public void something() {} \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " First.Inner foo = new First().new Inner(); \n"+ + " foo.something(); \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "}" + }, + "SUCCESS" + ); +} +/** + * + */ +public void test016() { + this.runConformTest( + new String[] { + /* pack1.Outer */ + "pack1/Outer.java", + "package pack1; \n"+ + "import pack2.*; \n"+ + "public class Outer { \n"+ + " int time, distance; \n"+ + " public Outer() { \n"+ + " } \n"+ + " public Outer(int d) { \n"+ + " distance = d; \n"+ + " } \n"+ + " public void aMethod() { \n"+ + " this.distance *= 2; \n"+ + " return; \n"+ + " } \n"+ + "}", + /* pack2.OuterTwo */ + "pack2/OuterTwo.java", + "package pack2; \n"+ + "import pack1.*; \n"+ + "public class OuterTwo extends Outer { \n"+ + " public OuterTwo(int bar) { \n"+ + " Outer A = new Outer(3) { \n"+ + " public void bMethod(){ \n"+ + " final class X { \n"+ + " int price; \n"+ + " public X(int inp) { \n"+ + " price = inp + 32; \n"+ + " } \n"+ + " } \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " System.out.println(\"\"); \n"+ + " OuterTwo foo = new OuterTwo(12); \n"+ + " Outer bar = new Outer(8); \n"+ + " } \n"+ + "}" + } + ); +} +/** + * + */ +public void test017() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " int value; \n"+ + " public A(B bVal) { \n"+ + " bVal.sval += \"V\"; \n"+ + " } \n"+ + " static class B { \n"+ + " public static String sval; \n"+ + " public void aMethod() { \n"+ + " sval += \"S\"; \n"+ + " A bar = new A(this); \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " B foo = new B(); \n"+ + " foo.sval = \"U\"; \n"+ + " foo.aMethod(); \n"+ + " System.out.println(foo.sval); \n"+ + " } \n"+ + "}" + }, + "USV" + ); +} +/** + * member class + */ +public void test018() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " private String rating; \n"+ + " public class B { \n"+ + " String rating; \n"+ + " public B (A sth) { \n"+ + " sth.rating = \"m\"; \n"+ + " rating = \"er\"; \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " A foo = new A(); \n"+ + " foo.rating = \"o\"; \n"+ + " B bar = foo.new B(foo); \n"+ + " System.out.println(foo.rating + bar.rating);\n"+ + " } \n"+ + "}" + }, + "mer" + ); +} +/** + * member class + */ +public void test019() { + this.runNegativeTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " private String rating; \n"+ + " public void setRating(A sth, String setTo) { \n"+ + " sth.rating = setTo; \n"+ + " return; \n"+ + " } \n"+ + " public class B { \n"+ + " public B (A sth) { \n"+ + " setRating(sth, \"m\"); \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " A foo = new A(); \n"+ + " foo.rating = \"o\"; \n"+ + " B bar = foo.new B(foo); \n"+ + " System.out.println(foo.rating + bar.other); \n"+ + " } \n"+ + "}" + }, + "----------\n" + + "1. ERROR in p1\\A.java (at line 17)\n" + + " System.out.println(foo.rating + bar.other); \n" + + " ^^^^^\n" + + "other cannot be resolved or is not a field\n" + + "----------\n" + ); +} +/** + * member class + */ +public void test020() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in p1\\A.java (at line 13)\n" + + " System.out.println(foo.rating + bar.other); \n" + + " ^^^^^\n" + + "other cannot be resolved or is not a field\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in p1\\A.java (at line 6)\n" + + " sth.rating = \"m\"; \n" + + " ^^^^^^\n" + + "Write access to enclosing field A.rating is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. ERROR in p1\\A.java (at line 13)\n" + + " System.out.println(foo.rating + bar.other); \n" + + " ^^^^^\n" + + "other cannot be resolved or is not a field\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " private String rating; \n"+ + " public class B { \n"+ + " public B (A sth) { \n"+ + " sth.rating = \"m\"; \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " A foo = new A(); \n"+ + " foo.rating = \"o\"; \n"+ + " B bar = foo.new B(foo); \n"+ + " System.out.println(foo.rating + bar.other); \n"+ + " } \n"+ + "}" + }, + errMessage); +} +/** + * member class + */ +public void test021() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " private String rating; \n"+ + " public class B { \n"+ + " public B (A sth) { \n"+ + " sth.rating = \"m\"; \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " A foo = new A(); \n"+ + " foo.rating = \"o\"; \n"+ + " B bar = foo.new B(foo); \n"+ + " System.out.println(foo.rating); \n"+ + " } \n"+ + "}" + } + ); +} +/** + * + */ +public void test022() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "import p2.*; \n"+ + "public class A { \n"+ + " public int aValue; \n"+ + " public A() {} \n"+ + " public static class C extends A { \n"+ + " public String aString; \n"+ + " public C() { \n"+ + " } \n"+ + " } \n"+ + "}", + /* p2.B */ + "p2/B.java", + "package p2; \n"+ + "import p1.*; \n"+ + "public class B extends A.C { \n"+ + " public B() {} \n"+ + " public class D extends A { \n"+ + " public D() { \n"+ + " C val2 = new C(); \n"+ + " val2.aString = \"s\"; \n"+ + " A val = new A(); \n"+ + " val.aValue = 23; \n"+ + " } \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " D foo = new B().new D(); \n"+ + " } \n"+ + "}" + } + ); +} +/** + * + */ +public void test023() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1;\n"+ + "public class A implements B { \n"+ + "} \n"+ + "interface B { \n"+ + " public class A implements B { \n"+ + " public static void main (String argv[]) { \n"+ + " class Ba { \n"+ + " int time; \n"+ + " } \n"+ + " Ba foo = new Ba(); \n"+ + " foo.time = 3; \n"+ + " } \n"+ + " interface C { \n"+ + " } \n"+ + " interface Bb extends C { \n"+ + " } \n"+ + " } \n"+ + "}" + } + ); +} +/** + * + */ +public void test024() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " protected static String bleh; \n"+ + " interface B { \n"+ + " public String bleh(); \n"+ + " class C{ \n"+ + " public String bleh() {return \"B\";}\n"+ + " } \n"+ + " } \n"+ + " class C implements B { \n"+ + " public String bleh() {return \"A\";} \n"+ + " } \n"+ + " public static void main(String argv[]) { \n"+ + " C foo = new A().new C(); \n"+ + " } \n"+ + "}" + } + ); +} +/** + * + */ +public void test025() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "import p2.*; \n"+ + "public class A { \n"+ + " public static class B { \n"+ + " public static int B; \n"+ + " } \n"+ + " public static void main(String argv[]) {\n"+ + " B foo = new A.B(); \n"+ + " B bar = new B(); \n"+ + " foo.B = 2; \n"+ + " p2.B bbar = new p2.B(); \n"+ + " if (bar.B == 35) { \n"+ + " System.out.println(\"SUCCESS\");\n"+ + " } \n"+ + " else { \n"+ + " System.out.println(bar.B); \n"+ + " } \n"+ + " } \n"+ + "}", + "p2/B.java", + "package p2; \n"+ + "import p1.*; \n"+ + "public class B extends A { \n"+ + " public B() { \n"+ + " A.B bleh = new A.B(); \n"+ + " bleh.B = 35; \n"+ + " } \n"+ + "}" + }, + "SUCCESS" + ); +} +/** + * + */ +public void test026() { + this.runNegativeTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " public static class B { \n"+ + " protected static int B; \n"+ + " } \n"+ + " public static void main(String argv[]) {\n"+ + " B foo = new A.B(); \n"+ + " B bar = new B(); \n"+ + " B.B = 2; \n"+ + " p2.B bbar = new p2.B(); \n"+ + " if (B.B == 35) { \n"+ + " System.out.println(\"SUCCESS\");\n"+ + " } \n"+ + " else { \n"+ + " System.out.println(B.B); \n"+ + " } \n"+ + " } \n"+ + "}", + "p2/B.java", + "package p2; \n"+ + "import p1.*; \n"+ + "public class B extends A { \n"+ + " public B() { \n"+ + " A.B bleh = new A.B(); \n"+ + " bleh.B = 35; \n"+ + " } \n"+ + "}" + }, + "----------\n" + + "1. ERROR in p2\\B.java (at line 6)\n" + + " bleh.B = 35; \n" + + " ^\n" + + "The field A.B.B is not visible\n" + + "----------\n"); +} +/** + * + */ +public void test027() { + this.runNegativeTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " protected static class B { \n"+ + " public static int B; \n"+ + " } \n"+ + " public static void main(String argv[]) {\n"+ + " B foo = new A.B(); \n"+ + " B bar = new B(); \n"+ + " B.B = 2; \n"+ + " p2.B bbar = new p2.B(); \n"+ + " if (B.B == 35) { \n"+ + " System.out.println(\"SUCCESS\");\n"+ + " } \n"+ + " else { \n"+ + " System.out.println(B.B); \n"+ + " } \n"+ + " } \n"+ + "}", + "p2/B.java", + "package p2; \n"+ + "import p1.*; \n"+ + "public class B extends A { \n"+ + " public B() { \n"+ + " A.B bleh = new A.B(); \n"+ + " A.B.B = 35; \n"+ + " } \n"+ + "}" + }, + "----------\n" + + "1. ERROR in p2\\B.java (at line 5)\n" + + " A.B bleh = new A.B(); \n" + + " ^^^^^^^^^\n" + + "The constructor A.B() is not visible\n" + + "----------\n" + ); +} +/** + * + */ +public void test028() { + this.runConformTest( + new String[] { + /* p1.A */ + "p1/A.java", + "package p1; \n"+ + "public class A { \n"+ + " static class B { \n"+ + " public static class C { \n"+ + " private static int a; \n"+ + " private int b; \n"+ + " } \n"+ + " } \n"+ + " class D extends B { \n"+ + " int j = p1.A.B.C.a; \n"+ + " } \n"+ + " public static void main (String argv[]) { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "}" + }, + "SUCCESS" + ); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=10634 + */ +public void test029() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "import p2.Top; \n"+ + "public class X extends Top { \n"+ + " Member field; \n"+ + "} \n", + "p2/Top.java", + "package p2; \n"+ + "public class Top { \n"+ + " class Member { \n"+ + " void foo(){} \n"+ + " } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " Member field; \n" + + " ^^^^^^\n" + + "The type Member is not visible\n" + + "----------\n"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11435 + * 1.3 compiler must accept classfiles without abstract method (target >=1.2) + */ +public void test030() { + + Hashtable target1_2 = new Hashtable(); + target1_2.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2); + + this.runConformTest( + new String[] { + "p1/A.java", + "package p1; \n"+ + "public abstract class A implements I { \n" + + " public static void main(String[] args) { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + "} \n" + + "interface I { \n" + + " void foo(); \n" + + "} \n", + }, + "SUCCESS", // expected output + null, // custom classpath + true, // flush previous output dir content + null, // special vm args + target1_2, // custom options + null/*no custom requestor*/); + + this.runConformTest( + new String[] { + "p1/C.java", + "package p1; \n"+ + "public class C { \n" + + " void bar(A a){ \n" + + " a.foo(); \n" + + " } \n" + + " public static void main(String[] args) { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + "} \n" + }, + "SUCCESS", // expected output + null, // custom classpath + false, // flush previous output dir content + null, // special vm args + null, // custom options + null/*no custom requestor*/); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=11511 + * variant - must filter abstract methods when searching concrete methods + */ +public void test031() { + + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n"+ + "public class X extends AbstractY { \n"+ + " public void init() { \n"+ + " super.init(); \n"+ + " } \n"+ + " public static void main(String[] arguments) { \n"+ + " new X().init(); \n"+ + " } \n"+ + "} \n"+ + "abstract class AbstractY extends AbstractZ implements I { \n"+ + " public void init(int i) { \n"+ + " } \n"+ + "} \n"+ + "abstract class AbstractZ implements I { \n"+ + " public void init() { \n"+ + " System.out.println(\"SUCCESS\"); \n"+ + " } \n"+ + "} \n"+ + "interface I { \n"+ + " void init(); \n"+ + " void init(int i); \n"+ + "} \n" + }, + "SUCCESS"); // expected output +} + +/** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=29211 + * http://dev.eclipse.org/bugs/show_bug.cgi?id=29213 + */ +public void test032() { + this.runNegativeTest( + new String[] { + "X.java", //-------------------------------- + "public class X {\n" + + " public static void main(String[] arguments) {\n" + + " System.out.println(p.Bar.array[0].length);\n" + + " System.out.println(p.Bar.array.length);\n" + + " System.out.println(p.Bar.array[0].foo());\n" + + " }\n" + + "}\n", + "p/Bar.java", //---------------------------- + "package p;\n" + + "public class Bar {\n" + + " public static Z[] array;\n" + + "}\n" + + "class Z {\n" + + " public String foo(){ \n" + + " return \"\";\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(p.Bar.array[0].length);\n" + + " ^^^^^^^^^^^^^^\n" + + "The type Z is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " System.out.println(p.Bar.array.length);\n" + + " ^^^^^^^^^^^\n" + + "The type Z is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " System.out.println(p.Bar.array[0].foo());\n" + + " ^^^^^^^^^^^^^^\n" + + "The type Z is not visible\n" + + "----------\n"); +} + +// 30805 Abstract non-visible method diagnosis fooled by intermediate declarations +public void test033() { + this.runNegativeTest( + new String[] { + "p/X.java", //================================== + "package p; \n" + + "public abstract class X { \n" + + " abstract void foo(); \n" + + "} \n", + "q/Y.java", //================================== + "package q; \n" + + "public class Y extends p.X { \n" + + " void foo(){} \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in q\\Y.java (at line 2)\n" + + " public class Y extends p.X { \n" + + " ^\n" + + "This class must implement the inherited abstract method X.foo(), but cannot override it since it is not visible from Y. Either make the type abstract or make the inherited method visible\n" + + "----------\n" + + "2. WARNING in q\\Y.java (at line 3)\n" + + " void foo(){} \n" + + " ^^^^^\n" + + "The method Y.foo() does not override the inherited method from X since it is private to a different package\n" + + "----------\n"); +} + +// 30805 Abstract non-visible method diagnosis fooled by intermediate declarations +public void test034() { + this.runNegativeTest( + new String[] { + "p/X.java", //================================== + "package p; \n" + + "public abstract class X { \n" + + " abstract void foo(); \n" + + "} \n", + "q/Y.java", //================================== + "package q; \n" + + "public abstract class Y extends p.X { \n" + + " void foo(){} \n" + + "} \n" + + "class Z extends Y { \n" + + "} \n", + }, + "----------\n" + + "1. WARNING in q\\Y.java (at line 3)\n" + + " void foo(){} \n" + + " ^^^^^\n" + + "The method Y.foo() does not override the inherited method from X since it is private to a different package\n" + + "----------\n" + + "2. ERROR in q\\Y.java (at line 5)\n" + + " class Z extends Y { \n" + + " ^\n" + + "This class must implement the inherited abstract method X.foo(), but cannot override it since it is not visible from Z. Either make the type abstract or make the inherited method visible\n" + + "----------\n" +); +} + +// 30805 Abstract non-visible method diagnosis fooled by intermediate declarations +public void test035() { + this.runNegativeTest( + new String[] { + "p/X.java", //================================== + "package p; \n" + + "public abstract class X { \n" + + " abstract void foo(); \n" + + " abstract void bar(); \n" + + "} \n", + "p/Y.java", //================================== + "package p; \n" + + "public abstract class Y extends X { \n" + + " void foo(){}; \n" + + "} \n", + "q/Z.java", //================================== + "package q; \n" + + "class Z extends p.Y { \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in q\\Z.java (at line 2)\n" + + " class Z extends p.Y { \n" + + " ^\n" + + "This class must implement the inherited abstract method X.bar(), but cannot override it since it is not visible from Z. Either make the type abstract or make the inherited method visible\n" + + "----------\n"); +} +// 30805 Abstract non-visible method diagnosis fooled by intermediate declarations +public void test036() { + this.runNegativeTest( + new String[] { + "p/X.java", //================================== + "package p; \n" + + "public abstract class X { \n" + + " abstract void foo(); \n" + + " public interface I { \n" + + " void foo(); \n" + + " } \n" + + "} \n", + "q/Y.java", //================================== + "package q; \n" + + "public abstract class Y extends p.X { \n" + + " void foo(){} \n" + + "} \n" + + "class Z extends Y implements p.X.I { \n" + + "} \n", + }, + "----------\n" + + "1. WARNING in q\\Y.java (at line 3)\n" + + " void foo(){} \n" + + " ^^^^^\n" + + "The method Y.foo() does not override the inherited method from X since it is private to a different package\n" + + "----------\n" + + "2. ERROR in q\\Y.java (at line 5)\n" + + " class Z extends Y implements p.X.I { \n" + + " ^\n" + + "This class must implement the inherited abstract method X.foo(), but cannot override it since it is not visible from Z. Either make the type abstract or make the inherited method visible\n" + + "----------\n" + // TODO (philippe) should not have following error due to default abstract? + "3. ERROR in q\\Y.java (at line 5)\n" + + " class Z extends Y implements p.X.I { \n" + + " ^\n" + + "The inherited method Y.foo() cannot hide the public abstract method in X.I\n" + + "----------\n"); +} +// 30805 Abstract non-visible method diagnosis fooled by intermediate declarations +public void test037() { + this.runNegativeTest( + new String[] { + "p/X.java", //================================== + "package p; \n" + + "public abstract class X { \n" + + " abstract void foo(); \n" + + " void bar(){} \n" + + "} \n", + "q/Y.java", //================================== + "package q; \n" + + "public abstract class Y extends p.X { \n" + + " void foo(){} //warn \n" + + " void bar(){} //warn \n" + + "} \n" + + "class Z extends Y { \n" + + " void bar(){} //nowarn \n" + + "} \n", + }, + "----------\n" + + "1. WARNING in q\\Y.java (at line 3)\n" + + " void foo(){} //warn \n" + + " ^^^^^\n" + + "The method Y.foo() does not override the inherited method from X since it is private to a different package\n" + + "----------\n" + + "2. WARNING in q\\Y.java (at line 4)\n" + + " void bar(){} //warn \n" + + " ^^^^^\n" + + "The method Y.bar() does not override the inherited method from X since it is private to a different package\n" + + "----------\n" + + "3. ERROR in q\\Y.java (at line 6)\n" + + " class Z extends Y { \n" + + " ^\n" + + "This class must implement the inherited abstract method X.foo(), but cannot override it since it is not visible from Z. Either make the type abstract or make the inherited method visible\n" + + "----------\n"); +} +// 30805 Abstract non-visible method diagnosis fooled by intermediate declarations +public void test038() { + this.runNegativeTest( + new String[] { + "p/X.java", //================================== + "package p; \n" + + "public abstract class X { \n" + + " abstract void foo(); \n" + + "} \n", + "q/Y.java", //================================== + "package q; \n" + + "public abstract class Y extends p.X { \n" + + " void foo(){} //warn \n" + + "} \n" + + "class Z extends Y { \n" + + " void foo(){} //error \n" + + "} \n", + }, + "----------\n" + + "1. WARNING in q\\Y.java (at line 3)\n" + + " void foo(){} //warn \n" + + " ^^^^^\n" + + "The method Y.foo() does not override the inherited method from X since it is private to a different package\n" + + "----------\n" + + "2. ERROR in q\\Y.java (at line 5)\n" + + " class Z extends Y { \n" + + " ^\n" + + "This class must implement the inherited abstract method X.foo(), but cannot override it since it is not visible from Z. Either make the type abstract or make the inherited method visible\n" + + "----------\n"); +} + +// 31198 - regression after 30805 - Abstract non-visible method diagnosis fooled by intermediate declarations +public void test039() { + this.runNegativeTest( + new String[] { + "p/X.java", //================================== + "package p; \n" + + "public abstract class X { \n" + + " abstract void foo(); \n" + // should not complain about this one in Z, since it has a visible implementation + " abstract void bar(); \n" + + "} \n", + "p/Y.java", //================================== + "package p; \n" + + "public abstract class Y extends X { \n" + + " public void foo(){}; \n" + + "} \n", + "q/Z.java", //================================== + "package q; \n" + + "class Z extends p.Y { \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in q\\Z.java (at line 2)\n" + + " class Z extends p.Y { \n" + + " ^\n" + + "This class must implement the inherited abstract method X.bar(), but cannot override it since it is not visible from Z. Either make the type abstract or make the inherited method visible\n" + + "----------\n"); +} + +/* + * 31398 - non-visible abstract method fooling method verification - should not complain about foo() or bar() + */ +public void test040() { + this.runNegativeTest( + new String[] { + "p/X.java", //================================ + "package p; \n" + + "public class X extends q.Y.Member { \n" + + " void baz(){} \n" + // doesn't hide Y.baz() + "} \n", + "q/Y.java", //================================ + "package q; \n" + + "public abstract class Y { \n" + + " abstract void foo(); \n" + + " abstract void bar(); \n" + + " abstract void baz(); \n" + + " public static abstract class Member extends Y { \n" + + " public void foo() {} \n" + + " void bar(){} \n" + + " } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " public class X extends q.Y.Member { \n" + + " ^\n" + + "This class must implement the inherited abstract method Y.baz(), but cannot override it since it is not visible from X. Either make the type abstract or make the inherited method visible\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 3)\n" + + " void baz(){} \n" + + " ^^^^^\n" + + "The method X.baz() does not override the inherited method from Y since it is private to a different package\n" + + "----------\n"); +} + +/* + * 31450 - non-visible abstract method fooling method verification - should not complain about foo() + */ +public void test041() { + this.runNegativeTest( + new String[] { + "p/X.java", //================================ + "package p; \n" + + "public class X extends q.Y.Member { \n" + + " public void foo() {} \n" + + " public static class M extends X {} \n" + + "} \n", + "q/Y.java", //================================ + "package q; \n" + + "public abstract class Y { \n" + + " abstract void foo(); \n" + + " abstract void bar(); \n" + + " public static abstract class Member extends Y { \n" + + " protected abstract void foo(); \n" + // takes precedence over inherited abstract Y.foo() + " } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " public class X extends q.Y.Member { \n" + + " ^\n" + + "This class must implement the inherited abstract method Y.bar(), but cannot override it since it is not visible from X. Either make the type abstract or make the inherited method visible\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 4)\n" + + " public static class M extends X {} \n" + + " ^\n" + + "This class must implement the inherited abstract method Y.bar(), but cannot override it since it is not visible from M. Either make the type abstract or make the inherited method visible\n" + + "----------\n"); +} + +/* + * 31450 - non-visible abstract method fooling method verification - should not complain about foo() + */ +public void test042() { + this.runNegativeTest( + new String[] { + "p/X.java", //================================ + "package p; \n" + + "public class X extends q.Y.Member { \n" + + " public void foo() {} \n" + + " public static class M extends X {} \n" + + "} \n", + "q/Y.java", //================================ + "package q; \n" + + "public abstract class Y { \n" + + " abstract void foo(); \n" + + " abstract void bar(); \n" + + " public static abstract class Member extends Y { \n" + + " void foo(){} \n" + + " } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " public class X extends q.Y.Member { \n" + + " ^\n" + + "This class must implement the inherited abstract method Y.bar(), but cannot override it since it is not visible from X. Either make the type abstract or make the inherited method visible\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 3)\n" + + " public void foo() {} \n" + + " ^^^^^\n" + + "The method X.foo() does not override the inherited method from Y.Member since it is private to a different package\n" + + "----------\n" + + "3. ERROR in p\\X.java (at line 4)\n" + + " public static class M extends X {} \n" + + " ^\n" + + "This class must implement the inherited abstract method Y.bar(), but cannot override it since it is not visible from M. Either make the type abstract or make the inherited method visible\n" + + "----------\n"); +} + +public void test043() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " public interface Copyable extends Cloneable {\n" + + " public Object clone() throws CloneNotSupportedException;\n" + + " }\n" + + "\n" + + " public interface TestIf extends Copyable {\n" + + " }\n" + + "\n" + + " public static class ClassA implements Copyable {\n" + + " public Object clone() throws CloneNotSupportedException {\n" + + " return super.clone();\n" + + " }\n" + + " }\n" + + "\n" + + " public static class ClassB implements TestIf {\n" + + " public Object clone() throws CloneNotSupportedException {\n" + + " return super.clone();\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " Copyable o1 = new ClassA();\n" + + " ClassB o2 = new ClassB();\n" + + " TestIf o3 = o2;\n" + + " Object clonedObject;\n" + + " clonedObject = o1.clone();\n" + + " clonedObject = o2.clone();\n" + + " clonedObject = o3.clone();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +/* + * 62639 - check that missing member type is not noticed if no direct connection with compiled type + */ +public void test044() { + this.runConformTest( + new String[] { + "p/Dumbo.java", + "package p;\n" + + "public class Dumbo {\n" + + " public class Clyde { }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + // delete binary file Dumbo$Clyde (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "Dumbo$Clyde.class")); + + this.runConformTest( + new String[] { + "q/Main.java", + "package q;\n" + + "public class Main extends p.Dumbo {\n" + + " public static void main(String[] args) {\n" + + " p.Dumbo d;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, + null); +} +/* + * ensure that can still found binary member types at depth >=2 (enclosing name Dumbo$Clyde $ Fred) + */ +public void test045() { + this.runConformTest( + new String[] { + "p/Dumbo.java", + "package p;\n" + + "public class Dumbo {\n" + + " public class Clyde {\n" + + " public class Fred {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + this.runConformTest( + new String[] { + "q/Main.java", + "package q;\n" + + "public class Main extends p.Dumbo {\n" + + " public static void main(String[] args) {\n" + + " p.Dumbo.Clyde.Fred f;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS", + null, + false, + null); +} +public void test046() { + this.runNegativeTest( + new String[] { + "X.java", //================================ + "public class X {\n" + + " private XY foo(XY t) {\n" + + " System.out.println(t);\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X() {\n" + + " void run() {\n" + + " foo(new XY());\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" + + "class XY {\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " foo(new XY());\n" + + " ^^^\n" + + "Cannot make a static reference to the non-static method foo(XY) from the type X\n" + + "----------\n"); +} +public void test047() { + this.runConformTest( + new String[] { + "X.java", //================================ + "public class X extends SuperTest\n" + + "{\n" + + " public X()\n" + + " {\n" + + " super();\n" + + " }\n" + + " \n" + + " static void print(Object obj)\n" + + " {\n" + + " System.out.println(\"Object:\" + obj.toString());\n" + + " }\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " print(\"Hello world\");\n" + + " }\n" + + "}\n" + + "class SuperTest\n" + + "{\n" + + " SuperTest(){};\n" + + " static void print(String s)\n" + + " {\n" + + " System.out.println(\"String: \" + s);\n" + + " }\n" + + "}\n" }, + "String: Hello world"); +} +// 73740 - missing serialVersionUID diagnosis shouldn't trigger load of Serializable +public void test048() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " public static void main(String[] args) {\n"+ + " System.out.println(\"SUCCESS\");\n"+ + " }\n"+ + "}\n", + }, + "SUCCESS", + Util.concatWithClassLibs(OUTPUT_DIR, true/*output in front*/), + false, // do not flush output + null, // vm args + null, // options + new ICompilerRequestor() { + public void acceptResult(CompilationResult result) { + assertNotNull("missing reference information",result.simpleNameReferences); + char[] serializable = TypeConstants.JAVA_IO_SERIALIZABLE[2]; + for (int i = 0, length = result.simpleNameReferences.length; i < length; i++) { + char[] name = result.simpleNameReferences[i]; + if (CharOperation.equals(name, serializable)) + assertTrue("should not contain reference to Serializable", false); + } + } + }); +} +// 76682 - ClassCastException in qualified name computeConversion +public void test049() { + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "public class X\n" + + "{\n" + + " private String foo() {\n" + + " return \"Started \" + java.text.DateFormat.format(new java.util.Date());\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\r\n" + + " return \"Started \" + java.text.DateFormat.format(new java.util.Date());\r\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot make a static reference to the non-static method format(Date) from the type DateFormat\n" + + "----------\n"); +} +public void test050() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " X.Y.Z.foo();\n" + + " }\n" + + " static class Y {\n" + + " static class Z {\n" + + " static void foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} + +public void test051() { + this.runNegativeTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " args.finalize();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " args.finalize();\n" + + " ^^^^^^^^\n" + + "The method finalize() from the type Object is not visible\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=87463 +public void test052() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " public void test() {\n" + + " class C {\n" + + " public C() {\n" + + " }\n" + + " public void foo() {\n" + + " System.out.println(\"hello\");\n" + + " }\n" + + " }\n" + + " int n = 0;\n" + + " switch (n) {\n" + + " case 0 :\n" + + " if (true) {\n" + + " C c2 = new C();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=87463 - variation +public void test053() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "public class X {\n" + + " public void test() {\n" + + " int l = 1;\n" + + " switch(l) {\n" + + " case 1: \n" + + " class C {\n" + + " public C() {\n" + + " }\n" + + " public void foo() {\n" + + " System.out.println(\"hello\");\n" + + " }\n" + + " }\n" + + " int n = 0;\n" + + " switch (n) {\n" + + " case 0 :\n" + + " if (true) {\n" + + " C c2 = new C();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=93486 +public void test054() { + this.runConformTest( + new String[] { + "X.java", //--------------------------- + "import java.util.LinkedHashMap;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class X {\n" + + " \n" + + " private LinkedHashMap fCache;\n" + + " \n" + + " public X(final int cacheSize) {\n" + + " // start with 100 elements but be able to grow until cacheSize\n" + + " fCache= new LinkedHashMap(100, 0.75f, true) {\n" + + " /** This class is not intended to be serialized. */\n" + + " private static final long serialVersionUID= 1L;\n" + + " protected boolean removeEldestEntry(Entry eldest) {\n" + + " return size() > cacheSize;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=106140 +public void test055() { + this.runNegativeTest( + new String[] { + "A.java", + "import p.*;\n" + + "public class A {\n" + + " public void errors() {\n" + + " B b = new B();\n" + + " String s1 = b.str;\n" + + " String s2 = B.str;\n" + + " }\n" + + "}\n", + "p/B.java", + "package p;\n" + + "class B {\n" + + " public static String str;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in A.java (at line 4)\n" + + " B b = new B();\n" + + " ^\n" + + "The type B is not visible\n" + + "----------\n" + + "2. ERROR in A.java (at line 4)\n" + + " B b = new B();\n" + + " ^\n" + + "The type B is not visible\n" + + "----------\n" + + "3. ERROR in A.java (at line 5)\n" + + " String s1 = b.str;\n" + + " ^\n" + + "The type B is not visible\n" + + "----------\n" + + "4. ERROR in A.java (at line 6)\n" + + " String s2 = B.str;\n" + + " ^\n" + + "The type B is not visible\n" + + "----------\n"); +} +// final method in static inner class still found in extending classes +public void test056() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I x = new Z();\n" + + " x.foo();\n" + + " }\n" + + " static interface I {\n" + + " Y foo();\n" + + " }\n" + + " static class Y {\n" + + " public final Y foo() { \n" + + " System.out.println(\"SUCCESS\");\n" + + " return null; \n" + + " }\n" + + " }\n" + + " static class Z extends Y implements I {\n" + + " // empty\n" + + " }\n" + + "}", + }, + "SUCCESS"); +} +// unresolved type does not fool methods signature comparison +public void test057() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.awt.*;\n" + + "public class X {\n" + + " public void foo(Window w) {\n" + + " // empty\n" + + " }\n" + + " public void foo(Applet a) {\n" + + " // empty\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public void foo(Applet a) {\n" + + " ^^^^^^\n" + + "Applet cannot be resolved to a type\n" + + "----------\n" + ); +} +public void test058() { + this.runConformTest( + new String[] { + "p/X.java", // ================= + "package p;\n" + + "\n" + + "import p.q.Z;\n" + + "public class X { \n" + + " public static void main(String argv[]) {\n" + + " System.out.println(Z.z);\n" + + " }\n" + + "}", // ================= + "p/q/Z.java", // ================= + "package p.q;\n" + + "\n" + + "public class Z extends Y implements I { \n" + + "}\n" + + "class Y {\n" + + " protected static int z = 1;\n" + + "}\n" + + "interface I {\n" + + " int z = 0;\n" + + "}", // ================= + }, + "0"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=132813 +public void test059() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " \n" + + " void aa(int i) {\n" + + " }\n" + + " void aa(long l) {\n" + + " }\n" + + " Zork bb() {\n" + + " }\n" + + " void cc() {\n" + + " this.bb();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork bb() {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " this.bb();\n" + + " ^^\n" + + "The method bb() from the type X refers to the missing type Zork\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=132813 - variation +public void test060() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " \n" + + " void aa(int i) {\n" + + " }\n" + + " Zork aa(long l) {\n" + + " }\n" + + " Zork bb() {\n" + + " }\n" + + " void cc() {\n" + + " this.bb();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork aa(long l) {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork bb() {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " this.bb();\n" + + " ^^\n" + + "The method bb() from the type X refers to the missing type Zork\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134839 +public void test061() { + Map options = getCompilerOptions(); + if (CompilerOptions.VERSION_1_3.equals(options.get(CompilerOptions.OPTION_Compliance))) { + // ensure target is 1.1 for having default abstract methods involved + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1); + } + this.runConformTest( + new String[] { + "X.java", // ================= + "interface MyInterface {\n" + + " public void writeToStream();\n" + + " public void readFromStream();\n" + + "}\n" + + "\n" + + "public abstract class X implements MyInterface {\n" + + " public void b() {\n" + + " }\n" + + " public void a() {\n" + + " writeTypeToStream();\n" + + " }\n" + + " private void writeTypeToStream() {\n" + + " }\n" + + "}\n", // ================= + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=134839 +public void test062() { + Map options = getCompilerOptions(); + if (CompilerOptions.VERSION_1_3.equals(options.get(CompilerOptions.OPTION_Compliance))) { + // ensure target is 1.1 for having default abstract methods involved + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1); + } + this.runConformTest( + new String[] { + "X.java", // ================= + "interface MyInterface {\n" + + " public void writeToStream();\n" + + " public void readFromStream();\n" + + "}\n" + + "\n" + + "public abstract class X implements MyInterface {\n" + + " public void b() {\n" + + " }\n" + + " public void a() {\n" + + " writeTypeToStream();\n" + + " }\n" + + " private void writeTypeToStream() {\n" + + " }\n" + + "}\n", // ================= + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=135292 +public void test063() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "class 56 {\n" + + "\n" + + " private static class B {\n" + + " public static final String F = \"\";\n" + + " }\n" + + "\n" + + " private static class C {\n" + + " }\n" + + "\n" + + " public void foo() {\n" + + " System.out.println(B.F);\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class 56 {\n" + + " ^^\n" + + "Syntax error on token \"56\", Identifier expected\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " private static class B {\n" + + " ^\n" + + "Illegal modifier for the class B; only public, abstract & final are permitted\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " private static class C {\n" + + " ^\n" + + "Illegal modifier for the class C; only public, abstract & final are permitted\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " System.out.println(B.F);\n" + + " ^^^\n" + + "The type B is not visible\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=137744 +public void test064() { + Map options = getCompilerOptions(); + if (CompilerOptions.VERSION_1_3.equals(options.get(CompilerOptions.OPTION_Compliance))) { + // ensure target is 1.1 for having default abstract methods involved + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1); + } + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " B a = new C();\n" + + " \n" + + " a.hasKursAt(1);\n" + + " }\n" + + "\n" + + "}", + "A.java", + "abstract public class A implements IA0 {\n" + + " int t;\n" + + " public A() {\n" + + " }\n" + + "}", + "B.java", + "abstract public class B extends A implements IA3, IA1 {\n" + + " int a;\n" + + " public B() {\n" + + " }\n" + + " public void test() { \n" + + " }\n" + + "}", + "C.java", + "public class C extends B implements IA4, IA2{\n" + + " int c;\n" + + " public C() {\n" + + " }\n" + + " public boolean hasKursAt(int zeitpunkt) {\n" + + " return false;\n" + + " }\n" + + "}", + "IA0.java", + "public interface IA0 {\n" + + " public void test();\n" + + "}", + "IA1.java", + "public interface IA1 extends IA0 {\n" + + " public boolean hasKursAt(int zeitpunkt);\n" + + "}", + "IA2.java", + "public interface IA2 extends IA0 {\n" + + " public boolean hasKursAt(int zeitpunkt);\n" + + "}", + "IA3.java", + "public interface IA3 extends IA2 {\n" + + "}", + "IA4.java", + "public interface IA4 extends IA3 {\n" + + "}" + }, + "SUCCESS", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=135323 +public void test065() { + this.runConformTest( + new String[] { + "com/internap/other/ScopeExample.java",//=================== + "package com.internap.other;\n" + + "import com.internap.*;\n" + + "public class ScopeExample {\n" + + " private static final String LOGGER = \"SUCCESS\";\n" + + " public static void main(String[] args) {\n" + + " PublicAccessSubclass sub = new PublicAccessSubclass() {\n" + + " public void implementMe() {\n" + + " System.out.println(LOGGER);\n" + + " }\n" + + " };\n" + + " sub.implementMe();\n" + + " }\n" + + "}", + "com/internap/PublicAccessSubclass.java",//=================== + "package com.internap;\n" + + "public abstract class PublicAccessSubclass extends DefaultAccessSuperclass {\n" + + " public abstract void implementMe(); \n" + + "}", + "com/internap/DefaultAccessSuperclass.java",//=================== + "package com.internap;\n" + + "class DefaultAccessSuperclass {\n" + + " private static final String LOGGER = \"FAILED\";\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=135323 - variation +public void test066() { + this.runConformTest( + new String[] { + "com/internap/other/ScopeExample.java",//=================== + "package com.internap.other;\n" + + "import com.internap.*;\n" + + "public class ScopeExample {\n" + + " private static final String LOGGER() { return \"SUCCESS\"; }\n" + + " public static void main(String[] args) {\n" + + " PublicAccessSubclass sub = new PublicAccessSubclass() {\n" + + " public void implementMe() {\n" + + " System.out.println(LOGGER());\n" + + " }\n" + + " };\n" + + " sub.implementMe();\n" + + " }\n" + + "}", + "com/internap/PublicAccessSubclass.java",//=================== + "package com.internap;\n" + + "public abstract class PublicAccessSubclass extends DefaultAccessSuperclass {\n" + + " public abstract void implementMe(); \n" + + "}", + "com/internap/DefaultAccessSuperclass.java",//=================== + "package com.internap;\n" + + "class DefaultAccessSuperclass {\n" + + " private static final String LOGGER() { return \"FAILED\"; }\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=135323 - variation +public void test067() { + Map options = getCompilerOptions(); + if (CompilerOptions.VERSION_1_3.equals(options.get(CompilerOptions.OPTION_Compliance))) { + this.runNegativeTest( + new String[] { + "com/internap/other/ScopeExample.java",//=================== + "package com.internap.other;\n" + + "import com.internap.*;\n" + + "public class ScopeExample {\n" + + " private static final String LOGGER = \"FAILED\";\n" + + " public static void main(String[] args) {\n" + + " PublicAccessSubclass sub = new PublicAccessSubclass() {\n" + + " public void implementMe() {\n" + + " System.out.println(LOGGER);\n" + + " }\n" + + " };\n" + + " sub.implementMe();\n" + + " }\n" + + "}", + "com/internap/PublicAccessSubclass.java",//=================== + "package com.internap;\n" + + "public abstract class PublicAccessSubclass extends DefaultAccessSuperclass {\n" + + " public abstract void implementMe(); \n" + + "}", + "com/internap/DefaultAccessSuperclass.java",//=================== + "package com.internap;\n" + + "class DefaultAccessSuperclass {\n" + + " public static final String LOGGER = \"SUCCESS\";\n" + + "}", + }, + "----------\n" + + "1. WARNING in com\\internap\\other\\ScopeExample.java (at line 4)\r\n" + + " private static final String LOGGER = \"FAILED\";\r\n" + + " ^^^^^^\n" + + "The value of the field ScopeExample.LOGGER is not used\n" + + "----------\n" + + "2. ERROR in com\\internap\\other\\ScopeExample.java (at line 8)\r\n" + + " System.out.println(LOGGER);\r\n" + + " ^^^^^^\n" + + "The field LOGGER is defined in an inherited type and an enclosing scope \n" + + "----------\n"); + return; + } + this.runConformTest( + new String[] { + "com/internap/other/ScopeExample.java",//=================== + "package com.internap.other;\n" + + "import com.internap.*;\n" + + "public class ScopeExample {\n" + + " private static final String LOGGER = \"FAILED\";\n" + + " public static void main(String[] args) {\n" + + " PublicAccessSubclass sub = new PublicAccessSubclass() {\n" + + " public void implementMe() {\n" + + " System.out.println(LOGGER);\n" + + " }\n" + + " };\n" + + " sub.implementMe();\n" + + " }\n" + + "}", + "com/internap/PublicAccessSubclass.java",//=================== + "package com.internap;\n" + + "public abstract class PublicAccessSubclass extends DefaultAccessSuperclass {\n" + + " public abstract void implementMe(); \n" + + "}", + "com/internap/DefaultAccessSuperclass.java",//=================== + "package com.internap;\n" + + "class DefaultAccessSuperclass {\n" + + " public static final String LOGGER = \"SUCCESS\";\n" + + "}", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139099 +public void test068() { + Map options = getCompilerOptions(); + CompilerOptions compOptions = new CompilerOptions(options); + if (compOptions.complianceLevel < ClassFileConstants.JDK1_5) return; + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + this.runConformTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X l = new X();\n" + + " StringBuffer sb = new StringBuffer();\n" + + " sb.append(l);\n" + + " }\n" + + "}", // =================, + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139099 +public void test068a() { + Map options = getCompilerOptions(); + CompilerOptions compOptions = new CompilerOptions(options); + if (compOptions.complianceLevel < ClassFileConstants.JDK1_5) return; + + this.runConformTest( + new String[] { + "X1.java", + "public class X1 { X1 foo() { return null; } }\n" + + "class X2 extends X1 { X2 foo() { return null; } }\n" + + "class Y { public X2 foo() { return null; } }\n" + + "interface I { X1 foo(); }\n" + + "class Z extends Y implements I {}", + }, + ""); + this.runConformTest( + new String[] { + "Test.java",//=================== + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " X1 x = new X2().foo();\n" + + " X2 xx = new X2().foo();\n" + + " X1 z = new Z().foo();\n" + + " X2 zz = new Z().foo();\n" + + " }\n" + + "}", // =================, + }, + "", + null, + false, + null); + + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + this.runConformTest( + new String[] { + "Test14.java",//=================== + "public class Test14 {\n" + + " public static void main(String[] args) {\n" + + " X1 x = new X2().foo();\n" + + " X2 xx = new X2().foo();\n" + + " X1 z = new Z().foo();\n" + + " X2 zz = new Z().foo();\n" + + " }\n" + + "}", // =================, + }, + "", + null, + false, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=139099 - variation +public void test069() { + this.runConformTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X l = new X();\n" + + " StringBuffer sb = new StringBuffer();\n" + + " sb.append(l);\n" + + " }\n" + + "}", // =================, + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=140643 +public void test070() { + this.runConformTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " interface I {\n" + + " }\n" + + "\n" + + " void test() {\n" + + " new I() {\n" + + " void foo() {\n" + + " }\n" + + " }.foo(); // compiles OK.\n" + + " new I() {\n" + + " void $foo() {\n" + + " }\n" + + " }.$foo(); // The method $foo() is undefined for the type new T.I(){}\n" + + " }\n" + + "}", // ================= + }, + ""); +} +// using $ in the name of a class defined within another package +public void test071() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + "}", + "p/X$X.java", + "package p;\n" + + "public class X$X {\n" + + "}", + }, + ""); + this.runConformTest( + new String[] { + "Y.java", + "import p.*;\n" + + "public class Y {\n" + + " X$X f = new X$X();\n" + + "}", + }, + "", + null /* no extra class libraries */, + false /* do not flush output directory */, + null /* no vm arguments */, + null /* no custom options*/, + null /* no custom requestor*/, + false /* do not skip javac for this peculiar test */); +} +public void test072() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "public class X {\n" + + " void bar(AX ax) {\n" + + " ax.foo(null);\n" + + " }\n" + + " \n" + + "}\n" + + "interface IX {\n" + + " void foo(String s);\n" + + "}\n" + + "interface JX {\n" + + " void foo(Thread t);\n" + + "}\n" + + "abstract class AX implements IX, JX {\n" + + " public void foo(String s) {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " ax.foo(null);\n" + + " ^^^\n" + + "The method foo(String) is ambiguous for the type AX\n" + + "----------\n"); +} +public void test073() { + this.runNegativeTest( + new String[] { + "E.java",//=================== + "public class E {\n" + + " void run(int i) {}\n" + + " static class Inner {\n" + + " void run() { run(1); }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in E.java (at line 4)\n" + + " void run() { run(1); }\n" + + " ^^^\n" + + "The method run() in the type E.Inner is not applicable for the arguments (int)\n" + + "----------\n"); +} + +// was Compliance_1_x#test008 +public void test074() { + String[] sources = new String[] { + "p1/Test.java", + "package p1; \n"+ + "import Test2; \n" + + "import Test2.Member; \n" + + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " System.out.println(\"SUCCESS\"); \n" + + " } \n"+ + "} \n", + "Test2.java", + "public class Test2 { \n"+ + " public class Member { \n" + + " } \n"+ + "} \n" + }; + if (this.complianceLevel == ClassFileConstants.JDK1_3) { + runConformTest( + sources, + "SUCCESS"); + } else { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in p1\\Test.java (at line 2)\n" + + " import Test2; \n" + + " ^^^^^\n" + + "The import Test2 cannot be resolved\n" + + "----------\n" + + "2. ERROR in p1\\Test.java (at line 3)\n" + + " import Test2.Member; \n" + + " ^^^^^\n" + + "The import Test2 cannot be resolved\n" + + "----------\n"); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150758 +public void test075() { + this.runConformTest( + new String[] { + "package1/Test.java",//=================== + "package package1;\n" + + "import package2.MyList;\n" + + "public class Test {\n" + + " public void reproduce(String sortKey, boolean isAscending) {\n" + + " MyList recList = new MyList();\n" + + " recList.add(null);\n" + + " }\n" + + "}\n",//=================== + "package2/MyList.java",//=================== + "package package2;\n" + + "import java.util.AbstractList;\n" + + "import java.util.List;\n" + + "public class MyList extends AbstractList implements List {\n" + + " void add(Integer i) {\n" + + " }\n" + + " public Object get(int index) {\n" + + " return null;\n" + + " }\n" + + " public int size() {\n" + + " return 0;\n" + + " }\n" + + "}", // ================= + }, + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159543 +public void test076() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "p/Y.java", //=================== + "package p;\n" + + "public class Y {\n" + + " public static void foo(String s) {\n" + + " }\n" + + "}\n", //=================== + "q/X.java", //=================== + "package q;\n" + + "import static p.Y.foo;\n" + + "public class X {\n" + + " void foo() {\n" + + " }\n" + + " void bar() {\n" + + " foo(\"\");\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. ERROR in q\\X.java (at line 7)\n" + + " foo(\"\");\n" + + " ^^^\n" + + "The method foo() in the type X is not applicable for the arguments (String)\n" + + "----------\n"); + } +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159893 +public void test077() { + this.runConformTest( + new String[] { + "X.java", //=================== + "abstract class B {\n" + + " public String getValue(){\n" + + " return \"pippo\";\n" + + " }\n" + + "}\n" + + "class D {\n" + + " private String value;\n" + + " public D(String p_Value){\n" + + " value = p_Value;\n" + + " }\n" + + " private String getValue(){\n" + + " return \"pippoD\";\n" + + " }\n" + + "}\n" + + "public class X extends B {\n" + + " class C extends D{\n" + + " public C() {\n" + + " super(getValue());\n" + + " String s = getValue();\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159893 - variation +public void test078() { + this.runNegativeTest( + new String[] { + "X.java", //=================== + "class D {\n" + + " private String value;\n" + + " public D(String p_Value){\n" + + " value = p_Value;\n" + + " }\n" + + " private String getValue(){\n" + + " return \"pippoD\";\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " class C extends D{\n" + + " public C() {\n" + + " super(getValue());\n" + + " String s = getValue();\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " private String value;\n" + + " ^^^^^\n" + + "The value of the field D.value is not used\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " super(getValue());\n" + + " ^^^^^^^^\n" + + "The method getValue() from the type D is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " String s = getValue();\n" + + " ^^^^^^^^\n" + + "The method getValue() from the type D is not visible\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166354 +// ** +public void test079() { + this.runConformTest( + new String[] { + "X.java", //=================== + "abstract class Y {\n" + + " private void foo(boolean b) {\n" + + " System.out.println(\"Y\");\n" + + " return;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " private void foo(String s) {\n" + + " System.out.println(\"X\");\n" + + " return;\n" + + " }\n" + + " private class Z extends Y {\n" + + " public void bar(boolean b) {\n" + + " foo(\"Flag \" + b);\n" + + " X.this.foo(\"Flag \" + b);\n" + + " }\n" + + " }\n" + + " Z m = new Z();\n" + + " public static void main(String args[]) {\n" + + " new X().m.bar(true);\n" + + " }\n" + + "}", // ================= + }, + "X\nX"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=166354 +// variant +public void test080() { + this.runConformTest( + new String[] { + "X.java", //=================== + "abstract class Y {\n" + + " private void foo(String s) {\n" + + " System.out.println(\"Y\");\n" + + " return;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " private void foo(String s) {\n" + + " System.out.println(\"X\");\n" + + " return;\n" + + " }\n" + + " private class Z extends Y {\n" + + " public void bar(boolean b) {\n" + + " foo(\"Flag \" + b);\n" + + " X.this.foo(\"Flag \" + b);\n" + + " }\n" + + " }\n" + + " Z m = new Z();\n" + + " public static void main(String args[]) {\n" + + " new X().m.bar(true);\n" + + " }\n" + + "}", // ================= + }, + "X\nX"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=174588 +public void test081() { + this.runConformTest( + new String[] { + "X.java", //=================== + "public class X extends Y {\n" + + " public void set(int value) {\n" + + " System.out.println(\"set(\" + value + \")\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.set(1L);\n" + + " }\n" + + "}\n" + + "abstract class Y implements I {\n" + + " public void set(long value) {\n" + + " set((int)value);\n" + + " }\n" + + " public void set(double value) {\n" + + " set((int)value);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void set(int value);\n" + + " void set(long value);\n" + + "}\n", // ================= + }, + "set(1)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=174588 +// variant +public void test082() { + this.runConformTest( + new String[] { + "X.java", //=================== + "public class X extends Y {\n" + + " public void set(int value) {\n" + + " System.out.println(\"set(\" + value + \")\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.set(1L);\n" + + " }\n" + + "}\n" + + "abstract class Y implements I {\n" + + " public abstract void set(int value);\n" + + " public void set(long value) {\n" + + " set((int)value);\n" + + " }\n" + + " public void set(double value) {\n" + + " set((int)value);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void set(int value);\n" + + " void set(long value);\n" + + "}\n", // ================= + }, + "set(1)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=174588 +// variant +public void test083() { + String src[] = + new String[] { + "X.java", + "public class X extends Z {\n" + + " public void set(int value) {\n" + + " System.out.println(\"set(\" + value + \")\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.set(1L);\n" + + " }\n" + + "}\n" + + "abstract class Z extends Y {\n" + + " public void set(long value) {\n" + + " set((int)value);\n" + + " }\n" + + " public void set(double value) {\n" + + " set((int)value);\n" + + " }\n" + + "}\n" + + "abstract class Y implements I {\n" + + "}\n" + + "interface I {\n" + + " void set(int value);\n" + + " void set(long value);\n" + + "}\n", + }; + if (this.complianceLevel <= ClassFileConstants.JDK1_3) { + this.runNegativeTest( + src, + "----------\n" + + "1. ERROR in X.java (at line 12)\r\n" + + " set((int)value);\r\n" + + " ^^^\n" + + "The method set(long) is ambiguous for the type Z\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\r\n" + + " set((int)value);\r\n" + + " ^^^\n" + + "The method set(long) is ambiguous for the type Z\n" + + "----------\n"); + } else { + this.runConformTest( + src, + "set(1)"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=174588 +// variant +public void test084() { + this.runConformTest( + new String[] { + "X.java", //=================== + "public class X extends Y {\n" + + " public void set(int value, int i) {\n" + + " System.out.println(\"set(\" + value + \")\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.set(1L, 1);\n" + + " }\n" + + "}\n" + + "abstract class Y implements I {\n" + + " public void set(long value, int i) {\n" + + " set((int)value, i);\n" + + " }\n" + + " public void set(int i, double value) {\n" + + " set(i, (int)value);\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void set(int value, int i);\n" + + "}\n", // ================= + }, + "set(1)"); +} + +public void test086() { + this.runNegativeTest( + new String[] { + "X.java", //=================== + "public class X {\n" + + " public static void main(String[] arguments) {\n" + + " Y y = new Y();\n" + + " System.out.println(y.array[0]);\n" + + " System.out.println(y.length);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " private class Invisible {}\n" + + " Invisible[] array;\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.println(y.length);\n" + + " ^^^^^^\n" + + "length cannot be resolved or is not a field\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 - variation +public void _test087() { + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.*;\n" + + "/**\n" + + " * @see Private - Private is not visible here\n" + + " */\n" + + "public abstract class X implements X.Private, Secondary.SecondaryPrivate {\n" + + " /**\n" + + " * @see Private - Private is visible here\n" + + " */\n" + + " private static interface Private {}\n" + + " Private field;\n" + + "}\n" + + "class Secondary {\n" + + " private static interface SecondaryPrivate {}\n" + + "}\n", // ================= + }, + "done"); +} +public void test088() { + this.runNegativeTest( + new String[] { + "java/lang/Object.java", //=================== + "package java.lang;\n" + + "public class Object {\n" + + " public Object() {\n" + + " super();\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in java\\lang\\Object.java (at line 4)\n" + + " super();\n" + + " ^^^^^^^^\n" + + "super cannot be used in java.lang.Object\n" + + "----------\n"); +} + +public void test089() { + this.runNegativeTest( + new String[] { + "X.java", //=================== + "public class X {\n" + + " static class Member implements X {\n" + + " Member () {\n" + + " super();\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " static class Member implements X {\n" + + " ^\n" + + "The type X cannot be a superinterface of Member; a superinterface must be an interface\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239833 +public void test090() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public synchronized int f;\n" + + " public synchronized X() {}\n" + + " public volatile void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public synchronized int f;\n" + + " ^\n" + + "Illegal modifier for the field f; only public, protected, private, static, final, transient & volatile are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public synchronized X() {}\n" + + " ^^^\n" + + "Illegal modifier for the constructor in type X; only public, protected & private are permitted\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " public volatile void foo() {}\n" + + " ^^^^^\n" + + "Illegal modifier for the method foo; only public, protected, private, abstract, static, final, synchronized, native & strictfp are permitted\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 - variation +public void test091() { + this.runNegativeTest( + new String[] { + "foo/Test.java",//------------------------------ + "package foo;\n" + + "public class Test {\n" + + " public class M1 {\n" + + " public class M2 {}\n" + + " }\n" + + "}\n", + "bar/Test2.java",//------------------------------ + "package bar;\n" + + "import foo.Test;\n" + + "import Test.M1.M2;\n" + + "public class Test2 {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in bar\\Test2.java (at line 3)\n" + + " import Test.M1.M2;\n" + + " ^^^^\n" + + "The import Test cannot be resolved\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 - variation +public void test092() { + this.runNegativeTest( + new String[] { + "foo/Test.java",//------------------------------ + "package foo;\n" + + "public class Test {\n" + + " public class M1 {\n" + + " public class M2 {}\n" + + " }\n" + + "}\n", + "bar/Test2.java",//------------------------------ + "package bar;\n" + + "import foo.*;\n" + + "import Test.M1.M2;\n" + + "public class Test2 {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in bar\\Test2.java (at line 3)\n" + + " import Test.M1.M2;\n" + + " ^^^^\n" + + "The import Test cannot be resolved\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 - variation +public void test093() { + this.runNegativeTest( + new String[] { + "foo/Test.java",//------------------------------ + "package foo;\n" + + "public class Test {\n" + + " public class M1 {\n" + + " public class foo {}\n" + + " }\n" + + "}\n", + "bar/Test2.java",//------------------------------ + "package bar;\n" + + "import foo.Test;\n" + + "import Test.M1.foo;\n" + + "public class Test2 {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in bar\\Test2.java (at line 3)\n" + + " import Test.M1.foo;\n" + + " ^^^^\n" + + "The import Test cannot be resolved\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 - variation +public void test094() { + this.runConformTest( + new String[] { + "foo/Test.java",//------------------------------ + "package foo;\n" + + "public class Test {\n" + + " public class M1 {\n" + + " public class foo {}\n" + + " }\n" + + "}\n", + "bar/Test2.java",//------------------------------ + "package bar;\n" + + "import foo.Test.M1.foo;\n" + + "public class Test2 {\n" + + "}\n", + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=277965 +public void test095() { + this.runNegativeTest( + new String[] { + "p1/B.java", + "package p1;\n" + + "protected class B1 {}", + "X.java", // ================= + "public class X extends p1.B1 {}", + }, + "----------\n" + + "1. ERROR in p1\\B.java (at line 2)\n" + + " protected class B1 {}\n" + + " ^^\n" + + "Illegal modifier for the class B1; only public, abstract & final are permitted\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends p1.B1 {}\n" + + " ^^^^^\n" + + "The type p1.B1 is not visible\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id= 317212 +public void test096() { + this.runNegativeTest( + new String[] { + "p0/B.java",//------------------------------ + "package p0;\n" + + "public class B {\n" + + " public static A m() {\n" + + " return new A();\n" + + " }\n" + + "}\n" + + "class A {\n" + + " public class M {\n" + + " public M() {}\n" + + " }\n" + + "}\n", + "p1/C.java",//------------------------------ + "package p1;\n" + + "import p0.B;\n" + + "public class C {\n" + + " public static void main(String[] args) {\n" + + " B.m().new M();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in p1\\C.java (at line 5)\n" + + " B.m().new M();\n" + + " ^^^^^\n" + + "The type p0.A is not visible\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id= 317212 +public void test097() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in B.java (at line 6)\n" + + " public class M {\n" + + " ^\n" + + "The type B.A.M is never used locally\n" + + "----------\n" + + "2. WARNING in B.java (at line 7)\n" + + " public M() {}\n" + + " ^^^\n" + + "The constructor B.A.M() is never used locally\n" + + "----------\n" + + "3. ERROR in B.java (at line 13)\n" + + " B.m().new M();\n" + + " ^^^^^\n" + + "The type B$A is not visible\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in B.java (at line 3)\n" + + " return new B().new A();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Access to enclosing constructor B.A() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. WARNING in B.java (at line 6)\n" + + " public class M {\n" + + " ^\n" + + "The type B.A.M is never used locally\n" + + "----------\n" + + "3. WARNING in B.java (at line 7)\n" + + " public M() {}\n" + + " ^^^\n" + + "The constructor B.A.M() is never used locally\n" + + "----------\n" + + "4. ERROR in B.java (at line 13)\n" + + " B.m().new M();\n" + + " ^^^^^\n" + + "The type B$A is not visible\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "B.java",//------------------------------ + "public class B {\n" + + " public static A m() {\n" + + " return new B().new A();\n" + + " }\n" + + " private class A {\n" + + " public class M {\n" + + " public M() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "class C {\n" + + " public static void main(String[] args) {\n" + + " B.m().new M();\n" + + " }\n" + + "}\n", + }, + errMessage); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858 +public void test098() { + this.runConformTest( + new String[] { + "B.java",//------------------------------ + "class A {\n" + + " public final static class B {\n" + + " public final static String length = \"very long\";\n" + + " }\n" + + " private int [] B = new int[5];\n" + + "}\n" + + "public class B {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(A.B.length);\n" + + " }\n" + + "}\n", + }, + "very long"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858 +public void test099() { + this.runNegativeTest( + new String[] { + "B.java",//------------------------------ + "class A {\n" + + " public final static class B {\n" + + " public final static String length = \"very long\";\n" + + " }\n" + + " public int [] B = new int[5];\n" + + "}\n" + + "public class B {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(A.B.length);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in B.java (at line 9)\n" + + " System.out.println(A.B.length);\n" + + " ^^^^^^^^^^\n" + + "Cannot make a static reference to the non-static field A.B\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858 +public void test100() { + this.runConformTest( + new String[] { + "B.java",//------------------------------ + "class A {\n" + + " public final class B {\n" + + " public final String length = \"very long\";\n" + + " }\n" + + " public static int [] B = new int[5];\n" + + "}\n" + + "public class B {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(A.B.length);\n" + + " }\n" + + "}\n", + }, + "5"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858 +public void test101() { + this.runNegativeTest( + new String[] { + "B.java",//------------------------------ + "class A {\n" + + " private final class B {\n" + + " public final String length = \"very long\";\n" + + " }\n" + + " private int [] B = new int[5];\n" + + "}\n" + + "public class B {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(A.B.length);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in B.java (at line 2)\n" + + " private final class B {\n" + + " ^\n" + + "The type A.B is never used locally\n" + + "----------\n" + + "2. WARNING in B.java (at line 3)\n" + + " public final String length = \"very long\";\n" + + " ^^^^^^\n" + + "The value of the field A.B.length is not used\n" + + "----------\n" + + "3. WARNING in B.java (at line 5)\n" + + " private int [] B = new int[5];\n" + + " ^\n" + + "The value of the field A.B is not used\n" + + "----------\n" + + "4. ERROR in B.java (at line 9)\n" + + " System.out.println(A.B.length);\n" + + " ^\n" + + "The field A.B is not visible\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858 +public void test102() { + this.runNegativeTest( + new String[] { + "B.java",//------------------------------ + "class A {\n" + + " public final class B {\n" + + " private final String length = \"very long\";\n" + + " }\n" + + " private int [] B = new int[5];\n" + + "}\n" + + "public class B {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(A.B.length);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in B.java (at line 3)\n" + + " private final String length = \"very long\";\n" + + " ^^^^^^\n" + + "The value of the field A.B.length is not used\n" + + "----------\n" + + "2. WARNING in B.java (at line 5)\n" + + " private int [] B = new int[5];\n" + + " ^\n" + + "The value of the field A.B is not used\n" + + "----------\n" + + "3. ERROR in B.java (at line 9)\n" + + " System.out.println(A.B.length);\n" + + " ^^^^^^\n" + + "The field A.B.length is not visible\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956 +public void test103() { + Map options = getCompilerOptions(); + CompilerOptions compOptions = new CompilerOptions(options); + if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return; + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.x is not used\n" + + "----------\n" + + "2. WARNING in A.java (at line 4)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.B.x is not used\n" + + "----------\n" + + "3. WARNING in A.java (at line 5)\n" + + " private C c = new C() {\n" + + " ^\n" + + "The value of the field A.B.c is not used\n" + + "----------\n" + + "4. WARNING in A.java (at line 6)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new A.C(){} is never used locally\n" + + "----------\n" + + "5. WARNING in A.java (at line 12)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.C.x is not used\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.x is not used\n" + + "----------\n" + + "2. WARNING in A.java (at line 4)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.B.x is not used\n" + + "----------\n" + + "3. WARNING in A.java (at line 5)\n" + + " private C c = new C() {\n" + + " ^\n" + + "The value of the field A.B.c is not used\n" + + "----------\n" + + "4. WARNING in A.java (at line 6)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new A.C(){} is never used locally\n" + + "----------\n" + + "5. WARNING in A.java (at line 7)\n" + + " x = 3;\n" + + " ^\n" + + "Write access to enclosing field A.B.x is emulated by a synthetic accessor method\n" + + "----------\n" + + "6. WARNING in A.java (at line 12)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.C.x is not used\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "A.java",//------------------------------ + "public class A {\n" + + " private int x;\n" + + " static class B {\n" + + " private int x;\n" + + " private C c = new C() {\n" + + " void foo() {\n" + + " x = 3;\n" + + " }\n" + + " };\n" + + " }\n" + + " static class C {\n" + + " private int x;\n" + + " }\n" + + " }\n", + }, + errMessage); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956 +public void test104() { + Map options = getCompilerOptions(); + CompilerOptions compOptions = new CompilerOptions(options); + if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return; + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "A.java",//------------------------------ + "public class A {\n" + + " private int x;\n" + + " static class B {\n" + + " private int x;\n" + + " private C c = new C() {\n" + + " void foo() {\n" + + " x = 3;\n" + + " }\n" + + " };\n" + + " }\n" + + " static class C {\n" + + " public int x;\n" + + " }\n" + + " }\n", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.x is not used\n" + + "----------\n" + + "2. WARNING in A.java (at line 4)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.B.x is not used\n" + + "----------\n" + + "3. WARNING in A.java (at line 5)\n" + + " private C c = new C() {\n" + + " ^\n" + + "The value of the field A.B.c is not used\n" + + "----------\n" + + "4. WARNING in A.java (at line 6)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new A.C(){} is never used locally\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956 +public void test105() { + Map options = getCompilerOptions(); + CompilerOptions compOptions = new CompilerOptions(options); + if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return; + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.x is not used\n" + + "----------\n" + + "2. WARNING in A.java (at line 3)\n" + + " private C c = new C() {\n" + + " ^\n" + + "The value of the field A.c is not used\n" + + "----------\n" + + "3. WARNING in A.java (at line 4)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new A.C(){} is never used locally\n" + + "----------\n" + + "4. WARNING in A.java (at line 9)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.C.x is not used\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.x is not used\n" + + "----------\n" + + "2. WARNING in A.java (at line 3)\n" + + " private C c = new C() {\n" + + " ^\n" + + "The value of the field A.c is not used\n" + + "----------\n" + + "3. WARNING in A.java (at line 4)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new A.C(){} is never used locally\n" + + "----------\n" + + "4. WARNING in A.java (at line 5)\n" + + " x = 3;\n" + + " ^\n" + + "Write access to enclosing field A.x is emulated by a synthetic accessor method\n" + + "----------\n" + + "5. WARNING in A.java (at line 9)\n" + + " private int x;\n" + + " ^\n" + + "The value of the field A.C.x is not used\n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "A.java",//------------------------------ + "public class A {\n" + + " private int x;\n" + + " private C c = new C() {\n" + + " void foo() {\n" + + " x = 3;\n" + + " }\n" + + " };\n" + + " static class C {\n" + + " private int x;\n" + + " }\n" + + " }\n", + }, + errMessage); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=350738 +public void test106() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java",//------------------------------ + "import java.util.List;\n" + + "import java.util.Set;\n" + + "public class X {\n" + + " private static List foo1(Set set) {\n" + + " return foo1(set);\n" + + " }\n" + + " private static List foo3(Set set) {\n" + + " return foo3(set);\n" + + " }\n" + + "}\n", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " private static List foo1(Set set) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The method foo1(Set) from the type X is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " private static List foo3(Set set) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method foo3(Set) from the type X is never used locally\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} + +public void testBug537828() { + Map options = getCompilerOptions(); + CompilerOptions compOptions = new CompilerOptions(options); + if (compOptions.complianceLevel < ClassFileConstants.JDK1_4) return; + this.runConformTest( + new String[] { + "FieldBug.java",//------------------------------ + "class A {\n" + + " Object obj = \"A.obj\";\n" + + "}\n" + + "\n" + + "class B {\n" + + " private Object obj = \"B.obj\";\n" + + " public Object getObj() {return obj;}\n" + + "}\n" + + "\n" + + "public class FieldBug {\n" + + " Object obj = \"FieldBug.obj\";\n" + + "\n" + + " static class AA extends A {\n" + + " class BB extends B {\n" + + " Object n = obj;\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.println(new AA().new BB().n);\n" + + " }\n" + + "}", + }, + "A.obj"); +} +public static Class testClass() { return LookupTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MANIFEST.MF b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MANIFEST.MF new file mode 100644 index 0000000000..9409c2a73e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MANIFEST.MF @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Class-Path: calledあ.jar +Created-By: 1.6.0 (IBM Corporation) + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ManifestAnalyzerTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ManifestAnalyzerTest.java new file mode 100644 index 0000000000..ee44a24480 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ManifestAnalyzerTest.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2009, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Fabrice Matrat - initial contribution + * IBM Corporation - code review and integration + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +import org.eclipse.jdt.internal.compiler.util.ManifestAnalyzer; + +@SuppressWarnings({ "rawtypes" }) +public class ManifestAnalyzerTest extends AbstractRegressionTest { + + private static final String FIRST_JAR = "firstJar.jar"; + private static final String SECOND_JAR = "secondJar.jar"; + private static final String WHITESPACE = " "; + + ManifestAnalyzer manifestAnalyzer = new ManifestAnalyzer(); + + public ManifestAnalyzerTest(String name) { + super(name); + } + public void testWithOneJar() throws IOException { + String testWithOneJar = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\nBuild-Reference: Version toto"; + analyzeManifestContents(testWithOneJar); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + } + + private void analyzeManifestContents(String contents) throws IOException { + InputStream stream = new ByteArrayInputStream(contents.getBytes()); + try { + this.manifestAnalyzer.analyzeManifestContents(stream); + } finally { + stream.close(); + } + } + public void testWithOneJarWithWiteSpace() throws IOException { + String testWithOneJarWithWiteSpace = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "\nBuild-Reference: Version toto"; + analyzeManifestContents(testWithOneJarWithWiteSpace); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + } + + public void testWithSecondJarOnNextLine() throws IOException { + String testWithSecondJarOnNextLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\n"+ WHITESPACE + WHITESPACE +"secondJar.jar\nBuild-Reference: Version toto"; + analyzeManifestContents(testWithSecondJarOnNextLine); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithSecondJarOnTwoLine() throws IOException { + String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "second\n" + WHITESPACE + "Jar.jar\nBuild-Reference: Version toto"; + analyzeManifestContents(testWithSecondJarOnTwoLine); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithSecondJarOnTwoLine2() throws IOException { + String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "second\n" + WHITESPACE + WHITESPACE + "Jar.jar\nBuild-Reference: Version toto"; + analyzeManifestContents(testWithSecondJarOnTwoLine); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 3, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals("second", jars.get(1)); + assertEquals("Jar.jar", jars.get(2)); + } + + public void testWithSecondJarOnTwoLine3() throws IOException { + String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "second\n" + "Jar.jar\nBuild-Reference: Version toto"; + analyzeManifestContents(testWithSecondJarOnTwoLine); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals("second", jars.get(1)); + } + + public void testWithSecondJarOnTwoLine4() throws IOException { + String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\n" + "second\n" + WHITESPACE + "Jar.jar\nBuild-Reference: Version toto"; + analyzeManifestContents(testWithSecondJarOnTwoLine); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + } + + public void testWithSecondJarOnNextLine5() throws IOException { + String testWithSecondJarOnNextLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\n"+ WHITESPACE + "secondJar.jar\nBuild-Reference: Version toto"; + analyzeManifestContents(testWithSecondJarOnNextLine); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals(FIRST_JAR + SECOND_JAR, jars.get(0)); + } + + public void testWithSecondJarOnTwoLineEndedWithEOF() throws IOException { + String testWithSecondJarOnTwoLineEndedWithEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar"; + analyzeManifestContents(testWithSecondJarOnTwoLineEndedWithEOF); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + } + + public void testWithSecondJarOnTwoLineEndedWithEOF2() throws IOException { + String testWithSecondJarOnTwoLineEndedWithEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar\n"; + analyzeManifestContents(testWithSecondJarOnTwoLineEndedWithEOF); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithSecondJarOnTwoLineEndedWithWhiteSpaceEOF() throws IOException { + String testWithSecondJarOnTwoLineEndedWithWhiteSpaceEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar "; + analyzeManifestContents(testWithSecondJarOnTwoLineEndedWithWhiteSpaceEOF); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithSecondJarOnTwoLineEndedWithWhiteSpaceNewLineEOF() throws IOException { + String testWithSecondJarOnTwoLineEndedWithWhiteSpaceNewLineEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar \n"; + analyzeManifestContents(testWithSecondJarOnTwoLineEndedWithWhiteSpaceNewLineEOF); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithSecondJarOnTwoLineEndedWithNewLineEOF() throws IOException { + String testWithSecondJarOnTwoLineEndedWithNewLineEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar\n"; + analyzeManifestContents(testWithSecondJarOnTwoLineEndedWithNewLineEOF); + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 2, jars.size()); + assertEquals(FIRST_JAR, jars.get(0)); + assertEquals(SECOND_JAR, jars.get(1)); + } + + public void testWithOneJarUsingUTF8Name() throws IOException { + InputStream inputStream = ManifestAnalyzerTest.class.getResourceAsStream("MANIFEST.MF"); + try { + this.manifestAnalyzer.analyzeManifestContents(inputStream); + } finally { + inputStream.close(); + } + List jars = this.manifestAnalyzer.getCalledFileNames(); + assertEquals("Wrong size", 1, jars.size()); + assertEquals("called\u3042.jar", jars.get(0)); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodHandleTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodHandleTest.java new file mode 100644 index 0000000000..45c6d0b790 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodHandleTest.java @@ -0,0 +1,394 @@ +/******************************************************************************* + * Copyright (c) 2011, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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; + +/** + * Regression test for MethodHandle.invokeExact(..)/invokeGeneric(..) invocation + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +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; + } + + static { +// TESTS_NAMES = new String [] { "test009" }; + } + + 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.invoke(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.invoke(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 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.invoke(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 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.invoke(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 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.invoke(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"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=386259, wrong unnecessary cast warning. + public void test009() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.invoke.MethodType;\n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " String str = \"test\";\n" + + " MethodHandle mh = MethodHandles.lookup().findVirtual(String.class, \"toString\", \n" + + " MethodType.methodType(String.class));\n" + + " String actual = (String) mh.invoke(str);\n" + + " assert \"test\".equals(actual);\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=386259 variation. + public void test010() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.invoke.MethodType;\n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " String str = \"test\";\n" + + " MethodHandle mh = MethodHandles.lookup().findVirtual(String.class, \"toString\", \n" + + " MethodType.methodType(String.class));\n" + + " Object actual = (Object) mh.invoke(str);\n" + + " assert \"test\".equals(actual);\n" + + " Zork z;\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Object actual = (Object) mh.invoke(str);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object to Object\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=466748 + public void test011() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.lang.invoke.MethodHandles;\n" + + "import java.lang.reflect.Method;\n" + + "\n" + + "public class X {\n" + + " public static void test1(Integer i){\n" + + " System.out.println(\"test1:\" + i);\n" + + " }\n" + + " public static void test2(int i){\n" + + " System.out.println(\"test2:\" + i);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws Throwable{\n" + + " Method m1 = X.class.getMethod(\"test1\", Integer.class);\n" + + " Method m2 = X.class.getMethod(\"test2\", int.class);\n" + + "\n" + + " MethodHandle test1Handle = MethodHandles.lookup().unreflect(m1);\n" + + " MethodHandle test2Handle = MethodHandles.lookup().unreflect(m2);\n" + + " \n" + + " Integer arg_Integer = 1;\n" + + " int arg_int = 1;\n" + + " \n" + + " // results in a java.lang.VerifyError - but should work without error\n" + + " test1Handle.invokeExact(Integer.class.cast(arg_int));\n" + + " \n" + + " // The following line also results in a java.lang.VerifyError, but should actually throw a ClassCastException\n" + + " try {\n" + + " test2Handle.invokeExact(int.class.cast(arg_Integer)); \n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}" + }, + "test1:1\n" + + "SUCCESS"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodParametersAttributeTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodParametersAttributeTest.java new file mode 100644 index 0000000000..80c29c67e6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodParametersAttributeTest.java @@ -0,0 +1,985 @@ +/******************************************************************************* + * Copyright (c) 2013, 2018 Jesper Steen Moeller and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jesper Steen Moeller - initial API and implementation + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type + * + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import junit.framework.Test; + +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.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +public class MethodParametersAttributeTest extends AbstractRegressionTest { + String versionString = null; + public MethodParametersAttributeTest(String name) { + super(name); + } + // No need for a tearDown() + @Override + protected void setUp() throws Exception { + super.setUp(); + this.versionString = AbstractCompilerTest.getVersionString(this.complianceLevel); + } + @SuppressWarnings("rawtypes") + public static Class testClass() { + return MethodParametersAttributeTest.class; + } + + // Use this static initializer to specify subset for tests + // All specified tests which does not belong to the class are skipped... + static { +// TESTS_PREFIX = "test012"; +// TESTS_NAMES = new String[] { "testBug359495" }; +// TESTS_NUMBERS = new int[] { 53 }; +// TESTS_RANGE = new int[] { 23 -1,}; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + + String originalSource = + "import java.util.concurrent.Callable;\n" + + "\n" + + "public class ParameterNames {\n" + + " \n" + + " public void someMethod(int simple, final double complex) {\n" + + " }\n" + + " \n" + + " public Callable makeInnerWithCapture(final String finalMessage, String mutableMessage) {\n" + + " return new Callable() {\n" + + " public String call() throws Exception {\n" + + " return finalMessage;\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " public int localMath(final String finalMessage, String mutableMessage) {\n" + + " int capturedB = 42;\n" + + " \n" + + " class Local {\n" + + " int fieldA;\n" + + " Local(int a) {\n" + + " this.fieldA = a;\n" + + " }\n" + + " int calculate(final int parameterC) {\n" + + " return this.fieldA + capturedB + parameterC;\n" + + " }\n" + + " }\n" + + " \n" + + " return new Local(2).calculate(3);\n" + + " }\n" + + "\n" + + "}\n" + + ""; + + public void test001() throws Exception { + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "ParameterNames.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "// Compiled from ParameterNames.java (version 1.8 : 52.0, super bit)\n" + + "public class ParameterNames {\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public ParameterNames();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [1]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " \n" + + " // Method descriptor #16 (ID)V\n" + + " // Stack: 0, Locals: 4\n" + + " public void someMethod(int simple, double complex);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Method Parameters:\n" + + " simple\n" + + " final complex\n" + + " \n" + + " // Method descriptor #21 (Ljava/lang/String;Ljava/lang/String;)Ljava/util/concurrent/Callable;\n" + + " // Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/util/concurrent/Callable;\n" + + " // Stack: 4, Locals: 3\n" + + " public java.util.concurrent.Callable makeInnerWithCapture(java.lang.String finalMessage, java.lang.String mutableMessage);\n" + + " 0 new ParameterNames$1 [2]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 aload_1 [finalMessage]\n" + + " 6 invokespecial ParameterNames$1(ParameterNames, java.lang.String) [3]\n" + + " 9 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " Method Parameters:\n" + + " final finalMessage\n" + + " mutableMessage\n" + + " \n" + + " // Method descriptor #27 (Ljava/lang/String;Ljava/lang/String;)I\n" + + " // Stack: 5, Locals: 4\n" + + " public int localMath(java.lang.String finalMessage, java.lang.String mutableMessage);\n" + + " 0 bipush 42\n" + + " 2 istore_3\n" + + " 3 new ParameterNames$1Local [4]\n" + + " 6 dup\n" + + " 7 aload_0 [this]\n" + + " 8 iconst_2\n" + + " 9 iload_3\n" + + " 10 invokespecial ParameterNames$1Local(ParameterNames, int, int) [5]\n" + + " 13 iconst_3\n" + + " 14 invokevirtual ParameterNames$1Local.calculate(int) : int [6]\n" + + " 17 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 17]\n" + + " [pc: 3, line: 29]\n" + + " Method Parameters:\n" + + " final finalMessage\n" + + " mutableMessage\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #4 ParameterNames$1Local, outer class info: #0\n" + + " inner name: #9 Local, accessflags: 0 default],\n" + + " [inner class info: #2 ParameterNames$1, outer class info: #0\n" + + " inner name: #0, accessflags: 0 default]\n" + + "}"; + + + assertSubstring(actualOutput, expectedOutput); + } + public void test002() throws Exception { + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "ParameterNames$1.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "// Compiled from ParameterNames.java (version 1.8 : 52.0, super bit)\n" + + "// Signature: Ljava/lang/Object;Ljava/util/concurrent/Callable;\n" + + "class ParameterNames$1 implements java.util.concurrent.Callable {\n" + + " \n" + + " // Field descriptor #9 Ljava/lang/String;\n" + + " final synthetic java.lang.String val$finalMessage;\n" + + " \n" + + " // Field descriptor #11 LParameterNames;\n" + + " final synthetic ParameterNames this$0;\n" + + " \n" + + " // Method descriptor #13 (LParameterNames;Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " ParameterNames$1(ParameterNames this$0, java.lang.String val$finalMessage);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [this$0]\n" + + " 2 putfield ParameterNames$1.this$0 : ParameterNames [1]\n" + + " 5 aload_0 [this]\n" + + " 6 aload_2 [val$finalMessage]\n" + + " 7 putfield ParameterNames$1.val$finalMessage : java.lang.String [2]\n" + + " 10 aload_0 [this]\n" + + " 11 invokespecial java.lang.Object() [3]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " Method Parameters:\n" + + " final mandated this$0\n" + + " final synthetic val$finalMessage\n" + + " \n" + + " // Method descriptor #18 ()Ljava/lang/String;\n" + + " // Stack: 1, Locals: 1\n" + + " public java.lang.String call() throws java.lang.Exception;\n" + + " 0 aload_0 [this]\n" + + " 1 getfield ParameterNames$1.val$finalMessage : java.lang.String [2]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " \n" + + " // Method descriptor #21 ()Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 1\n" + + " public bridge synthetic java.lang.Object call() throws java.lang.Exception;\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual ParameterNames$1.call() : java.lang.String [4]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #5 ParameterNames$1, outer class info: #0\n" + + " inner name: #0, accessflags: 0 default]\n" + + " Enclosing Method: #27 #28 ParameterNames.makeInnerWithCapture(Ljava/lang/String;Ljava/lang/String;)Ljava/util/concurrent/Callable;\n" + + "}"; + + assertSubstring(actualOutput, expectedOutput); + } + + public void test003() throws Exception { + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "ParameterNames$1Local.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "// Compiled from ParameterNames.java (version 1.8 : 52.0, super bit)\n" + + "class ParameterNames$1Local {\n" + + " \n" + + " // Field descriptor #8 I\n" + + " int fieldA;\n" + + " \n" + + " // Field descriptor #8 I\n" + + " final synthetic int val$capturedB;\n" + + " \n" + + " // Field descriptor #11 LParameterNames;\n" + + " final synthetic ParameterNames this$0;\n" + + " \n" + + " // Method descriptor #13 (LParameterNames;II)V\n" + + " // Signature: (I)V\n" + + " // Stack: 2, Locals: 4\n" + + " ParameterNames$1Local(ParameterNames this$0, int val$capturedB, int a);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [this$0]\n" + + " 2 putfield ParameterNames$1Local.this$0 : ParameterNames [1]\n" + + " 5 aload_0 [this]\n" + + " 6 iload_3 [a]\n" + + " 7 putfield ParameterNames$1Local.val$capturedB : int [2]\n" + + " 10 aload_0 [this]\n" + + " 11 invokespecial java.lang.Object() [3]\n" + + " 14 aload_0 [this]\n" + + " 15 iload_2 [val$capturedB]\n" + + " 16 putfield ParameterNames$1Local.fieldA : int [4]\n" + + " 19 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 21]\n" + + " [pc: 14, line: 22]\n" + + " [pc: 19, line: 23]\n" + + " Method Parameters:\n" + + " final mandated this$0\n" + + " final synthetic val$capturedB\n" + + " a\n" + + " \n" + + " // Method descriptor #21 (I)I\n" + + " // Stack: 2, Locals: 2\n" + + " int calculate(int parameterC);\n" + + " 0 aload_0 [this]\n" + + " 1 getfield ParameterNames$1Local.fieldA : int [4]\n" + + " 4 aload_0 [this]\n" + + " 5 getfield ParameterNames$1Local.val$capturedB : int [2]\n" + + " 8 iadd\n" + + " 9 iload_1 [parameterC]\n" + + " 10 iadd\n" + + " 11 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 25]\n" + + " Method Parameters:\n" + + " final parameterC\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #5 ParameterNames$1Local, outer class info: #0\n" + + " inner name: #33 Local, accessflags: 0 default]\n" + + " Enclosing Method: #26 #27 ParameterNames.localMath(Ljava/lang/String;Ljava/lang/String;)I\n" + + "}"; + + assertSubstring(actualOutput, expectedOutput); + } + + public void test004() throws Exception { + + // Test the results of the ClassFileReader + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "ParameterNames.class"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = ClassFileReader.read(path); + IBinaryMethod[] methodInfos = classFileReader.getMethods(); + assertNotNull("No method infos", methodInfos); + int length = methodInfos.length; + assertEquals("Must have four methods", 4, length); + assertEquals("finalMessage", new String(methodInfos[2].getArgumentNames()[0])); + assertEquals("mutableMessage", new String(methodInfos[2].getArgumentNames()[1])); + } + + public void test005() throws Exception { + // Test the results of the ClassFileReader where some of the paramers are synthetic and/or mandated + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "ParameterNames$1Local.class"; + + org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader classFileReader = ClassFileReader.read(path); + IBinaryMethod[] methodInfos = classFileReader.getMethods(); + assertNotNull("No method infos", methodInfos); + int length = methodInfos.length; + assertEquals("Must have two methods", 2, length); + assertEquals("this$0", new String(methodInfos[0].getArgumentNames()[0])); + assertEquals("val$capturedB", new String(methodInfos[0].getArgumentNames()[1])); + } + public void test006() throws Exception { + // Test that the code generator can emit the names, so the ClassFileReader may read them back + + this.runParameterNameTest( + "X.java", + "public class X {\n" + + " X(int wholeNumber) {\n" + + " }\n" + + " void foo(final float pluggedTheHoles, boolean yesItFloats) {\n" + + " }\n" + + "}"); + + try { + ClassFileReader classFileReader = ClassFileReader.read(OUTPUT_DIR + File.separator + "X.class"); + IBinaryMethod[] methods = classFileReader.getMethods(); + assertNotNull("No methods", methods); + assertEquals("Wrong size", 2, methods.length); + assertEquals("Wrong name", "", new String(methods[0].getSelector())); + char[][] argumentNames = methods[0].getArgumentNames(); + assertEquals(" should have 1 parameter", 1, argumentNames.length); + assertEquals("wholeNumber", new String(argumentNames[0])); + assertEquals("Wrong name", "foo", new String(methods[1].getSelector())); + assertEquals("pluggedTheHoles", new String(methods[1].getArgumentNames()[0])); + assertEquals("yesItFloats", new String(methods[1].getArgumentNames()[1])); + } catch (ClassFormatException e) { + assertTrue(false); + } catch (IOException e) { + assertTrue(false); + } + } + + public void test007() throws Exception { + // Test that the code generator can emit the names, so the disassembler may read them back (same source as was compiled with javac) + + this.runParameterNameTest( + "ParameterNames.java", + this.originalSource); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = OUTPUT_DIR + File.separator + "ParameterNames.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String nestMembers = ""; + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.complianceLevel >= ClassFileConstants.JDK11) { + nestMembers = "\n" + + "Nest Members:\n" + + " #20 ParameterNames$1,\n" + + " #29 ParameterNames$1Local\n"; + } + String expectedOutput = + "// Compiled from ParameterNames.java (" + this.versionString + ", super bit)\n" + + "public class ParameterNames {\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public ParameterNames();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " \n" + + " // Method descriptor #12 (ID)V\n" + + " // Stack: 0, Locals: 4\n" + + " public void someMethod(int simple, double complex);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " Method Parameters:\n" + + " simple\n" + + " final complex\n" + + " \n" + + " // Method descriptor #17 (Ljava/lang/String;Ljava/lang/String;)Ljava/util/concurrent/Callable;\n" + + " // Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/util/concurrent/Callable;\n" + + " // Stack: 4, Locals: 3\n" + + " public java.util.concurrent.Callable makeInnerWithCapture(java.lang.String finalMessage, java.lang.String mutableMessage);\n" + + " 0 new ParameterNames$1 [20]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 aload_1 [finalMessage]\n" + + " 6 invokespecial ParameterNames$1(ParameterNames, java.lang.String) [22]\n" + + " 9 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " Method Parameters:\n" + + " final finalMessage\n" + + " mutableMessage\n" + + " \n" + + " // Method descriptor #28 (Ljava/lang/String;Ljava/lang/String;)I\n" + + " // Stack: 5, Locals: 4\n" + + " public int localMath(java.lang.String finalMessage, java.lang.String mutableMessage);\n" + + " 0 bipush 42\n" + + " 2 istore_3\n" + + " 3 new ParameterNames$1Local [29]\n" + + " 6 dup\n" + + " 7 aload_0 [this]\n" + + " 8 iconst_2\n" + + " 9 iload_3\n" + + " 10 invokespecial ParameterNames$1Local(ParameterNames, int, int) [31]\n" + + " 13 iconst_3\n" + + " 14 invokevirtual ParameterNames$1Local.calculate(int) : int [34]\n" + + " 17 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 17]\n" + + " [pc: 3, line: 29]\n" + + " Method Parameters:\n" + + " final finalMessage\n" + + " mutableMessage\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #20 ParameterNames$1, outer class info: #0\n" + + " inner name: #0, accessflags: 0 default],\n" + + " [inner class info: #29 ParameterNames$1Local, outer class info: #0\n" + + " inner name: #41 Local, accessflags: 0 default]\n" + + nestMembers + + "}"; + + assertSubstring(actualOutput, expectedOutput); + } + + public void test008() throws Exception { + // Test that the code generator can emit synthetic and mandated names, just to match javac as closely as possibly + + this.runParameterNameTest( + "ParameterNames.java", + this.originalSource); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = OUTPUT_DIR + File.separator + "ParameterNames$1.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String nestHost = ""; + CompilerOptions options = new CompilerOptions(getCompilerOptions()); + if (options.complianceLevel >= ClassFileConstants.JDK11) { + nestHost = "\n" + + "Nest Host: #36 ParameterNames\n"; + } + String expectedOutput = + "// Compiled from ParameterNames.java (" + this.versionString + ", super bit)\n" + + "// Signature: Ljava/lang/Object;Ljava/util/concurrent/Callable;\n" + + "class ParameterNames$1 implements java.util.concurrent.Callable {\n" + + " \n" + + " // Field descriptor #8 LParameterNames;\n" + + " final synthetic ParameterNames this$0;\n" + + " \n" + + " // Field descriptor #10 Ljava/lang/String;\n" + + " private final synthetic java.lang.String val$finalMessage;\n" + + " \n" + + " // Method descriptor #12 (LParameterNames;Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " ParameterNames$1(ParameterNames this$0, java.lang.String val$finalMessage);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [this$0]\n" + + " 2 putfield ParameterNames$1.this$0 : ParameterNames [14]\n" + + " 5 aload_0 [this]\n" + + " 6 aload_2 [val$finalMessage]\n" + + " 7 putfield ParameterNames$1.val$finalMessage : java.lang.String [16]\n" + + " 10 aload_0 [this]\n" + + " 11 invokespecial java.lang.Object() [18]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " Method Parameters:\n" + + " final mandated this$0\n" + + " final synthetic val$finalMessage\n" + + " \n" + + " // Method descriptor #24 ()Ljava/lang/String;\n" + + " // Stack: 1, Locals: 1\n" + + " public java.lang.String call() throws java.lang.Exception;\n" + + " 0 aload_0 [this]\n" + + " 1 getfield ParameterNames$1.val$finalMessage : java.lang.String [16]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " \n" + + " // Method descriptor #28 ()Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 1\n" + + " public bridge synthetic java.lang.Object call() throws java.lang.Exception;\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual ParameterNames$1.call() : java.lang.String [29]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + "\n" + + " Inner classes:\n" + + " [inner class info: #1 ParameterNames$1, outer class info: #0\n" + + " inner name: #0, accessflags: 0 default]\n" + + " Enclosing Method: #36 #38 ParameterNames.makeInnerWithCapture(Ljava/lang/String;Ljava/lang/String;)Ljava/util/concurrent/Callable;\n" + + nestHost + + "}" ; + + assertSubstring(actualOutput, expectedOutput); + } + + public void test009() throws Exception { + // Test that the code generator can emit synthetic and mandated names, just to match javac as closely as possibly + + this.runParameterNameTest( + "FancyEnum.java", + "\n" + + "public enum FancyEnum {\n" + + " ONE(1), TWO(2);\n" + + " \n" + + " private FancyEnum(final int v) { this.var = v; }\n" + + " int var;\n" + + "}\n" + + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = OUTPUT_DIR + File.separator + "FancyEnum.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "// Compiled from FancyEnum.java (" + this.versionString + ", super bit)\n" + + "// Signature: Ljava/lang/Enum;\n" + + "public final enum FancyEnum {\n" + + " \n" + + " // Field descriptor #6 LFancyEnum;\n" + + " public static final enum FancyEnum ONE;\n" + + " \n" + + " // Field descriptor #6 LFancyEnum;\n" + + " public static final enum FancyEnum TWO;\n" + + " \n" + + " // Field descriptor #9 I\n" + + " int var;\n" + + " \n" + + " // Field descriptor #11 [LFancyEnum;\n" + + " private static final synthetic FancyEnum[] ENUM$VALUES;\n" + + " \n" + + " // Method descriptor #13 ()V\n" + + " // Stack: 5, Locals: 0\n" + + " static {};\n" + + " 0 new FancyEnum [1]\n" + + " 3 dup\n" + + " 4 ldc [15]\n" + + " 6 iconst_0\n" + + " 7 iconst_1\n" + + " 8 invokespecial FancyEnum(java.lang.String, int, int) [16]\n" + + " 11 putstatic FancyEnum.ONE : FancyEnum [20]\n" + + " 14 new FancyEnum [1]\n" + + " 17 dup\n" + + " 18 ldc [22]\n" + + " 20 iconst_1\n" + + " 21 iconst_2\n" + + " 22 invokespecial FancyEnum(java.lang.String, int, int) [16]\n" + + " 25 putstatic FancyEnum.TWO : FancyEnum [23]\n" + + " 28 iconst_2\n" + + " 29 anewarray FancyEnum [1]\n" + + " 32 dup\n" + + " 33 iconst_0\n" + + " 34 getstatic FancyEnum.ONE : FancyEnum [20]\n" + + " 37 aastore\n" + + " 38 dup\n" + + " 39 iconst_1\n" + + " 40 getstatic FancyEnum.TWO : FancyEnum [23]\n" + + " 43 aastore\n" + + " 44 putstatic FancyEnum.ENUM$VALUES : FancyEnum[] [25]\n" + + " 47 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 28, line: 2]\n" + + " \n" + + " // Method descriptor #19 (Ljava/lang/String;II)V\n" + + " // Stack: 3, Locals: 4\n" + + " private FancyEnum(java.lang.String $enum$name, int $enum$ordinal, int v);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [$enum$name]\n" + + " 2 iload_2 [$enum$ordinal]\n" + + " 3 invokespecial java.lang.Enum(java.lang.String, int) [28]\n" + + " 6 aload_0 [this]\n" + + " 7 iload_3 [v]\n" + + " 8 putfield FancyEnum.var : int [31]\n" + + " 11 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Method Parameters:\n" + + " synthetic $enum$name\n" + + " synthetic $enum$ordinal\n" + + " final v\n" + + " \n" + + " // Method descriptor #38 ()[LFancyEnum;\n" + + " // Stack: 5, Locals: 3\n" + + " public static FancyEnum[] values();\n" + + " 0 getstatic FancyEnum.ENUM$VALUES : FancyEnum[] [25]\n" + + " 3 dup\n" + + " 4 astore_0\n" + + " 5 iconst_0\n" + + " 6 aload_0\n" + + " 7 arraylength\n" + + " 8 dup\n" + + " 9 istore_1\n" + + " 10 anewarray FancyEnum [1]\n" + + " 13 dup\n" + + " 14 astore_2\n" + + " 15 iconst_0\n" + + " 16 iload_1\n" + + " 17 invokestatic java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int) : void [39]\n" + + " 20 aload_2\n" + + " 21 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " \n" + + " // Method descriptor #46 (Ljava/lang/String;)LFancyEnum;\n" + + " // Stack: 2, Locals: 1\n" + + " public static FancyEnum valueOf(java.lang.String name);\n" + + " 0 ldc [1]\n" + + " 2 aload_0 [name]\n" + + " 3 invokestatic java.lang.Enum.valueOf(java.lang.Class, java.lang.String) : java.lang.Enum [47]\n" + + " 6 checkcast FancyEnum [1]\n" + + " 9 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Method Parameters:\n" + + " mandated name\n" + + "}"; + + assertSubstring(actualOutput, expectedOutput); + } + + public void test010() throws Exception { + // Test that the non private inner class gets a mandated enclosing instance parameter. + + this.runParameterNameTest( + "X.java", + "public class X {\n" + + " class Y {}\n" + + "}\n" + ); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = OUTPUT_DIR + File.separator + "X$Y.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " X$Y(X this$0);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [this$0]\n" + + " 2 putfield X$Y.this$0 : X [10]\n" + + " 5 aload_0 [this]\n" + + " 6 invokespecial java.lang.Object() [12]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " Method Parameters:\n" + + " final mandated this$0\n" + + "\n"; + + assertSubstring(actualOutput, expectedOutput); + } + + public void test011() throws Exception { + // Test that a private inner class does not get a mandated enclosing instance parameter. + + this.runParameterNameTest( + "X.java", + "public class X {\n" + + " private class Y {}\n" + + "}\n" + ); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = OUTPUT_DIR + File.separator + "X$Y.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " private X$Y(X this$0);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [this$0]\n" + + " 2 putfield X$Y.this$0 : X [10]\n" + + " 5 aload_0 [this]\n" + + " 6 invokespecial java.lang.Object() [12]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " Method Parameters:\n" + + " final synthetic this$0\n" + + "\n"; + + assertSubstring(actualOutput, expectedOutput); + } + + public void test012() throws Exception { + + this.runParameterNameTest( + "X.java", + "public class X {\n" + + " void foo() {\n" + + " new Y().new Z() {\n" + + " };\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " class Z {}\n" + + "}\n" + ); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = OUTPUT_DIR + File.separator + "X$1.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " X$1(X this$0, Y this$1);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [this$0]\n" + + " 2 putfield X$1.this$0 : X [10]\n" + + " 5 aload_0 [this]\n" + + " 6 aload_2 [this$1]\n" + + " 7 invokespecial Y$Z(Y) [12]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " Method Parameters:\n" + + " final synthetic this$0\n" + + " final mandated this$1\n" + + "\n"; + + assertSubstring(actualOutput, expectedOutput); + } + + public void test013() throws Exception { + // Test that synthesized enum constructor arguments show up as synthetic + + this.runParameterNameTest( + "FancyEnum.java", + "\n" + + "public enum FancyEnum {\n" + + " ONE, TWO;\n" + + "}\n" + + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = OUTPUT_DIR + File.separator + "FancyEnum.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " private FancyEnum(java.lang.String $enum$name, int $enum$ordinal);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [$enum$name]\n" + + " 2 iload_2 [$enum$ordinal]\n" + + " 3 invokespecial java.lang.Enum(java.lang.String, int) [26]\n" + + " 6 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " Method Parameters:\n" + + " synthetic $enum$name\n" + + " synthetic $enum$ordinal\n" + + " \n"; + + assertSubstring(actualOutput, expectedOutput); + } + + public void test014() throws Exception { + // Test that the name argument of enum valueOf shows up as mandated + + this.runParameterNameTest( + "FancyEnum.java", + "\n" + + "public enum FancyEnum {\n" + + " ONE, TWO;\n" + + "}\n" + + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = OUTPUT_DIR + File.separator + "FancyEnum.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " public static FancyEnum valueOf(java.lang.String name);\n" + + " 0 ldc [1]\n" + + " 2 aload_0 [name]\n" + + " 3 invokestatic java.lang.Enum.valueOf(java.lang.Class, java.lang.String) : java.lang.Enum [40]\n" + + " 6 checkcast FancyEnum [1]\n" + + " 9 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Method Parameters:\n" + + " mandated name\n"; + assertSubstring(actualOutput, expectedOutput); + } + + public void test015() throws Exception { + // Test that the name argument of enum valueOf shows up as mandated + + this.runParameterNameTest( + "InnerLocalClassTest.java", + "public class InnerLocalClassTest {\n" + + " void test() {\n" + + " class Local { }\n" + + " new Local() { };\n" + + " } \n" + + "}\n"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = OUTPUT_DIR + File.separator + "InnerLocalClassTest$1.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " InnerLocalClassTest$1(InnerLocalClassTest this$0, InnerLocalClassTest this$1);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_2 [this$1]\n" + + " 2 putfield InnerLocalClassTest$1.this$0 : InnerLocalClassTest [10]\n" + + " 5 aload_0 [this]\n" + + " 6 aload_1 [this$0]\n" + + " 7 invokespecial InnerLocalClassTest$1Local(InnerLocalClassTest) [12]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " Method Parameters:\n" + + " final synthetic this$0\n" + + " final synthetic this$1\n"; + assertSubstring(actualOutput, expectedOutput); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=476528 + public void test016() throws Exception { + // Test that the name argument of enum valueOf shows up as mandated + + this.runParameterNameTest( + "Foo.java", + "public enum Foo {\n" + + " BAR;\n" + + " public static Foo valueOf(int intParameter) {\n" + + " return BAR;\n" + + " }\n" + + " public static Foo valueOf2(int intParameter) {\n" + + " return BAR;\n" + + " } \n" + + "}\n"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String path = OUTPUT_DIR + File.separator + "Foo.class"; + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(path)); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Stack: 1, Locals: 1\n" + + " public static Foo valueOf(int intParameter);\n" + + " 0 getstatic Foo.BAR : Foo [17]\n" + + " 3 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " Method Parameters:\n" + + " intParameter\n" + + " \n" + + " // Method descriptor #27 (I)LFoo;\n" + + " // Stack: 1, Locals: 1\n" + + " public static Foo valueOf2(int intParameter);\n" + + " 0 getstatic Foo.BAR : Foo [17]\n" + + " 3 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Method Parameters:\n" + + " intParameter\n"; + assertSubstring(actualOutput, expectedOutput); + // Test that synthetic method gets the right parameter names + expectedOutput = + " public static Foo valueOf(java.lang.String name);\n" + + " 0 ldc [1]\n" + + " 2 aload_0 [name]\n" + + " 3 invokestatic java.lang.Enum.valueOf(java.lang.Class, java.lang.String) : java.lang.Enum [39]\n" + + " 6 checkcast Foo [1]\n" + + " 9 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Method Parameters:\n" + + " mandated name\n"; + assertSubstring(actualOutput, expectedOutput); + } + + private void runParameterNameTest(String fileName, String body) { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); + compilerOptions.put(CompilerOptions.OPTION_MethodParametersAttribute, CompilerOptions.GENERATE); + this.runConformTest( + new String[] { + fileName, + body + }, + compilerOptions /* custom options */ + ); + } + + private void assertSubstring(String actualOutput, String expectedOutput) { + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java new file mode 100644 index 0000000000..3cf5ff80e3 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java @@ -0,0 +1,14484 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * bug 388800 - [1.8] adjust tests to 1.8 JRE + * bug 388795 - [compiler] detection of name clash depends on order of super interfaces + * bug 388739 - [1.8][compiler] consider default methods when detecting whether a class needs to be declared abstract + * bug 402237 - [1.8][compiler] investigate differences between compilers re MethodVerifyTest + * bug 395681 - [compiler] Improve simulation of javac6 behavior from bug 317719 after fixing bug 388795 + * bug 409473 - [compiler] JDT cannot compile against JRE 1.8 + * Bug 410325 - [1.7][compiler] Generified method override different between javac and eclipse compiler + * Andy Clement - Contribution for + * bug 406928 - computation of inherited methods seems damaged (affecting @Overrides) + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.Flags; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.Excuse; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.IMethodInfo; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class MethodVerifyTest extends AbstractComparableTest { + static { +// TESTS_NAMES = new String[] { "test124", "test124b" }; +// TESTS_NUMBERS = new int[] { 124 }; +// TESTS_RANGE = new int[] { 190, -1}; + } + + public MethodVerifyTest(String name) { + super(name); + } + + public static Test suite() { + return buildComparableTestSuite(testClass()); + } + + public static Class testClass() { + return MethodVerifyTest.class; + } + + @Override + protected Map getCompilerOptions() { + Map compilerOptions = super.getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); + return compilerOptions; + } + + String mustOverrideMessage(String method, String type) { + return "The method " + method + " of type " + type + + (new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 + ? " must override a superclass method\n" + : " must override or implement a supertype method\n"); + } + public void test001() { + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y extends X { public void foo(T t) {} }\n" + + "class X { public void foo(U u) {} }\n" + + "class A {}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " public class Y extends X { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type Y has the same erasure as foo(U) of type X but does not override it\n" + + "----------\n" + // name clash: foo(T) in Y and foo(U) in X have the same erasure, yet neither overrides the other + ); + } + + public void test001a() { + this.runNegativeTest( + new String[] { + "J.java", + "public class J implements I { public void foo(T t) {} }\n" + + "interface I { public void foo(U u); }\n" + + "class A {}\n" + }, + "----------\n" + + "1. ERROR in J.java (at line 1)\n" + + " public class J implements I { public void foo(T t) {} }\n" + + " ^\n" + + "The type J must implement the inherited abstract method I.foo(A)\n" + + "----------\n" + + "2. ERROR in J.java (at line 1)\n" + + " public class J implements I { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type J has the same erasure as foo(U) of type I but does not override it\n" + + "----------\n" + // J is not abstract and does not override abstract method foo(A) in I + ); + } + public void test001b() { + this.runNegativeTest( + new String[] { + "YY.java", + "public class YY extends X { public void foo(T t) {} }\n" + + "class X { public void foo(U u) {} }\n" + }, + "----------\n" + + "1. WARNING in YY.java (at line 1)\n" + + " public class YY extends X { public void foo(T t) {} }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in YY.java (at line 1)\n" + + " public class YY extends X { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type YY has the same erasure as foo(Object) of type X but does not override it\n" + + "----------\n" + // name clash: foo(T) in YY and foo(U) in X have the same erasure, yet neither overrides the other + ); + } + public void test001c() { + this.runNegativeTest( + new String[] { + "JJ.java", + "public class JJ implements I { public void foo(T t) {} }\n" + + "interface I { public void foo(U u); }\n" + }, + "----------\n" + + "1. ERROR in JJ.java (at line 1)\n" + + " public class JJ implements I { public void foo(T t) {} }\n" + + " ^^\n" + + "The type JJ must implement the inherited abstract method I.foo(Object)\n" + + "----------\n" + + "2. WARNING in JJ.java (at line 1)\n" + + " public class JJ implements I { public void foo(T t) {} }\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "3. ERROR in JJ.java (at line 1)\n" + + " public class JJ implements I { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type JJ has the same erasure as foo(Object) of type I but does not override it\n" + + "----------\n" + // JJ is not abstract and does not override abstract method foo(java.lang.Object) in I + ); + } + public void test001d() { + this.runConformTest( + new String[] { + "YYY.java", + "public class YYY extends X { public void foo(T t) {} }\n" + + "class X { public void foo(U u) {} }\n" + }, + "" + ); + } + public void test001e() { + this.runConformTest( + new String[] { + "JJJ.java", + "public class JJJ implements I { public void foo(T t) {} }\n" + + "interface I { public void foo(U u); }\n" + }, + "" + ); + } + + public void test002() { // separate files + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y extends X { public void foo(T t) {} }\n" + + "class A {}\n", + "X.java", + "class X { public void foo(U u) {} }\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " public class Y extends X { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type Y has the same erasure as foo(U) of type X but does not override it\n" + + "----------\n" + // name clash: foo(T) in Y and foo(U) in X have the same erasure, yet neither overrides the other + ); + } + public void test002a() { // separate files + this.runNegativeTest( + new String[] { + "J.java", + "public class J implements I { public void foo(T t) {} }\n" + + "class A {}\n", + "I.java", + "interface I { public void foo(U u); }\n" + }, + "----------\n" + + "1. ERROR in J.java (at line 1)\n" + + " public class J implements I { public void foo(T t) {} }\n" + + " ^\n" + + "The type J must implement the inherited abstract method I.foo(A)\n" + + "----------\n" + + "2. ERROR in J.java (at line 1)\n" + + " public class J implements I { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type J has the same erasure as foo(U) of type I but does not override it\n" + + "----------\n" + // J is not abstract and does not override abstract method foo(A) in I + ); + } + public void test002b() { // separate files + this.runNegativeTest( + new String[] { + "YY.java", + "public class YY extends X { public void foo(T t) {} }\n", + "X.java", + "class X { public void foo(U u) {} }\n" + }, + "----------\n" + + "1. WARNING in YY.java (at line 1)\n" + + " public class YY extends X { public void foo(T t) {} }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in YY.java (at line 1)\n" + + " public class YY extends X { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type YY has the same erasure as foo(Object) of type X but does not override it\n" + + "----------\n" + // name clash: foo(T) in YY and foo(U) in X have the same erasure, yet neither overrides the other + ); + } + public void test002c() { // separate files + this.runNegativeTest( + new String[] { + "JJ.java", + "public class JJ implements I { public void foo(T t) {} }\n", + "I.java", + "interface I { public void foo(U u); }\n" + }, + "----------\n" + + "1. ERROR in JJ.java (at line 1)\n" + + " public class JJ implements I { public void foo(T t) {} }\n" + + " ^^\n" + + "The type JJ must implement the inherited abstract method I.foo(Object)\n" + + "----------\n" + + "2. WARNING in JJ.java (at line 1)\n" + + " public class JJ implements I { public void foo(T t) {} }\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "3. ERROR in JJ.java (at line 1)\n" + + " public class JJ implements I { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type JJ has the same erasure as foo(Object) of type I but does not override it\n" + + "----------\n" + // JJ is not abstract and does not override abstract method foo(java.lang.Object) in I + ); + } + public void test002d() { // separate files + this.runConformTest( + new String[] { + "YYY.java", + "public class YYY extends X { public void foo(T t) {} }\n", + "X.java", + "class X { public void foo(U u) {} }\n" + }, + "" + ); + } + public void test002e() { // separate files + this.runConformTest( + new String[] { + "JJJ.java", + "public class JJJ implements I { public void foo(T t) {} }\n", + "I.java", + "interface I { public void foo(U u); }\n" + }, + "" + ); + } + + public void test003() { // pick up superTypes as binaries + this.runConformTest( + new String[] { + "A.java", + "class A {}\n", + "B.java", + "class B {}\n", + "X.java", + "class X { public void foo(U u) {} }\n", + "I.java", + "interface I { public void foo(U u); }\n", + }, + "" + ); + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y extends X { public void foo(T t) {} }\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " public class Y extends X { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type Y has the same erasure as foo(U) of type X but does not override it\n" + + "----------\n", + // name clash: foo(T) in Y and foo(U) in X have the same erasure, yet neither overrides the other + null, + false, + null + ); + } + public void test003a() { // pick up superTypes as binaries + this.runConformTest( + new String[] { + "A.java", + "class A {}\n", + "B.java", + "class B {}\n", + "X.java", + "class X { public void foo(U u) {} }\n", + "I.java", + "interface I { public void foo(U u); }\n", + }, + "" + ); + this.runNegativeTest( + new String[] { + "J.java", + "public class J implements I { public void foo(T t) {} }\n" + }, + "----------\n" + + "1. ERROR in J.java (at line 1)\n" + + " public class J implements I { public void foo(T t) {} }\n" + + " ^\n" + + "The type J must implement the inherited abstract method I.foo(A)\n" + + "----------\n" + + "2. ERROR in J.java (at line 1)\n" + + " public class J implements I { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type J has the same erasure as foo(U) of type I but does not override it\n" + + "----------\n", + // J is not abstract and does not override abstract method foo(A) in I + null, + false, + null + ); + } + public void test003b() { + this.runConformTest( + new String[] { + "A.java", + "class A {}\n", + "B.java", + "class B {}\n", + "X.java", + "class X { public void foo(U u) {} }\n", + "I.java", + "interface I { public void foo(U u); }\n", + }, + "" + ); + this.runNegativeTest( + new String[] { + "YY.java", + "public class YY extends X { public void foo(T t) {} }\n" + }, + "----------\n" + + "1. WARNING in YY.java (at line 1)\n" + + " public class YY extends X { public void foo(T t) {} }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in YY.java (at line 1)\n" + + " public class YY extends X { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type YY has the same erasure as foo(Object) of type X but does not override it\n" + + "----------\n", + // name clash: foo(T) in YY and foo(U) in X have the same erasure, yet neither overrides the other + null, + false, + null + ); + } + public void test003c() { + this.runConformTest( + new String[] { + "A.java", + "class A {}\n", + "B.java", + "class B {}\n", + "X.java", + "class X { public void foo(U u) {} }\n", + "I.java", + "interface I { public void foo(U u); }\n", + }, + "" + ); + this.runNegativeTest( + new String[] { + "JJ.java", + "public class JJ implements I { public void foo(T t) {} }\n" + }, + "----------\n" + + "1. ERROR in JJ.java (at line 1)\n" + + " public class JJ implements I { public void foo(T t) {} }\n" + + " ^^\n" + + "The type JJ must implement the inherited abstract method I.foo(Object)\n" + + "----------\n" + + "2. WARNING in JJ.java (at line 1)\n" + + " public class JJ implements I { public void foo(T t) {} }\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "3. ERROR in JJ.java (at line 1)\n" + + " public class JJ implements I { public void foo(T t) {} }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type JJ has the same erasure as foo(Object) of type I but does not override it\n" + + "----------\n", + // JJ is not abstract and does not override abstract method foo(java.lang.Object) in I + null, + false, + null + ); + } + public void test003d() { + this.runConformTest( + new String[] { + "A.java", + "class A {}\n", + "B.java", + "class B {}\n", + "X.java", + "class X { public void foo(U u) {} }\n", + "I.java", + "interface I { public void foo(U u); }\n", + }, + "" + ); + this.runConformTest( + new String[] { + "YYY.java", + "public class YYY extends X { public void foo(T t) {} }\n" + }, + "", + null, + false, + null + ); + } + public void test003e() { + this.runConformTest( + new String[] { + "A.java", + "class A {}\n", + "B.java", + "class B {}\n", + "X.java", + "class X { public void foo(U u) {} }\n", + "I.java", + "interface I { public void foo(U u); }\n", + }, + "" + ); + this.runConformTest( + new String[] { + "JJJ.java", + "public class JJJ implements I { public void foo(T t) {} }\n" + }, + "", + null, + false, + null + ); + } + + public void test004() { // all together + this.runNegativeTest( + new String[] { + "ALL.java", + "class A {}\n" + + "class B {}\n" + + "class X { public U foo() {return null;} }\n" + + "interface I { public U foo(); }\n" + + + "class J implements I { public T foo() {return null;} }\n" + + "class K implements I { public T foo() {return null;} }\n" + + "class L implements I { public T foo() {return null;} }\n" + + + "class Y extends X { @Override public T foo() { return super.foo(); } }\n" + + "class Z extends X { @Override public T foo() { return super.foo(); } }\n" + + "class W extends X { @Override public T foo() { return super.foo(); } }\n", + }, + "----------\n" + + "1. ERROR in ALL.java (at line 5)\n" + + " class J implements I { public T foo() {return null;} }\n" + + " ^\n" + + "The return type is incompatible with I.foo()\n" + + "----------\n" + + "2. WARNING in ALL.java (at line 7)\n" + + " class L implements I { public T foo() {return null;} }\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "3. ERROR in ALL.java (at line 8)\n" + + " class Y extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^\n" + + "The return type is incompatible with X.foo()\n" + + "----------\n" + + "4. ERROR in ALL.java (at line 8)\n" + + " class Y extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from A to T\n" + + "----------\n" + + "5. WARNING in ALL.java (at line 10)\n" + + " class W extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "6. ERROR in ALL.java (at line 10)\n" + + " class W extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to T\n" + + "----------\n" + /* + ALL.java:5: J is not abstract and does not override abstract method foo() in I + ALL.java:5: foo() in J cannot implement foo() in I; attempting to use incompatible return type + ALL.java:8: foo() in Y cannot override foo() in X; attempting to use incompatible return type + ALL.java:8: incompatible types + found : A + required: T + class Y extends X { public T foo() { return super.foo(); } } + ^ + ALL.java:10: incompatible types + found : java.lang.Object + required: T + class W extends X { public T foo() { return super.foo(); } } + */ + ); + } + + public void test005() { // separate files + this.runNegativeTest( + new String[] { + "A.java", + "class A {}\n", + "B.java", + "class B {}\n", + "X.java", + "class X { public U foo() {return null;} }\n", + "I.java", + "interface I { public U foo(); }\n", + + "J.java", + "class J implements I { public T foo() {return null;} }\n", + "K.java", + "class K implements I { public T foo() {return null;} }\n", + "L.java", + "class L implements I { public T foo() {return null;} }\n", + + "Y.java", + "class Y extends X { @Override public T foo() { return super.foo(); } }\n", + "Z.java", + "class Z extends X { @Override public T foo() { return super.foo(); } }\n", + "W.java", + "class W extends X { @Override public T foo() { return super.foo(); } }\n", + }, + "----------\n" + + "1. ERROR in J.java (at line 1)\n" + + " class J implements I { public T foo() {return null;} }\n" + + " ^\n" + + "The return type is incompatible with I.foo()\n" + + "----------\n" + + "----------\n" + + "1. WARNING in L.java (at line 1)\n" + + " class L implements I { public T foo() {return null;} }\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " class Y extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^\n" + + "The return type is incompatible with X.foo()\n" + + "----------\n" + + "2. ERROR in Y.java (at line 1)\n" + + " class Y extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from A to T\n" + + "----------\n" + + "----------\n" + + "1. WARNING in W.java (at line 1)\n" + + " class W extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in W.java (at line 1)\n" + + " class W extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to T\n" + + "----------\n" + /* + J.java:1: J is not abstract and does not override abstract method foo() in I + J.java:1: foo() in J cannot implement foo() in I; attempting to use incompatible return type + W.java:1: incompatible types + found : java.lang.Object + required: T + class W extends X { public T foo() { return super.foo(); } } + Y.java:1: foo() in Y cannot override foo() in X; attempting to use incompatible return type + Y.java:1: incompatible types + found : A + required: T + class Y extends X { public T foo() { return super.foo(); } } + */ + ); + } + + public void test006() { // pick up superTypes as binaries + this.runConformTest( + new String[] { + "A.java", + "class A {}\n", + "B.java", + "class B {}\n", + "X.java", + "class X { public U foo() {return null;} }\n", + "I.java", + "interface I { public U foo(); }\n", + }, + "" + ); + this.runNegativeTest( + new String[] { + "J.java", + "class J implements I { public T foo() {return null;} }\n", + "K.java", + "class K implements I { public T foo() {return null;} }\n", + "L.java", + "class L implements I { public T foo() {return null;} }\n", + + "Y.java", + "class Y extends X { @Override public T foo() { return super.foo(); } }\n", + "Z.java", + "class Z extends X { @Override public T foo() { return super.foo(); } }\n", + "W.java", + "class W extends X { @Override public T foo() { return super.foo(); } }\n", + }, + "----------\n" + + "1. ERROR in J.java (at line 1)\n" + + " class J implements I { public T foo() {return null;} }\n" + + " ^\n" + + "The return type is incompatible with I.foo()\n" + + "----------\n" + + "----------\n" + + "1. WARNING in L.java (at line 1)\n" + + " class L implements I { public T foo() {return null;} }\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " class Y extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^\n" + + "The return type is incompatible with X.foo()\n" + + "----------\n" + + "2. ERROR in Y.java (at line 1)\n" + + " class Y extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from A to T\n" + + "----------\n" + + "----------\n" + + "1. WARNING in W.java (at line 1)\n" + + " class W extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in W.java (at line 1)\n" + + " class W extends X { @Override public T foo() { return super.foo(); } }\n" + + " ^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to T\n" + + "----------\n", + /* + J.java:1: J is not abstract and does not override abstract method foo() in I + J.java:1: foo() in J cannot implement foo() in I; attempting to use incompatible return type + W.java:1: incompatible types + found : java.lang.Object + required: T + class W extends X { public T foo() { return super.foo(); } } + Y.java:1: foo() in Y cannot override foo() in X; attempting to use incompatible return type + Y.java:1: incompatible types + found : A + required: T + class Y extends X { public T foo() { return super.foo(); } } + */ + null, + false, + null + ); + } + + public void test007() { // simple covariance cases + this.runConformTest( + new String[] { + "A.java", + "abstract class A implements I {}\n" + + "interface I extends J { String foo(); }\n" + + "interface J { Object foo(); }\n", + "X.java", + "abstract class X1 extends A implements J {}\n" + }, + "" + ); + } + public void test007a() { // simple covariance cases + this.runNegativeTest( + new String[] { + "A.java", + "abstract class A implements I {}\n" + + "interface I extends J { Object foo(); }\n" + // with javac only this type gets an error + "interface J { String foo(); }\n", + "X.java", + "abstract class X2 extends A implements J {}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " interface I extends J { Object foo(); }\n" + + " ^^^^^^\n" + + "The return type is incompatible with J.foo()\n" + + "----------\n" + ); + } + public void test007b() { // simple covariance cases + this.runConformTest( + new String[] { + "A.java", + "abstract class A implements I {}\n" + + "interface I { String foo(); }\n", + "X.java", + "abstract class X3 extends A implements J {}\n" + + "interface J { Object foo(); }\n" + }, + "" + ); + } + public void test007c() { // simple covariance cases + this.runConformTest( + new String[] { + "A.java", + "abstract class A implements I {}\n" + + "interface I { Object foo(); }\n", + "X.java", + "abstract class X4 extends A implements J {}\n" + + "interface J { String foo(); }\n" + }, + "" + ); + } + public void test007d() { // simple covariance cases + this.runConformTest( + new String[] { + "A.java", + "class A { public String foo() { return null; } }\n" + + "interface I { Object foo(); }\n", + "X.java", + "abstract class X5 extends A implements I {}\n" + }, + "" + ); + } + public void test007e() { // simple covariance cases + this.runNegativeTest( + new String[] { + "A.java", + "class A { public Object foo() { return null; } }\n" + + "interface I { String foo(); }\n", + "X.java", + "abstract class X6 extends A implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class X6 extends A implements I {}\n" + + " ^^\n" + + "The type X6 must implement the inherited abstract method I.foo() to override A.foo()\n" + + "----------\n" + ); + } + public void test007f() { // simple covariance cases + this.runNegativeTest( + new String[] { + "A.java", + "class A { int get(short i, short s) { return i; } }\n" + + "class B extends A { @Override short get(short i, short s) {return i; } }\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " class B extends A { @Override short get(short i, short s) {return i; } }\n" + + " ^^^^^\n" + + "The return type is incompatible with A.get(short, short)\n" + + "----------\n" + ); + } + + public void test008() { // covariance test + this.runNegativeTest( + new String[] { + "ALL.java", + "interface I { I foo(); }\n" + + "class A implements I { public A foo() { return null; } }\n" + + "class B extends A { @Override public B foo() { return null; } }\n" + + "class C extends B { @Override public A foo() { return null; } }\n" + + "class D extends B implements I {}\n", + }, + "----------\n" + + "1. ERROR in ALL.java (at line 4)\n" + + " class C extends B { @Override public A foo() { return null; } }\n" + + " ^\n" + + "The return type is incompatible with B.foo()\n" + + "----------\n" + // foo() in C cannot override foo() in B; attempting to use incompatible return type + ); + } + + public void test009() { + this.runNegativeTest( + new String[] { + "A.java", + "class G {}\n" + + "interface I { void foo(G x); }\n" + + "abstract class A implements I { void foo(G x) {} }\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 3)\n" + + " abstract class A implements I { void foo(G x) {} }\n" + + " ^^^^^^^^^^^\n" + + "Name clash: The method foo(G) of type A has the same erasure as foo(G) of type I but does not override it\n" + + "----------\n" + // name clash: foo(G) in A and foo(G) in I have the same erasure, yet neither overrides the other + ); + } + public void test009a() { + this.runNegativeTest( + new String[] { + "A.java", + "class G {}\n" + + "interface I { I foo(G x); }\n" + + "abstract class A implements I { I foo(G x) { return null; } }\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 3)\n" + + " abstract class A implements I { I foo(G x) { return null; } }\n" + + " ^^^^^^^^^^^\n" + + "Name clash: The method foo(G) of type A has the same erasure as foo(G) of type I but does not override it\n" + + "----------\n" + // name clash: foo(G) in A and foo(G) in I have the same erasure, yet neither overrides the other + ); + } + + public void test010() { // executable bridge method case + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public X foo() {\n" + + " System.out.println(\"Did NOT add bridge method\");\n" + + " return this;\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " X x = new A();\n" + + " x.foo();\n" + + " System.out.print(\" + \");\n" + + " I i = new A();\n" + + " i.foo();\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " public I foo();\n" + + "}\n" + + "class A extends X implements I {\n" + + " public A foo() {\n" + + " System.out.print(\"Added bridge method\");\n" + + " return this;\n" + + " }\n" + + "}\n" + }, + "Added bridge method + Added bridge method" + ); + } + + public void test011() { + // javac 1.5.0 will only issue 1 name clash per compile... doesn't matter how many source files are involved + this.runNegativeTest( + new String[] { + "A.java", + "class A { void foo(T t) {} }\n" + + "interface I { void foo(T t); }\n", + "X.java", + "abstract class X1 extends A implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class X1 extends A implements I {}\n" + + " ^^\n" + + "The inherited method A.foo(T) cannot hide the public abstract method in I\n" + + "----------\n" + // foo(T) in A cannot implement foo(T) in I; attempting to assign weaker access privileges; was public + ); + } + public void test011a() { + this.runNegativeTest( + new String[] { + "A.java", + "class A { void foo(T t) {} }\n" + + "interface I { void foo(T t); }\n", + "X.java", + "abstract class X2 extends A implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class X2 extends A implements I {}\n" + + " ^^\n" + + "Name clash: The method foo(T) of type A has the same erasure as foo(T) of type I but does not override it\n" + + "----------\n" + // name clash: foo(T) in A and foo(T) in I have the same erasure, yet neither overrides the other + ); + } + public void test011b() { + this.runNegativeTest( + new String[] { + "A.java", + "class A { void foo(T t) {} }\n" + + "interface I { void foo(T t); }\n", + "X.java", + "abstract class X3 extends A implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class X3 extends A implements I {}\n" + + " ^^\n" + + "Name clash: The method foo(T) of type A has the same erasure as foo(T) of type I but does not override it\n" + + "----------\n" + // name clash: foo(T) in A and foo(T) in I have the same erasure, yet neither overrides the other + ); + } + + public void test012() { + this.runNegativeTest( + new String[] { + "A.java", + "class A { public void foo(T s) {} }\n" + + "class Y1 extends A { @Override void foo(Object s) {} }\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " class Y1 extends A { @Override void foo(Object s) {} }\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot reduce the visibility of the inherited method from A\n" + + "----------\n" + // foo(java.lang.Object) in Y1 cannot override foo(T) in A; attempting to assign weaker access privileges; was public + ); + } + public void test012a() { + this.runNegativeTest( + new String[] { + "A.java", + "class A { public void foo(T[] s) {} }\n" + + "class Y2 extends A { @Override void foo(Object[] s) {} }\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " class Y2 extends A { @Override void foo(Object[] s) {} }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Cannot reduce the visibility of the inherited method from A\n" + + "----------\n" + // foo(java.lang.Object[]) in Y2 cannot override foo(T[]) in A; attempting to assign weaker access privileges; was public + ); + } + public void test012b() { + this.runNegativeTest( + new String[] { + "A.java", + "class A { public void foo(Class s) {} }\n" + + "class Y3 extends A { @Override void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " class Y3 extends A { @Override void foo(Class s) {} }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot reduce the visibility of the inherited method from A\n" + + "----------\n" + // foo(java.lang.Class) in Y3 cannot override foo(java.lang.Class) in A; attempting to assign weaker access privileges; was public + ); + } + + public void test013() { + // javac 1.5.0 will only issue 1 name clash per compile... doesn't matter how many source files are involved + this.runConformTest( + new String[] { + "A.java", + "class A { public void foo(Class s) {} }\n" + + "interface I { void foo(Class s); }\n", + "X.java", + "abstract class X0 extends A implements I {}\n" + }, + "" + ); + } + public void test013a() { + // javac 1.5.0 will only issue 1 name clash per compile... doesn't matter how many source files are involved + this.runNegativeTest( + new String[] { + "A.java", + "class A { void foo(Class s) {} }\n" + + "interface I { void foo(Class s); }\n", + "X.java", + "abstract class X1 extends A implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class X1 extends A implements I {}\n" + + " ^^\n" + + "Name clash: The method foo(Class) of type A has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n" + // name clash: foo(java.lang.Class) in A and foo(java.lang.Class) in I have the same erasure, yet neither overrides the other + ); + } + public void test013b() { + // javac 1.5.0 will only issue 1 name clash per compile... doesn't matter how many source files are involved + this.runNegativeTest( + new String[] { + "A.java", + "class A { void foo(Class s) {} }\n" + + "interface I { void foo(Class s); }\n", + "X.java", + "abstract class X2 extends A implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class X2 extends A implements I {}\n" + + " ^^\n" + + "Name clash: The method foo(Class) of type A has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n" + // name clash: foo(java.lang.Class) in A and foo(java.lang.Class) in I have the same erasure, yet neither overrides the other + ); + } + public void test013c() { + // javac 1.5.0 will only issue 1 name clash per compile... doesn't matter how many source files are involved + this.runNegativeTest( + new String[] { + "A.java", + "class A { S foo(Class s) { return null; } }\n" + + "interface I { Object foo(Class s); }\n", + "X.java", + "abstract class X3 extends A implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class X3 extends A implements I {}\n" + + " ^^\n" + + "Name clash: The method foo(Class) of type A has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n" + // name clash: foo(java.lang.Class) in A and foo(java.lang.Class) in I have the same erasure, yet neither overrides the other + ); + } + public void test013d() { + // javac 1.5.0 will only issue 1 name clash per compile... doesn't matter how many source files are involved + this.runNegativeTest( + new String[] { + "A.java", + "class A { Object foo(Class s) { return null; } }\n" + + "interface I { S foo(Class s); }\n", + "X.java", + "abstract class X4 extends A implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class X4 extends A implements I {}\n" + + " ^^\n" + + "Name clash: The method foo(Class) of type A has the same erasure as foo(Class) of type I but does not override it\n" + + "----------\n" + // name clash: foo(java.lang.Class) in A and foo(java.lang.Class) in I have the same erasure, yet neither overrides the other + ); + } + public void test013e() { + // javac 1.5.0 will only issue 1 name clash per compile... doesn't matter how many source files are involved + this.runNegativeTest( + new String[] { + "A.java", + "class A { public void foo(Class s) {} }\n" + + "interface I { void foo(Class s); }\n", + + "X.java", + "class X5 extends A implements I { public void foo(Class s) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X5 extends A implements I { public void foo(Class s) {} }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Class) of type X5 has the same erasure as foo(Class) of type A but does not override it\n" + + "----------\n" + // name clash: foo(java.lang.Class) in X5 and foo(java.lang.Class) in A have the same erasure, yet neither overrides the other + ); + } + + public void test014() { // name clash tests + this.runConformTest( + new String[] { + "X.java", + "class X { void foo(A a) {} }\n" + + "class Y extends X { void foo(A a) {} }\n" + + "class A {}\n" + }, + "" + ); + } + public void test014a() { // name clash tests + this.runConformTest( + new String[] { + "X.java", + "class X { void foo(A[] a) {} }\n" + + "class Y extends X { void foo(A[] a) {} }\n" + + "class A {}\n" + }, + "" + ); + } + public void test014b() { // name clash tests + this.runConformTest( + new String[] { + "X.java", + "class X { void foo(A[] a) {} }\n" + + "class Y extends X { void foo(A[] a) {} }\n" + + "class A {}\n" + }, + "" + ); + } + public void test014c() { // name clash tests + this.runConformTest( + new String[] { + "X.java", + "class X { void foo(A a) {} }\n" + + "class Y extends X { void foo(A a) {} }\n" + + "class A {}\n" + }, + "" + ); + } + public void test014d() { // name clash tests + this.runNegativeTest( + new String[] { + "X.java", + "class X { void foo(A a) {} }\n" + + "class Y extends X { void foo(A a) {} }\n" + + "class A {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " class X { void foo(A a) {} }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " class Y extends X { void foo(A a) {} }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) of type Y has the same erasure as foo(A) of type X but does not override it\n" + + "----------\n" + // name clash: foo(A) in Y and foo(A) in X have the same erasure, yet neither overrides the other + ); + } + public void test014e() { // name clash tests + this.runNegativeTest( + new String[] { + "X.java", + "class X { void foo(A[] a) {} }\n" + + "class Y extends X { void foo(A[] a) {} }\n" + + "class A {}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " class X { void foo(A[] a) {} }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " class Y extends X { void foo(A[] a) {} }\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A[]) of type Y has the same erasure as foo(A[]) of type X but does not override it\n" + + "----------\n" + // name clash: foo(A[]) in Y and foo(A[]) in X have the same erasure, yet neither overrides the other + ); + } + + public void test015() { // more name clash tests + this.runConformTest( + new String[] { + "X.java", + "abstract class X extends Y implements I { }\n" + + "interface I { void foo(A a); }\n" + + "class Y { public void foo(A a) {} }\n" + + "class A {}\n" + }, + "" + ); + } + public void test015a() { // more name clash tests + this.runConformTest( + new String[] { + "X.java", + "abstract class X extends Y implements I { }\n" + + "interface I { void foo(A[] a); }\n" + + "class Y { public void foo(A[] a) {} }\n" + + "class A {}\n" + }, + "" + ); + } + public void test015b() { // more name clash tests + this.runConformTest( + new String[] { + "X.java", + "abstract class X extends Y implements I { }\n" + + "interface I { void foo(A[] a); }\n" + + "class Y { public void foo(A[] a) {} }\n" + + "class A {}\n" + }, + "" + ); + } + public void test015c() { // more name clash tests + this.runConformTest( + new String[] { + "X.java", + "abstract class X extends Y implements I { }\n" + + "interface I { void foo(A a); }\n" + + "class Y { public void foo(A a) {} }\n" + + "class A {}\n" + }, + "" + ); + } + public void test015d() { // more name clash tests + this.runNegativeTest( + new String[] { + "X.java", + "abstract class X extends Y implements I { }\n" + + "interface I { void foo(A a); }\n" + + "class Y { public void foo(A a) {} }\n" + + "class A {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class X extends Y implements I { }\n" + + " ^\n" + + "Name clash: The method foo(A) of type Y has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " interface I { void foo(A a); }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + // name clash: foo(A) in Y and foo(A) in I have the same erasure, yet neither overrides the other + ); + } + public void test015e() { // more name clash tests + this.runNegativeTest( + new String[] { + "X.java", + "abstract class X extends Y implements I { }\n" + + "interface I { void foo(A[] a); }\n" + + "class Y { public void foo(A[] a) {} }\n" + + "class A {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class X extends Y implements I { }\n" + + " ^\n" + + "Name clash: The method foo(A[]) of type Y has the same erasure as foo(A[]) of type I but does not override it\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " interface I { void foo(A[] a); }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + // name clash: foo(A[]) in Y and foo(A[]) in I have the same erasure, yet neither overrides the other + ); + } + + public void test016() { // 73971 + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void m(E e) { System.out.print(\"A=\"+e.getClass()); }\n" + + " void m(E e) { System.out.print(\"B=\"+e.getClass()); }\n" + + " public static void main(String[] args) {\n" + + " new X().m(new A());\n" + + " new X().m(new B());\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + }, + "A=class AB=class B" + ); + } + public void test016b() { // 73971 + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void m(E e) { System.out.print(\"A=\"+e.getClass()); }\n" + + " static void m(E e) { System.out.print(\"B=\"+e.getClass()); }\n" + + " public static void main(String[] args) {\n" + + " m(new A());\n" + + " m(new B());\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B extends A {}\n" + }, + "A=class AB=class B" + ); + } + + public void test017() { // 77785 + this.runNegativeTest( + new String[] { + "X.java", + "class X {}\n" + + "class Y { void test(X a) {} }\n" + + "class Z extends Y { void test(X a) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class Z extends Y { void test(X a) {} }\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method test(X) of type Z has the same erasure as test(X) of type Y but does not override it\n" + + "----------\n" + // name clash: test(X) in Z and test(X) in Y have the same erasure, yet neither overrides the other + ); + } + public void test017a() { // 77785 + this.runNegativeTest( + new String[] { + "X.java", + "class X {}\n" + + "class Y { void test(X a) {} }\n" + + "class Z extends Y { void test(X a) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class Z extends Y { void test(X a) {} }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method test(X) of type Z has the same erasure as test(X) of type Y but does not override it\n" + + "----------\n" + // name clash: test(X) in Z and test(X) in Y have the same erasure, yet neither overrides the other + ); + } + + public void test018() { // 77861 + this.runNegativeTest( + new String[] { + "X.java", + "class X implements Comparable {\n" + + " public int compareTo(Object o) { return 0; }\n" + + " public int compareTo(X o) { return 1; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public int compareTo(Object o) { return 0; }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method compareTo(Object) of type X has the same erasure as compareTo(T) of type Comparable but does not override it\n" + + "----------\n" + // name clash: compareTo(java.lang.Object) in X and compareTo(T) in java.lang.Comparable have the same erasure, yet neither overrides the other + ); + } + + public void test019() { // 78140 + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " T get() { return null; } \n" + + "}\n" + + "class B extends A {\n" + + " T get() { return null; } \n" + + "}\n" + }, + "" + ); + } + + public void test020() { // 78232 + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " AbstractBase ab = new AbstractBase();\n" + + " Derived d = new Derived();\n" + + " AbstractBase ab2 = new Derived();\n" + + " Visitor v = new MyVisitor();\n" + + " System.out.print(ab.accept(v, ab.getClass().getName()));\n" + + " System.out.print('+');\n" + + " System.out.print(d.accept(v, d.getClass().getName()));\n" + + " System.out.print('+');\n" + + " System.out.print(ab2.accept(v, ab2.getClass().getName()));\n" + + " }\n" + + " static class MyVisitor implements Visitor {\n" + + " public String visitBase(AbstractBase ab, String obj) { return \"Visited base: \" + obj; }\n" + + " public String visitDerived(Derived d, String obj) { return \"Visited derived: \" + obj; }\n" + + " }\n" + + "}\n" + + "interface Visitor {\n" + + " R visitBase(AbstractBase ab, T obj);\n" + + " R visitDerived(Derived d, T obj);\n" + + "}\n" + + "interface Visitable {\n" + + " R accept(Visitor v, T obj);\n" + + "}\n" + + "class AbstractBase implements Visitable {\n" + + " public R accept(Visitor v, T obj) { return v.visitBase(this, obj); }\n" + + "}\n" + + "class Derived extends AbstractBase implements Visitable {\n" + + " public R accept(Visitor v, T obj) { return v.visitDerived(this, obj); }\n" + + "}\n" + }, + "Visited base: AbstractBase+Visited derived: Derived+Visited derived: Derived" + ); + } + + public void test021() { + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " public void foo(java.util.Map> m) { } \n" + + "}\n", + "B.java", + "class B extends A {\n" + + " @Override void foo(java.util.Map> m) { } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in B.java (at line 2)\n" + + " @Override void foo(java.util.Map> m) { } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot reduce the visibility of the inherited method from A\n" + + "----------\n" + ); + // now save A & pick it up as a binary type + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public void foo(java.util.Map> m) { } \n" + + "}\n" + }, + "" + ); + this.runNegativeTest( + new String[] { + "B.java", + "class B extends A {\n" + + " @Override void foo(java.util.Map> m) { } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in B.java (at line 2)\n" + + " @Override void foo(java.util.Map> m) { } \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot reduce the visibility of the inherited method from A\n" + + "----------\n", + null, + false, + null + ); + } + + public void test022() { // 77562 + this.runConformTest( + new String[] { + "A.java", + "import java.util.*;\n" + + "class A { List getList() { return null; } }\n" + + "class B extends A { @Override List getList() { return null; } }\n" + }, + "" + ); + } + public void test022a() { // 77562 + this.runNegativeTest( + new String[] { + "A.java", + "import java.util.*;\n" + + "class A { List getList() { return null; } }\n" + + "class B extends A { @Override List getList() { return null; } }\n" + }, + "----------\n" + + "1. WARNING in A.java (at line 3)\n" + + " class B extends A { @Override List getList() { return null; } }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in A.java (at line 3)\n" + + " class B extends A { @Override List getList() { return null; } }\n" + + " ^^^^\n" + + "Type safety: The return type List for getList() from the type B needs unchecked conversion to conform to List from the type A\n" + + "----------\n" + // unchecked warning on B.getList() + ); + } + + public void test023() { // 80739 + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " void foo(T t) {}\n" + + " void foo(String i) {}\n" + + "}\n" + + "class B extends A {}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 5)\n" + + " class B extends A {}\n" + + " ^\n" + + "Duplicate methods named foo with the parameters (String) and (T) are defined by the type A\n" + + "----------\n" + // methods foo(T) from A and foo(java.lang.String) from A are inherited with the same signature + ); + } + + public void test024() { // 80626 + this.runConformTest( + new String[] { + "A.java", + "class A {\n" + + " public void m(E e) {}\n" + + "}\n" + + "class B extends A {\n" + + " public void m(Object e) {}\n" + + "}\n" + }, + "" + // no complaint + ); + } + public void test024a() { // 80626 + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " public void m(Object e) {}\n" + + "}\n" + + "class B extends A {\n" + + " public void m(E e) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 5)\n" + + " public void m(E e) {}\n" + + " ^^^^^^\n" + + "Name clash: The method m(E) of type B has the same erasure as m(Object) of type A but does not override it\n" + + "----------\n" + // name clash: m(E) in B and m(java.lang.Object) in A have the same erasure, yet neither overrides the other + ); + } + public void test024b() { // 80626 + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " public void m(E e) {}\n" + + "}\n" + + "class B extends A {\n" + + " @Override public void m(Object e) {}\n" + + "}\n" + + "class C extends B {\n" + + " public void m(E e) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 8)\n" + + " public void m(E e) {}\n" + + " ^^^^^^\n" + + "Name clash: The method m(E) of type C has the same erasure as m(Object) of type B but does not override it\n" + + "----------\n" + // name clash: m(E) in C and m(java.lang.Object) in B have the same erasure, yet neither overrides the other + ); + } + + public void test025() { // 81618 + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new B().test();\n" + + " }\n" + + "}\n" + + "class A {\n" + + " T test() { return null; }\n" + + "}\n" + + "class B extends A {\n" + + " @Override Integer test() { return 1; }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " @Override Integer test() { return 1; }\n" + + " ^^^^^^^\n" + + "Type safety: The return type Integer for test() from the type B needs unchecked conversion to conform to T from the type A\n" + + "----------\n" + // warning: test() in B overrides test() in A; return type requires unchecked conversion + ); + } + public void test025a() { // 81618 + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new B().test();\n" + + " }\n" + + "}\n" + + "class A {\n" + + " T[] test() { return null; }\n" + + "}\n" + + "class B extends A {\n" + + " @Override Integer[] test() { return new Integer[] {2}; }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " @Override Integer[] test() { return new Integer[] {2}; }\n" + + " ^^^^^^^^^\n" + + "Type safety: The return type Integer[] for test() from the type B needs unchecked conversion to conform to T[] from the type A\n" + + "----------\n" + // warning: test() in B overrides test() in A; return type requires unchecked conversion + ); + } + public void test025b() { // 81618 + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new B().test(new Integer(1)));\n" + + " }\n" + + "}\n" + + "class A {\n" + + " T test(T t) { return null; }\n" + + "}\n" + + "class B extends A {\n" + + " @Override T test(T t) { return t; }\n" + + "}\n" + }, + "1" + ); + } + public void test025c() { // 81618 + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new B().test(1));\n" + + " }\n" + + "}\n" + + "class A {\n" + + " T test(U u) { return null; }\n" + + "}\n" + + "class B extends A {\n" + + " @Override Integer test(U u) { return 1; }\n" + + "}\n" + }, + "1" + ); + } + public void test025d() { // 81618 + this.runConformTest( + new String[] { + "A.java", + "import java.util.concurrent.Callable;\n" + + "public class A {\n" + + " public static void main(String[] args) throws Exception {\n" + + " Callable integerCallable = new Callable() {\n" + + " public Integer call() { return new Integer(1); }\n" + + " };\n" + + " System.out.println(integerCallable.call());\n" + + " }\n" + + "}\n" + }, + "1" + ); + } + public void test025e() { // 81618 + this.runConformTest( + true, + new String[] { + "X.java", + "interface X { T x(); }\n" + + "abstract class Y implements X { public abstract S x(); }\n" + + "abstract class Z implements X { public abstract X x(); }\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " interface X { T x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " abstract class Y implements X { public abstract S x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " abstract class Z implements X { public abstract X x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\n" + + " abstract class Z implements X { public abstract X x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings + ); + } + public void test025f() { // 81618 + this.runConformTest( + true, + new String[] { + "X.java", + "interface X { T[] x(); }\n" + + "abstract class Y implements X { public abstract S[] x(); }\n" + + "abstract class Z implements X { public abstract X[] x(); }\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " interface X { T[] x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " abstract class Y implements X { public abstract S[] x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " abstract class Z implements X { public abstract X[] x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\n" + + " abstract class Z implements X { public abstract X[] x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings + ); + } + + public void test026() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\n" + + " new B().test().getClass() + \" & \"\n" + + " + new C().test().getClass() + \" & \"\n" + + " + new D().test().getClass());\n" + + " }\n" + + "}\n" + + "class A {\n" + + " A test() { return this; }\n" + + "}\n" + + "class B extends A {\n" + + " A test() { return super.test(); }\n" + + "}\n" + + "class C extends A {\n" + + " A test() { return super.test(); }\n" + + "}\n" + + "class D extends A {\n" + + " A test() { return super.test(); }\n" + + "}\n" + }, + "class B & class C & class D" + ); + } + public void test026a() { + this.runConformTest( + new String[] { + "A.java", + "public abstract class A {\n" + + " public abstract A test();\n" + + "}\n" + + "class H {\n" + + " class M extends A {\n" + + " public A test() { return null; }\n" + + " }\n" + + "}\n" + }, + "" + ); + } + public void test026b() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X extends java.util.AbstractMap {\n" + + " public java.util.Set entrySet() { return null; }\n" + + "}\n" + }, + "" + ); + } + public void test026c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(new C().test().getClass());\n" + + " }\n" + + "}\n" + + "class A {\n" + + " A test() { return this; }\n" + + "}\n" + + "class C extends A {\n" + + " @Override A test() { return super.test(); }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " @Override A test() { return super.test(); }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " @Override A test() { return super.test(); }\n" + + " ^\n" + + "Type safety: The return type A for test() from the type C needs unchecked conversion to conform to A from the type A\n" + + "----------\n" + // warning: test() in C overrides test() in A; return type requires unchecked conversion + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82102 + public void test027() { + this.runConformTest( + new String[] { + "X.java", + "public class X { void test() {} }\n" + + "class Y extends X { void test() {} }\n" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82102 + public void test027a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { void test() {} }\n" + + "class Y extends X { void test() {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X { void test() {} }\n" + + " ^^^^^^\n" + + "Name clash: The method test() of type Y has the same erasure as test() of type X but does not override it\n" + + "----------\n" + // name clash: foo() in Y and foo() in X have the same erasure, yet neither overrides the other + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82102 + public void test027b() { + this.runConformTest( + new String[] { + "X.java", + "public class X { void test(T o) {} }\n" + + "class Y extends X { void test(Object o) {} }\n" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82102 + public void test027c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { void test(T o, T t) {} }\n" + + "class Y extends X { void test(Object o, T t) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X { void test(Object o, T t) {} }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method test(Object, T) of type Y has the same erasure as test(T, T) of type X but does not override it\n" + + "----------\n" + // name clash: test(java.lang.Object,T) in Y and test(T,T) in X have the same erasure, yet neither overrides the other + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=82102 + public void test027d() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test() {\n" + + " Pair p = new InvertedPair();\n" + + " p.setA(Double.valueOf(1.1));\n" + + " }\n" + + "}\n" + + "class Pair {\n" + + " public void setA(A a) {}\n" + + "}\n" + + "class InvertedPair extends Pair {\n" + + " public void setA(A a) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " public void setA(A a) {}\n" + + " ^^^^^^^^^\n" + + "Name clash: The method setA(A) of type InvertedPair has the same erasure as setA(A) of type Pair but does not override it\n" + + "----------\n" + // name clash: setA(A) in InvertedPair and setA(A) in Pair have the same erasure, yet neither overrides the other + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81727 + public void test028() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I{\n" + + " public X foo() { return null; }\n" + + "}\n" + + "interface I { T foo(); }\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81568 + public void test029() { + this.runConformTest( + new String[] { + "I.java", + "public interface I {\n" + + " public I clone();\n" + + "}\n" + + "interface J extends I {}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81535 + public void test030() { + java.util.Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + + this.runConformTest( + new String[] { + "X.java", + "import java.io.OutputStreamWriter;\n" + + "import java.io.PrintWriter;\n" + + "public class X extends PrintWriter implements Runnable {\n" + + " public X(OutputStreamWriter out, boolean flag) { super(out, flag); }\n" + + " public void run() {}\n" + + "}\n" + }, + "", + null, // use default class-path + false, // do not flush previous output dir content + null, // no special vm args + options, + null + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80743 + public void test031() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X { long hashCode(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface X { long hashCode(); }\n" + + " ^^^^\n" + + "The return type is incompatible with Object.hashCode()\n" + + "----------\n" + // hashCode() in X cannot override hashCode() in java.lang.Object; attempting to use incompatible return type + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80736 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=113273 + public void test032() { + // NOTE: javac only reports these errors when the problem type follows the bounds + // if the type X is defined first, then no errors are reported + this.runConformTest( + new String[] { + "X.java", + "interface I { Integer foo(); }\n" + + "interface J { Integer foo(); }\n" + + "public class X implements I {\n" + + " public Integer foo() { return null; }\n" + + "}" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80736 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=113273 + public void test032a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { Float foo(); }\n" + + "interface J { Integer foo(); }\n" + + "public class X {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public class X {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods I.foo(), J.foo()\n" + + "----------\n" + // types J and I are incompatible; both define foo(), but with unrelated return types + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80736 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=113273 + public void test032b() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { String foo(); }\n" + + "class A { public Object foo() { return null; } }\n" + + "public class X {}\n" + + "interface J extends I { Object foo(); }\n" + + "class Y {}\n" + + "class Z {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public class X {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods I.foo(), A.foo()\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " interface J extends I { Object foo(); }\n" + + " ^^^^^^\n" + + "The return type is incompatible with I.foo()\n" + + "----------\n" + // foo() in A cannot implement foo() in I; attempting to use incompatible return type + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80745 + public void test033() { + this.runConformTest( + new String[] { + "X.java", + "interface I { Number foo(); }\n" + + "interface J { Integer foo(); }\n" + + "public class X implements I, J {\n" + + " public Integer foo() {return 1;}\n" + + " public static void main(String argv[]) {\n" + + " I i = null;\n" + + " J j = null;\n" + + " System.out.print(i instanceof J);\n" + + " System.out.print('=');\n" + + " System.out.print(j instanceof I);\n" + + " }\n" + + "}\n" + }, + "false=false" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80745 + public void test033a() { + this.runConformTest( + new String[] { + "X.java", + "interface I { Number foo(A a); }\n" + + "interface J { Integer foo(A a); }\n" + + "class A{}\n" + + "public class X implements I, J {\n" + + " public Integer foo(A a) {return 1;}\n" + + " public static void main(String argv[]) {\n" + + " I i = null;\n" + + " J j = null;\n" + + " System.out.print(i instanceof J);\n" + + " System.out.print('=');\n" + + " System.out.print(j instanceof I);\n" + + " }\n" + + "}\n" + }, + "false=false" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81332 + public void test034() { + this.runConformTest( + new String[] { + "B.java", + "interface I> { void test(E element); }\n" + + "class A implements I { public void test(Integer i) {} }\n" + + "public class B extends A { public void test(String i) {} }\n" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81332 + public void test034a() { + this.runConformTest( + new String[] { + "B.java", + "interface I { void test(E element); }\n" + + "class A { public void test(Integer i) {} }\n" + + "public class B extends A implements I {}\n" + + "class C extends B { public void test(Object i) {} }\n" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81332 + public void test034b() { + this.runNegativeTest( + new String[] { + "B.java", + "interface I { void test(E element); }\n" + + "class A { public void test(Integer i) {} }\n" + + "public class B extends A implements I { public void test(Comparable i) {} }\n" + }, + "----------\n" + + "1. WARNING in B.java (at line 1)\n" + + " interface I { void test(E element); }\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. ERROR in B.java (at line 3)\n" + + " public class B extends A implements I { public void test(Comparable i) {} }\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method test(Comparable) of type B has the same erasure as test(E) of type I but does not override it\n" + + "----------\n" + + "3. WARNING in B.java (at line 3)\n" + + " public class B extends A implements I { public void test(Comparable i) {} }\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + // name clash: test(java.lang.Comparable) in B and test(E) in I have the same erasure, yet neither overrides the other + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81332 + public void test034c() { + this.runNegativeTest( + new String[] { + "B.java", + "interface I> { void test(E element); }\n" + + "class A implements I { public void test(Integer i) {} }\n" + + "public class B extends A { public void test(Comparable i) {} }\n" + }, + "----------\n" + + "1. ERROR in B.java (at line 3)\n" + + " public class B extends A { public void test(Comparable i) {} }\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method test(Comparable) of type B has the same erasure as test(E) of type I but does not override it\n" + + "----------\n" + + "2. WARNING in B.java (at line 3)\n" + + " public class B extends A { public void test(Comparable i) {} }\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + // name clash: test(java.lang.Comparable) in B and test(E) in I have the same erasure, yet neither overrides the other + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81332 + public void test034d() { + this.runNegativeTest( + new String[] { + "B.java", + "abstract class AA { abstract void test(E element); }\n" + + "class A extends AA { @Override public void test(Integer i) {} }\n" + + "public class B extends A { public void test(Comparable i) {} }\n" + }, + "----------\n" + + "1. WARNING in B.java (at line 1)\n" + + " abstract class AA { abstract void test(E element); }\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + + "2. ERROR in B.java (at line 3)\n" + + " public class B extends A { public void test(Comparable i) {} }\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method test(Comparable) of type B has the same erasure as test(E) of type AA but does not override it\n" + + "----------\n" + + "3. WARNING in B.java (at line 3)\n" + + " public class B extends A { public void test(Comparable i) {} }\n" + + " ^^^^^^^^^^\n" + + "Comparable is a raw type. References to generic type Comparable should be parameterized\n" + + "----------\n" + // name clash: test(java.lang.Comparable) in B and test(E) in AA have the same erasure, yet neither overrides the other + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80626 + public void test035() { + this.runNegativeTest( + new String[] { + "E.java", + "interface I{ int compareTo(U o); }\n" + + "abstract class F> implements I{ public final int compareTo(T o) { return 0; } }\n" + + "public class E extends F { public int compareTo(Object o) { return 0; } }\n" + }, + "----------\n" + + "1. ERROR in E.java (at line 3)\n" + + " public class E extends F { public int compareTo(Object o) { return 0; } }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method compareTo(Object) of type E has the same erasure as compareTo(U) of type I but does not override it\n" + + "----------\n" + // name clash: compareTo(java.lang.Object) in E and compareTo(U) in I have the same erasure, yet neither overrides the other + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=80626 + public void test035a() { + this.runNegativeTest( + new String[] { + "X.java", + "public enum X {\n" + + " ;\n" + + " public int compareTo(Object o) { return 0; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public int compareTo(Object o) { return 0; }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method compareTo(Object) of type X has the same erasure as compareTo(T) of type Comparable but does not override it\n" + + "----------\n" + // name clash: compareTo(java.lang.Object) in X and compareTo(T) in java.lang.Comparable have the same erasure, yet neither overrides the other + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83162 + public void test036() { // 2 interface cases + // no bridge methods are created in these conform cases so no name clashes can occur + this.runConformTest( + new String[] { + "X.java", + "class X implements Equivalent, EqualityComparable {\n" + + " public boolean equalTo(Object other) { return true; }\n" + + "}\n" + + "abstract class Y implements Equivalent, EqualityComparable {}\n" + + "class Z extends Y {\n" + + " public boolean equalTo(Object other) { return true; }\n" + + "}\n" + + "interface Equivalent { boolean equalTo(T other); }\n" + + "interface EqualityComparable { boolean equalTo(T other); }\n" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83162 + public void test036a() { // 2 interface cases + this.runConformTest( + new String[] { + "X.java", + "class X implements Equivalent, EqualityComparable {\n" + + " public boolean equalTo(Comparable other) { return true; }\n" + + " public boolean equalTo(Number other) { return true; }\n" + + "}\n" + + "abstract class Y implements Equivalent, EqualityComparable {}\n" + + "class Z extends Y {\n" + + " public boolean equalTo(Comparable other) { return true; }\n" + + " public boolean equalTo(Number other) { return true; }\n" + + "}\n" + + "interface Equivalent { boolean equalTo(T other); }\n" + + "interface EqualityComparable { boolean equalTo(T other); }\n" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83162 + public void test036b() { // 2 interface cases + this.runConformTest( + new String[] { + "X.java", + "class X implements Equivalent, EqualityComparable {\n" + + " public boolean equalTo(S other) { return true; }\n" + + "}\n" + + "abstract class Y implements Equivalent, EqualityComparable {}\n" + + "class Z extends Y {\n" + + " public boolean equalTo(U other) { return true; }\n" + + "}\n" + + "interface Equivalent { boolean equalTo(T other); }\n" + + "interface EqualityComparable { boolean equalTo(T other); }\n" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83162 + public void test036c() { // 2 interface cases + this.runConformTest( + new String[] { + "X.java", + "class X implements Equivalent, EqualityComparable {\n" + + " public boolean equalTo(T other) { return true; }\n" + + " public boolean equalTo(S other) { return true; }\n" + + "}\n" + + "abstract class Y implements Equivalent, EqualityComparable {}\n" + + "class Z extends Y {\n" + + " public boolean equalTo(U other) { return true; }\n" + + " public boolean equalTo(V other) { return true; }\n" + + "}\n" + + "interface Equivalent { boolean equalTo(T other); }\n" + + "interface EqualityComparable { boolean equalTo(S other); }\n" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83162 + public void test036d() { // 2 interface cases + // in these cases, bridge methods are needed once abstract/concrete methods are defiined (either in the abstract class or a concrete subclass) + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runConformTest( + new String[] { + "Y.java", + "abstract class Y implements Equivalent, EqualityComparable {\n" + + " public abstract boolean equalTo(Number other);\n" + + "}\n" + + "interface Equivalent { boolean equalTo(T other); }\n" + + "interface EqualityComparable { boolean equalTo(T other); }\n" + }, + "" + // no bridge methods are created here since Y does not define an equalTo(?) method which equals an inherited equalTo method + ); + } else { + this.runNegativeTest( + new String[] { + "Y.java", + "abstract class Y implements Equivalent, EqualityComparable {\n" + + " public abstract boolean equalTo(Number other);\n" + + "}\n" + + "interface Equivalent { boolean equalTo(T other); }\n" + + "interface EqualityComparable { boolean equalTo(T other); }\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " abstract class Y implements Equivalent, EqualityComparable {\n" + + " ^\n" + + "Name clash: The method equalTo(T) of type EqualityComparable has the same erasure as equalTo(T) of type Equivalent but does not override it\n" + + "----------\n"); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83162 + public void test036e() { // 2 interface cases + this.runNegativeTest( + new String[] { + "Y.java", + "abstract class Y implements Equivalent, EqualityComparable {\n" + + " public abstract boolean equalTo(Object other);\n" + + "}\n" + + "interface Equivalent { boolean equalTo(T other); }\n" + + "interface EqualityComparable { boolean equalTo(T other); }\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in Y.java (at line 2)\n" + + " public abstract boolean equalTo(Object other);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method equalTo(Object) of type Y has the same erasure as equalTo(T) of type EqualityComparable but does not override it\n" + + "----------\n" + + "2. ERROR in Y.java (at line 2)\n" + + " public abstract boolean equalTo(Object other);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method equalTo(Object) of type Y has the same erasure as equalTo(T) of type Equivalent but does not override it\n" + + "----------\n" : + // name clash: equalTo(java.lang.Object) in Y and equalTo(T) in Equivalent have the same erasure, yet neither overrides the other + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " abstract class Y implements Equivalent, EqualityComparable {\n" + + " ^\n" + + "Name clash: The method equalTo(T) of type EqualityComparable has the same erasure as equalTo(T) of type Equivalent but does not override it\n" + + "----------\n" + + "2. ERROR in Y.java (at line 2)\n" + + " public abstract boolean equalTo(Object other);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method equalTo(Object) of type Y has the same erasure as equalTo(T) of type EqualityComparable but does not override it\n" + + "----------\n" + + "3. ERROR in Y.java (at line 2)\n" + + " public abstract boolean equalTo(Object other);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method equalTo(Object) of type Y has the same erasure as equalTo(T) of type Equivalent but does not override it\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83162 + public void test036f() { // 2 interface cases + // NOTE: javac has a bug, reverse the implemented interfaces & the name clash goes away + // but eventually when a concrete subclass must define the remaining method, the error shows up + this.runNegativeTest( + new String[] { + "Y.java", + "abstract class Y implements Equivalent, EqualityComparable {\n" + + " public abstract boolean equalTo(String other);\n" + + "}\n" + + "interface Equivalent { boolean equalTo(T other); }\n" + + "interface EqualityComparable { boolean equalTo(T other); }\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " abstract class Y implements Equivalent, EqualityComparable {\n" + + " ^\n" + + "Name clash: The method equalTo(T) of type Equivalent has the same erasure as equalTo(T) of type EqualityComparable but does not override it\n" + + "----------\n" + // name clash: equalTo(T) in Equivalent and equalTo(T) in EqualityComparable have the same erasure, yet neither overrides the other + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83162 + public void test036g() { // 2 interface cases + this.runNegativeTest( + new String[] { + "Y.java", + "abstract class Y implements EqualityComparable, Equivalent {\n" + + " public boolean equalTo(Integer other) { return true; }\n" + + "}\n" + + "interface Equivalent { boolean equalTo(T other); }\n" + + "interface EqualityComparable { boolean equalTo(T other); }\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " abstract class Y implements EqualityComparable, Equivalent {\n" + + " ^\n" + + "Name clash: The method equalTo(T) of type EqualityComparable has the same erasure as equalTo(T) of type Equivalent but does not override it\n" + + "----------\n" + // name clash: equalTo(T) in EqualityComparable and equalTo(T) in Equivalent have the same erasure, yet neither overrides the other + ); + } + + public void test037() { // test inheritance scenarios + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X implements I, J { }\n" + + "abstract class Y implements J, I { }\n" + + "abstract class Z implements K { }\n" + + + "class YYY implements J, I { public void foo(A a) {} }\n" + + "class XXX implements I, J { public void foo(A a) {} }\n" + + "class ZZZ implements K { public void foo(A a) {} }\n" + + + "interface I { void foo(A a); }\n" + + "interface J { void foo(A a); }\n" + + "interface K extends I { void foo(A a); }\n" + + "class A {}" + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\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 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 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 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 should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " interface K extends I { void foo(A a); }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) of type K has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n" : + "----------\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 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 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 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 should be parameterized\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " interface K extends I { void foo(A a); }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) 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( + new String[] { + "XX.java", + "public abstract class XX implements I, J { public abstract void foo(A a); }\n" + + "interface I { void foo(A a); }\n" + + "interface J { void foo(A a); }\n" + + "class A {}" + }, + "----------\n" + + "1. ERROR in XX.java (at line 1)\n" + + " public abstract class XX implements I, J { public abstract void foo(A a); }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) of type XX has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n" + + "2. WARNING in XX.java (at line 2)\n" + + " interface I { void foo(A a); }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + // name clash: foo(A) in XX and foo(A) in I have the same erasure, yet neither overrides the other + ); + } + public void test037b() { // test inheritance scenarios + this.runNegativeTest( + new String[] { + "XX.java", + "public class XX implements I, J { public void foo(A a) {} }\n" + + "class YY implements J, I { public void foo(A a) {} }\n" + + "class ZZ implements K { public void foo(A a) {} }\n" + + + "interface I { void foo(A a); }\n" + + "interface J { void foo(A a); }\n" + + "interface K extends I { void foo(A a); }\n" + + "class A {}" + }, + "----------\n" + + "1. ERROR in XX.java (at line 1)\n" + + " public class XX implements I, J { public void foo(A 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 a) {} }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) 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 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 a) {} }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) 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 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 a) {} }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) 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 should be parameterized\n" + + "----------\n" + + "8. ERROR in XX.java (at line 6)\n" + + " interface K extends I { void foo(A a); }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) of type K has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n" + ); + } + public void test037c() { // test inheritance scenarios + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X extends Y implements I { }\n" + + "interface I { void foo(A a); }\n" + + "class Y { void foo(A a) {} }\n" + + "class A {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public abstract class X extends Y implements I { }\n" + + " ^\n" + + "Name clash: The method foo(A) of type Y has the same erasure as foo(A) of type I but does not override it\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " interface I { void foo(A a); }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + // name clash: foo(A) in Y and foo(A) in I have the same erasure, yet neither overrides the other + ); + } + public void test037d() { // test inheritance scenarios + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X extends Y implements I { }\n" + + "interface I { void foo(A a); }\n" + + "class Y { void foo(A a) {} }\n" + + "class A {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public abstract class X extends Y implements I { }\n" + + " ^\n" + + "The inherited method Y.foo(A) cannot hide the public abstract method in I\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " class Y { void foo(A a) {} }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + // foo(A) in Y cannot implement foo(A) in I; attempting to assign weaker access privileges; was public + ); + } + public void test037e() { // test inheritance scenarios + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X extends Y implements I { }\n" + + "interface I { void foo(T t); }\n" + + "class Y { void foo(T t) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public abstract class X extends Y implements I { }\n" + + " ^\n" + + "Name clash: The method foo(T) of type Y has the same erasure as foo(T) of type I but does not override it\n" + + "----------\n" + // name clash: foo(T) in Y and foo(T) in I have the same erasure, yet neither overrides the other + ); + } + + public void test038() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends H { void foo(A a) { super.foo(a); } }\n" + + "class H { void foo(A a) {} }\n" + + "class A {}" + }, + "" + ); + } + public void test038a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends H { void foo(A a) {} }\n" + + "class H { void foo(A a) {} }\n" + + "class A {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends H { void foo(A a) {} }\n" + + " ^^^^^^^^^^^\n" + + "Name clash: The method foo(A) of type X has the same erasure as foo(A) of type H but does not override it\n" + + "----------\n" + // name clash: foo(A) in X and foo(A) in H have the same erasure, yet neither overrides the other + // with public class X extends H { void foo(A a) { super.foo(a); } } + // foo(A) in H cannot be applied to (A) + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83573 + public void test039() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Test test = new Test();\n" + + " This test2 = new Test();\n" + + " System.out.println(test.get());\n" + + " }\n" + + " interface This {\n" + + " public Object get();\n" + + " }\n" + + " \n" + + " interface That extends This {\n" + + " public String get();\n" + + " \n" + + " }\n" + + " \n" + + " static class Test implements That {\n" + + " \n" + + " public String get() {\n" + + " return \"That\";\n" + + " \n" + + " }\n" + + " }\n" + + "}\n" + }, + "That" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83218 + public void test040() { + this.runNegativeTest( + new String[] { + "Base.java", + "interface Base { Base proc(); }\n" + + "abstract class Derived implements Base { public abstract Derived proc(); }\n" + }, + "" // no warnings + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83218 + public void test040a() { + this.runNegativeTest( + new String[] { + "A.java", + "class A { T test() { return null; } }\n" + + "class B extends A { @Override Integer test() { return 1; } }\n" + }, + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " class B extends A { @Override Integer test() { return 1; } }\n" + + " ^^^^^^^\n" + + "Type safety: The return type Integer for test() from the type B needs unchecked conversion to conform to T from the type A\n" + + "----------\n" + // warning: test() in B overrides test() in A; return type requires unchecked conversion + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83218 + public void test040b() { + this.runNegativeTest( + new String[] { + "A.java", + "import java.util.*;\n" + + "class A { List getList() { return null; } }\n" + + "class B extends A { @Override List getList() { return null; } }\n" + }, + "----------\n" + + "1. WARNING in A.java (at line 3)\n" + + " class B extends A { @Override List getList() { return null; } }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in A.java (at line 3)\n" + + " class B extends A { @Override List getList() { return null; } }\n" + + " ^^^^\n" + + "Type safety: The return type List for getList() from the type B needs unchecked conversion to conform to List from the type A\n" + + "----------\n" + // unchecked warning on B.getList() + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83218 + public void test040c() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X { X x(); }\n" + + "abstract class Y implements X { public abstract X x(); }\n" + // warning: x() in Y implements x() in X; return type requires unchecked conversion + "abstract class Z implements X { public abstract X x(); }\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " abstract class Y implements X { public abstract X x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " abstract class Y implements X { public abstract X x(); }\n" + + " ^\n" + + "Type safety: The return type X for x() from the type Y needs unchecked conversion to conform to X from the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " abstract class Z implements X { public abstract X x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\n" + + " abstract class Z implements X { public abstract X x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83218 + public void test040d() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X { X[] x(); }\n" + + "abstract class Y implements X { public abstract X[] x(); }\n" + // warning: x() in Y implements x() in X; return type requires unchecked conversion + "abstract class Z implements X { public abstract X[] x(); }\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " abstract class Y implements X { public abstract X[] x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " abstract class Y implements X { public abstract X[] x(); }\n" + + " ^^^\n" + + "Type safety: The return type X[] for x() from the type Y needs unchecked conversion to conform to X[] from the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " abstract class Z implements X { public abstract X[] x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\n" + + " abstract class Z implements X { public abstract X[] x(); }\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 + public void test041() { // inherited cases for bridge methods, varargs clashes, return type conversion checks + runConformTest( + true, + new String[] { + "X.java", + "public class X { public void foo(String... n) {} }\n" + + "interface I { void foo(String[] n); }\n" + + "class Y extends X implements I { }\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class Y extends X implements I { }\n" + + " ^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike X.foo(String...) and I.foo(String[])\n" + + "----------\n", + null, + null, + JavacTestOptions.EclipseJustification.EclipseBug83902 + // warning: foo(java.lang.String...) in X cannot implement foo(java.lang.String[]) in I; overridden method has no '...' + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 + public void test041a() { // inherited cases for bridge methods, varargs clashes, return type conversion checks + this.runConformTest( + true, + new String[] { + "X.java", + "public class X { public void foo(String[] n) {} }\n" + + "interface I { void foo(String... n); }\n" + + "class Y extends X implements I { }\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class Y extends X implements I { }\n" + + " ^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike X.foo(String[]) and I.foo(String...)\n" + + "----------\n", + null, + null, + JavacTestOptions.EclipseJustification.EclipseBug83902 + // warning: foo(java.lang.String[]) in X cannot implement foo(java.lang.String...) in I; overriding method is missing '...' + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 + public void test041b() { // inherited cases for bridge methods, varargs clashes, return type conversion checks + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public Y foo() {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " ((I) new Y()).foo();\n" + + " }\n" + + "}\n" + + "interface I { X foo(); }\n" + + "class Y extends X implements I { }\n" + }, + "SUCCESS" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 + public void test041c() { // inherited cases for bridge methods, varargs clashes, return type conversion checks + this.runNegativeTest( + new String[] { + "X.java", + "public class X { public A foo() { return null; } }\n" + + "interface I { A foo(); }\n" + + "class Y extends X implements I { }\n" + + "class A { }\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X { public A foo() { return null; } }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " class Y extends X implements I { }\n" + + " ^\n" + + "Type safety: The return type A for foo() from the type X needs unchecked conversion to conform to A from the type I\n" + + "----------\n" + // warning: foo() in X implements foo() in I; return type requires unchecked conversion + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 + public void test041d() { // inherited cases for bridge methods, varargs clashes, return type conversion checks + this.runConformTest( + true, + new String[] { + "X.java", + "public class X { public Object foo() { return null; } }\n" + + "interface I { T foo(); }\n" + + "class Y extends X implements I { }\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class Y extends X implements I { }\n" + + " ^\n" + + "Type safety: The return type Object for foo() from the type X needs unchecked conversion to conform to T from the type I\n" + + "----------\n", + null, null, + JavacTestOptions.EclipseJustification.EclipseBug83902b + // NOTE: javac issues an error & a warning which contradict each other + // if the method Object foo() is implemented in Y then only the warning is issued, so X should be allowed to implement the method + // Y is not abstract and does not override abstract method foo() in I + // warning: foo() in X implements foo() in I; return type requires unchecked conversion + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85930 + public void test042() { + this.runConformTest( + new String[] { + "X.java", + "interface Callable\n" + + "{\n" + + " public enum Result { GOOD, BAD };\n" + + " public Result call(T arg);\n" + + "}\n" + + "\n" + + "public class X implements Callable\n" + + "{\n" + + " public Result call(String arg) { return Result.GOOD; } // Warning line\n" + + "}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72704 + public void test043() { // ambiguous message sends because of substitution from 2 different type variables + this.runNegativeTest( + new String[] { + "X.java", + "public class X { void test(E e) { e.id(Integer.valueOf(1)); } }\n" + + "abstract class C { public abstract void id(A x); }\n" + + "interface I { void id(B x); }\n" + + "abstract class E extends C implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " abstract class E extends C implements I {}\n" + + " ^\n" + + "Name clash: The method id(A) of type C has the same erasure as id(B) of type I but does not override it\n" + + "----------\n", + JavacTestOptions.EclipseJustification.EclipseBug72704 + // javac won't report it until C.id() is made concrete or implemented in E + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72704 + // variant where C and C.id are concrete + public void test043_1() { // ambiguous message sends because of substitution from 2 different type variables + this.runNegativeTest( + new String[] { + "X.java", + "public class X { void test(E e) { e.id(Integer.valueOf(1)); } }\n" + + "class C { public void id(A x) {} }\n" + + "interface I { void id(B x); }\n" + + "abstract class E extends C implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " abstract class E extends C implements I {}\n" + + " ^\n" + + "Name clash: The method id(A) of type C has the same erasure as id(B) of type I but does not override it\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72704 + public void test043a() { // ambiguous message sends because of substitution from 2 different type variables + this.runNegativeTest( + new String[] { + "X.java", + "public class X { void test(E e) { e.id(Integer.valueOf(2)); } }\n" + + "abstract class C { public abstract void id(A x); }\n" + + "interface I { void id(B x); }\n" + + "abstract class E extends C implements I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X { void test(E e) { e.id(Integer.valueOf(2)); } }\n" + + " ^^\n" + + "The method id(Integer) is ambiguous for the type E\n" + + "----------\n" + // reference to id is ambiguous, both method id(A) in C and method id(B) in I match + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72704 + public void test043b() { // ambiguous message sends because of substitution from 2 different type variables + this.runNegativeTest( + new String[] { + "X.java", + "public class X { void test(E e) { e.id(Integer.valueOf(111)); } }\n" + + "abstract class C { public void id(A x) {} }\n" + + "interface I { void id(B x); }\n" + + "class E extends C implements I { public void id(B b) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X { void test(E e) { e.id(Integer.valueOf(111)); } }\n" + + " ^^\n" + + "The method id(Integer) is ambiguous for the type E\n" + + "----------\n" + // reference to id is ambiguous, both method id(A) in C and method id(B) in E match + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72704 + public void test043c() { // ambiguous message sends because of substitution from 2 different type variables + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test(E e) { e.id(Integer.valueOf(111)); }\n" + + " void test(M m) {\n" + + " m.id(Integer.valueOf(111));\n" + + " ((E) m).id(Integer.valueOf(111));\n" + + " }\n" + + " void test(N n) { n.id(Integer.valueOf(111)); }\n" + + "}\n" + + "abstract class C { public void id(A x) {} }\n" + + "interface I { void id(B x); }\n" + + "abstract class E extends C implements I {}\n" + + "class M extends E { public void id(B b) {} }\n" + + "abstract class N extends E { @Override public void id(T n) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " m.id(Integer.valueOf(111));\n" + + " ^^\n" + + "The method id(Integer) is ambiguous for the type M\n" + + "----------\n" + // reference to id is ambiguous, both method id(A) in C and method id(B) in M match + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97161 + public void test043d() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.Y.*;\n" + + "import static p.Z.*;\n" + + "public class X {\n" + + " Y data = null;\n" + + " public X() { foo(data.l); }\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "import java.util.List;\n" + + "public class Y {\n" + + " List l = null;\n" + + " public static void foo(T... e) {}\n" + + "}\n", + "p/Z.java", + "package p;\n" + + "import java.util.List;\n" + + "public class Z {\n" + + " public static void foo(List... 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 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...) 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\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 should be parameterized\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 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...) 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\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 should be parameterized\n" + + "----------\n" + + "2. WARNING in p\\Y.java (at line 5)\n" + + " public static 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 void foo(List... e) {}\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter e\n" + + "----------\n" + // unchecked conversion warnings + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97161 + public void test043e() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.Y.*;\n" + + "public class X {\n" + + " Y data = null;\n" + + " public X() { foo(data.l); }\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "import java.util.List;\n" + + "public class Y {\n" + + " List l = null;\n" + + " public static void foo(T... e) {}\n" + + " public static void foo(List... 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 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...) 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\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 should be parameterized\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 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...) 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\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 should be parameterized\n" + + "----------\n" + + "2. WARNING in p\\Y.java (at line 5)\n" + + " public static 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 void foo(List... e) {}\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter e\n" + + "----------\n" + // unchecked conversion warnings + ); + } + + public void test043f() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void test(M m) {\n" + + " m.id(new Integer(111), new Integer(112));\n" + + " }\n" + + "}\n" + + "abstract class C { public void id(T1 x, U1 u) {} }\n" + + "interface I { }\n" + + "abstract class E extends C implements I {}\n" + + "class M extends E { public void id(T5 b, U2 u) {} }\n" + }, + "" + ); + } + public void test043g() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test(M m) {\n" + + " m.id(Integer.valueOf(111));\n" + + " }\n" + + "}\n" + + "abstract class C { public void id(T1 x) {} }\n" + + "interface I { void id(T2 x); }\n" + + "abstract class E extends C implements I {}\n" + + "class M extends E { public void id(T6 b) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " m.id(Integer.valueOf(111));\n" + + " ^^\n" + + "The method id(Integer) is ambiguous for the type M\n" + + "----------\n" + // reference to id is ambiguous, both method id(A) in C and method id(B) in M match + ); + } + + // ensure AccOverriding remains when attempting to override final method + public void test044() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { final void foo() {} }\n" + + "class XS extends X { @Override void foo() {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class XS extends X { @Override void foo() {} }\n" + + " ^^^^^\n" + + "Cannot override the final method from X\n" + + "----------\n" + ); + } + // ensure AccOverriding remains when attempting to override final method + public void test044a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { public void foo() {} }\n" + + "class XS extends X { @Override void foo() {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class XS extends X { @Override void foo() {} }\n" + + " ^^^^^\n" + + "Cannot reduce the visibility of the inherited method from X\n" + + "----------\n" + ); + } + // ensure AccOverriding remains when attempting to override final method + public void test044b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { void foo() {} }\n" + + "class XS extends X { @Override void foo() throws ClassNotFoundException {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class XS extends X { @Override void foo() throws ClassNotFoundException {} }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Exception ClassNotFoundException is not compatible with throws clause in X.foo()\n" + + "----------\n" + ); + } + // ensure AccOverriding remains when attempting to override final method + public void test044c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { void foo() {} }\n" + + "class XS extends X { @Override int foo() {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class XS extends X { @Override int foo() {} }\n" + + " ^^^\n" + + "The return type is incompatible with X.foo()\n" + + "----------\n" + ); + } + + public void test045() { + this.runConformTest( + new String[] { + "X.java", + "class Foo {}\n" + + "\n" + + "interface Bar {\n" + + " Foo get(Class c);\n" + + "}\n" + + "public class X implements Bar {\n" + + " public Foo get(Class c) { return null; }\n" + + "}\n" + }, + "" + ); + } + + // ensure no unchecked warning + public void test046() { + this.runNegativeTest( + new String[] { + "X.java", + "interface IX {\n" + + " public T doSomething();\n" + + "}\n" + + "public class X implements IX {\n" + + " Zork z;\n" + + " public Integer doSomething() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. 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=87157 + public void test047() { + this.runConformTest( + new String[] { + "X.java", + "interface Interface {\n" + + " Number getValue();\n" + + "}\n" + + "class C1 {\n" + + " public Double getValue() {\n" + + " return 0.0;\n" + + " }\n" + + "}\n" + + "public class X extends C1 implements Interface{\n" + + " public static void main(String[] args) {\n" + + " Interface i=new X();\n" + + " System.out.println(i.getValue());\n" + + " }\n" + + "}\n" + }, + "0.0"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85900 + public void test048() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X1.java (at line 2)\n" + + " public class X1 extends LinkedHashMap {\n" + + " ^^\n" + + "The serializable class X1 does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X1.java (at line 3)\n" + + " public Object putAll(Map a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method putAll(Map) of type X1 has the same erasure as putAll(Map) of type HashMap but does not override it\n" + + "----------\n": + "----------\n" + + "1. WARNING in X1.java (at line 2)\n" + + " public class X1 extends LinkedHashMap {\n" + + " ^^\n" + + "The serializable class X1 does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X1.java (at line 3)\n" + + " public Object putAll(Map a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method putAll(Map) of type X1 has the same erasure as putAll(Map) of type HashMap but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X1.java", + "import java.util.*;\n" + + "public class X1 extends LinkedHashMap {\n" + + " public Object putAll(Map a) { return null; }\n" + + "}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:4: name clash: putAll(Map) in X1 and putAll(Map) in HashMap have the same erasure, yet neither overrides the other + public Object putAll(Map a) { return null; } + ^ + where K,V are type-variables: + K extends Object declared in class HashMap + V extends Object declared in class HashMap +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85900 + public void test048a() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X2.java (at line 2)\n" + + " public Object foo(I z) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X2 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X2.java (at line 2)\n" + + " public Object foo(I z) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X2 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X2.java", + "public class X2 extends Y {\n" + + " public Object foo(I z) { return null; }\n" + + "}\n" + + "class Y implements I {\n" + + " public void foo(I a) {}\n" + + "}\n" + + "interface I {\n" + + " public void foo(I a);\n" + + "}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:2: name clash: foo(I) in X2 and foo(I) in Y have the same erasure, yet neither overrides the other + public Object foo(I z) { return null; } + ^ + where T is a type-variable: + T extends Object declared in class Y +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85900 + public void test048b() { + this.runNegativeTest( + new String[] { + "X3.java", + "public class X3 extends Y {\n" + + " public void foo(I z) {}\n" + + "}\n" + + "class Y implements I {\n" + + " public void foo(I a) {}\n" + + "}\n" + + "interface I {\n" + + " public void foo(I a);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X3.java (at line 2)\n" + + " public void foo(I z) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X3 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n" + ); +/* javac 7 +X.java:2: name clash: foo(I) in X3 and foo(I) in Y have the same erasure, yet neither overrides the other + public void foo(I z) {} + ^ + where T is a type-variable: + T extends Object declared in class Y +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85900 + public void test048c() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X4.java (at line 2)\n" + + " public String foo(I z) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X4 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X4.java (at line 2)\n" + + " public String foo(I z) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X4 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X4.java", + "public class X4 extends Y {\n" + + " public String foo(I z) { return null; }\n" + + "}\n" + + "class Y implements I {\n" + + " public Object foo(I a) { return null; }\n" + + "}\n" + + "interface I {\n" + + " public Object foo(I a);\n" + + "}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:2: name clash: foo(I) in X4 and foo(I) in Y have the same erasure, yet neither overrides the other + public String foo(I z) { return null; } + ^ + where T is a type-variable: + T extends Object declared in class Y +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85900 + public void test048d() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X5.java (at line 2)\n" + + " public Object foo(I z) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X5 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X5.java (at line 2)\n" + + " public Object foo(I z) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X5 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X5.java", + "public class X5 extends Y {\n" + + " public Object foo(I z) { return null; }\n" + + "}\n" + + "class Y implements I {\n" + + " public String foo(I a) { return null; }\n" + + "}\n" + + "interface I {\n" + + " public String foo(I a);\n" + + "}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:2: name clash: foo(I) in X5 and foo(I) in Y have the + same erasure, yet neither overrides the other + public Object foo(I z) { return null; } + ^ + where T is a type-variable: + T extends Object declared in class Y +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85900 + public void test048e() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X6.java (at line 2)\n" + + " public void foo(I z) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X6 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X6.java (at line 2)\n" + + " public void foo(I z) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X6 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X6.java", + "public class X6 extends Y {\n" + + " public void foo(I z) {}\n" + + "}\n" + + "class Y implements I {\n" + + " public Object foo(I a) { return null; }\n" + + "}\n" + + "interface I {\n" + + " public Object foo(I a);\n" + + "}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:2: name clash: foo(I) in X6 and foo(I) in Y have the same erasure, yet neither overrides the other + public void foo(I z) {} + ^ + where T is a type-variable: + T extends Object declared in class Y +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85900 + public void test048f() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X7.java (at line 2)\n" + + " public String foo(I z) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X7 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X7.java (at line 2)\n" + + " public String foo(I z) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X7 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X7.java", + "public class X7 extends Y {\n" + + " public String foo(I z) { return null; }\n" + + "}\n" + + "class Y implements I {\n" + + " public T foo(I a) { return null; }\n" + + "}\n" + + "interface I {\n" + + " public T foo(I a);\n" + + "}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:2: name clash: foo(I) in X7 and foo(I) in Y have the same erasure, yet neither overrides the other + public String foo(I z) { return null; } + ^ + where T is a type-variable: + T extends Object declared in class Y +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=85900 + public void test048g() { + this.runNegativeTest( + new String[] { + "X8.java", + "public class X8 extends Y {\n" + + " public Object foo(I z) { return null; }\n" + + "}\n" + + "class Y implements I {\n" + + " public T foo(I a) { return null; }\n" + + "}\n" + + "interface I {\n" + + " public T foo(I a);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X8.java (at line 2)\n" + + " public Object foo(I z) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(I) of type X8 has the same erasure as foo(I) of type Y but does not override it\n" + + "----------\n" + ); +/* javac 7 +X.java:2: name clash: foo(I) in X8 and foo(I) in Y have the same erasure, yet neither overrides the other + public Object foo(I z) { return null; } + ^ + where T is a type-variable: + T extends Object declared in class Y +1 error + */ + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88094 + public void test049() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T id(T x) { return x; }\n" + + " A id(A x) { return x; }\n" + + "}\n" + + "class Y extends X {\n" + + " @Override T id(T x) { return x; }\n" + + " @Override A id(A x) { return x; }\n" + + "}\n" + + "class A {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " @Override T id(T x) { return x; }\n" + + " ^^^^^^^\n" + + "Erasure of method id(T) is the same as another method in type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " @Override T id(T x) { return x; }\n" + + " ^^^^^^^\n" + + "Name clash: The method id(T) of type Y has the same erasure as id(A) of type X but does not override it\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " @Override A id(A x) { return x; }\n" + + " ^^^^^^^\n" + + "Erasure of method id(A) is the same as another method in type Y\n" + + "----------\n" + // id(T) is already defined in Y + // id(java.lang.String) in Y overrides id(T) in X; return type requires unchecked conversion + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88094 + public void test049a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T id(T x) { return x; }\n" + + " A id(A x) { return x; }\n" + + "}\n" + + "class Y extends X {}\n" + + "class A {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " class Y extends X {}\n" + + " ^\n" + + "Duplicate methods named id with the parameters (A) and (T) are defined by the type X\n" + + "----------\n" + // methods id(T) from X and id(A) from X are inherited with the same signature + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94754 + public void test050() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public static S foo() { System.out.print(\"A\"); return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " public static N foo() { System.out.print(\"B\"); return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " new X().foo();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The static method foo() from the type X should be accessed in a static way\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static S foo() { System.out.print(\"A\"); return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public static N foo() { System.out.print(\"B\"); return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " X.foo();\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo() of type X is not applicable for the arguments (). The inferred type B is not a valid substitute for the bounded parameter \n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " new X().foo();\n" + + " ^^^\n" + + "Bound mismatch: The generic method foo() of type X is not applicable for the arguments (). The inferred type B is not a valid substitute for the bounded parameter \n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static S foo() { System.out.print(\"A\"); return null; }\n" + + " public static N foo() { System.out.print(\"B\"); return null; }\n" + + " public static void main(String[] args) {\n" + + " X.foo();\n" + + " X.foo();\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B {}" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: foo() and foo() have the same erasure + public static N foo() { System.out.print("B"); return null; } + ^ + where N,S are type-variables: + N extends B declared in method foo() + S extends A declared in method foo() +X.java:6: method foo in class X cannot be applied to given types + X.foo(); + ^ + required: no arguments + found: no arguments +X.java:7: method foo in class X cannot be applied to given types + new X().foo(); + ^ + required: no arguments + found: no arguments +3 errors + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94754 + public void test050a() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public static void foo() { System.out.print(\"A\"); }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " public static N foo() { System.out.print(\"B\"); return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " X.foo();\n" + + " ^^^\n" + + "The method foo() is ambiguous for the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " foo();\n" + + " ^^^\n" + + "The method foo() is ambiguous for the type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static void foo() { System.out.print(\"A\"); }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public static N foo() { System.out.print(\"B\"); return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo() { System.out.print(\"A\"); }\n" + + " public static N foo() { System.out.print(\"B\"); return null; }\n" + + " static void test () {\n" + + " X.foo();\n" + + " foo();\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class B {}" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: foo() and foo() have the same erasure + public static N foo() { System.out.print("B"); return null; } + ^ + where N,S are type-variables: + N extends B declared in method foo() + S extends A declared in method foo() +1 error + */ + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 - variation + public void test050b() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C1\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Z foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C1\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " T foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C2\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " T foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C2\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " A foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C3\n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " A foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C3\n" + + "----------\n" + + "7. ERROR in X.java (at line 15)\n" + + " Y foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C4\n" + + "----------\n" + + "8. ERROR in X.java (at line 16)\n" + + " T foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C4\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C1\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Z foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C1\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " T foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C2\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " T foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C2\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " A foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C3\n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " A foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C3\n" + + "----------\n" + + "7. ERROR in X.java (at line 15)\n" + + " Y foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C4\n" + + "----------\n" + + "8. ERROR in X.java (at line 16)\n" + + " T foo(Object o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C4\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class C1 {\n" + + " Y foo(Object o) { return null; } // duplicate\n" + + " Z foo(Object o) { return null; } // duplicate\n" + + " }\n" + + " class C2 {\n" + + " T foo(Object o) { return null; } // duplicate\n" + + " T foo(Object o) { return null; } // duplicate\n" + + " }\n" + + " class C3 {\n" + + " A foo(Object o) { return null; } // duplicate\n" + + " A foo(Object o) { return null; } // duplicate\n" + + " }\n" + + " class C4 {\n" + + " Y foo(Object o) { return null; } // duplicate\n" + + " T foo(Object o) { return null; } // duplicate\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class Y {}\n" + + "class Z {}" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:4: foo(Object) is already defined in X.C1 + Z foo(Object o) { return null; } // duplicate + ^ +X.java:8: name clash: foo(Object) and foo(Object) have the same erasure + T foo(Object o) { return null; } // duplicate + ^ + where T#1,T#2 are type-variables: + T#1 extends Z declared in method foo(Object) + T#2 extends Y declared in method foo(Object) +X.java:12: foo(Object) is already defined in X.C3 + A foo(Object o) { return null; } // duplicate + ^ +X.java:16: foo(Object) is already defined in X.C4 + T foo(Object o) { return null; } // duplicate + ^ +4 errors + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 - variation + public void test050c() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " A foo(A o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X.C5\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " A foo(A o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X.C5\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " T foo(A o) { return null; } // ok\n" + + " ^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X.C6\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " T foo(A o) { return null; } // ok\n" + + " ^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X.C6\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " A foo(A o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X.C5\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " A foo(A o) { return null; } // duplicate\n" + + " ^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X.C5\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " T foo(A o) { return null; } // ok\n" + + " ^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X.C6\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " T foo(A o) { return null; } // ok\n" + + " ^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X.C6\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class C5 {\n" + + " A foo(A o) { return null; } // duplicate\n" + + " A foo(A o) { return null; } // duplicate\n" + + " }\n" + + " class C6 {\n" + + " T foo(A o) { return null; } // ok\n" + + " T foo(A o) { return null; } // ok\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class Y {}\n" + + "class Z {}" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:4: name clash: foo(A) and foo(A) have the same erasure + A foo(A o) { return null; } // duplicate + ^ +X.java:8: name clash: foo(A) and foo(A) have the same erasure + T foo(A o) { return null; } // ok + ^ + where T#1,T#2 are type-variables: + T#1 extends Z declared in method foo(A) + T#2 extends Y declared in method foo(A) +2 errors + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 - variation + public void test050d() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C7\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C7\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C7\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " T foo(Object o) { return null; } // ok\n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate method foo(Object) in type X.C7\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class C7 {\n" + + " T foo(Object o) { return null; } // ok\n" + + " T foo(Object o) { return null; } // ok\n" + + " }\n" + + "}\n" + + "class A {}\n" + + "class Y {}\n" + + "class Z {}" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:4: name clash: foo(Object) and foo(Object) have the same erasure + T foo(Object o) { return null; } // ok + ^ + where T#1,T#2,U are type-variables: + T#1 extends Z declared in method foo(Object) + T#2 extends Y declared in method foo(Object) + U extends Object declared in method foo(Object) +1 error + */ + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 + public void test050e() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " N a(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method a(A) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Object a(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method a(A) is the same as another method in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " void b(A s) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " B b(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 6)\n" + + " void c(A s) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method c(A) is the same as another method in type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 7)\n" + + " B c(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method c(A) is the same as another method in type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " N a(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method a(A) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Object a(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method a(A) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " void b(A s) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " B b(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " void c(A s) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method c(A) is the same as another method in type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " B c(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method c(A) is the same as another method in type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " N a(A s) { return null; }\n" + + " Object a(A n) { return null; }\n" + + " void b(A s) {}\n" + + " B b(A n) { return null; }\n" + + " void c(A s) {}\n" + + " B c(A n) { return null; }\n" + + "}\n" + + "class A {}\n" + + "class B {}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: a(A) and a(A) have the same erasure + Object a(A n) { return null; } + ^ + where N#1,N#2 are type-variables: + N#1 extends Object declared in method a(A) + N#2 extends B declared in method a(A) +X.java:5: name clash: b(A) and b(A) have the same erasure + B b(A n) { return null; } + ^ + where N#1,N#2 are type-variables: + N#1 extends B declared in method b(A) + N#2 extends B declared in method b(A) +X.java:7: name clash: c(A) and c(A) have the same erasure + B c(A n) { return null; } + ^ +3 errors + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 + public void test050f() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " N a(A s) { return null; }\n" + + " B a(A n) { return null; }\n" + + "}\n" + + "class A {}\n" + + "class B {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " N a(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method a(A) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " B a(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method a(A) is the same as another method in type X\n" + + "----------\n" + ); +/* javac 7 +X.java:3: name clash: a(A) and a(A) have the same erasure + B a(A n) { return null; } + ^ + where N#1,N#2 are type-variables: + N#1 extends Object declared in method a(A) + N#2 extends B declared in method a(A) +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 + public void test050g() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " N b(A s) { return null; }\n" + + " B b(A n) { return null; }\n" + + "}\n" + + "class A {}\n" + + "class B {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " N b(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " B b(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n" + ); +/* javac 7 +X.java:3: name clash: b(A) and b(A) have the same erasure + B b(A n) { return null; } + ^ + where N#1,N#2 are type-variables: + N#1 extends B declared in method b(A) + N#2 extends B declared in method b(A) +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 + public void test050h() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " B c(A s) { return null; }\n" + + " B c(A n) { return null; }\n" + + "}\n" + + "class A {}\n" + + "class B {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " B c(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method c(A) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " B c(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method c(A) is the same as another method in type X\n" + + "----------\n" + ); +/* javac 7 +X.java:3: name clash: c(A) and c(A) have the same erasure + B c(A n) { return null; } + ^ +1 error + */ + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 + public void test050i() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " N a(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method a(A) in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Object a(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method a(A) in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " N b(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " Object b(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " N a(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method a(A) in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Object a(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method a(A) in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " N b(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Object b(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " N a(A s) { return null; }\n" + + " Object a(A n) { return null; }\n" + + " N b(A s) { return null; }\n" + + " Object b(A n) { return null; }\n" + + "}\n" + + "class A {}\n" + + "class B {}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: a(A) and a(A) have the same erasure + Object a(A n) { return null; } + ^ + where N#1,N#2 are type-variables: + N#1 extends Object declared in method a(A) + N#2 extends B declared in method a(A) +X.java:5: name clash: b(A) and b(A) have the same erasure + Object b(A n) { return null; } + ^ + where N#1,N#2 are type-variables: + N#1 extends Object declared in method b(A) + N#2 extends B declared in method b(A) +2 errors + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 + public void test050j() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " N a(A s) { return null; }\n" + + " B a(A n) { return null; }\n" + + " N b(A s) { return null; }\n" + + " B b(A n) { return null; }\n" + + "}\n" + + "class A {}\n" + + "class B {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " N a(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method a(A) in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " B a(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method a(A) in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " N b(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " B b(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method b(A) is the same as another method in type X\n" + + "----------\n" + ); +/* javac 7 +X.java:3: name clash: a(A) and a(A) have the same erasure + B a(A n) { return null; } + ^ + where N#1,N#2 are type-variables: + N#1 extends Object declared in method a(A) + N#2 extends B declared in method a(A) +X.java:5: name clash: b(A) and b(A) have the same erasure + B b(A n) { return null; } + ^ + where N#1,N#2 are type-variables: + N#1 extends Object declared in method b(A) + N#2 extends B declared in method b(A) +2 errors + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 + public void test050k() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void a(A s) {}\n" + + " B a(A n) { return null; }\n" + + " Object b(A s) { return null; }\n" + + " B b(A n) { return null; }\n" + + "}\n" + + "class A {}\n" + + "class B {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void a(A s) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method a(A) in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " B a(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method a(A) in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Object b(A s) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method b(A) in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " B b(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method b(A) in type X\n" + + "----------\n" + ); +/* javac 7 +X.java:3: a(A) is already defined in X + B a(A n) { return null; } + ^ + where N is a type-variable: + N extends B declared in method a(A) +X.java:5: b(A) is already defined in X + B b(A n) { return null; } + ^ + where N is a type-variable: + N extends B declared in method b(A) +2 errors + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90423 + public void test050l() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void a(A s) {}\n" + + " B a(A n) { return null; }\n" + + " Object b(A s) {}\n" + + " B b(A n) { return null; }\n" + + "}\n" + + "class A {}\n" + + "class B {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void a(A s) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method a(A) in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " B a(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method a(A) in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Object b(A s) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method b(A) in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Object b(A s) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "This method must return a result of type Object\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " B b(A n) { return null; }\n" + + " ^^^^^^^^^^^^^^\n" + + "Duplicate method b(A) in type X\n" + + "----------\n" + ); +/* javac 7 +X.java:3: a(A) is already defined in X + B a(A n) { return null; } + ^ +X.java:5: b(A) is already defined in X + B b(A n) { return null; } + ^ +2 errors + */ + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=89470 + public void test051() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I {\n" + + " public void foo(T t) {}\n" + + "}\n" + + "interface I {\n" + + " void foo(T t);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements I {\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.foo(T)\n" + + "----------\n" + ); +/* javac 7 +X.java:1: X is not abstract and does not override abstract method foo(T) in I +class X implements I { +^ + where T is a type-variable: + T extends Object declared in method foo(T) +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=89470 + public void test051a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(A a) {}\n" + + " void foo(A a) {}\n" + + "}\n" + + "class A {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(A a) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " void foo(A a) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + ); +/* javac 7 +X.java:3: name clash: foo(A) and foo(A) have the same erasure + void foo(A a) {} + ^ +1 error + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=89470 + public void test051b() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo(A a) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Object foo(A a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(A a) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Object foo(A a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(A a) {}\n" + + " Object foo(A a) { return null; }\n" + + "}\n" + + "class A {}\n", + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: foo(A) and foo(A) have the same erasure + Object foo(A a) { return null; } + ^ +1 error + */ + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=91728 + public void test052() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public A test() { return null; }\n" + + " public A test2() { return null; }\n" + + " public A test3() { return null; }\n" + + " public A test4() { return null; }\n" + + "}\n" + + "class B extends A {\n" + + " @Override public B test() { return null; }\n" + + " @Override public B test2() { return null; }\n" + + " @Override public B test3() { return null; }\n" + + " @Override public A test4() { return null; }\n" + + "}\n" + + "class X{}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=91728 + public void test052a() { + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " public A test() { return null; }\n" + + " public A test2() { return null; }\n" + + " public A test3() { return null; }\n" + + "}\n" + + "class B extends A {\n" + + " @Override public B test() { return null; }\n" + + " @Override public A test2() { return null; }\n" + + " @Override public A test3() { return null; }\n" + + "}\n" + + "class X{}\n" + }, + "----------\n" + + "1. WARNING in A.java (at line 7)\n" + + " @Override public B test() { return null; }\n" + + " ^\n" + + "Type safety: The return type B for test() from the type B needs unchecked conversion to conform to A from the type A\n" + + "----------\n" + + "2. WARNING in A.java (at line 8)\n" + + " @Override public A test2() { return null; }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "3. WARNING in A.java (at line 8)\n" + + " @Override public A test2() { return null; }\n" + + " ^\n" + + "Type safety: The return type A for test2() from the type B needs unchecked conversion to conform to A from the type A\n" + + "----------\n" + + "4. WARNING in A.java (at line 9)\n" + + " @Override public A test3() { return null; }\n" + + " ^\n" + + "Type safety: The return type A for test3() from the type B needs unchecked conversion to conform to A from the type A\n" + + "----------\n" + // warning: test() in B overrides test() in A; return type requires unchecked conversion + // warning: test2() in B overrides test2() in A; return type requires unchecked conversion + // warning: test3() in B overrides test3() in A; return type requires unchecked conversion + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=91728 + public void test053() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void test(A a) { B b = a.foo(); }\n" + + " void test2(A a) { B b = a.foo(); }\n" + + " void test3(B b) { B bb = b.foo(); }\n" + + "}\n" + + "class A {\n" + + " A foo() { return null; }\n" + + "}\n" + + "class B extends A {\n" + + " @Override B foo() { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void test(A a) { B b = a.foo(); }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " void test(A a) { B b = a.foo(); }\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from A to B\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " void test2(A a) { B b = a.foo(); }\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from A to B\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " @Override B foo() { return null; }\n" + + " ^\n" + + "Type safety: The return type B for foo() from the type B needs unchecked conversion to conform to A from the type A\n" + + "----------\n" + // 2: incompatible types + // 3: incompatible types; no instance(s) of type variable(s) U exist so that A conforms to B + // 10 warning: foo() in B overrides foo() in A; return type requires unchecked conversion + ); + } + + // more duplicate tests, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=94897 + public void test054() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void a(Object x) {}\n" + + " T a(T x) { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void a(Object x) {}\n" + + " ^^^^^^^^^^^\n" + + "Erasure of method a(Object) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " T a(T x) { return null; }\n" + + " ^^^^^^\n" + + "Erasure of method a(T) is the same as another method in type X\n" + + "----------\n" + ); +/* javac 7 +X.java:3: a(Object) is already defined in X + T a(T x) { return null; } + ^ +1 error + */ + } + // more duplicate tests, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=94897 + public void test054a() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " String aaa(X x) { return null; }\n" + + " ^^^^^^^^\n" + + "Erasure of method aaa(X) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " T aaa(T x) { return null; }\n" + + " ^^^^^^^^\n" + + "Erasure of method aaa(T) is the same as another method in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " String aa(X x) { return null; }\n" + + " ^^^^^^^\n" + + "Erasure of method aa(X) is the same as another method in type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " T aa(T x) { return null; }\n" + + " ^^^^^^^\n" + + "Erasure of method aa(T) is the same as another method in type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " String a(X x) { return null; }\n" + + " ^^^^^^\n" + + "Erasure of method a(X) is the same as another method in type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " T a(T x) { return null; }\n" + + " ^^^^^^\n" + + "Erasure of method a(T) is the same as another method in type X\n" + + "----------\n" + + "7. WARNING in X.java (at line 8)\n" + + " String z(X x) { return null; }\n" + + " ^^^^^^\n" + + "Duplicate method z(X) in type X\n" + + "----------\n" + + "8. WARNING in X.java (at line 9)\n" + + " Object z(X x) { return null; }\n" + + " ^^^^^^\n" + + "Duplicate method z(X) in type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " String aaa(X x) { return null; }\n" + + " ^^^^^^^^\n" + + "Erasure of method aaa(X) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " T aaa(T x) { return null; }\n" + + " ^^^^^^^^\n" + + "Erasure of method aaa(T) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " String aa(X x) { return null; }\n" + + " ^^^^^^^\n" + + "Erasure of method aa(X) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " T aa(T x) { return null; }\n" + + " ^^^^^^^\n" + + "Erasure of method aa(T) is the same as another method in type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " String a(X x) { return null; }\n" + + " ^^^^^^\n" + + "Erasure of method a(X) is the same as another method in type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " T a(T x) { return null; }\n" + + " ^^^^^^\n" + + "Erasure of method a(T) is the same as another method in type X\n" + + "----------\n" + + "7. ERROR in X.java (at line 8)\n" + + " String z(X x) { return null; }\n" + + " ^^^^^^\n" + + "Duplicate method z(X) in type X\n" + + "----------\n" + + "8. ERROR in X.java (at line 9)\n" + + " Object z(X x) { return null; }\n" + + " ^^^^^^\n" + + "Duplicate method z(X) in type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String aaa(X x) { return null; }\n" + + " T aaa(T x) { return null; }\n" + + " String aa(X x) { return null; }\n" + + " T aa(T x) { return null; }\n" + + " String a(X x) { return null; }\n" + // dup + " T a(T x) { return null; }\n" + + " String z(X x) { return null; }\n" + + " Object z(X x) { return null; }\n" + + "}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: aaa(T) and aaa(X) have the same erasure + T aaa(T x) { return null; } + ^ + where T,T1,T2 are type-variables: + T extends X declared in method aaa(T) + T1 extends Object declared in method aaa(X) + T2 extends Object declared in method aaa(X) +X.java:5: name clash: aa(T#1) and aa(X) have the same erasure + T aa(T x) { return null; } + ^ + where T#1,T#2 are type-variables: + T#1 extends X declared in method aa(T#1) + T#2 extends Object declared in method aa(X) +X.java:7: a(X) is already defined in X + T a(T x) { return null; } + ^ +X.java:9: name clash: z(X) and z(X) have the same erasure + Object z(X x) { return null; } + ^ + where T#1,S,T#3 are type-variables: + T#1 extends Object declared in method z(X) + S extends Object declared in method z(X) + T#3 extends Object declared in method z(X) +4 errors + */ + } + // more duplicate tests, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=94897 + public void test054b() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " Object foo(X t) { return null; }\n" + + " ^^^^^^^^^^^\n" + + "Duplicate method foo(X) in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " String foo(X s) { return null; }\n" + + " ^^^^^^^^^^^\n" + + "Duplicate method foo(X) in type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Object foo(X t) { return null; }\n" + + " ^^^^^^^^^^^\n" + + "Duplicate method foo(X) in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " String foo(X s) { return null; }\n" + + " ^^^^^^^^^^^\n" + + "Duplicate method foo(X) in type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object foo(X t) { return null; }\n" + + " String foo(X s) { return null; }\n" + + "}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: foo(X) and foo(X) have the same erasure + String foo(X s) { return null; } + ^ + where S,T are type-variables: + S extends Object declared in method foo(X) + T extends Object declared in class X +1 error + */ + } + // more duplicate tests, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=94897 + public void test054c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " > void dupT() {}\n" + + " > Object dupT() {return null;}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " > void dupT() {}\n" + + " ^^^^^^\n" + + "Duplicate method dupT() in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " > Object dupT() {return null;}\n" + + " ^^^^^^\n" + + "Duplicate method dupT() in type X\n" + + "----------\n" + ); +/* javac 7 +X.java:3: dupT() is already defined in X + > Object dupT() {return null;} + ^ + where T1 is a type-variable: + T1 extends X declared in method dupT() +1 error + */ + } + // more duplicate tests, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=94897 + public void test054d() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " T a(A t) {return null;}\n" + + " ^^^^^^^^^\n" + + "Erasure of method a(A) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " String a(A o) {return null;}\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method a(A) is the same as another method in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " T aa(A t) {return null;}\n" + + " ^^^^^^^^^^\n" + + "Erasure of method aa(A) is the same as another method in type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " String aa(A o) {return null;}\n" + + " ^^^^^^^^^^^^^^^\n" + + "Erasure of method aa(A) is the same as another method in type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T a(A t) {return null;}\n" + + " ^^^^^^^^^\n" + + "Erasure of method a(A) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " String a(A o) {return null;}\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method a(A) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " T aa(A t) {return null;}\n" + + " ^^^^^^^^^^\n" + + "Erasure of method aa(A) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " String aa(A o) {return null;}\n" + + " ^^^^^^^^^^^^^^^\n" + + "Erasure of method aa(A) is the same as another method in type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T a(A t) {return null;}\n" + + " String a(A o) {return null;}\n" + + " T aa(A t) {return null;}\n" + + " String aa(A o) {return null;}\n" + + "}\n" + + "class A {}\n", + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: name clash: a(A) and a(A) have the same erasure + + String a(A o) {return null;} + ^ + where T#1,T#2 are type-variables: + T#1 extends Object declared in method a(A) + T#2 extends Object declared in method a(A) +X.java:5: name clash: aa(A) and aa(A) have the same erasure + String aa(A o) {return null;} + ^ + where T is a type-variable: + T extends Object declared in method aa(A) +2 errors + */ + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=95933 + public void test055() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A a = new C();\n" + + " try { a.f(new Object()); } catch (ClassCastException e) {\n" + + " System.out.println(1);\n" + + " }\n" + + " }\n" + + "}\n" + + "interface A { void f(T x); }\n" + + "interface B extends A { void f(String x); }\n" + + "class C implements B { public void f(String x) {} }\n" + }, + "1" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=97809 + public void test056() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String bind(String message, Object binding) { return null; }\n" + + " public static String bind(String message, Object[] bindings) { return null; }\n" + + "}\n" + + "class Y extends X {\n" + + " public static String bind(String message, Object binding) { return null; }\n" + + " public static String bind(String message, Object[] bindings) { return null; }\n" + + "}\n" + + "class Z {\n" + + " void bar() { Y.bind(\"\", new String[] {\"\"}); }\n" + + "}\n" + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84035 + public void test057() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " A x = new A();\n" + + " B y = new B();\n" + + " new X().print(x);\n" + + " new X().print(y);\n" + + " }\n" + + " public > void print(T a) { System.out.print(1); }\n" + + " public > void print(T a) { System.out.print(2); }\n" + + "}\n" + + "interface IA {}\n" + + "interface IB extends IA {}\n" + + "class A implements IA {}\n" + + "class B implements IB {}\n" + }, + "12"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84035 + public void test057a() { + this.runConformTest( + new String[] { + "XX.java", + "public class XX {\n" + + " public static void main(String[] args) {\n" + + " A x = new A();\n" + + " B y = new B();\n" + + " print(x);\n" + + " print(y);\n" + + " }\n" + + " public static > void print(T a) { System.out.print(3); }\n" + + " public static > void print(T a) { System.out.print(4); }\n" + + "}\n" + + "interface IA {}\n" + + "interface IB extends IA {}\n" + + "class A implements IA {}\n" + + "class B implements IB {}\n" + }, + "34"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94898 + public void test058() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.aaa(null);\n" + + " x.aaa(15);\n" + + " }\n" + + " T aaa(T t) { System.out.print('T'); return null; }\n" + + " void aaa(B b) { System.out.print('B'); }\n" + + "}\n" + }, + "BB"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94898 + public void test058a() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X().foo(\"X\");\n" + + " ^^^\n" + + "The method foo(String) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " new X().foo2(\"X\");\n" + + " ^^^^\n" + + "The method foo2(String) is ambiguous for the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " T foo(T t) {return null;}\n" + + " ^^^^^^^^\n" + + "Erasure of method foo(T) is the same as another method in type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " void foo(A a) {}\n" + + " ^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " T foo2(T t) {return null;}\n" + + " ^^^^^^^^^\n" + + "Erasure of method foo2(T) is the same as another method in type X\n" + + "----------\n" + + "6. WARNING in X.java (at line 9)\n" + + " void foo2(A a) {}\n" + + " ^^^^^^^^^\n" + + "Erasure of method foo2(A) is the same as another method in type X\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " T foo(T t) {return null;}\n" + + " ^^^^^^^^\n" + + "Erasure of method foo(T) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " void foo(A a) {}\n" + + " ^^^^^^^^\n" + + "Erasure of method foo(A) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " T foo2(T t) {return null;}\n" + + " ^^^^^^^^^\n" + + "Erasure of method foo2(T) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " void foo2(A a) {}\n" + + " ^^^^^^^^^\n" + + "Erasure of method foo2(A) is the same as another method in type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test() {\n" + + " new X().foo(\"X\");\n" + + " new X().foo2(\"X\");\n" + + " }\n" + + " T foo(T t) {return null;}\n" + + " void foo(A a) {}\n" + + " T foo2(T t) {return null;}\n" + + " void foo2(A a) {}\n" + + "}\n" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:7: name clash: foo(A) and foo(T) have the same erasure + void foo(A a) {} + ^ + where A,T are type-variables: + A extends Object declared in class X + T extends Object declared in method foo(T) +X.java:9: name clash: foo2(A) and foo2(T#3) have the same erasure + void foo2(A a) {} + ^ + where T#1,A,T#3 are type-variables: + T#1 extends Object declared in method foo2(A) + A extends Object declared in class X + T#3 extends Object declared in method foo2(T#3) +2 errors + */ + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=94898 + public void test058b() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X().foo(\"X\");\n" + + " ^^^\n" + + "The method foo(String) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " new X().foo2(\"X\");\n" + + " ^^^^\n" + + "The method foo2(String) is ambiguous for the type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " T foo(T t) {return null;}\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type X has the same erasure as foo(A) of type Y but does not override it\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " T foo2(T t) {return null;}\n" + + " ^^^^^^^^^\n" + + "Name clash: The method foo2(T) of type X has the same erasure as foo2(A) of type Y but does not override it\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X().foo(\"X\");\n" + + " ^^^\n" + + "The method foo(String) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " new X().foo2(\"X\");\n" + + " ^^^^\n" + + "The method foo2(String) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " T foo(T t) {return null;}\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(T) of type X has the same erasure as foo(A) of type Y but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " T foo2(T t) {return null;}\n" + + " ^^^^^^^^^\n" + + "Name clash: The method foo2(T) of type X has the same erasure as foo2(A) of type Y but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " void test() {\n" + + " new X().foo(\"X\");\n" + + " new X().foo2(\"X\");\n" + + " }\n" + + " T foo(T t) {return null;}\n" + + " T foo2(T t) {return null;}\n" + + "}\n" + + "class Y {\n" + + " void foo(A a) {}\n" + + " void foo2(A a) {}\n" + + "}" + }, + expectedCompilerLog + ); +/* javac 7 +X.java:3: reference to foo is ambiguous, both method foo(A) in Y and method foo(T) in X match + new X().foo("X"); + ^ + where A,T are type-variables: + A extends Object declared in class Y + T extends Object declared in method foo(T) +X.java:4: reference to foo2 is ambiguous, both method foo2(A) in Y and method foo2(T#3) in X match + new X().foo2("X"); + ^ + where T#1,A,T#3 are type-variables: + T#1 extends Object declared in method foo2(A) + A extends Object declared in class Y + T#3 extends Object declared in method foo2(T#3) +X.java:6: name clash: foo(T) in X and foo(A) in Y have the same erasure, yet neither overrides the other + T foo(T t) {return null;} + ^ + where T,A are type-variables: + T extends Object declared in method foo(T) + A extends Object declared in class Y +X.java:7: name clash: foo2(T#1) in X and foo2(A) in Y have the same erasure, yet neither overrides the other + T foo2(T t) {return null;} + ^ + where T#1,T#2,A are type-variables: + T#1 extends Object declared in method foo2(T#1) + T#2 extends Object declared in method foo2(A) + A extends Object declared in class Y +4 errors + */ + } + + public void test059() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {new B().foo(\"aa\");}\n" + + "}\n" + + "class A { void foo(U u) {System.out.print(false);} }\n" + + "class B extends A { void foo(String s) {System.out.print(true);} }\n" + }, + "true"); + } + public void test059a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {new B().foo(\"aa\");}\n" + + "}\n" + + "class A { void foo(String s) {System.out.print(true);} }\n" + + "class B extends A { void foo(V v) {System.out.print(false);} }\n" + }, + "true"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90619 + public void test060() { + this.runConformTest( + new String[] { + "I.java", + "import java.util.Iterator;\n" + + "public interface I {\n" + + " void method(Iterator iter);\n" + + " public static class TestClass implements I {\n" + + " public void method(Iterator iter) {}\n" + + " }\n" + + "}" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90619 + public void test060b() { + this.runConformTest( + new String[] { + "I2.java", + "import java.util.Iterator;\n" + + "public interface I2 {\n" + + " void method(Iterator[] iter);\n" + + " public static class TestClass implements I2 {\n" + + " public void method(Iterator[] iter) {}\n" + + " }\n" + + "}" + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=90619 + public void test060c() { + this.runNegativeTest( + new String[] { + "I3.java", + "import java.util.Iterator;\n" + + "public interface I3 {\n" + + " void method(Iterator[] iter);\n" + + " public static class TestClass implements I3 {\n" + + " public void method(Iterator[][] iter) {}\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in I3.java (at line 4)\n" + + " public static class TestClass implements I3 {\n" + + " ^^^^^^^^^\n" + + "The type I3.TestClass must implement the inherited abstract method I3.method(Iterator[])\n" + + "----------\n" + + "2. WARNING in I3.java (at line 5)\n" + + " public void method(Iterator[][] iter) {}\n" + + " ^^^^^^^^\n" + + "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + + "----------\n" + // does not override abstract method method(java.util.Iterator[]) in I3 + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=99106 + public void test061() { + this.runNegativeTest( + new String[] { + "Try.java", + "public class Try {\n" + + " public static void main(String[] args) {\n" + + " Ex ex = new Ex();\n" + + " ex.one(\"eclipse\", Integer.valueOf(1));\n" + + " ex.two(Integer.valueOf(1));\n" + + " ex.three(\"eclipse\");\n" + + " ex.four(\"eclipse\");\n" + + " System.out.print(',');\n" + + " Ex ex2 = ex;\n" + + " ex2.one(\"eclipse\", Integer.valueOf(1));\n" + // unchecked warning + " ex2.two(Integer.valueOf(1));\n" + // unchecked warning + " ex2.three(\"eclipse\");\n" + // unchecked warning + " ex2.four(\"eclipse\");\n" + // unchecked warning + " }\n" + + "}\n" + + "class Top {\n" + + " void one(TC cTop, TM mTop) { System.out.print(-1); }\n" + + " void two(TM mTop) { System.out.print(-2); }\n" + + " void three(TC cTop) { System.out.print(-3); }\n" + + " void four(TC cTop) { System.out.print(-4); }\n" + + "}\n" + + "class Ex extends Top {\n" + + " @Override void one(C cEx, M mEx) { System.out.print(1); }\n" + + " @Override void two(M mEx) { System.out.print(2); }\n" + + " @Override void three(C cEx) { System.out.print(3); }\n" + + " @Override void four(C cEx) { System.out.print(4); }\n" + + "}" + }, + "----------\n" + + "1. WARNING in Try.java (at line 9)\n" + + " Ex ex2 = ex;\n" + + " ^^\n" + + "Ex is a raw type. References to generic type Ex should be parameterized\n" + + "----------\n" + + "2. WARNING in Try.java (at line 10)\n" + + " ex2.one(\"eclipse\", Integer.valueOf(1));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method one(Object, Object) belongs to the raw type Ex. References to generic type Ex should be parameterized\n" + + "----------\n" + + "3. WARNING in Try.java (at line 11)\n" + + " ex2.two(Integer.valueOf(1));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method two(Object) belongs to the raw type Ex. References to generic type Ex should be parameterized\n" + + "----------\n" + + "4. WARNING in Try.java (at line 12)\n" + + " ex2.three(\"eclipse\");\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method three(Object) belongs to the raw type Ex. References to generic type Ex should be parameterized\n" + + "----------\n" + + "5. WARNING in Try.java (at line 13)\n" + + " ex2.four(\"eclipse\");\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method four(Object) belongs to the raw type Ex. References to generic type Ex should be parameterized\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=99106 + public void test062() { + this.runNegativeTest( + new String[] { + "Errors.java", + "public class Errors {\n" + + " void foo() {\n" + + " Ex ex = new Ex();\n" + + " ex.proof(\"eclipse\");\n" + + " ex.five(\"eclipse\");\n" + + " ex.six(\"eclipse\");\n" + + " Ex ex2 = ex;\n" + + " ex2.proof(\"eclipse\");\n" + + " ex2.five(\"eclipse\");\n" + + " ex2.six(\"eclipse\");\n" + + " }\n" + + "}\n" + + "class Top {\n" + + " void proof(Object cTop) {}\n" + + " void five(TC cTop) {}\n" + + " void six(TC cTop) {}\n" + + "}\n" + + "class Ex extends Top {\n" + + " @Override void proof(Object cTop) {}\n" + + " @Override void five(C cEx) {}\n" + + " @Override void six(C cEx) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in Errors.java (at line 5)\n" + + " ex.five(\"eclipse\");\n" + + " ^^^^\n" + + "The method five(String) is ambiguous for the type Ex\n" + + "----------\n" + + "2. ERROR in Errors.java (at line 6)\n" + + " ex.six(\"eclipse\");\n" + + " ^^^\n" + + "The method six(String) is ambiguous for the type Ex\n" + + "----------\n" + + "3. WARNING in Errors.java (at line 7)\n" + + " Ex ex2 = ex;\n" + + " ^^\n" + + "Ex is a raw type. References to generic type Ex should be parameterized\n" + + "----------\n" + + "4. ERROR in Errors.java (at line 9)\n" + + " ex2.five(\"eclipse\");\n" + + " ^^^^\n" + + "The method five(Object) is ambiguous for the type Ex\n" + + "----------\n" + + "5. ERROR in Errors.java (at line 10)\n" + + " ex2.six(\"eclipse\");\n" + + " ^^^\n" + + "The method six(Object) is ambiguous for the type Ex\n" + + "----------\n" + + "6. ERROR in Errors.java (at line 20)\n" + + " @Override void five(C cEx) {}\n" + + " ^^^^^^^^^^^\n" + + "Name clash: The method five(C) of type Ex has the same erasure as five(TC) of type Top but does not override it\n" + + "----------\n" + + "7. ERROR in Errors.java (at line 20)\n" + + " @Override void five(C cEx) {}\n" + + " ^^^^^^^^^^^\n" + + mustOverrideMessage("five(C)", "Ex") + + "----------\n" + + "8. ERROR in Errors.java (at line 21)\n" + + " @Override void six(C cEx) {}\n" + + " ^^^^^^^^^^\n" + + "Name clash: The method six(C) of type Ex has the same erasure as six(TC) of type Top but does not override it\n" + + "----------\n" + + "9. ERROR in Errors.java (at line 21)\n" + + " @Override void six(C cEx) {}\n" + + " ^^^^^^^^^^\n" + + mustOverrideMessage("six(C)", "Ex") + + "----------\n" + // 5: reference to five is ambiguous, both method five(TC) in Top and method five(C) in Ex match + // 6: reference to six is ambiguous, both method six(TC) in Top and method six(C) in Ex match + // 9: reference to five is ambiguous, both method five(TC) in Top and method five(C) in Ex match + // **** 9: warning: [unchecked] unchecked call to five(TC) as a member of the raw type Top + // 10: reference to six is ambiguous, both method six(TC) in Top and method six(C) in Ex match + // **** 10: warning: [unchecked] unchecked call to six(TC) as a member of the raw type Top + // 20: method does not override a method from its superclass + // 21: method does not override a method from its superclass + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=104551 + public void test063() { + this.runConformTest( + new String[] { + "X.java", + "interface IStructuredContentProvider {\n" + + " public E[] getElements(I inputElement);\n" + + " public E[] getChildren(E parent);\n" + + "}\n" + + "\n" + + "public class X implements IStructuredContentProvider {\n" + + "// eclipse error: The type X must implement the inherited\n" + + "// abstract method IStructuredContentProvider.getChildren(I)\n" + + "\n" + + " public Object[] getElements(Object inputElement) {\n" + + " // eclipse error: The return type is incompatible with\n" + + " // IStructuredContentProvider.getElements(Object)\n" + + " return null;\n" + + " }\n" + + "\n" + + " public Object[] getChildren(Object parent) {\n" + + " // eclipse error: Name clash: The method getChildren(Object) of type\n" + + " // X has the same erasure as getChildren(E) of type\n" + + " // IStructuredContentProvider but does not override it\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=104551 - variation + public void test064() { + this.runConformTest( + new String[] { + "X.java", + "interface IStructuredContentProvider {\n" + + " public E[] getElements(I inputElement);\n" + + " public E[] getChildren(E parent);\n" + + "}\n" + + "\n" + + "public class X implements IStructuredContentProvider {\n" + + "// eclipse error: The type X must implement the inherited\n" + + "// abstract method IStructuredContentProvider.getChildren(I)\n" + + "\n" + + " public Object[] getElements(Object inputElement) {\n" + + " // eclipse error: The return type is incompatible with\n" + + " // IStructuredContentProvider.getElements(Object)\n" + + " return null;\n" + + " }\n" + + "\n" + + " public Object[] getChildren(Object parent) {\n" + + " // eclipse error: Name clash: The method getChildren(Object) of type\n" + + " // X has the same erasure as getChildren(E) of type\n" + + " // IStructuredContentProvider but does not override it\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=104551 - variation + public void test065() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "interface IStructuredContentProvider> {\n" + + " public E[] getElements(I inputElement);\n" + + " public E[] getChildren(E parent);\n" + + "}\n" + + "\n" + + "public class X implements IStructuredContentProvider {\n" + + "// eclipse error: The type X must implement the inherited\n" + + "// abstract method IStructuredContentProvider.getChildren(I)\n" + + "\n" + + " public List[] getElements(Object inputElement) {\n" + + " // eclipse error: The return type is incompatible with\n" + + " // IStructuredContentProvider.getElements(Object)\n" + + " return null;\n" + + " }\n" + + "\n" + + " public List[] getChildren(List parent) {\n" + + " // eclipse error: Name clash: The method getChildren(Object) of type\n" + + " // X has the same erasure as getChildren(E) of type\n" + + " // IStructuredContentProvider but does not override it\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=103849 + public void test066() { + this.runConformTest( + new String[] { + "JukeboxImpl.java", + "public class JukeboxImpl implements Jukebox {\n" + + " public > A getArtist (M music){return null;}\n" + + " void test () { getArtist(new Rock()); }\n" + + "}\n" + + "interface Jukebox {\n" + + " > A getArtist (M music);\n" + + "}\n" + + "interface Music {}\n" + + "class Rock implements Music {}\n" + + "interface Artist {}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=107098 + public void test067() { + this.runConformTest( + new String[] { + "NoErrors.java", + "public class NoErrors {\n" + + " public static void main(String[] args) { new B().foo2(1, 10); }\n" + + "}\n" + + "class A {\n" + + " void foo2(Number t, S1 s) { System.out.print(false); }\n" + + "}\n" + + "class B extends A {\n" + + " void foo2(Number t, S2 s) { System.out.print(true); }\n" + + "}\n" + }, + "true"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=107681 + public void test068() { + this.runConformTest( + new String[] { + "ReflectionNavigator.java", + "import java.lang.reflect.Type;\n" + + "public class ReflectionNavigator implements Navigator {\n" + + " public Class erasure(Type t) { return null; }\n" + + "}\n" + + "interface Navigator {\n" + + " TypeT erasure(TypeT x);\n" + + "}\n" + + "class Usage {\n" + + " public void foo(ReflectionNavigator r, Type t) { r.erasure(t); }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=108203 + public void test069() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.reflect.Type;\n" + + "public class X implements I {\n" + + " public void x1() {}\n" + + " public void x2() {}\n" + + " public void x3() {}\n" + + "}\n" + + "interface I {\n" + + " void x1();\n" + + " void x2();\n" + + " void x3();\n" + + "}\n" + + "class A {}\n" + + "class B {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X implements I {\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.x3()\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public class X implements I {\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.x2()\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " public void x2() {}\n" + + " ^^^^\n" + + "Name clash: The method x2() of type X has the same erasure as x2() of type I but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " public void x3() {}\n" + + " ^^^^\n" + + "Name clash: The method x3() of type X has the same erasure as x3() of type I but does not override it\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " void x2();\n" + + " ^^^^^^\n" + + "The type parameter N should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=101049 + public void test070() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + this.runConformTest( + true, + new String[] { + "BooleanFactory.java", + "interface Factory {\n" + + " U create(Class c);\n" + + "}\n" + + "public class BooleanFactory implements Factory {\n" + + " public U create(Class c) {\n" + + " try { return c.newInstance(); } catch(Exception e) { return null; }\n" + + " }\n" + + "}\n" + }, null, options, + "----------\n" + + "1. WARNING in BooleanFactory.java (at line 5)\n" + + " public U create(Class c) {\n" + + " ^^^^^^^\n" + + "The type parameter U should not be bounded by the final type Boolean. Final types cannot be further extended\n" + + "----------\n", + null, null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=107045 + public void test071() { + this.runNegativeTest( + new String[] { + "D.java", + "class D extends B {\n" + + " @Override void m(Number t) {}\n" + + " @Override void m(Integer t) {}\n" + + "}\n" + + "class A { void m(T t) {} }\n" + + "class B extends A { @Override void m(S t) {} }" + }, + "----------\n" + + "1. ERROR in D.java (at line 2)\n" + + " @Override void m(Number t) {}\n" + + " ^^^^^^^^^^^\n" + + "Name clash: The method m(Number) of type D has the same erasure as m(T) of type A but does not override it\n" + + "----------\n" + + "2. ERROR in D.java (at line 2)\n" + + " @Override void m(Number t) {}\n" + + " ^^^^^^^^^^^\n" + + mustOverrideMessage("m(Number)", "D") + + "----------\n" + + "3. WARNING in D.java (at line 6)\n" + + " class B extends A { @Override void m(S t) {} }\n" + + " ^^^^^^^\n" + + "The type parameter S should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=108780 + public void test072() { + this.runConformTest( + new String[] { + "B.java", + "class A { E foo(E e) { return null; } }\n" + + "class B extends A {\n" + + " @Override T foo(Object arg0) { return null; }\n" + + "}" + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=111350 + public void test073() { + this.runConformTest( + new String[] { + "NumericArray.java", + "class Array {\n" + + " public void add(T t) { System.out.println(false); }\n" + + "}\n" + + "public class NumericArray extends Array {\n" + + " public static void main(String[] s) { new NumericArray().add(1); }\n" + + " @Override public void add(Number n) { System.out.println(true); }\n" + + "}" + }, + "true" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=111350 + public void test073a() { + this.runConformTest( + new String[] { + "NumericArray2.java", + "class Array {\n" + + " public T add(T t) { System.out.println(false); return null; }\n" + + "}\n" + + "public class NumericArray2 extends Array {\n" + + " public static void main(String[] s) { new NumericArray2().add(1); }\n" + + " @Override public T add(Number n) { System.out.println(true); return null; }\n" + + "}" + }, + "true" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=111350 + public void test073b() { + this.runConformTest( + new String[] { + "NumericArray3.java", + "class Array {\n" + + " public void add(U u) {}\n" + + "}\n" + + "public class NumericArray3 extends Array {\n" + + " public static void main(String[] s) { new NumericArray3().add(1); }\n" + + " @Override public void add(Number n) { System.out.println(true); }\n" + + "}" + }, + "true" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=111350 + public void test073c() { + this.runNegativeTest( + new String[] { + "NumericArray4.java", + "class Array {\n" + + " public void add(T t) {}\n" + + "}\n" + + "public class NumericArray4 extends Array {\n" + + " @Override public void add(Number n) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in NumericArray4.java (at line 5)\n" + + " @Override public void add(Number n) {}\n" + + " ^^^^^^^^^^^^^\n" + + mustOverrideMessage("add(Number)", "NumericArray4") + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=111350 + public void test073d() { + this.runNegativeTest( + new String[] { + "NumericArray5.java", + "class Array {\n" + + " public void add(T t, U u) {}\n" + + "}\n" + + "public class NumericArray5 extends Array {\n" + + " @Override public void add(Number n, Integer i) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in NumericArray5.java (at line 5)\n" + + " @Override public void add(Number n, Integer i) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + mustOverrideMessage("add(Number, Integer)", "NumericArray5") + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=100970 + public void test074() { + this.runNegativeTest( + new String[] { + "I.java", + "interface I {}\n" + + "interface J extends I { @Override void clone(); }" + }, + "----------\n" + + "1. WARNING in I.java (at line 2)\n" + + " interface J extends I { @Override void clone(); }\n" + + " ^^^^\n" + + "The return type is incompatible with Object.clone(), thus this interface cannot be implemented\n" + + "----------\n" + + "2. ERROR in I.java (at line 2)\n" + + " interface J extends I { @Override void clone(); }\n" + + " ^^^^^^^\n" + + mustOverrideMessage("clone()", "J") + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=100970 + public void test074a() { + this.runNegativeTest( + new String[] { + "I.java", + "interface I { @Override void clone(); }\n" + + "interface J extends I {}" + }, + "----------\n" + + "1. WARNING in I.java (at line 1)\n" + + " interface I { @Override void clone(); }\n" + + " ^^^^\n" + + "The return type is incompatible with Object.clone(), thus this interface cannot be implemented\n" + + "----------\n" + + "2. ERROR in I.java (at line 1)\n" + + " interface I { @Override void clone(); }\n" + + " ^^^^^^^\n" + + mustOverrideMessage("clone()", "I") + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=100970 + public void test074b() { + this.runNegativeTest( + new String[] { + "A.java", + "interface I {\n" + + " int finalize();\n" + + " float hashCode();\n" + + "}\n" + + "interface J extends I {}\n" + + "abstract class A implements J {}" + }, + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " int finalize();\n" + + " ^^^\n" + + "The return type is incompatible with Object.finalize(), thus this interface cannot be implemented\n" + + "----------\n" + + "2. ERROR in A.java (at line 3)\n" + + " float hashCode();\n" + + " ^^^^^\n" + + "The return type is incompatible with Object.hashCode()\n" + + "----------\n" + + "3. ERROR in A.java (at line 6)\n" + + " abstract class A implements J {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods I.finalize(), Object.finalize()\n" + + "----------\n" + + "4. ERROR in A.java (at line 6)\n" + + " abstract class A implements J {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods I.hashCode(), Object.hashCode()\n" + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=107105 + public void test075() { + this.runNegativeTest( + new String[] { + "A.java", + "class A { > void foo() { } }\n" + + "class B extends A { @Override > void foo() { } }\n" + // fails, name clash only shows up when Override is removed + "class C extends A { @Override void foo() { } }\n" + // fails, name clash only shows up when Override is removed + "class D extends A { @Override > void foo() { } }\n" + + "class E extends A { @Override & J> void foo() { } }\n" + + "interface I {}\n" + + "interface J {}" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " class B extends A { @Override > void foo() { } }\n" + + " ^^^^^\n" + + "Name clash: The method foo() of type B has the same erasure as foo() of type A but does not override it\n" + + "----------\n" + + "2. ERROR in A.java (at line 2)\n" + + " class B extends A { @Override > void foo() { } }\n" + + " ^^^^^\n" + + mustOverrideMessage("foo()", "B") + + "----------\n" + + "3. WARNING in A.java (at line 3)\n" + + " class C extends A { @Override void foo() { } }\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "4. ERROR in A.java (at line 3)\n" + + " class C extends A { @Override void foo() { } }\n" + + " ^^^^^\n" + + "Name clash: The method foo() of type C has the same erasure as foo() of type A but does not override it\n" + + "----------\n" + + "5. ERROR in A.java (at line 3)\n" + + " class C extends A { @Override void foo() { } }\n" + + " ^^^^^\n" + + mustOverrideMessage("foo()", "C") + + "----------\n" + // A.java:2: method does not override a method from its superclass + // A.java:3: method does not override a method from its superclass + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=107105 + public void test075a() { + this.runConformTest( + // there is no name clash in this case AND no override error - there would be if the annotation was present + new String[] { + "A.java", + "class A { void foo(U u, S s) { } }\n" + + "class B extends A { void foo(V v, S1 s) { } }\n" + + "interface J {}\n" + + "interface K extends J {}" + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=107105 + public void test075b() { + this.runNegativeTest( + new String[] { + "A.java", + "class A { > void foo(U u, T t, S s) { } }\n" + + "class B extends A { @Override > void foo(V v, T1 t, S1 s) { } }\n" + + "interface I {}\n" + + "interface J {}\n" + + "interface K extends J {}" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " class B extends A { @Override > void foo(V v, T1 t, S1 s) { } }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + mustOverrideMessage("foo(V, T1, S1)", "B") + + "----------\n" + // A.java:2: method does not override a method from its superclass + ); + } + public void test076() { + this.runConformTest( + new String[] { + "A.java", + "class A {\n" + + " > void foo(S s) { }\n" + + " & J > void foo(S s) { }\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n" + }, + "" + ); + } + public void test076a() { + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " > void foo() { }\n" + + " & J> void foo() { }\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " > void foo() { }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type A\n" + + "----------\n" + + "2. ERROR in A.java (at line 3)\n" + + " & J> void foo() { }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type A\n" + + "----------\n" + // foo() is already defined in A + ); + } + public void test076b() { + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " > void foo() { }\n" + + " & K> void foo() { }\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n" + + "interface K extends J {}" + }, + "----------\n" + + "1. ERROR in A.java (at line 2)\n" + + " > void foo() { }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type A\n" + + "----------\n" + + "2. ERROR in A.java (at line 3)\n" + + " & K> void foo() { }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type A\n" + + "----------\n" + // name clash: foo() and foo() have the same erasure + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=122881 + public void test077() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o = new A().foo(new Integer(1));\n" + + "}\n" + + "interface I { I foo(T1 t); }\n" + + "interface J { J foo(T2 t); }\n" + + "class B { public A foo(T t) { return new A(); } }\n" + + "class A extends B implements I, J {}" + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=122881 + public void test077a() { + this.runNegativeTest( + new String[] { + "I.java", + "public interface I { I foo(); }\n" + + "interface J { J foo(); }\n" + + "interface K extends I, J { K foo(); }\n" + + "interface L { K getI(); }\n" + + "interface M { I getI(); }\n" + + "interface N { J getI(); }\n" + + "interface O extends L, M, N { K getI(); }\n" + + "interface P extends L, M, N {}\n" + + "class X implements L, M, N { public K getI() { return null; } }\n" + + "abstract class Y implements L, M, N {}\n" + + "abstract class Z implements L, M, N { public K getI() { return null; } }\n" + }, + "" +// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=241821 +// Now if 1 of 3 methods is acceptable to the other 2 then no error is reported +/* See addtional comments in https://bugs.eclipse.org/bugs/show_bug.cgi?id=122881 + "----------\n" + + "1. ERROR in I.java (at line 3)\n" + + " interface K extends I, J { K foo(); }\n" + + " ^\n" + + "The return type is incompatible with J.foo(), I.foo()\n" + + "----------\n" + + "2. ERROR in I.java (at line 7)\n" + + " interface O extends L, M, N { K getI(); }\n" + + " ^\n" + + "The return type is incompatible with N.getI(), M.getI(), L.getI()\n" + + "----------\n" + + "3. ERROR in I.java (at line 8)\n" + + " interface P extends L, M, N {}\n" + + " ^\n" + + "The return type is incompatible with N.getI(), M.getI(), L.getI()\n" + + "----------\n" + + "4. ERROR in I.java (at line 10)\n" + + " abstract class Y implements L, M, N {}\n" + + " ^\n" + + "The return type is incompatible with N.getI(), M.getI(), L.getI()\n" + + "----------\n" +*/ + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=128560 + public void test078() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + customOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + this.runNegativeTest( + true, + new String[] { + "X.java", + "public abstract class X implements IAppendable {\n" + + " public X append(char c) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface IAppendable {\n" + + " IAppendable append(char c);\n" + + "}\n", + }, + null, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public X append(char c) {\n" + + " ^\n" + + "The return type is incompatible with IAppendable.append(char)\n" + + "----------\n", + JavacTestOptions.SKIP /* we are altering the compatibility settings */); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=81222 + public void test079() { + this.runNegativeTest( + new String[] { + "A.java", + "class A { void x(A s) {} }\n" + + "class B extends A { void x(A s) {} }\n" + + "class C extends A { @Override void x(A s) {} }\n" + + "class D extends A { void x(A s) {} }" + }, + "----------\n" + + "1. WARNING in A.java (at line 2)\n" + + " class B extends A { void x(A s) {} }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "2. ERROR in A.java (at line 2)\n" + + " class B extends A { void x(A s) {} }\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method x(A) of type B has the same erasure as x(A) of type A but does not override it\n" + + "----------\n" + + "3. WARNING in A.java (at line 3)\n" + + " class C extends A { @Override void x(A s) {} }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "4. WARNING in A.java (at line 3)\n" + + " class C extends A { @Override void x(A s) {} }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "5. WARNING in A.java (at line 4)\n" + + " class D extends A { void x(A s) {} }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "6. ERROR in A.java (at line 4)\n" + + " class D extends A { void x(A s) {} }\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method x(A) of type D has the same erasure as x(A) of type A but does not override it\n" + + "----------\n" + // name clash: x(A) in B and x(A) in A have the same erasure, yet neither overrides the other + // name clash: x(A) in D and x(A) in A have the same erasure, yet neither overrides the other + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=106880 + public void test080() { + this.runNegativeTest( + new String[] { + "HashOrder.java", + "public class HashOrder extends DoubleHash {\n" + + " public static HashOrder create() { return null; }\n" + + "}\n" + + "class DoubleHash {\n" + + " public static DoubleHash create() { return null; }\n" + + "}" + }, + "----------\n" + + "1. WARNING in HashOrder.java (at line 2)\n" + + " public static HashOrder create() { return null; }\n" + + " ^^^^^^^^^\n" + + "Type safety: The return type HashOrder for create() from the type HashOrder needs unchecked conversion to conform to DoubleHash from the type DoubleHash\n" + + "----------\n" + // warning: create() in HashOrder overrides create() in DoubleHash; return type requires unchecked conversion + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=125956 + public void test081() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X implements I {\n" + + " public A foo() { return null; }\n" + + " public A bar() { return null; }\n" + + "}\n" + + "interface I {\n" + + " A foo();\n" + + " A bar();\n" + + "}\n" + + "class A {}" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public A foo() { return null; }\n" + + " ^\n" + + "Type safety: The return type A for foo() from the type X needs unchecked conversion to conform to A from the type I\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public A bar() { return null; }\n" + + " ^^^^\n" + + "The return type is incompatible with I.bar()\n" + + "----------\n" + // bar() in X cannot implement bar() in I; attempting to use incompatible return type + // warning: foo() in X implements foo() in I; return type requires unchecked conversion + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=105339 + public void test082() { + this.runNegativeTest( + new String[] { + "V.java", + "public class V extends U { @Override public C foo() { return null; } }\n" + + "class U { public C foo() { return null; } }\n" + + "class A {}\n" + + "class B extends A {}\n" + + "class C {}" + }, + "----------\n" + + "1. WARNING in V.java (at line 1)\n" + + " public class V extends U { @Override public C foo() { return null; } }\n" + + " ^\n" + + "Type safety: The return type C for foo() from the type V needs unchecked conversion to conform to C from the type U\n" + + "----------\n" + // warning: foo() in V overrides foo() in U; return type requires unchecked conversion + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=132831 + public void test083() { + this.runConformTest( + new String[] { + "C.java", + "public class C extends p.B {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(((p.I) new C()).m() == null);\n" + + " }\n" + + "}", + "p/B.java", + "package p;\n" + + "public abstract class B extends A {}\n" + + "abstract class A implements I {\n" + + " public A m() { return null; }\n" + + "}", + "p/I.java", + "package p;\n" + + "public interface I { I m(); }\n" + }, + "true" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=132841 + public void test084() { + this.runConformTest( + new String[] { + "A.java", + "public class A implements I {\n" + + " public java.util.List f(M n) { return null; }\n" + + " static class M {}\n" + + "}\n" + + "interface I {\n" + + " java.util.List f(T2 t);\n" + + "}" + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=132841 + public void test084a() { + this.runConformTest( + new String[] { + "A.java", + "public class A implements I {\n" + + " public void foo(Number n, M m) {}\n" + + " public void foo2(Number n, M m) {}\n" + + " public void foo3(Number n, M m) {}\n" + + " static class M {}\n" + + "}\n" + + "interface I {\n" + + " void foo(U u, T2 t);\n" + + " void foo2(Number n, T2 t);\n" + + " void foo3(U u, A.M m);\n" + + "}" + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=132841 + public void test084b() { + this.runNegativeTest( + new String[] { + "A.java", + "public class A implements I {\n" + + " public void foo4(Number n, T1 m) {}\n" + + " static class M {}\n" + + "}\n" + + "interface I {\n" + + " void foo4(U u, A.M m);\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 1)\n" + + " public class A implements I {\n" + + " ^\n" + + "The type A must implement the inherited abstract method I.foo4(U, A.M)\n" + + "----------\n" + + "2. ERROR in A.java (at line 2)\n" + + " public void foo4(Number n, T1 m) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo4(Number, T1) of type A has the same erasure as foo4(U, A.M) of type I but does not override it\n" + + "----------\n" + // A is not abstract and does not override abstract method foo4(U,A.M) in I + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=136543 + public void test085() { + this.runNegativeTest( + new String[] { + "Parent.java", + "import java.util.Collection;\n" + + "public class Parent {\n" + + " static void staticCase1(Collection c) {}\n" + + " static void staticCase2(Collection c) {}\n" + + " void instanceCase1(Collection c) {}\n" + + " void instanceCase2(Collection c) {}\n" + + "}\n" + + "class Child extends Parent {\n" + + " static void staticCase1(Collection c) {}\n" + + " static void staticCase2(Collection c) {}\n" + + " void instanceCase1(Collection c) {}\n" + + " @Override void instanceCase2(Collection c) {}\n" + + "}" + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in Parent.java (at line 3)\n" + + " static void staticCase1(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in Parent.java (at line 5)\n" + + " void instanceCase1(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. WARNING in Parent.java (at line 10)\n" + + " static void staticCase2(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "4. ERROR in Parent.java (at line 11)\n" + + " void instanceCase1(Collection c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method instanceCase1(Collection) of type Child has the same erasure as instanceCase1(Collection) of type Parent but does not override it\n" + + "----------\n" + + "5. WARNING in Parent.java (at line 12)\n" + + " @Override void instanceCase2(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n": + "----------\n" + + "1. WARNING in Parent.java (at line 3)\n" + + " static void staticCase1(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in Parent.java (at line 5)\n" + + " void instanceCase1(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in Parent.java (at line 9)\n" + + " static void staticCase1(Collection c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method staticCase1(Collection) of type Child has the same erasure as staticCase1(Collection) of type Parent but does not hide it\n" + + "----------\n" + + "4. WARNING in Parent.java (at line 10)\n" + + " static void staticCase2(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "5. ERROR in Parent.java (at line 11)\n" + + " void instanceCase1(Collection c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method instanceCase1(Collection) of type Child has the same erasure as instanceCase1(Collection) of type Parent but does not override it\n" + + "----------\n" + + "6. WARNING in Parent.java (at line 12)\n" + + " @Override void instanceCase2(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + // @Override is an error for instanceCase1 + // name clash: instanceCase1(Collection) in Child and instanceCase1(Collection) in Parent have the same erasure, yet neither overrides the other + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=136543 - case 2 + public void test085b() { + this.runNegativeTest( + new String[] { + "Parent.java", + "import java.util.Collection;\n" + + "public class Parent {\n" + + " static void staticMismatchCase1(Collection c) {}\n" + + " static void staticMismatchCase2(Collection c) {}\n" + + " void mismatchCase1(Collection c) {}\n" + + " void mismatchCase2(Collection c) {}\n" + + "}\n" + + "class Child extends Parent {\n" + + " void staticMismatchCase1(Collection c) {}\n" + + " void staticMismatchCase2(Collection c) {}\n" + + " static void mismatchCase1(Collection c) {}\n" + + " static void mismatchCase2(Collection c) {}\n" + + "}" + }, + "----------\n" + + "1. WARNING in Parent.java (at line 3)\n" + + " static void staticMismatchCase1(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "2. WARNING in Parent.java (at line 5)\n" + + " void mismatchCase1(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in Parent.java (at line 9)\n" + + " void staticMismatchCase1(Collection c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "This instance method cannot override the static method from Parent\n" + + "----------\n" + + "4. WARNING in Parent.java (at line 9)\n" + + " void staticMismatchCase1(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "5. ERROR in Parent.java (at line 10)\n" + + " void staticMismatchCase2(Collection c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "This instance method cannot override the static method from Parent\n" + + "----------\n" + + "6. ERROR in Parent.java (at line 11)\n" + + " static void mismatchCase1(Collection c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "This static method cannot hide the instance method from Parent\n" + + "----------\n" + + "7. WARNING in Parent.java (at line 11)\n" + + " static void mismatchCase1(Collection c) {}\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "8. ERROR in Parent.java (at line 12)\n" + + " static void mismatchCase2(Collection c) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "This static method cannot hide the instance method from Parent\n" + + "----------\n" + // staticMismatchCase1(java.util.Collection) in Child cannot override staticMismatchCase1(java.util.Collection) in Parent; overridden method is static + // staticMismatchCase2(java.util.Collection) in Child cannot override staticMismatchCase2(java.util.Collection) in Parent; overridden method is static + // mismatchCase1(java.util.Collection) in Child cannot override mismatchCase1(java.util.Collection) in Parent; overriding method is static + // mismatchCase2(java.util.Collection) in Child cannot override mismatchCase2(java.util.Collection) in Parent; overriding method is static + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=136543 - case 3 + public void test085c() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X extends CX implements IX {}\n" + + "class CX { public static void foo(Object o) {} }\n" + + "abstract class X2 extends CX implements IX {}\n" + + "interface IX { void foo(U u); }" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public abstract class X extends CX implements IX {}\n" + + " ^\n" + + "The static method foo(Object) conflicts with the abstract method in IX\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " abstract class X2 extends CX implements IX {}\n" + + " ^^\n" + + "The static method foo(Object) conflicts with the abstract method in IX\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " abstract class X2 extends CX implements IX {}\n" + + " ^^\n" + + "CX is a raw type. References to generic type CX should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\n" + + " abstract class X2 extends CX implements IX {}\n" + + " ^^\n" + + "IX is a raw type. References to generic type IX should be parameterized\n" + + "----------\n" + // line 1: foo(java.lang.Object) in CX cannot implement foo(U) in IX; overriding method is static + // line 3: foo(java.lang.Object) in CX cannot implement foo(U) in IX; overriding method is static + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90438 + public void test086() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I { public void copyData(T data) {} }\n" + + "interface I { void copyData(A data); }\n" + + "interface Data {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements I { public void copyData(T data) {} }\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.copyData(A)\n" + + "----------\n" + // X is not abstract and does not override abstract method copyData(A) in I + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90438 - case 2 + public void test086b() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I { public G foo(Class stuffClass) { return null; } }\n" + + "interface I { G foo(Class stuffClass); }\n" + + "class G {}" + }, + "" + ); + } + public void test087() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "\n" + + "interface Interface1 {\n" + + "}\n" + + "interface Interface2 extends Interface1 {\n" + + "}\n" + + "interface Interface3 {\n" + + "

    Collection

    doStuff();\n" + + "}\n" + + "interface Interface4 extends Interface3 {\n" + + " Collection doStuff();\n" + + "}\n" + + "public class X {\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " Collection doStuff();\n" + + " ^^^^^^^^^^\n" + + "Type safety: The return type Collection for doStuff() from the type Interface4 needs unchecked conversion to conform to Collection from the type Interface3\n" + + "----------\n" + + "2. 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=142653 - variation + public void test088() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "import java.util.*;\n" + + "public class X extends ArrayList implements I,Runnable {\n" + + " \n" + + " void foo() {\n" + + " this.add(new Object());\n" + + " this.add(null);\n" + + " }\n" + + "}\n" + + "interface I extends Collection {\n" + + "}\n" , // =================, // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X extends ArrayList implements I,Runnable {\n" + + " ^\n" + + "The interface Collection cannot be implemented more than once with different arguments: Collection and Collection\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public class X extends ArrayList implements I,Runnable {\n" + + " ^\n" + + "The type X must implement the inherited abstract method Runnable.run()\n" + + "----------\n" + + "3. WARNING in X.java (at line 2)\n" + + " public class X extends ArrayList implements I,Runnable {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " this.add(new Object());\n" + + " ^^^\n" + + "The method add(T0) in the type ArrayList is not applicable for the arguments (Object)\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=142653 - variation + public void test089() { + this.runNegativeTest( + new String[] { + "X.java",//=================== + "import java.util.*;\n" + + "public class X extends X2 {}\n" + + "abstract class X2 extends X3 implements List {}\n" + + "abstract class X3 implements List {}", // ================= + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " abstract class X2 extends X3 implements List {}\n" + + " ^^\n" + + "The interface List cannot be implemented more than once with different arguments: List and List\n" + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=147690 + public void test090() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class XSuper {\n" + + " Object foo() throws Exception { return null; }\n" + + " protected Object bar() throws Exception { return null; }\n" + + "}\n" + + "public class X extends XSuper {\n" + + " protected String foo() { return null; }\n" + + " public String bar() { return null; }\n" + + "}", // ================= + }, + ""); + // ensure bridge methods have target method modifiers, and inherited thrown exceptions + String expectedOutput = + " // Method descriptor #17 ()Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 1\n" + + " public bridge synthetic java.lang.Object bar() throws java.lang.Exception;\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bar() : java.lang.String [21]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " \n" + + " // Method descriptor #17 ()Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 1\n" + + " protected bridge synthetic java.lang.Object foo() throws java.lang.Exception;\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.foo() : java.lang.String [23]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=148783 + public void test091() { + this.runNegativeTest( + new String[] { + "DataSet.java",//=================== + "import java.io.Serializable;\n" + + "import java.util.*;\n" + + "\n" + + "class DataSet implements List, Iterator, Serializable {\n" + + " \n" + + " public S[] toArray(S[] s) {\n" + + " return s;\n" + + " }\n" + + "\n" + + " public boolean add(Object o) { return false; }\n" + + " public void add(int index, Object element) {}\n" + + " public boolean addAll(Collection c) { return false; }\n" + + " public boolean addAll(int index, Collection c) { return false; }\n" + + " public void clear() {}\n" + + " public boolean contains(Object o) { return false; }\n" + + " public boolean containsAll(Collection c) { return false; }\n" + + " public Object get(int index) { return null; }\n" + + " public int indexOf(Object o) { return 0; }\n" + + " public boolean isEmpty() { return false; }\n" + + " public Iterator iterator() { return null; }\n" + + " public int lastIndexOf(Object o) { return 0; }\n" + + " public ListIterator listIterator() { return null; }\n" + + " public ListIterator listIterator(int index) { return null; }\n" + + " public boolean remove(Object o) { return false; }\n" + + " public Object remove(int index) { return null; }\n" + + " public boolean removeAll(Collection c) { return false; }\n" + + " public boolean retainAll(Collection c) { return false; }\n" + + " public Object set(int index, Object element) { return false; }\n" + + " public int size() { return 0; }\n" + + " public List subList(int fromIndex, int toIndex) { return null; }\n" + + " public Object[] toArray() { return null; }\n" + + " public boolean hasNext() { return false; }\n" + + " public Object next() { return null; }\n" + + " public void remove() {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^^^^\n" + + "The type DataSet must implement the inherited abstract method List.toArray(Object[])\n" + + "----------\n" + + "2. WARNING in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^^^^\n" + + "The serializable class DataSet does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^^^^^\n" + + "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + + "----------\n" + + "5. ERROR in DataSet.java (at line 6)\n" + + " public S[] toArray(S[] s) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method toArray(S[]) of type DataSet has the same erasure as toArray(Object[]) of type List but does not override it\n" + + "----------\n" + + "6. ERROR in DataSet.java (at line 6)\n" + + " public S[] toArray(S[] s) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method toArray(S[]) of type DataSet has the same erasure as toArray(Object[]) of type Collection but does not override it\n" + + "----------\n" + + "7. WARNING in DataSet.java (at line 12)\n" + + " public boolean addAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "8. WARNING in DataSet.java (at line 13)\n" + + " public boolean addAll(int index, Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "9. WARNING in DataSet.java (at line 16)\n" + + " public boolean containsAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "10. WARNING in DataSet.java (at line 20)\n" + + " public Iterator iterator() { return null; }\n" + + " ^^^^^^^^\n" + + "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + + "----------\n" + + "11. WARNING in DataSet.java (at line 22)\n" + + " public ListIterator listIterator() { return null; }\n" + + " ^^^^^^^^^^^^\n" + + "ListIterator is a raw type. References to generic type ListIterator should be parameterized\n" + + "----------\n" + + "12. WARNING in DataSet.java (at line 23)\n" + + " public ListIterator listIterator(int index) { return null; }\n" + + " ^^^^^^^^^^^^\n" + + "ListIterator is a raw type. References to generic type ListIterator should be parameterized\n" + + "----------\n" + + "13. WARNING in DataSet.java (at line 26)\n" + + " public boolean removeAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "14. WARNING in DataSet.java (at line 27)\n" + + " public boolean retainAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "15. WARNING in DataSet.java (at line 30)\n" + + " public List subList(int fromIndex, int toIndex) { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=148783 - variation + public void test092() { + this.runNegativeTest( + new String[] { + "DataSet.java",//=================== + "import java.io.Serializable;\n" + + "import java.util.*;\n" + + "\n" + + "class DataSet implements List, Iterator, Serializable {\n" + + " \n" + + " public S[] toArray(S[] s) {\n" + + " return s;\n" + + " }\n" + + "\n" + + " public boolean add(Object o) { return false; }\n" + + " public void add(int index, Object element) {}\n" + + " public boolean addAll(Collection c) { return false; }\n" + + " public boolean addAll(int index, Collection c) { return false; }\n" + + " public void clear() {}\n" + + " public boolean contains(Object o) { return false; }\n" + + " public boolean containsAll(Collection c) { return false; }\n" + + " public Object get(int index) { return null; }\n" + + " public int indexOf(Object o) { return 0; }\n" + + " public boolean isEmpty() { return false; }\n" + + " public Iterator iterator() { return null; }\n" + + " public int lastIndexOf(Object o) { return 0; }\n" + + " public ListIterator listIterator() { return null; }\n" + + " public ListIterator listIterator(int index) { return null; }\n" + + " public boolean remove(Object o) { return false; }\n" + + " public Object remove(int index) { return null; }\n" + + " public boolean removeAll(Collection c) { return false; }\n" + + " public boolean retainAll(Collection c) { return false; }\n" + + " public Object set(int index, Object element) { return false; }\n" + + " public int size() { return 0; }\n" + + " public List subList(int fromIndex, int toIndex) { return null; }\n" + + " public Object[] toArray() { return null; }\n" + + " public boolean hasNext() { return false; }\n" + + " public Object next() { return null; }\n" + + " public void remove() {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^^^^\n" + + "The type DataSet must implement the inherited abstract method List.toArray(Object[])\n" + + "----------\n" + + "2. WARNING in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^^^^\n" + + "The serializable class DataSet does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^^^^^\n" + + "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + + "----------\n" + + "5. WARNING in DataSet.java (at line 12)\n" + + " public boolean addAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "6. WARNING in DataSet.java (at line 13)\n" + + " public boolean addAll(int index, Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "7. WARNING in DataSet.java (at line 16)\n" + + " public boolean containsAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "8. WARNING in DataSet.java (at line 20)\n" + + " public Iterator iterator() { return null; }\n" + + " ^^^^^^^^\n" + + "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + + "----------\n" + + "9. WARNING in DataSet.java (at line 22)\n" + + " public ListIterator listIterator() { return null; }\n" + + " ^^^^^^^^^^^^\n" + + "ListIterator is a raw type. References to generic type ListIterator should be parameterized\n" + + "----------\n" + + "10. WARNING in DataSet.java (at line 23)\n" + + " public ListIterator listIterator(int index) { return null; }\n" + + " ^^^^^^^^^^^^\n" + + "ListIterator is a raw type. References to generic type ListIterator should be parameterized\n" + + "----------\n" + + "11. WARNING in DataSet.java (at line 26)\n" + + " public boolean removeAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "12. WARNING in DataSet.java (at line 27)\n" + + " public boolean retainAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "13. WARNING in DataSet.java (at line 30)\n" + + " public List subList(int fromIndex, int toIndex) { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=148783 - variation + public void test093() { + this.runNegativeTest( + new String[] { + "DataSet.java",//=================== + "import java.io.Serializable;\n" + + "import java.util.*;\n" + + "\n" + + "class DataSet implements List, Iterator, Serializable {\n" + + " \n" + + " public S[] toArray(S[] s) {\n" + + " return s;\n" + + " }\n" + + " public Object[] toArray(Object[] o) {\n" + + " return o;\n" + + " }\n" + + " public boolean add(Object o) { return false; }\n" + + " public void add(int index, Object element) {}\n" + + " public boolean addAll(Collection c) { return false; }\n" + + " public boolean addAll(int index, Collection c) { return false; }\n" + + " public void clear() {}\n" + + " public boolean contains(Object o) { return false; }\n" + + " public boolean containsAll(Collection c) { return false; }\n" + + " public Object get(int index) { return null; }\n" + + " public int indexOf(Object o) { return 0; }\n" + + " public boolean isEmpty() { return false; }\n" + + " public Iterator iterator() { return null; }\n" + + " public int lastIndexOf(Object o) { return 0; }\n" + + " public ListIterator listIterator() { return null; }\n" + + " public ListIterator listIterator(int index) { return null; }\n" + + " public boolean remove(Object o) { return false; }\n" + + " public Object remove(int index) { return null; }\n" + + " public boolean removeAll(Collection c) { return false; }\n" + + " public boolean retainAll(Collection c) { return false; }\n" + + " public Object set(int index, Object element) { return false; }\n" + + " public int size() { return 0; }\n" + + " public List subList(int fromIndex, int toIndex) { return null; }\n" + + " public Object[] toArray() { return null; }\n" + + " public boolean hasNext() { return false; }\n" + + " public Object next() { return null; }\n" + + " public void remove() {}\n" + + "}\n", // ================= + }, + "----------\n" + + "1. ERROR in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^^^^\n" + + "The type DataSet must implement the inherited abstract method List.toArray(Object[])\n" + + "----------\n" + + "2. WARNING in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^^^^\n" + + "The serializable class DataSet does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in DataSet.java (at line 4)\n" + + " class DataSet implements List, Iterator, Serializable {\n" + + " ^^^^^^^^\n" + + "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + + "----------\n" + + "5. ERROR in DataSet.java (at line 6)\n" + + " public S[] toArray(S[] s) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method toArray(S[]) is the same as another method in type DataSet\n" + + "----------\n" + + "6. ERROR in DataSet.java (at line 6)\n" + + " public S[] toArray(S[] s) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method toArray(S[]) of type DataSet has the same erasure as toArray(Object[]) of type List but does not override it\n" + + "----------\n" + + "7. ERROR in DataSet.java (at line 6)\n" + + " public S[] toArray(S[] s) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method toArray(S[]) of type DataSet has the same erasure as toArray(Object[]) of type Collection but does not override it\n" + + "----------\n" + + "8. ERROR in DataSet.java (at line 9)\n" + + " public Object[] toArray(Object[] o) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method toArray(Object[]) is the same as another method in type DataSet\n" + + "----------\n" + + "9. WARNING in DataSet.java (at line 14)\n" + + " public boolean addAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "10. WARNING in DataSet.java (at line 15)\n" + + " public boolean addAll(int index, Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "11. WARNING in DataSet.java (at line 18)\n" + + " public boolean containsAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "12. WARNING in DataSet.java (at line 22)\n" + + " public Iterator iterator() { return null; }\n" + + " ^^^^^^^^\n" + + "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + + "----------\n" + + "13. WARNING in DataSet.java (at line 24)\n" + + " public ListIterator listIterator() { return null; }\n" + + " ^^^^^^^^^^^^\n" + + "ListIterator is a raw type. References to generic type ListIterator should be parameterized\n" + + "----------\n" + + "14. WARNING in DataSet.java (at line 25)\n" + + " public ListIterator listIterator(int index) { return null; }\n" + + " ^^^^^^^^^^^^\n" + + "ListIterator is a raw type. References to generic type ListIterator should be parameterized\n" + + "----------\n" + + "15. WARNING in DataSet.java (at line 28)\n" + + " public boolean removeAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "16. WARNING in DataSet.java (at line 29)\n" + + " public boolean retainAll(Collection c) { return false; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "17. WARNING in DataSet.java (at line 32)\n" + + " public List subList(int fromIndex, int toIndex) { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + ); + } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=146383 +public void test094() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.JavacCompilesIncorrectSource, + new String[] { + "X.java",//=================== + "import java.util.ArrayList;\n" + + "import java.util.Arrays;\n" + + "class Y {}\n" + + "public class X\n" + + "{\n" + + " private static ArrayList> y = new ArrayList>();\n" + + " void foo(Y[] array)\n" + + " {\n" + + " y.addAll(Arrays.asList(array));\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " void foo(Y[] array)\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " y.addAll(Arrays.asList(array));\n" + + " ^^^^^^\n" + + "The method addAll(Collection>) in the type ArrayList> is not applicable for the arguments (List)\n" + + "----------\n" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148957 +public void test096() { + this.runNegativeTest( + new String[] { + "ProblemClass.java",//=================== + "import java.util.Collection;\n" + + "import javax.swing.JLabel;\n" + + "interface SuperInterface {\n" + + " public void doIt(Collection as);\n" + + "}\n" + + "\n" + + "public class ProblemClass implements SuperInterface {\n" + + " public void doIt(Collection as) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in ProblemClass.java (at line 7)\n" + + " public class ProblemClass implements SuperInterface {\n" + + " ^^^^^^^^^^^^\n" + + "The type ProblemClass must implement the inherited abstract method SuperInterface.doIt(Collection)\n" + + "----------\n" + + "2. ERROR in ProblemClass.java (at line 8)\n" + + " public void doIt(Collection as) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method doIt(Collection) of type ProblemClass has the same erasure as doIt(Collection) of type SuperInterface but does not override it\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=148957 - variation +public void test097() { + this.runConformTest( + new String[] { + "ProblemClass.java",//=================== + "import java.util.Collection;\n" + + "import javax.swing.JLabel;\n" + + "interface SuperInterface {\n" + + " public void doIt(Collection as);\n" + + "}\n" + + "\n" + + "public class ProblemClass implements SuperInterface {\n" + + " public void doIt(Collection as) {\n" + + " }\n" + + "}\n" + }, + "" + ); +} + +// autoboxing mixed with type parameters substitution +public void test098() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public X(List toAdd) {\n" + + " }\n" + + " public , LF extends Factory> L \n" + + " foo(B b, L l, LF lf) {\n" + + " return l;\n" + + " }\n" + + " public static class ListFactory implements Factory> {\n" + + " public List create() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public static interface Factory {\n" + + " public T create();\n" + + " }\n" + + " public static void bar() {\n" + + " (new X(new ArrayList())).\n" + + " foo(1, (List) null, new ListFactory());\n" + + " }\n" + + "}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=153874 +public void test099() { + Map customOptions= getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4); + this.runConformTest( + new String[] { + "TestCharset.java", + "import java.nio.charset.*;\n" + + "public class TestCharset extends Charset {\n" + + " protected TestCharset(String n, String[] a) { super(n, a); }\n" + + " public boolean contains(Charset cs) { return false; }\n" + + " public CharsetDecoder newDecoder() { return null; }\n" + + " public CharsetEncoder newEncoder() { return null; }\n" + + "}\n" , + }, + "", + null, + true, + null, + customOptions, + null/*no custom requestor*/); +} + +// name conflict +public void test100() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "public class X {\n" + + " boolean removeAll(Collection c) {\n" + + " return false;\n" + + " }\n" + + "}\n", + "Y.java", + "import java.util.Collection;\n" + + "public class Y extends X\n" + + "{\n" + + " boolean removeAll(Collection c) {\n" + + " return false;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Y.java (at line 4)\n" + + " boolean removeAll(Collection c) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method removeAll(Collection) of type Y has the same erasure as removeAll(Collection) of type X but does not override it\n" + + "----------\n" + ); +} + +// name conflict +public void test101() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Integer getX(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method getX(List) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " String getX(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method getX(List) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " Integer getX(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method getX(List) in type Y\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " String getX(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method getX(List) in type Y\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Integer getX(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method getX(List) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " String getX(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method getX(List) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " Integer getX(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method getX(List) in type Y\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " String getX(List l) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method getX(List) in type Y\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " Integer getX(List l) {\n" + + " return null;\n" + + " }\n" + + " String getX(List l) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " Integer getX(List l) {\n" + + " return null;\n" + + " }\n" + + " String getX(List l) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + expectedCompilerLog + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test102() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnLeaf extends ReturnDerived {\n" + + " }\n" + + "\n" + + " private interface Interface {\n" + + " ReturnBase bar();\n" + + " }\n" + + "\n" + + " private static class Implementation {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation implements Interface {\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child implements Interface {\n" + + " @Override\n" + + " public ReturnLeaf bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 26)\n" + + " public ReturnLeaf bar() {\n" + + " ^^^^^\n" + + "Cannot override the final method from X.Implementation\n" + + "----------\n", + null, + true, + options + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test103() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private interface Interface {\n" + + " ReturnBase bar();\n" + + " }\n" + + "\n" + + " private static class Implementation {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child implements Interface {\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation implements Interface {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); + File fileX = new File(OUTPUT_DIR + File.separator +"X$Child.class"); + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + IMethodInfo[] methodInfos = reader.getMethodInfos(); + boolean found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertTrue("bar should be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Grandchild.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test104() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private interface Interface {\n" + + " ReturnBase bar();\n" + + " }\n" + + "\n" + + " private static class Implementation {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation implements Interface {\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child implements Interface {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); + File fileX = new File(OUTPUT_DIR + File.separator +"X$Child.class"); + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + IMethodInfo[] methodInfos = reader.getMethodInfos(); + boolean found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertTrue("bar should be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Grandchild.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test105() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private static class Super {\n" + + " ReturnBase bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Implementation extends Super {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation {\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); + File fileX = new File(OUTPUT_DIR + File.separator +"X$Child.class"); + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + IMethodInfo[] methodInfos = reader.getMethodInfos(); + boolean found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Grandchild.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Implementation.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + int count = 0; + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if (new String(methodInfo.getName()).equals("bar")) { + count++; + if (Flags.isBridge(methodInfo.getAccessFlags())) { + found = true; + } + } + } + assertEquals("Should have two method bar", 2, count); + assertTrue("should have one bridge method", found); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test106() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private static class Super {\n" + + " ReturnBase bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static abstract class Implementation extends Super {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation {\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); + File fileX = new File(OUTPUT_DIR + File.separator +"X$Child.class"); + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + IMethodInfo[] methodInfos = reader.getMethodInfos(); + boolean found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Grandchild.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Implementation.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + int count = 0; + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if (new String(methodInfo.getName()).equals("bar")) { + count ++; + if (Flags.isBridge(methodInfo.getAccessFlags())) { + found = true; + } + } + } + assertEquals("should have two methods bar", 2, count); + assertTrue("should have one bridge method", found); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test107() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private interface Interface {\n" + + " ReturnBase bar();\n" + + " }\n" + + "\n" + + " private static class Implementation {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation implements Interface {\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child implements Interface {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); + File fileX = new File(OUTPUT_DIR + File.separator +"X$Child.class"); + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + IMethodInfo[] methodInfos = reader.getMethodInfos(); + boolean found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertTrue("bar should be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Grandchild.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test108() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnLeaf extends ReturnDerived {\n" + + " }\n" + + "\n" + + " private interface Interface {\n" + + " ReturnBase bar();\n" + + " }\n" + + "\n" + + " private static class Implementation {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation implements Interface {\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child implements Interface {\n" + + " @Override\n" + + " public ReturnLeaf bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 26)\n" + + " public ReturnLeaf bar() {\n" + + " ^^^^^\n" + + "Cannot override the final method from X.Implementation\n" + + "----------\n", + null, + true, + options + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test109() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private interface Interface {\n" + + " ReturnBase bar();\n" + + " }\n" + + "\n" + + " private static class Implementation {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child implements Interface {\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation implements Interface {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); + File fileX = new File(OUTPUT_DIR + File.separator +"X$Child.class"); + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + IMethodInfo[] methodInfos = reader.getMethodInfos(); + boolean found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertTrue("bar should be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Grandchild.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test110() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private interface Interface {\n" + + " ReturnBase bar();\n" + + " }\n" + + "\n" + + " private static class Implementation {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation implements Interface {\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child implements Interface {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); + File fileX = new File(OUTPUT_DIR + File.separator +"X$Child.class"); + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + IMethodInfo[] methodInfos = reader.getMethodInfos(); + boolean found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertTrue("bar should be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Grandchild.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test111() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private static class Super {\n" + + " ReturnBase bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Implementation extends Super {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation {\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); + File fileX = new File(OUTPUT_DIR + File.separator +"X$Child.class"); + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + IMethodInfo[] methodInfos = reader.getMethodInfos(); + boolean found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Grandchild.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Implementation.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + int count = 0; + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if (new String(methodInfo.getName()).equals("bar")) { + count++; + if (Flags.isBridge(methodInfo.getAccessFlags())) { + found = true; + } + } + } + assertEquals("should have two methods bar", 2, count); + assertTrue("should have one bridge method", found); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973 +public void test112() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private interface ReturnBase {\n" + + " }\n" + + "\n" + + " private interface ReturnDerived extends ReturnBase {\n" + + " }\n" + + "\n" + + " private static class Super {\n" + + " ReturnBase bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static abstract class Implementation extends Super {\n" + + " public final ReturnDerived bar() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " private static class Child extends Implementation {\n" + + " }\n" + + "\n" + + " private static class Grandchild extends Child {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new Grandchild();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); + File fileX = new File(OUTPUT_DIR + File.separator +"X$Child.class"); + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + IMethodInfo[] methodInfos = reader.getMethodInfos(); + boolean found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Grandchild.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + if (new String(methodInfos[i].getName()).equals("bar")) { + found = true; + break; + } + } + assertFalse("bar should not be there", found); + + fileX = new File(OUTPUT_DIR + File.separator +"X$Implementation.class"); + reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES); + methodInfos = reader.getMethodInfos(); + int count = 0; + found = false; + for (int i = 0, max = methodInfos.length; i < max; i++) { + IMethodInfo methodInfo = methodInfos[i]; + if (new String(methodInfo.getName()).equals("bar")) { + count++; + if (Flags.isBridge(methodInfo.getAccessFlags())) { + found = true; + } + } + } + assertEquals("should have two methods bar", 2, count); + assertTrue("should have one bridge method", found); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156736 +public void test113() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperInvocation, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "abstract class Y {\n" + + " abstract void foo();\n" + + "}\n" + + "public class X extends Y {\n" + + " void foo() {\n" + + " // should not complain for missing super call, since overriding \n" + + " // abstract method\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156736 +public void test114() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperInvocation, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class Y {\n" + + " void foo() {}\n" + + "}\n" + + "public class X extends Y {\n" + + " @Override\n" + + " void foo() {\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method X.foo() is overriding a method without making a super invocation\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156736 +public void test115() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperInvocation, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "class Y {\n" + + " void foo() {}\n" + + "}\n" + + "public class X extends Y {\n" + + " @Override\n" + + " void foo() {\n" + + " super.foo();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156736 +public void test116() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperInvocation, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " Zork foo() {}\n" + + "}\n" + + "public class X extends Y {\n" + + " @Override\n" + + " Object foo() {\n" + + " return new Y() {\n" + + " Object foo() {\n" + + " return null;\n" + + " }\n" + + " };" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Zork foo() {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Object foo() {\n" + + " ^^^^^^\n" + + "The return type is incompatible with Y.foo()\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " Object foo() {\n" + + " ^^^^^\n" + + "The method X.foo() is overriding a method without making a super invocation\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " Object foo() {\n" + + " ^^^^^^\n" + + "The return type is incompatible with Y.foo()\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " Object foo() {\n" + + " ^^^^^\n" + + "The method foo() of type new Y(){} should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " Object foo() {\n" + + " ^^^^^\n" + + "The method new Y(){}.foo() is overriding a method without making a super invocation\n" + + "----------\n", + null, + true, + options ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156736 +public void test117() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperInvocation, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class Y {\n" + + " Object foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " @Override\n" + + " Object foo() {\n" + + " return new Y() {\n" + + " @Override\n" + + " Object foo() {\n" + + " return null;\n" + + " }\n" + + " };" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 8)\n" + + " Object foo() {\n" + + " ^^^^^\n" + + "The method X.foo() is overriding a method without making a super invocation\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " Object foo() {\n" + + " ^^^^^\n" + + "The method new Y(){}.foo() is overriding a method without making a super invocation\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156736 +public void test118() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperInvocation, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class Y {\n" + + " U foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends Y {\n" + + " @Override\n" + + " V foo() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 9)\n" + + " V foo() {\n" + + " ^^^^^\n" + + "The method X.foo() is overriding a method without making a super invocation\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156736 +public void test119() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperInvocation, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "class Y {\n" + + " E foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X extends Y {\n" + + " @Override\n" + + " T foo() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + options /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 9)\n" + + " T foo() {\n" + + " ^^^^^\n" + + "The method X.foo() is overriding a method without making a super invocation\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=161541 +public void test120() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " abstract class M {\n" + + " void e(T t) {}\n" + + " void e(S s) {}\n" + + " }\n" + + " class N extends M {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " class N extends M {}\n" + + " ^\n" + + "Duplicate methods named e with the parameters (S) and (T) are defined by the type X.M\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=202830 +public void test120a() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in Bar.java (at line 2)\n" + + " int getThing(V v) { return 1; }\n" + + " ^^^^^^^^^^^^^\n" + + "Erasure of method getThing(V) is the same as another method in type Foo\n" + + "----------\n" + + "2. WARNING in Bar.java (at line 3)\n" + + " boolean getThing(E e) { return true; }\n" + + " ^^^^^^^^^^^^^\n" + + "Erasure of method getThing(E) is the same as another method in type Foo\n" + + "----------\n": + "----------\n" + + "1. ERROR in Bar.java (at line 2)\n" + + " int getThing(V v) { return 1; }\n" + + " ^^^^^^^^^^^^^\n" + + "Erasure of method getThing(V) is the same as another method in type Foo\n" + + "----------\n" + + "2. ERROR in Bar.java (at line 3)\n" + + " boolean getThing(E e) { return true; }\n" + + " ^^^^^^^^^^^^^\n" + + "Erasure of method getThing(E) is the same as another method in type Foo\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "Bar.java", + "class Foo {\n" + + " int getThing(V v) { return 1; }\n" + + " boolean getThing(E e) { return true; }\n" + + "}\n" + + "public class Bar extends Foo {}" + }, + expectedCompilerLog + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=173477 +public void test121() { + this.runConformTest( + new String[] { + "X.java", + "interface Root {\n" + + " public Root someMethod();\n" + + "}\n" + + "\n" + + "interface Intermediary extends Root {\n" + + " public Leaf someMethod();\n" + + "}\n" + + "\n" + + "class Leaf implements Intermediary {\n" + + " public Leaf someMethod() {\n" + + " System.out.print(\"SUCCESS\");\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Leaf leafReference = new Leaf();\n" + + " leafReference.someMethod();\n" + + " Root rootReference = leafReference;\n" + + " rootReference.someMethod(); /* throws error */\n" + + " }\n" + + "}" + }, + "SUCCESSSUCCESS" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175987 +public void test122() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " public void foo(Integer i, Y l1, Y l2);\n" + + "}\n" + + "public class X implements I {\n" + + " public void foo(Integer i, Y l1, Y l2) {\n" + + " }\n" + + "}\n" + + "class Y {\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X implements I {\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.foo(Integer, Y, Y)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public void foo(Integer i, Y l1, Y l2) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Integer, Y, Y) of type X has the same erasure as foo(Integer, Y, Y) of type I but does not override it\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " public void foo(Integer i, Y l1, Y l2) {\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=175987 +// variant that must pass because X#foo's signature is a subsignature of +// I#foo's. +public void test123() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " public void foo(Integer i, Y l1, Y l2);\n" + + "}\n" + + "public class X implements I {\n" + + " public void foo(Integer i, Y l1, Y l2) {\n" + + " }\n" + + "}\n" + + "class Y {\n" + + "}"}, + "" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150655 +// ** +public void test124() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String choose(String one, String two) {\n" + + " return one + X.choose(one, two);\n" + + " }\n" + + " public static T choose(T one, T two) {\n" + + " return two;\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " try {\n" + + " System.out.println(choose(\"a\", \"b\"));\n" + + " } catch (StackOverflowError e) {\n" + + " System.out.println(\"Stack Overflow\");\n" + + " }\n" + + " }\n" + + "}"}, + this.complianceLevel <= ClassFileConstants.JDK1_6 ? "ab" : "Stack Overflow"); +} +// Bug 460993: [compiler] Incremental build not always reports the same errors (type cannot be resolved - indirectly referenced) +public void test124b() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public Object o = \"\";\n" + + " public static void main(String args[]) {\n" + + " X.main(args);\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " public static String choose(String one, String two) {\n" + + " return one + X.choose(one, two);\n" + + " }\n" + + " public static T choose(T one, T two) {\n" + + " return two;\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " try {\n" + + " System.out.println(choose(\"a\", \"b\"));\n" + + " } catch (StackOverflowError e) {\n" + + " System.out.println(\"Stack Overflow\");\n" + + " }\n" + + " }\n" + + "}"}, + this.complianceLevel <= ClassFileConstants.JDK1_6 ? "ab" : "Stack Overflow"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150655 +// variant +public void test125() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String choose(String one, String two) {\n" + + " return one;\n" + + " }\n" + + " public static T choose(T one, T two) {\n" + + " return two;\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " System.out.println(choose(\"a\", \"b\") + X.choose(\"a\", \"b\"));\n" + + " }\n" + + "}" + }, + "aa" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150655 +// variant +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176171 +// deprecated by GenericTypeTest#test1203. +//public void _test126() { +// this.runNegativeTest( +// new String[] { +// "X.java", +// "public class X extends Y {\n" + +// " public static String foo(String one, String two) {\n" + // complain +// " return X.foo(one, two);\n" + +// " }\n" + +// " public String bar(String one, String two) {\n" + // complain +// " return this.bar(one, two);\n" + +// " }\n" + +// " @Override\n" + +// " public String foobar(String one, String two) {\n" + // OK +// " return this.foobar(one, two);\n" + +// " }\n" + +// "}\n" + +// "class Y {\n" + +// " public String foobar(String one, String two) {\n" + +// " return null;\n" + +// " }\n" + +// "}\n"}, +// "----------\n" + +// "1. ERROR in X.java (at line 3)\n" + +// " return X.foo(one, two);\n" + +// " ^^^\n" + +// "The method foo(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + +// "----------\n" + +// "2. ERROR in X.java (at line 6)\n" + +// " return this.bar(one, two);\n" + +// " ^^^\n" + +// "The method bar(String, String) of type X is not generic; it cannot be parameterized with arguments \n" + +// "----------\n"); +//} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=174445 +public void test127() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Enum1 {\n" + + " value;\n" + + " }\n" + + " enum Enum2 {\n" + + " value;\n" + + " }\n" + + " static abstract class A {\n" + + " abstract U foo();\n" + + " }\n" + + " static class B extends A> {\n" + + " @Override\n" + + " Enum foo() {\n" + + " return Enum1.value;\n" + + " } \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " A> a = new B();\n" + + " Enum2 value = a.foo();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " Enum foo() {\n" + + " ^^^^\n" + + "Type safety: The return type Enum for foo() from the type X.B needs unchecked conversion to conform to U from the type X.A\n" + + "----------\n", + null, + true, + null, + "java.lang.ClassCastException"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 +public void test128() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " U foo(Object o, V v);\n" + + "}\n" + + "public class X implements I {\n" + + " public Object foo(Object o, Object v) { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public Object foo(Object o, Object v) { return null; }\n" + + " ^^^^^^\n" + + "Type safety: The return type Object for foo(Object, Object) from the type X needs unchecked conversion to conform to U from the type I\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 +// variant - Object is not a subtype of Z +public void test129() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " U foo(Object o, V v);\n" + + "}\n" + + "public class X implements I {\n" + + " public Object foo(Object o, Object v) { return null; }\n" + + "}\n" + + "class Z {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public Object foo(Object o, Object v) { return null; }\n" + + " ^^^^^^\n" + + "The return type is incompatible with I.foo(Object, V)\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 +// variant - Z is not a subtype of Z, and |Z| = Z, not Z +public void test130() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Z foo(Object o, V v);\n" + + "}\n" + + "public class X implements I {\n" + + " public Z foo(Object o, Object v) { return null; }\n" + + "}\n" + + "class Z {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public Z foo(Object o, Object v) { return null; }\n" + + " ^^^^^^^^^\n" + + "The return type is incompatible with I.foo(Object, V)\n" + + "----------\n", + JavacTestOptions.EclipseJustification.EclipseBug180789 + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 +// variant - two interfaces +public void test131() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " U foo();\n" + + " U foo(Object o, V v);\n" + + "}\n" + + "interface X extends I {\n" + + " Object foo();\n" + + " Object foo(Object o, Object v);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Object foo();\n" + + " ^^^^^^\n" + + "The return type is incompatible with I.foo()\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " Object foo(Object o, Object v);\n" + + " ^^^^^^\n" + + "Type safety: The return type Object for foo(Object, Object) from the type X needs unchecked conversion to conform to U from the type I\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 +// variant - type identity vs type equivalence +public void test132() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " U foo(I p);\n" + + " U foo2(I p);\n" + + "}\n" + + "public class X implements I {\n" + + " public Object foo(I p) { return null; }\n" + + " public Object foo2(I p) { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public Object foo(I p) { return null; }\n" + + " ^^^^^^\n" + + "The return type is incompatible with I.foo(I)\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public Object foo2(I p) { return null; }\n" + + " ^^^^^^\n" + + "The return type is incompatible with I.foo2(I)\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 +// variant - if we detect a return type incompatibility, then skip any @Override errors +public void test133() { + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " U foo() { return null; }\n" + + " U foo(U one) { return null; }\n" + + " U foo(U one, U two) { return null; }\n" + + "}\n" + + "class B extends A {\n" + + " @Override // does not override error\n" + + " Object foo() { return null; } // cannot override foo(), incompatible return type error\n" + + " @Override // does not override error\n" + + " Object foo(Object one) { return null; } // unchecked conversion warning\n" + + " @Override // does not override error\n" + + " Object foo(Object one, U two) { return null; }\n" + + "}\n" + + "class C extends A {\n" + + " @Override // does not override error\n" + + " Object foo(U one) { return null; } // cannot override foo(U), incompatible return type error\n" + + " @Override // does not override error\n" + + " Object foo(U one, U two) { return null; } // cannot override foo(U), incompatible return type error\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 8)\n" + + " Object foo() { return null; } // cannot override foo(), incompatible return type error\n" + + " ^^^^^^\n" + + "The return type is incompatible with A.foo()\n" + + "----------\n" + + "2. WARNING in A.java (at line 10)\n" + + " Object foo(Object one) { return null; } // unchecked conversion warning\n" + + " ^^^^^^\n" + + "Type safety: The return type Object for foo(Object) from the type B needs unchecked conversion to conform to U from the type A\n" + + "----------\n" + + "3. ERROR in A.java (at line 12)\n" + + " Object foo(Object one, U two) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Object, U) of type B has the same erasure as foo(U, U) of type A but does not override it\n" + + "----------\n" + + "4. ERROR in A.java (at line 12)\n" + + " Object foo(Object one, U two) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + mustOverrideMessage("foo(Object, U)", "B") + + "----------\n" + + "5. ERROR in A.java (at line 16)\n" + + " Object foo(U one) { return null; } // cannot override foo(U), incompatible return type error\n" + + " ^^^^^^\n" + + "The return type is incompatible with A.foo(U)\n" + + "----------\n" + + "6. ERROR in A.java (at line 18)\n" + + " Object foo(U one, U two) { return null; } // cannot override foo(U), incompatible return type error\n" + + " ^^^^^^\n" + + "The return type is incompatible with A.foo(U, U)\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184293 +public void test134() { + this.runNegativeTest( + new String[] { + "A.java", + "interface I {\n" + + " T foo(Number n);\n" + + "}\n" + + "interface J extends I {\n" + + " A foo(Number n);\n" + // warning: overrides foo(java.lang.Number) in I; return type requires unchecked conversion + "}\n" + + "abstract class A extends Exception implements Cloneable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "----------\n" + + "1. WARNING in A.java (at line 5)\n" + + " A foo(Number n);\n" + + " ^\n" + + "Type safety: The return type A for foo(Number) from the type J needs unchecked conversion to conform to T from the type I\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184293 +public void test135() { + this.runNegativeTest( + new String[] { + "X.java", + "abstract class X implements J {}\n" + + "class X2 implements J {\n" + + " public A foo(Number n) { return null; }\n" + + "}\n" + + "abstract class Y extends X {}\n" + + "interface I {\n" + + " T foo(Number n);\n" + + "}\n" + + "interface J extends I {\n" + + " A foo(Number n);\n" + // warning: overrides foo(java.lang.Number) in I; return type requires unchecked conversion + "}\n" + + "abstract class A extends Exception implements Cloneable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public A foo(Number n) { return null; }\n" + + " ^\n" + + "Type safety: The return type A for foo(Number) from the type X2 needs unchecked conversion to conform to T from the type I\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " A foo(Number n);\n" + + " ^\n" + + "Type safety: The return type A for foo(Number) from the type J needs unchecked conversion to conform to T from the type I\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184293 +public void test136() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X extends E {}\n" + + "class X2 extends E {\n" + + " @Override public A foo(Number n) { return null; }\n" + + "}\n" + + "abstract class Y extends X {}\n" + + "abstract class D {\n" + + " abstract T foo(Number n);\n" + + "}\n" + + "abstract class E extends D {\n" + + " @Override abstract A foo(Number n);\n" + // warning: overrides foo(java.lang.Number) in I; return type requires unchecked conversion + "}\n" + + "abstract class A extends Exception implements Cloneable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " @Override abstract A foo(Number n);\n" + + " ^\n" + + "Type safety: The return type A for foo(Number) from the type E needs unchecked conversion to conform to T from the type D\n" + + "----------\n" + // javac reports warnings against X AND Y about E.foo(), as well as reporting the warning on E.foo() twice + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184293 +public void test137() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X implements J {}\n" + + "interface I {\n" + + " & Cloneable> T foo(Number n);\n" + + "}\n" + + "interface J extends I {\n" + + " XX foo(Number n);\n" + + "}\n" + + "class Z { }\n" + + "class Y extends Z { }\n" + + "abstract class XX extends Y implements Cloneable {}" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " XX foo(Number n);\n" + + " ^^\n" + + "Type safety: The return type XX for foo(Number) from the type J needs unchecked conversion to conform to T from the type I\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184293 +public void test138() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X implements J {}\n" + + "interface I {\n" + + " A foo(Number n);\n" + + "}\n" + + "interface J extends I {\n" + + " A foo(Number n);\n" + + "}\n" + + "class A { }" + + "abstract class XX extends Exception implements Cloneable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " A foo(Number n);\n" + + " ^\n" + + "Type safety: The return type A for foo(Number) from the type J needs unchecked conversion to conform to A from the type I\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184293 +public void test139() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X implements J {\n" + + " void foo() {}\n" + + " public XX foo(Number n) { return null; }\n" + + "}\n" + + "interface I {\n" + + " T foo(Number n);\n" + + "}\n" + + "interface J extends I {\n" + + " XX foo(Number n);\n" + + "}\n" + + "abstract class XX extends Exception implements Cloneable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public XX foo(Number n) { return null; }\n" + + " ^^\n" + + "Type safety: The return type XX for foo(Number) from the type X needs unchecked conversion to conform to T from the type I\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " XX foo(Number n);\n" + + " ^^\n" + + "Type safety: The return type XX for foo(Number) from the type J needs unchecked conversion to conform to T from the type I\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=162073 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184293 +public void test140() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X implements J, K {}\n" + + "interface I {\n" + + " T foo(Number n);\n" + + "}\n" + + "interface J extends I {\n" + + " XX foo(Number n);\n" + + "}\n" + + "interface K {\n" + + " NullPointerException foo(Number n);\n" + + "}\n" + + "abstract class XX extends Exception implements Cloneable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public abstract class X implements J, K {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods J.foo(Number), K.foo(Number)\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " XX foo(Number n);\n" + + " ^^\n" + + "Type safety: The return type XX for foo(Number) from the type J needs unchecked conversion to conform to T from the type I\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=186457 +public void test141() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.nio.charset.Charset;\n" + + "import java.nio.charset.CharsetDecoder;\n" + + "import java.nio.charset.CharsetEncoder;\n" + + "public class X extends Charset {\n" + + " public X(String name, String[] aliases) { super(name, aliases); }\n" + + " @Override public CharsetEncoder newEncoder() { return null; }\n" + + " @Override public CharsetDecoder newDecoder() { return null; }\n" + + " @Override public boolean contains(Charset x) { return false; }\n" + + " public int compareTo(Object obj) {\n" + + " return compareTo((Charset) obj);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " public int compareTo(Object obj) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method compareTo(Object) of type X has the same erasure as compareTo(T) of type Comparable but does not override it\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=186457 +public void test142() { + this.runConformTest( + new String[] { + "X.java", + "import java.nio.charset.Charset;\n" + + "import java.nio.charset.CharsetDecoder;\n" + + "import java.nio.charset.CharsetEncoder;\n" + + "public class X extends Charset {\n" + + " public X(String name, String[] aliases) { super(name, aliases); }\n" + + " public CharsetEncoder newEncoder() { return null; }\n" + + " public CharsetDecoder newDecoder() { return null; }\n" + + " public boolean contains(Charset x) { return false; }\n" + + "}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190748 +public void test143() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) { ((IBase) new Impl()).get(); }\n" + + "}\n" + + "class Impl extends AImpl implements IBase, IEnhanced {}\n" + + "interface IBase {\n" + + " IBaseReturn get();\n" + + "}\n" + + "interface IEnhanced extends IBase {\n" + + " IEnhancedReturn get();\n" + + "}\n" + + "abstract class AImpl {\n" + + " public IEnhancedReturn get() { return null; }\n" + + "}\n" + + "interface IBaseReturn {}\n" + + "interface IEnhancedReturn extends IBaseReturn {}" + }, + ""); +} +//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[] { + "PurebredCatShopImpl.java", + "import java.util.List;\n" + + "interface Pet {}\n" + + "interface Cat extends Pet {}\n" + + "interface PetShop { List getPets(); }\n" + + "interface CatShop extends PetShop {\n" + + " List getPets();\n" + + "}\n" + + "interface PurebredCatShop extends CatShop {}\n" + + "class CatShopImpl implements CatShop {\n" + + " public List getPets() { return null; }\n" + + "}\n" + + "class PurebredCatShopImpl extends CatShopImpl implements PurebredCatShop {}" + }, + "----------\n" + + "1. ERROR in PurebredCatShopImpl.java (at line 6)\n" + + " List 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 getPets() { return null; }\n" + + " ^^^^\n" + + "Type safety: The return type List for getPets() from the type CatShopImpl needs unchecked conversion to conform to List from the type CatShop\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=195468 +public void test145() { + this.runConformTest( + new String[] { + "BaseImpl.java", + "abstract class Base implements BaseInterface{ public void setValue(Object object) {} }\n" + + "interface BaseInterface { void setValue(Tvalue object); }\n" + + "class BaseImpl extends Base { public void setValue(String object) {} }" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=195802 +public void test146() { + this.runConformTest( + new String[] { + "BugB.java", + "abstract class A { void get(K key) {} }\n" + + "abstract class B extends A { void get(C type) {} }\n" + + "class B2 extends A { void get(C type) {} }\n" + + "class BugB extends B {}\n" + + "class NonBugB extends B2 {}\n" + + "class C {}" + }, + "" + ); +} +public void test147() { + this.runNegativeTest( + new String[] { + "X.java", + "interface J { void foo(T t); }\n" + + "class Y { public void foo(T t) {} }\n" + + "abstract class X extends Y implements J {\n" + + " @Override public void foo(Object o) {}\n" + + "}\n" + + "abstract class X1 extends Y implements J {\n" + + " public void foo(Object o) {}\n" + + "}\n" + + "abstract class X2 extends Y implements J {}\n" + + "abstract class X3 extends Y implements J {}\n" + + "abstract class X4 extends Y implements J {\n" + + " @Override public void foo(Number o) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " abstract class X1 extends Y implements J {\n" + + " ^^\n" + + "Name clash: The method foo(T) of type Y has the same erasure as foo(T) of type J but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public void foo(Object o) {}\n" + + " ^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Object) of type X1 has the same erasure as foo(T) of type Y but does not override it\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " public void foo(Object o) {}\n" + + " ^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Object) of type X1 has the same erasure as foo(T) of type J but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " abstract class X2 extends Y implements J {}\n" + + " ^^\n" + + "Name clash: The method foo(T) of type Y has the same erasure as foo(T) of type J but does not override it\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " abstract class X3 extends Y implements J {}\n" + + " ^^\n" + + "Name clash: The method foo(T) of type Y has the same erasure as foo(T) of type J but does not override it\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " abstract class X4 extends Y implements J {\n" + + " ^^\n" + + "Name clash: The method foo(T) of type Y has the same erasure as foo(T) of type J but does not override it\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204624 +public void test148() { + this.runNegativeTest( + new String[] { + "Y.java", + "abstract class X { abstract T go(A a); }\n" + + "class Y extends X {\n" + + " @Override T go(A a) { return null; }\n" + + "}\n" + + "class A {}" + }, + "----------\n" + + "1. ERROR in Y.java (at line 2)\n" + + " class Y extends X {\n" + + " ^\n" + + "The type Y must implement the inherited abstract method X.go(A)\n" + + "----------\n" + + "2. ERROR in Y.java (at line 3)\n" + + " @Override T go(A a) { return null; }\n" + + " ^^^^^^^\n" + + "Name clash: The method go(A) of type Y has the same erasure as go(A) of type X but does not override it\n" + + "----------\n" + + "3. ERROR in Y.java (at line 3)\n" + + " @Override T go(A a) { return null; }\n" + + " ^^^^^^^\n" + + mustOverrideMessage("go(A)", "Y") + + "----------\n" + + "4. WARNING in Y.java (at line 3)\n" + + " @Override T go(A a) { return null; }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208995 +public void test149() { + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " void a(X x) {}\n" + + " void b(Y y) {}\n" + + " static void c(X x) {}\n" + + " static void d(Y y) {}\n" + + "}\n", + "B.java", + "class B extends A {\n" + + " static void a(X x) {}\n" + // cannot override a(X) in A; overriding method is static + " static void b(Y y) {}\n" + // name clash + " static void c(X x) {}\n" + + " static void d(Y y) {}\n" + + "}\n", + "B2.java", + "class B2 extends A {\n" + + " static void b(Y y) {}\n" + // cannot override b(Y) in A; overriding method is static + " static void d(Y y) {}\n" + + "}\n", + "C.java", + "class C extends A {\n" + + " @Override void a(X x) {}\n" + + " void b(Y y) {}\n" + // name clash + " void c(X x) {}\n" + // cannot override c(X) in A; overridden method is static + " void d(Y y) {}\n" + + "}\n", + "C2.java", + "class C2 extends A {\n" + + " @Override void b(Y y) {}\n" + + " void d(Y y) {}\n" + // cannot override b(Y) in A; overridden method is static + "}\n" + + "class X {}\n" + + "class Y {}" + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in B.java (at line 2)\n" + + " static void a(X x) {}\n" + + " ^^^^^^\n" + + "This static method cannot hide the instance method from A\n" + + "----------\n" + + "----------\n" + + "1. ERROR in B2.java (at line 2)\n" + + " static void b(Y y) {}\n" + + " ^^^^^^^^^^^^^^^\n" + + "This static method cannot hide the instance method from A\n" + + "----------\n" + + "----------\n" + + "1. ERROR in C.java (at line 3)\n" + + " void b(Y y) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method b(Y) of type C has the same erasure as b(Y) of type A but does not override it\n" + + "----------\n" + + "2. ERROR in C.java (at line 4)\n" + + " void c(X x) {}\n" + + " ^^^^^^\n" + + "This instance method cannot override the static method from A\n" + + "----------\n" + + "----------\n" + + "1. ERROR in C2.java (at line 3)\n" + + " void d(Y y) {}\n" + + " ^^^^^^^^^^^^^^^\n" + + "This instance method cannot override the static method from A\n" + + "----------\n" : + "----------\n" + + "1. ERROR in B.java (at line 2)\n" + + " static void a(X x) {}\n" + + " ^^^^^^\n" + + "This static method cannot hide the instance method from A\n" + + "----------\n" + + "2. ERROR in B.java (at line 3)\n" + + " static void b(Y y) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method b(Y) of type B has the same erasure as b(Y) of type A but does not hide it\n" + + "----------\n" + + "3. ERROR in B.java (at line 5)\n" + + " static void d(Y y) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method d(Y) of type B has the same erasure as d(Y) of type A but does not hide it\n" + + "----------\n" + + "----------\n" + + "1. ERROR in B2.java (at line 2)\n" + + " static void b(Y y) {}\n" + + " ^^^^^^^^^^^^^^^\n" + + "This static method cannot hide the instance method from A\n" + + "----------\n" + + "----------\n" + + "1. ERROR in C.java (at line 3)\n" + + " void b(Y y) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method b(Y) of type C has the same erasure as b(Y) of type A but does not override it\n" + + "----------\n" + + "2. ERROR in C.java (at line 4)\n" + + " void c(X x) {}\n" + + " ^^^^^^\n" + + "This instance method cannot override the static method from A\n" + + "----------\n" + + "3. ERROR in C.java (at line 5)\n" + + " void d(Y y) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Name clash: The method d(Y) of type C has the same erasure as d(Y) of type A but does not hide it\n" + + "----------\n" + + "----------\n" + + "1. ERROR in C2.java (at line 3)\n" + + " void d(Y y) {}\n" + + " ^^^^^^^^^^^^^^^\n" + + "This instance method cannot override the static method from A\n" + + "----------\n" + ); +} +public void test150() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " // DOESN\'T Compile\n" + + " public MyT method3(D1 harg, D1 oarg, D1 date){\n" + + " return null;\n" + + " }\n" + + " // Doesn\'t compile\n" + + " public MyT method3(D1 harg, D1 oarg, D1 date){\n" + + " return null;\n" + + " }\n" + + " // Using vararg trick compiles ok use vararg to differentiate method signature\n" + + " public MyT method3(D1 harg, D1 oarg, D1 date, D1 ... notUsed){\n" + + " return null;\n" + + " }\n" + + " // Using vararg trick compiles ok use vararg to differentiate method signature\n" + + " public MyT method3(D1 harg, D1 oarg, D1 date, D2 ... notUsed){\n" + + " return null;\n" + + " }\n" + + " class MyT{}\n" + + " class D1{}\n" + + " class D2{}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public MyT method3(D1 harg, D1 oarg, D1 date){\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method method3(X.D1, X.D1, X.D1) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public MyT method3(D1 harg, D1 oarg, D1 date){\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method method3(X.D1, X.D1, X.D1) is the same as another method in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " public MyT method3(D1 harg, D1 oarg, D1 date, D1 ... notUsed){\n" + + " ^^\n" + + "X.D1 is a raw type. References to generic type X.D1 should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " public MyT method3(D1 harg, D1 oarg, D1 date, D2 ... notUsed){\n" + + " ^^\n" + + "X.D2 is a raw type. References to generic type X.D2 should be parameterized\n" + + "----------\n"); +} +public void test151() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Date;\n" + + "\n" + + "public class X {\n" + + " // Using vararg trick compiles ok use vararg to differentiate method signature\n" + + " public static MyT method3(D1 harg, D1 oarg, D1 date, D1... notUsed) {\n" + + " System.out.print(\"#method3(D1, D1, D1, D1[])\");\n" + + " return null;\n" + + " }\n" + + "\n" + + " // Using vararg trick compiles ok use vararg to differentiate method signature\n" + + " public static MyT method3(D1 harg, D1 oarg, D1 date, D2... notUsed) {\n" + + " System.out.print(\"#method3(D1, D1, D1, D2[])\");\n" + + " return null;\n" + + " }\n" + + "\n" + + " /**\n" + + " * this java main demonstrates that compiler can differentiate between to\n" + + " * the 2 different methods.\n" + + " * @param args\n" + + " */\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " D1 dString = x.new D1();\n" + + " D1 dDate = x.new D1();\n" + + " // calling first defined method\n" + + " X.method3(dString, dString, dDate);\n" + + " // calling second defined method\n" + + " X.method3(dString, dString, dString);\n" + + " // / will write out\n" + + " // method3 called with this signature: D1 harg, D1 oarg,\n" + + " // D1 date\n" + + " // method3 called with this signature: D1 harg, D1 oarg,\n" + + " // D1 date\n" + + " }\n" + + " class MyT {}\n" + + " public class D1 {}\n" + + " public class D2 {}\n" + + "}\n" + }, + "#method3(D1, D1, D1, D1[])#method3(D1, D1, D1, D2[])"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=219625 +public void test152() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void feedFoosValueIntoFoo(Foo foo) {\n" + + " foo.doSomething(foo.getValue());\n" + + " }\n" + + " static void testTypedString() {\n" + + " ConcreteFoo foo = new ConcreteFoo();\n" + + " foo.doSomething(foo.getValue());\n" + + " }\n" + + " static void testGenericString() {\n" + + " feedFoosValueIntoFoo(new ConcreteFoo());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " testTypedString();\n" + + " testGenericString();\n" + + " System.out.print(1);\n" + + " }\n" + + "}\n" + + "interface Foo {\n" + + " T getValue();\n" + + " void doSomething(T o);\n" + + "}\n" + + "abstract class AbstractFoo implements Foo {\n" + + " public void doSomething(String o) {}\n" + + "}\n" + + "class ConcreteFoo extends AbstractFoo {\n" + + " public String getValue() { return null; }\n" + + "}" + }, + "1" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223986 +public void test153() { + this.runConformTest( + new String[] { + "test/impl/SubOneImpl.java", //-------------------------------------------- + "package test.impl;\n" + + "import test.intf.SubTwo;\n" + + "public abstract class SubOneImpl extends SuperTypeExtendImpl implements test.intf.SubOne\n" + + "{\n" + + " public SubOneImpl plus(test.intf.SubOne attribute)\n" + + " {\n" + + " throw new RuntimeException(\"foo\");\n" + + " }\n" + + " public SubTwoImpl plus(SubTwo attribute)\n" + + " {\n" + + " throw new RuntimeException(\"foo\");\n" + + " }\n" + + "}\n", + "test/impl/SubSubOneImpl.java", //-------------------------------------------- + "package test.impl;\n" + + "public abstract class SubSubOneImpl extends SubOneImpl\n" + + "{\n" + + "}\n", + "test/impl/SubTwoImpl.java", //-------------------------------------------- + "package test.impl;\n" + + "import test.intf.SubOne;\n" + + "public abstract class SubTwoImpl extends SuperTypeExtendImpl implements\n" + + "test.intf.SubTwo\n" + + "{\n" + + " public SubTwoImpl plus(SubOne attribute)\n" + + " {\n" + + " throw new RuntimeException(\"foo\");\n" + + " }\n" + + " public SubTwoImpl plus(test.intf.SubTwo attribute)\n" + + " {\n" + + " throw new RuntimeException(\"foo\");\n" + + " }\n" + + "}\n", + "test/impl/SuperTypeExtend.java", //-------------------------------------------- + "package test.impl;\n" + + "import test.intf.SubOne;\n" + + "import test.intf.SubTwo;\n" + + "public interface SuperTypeExtend extends test.intf.SuperType\n" + + "{\n" + + " public SuperTypeExtend plus(SubOne addend);\n" + + " public SuperTypeExtend plus(SubTwo addend);\n" + + "}\n", + "test/impl/SuperTypeExtendImpl.java", //-------------------------------------------- + "package test.impl;\n" + + "public abstract class SuperTypeExtendImpl implements SuperTypeExtend\n" + + "{\n" + + "}\n", + "test/intf/SubOne.java", //-------------------------------------------- + "package test.intf;\n" + + "public interface SubOne extends SuperType\n" + + "{\n" + + " public SubOne plus(SubOne addend);\n" + + " public SubTwo plus(SubTwo addend);\n" + + "}\n", + "test/intf/SubTwo.java", //-------------------------------------------- + "package test.intf;\n" + + "public interface SubTwo extends SuperType\n" + + "{\n" + + " public SubTwo plus(SubOne addend);\n" + + " public SubTwo plus(SubTwo addend);\n" + + "}\n", + "test/intf/SuperType.java", //-------------------------------------------- + "package test.intf;\n" + + "public interface SuperType\n" + + "{\n" + + " public SuperType plus(SubOne addend);\n" + + " public SuperType plus(SubTwo addend);\n" + + "}\n", + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223986 - variation +public void test154() { + this.runConformTest( + new String[] { + "test/impl/SubOneImpl.java", //-------------------------------------------- + "package test.impl;\n" + + "public abstract class SubOneImpl extends SuperTypeExtendImpl implements test.impl.SubOne {\n" + + " public SubOneImpl plus(test.impl.SubOne attribute) {\n" + + " throw new RuntimeException(\"foo\");\n" + + " }\n" + + " public SubTwoImpl plus(SubTwo attribute) {\n" + + " throw new RuntimeException(\"foo\");\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class SubSubOneImpl extends SubOneImpl {\n" + + "}\n" + + "\n" + + "abstract class SubTwoImpl extends SuperTypeExtendImpl implements test.impl.SubTwo {\n" + + " public SubTwoImpl plus(SubOne attribute) {\n" + + " throw new RuntimeException(\"foo\");\n" + + " }\n" + + " public SubTwoImpl plus(test.impl.SubTwo attribute) {\n" + + " throw new RuntimeException(\"foo\");\n" + + " }\n" + + "}\n" + + "\n" + + "interface SuperTypeExtend extends test.impl.SuperType {\n" + + " public SuperTypeExtend plus(SubOne addend);\n" + + " public SuperTypeExtend plus(SubTwo addend);\n" + + "}\n" + + "\n" + + "abstract class SuperTypeExtendImpl implements SuperTypeExtend {\n" + + "}\n" + + "\n" + + "interface SubOne extends SuperType {\n" + + " public SubOne plus(SubOne addend);\n" + + " public SubTwo plus(SubTwo addend);\n" + + "}\n" + + "\n" + + "interface SubTwo extends SuperType {\n" + + " public SubTwo plus(SubOne addend);\n" + + " public SubTwo plus(SubTwo addend);\n" + + "}\n" + + "\n" + + "interface SuperType {\n" + + " public SuperType plus(SubOne addend);\n" + + " public SuperType plus(SubTwo addend);\n" + + "}\n", + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223986 - variation +public void test155() { + this.runNegativeTest( + new String[] { + "X.java", //-------------------------------------------- + "class A {}\n" + + "class B {}\n" + + "interface I {\n" + + " A foo();\n" + + "}\n" + + "interface J {\n" + + " B foo();\n" + + "}\n" + + "public abstract class X implements I, J {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " public abstract class X implements I, J {\n" + + " ^\n" + + "The return types are incompatible for the inherited methods I.foo(), J.foo()\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223986 - variation +public void test156() { + this.runNegativeTest( + new String[] { + "X.java", //-------------------------------------------- + "class Common {}\n" + + "class A extends Common {}\n" + + "class B extends Common {}\n" + + "interface I {\n" + + " A foo();\n" + + "}\n" + + "interface J {\n" + + " B foo();\n" + + "}\n" + + "public abstract class X implements I, J {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " public abstract class X implements I, J {\n" + + " ^\n" + + "The return types are incompatible for the inherited methods I.foo(), J.foo()\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223986 - variation +public void test157() { + this.runNegativeTest( + new String[] { + "X.java", //-------------------------------------------- + "interface A {\n" + + " A foo();\n" + + "}\n" + + "interface B {\n" + + " B foo();\n" + + "}\n" + + "interface C extends A, B {}\n" + + "\n" + + "class Root {\n" + + " public C foo() { return null; }\n" + + "}\n" + + "public abstract class X extends Root implements A, B {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " interface C extends A, B {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods A.foo(), B.foo()\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223986 - variation +public void test158() { + this.runNegativeTest( + new String[] { + "X.java", //-------------------------------------------- + "import java.io.Serializable;\n" + + "\n" + + "interface AFoo { \n" + + " Serializable foo();\n" + + " Serializable bar();\n" + + "}\n" + + "interface BFoo { \n" + + " Cloneable foo(); \n" + + " Cloneable bar(); \n" + + "}\n" + + "\n" + + "interface C extends Serializable, Cloneable {}\n" + + "\n" + + "class Root {\n" + + " public C foo() { return null; }\n" + + "}\n" + + "public abstract class X extends Root implements AFoo, BFoo {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " public abstract class X extends Root implements AFoo, BFoo {\n" + + " ^\n" + + "The return types are incompatible for the inherited methods AFoo.bar(), BFoo.bar()\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=223986 - variation +public void test159() { + this.runNegativeTest( + new String[] { + "X.java", //-------------------------------------------- + "import java.io.Serializable;\n" + + "\n" + + "interface AFoo { \n" + + " Serializable foo();\n" + + " Serializable bar();\n" + + "}\n" + + "interface BFoo { \n" + + " Cloneable foo(); \n" + + " Cloneable bar(); \n" + + "}\n" + + "interface C extends Serializable, Cloneable {}\n" + + "class Root {\n" + + " public C foo() { return null; }\n" + + "}\n" + + "public abstract class X extends Root implements AFoo, BFoo {}\n" + + "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 AFoo.bar(), BFoo.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 AFoo.bar(), BFoo.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 BFoo.bar()\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=208010 +public void test160() { + this.runConformTest( + new String[] { + "bar/X.java", //-------------------------------------------- + "package bar;" + + "public class X {\n" + + " static void foo() {}\n" + + "}", + "foo/Y.java", //-------------------------------------------- + "package foo;" + + "public class Y extends bar.X {\n" + + " static void foo() {}\n" + + "}", + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227185 +public void test161() { + this.runConformTest( + new String[] { + "Concrete.java", + "abstract class SuperAbstract {\n" + + " abstract Object foo(Type other);\n" + + "}\n" + + "abstract class HalfGenericSuper extends SuperAbstract {\n" + + " @Override abstract Object foo(String other);\n" + + "}\n" + + "abstract class AbstractImpl extends HalfGenericSuper {\n" + + " @Override Object foo(String other) { return null; }\n" + + "}\n" + + "class Concrete extends AbstractImpl{}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227185 - variant +public void test162() { + this.runConformTest( + new String[] { + "Concrete.java", + "abstract class SuperAbstract {\n" + + " abstract Object foo(Type other);\n" + + "}\n" + + "class HalfGenericSuper extends SuperAbstract {\n" + + " @Override Object foo(String other) { return null; }\n" + + "}\n" + + "abstract class AbstractImpl extends HalfGenericSuper {}\n" + + "class HalfConcrete extends HalfGenericSuper {}\n" + + "class Concrete extends AbstractImpl{}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227185 - variant return types +public void test163() { + this.runNegativeTest( + new String[] { + "Concrete.java", + "abstract class SuperAbstract {\n" + + " abstract Type foo(Type other);\n" + + "}\n" + + "class HalfGenericSuper extends SuperAbstract {\n" + + " @Override Object foo(String other) { return null; }\n" + + "}\n" + + "class Concrete extends HalfGenericSuper{}" + }, + "----------\n" + + "1. ERROR in Concrete.java (at line 5)\n" + + " @Override Object foo(String other) { return null; }\n" + + " ^^^^^^\n" + + "The return type is incompatible with SuperAbstract.foo(String)\n" + + "----------\n" + + "2. WARNING in Concrete.java (at line 7)\n" + + " class Concrete extends HalfGenericSuper{}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "HalfGenericSuper is a raw type. References to generic type HalfGenericSuper should be parameterized\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227185 - variant return types +public void test164() { + this.runNegativeTest( + new String[] { + "Concrete.java", + "interface I {\n" + + " Type foo(Type other);\n" + + " Owner foo2(Type other);\n" + + " Object foo3(Type other);\n" + + "}\n" + + "class HalfGenericSuper {\n" + + " public Object foo(String other) { return null; }\n" + + " public Integer foo2(String other) { return null; }\n" + + " public String foo3(String other) { return null; }\n" + + "}\n" + + "class HalfConcrete extends HalfGenericSuper {}\n" + + "class Concrete extends HalfConcrete implements I {}" + }, + "----------\n" + + "1. ERROR in Concrete.java (at line 12)\n" + + " class Concrete extends HalfConcrete implements I {}\n" + + " ^^^^^^^^\n" + + "The type Concrete must implement the inherited abstract method I.foo(String) to override HalfGenericSuper.foo(String)\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227185 - variant return types +public void test165() { + this.runNegativeTest( + new String[] { + "X.java", + "class X { void foo() {} }\n" + + "class Y extends X { @Override int foo() { return 1; } }" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X { @Override int foo() { return 1; } }\n" + + " ^^^\n" + + "The return type is incompatible with X.foo()\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238014 +public void test166() { + this.runNegativeTest( + new String[] { + "X.java", + "class X extends A implements I {}\n" + + "interface I { void foo(T item); }\n" + + "class A {\n" + + " public void foo(Object item) {}\n" + + " public void foo(String item) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends A implements I {}\n" + + " ^\n" + + "Name clash: The method foo(Object) of type A has the same erasure as foo(T) of type I but does not override it\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=238817 +public void test167() { + this.runConformTest( + new String[] { + "X.java", + "class X implements I, J {\n" + + " public void foo(T3 t, String s) {}\n" + + "}\n" + + "interface I { void foo(T1 t, U1 u); }\n" + + "interface J { void foo(T2 t, U2 u); }\n" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=236096 +public void test168() { + this.runNegativeTest( + new String[] { + "X.java", + "class X extends Y {\n" + + " @Override void foo(M m) { }\n" + + " @Override M bar() { return null; }\n" + + "}\n" + + "class Y {\n" + + " class M {}\n" + + " void foo(M m) {}\n" + + " M bar() { return null; }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " class X extends Y {\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " @Override void foo(M m) { }\n" + + " ^^^^^^^^\n" + + "Name clash: The method foo(Y.M) of type X has the same erasure as foo(Y.M) of type Y but does not override it\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " @Override void foo(M m) { }\n" + + " ^^^^^^^^\n" + + mustOverrideMessage("foo(Y.M)", "X") + + "----------\n" + + "4. WARNING in X.java (at line 2)\n" + + " @Override void foo(M m) { }\n" + + " ^\n" + + "Y.M is a raw type. References to generic type Y.M should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 3)\n" + + " @Override M bar() { return null; }\n" + + " ^\n" + + "Y.M is a raw type. References to generic type Y.M should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 3)\n" + + " @Override M bar() { return null; }\n" + + " ^^^^^\n" + + "Name clash: The method bar() of type X has the same erasure as bar() of type Y but does not override it\n" + + "----------\n" + + "7. ERROR in X.java (at line 3)\n" + + " @Override M bar() { return null; }\n" + + " ^^^^^\n" + + mustOverrideMessage("bar()", "X") + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=243820 +public void test169() { + this.runNegativeTest( + false, + new String[] { + "X.java", + "class X {\n" + + " interface I {}\n" + + " interface J { A foo(A a, I i); }\n" + + " static class A {}\n" + + " static class B implements J {\n" + + " public R foo(A a, I i) { return null; }\n" + + " }\n" + + "}\n" + + "class R extends X.A {}" + }, + null, + null, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public R foo(A a, I i) { return null; }\n" + + " ^\n" + + "R is a raw type. References to generic type R should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public R foo(A a, I i) { return null; }\n" + + " ^\n" + + "X.I is a raw type. References to generic type X.I should be parameterized\n" + + "----------\n", + Excuse.EclipseHasSomeMoreWarnings + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=243820 +public void test169a() { + this.runNegativeTest( + false, + new String[] { + "X.java", + "class X {\n" + + " abstract class B implements J {\n" + + " public R foo(X.B b, I i) { return null; }\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "interface J { A foo(A a, I i); }\n" + + "class A {}\n" + + "class R extends A {}" + }, + null, + null, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public R foo(X.B b, I i) { return null; }\n" + + " ^\n" + + "R is a raw type. References to generic type R should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " public R foo(X.B b, I i) { return null; }\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n", + Excuse.EclipseHasSomeMoreWarnings + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239066 +public void test170() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingSynchronizedOnInheritedMethod, CompilerOptions.ERROR); + this.runNegativeTest( + false, + new String[] { + "X.java", + "class X { synchronized void foo() {} }\n" + + "class Y extends X { @Override void foo() { } }" + }, + null, // libs + options, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X { @Override void foo() { } }\n" + + " ^^^^^\n" + + "The method Y.foo() is overriding a synchronized method without being synchronized\n" + + "----------\n", + Excuse.EclipseWarningConfiguredAsError); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239066 - variation +public void test171() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingSynchronizedOnInheritedMethod, CompilerOptions.ERROR); + this.runNegativeTest( + false, + new String[] { + "X.java", + "public enum X {\n" + + " FOO { @Override void foo() { super.foo(); } };\n"+ + " synchronized void foo() { }\n"+ + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " FOO { @Override void foo() { super.foo(); } };\n" + + " ^^^^^\n" + + "The method new X(){}.foo() is overriding a synchronized method without being synchronized\n" + + "----------\n", + Excuse.EclipseWarningConfiguredAsError); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239066 - variation +public void test172() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingSynchronizedOnInheritedMethod, CompilerOptions.ERROR); + this.runNegativeTest( + false, + new String[] { + "X.java", + "public class X {\n" + + " void bar() { new X() { @Override void foo() {} }; }\n"+ + " synchronized void foo() { }\n"+ + "}" + }, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void bar() { new X() { @Override void foo() {} }; }\n"+ + " ^^^^^\n" + + "The method new X(){}.foo() is overriding a synchronized method without being synchronized\n" + + "----------\n", + Excuse.EclipseWarningConfiguredAsError); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239066 - variation +public void test173() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingSynchronizedOnInheritedMethod, CompilerOptions.ERROR); + this.runNegativeTest( + false, + new String[] { + "X.java", + "public class X { synchronized void foo() {} }\n" + + "class Y extends X {}\n" + + "class Z extends Y { @Override void foo() {} }\n" + }, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class Z extends Y { @Override void foo() {} }\n" + + " ^^^^^\n" + + "The method Z.foo() is overriding a synchronized method without being synchronized\n" + + "----------\n", + Excuse.EclipseWarningConfiguredAsError); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249140 +public void test174() { + this.runNegativeTest( + new String[] { + "X.java", + "class X extends Y implements I { }\n" + + "abstract class Y { public abstract Object m(); }\n" + + "abstract class A implements I, J { }\n" + + "abstract class B implements J, I { }\n" + + "interface I { String m(); }\n" + + "interface J { Object m(); }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends Y implements I { }\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.m() to override Y.m()\n" + + "----------\n" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38751 +public void test175() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingHashCodeMethod, CompilerOptions.WARNING); + this.runNegativeTest( + false, + new String[] { + "A.java", + "class A {\n" + + " @Override public boolean equals(Object o) { return true; }\n" + + "}" + }, + null, + options, + "----------\n" + + "1. WARNING in A.java (at line 1)\n" + + " class A {\n" + + " ^\n" + + "The type A should also implement hashCode() since it overrides Object.equals()\n" + + "----------\n", + Excuse.EclipseHasSomeMoreWarnings); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=38751 +public void test176() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingHashCodeMethod, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " @Override public boolean equals(Object o) { return true; }\n" + + " @Override public int hashCode() { return 1; }\n" + + "}\n" + + "class B extends A {\n" + + " @Override public boolean equals(Object o) { return false; }\n" + + "}" + }, + "", + null, + false, + options); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=251091 +// Srikanth, Aug 10th 2010. This test does not elicit any name clash error from javac 5 or javac6 +// javac7 reports "X.java:7: name clash: foo(Collection) in X and foo(Collection) in A have the +// same erasure, yet neither overrides the other" +// After the fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=322001, we match +// JDK7 (7b100) behavior. (earlier we would issue an extra name clash) +public void test177() { + if (new CompilerOptions(getCompilerOptions()).complianceLevel >= ClassFileConstants.JDK1_6) { // see test187() + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6)? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class A extends LinkedHashMap {\n" + + " ^\n" + + "The serializable class A does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " class A extends LinkedHashMap {\n" + + " ^^^^^^^^^^^^^\n" + + "LinkedHashMap is a raw type. References to generic type LinkedHashMap should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " public A foo(Collection c) { return this; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " class X extends A implements I {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " @Override public X foo(Collection c) { return this; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Collection) of type X has the same erasure as foo(Collection) of type A but does not override it\n" + + "----------\n": + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class A extends LinkedHashMap {\n" + + " ^\n" + + "The serializable class A does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " class A extends LinkedHashMap {\n" + + " ^^^^^^^^^^^^^\n" + + "LinkedHashMap is a raw type. References to generic type LinkedHashMap should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " public A foo(Collection c) { return this; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " class X extends A implements I {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " @Override public X foo(Collection c) { return this; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Collection) of type X has the same erasure as foo(Collection) of type A but does not override it\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface I { I foo(Collection c); }\n" + + "class A extends LinkedHashMap {\n" + + " public A foo(Collection c) { return this; }\n" + + "}\n" + + "class X extends A implements I {\n" + + " @Override public X foo(Collection c) { return this; }\n" + + "}" + }, + expectedCompilerLog + ); + } else { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface I { I foo(Collection c); }\n" + + "class A extends LinkedHashMap {\n" + + " public A foo(Collection c) { return this; }\n" + + "}\n" + + "class X extends A implements I {\n" + + " @Override public X foo(Collection c) { return this; }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class A extends LinkedHashMap {\n" + + " ^\n" + + "The serializable class A does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " class A extends LinkedHashMap {\n" + + " ^^^^^^^^^^^^^\n" + + "LinkedHashMap is a raw type. References to generic type LinkedHashMap should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " public A foo(Collection c) { return this; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " class X extends A implements I {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " @Override public X foo(Collection c) { return this; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(Collection) of type X has the same erasure as foo(Collection) of type A but does not override it\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " @Override public X foo(Collection c) { return this; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The method foo(Collection) of type X must override a superclass method\n" + + "----------\n" + ); + } +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=241821 +public void test178() { + this.runConformTest( + new String[] { + "I.java", + "import java.util.*;\n" + + "interface I extends I1, I2, I3 {}\n" + + "interface I1 { List m(); }\n" + + "interface I2 { Queue m(); }\n" + + "interface I3 { LinkedList m(); }" + }, + "" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163093 +public void test179() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Adaptable {\n" + + " public Object getAdapter(Class clazz); \n" + + "}\n" + + "\n" + + "public class X implements Adaptable {\n" + + " @Override\n" + + " public Object getAdapter(Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public Object getAdapter(Class clazz); \n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X implements Adaptable {\n" + + " ^\n" + + "The type X must implement the inherited abstract method Adaptable.getAdapter(Class)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " public Object getAdapter(Class clazz) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method getAdapter(Class) of type X has the same erasure as getAdapter(Class) of type Adaptable but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " public Object getAdapter(Class clazz) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + mustOverrideMessage("getAdapter(Class)", "X") + + "----------\n" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=255035 +public void test180() { + this.runNegativeTest( + new String[] { + "X.java", + "class S {\n" + + " String foo() { return null; }\n" + + "}\n" + + "class X extends S {\n" + + " foo() { return null; }\n" + + " @Override String foo() { return null; }\n" + // should keep this definition + " Number foo() { return null; }\n" + + " void test() { foo(); }\n" + // no secondary error + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " foo() { return null; }\n" + + " ^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " @Override String foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " Number foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249134 +public void test181() { + this.runNegativeTest( + new String[] { + "I.java", + "interface I {\n" + + " String m();\n" + + " Object n();\n" + + " String o();\n" + + " Object p();\n" + + "}\n" + + "abstract class A {\n" + + " public abstract Object m();\n" + + " public abstract String n();\n" + + " abstract Object o();\n" + + " abstract String p();\n" + + "}\n" + + "class A2 {\n" + + " public abstract Object m();\n" + + " public abstract String n();\n" + + " abstract Object o();\n" + + " abstract String p();\n" + + "}\n", + "B.java", + "class B extends A implements I {}", + "B2.java", + "class B2 extends A2 implements I {}" + }, + "----------\n" + + "1. ERROR in I.java (at line 13)\n" + + " class A2 {\n" + + " ^^\n" + + "The type A2 must be an abstract class to define abstract methods\n" + + "----------\n" + + "2. ERROR in I.java (at line 14)\n" + + " public abstract Object m();\n" + + " ^^^\n" + + "The abstract method m in type A2 can only be defined by an abstract class\n" + + "----------\n" + + "3. ERROR in I.java (at line 15)\n" + + " public abstract String n();\n" + + " ^^^\n" + + "The abstract method n in type A2 can only be defined by an abstract class\n" + + "----------\n" + + "4. ERROR in I.java (at line 16)\n" + + " abstract Object o();\n" + + " ^^^\n" + + "The abstract method o in type A2 can only be defined by an abstract class\n" + + "----------\n" + + "5. ERROR in I.java (at line 17)\n" + + " abstract String p();\n" + + " ^^^\n" + + "The abstract method p in type A2 can only be defined by an abstract class\n" + + "----------\n" + + "----------\n" + + "1. ERROR in B.java (at line 1)\n" + + " class B extends A implements I {}\n" + + " ^\n" + + "The type B must implement the inherited abstract method A.p()\n" + + "----------\n" + + "2. ERROR in B.java (at line 1)\n" + + " class B extends A implements I {}\n" + + " ^\n" + + "The type B must implement the inherited abstract method I.o() to override A.o()\n" + + "----------\n" + + "3. ERROR in B.java (at line 1)\n" + + " class B extends A implements I {}\n" + + " ^\n" + + "The type B must implement the inherited abstract method A.n()\n" + + "----------\n" + + "4. ERROR in B.java (at line 1)\n" + + " class B extends A implements I {}\n" + + " ^\n" + + "The type B must implement the inherited abstract method I.m() to override A.m()\n" + + "----------\n" + + "----------\n" + + "1. ERROR in B2.java (at line 1)\n" + + " class B2 extends A2 implements I {}\n" + + " ^^\n" + + "The type B2 must implement the inherited abstract method I.o() to override A2.o()\n" + + "----------\n" + + "2. ERROR in B2.java (at line 1)\n" + + " class B2 extends A2 implements I {}\n" + + " ^^\n" + + "The type B2 must implement the inherited abstract method I.m() to override A2.m()\n" + + "----------\n", + null, + true, + null, + true, + false, + false + ); + this.runNegativeTest( + new String[] { + "B.java", + "class B extends A implements I {}", + "B2.java", + "class B2 extends A2 implements I {}" + }, + "----------\n" + + "1. ERROR in B.java (at line 1)\n" + + " class B extends A implements I {}\n" + + " ^\n" + + "The type B must implement the inherited abstract method A.p()\n" + + "----------\n" + + "2. ERROR in B.java (at line 1)\n" + + " class B extends A implements I {}\n" + + " ^\n" + + "The type B must implement the inherited abstract method I.o() to override A.o()\n" + + "----------\n" + + "3. ERROR in B.java (at line 1)\n" + + " class B extends A implements I {}\n" + + " ^\n" + + "The type B must implement the inherited abstract method A.n()\n" + + "----------\n" + + "4. ERROR in B.java (at line 1)\n" + + " class B extends A implements I {}\n" + + " ^\n" + + "The type B must implement the inherited abstract method I.m() to override A.m()\n" + + "----------\n" + + "----------\n" + + "1. ERROR in B2.java (at line 1)\n" + + " class B2 extends A2 implements I {}\n" + + " ^^\n" + + "The type B2 must implement the inherited abstract method I.o() to override A2.o()\n" + + "----------\n" + + "2. ERROR in B2.java (at line 1)\n" + + " class B2 extends A2 implements I {}\n" + + " ^^\n" + + "The type B2 must implement the inherited abstract method I.m() to override A2.m()\n" + + "----------\n", + null, + false + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=249134 +public void test182() { + this.runNegativeTest( + new String[] { + "I.java", + "interface I {\n" + + " String m();\n" + + " Object n();\n" + + "}\n" + + "class A {\n" + + " public Object m() { return null; }\n" + + " public String n() { return null; }\n" + + "}\n" + + "abstract class A2 {\n" + + " public Object m() { return null; }\n" + + " public String n() { return null; }\n" + + "}\n", + "B.java", + "class B extends A implements I {}", + "B2.java", + "class B2 extends A2 implements I {}" + }, + "----------\n" + + "1. ERROR in B.java (at line 1)\n" + + " class B extends A implements I {}\n" + + " ^\n" + + "The type B must implement the inherited abstract method I.m() to override A.m()\n" + + "----------\n" + + "----------\n" + + "1. ERROR in B2.java (at line 1)\n" + + " class B2 extends A2 implements I {}\n" + + " ^^\n" + + "The type B2 must implement the inherited abstract method I.m() to override A2.m()\n" + + "----------\n" + ); + this.runNegativeTest( + new String[] { + "B.java", + "class B extends A implements I {}", + "B2.java", + "class B2 extends A2 implements I {}" + }, + "----------\n" + + "1. ERROR in B.java (at line 1)\n" + + " class B extends A implements I {}\n" + + " ^\n" + + "The type B must implement the inherited abstract method I.m() to override A.m()\n" + + "----------\n" + + "----------\n" + + "1. ERROR in B2.java (at line 1)\n" + + " class B2 extends A2 implements I {}\n" + + " ^^\n" + + "The type B2 must implement the inherited abstract method I.m() to override A2.m()\n" + + "----------\n", + null, + false + ); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262208 +public void test183() { + this.runNegativeTest( + new String[] { + "X.java", + "class XX {\n" + + " > void a(S gC) {}\n" + + " > void b(T c) {}\n" + + " void c(G gC) {}\n" + + " > void d(S gC) {}\n" + + "}\n" + + "class X extends XX {\n" + + " @Override void a(G g) {}\n" + + " @Override void b(C c) {}\n" + + " @Override void c(G g) {}\n" + + " @Override > void d(S gc) {}\n" + + "}\n" + + "class C {}\n" + + "class G {}" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " @Override void a(G g) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " @Override void c(G g) {}\n" + + " ^\n" + + "G is a raw type. References to generic type G should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " @Override > void d(S gc) {}\n" + + " ^^^^^^^\n" + + "Name clash: The method d(S) of type X has the same erasure as d(S) of type XX but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " @Override > void d(S gc) {}\n" + + " ^^^^^^^\n" + + mustOverrideMessage("d(S)", "X") + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=264881 +public void test184() { + this.runNegativeTest( + new String[] { + "A.java", + "class A {\n" + + " > T a() { return null; }\n" + + " U num() { return null; }\n" + + " T x() { return null; }\n" + + " T y() { return null; }\n" + + " T z() { return null; }\n" + + "}\n" + + "class B extends A {\n" + + " @Override A a() { return null; }\n" + + " @Override Double num() { return 1.0; }\n" + + " @Override Integer x() { return 1; }\n" + + " @Override Integer y() { return 1; }\n" + + " @Override Integer z() { return 1; }\n" + + "}\n" + + "class C extends A {\n" + + " @Override A a() { return null; }\n" + + " @Override Double num() { return 1.0; }\n" + + " @Override Integer x() { return 1; }\n" + + " @Override Integer y() { return 1; }\n" + + " @Override Integer z() { return 1; }\n" + + "}\n" + + "class M {\n" + + " Object m(Class c) { return null; }\n" + + " Object n(Class c) { return null; }\n" + + "}\n" + + "class N extends M {\n" + + " @Override T m(Class c) { return null; }\n" + + " @Override V n(Class c) { return null; }\n" + + "}" + }, + "----------\n" + + "1. WARNING in A.java (at line 6)\n" + + " T z() { return null; }\n" + + " ^^^^^^^\n" + + "The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in A.java (at line 9)\n" + + " @Override A a() { return null; }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "3. WARNING in A.java (at line 9)\n" + + " @Override A a() { return null; }\n" + + " ^\n" + + "Type safety: The return type A for a() from the type B needs unchecked conversion to conform to T from the type A\n" + + "----------\n" + + "4. WARNING in A.java (at line 11)\n" + + " @Override Integer x() { return 1; }\n" + + " ^^^^^^^\n" + + "Type safety: The return type Integer for x() from the type B needs unchecked conversion to conform to T from the type A\n" + + "----------\n" + + "5. WARNING in A.java (at line 12)\n" + + " @Override Integer y() { return 1; }\n" + + " ^^^^^^^\n" + + "Type safety: The return type Integer for y() from the type B needs unchecked conversion to conform to T from the type A\n" + + "----------\n" + + "6. WARNING in A.java (at line 13)\n" + + " @Override Integer z() { return 1; }\n" + + " ^^^^^^^\n" + + "Type safety: The return type Integer for z() from the type B needs unchecked conversion to conform to T from the type A\n" + + "----------\n" + + "7. WARNING in A.java (at line 15)\n" + + " class C extends A {\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + + "8. WARNING in A.java (at line 16)\n" + + " @Override A a() { return null; }\n" + + " ^\n" + + "A is a raw type. References to generic type A should be parameterized\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=267088 +public void test185() { + this.runNegativeTest( + new String[] { + "A.java", + "interface I { I hello(); }\n" + + "interface J { J hello(); }\n" + + "class A implements I, J {}" + }, + "----------\n" + + "1. ERROR in A.java (at line 3)\n" + + " class A implements I, J {}\n" + + " ^\n" + + "The type A must implement the inherited abstract method J.hello()\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=271303 +public void test186() { + this.runNegativeTest( + false, + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A { void m() {} }\n", + "p2/B.java", + "package p2;\n" + + "public class B extends p1.A { void m() {} }\n", + "p1/C.java", + "package p1;\n" + + "public class C extends p2.B { @Override void m() {} }" + }, + null, + null, + "----------\n" + + "1. WARNING in p2\\B.java (at line 2)\n" + + " public class B extends p1.A { void m() {} }\n" + + " ^^^\n" + + "The method B.m() does not override the inherited method from A since it is private to a different package\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p1\\C.java (at line 2)\n" + + " public class C extends p2.B { @Override void m() {} }\n" + + " ^^^\n" + + "The method C.m() does not override the inherited method from B since it is private to a different package\n" + + "----------\n", + Excuse.EclipseHasSomeMoreWarnings + ); +} +// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6182950 +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=? +public void test187() { + String expectedCompilerLog = (this.complianceLevel == ClassFileConstants.JDK1_6 )? + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " double f(List l) {return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method f(List) of type Y has the same erasure as f(List) of type X but does not override it\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " int f(List l) {return 0;}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Erasure of method f(List) is the same as another method in type XX\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " double f(List l) {return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method f(List) is the same as another method in type XX\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " double f(List l) {return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method f(List) of type Y has the same erasure as f(List) of type X but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " int f(List l) {return 0;}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Erasure of method f(List) is the same as another method in type XX\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " double f(List l) {return 0;}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method f(List) is the same as another method in type XX\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class X {\n" + + " int f(List l) {return 0;}\n" + + "}\n" + + "class Y extends X {\n" + + " double f(List l) {return 0;}\n" +// name clash in 7 + "}\n" + + "interface I {\n" + + " double f(List l);\n" + + "}\n" + + "abstract class Z extends X implements I {}\n" + + "class XX {\n" + + " int f(List l) {return 0;}\n" + + "double f(List l) {return 0;}\n" +// name clash in 1.5 & 7 + "}" + }, + expectedCompilerLog + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=279836 +public void test188() { + this.runNegativeTest( + false, + new String[] { + "Y.java", + "abstract class Y implements I {\n" + + " public T get(T element) { return null; }\n" + + "}\n" + + "interface I { T get(T element); }\n" + + "class Z extends Y {}" + }, + null, + null, + "----------\n" + + "1. WARNING in Y.java (at line 5)\n" + + " class Z extends Y {}\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n", + Excuse.EclipseHasSomeMoreWarnings + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284431 +public void test189() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Interface {\n" + + " void foo() throws CloneNotSupportedException, InterruptedException;\n" + + "}\n" + + "abstract class AbstractClass1 {\n" + + " public abstract void foo() throws ClassNotFoundException, CloneNotSupportedException;\n" + + "}\n" + + "abstract class AbstractClass2 extends AbstractClass1 implements Interface {\n" + + " void bar() {\n" + + " try {\n" + + " foo();\n" + + " } catch (CloneNotSupportedException e) {\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class X extends AbstractClass2 {\n" + + " @Override\n" + + " public void foo() throws CloneNotSupportedException {\n" + + " }\n" + + "}\n" + + "class Y extends AbstractClass2 {\n" + + " @Override public void foo() throws ClassNotFoundException, CloneNotSupportedException {}\n" + + "}\n" + + "class Z extends AbstractClass2 {\n" + + " @Override public void foo() throws CloneNotSupportedException, InterruptedException {}\n" + + "}\n" + + "class All extends AbstractClass2 {\n" + + " @Override public void foo() throws ClassNotFoundException, CloneNotSupportedException, InterruptedException {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " @Override public void foo() throws ClassNotFoundException, CloneNotSupportedException {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Exception ClassNotFoundException is not compatible with throws clause in Interface.foo()\n" + + "----------\n" + + "2. ERROR in X.java (at line 25)\n" + + " @Override public void foo() throws CloneNotSupportedException, InterruptedException {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Exception InterruptedException is not compatible with throws clause in AbstractClass1.foo()\n" + + "----------\n" + + "3. ERROR in X.java (at line 28)\n" + + " @Override public void foo() throws ClassNotFoundException, CloneNotSupportedException, InterruptedException {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Exception ClassNotFoundException is not compatible with throws clause in Interface.foo()\n" + + "----------\n" + + "4. ERROR in X.java (at line 28)\n" + + " @Override public void foo() throws ClassNotFoundException, CloneNotSupportedException, InterruptedException {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Exception InterruptedException is not compatible with throws clause in AbstractClass1.foo()\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284482 +public void test190() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " void foo() {}\n" + + "}", + "p1/B.java", + "package p1;\n" + + "public class B extends p2.C {\n" + + " @Override public int foo() { return 0; }\n" + + "}", + "p2/C.java", + "package p2;\n" + + "public class C extends p1.A {\n" + + " public int foo() { return 1; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p1\\B.java (at line 3)\n" + + " @Override public int foo() { return 0; }\n" + + " ^^^\n" + + "The return type is incompatible with A.foo()\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p2\\C.java (at line 3)\n" + + " public int foo() { return 1; }\n" + + " ^^^^^\n" + + "The method C.foo() does not override the inherited method from A since it is private to a different package\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284482 +public void test191() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " static void foo() {}\n" + + "}", + "p1/B.java", + "package p1;\n" + + "public class B extends p2.C {\n" + + " public static int foo() { return 0; }\n" + + "}", + "p2/C.java", + "package p2;\n" + + "public class C extends p1.A {\n" + + " public static int foo() { return 1; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p1\\B.java (at line 3)\n" + + " public static int foo() { return 0; }\n" + + " ^^^\n" + + "The return type is incompatible with A.foo()\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284482 +public void test192() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " void foo() {}\n" + + "}", + "p1/B.java", + "package p1;\n" + + "public class B extends p2.C {\n" + + " public static int foo() { return 0; }\n" + + "}", + "p2/C.java", + "package p2;\n" + + "public class C extends p1.A {\n" + + " public static int foo() { return 1; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p1\\B.java (at line 3)\n" + + " public static int foo() { return 0; }\n" + + " ^^^^^\n" + + "This static method cannot hide the instance method from A\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284482 +public void test193() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " void foo() {}\n" + + "}", + "p1/B.java", + "package p1;\n" + + "public class B extends p2.C {\n" + + " @Override public int foo() { return 0; }\n" + + "}", + "p2/C.java", + "package p2;\n" + + "public class C extends p1.A {\n" + + " public static int foo() { return 1; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p1\\B.java (at line 3)\n" + + " @Override public int foo() { return 0; }\n" + + " ^^^\n" + + "The return type is incompatible with A.foo()\n" + + "----------\n" + + "2. ERROR in p1\\B.java (at line 3)\n" + + " @Override public int foo() { return 0; }\n" + + " ^^^^^\n" + + "This instance method cannot override the static method from C\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284482 +public void test194() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " static void foo() {}\n" + + "}", + "p1/B.java", + "package p1;\n" + + "public class B extends p2.C {\n" + + " public int foo() { return 0; }\n" + + "}", + "p2/C.java", + "package p2;\n" + + "public class C extends p1.A {\n" + + " public static int foo() { return 1; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p1\\B.java (at line 3)\n" + + " public int foo() { return 0; }\n" + + " ^^^^^\n" + + "This instance method cannot override the static method from A\n" + + "----------\n" + + "2. ERROR in p1\\B.java (at line 3)\n" + + " public int foo() { return 0; }\n" + + " ^^^^^\n" + + "This instance method cannot override the static method from C\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284482 +public void test195() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " static void foo() {}\n" + + "}", + "p1/B.java", + "package p1;\n" + + "public class B extends p2.C {\n" + + " @Override public int foo() { return 0; }\n" + + "}", + "p2/C.java", + "package p2;\n" + + "public class C extends p1.A {\n" + + " public int foo() { return 1; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p1\\B.java (at line 3)\n" + + " @Override public int foo() { return 0; }\n" + + " ^^^^^\n" + + "This instance method cannot override the static method from A\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284482 +public void test196() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " static void foo() {}\n" + + "}", + "p1/B.java", + "package p1;\n" + + "public class B extends p2.C {\n" + + " public static int foo() { return 0; }\n" + + "}", + "p2/C.java", + "package p2;\n" + + "public class C extends p1.A {\n" + + " public int foo() { return 1; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p1\\B.java (at line 3)\n" + + " public static int foo() { return 0; }\n" + + " ^^^\n" + + "The return type is incompatible with A.foo()\n" + + "----------\n" + + "2. ERROR in p1\\B.java (at line 3)\n" + + " public static int foo() { return 0; }\n" + + " ^^^^^\n" + + "This static method cannot hide the instance method from C\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284482 +public void test197() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " void foo() {}\n" + + "}", + "p1/B.java", + "package p1;\n" + + "public class B extends p2.C {\n" + + " public static int foo() { return 0; }\n" + + "}", + "p2/C.java", + "package p2;\n" + + "public class C extends p1.A {\n" + + " public int foo() { return 1; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p1\\B.java (at line 3)\n" + + " public static int foo() { return 0; }\n" + + " ^^^^^\n" + + "This static method cannot hide the instance method from A\n" + + "----------\n" + + "2. ERROR in p1\\B.java (at line 3)\n" + + " public static int foo() { return 0; }\n" + + " ^^^^^\n" + + "This static method cannot hide the instance method from C\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p2\\C.java (at line 3)\n" + + " public int foo() { return 1; }\n" + + " ^^^^^\n" + + "The method C.foo() does not override the inherited method from A since it is private to a different package\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284948 +public void test198() { + if (new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6) return; + + this.runConformTest( + new String[] { + "MyAnnotation.java", + "@interface MyAnnotation {\n" + + " MyEnum value();\n" + + "}", + "MyClass.java", + "public class MyClass implements MyInterface {\n" + + " @Override public void foo() {}\n" + + "}", + "MyEnum.java", + "enum MyEnum implements Runnable {\n" + + " G {\n" + + " @Override public void methodA() {\n" + + " new Runnable() {\n" + + " @Override public void run() {}\n" + + " };\n" + + " }\n" + + " },\n" + + " D {\n" + + " @Override public void methodA() {}\n" + + " },\n" + + " A {\n" + + " @Override public void methodA() {}\n" + + " @Override public void methodB() {}\n" + + " },\n" + + " B {\n" + + " @Override public void methodA() {}\n" + + " },\n" + + " C {\n" + + " @Override public void methodA() {}\n" + + " @Override public void methodB() {}\n" + + " },\n" + + " E {\n" + + " @Override public void methodA() {}\n" + + " },\n" + + " F {\n" + + " @Override public void methodA() {}\n" + + " };\n" + + " private MyEnum() {}\n" + + " public void methodA() {}\n" + + " public void methodB() {}\n" + + " @Override public void run() {}\n" + + "}", + "MyInterface.java", + "interface MyInterface {\n" + + " @MyAnnotation(MyEnum.D) public void foo();\n" + + "}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284785 +public void test199() { + this.runConformTest( + new String[] { + "Bar.java", + "public interface Bar {\n" + + " void addError(String message, Object... arguments);\n" + + " void addError(Throwable t);\n" + + "}", + }, + "" + ); + this.runConformTest( + false, + new String[] { + "Foo.java", + "public class Foo {\n" + + " void bar(Bar bar) {\n" + + " bar.addError(\"g\");\n" + + " }\n" + + "}" + }, + "", + "", + "", + JavacTestOptions.SKIP + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285088 +public void test200() { + String errorMessage = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int foo(Collection bar) { return 0; }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(Collection) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " int foo(Collection bar) { return 0; }\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " double foo(Collection bar) {return 0; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(Collection) is the same as another method in type X\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "class X {\n" + + " int foo(Collection bar) { return 0; }\n" + + " double foo(Collection bar) {return 0; }\n" + + "}" + }, + errorMessage + ); +/* javac 7 +X.java:4: foo(Collection) is already defined in X + double foo(Collection bar) {return 0; } + ^ +1 error + */ +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=286228 +public void test201() { + this.runConformTest( + new String[] { + "A.java", + "interface I {}\n" + + "interface J { J get(); }\n" + + "interface K> { T2 get(); }\n" + + "interface A & J> extends J {}\n" + + "interface B & K> extends J {}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=284280 +public void test202() { + this.runConformTest( + new String[] { + "SubClass.java", + "interface MyInterface {\n" + + " String testMe(T0 t);\n" + + "}\n" + + "abstract class AbstractSuperClass implements MyInterface {\n" + + " public String testMe(T1 o) { return null; }\n" + + "}\n" + + "class SubClass extends AbstractSuperClass {\n" + + " @Override public String testMe(SubClass o) {\n" + + " return super.testMe(o);\n" + + " }\n" + + "}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=292240 +public void test203() { + this.runConformTest( + new String[] { + "X.java", + "interface I {}\n" + + "interface Y extends java.util.Comparator {\n" + + " public int compare(T o1, T o2);\n" + + "}\n" + + "class X implements Y {\n" + + " public int compare(Object o1, Object o2) {\n" + + " return compare((I) o1, (I) o2);\n" + + " }\n" + + " public int compare(I o1, I o2) { return 0; }\n" + + "}" + }, + "" + ); +} +// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=293615 (bad name clash error) +// No user vs user clash or user vs synthetic clash in this test +public void test204() { + this.runConformTest( + new String[] { + "OverrideBug.java", + "import java.util.List;\n" + + "interface Map {\n" + + " public V put(K key, V value);\n" + + "}\n" + + "public class OverrideBug implements Map> {\n" + + "public List put(final K arg0, final List arg1) {\n" + + " return null;\n" + + "}\n" + + "public List put(final K arg0, final V arg1) {\n" + + " return null;\n" + + "}\n" + + "}" + }, + ""); +} +// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=293615 (bad name clash error) +// verify that we report user vs bridge clash properly. +public void test204a() { + this.runNegativeTest( + new String[] { + "OverrideBug.java", + "import java.util.List;\n" + + "interface Map {\n" + + " public V put(K key, V value);\n" + + "}\n" + + "public class OverrideBug implements Map> {\n" + + "public List put(final K arg0, final List arg1) {\n" + + " return null;\n" + + "}\n" + + "public V put(final K arg0, final V arg1) {\n" + + " return null;\n" + + "}\n" + + "}" + }, + "----------\n" + + "1. ERROR in OverrideBug.java (at line 9)\n" + + " public V put(final K arg0, final V arg1) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method put(K, V) of type OverrideBug has the same erasure as put(K, V) of type Map but does not override it\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=298362 +public void test205() { + this.runConformTest( + new String[] { + "Tester.java", + "import java.lang.reflect.Method;\n" + + "\n" + + "public class Tester {\n" + + "\n" + + " public static interface Converter {\n" + + " T convert(String input);\n" + + " }\n" + + "\n" + + " public static abstract class EnumConverter> implements Converter> {\n" + + " public final T convert(String input) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static class SomeEnumConverter extends EnumConverter {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " Method m = SomeEnumConverter.class.getMethod(\"convert\", String.class);\n" + + " System.out.println(m.getGenericReturnType());\n" + + " }\n" + + "\n" + + "}\n" + + }, + "T"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=298362 (variation) +public void test206() { + this.runConformTest( + new String[] { + "Tester.java", + "import java.lang.reflect.Method;\n" + + "\n" + + "public class Tester {\n" + + "\n" + + " public static interface Converter {\n" + + " T convert(String input);\n" + + " }\n" + + "\n" + + " public static abstract class EnumConverter> implements Converter {\n" + + " public final T convert(String input) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static class SomeEnumConverter extends EnumConverter {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " Method m = SomeEnumConverter.class.getMethod(\"convert\", String.class);\n" + + " System.out.println(m.getGenericReturnType());\n" + + " }\n" + + "\n" + + "}\n" + + }, + "T"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=298362 (variation) +// Note that this test prints "T" with javac5 and "class java.lang.Object with javac 6,7 +public void test207() { + this.runConformTest( + new String[] { + "Tester.java", + "import java.lang.reflect.Method;\n" + + "\n" + + "public class Tester {\n" + + "\n" + + " public static interface Converter {\n" + + " T convert(String input);\n" + + " }\n" + + "\n" + + " public static abstract class EnumConverter, K> implements Converter {\n" + + " public final T convert(K input) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "\n" + + " public static class SomeEnumConverter extends EnumConverter {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " Method m = SomeEnumConverter.class.getMethod(\"convert\", String.class);\n" + + " System.out.println(m.getGenericReturnType());\n" + + " }\n" + + "\n" + + "}\n" + + }, + "class java.lang.Object"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=288658, make sure a bridge method +// is generated when a public method is inherited from a non-public class into a +// public class. +public void test208() { + this.runConformTest( + new String[] { + "Test.java", + "import java.lang.annotation.Annotation;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.reflect.Method;\n"+ + "\n"+ + "public class Test extends Super {\n"+ + " public static void main(String[] args) {\n"+ + " try {\n"+ + " Method m = Test.class.getMethod(\"setFoo\", String.class);\n"+ + " Annotation a = m.getAnnotation(Anno.class);\n"+ + " System.out.println(\"Annotation was \" + (a == null ? \"not \" : \"\") +\n"+ + "\"found\");\n"+ + " } catch (Exception e) {\n"+ + " e.printStackTrace();\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Super {\n"+ + " @Anno\n"+ + " public void setFoo(String foo) {}\n"+ + "}\n"+ + "\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@interface Anno {\n"+ + "\n"+ + "}\n" + }, + "Annotation was found"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=288658, make sure a bridge method +// is generated when a public method is inherited from a non-public class into a +// public class. +public void test208a() { + this.runConformTest( + new String[] { + "Test.java", + "import java.lang.annotation.Annotation;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.reflect.Method;\n"+ + "\n"+ + "public class Test extends Super {\n"+ + " public void setFoo() {}\n" + + " public static void main(String[] args) {\n"+ + " try {\n"+ + " Method m = Test.class.getMethod(\"setFoo\", String.class);\n"+ + " Annotation a = m.getAnnotation(Anno.class);\n"+ + " System.out.println(\"Annotation was \" + (a == null ? \"not \" : \"\") +\n"+ + "\"found\");\n"+ + " } catch (Exception e) {\n"+ + " e.printStackTrace();\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Super {\n"+ + " @Anno\n"+ + " public void setFoo(String foo) {}\n"+ + "}\n"+ + "\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@interface Anno {\n"+ + "\n"+ + "}\n" + }, + "Annotation was found"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=322001 +public void test209() { + this.runNegativeTest( + new String[] { + "Concrete.java", + "class Bar extends Zork {}\n" + + "class Foo {}\n" + + "\n" + + "interface Function {\n" + + " T apply(F f);\n" + + "}\n" + + "interface Predicate {\n" + + " boolean apply(T t);\n" + + "}\n" + + "\n" + + "public class Concrete implements Predicate, Function {\n" + + " public Boolean apply(Bar two) {\n" + + " return null;\n" + + " }\n" + + " public boolean apply(Foo foo) {\n" + + " return false;\n" + + " }\n" + + + "}\n" + }, + "----------\n" + + "1. ERROR in Concrete.java (at line 1)\n" + + " class Bar extends Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=321548 +public void test210() { + this.runNegativeTest( + new String[] { + "ErasureTest.java", + "interface Interface1 {\n" + + " public void hello(T greeting);\n" + + "}\n" + + "interface Interface2 {\n" + + " public int hello(T greeting);\n" + + "}\n" + + "public class ErasureTest extends Zork implements Interface1, Interface2 {\n" + + " public void hello(String greeting) { }\n" + + " public int hello(Double greeting) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in ErasureTest.java (at line 7)\n" + + " public class ErasureTest extends Zork implements Interface1, Interface2 {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=83162 +public void test211() { + this.runNegativeTest( + new String[] { + "SomeClass.java", + "interface Equivalent {\n" + + " boolean equalTo(T other);\n" + + "}\n" + + "\n" + + "interface EqualityComparable {\n" + + " boolean equalTo(T other);\n" + + "}\n" + + "\n" + + "public class SomeClass implements Equivalent, EqualityComparable {\n" + + " public boolean equalTo(String other) {\n" + + " return true;\n" + + " }\n" + + " public boolean equalTo(Integer other) {\n" + + " return true;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in SomeClass.java (at line 9)\n" + + " public class SomeClass implements Equivalent, EqualityComparable {\n" + + " ^^^^^^^^^\n" + + "Name clash: The method equalTo(T) of type EqualityComparable has the same erasure as equalTo(T) of type Equivalent but does not override it\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=323693 +public void test212() { + this.runNegativeTest( + new String[] { + "Derived.java", + "class Base {\n" + + " T foo(T x) {\n" + + " return x;\n" + + " }\n" + + "}\n" + + "interface Interface{\n" + + " T foo(T x);\n" + + "}\n" + + "public class Derived extends Base implements Interface {\n" + + " public Integer foo(Integer x) {\n" + + " return x;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Derived.java (at line 9)\n" + + " public class Derived extends Base implements Interface {\n" + + " ^^^^^^^\n" + + "Name clash: The method foo(T) of type Interface has the same erasure as foo(T) of type Base but does not override it\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850 +public void test213() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "Y.java", + "public abstract class Y implements I {\n" + + " public final Y foo(Object o, J j) {\n" + + " return null;\n" + + " }\n" + + " public final void bar(Object o, J j, Y y) {\n" + + " }\n" + + "}", + "I.java", + "public interface I {\n" + + " public S foo(Object o, J j);\n" + + " public void bar(Object o, J j, S s);\n" + + "}", + "J.java", + "public interface J {}" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public Object foo() {\n" + + " return new Y() {};\n" + + " }\n" + + "}" + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850 +public void test213a() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "Y.java", + "public abstract class Y implements I {\n" + + " public final Y foo(Object o, J> j) {\n" + + " return null;\n" + + " }\n" + + " public final void bar(Object o, J j, Y y) {\n" + + " }\n" + + "}", + "I.java", + "public interface I {\n" + + " public S foo(Object o, J> j);\n" + + " public void bar(Object o, J j, S s);\n" + + "}", + "J.java", + "public interface J {}" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public Object foo() {\n" + + " return new Y() {};\n" + + " }\n" + + "}" + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850 +public void test213b() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "ConsoleSession.java", + "public abstract class ConsoleSession implements ServiceFactory {\n" + + " public final void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {\n" + + " }\n" + + " \n" + + " public final Object getService(Bundle bundle, ServiceRegistration registration) {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "\n" + + "class Bundle {}\n" + + "\n" + + "interface ServiceFactory {\n" + + " public void ungetService(Bundle b, ServiceRegistration registration, S service);\n" + + " public S getService(Bundle bundle, ServiceRegistration registration);\n" + + "}\n" + + "\n" + + "interface ServiceRegistration {\n" + + "\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "OSGiConsole.java", + "public class OSGiConsole {\n" + + " OSGiConsole() {\n" + + " new ConsoleSession() {\n" + + " };\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850 +public void test213c() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "ConsoleSession.java", + "public abstract class ConsoleSession implements ServiceFactory {\n" + + " public final void ungetService(Bundle bundle, ServiceRegistration registration, ConsoleSession service) {\n" + + " }\n" + + " \n" + + " public final ConsoleSession getService(Bundle bundle, ServiceRegistration registration) {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "\n" + + "class Bundle {}\n" + + "\n" + + "interface ServiceFactory {\n" + + " public void ungetService(Bundle b, ServiceRegistration registration, S service);\n" + + " public S getService(Bundle bundle, ServiceRegistration registration);\n" + + "}\n" + + "\n" + + "interface ServiceRegistration {\n" + + "\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "OSGiConsole.java", + "public class OSGiConsole {\n" + + " OSGiConsole() {\n" + + " new ConsoleSession() {\n" + + " };\n" + + " }\n" + + "}\n", + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +public void test326354() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y implements I {\n" + + " public static void main(String[] args) {\n" + + " ((I) new X()).foo(null);\n" + + " }\n" + + "}\n" + + "\n" + + "interface I {\n" + + " public void foo(I i);\n" + + "}\n" + + " \n" + + "abstract class Y {\n" + + " public void foo(T t) {}\n" + + "}\n" + }, + "" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328827 +public void test328827() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "Map.java", + "public interface Map {}\n", + + "EventProperties.java", + "public class EventProperties implements Map {}\n", + + "Event.java", + "public class Event {\n" + + " public Event(Map properties) {}\n" + + "}" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + this.runConformTest( + new String[] { + "Map.java", + "public interface Map {}\n", + + "X.java", + "public class X {\n" + + " public void start() {\n" + + " Event event = new Event(new EventProperties());\n" + + " }\n" + + "}" + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=329584 +public void test329584() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "I.java", + "public interface I {\n" + + " void foo(Object o[], Dictionary dict);\n" + + "}", + "Dictionary.java", + "public class Dictionary {}\n", + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {\n" + + " public void foo(Object o[], Dictionary dict) {}\n" + + "}", + "Dictionary.java", + "public class Dictionary {}\n", + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=329588 +public void test329588() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public O foo() {\n" + + " return null;\n" + + " }\n" + + "}", + "O.java", + "public class O {}\n", + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(A a) {\n" + + " O o = (O) a.foo();\n" + + " System.out.println(o);\n" + + " }\n" + + "}", + "O.java", + "public class O {}\n", + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=330445 +public void test330445() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "Y.java", + "import java.util.Map;\n" + + "public class Y {\n" + + " static void foo(Map map) {\n" + + " }\n" + + "}", + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.util.Properties;\n" + + "public class X {\n" + + " static void bar(Object[] args) {\n" + + " Y.foo(new Properties());\n" + + " }\n" + + "}", + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=330435 +public void test330435() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public static B asList(T... tab) {\n" + + " return null;\n" + + " }\n" + + "}", + "B.java", + "public interface B {\n" + + " T[] toArray(T[] tab);\n" + + "}\n", + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String[] foo(Object[] args) {\n" + + " String[] a = A.asList(args).toArray(new String[0]);\n" + + " return a;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " String[] a = A.asList(args).toArray(new String[0]);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object[] to String[]\n" + + "----------\n", + null, + false, + compilerOptions14); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=330264 +public void test330264() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "BundleContext.java", + "public interface BundleContext {\n" + + " S getService(ServiceReference reference);\n" + + "}\n", + "ServiceReference.java", + "public interface ServiceReference extends Comparable {}\n" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runNegativeTest( + new String[] { + "Activator.java", + "public class Activator {\n" + + " public void start(BundleContext context, ServiceReference ref) {\n" + + " Runnable r = context.getService(ref);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Activator.java (at line 3)\n" + + " Runnable r = context.getService(ref);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to Runnable\n" + + "----------\n", + null, + false, + compilerOptions14); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446 +public void test331446() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "Test.java", + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "\n" + + "public class Test {\n" + + " public static void assertEquals(String message,\n" + + " Comparator comparator, List expected, List actual) {\n" + + " if (expected.size() != actual.size()) {\n" + + " //failNotEquals(message, expected, actual);\n" + + " }\n" + + " for (int i = 0, l = expected.size(); i < l; i++) {\n" + + " assertEquals(message, comparator, expected.get(i), actual.get(i));\n" + + " }\n" + + " }\n" + + " public static void assertEquals(String message,\n" + + " Comparator comparator, T expected, T actual) {\n" + + " if (comparator.compare(expected, actual) == 0) {\n" + + " return;\n" + + " }\n" + + " //failNotEquals(message, expected, actual);\n" + + " }\n" + + "}\n" + + "" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Comparator;\n" + + "\n" + + "public class X {\n" + + " public static void testAmbiguity() {\n" + + " Comparator comparator = new Comparator() {\n" + + " \n" + + " public int compare(Object o1, Object o2) {\n" + + " return 0;\n" + + " }\n" + + " };\n" + + " Test.assertEquals(\"Test\", comparator, new ArrayList(), new ArrayList());\n" + + " }\n" + + "}\n" + + "", + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446 +public void test331446a() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_4); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4); + this.runConformTest( + new String[] { + "Test.java", + "import java.util.Comparator;\n" + + "import java.util.List;\n" + + "\n" + + "public class Test {\n" + + " public static void assertEquals(String message,\n" + + " Comparator comparator, List expected, List actual) {\n" + + " if (expected.size() != actual.size()) {\n" + + " //failNotEquals(message, expected, actual);\n" + + " }\n" + + " for (int i = 0, l = expected.size(); i < l; i++) {\n" + + " assertEquals(message, comparator, expected.get(i), actual.get(i));\n" + + " }\n" + + " }\n" + + " public static void assertEquals(String message,\n" + + " Comparator comparator, Object expected, Object actual) {\n" + + " if (comparator.compare(expected, actual) == 0) {\n" + + " return;\n" + + " }\n" + + " //failNotEquals(message, expected, actual);\n" + + " }\n" + + "}\n" + + "" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Comparator;\n" + + "\n" + + "public class X {\n" + + " public static void testAmbiguity() {\n" + + " Comparator comparator = new Comparator() {\n" + + " \n" + + " public int compare(Object o1, Object o2) {\n" + + " return 0;\n" + + " }\n" + + " };\n" + + " Test.assertEquals(\"Test\", comparator, new ArrayList(), new ArrayList());\n" + + " }\n" + + "}\n" + + "", + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446 (all 1.4) +public void test331446b() { + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4); + this.runConformTest( + new String[] { + "Project.java", + "class List{}\n" + + "public class Project {\n" + + " static void foo(List expected) {}\n" + + " public static void foo(Object expected) {}\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions14, + null); + + this.runConformTest( + new String[] { + "Client.java", + "public class Client {\n" + + " Client(List l) {\n" + + " Project.foo(l);\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446 (1.4/1.5 mix) +public void test331446c() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "Project.java", + "class List {}\n" + + "public class Project {\n" + + " static void foo(List expected) {}\n" + + " public static void foo(T expected) {}\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "Client.java", + "public class Client {\n" + + " Client(List l) {\n" + + " Project.foo(l);\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446 (all 1.5) +public void test331446d() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "Project.java", + "class List {}\n" + + "public class Project {\n" + + " static void foo(List expected) {}\n" + + " public static void foo(T expected) {}\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions15, + null); + this.runConformTest( + new String[] { + "Client.java", + "public class Client {\n" + + " Client(List l) {\n" + + " Project.foo(l);\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null, + compilerOptions15, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446 +public void test1415Mix() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "Abstract.java", + "abstract class Generic {\n" + + " abstract void foo(T t);\n" + + "}\n" + + "public abstract class Abstract extends Generic {\n" + + "}" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runNegativeTest( + new String[] { + "Concrete.java", + "public class Concrete extends Abstract {\n" + + "}", + }, + "----------\n" + + "1. ERROR in Concrete.java (at line 1)\n" + + " public class Concrete extends Abstract {\n" + + " ^^^^^^^^\n" + + "The type Concrete must implement the inherited abstract method Generic.foo(String)\n" + + "----------\n", + null, + false, + compilerOptions14); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=331446 +public void test1415Mix2() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "Abstract.java", + "abstract class Generic {\n" + + " abstract void foo(T t);\n" + + "}\n" + + "public abstract class Abstract extends Generic {\n" + + "}" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "Concrete.java", + "public class Concrete extends Abstract {\n" + + " void foo(String s) {}\n" + + "}", + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332744 (all 1.5+) +public void test332744() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "EList.java", + "import java.util.List;\n" + + "public interface EList extends List {\n" + + "}\n", + "FeatureMap.java", + "public interface FeatureMap extends EList {\n" + + " interface Entry {\n" + + " }\n" + + "}\n", + "InternalEList.java", + "public interface InternalEList extends EList {\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + this.runConformTest( + new String[] { + "Client.java", + "public class Client {\n" + + " Client(FeatureMap fm) {\n" + + " InternalEList e = (InternalEList) fm;\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null, + compilerOptions15, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332744 (1.4/1.5 mix) +public void test332744b() { + Map compilerOptions15 = getCompilerOptions(); + compilerOptions15.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, CompilerOptions.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + compilerOptions15.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + this.runConformTest( + new String[] { + "EList.java", + "import java.util.List;\n" + + "public interface EList extends List {\n" + + "}\n", + "FeatureMap.java", + "public interface FeatureMap extends EList {\n" + + " interface Entry {\n" + + " }\n" + + "}\n", + "InternalEList.java", + "public interface InternalEList extends EList {\n" + + "}\n" + }, + "", + null, + true, + null, + compilerOptions15, + null); + + Map compilerOptions14 = getCompilerOptions(); + compilerOptions14.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2); + compilerOptions14.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4); + compilerOptions14.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3); + compilerOptions14.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.IGNORE); + this.runConformTest( + new String[] { + "Client.java", + "public class Client {\n" + + " Client(FeatureMap fm) {\n" + + " InternalEList e = (InternalEList) fm;\n" + + " }\n" + + "}\n" + }, + "", + null, + false, + null, + compilerOptions14, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=339447 +public void test339447() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X implements Cloneable {\n" + + " public synchronized X clone() {\n" + + " return this;\n" + + " }\n" + + "}", // ================= + }, + ""); + // ensure bridge methods have target method modifiers, and inherited thrown exceptions + String expectedOutput = + " public bridge synthetic java.lang.Object clone() throws java.lang.CloneNotSupportedException;"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// 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 {\n" + + " boolean equalTo(T other);\n" + + "}\n" + + "public class X extends Base implements EqualityComparable {\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 {\n" + + " ^\n" + + "Name clash: The method equalTo(T) of type EqualityComparable 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 {}\n" + + "interface I {\n" + + " void foo(X p);\n" + + "}\n" + + "interface J extends I {\n" + + " void foo(X p);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " void foo(X p);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(X) of type J has the same erasure as foo(X) 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 extends DTOAdapter {\n" + + " public A convert(B b);\n" + + "}\n", + "DTOAdapter.java", + "public interface DTOAdapter {\n" + + " public B convert(A a);\n" + + "}\n", + "TestAdapter.java", + "public class TestAdapter implements TwoWayDTOAdapter {\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 has the same erasure as convert(A) of type DTOAdapter 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 {\n" + + " void f(String s) {}\n" + + "}\n" + + "class B extends A {\n" + + " void f(T t) {}\n" + + "}\n" + + "public class X extends B {\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 {\n" + + " ^\n" + + "Duplicate methods named f with the parameters (T) and (String) are inherited from the types B and A\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 {\n" + + " void f(String s);\n" + + "}\n" + + "interface B extends A {\n" + + " void f(T t);\n" + + "}\n" + + "public class X implements B {\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( + false, + new String[] { + "X.java", + "class A {\n" + + " void f(String s) {}\n" + + "}\n" + + "interface B {\n" + + " void f(T t);\n" + + "}\n" + + "public class X extends A implements B {\n" + + " public void f(String t) {\n" + + " }\n" + + "}\n" + }, + null, + null, + "----------\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", + Excuse.EclipseHasSomeMoreWarnings); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=346029 +public void test346029d() throws Exception { + this.runNegativeTest( + false, + new String[] { + "X.java", + "class A {\n" + + " void f(T s) {}\n" + + "}\n" + + "interface B {\n" + + " void f(String t);\n" + + "}\n" + + "public class X extends A implements B {\n" + + " public void f(String t) {\n" + + " }\n" + + "}\n" + }, + null, + null, + "----------\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", + Excuse.EclipseHasSomeMoreWarnings); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346029 +public void test346029e() throws Exception { + this.runNegativeTest( + false, + new String[] { + "X.java", + "class A {\n" + + " void f(String s) {}\n" + + "}\n" + + "class B extends A {\n" + + " void f(T t) {}\n" + + "}\n" + + "public class X extends B {\n" + + " void f(String s) {\n" + + " }\n" + + "}\n" + }, + null, + null, + "----------\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", + Excuse.EclipseHasSomeMoreWarnings); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346029 +public void test346029f() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class A {\n" + + " void f(String s) {}\n" + + "}\n" + + "class B extends A {\n" + + " void f(T t) {}\n" + + "}\n" + + "public class X extends B {\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\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353089 +public void test353089() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface A {\n" + + "int get(List l);\n" + + "}\n" + + "interface B {\n" + + "int get(List l);\n" + + "}\n" + + "interface C extends A, B { \n" + + "int get(List l); // name clash error here\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"Built OK\");\n" + + " }\n" + + "}" + }, + "Built OK"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=353089 +public void test353089b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " void a(List i, List j);\n" + + " void b(List i, List j);\n" + + " void c(List i, List j);\n" + + "}\n" + + "interface X extends I {\n" + + " public void a(List i, List j);\n" + + " public void b(List i, List j);\n" + + " public void c(List i, List j);\n" + + " public void d(Zork z);\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void c(List i, List j);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public void a(List i, List j);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method a(List, List) of type X has the same erasure as a(List, List) of type I but does not override it\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " public void a(List i, List j);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " public void b(List i, List j);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " public void b(List i, List j);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 10)\n" + + " public void c(List i, List j);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "7. WARNING in X.java (at line 10)\n" + + " public void c(List i, List j);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "8. ERROR in X.java (at line 11)\n" + + " public void d(Zork z);\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=353089 +public void test353089c() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface IFtest {\n" + + " public void doTest(Integer i, List pList, List pList2);\n" + + "}\n" + + "interface Impl extends IFtest {\n" + + " public void doTest(Integer i, List iList, List iList2);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public void doTest(Integer i, List iList, List iList2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method doTest(Integer, List, List) of type Impl has the same erasure as doTest(Integer, List, List) of type IFtest but does not override it\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public void doTest(Integer i, List iList, List iList2);\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 +public void testBug317719() throws Exception { + String output = this.complianceLevel == ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public T foo() { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public T foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " public T foo() { return null; }\n" + + " ^^^\n" + + "Set is a raw type. References to generic type Set should be parameterized\n" + + "----------\n" + + "4. WARNING in X.java (at line 5)\n" + + " public T foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n": + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public T foo() { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public T foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " public T foo() { return null; }\n" + + " ^^^\n" + + "Set is a raw type. References to generic type Set should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " public T foo() { return null; }\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "5. 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", + "import java.util.List;\n" + + "import java.util.Set;\n" + + "class X {\n" + + " public T foo() { return null; }\n" + + " public T foo() { return null; }\n" + + " Zork z;\n" + + "}\n" + }, + output); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 +public void testBug317719a() throws Exception { + String output = this.complianceLevel == ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public Integer same(List a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method same(List) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " public String same(List b) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method same(List) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public Integer same(List a) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method same(List) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public String same(List b) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method same(List) is the same as another method in type X\n" + + "----------\n" + + "3. 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", + "import java.util.List;\n" + + "import java.util.Set;\n" + + "class X {\n" + + " public Integer same(List a) { return null; }\n" + + " public String same(List b) { return null; }\n" + + " Zork z;\n" + + "}\n" + }, + output); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 +public void testBug317719b() throws Exception { + String output = this.complianceLevel == ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static String doIt(final List arg) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt(List) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public static CharSequence doIt(final List arg) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt(List) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public static String doIt(final List arg) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt(List) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public static CharSequence doIt(final List arg) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt(List) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class X {\n" + + " public static String doIt(final List arg) { return null; }\n" + + " public static CharSequence doIt(final List arg) { return null; }\n" + + " Zork z;\n" + + "}\n" + }, + output); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 +public void testBug317719c() throws Exception { + String output = this.complianceLevel == ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " protected static T same(Collection p_col) { return null; }\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " protected static T same(Collection p_col) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method same(Collection) is the same as another method in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " protected static T same(Collection p_col) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method same(Collection) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n": + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " protected static T same(Collection p_col) { return null; }\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " protected static T same(Collection p_col) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method same(Collection) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " protected static T same(Collection p_col) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method same(Collection) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "class X {\n" + + " protected static T same(Collection p_col) { return null; }\n" + + " protected static T same(Collection p_col) { return null; }\n" + + " Zork z;\n" + + "}\n" + }, + output); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 +public void testBug317719d() throws Exception { + String output = this.complianceLevel == ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static boolean foo(List x) { return true; }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(List) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public static int foo(List x) { return 2; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(List) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public static boolean foo(List x) { return true; }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(List) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public static int foo(List x) { return 2; }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method foo(List) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class X {\n" + + " public static boolean foo(List x) { return true; }\n" + + " public static int foo(List x) { return 2; }\n" + + " Zork z;\n" + + "}\n" + }, + output); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 +public void testBug317719e() throws Exception { + String output = this.complianceLevel == ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public String getFirst (ArrayList ss) { return ss.get(0); }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method getFirst(ArrayList) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public Integer getFirst (ArrayList ss) { return ss.get(0); }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method getFirst(ArrayList) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public String getFirst (ArrayList ss) { return ss.get(0); }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method getFirst(ArrayList) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public Integer getFirst (ArrayList ss) { return ss.get(0); }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method getFirst(ArrayList) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "class X {\n" + + " public String getFirst (ArrayList ss) { return ss.get(0); }\n" + + " public Integer getFirst (ArrayList ss) { return ss.get(0); }\n" + + " Zork z;\n" + + "}\n" + }, + output); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 +public void testBug317719f() throws Exception { + String output = this.complianceLevel == ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static X forAccountSet(List list) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method forAccountSet(List) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " public static X forAccountSet(List list) { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " public static ChildX forAccountSet(List list) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method forAccountSet(List) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public static X forAccountSet(List list) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method forAccountSet(List) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " public static X forAccountSet(List list) { return null; }\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " public static ChildX forAccountSet(List list) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method forAccountSet(List) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class X {\n" + + " public static X forAccountSet(List list) { return null; }\n" + + " public static ChildX forAccountSet(List list) { return null; }\n" + + " Zork z;\n" + + "}\n" + + "class ChildX extends X{}\n" + }, + output); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 +public void testBug317719g() throws Exception { + String output = this.complianceLevel == ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public static int[] doIt(Collection col) { return new int[1]; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt(Collection) is the same as another method in type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public static int[][] doIt(Collection col) { return new int[0][0]; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt(Collection) is the same as another method in type X\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " public int[] doIt2(Collection col) { return new int[0]; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt2(Collection) is the same as another method in type X\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " public int[][] doIt2(Collection col) { return new int[0][0]; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt2(Collection) is the same as another method in type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n": + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public static int[] doIt(Collection col) { return new int[1]; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt(Collection) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public static int[][] doIt(Collection col) { return new int[0][0]; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt(Collection) is the same as another method in type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public int[] doIt2(Collection col) { return new int[0]; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt2(Collection) is the same as another method in type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " public int[][] doIt2(Collection col) { return new int[0][0]; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method doIt2(Collection) is the same as another method in type X\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "class X {\n" + + " public static int[] doIt(Collection col) { return new int[1]; }\n" + + " public static int[][] doIt(Collection col) { return new int[0][0]; }\n" + + " public int[] doIt2(Collection col) { return new int[0]; }\n" + + " public int[][] doIt2(Collection col) { return new int[0][0]; }\n" + + " Zork z;\n" + + "}\n" + + "class ChildX extends X{}\n" + }, + output); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719 +public void testBug317719h() throws Exception { + String output = this.complianceLevel == ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. WARNING in Test.java (at line 3)\n" + + " public class Test extends HashMap> {\n" + + " ^^^^\n" + + "The serializable class Test does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in Test.java (at line 4)\n" + + " public Collection put(Key k, Value v) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method put(Key, Value) of type Test has the same erasure as put(K, V) of type HashMap but does not override it\n" + + "----------\n" + + "3. WARNING in Test.java (at line 5)\n" + + " public Collection get(Key k) { return null; }\n" + + " ^^^^^^^^^^\n" + + "Name clash: The method get(Key) of type Test has the same erasure as get(Object) of type HashMap but does not override it\n" + + "----------\n" + + "4. ERROR in Test.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n": + "----------\n" + + "1. WARNING in Test.java (at line 3)\n" + + " public class Test extends HashMap> {\n" + + " ^^^^\n" + + "The serializable class Test does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in Test.java (at line 4)\n" + + " public Collection put(Key k, Value v) { return null; }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method put(Key, Value) of type Test has the same erasure as put(K, V) of type HashMap but does not override it\n" + + "----------\n" + + "3. ERROR in Test.java (at line 5)\n" + + " public Collection get(Key k) { return null; }\n" + + " ^^^^^^^^^^\n" + + "Name clash: The method get(Key) of type Test has the same erasure as get(Object) of type HashMap but does not override it\n" + + "----------\n" + + "4. ERROR in Test.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "Test.java", + "import java.util.Collection;\n" + + "import java.util.HashMap;\n" + + "public class Test extends HashMap> {\n" + + " public Collection put(Key k, Value v) { return null; }\n" + + " public Collection get(Key k) { return null; }\n" + + " Zork z;\n" + + "}\n" + }, + output); +} +public void test345949a() throws Exception { + if (new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_7) return; + this.runNegativeTest( + new String[] { + "Sub.java", + "class A {}\n" + + "class Super {\n" + + " public static void foo(A p) {}\n" + + "}\n" + + "public class Sub extends Super {\n" + + " public static void foo(A p) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Sub.java (at line 6)\n" + + " public static void foo(A p) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Name clash: The method foo(A) of type Sub has the same erasure as foo(A) of type Super but does not hide it\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=355838 +public void testBug355838() throws Exception { + String output = + "----------\n" + + "1. ERROR in ErasureBug.java (at line 4)\n" + + " public String output(List integers) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method output(List) is the same as another method in type ErasureBug\n" + + "----------\n" + + "2. ERROR in ErasureBug.java (at line 7)\n" + + " public String output(List doubles) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Erasure of method output(List) is the same as another method in type ErasureBug\n" + + "----------\n" + + "3. WARNING in ErasureBug.java (at line 7)\n" + + " public String output(List doubles) {\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. WARNING in ErasureBug.java (at line 10)\n" + + " public static void main(String[] args) { new ErasureBug().output(new ArrayList()); }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type ArrayList needs unchecked conversion to conform to List\n" + + "----------\n" + + "5. WARNING in ErasureBug.java (at line 10)\n" + + " public static void main(String[] args) { new ErasureBug().output(new ArrayList()); }\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "ErasureBug.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class ErasureBug {\n" + + " public String output(List integers) {\n" + + " return \"1\";\n" + + " }\n" + + " public String output(List doubles) {\n" + + " return \"2\";\n" + + " }\n" + + " public static void main(String[] args) { new ErasureBug().output(new ArrayList()); }\n" + + "}\n" + }, + output); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=288658, make sure a bridge method +// is generated when a public method is inherited from a non-public class into a +// public class if the non public class happens to be defined in a named package. +public void test288658() { + this.runConformTest( + new String[] { + "pkg/Test.java", + "package pkg;\n" + + "import java.lang.annotation.Annotation;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.reflect.Method;\n"+ + "\n"+ + "public class Test extends Super {\n"+ + " public static void main(String[] args) {\n"+ + " try {\n"+ + " Method m = Test.class.getMethod(\"setFoo\", String.class);\n"+ + " Annotation a = m.getAnnotation(Anno.class);\n"+ + " System.out.println(\"Annotation was \" + (a == null ? \"not \" : \"\") +\n"+ + "\"found\");\n"+ + " } catch (Exception e) {\n"+ + " e.printStackTrace();\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Super {\n"+ + " @Anno\n"+ + " public void setFoo(String foo) {}\n"+ + "}\n"+ + "\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@interface Anno {\n"+ + "\n"+ + "}\n" + }, + "Annotation was found"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=288658, make sure a bridge method +// is generated when a public method is inherited from a non-public class into a +// public class if the non public class happens to be defined in a named package. +public void test288658a() { + this.runConformTest( + new String[] { + "pkg/Test.java", + "package pkg;\n" + + "import java.lang.annotation.Annotation;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.reflect.Method;\n"+ + "\n"+ + "public class Test extends Super {\n"+ + " public void setFoo() {}\n" + + " public static void main(String[] args) {\n"+ + " try {\n"+ + " Method m = Test.class.getMethod(\"setFoo\", String.class);\n"+ + " Annotation a = m.getAnnotation(Anno.class);\n"+ + " System.out.println(\"Annotation was \" + (a == null ? \"not \" : \"\") +\n"+ + "\"found\");\n"+ + " } catch (Exception e) {\n"+ + " e.printStackTrace();\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Super {\n"+ + " @Anno\n"+ + " public void setFoo(String foo) {}\n"+ + "}\n"+ + "\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@interface Anno {\n"+ + "\n"+ + "}\n" + }, + "Annotation was found"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=354229 +public void test354229() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface A {\n" + + "int get(List l);\n" + + "}\n" + + "interface B {\n" + + "int get(List l);\n" + + "}\n" + + "interface C extends A, B { \n" + + "//int get(List l); // name clash error here\n" + + " Zork z;\n" + + "}\n" + }, + this.complianceLevel <= ClassFileConstants.JDK1_6 ? + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " interface C extends A, B { \n" + + " ^\n" + + "Name clash: The method get(List) of type B has the same erasure as get(List) of type A but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=354229 +public void test354229b() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface A {\n" + + "int get(List l);\n" + + "}\n" + + "interface B {\n" + + "int get(List l);\n" + + "}\n" + + "interface C extends A, B { \n" + + " int get(List l); // name clash error here\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " int get(List l); // name clash error here\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=354229 +public void test354229c() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n" + + " T e(Action p);\n" + + "}\n" + + "interface Y {\n" + + " S e(Action t);\n" + + "}\n" + + "interface E extends X, Y {\n" + + "}\n" + + "class Action {\n" + + " Zork z;\n" + + "}\n" + + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " interface E extends X, Y {\n" + + " ^\n" + + "Name clash: The method e(Action) of type Y has the same erasure as e(Action) of type X but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=354229 +public void test354229d() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n" + + " T e(Action p);\n" + + " S e(Action t);\n" + + "}\n" + + "class Action {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " T e(Action p);\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method e(Action) is the same as another method in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " S e(Action t);\n" + + " ^^^^^^^^^^^^^^\n" + + "Erasure of method e(Action) is the same as another method in type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384580, Apply changes in JLS 8.4.5 to calculation of duplicate method return types +public void testBug384580() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface X { List m(); }\n" + + "interface Y { List m(); }\n" + + "interface Z extends X, Y {} \n" + + "class Foo implements Z {\n" + + " public List m() {\n" + + " return null;\n" + + " }\n" + + " \n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " interface Z extends X, Y {} \n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " class Foo implements Z {\n" + + " ^^^\n" + + "The type Foo must implement the inherited abstract method Y.m()\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public List m() {\n" + + " ^^^\n" + + "Name clash: The method m() of type Foo has the same erasure as m() of type Y but does not override it\n" + + "----------\n"); +} +// https://bugs.eclipse.org/406928 - computation of inherited methods seems damaged (affecting @Overrides) +public void testBug406928() { + if (this.complianceLevel < ClassFileConstants.JDK1_6) return; + this.runConformTest( + new String[] { + "TestPointcut.java", + "interface MethodMatcher {\n"+ + " boolean matches();\n"+ + "}\n"+ + "abstract class StaticMethodMatcher implements MethodMatcher { }\n"+ + "abstract class StaticMethodMatcherPointcut extends StaticMethodMatcher { }\n"+ + "\n"+ + "class TestPointcut extends StaticMethodMatcherPointcut {\n"+ + " @Override\n"+ + " public boolean matches() { return false; } \n"+ + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/409473 - [compiler] JDT cannot compile against JRE 1.8 +// Test failed when running on a JRE 1.8 b90 +public void testBug409473() { + this.runConformTest( + new String[] { + "Foo.java", + "public abstract class Foo implements java.util.List { } " + }); +} +// https://bugs.eclipse.org/410325 - [1.7][compiler] Generified method override different between javac and eclipse compiler +public void testBug410325() { + runConformTest( + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " F3 f3 = new F3();\n" + + " SubSub sub = new SubSub();\n" + + " sub.foo(f3);\n" + + "\n" + + " Sub sub2 = sub;\n" + + " Base base = sub;\n" + + " sub2.foo(f3);\n" + + " base.foo(f3);\n" + + "\n" + + " F2 f2 = new F2();\n" + + " sub2.foo(f2);\n" + + " }\n" + + "\n" + + " public static class F1 {\n" + + " }\n" + + "\n" + + " public static class F2 extends F1 {\n" + + " }\n" + + "\n" + + " public static class F3 extends F2 {\n" + + " public void bar() {\n" + + " System.out.println(\"bar in F3\");\n" + + " }\n" + + " }\n" + + "\n" + + " public static abstract class Base {\n" + + " public abstract void foo(T bar);\n" + + " }\n" + + "\n" + + " public static abstract class Sub extends Base {\n" + + " @Override\n" + + " public void foo(F2 bar) {\n" + + " System.out.println(getClass().getSimpleName() + \": F2 + \"\n" + + " + bar.getClass().getSimpleName());\n" + + " }\n" + + " }\n" + + "\n" + + " public static class SubSub extends Sub {\n" + + " }\n" + + "}" + }); +} +// https://bugs.eclipse.org/410325 - [1.7][compiler] Generified method override different between javac and eclipse compiler +// test from duplicate bug 411811 +public void testBug411811() { + runConformTest( + new String[] { + "FaultyType.java", + " class ParamType {}\n" + + "\n" + + " abstract class AbstractType {\n" + + " public abstract void foo(T t);\n" + + " }\n" + + "\n" + + " abstract class SubAbstractType extends AbstractType {\n" + + " @Override public void foo(ParamType t) {}\n" + + " }\n" + + "\n" + + " class SubParamType extends ParamType {}\n" + + " \n" + + "public class FaultyType extends SubAbstractType {}" + }); +} +// https://bugs.eclipse.org/410325 - [1.7][compiler] Generified method override different between javac and eclipse compiler +// test from duplicate bug 415600 +public void testBug415600() { + runConformTest( + new String[] { + "A.java", + "import java.io.Reader;\n" + + "import java.io.StringReader;\n" + + "\n" + + "public abstract class A {\n" + + " protected abstract void create(E element);\n" + + "}\n" + + "\n" + + "abstract class B extends A {\n" + + " public void create(Reader element) { }\n" + + "}\n" + + "\n" + + "class C extends B { }\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=423849, [1.8][compiler] cannot implement java.nio.file.Path because of compiler name clash +public void test423849() { + runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.nio.file.Path;\n" + + "import java.nio.file.WatchEvent.Kind;\n" + + "import java.nio.file.WatchEvent.Modifier;\n" + + "import java.nio.file.WatchKey;\n" + + "import java.nio.file.WatchService;\n" + + "abstract class Y implements Path {\n" + + " public WatchKey register(WatchService watcher, Kind[] events, Modifier... modifiers) throws IOException {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }); +} +// assure that an inherited bridge method need not be repeated +public void testBug426546() { + runConformTest( + new String[] { + "C.java", + "class A {\n" + + " A getMe() { return null; }\n" + + "}\n" + + "class B extends A {\n" + + " B getMe() { return null; }\n" + + "}\n" + + "public class C extends B {\n" + + " C getMe() { return this; }\n" + + " public String toString() { return \"C\"; }\n" + + " public static void main(String[] args) {\n" + + " C c = new C();\n" + + " System.out.print(c.getMe());\n" + + " B b = c;\n" + + " System.out.print(b.getMe());\n" + + " A a = c;\n" + + " System.out.print(a.getMe()); \n" + + " }\n" + + "}\n" + }, + "CCC"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=438812, Missing bridge methods in indirect child classes with ECJ 3.10.0 +public void testBug438812() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "\n" + + "public interface A {\n" + + " Iterable getIterable();\n" + + "}\n" + + "\n" + + "class B implements A {\n" + + " public Collection getIterable() { return null; }\n" + + "}\n" + + "\n" + + "class C extends B {\n" + + " public List getIterable() { return null; }\n" + + "}", + }, + ""); + String expectedOutput = " public bridge synthetic java.lang.Iterable getIterable();"; + + File f = new File(OUTPUT_DIR + File.separator + "C.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=469454, The compiler generates wrong code during inheritance +public void testBug469454() throws Exception { + this.runConformTest( + new String[] { + "TestClass.java", + "public class TestClass {\n" + + " public static class A {\n" + + " public static A method() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public static class B extends A {\n" + + " public static B method() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(B.class.getDeclaredMethods().length);\n" + + " }\n" + + "}\n", + }, + "1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=469454, The compiler generates wrong code during inheritance +public void testBug469454a() throws Exception { + this.runNegativeTest( + new String[] { + "TestClass.java", + "public class TestClass {\n" + + " public static class A {\n" + + " public final A method() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public static class B extends A {\n" + + " @Override\n" + + " public B method() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(B.class.getDeclaredMethods().length);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in TestClass.java (at line 9)\n" + + " public B method() {\n" + + " ^^^^^^^^\n" + + "Cannot override the final method from TestClass.A\n" + + "----------\n", + null, + true, + null, + true, + false, + false); + String expectedOutput = " public bridge synthetic TestClass.A method();"; + + File f = new File(OUTPUT_DIR + File.separator + "TestClass$B.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index != -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index != -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=438812, Missing bridge methods in indirect child classes with ECJ 3.10.0 +public void testBug438812a() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "\n" + + "public abstract class A {\n" + + " abstract Iterable getIterable();\n" + + "}\n" + + "\n" + + "class B extends A {\n" + + " public Collection getIterable() { return null; }\n" + + "}\n" + + "\n" + + "class C extends B {\n" + + " public List getIterable() { return null; }\n" + + "}", + }, + ""); + String expectedOutput = " public bridge synthetic java.lang.Iterable getIterable();"; + + File f = new File(OUTPUT_DIR + File.separator + "C.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=461529, Abstract class extending interface with default impl won't compile, but does compile from cmd line +public void testBug461529() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; + this.runConformTest( + new String[] { + "foo/IBarable.java", + "package foo;\n" + + "public interface IBarable> {\n" + + " default IBar createBar() {\n" + + " throw new UnsupportedOperationException();\n" + + " }\n" + + "}\n", + "foo/IBar.java", + "package foo;\n" + + "public interface IBar> {\n" + + " T bar();\n" + + "}\n", + "foo/Foo.java", + "package foo;\n" + + "public abstract class Foo implements IBarable {\n" + + " public abstract static class Builder implements IBar {}\n" + + " @Override\n" + + " public abstract Builder createBar();\n" + + "}\n", + "foo/ChildFoo.java", + "package foo;\n" + + "public abstract class ChildFoo extends Foo {}\n" + }); +} +public void testBug467776_regression() { + if (this.complianceLevel < ClassFileConstants.JDK1_6) return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + runConformTest( + new String[] { + "ITeam.java", + "public interface ITeam {\n" + + " T getRole(Object o, Class clazz);\n" + + "}\n", + "Team.java", + "public class Team implements ITeam {\n" + + "\n" + + " @Override\n" + + " public T getRole(Object o, Class clazz) {\n" + + " return null;\n" + + " }\n" + + "}\n", + "MyTeam.java", + "public class MyTeam extends Team {\n" + + " @Override\n" + + " public T getRole(Object o, Class clazz) {\n" + + " return super.getRole(o, clazz);\n" + + " }\n" + + "}\n" + + }, + compilerOptions); +} +public void testBug500673() { + runNegativeTest( + new String[] { + "mfi.java", + "interface mfi {\n" + + " public transient void a(Throwable throwable);\n" + + "}\n", + "mfa.java", + "final class mfa implements mfi {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in mfi.java (at line 2)\n" + + " public transient void a(Throwable throwable);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Illegal modifier for the interface method a; only public & abstract are permitted\n" + : this.complianceLevel < ClassFileConstants.JDK9 ? + "Illegal modifier for the interface method a; only public, abstract, default, static and strictfp are permitted\n" : + "Illegal modifier for the interface method a; only public, private, abstract, default, static and strictfp are permitted\n" + ) + + "----------\n" + + "----------\n" + + "1. ERROR in mfa.java (at line 1)\n" + + " final class mfa implements mfi {\n" + + " ^^^\n" + + "The type mfa must implement the inherited abstract method mfi.a(Throwable)\n" + + "----------\n"); +} +public void testBug506653() { + runConformTest( + false, // flushOutputDirectory + new String[] { + "A.java", + " public class A {\n" + + " public class B {\n" + + " E bar(F x) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public class C extends B {\n" + + " @Override\n" + + " public String bar(Object x) {\n" + + " return \"Oops\";\n" + + " }\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new A().test();\n" + + " }\n" + + " void test() {\n" + + " B b = new C();\n" + + " try {\n" + + " Integer i = b.bar(1);\n" + + " } catch (ClassCastException cce) {\n" + + " System.out.print(\"cce\");\n" + + " }\n" + + " }\n" + + " }\n" + }, + "----------\n" + + "1. WARNING in A.java (at line 9)\n" + + " public String bar(Object x) {\n" + + " ^^^^^^\n" + + "Type safety: The return type String for bar(Object) from the type A.C needs unchecked conversion to conform to E from the type A.B\n" + + "----------\n", + "cce", + "", + JavacTestOptions.DEFAULT); +} +public void testBug536593() { + runConformTest( + new String[] { + "AbstractComp.java", + "public abstract class AbstractComp {\n" + + " protected abstract boolean isReadOnly();\n" + + "}\n", + "HasValue.java", + "public interface HasValue {\n" + + " boolean isReadOnly();\n" + + "}\n", + "Factory.java", + "public class Factory> {\n" + + "}\n" + }); +} +public void testBug536978_comment2() { + runNegativeTest( + new String[] { + "SimpleDemo.java", + "abstract interface AbstractResult {\n" + + " public abstract int test();\n" + + "}\n" + + "\n" + + "abstract class AbstractDemo {\n" + + " protected abstract Response test(Request request);\n" + + "}\n" + + "\n" + + "interface SimpleResult extends AbstractResult {};\n" + + "\n" + + "class Result1 implements SimpleResult {\n" + + " public int test() { return 1; }\n" + + "}\n" + + "class OtherResult implements AbstractResult {\n" + + " public int test() { return 2; }\n" + + "}\n" + + "\n" + + "public class SimpleDemo \n" + + "extends AbstractDemo {\n" + + "\n" + + " @Override\n" + + " protected SimpleResult test(AbstractResult request) {\n" + + " return new Result1();\n" + + " }\n" + + " \n" + + " public static void main(String... args) {\n" + + " AbstractDemo demo = new SimpleDemo();\n" + + " OtherResult result = demo.test(new OtherResult());\n" + + " }\n" + + "\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in SimpleDemo.java (at line 22)\n" + + " protected SimpleResult test(AbstractResult request) {\n" + + " ^^^^^^^^^^^^\n" + + "The return type is incompatible with AbstractDemo.test(Request)\n" + + "----------\n"); +} +public void testBug536978_comment5() { + String errMsg = isJRE11Plus + ? "class Result1 cannot be cast to class OtherResult (Result1 and OtherResult are in unnamed module of loader" + : "Result1 cannot be cast to OtherResult"; + runConformTest( + new String[] { + "SimpleDemo.java", + "\n" + + "abstract interface AbstractResult {\n" + + " public abstract int test();\n" + + "}\n" + + "\n" + + "abstract class AbstractDemo {\n" + + " protected abstract Response test(Request request);\n" + + "\n" + + "}\n" + + "\n" + + "class Result1 implements AbstractResult {\n" + + " public int test() {\n" + + " return 1;\n" + + " }\n" + + "}\n" + + "\n" + + "class OtherResult implements AbstractResult {\n" + + " public int test() {\n" + + " return 2;\n" + + " }\n" + + "}\n" + + "\n" + + "public class SimpleDemo extends AbstractDemo {\n" + + " @Override @SuppressWarnings(\"unchecked\")\n" + + " protected AbstractResult test(AbstractResult request) {\n" + + " return new Result1();\n" + + " }\n" + + "\n" + + " public static void main(String... args) {\n" + + " AbstractDemo demo = new SimpleDemo();\n" + + " try {\n" + + " OtherResult result = demo.test(new OtherResult());\n" + + " } catch (ClassCastException e) {\n" + + " System.out.println(e.getMessage());\n" + // omit the stack trace for test robustness + " }\n" + + " }\n" + + "}\n" + }, + errMsg); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleAttributeTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleAttributeTests.java new file mode 100644 index 0000000000..95f24040fd --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleAttributeTests.java @@ -0,0 +1,250 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Arrays; +import java.util.stream.Stream; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.util.IAttributeNamesConstants; +import org.eclipse.jdt.core.util.IClassFileAttribute; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.IModuleAttribute; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; + +public class ModuleAttributeTests extends AbstractRegressionTest9 { + + public ModuleAttributeTests(String name) { + super(name); + } + + public static Class testClass() { + return ModuleAttributeTests.class; + } + + private static String[] allowedAttributes = { + new String(IAttributeNamesConstants.MODULE), + new String(IAttributeNamesConstants.MODULE_MAIN_CLASS), + new String(IAttributeNamesConstants.MODULE_PACKAGES), + new String(IAttributeNamesConstants.RUNTIME_VISIBLE_ANNOTATIONS), + new String(IAttributeNamesConstants.RUNTIME_INVISIBLE_ANNOTATIONS), + new String(IAttributeNamesConstants.SOURCE) + }; + // Use this static initializer to specify subset for tests + // All specified tests which does not belong to the class are skipped... + static { +// TESTS_PREFIX = "testBug95521"; +// TESTS_NAMES = new String[] { "testBug508889_003" }; +// TESTS_NUMBERS = new int[] { 53 }; +// TESTS_RANGE = new int[] { 23 -1,}; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); + } + + private IModuleAttribute getModuleAttribute(String[] contents) { + this.runConformTest(contents); + IClassFileReader cfr = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "module-info.class", IClassFileReader.CLASSFILE_ATTRIBUTES); + assertNotNull("Error reading module-info.class", cfr); + IClassFileAttribute attr = Arrays.stream(cfr.getAttributes()) + .filter(e -> new String(e.getAttributeName()).equals("Module")) + .findFirst() + .orElse(null); + assertNotNull("Module attribute not found", attr); + assertTrue("Not a module attribute", attr instanceof IModuleAttribute); + return (IModuleAttribute) attr; + } + + // basic test to check for presence of module attribute in module-info.class + public void test001() throws Exception { + this.runConformTest( + new String[] { + "module-info.java", + "module test {\n" + + "}\n", + }); + IClassFileReader cfr = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "module-info.class", IClassFileReader.CLASSFILE_ATTRIBUTES); + assertNotNull("Error reading module-info.class", cfr); + IClassFileAttribute moduleAttribute = null; + IClassFileAttribute[] attrs = cfr.getAttributes(); + for (int i=0,max=attrs.length;i new String(e.getAttributeName()).equals("Module")) + .count(); + assertEquals("Unexpected number of module attributes", 1, count); + } + // Module Atrribute sanity + public void _testBug508889_003() throws Exception { + String[] contents = { + "module-info.java", + "module first {\n" + + "exports pack1;\n" + + "exports pack2 to zero;\n" + + "}\n", + "pack1/X11.java", + "package pack1;\n" + + "public class X11 {}\n", + "pack2/X21.java", + "package pack2;\n" + + "public class X21 {}\n", + }; + IModuleAttribute module = getModuleAttribute(contents); + assertEquals("Wrong Module Name", "first", new String(module.getModuleName())); + assertTrue("Unexpected attribute length", module.getAttributeLength() > 0); + //int flags = module.getModuleFlags(); + } + public void testBug521521() throws Exception { + this.runConformTest( + new String[] { + "module-info.java", + "module test {\n" + + "}\n", + }); + IClassFileReader cfr = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "module-info.class", IClassFileReader.CLASSFILE_ATTRIBUTES); + assertNotNull("Error reading module-info.class", cfr); + int flags = cfr.getAccessFlags(); + assertTrue("Invalid access flags", (flags & ~ClassFileConstants.AccModule) == 0); + } + public void testBug521521a() throws Exception { + this.runConformTest( + new String[] { + "module-info.java", + "open module test {\n" + + "}\n", + }); + IClassFileReader cfr = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "module-info.class", IClassFileReader.CLASSFILE_ATTRIBUTES); + assertNotNull("Error reading module-info.class", cfr); + int flags = cfr.getAccessFlags(); + assertTrue("Invalid access flags", (flags & ~ClassFileConstants.AccModule) == 0); + } + + public void testModuleCompile() throws Exception { + String pack1_x11java = "pack1/X11.java"; + String pack2_x21java = "pack2/X21.java"; + associateToModule("first", pack1_x11java, pack2_x21java); + String[] contents = { + "module-info.java", + "module first {\n" + + "exports pack1;\n" + + "exports pack2 to zero;\n" + + "}\n", + pack1_x11java, + "package pack1;\n" + + "public class X11 {}\n", + pack2_x21java, + "package pack2;\n" + + "public class X21 {}\n", + }; + this.runConformTest(contents); + } + public void testBug495967() throws Exception { + String pack1_x11java = "pack1/pack2/pack3/pack4/X11.java"; + String pack2_x21java = "pack21/pack22/pack23/pack24/X21.java"; + String pack3_x31java = "pack31/pack32/pack33/pack34/X31.java"; + String pack4_x41java = "pack41/pack42/pack43/pack44/X41.java"; + String pack5_x51java = "pack51/pack52/pack53/pack54/X51.java"; + String pack6_x61java = "pack61/pack62/pack63/pack64/X61.java"; + String pack7_x71java = "pack71/pack72/pack73/pack74/X71.java"; + String pack8_x81java = "pack81/pack82/pack83/pack84/X81.java"; + String pack9_x91java = "pack91/pack92/pack93/pack94/X91.java"; + associateToModule("first", pack1_x11java, pack2_x21java, pack3_x31java, pack4_x41java, pack5_x51java, pack6_x61java, pack7_x71java, pack8_x81java, pack9_x91java); + String[] contents = { + "module-info.java", + "module first {\n" + + "exports pack1.pack2.pack3.pack4 to zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty;\n" + + "exports pack21.pack22.pack23.pack24 to zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty;\n" + + "exports pack31.pack32.pack33.pack34 to zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty;\n" + + "exports pack41.pack42.pack43.pack44 to zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty;\n" + + "exports pack51.pack52.pack53.pack54 to zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty;\n" + + "exports pack61.pack62.pack63.pack64 to zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty;\n" + + "exports pack71.pack72.pack73.pack74 to zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty;\n" + + "exports pack81.pack82.pack83.pack84 to zero, one, two, three, four, five;\n" + + "exports pack91.pack92.pack93.pack94 to zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty;\n" + + "}\n", + pack1_x11java, + "package pack1.pack2.pack3.pack4;\n" + + "public class X11 {}\n", + pack2_x21java, + "package pack21.pack22.pack23.pack24;\n" + + "public class X21 {}\n", + pack3_x31java, + "package pack31.pack32.pack33.pack34;\n" + + "public class X31 {}\n", + pack4_x41java, + "package pack41.pack42.pack43.pack44;\n" + + "public class X41 {}\n", + pack5_x51java, + "package pack51.pack52.pack53.pack54;\n" + + "public class X51 {}\n", + pack6_x61java, + "package pack61.pack62.pack63.pack64;\n" + + "public class X61 {}\n", + pack7_x71java, + "package pack71.pack72.pack73.pack74;\n" + + "public class X71 {}\n", + pack8_x81java, + "package pack81.pack82.pack83.pack84;\n" + + "public class X81 {}\n", + pack9_x91java, + "package pack91.pack92.pack93.pack94;\n" + + "public class X91 {}\n", + }; + this.runConformTest(contents); + } + public void testBug519330() throws Exception { + String[] contents = { + "module-info.java", + "module java.base {\n" + + "}\n", + }; + IModuleAttribute moduleAttribute = getModuleAttribute(contents); + assertTrue("module java.base should not require any other modules", moduleAttribute.getRequiresCount() == 0); + } + public void testBug533134() throws Exception { + String[] contents = { + "module-info.java", + "@Deprecated\n" + + "module test {\n" + + "}\n", + }; + this.runConformTest(contents); + IClassFileReader cfr = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "module-info.class", IClassFileReader.CLASSFILE_ATTRIBUTES); + assertNotNull("Error reading module-info.class", cfr); + IClassFileAttribute[] attrs = cfr.getAttributes(); + for (IClassFileAttribute attr : attrs) { + String name = new String(attr.getAttributeName()); + assertTrue("Attribute " + name + " is not allowed", Stream.of(allowedAttributes).anyMatch(a -> a.equals(name))); + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java new file mode 100644 index 0000000000..3f5f53d72d --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ModuleCompilationTests.java @@ -0,0 +1,5635 @@ +/******************************************************************************* + * Copyright (c) 2016, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.DirectoryNotEmptyException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.IClassFileAttribute; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.IModuleAttribute; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.codegen.AttributeNamesConstants; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; + +public class ModuleCompilationTests extends AbstractBatchCompilerTest { + + static { +// TESTS_NAMES = new String[] { "testRelease565930" }; + // TESTS_NUMBERS = new int[] { 1 }; + // TESTS_RANGE = new int[] { 298, -1 }; + } + + // use -source rather than --release but suppress: warning: [options] bootstrap class path not set in conjunction with -source 9: + private static final String JAVAC_SOURCE_9_OPTIONS = "-source 9 -Xlint:-options"; + + public ModuleCompilationTests(String name) { + super(name); + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); + } + + public static Class testClass() { + return ModuleCompilationTests.class; + } + + protected void writeFileCollecting(List collectedFiles, String directoryName, String fileName, String source) { + writeFile(directoryName, fileName, source); + collectedFiles.add(directoryName+File.separator+fileName); + } + + protected void writeFile(String directoryName, String fileName, String source) { + File directory = new File(directoryName); + if (!directory.exists()) { + if (!directory.mkdirs()) { + System.out.println("Could not create " + directoryName); + return; + } + } + String filePath = directory.getAbsolutePath() + File.separator + fileName; + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(filePath)); + writer.write(source); + writer.flush(); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + class Runner extends AbstractRegressionTest.Runner { + StringBuffer commandLine = new StringBuffer(); + String outputDir = OUTPUT_DIR + File.separator + "javac"; + List fileNames = new ArrayList<>(); + /** will replace any -8, -9 ... option for javac */ + String javacVersionOptions; + + Runner() { + this.javacTestOptions = JavacTestOptions.DEFAULT; + this.expectedOutputString = ""; + this.expectedErrorString = ""; + } + /** Create a source file and add the filename to the compiler command line. */ + void createFile(String directoryName, String fileName, String source) { + writeFileCollecting(this.fileNames, directoryName, fileName, source); + } + Set runConformModuleTest() { + if (!this.fileNames.isEmpty()) { + this.shouldFlushOutputDirectory = false; + if (this.testFiles == null) + this.testFiles = new String[0]; + for (String fileName : this.fileNames) { + this.commandLine.append(" \"").append(fileName).append("\""); + } + } + String commandLineString = this.commandLine.toString(); + String javacCommandLine = adjustForJavac(commandLineString, this.javacVersionOptions); + return ModuleCompilationTests.this.runConformModuleTest(this.testFiles, commandLineString, + this.expectedOutputString, this.expectedErrorString, + this.shouldFlushOutputDirectory, this.outputDir, + this.javacTestOptions, javacCommandLine); + } + } + + void runConformModuleTest(List testFileNames, StringBuffer commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory) + { + runConformModuleTest(testFileNames, commandLine, + expectedFailureOutOutputString, expectedFailureErrOutputString, shouldFlushOutputDirectory, OUTPUT_DIR + File.separator + "javac"); + } + + void runConformModuleTest(List testFileNames, StringBuffer commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String output) + { + for (String file : testFileNames) + commandLine.append(" \"").append(file).append("\""); + runConformModuleTest(new String[0], commandLine.toString(), + expectedFailureOutOutputString, expectedFailureErrOutputString, shouldFlushOutputDirectory, + output, JavacTestOptions.DEFAULT, null); + } + + Set runConformModuleTest(String[] testFiles, String commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory) + { + return runConformModuleTest(testFiles, commandLine, expectedFailureErrOutputString, expectedFailureErrOutputString, + shouldFlushOutputDirectory, OUTPUT_DIR, JavacTestOptions.DEFAULT, null); + } + + Set runConformModuleTest(String[] testFiles, String commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String output, JavacTestOptions options, String javacCommandLine) + { + this.runConformTest(testFiles, commandLine, expectedFailureOutOutputString, expectedFailureErrOutputString, shouldFlushOutputDirectory); + if (RUN_JAVAC) { + File outputDir = new File(output); + final Set outFiles = new HashSet<>(); + walkOutFiles(output, outFiles, true); + String[] testFileNames = new String[testFiles.length/2]; + for (int i = 0; i < testFileNames.length; i++) { + testFileNames[i] = testFiles[i*2]; + } + if (javacCommandLine == null) { + javacCommandLine = adjustForJavac(commandLine, null); + } + for (JavacCompiler javacCompiler : javacCompilers) { + if (javacCompiler.compliance < ClassFileConstants.JDK9) + continue; + if (options.skip(javacCompiler)) { + System.err.println("Skip testing javac in "+testName()); + continue; + } + StringBuffer log = new StringBuffer(); + try { + long compileResult = javacCompiler.compile( + outputDir, /* directory */ + javacCommandLine /* options */, + testFileNames /* source file names */, + log, + false); // don't repeat filenames on the command line + if (compileResult != 0) { + System.err.println("Previous error was from "+testName()); + fail("Unexpected error from javac"); + } + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + throw new AssertionFailedError(e.getMessage()); + } + final Set expectedFiles = new HashSet<>(outFiles); + walkOutFiles(output, expectedFiles, false); + for (String missingFile : expectedFiles) + System.err.println("Missing output file from javac: "+missingFile); + } + return outFiles; + } + return null; + } + + void runNegativeModuleTest(List testFileNames, StringBuffer commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String javacErrorMatch) { + runNegativeModuleTest(testFileNames, commandLine, expectedFailureOutOutputString, + expectedFailureErrOutputString, shouldFlushOutputDirectory, javacErrorMatch, OUTPUT_DIR + File.separator + "javac"); + } + + void runNegativeModuleTest(List testFileNames, StringBuffer commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String javacErrorMatch, String output) + { + runNegativeModuleTest(testFileNames, commandLine, expectedFailureOutOutputString, expectedFailureErrOutputString, + shouldFlushOutputDirectory, javacErrorMatch, output, JavacTestOptions.DEFAULT); + } + void runNegativeModuleTest(List testFileNames, StringBuffer commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String javacErrorMatch, String output, JavacTestOptions options) + { + for (String file : testFileNames) + commandLine.append(" \"").append(file).append("\""); + runNegativeModuleTest(new String[0], commandLine.toString(), + expectedFailureOutOutputString, expectedFailureErrOutputString, shouldFlushOutputDirectory, javacErrorMatch, output, + options); + } + void runNegativeModuleTest(String[] testFiles, String commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String javacErrorMatch) { + runNegativeModuleTest(testFiles, commandLine, expectedFailureOutOutputString, expectedFailureErrOutputString, + shouldFlushOutputDirectory, javacErrorMatch, OUTPUT_DIR, JavacTestOptions.DEFAULT); + } + + void runNegativeModuleTest(String[] testFiles, String commandLine, + String expectedFailureOutOutputString, String expectedFailureErrOutputString, + boolean shouldFlushOutputDirectory, String javacErrorMatch, String output, JavacTestOptions options) + { + this.runNegativeTest(testFiles, commandLine, expectedFailureOutOutputString, expectedFailureErrOutputString, shouldFlushOutputDirectory); + if (RUN_JAVAC) { + String[] testFileNames = new String[testFiles.length/2]; + for (int i = 0; i < testFileNames.length; i++) { + testFileNames[i] = testFiles[i*2]; + } + File outputDir = new File(OUTPUT_DIR); + final Set outFiles = new HashSet<>(); + walkOutFiles(output, outFiles, true); + for (JavacCompiler javacCompiler : javacCompilers) { + if (javacCompiler.compliance < ClassFileConstants.JDK9) + continue; + JavacTestOptions.Excuse excuse = options.excuseFor(javacCompiler); + + commandLine = adjustForJavac(commandLine, null); + StringBuffer log = new StringBuffer(); + int mismatch = 0; + try { + long compileResult = javacCompiler.compile( + outputDir, /* directory */ + commandLine /* options */, + testFileNames /* source file names */, + log); + if (compileResult == 0) { + mismatch = JavacTestOptions.MismatchType.EclipseErrorsJavacNone; + javacErrorMatch = expectedFailureErrOutputString; + System.err.println("Previous error was from "+testName()); + } else if (!log.toString().contains(javacErrorMatch)) { + mismatch = JavacTestOptions.MismatchType.CompileErrorMismatch; + System.err.println(testName()+": Error match " + javacErrorMatch + " not found in \n"+log.toString()); + } + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + throw new AssertionFailedError(e.getMessage()); + } + handleMismatch(javacCompiler, testName(), testFiles, javacErrorMatch, + "", "", log, "", "", + excuse, mismatch); + final Set expectedFiles = new HashSet<>(outFiles); + walkOutFiles(output, expectedFiles, false); + for (String missingFile : expectedFiles) + System.err.println("Missing output file from javac: "+missingFile); + } + } + } + + /** + * @param commandLine command line arguments as used for ecj + * @param versionOptions if non-null use this to replace any ecj-specific -8, -9 etc. arg. + * If ecj-specific arg is not found, append anyway + * @return commandLine adjusted for javac + */ + String adjustForJavac(String commandLine, String versionOptions) { + String[] tokens = commandLine.split(" "); + StringBuilder buf = new StringBuilder(); + boolean skipNext = false; + for (int i = 0; i < tokens.length; i++) { + if (skipNext) { + skipNext = false; + continue; + } + if (tokens[i].trim().equals("-9")) { + if (versionOptions == null) + buf.append(' ').append(" --release 9 "); + continue; + } + if (tokens[i].trim().equals("-8")) { + if (versionOptions == null) + buf.append(' ').append(" --release 8 "); + continue; + } + if (tokens[i].startsWith("-warn") || tokens[i].startsWith("-err") || tokens[i].startsWith("-info")) { + if (tokens[i].contains("exports") && !tokens[i].contains("-exports")) + buf.append(" -Xlint:exports "); + continue; + } + if (tokens[i].trim().equals("-classNames")) { + skipNext = true; + continue; + } + buf.append(tokens[i]).append(' '); + } + if (versionOptions != null) { + buf.append(versionOptions); + } + return buf.toString(); + } + + private void walkOutFiles(final String outputLocation, final Set fileNames, boolean add) { + if (!(new File(outputLocation)).exists()) + return; + try { + Files.walkFileTree(FileSystems.getDefault().getPath(outputLocation), new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + if (file.toString().endsWith(".class")) { + if (add) { + fileNames.add(file.toString()); + } else { + if (!fileNames.remove(file.toString())) + System.err.println("Unexpected output file from javac: "+file.toString()); + } + Files.delete(file); + } + return FileVisitResult.CONTINUE; + } + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (!dir.toString().equals(outputLocation)) { + try { + Files.delete(dir); + } catch (DirectoryNotEmptyException ex) { + // expected + } + } + return FileVisitResult.CONTINUE; + } + }); + } catch (IOException e) { + e.printStackTrace(); + throw new AssertionFailedError(e.getMessage()); + } + } + + private void assertClassFile(String msg, String fileName, Set classFiles) { + if (classFiles != null) { + assertTrue(msg, classFiles.contains(fileName)); + } else { + assertTrue(msg, (new File(fileName).exists())); + } + } + + public void test001() { + runNegativeModuleTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.sql.Connection con = null;\n" + + " }\n" + + "}", + "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + "}" + }, + " -9 \"" + OUTPUT_DIR + File.separator + "module-info.java\" " + + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 4)\n" + + " java.sql.Connection con = null;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type java.sql.Connection is not accessible\n" + + "----------\n" + + "1 problem (1 error)\n", + true, + "package java.sql" /* match for javac error */); + } + public void test002() { + runConformModuleTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.sql.Connection con = null;\n" + + " System.out.println(con);\n" + + " }\n" + + "}", + "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + "}" + }, + " -9 \"" + OUTPUT_DIR + File.separator + "module-info.java\" " + + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"", + "", + "", + true); + } + public void test003() { + runConformModuleTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.sql.Connection con = null;\n" + + " System.out.println(con);\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"", + "", + "", + true); + } + public void test004() { + Set classFiles = runConformModuleTest( + new String[] { + "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + "}" + }, + " -9 \"" + OUTPUT_DIR + File.separator + "module-info.java\"", + "", + "", + true); + String fileName = OUTPUT_DIR + File.separator + "module-info.class"; + assertClassFile("Missing modul-info.class: " + fileName, fileName, classFiles); + } + public void test005() { + Set classFiles = runConformModuleTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " java.sql.Connection con;\n" + + "}", + "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + " requires java.desktop;\n" + + "}", + "q/Y.java", + "package q;\n" + + "public class Y {\n" + + " java.awt.Image image;\n" + + "}" + }, + " -9 \"" + OUTPUT_DIR + File.separator + "module-info.java\" " + + "\"" + OUTPUT_DIR + File.separator + "q/Y.java\" " + + "\"" + OUTPUT_DIR + File.separator + "p/X.java\" " + + "-d " + OUTPUT_DIR , + "", + "", + true); + String fileName = OUTPUT_DIR + File.separator + "module-info.class"; + assertClassFile("Missing modul-info.class: " + fileName, fileName, classFiles); + } + public void test006() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + " requires java.desktop;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " java.sql.Connection con;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " java.awt.Image image;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + runConformModuleTest(files, buffer, "", "", false); + } + public void test007() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/q/Y.java (at line 3)\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + " ^^^\n" + + "The type p.X is not accessible\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "p.X"); + } + public void test008() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + " requires mod.two;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "import q.Y;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return Y.con;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " exports q;\n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " public static java.sql.Connection con = null;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-exports") // Y.con unreliably refers to Connection (missing requires transitive) + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + } + public void test008a() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p.q;\n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "X.java", + "package p.q;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q" + File.separator + "r", "Y.java", + "package q.r;\n" + + "public class Y {\n" + + " java.sql.Connection con = p.q.X.getConnection();\n" + + "}"); + + String systemDirectory = OUTPUT_DIR+File.separator+"system"; + writeFile(systemDirectory, "readme.txt", "Not a valid system"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append("--system ").append(systemDirectory) + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "invalid location for system libraries: ---OUTPUT_DIR_PLACEHOLDER---/system\n", + false, + "system"); + } + public void test009() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + } + private void createUnnamedLibrary(String unnamedLoc, String unnamedBin) { + writeFile(unnamedLoc + File.separator + "s" + File.separator + "t", "Tester.java", + "package s.t;\n" + + "public class Tester {\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + unnamedBin) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\"") + .append(" -sourcepath \"" + unnamedLoc + "\" ") + .append(unnamedLoc + File.separator + "s" + File.separator + "t" + File.separator + "Tester.java"); + + runConformTest(new String[]{}, + buffer.toString(), + "", + "", + false); + } + private void createReusableModules(String srcDir, String outDir, File modDir) { + String moduleLoc = srcDir + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + // This one is not exported (i.e. internal to this module) + writeFileCollecting(files, moduleLoc + File.separator + "p1", "X1.java", + "package p1;\n" + + "public class X1 {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + + moduleLoc = srcDir + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " exports q;\n" + + " requires java.base;\n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" --module-path \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + srcDir + "\""); + for (String fileName : files) + buffer.append(" \"").append(fileName).append("\""); + + runConformTest(new String[]{}, + buffer.toString(), + "", + "", + false); + + String fileName = modDir + File.separator + "mod.one.jar"; + try { + Util.zip(new File(outDir + File.separator + "mod.one"), + fileName); + } catch (IOException e) { + e.printStackTrace(); + } + if (!modDir.exists()) { + if (!modDir.mkdirs()) { + fail("Coult not create folder " + modDir); + } + } + File mod2 = new File(modDir, "mod.two"); + if (!mod2.mkdir()) { + fail("Coult not create folder " + mod2); + } + Util.copy(outDir + File.separator + "mod.two", mod2.getAbsolutePath()); + + Util.flushDirectoryContent(new File(outDir)); + Util.flushDirectoryContent(new File(srcDir)); + } + public void test010() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "r", "Z.java", + "package r;\n" + + "public class Z extends Object {\n" + + " p.X x = null;\n" + + " q.Y y = null;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" -p \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir.getAbsolutePath()) + .append("\" ") + .append(" --module-source-path " + "\"" + srcDir + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false, outDir); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=487421 + public void test011() { + runConformModuleTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " java.lang.SecurityException ex = null;\n" + + "}", + "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + "}" + }, + " -9 \"" + OUTPUT_DIR + File.separator + "module-info.java\" " + + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"", + "", + "", + true); + } + // Modules used as regular -classpath (as opposed to --module-path) and module-info referencing + // those modules are reported as missing. + public void test012() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "r", "Z.java", + "package r;\n" + + "public class Z extends Object {\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir + File.separator + "mod.one.jar").append(File.pathSeparator) + .append(modDir + File.separator + "mod.two").append(File.pathSeparator) + .append("\" ") + .append(" --module-source-path " + "\"" + srcDir + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 2)\n" + + " requires mod.one;\n" + + " ^^^^^^^\n" + + "mod.one cannot be resolved to a module\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 3)\n" + + " requires mod.two;\n" + + " ^^^^^^^\n" + + "mod.two cannot be resolved to a module\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "module"); + } + // Modules used as regular -classpath as opposed to --module-path. The files being compiled + // aren't part of any modules (i.e. module-info is missing). The files should be able to + // reference the types from referenced classpath. + public void test013() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc + File.separator + "p", "Z.java", + "package r;\n" + + "public class Z extends Object {\n" + + " p.X x = null;\n" + + " q.Y y = null;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -9") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir + File.separator + "mod.one.jar").append(File.pathSeparator) + .append(modDir + File.separator + "mod.two").append(File.pathSeparator) + .append("\" "); + runConformModuleTest(files, + buffer, + "", + "", + false, + outDir); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=495500 + //-source 9 + public void testBug495500a() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -9 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + String expectedOutput = "// Compiled from X.java (version 9 : 53.0, super bit)"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + //-source 8 -target 9 + public void testBug495500b() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -9 -source 8 -target 9 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + String expectedOutput = "// Compiled from X.java (version 9 : 53.0, super bit)"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + // compliance 9 -source 9 -target 9 + public void testBug495500c() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -9 -source 9 -target 9 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + String expectedOutput = "// Compiled from X.java (version 9 : 53.0, super bit)"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + /* + * Test add-exports grants visibility to another module + */ + public void test014() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-exports mod.one/p=mod.two"); + + runConformModuleTest(files, + buffer, + "", + "", + false); + } + public void test015() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-exports mod.one/p=mod.two"); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/q/Y.java (at line 3)\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + " ^^^\n" + + "The type p.X is not accessible\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "cannot be resolved", + OUTPUT_DIR + File.separator + out, + JavacTestOptions.JavacHasABug.JavacBug8207032); + } + public void test016() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-exports mod.one/p=mod.two") + .append(" --add-reads mod.two=mod.one"); + + runConformModuleTest(files, + buffer, + "", + "", + false); + } + public void test017() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-exports mod.one/p=mod.three") + .append(" --add-reads mod.two=mod.one"); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/q/Y.java (at line 3)\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + " ^^^\n" + + "The type p.X is not accessible\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "visible", + OUTPUT_DIR + File.separator + out); + } + public void test018() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + "}"); + moduleLoc = directory + File.separator + "mod.three"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires java.base;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "r", "Z.java", + "package r;\n" + + "public class Z {\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + "}"); + + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-exports mod.one/p=mod.two,mod.three") + .append(" --add-reads mod.two=mod.one") + .append(" --add-reads mod.three=mod.one"); + + runConformModuleTest(files, + buffer, + "", + "", + false); + } + /* + * Unnamed module tries to access a type from an unexported package successfully due to --add-exports + */ + public void test019() { + Runner runner = new Runner(); + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + runner.createFile(moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public abstract class X extends com.sun.security.ntlm.Server {\n" + + " //public X() {}\n" + + " public X(String arg0, String arg1) throws com.sun.security.ntlm.NTLMException {\n" + + " super(arg0, arg1);\n" + + " }\n" + + "}"); + + runner.commandLine.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -sourcepath " + "\"" + moduleLoc + "\" ") + .append(" --add-exports java.base/com.sun.security.ntlm=ALL-UNNAMED "); + + runner.javacVersionOptions = JAVAC_SOURCE_9_OPTIONS; // otherwise javac: error: exporting a package from system module java.base is not allowed with --release + runner.runConformModuleTest(); + } + /* + * Named module tries to access a type from an unnamed module successfully due to --add-reads + */ + public void test019b() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String unnamedLoc = directory + File.separator + "nomodule"; + String unnamedBin = OUTPUT_DIR + File.separator + "un_bin"; + String moduleLoc = directory + File.separator + "mod" + File.separator + "mod.one"; + + createUnnamedLibrary(unnamedLoc, unnamedBin); + + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one {\n" + + " exports p.q;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "X.java", + "package p.q;\n" + + "public abstract class X {\n" + + " s.t.Tester t;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append(unnamedBin + File.pathSeparator) + .append("\"") + .append(" --module-source-path \"" + directory + File.separator + "mod" + "\" ") + .append(" --add-reads mod.one=ALL-UNNAMED "); + + runConformModuleTest(files, + buffer, + "", + "", + false, + OUTPUT_DIR + File.separator + out); + } + + /* + * Can only import from a package that contains compilation units (from the unnamed module) + */ + public void test019c() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String unnamedLoc = directory + File.separator + "nomodule"; + String unnamedBin = OUTPUT_DIR + File.separator + "un_bin"; + + createUnnamedLibrary(unnamedLoc, unnamedBin); + + List files = new ArrayList<>(); + String moduleLoc = directory + File.separator + "mod.one"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one {\n" + + " exports p.q;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "X.java", + "package p.q;\n" + + "import s.*;\n" + + "import s.t.*;\n" + + "public abstract class X {\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append(unnamedBin + File.pathSeparator) + .append("\"") + .append(" --module-source-path \"" + directory + "\" ") + .append(" --add-reads mod.one=ALL-UNNAMED "); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/q/X.java (at line 2)\n" + + " import s.*;\n" + + " ^\n" + + "The package s is not accessible\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "package s", + OUTPUT_DIR + File.separator + out, + JavacTestOptions.JavacHasABug.JavacBug8204534); + } + /* + * Unnamed module tries to access a type from an unexported package, fail + */ + public void test019fail() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public abstract class X extends com.sun.security.ntlm.Server {\n" + + " //public X() {}\n" + + " public X(String arg0, String arg1) throws com.sun.security.ntlm.NTLMException {\n" + + " super(arg0, arg1);\n" + + " }\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -sourcepath " + "\"" + moduleLoc + "\" "); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/X.java (at line 2)\n" + + " public abstract class X extends com.sun.security.ntlm.Server {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type com.sun.security.ntlm.Server is not accessible\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/X.java (at line 4)\n" + + " public X(String arg0, String arg1) throws com.sun.security.ntlm.NTLMException {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type com.sun.security.ntlm.NTLMException is not accessible\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "package com.sun.security.ntlm"); + /* javac9: + * src/mod.one/p/X.java:2: error: package com.sun.security.ntlm is not visible + * public abstract class X extends com.sun.security.ntlm.Server { + * ^ + * (package com.sun.security.ntlm is declared in module java.base, which does not export it to the unnamed module) + * src/mod.one/p/X.java:4: error: package com.sun.security.ntlm is not visible + * public X(String arg0, String arg1) throws com.sun.security.ntlm.NTLMException { + * ^ + * (package com.sun.security.ntlm is declared in module java.base, which does not export it to the unnamed module) + */ + /* javac10: + * src/mod.one/p/X.java:2: error: package com.sun.security.ntlm does not exist + * public abstract class X extends com.sun.security.ntlm.Server { + * ^ + * src/mod.one/p/X.java:4: error: package com.sun.security.ntlm does not exist + * public X(String arg0, String arg1) throws com.sun.security.ntlm.NTLMException { + * ^ + */ + } + public void test020() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-exports mod.one=mod.two,mod.three"); + + runNegativeModuleTest(files, + buffer, + "", + "incorrectly formatted option: --add-exports mod.one=mod.two,mod.three\n", + false, + "option"); + } + public void test021() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-reads mod.one/mod.two"); + + runNegativeModuleTest(files, + buffer, + "", + "incorrectly formatted option: --add-reads mod.one/mod.two\n", + false, + "option"); + } + public void test022() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-exports mod.one/p=mod.three") + .append(" --add-exports mod.one/p=mod.three"); + + runNegativeModuleTest(files, + buffer, + "", + "can specify a package in a module only once with --add-export\n", + false, + "export"); + } + public void test023() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append("\"" + moduleLoc + File.separator + "module-info.java\" ") + .append(" -extdirs " + OUTPUT_DIR + File.separator + "src"); + + runNegativeModuleTest(files, + buffer, + "", + "option -extdirs not supported at compliance level 9 and above\n", + false, + "extdirs"); + } + public void test024() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" \"" + moduleLoc + File.separator + "module-info.java\" ") + .append(" -bootclasspath " + OUTPUT_DIR + File.separator + "src"); + + runNegativeModuleTest(files, + buffer, + "", + "option -bootclasspath not supported at compliance level 9 and above\n", + false, + "not allowed"); // when specifying -bootclasspath javac answers: "option --boot-class-path not allowed with target 1.9" (two bugs) + } + public void test025() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append("\"" + moduleLoc + File.separator + "module-info.java\" ") + .append(" -endorseddirs " + OUTPUT_DIR + File.separator + "src"); + + runNegativeModuleTest(files, + buffer, + "", + "option -endorseddirs not supported at compliance level 9 and above\n", + false, + "endorseddirs"); + } + public void test026() { + Runner runner = new Runner(); + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + runner.createFile( + moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires transitive java.sql;\n" + + "}"); + String javaHome = System.getProperty("java.home"); + runner.commandLine.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" --system \"").append(javaHome).append("\""); + + runner.javacVersionOptions = JAVAC_SOURCE_9_OPTIONS; + runner.runConformModuleTest(); + } + /** + * Mixed case of exported and non exported packages being referred to in another module + */ + public void test028() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "r", "Z.java", + "package r;\n" + + "public class Z extends Object {\n" + + " p.X x = null;\n" + + " p1.X1 x1 = null;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" -p \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir.getAbsolutePath()) + .append("\" ") + .append(" --module-source-path " + "\"" + srcDir + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/r/Z.java (at line 4)\n"+ + " p1.X1 x1 = null;\n" + + " ^^^^^\n" + + "The type p1.X1 is not accessible\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "visible", + outDir); + } + public void test029() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "public class Y {\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-exports mod.one/p=mod.two,mod.three") + .append(" --add-reads mod.two=mod.one"); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/X.java (at line 3)\n" + + " public static java.sql.Connection getConnection() {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type Connection from module java.sql may not be accessible to clients due to missing \'requires transitive\'\n" + + "----------\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/q/Y.java (at line 3)\n" + + " java.sql.Connection con = p.X.getConnection();\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type java.sql.Connection is not accessible\n" + + "----------\n" + + "2 problems (1 error, 1 warning)\n", + false, + "visible"); + } + public void test030() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "import java.sql.*;\n" + + "public class Y {\n" + + " Connection con = null;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-exports") // getConnection() leaks non-transitively required type + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-exports mod.one/p=mod.two,mod.three") + .append(" --add-reads mod.two=mod.one"); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n"+ + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/q/Y.java (at line 2)\n"+ + " import java.sql.*;\n"+ + " ^^^^^^^^\n"+ + "The package java.sql is not accessible\n"+ + "----------\n"+ + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/q/Y.java (at line 4)\n"+ + " Connection con = null;\n"+ + " ^^^^^^^^^^\n"+ + "Connection cannot be resolved to a type\n"+ + "----------\n"+ + "2 problems (2 errors)\n", + false, + "visible", + OUTPUT_DIR + File.separator + out); + } + public void test031() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + " static java.sql.Connection getConnection() {\n" + + " return null;\n" + + " }\n" + + "}"); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires java.base;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "Y.java", + "package q;\n" + + "import java.sql.Connection;\n" + + "public class Y {\n" + + " Connection con = null;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\"") + .append(" --add-exports mod.one/p=mod.two,mod.three") + .append(" --add-reads mod.two=mod.one"); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n"+ + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/q/Y.java (at line 2)\n"+ + " import java.sql.Connection;\n"+ + " ^^^^^^^^^^^^^^^^^^^\n"+ + "The type java.sql.Connection is not accessible\n"+ + "----------\n"+ + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/q/Y.java (at line 4)\n"+ + " Connection con = null;\n"+ + " ^^^^^^^^^^\n"+ + "Connection cannot be resolved to a type\n"+ + "----------\n"+ + "2 problems (2 errors)\n", + false, + "visible", + OUTPUT_DIR + File.separator + out); + } + public void test032() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + "}"); + writeFileCollecting(files, moduleLoc+"/p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static class Inner {\n" + + " }\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false, + OUTPUT_DIR + File.separator + out); + } + /** + * Test that a module can't access types/packages in a plain Jar put in classpath + */ + public void test033() { + File libDir = new File(LIB_DIR); + Util.delete(libDir); // make sure we recycle the libs + libDir.mkdirs(); + try { + Util.createJar( + new String[] { + "a/A.java", + "package a;\n" + + "public class A {\n" + + "}" + }, + LIB_DIR + "/lib1.jar", + JavaCore.VERSION_9); + } catch (IOException e) { + // ignore + } + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X extends a.A {\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append(LIB_DIR).append(File.separator).append("lib1.jar").append(File.pathSeparator).append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/X.java (at line 2)\n" + + " public class X extends a.A {\n" + + " ^^^\n" + + "The type a.A is not accessible\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "package a does not exist"); + } + /** + * Test that a module can't access types/packages in a plain Jar put in modulepath + * but not explicitly added to the "requires" clause + */ + public void test034() { + File libDir = new File(LIB_DIR); + Util.delete(libDir); // make sure we recycle the libs + libDir.mkdirs(); + try { + Util.createJar( + new String[] { + "a/A.java", + "package a;\n" + + "public class A {\n" + + "}" + }, + LIB_DIR + "/lib1.jar", + JavaCore.VERSION_9); + } catch (IOException e) { + // ignore + } + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X extends a.A {\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()).append("\" ") + .append("-p \"") + .append(LIB_DIR).append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/X.java (at line 2)\n" + + " public class X extends a.A {\n" + + " ^^^\n" + + "The type a.A is not accessible\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "does not read"); + } + /** + * Test that a module can access types/packages in a plain Jar put in modulepath + * and explicitly added to the "requires" clause + */ + public void test035() { + File libDir = new File(LIB_DIR); + Util.delete(libDir); // make sure we recycle the libs + libDir.mkdirs(); + try { + Util.createJar( + new String[] { + "a/A.java", + "package a;\n" + + "public class A {\n" + + "}" + }, + LIB_DIR + "/lib1.jar", + JavaCore.VERSION_9); + } catch (IOException e) { + // ignore + } + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.sql;\n" + + " requires lib1;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X extends a.A {\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()).append("\" ") + .append("-p \"") + .append(LIB_DIR).append("\" ") + .append(" -warn:-module ") + .append(" --module-source-path " + "\"" + directory + "\""); + runConformModuleTest(files, + buffer, + "", + "", + false); + } + public void testBug515985() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "impl", "Other.java", + "package impl;\n" + + "public class Other {\n" + + " public void privateMethod() {}" + + "}\n"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "import impl.Other;\n" + + "public class C1 extends Other {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "po", "Client.java", + "package po;\n" + + "import pm.C1;\n" + + "public class Client {\n" + + " void test1(C1 one) {\n" + + " one.privateMethod(); // ecj: The method privateMethod() is undefined for the type C1\n" + + " }\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + } + + public void testApiLeak1() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "impl", "Other.java", + "package impl;\n" + + "public class Other {\n" + + "}\n"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "import impl.Other;\n" + + "public class C1 extends Other {\n" + + " public void m1(Other o) {}\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "impl", "Other.java", + "package impl;\n" + + "public class Other {\n" + + "}\n"); + writeFileCollecting(files, moduleLoc + File.separator + "po", "Client.java", + "package po;\n" + + "import pm.C1;\n" + + "public class Client {\n" + + " void test1(C1 one) {\n" + + " one.m1(one);\n" + + " }\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/pm/C1.java (at line 4)\n" + + " public void m1(Other o) {}\n" + + " ^^^^^\n" + + "The type Other is not exported from this module\n" + + "----------\n" + + "1 problem (1 warning)\n", + false); + } + + /** + * Same-named classes should not conflict, since one is not accessible. + * Still a sub class of the inaccessible class can be accessed and used for a method argument. + */ + public void testApiLeak2() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "impl", "SomeImpl.java", + "package impl;\n" + + "public class SomeImpl {\n" + + "}\n"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "import impl.SomeImpl;\n" + + "public class C1 {\n" + + " public void m1(SomeImpl o) {}\n" + + "}\n"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "Other.java", + "package pm;\n" + + "import impl.SomeImpl;\n" + + "public class Other extends SomeImpl {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "impl", "SomeImpl.java", + "package impl;\n" + + "public class SomeImpl {\n" + // pseudo-conflict to same named, but inaccessible class from mod.one + "}\n"); + writeFileCollecting(files, moduleLoc + File.separator + "po", "Client.java", + "package po;\n" + + "import pm.C1;\n" + + "import pm.Other;\n" + + "import impl.SomeImpl;\n" + + "public class Client {\n" + + " void test1(C1 one) {\n" + + " SomeImpl impl = new SomeImpl();\n" + // our own version + " one.m1(impl);\n" + // incompatible to what's required + " one.m1(new Other());\n" + // OK + " }\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -info:+exports") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. INFO in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/pm/C1.java (at line 4)\n" + + " public void m1(SomeImpl o) {}\n" + + " ^^^^^^^^\n" + + "The type SomeImpl is not exported from this module\n" + + "----------\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/po/Client.java (at line 8)\n" + + " one.m1(impl);\n" + + " ^^\n" + + "The method m1(impl.SomeImpl) in the type C1 is not applicable for the arguments (impl.SomeImpl)\n" + + "----------\n" + + "2 problems (1 error, 0 warnings, 1 info)\n", + false, + "incompatible", + OUTPUT_DIR + File.separator + out); + } + + // conflict even without any reference to the conflicting package + // - three-way conflict between two direct and one indirect dependency + public void testPackageConflict0() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.x"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.x { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1x.java", + "package pm;\n" + + "public class C1x {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.y"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.y { \n" + + " requires transitive mod.x;\n" + + "}"); + + moduleLoc = directory + File.separator + "mod.one"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports pm;\n" + + " exports p2;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + writeFileCollecting(files, moduleLoc + File.separator + "p2", "C2.java", + "package p2;\n" + + "public class C2 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " exports pm;\n" + + " exports p2.sub;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C3.java", + "package pm;\n" + + "public class C3 {\n" + + "}\n"); + writeFileCollecting(files, moduleLoc + File.separator + "p2" + File.separator + "sub", "C4.java", + "package p2.sub;\n" + + "public class C4 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.three"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + " requires transitive mod.y;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 2)\n" + + " requires mod.one;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The package pm is accessible from more than one module: mod.one, mod.two, mod.x\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 3)\n" + + " requires mod.two;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The package pm is accessible from more than one module: mod.one, mod.two, mod.x\n" + + "----------\n" + + "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 4)\n" + + " requires transitive mod.y;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The package pm is accessible from more than one module: mod.one, mod.two, mod.x\n" + + "----------\n" + + "3 problems (3 errors)\n", + false, + "reads package pm"); + } + + public void testPackageConflict1() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports pm;\n" + + " exports p2;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + writeFileCollecting(files, moduleLoc + File.separator + "p2", "C2.java", + "package p2;\n" + + "public class C2 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " exports pm;\n" + + " exports p2.sub;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C3.java", + "package pm;\n" + + "public class C3 {\n" + + "}\n"); + writeFileCollecting(files, moduleLoc + File.separator + "p2" + File.separator + "sub", "C4.java", + "package p2.sub;\n" + + "public class C4 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.three"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "po", "Client.java", + "package po;\n" + + "import pm.*;\n" + + "import pm.C3;\n" + + "import p2.C2;\n" + + "public class Client {\n" + + " void test1(C1 one) {\n" + + " }\n" + + " pm.C1 f1;\n" + + " p2.sub.C4 f4;\n" + // no conflict mod.one/p2 <-> mod.two/p2.sub + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 2)\n" + + " requires mod.one;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The package pm is accessible from more than one module: mod.one, mod.two\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 3)\n" + + " requires mod.two;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The package pm is accessible from more than one module: mod.one, mod.two\n" + + "----------\n" + + "----------\n" + + "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/po/Client.java (at line 2)\n" + + " import pm.*;\n" + + " ^^\n" + + "The package pm is accessible from more than one module: mod.one, mod.two\n" + + "----------\n" + + "4. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/po/Client.java (at line 3)\n" + + " import pm.C3;\n" + + " ^^\n" + + "The package pm is accessible from more than one module: mod.one, mod.two\n" + + "----------\n" + + "5. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/po/Client.java (at line 8)\n" + + " pm.C1 f1;\n" + + " ^^\n" + + "The package pm is accessible from more than one module: mod.one, mod.two\n" + + "----------\n" + + "5 problems (5 errors)\n", + false, + "reads package pm"); + } + // conflict foreign<->local package + public void testPackageConflict3() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + List files = new ArrayList<>(); + String moduleLoc = directory + File.separator + "mod.one"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C3.java", + "package pm;\n" + + "public class C3 {\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/pm/C3.java (at line 1)\n" + + " package pm;\n" + + " ^^\n" + + "The package pm conflicts with a package accessible from another module: mod.one\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "", + OUTPUT_DIR + File.separator + out); + } + public void testPackageConflict4() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + File srcDir = new File(directory); + + String moduleLoc = directory + File.separator + "mod.x"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.x { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.y"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.y { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + Util.flushDirectoryContent(srcDir); + files.clear(); + writeFileCollecting(files, directory + File.separator + "p", "X.java", + "public class X extends pm.C1 { \n" + + "}"); + buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-path " + "\"" + OUTPUT_DIR + File.separator + out + "\""); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 1)\n" + + " public class X extends pm.C1 { \n" + + " ^^\n" + + "The package pm is accessible from more than one module: mod.x, mod.y\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "package conflict"); + } + /** + * currently disabled because ECJ allows unnamed modules to read from other modules from + * module-path even if they are not part of root modules. + */ + public void _testPackageConflict4a() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + File srcDir = new File(directory); + + String moduleLoc = directory + File.separator + "mod.x"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.x { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + Util.flushDirectoryContent(srcDir); + files.clear(); + writeFileCollecting(files, directory + File.separator + "p", "X.java", + "public class X extends pm.C1 { \n" + + "}"); + buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-path " + "\"" + OUTPUT_DIR + File.separator + out + "\""); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 1)\n" + + " public class X extends pm.C1 { \n" + + " ^^\n" + + "pm cannot be resolved to a type\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "package conflict"); + } + public void testPackageConflict5() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + File srcDir = new File(directory); + + String moduleLoc = directory + File.separator + "mod.x"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.x { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.y"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.y { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + Util.flushDirectoryContent(srcDir); + files.clear(); + writeFileCollecting(files, directory + File.separator + "p", "X.java", + "public class X extends pm.C1 { \n" + + "}"); + buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-path " + "\"" + OUTPUT_DIR + File.separator + out + "\"") + .append(" --add-modules mod.x,mod.y"); + runNegativeModuleTest(files, + buffer, + "", + "The package pm is accessible from more than one module: mod.y, mod.x\n", + false, + "reads package pm from both"); + buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-path " + "\"" + OUTPUT_DIR + File.separator + out + "\"") + .append(" --add-modules mod.x,mod.z"); + runNegativeModuleTest(files, + buffer, + "", + "invalid module name: mod.z\n", + false, + "module not found"); + } + public void testPackageConflict6() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + File srcDir = new File(directory); + + String moduleLoc = directory + File.separator + "mod.x"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.x { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.y"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.y { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + Util.flushDirectoryContent(srcDir); + files.clear(); + writeFileCollecting(files, directory + File.separator + "p", "X.java", + "public class X extends pm.C1 { \n" + + "}"); + buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-path " + "\"" + OUTPUT_DIR + File.separator + out + "\"") + .append(" --add-modules mod.x,"); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/p/X.java (at line 1)\n" + + " public class X extends pm.C1 { \n" + + " ^^\n" + + "The package pm is accessible from more than one module: mod.x, mod.y\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "package conflict"); + } + public void testPackageConflict7() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + File srcDir = new File(directory); + + String moduleLoc = directory + File.separator + "mod.x"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.x { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.y"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.y { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + Util.flushDirectoryContent(srcDir); + files.clear(); + writeFileCollecting(files, directory + File.separator + "p", "X.java", + "public class X { \n" + + "}"); + buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-path " + "\"" + OUTPUT_DIR + File.separator + out + "\"") + .append(" --add-modules mod.x,mod.y"); + runNegativeModuleTest(files, + buffer, + "", + "The package pm is accessible from more than one module: mod.y, mod.x\n", + false, + "reads package pm from both"); + } + public void testPackageTypeConflict1() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p1" + File.separator + "p2", "t3.java", + "package p1.p2;\n" + + "public class t3 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " exports p1.p2.t3;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p1" + File.separator + "p2" + File.separator + "t3", "t4.java", + "package p1.p2.t3;\n" + + "public class t4 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.three"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "po", "Client.java", + "package po;\n" + + "public class Client {\n" + + " p1.p2.t3.t4 f;\n" + // no conflict mod.one/p1.p2.t3 <-> mod.two/p1.p2.t3 + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + } + + public void testBug519922() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + List files = new ArrayList<>(); + writeFileCollecting(files, directory + File.separator + "test", "Test.java", + "package test;\n" + + "\n" + + "public class Test implements org.eclipse.SomeInterface {\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" "); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/test/Test.java (at line 3)\n" + + " public class Test implements org.eclipse.SomeInterface {\n" + + " ^^^^^^^^^^^\n" + + "org.eclipse cannot be resolved to a type\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "does not exist"); + } + public void testMixedSourcepath() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod" + File.separator + "mod.one"; + + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one {\n" + + " exports p.q;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\"") + .append(" -sourcepath \"" + directory + "\" ") + .append(" --module-source-path \"" + directory + File.separator + "mod" + "\" ") + .append(" --add-reads mod.one=ALL-UNNAMED "); + + runNegativeModuleTest(files, + buffer, + "", + "cannot specify both -source-path and --module-source-path\n", + false, + "cannot specify both", + OUTPUT_DIR + File.separator + out); + } + + // causes: non-public type (C0), non-exported package (p.priv) + // locations: field, method parameter, method return + public void testAPILeakDetection1() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p.exp;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "exp", "C1.java", + "package p.exp;\n" + + "import p.priv.*;\n" + + "class C0 {\n" + + " public void test(C0 c) {}\n" + + "}\n" + + "public class C1 {\n" + + " public C2 f;\n" + + " public void test1(C0 c) {}\n" + + " public void test2(C2 c) {}\n" + + " protected void test3(C0 c) {}\n" + + " protected void test4(C2 c) {}\n" + + " public p.priv.C2 test5() { return null; }\n" + + "}\n"); + + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "priv", "C2.java", + "package p.priv;\n" + + "public class C2 {\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -err:exports") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/exp/C1.java (at line 7)\n" + + " public C2 f;\n" + + " ^^\n" + + "The type C2 is not exported from this module\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/exp/C1.java (at line 8)\n" + + " public void test1(C0 c) {}\n" + + " ^^\n" + + "The type C0 is not accessible to clients that require this module\n" + + "----------\n" + + "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/exp/C1.java (at line 9)\n" + + " public void test2(C2 c) {}\n" + + " ^^\n" + + "The type C2 is not exported from this module\n" + + "----------\n" + + "4. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/exp/C1.java (at line 12)\n" + + " public p.priv.C2 test5() { return null; }\n" + + " ^^^^^^^^^\n" + + "The type C2 is not exported from this module\n" + + "----------\n" + + "4 problems (4 errors)\n", + false, + "is not exported"); + } + + // details: in array, parameterized type + public void testAPILeakDetection2() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p.exp;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "exp", "C1.java", + "package p.exp;\n" + + "import java.util.*;\n" + + "class C0 {\n" + + " public void test(C0 c) {}\n" + + "}\n" + + "public class C1 {\n" + + " public List f1;\n" + + " public C0[] f2;\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -err:+exports") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/exp/C1.java (at line 7)\n" + + " public List f1;\n" + + " ^^\n" + + "The type C0 is not accessible to clients that require this module\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/exp/C1.java (at line 8)\n" + + " public C0[] f2;\n" + + " ^^\n" + + "The type C0 is not accessible to clients that require this module\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "not accessible to clients"); + } + + // suppress + public void testAPILeakDetection3() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p.exp;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "exp", "C1.java", + "package p.exp;\n" + + "import java.util.*;\n" + + "class C0 {\n" + + " public void test(C0 c) {}\n" + + "}\n" + + "public class C1 {\n" + + " @SuppressWarnings(\"exports\")\n" + + " public List f1;\n" + + " @SuppressWarnings(\"exports\")\n" + + " public C0[] f2;\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:+exports,+suppress") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false); + } + + // details: nested types + public void testAPILeakDetection4() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p.exp;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "exp", "C1.java", + "package p.exp;\n" + + "public class C1 {\n" + + " static class C3 {\n" + + " public static class C4 {}\n" + // public but nested in non-public + " }\n" + + " public C3 f1;\n" + + " public C3.C4 f2;\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -err:+exports") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/exp/C1.java (at line 6)\n" + + " public C3 f1;\n" + + " ^^\n" + + "The type C1.C3 is not accessible to clients that require this module\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/exp/C1.java (at line 7)\n" + + " public C3.C4 f2;\n" + + " ^^^^^\n" + + "The type C1.C3.C4 is not accessible to clients that require this module\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "one is not accessible to clients"); + } + + // type from non-transitive required module + public void testAPILeakDetection5() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p.exp1;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "exp1", "C1.java", + "package p.exp1;\n" + + "public class C1 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " exports p.exp2;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "exp2", "C2.java", + "package p.exp2;\n" + + "public class C2 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.three"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one; // missing transitive\n" + + " requires transitive mod.two;\n" + + " exports p.exp3;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "exp3", "C3.java", + "package p.exp3;\n" + + "public class C3 {\n" + + " public void m1(p.exp1.C1 arg) {}\n" + + " public void m2(p.exp2.C2 arg) {}\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -err:+exports") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/p/exp3/C3.java (at line 3)\n" + + " public void m1(p.exp1.C1 arg) {}\n" + + " ^^^^^^^^^\n" + + "The type C1 from module mod.one may not be accessible to clients due to missing \'requires transitive\'\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "is not indirectly exported"); + } + + // annotated types in API + public void testAPILeakDetection6() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p.exp;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "exp", "C1.java", + "package p.exp;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface ANN {}\n" + + "class C0 {}\n" + + "public class C1 {\n" + + " public @ANN String f1;\n" + + " public @ANN C0 f3;\n" + + " public @ANN String test(@ANN String arg, @ANN C0 c) { return \"\"; }\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -err:exports") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/exp/C1.java (at line 8)\n" + + " public @ANN C0 f3;\n" + + " ^^\n" + + "The type C0 is not accessible to clients that require this module\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/exp/C1.java (at line 9)\n" + + " public @ANN String test(@ANN String arg, @ANN C0 c) { return \"\"; }\n" + + " ^^\n" + + "The type C0 is not accessible to clients that require this module\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "is not accessible to clients"); + } + + // enum API + public void testAPILeakDetection7() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p.exp;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "exp", "C1.java", + "package p.exp;\n" + + "public enum C1 {\n" + + " X, Y, Z;\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -err:exports") + .append(" --module-source-path " + "\"" + directory + "\""); + + runConformModuleTest(files, buffer, + "", + "", + false); + } + + public void testBug486013_comment27() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String projLoc = directory + File.separator + "Proj"; + List files = new ArrayList<>(); + writeFileCollecting(files, projLoc + File.separator + "p" + File.separator + "exp", "C1.java", + "package p.exp;\n" + + "import java.util.*;\n" + + "public class C1 {\n" + + " List l;\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -err:exports"); + + runConformModuleTest(files, buffer, + "", + "", + false); + } + public void testBug518295a() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" -p \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir.getAbsolutePath()) + .append("\" ") + .append("-classNames mod.one/p.XYZ") + .append(" --module-source-path " + "\"" + srcDir + "\""); + + files.forEach(name -> buffer.append(" \"" + name + "\"")); + runNegativeTest(new String[0], + buffer.toString(), + "", + "invalid class name: mod.one/p.XYZ\n", + false); + } + public void testBug518295b() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" -p \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir.getAbsolutePath()) + .append("\" ") + .append("-classNames mod.xyz/p.X") + .append(" --module-source-path " + "\"" + srcDir + "\""); + + files.forEach(name -> buffer.append(" \"" + name + "\"")); + runNegativeTest(new String[0], + buffer.toString(), + "", + "invalid module name: mod.xyz\n", + false); + } + public void testBug518295c() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" -p \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir.getAbsolutePath()) + .append("\" ") + .append("-classNames mod.one/p.X") + .append(" --module-source-path " + "\"" + srcDir + "\""); + + runConformModuleTest(files, + buffer, + "", + "", + false, + outDir); + } + public void testUnnamedPackage_Bug520839() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + "}"); + writeFileCollecting(files, moduleLoc, "X.java", + "public class X {\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "Must declare a named package because this compilation unit is associated to the named module \'mod.one\'\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "unnamed package is not allowed in named modules", + OUTPUT_DIR + File.separator + out); + } + public void testAutoModule1() throws Exception { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + + String[] sources = { + "p/a/X.java", + "package p.a;\n" + + "public class X {}\n;" + }; + String jarPath = OUTPUT_DIR + File.separator + "lib-x.jar"; + Util.createJar(sources, jarPath, "1.8"); + + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires lib.x;\n" + // lib.x is derived from lib-x.jar + "}"); + writeFileCollecting(files, moduleLoc+File.separator+"q", "X.java", + "package q;\n" + + "public class X {\n" + + " p.a.X f;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -info:+module ") + .append(" --module-path " + "\"" + jarPath + "\""); + + runConformModuleTest(files, + buffer, + "", + "----------\n" + + "1. INFO in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 2)\n" + + " requires lib.x;\n" + + " ^^^^^\n" + + "Name of automatic module \'lib.x\' is unstable, it is derived from the module\'s file name.\n" + + "----------\n" + + "1 problem (1 info)\n", + false, + OUTPUT_DIR + File.separator + out); + } + public void testBug521458a() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod._3_ { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" -p \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir.getAbsolutePath()) + .append("\" ") + .append("-classNames mod.one/p.X") + .append(" --module-source-path " + "\"" + srcDir + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "module name mod._3_ does not match expected name mod.three\n", + false, + "does not match expected name"); + } + /* + * Disabled because the parser seem to take the module path as mod and not mod.e + */ + public void _testBug521458b() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.3 { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" -p \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir.getAbsolutePath()) + .append("\" ") + .append("-classNames mod.one/p.X") + .append(" --module-source-path " + "\"" + srcDir + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "module name mod.3 does not match expected name mod.three\r\n", + false, + outDir); + } +public void testBug521362_emptyFile() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p1;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p1", "X.java", + ""); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 2)\n" + + " exports p1;\n" + + " ^^\n" + + "The package p1 does not exist or is empty\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "empty", + OUTPUT_DIR + File.separator + out); + } + public void testBug521362_mismatchingdeclaration() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p1;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p1", "X.java", + "package q;\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 2)\n" + + " exports p1;\n" + + " ^^\n" + + "The package p1 does not exist or is empty\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "package is empty", + OUTPUT_DIR + File.separator + out); + } + public void testBug521362_multiplePackages() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p1;\n" + + " exports p2;\n" + + " exports p3;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p1", "X.java", + "package q;\n"); + writeFileCollecting(files, moduleLoc + File.separator + "p2", "X.java", + "package q2;\n"); + writeFileCollecting(files, moduleLoc + File.separator + "p3", "X.java", + "package p3;\n"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 2)\n" + + " exports p1;\n" + + " ^^\n" + + "The package p1 does not exist or is empty\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 3)\n" + + " exports p2;\n" + + " ^^\n" + + "The package p2 does not exist or is empty\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "package is empty", + OUTPUT_DIR + File.separator + out); + } + public void testBug521362_multiplePackages2() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p1;\n" + + " exports p2;\n" + + " exports p3.p4.p5;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p1", "X.java", + "package q;\n"); + writeFileCollecting(files, moduleLoc + File.separator + "p2", "X.java", + "package q2;\n"); + writeFileCollecting(files, moduleLoc + File.separator + "p3" + File.separator + "p4" + File.separator + "p5", "X.java", + "package p3.p4.p5;\n"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 2)\n" + + " exports p1;\n" + + " ^^\n" + + "The package p1 does not exist or is empty\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 3)\n" + + " exports p2;\n" + + " ^^\n" + + "The package p2 does not exist or is empty\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "package is empty", + OUTPUT_DIR + File.separator + out); + } + /* + * Test that when module-info is the only file being compiled, the class is still + * generated inside the module's sub folder. + */ + public void testBug500170a() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.sql;\n" + + "}"); + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java"); + + Set classFiles = runConformModuleTest( + new String[0], + buffer.toString(), + "", + "", + false); + String fileName = OUTPUT_DIR + File.separator + out + File.separator + "mod.one" + File.separator + "module-info.class"; + assertClassFile("Missing modul-info.class: " + fileName, fileName, classFiles); + } + /* + * Test that no NPE is thrown when the module-info is compiled at a level below 9 + */ + public void testBug500170b() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.sql;\n" + + "}"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -8") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" "); + + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 1)\n" + + " module mod.one { \n" + + " ^^^^^^\n" + + "Syntax error on token \"module\", package expected\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 1)\n" + + " module mod.one { \n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error on token(s), misplaced construct(s)\n" + + "----------\n" + + "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 2)\n" + + " requires java.sql;\n" + + " ^\n" + + "Syntax error on token \".\", , expected\n" + + "----------\n" + + "4. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/module-info.java (at line 3)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n" + + "4 problems (4 errors)\n", + false, + "modules are not supported"); + } + public void testBug522472c() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + File srcDir = new File(directory); + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, + "module-info.java", + "module mod.one { \n" + + " exports x.y.z;\n" + + " exports a.b.c;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "x" + File.separator + "y" + File.separator + "z", + "X.java", + "package x.y.z;\n"); + writeFileCollecting(files, moduleLoc + File.separator + "a" + File.separator + "b" + File.separator + "c", + "A.java", + "package a.b.c;\n" + + "public class A {}"); + + moduleLoc = directory + File.separator + "mod.one.a"; + writeFileCollecting(files, moduleLoc, + "module-info.java", + "module mod.one.a { \n" + + " exports x.y.z;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "x" + File.separator + "y" + File.separator + "z", + "X.java", + "package x.y.z;\n" + + "public class X {}\n"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" "); + + runConformModuleTest(files, + buffer, + "", + "", + false); + + Util.flushDirectoryContent(srcDir); + files.clear(); + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, + "module-info.java", + "module mod.two { \n" + + " requires mod.one;\n" + + " requires mod.one.a;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "r", + "Main.java", + "package p.q.r;\n" + + "import a.b.c.*;\n" + + "import x.y.z.*;\n" + + "@SuppressWarnings(\"unused\")\n" + + "public class Main {" + + "}"); + buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-path " + "\"" + OUTPUT_DIR + File.separator + out + "\" ") + .append(" --module-source-path " + "\"" + directory + "\" "); + runNegativeModuleTest(files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/module-info.java (at line 2)\n" + + " requires mod.one;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The package x.y.z is accessible from more than one module: mod.one, mod.one.a\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/module-info.java (at line 3)\n" + + " requires mod.one.a;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The package x.y.z is accessible from more than one module: mod.one, mod.one.a\n" + + "----------\n" + + "2 problems (2 errors)\n", + false, + "module mod.two reads package x.y.z from both mod.one and mod.one.a"); + } + public void testReleaseOption1() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 8 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + String expectedOutput = "// Compiled from X.java (version 1.8 : 52.0, super bit)"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + public void testReleaseOption2() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 7 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + String expectedOutput = "// Compiled from X.java (version 1.7 : 51.0, super bit)"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + public void testReleaseOption3() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 7 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + String expectedOutput = "// Compiled from X.java (version 1.7 : 51.0, super bit)"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + public void testReleaseOption4() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 6 -source 1.6 -d \"" + OUTPUT_DIR + "\"", + "", + "option -source is not supported when --release is used\n", + true); + } + public void testReleaseOption5() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 8 -target 1.8 -d \"" + OUTPUT_DIR + "\"", + "", + "option -target is not supported when --release is used\n", + true); + } + public void testReleaseOption6() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 5 -d \"" + OUTPUT_DIR + "\"", + "", + "release 5 is not found in the system\n", + true); + } + public void testReleaseOption7() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.stream.*;\n" + + "/** */\n" + + "public class X {\n" + + " public Stream emptyStream() {\n" + + " Stream st = Stream.empty();\n" + + " return st;\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 8 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + } + public void testReleaseOption8() throws Exception { + + String output = + isJRE12Plus ? + " public java.util.stream.Stream emptyStream() {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "java.util.stream cannot be resolved to a type\n" : + " public java.util.stream.Stream emptyStream() {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "java.util.stream.Stream cannot be resolved to a type\n"; + + this.runNegativeTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + " public java.util.stream.Stream emptyStream() {\n" + + " return null;\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 7 -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" + + output + + "----------\n" + + "1 problem (1 error)\n", + true); + } + public void testReleaseOption9() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int add(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (x, y) -> {\n" + + " return x + y;\n" + + " };\n" + + " }\n" + + "}\n", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 7 -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 6)\n" + + " I i = (x, y) -> {\n" + + " ^^^^^^^^^\n" + + "Lambda expressions are allowed only at source level 1.8 or above\n" + + "----------\n" + + "1 problem (1 error)\n", + true); + } + public void testReleaseOption10() throws Exception { + if (isJRE12Plus) return; + 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" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 6 -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 9)\n" + + " } catch(IOException | FileNotFoundException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Multi-catch parameters are not allowed for source level below 1.7\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 9)\n" + + " } catch(IOException | FileNotFoundException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The exception FileNotFoundException is already caught by the alternative IOException\n" + + "----------\n" + + "2 problems (2 errors)\n", + true); + } + public void testReleaseOption11() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " -bootclasspath " + OUTPUT_DIR + File.separator + "src " + + " --release 9 -d \"" + OUTPUT_DIR + "\"", + "", + "option -bootclasspath not supported at compliance level 9 and above\n", + true); + } + public void _testReleaseOption12() throws Exception { + String javaHome = System.getProperty("java.home"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --system \"" + javaHome + "\"" + + " --release 6 -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "option --system not supported below compliance level 9", + true); + } + public void testReleaseOption13() { + runConformModuleTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}", + "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + "}" + }, + " --release 9 \"" + OUTPUT_DIR + File.separator + "module-info.java\" " + + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"", + "", + "", + true); + } + public void testReleaseOption13a() { + Runner runner = new Runner(); + runner.createFile( + OUTPUT_DIR +File.separator+"p", "X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}"); + runner.createFile( + OUTPUT_DIR, "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + "}"); + runner.commandLine.append(" --release 10"); + runner.javacTestOptions = new JavacTestOptions(ClassFileConstants.JDK10); + runner.runConformModuleTest(); + } + public void testReleaseOption14() { + runNegativeModuleTest( + new String[] { + "module-info.java", + "module mod.one { \n" + + "}" + }, + " --release 8 \"" + OUTPUT_DIR + File.separator + "module-info.java\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/module-info.java (at line 1)\n" + + " module mod.one { \n" + + " ^^^^^^\n" + + "Syntax error on token \"module\", package expected\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/module-info.java (at line 1)\n" + + " module mod.one { \n" + + "}\n" + + " ^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + + "2 problems (2 errors)\n", + true, + /*not tested with javac*/""); + } + // Test from https://bugs.eclipse.org/bugs/show_bug.cgi?id=526997 + public void testReleaseOption15() { + Runner runner = new Runner(); + String fooDir = OUTPUT_DIR + File.separator + "foo"; + runner.createFile( + fooDir, "Module.java", + "package foo;\n" + + "public class Module {}\n"); + runner.createFile( + fooDir, "X.java", + "package foo;\n" + + "public class X { \n" + + " public Module getModule(String name) {\n" + + " return null;\n" + + " }\n" + + "}"); + runner.commandLine.append(" --release 8 "); + runner.runConformModuleTest(); + } + // Test from https://bugs.eclipse.org/bugs/show_bug.cgi?id=526997 + public void testReleaseOption16() { + runNegativeModuleTest( + new String[] { + "foo/Module.java", + "package foo;\n" + + "public class Module {}\n", + "bar/X.java", + "package bar;\n" + + "import foo.*;\n" + + "public class X { \n" + + " public Module getModule(String name) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + " -source 9 \"" + OUTPUT_DIR + File.separator + "foo" + File.separator + "Module.java\" " + + "\"" + OUTPUT_DIR + File.separator + "bar" + File.separator + "X.java\" ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/bar/X.java (at line 4)\n" + + " public Module getModule(String name) {\n" + + " ^^^^^^\n" + + "The type Module is ambiguous\n" + + "----------\n" + + "1 problem (1 error)\n", + true, + /*not tested with javac*/""); + } + public void testReleaseOption17() { + runNegativeModuleTest( + new String[] { + "foo/Module.java", + "package foo;\n" + + "public class Module {}\n", + "foo/X.java", + "package foo;\n" + + "public class X { \n" + + " public Module getModule(String name) {\n" + + " return null;\n" + + " }\n" + + "}" + }, + " --release 60 \"" + OUTPUT_DIR + File.separator + "foo" + File.separator + "Module.java\" " + + "\"" + OUTPUT_DIR + File.separator + "foo" + File.separator + "X.java\" ", + "", + "release version 60 is not supported\n", + true, + /*not tested with javac*/""); + } + public void testReleaseOption18() { + runNegativeModuleTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + " --release 6 -1.8 \"" + OUTPUT_DIR + File.separator + "foo" + File.separator + "Module.java\" " + + "\"" + OUTPUT_DIR + File.separator + "foo" + File.separator + "X.java\" ", + "", + "option 1.8 is not supported when --release is used\n", + true, + /*not tested with javac*/""); + } + public void testReleaseOption19() { + runNegativeModuleTest( + new String[] { + "X.java", + "/** */\n" + + "public class X {\n" + + "}", + }, + " -9 --release 9 \"" + OUTPUT_DIR + File.separator + "foo" + File.separator + "Module.java\" " + + "\"" + OUTPUT_DIR + File.separator + "foo" + File.separator + "X.java\" ", + "", + "option 9 is not supported when --release is used\n", + true, + /*not tested with javac*/""); + } + public void testReleaseOption20() throws Exception { + if (!isJRE12Plus) return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String str = Integer.toUnsignedString(1, 1);\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 7 -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 5)\n" + + " String str = Integer.toUnsignedString(1, 1);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method toUnsignedString(int, int) is undefined for the type Integer\n" + + "----------\n" + + "1 problem (1 error)\n", + true); + } + public void testReleaseOption21() throws Exception { + if (!isJRE12Plus) return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer.toUnsignedString(1, 1);\n" + + " }\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "X.java\"" + + " --release 8 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + } + public void testReleaseOption22() { + if (isJRE11Plus || isJRE12Plus) return; + runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}", + "module-info.java", + "module mod.one { \n" + + " requires java.base;\n" + + " requires java.xml.ws.annotation;\n" + + "}" + }, + " --limit-modules java.base,java.xml.ws.annotation " + + " --release 10 \"" + OUTPUT_DIR + File.separator + "module-info.java\" " + + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/module-info.java (at line 3)\n" + + " requires java.xml.ws.annotation;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "The module java.xml.ws.annotation has been deprecated since version 9 and marked for removal\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); + } + public void testReleaseOption23() { + if (!isJRE11Plus) return; + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}", + "module-info.java", + "module mod.one { \n" + + " requires java.xml.ws.annotation;\n" + + "}" + }, + " --limit-modules java.base,java.xml.ws.annotation " + + " --release 11 \"" + OUTPUT_DIR + File.separator + "module-info.java\" " + + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"", + "", + "invalid module name: java.xml.ws.annotation\n", + true); + } + public void testReleaseOption24() { + if (!isJRE11Plus) return; + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "}", + "module-info.java", + "module mod.one { \n" + + " requires java.xml.ws.annotation;\n" + + "}" + }, + " --limit-modules java.base,java.xml.ws.annotation " + + " --release 12 \"" + OUTPUT_DIR + File.separator + "module-info.java\" " + + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"", + "", + "invalid module name: java.xml.ws.annotation\n", + true); + } + public void testLimitModules1() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.x"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.x { \n" + + " exports pm;\n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --limit-modules java.base") + .append(" --module-source-path " + "\"" + directory + "\""); + runNegativeModuleTest(files, buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.x/module-info.java (at line 3)\n" + + " requires java.sql;\n" + + " ^^^^^^^^\n" + + "java.sql cannot be resolved to a module\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "module not found"); + } + public void testLimitModules2() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.x"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.x { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "import java.sql.Connection;\n" + + "public class C1 {\n" + + "}\n"); + + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --limit-modules java.base") + .append(" --module-source-path " + "\"" + directory + "\""); + runNegativeModuleTest(files, buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.x/pm/C1.java (at line 2)\n" + + " import java.sql.Connection;\n" + + " ^^^^^^^^\n" + + "The import java.sql cannot be resolved\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "is not visible"); + } + public void testLimitModules3() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.x"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.x { \n" + + " exports pm;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pm", "C1.java", + "package pm;\n" + + "public class C1 {\n" + + "}\n"); + + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --limit-modules java.sql") + .append(" --module-source-path " + "\"" + directory + "\""); + runConformModuleTest(files, buffer, + "", + "", + false); + } + public void testLimitModules4() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" --module-path \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir.getAbsolutePath()) + .append("\" ") + .append(" --limit-modules mod.one,mod.two ") + .append(" --module-source-path " + "\"" + srcDir + "\" "); + runConformModuleTest(files, buffer, + "", + "", + false); + } + public void testLimitModules5() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " requires mod.one;\n" + + " requires mod.two;\n" + + "}"); + + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" --module-path \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir.getAbsolutePath()) + .append("\" ") + .append(" --limit-modules mod.one ") + .append(" --module-source-path " + "\"" + srcDir + "\" "); + runNegativeModuleTest(files, buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 3)\n" + + " requires mod.two;\n" + + " ^^^^^^^\n" + + "mod.two cannot be resolved to a module\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + ""); + } + public void testBug519600() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = srcDir + File.separator + "test"; + Runner runner = new Runner(); + runner.createFile(moduleLoc, "module-info.java", + "module test {}"); + runner.createFile(moduleLoc + File.separator + "test", "Thing.java", + "package test;\n" + + "import java.util.Comparator;\n" + + "import java.util.Iterator;\n" + + "public abstract class Thing implements Iterator {\n" + + " void breaking() {\n" + + " remove(); // allowed (good)\n" + + " Iterator.super.remove(); // not 1.7-compliant (must be an error)\n" + + " Comparator.naturalOrder(); // not 1.7-compliant (bad error message)\n" + + " }\n" + + "}\n"); + + runner.commandLine.append("-d " + outDir ) + .append(" -source 9 ") + .append(" --module-source-path " + "\"" + srcDir + "\" "); + runner.javacVersionOptions = "-Xlint:-options"; // -source 9 already provided + runner.runConformModuleTest(); + } + public void testBug508889_001() throws Exception { + this.runConformTest( + new String[] { + "module-info.java", + "module mymodule {\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "module-info.java\"" + + " -9 -source 9 -target 9 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + String expectedOutput = "// Compiled from module-info.java (version 9 : 53.0, no super bit)\n" + + " module mymodule {\n" + + " // Version: \n" + + "\n" + + " requires java.base;\n" + + "\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "module-info.class", "module-info", expectedOutput); + } + public void testBug508889_002() throws Exception { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports pack1;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pack1", "X11.java", + "package pack1;\n" + + "public class X11 {\n" + + "}"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" "); + + runConformModuleTest(files, + buffer, + "", + "", + false); + String expectedOutput = "// Compiled from module-info.java (version 9 : 53.0, no super bit)\n" + + " module mod.one {\n" + + " // Version: \n" + + "\n" + + " requires java.base;\n" + + "\n" + + " exports pack1;\n" + + "\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + out + File.separator + "module-info.class", "module-info", expectedOutput); + } + public void testBug508889_003() throws Exception { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports pack1;\n" + + " exports pack2 to second;\n" + + " opens pack3;\n" + + " opens pack4 to third;\n" + + " uses pack5.X51;\n" + + " provides pack1.I11 with pack1.X11;\n" + + " requires transitive java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pack1", "I11.java", + "package pack1;\n" + + "public interface I11 {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pack1", "X11.java", + "package pack1;\n" + + "public class X11 implements I11{\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pack2", "X21.java", + "package pack2;\n" + + "public class X21 {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pack3", "X31.java", + "package pack3;\n" + + "public class X31 {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pack4", "X41.java", + "package pack4;\n" + + "public class X41 {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "pack5", "X51.java", + "package pack5;\n" + + "public class X51 {\n" + + "}"); + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" "); + files.forEach(name -> buffer.append(" \"" + name + "\"")); + runConformTest(new String[0], + buffer.toString(), + "", + "", + false); + String expectedOutput = "// Compiled from module-info.java (version 9 : 53.0, no super bit)\n" + + " module mod.one {\n" + + " // Version: \n" + + "\n" + + " requires transitive java.sql;\n" + + " requires java.base;\n" + + "\n" + + " exports pack1;\n" + + " exports pack2 to second;\n" + + "\n" + + " opens pack3;\n" + + " opens pack4 to third;\n" + + "\n" + + " uses pack5.X51\n" + + "\n" + + " provides pack1.I11 with pack1.X11;\n" + + "\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + out + File.separator + "module-info.class", "module-info", expectedOutput); + } + public void testBug520858() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = srcDir + File.separator + "test"; + Runner runner = new Runner(); + runner.createFile(moduleLoc, "module-info.java", + "module test {\n" + + " requires org.astro;\n" + + "}"); + runner.createFile(moduleLoc + File.separator + "p", "Test.java", + "package p;\n" + + "import org.astro.World;\n" + + "public class Test {\n" + + " World w = null;\n" + + "}"); + moduleLoc = srcDir + File.separator + "org.astro"; + runner.createFile(moduleLoc, "module-info.java", + "module org.astro {\n" + + " exports org.astro;\n" + + "}"); + runner.createFile(moduleLoc + File.separator + "org" + File.separator + "astro", "World.java", + "package org.astro;\n" + + "public interface World {\n" + + " public static String name() {\n" + + " return \"\";\n" + + " }\n" + + "}"); + runner.commandLine.append("-d " + outDir ) + .append(" -source 9 ") + .append(" --module-source-path " + "\"" + srcDir + "\" "); + runner.javacVersionOptions = " -Xlint:-options"; + runner.runConformModuleTest(); + } + public void testBug520858a() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = srcDir + File.separator + "test"; + Runner runner = new Runner(); + // not adding some files to the command line + writeFile(moduleLoc, "module-info.java", + "module test {\n" + + " requires org.astro;\n" + + "}"); + // the only file added: + runner.createFile(moduleLoc + File.separator + "p", "Test.java", + "package p;\n" + + "import org.astro.World;\n" + + "public class Test {\n" + + " World w = null;\n" + + "}"); + moduleLoc = srcDir + File.separator + "org.astro"; + writeFile(moduleLoc, "module-info.java", + "module org.astro {\n" + + " exports org.astro;\n" + + "}"); + writeFile(moduleLoc + File.separator + "org" + File.separator + "astro", "World.java", + "package org.astro;\n" + + "public interface World {\n" + + " public static String name() {\n" + + " return \"\";\n" + + " }\n" + + "}"); + runner.commandLine.append("-d " + outDir ) + .append(" -source 9 ") + .append(" --module-source-path " + "\"" + srcDir + "\" "); + runner.javacVersionOptions = " -Xlint:-options"; + runner.runConformModuleTest(); + } + public void testBug520858b() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = srcDir + File.separator + "test"; + Runner runner = new Runner(); + runner.createFile(moduleLoc, "module-info.java", + "module test {\n" + + " requires org.astro;\n" + + "}"); + runner.createFile(moduleLoc + File.separator + "p", "Test.java", + "package p;\n" + + "import org.astro.World;\n" + + "public class Test {\n" + + " World w = null;\n" + + "}"); + moduleLoc = srcDir + File.separator + "org.astro"; + // not adding this file to the command line (intentional?): + writeFile(moduleLoc, "module-info.java", + "module org.astro {\n" + + " exports org.astro;\n" + + "}"); + runner.createFile(moduleLoc + File.separator + "org" + File.separator + "astro", "World.java", + "package org.astro;\n" + + "public interface World {\n" + + " public static String name() {\n" + + " return \"\";\n" + + " }\n" + + "}"); + runner.commandLine.append("-d " + outDir ) + .append(" -source 9 ") + .append(" --module-source-path " + "\"" + srcDir + "\" "); + runner.javacVersionOptions = " -Xlint:-options"; + runner.runConformModuleTest(); + } + public void testBug520858c() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = srcDir + File.separator + "test"; + List files = new ArrayList<>(); + + writeFileCollecting(files, moduleLoc + File.separator + "p", "Test.java", + "package p;\n" + + "import org.astro.World;\n" + + "public class Test {\n" + + " World w = null;\n" + + "}"); + moduleLoc = srcDir + File.separator + "org.astro"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module org.astro {\n" + + " exports org.astro;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "org" + File.separator + "astro", "World.java", + "package org.astro;\n" + + "public interface World {\n" + + " public static String name() {\n" + + " return \"\";\n" + + " }\n" + + "}"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -source 9 ") + .append(" --module-source-path " + "\"" + srcDir + "\" "); + runNegativeModuleTest(files, buffer, + "", + "\'---OUTPUT_DIR_PLACEHOLDER---/src/test/p/Test.java\' does not belong to a module on the module source path\n", + false, + "not in a module on the module source path"); + } + public void testBug520858d() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = srcDir + File.separator + "test"; + List files = new ArrayList<>(); + + writeFileCollecting(files, moduleLoc + File.separator + "p", "Test.java", + "package p;\n" + + "import org.astro.World;\n" + + "public class Test {\n" + + " World w = null;\n" + + "}"); + moduleLoc = srcDir + File.separator + "org.astro"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module org.astro {\n" + + " exports org.astro;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "org" + File.separator + "astro", "World.java", + "package org.astro;\n" + + "public interface World {\n" + + " public static String name() {\n" + + " return \"\";\n" + + " }\n" + + "}"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -source 9 ") + .append(" --module-source-path " + "\"" + srcDir + "\" ") + .append(srcDir + File.separator + "org.astro" + File.separator + "org" + File.separator + "astro" + File.separator + "World.java ") + .append(srcDir + File.separator + "test" + File.separator + "p" + File.separator + "Test.java"); + runNegativeModuleTest(Collections.emptyList(), buffer, + "", + "\'---OUTPUT_DIR_PLACEHOLDER---/src/test/p/Test.java\' does not belong to a module on the module source path\n", + false, + "not in a module on the module source path"); + } + public void testBug520858e() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = srcDir + File.separator + "test"; + List files = new ArrayList<>(); + + writeFileCollecting(files, moduleLoc + File.separator + "p", "Test.java", + "package p;\n" + + "import org.astro.World;\n" + + "public class Test {\n" + + " World w = null;\n" + + "}"); + moduleLoc = srcDir + File.separator + "org.astro"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module org.astro {\n" + + " exports org.astro;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "org" + File.separator + "astro", "World.java", + "package org.astro;\n" + + "public interface World {\n" + + " public static String name() {\n" + + " return \"\";\n" + + " }\n" + + "}"); + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -source 9 ") + .append(" --module-source-path " + "\"" + srcDir + "\" ") + .append(srcDir + File.separator + "org.astro" + File.separator + "org" + File.separator + "astro" + File.separator + "World.java ") + .append(srcDir + File.separator + "org.astro" + File.separator + "module-info.java ") + .append(srcDir + File.separator + "test" + File.separator + "p" + File.separator + "Test.java"); + runNegativeModuleTest(Collections.emptyList(), buffer, + "", + "\'---OUTPUT_DIR_PLACEHOLDER---/src/test/p/Test.java\' does not belong to a module on the module source path\n", + false, + "not in a module on the module source path"); + } + public void testBug530575() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + File srcDir = new File(directory); + + String moduleLoc = directory + File.separator + "mod.x"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.x { \n" + + " exports px;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "px", "C1.java", + "package px;\n" + + "public class C1 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.y"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.y { \n" + + " exports py;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "py", "C1.java", + "package py;\n" + + "public class C1 {\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + for (String fileName : files) + buffer.append(" \"").append(fileName).append("\""); + runConformTest(new String[0], + buffer.toString(), + "", + "", + false); + Util.flushDirectoryContent(srcDir); + files.clear(); + writeFileCollecting(files, directory, "module-info.java", + "module test { \n" + + " requires mod.x;\n" + + " requires mod.y;\n" + + "}"); + writeFileCollecting(files, directory + File.separator + "p", "X.java", + "package p;\n" + + "public class X extends px.C1 { \n" + + " py.C1 c = null;\n" + + "}"); + buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-path " + "\"" + OUTPUT_DIR + File.separator + out + File.separator + "mod.x" + File.pathSeparator + OUTPUT_DIR + File.separator + out + File.separator + "mod.y" + "\""); + runConformModuleTest(files, + buffer, + "", + "", + false, + OUTPUT_DIR + "javac"); + } + /* + * Test that when module-info is not included in the command line, the class is still + * generated inside the module's sub folder. + */ + public void testBug533411() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " requires java.sql;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "Test.java", + "package p;\n" + + "public class Test {\n" + + " java.sql.Connection conn = null;\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "p" + File.separator + "Test.java"); + + Set classFiles = runConformModuleTest( + new String[0], + buffer.toString(), + "", + "", + false); + String fileName = OUTPUT_DIR + File.separator + out + File.separator + "mod.one" + File.separator + "module-info.class"; + assertClassFile("Missing modul-info.class: " + fileName, fileName, classFiles); + } + public void test_npe_bug535107() { + runConformModuleTest( + new String[] { + "p/X.java", + "package p;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.MODULE)\n" + + "public @interface X {\n" + + " ElementType value();\n" + + "}", + "module-info.java", + "import java.lang.annotation.*;\n" + + "@p.X(ElementType.MODULE)\n" + + "module mod.one { \n" + + "}" + }, + " -9 \"" + OUTPUT_DIR + File.separator + "module-info.java\" " + + "\"" + OUTPUT_DIR + File.separator + "p/X.java\"", + "", + "", + true); + } + public void testBug540067a() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java", + "/*nothing in it */"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "X.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java"); + + runConformModuleTest( + new String[0], + buffer.toString(), + "", + "", + false); + } + public void testBug540067b() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java", + "package p.q;"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "X.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java"); + + runConformModuleTest( + new String[0], + buffer.toString(), + "", + "", + false); + } + public void testBug540067c() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java", + "package p.q;\n" + + "class Test {}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "X.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java"); + + runConformModuleTest( + new String[0], + buffer.toString(), + "", + "", + false); + } + public void testBug540067d() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java", + "class Test {}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "X.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/q/Test.java (at line 1)\n" + + " class Test {}\n" + + " ^\n" + + "Must declare a named package because this compilation unit is associated to the named module \'mod.one\'\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "unnamed package is not allowed in named modules"); + } + public void testBug540067e() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p" + File.separator + "q", "Test.java", + "import java.lang.*;"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(moduleLoc + File.separator + "module-info.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "X.java ") + .append(moduleLoc + File.separator + "p" + File.separator + "q" + File.separator + "Test.java"); + + runNegativeModuleTest( + new String[0], + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.one/p/q/Test.java (at line 1)\n" + + " import java.lang.*;\n" + + " ^\n" + + "Must declare a named package because this compilation unit is associated to the named module \'mod.one\'\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "unnamed package is not allowed in named modules"); + } + public void testBug548195() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + String binDir = OUTPUT_DIR + File.separator + out; + buffer.append("-d " + binDir ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(" --module-version 47.11 "); + String outText = isJRE9Plus ? "" : "Could not invoke method java.lang.module.ModuleDescriptor.Version.parse(), cannot validate module version.\n"; + runConformModuleTest(files, buffer, outText, "", false); + + IClassFileReader cfr = ToolFactory.createDefaultClassFileReader(binDir + File.separator + "mod.one" + File.separator + "module-info.class", IClassFileReader.CLASSFILE_ATTRIBUTES); + assertNotNull("Error reading module-info.class", cfr); + IClassFileAttribute[] attrs = cfr.getAttributes(); + for (IClassFileAttribute attr : attrs) { + char[] name = attr.getAttributeName(); + if (CharOperation.equals(name, AttributeNamesConstants.ModuleName)) { + IModuleAttribute modAttr = (IModuleAttribute) attr; + String expectedVersion = isJRE9Plus ? "47.11" : ""; + assertEquals("version in attribute", expectedVersion, new String(modAttr.getModuleVersionValue())); + return; + } + } + fail("module attribute not found"); + } + public void testBug548195fail() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "X.java", + "package p;\n" + + "public class X {\n" + + "}"); + + StringBuffer buffer = new StringBuffer(); + String binDir = OUTPUT_DIR + File.separator + out; + buffer.append("-d " + binDir ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" -warn:-unused") + .append(" --module-source-path " + "\"" + directory + "\" ") + .append(" --module-version fourtyseven.11 "); + if (isJRE9Plus) { + runNegativeModuleTest(files, buffer, "", "fourtyseven.11: Version string does not start with a number\n", false, "bad value"); + } else { + runConformModuleTest(files, buffer, "Could not invoke method java.lang.module.ModuleDescriptor.Version.parse(), cannot validate module version.\n", "", false); + } + } + public void testPackageTypeConflict2() { + File outputDirectory = new File(OUTPUT_DIR); + Util.flushDirectoryContent(outputDirectory); + String out = "bin"; + String directory = OUTPUT_DIR + File.separator + "src"; + + String moduleLoc = directory + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p1.p2;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p1" + File.separator + "p2", "t3.java", + "package p1.p2;\n" + + "public class t3 {\n" + + "}\n"); + + moduleLoc = directory + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " exports p1.p2.t3;\n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p1" + File.separator + "p2" + File.separator + "t3", "t4.java", + "package p1.p2.t3;\n" + + "public class t4 {\n" + + "}\n"); + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + OUTPUT_DIR + File.separator + out ) + .append(" -9 ") + .append(" -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + directory + "\""); + + runNegativeModuleTest( + files, + buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/p1/p2/t3/t4.java (at line 1)\n" + + " package p1.p2.t3;\n" + + " ^^^^^^^^\n" + + "The package p1.p2.t3 collides with a type\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + "package p1.p2.t3 clashes with class of same name"); + } + public void testBug550178() throws Exception { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + createReusableModules(srcDir, outDir, modDir); + String moduleLoc = srcDir + File.separator + "mod.three"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.three { \n" + + " exports pkg.invalid;\n" + + "}"); + + + StringBuffer buffer = new StringBuffer(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" --module-path \"") + .append(Util.getJavaClassLibsAsString()) + .append(modDir.getAbsolutePath()) + .append("\" ") + .append(" --module-source-path " + "\"" + srcDir + "\" "); + runNegativeModuleTest(files, buffer, + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.three/module-info.java (at line 2)\n" + + " exports pkg.invalid;\n" + + " ^^^^^^^^^^^\n" + + "The package pkg.invalid does not exist or is empty\n" + + "----------\n" + + "1 problem (1 error)\n", + false, + ""); + } + public void testRelease565930_1() throws Exception { + this.runConformTest( + new String[] { + "Dummy.java", + "public class Dummy {\n" + + " boolean b = new String(\"a\").contains(\"b\");\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "Dummy.java\"" + + " --release 9 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + } + public void testRelease565930_2() throws Exception { + this.runConformTest( + new String[] { + "Main.java", + "public final class Main {\n" + + " public void test() {\n" + + " final ClassLoader classLoader = this.getClass().getClassLoader();\n" + + " } \n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "Main.java\"" + + " --release 9 -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/Main.java (at line 3)\n" + + " final ClassLoader classLoader = this.getClass().getClassLoader();\n" + + " ^^^^^^^^^^^\n" + + "The value of the local variable classLoader is not used\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); + } + public void testBug571363() throws Exception { + if (!isJRE12Plus) return; + this.runConformTest( + new String[] { + "A.java", + "public final class A {\n" + + " org.w3c.dom.Element list;\n" + + "}", + }, + "\"" + OUTPUT_DIR + File.separator + "A.java\"" + + " -classpath " + "\"" + this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test571363.jar\"" + + " --release 11 -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + } + public void _testBug574097() { // GROOVY no APT + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String outDir = OUTPUT_DIR + File.separator + "bin"; + String srcDir = OUTPUT_DIR + File.separator + "src"; + File modDir = new File(OUTPUT_DIR + File.separator + "mod"); + String moduleLoc = srcDir + File.separator + "mod.one"; + List files = new ArrayList<>(); + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.one { \n" + + " exports p;\n" + + " requires transitive java.compiler;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "p", "TestProcessor.java", + "package p;\n" + + "import java.util.Set;\n" + + "import javax.annotation.processing.AbstractProcessor;\n" + + "import javax.annotation.processing.RoundEnvironment;\n" + + "import javax.lang.model.element.TypeElement;\n" + + "public class TestProcessor extends AbstractProcessor {\n" + + " @Override\n" + + " public boolean process(Set annotations, RoundEnvironment roundEnv) {\n" + + " return false;\n" + + " }\n" + + "}"); + + StringBuilder buffer = new StringBuilder(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" --module-path \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + srcDir + "\""); + for (String fileName : files) + buffer.append(" \"").append(fileName).append("\""); + + runConformTest(new String[]{}, + buffer.toString(), + "", + "", + false); + String jarName = modDir + File.separator + "mod.one.jar"; + try { + Util.zip(new File(outDir + File.separator + "mod.one"), + jarName); + } catch (IOException e) { + e.printStackTrace(); + } + if (!modDir.exists()) { + if (!modDir.mkdirs()) { + fail("Coult not create folder " + modDir); + } + } + Util.flushDirectoryContent(new File(srcDir)); + files = new ArrayList<>(); + moduleLoc = srcDir + File.separator + "mod.two"; + writeFileCollecting(files, moduleLoc, "module-info.java", + "module mod.two { \n" + + " exports q;\n" + + " requires java.base;\n" + + " requires mod.one;\n" + + "}"); + writeFileCollecting(files, moduleLoc + File.separator + "q", "A.java", + "package q;\n" + + "public class A {\n" + + " p.TestProcessor prc = null;\n" + + "}"); + buffer = new StringBuilder(); + buffer.append("-d " + outDir ) + .append(" -9 ") + .append(" --module-path \"") + .append(Util.getJavaClassLibsAsString()) + .append("\" ") + .append(" --module-source-path " + "\"" + srcDir + "\"") + .append(" --processor-module-path " + "\"" + jarName + "\""); + for (String name : files) + buffer.append(" \"").append(name).append("\""); + + runNegativeTest(new String[]{}, + buffer.toString(), + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/module-info.java (at line 4)\n" + + " requires mod.one;\n" + + " ^^^^^^^\n" + + "mod.one cannot be resolved to a module\n" + + "----------\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/mod.two/q/A.java (at line 3)\n" + + " p.TestProcessor prc = null;\n" + + " ^\n" + + "p cannot be resolved to a type\n" + + "----------\n" + + "2 problems (2 errors)\n", + false); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MultiReleaseJarTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MultiReleaseJarTests.java new file mode 100644 index 0000000000..f73a063c94 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MultiReleaseJarTests.java @@ -0,0 +1,212 @@ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; + +import org.eclipse.jdt.core.tests.util.Util; + +import junit.framework.Test; + +public class MultiReleaseJarTests extends AbstractBatchCompilerTest { + + private boolean isJRE10 = false; + public MultiReleaseJarTests(String name) { + super(name); + try { + Object valueOf = javax.lang.model.SourceVersion.valueOf("RELEASE_10"); + if (valueOf != null) this.isJRE10 = true; + } catch (Exception ignore) { + } + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); + } + + public static Class testClass() { + return MultiReleaseJarTests.class; + } + + public void test001() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar"; + String[] libs = new String[1]; + libs[0] = path; + runNegativeTest( + new String[] { + "src/X.java", + "import a.b.c.MultiVersion1.Inner;\n" + + "import p.q.r.MultiVersion2.Inner;\n" + + "public class X {\n" + + "}\n"}, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -classpath " + path + " --release 8 ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 1)\n" + + " import a.b.c.MultiVersion1.Inner;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import a.b.c.MultiVersion1.Inner cannot be resolved\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 2)\n" + + " import p.q.r.MultiVersion2.Inner;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import p.q.r.MultiVersion2.Inner cannot be resolved\n" + + "----------\n" + + "2 problems (2 errors)\n", + false + ); + } + public void test002() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar"; + String[] libs = new String[1]; + libs[0] = path; + runNegativeTest( + new String[] { + "src/X.java", + "import a.b.c.MultiVersion1.Inner;\n" + + "import p.q.r.MultiVersion2.Inner;\n" + + "public class X {\n" + + "}\n"}, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -classpath " + path + " --release 9 ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 1)\n" + + " import a.b.c.MultiVersion1.Inner;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type a.b.c.MultiVersion1.Inner is not visible\n" + + "----------\n" + + "1 problem (1 error)\n", + false + ); + } + public void test003() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar"; + String[] libs = new String[1]; + libs[0] = path; + runConformTest( + new String[] { + "src/X.java", + "import p.q.r.MultiVersion3.Inner;\n" + + "public class X {\n" + + " Inner i = null;\n" + + " p.q.r.MultiVersion2.Inner i2 = null;\n" + + "}\n"}, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -classpath " + path + " --release 9 ", + "", + "", + false + ); + } + public void test004() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar"; + String[] libs = new String[1]; + libs[0] = path; + runNegativeTest( + new String[] { + "src/X.java", + "import p.q.r.MultiVersion3.Inner;\n" + + "import p.q.r.MultiVersion2.Inner;\n" + + "public class X {\n" + + " Inner i = null;\n" + + "}\n"}, + "\"" + OUTPUT_DIR + File.separator + "src/X.java\"" + + " -classpath " + path + " --release 9 ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/X.java (at line 2)\n" + + " import p.q.r.MultiVersion2.Inner;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import p.q.r.MultiVersion2.Inner collides with another import statement\n" + + "----------\n" + + "1 problem (1 error)\n", + false + ); + } + public void test005() { + Util.flushDirectoryContent(new File(OUTPUT_DIR)); + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar"; + String[] libs = new String[1]; + libs[0] = path; + File directory = new File(OUTPUT_DIR + File.separator + "src" + File.separator + "MyModule" ); + File out = new File(OUTPUT_DIR + File.separator + "out" ); + if (!directory.exists()) { + if (!directory.mkdirs()) { + System.out.println("Could not create " + directory.toString()); + return; + } + } + if (!out.exists()) { + if (!out.mkdirs()) { + System.out.println("Could not create " + directory.toString()); + return; + } + } + runNegativeTest( + new String[] { + "src/MyModule/module-info.java", + "module MyModule {\n" + + " requires Version9;\n" + + "}", + "src/MyModule/p/X.java", + "package p;\n" + + "public class X {\n" + + " java.sql.Connection con = null;\n" + + "}\n"}, + " -d \"" + out.toString() + "\" " + + " --module-source-path \"" + directory.toString() + "\" " + + " \"" + OUTPUT_DIR + File.separator + "src" + File.separator + "MyModule" + File.separator + "module-info.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src" + File.separator + "MyModule" + File.separator + "p" + File.separator + "X.java\" " + + " --module-path " + path + " --release 9 ", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/src/MyModule/p/X.java (at line 3)\n" + + " java.sql.Connection con = null;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type java.sql.Connection is not accessible\n" + + "----------\n" + + "1 problem (1 error)\n", + false + ); + } + public void test006() { + if (!this.isJRE10) return; + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "multi.jar"; + String[] libs = new String[1]; + libs[0] = path; + File directory = new File(OUTPUT_DIR + File.separator + "src" + File.separator + "MyModule" ); + File out = new File(OUTPUT_DIR + File.separator + "out" ); + if (!directory.exists()) { + if (!directory.mkdirs()) { + System.out.println("Could not create " + directory.toString()); + return; + } + } + if (!out.exists()) { + if (!directory.mkdirs()) { + System.out.println("Could not create " + directory.toString()); + return; + } + } + runConformTest( + new String[] { + "src/MyModule/module-info.java", + "module MyModule {\n" + + " requires Version10;\n" + + "}", + "src/MyModule/p/X.java", + "package p;\n" + + "public class X {\n" + + " java.sql.Connection con = null;\n" + + "}\n"}, + " -d \"" + out.toString() + "\" " + + " --module-source-path \"" + directory.toString() + "\" " + + " \"" + OUTPUT_DIR + File.separator + "src" + File.separator + "MyModule" + File.separator + "module-info.java\"" + + " \"" + OUTPUT_DIR + File.separator + "src" + File.separator + "MyModule" + File.separator + "p" + File.separator + "X.java\" " + + " --module-path " + path + " --release 10 ", + "", + "", + false + ); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java new file mode 100644 index 0000000000..8dc580b3bb --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java @@ -0,0 +1,10090 @@ +/******************************************************************************* + * Copyright (c) 2011, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Jesper S Moller - Contributions for + * bug 382701 - [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expression + * bug 382721 - [1.8][compiler] Effectively final variables needs special treatment + * Bug 384687 - [1.8] Wildcard type arguments should be rejected for lambda and reference expressions + * Bug 404657 - [1.8][compiler] Analysis for effectively final variables fails to consider loops + * Stephan Herrmann - Contribution for + * bug 404649 - [1.8][compiler] detect illegal reference to indirect or redundant super via I.super.m() syntax + * bug 404728 - [1.8]NPE on QualifiedSuperReference error + * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) + * Bug 423504 - [1.8] Implement "18.5.3 Functional Interface Parameterization Inference" + * Bug 425156 - [1.8] Lambda as an argument is flagged with incompatible error + * Bug 426563 - [1.8] AIOOBE when method with error invoked with lambda expression as argument + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.IOException; +import java.util.Map; + +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.Excuse; +import org.eclipse.jdt.core.tests.junit.extension.TestCase; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class NegativeLambdaExpressionsTest extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test401610i"}; +// TESTS_NUMBERS = new int[] { 50 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public NegativeLambdaExpressionsTest(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} + +public static Test setUpTest(Test test) throws Exception { + TestCase.setUpTest(test); + RegressionTestSetup suite = new RegressionTestSetup(ClassFileConstants.JDK1_8); + suite.addTest(test); + return suite; +} + +@Override +protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + return defaultOptions; +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382818, ArrayStoreException while compiling lambda +public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int x, y;\n" + + " I i = () -> {\n" + + " int z = 10;\n" + + " };\n" + + " i++;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i = () -> {\n" + + " ^^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method foo(int, int)\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " i++;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from I to int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382841, ClassCastException while compiling lambda +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int x, y;\n" + + " I i = (p, q) -> {\n" + + " int r = 10;\n" + + " };\n" + + " i++;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " i++;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from I to int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382841, ClassCastException while compiling lambda +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int x, y;\n" + + " I i = null, i2 = (p, q) -> {\n" + + " int r = 10;\n" + + " }, i3 = null;\n" + + " i++;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " i++;\n" + + " ^^^\n" + + "Type mismatch: cannot convert from I to int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383046, syntax error reported incorrectly on syntactically valid lambda expression +public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "interface IX {\n" + + " public void foo();\n" + + "}\n" + + "public class X {\n" + + " IX i = () -> 42;\n" + + " int x\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " IX i = () -> 42;\n" + + " ^^\n" + + "Void methods cannot return a value\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " int x\n" + + " ^\n" + + "Syntax error, insert \";\" to complete FieldDeclaration\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383085 super::identifier not accepted. +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "interface IX{\n" + + " public void foo();\n" + + "}\n" + + "public class X {\n" + + " IX i = super::toString;\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=383046, syntax error reported incorrectly on *syntactically* valid reference expression +public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "interface One{}\n" + + "interface Two{}\n" + + "interface Three{}\n" + + "interface Four{}\n" + + "interface Five{}\n" + + "interface Blah{}\n" + + "interface Outer{interface Inner{interface Leaf{ void method(); } } }\n" + + "interface IX{\n" + + " public void foo();\n" + + "}\n" + + "public class X {\n" + + " IX i = Outer.Inner.Deeper>.Leaf::method;\n" + + " int x\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " IX i = Outer.Inner.Deeper>.Leaf::method;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The member type Outer.Inner cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type Outer\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " IX i = Outer.Inner.Deeper>.Leaf::method;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Outer.Inner.Deeper cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " IX i = Outer.Inner.Deeper>.Leaf::method;\n" + + " ^^^\n" + + "Six cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " int x\n" + + " ^\n" + + "Syntax error, insert \";\" to complete FieldDeclaration\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383096, NullPointerException with a wrong lambda code snippet +public void _test007() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "public class X {\n" + + " void foo() {\n" + + " I t1 = f -> {{};\n" + + " I t2 = () -> 42;\n" + + " } \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int\n" + + " ^^^\n" + + "Syntax error on token \"int\", delete this token\n" + + "----------\n" /* expected compiler log */, + true /* perform statement recovery */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383949, Explicit this parameter illegal in lambda expressions +public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo(X x);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (X this) -> 10; \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = (X this) -> 10; \n" + + " ^^^^\n" + + "Lambda expressions cannot declare a this parameter\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383949, Explicit this parameter illegal in lambda expressions +public void test009() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.awt.event.ActionListener;\n" + + "interface I {\n" + + " void doit(String s1, String s2);\n" + + "}\n" + + "public class X {\n" + + " public void test1(int x) {\n" + + " ActionListener al = (public xyz) -> System.out.println(xyz); \n" + + " I f = (abstract final s, @Nullable t) -> System.out.println(s + t); \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " ActionListener al = (public xyz) -> System.out.println(xyz); \n" + + " ^^^\n" + + "Syntax error, modifiers and annotations are not allowed for the lambda parameter xyz as its type is elided\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " I f = (abstract final s, @Nullable t) -> System.out.println(s + t); \n" + + " ^\n" + + "Syntax error, modifiers and annotations are not allowed for the lambda parameter s as its type is elided\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " I f = (abstract final s, @Nullable t) -> System.out.println(s + t); \n" + + " ^\n" + + "Syntax error, modifiers and annotations are not allowed for the lambda parameter t as its type is elided\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=381121, [] should be accepted in reference expressions. +public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo(int [] ia);\n" + + "}\n" + + "public class X {\n" + + " I i = (int [] ia) -> {\n" + + " return ia.clone();\n" + + " };\n" + + " I i2 = int[]::clone;\n" + + " Zork z;\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=382701, [1.8][compiler] Implement semantic analysis of Lambda expressions & Reference expressions. +public void test011() { + // This test checks that common semantic checks are indeed + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo(int [] ia);\n" + + "}\n" + + "public class X {\n" + + " I i = (int [] ia) -> {\n" + + " Zork z;\n" + // Error: No such type + " unknown = 0;\n;" + // Error: No such variable + " int a = 42 + ia;\n" + // Error: int + int[] is wrong + " return ia.clone();\n" + + " };\n" + + " static void staticLambda() {\n" + + " I i = (int [] ia) -> this;\n" + // 'this' is static + " }\n" + + " I j = array -> {\n" + + " int a = array[2] + 3;\n" + // No error, ia must be correctly identifies as int[] + " int b = 42 + array;\n" + // Error: int + int[] is wrong - yes it is! + " System.out.println(\"i(array) = \" + i.foo(array));\n" + // fields are accessible! + " return;\n" + // Error here, expecting Object, not void + " };\n" + + " Runnable r = () -> { return 42; };\n" + // Runnable.run not expecting return value + " void anotherLambda() {\n" + + " final int beef = 0;\n" + + " I k = (int [] a) -> a.length + beef;\n" + // No error, beef is in scope + " }\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" + + "2. ERROR in X.java (at line 7)\n" + + " unknown = 0;\n" + + " ^^^^^^^\n" + + "unknown cannot be resolved to a variable\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " ; int a = 42 + ia;\n" + + " ^^^^^^^\n" + + "The operator + is undefined for the argument type(s) int, int[]\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " I i = (int [] ia) -> this;\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n" + + "5. ERROR in X.java (at line 16)\n" + + " int b = 42 + array;\n" + + " ^^^^^^^^^^\n" + + "The operator + is undefined for the argument type(s) int, int[]\n" + + "----------\n" + + "6. ERROR in X.java (at line 18)\n" + + " return;\n" + + " ^^^^^^^\n" + + "This method must return a result of type Object\n" + + "----------\n" + + "7. ERROR in X.java (at line 20)\n" + + " Runnable r = () -> { return 42; };\n" + + " ^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n" +); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384600, [1.8] 'this' should not be allowed in lambda expressions in contexts that don't allow it +public void test012() { + // This test checks that common semantic checks are indeed + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " static void foo() {\n" + + " I i = () -> {\n" + + " System.out.println(this);\n" + + " I j = () -> {\n" + + " System.out.println(this);\n" + + " I k = () -> {\n" + + " System.out.println(this);\n" + + " };\n" + + " };\n" + + " };\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(this);\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " System.out.println(this);\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " System.out.println(this);\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384600, [1.8] 'this' should not be allowed in lambda expressions in contexts that don't allow it +public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " void foo(Zork z) {\n" + + " I i = () -> {\n" + + " System.out.println(this);\n" + + " I j = () -> {\n" + + " System.out.println(this);\n" + + " I k = () -> {\n" + + " System.out.println(this);\n" + + " };\n" + + " };\n" + + " };\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " void foo(Zork z) {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384595, Reject illegal modifiers on lambda arguments. +public void test014() { + String extra = this.complianceLevel < ClassFileConstants.JDK17 ? "" : + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" + + " ^^^^^^^^\n" + + "Floating-point expressions are always strictly evaluated from source level 17. Keyword \'strictfp\' is not required.\n"; + int offset = this.complianceLevel < ClassFileConstants.JDK17 ? 0 : 1; + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x, int y, int z); \n" + + "}\n" + + "public class X {\n" + + " I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" + + "}\n" + + "@interface Marker {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" + + " ^^^^^^^^^\n" + + "Undefined cannot be resolved to a type\n" + + extra + + "----------\n" + + (2 + offset) + ". ERROR in X.java (at line 5)\n" + + " I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter o is expected to be of type int\n" + + "----------\n" + + (3 + offset) + ". ERROR in X.java (at line 5)\n" + + " I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" + + " ^\n" + + "Illegal modifier for parameter o; only final is permitted\n" + + "----------\n" + + (4 + offset) + ". ERROR in X.java (at line 5)\n" + + " I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" + + " ^\n" + + "Illegal modifier for parameter p; only final is permitted\n" + + "----------\n" + + (5 + offset) + ". ERROR in X.java (at line 5)\n" + + " I i = (final @Marker int x, @Undefined static strictfp public Object o, static volatile int p) -> x;\n" + + " ^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399534, [1.8][compiler] Lambda parameters must be checked for compatibility with the single abstract method of the functional interface. +public void test015() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "interface I { void run(int x); }\n" + + "interface J { void run(int x, String s); }\n" + + "interface K { void run(Collection jobs); }\n" + + "class X {\n" + + " I i1 = (String y) -> {};\n" + + " I i2 = (y) -> {};\n" + + " I i3 = y -> {};\n" + + " I i4 = (int x, String y) -> {};\n" + + " I i5 = (int x) -> {};\n" + + " J j1 = () -> {};\n" + + " J j2 = (x, s) -> {};\n" + + " J j3 = (String x, int s) -> {};\n" + + " J j4 = (int x, String s) -> {};\n" + + " J j5 = x -> {};\n" + + " K k1 = (Collection l) -> {};\n" + + " K k2 = (Collection l) -> {};\n" + + " K k3 = (Collection l) -> {};\n" + + " K k4 = (List l) -> {};\n" + + " K k5 = (l) -> {};\n" + + " K k6 = l -> {};\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i1 = (String y) -> {};\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter y is expected to be of type int\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " I i4 = (int x, String y) -> {};\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method run(int)\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " J j1 = () -> {};\n" + + " ^^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method run(int, String)\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " J j3 = (String x, int s) -> {};\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter x is expected to be of type int\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " J j3 = (String x, int s) -> {};\n" + + " ^^^\n" + + "Lambda expression\'s parameter s is expected to be of type String\n" + + "----------\n" + + "6. ERROR in X.java (at line 16)\n" + + " J j5 = x -> {};\n" + + " ^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method run(int, String)\n" + + "----------\n" + + "7. WARNING in X.java (at line 17)\n" + + " K k1 = (Collection l) -> {};\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "8. ERROR in X.java (at line 17)\n" + + " K k1 = (Collection l) -> {};\n" + + " ^^^^^^^^^^\n" + + "Lambda expression\'s parameter l is expected to be of type Collection\n" + + "----------\n" + + "9. ERROR in X.java (at line 18)\n" + + " K k2 = (Collection l) -> {};\n" + + " ^^^^^^^^^^\n" + + "Lambda expression\'s parameter l is expected to be of type Collection\n" + + "----------\n" + + "10. ERROR in X.java (at line 20)\n" + + " K k4 = (List l) -> {};\n" + + " ^^^^\n" + + "Lambda expression\'s parameter l is expected to be of type Collection\n" + + "----------\n"); +} +// Bug 398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i1 = () -> 42;\n" + + " I i2 = () -> \"Hello\";\n" + + " I i3 = () -> { return 42; };\n" + + " I i4 = () -> { return \"Hello\"; };\n" + + " I i5 = () -> {};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i1 = () -> 42;\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " I i3 = () -> { return 42; };\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n"); +} +// Bug 398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test017() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i1 = () -> 42;\n" + + " I i2 = () -> \"Hello\";\n" + + " I i3 = () -> { return 42; };\n" + + " I i4 = () -> { return \"Hello\"; };\n" + + " I i5 = () -> {};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i2 = () -> \"Hello\";\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " I i4 = () -> { return \"Hello\"; };\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to Integer\n" + + "----------\n"); +} +// Bug 398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test018() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " I foo();\n" + + "}\n" + + "class P implements I {\n" + + " public I foo() { return null; }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i1 = () -> 42;\n" + + " I i2 = () -> \"Hello\";\n" + + " I i3 = () -> { return 42; };\n" + + " I i4 = () -> { return \"Hello\"; };\n" + + " I i5 = () -> { return new P(); };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i1 = () -> 42;\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to I\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " I i2 = () -> \"Hello\";\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to I\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " I i3 = () -> { return 42; };\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to I\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " I i4 = () -> { return \"Hello\"; };\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to I\n" + + "----------\n"); +} +// Bug 398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test019() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " I i1 = () -> 42;\n" + + " I i3 = () -> { return 42; };\n" + + " I i4 = () -> System.out.println();\n" + + " I i5 = () -> { System.out.println(); };\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " I i1 = () -> 42;\n" + + " ^^\n" + + "Void methods cannot return a value\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " I i3 = () -> { return 42; };\n" + + " ^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +// Bug 398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo(int x);\n" + + "}\n" + + "public class X {\n" + + " I i5 = (x) -> { if (x == 0) throw new NullPointerException(); };\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " I i5 = (x) -> { if (x == 0) throw new NullPointerException(); };\n" + + " ^^^^^^\n" + + "This method must return a result of type int\n" + + "----------\n"); +} +// Bug 398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test021() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo(int x);\n" + + "}\n" + + "public class X {\n" + + " I i5 = (x) -> { if (x == 0) throw new NullPointerException(); throw new NullPointerException(); };\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"); +} +// Bug 398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test022() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " J foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " I I = () -> () -> 10;\n" + + " Zork z;\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"); +} +// Bug 398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test023() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " J foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " I i1 = () -> 10;\n" + + " I i2 = () -> { return 10; };\n" + + " I i3 = () -> () -> 10;\n" + + " I i4 = () -> { return () -> 10; };\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " I i1 = () -> 10;\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to J\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " I i2 = () -> { return 10; };\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to J\n" + + "----------\n"); +} +// Bug 398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I3 {\n" + + " Object foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I3 i = () -> 42; // Warning: Autoboxing, but casting to Object??\n" + + " }\n" + + " Object foo(Zork z) {\n" + + " return 42;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Object foo(Zork z) {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test025() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\r\n" + + " String foo();\r\n" + + "}\r\n" + + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " I i = () -> 42;\r\n" + + " I i2 = () -> \"Hello, Lambda\";\r\n" + + " }\r\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = () -> 42;\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\r\n" + + " String foo();\r\n" + + "}\r\n" + + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " I i = () -> {\r\n" + + " return 42;\r\n" + + " };\r\n" + + " I i2 = () -> {\r\n" + + " return \"Hello, Lambda as a block!\";\r\n" + + " };\r\n" + + " }\r\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return 42;\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test027() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\r\n" + + " int baz();\r\n" + + "}\r\n" + + "public class X {\r\n" + + " public static void main(String[] args) {\n" + + " I i1 = () -> {\n" + + " System.out.println(\"No return\");\n" + + " }; // Error: Lambda block should return value\n" + + " I i2 = () -> {\n" + + " if (Math.random() < 0.5) return 42;\n" + + " }; // Error: Lambda block doesn't always return a value\n" + + " I i3 = () -> {\n" + + " return 42;\n" + + " System.out.println(\"Dead!\");\n" + + " }; // Error: Lambda block has dead code\n" + + " }\n" + + " public static I doesFlowInfoEscape() {\n" + + " I i1 = () -> {\n" + + " return 42;\n" + + " };\n" + + " return i1; // Must not complain about unreachable code!\n" + + " }\n" + + " public static I areExpresionsCheckedForReturns() {\n" + + " I i1 = () -> 42; // Must not complain about missing return!\n" + + " return i1;\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i1 = () -> {\n" + + " ^^^^^\n" + + "This method must return a result of type int\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " I i2 = () -> {\n" + + " ^^^^^\n" + + "This method must return a result of type int\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " System.out.println(\"Dead!\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +// Bug 399979 - [1.8][compiler] Statement expressions should be allowed in non-block lambda body when return type is void (edit) +public void test028() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " int data;\n" + + " public void main(String[] args) {\n" + + " I i1 = () -> data++;\n" + + " I i2 = () -> data = 10;\n" + + " I i3 = () -> data += 10;\n" + + " I i4 = () -> --data;\n" + + " I i5 = () -> bar();\n" + + " I i6 = () -> new X();\n" + + " I i7 = () -> 0;\n" + + " I i = () -> 1 + data++;\n" + + " }\n" + + " int bar() {\n" + + " return 0;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " I i7 = () -> 0;\n" + + " ^\n" + + "Void methods cannot return a value\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " I i = () -> 1 + data++;\n" + + " ^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +// Bug 384600 - [1.8] 'this' should not be allowed in lambda/Reference expressions in contexts that don't allow it +public void test029() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X extends Y {\n" + + " static void foo() {\n" + + " I i1 = this::zoo;\n" + + " I i2 = super::boo;\n" + + " I i3 = () -> super.zoo();\n" + + " I i4 = () -> this.boo();\n" + + " }\n" + + " void boo () {\n" + + " I i1 = this::zoo;\n" + + " I i2 = super::boo;\n" + + " I i3 = () -> super.zoo();\n" + + " I i4 = () -> this.boo();\n" + + " }\n" + + " void zoo() {\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " void boo() {\n" + + " }\n" + + " void zoo() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i1 = this::zoo;\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " I i2 = super::boo;\n" + + " ^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " I i3 = () -> super.zoo();\n" + + " ^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " I i4 = () -> this.boo();\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n"); +} +// Bug 382713 - [1.8][compiler] Compiler should reject lambda expressions when target type is not a functional interface +public void test030() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + " void goo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = () -> 10;\n" + + " I i = () -> 10;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X x = () -> 10;\n" + + " ^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " I i = () -> 10;\n" + + " ^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// Bug 398267 - [1.8][compiler] Variables in the body of the lambda expression should be valid +public void test031() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " public void main(String[] args) {\n" + + " I i = () -> {\n" + + " p = 10;\n" + + " Zork z = this.blank;\n" + + " super.foo();\n" + + " goo();\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " p = 10;\n" + + " ^\n" + + "p cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork z = this.blank;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork z = this.blank;\n" + + " ^^^^^\n" + + "blank cannot be resolved or is not a field\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " super.foo();\n" + + " ^^^\n" + + "The method foo() is undefined for the type Object\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " goo();\n" + + " ^^^\n" + + "The method goo() is undefined for the type X\n" + + "----------\n"); +} +// Bug 399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor +public void test032() { + this.runNegativeTest( + new String[] { + "X.java", + "interface IA {\r\n" + + " void snazz();\r\n" + + "}\r\n" + + "interface IB {\r\n" + + " void baz() throws java.io.IOException;\r\n" + + "}\r\n" + + "public class X {\r\n" + + " public static void main(String[] args) {\n" + + " IA i1 = () -> {\n" + + " throw new java.io.EOFException(); // Error: not declared\n" + + " };\n" + + " IB i2 = () -> {\n" + + " throw new java.io.EOFException(); // Fine: IOException is declared\n" + + " }; // No error, it's all good\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " throw new java.io.EOFException(); // Error: not declared\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type EOFException\n" + + "----------\n"); +} +// Bug 399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor +public void test033() { + this.runNegativeTest( + new String[] { + "X.java", + "interface IA {\r\n" + + " void snazz();\r\n" + + "}\r\n" + + "interface IB {\r\n" + + " void baz() throws java.io.IOException;\r\n" + + "}\r\n" + + "public class X {\r\n" + + " public static void main(String[] args) {\n" + + " IA i1 = () -> {\n" + + " throw new java.io.EOFException(); // Error: not declared\n" + + " };\n" + + " IB i2 = () -> {\n" + + " throw new java.io.EOFException(); // Fine: IOException is declared\n" + + " }; // No error, it's all good\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " throw new java.io.EOFException(); // Error: not declared\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type EOFException\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=398734 - [1.8][compiler] Lambda expression type or return type should be checked against the target functional interface method's result type +public void test034() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\r\n" + + " int foo(int x, int y);\r\n" + + "}\r\n" + + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " int x = 2;\r\n" + + " I i = (a, b) -> {\r\n" + + " return 42.0 + a + args.length; // Type mismatch: cannot convert from double to int\r\n" + + " };\r\n" + + " }\r\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " return 42.0 + a + args.length; // Type mismatch: cannot convert from double to int\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from double to int\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=381121, [] should be accepted in reference expressions. +public void test035() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo(int [] ia);\n" + + "}\n" + + "public class X {\n" + + " I i = (int [] ia) -> ia.clone();\n" + + " I i2 = int[]::clone;\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, Lambda expression parameters and locals cannot shadow variables from context +public void test036() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\r\n" + + " void foo(int x, int y);\r\n" + + "}\r\n" + + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " int x, y;\r\n" + + " I i = (x, y) -> { // Error: x,y being redeclared\r\n" + + " int args = 10; // Error args is being redeclared\r\n" + + " };\r\n" + + " }\r\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i = (x, y) -> { // Error: x,y being redeclared\n" + + " ^\n" + + "Lambda expression\'s parameter x cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " I i = (x, y) -> { // Error: x,y being redeclared\n" + + " ^\n" + + "Lambda expression\'s parameter y cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " int args = 10; // Error args is being redeclared\n" + + " ^^^^\n" + + "Lambda expression\'s local variable args cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382702 - [1.8][compiler] Lambda expressions should be rejected in disallowed contexts +public void test037() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\r\n" + + " int foo1(String x);\r\n" + + "}\r\n" + + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " System.out.println(\"Lambda in illegal context: \" + (() -> \"Illegal Lambda\"));\r\n" + + " System.out.println(\"Method Reference in illegal context: \" + System::exit);\r\n" + + " System.out.println(\"Constructor Reference in illegal context: \" + String::new);\r\n" + + " I sam1 = (x) -> x.length(); // OK\r\n" + +// " I sam2 = ((String::length)); // OK\r\n" + +// " I sam3 = (Math.random() > 0.5) ? String::length : String::hashCode; // OK\r\n" + +// " I sam4 = (I)(String::length); // OK\r\n" + + " int x = (x) -> 10;\n" + + " X x2 = (x) -> 10;\n" + + " }\r\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " System.out.println(\"Lambda in illegal context: \" + (() -> \"Illegal Lambda\"));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " System.out.println(\"Method Reference in illegal context: \" + System::exit);\n" + + " ^^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " System.out.println(\"Constructor Reference in illegal context: \" + String::new);\n" + + " ^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " int x = (x) -> 10;\n" + + " ^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " X x2 = (x) -> 10;\n" + + " ^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor +public void test038() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.EOFException;\n" + + "import java.io.IOException;\n" + + "interface I { void m() throws IOException; }\n" + + "interface J { void m() throws EOFException; }\n" + + "interface K { void m() throws ClassNotFoundException; }\n" + + "interface IJ extends I, J {}\n" + + "interface IJK extends I, J, K {}\n" + + "public class X {\n" + + " int var;\n" + + " IJ ij = () -> {\n" + + " if (var == 0) {\n" + + " throw new IOException();\n" + + " } else if (var == 2) {\n" + + " throw new EOFException();\n" + + " } else {\n" + + " throw new ClassNotFoundException(); \n" + + " }\n" + + " };\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " throw new IOException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " throw new ClassNotFoundException(); \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type ClassNotFoundException\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor +public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.EOFException;\n" + + "import java.io.IOException;\n" + + "import java.sql.SQLException;\n" + + "import java.sql.SQLTransientException;\n" + + "import java.util.List;\n" + + "import java.util.concurrent.TimeoutException;\n" + + "interface A {\n" + + " List foo(List arg) throws IOException, SQLTransientException;\n" + + "}\n" + + "interface B {\n" + + " List foo(List arg) throws EOFException, SQLException, TimeoutException;\n" + + "}\n" + + "interface C {\n" + + " List foo(List arg) throws Exception;\n" + + "}\n" + + "interface D extends A, B {}\n" + + "interface E extends A, B, C {}\n" + + "public class X {\n" + + " int var;\n" + + " D d = (x) -> {\n" + + " switch (var) {\n" + + " case 0 : throw new EOFException();\n" + + " case 1: throw new IOException();\n" + + " case 2: throw new SQLException();\n" + + " case 3: throw new SQLTransientException();\n" + + " case 4: throw new TimeoutException();\n" + + " default: throw new NullPointerException();\n" + + " }\n" + + " };\n" + + " E e = (x) -> {\n" + + " switch (var) {\n" + + " case 0 : throw new EOFException();\n" + + " case 1: throw new IOException();\n" + + " case 2: throw new SQLException();\n" + + " case 3: throw new SQLTransientException();\n" + + " case 4: throw new TimeoutException();\n" + + " default: throw new NullPointerException();\n" + + " }\n" + + " };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " List foo(List arg) throws EOFException, SQLException, TimeoutException;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " List foo(List arg) throws Exception;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " List foo(List arg) throws Exception;\n" + + " ^^^^\n" + + "List is a raw type. References to generic type List should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 23)\n" + + " case 1: throw new IOException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n" + + "5. ERROR in X.java (at line 24)\n" + + " case 2: throw new SQLException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type SQLException\n" + + "----------\n" + + "6. ERROR in X.java (at line 26)\n" + + " case 4: throw new TimeoutException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type TimeoutException\n" + + "----------\n" + + "7. ERROR in X.java (at line 33)\n" + + " case 1: throw new IOException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n" + + "8. ERROR in X.java (at line 34)\n" + + " case 2: throw new SQLException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type SQLException\n" + + "----------\n" + + "9. ERROR in X.java (at line 36)\n" + + " case 4: throw new TimeoutException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type TimeoutException\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor +public void test040() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + "

    Object m() throws P;\n" + + "}\n" + + "interface J {\n" + + " String m() throws Exception;\n" + + "}\n" + + "interface G extends I, J {}\n" + + "public class X {\n" + + " int var;\n" + + " G g1 = () -> {\n" + + " throw new Exception(); \n" + + " };\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " G g1 = () -> {\n" + + " ^^^^^\n" + + "Illegal lambda expression: Method m of type J is generic \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor +public void test041() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.sql.SQLException;\n" + + "interface G1 {\n" + + " Object m(E p) throws E;\n" + + "}\n" + + "interface G2 {\n" + + " String m(F q) throws Exception;\n" + + "}\n" + + "interface G extends G1, G2 {} // G has descriptor ()->String throws F\n" + + "public class X {\n" + + " G g = (x) -> { // Elided type is inferred from descriptor to be F\n" + + " throw x; // ~== throw new F()\n" + + " };\n" + + "}\n" + + "class Y implements G {\n" + + " public String m(T t) throws T {\n" + + " throw t;\n" + + " }\n" + + " void foo(G1 g1) {\n" + + " g1.m(new IOException());\n" + + " }\n" + + " void foo(G2 g2) {\n" + + " g2.m(new SQLException());\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " G g = (x) -> { // Elided type is inferred from descriptor to be F\n" + + " ^^^^^^\n" + + "Illegal lambda expression: Method m of type G2 is generic \n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " g1.m(new IOException());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " g2.m(new SQLException());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399537 - [1.8][compiler] Exceptions thrown from lambda body must match specification per function descriptor +public void test042() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.sql.SQLException;\n" + + "interface G1 {\n" + + " Object m(E p) throws E;\n" + + "}\n" + + "interface G2 {\n" + + " String m(F q) throws Exception;\n" + + "}\n" + + "interface G extends G1, G2 {} // G has descriptor ()->String throws F\n" + + "public class X {\n" + + " G g1 = (F x) -> {\n" + + " throw x;\n" + + " };\n" + + " G g2 = (IOException x) -> {\n" + + " throw x;\n" + + " };\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " G g1 = (F x) -> {\n" + + " ^^^^^^^^\n" + + "Illegal lambda expression: Method m of type G2 is generic \n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " G g1 = (F x) -> {\n" + + " ^\n" + + "F cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " G g2 = (IOException x) -> {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Illegal lambda expression: Method m of type G2 is generic \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399224 - [1.8][compiler][internal] Implement TypeBinding.getSingleAbstractMethod +public void test043() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportTypeParameterHiding, CompilerOptions.IGNORE); + + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface A { void foo(); }\n" + // yes + "interface B { boolean equals(Object obj); }\n" + // no + "interface C extends B { void foo(); }\n" + // yes + "interface D { boolean equals(Object obj); void foo(); }\n" + // yes + "interface E { void foo(); Object clone(); }\n" + // no + "interface F { void foo(List p); }\n" + // yes + "interface G { void foo(List p); }\n" + // yes + "interface H extends F, G {}\n" + // yes + "interface I { List foo(List p); }\n" + // yes + "interface J { List foo(List arg); }\n" + // yes + "interface K extends I, J {}\n" + // yes + "interface L { void foo(List p); }\n" + // yes + "interface M extends I, L {}\n" + // no + "interface N { void foo(List p, Class q); }\n" + // yes + "interface O { void foo(List p, Class q); }\n" + // yes + "interface P extends N, O {}\n" + // no + "interface Q { long foo(); }\n" + // yes + "interface R { int foo(); }\n" + // yes + "interface S extends Q, R {}\n" + // no + "interface T

    { void foo(P p); }\n" + // yes + "interface U

    { void foo(P p); }\n" + // yes + "interface V extends T

    , U {}\n" + // no + "interface W { void m(T arg); void m(N arg); }\n" + // no + "interface X extends W {}\n" + // no + "interface Y extends W {}\n" + // yes + + "class Z {\n" + + " A a = () -> {};\n" + + " B b = () -> {};\n" + + " C c = () -> {};\n" + + " D d = () -> {};\n" + + " E e = () -> {};\n" + + " F f = (p0) -> {};\n" + + " G g = (p0) -> {};\n" + + " H h = (p0) -> {};\n" + + " I i = (p0) -> { return null; };\n" + + " J j = (p0) -> { return null; };\n" + + " K k = (p0) -> { return null; };\n" + + " L l = (p0) -> {};\n" + + " M m = (p0) -> {};\n" + + " N n = (p0, q0) -> {};\n" + + " O o = (p0, q0) -> {};\n" + + " P p = (p0, q0) -> {};\n" + + " Q q = () -> { return 0;};\n" + + " R r = () -> { return 0;};\n" + + " S s = () -> {};\n" + + " T t = (p0) -> {};\n" + + " U u = (p0) -> {};\n" + + " V v = (p0) -> {};\n" + + " W w = (p0) -> {};\n" + + " X x = (p0) -> {};\n" + + " Y y = (p0) -> {};\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " interface P extends N, O {}\n" + + " ^\n" + + "Name clash: The method foo(List, Class) of type O has the same erasure as foo(List, Class) of type N but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " interface S extends Q, R {}\n" + + " ^\n" + + "The return types are incompatible for the inherited methods Q.foo(), R.foo()\n" + + "----------\n" + + "3. ERROR in X.java (at line 23)\n" + + " interface V extends T

    , U {}\n" + + " ^\n" + + "Name clash: The method foo(P) of type U

    has the same erasure as foo(P) of type T

    but does not override it\n" + + "----------\n" + + "4. ERROR in X.java (at line 29)\n" + + " B b = () -> {};\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "5. ERROR in X.java (at line 32)\n" + + " E e = () -> {};\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "6. ERROR in X.java (at line 40)\n" + + " M m = (p0) -> {};\n" + + " ^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "7. ERROR in X.java (at line 43)\n" + + " P p = (p0, q0) -> {};\n" + + " ^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "8. ERROR in X.java (at line 46)\n" + + " S s = () -> {};\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "9. ERROR in X.java (at line 49)\n" + + " V v = (p0) -> {};\n" + + " ^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "10. ERROR in X.java (at line 50)\n" + + " W w = (p0) -> {};\n" + + " ^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "11. ERROR in X.java (at line 51)\n" + + " X x = (p0) -> {};\n" + + " ^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n", + null, + false, + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399224 - [1.8][compiler][internal] Implement TypeBinding.getSingleAbstractMethod +public void test044() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportTypeParameterHiding, CompilerOptions.IGNORE); + + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface A { T foo(List p); }\n" + + "interface B { S foo(List p); }\n" + + "interface C { S foo(List p); }\n" + + "interface D extends A, B {}\n" + + "interface E extends A, C {}\n" + + + "class Z {\n" + + " A a = (p) -> { return null;};\n" + + " B b = (p) -> { return null;};\n" + + " C c = (p) -> { return null;};\n" + + " D d = (p) -> { return null;};\n" + + " E e = (p) -> { return null;};\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " interface E extends A, C {}\n" + + " ^\n" + + "Name clash: The method foo(List) of type C has the same erasure as foo(List) of type A but does not override it\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " A a = (p) -> { return null;};\n" + + " ^^^^^^\n" + + "Illegal lambda expression: Method foo of type A is generic \n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " B b = (p) -> { return null;};\n" + + " ^^^^^^\n" + + "Illegal lambda expression: Method foo of type B is generic \n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " C c = (p) -> { return null;};\n" + + " ^^^^^^\n" + + "Illegal lambda expression: Method foo of type C is generic \n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " D d = (p) -> { return null;};\n" + + " ^^^^^^\n" + + "Illegal lambda expression: Method foo of type B is generic \n" + + "----------\n" + + "6. ERROR in X.java (at line 12)\n" + + " E e = (p) -> { return null;};\n" + + " ^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n", + null, + false, + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400386 - [1.8][spec] Broken example in 9.8, discussion box - bullet 2 ? +public void test045() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { Object m(); }\n" + + "interface J { S m(); }\n" + + "interface K { T m(); }\n" + + "interface Functional extends I, J, K {}\n" + + "class X {\n" + + " Functional f = () -> { };\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " interface Functional extends I, J, K {}\n" + + " ^^^^^^^^^^\n" + + "The return types are incompatible for the inherited methods I.m(), J.m(), K.m()\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Functional f = () -> { };\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +public void test046() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface A { void f(List ls); }\n" + + "interface B { void f(List li); }\n" + + "interface C extends A,B {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " interface C extends A,B {}\n" + + " ^\n" + + "Name clash: The method f(List) of type B has the same erasure as f(List) of type A but does not override it\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test047() { + // This test checks that the simple cases are OK + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int var = 2;\n" + + " I x = new I() {\n" + + " public void doit() {\n" + + " System.out.println(args); // OK: args is not re-assignment since declaration/first assignment\n" + + " System.out.println(var); // Error: var is not effectively final\n" + + " }\n" + + " };\n" + + " var=2;\n" + + " }\n" + + "}" , + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " System.out.println(var); // Error: var is not effectively final\n" + + " ^^^\n" + + "Local variable var defined in an enclosing scope must be final or effectively final\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test048() { + // This test checks that the simple cases are OK + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int var = 2;\n" + + " I x2 = () -> {\n" + + " System.out.println(var); // Error: var is not effectively final\n" + + " };\n" + + " var=2;\n" + + " }\n" + + "}" , + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(var); // Error: var is not effectively final\n" + + " ^^^\n" + + "Local variable var defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test049() { + // This test checks that the simple cases are OK + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int var = 2;\n" + + " I x2 = () -> {\n" + + " System.out.println(args); // OK: args is not re-assignment since declaration/first assignment\n" + + " };\n" + + " var=2;\n" + + " }\n" + + "}" , + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test050() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new java.io.File(\"dweep\").getCanonicalPath();\n" + + " } catch (java.io.IOException ioe) {\n" + + " I x2 = () -> {\n" + + " System.out.println(ioe.getMessage()); // OK: args is not re-assignment since declaration/first assignment\n" + + " };\n" + + " };\n"+ + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test051() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.List list = new java.util.ArrayList<>();\n" + + " for (String s : list) {\n" + + " I x2 = () -> {\n" + + " System.out.println(s); // OK: args is not re-assignment since declaration/first assignment\n" + + " };\n" + + " };\n" + + " }\n" + + "\n" + + "}\n" , + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test052() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.util.List list = new java.util.ArrayList<>();\n" + + " for (String s2 : list) {\n" + + " s2 = \"Nice!\";\n" + + " I x2 = () -> {\n" + + " System.out.println(s2); // Error: var is not effectively final\n" + + " };\n" + + " };\n" + + " }\n" + + "\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " System.out.println(s2); // Error: var is not effectively final\n" + + " ^^\n" + + "Local variable s2 defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test053() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " try {\n" + + " System.out.println(\"try\");\n" + + " } catch (NullPointerException | ArrayIndexOutOfBoundsException e) {\n" + + " I i = () -> {\n" + + " System.out.println(e);\n" + + " };\n" + + " }\n" + + " }\n" + + "}\n" , + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test054() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " void foo2(String[] args) {\n" + + " int var;\n" + + " if (args != null)\n" + + " var = args.length;\n" + + " else\n" + + " var = 2;\n" + + " I x = new I() {\n" + + " public void doit() {\n" + + " System.out.println(var);\n" + // no error here. + " args = null;\n" + // error here. + " }\n" + + " };\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " args = null;\n" + + " ^^^^\n" + + "Local variable args defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test055() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " void foo(final int x) {\n" + + " I i = () -> {\n" + + " x = 10;\n" + + " };\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " x = 10;\n" + + " ^\n" + + "The final local variable x cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test056() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " void foo(final int x) {\n" + + " X i = new X() {\n" + + " { x = 10; }\n" + + " };\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " { x = 10; }\n" + + " ^\n" + + "The final local variable x cannot be assigned, since it is defined in an enclosing type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test057() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " void foo(int x) {\n" + + " I i = () -> {\n" + + " x = 10;\n" + + " };\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " x = 10;\n" + + " ^\n" + + "Local variable x defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test058() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " void foo(int x) {\n" + + " X i = new X() {\n" + + " { x = 10; }\n" + + " };\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " { x = 10; }\n" + + " ^\n" + + "Local variable x defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test059() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "class X {\n" + + " void foo(int [] p) {\n" + + " for (int is : p) {\n" + + " I j = new I () {\n" + + " public void foo() {\n" + + " System.out.println(is);\n" + + " };\n" + + " };\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test060() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "class X {\n" + + " void foo(int [] p) {\n" + + " for (int is : p) {\n" + + " I j = () -> {\n" + + " System.out.println(is);\n" + + " };\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test061() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " void foo2(String[] args) {\n" + + " int var;\n" + + " if (args != null)\n" + + " var = args.length;\n" + + " else\n" + + " var = 2;\n" + + " I x = () -> {\n" + + " System.out.println(var);\n" + // no error here. + " args = null;\n" + // error here. + " };\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " args = null;\n" + + " ^^^^\n" + + "Local variable args defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test062() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int var;\n" + + " if (args != null) {\n" + + " var = args.length;\n" + + " I x = new I() {\n" + + " public void doit() {\n" + + " System.out.println(var);\n" + + " }\n" + + " };\n" + + " } else {\n" + + " var = 2; // HERE\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test063() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) throws IOException {\n" + + "\n" + + " try {\n" + + " throw new IOException();\n" + + " } catch (Exception e) {\n" + + " if (args == null) {\n" + + " throw e;\n" + + " } \n" + + " else {\n" + + " e = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " throw e;\n" + + " ^^^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " else {\n" + + " e = null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test064() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "interface I {\n" + + " void doit();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) throws IOException {\n" + + "\n" + + " try {\n" + + " throw new IOException();\n" + + " } catch (Exception e) {\n" + + " if (args == null) {\n" + + " throw e;\n" + + " } \n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test065() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "class X {\n" + + " void foo() {\n" + + " int x = 10;\n" + + " I i = () -> {\n" + + " System.out.println(x++);\n" + + " };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(x++);\n" + + " ^\n" + + "Local variable x defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test066() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "class X {\n" + + " void foo(int x) throws IOException {\n" + + " try {\n" + + " throw new IOException();\n" + + " } catch (Exception e) {\n" + + " if (x == 0) {\n" + + " throw e;\n" + + " } else {\n" + + " e = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " throw e;\n" + + " ^^^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " } else {\n" + + " e = null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test067() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit ();\n" + + "}\n" + + "class X {\n" + + " int p;\n" + + " void foo(int p) {\n" + + " int i = 10;\n" + + " X x = new X();\n" + + " x = new X();\n" + + " I l = () -> {\n" + + " x.p = i++;\n" + + " };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " void foo(int p) {\n" + + " ^\n" + + "The parameter p is hiding a field from type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " x.p = i++;\n" + + " ^\n" + + "Local variable i defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment +public void test068() { + // This test checks that common semantic checks are indeed run + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit ();\n" + + "}\n" + + "class X {\n" + + " int p;\n" + + " void foo(int p) {\n" + + " int i = 10;\n" + + " X x = new X();\n" + + " x = new X();\n" + + " I l = () -> {\n" + + " x.p = i;\n" + + " };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " void foo(int p) {\n" + + " ^\n" + + "The parameter p is hiding a field from type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " x.p = i;\n" + + " ^\n" + + "Local variable x defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test069() { + // Lambda argument hides a field. + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p);\n" + + "}\n" + + "public class X {\n" + + " int f1;\n" + + " int f2;\n" + + "\n" + + " void foo() {\n" + + " I i = (int f1) -> {\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " I i = (int f1) -> {\n" + + " ^^\n" + + "The parameter f1 is hiding a field from type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test070() { + // Lambda argument redeclares outer method argument. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p);\n" + + "}\n" + + "public class X {\n" + + " void foo(int x) {\n" + + " I i = (int x) -> {\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = (int x) -> {\n" + + " ^\n" + + "Lambda expression\'s parameter x cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test071() { + // Lambda argument redeclares outer method local. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p);\n" + + "}\n" + + "public class X {\n" + + " void foo(int x) {\n" + + " int l;\n" + + " I i = (int l) -> {\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i = (int l) -> {\n" + + " ^\n" + + "Lambda expression\'s parameter l cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test072() { + // Lambda redeclares its own argument + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " void foo(int x) {\n" + + " int l;\n" + + " I i = (int p, int p) -> {\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i = (int p, int p) -> {\n" + + " ^\n" + + "Duplicate parameter p\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test073() { + // Lambda local hides a field + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo() {\n" + + " I i = (int p, int q) -> {\n" + + " int f;\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " int f;\n" + + " ^\n" + + "The local variable f is hiding a field from type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test074() { + // Lambda local redeclares the enclosing method's argument + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int a) {\n" + + " I i = (int p, int q) -> {\n" + + " int a;\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " int a;\n" + + " ^\n" + + "Lambda expression\'s local variable a cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test075() { + // Lambda local redeclares the enclosing method's local + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int a) {\n" + + " int loc;\n" + + " I i = (int p, int q) -> {\n" + + " int loc;\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " int loc;\n" + + " ^^^\n" + + "Lambda expression\'s local variable loc cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test076() { + // Lambda local redeclares its own parameter + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int a) {\n" + + " int loc;\n" + + " I i = (int p, int q) -> {\n" + + " int p;\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " int p;\n" + + " ^\n" + + "Duplicate local variable p\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test077() { + // Lambda local redeclares its own self + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int a) {\n" + + " int loc;\n" + + " I i = (int p, int q) -> {\n" + + " int self, self;\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " int self, self;\n" + + " ^^^^\n" + + "Duplicate local variable self\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test078() { + // Nested Lambda argument redeclares a field. + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int a) {\n" + + " int loc;\n" + + " I i = (int p, int q) -> {\n" + + " I i2 = (int f, int p0) -> {};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " I i2 = (int f, int p0) -> {};\n" + + " ^\n" + + "The parameter f is hiding a field from type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test079() { + // Nested Lambda argument redeclares outer method's argument. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int loc;\n" + + " I i = (int p, int q) -> {\n" + + " I i2 = (int f, int outerp) -> {};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " I i2 = (int f, int outerp) -> {};\n" + + " ^\n" + + "The parameter f is hiding a field from type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " I i2 = (int f, int outerp) -> {};\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter outerp cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test080() { + // Nested Lambda argument redeclares outer method's local. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " I i2 = (int locouter, int outerp) -> {};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i2 = (int locouter, int outerp) -> {};\n" + + " ^^^^^^^^\n" + + "Lambda expression\'s parameter locouter cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " I i2 = (int locouter, int outerp) -> {};\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter outerp cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test081() { + // Nested Lambda argument redeclares outer lambda's argument. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " I i2 = (int p, int q) -> {};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i2 = (int p, int q) -> {};\n" + + " ^\n" + + "Lambda expression\'s parameter p cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " I i2 = (int p, int q) -> {};\n" + + " ^\n" + + "Lambda expression\'s parameter q cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test082() { + // Nested Lambda argument redeclares outer lambda's local. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " I i2 = (int lamlocal, int q) -> {};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " I i2 = (int lamlocal, int q) -> {};\n" + + " ^^^^^^^^\n" + + "Lambda expression\'s parameter lamlocal cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " I i2 = (int lamlocal, int q) -> {};\n" + + " ^\n" + + "Lambda expression\'s parameter q cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test083() { + // Nested Lambda local redeclares a field. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " I i2 = (int lamlocal, int q) -> {int f;};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " I i2 = (int lamlocal, int q) -> {int f;};\n" + + " ^^^^^^^^\n" + + "Lambda expression\'s parameter lamlocal cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " I i2 = (int lamlocal, int q) -> {int f;};\n" + + " ^\n" + + "Lambda expression\'s parameter q cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " I i2 = (int lamlocal, int q) -> {int f;};\n" + + " ^\n" + + "The local variable f is hiding a field from type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test084() { + // Nested Lambda local redeclares outer methods local. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " I i2 = (int lamlocal, int q) -> {int locouter;};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " I i2 = (int lamlocal, int q) -> {int locouter;};\n" + + " ^^^^^^^^\n" + + "Lambda expression\'s parameter lamlocal cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " I i2 = (int lamlocal, int q) -> {int locouter;};\n" + + " ^\n" + + "Lambda expression\'s parameter q cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " I i2 = (int lamlocal, int q) -> {int locouter;};\n" + + " ^^^^^^^^\n" + + "Lambda expression\'s local variable locouter cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test085() { + // Nested Lambda local redeclares outer lambda's argument & local + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " I i2 = (int j, int q) -> {int p, lamlocal;};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " I i2 = (int j, int q) -> {int p, lamlocal;};\n" + + " ^\n" + + "Lambda expression\'s parameter q cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " I i2 = (int j, int q) -> {int p, lamlocal;};\n" + + " ^\n" + + "Lambda expression\'s local variable p cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " I i2 = (int j, int q) -> {int p, lamlocal;};\n" + + " ^^^^^^^^\n" + + "Lambda expression\'s local variable lamlocal cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test086() { + // Nested Lambda local redeclares its own argument & local + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " I i2 = (int x1, int x2) -> {int x1, x2;};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " I i2 = (int x1, int x2) -> {int x1, x2;};\n" + + " ^^\n" + + "Duplicate local variable x1\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " I i2 = (int x1, int x2) -> {int x1, x2;};\n" + + " ^^\n" + + "Duplicate local variable x2\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test087() { + // Inner class (!) inside Lambda hides field + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " class X { void foo(int f) {} }\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " class X { void foo(int f) {} }\n" + + " ^\n" + + "The nested type X cannot hide an enclosing type\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " class X { void foo(int f) {} }\n" + + " ^\n" + + "The parameter f is hiding a field from type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test088() { + // class inside lambda (!) redeclares a field. + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int a) {\n" + + " int loc;\n" + + " I i = (int p, int q) -> {\n" + + " I i2 = new I() { public void foo(int f, int p0) {};\n" + + " };};\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " I i2 = new I() { public void foo(int f, int p0) {};\n" + + " ^\n" + + "The parameter f is hiding a field from type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test089() { + // class inside lambda redeclares outer method's argument. + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int loc;\n" + + " I i = (int p, int q) -> {\n" + + " I i2 = new I() { public void foo(int f, int outerp) {}};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " I i2 = new I() { public void foo(int f, int outerp) {}};\n" + + " ^\n" + + "The parameter f is hiding a field from type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " I i2 = new I() { public void foo(int f, int outerp) {}};\n" + + " ^^^^^^\n" + + "The parameter outerp is hiding another local variable defined in an enclosing scope\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test090() { + // class inside lambda redeclares outer method's local. + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " I i2 = new I() { public void foo(int locouter, int outerp) {}};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " I i2 = new I() { public void foo(int locouter, int outerp) {}};\n" + + " ^^^^^^^^\n" + + "The parameter locouter is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " I i2 = new I() { public void foo(int locouter, int outerp) {}};\n" + + " ^^^^^^\n" + + "The parameter outerp is hiding another local variable defined in an enclosing scope\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test091() { + // class inside lambda redeclares outer lambda's argument. + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " I i2 = new I() { public void foo (int p, int q) {}};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " I i2 = new I() { public void foo (int p, int q) {}};\n" + + " ^\n" + + "The parameter p is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " I i2 = new I() { public void foo (int p, int q) {}};\n" + + " ^\n" + + "The parameter q is hiding another local variable defined in an enclosing scope\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test092() { + // class inside lambda redeclares outer lambda's local. + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " I i2 = new I() { public void foo (int lamlocal, int q) {} };\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo (int lamlocal, int q) {} };\n" + + " ^^^^^^^^\n" + + "The parameter lamlocal is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo (int lamlocal, int q) {} };\n" + + " ^\n" + + "The parameter q is hiding another local variable defined in an enclosing scope\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test093() { + // local of class inside lambda redeclares a field. + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " I i2 = new I() { public void foo (int lamlocal, int q) {int f;}};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo (int lamlocal, int q) {int f;}};\n" + + " ^^^^^^^^\n" + + "The parameter lamlocal is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo (int lamlocal, int q) {int f;}};\n" + + " ^\n" + + "The parameter q is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo (int lamlocal, int q) {int f;}};\n" + + " ^\n" + + "The local variable f is hiding a field from type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test094() { + // local of class under lambda redeclares outer methods local. + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " I i2 = new I() { public void foo(int lamlocal, int q) {int locouter;}};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo(int lamlocal, int q) {int locouter;}};\n" + + " ^^^^^^^^\n" + + "The parameter lamlocal is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo(int lamlocal, int q) {int locouter;}};\n" + + " ^\n" + + "The parameter q is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo(int lamlocal, int q) {int locouter;}};\n" + + " ^^^^^^^^\n" + + "The local variable locouter is hiding another local variable defined in an enclosing scope\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test095() { + // local of class under lambda redeclares outer lambda's argument & local + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " I i2 = new I() { public void foo(int j, int q) {int p, lamlocal;}};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo(int j, int q) {int p, lamlocal;}};\n" + + " ^\n" + + "The parameter q is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo(int j, int q) {int p, lamlocal;}};\n" + + " ^\n" + + "The local variable p is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " I i2 = new I() { public void foo(int j, int q) {int p, lamlocal;}};\n" + + " ^^^^^^^^\n" + + "The local variable lamlocal is hiding another local variable defined in an enclosing scope\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382727, [1.8][compiler] Lambda expression parameters and locals cannot shadow variables from context +public void test096() { + // local of class under lambda redeclares its own argument & local + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int p, int q);\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " void foo(int outerp) {\n" + + " int locouter;\n" + + " I i = (int p, int q) -> {\n" + + " int lamlocal;\n" + + " I i2 = new I() { public void foo(int x1, int x2) {int x1, x2;}};\n" + + " };\n" + + " } \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " I i2 = new I() { public void foo(int x1, int x2) {int x1, x2;}};\n" + + " ^^\n" + + "Duplicate local variable x1\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " I i2 = new I() { public void foo(int x1, int x2) {int x1, x2;}};\n" + + " ^^\n" + + "Duplicate local variable x2\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384687 [1.8] Wildcard type arguments should be rejected for lambda and reference expressions +public void test097() { + this.runNegativeTest( + new String[] { + "X.java", + "class Action {\r\n" + + " static int fooMethod(Object x) { return 0; }\r\n" + + "}\r\n" + + "interface I {\r\n" + + " int foo(Object x);\r\n" + + "}\r\n" + + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " I functional = Action::fooMethod;\r\n" + // no raw type warning here, Action:: is really Action<>:: + " }\r\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I functional = Action::fooMethod;\n" + + " ^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=384687 [1.8] Wildcard type arguments should be rejected for lambda and reference expressions +public void test098() { + this.runNegativeTest( + new String[] { + "X.java", + "class Action {\r\n" + + " int foo(Object x, Object y, Object z) { return 0; }\r\n" + + "}\r\n" + + "interface I {\r\n" + + " void foo(Object x);\r\n" + + "}\r\n" + + "public class X {\r\n" + + " public static void main(String[] args) {\r\n" + + " Action exp = new Action();\r\n" + + " int x,y,z;\r\n" + + " I len6 = foo->exp.method(x, y, z);\r\n" + + " }\r\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " I len6 = foo->exp.method(x, y, z);\n" + + " ^\n" + + "Wildcard is not allowed at this location\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399770: [1.8][compiler] Implement support for @FunctionalInterface +public void test_bug399770_1() { + this.runConformTest( + new String[] { + "YYY.java", + "interface BASE { void run(); }\n" + + "@FunctionalInterface\n" + + "interface DERIVED extends BASE {void run();}" + + "public class YYY {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Hello\");" + + " }\n" + + "}", + }, + "Hello" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=399770: [1.8][compiler] Implement support for @FunctionalInterface +public void test_bug399770_2() { + this.runNegativeTest( + new String[] { + "YYY.java", + "interface BASE { void run(); }\n" + + "@FunctionalInterface\n" + + "interface DERIVED extends BASE {void run1();}" + + "@FunctionalInterface public class YYY {\n" + + " @FunctionalInterface int x;" + + " @FunctionalInterface public static void main(String[] args) {\n" + + " @FunctionalInterface int y;" + + " System.out.println(\"Hello\");" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in YYY.java (at line 3)\n" + + " interface DERIVED extends BASE {void run1();}@FunctionalInterface public class YYY {\n" + + " ^^^^^^^\n" + + "Invalid \'@FunctionalInterface\' annotation; DERIVED is not a functional interface\n" + + "----------\n" + + "2. ERROR in YYY.java (at line 3)\n" + + " interface DERIVED extends BASE {void run1();}@FunctionalInterface public class YYY {\n" + + " ^^^\n" + + "Invalid \'@FunctionalInterface\' annotation; YYY is not a functional interface\n" + + "----------\n" + + "3. ERROR in YYY.java (at line 4)\n" + + " @FunctionalInterface int x; @FunctionalInterface public static void main(String[] args) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The annotation @FunctionalInterface is disallowed for this location\n" + + "----------\n" + + "4. ERROR in YYY.java (at line 4)\n" + + " @FunctionalInterface int x; @FunctionalInterface public static void main(String[] args) {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The annotation @FunctionalInterface is disallowed for this location\n" + + "----------\n" + + "5. ERROR in YYY.java (at line 5)\n" + + " @FunctionalInterface int y; System.out.println(\"Hello\"); }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The annotation @FunctionalInterface is disallowed for this location\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400745, [1.8][compiler] Compiler incorrectly allows shadowing of local class names. +public void test400745() { + // Lambda redeclares a local class from its outer scope. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " public void foo() {\n" + + " class Y {};\n" + + " I i = () -> {\n" + + " class Y{} ;\n" + + " };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " class Y{} ;\n" + + " ^\n" + + "Duplicate nested type Y\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400745, [1.8][compiler] Compiler incorrectly allows shadowing of local class names. +public void test400745a() { + // local type hiding scenario + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " private void foo() {\n" + + " class Y {}\n" + + " X x = new X() {\n" + + " private void foo() {\n" + + " class Y {};\n" + + " }\n" + + " };\n" + + " I i = () -> {\n" + + " class LX {\n" + + " void foo() {\n" + + " class Y {};\n" + + " }\n" + + " };\n" + + " };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " private void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type X is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " class Y {}\n" + + " ^\n" + + "The type Y is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " private void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type new X(){} is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " class Y {};\n" + + " ^\n" + + "The type Y is hiding the type Y\n" + + "----------\n" + + "5. WARNING in X.java (at line 9)\n" + + " class Y {};\n" + + " ^\n" + + "The type Y is never used locally\n" + + "----------\n" + + "6. WARNING in X.java (at line 13)\n" + + " class LX {\n" + + " ^^\n" + + "The type LX is never used locally\n" + + "----------\n" + + "7. WARNING in X.java (at line 14)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type LX is never used locally\n" + + "----------\n" + + "8. WARNING in X.java (at line 15)\n" + + " class Y {};\n" + + " ^\n" + + "The type Y is hiding the type Y\n" + + "----------\n" + + "9. WARNING in X.java (at line 15)\n" + + " class Y {};\n" + + " ^\n" + + "The type Y is never used locally\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "public interface I

    {\n" + + " R doit(P p) throws T;\n" + + "}\n" + + "\n" + + "class ReturnType {\n" + + "}\n" + + "\n" + + "class ParameterType {\n" + + "}\n" + + "\n" + + "class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "public class X {\n" + + " I i = (p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\I.java (at line 12)\n" + + " class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^\n" + + "I is a raw type. References to generic type I

    should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^^^^^^\n" + + "The type ReturnType from the descriptor computed for the target context is not visible here. \n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^^^^^^\n" + + "The type ParameterType from the descriptor computed for the target context is not visible here. \n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^^^^^^\n" + + "The type ExceptionType from the descriptor computed for the target context is not visible here. \n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556a() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "public interface I

    {\n" + + " R doit(P p) throws T;\n" + + "}\n", + "p/ReturnType.java", + "package p;\n" + + "public class ReturnType {\n" + + "}\n" + + "\n" + + "class ParameterType {\n" + + "}\n", + "p/ExceptionType.java", + "package p;\n" + + "public class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "public class X {\n" + + " I i = (p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\ExceptionType.java (at line 2)\n" + + " public class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^\n" + + "I is a raw type. References to generic type I

    should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^^^^^^\n" + + "The type ParameterType from the descriptor computed for the target context is not visible here. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556b() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.List;\n" + + "public interface I

    {\n" + + " R doit(List>[] p) throws T;\n" + + "}\n" + + "\n" + + "class ReturnType {\n" + + "}\n" + + "\n" + + "class ParameterType {\n" + + "}\n" + + "\n" + + "class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "public class X {\n" + + " I i = (p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\I.java (at line 13)\n" + + " class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^\n" + + "I is a raw type. References to generic type I

    should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^^^^^^\n" + + "The type ReturnType from the descriptor computed for the target context is not visible here. \n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^^^^^^\n" + + "The type ExceptionType from the descriptor computed for the target context is not visible here. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556c() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.List;\n" + + "public interface I

    {\n" + + " R doit(List>[] p) throws T;\n" + + "}\n" + + "class ParameterType {\n" + + "}\n" + + "class ReturnType {\n" + + "}\n" + + "class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "public class X {\n" + + " I i = (p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\I.java (at line 10)\n" + + " class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^^^^^^\n" + + "The type ReturnType from the descriptor computed for the target context is not visible here. \n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^^^^^^\n" + + "The type ParameterType from the descriptor computed for the target context is not visible here. \n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " I i = (p) -> { return null; };\n" + + " ^^^^^^\n" + + "The type ExceptionType from the descriptor computed for the target context is not visible here. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556d() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.List;\n" + + "public interface I

    {\n" + + " R doit(List>[] p) throws T;\n" + + "}\n", + "p/ParameterType.java", + "package p;\n" + + "public class ParameterType {\n" + + "}\n", + "p/ReturnType.java", + "package p;\n" + + "public class ReturnType {\n" + + "}\n", + "p/ExceptionType.java", + "package p;\n" + + "public class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "public class X {\n" + + " I i = (p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\ExceptionType.java (at line 2)\n" + + " public class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556e() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.List;\n" + + "public interface I

    {\n" + + " R doit(List>[] p) throws T;\n" + + "}\n", + "p/ParameterType.java", + "package p;\n" + + "public class ParameterType {\n" + + "}\n", + "p/ReturnType.java", + "package p;\n" + + "public class ReturnType {\n" + + "}\n", + "p/ExceptionType.java", + "package p;\n" + + "public class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "public class X {\n" + + " I i = (String p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\ExceptionType.java (at line 2)\n" + + " public class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I i = (String p) -> { return null; };\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter p is expected to be of type List>[]\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556f() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.List;\n" + + "public interface I

    {\n" + + " R doit(List>[] p) throws T;\n" + + "}\n", + "p/ParameterType.java", + "package p;\n" + + "public class ParameterType {\n" + + "}\n", + "p/ReturnType.java", + "package p;\n" + + "public class ReturnType {\n" + + "}\n", + "p/ExceptionType.java", + "package p;\n" + + "public class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "public class X {\n" + + " I i = (String p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\ExceptionType.java (at line 2)\n" + + " public class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I i = (String p) -> { return null; };\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter p is expected to be of type List>[]\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556g() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.List;\n" + + "public interface I

    {\n" + + " R doit(List>[] p) throws T;\n" + + "}\n", + "p/ParameterType.java", + "package p;\n" + + "public class ParameterType {\n" + + "}\n", + "p/ReturnType.java", + "package p;\n" + + "public class ReturnType {\n" + + "}\n", + "p/ExceptionType.java", + "package p;\n" + + "public class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "class P extends p.ParameterType {}\n" + + "class T extends p.ExceptionType {}\n" + + "class R extends p.ReturnType {}\n" + + "public class X {\n" + + " I i = (String p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\ExceptionType.java (at line 2)\n" + + " public class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class T extends p.ExceptionType {}\n" + + " ^\n" + + "The serializable class T does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " I i = (String p) -> { return null; };\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter p is expected to be of type List>[]\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556h() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.List;\n" + + "public interface I

    {\n" + + " R doit(List>[] p) throws T;\n" + + "}\n", + "p/ParameterType.java", + "package p;\n" + + "public class ParameterType {\n" + + "}\n", + "p/ReturnType.java", + "package p;\n" + + "public class ReturnType {\n" + + "}\n", + "p/ExceptionType.java", + "package p;\n" + + "public class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "class P extends p.ParameterType {}\n" + + "class T extends p.ExceptionType {}\n" + + "class R extends p.ReturnType {}\n" + + "public class X {\n" + + " I i = (String p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\ExceptionType.java (at line 2)\n" + + " public class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class T extends p.ExceptionType {}\n" + + " ^\n" + + "The serializable class T does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " I i = (String p) -> { return null; };\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter

    of the type I\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " I i = (String p) -> { return null; };\n" + + " ^\n" + + "Bound mismatch: The type R is not a valid substitute for the bounded parameter of the type I\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " I i = (String p) -> { return null; };\n" + + " ^\n" + + "Bound mismatch: The type P is not a valid substitute for the bounded parameter of the type I\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " I i = (String p) -> { return null; };\n" + + " ^^^^^^^^^^^^^\n" + + "The target type of this expression is not a well formed parameterized type due to bound(s) mismatch\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556i() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.List;\n" + + "public interface I

    {\n" + + " R doit(List>[] p) throws T;\n" + + "}\n", + "p/ParameterType.java", + "package p;\n" + + "public class ParameterType {\n" + + "}\n", + "p/ReturnType.java", + "package p;\n" + + "public class ReturnType {\n" + + "}\n", + "p/ExceptionType.java", + "package p;\n" + + "public class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "class P extends p.ParameterType {}\n" + + "class T extends p.ExceptionType {}\n" + + "class R extends p.ReturnType {}\n" + + "public class X {\n" + + " I i = (String p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\ExceptionType.java (at line 2)\n" + + " public class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class T extends p.ExceptionType {}\n" + + " ^\n" + + "The serializable class T does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " I i = (String p) -> { return null; };\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter p is expected to be of type List>[]\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556j() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.List;\n" + + "public interface I

    {\n" + + " R doit(List>[] p) throws T;\n" + + "}\n", + "p/ParameterType.java", + "package p;\n" + + "public class ParameterType {\n" + + "}\n", + "p/ReturnType.java", + "package p;\n" + + "public class ReturnType {\n" + + "}\n", + "p/ExceptionType.java", + "package p;\n" + + "public class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "class P extends p.ParameterType {}\n" + + "class T extends p.ExceptionType {}\n" + + "class R extends p.ReturnType {}\n" + + "public class X {\n" + + " I i = (String p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\I.java (at line 4)\n" + + " R doit(List>[] p) throws T;\n" + + " ^\n" + + "No exception of type T can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\ExceptionType.java (at line 2)\n" + + " public class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " class T extends p.ExceptionType {}\n" + + " ^\n" + + "The serializable class T does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " I i = (String p) -> { return null; };\n" + + " ^^^^^^^^^^^^^\n" + + "The target type of this expression is not a well formed parameterized type due to bound(s) mismatch\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400556, [1.8][compiler] Visibility checks are missing for lambda/reference expressions +public void test400556k() { + this.runNegativeTest( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.List;\n" + + "public interface I

    {\n" + + " R doit(List>[] p) throws T;\n" + + "}\n", + "p/ParameterType.java", + "package p;\n" + + "public class ParameterType {\n" + + "}\n", + "p/ReturnType.java", + "package p;\n" + + "public class ReturnType {\n" + + "}\n", + "p/ExceptionType.java", + "package p;\n" + + "public class ExceptionType extends Exception {\n" + + "}\n", + "X.java", + "import p.I;\n" + + "public class X {\n" + + " I i = (String p) -> { return null; };\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\ExceptionType.java (at line 2)\n" + + " public class ExceptionType extends Exception {\n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class ExceptionType does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " I i = (String p) -> { return null; };\n" + + " ^\n" + + "I is a raw type. References to generic type I should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I i = (String p) -> { return null; };\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter p is expected to be of type List[]\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void zoo(int x, String p);\n" + + "}\n" + + "public class X {\n" + + " int x = 0;\n" + + " I i = x::zoo;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = x::zoo;\n" + + " ^\n" + + "Cannot invoke zoo(int, String) on the primitive type int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void zoo(int x, String p);\n" + + "}\n" + + "public class X {\n" + + " int x = 0;\n" + + " I i = I::new;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = I::new;\n" + + " ^\n" + + "Cannot instantiate the type I\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750b() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void zoo(int x, String p);\n" + + "}\n" + + "abstract public class X {\n" + + " int x = 0;\n" + + " I i = X::new;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = X::new;\n" + + " ^\n" + + "Cannot instantiate the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750c() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void zoo(int x, String p);\n" + + "}\n" + + "abstract public class X {\n" + + " int x = 0;\n" + + " I i = E::new;\n" + + "}\n" + + "enum E {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = E::new;\n" + + " ^\n" + + "Cannot instantiate the type E\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750d() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " X zoo(int x, String p);\n" + + "}\n" + + "public class X {\n" + + " X(int x, String p) {}\n" + + " I i = X::new;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = X::new;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Cannot instantiate the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750e() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " X zoo(int x, String p);\n" + + "}\n" + + "public class X {\n" + + " X(int x, String p) {}\n" + + " I i = T::new;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = T::new;\n" + + " ^\n" + + "Cannot instantiate the type T\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750f() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " X zoo(int x, String p);\n" + + "}\n" + + "public class X {\n" + + " X(int x, String p) {}\n" + + " I i = Annot::new;\n" + + "}\n" + + "@interface Annot {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = Annot::new;\n" + + " ^^^^^\n" + + "Cannot instantiate the type Annot\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750g() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " X zoo(int x, String p);\n" + + "}\n" + + "public class X {\n" + + " X(int x, String p) {}\n" + + " static {\n" + + " I i = this::foo;\n" + + " }\n" + + " X foo(int x, String p) { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i = this::foo;\n" + + " ^^^^\n" + + "Cannot use this in a static context\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750h() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " X zoo(int x, String p);\n" + + "}\n" + + "public class X {\n" + + " X(int x, String p) {}\n" + + " I i = this::foo;\n" + + " X foo(int x, String p) { return null; }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750i() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " X zoo(int x, String p);\n" + + "}\n" + + "public class X extends Y {\n" + + " static {\n" + + " I i = super::foo;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " X foo(int x, String p) { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = super::foo;\n" + + " ^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750j() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " X zoo(int x, String p);\n" + + "}\n" + + "public class X extends Y {\n" + + " I i = super::foo;\n" + + "}\n" + + "class Y {\n" + + " X foo(int x, String p) { return null; }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " I i = super::foo;\n" + + " ^^^^^^^^^^\n" + + "Access to enclosing method foo(int, String) from the type Y is emulated by a synthetic accessor method\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750k() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void zoo();\n" + + "}\n" + + "class Z {\n" + + " void zoo() {}\n" + + "}\n" + + "class X extends Z {\n" + + " static class N {\n" + + " I i = X.super::zoo;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i = X.super::zoo;\n" + + " ^^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750l() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void zoo();\n" + + "}\n" + + "class Z {\n" + + " void zoo() {}\n" + + "}\n" + + "class X extends Z {\n" + + " class N {\n" + + " I i = X.super::zoo;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " I i = X.super::zoo;\n" + + " ^^^^^^^^^^^^\n" + + "Access to enclosing method zoo() from the type Z is emulated by a synthetic accessor method\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750m() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "interface I {\n" + + " List doit();\n" + + "}\n" + + "interface J {\n" + + " int size(ArrayList als);\n" + + "}\n" + + "class X {\n" + + " I i1 = ArrayList::new;\n" + + " I i2 = ArrayList::new;\n" + + " I i3 = ArrayList::new;\n" + + " I i4 = List::new;\n" + + " J j1 = String::length;\n" + + " J j2 = List::size;\n" + + " J j3 = List::size;\n" + + " J j4 = List::size;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " I i3 = ArrayList::new;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructed object of type ArrayList is incompatible with the descriptor\'s return type: List\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " I i4 = List::new;\n" + + " ^^^^^^^^^^^^\n" + + "Cannot instantiate the type List\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " J j1 = String::length;\n" + + " ^^^^^^^^^^^^^^\n" + + "The type String does not define length(ArrayList) that is applicable here\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " J j4 = List::size;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type List does not define size(ArrayList) that is applicable here\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750n() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "interface I {\n" + + " List doit();\n" + + "}\n" + + "public class X {\n" + + " I i1 = ArrayList[]::new;\n" + + " I i2 = List[]::new;\n" + + " I i3 = ArrayList::new;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i1 = ArrayList[]::new;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of ArrayList\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " I i2 = List[]::new;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of List\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750o() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "interface I {\n" + + " List [] doit();\n" + + "}\n" + + "interface J {\n" + + " List [] doit(long l);\n" + + "}\n" + + "interface K {\n" + + " List [] doit(String s, long l);\n" + + "}\n" + + "interface L {\n" + + " List [] doit(short s);\n" + + "}\n" + + "interface M {\n" + + " List [] doit(byte b);\n" + + "}\n" + + "interface N {\n" + + " List [] doit(int i);\n" + + "}\n" + + "interface O {\n" + + " List [] doit(Integer i);\n" + + "}\n" + + "interface P {\n" + + " List [] doit(Short i);\n" + + "}\n" + + "interface Q {\n" + + " List [] doit(Float i);\n" + + "}\n" + + "interface R {\n" + + " List [] doit(int i);\n" + + "}\n" + + "public class X {\n" + + " I i = List[]::new;\n" + + " J j = ArrayList[]::new;\n" + + " K k = ArrayList[]::new;\n" + + " L l = ArrayList[]::new;\n" + + " M m = ArrayList[]::new;\n" + + " N n = ArrayList[]::new;\n" + + " O o = ArrayList[]::new;\n" + + " P p = ArrayList[]::new;\n" + + " Q q = ArrayList[]::new;\n" + + " R r = ArrayList[][][]::new;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 34)\n" + + " I i = List[]::new;\n" + + " ^^^^^^^^^^^\n" + + "Incompatible parameter list for array constructor. Expected (int), but found ()\n" + + "----------\n" + + "2. ERROR in X.java (at line 35)\n" + + " J j = ArrayList[]::new;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Incompatible parameter list for array constructor. Expected (int), but found (long)\n" + + "----------\n" + + "3. ERROR in X.java (at line 36)\n" + + " K k = ArrayList[]::new;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Incompatible parameter list for array constructor. Expected (int), but found (String, long)\n" + + "----------\n" + + "4. ERROR in X.java (at line 42)\n" + + " Q q = ArrayList[]::new;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Incompatible parameter list for array constructor. Expected (int), but found (Float)\n" + + "----------\n" + + "5. ERROR in X.java (at line 43)\n" + + " R r = ArrayList[][][]::new;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Constructed array ArrayList[][][] cannot be assigned to List[] as required in the interface descriptor \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750p() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " List doit();\n" + + "}\n" + + "class X {\n" + + " static void foo() {}\n" + + " {\n" + + " X x = new X();\n" + + " I i1 = x::foo;\n" + + " I i2 = X::foo;\n" + + " I i3 = X::foo;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i1 = x::foo;\n" + + " ^^^^^^\n" + + "The method foo() from the type X should be accessed in a static way \n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " I i2 = X::foo;\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo() from the type X should be accessed in a static way \n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " I i3 = X::foo;\n" + + " ^^^^^^\n" + + "The type of foo() from the type X is void, this is incompatible with the descriptor\'s return type: List\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750q() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " List doit();\n" + + "}\n" + + "class X {\n" + + " void foo() {}\n" + + " {\n" + + " X x = new X();\n" + + " I i1 = x::foo;\n" + + " I i2 = X::foo;\n" + + " I i3 = X::foo;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i1 = x::foo;\n" + + " ^^^^^^\n" + + "The type of foo() from the type X is void, this is incompatible with the descriptor\'s return type: List\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " I i2 = X::foo;\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot make a static reference to the non-static method foo() from the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " I i3 = X::foo;\n" + + " ^^^^^^\n" + + "Cannot make a static reference to the non-static method foo() from the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750r() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " List doit(X xs);\n" + + "}\n" + + "class X {\n" + + " void foo() {}\n" + + " {\n" + + " X x = new X();\n" + + " I i1 = X::foo;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i1 = X::foo;\n" + + " ^^^^^^\n" + + "The type of foo() from the type X is void, this is incompatible with the descriptor\'s return type: List\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750s() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " List doit(X xs);\n" + + "}\n" + + "class X {\n" + + " void foo() {}\n" + + " {\n" + + " X x = new X();\n" + + " I i1 = X::foo;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i1 = X::foo;\n" + + " ^^^^^^^^^^^^^^\n" + + "The type of foo() from the type X is void, this is incompatible with the descriptor\'s return type: List\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750t() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " List doit(X xs);\n" + + "}\n" + + "class X {\n" + + " static List foo() {}\n" + + " {\n" + + " X x = new X();\n" + + " I i1 = X::foo;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i1 = X::foo;\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo() from the type X should be accessed in a static way \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750u() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " List doit(X xs, int x);\n" + + "}\n" + + "class X {\n" + + " static List foo() {}\n" + + " {\n" + + " X x = new X();\n" + + " I i1 = X::foo;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i1 = X::foo;\n" + + " ^^^^^^\n" + + "The type X does not define foo(X, int) that is applicable here\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750v() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " List doit(X xs, int x);\n" + + "}\n" + + "class X {\n" + + " static List foo(X xs, int x) {}\n" + + " List foo(int x) {}\n" + + " {\n" + + " X x = new X();\n" + + " I i1 = X::foo;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " I i1 = X::foo;\n" + + " ^^^^^^\n" + + "Ambiguous method reference: both foo(int) and foo(X, int) from the type X are eligible\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750w() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " X doit(int x);\n" + + "}\n" + + "interface J {\n" + + " X doit(int x, int p);\n" + + "}\n" + + "interface K {\n" + + " X doit(int x);\n" + + " void goo();\n" + + "}\n" + + "interface L {\n" + + " X doit(short x);\n" + + "}\n" + + "interface M {\n" + + " X doit(String s);\n" + + "}\n" + + "class X {\n" + + " X(int x, int y) {}\n" + + " X(int x) {}\n" + + " {\n" + + " I i = X::new;\n" + + " J j = X::new;\n" + + " K k = X::new;\n" + + " L l = X::new;\n" + + " M m = X::new;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 23)\n" + + " J j = X::new;\n" + + " ^^^^^^^^^^^^^^^\n" + + "The constructed object of type X is incompatible with the descriptor\'s return type: X\n" + + "----------\n" + + "2. ERROR in X.java (at line 24)\n" + + " K k = X::new;\n" + + " ^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "3. ERROR in X.java (at line 26)\n" + + " M m = X::new;\n" + + " ^^^^^^^^^^^^^^\n" + + "The type X does not define X(String) that is applicable here\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750x() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.io.IOException;\n" + + "import java.io.FileNotFoundException;\n" + + "interface I {\n" + + " X doit(int x);\n" + + "}\n" + + "interface J {\n" + + " X doit(int x) throws IOException;\n" + + "}\n" + + "interface K {\n" + + " X doit(int x) throws FileNotFoundException;\n" + + "}\n" + + "interface L {\n" + + " X doit(short x) throws Exception;\n" + + "}\n" + + "class X {\n" + + " X(int x) throws IOException, FileNotFoundException {}\n" + + " {\n" + + " I i = X::new;\n" + + " J j = X::new;\n" + + " K k = X::new;\n" + + " L l = X::new;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " I i = X::new;\n" + + " ^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " I i = X::new;\n" + + " ^^^^^^\n" + + "Unhandled exception type FileNotFoundException\n" + + "----------\n" + + "3. ERROR in X.java (at line 20)\n" + + " J j = X::new;\n" + + " ^^^^^^^^^^^^^^^\n" + + "The constructed object of type X is incompatible with the descriptor\'s return type: X\n" + + "----------\n" + + "4. ERROR in X.java (at line 21)\n" + + " K k = X::new;\n" + + " ^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750y() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " void doit();\n" + + "}\n" + + "abstract class Y {\n" + + " abstract void foo();\n" + + "}\n" + + "class X extends Y {\n" + + " void foo() {}\n" + + " I i = super::foo;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " I i = super::foo;\n" + + " ^^^^^^^^^^\n" + + "Cannot directly invoke the abstract method foo() for the type Y\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750z() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportIndirectStaticAccess, CompilerOptions.WARNING); + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "class Y {\n" + + " static void foo() {}\n" + + "}\n" + + "class X extends Y {\n" + + " I i = X::foo;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " I i = X::foo;\n" + + " ^^^^^^\n" + + "The static method foo() from the type Y should be accessed directly \n" + + "----------\n", + null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750z1() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "class X extends Y {\n" + + " I i = X::foo;\n" + + "}\n", + "Y.java", + "@Deprecated class Y {\n" + + " @Deprecated static void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class X extends Y {\n" + + " ^\n" + + "The type Y is deprecated\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " I i = X::foo;\n" + + " ^^^^^^\n" + + "The method foo() from the type Y is deprecated\n" + + "----------\n", + null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750z2() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedTypeArgumentsForMethodInvocation, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "class X extends Y {\n" + + " I i = X::foo;\n" + + "}\n", + "Y.java", + "@Deprecated class Y {\n" + + " @Deprecated static void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " class X extends Y {\n" + + " ^\n" + + "The type Y is deprecated\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " I i = X::foo;\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo() from the type Y is deprecated\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " I i = X::foo;\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foo() of type Y; it should not be parameterized with arguments \n" + + "----------\n", + null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750z3() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit();\n" + + "}\n" + + "class X {\n" + + " String foo() { return null; }\n" + + " I i = new X()::foo;\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750z4() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " List doit();\n" + + "}\n" + + "class X {\n" + + " void foo() { return; }\n" + + " I i = new X()::foo;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i = new X()::foo;\n" + + " ^^^^^^^^^^^^\n" + + "The type of foo() from the type X is void, this is incompatible with the descriptor\'s return type: List\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750z5() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "interface I {\n" + + " List doit();\n" + + "}\n" + + "class X {\n" + + " ArrayList foo() { return null; }\n" + + " I i = new X()::foo;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " I i = new X()::foo;\n" + + " ^^^^^^^^^^^^\n" + + "The type of foo() from the type X is ArrayList, this is incompatible with the descriptor\'s return type: List\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750z6() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.DEFAULT, + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "interface I {\n" + + " List doit(X x, int y);\n" + + "}\n" + + "class X {\n" + + " ArrayList foo(int x) { return null; }\n" + + " I i = X::foo;\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750z7() { +this.runNegativeTest( + false /* skipJavac */, + new JavacTestOptions("-Xlint:rawtypes"), + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "interface I {\n" + + " List doit(X x, int y);\n" + + "}\n" + + "class X {\n" + + " ArrayList foo(int x) { return null; }\n" + + " I i = X::foo;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " List doit(X x, int y);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750z8() { +this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int [] doit(int [] ia);\n" + + "}\n" + + "class X {\n" + + " I i = int []::clone;\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions +public void test384750z9() { +this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int [] doit(X x);\n" + + "}\n" + + "public class X {\n" + + " Zork foo() {\n" + + " }\n" + + " I i = X::foo;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork foo() {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " I i = X::foo;\n" + + " ^^^^^^\n" + + "The method foo() from the type X refers to the missing type Zork\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " I i = X::foo;\n" + + " ^^^^^^\n" + + "The type of foo() from the type X is Zork, this is incompatible with the descriptor\'s return type: int[]\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610() { +this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " void foo(I i) {\n" + + " System.out.println(\"foo\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(()->{});\n" + + " }\n" + + "}\n", + }, + "foo"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610a() { +this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "interface K {\n" + + " void foo(String s);\n" + + "}\n" + + "public class X {\n" + + " void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " void foo(K k) {\n" + + " System.out.println(\"foo(K)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(()->{});\n" + + " new X().foo((x, y)->{});\n" + + " new X().foo((s)->{});\n" + + " }\n" + + "}\n", + }, + "foo(I)\n" + + "foo(J)\n" + + "foo(K)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610b() { +this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "interface K {\n" + + " void foo(String s);\n" + + "}\n" + + "public class X {\n" + + " void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(()->{});\n" + + " new X().foo((x, y)->{});\n" + + " new X().foo((s)->{});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " new X().foo((s)->{});\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (( s) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " new X().foo((s)->{});\n" + + " ^^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method foo()\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610c() { +this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface K {\n" + + " String foo(String s);\n" + + "}\n" + + "public class X {\n" + + " void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " void foo(K k) {\n" + + " System.out.println(\"foo(K)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(()->{ return \"\";});\n" + + " new X().foo(()-> 10);\n" + + " new X().foo((s)->{});\n" + + " new X().foo((s)->{ return;});\n" + + " new X().foo((s)->{ return \"\";});\n" + + " new X().foo((s)-> \"hello\");\n" + + " new X().foo(()->{ return;});\n" + + " new X().foo(()-> System.out.println());\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " new X().foo(()->{ return \"\";});\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " new X().foo(()->{ return \"\";});\n" + + " ^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " new X().foo(()-> 10);\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n" + + "4. ERROR in X.java (at line 16)\n" + + " new X().foo(()-> 10);\n" + + " ^^\n" + + "Void methods cannot return a value\n" + + "----------\n" + + "5. ERROR in X.java (at line 17)\n" + + " new X().foo((s)->{});\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (( s) -> {})\n" + + "----------\n" + + "6. ERROR in X.java (at line 17)\n" + + " new X().foo((s)->{});\n" + + " ^^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method foo()\n" + + "----------\n" + + "7. ERROR in X.java (at line 18)\n" + + " new X().foo((s)->{ return;});\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (( s) -> {})\n" + + "----------\n" + + "8. ERROR in X.java (at line 18)\n" + + " new X().foo((s)->{ return;});\n" + + " ^^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method foo()\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610d() { +this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " T id(T arg) { return arg; }\n" + + " Runnable r = id(() -> { System.out.println(); });\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610e() { +this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " T foo(I it) { return null; }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(()->{});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " interface I {\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " T foo(I it) { return null; }\n" + + " ^\n" + + "Bound mismatch: The type T is not a valid substitute for the bounded parameter of the type I\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " new X().foo(()->{});\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " new X().foo(()->{});\n" + + " ^^^^\n" + + "The target type of this expression is not a well formed parameterized type due to bound(s) mismatch\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +// demonstrate that the bound problem is the only real issue in test401610e() +public void test401610ee() { +this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " T foo(I it) { return null; }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(()->{});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " interface I {\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " T foo(I it) { return null; }\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610f() { +this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " T foo(I it) { return null; }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(()->{});\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610g() { +this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J { \n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " void foo(I it) { System.out.println(\"foo(I)\");}\n" + + " void foo(J it) { System.out.println(\"foo(J)\");}\n" + + " public static void main(String[] args) {\n" + + " new X().foo(()->{});\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610h() { +this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J { \n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " void foo(I it) { System.out.println(\"foo(I)\");}\n" + + " void foo(J it) { System.out.println(\"foo(J)\");}\n" + + " public static void main(String[] args) {\n" + + " new X().foo(()->{ return 10; });\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " new X().foo(()->{ return 10; });\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " new X().foo(()->{ return 10; });\n" + + " ^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610i() { +this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J { \n" + + " void foo(String s);\n" + + "}\n" + + "public class X {\n" + + " void foo(I it) { System.out.println(\"foo(I)\");}\n" + + " void foo(J it) { System.out.println(\"foo(J)\");}\n" + + + " public static void main(String[] args) {\n" + + " new X().foo((String s)->{});\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts +public void test401610j() { +this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J { \n" + + " void foo(String s);\n" + + "}\n" + + "public class X {\n" + + " void foo(I it) { System.out.println(\"foo(I)\");}\n" + + " void foo(J it) { System.out.println(\"foo(J)\");}\n" + + + " public static void main(String[] args) {\n" + + " new X().foo((Object o)->{});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " new X().foo((Object o)->{});\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments ((Object o) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " new X().foo((Object o)->{});\n" + + " ^^^^^^\n" + + "Lambda expression\'s parameter o is expected to be of type int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401789, [1.8][compiler] Enable support for method/constructor references in non-overloaded method calls. +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401790, Follow up of bug 401610, explicit constructor calls and allocation expressions needs updates too. +public void test401789_401790() { +this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo(X x);\n" + + "}\n" + + "public class X {\n" + + " int foo(I i) { return 10;}\n" + + " class Y {\n" + + " Y (I i) {}\n" + + " Y() {\n" + + " this(X::goo);\n" + + " }\n" + + " }\n" + + " X(I i) {}\n" + + " X() {\n" + + " this((x) -> { return 10;});\n" + + " }\n" + + " int goo() { return 0;}\n" + + " {\n" + + " foo(X::goo);\n" + + " new X((x)->{ return 10;});\n" + + " new X((x)->{ return 10;}).new Y((x) -> { return 0;});\n" + + " new X((x)->{ return 10;}) {};\n" + + " }\n" + + "}\n" + + "class Z extends X {\n" + + " Z() {\n" + + " super(X::goo);\n" + + " }\n" + + " Z(int i) {\n" + + " super (x -> 10);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 31)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401789, [1.8][compiler] Enable support for method/constructor references in non-overloaded method calls. +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401790, Follow up of bug 401610, explicit constructor calls and allocation expressions needs updates too. +public void test401789_401790a() { +this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(X x);\n" + + "}\n" + + "public class X {\n" + + " int foo(I i) { return 10;}\n" + + " class Y {\n" + + " Y (I i) {}\n" + + " Y() {\n" + + " this(X::goo);\n" + + " }\n" + + " }\n" + + " X(I i) {}\n" + + " X() {\n" + + " this((x) -> { return 10;});\n" + + " }\n" + + " int goo() { return 0;}\n" + + " {\n" + + " foo(X::goo);\n" + + " new X((x)->{ return 10;});\n" + + " new X((x)->{ return 10;}).new Y((x) -> { return 0;});\n" + + " new X((x)->{ return 10;}) {};\n" + + " }\n" + + "}\n" + + "class Z extends X {\n" + + " Z() {\n" + + " super(X::goo);\n" + + " }\n" + + " Z(int i) {\n" + + " super (x -> 10);\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " this(X::goo);\n" + + " ^^^^^^^^^^^^^\n" + + "The constructor X.Y(X::goo) is undefined\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " this(X::goo);\n" + + " ^^^^^^\n" + + "The type of goo() from the type X is int, this is incompatible with the descriptor\'s return type: String\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " this((x) -> { return 10;});\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "4. ERROR in X.java (at line 18)\n" + + " foo(X::goo);\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (X::goo)\n" + + "----------\n" + + "5. ERROR in X.java (at line 18)\n" + + " foo(X::goo);\n" + + " ^^^^^^\n" + + "The type of goo() from the type X is int, this is incompatible with the descriptor\'s return type: String\n" + + "----------\n" + + "6. ERROR in X.java (at line 19)\n" + + " new X((x)->{ return 10;});\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "7. ERROR in X.java (at line 20)\n" + + " new X((x)->{ return 10;}).new Y((x) -> { return 0;});\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "8. ERROR in X.java (at line 20)\n" + + " new X((x)->{ return 10;}).new Y((x) -> { return 0;});\n" + + " ^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "9. ERROR in X.java (at line 21)\n" + + " new X((x)->{ return 10;}) {};\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "10. ERROR in X.java (at line 26)\n" + + " super(X::goo);\n" + + " ^^^^^^^^^^^^^^\n" + + "The constructor X(X::goo) is undefined\n" + + "----------\n" + + "11. ERROR in X.java (at line 26)\n" + + " super(X::goo);\n" + + " ^^^^^^\n" + + "The type of goo() from the type X is int, this is incompatible with the descriptor\'s return type: String\n" + + "----------\n" + + "12. ERROR in X.java (at line 29)\n" + + " super (x -> 10);\n" + + " ^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "13. ERROR in X.java (at line 31)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401845, [1.8][compiler] Bad interaction between varargs and lambas/references +public void test401845() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo(X x);\n" + + "}\n" + + "public class X extends Zork {\n" + + " int foo(I ...i) { return 10;}\n" + + " int goo() { return 0;}\n" + + " {\n" + + " foo(X::goo);\n" + + " foo((x)-> {return 10;});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401845, [1.8][compiler] Bad interaction between varargs and lambas/references +public void test401845a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo(X x);\n" + + "}\n" + + "public class X {\n" + + " int foo(I [] ...i) { return 10;}\n" + + " int goo() { return 0;}\n" + + " {\n" + + " foo(X::goo);\n" + + " foo((x)-> {return 10;});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " foo(X::goo);\n" + + " ^^^\n" + + "The method foo(I[]...) in the type X is not applicable for the arguments (X::goo)\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " foo(X::goo);\n" + + " ^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " foo((x)-> {return 10;});\n" + + " ^^^\n" + + "The method foo(I[]...) in the type X is not applicable for the arguments (( x) -> {})\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " foo((x)-> {return 10;});\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401845, [1.8][compiler] Bad interaction between varargs and lambas/references +public void test401845b() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo(X x);\n" + + "}\n" + + "public class X extends Zork {\n" + + " X(I ...i) {}\n" + + " int goo() { return 0;}\n" + + " {\n" + + " new X(X::goo);\n" + + " new X((x)-> {return 10;});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401845, [1.8][compiler] Bad interaction between varargs and lambas/references +public void test401845c() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo(X x);\n" + + "}\n" + + "public class X extends Zork {\n" + + " X(I ...i) {}\n" + + " X() {\n" + + " this((x)-> {return 10;});\n" + + "}\n" + + " int goo() { return 0;}\n" + + " {\n" + + " new X(X::goo);\n" + + " new X((x)-> {return 10;});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401845, [1.8][compiler] Bad interaction between varargs and lambas/references +public void test401845d() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo(X x);\n" + + "}\n" + + "public class X extends Zork {\n" + + " class Y {\n" + + " Y(I ... i) {}\n" + + " }\n" + + " int goo() { return 0;}\n" + + " {\n" + + " new X().new Y(X::goo);\n" + + " new X().new Y((x)-> {return 10;});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401845, [1.8][compiler] Bad interaction between varargs and lambas/references +public void test401845e() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo(X x);\n" + + "}\n" + + "public class X extends Zork {\n" + + " X(I ...i) {}\n" + + " X() {\n" + + " this((x)-> {return 10;});\n" + + "}\n" + + " int goo() { return 0;}\n" + + " {\n" + + " new X(X::goo) {};\n" + + " new X((x)-> {return 10;}){};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401847, [1.8][compiler] Polyconditionals not accepted in method invocation contexts. +public void test401847() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " Integer foo(X x);\n" + + "}\n" + + "public class X {\n" + + " int foo(I ...i) { return 10;}\n" + + " int goo() { return 0;}\n" + + " {\n" + + " foo(true ? X::goo : X::goo);\n" + + " foo(true ? x-> 1 : x->0);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " foo(true ? X::goo : X::goo);\n" + + " ^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " foo(true ? x-> 1 : x->0);\n" + + " ^^^^\n" + + "Dead code\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401847, [1.8][compiler] Polyconditionals not accepted in method invocation contexts. +public void test401847a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(X x);\n" + + "}\n" + + "public class X {\n" + + " int foo(I ...i) { return 10;}\n" + + " int goo() { return 0;}\n" + + " {\n" + + " foo(true ? X::goo : X::goo);\n" + + " foo(true ? x-> 1 : x->0);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " foo(true ? X::goo : X::goo);\n" + + " ^^^\n" + + "The method foo(I...) in the type X is not applicable for the arguments ((true ? X::goo : X::goo))\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " foo(true ? X::goo : X::goo);\n" + + " ^^^^^^\n" + + "The type of goo() from the type X is int, this is incompatible with the descriptor\'s return type: String\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " foo(true ? X::goo : X::goo);\n" + + " ^^^^^^\n" + + "The type of goo() from the type X is int, this is incompatible with the descriptor\'s return type: String\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " foo(true ? x-> 1 : x->0);\n" + + " ^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " foo(true ? x-> 1 : x->0);\n" + + " ^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401939, [1.8][compiler] Incorrect shape analysis leads to method resolution failure . +public void test401939() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "class X {\n" + + " void foo(I i) {}\n" + + " I i = ()->{ throw new RuntimeException(); }; // OK\n" + + " {\n" + + " foo(()->{ throw new RuntimeException(); });\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void foo(I i) {}\n" + + " ^\n" + + "The parameter i is hiding a field from type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401939, [1.8][compiler] Incorrect shape analysis leads to method resolution failure . +public void test401939a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "class X {\n" + + " void foo(I i) {}\n" + + " I i = ()->{ throw new RuntimeException(); }; // OK\n" + + " {\n" + + " foo(()->{ if (1 == 2) throw new RuntimeException(); });\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void foo(I i) {}\n" + + " ^\n" + + "The parameter i is hiding a field from type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " foo(()->{ if (1 == 2) throw new RuntimeException(); });\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401939, [1.8][compiler] Incorrect shape analysis leads to method resolution failure . +public void test401939b() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(String x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " static final boolean FALSE = false;\n" + + " static final boolean TRUE = true;\n" + + " void goo(I i) {\n" + + " }\n" + + " void zoo() {\n" + + " final boolean NIJAM = true;\n" + + " final boolean POI = false;\n" + + " final boolean BLANK;\n" + + " BLANK = true;\n" + + " goo((x) -> { while (FALSE) throw new Exception(); });\n" + + " goo((x) -> { while (TRUE) throw new Exception(); });\n" + + " goo((x) -> { while (NIJAM) throw new Exception(); });\n" + + " goo((x) -> { while (POI) throw new Exception(); });\n" + + " goo((x) -> { if (TRUE) throw new Exception(); else throw new Exception(); });\n" + + " goo((x) -> { if (TRUE) throw new Exception(); });\n" + + " goo((x) -> { if (true) throw new Exception(); else throw new Exception(); });\n" + + " goo((x) -> { if (false) throw new Exception(); else throw new Exception(); });\n" + + " goo((x) -> { while (BLANK) throw new Exception(); });\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " goo((x) -> { while (FALSE) throw new Exception(); });\n" + + " ^^^^^^\n" + + "This lambda expression must return a result of type String\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " goo((x) -> { while (POI) throw new Exception(); });\n" + + " ^^^^^^\n" + + "This lambda expression must return a result of type String\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " goo((x) -> { if (TRUE) throw new Exception(); });\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (( x) -> {})\n" + + "----------\n" + + "4. ERROR in X.java (at line 22)\n" + + " goo((x) -> { while (BLANK) throw new Exception(); });\n" + + " ^^^^^^\n" + + "This lambda expression must return a result of type String\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401939, [1.8][compiler] Incorrect shape analysis leads to method resolution failure . +public void test401939c() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(String x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {\n" + + " }\n" + + " void zoo() {\n" + + " goo((x) -> { if (x) return null; });\n" + + " goo((x) -> {});\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " goo((x) -> { if (x) return null; });\n" + + " ^\n" + + "Type mismatch: cannot convert from String to boolean\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " goo((x) -> {});\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (( x) -> {})\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401939, [1.8][compiler] Incorrect shape analysis leads to method resolution failure . +public void test401939ca() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(String x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {\n" + + " }\n" + + " void zoo() {\n" + + " goo((x) -> {});\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " goo((x) -> {});\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (( x) -> {})\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401939, [1.8][compiler] Incorrect shape analysis leads to method resolution failure . +public void test401939d() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(boolean x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {\n" + + " }\n" + + " void zoo() {\n" + + " goo((x) -> { if (x) return null; });\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " goo((x) -> { if (x) return null; });\n" + + " ^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401939, [1.8][compiler] Incorrect shape analysis leads to method resolution failure . +public void test401939e() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(boolean x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {\n" + + " }\n" + + " void zoo() {\n" + + " goo((x) -> { return null; });\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " goo((x) -> { return null; });\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (( x) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " goo((x) -> { return null; });\n" + + " ^^^^^^^^^^^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401939, [1.8][compiler] Incorrect shape analysis leads to method resolution failure . +public void test401939f() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(boolean x) throws Exception;\n" + + "}\n" + + "public class X {\n" + + " void goo(I i) {\n" + + " }\n" + + " void zoo() {\n" + + " goo((x) -> { throw new Exception(); });\n" + + " }\n" + + "}\n", }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402219, [1.8][compiler] Compile time errors in lambda during hypothetical type check should render candidate method inapplicable. +public void test402219() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(String s1, String s2);\n" + + "}\n" + + "interface J {\n" + + " X foo(X x1, X x2);\n" + + "}\n" + + "public class X { \n" + + " void goo(I i) {}\n" + + " void goo(J j) {}\n" + + " public static void main(String [] args) {\n" + + " new X().goo((p1, p2) -> p1 = p1 + p2);\n" + + " }\n" + + " Zork z;\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " new X().goo((p1, p2) -> p1 = p1 + p2);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n" + + "2. 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=402219, [1.8][compiler] Compile time errors in lambda during hypothetical type check should render candidate method inapplicable. +public void test402219a() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUndocumentedEmptyBlock, CompilerOptions.ERROR); + this.runNegativeTest( + false /* skipJavac */, + new JavacTestOptions("Xlint:empty"), + new String[] { + "X.java", + "interface I {\n" + + " void foo(String s1, String s2);\n" + + "}\n" + + "interface J {\n" + + " X foo(X x1, X x2);\n" + + "}\n" + + "public class X { \n" + + " void goo(I i) {/* */}\n" + + " void goo(J j) {/* */}\n" + + " public static void main(String [] args) {\n" + + " new X().goo((p1, p2) -> {});\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " new X().goo((p1, p2) -> {});\n" + + " ^^\n" + + "Empty block should be documented\n" + + "----------\n", + null, + false, + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402219, [1.8][compiler] Compile time errors in lambda during hypothetical type check should render candidate method inapplicable. +public void test402219b() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(String s1, String s2);\n" + + "}\n" + + "interface J {\n" + + " X foo(X x1, X x2);\n" + + "}\n" + + "public class X { \n" + + " void goo(I i) {}\n" + + " void goo(J j) {}\n" + + " public static void main(String [] args) {\n" + + " new X().goo((p1, p2) -> p1 + p2);\n" + + " }\n" + + " Zork z;\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " new X().goo((p1, p2) -> p1 + p2);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n" + + "2. 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=402259, [1.8][compiler] NPE during overload resolution when there are syntax errors. +public void test402259() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " J foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " void foo(I i) {};\n" + + " public static void main(String[] args) {\n" + + " new X().foo(() -> { return () -> { return}; });\n" + + " }\n" + + "}\n", }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " new X().foo(() -> { return () -> { return}; });\n" + + " ^^^^^^\n" + + "Syntax error, insert \";\" to complete BlockStatements\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402261, [1.8][compiler] Shape analysis confused by returns from inner classes.. +public void test402261() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " J foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " void foo(I i) {};\n" + + " public static void main(String[] args) {\n" + + " new X().foo(() -> { class local { void foo() { return; }} return () -> { return;}; });\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402261, [1.8][compiler] Shape analysis confused by returns from inner classes.. +public void test402261a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " J foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " void foo(I i) {};\n" + + " public static void main(String[] args) {\n" + + " new X().foo(() -> { J j = () -> { return; }; return () -> { return;}; });\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402261, [1.8][compiler] Shape analysis confused by returns from inner classes.. +public void test402261b() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " J foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " void foo(I i) {};\n" + + " public static void main(String[] args) {\n" + + " new X().foo(() -> { J j = new J() { public void foo() { return; } }; return () -> { return;}; });\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402261, [1.8][compiler] Shape analysis confused by returns from inner classes.. +public void test402261c() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " J foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " void foo(I i) {};\n" + + " public static void main(String[] args) {\n" + + " new X().foo(() -> { return new J() { public void foo() { return; } }; });\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401769, [1.8][compiler] Explore solutions with better performance characteristics than LambdaExpression#copy() +public void test401769() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "class X {\n" + + " void g(I i) {}\n" + + " void g(J j) {}\n" + + " int f;\n" + + " {\n" + + " g(() -> f++);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " g(() -> f++);\n" + + " ^\n" + + "The method g(I) is ambiguous for the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402609, [1.8][compiler] AIOOB exception with a program using method references. +public void test402609() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "abstract class Y {\n" + + " abstract void foo();\n" + + "}\n" + + "public class X extends Y {\n" + + " void f(I i) {}\n" + + " void f(J j) {}\n" + + " \n" + + " void foo() {\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " f(super::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " f(super::foo);\n" + + " ^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402609, [1.8][compiler] AIOOB exception with a program using method references. +public void test402609a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "abstract class Y {\n" + + " abstract void foo();\n" + + "}\n" + + "public class X extends Y {\n" + + " void f(I i) {}\n" + + " \n" + + " void foo() {\n" + + " }\n" + + " \n" + + " public void main(String[] args) {\n" + + " f(super::foo);\n" + + " I i = super::foo;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " f(super::foo);\n" + + " ^^^^^^^^^^\n" + + "Cannot directly invoke the abstract method foo() for the type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " I i = super::foo;\n" + + " ^^^^^^^^^^\n" + + "Cannot directly invoke the abstract method foo() for the type Y\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402609, [1.8][compiler] AIOOB exception with a program using method references. +public void test402609b() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "abstract class Y {\n" + + " abstract void foo();\n" + + "}\n" + + "public class X extends Y {\n" + + " void f(I i) {}\n" + + " void f(J j) {}\n" + + " \n" + + " void foo() {\n" + + " }\n" + + " \n" + + " public void zoo(String[] args) {\n" + + " f(super::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " f(super::foo);\n" + + " ^\n" + + "The method f(I) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " f(super::foo);\n" + + " ^^^^^^^^^^\n" + + "Cannot directly invoke the abstract method foo() for the type Y\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402609, [1.8][compiler] AIOOB exception with a program using method references. +public void test402609c() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "abstract class Y {\n" + + " void foo() {}\n" + + "}\n" + + "public class X extends Y {\n" + + " void f(I i) {}\n" + + " void f(J j) {}\n" + + " \n" + + " void foo() {\n" + + " }\n" + + " \n" + + " public void main(String[] args) {\n" + + " f(super::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " f(super::foo);\n" + + " ^\n" + + "The method f(I) is ambiguous for the type X\n" + + "----------\n"); +} + +// 15.28: +// https://bugs.eclipse.org/382350 - [1.8][compiler] Unable to invoke inherited default method via I.super.m() syntax +public void testSuperReference01() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements I2, I1 {\n" + + " @Override\n" + + " public void print() {\n" + + " System.out.print(\"!\");" + + " }\n" + + " void test() {\n" + + " doOutput(I1.super::print); // illegal attempt to skip I2.print()\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().test();\n" + + " }\n" + + " void doOutput(CanPrint printer) {\n" + + " printer.print();" + + " }\n" + + "}\n" + + "interface CanPrint {\n" + + " void print();\n" + + "}\n" + + "interface I1 {\n" + + " default void print() {\n" + + " System.out.print(\"O\");\n" + + " }\n" + + "}\n" + + "interface I2 extends I1 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " doOutput(I1.super::print); // illegal attempt to skip I2.print()\n" + + " ^^^^^^^^\n" + + "Illegal reference to super type I1, cannot bypass the more specific direct super type I2\n" + + "----------\n" + ); +} + +// 15.28.1: +// https://bugs.eclipse.org/382350 - [1.8][compiler] Unable to invoke inherited default method via I.super.m() syntax +public void testSuperReference02() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I0 {\n" + + " default void print() { System.out.println(\"I0\"); }\n" + + "}\n" + + "\n" + + "interface IA extends I0 {}\n" + + "\n" + + "interface IB extends I0 {\n" + + " @Override default void print() {\n" + + " System.out.println(\"IB\");\n" + + " }\n" + + "}\n" + + "public class X implements IA, IB {\n" + + " @Override\n" + + " public void print() {\n" + + " System.out.print(\"!\");" + + " }\n" + + " void test() {\n" + + " doOutput(IA.super::print); // illegal attempt to skip IB.print()\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().test();\n" + + " }\n" + + " void doOutput(CanPrint printer) {\n" + + " printer.print();" + + " }\n" + + "}\n" + + "interface CanPrint {\n" + + " void print();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " doOutput(IA.super::print); // illegal attempt to skip IB.print()\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal reference to super method print() from type I0, cannot bypass the more specific override from type IB\n" + + "----------\n" + ); +} + +public void testSuperReference03() { + this.runNegativeTest( + new String[] { + "XY.java", + "interface J {\n" + + " void foo(int x);\n" + + "}\n" + + "class XX {\n" + + " public void foo(int x) {}\n" + + "}\n" + + "class Y extends XX {\n" + + " static class Z {\n" + + " public static void foo(int x) {\n" + + " System.out.print(x);\n" + + " }\n" + + " }\n" + + " public void foo(int x) {\n" + + " System.out.print(x);\n" + + " }\n" + + "}\n" + + "\n" + + "public class XY extends XX {\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void bar(String [] args) {\n" + + " Y y = new Y();\n" + + " J jj = y :: foo;\n" + + " J jx = y.super :: foo;\n" + + " }\n" + + " public static void main (String [] args) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in XY.java (at line 23)\n" + + " J jx = y.super :: foo;\n" + + " ^\n" + + "y cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406614, [1.8][compiler] Missing and incorrect errors for lambda in explicit constructor call. +public void test406614() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int doit();\n" + + "}\n" + + "public class X {\n" + + " int f;\n" + + " X(I i) {\n" + + " }\n" + + " X() {\n" + + " this(() -> this.f);\n" + + " }\n" + + " X(short s) {\n" + + " this(() -> this.g());\n" + + " }\n" + + " X (int x) {\n" + + " this(() -> f);\n" + + " }\n" + + " X (long x) {\n" + + " this(() -> g());\n" + + " }\n" + + " int g() {\n" + + " return 0;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " this(() -> this.f);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(() -> {}) is undefined\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " this(() -> this.f);\n" + + " ^^^^\n" + + "Cannot refer to \'this\' nor \'super\' while explicitly invoking a constructor\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " this(() -> this.g());\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor X(() -> {}) is undefined\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " this(() -> this.g());\n" + + " ^^^^\n" + + "Cannot refer to \'this\' nor \'super\' while explicitly invoking a constructor\n" + + "----------\n" + + "5. ERROR in X.java (at line 15)\n" + + " this(() -> f);\n" + + " ^^^^^^^^^^^^^^\n" + + "The constructor X(() -> {}) is undefined\n" + + "----------\n" + + "6. ERROR in X.java (at line 15)\n" + + " this(() -> f);\n" + + " ^\n" + + "Cannot refer to an instance field f while explicitly invoking a constructor\n" + + "----------\n" + + "7. ERROR in X.java (at line 18)\n" + + " this(() -> g());\n" + + " ^\n" + + "Cannot refer to an instance method while explicitly invoking a constructor\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial +public void test406588() { + this.runNegativeTest( + false /* skipJavac */, + null, + new String[] { + "X.java", + "interface I {\n" + + " X.Y.Z makeY(int x);\n" + + "}\n" + + "public class X {\n" + + " class Y {\n" + + " Y(I i) {\n" + + " \n" + + " }\n" + + " Y() {\n" + + " this(Z::new);\n" + + " }\n" + + " class Z {\n" + + " Z(int x) {\n" + + "\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " this(Z::new);\n" + + " ^^^^^^\n" + + "No enclosing instance of the type X.Y is accessible in scope\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406586, [1.8][compiler] Missing error about unavailable enclosing instance +public void test406586() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " X.Y makeY();\n" + + "}\n" + + "public class X {\n" + + " public class Y {\n" + + " }\n" + + " static void foo() {\n" + + " I i = Y::new;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " I i = Y::new;\n" + + " ^^^^^^\n" + + "No enclosing instance of the type X is accessible in scope\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401989, [1.8][compiler] hook lambda expressions into "can be static" analysis +public void test401989() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError, + new String[] { + "X.java", + "interface I {\n" + + " void make();\n" + + "}\n" + + "public class X {\n" + + " int val;\n" + + " private I test() {\n" + + " return () -> System.out.println(val);\n" + + " }\n" + + " private I testCanBeStatic() {\n" + + " return () -> System.out.println();\n" + + " }\n" + + " public void call() { test().make(); testCanBeStatic().make();}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " private I testCanBeStatic() {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The method testCanBeStatic() from the type X can be declared as static\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor +public void test406773() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " I i = X::new;\n" + + " ^^^^^^\n" + + "Access to enclosing constructor X(int) is emulated by a synthetic accessor method\n" + + "----------\n"; + this.runNegativeTest( + false, + JavacTestOptions.SKIP, /* skip, because we are using custom error settings here */ + new String[] { + "X.java", + "interface I {\n" + + " X makeX(int x);\n" + + "}\n" + + "public class X {\n" + + " void foo() {\n" + + " int local = 10;\n" + + " class Y extends X {\n" + + " class Z extends X {\n" + + " void f() {\n" + + " I i = X::new;\n" + + " i.makeX(123456);\n" + + " i = Y::new;\n" + + " i.makeX(987654);\n" + + " i = Z::new;\n" + + " i.makeX(456789);\n" + + " }\n" + + " private Z(int z) {\n" + + " }\n" + + " Z() {}\n" + + " }\n" + + " private Y(int y) {\n" + + " System.out.println(local);\n" + + " }\n" + + " private Y() {\n" + + " }\n" + + " }\n" + + " new Y().new Z().f();\n" + + " }\n" + + " private X(int x) {\n" + + " }\n" + + " X() {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + errMessage, + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=406859, [1.8][compiler] Bad hint that method could be declared static +public void test406859a() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo(int i);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " I i = x::foo;\n" + + " i.foo(3);\n" + + " }\n" + + " int foo(int x) {\n" + + " return x;\n" + + " } \n" + + "}\n" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=406859, [1.8][compiler] Bad hint that method could be declared static +public void test406859b() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit (Y y);\n" + + "}\n" + + "\n" + + "class Y {\n" + + " void foo() {\n" + + " return;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = Y::foo; \n" + + " Y y = new Y();\n" + + " i.doit(y);\n" + + " }\n" + + "}\n" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=406859, [1.8][compiler] Bad hint that method could be declared static +public void test406859c() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void doit ();\n" + + "}\n" + + "\n" + + "class Y {\n" + + " void foo() { \n" + + " return;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = new Y()::foo;\n" + + " i.doit();\n" + + " }\n" + + "}\n" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406859, [1.8][compiler] Bad hint that method could be declared static +// A case where we can't help but report the wrong hint due to separate compilation. +public void test406859d() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.WARNING); + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "Y.java", + "public class Y {\n" + + " void foo() {\n" + + " return;\n" + + " }\n" + + "}", + "X.java", + "interface I {\n" + + " void doit ();\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = new Y()::foo;\n" + + " i.doit();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Y.java (at line 2)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type Y can potentially be declared as static\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=410114, [1.8] CCE when trying to parse method reference expression with inappropriate type arguments +public void test410114() throws IOException { + String source = "interface I {\n" + + " void foo(Y y);\n" + + "}\n" + + "public class Y {\n" + + " class Z {\n" + + " Z(Y y) {\n" + + " System.out.println(\"Y.Z:: new\");\n" + + " }\n" + + " void bar() {\n" + + " I i = Y.Z:: new;\n" + + " i.foo(new Y());\n" + + " i = Y.Z:: new;\n" + + " i.foo(new Y());\n" + + " i = Y.Z:: new;\n" + + " i.foo(new Y());\n" + + " }\n" + + " }\n" + + "}\n"; + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[]{"Y.java", + source}, + "----------\n" + + "1. WARNING in Y.java (at line 10)\n" + + " I i = Y.Z:: new;\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor Y.Z(Y) of type Y.Z; it should not be parameterized with arguments \n" + + "----------\n" + + "2. WARNING in Y.java (at line 14)\n" + + " i = Y.Z:: new;\n" + + " ^^^^^^^^^\n" + + "Type safety: The constructor Y.Z(Y) belongs to the raw type Y.Z. References to generic type Y.Z should be parameterized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=412453, +//[1.8][compiler] Stackoverflow when compiling LazySeq +public void test412453() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.AbstractList;\n" + + "import java.util.Comparator;\n" + + "import java.util.Optional;\n" + + "\n" + + "import java.util.function.*;\n" + + "\n" + + "abstract class Y extends AbstractList {\n" + + " public > Optional minBy(Function propertyFun) { return null;} \n" + + "}\n" + + "\n" + + "public class X {\n" + + " public void foo(Y empty) throws Exception {\n" + + " final Optional min = empty.minBy((a, b) -> a - b);\n" + + " }\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " final Optional min = empty.minBy((a, b) -> a - b);\n" + + " ^^^^^\n" + + "The method minBy(Function) in the type Y is not applicable for the arguments (( a, b) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " final Optional min = empty.minBy((a, b) -> a - b);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method apply(Integer)\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* custom options */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=412284, +//[1.8][compiler] [1.8][compiler] Inspect all casts to/instanceof AbstractMethodDeclaration to eliminate potential CCEs +public void test412284a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "interface I { void foo() throws IOException; }\n" + + "public class X {\n" + + " void bar() {\n" + + " I i = () -> {\n" + + " try {\n" + + " throw new IOException();\n" + + " } catch (IOException e) { \n" + + " } finally {\n" + + " i.foo();\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " i.foo();\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* custom options */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=412284, +//[1.8][compiler] [1.8][compiler] Inspect all casts to/instanceof AbstractMethodDeclaration to eliminate potential CCEs +public void test412284b() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { void foo();}\n" + + "class X { \n" + + " final int t;\n" + + " X(){\n" + + " I x = () -> {\n" + + " try {\n" + + " t = 3;\n" + + " } catch (Exception e) {\n" + + " t = 4;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X(){\n" + + " ^^^\n" + + "The blank final field t may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " t = 3;\n" + + " ^\n" + + "The final field X.t cannot be assigned\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " t = 4;\n" + + " ^\n" + + "The final field X.t cannot be assigned\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* custom options */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=412284, +//[1.8][compiler] [1.8][compiler] Inspect all casts to/instanceof AbstractMethodDeclaration to eliminate potential CCEs +public void test412284c() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { void foo();}\n" + + "class X { \n" + + " final int t;\n" + + " X(){\n" + + " I x = () -> {\n" + + " try {\n" + + " t += 3;\n" + + " } catch (Exception e) {\n" + + " t += 4;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X(){\n" + + " ^^^\n" + + "The blank final field t may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " t += 3;\n" + + " ^\n" + + "The blank final field t may not have been initialized\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " t += 3;\n" + + " ^\n" + + "The final field X.t cannot be assigned\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " t += 4;\n" + + " ^\n" + + "The blank final field t may not have been initialized\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " t += 4;\n" + + " ^\n" + + "The final field X.t cannot be assigned\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* custom options */ + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=412650 +// [1.8][compiler]Incongruent Lambda Exception thrown +public void test412650() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String sam();\n" + + "}\n" + + "public class X {\n" + + " static String foo(I i) { return \"\"; }\n" + + " public static void main(String[] args) {\n" + + " foo(() -> foo(X::getInt));\n" + + " }\n" + + " static Integer getInt() { return 0; }\n" + + "}\n" + }, + "----------\n" + + // this is reported because the lambda has errors and thus is not marked as valueCompatible: + "1. ERROR in X.java (at line 7)\n" + + " foo(() -> foo(X::getInt));\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " foo(() -> foo(X::getInt));\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (X::getInt)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " foo(() -> foo(X::getInt));\n" + + " ^^^^^^^^^\n" + + "The type of getInt() from the type X is Integer, this is incompatible with the descriptor\'s return type: String\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* custom options */ + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=409544 +// Bug 409544 - [1.8][compiler] Any local variable used but not declared in a lambda body must be definitely assigned before the lambda body. +public void test409544() { + this.runNegativeTest( + new String[] { + "Sample.java", + "public class Sample{\n" + + " interface Int { void setInt(int[] i); }\n" + + " public static void main(String[] args) {\n" + + " int j;\n" + + " Int int1 = (int... i) -> {\n" + + " j=10;\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Sample.java (at line 6)\n" + + " j=10;\n" + + " ^\n" + + "Local variable j defined in an enclosing scope must be final or effectively final\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* custom options */ + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=409544 +// Bug 409544 - [1.8][compiler] Any local variable used but not declared in a lambda body must be definitely assigned before the lambda body. +public void test409544b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Int {\n" + + " void setInt(int[] i);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + "\n" + + " int j = 0;\n" + + " Int i = new Int() {\n" + + " @Override\n" + + " public void setInt(int[] i) {\n" + + " j = 10;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " public void setInt(int[] i) {\n" + + " ^\n" + + "The parameter i is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " j = 10;\n" + + " ^\n" + + "Local variable j defined in an enclosing scope must be final or effectively final\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* custom options */ + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=415844 +// Bug 415844 - [1.8][compiler] Blank final initialized in a lambda expression should not pass +public void test415844a() { + this.runNegativeTest( + new String[] { + "Sample.java", + "public class Sample{\n" + + " interface Int { void setInt(int i); }\n" + + " public static void main(String[] args) {\n" + + " final int j;\n" + + " Int int1 = (int i) -> {\n" + + " j=10;\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Sample.java (at line 6)\n" + + " j=10;\n" + + " ^\n" + + "The final local variable j cannot be assigned, since it is defined in an enclosing type\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* custom options */ + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=415844 +// Bug 415844 - [1.8][compiler] Blank final initialized in a lambda expression should not pass +public void test415844b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Int {\n" + + " void setInt(int[] i);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final int j;\n" + + " Int i = new Int() {\n" + + " @Override\n" + + " public void setInt(int[] i) {\n" + + " j = 10;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " public void setInt(int[] i) {\n" + + " ^\n" + + "The parameter i is hiding another local variable defined in an enclosing scope\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " j = 10;\n" + + " ^\n" + + "The final local variable j cannot be assigned, since it is defined in an enclosing type\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* custom options */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=404657 [1.8][compiler] Analysis for effectively final variables fails to consider loops +public void test404657_final() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void executeLater(Runnable r) { /* ... */\n" + + " }\n" + + " public int testFinally() {\n" + + " int n;\n" + + " try {\n" + + " n = 42;\n" + + " executeLater(() -> System.out.println(n)); // Error: n is not effectively final\n" + + " } finally {\n" + + " n = 23;\n" + + " }\n" + + " return n;\n" + + " }\n" + + "\n" + + "}\n" + + "" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " executeLater(() -> System.out.println(n)); // Error: n is not effectively final\n" + + " ^\n" + + "Local variable n defined in an enclosing scope must be final or effectively final\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=404657 [1.8][compiler] Analysis for effectively final variables fails to consider loops +public void test404657_loop() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void executeLater(Runnable r) { /* ... */\n" + + " }\n" + + " public void testLoop() {\n" + + " int n;\n" + + " for (int i = 0; i < 3; i++) {\n" + + " n = i;\n" + + " executeLater(() -> System.out.println(n)); // Error: n is not effectively final\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + + "" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " executeLater(() -> System.out.println(n)); // Error: n is not effectively final\n" + + " ^\n" + + "Local variable n defined in an enclosing scope must be final or effectively final\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=420580, [1.8][compiler] ReferenceExpression drops explicit type arguments +public void testExplicitTypeArgument() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void sam(X t, Integer s);\n" + + "}\n" + + "public class X {\n" + + " void function(T t) {}\n" + + " public static void main(String [] args) {\n" + + " I i = X::function;\n" + + " i = X::function;\n" + + " i = X::function;\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i = X::function;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type X does not define function(X, Integer) that is applicable here\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=420582, [1.8][compiler] Compiler should allow creation of generic array creation with unbounded wildcard type arguments +public void testGenericArrayCreation() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " X[] makeArray(int i);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = X[]::new; // OK.\n" + + " i = X[]::new; // ! OK\n" + + " X [] a = new X[10]; // OK\n" + + " a = new X[10]; // ! OK\n" + + " System.out.println(i.makeArray(1024).length);\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " i = X[]::new; // ! OK\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " a = new X[10]; // ! OK\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot create a generic array of X\n" + + "----------\n" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=420598, [1.8][compiler] Incorrect error about intersection cast type not being a functional interface. +public void testIntersectionCast() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J extends I {\n" + + " void foo();\n" + + "}\n" + + "interface K {\n" + + "}\n" + + "interface L {\n" + + " void foo();\n" + + "}\n" + + "interface All extends J, I, K, L {}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (I & Serializable) () -> {};\n" + + " i = (I & J & K) () -> {};\n" + + " i = (J & I & K) () -> {}; \n" + + " i = (J & I & K & L) () -> {}; \n" + + " i = (All) () -> {};\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421711, [1.8][compiler] '_' as identifier for a lambda parameter should be rejected. +public void testUnderScoreParameter() { + String level = this.complianceLevel >= ClassFileConstants.JDK9 ? "ERROR" : "WARNING"; + String errorMessage = this.complianceLevel >= ClassFileConstants.JDK9 ? "\'_\' is a keyword from source level 9 onwards, cannot be used as identifier\n" : "\'_\' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on\n"; + this.runNegativeTest( + new String[] { + "X.java", + "interface F {\n" + + " void foo(int x);\n" + + "}\n" + + "interface I {\n" + + " default void foo() {\n" + + " F f = (int _) -> {\n" + + " };\n" + + " F f2 = _ -> {};\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " F f = (int _) -> {\n" + + " ^\n" + + "\'_\' is a keyword from source level 9 onwards, cannot be used as identifier\n" + + "----------\n" + + "2. "+ level +" in X.java (at line 8)\n" + + " F f2 = _ -> {};\n" + + " ^\n" + + errorMessage + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " F f2 = _ -> {};\n" + + " ^\n" + + "\'_\' is a keyword from source level 9 onwards, cannot be used as identifier\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383096, [1.8][compiler]NullPointerException with a wrong lambda code snippet. +public void test383096() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {}\n" + + "class XI {\n" + + " void foo() {\n" + + " I t1 = f -> {{};\n" + + " I t2 = () -> 42;\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " I t2 = () -> 42;\n" + + " ^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " } \n" + + " ^\n" + + "Syntax error, insert \";\" to complete BlockStatements\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n", + true // statement recovery. + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422516, [1.8][compiler] NPE in ArrayReference.analyseAssignment. +public void test422516() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws InterruptedException {\n" + + " final int[] result= { 0 };\n" + + " Thread t = new Thread(() -> {\n" + + " sysoresult[0]= 42;\n" + + " });\n" + + " t.start();\n" + + " t.join();\n" + + " System.out.println(result[0]);\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " sysoresult[0]= 42;\n" + + " ^^^^^^^^^^\n" + + "sysoresult cannot be resolved to a variable\n" + + "----------\n", + true // statement recovery. + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422516, [1.8][compiler] NPE in ArrayReference.analyseAssignment. +public void test422516a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws InterruptedException {\n" + + " final int[] result= { 0 };\n" + + " Thread t = new Thread(() -> {\n" + + " System.out.printlnresult[0]= 42;\n" + + " });\n" + + " t.start();\n" + + " t.join();\n" + + " System.out.println(result[0]);\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.printlnresult[0]= 42;\n" + + " ^^^^^^^^^^^^^\n" + + "printlnresult cannot be resolved or is not a field\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422489, [1.8][compiler] NPE in CompoundAssignment.analyseCode when creating AST for java.util.stream.Collectors +public void test422489() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String [] x, String y);\n" + + "}\n" + + "interface J {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " }\n" + + " static void goo(J j) {\n" + + " }\n" + + " public static void main(String[] args) throws InterruptedException {\n" + + " goo((x, y) -> { x[0] += 1; });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " goo((x, y) -> { x[0] += 1; });\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422489, [1.8][compiler] NPE in CompoundAssignment.analyseCode when creating AST for java.util.stream.Collectors +public void test422489a() { // interfaces and methods order changed, triggers NPE. + this.runNegativeTest( + new String[] { + "X.java", + "interface J {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "interface I {\n" + + " void foo(String [] x, String y);\n" + + "}\n" + + "public class X {\n" + + " static void goo(J j) {\n" + + " }\n" + + " static void goo(I i) {\n" + + " }\n" + + " public static void main(String[] args) throws InterruptedException {\n" + + " goo((x, y) -> { x[0] += 1; });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " goo((x, y) -> { x[0] += 1; });\n" + + " ^^^\n" + + "The method goo(J) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " goo((x, y) -> { x[0] += 1; });\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to int\n" + + "----------\n" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422489, [1.8][compiler] NPE in CompoundAssignment.analyseCode when creating AST for java.util.stream.Collectors +public void test422489b() { // interfaces and methods order changed, triggers NPE. + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.JavacHasWarningsEclipseNotConfigured, + new String[] { + "X.java", + "interface I {\n" + + " String foo(String [] x, String y);\n" + + "}\n" + + "interface J {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " static void goo(J j) {\n" + + " }\n" + + " static void goo(I i) {\n" + + " }\n" + + " public static void main(String[] args) throws InterruptedException {\n" + + " goo((x, y) -> { return x[0] += 1; });\n" + + " }\n" + + "}\n" + }, + "" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422489, [1.8][compiler] NPE in CompoundAssignment.analyseCode when creating AST for java.util.stream.Collectors +public void test422489c() { // interfaces and methods order changed, triggers NPE. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(String [] x, String y);\n" + + "}\n" + + "interface J {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " static void goo(J j) {\n" + + " }\n" + + " static void goo(I i) {\n" + + " }\n" + + " public static void main(String[] args) throws InterruptedException {\n" + + " goo((x, y) -> x[0] += 1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " goo((x, y) -> x[0] += 1);\n" + + " ^^^\n" + + "The method goo(J) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " goo((x, y) -> x[0] += 1);\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to int\n" + + "----------\n" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422489, [1.8][compiler] NPE in CompoundAssignment.analyseCode when creating AST for java.util.stream.Collectors +public void test422489d() { // interfaces and methods order changed, triggers NPE. + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(String x, String y);\n" + + "}\n" + + "interface J {\n" + + " void foo(int x, int y);\n" + + "}\n" + + "public class X {\n" + + " static void goo(J j) {\n" + + " }\n" + + " static void goo(I i) {\n" + + " }\n" + + " public static void main(String[] args) throws InterruptedException {\n" + + " goo((x, y) -> x[0] += 1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " goo((x, y) -> x[0] += 1);\n" + + " ^^^\n" + + "The method goo(J) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " goo((x, y) -> x[0] += 1);\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to int\n" + + "----------\n" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422801, [1.8][compiler] NPE in MessageSend.analyseCode in lambda body with missing import +public void test422801() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Random arg) {\n" + + " new Thread(() -> {\n" + + " arg.intValue();\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(Random arg) {\n" + + " ^^^^^^\n" + + "Random cannot be resolved to a type\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422801, [1.8][compiler] NPE in MessageSend.analyseCode in lambda body with missing import +public void test422801a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Random arg;\n" + + " public void foo() {\n" + + " new Thread(() -> {\n" + + " arg.intValue();\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Random arg;\n" + + " ^^^^^^\n" + + "Random cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " arg.intValue();\n" + + " ^^^\n" + + "Random cannot be resolved to a type\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405134, [1.8][code assist + compiler] compiler and code assist problem in multilevel lambda with curly bracketed body +public void test405134a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Foo { \n" + + " int run1(int s1, int s2);\n" + + " static int x2 = 0;\n" + + "}\n" + + "interface Foo1 {\n" + + " Foo run2(int argFoo1);\n" + + "}\n" + + "interface X extends Foo{\n" + + " static int x1 = 2;\n" + + " static Foo f = (x5, x6) -> x5;\n" + + " static Foo1 f1 = af1 -> (a1,b1) -> {int uniqueName = 4; return uniqueName};\n" + // missing semicolon triggers an NPE + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " static Foo1 f1 = af1 -> (a1,b1) -> {int uniqueName = 4; return uniqueName};\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \";\" to complete FieldDeclaration\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete InterfaceBody\n" + + "----------\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421927, [1.8][compiler] Bad diagnostic: Unnecessary cast from I to I for lambdas. +public void test421927() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " I i = (I & java.io.Serializable) () -> 42;\n" + + "}\n" + }, + "", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421927, [1.8][compiler] Bad diagnostic: Unnecessary cast from I to I for lambdas. +public void test421927a() { + this.runNegativeTest( + false, + Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "X.java", + "interface I { \n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " I i;\n" + + " { i = (I & java.io.Serializable) () -> 42;\n" + + " I j = (I & java.io.Serializable) () -> 42;\n" + + " j = (I & java.io.Serializable) j == null ? () -> 42 : () -> 42;\n" + + " j = goo((I & java.io.Serializable) () -> 42);\n" + + " }\n" + + " I goo(I i) {\n" + + " return (I & java.io.Serializable) () -> 42;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " I goo(I i) {\n" + + " ^\n" + + "The parameter i is hiding a field from type X\n" + + "----------\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=423429, [1.8][compiler] NPE in LambdaExpression.analyzeCode +public void test423429() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " J foo(String x, String y);\n" + + "}\n" + + "interface J {\n" + + " K foo(String x, String y);\n" + + "}\n" + + "interface K {\n" + + " int foo(String x, int y);\n" + + "}\n" + + "public class X {\n" + + " static void goo(K i) {}\n" + + " public static void main(String[] args) {\n" + + " goo ((first, second) -> {\n" + + " return (xyz, pqr) -> first.length();\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " return (xyz, pqr) -> first.length();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=423129, [1.8][compiler] Hook up lambda expressions into statement recovery +public void test423129() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " String foo(Integer x);\n" + + "}\n" + + "public class X {\n" + + " static void goo(String s) {\n" + + " }\n" + + " static void goo(I i) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo((xyz) -> {\n" + + " System.out.println(xyz);\n" + + " return xyz.\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " return xyz.\n" + + " ^^^\n" + + "Type mismatch: cannot convert from Integer to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " return xyz.\n" + + " ^\n" + + "Syntax error on token \".\", ; expected\n" + + "----------\n", + true); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=423129, [1.8][compiler] Hook up lambda expressions into statement recovery +public void test423129b() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Arrays;\n" + + "import java.util.Collections;\n" + + "import java.util.Comparator;\n" + + "public class X {\n" + + " int compareTo(X x) { return 0; }\n" + + " void foo() {\n" + + " Collections.sort(new ArrayList(Arrays.asList(new X(), new X(), new X())),\n" + + " (X o1, X o2) -> o1.compareTo(o2)); //[2]\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n", + true); +} +// modified the previous example to craft a result requiring constant narrowing (13 -> byte) +public void test423129c() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.Arrays;\n" + + "class MySorter { static void sort(List l, MyComparator comp) { } }\n" + + "interface MyComparator { byte compare(T t1, T t2); }\n" + + "public class X {\n" + + " int compareTo(X x) { return 0; }\n" + + " void foo() {\n" + + " MySorter.sort(new ArrayList(Arrays.asList(new X(), new X(), new X())),\n" + + " (X o1, X o2) -> 13);\n" + + " }\n" + + "}\n" + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424400, [1.8] Interfaces in the same hierarchy are allowed in an intersection cast with different type argument +public void test424400() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements MyComparable{\n" + + " public static void main(String argv[]) {\n" + + " int result = ((Comparable & MyComparable) new X()).compareTo(1);\n" + + " }\n" + + " public int compareTo(T o) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "interface MyComparable extends Comparable {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int result = ((Comparable & MyComparable) new X()).compareTo(1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " int result = ((Comparable & MyComparable) new X()).compareTo(1);\n" + + " ^^^^^^^^^^^^\n" + + "MyComparable is a raw type. References to generic type MyComparable should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " int result = ((Comparable & MyComparable) new X()).compareTo(1);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424400, [1.8] Interfaces in the same hierarchy are allowed in an intersection cast with different type argument +public void _test424400() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements MyComparable {\n" + + " public static void main(String argv[]) {\n" + + " int result = ((Comparable & MyComparable) new X()).compareTo(1);\n" + + " }\n" + + " public int compareTo(T o) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "interface MyComparable {\n" + + " public int compareTo(T value);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int result = ((Comparable & MyComparable) new X()).compareTo(1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The interface Comparable cannot be implemented more than once with different arguments: Comparable and Comparable\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " int result = ((Comparable & MyComparable) new X()).compareTo(1);\n" + + " ^^^^^^^^^^^^\n" + + "MyComparable is a raw type. References to generic type MyComparable should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " int result = ((Comparable & MyComparable) new X()).compareTo(1);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424444, [1.8] VerifyError when constructor reference used with array +public void test424444() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface Functional {\n" + + " T foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = goo(10);\n" + + " Functional contr = int[]::new;\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " static int [] goo(int x) {\n" + + " return new int [x];\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Functional contr = int[]::new;\n" + + " ^^^^^^^^^^\n" + + "Constructed array int[] cannot be assigned to Integer[] as required in the interface descriptor \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425512, [1.8][compiler] Arrays should be allowed in intersection casts +public void test425512() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface IJK {\n" + + " void foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = (int [] & IJK) null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int [] a = (int [] & IJK) null;\n" + + " ^^^^^^\n" + + "Arrays are not allowed in intersection cast operator\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425512, [1.8][compiler] Arrays should be allowed in intersection casts +public void test425512a() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "interface IJK {\n" + + " void foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = (int [] & Serializable & IJK) null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " int [] a = (int [] & Serializable & IJK) null;\n" + + " ^^^^^^\n" + + "Arrays are not allowed in intersection cast operator\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425512, [1.8][compiler] Arrays should be allowed in intersection casts +public void test425512b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "interface IJK {\n" + + " void foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = (int [] & IJK & Serializable) null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " int [] a = (int [] & IJK & Serializable) null;\n" + + " ^^^^^^\n" + + "Arrays are not allowed in intersection cast operator\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425512, [1.8][compiler] Arrays should be allowed in intersection casts +public void test425512c() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "interface IJK {\n" + + " void foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int [] a = (IJK & Serializable & int []) null;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " int [] a = (IJK & Serializable & int []) null;\n" + + " ^^^^^^\n" + + "The type int[] is not an interface; it cannot be specified as a bounded parameter\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425512, [1.8][compiler] Arrays should be allowed in intersection casts +public void test425512cd() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "interface I {\n" + + " void foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " I i = (int [] & I) (i) -> {};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i = (int [] & I) (i) -> {};\n" + + " ^^^^^^\n" + + "Arrays are not allowed in intersection cast operator\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " I i = (int [] & I) (i) -> {};\n" + + " ^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425512, [1.8][compiler] Arrays should be allowed in intersection casts +public void test425512ce() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "interface I {\n" + + " void foo(int size);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " I i = (int [] & Serializable) (i) -> {};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I i = (int [] & Serializable) (i) -> {};\n" + + " ^^^^^^\n" + + "Arrays are not allowed in intersection cast operator\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " I i = (int [] & Serializable) (i) -> {};\n" + + " ^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425621, [1.8][compiler] Missing error for raw type in constructor reference with explicit type arguments +public void test425621() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " Y() {}\n" + + "} \n" + + "interface I {\n" + + " Y foo();\n" + + "}\n" + + "public class X {\n" + + " I i = Y::new;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Y foo();\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " I i = Y::new;\n" + + " ^\n" + + "Explicit type arguments cannot be specified in raw constructor reference expression\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=423803, [1.8][compiler] No error shown for ambiguous reference to the method +public void test423803() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class C2 implements C2_Sup {\n" + + " public static final FI fi = x -> x++;\n" + + " public static final FL fl = x -> x++;\n" + + " {\n" + + " bar(x -> x++); // [1]\n" + + " bar(fl); \n" + + " }\n" + + " void bar(FI fi) { }\n" + + "}\n" + + "interface C2_Sup { \n" + + " default void bar(FL fl) { }\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface FI {\n" + + " int foo(int x);\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface FL {\n" + + " long foo(long x);\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " bar(x -> x++); // [1]\n" + + " ^^^\n" + + "The method bar(FI) is ambiguous for the type C2\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " void bar(FI fi) { }\n" + + " ^^\n" + + "The parameter fi is hiding a field from type C2\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=423803, [1.8][compiler] No error shown for ambiguous reference to the method +public void test423803b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements K {\n" + + " {\n" + + " bar(x -> x++); // [1]\n" + + " }\n" + + " void bar(I fi) { }\n" + + "}\n" + + "interface K { \n" + + " default void bar(J fl) { }\n" + + "}\n" + + "interface I {\n" + + " int foo(int x);\n" + + "}\n" + + "interface J {\n" + + " long foo(long x);\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " bar(x -> x++); // [1]\n" + + " ^^^\n" + + "The method bar(I) is ambiguous for the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425712, [1.8][compiler] Valid program rejected by the compiler. +public void test425712() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class C2 {\n" + + " {\n" + + " bar( () -> (char) 0); // [1]\n" + + " }\n" + + " void bar(FC fc) { }\n" + + " void bar(FB fb) { }\n" + + "}\n" + + "interface FB {\n" + + " byte foo();\n" + + "}\n" + + "interface FC {\n" + + " char foo();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " bar( () -> (char) 0); // [1]\n" + + " ^^^\n" + + "The method bar(FC) is ambiguous for the type C2\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421926, [1.8][compiler] Compiler tolerates illegal forward reference from lambda in initializer +public void test421926() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " I run(int s1);\n" + + "}\n" + + "class X { \n" + + " public static final int f = f;\n" + + " public static final I fi = x -> fi;\n" + + " public static final I fj = x -> fk;\n" + + " public static final I fk = x -> fj;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public static final int f = f;\n" + + " ^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public static final I fi = x -> fi;\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " public static final I fj = x -> fk;\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421926, [1.8][compiler] Compiler tolerates illegal forward reference from lambda in initializer +public void test421926b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " int run(int s1, int s2); \n" + + "}\n" + + "public class X {\n" + + " static int f = ((I) (int x5, int x2) -> x1).run(10, 20);\n" + + " static int x1 = 2;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static int f = ((I) (int x5, int x2) -> x1).run(10, 20);\n" + + " ^^\n" + + "Cannot reference a field before it is defined\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421926, [1.8][compiler] Compiler tolerates illegal forward reference from lambda in initializer +public void test421926c() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "interface I { \n" + + " int run(int s1, int s2); \n" + + "}\n" + + "public class X {\n" + + " int f = ((I) (int x5, int x2) -> x1).run(10, 20);\n" + + " static int x1 = 2;\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426206, [1.8][compiler] Compiler tolerates illegal code. +public void test426206() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Comparator;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " Comparator c = true ? (Integer i, Integer j) -> { return 0; } : (Long i, Long j) -> { return 1; };\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Comparator c = true ? (Integer i, Integer j) -> { return 0; } : (Long i, Long j) -> { return 1; };\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Comparator to Comparator\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Comparator c = true ? (Integer i, Integer j) -> { return 0; } : (Long i, Long j) -> { return 1; };\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Comparator to Comparator\n" + + "----------\n"); +} +public void testBug426563() { + runNegativeTest( + new String[] { + "X.java", + "interface I> { \n" + + " void foo(U u, V v); \n" + + "}\n" + + "\n" + + "interface J {}\n" + + "\n" + + "public class X {\n" + + "\n" + + " public void bar(FI fi) {}\n" + + "\n" + + " public static void main(String args[]) {\n" + + " new X().bar((p, q) -> {}); \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " public void bar(FI fi) {}\n" + + " ^^\n" + + "FI cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " new X().bar((p, q) -> {}); \n" + + " ^^^\n" + + "The method bar(FI) from the type X refers to the missing type FI\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " new X().bar((p, q) -> {}); \n" + + " ^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=426965, [1.8] Eclipse rejects valid type conversion in lambda +public void test426965() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " interface I, V> {\n" + + " V foo(U p);\n" + + " }\n" + + " public void main() {\n" + + " I, Object> fi = p -> p.toArray(new X[] {});\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427207, - [1.8][bytecode] Runtime type problem: Instruction type does not match stack map +public void test427207() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " I i = (I) ((args == null) ? ()->{} : ()-> {});\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I i = (I) ((args == null) ? ()->{} : ()-> {});\n" + + " ^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " I i = (I) ((args == null) ? ()->{} : ()-> {});\n" + + " ^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=425278, [1.8][compiler] Suspect error: The target type of this expression is not a well formed parameterized type due to bound(s) mismatch +// NOTE: javac 8b127 incorrectly accepts this program due to https://bugs.openjdk.java.net/browse/JDK-8033810 +public void test425278() { + runNegativeTest( + false /*skipJavac */, + JavacTestOptions.JavacHasABug.JavacBug8033810, + new String[] { + "X.java", + "interface I> { \n" + + " T foo(S p);\n" + + "}\n" + + "public class X {\n" + + " public void bar() {\n" + + " I> f = (p) -> p;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " I> f = (p) -> p;\n" + + " ^^^^^^^^\n" + + "The target type of this expression is not a well formed parameterized type due to bound(s) mismatch\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427265, - [1.8][compiler] Type inference with anonymous classes +public void test427265() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List ss = Arrays.asList(\"1\", \"2\", \"3\");\n" + + " ss.stream().map(s -> new Object() {});\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427749, - [1.8][compiler]NullPointerException in ReferenceExpression.resolveType +public void test427749() { + runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(X y);\n" + + "}\n" + + "public class X {\n" + + " class Z {\n" + + " Z(X y) {\n" + + " System.out.println(\"Y.Z::new\");\n" + + " }\n" + + " public void bar() {\n" + + " I i = Y.Z:: new;\n" + + " i.foo(new Y());\n" + + " }\n" + + " }\n" + + " public void foo() {\n" + + " Z z = new Z(null);\n" + + " z.bar();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Y y = new Y();\n" + + " y.foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " I i = Y.Z:: new;\n" + + " ^\n" + + "Y cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " i.foo(new Y());\n" + + " ^\n" + + "Y cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Y cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 19)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Y cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428300, - [1.8] Map.computeIfAbsent fails with array value types +public void test428300() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.concurrent.ConcurrentHashMap;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " ConcurrentHashMap map = new ConcurrentHashMap<>();\n" + + " map.computeIfAbsent(\"doo\", e -> new String[] {});\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428300, - [1.8] Map.computeIfAbsent fails with array value types +public void test428300a() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.concurrent.ConcurrentHashMap;\n" + + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " ConcurrentHashMap map = new ConcurrentHashMap<>();\n" + + " Function f = e -> new String[] {};\n" + + " map.computeIfAbsent(\"doo\", f);\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428177, - [1.8][compiler] Insistent capture issues +public void test428177() { + runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.nio.file.Path;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.jar.JarEntry;\n" + + "import java.util.jar.JarFile;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "class InsistentCapture {\n" + + " static void processJar(Path plugin) throws IOException {\n" + + " try(JarFile jar = new JarFile(plugin.toFile())) {\n" + + " try(Stream entries = jar.stream()) {\n" + + " Function toName =\n" + + " entry -> entry.getName();\n" + + " Stream stream = entries.map(toName).distinct(); // Ok\n" + + " withWildcard(entries.map(toName).distinct()); // Ok\n" + + " withWildcard(stream); // Ok\n" + + " Stream stream2 = entries.map(toName).distinct(); // ERROR\n" + + " withoutWildcard(entries.map(toName).distinct()); // ERROR\n" + + " withoutWildcard(stream); // ERROR\n" + + " withoutWildcard(stream2); // Ok\n" + + " withoutWildcard(coerce(stream)); // Ok\n" + + " withoutWildcard(stream.map((String v1) -> { // ERROR\n" + + " String r = \"\" + v1; // Hover on v: Ok\n" + + " return r;\n" + + " }));\n" + + " withoutWildcard(stream.map((v2) -> { // Ok\n" + + " String r = \"\" + v2; // Hover on v: NOT OK\n" + + " return r;\n" + + " }));\n" + + " }\n" + + " }\n" + + " }\n" + + " private static Stream coerce(Stream stream) {\n" + + " if(\"1\" == \"\") { return stream.collect(Collectors.toList()).stream(); // ERROR\n" + + " }\n" + + " return stream.collect(Collectors.toList()); // NO ERROR\n" + + " }\n" + + " private static void withWildcard(Stream distinct) {\n" + + " distinct.forEach(s1 -> System.out.println(s1)); // hover on s: NOT OK\n" + + " }\n" + + " private static void withoutWildcard(Stream distinct) {\n" + + " distinct.forEach(s2 -> System.out.println(s2)); // hover on s: Ok\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " Stream stream2 = entries.map(toName).distinct(); // ERROR\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Stream to Stream\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " withoutWildcard(entries.map(toName).distinct()); // ERROR\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method withoutWildcard(Stream) in the type InsistentCapture is not applicable for the arguments (Stream)\n" + + "----------\n" + + "3. ERROR in X.java (at line 21)\n" + + " withoutWildcard(stream); // ERROR\n" + + " ^^^^^^^^^^^^^^^\n" + + "The method withoutWildcard(Stream) in the type InsistentCapture is not applicable for the arguments (Stream)\n" + + "----------\n" + + "4. ERROR in X.java (at line 36)\n" + + " if(\"1\" == \"\") { return stream.collect(Collectors.toList()).stream(); // ERROR\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Stream to Stream\n" + + "----------\n" + + "5. ERROR in X.java (at line 38)\n" + + " return stream.collect(Collectors.toList()); // NO ERROR\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to Stream\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428795, - [1.8]Internal compiler error: java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.ast.MessageSend.analyseCode +public void test428795() { + runNegativeTest( + new String[] { + "X.java", + "import java.net.NetworkInterface;\n" + + "import java.util.Optional;\n" + + "public class X {\n" + + " public static void main( String[] args ) {\n" + + " Optional.ofNullable( NetworkInterface.getByIndex( 2 ) ).ifPresent( ni -> {\n" + + " Optional.ofNullable( ni.getDisplayName() ).ifPresent( name ->\n" + + " System.out.println( name.get().toUpperCase() )\n" + + " );\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println( name.get().toUpperCase() )\n" + + " ^^^\n" + + "The method get() is undefined for the type String\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, - [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " Function, String> func = ArrayList::toString;\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Function, String> func = ArrayList::toString;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The type ArrayList does not define toString(List) that is applicable here\n" + + "----------\n", null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, - [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " Function, String> func = ArrayList::toString;\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " ^^^^^\n" + + "The method apply(ArrayList) in the type Function,String> is not applicable for the arguments (List)\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to ArrayList\n" + + "----------\n", null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, - [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " Function, String> func = List::toString;\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " ^^^^^\n" + + "The method apply(ArrayList) in the type Function,String> is not applicable for the arguments (List)\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to ArrayList\n" + + "----------\n", null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, - [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857c() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "class Vector extends ArrayList {}\n" + + "interface I {\n" + + " ArrayList get();\n" + + "}\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " I i = ArrayList::new;\n" + + " System.out.println(i.get());\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " class Vector extends ArrayList {}\n" + + " ^^^^^^\n" + + "The serializable class Vector does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, - [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857d() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "class Vector extends ArrayList {}\n" + + "interface I {\n" + + " List get();\n" + + "}\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " I i = ArrayList::new;\n" + + " System.out.println(i.get());\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " class Vector extends ArrayList {}\n" + + " ^^^^^^\n" + + "The serializable class Vector does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, - [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857e() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "class Vector extends ArrayList {}\n" + + "interface I {\n" + + " Vector get();\n" + + "}\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " I i = ArrayList::new;\n" + + " System.out.println(i.get());\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " class Vector extends ArrayList {}\n" + + " ^^^^^^\n" + + "The serializable class Vector does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " I i = ArrayList::new;\n" + + " ^^^^^^^^^^^^^^\n" + + "The constructed object of type ArrayList is incompatible with the descriptor\'s return type: Vector\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, - [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857f() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "class Vector extends ArrayList {}\n" + + "interface I {\n" + + " ArrayList get();\n" + + "}\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " I i = Vector::new;\n" + + " System.out.println(i.get());\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " class Vector extends ArrayList {}\n" + + " ^^^^^^\n" + + "The serializable class Vector does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428857, - [1.8] Method reference to instance method of generic class incorrectly gives raw type warning +public void test428857g() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "import java.util.function.Function;\n" + + "public class X {\n" + + " public static void main (String[] args) {\n" + + " Function, String> func = ArrayList::toString;\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " ^^^^^\n" + + "The method apply(capture#1-of ? extends ArrayList) in the type Function,String> is not applicable for the arguments (List)\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " System.out.println(func.apply(Arrays.asList(\"a\", \"b\")));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from List to capture#1-of ? extends ArrayList\n" + + "----------\n", null, false, customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429833, - [1.8][compiler] Missing types cause NPE in lambda analysis. +public void test429833() { + runNegativeTest( + new String[] { + "X.java", + "interface I1 { int foo(Strin i); }\n" + + "class Y {\n" + + " I1 i = (a) -> { \n" + + " a.charAt(0);\n" + + " };\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface I1 { int foo(Strin i); }\n" + + " ^^^^^\n" + + "Strin cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I1 i = (a) -> { \n" + + " ^^^^^^\n" + + "This lambda expression refers to the missing type Strin\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429934, - [1.8][search] for references to type of lambda with 'this' parameter throws AIIOBE/NPE +public void test429934() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Function f1= (String s, Function this) -> s;\n" + + " Function f2= (Function this, String s) -> s;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Function f1= (String s, Function this) -> s;\n" + + " ^^^^^^^^\n" + + "Function cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Function f1= (String s, Function this) -> s;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Function f1= (String s, Function this) -> s;\n" + + " ^^^^^^^^\n" + + "Function cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " Function f1= (String s, Function this) -> s;\n" + + " ^^^^\n" + + "Lambda expressions cannot declare a this parameter\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " Function f2= (Function this, String s) -> s;\n" + + " ^^^^^^^^\n" + + "Function cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " Function f2= (Function this, String s) -> s;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n" + + "7. ERROR in X.java (at line 4)\n" + + " Function f2= (Function this, String s) -> s;\n" + + " ^^^^^^^^\n" + + "Function cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 4)\n" + + " Function f2= (Function this, String s) -> s;\n" + + " ^^^^\n" + + "Lambda expressions cannot declare a this parameter\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429969, [1.8][compiler] Possible RuntimeException in Lambda tangles ECJ +public void test429969() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.Optional;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final String s = Arrays.asList(\"done\").stream().reduce(null, (s1,s2) -> {\n" + + " // THE FOLLOWING LINE CAUSES THE PROBLEM\n" + + " require(s1 != null || s2 != null, \"both strings are null\");\n" + + " return (s1 != null) ? s1 : s2;\n" + + " }, (s1,s2) -> (s1 != null) ? s1 : s2);\n" + + " \n" + + " System.out.println(s);\n" + + " }\n" + + " static void require(boolean condition, String msg) throws java.io.IOException {\n" + + " if (!condition) {\n" + + " throw new java.io.IOException(msg);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " import java.util.Optional;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The import java.util.Optional is never used\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " require(s1 != null || s2 != null, \"both strings are null\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429969, [1.8][compiler] Possible RuntimeException in Lambda tangles ECJ +public void test429969a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo() throws RuntimeException;\n" + + "}\n" + + "public class X {\n" + + " static void goo() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " I i = X::goo;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " I i = X::goo;\n" + + " ^^^^^^\n" + + "Unhandled exception type Exception\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=430310, [1.8][compiler] Functional interface incorrectly rejected as not being. +public void test430310() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Func1 {\n" + + " R apply(T1 v1);\n" + + " void other();\n" + + "}\n" + + "@FunctionalInterface // spurious error: F1 is not a functional interface\n" + + "interface F1 extends Func1 {\n" + + " default void other() {}\n" + + "}\n" + + "@FunctionalInterface\n" + + "interface F2 extends Func1 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " interface F2 extends Func1 {\n" + + " ^^\n" + + "Invalid \'@FunctionalInterface\' annotation; F2 is not a functional interface\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424154, [1.8][compiler] PolyTypeBinding must not render the full lambda body in error messages +//Example copied from bug report. +public void test424154a() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;" + + "public class X {\n" + + " void foo(List list) {\n" + + " list.removeIf((int x) -> \"\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " list.removeIf((int x) -> \"\");\n" + + " ^^^^^^^^\n" + + "The method removeIf(Predicate) in the type Collection is not applicable for the arguments ((int x) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " list.removeIf((int x) -> \"\");\n" + + " ^^^\n" + + "Lambda expression\'s parameter x is expected to be of type Process\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " list.removeIf((int x) -> \"\");\n" + + " ^^\n" + + "Type mismatch: cannot convert from String to boolean\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424154, [1.8][compiler] PolyTypeBinding must not render the full lambda body in error messages +//Variations where return types or arguments mismatch or both. +public void test424154b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface I {int foo(int x);}\n" + + " void foo2(I i) {}\n" + + " void foo() {}\n" + + " void bar() {\n" + + " foo(0, (int x, int y) -> {return 2;}, 0);\n" + + " foo2((int x) -> \"\");\n"+ + " foo2((float x) -> 0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " foo(0, (int x, int y) -> {return 2;}, 0);\n" + + " ^^^\n" + + "The method foo() in the type X is not applicable for the arguments (int, (int x, int y) -> {}, int)\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " foo2((int x) -> \"\");\n" + + " ^^^^\n" + + "The method foo2(X.I) in the type X is not applicable for the arguments ((int x) -> {})\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " foo2((int x) -> \"\");\n" + + " ^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " foo2((float x) -> 0);\n" + + " ^^^^\n" + + "The method foo2(X.I) in the type X is not applicable for the arguments ((float x) -> {})\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " foo2((float x) -> 0);\n" + + " ^^^^^\n" + + "Lambda expression's parameter x is expected to be of type int\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=431514 [1.8] Incorrect compilation error in lambda expression +public void test431514() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.function.Supplier;\n" + + "public class X {\n" + + " public void foo() {\n" + + " class Z {\n" + + " public Supplier get() {\n" + + " return () -> {\n" + + " class Z { }\n" + + " return new Z();\n" + + " };\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " class Z { }\n" + + " ^\n" + + "The nested type Z cannot hide an enclosing type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=439707 [1.8][compiler] Lambda can be passed illegally to invisible method argument +public void test439707() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " T2.run(() -> {});\n" + + " }\n" + + "}\n", + "T2.java", + "public class T2 {\n" + + " public static void run(InvisibleInterface i) {\n" + + " }\n" + + " private interface InvisibleInterface {\n" + + " void run();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " T2.run(() -> {});\n" + + " ^^^^^\n" + + "The type T2.InvisibleInterface from the descriptor computed for the target context is not visible here. \n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=442983, [1.8] NPE in Scope.findDefaultAbstractMethod +public void test442983() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "class CL {\n" + + " String method1(CL ie) {\n" + + " return \"b\";\n" + + " }\n" + + " public void bar() { \n" + + " Function, String> v5 = CL::method1;\n" + + " v5 = t -> t.method1(); \n" + + " } \n" + + "}\n" + }, + // Note: new message aligns better with javac 8u20. + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Function, String> v5 = CL::method1;\n" + + " ^^^^^^^^^^^\n" + + "Cannot make a static reference to the non-static method method1(CL) from the type CL\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " v5 = t -> t.method1(); \n" + + " ^^^^^^^\n" + + "The method method1(CL) in the type CL is not applicable for the arguments ()\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=438945, [1.8] NullPointerException InferenceContext18.checkExpression in java 8 with generics, primitives, and overloading +public void test438945() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.JavacHasWarningsEclipseNotConfigured, + new String[] { + "X.java", + "import java.util.function.ToIntFunction;\n" + + "import java.util.function.ToLongFunction;\n" + + "public class X {\n" + + " public static void error() {\n" + + " test(X::works);\n" + + " test(X::broken);\n" + + " }\n" + + " private static void test(ToLongFunction func) {}\n" + + " private static void test(ToIntFunction func) {}\n" + + " private static int broken(Object o) { return 0; }\n" + + " private static long works(Object o) { return 0; } \n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=440643, Eclipse compiler doesn't like method references with overloaded varargs method +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=439515, [1.8] ECJ reports error at method reference to overloaded instance method +public void test440643() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError, + new String[] { + "X.java", + "@FunctionalInterface\n" + + "interface Accumalator {\n" + + " void acum(Container container, E data);\n" + + "}\n" + + "interface Container {\n" + + " public void add(E data);\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public void add(E...data);\n" + + "}\n" + + "class Binding {\n" + + " private final Accumalator function;\n" + + " \n" + + " public Binding() {\n" + + " function = Container::add;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " private final Accumalator function;\n" + + " ^^^^^^^^\n" + + "The value of the field Binding.function is not used\n" + + "----------\n", + null, + false, + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=440643, Eclipse compiler doesn't like method references with overloaded varargs method +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=439515, [1.8] ECJ reports error at method reference to overloaded instance method +public void test440643a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Fun {\n" + + " R apply(T arg);\n" + + "}\n" + + "public class X {\n" + + " static int size() {\n" + + " return -1;\n" + + " }\n" + + " static int size(Object arg) {\n" + + " return 0;\n" + + " }\n" + + " int size(X arg) {\n" + + " return 1;\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " Fun f1 = X::size;\n" + + " System.out.println(f1.apply(new X()));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " Fun f1 = X::size;\n" + + " ^^^^^^^\n" + + "Cannot make a static reference to the non-static method size(X) from the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=440643, Eclipse compiler doesn't like method references with overloaded varargs method +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=439515, [1.8] ECJ reports error at method reference to overloaded instance method +public void test440643b() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Fun {\n" + + " R apply(T arg);\n" + + "}\n" + + "public class X {\n" + + " int size() {\n" + + " return -1;\n" + + " }\n" + + " static int size(Object arg) {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " Fun f1 = X::size;\n" + + " System.out.println(f1.apply(new X()));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Fun f1 = X::size;\n" + + " ^^^^^^^\n" + + "Ambiguous method reference: both size() and size(Object) from the type X are eligible\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=435397, [1.8][compiler] Ambiguous method while using Lambdas +public void test435397() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.function.Function;\n" + + "interface B {}\n" + + "interface Config {}\n" + + "interface M {\n" + + " void configure(B binder);\n" + + "}\n" + + "class M2 implements M {\n" + + " public M2(final Config conf) {\n" + + " }\n" + + " public M2() {\n" + + " }\n" + + "@Override\n" + + " public void configure(final B binder) {\n" + + " }\n" + + "}\n" + + "// BootModule\n" + + "class BaseModule implements M {\n" + + " // eager module creation\n" + + " public BaseModule module(final M m) {\n" + + " return this;\n" + + " }\n" + + " // lazy module creation\n" + + " public BaseModule module(final Function cons) {\n" + + " return this;\n" + + " }\n" + + " @Override\n" + + " public void configure(final B binder) {\n" + + " }\n" + + "}\n" + + "// Client with error\n" + + "class M1 extends BaseModule {\n" + + " public static void main(final String[] args) {\n" + + " new M1().module((c) -> new M2());\n" + + " // The method module(M) is ambiguous for the type M1\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 33)\n" + + " new M1().module((c) -> new M2());\n" + + " ^^^^^^\n" + + "The method module(M) is ambiguous for the type M1\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433458, [1.8][compiler] Eclipse accepts lambda expression with potentially uninitialized arguments +public void test433458() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Comparator;\n" + + "public class X {\n" + + " final Comparator mComparator1;\n" + + //" Comparator mComparator2 = mComparator1;\n" + + " Comparator mComparator2 = (pObj1, pObj2) -> mComparator1.compare(pObj1, pObj2);\n" + + " X() {mComparator1 = Comparator.naturalOrder();}\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " final Comparator mComparator1;\n" + + " ^^^^^^^^^^\n" + + "Comparator is a raw type. References to generic type Comparator should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " Comparator mComparator2 = (pObj1, pObj2) -> mComparator1.compare(pObj1, pObj2);\n" + + " ^^^^^^^^^^\n" + + "Comparator is a raw type. References to generic type Comparator should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 4)\n" + + " Comparator mComparator2 = (pObj1, pObj2) -> mComparator1.compare(pObj1, pObj2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: The method compare(Object, Object) belongs to the raw type Comparator. References to generic type Comparator should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Comparator mComparator2 = (pObj1, pObj2) -> mComparator1.compare(pObj1, pObj2);\n" + + " ^^^^^^^^^^^^\n" + + "The blank final field mComparator1 may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433458, [1.8][compiler] Eclipse accepts lambda expression with potentially uninitialized arguments +public void test433458a() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "class X {\n" + + " final int x;\n" + + " X() {\n" + + " I i = () -> {\n" + + " x = 20;\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " X() {\n" + + " ^^^\n" + + "The blank final field x may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " x = 20;\n" + + " ^\n" + + "The final field X.x cannot be assigned\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433588, [1.8][compiler] ECJ compiles an ambiguous call in the presence of an unrelated unused method. +public void test433588() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in X.java (at line 15)\n" + + " public final @SafeVarargs void forEachOrdered(Consumer action, Consumer... actions) throws E {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method forEachOrdered(Consumer, Consumer...) from the type X.AbstractStream is never used locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 29)\n" + + " lines1.forEachOrdered(s -> Files.isHidden(Paths.get(s)));\n" + + " ^^^^^^^^^^^^^^\n" + + "The method forEachOrdered(X.IOConsumer) is ambiguous for the type X.IOStream\n" + + "----------\n" + + "3. ERROR in X.java (at line 30)\n" + + " lines1.forEachOrdered(s -> System.out.println(s));\n" + + " ^^^^^^^^^^^^^^\n" + + "The method forEachOrdered(X.IOConsumer) is ambiguous for the type X.IOStream\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 15)\n" + + " public final @SafeVarargs void forEachOrdered(Consumer action, Consumer... actions) throws E {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method forEachOrdered(Consumer, Consumer...) from the type X.AbstractStream is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 17)\n" + + " private static class UnStream extends AbstractStream, UnStream, Consumer> {}\n" + + " ^^^^^^^^\n" + + "Access to enclosing constructor X.AbstractStream() is emulated by a synthetic accessor method\n" + + "----------\n" + + "3. WARNING in X.java (at line 18)\n" + + " private static class IOStream extends AbstractStream, IOStream, IOConsumer> {}\n" + + " ^^^^^^^^\n" + + "Access to enclosing constructor X.AbstractStream() is emulated by a synthetic accessor method\n" + + "----------\n" + + "4. ERROR in X.java (at line 29)\n" + + " lines1.forEachOrdered(s -> Files.isHidden(Paths.get(s)));\n" + + " ^^^^^^^^^^^^^^\n" + + "The method forEachOrdered(X.IOConsumer) is ambiguous for the type X.IOStream\n" + + "----------\n" + + "5. ERROR in X.java (at line 30)\n" + + " lines1.forEachOrdered(s -> System.out.println(s));\n" + + " ^^^^^^^^^^^^^^\n" + + "The method forEachOrdered(X.IOConsumer) is ambiguous for the type X.IOStream\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.nio.file.Files;\n" + + "import java.nio.file.Paths;\n" + + "import java.util.function.Consumer;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + " private interface StreamyBase {\n" + + " @SuppressWarnings(\"unused\")\n" + + " default void forEachOrdered(Consumer action) throws E {}\n" + + " }\n" + + " abstract private static class AbstractStream, CONSUMER> implements StreamyBase {\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void forEachOrdered(CONSUMER action) throws E {}\n" + + " // remove this method with a warning about it being unused:\n" + + " public final @SafeVarargs void forEachOrdered(Consumer action, Consumer... actions) throws E {}\n" + + " }\n" + + " private static class UnStream extends AbstractStream, UnStream, Consumer> {}\n" + + " private static class IOStream extends AbstractStream, IOStream, IOConsumer> {}\n" + + " @FunctionalInterface\n" + + " private interface ExConsumer {\n" + + " void accept(T t1) throws E;\n" + + " }\n" + + " @FunctionalInterface\n" + + " private interface IOConsumer extends ExConsumer {}\n" + + " public static void tests1(IOStream lines1, UnStream lines2) throws IOException {\n" + + " IOConsumer action = s -> Files.isHidden(Paths.get(s));\n" + + " Consumer action2 = s -> System.out.println(s);\n" + + " // After removal these two become ambiguous:\n" + + " lines1.forEachOrdered(s -> Files.isHidden(Paths.get(s)));\n" + + " lines1.forEachOrdered(s -> System.out.println(s));\n" + + " lines1.forEachOrdered(action);\n" + + " lines1.forEachOrdered(action2);\n" + + " lines2.forEachOrdered(action2);\n" + + " }\n" + + "}\n" + }, + errMessage); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433588, [1.8][compiler] ECJ compiles an ambiguous call in the presence of an unrelated unused method. +public void test433588a() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. ERROR in X.java (at line 29)\n" + + " lines1.forEachOrdered(s -> Files.isHidden(Paths.get(s)));\n" + + " ^^^^^^^^^^^^^^\n" + + "The method forEachOrdered(X.IOConsumer) is ambiguous for the type X.IOStream\n" + + "----------\n" + + "2. ERROR in X.java (at line 30)\n" + + " lines1.forEachOrdered(s -> System.out.println(s));\n" + + " ^^^^^^^^^^^^^^\n" + + "The method forEachOrdered(X.IOConsumer) is ambiguous for the type X.IOStream\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 17)\n" + + " private static class UnStream extends AbstractStream, UnStream, Consumer> {}\n" + + " ^^^^^^^^\n" + + "Access to enclosing constructor X.AbstractStream() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. WARNING in X.java (at line 18)\n" + + " private static class IOStream extends AbstractStream, IOStream, IOConsumer> {}\n" + + " ^^^^^^^^\n" + + "Access to enclosing constructor X.AbstractStream() is emulated by a synthetic accessor method\n" + + "----------\n" + + "3. ERROR in X.java (at line 29)\n" + + " lines1.forEachOrdered(s -> Files.isHidden(Paths.get(s)));\n" + + " ^^^^^^^^^^^^^^\n" + + "The method forEachOrdered(X.IOConsumer) is ambiguous for the type X.IOStream\n" + + "----------\n" + + "4. ERROR in X.java (at line 30)\n" + + " lines1.forEachOrdered(s -> System.out.println(s));\n" + + " ^^^^^^^^^^^^^^\n" + + "The method forEachOrdered(X.IOConsumer) is ambiguous for the type X.IOStream\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.nio.file.Files;\n" + + "import java.nio.file.Paths;\n" + + "import java.util.function.Consumer;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + " private interface StreamyBase {\n" + + " @SuppressWarnings(\"unused\")\n" + + " default void forEachOrdered(Consumer action) throws E {}\n" + + " }\n" + + " abstract private static class AbstractStream, CONSUMER> implements StreamyBase {\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void forEachOrdered(CONSUMER action) throws E {}\n" + + " // remove this method with a warning about it being unused:\n" + + " // public final @SafeVarargs void forEachOrdered(Consumer action, Consumer... actions) throws E {}\n" + + " }\n" + + " private static class UnStream extends AbstractStream, UnStream, Consumer> {}\n" + + " private static class IOStream extends AbstractStream, IOStream, IOConsumer> {}\n" + + " @FunctionalInterface\n" + + " private interface ExConsumer {\n" + + " void accept(T t1) throws E;\n" + + " }\n" + + " @FunctionalInterface\n" + + " private interface IOConsumer extends ExConsumer {}\n" + + " public static void tests1(IOStream lines1, UnStream lines2) throws IOException {\n" + + " IOConsumer action = s -> Files.isHidden(Paths.get(s));\n" + + " Consumer action2 = s -> System.out.println(s);\n" + + " // After removal these two become ambiguous:\n" + + " lines1.forEachOrdered(s -> Files.isHidden(Paths.get(s)));\n" + + " lines1.forEachOrdered(s -> System.out.println(s));\n" + + " lines1.forEachOrdered(action);\n" + + " lines1.forEachOrdered(action2);\n" + + " lines2.forEachOrdered(action2);\n" + + " }\n" + + "}\n" + }, + errMessage); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=433735, [1.8] Discrepancy with javac when dealing with local classes in lambda expressions +public void test433735() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.function.Supplier;\n" + + "class E {\n" + + " E(Supplier factory) { }\n" + + "}\n" + + "public class X extends E {\n" + + " X() {\n" + + " super( () -> {\n" + + " class Z extends E {\n" + + " Z() {\n" + + " super(new Supplier() {\n" + + " @Override\n" + + " public Object get() {\n" + + " return new Object();\n" + + " }\n" + + " });\n" + + " }\n" + + " } \n" + + " return new Z();\n" + + " });\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " super( () -> {\n" + + " ^^^^^\n" + + "Cannot refer to \'this\' nor \'super\' while explicitly invoking a constructor\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432531 [1.8] VerifyError with anonymous subclass inside of lambda expression in the superclass constructor call +public void test432531a() { + this.runNegativeTest( + new String[] { + "Y.java", + "import java.util.function.Supplier;\n" + + "class E {\n" + + " E(Supplier factory) { }\n" + + "}\n" + + "public class Y extends E {\n" + + " Y() {\n" + + " super( () -> {\n" + + " class Z extends E {\n" + + " Z() {\n" + + " super(() -> new Object());\n" + + " }\n" + + " }\n" + + " return new Z();\n" + + " });\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Y();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Y.java (at line 7)\n" + + " super( () -> {\n" + + " ^^^^^\n" + + "Cannot refer to \'this\' nor \'super\' while explicitly invoking a constructor\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432605, [1.8] Incorrect error "The type ArrayList does not define add(ArrayList, Object) that is applicable here" +public void _test432605() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.HashMap;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.stream.Collector;\n" + + "import java.util.stream.Collectors;\n" + + "import java.util.stream.Stream;\n" + + "public class X {\n" + + "static M terminalAsMapToList(\n" + + " Function classifier,\n" + + " Function, M> intoMap,\n" + + " Function, L> intoList,\n" + + " Supplier> supplier,\n" + + " Class classOfE) throws E {\n" + + " return terminalAsCollected(\n" + + " classOfE,\n" + + " Collectors.collectingAndThen(\n" + + " Collectors.groupingBy(\n" + + " classifier,\n" + + " HashMap::new,\n" + + " Collectors.collectingAndThen(\n" + + " // The type ArrayList does not define add(ArrayList, Object) that is applicable here\n" + + " // from ArrayList::add:\n" + + " Collector.of(ArrayList::new, ArrayList::add, (ArrayList left, ArrayList right) -> { \n" + + " left.addAll(right);\n" + + " return left;\n" + + " }),\n" + + " intoList)),\n" + + " intoMap),\n" + + " supplier);\n" + + " }\n" + + " static M terminalAsCollected(\n" + + " Class class1,\n" + + " Collector collector,\n" + + " Supplier> supplier) throws E {\n" + + " try(Stream s = supplier.get()) {\n" + + " return s.collect(collector);\n" + + " } catch(RuntimeException e) {\n" + + " throw unwrapCause(class1, e);\n" + + " }\n" + + " }\n" + + " static E unwrapCause(Class classOfE, RuntimeException e) throws E {\n" + + " Throwable cause = e.getCause();\n" + + " if(classOfE.isInstance(cause) == false) {\n" + + " throw e;\n" + + " }\n" + + " throw classOfE.cast(cause);\n" + + "}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Y.java (at line 7)\n" + + " super( () -> {\n" + + " ^^^^^\n" + + "No enclosing instance of type Y is available due to some intermediate constructor invocation\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=444665, Internal compiler error: java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.problem.ProblemReporter.invalidMethod +public void test444665() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(java.util.Map map) {\n" + + " java.util.function.Consumer c = array -> map.compute(array.get(0), (k, v) -> null);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " java.util.function.Consumer c = array -> map.compute(array.get(0), (k, v) -> null);\n" + + " ^^^^^^^^^^^^\n" + + "Cannot invoke get(int) on the array type int[]\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=442446, [1.8][compiler] compiler unable to infer lambda's generic argument types +public void test442446() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.Map;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Collectors;\n" + + "public class X {\n" + + " X(Collection pCollection) {\n" + + " this(\n" + + " pCollection.stream().collect(\n" + + " Collectors.toMap(\n" + + " Function.identity(), pElement -> 1, (pInt1, pInt2) -> pInt1 + pInt2\n" + + " )\n" + + " )\n" + + " );\n" + + " }\n" + + " X(Map pMap) {}\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=432759, [1.8][compiler] Some differences between Javac and ECJ regarding wildcards and static methods +public void test432759() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.JavacDoesNotCompileCorrectSource, + new String[] { + "X.java", + "import java.util.function.BinaryOperator;\n" + + "import java.util.function.Consumer;\n" + + "\n" + + "/*Q*/\n" + + "@FunctionalInterface interface Subsumer { void accept(T t);\n" + + " default Subsumer andThe1( Subsumer afterT) { return (T t) -> { accept(t); afterT.accept(t); }; }\n" + + " default Subsumer andThe2(Subsumer this, Subsumer afterT) { return (T t) -> { this.accept(t); afterT.accept(t); }; }\n" + + " static Subsumer andThe3(Subsumer tihs, Subsumer afterU) { return (U u) -> { tihs.accept(u); afterU.accept(u); }; }\n" + + " static Subsumer andThe4(Subsumer tihs, Subsumer afterS) { return (S s) -> { tihs.accept(s); afterS.accept(s); }; }\n" + + "}\n" + + "public class X {\n" + + " static void method() {\n" + + " BinaryOperator> attempt_X_0 = Consumer::andThen;\n" + + " BinaryOperator> attempt_X_1 = Subsumer::andThe1;\n" + + " BinaryOperator> attempt_X_2 = Subsumer::andThe2;\n" + + " BinaryOperator> attempt_X_3 = Subsumer::andThe3;\n" + + " BinaryOperator> attempt_X_4 = Subsumer::andThe4;\n" + + " BinaryOperator> attempt_n_0 = Consumer::andThen;\n" + + " BinaryOperator> attempt_n_1 = Subsumer::andThe1;\n" + + " BinaryOperator> attempt_n_2 = Subsumer::andThe2;\n" + + " BinaryOperator> attempt_n_3 = Subsumer::andThe3;\n" + + " BinaryOperator> attempt_n_4 = Subsumer::andThe4;\n" + + " // Summary:\n" + + " // ECJ error #1, javac no error\n" + + " // ECJ error #2, javac no error\n" + + " // ECJ error #3, javac no error\n" + + " // ECJ error #4, javac error #1\n" + + " // ECJ error #5, javac error #2\n" + + " // ECJ no error, javac no error\n" + + " // ECJ no error, javac no error\n" + + " // ECJ no error, javac no error\n" + + " // ECJ no error, javac no error\n" + + " // ECJ no error, javac no error\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=437444#c36, NPE in broken code +public void test437444() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.stream.Collectors;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List roster = new ArrayList<>();\n" + + " Map map = \n" + + " roster\n" + + " .stream()\n" + + " .collect(\n" + + " Collectors.toMap(\n" + + " Person::getLast,\n" + + " Function.identity() \n" + + " ));\n" + + " }\n" + + "}\n" + + "class Person {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Map map = \n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " Function.identity() \n" + + " ^^^^^^^^\n" + + "Function cannot be resolved\n" + + "----------\n"); +} +// test ground target type with wildcards left in non parameter positions. +public void testGroundTargetTypeWithWithWildcards() { + this.runNegativeTest( + new String[] { + "X.java", + "class A {}\n" + + "class B {}\n" + + "class C {}\n" + + "class Y extends C {}\n" + + "interface I {\n" + + " T m(R r, S s);\n" + + "}\n" + + "public class X extends A {\n" + + " Object m(I i) {\n" + + " return m((X x1, X x2) -> { return new Y(); });\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " return m((X x1, X x2) -> { return new Y(); });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from I to I\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=474522, [1.8][compiler] ecj doesn't handle captured final fields correctly in lambdas +public void test474522() { + this.runNegativeTest( + new String[] { + "Bug.java", + "import java.awt.event.ActionEvent;\n" + + "import java.awt.event.ActionListener;\n" + + "public class Bug {\n" + + " final String s;\n" + + " public Bug() {\n" + + " this.s = \"\";\n" + + " }\n" + + " private final ActionListener listener1 = new ActionListener() {\n" + + " @Override public void actionPerformed(ActionEvent e) {\n" + + " System.out.println(s);\n" + + " }\n" + + " };\n" + + " private final ActionListener listener2 = e -> System.out.println(s);\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Bug.java (at line 8)\n" + + " private final ActionListener listener1 = new ActionListener() {\n" + + " ^^^^^^^^^\n" + + "The value of the field Bug.listener1 is not used\n" + + "----------\n" + + "2. WARNING in Bug.java (at line 13)\n" + + " private final ActionListener listener2 = e -> System.out.println(s);\n" + + " ^^^^^^^^^\n" + + "The value of the field Bug.listener2 is not used\n" + + "----------\n" + + "3. ERROR in Bug.java (at line 13)\n" + + " private final ActionListener listener2 = e -> System.out.println(s);\n" + + " ^\n" + + "The blank final field s may not have been initialized\n" + + "----------\n"); +} +public void testBug487390() { + runNegativeTest( + new String[] { + "X.java", + "interface ConsumeN {\n" + + " void consume(String.. strings); // syntax error here\n" + + "}\n" + + "public class X {\n" + + "\n" + + " void consu(ConsumeN c) { }\n" + + " void test() {\n" + + " consu((String... s) -> System.out.print(s.length));\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void consume(String.. strings); // syntax error here\n" + + " ^\n" + + "Syntax error on token \".\", Identifier expected\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " consu((String... s) -> System.out.print(s.length));\n" + + " ^^^^^\n" + + "The method consu(ConsumeN) in the type X is not applicable for the arguments ((String... s) -> {})\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " consu((String... s) -> System.out.print(s.length));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method consume()\n" + + "----------\n"); +} +public void testBug487390b() { + runNegativeTest( + new String[] { + "X.java", + "interface ConsumeN {\n" + + " void consume();\n" + + "}\n" + + "public class X {\n" + + "\n" + + " void consu(ConsumeN c) { }\n" + + " void test() {\n" + + " consu((String... s) -> System.out.print(s.length));\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " consu((String... s) -> System.out.print(s.length));\n" + + " ^^^^^\n" + + "The method consu(ConsumeN) in the type X is not applicable for the arguments ((String... s) -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " consu((String... s) -> System.out.print(s.length));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Lambda expression\'s signature does not match the signature of the functional interface method consume()\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=458332, [1.8][compiler] only 409 method references/lambda expressions per class possible +public void testBug458332() { + runConformTest( + false, + null, + new String[] { + "Test.java", + "import java.io.Serializable;\n" + + "import java.util.function.Consumer;\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Data.part1().length);\n" + + " System.out.println(Data.part2().length);\n" + + " }\n" + + " @FunctionalInterface\n" + + " private static interface MethodRef extends Consumer, Serializable {}\n" + + " private static class Data {\n" + + " static MethodRef[] part1() {\n" + + " return new MethodRef[] {\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " };\n" + + " }\n" + + " static MethodRef[] part2() {\n" + + " return new MethodRef[] {\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main, Test::main,\n" + + " };\n" + + " }\n" + + " }\n" + + "}\n" + }, + "450\n" + + "250"); +} +public static Class testClass() { + return NegativeLambdaExpressionsTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java new file mode 100644 index 0000000000..dee08ac969 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeTypeAnnotationTest.java @@ -0,0 +1,4419 @@ +/******************************************************************************* + * Copyright (c) 2011, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.EclipseJustification; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class NegativeTypeAnnotationTest extends AbstractRegressionTest { + + static { +// TESTS_NUMBERS = new int [] { 35 }; +// TESTS_NAMES = new String [] { "test0390882b" }; + } + public static Class testClass() { + return NegativeTypeAnnotationTest.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + public NegativeTypeAnnotationTest(String testName){ + super(testName); + } + public void test001() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends @Marker2 Object {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends @Marker2 Object {}\n" + + " ^^^^^^^\n" + + "Marker2 cannot be resolved to a type\n" + + "----------\n"); + } + public void test002() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X implements @Marker2 Serializable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X implements @Marker2 Serializable {\n" + + " ^^^^^^^\n" + + "Marker2 cannot be resolved to a type\n" + + "----------\n"); + } + public void test003() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends @Marker Object {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends @Marker Object {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + public void test004() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<@Marker T> {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X<@Marker T> {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + public void test005() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<@Marker T> {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X<@Marker T> {}\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + public void test006() throws Exception { + this.runNegativeTest( + new String[] { + "Y.java", + "class Y {}\n", + "X.java", + "public class X extends @A(id=\"Hello, World!\") @B @C('(') Y {\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends @A(id=\"Hello, World!\") @B @C(\'(\') Y {\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends @A(id=\"Hello, World!\") @B @C(\'(\') Y {\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X extends @A(id=\"Hello, World!\") @B @C(\'(\') Y {\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n"); + } + public void test007() throws Exception { + this.runNegativeTest( + new String[] { + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X implements @A(id=\"Hello, World!\") I, @B @C('(') J {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements @A(id=\"Hello, World!\") I, @B @C(\'(\') J {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X implements @A(id=\"Hello, World!\") I, @B @C(\'(\') J {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X implements @A(id=\"Hello, World!\") I, @B @C(\'(\') J {}\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n"); + } + public void test010() throws Exception { + this.runNegativeTest( + new String[] { + "Y.java", + "class Y {}\n", + "X.java", + "public class X extends @A(\"Hello, World!\") Y<@B @C('(') String> {\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends @A(\"Hello, World!\") Y<@B @C(\'(\') String> {\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X extends @A(\"Hello, World!\") Y<@B @C(\'(\') String> {\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X extends @A(\"Hello, World!\") Y<@B @C(\'(\') String> {\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n"); + } + public void test011() throws Exception { + this.runNegativeTest( + new String[] { + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X implements I<@A(\"Hello, World!\") String>, @B J<@C('(') Integer> {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements I<@A(\"Hello, World!\") String>, @B J<@C(\'(\') Integer> {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X implements I<@A(\"Hello, World!\") String>, @B J<@C(\'(\') Integer> {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X implements I<@A(\"Hello, World!\") String>, @B J<@C(\'(\') Integer> {}\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n"); + } + // throws + public void test012() throws Exception { + this.runNegativeTest( + new String[] { + "E.java", + "class E extends RuntimeException {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n", + "E1.java", + "class E1 extends RuntimeException {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n", + "E2.java", + "class E2 extends RuntimeException {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n", + "X.java", + "public class X {\n" + + " void foo() throws @A(\"Hello, World!\") E, E1, @B @C('(') E2 {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo() throws @A(\"Hello, World!\") E, E1, @B @C(\'(\') E2 {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " void foo() throws @A(\"Hello, World!\") E, E1, @B @C(\'(\') E2 {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " void foo() throws @A(\"Hello, World!\") E, E1, @B @C(\'(\') E2 {}\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n"); + } + // method receiver + public void test013() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(@B(3) X this) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(@B(3) X this) {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // method return type + public void test014() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @B(3) int foo() {\n" + + " return 1;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @B(3) int foo() {\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // field type + public void test015() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @B(3) int field;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @B(3) int field;\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // method parameter + public void test016() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int foo(@B(3) String s) {\n" + + " return s.length();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int foo(@B(3) String s) {\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // method parameter generic or array + public void test017() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int foo(String @B(3) [] s) {\n" + + " return s.length;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int foo(String @B(3) [] s) {\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // field type generic or array + public void test018() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int @B(3) [] field;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int @B(3) [] field;\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // class type parameter + public void test019() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X<@A @B(3) T> {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X<@A @B(3) T> {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X<@A @B(3) T> {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // method type parameter + public void test020() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " <@A @B(3) T> void foo(T t) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " <@A @B(3) T> void foo(T t) {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " <@A @B(3) T> void foo(T t) {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // class type parameter bound + public void test021() throws Exception { + this.runNegativeTest( + new String[] { + "Z.java", + "public class Z {}", + "X.java", + "public class X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // class type parameter bound generic or array + public void test022() throws Exception { + this.runNegativeTest( + new String[] { + "Y.java", + "public class Y {}", + "X.java", + "public class X & @B(3) Cloneable> {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X & @B(3) Cloneable> {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public class X & @B(3) Cloneable> {}\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public class X & @B(3) Cloneable> {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 1)\n" + + " public class X & @B(3) Cloneable> {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // method type parameter bound + public void test023() throws Exception { + this.runNegativeTest( + new String[] { + "Z.java", + "public class Z {}", + "X.java", + "public class X {\n" + + " void foo(T t) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(T t) {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " void foo(T t) {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // class type parameter bound generic or array + public void test024() throws Exception { + this.runNegativeTest( + new String[] { + "Z.java", + "public class Z {}", + "Y.java", + "public class Y {}", + "X.java", + "public class X {\n" + + " & @B(3) Cloneable> void foo(T t) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " & @B(3) Cloneable> void foo(T t) {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " & @B(3) Cloneable> void foo(T t) {}\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " & @B(3) Cloneable> void foo(T t) {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 2)\n" + + " & @B(3) Cloneable> void foo(T t) {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // local variable + generic or array + public void test025() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(String s) {\n" + + " @C int i;\n" + + " @A String [] @B(3)[] tab = new String[][] {};\n" + + " if (tab != null) {\n" + + " i = 0;\n" + + " System.out.println(i + tab.length);\n" + + " } else {\n" + + " System.out.println(tab.length);\n" + + " }\n" + + " i = 4;\n" + + " System.out.println(-i + tab.length);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @C int i;\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " @A String [] @B(3)[] tab = new String[][] {};\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " @A String [] @B(3)[] tab = new String[][] {};\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // type argument constructor call + public void test026() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(T t) {\n" + + " }\n" + + " public Object foo() {\n" + + " X x = new <@A @B(1) String>X(null);\n" + + " return x;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X x = new <@A @B(1) String>X(null);\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X x = new <@A @B(1) String>X(null);\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // type argument constructor call generic or array + public void test027() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(T t) {\n" + + " }\n" + + " public Object foo() {\n" + + " X x = new <@A @B(1) String>X(null);\n" + + " return x;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X x = new <@A @B(1) String>X(null);\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " X x = new <@A @B(1) String>X(null);\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n"); + } + // type argument method call and generic or array + public void test028() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " static T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.<@A @B(1) String[], @C('-') X>foo(new String[]{\"SUCCESS\"}, null)[0]);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(X.<@A @B(1) String[], @C(\'-\') X>foo(new String[]{\"SUCCESS\"}, null)[0]);\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " System.out.println(X.<@A @B(1) String[], @C(\'-\') X>foo(new String[]{\"SUCCESS\"}, null)[0]);\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " System.out.println(X.<@A @B(1) String[], @C(\'-\') X>foo(new String[]{\"SUCCESS\"}, null)[0]);\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n"); + } + public void test029() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends @Marker2 Object {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends @Marker2 Object {}\n" + + " ^^^^^^^\n" + + "Marker2 cannot be resolved to a type\n" + + "----------\n"); + } + public void test030() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X implements @Marker2 Serializable {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X implements @Marker2 Serializable {\n" + + " ^^^^^^^\n" + + "Marker2 cannot be resolved to a type\n" + + "----------\n"); + } + public void test031() throws Exception { + this.runNegativeTest( + new String[] { + "Marker.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Target(TYPE)\n" + + "@interface Marker {}", + "X.java", + "public class X<@Marker T> {}", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X<@Marker T> {}\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n"); + } + public void test032() throws Exception { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Marker.java", + "@interface Marker {}", + "X.java", + "public class X<@Marker T> {}", + }; + runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8231436; + runner.runConformTest(); + } + public void test033() throws Exception { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Marker.java", + "@interface Marker {}", + "Y.java", + "public class Y {}", + "X.java", + "public class X extends @Marker Y {}", + }; + runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8231436; + runner.runConformTest(); + } + // check locations + public void test034() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " @H String @E[] @F[] @G[] field;\n" + + " @A Map<@B String, @C List<@D Object>> field2;\n" + + " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @H String @E[] @F[] @G[] field;\n" + + " ^\n" + + "H cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " @H String @E[] @F[] @G[] field;\n" + + " ^\n" + + "E cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " @H String @E[] @F[] @G[] field;\n" + + " ^\n" + + "F cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " @H String @E[] @F[] @G[] field;\n" + + " ^\n" + + "G cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " @A Map<@B String, @C List<@D Object>> field2;\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 5)\n" + + " @A Map<@B String, @C List<@D Object>> field2;\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 5)\n" + + " @A Map<@B String, @C List<@D Object>> field2;\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 5)\n" + + " @A Map<@B String, @C List<@D Object>> field2;\n" + + " ^\n" + + "D cannot be resolved to a type\n" + + "----------\n" + + "9. ERROR in X.java (at line 6)\n" + + " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "10. ERROR in X.java (at line 6)\n" + + " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "11. ERROR in X.java (at line 6)\n" + + " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" + + " ^\n" + + "H cannot be resolved to a type\n" + + "----------\n" + + "12. ERROR in X.java (at line 6)\n" + + " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" + + " ^\n" + + "E cannot be resolved to a type\n" + + "----------\n" + + "13. ERROR in X.java (at line 6)\n" + + " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" + + " ^\n" + + "F cannot be resolved to a type\n" + + "----------\n" + + "14. ERROR in X.java (at line 6)\n" + + " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" + + " ^\n" + + "G cannot be resolved to a type\n" + + "----------\n"); + } + // check locations + public void test035() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " @H java.lang.String @E[] @F[] @G[] field;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @H java.lang.String @E[] @F[] @G[] field;\n" + + " ^\n" + + "H cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " @H java.lang.String @E[] @F[] @G[] field;\n" + + " ^\n" + + "E cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " @H java.lang.String @E[] @F[] @G[] field;\n" + + " ^\n" + + "F cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " @H java.lang.String @E[] @F[] @G[] field;\n" + + " ^\n" + + "G cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383884 -- Compiler tolerates illegal dimension annotation in class literal expressions + public void test036() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " System.out.println(X @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " System.out.println(int [] [] [] [] [].class);\n" + + " System.out.println(X [] [] [] [] [].class);\n" + + " }\n" + + "}\n" + + "@interface Empty {\n" + + "}\n" + + "@interface NonEmpty {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " System.out.println(int @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " System.out.println(X @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " System.out.println(X @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " System.out.println(X @NonEmpty [] [] @NonEmpty @Empty [] [] @NonEmpty[].class); // illegal!\n" + + " ^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + public void test037() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "@interface Marker {}\n" + + "@Marker // line 2: Don't complain \n" + + "public class X<@Marker T> extends @Marker Object{ // 3: Complain \n" + + " public @Marker Object foo(@Marker Object obj) { // 4: Don't complain on both\n" + + " return null;\n" + + " }\n" + + "}\n", + }; + runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8231436; + runner.runConformTest(); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383950 + // [1.8][compiler] Type annotations must have target type meta annotation TYPE_USE + public void test038() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Target({PACKAGE, TYPE, METHOD, FIELD, CONSTRUCTOR, PARAMETER, LOCAL_VARIABLE})\n" + + "@interface Marker {}\n" + + "public class X<@Marker T> extends @Marker Object{ // 3: Complain \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public class X<@Marker T> extends @Marker Object{ // 3: Complain \n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public class X<@Marker T> extends @Marker Object{ // 3: Complain \n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n"); + } + // JSR 308: "It is not permitted to annotate the type name in an import statement." + public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "import @Marker java.lang.String; // Compilation error \n" + + "public class X { \n" + + "}\n" + + "@interface Marker {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import @Marker java.lang.String; // Compilation error \n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // Test that type name can't be left out in a cast expression with an annotations + public void test040() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n" + + " public void foo(Object myObject) {\n" + + " String myString = (@NonNull) myObject;" + + " }\n" + + "}\n" + + "@interface NonNull {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " String myString = (@NonNull) myObject; }\n" + + " ^\n" + + "Syntax error on token \"@\", delete this token\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=385111 + // [1.8][compiler] Compiler fails to flag undefined annotation type. + public void test0385111() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public void foo(String fileName) {\n" + + " List l = new @MissingTypeNotIgnored ArrayList();\n" + + " List l1 = new @MissingTypeIgnored ArrayList<>();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " List l = new @MissingTypeNotIgnored ArrayList();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "MissingTypeNotIgnored cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " List l1 = new @MissingTypeIgnored ArrayList<>();\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "MissingTypeIgnored cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=385111 + // Test to exercise assorted cleanup along with bug fix. + public void test0385111a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String fileName) {\n" + + " try (@Annot X x = null; @Annot X x2 = null) {\n"+ + " } catch (@Annot NullPointerException | @Annot UnsupportedOperationException e) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (@Annot X x = null; @Annot X x2 = null) {\n" + + " ^^^^^\n" + + "Annot cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " try (@Annot X x = null; @Annot X x2 = null) {\n" + + " ^\n" + + "The resource type X does not implement java.lang.AutoCloseable\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " try (@Annot X x = null; @Annot X x2 = null) {\n" + + " ^^^^^\n" + + "Annot cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " try (@Annot X x = null; @Annot X x2 = null) {\n" + + " ^\n" + + "The resource type X does not implement java.lang.AutoCloseable\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " } catch (@Annot NullPointerException | @Annot UnsupportedOperationException e) {\n" + + " ^^^^^\n" + + "Annot cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " } catch (@Annot NullPointerException | @Annot UnsupportedOperationException e) {\n" + + " ^^^^^\n" + + "Annot cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383913 + public void test0383913() { + this.runNegativeTest( + new String[]{ + "X.java", + "public class X {\n" + + " public void foo(Object obj, X this) {}\n" + + " public void foo(Object obj1, X this, Object obj2) {}\n" + + " public void foo(Object obj, Object obj2, Object obj3, X this) {}\n" + + " class Y {\n" + + " Y(Object obj, Y Y.this){}\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(Object obj, X this) {}\n" + + " ^^^^\n" + + "Only the first formal parameter may be declared explicitly as 'this'\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public void foo(Object obj1, X this, Object obj2) {}\n" + + " ^^^^\n" + + "Only the first formal parameter may be declared explicitly as 'this'\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " public void foo(Object obj, Object obj2, Object obj3, X this) {}\n" + + " ^^^^\n" + + "Only the first formal parameter may be declared explicitly as 'this'\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Y(Object obj, Y Y.this){}\n" + + " ^^^^\n" + + "Only the first formal parameter may be declared explicitly as 'this'\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383913 + public void test0383913b() { + this.runNegativeTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " Outer(Outer Outer.this) {}\n" + + " Outer(Outer this, int i) {}\n" + + " class Inner {\n" + + " class InnerMost {\n" + + " InnerMost(Outer.Inner this) {}\n" + + " InnerMost(Outer.Inner Outer.Inner.this, int i, float f) {}\n" + + " InnerMost(Outer Outer.this, float f) {}\n" + + " InnerMost(Outer.Inner.InnerMost Outer.Inner.InnerMost.this, Object obj) {}\n" + + " InnerMost(Inner Outer.Inner.InnerMost.this, int i) {}\n" + + " InnerMost(Outer.Inner this, float f, int i) {}\n" + + " InnerMost(Outer.Inner Inner.this, long l) {}\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in Outer.java (at line 2)\n" + + " Outer(Outer Outer.this) {}\n" + + " ^^^^\n" + + "Explicit 'this' parameter is allowed only in instance methods of non-anonymous classes and inner class constructors\n" + + "----------\n" + + "2. ERROR in Outer.java (at line 3)\n" + + " Outer(Outer this, int i) {}\n" + + " ^^^^\n" + + "Explicit 'this' parameter is allowed only in instance methods of non-anonymous classes and inner class constructors\n" + + "----------\n" + + "3. WARNING in Outer.java (at line 6)\n" + + " InnerMost(Outer.Inner this) {}\n" + + " ^^^^^^^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "4. ERROR in Outer.java (at line 6)\n" + + " InnerMost(Outer.Inner this) {}\n" + + " ^^^^^^^^^^^\n" + + "The declared type of the explicit 'this' parameter is expected to be Outer.Inner\n" + + "----------\n" + + "5. ERROR in Outer.java (at line 6)\n" + + " InnerMost(Outer.Inner this) {}\n" + + " ^^^^\n" + + "The explicit 'this' parameter is expected to be qualified with Inner\n" + + "----------\n" + + "6. WARNING in Outer.java (at line 7)\n" + + " InnerMost(Outer.Inner Outer.Inner.this, int i, float f) {}\n" + + " ^^^^^^^^^^^\n" + + "Outer.Inner is a raw type. References to generic type Outer.Inner should be parameterized\n" + + "----------\n" + + "7. ERROR in Outer.java (at line 7)\n" + + " InnerMost(Outer.Inner Outer.Inner.this, int i, float f) {}\n" + + " ^^^^^^^^^^^\n" + + "The declared type of the explicit 'this' parameter is expected to be Outer.Inner\n" + + "----------\n" + + "8. ERROR in Outer.java (at line 7)\n" + + " InnerMost(Outer.Inner Outer.Inner.this, int i, float f) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The explicit 'this' parameter is expected to be qualified with Inner\n" + + "----------\n" + + "9. ERROR in Outer.java (at line 8)\n" + + " InnerMost(Outer Outer.this, float f) {}\n" + + " ^^^^^\n" + + "The declared type of the explicit 'this' parameter is expected to be Outer.Inner\n" + + "----------\n" + + "10. ERROR in Outer.java (at line 8)\n" + + " InnerMost(Outer Outer.this, float f) {}\n" + + " ^^^^^^^^^^\n" + + "The explicit 'this' parameter is expected to be qualified with Inner\n" + + "----------\n" + + "11. ERROR in Outer.java (at line 9)\n" + + " InnerMost(Outer.Inner.InnerMost Outer.Inner.InnerMost.this, Object obj) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The declared type of the explicit 'this' parameter is expected to be Outer.Inner\n" + + "----------\n" + + "12. ERROR in Outer.java (at line 9)\n" + + " InnerMost(Outer.Inner.InnerMost Outer.Inner.InnerMost.this, Object obj) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The explicit 'this' parameter is expected to be qualified with Inner\n" + + "----------\n" + + "13. ERROR in Outer.java (at line 10)\n" + + " InnerMost(Inner Outer.Inner.InnerMost.this, int i) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The explicit 'this' parameter is expected to be qualified with Inner\n" + + "----------\n" + + "14. ERROR in Outer.java (at line 11)\n" + + " InnerMost(Outer.Inner this, float f, int i) {}\n" + + " ^^^^\n" + + "The explicit 'this' parameter is expected to be qualified with Inner\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383913 + public void test0383913c() { + this.runNegativeTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " class Inner {\n" + + " class InnerMost {\n" + + " public void foo(Outer Outer.this) {}\n" + + " public void foo(Inner Inner.this, int i) {}\n" + + " public void foo(InnerMost this, int i, int j) {}\n" + + " public void foo(Inner.InnerMost this, Object obj) {}\n" + + " public void foo(InnerMost this, float f) {}\n" + + " public void foo(Inner.InnerMost this, long l) {}\n" + + " public void foo(Outer.Inner.InnerMost this, float f, float ff) {}\n" + + " public void foo(InnerMost Outer.Inner.InnerMost.this, int i, float f) {}\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in Outer.java (at line 4)\n" + + " public void foo(Outer Outer.this) {}\n" + + " ^^^^^\n" + + "The declared type of the explicit 'this' parameter is expected to be Outer.Inner.InnerMost\n" + + "----------\n" + + "2. ERROR in Outer.java (at line 4)\n" + + " public void foo(Outer Outer.this) {}\n" + + " ^^^^^^^^^^\n" + + "The explicit 'this' parameter for a method cannot have a qualifying name\n" + + "----------\n" + + "3. ERROR in Outer.java (at line 5)\n" + + " public void foo(Inner Inner.this, int i) {}\n" + + " ^^^^^\n" + + "The declared type of the explicit 'this' parameter is expected to be Outer.Inner.InnerMost\n" + + "----------\n" + + "4. ERROR in Outer.java (at line 5)\n" + + " public void foo(Inner Inner.this, int i) {}\n" + + " ^^^^^^^^^^\n" + + "The explicit 'this' parameter for a method cannot have a qualifying name\n" + + "----------\n" + + "5. WARNING in Outer.java (at line 6)\n" + + " public void foo(InnerMost this, int i, int j) {}\n" + + " ^^^^^^^^^\n" + + "Outer.Inner.InnerMost is a raw type. References to generic type Outer.Inner.InnerMost should be parameterized\n" + + "----------\n" + + "6. ERROR in Outer.java (at line 6)\n" + + " public void foo(InnerMost this, int i, int j) {}\n" + + " ^^^^^^^^^\n" + + "The declared type of the explicit 'this' parameter is expected to be Outer.Inner.InnerMost\n" + + "----------\n" + + "7. ERROR in Outer.java (at line 7)\n" + + " public void foo(Inner.InnerMost this, Object obj) {}\n" + + " ^^^^^^^^^^^^^^^\n" + + "The member type Outer.Inner.InnerMost must be qualified with a parameterized type, since it is not static\n" + + "----------\n" + + "8. ERROR in Outer.java (at line 7)\n" + + " public void foo(Inner.InnerMost this, Object obj) {}\n" + + " ^^^^^^^^^^^^^^^\n" + + "The declared type of the explicit 'this' parameter is expected to be Outer.Inner.InnerMost\n" + + "----------\n" + + "9. ERROR in Outer.java (at line 11)\n" + + " public void foo(InnerMost Outer.Inner.InnerMost.this, int i, float f) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The explicit 'this' parameter for a method cannot have a qualifying name\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383913 + public void test0383913d() { + this.runNegativeTest( + new String[] { + "Outer.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class Outer {\n" + + " class Inner {\n" + + " public Inner(@Missing Outer Outer.this) {}\n" + + " class InnerMost {\n" + + " public void bar() {\n" + + " new AnonymousInner() {\n" + + " public void foobar(AnonymousInner this) {}\n" + + " };\n" + + " }\n" + + " void bar(int i) {\n" + + " class Local {\n" + + " public int hashCode(Local this, int k) { return 0; }\n" + + " public int hashCode(Outer.Local this) { return 0; }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " static class StaticNested {\n" + + " public StaticNested(@Marker Outer.StaticNested Outer.StaticNested.this) {}\n" + + " }\n" + + " public static void foo(@Marker Outer this) {}\n" + + " public void foo(@Missing Outer this, int i) {}\n" + + "}\n" + + "interface AnonymousInner {\n" + + " public void foobar(AnonymousInner this);\n" + + "}\n" + + "@Target(TYPE_USE)\n" + + "@interface Marker {}", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Outer.java (at line 5)\n" + + " public Inner(@Missing Outer Outer.this) {}\n" + + " ^^^^^^^\n" + + "Missing cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in Outer.java (at line 9)\n" + + " public void foobar(AnonymousInner this) {}\n" + + " ^^^^\n" + + "Explicit \'this\' parameter is allowed only in instance methods of non-anonymous classes and inner class constructors\n" + + "----------\n" + + "3. ERROR in Outer.java (at line 15)\n" + + " public int hashCode(Outer.Local this) { return 0; }\n" + + " ^^^^^^^^^^^\n" + + "Outer.Local cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in Outer.java (at line 21)\n" + + " public StaticNested(@Marker Outer.StaticNested Outer.StaticNested.this) {}\n" + + " ^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "5. ERROR in Outer.java (at line 21)\n" + + " public StaticNested(@Marker Outer.StaticNested Outer.StaticNested.this) {}\n" + + " ^^^^\n" + + "Explicit \'this\' parameter is allowed only in instance methods of non-anonymous classes and inner class constructors\n" + + "----------\n" + + "6. ERROR in Outer.java (at line 23)\n" + + " public static void foo(@Marker Outer this) {}\n" + + " ^^^^\n" + + "Explicit \'this\' parameter is allowed only in instance methods of non-anonymous classes and inner class constructors\n" + + "----------\n" + + "7. ERROR in Outer.java (at line 24)\n" + + " public void foo(@Missing Outer this, int i) {}\n" + + " ^^^^^^^\n" + + "Missing cannot be resolved to a type\n" + + "----------\n"); + } + public void test0383908() { + this.runNegativeTest( + new String[]{"X.java", + "public class X { \n" + + " void foo(X this) {}\n" + + " void foo() {}\n" + + "}\n" + + "class Y {\n" + + " void foo(Y this) {}\n" + + " public static void main(String[] args) {\n" + + " new Y().foo();\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(X this) {}\n" + + " ^^^^^^^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " void foo() {}\n" + + " ^^^^^\n" + + "Duplicate method foo() in type X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on nested package names. + public void test383596() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "package p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + "public class X {\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " package p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " package p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " package p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on nested package names. + public void test383596a() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "@Marker package p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + "public class X {\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Marker package p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^^^^^^^\n" + + "Package annotations must be in file package-info.java\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " @Marker package p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " @Marker package p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 1)\n" + + " @Marker package p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on nested import names. + public void test039b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + "public class X {\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^\n" + + "The import p cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " import p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " import p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 1)\n" + + " import p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z. z2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on nested import names. + public void test383596b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.*;\n" + + "public class X {\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.*;\n" + + " ^\n" + + "The import p cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " import p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.*;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " import p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.*;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 1)\n" + + " import p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.*;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on nested static import names. + public void test041() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import static p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.z2;\n" + + "public class X {\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.z2;\n" + + " ^\n" + + "The import p cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " import static p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.z2;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " import static p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.z2;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 1)\n" + + " import static p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.z2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on nested static import names. + public void test042() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "import static p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.*;\n" + + "public class X {\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.*;\n" + + " ^\n" + + "The import p cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " import static p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.*;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " import static p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.*;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 1)\n" + + " import static p. @Marker q.x. @Marker @Marker y. @Marker @Marker @Marker z.*;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on Qualified name in explicit this. + // Much water has flown under the bridge. The grammar itself does not allow annotations in qualified name in explicit this. + // We now use the production UnannotatableName instead of plain Name. + public void test043() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " class Z {\n" + + " Z(X. @Marker Y Y.this) {\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Z(X. @Marker Y Y.this) {\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on Qualified name in explicit constructor call -- super form + public void test044() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static X x;\n" + + " public class InnerBar {\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar() {\n" + + " X.@Marker x. @Marker @Marker @Marker x.super();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X.@Marker x. @Marker @Marker @Marker x.super();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X.@Marker x. @Marker @Marker @Marker x.super();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " X.@Marker x. @Marker @Marker @Marker x.super();\n" + + " ^\n" + + "The static field X.x should be accessed in a static way\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on Qualified name in explicit constructor call, super form with explicit type arguments + public void test045() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static X x;\n" + + " public class InnerBar {\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar() {\n" + + " X.@Marker x. @Marker @Marker @Marker x.super();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " X.@Marker x. @Marker @Marker @Marker x.super();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " X.@Marker x. @Marker @Marker @Marker x.super();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " X.@Marker x. @Marker @Marker @Marker x.super();\n" + + " ^\n" + + "The static field X.x should be accessed in a static way\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " X.@Marker x. @Marker @Marker @Marker x.super();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X.InnerBar() of type X.InnerBar; it should not be parameterized with arguments \n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on Qualified name in explicit constructor call - this form + public void test046() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Bar bar;\n" + + " class Bar {\n" + + " //static Bar x;\n" + + " public class InnerBar {\n" + + " InnerBar(Bar x) {\n" + + " }\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar() {\n" + + " X. @Marker bar.this();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X. @Marker bar.this();\n" + + " ^^^^^^^^^^^^^^\n" + + "Illegal enclosing instance specification for type X.Bar.SubInnerBar\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " X. @Marker bar.this();\n" + + " ^^^^^^^^^^^^^^\n" + + "Cannot make a static reference to the non-static field X.bar\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " X. @Marker bar.this();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on Qualified name in explicit constructor call, this form with explicit type arguments + public void test047() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Bar bar;\n" + + " class Bar {\n" + + " //static Bar x;\n" + + " public class InnerBar {\n" + + " InnerBar(Bar x) {\n" + + " }\n" + + " }\n" + + " public class SubInnerBar extends InnerBar {\n" + + " SubInnerBar() {\n" + + " X.@Marker bar.this();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X.@Marker bar.this();\n" + + " ^^^^^^^^^^^^^\n" + + "Illegal enclosing instance specification for type X.Bar.SubInnerBar\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " X.@Marker bar.this();\n" + + " ^^^^^^^^^^^^^\n" + + "Cannot make a static reference to the non-static field X.bar\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " X.@Marker bar.this();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " X.@Marker bar.this();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor X.Bar.SubInnerBar() of type X.Bar.SubInnerBar; it should not be parameterized with arguments \n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations on Qualified name in PrimaryNoNewArray + public void test048() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar;\n" + + " private void foo(X x) {\n" + + " System.out.println((x. @Marker bar));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " System.out.println((x. @Marker bar));\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in qualified this. + public void test049() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " class Z {\n" + + " void foo() {\n" + + " Object o = X.@Marker Y.this; \n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Object o = X.@Marker Y.this; \n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in qualified super. + public void test050() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class Y {\n" + + " public void foo() {\n" + + " X. @Marker Y.super.hashCode();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X. @Marker Y.super.hashCode();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in Name.class + public void test051() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class Y {\n" + + " public void foo() {\n" + + " Class c = X. @Marker @Illegal Y.class;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Class c = X. @Marker @Illegal Y.class;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in Name [].class. + public void test052() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class Y {\n" + + " public void foo() {\n" + + " Class c = X. @Marker @Another Y @YetMore [].class;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Class c = X. @Marker @Another Y @YetMore [].class;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Class c = X. @Marker @Another Y @YetMore [].class;\n" + + " ^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in binary expressions with qualified names. + public void test053() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static int x;\n" + + " static boolean fb;\n" + + " public void foo(boolean b) {\n" + + " x = (X.@Marker x * 10);\n" + + " x = (X.@Marker x / 10);\n" + + " x = (X.@Marker x % 10);\n" + + " x = (X.@Marker x + 10);\n" + + " x = (X.@Marker x - 10);\n" + + " x = (X.@Marker x << 10);\n" + + " x = (X.@Marker x >> 10);\n" + + " x = (X.@Marker x >>> 10);\n" + + " b = (X.@Marker x < 10);\n" + + " b = (X.@Marker x > 10);\n" + + " b = (X.@Marker x <= 10);\n" + + " b = (X.@Marker x >= 10);\n" + + " b = (X.@Marker x instanceof Object);\n" + + " b = (X.@Marker x == 10);\n" + + " b = (X.@Marker x != 10);\n" + + " x = (X.@Marker x & 10);\n" + + " x = (X.@Marker x ^ 10);\n" + + " x = (X.@Marker x | 10);\n" + + " fb = (X.@Marker fb && true);\n" + + " fb = (X.@Marker fb || true);\n" + + " x = (X.@Marker fb ? 10 : 10);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " x = (X.@Marker x * 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " x = (X.@Marker x / 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " x = (X.@Marker x % 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " x = (X.@Marker x + 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " x = (X.@Marker x - 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " x = (X.@Marker x << 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " x = (X.@Marker x >> 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "8. ERROR in X.java (at line 12)\n" + + " x = (X.@Marker x >>> 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "9. ERROR in X.java (at line 13)\n" + + " b = (X.@Marker x < 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "10. ERROR in X.java (at line 14)\n" + + " b = (X.@Marker x > 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "11. ERROR in X.java (at line 15)\n" + + " b = (X.@Marker x <= 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "12. ERROR in X.java (at line 16)\n" + + " b = (X.@Marker x >= 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "13. ERROR in X.java (at line 17)\n" + + " b = (X.@Marker x instanceof Object);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types int and Object\n" + + "----------\n" + + "14. ERROR in X.java (at line 17)\n" + + " b = (X.@Marker x instanceof Object);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "15. ERROR in X.java (at line 18)\n" + + " b = (X.@Marker x == 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "16. ERROR in X.java (at line 19)\n" + + " b = (X.@Marker x != 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "17. ERROR in X.java (at line 20)\n" + + " x = (X.@Marker x & 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "18. ERROR in X.java (at line 21)\n" + + " x = (X.@Marker x ^ 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "19. ERROR in X.java (at line 22)\n" + + " x = (X.@Marker x | 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "20. ERROR in X.java (at line 23)\n" + + " fb = (X.@Marker fb && true);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "21. ERROR in X.java (at line 24)\n" + + " fb = (X.@Marker fb || true);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "22. ERROR in X.java (at line 25)\n" + + " x = (X.@Marker fb ? 10 : 10);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in annotations with qualified names. + This test is disabled. Now the grammar itself forbids annotations in the said place by using the production + AnnotationName ::= '@' UnannotatableName. We don't want to add tests that will be fragile and unstable due to + syntax. If a construct is provably not parsed at the grammar level, that ought to be good enough. + */ + public void test054() throws Exception { + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in qualified names used as annotation values. + public void test055() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Annot {\n" + + " String bar();\n" + + "}\n" + + "@Annot(bar = X. @Marker s)\n" + + "public class X {\n" + + " final static String s = \"\";\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Annot(bar = X. @Marker s)\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in qualified names that are postfix expressions. + public void test056() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static int x;\n" + + " int foo() {\n" + + " return X.@Marker x;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return X.@Marker x;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in qualified names used in array access. + public void test057() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static int x[];\n" + + " int foo() {\n" + + " return X.@Marker x[0];\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return X.@Marker x[0];\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in qualified name with type arguments used in method invocation. + public void test058() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static X x;\n" + + " int foo() {\n" + + " return X.@Marker x. foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return X.@Marker x. foo();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " return X.@Marker x. foo();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method foo() of type X; it should not be parameterized with arguments \n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in qualified name used in method invocation. + public void test059() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static X x;\n" + + " int foo() {\n" + + " return X.@Marker x. @Blah foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return X.@Marker x. @Blah foo();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " return X.@Marker x. @Blah foo();\n" + + " ^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in qualified name used in class instance creation + public void test060() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static Y y;\n" + + " class Y {\n" + + " class Z {\n" + + " void foo() {\n" + + " Z z = X. @Marker y.new Z();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Z z = X. @Marker y.new Z();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383596 -- reject annotations in qualified name used in class instance creation + public void test061() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static X x;\n" + + " X getX() {\n" + + " return (X.@Marker x);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return (X.@Marker x);\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + public void test062() throws Exception { + // was negative prior to https://bugs.openjdk.java.net/browse/JDK-8231435 + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public @Marker Object foo() {\n" + + " return null;" + + " }\n" + + "}\n" + + "@interface Marker {\n" + + "}\n" + }, + ""); + } + public void test063() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o = @Marker int.class;\n" + + "}\n" + + "@interface Marker {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Object o = @Marker int.class;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + public void test064() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "@interface X {\n" + + " @Marker String foo();\n" + + "}\n" + + "@interface Marker {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Marker String foo();\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " @Marker String foo();\n" + + " ^^^^^\n" + + "Annotation attributes cannot be generic\n" + + "----------\n"); + } + public void test065() throws Exception { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " Object o = new @Marker X();\n" + + "}\n" + + "@interface Marker {\n" + + "}\n" + }; + runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8231436; + runner.runConformTest(); + } + public void test066() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o = new X().new @Marker X();\n" + + "}\n" + + "@interface Marker {\n" + + "}\n" + }, + // one error removed after https://bugs.openjdk.java.net/browse/JDK-8231435 + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Object o = new X().new @Marker X();\n" + + " ^^^^^^^^^\n" + + "X.X cannot be resolved to a type\n" + + "----------\n"); + } + public void test067() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o = x.new @Marker X() {};\n" + + "}\n" + + "@interface Marker {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Object o = x.new @Marker X() {};\n" + + " ^\n" + + "x cannot be resolved to a variable\n" + + "----------\n"); + } + public void test068() throws Exception { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " Object o = new @Marker X() {};\n" + + "}\n" + + "@interface Marker {\n" + + "}\n" + }; + runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8231436; + runner.runConformTest(); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=385293 + public void test069() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " Object o = (Object) (public X) null;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^^^^^\n" + + "Syntax error on token \"final\", delete this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " Object o = (Object) (public X) null;\n" + + " ^^^^^^\n" + + "Syntax error on token \"public\", delete this token\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " Object o = (Object) (public X) null;\n" + + " ^^^^^\n" + + "Syntax error on token \"final\", delete this token\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=388085 + public void test0388085() { + this.runNegativeTest( + new String[] {"X.java", + "class X {\n" + + " public void main() {\n" + + " final One<@Marker ? extends Two<@Marker ? super Three>>> one = null;" + + " one = null;\n" + + " }\n" + + "}\n" + + "class One {}\n" + + "class Two {}\n" + + "class Three {}\n" + + "class Four {}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " final One<@Marker ? extends Two<@Marker ? super Three>>> one = null; one = null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " final One<@Marker ? extends Two<@Marker ? super Three>>> one = null; one = null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " final One<@Marker ? extends Two<@Marker ? super Three>>> one = null; one = null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " final One<@Marker ? extends Two<@Marker ? super Three>>> one = null; one = null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + public void test0388085a() { + this.runNegativeTest( + new String[] {"X.java", + "class X {\n" + + " public void main() {\n" + + " final One<@Marker ? extends Two<@Marker ? super Three>>> one = null;" + + " one = null;\n" + + " }\n" + + "}\n" + + "class One {}\n" + + "class Two {}\n" + + "class Three {}\n" + + "class Four {}\n" + + "@interface Marker {}"}, + // some errors no longer raised since https://bugs.openjdk.java.net/browse/JDK-8231435 + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " final One<@Marker ? extends Two<@Marker ? super Three>>> one = null; one = null;\n" + + " ^^^\n" + + "The final local variable one cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=390882 + public void test0390882() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class X { \n " + + " Object o1 = (@Marker java.lang.Integer) null; // 1. Right.\n" + + " Object o2 = (java. @Marker lang.Integer) null; // 2. Wrong.\n" + + " Object o3 = (java.lang. @Marker Integer) null; // 3. Legal.\n" + + " public void foo(java. @Marker lang.Integer arg) {}\n" + + " public void bar(java.lang. @Marker Integer arg) {}\n" + + " public void foobar(@Marker java.lang.Integer arg) {}\n" + + "}\n" + + "@Target(TYPE_USE)\n" + + "@interface Marker {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Object o1 = (@Marker java.lang.Integer) null; // 1. Right.\n" + + " ^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Object o2 = (java. @Marker lang.Integer) null; // 2. Wrong.\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " public void foo(java. @Marker lang.Integer arg) {}\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " public void foobar(@Marker java.lang.Integer arg) {}\n" + + " ^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n"); + } + public void test0390882a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class X { \n " + + " Object o1 = (java. @Marker @Annot lang.Integer) null; // 1. Wrong.\n" + + " Object o2 = (java.lang. @Marker @Annot Integer) null; // 2. Legal\n" + + " Object o3 = (java.@lang lang) null; // 3. Wrong.\n" + + "}\n" + + "@Target(TYPE_USE)\n" + + "@interface Marker {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Annot {}", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Object o1 = (java. @Marker @Annot lang.Integer) null; // 1. Wrong.\n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Object o3 = (java.@lang lang) null; // 3. Wrong.\n" + + " ^^^^^^^^^^^^^^^\n" + + "java.lang cannot be resolved to a type\n" + + "----------\n"); + } + public void test0390882b() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class X { \n " + + " Object o1 = (@Marker @Annot java.util.List) null; // 1. Wrong.\n" + + " Object o2 = (java. @Marker @Annot lang.Integer[]) null; // 2. Wrong.\n" + + " Object o3 = (@Marker @Annot java.util.List[]) null; // 3. Wrong.\n" + + " Object o4 = (java.util.List @Marker @Annot []) null; // 4. Right.\n" + + " Object o5 = (java.lang.Integer @Marker @Annot []) null; // 5. Right.\n" + + "}\n" + + "@Target(TYPE_USE)\n" + + "@interface Marker {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Annot {}", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Object o1 = (@Marker @Annot java.util.List) null; // 1. Wrong.\n" + + " ^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Object o1 = (@Marker @Annot java.util.List) null; // 1. Wrong.\n" + + " ^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Object o2 = (java. @Marker @Annot lang.Integer[]) null; // 2. Wrong.\n" + + " ^^^^^^^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Object o3 = (@Marker @Annot java.util.List[]) null; // 3. Wrong.\n" + + " ^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " Object o3 = (@Marker @Annot java.util.List[]) null; // 3. Wrong.\n" + + " ^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=385137 + public void test0385137() { + this.runNegativeTest( + new String[]{ "A.java", + "package p;" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class A { \n" + + " static class B {" + + " static class C {" + + " } " + + " }\n" + + " public void foo() {\n" + + " Object o = (@Marker @Annot A.@Marker B.@Marker C) null;\n" + + " Object o2 = (@Marker p.@Marker A.@Marker B.@Marker C) null;\n" + + " }\n" + + "}\n" + + "@Target(TYPE_USE)\n" + + "@interface Marker {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Annot {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n"}, + "----------\n" + + "1. ERROR in A.java (at line 6)\n" + + " Object o = (@Marker @Annot A.@Marker B.@Marker C) null;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "2. WARNING in A.java (at line 6)\n" + + " Object o = (@Marker @Annot A.@Marker B.@Marker C) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "A.B.C is a raw type. References to generic type A.B.C should be parameterized\n" + + "----------\n" + + "3. ERROR in A.java (at line 6)\n" + + " Object o = (@Marker @Annot A.@Marker B.@Marker C) null;\n" + + " ^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "4. ERROR in A.java (at line 7)\n" + + " Object o2 = (@Marker p.@Marker A.@Marker B.@Marker C) null;\n" + + " ^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "5. WARNING in A.java (at line 7)\n" + + " Object o2 = (@Marker p.@Marker A.@Marker B.@Marker C) null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "A.B.C is a raw type. References to generic type A.B.C should be parameterized\n" + + "----------\n" + + "6. ERROR in A.java (at line 7)\n" + + " Object o2 = (@Marker p.@Marker A.@Marker B.@Marker C) null;\n" + + " ^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "7. ERROR in A.java (at line 7)\n" + + " Object o2 = (@Marker p.@Marker A.@Marker B.@Marker C) null;\n" + + " ^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + public void test0385137a() { + this.runNegativeTest( + new String[]{"A.java", + "package p;" + + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class A { \n" + + " static class B {" + + " static class C {" + + " } " + + " }\n" + + " public void foo() {\n" + + " Object o1 = (@Marker p.@Marker A.@Marker B.@Marker C[]) null;\n" + + " Object o2 = (@Marker @Annot A.@Annot B.C) null;\n" + + " Object o5 = (@Marker @Annot A.B[]) null;\n" + + " }\n" + + "}\n" + + "@Target(TYPE_USE)\n" + + "@interface Marker {}\n" + + "@Target(TYPE_USE)\n" + + "@interface Annot {}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in A.java (at line 6)\n" + + " Object o1 = (@Marker p.@Marker A.@Marker B.@Marker C[]) null;\n" + + " ^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "2. ERROR in A.java (at line 6)\n" + + " Object o1 = (@Marker p.@Marker A.@Marker B.@Marker C[]) null;\n" + + " ^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "3. ERROR in A.java (at line 6)\n" + + " Object o1 = (@Marker p.@Marker A.@Marker B.@Marker C[]) null;\n" + + " ^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "4. ERROR in A.java (at line 7)\n" + + " Object o2 = (@Marker @Annot A.@Annot B.C) null;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "5. ERROR in A.java (at line 7)\n" + + " Object o2 = (@Marker @Annot A.@Annot B.C) null;\n" + + " ^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "6. ERROR in A.java (at line 8)\n" + + " Object o5 = (@Marker @Annot A.B[]) null;\n" + + " ^^^^^^^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + public void testBug391196() { + this.runNegativeTest( + new String[]{ + "p/Bug391196.java", + "package p;\n" + + "public class Bug391196 {\n" + + " @Marker\n" + + " public class X<@Marker @Marker2 T> {\n" + + " @Marker @Marker2 X(@Marker int i) {}\n" + + " @Unresolved X() {}\n" + + " }\n" + + " @Marker\n" + + " enum Color {RED, BLUE}\n" + + " @Marker\n" + + " interface Inter {}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker2 {}\n" + + "}\n", + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\Bug391196.java (at line 6)\n" + + " @Unresolved X() {}\n" + + " ^^^^^^^^^^\n" + + "Unresolved cannot be resolved to a type\n" + + "----------\n"); + } + public void testBug391315() { + this.runNegativeTest( + new String[]{ + "X.java", + "class X {\n" + + " X<@Marker ?> l;\n" + + " X<@Marker2 ?> l2;\n" + + " X<@Marker3 ?> l3;\n" + + " class Y {\n" + + " void Y1(Y this) {}\n" + + " }\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker2 {}\n" + + "@interface Marker3 {}\n", + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n"}, + // one error removed after https://bugs.openjdk.java.net/browse/JDK-8231435 + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X<@Marker ?> l;\n" + + " ^^^^^^^\n" + + "The annotation @Marker is disallowed for this location\n" + + "----------\n"); + } + public void testBug391315a() { + this.runNegativeTest( + new String[]{ + "X.java", + "public class X<@Marker T> {\n" + + " @Marker T t;\n" + + " T t2 = (@Marker T) null;\n" + + "}\n" + + "class X2<@Marker2 T> {\n" + + " @Marker2 T t;\n" + + " T t2 = (@Marker2 T) null;\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_PARAMETER)\n" + + "@interface Marker2 {}", + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " @Marker2 T t;\n" + + " ^^^^^^^^\n" + + "The annotation @Marker2 is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " T t2 = (@Marker2 T) null;\n" + + " ^^^^^^^^\n" + + "The annotation @Marker2 is disallowed for this location\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=391500 + public void testBug391500() { + this.runNegativeTest( + new String[]{ + "X.java", + "public class X {\n" + + " class Y {\n" + + " class Z {\n" + + " }\n" + + " Z z1 = new @Marker X().new @Marker Y().new @Marker Z();\n" + + " Z z3 = new @Marker Z(){};\n" + + " };\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Z z1 = new @Marker X().new @Marker Y().new @Marker Z();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Z z1 = new @Marker X().new @Marker Y().new @Marker Z();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Z z1 = new @Marker X().new @Marker Y().new @Marker Z();\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Z z3 = new @Marker Z(){};\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + public void testBug391464() { + this.runNegativeTest( + new String[]{ + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Object o = (X @Marker []) null;\n" + + " o = (java.lang.String @Marker []) null;\n" + + " o = (X @Marker []) null;\n" + + " o = (java.util.List @Marker []) null;\n" + + " if (o == null) return;\n" + + " }" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = (X @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " o = (java.lang.String @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " o = (X @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " o = (java.util.List @Marker []) null;\n" + + " ^^^^^^\n" + + "Marker cannot be resolved to a type\n" + + "----------\n"); + } + public void testBug391464_2() { + this.runNegativeTest( + new String[]{ + "X.java", + "public class X {\n" + + " class Y {\n" + + " class Z {}\n" + + " }\n" + + " @M X.@M Y.@Unreported Z z = null;\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface M {\n" + + "}\n", + + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @M X.@M Y.@Unreported Z z = null;\n" + + " ^^^^^^^^^^\n" + + "Unreported cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=391108 + public void testBug391108() { + this.runNegativeTest( + new String[]{ + "X.java", + "public class X {\n" + + " @Marker @Marker2 @Marker3 public void foo() {}\n" + + " @Marker @Marker2 @Marker3 void foo2() {}\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.METHOD)\n" + + "@interface Marker2 {}\n" + + "@java.lang.annotation.Target ({java.lang.annotation.ElementType.TYPE_USE, java.lang.annotation.ElementType.METHOD})\n" + + "@interface Marker3 {}", + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Marker @Marker2 @Marker3 public void foo() {}\n" + + " ^^^^^^^\n" + + "Type annotation is illegal for a method that returns void\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " @Marker @Marker2 @Marker3 void foo2() {}\n" + + " ^^^^^^^\n" + + "Type annotation is illegal for a method that returns void\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=392119 + public void test392119() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "@Marker78 @Marker8 @Marker7\n" + + "public class X {\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Target ({java.lang.annotation.ElementType.TYPE_USE, java.lang.annotation.ElementType.TYPE})\n" + + "@interface Marker78 {\n" + + "}\n" + + "@java.lang.annotation.Target ({java.lang.annotation.ElementType.TYPE})\n" + + "@interface Marker7 {\n" + + "}\n" + + "@java.lang.annotation.Target ({java.lang.annotation.ElementType.TYPE_USE})\n" + + "@interface Marker8 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = + " RuntimeInvisibleAnnotations: \n" + + " #24 @Marker78(\n" + + " )\n" + + " #25 @Marker8(\n" + + " )\n" + + " #26 @Marker7(\n" + + " )\n" + + " Attribute: MissingTypes Length: 4\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=392119, variant with explicit class file retention. + public void test392119b() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "@Marker78 @Marker8 @Marker7\n" + + "public class X {\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)\n" + + "@java.lang.annotation.Target ({java.lang.annotation.ElementType.TYPE_USE, java.lang.annotation.ElementType.TYPE})\n" + + "@interface Marker78 {\n" + + "}\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)\n" + + "@java.lang.annotation.Target ({java.lang.annotation.ElementType.TYPE})\n" + + "@interface Marker7 {\n" + + "}\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)\n" + + "@java.lang.annotation.Target ({java.lang.annotation.ElementType.TYPE_USE})\n" + + "@interface Marker8 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = + " RuntimeInvisibleAnnotations: \n" + + " #24 @Marker78(\n" + + " )\n" + + " #25 @Marker8(\n" + + " )\n" + + " #26 @Marker7(\n" + + " )\n" + + " Attribute: MissingTypes Length: 4\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=392119, variant with explicit runtime retention. + public void test392119c() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "@Marker78 @Marker8 @Marker7\n" + + "public class X {\n" + + " Zork z;\n" + + "}\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" + + "@java.lang.annotation.Target ({java.lang.annotation.ElementType.TYPE_USE, java.lang.annotation.ElementType.TYPE})\n" + + "@interface Marker78 {\n" + + "}\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" + + "@java.lang.annotation.Target ({java.lang.annotation.ElementType.TYPE})\n" + + "@interface Marker7 {\n" + + "}\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" + + "@java.lang.annotation.Target ({java.lang.annotation.ElementType.TYPE_USE})\n" + + "@interface Marker8 {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + String expectedOutput = + " RuntimeVisibleAnnotations: \n" + + " #24 @Marker78(\n" + + " )\n" + + " #25 @Marker8(\n" + + " )\n" + + " #26 @Marker7(\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=394355 + public void testBug394355() { + this.runNegativeTest( + new String[]{ + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class X {\n" + + " public void foo(@Marker @Marker2 X this) {}\n" + + " class Y {\n" + + " Y(@Marker @Marker2 X X.this) {}\n" + + " }\n" + + "}\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + + "@Target ({METHOD, PARAMETER, TYPE, PACKAGE, FIELD, CONSTRUCTOR, LOCAL_VARIABLE, TYPE_PARAMETER})\n" + + "@interface Marker2 {}", + "java/lang/annotation/ElementType.java", + "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public void foo(@Marker @Marker2 X this) {}\n" + + " ^^^^^^^^\n" + + "The annotation @Marker2 is disallowed for this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Y(@Marker @Marker2 X X.this) {}\n" + + " ^^^^^^^^\n" + + "The annotation @Marker2 is disallowed for this location\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399453 + public void testBug399453() { + this.runNegativeTest( + new String[]{ + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker bar()] @Marker @Marker2 [];\n" + + " int @Marker [][][] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker X.bar2(2)] @Marker @Marker2 [];\n" + + " }\n" + + " public int bar() {\n" + + " return 2;\n" + + " }\n" + + " public static int bar2(int k) {\n" + + " return k;\n" + + " }\n" + + "}\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker2 {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker bar()] @Marker @Marker2 [];\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " int @Marker [][][] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker X.bar2(2)] @Marker @Marker2 [];\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399453 + public void testBug391894() { + this.runNegativeTest( + new String[]{ + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker bar()] ;\n" + + " int @Marker [] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker bar()] ;\n" + + " }\n" + + " public int bar() {\n" + + " return 2;\n" + + " }\n" + + "}\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker2 {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker bar()] ;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from int[][] to int[][][]\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int @Marker [][][] i = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker bar()] ;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " int @Marker [] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker bar()] ;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from int[][] to int[]\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " int @Marker [] j = new @Marker2 int @Marker @Marker2 [2] @Marker @Marker2 [@Marker bar()] ;\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=402618, [1.8][compiler] Compiler fails to resolve type annotations on method/constructor references + public void test402618() { + this.runNegativeTest( + new String[]{ + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " void foo(List l);\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public void main(String[] args) {\n" + + " I i = @Readonly List<@English String>::<@NonNegative Integer>size;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " I i = @Readonly List<@English String>::<@NonNegative Integer>size;\n" + + " ^^^^^^^^\n" + + "Readonly cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " I i = @Readonly List<@English String>::<@NonNegative Integer>size;\n" + + " ^^^^^^^\n" + + "English cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " I i = @Readonly List<@English String>::<@NonNegative Integer>size;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Unused type arguments for the non generic method size() of type List; it should not be parameterized with arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " I i = @Readonly List<@English String>::<@NonNegative Integer>size;\n" + + " ^^^^^^^^^^^\n" + + "NonNegative cannot be resolved to a type\n" + + "----------\n"); + } + public void testBug403132() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class Y {\n" + + " class Z {\n" + + " public Z (@A X.@B Y Y.this, String str) {}\n" + + " public void foo (@A X.@B Y.@C Z this, String str) {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public Z (@A X.@B Y Y.this, String str) {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public Z (@A X.@B Y Y.this, String str) {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " public void foo (@A X.@B Y.@C Z this, String str) {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " public void foo (@A X.@B Y.@C Z this, String str) {}\n" + + " ^\n" + + "B cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " public void foo (@A X.@B Y.@C Z this, String str) {}\n" + + " ^\n" + + "C cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=403410 + public void testBug403410() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface A {}\n" + + "public class X {\n" + + " class Y {\n" + + " public Y (final @A X X.this) {}\n" + + " public Y (static @A X X.this, int i) {}\n" + + " public void foo(final @A Y this) {}\n" + + " public void foo(static @A Y this, int i) {}\n" + + "}\n}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public Y (final @A X X.this) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Syntax error, modifiers are not allowed here\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public Y (static @A X X.this, int i) {}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Syntax error, modifiers are not allowed here\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " public void foo(final @A Y this) {}\n" + + " ^^^^^^^^^^^^^^^\n" + + "Syntax error, modifiers are not allowed here\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " public void foo(static @A Y this, int i) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Syntax error, modifiers are not allowed here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=403581, [1.8][compiler] Compile error on varargs annotations. + public void test403581() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void foo(List @Marker ... ls) {}\n" + + "}\n" + + "@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo(List @Marker ... ls) {}\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter ls\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=392671, [1.8][recovery] NPE with a method with explicit this and a following incomplete parameter + public void test392671() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " public void foobar(X this, int, int k) {} // NPE!\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public void foobar(X this, int, int k) {} // NPE!\n" + + " ^^^\n" + + "Syntax error, insert \"... VariableDeclaratorId\" to complete FormalParameter\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n"); + } + // [1.8][compiler] Missing expected error for incorrect placement of type annotation (https://bugs.eclipse.org/bugs/show_bug.cgi?id=406587) + public void test406587() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import java.lang.annotation.*;\n" + + "public class X {\n" + + " @B(1) @A(1) String field1;\n" + + " @B @A X.Y field3;\n" + + " @A @B p.X.Y field4;\n" + + " @B(1) @A(1) java.lang.@A(1) @B(1) String field2;\n" + + " public @B(1) @A(1) java.lang. @A(1) @B(1) String foo(@A(1) @B(1) java.lang. @A(1) @B(1) String str1) {\n" + + " @A(1) @B(1) String local1;\n" + + " @A(1) @B(1) java.lang. @B(1) @A(1) String local2;\n" + + " @B @A X.Y local3;\n" + + " @B @A p.X.Y local4;\n" + + " @B @A p.q.X local5;\n" + + " return null;\n" + + " }\n" + + " class Y {}" + + "}\n" + + "@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})\n" + + "@interface A {\n" + + " int value() default -1;\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 6)\n" + + " @A @B p.X.Y field4;\n" + + " ^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 7)\n" + + " @B(1) @A(1) java.lang.@A(1) @B(1) String field2;\n" + + " ^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "3. ERROR in p\\X.java (at line 7)\n" + + " @B(1) @A(1) java.lang.@A(1) @B(1) String field2;\n" + + " ^^\n" + + "The annotation @A is disallowed for this location\n" + + "----------\n" + + "4. ERROR in p\\X.java (at line 8)\n" + + " public @B(1) @A(1) java.lang. @A(1) @B(1) String foo(@A(1) @B(1) java.lang. @A(1) @B(1) String str1) {\n" + + " ^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "5. ERROR in p\\X.java (at line 8)\n" + + " public @B(1) @A(1) java.lang. @A(1) @B(1) String foo(@A(1) @B(1) java.lang. @A(1) @B(1) String str1) {\n" + + " ^^\n" + + "The annotation @A is disallowed for this location\n" + + "----------\n" + + "6. ERROR in p\\X.java (at line 8)\n" + + " public @B(1) @A(1) java.lang. @A(1) @B(1) String foo(@A(1) @B(1) java.lang. @A(1) @B(1) String str1) {\n" + + " ^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "7. ERROR in p\\X.java (at line 8)\n" + + " public @B(1) @A(1) java.lang. @A(1) @B(1) String foo(@A(1) @B(1) java.lang. @A(1) @B(1) String str1) {\n" + + " ^^\n" + + "The annotation @A is disallowed for this location\n" + + "----------\n" + + "8. ERROR in p\\X.java (at line 10)\n" + + " @A(1) @B(1) java.lang. @B(1) @A(1) String local2;\n" + + " ^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "9. ERROR in p\\X.java (at line 10)\n" + + " @A(1) @B(1) java.lang. @B(1) @A(1) String local2;\n" + + " ^^\n" + + "The annotation @A is disallowed for this location\n" + + "----------\n" + + "10. ERROR in p\\X.java (at line 12)\n" + + " @B @A p.X.Y local4;\n" + + " ^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "11. ERROR in p\\X.java (at line 13)\n" + + " @B @A p.q.X local5;\n" + + " ^^^\n" + + "p.q cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=417076, Eclipse compiler rejects multiple annotations for varargs. + public void test417076() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface A {\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface B {\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface C {\n" + + "}\n" + + "public class X {\n" + + " public @A String foo(int @B @C @D ... args) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " public @A String foo(int @B @C @D ... args) {\n" + + " ^\n" + + "D cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=417076, Eclipse compiler rejects multiple annotations for varargs. + public void test417076b() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface A {\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface B {\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface C {\n" + + "}\n" + + "public class X {\n" + + " public @A String foo(int @B @C @A ... args) {\n" + + " return null;\n" + + " }\n" + + " public @A String goo(int @B @C @A ... args) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " public @A String goo(int @B @C @A ... args) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "This method must return a result of type String\n" + + "----------\n"); + } + // [1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + // This is the basic test case which demonstrated the issue for a local variable. + // We correctly identified the problem in function bar but failed to do so for foo. + public void test415308a() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Illegal {\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " Z() {}\n" + + " }\n" + + "}\n" + + "class X {\n" + + " Y.Z foo() {\n" + + " @Illegal Y.Z z = null;\n" + + " return z;\n" + + " }\n" + + " Y.Z bar() {\n" + + " Y.Z z = (@Illegal Y.Z)null;\n" + + " return z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " @Illegal Y.Z z = null;\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " Y.Z z = (@Illegal Y.Z)null;\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + // [1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + // This test case is similar to test415308a. SimpleTypes on which annotations are applied are modified to array + // types. + public void test415308a2() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Illegal {\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " Z() {}\n" + + " }\n" + + "}\n" + + "class X {\n" + + " Y.Z[] foo() {\n" + + " @Illegal Y.Z[] z = null;\n" + + " return z;\n" + + " }\n" + + " Y.Z[] bar() {\n" + + " Y.Z[] z = (@Illegal Y.Z[])null;\n" + + " return z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " @Illegal Y.Z[] z = null;\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " Y.Z[] z = (@Illegal Y.Z[])null;\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + // [1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + // Testing type use annotations on nested types. + // We check all the qualifiers as we look for a static type. This test checks if we are able to + // go beyond 1 level as part of the loop. + public void test415308b() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Illegal {\n" + + "}\n" + + "class Y {\n" + + " static class YY {\n" + + " class Z {\n" + + " Z() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "class X {\n" + + " Y.YY.Z foo() {\n" + + " @Illegal Y.YY.Z z = null;\n" + + " return z;\n" + + " }\n" + + " Y.YY.Z foo2() {\n" + + " Y.@Illegal YY.Z z = null;\n" + + " return z;\n" + + " }\n" + + " Y.YY.Z foo3() {\n" + + " Y.YY.@Illegal Z z = null;\n" + + " return z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " @Illegal Y.YY.Z z = null;\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + // [1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + // This test case is similar to test415308a. SimpleTypes on which annotations are applied are modified to array + // types. + public void test415308b2() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Illegal {\n" + + "}\n" + + "class Y {\n" + + " static class YY {\n" + + " class Z {\n" + + " Z() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "class X {\n" + + " Y.YY.Z[] foo() {\n" + + " @Illegal Y.YY.Z[] z = null;\n" + + " return z;\n" + + " }\n" + + " Y.YY.Z[] foo2() {\n" + + " Y.@Illegal YY.Z[] z = null;\n" + + " return z;\n" + + " }\n" + + " Y.YY.Z[] foo3() {\n" + + " Y.YY.@Illegal Z[] z = null;\n" + + " return z;\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " @Illegal Y.YY.Z[] z = null;\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"; + runner.javacTestOptions = EclipseJustification.EclipseBug561549; + runner.runNegativeTest(); + } + // [1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + // The test case is to validate that we report errors for only type annotations and nothing else in case of + // of parameter types. + public void test415308c() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface IllegalTypeUse {\n" + + "}\n" + + "@Target({ElementType.TYPE_USE, ElementType.PARAMETER})\n" + + "@interface LegalTypeUseParam {\n" + + "}\n" + + "@Target(ElementType.PARAMETER)\n" + + "@interface LegalParam {\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " Z() {}\n" + + " }\n" + + "}\n" + + "class X {\n" + + " Y.Z foo(@LegalParam Y.Z z) { //Legal\n" + + " return z;\n" + + " }\n" + + " Y.Z foo2(@LegalTypeUseParam Y.Z z) { //Legal\n" + + " return z;\n" + + " }\n" + + " Y.Z foo3(@IllegalTypeUse @LegalParam Y.Z z) { //Illegal\n" + + " return z;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 25)\n" + + " Y.Z foo3(@IllegalTypeUse @LegalParam Y.Z z) { //Illegal\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + //[1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + //The test case is to validate type use annotation for class fields. + public void test415308d() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Illegal {\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " Z() {}\n" + + " }\n" + + "}\n" + + "class X {\n" + + " @Illegal \n" + + " Y.Z z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " @Illegal \n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + //[1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + //The test case checks for annotations which are not exclusively TYPE_USE. We should not report a error. + public void test415308d2() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target({ElementType.TYPE_USE, ElementType.FIELD})\n" + + "@interface Legal {\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " Z() {}\n" + + " }\n" + + "}\n" + + "class X {\n" + + " @Legal \n" + + " Y.Z z;\n" + + "}\n" + }, + ""); + } + //[1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + //The test case is to validate type use annotation for class fields. + //We check all the qualifiers as we look for a static type. This test checks if we are able to + //go beyond 1 level as part of the loop. + public void test415308e() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Illegal {\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Illegal2 {\n" + + "}\n" + + "@Target(ElementType.FIELD)\n" + + "@interface Legal {\n" + + "}\n" + + "class Y {\n" + + " static class YY {\n" + + " class Z {\n" + + " Z() {}\n" + + " }\n" + + " }\n" + + "}\n" + + "class X {\n" + + " @Legal @Illegal @Illegal2\n" + + " Y.YY.Z z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 21)\n" + + " @Legal @Illegal @Illegal2\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " @Legal @Illegal @Illegal2\n" + + " ^^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + // [1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + // The test case is to validate type use annotations on return types for methods. + public void test415308f() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Illegal {\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " Z() {}\n" + + " }\n" + + "}\n" + + "class X {\n" + + " public @Illegal Y.Z foo() { return null;}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " public @Illegal Y.Z foo() { return null;}\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + // [1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + // The test case is a array version of test415308f. + public void test415308f2() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Illegal {\n" + + "}\n" + + "class Y {\n" + + " static class Z {\n" + + " Z() {}\n" + + " }\n" + + "}\n" + + "class X {\n" + + " public @Illegal Y.Z[] foo() { return null;}\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " public @Illegal Y.Z[] foo() { return null;}\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"; + runner.javacTestOptions = EclipseJustification.EclipseBug561549; + runner.runNegativeTest(); + } + // [1.8][compiler] Illegal type annotations not rejected (https://bugs.eclipse.org/bugs/show_bug.cgi?id=415308) + // The test case is used to test enums with type annotations. + public void test415308g() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Illegal {\n" + + "}\n" + + "class Y {\n" + + " enum A { B }\n" + + "}\n" + + "class X {\n" + + " @Illegal Y.A foo(@Illegal Y.A a) {\n" + + " return a;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " @Illegal Y.A foo(@Illegal Y.A a) {\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " @Illegal Y.A foo(@Illegal Y.A a) {\n" + + " ^^^^^^^^\n" + + "Type annotations are not allowed on type names used to access static members\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=418041, NPE during AST creation. + public void test418041() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import java.util.List;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Readonly {\n" + + "}\n" + + "class UnmodifiableList implements\n" + + "@Readonly List<@Readonly T> { }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.addAll(int, Collection)\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.addAll(Collection)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.lastIndexOf(Object)\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.subList(int, int)\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.contains(Object)\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.get(int)\n" + + "----------\n" + + "7. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.retainAll(Collection)\n" + + "----------\n" + + "8. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.clear()\n" + + "----------\n" + + "9. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.indexOf(Object)\n" + + "----------\n" + + "10. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.toArray(T[])\n" + + "----------\n" + + "11. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.toArray()\n" + + "----------\n" + + "12. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.isEmpty()\n" + + "----------\n" + + "13. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.listIterator(int)\n" + + "----------\n" + + "14. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.listIterator()\n" + + "----------\n" + + "15. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.add(int, T)\n" + + "----------\n" + + "16. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.add(T)\n" + + "----------\n" + + "17. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.set(int, T)\n" + + "----------\n" + + "18. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.size()\n" + + "----------\n" + + "19. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.containsAll(Collection)\n" + + "----------\n" + + "20. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.remove(int)\n" + + "----------\n" + + "21. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.remove(Object)\n" + + "----------\n" + + "22. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.removeAll(Collection)\n" + + "----------\n" + + "23. ERROR in X.java (at line 7)\n" + + " class UnmodifiableList implements\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type UnmodifiableList must implement the inherited abstract method List.iterator()\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=418041, NPE during AST creation. + public void test418041a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" + + " ^\n" + + "Y cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 1)\n" + + " public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The type parameter Q should not be bounded by the final type Integer. Final types cannot be further extended\n" + + "----------\n"); + } + public void testWildcardCapture() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import java.util.List;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface NonNull {\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Nullable {\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List<@Nullable ? extends X> lx1 = null;\n" + + " List<@NonNull ? extends X> lx2 = null;\n" + + " lx1 = lx2;\n" + + " lx1.add(lx2.get(0));\n" + + " lx1.add(lx1.get(0));\n" + + " getAdd(lx1, lx2);\n" + + " }\n" + + " static <@NonNull P> void getAdd(List

    p1, List

    p2) {\n" + + " p1.add(p2.get(0));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " lx1.add(lx2.get(0));\n" + + " ^^^\n" + + "The method add(capture#3-of ? extends X) in the type List is not applicable for the arguments (capture#4-of ? extends X)\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " lx1.add(lx1.get(0));\n" + + " ^^^\n" + + "The method add(capture#5-of ? extends X) in the type List is not applicable for the arguments (capture#6-of ? extends X)\n" + + "----------\n" + + "3. ERROR in X.java (at line 20)\n" + + " getAdd(lx1, lx2);\n" + + " ^^^^^^\n" + + "The method getAdd(List

    , List

    ) in the type X is not applicable for the arguments (List, List)\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=414038, [1.8][compiler] CCE in resolveAnnotations + public void testBug414038() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface NonNull { int[].class value() default 0;}\n" + + "public class X extends @NonNull() Object { \n" + + " public static int i = 0; \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @interface NonNull { int[].class value() default 0;}\n" + + " ^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n"); + } + public void testGenericConstructor() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {\n" + + "} \n" + + "public class X { \n" + + "\n" + + "

    @T X() {\n" + + " }\n" + + " @T

    X(X x) {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + "

    @T X() {\n" + + " ^\n" + + "Syntax error on token \"@\", delete this token\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=419833, [1.8] NPE in CompilationUnitProblemFinder and ASTNode + public void test419833() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {\n" + + "}\n" + + "class S {\n" + + "}\n" + + "interface I {\n" + + "}\n" + + "public class X extends @T S implements @T {\n" + + " public int foo() {\n" + + " return 0;\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " public class X extends @T S implements @T {\n" + + " ^\n" + + "Syntax error on token \"@\", delete this token\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=420038, [1.8][compiler] Tolerate type annotations on array dimensions of class literals for now for compatibility. + public void test420038() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Class c = int @T [].class; \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Class c = int @T [].class; \n" + + " ^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=420284, [1.8][compiler] IllegalStateException from TypeSystem.cacheDerivedType + public void test420284() { + runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " void foo(Object o) {\n" + + " Integer i = (Integer & Serializable) o;\n" + + " List<@NonNull Integer> l;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " List<@NonNull Integer> l;\n" + + " ^^^^^^^\n" + + "NonNull cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=391521, [1.8][compiler] Error highlighting is not accurate for type references with type annotations + public void test391521() { + runNegativeTest( + new String[] { + "X.java", + "class Y {}\n" + + "public class X {\n" + + " Y y1 = (@Marker Z) null;\n" + + " Y y2 = new @Marker Z();\n" + + " Y[] y3 = (@Marker Z[]) null;\n" + + " Y[] y4 = new @Marker Z[0];\n" + + " Y[] y5 = (@Marker Y.Z) null;\n" + + " Y[] y6 = new @Marker Y. Z();\n" + + " Y[] y7 = (@Marker Y.Z[]) null;\n" + + " Y[] y8 = new @Marker Y[0]. Z;\n" + + " Y[] y9 = new @Marker Y. Z[0];\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker{}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y y1 = (@Marker Z) null;\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Y y2 = new @Marker Z();\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Y[] y3 = (@Marker Z[]) null;\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Y[] y4 = new @Marker Z[0];\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " Y[] y5 = (@Marker Y.Z) null;\n" + + " ^^^\n" + + "Y.Z cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " Y[] y6 = new @Marker Y. Z();\n" + + " ^^^^^\n" + + "Y.Z cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 9)\n" + + " Y[] y7 = (@Marker Y.Z[]) null;\n" + + " ^^^\n" + + "Y.Z cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 10)\n" + + " Y[] y8 = new @Marker Y[0]. Z;\n" + + " ^\n" + + "Z cannot be resolved or is not a field\n" + + "----------\n" + + "9. ERROR in X.java (at line 11)\n" + + " Y[] y9 = new @Marker Y. Z[0];\n" + + " ^^^^^\n" + + "Y.Z cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=414038, [1.8][compiler] CCE in resolveAnnotations + public void test414038() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface NonNull { int[].class value() default 0;}\n" + + "public class X extends @NonNull() Object { \n" + + " public static int i = 0; \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @interface NonNull { int[].class value() default 0;}\n" + + " ^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n", + true); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421791, [1.8][compiler] TYPE_USE annotations should be allowed on annotation type declarations + public void test421791() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {}\n" + + "@T\n" + + "@interface T2 {}\n" + + "public class X {}\n" + }, + "", + true); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=424977, [1.8][compiler]ArrayIndexIndexOutOfBoundException in annotated wrong<> code + public void testBug426977() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "public class X {\n" + + " test.@A Outer<>.@A Inner<> i;\n" + + "}\n" + + "class Outer {\n" + + " class Inner {}\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface A {}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " test.@A Outer<>.@A Inner<> i;\n" + + " ^^^^^^^^^^^^^\n" + + "Incorrect number of arguments for type Outer; it cannot be parameterized with arguments <>\n" + + "----------\n", + null, + true, + customOptions); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=424977, [1.8][compiler] ArrayIndexIndexOutOfBoundException in annotated wrong<> code + public void testBug426977a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + runNegativeTest( + new String[] { + "test/X.java", + "package test;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "public class X {\n" + + " test.@A Outer.@A Inner<> i;\n" + + "}\n" + + "class Outer {\n" + + " class Inner {}\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface A {}\n" + }, + "----------\n" + + "1. ERROR in test\\X.java (at line 6)\n" + + " test.@A Outer.@A Inner<> i;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type Outer.Inner is not generic; it cannot be parameterized with arguments <>\n" + + "----------\n", + null, + true, + customOptions); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=425599, [1.8][compiler] ISE when trying to compile qualified and annotated class instance creation + public void test425599() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "public class X {\n" + + " Object ax = new @A Outer().new Middle();\n" + + "}\n" + + "@Target(ElementType.TYPE_USE) @interface A {}\n" + + "class Outer {\n" + + " class Middle {}\n" + + "}\n" + }, + "", + null, + true, + customOptions); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427955, [1.8][compiler] NPE in TypeSystem.getUnannotatedType + public void test427955() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * @param unused\n" + + " * @param unused\n" + + " */\n" + + "public class X {}\n" + + "class Outer {\n" + + " void method() {\n" + + " //Internal compiler error: java.lang.NullPointerException at\n" + + " // org.eclipse.jdt.internal.compiler.lookup.TypeSystem.getUnannotatedType(TypeSystem.java:76)\n" + + " new Inner<>(null);\n" + + " }\n" + + " final class Inner {\n" + + " /**\n" + + " * @param next unused \n" + + " */\n" + + " Inner(Inner next) {}\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + customOptions); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=419827, [1.8] Annotation with TYPE_USE as target is not allowed to use container with target TYPE + public void test419827a() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Repeatable;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target({ElementType.TYPE_USE})\n" + + "@Repeatable(FooContainer.class)\n" + + "@interface Foo {}\n" + + "@Target({ElementType.TYPE, ElementType.TYPE_USE})\n" + + "@interface FooContainer {\n" + + " Foo[] value();\n" + + "}\n" + + "public class X{}\n" + }, + "", + true); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=419827, [1.8] Annotation with TYPE_USE as target is not allowed to use container with target TYPE + // Although the target of FooContainer is different from that of Foo, Foo container cannot be used in any place where + // Foo can't be used. + public void test419827b() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Repeatable;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target({ElementType.TYPE_USE})\n" + + "@Repeatable(FooContainer.class)\n" + + "@interface Foo {}\n" + + "@Target({ElementType.TYPE})\n" + + "@interface FooContainer {\n" + + " Foo[] value();\n" + + "}\n" + + "public class X{}\n" + }, + "", + true); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NonFatalErrorTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NonFatalErrorTest.java new file mode 100644 index 0000000000..a230a29426 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NonFatalErrorTest.java @@ -0,0 +1,590 @@ +/******************************************************************************* + * Copyright (c) 2000, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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 org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class NonFatalErrorTest extends AbstractRegressionTest { + public NonFatalErrorTest(String name) { + super(name); + } + // 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[] { "test127" }; +// TESTS_NUMBERS = new int[] { 7 }; +// TESTS_RANGE = new int[] { 169, 180 }; + } + + public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); + } + + public static Class testClass() { + return NonFatalErrorTest.class; + } + + public void test001() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_FatalOptionalError, CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 1)\n" + + " import java.util.*;\n" + + " ^^^^^^^^^\n" + + "The import java.util is never used\n" + + "----------\n", + // runtime results + "SUCCESS" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + } + + public void test002() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_FatalOptionalError, CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 1)\n" + + " import java.util.*;\n" + + " ^^^^^^^^^\n" + + "The import java.util is never used\n" + + "----------\n", + // runtime results + "" /* expected output string */, + "java.lang.Error: Unresolved compilation problem: \n" + /* expectedErrorString */ + "\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + } + + public void test003() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_FatalOptionalError, CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(\"SUCCESS\");\n" + + " ^^^^^^^^^\n" + + "Non-externalized string literal; it should be followed by //$NON-NLS-$\n" + + "----------\n", + // runtime results + "SUCCESS" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + } + + public void test004() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_FatalOptionalError, CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_ReportUndocumentedEmptyBlock, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void foo() {}\n" + + " public static void main(String argv[]) {\n" + + " foo();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " public static void foo() {}\n" + + " ^^\n" + + "Empty block should be documented\n" + + "----------\n", + // runtime results + "SUCCESS" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + } + + public void test005() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_FatalOptionalError, CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUndocumentedEmptyBlock, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void foo() {}\n" + + " public static void main(String argv[]) {\n" + + " foo();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " public static void foo() {}\n" + + " ^^\n" + + "Empty block should be documented\n" + + "----------\n", + // runtime results + "" /* expected output string */, + "java.lang.Error: Unresolved compilation problem: \n" + /* expectedErrorString */ + " Empty block should be documented\n" + + "\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=319626 + public void test006() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_FatalOptionalError, CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_ReportUndocumentedEmptyBlock, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " { }\n" + + " static { }\n" + + " X() { }\n" + + " X(int a) {}\n" + + " public void foo() {}\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " { }\n" + + " ^^^^^^^\n" + + "Empty block should be documented\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " static { }\n" + + " ^^^^\n" + + "Empty block should be documented\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " X(int a) {}\n" + + " ^^\n" + + "Empty block should be documented\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " public void foo() {}\n" + + " ^^\n" + + "Empty block should be documented\n" + + "----------\n", + // runtime results + "SUCCESS" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + } + public void test007() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_FatalOptionalError, + CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, + CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressWarnings, + CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, + CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, + CompilerOptions.ERROR); + runConformTest( + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"unused\")\n" + + " static void foo() {\n" + + " String s = null;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " foo();\n" + + " }\n" + + "}" + }, + "SUCCESS" /* expected output string */, + null /* no class libraries */, + true, + null, + customOptions /* custom options */, + // compiler results + null /* do not check error string */); + } + public void testImportUnresolved() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_IMPORT, JavaCore.ERROR); + runNegativeTest( + true, // flush dir + new String[] { + "X.java", + "import com.bogus.Missing;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().test();\n" + + " }\n" + + " void test() {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + null, // libs + options, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import com.bogus.Missing;\n" + + " ^^^^^^^^^\n" + + "The import com.bogus cannot be resolved\n" + + "----------\n", + "OK", + "", + JavacTestOptions.SKIP); + } + public void testImportUnresolved_fatal() { + Map options = getCompilerOptions(); + try { + options.put(JavaCore.COMPILER_PB_UNUSED_IMPORT, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_FATAL_OPTIONAL_ERROR, JavaCore.ENABLED); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runNegativeTest( + true, // flush dir + new String[] { + "p/Z.java", + "package p;\n" + + "public class Z {\n" + + " public static void main(String[] args) throws Exception {\n" + + " try {\n" + + " Class.forName(\"X\").newInstance();\n" + // forward reference, workaround by using reflection + " } catch (java.lang.Error e) {\n" + + " System.err.println(e.getMessage());\n" + + " }\n" + + " }\n" + + "}\n", + "X.java", + "import com.bogus.Missing;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().test();\n" + + " }\n" + + " void test() {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + null, // libs + options, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import com.bogus.Missing;\n" + + " ^^^^^^^^^\n" + + "The import com.bogus cannot be resolved\n" + + "----------\n", + "", + "Unresolved compilation problem: \n" + + " The import com.bogus cannot be resolved", + JavacTestOptions.SKIP); + } finally { + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + } + } + public void testPackageConflict() { + Map options = getCompilerOptions(); + try { + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + + runNegativeTest( + true, // flush dir + new String[] { + "p/z.java", + "package p;\n" + + "public class z {\n" + + " public static void main(String[] args) throws Exception {\n" + + " try {\n" + + " Class.forName(\"p.z.X\").newInstance();\n" + + " } catch (ClassNotFoundException e) {\n" + + " System.out.println(e.getClass().getName());\n" + + " }\n" + + " }\n" + + "}\n", + "p/z/X.java", + "package p.z;\n" + + "public class X {\n" + + " public X() {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n", + }, + null, // libs + options, + "----------\n" + + "1. ERROR in p\\z\\X.java (at line 1)\n" + + " package p.z;\n" + + " ^^^\n" + + "The package p.z collides with a type\n" + + "----------\n", + "java.lang.ClassNotFoundException", // cannot generate code in presence of the above error + "", + JavacTestOptions.SKIP); + } finally { + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + } + } + public void testImportVariousProblems() { + Map options = getCompilerOptions(); + try { + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + + runNegativeTest( + true, // flush dir + new String[] { + "p/Z.java", + "package p;\n" + + "public class Z {\n" + + " public static void main(String[] args) throws Exception {\n" + + " try {\n" + + " Class.forName(\"X\").newInstance();\n" + // forward reference, workaround by using reflection + " } catch (ClassNotFoundException e) {\n" + + " System.out.println(e.getClass().getName());\n" + + " }\n" + + " }\n" + + "}\n", + "p1/Y.java", + "package p1;\n" + + "public class Y {}\n", + "p2/Y.java", + "package p2;\n" + + "public class Y {}\n", + "X.java", + "import java.util;\n" + + "import p.Z;\n" + + "import p1.Y;\n" + + "import p2.Y;\n" + + "public class X {\n" + + " public X() {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + + "class Z {}\n" + }, + null, // libs + options, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import java.util;\n" + + " ^^^^^^^^^\n" + + "Only a type can be imported. java.util resolves to a package\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " import p.Z;\n" + + " ^^^\n" + + "The import p.Z conflicts with a type defined in the same file\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " import p2.Y;\n" + + " ^^^^\n" + + "The import p2.Y collides with another import statement\n" + + "----------\n", + "OK", + "", + JavacTestOptions.SKIP); + } finally { + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + } + } + public void testImportStaticProblems() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses static imports + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runNegativeTest( + true, // flush dir + new String[] { + "p/Z.java", + "package p;\n" + + "public class Z {\n" + + " public static void main(String[] args) throws Exception {\n" + + " try {\n" + + " Class.forName(\"X\").newInstance();\n" + // forward reference, workaround by using reflection + " } catch (ClassNotFoundException e) {\n" + + " System.out.println(e.getClass().getName());\n" + + " }\n" + + " }\n" + + "}\n", + "p1/Y.java", + "package p1;\n" + + "public class Y {\n" + + " static int f;\n" + + "}\n", + "X.java", + "import static p1.Y;\n" + + "import static p1.Y.f;\n" + + "public class X {\n" + + " public X() {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + + "class Z {}\n" + }, + null, // libs + options, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static p1.Y;\n" + + " ^^^^\n" + + "The static import p1.Y must be a field or member type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " import static p1.Y.f;\n" + + " ^^^^^^\n" + + "The field Y.p1.Y.f is not visible\n" + + "----------\n", + "OK", + "", + JavacTestOptions.SKIP); + } + public void testDuplicateImports1() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses static imports + runConformTest( + new String[] { + "Test.java", + "import java.lang.Character.Subset;\n" + + "import static java.lang.Character.Subset;\n" + + "\n" + + "public class Test {\n" + + " Subset s = null;\n" + + "}\n" + }); + } + public void testDuplicateImports2() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses static imports + runConformTest( + new String[] { + "Test.java", + "import static java.awt.geom.Line2D.Double;\n" + + "import static java.awt.geom.Line2D.Double;\n" + + "\n" + + "public class Test {\n" + + " Double d = null;\n" + + "}\n" + }); + } + public void testDuplicateImports3() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses static imports + runNegativeTest( + new String[] { + "Test.java", + // JLS doesn't really allow this duplication, but also javac defers the error to the use site, see: + // https://bugs.openjdk.java.net/browse/JDK-8133619?focusedCommentId=14133759&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14133759 + "import static java.awt.geom.Line2D.Double;\n" + + "import static java.awt.geom.Point2D.Double;\n" + + "\n" + + "public class Test {\n" + + " Double d = null;\n" + + "}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " import static java.awt.geom.Point2D.Double;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import java.awt.geom.Point2D.Double collides with another import statement\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in Test.java (at line 5)\n" + + " Double d = null;\n" + + " ^^^^^^\n" + + "The type Double is ambiguous\n" + + "----------\n")); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationBatchCompilerTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationBatchCompilerTest.java new file mode 100644 index 0000000000..ff78e89143 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationBatchCompilerTest.java @@ -0,0 +1,1119 @@ +/******************************************************************************* + * Copyright (c) 2017 GK Software AG and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jdt.core.tests.util.Util; + +import junit.framework.Test; + +public class NullAnnotationBatchCompilerTest extends AbstractBatchCompilerTest { + + protected static final String NONNULL_BY_DEFAULT_ANNOTATION_CONTENT = "package org.eclipse.jdt.annotation;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" + + "public @interface NonNullByDefault{\n" + + "}"; + protected static final String NULLABLE_ANNOTATION_CONTENT = "package org.eclipse.jdt.annotation;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER, FIELD })\n" + + "public @interface Nullable{\n" + + "}\n"; + protected static final String NONNULL_ANNOTATION_CONTENT = "package org.eclipse.jdt.annotation;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER, FIELD })\n" + + "public @interface NonNull{\n" + + "}\n"; + protected static final String ELEMENT_TYPE_18_CONTENT = "package java.lang.annotation;\n" + + "public enum ElementType {\n" + + " TYPE,\n" + + " FIELD,\n" + + " METHOD,\n" + + " PARAMETER,\n" + + " CONSTRUCTOR,\n" + + " LOCAL_VARIABLE,\n" + + " ANNOTATION_TYPE,\n" + + " PACKAGE,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_USE\n" + + "}\n" + + ""; + protected static final String NONNULL_ANNOTATION_18_CONTENT = "package org.eclipse.jdt.annotation;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.*;\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ ElementType.TYPE_USE })\n" + + "public @interface NonNull{\n" + + "}\n"; + protected static final String NULLABLE_ANNOTATION_18_CONTENT = "package org.eclipse.jdt.annotation;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.*;\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ ElementType.TYPE_USE })\n" + + "public @interface Nullable{\n" + + "}\n"; + protected static final String NONNULL_BY_DEFAULT_ANNOTATION_18_CONTENT = "package org.eclipse.jdt.annotation;\n" + + "import java.lang.annotation.ElementType;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" + + "\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE })\n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" + + "}\n"; + protected static final String DEFAULT_LOCATION_CONTENT = "package org.eclipse.jdt.annotation;\n" + + "public enum DefaultLocation {\n" + + " PARAMETER,\n" + + " RETURN_TYPE,\n" + + " FIELD,\n" + + " TYPE_PARAMETER,\n" + + " TYPE_BOUND,\n" + + " TYPE_ARGUMENT,\n" + + " ARRAY_CONTENTS\n" + + "}\n"; + + static { +// TESTS_NAMES = new String[] { "test490010NoEeaFile" }; +// TESTS_NUMBERS = new int[] { 306 }; +// TESTS_RANGE = new int[] { 298, -1 }; + } + + /** + * This test suite only needs to be run on one compliance. + * As it includes some specific 1.5 tests, it must be used with a least a 1.5 VM + * and not be duplicated in general test suite. + * @see TestAll + */ + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); + } + + public static Class testClass() { + return NullAnnotationBatchCompilerTest.class; + } + + public NullAnnotationBatchCompilerTest(String name) { + super(name); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + Util.delete(OUTPUT_DIR); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342 + // -err option - regression tests to check option nullAnnot + // Null warnings because of annotations, null spec violations plus one specific problem configured as errors + public void test314_warn_options() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -err:+nullAnnot -warn:-null -err:+nonnullNotRepeated -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.foo(Object, Object) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^\n" + + "Missing nullable annotation: inherited method from X specifies this parameter as @Nullable\n" + + "----------\n" + + "3. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "3 problems (3 errors)\n", + true); + } + + // -warn option - regression tests to check option nullAnnot and missingNullDefault + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=372012 + public void test315_warn_options() { + this.runConformTest( + new String[] { + "p/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p;\n", + "p/X.java", + "package p;\n" + + "public class X {\n" + + "}\n", + "p1/X1.java", + "package p1;\n" + + "public class X1 {\n" + + "}\n", + "p1/X1a.java", + "package p1;\n" + + "public class X1a {\n" + + "}\n", + "Default1.java", + "public class Default1 {\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+nullAnnot -warn:+null -missingNullDefault -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + } + + // -warn option - regression tests to check option nullAnnot and missingNullDefault + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=372012 + public void test315_warn_options_a() { + this.runConformTest( + new String[] { + "p1/X1.java", + "package p1;\n" + + "public class X1 {\n" + + " class Inner{};\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p1" + File.separator + "X1.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+nullAnnot -warn:+null -missingNullDefault -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p1/X1.java (at line 1)\n" + + " package p1;\n" + + " ^^\n" + + "A default nullness annotation has not been specified for the package p1\n" + + "----------\n" + + "1 problem (1 warning)\n", + true); + } + + // -warn option - regression tests to check option nullAnnot and missingNullDefault + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=372012 + public void test315_warn_options_b() { + this.runNegativeTest( + new String[] { + "X1.java", + "public class X1 {\n" + + " Zork z;\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "X1.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+nullAnnot -warn:+null -missingNullDefault -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X1.java (at line 1)\n" + + " public class X1 {\n" + + " ^^\n" + + "A default nullness annotation has not been specified for the type X1\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X1.java (at line 2)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2 problems (1 error, 1 warning)\n", + true); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342 + // -warn option - regression tests to check option nullAnnot + // option syntax error + public void test316_warn_options() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@SuppressWarnings(\"unused\")\n" + + "public class X {}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+nullAnnot(foo|bar) -warn:+null -nonNullByDefault -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "Token nullAnnot(foo|bar) is not in the expected format \"nullAnnot( | | )\"\n", + true); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=408815 + // -warn option - regression tests to check option syntacticAnalysis + // Null warnings because of annotations, null spec violations, suppressed by null-check + public void test316b_warn_options() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object f;\n" + + " @NonNull Object foo() {\n" + + " if (this.f != null)\n" + + " return this.f;\n" + + " return this;\n" + + " }\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+nullAnnot -warn:+null,syntacticAnalysis -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342 + // -warn option - regression tests to check option nullAnnot (no args) + // Null warnings because of annotations, null spec violations + public void test313_warn_options() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+nullAnnot -warn:-null -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.foo(Object, Object) (mismatching null constraints)\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^\n" + + "Missing nullable annotation: inherited method from X specifies this parameter as @Nullable\n" + + "----------\n" + + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "3 problems (3 warnings)\n", + true); + } + + // Bug 388281 - [compiler][null] inheritance of null annotations as an option + // -warn option - regression tests to check option inheritNullAnnot + public void test320_warn_options() { + this.runNegativeTest( + new String[] { + "p/Super.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Super {\n" + + " void foo(@NonNull String s) {}\n" + + "}\n", + "p/Sub.java", + "package p;\n" + + "public class Sub extends Super {\n" + + " void foo(String s) {\n" + + " s= null;\n" + // illegal since s inherits @NonNull + " super.foo(s);\n" + // legal + " }\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "Sub.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -err:+nullAnnot,+null,+inheritNullAnnot -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/Sub.java (at line 4)\n" + + " s= null;\n" + + " ^^^^\n" + + "Null type mismatch: required '@NonNull String' but the provided value is null\n" + + "----------\n" + + "1 problem (1 error)\n", + true); + } + + // -warn option - test multiple sets of null annotations + public void testBug466291() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " public Object foo(@Nullable Object o, Object o2) {\n" + + " return new Object();\n" + + " }\n" + + " public Object bar() {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface NonNull{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface Nullable{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" + + "@interface NonNullByDefault{\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -1.5" + + " -warn:+nullAnnot(p.Nullable|p.NonNull|p.NonNullByDefault) -warn:+null -warn:-nullUncheckedConversion " + + "-proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + + // test twice: 1. against SourceTypeBinding(p.X), 2. against BinaryTypeBinding(p.X): + for (int i=0; i<2; i++) { + this.runNegativeTest( + new String[] { + "p2/X2.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X2 {\n" + + " @NonNull Object test(@NonNull p.X nonnullX, @Nullable p.X nullableX) {\n" + + " nonnullX.foo(nullableX, nullableX);\n" + + " return nonnullX.bar();\n" + + " }\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p2" + File.separator + "X2.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -classpath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+nullAnnot(org.eclipse.jdt.annotation.Nullable|org.eclipse.jdt.annotation.NonNull|org.eclipse.jdt.annotation.NonNullByDefault)" + + " -warn:+nullAnnot(p.Nullable||p.NonNullByDefault) -warn+null -proc:none -d \"" + OUTPUT_DIR + "\"", // nonnull remains unset for secondaries + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p2/X2.java (at line 5)\n" + + " nonnullX.foo(nullableX, nullableX);\n" + + " ^^^^^^^^^\n" + + "Null type mismatch: required '@NonNull Object' but the provided value is specified as @Nullable\n" + + "----------\n" + + "1 problem (1 error)\n", + false); + // force reading of BinaryTypeBinding(p.X): + String xPath = OUTPUT_DIR + File.separator + "p" + File.separator + "X.java"; + new File(xPath).delete(); + } + } + + //-warn option - test multiple sets of null annotations, three (partial) sets of secondary annotations + public void testBug466291b() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " public Object foo(@Nullable Object o, Object o2) {\n" + + " return new Object();\n" + + " }\n" + + " public Object bar() {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface NonNull{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ METHOD, PARAMETER })\n" + + "@interface Nullable{\n" + + "}\n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ PACKAGE, TYPE, METHOD, CONSTRUCTOR })\n" + + "@interface NonNullByDefault{\n" + + "}" + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -1.5" + + " -warn:+nullAnnot(p.Nullable|p.NonNull|p.NonNullByDefault) -warn:+null -warn:-nullUncheckedConversion " + + "-proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "", + true); + + // force reading of BinaryTypeBinding(p.X): + String xPath = OUTPUT_DIR + File.separator + "p" + File.separator + "X.java"; + new File(xPath).delete(); + + this.runNegativeTest( + new String[] { + "p2/X2.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X2 {\n" + + " @NonNull Object test(@NonNull p.X nonnullX, @Nullable p.X nullableX) {\n" + + " nonnullX.foo(nullableX, nullableX);\n" + + " return nonnullX.bar();\n" + + " }\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p2" + File.separator + "X2.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -classpath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -warn:+nullAnnot(org.eclipse.jdt.annotation.Nullable|org.eclipse.jdt.annotation.NonNull|org.eclipse.jdt.annotation.NonNullByDefault)" + + " -warn:+nullAnnot(|x.AbsentNonNull|) " + + " -warn:+nullAnnot(p.Nullable||p.NonNullByDefault) " + + " -warn:+nullAnnot(yet.AnotherNullable|yet.AnotherNonnull|yet.anotherNNBD) " + + " -warn+null -proc:none -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p2/X2.java (at line 5)\n" + + " nonnullX.foo(nullableX, nullableX);\n" + + " ^^^^^^^^^\n" + + "Null type mismatch: required '@NonNull Object' but the provided value is specified as @Nullable\n" + + "----------\n" + + "1 problem (1 error)\n", + false); + } + + // == Variants of org.eclipse.jdt.core.tests.compiler.regression.BatchCompilerTest.testBug375366a(): == + + // Bug 375366 - ECJ ignores unusedParameterIncludeDocCommentReference unless enableJavadoc option is set + // property file enables null annotation support + public void testBug375366c() throws IOException { + createOutputTestDirectory("regression/.settings"); + Util.createFile(OUTPUT_DIR+"/.settings/org.eclipse.jdt.core.prefs", + "eclipse.preferences.version=1\n" + + "org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled\n"); + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -properties " + OUTPUT_DIR + File.separator +".settings" + File.separator + "org.eclipse.jdt.core.prefs " + + " -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.foo(Object, Object) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^\n" + + "Missing nullable annotation: inherited method from X specifies this parameter as @Nullable\n" + + "----------\n" + + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "3 problems (2 errors, 1 warning)\n", + false/*don't flush*/); + } + + // Bug 375366 - ECJ ignores unusedParameterIncludeDocCommentReference unless enableJavadoc option is set + // property file enables null annotation support, one optional warning disabled + public void testBug375366d() throws IOException { + createOutputTestDirectory("regression/.settings"); + Util.createFile(OUTPUT_DIR+"/.settings/org.eclipse.jdt.core.prefs", + "eclipse.preferences.version=1\n" + + "org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled\n" + + "org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=ignore\n"); + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object foo(@Nullable Object o, @NonNull Object o2) {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + "}\n", + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_CONTENT + }, + "\"" + OUTPUT_DIR + File.separator + "p" + File.separator + "X.java\"" + + " -sourcepath \"" + OUTPUT_DIR + "\"" + + " -1.5" + + " -properties " + OUTPUT_DIR + File.separator +".settings" + File.separator + "org.eclipse.jdt.core.prefs " + + " -d \"" + OUTPUT_DIR + "\"", + "", + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.foo(Object, Object) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/p/X.java (at line 9)\n" + + " @Nullable Object foo(Object o, Object o2) { return null; }\n" + + " ^^^^^^\n" + + "Missing nullable annotation: inherited method from X specifies this parameter as @Nullable\n" + + "----------\n" + + "2 problems (2 errors)\n", + false/*don't flush*/); + } + + // Bug 440477 - [null] Infrastructure for feeding external annotations into compilation + // - single external annotation directory + public void test440477() throws IOException { + String annots_dir = Util.getOutputDirectory() + File.separator + "annots"; + String annots_java_util = annots_dir + File.separator + "java/util"; + new File(annots_java_util).mkdirs(); + Util.createFile( + annots_java_util + File.separator + "Map.eea", + TEST_440687_MAP_EEA_CONTENT); + + String o_e_j_annotation_dir = OUTPUT_DIR + File.separator + + "org" + File.separator + "eclipse" + File.separator + "jdt" + File.separator + "annotation"; + String j_l_annotation_dir = OUTPUT_DIR + File.separator + + "java" + File.separator + "lang" + File.separator + "annotation"; + this.runConformTest( + new String[] { + "java/lang/annotation/ElementType.java", + ELEMENT_TYPE_18_CONTENT, + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_18_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_18_CONTENT, + "org/eclipse/jdt/annotation/DefaultLocation.java", + DEFAULT_LOCATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_18_CONTENT, + "test1/Test1.java", + "package test1;\n" + + "\n" + + "import java.util.Map;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test1 {\n" + + " void test(Map map, String key) {\n" + + " Test1 v = map.get(key);\n" + + " if (v == null)\n" + + " throw new RuntimeException(); // should not be reported as dead code, although V is a '@NonNull Test1'\n" + + " }\n" + + "}\n" + }, + " -1.8 -proc:none -d none -warn:+nullAnnot -annotationpath " + annots_dir + + " -sourcepath \"" + OUTPUT_DIR + "\" " + + // explicitly mention all files to ensure a good order, cannot pull in source of NNBD on demand + "\"" + j_l_annotation_dir + File.separator + "ElementType.java\" " + + "\"" + o_e_j_annotation_dir + File.separator + "NonNull.java\" " + + "\"" + o_e_j_annotation_dir + File.separator + "DefaultLocation.java\" " + + "\"" + o_e_j_annotation_dir + File.separator + "NonNullByDefault.java\" " + + "\"" + OUTPUT_DIR + File.separator + "test1" + File.separator + "Test1.java\"", + "", + "", + true); + } + // file content for tests below: + private static final String TEST_440687_MAP_EEA_CONTENT = + "class java/util/Map\n" + + " \n" + + "\n" + + "get\n" + + " (Ljava/lang/Object;)TV;\n" + + " (Ljava/lang/Object;)T0V;\n" + + "put\n" + + " (TK;TV;)TV;\n" + + " (TK;TV;)T0V;\n" + + "remove\n" + + " (Ljava/lang/Object;)TV;\n" + + " (Ljava/lang/Object;)T0V;\n"; + private static final String TEST_440687_OBJECT_EEA_CONTENT = + "class java/lang/Object\n" + + "\n" + + "equals\n" + + " (Ljava/lang/Object;)Z\n" + + " (L0java/lang/Object;)Z\n"; + // Bug 440687 - [compiler][batch][null] improve command line option for external annotations + // work horse for tests below + void runTest440687(String compilerPathArgs, String extraSourcePaths, String expectedCompilerMessage, boolean isSuccess) { + + String[] testFiles = new String[] { + "java/lang/annotation/ElementType.java", + ELEMENT_TYPE_18_CONTENT, + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_18_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_18_CONTENT, + "org/eclipse/jdt/annotation/DefaultLocation.java", + DEFAULT_LOCATION_CONTENT, + "org/eclipse/jdt/annotation/NonNullByDefault.java", + NONNULL_BY_DEFAULT_ANNOTATION_18_CONTENT, + "test1/Test1.java", + "package test1;\n" + + "\n" + + "import java.util.Map;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test1 {\n" + + " void test(Map map, String key) {\n" + + " Test1 v = map.get(key);\n" + + " if (v == null)\n" + + " throw new RuntimeException(); // should not be reported as dead code, although V is a '@NonNull Test1'\n" + + " }\n" + + " public boolean equals(@NonNull Object other) { return false; }\n" + + "}\n" + }; + + String o_e_j_annotation_dir = OUTPUT_DIR + File.separator + + "org" + File.separator + "eclipse" + File.separator + "jdt" + File.separator + "annotation"; + String j_l_annotation_dir = OUTPUT_DIR + File.separator + + "java" + File.separator + "lang" + File.separator + "annotation"; + + String commandLine = " -1.8 -proc:none -d none -warn:+nullAnnot " + compilerPathArgs + + " -sourcepath \"" + OUTPUT_DIR + extraSourcePaths + "\" " + + // explicitly mention all files to ensure a good order, cannot pull in source of NNBD on demand + "\"" + j_l_annotation_dir + File.separator + "ElementType.java\" " + + "\"" + o_e_j_annotation_dir + File.separator + "NonNull.java\" " + + "\"" + o_e_j_annotation_dir + File.separator + "DefaultLocation.java\" " + + "\"" + o_e_j_annotation_dir + File.separator + "NonNullByDefault.java\" " + + "\"" + OUTPUT_DIR + File.separator + "test1" + File.separator + "Test1.java\""; + + if (expectedCompilerMessage == null) + expectedCompilerMessage = + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 13)\n" + + " public boolean equals(@NonNull Object other) { return false; }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter other, inherited method from Object declares this parameter as @Nullable\n" + + "----------\n" + + "1 problem (1 warning)\n"; + try { + if (isSuccess) + this.runConformTest(testFiles, commandLine, "", expectedCompilerMessage, true); + else + this.runNegativeTest(testFiles, commandLine, "", expectedCompilerMessage, true); + } finally { + Util.delete(Util.getOutputDirectory()); + } + } + // Bug 440687 - [compiler][batch][null] improve command line option for external annotations + // - two external annotation directories as part of the sourcepath/classpath + public void test440687a() throws IOException { + + String annots_dir1 = Util.getOutputDirectory() + File.separator + "annots1"; + String annots_java_util = annots_dir1 + File.separator + "java/util"; + new File(annots_java_util).mkdirs(); + Util.createFile(annots_java_util + File.separator + "Map.eea", + TEST_440687_MAP_EEA_CONTENT); + + String annots_dir2 = Util.getOutputDirectory() + File.separator + "annots2"; + String annots_java_lang = annots_dir2 + File.separator + "java/lang"; + new File(annots_java_lang).mkdirs(); + Util.createFile(annots_java_lang + File.separator + "Object.eea", + TEST_440687_OBJECT_EEA_CONTENT); + + runTest440687("-annotationpath CLASSPATH -classpath \"" + annots_dir2 + "\"", + File.pathSeparator + annots_dir1, // extra source path + null, // expect normal error + true); + } + // Bug 440687 - [compiler][batch][null] improve command line option for external annotations + // - two external annotation directories specifically configured. + public void test440687b() throws IOException { + + String annots_dir = Util.getOutputDirectory() + File.separator + "annots1"; + String annots_java_util = annots_dir + File.separator + "java/util"; + new File(annots_java_util).mkdirs(); + Util.createFile( + annots_java_util + File.separator + "Map.eea", + TEST_440687_MAP_EEA_CONTENT); + + String annots_dir2 = Util.getOutputDirectory() + File.separator + "annots2"; + String annots_java_lang = annots_dir2 + File.separator + "java/lang"; + new File(annots_java_lang).mkdirs(); + Util.createFile( + annots_java_lang + File.separator + "Object.eea", + TEST_440687_OBJECT_EEA_CONTENT); + + runTest440687("-annotationpath \"" + annots_dir + File.pathSeparator + annots_dir2 + "\" ", + "", // no extra source path + null, // expect normal error + true); + } + // Bug 440687 - [compiler][batch][null] improve command line option for external annotations + // - single external annotation zip with 2 entries + public void test440687c() throws IOException { + + String annots_dir = Util.getOutputDirectory() + File.separator + "annots"; + new File(annots_dir).mkdirs(); + String annotsZipFile = annots_dir+ File.separator + "jre-annots.zip"; + Util.createSourceZip( + new String[] { + "java/util/Map.eea", + TEST_440687_MAP_EEA_CONTENT, + "java/lang/Object.eea", + TEST_440687_OBJECT_EEA_CONTENT + }, + annotsZipFile); + + runTest440687("-annotationpath CLASSPATH -classpath \"" + annotsZipFile + "\"", + "", // no extra source path + null, // expect normal error + true); + } + // Bug 440687 - [compiler][batch][null] improve command line option for external annotations + // - missing argument after -annotationpath + public void test440687d() throws IOException { + runTest440687("-annotationpath", // missing argument + "", + "Missing argument to -annotationpath at \'-sourcepath\'\n", + false); + } + + // project is configured for eea (directory on classpath), but no specific file for Map found + public void test490010NoEeaFile1() throws IOException { + + String annots_dir1 = Util.getOutputDirectory() + File.separator + "annots1"; + new File(annots_dir1).mkdirs(); + + String annots_dir2 = Util.getOutputDirectory() + File.separator + "annots2"; + String annots_java_lang = annots_dir2 + File.separator + "java/lang"; + new File(annots_java_lang).mkdirs(); + Util.createFile(annots_java_lang + File.separator + "Object.eea", + TEST_440687_OBJECT_EEA_CONTENT); + + runTest440687("-annotationpath CLASSPATH -classpath \"" + annots_dir2 + "\"", + File.pathSeparator + annots_dir1, // extra source path + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 9)\n" + + " Test1 v = map.get(key);\n" + + " ^^^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Map<@NonNull String,@NonNull Test1>\'. Type \'Map\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 11)\n" + + " throw new RuntimeException(); // should not be reported as dead code, although V is a \'@NonNull Test1\'\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 13)\n" + + " public boolean equals(@NonNull Object other) { return false; }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter other, inherited method from Object declares this parameter as @Nullable\n" + + "----------\n" + + "3 problems (3 warnings)\n", + true); + } + + // project is configured for eea (jar on classpath), but no specific file for Map found + public void test490010NoEeaFile2() throws IOException { + + String annots_dir1 = Util.getOutputDirectory() + File.separator + "annots1"; + new File(annots_dir1).mkdirs(); + + String annots_dir2 = Util.getOutputDirectory() + File.separator + "annots2"; + String annots_java_lang = annots_dir2 + File.separator + "java/lang"; + new File(annots_java_lang).mkdirs(); + Util.createFile(annots_java_lang + File.separator + "Object.eea", + TEST_440687_OBJECT_EEA_CONTENT); + String zipName = Util.getOutputDirectory() + File.separator + "annots2.zip"; + Util.zip(new File(annots_dir2), zipName); + Util.delete(annots_dir2); + + runTest440687("-annotationpath CLASSPATH -classpath \"" + zipName + "\"", + File.pathSeparator + annots_dir1, // extra source path + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 9)\n" + + " Test1 v = map.get(key);\n" + + " ^^^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Map<@NonNull String,@NonNull Test1>\'. Type \'Map\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 11)\n" + + " throw new RuntimeException(); // should not be reported as dead code, although V is a \'@NonNull Test1\'\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 13)\n" + + " public boolean equals(@NonNull Object other) { return false; }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter other, inherited method from Object declares this parameter as @Nullable\n" + + "----------\n" + + "3 problems (3 warnings)\n", + true); + } + + // project is configured for eea (dedicated annotation zip), but no specific file for Map found + public void test490010NoEeaFile3() throws IOException { + + String annots_dir1 = Util.getOutputDirectory() + File.separator + "annots1"; + new File(annots_dir1).mkdirs(); + + String annots_dir2 = Util.getOutputDirectory() + File.separator + "annots2"; + String annots_java_lang = annots_dir2 + File.separator + "java/lang"; + new File(annots_java_lang).mkdirs(); + Util.createFile(annots_java_lang + File.separator + "Object.eea", + TEST_440687_OBJECT_EEA_CONTENT); + String zipName = Util.getOutputDirectory() + File.separator + "annots2.zip"; + Util.zip(new File(annots_dir2), zipName); + Util.delete(annots_dir2); + + runTest440687("-annotationpath \"" + zipName + "\"", + File.pathSeparator + annots_dir1, // extra source path + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 9)\n" + + " Test1 v = map.get(key);\n" + + " ^^^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Map<@NonNull String,@NonNull Test1>\'. Type \'Map\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 11)\n" + + " throw new RuntimeException(); // should not be reported as dead code, although V is a \'@NonNull Test1\'\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 13)\n" + + " public boolean equals(@NonNull Object other) { return false; }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter other, inherited method from Object declares this parameter as @Nullable\n" + + "----------\n" + + "3 problems (3 warnings)\n", + true); + } + public void testBug571055_explicit() throws IOException { + runTestBug571055(false, false); + } + public void testBug571055_inherit() throws IOException { + runTestBug571055(true, false); + } + public void testBug571055_dedicatedAnnotationPath() throws IOException { + runTestBug571055(false, true); + } + private void runTestBug571055(boolean inheritAnnotations, boolean dedicatedAnnotationPath) throws IOException { + String annots_dir = Util.getOutputDirectory() + File.separator + "annots"; + String annots_api = annots_dir + File.separator + "api"; + new File(annots_api).mkdirs(); + Util.createFile( + annots_api + File.separator + "Foo.eea", + "class api/Foo\n" + + "m\n" + + " (Ljava/lang/String;)Ljava/lang/String;\n" + + " (L1java/lang/String;)L0java/lang/String;\n"); + if (!inheritAnnotations) { + // 'manually' establish consistency: + String annots_impl = annots_dir + File.separator + "impl"; + new File(annots_impl).mkdirs(); + Util.createFile( + annots_impl + File.separator + "FooImpl.eea", + "class impl/FooImpl\n" + + "m\n" + + " (Ljava/lang/String;)Ljava/lang/String;\n" + + " (L1java/lang/String;)L0java/lang/String;\n"); + } + + String[] testFiles = new String[] { + "java/lang/annotation/ElementType.java", + ELEMENT_TYPE_18_CONTENT, + "org/eclipse/jdt/annotation/NonNull.java", + NONNULL_ANNOTATION_18_CONTENT, + "org/eclipse/jdt/annotation/Nullable.java", + NULLABLE_ANNOTATION_18_CONTENT, + "org/eclipse/jdt/annotation/DefaultLocation.java", + DEFAULT_LOCATION_CONTENT, + "api/Foo.java", + "package api;\n" + + "public interface Foo {\n" + + " String m(String a);\n" + + "}\n", + "impl/FooImpl.java", + "package impl;\n" + + "import api.Foo;\n" + + "public class FooImpl implements Foo {\n" + + " public String m(String a) { return null; }\n" + // ensure Foo & FooImpl are seen with consistent nullness + "}\n", + "test1/Test1.java", + "package test1;\n" + + "\n" + + "import api.Foo;\n" + + "\n" + + "public class Test1 {\n" + + " void test(Foo api) {\n" + + " String result = api.m(null);\n" + + " System.out.println(result.toUpperCase());\n" + + " }\n" + + "}\n" + }; + + String commandLine; + if (dedicatedAnnotationPath) { + commandLine = "-annotationpath \"" + annots_dir + "\" " + + " -1.8 -proc:none -err:+nullAnnot -warn:+null " + + (inheritAnnotations ? " -warn:+inheritNullAnnot ": "") + + " \"" + OUTPUT_DIR + "\""; + } else { + commandLine = "-annotationpath CLASSPATH " + + " -1.8 -proc:none -err:+nullAnnot -warn:+null " + + (inheritAnnotations ? " -warn:+inheritNullAnnot ": "") + + " -classpath \"" + annots_dir + "\" " + + " \"" + OUTPUT_DIR + "\""; + } + + // expect eea-motivated problems in Test1 but no in FooImpl: + String expectedCompilerMessage = + "----------\n" + + "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 7)\n" + + " String result = api.m(null);\n" + + " ^^^^\n" + + "Null type mismatch: required '@NonNull String' but the provided value is null\n" + + "----------\n" + + "2. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/test1/Test1.java (at line 8)\n" + + " System.out.println(result.toUpperCase());\n" + + " ^^^^^^\n" + + "Potential null pointer access: The variable result may be null at this location\n" + + "----------\n" + + "2 problems (1 error, 1 warning)\n"; + this.runNegativeTest(testFiles, commandLine, "", expectedCompilerMessage, false); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java new file mode 100644 index 0000000000..38fe90ca06 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java @@ -0,0 +1,11102 @@ +/******************************************************************************* + * Copyright (c) 2010, 2021 GK Software AG and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + * Till Brychcy - Contribution for + * Bug 415413 - [compiler][null] NullpointerException in Null Analysis caused by interaction of LoopingFlowContext and FinallyFlowContext + * Bug 415269 - [compiler][null] NonNullByDefault is not always inherited to nested classes + * IBM Corporation - additional tests + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.Excuse; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +// see bug 186342 - [compiler][null] Using annotations for null checking +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class NullAnnotationTest extends AbstractNullAnnotationTest { + +private String TEST_JAR_SUFFIX = ".jar"; + +public NullAnnotationTest(String name) { + super(name); +} + +// Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which do not belong to the class are skipped... +static { +// TESTS_NAMES = new String[] { "testBug545715" }; +// TESTS_NUMBERS = new int[] { 561 }; +// TESTS_RANGE = new int[] { 1, 2049 }; +} + +public static Test suite() { + return buildComparableTestSuite(testClass()); +} + +public static Class testClass() { + return NullAnnotationTest.class; +} + +String mismatch_NonNull_Nullable(String type) { + return (this.complianceLevel < ClassFileConstants.JDK1_8) + ? "Null type mismatch: required \'@NonNull "+type+"\' but the provided value is specified as @Nullable\n" + : "Null type mismatch (type annotations): required '@NonNull "+type+"' but this expression has type '@Nullable "+type+"'\n"; +} +String nullTypeSafety() { + return (this.complianceLevel < ClassFileConstants.JDK1_8) + ? "Null type safety: " + : "Null type safety (type annotations): "; +} +String variableMayBeNull(String var) { + return (this.complianceLevel < ClassFileConstants.JDK1_8) + ? "Potential null pointer access: The variable "+var+" may be null at this location\n" + : "Potential null pointer access: this expression has a '@Nullable' type\n"; +} +String redundant_check_nonnull(String expr, String type) { + return this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Redundant null check: "+expr+" is specified as @NonNull\n" + : "Redundant null check: comparing '"+type+"' against null\n"; +} +String redundantCheck_method_cannot_return_null(String method, String type) { + return this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Redundant null check: The method "+method+" cannot return null\n" + : "Redundant null check: comparing '@NonNull "+type+"' against null\n"; +} +String checkAlwaysFalse_method_cannot_return_null(String method, String type) { + return this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Null comparison always yields false: The method "+method+" cannot return null\n" + : "Redundant null check: comparing '@NonNull "+type+"' against null\n"; +} +String redundant_check_canonlynull(String expr, String type) { + return this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Redundant null check: "+expr+" can only be null at this location\n" + : "Redundant null check: comparing '@NonNull "+type+"' against null\n"; +} + +String checkAlwaysFalse_nonnull(String expr, String type) { + return (this.complianceLevel < ClassFileConstants.JDK1_8) + ? "Null comparison always yields false: "+expr+" is specified as @NonNull\n" + : "Redundant null check: comparing '@NonNull "+type+"' against null\n"; +} +String potNPE_nullable(String expr) { + return (this.complianceLevel < ClassFileConstants.JDK1_8) + ? "Potential null pointer access: "+expr+" is specified as @Nullable\n" + : "Potential null pointer access: this expression has a '@Nullable' type\n"; +} +String potNPE_nullable_maybenull(String expr) { + return (this.complianceLevel < ClassFileConstants.JDK1_8) + ? "Potential null pointer access: "+expr+" may be null at this location\n" + : "Potential null pointer access: this expression has a '@Nullable' type\n"; +} +String nonNullArrayOf(String string) { + return (this.complianceLevel < ClassFileConstants.JDK1_8) + ? "@NonNull Object[]" + : "Object @NonNull[]"; +} + + +String targetTypeUseIfAvailable() { + return this.complianceLevel >= ClassFileConstants.JDK1_8 + ? "@Target(ElementType.TYPE_USE)\n" + : ""; +} + +String cancenNonNullByDefault() { + return this.complianceLevel < ClassFileConstants.JDK1_8 + ? " @NonNullByDefault(false)\n" + : " @NonNullByDefault({})\n"; +} + +/** + * @deprecated + */ +@Override +protected void setUp() throws Exception { + super.setUp(); + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + this.TEST_JAR_SUFFIX = "_1.8.jar"; + if (this.LIBS == null) { + this.LIBS = getLibsWithNullAnnotations(this.complianceLevel); + } +} + +// a nullable argument is dereferenced without a check +public void test_nullable_paramter_001() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@Nullable Object o) {\n" + + " System.out.print(o.toString());\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " System.out.print(o.toString());\n" + + " ^\n" + + variableMayBeNull("o") + + "----------\n"); +} + +// a null value is passed to a nullable argument +public void test_nullable_paramter_002() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@Nullable Object o) {\n" + + " // nop\n" + + " }\n" + + " void bar() {\n" + + " foo(null);\n" + + " }\n" + + "}\n"}, + null, + ""); +} + +// a non-null argument is checked for null +public void test_nonnull_parameter_001() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@NonNull Object o) {\n" + + " if (o != null)\n" + + " System.out.print(o.toString());\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null)\n" + + " ^\n" + + redundant_check_nonnull("The variable o", "@NonNull Object") + + "----------\n"); +} +// a non-null argument is dereferenced without a check +public void test_nonnull_parameter_002() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@NonNull Object o) {\n" + + " System.out.print(o.toString());\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(\"OK\");\n" + + " }\n" + + "}\n"}, + getCompilerOptions(), + "", + "OK"); +} +// passing null to nonnull parameter - many fields in enclosing class +public void test_nonnull_parameter_003() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " int i00, i01, i02, i03, i04, i05, i06, i07, i08, i09;" + + " int i10, i11, i12, i13, i14, i15, i16, i17, i18, i19;" + + " int i20, i21, i22, i23, i24, i25, i26, i27, i28, i29;" + + " int i30, i31, i32, i33, i34, i35, i36, i37, i38, i39;" + + " int i40, i41, i42, i43, i44, i45, i46, i47, i48, i49;" + + " int i50, i51, i52, i53, i54, i55, i56, i57, i58, i59;" + + " int i60, i61, i62, i63, i64, i65, i66, i67, i68, i69;" + + " void foo(@NonNull Object o) {\n" + + " System.out.print(o.toString());\n" + + " }\n" + + " void bar() {\n" + + " foo(null);\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " foo(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// passing potential null to nonnull parameter - target method is consumed from .class +public void test_nonnull_parameter_004() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Lib {\n" + + " void setObject(@NonNull Object o) { }\n" + + "}\n" + }, + null /*customOptions*/, + ""); + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "X.java", + "public class X {\n" + + " void bar(Lib l, boolean b) {\n" + + " Object o = null;\n" + + " if (b) o = new Object();\n" + + " l.setObject(o);\n" + + " }\n" + + "}\n"}, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " l.setObject(o);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is inferred as @Nullable\n" + + "----------\n"); +} +// passing unknown value to nonnull parameter - target method is consumed from .class +public void test_nonnull_parameter_005() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Lib {\n" + + " void setObject(@NonNull Object o) { }\n" + + "}\n" + }, + null /*customOptions*/, + ""); + runWarningTestWithLibs( + false, // don't flush + new String[] { + "X.java", + "public class X {\n" + + " void bar(Lib l, Object o) {\n" + + " l.setObject(o);\n" + + " }\n" + + "}\n"}, + null /* options */, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " l.setObject(o);\n" + + " ^\n" + + nullTypeSafety() + "The expression of type 'Object' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n"); +} +// a ternary non-null expression is passed to a nonnull parameter +public void test_nonnull_parameter_006() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void m1(@NonNull String a) {}\n" + + " void m2(@Nullable String b) {\n" + + " m1(b == null ? \"\" : b);\n" + + " }\n" + + "}\n"}, + customOptions, + "" /* compiler output */); +} +// nullable value passed to a non-null parameter in a super-call +public void test_nonnull_parameter_007() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "XSub.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class XSub extends XSuper {\n" + + " XSub(@Nullable String b) {\n" + + " super(b);\n" + + " }\n" + + "}\n", + "XSuper.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class XSuper {\n" + + " XSuper(@NonNull String b) {\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in XSub.java (at line 4)\n" + + " super(b);\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n"); +} +// a nullable value is passed to a non-null parameter in an allocation expression +public void test_nonnull_parameter_008() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " X(@NonNull String a) {}\n" + + " static X create(@Nullable String b) {\n" + + " return new X(b);\n" + + " }\n" + + "}\n"}, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return new X(b);\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" /* compiler output */); +} +// a nullable value is passed to a non-null parameter in a qualified allocation expression +public void test_nonnull_parameter_009() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " class Local {\n" + + " Local(@NonNull String a) {}\n" + + " }\n" + + " Local create(@Nullable String b) {\n" + + " return this.new Local(b);\n" + + " }\n" + + "}\n"}, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return this.new Local(b);\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" /* compiler output */); +} +// null is passed to a non-null parameter in a qualified allocation expression, across CUs +public void test_nonnull_parameter_010() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "ContainingInner2.java", + "public class ContainingInner2 {\n" + + " public ContainingInner2 (@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " }\n" + + " public class Inner {\n" + + " public Inner (@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " }\n" + + " }\n" + + "}\n", + "X.java", + "public class X {\n" + + " void create() {\n" + + " ContainingInner2 container = new ContainingInner2(null);\n" + + " ContainingInner2.Inner inner = container.new Inner(null);\n" + + " }\n" + + "}\n"}, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " ContainingInner2 container = new ContainingInner2(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " ContainingInner2.Inner inner = container.new Inner(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" /* compiler output */); +} +// null is passed to a non-null parameter in a qualified allocation expression, target class read from .class +public void test_nonnull_parameter_011() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "ContainingInner2.java", + "public class ContainingInner2 {\n" + + " public ContainingInner2 (@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " }\n" + + " public class Inner {\n" + + " public Inner (@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + null /*customOptions*/, + ""); + runNegativeTestWithLibs( + false, // flush directory + new String[] { + "X.java", + "public class X {\n" + + " void create() {\n" + + " ContainingInner2 container = new ContainingInner2(null);\n" + + " ContainingInner2.Inner inner = container.new Inner(null);\n" + + " }\n" + + "}\n"}, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " ContainingInner2 container = new ContainingInner2(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " ContainingInner2.Inner inner = container.new Inner(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" /* compiler output */); +} +// null is passed to a non-null parameter in a qualified allocation expression, generic constructor, target class read from .class +// Note: in new type inference we infer the parameter of the Inner ctor to NullTypeBinding. +// This needs special treatment in ctor of ParameterizedGenericMethodBinding and in Statement.analyseOneArgument18 +// as to propagate nonnull info, although the NullTypeBinding cannot transport this info. +public void test_nonnull_parameter_012() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "ContainingInner2.java", + "public class ContainingInner2 {\n" + + " public ContainingInner2 (@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " }\n" + + " public class Inner {\n" + + " public Inner (@org.eclipse.jdt.annotation.NonNull T o) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + null /*customOptions*/, + ""); + runNegativeTestWithLibs( + false, // flush directory + new String[] { + "X.java", + "public class X {\n" + + " void create() {\n" + + " ContainingInner2 container = new ContainingInner2(null);\n" + + " ContainingInner2.Inner inner = container.new Inner(null);\n" + + " }\n" + + "}\n"}, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " ContainingInner2 container = new ContainingInner2(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " ContainingInner2.Inner inner = container.new Inner(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object' but the provided value is null\n" + + "----------\n"); +} +// a method of a local class has a non-null parameter, client passes null +public void test_nonnull_parameter_013() { + runNegativeTestWithLibs( + new String[] { + "B.java", + "class B {\n" + + " void bar () {\n" + + " class Local {\n" + + " void callMe(@org.eclipse.jdt.annotation.NonNull Object o){\n" + + " }\n" + + " }\n" + + " Local l = new Local();\n" + + " l.callMe(null);\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in B.java (at line 8)\n" + + " l.callMe(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// non-null varargs (message send) +public void test_nonnull_parameter_015() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + ((this.complianceLevel < ClassFileConstants.JDK1_8) + ? " void foo(@NonNull Object ... o) {\n" + : " void foo(Object @NonNull... o) {\n") + + " if (o != null)\n" + + " System.out.print(o.toString());\n" + + " }\n" + + ((this.complianceLevel < ClassFileConstants.JDK1_8) + ? " void foo2(int i, @NonNull Object ... o) {\n" + : " void foo2(int i, Object @NonNull ... o) {\n" + ) + + " if (o.length > 0 && o[0] != null)\n" + + " System.out.print(o[0].toString());\n" + + " }\n" + + " void bar() {\n" + + " foo((Object)null);\n" + // unchecked: single plain argument + " Object[] objs = null;\n" + + " foo(objs);\n" + // error + " foo(this, null);\n" + // unchecked: multiple plain arguments + " foo2(2, (Object)null);\n" + // unchecked: single plain argument + " foo2(2, null, this);\n" + // unchecked: multiple plain arguments + " foo2(2, null);\n" + // error + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null)\n" + + " ^\n" + + redundant_check_nonnull("The variable o", "Object @NonNull[]") + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " foo(objs);\n" + + " ^^^^\n" + + "Null type mismatch: required \'"+nonNullArrayOf("Object")+"\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in X.java (at line 18)\n" + + " foo2(2, null);\n" + + " ^^^^^^^^^^^^^\n" + + "Type null of the last argument to method foo2(int, Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "4. ERROR in X.java (at line 18)\n" + + " foo2(2, null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'"+nonNullArrayOf("Object")+"\' but the provided value is null\n" + + "----------\n"); +} +// non-null varargs (allocation and explicit constructor calls) +public void test_nonnull_parameter_016() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + ((this.complianceLevel < ClassFileConstants.JDK1_8) + ? " X(@NonNull Object ... o) {\n" + : " X(Object @NonNull... o) {\n") + + " if (o != null)\n" + + " System.out.print(o.toString());\n" + + " }\n" + + " class Y extends X {\n" + + ((this.complianceLevel < ClassFileConstants.JDK1_8) + ? " Y(int i, @NonNull Object ... o) {\n" + : " Y(int i, Object @NonNull... o) {\n") + + " super(i, (Object)null);\n" + + " }\n" + + ((this.complianceLevel < ClassFileConstants.JDK1_8) + ? " Y(char c, @NonNull Object ... o) {\n" + : " Y(char c, Object @NonNull... o) {\n") + + " this(1, new Object(), null);\n" + + " }\n" + + " }\n" + + " void bar() {\n" + + " new X((Object[])null);\n" + + " new X(this, null);\n" + + " X x = new X(null, this);\n" + + " x.new Y(2, (Object)null);\n" + + " this.new Y(2, null, this);\n" + + " this.new Y(2, (Object[])null);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null)\n" + + " ^\n" + + redundant_check_nonnull("The variable o", "Object @NonNull[]") + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " new X((Object[])null);\n" + + " ^^^^^^^^^^^^^^\n" + + "Null type mismatch: required \'"+nonNullArrayOf("Object")+"\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in X.java (at line 21)\n" + + " this.new Y(2, (Object[])null);\n" + + " ^^^^^^^^^^^^^^\n" + + "Null type mismatch: required \'"+nonNullArrayOf("Object")+"\' but the provided value is null\n" + + "----------\n"); +} +// Bug 367203 - [compiler][null] detect assigning null to nonnull argument +public void test_nonnull_argument_001() { + runNegativeTestWithLibs( + new String[] { + "ShowNPE2.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "public class ShowNPE2 {\n" + + " public Object foo(Object o1, final boolean b) {\n" + + " o1 = null; // expect NPE error\n" + + " System.out.println(o1.toString()); \n" + + " return null; // expect NPE error\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in ShowNPE2.java (at line 5)\n" + + " o1 = null; // expect NPE error\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in ShowNPE2.java (at line 7)\n" + + " return null; // expect NPE error\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// Bug 367203 - [compiler][null] detect assigning null to nonnull argument +public void test_nonnull_argument_002() { + runNegativeTestWithLibs( + new String[] { + "ShowNPE2.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "public class ShowNPE2 {\n" + + " public Object foo(Object o1, final boolean b) {\n" + + " bar(o1); // expecting no problem\n" + + " return null; // expect NPE error\n" + + " }\n" + + " void bar(Object o2) {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in ShowNPE2.java (at line 6)\n" + + " return null; // expect NPE error\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// a method of a local class has a non-null parameter, client passes potential null (msg send) +public void test_nonnull_parameter_014() { + runNegativeTestWithLibs( + new String[] { + "B.java", + "class B {\n" + + " void bar () {\n" + + " class Local {\n" + + " void callMe(@org.eclipse.jdt.annotation.NonNull Object o){\n" + + " }\n" + + " }\n" + + " Local l = new Local();\n" + + " l.callMe(getNull());\n" + + " }\n" + + " @org.eclipse.jdt.annotation.Nullable Object getNull() { return null; }" + + "}\n" + }, + "----------\n" + + "1. ERROR in B.java (at line 8)\n" + + " l.callMe(getNull());\n" + + " ^^^^^^^^^\n" + + mismatch_NonNull_Nullable("Object") + + "----------\n"); +} +// assigning potential null to a nonnull local variable +public void test_nonnull_local_001() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(boolean b, Object p) {\n" + + " @NonNull Object o1 = b ? null : new Object();\n" + + " @NonNull String o2 = \"\";\n" + + " o2 = null;\n" + + " @NonNull Object o3 = p;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @NonNull Object o1 = b ? null : new Object();\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is inferred as @Nullable\n" + : + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n") + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " o2 = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " @NonNull Object o3 = p;\n" + + " ^\n" + + nullTypeSafety() + "The expression of type 'Object' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n"); +} + +// assigning potential null to a nonnull local variable - separate decl and assignment +public void test_nonnull_local_002() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(boolean b, Object p) {\n" + + " @NonNull Object o1;\n" + + " o1 = b ? null : new Object();\n" + + " @NonNull String o2;\n" + + " o2 = \"\";\n" + + " o2 = null;\n" + + " @NonNull Object o3;\n" + + " o3 = p;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o1 = b ? null : new Object();\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is inferred as @Nullable\n" + : + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n") + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " o2 = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " o3 = p;\n" + + " ^\n" + + nullTypeSafety() + "The expression of type 'Object' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n"); +} + +// a method tries to tighten the type specification, super declares parameter o as @Nullable +// other parameters: s is redefined from not constrained to @Nullable which is OK +// third is redefined from not constrained to @NonNull which is bad, too +public void test_parameter_specification_inheritance_001() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Lib {\n" + + " void foo(String s, @Nullable Object o, Object third) { }\n" + + "}\n" + }, + null /*customOptions*/, + ""); + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X extends Lib {\n" + + " @Override\n" + + " void foo(@Nullable String s, @NonNull Object o, @NonNull Object third) { System.out.print(o.toString()); }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " void foo(@Nullable String s, @NonNull Object o, @NonNull Object third) { System.out.print(o.toString()); }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter o, inherited method from Lib declares this parameter as @Nullable\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " void foo(@Nullable String s, @NonNull Object o, @NonNull Object third) { System.out.print(o.toString()); }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter third, inherited method from Lib does not constrain this parameter\n" + + "----------\n"); +} +// a method body fails to redeclare the inherited null annotation, super declares parameter as @Nullable +public void test_parameter_specification_inheritance_002() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Lib {\n" + + " void foo(@Nullable Object o) { }\n" + + "}\n" + }, + null, + ""); + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "X.java", + "public class X extends Lib {\n" + + " @Override\n" + + " void foo(Object o) {\n" + + " System.out.print(o.toString());\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo(Object o) {\n" + + " ^^^^^^\n" + + "Missing nullable annotation: inherited method from Lib specifies this parameter as @Nullable\n" + + "----------\n"); +} +// a method relaxes the parameter null specification, super interface declares parameter o as @NonNull +// other (first) parameter just repeats the inherited @NonNull +public void test_parameter_specification_inheritance_003() { + runConformTestWithLibs( + new String[] { + "IX.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface IX {\n" + + " void foo(@NonNull String s, @NonNull Object o);\n" + + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X implements IX {\n" + + " public void foo(@NonNull String s, @Nullable Object o) { ; }\n" + + " void bar() { foo(\"OK\", null); }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// a method adds a @NonNull annotation, super interface has no null annotation +// changing other from unconstrained to @Nullable is OK +public void test_parameter_specification_inheritance_004() { + runConformTestWithLibs( + new String[] { + "IX.java", + "public interface IX {\n" + + " void foo(Object o, Object other);\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X implements IX {\n" + + " public void foo(@NonNull Object o, @Nullable Object other) { System.out.print(o.toString()); }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public void foo(@NonNull Object o, @Nullable Object other) { System.out.print(o.toString()); }\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter o, inherited method from IX does not constrain this parameter\n" + + "----------\n"); +} +// a method tries to relax the null contract, super declares @NonNull return +public void test_parameter_specification_inheritance_005() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Lib {\n" + + " @NonNull Object getObject() { return new Object(); }\n" + + "}\n" + }, + null /*customOptions*/, + ""); + runNegativeTestWithLibs( + false, //dont' flush + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X extends Lib {\n" + + " @Override\n" + + " @Nullable Object getObject() { return null; }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Nullable Object getObject() { return null; }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with '@NonNull Object' returned from Lib.getObject() (mismatching null constraints)\n" + + "----------\n"); +} + +// super has no constraint for return, sub method confirms the null contract as @Nullable +public void test_parameter_specification_inheritance_006() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "public class Lib {\n" + + " Object getObject() { return null; }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runConformTestWithLibs( + false, // don't flush + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X extends Lib {\n" + + " @Override\n" + + " @Nullable Object getObject() { return null; }\n" + + "}\n" + }, + null /*customOptions*/, + ""); +} +// a method body violates the inherited null specification, super declares @NonNull return, missing redeclaration +public void test_parameter_specification_inheritance_007() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Lib {\n" + + " @NonNull Object getObject() { return new Object(); }\n" + + "}\n" + }, + null /*customOptions*/, + ""); + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "X.java", + "public class X extends Lib {\n" + + " @Override\n" + + " Object getObject() { return null; }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object getObject() { return null; }\n" + + " ^^^^^^\n" + + "The return type is incompatible with '@NonNull Object' returned from Lib.getObject() (mismatching null constraints)\n" + + "----------\n"); +} +//a method body violates the @NonNull return specification (repeated from super) +public void test_parameter_specification_inheritance_007a() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Lib {\n" + + " @NonNull Object getObject() { return new Object(); }\n" + + "}\n" + }, + null /*customOptions*/, + ""); + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X extends Lib {\n" + + " @Override\n" + + " @NonNull Object getObject() { return null; }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @NonNull Object getObject() { return null; }\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// a client potentially violates the inherited null specification, super interface declares @NonNull parameter +public void test_parameter_specification_inheritance_008() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void printObject(@NonNull Object o) { System.out.print(o.toString()); }\n" + + "}\n" + }, + null /*customOptions*/, + ""); + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "XSub.java", + "public class XSub extends X {\n" + + " @Override\n" + + " public void printObject(Object o) { super.printObject(o); }\n" + + "}\n", + "M.java", + "public class M{\n" + + " void foo(X x, Object o) {\n" + + " x.printObject(o);\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. WARNING in XSub.java (at line 3)\n" + + " public void printObject(Object o) { super.printObject(o); }\n" + + " ^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "2. ERROR in XSub.java (at line 3)\n" + + " public void printObject(Object o) { super.printObject(o); }\n" + + " ^\n" + + nullTypeSafety() + "The expression of type 'Object' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n" + + "----------\n" + + "1. ERROR in M.java (at line 3)\n" + + " x.printObject(o);\n" + + " ^\n" + + nullTypeSafety() + "The expression of type 'Object' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n"); +} +// a static method has a more relaxed null contract than a like method in the super class, but no overriding. +public void test_parameter_specification_inheritance_009() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Lib {\n" + + " @NonNull static Object getObject() { return new Object(); }\n" + + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X extends Lib {\n" + + " @Nullable static Object getObject() { return null; }\n" + + "}\n" + }, + null /*customOptions*/, + ""); +} +// class default is nonnull, method and its super both use the default +public void test_parameter_specification_inheritance_010() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " protected String getString(String s) {\n" + + " if (Character.isLowerCase(s.charAt(0)))\n" + + " return getString(s);\n" + + " return s;\n" + + " }\n" + + "}\n", + "p1/Y.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y extends X {\n" + + " @Override\n" + + " protected String getString(String s) {\n" + + " return super.getString(s);\n" + + " }\n" + + "}\n", + }, + customOptions, + ""); +} +// class default is nonnull, method and its super both use the default, super-call passes null +public void test_parameter_specification_inheritance_011() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " protected String getString(String s) {\n" + + " if (Character.isLowerCase(s.charAt(0)))\n" + + " return getString(s);\n" + + " return s;\n" + + " }\n" + + "}\n", + "p1/Y.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y extends X {\n" + + " @Override\n" + + " protected String getString(String s) {\n" + + " return super.getString(null);\n" + + " }\n" + + "}\n", + }, + customOptions, + "----------\n" + + "1. ERROR in p1\\Y.java (at line 7)\n" + + " return super.getString(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); +} +// methods from two super types have different null contracts. +// sub-class merges both using the weakest common contract +public void test_parameter_specification_inheritance_012() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " public @Nullable String getString(String s1, @Nullable String s2, @NonNull String s3) {\n" + + " return s1;\n" + + " }\n" + + "}\n", + "p1/IY.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public interface IY {\n" + + " @NonNull String getString(@NonNull String s1, @NonNull String s2, @Nullable String s3);\n" + + "}\n", + "p1/Y.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y extends X implements IY {\n" + + " @Override\n" + + " public @NonNull String getString(@Nullable String s1, @Nullable String s2, @Nullable String s3) {\n" + + " return \"\";\n" + + " }\n" + + "}\n", + }, + customOptions, + ""); +} +// methods from two super types have different null contracts. +// sub-class overrides this method in non-conforming ways +public void test_parameter_specification_inheritance_013() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " public @Nullable String getString(String s1, @Nullable String s2, @NonNull String s3) {\n" + + " return s1;\n" + + " }\n" + + "}\n", + "p1/IY.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public interface IY {\n" + + " @NonNull String getString(@NonNull String s1, @NonNull String s2, @Nullable String s3);\n" + + "}\n", + "p1/Y.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y extends X implements IY {\n" + + " @Override\n" + + " public @Nullable String getString(String s1, @NonNull String s2, @NonNull String s3) {\n" + + " return \"\";\n" + + " }\n" + + "}\n", + }, + customOptions, + "----------\n" + + "1. ERROR in p1\\Y.java (at line 5)\n" + + " public @Nullable String getString(String s1, @NonNull String s2, @NonNull String s3) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with '@NonNull String' returned from IY.getString(String, String, String) (mismatching null constraints)\n" + + // no problem regarding s1: widening @NonNull to unannotated + "----------\n" + + "2. ERROR in p1\\Y.java (at line 5)\n" + + " public @Nullable String getString(String s1, @NonNull String s2, @NonNull String s3) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter s2, inherited method from X declares this parameter as @Nullable\n" + + "----------\n" + + "3. ERROR in p1\\Y.java (at line 5)\n" + + " public @Nullable String getString(String s1, @NonNull String s2, @NonNull String s3) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter s3, inherited method from IY declares this parameter as @Nullable\n" + + "----------\n"); +} +// methods from two super types have different null contracts. +// sub-class does not override, but should to bridge the incompatibility +public void test_parameter_specification_inheritance_014() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "p1/IY.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public interface IY {\n" + + " public @NonNull String getString1(String s);\n" + + " public @NonNull String getString2(String s);\n" + + " public String getString3(@Nullable String s);\n" + + " public @NonNull String getString4(@Nullable String s);\n" + + " public @NonNull String getString5(@Nullable String s);\n" + + " public @Nullable String getString6(@NonNull String s);\n" + + "}\n", + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " public @Nullable String getString1(String s) {\n" + // incomp. return + " return s;\n" + + " }\n" + + " public String getString2(String s) {\n" + // incomp. return + " return s;\n" + + " }\n" + + " public String getString3(String s) {\n" + // incomp. arg + " return \"\";\n" + + " }\n" + + " public @NonNull String getString4(@Nullable String s) {\n" + + " return \"\";\n" + + " }\n" + + " public @NonNull String getString5(@NonNull String s) {\n" + // incomp. arg + " return s;\n" + + " }\n" + + " public @NonNull String getString6(@Nullable String s) {\n" + + " return \"\";\n" + + " }\n" + + "}\n", + "p1/Y.java", + "package p1;\n" + + "public class Y extends X implements IY {\n" + + "}\n", + }, + customOptions, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in p1\\Y.java (at line 2)\n" + + " public class Y extends X implements IY {\n" + + " ^\n" + + "The method getString1(String) from X cannot implement the corresponding method from IY due to incompatible nullness constraints\n" + + "----------\n" + + "2. ERROR in p1\\Y.java (at line 2)\n" + + " public class Y extends X implements IY {\n" + + " ^\n" + + "The method getString2(String) from X cannot implement the corresponding method from IY due to incompatible nullness constraints\n" + + "----------\n" + + "3. ERROR in p1\\Y.java (at line 2)\n" + + " public class Y extends X implements IY {\n" + + " ^\n" + + "The method getString5(String) from X cannot implement the corresponding method from IY due to incompatible nullness constraints\n" + + "----------\n" + + "4. ERROR in p1\\Y.java (at line 2)\n" + + " public class Y extends X implements IY {\n" + + " ^\n" + + "The method getString3(String) from X cannot implement the corresponding method from IY due to incompatible nullness constraints\n" + + "----------\n" + : // at 1.8 we show null type annotations in the message: + "----------\n" + + "1. ERROR in p1\\Y.java (at line 2)\n" + + " public class Y extends X implements IY {\n" + + " ^\n" + + "The method @Nullable String getString1(String) from X cannot implement the corresponding method from IY due to incompatible nullness constraints\n" + + "----------\n" + + "2. ERROR in p1\\Y.java (at line 2)\n" + + " public class Y extends X implements IY {\n" + + " ^\n" + + "The method String getString2(String) from X cannot implement the corresponding method from IY due to incompatible nullness constraints\n" + + "----------\n" + + "3. ERROR in p1\\Y.java (at line 2)\n" + + " public class Y extends X implements IY {\n" + + " ^\n" + + "The method getString5(@NonNull String) from X cannot implement the corresponding method from IY due to incompatible nullness constraints\n" + + "----------\n" + + "4. ERROR in p1\\Y.java (at line 2)\n" + + " public class Y extends X implements IY {\n" + + " ^\n" + + "The method getString3(String) from X cannot implement the corresponding method from IY due to incompatible nullness constraints\n" + + "----------\n")); +} +// a method relaxes the parameter null specification from @NonNull to un-annotated +// see https://bugs.eclipse.org/381443 +public void test_parameter_specification_inheritance_015() { + runWarningTestWithLibs( + true, // flush + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@NonNull String s) { System.out.println(s); }\n" + + "}\n", + "XSub.java", + "public class XSub extends X {\n" + + " @Override\n" + + " public void foo(String s) { if (s != null) super.foo(s); }\n" + + " void bar() { foo(null); }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in XSub.java (at line 3)\n" + + " public void foo(String s) { if (s != null) super.foo(s); }\n" + + " ^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n"); +} + +// a method relaxes the parameter null specification from @NonNull to un-annotated +// see https://bugs.eclipse.org/381443 +// issue configured as error +public void test_parameter_specification_inheritance_016() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@NonNull String s) { System.out.println(s); }\n" + + "}\n", + "XSub.java", + "public class XSub extends X {\n" + + " @Override\n" + + " public void foo(String s) { if (s != null) super.foo(s); }\n" + + " void bar() { foo(null); }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in XSub.java (at line 3)\n" + + " public void foo(String s) { if (s != null) super.foo(s); }\n" + + " ^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n"); +} + +// a class inherits two methods with different spec: one non-null param & one unannotated param +// widening reported as warning by default +// see https://bugs.eclipse.org/381443 +public void test_parameter_specification_inheritance_017() { + runWarningTestWithLibs( + true, + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) { System.out.println(s); }\n" + + "}\n", + "IX.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface IX {\n" + + " void foo(@NonNull String s);\n" + + "}\n", + "XSub.java", + "public class XSub extends X implements IX {\n" + + " void bar() { foo(null); }\n" + + " static void zork(XSub sub) {\n" + + " sub.foo(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in XSub.java (at line 1)\n" + + " public class XSub extends X implements IX {\n" + + " ^\n" + + "Parameter 1 of method foo(String) lacks a @NonNull annotation as specified in type IX\n" + + "----------\n"); +} + +// a class inherits two methods with different spec: one non-null param & one unannotated param +// opt to accept this widening +// see https://bugs.eclipse.org/381443 +public void test_parameter_specification_inheritance_018() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) { System.out.println(s); }\n" + + "}\n", + "IX.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public interface IX {\n" + + " void foo(@NonNull String s);\n" + + "}\n", + "XSub.java", + "public class XSub extends X implements IX {\n" + + " void bar() { foo(null); }\n" + + " static void zork(XSub sub) {\n" + + " sub.foo(null);\n" + + " }\n" + + "}\n" + }, + options, + ""); +} + +// a nullable return value is dereferenced without a check +public void test_nullable_return_001() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object getObject() { return null; }\n" + + " void foo() {\n" + + " Object o = getObject();\n" + + " System.out.print(o.toString());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " System.out.print(o.toString());\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"); +} +// a nullable return value is dereferenced without a check, method is read from .class file +public void test_nullable_return_002() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Lib {\n" + + " @Nullable Object getObject() { return null; }\n" + + "}\n" + }, + null /*customOptions*/, + ""); + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "X.java", + "public class X {\n" + + " void foo(Lib l) {\n" + + " Object o = l.getObject();\n" + + " System.out.print(o.toString());\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " System.out.print(o.toString());\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"); +} +// a non-null return value is checked for null, method is read from .class file +public void test_nonnull_return_001() { + runConformTestWithLibs( + new String[] { + "Lib.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Lib {\n" + + " @NonNull Object getObject() { return new Object(); }\n" + + "}\n" + }, + null /*customOptions*/, + ""); + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "X.java", + "public class X {\n" + + " void foo(Lib l) {\n" + + " Object o = l.getObject();\n" + + " if (o != null)\n" + + " System.out.print(o.toString());\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null)\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + // no immediate type annotation + "----------\n"); +} +// a non-null method returns null +public void test_nonnull_return_003() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object getObject(boolean b) {\n" + + " if (b)\n" + + " return null;\n" + // definite specification violation despite enclosing "if" + " return new Object();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// a non-null method potentially returns null +public void test_nonnull_return_004() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object getObject(@Nullable Object o) {\n" + + " return o;\n" + // 'o' is only potentially null + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return o;\n" + + " ^\n" + + mismatch_NonNull_Nullable("Object") + + "----------\n"); +} +// a non-null method returns its non-null argument +public void test_nonnull_return_005() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object getObject(@NonNull Object o) {\n" + + " return o;\n" + + " }\n" + + "}\n" + }, + null, // options + ""); +} +//a non-null method has insufficient nullness info for its return value +public void test_nonnull_return_006() { + runWarningTestWithLibs( + true, // flush + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object getObject(Object o) {\n" + + " return o;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return o;\n" + + " ^\n" + + nullTypeSafety() + "The expression of type 'Object' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n"); +} +// a result from a nullable method is directly dereferenced +public void test_nonnull_return_007() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object getObject() {\n" + + " return null;\n" + + " }\n" + + " void test() {\n" + + " getObject().toString();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " getObject().toString();\n" + + " ^^^^^^^^^^^\n" + + "Potential null pointer access: The method getObject() may return null\n" + + "----------\n"); +} +// a result from a nonnull method is directly checked for null: redundant +public void test_nonnull_return_008() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object getObject() {\n" + + " return new Object();\n" + + " }\n" + + " void test() {\n" + + " if (getObject() == null)\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (getObject() == null)\n" + + " ^^^^^^^^^^^\n" + + checkAlwaysFalse_method_cannot_return_null("getObject()", "Object") + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " throw new RuntimeException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +// a result from a nonnull method is directly checked for null (from local): redundant +public void test_nonnull_return_009() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object getObject() {\n" + + " return new Object();\n" + + " }\n" + + " void test() {\n" + + " Object left = null;\n" + + " if (left != getObject())\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " if (left != getObject())\n" + + " ^^^^\n" + + "Redundant null check: The variable left can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " if (left != getObject())\n" + + " ^^^^^^^^^^^\n" + + redundantCheck_method_cannot_return_null("getObject()", "Object") + + "----------\n"); +} +// a result from a nonnull method is directly checked for null (from local): not redundant due to loop +public void test_nonnull_return_009a() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object getObject() {\n" + + " return new Object();\n" + + " }\n" + + " void test() {\n" + + " Object left = null;\n" + + " for (int i=0; i<3; i++) {\n" + + " if (left != getObject())\n" + + " throw new RuntimeException();\n" + + " left = new Object();\n" + + " }\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); +} +// a result from a nonnull method is directly checked for null (from local): redundant despite loop +// disabled because only one of two desirable errors is raised +// need to integrate @NonNull expressions (MessageSend and more) into deferred analysis by FlowContext +public void _test_nonnull_return_009b() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object getObject() {\n" + + " return new Object();\n" + + " }\n" + + " void test() {\n" + + " Object left = null;\n" + + " for (int i=0; i<3; i++) {\n" + + " if (left != getObject())\n" + + " throw new RuntimeException();\n" + + " // left remains null\n" + + " }\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (left != getObject())\n" + + " ^^^^\n" + + redundant_check_canonlynull("The variable left", "Object") + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " if (left != getObject())\n" + + " ^^^^^^^^^^^\n" + + "Redundant null check: The method getObject() cannot return null\n" + + "----------\n"); +} +// a result from a nullable method is assigned and checked for null (from local): not redundant +// see also Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop +public void test_nonnull_return_010() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable X getX() {\n" + + " return new X();\n" + + " }\n" + + " void test() {\n" + + " X left = this;\n" + + " do {\n" + + " if (left == null) \n" + + " throw new RuntimeException();\n" + + " } while ((left = left.getX()) != null);\n" + // no warning/error here! + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (left == null) \n" + + " ^^^^\n" + + "Null comparison always yields false: The variable left cannot be null at this location\n" + + "----------\n"); +} +// a non-null method returns a checked-for null value, but that branch is dead code +public void test_nonnull_return_011() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " Object getObject(Object dubious) {\n" + + " if (dubious == null)\n" + // redundant + " return dubious;\n" + // definitely null, but not reported inside dead code + " return new Object();\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (dubious == null)\n" + + " ^^^^^^^\n" + + ((this.complianceLevel < ClassFileConstants.JDK1_8) + ? "Null comparison always yields false: The variable dubious is specified as @NonNull\n" + : "Redundant null check: comparing '@NonNull Object' against null\n" ) + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " return dubious;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +// a non-null method returns a definite null from a conditional expression +// requires the fix for Bug 354554 - [null] conditional with redundant condition yields weak error message +// TODO(SH): ENABLE! +public void _test_nonnull_return_012() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " Object getObject(Object dubious) {\n" + + " return dubious == null ? dubious : null;\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return dubious == null ? dubious : null;\n" + + " ^^^^^^^\n" + + "Null comparison always yields false: The variable dubious cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " return dubious == null ? dubious : null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// don't apply any default annotations to return void +public void test_nonnull_return_013() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void getObject() {}\n" + + "}\n", + "Y.java", + "public class Y extends X {\n" + + " @Override\n" + + " void getObject() {}\n" + // don't complain, void takes no (default) annotation + "}\n" + }, + customOptions, + ""); +} +// bug 365835: [compiler][null] inconsistent error reporting. +public void test_nonnull_return_014() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class X {\n" + + " @NonNull\n" + + " public Object foo(Object x, int y) {\n" + + " @NonNull Object local;\n" + + " while (true) {\n" + + " if (y == 4) {\n" + + " local = x; // error\n" + + " return x; // only a warning.\n" + + " }\n" + + " x = null;\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " local = x; // error\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is inferred as @Nullable\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " return x; // only a warning.\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is inferred as @Nullable\n" + + "----------\n"); +} +// suppress an error regarding null-spec violation +public void test_suppress_001() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @SuppressWarnings(\"null\")\n" + + " @NonNull Object getObject(@Nullable Object o) {\n" + + " return o;\n" + // 'o' is only potentially null + " }\n" + + "}\n" + }, + customOptions, + ""); +} +// mixed use of fully qualified name / explicit import +public void test_annotation_import_001() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + runConformTestWithLibs( + new String[] { + CUSTOM_NULLABLE_NAME, + CUSTOM_NULLABLE_CONTENT, + CUSTOM_NONNULL_NAME, + CUSTOM_NONNULL_CONTENT, + "Lib.java", + "public class Lib {\n" + + " @org.foo.NonNull Object getObject() { return new Object(); }\n" + // FQN + "}\n", + "X.java", + "import org.foo.NonNull;\n" + // explicit import + "public class X {\n" + + " @NonNull Object getObject(@NonNull Lib l) {\n" + + " return l.getObject();\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); +} + +// use of explicit imports throughout +public void test_annotation_import_002() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + runConformTest( + new String[] { + CUSTOM_NULLABLE_NAME, + CUSTOM_NULLABLE_CONTENT, + CUSTOM_NONNULL_NAME, + CUSTOM_NONNULL_CONTENT, + "Lib.java", + "import org.foo.NonNull;\n" + + "public class Lib {\n" + + " @NonNull Object getObject() { return new Object(); }\n" + + "}\n", + "X.java", + "import org.foo.NonNull;\n" + + "public class X {\n" + + " @NonNull Object getObject(@org.foo.Nullable String dummy, @NonNull Lib l) {\n" + + " Object o = l.getObject();" + + " return o;\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); +} +// explicit import of existing annotation types +// using a Lib without null specifications +public void test_annotation_import_005() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.MayBeNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.MustNotBeNull"); + runNegativeTest( + true/*shouldFlushOutputDirectory*/, + new String[] { + "org/foo/MayBeNull.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + targetTypeUseIfAvailable() + + "public @interface MayBeNull {}\n", + + "org/foo/MustNotBeNull.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + targetTypeUseIfAvailable() + + "public @interface MustNotBeNull {}\n", + + "Lib.java", + "public class Lib {\n" + + " public Object getObject() { return new Object(); }\n" + + "}\n", + "X.java", + "import org.foo.*;\n" + + "public class X {\n" + + " @MustNotBeNull Object getObject(@MustNotBeNull Lib l) {\n" + + " return l.getObject();\n" + + " }\n" + + "}\n", + + }, + null /*no libs*/, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return l.getObject();\n" + + " ^^^^^^^^^^^^^\n" + + nullTypeSafety() + "The expression of type 'Object' needs unchecked conversion to conform to \'@MustNotBeNull Object\'\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// a non-null method returns a value obtained from an unannotated method, missing annotation types +public void test_annotation_import_006() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.MayBeNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.MustNotBeNull"); + runNegativeTest( + true/*shouldFlushOutputDirectory*/, + new String[] { + "Lib.java", + "public class Lib {\n" + + " Object getObject() { return new Object(); }\n" + + "}\n", + "X.java", + "public class X {\n" + + " @MustNotBeNull Object getObject(@MustNotBeNull Lib l) {\n" + + " return l.getObject();\n" + + " }\n" + + "}\n" + }, + null /* no libs */, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @MustNotBeNull Object getObject(@MustNotBeNull Lib l) {\n" + + " ^^^^^^^^^^^^^\n" + + "MustNotBeNull cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " @MustNotBeNull Object getObject(@MustNotBeNull Lib l) {\n" + + " ^^^^^^^^^^^^^\n" + + "MustNotBeNull cannot be resolved to a type\n" + + "----------\n", + JavacTestOptions.DEFAULT); +} + +// a null annotation is illegally used on a class: +public void test_illegal_annotation_001() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNull public class X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @NonNull public class X {\n" + + " ^^^^^^^^\n" + + ((this.complianceLevel < ClassFileConstants.JDK1_8) + ? "The annotation @NonNull is disallowed for this location\n" + : "The nullness annotation 'NonNull' is not applicable at this location\n") + + "----------\n"); +} +// this test has been removed: +// setting default to nullable, default applies to a parameter +// public void test_default_nullness_001() + +// a null annotation is illegally defined by its simple name +// disabled because specific error is not currently raised +public void _test_illegal_annotation_002() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "NichtNull"); + runNegativeTestWithLibs( + new String[] { + "X.java", + "public class X {\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "Cannot use the unqualified name \'NichtNull\' as an annotation name for null specification\n" + + "----------\n"); +} + +// a null annotation is illegally used on a void method: +public void test_illegal_annotation_003() { + runNegativeTest( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @NonNull void foo() {}\n" + + " ^^^^^^^^\n" + + ((this.complianceLevel < ClassFileConstants.JDK1_8) + ? "The nullness annotation @NonNull is not applicable for the primitive type void\n" + : "Type annotation is illegal for a method that returns void\n") + + "----------\n", + this.LIBS, + false/*shouldFlush*/); +} + +// a null annotation is illegally used on an int method: +public void test_illegal_annotation_003b() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull int foo() { return 1; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @NonNull int foo() { return 1; }\n" + + " ^^^^^^^^\n" + + "The nullness annotation @NonNull is not applicable for the primitive type int\n" + + "----------\n"); +} + +// a null annotation is illegally used on a primitive type parameter +public void test_illegal_annotation_004() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@Nullable int i) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo(@Nullable int i) {}\n" + + " ^^^^^^^^^\n" + + "The nullness annotation @Nullable is not applicable for the primitive type int\n" + + "----------\n"); +} + +// a null annotation is illegally used on a primitive type local var +public void test_illegal_annotation_005() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " int foo() {\n" + + " @Nullable int i = 3;\n" + + " return i;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Nullable int i = 3;\n" + + " ^^^^^^^^^\n" + + "The nullness annotation @Nullable is not applicable for the primitive type int\n" + + "----------\n"); +} + +// a configured annotation type does not exist +// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=186342#c133 +public void test_illegal_annotation_006() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "nullAnn.Nullable"); + runNegativeTest( + new String[] { + "p/Test.java", + "package p;\n" + + "import nullAnn.*; // 1 \n" + + "\n" + + "public class Test { \n" + + "\n" + + " void foo(@nullAnn.Nullable Object o) { // 2\n" + + " o.toString(); \n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p\\Test.java (at line 2)\n" + + " import nullAnn.*; // 1 \n" + + " ^^^^^^^\n" + + "The import nullAnn cannot be resolved\n" + + "----------\n" + + "2. ERROR in p\\Test.java (at line 6)\n" + + " void foo(@nullAnn.Nullable Object o) { // 2\n" + + " ^^^^^^^\n" + + "nullAnn cannot be resolved to a type\n" + + "----------\n", + this.LIBS, + true, // flush + customOptions); +} + +// a configured annotation type does not exist +// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=186342#c186 +public void test_illegal_annotation_007() { + Map customOptions = getCompilerOptions(); + runNegativeTest( + new String[] { + "p/Test.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "interface TestInt{\n" + + " @NonNull Object foo();\n" + + "}\n" + + "\n" + + "public class Test { \n" + + " void bar() {" + + " new TestInt() {\n" + + " @org public Object foo() {\n" + + " }\n" + + " };\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in p\\Test.java (at line 9)\n" + + " @org public Object foo() {\n" + + " ^^^\n" + + "org cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in p\\Test.java (at line 9)\n" + + " @org public Object foo() {\n" + + " ^^^^^^\n" + + "The return type is incompatible with '@NonNull Object' returned from TestInt.foo() (mismatching null constraints)\n" + + "----------\n", + this.LIBS, + true, // flush + customOptions); +} + +// a null annotation is illegally used on a constructor: +public void test_illegal_annotation_008() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull X() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @NonNull X() {}\n" + + " ^^^^^^^^\n" + + ((this.complianceLevel < ClassFileConstants.JDK1_8) + ? "The annotation @NonNull is disallowed for this location\n" + : "The nullness annotation 'NonNull' is not applicable at this location\n" ) + + "----------\n"); +} + +public void test_default_nullness_002() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); +// This option currently does nothing: +// customOptions.put(JavaCore.COMPILER_NONNULL_IS_DEFAULT, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " Object getObject(@Nullable Object o) {\n" + + " return new Object();\n" + + " }\n" + + "}\n", + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y extends X {\n" + + " @Override\n" + + " @Nullable Object getObject(Object o) {\n" + // complain illegal return redef and inherited annot is not repeated + " return o;\n" + + " }\n" + + "}\n", + }, + customOptions, + // main error: + "----------\n" + + "1. ERROR in Y.java (at line 5)\n" + + " @Nullable Object getObject(Object o) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with '@NonNull Object' returned from X.getObject(Object) (mismatching null constraints)\n" + + "----------\n" + + // additional error: + "2. ERROR in Y.java (at line 5)\n" + + " @Nullable Object getObject(Object o) {\n" + + " ^^^^^^\n" + + "Illegal redefinition of parameter o, inherited method from X declares this parameter as @Nullable\n" + + "----------\n"); +} + +public void test_default_nullness_002_custom() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + runner.customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "org.foo.NonNullByDefault"); + runner.testFiles = + new String[] { + CUSTOM_NULLABLE_NAME, + CUSTOM_NULLABLE_CONTENT, + CUSTOM_NNBD_NAME, + CUSTOM_NNBD_CONTENT, + "X.java", + "import org.foo.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " Object getObject(@Nullable Object o) {\n" + + " return new Object();\n" + + " }\n" + + "}\n", + "Y.java", + "import org.foo.*;\n" + + "@NonNullByDefault\n" + + "public class Y extends X {\n" + + " @Override\n" + + " @Nullable Object getObject(Object o) {\n" + // complain illegal return redef and inherited annot is not repeated + " return o;\n" + + " }\n" + + "}\n", + }; + runner.expectedCompilerLog = + // main error: + "----------\n" + + "1. ERROR in Y.java (at line 5)\n" + + " @Nullable Object getObject(Object o) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with '@NonNull Object' returned from X.getObject(Object) (mismatching null constraints)\n" + + "----------\n" + + // additional error: + "2. ERROR in Y.java (at line 5)\n" + + " @Nullable Object getObject(Object o) {\n" + + " ^^^^^^\n" + + "Illegal redefinition of parameter o, inherited method from X declares this parameter as @Nullable\n" + + "----------\n"; + runner.runNegativeTest(); +} + +// package default is non-null +public void test_default_nullness_003() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " protected Object getObject(@Nullable Object o) {\n" + + " return new Object();\n" + + " }\n" + + "}\n", + "p2/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p2;\n", + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y extends p1.X {\n" + + " @Override\n" + + " protected @Nullable Object getObject(@Nullable Object o) {\n" + + " bar(o);\n" + + " return o;\n" + + " }\n" + + " void bar(Object o2) { }\n" + // parameter is nonnull per package default + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p2\\Y.java (at line 5)\n" + + " protected @Nullable Object getObject(@Nullable Object o) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with '@NonNull Object' returned from X.getObject(Object) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in p2\\Y.java (at line 6)\n" + + " bar(o);\n" + + " ^\n" + + mismatch_NonNull_Nullable("Object") + + "----------\n"); +} +// package level default is consumed from package-info.class, similarly for type level default +public void test_default_nullness_003a() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " protected Object getObject(@Nullable Object o) {\n" + + " return new Object();\n" + + " }\n" + + " protected void bar(Object o2) { }\n" + // parameter is nonnull per type default + "}\n", + "p2/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p2;\n", + }, + customOptions, + ""); + // check if default is visible from package-info.class. + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y extends p1.X {\n" + + " @Override\n" + + " protected @Nullable Object getObject(@Nullable Object o) {\n" + // can't override inherited default nonnull + " bar(o);\n" + // parameter is nonnull in super class's .class file + " accept(o);\n" + + " return o;\n" + + " }\n" + + " void accept(Object a) {}\n" + // governed by package level default + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p2\\Y.java (at line 5)\n" + + " protected @Nullable Object getObject(@Nullable Object o) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with '@NonNull Object' returned from X.getObject(Object) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in p2\\Y.java (at line 6)\n" + + " bar(o);\n" + + " ^\n" + + mismatch_NonNull_Nullable("Object") + + "----------\n" + + "3. ERROR in p2\\Y.java (at line 7)\n" + + " accept(o);\n" + + " ^\n" + + mismatch_NonNull_Nullable("Object") + + "----------\n"); +} +// same as test_default_nullness_003a, but default-induced annotations are combined with explicit ones (not null related) +public void test_default_nullness_003b() { + Map customOptions = getCompilerOptions(); + runConformTestWithLibs( + new String[] { + "p1/Annot.java", + "package p1;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({METHOD,PARAMETER})\n" + + "public @interface Annot {}\n", + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " protected @Annot Object getObject(@Annot @Nullable Object o) {\n" + + " return new Object();\n" + + " }\n" + + " protected @Annot void bar(@Annot Object o2) { }\n" + // parameter is nonnull per type default + "}\n", + "p2/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p2;\n", + }, + customOptions, + ""); + // check if default is visible from package-info.class. + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y extends p1.X {\n" + + " @Override\n" + + " protected @Nullable Object getObject(@Nullable Object o) {\n" + // can't override inherited default nonnull + " bar(o);\n" + // parameter is nonnull in super class's .class file + " accept(o);\n" + + " return o;\n" + + " }\n" + + " void accept(@p1.Annot Object a) {}\n" + // governed by package level default + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p2\\Y.java (at line 5)\n" + + " protected @Nullable Object getObject(@Nullable Object o) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with '@NonNull Object' returned from X.getObject(Object) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in p2\\Y.java (at line 6)\n" + + " bar(o);\n" + + " ^\n" + + mismatch_NonNull_Nullable("Object") + + "----------\n" + + "3. ERROR in p2\\Y.java (at line 7)\n" + + " accept(o);\n" + + " ^\n" + + mismatch_NonNull_Nullable("Object") + + "----------\n"); +} +// package level default is consumed from package-info.class, similarly for type level default - fine tuned default +public void test_default_nullness_003c() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // uses version 2.0 of @NonNullByDefault + Map customOptions = getCompilerOptions(); + runConformTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " protected Object getObject(@Nullable Object o) {\n" + + " return new Object();\n" + + " }\n" + + " protected void bar(Object o2) { }\n" + // parameter is nonnull per type default + "}\n", + "p2/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault({org.eclipse.jdt.annotation.DefaultLocation.PARAMETER})\n" + + "package p2;\n", + }, + customOptions, + ""); + // check if default is visible from package-info.class. + runNegativeTestWithLibs( + false, // don't flush + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y extends p1.X {\n" + + " @Override\n" + + " protected @Nullable Object getObject(@Nullable Object o) {\n" + // can't override inherited default nonnull + " bar(o);\n" + // parameter is nonnull in super class's .class file + " @NonNull Object nno = accept(o); // 2xERR\n" + + " return o;\n" + + " }\n" + + " Object accept(Object a) { return a; }\n" + // governed by package level default (only the parameter!) + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p2\\Y.java (at line 5)\n" + + " protected @Nullable Object getObject(@Nullable Object o) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with '@NonNull Object' returned from X.getObject(Object) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in p2\\Y.java (at line 6)\n" + + " bar(o);\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable Object\'\n" + + "----------\n" + + "3. WARNING in p2\\Y.java (at line 7)\n" + + " @NonNull Object nno = accept(o); // 2xERR\n" + + " ^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'Object\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n" + + "4. ERROR in p2\\Y.java (at line 7)\n" + + " @NonNull Object nno = accept(o); // 2xERR\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable Object\'\n" + + "----------\n"); +} +// don't apply type-level default to non-reference type +public void test_default_nullness_004() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " protected Object getObject(boolean o) {\n" + + " return new Object();\n" + + " }\n" + + "}\n", + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y extends p1.X {\n" + + " @Override\n" + + " protected @NonNull Object getObject(boolean o) {\n" + + " return o ? this : new Object();\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); +} +// package default is non-null +// see also Bug 354536 - compiling package-info.java still depends on the order of compilation units +public void test_default_nullness_005() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + runNegativeTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " class Inner {" + + " protected Object getObject(String s) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n", + "p1/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;\n", + CUSTOM_NONNULL_NAME, + CUSTOM_NONNULL_CONTENT, + CUSTOM_NULLABLE_NAME, + CUSTOM_NULLABLE_CONTENT + }, + customOptions, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " return null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// package default is non-null, package-info.java read before the annotation type +// compile order: beginToCompile(X.Inner) triggers reading of package-info.java before the annotation type was read +public void test_default_nullness_006() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + runNegativeTestWithLibs( + new String[] { + "p1/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;\n", + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " class Inner {" + + " protected Object getObject(String s) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n", + CUSTOM_NONNULL_NAME, + CUSTOM_NONNULL_CONTENT, + CUSTOM_NULLABLE_NAME, + CUSTOM_NULLABLE_CONTENT + }, + customOptions, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " return null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// global default nonnull, but return may be null +// DISABLED due to dysfunctional global default after Bug 366063 - Compiler should not add synthetic @NonNull annotations +public void _test_default_nullness_007() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); +// customOptions.put(JavaCore.COMPILER_NONNULL_IS_DEFAULT, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object dangerous() {\n" + + " return null;\n" + + " }\n" + + " Object broken() {\n" + + " return dangerous();\n" + + " }\n" + + "}\n", + + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return dangerous();\n" + + " ^^^^^^^^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is inferred as @Nullable\n" + + "----------\n"); +} + +// cancel type level default to comply with super specification +public void test_default_nullness_008() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " protected Object getObject(Object o) {\n" + + " return new Object();\n" + + " }\n" + + "}\n", + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y extends p1.X {\n" + + " @Override\n" + + cancenNonNullByDefault() + + " protected Object getObject(Object o) {\n" + + " if (o.toString().length() == 0)\n" + // dereference without a warning + " return null;\n" + // return null without a warning + " return o.toString();\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); +} + +// cancel outer type level default to comply with super specification +public void test_default_nullness_009() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " protected Object getObject(Object o) {\n" + + " return new Object();\n" + + " }\n" + + "}\n", + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y { \n" + + cancenNonNullByDefault() + + " static class Z extends p1.X {\n" + + " @Override\n" + + " protected Object getObject(Object o) {\n" + + " if (o.toString().length() == 0) {\n" + + " o = null;\n" + // assign null without a warning + " bar(o); // error: arg is declared @NonNull\n" + + " return null;\n" + + " }\n" + + " return o.toString();\n" + + " }\n" + + " String bar(@NonNull Object o) {\n" + + " return getObject(o).toString();" + + " }\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p2\\Y.java (at line 11)\n" + + " bar(o); // error: arg is declared @NonNull\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// non-null declarations are redundant within a default scope. +public void test_default_nullness_010() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); + runWarningTestWithLibs( + true, // flush + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y {\n" + + " protected @NonNull Object getObject(@NonNull Object o) {\n" + + " return o;\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. WARNING in p2\\Y.java (at line 5)\n" + + " protected @NonNull Object getObject(@NonNull Object o) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The nullness annotation is redundant with a default that applies to this location\n" + + "----------\n" + + "2. WARNING in p2\\Y.java (at line 5)\n" + + " protected @NonNull Object getObject(@NonNull Object o) {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The nullness annotation is redundant with a default that applies to this location\n" + + "----------\n"); +} +// package-info declares nonnull-by-default +// special compile order due to import of type from that package +// cf. https://bugs.eclipse.org/bugs/show_bug.cgi?id=186342#add_comment +public void test_default_nullness_011() { + runNegativeTestWithLibs( + new String[] { + "Main.java", + "import p1.C;\n" + + "public class Main {\n" + + " void test(@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " o = null;\n" + + " new C(null);\n" + + " }\n" + + "}\n", + "p1/C.java", + "package p1;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class C {\n" + + " public C (Object o) {}\n" + + "}\n", + "p1/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;\n" + }, + "----------\n" + + "1. ERROR in Main.java (at line 4)\n" + + " o = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in Main.java (at line 5)\n" + + " new C(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p1\\C.java (at line 2)\n" + + " @org.eclipse.jdt.annotation.NonNullByDefault\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing package p1\n" + + "----------\n"); +} +// Bug 365836 - [compiler][null] Incomplete propagation of null defaults. +public void test_default_nullness_012() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class X {\n" + + " @NonNullByDefault \n" + + " public void foo(@Nullable String [] args) {\n" + + " class local {\n" + + " void zoo(Object o) {\n" + + " }\n" + + " };\n" + + " new local().zoo(null); // defaults applying from foo\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " new local().zoo(null); // defaults applying from foo\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// Bug 365836 - [compiler][null] Incomplete propagation of null defaults. +public void test_default_nullness_013() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@SuppressWarnings(\"unused\")\n" + + "public class X {\n" + + " @NonNullByDefault \n" + + " public void foo(@Nullable String [] args) {\n" + + " class local {\n" + + " class Deeply {\n" + + " Object zoo() {\n" + + " return null; // defaults applying from foo\n" + + " }\n" + + " }\n" + + " };\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " return null; // defaults applying from foo\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// bug 367154 - [compiler][null] Problem in propagating null defaults. +public void test_default_nullness_014() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@SuppressWarnings(\"unused\")\n" + + "public class X {\n" + + "\n" + + " public void foo(@Nullable String [] args) {\n" + + " @NonNullByDefault\n" + + " class local {\n" + + " class Deeply {\n" + + " Object zoo() {\n" + + " return null; // expect error here\n" + + " }\n" + + " }\n" + + " };\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " return null; // expect error here\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// bug 367154 - [compiler][null] Problem in propagating null defaults. +// initializer involved +public void test_default_nullness_015() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@SuppressWarnings(\"unused\")\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " {\n" + + " class local {\n" + + " class Deeply {\n" + + " Object zoo() {\n" + + " return null; // expect error here\n" + + " }\n" + + " }\n" + + " };\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " return null; // expect error here\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} + +// default nullness applied to fields, class-level: +public void test_default_nullness_016() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " Object foo;\n" + + " void doFoo() {\n" + + " foo = null;\n" + + " }\n" + + " class Inner {\n" + + " Object iFoo;\n" + + " void diFoo(@Nullable Object arg) {\n" + + " iFoo = arg;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Object foo;\n" + + " ^^^\n" + + "The @NonNull field foo may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " foo = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Object iFoo;\n" + + " ^^^^\n" + + "The @NonNull field iFoo may not have been initialized\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " iFoo = arg;\n" + + " ^^^\n" + + mismatch_NonNull_Nullable("Object") + + "----------\n"); +} + +// default nullness applied to fields, method level applied to local class + redundant annotation +public void test_default_nullness_017() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNullByDefault\n" + + " Object doFoo() {\n" + + " class Local {\n" + + " Object foo;\n" + + " @NonNull Object goo;\n" + + " };" + + " return new Local();\n" + + " }\n" + + "}\n", + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Object foo;\n" + + " ^^^\n" + + "The @NonNull field foo may not have been initialized\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " @NonNull Object goo;\n" + + " ^^^^^^^^^^^^^^^\n" + + "The nullness annotation is redundant with a default that applies to this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " @NonNull Object goo;\n" + + " ^^^\n" + + "The @NonNull field goo may not have been initialized\n" + + "----------\n"); +} + +// package case +public void test_nullness_default_018() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.WARNING); + customOptions.put(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "pack/NullWarn.java", + "package pack;\n" + + "@SuppressWarnings(\"null\")\n" + + "public class NullWarn {\n" + + "\n" + + " // Some code\n" + + "\n" + + "}\n" + }, + customOptions, + ""); + +} + +// type case (inside default package) +public void test_nullness_default_018b() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.WARNING); + customOptions.put(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "NullWarn.java", + "@SuppressWarnings(\"null\")\n" + + "public class NullWarn {\n" + + "\n" + + " // Some code\n" + + "\n" + + "}\n" + }, + customOptions, + ""); + +} + +// redundant default annotations - class vs. inner class +public void test_redundant_annotation_01() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); + runWarningTestWithLibs( + true, + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y {\n" + + " @NonNullByDefault class Inner {\n" + + " @NonNullByDefault class DeepInner {}\n" + + " }\n" + + " class Inner2 {\n" + + " @NonNullByDefault class DeepInner2 {\n" + + " }\n" + + " void foo() {\n" + + " @SuppressWarnings(\"unused\") @NonNullByDefault class Local {}\n" + + " }\n" + + " }\n" + + "}\n" + + "@NonNullByDefault class V {}\n", + "p3/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault package p3;\n", + "p3/Z.java", + "package p3;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Z {\n" + + "}\n" + + "class X {\n" + + " @NonNullByDefault class Inner {}\n" + + " class Inner2 {\n" + + " @NonNullByDefault class DeepInner {}\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. WARNING in p2\\Y.java (at line 5)\n" + + " @NonNullByDefault class Inner {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type Y\n" + + "----------\n" + + "2. WARNING in p2\\Y.java (at line 6)\n" + + " @NonNullByDefault class DeepInner {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type Y.Inner\n" + + "----------\n" + + "3. WARNING in p2\\Y.java (at line 9)\n" + + " @NonNullByDefault class DeepInner2 {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type Y\n" + + "----------\n" + + "4. WARNING in p2\\Y.java (at line 12)\n" + + " @SuppressWarnings(\"unused\") @NonNullByDefault class Local {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type Y\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p3\\Z.java (at line 3)\n" + + " @NonNullByDefault\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing package p3\n" + + "----------\n" + + "2. WARNING in p3\\Z.java (at line 7)\n" + + " @NonNullByDefault class Inner {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing package p3\n" + + "----------\n" + + "3. WARNING in p3\\Z.java (at line 9)\n" + + " @NonNullByDefault class DeepInner {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing package p3\n" + + "----------\n"); +} + +// redundant default annotations - class vs. method +public void test_redundant_annotation_02() { + Map customOptions = getCompilerOptions(); + runWarningTestWithLibs( + true, + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y {\n" + + " @NonNullByDefault void foo() {}\n" + + "}\n" + + "class Z {\n" + + " @NonNullByDefault void bar() {\n" + + " @NonNullByDefault @SuppressWarnings(\"unused\") class Zork {\n" + + " @NonNullByDefault void fubar() {}\n" + + " }\n" + + " }\n" + + " @NonNullByDefault void zink() {\n" + + " @SuppressWarnings(\"unused\") class Bork {\n" + + " @NonNullByDefault void jubar() {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. WARNING in p2\\Y.java (at line 5)\n" + + " @NonNullByDefault void foo() {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type Y\n" + + "----------\n" + + "2. WARNING in p2\\Y.java (at line 9)\n" + + " @NonNullByDefault @SuppressWarnings(\"unused\") class Zork {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing method bar()\n" + + "----------\n" + + "3. WARNING in p2\\Y.java (at line 10)\n" + + " @NonNullByDefault void fubar() {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type Zork\n" + + "----------\n" + + "4. WARNING in p2\\Y.java (at line 15)\n" + + " @NonNullByDefault void jubar() {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing method zink()\n" + + "----------\n"); +} + +//redundant default annotations - class vs. method - generics +public void test_redundant_annotation_02g() { + Map customOptions = getCompilerOptions(); + runWarningTestWithLibs( + true, + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y {\n" + + " @NonNullByDefault void foo(TF arg) {}\n" + + "}\n" + + "class Z {\n" + + " @NonNullByDefault void bar() {\n" + + " @NonNullByDefault @SuppressWarnings(\"unused\") class Zork {\n" + + " @NonNullByDefault void fubar(TB arg) {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. WARNING in p2\\Y.java (at line 5)\n" + + " @NonNullByDefault void foo(TF arg) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type Y\n" + + "----------\n" + + "2. WARNING in p2\\Y.java (at line 9)\n" + + " @NonNullByDefault @SuppressWarnings(\"unused\") class Zork {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing method bar()\n" + + "----------\n" + + "3. WARNING in p2\\Y.java (at line 10)\n" + + " @NonNullByDefault void fubar(TB arg) {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type Zork\n" + + "----------\n"); +} + +// test missing default nullness annotation for types in default package +public void test_missing_default_annotation_01() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "Lib.java", + "public class Lib {\n" + + " Object getObject() { return new Object(); }\n" + + "}\n", + "X.java", + "public class X {\n" + + " class XInner{}\n" + // don't warn for inner types + " Object getObject(Lib l) {\n" + + " return l.getObject();\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Lib.java (at line 1)\n" + + " public class Lib {\n" + + " ^^^\n" + + "A default nullness annotation has not been specified for the type Lib\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X {\n" + + " ^\n" + + "A default nullness annotation has not been specified for the type X\n" + + "----------\n"); +} + +// test missing default nullness annotation for a package with package-info +public void test_missing_default_annotation_02() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "p2/package-info.java", + "package p2;\n", + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y {\n" + + " void foo() {}\n" + + "}\n", + "p3/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault package p3;\n", + "p3/Z.java", + "package p3;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Z {\n" + + " @NonNullByDefault void bar() {}\n" + + "}\n", + }, + customOptions, + "----------\n" + + "1. ERROR in p2\\package-info.java (at line 1)\n" + + " package p2;\n" + + " ^^\n" + + "A default nullness annotation has not been specified for the package p2\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p3\\Z.java (at line 4)\n" + + " @NonNullByDefault void bar() {}\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing package p3\n" + + "----------\n"); +} + +// redundant default annotations - class vs. inner class +// ensure that disabling null annotations also disables this diagnostic +public void test_redundant_annotation_04() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.DISABLED); + runConformTestWithLibs( + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Y {\n" + + " @NonNullByDefault class Inner {\n" + + " @NonNullByDefault class DeepInner {}\n" + + " }\n" + + " class Inner2 {\n" + + " @NonNullByDefault class DeepInner2 {\n" + + " }\n" + + " @NonNullByDefault void foo(@Nullable @NonNull Object arg) {\n" + + " @NonNullByDefault class Local {}\n" + + " }\n" + + " }\n" + + "}\n" + + "@NonNullByDefault class V {}\n", + "p3/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault package p3;\n", + "p3/Z.java", + "package p3;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Z {\n" + + "}\n" + + "class X {\n" + + " @NonNullByDefault class Inner {}\n" + + " class Inner2 {\n" + + " @NonNullByDefault class DeepInner {}\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); +} + +// contradictory null annotations +public void test_contradictory_annotations_01() { + Map customOptions = getCompilerOptions(); + runNegativeTestWithLibs( + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " void foo(@NonNull @Nullable Object o) {}\n" + + " @Nullable @NonNull Object bar() {\n" + + " @NonNull @Nullable Object o = null;\n" + + " return o;\n" + + " }\n" + + "}\n" + + "class Z {\n" + + " @NonNullByDefault void bar() {}\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p2\\Y.java (at line 4)\n" + + " void foo(@NonNull @Nullable Object o) {}\n" + + " ^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + + "2. ERROR in p2\\Y.java (at line 5)\n" + + " @Nullable @NonNull Object bar() {\n" + + " ^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + + "3. ERROR in p2\\Y.java (at line 6)\n" + + " @NonNull @Nullable Object o = null;\n" + + " ^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n"); +} + +// contradictory null annotations on a field +public void test_contradictory_annotations_02() { + Map customOptions = getCompilerOptions(); + runNegativeTestWithLibs( + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " @NonNull @Nullable Object o;\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p2\\Y.java (at line 4)\n" + + " @NonNull @Nullable Object o;\n" + + " ^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n"); +} + +// contradictory null annotations on a field - array type +public void test_contradictory_annotations_03() { + Map customOptions = getCompilerOptions(); + runNegativeTestWithLibs( + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " @NonNull @Nullable Object[] o;\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p2\\Y.java (at line 4)\n" + + " @NonNull @Nullable Object[] o;\n" + + " ^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n"); +} + +// a nonnull variable is dereferenced in a loop +public void test_nonnull_var_in_constrol_structure_1() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); +// This option currently does nothing: +// customOptions.put(JavaCore.COMPILER_NONNULL_IS_DEFAULT, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void print4(@NonNull String s) {\n" + + " for (int i=0; i<4; i++)\n" + + " print(s);\n" + + " }\n" + + " void print5(@Nullable String s) {\n" + + " for (int i=0; i<5; i++)\n" + + " print(s);\n" + + " }\n" + + " void print6(boolean b) {\n" + + " String s = b ? null : \"\";\n" + + " for (int i=0; i<5; i++)\n" + + " print(s);\n" + + " }\n" + + " void print(@NonNull String s) {\n" + + " System.out.print(s);\n" + + " }\n" + + "}\n", + + }, + customOptions, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void print4(@NonNull String s) {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The nullness annotation is redundant with a default that applies to this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " print(s);\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " print(s);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is inferred as @Nullable\n" + + "----------\n" + + "4. WARNING in X.java (at line 17)\n" + + " void print(@NonNull String s) {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The nullness annotation is redundant with a default that applies to this location\n" + + "----------\n"); +} +// a nonnull variable is dereferenced in a finally block +public void test_nonnull_var_in_constrol_structure_2() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); +// This option currently does nothing: +// customOptions.put(JavaCore.COMPILER_NONNULL_IS_DEFAULT, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void print4(String s) {\n" + + " try { /*empty*/ } finally {\n" + + " print(s);\n" + + " }\n" + + " }\n" + + " void print5(@Nullable String s) {\n" + + " try { /*empty*/ } finally {\n" + + " print(s);\n" + + " }\n" + + " }\n" + + " void print6(boolean b) {\n" + + " String s = b ? null : \"\";\n" + + " try { /*empty*/ } finally {\n" + + " print(s);\n" + + " }\n" + + " }\n" + + " void print(String s) {\n" + + " System.out.print(s);\n" + + " }\n" + + "}\n", + + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " print(s);\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " print(s);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is inferred as @Nullable\n" + + "----------\n"); +} +// a nonnull variable is dereferenced in a finally block inside a loop +public void test_nonnull_var_in_constrol_structure_3() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_ANNOTATION, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void print4(@NonNull String s) {\n" + + " for (int i=0; i<4; i++)\n" + + " try { /*empty*/ } finally {\n" + + " print(s);\n" + + " }\n" + + " }\n" + + " void print5(@Nullable String s) {\n" + + " for (int i=0; i<5; i++)\n" + + " try { /*empty*/ } finally {\n" + + " print(s);\n" + + " }\n" + + " }\n" + + " void print6(boolean b) {\n" + + " String s = b ? null : \"\";\n" + + " for (int i=0; i<4; i++)\n" + + " try { /*empty*/ } finally {\n" + + " print(s);\n" + + " }\n" + + " }\n" + + " void print(@NonNull String s) {\n" + + " System.out.print(s);\n" + + " }\n" + + "}\n", + + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " print(s);\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " print(s);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is inferred as @Nullable\n" + + "----------\n"); +} +// witness for an AIOOBE in FlowContext.recordExpectedType() +public void test_message_send_in_control_structure_01() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.IGNORE); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.WARNING); + runNegativeTestWithLibs( + new String[] { + "p/Scope.java", + "package p;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public abstract class Scope {\n" + + " public ReferenceBinding findMemberType(char[] typeName, ReferenceBinding enclosingType) {\n" + + " ReferenceBinding enclosingSourceType = enclosingSourceType();\n" + + " PackageBinding currentPackage = getCurrentPackage();\n" + + " CompilationUnitScope unitScope = compilationUnitScope();\n" + + " ReferenceBinding memberType = enclosingType.getMemberType(typeName);\n" + + " ReferenceBinding currentType = enclosingType;\n" + + " ReferenceBinding[] interfacesToVisit = null;\n" + + " while (true) {\n" + + " ReferenceBinding[] itsInterfaces = currentType.superInterfaces();\n" + + " if (itsInterfaces != null) {\n" + + " if (interfacesToVisit == null) {\n" + + " interfacesToVisit = itsInterfaces;\n" + + " }\n" + + " }\n" + + " unitScope.recordReference(currentType, typeName);\n" + + " \n" + + " if ((memberType = currentType.getMemberType(typeName)) != null) {\n" + + " if (enclosingSourceType == null\n" + + " ? memberType.canBeSeenBy(currentPackage)\n" + + " : memberType.canBeSeenBy(enclosingType, enclosingSourceType)) {\n" + + " return memberType;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " private CompilationUnitScope compilationUnitScope() {\n" + + " return compilationUnitScope();\n" + + " }\n" + + " private PackageBinding getCurrentPackage() {\n" + + " return getCurrentPackage();\n" + + " }\n" + + " private ReferenceBinding enclosingSourceType() {\n" + + " return enclosingSourceType();\n" + + " }\n" + + "}\n", + "p/CompilationUnitScope.java", + "package p;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class CompilationUnitScope {\n" + + " void recordReference(ReferenceBinding rb, char[] name) {}\n" + + "}\n", + "p/PackageBinding.java", + "package p;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class PackageBinding {\n" + + "}\n", + "p/ReferenceBinding.java", + "package p;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class ReferenceBinding {\n" + + " ReferenceBinding getMemberType(char[] name) { return this; }\n" + + " ReferenceBinding[] superInterfaces() { return new ReferenceBinding[0]; }\n" + + " boolean canBeSeenBy(PackageBinding ob) { return true; }\n" + + " boolean canBeSeenBy(ReferenceBinding rb, ReferenceBinding rb2) { return true; }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p\\Scope.java (at line 13)\n" + + " if (itsInterfaces != null) {\n" + + " ^^^^^^^^^^^^^\n" + + "Redundant null check: The variable itsInterfaces cannot be null at this location\n" + + "----------\n" + + "2. ERROR in p\\Scope.java (at line 20)\n" + + " if ((memberType = currentType.getMemberType(typeName)) != null) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant null check: The variable memberType cannot be null at this location\n" + + "----------\n" + + "3. ERROR in p\\Scope.java (at line 21)\n" + + " if (enclosingSourceType == null\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Null comparison always yields false: The variable enclosingSourceType cannot be null at this location\n" + + "----------\n"); +} + +// Bug 370930 - NonNull annotation not considered for enhanced for loops +public void test_message_send_in_control_structure_02() { + runWarningTestWithLibs( + true, // flush + new String[] { + "Bug370930.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class Bug370930 {\n" + + " void loop(Collection list) {\n" + + " for(@NonNull String s: list) { // warning here: insufficient info on elements\n" + + " expectNonNull(s); // no warning here\n" + + " }\n" + + " }\n" + + " \n" + + " void expectNonNull(@NonNull String s) {}\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Bug370930.java (at line 5)\n" + + " for(@NonNull String s: list) { // warning here: insufficient info on elements\n" + + " ^^^^\n" + + nullTypeSafety() + "The expression of type 'String' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n"); +} +//Bug 370930 - NonNull annotation not considered for enhanced for loops over array +public void test_message_send_in_control_structure_02a() { + runWarningTestWithLibs( + true, // flush + new String[] { + "Bug370930.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Bug370930 {\n" + + " void loop(String[] array) {\n" + + " for(@NonNull String s: array) { // warning here: insufficient info on elements\n" + + " expectNonNull(s); // no warning here\n" + + " }\n" + + " }\n" + + " \n" + + " void expectNonNull(@NonNull String s) {}\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Bug370930.java (at line 4)\n" + + " for(@NonNull String s: array) { // warning here: insufficient info on elements\n" + + " ^^^^^\n" + + nullTypeSafety() + "The expression of type 'String' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n"); +} +//Bug 370930 - NonNull annotation not considered for enhanced for loops +public void test_message_send_in_control_structure_03() { + runNegativeTestWithLibs( + new String[] { + "Bug370930.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class Bug370930 {\n" + + " void loop(Collection list) {\n" + + " for(@Nullable String s: list) {\n" + + " expectNonNull(s); // warning here\n" + + " }\n" + + " }\n" + + " \n" + + " void expectNonNull(@NonNull String s) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug370930.java (at line 6)\n" + + " expectNonNull(s); // warning here\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n"); +} +public void test_assignment_expression_1() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object foo() {\n" + + " Object o = null;\n" + + " boolean keepLooking = true;\n" + + " while(keepLooking) {\n" + + " if ((o=getO()) != null) {\n" + + " return o;\n" + + " }\n" + + " }\n" + + " return null;\n" + + " }\n" + + "\n" + + " private @Nullable Object getO() {\n" + + " return new Object();\n" + + " }\n" + + "}\n", + + }, + customOptions, + ""); +} +// a nonnull variable is dereferenced in a method of a nested type +public void test_nesting_1() { + Map customOptions = getCompilerOptions(); +// customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR); +// This option currently does nothing: +// customOptions.put(JavaCore.COMPILER_NONNULL_IS_DEFAULT, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void print4(final String s1) {\n" + + " for (int i=0; i<3; i++)\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " print(s1);\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " void print8(final @Nullable String s2) {\n" + + " for (int i=0; i<3; i++)\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " print(s2);\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " void print16(boolean b) {\n" + + " final String s3 = b ? null : \"\";\n" + + " for (int i=0; i<3; i++)\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " @NonNull String s3R = s3;\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " void print(String s) {\n" + + " System.out.print(s);\n" + + " }\n" + + "}\n", + + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " print(s2);\n" + + " ^^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "2. ERROR in X.java (at line 25)\n" + + " @NonNull String s3R = s3;\n" + + " ^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is inferred as @Nullable\n" + + "----------\n"); +} +// Test a regression incurred to the OT/J based implementation +// by the fix in Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) +public void test_constructor_with_nested_class() { + runConformTestWithLibs( + new String[] { + "X.java", + "public class X {\n" + + " final Object o1;\n" + + " final Object o2;\n" + + " public X() {\n" + + " this.o1 = new Object() {\n" + + " @Override\n" + + " public String toString() { return \"O1\"; }\n" + + " };\n" + + " this.o2 = new Object();" + + " }\n" + + "}\n" + }, + null,//options + ""); +} +// test analysis disablement, binary type contains annotation +public void test_options_01() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "ContainingInner2.java", + "public class ContainingInner2 {\n" + + " public ContainingInner2 (@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " }\n" + + " public class Inner {\n" + + " public Inner (@org.eclipse.jdt.annotation.NonNull T o) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + null /*customOptions*/, + ""); + customOptions.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.DISABLED); + runConformTestWithLibs( + false, // flush directory + new String[] { + "X.java", + "public class X {\n" + + " void create() {\n" + + " ContainingInner2 container = new ContainingInner2(null);\n" + + " ContainingInner2.Inner inner = container.new Inner(null);\n" + + " }\n" + + "}\n"}, + customOptions, + "" /* compiler output */); +} +// test illegally trying to ignore null spec violations +public void test_options_02() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION, JavaCore.IGNORE); // has no effect + runNegativeTestWithLibs( + new String[] { + "Test.java", + "public class Test {\n" + + " public void foo(@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " o = null;\n" + + " Object p = o;\n" + + " if (p == null)\n" + + " p.toString();\n" + + " }\n" + + "}\n", + }, + customOptions, + "----------\n" + + "1. ERROR in Test.java (at line 3)\n" + + " o = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in Test.java (at line 5)\n" + + " if (p == null)\n" + + " ^\n" + + "Null comparison always yields false: The variable p cannot be null at this location\n" + + "----------\n" + + "3. WARNING in Test.java (at line 6)\n" + + " p.toString();\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +// test setting null spec violations to "warning" +public void test_options_03() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION, JavaCore.WARNING); // OK + runNegativeTestWithLibs( + new String[] { + "Test.java", + "public class Test {\n" + + " public void foo(@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " o = null;\n" + + " Object p = o;\n" + + " if (p == null)\n" + + " p.toString();\n" + + " }\n" + + "}\n", + }, + customOptions, + "----------\n" + + "1. WARNING in Test.java (at line 3)\n" + + " o = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in Test.java (at line 5)\n" + + " if (p == null)\n" + + " ^\n" + + "Null comparison always yields false: The variable p cannot be null at this location\n" + + "----------\n" + + "3. WARNING in Test.java (at line 6)\n" + + " p.toString();\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +// access to a non-null field +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_1() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object o = new Object();\n" + + " public String oString() {\n" + + " return o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + ""); +} + +// a non-null field is not properly initialized +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_2() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object o;\n" + + " public String oString() {\n" + + " return o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @NonNull Object o;\n" + + " ^\n" + + "The @NonNull field o may not have been initialized\n" + + "----------\n"); +} + +// a non-null field is not properly initialized - explicit constructor +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_2a() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object o;\n" + + " X (boolean b) { // only potentially initialized\n" + + " if (b)\n" + + " o = this;\n" + + " }\n" + + " X (@NonNull Object other) {\n" + // no problem + " o = other;\n" + + " }\n" + + " public String oString() {\n" + + " return o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " X (boolean b) { // only potentially initialized\n" + + " ^^^^^^^^^^^^^\n" + + "The @NonNull field o may not have been initialized\n" + + "----------\n"); +} + +// a non-null field is not properly initialized - explicit constructor - incomplete switch +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_2b() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "enum Color { BLACK, GREEN }\n" + + "public class X {\n" + + " @NonNull Object o;\n" + + " X (Color c) { // only potentially initialized\n" + + " switch (c) {\n" + + " case BLACK: o = this; break;\n" + + " case GREEN: o = new Object(); break;\n" + + " }\n" + + " }\n" + + " public String oString() {\n" + + " return o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X (Color c) { // only potentially initialized\n" + + " ^^^^^^^^^^^\n" + + "The @NonNull field o may not have been initialized. Note that a problem regarding missing \'default:\' on \'switch\' has been suppressed, which is perhaps related to this problem\n" + + "----------\n"); +} + +// a non-null static field is not properly initialized +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_2c() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " static @NonNull Object o;\n" + + " static {\n" + + " if (new Object().hashCode() == 42)\n" + + " o = new Object();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " static @NonNull Object o;\n" + + " ^\n" + + "The @NonNull field o may not have been initialized\n" + + "----------\n"); +} + +// a non-null static field is properly initialized +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_2d() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " static @NonNull Object o;\n" + + " static {\n" + + " o = new Object();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + ""); +} + +// a non-null field is properly initialized - using this.f reference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_2e() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object f;\n" + + " {\n" + + " this.f = new Object();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + ""); +} + +// a non-null field is initialized to null +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_3() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object o = null;\n" + + " public String oString() {\n" + + " return o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @NonNull Object o = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// a non-null field is assigned to null +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_4() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object o = new Object();\n" + + " void breakIt1() {\n" + + " o = null;\n" + + " }\n" + + " void breakIt2() {\n" + + " this.o = null;\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " this.o = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// a non-null field is checked for null +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_5() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object o = new Object();\n" + + " boolean checkIt1() {\n" + + " return o == null;\n" + + " }\n" + + " boolean checkIt() {\n" + + " return this.o != null;\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return o == null;\n" + + " ^\n" + + checkAlwaysFalse_nonnull("The field o", "Object") + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return this.o != null;\n" + + " ^\n" + + redundant_check_nonnull("The field o", "@NonNull Object") + + "----------\n"); +} + +// a non-null field is checked for null twice - method call inbetween +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_6() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Object o = new Object();\n" + + " boolean checkIt1() {\n" + + " if (o != null)\n" + + " System.out.print(\"not null\");\n" + + " System.out.print(\"continue\");\n" + + " return this.o == null;\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o != null)\n" + + " ^\n" + + redundant_check_nonnull("The field o", "@NonNull Object") + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return this.o == null;\n" + + " ^\n" + + checkAlwaysFalse_nonnull("The field o", "Object") + + "----------\n"); +} + +// a non-null field is accessed via a qualified name reference - static field +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_7() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class Objects {\n" + + " static @NonNull Object o = new Object();\n" + + "}\n" + + "public class X {\n" + + " @NonNull Object getIt1() {\n" + + " if (Objects.o != null) // redundant\n" + + " System.out.print(\"not null\");\n" + + " System.out.print(\"continue\");\n" + + " return Objects.o;\n" + + " }\n" + + " @NonNull Object getIt2() {\n" + + " if (null != Objects.o) // redundant\n" + + " System.out.print(\"not null\");\n" + + " System.out.print(\"continue\");\n" + + " return Objects.o;\n" + + " }\n" + + " String getIt3() {\n" + + " return Objects.o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (Objects.o != null) // redundant\n" + + " ^\n" + + redundant_check_nonnull("The field o", "@NonNull Object") + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " if (null != Objects.o) // redundant\n" + + " ^\n" + + redundant_check_nonnull("The field o", "@NonNull Object") + + "----------\n"); +} + +// a non-null field is accessed via a qualified name reference - instance field +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_8() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class Objects {\n" + + " @NonNull Object o = new Object();\n" + + "}\n" + + "public class X {\n" + + " @NonNull Object getIt1(@NonNull Objects objs) {\n" + + " if (objs.o == null) // always false\n" + + " System.out.print(\"not null\");\n" + + " System.out.print(\"continue\");\n" + + " return objs.o;\n" + + " }\n" + + " String getIt2(@NonNull Objects objs) {\n" + + " return objs.o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (objs.o == null) // always false\n" + + " ^\n" + + checkAlwaysFalse_nonnull("The field o", "Object") + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " System.out.print(\"not null\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} + +// a non-null field is accessed via an indirect field reference - instance field +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_9() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class Objects {\n" + + " @NonNull Object o = new Object();\n" + + "}\n" + + "public class X {\n" + + " Objects objs = new Objects();\n" + + " @NonNull Object getIt1() {\n" + + " if (this.objs.o != null) // redundant\n" + + " System.out.print(\"not null\");\n" + + " System.out.print(\"continue\");\n" + + " if (getObjs().o != null) // redundant\n" + + " System.out.print(\"not null\");\n" + + " return this.objs.o;\n" + + " }\n" + + " Objects getObjs() { return this.objs; }\n" + + " String getIt2() {\n" + + " return this.objs.o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " if (this.objs.o != null) // redundant\n" + + " ^\n" + + redundant_check_nonnull("The field o", "@NonNull Object") + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " if (getObjs().o != null) // redundant\n" + + " ^\n" + + redundant_check_nonnull("The field o", "@NonNull Object") + + "----------\n"); +} + +// trying to assign null to a nonnull field via a single / a qualified name reference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_11() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class Objects {\n" + + " @NonNull Object o = new Object();\n" + + " void test0(@Nullable Object x) {\n" + + " o = x;\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " void test(@NonNull Objects objs) {\n" + + " objs.o = null;\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o = x;\n" + + " ^\n" + + mismatch_NonNull_Nullable("Object") + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " objs.o = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} + +// @NonNull is applied to a field with primitive type +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_12() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull int o = 1;\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @NonNull int o = 1;\n" + + " ^^^^^^^^\n" + + "The nullness annotation @NonNull is not applicable for the primitive type int\n" + + "----------\n"); +} + +// A final field is initialized to non-null, treat as effectively @NonNull +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void _test_nonnull_field_13() { + // withdrawn as of https://bugs.eclipse.org/331649#c75 + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " final String s1 = \"\";\n" + + " @NonNull String s2;\n" + + " X() {\n" + + " s2 = s1;\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + ""); +} + +// A field in a different CU is implicitly @NonNull (by type default) - that class is read from binary +// Assignment to other @NonNull field should not raise a warning +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_14() { + runConformTestWithLibs( + new String[] { + "p1/X.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " public String s1 = \"\";\n" + + "}\n", + }, + null /*customOptions*/, + ""); + runConformTestWithLibs( + false /*flush*/, + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "import p1.X;\n" + + "public class Y {\n" + + " @NonNull String s2 = \"\";\n" + + " void foo(X other) {\n" + + " s2 = other.s1;\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + ""); +} + +// A field in a different CU is implicitly @NonNull (by package default) - that class is read from binary +// Assignment to other @NonNull field should not raise a warning +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nonnull_field_14b() { + runConformTestWithLibs( + new String[] { + "p1/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;\n", + "p1/X.java", + "package p1;\n" + + "public class X {\n" + + " public String s1 = \"\";\n" + + "}\n", + }, + null /*customOptions*/, + ""); + runConformTestWithLibs( + false /*flush*/, + new String[] { + "p2/Y.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "import p1.X;\n" + + "public class Y {\n" + + " @NonNull String s2 = \"\";\n" + + " void foo(X other) {\n" + + " s2 = other.s1;\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + ""); +} + +// A @NonNull field is assumed to be initialized by the injection framework +// [compiler] Null analysis for fields does not take @com.google.inject.Inject into account +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400421 +public void test_nonnull_field_15() { + runConformTestWithLibs( + new String[] { + GOOGLE_INJECT_NAME, + GOOGLE_INJECT_CONTENT, + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import com.google.inject.Inject;\n" + + "public class X {\n" + + " @NonNull @Inject Object o;\n" + + " @NonNullByDefault class Inner {\n" + + " @Inject String s;\n" + + " }\n" + + "}\n", + }, + null /*customOptions*/, + ""); +} + +// Injection is optional, don't rely on the framework +// [compiler] Null analysis for fields does not take @com.google.inject.Inject into account +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400421 +public void test_nonnull_field_16() { + runNegativeTestWithLibs( + new String[] { + GOOGLE_INJECT_NAME, + GOOGLE_INJECT_CONTENT, + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import com.google.inject.Inject;\n" + + "public class X {\n" + + " @Inject(optional=true) @NonNull Object o;\n" + + " @NonNullByDefault class Inner {\n" + + " @Inject(optional=true) String s;\n" + + " @Inject(optional=false) String t;\n" + // don't complain here + " }\n" + + "}\n", + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Inject(optional=true) @NonNull Object o;\n" + + " ^\n" + + "The @NonNull field o may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " @Inject(optional=true) String s;\n" + + " ^\n" + + "The @NonNull field s may not have been initialized\n" + + "----------\n"); +} + +// Using javax.inject.Inject, slight variations +// [compiler] Null analysis for fields does not take @com.google.inject.Inject into account +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400421 +public void test_nonnull_field_17() { + runNegativeTestWithLibs( + new String[] { + JAVAX_INJECT_NAME, + JAVAX_INJECT_CONTENT, + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import javax.inject.Inject;\n" + + "public class X {\n" + + " @NonNull @Inject static String s; // warn since injection of static field is less reliable\n" + // variation: static field + " @NonNull @Inject @Deprecated Object o;\n" + + " public X() {}\n" + // variation: with explicit constructor + "}\n", + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @NonNull @Inject static String s; // warn since injection of static field is less reliable\n" + + " ^\n" + + "The @NonNull field s may not have been initialized\n" + + "----------\n"); +} + +// access to a nullable field - field reference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_1() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o = new Object();\n" + + " public String oString() {\n" + + " return this.o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return this.o.toString();\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n"); +} +// access to a nullable field - single name reference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_2() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o = new Object();\n" + + " public String oString() {\n" + + " return o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return o.toString();\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n"); +} +// access to a nullable field - qualified name reference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_3() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o = new Object();\n" + + " @Nullable X other;\n" + + " public String oString() {\n" + + " return other.o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return other.o.toString();\n" + + " ^^^^^\n" + + potNPE_nullable("The field other") + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " return other.o.toString();\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n"); +} +// access to a nullable field - qualified name reference - multiple segments +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_3m() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o = new Object();\n" + + " @Nullable X other;\n" + + " public String oString() {\n" + + " return other.other.o.toString();\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return other.other.o.toString();\n" + + " ^^^^^\n" + + potNPE_nullable("The field other") + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " return other.other.o.toString();\n" + + " ^^^^^\n" + + potNPE_nullable("The field other") + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " return other.other.o.toString();\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n"); +} +// access to a nullable field - dereference after check +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_4() { + // currently no flow analysis for fields is implemented, + // but the direct sequence of null-check + dereference is optionally supported as a special case + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o = new Object();\n" + + " public String oString() {\n" + + " if (this.o != null)\n" + + " return this.o.toString();\n" + // silent after check + " if (o != null)\n" + + " return o.toString();\n" + // silent after check + " return \"\";\n" + + " }\n" + + " public String oString2() {\n" + + " String local = o.toString();\n" + + " if (this.o != null) {\n" + + " this.toString();\n" + // method call wipes null info + " return this.o.toString(); // warn here\n" + + " }\n" + + " return \"\";\n" + + " }\n" + + "}\n" + }, + options /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " String local = o.toString();\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " return this.o.toString(); // warn here\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n"); +} + +// access to a nullable field - intermediate component in a QNR +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_5() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Y y = new Y();\n" + + " public String oString() {\n" + + " return y.z.o.toString(); // pot.NPE on z\n" + + " }\n" + + "}\n", + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " @Nullable Z z = new Z();\n" + + "}\n", + "Z.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Z {\n" + + " @NonNull Object o = new Object();\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return y.z.o.toString(); // pot.NPE on z\n" + + " ^\n" + + potNPE_nullable("The field z") + + "----------\n"); +} + +// access to a nullable field - intermediate component in a QNR - inverse of test_nullable_field_5 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_6() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Y y = new Y();\n" + + " public String oString() {\n" + + " return y.z.o.toString(); // pot.NPE on y and o\n" + + " }\n" + + "}\n", + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " @NonNull Z z = new Z();\n" + + "}\n", + "Z.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Z {\n" + + " Object dummy;\n" + // ensure different interal fieldId + " @Nullable Object o = new Object();\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return y.z.o.toString(); // pot.NPE on y and o\n" + + " ^\n" + + potNPE_nullable("The field y") + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " return y.z.o.toString(); // pot.NPE on y and o\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n"); +} + +// access to a nullable field - intermediate component in a double field reference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_7() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Y y = new Y();\n" + + " public String oString() {\n" + + " return this.y.o.toString(); // pot.NPE on y and o\n" + + " }\n" + + "}\n", + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " @Nullable Object o = new Object();\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return this.y.o.toString(); // pot.NPE on y and o\n" + + " ^\n" + + potNPE_nullable("The field y") + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " return this.y.o.toString(); // pot.NPE on y and o\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n"); +} + +// static access to a nullable field - qualified name reference +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_8() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable static final Object o = null;\n" + + " public void foo() {\n" + + " if (X.o == null){\n" + + " System.out.println(X.o);\n" + + " }\n" + + " }\n" + + "}\n" + }, + null /*customOptions*/, + ""); +} + +// illegal use of @Nullable for a field of primitive type +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_9() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable int i;\n" + + "}\n" + }, + null /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @Nullable int i;\n" + + " ^^^^^^^^^\n" + + "The nullness annotation @Nullable is not applicable for the primitive type int\n" + + "----------\n"); +} + +// protected access to nullable fields - different kinds of references +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_10a() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o1, o2, o3;\n" + + " @NonNull X x = new X();\n" + + " public void foo(X other) {\n" + + " if (other.o1 != null){\n" + // qualified reference -> block + " System.out.println(other.o1.toString());\n" + + " }\n" + + " if (this.o2 != null)\n" + // field reference -> statement + " System.out.println(o2.toString());\n" + + " if (this.o2 != null)\n" + // identical field references + " System.out.println(this.o2.toString());\n" + + " System.out.println (null != o3 ? o3.toString() : \"nothing\");\n" + // ternary + " if (this.x.o1 != null)\n" + // nested field reference ... + " System.out.println(x.o1.toString());\n" + // ... equiv qualified name reference + " if (x.o1 != null)\n" + // qualified name reference ... + " System.out.println(this.x.o1.toString());\n" +// ... equiv nested field reference + " if (this.x.o1 != null)\n" + // identical nested field references + " System.out.println(this.x.o1.toString());\n" + + " }\n" + + "}\n" + }, + options, + ""); +} + +// protected access to nullable fields - different kinds of references - option not enabled +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_10b() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.DISABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o1, o2, o3;\n" + + " @NonNull X x = new X();\n" + + " public void foo(X other) {\n" + + " if (other.o1 != null){\n" + // qualified reference -> block + " System.out.println(other.o1.toString());\n" + + " }\n" + + " if (this.o2 != null)\n" + // field reference -> statement + " System.out.println(o2.toString());\n" + + " if (this.o2 != null)\n" + // identical field references + " System.out.println(this.o2.toString());\n" + + " System.out.println (null != o3 ? o3.toString() : \"nothing\");\n" + // ternary + " if (this.x.o1 != null)\n" + // nested field reference ... + " System.out.println(x.o1.toString());\n" + // ... equiv qualified name reference + " if (x.o1 != null)\n" + // qualified name reference ... + " System.out.println(this.x.o1.toString());\n" +// ... equiv nested field reference + " if (this.x.o1 != null)\n" + // identical nested field references + " System.out.println(this.x.o1.toString());\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(other.o1.toString());\n" + + " ^^\n" + + potNPE_nullable("The field o1") + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " System.out.println(o2.toString());\n" + + " ^^\n" + + potNPE_nullable("The field o2") + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " System.out.println(this.o2.toString());\n" + + " ^^\n" + + potNPE_nullable("The field o2") + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " System.out.println (null != o3 ? o3.toString() : \"nothing\");\n" + + " ^^\n" + + potNPE_nullable("The field o3") + + "----------\n" + + "5. ERROR in X.java (at line 15)\n" + + " System.out.println(x.o1.toString());\n" + + " ^^\n" + + potNPE_nullable("The field o1") + + "----------\n" + + "6. ERROR in X.java (at line 17)\n" + + " System.out.println(this.x.o1.toString());\n" + + " ^^\n" + + potNPE_nullable("The field o1") + + "----------\n" + + "7. ERROR in X.java (at line 19)\n" + + " System.out.println(this.x.o1.toString());\n" + + " ^^\n" + + potNPE_nullable("The field o1") + + "----------\n"); +} + +// protected access to nullable fields - different boolean operators +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_10c() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o1, o2, o3;\n" + + " public void foo(X other) {\n" + + " if (o1 != null && o2 != null & o3 != null) \n" + // conjunction: OK + " System.out.println(o2.toString());\n" + + " if (o1 != null || o2 != null || o3 != null) \n" + + " System.out.println(o2.toString()); // warn here: disjunktion is no protection\n" + + " if (!(o1 != null)) \n" + + " System.out.println(o1.toString()); // warn here: negated inequality is no protection\n" + + " if (!(o1 == null || o2 == null)) \n" + + " System.out.println(o1.toString()); // don't warn here\n" + + " if (!(o1 == null && o2 == null)) \n" + + " System.out.println(o2.toString()); // warn here: negated conjunction is no protection\n" + + " if (!(!(o1 == null))) \n" + + " System.out.println(o1.toString()); // warn here: double negation is no protection\n" + + " if (!(!(o1 != null && o2 != null))) \n" + + " System.out.println(o1.toString()); // don't warn here\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(o2.toString()); // warn here: disjunktion is no protection\n" + + " ^^\n" + + potNPE_nullable("The field o2") + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " System.out.println(o1.toString()); // warn here: negated inequality is no protection\n" + + " ^^\n" + + potNPE_nullable("The field o1") + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " System.out.println(o2.toString()); // warn here: negated conjunction is no protection\n" + + " ^^\n" + + potNPE_nullable("The field o2") + + "----------\n" + + "4. ERROR in X.java (at line 16)\n" + + " System.out.println(o1.toString()); // warn here: double negation is no protection\n" + + " ^^\n" + + potNPE_nullable("The field o1") + + "----------\n"); +} + +// protected access to nullable fields - assignment as expression +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_10d() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o1;\n" + + " public void foo(@NonNull X other, X last) {\n" + + " o1 = other;\n" + // reference test case: assignment as statement + " if (o1 == last) \n" + // no expiry + " System.out.println(o1.toString());\n" + + " if ((o1 = other) == last) \n" + // no expiry + " System.out.println(o1.toString());\n" + + " if ((o1 = other) == last) {\n" + + " o1 = null;\n" + // expire here + " System.out.println(o1.toString()); // info is expired\n" + + " }\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " System.out.println(o1.toString()); // info is expired\n" + + " ^^\n" + + potNPE_nullable("The field o1") + + "----------\n"); +} + +// protected access to nullable fields - distinguish local and field +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_10e() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class Y {\n" + + " @Nullable Object o2;\n" + + " void bar(Object o2) {\n" + + " if (o2 != null)\n" + + " System.out.println(this.o2.toString()); // field access is not protected\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " @NonNull Y o1 = new Y();\n" + + " public void foo() {\n" + + " Y o1 = new Y();\n" + + " if (o1.o2 != null) \n" + // check via local + " System.out.println(this.o1.o2.toString()); // field access via other field not protected\n" + + " if (this.o1.o2 != null) \n" + // check via field + " System.out.println(o1.o2.toString()); // field access via local not protected\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " void bar(Object o2) {\n" + + " ^^\n" + + "The parameter o2 is hiding a field from type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " System.out.println(this.o2.toString()); // field access is not protected\n" + + " ^^\n" + + potNPE_nullable("The field o2") + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " Y o1 = new Y();\n" + + " ^^\n" + + "The local variable o1 is hiding a field from type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " System.out.println(this.o1.o2.toString()); // field access via other field not protected\n" + + " ^^\n" + + potNPE_nullable("The field o2") + + "----------\n" + + "5. ERROR in X.java (at line 16)\n" + + " System.out.println(o1.o2.toString()); // field access via local not protected\n" + + " ^^\n" + + potNPE_nullable("The field o2") + + "----------\n"); +} + +// protected access to nullable fields - duplicate comparison +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_10f() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o1;\n" + + " public void foo(X other) {\n" + + " if (o1 != null && o1 != null) // second term is redundant\n" + + " System.out.println(o1.toString());\n" + + " if (o1 != null)\n" + + " if (o1 != null) // this if is redundant\n" + + " System.out.println(o1.toString());\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o1 != null && o1 != null) // second term is redundant\n" + + " ^^\n" + + "Redundant null check: The field o1 cannot be null at this location (ignoring concurrency)\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " if (o1 != null) // this if is redundant\n" + + " ^^\n" + + "Redundant null check: The field o1 cannot be null at this location (ignoring concurrency)\n" + + "----------\n"); +} + +// combined test from comment 20 in https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_11() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class X {\n" + + " @Nullable Object o;\n" + + " public @NonNull Object foo(X x) {\n" + + " return x.o != null ? x.o : new Object();\n" + + " }\n" + + " public void goo(X x) {\n" + + " if (x.o != null) {\n" + + " x.o.toString();\n" + + " }\n" + + " }\n" + + " public void boo(X x) {\n" + + " if (x.o instanceof String) {\n" + + " x.o.toString();\n" + + " }\n" + + " }\n" + + " public void zoo(X x) {\n" + + " x.o = new Object();\n" + + " System.out.println(\"hashCode of new Object = \" + x.o.hashCode());\n" + + " }\n" + + " public void doo(X x) {\n" + + " x.o = foo(x); // foo is guaranteed to return @NonNull Object.\n" + + " System.out.println(\"hashCode of new Object = \" + x.o.hashCode());\n" + + " }\n" + + "}\n" + }, + options, + ""); +} + +// combined test from comment 20 in https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +// - version with 'this' field references +public void test_nullable_field_11a() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class X {\n" + + " @Nullable Object o;\n" + + " public @NonNull Object foo() {\n" + + " return o != null ? o : new Object();\n" + + " }\n" + + " public void goo() {\n" + + " if (o != null) {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + " public void boo() {\n" + + " if (o instanceof String) {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + " public void zoo() {\n" + + " o = new Object();\n" + + " System.out.println(\"hashCode of new Object = \" + o.hashCode());\n" + + " }\n" + + " public void doo() {\n" + + " o = foo(); // foo is guaranteed to return @NonNull Object.\n" + + " System.out.println(\"hashCode of new Object = \" + o.hashCode());\n" + + " }\n" + + "}\n" + }, + options, + ""); +} + +// protected access to nullable field - expiration of information +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_12() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o1, o2, o3, o4;\n" + + " public void foo(X other) {\n" + + " if (other.o1 != null){\n" + + " System.out.println(goo()+other.o1.toString()); // warn here: expired by call to goo()\n" + + " }\n" + + " Object x = o2 != null ? o2 : o1;\n" + + " System.out.println(o2.toString()); // warn here: not protected\n" + + " if (o3 != null) /*nop*/;\n" + + " System.out.println(o3.toString()); // warn here: expired by empty statement\n" + + " if (o4 != null && hoo())\n" + + " System.out.println(o4.toString()); // warn here: expired by call to hoo()\n" + + " }\n" + + " String goo() { return \"\"; }\n" + + " boolean hoo() { return false; }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " System.out.println(goo()+other.o1.toString()); // warn here: expired by call to goo()\n" + + " ^^\n" + + potNPE_nullable("The field o1") + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " System.out.println(o2.toString()); // warn here: not protected\n" + + " ^^\n" + + potNPE_nullable("The field o2") + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " System.out.println(o3.toString()); // warn here: expired by empty statement\n" + + " ^^\n" + + potNPE_nullable("The field o3") + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " System.out.println(o4.toString()); // warn here: expired by call to hoo()\n" + + " ^^\n" + + potNPE_nullable("The field o4") + + "----------\n"); +} + +// example from comment 47 +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_13() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o1;\n" + + " @NonNull Object o2 = new Object();\n" + + " public void foo(X other) {\n" + + " if (other.o1 == null){\n" + + " this.o2 = other.o1; // warn here: assign @Nullable to @NonNull\n" + + " }\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " this.o2 = other.o1; // warn here: assign @Nullable to @NonNull\n" + + " ^^^^^^^^\n" + + mismatch_NonNull_Nullable("Object") + + "----------\n"); +} + +// access to a nullable field - protected by check against a @NonNull value +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_14() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o = new Object();\n" + + " public String oString(@NonNull Object a) {\n" + + " if (this.o == a)\n" + + " return this.o.toString();\n" + // silent after check + " return \"\";\n" + + " }\n" + + "}\n" + }, + options, + ""); +} + +// access to a nullable field - not protected by negative check against a @NonNull value +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=331649 +public void test_nullable_field_14a() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o = new Object();\n" + + " public String oString(@NonNull Object a) {\n" + + " if (this.o != a)\n" + + " return this.o.toString(); // warn here, check has no effect\n" + + " return \"\";\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return this.o.toString(); // warn here, check has no effect\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n"); +} + +// https://bugs.eclipse.org/401017: [compiler][null] casted reference to @Nullable field lacks a warning +public void test_nullable_field_15() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable\n" + + " private Object nullable;\n" + + "\n" + + " public void test() {\n" + + " if (nullable instanceof Number) {\n" + + " ((Number)nullable).intValue(); // A\n" + + " }\n" + + " if (nullable != null) {\n" + + " nullable.toString(); // B\n" + + " }\n" + + " nullable.toString(); // C\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " ((Number)nullable).intValue(); // A\n" + + " ^^^^^^^^\n" + + potNPE_nullable("The field nullable") + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " nullable.toString(); // B\n" + + " ^^^^^^^^\n" + + potNPE_nullable("The field nullable") + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " nullable.toString(); // C\n" + + " ^^^^^^^^\n" + + potNPE_nullable("The field nullable") + + "----------\n"); +} +// access to a nullable field - dereference after check in while loop +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=414761 +public void test_nullable_field_16() { + // currently no flow analysis for fields is implemented, + // but the direct sequence of null-check + dereference is optionally supported as a special case + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object prop;\n" + + " void testWhileAlone(){\n" + + " while(this.prop != null) {\n" + + " test(this.prop);\n" + + " }\n" + + " }\n" + + " @Nullable Object other;\n" + + " void testTwoFields() {\n" + + " boolean b = this.other != null;\n" + // we had funny interaction between analyses of other & prop + " while(this.prop != null) {\n" + + " test(this.prop);\n" + + " }\n" + + " }\n" + + " void testWhileInIf() {\n" + + " if (this.prop != null) {\n" + + " while(this.other != null) {\n" + + " test(this.prop);\n" + // no longer protected by outer if + " }\n" + + " }\n" + + " }\n" + + " void test(@NonNull Object param){\n" + + " assert param != null;\n" + + " }" + + "}\n" + }, + options /*customOptions*/, + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " test(this.prop);\n" + + " ^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Null type mismatch: required '@NonNull Object' but the provided value is specified as @Nullable\n" + : "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable Object\'\n") + + "----------\n"); +} +// access to a nullable field - field reference +// Configured as of https://bugs.eclipse.org/bugs/show_bug.cgi?id=433615 +public void test_nullable_field_17() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.INFO); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o = new Object();\n" + + " public String oString() {\n" + + " return this.o.toString();\n" + + " }\n" + + "}\n" + }, + options /*customOptions*/, + "----------\n" + + "1. INFO in X.java (at line 5)\n" + + " return this.o.toString();\n" + + " ^\n" + + potNPE_nullable("The field o") + + "----------\n"); +} +// an enum is declared within the scope of a null-default +// https://bugs.eclipse.org/331649#c61 +public void test_enum_field_01() { + runConformTestWithLibs( + new String[] { + "tests/X.java", + "package tests;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class X {\n" + + " enum A { B }\n" + + " public static void main(String ... args) {\n" + + " System.out.println(A.B);\n" + + " }\n" + + "}\n" + }, + null, + "", + "B"); +} + +// Bug 380896 - Enum constants not recognised as being NonNull. +// see also https://bugs.eclipse.org/331649#c61 +public void test_enum_field_02() { + runConformTestWithLibs( + new String[] { + "tests/X.java", + "package tests;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " enum A { B }\n" + + " public static void main(String ... args) {\n" + + " test(A.B);\n" + + " }\n" + + " static void test(@NonNull A a) {\n" + + " System.out.println(a.ordinal());\n" + + " }\n" + + "}\n" + }, + null, + "", + "0"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=372011 +// Test whether @NonNullByDefault on a binary package or an enclosing type is respected from enclosed elements. +public void testBug372011() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test372011.jar"; + String[] libs = new String[this.LIBS.length + 1]; + System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); + libs[this.LIBS.length] = path; + runNegativeNullTest( + new String[] { + "X.java", + "import p11.T11;\n" + + "import p12.T12;\n" + + "import p12.T12a;\n" + + "import p12.Public;\n" + + "public class X {\n" + + " void foo() {\n" + + " new T11().t11foo(null);\n" + + " new T12().new T122().foo122(null);\n" + + " }\n" + + " void trigger1 (Public o){\n" + + " o.bar(null);\n" + + " }\n" + + " @org.eclipse.jdt.annotation.NonNull Object foo2() {\n" + + " new T12a().foo12a(new Object());\n" + // don't complain + " new T12().new T122().new T1222().foo1222(null);\n" + + " return new T11().retSomething();\n" + // don't complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " new T11().t11foo(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " new T12().new T122().foo122(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " o.bar(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " new T12().new T122().new T1222().foo1222(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n", + libs, + true /* shouldFlush*/, + getCompilerOptions()); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=374129 - more tests for bug 372011 +// Test whether @NonNullByDefault on a binary package or an enclosing type is respected from enclosed elements. +public void testBug374129() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test374129"+this.TEST_JAR_SUFFIX; + /* content of Test372129.jar: + p1bin/package-info.java: + @org.eclipse.jdt.annotation.NonNullByDefault + package p1bin; + p1bin/C1bin.java: + package p1bin; + import org.eclipse.jdt.annotation.Nullable; + public class C1bin { + public String getId(String id, @Nullable String n) { + return id; + } + public static class C1binInner { + public String getId(String id, @Nullable String n) { + return id; + } + } + } + p2bin/C2bin.java: + package p2bin; + import org.eclipse.jdt.annotation.NonNullByDefault; + import org.eclipse.jdt.annotation.Nullable; + @NonNullByDefault + public class C2bin { + public String getId(String id, @Nullable String n) { + return id; + } + @NonNullByDefault(false) + public static class C2binInner { + public String getId(String id, @Nullable String n) { + return id; + } + } + } + p2bin/C3bin.java: + package p2bin; + import org.eclipse.jdt.annotation.NonNullByDefault; + import org.eclipse.jdt.annotation.Nullable; + public class C3bin { + @NonNullByDefault public String getId(String id, @Nullable String n) { + return id; + } + } + */ + String[] libs = new String[this.LIBS.length + 1]; + System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); + libs[this.LIBS.length] = path; + runNegativeNullTest( + new String[] { + "bug374129/Test.java", + "package bug374129;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "import p1bin.C1bin;\n" + + "import p1bin.C1bin.C1binInner;\n" + + "import p2bin.C2bin;\n" + + "import p2bin.C2bin.C2binInner;\n" + + "import p2bin.C3bin;\n" + + "\n" + + "public class Test {\n" + + " static C1bin c1 = new C1bin();\n" + + " static C1binInner c1i = new C1binInner();\n" + + " static C2bin c2 = new C2bin();\n" + + " static C2binInner c2i = new C2binInner();\n" + + " static C3bin c3 = new C3bin();\n" + + " \n" + + " public static void main(String[] args) {\n" + + " @Nullable String n = getN();\n" + + " @NonNull String s;\n" + + " s = c1.getId(n, n); // error on first arg (package default)\n" + + " s = c1i.getId(n, n); // error on first arg (package default propagated into inner)\n" + + " s = c2.getId(n, n); // error on first arg (type default)\n" + + " s = c2i.getId(n, n); // no arg error (canceled default), return requires unchecked conversion\n" + + " s = c3.getId(n, n); // error on first arg (method default)\n" + + " }\n" + + " static String getN() { return null; }\n" + + "}\n" + + "\n"}, + "----------\n" + + "1. ERROR in bug374129\\Test.java (at line 22)\n" + + " s = c1.getId(n, n); // error on first arg (package default)\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "2. ERROR in bug374129\\Test.java (at line 23)\n" + + " s = c1i.getId(n, n); // error on first arg (package default propagated into inner)\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "3. ERROR in bug374129\\Test.java (at line 24)\n" + + " s = c2.getId(n, n); // error on first arg (type default)\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "4. WARNING in bug374129\\Test.java (at line 25)\n" + + " s = c2i.getId(n, n); // no arg error (canceled default), return requires unchecked conversion\n" + + " ^^^^^^^^^^^^^^^\n" + + nullTypeSafety() + "The expression of type 'String' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n" + + "5. ERROR in bug374129\\Test.java (at line 26)\n" + + " s = c3.getId(n, n); // error on first arg (method default)\n" + + " ^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n", + libs, + true /* shouldFlush*/, + getCompilerOptions()); +} + +// Bug 385626 - @NonNull fails across loop boundaries +public void testBug385626_1() { + runConformTestWithLibs( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void test() {\n" + + " for (Integer i : new ArrayList()) {\n" + + " if (i != null) {\n" + + " for (Integer j : new ArrayList()) {\n" + + " if (j != null) {\n" + + " @NonNull Integer j1 = i; // bogus error was here\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + null,//options + ""); +} + +// Bug 385626 - @NonNull fails across loop boundaries +public void testBug385626_2() { + runConformTestWithLibs( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void test(Integer j) {\n" + + " for (Integer i : new ArrayList()) {\n" + + " if (i != null) {\n" + + " try {\n" + + " if (j != null) {\n" + + " @NonNull Integer j1 = i;\n" + + " }\n" + + " } finally {\n" + + " if (j != null) {\n" + + " @NonNull Integer j1 = i; // bogus error was here\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + null,//options + ""); +} + +// Bug 388630 - @NonNull diagnostics at line 0 +// synthetic constructor must repeat null annotations of its super +public void testBug388630_1() { + runConformTestWithLibs( + new String[] { + "C0.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class C0 {\n" + + " C0 (@NonNull Object o) { }\n" + + " void test() { }\n" + + "}\n", + "X.java", + "public class X {\n" + + " void foo() {\n" + + " new C0(\"\") { }.test();\n" + + " }\n" + + "}\n" + }, + null, + ""); +} + +// Bug 388630 - @NonNull diagnostics at line 0 +// additionally also references to outer variables must share their nullness +public void testBug388630_2() { + runNegativeTestWithLibs( + new String[] { + "C0.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class C0 {\n" + + " C0 (@NonNull Object o) { }\n" + + " void test() { }\n" + + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public class X {\n" + + " void foo(final @Nullable Object a) {\n" + + " new C0(\"\") {\n" + + " @Override\n" + + " void test() {\n" + + " System.out.println(a.toString());\n" + + " super.test();\n" + + " }\n" + + " }.test();\n" + + " }\n" + + "}\n" + }, + null, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(a.toString());\n" + + " ^\n" + + variableMayBeNull("a") + + "----------\n"); +} + +/* Content of Test388281.jar used in the following tests: + +// === package i (explicit annotations): === +package i; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +public interface I { + @NonNull Object m1(@Nullable Object a1); + @Nullable String m2(@NonNull Object a2); + Object m1(@Nullable Object o1, Object o2); +} + +// === package i2 with package-info.java (default annot, canceled in one type): === +@org.eclipse.jdt.annotation.NonNullByDefault +package i2; + +package i2; +public interface I2 { + Object m1(Object a1); + String m2(Object a2); +} + +package i2; +public interface II extends i.I { + String m1(Object o1, Object o2); +} + +package i2; +import org.eclipse.jdt.annotation.NonNullByDefault; +@NonNullByDefault({}) +public interface I2A { + Object m1(Object a1); + String m2(Object a2); +} + +// === package c (no null annotations): === +package c; +public class C1 implements i.I { + public Object m1(Object a1) { + System.out.println(a1.toString()); // (1) + return null; // (2) + } + public String m2(Object a2) { + System.out.println(a2.toString()); + return null; + } + public Object m1(Object o1, Object o2) { + return null; + } +} + +package c; +public class C2 implements i2.I2 { + public Object m1(Object a1) { + return a1; + } + public String m2(Object a2) { + return a2.toString(); + } +} + */ +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 +// Test whether null annotations from a super interface are respected +// Class and its super interface both read from binary +public void testBug388281_01() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281"+this.TEST_JAR_SUFFIX; + String[] libs = new String[this.LIBS.length + 1]; + System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); + libs[this.LIBS.length] = path; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); + runNegativeNullTest( + new String[] { + "Client.java", + "import c.C1;\n" + + "public class Client {\n" + + " void test(C1 c) {\n" + + " String s = c.m2(null); // (3)\n" + + " System.out.println(s.toUpperCase()); // (4)\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Client.java (at line 4)\n" + + " String s = c.m2(null); // (3)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in Client.java (at line 5)\n" + + " System.out.println(s.toUpperCase()); // (4)\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n", + libs, + true /* shouldFlush*/, + options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 +// Test whether null annotations from a super interface are respected +// Class from source, its supers (class + super interface) from binary +public void testBug388281_02() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281"+this.TEST_JAR_SUFFIX; + String[] libs = new String[this.LIBS.length + 1]; + System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); + libs[this.LIBS.length] = path; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); + runNegativeNullTest( + new String[] { + "ctest/C.java", + "package ctest;\n" + + "public class C extends c.C1 {\n" + + " @Override\n" + + " public Object m1(Object a1) {\n" + + " System.out.println(a1.toString()); // (1)\n" + + " return null; // (2)\n" + + " }\n" + + " @Override\n" + + " public String m2(Object a2) {\n" + + " System.out.println(a2.toString());\n" + + " return null;\n" + + " }\n" + + "}\n", + "Client.java", + "import ctest.C;\n" + + "public class Client {\n" + + " void test(C c) {\n" + + " String s = c.m2(null); // (3)\n" + + " System.out.println(s.toUpperCase()); // (4)\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in ctest\\C.java (at line 5)\n" + + " System.out.println(a1.toString()); // (1)\n" + + " ^^\n" + + potNPE_nullable_maybenull("The variable a1") + + "----------\n" + + "2. ERROR in ctest\\C.java (at line 6)\n" + + " return null; // (2)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Client.java (at line 4)\n" + + " String s = c.m2(null); // (3)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in Client.java (at line 5)\n" + + " System.out.println(s.toUpperCase()); // (4)\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n", + libs, + true /* shouldFlush*/, + options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 +// Test whether null annotations from a super interface trigger an error against the overriding implementation +// Class from source, its super interface from binary +public void testBug388281_03() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281"+this.TEST_JAR_SUFFIX; + String[] libs = new String[this.LIBS.length + 1]; + System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); + libs[this.LIBS.length] = path; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); + runNegativeNullTest( + new String[] { + "ctest/C.java", + "package ctest;\n" + + "public class C implements i.I {\n" + + " public Object m1(Object a1) {\n" + + " System.out.println(a1.toString()); // (1)\n" + + " return null; // (2)\n" + + " }\n" + + " public String m2(Object a2) {\n" + + " System.out.println(a2.toString());\n" + + " return null;\n" + + " }\n" + + " public Object m1(Object a1, Object a2) {\n" + + " System.out.println(a1.toString()); // (3)\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in ctest\\C.java (at line 4)\n" + + " System.out.println(a1.toString()); // (1)\n" + + " ^^\n" + + potNPE_nullable_maybenull("The variable a1") + + "----------\n" + + "2. ERROR in ctest\\C.java (at line 5)\n" + + " return null; // (2)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in ctest\\C.java (at line 12)\n" + + " System.out.println(a1.toString()); // (3)\n" + + " ^^\n" + + potNPE_nullable_maybenull("The variable a1") + + "----------\n", + libs, + true /* shouldFlush*/, + options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 +// Do inherit even if one parameter/return is annotated +// also features some basic overloading +public void testBug388281_04() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); + runNegativeTestWithLibs( + true /* shouldFlush*/, + new String[] { + "i/I.java", + "package i;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public interface I {\n" + + " @NonNull Object m1(@NonNull Object s1, @Nullable String s2);\n" + + " @Nullable Object m1(@Nullable String s1, @NonNull Object s2);\n" + + "}\n", + "ctest/C.java", + "package ctest;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class C implements i.I {\n" + + " public Object m1(@Nullable Object o1, String s2) {\n" + + " System.out.println(s2.toString()); // (1)\n" + + " return null; // (2)\n" + + " }\n" + + " public @NonNull Object m1(String s1, Object o2) {\n" + + " System.out.println(s1.toString()); // (3)\n" + + " return new Object();\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in ctest\\C.java (at line 5)\n" + + " System.out.println(s2.toString()); // (1)\n" + + " ^^\n" + + variableMayBeNull("s2") + + "----------\n" + + "2. ERROR in ctest\\C.java (at line 6)\n" + + " return null; // (2)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in ctest\\C.java (at line 9)\n" + + " System.out.println(s1.toString()); // (3)\n" + + " ^^\n" + + variableMayBeNull("s1") + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 +// Test whether null annotations from a super interface trigger an error against the overriding implementation +// Class from source, its super interface from binary +// Super interface subject to package level @NonNullByDefault +public void testBug388281_05() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281"+this.TEST_JAR_SUFFIX; + String[] libs = new String[this.LIBS.length + 1]; + System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); + libs[this.LIBS.length] = path; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); + runNegativeNullTest( + new String[] { + "ctest/C.java", + "package ctest;\n" + + "public class C implements i2.I2 {\n" + + " public Object m1(Object a1) {\n" + + " System.out.println(a1.toString()); // silent\n" + + " return null; // (1)\n" + + " }\n" + + " public String m2(Object a2) {\n" + + " System.out.println(a2.toString());\n" + + " return null; // (2)\n" + + " }\n" + + "}\n", + "Client.java", + "import ctest.C;\n" + + "public class Client {\n" + + " void test(C c) {\n" + + " String s = c.m2(null); // (3)\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in ctest\\C.java (at line 5)\n" + + " return null; // (1)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in ctest\\C.java (at line 9)\n" + + " return null; // (2)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Client.java (at line 4)\n" + + " String s = c.m2(null); // (3)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n", + libs, + true /* shouldFlush*/, + options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 +// Conflicting annotations from several indirect super interfaces must be detected +public void testBug388281_06() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281"+this.TEST_JAR_SUFFIX; + String[] libs = new String[this.LIBS.length + 1]; + System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); + libs[this.LIBS.length] = path; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); + runNegativeNullTest( + new String[] { + "ctest/C.java", + "package ctest;\n" + + "public class C extends c.C2 implements i2.I2A {\n" + // neither super has explicit annotations, + // but C2 inherits those from the default applicable at its super interface i2.I2 + // whereas I2A cancels that same default + "}\n" + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in ctest\\C.java (at line 2)\n" + + " public class C extends c.C2 implements i2.I2A {\n" + + " ^^^^\n" + + "The method m2(Object) from C2 cannot implement the corresponding method from I2A due to incompatible nullness constraints\n" + + "----------\n" + + "2. ERROR in ctest\\C.java (at line 2)\n" + + " public class C extends c.C2 implements i2.I2A {\n" + + " ^^^^\n" + + "The method m1(Object) from C2 cannot implement the corresponding method from I2A due to incompatible nullness constraints\n" + + "----------\n" + : // at 1.8 we show null type annotations: + "----------\n" + + "1. ERROR in ctest\\C.java (at line 2)\n" + + " public class C extends c.C2 implements i2.I2A {\n" + + " ^^^^\n" + + "The method m2(@NonNull Object) from C2 cannot implement the corresponding method from I2A due to incompatible nullness constraints\n" + + "----------\n" + + "2. ERROR in ctest\\C.java (at line 2)\n" + + " public class C extends c.C2 implements i2.I2A {\n" + + " ^^^^\n" + + "The method m1(@NonNull Object) from C2 cannot implement the corresponding method from I2A due to incompatible nullness constraints\n" + + "----------\n"), + libs, + true /* shouldFlush*/, + options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 +// report conflict between inheritance and default +public void testBug388281_07() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "p1/Super.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Super {\n" + + " public @Nullable Object m(@Nullable Object arg) {\n" + + " return null;" + + " }\n" + + "}\n", + "p2/Sub.java", + "package p2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Sub extends p1.Super {\n" + + " @Override\n" + + " public Object m(Object arg) { // (a)+(b) conflict at arg and return\n" + + " System.out.println(arg.toString()); // (1)\n" + + " return null;\n" + + " }\n" + + "}\n", + "Client.java", + "public class Client {\n" + + " void test(p2.Sub s) {\n" + + " Object result = s.m(null);\n" + + " System.out.println(result.toString()); // (2)\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in p2\\Sub.java (at line 6)\n" + + " public Object m(Object arg) { // (a)+(b) conflict at arg and return\n" + + " ^^^^^^\n" + + "The default \'@NonNull\' conflicts with the inherited \'@Nullable\' annotation in the overridden method from Super \n" + + "----------\n" + + "2. ERROR in p2\\Sub.java (at line 6)\n" + + " public Object m(Object arg) { // (a)+(b) conflict at arg and return\n" + + " ^^^\n" + + "The default \'@NonNull\' conflicts with the inherited \'@Nullable\' annotation in the overridden method from Super \n" + + "----------\n" + + "3. ERROR in p2\\Sub.java (at line 7)\n" + + " System.out.println(arg.toString()); // (1)\n" + + " ^^^\n" + + variableMayBeNull("arg") + + "----------\n" + + "----------\n" + + "1. ERROR in Client.java (at line 4)\n" + + " System.out.println(result.toString()); // (2)\n" + + " ^^^^^^\n" + + "Potential null pointer access: The variable result may be null at this location\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 +// report conflict between inheritance and default - binary types +public void testBug388281_08() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test388281"+this.TEST_JAR_SUFFIX; + String[] libs = new String[this.LIBS.length + 1]; + System.arraycopy(this.LIBS, 0, libs, 0, this.LIBS.length); + libs[this.LIBS.length] = path; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); + runNegativeNullTest( + new String[] { + "ctest/Ctest.java", + "package ctest;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Ctest implements i2.II {\n" + // note: i2.II.m1(Object,Object) actually has a bug itself: conflicting default & inherited annotations + " public Object m1(@Nullable Object a1) { // silent: conflict at a1 avoided\n" + + " return new Object();\n" + + " }\n" + + " public String m2(Object a2) { // (a) conflict at return\n" + + " return null;\n" + + " }\n" + + " public String m1(Object o1, Object o2) { // (b) conflict at o1\n" + + " System.out.println(o1.toString()); // (1) inherited @Nullable\n" + + " return null; // (2) @NonNullByDefault in i2.II\n" + + " }\n" + + "}\n", + "Client.java", + "public class Client {\n" + + " void test(ctest.Ctest c) {\n" + + " Object result = c.m1(null, null); // (3) 2nd arg @NonNullByDefault from i2.II\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in ctest\\Ctest.java (at line 8)\n" + + " public String m2(Object a2) { // (a) conflict at return\n" + + " ^^^^^^\n" + + "The default \'@NonNull\' conflicts with the inherited \'@Nullable\' annotation in the overridden method from I \n" + + "----------\n" + + "2. ERROR in ctest\\Ctest.java (at line 11)\n" + + " public String m1(Object o1, Object o2) { // (b) conflict at o1\n" + + " ^^\n" + + "The default \'@NonNull\' conflicts with the inherited \'@Nullable\' annotation in the overridden method from II \n" + + "----------\n" + + "3. ERROR in ctest\\Ctest.java (at line 12)\n" + + " System.out.println(o1.toString()); // (1) inherited @Nullable\n" + + " ^^\n" + + potNPE_nullable_maybenull("The variable o1") + + "----------\n" + + "4. ERROR in ctest\\Ctest.java (at line 13)\n" + + " return null; // (2) @NonNullByDefault in i2.II\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Client.java (at line 3)\n" + + " Object result = c.m1(null, null); // (3) 2nd arg @NonNullByDefault from i2.II\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n", + libs, + true, // should flush + options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 +// difference between inherited abstract & non-abstract methods +public void testBug388281_09() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "p1/Super.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public abstract class Super {\n" + + " public abstract @NonNull Object compatible(@Nullable Object arg);\n" + + " public @Nullable Object incompatible(int dummy, @NonNull Object arg) {\n" + + " return null;" + + " }\n" + + "}\n", + "p1/I.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public interface I {\n" + + " public @Nullable Object compatible(@NonNull Object arg);\n" + + " public @NonNull Object incompatible(int dummy, @Nullable Object arg);\n" + + "}\n", + "p2/Sub.java", + "package p2;\n" + + "public class Sub extends p1.Super implements p1.I {\n" + + " @Override\n" + + " public Object compatible(Object arg) {\n" + + " return this;\n" + + " }\n" + + " @Override\n" + + " public Object incompatible(int dummy, Object arg) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in p2\\Sub.java (at line 4)\n" + + " public Object compatible(Object arg) {\n" + + " ^^^^^^\n" + + "Conflict between inherited null annotations \'@Nullable\' declared in I versus \'@NonNull\' declared in Super \n" + + "----------\n" + + "2. ERROR in p2\\Sub.java (at line 4)\n" + + " public Object compatible(Object arg) {\n" + + " ^^^^^^\n" + + "Conflict between inherited null annotations \'@NonNull\' declared in I versus \'@Nullable\' declared in Super \n" + + "----------\n" + + "3. ERROR in p2\\Sub.java (at line 8)\n" + + " public Object incompatible(int dummy, Object arg) {\n" + + " ^^^^^^\n" + + "Conflict between inherited null annotations \'@NonNull\' declared in I versus \'@Nullable\' declared in Super \n" + + "----------\n" + + "4. ERROR in p2\\Sub.java (at line 8)\n" + + " public Object incompatible(int dummy, Object arg) {\n" + + " ^^^^^^\n" + + "Conflict between inherited null annotations \'@Nullable\' declared in I versus \'@NonNull\' declared in Super \n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=388281 +// respect inherited @NonNull also inside the method body, see comment 28 +public void testBug388281_10() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_INHERIT_NULL_ANNOTATIONS, JavaCore.ENABLED); + runNegativeTestWithLibs( + new String[] { + "p1/Super.java", + "package p1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Super {\n" + + " public void m(@NonNull Object arg) {}\n" + + "}\n", + "p2/Sub.java", + "package p2;\n" + + "public class Sub extends p1.Super {\n" + + " @Override\n" + + " public void m(Object arg) {\n" + + " arg = null;\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in p2\\Sub.java (at line 5)\n" + + " arg = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions +// junit's assertNull vs. a @NonNull field / expression +public void testBug382069_j() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + NullReferenceTestAsserts.JUNIT_ASSERT_NAME, + NullReferenceTestAsserts.JUNIT_ASSERT_CONTENT, + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class X {\n" + + " @NonNull String o1 = \"\";\n" + + " boolean foo() {\n" + + " junit.framework.Assert.assertNull(\"something's wrong\", o1);\n" + // always fails due to @NonNull + " return false; // dead code\n" + + " }\n" + + " void bar() {\n" + + " junit.framework.Assert.assertNull(\"\");\n" + // constantly false + " return; // dead code\n" + + " }\n" + + " void zork() {\n" + + " junit.framework.Assert.assertNotNull(null);\n" + // constantly false + " return; // dead code\n" + + " }\n" + + "}\n"}, + options, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return false; // dead code\n" + + " ^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " return; // dead code\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " return; // dead code\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions +// junit's assertNonNull et al. affecting a @Nullable field using syntactic analysis +public void testBug382069_k() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + NullReferenceTestAsserts.JUNIT_ASSERT_NAME, + NullReferenceTestAsserts.JUNIT_ASSERT_CONTENT, + "X.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public class X {\n" + + " @Nullable String o1;\n" + + " int foo() {\n" + + " junit.framework.Assert.assertNotNull(\"something's wrong\", o1);\n" + + " return o1.length();\n" + + " }\n" + + " int bar(int i) {\n" + + " junit.framework.Assert.assertNotNull(o1);\n" + + " i++;\n" + // expire + " return o1.length(); // no longer protected\n" + + " }\n" + + " int garp() {\n" + + " junit.framework.Assert.assertFalse(\"something's wrong\", o1 == null);\n" + + " return o1.length();\n" + + " }\n" + + " int zipp() {\n" + + " junit.framework.Assert.assertTrue(\"something's wrong\", o1 != null);\n" + + " return o1.length();\n" + + " }\n" + + "}\n"}, + options, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " return o1.length(); // no longer protected\n" + + " ^^\n" + + potNPE_nullable("The field o1") + + "----------\n"); +} +//https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic +public void test_conditional_expression_1() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " boolean badFunction5(int i) {\n" + + " // expected a potential null problem:\n" + + " return i > 0 ? true : getBoolean();\n" + + " }\n" + + " private @Nullable Boolean getBoolean() {\n" + + " return null;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return i > 0 ? true : getBoolean();\n" + + " ^^^^^^^^^^^^\n" + + "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" + + "----------\n"); +} + +// Bug 403086 - [compiler][null] include the effect of 'assert' in syntactic null analysis for fields +public void testBug403086_1() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_PB_INCLUDE_ASSERTS_IN_NULL_ANALYSIS, JavaCore.ENABLED); + customOptions.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + NullReferenceTestAsserts.JUNIT_ASSERT_NAME, + NullReferenceTestAsserts.JUNIT_ASSERT_CONTENT, + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class Y {\n" + + " @Nullable String str;\n" + + " int foo(@Nullable String str2) {\n" + + " int i;\n" + + " junit.framework.Assert.assertNotNull(str);\n" + + " i = str.length();\n" + + "\n" + + " assert this.str != null;\n" + + " i = str.length();\n" + + "\n" + + " return i;\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); +} + +//Bug 403086 - [compiler][null] include the effect of 'assert' in syntactic null analysis for fields +public void testBug403086_2() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_PB_INCLUDE_ASSERTS_IN_NULL_ANALYSIS, JavaCore.ENABLED); + customOptions.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + NullReferenceTestAsserts.JUNIT_ASSERT_NAME, + NullReferenceTestAsserts.JUNIT_ASSERT_CONTENT, + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class Y {\n" + + " @Nullable String str;\n" + + " int foo(@Nullable String str2) {\n" + + " int i;\n" + + " junit.framework.Assert.assertNotNull(str);\n" + + " i = str.length();\n" + + "\n" + + " assert ! (this.str == null);\n" + + " i = str.length();\n" + + "\n" + + " return i;\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); +} + +// https://bugs.eclipse.org/412076 - [compiler] @NonNullByDefault doesn't work for varargs parameter when in generic interface +public void testBug412076() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "Foo.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public interface Foo {\n" + + " V bar(String... values);\n" + + " V foo(String value);\n" + + "}\n" + }, + options, + ""); + runConformTestWithLibs( + false /*flush*/, + new String[] { + "FooImpl.java", + "import org.eclipse.jdt.annotation.*;\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "@NonNullByDefault\n" + : "@NonNullByDefault({DefaultLocation.PARAMETER,DefaultLocation.RETURN_TYPE})\n" // avoid @NonNull on type argument + ) + + "public class FooImpl implements Foo {\n" + + " public String bar(final String... values) {\n" + + " return (\"\");\n" + + " }\n" + + " public String foo(final String value) {\n" + + " return (\"\");\n" + + " }\n" + + "}\n" + }, + options, + ""); +} + +public void testBug413460() { + runConformTestWithLibs( + new String[] { + "Class2.java", + "\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class Class2 {\n" + + " public class Class3 {\n" + + " public Class3(String nonNullArg) {\n" + + " assert nonNullArg != null;\n" + + " }\n" + + " }\n" + + "\n" + + " public Class2(String nonNullArg) {\n" + + " assert nonNullArg != null;\n" + + " }\n" + + "\n" + + " public static Class2 create(String nonNullArg) {\n" + + " return new Class2(nonNullArg);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runNegativeTestWithLibs(false, + new String[] { + "Class1.java", + "public class Class1 {\n" + + " public static Class2 works() {\n" + + " return Class2.create(null);\n" + + " }\n" + + "\n" + + " public static Class2 bug() {\n" + + " return new Class2(null);\n" + + " }\n" + + "\n" + + " public static Class2.Class3 qualifiedbug() {\n" + + " return new Class2(\"\").new Class3(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Class1.java (at line 3)\n" + + " return Class2.create(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in Class1.java (at line 7)\n" + + " return new Class2(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in Class1.java (at line 11)\n" + + " return new Class2(\"\").new Class3(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); +} + +// missing type in constructor declaration must not cause NPE in QAE#resolveType(..) +public void testBug415850_a() { + runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = new X1(x1){};\n" + + " }\n" + + "}\n", + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new X1(x1){};\n" + + " ^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + this.LIBS, + true/*flush*/, + null/*options*/); +} + +// avoid NPE in BinaryTypeBinding.getField(..) due to recursive dependency enum->package-info->annotation->enum +public void testBug415850_b() { + runConformTestWithLibs( + new String[] { + "p/package-info.java", + "@p.Annot(state=p.MyEnum.BROKEN)\n" + + "package p;", + "p/Annot.java", + "package p;\n" + + "@Annot(state=MyEnum.KO)\n" + + "public @interface Annot {\n" + + " MyEnum state() default MyEnum.KO;\n" + + "}", + "p/MyEnum.java", + "package p;\n" + + "@Annot(state=MyEnum.KO)\n" + + "public enum MyEnum {\n" + + " WORKS, OK, KO, BROKEN, ;\n" + + "}", + "test180/Test.java", + "package test180;\n" + + "import p.MyEnum;\n" + + "import p.Annot;\n" + + "@Annot(state=MyEnum.OK)\n" + + "public class Test {}", + }, + getCompilerOptions(), + "" + ); + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + runConformTestWithLibs( + false /* don't flush output dir */, + new String[] { + "X.java", + "import test180.Test;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Test.class);\n" + + " }\n" + + "}" + }, + options, + "", + "class test180.Test"); +} +public void testBug417295_5() { + runNegativeTestWithLibs( + new String[] { + "AllAreNonNull.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class AllAreNonNull {\n" + + " String s3 = \"\";\n" + + " void test() {\n" + + " this.s3 = null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in AllAreNonNull.java (at line 5)\n" + + " this.s3 = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); +} +public void testBug417295_7() { + runConformTestWithLibs( + new String[] { + "p1/AllAreNonNull.java", + "package p1;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class AllAreNonNull {\n" + + " public String s3 = \"\";\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runNegativeTestWithLibs( + false, + new String[] { + "Client.java", + "public class Client {\n" + + " void test(p1.AllAreNonNull aann) {\n" + + " aann.s3 = null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Client.java (at line 3)\n" + + " aann.s3 = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); +} +// Bug 415413 - [compiler][null] NullpointerException in Null Analysis caused by interaction of LoopingFlowContext and FinallyFlowContext +public void testBug415413() { + Map options = getCompilerOptions(); + runNegativeTestWithLibs( + new String[]{ + "ClassF.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class ClassF {\n" + + " public static void needNonNull(@NonNull Object o) {\n" + + " o.hashCode();\n" + + " }\n" + + " public void method() {\n" + + " for (int j = 0; j < 1; j++) {\n" + + " try {\n" + + " this.hashCode();\n" + + " } finally {\n" + + " for (int i = 0; i < 1; i++) {\n" + + " Object o = null;\n" + + " needNonNull(o);\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in ClassF.java (at line 13)\n" + + " needNonNull(o);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); +} +// Bug 415413 - [compiler][null] NullpointerException in Null Analysis caused by interaction of LoopingFlowContext and FinallyFlowContext +// Variant: non-null before the loop and at the end of the loop body +public void testBug415413a() { + Map options = getCompilerOptions(); + runConformTestWithLibs( + new String[]{ + "ClassF.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class ClassF {\n" + + " public static void needNonNull(@NonNull Object o) {\n" + + " o.hashCode();\n" + + " }\n" + + " public void method() {\n" + + " for (int j = 0; j < 1; j++) {\n" + + " try {\n" + + " this.hashCode();\n" + + " } finally {\n" + + " Object o = new Object();\n" + + " for (int i = 0; i < 1; i++) {\n" + + " needNonNull(o);\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + options, + ""); +} +// Bug 415413 - [compiler][null] NullpointerException in Null Analysis caused by interaction of LoopingFlowContext and FinallyFlowContext +// Variant: null before the loop and non-null at the end of the loop body +public void testBug415413b() { + Map options = getCompilerOptions(); + runNegativeTestWithLibs( + new String[]{ + "ClassF.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class ClassF {\n" + + " public static void needNonNull(@NonNull Object o) {\n" + + " o.hashCode();\n" + + " }\n" + + " public void method() {\n" + + " for (int j = 0; j < 1; j++) {\n" + + " try {\n" + + " this.hashCode();\n" + + " } finally {\n" + + " Object o = null;\n" + + " for (int i = 0; i < 1; i++) {\n" + + " needNonNull(o);\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in ClassF.java (at line 13)\n" + + " needNonNull(o);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is inferred as @Nullable\n" + + "----------\n"); +} +// Bug 415413 - [compiler][null] NullpointerException in Null Analysis caused by interaction of LoopingFlowContext and FinallyFlowContext +// Variant: non-null before the loop and null at the end of the loop body +public void testBug415413c() { + Map options = getCompilerOptions(); + runNegativeTestWithLibs( + new String[]{ + "ClassF.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class ClassF {\n" + + " public static void needNonNull(@NonNull Object o) {\n" + + " o.hashCode();\n" + + " }\n" + + " public void method() {\n" + + " for (int j = 0; j < 1; j++) {\n" + + " try {\n" + + " this.hashCode();\n" + + " } finally {\n" + + " Object o = new Object();\n" + + " for (int i = 0; i < 1; i++) {\n" + + " needNonNull(o);\n" + + " o = null;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in ClassF.java (at line 13)\n" + + " needNonNull(o);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is inferred as @Nullable\n" + + "----------\n"); +} +public void testBug_415269() { + Map options = getCompilerOptions(); + runConformTestWithLibs( + new String[]{ + "Y.java", + "import org.eclipse.jdt.annotation.NonNull;\n"+ + "public class Y {\n"+ + " public static class C implements X.I {\n"+ + " public void method(@NonNull Object arg) {\n"+ + " }\n"+ + " }\n"+ + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n"+ + "@NonNullByDefault\n"+ + "public class X {\n"+ + " public interface I {\n"+ + " public void method(Object arg);\n"+ + " }\n"+ + "}\n" + }, + options, + ""); +} +public void testBug416267() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void test() {\n" + + " Missing m = new Missing() { };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Missing m = new Missing() { };\n" + + " ^^^^^^^\n" + + "Missing cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Missing m = new Missing() { };\n" + + " ^^^^^^^\n" + + "Missing cannot be resolved to a type\n" + + "----------\n", + this.LIBS, + true, /*flush*/ + null /*options*/); +} +//duplicate of bug 416267 +public void testBug418843() { + runNegativeTest( + new String[] { + "TestEnum.java", + "public enum TestEnum {\n" + + " TestEntry(1){};\n" + + "}" + }, + "----------\n" + + "1. ERROR in TestEnum.java (at line 2)\n" + + " TestEntry(1){};\n" + + " ^^^^^^^^^\n" + + "The constructor TestEnum(int) is undefined\n" + + "----------\n", + this.LIBS, + true,/*flush*/ + null/*options*/); +} +public void testBug418235() { + String[] testFiles = + new String[] { + "GenericInterface.java", + "public interface GenericInterface {\n" + + " T doSomethingGeneric(T o);\n" + + "}", + "Implementation.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "public class Implementation implements GenericInterface {\n" + + "\n" + + (this.complianceLevel < ClassFileConstants.JDK1_6 ? "\n" : " @Override\n" ) + + " public Object doSomethingGeneric(Object o) {\n" + + " return o;\n" + + " }\n" + + "}\n" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runNegativeTestWithLibs( + testFiles, + "----------\n" + + "1. ERROR in Implementation.java (at line 6)\n" + + " public Object doSomethingGeneric(Object o) {\n" + + " ^^^^^^\n" + + "Illegal redefinition of parameter o, inherited method from GenericInterface does not constrain this parameter\n" + + "----------\n"); + } else { + // in 1.8 the nullness default also affects the type argument from which T is instantiated to '@NonNull Object' + runConformTestWithLibs( + testFiles, getCompilerOptions(), ""); + } +} +public void testBug418235b() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + runNegativeTestWithLibs( + new String[] { + "GenericInterface.java", + "public interface GenericInterface {\n" + + " T doSomethingGeneric(T o);\n" + + "}", + "Implementation.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault({DefaultLocation.PARAMETER,DefaultLocation.RETURN_TYPE})\n" + + "public class Implementation implements GenericInterface {\n" + + "\n" + + " @Override\n" + + " public Object doSomethingGeneric(Object o) {\n" + + " return o;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Implementation.java (at line 6)\n" + + " public Object doSomethingGeneric(Object o) {\n" + + " ^^^^^^\n" + + "Illegal redefinition of parameter o, inherited method from GenericInterface does not constrain this parameter\n" + + "----------\n"); +} + +public void testTypeAnnotationProblemNotIn17() { + String source = + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " public @NonNull java.lang.String test(@NonNull java.lang.String arg) {\n" + + " @NonNull java.lang.String local = arg;\n" + + " return local;\n" + + " }\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) + runConformTestWithLibs( + new String[] { + "X.java", + source + }, + getCompilerOptions(), + ""); + else + runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public @NonNull java.lang.String test(@NonNull java.lang.String arg) {\n" + + " ^^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public @NonNull java.lang.String test(@NonNull java.lang.String arg) {\n" + + " ^^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " @NonNull java.lang.String local = arg;\n" + + " ^^^^^^^^\n" + + "Illegally placed annotation: type annotations must directly precede the simple name of the type they are meant to affect (or the [] for arrays)\n" + + "----------\n", + this.LIBS, + true, // flush + getCompilerOptions()); +} +public void testBug420313() { + runWarningTestWithLibs( + true, /*flush*/ + new String[] { + "OverrideTest.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class OverrideTest implements TypedBase, UntypedBase\n" + + "{\n" + + " public void doSomething(String text) // No warning\n" + + " {\n" + + " System.out.println(text);\n" + + " }\n" + + " \n" + + " public void doSomethingElse(String text) // \"Missing non-null annotation\" warning\n" + + " {\n" + + " System.out.println(text);\n" + + " }\n" + + "}\n" + + "\n" + + "interface TypedBase\n" + + "{\n" + + " void doSomething(@NonNull T text);\n" + + "}\n" + + "\n" + + "interface UntypedBase\n" + + "{\n" + + " void doSomethingElse(@NonNull String text);\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in OverrideTest.java (at line 5)\n" + + " public void doSomething(String text) // No warning\n" + + " ^^^^^^\n" + + "Missing non-null annotation: inherited method from TypedBase specifies this parameter as @NonNull\n" + + "----------\n" + + "2. WARNING in OverrideTest.java (at line 10)\n" + + " public void doSomethingElse(String text) // \"Missing non-null annotation\" warning\n" + + " ^^^^^^\n" + + "Missing non-null annotation: inherited method from UntypedBase specifies this parameter as @NonNull\n" + + "----------\n"); +} +// original test +public void testBug424624() { + runConformTestWithLibs( + new String[] { + "Test3.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class Test3 {\n" + + "\n" + + " public Test3() {\n" + + " }\n" + + "\n" + + " static public class Test3aa extends Object {}\n" + + " static public final @NonNull Test3aa Test3a = new Test3aa();\n" + + "\n" + + "}\n", + }, + getCompilerOptions(), + ""); + runConformTestWithLibs( + false /*flush*/, + new String[] { + "Test4.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class Test4 {\n" + + "\n" + + " public Test4() {\n" + + " }\n" + + " \n" + + " public void test() {\n" + + " test1( Test3.Test3a);\n" + + " }\n" + + " \n" + + " public void test1( @NonNull Object object) {\n" + + " }\n" + + "\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// other nesting levels, binary case +public void testBug424624a() { + runConformTestWithLibs( + new String[] { + "test/Test3.java", + "package test;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + (this.complianceLevel >= ClassFileConstants.JDK1_8 ? + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE) @interface Marker {}\n" + : + "" + )+ + "\n" + + "public class Test3 {\n" + + "\n" + + " public Test3() {\n" + + " }\n" + + "\n" + + " public class Inner extends Object {\n" + + " class DeepInner {}\n" + + " }\n" + + " public static class Nested extends Object {\n" + + " class InnerInNested {}\n" + + " static class DeepNested {}\n" + + " }\n" + + " static public final @NonNull Inner field1 = new Test3().new Inner();\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + " static public final @NonNull Inner.DeepInner field2 = field1.new DeepInner();\n" + + " static public final @NonNull Nested.InnerInNested field3 = new Nested().new InnerInNested();\n" + + " static public final @NonNull Nested.DeepNested field4 = new Nested.DeepNested();\n" + : + " static public final @Marker Inner.@NonNull DeepInner field2 = field1.new DeepInner();\n" + + " static public final Nested.@NonNull InnerInNested field3 = new Nested().new InnerInNested();\n" + + " static public final Nested.@NonNull DeepNested field4 = new Nested.DeepNested();\n" + ) + + "\n" + + "}\n", + }, + getCompilerOptions(), + ""); + runConformTestWithLibs( + false /*flush*/, + new String[] { + "Test4.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import test.Test3;\n" + + "\n" + + "public class Test4 {\n" + + "\n" + + " public Test4() {\n" + + " }\n" + + " \n" + + " public void test() {\n" + + " test1( Test3.field1);\n" + + " test1( Test3.field2);\n" + + " test1( Test3.field3);\n" + + " test1( Test3.field4);\n" + + " }\n" + + " \n" + + " public void test1( @NonNull Object object) {\n" + + " }\n" + + "\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// same as previous, source case for reference +public void testBug424624b() { + runConformTestWithLibs( + new String[] { + "Test3.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + (this.complianceLevel >= ClassFileConstants.JDK1_8 ? + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE) @interface Marker {}\n" + : + "" + )+ + "\n" + + "public class Test3 {\n" + + "\n" + + " public Test3() {\n" + + " }\n" + + "\n" + + " public class Inner extends Object {\n" + + " class DeepInner {}\n" + + " }\n" + + " public static class Nested extends Object {\n" + + " class InnerInNested {}\n" + + " static class DeepNested {}\n" + + " }\n" + + " static public final @NonNull Inner field1 = new Test3().new Inner();\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + " static public final @NonNull Inner.DeepInner field2 = field1.new DeepInner();\n" + + " static public final @NonNull Nested.InnerInNested field3 = new Nested().new InnerInNested();\n" + + " static public final @NonNull Nested.DeepNested field4 = new Nested.DeepNested();\n" + : + " static public final @Marker Inner.@NonNull DeepInner field2 = field1.new DeepInner();\n" + + " static public final Nested.@NonNull InnerInNested field3 = new Nested().new InnerInNested();\n" + + " static public final Nested.@NonNull DeepNested field4 = new Nested.DeepNested();\n" + ) + + "\n" + + "}\n", + "Test4.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class Test4 {\n" + + "\n" + + " public Test4() {\n" + + " }\n" + + " \n" + + " public void test() {\n" + + " test1( Test3.field1);\n" + + " test1( Test3.field2);\n" + + " test1( Test3.field3);\n" + + " test1( Test3.field4);\n" + + " }\n" + + " \n" + + " public void test1( @NonNull Object object) {\n" + + " }\n" + + "\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug430084() { + runNegativeTest( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "public class X {" + + " Y() {} " + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public class X { Y() {} }\n" + + " ^^^\n" + + "Return type for the method is missing\n" + + "----------\n", + this.LIBS, + true, /*flush*/ + null /*options*/); +} +public void testBug432348() { + String sourceString = + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import java.lang.annotation.*;\n" + + "\n" + + "@Target(ElementType.FIELD)\n" + + "@interface Marker {}\n" + + "public enum E {\n" + + " @Marker @NonNull A, B, C\n" + + "}\n"; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runConformTestWithLibs( + new String[] { + "E.java", + sourceString + }, + getCompilerOptions(), + ""); + } else { + runNegativeTestWithLibs( + new String[] { + "E.java", + sourceString + }, + "----------\n" + + "1. ERROR in E.java (at line 7)\n" + + " @Marker @NonNull A, B, C\n" + + " ^^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n"); + } +} +// Bug 403674 - [compiler][null] Switching on @Nullable enum value does not trigger "Potential null pointer access" warning +// String value being used in switch condition. +public void testBug403674() { + Map options = getCompilerOptions(); + runNegativeTestWithLibs( + new String[]{ + "X.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " // Correctly flagged as \"Potential null pointer access.\"\n" + + " switch (computeStringValue()) {}\n" + + " }\n" + + " private static @Nullable String computeStringValue() { return null; }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " switch (computeStringValue()) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_7 + ? + "Cannot switch on a value of type String for source level below 1.7. " + + "Only convertible int values or enum variables are permitted\n" + : + "Potential null pointer access: The method computeStringValue() may return null\n" + ) + + "----------\n"); +} +// Bug 403674 - [compiler][null] Switching on @Nullable enum value does not trigger "Potential null pointer access" warning +// Enum value being used in switch condition. +public void testBug403674a() { + Map options = getCompilerOptions(); + runNegativeTestWithLibs( + new String[]{ + "X.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public class X {\n" + + " private enum EnumValue{}\n" + + " public static void main(String[] args) {\n" + + " // Before Fix: Not flagged.\n" + + " switch (computeEnumValue()) {}\n" + + " @Nullable EnumValue value = computeEnumValue();\n" + + " // Correctly flagged as \"Potential null pointer access.\"\n" + + " // Before Fix: Not flagged.\n" + + " switch (value) {}\n" + + " }\n" + + " private static @Nullable EnumValue computeEnumValue() { return null; }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " switch (computeEnumValue()) {}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The method computeEnumValue() may return null\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " switch (value) {}\n" + + " ^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? + "Potential null pointer access: The variable value may be null at this location\n" + : + "Potential null pointer access: this expression has a '@Nullable' type\n" + ) + + "----------\n"); +} +// original test +public void testBug422796() { + runConformTestWithLibs( + new String[] { + "NullExprTest.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class NullExprTest {\n" + + " \n" + + " private @Nullable Boolean b() { return null; }\n" + + " \n" + + " public void testBoolean() {\n" + + " Boolean b1 = b();\n" + + " boolean b = b1 == null || \n" + + " b1; // <-- Previously bugggy: reported potential NPE (*)\n" + + " assertTrue(b);\n" + + " }\n" + + " static void assertTrue(boolean b) {}\n" + + "\n" + + "}" + }, + getCompilerOptions(), + ""); +} +// inverted logic: +public void testBug422796a() { + runConformTestWithLibs( + new String[] { + "NullExprTest.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class NullExprTest {\n" + + " \n" + + " private @Nullable Boolean b() { return null; }\n" + + " \n" + + " public void testBoolean() {\n" + + " Boolean b1 = b();\n" + + " boolean b = b1 != null && \n" + + " b1; // <-- Previously bugggy: reported potential NPE (*)\n" + + " assertTrue(b);\n" + + " }\n" + + " static void assertTrue(boolean b) {}\n" + + "\n" + + "}" + }, + getCompilerOptions(), + ""); +} +// negative tests: +public void testBug422796b() { + runNegativeTestWithLibs( + new String[] { + "NullExprTest.java", + "public class NullExprTest {\n" + + " \n" + + " private Boolean b() { return null; }\n" + + " \n" + + " public void testBoolean1() {\n" + + " Boolean b1 = b();\n" + + " boolean b = b1 == null && \n" + + " b1; // <-- definite NPE (*)\n" + + " assertTrue(b);\n" + + " }\n" + + " public void testBoolean2(boolean x) {\n" + + " Boolean b1 = b();\n" + + " boolean b = (b1 == null || x) && \n" + + " b1; // <-- potential NPE (*)\n" + + " assertTrue(b);\n" + + " }\n" + + " static void assertTrue(boolean b) {}\n" + + "\n" + + "}" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in NullExprTest.java (at line 8)\n" + + " b1; // <-- definite NPE (*)\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in NullExprTest.java (at line 14)\n" + + " b1; // <-- potential NPE (*)\n" + + " ^^\n" + + "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" + + "----------\n"); +} +public void testBug434374() { + runConformTestWithLibs( + new String[] { + "bal/AdapterService.java", + "/*******************************************************************************\n" + + " * Copyright (c) 2013 BestSolution.at and others.\n" + + " * All rights reserved. This program and the accompanying materials\n" + + " * are made available under the terms of the Eclipse Public License v1.0\n" + + " * which accompanies this distribution, and is available at\n" + + " * http://www.eclipse.org/legal/epl-v10.html\n" + + " *\n" + + " * Contributors:\n" + + " * Tom Schindl - initial API and implementation\n" + + " *******************************************************************************/\n" + + "package bal;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public interface AdapterService {\n" + + " public boolean canAdapt(@Nullable Object sourceObject, @NonNull Class targetType);\n" + + "\n" + + " @Nullable\n" + + " public A adapt(@Nullable Object sourceObject, @NonNull Class targetType, ValueAccess... valueAccesses);\n" + + "\n" + + " public interface ValueAccess {\n" + + " @Nullable\n" + + " public O getValue(@NonNull String key);\n" + + "\n" + + " @Nullable\n" + + " public O getValue(@NonNull Class key);\n" + + " }\n" + + "}\n", + "bal/AdapterServiceImpl.java", + "/*******************************************************************************\n" + + " * Copyright (c) 2013 BestSolution.at and others.\n" + + " * All rights reserved. This program and the accompanying materials\n" + + " * are made available under the terms of the Eclipse Public License v1.0\n" + + " * which accompanies this distribution, and is available at\n" + + " * http://www.eclipse.org/legal/epl-v10.html\n" + + " *\n" + + " * Contributors:\n" + + " * Tom Schindl - initial API and implementation\n" + + " *******************************************************************************/\n" + + "package bal;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class AdapterServiceImpl implements AdapterService {\n" + + "\n" + + (this.complianceLevel >= ClassFileConstants.JDK1_6 + ? " @Override\n" + : "") + + " public boolean canAdapt(@Nullable Object sourceObject, @NonNull Class targetType) {\n" + + " return false;\n" + + " }\n" + + "\n" + + (this.complianceLevel >= ClassFileConstants.JDK1_6 + ? " @Override\n" + : "") + + " @Nullable\n" + + " public A adapt(@Nullable Object sourceObject, @NonNull Class targetType, ValueAccess... valueAccesses) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// test return type compatibility +public void testBug434374a() { + runConformTestWithLibs( + new String[] { + "bug434374/AdapterService.java", + "package bug434374;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public interface AdapterService {\n" + + " public @NonNull Class getClassOfA(A object);\n" + + "\n" + + "}\n", + "bug434374/AdapterServiceImpl.java", + "package bug434374;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class AdapterServiceImpl implements AdapterService {\n" + + "\n" + + (this.complianceLevel >= ClassFileConstants.JDK1_6 + ? " @Override\n" + : "") + + " @NonNull\n" + + " public Class getClassOfA(A object) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// original (broken) test (second part): +public void testBug434374b() { + runNegativeTestWithLibs( + new String[] { + "bal/TestGeneric.java", + "package bal;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class TestGeneric {\n" + + " @NonNull\n" + + " public T test() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in bal\\TestGeneric.java (at line 7)\n" + + " return null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull T\' but the provided value is null\n" + + "----------\n"); +} +// rectified test: +public void testBug434374c() { + runConformTestWithLibs( + new String[] { + "bal/TestGeneric.java", + "package bal;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class TestGeneric {\n" + + " public @Nullable T test() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} + +// @NNBD should not affect implicit constructor +public void testBug443347() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "abstract class Super {\n" + + " Super(String s) { }\n" + + " abstract void bar();\n" + + " void foo() { bar(); }\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void test1(@Nullable String s) {\n" + + " new Super(s) {\n" + + " @Override\n" + + " void bar() {}\n" + + " }.foo();\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} + +// explicit annotation on super ctor should be inherited +public void testBug443347b() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "abstract class Super {\n" + + " Super(@NonNull String s) { }\n" + + " abstract void bar();\n" + + " void foo() { bar(); }\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void test1(@Nullable String s) {\n" + + " new Super(s) {\n" + + " @Override\n" + + " void bar() {}\n" + + " }.foo();\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " new Super(s) {\n" + + " ^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Null type mismatch: required \'@NonNull String\' but the provided value is specified as @Nullable\n" + : "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n") + + "----------\n"); +} + +// @NNBD on super ctor should be inherited +public void testBug443347c() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "abstract class Super {\n" + + " Super(String s) { }\n" + + " abstract void bar();\n" + + " void foo() { bar(); }\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void test1(@Nullable String s) {\n" + + " new Super(s) {\n" + + " @Override\n" + + " void bar() {}\n" + + " }.foo();\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " new Super(s) {\n" + + " ^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Null type mismatch: required \'@NonNull String\' but the provided value is specified as @Nullable\n" + : "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n") + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=444024, Type mismatch error in annotation generics assignment which happens "sometimes" +public void test444024() { + this.runConformTest( + new String[] { + "ViewpointOrganisationEntity.java", + "abstract public class ViewpointOrganisationEntity {\n" + + "}\n", + "MetaCombo.java", + "public @interface MetaCombo {\n" + + " Class< ? extends IComboDataSet< ? >> dataSet();\n" + + "}\n", + "IComboDataSet.java", + "public interface IComboDataSet {\n" + + "}\n", + "ContractantTypeLister.java", + "public class ContractantTypeLister implements IComboDataSet {\n" + + "}\n", + "ContractantType.java", + "@MetaCombo(dataSet = ContractantTypeLister.class)\n" + + "public class ContractantType extends ViewpointOrganisationEntity {\n" + + "}\n", + "Contractant.java", + "public class Contractant extends ViewpointOrganisationEntity {\n" + + " @MetaCombo(dataSet = ContractantTypeLister.class)\n" + + " public ContractantType getContractantType() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + ""); +} +public void testBug435805() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + options.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + runNegativeTest( + true/*flush*/, + new String[] { + "org/foo/Nullable.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})\n" + + "public @interface Nullable {}\n", + "org/foo/NonNull.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})\n" + + "public @interface NonNull {}\n", + "TestNulls.java", + "import org.foo.*;\n" + + "\n" + + "public class TestNulls {\n" + + " public void testCase(@Nullable String theValue) {\n" + + " int len = theValue.length(); // Is nullable, so should report error here.\n" + + " }\n" + + "\n" + + "}" + }, + null/*libs*/, + options, + "----------\n" + + "1. ERROR in TestNulls.java (at line 5)\n" + + " int len = theValue.length(); // Is nullable, so should report error here.\n" + + " ^^^^^^^^\n" + + "Potential null pointer access: The variable theValue may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +public void testBug445147() { + runConformTestWithLibs( + new String[] { + "foobar/Bar.java", + "package foobar;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "interface Bar, F extends Foo> {}", + "foobar/Foo.java", + "package foobar;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "interface Foo, B extends Bar> {}" + }, + getCompilerOptions(), + ""); +} +public void testBug445708() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // uses switch on string. + runNegativeTestWithLibs( + new String[] { + "SwitchTest.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class SwitchTest\n" + + "{\n" + + " private enum EnumValue\n" + + " {\n" + + " }\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " // Should be flagged as \"Potential null pointer access,\" but is not.\n" + + " switch (computeStringValue())\n" + + " {\n" + + " }\n" + + " \n" + + " @Nullable String stringValue = null;\n" + + " \n" + + " // Properly flagged as \"Null pointer access.\"\n" + + " switch (stringValue)\n" + + " {\n" + + " }\n" + + " \n" + + " stringValue = computeStringValue();\n" + + " \n" + + " // Should be flagged as \"Potential null pointer access,\" but is not.\n" + + " switch (stringValue)\n" + + " {\n" + + " }\n" + + " \n" + + " // Should also be flagged, but is not.\n" + + " switch (computeEnumValue())\n" + + " {\n" + + " }\n" + + " \n" + + " @Nullable EnumValue enumValue = null;\n" + + " \n" + + " // Fixed in bug #403674.\n" + + " switch (enumValue)\n" + + " {\n" + + " }\n" + + " }\n" + + " \n" + + " private static @Nullable String computeStringValue()\n" + + " {\n" + + " return null;\n" + + " }\n" + + " \n" + + " private static @Nullable EnumValue computeEnumValue()\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in SwitchTest.java (at line 12)\n" + + " switch (computeStringValue())\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The method computeStringValue() may return null\n" + + "----------\n" + + "2. ERROR in SwitchTest.java (at line 19)\n" + + " switch (stringValue)\n" + + " ^^^^^^^^^^^\n" + + "Null pointer access: The variable stringValue can only be null at this location\n" + + "----------\n" + + "3. ERROR in SwitchTest.java (at line 26)\n" + + " switch (stringValue)\n" + + " ^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Potential null pointer access: The variable stringValue may be null at this location\n" + : "Potential null pointer access: this expression has a \'@Nullable\' type\n" ) + + "----------\n" + + "4. ERROR in SwitchTest.java (at line 31)\n" + + " switch (computeEnumValue())\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The method computeEnumValue() may return null\n" + + "----------\n" + + "5. ERROR in SwitchTest.java (at line 38)\n" + + " switch (enumValue)\n" + + " ^^^^^^^^^\n" + + "Null pointer access: The variable enumValue can only be null at this location\n" + + "----------\n"); +} +// same as above but 1.8 with declaration annotations +public void testBug445708b() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // only one combination tested + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + runNegativeTestWithLibs( + new String[] { + CUSTOM_NULLABLE_NAME, + CUSTOM_NULLABLE_CONTENT, + "SwitchTest.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class SwitchTest\n" + + "{\n" + + " private enum EnumValue\n" + + " {\n" + + " }\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " // Should be flagged as \"Potential null pointer access,\" but is not.\n" + + " switch (computeStringValue())\n" + + " {\n" + + " }\n" + + " \n" + + " @Nullable String stringValue = null;\n" + + " \n" + + " // Properly flagged as \"Null pointer access.\"\n" + + " switch (stringValue)\n" + + " {\n" + + " }\n" + + " \n" + + " stringValue = computeStringValue();\n" + + " \n" + + " // Should be flagged as \"Potential null pointer access,\" but is not.\n" + + " switch (stringValue)\n" + + " {\n" + + " }\n" + + " \n" + + " // Should also be flagged, but is not.\n" + + " switch (computeEnumValue())\n" + + " {\n" + + " }\n" + + " \n" + + " @Nullable EnumValue enumValue = null;\n" + + " \n" + + " // Fixed in bug #403674.\n" + + " switch (enumValue)\n" + + " {\n" + + " }\n" + + " }\n" + + " \n" + + " private static @Nullable String computeStringValue()\n" + + " {\n" + + " return null;\n" + + " }\n" + + " \n" + + " private static @Nullable EnumValue computeEnumValue()\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in SwitchTest.java (at line 12)\n" + + " switch (computeStringValue())\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The method computeStringValue() may return null\n" + + "----------\n" + + "2. ERROR in SwitchTest.java (at line 19)\n" + + " switch (stringValue)\n" + + " ^^^^^^^^^^^\n" + + "Null pointer access: The variable stringValue can only be null at this location\n" + + "----------\n" + + "3. ERROR in SwitchTest.java (at line 26)\n" + + " switch (stringValue)\n" + + " ^^^^^^^^^^^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n" + + "4. ERROR in SwitchTest.java (at line 31)\n" + + " switch (computeEnumValue())\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The method computeEnumValue() may return null\n" + + "----------\n" + + "5. ERROR in SwitchTest.java (at line 38)\n" + + " switch (enumValue)\n" + + " ^^^^^^^^^\n" + + "Null pointer access: The variable enumValue can only be null at this location\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=452780 - Internal compiler error: arrayIndexOutOfBounds +public void testBug452780() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; + runConformTestWithLibs( + new String[] { + "Tools2.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "import java.util.Set;\n" + + "import java.util.stream.Collector;\n" + + "import java.util.stream.Collectors;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class Tools2 {\n" + + " @SafeVarargs\n" + + " public static List<@NonNull T> asList(T... ts) {\n" + + " @SuppressWarnings(\"null\")\n" + + " @NonNull\n" + + " List<@NonNull T> res = Arrays.asList(ts);\n" + + " return res;\n" + + " }\n" + + " @SuppressWarnings(\"null\")\n" + + " public static Collector<@NonNull T, @NonNull ?, @NonNull Set<@NonNull T>> toSet() {\n" + + " @NonNull\n" + + " Collector<@NonNull T, ?, @NonNull Set<@NonNull T>> res = Collectors\n" + + " .toSet();\n" + + " return res;\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + ""); +} +public void testBug455557() { + runWarningTestWithLibs( + true, /*flush*/ + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "\n" + + "public class X {\n" + + " void test(List list, boolean b) {\n" + + " if (b) {\n" + + " while (true) {\n" + + " for (@NonNull Object y : list) { \n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + null, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " for (@NonNull Object y : list) { \n" + + " ^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Null type safety: The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + : "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + ) + + "----------\n"); +} +public void testBug455723() { + runConformTestWithLibs( + new String[] { + "Problem.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Problem {\n" + + " public void fubar(final @Nullable String arg) {\n" + + " if (arg == null) {\n" + + " return;\n" + + " }\n" + + " \n" + + " doSomething(arg);\n" + + " // no errors here\n" + + " \n" + + " while (true) { \n" + + " doSomething(arg);\n" + + " // ^^^ compiler error\n" + + " }\n" + + " }\n" + + " \n" + + " private void doSomething(@NonNull String arg) { }\n" + + "}\n" + }, + null, + ""); +} +public void testBug455723b() { + runConformTestWithLibs( + new String[] { + "Problem.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Problem {\n" + + " public void fubar(final @Nullable String arg) {\n" + + " if (arg == null) {\n" + + " return;\n" + + " }\n" + + " @NonNull String local;\n" + + " \n" + + " while (true) { \n" + + " local = arg;\n" + + " }\n" + + " }\n" + + "}\n" + }, + null, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=436486 +public void test_null_with_apt() { + boolean apt = this.enableAPT; + this.enableAPT = true; + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_MISSING_NONNULL_BY_DEFAULT_ANNOTATION, JavaCore.WARNING); + customOptions.put(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "NullWarn.java", + "@SuppressWarnings(\"null\")\n" + + "public class NullWarn {\n" + + "\n" + + " // Some code\n" + + "\n" + + "}\n" + }, + customOptions, + ""); + this.enableAPT = apt; +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=436486#c4 +public void test_null_with_apt_comment4() { + boolean apt = this.enableAPT; + this.enableAPT = true; + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN, JavaCore.ERROR); + runWarningTestWithLibs( + true, // flush + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + "\n" + + " public static final Test t = new Test(Integer.valueOf(0));\n" + + "\n" + + " public Test(Integer integer) {\n" + + " \n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. WARNING in Test.java (at line 6)\n" + + " public static final Test t = new Test(Integer.valueOf(0));\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? "Null type safety: The expression of type \'Integer\' needs unchecked conversion to conform to \'@NonNull Integer\'\n" + : "Null type safety (type annotations): The expression of type \'Integer\' needs unchecked conversion to conform to \'@NonNull Integer\'\n" + ) + + "----------\n"); + this.enableAPT = apt; +} +public void testBug457210() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + runNegativeNullTest( + new String[] { + "org/foo/NonNull.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "public @interface NonNull {\n" + + "}\n", + "org/foo/Nullable.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "public @interface Nullable {\n" + + "}\n", + "TestRunner.java", + "import org.foo.*;\n" + + "public class TestRunner {\n" + + " private TestRunner() {}\n" + + "\n" + + " @Nullable\n" + + " OutputHelper m_outputHelper;\n" + + " int foo(@NonNull OutputHelper helper) { return helper.i; }\n" + + "}\n", + "OutputHelper.java", + "@org.foo.NonNull public class OutputHelper {\n" + + " public int i;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in OutputHelper.java (at line 1)\n" + + " @org.foo.NonNull public class OutputHelper {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The nullness annotation \'NonNull\' is not applicable at this location\n" + + "----------\n", + null, + true, + customOptions); +} +public void testBug462790() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // multi catch used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runWarningTestWithLibs( + true, /*flush*/ + new String[] { + "EclipseBug.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class EclipseBug {\n" + + "\n" + + " public void method(Class commandType) {\n" + + " String command = (String)getCommand(commandType);\n" + + " }\n" + + " \n" + + " public static T getCommand(Class commandType) {\n" + + " try {\n" + + " return commandType.newInstance();\n" + + " } catch (InstantiationException | IllegalAccessException e) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " }\n" + + "}" + }, + options, + "----------\n" + + "1. WARNING in EclipseBug.java (at line 5)\n" + + " String command = (String)getCommand(commandType);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from capture#1-of ? extends String to String\n" + + "----------\n" + + "2. WARNING in EclipseBug.java (at line 8)\n" + + " public static T getCommand(Class commandType) {\n" + + " ^^^^^^\n" + + "The type parameter T should not be bounded by the final type String. Final types cannot be further extended\n" + + "----------\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? + "3. WARNING in EclipseBug.java (at line 10)\n" + + " return commandType.newInstance();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety: The expression of type \'T\' needs unchecked conversion to conform to \'@NonNull T\'\n" + + "----------\n" + : + "3. INFO in EclipseBug.java (at line 10)\n" + + " return commandType.newInstance();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull Class\'. Type \'Class\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n")); +} +public void testBug459967_Enum_valueOf() { + runConformTestWithLibs( + new String[] { + "MyEnum.java", + "public enum MyEnum { V1, V2 }\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull MyEnum forString(String name) {\n" + + " return MyEnum.valueOf(name);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug459967_Enum_valueOf_binary() { + runConformTest( + new String[] { + "MyEnum.java", + "public enum MyEnum { V1, V2 }\n" + }); + runConformTestWithLibs( + false /*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull MyEnum forString(String name) {\n" + + " return MyEnum.valueOf(name);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug459967_Enum_values() { + String[] testFiles = new String[] { + "MyEnum.java", + "public enum MyEnum { V1, V2 }\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? + " @NonNull MyEnum[] getValues() {\n" + : + " @NonNull MyEnum @NonNull[] getValues() {\n" + )+ + " return MyEnum.values();\n" + + " }\n" + + " void printAll() {\n" + + " for (@NonNull MyEnum value : MyEnum.values())\n" + + " System.out.println(value);\n" + + " }\n" + + "}\n" + }; + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runConformTestWithLibs( + testFiles, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " for (@NonNull MyEnum value : MyEnum.values())\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null type safety: The expression of type \'MyEnum\' needs unchecked conversion to conform to \'@NonNull MyEnum\'\n" + + "----------\n"); + } else { + runConformTestWithLibs( + testFiles, + getCompilerOptions(), + ""); + } +} +public void testBug459967_Enum_values_binary() { + String[] testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + (this.complianceLevel < ClassFileConstants.JDK1_8 + ? + " @NonNull MyEnum[] getValues() {\n" + : + " @NonNull MyEnum @NonNull[] getValues() {\n" + )+ + " return MyEnum.values();\n" + + " }\n" + + " void printAll() {\n" + + " for (@NonNull MyEnum value : MyEnum.values())\n" + + " System.out.println(value);\n" + + " }\n" + + "}\n" + }; + runConformTest( + new String[] { + "MyEnum.java", + "public enum MyEnum { V1, V2 }\n", + }); + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + runConformTestWithLibs( + false /*flush*/, + testFiles, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " for (@NonNull MyEnum value : MyEnum.values())\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null type safety: The expression of type \'MyEnum\' needs unchecked conversion to conform to \'@NonNull MyEnum\'\n" + + "----------\n"); + } else { + runConformTestWithLibs( + false /*flush*/, + testFiles, + getCompilerOptions(), + ""); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=407414 +// Incorrect warning on a primitive type being null. +public void test407414a() { + String testCode = "package p1;\n" + + "public class Test {\n" + + " void fooI(int i) { \n" + + " barI(i);\n" + + " }\n" + + " void fooB(boolean i) {\n" + + " barB(i);\n" + + " }\n" + + " void fooBy(byte i) {\n" + + " barBy(i);\n" + + " }\n" + + " void fooF(float i) {\n" + + " barF(i);\n" + + " }\n" + + " void fooL(long i) {\n" + + " barL(i);\n" + + " }\n" + + " void fooC(char i) {\n" + + " barC(i);\n" + + " }\n" + + " void fooS(short i) {\n" + + " barS(i);\n" + + " }\n" + + " static void barI(Integer i) {}\n" + + " static void barB(Boolean i) {}\n" + + " static void barBy(Byte i) {}\n" + + " static void barF(Float i) {}\n" + + " static void barL(Long i) {}\n" + + " static void barC(Character i) {}\n" + + " static void barS(Short i) {}\n" + + "}"; + String pcode = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;"; + runConformTestWithLibs( + new String[] { + "p1/package-info.java", + pcode, + "p1/Test.java", + testCode + }, + getCompilerOptions(), + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=407414 +// Incorrect warning on a primitive type being null. +// The information that boxing is happening at i2 = i +// and therefore there cannot be null values in i2 is +// not flowing down to access of i2. +// The test case also illustrates array access and Qualified access. +public void test407414b() { + String testCode = "package p1;\n" + + " public class Test {\n" + + " class Y {\n" + + " class Z {\n" + + " int i;\n" + + " int a[];\n" + + " Z() {\n" + + " a = new int[0];\n" + + " }\n" + + " }\n" + + " }\n" + + " void foo(int i) {\n" + + " Integer i2 = i;\n" + + " bar(i2);\n" + + " }\n" + + " void fooA(int a[], int i) {\n" + + " Integer i2 = a[i];\n" + + " bar(i2);\n" + + " }\n" + + " void fooQ(Y.Z yz, int i) {\n" + + " Integer i2 = yz.i;\n" + + " bar(i2);\n" + + " i2 = yz.a[i];\n" + + " bar(i2);\n" + + " }\n" + + " static void bar(Integer i) { }\n" + + "}"; + String pcode = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;"; + runConformTestWithLibs( + new String[] { + "p1/package-info.java", + pcode, + "p1/Test.java", + testCode + }, + getCompilerOptions(), + ""); +} + +public void test407414b2() { + String testCode = "package p1;\n" + + " public class Test {\n" + + " int a[];\n" + + " Test() {\n" + + " a = new int[0];\n" + + " a[0] = 0;\n" + + " }\n" + + " void fooA(int i) {\n" + + " Integer i2 = a[i];\n" + + " bar(i2);\n" + + " }\n" + + " static void bar(Integer i) { }\n" + + "}"; + String pcode = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;"; + runConformTestWithLibs( + new String[] { + "p1/package-info.java", + pcode, + "p1/Test.java", + testCode + }, + getCompilerOptions(), + ""); +} + +// FieldReference. +public void test407414b3() { + String testCode = "package p1;\n" + + "public class Test {\n" + + " class Z {\n" + + " int a[];\n" + + " Z() {\n" + + " a = new int[0];\n" + + " a[0] = 0;\n" + + " }\n" + + " }\n" + + " class Y {\n" + + " Z[] z;\n" + + " Y () {\n" + + " z = new Z[0];\n" + + " }\n" + + " }\n" + + " void fooQ(Y y, int i) {\n" + + " Integer i2 = y.z[i].a[i];\n" + + " bar(i2);\n" + + " }\n" + + " static void bar(Integer i) { }\n" + + "}"; + String pcode = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;"; + runConformTestWithLibs( + new String[] { + "p1/package-info.java", + pcode, + "p1/Test.java", + testCode + }, + getCompilerOptions(), + ""); +} + +// arrayRefrence +public void test407414b4() { + String testCode = "package p1;\n" + + "public class Test {\n" + + " class Y {\n" + + " int a[];\n" + + " Y() {\n" + + " a = new int[0];\n" + + " a[0] = 0;\n" + + " }\n" + + " }\n" + + " void fooQ(Y[] y, int i) {\n" + + " Integer i2 = y[i].a[i];\n" + + " bar(i2);\n" + + " }\n" + + " static void bar(Integer i) { }\n" + + "}"; + String pcode = "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p1;"; + runConformTestWithLibs( + new String[] { + "p1/package-info.java", + pcode, + "p1/Test.java", + testCode + }, + getCompilerOptions(), + ""); +} + +// value of a (compound) assignment +public void testBug407414c() { + runConformTestWithLibs( + new String[] { + "X.java", + "public class X {\n" + + " int fI;\n" + + " @org.eclipse.jdt.annotation.NonNull Integer test1(int i) {\n" + + " return fI = i;\n" + + " }\n" + + " @org.eclipse.jdt.annotation.NonNull Integer test2(int i) {\n" + + " return fI += i;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} + +// primitive cast +public void testBug407414d() { + runConformTestWithLibs( + new String[] { + "X.java", + "public class X {\n" + + " @org.eclipse.jdt.annotation.NonNull Long test(int i) {\n" + + " return (long)i;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} + +// conditional +public void testBug407414e() { + runConformTestWithLibs( + new String[] { + "X.java", + "public class X {\n" + + " @org.eclipse.jdt.annotation.NonNull Long test(long l, boolean b) {\n" + + " return b ? l : 3;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} + +// operators +public void testBug407414f() { + runConformTestWithLibs( + new String[] { + "X.java", + "public class X {\n" + + " @org.eclipse.jdt.annotation.NonNull Long test1(long l) {\n" + + " return l + 3;\n" + + " }\n" + + " @org.eclipse.jdt.annotation.NonNull Long test2(long l) {\n" + + " return l << 3;\n" + + " }\n" + + " @org.eclipse.jdt.annotation.NonNull Long test3(long l) {\n" + + " return l++;\n" + + " }\n" + + " @org.eclipse.jdt.annotation.NonNull Long test4(long l) {\n" + + " return -l;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=428104 +// Null annotation heuristics does not understand autoboxed primitives to be non-null. +public void test428104() { + String testCode = "package p1;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class Test {\n" + + " @NonNull\n" + + " Boolean case1Parent() {\n" + + " return case1Child();\n" + + " }\n" + + " boolean case1Child() {\n" + + " return Math.random() > 0.5;\n" + + " }\n" + + "}\n"; + String pcode = "package p1;"; + runConformTestWithLibs( + new String[] { + "p1/package-info.java", + pcode, + "p1/Test.java", + testCode + }, + getCompilerOptions(), + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=424702 +// Warning at an assignment of a boolean-Variable to an Boolean-Variable +public void test424702() { + String testCode = "package p1;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class Test {\n" + + " private @NonNull Boolean t = true;\n" + + " Boolean foo() {\n" + + " boolean y = false;\n" + + " t = y;\n" + + " return t;\n" + + " }\n" + + "}\n"; + String pcode = "package p1;"; + runConformTestWithLibs( + new String[] { + "p1/package-info.java", + pcode, + "p1/Test.java", + testCode + }, + getCompilerOptions(), + ""); +} + +public void testBug237236() { + runConformTestWithLibs( + new String[] { + "X.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class X {\n" + + " public void x(Long l) {}\n" + + " public long z() { return 0L; }\n" + + " public void y() { x(z()); }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug418236() { + runConformTestWithLibs( + new String[] { + "MyClass.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class MyClass {\n" + + " private static final int CONSTANT = 24;\n" + + "\n" + + " public Integer returnConstant() {\n" + + " return CONSTANT; // <-- incorrect error. Integer.valueOf is declared as non-null.\n" + + " }\n" + + "\n" + + " public Integer returnInteger() {\n" + + " return 24; // <-- no error reported here\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug461878() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "javax.annotation.Nonnull"); + runNegativeTest( + true, /*flush*/ + new String[] { + "javax/annotation/Nonnull.java", + "package javax.annotation;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "public @interface Nonnull {\n" + + "}\n", + "edu/umd/cs/findbugs/annotations/PossiblyNull.java", + "package edu.umd.cs.findbugs.annotations;\n" + + "@javax.annotation.Nonnull // <-- error!!!\n" + + "public @interface PossiblyNull {\n" + + "}\n" + }, + null, /*libs*/ + compilerOptions, + "----------\n" + + "1. WARNING in edu\\umd\\cs\\findbugs\\annotations\\PossiblyNull.java (at line 2)\n" + + " @javax.annotation.Nonnull // <-- error!!!\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The nullness annotation \'Nonnull\' is not applicable at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} +public void testBug467610() { + runConformTestWithLibs( + new String[] { + "SuperClass.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public abstract class SuperClass {\n" + + "\n" + + " abstract T doSomething(T arg);\n" + + "\n" + + " abstract String returnAString();\n" + + "\n" + + " public static abstract class SubClass extends SuperClass {\n" + + "\n" + + " @Override\n" + + " abstract S doSomething(S arg);\n" + + "\n" + + " @Override\n" + + " abstract String returnAString();\n" + + " \n" + + " }\n" + + "\n" + + "}" + }, + getCompilerOptions(), + ""); +} +public void testBug477719() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void consume(@NonNull Class c) {}\n" + + " void test(Double d) {\n" + + " consume(Integer.class);\n" + + " consume(d.getClass());\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug482075() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "TestIncidentImports2.java", + "public class TestIncidentImports2 {\n" + + "\n" + + " private String arg0;\n" + + " private TestIncidentImports2 arg2;\n" + + "\n" + + " public TestIncidentImports2(String arg0) {\n" + + " this.arg0 = arg0;\n" + + " }\n" + + "\n" + + " protected void apply(Object o) throws Exception {\n" + + " arg0.length();\n" + + " other(arg0);\n" + // arg0 is protected by dereference as MessageSend.receiver +// still triggers an error: QualifiedNameReference doesn't have an ASTNode representing the receiver +// " if (arg2.arg0 != null && other(arg2))\n" + // arg2 is protected by dereference from QualifiedNameReference +// " System.out.println(7);\n" + + " if (this.arg2.arg0 != null && other(arg2))\n" + // arg2 is protected by dereference as FieldReference.receiver + " System.out.println(9);\n" + + " }\n" + + "\n" + + " boolean other(@org.eclipse.jdt.annotation.NonNull Object o) {\n" + + " return true;\n" + + " }\n" + + "}\n" + }, + options, + "" + ); +} +public void testMultipleAnnotations() { + Map options1 = new HashMap<>(getCompilerOptions()); + options1.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo1.NonNull"); + options1.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo1.Nullable"); + runConformTest( + new String[] { + "org/foo1/Nullable.java", + "package org.foo1;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})\n" + + "public @interface Nullable {}\n", + "org/foo1/NonNull.java", + "package org.foo1;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})\n" + + "public @interface NonNull {}\n", + "p1/TestNulls.java", + "package p1;\n" + + "import org.foo1.*;\n" + + "\n" + + "public class TestNulls {\n" + + " public @Nullable String weaken(@NonNull String theValue) {\n" + + " return theValue;\n" + + " }\n" + + "\n" + + "}" + }, + options1); + Map options2 = new HashMap<>(getCompilerOptions()); + options2.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo2.NonNull2"); + options2.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo2.Nullable2"); + options2.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "org.foo2.NoNulls2"); + options2.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION, JavaCore.WARNING); + runConformTest( + false, // flush + new String[] { + "org/foo2/Nullable2.java", + "package org.foo2;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})\n" + + "public @interface Nullable2 {}\n", + "org/foo2/NonNull2.java", + "package org.foo2;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.LOCAL_VARIABLE})\n" + + "public @interface NonNull2 {}\n", + "org/foo2/NoNulls2.java", + "package org.foo2;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})\n" + + "public @interface NoNulls2 {}\n", + "p2/TestNulls2.java", + "package p2;\n" + + "import org.foo2.*;\n" + + "\n" + + "public class TestNulls2 {\n" + + " public @Nullable2 String weaken(@NonNull2 String theValue) {\n" + + " return theValue;\n" + + " }\n" + + " @NoNulls2\n" + + " public String strong(String theValue) {\n" + + " return weaken(theValue);\n" + + " }\n" + + "\n" + + "}", + "p2/TestNulls2a.java", + "package p2;\n" + + "import org.foo2.*;\n" + + "\n" + + "@NoNulls2\n" + + "public class TestNulls2a {\n" + + " public String strong(String theValue) {\n" + + " return theValue;\n" + + " }\n" + + "\n" + + "}" + }, + null, //libs + options2, + "----------\n" + + "1. WARNING in p2\\TestNulls2.java (at line 10)\n" + + " return weaken(theValue);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null type mismatch: required \'@NonNull2 String\' but the provided value is specified as @Nullable2\n" + + "----------\n", + "", + "", + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + Map options3 = getCompilerOptions(); + options3.put(JavaCore.COMPILER_NONNULL_ANNOTATION_SECONDARY_NAMES, "org.foo1.NonNull,org.foo2.NonNull2"); + options3.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_SECONDARY_NAMES, " org.foo1.Nullable , org.foo2.Nullable2 "); // some spaces to test trimming + options3.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES, "org.foo2.NoNulls2"); + runNegativeTestWithLibs( + new String[] { + "p3/Test.java", + "package p3;\n" + + "import p1.TestNulls;\n" + + "import p2.TestNulls2;\n" + + "import p2.TestNulls2a;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Test {\n" + + " @NonNull String test1(TestNulls test, @Nullable String input) {\n" + + " return test.weaken(input);\n" + + " }\n" + + " @NonNull String test2(TestNulls2 test, @Nullable String input) {\n" + + " return test.weaken(input);\n" + + " }\n" + + " @NonNull String test3(TestNulls2 test, @Nullable String input) {\n" + + " return test.strong(input); // requires nonnull due to method-level default\n" + + " }\n" + + " @NonNull String test4(TestNulls2a test, @Nullable String input) {\n" + + " return test.strong(input); // requires nonnull due to type-level default\n" + + " }\n" + + "}\n" + }, + options3, + "----------\n" + + "1. ERROR in p3\\Test.java (at line 8)\n" + + " return test.weaken(input);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "2. ERROR in p3\\Test.java (at line 8)\n" + + " return test.weaken(input);\n" + + " ^^^^^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "3. ERROR in p3\\Test.java (at line 11)\n" + + " return test.weaken(input);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "4. ERROR in p3\\Test.java (at line 11)\n" + + " return test.weaken(input);\n" + + " ^^^^^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "5. ERROR in p3\\Test.java (at line 14)\n" + + " return test.strong(input); // requires nonnull due to method-level default\n" + + " ^^^^^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n" + + "6. ERROR in p3\\Test.java (at line 17)\n" + + " return test.strong(input); // requires nonnull due to type-level default\n" + + " ^^^^^\n" + + mismatch_NonNull_Nullable("String") + + "----------\n"); +} + +public void testBug489486conform() { + runConformTestWithLibs( + new String[] { + "test/DurationAdapter.java", + "package test;\n" + + "\n" + + "final class DurationAdapter extends java.lang.ref.SoftReference {\n" + + " public DurationAdapter(String referent) {\n" + + " super(referent);\n" + + " }\n" + + "}\n", + "test/TheAnnotation.java", + "package test;\n" + + "\n" + + "public @interface TheAnnotation {\n" + + " Class> value();\n" + + "}\n", + "test/package-info.java", + "@TheAnnotation(value = DurationAdapter.class)\n" + + "package test;\n", + }, + getCompilerOptions(), + "" + ); +} + +public void testBug489486negative() { + runNegativeTest( + new String[] { + "test/DurationAdapter.java", + "package test;\n" + + "\n" + + "final class DurationAdapter extends java.lang.ref.WeakReference {\n" + + " public DurationAdapter(String referent) {\n" + + " super(referent);\n" + + " }\n" + + "}\n", + "test/TheAnnotation.java", + "package test;\n" + + "\n" + + "public @interface TheAnnotation {\n" + + " Class> value();\n" + + "}\n", + "test/package-info.java", + "@TheAnnotation(value = DurationAdapter.class)\n" + + "package test;\n", + }, + "----------\n" + + "1. ERROR in test\\package-info.java (at line 1)\n" + + " @TheAnnotation(value = DurationAdapter.class)\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class>\n" + + "----------\n", + this.LIBS, + true, /*flush*/ + getCompilerOptions() + ); +} +public void testBug502113() { + runConformTestWithLibs( + new String[] { + "test/I.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public interface I {\n" + + " String method();\n" + + "\n" + + " boolean equals(@Nullable Object obj);\n" + + " @NonNull String toString();\n" + + "}\n" + + "", + "test/X.java", + "package test;\n" + + "\n" + + "public class X implements I {\n" + + " public String method() {\n" + + " return \"\";\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug502113b() { + runNegativeTestWithLibs( + new String[] { + "test/I.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public interface I {\n" + + " String method();\n" + + "\n" + + " boolean equals(@Nullable Object obj);\n" + + " @NonNull String toString();\n" + + "}\n" + + "", + "test/X.java", + "package test;\n" + + "\n" + + "public class X implements I {\n" + + " public String method() {\n" + + " return \"\";\n" + + " }\n" + + " @Override\n" + + " public boolean equals(Object other) {\n" + + " return false;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\X.java (at line 8)\n" + + " public boolean equals(Object other) {\n" + + " ^^^^^^\n" + + "Missing nullable annotation: inherited method from I specifies this parameter as @Nullable\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 12)\n" + + " public String toString() {\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull String\' returned from I.toString() (mismatching null constraints)\n" + + "----------\n" + ); +} +public void testBug502214() { + runNegativeTestWithLibs( + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class A {\n" + + " public boolean m1(Object obj) {\n" + + " return this == obj;\n" + + " }\n" + + " public @Nullable String m2() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "interface I {\n" + + " public boolean m1(@Nullable Object obj);\n" + + " public @NonNull String m2(); \n" + + "}\n" + + "\n" + + "public class X {\n" + + " I f() {\n" + + " class Y extends A implements I {\n" + + " }\n" + + " return new Y();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in test\\X.java (at line 22)\n" + + " class Y extends A implements I {\n" + + " ^\n" + + "The method m2() from A cannot implement the corresponding method from I due to incompatible nullness constraints\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 22)\n" + + " class Y extends A implements I {\n" + + " ^\n" + + "The method m1(Object) from A cannot implement the corresponding method from I due to incompatible nullness constraints\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in test\\X.java (at line 22)\n" + + " class Y extends A implements I {\n" + + " ^\n" + + "The method @Nullable String m2() from A cannot implement the corresponding method from I due to incompatible nullness constraints\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 22)\n" + + " class Y extends A implements I {\n" + + " ^\n" + + "The method m1(Object) from A cannot implement the corresponding method from I due to incompatible nullness constraints\n" + + "----------\n" + ) + ); +} + +//apply null default to parameters: +public void testBug530970_param() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import annotation.*;\n" + + "@NonNullByDefault(DefaultLocation.PARAMETER)\n" + + "public class X {\n" + + " Number test1(Number in) {\n" + + " System.out.print(in.intValue()); // OK\n" + + " test1(null); // ERR\n" + + " return null; // OK\n" + + " }\n" + + " java.lang.Number test2(java.lang.Number in) {\n" + + " System.out.print(in.intValue()); // OK\n" + + " test2(null); // ERR\n" + + " return null; // OK\n" + + " }\n" + + " void redundant(@NonNullByDefault(DefaultLocation.PARAMETER) java.lang.Number in) { // WARNING\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " test1(null); // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " test2(null); // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " void redundant(@NonNullByDefault(DefaultLocation.PARAMETER) java.lang.Number in) { // WARNING\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type X\n" + + "----------\n" + ); +} + +//apply null default to return type - annotation at method: +public void testBug530970_return() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import annotation.*;\n" + + "public class X {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " Number test(Number in) {\n" + + " System.out.print(in.intValue());\n" + + " test(null); // OK\n" + + " return null; // ERR\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return null; // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n"); +} + +//apply null default to field +public void testBug530970_field() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import annotation.*;\n" + + "@NonNullByDefault(DefaultLocation.FIELD)\n" + + "public class X {\n" + + " Number field; // ERR since uninitialized\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Number field; // ERR since uninitialized\n" + + " ^^^^^\n" + + "The @NonNull field field may not have been initialized\n" + + "----------\n"); +} + +//default default +public void testBug530970_default() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " Number field; // ERR since uninitialized\n" + + " void test1(Number[] ns) {\n" + + " ns[0] = null; // OK since not affected by default\n" + + " }\n" + + " void test2(java.lang.Number[] ns) {\n" + + " ns[0] = null; // OK since not affected by default\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Number field; // ERR since uninitialized\n" + + " ^^^^^\n" + + "The @NonNull field field may not have been initialized\n" + + "----------\n"); +} + +//apply null default to parameters: +public void testBug530970_param_bin() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runConformTestWithLibs( + false, + new String[] { + "X.java", + "import annotation.*;\n" + + "@NonNullByDefault(DefaultLocation.PARAMETER)\n" + + "public class X {\n" + + " Number test1(Number in) {\n" + + " return null; // OK\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y.java", + "import annotation.*;\n" + + "public class Y {\n" + + " @NonNull Number test(X x) {\n" + + " return x.test1(null); // error at arg, unchecked at return\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. WARNING in Y.java (at line 4)\n" + + " return x.test1(null); // error at arg, unchecked at return\n" + + " ^^^^^^^^^^^^^\n" + + "Null type safety: The expression of type \'Number\' needs unchecked conversion to conform to \'@NonNull Number\'\n" + + "----------\n" + + "2. ERROR in Y.java (at line 4)\n" + + " return x.test1(null); // error at arg, unchecked at return\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n"); +} + +//apply null default to return type - annotation at method: +public void testBug530970_return_bin() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runConformTestWithLibs( + false, + new String[] { + "X.java", + "import annotation.*;\n" + + "public class X {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " Number test(Number in) {\n" + + " return new MyInteger(13);\n" + + " }\n" + + "}\n" + + "class MyInteger extends Number {\n" + + "private static final long serialVersionUID = 1L;\n" + + " public MyInteger(int i) {}\n" + + " @Override\n" + + " public int intValue() { return 0;}\n" + + " @Override\n" + + " public long longValue() { return 0; }\n" + + " @Override\n" + + " public float floatValue() { return 0;}\n" + + " @Override\n" + + " public double doubleValue() { return 0; }\n" + + "}\n" + + }, + customOptions, + ""); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "Y.java", + "import annotation.*;\n" + + "public class Y {\n" + + " @NonNull Number test(X x) {\n" + + " return x.test(null); // both OK\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); +} + +//apply null default to field +public void testBug530970_field_bin() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runConformTestWithLibs( + false, + new String[] { + "X.java", + "import annotation.*;\n" + + "@NonNullByDefault(DefaultLocation.FIELD)\n" + + "public class X {\n" + + " Number field = new MyDouble(1.1);\n" + + "}\n" + + "class MyDouble extends Number {\n" + + "private static final long serialVersionUID = 1L;\n" + + " public MyDouble(double d) {}\n" + + " @Override\n" + + " public int intValue() { return 0;}\n" + + " @Override\n" + + " public long longValue() { return 0; }\n" + + " @Override\n" + + " public float floatValue() { return 0;}\n" + + " @Override\n" + + " public double doubleValue() { return 0; }\n" + + "}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y.java", + "public class Y {\n" + + " void test(X x) {\n" + + " x.field = null; // ERR\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " x.field = null; // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n");} + +//default default +public void testBug530970_default_bin() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runConformTestWithLibs( + false, + new String[] { + "X.java", + "import annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " Number field = new MyLong(13);\n" + + " void test1(Number[] ns) {\n" + + " ns[0] = null; // OK since not affected by default\n" + + " }\n" + + "}\n" + + "class MyLong extends Number {\n" + + "private static final long serialVersionUID = 1L;\n" + + " public MyLong(long l) {}\n" + + " @Override\n" + + " public int intValue() { return 0;}\n" + + " @Override\n" + + " public long longValue() { return 0; }\n" + + " @Override\n" + + " public float floatValue() { return 0;}\n" + + " @Override\n" + + " public double doubleValue() { return 0; }\n" + + "}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y.java", + "public class Y {\n" + + " void test(X x) {\n" + + " x.test1(new Number[1]); // OK since not affected by default\n" + + " x.field = null; // ERR\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y.java (at line 4)\n" + + " x.field = null; // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n");} + +public void testBug530970_on_field_and_local() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runNegativeTestWithLibs( + new String[] { + "nnbd_test1/Test.java", + "package nnbd_test1;\n" + + "\n" + + "import annotation.DefaultLocation;\n" + + "import annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault({ DefaultLocation.RETURN_TYPE, DefaultLocation.PARAMETER })\n" + + "abstract class X {\n" + + " @NonNullByDefault(DefaultLocation.FIELD)\n" + + " public Object a = \"\";\n" + + "\n" + + " @NonNullByDefault({})\n" + + " public Object b;\n" + + "\n" + + " @NonNullByDefault\n" + + " abstract String f(Integer p);\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " abstract String g(Integer p);\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " abstract String h(Integer p);\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " abstract String i(@NonNullByDefault({}) Integer p);\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " X x1 = new X() {\n" + + " @Override\n" + + " public String f(Integer p) { // warning on parameter expected\n" + + " this.a = null; // warning expected\n" + + " this.b = null;\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String g(Integer p) {\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String h(Integer p) { // warning on parameter type expected\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String i(Integer p) {\n" + + " return null; // warning expected\n" + + " }\n" + + " };\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " X x2 = new X() {\n" + + " @Override\n" + + " public String f(Integer p) { // warning on return type expected\n" + + " this.a = null; // warning expected\n" + + " this.b = null;\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String h(Integer p) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String i(Integer p) { // warning on parameter expected\n" + + " return null;\n" + + " }\n" + + " };\n" + + "\n" + + " void method() {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " X l1 = new X() {\n" + + " @Override\n" + + " public String f(Integer p) { // warning on parameter expected\n" + + " this.a = null; // warning expected\n" + + " this.b = null;\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String g(Integer p) {\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String h(Integer p) { // warning on parameter type expected\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String i(Integer p) {\n" + + " return null; // warning expected\n" + + " }\n" + + " };\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " X l2 = new X() {\n" + + " @Override\n" + + " public String f(Integer p) { // warning on return type expected\n" + + " this.a = null; // warning expected\n" + + " this.b = null;\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String h(Integer p) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String i(Integer p) { // warning on parameter expected\n" + + " return null;\n" + + " }\n" + + " };\n" + + "\n" + + " l1.equals(l2);\n" + + " }\n" + + "}\n" + + "", + }, + customOptions, + "----------\n" + + "1. WARNING in nnbd_test1\\Test.java (at line 32)\n" + + " public String f(Integer p) { // warning on parameter expected\n" + + " ^^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "2. ERROR in nnbd_test1\\Test.java (at line 33)\n" + + " this.a = null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in nnbd_test1\\Test.java (at line 35)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "4. ERROR in nnbd_test1\\Test.java (at line 40)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "5. WARNING in nnbd_test1\\Test.java (at line 44)\n" + + " public String h(Integer p) { // warning on parameter type expected\n" + + " ^^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "6. ERROR in nnbd_test1\\Test.java (at line 45)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "7. ERROR in nnbd_test1\\Test.java (at line 50)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "8. ERROR in nnbd_test1\\Test.java (at line 56)\n" + + " public String f(Integer p) { // warning on return type expected\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull String\' returned from X.f(Integer) (mismatching null constraints)\n" + + "----------\n" + + "9. ERROR in nnbd_test1\\Test.java (at line 57)\n" + + " this.a = null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "10. ERROR in nnbd_test1\\Test.java (at line 63)\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull String\' returned from X.g(Integer) (mismatching null constraints)\n" + + "----------\n" + + "11. ERROR in nnbd_test1\\Test.java (at line 63)\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " ^^^^^^^\n" + + "Illegal redefinition of parameter p, inherited method from X does not constrain this parameter\n" + + "----------\n" + + "12. ERROR in nnbd_test1\\Test.java (at line 73)\n" + + " public String i(Integer p) { // warning on parameter expected\n" + + " ^^^^^^^\n" + + "Illegal redefinition of parameter p, inherited method from X does not constrain this parameter\n" + + "----------\n" + + "13. WARNING in nnbd_test1\\Test.java (at line 82)\n" + + " public String f(Integer p) { // warning on parameter expected\n" + + " ^^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "14. ERROR in nnbd_test1\\Test.java (at line 83)\n" + + " this.a = null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "15. ERROR in nnbd_test1\\Test.java (at line 85)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "16. ERROR in nnbd_test1\\Test.java (at line 90)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "17. WARNING in nnbd_test1\\Test.java (at line 94)\n" + + " public String h(Integer p) { // warning on parameter type expected\n" + + " ^^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "18. ERROR in nnbd_test1\\Test.java (at line 95)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "19. ERROR in nnbd_test1\\Test.java (at line 100)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "20. ERROR in nnbd_test1\\Test.java (at line 106)\n" + + " public String f(Integer p) { // warning on return type expected\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull String\' returned from X.f(Integer) (mismatching null constraints)\n" + + "----------\n" + + "21. ERROR in nnbd_test1\\Test.java (at line 107)\n" + + " this.a = null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "22. ERROR in nnbd_test1\\Test.java (at line 113)\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull String\' returned from X.g(Integer) (mismatching null constraints)\n" + + "----------\n" + + "23. ERROR in nnbd_test1\\Test.java (at line 113)\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " ^^^^^^^\n" + + "Illegal redefinition of parameter p, inherited method from X does not constrain this parameter\n" + + "----------\n" + + "24. ERROR in nnbd_test1\\Test.java (at line 123)\n" + + " public String i(Integer p) { // warning on parameter expected\n" + + " ^^^^^^^\n" + + "Illegal redefinition of parameter p, inherited method from X does not constrain this parameter\n" + + "----------\n" + ); +} +public void testBug530970_on_field_bin() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runConformTestWithLibs( + false, + new String[] { + "nnbd_test1/X.java", + "package nnbd_test1;\n" + + "\n" + + "import annotation.DefaultLocation;\n" + + "import annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault({ DefaultLocation.RETURN_TYPE, DefaultLocation.PARAMETER })\n" + + "abstract class X {\n" + + " @NonNullByDefault(DefaultLocation.FIELD)\n" + + " public Object a = \"\";\n" + + "\n" + + " @NonNullByDefault({})\n" + + " public Object b;\n" + + "\n" + + " @NonNullByDefault\n" + + " abstract String f(Integer p);\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " abstract String g(Integer p);\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " abstract String h(Integer p);\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " abstract String i(@NonNullByDefault({}) Integer p);\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runNegativeTestWithLibs( + new String[] { + "nnbd_test1/Test.java", + "package nnbd_test1;\n" + + "\n" + + "import annotation.DefaultLocation;\n" + + "import annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault({ DefaultLocation.RETURN_TYPE, DefaultLocation.PARAMETER })\n" + + "abstract class Unused { // just here to keep line number in sync with testBug530970_on_field_and_local\n" + + " @NonNullByDefault(DefaultLocation.FIELD)\n" + + " public Object a = \"\";\n" + + "\n" + + " @NonNullByDefault({})\n" + + " public Object b;\n" + + "\n" + + " @NonNullByDefault\n" + + " abstract String f(Integer p);\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " abstract String g(Integer p);\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " abstract String h(Integer p);\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " abstract String i(@NonNullByDefault({}) Integer p);\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " X x1 = new X() {\n" + + " @Override\n" + + " public String f(Integer p) { // warning on parameter expected\n" + + " this.a = null; // warning expected\n" + + " this.b = null;\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String g(Integer p) {\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String h(Integer p) { // warning on parameter type expected\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String i(Integer p) {\n" + + " return null; // warning expected\n" + + " }\n" + + " };\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " X x2 = new X() {\n" + + " @Override\n" + + " public String f(Integer p) { // warning on return type expected\n" + + " this.a = null; // warning expected\n" + + " this.b = null;\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String h(Integer p) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String i(Integer p) { // warning on parameter expected\n" + + " return null;\n" + + " }\n" + + " };\n" + + "\n" + + " void method() {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " X l1 = new X() {\n" + + " @Override\n" + + " public String f(Integer p) { // warning on parameter expected\n" + + " this.a = null; // warning expected\n" + + " this.b = null;\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String g(Integer p) {\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String h(Integer p) { // warning on parameter type expected\n" + + " return null; // warning expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String i(Integer p) {\n" + + " return null; // warning expected\n" + + " }\n" + + " };\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " X l2 = new X() {\n" + + " @Override\n" + + " public String f(Integer p) { // warning on return type expected\n" + + " this.a = null; // warning expected\n" + + " this.b = null;\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String h(Integer p) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public String i(Integer p) { // warning on parameter expected\n" + + " return null;\n" + + " }\n" + + " };\n" + + "\n" + + " l1.equals(l2);\n" + + " }\n" + + "}\n" + + "", + }, + customOptions, + "----------\n" + + "1. WARNING in nnbd_test1\\Test.java (at line 32)\n" + + " public String f(Integer p) { // warning on parameter expected\n" + + " ^^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "2. ERROR in nnbd_test1\\Test.java (at line 33)\n" + + " this.a = null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in nnbd_test1\\Test.java (at line 35)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "4. ERROR in nnbd_test1\\Test.java (at line 40)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "5. WARNING in nnbd_test1\\Test.java (at line 44)\n" + + " public String h(Integer p) { // warning on parameter type expected\n" + + " ^^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "6. ERROR in nnbd_test1\\Test.java (at line 45)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "7. ERROR in nnbd_test1\\Test.java (at line 50)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "8. ERROR in nnbd_test1\\Test.java (at line 56)\n" + + " public String f(Integer p) { // warning on return type expected\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull String\' returned from X.f(Integer) (mismatching null constraints)\n" + + "----------\n" + + "9. ERROR in nnbd_test1\\Test.java (at line 57)\n" + + " this.a = null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "10. ERROR in nnbd_test1\\Test.java (at line 63)\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull String\' returned from X.g(Integer) (mismatching null constraints)\n" + + "----------\n" + + "11. ERROR in nnbd_test1\\Test.java (at line 63)\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " ^^^^^^^\n" + + "Illegal redefinition of parameter p, inherited method from X does not constrain this parameter\n" + + "----------\n" + + "12. ERROR in nnbd_test1\\Test.java (at line 73)\n" + + " public String i(Integer p) { // warning on parameter expected\n" + + " ^^^^^^^\n" + + "Illegal redefinition of parameter p, inherited method from X does not constrain this parameter\n" + + "----------\n" + + "13. WARNING in nnbd_test1\\Test.java (at line 82)\n" + + " public String f(Integer p) { // warning on parameter expected\n" + + " ^^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "14. ERROR in nnbd_test1\\Test.java (at line 83)\n" + + " this.a = null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "15. ERROR in nnbd_test1\\Test.java (at line 85)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "16. ERROR in nnbd_test1\\Test.java (at line 90)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "17. WARNING in nnbd_test1\\Test.java (at line 94)\n" + + " public String h(Integer p) { // warning on parameter type expected\n" + + " ^^^^^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "18. ERROR in nnbd_test1\\Test.java (at line 95)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "19. ERROR in nnbd_test1\\Test.java (at line 100)\n" + + " return null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "20. ERROR in nnbd_test1\\Test.java (at line 106)\n" + + " public String f(Integer p) { // warning on return type expected\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull String\' returned from X.f(Integer) (mismatching null constraints)\n" + + "----------\n" + + "21. ERROR in nnbd_test1\\Test.java (at line 107)\n" + + " this.a = null; // warning expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "22. ERROR in nnbd_test1\\Test.java (at line 113)\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull String\' returned from X.g(Integer) (mismatching null constraints)\n" + + "----------\n" + + "23. ERROR in nnbd_test1\\Test.java (at line 113)\n" + + " public String g(Integer p) { // warning on return type and parameter expected\n" + + " ^^^^^^^\n" + + "Illegal redefinition of parameter p, inherited method from X does not constrain this parameter\n" + + "----------\n" + + "24. ERROR in nnbd_test1\\Test.java (at line 123)\n" + + " public String i(Integer p) { // warning on parameter expected\n" + + " ^^^^^^^\n" + + "Illegal redefinition of parameter p, inherited method from X does not constrain this parameter\n" + + "----------\n" + ); +} +public void testBug542707_001() { + if (this.complianceLevel < ClassFileConstants.JDK12) + return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.io.IOException;\n"+ + "\n"+ + "import org.eclipse.jdt.annotation.NonNull;\n"+ + "\n"+ + "public class X {\n"+ + " public static int foo(int i) throws IOException {\n"+ + " int k = 0;\n"+ + " @NonNull\n"+ + " X x = new X();\n"+ + " x = switch (i) { \n"+ + " case 1 -> {\n"+ + " x = null;\n"+ + " break x;\n"+ + " }\n"+ + " default -> null;\n"+ + " };\n"+ + "\n"+ + " return k ;\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " try {\n"+ + " System.out.println(foo(3));\n"+ + " } catch (IOException e) {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 0)\n" + + " import java.io.IOException;\n" + + " ^\n" + + "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" + + "----------\n" + ); +} +/** + * should not throw IOOBE while building - a safety check test case. + */ +public void testBug542707_002() { + if (this.complianceLevel != ClassFileConstants.JDK12) + return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_12); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_12); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void m1(@NonNull String a) {}\n" + + " void m2(@Nullable String b, int i) {\n" + + " m1(switch(i) {\n" + + " case 0 : {\n" + + " break \"hello\";\n" + + " }\n" + + " default : break \"world\";\n" + + " });\n" + + " }\n" + + " void m3() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 0)\n" + + " import org.eclipse.jdt.annotation.*;\n" + + " ^\n" + + "Preview features enabled at an invalid source release level 12, preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" + + "----------\n" + ); +} +public void testBug542707_003() { + if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression + // outer expected type (from assignment) is propagated deeply into a switch expression + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + runner.customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runner.classLibraries = this.LIBS; + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable String maybe() { return null; }\n" + + " void test(int i) {\n" + + " @NonNull String s = switch (i) {\n" + + " case 1 -> \"\";\n" + + " default -> i == 3 ? maybe() : \"\";\n" + + " };\n" + + " System.out.println(s.toLowerCase());\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = checkPreviewAllowed() ? + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " default -> i == 3 ? maybe() : \"\";\n" + + " ^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 0)\n" + + " import org.eclipse.jdt.annotation.*;\n" + + " ^\n" + + "Preview features enabled at an invalid source release level "+CompilerOptions.versionFromJdkLevel(this.complianceLevel)+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" + + "----------\n"; + runner.runNegativeTest(); +} +// failing, see https://bugs.eclipse.org/543860 +public void _testBug542707_004() { + if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression + // outer expected type (from method parameter) is propagated deeply into a switch expression + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + runner.customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runner.classLibraries = this.LIBS; + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable String maybe() { return null; }\n" + + " void need(@NonNull String s) {\n" + + " System.out.println(s.toLowerCase());\n" + + " }\n" + + " void test(int i) {\n" + + " need(switch (i) {\n" + + " case 1 -> \"\";\n" + + " default -> i == 3 ? maybe() : \"\";\n" + + " });\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " default -> i == 3 ? maybe() : \"\";\n" + + " ^^^^^^^\n" + + "Null type mismatch (type annotations): required '@NonNull String' but this expression has type '@Nullable String'\n" + + "----------\n"; + runner.runNegativeTest(); +} +public void testBug542707_005() { + if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression + // switch value must not be null (@Nullable) + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + runner.customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runner.classLibraries = this.LIBS; + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "enum SomeDays { Mon, Wed, Fri }\n" + + "public class X {\n" + + " int testEnum(@Nullable SomeDays day) {\n" + + " return switch(day) {\n" + + " case Mon -> 1;\n" + + " case Wed -> 2;\n" + + " case Fri -> 3;\n" + + " };\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = checkPreviewAllowed() ? + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return switch(day) {\n" + + " ^^^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 0)\n" + + " import org.eclipse.jdt.annotation.*;\n" + + " ^\n" + + "Preview features enabled at an invalid source release level "+CompilerOptions.versionFromJdkLevel(this.complianceLevel)+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" + + "----------\n"; + runner.runNegativeTest(); +} +public void testBug542707_006() { + if (this.complianceLevel < ClassFileConstants.JDK12) return; // switch expression + // switch value must not be null (pot-null by flow analysis) + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + runner.customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runner.classLibraries = this.LIBS; + runner.testFiles = new String[] { + "X.java", + "enum SomeDays { Mon, Wed, Fri }\n" + + "public class X {\n" + + " int testEnum(boolean b) {\n" + + " SomeDays day = b ? SomeDays.Mon : null;\n" + + " return switch(day) {\n" + + " case Mon -> 1;\n" + + " case Wed -> 2;\n" + + " case Fri -> 3;\n" + + " };\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = checkPreviewAllowed() ? + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " return switch(day) {\n" + + " ^^^\n" + + "Potential null pointer access: The variable day may be null at this location\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 0)\n" + + " enum SomeDays { Mon, Wed, Fri }\n" + + " ^\n" + + "Preview features enabled at an invalid source release level "+CompilerOptions.versionFromJdkLevel(this.complianceLevel)+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" + + "----------\n"; + runner.runNegativeTest(); +} +public void testBug545715() { + if (!checkPreviewAllowed()) return; // switch expression + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " void f() {\n"+ + " loop: while(true) {\n"+ + " break loop;\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " new X().f();\n"+ + " }\n"+ + "}\n" + }, + "", + customOptions, + new String[] {"--enable-preview"}); +} +public void testBug548418_001a() { + if (this.complianceLevel < ClassFileConstants.JDK14) return; + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.io.IOException;\n"+ + "\n"+ + "import org.eclipse.jdt.annotation.NonNull;\n"+ + "\n"+ + "public class X {\n"+ + " public static int foo(int i) throws IOException {\n"+ + " int k = 0;\n"+ + " @NonNull\n"+ + " X x = new X();\n"+ + " x = switch (i) { \n"+ + " case 1 -> {\n"+ + " x = null;\n"+ + " break x;\n"+ + " }\n"+ + " default -> null;\n"+ + " };\n"+ + "\n"+ + " return k ;\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " try {\n"+ + " System.out.println(foo(3));\n"+ + " } catch (IOException e) {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " break x;\n" + + " ^^^^^^^^\n" + + "Breaking out of switch expressions not permitted\n" + + "----------\n" + ); +} +public void testBug548418_001b() { + if (this.complianceLevel < ClassFileConstants.JDK14) return; + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.io.IOException;\n"+ + "\n"+ + "import org.eclipse.jdt.annotation.NonNull;\n"+ + "\n"+ + "public class X {\n"+ + " public static int foo(int i) throws IOException {\n"+ + " int k = 0;\n"+ + " @NonNull\n"+ + " X x = new X();\n"+ + " x = switch (i) { \n"+ + " case 1 -> {\n"+ + " x = null;\n"+ + " yield x;\n"+ + " }\n"+ + " default -> null;\n"+ + " };\n"+ + "\n"+ + " return k ;\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " try {\n"+ + " System.out.println(foo(3));\n"+ + " } catch (IOException e) {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " x = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull X\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " default -> null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull X\' but the provided value is null\n" + + "----------\n" + ); +} +public void testBug548418_002a() { + if (this.complianceLevel < ClassFileConstants.JDK14) return; + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void m1(@NonNull String a) {}\n" + + " void m2(@Nullable String b, int i) {\n" + + " m1(switch(i) {\n" + + " case 0 : {\n" + + " break \"hello\";\n" + + " }\n" + + " default : break \"world\";\n" + + " });\n" + + " }\n" + + " void m3() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " break \"hello\";\n" + + " ^^^^^^^\n" + + "Syntax error on token \"\"hello\"\", delete this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " default : break \"world\";\n" + + " ^^^^^^^\n" + + "Syntax error on token \"\"world\"\", delete this token\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + ); +} +public void testBug548418_002b() { + if (this.complianceLevel < ClassFileConstants.JDK14) return; + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void m1(@NonNull String a) {}\n" + + " void m2(@Nullable String b, int i) {\n" + + " m1(switch(i) {\n" + + " case 0 : {\n" + + " yield \"hello\";\n" + + " }\n" + + " default : yield \"world\";\n" + + " });\n" + + " }\n" + + " void m3() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + ); +} +public void testBug499714() { + runConformTestWithLibs( + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object o = null;\n" + + " for (final String s : args) {\n" + + " if (s.equals(\"-x\")) {\n" + + " if (o != null) { // bogus warning here\n" + + " //\n" + + " }\n" + + " continue;\n" + + " }\n" + + " o = read();\n" + + " }\n" + + " }\n" + + "\n" + + " @Nullable\n" + + " public static Object read() {\n" + + " return \"\";\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + ""); +} +public void testBug481931_source() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " static final String CONST = \"const1\";\n" + + " final String INST_CONST = \"const2\" + CONST;\n" + + " @NonNull String getInstConst() {\n" + + " if (INST_CONST == null) {\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " return INST_CONST;\n" + + " }\n" + + " static @NonNull String getConst() {\n" + + " if (CONST == null) {\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " return CONST;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (INST_CONST == null) {\n" + + " ^^^^^^^^^^\n" + + "Null comparison always yields false: The field INST_CONST is a nonnull constant\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " if (INST_CONST == null) {\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " if (CONST == null) {\n" + + " ^^^^^\n" + + "Null comparison always yields false: The field CONST is a nonnull constant\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " if (CONST == null) {\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +public void testBug481931_binary() { + runConformTestWithLibs( + new String[] { + "test/X.java", + "package test;\n" + + "public class X {\n" + + " public static final String CONST = \"const1\";\n" + + " public final String INST_CONST = \"const2\" + CONST;\n" + + " X() {}\n" + + " X(int i) {}\n" + // ctors to demonstrate independence of actual initialization + "}\n" + }, + getCompilerOptions(), + ""); + Runner runner = new Runner(); + runner.shouldFlushOutputDirectory = false; + runner.testFiles = new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import test.X;\n" + + "public class Y {\n" + + " @NonNull String getInstConst(X x) {\n" + + " if (x.INST_CONST == null) {\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " return x.INST_CONST;\n" + + " }\n" + + " static @NonNull String getConst() {\n" + + " if (X.CONST == null) {\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " return X.CONST;\n" + + " }\n" + + "}\n" + }; + runner.classLibraries = this.LIBS; + runner.customOptions = getCompilerOptions(); + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in Y.java (at line 5)\n" + + " if (x.INST_CONST == null) {\n" + + " ^^^^^^^^^^\n" + + "Null comparison always yields false: The field INST_CONST is a nonnull constant\n" + + "----------\n" + + "2. WARNING in Y.java (at line 5)\n" + + " if (x.INST_CONST == null) {\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in Y.java (at line 11)\n" + + " if (X.CONST == null) {\n" + + " ^^^^^\n" + + "Null comparison always yields false: The field CONST is a nonnull constant\n" + + "----------\n" + + "4. WARNING in Y.java (at line 11)\n" + + " if (X.CONST == null) {\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"; + runner.javacTestOptions = Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +public void testBug459397() { + runNegativeTestWithLibs( + new String[] { + "NonNullBug.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class NonNullBug {\n" + + " public static final String PACKid_$metamodel$ = null;\n" + + " public static final String PACKid_http_c_s_s_www_eclipse_org_s_qvt_s_examples_s_0_1_s_SimpleRDBMS = null;\n" + + " public static final String PACKid_http_c_s_s_www_eclipse_org_s_qvt_s_examples_s_0_1_s_UMLtoRDBMS = null;\n" + + " public static final String PACKid_http_c_s_s_www_eclipse_org_s_qvt_s_examples_s_0_1_s_simpleUML = null;\n" + + " public static final String CLSSid_Association = null;\n" + + " public static final String CLSSid_AssociationToForeignKey = null;\n" + + " public static final String CLSSid_Attribute = null;\n" + + " public static final String CLSSid_AttributeToColumn = null;\n" + + " public static final String CLSSid_Class = null;\n" + + " public static final String CLSSid_ClassToTable = null;\n" + + " public static final String CLSSid_Class_0 = null;\n" + + " public static final String CLSSid_Classifier = null;\n" + + " public static final String CLSSid_Column = null;\n" + + " public static final String CLSSid_ForeignKey = null;\n" + + " public static final String CLSSid_FromAttribute = null;\n" + + " public static final String CLSSid_Key = null;\n" + + " public static final String CLSSid_NonLeafAttribute = null;\n" + + " public static final String CLSSid_Package = null;\n" + + " public static final String CLSSid_PackageElement = null;\n" + + " public static final String CLSSid_PackageToSchema = null;\n" + + " public static final String CLSSid_PrimitiveDataType = null;\n" + + " public static final String CLSSid_PrimitiveToName = null;\n" + + " public static final String CLSSid_Schema = null;\n" + + " public static final String CLSSid_Table = null;\n" + + " public static final String STR_2 = \"2\";\n" + + " public static final String STR_BOOLEAN = \"BOOLEAN\";\n" + + " public static final String STR_Boolean = \"Boolean\";\n" + + " public static final String STR_Integer = \"Integer\";\n" + + " public static final String STR_NUMBER = \"NUMBER\";\n" + + " public static final String STR_String = \"String\";\n" + + " public static final String STR_VARCHAR = \"VARCHAR\";\n" + + " public static final String STR__ = \"_\";\n" + + " public static final String STR__pk = \"_pk\";\n" + + " public static final String STR__tid = \"_tid\";\n" + + " public static final String STR_base = \"base\";\n" + + " public static final String STR_persistent = \"persistent\";\n" + + " public static final String STR_primary = \"primary\";\n" + + " public static final String BAG_CLSSid_AttributeToColumn = null;\n" + + " public static final String BAG_CLSSid_FromAttribute = null;\n" + + " public static final String ORD_CLSSid_AssociationToForeignKey = null;\n" + + " public static final String ORD_CLSSid_Attribute = null;\n" + + " public static final String ORD_CLSSid_Column = null;\n" + + " public static final String ORD_CLSSid_ForeignKey = null;\n" + + " public static final String ORD_CLSSid_Key = null;\n" + + " public static final String ORD_CLSSid_PackageElement = null;\n" + + " public static final String SET_CLSSid_Association = null;\n" + + " public static final String SET_CLSSid_Attribute = null;\n" + + " public static final String SET_CLSSid_AttributeToColumn = null;\n" + + " public static final String SET_CLSSid_Class = null;\n" + + " public static final String SET_CLSSid_ClassToTable = null;\n" + + " public static final String SET_CLSSid_FromAttribute = null;\n" + + " public static final String SET_CLSSid_NonLeafAttribute = null;\n" + + " public static final String SET_CLSSid_Package = null;\n" + + " public static final String SET_CLSSid_PrimitiveToName = null;\n" + + "\n" + + " protected final String OPPOSITE_OF_ClassToTable_table = null;\n" + + " protected final String OPPOSITE_OF_ClassToTable_umlClass = null;\n" + + " protected final String OPPOSITE_OF_FromAttribute_attribute = null;\n" + + " protected final String OPPOSITE_OF_PrimitiveToName_primitive = null;\n" + + "\n" + + " @SuppressWarnings(\"unused\")\n" + + " private static final String[] classIndex2classId = new String[] {};\n" + + " @SuppressWarnings(\"unused\")\n" + + " private final static int[][] classIndex2allClassIndexes = new int[][] {};\n" + + "\n" + + " protected String x(final @NonNull Exception a, final @NonNull String p_4, final @Nullable String p2s_9) throws Exception {\n" + + " final @Nullable Throwable destination = a.getCause();\n" + + " final @Nullable Throwable dc = a.getCause();\n" + + " if (dc == null) {\n" + + " throw new Exception();\n" + + " }\n" + + " try {\n" + + " if (dc instanceof Exception) {\n" + + " throw (Exception) dc;\n" + + " }\n" + + " boolean eq_2 = (destination != null) ? destination.equals(dc) : (dc == null);\n" + + " } catch (Exception e) {\n" + + " }\n" + + " boolean ne = (destination != null) ? !destination.equals(dc) : (dc != null);\n" + + " return dc.toString();\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in NonNullBug.java (at line 80)\n" + + " boolean eq_2 = (destination != null) ? destination.equals(dc) : (dc == null);\n" + + " ^^\n" + + "Null comparison always yields false: The variable dc cannot be null at this location\n" + + "----------\n" + + "2. ERROR in NonNullBug.java (at line 83)\n" + + " boolean ne = (destination != null) ? !destination.equals(dc) : (dc != null);\n" + + " ^^\n" + + "Redundant null check: The variable dc cannot be null at this location\n" + + "----------\n"); +} +public void testBug466477() { + runNegativeTestWithLibs( + new String[] { + "SuperI.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public interface SuperI {\n" + + " void testNN(@NonNull String s);\n" + + " void testNu(@Nullable String s);\n" + + "}\n", + "Base.java", + "public class Base {\n" + + " public void testNN(String s) { }\n" + + " public void testNu(String s) { }\n" + + "}\n", + "Custom.java", + "public class Custom extends Base implements SuperI {\n" + + "}" + }, + "----------\n" + + "1. ERROR in Custom.java (at line 1)\n" + + " public class Custom extends Base implements SuperI {\n" + + " ^^^^\n" + + "The method testNu(String) from Base cannot implement the corresponding method from SuperI due to incompatible nullness constraints\n" + + "----------\n" + + "2. WARNING in Custom.java (at line 1)\n" + + " public class Custom extends Base implements SuperI {\n" + + " ^^^^\n" + + "Parameter 1 of method testNN(String) lacks a @NonNull annotation as specified in type SuperI\n" + + "----------\n"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests17.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests17.java new file mode 100644 index 0000000000..4e28565ca0 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests17.java @@ -0,0 +1,495 @@ +/******************************************************************************* + * Copyright (c) 2021 GK Software SE, and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import static org.eclipse.jdt.core.tests.util.Util.createJar; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class NullAnnotationTests17 extends AbstractNullAnnotationTest { + + public NullAnnotationTests17(String name) { + super(name); + } + + static { +// TESTS_NAMES = new String[] { "test_totalTypePatternNonNullExpression" }; +// TESTS_NUMBERS = new int[] { 001 }; +// TESTS_RANGE = new int[] { 1, 12 }; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_17); + } + + public static Class testClass() { + return NullAnnotationTests17.class; + } + + @Deprecated // super method is deprecated + @Override + protected void setUpAnnotationLib() throws IOException { + if (this.LIBS == null) { + String[] defaultLibs = getDefaultClassPaths(); + int len = defaultLibs.length; + this.LIBS = new String[len+1]; + System.arraycopy(defaultLibs, 0, this.LIBS, 0, len); + this.LIBS[len] = createAnnotation_2_2_jar(Util.getOutputDirectory() + File.separator, null); + } + } + + public static String createAnnotation_2_2_jar(String dirName, String jcl17Path) throws IOException { + // role our own annotation library as long as o.e.j.annotation is still at BREE 1.8: + String jarFileName = dirName + "org.eclipse.jdt.annotation_2.2.0.jar"; + createJar(new String[] { + "module-info.java", + "module org.eclipse.jdt.annotation {\n" + + " exports org.eclipse.jdt.annotation;\n" + + "}\n", + + "org/eclipse/jdt/annotation/DefaultLocation.java", + "package org.eclipse.jdt.annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " \n" + + " PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS\n" + + "}\n", + + "org/eclipse/jdt/annotation/NonNullByDefault.java", + "package org.eclipse.jdt.annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" + + "\n" + + "import java.lang.annotation.*;\n" + + " \n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ ElementType.MODULE, ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE })\n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" + + "}", + + "org/eclipse/jdt/annotation/NonNull.java", + "package org.eclipse.jdt.annotation;\n" + + "import static java.lang.annotation.ElementType.TYPE_USE;\n" + + "\n" + + "import java.lang.annotation.*;\n" + + " \n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ TYPE_USE })\n" + + "public @interface NonNull {\n" + + " // marker annotation with no members\n" + + "}\n", + + "org/eclipse/jdt/annotation/Nullable.java", + "package org.eclipse.jdt.annotation;\n" + + "\n" + + "import static java.lang.annotation.ElementType.TYPE_USE;\n" + + "\n" + + "import java.lang.annotation.*;\n" + + " \n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ TYPE_USE })\n" + + "public @interface Nullable {\n" + + " // marker annotation with no members\n" + + "}\n" + }, + null, + jarFileName, + jcl17Path != null ? new String[] { jcl17Path } : null, + "17"); + return jarFileName; + } + + // -------- helper ------------ + + private Runner getDefaultRunner() { + Runner runner = new Runner(); + runner.classLibraries = this.LIBS; + Map opts = getCompilerOptions(); + opts.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17); + opts.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + opts.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runner.customOptions = opts; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + return runner; + } + + // --------- tests start ----------- + + public void test_typePatternIsNN() { + Runner runner = getDefaultRunner(); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(Object o) {\n" + + " switch (o) {\n" + + " case Integer i -> consumeInt(i);\n" + + " default -> System.out.println(\"default\");\n" + + " }\n" + + " }\n" + + " void consumeInt(@NonNull Integer i) {\n" + + " System.out.print(i);\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(3);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = ""; + runner.expectedOutputString = "3"; + runner.runConformTest(); + } + + public void test_totalTypePatternAdmitsNull() { + Runner runner = getDefaultRunner(); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(Number n) {\n" + + " try {\n" + + " switch (n) {\n" + + " case Integer i -> consumeInt(i);\n" + + " case Number n0 -> consumeNumber(n0);\n" + + " }\n" + + " } catch (NullPointerException npe) {\n" + + " // ignoring the unchecked warning, and expecting the NPE:\n" + + " System.out.print(npe.getMessage());\n" + + " }\n" + + " }\n" + + " void consumeInt(@NonNull Integer i) {\n" + + " System.out.print(i);\n" + + " }\n" + + " void consumeNumber(@NonNull Number n) {\n" + + " System.out.print(n.toString());\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(null);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " case Number n0 -> consumeNumber(n0);\n" + + " ^^\n" + + "Null type safety (type annotations): The expression of type \'Number\' needs unchecked conversion to conform to \'@NonNull Number\'\n" + + "----------\n"; + runner.expectedOutputString = "Cannot invoke \"Object.toString()\" because \"n\" is null"; + runner.runConformTest(); + } + + public void test_totalTypePatternNonNullExpression() { + Runner runner = getDefaultRunner(); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(Number n) {\n" + + " if (n == null) return;\n" + // this prevents the NPE -> no need to warn + " switch (n) {\n" + + " case Integer i -> System.out.print(i);\n" + + " case Number n0 -> consumeNumber(n0);\n" + + " }\n" + + " }\n" + + " void consumeNumber(@NonNull Number n) {\n" + + " System.out.print(n.toString());\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(null);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = ""; + runner.expectedOutputString = ""; + runner.runConformTest(); + } + + public void test_totalTypePatternNonNullExpression_swExpr() { + Runner runner = getDefaultRunner(); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " int foo(Number n) {\n" + + " if (n == null) return -1;\n" + // this prevents the NPE -> no need to warn + " return switch (n) {\n" + + " case Integer i -> i;\n" + + " case Number n0 -> consumeNumber(n0);\n" + + " };\n" + + " }\n" + + " int consumeNumber(@NonNull Number n) {\n" + + " return Integer.valueOf(n.toString());\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(null);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = ""; + runner.expectedOutputString = ""; + runner.runConformTest(); + } + + public void test_totalTypePatternPlusNullPattern() { + Runner runner = getDefaultRunner(); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(Number n) {\n" + + " switch (n) {\n" + + " case null -> System.out.print(\"null\");\n" + // this prevents the NPE + " case Integer i -> System.out.print(i);\n" + + " case Number n0 -> consumeNumber(n0);\n" + + " }\n" + + " }\n" + + " void consumeNumber(@NonNull Number n) {\n" + + " System.out.print(n.toString());\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(null);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = ""; + runner.expectedOutputString = "null"; + runner.runConformTest(); + } + + public void test_totalTypePatternNullableExpression() { + Runner runner = getDefaultRunner(); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@Nullable Number n) {\n" + // @Nullable here turns "unchecked" into "null type mismatch" + " switch (n) {\n" + + " case Integer i -> System.out.print(i);\n" + + " case Number n0 -> consumeNumber(n0);\n" + + " }\n" + + " }\n" + + " void consumeNumber(@NonNull Number n) {\n" + + " System.out.print(n.toString());\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(null);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case Number n0 -> consumeNumber(n0);\n" + + " ^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is inferred as @Nullable\n" + + "----------\n"; + runner.runNegativeTest(); + } + + public void test_switchOverNNValueWithNullCase() { + Runner runner = getDefaultRunner(); + runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@NonNull Object o) {\n" + + " switch (o) {\n" + + " case Integer i -> consumeInt(i);\n" + + " case null -> System.out.print(\"null\");\n" + + " default -> System.out.println(\"default\");\n" + + " }\n" + + " }\n" + + " void consumeInt(@NonNull Integer i) {\n" + + " System.out.print(i);\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(3);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " case null -> System.out.print(\"null\");\n" + + " ^^^^^^^^^\n" + + "Unnecessary \'null\' pattern, the switch selector expression cannot be null\n" + + "----------\n"; + runner.expectedOutputString = "3"; + runner.runConformTest(); + } + + public void test_switchNullInSameCase() { + Runner runner = getDefaultRunner(); + runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(Object o) {\n" + + " switch (o) {\n" + + " case null, Integer i -> consumeInt(i);\n" + + " default -> System.out.println(\"default\");\n" + + " }\n" + + " }\n" + + " void consumeInt(@NonNull Integer i) {\n" + + " System.out.print(i);\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(3);\n" + + " }\n" + + "}\n" + }; + // demonstrate that null case cannot leak into a type pattern: + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case null, Integer i -> consumeInt(i);\n" + + " ^^^^^^^^^\n" + + "Illegal fall-through to a pattern\n" + + "----------\n"; + runner.runNegativeTest(); + } + + public void test_switchOverNNValueWithNullCase_swExpr() { + Runner runner = getDefaultRunner(); + runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " int foo(@NonNull Object o) {\n" + + " return switch (o) {\n" + + " case Integer i -> consumeInt(i);\n" + + " case null -> 0;\n" + + " default -> -1;\n" + + " };\n" + + " }\n" + + " int consumeInt(@NonNull Integer i) {\n" + + " return i;\n" + + " }\n" + + " public static void main(String... args) {\n" + + " System.out.print(new X().foo(3));\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " case null -> 0;\n" + + " ^^^^^^^^^\n" + + "Unnecessary \'null\' pattern, the switch selector expression cannot be null\n" + + "----------\n"; + runner.expectedOutputString = "3"; + runner.runConformTest(); + } + + public void test_nullHostileSwitch() { + Runner runner = getDefaultRunner(); + runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@Nullable Object o) {\n" + + " switch (o) {\n" + + " case Integer i -> consumeInt(i);\n" + + " default -> System.out.println(o);\n" + + " };\n" + + " }\n" + + " void consumeInt(@NonNull Integer i) {\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(null);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " switch (o) {\n" + + " ^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n"; + runner.runNegativeTest(); + } + + public void test_defaultDoesNotApplyToNull() { + Runner runner = getDefaultRunner(); + runner.customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void foo(@Nullable Object o) {\n" + + " switch (o) {\n" + + " case Integer i -> consumeInt(i);\n" + + " default -> System.out.println(o.toString());\n" + + " case null -> System.out.print(\"null\");\n" + + " };\n" + + " }\n" + + " void consumeInt(@NonNull Integer i) {\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo(null);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = ""; + runner.expectedOutputString = "null"; + runner.runConformTest(); + } + + public void test_defaultDoesNotApplyToNull_field() { + Runner runner = getDefaultRunner(); + runner.customOptions.put(CompilerOptions.OPTION_SyntacticNullAnalysisForFields, CompilerOptions.ENABLED); + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable Object o;\n" + + " void foo() {\n" + + " switch (this.o) {\n" + + " case Integer i -> consumeInt(i);\n" + + " default -> System.out.println(this.o.toString());\n" + + " case null -> System.out.print(\"null\");\n" + + " };\n" + + " }\n" + + " void consumeInt(@NonNull Integer i) {\n" + + " }\n" + + " public static void main(String... args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = ""; + runner.expectedOutputString = "null"; + runner.runConformTest(); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests9.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests9.java new file mode 100644 index 0000000000..34b05786bf --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTests9.java @@ -0,0 +1,434 @@ +/******************************************************************************* + * Copyright (c) 2017, 2018 GK Software AG, and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.batch.BasicModule; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; + +import junit.framework.Test; + +import static org.eclipse.jdt.core.tests.util.Util.createJar; + +public class NullAnnotationTests9 extends AbstractNullAnnotationTest { + + public NullAnnotationTests9(String name) { + super(name); + } + + static { +// TESTS_NAMES = new String[] { "testBug456497" }; +// TESTS_NUMBERS = new int[] { 001 }; +// TESTS_RANGE = new int[] { 1, 12 }; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); + } + + public static Class testClass() { + return NullAnnotationTests9.class; + } + + @Deprecated // super method is deprecated + @Override + protected void setUpAnnotationLib() throws IOException { + if (this.LIBS == null) { + String[] defaultLibs = getDefaultClassPaths(); + int len = defaultLibs.length; + this.LIBS = new String[len+1]; + System.arraycopy(defaultLibs, 0, this.LIBS, 0, len); + this.LIBS[len] = createAnnotation_2_2_jar(Util.getOutputDirectory() + File.separator, null); + } + } + + public static String createAnnotation_2_2_jar(String dirName, String jcl9Path) throws IOException { + // role our own annotation library as long as o.e.j.annotation is still at BREE 1.8: + String jarFileName = dirName + "org.eclipse.jdt.annotation_2.2.0.jar"; + createJar(new String[] { + "module-info.java", + "module org.eclipse.jdt.annotation {\n" + + " exports org.eclipse.jdt.annotation;\n" + + "}\n", + + "org/eclipse/jdt/annotation/DefaultLocation.java", + "package org.eclipse.jdt.annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " \n" + + " PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS\n" + + "}\n", + + "org/eclipse/jdt/annotation/NonNullByDefault.java", + "package org.eclipse.jdt.annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" + + "\n" + + "import java.lang.annotation.*;\n" + + " \n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ ElementType.MODULE, ElementType.PACKAGE, ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.LOCAL_VARIABLE })\n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" + + "}", + + "org/eclipse/jdt/annotation/NonNull.java", + "package org.eclipse.jdt.annotation;\n" + + "import static java.lang.annotation.ElementType.TYPE_USE;\n" + + "\n" + + "import java.lang.annotation.*;\n" + + " \n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ TYPE_USE })\n" + + "public @interface NonNull {\n" + + " // marker annotation with no members\n" + + "}\n", + + "org/eclipse/jdt/annotation/Nullable.java", + "package org.eclipse.jdt.annotation;\n" + + "\n" + + "import static java.lang.annotation.ElementType.TYPE_USE;\n" + + "\n" + + "import java.lang.annotation.*;\n" + + " \n" + + "@Documented\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ TYPE_USE })\n" + + "public @interface Nullable {\n" + + " // marker annotation with no members\n" + + "}\n" + }, + null, + jarFileName, + jcl9Path != null ? new String[] { jcl9Path } : null, + "9"); + return jarFileName; + } + + // -------- internal infrastructure ------------ + + Map moduleMap = new HashMap<>(); // by name + Map file2module = new HashMap<>(); + + @Override + protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths, Map options) { + this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths; + INameEnvironment[] classLibs = getClassLibs(classPaths == null, options); + for (INameEnvironment nameEnvironment : classLibs) { + ((FileSystem) nameEnvironment).scanForModules(createParser()); + } + return new InMemoryNameEnvironment9(testFiles, this.moduleMap, classLibs); + } + + // --- same as AbstractRegressionTest9, just in a different inheritance hierarchy: + + @Override + protected CompilationUnit[] getCompilationUnits(String[] testFiles) { + Map moduleFiles= new HashMap<>(); // filename -> modulename + + // scan for all module-info.java: + for (int i = 0; i < testFiles.length; i+=2) { + IModule module = extractModuleDesc(testFiles[i], testFiles[i+1]); + if (module != null) { + this.moduleMap.put(String.valueOf(module.name()), module); + moduleFiles.put(testFiles[0], module.name()); + } + } + // record module information in CUs: + CompilationUnit[] compilationUnits = Util.compilationUnits(testFiles); + for (int i = 0; i < compilationUnits.length; i++) { + char[] fileName = compilationUnits[i].getFileName(); + String fileNameString = String.valueOf(compilationUnits[i].getFileName()); + if (CharOperation.endsWith(fileName, TypeConstants.MODULE_INFO_FILE_NAME)) { + compilationUnits[i].module = moduleFiles.get(fileNameString.replace(File.separator, "/")); + } else { + String modName = this.file2module.get(fileNameString.replace(File.separator, "/")); + if (modName != null) { + compilationUnits[i].module = modName.toCharArray(); + } + } + } + return compilationUnits; + } + + IModule extractModuleDesc(String fileName, String fileContent) { + if (fileName.toLowerCase().endsWith(IModule.MODULE_INFO_JAVA)) { + Parser parser = createParser(); + + ICompilationUnit cu = new CompilationUnit(fileContent.toCharArray(), fileName, null); + CompilationResult compilationResult = new CompilationResult(cu, 0, 1, 10); + CompilationUnitDeclaration unit = parser.parse(cu, compilationResult); + if (unit.isModuleInfo() && unit.moduleDeclaration != null) { + return new BasicModule(unit.moduleDeclaration, null); + } + } + return null; + } + + Parser createParser() { + Map opts = new HashMap(); + opts.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); + return new Parser( + new ProblemReporter(getErrorHandlingPolicy(), new CompilerOptions(opts), getProblemFactory()), + false); + } + + // ------------------------------------------------------ + + /** Use in tests to associate the CU in file 'fileName' to the module of the given name. */ + void associateToModule(String moduleName, String... fileNames) { + for (String fileName : fileNames) + this.file2module.put(fileName, moduleName); + } + + private Runner getDefaultRunner() { + Runner runner = new Runner(); + runner.classLibraries = this.LIBS; + runner.libsOnModulePath = true; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + return runner; + } + + public void test_nnbd_in_module_01() { + associateToModule("my.mod", "my.mod/p/X.java"); + Runner runner = getDefaultRunner(); + runner.testFiles = new String[] { + "my.mod/module-info.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "module my.mod {\n" + + " requires static org.eclipse.jdt.annotation;\n" + + "}\n", + "my.mod/p/X.java", + "package p;\n" + + "public class X {\n" + + " String f; // missing nn init\n" + + " void foo(String s) {\n" + + " this.f = s; // OK\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in my.mod\\p\\X.java (at line 3)\n" + + " String f; // missing nn init\n" + + " ^\n" + + "The @NonNull field f may not have been initialized\n" + + "----------\n"; + runner.runNegativeTest(); + } + + public void test_nnbd_in_module_02() throws IOException { + + String jarPath = OUTPUT_DIR+"/mod.one.jar"; + createJar( + new String[] { + "module-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "module mod.one {\n" + + " requires org.eclipse.jdt.annotation;\n" + + " exports p.q;\n" + + "}\n", + "p/q/API.java", + "package p.q;\n" + + "public class API {\n" + + " public String id(String in) { return in; }\n" + + "}\n" + }, + null, // extra path & content + jarPath, + this.LIBS, + "9"); + + associateToModule("my.mod", "my.mod/p/X.java"); + Runner runner = new Runner(); + runner.shouldFlushOutputDirectory = false; + runner.classLibraries = Arrays.copyOf(this.LIBS, this.LIBS.length+1); + runner.classLibraries[runner.classLibraries.length-1] = jarPath; + runner.libsOnModulePath = true; + runner.testFiles = new String[] { + "my.mod/module-info.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "module my.mod {\n" + + " requires static org.eclipse.jdt.annotation;\n" + + " requires mod.one;\n" + + "}\n", + "my.mod/p/X.java", + "package p;\n" + + "import p.q.API;\n" + + "public class X {\n" + + " void foo(API api) {\n" + + " api.id(api.id(\"\")); // OK\n" + + " api.id(null); // NOK\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in my.mod\\p\\X.java (at line 6)\n" + + " api.id(null); // NOK\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); + } + + public void test_redundant_nnbd_vs_module() { + associateToModule("my.mod", "my.mod/p/X.java", "my.mod/p2/package-info.java"); + Runner runner = getDefaultRunner(); + runner.testFiles = new String[] { + "my.mod/module-info.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "module my.mod {\n" + + " requires static org.eclipse.jdt.annotation;\n" + + "}\n", + "my.mod/p/X.java", + "package p;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class X {\n" + + " String f; // missing nn init\n" + + " void foo(String s) {\n" + + " this.f = s; // OK\n" + + " }\n" + + "}\n", + "my.mod/p/Y.java", + "package p;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault(PARAMETER)\n" + // not: FIELD, due to details not redundant + "public class Y {\n" + + " String f; // missing init is NOT a problem\n" + + " void foo(String s) {\n" + + " this.f = s; // OK\n" + + " }\n" + + "}\n", + "my.mod/p2/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p2;\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in my.mod\\p\\X.java (at line 2)\n" + + " @org.eclipse.jdt.annotation.NonNullByDefault\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing module my.mod\n" + + "----------\n" + + "2. ERROR in my.mod\\p\\X.java (at line 4)\n" + + " String f; // missing nn init\n" + + " ^\n" + + "The @NonNull field f may not have been initialized\n" + + "----------\n" + + "----------\n" + + "1. WARNING in my.mod\\p2\\package-info.java (at line 1)\n" + + " @org.eclipse.jdt.annotation.NonNullByDefault\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing module my.mod\n" + + "----------\n"; + runner.runNegativeTest(); + } + public void testBug536037a() { + if (this.complianceLevel < ClassFileConstants.JDK10) return; + runConformTestWithLibs( + new String[] { + "Bar.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class Bar {\n" + + " static void bar(Iterable list) {\n" + + " for(var s : list);\n" + + " }\n" + + "}\n" + }, + null, + ""); + this.verifier.shutDown(); + } + public void testBug536037b() { + // tests combination of declaration null-annotations & 'var': + if (this.complianceLevel < ClassFileConstants.JDK10) return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "test.NonNull"); + options.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "test.Nullable"); + runNegativeTestWithLibs( + new String[] { + "test/NonNull.java", + "package test;\n" + + "import java.lang.annotation.*;\n" + + "@Target({ElementType.LOCAL_VARIABLE,ElementType.PARAMETER}) public @interface NonNull {}\n", + "test/Nullable.java", + "package test;\n" + + "import java.lang.annotation.*;\n" + + "@Target({ElementType.LOCAL_VARIABLE,ElementType.PARAMETER}) public @interface Nullable {}\n", + "Bar.java", + "import test.*;\n" + + "public class Bar {\n" + + " static void bar1(@Nullable String s1, Iterable list) {\n" + + " @NonNull var s2 = s1;\n" + + " for (@NonNull var s : list);\n" + + " }\n" + + " static void bar2(int[] array) {\n" + + " @NonNull var i1 = 3;\n" + + " for (@NonNull var s : array);\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in Bar.java (at line 4)\n" + + " @NonNull var s2 = s1;\n" + + " ^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is specified as @Nullable\n" + + "----------\n" + + "2. WARNING in Bar.java (at line 5)\n" + + " for (@NonNull var s : list);\n" + + " ^^^^\n" + + "Null type safety: The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n" + + "3. ERROR in Bar.java (at line 8)\n" + + " @NonNull var i1 = 3;\n" + + " ^^^^^^^^\n" + + "The nullness annotation @NonNull is not applicable for the primitive type int\n" + + "----------\n" + + "4. ERROR in Bar.java (at line 9)\n" + + " for (@NonNull var s : array);\n" + + " ^^^^^^^^\n" + + "The nullness annotation @NonNull is not applicable for the primitive type int\n" + + "----------\n"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullChecksTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullChecksTests.java new file mode 100644 index 0000000000..6d8dfdaa1a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullChecksTests.java @@ -0,0 +1,447 @@ +/******************************************************************************* + * Copyright (c) 2016, 2020 Stephan Herrmann and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class NullChecksTests extends AbstractNullAnnotationTest { + + public NullChecksTests(String name) { + super(name); + } + + // Static initializer to specify tests subset using TESTS_* static variables + // All specified tests which do not belong to the class are skipped... + static { +// TESTS_NAMES = new String[] { "testAssertNonNull1" }; +// TESTS_NUMBERS = new int[] { 561 }; +// TESTS_RANGE = new int[] { 1, 2049 }; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + + public static Class testClass() { + return NullChecksTests.class; + } + + public void testAssertNonNull1() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import static org.eclipse.jdt.annotation.Checks.*;\n" + + "public class X {\n" + + " @SuppressWarnings(\"null\")\n" + + " static @NonNull String hide(String some) {\n" + + " return some;\n" + + " }\n" + + " public static void main(String... args) {\n" + + " @NonNull String myHiddenNull = hide(null);\n" + + " try {\n" + + " assertNonNull(\"foo\", myHiddenNull);\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(npe.getMessage());\n" + + " }\n" + + " try {\n" + + " assertNonNullWithMessage(\"Shouldn't!\", \"foo\", myHiddenNull);\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(npe.getMessage());\n" + + " }\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "Value in position 1 must not be null\n" + + "Shouldn\'t!"); + } + + public void testAssertNonNullElements() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import static org.eclipse.jdt.annotation.Checks.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " @SuppressWarnings(\"null\")\n" + + " static @NonNull String hide(String some) {\n" + + " return some;\n" + + " }\n" + + " public static void main(String... args) {\n" + + " @NonNull List myList = new ArrayList<>();\n" + + " myList.add(\"foo\");\n" + + " myList.add(null);\n" + + " try {\n" + + " assertNonNullElements(myList);\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(npe.getMessage());\n" + + " }\n" + + " @NonNull List<@NonNull String> myList2 = new ArrayList<>();\n" + + " myList2.add(\"foo\");\n" + + " myList2.add(hide(null));\n" + + " try {\n" + + " assertNonNullElements(myList2, \"Shouldn't!\");\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(npe.getMessage());\n" + + " }\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "Value in position 1 must not be null\n" + + "Shouldn\'t!"); + } + + public void testRequireNonNull() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import static org.eclipse.jdt.annotation.Checks.*;\n" + + "public class X {\n" + + " @SuppressWarnings(\"null\")\n" + + " static @NonNull String hide(String some) {\n" + + " return some;\n" + + " }\n" + + " static void test(@Nullable String str, @Nullable X x) {\n" + + " @NonNull String nnStr;\n" + + " @NonNull X nnX;\n" + + " try {\n" + + " nnStr = requireNonNull(str);\n" + + " nnX = requireNonNull(null, \"Shouldn\'t!\");\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(npe.getMessage());\n" + + " }\n" + + " }\n" + + " public static void main(String... args) {\n" + + " test(\"foo\", null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "Shouldn\'t!"); + } + + public void testRequireNonEmptyString() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import static org.eclipse.jdt.annotation.Checks.*;\n" + + "public class X {\n" + + " @SuppressWarnings(\"null\")\n" + + " static @NonNull String hide(String some) {\n" + + " return some;\n" + + " }\n" + + " static void test(@Nullable String str1, @Nullable String str2) {\n" + + " @NonNull String nnStr;\n" + + " try {\n" + + " nnStr = requireNonEmpty(str1);\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(\"npe:\"+npe.getMessage());\n" + + " }\n" + + " try {\n" + + " nnStr = requireNonEmpty(str2, \"Shouldn't!\");\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(\"npe\"+npe.getMessage());\n" + + " } catch (IllegalArgumentException iae) {\n" + + " System.out.println(iae.getMessage());\n" + + " }\n" + + " }\n" + + " public static void main(String... args) {\n" + + " test(null, \"\");\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "npe:null\n" + + "Shouldn\'t!"); + } + + public void testRequireNonEmptyCollection() { + runConformTestWithLibs( + new String[] { + "X.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "import static org.eclipse.jdt.annotation.Checks.*;\n" + + "public class X {\n" + + " static void test(@Nullable Collection strs, @Nullable Collection strs1, Collection strs2) {\n" + + " @NonNull Collection nnStrs;\n" + + " try {\n" + + " nnStrs = requireNonEmpty(strs);\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(\"NPE:\"+npe.getMessage());\n" + + " }\n" + + " try {\n" + + " nnStrs = requireNonEmpty(strs1);\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(\"npe:\"+npe.getMessage());\n" + + " }\n" + + " try {\n" + + " nnStrs = requireNonEmpty(strs2, \"Shouldn't!\");\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(\"npe\"+npe.getMessage());\n" + + " } catch (IllegalArgumentException iae) {\n" + + " System.out.println(iae.getMessage());\n" + + " }\n" + + " }\n" + + " public static void main(String... args) {\n" + + " test(Collections.singletonList(\"good\"), null, Collections.emptyList());\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "npe:null\n" + + "Shouldn\'t!"); + } + + public void testIsNull() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import static org.eclipse.jdt.annotation.Checks.*;\n" + + "public class X {\n" + + " @SuppressWarnings(\"null\")\n" + + " static @NonNull T hide(T some) {\n" + + " return some;\n" + + " }\n" + + " static void test(@NonNull X x1, @NonNull X x2, @NonNull X x3) {\n" + + " if (isNull(x1))\n" + + " System.out.println(\"IS NULL\");\n" + + " if (isAnyNull(x2, x1))\n" + + " System.out.println(\"IS ANY NULL 1\");\n" + + " if (isAnyNull(x2, x3))\n" + + " System.out.println(\"IS ANY NULL 2\");\n" + + " }\n" + + " public static void main(String... args) {\n" + + " test(hide(null), new X(), new X());\n" + + " }\n" + + "}\n" + }, + compilerOptions, + "", + "IS NULL\n" + + "IS ANY NULL 1"); + } + + public void testAsNullable() { + runConformTestWithLibs( + new String[] { + "X.java", + "import java.util.*;\n" + + "import static org.eclipse.jdt.annotation.Checks.*;\n" + + "public class X {\n" + + " static void test(Optional xopt) {\n" + + " if (xopt != null) {\n" + + " X x = asNullable(xopt);\n" + + " if (x == null)\n" + + " System.out.println(\"NULL\");\n" + + " }\n" + + " }\n" + + " public static void main(String... args) {\n" + + " test(Optional.ofNullable(null));\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "NULL"); + } + + public void testNonNullElse() { + runConformTestWithLibs( + new String[] { + "X.java", + "import java.util.function.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "import static org.eclipse.jdt.annotation.Checks.*;\n" + + "public class X {\n" + + " static void test(String str, String noStr, @NonNull Supplier<@NonNull String> prov) {\n" + + " System.out.println(nonNullElse(str, \"ELSE1\"));\n" + + " System.out.println(nonNullElse(noStr, \"ELSE2\"));\n" + + " System.out.println(nonNullElseGet(str, () -> \"ELSE3\"));\n" + + " System.out.println(nonNullElseGet(noStr, prov));\n" + + " }\n" + + " public static void main(String... args) {\n" + + " test(\"good\", null, () -> \"ELSE4\");\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "good\n" + + "ELSE2\n" + + "good\n" + + "ELSE4"); + } + + public void _testIfNonNull() { // FIXME: see https://bugs.eclipse.org/489609 - [1.8][null] null annotation on wildcard is dropped during inference + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import static org.eclipse.jdt.annotation.Checks.*;\n" + + "public class X {\n" + + " static void test(@Nullable String str) {\n" + + " ifNonNull(str, s -> print(s));\n" + + " }\n" + + " static void print(@NonNull String s) {\n" + + " System.out.print(s);\n" + + " }\n" + + " public static void main(String... args) {\n" + + " test(\"good\");\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "good"); + } + + public void testBooleanNullAssertions() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.Objects;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " public void demonstrateNotWorkingNullCheck() {\n" + + " Object mayBeNull = null;\n" + + " if (Math.random() > 0.5) {\n" + + " mayBeNull = new Object();\n" + + " }\n" + + " if (Object.class.isInstance(mayBeNull)) {\n" + + " mayBeNull.toString();\n" + + " }\n" + + " }\n" + + " public void negatedNullCheck() {\n" + + " Object mayBeNull = null;\n" + + " if (Math.random() > 0.5) {\n" + + " mayBeNull = new Object();\n" + + " }\n" + + " if (!Objects.nonNull(mayBeNull)) {\n" + + " System.out.println(\"not\");\n" + + " } else {\n" + + " mayBeNull.toString();\n" + + " }\n" + + " if (!(Integer.class.isInstance(mayBeNull) || Long.class.isInstance(mayBeNull))) {\n" + + " mayBeNull.toString(); // still only a potential problem\n" + + " }\n" + + " }\n" + + " public void nullCheckAlgegra() {\n" + + " Object mayBeNull = null;\n" + + " if (Math.random() > 0.5) {\n" + + " mayBeNull = new Object();\n" + + " }\n" + + " if (Math.random() > 0.5 && Object.class.isInstance(mayBeNull)) {\n" + + " mayBeNull.toString();\n" + // both operands are true + " }\n" + + " if (!Object.class.isInstance(mayBeNull) || Math.random() > 0.5) {\n" + + " System.out.println(\"not\");\n" + + " } else {\n" + + " mayBeNull.toString();\n" + // both operands are false + " }\n" + + " if (Object.class.isInstance(mayBeNull) && mayBeNull.equals(\"hi\"))\n" + // second evaluated only when first is true + " System.out.println(\"equal\");\n" + + " if (Objects.isNull(mayBeNull) || mayBeNull.equals(\"hi\"))\n" + // second evaluated only when first is false + " System.out.println(\"equal or null\");\n" + + " }\n" + + " public void objectsUtils() {\n" + + " Object mayBeNull = null;\n" + + " if (Math.random() > 0.5) {\n" + + " mayBeNull = new Object();\n" + + " }\n" + + " String s = Objects.nonNull(mayBeNull) ? mayBeNull.toString(): null;\n" + + " if (Objects.isNull(mayBeNull) || Math.random() > 0.5) {\n" + + " System.out.println(\"not\");\n" + + " } else {\n" + + " mayBeNull.toString();\n" + + " }\n" + + " }\n" + + " public void loops() {\n" + + " Object mayBeNull = null;\n" + + " if (Math.random() > 0.5) {\n" + + " mayBeNull = new Object();\n" + + " }\n" + + " for (; Objects.nonNull(mayBeNull); mayBeNull=next(mayBeNull)) {\n" + + " mayBeNull.toString();\n" + // guarded by the condition + " }\n" + + " mayBeNull.toString(); // can only be null after the loop\n" + + " Object initiallyNN = new Object();\n" + + " while (Objects.nonNull(initiallyNN)) {\n" + + " initiallyNN.toString();\n" + // guarded by the condition + " initiallyNN = next(initiallyNN);\n" + + " }\n" + + " initiallyNN.toString(); // can only be null after the loop\n" + + " }\n" + + " @Nullable Object next(Object o) { return o; }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " mayBeNull.toString(); // still only a potential problem\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: The variable mayBeNull may be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 65)\n" + + " mayBeNull.toString(); // can only be null after the loop\n" + + " ^^^^^^^^^\n" + + "Null pointer access: The variable mayBeNull can only be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 71)\n" + + " initiallyNN.toString(); // can only be null after the loop\n" + + " ^^^^^^^^^^^\n" + + "Null pointer access: The variable initiallyNN can only be null at this location\n" + + "----------\n"); + } + public void testBug465085_comment12() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); + runConformTest( + new String[] { + "Snippet.java", + "import java.util.Collection;\n" + + "\n" + + "public class Snippet {\n" + + " int instanceCount(Collection elements, Class clazz) {\n" + + " int count = 0;\n" + + " for (Object o : elements) { // warning here: \"The value of the local variable o is not used\"\n" + + " if (clazz.isInstance(o)) {\n" + + " count++;\n" + + " }\n" + + " }\n" + + " return count;\n" + + " }\n" + + "}\n" + }, + options); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTests.java new file mode 100644 index 0000000000..a4dbc3b0e0 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTests.java @@ -0,0 +1,1817 @@ +/******************************************************************************* + * Copyright (c) 2005, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 320170 + * bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" + * bug 386181 - [compiler][null] wrong transition in UnconditionalFlowInfo.mergedWith() + * bug 395002 - Self bound generic class doesn't resolve bounds properly for wildcards for certain parametrisation. + * Bug 453635 - [compiler][null] Update NullReferenceImplTests and friends + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.jdt.core.tests.compiler.regression.NullReferenceImplTests.State; +import org.eclipse.jdt.internal.compiler.flow.FlowInfo; +import org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo; +import org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo.AssertionFailedException; +import org.eclipse.jdt.internal.compiler.impl.Constant; +import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; +import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; +import org.eclipse.jdt.internal.compiler.lookup.Scope; +import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; + +/** + * A tests series especially meant to validate the internals of our null + * reference analysis. See NullReferenceTest for tests targetted at + * the source code compiler behavior level. + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class NullReferenceImplTests extends NullReferenceTest { + // Static initializer to specify tests subset using TESTS_* static variables + // All specified tests which does not belong to the class are skipped... + // 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[] { "test2050" }; +// TESTS_NUMBERS = new int[] { 2061 }; +// TESTS_NUMBERS = new int[] { 2999 }; +// TESTS_RANGE = new int[] { 2050, -1 }; + } + +/** + * A class to hold states as seen by the low level validation tests and machinery. + * State provides: + * - singletons for all possible states given the number of bits for the said + * states; + * - semantic names for known states; + * - printable representation of states as bit fields; + * - coordination with other classes to perform transitive closure analysis, etc. + */ + /* + This is a tabular definition for states. It can be completed/leveraged by + the Generator class so as to smoothen the transition between differing encodings + of the states. + // STATES DEFINITION START + 000000 start + 000001 + 000010 + 000011 + 000100 pot. unknown + 000101 + 000110 + 000111 + 001000 pot. non null + 001001 + 001010 + 001011 + 001100 pot. nn & pot. un + 001101 + 001110 + 001111 + 010000 pot. null + 010001 + 010010 + 010011 + 010100 pot. n & pot. un + 010101 + 010110 + 010111 + 011000 pot. n & pot. nn + 011001 + 011010 + 011011 + 011100 pot. n & pot. nn & pot. un + 011101 + 011110 + 011111 + 100000 + 100001 + 100010 + 100011 + 100100 def. unknown + 100101 + 100110 + 100111 + 101000 def. non null + 101001 + 101010 + 101011 + 101100 pot. nn & prot. nn + 101101 + 101110 + 101111 + 110000 def. null + 110001 + 110010 + 110011 + 110100 pot. n & prot. n + 110101 + 110110 + 110111 + 111000 prot. null + 111001 + 111010 + 111011 + 111100 prot. non null + 111101 + 111110 + 111111 + // STATES DEFINITION END + */ + public static class State implements Comparable { + // PREMATURE consider moving initialization to test setup/dispose + public final static State[] states = { + // STATES INITIALIZER START + new State(0, "start"), // 000000 + new State(1), // 000001 + new State(2), // 000010 + new State(3), // 000011 + new State(4, "pot. unknown"), // 000100 + new State(5), // 000101 + new State(6), // 000110 + new State(7), // 000111 + new State(8, "pot. non null"), // 001000 + new State(9), // 001001 + new State(10), // 001010 + new State(11), // 001011 + new State(12, "pot. nn & pot. un"), // 001100 + new State(13), // 001101 + new State(14), // 001110 + new State(15), // 001111 + new State(16, "pot. null"), // 010000 + new State(17), // 010001 + new State(18), // 010010 + new State(19), // 010011 + new State(20, "pot. n & pot. un"), // 010100 + new State(21), // 010101 + new State(22), // 010110 + new State(23), // 010111 + new State(24, "pot. n & pot. nn"), // 011000 + new State(25), // 011001 + new State(26), // 011010 + new State(27), // 011011 + new State(28, "pot. n & pot. nn & pot. un"), // 011100 + new State(29), // 011101 + new State(30), // 011110 + new State(31), // 011111 + new State(32), // 100000 + new State(33), // 100001 + new State(34), // 100010 + new State(35), // 100011 + new State(36, "def. unknown"), // 100100 + new State(37), // 100101 + new State(38), // 100110 + new State(39), // 100111 + new State(40, "def. non null"), // 101000 + new State(41), // 101001 + new State(42), // 101010 + new State(43), // 101011 + new State(44, "pot. nn & prot. nn"), // 101100 + new State(45), // 101101 + new State(46), // 101110 + new State(47), // 101111 + new State(48, "def. null"), // 110000 + new State(49), // 110001 + new State(50), // 110010 + new State(51), // 110011 + new State(52, "pot. n & prot. n"), // 110100 + new State(53), // 110101 + new State(54), // 110110 + new State(55), // 110111 + new State(56, "prot. null"), // 111000 + new State(57), // 111001 + new State(58), // 111010 + new State(59), // 111011 + new State(60, "prot. non null"), // 111100 + new State(61), // 111101 + new State(62), // 111110 + new State(63), // 111111 + // STATES INITIALIZER END + }; + public final static State start = states[0]; + public static final int + stateMaxValue = 0x3F, + stateWidth = 6, + statesNb = stateMaxValue + 1; + String name, printableBitsField, hexString; + public byte value; + boolean symbolic; + private State() { + } + private State(int numericValue) { + this(numericValue, null); + } + private State(int numericValue, String publicName) { + if (numericValue > stateMaxValue) { + throw new IllegalArgumentException("state value overflow"); + } + this.value = (byte) numericValue; + StringBuilder printableValue = new StringBuilder(6); + for (int i = stateWidth - 1; i >= 0; i--) { + printableValue.append((numericValue >>> i & 1) != 0 ? '1' : '0'); + } + this.printableBitsField = printableValue.toString(); + if (this.value > 0xF) { + this.hexString = "0x" + Integer.toHexString(this.value).toUpperCase(); + } + else { + this.hexString = "0x0" + Integer.toHexString(this.value).toUpperCase(); + } + if (publicName != null) { + this.name = publicName; + this.symbolic = true; + } + else { + this.name = this.printableBitsField; + } + } + private State(String commentLine) { + char current = ' '; // keep the initialization status quiet + int cursor, length; + for (cursor = 0, length = commentLine.length(); + cursor < length; + cursor++) { + if ((current = commentLine.charAt(cursor)) == '0' || + current == '1') { + break; + } + } + if (cursor == length) { + throw new RuntimeException("bad state definition format (missing bits field): " + commentLine); + // PREMATURE adopt consistent error policy + } + int valueDigits; + for (valueDigits = 1; cursor < (length - 1) && valueDigits < stateWidth; valueDigits++) { + this.value = (byte) ((this.value << 1) + (current - '0')); + if ((current = commentLine.charAt(++cursor)) != '0' && + current != '1') { + throw new RuntimeException("bad state definition format (inappropriate character in bits field): " + commentLine); + // PREMATURE adopt consistent error policy + } + } + if (valueDigits < stateWidth) { + throw new RuntimeException("bad state definition format (bits field is too short): " + commentLine); + // PREMATURE adopt consistent error policy + } + this.value = (byte) ((this.value << 1) + (current - '0')); + this.printableBitsField = commentLine.substring(cursor - stateWidth + 1, cursor + 1); + if (this.value > 0xF) { + this.hexString = "0x" + Integer.toHexString(this.value).toUpperCase(); + } + else { + this.hexString = "0x0" + Integer.toHexString(this.value).toUpperCase(); + } + while (++cursor < length && Character.isWhitespace(current = commentLine.charAt(++cursor)) && current != '\n') { + // loop + } + if (cursor < length && current != '\n') { + this.name = commentLine.substring(cursor, length); + } + if (this.name == null) { + this.name = this.printableBitsField; + } else { + this.symbolic = true; + } + } + private String asInitializer() { + StringBuilder result = new StringBuilder(70); + result.append(" new State("); + result.append(this.value); + char first; + boolean nameIsSymbolic = (first = this.name.charAt(0)) != '0' + && first != '1'; + if (nameIsSymbolic) { + result.append(", \""); + result.append(this.name); + result.append('"'); + } + result.append("), // "); + result.append(this.printableBitsField); + return result.toString(); + } + long [] asLongArray() { + long[] result = new long[stateWidth]; + for (int i = 0; i < stateWidth; i++) { + result[i] = ((this.value >> (stateWidth - i - 1)) & 1) == 0 ? 0 : 1; + } + return result; + } + private String asSourceComment() { + StringBuilder result = new StringBuilder(70); + result.append("\t\t"); + result.append(this.printableBitsField); + char first; + boolean nameIsSymbolic = (first = this.name.charAt(0)) != '0' + && first != '1'; + if (nameIsSymbolic) { + result.append('\t'); + result.append(this.name); + } + return result.toString(); + } + @Override + public int compareTo(Object o) { + return this.value - ((State) o).value; + } + static State fromLongValues(long bit1, long bit2, long bit3, long bit4, long bit5, long bit6) { + // PREMATURE consider taking an UnconditionalFlowInfo in parameter + return states[(int)( + (bit6 & 1) + + 2 * ((bit5 & 1) + + 2 * ((bit4 & 1) + + 2 * ((bit3 & 1) + + 2 * ((bit2 & 1) + + 2 * (bit1 & 1))))))]; + } + private static Map namesIndex; + static State fromSymbolicName (String name) { + if (namesIndex == null) { + namesIndex = new HashMap(states.length); + for (int i = 0; i < states.length; i++) { + if (states[i].name != null) { + namesIndex.put(states[i].name, states[i]); + } + } + } + return (State) namesIndex.get(name); + } + private static void grabDefinitionFromComment(BufferedReader input) { + String line; + State current; + // use when the initializer is incomplete, hence needs to be reinitialized + // states = new State[stateMaxValue + 1]; + // use when the states field is final, with the appropriate size: + for (int i = 0; i <= stateMaxValue; i++) { + states[i] = null; + } + try { + while ((line = input.readLine()) != null && line.indexOf(definitionEndMarker) == -1) { + current = new State(line); + if (states[current.value] != null) { + throw new RuntimeException("duplicate state for index: " + current.value); + } + else { + states[current.value] = current; + } + } + } catch (IOException e) { + throw new RuntimeException(e); + } + for (int i = 0; i < stateMaxValue; i++) { + if (states[i] == null) { + states[i] = new State(i); + } + } + } + // PREMATURE may decide to remove + //private static void printAsInitializer() { + // int i, length; + // System.out.println(initializerStartMarker); + // for (i = 0, length = states.length; i < length; i++) { + // System.out.println(states[i].asInitializer()); + // } + // for (/* continue */; i <= stateMaxValue; i++) { + // System.out.println((new State(i)).asInitializer() + " CHECK"); + // } + // System.out.println(initializerEndMarker); + //} + // PREMATURE may decide to remove + //private static void printAsSourceComment() { + // int i, length; + // System.out.println("/*"); + // System.out.println(definitionStartMarker); + // for (i = 0, length = states.length; i < length; i++) { + // System.out.println(states[i].asSourceComment()); + // } + // for (/* continue */; i <= stateMaxValue; i++) { + // System.out.println((new State(i)).asSourceComment()); + // } + // System.out.println(definitionEndMarker); + // System.out.println("*/"); + //} + private final static String + definitionStartMarker = "// STATES " + CodeAnalysis.definitionStartMarker, + definitionEndMarker = "// STATES " + CodeAnalysis.definitionEndMarker, + initializerStartMarker = "// STATES " + CodeAnalysis.initializerStartMarker, + initializerEndMarker = "// STATES " + CodeAnalysis.initializerEndMarker; + static void reinitializeFromComment(BufferedReader input, BufferedWriter output) { + String line, tab = ""; + int cursor; + char c; + try { + while ((line = input.readLine()) != null) { + output.write(line); + output.write('\n'); + if ((cursor = line.indexOf(definitionStartMarker)) != -1) { + // check the line format + boolean reachedStart = true; + for (int i = 0; i < cursor; i++) { + if (!Character.isWhitespace(c = line.charAt(i))) { + reachedStart = false; + break; + } + else { + tab += c; + } + } + if (reachedStart) { + grabDefinitionFromComment(input); // consumes up to the END line + int i, length; + for (i = 0, length = states.length; i < length; i++) { + output.write(states[i].asSourceComment()); + output.write('\n'); + } + output.write(tab + definitionEndMarker + "\n"); + } + } + if ((cursor = line.indexOf(initializerStartMarker)) != -1) { + // check the line format + boolean reachedStart = true; + tab = ""; + for (int i = 0; i < cursor; i++) { + if (!Character.isWhitespace(c = line.charAt(i))) { + reachedStart = false; + break; + } + else { + tab += c; + } + } + if (reachedStart) { + while ((line = input.readLine()) != null && + line.indexOf(initializerEndMarker) == -1) { + // loop + } + int i, length; + for (i = 0, length = states.length; i < length; i++) { + output.write(states[i].asInitializer()); + output.write('\n'); + } + output.write(tab + initializerEndMarker + "\n"); + } + } + } + output.flush(); + namesIndex = null; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + static Iterator symbolicStates() { + return new Iterator() { + int nextSymbolic = -1; + @Override + public boolean hasNext() { + if (this.nextSymbolic == -1) { + for (this.nextSymbolic = 0; this.nextSymbolic < states.length; this.nextSymbolic++) { + if (states[this.nextSymbolic].symbolic) { + break; + } + } + } else { + for (; this.nextSymbolic < states.length; this.nextSymbolic++) { + if (states[this.nextSymbolic].symbolic) { + break; + } + } + } + return this.nextSymbolic < states.length; + } + @Override + public Object next() { + State result = null; + if (this.nextSymbolic < states.length) { + result = states[this.nextSymbolic]; + this.nextSymbolic++; + } + return result; + } + @Override + public void remove() { + throw new RuntimeException("unimplemented"); + } + }; + } + @Override + public String toString() { + return this.name; + } + @Override + public boolean equals(Object other) { + return (other instanceof State) && ((State)other).value == this.value; + } + @Override + public int hashCode() { + return this.value; + } + } + +public NullReferenceImplTests(String name) { + super(name); +} + + // Tests tuning + // private static final boolean skipHighOrderBits = false; // define to true when tuning encoding + private static final int COMBINATION_TESTS_LOOP_NB = 1; // define to 10000s to measure performances + private static final boolean MEASURE_PERFORMANCES = COMBINATION_TESTS_LOOP_NB > 1; + +public static Test suite() { + // we do not want to run for 1.3, 1.4, 1.5 but once only + Class clazz = testClass(); + TestSuite all = new TestSuite(clazz.getName()); + List tests = buildTestsList(testClass()); + for (int i = 0, length = tests.size(); i < length; i++) { + all.addTest((Test) tests.get(i)); + } + return all; +} + +public static Class testClass() { + return NullReferenceImplTests.class; +} + +public void test2050_markAsComparedEqualToNonNull() { + int failures = NullReferenceImplTransformations.markAsComparedEqualToNonNull.test(); + assertTrue("nb of failures: " + failures, failures == 0); +} + +public void test2051_markAsComparedEqualToNull() { + int failures = NullReferenceImplTransformations.markAsComparedEqualToNull.test(); + assertTrue("nb of failures: " + failures, failures == 0); +} + +public void test2055_markAsDefinitelyNonNull() { + int failures = NullReferenceImplTransformations.markAsDefinitelyNonNull.test(); + assertTrue("nb of failures: " + failures, failures == 0); +} + +public void test2056_markAsDefinitelyNull() { + int failures = NullReferenceImplTransformations.markAsDefinitelyNull.test(); + assertTrue("nb of failures: " + failures, failures == 0); +} + +public void test2057_markAsDefinitelyUnknown() { + int failures = NullReferenceImplTransformations.markAsDefinitelyUnknown.test(); + assertTrue("nb of failures: " + failures, failures == 0); +} + +public void test2060_addInitializationsFrom() { + int failures = NullReferenceImplTransformations.addInitializationsFrom.test(); + assertTrue("nb of failures: " + failures, failures == 0); +} + +public void test2061_addPotentialInitializationsFrom() { + int failures = NullReferenceImplTransformations.addPotentialInitializationsFrom.test(); + assertTrue("nb of failures: " + failures, failures == 0); +} + +public void test2062_mergedWith() { + int failures = NullReferenceImplTransformations.mergedWith.test(); + assertTrue("nb of failures: " + failures, failures == 0); +} + +// PREMATURE rewrite from scratch +//public void _test2058_recode() { +// long [][][] testData = transitionsTablesData[recode]; +// int failures = 0; +// long start; +// if (combinationTestsloopsNb > 1) { +// start = System.currentTimeMillis(); +// } +// String header = "recode failures: "; +// for (int l = 0; l < combinationTestsloopsNb ; l++) { +// for (int i = 0; i < testData.length; i++) { +// UnconditionalFlowInfoTestHarness result; +// result = UnconditionalFlowInfoTestHarness. +// testUnconditionalFlowInfo(testData[i][0]); +// result.encode(); +// result.decode(); +// +// if (!result.testEquals(UnconditionalFlowInfoTestHarness. +// testUnconditionalFlowInfo(testData[i][0]))) { +// if (failures == 0) { +// System.out.println(header); +// } +// failures++; +// System.out.println("\t\t{" + result.testString() + +// "}, // instead of: " + testStringValueOf(testData[i][0])); +// } +// } +// } +// if (combinationTestsloopsNb > 1) { +// System.out.println("mergedWith\t\t\t" + combinationTestsloopsNb + "\t" + +// (System.currentTimeMillis() - start)); +// } +// for (int i = 0; i < testData.length; i++) { +// UnconditionalFlowInfoTestHarness result; +// result = UnconditionalFlowInfoTestHarness. +// testUnconditionalFlowInfo(testData[i][0], 64); +// result.encode(); +// result.decode(); +// +// if (!result.testEquals(UnconditionalFlowInfoTestHarness. +// testUnconditionalFlowInfo(testData[i][0], 64))) { +// if (failures == 0) { +// System.out.println(header); +// } +// failures++; +// System.out.println("\t\t{" + result.testString() + +// "}, // (64) - instead of: " + testStringValueOf(testData[i][0])); +// } +// } +// assertTrue("nb of failures: " + failures, failures == 0); +//} + +public void test2400_state_consistency() { + int failures = 0; + long start; + if (MEASURE_PERFORMANCES) { + start = System.currentTimeMillis(); + } + String header = "state consistency failures: "; + for (int l = 0; l < COMBINATION_TESTS_LOOP_NB ; l++) { + for (int i = 0; i < State.states.length; i++) { + if (State.states[i].symbolic) { + UnconditionalFlowInfoTestHarness + state = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(State.states[i]); + boolean + isDefinitelyNonNull = state.isDefinitelyNonNull(TestLocalVariableBinding.local0), + isDefinitelyNull = state.isDefinitelyNull(TestLocalVariableBinding.local0), + isDefinitelyUnknown = state.isDefinitelyUnknown(TestLocalVariableBinding.local0), + isPotentiallyNonNull = state.isPotentiallyNonNull(TestLocalVariableBinding.local0), + isPotentiallyNull = state.isPotentiallyNull(TestLocalVariableBinding.local0), + isPotentiallyUnknown = state.isPotentiallyUnknown(TestLocalVariableBinding.local0), + isProtectedNonNull = state.isProtectedNonNull(TestLocalVariableBinding.local0), + isProtectedNull = state.isProtectedNull(TestLocalVariableBinding.local0), + cannotBeDefinitelyNullOrNonNull = state.cannotBeDefinitelyNullOrNonNull(TestLocalVariableBinding.local0), + cannotBeNull = state.cannotBeNull(TestLocalVariableBinding.local0), + canOnlyBeNull = state.canOnlyBeNull(TestLocalVariableBinding.local0); + if (isDefinitelyNonNull + && (isDefinitelyNull || isDefinitelyUnknown + || isPotentiallyNull + || isProtectedNull)) { + if (failures == 0) { + System.out.println(header); + } + failures++; + System.out.println("\t\tconsistency breakage for definitely non null state " + State.states[i].name); + } + if (isDefinitelyNull + && (isDefinitelyNonNull || isDefinitelyUnknown + || isPotentiallyUnknown || isProtectedNonNull)) { + if (failures == 0) { + System.out.println(header); + } + failures++; + System.out.println("\t\tconsistency breakage for definitely null state " + State.states[i].name); + } + if (isDefinitelyUnknown + && (isDefinitelyNonNull || isDefinitelyNull + || isPotentiallyNull || isProtectedNonNull + || isProtectedNull)) { + if (failures == 0) { + System.out.println(header); + } + failures++; + System.out.println("\t\tconsistency breakage for definitely unknown state " + State.states[i].name); + } + if (isProtectedNonNull && !isDefinitelyNonNull + || isProtectedNull && !isDefinitelyNull + || i > 0 // not start + && !State.states[i].name.equals("pot. non null") + && !(isDefinitelyNonNull || isDefinitelyNull + || isDefinitelyUnknown || isPotentiallyNull + || isPotentiallyUnknown || isProtectedNonNull + || isProtectedNull) + || cannotBeDefinitelyNullOrNonNull != + (isPotentiallyUnknown || + isPotentiallyNull && isPotentiallyNonNull) + || cannotBeNull != (isProtectedNonNull || + isDefinitelyNonNull) + || canOnlyBeNull != (isProtectedNull || + isDefinitelyNull)) { + if (failures == 0) { + System.out.println(header); + } + failures++; + System.out.println("\t\tconsistency breakage for " + State.states[i].name); + } + } + } + } + if (MEASURE_PERFORMANCES) { + System.out.println("mergedWith\t\t\t" + COMBINATION_TESTS_LOOP_NB + "\t" + + (System.currentTimeMillis() - start)); + } + for (int i = 0; i < State.states.length; i++) { + if (State.states[i].symbolic) { + UnconditionalFlowInfoTestHarness state; + state = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(State.states[i], 64); + boolean + isDefinitelyNonNull = state.isDefinitelyNonNull(TestLocalVariableBinding.local64), + isDefinitelyNull = state.isDefinitelyNull(TestLocalVariableBinding.local64), + isDefinitelyUnknown = state.isDefinitelyUnknown(TestLocalVariableBinding.local64), + isPotentiallyNonNull = state.isPotentiallyNonNull(TestLocalVariableBinding.local64), + isPotentiallyNull = state.isPotentiallyNull(TestLocalVariableBinding.local64), + isPotentiallyUnknown = state.isPotentiallyUnknown(TestLocalVariableBinding.local64), + isProtectedNonNull = state.isProtectedNonNull(TestLocalVariableBinding.local64), + isProtectedNull = state.isProtectedNull(TestLocalVariableBinding.local64), + cannotBeDefinitelyNullOrNonNull = state.cannotBeDefinitelyNullOrNonNull(TestLocalVariableBinding.local64), + cannotBeNull = state.cannotBeNull(TestLocalVariableBinding.local64), + canOnlyBeNull = state.canOnlyBeNull(TestLocalVariableBinding.local64); + if (isDefinitelyNonNull + && (isDefinitelyNull || isDefinitelyUnknown + || isPotentiallyNull + || isProtectedNull)) { + if (failures == 0) { + System.out.println(header); + } + failures++; + System.out.println("\t\tconsistency breakage (64) for definitely non null state " + State.states[i].name); + } + if (isDefinitelyNull + && (isDefinitelyNonNull || isDefinitelyUnknown + || isPotentiallyUnknown || isProtectedNonNull)) { + if (failures == 0) { + System.out.println(header); + } + failures++; + System.out.println("\t\tconsistency breakage (64) for definitely null state " + State.states[i].name); + } + if (isDefinitelyUnknown + && (isDefinitelyNonNull || isDefinitelyNull + || isPotentiallyNull || isProtectedNonNull + || isProtectedNull)) { + if (failures == 0) { + System.out.println(header); + } + failures++; + System.out.println("\t\tconsistency breakage (64) for definitely unknown state " + State.states[i].name); + } + if (isProtectedNonNull && !isDefinitelyNonNull + || isProtectedNull && !isDefinitelyNull + || i > 0 // not start + && !State.states[i].name.equals("pot. non null") + && !(isDefinitelyNonNull || isDefinitelyNull + || isDefinitelyUnknown || isPotentiallyNull + || isPotentiallyUnknown || isProtectedNonNull + || isProtectedNull) + || cannotBeDefinitelyNullOrNonNull != + (isPotentiallyUnknown || + isPotentiallyNull && + isPotentiallyNonNull) + || cannotBeNull != (isProtectedNonNull || + isDefinitelyNonNull) + || canOnlyBeNull != (isProtectedNull || + isDefinitelyNull)) { + if (failures == 0) { + System.out.println(header); + } + failures++; + System.out.println("\t\tconsistency breakage (64) for " + State.states[i].name); + } + } + } + assertTrue("nb of failures: " + failures, failures == 0); +} + +public void test2500_addInitializationsFrom_for_definites() { + // when an added initialization is a def. something, it should + // affect the left hand term as the markAsDefinite* method would + // do + int failures = 0; + for (int i = 0; i < State.states.length; i++) { + if (State.states[i].symbolic) { + UnconditionalFlowInfoTestHarness source1, source2, result1, result2; + source1 = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(State.states[i]); + for (int j = 0; j < State.states.length; j++) { + if (State.states[j].symbolic) { + source2 = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(State.states[j]); + result1 = (UnconditionalFlowInfoTestHarness) source1.copy(); + result2 = (UnconditionalFlowInfoTestHarness) source1.copy(); + if (source2.isDefinitelyNonNull(TestLocalVariableBinding.local0)) { + if (! source2.isProtectedNonNull(TestLocalVariableBinding.local0)) { + result1.markAsDefinitelyNonNull(TestLocalVariableBinding.local0); + } else { + continue; + } + } + else if (source2.isDefinitelyNull(TestLocalVariableBinding.local0)) { + if (! source2.isProtectedNull(TestLocalVariableBinding.local0)) { + result1.markAsDefinitelyNull(TestLocalVariableBinding.local0); + } else { + continue; + } + } + else if (source2.isDefinitelyUnknown(TestLocalVariableBinding.local0)) { + result1.markAsDefinitelyUnknown(TestLocalVariableBinding.local0); + } + else if (source2.nullBit1 != 0) { + if (failures == 0) { + System.out.println("addInitializationsFrom_for_definites failures: "); //$NON-NLS-1$ + } + failures++; + System.out.println("\t\t" + State.states[j].name + + " should answer true to at least one isDefinite* query"); + // PREMATURE move to specific queries test case + } + else { + continue; + } + result2.addInitializationsFrom(source2); + if (!result1.testEquals(result2)) { + if (failures == 0) { + System.out.println("addInitializationsFrom_for_definites failures: "); //$NON-NLS-1$ + } + failures++; + System.out.println("\t\t" + State.states[i].name + + " + " + State.states[j].name + + " => " + result2.asState().name + + " instead of: " + result1.asState().name); + } + } + } + } + } + assertTrue("nb of failures: " + failures, failures == 0); +} + +// Use for coverage tests only. Needs specific instrumentation of code, +// that is controled by UnconditionalFlowInfo#coverageTestFlag. +// Note: coverage tests tend to fill the console with messages, and the +// instrumented code is slower, so never release code with active +// coverage tests. +private static int coveragePointsNb = 45; + +// PREMATURE reactivate coverage tests +// Coverage by state transition tables methods. +public void test2998_coverage() { + if (UnconditionalFlowInfo.COVERAGE_TEST_FLAG) { + // sanity check: need to be sure that the tests execute properly when not + // trying to check coverage + UnconditionalFlowInfo.CoverageTestId = 0; + test0053_array(); + test0070_type_reference(); + test2050_markAsComparedEqualToNonNull(); + test2051_markAsComparedEqualToNull(); + test2055_markAsDefinitelyNonNull(); + test2056_markAsDefinitelyNull(); + test2057_markAsDefinitelyUnknown(); + test2060_addInitializationsFrom(); + test2061_addPotentialInitializationsFrom(); + test2062_mergedWith(); + testBug292478(); + testBug292478c(); + test0331_if_else_nested(); + testBug325755b(); + testBug292478g(); + // coverage check + int failuresNb = 0; + for (int i = 1; i <= coveragePointsNb; i++) { + if (i == 11 || i == 12 || i == 14) { + continue; + // these can only be reached via a direct call to addPotentialNullInfoFrom, + // which is not implemented in low level tests - all those go through + // addPotentialInitsFrom + } + try { + UnconditionalFlowInfo.CoverageTestId = i; + test0053_array(); + test0070_type_reference(); + test2050_markAsComparedEqualToNonNull(); + test2051_markAsComparedEqualToNull(); + test2055_markAsDefinitelyNonNull(); + test2056_markAsDefinitelyNull(); + test2057_markAsDefinitelyUnknown(); + test2060_addInitializationsFrom(); + test2061_addPotentialInitializationsFrom(); + test2062_mergedWith(); + testBug292478(); + testBug292478c(); + test0331_if_else_nested(); + testBug325755b(); + testBug292478g(); + } + catch (AssertionFailedError e) { + continue; + } + catch (AssertionFailedException e) { + continue; + } + failuresNb++; + System.out.println("Missing coverage point: " + i); + } + UnconditionalFlowInfo.CoverageTestId = 0; // reset for other tests + assertEquals(failuresNb + " missing coverage point(s)", failuresNb, 0); + } +} + +// Coverage by code samples. +public void test2999_coverage() { + if (UnconditionalFlowInfo.COVERAGE_TEST_FLAG) { + // sanity check: need to be sure that the tests execute properly when not + // trying to check coverage + UnconditionalFlowInfo.CoverageTestId = 0; + test0001_simple_local(); + test0053_array(); + test0070_type_reference(); + test0327_if_else(); + test0401_while(); + test0420_while(); + test0509_try_finally_embedded(); + test2000_flow_info(); + test2004_flow_info(); + test2008_flow_info(); + test2011_flow_info(); + test2013_flow_info(); + test2018_flow_info(); + test2019_flow_info(); + test2020_flow_info(); + // coverage check + int failuresNb = 0; + for (int i = 1; i <= coveragePointsNb; i++) { + if (i < 3 + || 4 < i && i < 11 + || 11 < i && i < 16 + || 16 < i && i < 20 + || i == 21 + || 23 < i && i < 27 + || 29 < i && i < 33 + || 36 < i) { // TODO (maxime) complete coverage tests + continue; + } + try { + UnconditionalFlowInfo.CoverageTestId = i; + test0001_simple_local(); + test0053_array(); + test0070_type_reference(); + test0327_if_else(); + test0401_while(); + test0420_while(); + test0509_try_finally_embedded(); + test2000_flow_info(); + test2004_flow_info(); + test2008_flow_info(); + test2011_flow_info(); + test2013_flow_info(); + test2018_flow_info(); + test2019_flow_info(); + test2020_flow_info(); + } + catch (AssertionFailedError e) { + continue; + } + catch (AssertionFailedException e) { + continue; + } + failuresNb++; + System.out.println("Missing coverage point: " + i); + } + UnconditionalFlowInfo.CoverageTestId = 0; // reset for other tests + assertEquals(failuresNb + " missing coverage point(s)", failuresNb, 0); + } +} + +// only works for info coded on bit 0 - least significant +String testCodedValueOf(long[] data) { + int length; + StringBuilder result = new StringBuilder(length = data.length); + for (int i = 0; i < length; i++) { + result.append(data[i] == 0 ? '0' : '1'); + } + return result.toString(); +} + +static String testStringValueOf(long[] data) { + int length; + StringBuilder result = new StringBuilder((length = data.length) * 2 + 1); + result.append('{'); + for (int i = 0; i < length; i++) { + if (i > 0) { + result.append(','); + } + result.append(data[i]); + } + result.append('}'); + return result.toString(); +} +} + +/** + * A specific extension of LocalVariableBinding suitable for flow info + * manipulation at an implementation level. + */ +class TestLocalVariableBinding extends LocalVariableBinding { + static class TestTypeBinding extends TypeBinding { + public TestTypeBinding() { + this.tagBits = 0L; + } + public char[] constantPoolName() { + return null; + } + public PackageBinding getPackage() { + return null; + } + public boolean isCompatibleWith(TypeBinding right, Scope captureScope) { + return false; + } + public char[] qualifiedSourceName() { + return null; + } + public char[] sourceName() { + return null; + } + public char[] readableName() { + return null; + } + } + final static TypeBinding testTypeBinding = new TestTypeBinding(); + final static char [] testName = {'t', 'e', 's', 't'}; + TestLocalVariableBinding(int id) { + super(testName, testTypeBinding, 0, false); + this.id = id; + } + public Constant constant() { + return Constant.NotAConstant; + } + static final TestLocalVariableBinding + local0 = new TestLocalVariableBinding(0), + local64 = new TestLocalVariableBinding(64), + local128 = new TestLocalVariableBinding(128); +} + +/** + * A class meant to augment + * @link{org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo} with + * capabilities in the test domain. It especially provides factories to build + * fake flow info instances for use in state transitions validation. + */ +/* + * Moreover, this class defines the implementation of key operations for the + * benefit of itself and NullInfoRegistryTestHarness. Given the fact that the + * latter could not extend UnconditionalFlowInfoTestHarness and + * NullInfoRegistry, the code is factorized into static methods. + */ +class UnconditionalFlowInfoTestHarness extends UnconditionalFlowInfo { + int testPosition; + // Interface +/** + * Return the state represented by this. + * @return the state represented by this + */ +NullReferenceImplTests.State asState() { + return asState(this, 0); +} + +/** + * Return the state represented by this for a variable encoded at a given position. + * @param position - int the position of the considered variable + * @return the state represented by this for a variable encoded at a given position + */ +NullReferenceImplTests.State asState(int position) { + return asState(this, position); +} + +public FlowInfo copy() { + UnconditionalFlowInfoTestHarness copy = + new UnconditionalFlowInfoTestHarness(); + copy.testPosition = this.testPosition; + copy(this, copy); + return copy; +} + +public void markAsDefinitelyNonNull(LocalVariableBinding local) { + grow(local.id + this.maxFieldCount); + super.markAsDefinitelyNonNull(local); +} + +public void markAsDefinitelyNull(LocalVariableBinding local) { + grow(local.id + this.maxFieldCount); + super.markAsDefinitelyNull(local); +} + +public void markAsDefinitelyUnknown(LocalVariableBinding local) { + grow(local.id + this.maxFieldCount); + super.markAsDefinitelyUnknown(local); +} + +/** + * Return a fake unconditional flow info which bit fields represent the given + * null bits for a local variable of id 0 within a class that would have no + * field. + * @param nullBits the bits that must be set, given in the same order as the + * nullAssignment* fields in UnconditionalFlowInfo definition; use 0 + * for a bit that is not set, 1 else + * @return a fake unconditional flow info which bit fields represent the + * null bits given in parameter + */ +public static UnconditionalFlowInfoTestHarness testUnconditionalFlowInfo( + long [] nullBits) { + return testUnconditionalFlowInfo(nullBits, 0); +} + +/** + * Return a fake unconditional flow info which bit fields represent the given + * null bits for a local variable of id position within a class that would have + * no field. + * @param nullBits the bits that must be set, given in the same order as the + * nullAssignment* fields in UnconditionalFlowInfo definition; use 0 + * for a bit that is not set, 1 else + * @param position the position of the variable within the bit fields; use + * various values to test different parts of the bit fields, within + * or beyond BitCacheSize + * @return a fake unconditional flow info which bit fields represent the + * null bits given in parameter + */ +public static UnconditionalFlowInfoTestHarness testUnconditionalFlowInfo( + long [] nullBits, int position) { + UnconditionalFlowInfoTestHarness result = + new UnconditionalFlowInfoTestHarness(); + result.testPosition = position; + init(result, nullBits, position); + return result; +} + +/** + * Return a fake unconditional flow info which bit fields represent the given + * state for a local variable of id 0 within a class that would have + * no field. + * @param state - State the desired state for the variable + * @return a fake unconditional flow info which bit fields represent the + * state given in parameter + */ +public static UnconditionalFlowInfoTestHarness testUnconditionalFlowInfo(NullReferenceImplTests.State state) { + return testUnconditionalFlowInfo(state, 0); +} + +/** + * Return a fake unconditional flow info which bit fields represent the given + * state for a local variable of id position within a class that would have + * no field. + * @param state - State the desired state for the variable + * @param position the position of the variable within the bit fields; use + * various values to test different parts of the bit fields, within + * or beyond BitCacheSize + * @return a fake unconditional flow info which bit fields represent the + * state given in parameter + */ +public static UnconditionalFlowInfoTestHarness testUnconditionalFlowInfo( + NullReferenceImplTests.State state, int position) { + UnconditionalFlowInfoTestHarness result = + new UnconditionalFlowInfoTestHarness(); + long[] nullBits = state.asLongArray(); + result.testPosition = position; + init(result, nullBits, position); + return result; +} + +/** + * Return true iff this flow info can be considered as equal to the one passed + * in parameter. + * @param other the flow info to compare to + * @return true iff this flow info compares equal to other + */ +public boolean testEquals(UnconditionalFlowInfo other) { + return testEquals(this, other); +} + +/** + * Return true iff this flow info can be considered as equal to the one passed + * in parameter in respect with a single local variable which id would be + * position in a class with no field. + * @param other the flow info to compare to + * @param position the position of the local to consider + * @return true iff this flow info compares equal to other for a given local + */ +public boolean testEquals(UnconditionalFlowInfo other, int position) { + return testEquals(this, other, position); +} + +/** + * Return a string suitable for use as a representation of this flow info + * within test series. + * @return a string suitable for use as a representation of this flow info + */ +public String testString() { + if (this == DEAD_END) { + return "FlowInfo.DEAD_END"; //$NON-NLS-1$ + } + return testString(this, this.testPosition); +} + +/** + * Return a string suitable for use as a representation of this flow info + * within test series. + * @param position a position to consider instead of this flow info default + * test position + * @return a string suitable for use as a representation of this flow info + */ +public String testString(int position) { + return testString(this, position); +} + + // Factorized implementation +static NullReferenceImplTests.State asState(UnconditionalFlowInfo zis, int position) { + if ((zis.tagBits & NULL_FLAG_MASK) == 0) { + return NullReferenceImplTests.State.start; + } + if (position < BitCacheSize) { + return NullReferenceImplTests.State.fromLongValues( + (zis.nullBit1 >> position) & 1, + (zis.nullBit2 >> position) & 1, + (zis.nullBit3 >> position) & 1, + (zis.nullBit4 >> position) & 1, + 0, + 0); + } + else { + int vectorIndex = (position / BitCacheSize) - 1; + position %= BitCacheSize; + if (vectorIndex >= zis.extra[2].length) { + return NullReferenceImplTests.State.start; + } + return NullReferenceImplTests.State.fromLongValues( + (zis.extra[2][vectorIndex] >> position) & 1, + (zis.extra[3][vectorIndex] >> position) & 1, + (zis.extra[4][vectorIndex] >> position) & 1, + (zis.extra[5][vectorIndex] >> position) & 1, + 0 //(zis.extra[6][vectorIndex] >> position) & 1, + , 0 //(zis.extra[7][vectorIndex] >> position) & 1 + ); + } +} + +static void copy(UnconditionalFlowInfo source, UnconditionalFlowInfo target) { + target.definiteInits = source.definiteInits; + target.potentialInits = source.potentialInits; + boolean hasNullInfo = (source.tagBits & NULL_FLAG_MASK) != 0; + if (hasNullInfo) { + target.nullBit1 = source.nullBit1; + target.nullBit2 = source.nullBit2; + target.nullBit3 = source.nullBit3; + target.nullBit4 = source.nullBit4; + } + target.iNBit = source.iNBit; + target.iNNBit = source.iNNBit; + target.tagBits = source.tagBits; + target.maxFieldCount = source.maxFieldCount; + if (source.extra != null) { + int length; + target.extra = new long[extraLength][]; + System.arraycopy(source.extra[0], 0, + (target.extra[0] = new long[length = source.extra[0].length]), 0, length); + System.arraycopy(source.extra[1], 0, + (target.extra[1] = new long[length]), 0, length); + if (hasNullInfo) { + for (int j = 0; j < extraLength; j++) { + System.arraycopy(source.extra[j], 0, + (target.extra[j] = new long[length]), 0, length); + } + } + else { + for (int j = 0; j < extraLength; j++) { + target.extra[j] = new long[length]; + } + } + } +} + +public void grow(int position) { + int vectorIndex = ((position) / BitCacheSize) - 1; + int length = vectorIndex + 1, oldLength; + if (this.extra == null) { + this.extra = new long[extraLength][]; + for (int j = 0; j < extraLength; j++) { + this.extra[j] = new long[length]; + } + } else if (length > (oldLength = this.extra[2].length)) { + for (int j = 0; j < extraLength; j++) { + System.arraycopy(this.extra[j], 0, + this.extra[j] = new long[length], 0, oldLength); + } + } +} + +static void init(UnconditionalFlowInfo zis, long [] nullBits, int position) { + if (position < BitCacheSize) { + zis.nullBit1 = nullBits[0] << position; + zis.nullBit2 = nullBits[1] << position; + zis.nullBit3 = nullBits[2] << position; + zis.nullBit4 = nullBits[3] << position; + } + else { + int vectorIndex = (position / BitCacheSize) - 1, + length = vectorIndex + 1; + position %= BitCacheSize; + zis.extra = new long[extraLength][]; + zis.extra[0] = new long[length]; + zis.extra[1] = new long[length]; + for (int j = 2; j < extraLength; j++) { + zis.extra[j] = new long[length]; + zis.extra[j][vectorIndex] = nullBits[j - 2] << position; + } + // FIXME: while IN,INN are not included in nullBits: + Arrays.fill(zis.extra[UnconditionalFlowInfo.IN], -1L); + Arrays.fill(zis.extra[UnconditionalFlowInfo.INN], -1L); + } + zis.iNBit = -1L; // FIXME: nullBits[4] << position; + zis.iNNBit = -1L; // FIXME: nullBits[5] << position; + if (nullBits[0] != 0 || nullBits[1] != 0 + || nullBits[2] != 0 || nullBits[3] != 0 + || nullBits[4] != 0 || nullBits[5] != 0) { + // cascade better than nullBits[0] | nullBits[1] | nullBits[2] | nullBits[3] + // by 10%+ + // TODO (maxime) run stats to determine which is the better order + zis.tagBits |= NULL_FLAG_MASK; + } + zis.maxFieldCount = 0; +} + +static boolean testEquals(UnconditionalFlowInfo zis, UnconditionalFlowInfo other) { + if (zis.tagBits != other.tagBits) { + return false; + } + if (zis.nullBit1 != other.nullBit1 + || zis.nullBit2 != other.nullBit2 + || zis.nullBit3 != other.nullBit3 + || zis.nullBit4 != other.nullBit4 + /*|| zis.iNBit != other.iNBit // FIXME: include these bits in comparison? + || zis.iNNBit != other.iNNBit */) { + return false; + } + int left = zis.extra == null ? 0 : zis.extra[2].length, + right = other.extra == null ? 0 : other.extra[2].length, + both = 0, i; + if (left > right) { + both = right; + } + else { + both = left; + } + for (i = 0; i < both ; i++) { + for (int j = 2; j < extraLength; j++) { + if (zis.extra[j][i] != + other.extra[j][i]) { + return false; + } + } + } + for (; i < left; i++) { + for (int j = 2; j < extraLength; j++) { + if (zis.extra[j][i] != 0) { + return false; + } + } + } + for (; i < right; i++) { + for (int j = 2; j < extraLength; j++) { + if (other.extra[j][i] != 0) { + return false; + } + } + } + return true; +} + +static boolean testEquals(UnconditionalFlowInfo zis, UnconditionalFlowInfo other, + int position) { + int vectorIndex = position / BitCacheSize - 1; + if ((zis.tagBits & other.tagBits & NULL_FLAG_MASK) == 0) { + return true; + } + long mask; + if (vectorIndex < 0) { + return ((zis.nullBit1 & (mask = (1L << position))) ^ + (other.nullBit1 & mask)) == 0 && + ((zis.nullBit2 & mask) ^ + (other.nullBit2 & mask)) == 0 && + ((zis.nullBit3 & mask) ^ + (other.nullBit3 & mask)) == 0 && + ((zis.nullBit4 & mask) ^ + (other.nullBit4 & mask)) == 0 /* && // FIXME: include these bits in comparison? + ((zis.iNBit & mask) ^ + (other.iNBit & mask)) == 0 && + ((zis.iNNBit & mask) ^ + (other.iNNBit & mask)) == 0 */; + } + else { + int left = zis.extra == null ? + 0 : + zis.extra[0].length; + int right = other.extra == null ? + 0 : + other.extra[0].length; + int both = left < right ? left : right; + if (vectorIndex < both) { + mask = (1L << (position % BitCacheSize)); + for (int j = 2; j < extraLength; j++) { + if (((zis.extra[j][vectorIndex] & mask) + ^ (other.extra[j][vectorIndex] & mask)) != 0) { + return false; + } + } + return true; + } + if (vectorIndex < left) { + return ((zis.extra[2][vectorIndex] | + zis.extra[3][vectorIndex] | + zis.extra[4][vectorIndex] | + zis.extra[5][vectorIndex] | + zis.extra[6][vectorIndex] | + zis.extra[7][vectorIndex]) & + (1L << (position % BitCacheSize))) == 0; + } + return ((other.extra[2][vectorIndex] | + other.extra[3][vectorIndex] | + other.extra[4][vectorIndex] | + other.extra[5][vectorIndex] | + other.extra[6][vectorIndex] | + other.extra[7][vectorIndex]) & + (1L << (position % BitCacheSize))) == 0; + } +} + +static String testString(UnconditionalFlowInfo zis, int position) { + if (zis == DEAD_END) { + return "FlowInfo.DEAD_END"; //$NON-NLS-1$ + } + if (position < BitCacheSize) { + return "{" + (zis.nullBit1 >> position) //$NON-NLS-1$ + + "," + (zis.nullBit2 >> position) //$NON-NLS-1$ + + "," + (zis.nullBit3 >> position) //$NON-NLS-1$ + + "," + (zis.nullBit4 >> position) //$NON-NLS-1$ +// + "," + (zis.iNBit >> position) //$NON-NLS-1$ +// + "," + (zis.iNNBit >> position) //$NON-NLS-1$ + + "}"; //$NON-NLS-1$ + } + else { + int vectorIndex = position / BitCacheSize - 1, + shift = position % BitCacheSize; + return "{" + (zis.extra[2][vectorIndex] //$NON-NLS-1$ + >> shift) + + "," + (zis.extra[3][vectorIndex] //$NON-NLS-1$ + >> shift) + + "," + (zis.extra[4][vectorIndex] //$NON-NLS-1$ + >> shift) + + "," + (zis.extra[5][vectorIndex] //$NON-NLS-1$ + >> shift) +// + "," + (zis.extra[6][vectorIndex] //$NON-NLS-1$ +// >> shift) +// + "," + (zis.extra[7][vectorIndex] //$NON-NLS-1$ +// >> shift) + + "}"; //$NON-NLS-1$ + } +} +} +interface CodeAnalysis { + public static final String + definitionStartMarker = "DEFINITION START", + definitionEndMarker = "DEFINITION END", + initializerStartMarker = "INITIALIZER START", + initializerEndMarker = "INITIALIZER END"; +} +@SuppressWarnings({ "unchecked", "rawtypes" }) +class TransitiveClosureHolder { +static class Element { + NullReferenceImplTests.State value; + boolean alreadyKnown; + Element(NullReferenceImplTests.State value) { + if (value == null) { + throw new IllegalArgumentException("not a valid element"); + } + this.value = value; + } +} +Map elements = new TreeMap(); +public TransitiveClosureHolder() { + Element start = new Element(NullReferenceImplTests.State.start); + this.elements.put(start.value, start); +} +void add(NullReferenceImplTests.State value) { + if (value == null) { + throw new IllegalArgumentException("not a valid state"); + } + if (! this.elements.containsKey(value)) { + this.elements.put(value, new Element(value)); + } +} +void add(NullReferenceImplTests.State[] values) { + if (values == null) { + throw new IllegalArgumentException("not a valid states set"); + } + for (int i = 0, length = values.length; i < length; i++) { + add(values[i]); + } +} +NullReferenceImplTests.State[] asArray() { + int length; + NullReferenceImplTests.State[] result = new NullReferenceImplTests.State[length = this.elements.size()]; + Iterator elementsIterator = this.elements.keySet().iterator(); + for (int j = 0; j < length; j++) { + result[j] = (NullReferenceImplTests.State) elementsIterator.next(); + } + return result; +} +NullReferenceImplTests.State[] notAlreadyKnowns() { + List resultAccumulator = new ArrayList(this.elements.size()); + Iterator i = this.elements.values().iterator(); + Element current; + while (i.hasNext()) { + if (! (current = (Element) i.next()).alreadyKnown) { + resultAccumulator.add(current.value); + } + } + int length; + NullReferenceImplTests.State[] result = new NullReferenceImplTests.State[length = resultAccumulator.size()]; + for (int j = 0; j < length; j++) { + result[j] = (NullReferenceImplTests.State) resultAccumulator.get(j); + } + return result; +} +void markAllAsAlreadyKnown() { + Iterator i = this.elements.values().iterator(); + while (i.hasNext()) { + ((Element) i.next()).alreadyKnown = true; + } +} +@Override +public String toString() { + StringBuilder output = new StringBuilder(); + output.append("Transitive closure:\n"); + SortedMap sorted = new TreeMap(this.elements); + Iterator i = sorted.keySet().iterator(); + while (i.hasNext()) { + output.append(i.next().toString()); + output.append('\n'); + } + return output.toString(); +} +} + +// PREMATURE segregate pure tooling into a separate project, keep tests only here +/** + * The Generator class is meant to generate the tabular data needed by the + * flow information implementation level tests. While the tests should ensure + * non regression by leveraging their initialization tables only, any change + * into the flow information logic or encoding is due to yield considerable + * changes into the literal values sets of the initializers themselves. + * Tooling the production of those literals buys us flexibility. + * {@link #printHelp printHelp} for details. + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +class Generator { +static NullReferenceImplTests.State[] computeTransitiveClosure() { + TransitiveClosureHolder transitiveClosure = new TransitiveClosureHolder(); + NullReferenceImplTests.State[] unknowns; + unknowns = transitiveClosure.notAlreadyKnowns(); + while (unknowns.length != 0) { + transitiveClosure.markAllAsAlreadyKnown(); + for (int i = 0, length = NullReferenceImplTransformations.transformations.length; i < length; i ++) { + transitiveClosure.add( + NullReferenceImplTransformations.transformations[i]. + computeOutputs(transitiveClosure.asArray())); + } + unknowns = transitiveClosure.notAlreadyKnowns(); + } + return transitiveClosure.asArray(); +} +public static void main(String[] args) { + if (args.length == 0) { + printHelp(false); + System.exit(1); + } + switch (args.length) { + case 1: + if (args[0].equals("--help")) { + printHelp(true); + System.exit(0); + } + else { + printHelp(false); + System.exit(1); + } + break; + case 2: + if (args[0].equals("--printTruthTables")) { + File outputDir = new File(args[1]); + if (outputDir.isDirectory()) { + for (int i = 0, length = NullReferenceImplTransformations.transformations.length; i < length; i++) { + NullReferenceImplTransformations.transformations[i].printTruthTables(outputDir); + } + } + else { + // PREMATURE error handling + } + System.exit(0); + } + else { + printHelp(false); + System.exit(1); + } + break; + case 3: + if (args[0].equals("--reinitializeFromComputedValues")) { + reinitializeFromComputedValues(args[1], args[2]); + System.out.println("Generator generated new file into " + args[2]); + System.exit(0); + } + //$FALL-THROUGH$ + case 5: + if (args[0].equals("--reinitializeFromComments")) { + reinitializeFromComments(args[1], args[2], args[3], args[4]); + System.out.println("Generator generated new files into " + args[2] + + " and " + args[4]); + System.exit(0); + } + //$FALL-THROUGH$ + default: + printHelp(false); + System.exit(1); + } +} + +private static void reinitializeFromComments( + String statesSource, String statesTarget, + String transformationsSource, String transformationsTarget) { + if (statesSource.equals(transformationsSource) || + statesTarget.equals(transformationsTarget)) { + throw new RuntimeException(); + } + try { + BufferedReader in; + BufferedWriter out; + NullReferenceImplTests.State.reinitializeFromComment( + in = new BufferedReader( + new FileReader(statesSource)), + out = new BufferedWriter(new FileWriter(statesTarget))); + in.close(); + out.close(); + File[] tempFiles = new File[2]; + tempFiles[0] = File.createTempFile("generator", "java"); + tempFiles[1] = File.createTempFile("generator", "java"); + NullReferenceImplTransformations.transformations[0].reinitializeFromComments( + in = new BufferedReader( + new FileReader(transformationsSource)), + out = new BufferedWriter(new FileWriter(tempFiles[0]))); + in.close(); + out.close(); + int i, length; + for (i = 1, length = NullReferenceImplTransformations.transformations.length - 1; i < length; i++) { + NullReferenceImplTransformations.transformations[i].reinitializeFromComments( + in = new BufferedReader( + new FileReader(tempFiles[(i + 1) % 2])), + out = new BufferedWriter(new FileWriter(tempFiles[i % 2]))); + in.close(); + out.close(); + } + NullReferenceImplTransformations.transformations[i].reinitializeFromComments( + in = new BufferedReader( + new FileReader(tempFiles[(i + 1) % 2])), + out = new BufferedWriter(new FileWriter(transformationsTarget))); + in.close(); + out.close(); + } catch (Throwable t) { + System.err.println("Generator error:"); + t.printStackTrace(System.err); + System.exit(2); + } +} + +private static void reinitializeFromComputedValues(String source, String target) { + for (int i = 0, length = NullReferenceImplTransformations.transformations.length; + i < length; i++) { + NullReferenceImplTransformations.transformations[i].hydrate(); + } + NullReferenceImplTests.State[] transitiveClosure = computeTransitiveClosure(); // need for initialization? + transitiveClosure = addSymbolicStates(transitiveClosure); // don't rely on reachibility alone, since we don't cover all operations in these tests. + Arrays.sort(transitiveClosure, new Comparator() { + @Override + public int compare(Object o1, Object o2) { + return Integer.valueOf(((State)o1).value).compareTo(Integer.valueOf(((State)o2).value)); + } + }); + try { + BufferedReader in; + BufferedWriter out; + File[] tempFiles = new File[2]; + tempFiles[0] = File.createTempFile("generator", "java"); + tempFiles[1] = File.createTempFile("generator", "java"); + NullReferenceImplTransformations.transformations[0].reinitializeFromComputedValues( + in = new BufferedReader( + new FileReader(source)), + out = new BufferedWriter(new FileWriter(tempFiles[0])), + transitiveClosure); + in.close(); + out.close(); + int i, length; + for (i = 1, length = NullReferenceImplTransformations.transformations.length - 1; i < length; i++) { + NullReferenceImplTransformations.transformations[i].reinitializeFromComputedValues( + in = new BufferedReader( + new FileReader(tempFiles[(i + 1) % 2])), + out = new BufferedWriter(new FileWriter(tempFiles[i % 2])), + transitiveClosure); + in.close(); + out.close(); + } + NullReferenceImplTransformations.transformations[i].reinitializeFromComputedValues( + in = new BufferedReader( + new FileReader(tempFiles[(i + 1) % 2])), + out = new BufferedWriter(new FileWriter(target)), + transitiveClosure); + in.close(); + out.close(); + } catch (Throwable t) { + System.err.println("Generator error:"); + t.printStackTrace(System.err); + System.exit(2); + } +} +private static State[] addSymbolicStates(State[] transitiveClosure) { + Set allStates = new HashSet(); + allStates.addAll(Arrays.asList(transitiveClosure)); + for (int i=0; i < State.statesNb; i++) + if (State.states[i].symbolic) + allStates.add(State.states[i]); + return (State[]) allStates.toArray(new State[allStates.size()]); +} + +private static void printHelp(boolean longText) { + if (longText) { + System.out.println( + "Generator use cases\n" + + " - when a brand new logic is experimented for the transitions, the best\n" + + " way to go is to write explicit (inefficient) transformation code within\n" + + " UnconditionalFlowInfo, then generate the literal initializers from\n" + + " there; use the command\n" + + " --reinitializeFromComputedValues \n" + + " to this effect; in case of inconsistencies or errors, messages are\n" + + " printed to the error output stream and the result should be considered as non reliable;\n" + + " - when only a few changes are made to state names or a specific\n" + + " transitions, it should be possible to get the test initializers fixed\n" + + " before UnconditionalFlowInfo implements those changes; use the command\n" + + " --reinitializeFromComments \n" + + " to this effect;\n" + + " - the same command can be used when, while the semantics of the system\n" + + " are unchanged, the encoding is modified; it should then produce the\n" + + " initializers according to the new encoding, as defined by the comment\n" + + " for State.states, and the transformations as defined by their\n" + + " respective comment;\n" + + " - when a given encoding is retained, its optimization may leverage truth\n" + + " tables; use the --printTruthTables command to this effect.\n" + + " \n\n"); + printHelp(false); + } + else { + System.out.println( + "Usage:\n" + + "Generator --help\n" + + " prints a more detailed help message\n" + + "Generator --printTruthTables\n" + + " prints the truth tables of the transformations\n" + + "Generator --reinitializeFromComments \n" + + " generates into target file a copy of source file into which\n" + + " transformations initializers have been reset from their definitions\n" + + "Generator --reinitializeFromComputedValues \n" + + " generates into target file a copy of source file into which\n" + + " transformations definitions and initializers have been reset\n" + + " according to the behavior of the current UnconditionalFlowInfo\n" + ); + } +} +} + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTransformations.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTransformations.java new file mode 100644 index 0000000000..d4cd6d2413 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceImplTransformations.java @@ -0,0 +1,3296 @@ +/******************************************************************************* + * Copyright (c) 2005, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" + * bug 386181 - [compiler][null] wrong transition in UnconditionalFlowInfo.mergedWith() + * Bug 453635 - [compiler][null] Update NullReferenceImplTests and friends + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.eclipse.jdt.core.tests.compiler.regression.NullReferenceImplTests.State; +import org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class NullReferenceImplTransformations { + public static final Transformation + markAsComparedEqualToNonNull = + // markAsComparedEqualToNonNull DEFINITION START + // start => prot. non null + // pot. unknown => pot. nn & prot. nn + // pot. non null => pot. nn & prot. nn + // pot. nn & pot. un => pot. nn & prot. nn + // pot. null => prot. non null + // pot. n & pot. un => pot. nn & prot. nn + // pot. n & pot. nn => pot. nn & prot. nn + // pot. n & pot. nn & pot. un => prot. non null // pot. nn & prot. nn could be better? + // def. unknown => def. non null + // def. non null => def. non null + // pot. nn & prot. nn => pot. nn & prot. nn + // def. null => prot. non null + // pot. n & prot. n => prot. non null + // prot. null => prot. non null + // prot. non null => prot. non null + // markAsComparedEqualToNonNull DEFINITION END + new TwoDimensionalTransformation("markAsComparedEqualToNonNull", + new byte[][] { + // markAsComparedEqualToNonNull INITIALIZER START + {0x00,0x3C}, + {0x04,0x2C}, + {0x08,0x2C}, + {0x0C,0x2C}, + {0x10,0x3C}, + {0x14,0x2C}, + {0x18,0x2C}, + {0x1C,0x3C}, + {0x24,0x28}, + {0x28,0x28}, + {0x2C,0x2C}, + {0x30,0x3C}, + {0x34,0x3C}, + {0x38,0x3C}, + {0x3C,0x3C}, + // markAsComparedEqualToNonNull INITIALIZER END + }) { + @Override + UnconditionalFlowInfo output(UnconditionalFlowInfo input, + TestLocalVariableBinding local) { + UnconditionalFlowInfo result = (UnconditionalFlowInfo)input.copy(); + result.markAsComparedEqualToNonNull(local); + return result; + } + }, + markAsComparedEqualToNull = + // markAsComparedEqualToNull DEFINITION START + // start => prot. null + // pot. unknown => pot. n & prot. n + // pot. non null => prot. null + // pot. nn & pot. un => pot. n & prot. n + // pot. null => pot. n & prot. n + // pot. n & pot. un => pot. n & prot. n + // pot. n & pot. nn => pot. n & prot. n + // pot. n & pot. nn & pot. un => pot. n & prot. n + // def. unknown => def. null + // def. non null => prot. null + // pot. nn & prot. nn => prot. null + // def. null => def. null + // pot. n & prot. n => pot. n & prot. n + // prot. null => prot. null + // prot. non null => prot. null + // markAsComparedEqualToNull DEFINITION END + new TwoDimensionalTransformation("markAsComparedEqualToNull", + new byte[][] { + // markAsComparedEqualToNull INITIALIZER START + {0x00,0x38}, + {0x04,0x34}, + {0x08,0x38}, + {0x0C,0x34}, + {0x10,0x34}, + {0x14,0x34}, + {0x18,0x34}, + {0x1C,0x34}, + {0x24,0x30}, + {0x28,0x38}, + {0x2C,0x38}, + {0x30,0x30}, + {0x34,0x34}, + {0x38,0x38}, + {0x3C,0x38}, + // markAsComparedEqualToNull INITIALIZER END + }) { + @Override + UnconditionalFlowInfo output(UnconditionalFlowInfo input, + TestLocalVariableBinding local) { + UnconditionalFlowInfo result = (UnconditionalFlowInfo)input.copy(); + result.markAsComparedEqualToNull(local); + return result; + } + }, + markAsDefinitelyNonNull = + // markAsDefinitelyNonNull DEFINITION START + // start => def. non null + // pot. unknown => def. non null + // pot. non null => def. non null + // pot. nn & pot. un => def. non null + // pot. null => def. non null + // pot. n & pot. un => def. non null + // pot. n & pot. nn => def. non null + // pot. n & pot. nn & pot. un => def. non null + // def. unknown => def. non null + // def. non null => def. non null + // pot. nn & prot. nn => def. non null + // def. null => def. non null + // pot. n & prot. n => def. non null + // prot. null => def. non null + // prot. non null => def. non null + // markAsDefinitelyNonNull DEFINITION END + new TwoDimensionalTransformation("markAsDefinitelyNonNull", + new byte[][] { + // markAsDefinitelyNonNull INITIALIZER START + {0x00,0x28}, + {0x04,0x28}, + {0x08,0x28}, + {0x0C,0x28}, + {0x10,0x28}, + {0x14,0x28}, + {0x18,0x28}, + {0x1C,0x28}, + {0x24,0x28}, + {0x28,0x28}, + {0x2C,0x28}, + {0x30,0x28}, + {0x34,0x28}, + {0x38,0x28}, + {0x3C,0x28}, + // markAsDefinitelyNonNull INITIALIZER END + }) { + @Override + UnconditionalFlowInfo output(UnconditionalFlowInfo input, + TestLocalVariableBinding local) { + UnconditionalFlowInfo result = (UnconditionalFlowInfo)input.copy(); + result.markAsDefinitelyNonNull(local); + return result; + } + }, + markAsDefinitelyNull = + // markAsDefinitelyNull DEFINITION START + // start => def. null + // pot. unknown => def. null + // pot. non null => def. null + // pot. nn & pot. un => def. null + // pot. null => def. null + // pot. n & pot. un => def. null + // pot. n & pot. nn => def. null + // pot. n & pot. nn & pot. un => def. null + // def. unknown => def. null + // def. non null => def. null + // pot. nn & prot. nn => def. null + // def. null => def. null + // pot. n & prot. n => def. null + // prot. null => def. null + // prot. non null => def. null + // markAsDefinitelyNull DEFINITION END + // PREMATURE add 'catch rules' + new TwoDimensionalTransformation("markAsDefinitelyNull", + new byte[][] { + // markAsDefinitelyNull INITIALIZER START + {0x00,0x30}, + {0x04,0x30}, + {0x08,0x30}, + {0x0C,0x30}, + {0x10,0x30}, + {0x14,0x30}, + {0x18,0x30}, + {0x1C,0x30}, + {0x24,0x30}, + {0x28,0x30}, + {0x2C,0x30}, + {0x30,0x30}, + {0x34,0x30}, + {0x38,0x30}, + {0x3C,0x30}, + // markAsDefinitelyNull INITIALIZER END + }) { + @Override + UnconditionalFlowInfo output(UnconditionalFlowInfo input, + TestLocalVariableBinding local) { + UnconditionalFlowInfo result = (UnconditionalFlowInfo)input.copy(); + result.markAsDefinitelyNull(local); + return result; + } + }, + markAsDefinitelyUnknown = + // markAsDefinitelyUnknown DEFINITION START + // start => def. unknown + // pot. unknown => def. unknown + // pot. non null => def. unknown + // pot. nn & pot. un => def. unknown + // pot. null => def. unknown + // pot. n & pot. un => def. unknown + // pot. n & pot. nn => def. unknown + // pot. n & pot. nn & pot. un => def. unknown + // def. unknown => def. unknown + // def. non null => def. unknown + // pot. nn & prot. nn => def. unknown + // def. null => def. unknown + // pot. n & prot. n => def. unknown + // prot. null => def. unknown + // prot. non null => def. unknown + // markAsDefinitelyUnknown DEFINITION END + new TwoDimensionalTransformation("markAsDefinitelyUnknown", + new byte[][] { + // markAsDefinitelyUnknown INITIALIZER START + {0x00,0x24}, + {0x04,0x24}, + {0x08,0x24}, + {0x0C,0x24}, + {0x10,0x24}, + {0x14,0x24}, + {0x18,0x24}, + {0x1C,0x24}, + {0x24,0x24}, + {0x28,0x24}, + {0x2C,0x24}, + {0x30,0x24}, + {0x34,0x24}, + {0x38,0x24}, + {0x3C,0x24}, + // markAsDefinitelyUnknown INITIALIZER END + }) { + @Override + UnconditionalFlowInfo output(UnconditionalFlowInfo input, + TestLocalVariableBinding local) { + UnconditionalFlowInfo result = (UnconditionalFlowInfo)input.copy(); + result.markAsDefinitelyUnknown(local); + return result; + } + }, + addInitializationsFrom = + // addInitializationsFrom DEFINITION START + // def. non null + def. non null => def. non null + // def. non null + def. null => def. null + // def. non null + def. unknown => def. unknown + // def. non null + pot. n & pot. nn & pot. un => pot. non null // BOGUS + // def. non null + pot. n & pot. nn => pot. n & pot. nn + // def. non null + pot. n & pot. un => pot. n & pot. nn + // def. non null + pot. n & prot. n => pot. n & prot. n + // def. non null + pot. nn & pot. un => def. unknown + // def. non null + pot. nn & prot. nn => def. non null + // def. non null + pot. non null => def. non null + // def. non null + pot. null => pot. n & pot. nn + // def. non null + pot. unknown => def. unknown // priv. + // def. non null + prot. non null => def. non null + // def. non null + prot. null => prot. null + // def. non null + start => def. non null + // def. null + def. non null => def. non null + // def. null + def. null => def. null + // def. null + def. unknown => def. unknown + // def. null + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // def. null + pot. n & pot. nn => pot. n & pot. nn + // def. null + pot. n & pot. un => pot. n & pot. un + // def. null + pot. n & prot. n => def. null + // def. null + pot. nn & pot. un => pot. n & pot. nn + // def. null + pot. nn & prot. nn => pot. nn & prot. nn + // def. null + pot. non null => pot. n & pot. nn + // def. null + pot. null => def. null + // def. null + pot. unknown => pot. n & pot. un // pot. null privileged over def. unknown + // def. null + prot. non null => prot. non null + // def. null + prot. null => def. null + // def. null + start => def. null + // def. unknown + def. non null => def. non null + // def. unknown + def. null => def. null + // def. unknown + def. unknown => def. unknown + // def. unknown + pot. n & pot. nn & pot. un => pot. non null // BOGUS + // def. unknown + pot. n & pot. nn => pot. n & pot. nn + // def. unknown + pot. n & pot. un => pot. n & pot. un // we loose the def here, but we need the pot. null + // def. unknown + pot. n & prot. n => def. null + // def. unknown + pot. nn & pot. un => def. unknown // priv. + // def. unknown + pot. nn & prot. nn => def. non null + // def. unknown + pot. non null => def. unknown // privileging over pot. nn & pot. un + // def. unknown + pot. null => pot. n & pot. un + // def. unknown + pot. unknown => def. unknown + // def. unknown + prot. non null => def. non null + // def. unknown + prot. null => def. null + // def. unknown + start => def. unknown + // pot. n & pot. nn & pot. un + def. non null => def. non null + // pot. n & pot. nn & pot. un + def. null => def. null + // pot. n & pot. nn & pot. un + def. unknown => def. unknown + // pot. n & pot. nn & pot. un + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. n & pot. nn & pot. un + pot. n & pot. nn => pot. n & pot. nn + // pot. n & pot. nn & pot. un + pot. n & pot. un => pot. n & pot. nn + // pot. n & pot. nn & pot. un + pot. n & prot. n => pot. n & prot. n + // pot. n & pot. nn & pot. un + pot. nn & pot. un => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + pot. nn & prot. nn => pot. nn & prot. nn + // pot. n & pot. nn & pot. un + pot. non null => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + pot. null => pot. n & pot. nn + // pot. n & pot. nn & pot. un + pot. unknown => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + prot. non null => pot. nn & prot. nn + // pot. n & pot. nn & pot. un + prot. null => pot. n & prot. n + // pot. n & pot. nn & pot. un + start => pot. n & pot. nn & pot. un + // pot. n & pot. nn + def. non null => def. non null + // pot. n & pot. nn + def. null => def. null + // pot. n & pot. nn + def. unknown => def. unknown + // pot. n & pot. nn + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. n & pot. nn + pot. n & pot. nn => pot. n & pot. nn + // pot. n & pot. nn + pot. n & pot. un => pot. n & pot. nn + // pot. n & pot. nn + pot. n & prot. n => pot. n & prot. n + // pot. n & pot. nn + pot. nn & pot. un => pot. n & pot. nn + // pot. n & pot. nn + pot. nn & prot. nn => pot. nn & prot. nn + // pot. n & pot. nn + pot. non null => pot. n & pot. nn + // pot. n & pot. nn + pot. null => pot. n & pot. nn + // pot. n & pot. nn + pot. unknown => pot. n & pot. nn + // pot. n & pot. nn + prot. non null => pot. nn & prot. nn + // pot. n & pot. nn + prot. null => pot. n & prot. n + // pot. n & pot. nn + start => pot. n & pot. nn + // pot. n & pot. un + def. non null => def. non null + // pot. n & pot. un + def. null => def. null + // pot. n & pot. un + def. unknown => def. unknown + // pot. n & pot. un + pot. n & pot. nn & pot. un => pot. n & pot. nn // should ideally include un + // pot. n & pot. un + pot. n & pot. nn => pot. n & pot. nn + // pot. n & pot. un + pot. n & pot. un => pot. n & pot. un + // pot. n & pot. un + pot. n & prot. n => pot. n & prot. n + // pot. n & pot. un + pot. nn & pot. un => pot. n & pot. nn + // pot. n & pot. un + pot. nn & prot. nn => pot. nn & prot. nn + // pot. n & pot. un + pot. non null => pot. n & pot. nn + // pot. n & pot. un + pot. null => pot. n & pot. un + // pot. n & pot. un + pot. unknown => pot. n & pot. un + // pot. n & pot. un + prot. non null => pot. nn & prot. nn + // pot. n & pot. un + prot. null => pot. n & prot. n + // pot. n & pot. un + start => pot. n & pot. un + // pot. n & prot. n + def. non null => def. non null + // pot. n & prot. n + def. null => def. null + // pot. n & prot. n + def. unknown => def. unknown + // pot. n & prot. n + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // pot. n & prot. n + pot. n & pot. nn => pot. n & pot. nn + // pot. n & prot. n + pot. n & pot. un => pot. n & pot. un + // pot. n & prot. n + pot. n & prot. n => pot. n & prot. n + // pot. n & prot. n + pot. nn & pot. un => pot. n & pot. nn + // pot. n & prot. n + pot. nn & prot. nn => pot. nn & prot. nn + // pot. n & prot. n + pot. non null => pot. n & pot. nn + // pot. n & prot. n + pot. null => pot. n & prot. n + // pot. n & prot. n + pot. unknown => pot. n & pot. un + // pot. n & prot. n + prot. non null => prot. non null + // pot. n & prot. n + prot. null => pot. n & prot. n + // pot. n & prot. n + start => pot. n & prot. n + // pot. nn & pot. un + def. non null => def. non null + // pot. nn & pot. un + def. null => def. null + // pot. nn & pot. un + def. unknown => def. unknown + // pot. nn & pot. un + pot. n & pot. nn & pot. un => pot. non null // should ideally include un + // pot. nn & pot. un + pot. n & pot. nn => pot. n & pot. nn + // pot. nn & pot. un + pot. n & pot. un => pot. n & pot. nn + // pot. nn & pot. un + pot. n & prot. n => pot. n & prot. n + // pot. nn & pot. un + pot. nn & pot. un => pot. nn & pot. un + // pot. nn & pot. un + pot. nn & prot. nn => pot. nn & prot. nn + // pot. nn & pot. un + pot. non null => pot. nn & pot. un + // pot. nn & pot. un + pot. null => pot. n & pot. nn + // pot. nn & pot. un + pot. unknown => pot. nn & pot. un + // pot. nn & pot. un + prot. non null => pot. nn & prot. nn + // pot. nn & pot. un + prot. null => pot. n & prot. n + // pot. nn & pot. un + start => pot. nn & pot. un + // pot. nn & prot. nn + def. non null => def. non null + // pot. nn & prot. nn + def. null => def. null + // pot. nn & prot. nn + def. unknown => def. unknown + // pot. nn & prot. nn + pot. n & pot. nn & pot. un => pot. non null // must include n + // pot. nn & prot. nn + pot. n & pot. nn => pot. n & pot. nn + // pot. nn & prot. nn + pot. n & pot. un => pot. n & pot. nn + // pot. nn & prot. nn + pot. n & prot. n => pot. n & prot. n + // pot. nn & prot. nn + pot. nn & pot. un => pot. nn & pot. un + // pot. nn & prot. nn + pot. nn & prot. nn => pot. nn & prot. nn + // pot. nn & prot. nn + pot. non null => pot. nn & prot. nn + // pot. nn & prot. nn + pot. null => pot. n & pot. nn + // pot. nn & prot. nn + pot. unknown => pot. nn & pot. un + // pot. nn & prot. nn + prot. non null => pot. nn & prot. nn + // pot. nn & prot. nn + prot. null => prot. null + // pot. nn & prot. nn + start => pot. nn & prot. nn + // pot. non null + def. non null => def. non null + // pot. non null + def. null => def. null + // pot. non null + def. unknown => def. unknown + // pot. non null + pot. n & pot. nn & pot. un => pot. non null // must include n + // pot. non null + pot. n & pot. nn => pot. n & pot. nn + // pot. non null + pot. n & pot. un => pot. n & pot. nn + // pot. non null + pot. n & prot. n => pot. n & prot. n + // pot. non null + pot. nn & pot. un => pot. nn & pot. un + // pot. non null + pot. nn & prot. nn => pot. nn & prot. nn + // pot. non null + pot. non null => pot. non null + // pot. non null + pot. null => pot. n & pot. nn + // pot. non null + pot. unknown => pot. nn & pot. un + // pot. non null + prot. non null => pot. nn & prot. nn + // pot. non null + prot. null => prot. null + // pot. non null + start => pot. non null + // pot. null + def. non null => def. non null + // pot. null + def. null => def. null + // pot. null + def. unknown => def. unknown + // pot. null + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. null + pot. n & pot. nn => pot. n & pot. nn + // pot. null + pot. n & pot. un => pot. n & pot. un + // pot. null + pot. n & prot. n => pot. n & prot. n + // pot. null + pot. nn & pot. un => pot. n & pot. nn + // pot. null + pot. nn & prot. nn => pot. nn & prot. nn + // pot. null + pot. non null => pot. n & pot. nn + // pot. null + pot. null => pot. null + // pot. null + pot. unknown => pot. n & pot. un + // pot. null + prot. non null => prot. non null + // pot. null + prot. null => pot. n & prot. n + // pot. null + start => pot. null + // pot. unknown + def. non null => def. non null + // pot. unknown + def. null => def. null + // pot. unknown + def. unknown => def. unknown + // pot. unknown + pot. n & pot. nn & pot. un => pot. non null // must include n + // pot. unknown + pot. n & pot. nn => pot. n & pot. nn + // pot. unknown + pot. n & pot. un => pot. n & pot. un + // pot. unknown + pot. n & prot. n => pot. n & prot. n + // pot. unknown + pot. nn & pot. un => pot. nn & pot. un + // pot. unknown + pot. nn & prot. nn => pot. nn & prot. nn + // pot. unknown + pot. non null => pot. nn & pot. un + // pot. unknown + pot. null => pot. n & pot. un + // pot. unknown + pot. unknown => pot. unknown + // pot. unknown + prot. non null => pot. nn & prot. nn + // pot. unknown + prot. null => pot. n & prot. n + // pot. unknown + start => pot. unknown + // prot. non null + def. non null => def. non null + // prot. non null + def. null => def. null + // prot. non null + def. unknown => def. unknown + // prot. non null + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // prot. non null + pot. n & pot. nn => pot. n & pot. nn + // prot. non null + pot. n & pot. un => pot. n & pot. un + // prot. non null + pot. n & prot. n => pot. n & prot. n + // prot. non null + pot. nn & pot. un => pot. nn & pot. un + // prot. non null + pot. nn & prot. nn => pot. nn & prot. nn + // prot. non null + pot. non null => pot. nn & prot. nn + // prot. non null + pot. null => pot. null + // prot. non null + pot. unknown => pot. unknown + // prot. non null + prot. non null => prot. non null + // prot. non null + prot. null => prot. null + // prot. non null + start => prot. non null + // prot. null + def. non null => def. non null + // prot. null + def. null => def. null + // prot. null + def. unknown => def. unknown + // prot. null + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // prot. null + pot. n & pot. nn => pot. n & pot. nn + // prot. null + pot. n & pot. un => pot. n & pot. un + // prot. null + pot. n & prot. n => pot. n & prot. n + // prot. null + pot. nn & pot. un => pot. nn & pot. un + // prot. null + pot. nn & prot. nn => pot. nn & prot. nn + // prot. null + pot. non null => pot. non null + // prot. null + pot. null => pot. n & prot. n + // prot. null + pot. unknown => pot. unknown + // prot. null + prot. non null => prot. non null + // prot. null + prot. null => prot. null + // prot. null + start => prot. null + // start + def. non null => def. non null + // start + def. null => def. null + // start + def. unknown => def. unknown + // start + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // start + pot. n & pot. nn => pot. n & pot. nn + // start + pot. n & pot. un => pot. n & pot. un + // start + pot. n & prot. n => pot. n & prot. n + // start + pot. nn & pot. un => pot. nn & pot. un + // start + pot. nn & prot. nn => pot. nn & prot. nn + // start + pot. non null => pot. non null + // start + pot. null => pot. null + // start + pot. unknown => pot. unknown + // start + prot. non null => prot. non null + // start + prot. null => prot. null + // start + start => start + // addInitializationsFrom DEFINITION END + new ThreeDimensionalTransformation("addInitializationsFrom", + new byte[][] { + // addInitializationsFrom INITIALIZER START + {0x00,0x00,0x00}, + {0x00,0x04,0x04}, + {0x00,0x08,0x08}, + {0x00,0x0C,0x0C}, + {0x00,0x10,0x10}, + {0x00,0x14,0x14}, + {0x00,0x18,0x18}, + {0x00,0x1C,0x1C}, + {0x00,0x24,0x24}, + {0x00,0x28,0x28}, + {0x00,0x2C,0x2C}, + {0x00,0x30,0x30}, + {0x00,0x34,0x34}, + {0x00,0x38,0x38}, + {0x00,0x3C,0x3C}, + {0x04,0x00,0x04}, + {0x04,0x04,0x04}, + {0x04,0x08,0x0C}, + {0x04,0x0C,0x0C}, + {0x04,0x10,0x14}, + {0x04,0x14,0x14}, + {0x04,0x18,0x18}, + {0x04,0x1C,0x08}, + {0x04,0x24,0x24}, + {0x04,0x28,0x28}, + {0x04,0x2C,0x2C}, + {0x04,0x30,0x30}, + {0x04,0x34,0x34}, + {0x04,0x38,0x34}, + {0x04,0x3C,0x2C}, + {0x08,0x00,0x08}, + {0x08,0x04,0x0C}, + {0x08,0x08,0x08}, + {0x08,0x0C,0x0C}, + {0x08,0x10,0x18}, + {0x08,0x14,0x18}, + {0x08,0x18,0x18}, + {0x08,0x1C,0x08}, + {0x08,0x24,0x24}, + {0x08,0x28,0x28}, + {0x08,0x2C,0x2C}, + {0x08,0x30,0x30}, + {0x08,0x34,0x34}, + {0x08,0x38,0x38}, + {0x08,0x3C,0x2C}, + {0x0C,0x00,0x0C}, + {0x0C,0x04,0x0C}, + {0x0C,0x08,0x0C}, + {0x0C,0x0C,0x0C}, + {0x0C,0x10,0x18}, + {0x0C,0x14,0x18}, + {0x0C,0x18,0x18}, + {0x0C,0x1C,0x08}, + {0x0C,0x24,0x24}, + {0x0C,0x28,0x28}, + {0x0C,0x2C,0x2C}, + {0x0C,0x30,0x30}, + {0x0C,0x34,0x34}, + {0x0C,0x38,0x34}, + {0x0C,0x3C,0x2C}, + {0x10,0x00,0x10}, + {0x10,0x04,0x14}, + {0x10,0x08,0x18}, + {0x10,0x0C,0x18}, + {0x10,0x10,0x10}, + {0x10,0x14,0x14}, + {0x10,0x18,0x18}, + {0x10,0x1C,0x18}, + {0x10,0x24,0x24}, + {0x10,0x28,0x28}, + {0x10,0x2C,0x2C}, + {0x10,0x30,0x30}, + {0x10,0x34,0x34}, + {0x10,0x38,0x34}, + {0x10,0x3C,0x3C}, + {0x14,0x00,0x14}, + {0x14,0x04,0x14}, + {0x14,0x08,0x18}, + {0x14,0x0C,0x18}, + {0x14,0x10,0x14}, + {0x14,0x14,0x14}, + {0x14,0x18,0x18}, + {0x14,0x1C,0x18}, + {0x14,0x24,0x24}, + {0x14,0x28,0x28}, + {0x14,0x2C,0x2C}, + {0x14,0x30,0x30}, + {0x14,0x34,0x34}, + {0x14,0x38,0x34}, + {0x14,0x3C,0x2C}, + {0x18,0x00,0x18}, + {0x18,0x04,0x18}, + {0x18,0x08,0x18}, + {0x18,0x0C,0x18}, + {0x18,0x10,0x18}, + {0x18,0x14,0x18}, + {0x18,0x18,0x18}, + {0x18,0x1C,0x18}, + {0x18,0x24,0x24}, + {0x18,0x28,0x28}, + {0x18,0x2C,0x2C}, + {0x18,0x30,0x30}, + {0x18,0x34,0x34}, + {0x18,0x38,0x34}, + {0x18,0x3C,0x2C}, + {0x1C,0x00,0x1C}, + {0x1C,0x04,0x1C}, + {0x1C,0x08,0x1C}, + {0x1C,0x0C,0x1C}, + {0x1C,0x10,0x18}, + {0x1C,0x14,0x18}, + {0x1C,0x18,0x18}, + {0x1C,0x1C,0x18}, + {0x1C,0x24,0x24}, + {0x1C,0x28,0x28}, + {0x1C,0x2C,0x2C}, + {0x1C,0x30,0x30}, + {0x1C,0x34,0x34}, + {0x1C,0x38,0x34}, + {0x1C,0x3C,0x2C}, + {0x24,0x00,0x24}, + {0x24,0x04,0x24}, + {0x24,0x08,0x24}, + {0x24,0x0C,0x24}, + {0x24,0x10,0x14}, + {0x24,0x14,0x14}, + {0x24,0x18,0x18}, + {0x24,0x1C,0x08}, + {0x24,0x24,0x24}, + {0x24,0x28,0x28}, + {0x24,0x2C,0x28}, + {0x24,0x30,0x30}, + {0x24,0x34,0x30}, + {0x24,0x38,0x30}, + {0x24,0x3C,0x28}, + {0x28,0x00,0x28}, + {0x28,0x04,0x24}, + {0x28,0x08,0x28}, + {0x28,0x0C,0x24}, + {0x28,0x10,0x18}, + {0x28,0x14,0x18}, + {0x28,0x18,0x18}, + {0x28,0x1C,0x08}, + {0x28,0x24,0x24}, + {0x28,0x28,0x28}, + {0x28,0x2C,0x28}, + {0x28,0x30,0x30}, + {0x28,0x34,0x34}, + {0x28,0x38,0x38}, + {0x28,0x3C,0x28}, + {0x2C,0x00,0x2C}, + {0x2C,0x04,0x0C}, + {0x2C,0x08,0x2C}, + {0x2C,0x0C,0x0C}, + {0x2C,0x10,0x18}, + {0x2C,0x14,0x18}, + {0x2C,0x18,0x18}, + {0x2C,0x1C,0x08}, + {0x2C,0x24,0x24}, + {0x2C,0x28,0x28}, + {0x2C,0x2C,0x2C}, + {0x2C,0x30,0x30}, + {0x2C,0x34,0x34}, + {0x2C,0x38,0x38}, + {0x2C,0x3C,0x2C}, + {0x30,0x00,0x30}, + {0x30,0x04,0x14}, + {0x30,0x08,0x18}, + {0x30,0x0C,0x18}, + {0x30,0x10,0x30}, + {0x30,0x14,0x14}, + {0x30,0x18,0x18}, + {0x30,0x1C,0x1C}, + {0x30,0x24,0x24}, + {0x30,0x28,0x28}, + {0x30,0x2C,0x2C}, + {0x30,0x30,0x30}, + {0x30,0x34,0x30}, + {0x30,0x38,0x30}, + {0x30,0x3C,0x3C}, + {0x34,0x00,0x34}, + {0x34,0x04,0x14}, + {0x34,0x08,0x18}, + {0x34,0x0C,0x18}, + {0x34,0x10,0x34}, + {0x34,0x14,0x14}, + {0x34,0x18,0x18}, + {0x34,0x1C,0x1C}, + {0x34,0x24,0x24}, + {0x34,0x28,0x28}, + {0x34,0x2C,0x2C}, + {0x34,0x30,0x30}, + {0x34,0x34,0x34}, + {0x34,0x38,0x34}, + {0x34,0x3C,0x3C}, + {0x38,0x00,0x38}, + {0x38,0x04,0x04}, + {0x38,0x08,0x08}, + {0x38,0x0C,0x0C}, + {0x38,0x10,0x34}, + {0x38,0x14,0x14}, + {0x38,0x18,0x18}, + {0x38,0x1C,0x1C}, + {0x38,0x24,0x24}, + {0x38,0x28,0x28}, + {0x38,0x2C,0x2C}, + {0x38,0x30,0x30}, + {0x38,0x34,0x34}, + {0x38,0x38,0x38}, + {0x38,0x3C,0x3C}, + {0x3C,0x00,0x3C}, + {0x3C,0x04,0x04}, + {0x3C,0x08,0x2C}, + {0x3C,0x0C,0x0C}, + {0x3C,0x10,0x10}, + {0x3C,0x14,0x14}, + {0x3C,0x18,0x18}, + {0x3C,0x1C,0x1C}, + {0x3C,0x24,0x24}, + {0x3C,0x28,0x28}, + {0x3C,0x2C,0x2C}, + {0x3C,0x30,0x30}, + {0x3C,0x34,0x34}, + {0x3C,0x38,0x38}, + {0x3C,0x3C,0x3C}, + // addInitializationsFrom INITIALIZER END + }) { + @Override + UnconditionalFlowInfo output(UnconditionalFlowInfo input1, + UnconditionalFlowInfo input2) { + return (UnconditionalFlowInfo) + input1.copy().addInitializationsFrom(input2); + } + }, + // addPotentialInitializationsFrom DEFINITION START + // def. non null + def. non null => def. non null + // def. non null + def. null => pot. n & pot. nn + // def. non null + def. unknown => def. unknown + // def. non null + pot. n & pot. nn & pot. un => pot. n & pot. nn + // def. non null + pot. n & pot. nn => pot. n & pot. nn + // def. non null + pot. n & pot. un => pot. n & pot. nn + // def. non null + pot. n & prot. n => pot. n & pot. nn + // def. non null + pot. nn & pot. un => def. unknown + // def. non null + pot. nn & prot. nn => def. non null + // def. non null + pot. non null => def. non null + // def. non null + pot. null => pot. n & pot. nn + // def. non null + pot. unknown => def. unknown + // def. non null + prot. non null => def. non null + // def. non null + prot. null => def. non null + // def. non null + start => def. non null + // def. null + def. non null => pot. n & pot. nn + // def. null + def. null => def. null + // def. null + def. unknown => pot. n & pot. un + // def. null + pot. n & pot. nn & pot. un => pot. n & pot. nn + // def. null + pot. n & pot. nn => pot. n & pot. nn + // def. null + pot. n & pot. un => pot. n & pot. un + // def. null + pot. n & prot. n => def. null + // def. null + pot. nn & pot. un => pot. n & pot. nn + // def. null + pot. nn & prot. nn => pot. n & pot. nn + // def. null + pot. non null => pot. n & pot. nn + // def. null + pot. null => def. null + // def. null + pot. unknown => pot. n & pot. un + // def. null + prot. non null => def. null + // def. null + prot. null => def. null + // def. null + start => def. null + // def. unknown + def. non null => def. unknown + // def. unknown + def. null => pot. n & pot. un + // def. unknown + def. unknown => def. unknown + // def. unknown + pot. n & pot. nn & pot. un => pot. n & pot. nn // should ideally include un + // def. unknown + pot. n & pot. nn => pot. n & pot. nn + // def. unknown + pot. n & pot. un => pot. n & pot. un + // def. unknown + pot. n & prot. n => pot. n & pot. un + // def. unknown + pot. nn & pot. un => def. unknown + // def. unknown + pot. nn & prot. nn => def. unknown + // def. unknown + pot. non null => def. unknown + // def. unknown + pot. null => pot. n & pot. un + // def. unknown + pot. unknown => def. unknown + // def. unknown + prot. non null => def. unknown + // def. unknown + prot. null => def. unknown + // def. unknown + start => def. unknown + // pot. n & pot. nn & pot. un + def. non null => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + def. null => pot. n & pot. nn + // pot. n & pot. nn & pot. un + def. unknown => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. n & pot. nn & pot. un + pot. n & pot. nn => pot. n & pot. nn + // pot. n & pot. nn & pot. un + pot. n & pot. un => pot. n & pot. nn + // pot. n & pot. nn & pot. un + pot. n & prot. n => pot. n & pot. nn + // pot. n & pot. nn & pot. un + pot. nn & pot. un => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + pot. nn & prot. nn => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + pot. non null => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + pot. null => pot. n & pot. nn + // pot. n & pot. nn & pot. un + pot. unknown => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + prot. non null => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + prot. null => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + start => pot. n & pot. nn & pot. un + // pot. n & pot. nn + def. non null => pot. n & pot. nn + // pot. n & pot. nn + def. null => pot. n & pot. nn + // pot. n & pot. nn + def. unknown => pot. n & pot. nn + // pot. n & pot. nn + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. n & pot. nn + pot. n & pot. nn => pot. n & pot. nn + // pot. n & pot. nn + pot. n & pot. un => pot. n & pot. nn + // pot. n & pot. nn + pot. n & prot. n => pot. n & pot. nn + // pot. n & pot. nn + pot. nn & pot. un => pot. n & pot. nn + // pot. n & pot. nn + pot. nn & prot. nn => pot. n & pot. nn + // pot. n & pot. nn + pot. non null => pot. n & pot. nn + // pot. n & pot. nn + pot. null => pot. n & pot. nn + // pot. n & pot. nn + pot. unknown => pot. n & pot. nn + // pot. n & pot. nn + prot. non null => pot. n & pot. nn + // pot. n & pot. nn + prot. null => pot. n & pot. nn + // pot. n & pot. nn + start => pot. n & pot. nn + // pot. n & pot. un + def. non null => pot. n & pot. nn + // pot. n & pot. un + def. null => pot. n & pot. un + // pot. n & pot. un + def. unknown => pot. n & pot. un + // pot. n & pot. un + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. n & pot. un + pot. n & pot. nn => pot. n & pot. nn + // pot. n & pot. un + pot. n & pot. un => pot. n & pot. un + // pot. n & pot. un + pot. n & prot. n => pot. n & pot. un + // pot. n & pot. un + pot. nn & pot. un => pot. n & pot. nn + // pot. n & pot. un + pot. nn & prot. nn => pot. n & pot. nn + // pot. n & pot. un + pot. non null => pot. n & pot. nn + // pot. n & pot. un + pot. null => pot. n & pot. un + // pot. n & pot. un + pot. unknown => pot. n & pot. un + // pot. n & pot. un + prot. non null => pot. n & pot. un + // pot. n & pot. un + prot. null => pot. n & pot. un + // pot. n & pot. un + start => pot. n & pot. un + // pot. n & prot. n + def. non null => pot. n & pot. nn + // pot. n & prot. n + def. null => pot. n & prot. n + // pot. n & prot. n + def. unknown => pot. n & pot. un + // pot. n & prot. n + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. n & prot. n + pot. n & pot. nn => pot. n & pot. nn + // pot. n & prot. n + pot. n & pot. un => pot. n & pot. un + // pot. n & prot. n + pot. n & prot. n => pot. n & prot. n + // pot. n & prot. n + pot. nn & pot. un => pot. n & pot. nn + // pot. n & prot. n + pot. nn & prot. nn => pot. n & pot. nn + // pot. n & prot. n + pot. non null => pot. n & pot. nn + // pot. n & prot. n + pot. null => pot. n & prot. n + // pot. n & prot. n + pot. unknown => pot. n & pot. un + // pot. n & prot. n + prot. non null => pot. n & prot. n + // pot. n & prot. n + prot. null => pot. n & prot. n + // pot. n & prot. n + start => pot. n & prot. n + // pot. nn & pot. un + def. non null => pot. nn & pot. un + // pot. nn & pot. un + def. null => pot. n & pot. nn + // pot. nn & pot. un + def. unknown => pot. nn & pot. un + // pot. nn & pot. un + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. nn & pot. un + pot. n & pot. nn => pot. n & pot. nn + // pot. nn & pot. un + pot. n & pot. un => pot. n & pot. nn + // pot. nn & pot. un + pot. n & prot. n => pot. n & pot. nn + // pot. nn & pot. un + pot. nn & pot. un => pot. nn & pot. un + // pot. nn & pot. un + pot. nn & prot. nn => pot. nn & pot. un + // pot. nn & pot. un + pot. non null => pot. nn & pot. un + // pot. nn & pot. un + pot. null => pot. n & pot. nn + // pot. nn & pot. un + pot. unknown => pot. nn & pot. un + // pot. nn & pot. un + prot. non null => pot. nn & pot. un + // pot. nn & pot. un + prot. null => pot. nn & pot. un + // pot. nn & pot. un + start => pot. nn & pot. un + // pot. nn & prot. nn + def. non null => pot. nn & prot. nn + // pot. nn & prot. nn + def. null => pot. n & pot. nn + // pot. nn & prot. nn + def. unknown => pot. nn & pot. un + // pot. nn & prot. nn + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. nn & prot. nn + pot. n & pot. nn => pot. n & pot. nn + // pot. nn & prot. nn + pot. n & pot. un => pot. n & pot. nn + // pot. nn & prot. nn + pot. n & prot. n => pot. n & pot. nn + // pot. nn & prot. nn + pot. nn & pot. un => pot. nn & pot. un // see test1501 + // pot. nn & prot. nn + pot. nn & prot. nn => pot. nn & prot. nn + // pot. nn & prot. nn + pot. non null => pot. nn & prot. nn + // pot. nn & prot. nn + pot. null => pot. n & pot. nn + // pot. nn & prot. nn + pot. unknown => pot. nn & pot. un + // pot. nn & prot. nn + prot. non null => pot. nn & prot. nn + // pot. nn & prot. nn + prot. null => pot. nn & prot. nn + // pot. nn & prot. nn + start => pot. nn & prot. nn + // pot. non null + def. non null => pot. non null + // pot. non null + def. null => pot. n & pot. nn + // pot. non null + def. unknown => pot. nn & pot. un + // pot. non null + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. non null + pot. n & pot. nn => pot. n & pot. nn + // pot. non null + pot. n & pot. un => pot. n & pot. nn + // pot. non null + pot. n & prot. n => pot. n & pot. nn + // pot. non null + pot. nn & pot. un => pot. nn & pot. un + // pot. non null + pot. nn & prot. nn => pot. non null + // pot. non null + pot. non null => pot. non null + // pot. non null + pot. null => pot. n & pot. nn + // pot. non null + pot. unknown => pot. nn & pot. un + // pot. non null + prot. non null => pot. non null + // pot. non null + prot. null => pot. non null + // pot. non null + start => pot. non null + // pot. null + def. non null => pot. n & pot. nn + // pot. null + def. null => pot. null + // pot. null + def. unknown => pot. n & pot. un + // pot. null + pot. n & pot. nn & pot. un => pot. n & pot. nn + // pot. null + pot. n & pot. nn => pot. n & pot. nn + // pot. null + pot. n & pot. un => pot. n & pot. un + // pot. null + pot. n & prot. n => pot. null + // pot. null + pot. nn & pot. un => pot. n & pot. nn + // pot. null + pot. nn & prot. nn => pot. n & pot. nn + // pot. null + pot. non null => pot. n & pot. nn + // pot. null + pot. null => pot. null + // pot. null + pot. unknown => pot. n & pot. un + // pot. null + prot. non null => pot. null + // pot. null + prot. null => pot. null + // pot. null + start => pot. null + // pot. unknown + def. non null => pot. nn & pot. un + // pot. unknown + def. null => pot. n & pot. un + // pot. unknown + def. unknown => pot. unknown + // pot. unknown + pot. n & pot. nn & pot. un => pot. n & pot. nn // should ideally include un + // pot. unknown + pot. n & pot. nn => pot. n & pot. nn + // pot. unknown + pot. n & pot. un => pot. n & pot. un + // pot. unknown + pot. n & prot. n => pot. n & pot. un + // pot. unknown + pot. nn & pot. un => pot. nn & pot. un + // pot. unknown + pot. nn & prot. nn => pot. nn & pot. un + // pot. unknown + pot. non null => pot. nn & pot. un + // pot. unknown + pot. null => pot. n & pot. un + // pot. unknown + pot. unknown => pot. unknown + // pot. unknown + prot. non null => pot. unknown + // pot. unknown + prot. null => pot. unknown + // pot. unknown + start => pot. unknown + // prot. non null + def. non null => pot. nn & prot. nn + // prot. non null + def. null => pot. null + // prot. non null + def. unknown => pot. unknown + // prot. non null + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // prot. non null + pot. n & pot. nn => pot. n & pot. nn + // prot. non null + pot. n & pot. un => pot. n & pot. un + // prot. non null + pot. n & prot. n => pot. null + // prot. non null + pot. nn & pot. un => pot. nn & pot. un // see test1500 + // prot. non null + pot. nn & prot. nn => pot. nn & prot. nn + // prot. non null + pot. non null => pot. nn & prot. nn + // prot. non null + pot. null => pot. null + // prot. non null + pot. unknown => pot. unknown + // prot. non null + prot. non null => prot. non null + // prot. non null + prot. null => prot. non null + // prot. non null + start => prot. non null + // prot. null + def. non null => pot. non null + // prot. null + def. null => pot. n & prot. n + // prot. null + def. unknown => pot. unknown + // prot. null + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // prot. null + pot. n & pot. nn => pot. n & pot. nn + // prot. null + pot. n & pot. un => pot. n & pot. un + // prot. null + pot. n & prot. n => pot. n & prot. n + // prot. null + pot. nn & pot. un => pot. nn & pot. un + // prot. null + pot. nn & prot. nn => pot. non null + // prot. null + pot. non null => pot. non null + // prot. null + pot. null => pot. n & prot. n + // prot. null + pot. unknown => pot. unknown + // prot. null + prot. non null => prot. null + // prot. null + prot. null => prot. null + // prot. null + start => prot. null + // start + def. non null => pot. non null + // start + def. null => pot. null + // start + def. unknown => pot. unknown + // start + pot. n & pot. nn & pot. un => pot. n & pot. nn // un? + // start + pot. n & pot. nn => pot. n & pot. nn + // start + pot. n & pot. un => pot. n & pot. un + // start + pot. n & prot. n => pot. null + // start + pot. nn & pot. un => pot. nn & pot. un + // start + pot. nn & prot. nn => pot. non null + // start + pot. non null => pot. non null + // start + pot. null => pot. null + // start + pot. unknown => pot. unknown + // start + prot. non null => start // PREMATURE may need to be tainted? + // start + prot. null => start // PREMATURE may need to be tainted? + // start + start => start + // addPotentialInitializationsFrom DEFINITION END + addPotentialInitializationsFrom = + new ThreeDimensionalTransformation("addPotentialInitializationsFrom", + new byte[][] { + // addPotentialInitializationsFrom INITIALIZER START + {0x00,0x00,0x00}, + {0x00,0x04,0x04}, + {0x00,0x08,0x08}, + {0x00,0x0C,0x0C}, + {0x00,0x10,0x10}, + {0x00,0x14,0x14}, + {0x00,0x18,0x18}, + {0x00,0x1C,0x18}, + {0x00,0x24,0x04}, + {0x00,0x28,0x08}, + {0x00,0x2C,0x08}, + {0x00,0x30,0x10}, + {0x00,0x34,0x10}, + {0x00,0x38,0x00}, + {0x00,0x3C,0x00}, + {0x04,0x00,0x04}, + {0x04,0x04,0x04}, + {0x04,0x08,0x0C}, + {0x04,0x0C,0x0C}, + {0x04,0x10,0x14}, + {0x04,0x14,0x14}, + {0x04,0x18,0x18}, + {0x04,0x1C,0x18}, + {0x04,0x24,0x04}, + {0x04,0x28,0x0C}, + {0x04,0x2C,0x0C}, + {0x04,0x30,0x14}, + {0x04,0x34,0x14}, + {0x04,0x38,0x04}, + {0x04,0x3C,0x04}, + {0x08,0x00,0x08}, + {0x08,0x04,0x0C}, + {0x08,0x08,0x08}, + {0x08,0x0C,0x0C}, + {0x08,0x10,0x18}, + {0x08,0x14,0x18}, + {0x08,0x18,0x18}, + {0x08,0x1C,0x18}, + {0x08,0x24,0x0C}, + {0x08,0x28,0x08}, + {0x08,0x2C,0x08}, + {0x08,0x30,0x18}, + {0x08,0x34,0x18}, + {0x08,0x38,0x08}, + {0x08,0x3C,0x08}, + {0x0C,0x00,0x0C}, + {0x0C,0x04,0x0C}, + {0x0C,0x08,0x0C}, + {0x0C,0x0C,0x0C}, + {0x0C,0x10,0x18}, + {0x0C,0x14,0x18}, + {0x0C,0x18,0x18}, + {0x0C,0x1C,0x18}, + {0x0C,0x24,0x0C}, + {0x0C,0x28,0x0C}, + {0x0C,0x2C,0x0C}, + {0x0C,0x30,0x18}, + {0x0C,0x34,0x18}, + {0x0C,0x38,0x0C}, + {0x0C,0x3C,0x0C}, + {0x10,0x00,0x10}, + {0x10,0x04,0x14}, + {0x10,0x08,0x18}, + {0x10,0x0C,0x18}, + {0x10,0x10,0x10}, + {0x10,0x14,0x14}, + {0x10,0x18,0x18}, + {0x10,0x1C,0x18}, + {0x10,0x24,0x14}, + {0x10,0x28,0x18}, + {0x10,0x2C,0x18}, + {0x10,0x30,0x10}, + {0x10,0x34,0x10}, + {0x10,0x38,0x10}, + {0x10,0x3C,0x10}, + {0x14,0x00,0x14}, + {0x14,0x04,0x14}, + {0x14,0x08,0x18}, + {0x14,0x0C,0x18}, + {0x14,0x10,0x14}, + {0x14,0x14,0x14}, + {0x14,0x18,0x18}, + {0x14,0x1C,0x18}, + {0x14,0x24,0x14}, + {0x14,0x28,0x18}, + {0x14,0x2C,0x18}, + {0x14,0x30,0x14}, + {0x14,0x34,0x14}, + {0x14,0x38,0x14}, + {0x14,0x3C,0x14}, + {0x18,0x00,0x18}, + {0x18,0x04,0x18}, + {0x18,0x08,0x18}, + {0x18,0x0C,0x18}, + {0x18,0x10,0x18}, + {0x18,0x14,0x18}, + {0x18,0x18,0x18}, + {0x18,0x1C,0x18}, + {0x18,0x24,0x18}, + {0x18,0x28,0x18}, + {0x18,0x2C,0x18}, + {0x18,0x30,0x18}, + {0x18,0x34,0x18}, + {0x18,0x38,0x18}, + {0x18,0x3C,0x18}, + {0x1C,0x00,0x1C}, + {0x1C,0x04,0x1C}, + {0x1C,0x08,0x1C}, + {0x1C,0x0C,0x1C}, + {0x1C,0x10,0x18}, + {0x1C,0x14,0x18}, + {0x1C,0x18,0x18}, + {0x1C,0x1C,0x18}, + {0x1C,0x24,0x1C}, + {0x1C,0x28,0x1C}, + {0x1C,0x2C,0x1C}, + {0x1C,0x30,0x18}, + {0x1C,0x34,0x18}, + {0x1C,0x38,0x1C}, + {0x1C,0x3C,0x1C}, + {0x24,0x00,0x24}, + {0x24,0x04,0x24}, + {0x24,0x08,0x24}, + {0x24,0x0C,0x24}, + {0x24,0x10,0x14}, + {0x24,0x14,0x14}, + {0x24,0x18,0x18}, + {0x24,0x1C,0x18}, + {0x24,0x24,0x24}, + {0x24,0x28,0x24}, + {0x24,0x2C,0x24}, + {0x24,0x30,0x14}, + {0x24,0x34,0x14}, + {0x24,0x38,0x24}, + {0x24,0x3C,0x24}, + {0x28,0x00,0x28}, + {0x28,0x04,0x24}, + {0x28,0x08,0x28}, + {0x28,0x0C,0x24}, + {0x28,0x10,0x18}, + {0x28,0x14,0x18}, + {0x28,0x18,0x18}, + {0x28,0x1C,0x18}, + {0x28,0x24,0x24}, + {0x28,0x28,0x28}, + {0x28,0x2C,0x28}, + {0x28,0x30,0x18}, + {0x28,0x34,0x18}, + {0x28,0x38,0x28}, + {0x28,0x3C,0x28}, + {0x2C,0x00,0x2C}, + {0x2C,0x04,0x0C}, + {0x2C,0x08,0x2C}, + {0x2C,0x0C,0x0C}, + {0x2C,0x10,0x18}, + {0x2C,0x14,0x18}, + {0x2C,0x18,0x18}, + {0x2C,0x1C,0x18}, + {0x2C,0x24,0x0C}, + {0x2C,0x28,0x2C}, + {0x2C,0x2C,0x2C}, + {0x2C,0x30,0x18}, + {0x2C,0x34,0x18}, + {0x2C,0x38,0x2C}, + {0x2C,0x3C,0x2C}, + {0x30,0x00,0x30}, + {0x30,0x04,0x14}, + {0x30,0x08,0x18}, + {0x30,0x0C,0x18}, + {0x30,0x10,0x30}, + {0x30,0x14,0x14}, + {0x30,0x18,0x18}, + {0x30,0x1C,0x18}, + {0x30,0x24,0x14}, + {0x30,0x28,0x18}, + {0x30,0x2C,0x18}, + {0x30,0x30,0x30}, + {0x30,0x34,0x30}, + {0x30,0x38,0x30}, + {0x30,0x3C,0x30}, + {0x34,0x00,0x34}, + {0x34,0x04,0x14}, + {0x34,0x08,0x18}, + {0x34,0x0C,0x18}, + {0x34,0x10,0x34}, + {0x34,0x14,0x14}, + {0x34,0x18,0x18}, + {0x34,0x1C,0x18}, + {0x34,0x24,0x14}, + {0x34,0x28,0x18}, + {0x34,0x2C,0x18}, + {0x34,0x30,0x34}, + {0x34,0x34,0x34}, + {0x34,0x38,0x34}, + {0x34,0x3C,0x34}, + {0x38,0x00,0x38}, + {0x38,0x04,0x04}, + {0x38,0x08,0x08}, + {0x38,0x0C,0x0C}, + {0x38,0x10,0x34}, + {0x38,0x14,0x14}, + {0x38,0x18,0x18}, + {0x38,0x1C,0x1C}, + {0x38,0x24,0x04}, + {0x38,0x28,0x08}, + {0x38,0x2C,0x08}, + {0x38,0x30,0x34}, + {0x38,0x34,0x34}, + {0x38,0x38,0x38}, + {0x38,0x3C,0x38}, + {0x3C,0x00,0x3C}, + {0x3C,0x04,0x04}, + {0x3C,0x08,0x2C}, + {0x3C,0x0C,0x0C}, + {0x3C,0x10,0x10}, + {0x3C,0x14,0x14}, + {0x3C,0x18,0x18}, + {0x3C,0x1C,0x1C}, + {0x3C,0x24,0x04}, + {0x3C,0x28,0x2C}, + {0x3C,0x2C,0x2C}, + {0x3C,0x30,0x10}, + {0x3C,0x34,0x10}, + {0x3C,0x38,0x3C}, + {0x3C,0x3C,0x3C}, + // addPotentialInitializationsFrom INITIALIZER END + }) { + @Override + UnconditionalFlowInfo output(UnconditionalFlowInfo input1, + UnconditionalFlowInfo input2) { + return (UnconditionalFlowInfo) + input1.copy().addPotentialInitializationsFrom(input2); + } + }, + mergedWith = + // mergedWith DEFINITION START + // def. non null + def. non null => def. non null + // def. non null + def. null => pot. n & pot. nn + // def. non null + pot. n & prot. n => pot. n & pot. nn + // def. non null + pot. nn & prot. nn => pot. nn & prot. nn + // def. non null + prot. non null => pot. nn & prot. nn + // def. non null + prot. null => pot. non null // PREMATURE should become tainted null & pot. nn... not really, depends on the three way merge... or even on the conditions that got there (pb with no contrib prot. null branch) + // def. null + def. null => def. null + // def. null + pot. n & prot. n => pot. n & prot. n + // def. null + prot. non null => pot. null + // def. null + prot. null => pot. n & prot. n + // def. unknown + def. non null => pot. nn & pot. un + // def. unknown + def. null => pot. n & pot. un // pot. n priv. over def. unknown + // def. unknown + def. unknown => def. unknown + // def. unknown + pot. n & prot. n => pot. n & pot. un + // def. unknown + pot. nn & prot. nn => pot. nn & pot. un + // def. unknown + prot. non null => def. unknown // test726 + // def. unknown + prot. null => pot. unknown // PREMATURE possibly wrong, but no test case yet + // pot. n & pot. nn & pot. un + def. non null => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + def. null => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + def. unknown => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + pot. n & prot. n => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + pot. nn & prot. nn => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + prot. non null => pot. n & pot. nn & pot. un + // pot. n & pot. nn & pot. un + prot. null => pot. n & pot. nn & pot. un + // pot. n & pot. nn + def. non null => pot. n & pot. nn + // pot. n & pot. nn + def. null => pot. n & pot. nn + // pot. n & pot. nn + def. unknown => pot. n & pot. nn + // pot. n & pot. nn + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // pot. n & pot. nn + pot. n & pot. nn => pot. n & pot. nn + // pot. n & pot. nn + pot. n & prot. n => pot. n & pot. nn + // pot. n & pot. nn + pot. nn & prot. nn => pot. n & pot. nn + // pot. n & pot. nn + prot. non null => pot. n & pot. nn + // pot. n & pot. nn + prot. null => pot. n & pot. nn + // pot. n & pot. un + def. non null => pot. n & pot. nn + // pot. n & pot. un + def. null => pot. n & pot. un + // pot. n & pot. un + def. unknown => pot. n & pot. un + // pot. n & pot. un + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // pot. n & pot. un + pot. n & pot. nn => pot. n & pot. nn + // pot. n & pot. un + pot. n & pot. un => pot. n & pot. un + // pot. n & pot. un + pot. n & prot. n => pot. n & pot. un + // pot. n & pot. un + pot. nn & prot. nn => pot. n & pot. nn + // pot. n & pot. un + prot. non null => pot. n & pot. un + // pot. n & pot. un + prot. null => pot. n & pot. un + // pot. n & prot. n + pot. n & prot. n => pot. n & prot. n + // pot. n & prot. n + prot. non null => pot. null + // pot. n & prot. n + prot. null => pot. n & prot. n + // pot. nn & pot. un + def. non null => pot. nn & pot. un + // pot. nn & pot. un + def. null => pot. n & pot. nn + // pot. nn & pot. un + def. unknown => pot. nn & pot. un + // pot. nn & pot. un + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // pot. nn & pot. un + pot. n & pot. nn => pot. n & pot. nn + // pot. nn & pot. un + pot. n & pot. un => pot. n & pot. nn + // pot. nn & pot. un + pot. n & prot. n => pot. n & pot. nn + // pot. nn & pot. un + pot. nn & pot. un => pot. nn & pot. un + // pot. nn & pot. un + pot. nn & prot. nn => pot. nn & pot. un + // pot. nn & pot. un + pot. null => pot. n & pot. nn + // pot. nn & pot. un + prot. non null => pot. nn & pot. un + // pot. nn & pot. un + prot. null => pot. n & pot. nn + // pot. nn & prot. nn + def. null => pot. n & pot. nn + // pot. nn & prot. nn + pot. n & prot. n => pot. n & pot. nn + // pot. nn & prot. nn + pot. nn & prot. nn => pot. nn & prot. nn + // pot. nn & prot. nn + prot. non null => pot. nn & prot. nn + // pot. nn & prot. nn + prot. null => pot. n & pot. nn + // pot. non null + def. non null => pot. non null + // pot. non null + def. null => pot. n & pot. nn + // pot. non null + def. unknown => pot. nn & pot. un + // pot. non null + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // pot. non null + pot. n & pot. nn => pot. n & pot. nn + // pot. non null + pot. n & pot. un => pot. n & pot. nn + // pot. non null + pot. n & prot. n => pot. n & pot. nn + // pot. non null + pot. nn & pot. un => pot. nn & pot. un + // pot. non null + pot. nn & prot. nn => pot. non null + // pot. non null + pot. non null => pot. non null + // pot. non null + pot. null => pot. n & pot. nn + // pot. non null + prot. non null => pot. non null + // pot. non null + prot. null => pot. n & pot. nn + // pot. null + def. non null => pot. n & pot. nn + // pot. null + def. null => pot. null + // pot. null + def. unknown => pot. n & pot. un + // pot. null + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // pot. null + pot. n & pot. nn => pot. n & pot. nn + // pot. null + pot. n & pot. un => pot. n & pot. un + // pot. null + pot. n & prot. n => pot. null + // pot. null + pot. nn & prot. nn => pot. n & pot. nn + // pot. null + pot. null => pot. null + // pot. null + prot. non null => pot. null + // pot. null + prot. null => pot. null + // pot. unknown + def. non null => pot. nn & pot. un + // pot. unknown + def. null => pot. n & pot. un + // pot. unknown + def. unknown => pot. unknown + // pot. unknown + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // pot. unknown + pot. n & pot. nn => pot. n & pot. nn + // pot. unknown + pot. n & pot. un => pot. n & pot. un + // pot. unknown + pot. n & prot. n => pot. n & pot. un + // pot. unknown + pot. nn & pot. un => pot. nn & pot. un + // pot. unknown + pot. nn & prot. nn => pot. nn & pot. un + // pot. unknown + pot. non null => pot. nn & pot. un + // pot. unknown + pot. null => pot. n & pot. un + // pot. unknown + pot. unknown => pot. unknown + // pot. unknown + prot. non null => pot. unknown + // pot. unknown + prot. null => pot. unknown // PREMATURE possibly wrong, but no test case yet + // prot. non null + prot. non null => prot. non null + // prot. null + prot. non null => pot. null // PREMATURE use tainted instead + // prot. null + prot. null => prot. null + // start + def. non null => pot. non null + // start + def. null => pot. null + // start + def. unknown => pot. unknown + // start + pot. n & pot. nn & pot. un => pot. n & pot. nn & pot. un + // start + pot. n & pot. nn => pot. n & pot. nn + // start + pot. n & pot. un => pot. n & pot. un + // start + pot. n & prot. n => pot. null + // start + pot. nn & pot. un => pot. nn & pot. un + // start + pot. nn & prot. nn => pot. non null + // start + pot. non null => pot. non null + // start + pot. null => pot. null + // start + pot. unknown => pot. unknown + // start + prot. non null => start // PREMATURE should it taint? + // start + prot. null => start + // start + start => start + // mergedWith DEFINITION END + new SymmetricalThreeDimensionalTransformation("mergedWith", + new byte[][] { + // mergedWith INITIALIZER START + {0x00,0x00,0x00}, + {0x00,0x04,0x04}, + {0x00,0x08,0x08}, + {0x00,0x0C,0x0C}, + {0x00,0x10,0x10}, + {0x00,0x14,0x14}, + {0x00,0x18,0x18}, + {0x00,0x1C,0x1C}, + {0x00,0x24,0x04}, + {0x00,0x28,0x08}, + {0x00,0x2C,0x08}, + {0x00,0x30,0x10}, + {0x00,0x34,0x10}, + {0x00,0x38,0x00}, + {0x00,0x3C,0x00}, + {0x04,0x04,0x04}, + {0x04,0x08,0x0C}, + {0x04,0x0C,0x0C}, + {0x04,0x10,0x14}, + {0x04,0x14,0x14}, + {0x04,0x18,0x18}, + {0x04,0x1C,0x1C}, + {0x04,0x24,0x04}, + {0x04,0x28,0x0C}, + {0x04,0x2C,0x0C}, + {0x04,0x30,0x14}, + {0x04,0x34,0x14}, + {0x04,0x38,0x04}, + {0x04,0x3C,0x04}, + {0x08,0x08,0x08}, + {0x08,0x0C,0x0C}, + {0x08,0x10,0x18}, + {0x08,0x14,0x18}, + {0x08,0x18,0x18}, + {0x08,0x1C,0x1C}, + {0x08,0x24,0x0C}, + {0x08,0x28,0x08}, + {0x08,0x2C,0x08}, + {0x08,0x30,0x18}, + {0x08,0x34,0x18}, + {0x08,0x38,0x18}, + {0x08,0x3C,0x08}, + {0x0C,0x0C,0x0C}, + {0x0C,0x10,0x18}, + {0x0C,0x14,0x18}, + {0x0C,0x18,0x18}, + {0x0C,0x1C,0x1C}, + {0x0C,0x24,0x0C}, + {0x0C,0x28,0x0C}, + {0x0C,0x2C,0x0C}, + {0x0C,0x30,0x18}, + {0x0C,0x34,0x18}, + {0x0C,0x38,0x18}, + {0x0C,0x3C,0x0C}, + {0x10,0x10,0x10}, + {0x10,0x14,0x14}, + {0x10,0x18,0x18}, + {0x10,0x1C,0x1C}, + {0x10,0x24,0x14}, + {0x10,0x28,0x18}, + {0x10,0x2C,0x18}, + {0x10,0x30,0x10}, + {0x10,0x34,0x10}, + {0x10,0x38,0x10}, + {0x10,0x3C,0x10}, + {0x14,0x14,0x14}, + {0x14,0x18,0x18}, + {0x14,0x1C,0x1C}, + {0x14,0x24,0x14}, + {0x14,0x28,0x18}, + {0x14,0x2C,0x18}, + {0x14,0x30,0x14}, + {0x14,0x34,0x14}, + {0x14,0x38,0x14}, + {0x14,0x3C,0x14}, + {0x18,0x18,0x18}, + {0x18,0x1C,0x1C}, + {0x18,0x24,0x18}, + {0x18,0x28,0x18}, + {0x18,0x2C,0x18}, + {0x18,0x30,0x18}, + {0x18,0x34,0x18}, + {0x18,0x38,0x18}, + {0x18,0x3C,0x18}, + {0x1C,0x1C,0x1C}, + {0x1C,0x24,0x1C}, + {0x1C,0x28,0x1C}, + {0x1C,0x2C,0x1C}, + {0x1C,0x30,0x1C}, + {0x1C,0x34,0x1C}, + {0x1C,0x38,0x1C}, + {0x1C,0x3C,0x1C}, + {0x24,0x24,0x24}, + {0x24,0x28,0x0C}, + {0x24,0x2C,0x0C}, + {0x24,0x30,0x14}, + {0x24,0x34,0x14}, + {0x24,0x38,0x04}, + {0x24,0x3C,0x24}, + {0x28,0x28,0x28}, + {0x28,0x2C,0x2C}, + {0x28,0x30,0x18}, + {0x28,0x34,0x18}, + {0x28,0x38,0x08}, + {0x28,0x3C,0x2C}, + {0x2C,0x2C,0x2C}, + {0x2C,0x30,0x18}, + {0x2C,0x34,0x18}, + {0x2C,0x38,0x18}, + {0x2C,0x3C,0x2C}, + {0x30,0x30,0x30}, + {0x30,0x34,0x34}, + {0x30,0x38,0x34}, + {0x30,0x3C,0x10}, + {0x34,0x34,0x34}, + {0x34,0x38,0x34}, + {0x34,0x3C,0x10}, + {0x38,0x38,0x38}, + {0x38,0x3C,0x10}, + {0x3C,0x3C,0x3C}, + // mergedWith INITIALIZER END + }) { + @Override + UnconditionalFlowInfo output(UnconditionalFlowInfo input1, + UnconditionalFlowInfo input2) { + return input1.copy().mergedWith(input2); + } + }; + public static final Transformation[] transformations = { + markAsComparedEqualToNonNull, + markAsComparedEqualToNull, + markAsDefinitelyNonNull, + markAsDefinitelyNull, + markAsDefinitelyUnknown, + addInitializationsFrom, + addPotentialInitializationsFrom, + mergedWith + }; +public abstract static class Transformation { + public String name; + String definitionStartMarker, definitionEndMarker, + initializerStartMarker, initializerEndMarker; + int dimension; + public Map initializedTransitions, computedTransitions; + // PREMATURE limit public access + int failuresNb; // transient +// PREMATURE complete the test coverage for NullInfoRegistry (need to consider several classes +// of transitions so as to avoid considering NullInfoRegistry states and +// UnconditionalFlowInfo states into the same pool; moreover, cross classes +// transformations exist. +Transformation(String name) { + this.name = name; + this.definitionStartMarker = "// " + name + " " + CodeAnalysis.definitionStartMarker; + this.definitionEndMarker = "// " + name + " " + CodeAnalysis.definitionEndMarker; + this.initializerStartMarker = "// " + name + " " + CodeAnalysis.initializerStartMarker; + this.initializerEndMarker = "// " + name + " " + CodeAnalysis.initializerEndMarker; +} +abstract State[] computeOutputs(State[] inputs); +abstract void hydrate(); +void fail() { + if (this.failuresNb == 0) { + System.out.println(this.name + " failures: "); + } + this.failuresNb++; +} +abstract void printTruthTables(File outputDirectory); + +static boolean checkContiguity(String a, String b) { + int aLength; + if ((aLength = a.length()) != b.length()) { + System.out.println("inappropriate string length: " + a + " vs " + b); + return false; + } + int status = 0; + for (int i = 0; i < aLength; i++) { + if (a.charAt(i) != b.charAt(i)) { + status++; + } + } + if (status != 1) { + System.out.println("non contiguous strings: " + a + " vs " + b); + return false; + } + return true; +} + +final static String truthTableRowNames[] = { // need a specific order to yield simplication opportunities + "000000", + "000100", + "001100", + "001000", + "011000", + "011100", + "010100", + "010000", + "110000", + "110100", + "111100", + "111000", + "101000", + "101100", + "100100", + "100000", + // PREMATURE cheated to group first four bits... reconsider + "000001", + "000011", + "000010", + "000110", + "000111", + "000101", + "001101", + "001111", + "001110", + "001010", + "001011", + "001001", + "011001", + "011011", + "011010", + "011110", + "011111", + "011101", + "010101", + "010111", + "010110", + "010010", + "010011", + "010001", + "110001", + "110011", + "110010", + "110110", + "110111", + "110101", + "111101", + "111111", + "111110", + "111010", + "111011", + "111001", + "101001", + "101011", + "101010", + "101110", + "101111", + "101101", + "100101", + "100111", + "100110", + "100010", + "100011", + "100001", + }; + +private static Map ranksForStates; +int rankForState(State state) { + int length; + if (ranksForStates == null) { + ranksForStates = new HashMap(length = truthTableRowNames.length); + for (int i = 0; i < length; i++) { + ranksForStates.put(truthTableRowNames[i], Integer.valueOf(i)); + } + } + Integer rank; + if ((rank = (Integer) ranksForStates.get(state.printableBitsField)) != null) { + return rank.intValue(); + } + return 0; +} + +abstract void reinitializeFromComments(BufferedReader input, BufferedWriter output); +abstract void reinitializeFromComputedValues(BufferedReader input, BufferedWriter output, + State[] consideredStates); +/** + * Run a test against UnconditionalFlowInfo by comparing the transitions as memorized + * into the initializer and as delivered by UnconditionalFlowInfo for various positions + * in the encoding and return the number of failures. + * @return the number of failures, that is 0 if the results match the expectations + */ +abstract int test(); +} +abstract static class TwoDimensionalTransformation extends Transformation { +TwoDimensionalTransformation(String name, byte[][] transitions) { + super(name); + this.dimension = 2; + int length; + this.initializedTransitions = new HashMap(length = transitions.length); + State input1; + for (int i = 0; i < length; i++) { + if (transitions[i].length != 2) { + throw new IllegalArgumentException("transitions should have two entries"); + } + input1 = State.states[transitions[i][0]]; // array out of bounds exception if broken + if (this.initializedTransitions.get(input1) != null) { + throw new IllegalArgumentException("duplicate entry"); + } + this.initializedTransitions.put(input1, State.states[transitions[i][1]]); + } +} +@Override +State[] computeOutputs(State[] inputs) { + Map resultAccumulator = new HashMap(State.stateMaxValue + 1); + hydrate(); // pre-compute all possible combinations, then cache them + for (int i = 0, inputsLength = inputs.length; i < inputsLength; i++) { + resultAccumulator.put(this.computedTransitions.get(inputs[i]), null); + } + int length; + State[] result = new State[length = resultAccumulator.size()]; + Iterator resultIterator = resultAccumulator.keySet().iterator(); + for (int j = 0; j < length; j++) { + result[j] = (State) resultIterator.next(); + } + return result; +} +@Override +void hydrate() { + if (this.computedTransitions == null) { + State input, output; + this.computedTransitions = new HashMap(State.stateMaxValue + 1); + for (int i = 0, length = State.states.length; i < length; i++) { + output = ((UnconditionalFlowInfoTestHarness) + output(UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input = State.states[i]), + TestLocalVariableBinding.local0)).asState(); + if (input.symbolic && !output.symbolic) { + System.err.println(this.name + " generates non-symbolic state " + + output + " upon entry: " + input); + } + this.computedTransitions.put(input, output); + } + } +} +abstract UnconditionalFlowInfo output(UnconditionalFlowInfo input, TestLocalVariableBinding local); + +@Override +void printTruthTables(File outputDirectory) { + try { + String outputFileName = outputDirectory.getPath() + File.separator + this.name + ".txt"; + PrintWriter out = new PrintWriter(new FileOutputStream( + new File(outputFileName))); + System.out.println("Printing " + outputFileName); + out.println("======================================================"); + out.println("Truth table for " + this.name ); + char truthValues[][] = new char[State.statesNb][State.stateWidth]; + int row, column; + for (row = 0; row < State.statesNb; row++) { + for (column = 0; column < State.stateWidth; column++) { + truthValues[row][column] = '.'; + } + } + boolean keepRow[] = new boolean[State.statesNb]; + Iterator i1 = this.initializedTransitions.entrySet().iterator(); + while (i1.hasNext()) { + Map.Entry transitionsSet = (Map.Entry) i1.next(); + State input = (State) transitionsSet.getKey(); + keepRow[row = rankForState(input)] = true; + for (int bit = 0; bit < State.stateWidth; bit++) { + truthValues[row][bit] = + ((State) transitionsSet.getValue()).printableBitsField.charAt(bit); + } + } + StringBuffer line; + line = new StringBuffer(140); + line.append(" "); + for (int i = 1; i <= State.stateWidth; i++) { + line.append(i); + line.append(' '); + } + out.println(line); + line = new StringBuffer(140); + line.append(" ---------------------"); + out.println(line); + for (row = 0; row < State.statesNb; row++) { + if (keepRow[row]) { + line = new StringBuffer(140); + line.append(truthTableRowNames[row]); + line.append(" | "); + for (int i = 0; i < State.stateWidth; i++) { + line.append(truthValues[row][i]); + line.append(' '); + } + out.println(line); + } + } + out.println("======================================================"); + out.flush(); + out.close(); + } + catch (Throwable t) { + // PREMATURE improve error handling + } +} + +@Override +void reinitializeFromComments(BufferedReader input, BufferedWriter output) { + String line, tab = ""; + int cursor; + char c; + this.initializedTransitions = new HashMap(State.stateMaxValue); + int lineNumber = 0; + try { + while ((line = input.readLine()) != null) { + lineNumber++; + output.write(line); + output.write('\n'); + if ((cursor = line.indexOf(this.definitionStartMarker)) != -1) { + // check the line format + boolean reachedStart = true; + for (int i = 0; i < cursor; i++) { + if (!Character.isWhitespace(c = line.charAt(i))) { + reachedStart = false; + break; + } + else { + tab += c; + } + } + if (reachedStart) { + while ((line = input.readLine()) != null && + line.indexOf(this.definitionEndMarker) == -1) { + lineNumber++; + final int + start = 0, + commentStart = 1, + commentFound = 2, + firstState = 10, + firstStateWS = 11, + implies = 20, + impliesWS = 21, + secondState = 30, + secondStateWS = 31, // caveat, multi-state + error = 99; + int state = start, + firstStateStart = 0, firstStateEnd = 0, firstStateWhiteSpace = 0, + secondStateStart = 0, secondStateEnd = 0, secondStateWhiteSpace = 0; + char current; + analysis: for (int i = 0, length = line.length(); i < length; i++) { + current = line.charAt(i); + switch (state) { + case start: + if (current == '/') { + state = commentStart; + } else if (! Character.isWhitespace(current)) { + state = error; + break analysis; + } + break; + case commentStart: + if (current == '/') { + state = commentFound; + } else { + state = error; + break analysis; + } + break; + case commentFound: + if (! Character.isWhitespace(current)) { + firstStateStart = firstStateEnd = i; + state = firstState; + } + break; + case firstState: + if (Character.isWhitespace(current)) { + state = firstStateWS; + firstStateWhiteSpace = 1; + } else { + firstStateEnd++; + } + break; + case firstStateWS: + if (current == '=') { + state = implies; + } else if (Character.isWhitespace(current)) { + firstStateWhiteSpace++; + } else { + state = firstState; + firstStateEnd += firstStateWhiteSpace + 1; + } + break; + case implies: + if (current == '>') { + state = impliesWS; + } else { + state = error; + break analysis; + } + break; + case impliesWS: + if (! Character.isWhitespace(current)) { + secondStateStart = secondStateEnd = i; + state = secondState; + } + break; + case secondState: + if (current == '/') { + break analysis; + } else if (Character.isWhitespace(current)) { + state = secondStateWS; + secondStateWhiteSpace = 1; + } else { + secondStateEnd++; + } + break; + case secondStateWS: + if (current == '/') { + state = secondState; + break analysis; + } else if (current == 'C') { + state++; + } else if (Character.isWhitespace(current)) { + secondStateWhiteSpace++; + } else { + state = secondState; + secondStateEnd += secondStateWhiteSpace + 1; + } + break; + case secondStateWS + 1: + if (current == '/') { + state = secondState; + break analysis; + } else if (current == 'H') { + state++; + } else { + state = secondState; + secondStateEnd += secondStateWhiteSpace + 2; + } + break; + case secondStateWS + 2: + if (current == '/') { + state = secondState; + break analysis; + } else if (current == 'E') { + state++; + } else { + state = secondState; + secondStateEnd += secondStateWhiteSpace + 3; + } + break; + case secondStateWS + 3: + if (current == '/') { + state = secondState; + break analysis; + } else if (current == 'C') { + state++; + } else { + state = secondState; + secondStateEnd += secondStateWhiteSpace + 4; + } + break; + case secondStateWS + 4: + if (current == '/' || current == 'K') { + state = secondState; + break analysis; + } else { + state = secondState; + secondStateEnd += secondStateWhiteSpace + 5; + } + break; + + } + } + if (state == error || state < secondState) { + System.err.println("Could not interpret comment definition"); // PREMATURE improve diagnostic + } else { + if (state > secondStateWS) { + secondStateEnd += (state - secondState); + } + String stateName; + State first, second; + if ((first = State.fromSymbolicName( + stateName = line.substring(firstStateStart, firstStateEnd + 1))) + == null) { + System.err.println("Could not find state: " + stateName); // PREMATURE improve diagnostic + } + if ((second = State.fromSymbolicName( + stateName = line.substring(secondStateStart, secondStateEnd + 1))) + == null) { + System.err.println("Could not find state: " + stateName); // PREMATURE improve diagnostic + } + if (first != null && second != null) { + if (this.initializedTransitions.get(first) != null) { + System.err.println("Line " + lineNumber + ": Skipping duplicate entry for state: " + first); // PREMATURE improve diagnostic + } else { + this.initializedTransitions.put(first, second); + } + } + } + output.write(line); + output.write('\n'); + } + Iterator firsts = State.symbolicStates(); + State first; + while (firsts.hasNext()) { + first = (State) firsts.next(); + if (this.initializedTransitions.get(first) == null) { + System.err.println("Adding missing transition for state: " + first); + output.write(tab); + output.write("// "); + output.write(first.toString()); + output.write(" => start\t\t CHECK\n"); + } + } + } + output.write(tab + this.definitionEndMarker + "\n"); + } + if (line != null && (cursor = line.indexOf(this.initializerStartMarker)) != -1) { + // check the line format + boolean reachedStart = true; + tab = ""; + for (int i = 0; i < cursor; i++) { + if (!Character.isWhitespace(c = line.charAt(i))) { + reachedStart = false; + break; + } + else { + tab += c; + } + } + if (reachedStart) { + while ((line = input.readLine()) != null && + line.indexOf(this.initializerEndMarker) == -1) { + // loop + } + SortedMap sorted = new TreeMap(this.initializedTransitions); + Iterator transitions = sorted.entrySet().iterator(); + Map.Entry transition; + while (transitions.hasNext()) { + transition = (Map.Entry) transitions.next(); + output.write(tab); + output.write('{'); + output.write(((State)transition.getKey()).hexString); + output.write(','); + output.write(((State)transition.getValue()).hexString); + output.write("},"); + output.write('\n'); + } + output.write(tab + this.initializerEndMarker + "\n"); + } + } + } + output.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } +} + +@Override +void reinitializeFromComputedValues(BufferedReader input, BufferedWriter output, + State[] consideredStates) { + String line, tab = ""; + int cursor; + char c; + State result; + try { + while ((line = input.readLine()) != null) { + output.write(line); + output.write('\n'); + if ((cursor = line.indexOf(this.definitionStartMarker)) != -1) { + // check the line format + boolean reachedStart = true; + for (int i = 0; i < cursor; i++) { + if (!Character.isWhitespace(c = line.charAt(i))) { + reachedStart = false; + break; + } + else { + tab += c; + } + } + if (reachedStart) { + while ((line = input.readLine()) != null && + line.indexOf(this.definitionEndMarker) == -1) { + // loop + } + int i, length; + // definitions of two-dim trafos in natural order (by state value): + for (i = 0, length = consideredStates.length; i < length; i++) { + output.write(tab); + output.write("// "); + output.write(consideredStates[i].name); + output.write(" => "); + output.write( + (result = (State) this.computedTransitions.get(consideredStates[i])).name); + if (!result.symbolic || + result != this.initializedTransitions.get(consideredStates[i])) { + output.write("\t\t CHECK"); + } + output.write('\n'); + } + output.write(tab + this.definitionEndMarker + "\n"); + } + } + if (line != null && (cursor = line.indexOf(this.initializerStartMarker)) != -1) { + // check the line format + boolean reachedStart = true; + tab = ""; + for (int i = 0; i < cursor; i++) { + if (!Character.isWhitespace(c = line.charAt(i))) { + reachedStart = false; + break; + } + else { + tab += c; + } + } + if (reachedStart) { + while ((line = input.readLine()) != null && + line.indexOf(this.initializerEndMarker) == -1) { + // loop + } + int i, length; + for (i = 0, length = consideredStates.length; i < length; i++) { + output.write(tab); + output.write('{'); + output.write(consideredStates[i].hexString); + output.write(','); + output.write( + ((State) this.computedTransitions.get(consideredStates[i])).hexString); + output.write("},"); + output.write('\n'); + } + output.write(tab + this.initializerEndMarker + "\n"); + } + } + } + output.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } +} +@Override +int test() { + Iterator transitions = this.initializedTransitions.entrySet().iterator(); + State input, expectedOutput, effectiveOutput; + Map.Entry transition; + this.failuresNb = 0; // reset + while (transitions.hasNext()) { + transition = (Map.Entry) transitions.next(); + input = (State) transition.getKey(); + expectedOutput = (State) transition.getValue(); + effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input), + TestLocalVariableBinding.local0)).asState(); + if (effectiveOutput != expectedOutput) { + fail(); + System.out.println("\t\t" + input.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " instead of: " + expectedOutput.printableBitsField); + } + } + transitions = this.initializedTransitions.entrySet().iterator(); + while (transitions.hasNext()) { + transition = (Map.Entry) transitions.next(); + input = (State) transition.getKey(); + expectedOutput = (State) transition.getValue(); + effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input, 64), + TestLocalVariableBinding.local64)).asState(64); + if (effectiveOutput != expectedOutput) { + fail(); + System.out.println("\t\t" + input.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (64) instead of: " + expectedOutput.printableBitsField); + } + if (input == State.start) { + effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(expectedOutput), + TestLocalVariableBinding.local64)).asState(64); + if (effectiveOutput != expectedOutput) { + fail(); + System.out.println("\t\t" + input.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero 64) instead of: " + expectedOutput.printableBitsField); + } + } + } + transitions = this.initializedTransitions.entrySet().iterator(); + while (transitions.hasNext()) { + transition = (Map.Entry) transitions.next(); + input = (State) transition.getKey(); + if (input == State.start) { + expectedOutput = (State) transition.getValue(); + effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(expectedOutput, 64), + TestLocalVariableBinding.local128)).asState(128); + if (effectiveOutput != expectedOutput) { + fail(); + System.out.println("\t\t" + input.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero 128) instead of: " + expectedOutput.printableBitsField); + } + } + } + return this.failuresNb; +} +} +public abstract static class ThreeDimensionalTransformation extends Transformation { +private static final boolean CHECKING_ROW_NAMES = false; +ThreeDimensionalTransformation(String name) { + super(name); + this.dimension = 3; +} +ThreeDimensionalTransformation(String name, byte[][] transitions) { + super(name); + this.dimension = 3; + int length; + this.initializedTransitions = new HashMap(length = transitions.length); + State input1, input2; + for (int i = 0; i < length; i++) { + if (transitions[i].length != 3) { + throw new IllegalArgumentException("transitions should have three entries"); + } + input1 = State.states[transitions[i][0]]; // array out of bounds exception if broken + input2 = State.states[transitions[i][1]]; + Map transitionsForInput1 = (Map) this.initializedTransitions.get(input1); + if (transitionsForInput1 == null) { + transitionsForInput1 = new HashMap(length); + this.initializedTransitions.put(input1, transitionsForInput1); + } + if (transitionsForInput1.get(input2) != null) { + throw new IllegalArgumentException("duplicate entry"); + } + transitionsForInput1.put(input2, State.states[transitions[i][2]]); + } +} +@Override +State[] computeOutputs(State[] inputs) { + Map resultAccumulator = new HashMap(State.stateMaxValue + 1); + hydrate(); // pre-compute all possible combinations, then cache them + for (int i = 0, inputsLength = inputs.length; i < inputsLength; i++) { + for (int i2 = 0; i2 < inputsLength; i2++) { + resultAccumulator.put( + ((Map) this.computedTransitions.get(inputs[i])).get(inputs[i2]), null); + } + } + int length; + State[] result = new State[length = resultAccumulator.size()]; + Iterator resultIterator = resultAccumulator.keySet().iterator(); + for (int j = 0; j < length; j++) { + result[j] = (State) resultIterator.next(); + } + return result; +} +@Override +void hydrate() { + if (this.computedTransitions == null) { + State input1, input2, output; + this.computedTransitions = new HashMap(State.stateMaxValue + 1); + Map entry; + for (int i = 0, length = State.states.length; i < length; i++) { + entry = new HashMap(State.stateMaxValue + 1); + this.computedTransitions.put(input1 = State.states[i], entry); + for (int j = 0; j < length; j++) { + output = ((UnconditionalFlowInfoTestHarness) + output(UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input1), + UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input2 = State.states[j]))).asState(); + if (input1.symbolic && input2.symbolic && !output.symbolic) { + System.err.println(this.name + " generates non-symbolic state " + + output + " upon entry: " + input1 + " + " + input2); + } + entry.put(input2, output); + } + } + } +} +abstract UnconditionalFlowInfo output(UnconditionalFlowInfo input1, UnconditionalFlowInfo input2); +void printDefinitions(BufferedWriter output, State[] consideredStates, String tab) + throws IOException { + int i, j, length = consideredStates.length; + State result; + // temporary store to support lexical sorting: + String[] lines = new String[length * length]; + int lCount = 0; + for (i = 0; i < length; i++) { + for (j = 0; j < length; j++) { + StringBuilder line = new StringBuilder(); + line.append(tab); + line.append("// "); + line.append(consideredStates[i].name); + line.append(" + "); + line.append(consideredStates[j].name); + line.append(" => "); + line.append( + (result = (State) getResult(this.computedTransitions, consideredStates[i], consideredStates[j])).name); + if (!result.symbolic || + result != getResult(this.initializedTransitions, consideredStates[i], consideredStates[j])) { + line.append("\t\t CHECK"); + } + line.append('\n'); + lines[lCount++] = line.toString(); + } + } + Arrays.sort(lines); + for (i = 0; i < lCount; i++) { + output.write(lines[i]); + } +} +Object getResult(Map transitions, State statei, State statej) { + Object res1 = transitions.get(statei); + if (res1 instanceof Map) { + return ((Map)res1).get(statej); + } + return null; +} +void printInitializers(BufferedWriter output, State[] consideredStates, String tab) + throws IOException { + int i, j, length; + for (i = 0, length = consideredStates.length; i < length; i++) { + for (j = 0; j < length; j++) { + output.write(tab); + output.write('{'); + output.write(consideredStates[i].hexString); + output.write(','); + output.write(consideredStates[j].hexString); + output.write(','); + output.write( + ((State) + ((Map) this.computedTransitions.get(consideredStates[i])).get(consideredStates[j])).hexString); + output.write("},"); + output.write('\n'); + } + } +} +void printMissingEntries(BufferedWriter output, String tab) throws IOException { + Iterator firsts = State.symbolicStates(), seconds; + State first, second; + Map transitions; + while (firsts.hasNext()) { + first = (State) firsts.next(); + seconds = State.symbolicStates(); + if ((transitions = (Map) this.initializedTransitions.get(first)) + == null) { + while (seconds.hasNext()) { + second = (State) seconds.next(); + System.err.println("Adding missing transition for states (" + first + ", " + second + ")"); + output.write(tab); + output.write("// "); + output.write(first.toString()); + output.write(" + "); + output.write(second.toString()); + output.write(" => start\t\t CHECK\n"); + } + } else { + while (seconds.hasNext()) { + second = (State) seconds.next(); + if (transitions.get(second) == null) { + System.err.println("Adding missing transition for states (" + first + ", " + second + ")"); + output.write(tab); + output.write("// "); + output.write(first.toString()); + output.write(" + "); + output.write(second.toString()); + output.write(" => start\t\t CHECK\n"); + } + } + } + } +} +@Override +void printTruthTables(File outputDirectory) { + for (int bit = 1; bit <= State.stateWidth; bit++) { + try { + String outputFileName = outputDirectory.getPath() + File.separator + this.name + "_" + bit + ".txt"; + PrintWriter out = new PrintWriter(new FileOutputStream( + new File(outputFileName))); + System.out.println("Printing " + outputFileName); + out.println("======================================================"); + out.println("Truth table for " + this.name + " null bit " + bit); + char truthValues[][] = new char[State.statesNb][State.statesNb]; + int row, column; + for (row = 0; row < State.statesNb; row++) { + for (column = 0; column < State.statesNb; column++) { + truthValues[row][column] = '.'; + } + } + if (CHECKING_ROW_NAMES) { // checking row names + boolean gotProblem = false; + if (truthTableRowNames.length > State.statesNb) { + System.out.println("row names table contains too many rows"); + gotProblem = true; + } + else if (truthTableRowNames.length < State.statesNb) { + System.out.println("row names table contains too few rows"); + gotProblem = true; + } + Map check = new HashMap(State.statesNb); + for (row = 0; row < truthTableRowNames.length; row++) { + if (check.containsKey(truthTableRowNames[row])) { + System.out.println("duplicate row: " + truthTableRowNames[row]); + gotProblem = true; + } + else { + check.put(truthTableRowNames[row], null); + } + if (row > 0 && !checkContiguity(truthTableRowNames[row - 1], truthTableRowNames[row])) { + gotProblem = true; + } + } + // assertFalse("invalid rows table", gotProblem); + } + boolean keepRow[] = new boolean[State.statesNb], + keepColumn[] = new boolean[State.statesNb]; + Iterator i1 = this.initializedTransitions.entrySet().iterator(); + while (i1.hasNext()) { + Map.Entry transitionsSet = (Map.Entry) i1.next(); + State first = (State) transitionsSet.getKey(); + Iterator i2 = ((Map) transitionsSet.getValue()).entrySet().iterator(); + while (i2.hasNext()) { + Map.Entry transition = (Map.Entry) i2.next(); + mark(truthValues, keepRow, keepColumn, rankForState(first), + rankForState((State) transition.getKey()), + ((State) transition.getValue()).printableBitsField.charAt(bit - 1)); + } + } + for (row = 0; row < State.statesNb; row += 2) { + if (keepRow[row]) { + keepRow[row + 1] = true; + } + else if (keepRow[row + 1]) { + keepRow[row] = true; + } + if (keepColumn[row]) { + keepColumn[row + 1] = true; + } + else if (keepColumn[row + 1]) { + keepColumn[row] = true; + } + } + StringBuffer line; + for (int i = 0; i < State.stateWidth; i++) { + line = new StringBuffer(140); + line.append(" "); + for (column = 0; column < State.statesNb; column++) { + if (keepColumn[column]) { + line.append(truthTableRowNames[column].charAt(i)); + line.append(' '); + } + } + out.println(line); + } + line = new StringBuffer(140); + line.append(" --"); + for (column = 0; column < State.statesNb; column++) { + if (keepColumn[column]) { + line.append('-'); + line.append('-'); + } + } + out.println(line); + for (row = 0; row < State.statesNb; row++) { + if (keepRow[row]) { + line = new StringBuffer(140); + line.append(truthTableRowNames[row]); + line.append(" | "); + for (column = 0; column < State.statesNb; column++) { + if (keepColumn[column]) { + line.append(truthValues[row][column]); + line.append(' '); + } + } + out.println(line); + } + } + out.println("======================================================"); + out.flush(); + out.close(); + } + catch (Throwable t) { + // PREMATURE improve error handling + } + } +} + +void mark(char truthValues[][], boolean keepRow[], boolean keepColumn[], + int row, int column, char value) { + truthValues[row][column] = value; + keepRow[row] = true; + keepColumn[column] = true; +} + +@Override +void reinitializeFromComments(BufferedReader input, BufferedWriter output) { + String line, tab = ""; + int cursor; + char c; + this.initializedTransitions = new HashMap(State.stateMaxValue); + int lineNumber = 0; + try { + while ((line = input.readLine()) != null) { + lineNumber++; + output.write(line); + output.write('\n'); + if ((cursor = line.indexOf(this.definitionStartMarker)) != -1) { + // check the line format + boolean reachedStart = true; + for (int i = 0; i < cursor; i++) { + if (!Character.isWhitespace(c = line.charAt(i))) { + reachedStart = false; + break; + } + else { + tab += c; + } + } + if (reachedStart) { + while ((line = input.readLine()) != null && + line.indexOf(this.definitionEndMarker) == -1) { + lineNumber++; + final int + start = 0, + commentStart = 1, + commentFound = 2, + firstState = 10, + firstStateWS = 11, + plus = 20, + secondState = 30, + secondStateWS = 31, + implies = 40, + impliesWS = 41, + thirdState = 50, + thirdStateWS = 51, // caveat, multi-state + error = 99; + int state = start, + firstStateStart = 0, firstStateEnd = 0, firstStateWhiteSpace = 0, + secondStateStart = 0, secondStateEnd = 0, secondStateWhiteSpace = 0, + thirdStateStart = 0, thirdStateEnd = 0, thirdStateWhiteSpace = 0; + char current; + analysis: for (int i = 0, length = line.length(); i < length; i++) { + current = line.charAt(i); + switch (state) { + case start: + if (current == '/') { + state = commentStart; + } else if (! Character.isWhitespace(current)) { + state = error; + break analysis; + } + break; + case commentStart: + if (current == '/') { + state = commentFound; + } else { + state = error; + break analysis; + } + break; + case commentFound: + if (! Character.isWhitespace(current)) { + firstStateStart = firstStateEnd = i; + state = firstState; + } + break; + case firstState: + if (Character.isWhitespace(current)) { + state = firstStateWS; + firstStateWhiteSpace = 1; + } else { + firstStateEnd++; + } + break; + case firstStateWS: + if (current == '+') { + state = plus; + } else if (Character.isWhitespace(current)) { + firstStateWhiteSpace++; + } else { + state = firstState; + firstStateEnd += firstStateWhiteSpace + 1; + } + break; + case plus: + if (! Character.isWhitespace(current)) { + secondStateStart = secondStateEnd = i; + state = secondState; + } + break; + case secondState: + if (Character.isWhitespace(current)) { + state = secondStateWS; + secondStateWhiteSpace = 1; + } else { + secondStateEnd++; + } + break; + case secondStateWS: + if (current == '=') { + state = implies; + } else if (Character.isWhitespace(current)) { + secondStateWhiteSpace++; + } else { + state = secondState; + secondStateEnd += secondStateWhiteSpace + 1; + } + break; + case implies: + if (current == '>') { + state = impliesWS; + } else { + state = error; + break analysis; + } + break; + case impliesWS: + if (! Character.isWhitespace(current)) { + thirdStateStart = thirdStateEnd = i; + state = thirdState; + } + break; + case thirdState: + if (current == '/') { + break analysis; + } else if (Character.isWhitespace(current)) { + state = thirdStateWS; + thirdStateWhiteSpace = 1; + } else { + thirdStateEnd++; + } + break; + case thirdStateWS: + if (current == '/') { + state = thirdState; + break analysis; + } else if (current == 'C') { + state++; + } else if (Character.isWhitespace(current)) { + thirdStateWhiteSpace++; + } else { + state = thirdState; + thirdStateEnd += thirdStateWhiteSpace + 1; + } + break; + case thirdStateWS + 1: + if (current == '/') { + state = thirdState; + break analysis; + } else if (current == 'H') { + state++; + } else { + state = thirdState; + thirdStateEnd += thirdStateWhiteSpace + 2; + } + break; + case thirdStateWS + 2: + if (current == '/') { + state = thirdState; + break analysis; + } else if (current == 'E') { + state++; + } else { + state = thirdState; + thirdStateEnd += thirdStateWhiteSpace + 3; + } + break; + case thirdStateWS + 3: + if (current == '/') { + state = thirdState; + break analysis; + } else if (current == 'C') { + state++; + } else { + state = thirdState; + thirdStateEnd += thirdStateWhiteSpace + 4; + } + break; + case thirdStateWS + 4: + if (current == '/' || current == 'K') { + state = thirdState; + break analysis; + } else { + state = thirdState; + thirdStateEnd += thirdStateWhiteSpace + 5; + } + break; + + } + } + if (state == error || state < thirdState) { + System.err.println("Could not interpret comment definition"); // PREMATURE improve diagnostic + } else { + if (state > thirdStateWS) { + thirdStateEnd += (state - thirdState); + } + String stateName; + State first, second, third; + if ((first = State.fromSymbolicName( + stateName = line.substring(firstStateStart, firstStateEnd + 1))) + == null) { + System.err.println("Could not find state: " + stateName); // PREMATURE improve diagnostic + } + if ((second = State.fromSymbolicName( + stateName = line.substring(secondStateStart, secondStateEnd + 1))) + == null) { + System.err.println("Could not find state: " + stateName); // PREMATURE improve diagnostic + } + if ((third = State.fromSymbolicName( + stateName = line.substring(thirdStateStart, thirdStateEnd + 1))) + == null) { + System.err.println("Could not find state: " + stateName); // PREMATURE improve diagnostic + } + if (first != null && second != null && third != null) { + Map transitions; + if ((transitions = (Map) this.initializedTransitions.get(first)) == null) { + transitions = new HashMap(State.stateMaxValue + 1); + this.initializedTransitions.put(first, transitions); + } + if (transitions.get(second) != null) { + System.err.println("Line " + lineNumber + ": Skipping duplicate entry for states: (" + first + + ", " + second + ")"); // PREMATURE improve diagnostic + } else { + transitions.put(second, third); + } + } + } + output.write(line); + output.write('\n'); + } + } + printMissingEntries(output, tab); + output.write(tab + this.definitionEndMarker + "\n"); + } + if (line != null && (cursor = line.indexOf(this.initializerStartMarker)) != -1) { + // check the line format + boolean reachedStart = true; + tab = ""; + for (int i = 0; i < cursor; i++) { + if (!Character.isWhitespace(c = line.charAt(i))) { + reachedStart = false; + break; + } + else { + tab += c; + } + } + if (reachedStart) { + while ((line = input.readLine()) != null && + line.indexOf(this.initializerEndMarker) == -1) { + // loop + } + SortedMap sortedTransitionsSet = new TreeMap(this.initializedTransitions); + Iterator transitionsSets = sortedTransitionsSet.entrySet().iterator(); + Map.Entry transitionsSet; + while (transitionsSets.hasNext()) { + transitionsSet = (Map.Entry) transitionsSets.next(); + SortedMap sortedTransitions = new TreeMap((Map) transitionsSet.getValue()); + Iterator transitions = sortedTransitions.entrySet().iterator(); + Map.Entry transition; + while (transitions.hasNext()) { + transition = (Map.Entry) transitions.next(); + output.write(tab); + output.write('{'); + output.write(((State)transitionsSet.getKey()).hexString); + output.write(','); + output.write(((State)transition.getKey()).hexString); + output.write(','); + output.write(((State)transition.getValue()).hexString); + output.write("},"); + output.write('\n'); + } + } + output.write(tab + this.initializerEndMarker + "\n"); + } + } + } + output.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } +} +@Override +void reinitializeFromComputedValues(BufferedReader input, BufferedWriter output, + State[] consideredStates) { + String line, tab = ""; + int cursor; + char c; + try { + while ((line = input.readLine()) != null) { + output.write(line); + output.write('\n'); + if ((cursor = line.indexOf(this.definitionStartMarker)) != -1) { + // check the line format + boolean reachedStart = true; + for (int i = 0; i < cursor; i++) { + if (!Character.isWhitespace(c = line.charAt(i))) { + reachedStart = false; + break; + } + else { + tab += c; + } + } + if (reachedStart) { + while ((line = input.readLine()) != null && + line.indexOf(this.definitionEndMarker) == -1) { + // loop + } + printDefinitions(output, consideredStates, tab); + output.write(tab + this.definitionEndMarker + "\n"); + } + } + if (line != null && (cursor = line.indexOf(this.initializerStartMarker)) != -1) { + // check the line format + boolean reachedStart = true; + tab = ""; + for (int i = 0; i < cursor; i++) { + if (!Character.isWhitespace(c = line.charAt(i))) { + reachedStart = false; + break; + } + else { + tab += c; + } + } + if (reachedStart) { + while ((line = input.readLine()) != null && + line.indexOf(this.initializerEndMarker) == -1) { + // loop + } + printInitializers(output, consideredStates, tab); + output.write(tab + this.initializerEndMarker + "\n"); + } + } + } + output.flush(); + } catch (IOException e) { + throw new RuntimeException(e); + } +} +@Override +int test() { + return test(1, false); +} +int test(int combinationTestsLoopsNb, boolean skipHighOrderBits) { + Iterator transitionsSetsIterator, transitionsIterator; + State input1, input2, expectedOutput, effectiveOutput; + Map.Entry transition, transitionsSet; + this.failuresNb = 0; // reset + this.failuresNb = 0; // reset + long start = 0; + if (combinationTestsLoopsNb > 1) { + start = System.currentTimeMillis(); + } + for (int l = 0; l < combinationTestsLoopsNb ; l++) { + transitionsSetsIterator = this.initializedTransitions.entrySet().iterator(); + while (transitionsSetsIterator.hasNext()) { + transitionsSet = (Map.Entry) transitionsSetsIterator.next(); + input1 = (State) transitionsSet.getKey(); + transitionsIterator = ((Map) transitionsSet.getValue()). + entrySet().iterator(); + while (transitionsIterator.hasNext()) { + transition = (Map.Entry) transitionsIterator.next(); + input2 = (State) transition.getKey(); + expectedOutput = (State) transition.getValue(); + effectiveOutput = ((UnconditionalFlowInfoTestHarness) output( + UnconditionalFlowInfoTestHarness.testUnconditionalFlowInfo(input1), + UnconditionalFlowInfoTestHarness.testUnconditionalFlowInfo(input2))) + .asState(); + if (effectiveOutput != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " instead of: " + expectedOutput.printableBitsField); + } + } + } + } + if (combinationTestsLoopsNb > 1) { + System.out.println(this.name + "...\t\t" + combinationTestsLoopsNb + "\t" + + (System.currentTimeMillis() - start)); + } + // PREMATURE optimize test (extraneous allocations and copies) + // PREMATURE optimize test (extraneous iterations - undup) + if (!skipHighOrderBits) { + UnconditionalFlowInfoTestHarness + zero = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(State.start), + left, right, left64, right64, left128, right128, + special = (UnconditionalFlowInfoTestHarness) zero.copy(); + special.grow(64); // allocates one extra without adding null info + transitionsSetsIterator = this.initializedTransitions.entrySet().iterator(); + while (transitionsSetsIterator.hasNext()) { + transitionsSet = (Map.Entry) transitionsSetsIterator.next(); + input1 = (State) transitionsSet.getKey(); + transitionsIterator = ((Map) transitionsSet.getValue()). + entrySet().iterator(); + while (transitionsIterator.hasNext()) { + transition = (Map.Entry) transitionsIterator.next(); + input2 = (State) transition.getKey(); + expectedOutput = (State) transition.getValue(); + left = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input1); + left64 = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input1, 64); + left128 = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input1, 128); + right = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input2); + right64 = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input2, 64); + right128 = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input2, 128); + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(left64, right64)).asState(64)) != + expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (64, 64) - instead of: " + expectedOutput.printableBitsField); + } + if (input1 == State.start) { + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right128, right)).asState()) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero 128, 1) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(zero, right64)).asState(64)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero, 64) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right128, right64)).asState(64)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero 128, 64) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(zero, right128)).asState(128)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero, 128) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right64, right128)).asState(128)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero 64, 128) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(special, right128)).asState(128)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (special zero, 128) - instead of: " + expectedOutput.printableBitsField); + } + } + if (input2 == State.start) { + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(left, left128)).asState()) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (1, zero 128) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(left64, zero)).asState(64)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (64, zero) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(left64, left128)).asState(64)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (64, zero 128) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(left128, zero)).asState(128)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (128, zero) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(left128, left64)).asState(128)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (128, zero 64) - instead of: " + expectedOutput.printableBitsField); + } + } + } + } + } + return this.failuresNb; +} +} + +public abstract static class SymmetricalThreeDimensionalTransformation + extends ThreeDimensionalTransformation{ +SymmetricalThreeDimensionalTransformation(String name, byte[][] transitions) { + super(name); + int length; + this.initializedTransitions = new HashMap((length = transitions.length) * 2 - 1); + State input1, input2; + for (int i = 0; i < length; i++) { + if (transitions[i].length != 3) { + throw new IllegalArgumentException("transitions should have three entries"); + } + if (transitions[i][0] <= transitions[i][1]) { + input1 = State.states[transitions[i][0]]; // array out of bounds exception if broken + input2 = State.states[transitions[i][1]]; + } + else { + input1 = State.states[transitions[i][1]]; + input2 = State.states[transitions[i][0]]; + } + Map transitionsForInput1 = (Map) this.initializedTransitions.get(input1); + if (transitionsForInput1 == null) { + transitionsForInput1 = new HashMap(length); + this.initializedTransitions.put(input1, transitionsForInput1); + } + if (transitionsForInput1.get(input2) != null) { + throw new IllegalArgumentException("duplicate entry"); + } + transitionsForInput1.put(input2, State.states[transitions[i][2]]); + } +} +@Override +void hydrate() { + super.hydrate(); + checkSymmetry(this.computedTransitions); +} +private void checkSymmetry(Map map) { + State input1, input2, result; + Map.Entry entry1, entry2; + Map transition; + Iterator transitions1 = map.entrySet().iterator(), transitions2; + while (transitions1.hasNext()) { + entry1 = (Map.Entry) transitions1.next(); + input1 = (State) entry1.getKey(); + transition = (Map) entry1.getValue(); + transitions2 = transition.entrySet().iterator(); + while (transitions2.hasNext()) { + entry2 = (Map.Entry) transitions2.next(); + input2 = (State) entry2.getKey(); + result = (State) entry2.getValue(); + if (result != ((Map) map.get(input2)).get(input1) && input1.symbolic && input2.symbolic) { + System.err.println("symmetry mismatch: " + input1 + " + " + + input2 + " -> " + result + "/" + ((Map) map.get(input2)).get(input1)); + } + } + } +} +@Override +void mark(char truthValues[][], boolean keepRow[], boolean keepColumn[], + int row, int column, char value) { + truthValues[row][column] = truthValues[column][row] = value; + keepRow[row] = true; + keepColumn[column] = true; + keepRow[column] = true; + keepColumn[row] = true; +} +@Override +void printDefinitions(BufferedWriter output, State[] consideredStates, String tab) + throws IOException { + // only difference with parent is that we print only half of possible + // combinations + int i, j, length = consideredStates.length; + State result; + // temporary store to support lexical sorting: + String[] lines = new String[length * (length +1) / 2 ]; + int lCount = 0; + for (i = 0; i < length; i++) { + for (j = i; j < length; j++) { + StringBuilder line = new StringBuilder(); + line.append(tab); + line.append("// "); + line.append(consideredStates[i].name); + line.append(" + "); + line.append(consideredStates[j].name); + line.append(" => "); + line.append( + (result = (State) getResult(this.computedTransitions, consideredStates[i], consideredStates[j])).name); + if (!result.symbolic || + result != getResult(this.initializedTransitions, consideredStates[i], consideredStates[j])) { + line.append("\t\t CHECK"); + } + line.append('\n'); + lines[lCount++] = line.toString(); + } + } + Arrays.sort(lines); + for (i = 0; i < lCount; i++) { + output.write(lines[i]); + } +} +@Override +Object getResult(Map transitions, State statei, State statej) { + Object r = super.getResult(transitions, statei, statej); + if (r == null) + r = super.getResult(transitions, statej, statei); + return r; +} +@Override +void printInitializers(BufferedWriter output, State[] consideredStates, String tab) + throws IOException { + // only difference with parent is that we print only half of possible + // combinations + int i, j, length; + for (i = 0, length = consideredStates.length; i < length; i++) { + for (j = i; j < length; j++) { + output.write(tab); + output.write('{'); + output.write(consideredStates[i].hexString); + output.write(','); + output.write(consideredStates[j].hexString); + output.write(','); + output.write( + ((State) + ((Map) this.computedTransitions.get(consideredStates[i])).get(consideredStates[j])).hexString); + output.write("},"); + output.write('\n'); + } + } +} +@Override +void printMissingEntries(BufferedWriter output, String tab) throws IOException { + Iterator firsts = State.symbolicStates(), seconds; + State first, second; + while (firsts.hasNext()) { + first = (State) firsts.next(); + seconds = State.symbolicStates(); + while (seconds.hasNext()) { + second = (State) seconds.next(); + if (!checkPair(first, second)) { + addPair(first, second); + System.err.println("Adding missing transition for states (" + first + ", " + second + ")"); + output.write(tab); + output.write("// "); + output.write(first.toString()); + output.write(" + "); + output.write(second.toString()); + output.write(" => start\t\t CHECK\n"); + } + } + } +} +private boolean checkPair(State s1, State s2) { + Map transitions; + if ((transitions = (Map) this.initializedTransitions.get(s1)) != null) { + if (transitions.get(s2) != null) { + return true; + } + } + if ((transitions = (Map) this.initializedTransitions.get(s2)) != null) { + if (transitions.get(s1) != null) { + return true; + } + } + return false; +} +private void addPair(State s1, State s2) { + Map transitions; + if ((transitions = (Map) this.initializedTransitions.get(s1)) == null) { + transitions = new HashMap(); + this.initializedTransitions.put(s1, transitions); + } + transitions.put(s2, s2); // dummy, non null value +} +// PREMATURE factorize upward +@Override +int test(int combinationTestsLoopsNb, boolean skipHighOrderBits) { + Iterator transitionsSetsIterator, transitionsIterator; + State input1, input2, expectedOutput, effectiveOutput; + Map.Entry transition, transitionsSet; + this.failuresNb = 0; // reset + this.failuresNb = 0; // reset + long start = 0; + if (combinationTestsLoopsNb > 1) { + start = System.currentTimeMillis(); + } + for (int l = 0; l < combinationTestsLoopsNb ; l++) { + transitionsSetsIterator = this.initializedTransitions.entrySet().iterator(); + while (transitionsSetsIterator.hasNext()) { + transitionsSet = (Map.Entry) transitionsSetsIterator.next(); + input1 = (State) transitionsSet.getKey(); + transitionsIterator = ((Map) transitionsSet.getValue()). + entrySet().iterator(); + while (transitionsIterator.hasNext()) { + transition = (Map.Entry) transitionsIterator.next(); + input2 = (State) transition.getKey(); + expectedOutput = (State) transition.getValue(); + effectiveOutput = ((UnconditionalFlowInfoTestHarness) output( + UnconditionalFlowInfoTestHarness.testUnconditionalFlowInfo(input1), + UnconditionalFlowInfoTestHarness.testUnconditionalFlowInfo(input2))) + .asState(); + if (effectiveOutput != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " instead of: " + expectedOutput.printableBitsField); + } + effectiveOutput = ((UnconditionalFlowInfoTestHarness) output( + UnconditionalFlowInfoTestHarness.testUnconditionalFlowInfo(input2), + UnconditionalFlowInfoTestHarness.testUnconditionalFlowInfo(input1))) + .asState(); + if (effectiveOutput != expectedOutput) { + fail(); + System.out.println("\t\t" + input2.printableBitsField + + " + " + input1.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " instead of: " + expectedOutput.printableBitsField); + } + } + } + } + if (combinationTestsLoopsNb > 1) { + System.out.println(this.name + "...\t\t" + combinationTestsLoopsNb + "\t" + + (System.currentTimeMillis() - start)); + } + // PREMATURE optimize test (extraneous allocations and copies) + // PREMATURE optimize test (extraneous iterations - undup) + if (!skipHighOrderBits) { + UnconditionalFlowInfoTestHarness + zero = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(State.start), + right, left64, right64, right128; + transitionsSetsIterator = this.initializedTransitions.entrySet().iterator(); + while (transitionsSetsIterator.hasNext()) { + transitionsSet = (Map.Entry) transitionsSetsIterator.next(); + input1 = (State) transitionsSet.getKey(); + transitionsIterator = ((Map) transitionsSet.getValue()). + entrySet().iterator(); + while (transitionsIterator.hasNext()) { + transition = (Map.Entry) transitionsIterator.next(); + input2 = (State) transition.getKey(); + expectedOutput = (State) transition.getValue(); + left64 = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input1, 64); + right = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input2); + right64 = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input2, 64); + right128 = UnconditionalFlowInfoTestHarness. + testUnconditionalFlowInfo(input2, 128); + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(left64, right64)).asState(64)) != + expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (64, 64) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right64, left64)).asState(64)) != + expectedOutput) { + fail(); + System.out.println("\t\t" + input2.printableBitsField + + " + " + input1.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (64, 64) - instead of: " + expectedOutput.printableBitsField); + } + if (input1 == State.start) { + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right128, right)).asState()) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero 128, 1) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(zero, right64)).asState(64)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero, 64) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right128, right64)).asState(64)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero 128, 64) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(zero, right128)).asState(128)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero, 128) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right64, right128)).asState(128)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input1.printableBitsField + + " + " + input2.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (zero 64, 128) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right, right128)).asState()) != expectedOutput) { + fail(); + System.out.println("\t\t" + input2.printableBitsField + + " + " + input1.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (1, zero 128) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right64, zero)).asState(64)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input2.printableBitsField + + " + " + input1.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (64, zero) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right64, right128)).asState(64)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input2.printableBitsField + + " + " + input1.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (64, zero 128) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right128, zero)).asState(128)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input2.printableBitsField + + " + " + input1.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (128, zero) - instead of: " + expectedOutput.printableBitsField); + } + if ((effectiveOutput = ((UnconditionalFlowInfoTestHarness) + output(right128, right64)).asState(128)) != expectedOutput) { + fail(); + System.out.println("\t\t" + input2.printableBitsField + + " + " + input1.printableBitsField + + " => " + effectiveOutput.printableBitsField + + " (128, zero 64) - instead of: " + expectedOutput.printableBitsField); + } + } + } + } + } + return this.failuresNb; +} +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java new file mode 100644 index 0000000000..1f8c8d2a74 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java @@ -0,0 +1,18488 @@ +/******************************************************************************* + * Copyright (c) 2005, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 325755 - [compiler] wrong initialization state after conditional expression + * bug 133125 - [compiler][null] need to report the null status of expressions and analyze them simultaneously + * bug 292478 - Report potentially null across variable assignment + * bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE + * bug 320170 - [compiler] [null] Whitebox issues in null analysis + * bug 332637 - Dead Code detection removing code that isn't dead + * bug 338303 - Warning about Redundant assignment conflicts with definite assignment + * bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop + * bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself + * bug 354554 - [null] conditional with redundant condition yields weak error message + * bug 358827 - [1.7] exception analysis for t-w-r spoils null analysis + * bug 349326 - [1.7] new warning for missing try-with-resources + * bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) + * bug 367879 - Incorrect "Potential null pointer access" warning on statement after try-with-resources within try-finally + * bug 383690 - [compiler] location of error re uninitialized final field should be aligned + * bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" + * bug 376263 - Bogus "Potential null pointer access" warning + * bug 331649 - [compiler][null] consider null annotations for fields + * bug 382789 - [compiler][null] warn when syntactically-nonnull expression is compared against null + * bug 401088 - [compiler][null] Wrong warning "Redundant null check" inside nested try statement + * bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try + * bug 400761 - [compiler][null] null may be return as boolean without a diagnostic + * bug 402993 - [null] Follow up of bug 401088: Missing warning about redundant null check + * bug 403147 - [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking + * bug 384380 - False positive on a "Potential null pointer access" after a continue + * bug 406384 - Internal error with I20130413 + * Bug 364326 - [compiler][null] NullPointerException is not found by compiler. FindBugs finds that one + * Bug 453483 - [compiler][null][loop] Improve null analysis for loops + * Bug 195638 - [compiler][null][refactoring] Wrong error : "Null pointer access: The variable xxx can only be null at this location " with try..catch in loop + * Bug 454031 - [compiler][null][loop] bug in null analysis; wrong "dead code" detection + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.HashMap; +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; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +/* See also NullReferenceImplTests for low level, implementation dependent + * tests. */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class NullReferenceTest extends AbstractRegressionTest { + +public NullReferenceTest(String name) { + super(name); +} + + // Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which does not belong to the class are skipped... +// 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[] { "testBug542707_1" }; +// TESTS_NAMES = new String[] { "testBug384380" }; +// TESTS_NAMES = new String[] { "testBug384380_b" }; +// TESTS_NAMES = new String[] { "testBug321926a2" }; +// TESTS_NAMES = new String[] { "testBug432109" }; +// TESTS_NAMES = new String[] { "testBug418500" }; +// TESTS_NUMBERS = new int[] { 561 }; +// TESTS_RANGE = new int[] { 1, 2049 }; +} + +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public static Class testClass() { + return NullReferenceTest.class; +} + +// Conditionally augment problem detection settings +static boolean setNullRelatedOptions = true; +@Override +protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + if (setNullRelatedOptions) { + defaultOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + defaultOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); + defaultOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_IncludeNullInfoFromAsserts, CompilerOptions.ENABLED); + } + return defaultOptions; +} + +protected void runNegativeNullTest(String[] testFiles, String expectedCompilerLog) { + runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- simple case for local +public void test0001_simple_local() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- simple case for field +// the current design leaves fields out of the analysis altogether +public void test0002_simple_field() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + " void foo() {\n" + + " o = null;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "" +// "----------\n" + +// "1. ERROR in X.java (at line 5)\n" + +// " o.toString();\n" + +// " ^\n" + +// "The field o is likely null; it was either set to null or checked for null when last used\n" + +// "----------\n" + ); +} + +// null analysis -- simple case for parameter +public void test0003_simple_parameter() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o = null;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- final local +public void test0004_final_local() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final Object o = null;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- final local +public void test0005_final_local() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final Object o;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "The local variable o may not have been initialized\n" + + // hides the null related message, but complains once, which is good + "----------\n"); +} + +// null analysis -- final local +public void test0006_final_local() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " final Object o = null;\n" + + " if (o != null) { /* */ }\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o != null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- local with member +public void test0007_local_with_member() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m;\n" + + " void foo() {\n" + + " X x = null;\n" + + " x.m.toString();\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " x.m.toString();\n" + + " ^\n" + + "Null pointer access: The variable x can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- local with member +public void test0008_local_with_member() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m;\n" + + " void foo() {\n" + + " X x = null;\n" + + " System.out.println(x.m);\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.println(x.m);\n" + + " ^\n" + + "Null pointer access: The variable x can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- local with member +public void test0009_local_with_member() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m;\n" + + " void foo(X x) {\n" + + " x.m.toString();\n" + // quiet + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- field +public void test0010_field_with_method_call() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + " void foo() {\n" + + " o = null;\n" + + " bar();\n" + // defuses null by side effect + " o.toString();\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- field +public void test0011_field_with_method_call() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static Object o;\n" + + " void foo() {\n" + + " o = null;\n" + + " bar();\n" + // defuses null by side effect + " o.toString();\n" + + " }\n" + + " static void bar() {\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- field +public void test0012_field_with_method_call() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + " void foo() {\n" + + " o = null;\n" + + " bar();\n" + + " o.toString();\n" + + " }\n" + + " static void bar() {\n" + + " }\n" + + "}\n"}, + "" // still ok because the class may hold a pointer to this + ); +} + +// null analysis -- field +public void test0013_field_with_method_call() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static Object o;\n" + + " void foo() {\n" + + " o = null;\n" + + " bar();\n" + + " o.toString();\n" + + " }\n" + + " void bar() {\n" + + " }\n" + + "}\n"}, + "" // still ok because this may place a static call upon X + ); +} + +// null analysis -- field +public void test0014_field_with_explicit_this_access() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + " void foo() {\n" + + " o = null;\n" + + " this.o.toString();\n" + + " }\n" + + "}\n"}, + "" +// "----------\n" + +// "1. ERROR in X.java (at line 5)\n" + +// " this.o.toString();\n" + +// " ^^^^^^\n" + +// "The field o is likely null; it was either set to null or checked for null when last used\n" + +// "----------\n" + ); +} + +// null analysis -- field +public void test0015_field_with_explicit_this_access() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + " void foo() {\n" + + " this.o = null;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "" +// "----------\n" + +// "1. ERROR in X.java (at line 5)\n" + +// " o.toString();\n" + +// " ^\n" + +// "The field o is likely null; it was either set to null or checked for null when last used\n" + +// "----------\n" + ); +} + +// null analysis -- field +public void test0016_field_of_another_object() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + " void foo() {\n" + + " X other = new X();\n" + + " other.o = null;\n" + + " other.o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- field +public void test0017_field_of_another_object() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + " void foo() {\n" + + " X other = this;\n" + + " o = null;\n" + + " other.o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- field +public void test0018_field_of_enclosing_object() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + " public class Y {\n" + + " void foo() {\n" + + " X.this.o = null;\n" + + " X.this.o.toString();\n" + // complain + " }\n" + + " }\n" + + "}\n"}, + "" +// "----------\n" + +// "1. ERROR in X.java (at line 6)\n" + +// " X.this.o.toString();\n" + +// " ^^^^^^^^\n" + +// "The field o is likely null; it was either set to null or checked for null when last used\n" + +// "----------\n" + ); +} + +// null analysis -- fields +// check that fields that are protected against concurrent access +// behave as locals when no call to further methods can affect them +public void test0019_field_synchronized() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + " public synchronized void foo() {\n" + + " o = null;\n" + + " o.toString();\n" + + " }\n" + + " void bar() {/* */}\n" + + "}\n"}, + "" +// "----------\n" + +// "1. ERROR in X.java (at line 5)\n" + +// " o.toString();\n" + +// " ^\n" + +// "The field o is likely null; it was either set to null or checked for null when last used\n" + +// "----------\n" + ); +} + +// null analysis -- field +// check that final fields behave as locals despite calls to further +// methods +public void test0020_final_field() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " final Object o = null;\n" + + " public synchronized void foo() {\n" + + " bar();\n" + + " o.toString();\n" + + " }\n" + + " void bar() {/* */}\n" + + "}\n"}, + "" +// "----------\n" + +// "1. ERROR in X.java (at line 5)\n" + +// " o.toString();\n" + +// " ^\n" + +// "The field o is likely null; it was either set to null or checked for null when last used\n" + +// "----------\n" + ); +} + +// null analysis -- field +public void test0021_final_field() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " final Object o = null;\n" + + " X () {\n" + + " bar();\n" + + " o.toString();\n" + + " }\n" + + " void bar() {/* */}\n" + + "}\n"}, + "" +// "----------\n" + +// "1. ERROR in X.java (at line 5)\n" + +// " o.toString();\n" + +// " ^\n" + +// "The field o is likely null; it was either set to null or checked for null when last used\n" + +// "----------\n" + ); +} + +// null analysis -- field +public void test0022_final_field() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " final Object o = new Object();\n" + + " X () {\n" + + " bar();\n" + + " if (o == null) { /* empty */ }\n" + + " }\n" + + " void bar() {/* */}\n" + + "}\n"}, + "" +// "----------\n" + +// "1. ERROR in X.java (at line 5)\n" + +// " if (o == null) { /* empty */ }\n" + +// " ^\n" + +// "The field o is likely non null; it was either set to a non-null value or assumed to be non-null when last used\n" + +// "----------\n" + ); +} + +// null analysis -- field +public void test0023_field_assignment() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m;\n" + + " void foo(X x) {\n" + + " Object o = x.m;\n" + + " if (o == null) { /* */ };\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- field +public void test0024_field_cast_assignment() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m;\n" + + " void foo(Object x) {\n" + + " Object o = ((X) x).m;\n" + + " if (o == null) { /* */ };\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- parameter +public void test0025_parameter() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o.toString();\n" + // quiet: parameters have unknown value + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- suppress warnings +public void test0026_suppress_warnings() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"null\")\n" + + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "", null, true, null, compilerOptions, null); + } +} + +// null analysis -- embedded comparison +public void test0027_embedded_comparison() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " boolean b = o != null;\n" + // shades doubts upon o + " if (b) { /* */ }\n" + + " o.toString();\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- field +public void test0028_field_as_initializer() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X f;\n" + + " void foo() {\n" + + " X x = f;\n" + + " if (x == null) { /* */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- field +public void test0029_field_assignment() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m;\n" + + " void foo() {\n" + + " X x = null;\n" + + " x.m = new Object();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " x.m = new Object();\n" + + " ^\n" + + "Null pointer access: The variable x can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- conditional expression +public void test0030_conditional_expression() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = true ? null : null;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object o = true ? null : null;\n" + + " ^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- conditional expression +public void test0031_conditional_expression() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = true ? null : new Object();\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object o = true ? null : new Object();\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- conditional expression +public void test0032_conditional_expression() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = false ? null : new Object();\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- conditional expression +public void test0033_conditional_expression() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = (1 == 1) ? null : new Object();\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Object o = (1 == 1) ? null : new Object();\n" + + " ^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Object o = (1 == 1) ? null : new Object();\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- conditional expression +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125 +public void test0034_conditional_expression() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo() {\n" + + " Object o = b ? null : new Object();\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"); +} + +// null analysis -- conditional expression +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125 +// variant with constant condition +public void test0034_conditional_expression_2() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo() {\n" + + " Object o = false ? null : new Object();\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- conditional expression +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125 +public void test0034_conditional_expression_3() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo(Object a) {\n" + + " if (a == null) {}\n" + + " Object o = b ? a : new Object();\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"); +} + +// null analysis -- conditional expression +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125 +// variant with dependency between condition and expression - LocalDeclaration +// TODO(stephan) cannot analyse this flow dependency +public void _test0034_conditional_expression_4() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo(Object u) {\n" + + " if (u == null) {}\n" + //taint + " Object o = (u == null) ? new Object() : u;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- conditional expression +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133125 +// variant with dependency between condition and expression - Assignment +// TODO(stephan) cannot analyse this flow dependency +public void _test0034_conditional_expression_5() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo(Object u) {\n" + + " if (u == null) {}\n" + //taint + " Object o;\n" + + " o = (u == null) ? new Object() : u;\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- conditional expression +public void test0035_conditional_expression() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo() {\n" + + " Object o = b ? null : new Object();\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- conditional expression +public void test0036_conditional_expression() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo() {\n" + + " Object o = b ? null : null;\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic +public void test0037_conditional_expression_1() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // needs autoboxing + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean badFunction(int i) {\n" + + " return i > 0 ? true : null;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return i > 0 ? true : null;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic +public void test0037_conditional_expression_2() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // needs autoboxing + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " int badFunction(int i) {\n" + + " return i > 0 ? null : Integer.MIN_VALUE;\n" + + " }\n" + + " @SuppressWarnings(\"null\")\n" + + " int silent(int i) {\n" + + " return i > 0 ? null : Integer.MIN_VALUE;\n" + + " }\n" + + "}\n"}, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return i > 0 ? null : Integer.MIN_VALUE;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic +public void test0037_conditional_expression_3() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // needs autoboxing + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " boolean badFunction3(int i) {\n" + + " //expected a potential null problem:\n" + + " return i > 0 ? true : (Boolean) null;\n" + + " }\n" + + "}\n"}, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return i > 0 ? true : (Boolean) null;\n" + + " ^^^^^^^^^^^^^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic +// if-then-else instead of conditional expression +public void test0037_conditional_expression_4() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // needs autoboxing + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_UNNECESSARY_ELSE, JavaCore.IGNORE); + runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " boolean badFunction4(int i) {\n" + + " if (i > 0)\n" + + " return true;\n" + + " else\n" + + " // expected a null problem:\n" + + " return (Boolean) null;\n" + + " }\n" + + "}\n"}, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return (Boolean) null;\n" + + " ^^^^^^^^^^^^^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/400761: [compiler][null] null may be return as boolean without a diagnostic +// pot-null cond-expr in receiver position +public void test0037_conditional_expression_5() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " String badFunction3(int i) {\n" + + " return (i > 0 ? this : null).toString();\n" + + " }\n" + + " String badFunction4(int i) {\n" + + " Object o = null;\n" + + " return (i > 0 ? o : null).toString();\n" + + " }\n" + + "}\n"}, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return (i > 0 ? this : null).toString();\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: This expression may be null\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " return (i > 0 ? o : null).toString();\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Null pointer access: This expression can only be null\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/403147 [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking +// finally block injects pot-nn into itself via enclosing loop +public void test0037_autounboxing_1() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " void foo1(boolean b) {\n" + + " int j = 0;\n" + + " Integer i = null;\n" + + " while (true) {\n" + + " try {\n" + + " j = 1;\n" + + " } finally {\n" + + " j = (b?i:1)+1;\n" + + " i = 2;\n" + + " }\n" + + " }\n" + + " }\n" + + " void foo2(boolean b) {\n" + + " int j = 0;\n" + + " Integer i = null;\n" + + " try {\n" + + " j = 1;\n" + + " } finally {\n" + + " j = (b?i:1)+1;\n" + + " i = 2;\n" + + " }\n" + + " }\n" + + "}\n"}, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " j = (b?i:1)+1;\n" + + " ^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " j = (b?i:1)+1;\n" + + " ^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/403147 [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking +// inject pot.nn from try into finally +public void test0037_autounboxing_2() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " void foo2(boolean b) {\n" + + " int j = 0;\n" + + " Integer i = null;\n" + + " while (true) {\n" + + " try {\n" + + " if (b)\n" + + " i = 3;\n" + + " } finally {\n" + + " j = (b?i:1)+1;\n" + + " }\n" + + " }\n" + + " }\n" + + " void foo3(boolean b) {\n" + + " int j = 0;\n" + + " Integer i = null;\n" + + " try {\n" + + " if (b)\n" + + " i = 3;\n" + + " } finally {\n" + + " j = (b?i:1)+1;\n" + + " }\n" + + " }\n" + + "}\n"}, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " j = (b?i:1)+1;\n" + + " ^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " j = (b?i:1)+1;\n" + + " ^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/403147 [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking +// null from try, nn from catch, merge both into finally +public void test0037_autounboxing_3() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " void foo3(Integer i, boolean b) {\n" + + " int j = 0;\n" + + " while (true) {\n" + + " try {\n" + + " i = null;\n" + + " unsafe();\n" + + " } catch (Exception e) {\n" + + " i = 3;\n" + + " } finally {\n" + + " j = (b?i:1)+1;\n" + + " }\n" + + " }\n" + + " }\n" + + " void foo4(Integer i, boolean b) {\n" + + " int j = 0;\n" + + " try {\n" + + " i = null;\n" + + " unsafe();\n" + + " } catch (Exception e) {\n" + + " i = 3;\n" + + " } finally {\n" + + " while (j < 0)\n" + + " j = (b?i:1)+1;\n" + + " }\n" + + " }\n" + + "\n" + + " private void unsafe() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + "}\n"}, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " j = (b?i:1)+1;\n" + + " ^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in X.java (at line 24)\n" + + " j = (b?i:1)+1;\n" + + " ^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/403147 [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking +// effective protection locally within the finally block +public void test0037_autounboxing_4() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo3(Integer i, boolean b) {\n" + + " int j = 0;\n" + + " while (true) {\n" + + " try {\n" + + " i = null;\n" + + " unsafe();\n" + + " } catch (Exception e) {\n" + + " i = 3;\n" + + " } finally {\n" + + " if (i == null) i = 4;\n" + + " j = (b?i:1)+1;\n" + + " }\n" + + " }\n" + + " }\n" + + " void foo4(Integer i, boolean b) {\n" + + " int j = 0;\n" + + " try {\n" + + " i = null;\n" + + " unsafe();\n" + + " } catch (Exception e) {\n" + + " i = 3;\n" + + " } finally {\n" + + " while (i == null)\n" + + " i = 4;\n" + + " while (j < 4)\n" + + " j = (b?i:1)+1;\n" + + " }\n" + + " }\n" + + "\n" + + " private void unsafe() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + "}\n"}, + options); +} +// https://bugs.eclipse.org/403147 [compiler][null] FUP of bug 400761: consolidate interaction between unboxing, NPE, and deferred checking +// array reference in nested try +public void test0037_autounboxing_5() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object [] o, boolean b, Integer i) {\n" + + " int j = 1;\n" + + " try {\n" + + " if (b) i = null;\n" + + " } catch (RuntimeException r) {\n" + + " i = 3;\n" + + " } finally {\n" + + " try {\n" + + " System.out.println(o[i]); \n" + + " } finally {\n" + + " System.out.println(j);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + null, + options, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " System.out.println(o[i]); \n" + + " ^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// Bug 406384 - Internal error with I20130413 +public void test0037_autounboxing_6() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void test(List l1, List l2, int i, Object val) {\n" + + " for (String s1 : l1) {\n" + + " for (String s2 : l2) {\n" + + " switch (i) {\n" + + " case 1: \n" + + " boolean booleanValue = (Boolean)val;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }); +} + +// null analysis -- autoboxing +public void test0040_autoboxing_compound_assignment() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Integer i = null;\n" + + " i += 1;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " i += 1;\n" + + " ^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- autoboxing +public void test0041_autoboxing_increment_operator() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Integer i = null;\n" + + " i++;\n" + // complain: this is null + " ++i;\n" + // quiet (because previous step guards it) + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " i++;\n" + + " ^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- autoboxing +public void test0042_autoboxing_literal() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Integer i = 0;\n" + + " if (i == null) {};\n" + // complain: this is non null + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (i == null) {};\n" + + " ^\n" + + "Null comparison always yields false: The variable i cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (i == null) {};\n" + + " ^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- autoboxing +public void test0043_autoboxing_literal() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Integer i = null;\n" + + " System.out.println(i + 4);\n" + // complain: this is null + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " System.out.println(i + 4);\n" + + " ^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- autoboxing +// origin: AssignmentTest#test020 +public void test0044_autoboxing() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " int i = 0;\n" + + " boolean b = i < 10;\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- autoboxing +// variant of 42 for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=165346 +public void test0045_autoboxing_operator() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " int j = 5;" + + " Integer i = 0 + j;\n" + + " if (i == null) {}\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (i == null) {}\n" + + " ^\n" + + "Null comparison always yields false: The variable i cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (i == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- array +public void test0050_array() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " args = new String[] {\"zero\"};\n" + + " args[0] = null;\n" + + " if (args[0] == null) {};\n" + + // quiet: we don't keep track of all array elements + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- array +public void test0051_array() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " args = null;\n" + + " args[0].toString();\n" + // complain: args is null + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " args[0].toString();\n" + + " ^^^^\n" + + "Null pointer access: The variable args can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- array +public void test0052_array() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String args[]) {\n" + + " String s = args[0];\n" + + " if (s == null) {};\n" + + // quiet: we don't keep track of all array elements + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- array +public void test0053_array() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String args[]) {\n" + + " for (int i = 0; i < args.length; i++) { /* */}\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- method call +public void test0061_method_call_guard() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o.toString();\n" + // guards o from being null + " if (o == null) {};\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o == null) {};\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o == null) {};\n" + + " ^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - method call +public void test0062_method_call_isolation() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (bar(o = null)) {\n" + + " if (o == null) {/* empty */}\n" + // complain + " }\n" + + " }\n" + + " boolean bar(Object o) {\n" + + " return true;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o == null) {/* empty */}\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - method call +public void test0063_method_call_isolation() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (bar(o == null ? new Object() : o)) {\n" + + " if (o == null) {/* empty */}\n" + // quiet + " }\n" + + " }\n" + + " boolean bar(Object o) {\n" + + " return true;\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - method call +public void test0064_method_call_isolation() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (bar(o = new Object())) {\n" + + " if (o == null) {/* empty */}\n" + // complain + " }\n" + + " }\n" + + " boolean bar(Object o) {\n" + + " return true;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o == null) {/* empty */}\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o == null) {/* empty */}\n" + + " ^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - method call +public void test0065_method_call_invocation_target() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " (o = new Object()).toString();\n" + // quiet + " }\n" + + "}\n"}, + ""); +} + +// null analysis - method call +public void test0066_method_call_invocation_target() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " (o = null).toString();\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " (o = null).toString();\n" + + " ^^^^^^^^^^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - method call +public void test0067_method_call_invocation_target() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " (o = new Object()).toString();\n" + // quiet + " if (o == null) { /* */ }\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - method call +public void test0068_method_call_assignment() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar() {\n" + + " return null;\n" + + " }\n" + + " void foo(X x) {\n" + + " x = x.bar();\n" + + " if (x == null) { /* */ }\n" + // quiet + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- type reference +public void test0070_type_reference() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Class c = java.lang.Object.class;\n" + + " if (c == null) {};\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (c == null) {};\n" + + " ^\n" + + "Null comparison always yields false: The variable c cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (c == null) {};\n" + + " ^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test0080_shortcut_boolean_expressions() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1, Object o2) {\n" + + " if (o1 != null && (o2 = o1) != null) { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (o1 != null && (o2 = o1) != null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Redundant null check: The variable o2 cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test0081_shortcut_boolean_expressions() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1, Object o2) {\n" + + " while (o1 != null && (o2 = o1) != null) { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " while (o1 != null && (o2 = o1) != null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Redundant null check: The variable o2 cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - shortcut boolean expression +public void test0082_shortcut_boolean_expression() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o == null || o == null) {\n" + + " o = new Object();\n" + + " }\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (o == null || o == null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - shortcut boolean expression +public void test0083_shortcut_boolean_expression() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o == null && o == null) {\n" + + " o = new Object();\n" + + " }\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (o == null && o == null) {\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - shortcut boolean expression +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=130311 +public void test0084_shortcut_boolean_expression() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean foo(Integer i1, Integer i2) {\n" + + " return (i1 == null && i2 == null)\n" + + " || (i1.byteValue() == i2.byteValue());\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " || (i1.byteValue() == i2.byteValue());\n" + + " ^^\n" + + "Potential null pointer access: The variable i1 may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - shortcut boolean expression +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=130311 +public void test0085_shortcut_boolean_expression() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean foo(Integer i1, Integer i2) {\n" + + " return (i1 == null & i2 == null)\n" + + " || (i1.byteValue() == i2.byteValue());\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " || (i1.byteValue() == i2.byteValue());\n" + + " ^^\n" + + "Potential null pointer access: The variable i1 may be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " || (i1.byteValue() == i2.byteValue());\n" + + " ^^\n" + + "Potential null pointer access: The variable i2 may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - shortcut boolean expression and correlation +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=195774 +public void test0086_shortcut_boolean_expression() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(Integer i, Integer j) {\n" + + " if (i == null && j == null) {\n" + + " return 1;\n" + + " }\n" + + " if (i == null) {\n" + + " return j.intValue();\n" + + " }\n" + + " if (j == null) {\n" + + " return i.intValue();\n" + + " }\n" + + " return 0;\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - shortcut boolean expression and correlation +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=195774 +public void _test0087_shortcut_boolean_expression() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(Integer i, Integer j) {\n" + + " if (i == null && j == null) {\n" + + " return 1;\n" + + " }\n" + + " if (j == null) {\n" + + " return i.intValue();\n" + + " }\n" + + " if (i == null) {\n" + + " return j.intValue();\n" + + " }\n" + + " return 0;\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis -- instanceof +// JLS: instanceof returns false if o turns out to be null +public void test0090_instanceof() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " boolean dummy;\n" + + " void foo (Object o) {\n" + + " if (dummy) {\n" + + " o = null;\n" + + " }\n" + + " if (o instanceof X) { /* */ }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis -- instanceof +public void test0091_instanceof() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " boolean dummy;\n" + + " void foo (Object o) {\n" + + " if (dummy) {\n" + + " o = null;\n" + + " }\n" + + " if (o instanceof X) { /* */ }\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis -- instanceof +// can only be null always yields false +public void test0092_instanceof() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " boolean dummy;\n" + + " void foo () {\n" + + " Object o = null;\n" + + " if (o instanceof X) { /* */ }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o instanceof X) { /* */ }\n" + + " ^\n" + + "instanceof always yields false: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- instanceof +public void test0093_instanceof() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object x) {\n" + + " if (x instanceof X) {\n" + + " if (x == null) { /* */ }\n" + // cannot happen + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (x == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable x cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (x == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- instanceof +public void test0094_instanceof() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object x) {\n" + + " if (x instanceof X) {\n" + + " return;\n" + + " }\n" + + " if (x != null) { /* */ }\n" + + // cannot decide: could be null of new Object() for example + " }\n" + + "}"}, + ""); +} + +// null analysis -- instanceof combined with conditional or +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=145202 +public void test0095_instanceof_conditional_or() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object x) {\n" + + " if (! (x instanceof String)\n" + + " || x == null) {\n" + + " return;\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " || x == null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable x cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- strings concatenation +// JLS 15.18.1: if one of the operands is null, it is replaced by "null" +// Note: having the diagnostic could come handy when the initialization path +// is non trivial; to get the diagnostic, simply put in place an +// extraneous call to toString() -- and remove it before releasing. +public void test0120_strings_concatenation() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo(String s1, String s2) {\n" + + " if (s1 == null) { /* */ };\n" + + " return s1 + s2;\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- strings concatenation +public void test0121_strings_concatenation() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo(String s1, String s2) {\n" + + " if (s1 == null) { /* */ };\n" + + " s1 += s2;\n" + + " return s1;\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- strings concatenation +public void test0122_strings_concatenation() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo(String s1) {\n" + + " if (s1 == null) { /* */ };\n" + + " return s1.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return s1.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable s1 may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- strings concatenation +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127919 +// it should suffice that the return type is String to avoid +// errors +public void test0123_strings_concatenation() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo(String s, Object o, Integer i) {\n" + + " if (s == null || o == null || i == null) { /* */ };\n" + + " if (bar()) {\n" + + " return s + i;\n" + // quiet: i replaced by "null" if null + " }\n" + + " return o + s;\n" + // quiet: o replaced by "null" if null + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- strings concatenation +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127919 +// variant +public void test0124_strings_concatenation() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo(String s, Object o, Integer i) {\n" + + " if (s == null || o == null || i == null) { /* */ };\n" + + " s += o;\n" + // quiet: o replaced by "null" if null + " s += i;\n" + // quiet: i replaced by "null" if null + " return s;\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- strings concatenation +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127919 +// variant +public void test0125_strings_concatenation() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, Integer i) {\n" + + " System.out.println(o + (o == null ? \"\" : o.toString()));\n" + // quiet: o replaced by "null" if null + " System.out.println(i + (i == null ? \"\" : i.toString()));\n" + // quiet: o replaced by "null" if null + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- strings concatenation +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=132867 +public void test0126_strings_concatenation() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " System.out.println(o + \"\");\n" + + " if (o != null) { /* */ };\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- strings concatenation +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=132867 +public void test0127_strings_concatenation() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " System.out.println(o + \"\");\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- if/else +// check that obviously unreachable code does not modify the null +// status of a local +// the said code is not marked as unreachable per JLS 14.21 (the rationale +// being the accommodation for the if (constant_flag_evaluating_to_false) +// {code...} volontary code exclusion pattern) +public void test0300_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Object o = null;\n" + + " if (false) {\n" + + " o = new Object();\n" + // skipped + " }\n" + + " if (true) {\n" + + " //\n" + + " }\n" + + " else {\n" + + " o = new Object();\n" + // skipped + " }\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " o = new Object();\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " else {\n" + + " o = new Object();\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0301_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " if (o != null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0302_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) throws Exception {\n" + + " if (o == null) {\n" + + " throw new Exception();\n" + + " }\n" + + " if (o != null) {\n" + // only get there if o non null + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o != null) {\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0303_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o == null) {\n" + + " return;\n" + + " }\n" + + " if (o != null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o != null) {\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0304_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o == null) {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0305_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o == null) {\n" + + " // do nothing\n" + + " }\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0306_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o.toString().equals(\"\")) {\n" + + " if (o == null) {\n" + // complain: could not get here + " // do nothing\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o == null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o == null) {\n" + + " // do nothing\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0307_if_else() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o == null) {\n" + + " System.exit(0);\n" + + " }\n" + + " if (o == null) {\n" + + // quiet + // a direct call to System.exit() can be recognized as such; yet, + // a lot of other methods may have the same property (aka calling + // System.exit() themselves.) + " // do nothing\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - if/else +public void test0308_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo(Object o) {\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o.toString();\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0309_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b1, b2;\n" + + " void foo(Object o) {\n" + + " if (b1) {\n" + + " o = null;\n" + + " }\n" + + " if (b2) {\n" + + " o = new Object();\n" + + " }\n" + + " o.toString();\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0310_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b1, b2;\n" + + " void foo(Object o) {\n" + + " if (b1) {\n" + + " o = null;\n" + + " }\n" + + " if (b2) {\n" + + " o.toString();\n" + // complain + " o.toString();\n" + // silent + " }\n" + + " o.toString();\n" + // complain + " }\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" + + "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); +} + +// null analysis - if/else +public void test0311_if_else() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o == null)\n" + + " o = new Object();\n" + + " o.toString();\n" + // quiet + " }\n" + + "}" }, + ""); +} + +// null analysis - if/else +public void test0312_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " if (o == null) { /* */ }\n" + // complain + " if (o != null) { /* */ }\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0313_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o == null) {\n" + // quiet + " o = new Object();\n" + + " }\n" + + " if (o == null) { /* */ }\n" + + // complain: o set to non null iff it was null + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0314_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o != null) {\n" + // quiet + " o = null;\n" + + " }\n" + + " if (o == null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0315_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o != null) {\n" + // quiet + " o = null;\n" + + " }\n" + + " o.toString();\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0316_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (o == null || b) { /* */ }\n" + // quiet + " else { /* */ }\n" + + " o.toString();\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0317_if_else_nested() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (o != null) {\n" + // quiet + " if (b) {\n" + // quiet + " o = null;\n" + + " }\n" + + " }\n" + + " if (o == null) { /* */ }\n" + // quiet + " }\n" + + "}"}, + ""); +} + +// null analysis - if/else +public void test0318_if_else_nested() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (o != null) {\n" + // quiet + " if (b) {\n" + // quiet + " o = null;\n" + + " }\n" + + " if (o == null) { /* */ }\n" + // quiet + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - if/else +// we do nothing to diagnose the contents of fake reachable code +public void test0319_if_else_dead_branch() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (false) {\n" + + " o = null;\n" + + " if (o == null) { /* */ }\n" + // may have considered complaining here + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - if/else +public void test0320_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o.toString();\n" + + " if (o == null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0321_if_else() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " Object other = new Object();\n" + + " if (b) {\n" + + " other = o;\n" + + " }\n" + + " if (o != null) { /* */ }\n" + // quiet + " }\n" + + "}"}, + ""); +} + +// null analysis - if/else +public void test0322_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " o.toString();\n" + + " if (b) { /* */ }\n" + + " if (o == null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0323_if_else() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (o == null && b) {\n" + + " o = new Object();\n" + + " }\n" + + " if (o == null) { /* */ }\n" + // quiet + " }\n" + + "}"}, + ""); +} + +// null analysis - if/else +public void test0324_if_else_nested() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " void foo (boolean b) {\n" + + " String s = null;\n" + + " if (b) {\n" + + " if (b) {\n" + + " s = \"1\";\n" + + " } \n" + + " else {\n" + + " s = \"2\";\n" + + " }\n" + + " } \n" + + " else if (b) {\n" + + " s = \"3\"; \n" + + " } \n" + + " else {\n" + + " s = \"4\";\n" + + " }\n" + + " s.toString();\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - if/else +public void test0325_if_else_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo (boolean b) {\n" + + " String s = null;\n" + + " if (b) {\n" + + " if (b) {\n" + + " s = \"1\";\n" + + " } \n" + + " else {\n" + + " s = \"2\";\n" + + " }\n" + + " } \n" + + " else if (b) {\n" + + " if (b) {\n" + + " s = \"3\"; \n" + + " }\n" + + " } \n" + + " else {\n" + + " s = \"4\";\n" + + " }\n" + + " s.toString();\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " s.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +// limit: we cannot sync on external factors, even if this is a pattern +// that is quite used +public void test0326_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo (boolean b) {\n" + + " String s1 = null;\n" + + " if (b) {\n" + + " s1 = \"1\";\n" + + " }\n" + + " s1.toString();\n" + // complain: can't guess if b means anything for s1 init + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " s1.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable s1 may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +// limit: we cannot sync on external factors, even if this is a pattern +// that is quite used +public void test0327_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo (String s1) {\n" + + " String s2 = null;\n" + + " if (s1 == null) {\n" + + " s1 = \"1\";\n" + + " s2 = \"2\";\n" + + " }\n" + + " s1.toString();\n" + // quiet + " s2.toString();\n" + // complain: can't guess whether s2 depends on s1 for init + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " s2.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable s2 may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0328_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (o != null || b) {\n" + + " if (b) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + // quiet + " else { /* */ }\n" + + " o.toString();\n" + // complain + " }\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); +} + +// null analysis - if/else +public void test0329_if_else_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (b) {\n" + + " if (o != null) { /* */ }\n" + // shade doubts on o + " }\n" + + " o.toString();\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +public void test0330_if_else_nested() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (b) {\n" + + " if (o == null) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " o.toString();\n" + // quiet + " }\n" + + "}"}, + ""); +} + +// null analysis - if/else +public void test0331_if_else_nested() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1, Object o2) {\n" + + " Object o3 = o2;\n" + + " if (o1 != null) {\n" + + " o3.toString(); // guards o3\n" + + " }\n" + + " o1 = o3;\n" + + " if (o1 != null) { /* */ }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - if/else +public void test0332_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " o = new Object();\n" + + " if (b) {\n" + + " o = new Object();\n" + + " }\n" + + " if (o != null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128014 +// invalid analysis when redundant check is done +public void test0333_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o = new Object();\n" + + " if (o != null) {\n" + // complain + " o.toString();\n" + + " }\n" + + " o.toString();\n" + // quiet asked + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128014 +// invalid analysis when redundant check is done - variant +public void test0334_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o = new Object();\n" + + " if (o != null) {\n" + // complain + " o.toString();\n" + + " }\n" + + " else {\n" + + " o.toString();\n" + + " }\n" + + " o.toString();\n" + // quiet + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " else {\n" + + " o.toString();\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129581 +// Test that no false null reference warning is issued for a variable +// that has been wrongly tainted by a redundant null check upstream. +public void test0335_if_else() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o != null) {\n" + + " if (o != null) {\n" + // complain + " o.toString();\n" + + " }\n" + + " o.toString();\n" + // quiet + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n"); +} + +// null analysis - if/else +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128014 +// invalid analysis when redundant check is done - variant +public void test0336_if_else() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o != null) {\n" + + " if (o != null) {\n" + // complain + " o.toString();\n" + + " }\n" + + " else {\n" + + " o.toString();\n" + // must complain anyway (could be quite distant from the if test) + " }\n" + + " o.toString();\n" + // quiet + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " else {\n" + + " o.toString();\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + + +// null analysis - if/else nested with correlation +// reconsider if we implement correlation +// TODO (maxime) https://bugs.eclipse.org/bugs/show_bug.cgi?id=128861 +public void _test0337_if_else_nested_correlation() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int foo (Object o1, Object o2) {\n" + + " int result = 0;\n" + + " if (o1 == null && o2 != null) {\n" + + " result = -1;\n" + + " } else {\n" + + " if (o1 == null && o2 == null) {\n" + + " result = 0;\n" + + " } else {\n" + + " if (o1 != null && o2 == null) {\n" + + " result = 1;\n" + + " } else {\n" + + " int lhs = ((Y) o1).foo(); // may be null\n" + + " int rhs = ((Y) o2).foo();\n" + + " result = lhs - rhs;\n" + + " }\n" + + " }\n" + + " }\n" + + " return result;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " abstract int foo();\n" + + "}\n" + + "\n"}, + ""); +} + +// null analysis - if/else nested with correlation +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128861 +// workaround +public void test0338_if_else_nested() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int foo (Object o1, Object o2) {\n" + + " int result = 0;\n" + + " if (o1 == null && o2 == null) {\n" + + " result = 0;\n" + + " } else {\n" + + " if (o1 == null) {\n" + + " result = -1;\n" + + " } else {\n" + + " if (o2 == null) {\n" + + " result = 1;\n" + + " } else {\n" + + " int lhs = ((Y) o1).foo();\n" + + " int rhs = ((Y) o2).foo();\n" + + " result = lhs - rhs;\n" + + " }\n" + + " }\n" + + " }\n" + + " return result;\n" + + " }\n" + + "}\n" + + "abstract class Y {\n" + + " abstract int foo();\n" + + "}\n" + + "\n"}, + ""); +} + +// null analysis - if/else nested with unknown protection: unknown cannot protect +public void test0339_if_else_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (o == null || b) {\n" + + " if (bar() == o) {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + " Object bar() {\n" + + " return new Object();\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else nested +public void test0340_if_else_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o == null) {\n" + + " if (bar() == o) {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + " Object bar() {\n" + + " return new Object();\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else nested +public void test0341_if_else_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1, Object o2, boolean b) {\n" + + " if (o1 == null || b) {\n" + + " if (o1 == o2) {\n" + + " o1.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o1.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable o1 may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - if/else nested +public void test0342_if_else_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1, Object o2, boolean b) {\n" + + " if (o1 == null || b) {\n" + + " if (o2 == o1) {\n" + + " o1.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o1.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable o1 may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0401_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (o.toString() != null) {/* */}\n" + + // complain: NPE + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " while (o.toString() != null) {/* */}\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0402_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (o != null) {/* */}\n" + + // complain: get o null first time and forever + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " while (o != null) {/* */}\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0403_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (o == null) {\n" + + // quiet: first iteration is sure to find o null, + // but other iterations may change it + " o = new Object();\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- while +public void test0404_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (o == null) {\n" + + // quiet: first iteration is sure to find o null, + // but other iterations may change it + " if (System.currentTimeMillis() > 10L) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- while +public void test0405_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() {\n" + + " return true;\n" + + " }\n" + + " void foo(Object o) {\n" + + " while (bar() && o == null) {\n" + + " o.toString();\n" + // complain: NPE + " o = new Object();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0406_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo(Object o) {\n" + + " o = null;\n" + + " while (dummy || o != null) { /* */ }\n" + // o can only be null + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " while (dummy || o != null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0407_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (dummy) {\n" + + " o.toString();\n" + // complain: NPE on first iteration + " o = new Object();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +// this test shows that, as long as we do not explore all possible +// paths, we have to take potential initializations into account +// even in branches that could be pruned in the first passes +// first approximation is to stop pruning code conditioned by +// variables +// second approximation could still rely upon variables that are +// never affected by the looping code (unassigned variables) +// complete solution would call for multiple iterations in the +// null analysis +public void test0408_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null,\n" + + " u = new Object(),\n" + + " v = new Object();\n" + + " while (o == null) {\n" + + " if (v == null) {\n" + + " o = new Object();\n" + + " };\n" + + " if (u == null) {\n" + + " v = null;\n" + + " };\n" + + " u = null;\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- while +public void test0409_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (dummy || (o = new Object()).equals(o)) {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0410_while_nested() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (dummy) {\n" + + " while (o != null) {\n" + + " o.toString();\n" + + " }\n" + + " if (System.currentTimeMillis() > 10L) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- while +public void test0411_while_nested() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null,\n" + + " u = new Object(),\n" + + " v = new Object();\n" + + " while (o == null) {\n" + + " if (v == null) {\n" + + " o = new Object();\n" + + " };\n" + + " while (o == null) {\n" + + " if (u == null) {\n" + + " v = null;\n" + + " };\n" + + " u = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- while +public void test0412_while_if_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy, other;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (dummy) {\n" + + " if (other) {\n" + + " o.toString();\n" + + " }\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0413_while_unknown_field() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + " void foo(boolean dummy) {\n" + + " while (dummy) {\n" + + " o = null;\n" + + " }\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- while +public void test0414_while_unknown_parameter() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo(Object o) {\n" + + " while (dummy) {\n" + + " o = null;\n" + // quiet: first iteration doesn't know + " }\n" + + " o.toString();\n" + // complain: only get out of the loop with null + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0415_while_unknown_if_else() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " if (dummy) {\n" + + " o = new Object();\n" + + " }\n" + + " while (dummy) {\n" + + // limit of the analysis: we do not correlate if and while conditions + " if (o == null) {/* */}\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- while +public void test0416_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (dummy) {\n" + + " o = new Object();\n" + + " }\n" + + " o.toString();\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 analysis -- while +public void test0417_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (dummy) { /* */ }\n" + // doesn't affect o + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +// origin AssignmentTest.testO22 +public void test0418_while_try() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bool() { return true; }\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (bool()) {\n" + + " try {\n" + + " if (o == null) {\n" + + " o = new Object();\n" + + " }\n" + + " } finally { /* */ }\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis -- while +public void test0419_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bool;\n" + + " void foo(Object o) {\n" + + " while (bool) {\n" + + " o.toString();" + // complain NPE because of second iteration + " o = null;\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o.toString(); o = null;\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0420_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bool;\n" + + " void foo(Object compare) {\n" + + " Object o = new Object();\n" + + " while ((o = null) == compare) {\n" + + " if (true) {\n" + + " break;\n" + + " }\n" + + " }\n" + + " if (o == null) { /* */ }\n" + // complain can only be null + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0421_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bool;\n" + + " void foo(Object compare) {\n" + + " Object o = null;\n" + + " while (bool) {\n" + + " o = new Object();\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis -- while +public void test0422_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bool;\n" + + " void foo() {\n" + + " Object o;\n" + + " while (bool) {\n" + + " o = new Object();\n" + + " if (o == null) { /* */ }\n" + + " o = null;\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0423_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bool;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (bool) {\n" + + " o = new Object();\n" + + " if (o == null) { /* */ }\n" + + " o = null;\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0424_while_try() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " Object o = null;\n" + + " while (o == null) {\n" + + // quiet: first iteration is sure to find o null, + // but other iterations may change it + " try { /* */ }\n" + + " finally {\n" + + " if (b) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- while +public void test0425_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo(Object u) {\n" + + " Object o = null;\n" + + " while (dummy) {\n" + + " o = u;\n" + + " }\n" + + " o.toString();\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 analysis -- while +public void test0426_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo(Object o) {\n" + + " o.toString();\n" + + " while (dummy) { /* */ }\n" + + " if (o == null) { /* */ }\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- while +public void test0427_while_return() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (dummy) {\n" + + " if (o == null) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null) {\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +public void test0428_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar() {\n" + + " return null;\n" + + " }\n" + + " void foo(X x) {\n" + + " x.bar();\n" + + " while (x != null) {\n" + + " x = x.bar();\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - while +public void test0429_while_nested() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " boolean dummy;\n" + + " void foo (X[] xa) {\n" + + " while (dummy) {\n" + + " xa = null;\n" + + " if (dummy) {\n" + + " xa = new X[5];\n" + + " }\n" + + " if (xa != null) {\n" + + " int i = 0;\n" + + " while (dummy) {\n" + + " X x = xa[i++];\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0430_while_for_nested() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " boolean dummy;\n" + + " void foo (X[] xa) {\n" + + " while (dummy) {\n" + + " xa = null;\n" + + " if (dummy) {\n" + + " xa = new X[5];\n" + + " }\n" + + " if (xa != null) {\n" + + " for (int i = 0; i < xa.length; i++) {\n" + + " X x = xa[i];\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0431_while() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " boolean dummy;\n" + + " void foo (X x) {\n" + + " x = null;\n" + + " while (dummy) {\n" + + " x = bar();\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + " X bar() {\n" + + " return null;\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0432_while() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " boolean dummy;\n" + + " void foo (X x) {\n" + + " while (dummy) {\n" + + " x = bar();\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + " X bar() {\n" + + " return null;\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0433_while() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " boolean dummy;\n" + + " void foo (X x) {\n" + + " x = null;\n" + + " while (dummy) {\n" + + " x.toString();\n" + // complain and protect + " x.toString();\n" + // quiet + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x.toString();\n" + + " ^\n" + + "Null pointer access: The variable x can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +// this one shows that we cannot project definitely unknown onto potentially unknown too soon +public void test0434_while_switch_nested() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " Object bar() {\n" + + " return new Object();\n" + + " }\n" + + " void foo(boolean b, int selector) {\n" + + " Object o = null;\n" + + " while (b) {\n" + + " switch (selector) {\n" + + " case 0:\n" + + " o = bar();\n" + + " if (o != null) { \n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0435_while_init() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " int f1;\n" + + " X f2;\n" + + " void foo(X x1, boolean b) {\n" + + " X x2;\n" + + " x2 = x1;\n" + + " while (b) {\n" + +// " if (x2.f1 > 0) { /* */ }\n" + + " if (x2.toString().equals(\"\")) { /* */ }\n" + + " x2 = x2.f2;\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0436_while_init() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " int f1;\n" + + " X f2;\n" + + " void foo(X x1, boolean b) {\n" + + " X x2 = x1;\n" + + " while (b) {\n" + + " if (x2.f1 > 0) { /* */ }\n" + + " x2 = x2.f2;\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0437_while_exit() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(boolean b) {\n" + + " Object o = null;\n" + + " while (b) {\n" + + " if (b) {\n" + + " o = new Object();\n" + + " }\n" + + " if (o != null) {\n" + + " throw new RuntimeException(); \n" + + " }\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + + +// null analysis - while +public void test0438_while() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object o) {\n" + + " while (o == null) { /* */ }\n" + + " o.toString();\n" + // quiet + " if (o != null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +public void test0439_while() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object o) {\n" + + " while (o == null) {\n" + + " o = new Object();\n" + + " }\n" + + " o.toString();\n" + // quiet + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0440_while() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object o) {\n" + + " while (o == null) {\n" + + " o = new Object();\n" + + " }\n" + + " if (o != null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +public void test0441_while() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " X bar() {\n" + + " return new X();\n" + + " }\n" + + " void foo(Object o) {\n" + + " while (o == null) {\n" + + " o = bar();\n" + + " }\n" + + " if (o != null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +public void test0442_while() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " boolean bar() {\n" + + " return true;\n" + + " }\n" + + " void foo(Object o) {\n" + + " while (o == null && bar()) { /* */ }\n" + + " o.toString();\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +public void test0443_while_nested() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " ext: for (int i = 0; i < 5 ; i++) {\n" + + " if (o != null) {\n" + + " break;\n" + + " }\n" + + " o = new Object();\n" + + " int j = 0;\n" + + " while (j++ < 2) {\n" + + " continue ext;\n" + + " }\n" + + " return;\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0444_while_deeply_nested() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(boolean b) {\n" + + " Object o = null;\n" + + " ext: for (int i = 0; i < 5 ; i++) {\n" + + " if (o != null) {\n" + + " break;\n" + + " }\n" + + " do {\n" + + " o = new Object();\n" + + " int j = 0;\n" + + " while (j++ < 2) {\n" + + " continue ext;\n" + + " }\n" + + " } while (b);\n" + + " return;\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0445_while_deeply_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(boolean b) {\n" + + " Object o = null;\n" + + " ext: for (int i = 0; i < 5 ; i++) {\n" + + " if (o != null) {\n" + + " break;\n" + + " }\n" + + " do {\n" + + " // o = new Object();\n" + + " int j = 0;\n" + + " while (j++ < 2) {\n" + + " continue ext;\n" + + " }\n" + + " } while (b);\n" + + " return;\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o != null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +public void test0446_while() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object o, boolean b) {\n" + + " while (o == null || b) {\n" + + " o = new Object();\n" + + " }\n" + + " if (o != null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +public void test0447_while() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object o, boolean b) {\n" + + " while (o == null & b) {\n" + + " o = new Object();\n" + + " }\n" + + " if (o != null) { /* */ }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0448_while() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(boolean b[]) {\n" + + " Object o = null;\n" + + " ext: for (int i = 0; i < 5 ; i++) {\n" + + " if (o != null) {\n" + + " break;\n" + + " }\n" + + " while (b[1]) {\n" + + " continue ext;\n" + + " }\n" + + " while (b[2]) {\n" + + " continue ext;\n" + + " }\n" + + " while (b[3]) {\n" + + " continue ext;\n" + + " }\n" + + " while (b[4]) {\n" + + " continue ext;\n" + + " }\n" + + " while (b[5]) {\n" + + " continue ext;\n" + + " }\n" + + " while (b[6]) {\n" + + " continue ext;\n" + + " }\n" + + " return;\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o != null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +// this series (up to 451) shows that the merge of the states +// potential non null and potential unknown yields damages in +// case of nested loops (unested loops still OK because we can +// carry the definite non null property) +public void test0449_while_nested() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object p, boolean b) {\n" + + " Object o = new Object();\n" + + " while (b) {\n" + + " while (b) {\n" + + " o = p;\n" + // now o is unknown + " }\n" + + " }\n" + + " if (o != null) { /* */ }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +public void test0450_while() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(boolean b) {\n" + + " Object o = new Object();\n" + + " while (b) {\n" + + " o = new Object();\n" + // o still non null + " }\n" + + " if (o != null) { /* */ }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133131 +public void test0451_while_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(boolean b) {\n" + + " Object o = new Object();\n" + + " while (b) {\n" + + " while (b) {\n" + + " o = new Object();\n" + // o still non null + " }\n" + + " }\n" + + " if (o != null) { /* */ }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=123399 +// variant - the bug is not specific to the do while loop +public void _test0452_while() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object doubt) {\n" + + " Object o = null;\n" + + " while (true) {\n" + + " if (o == null) {\n" + + " return;\n" + + " }\n" + + " o = doubt;\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null) {\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=123399 +// variant - cannot refine the diagnostic without engaging into conditionals +// dedicated flow context +public void _test0453_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object doubt, boolean b) {\n" + + " Object o1 = null, o2 = null;\n" + + " while (true) {\n" + + " if (o1 == null) { /* empty */ }\n" + + " if (b) {\n" + + " if (o2 == null) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " o1 = o2 = doubt;\n" + + " }\n" + + " }\n" + + "}"}, + "ERROR: complain on line 7, but not on line 5" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129122 +public void test0454_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object bar() {\n" + + " return new Object();\n" + + " }\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (true) {\n" + + " o = bar();\n" + + " if (o != null) {\n" + + " o = new Object();\n" + + " }\n" + + " o = null; // quiet pls\n" + + " }\n" + + " }\n" + + "}"}, + "" + ); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133131 +// variant +public void test0455_while_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(boolean b) {\n" + + " Object o = new Object();\n" + + " while (b) {\n" + + " o = new Object();\n" + // o still non null + " }\n" + + " if (o != null) { /* */ }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=134848 +// false positive after nested loop with break to explicit label +public void test0456_while_nested_explicit_label() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " while (true) {\n" + + " if (o != null) {\n" + + " o.toString();\n" + + " loop: while (true) {\n" + + " break loop;\n" + + " }\n" + + " o.toString();\n" + // must not complain here + " }\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=154995 +public void test0457_while_nested_break() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(String p, String q, boolean b) {\n" + + " while (b) {\n" + + " String e = q;\n" + + " e.trim();\n" + + " while (true) {\n" + + " if (b)\n" + + " e = q;\n" + + " else\n" + + " e = null;\n" + + " if (e == null || p != null) {\n" + + " if (e != null) {\n" + // should not complain here + " // Do something\n" + + " }\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=134848 +// variant: no label yields no problem +public void test0458_while_nested_explicit_label() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " while (true) {\n" + + " if (o != null) {\n" + + " o.toString();\n" + + " while (true) {\n" + + " break;\n" + + " }\n" + + " o.toString();\n" + // must not complain here + " }\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis -- while nested hits CAN_ONLY_NON_NULL +public void test0459_while_nested() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " Object o = b ? null : new Object(),\n" + + " u = new Object(),\n" + + " v = new Object();\n" + + " while (o != null) {\n" + + " while (b) {\n" + + " if (v == null) {\n" + + " o = new Object();\n" + + " };\n" + + " while (o == null) {\n" + + " if (u == null) {\n" + + " v = null;\n" + + " };\n" + + " u = null;\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " while (o == null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472 +// extraneous error in case of a labeled while(true) statement +public void test0460_while_explicit_label() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(int i) {\n" + + " Object o = null;\n" + + " done: while (true) {\n" + + " switch (i) {\n" + + " case 0:\n" + + " o = new Object();\n" + + " break;\n" + + " case 1:\n" + + " break done;\n" + + " }\n" + + " }\n" + + " if (o == null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472 +// extraneous error in case of a labeled while(true) statement +public void test0461_while_explicit_label() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean test() {\n" + + " return true;\n" + + " }\n" + + " void foo() {\n" + + " Object o = null;\n" + + " done: while (true) {\n" + + " if (test()) {\n" + + " break done;\n" + + " }\n" + + " o = new Object();\n" + + " }\n" + + " if (o == null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472 +// variant +public void test0462_while_explicit_label() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean test() {\n" + + " return true;\n" + + " }\n" + + " void foo() {\n" + + " Object o = null;\n" + + " done: while (true) {\n" + + " try {\n" + + " while (true) {\n" + + " if (test()) {\n" + + " break done;\n" + + " }\n" + + " }\n" + + " }\n" + + " finally {\n" + + " if (test()) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " }\n" + + " if (o == null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184298 +// variant +public void test0463_while_infinite() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(String[] a) {\n" + + " String key = null;\n" + + " while(true)\n" + + " {\n" + + " if (a[0] == null)\n" + + " break;\n" + + " key = a[0];\n" + + " }\n" + + " if (key != null) {\n" + + " // empty\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184298 +// variant +public void test0464_while_infinite() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(String[] a) {\n" + + " String key = null;\n" + + " loop: while(true)\n" + + " {\n" + + " if (a[0] == null)\n" + + " break loop;\n" + + " key = a[0];\n" + + " }\n" + + " if (key != null) {\n" + + " // empty\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184298 +// variant +public void test0465_while_infinite() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(String[] a) {\n" + + " String key = null;\n" + + " while(true)\n" + + " {\n" + + " if (a[0] == null)\n" + + " break;\n" + + " key = \"non null\";\n" + + " }\n" + + " if (key != null) {\n" + + " // empty\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=198955 +// dupe of bug 184298 in fact +public void test0466_while_infinite() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (true) {\n" + + " if (bar()) {\n" + + " break;\n" + + " }\n" + + " if (o == null) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " if (o == null) {}\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}\n"}, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=212283 +// (which is a dupe of 184298) +public void test0467_while_break() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " RuntimeException e = null;\n" + + " while (e != null || bar()) {\n" + + " if (e != null || bar()) {\n" + + " break;\n" + // always breaks out of the loop if e non-null + " }\n" + + " if (bar()) {\n" + + " e = new RuntimeException();\n" + + " }\n" + + " }\n" + + " if (e != null) {\n" + + " throw e;\n" + + " }\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=212283 +// (which is a dupe of 184298) +public void test0468_while_break() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " RuntimeException e = null;\n" + + " while (e != null || bar()) {\n" + + " if (bar()) {\n" + + " break;\n" + + " }\n" + + " if (bar()) {\n" + + " e = new RuntimeException();\n" + + " }\n" + + " }\n" + + " if (e != null) {\n" + + " throw e;\n" + + " }\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=212283 +// (which is a dupe of 184298) +public void test0469_while_break() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " RuntimeException e = null;\n" + + " while (e != null || bar()) {\n" + + " if (e != null) {\n" + + " break;\n" + + " }\n" + + " if (bar()) {\n" + + " e = new RuntimeException();\n" + + " }\n" + + " }\n" + + " if (e != null) {\n" + + " throw e;\n" + + " }\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=220788 +public void test0470_while() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " while (bar()) {\n" + + " if (o != null && o.toString().equals(\"o\")) {\n" + + " }\n" + + " }\n" + + " if (o.toString().equals(\"o\")) {\n" + + " }\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o != null && o.toString().equals(\"o\")) {\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n"); +} +// null analysis -- try/finally +public void test0500_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " try { /* */ }\n" + + " finally {\n" + + " o = m;\n" + + " }\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "" // because finally assigns to unknown value + ); +} + +// null analysis -- try/finally +public void test0501_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " try { /* */ }\n" + + " finally {\n" + + " o = null;\n" + + " }\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", // because finally assigns to null + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +public void test0502_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " try {\n" + + " System.out.println();\n" + // might throw a runtime exception + " o = new Object();\n" + + " }\n" + + " finally { /* */ }\n" + + " o.toString();\n" + + // still OK because in case of exception this code is + // not reached + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- try/finally +public void test0503_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = null;\n" + + " try {\n" + + " x = null;\n" + // complain, already null + " } finally { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " x = null;\n" + + " ^\n" + + "Redundant assignment: The variable x can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +public void test0504_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = null;\n" + + " try {\n" + + " } finally {\n" + + " if (x != null) { /* */ }\n" + // complain null + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (x != null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable x can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// origin: AssignmentTest#test017 +// The whole issue here is whether or not to detect premature exits. +// Previously, we followed JLS's conservative approach, which considers +// that the try block may exit before the assignment is completed. +// As of Bug 345305 this has been changed to a more accurate analysis. +public void test0505_try_finally() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = this;\n" + // 1 + " try {\n" + + " x = null;\n" + + " } finally {\n" + + " if (x == null) {/* */}\n" + // 2 + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (x == null) {/* */}\n" + + " ^\n" + + "Redundant null check: The variable x can only be null at this location\n" + + "----------\n"); +} + +// null analysis -- try finally +public void test0506_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " try { /* */ }\n" + + " finally {\n" + + " o = new Object();\n" + + " }\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try finally +public void test0507_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " try { /* */ }\n" + + " finally {\n" + + " o.toString();\n" + // protect + " }\n" + + " if (o == null) {\n" + // complain + " o = new Object();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (o == null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " if (o == null) {\n" + + " o = new Object();\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try finally +public void test0508_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o = null;" + + " try { /* */ }\n" + + " finally {\n" + + " o.toString();\n" + // complain and protect + " o.toString();\n" + // quiet + " }\n" + + " o.toString();\n" + // quiet + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try finally +public void test0509_try_finally_embedded() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1) {\n" + + " Object o2 = null;" + + " while (true) {\n" + + " // o2 = o1;\n" + + " try { /* */ }\n" + + " finally {\n" + + " o2.toString();\n" + // complain and protect + " o2.toString();\n" + // quiet + " }\n" + + " o2.toString();\n" + // quiet + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o2.toString();\n" + + " ^^\n" + + "Null pointer access: The variable o2 can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try finally +public void test0510_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar() throws Exception {\n" + + " // empty\n" + + " }\n" + + " void foo(Object o, boolean b) throws Exception {\n" + + " try {\n" + + " bar();\n" + + " if (b) {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + " finally {\n" + + " if (o != null) {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- try finally +public void test0511_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1, boolean b) {\n" + + " Object o2 = null;\n" + + " if (b) {\n" + + " o2 = new Object();\n" + + " }\n" + // 0011 + " try { /* */ }\n" + + " finally {\n" + + " o2 = o1;\n" + // 1011 + " }\n" + + " o2.toString();\n" + // 1011 -- quiet + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- try/finally +public void test0512_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = null;\n" + + " try {\n" + + " x = new X();\n" + + " } finally {\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " x.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable x may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128547 +public void test0513_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar() {\n" + + " return null;\n" + + " }\n" + + " Object foo() {\n" + + " X x = null;\n" + + " try {\n" + + " x = bar();\n" + + " x.toString();\n" + + " return x;\n" + + " } finally {\n" + + " if (x != null) {\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128547 +// embedded variant 1 +public void test0514_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar() {\n" + + " return null;\n" + + " }\n" + + " Object foo() {\n" + + " X x = null;\n" + + " try {\n" + + " try {\n" + + " x = bar();\n" + + " x.toString();\n" + + " return x;\n" + + " }\n" + + " finally {\n" + + " }\n" + + " }\n" + + " finally {\n" + + " if (x != null) {\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128547 +// embedded variant 2 +public void test0515_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar() {\n" + + " return null;\n" + + " }\n" + + " Object foo() {\n" + + " X x = null;\n" + + " try {\n" + + " try {\n" + + " x = bar();\n" + + " x.toString();\n" + + " return x;\n" + + " }\n" + + " finally {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " finally {\n" + + " if (x != null) {\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128547 +// variant +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184546 +// variant +public void test0516_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object foo() {\n" + + " X x = null;\n" + + " try {\n" + + " x = new X();\n" + + " return x;\n" + + " }\n" + + " finally {\n" + + " if (x != null) {\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=132072 +// AIOOBE in null check compiling com.sun.org.apache.xalan.internal.res.XSLTErrorResources from JDK 1.5 source +public void test0517_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object foo() {\n" + + " String s00, s01, s02, s03, s04, s05, s06, s07, s08, s09;\n" + + " String s10, s11, s12, s13, s14, s15, s16, s17, s18, s19;\n" + + " String s20, s21, s22, s23, s24, s25, s26, s27, s28, s29;\n" + + " String s30, s31, s32, s33, s34, s35, s36, s37, s38, s39;\n" + + " String s40, s41, s42, s43, s44, s45, s46, s47, s48, s49;\n" + + " String s50, s51, s52, s53, s54, s55, s56, s57, s58, s59;\n" + + " String s60, s61, s62, s63, s64, s65, s66, s67, s68, s69;\n" + + " String s100, s101, s102, s103, s104, s105, s106, s107, s108, s109;\n" + + " String s110, s111, s112, s113, s114, s115, s116, s117, s118, s119;\n" + + " String s120, s121, s122, s123, s124, s125, s126, s127, s128, s129;\n" + + " String s130, s131, s132, s133, s134, s135, s136, s137, s138, s139;\n" + + " String s140, s141, s142, s143, s144, s145, s146, s147, s148, s149;\n" + + " String s150, s151, s152, s153, s154, s155, s156, s157, s158, s159;\n" + + " String s160, s161, s162, s163, s164, s165, s166, s167, s168, s169;\n" + + " String s200, s201, s202, s203, s204, s205, s206, s207, s208, s209;\n" + + " String s210, s211, s212, s213, s214, s215, s216, s217, s218, s219;\n" + + " String s220, s221, s222, s223, s224, s225, s226, s227, s228, s229;\n" + + " String s230, s231, s232, s233, s234, s235, s236, s237, s238, s239;\n" + + " String s240, s241, s242, s243, s244, s245, s246, s247, s248, s249;\n" + + " String s250, s251, s252, s253, s254, s255, s256, s257, s258, s259;\n" + + " String s260, s261, s262, s263, s264, s265, s266, s267, s268, s269;\n" + + " X x = new X();\n" + + " try {\n" + + " return x;\n" + + " }\n" + + " finally {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=132120 +// [compiler][null] NPE batch compiling JDT/Core from HEAD +public void test0518_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s00, s01, s02, s03, s04, s05, s06, s07, s08, s09;\n" + + " String s10, s11, s12, s13, s14, s15, s16, s17, s18, s19;\n" + + " String s20, s21, s22, s23, s24, s25, s26, s27, s28, s29;\n" + + " String s30, s31, s32, s33, s34, s35, s36, s37, s38, s39;\n" + + " String s40, s41, s42, s43, s44, s45, s46, s47, s48, s49;\n" + + " String s50, s51, s52, s53, s54, s55, s56, s57, s58, s59;\n" + + " String s60, s61, s62, s63, s64, s65, s66, s67, s68, s69;\n" + + " String s100, s101, s102, s103, s104, s105, s106, s107, s108, s109;\n" + + " String s110, s111, s112, s113, s114, s115, s116, s117, s118, s119;\n" + + " String s120, s121, s122, s123, s124, s125, s126, s127, s128, s129;\n" + + " String s130, s131, s132, s133, s134, s135, s136, s137, s138, s139;\n" + + " String s140, s141, s142, s143, s144, s145, s146, s147, s148, s149;\n" + + " String s150, s151, s152, s153, s154, s155, s156, s157, s158, s159;\n" + + " String s160, s161, s162, s163, s164, s165, s166, s167, s168, s169;\n" + + " String s200, s201, s202, s203, s204, s205, s206, s207, s208, s209;\n" + + " String s210, s211, s212, s213, s214, s215, s216, s217, s218, s219;\n" + + " String s220, s221, s222, s223, s224, s225, s226, s227, s228, s229;\n" + + " String s230, s231, s232, s233, s234, s235, s236, s237, s238, s239;\n" + + " String s240, s241, s242, s243, s244, s245, s246, s247, s248, s249;\n" + + " String s250, s251, s252, s253, s254, s255, s256, s257, s258, s259;\n" + + " String s260, s261, s262, s263, s264, s265, s266, s267, s268, s269;\n" + + " X x = null;\n" + + " try {\n" + + " x = new X();\n" + + " } finally {\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 28)\n" + + " x.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable x may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128962 +// incorrect analysis within try finally with a constructor throwing an exception +public void test0519_try_finally_constructor_exc() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Y y) throws E {\n" + + " try {\n" + + " new Y();\n" + + " y.toString();\n" + // should be quiet + " } finally {\n" + + " y = null;\n" + + " }\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " Y() throws E {\n" + + " }\n" + + "}\n" + + "class E extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"}, + ""); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=128962 +// incorrect analysis within try finally with a constructor throwing an exception +// variant +public void test0520_try_finally_constructor_exc() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Y y) throws E { \n" + + " try { \n" + + " new Y() {\n" + + " void bar() {\n" + + " // do nothing\n" + + " }\n" + + " }; \n" + + " y.toString();\n" + + " } finally { \n" + + " y = null; \n" + + " } \n" + + " } \n" + + "}\n" + + "abstract class Y {\n" + + " Y() throws E { \n" + + " }\n" + + " abstract void bar();\n" + + "} \n" + + "class E extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}"}, + ""); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149665 +// incorrect analysis within try finally with an embedded && expression +public void test0521_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " X m;\n" + + " public void foo() {\n" + + " for(int j = 0; j < 10; j++) {\n" + + " try {\n" + + " j++;\n" + + " } finally {\n" + + " X t = m;\n" + + " if( t != null && t.bar()) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149665 +// variant +public void test0522_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " X m;\n" + + " public void foo() {\n" + + " for(int j = 0; j < 10; j++) {\n" + + " try {\n" + + " j++;\n" + + " } finally {\n" + + " X t = null;\n" + + " if(t.bar()) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " if(t.bar()) {\n" + + " ^\n" + + "Null pointer access: The variable t can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149665 +// variant +public void test0523_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " X m;\n" + + " public void foo() {\n" + + " for(int j = 0; j < 10; j++) {\n" + + " try {\n" + + " j++;\n" + + " } finally {\n" + + " X t = m;\n" + + " if(t == null ? false : (t == null ? false : t.bar())) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " if(t == null ? false : (t == null ? false : t.bar())) {\n" + + " ^\n" + + "Null comparison always yields false: The variable t cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=149665 +// variant +public void test0524_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " X m;\n" + + " public void foo() {\n" + + " for(int j = 0; j < 10; j++) {\n" + + " try {\n" + + " j++;\n" + + " } finally {\n" + + " X t = m;\n" + + " if(t != null ? false : (t == null ? false : t.bar())) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " boolean bar() {\n" + + " return false;\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " if(t != null ? false : (t == null ? false : t.bar())) {\n" + + " ^\n" + + "Redundant null check: The variable t can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150082 +public void _test0525_try_finally_unchecked_exception() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " String foo(Object p) {\n" + + " String s = null;\n" + + " Object o = null;\n" + + " try {\n" + + " o = p;\n" + + " if (o == null) {\n" + + " return null;\n" + + " }\n" + + " s = o.getClass().getName();\n" + + " } catch (RuntimeException e) {\n" + + " o.toString();\n" + + " s = null;\n" + + " } finally {\n" + + " if (o != null) {\n" + + " }\n" + + " }\n" + + " return s;\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150082 +// variant +public void test0526_try_finally_unchecked_exception() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " String foo(Object p) {\n" + + " String s = null;\n" + + " Object o = p;\n" + + " try {\n" + + " if (o == null) {\n" + // shades doubts upon o + " return null;\n" + // may throw a RuntimeException by spec + " }\n" + + " s = o.getClass().getName();\n" + + " } catch (RuntimeException e) {\n" + + " o.toString();\n" + + " s = null;\n" + + " } finally {\n" + + " if (o != null) {\n" + + " }\n" + + " }\n" + + " return s;\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +//null analysis -- try/finally +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=150082 +//variant +public void test0527_try_finally_unchecked_exception() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " String foo(Object p) {\n" + + " String s = null;\n" + + " Object o = p;\n" + + " try {\n" + + " if (o == null) {\n" + // shades doubts upon o + " return null;\n" + // may throw a RuntimeException by spec + " }\n" + + " s = o.getClass().getName();\n" + + " } catch (RuntimeException e) {\n" + + " o.toString();\n" + + " s = null;\n" + + " }\n" + + " return s;\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158000 +public void test0528_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = null;\n" + + " X y = null;\n" + + " try {\n" + + " } finally {\n" + + " if (x != null) { /* */ }\n" + // complain null + " if (y != null) { /* */ }\n" + // complain null as well + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (x != null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable x can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " if (y != null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable y can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158000 +public void test0529_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o = null;\n" + + " Object o2 = null;\n" + + " try { /* */ }\n" + + " finally {\n" + + " o.toString();\n" + // complain + " o2.toString();\n" + // complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\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 8)\n" + + " o2.toString();\n" + + " ^^\n" + + "Null pointer access: The variable o2 can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158000 +public void test0530_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = null;\n" + + " X y = null;\n" + + " try {\n" + + " x = new X();\n" + + " } finally {\n" + + " x.toString();\n" + + " y.toString();\n" + // complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " x.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable x may be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " y.toString();\n" + + " ^\n" + + "Null pointer access: The variable y can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=158000 +public void test0531_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " X x = new X();\n" + + " X y = null;\n" + + " try {\n" + + " } finally {\n" + + " if (x != null) {\n" + + " x.toString();\n" + + " }\n" + + " y.toString();\n" + // complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (x != null) {\n" + + " ^\n" + + "Redundant null check: The variable x cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " y.toString();\n" + + " ^\n" + + "Null pointer access: The variable y can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=177863 +public void test0532_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Object o = null;\n" + + " try {\n" + + " } finally {\n" + + " o = Object.class.getClass();\n" + + " o.getClass();\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184546 +public void test0533_try_finally_field() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static char SHOULD_NOT_MATTER = '?';\n" + + " Object foo() {\n" + + " X x = null;\n" + + " try {\n" + + " x = new X();\n" + + " return x;\n" + + " }\n" + + " finally {\n" + + " if (x != null) {\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - try finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=198970 +public void _test0534_try_finally() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String foo = null;\n" + + " boolean a = true;\n" + + " try {\n" + + " }\n" + + " catch(Exception e) {\n" + + " }\n" + + " finally {\n" + + " if (a) {\n" + + " foo = new String();\n" + + " }\n" + + " if (foo != null) {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + "" /* expectedErrorString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + false /* skipJavac */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=295260 +public void test0535_try_finally() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test3(String[] args) {\n" + + " while (true) {\n" + + " Object a = null;\n" + + " try {\n" + + " a = new Object();\n" + + " } catch (Exception e) {\n" + + " } finally {\n" + + " if (a != null)\n" + + " a = null;\n" + // quiet + " }\n" + + " }\n" + + " }\n"+ + "}", + }, + ""); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 - [compiler] [null] Whitebox issues in null analysis +// trigger nullbits 0111 (pot n|nn|un), don't let "definitely unknown" override previous information +public void test0536_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar () { return null; }\n" + + " void foo() {\n" + + " X x = new X();\n" + + " try {\n" + + " x = null;\n" + + " x = new X();\n" + // if this throws an exception finally finds x==null + " x = bar();\n" + + " } finally {\n" + + " x.toString();\n" + // complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " x.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable x may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/finally +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320170 - [compiler] [null] Whitebox issues in null analysis +// trigger nullbits 0111 (pot n|nn|un), don't let "definitely unknown" override previous information +// multiple variables +public void test0537_try_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar () { return null; }\n" + + " void foo() {\n" + + " X x1 = new X();\n" + + " X x2 = new X();\n" + + " X x3 = new X();\n" + + " try {\n" + + " x1 = null;\n" + + " x2 = null;\n" + + " x1 = new X();\n" + // if this throws an exception finally finds x1==null + " x2 = new X();\n" + // if this throws an exception finally finds x2==null + " x3 = new X();\n" + // if this throws an exception finally still finds x3!=null + " x1 = bar();\n" + + " x2 = bar();\n" + + " } finally {\n" + + " x1.toString();\n" + // complain + " x2.toString();\n" + // complain + " x3.toString();\n" + // don't complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " x1.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable x1 may be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " x2.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable x2 may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- try/catch +public void test0550_try_catch() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " try {\n" + + " System.out.println();\n" + // might throw a runtime exception + " o = new Object();\n" + + " }\n" + + " catch (Throwable t) {\n" + // catches everything + " return;\n" + // gets out + " }\n" + + " o.toString();\n" + // non null + " }\n" + + "}\n"}, + ""); +} + +// null analysis - try/catch +public void test0551_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " try {\n" + + " System.out.println();\n" + + " if (dummy) {\n" + + " o = null;\n" + + " throw new Exception();\n" + + " }\n" + + " }\n" + + " catch (Exception e) {\n" + + " o.toString();\n" + // complain + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - try/catch +public void test0552_try_catch() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() throws Exception {\n" + + " Object o = new Object();\n" + + " try {\n" + + " if (dummy) {\n" + + " o = null;\n" + + " throw new Exception();\n" + + " }\n" + + " }\n" + + " catch (Exception e) {\n" + + " }\n" + + " if (o != null) {\n" + + // quiet: get out of try either through normal flow, leaves a new + // object, or through Exception, leaves a null + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - try/catch +public void test0553_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy, other;\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " try {\n" + + " if (dummy) {\n" + + " if (other) {\n" + + " throw new LocalException();\n" + // may launch new exception + " }\n" + + " o = null;\n" + + " throw new LocalException();\n" + // must launch new exception + " }\n" + + " }\n" + + " catch (LocalException e) {\n" + + " o.toString();\n" + // complain + " }\n" + + " }\n" + + " class LocalException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - try/catch +public void test0554_try_catch() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) throws Exception {\n" + + " try {\n" + + " o = null;\n" + + " throwLocalException();\n" + + " throw new Exception();\n" + + " }\n" + + " catch (LocalException e) {\n" + + " }\n" + + " if (o != null) {\n" + + // complain: only way to get out of try and get there is to go + // through throwLocalException, after the assignment + " }\n" + + " }\n" + + " class LocalException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " void throwLocalException() throws LocalException {\n" + + " throw new LocalException();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " if (o != null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " if (o != null) {\n" + + " }\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + ); +} + +// null analysis - try/catch +public void test0555_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " try {\n" + + " o = null;\n" + + " throwException();\n" + + " }\n" + + " catch (Exception e) {\n" + + " o.toString();\n" + // complain NPE + " }\n" + + " }\n" + + " void throwException() throws Exception {\n" + + " throw new Exception();\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", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - try/catch +public void test0556_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " try {\n" + + " o = null;\n" + + " throwException();\n" + + " }\n" + + " catch (Throwable t) {\n" + + " o.toString();\n" + // complain NPE + " }\n" + + " }\n" + + " void throwException() throws Exception {\n" + + " throw new Exception();\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", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - try/catch +public void test0557_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " try {\n" + + " if (dummy) {\n" + + " o = null;\n" + + " throw new Exception();\n" + + " }\n" + + " }\n" + + " catch (Exception e) {\n" + + " o.toString();\n" + // complain NPE + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - try/catch +public void test0558_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " try {\n" + + " if (dummy) {\n" + + " System.out.print(0);\n" + // may thow RuntimeException + " o = null;\n" + + " throw new LocalException();\n" + + " }\n" + + " }\n" + + " catch (LocalException e) {\n" + // doesn't catch RuntimeException + " o.toString();\n" + // complain NPE + " }\n" + + " }\n" + + " class LocalException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - try/catch +public void test0559_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " try {\n" + + " if (dummy) {\n" + + " o = null;\n" + + " throw new SubException();\n" + + " }\n" + + " }\n" + + " catch (LocalException e) {\n" + // must catch SubException + " o.toString();\n" + // complain NPE + " }\n" + + " }\n" + + " class LocalException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " class SubException extends LocalException {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - try/catch +public void test0560_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Class bar(boolean b) throws ClassNotFoundException {\n" + + " if (b) {\n" + + " throw new ClassNotFoundException();\n" + + " }\n" + + " return null;\n" + + " }\n" + + " public Class foo(Class c, boolean b) {\n" + + " if (c != null)\n" + + " return c;\n" + + " if (b) {\n" + + " try {\n" + + " c = bar(b);\n" + + " return c;\n" + + " } catch (ClassNotFoundException e) {\n" + + " // empty\n" + + " }\n" + + " }\n" + + " if (c == null) { // should complain: c can only be null\n" + + " }\n" + + " return c;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " if (c == null) { // should complain: c can only be null\n" + + " ^\n" + + "Redundant null check: The variable c can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - try/catch +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=130359 +public void test0561_try_catch_unchecked_exception() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " try {\n" + + " o = bar();\n" + + " } catch (RuntimeException e) {\n" + + " o.toString();\n" + // may be null + " }\n" + + " }\n" + + " private Object bar() {\n" + + " return new Object();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - try/catch +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150854 +// (slightly different) variant of 561 +public void test0562_try_catch_unchecked_exception() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + this.runNegativeTest( + true, + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " void foo() {\n" + + " LineNumberReader o = null;\n" + + " try {\n" + + " o = new LineNumberReader(new FileReader(\"dummy\"));\n" + + " } catch (NumberFormatException e) {\n" + + " o.toString();\n" + // may be null + " } catch (IOException e) {\n" + + " }\n" + + " }\n" + + "}\n"}, + null, + options, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " o = new LineNumberReader(new FileReader(\"dummy\"));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'o\' may not be closed\n" + + "----------\n" + + "2. 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 analysis - try/catch +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=155117 +public void test0563_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(boolean b) {\n" + + " Exception ex = null;\n" + + " if (b) {\n" + + " try {\n" + + " System.out.println();\n" + + " return;\n" + + " } catch (Exception e) {\n" + + " ex = e;\n" + + " }\n" + + " }\n" + + " else {\n" + + " try {\n" + + " System.out.println();\n" + + " return;\n" + + " } catch (Exception e) {\n" + + " ex = e;\n" + + " }\n" + + " }\n" + + " if (ex == null) {\n" + // complain: ex cannot be null\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " if (ex == null) {\n" + + " ^^\n" + + "Null comparison always yields false: The variable ex cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 20)\n" + + " if (ex == null) {\n" + + " }\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - try/catch +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150854 +public void test0564_try_catch_unchecked_exception() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Object foo() {\n" + + " Object result = null;\n" + + " try {\n" + + " result = new Object();\n" + + " } catch (Exception e) {\n" + + " result = null;\n" + + " }\n" + + " return result;\n" + + " }\n" + + "}"}, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null /* no vm arguments */, + options, + null /* no custom requestor*/, + false /* do not skip javac for this peculiar test */); +} + +// null analysis - try/catch +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150854 +// variant +public void test0565_try_catch_unchecked_exception() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Object foo() {\n" + + " Object result = null;\n" + + " try {\n" + + " result = new Object();\n" + + " result = new Object();\n" + + " } catch (Exception e) {\n" + + " result = null;\n" + + " }\n" + + " return result;\n" + + " }\n" + + "}"}, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null /* no vm arguments */, + options, + null /* no custom requestor*/, + false /* do not skip javac for this peculiar test */); +} + +// null analysis - try/catch +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150854 +// variant +public void test0566_try_catch_unchecked_exception() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Object foo(Y y) {\n" + + " Object result = null;\n" + + " try {\n" + + " while (y.next()) {\n" + + " result = y.getObject();\n" + + " }\n" + + " } catch (Exception e) {\n" + + " result = null;\n" + + " }\n" + + " return result;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " boolean next() {\n" + + " return false;\n" + + " }\n" + + " Object getObject() {\n" + + " return null;\n" + + " }\n" + + "}"}, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null /* no vm arguments */, + options, + null /* no custom requestor*/, + false /* do not skip javac for this peculiar test */); +} + +// null analysis - try/catch for checked exceptions +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=295260 +public void test0567_try_catch_checked_exception() { + this.runConformTest( + new String[] { + "X.java", + "import java.net.MalformedURLException;\n" + + "import java.net.URL;\n" + + "public class X {\n" + + " public void test1(String[] args) {\n" + + " URL[] urls = null;\n" + + " try {\n" + + " urls = new URL[args.length];\n" + + " for (int i = 0; i < args.length; i++)\n" + + " urls[i] = new URL(\"http\", \"\", -1, args[i]);\n" + + " }\n" + + " catch (MalformedURLException mfex) {\n" + + " urls = null;\n" + // quiet + " }\n" + + " }\n" + + "}", + }, + ""); +} + +// null analysis - try/catch for checked exceptions with finally block +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=295260 +public void test0568_try_catch_checked_exception() { + this.runConformTest( + new String[] { + "X.java", + "import java.net.MalformedURLException;\n" + + "import java.net.URL;\n" + + "public class X {\n" + + " public void test1(String[] args) {\n" + + " URL[] urls = null;\n" + + " try {\n" + + " urls = new URL[args.length];\n" + + " for (int i = 0; i < args.length; i++)\n" + + " urls[i] = new URL(\"http\", \"\", -1, args[i]);\n" + + " }\n" + + " catch (MalformedURLException mfex) {\n" + + " urls = null;\n" + // quiet + " }\n" + + " finally{\n"+ + " System.out.println(\"complete\");\n" + + " }\n" + + " }\n" + + "}", + }, + ""); +} +// null analysis -- try/catch +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=302446 +public void test0569_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " int i;\n" + + " if (o == null)\n" + // redundant check + " i = 0;\n" + + " try {\n" + + " System.out.println(i);\n" + // might throw a runtime exception + " o = new Object();\n" + + " throw new Exception(\"Exception thrown from try block\");\n" + + " }\n" + + " catch (Throwable t) {\n" + // catches everything + " return;\n" + // gets out + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o == null)\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " System.out.println(i);\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); +} +// null analysis -- try/catch +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=302446 +public void test0570_try_catch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " int i;\n" + + " if (o == null)\n" + // redundant check + " i = 0;\n" + + " try {\n" + + " System.out.println();\n" + // might throw a runtime exception + " o = new Object();\n" + + " if (o != null)\n" + // redundant check + " i = 1\n;" + + " throw new Exception(\"Exception thrown from try block\");\n" + + " }\n" + + " catch (Exception e) {\n" + + " if(i == 0)\n" + + " System.out.println(\"o was initialised\");\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o == null)\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " if (o != null)\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " if(i == 0)\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); +} +//null analysis -- try/catch +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=302446 +public void test0571_try_catch_finally() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " int i;\n" + + " if (o == null)\n" + // redundant check + " i = 0;\n" + + " try {\n" + + " o = new Object();\n" + + " i = 1\n;" + + " throw new Exception(\"Exception thrown from try block\");\n" + + " }\n" + + " catch (Exception e) {\n" + + " if(o == null)\n" + + " o = new Object();\n" + + " i = 1;\n" + + " }\n" + + " finally {\n" + + " if (i==1) {\n" + + " System.out.println(\"Method ended with o being initialised\");\n" + + " System.out.println(o.toString());\n" + // may be null + " } \n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o == null)\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " if (i==1) {\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n" + + "3. ERROR in X.java (at line 20)\n" + + " System.out.println(o.toString());\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"); +} +//null analysis -- if statement +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=302446 +public void test0572_if_statement() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " int i;\n" + + " if (o == null) // redundant check\n" + + " i = 0;\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n" + + ""}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o == null) // redundant check\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " System.out.println(i);\n" + + " ^\n" + + "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() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " Throwable t = null;\n" + + " throw t;\n" + + " }\n" + + "}\n" + }, + true /* expectingCompilerErrors */, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " throw t;\n" + + " ^\n" + + "Null pointer access: The variable t can only be null at this location\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + "" /* expectedErrorString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + +// null analysis - throw +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=201182 +// variant - potential NPE +public void test0596_throw() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " Throwable t = null;\n" + + " if (args.length > 0) {\n" + + " t = new Throwable();\n" + + " }\n" + + " throw t;\n" + + " }\n" + + "}\n" + }, + true /* expectingCompilerErrors */, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " throw t;\n" + + " ^\n" + + "Potential null pointer access: The variable t may be null at this location\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + "" /* expectedErrorString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + + +// null analysis - throw +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=201182 +// variant - unknown +public void test0597_throw() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() throws Throwable {\n" + + " throw t();\n" + + " }\n" + + " Throwable t() {\n" + + " return new Throwable();\n" + + " }\n" + + "}\n" + }, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + "" /* expectedErrorString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + +// null analysis -- do while +public void test0601_do_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " do {/* */}\n" + + " while (o.toString() != null);\n" + + // complain: NPE + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " while (o.toString() != null);\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- do while +public void test0602_do_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " do {/* */}\n" + + " while (o != null);\n" + + // complain: get o null first time and forever + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " while (o != null);\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- do while +public void test0603_do_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " do {\n" + + " o = new Object();\n" + + " }\n" + + " while (o == null);\n" + + // complain: set it to non null before test, for each iteration + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " while (o == null);\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- do while +public void test0604_do_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " do {\n" + + " if (System.currentTimeMillis() > 10L) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " while (o == null);\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- do while +public void test0605_do_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo(Object o) {\n" + + " o = null;\n" + + " do {\n" + + " // do nothing\n" + + " }\n" + + " while (dummy || o != null);\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " while (dummy || o != null);\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- do while +public void test0606_do_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null,\n" + + " u = new Object(),\n" + + " v = new Object();\n" + + " do {\n" + + " if (v == null) {\n" + + " o = new Object();\n" + + " };\n" + + " if (u == null) {\n" + + " v = null;\n" + + " };\n" + + " u = null;\n" + + " }\n" + + " while (o == null);\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- do while +public void test0607_do_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " do {\n" + + " o.toString();\n" + + // complain: NPE + " o = new Object();\n" + + " }\n" + + " while (dummy);\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- do while +public void test0608_do_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " do {\n" + + " o = new Object();\n" + + " }\n" + + " while (dummy);\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- do while +public void test0609_do_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " do { /* */ }\n" + + " while (dummy);\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - do while +public void test0610_do_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar() {\n" + + " return null;\n" + + " }\n" + + " void foo(X x) {\n" + + " x.bar();\n" + + " do {\n" + + " x = x.bar();\n" + + " } while (x != null);\n" + // quiet + " }\n" + + "}\n"}, + ""); +} + +// null analysis - do while +public void test0611_do_while() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " X bar() {\n" + + " return new X();\n" + + " }\n" + + " void foo(Object o) {\n" + + " do {\n" + + " o = bar();\n" + + " } while (o == null);\n" + + " if (o != null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// the problem here is that a single pass cannot know for the return +// embedded into the if; prior approach did use the upstream flow +// info to catch this, but this is inappropriate in many cases (eg +// test0606) +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=123399 +public void _test0612_do_while() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object doubt) {\n" + + " Object o = null;\n" + + " do {\n" + + " if (o == null) {\n" + + " return;\n" + + " }\n" + + " o = doubt;\n" + + " } while (true);\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null) {\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n" + ); +} + +// null analysis - do while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=147118 +public void test0613_do_while() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String f;\n" + + " void foo (boolean b) {\n" + + " X x = new X();\n" + + " do {\n" + + " System.out.println(x.f);\n" + + " if (b) {\n" + + " x = null;\n" + + " }\n" + + " } while (x != null);\n" + + " }\n" + + "}\n"}, + ""); +} + + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=123399 +// variant +public void _test0614_do_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object doubt) {\n" + + " Object o = null;\n" + + " exit: do {\n" + + " if (o == null) {\n" + + " continue exit;\n" + + " }\n" + + " o = doubt;\n" + + " } while (true);\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null) {\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=123399 +// variant +public void _test0615_do_while() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object doubt) {\n" + + " Object o = null;\n" + + " do {\n" + + " if (o == null) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + " o = doubt;\n" + + " } while (true);\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null) {\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - do while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472 +// variant +public void test0616_do_while_explicit_label() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(int i) {\n" + + " Object o = null;\n" + + " done: do {\n" + + " switch (i) {\n" + + " case 0:\n" + + " o = new Object();\n" + + " break;\n" + + " case 1:\n" + + " break done;\n" + + " }\n" + + " } while (true);\n" + + " if (o == null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - do while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472 +// variant +public void test0617_do_while_explicit_label() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean test() {\n" + + " return true;\n" + + " }\n" + + " void foo() {\n" + + " Object o = null;\n" + + " done: do {\n" + + " if (test()) {\n" + + " break done;\n" + + " }\n" + + " o = new Object();\n" + + " } while (true);\n" + + " if (o == null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - do while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184298 +// variant +public void test0618_do_while_infinite() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(String[] a) {\n" + + " String key = null;\n" + + " do {\n" + + " if (a[0] == null)\n" + + " break;\n" + + " key = a[0];\n" + + " } while (true);\n" + + " if (key != null) {\n" + + " // empty\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - do while +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184298 +// variant +public void test0619_do_while_infinite() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(String[] a) {\n" + + " String key = null;\n" + + " loop: do {\n" + + " if (a[0] == null)\n" + + " break loop;\n" + + " key = a[0];\n" + + " } while (true);\n" + + " if (key != null) {\n" + + " // empty\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis -- for +public void test0701_for() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " for (;o.toString() != null;) {/* */}\n" + + // complain: NPE + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for (;o.toString() != null;) {/* */}\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- for +public void test0702_for() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " for (;o != null;) {/* */}\n" + + // complain: get o null first time and forever + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for (;o != null;) {/* */}\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- for +public void test0703_for() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " for (;o == null;) {\n" + + // quiet: first iteration is sure to find it null, + // but other iterations may change it + " o = new Object();\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- for +public void test0704_for() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " for (;o == null;) {\n" + + // quiet: first iteration is sure to find it null, + // but other iterations may change it + " if (System.currentTimeMillis() > 10L) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- for +public void test0705_for() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() {\n" + + " return true;\n" + + " }\n" + + " void foo(Object o) {\n" + + " for (;bar() && o == null;) {\n" + + " o.toString();\n" + // complain: NPE because of condition + " o = new Object();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- for +public void test0707_for() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " for (;o == null; o.toString()) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- for +public void test0708_for() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " for (;o == null; o.toString()) {\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (;o == null; o.toString()) {\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- for +public void test0709_for() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " for (o.toString(); o == null;) { /* */ }\n" + // complain: protected then unchanged + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (o.toString(); o == null;) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- for +public void test0710_for() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bar() {\n" + + " return true;\n" + + " }\n" + + " void foo(Object o) {\n" + + " o = null;\n" + + " for (o.toString(); bar();) {\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " for (o.toString(); bar();) {\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- for +public void test0711_for() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object t[] = null;\n" + + " for (Object o : t) {/* */}\n" + + // complain: NPE + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for (Object o : t) {/* */}\n" + + " ^\n" + + "Null pointer access: The variable t can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- for +public void test0712_for() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Iterable i = null;\n" + + " for (Object o : i) {/* */}\n" + + // complain: NPE + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for (Object o : i) {/* */}\n" + + " ^\n" + + "Null pointer access: The variable i can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- for +public void test0713_for() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object t[] = new Object[1];\n" + + " for (Object o : t) {/* */}\n" + + " }\n" + + "}\n"}, + ""); + } +} + +// null analysis -- for +public void test0714_for() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Iterable i = new java.util.Vector();\n" + + " for (Object o : i) {/* */}\n" + + " }\n" + + "}\n"}, + ""); + } +} + +// null analysis -- for +public void test0715_for() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Iterable i = new java.util.Vector();\n" + + " Object flag = null;\n" + + " for (Object o : i) {\n" + + " flag = new Object();\n" + + " }\n" + + " flag.toString();\n" + + // complain: cannot know if at least one iteration got executed + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " flag.toString();\n" + + " ^^^^\n" + + "Potential null pointer access: The variable flag may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- for +public void test0716_for() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Iterable i = new java.util.Vector();\n" + + " Object flag = null;\n" + + " for (Object o : i) { /* */ }\n" + + " flag.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " flag.toString();\n" + + " ^^^^\n" + + "Null pointer access: The variable flag can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- for +public void test0717_for() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean dummy) {\n" + + " Object flag = null;\n" + + " for (;dummy;) {\n" + + " flag = new Object();\n" + + " }\n" + + " flag.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " flag.toString();\n" + + " ^^^^\n" + + "Potential null pointer access: The variable flag may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- for +public void test0718_for() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean dummy) {\n" + + " Object flag = null;\n" + + " for (;dummy;) { /* */ }\n" + + " flag.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " flag.toString();\n" + + " ^^^^\n" + + "Null pointer access: The variable flag can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- for +// origin: AssignmentTest#test019 +public void test0719_for() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final char[] foo(char[] a, char c1, char c2) {\n" + + " char[] r = null;\n" + + " for (int i = 0, length = a.length; i < length; i++) {\n" + + " char c = a[i];\n" + + " if (c == c1) {\n" + + " if (r == null) {\n" + + " r = new char[length];\n" + + " }\n" + + " r[i] = c2;\n" + + " } else if (r != null) {\n" + + " r[i] = c;\n" + + " }\n" + + " }\n" + + " if (r == null) return a;\n" + + " return r;\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- for +public void test0720_for_continue_break() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " for (int i = 0; i < 10; i++) {\n" + + " if (o == null) {\n" + // complain: o cannot be null + " continue;\n" + + " }\n" + + " o = null;\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o == null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- for +public void test0721_for() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " Object o = null;\n" + + " for (; b ? (o = new Object()).equals(o) : false ;) {\n" + + // contrast this with test0238; here the condition shades doubts + // upon o being null + " /* */\n" + + " }\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- for +public void test0722_for_return() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo (boolean b) {\n" + + " Object o = null;\n" + + " for (int i = 0; i < 25; i++) {\n" + + " if (b) {\n" + + " if (o == null) {\n" + + " o = new Object();\n" + // cleared by return downstream + " }\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null) {\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- for +public void test0723_for() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo () {\n" + + " Object o[] = new Object[1];\n" + + " for (int i = 0; i < 1; i++) {\n" + + " if (i < 1) {\n" + + " o[i].toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- for +public void test0724_for_with_initialization() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X field;\n" + + " void foo(X x1) {\n" + + " // X x2;\n" + + " outer: for (int i = 0; i < 30; i++) {\n" + + " X x2 = x1;\n" + + " do {\n" + + " if (x2.equals(x1)) {\n" + + " continue outer;\n" + + " }\n" + + " x2 = x2.field;\n" + + " } while (x2 != null);\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- for +public void test0725_for_with_assignment() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X field;\n" + + " void foo(X x1) {\n" + + " X x2;\n" + + " outer: for (int i = 0; i < 30; i++) {\n" + + " x2 = x1;\n" + + " do {\n" + + " if (x2.equals(x1)) {\n" + + " continue outer;\n" + + " }\n" + + " x2 = x2.field;\n" + + " } while (x2 != null);\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- for +// changed with https://bugs.eclipse.org/bugs/show_bug.cgi?id=127570 +// we are now able to see that x2 is reinitialized with x1, which is unknown +public void test0726_for() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x1) {\n" + + " X x2 = null;\n" + + " for (int i = 0; i < 5; i++) {\n" + + " if (x2 == null) {\n" + + " x2 = x1;\n" + + " }\n" + + " x2.toString();\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- for +public void test0727_for() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " for (; true;) { /* */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- for +public void test0728_for() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " for (; true; x.toString()) { /* */ }\n" + + " if (x == null) { /* */ }\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (x == null) { /* */ }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} + +// null analysis -- for +public void test0729_for_try_catch_finally() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "class X {\n" + + " X f;\n" + + " void bar() throws IOException {\n" + + " throw new IOException();\n" + + " }\n" + + " void foo(boolean b) {\n" + + " for (int i = 0 ; i < 5 ; i++) {\n" + + " X x = this.f;\n" + + " if (x == null) { \n" + + " continue;\n" + + " }\n" + + " if (b) {\n" + + " try {\n" + + " bar();\n" + + " } \n" + + " catch(IOException e) { /* */ }\n" + + " finally {\n" + + " x.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - for +public void test0730_for() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object o) {\n" + + " for ( ; o == null ; ) {\n" + + " o = new Object();\n" + + " }\n" + + " if (o != null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - for +public void test0731_for() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " X bar() {\n" + + " return new X();\n" + + " }\n" + + " void foo(Object o) {\n" + + " for ( ; o == null ; ) {\n" + + " o = bar();\n" + + " }\n" + + " if (o != null) { /* */ }\n" + // complain + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - for nested with break +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129371 +public void test0732_for_nested_break() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(String doubt) {\n" + + " for(int i = 0; i < 10; i++) {\n" + + " String s = doubt;\n" + + " if(s != null) {\n" + + " for(int j = 0; j < 1; j++) {\n" + + " break;\n" + + " }\n" + + " s.length();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + "\n"}, + ""); +} + +// null analysis - for while with break +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129371 +// variant +public void test0733_for_while_break() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(String doubt, boolean b) {\n" + + " for(int i = 0; i < 10; i++) {\n" + + " String s = doubt;\n" + + " if (s != null) {\n" + + " while (b) {\n" + + " break;\n" + + " }\n" + + " s.length();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + "\n"}, + ""); +} + +// null analysis - for while with break +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129371 +// variant +public void test0734_for_while_break() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(String doubt, boolean b) {\n" + + " for(int i = 0; i < 10; i++) {\n" + + " String s = doubt;\n" + + " if (s != null) {\n" + + " do {\n" + + " break;\n" + + " } while (b);\n" + + " s.length();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + "\n"}, + ""); +} + +// null analysis - for nested with break +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=129371 +// variant +public void test0735_for_nested_break() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object[] a, String doubt) {\n" + + " for(int i = 0; i < 10; i++) {\n" + + " String s = doubt;\n" + + " if(s != null) {\n" + + " for(Object o : a) {\n" + + " break;\n" + + " }\n" + + " s.length();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + "\n"}, + ""); + } +} + +// null analysis - for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127570 +public void test0736_for_embedded_lazy_init() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public boolean foo() {\n" + + " Boolean b = null;\n" + + " for (int i = 0; i < 1; i++) {\n" + + " if (b == null) {\n" + + " b = Boolean.TRUE;\n" + + " }\n" + + " if (b.booleanValue()) {\n" + // quiet + " return b.booleanValue();\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - for with unknown protection: unknown cannot protect anything +// suggested by https://bugs.eclipse.org/bugs/show_bug.cgi?id=127570 +public void test0737_for_unknown_protection() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " public boolean foo(Boolean p) {\n" + + " Boolean b = null;\n" + + " for (int i = 0; i < 1; i++) {\n" + + " if (b == p) {\n" + // tells us that p is null as well + " // empty\n" + + " }\n" + + " else {\n" + + " continue;\n" + + " }\n" + + " if (b.booleanValue()) {\n" + // complain b can only be null + " return b.booleanValue();\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " if (b.booleanValue()) {\n" + + " ^\n" + + "Null pointer access: The variable b can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis - for with unknown protection +// suggested by https://bugs.eclipse.org/bugs/show_bug.cgi?id=127570 +// the issue is that we cannot do less than full aliasing analysis to +// catch this one +// PREMATURE (maxime) reconsider when/if we bring full aliasing in +public void _test0738_for_unknown_protection() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " public boolean foo(Boolean p) {\n" + + " Boolean b = null;\n" + + " for (int i = 0; i < 1; i++) {\n" + + " if (b == p) {\n" + + " // empty\n" + + " }\n" + + " else {\n" + + " b = p;\n" + + " }\n" + + " if (b.booleanValue()) {\n" + // quiet because b is an alias for p, unknown + " return b.booleanValue();\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis -- for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=178895 +public void test0739_for() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void foo(List l, boolean b) {\n" + + " for (Object o : l) {\n" + + " if (b) {\n" + + " if (o != null) {\n" + + " return;\n" + + " }\n" + + " } else {\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); + } +} + +// null analysis - for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472 +// variant +public void test0740_for_explicit_label() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(int i) {\n" + + " Object o = null;\n" + + " done: for (;;) {\n" + + " switch (i) {\n" + + " case 0:\n" + + " o = new Object();\n" + + " break;\n" + + " case 1:\n" + + " break done;\n" + + " }\n" + + " }\n" + + " if (o == null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472 +// variant +public void test0741_for_explicit_label() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean test() {\n" + + " return true;\n" + + " }\n" + + " void foo() {\n" + + " Object o = null;\n" + + " done: for (;;) {\n" + + " if (test()) {\n" + + " break done;\n" + + " }\n" + + " o = new Object();\n" + + " }\n" + + " if (o == null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis - for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=176472 +// variant +public void test0742_for_explicit_label() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " void foo(int i, List l) {\n" + + " Object o = null;\n" + + " done: for (Object j: l) {\n" + + " switch (i) {\n" + + " case 0:\n" + + " o = new Object();\n" + + " break;\n" + + " case 1:\n" + + " break done;\n" + + " }\n" + + " }\n" + + " if (o == null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); + } +} + +// null analysis - for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184298 +public void test0743_for_infinite() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(String[] a) {\n" + + " String key = null;\n" + + " for( int i = 0; ; i++ )\n" + + " {\n" + + " if (a[i] == null)\n" + + " break;\n" + + " key = a[i];\n" + + " }\n" + + " if (key != null) {\n" + + " // empty\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=184298 +// variant +public void test0744_for_infinite() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void test(String[] a) {\n" + + " String key = null;\n" + + " loop: for( int i = 0; ; i++ )\n" + + " {\n" + + " if (a[i] == null)\n" + + " break loop;\n" + + " key = a[i];\n" + + " }\n" + + " if (key != null) {\n" + + " // empty\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +// null analysis - for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=195638 +public void test0746_for_try_catch() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String str = null;\n" + + " for (int i = 0; i < 2; i++) {\n" + + " try {\n" + + " str = new String(\"Test\");\n" + + " } catch (Exception ex) {\n" + + " ex.printStackTrace();\n" + + " }\n" + + " str.charAt(i);\n" + + " str = null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " str.charAt(i);\n" + + " ^^^\n" + + "Potential null pointer access: The variable str may be null at this location\n" + + "----------\n"); +} + +// null analysis - for +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=195638 +// variant: do not reset to null +public void test0747_for_try_catch() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String str = null;\n" + + " for (int i = 0; i < 2; i++) {\n" + + " try {\n" + + " str = new String(\"Test\");\n" + + " } catch (Exception ex) {\n" + + " ex.printStackTrace();\n" + + " }\n" + + " str.charAt(i);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " str.charAt(i);\n" + + " ^^^\n" + + "Potential null pointer access: The variable str may be null at this location\n" + + "----------\n" /* expectedCompilerLog */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- switch +public void test0800_switch() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int k;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " switch (k) {\n" + + " case 0 :\n" + + " o = new Object();\n" + + " break;\n" + + " case 2 :\n" + + " return;\n" + + " }\n" + + " if(o == null) { /* */ }\n" + // quiet: don't know whether came from 0 or default + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- switch +public void test0801_switch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int k;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " switch (k) {\n" + + " case 0 :\n" + + " o = new Object();\n" + + " break;\n" + + " default :\n" + + " return;\n" + + " }\n" + + " if(o == null) { /* */ }\n" + // complain: only get there through 0, o non null + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " if(o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " if(o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- switch +public void test0802_switch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int k;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " switch (k) {\n" + + " case 0 :\n" + + " o.toString();\n" + // complain: o can only be null + " break;\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- switch +public void test0803_switch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int k;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " switch (k) {\n" + + " case 0 :\n" + + " o = new Object();\n" + + " case 1 :\n" + + " o.toString();\n" + // complain: may come through 0 or 1 + " break;\n" + + " }\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); +} + +// null analysis -- switch +public void test0804_switch() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo (Object o, int info) {\n" + + " o = null;\n" + + " switch (info) {\n" + + " case 0 :\n" + + " o = new Object();\n" + + " break;\n" + + " case 1 :\n" + + " o = new String();\n" + + " break;\n" + + " default :\n" + + " o = new X();\n" + + " break;\n" + + " }\n" + + " if(o != null) { /* */ }\n" + // complain: all branches allocate a new o + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " if(o != null) { /* */ }\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- switch +public void test0805_switch() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X p) {\n" + + " X x = this;\n" + + " for (int i = 0; i < 5; i++) {\n" + + " switch (i) {\n" + + " case 1:\n" + + " x = p;\n" + + " }\n" + + " }\n" + + " if (x != null) { /* */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- non null protection tag +public void _test0900_non_null_protection_tag() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " boolean b = o != null;\n" + // shades doubts upon o + " o/*NN*/.toString();\n" + // protection => do not complain + " o.toString();\n" + // protected by previous line + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- non null protection tag +public void _test0901_non_null_protection_tag() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/*NN*/.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/*\n" + + " NN comment */.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/* NN\n" + + " */.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o // NN \n" + + " .toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- non null protection tag +public void _test0902_non_null_protection_tag() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/*NON-NULL*/.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/* NON-NULL comment */.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/* NON-NULL \n" + + " */.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o // NON-NULL \n" + + " .toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- non null protection tag +public void test0903_non_null_protection_tag() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/*N N*/.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/*NNa*/.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/*aNN */.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/*NON NULL*/.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/*Non-Null*/.toString();\n" + + " if (b) {\n" + + " o = null;\n" + + " }\n" + + " o/*aNON-NULL */.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " o/*N N*/.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " o/*NNa*/.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " o/*aNN */.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 18)\n" + + " o/*NON NULL*/.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 22)\n" + + " o/*Non-Null*/.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n" + + "6. ERROR in X.java (at line 26)\n" + + " o/*aNON-NULL */.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + + +// null analysis -- non null protection tag +public void test0905_non_null_protection_tag() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " boolean b = o != null;\n" + // shades doubts upon o + " o.toString();/*NN*/\n" + // too late to protect => complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o.toString();/*NN*/\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- non null protection tag +public void test0906_non_null_protection_tag() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " boolean b = o != null;\n" + // shades doubts upon o + " /*NN*/o.toString();\n" + // too soon to protect => complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " /*NN*/o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 +// [compiler] Null reference analysis doesn't understand assertions +public void test0950_assert() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " boolean b = o != null;\n" + // shades doubts upon o + " assert(o != null);\n" + // protection + " o.toString();\n" + // quiet + " }\n" + + "}\n"}, + ""); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 +// [compiler] Null reference analysis doesn't understand assertions +public void test0951_assert() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " assert(o == null);\n" + // forces null + " o.toString();\n" + // can only be null + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 +// [compiler] Null reference analysis doesn't understand assertions +public void test0952_assert() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " assert(o != null || b);\n" + // shade doubts + " o.toString();\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 +// [compiler] Null reference analysis doesn't understand assertions +public void test0953_assert_combined() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1, Object o2) {\n" + + " assert(o1 != null && o2 == null);\n" + + " if (o1 == null) { };\n" + // complain + " if (o2 == null) { };\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o1 == null) { };\n" + + " ^^\n" + + "Null comparison always yields false: The variable o1 cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o1 == null) { };\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " if (o2 == null) { };\n" + + " ^^\n" + + "Redundant null check: The variable o2 can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 +// [compiler] Null reference analysis doesn't understand assertions +public void test0954_assert_fake_reachable() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + runConformTest( + true/*flush*/, + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " assert(false && o != null);\n" + + " if (o == null) { };\n" + // quiet + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " assert(false && o != null);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + "", + "", + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 +// [compiler] Null reference analysis doesn't understand assertions +public void test0955_assert_combined() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " assert(false || o != null);\n" + + " if (o == null) { };\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o == null) { };\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o == null) { };\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127244 +// [compiler] Null reference analysis doesn't understand assertions +public void test0956_assert_combined() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " assert(o != null);\n" + // complain + " if (o == null) { };\n" + // complain + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " assert(o != null);\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " if (o == null) { };\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " if (o == null) { };\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056 +// Test to verify that asserts are exempted from redundant null check warnings, +// but this doesn't affect the downstream info. +public void test0957_assert() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " X foo = new X();\n" + + " assert (foo != null);\n" + //don't warn + " if (foo == null) {}\n" + + " X foo2 = new X();\n" + + " assert (foo2 == null);\n" + //don't warn + " if (foo2 == null) {}\n" + + " X bar = null;\n" + + " assert (bar == null);\n" + //don't warn + " if (bar == null) {}\n" + + " X bar2 = null;\n" + + " assert (bar2 != null);\n" + //don't warn + " if (bar2 == null) {}\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (foo == null) {}\n" + + " ^^^\n" + + "Null comparison always yields false: The variable foo cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " if (foo == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " assert (foo2 == null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable foo2 cannot be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " if (foo2 == null) {}\n" + + " ^^^^\n" + + "Redundant null check: The variable foo2 can only be null at this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " if (bar == null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable bar can only be null at this location\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " assert (bar2 != null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 can only be null at this location\n" + + "----------\n" + + "7. ERROR in X.java (at line 14)\n" + + " if (bar2 == null) {}\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + + "----------\n" + + "8. WARNING in X.java (at line 14)\n" + + " if (bar2 == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056 +// Test to verify that asserts are exempted from null comparison warnings, +// but this doesn't affect the downstream info. +public void test0958_assert() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "public class X {\n" + + " void m() {\n" + + " HashMap map = new HashMap();\n" + + " X bar = null;\n" + + " X foo = map.get(1);\n" + + " if (foo == null) {\n" + + " foo = new X();\n" + + " map.put(1, foo);\n" + + " }\n" + + " assert (foo != null && bar == null);\n" + // don't warn but do the null analysis + " if (foo != null) {}\n" + // warn + " if (bar == null) {}\n" + // warn + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " if (foo != null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable foo cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " if (bar == null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable bar can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056 +// Test to verify that asserts are exempted from redundant null check warnings in a looping context, +// but this doesn't affect the downstream info. +public void test0959a_assert_loop() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " X foo = new X();\n" + + " X foo2 = new X();\n" + + " X bar = null;\n" + + " X bar2 = null;\n" + + " while (true) {\n" + + " assert (foo != null);\n" + //don't warn + " if (foo == null) {}\n" + + " assert (foo2 == null);\n" + //don't warn + " if (foo2 == null) {}\n" + + " assert (bar == null);\n" + //don't warn + " if (bar == null) {}\n" + + " assert (bar2 != null);\n" + //don't warn + " if (bar2 == null) {}\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (foo == null) {}\n" + + " ^^^\n" + + "Null comparison always yields false: The variable foo cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " if (foo == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " assert (foo2 == null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable foo2 cannot be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " if (foo2 == null) {}\n" + + " ^^^^\n" + + "Redundant null check: The variable foo2 can only be null at this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " if (bar == null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable bar can only be null at this location\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " assert (bar2 != null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 can only be null at this location\n" + + "----------\n" + + "7. ERROR in X.java (at line 15)\n" + + " if (bar2 == null) {}\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + + "----------\n" + + "8. WARNING in X.java (at line 15)\n" + + " if (bar2 == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056 +// Test to verify that asserts are exempted from redundant null check warnings in a looping context, +// but this doesn't affect the downstream info. +public void test0959b_assert_loop() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " while (true) {\n" + + " X foo = new X();\n" + + " assert (foo != null);\n" + //don't warn + " if (foo == null) {}\n" + + " X foo2 = new X();\n" + + " assert (foo2 == null);\n" + //don't warn + " if (foo2 == null) {}\n" + + " X bar = null;\n" + + " assert (bar == null);\n" + //don't warn + " if (bar == null) {}\n" + + " X bar2 = null;\n" + + " assert (bar2 != null);\n" + //don't warn + " if (bar2 == null) {}\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (foo == null) {}\n" + + " ^^^\n" + + "Null comparison always yields false: The variable foo cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " if (foo == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " assert (foo2 == null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable foo2 cannot be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " if (foo2 == null) {}\n" + + " ^^^^\n" + + "Redundant null check: The variable foo2 can only be null at this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 12)\n" + + " if (bar == null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable bar can only be null at this location\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " assert (bar2 != null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 can only be null at this location\n" + + "----------\n" + + "7. ERROR in X.java (at line 15)\n" + + " if (bar2 == null) {}\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + + "----------\n" + + "8. WARNING in X.java (at line 15)\n" + + " if (bar2 == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056 +// Test to verify that asserts are exempted from redundant null check warnings in a finally context, +// but this doesn't affect the downstream info. +public void test0960_assert_finally() { + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " X foo = new X();\n" + + " X foo2 = new X();\n" + + " X bar = null;\n" + + " X bar2 = null;\n" + + " try {\n" + + " System.out.println(\"Inside try\");\n" + + " }\n" + + " finally {\n" + + " assert (foo != null);\n" + //don't warn + " if (foo == null) {}\n" + + " assert (foo2 == null);\n" + //don't warn + " if (foo2 == null) {}\n" + + " assert (bar == null);\n" + //don't warn + " if (bar == null) {}\n" + + " assert (bar2 != null);\n" + //don't warn + " if (bar2 == null) {}\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " if (foo == null) {}\n" + + " ^^^\n" + + "Null comparison always yields false: The variable foo cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " if (foo == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " assert (foo2 == null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable foo2 cannot be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " if (foo2 == null) {}\n" + + " ^^^^\n" + + "Redundant null check: The variable foo2 can only be null at this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 16)\n" + + " if (bar == null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable bar can only be null at this location\n" + + "----------\n" + + "6. ERROR in X.java (at line 17)\n" + + " assert (bar2 != null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 can only be null at this location\n" + + "----------\n" + + "7. ERROR in X.java (at line 18)\n" + + " if (bar2 == null) {}\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + + "----------\n" + + "8. WARNING in X.java (at line 18)\n" + + " if (bar2 == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// null analysis -- notNull protection tag +public void _test0900_notNull_protection_tag() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(/** @notNull */ Object o) {\n" + + " boolean b = o != null;\n" + + " }\n" + + "}\n"}, + "ERR cannot be null"); +} + +// null analysis -- notNull protection tag +public void _test0901_notNull_protection_tag() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " /** @notNull */ Object l = o;\n" + + " }\n" + + "}\n"}, + "ERR cannot be null... ou pas ?"); +} + +// null analysis -- notNull protection tag +public void _test0902_notNull_protection_tag() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(/** @nullable */ Object o) {\n" + + " /** @notNull */ Object l = o;\n" + + " }\n" + + "}\n"}, + "ERR cannot be null"); +} + +// null analysis -- notNull protection tag +public void test0903_notNull_protection_tag() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object bar() {\n" + + " return null;\n" + + " }\n" + + " void foo() {\n" + + " /** @notNull */ Object l = bar();\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- notNull protection tag +public void _test0904_notNull_protection_tag() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /** @notNull */\n" + + " Object bar() {\n" + + " return new Object();\n" + + " }\n" + + " void foo() {\n" + + " Object l = bar();\n" + + " if (l == null) { /* empty */ }\n" + + " }\n" + + "}\n"}, + "ERR cannot be null"); +} + +// null analysis -- notNull protection tag +public void _test0905_notNull_protection_tag() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " /** @notNull */\n" + + " Object bar() {\n" + + " return null;\n" + + " }\n" + + "}\n"}, + "ERR cannot be null"); +} + +// null analysis -- nullable tag +public void _test0950_nullable_tag() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(/** @nullable */ Object o) {\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "ERR may be null"); +} + +// null analysis -- nullable tag +public void _test0951_nullable_tag() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(/** @nullable */ Object o) {\n" + + " Object l = o;\n" + + " l.toString();\n" + + " }\n" + + "}\n"}, + "ERR may be null"); +} + +// null analysis -- nullable tag +public void _test0952_nullable_tag() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " /** @nullable */ Object o;\n" + + " if (b) {\n" + + " o = new Object();\n" + + " }\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "ERR may be null"); +} + +// moved from AssignmentTest +public void test1004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X foo(X x) {\n" + + " x.foo(null); // 0\n" + + " if (x != null) { // 1\n" + + " if (x == null) { // 2\n" + + " x.foo(null); // 3\n" + + " } else if (x instanceof X) { // 4\n" + + " x.foo(null); // 5 \n" + + " } else if (x != null) { // 6\n" + + " x.foo(null); // 7\n" + + " }\n" + + " x.foo(null); // 8\n" + + " }\n" + + " return this;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (x != null) { // 1\n" + + " ^\n" + + "Redundant null check: The variable x cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " if (x == null) { // 2\n" + + " ^\n" + + "Null comparison always yields false: The variable x cannot be null at this location\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " if (x == null) { // 2\n" + + " x.foo(null); // 3\n" + + " } else if (x instanceof X) { // 4\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " } else if (x != null) { // 6\n" + + " ^\n" + + "Redundant null check: The variable x cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1005() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Class c) {\n" + + " if (c.isArray() ) {\n" + + " } else if (c == java.lang.String.class ) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test1006() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " if (x == this)\n" + + " return;\n" + + " x.foo(this);\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test1007() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x, X x2) {\n" + + " if (x != null)\n" + + " return;\n" + + " x = x2;\n" + + " if (x == null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test1008() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x, X x2) {\n" + + " if (x != null)\n" + + " return;\n" + + " try {\n" + + " x = x2;\n" + + " } catch(Exception e) {}\n" + + " if (x == null) {\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test1009() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "\n" + + "public class X {\n" + + " boolean check(String name) { return true; }\n" + + " Class bar(String name) throws ClassNotFoundException { return null; }\n" + + " File baz(String name) { return null; }\n" + + " \n" + + " public Class foo(String name, boolean resolve) throws ClassNotFoundException {\n" + + " \n" + + " Class c = bar(name);\n" + + " if (c != null)\n" + + " return c;\n" + + " if (check(name)) {\n" + + " try {\n" + + " c= bar(name);\n" + + " return c;\n" + + " } catch (ClassNotFoundException e) {\n" + + " // keep searching\n" + + " // only path to here left c unassigned from try block, means it was assumed to be null\n" + + " }\n" + + " }\n" + + " if (c == null) {// should complain: c can only be null\n" + + " File file= baz(name);\n" + + " if (file == null)\n" + + " throw new ClassNotFoundException();\n" + + " }\n" + + " return c;\n" + + " }\n" + + "\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 22)\n" + + " if (c == null) {// should complain: c can only be null\n" + + " ^\n" + + "Redundant null check: The variable c can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1010() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " X itself() { return this; }\n" + + "\n" + + " void bar() {\n" + + " X itself = this.itself();\n" + + " if (this == itself) {\n" + + " System.out.println(itself.toString()); //1\n" + + " } else {\n" + + " System.out.println(itself.toString()); //2\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test1011() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " X itself() { return this; }\n" + + "\n" + + " void bar() {\n" + + " X itself = this.itself();\n" + + " if (this == itself) {\n" + + " X other = (X)itself;\n" + + " if (other != null) {\n" + + " }\n" + + " if (other == null) {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (other != null) {\n" + + " ^^^^^\n" + + "Redundant null check: The variable other cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " if (other == null) {\n" + + " ^^^^^\n" + + "Null comparison always yields false: The variable other cannot be null at this location\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " if (other == null) {\n" + + " }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1012() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " Object o = null;\n" + + " do {\n" + + " if (o == null) {\n" + + " return;\n" + + " }\n" + + " // o = bar();\n" + + " } while (true);\n" + + " }\n" + + " X bar() { \n" + + " return null; \n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null) {\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// x cannot equal this then null with no assignment in between +// each diagnostic is locally sound though +public void test1013() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " if (x == this) {\n" + + " if (x == null) {\n" + + " x.foo(this);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (x == null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable x cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (x == null) {\n" + + " x.foo(this);\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1014() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = null;\n" + + " try {\n" + + " x = this;\n" + + " } finally {\n" + + " x.foo(null);\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test1015() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " int i = 1;\n" + + " switch (i) {\n" + + " case 1:\n" + + " o = new Object();\n" + + " break;\n" + + " }\n" + + " if (o != null)\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test1016() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = null;\n" + + " try {\n" + + " x = null;\n" + + " } finally {\n" + + " if (x != null) {\n" + + " x.foo(null);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " x = null;\n" + + " ^\n" + + "Redundant assignment: The variable x can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " if (x != null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable x can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1017() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X x) {\n" + + " x = this;\n" + + " try {\n" + + " x = null;\n" + + " } finally {\n" + + " if (x == null) {\n" + + " x.foo(null);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (x == null) {\n" + + " ^\n" + + "Redundant null check: The variable x can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " x.foo(null);\n" + + " ^\n" + + "Null pointer access: The variable x can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1018() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " Object o = null;\n" + + " do {\n" + + " if (o != null) return;\n" + + " o = null;\n" + + " } while (true);\n" + + " }\n" + + " X bar() { \n" + + " return null; \n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o != null) return;\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " o = null;\n" + + " ^\n" + + "Redundant assignment: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1019() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final char[] replaceOnCopy(\n" + + " char[] array,\n" + + " char toBeReplaced,\n" + + " char replacementChar) {\n" + + " \n" + + " char[] result = null;\n" + + " for (int i = 0, length = array.length; i < length; i++) {\n" + + " char c = array[i];\n" + + " if (c == toBeReplaced) {\n" + + " if (result == null) {\n" + + " result = new char[length];\n" + + " System.arraycopy(array, 0, result, 0, i);\n" + + " }\n" + + " result[i] = replacementChar;\n" + + " } else if (result != null) {\n" + + " result[i] = c;\n" + + " }\n" + + " }\n" + + " if (result == null) return array;\n" + + " return result;\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test1021() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int kind;\n" + + " X parent;\n" + + " Object[] foo() { return null; }\n" + + " void findTypeParameters(X scope) {\n" + + " Object[] typeParameters = null;\n" + + " while (scope != null) {\n" + + " typeParameters = null;\n" + + " switch (scope.kind) {\n" + + " case 0 :\n" + + " typeParameters = foo();\n" + + " break;\n" + + " case 1 :\n" + + " typeParameters = foo();\n" + + " break;\n" + + " case 2 :\n" + + " return;\n" + + " }\n" + + " if(typeParameters != null) {\n" + + " foo();\n" + + " }\n" + + " scope = scope.parent;\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test1022() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bool() { return true; }\n" + + " void doSomething() {}\n" + + " \n" + + " void foo() {\n" + + " Object progressJob = null;\n" + + " while (bool()) {\n" + + " if (bool()) {\n" + + " if (progressJob != null)\n" + + " progressJob = null;\n" + + " doSomething();\n" + + " }\n" + + " try {\n" + + " if (progressJob == null) {\n" + + " progressJob = new Object();\n" + + " }\n" + + " } finally {\n" + + " doSomething();\n" + + " }\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +public void test1023() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo(Object that) {\n" + + " Object o = new Object();\n" + + " while (that != null) {\n" + + " try {\n" + + " o = null;\n" + + " break;\n" + + " } finally {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " if (o == null) return;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " if (o == null) return;\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " if (o == null) return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1024() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " boolean bool() { return true; }\n" + + " void doSomething() {}\n" + + " \n" + + " void foo() {\n" + + " Object progressJob = null;\n" + + " while (bool()) {\n" + + " if (progressJob != null)\n" + + " progressJob = null;\n" + + " doSomething();\n" + + " try {\n" + + " if (progressJob == null) {\n" + + " progressJob = new Object();\n" + + " }\n" + + " } finally {\n" + + " doSomething();\n" + + " }\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " if (progressJob == null) {\n" + + " ^^^^^^^^^^^\n" + + "Redundant null check: The variable progressJob can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1025() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " Object o;\n" + + " try {\n" + + " o = null;\n" + + " } finally {\n" + + " o = new Object();\n" + + " }\n" + + " if (o == null) return;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " if (o == null) return;\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " if (o == null) return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// TODO (philippe) reenable once fixed +public void _test1026() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " Object o;\n" + + " try {\n" + + " o = null;\n" + + " } finally {\n" + + " if (args == null) o = new Object();\n" + + " }\n" + + " if (o == null) System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n"}, + "SUCCESS"); +} + +public void test1027() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (b) {\n" + + " try {\n" + + " o = null;\n" + + " } finally {\n" + + " if (o == null) \n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " if (o == null) return;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (o == null) \n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n"); +} + +// TODO (philippe) reenable once fixed +public void _test1028() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean b;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " while (b) {\n" + + " try {\n" + + " o = null;\n" + + " break;\n" + + " } finally {\n" + + " if (o == null) \n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " if (o == null) return;\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test1029() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object o = null;\n" + + " int i = 0;\n" + + " while (i++ < 2) {\n" + + " try {\n" + + " if (i == 2) return;\n" + + " o = null;\n" + + " } finally {\n" + + " if (i == 2) System.out.println(o);\n" + + " o = \"SUCCESS\";\n" + + " }\n" + + " }\n" + + " if (o == null) return;\n" + + " }\n" + + "}\n"}, + "SUCCESS"); +} + +public void test1030() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " Object a = null;\n" + + " while (true) {\n" + + " a = null;\n" + + " if (a == null) {\n" + + " System.out.println();\n" + + " }\n" + + " a = new Object();\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " a = null;\n" + + " ^\n" + + "Redundant assignment: The variable a can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " if (a == null) {\n" + + " ^\n" + + "Redundant null check: The variable a can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1031() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " Object a = null;\n" + + " while (true) {\n" + + " a = null;\n" + + " if (a == null) {\n" + + " System.out.println();\n" + + " }\n" + + " a = new Object();\n" + + " break;\n" + + " }\n" + + " if (a == null) {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " a = null;\n" + + " ^\n" + + "Redundant assignment: The variable a can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " if (a == null) {\n" + + " ^\n" + + "Redundant null check: The variable a can only be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " if (a == null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable a cannot be null at this location\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " if (a == null) {\n" + + " System.out.println();\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test1032() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o1 = this;\n" + + " Object o3;\n" + + " while (o1 != null && (o3 = o1) != null) {\n" + + " o1 = o3;\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " while (o1 != null && (o3 = o1) != null) {\n" + + " ^^\n" + + "Redundant null check: The variable o1 cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " while (o1 != null && (o3 = o1) != null) {\n" + + " ^^^^^^^^^\n" + + "Redundant null check: The variable o3 cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// (simplified to focus on nulls) +public void test1033() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " void foo() {\n" + + " String a,b;\n" + + " do{\n" + + " a=\"Hello \";\n" + + " }while(a!=null);\n" + + " if(a!=null)\n" + + " { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " }while(a!=null);\n" + + " ^\n" + + "Redundant null check: The variable a cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " if(a!=null)\n" + + " ^\n" + + "Null comparison always yields false: The variable a can only be null at this location\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// from AssignmentTest#test034, simplified +public void test1034() { + runNegativeNullTest( + new String[] { + "X.java", + "public final class X \n" + + "{\n" + + " void foo()\n" + + " {\n" + + " String rs = null;\n" + + " try\n" + + " {\n" + + " rs = \"\";\n" + + " return;\n" + + " }\n" + + " catch (Exception e)\n" + + " {\n" + + " }\n" + + " finally\n" + + " {\n" + + " if (rs != null)\n" + + " {\n" + + " try\n" + + " {\n" + + " rs.toString();\n" + + " }\n" + + " catch (Exception e)\n" + + " {\n" + + " }\n" + + " }\n" + + " }\n" + + " return;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " if (rs != null)\n" + + " ^^\n" + + "Redundant null check: The variable rs cannot be null at this location\n" + + "----------\n"); +} + +public void test1036() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo() {\n" + + " Object o = new Object();\n" + + " do {\n" + + " o = null;\n" + + " } while (o != null);\n" + + " if (o == null) {\n" + + " // throw new Exception();\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " } while (o != null);\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " if (o == null) {\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 +// adding distinct options to control null checks in more detail +// default for null options is Ignore +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=192875 +// changed default for null access to warning +public void test1050_options_all_default() { + try { + setNullRelatedOptions = false; + runConformTest( + true, // flush + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object p) {\n" + + " Object o = null;\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " if (p == null) {}\n" + // taint p + " o.toString();\n" + + " p.toString();\n" + + " }\n" + + "}\n" + } /* testFiles */, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + "" /* expectedErrorString */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); + } + finally { + setNullRelatedOptions = true; + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 +// adding distinct options to control null checks in more detail +// all null options set to Ignore +public void test1051_options_all_ignore() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object p) {\n" + + " Object o = null;\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " if (p == null) {}\n" + // taint p + " o.toString();\n" + + " p.toString();\n" + + " }\n" + + "}\n"}, + null /* no expected output string */, + null /* no extra class libraries */, + true /* flush output directory */, + null /* no vm arguments */, + customOptions, + null /* no custom requestor*/, + false /* do not skip javac for this peculiar test */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 +// adding distinct options to control null checks in more detail +// all options set to error +public void test1052_options_all_error() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object p) {\n" + + " Object o = null;\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " if (p == null) {}\n" + // taint p + " o.toString();\n" + + " p.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " p.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable p may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 +// adding distinct options to control null checks in more detail +// selectively changing error levels +public void test1053_options_mix() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(Object p) {\n" + + " Object o = null;\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " if (p == null) {}\n" + // taint p + " o.toString();\n" + + " p.toString();\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 4)\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 +// adding distinct options to control null checks in more detail +// selectively changing error levels +public void test1054_options_mix() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(Object p) {\n" + + " Object o = null;\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " if (p == null) {}\n" + // taint p + " o.toString();\n" + + " p.toString();\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 +// adding distinct options to control null checks in more detail +// selectively changing error levels +public void test1055_options_mix() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " void foo(Object p) {\n" + + " Object o = null;\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " if (p == null) {}\n" + // taint p + " o.toString();\n" + + " p.toString();\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " p.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable p may be null at this location\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 +// adding distinct options to control null checks in more detail +// selectively changing error levels +public void test1056_options_mix_with_SuppressWarnings() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + "@SuppressWarnings(\"null\")\n" + + " void foo(Object p) {\n" + + " Object o = null;\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " if (p == null) {}\n" + // taint p + " o.toString();\n" + + " p.toString();\n" + + " }\n" + + "}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. WARNING in X.java (at line 5)\n" + + " if (o != null) {\n" + + " o = null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. 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", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 +// adding distinct options to control null checks in more detail +public void test1057_options_instanceof_is_check() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object p) {\n" + + " Object o = null;\n" + + " if (p == null) {}\n" + // taint p + " if (o instanceof String) {};\n" + + " if (p instanceof String) {};\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o instanceof String) {};\n" + + " ^\n" + + "instanceof always yields false: The variable o can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 +// adding distinct options to control null checks in more detail +public void test1058_options_instanceof_is_check() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object p) {\n" + + " Object o = null;\n" + + " if (p == null) {}\n" + // taint p + " if (o instanceof String) {};\n" + + " if (p instanceof String) {};\n" + + " }\n" + + "}\n"}, + null /* no expected output string */, + null /* no extra class libraries */, + true /* flush output directory */, + null /* no vm arguments */, + customOptions, + null /* no custom requestor*/, + false /* do not skip javac for this peculiar test */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=170704 +// adding distinct options to control null checks in more detail +public void test1059_options_cannot_be_null_check() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object p) {\n" + + " Object o = new Object();\n" + + " if (o == null) {}\n" + + " }\n" + + "}\n"}, + null /* no expected output string */, + null /* no extra class libraries */, + true /* flush output directory */, + null /* no vm arguments */, + customOptions, + null /* no custom requestor*/, + false /* do not skip javac for this peculiar test */); +} +// encoding validation +public void test1500() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, int i, boolean b, Object u) {\n" + + " o.toString();\n" + + " switch (i) {\n" + + " case 0:\n" + + " if (b) {\n" + + " o = u;\n" + + " } else {\n" + + " o = new Object();\n" + + " }\n" + + " break;\n" + + " }\n" + + " if (o == null) { /* empty */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +// encoding validation +public void test1501() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, int i, boolean b, Object u) {\n" + + " if (b) {\n" + + " o = new Object();\n" + + " }\n" + + " o.toString();\n" + + " switch (i) {\n" + + " case 0:\n" + + " if (b) {\n" + + " o = u;\n" + + " } else {\n" + + " o = new Object();\n" + + " }\n" + + " break;\n" + + " }\n" + + " if (o == null) { /* empty */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +// encoding validation +public void test1502() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, int i, boolean b, Object u) {\n" + + " if (b) {\n" + + " o = u;\n" + + " }\n" + + " o.toString();\n" + + " switch (i) {\n" + + " case 0:\n" + + " if (b) {\n" + + " o = u;\n" + + " } else {\n" + + " o = new Object();\n" + + " }\n" + + " break;\n" + + " }\n" + + " if (o == null) { /* empty */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +// encoding validation +public void test1503() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, int i, boolean b, Object u) {\n" + + " if (b) {\n" + + " o = u;\n" + + " } else {\n" + + " o = new Object();\n" + + " }\n" + + " o.toString();\n" + + " switch (i) {\n" + + " case 0:\n" + + " if (b) {\n" + + " o = u;\n" + + " } else {\n" + + " o = new Object();\n" + + " }\n" + + " break;\n" + + " }\n" + + " if (o == null) { /* empty */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +// flow info low-level validation +public void test2000_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo() {\n" + + " Object o0 = new Object(), o1 = o0, o2 = o0, o3 = o0, o4 = o0,\n" + + " o5 = o0, o6 = o0, o7 = o0, o8 = o0, o9 = o0,\n" + + " o10 = o0, o11 = o0, o12 = o0, o13 = o0, o14 = o0,\n" + + " o15 = o0, o16 = o0, o17 = o0, o18 = o0, o19 = o0,\n" + + " o20 = o0, o21 = o0, o22 = o0, o23 = o0, o24 = o0,\n" + + " o25 = o0, o26 = o0, o27 = o0, o28 = o0, o29 = o0,\n" + + " o30 = o0, o31 = o0, o32 = o0, o33 = o0, o34 = o0,\n" + + " o35 = o0, o36 = o0, o37 = o0, o38 = o0, o39 = o0,\n" + + " o40 = o0, o41 = o0, o42 = o0, o43 = o0, o44 = o0,\n" + + " o45 = o0, o46 = o0, o47 = o0, o48 = o0, o49 = o0,\n" + + " o50 = o0, o51 = o0, o52 = o0, o53 = o0, o54 = o0,\n" + + " o55 = o0, o56 = o0, o57 = o0, o58 = o0, o59 = o0,\n" + + " o60 = o0, o61 = o0, o62 = o0, o63 = o0, o64 = o0,\n" + + " o65 = o0, o66 = o0, o67 = o0, o68 = o0, o69 = o0;\n" + + " if (o65 == null) { /* */ }\n" + // complain + " if (o65 != null) { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " if (o65 == null) { /* */ }\n" + + " ^^^\n" + + "Null comparison always yields false: The variable o65 cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 18)\n" + + " if (o65 == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 19)\n" + + " if (o65 != null) { /* */ }\n" + + " ^^^\n" + + "Redundant null check: The variable o65 cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +public void test2001_flow_info() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo(\n" + + " Object o0, Object o1, Object o2, Object o3, Object o4,\n" + + " Object o5, Object o6, Object o7, Object o8, Object o9,\n" + + " Object o10, Object o11, Object o12, Object o13, Object o14,\n" + + " Object o15, Object o16, Object o17, Object o18, Object o19,\n" + + " Object o20, Object o21, Object o22, Object o23, Object o24,\n" + + " Object o25, Object o26, Object o27, Object o28, Object o29,\n" + + " Object o30, Object o31, Object o32, Object o33, Object o34,\n" + + " Object o35, Object o36, Object o37, Object o38, Object o39,\n" + + " Object o40, Object o41, Object o42, Object o43, Object o44,\n" + + " Object o45, Object o46, Object o47, Object o48, Object o49,\n" + + " Object o50, Object o51, Object o52, Object o53, Object o54,\n" + + " Object o55, Object o56, Object o57, Object o58, Object o59,\n" + + " Object o60, Object o61, Object o62, Object o63, Object o64,\n" + + " Object o65, Object o66, Object o67, Object o68, Object o69) {\n" + + " if (o65 == null) { /* */ }\n" + + " if (o65 != null) { /* */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test2002_flow_info() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m0, m1, m2, m3, m4,\n" + + " m5, m6, m7, m8, m9,\n" + + " m10, m11, m12, m13, m14,\n" + + " m15, m16, m17, m18, m19,\n" + + " m20, m21, m22, m23, m24,\n" + + " m25, m26, m27, m28, m29,\n" + + " m30, m31, m32, m33, m34,\n" + + " m35, m36, m37, m38, m39,\n" + + " m40, m41, m42, m43, m44,\n" + + " m45, m46, m47, m48, m49,\n" + + " m50, m51, m52, m53, m54,\n" + + " m55, m56, m57, m58, m59,\n" + + " m60, m61, m62, m63;\n" + + " void foo(Object o) {\n" + + " if (o == null) { /* */ }\n" + + " if (o != null) { /* */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test2003_flow_info() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m0, m1, m2, m3, m4,\n" + + " m5, m6, m7, m8, m9,\n" + + " m10, m11, m12, m13, m14,\n" + + " m15, m16, m17, m18, m19,\n" + + " m20, m21, m22, m23, m24,\n" + + " m25, m26, m27, m28, m29,\n" + + " m30, m31, m32, m33, m34,\n" + + " m35, m36, m37, m38, m39,\n" + + " m40, m41, m42, m43, m44,\n" + + " m45, m46, m47, m48, m49,\n" + + " m50, m51, m52, m53, m54,\n" + + " m55, m56, m57, m58, m59,\n" + + " m60, m61, m62, m63;\n" + + " void foo(Object o) {\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test2004_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m0, m1, m2, m3, m4,\n" + + " m5, m6, m7, m8, m9,\n" + + " m10, m11, m12, m13, m14,\n" + + " m15, m16, m17, m18, m19,\n" + + " m20, m21, m22, m23, m24,\n" + + " m25, m26, m27, m28, m29,\n" + + " m30, m31, m32, m33, m34,\n" + + " m35, m36, m37, m38, m39,\n" + + " m40, m41, m42, m43, m44,\n" + + " m45, m46, m47, m48, m49,\n" + + " m50, m51, m52, m53, m54,\n" + + " m55, m56, m57, m58, m59,\n" + + " m60, m61, m62, m63;\n" + + " void foo() {\n" + + " Object o;\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "The local variable o may not have been initialized\n" + + "----------\n"); +} + +public void test2005_flow_info() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m0, m1, m2, m3, m4,\n" + + " m5, m6, m7, m8, m9,\n" + + " m10, m11, m12, m13, m14,\n" + + " m15, m16, m17, m18, m19,\n" + + " m20, m21, m22, m23, m24,\n" + + " m25, m26, m27, m28, m29,\n" + + " m30, m31, m32, m33, m34,\n" + + " m35, m36, m37, m38, m39,\n" + + " m40, m41, m42, m43, m44,\n" + + " m45, m46, m47, m48, m49,\n" + + " m50, m51, m52, m53, m54,\n" + + " m55, m56, m57, m58, m59,\n" + + " m60, m61, m62, m63;\n" + + " void foo(Object o) {\n" + + " o = null;\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test2006_flow_info() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m0, m1, m2, m3, m4,\n" + + " m5, m6, m7, m8, m9,\n" + + " m10, m11, m12, m13, m14,\n" + + " m15, m16, m17, m18, m19,\n" + + " m20, m21, m22, m23, m24,\n" + + " m25, m26, m27, m28, m29,\n" + + " m30, m31, m32, m33, m34,\n" + + " m35, m36, m37, m38, m39,\n" + + " m40, m41, m42, m43, m44,\n" + + " m45, m46, m47, m48, m49,\n" + + " m50, m51, m52, m53, m54,\n" + + " m55, m56, m57, m58, m59,\n" + + " m60, m61, m62, m63;\n" + + " void foo() {\n" + + " Object o = null;\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test2007_flow_info() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m0, m1, m2, m3, m4,\n" + + " m5, m6, m7, m8, m9,\n" + + " m10, m11, m12, m13, m14,\n" + + " m15, m16, m17, m18, m19,\n" + + " m20, m21, m22, m23, m24,\n" + + " m25, m26, m27, m28, m29,\n" + + " m30, m31, m32, m33, m34,\n" + + " m35, m36, m37, m38, m39,\n" + + " m40, m41, m42, m43, m44,\n" + + " m45, m46, m47, m48, m49,\n" + + " m50, m51, m52, m53, m54,\n" + + " m55, m56, m57, m58, m59,\n" + + " m60, m61, m62, m63;\n" + + " void foo() {\n" + + " Object o[] = null;\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- flow info +public void test2008_flow_info() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m0, m1, m2, m3, m4,\n" + + " m5, m6, m7, m8, m9,\n" + + " m10, m11, m12, m13, m14,\n" + + " m15, m16, m17, m18, m19,\n" + + " m20, m21, m22, m23, m24,\n" + + " m25, m26, m27, m28, m29,\n" + + " m30, m31, m32, m33, m34,\n" + + " m35, m36, m37, m38, m39,\n" + + " m40, m41, m42, m43, m44,\n" + + " m45, m46, m47, m48, m49,\n" + + " m50, m51, m52, m53, m54,\n" + + " m55, m56, m57, m58, m59,\n" + + " m60, m61, m62, m63;\n" + + " void foo(boolean b) {\n" + + " Object o = null;\n" + + " while (o == null) {\n" + + // quiet: first iteration is sure to find o null, + // but other iterations may change it + " try { /* */ }\n" + + " finally {\n" + + " if (b) {\n" + + " o = new Object();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"}, + ""); +} + +// null analysis -- flow info +public void test2009_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m0, m1, m2, m3, m4,\n" + + " m5, m6, m7, m8, m9,\n" + + " m10, m11, m12, m13, m14,\n" + + " m15, m16, m17, m18, m19,\n" + + " m20, m21, m22, m23, m24,\n" + + " m25, m26, m27, m28, m29,\n" + + " m30, m31, m32, m33, m34,\n" + + " m35, m36, m37, m38, m39,\n" + + " m40, m41, m42, m43, m44,\n" + + " m45, m46, m47, m48, m49,\n" + + " m50, m51, m52, m53, m54,\n" + + " m55, m56, m57, m58, m59,\n" + + " m60, m61, m62, m63;\n" + + " void foo(Object o) {\n" + + " try { /* */ }\n" + + " finally {\n" + + " o = new Object();\n" + + " }\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 20)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- flow info +public void test2010_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m00, m01, m02, m03, m04,\n" + + " m05, m06, m07, m08, m09,\n" + + " m10, m11, m12, m13, m14,\n" + + " m15, m16, m17, m18, m19,\n" + + " m20, m21, m22, m23, m24,\n" + + " m25, m26, m27, m28, m29,\n" + + " m30, m31, m32, m33, m34,\n" + + " m35, m36, m37, m38, m39,\n" + + " m40, m41, m42, m43, m44,\n" + + " m45, m46, m47, m48, m49,\n" + + " m50, m51, m52, m53, m54,\n" + + " m55, m56, m57, m58, m59,\n" + + " m60, m61, m62, m63;\n" + + " void foo() {\n" + + " Object o;\n" + + " try { /* */ }\n" + + " finally {\n" + + " o = new Object();\n" + + " }\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 21)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 21)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- flow info +public void test2011_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m000, m001, m002, m003, m004, m005, m006, m007, m008, m009,\n" + + " m010, m011, m012, m013, m014, m015, m016, m017, m018, m019,\n" + + " m020, m021, m022, m023, m024, m025, m026, m027, m028, m029,\n" + + " m030, m031, m032, m033, m034, m035, m036, m037, m038, m039,\n" + + " m040, m041, m042, m043, m044, m045, m046, m047, m048, m049,\n" + + " m050, m051, m052, m053, m054, m055, m056, m057, m058, m059,\n" + + " m060, m061, m062, m063;\n" + + " void foo() {\n" + + " Object o000, o001, o002, o003, o004, o005, o006, o007, o008, o009,\n" + + " o010, o011, o012, o013, o014, o015, o016, o017, o018, o019,\n" + + " o020, o021, o022, o023, o024, o025, o026, o027, o028, o029,\n" + + " o030, o031, o032, o033, o034, o035, o036, o037, o038, o039,\n" + + " o040, o041, o042, o043, o044, o045, o046, o047, o048, o049,\n" + + " o050, o051, o052, o053, o054, o055, o056, o057, o058, o059,\n" + + " o060, o061, o062, o063;\n" + + " Object o;\n" + + " try {\n" + + " o000 = new Object();\n" + + " }\n" + + " finally {\n" + + " o = new Object();\n" + + " }\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 24)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- flow info +public void test2012_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Object m000, m001, m002, m003, m004, m005, m006, m007, m008, m009,\n" + + " m010, m011, m012, m013, m014, m015, m016, m017, m018, m019,\n" + + " m020, m021, m022, m023, m024, m025, m026, m027, m028, m029,\n" + + " m030, m031, m032, m033, m034, m035, m036, m037, m038, m039,\n" + + " m040, m041, m042, m043, m044, m045, m046, m047, m048, m049,\n" + + " m050, m051, m052, m053, m054, m055, m056, m057, m058, m059,\n" + + " m060, m061, m062, m063;\n" + + " void foo() {\n" + + " Object o000, o001, o002, o003, o004, o005, o006, o007, o008, o009,\n" + + " o010, o011, o012, o013, o014, o015, o016, o017, o018, o019,\n" + + " o020, o021, o022, o023, o024, o025, o026, o027, o028, o029,\n" + + " o030, o031, o032, o033, o034, o035, o036, o037, o038, o039,\n" + + " o040, o041, o042, o043, o044, o045, o046, o047, o048, o049,\n" + + " o050, o051, o052, o053, o054, o055, o056, o057, o058, o059,\n" + + " o060, o061, o062, o063;\n" + + " Object o;\n" + + " try {\n" + + " o = new Object();\n" + + " }\n" + + " finally {\n" + + " o000 = new Object();\n" + + " }\n" + + " if (o == null) { /* */ }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " if (o == null) { /* */ }\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 24)\n" + + " if (o == null) { /* */ }\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- flow info +public void test2013_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " Object m000, m001, m002, m003, m004, m005, m006, m007, m008, m009,\n" + + " m010, m011, m012, m013, m014, m015, m016, m017, m018, m019,\n" + + " m020, m021, m022, m023, m024, m025, m026, m027, m028, m029,\n" + + " m030, m031, m032, m033, m034, m035, m036, m037, m038, m039,\n" + + " m040, m041, m042, m043, m044, m045, m046, m047, m048, m049,\n" + + " m050, m051, m052, m053, m054, m055, m056, m057, m058, m059,\n" + + " m060, m061, m062, m063;\n" + + " void foo(Object u) {\n" + + " Object o = null;\n" + + " while (dummy) {\n" + + " o = u;\n" + + " }\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// null analysis -- flow info +public void test2014_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " int m000, m001, m002, m003, m004, m005, m006, m007, m008, m009,\n" + + " m010, m011, m012, m013, m014, m015, m016, m017, m018, m019,\n" + + " m020, m021, m022, m023, m024, m025, m026, m027, m028, m029,\n" + + " m030, m031, m032, m033, m034, m035, m036, m037, m038, m039,\n" + + " m040, m041, m042, m043, m044, m045, m046, m047, m048, m049,\n" + + " m050, m051, m052, m053, m054, m055, m056, m057, m058, m059,\n" + + " m060, m061, m062, m063;\n" + + " final int m064;\n" + + " X() {\n" + + " m064 = 10;\n" + + " class Inner extends X {\n" + + " int m100, m101, m102, m103, m104, m105, m106, m107, m108, m109,\n" + + " m110, m111, m112, m113, m114, m115, m116, m117, m118, m119,\n" + + " m120, m121, m122, m123, m124, m125, m126, m127, m128, m129,\n" + + " m130, m131, m132, m133, m134, m135, m136, m137, m138, m139,\n" + + " m140, m141, m142, m143, m144, m145, m146, m147, m148, m149,\n" + + " m150, m151, m152, m153, m154, m155, m156, m157, m158, m159,\n" + + " m160, m161, m162, m163;\n" + + " final int m164;\n" + + " int bar() {\n" + + " return m100 + m101 + m102 + m103 + m104 +\n" + + " m105 + m106 + m107 + m108 + m109 +\n" + + " m110 + m111 + m112 + m113 + m114 +\n" + + " m115 + m116 + m117 + m118 + m119 +\n" + + " m120 + m121 + m122 + m123 + m124 +\n" + + " m125 + m126 + m127 + m128 + m129 +\n" + + " m130 + m131 + m132 + m133 + m134 +\n" + + " m135 + m136 + m137 + m138 + m139 +\n" + + " m140 + m141 + m142 + m143 + m144 +\n" + + " m145 + m146 + m147 + m148 + m149 +\n" + + " m150 + m151 + m152 + m153 + m154 +\n" + + " m155 + m156 + m157 + m158 + m159 +\n" + + " m160 + m161 + m162 + m163 + m164;\n" + + " }\n" + + " };\n" + + " System.out.println((new Inner()).bar());\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " final int m164;\n" + + " ^^^^\n" + + "The blank final field m164 may not have been initialized\n" + + "----------\n"); +} + +// null analysis -- flow info +public void test2015_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " int m000, m001, m002, m003, m004, m005, m006, m007, m008, m009,\n" + + " m010, m011, m012, m013, m014, m015, m016, m017, m018, m019,\n" + + " m020, m021, m022, m023, m024, m025, m026, m027, m028, m029,\n" + + " m030, m031, m032, m033, m034, m035, m036, m037, m038, m039,\n" + + " m040, m041, m042, m043, m044, m045, m046, m047, m048, m049,\n" + + " m050, m051, m052, m053, m054, m055, m056, m057, m058, m059,\n" + + " m060, m061, m062, m063;\n" + + " final int m200;\n" + + " int m201, m202, m203, m204, m205, m206, m207, m208, m209,\n" + + " m210, m211, m212, m213, m214, m215, m216, m217, m218, m219,\n" + + " m220, m221, m222, m223, m224, m225, m226, m227, m228, m229,\n" + + " m230, m231, m232, m233, m234, m235, m236, m237, m238, m239,\n" + + " m240, m241, m242, m243, m244, m245, m246, m247, m248, m249,\n" + + " m250, m251, m252, m253, m254, m255, m256, m257, m258, m259,\n" + + " m260, m261, m262, m263;\n" + + " int m301, m302, m303, m304, m305, m306, m307, m308, m309,\n" + + " m310, m311, m312, m313, m314, m315, m316, m317, m318, m319,\n" + + " m320, m321, m322, m323, m324, m325, m326, m327, m328, m329,\n" + + " m330, m331, m332, m333, m334, m335, m336, m337, m338, m339,\n" + + " m340, m341, m342, m343, m344, m345, m346, m347, m348, m349,\n" + + " m350, m351, m352, m353, m354, m355, m356, m357, m358, m359,\n" + + " m360, m361, m362, m363;\n" + + " X() {\n" + + " m200 = 10;\n" + + " class Inner extends X {\n" + + " int m100, m101, m102, m103, m104, m105, m106, m107, m108, m109,\n" + + " m110, m111, m112, m113, m114, m115, m116, m117, m118, m119,\n" + + " m120, m121, m122, m123, m124, m125, m126, m127, m128, m129,\n" + + " m130, m131, m132, m133, m134, m135, m136, m137, m138, m139,\n" + + " m140, m141, m142, m143, m144, m145, m146, m147, m148, m149,\n" + + " m150, m151, m152, m153, m154, m155, m156, m157, m158, m159,\n" + + " m160, m161, m162, m163;\n" + + " final int m164;\n" + + " int bar() {\n" + + " return m100 + m101 + m102 + m103 + m104 +\n" + + " m105 + m106 + m107 + m108 + m109 +\n" + + " m110 + m111 + m112 + m113 + m114 +\n" + + " m115 + m116 + m117 + m118 + m119 +\n" + + " m120 + m121 + m122 + m123 + m124 +\n" + + " m125 + m126 + m127 + m128 + m129 +\n" + + " m130 + m131 + m132 + m133 + m134 +\n" + + " m135 + m136 + m137 + m138 + m139 +\n" + + " m140 + m141 + m142 + m143 + m144 +\n" + + " m145 + m146 + m147 + m148 + m149 +\n" + + " m150 + m151 + m152 + m153 + m154 +\n" + + " m155 + m156 + m157 + m158 + m159 +\n" + + " m160 + m161 + m162 + m163 + m164;\n" + + " }\n" + + " };\n" + + " System.out.println((new Inner()).bar());\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 34)\n" + + " final int m164;\n" + + " ^^^^\n" + + "The blank final field m164 may not have been initialized\n" + + "----------\n"); +} + +// null analysis -- flow info +public void test2016_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " int m000, m001, m002, m003, m004, m005, m006, m007, m008, m009,\n" + + " m010, m011, m012, m013, m014, m015, m016, m017, m018, m019,\n" + + " m020, m021, m022, m023, m024, m025, m026, m027, m028, m029,\n" + + " m030, m031, m032, m033, m034, m035, m036, m037, m038, m039,\n" + + " m040, m041, m042, m043, m044, m045, m046, m047, m048, m049,\n" + + " m050, m051, m052, m053, m054, m055, m056, m057, m058, m059,\n" + + " m060, m061;\n" + + " final int m062;\n" + + " {\n" + + " int l063, m201 = 0, m202, m203, m204, m205, m206, m207, m208, m209,\n" + + " m210, m211, m212, m213, m214, m215, m216, m217, m218, m219,\n" + + " m220, m221, m222, m223, m224, m225, m226, m227, m228, m229,\n" + + " m230, m231, m232, m233, m234, m235, m236, m237, m238, m239,\n" + + " m240, m241, m242, m243, m244, m245, m246, m247, m248, m249,\n" + + " m250, m251, m252, m253, m254, m255, m256, m257, m258, m259,\n" + + " m260, m261, m262, m263;\n" + + " int m301, m302, m303, m304, m305, m306, m307, m308, m309,\n" + + " m310, m311, m312, m313, m314, m315, m316, m317, m318, m319,\n" + + " m320, m321, m322, m323, m324, m325, m326, m327, m328, m329,\n" + + " m330, m331, m332, m333, m334, m335, m336, m337, m338, m339,\n" + + " m340, m341, m342, m343, m344, m345, m346, m347, m348, m349,\n" + + " m350, m351, m352, m353, m354, m355, m356, m357, m358, m359,\n" + + " m360 = 0, m361 = 0, m362 = 0, m363 = 0;\n" + + " m062 = m360;\n" + + " }\n" + + " X() {\n" + + " int l0, l1;\n" + + " m000 = l1;\n" + + " class Inner extends X {\n" + + " int bar() {\n" + + " return 0;\n" + + " }\n" + + " };\n" + + " System.out.println((new Inner()).bar());\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 29)\n" + + " m000 = l1;\n" + + " ^^\n" + + "The local variable l1 may not have been initialized\n" + + "----------\n"); +} + +public void test2017_flow_info() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " Object m000, m001, m002, m003, m004, m005, m006, m007, m008, m009,\n" + + " m010, m011, m012, m013, m014, m015, m016, m017, m018, m019,\n" + + " m020, m021, m022, m023, m024, m025, m026, m027, m028, m029,\n" + + " m030, m031, m032, m033, m034, m035, m036, m037, m038, m039,\n" + + " m040, m041, m042, m043, m044, m045, m046, m047, m048, m049,\n" + + " m050, m051, m052, m053, m054, m055, m056, m057, m058, m059,\n" + + " m060, m061, m062, m063;\n" + + " void foo(Object u) {\n" + + " Object o = null;\n" + + " while (dummy) {\n" + + " if (dummy) {\n" + // uncorrelated + " o = u;\n" + + " continue;\n" + + " }\n" + + " }\n" + + " if (o != null) { /* */ }\n" + + " }\n" + + "}\n"}, + ""); +} + +public void test2018_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " Object m000, m001, m002, m003, m004, m005, m006, m007, m008, m009,\n" + + " m010, m011, m012, m013, m014, m015, m016, m017, m018, m019,\n" + + " m020, m021, m022, m023, m024, m025, m026, m027, m028, m029,\n" + + " m030, m031, m032, m033, m034, m035, m036, m037, m038, m039,\n" + + " m040, m041, m042, m043, m044, m045, m046, m047, m048, m049,\n" + + " m050, m051, m052, m053, m054, m055, m056, m057, m058, m059,\n" + + " m060, m061, m062, m063;\n" + + " void foo() {\n" + + " Object o;\n" + + " while (dummy) {\n" + + " if (dummy) {\n" + // uncorrelated + " o = null;\n" + + " continue;\n" + + " }\n" + + " }\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " o.toString();\n" + + " ^\n" + + "The local variable o may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"); +} + +public void test2019_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " Object m000, m001, m002, m003, m004, m005, m006, m007, m008, m009,\n" + + " m010, m011, m012, m013, m014, m015, m016, m017, m018, m019,\n" + + " m020, m021, m022, m023, m024, m025, m026, m027, m028, m029,\n" + + " m030, m031, m032, m033, m034, m035, m036, m037, m038, m039,\n" + + " m040, m041, m042, m043, m044, m045, m046, m047, m048, m049,\n" + + " m050, m051, m052, m053, m054, m055, m056, m057, m058, m059,\n" + + " m060, m061, m062, m063;\n" + + " void foo() {\n" + + " Object o;\n" + + " while (dummy) {\n" + + " if (dummy) {\n" + // uncorrelated + " continue;\n" + + " }\n" + + " o = null;\n" + + " }\n" + + " o.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " o.toString();\n" + + " ^\n" + + "The local variable o may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"); +} + +public void test2020_flow_info() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean dummy;\n" + + " Object m000, m001, m002, m003, m004, m005, m006, m007, m008, m009,\n" + + " m010, m011, m012, m013, m014, m015, m016, m017, m018, m019,\n" + + " m020, m021, m022, m023, m024, m025, m026, m027, m028, m029,\n" + + " m030, m031, m032, m033, m034, m035, m036, m037, m038, m039,\n" + + " m040, m041, m042, m043, m044, m045, m046, m047, m048, m049,\n" + + " m050, m051, m052, m053, m054, m055, m056, m057, m058, m059,\n" + + " m060, m061, m062, m063;\n" + + " int m200, m201, m202, m203, m204, m205, m206, m207, m208, m209,\n" + + " m210, m211, m212, m213, m214, m215, m216, m217, m218, m219,\n" + + " m220, m221, m222, m223, m224, m225, m226, m227, m228, m229,\n" + + " m230, m231, m232, m233, m234, m235, m236, m237, m238, m239,\n" + + " m240, m241, m242, m243, m244, m245, m246, m247, m248, m249,\n" + + " m250, m251, m252, m253, m254, m255, m256, m257, m258, m259,\n" + + " m260, m261;\n" + + " void foo() {\n" + + " Object o0, o1;\n" + + " while (dummy) {\n" + + " o0 = new Object();\n" + + " if (dummy) {\n" + // uncorrelated + " o1 = null;\n" + + " continue;\n" + + " }\n" + + " }\n" + + " o1.toString();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 26)\n" + + " o1.toString();\n" + + " ^^\n" + + "The local variable o1 may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 26)\n" + + " o1.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable o1 may be null at this location\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=291418 +// Test to verify that redundant null checks are properly reported in all loops +public void testBug291418a() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeNullTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(int[] argArray) {\n" + + " int[] array = {2};\n" + + " int[] collectionVar = {1,2};\n" + + " if(argArray == null) return;\n" + + " for(int x:collectionVar) {\n" + + " if (collectionVar == null);\n" + // collectionVar cannot be null here + " if (array == null);\n" + // array is not null here + " if (argArray == null);\n" + // argArray cannot be null here + " }\n" + + " int count = 0;\n" + + " do {\n" + + " count++;\n" + + " if (array == null);\n" + // array is not null here + " if (argArray == null);\n" + // argArray cannot be null here + " } while (count<10);\n" + + " array = new int[0];\n" + // reset tainting by null check + " if (argArray == null) return;\n" + // reset tainting by null check + " for (int i=0; i<2; i++) {\n" + + " if (array == null);\n" + // array is not null here + " if (argArray == null);\n" + // argArray cannot be null here + " }\n" + + " while (true) {\n" + + " if (array == null);\n" + // array is not null here + " if (argArray == null);\n" + // argArray cannot be null here + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (collectionVar == null);\n" + + " ^^^^^^^^^^^^^\n" + + "Null comparison always yields false: The variable collectionVar cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " if (array == null);\n" + + " ^^^^^\n" + + "Null comparison always yields false: The variable array cannot be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " if (argArray == null);\n" + + " ^^^^^^^^\n" + + "Null comparison always yields false: The variable argArray cannot be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " if (array == null);\n" + + " ^^^^^\n" + + "Null comparison always yields false: The variable array cannot be null at this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 15)\n" + + " if (argArray == null);\n" + + " ^^^^^^^^\n" + + "Null comparison always yields false: The variable argArray cannot be null at this location\n" + + "----------\n" + + "6. ERROR in X.java (at line 20)\n" + + " if (array == null);\n" + + " ^^^^^\n" + + "Null comparison always yields false: The variable array cannot be null at this location\n" + + "----------\n" + + "7. ERROR in X.java (at line 21)\n" + + " if (argArray == null);\n" + + " ^^^^^^^^\n" + + "Null comparison always yields false: The variable argArray cannot be null at this location\n" + + "----------\n" + + "8. ERROR in X.java (at line 24)\n" + + " if (array == null);\n" + + " ^^^^^\n" + + "Null comparison always yields false: The variable array cannot be null at this location\n" + + "----------\n" + + "9. ERROR in X.java (at line 25)\n" + + " if (argArray == null);\n" + + " ^^^^^^^^\n" + + "Null comparison always yields false: The variable argArray cannot be null at this location\n" + + "----------\n"); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=291418 +// Test to verify that redundant null checks are properly reported +// in a loop in case the null status is modified downstream in the loop +public void testBug291418b() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeNullTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(int[] argArray) {\n" + + " int[] array = {2};\n" + + " int[] collectionVar = {1,2};\n" + + " if(argArray == null) return;" + + " for(int x:collectionVar) {\n" + + " if (collectionVar == null);\n" + // collectionVar cannot be null here + " if (array == null);\n" + // array is not null in first iteration but assigned null later in the loop. So we keep quiet + " if (argArray == null);\n" + // argArray cannot be null here + " array = null;\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (collectionVar == null);\n" + + " ^^^^^^^^^^^^^\n" + + "Null comparison always yields false: The variable collectionVar cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " if (argArray == null);\n" + + " ^^^^^^^^\n" + + "Null comparison always yields false: The variable argArray cannot be null at this location\n" + + "----------\n"); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=293917 +// Test that a redundant null check doesn't affect the null status of +// a variable downstream. +public void testBug293917a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(){\n" + + " String x = null, y = null;\n" + + " if (x == null) x = \"foo\";\n" + + " if (x != null) y = \"bar\";\n" + + " x.length();\n" + // shouldn't warn here + " y.length();\n" + // shouldn't warn here + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (x == null) x = \"foo\";\n" + + " ^\n" + + "Redundant null check: The variable x can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " if (x != null) y = \"bar\";\n" + + " ^\n" + + "Redundant null check: The variable x cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=293917 +// Test that a redundant null check doesn't affect the null status of +// a variable downstream in a loop. +public void testBug293917b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(){\n" + + " String x = null, y = null;" + + " while(true) {\n" + + " if (x == null) x = \"foo\";\n" + + " if (x != null) y = \"bar\";\n" + + " x.length();\n" + // shouldn't warn here + " y.length();\n" + // shouldn't warn here + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (x != null) y = \"bar\";\n" + + " ^\n" + + "Redundant null check: The variable x cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=293917 +// Test that a redundant null check doesn't affect the null status of +// a variable downstream in a finally block. +public void testBug293917c() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(){\n" + + " String x = null, y = null;" + + " try {}\n" + + " finally {\n" + + " if (x == null) x = \"foo\";\n" + + " if (x != null) y = \"bar\";\n" + + " x.length();\n" + // shouldn't warn here + " y.length();\n" + // shouldn't warn here + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (x == null) x = \"foo\";\n" + + " ^\n" + + "Redundant null check: The variable x can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " if (x != null) y = \"bar\";\n" + + " ^\n" + + "Redundant null check: The variable x cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=190623 +// Test that a redundant null check doesn't affect the null status of +// a variable downstream. +public void testBug190623() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Number n = getNumber();\n" + + " if (n instanceof Double) {\n" + + " Double d= (Double) n;\n" + + " if (d != null && d.isNaN()) {\n" + + " System.out.println(\"outside loop\");\n" + + " }\n" + + " for (int i= 0; i < 10; i++) {\n" + + " if (d != null && d.isNaN()) {\n" + + " System.out.println(\"inside loop\");\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " private static Number getNumber() {\n" + + " return Double.valueOf(Math.sqrt(-1));\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (d != null && d.isNaN()) {\n" + + " ^\n" + + "Redundant null check: The variable d cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " if (d != null && d.isNaN()) {\n" + + " ^\n" + + "Redundant null check: The variable d cannot be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=299900 +//Test to verify that null checks are properly reported for the variable(s) +//in the right expression of an OR condition statement. +public void testBug299900a() { + runNegativeNullTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object foo, Object bar) {\n" + + " if(foo == null || bar == null) {\n" + + " System.out.println(foo.toString());\n" + + " System.out.println(bar.toString());\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " System.out.println(foo.toString());\n" + + " ^^^\n" + + "Potential null pointer access: The variable foo may be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.println(bar.toString());\n" + + " ^^^\n" + + "Potential null pointer access: The variable bar may be null at this location\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=299900 +//Test to verify that null checks are properly reported for the variable(s) +//in the right expression of an OR condition statement. +public void testBug299900b() { + runNegativeNullTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(Object foo, Object bar) {\n" + + " if(foo == null || bar == null) {\n" + + " }\n" + + " System.out.println(foo.toString());\n" + + " System.out.println(bar.toString());\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.println(foo.toString());\n" + + " ^^^\n" + + "Potential null pointer access: The variable foo may be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " System.out.println(bar.toString());\n" + + " ^^^\n" + + "Potential null pointer access: The variable bar may be null at this location\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896 +// Test whether Null pointer access warnings are being reported correctly when auto-unboxing +public void testBug253896a() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Integer f1 = null;\n" + + " if(f1 == 1)\n" + + " System.out.println(\"f1 is 1\");\n" + + " Integer f2 = null;\n" + + " int abc = (f2 != 1)? 1 : 0;\n" + + " Float f3 = null;\n" + + " if(f3 == null)\n" + + " System.out.println(\"f3 is null\");\n" + + " Byte f4 = null;\n" + + " if(f4 != null)\n" + + " System.out.println(\"f4 is not null\");\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if(f1 == 1)\n" + + " ^^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " int abc = (f2 != 1)? 1 : 0;\n" + + " ^^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " if(f3 == null)\n" + + " ^^\n" + + "Redundant null check: The variable f3 can only be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " if(f4 != null)\n" + + " ^^\n" + + "Null comparison always yields false: The variable f4 can only be null at this location\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " System.out.println(\"f4 is not null\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896 +// To test whether null pointer access and potential null pointer access warnings are correctly reported when auto-unboxing +public void testBug253896b() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Integer i1, Integer i2) {\n" + + " if(i1 == null && i2 == null){\n" + + " if(i1 == 1)\n" + + " System.out.println(i1);}\n" + //i1 is definitely null here + " else {\n" + + " if(i1 == 0) {}\n" + //i1 may be null here. + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if(i1 == 1)\n" + + " ^^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " if(i1 == 0) {}\n" + + " ^^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n"); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896 +// Test whether Null pointer access warnings are being reported correctly when auto-unboxing inside loops +public void testBug253896c() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Integer a = null;\n" + + " Integer outer2 = null;\n" + + " while (true) {\n" + + " Integer f1 = null;\n" + + " if(f1 == 1)\n" + + " System.out.println(\"f1 is 1\");\n" + + " Integer f2 = null;\n" + + " int abc = (f2 != 1)? 1 : 0;\n" + + " Float f3 = null;\n" + + " if(f3 == null)\n" + + " System.out.println(\"f3 is null\");\n" + + " Byte f4 = null;\n" + + " if(f4 != null)\n" + + " System.out.println(\"f4 is not null\");\n" + + " if(a == 1) {}\n" + // warn null reference in deferred check case + " if(outer2 == 1) {}\n" + // warn potential null reference in deferred check case + " outer2 = 1;\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if(f1 == 1)\n" + + " ^^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " int abc = (f2 != 1)? 1 : 0;\n" + + " ^^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " if(f3 == null)\n" + + " ^^\n" + + "Redundant null check: The variable f3 can only be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 15)\n" + + " if(f4 != null)\n" + + " ^^\n" + + "Null comparison always yields false: The variable f4 can only be null at this location\n" + + "----------\n" + + "5. WARNING in X.java (at line 16)\n" + + " System.out.println(\"f4 is not null\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "6. ERROR in X.java (at line 17)\n" + + " if(a == 1) {}\n" + + " ^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "7. ERROR in X.java (at line 18)\n" + + " if(outer2 == 1) {}\n" + + " ^^^^^^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n"); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896 +// Test whether Null pointer access warnings are being reported correctly when auto-unboxing inside finally contexts +public void testBug253896d() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Integer param) {\n" + + " Integer outer = null;\n" + + " if (param == null) {}\n" + //tainting param + " try {}\n" + + " finally {\n" + + " Integer f1 = null;\n" + + " if(f1 == 1)\n" + + " System.out.println(\"f1 is 1\");\n" + + " Integer f2 = null;\n" + + " int abc = (f2 != 1)? 1 : 0;\n" + + " Float f3 = null;\n" + + " if(f3 == null)\n" + + " System.out.println(\"f3 is null\");\n" + + " Byte f4 = null;\n" + + " if(f4 != null)\n" + + " System.out.println(\"f4 is not null\");\n" + + " if(outer == 1) {}\n" + // warn null reference in deferred check case + " if(param == 1) {}\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " if(f1 == 1)\n" + + " ^^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " int abc = (f2 != 1)? 1 : 0;\n" + + " ^^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " if(f3 == null)\n" + + " ^^\n" + + "Redundant null check: The variable f3 can only be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 16)\n" + + " if(f4 != null)\n" + + " ^^\n" + + "Null comparison always yields false: The variable f4 can only be null at this location\n" + + "----------\n" + + "5. WARNING in X.java (at line 17)\n" + + " System.out.println(\"f4 is not null\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "6. ERROR in X.java (at line 18)\n" + + " if(outer == 1) {}\n" + + " ^^^^^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "7. ERROR in X.java (at line 19)\n" + + " if(param == 1) {}\n" + + " ^^^^^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n"); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448 +//To check that code gen is not optimized for an if statement +//where a local variable's definite nullness or otherwise is known because of +//an earlier assert expression (inside finally context) +public void testBug303448a() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Object foo = null;\n" + + " Object foo2 = null;\n" + + " try {} \n" + + " finally {\n" + + " assert (foo != null && foo2 != null);\n" + + " if (foo != null) {\n" + + " System.out.println(\"foo is not null\");\n" + + " } else {\n" + + " System.out.println(\"foo is null\");\n" + + " }\n" + + " if (foo2 != null) {\n" + + " System.out.println(\"foo2 is not null\");\n" + + " } else {\n" + + " System.out.println(\"foo2 is null\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, + true, + null, + options, + null); // custom requestor + + String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_5? + " // Method descriptor #11 ()V\n" + + " // Stack: 2, Locals: 3\n" + + " public void foo();\n" + + " 0 aconst_null\n" + + " 1 astore_1 [foo]\n" + + " 2 aconst_null\n" + + " 3 astore_2 [foo2]\n" + + " 4 getstatic X.$assertionsDisabled : boolean [38]\n" + + " 7 ifne 26\n" + + " 10 aload_1 [foo]\n" + + " 11 ifnull 18\n" + + " 14 aload_2 [foo2]\n" + + " 15 ifnonnull 26\n" + + " 18 new java.lang.AssertionError [49]\n" + + " 21 dup\n" + + " 22 invokespecial java.lang.AssertionError() [51]\n" + + " 25 athrow\n" + + " 26 aload_1 [foo]\n" + + " 27 ifnull 41\n" + + " 30 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + + " 33 ldc [58]\n" + + " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + + " 38 goto 49\n" + + " 41 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + + " 44 ldc [65]\n" + + " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + + " 49 aload_2 [foo2]\n" + + " 50 ifnull 64\n" + + " 53 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + + " 56 ldc [67]\n" + + " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + + " 61 goto 72\n" + + " 64 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + + " 67 ldc [69]\n" + + " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" + + " 72 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 4, line: 7]\n" + + " [pc: 26, line: 8]\n" + + " [pc: 30, line: 9]\n" + + " [pc: 38, line: 10]\n" + + " [pc: 41, line: 11]\n" + + " [pc: 49, line: 13]\n" + + " [pc: 53, line: 14]\n" + + " [pc: 61, line: 15]\n" + + " [pc: 64, line: 16]\n" + + " [pc: 72, line: 19]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 73] local: this index: 0 type: X\n" + + " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + + " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" + : this.complianceLevel < ClassFileConstants.JDK1_6? + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 3\n" + + " public void foo();\n" + + " 0 aconst_null\n" + + " 1 astore_1 [foo]\n" + + " 2 aconst_null\n" + + " 3 astore_2 [foo2]\n" + + " 4 getstatic X.$assertionsDisabled : boolean [16]\n" + + " 7 ifne 26\n" + + " 10 aload_1 [foo]\n" + + " 11 ifnull 18\n" + + " 14 aload_2 [foo2]\n" + + " 15 ifnonnull 26\n" + + " 18 new java.lang.AssertionError [26]\n" + + " 21 dup\n" + + " 22 invokespecial java.lang.AssertionError() [28]\n" + + " 25 athrow\n" + + " 26 aload_1 [foo]\n" + + " 27 ifnull 41\n" + + " 30 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + + " 33 ldc [35]\n" + + " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + + " 38 goto 49\n" + + " 41 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + + " 44 ldc [43]\n" + + " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + + " 49 aload_2 [foo2]\n" + + " 50 ifnull 64\n" + + " 53 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + + " 56 ldc [45]\n" + + " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + + " 61 goto 72\n" + + " 64 getstatic java.lang.System.out : java.io.PrintStream [29]\n" + + " 67 ldc [47]\n" + + " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" + + " 72 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 4, line: 7]\n" + + " [pc: 26, line: 8]\n" + + " [pc: 30, line: 9]\n" + + " [pc: 38, line: 10]\n" + + " [pc: 41, line: 11]\n" + + " [pc: 49, line: 13]\n" + + " [pc: 53, line: 14]\n" + + " [pc: 61, line: 15]\n" + + " [pc: 64, line: 16]\n" + + " [pc: 72, line: 19]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 73] local: this index: 0 type: X\n" + + " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + + " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" + : " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 3\n" + + " public void foo();\n" + + " 0 aconst_null\n" + + " 1 astore_1 [foo]\n" + + " 2 aconst_null\n" + + " 3 astore_2 [foo2]\n" + + " 4 getstatic X.$assertionsDisabled : boolean [16]\n" + + " 7 ifne 26\n" + + " 10 aload_1 [foo]\n" + + " 11 ifnull 18\n" + + " 14 aload_2 [foo2]\n" + + " 15 ifnonnull 26\n" + + " 18 new java.lang.AssertionError [27]\n" + + " 21 dup\n" + + " 22 invokespecial java.lang.AssertionError() [29]\n" + + " 25 athrow\n" + + " 26 aload_1 [foo]\n" + + " 27 ifnull 41\n" + + " 30 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + + " 33 ldc [36]\n" + + " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + + " 38 goto 49\n" + + " 41 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + + " 44 ldc [44]\n" + + " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + + " 49 aload_2 [foo2]\n" + + " 50 ifnull 64\n" + + " 53 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + + " 56 ldc [46]\n" + + " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + + " 61 goto 72\n" + + " 64 getstatic java.lang.System.out : java.io.PrintStream [30]\n" + + " 67 ldc [48]\n" + + " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" + + " 72 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 4, line: 7]\n" + + " [pc: 26, line: 8]\n" + + " [pc: 30, line: 9]\n" + + " [pc: 38, line: 10]\n" + + " [pc: 41, line: 11]\n" + + " [pc: 49, line: 13]\n" + + " [pc: 53, line: 14]\n" + + " [pc: 61, line: 15]\n" + + " [pc: 64, line: 16]\n" + + " [pc: 72, line: 19]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 73] local: this index: 0 type: X\n" + + " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" + + " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" + + " Stack map table: number of frames 6\n" + + " [pc: 18, append: {java.lang.Object, java.lang.Object}]\n" + + " [pc: 26, same]\n" + + " [pc: 41, same]\n" + + " [pc: 49, same]\n" + + " [pc: 64, same]\n" + + " [pc: 72, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448 +//To check that code gen is not optimized for an if statement +//where a local variable's definite nullness or otherwise is known because of +//an earlier assert expression (inside finally context) +public void testBug303448b() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + if (this.complianceLevel >= ClassFileConstants.JDK1_4) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"start\");\n" + + " Object foo = null;\n" + + " assert (foo != null);\n" + + " if (foo != null) {\n" + + " System.out.println(\"foo is not null\");\n" + + " }\n" + + " System.out.print(\"end\");\n" + + " }\n" + + "}\n", + }, + "startend", + null, + true, + null, + options, + null); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304416 +public void testBug304416() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = null;\n" + + " String s2 = null;\n" + + " if (s != null && s2 != null) {\n" + + " System.out.println(s);\n" + + " System.out.println(s2);\n" + + " }\n" + + " }\n" + + "}", + }, + "", + null, + true, + null, + options, + null); + String expectedOutput = + " public static void main(java.lang.String[] args);\n" + + " 0 aconst_null\n" + + " 1 astore_1 [s]\n" + + " 2 aconst_null\n" + + " 3 astore_2 [s2]\n" + + " 4 aload_1 [s]\n" + + " 5 ifnull 26\n" + + " 8 aload_2 [s2]\n" + + " 9 ifnull 26\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 15 aload_1 [s]\n" + + " 16 invokevirtual java.io.PrintStream.println(java.lang.String) : void [22]\n" + + " 19 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 22 aload_2 [s2]\n" + + " 23 invokevirtual java.io.PrintStream.println(java.lang.String) : void [22]\n" + + " 26 return\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=305590 +// To verify that a "instanceof always yields false" warning is not elicited in the +// case when the expression has been assigned a non null value in the instanceof check. +public void testBug305590() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Object str = null;\n" + + " if ((str = \"str\") instanceof String) {}\n" + // shouldn't warn + " str = null;\n" + + " if ((str = \"str\") instanceof Number) {}\n" + // shouldn't warn + " str = null;\n" + + " if (str instanceof String) {}\n" + // should warn + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " if (str instanceof String) {}\n" + + " ^^^\n" + + "instanceof always yields false: The variable str can only be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 +// unboxing raises an NPE +// LocalDeclaration +public void testBug319201() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Integer i = null;\n" + + " int j = i;\n" + // should warn + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int j = i;\n" + + " ^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 +// unboxing could raise an NPE +// Assignment +public void testBug319201a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Integer i) {\n" + + " if (i == null) {};\n" + + " int j;\n" + + " j = i;\n" + // should warn + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " j = i;\n" + + " ^\n" + + "Potential null pointer access: This expression of type Integer may be null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 +// unboxing raises an NPE +// MessageSend +public void testBug319201b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Boolean bo = null;;\n" + + " bar(bo);\n" + // should warn + " }\n" + + " void bar(boolean b) {}\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " bar(bo);\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 +// unboxing raises an NPE +// Node types covered (in this order): +// ExplicitConstructorCall +// AllocationExpression +// AND_AND_Expression +// OR_OR_Expression +// ArrayAllocationExpression +// ForStatement +// DoStatement +// IfStatement +// QualifiedAllocationExpression +// SwitchStatement +// WhileStatement +// CastExpression +// AssertStatement +// ReturnStatement +public void testBug319201c() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runNegativeTest( + new String[] { + "X.java", + "class Y { public Y(boolean b1, boolean b2) {} }\n" + + "public class X extends Y {\n" + + " public X(boolean b, Boolean b2) {\n" + + " super(b2 == null, b2);\n" + + " }\n" + + " class Z {\n" + + " public Z(boolean b) {}\n" + + " }\n" + + " boolean fB = (Boolean)null;\n" + + " public boolean foo(boolean inB) {\n" + + " Boolean b1 = null;\n" + + " X x = new X(b1, null);\n" + + " Boolean b2 = null;\n" + + " boolean dontcare = b2 && inB;\n" + + " Boolean b3 = null;\n" + + " dontcare = inB || b3;\n" + + " Integer dims = null;\n" + + " char[] cs = new char[dims];\n" + + " Boolean b5 = null;\n" + + " do {\n" + + " Boolean b4 = null;\n" + + " for (int i=0;b4; i++);\n" + + " } while (b5);\n" + + " Boolean b6 = null;\n" + + " if (b6) { }\n" + + " Boolean b7 = null;\n" + + " Z z = this.new Z(b7);\n" + + " Integer sel = null;\n" + + " switch(sel) {\n" + + " case 1: break;\n" + + " default: break;\n" + + " }\n" + + " Boolean b8 = null;\n" + + " while (b8) {}\n" + + " Boolean b9 = null;\n" + + " dontcare = (boolean)b9;\n" + + " Boolean b10 = null;\n" + + " assert b10 : \"shouldn't happen, but will\";\n" + + " Boolean b11 = null;\n" + + " return b11;\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " super(b2 == null, b2);\n" + + " ^^\n" + + "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " boolean fB = (Boolean)null;\n" + + " ^^^^^^^^^^^^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " X x = new X(b1, null);\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " boolean dontcare = b2 && inB;\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "5. ERROR in X.java (at line 16)\n" + + " dontcare = inB || b3;\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "6. ERROR in X.java (at line 18)\n" + + " char[] cs = new char[dims];\n" + + " ^^^^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "7. ERROR in X.java (at line 22)\n" + + " for (int i=0;b4; i++);\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "8. ERROR in X.java (at line 23)\n" + + " } while (b5);\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "9. ERROR in X.java (at line 25)\n" + + " if (b6) { }\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "10. ERROR in X.java (at line 27)\n" + + " Z z = this.new Z(b7);\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "11. ERROR in X.java (at line 29)\n" + + " switch(sel) {\n" + + " ^^^\n" + + "Null pointer access: This expression of type Integer is null but requires auto-unboxing\n" + + "----------\n" + + "12. ERROR in X.java (at line 34)\n" + + " while (b8) {}\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "13. ERROR in X.java (at line 36)\n" + + " dontcare = (boolean)b9;\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "14. ERROR in X.java (at line 38)\n" + + " assert b10 : \"shouldn\'t happen, but will\";\n" + + " ^^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "15. ERROR in X.java (at line 40)\n" + + " return b11;\n" + + " ^^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 +// unboxing raises an NPE +// DoStatement, variants with assignement and/or continue in the body & empty body +public void testBug319201d() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryElse, CompilerOptions.IGNORE); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(boolean cond, boolean cond2) {\n" + + " Boolean b = null;\n" + + " do {\n" + + " b = false;\n" + + " if (cond) continue;\n" + // shouldn't make a difference + " } while (b);\n" + // don't complain, loop body has already assigned b + " Boolean b2 = null;\n" + + " do {\n" + + " if (cond) continue;\n" + + " b2 = false;\n" + + " } while (b2);\n" + // complain here: potentially null + " Boolean b3 = null;\n" + + " do {\n" + + " } while (b3);\n" + // complain here: definitely null + " Boolean b4 = null;\n" + + " do {\n" + + " if (cond) {\n" + + " b4 = true;\n" + + " if (cond2) continue;\n" + + " }\n" + + " b4 = false;\n" + + " } while (b4);\n" + // don't complain here: definitely non-null + " Boolean b5 = null;\n" + + " do {\n" + + " b5 = true;\n" + + " } while (b5);\n" + // don't complain + " Boolean b6 = null;\n" + + " do {\n" + + " b6 = true;\n" + + " continue;\n" + + " } while (b6); \n" + // don't complain + " Boolean b7 = null;\n" + + " Boolean b8 = null;\n" + + " do {\n" + + " if (cond) {\n" + + " b7 = true;\n" + + " continue;\n" + + " } else {\n" + + " b8 = true;\n" + + " }\n" + + " } while (b7);\n" + // complain here: after else branch b7 can still be null + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " } while (b2);\n" + + " ^^\n" + + "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " } while (b3);\n" + + " ^^\n" + + "Null pointer access: This expression of type Boolean is null but requires auto-unboxing\n" + + "----------\n" + + "3. ERROR in X.java (at line 42)\n" + + " } while (b7);\n" + + " ^^\n" + + "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions, + "", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=320414 +public void testBug320414() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static class B {\n" + + " public static final int CONST = 16;\n" + + " int i;\n" + + " }\n" + + " B b;\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " void foo() {\n" + + " B localB = b; \n" + + " int i = localB.CONST;\n" + + " if (localB != null) {\n" + + " i = localB.i;\n" + + " }\n" + + " System.out.println(i);\n" + + " }\n" + + "}", + }, + "16", + null, + true, + null, + options, + null); + String expectedOutput = + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield X.b : X.B [24]\n" + + " 4 astore_1 [localB]\n" + + " 5 bipush 16\n" + + " 7 istore_2 [i]\n" + + " 8 aload_1 [localB]\n" + + " 9 ifnull 17\n" + + " 12 aload_1 [localB]\n" + + " 13 getfield X$B.i : int [26]\n" + + " 16 istore_2 [i]\n" + + " 17 getstatic java.lang.System.out : java.io.PrintStream [32]\n" + + " 20 iload_2 [i]\n" + + " 21 invokevirtual java.io.PrintStream.println(int) : void [38]\n" + + " 24 return\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=321926 +// To verify that a "redundant null check" warning is NOT elicited for a variable assigned non-null +// in an infinite while loop inside a try catch block and that code generation shows no surprises. +public void testBug321926a() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=321926 +// need more precise info from the throw location +public void testBug321926a2() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses @SW annotation + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_WARNING_TOKEN, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " @SuppressWarnings(\"null\")\n" + // expecting "redundant null check" at "if (someVariable == null)" + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else {\n" + + " someVariable = \"value\";\n" + + " throw new IOException();\n" + + " }\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good", + options); +} +// Test that dead code warning does show up. +public void testBug321926b() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " System.out.println(\"This is dead code\");\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " System.out.println(\"This is dead code\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} +// Check nullness in catch block, finally block and downstream code. +public void testBug321926c() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " } finally {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good Compiler good Compiler good"); +} +// Various nested loops. +public void testBug321926d() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " for(;;) { \n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " }\n" + + " }\n" + + " } catch (IOException e) {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " } finally {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good Compiler good Compiler good"); +} +// Test widening catch. +public void testBug321926e() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (Exception e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good"); +} +// Tested nested try blocks. +public void testBug321926f() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i != 0) {\n" + + " try {\n" + + " throw new IOException();\n" + + " } catch (IOException e) {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"The compiler is buggy\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " throw e;\n" + + " }\n" + + " } else {\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " }\n" + + " } catch (Exception e) {\n" + + " // having broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"The compiler is buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}\n"}, + "Compiler good Compiler good"); +} +// test for loop +public void testBug321926g() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " for (int j = 0; true; j++) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good"); +} +// test do while loop +public void testBug321926h() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " do {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " } while(true);\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good"); +} +// test with while (true) with a break inside. was working already. +public void testBug321926i() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " break;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good"); +} +// Test with non-explicit throws, i.e call method which throws rather than an inline throw statement. +public void testBug321926j() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " invokeSomeMethod();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + " public static void invokeSomeMethod() throws IOException {\n" + + " throw new IOException();\n" + + " }\n" + + "}"}, + "Compiler good"); +} +// Variation with nested loops +public void testBug321926k() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good Compiler good"); +} +// variation with nested loops. +public void testBug321926l() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + + this.runTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " someVariable = null;\n"+ + " try {\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + false, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " someVariable = null;\n" + + " ^^^^^^^^^^^^\n" + + "Redundant assignment: The variable someVariable can only be null at this location\n" + + "----------\n", + "Compiler good Compiler good", + "", + true, // force execution + null, // classlibs + true, // flush output, + null, // vm args + options, + null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} +public void testBug321926m() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " if (true) {\n" + + " break;\n" + + " }\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good"); +} +public void testBug321926n() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \"not null\";\n" + + " while (true) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good", + options); +} +public void testBug321926o() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \"not null\";\n" + + " for(;;) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good", + options); +} +public void testBug321926p() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \"not null\";\n" + + " do {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " } while (true);\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good", + options); +} +public void testBug321926q() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \"not null\";\n" + + " do {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " } while ((someVariable = \"not null\") != null);\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good", null, true, null, options, null); +} +public void testBug321926r() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while ((someVariable = \"not null\") != null) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good", null, true, null, options, null + ); +} +public void testBug321926s() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \" not null\";\n" + + " while ((someVariable = null) != null) {\n" + + " if (i == 0){\n" + + " someVariable = \"not null\";\n" + + " i++;\n" + + " }\n" + + " else\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " // broken from loop, continue on\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler good\");\n" + + " } else {\n" + + " System.out.println(\"Compiler buggy\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good", null, true, null, options, null + ); +} +public void testBug321926t() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String s[]) {\n" + + " String file = \"non null\";\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0) {\n" + + " file = null;\n" + + " i++;\n"+ + " }\n" + + " else \n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " }\n" + + " if (file == null)\n" + + " System.out.println(\"Compiler good\");\n" + + " else \n" + + " System.out.println(\"Compiler bad\");\n" + + " }\n" + + "}\n"}, + "Compiler good"); +} +public void testBug321926u() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String s[]) {\n" + + " String file = \"non null\";\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0) {\n" + + " file = null;\n" + + " i++;\n"+ + " }\n" + + " else {\n" + + " file = null;\n" + + " throw new IOException();\n" + + " }\n" + + " }\n" + + " } catch (IOException e) {\n" + + " }\n" + + " if (file == null)\n" + + " System.out.println(\"Compiler good\");\n" + + " else \n" + + " System.out.println(\"Compiler bad\");\n" + + " }\n" + + "}\n"}, + "Compiler good", + options); +} +public void testBug321926v() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String s[]) {\n" + + " String file = null;\n" + + " int i = 0;\n" + + " try {\n" + + " while (true) {\n" + + " if (i == 0) {\n" + + " file = \"non null\";\n" + + " i++;\n"+ + " }\n" + + " else {\n" + + " file = \"non null\";\n" + + " throw new IOException();\n" + + " }\n" + + " }\n" + + " } catch (IOException e) {\n" + + " }\n" + + " if (file == null)\n" + + " System.out.println(\"Compiler bad\");\n" + + " else \n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + "}\n"}, + "Compiler good", + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317829 +public void testBug317829a() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \"not null\";\n" + + " while (true) {\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good Compiler good", + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317829 +// assignment from unknown - not reporting redundant check +public void testBug317829a2() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = getString();\n" + + " while (true) {\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + " static String getString() { return \"\"; }\n" + + "}"}, + "Compiler good Compiler good"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=317829 +public void testBug317829b() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \"not null\";\n" + + " while (true) {\n" + + " someMethod();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + " public static void someMethod() throws IOException {\n" + + " throw new IOException();\n" + + " }\n" + + "}"}, + "Compiler good Compiler good", + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317829 +public void testBug317829c() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \"not null\";\n" + + " for (;;) {\n" + + " throw new IOException();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good Compiler good", + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=317829 +public void testBug317829d() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \"not null\";\n" + + " for(;;) {\n" + + " someMethod();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + " public static void someMethod() throws IOException {\n" + + " throw new IOException();\n" + + " }\n" + + "}"}, + "Compiler good Compiler good", + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317829 +public void testBug317829e() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \"not null\";\n" + + " do {\n" + + " throw new IOException();\n" + + " } while (true);\n" + + " } catch (IOException e) {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + "}"}, + "Compiler good Compiler good", + options); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317829 +public void testBug317829f() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.WARNING); + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String someVariable = null;\n" + + " int i = 0;\n" + + " try {\n" + + " someVariable = \"not null\";\n" + + " do {\n" + + " someMethod();\n" + + " } while (true);\n" + + " } catch (IOException e) {\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.print(\"Compiler good \");\n" + + " }\n" + + " }\n" + + " if (someVariable == null) {\n" + + " System.out.println(\"Compiler bad\");\n" + + " } else {\n" + + " System.out.println(\"Compiler good\");\n" + + " }\n" + + " }\n" + + " public static void someMethod() throws IOException {\n" + + " throw new IOException();\n" + + " }\n" + + "}"}, + "Compiler good Compiler good", + options); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment +// LocalDeclaration +public void testBug292478() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " if (o != null) {/* */}\n" + + " Object p = o;\n" + + " p.toString();\n" + // complain here + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " p.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable p may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment +// Assignment +public void testBug292478a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " Object p;" + + " if (o != null) {/* */}\n" + + " p = o;\n" + + " p.toString();\n" + // complain here + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " p.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable p may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment +// Assignment after definite null +public void testBug292478b() { +this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " Object p = null;\n" + + " if (o != null) {/* */}\n" + + " p = o;\n" + + " p.toString();\n" + // complain here + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " p.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable p may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment +// Assignment after definite null - many locals +public void testBug292478c() { +this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " int i00, i01, i02, i03, i04, i05, i06, i07, i08, i09;\n" + + " int i10, i11, i12, i13, i14, i15, i16, i17, i18, i19;\n" + + " int i20, i21, i22, i23, i24, i25, i26, i27, i28, i29;\n" + + " int i30, i31, i32, i33, i34, i35, i36, i37, i38, i39;\n" + + " int i40, i41, i42, i43, i44, i45, i46, i47, i48, i49;\n" + + " int i50, i51, i52, i53, i54, i55, i56, i57, i58, i59;\n" + + " int i60, i61, i62, i63, i64, i65, i66, i67, i68, i69;\n" + + " Object p = null;\n" + + " if (o != null) {/* */}\n" + + " p = o;\n" + + " p.toString();\n" + // complain here + " }\n" + + "}"}, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " p.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable p may be null at this location\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment +// Assignment affects initsOnFinally +public void testBug292478d() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " X bar() {\n" + + " return null;\n" + + " }\n" + + " Object foo() {\n" + + " X x = null;\n" + + " X y = new X();\n" + + " X u = null;\n" + + " try {\n" + + " u = bar();\n" + + " x = bar();\n" + + " if (x==null) { }\n" + + " y = x;\n" + // this makes y potentially null + " if (x==null) { y=bar();} else { y=new X(); }\n" + + " return x;\n" + + " } finally {\n" + + " y.toString();\n" + // must complain against potentially null, although normal exist of tryBlock says differently (unknown or non-null) + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " y.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable y may be null at this location\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment +// test regression reported in comment 8 +public void testBug292478e() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " Object foo(int i, boolean b1, boolean b2) {\n" + + " Object o1 = null;\n" + + " done : while (true) { \n" + + " switch (i) {\n" + + " case 1 :\n" + + " Object o2 = null;\n" + + " if (b2)\n" + + " o2 = new Object();\n" + + " o1 = o2;\n" + + " break;\n" + + " case 2 :\n" + + " break done;\n" + + " }\n" + + " } \n" + + " if (o1 != null)\n" + + " return o1;\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment +// variant where regression occurred inside the while-switch structure +public void testBug292478f() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " Object foo(int i, boolean b1, boolean b2) {\n" + + " Object o1 = null;\n" + + " done : while (true) { \n" + + " switch (i) {\n" + + " case 1 :\n" + + " Object o2 = null;\n" + + " if (b2)\n" + + " o2 = new Object();\n" + + " o1 = o2;\n" + + " if (o1 != null)\n" + + " return o1;\n" + + " break;\n" + + " case 2 :\n" + + " break done;\n" + + " }\n" + + " } \n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=292478 - Report potentially null across variable assignment +// variant for transfering state potentially unknown +public void testBug292478g() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " Object foo(int i, boolean b1, boolean b2, Object o2) {\n" + + " Object o1 = null;\n" + + " done : while (true) { \n" + + " switch (i) {\n" + + " case 1 :\n" + + " if (b2)\n" + + " o2 = bar();\n" + + " o1 = o2;\n" + + " if (o1 != null)\n" + + " return o1;\n" + + " break;\n" + + " case 2 :\n" + + " break done;\n" + + " }\n" + + " } \n" + + " return null;\n" + + " }\n" + + " Object bar() { return null; }\n" + + "}\n" + }); +} + +// Bug 324762 - Compiler thinks there is deadcode and removes it! +// regression caused by the fix for bug 133125 +// ternary is non-null or null +public void testBug324762() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void zork(boolean b1) {\n" + + " Object satisfied = null;\n" + + " if (b1) {\n" + + " String[] s = new String[] { \"a\", \"b\" };\n" + + " for (int k = 0; k < s.length && satisfied == null; k++)\n" + + " satisfied = s.length > 1 ? new Object() : null;\n" + + " }\n" + + " }\n" + + "}\n" + }); +} + +// Bug 324762 - Compiler thinks there is deadcode and removes it! +// regression caused by the fix for bug 133125 +// ternary is unknown or null +public void testBug324762a() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void zork(boolean b1) {\n" + + " Object satisfied = null;\n" + + " if (b1) {\n" + + " String[] s = new String[] { \"a\", \"b\" };\n" + + " for (int k = 0; k < s.length && satisfied == null; k++)\n" + + " satisfied = s.length > 1 ? bar() : null;\n" + + " }\n" + + " }\n" + + " Object bar() { return null; }\n" + + "}\n" + }); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325229 +// instancof expression +public void testBug325229a() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void foo(Object a) {\n" + + " assert a instanceof Object;\n " + + " if (a!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " System.out.println(\"a is null\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args){\n" + + " Test test = new Test();\n" + + " test.foo(null);\n" + + " }\n" + + "}\n"}, + "a is null", + null, + true, + new String[] {"-da"}, + compilerOptions, + null); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325229 +// MessageSend in assert +public void testBug325229b() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " boolean bar() {\n" + + " return false;\n" + + " }" + + " void foo(Test a) {\n" + + " assert a.bar();\n " + + " if (a!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " System.out.println(\"a is null\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args){\n" + + " Test test = new Test();\n" + + " test.foo(null);\n" + + " }\n" + + "}\n"}, + "a is null", + null, + true, + new String[] {"-da"}, + compilerOptions, + null); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325229 +// QualifiedNameReference in assert +public void testBug325229c() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " boolean bar() {\n" + + " return false;\n" + + " }" + + " Test tfield;\n" + + " void foo(Test a) {\n" + + " assert a.tfield.bar();\n " + + " if (a!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " System.out.println(\"a is null\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args){\n" + + " Test test = new Test();\n" + + " test.foo(null);\n" + + " }\n" + + "}\n"}, + "a is null", + null, + true, + new String[] {"-da"}, + compilerOptions, + null); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325229 +// EqualExpression in assert, comparison against non null +public void testBug325229d() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void foo(Object a) {\n" + + " Object b = null;" + + " assert a == b;\n " + + " if (a!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " System.out.println(\"a is null\");\n" + + " }\n" + + " assert a != b;\n " + + " if (a!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " System.out.println(\"a is null\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args){\n" + + " Test test = new Test();\n" + + " test.foo(null);\n" + + " }\n" + + "}\n"}, + "a is null\n" + + "a is null", + null, + true, + new String[] {"-da"}, + compilerOptions, + null); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342 +// Null warnings because of assert statements should be suppressed +// when CompilerOptions.OPTION_IncludeNullInfoFromAsserts is disabled. +public void testBug325342a() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_IncludeNullInfoFromAsserts, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void foo(Object a, Object b, Object c) {\n" + + " assert a == null;\n " + + " if (a!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " System.out.println(\"a is null\");\n" + + " }\n" + + " a = null;\n" + + " if (a== null) {}\n" + + " assert b != null;\n " + + " if (b!=null) {\n" + + " System.out.println(\"b is not null\");\n" + + " } else{\n" + + " System.out.println(\"b is null\");\n" + + " }\n" + + " assert c == null;\n" + + " if (c.equals(a)) {\n" + + " System.out.println(\"\");\n" + + " } else{\n" + + " System.out.println(\"\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args){\n" + + " Test test = new Test();\n" + + " test.foo(null,null, null);\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in Test.java (at line 10)\n" + + " if (a== null) {}\n" + + " ^\n" + + "Redundant null check: The variable a can only be null at this location\n" + + "----------\n", + null, + true, + compilerOptions, + "", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325342 +// Null warnings because of assert statements should not be suppressed +// when CompilerOptions.OPTION_IncludeNullInfoFromAsserts is enabled. +public void testBug325342b() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_IncludeNullInfoFromAsserts, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void foo(Object a, Object b, Object c) {\n" + + " assert a == null;\n " + + " if (a!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " System.out.println(\"a is null\");\n" + + " }\n" + + " assert b != null;\n " + + " if (b!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " System.out.println(\"a is null\");\n" + + " }\n" + + " assert c == null;\n" + + " if (c.equals(a)) {\n" + + " System.out.println(\"\");\n" + + " } else{\n" + + " System.out.println(\"\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args){\n" + + " Test test = new Test();\n" + + " test.foo(null,null,null);\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in Test.java (at line 4)\n" + + " if (a!=null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable a can only be null at this location\n" + + "----------\n" + + "2. WARNING in Test.java (at line 4)\n" + + " if (a!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in Test.java (at line 10)\n" + + " if (b!=null) {\n" + + " ^\n" + + "Redundant null check: The variable b cannot be null at this location\n" + + "----------\n" + + "4. WARNING in Test.java (at line 12)\n" + + " } else{\n" + + " System.out.println(\"a is null\");\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "5. ERROR in Test.java (at line 16)\n" + + " if (c.equals(a)) {\n" + + " ^\n" + + "Null pointer access: The variable c can only be null at this location\n" + + "----------\n", + null, true, compilerOptions, "", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325755 +// null analysis -- conditional expression +public void testBug325755a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Object foo(String s1, String s2) {\n" + + " String local1 = s1;\n" + + " String local2 = s2;\n" + + " \n" + + " String local3 = null;\n" + + " if (local1 != null && local2 != null)\n" + + " local3 = \"\"; //$NON-NLS-1$\n" + + " else\n" + + " local3 = local1 != null ? local1 : local2;\n" + + "\n" + + " if (local3 != null)\n" + + " return new Integer(local3.length());\n" + + " return null;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.print(foo(null, null));\n" + + " System.out.print(foo(\"p1\", null));\n" + + " System.out.print(foo(null, \"p2\"));\n" + + " System.out.print(foo(\"p1\", \"p2\"));\n" + + " }\n" + + "}"}, + "null220"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=325755 +// null analysis -- conditional expression, many locals +public void testBug325755b() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Object foo(String s1, String s2) {\n" + + " int i00, i01, i02, i03, i04, i05, i06, i07, i08, i09;\n" + + " int i10, i11, i12, i13, i14, i15, i16, i17, i18, i19;\n" + + " int i20, i21, i22, i23, i24, i25, i26, i27, i28, i29;\n" + + " int i30, i31, i32, i33, i34, i35, i36, i37, i38, i39;\n" + + " int i40, i41, i42, i43, i44, i45, i46, i47, i48, i49;\n" + + " int i50, i51, i52, i53, i54, i55, i56, i57, i58, i59;\n" + + " int i60, i61, i62, i63, i64, i65, i66, i67, i68, i69;\n" + + + " String local1 = s1;\n" + + " String local2 = s2;\n" + + " \n" + + " String local3 = null;\n" + + " if (local1 != null && local2 != null)\n" + + " local3 = \"\"; //$NON-NLS-1$\n" + + " else\n" + + " local3 = local1 != null ? local1 : local2;\n" + + "\n" + + " if (local3 != null)\n" + + " return new Integer(local3.length());\n" + + " return null;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.print(foo(null, null));\n" + + " System.out.print(foo(\"p1\", null));\n" + + " System.out.print(foo(null, \"p2\"));\n" + + " System.out.print(foo(\"p1\", \"p2\"));\n" + + " }\n" + + "}"}, + "null220"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332637 +// Dead Code detection removing code that isn't dead +public void testBug332637() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runConformTest( + new String[] { + "DeadCodeExample.java", + "public class DeadCodeExample {\n" + + "\n" + + " private class CanceledException extends Exception {\n" + + " }\n" + + "\n" + + " private interface ProgressMonitor {\n" + + " boolean isCanceled();\n" + + " }\n" + + "\n" + + " private void checkForCancellation(ProgressMonitor monitor)\n" + + " throws CanceledException {\n" + + " if (monitor.isCanceled()) {\n" + + " throw new CanceledException();\n" + + " }\n" + + " }\n" + + "\n" + + " private int run() {\n" + + "\n" + + " ProgressMonitor monitor = new ProgressMonitor() {\n" + + " private int i = 0;\n" + + "\n" + + " public boolean isCanceled() {\n" + + " return (++i == 5);\n" + + " }\n" + + " };\n" + + "\n" + + " Integer number = null;\n" + + "\n" + + " try {\n" + + " checkForCancellation(monitor);\n" + + "\n" + + " number = Integer.valueOf(0);\n" + + "\n" + + " for (String s : new String[10]) {\n" + + " checkForCancellation(monitor);\n" + + " number++;\n" + + " }\n" + + " return 0;\n" + + " } catch (CanceledException e) {\n" + + " System.out.println(\"Canceled after \" + number\n" + + " + \" times through the loop\");\n" + + " if (number != null) {\n" + + " System.out.println(\"number = \" + number);\n" + + " }\n" + + " return -1;\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new DeadCodeExample().run());\n" + + " }\n" + + "}\n" + }, + "Canceled after 3 times through the loop\n" + + "number = 3\n" + + "-1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332637 +// Dead Code detection removing code that isn't dead +// variant with a finally block +public void testBug332637b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runConformTest( + new String[] { + "DeadCodeExample.java", + "public class DeadCodeExample {\n" + + "\n" + + " private class CanceledException extends Exception {\n" + + " }\n" + + "\n" + + " private interface ProgressMonitor {\n" + + " boolean isCanceled();\n" + + " }\n" + + "\n" + + " private void checkForCancellation(ProgressMonitor monitor)\n" + + " throws CanceledException {\n" + + " if (monitor.isCanceled()) {\n" + + " throw new CanceledException();\n" + + " }\n" + + " }\n" + + "\n" + + " private int run() {\n" + + "\n" + + " ProgressMonitor monitor = new ProgressMonitor() {\n" + + " private int i = 0;\n" + + "\n" + + " public boolean isCanceled() {\n" + + " return (++i == 5);\n" + + " }\n" + + " };\n" + + "\n" + + " Integer number = null;\n" + + "\n" + + " try {\n" + + " checkForCancellation(monitor);\n" + + "\n" + + " number = Integer.valueOf(0);\n" + + "\n" + + " for (String s : new String[10]) {\n" + + " checkForCancellation(monitor);\n" + + " number++;\n" + + " }\n" + + " return 0;\n" + + " } catch (CanceledException e) {\n" + + " System.out.println(\"Canceled after \" + number\n" + + " + \" times through the loop\");\n" + + " if (number != null) {\n" + + " System.out.println(\"number = \" + number);\n" + + " }\n" + + " return -1;\n" + + " } finally {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new DeadCodeExample().run());\n" + + " }\n" + + "}\n" + }, + "Canceled after 3 times through the loop\n" + + "number = 3\n" + + "Done\n" + + "-1"); +} + +public void testBug406160a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runConformTest( + new String[] { + "DeadCodeExample.java", + "public class DeadCodeExample {\n" + + "\n" + + " class CanceledException extends Exception {\n" + + " }\n" + + "\n" + + " private interface ProgressMonitor {\n" + + " boolean isCanceled();\n" + + " }\n" + + "\n" + + " private void checkForCancellation(ProgressMonitor monitor)\n" + + " throws CanceledException {\n" + + " if (monitor.isCanceled()) {\n" + + " throw new CanceledException();\n" + + " }\n" + + " }\n" + + "\n" + + " private int run() {\n" + + "\n" + + " ProgressMonitor monitor = new ProgressMonitor() {\n" + + " private int i = 0;\n" + + "\n" + + " public boolean isCanceled() {\n" + + " return (++i == 5);\n" + + " }\n" + + " };\n" + + "\n" + + " Integer number = null;\n" + + "\n" + + " for (int j = 0; j < 1; ) {\n" + + "\n" + + " try {\n" + + " checkForCancellation(monitor);\n" + + "\n" + + " number = Integer.valueOf(0);\n" + + "\n" + + " for (String s : new String[10]) {\n" + + " checkForCancellation(monitor);\n" + + " number++;\n" + + " }\n" + + " return 0;\n" + + " } catch (CanceledException e) {\n" + + " System.out.println(\"Canceled after \" + number\n" + + " + \" times through the loop\");\n" + + " if (number != null) {\n" + + " System.out.println(\"number = \" + number);\n" + + " }\n" + + " return -1;\n" + + " }\n" + + " }\n" + + " return 13;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new DeadCodeExample().run());\n" + + " }\n" + + "}\n" + }, + "Canceled after 3 times through the loop\n" + + "number = 3\n" + + "-1"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=333089 +// null analysis -- to make sure no AIOOBE or NPE is thrown while calling UnconditionalFlowInfo.markNullStatus(..) +public void testBug333089() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object s1) {\n" + + " int i00, i01, i02, i03, i04, i05, i06, i07, i08, i09;\n" + + " int i10, i11, i12, i13, i14, i15, i16, i17, i18, i19;\n" + + " int i20, i21, i22, i23, i24, i25, i26, i27, i28, i29;\n" + + " int i30, i31, i32, i33, i34, i35, i36, i37, i38, i39;\n" + + " int i40, i41, i42, i43, i44, i45, i46, i47, i48, i49;\n" + + " int i50, i51, i52, i53, i54, i55, i56, i57, i58, i59;\n" + + " int i60, i61, i62, i63, i64, i65, i66, i67, i68, i69;\n" + + " Object local1;\n" + + " if (s1 == null){}\n" + + " try {" + + " local1 = s1;\n" + + " } finally {\n" + + " }\n" + + " }\n" + + "}"}, + ""); +} + +//Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop +//original issue +public void testBug336428() { + this.runConformTest( + new String[] { + "DoWhileBug.java", + "public class DoWhileBug {\n" + + " void test(boolean b1, Object o1) {\n" + + " Object o2 = new Object();\n" + + " do {\n" + + " if (b1)\n" + + " o1 = null;\n" + + " } while ((o2 = o1) != null);\n" + + " }\n" + + "}" + }, + ""); +} +//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[] { + "DoWhileBug.java", + "public class DoWhileBug {\n" + + " void test(boolean b1, Object o1) {\n" + + " Object o2 = null;\n" + + " do {\n" + + " if (b1)\n" + + " o1 = null;\n" + + " if ((o2 = o1) != null)\n" + + " break;\n" + + " } while (true);\n" + + " }\n" + + "}" + }, + ""); +} + +//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() { + runNegativeNullTest( + new String[] { + "DoWhileBug.java", + "public class DoWhileBug {\n" + + " void test(boolean b1) {\n" + + " Object o1 = null;\n" + + " Object o2 = null;\n" + + " do {\n" + + " if ((o2 = o1) == null) break;\n" + + " } while (true);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in DoWhileBug.java (at line 6)\n" + + " if ((o2 = o1) == null) break;\n" + + " ^^^^^^^^^\n" + + "Redundant null check: The variable o2 can only be null at this location\n" + + "----------\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 +public void testBug336428c() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "DoWhileBug.java", + "public class DoWhileBug {\n" + + " void test(boolean b1, Object o1) {\n" + + " Object o2 = null;\n" + + " do {\n" + + " if ((o2 = o1) == null) break;\n" + + " } while (true);\n" + + " }\n" + + "}" + }, + ""); + } +} + +//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() { + runNegativeNullTest( + new String[] { + "DoWhileBug.java", + "public class DoWhileBug {\n" + + " void test(boolean b1) {\n" + + " Object o1 = null;\n" + + " Object o2 = null;\n" + + " do {\n" + + " if (b1)\n" + + " o1 = null;\n" + + " if ((o2 = o1) == null) break;\n" + + " } while (true);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in DoWhileBug.java (at line 7)\n" + + " o1 = null;\n" + + " ^^\n" + + "Redundant assignment: The variable o1 can only be null at this location\n" + +/* In general it's safer *not* to assume that o1 is null on every iteration (see also testBug336428d2): + "----------\n" + + "2. ERROR in DoWhileBug.java (at line 8)\n" + + " if ((o2 = o1) == null) break;\n" + + " ^^^^^^^^^\n" + + "Redundant null check: The variable o2 can only be null at this location\n" + + */ + "----------\n" + ); +} + +// Bug 336428 - [compiler][null] bogus warning "redundant null check" in condition of do {} while() loop +// variant after Bug 454031 to demonstrate: +// - previously we would believe that o1 is always null in the assignment to o2 -> bogus warning re redundant null check +// - with improved analysis we don't claim to know the value of o1 in this assignment -> no warning +public void testBug336428d2() { + this.runConformTest( + new String[] { + "DoWhileBug.java", + "public class DoWhileBug {\n" + + " void test(boolean b1) {\n" + + " Object o1 = null;\n" + + " Object o2 = null;\n" + + " do {\n" + + " if (b1)\n" + + " o1 = null;\n" + + " if ((o2 = o1) == null) System.out.println(\"null\");\n" + + " o1 = new Object();\n" + + " } while (true);\n" + + " }\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 +public void testBug336428e() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeNullTest( + new String[] { + "DoWhileBug.java", + "public class DoWhileBug {\n" + + " void test(boolean b1) {\n" + + " Object o1 = null;\n" + + " Object o2 = null;\n" + + " do {\n" + + " if (b1)\n" + + " o1 = null;\n" + + " assert (o2 = o1) != null : \"bug\";\n" + + " } while (true);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in DoWhileBug.java (at line 7)\n" + + " o1 = null;\n" + + " ^^\n" + + "Redundant assignment: The variable o1 can only be null at this location\n" + +/* In general it's safer *not* to assume that o1 is null on every iteration: + "----------\n" + + "2. ERROR in DoWhileBug.java (at line 8)\n" + + " assert (o2 = o1) != null : \"bug\";\n" + + " ^^^^^^^^^\n" + + "Null comparison always yields false: The variable o2 can only be null at this location\n" + + */ + "----------\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 +// condition inside assert is redundant null check and hence should not be warned against +public void testBug336428f() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeNullTest( + new String[] { + "DoWhileBug.java", + "public class DoWhileBug {\n" + + " void test(boolean b1) {\n" + + " Object o1 = null;\n" + + " Object o2 = null;\n" + + " do {\n" + + " if (b1)\n" + + " o1 = null;\n" + + " assert (o2 = o1) == null : \"bug\";\n" + + " } while (true);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in DoWhileBug.java (at line 7)\n" + + " o1 = null;\n" + + " ^^\n" + + "Redundant assignment: The variable o1 can only be null at this location\n" + + "----------\n"); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332838 +// Null info of assert statements should not affect flow info +// when CompilerOptions.OPTION_IncludeNullInfoFromAsserts is disabled. +public void testBug332838() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_IncludeNullInfoFromAsserts, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "Info.java", + "public class Info {\n" + + " public void test(Info[] infos) {\n" + + " for (final Info info : infos) {\n " + + " if (info != null) {\n" + + " assert info.checkSomething();\n" + + " info.doSomething();\n" + // no warning + " }\n" + + " }\n" + + " for (final Info info : infos) {\n " + + " if (info == null) {\n" + + " assert info.checkSomething();\n" + + " info.doSomething();\n" + // warn NPE, not pot. NPE + " }\n" + + " }\n" + + " }\n" + + " void doSomething() {}\n" + + " boolean checkSomething() {return true;}\n" + + "}\n"}, + "----------\n" + + "1. ERROR in Info.java (at line 11)\n" + + " assert info.checkSomething();\n" + + " ^^^^\n" + + "Null pointer access: The variable info can only be null at this location\n" + + "----------\n" + + "2. ERROR in Info.java (at line 12)\n" + + " info.doSomething();\n" + + " ^^^^\n" + + "Null pointer access: The variable info can only be null at this location\n" + + "----------\n", + null, + true, + compilerOptions, + "", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=336544 +public void testBug336544() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer i1 = getInt();\n" + + " Integer i2 = i1 == null ? null : i1;\n" + + " if (i2 != null) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILURE\");\n" + + " }\n" + + " private static Integer getInt() {\n" + + " return new Integer(0);\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=336544 +public void testBug336544_2() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer i1 = null;\n" + + " Integer i2 = (i1 = getInt()) == null ? null : i1;\n" + + " if (i2 != null) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILURE\");\n" + + " }\n" + + " private static Integer getInt() {\n" + + " return new Integer(0);\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=336544 +public void testBug336544_3() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Integer i1 = null;\n" + + " Integer i2;\n" + + " i2 = (i1 = getInt()) == null ? null : i1;\n" + + " if (i2 != null) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILURE\");\n" + + " }\n" + + " private static Integer getInt() {\n" + + " return new Integer(0);\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=313870 +public void testBug313870() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = \"\";\n" + + " for (int i = 0; i < 2; i++) {\n" + + " if (i != 0) { \n" + + " s = test();\n" + + " }\n" + + " if (s == null) {\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " }\n" + + " }\n" + + " public static String test() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + "null"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=313870 +public void testBug313870b() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.BufferedReader;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " public void main(BufferedReader bufReader) throws IOException {\n" + + " String line = \"\";\n" + + " boolean doRead = false;\n" + + " while (true) {\n" + + " if (doRead) { \n" + + " line = bufReader.readLine();\n" + + " }\n" + + " if (line == null) {\n" + + " return;\n" + + " }\n" + + " doRead = true;\n" + + " }\n" + + " }\n" + + "}" + }, + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=313870 +public void testBug313870c() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean sometimes = (System.currentTimeMillis() & 1L) != 0L;\n" + + " File file = new File(\"myfile\");\n" + + " for (int i = 0; i < 2; i++) {\n" + + " if (sometimes) { \n" + + " file = getNewFile();\n" + + " }\n" + + " if (file == null) { \n" + + " System.out.println(\"\");\n" + + " }\n" + + " }\n" + + " }\n" + + " private static File getNewFile() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + ""); +} +// https://bugs.eclipse.org/338303 - Warning about Redundant assignment conflicts with definite assignment +public void testBug338303() { + this.runConformTest( + new String[] { + "Bug338303.java", + "import java.io.File;\n" + + "import java.io.IOException;\n" + + "\n" + + "public class Bug338303 {\n" + + " Object test(Object in, final File f) {\n" + + " Object local;\n" + + " try {\n" + + " local = in;\n" + + " if (local == null)\n" + + " local = loadEntry(f, false);\n" + + " } catch (final IOException e) {\n" + + " e.printStackTrace();\n" + + " local = null;\n" + + " }\n" + + " return local;\n" + + " }\n" + + "\n" + + " private Object loadEntry(File f, boolean b) throws IOException {\n" + + " throw new IOException();\n" + + " }\n" + + "}\n" + }, + ""); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234 +public void testBug338234() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " static int foo() {\n" + + " Object o = null;\n" + + " int i = 0;\n" + + " label: {\n" + + " if (o == null)\n" + + " break label;\n" + + " i++;" + + " }\n" + + " if (i != 0) {\n" + + " System.out.println(i);\n" + + " }\n" + + " return 0;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (o == null)\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " i++; }\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n"); +} +// Bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself +public void testBug324178() { + this.runConformTest( + new String[] { + "Bug324178.java", + "public class Bug324178 {\n" + + " boolean b;\n" + + " void foo(Object u) {\n" + + " if (u == null) {}\n" + + " Object o = (u == null) ? new Object() : u;\n" + + " o.toString(); // Incorrect potential NPE\n" + + " }\n" + + "}\n" + }, + ""); +} + +// Bug 324178 - [null] ConditionalExpression.nullStatus(..) doesn't take into account the analysis of condition itself +public void testBug324178a() { + this.runConformTest( + new String[] { + "Bug324178.java", + "public class Bug324178 {\n" + + " boolean b;\n" + + " void foo(Boolean u) {\n" + + " if (u == null) {}\n" + + " Boolean o;\n" + + " o = (u == null) ? Boolean.TRUE : u;\n" + + " o.toString(); // Incorrect potential NPE\n" + + " }\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=326950 +public void testBug326950a() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = null;\n" + + " if (s == null) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } else {\n" + + " System.out.println(\"Dead code, but don't optimize me out\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS", + null, + true, + null, + options, + null); + String expectedOutput = + " public static void main(java.lang.String[] args);\n" + + " 0 aconst_null\n" + + " 1 astore_1 [s]\n" + + " 2 aload_1 [s]\n" + + " 3 ifnonnull 17\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 ldc [22]\n" + + " 11 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 14 goto 25\n" + + " 17 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 20 ldc [30]\n" + + " 22 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 25 return\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=326950 +// Code marked dead due to if(false), etc. can be optimized out +public void testBug326950b() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int i = 0;\n" + + " if (false) {\n" + + " System.out.println(\"Deadcode and you can optimize me out\");\n" + + " }\n" + + " if (true) {\n" + + " i++;\n" + + " } else {\n" + + " System.out.println(\"Deadcode and you can optimize me out\");\n" + + " }\n" + + " }\n" + + "}", + }, + "", + null, + true, + null, + options, + null); + String expectedOutput = + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 iinc 1 1 [i]\n" + + " 5 return\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=326950 +// Free return should be generated for a method even if it ends with dead code +public void testBug326950c() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String[] args) {\n" + + " String s = \"\";\n" + + " int i = 0;\n" + + " if (s != null) {\n" + + " return;\n" + + " }\n" + + " i++;\n" + + " }\n" + + "}", + }, + "", + null, + true, + null, + options, + null); + String expectedOutput = + " public void foo(java.lang.String[] args);\n" + + " 0 ldc [16]\n" + + " 2 astore_2 [s]\n" + + " 3 iconst_0\n" + + " 4 istore_3 [i]\n" + + " 5 aload_2 [s]\n" + + " 6 ifnull 10\n" + + " 9 return\n" + + " 10 iinc 3 1 [i]\n" + + " 13 return\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=326950 +// Free return should be generated for a constructor even if it ends with dead code +public void testBug326950d() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X() {\n" + + " String s = \"\";\n" + + " int i = 0;\n" + + " if (s != null) {\n" + + " return;\n" + + " }\n" + + " i++;\n" + + " }\n" + + "}", + }, + "", + null, + true, + null, + options, + null); + String expectedOutput = + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 ldc [10]\n" + + " 6 astore_1 [s]\n" + + " 7 iconst_0\n" + + " 8 istore_2 [i]\n" + + " 9 aload_1 [s]\n" + + " 10 ifnull 14\n" + + " 13 return\n" + + " 14 iinc 2 1 [i]\n" + + " 17 return\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339250 +// Check code gen +public void testBug339250() throws Exception { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = null;\n" + + " s += \"correctly\";\n" + + " if (s != null) {\n" + // s cannot be null + " System.out.println(\"It works \" + s);\n" + + " }\n" + + " }\n" + + "}", + }, + "It works nullcorrectly", + null, + true, + null, + options, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339250 +// Check that the redundant null check warning is correctly produced +public void testBug339250a() throws Exception { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = null;\n" + + " s += \"correctly\";\n" + + " if (s != null) {\n" + // s cannot be null + " System.out.println(\"It works \" + s);\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (s != null) {\n" + + " ^\n" + + "Redundant null check: The variable s cannot be null at this location\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339250 +// Check that the redundant null check warning is correctly produced +public void testBug339250b() throws Exception { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s = null;\n" + + " s += null;\n" + + " if (s != null) {\n" + // s is definitely not null + " System.out.println(\"It works \" + s);\n" + + " }\n" + + " s = null;\n" + + " if (s != null) {\n" + // s is definitely null + " System.out.println(\"Fails \" + s);\n" + + " } else {\n" + + " System.out.println(\"Works second time too \" + s);\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (s != null) {\n" + + " ^\n" + + "Redundant null check: The variable s cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " if (s != null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable s can only be null at this location\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " if (s != null) {\n" + + " System.out.println(\"Fails \" + s);\n" + + " } else {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=342300 +public void testBug342300() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void initPattern(String p, Character escapeChar) {\n" + + " int len = p.length();\n" + + " for (int i = 0; i < len; i++) {\n" + + " char c = p.charAt(i);\n" + + " if (escapeChar != null && escapeChar == c) {\n" + // quiet + " c = p.charAt(++i);\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + ""); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=342300 +// To make sure only the redundant null check is given and not a potential NPE +public void testBug342300b() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void initPattern(String p, Character escapeChar) {\n" + + " int len = p.length();\n" + + " for (int i = 0; i < len; i++) {\n" + + " char c = p.charAt(i);\n" + + " if (escapeChar != null && escapeChar != null) {\n" + // look here + " c = p.charAt(++i);\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (escapeChar != null && escapeChar != null) {\n" + + " ^^^^^^^^^^\n" + + "Redundant null check: The variable escapeChar cannot be null at this location\n" + + "----------\n"); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=348379 +public void testBug348379a() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + runNegativeNullTest( + 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) { + runNegativeNullTest( + 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) { + runNegativeNullTest( + 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) { + runNegativeNullTest( + 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"); + } +} +// Bug 354554 - [null] conditional with redundant condition yields weak error message +public void testBug354554() { + runNegativeNullTest( + new String[] { + "Bug354554.java", + "public class Bug354554{\n" + + " void foo() {\n" + + " Object u = new Object();\n" + + " Object r = (u == null ? u : null);\n" + // condition is always false - should not spoil subsequent null-analysis + " System.out.println(r.toString());\n" + // should strongly complain: r is definitely null + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug354554.java (at line 4)\n" + + " Object r = (u == null ? u : null);\n" + + " ^\n" + + "Null comparison always yields false: The variable u cannot be null at this location\n" + + "----------\n" + + "2. ERROR in Bug354554.java (at line 5)\n" + + " System.out.println(r.toString());\n" + + " ^\n" + + "Null pointer access: The variable r can only be null at this location\n" + + "----------\n"); +} +//Bug 354554 - [null] conditional with redundant condition yields weak error message +public void testBug354554b() { + runNegativeNullTest( + new String[] { + "Bug354554.java", + "public class Bug354554{\n" + + " void foo() {\n" + + " Object u = new Object();\n" + + " Object r = (u != null ? u : null);\n" + // condition is always true - should not spoil subsequent null-analysis + " System.out.println(r.toString());\n" + // don't complain: r is definitely non-null + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug354554.java (at line 4)\n" + + " Object r = (u != null ? u : null);\n" + + " ^\n" + + "Redundant null check: The variable u cannot be null at this location\n" + + "----------\n"); +} +// Bug 358827 - [1.7] exception analysis for t-w-r spoils null analysis +public void test358827() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + runNegativeNullTest( + new String[] { + "Bug358827.java", + "import java.io.FileReader;\n" + + "public class Bug358827 {\n" + + " Object foo2() throws Exception {\n" + + " String o = null;\n" + + " try (FileReader rf = new FileReader(\"file\")){\n" + + " o = o.toUpperCase();\n" + + " } finally {\n" + + " o = \"OK\";\n" + + " }\n" + + " return o;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug358827.java (at line 6)\n" + + " o = o.toUpperCase();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n"); + } +} +// Bug 367879 - Incorrect "Potential null pointer access" warning on statement after try-with-resources within try-finally +public void test367879() { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runConformTest( + new String[] { + "Bug367879.java", + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "import java.net.HttpURLConnection;\n" + + "import java.net.URL;\n" + + "public class Bug367879 {\n" + + " public void test() throws IOException {\n" + + " HttpURLConnection http = null;\n" + + " try {\n" + + " http = (HttpURLConnection) new URL(\"http://example.com/\").openConnection();\n" + + " try (InputStream in = http.getInputStream()) { /* get input */ }\n" + + " http.getURL();\n" + // shouldn't *not* flag as Potential null pointer access + " } finally {\n" + + " if (http != null) { http.disconnect(); }\n" + + " }\n" + + " }\n" + + "}\n" + }, + ""); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=256796 +public void testBug256796() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUnnecessaryElse, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.WARNING); + compilerOptions.put(CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "Bug.java", + "public class Bug {\n" + + " private static final boolean TRUE = true;\n" + + " private static final boolean FALSE = false;\n" + + " void foo() throws Exception {\n" + + " if (TRUE) return;\n" + + " else System.out.println(\"\");\n" + + " System.out.println(\"\");\n" + // not dead code + " if (TRUE) throw new Exception();\n" + + " else System.out.println(\"\");\n" + + " System.out.println(\"\");\n" + // not dead code + " if (TRUE) return;\n" + + " System.out.println(\"\");\n" + // not dead code + " if (FALSE) System.out.println(\"\");\n" + + " else return;\n" + + " System.out.println(\"\");\n" + // not dead code + " if (FALSE) return;\n" + + " System.out.println(\"\");\n" + // not dead code + " if (false) return;\n" + // dead code + " System.out.println(\"\");\n" + + " if (true) return;\n" + + " System.out.println(\"\");\n" + // dead code + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Bug.java (at line 18)\n" + + " if (false) return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in Bug.java (at line 21)\n" + + " System.out.println(\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + null, + true, + compilerOptions, + null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=256796 +public void testBug256796a() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUnnecessaryElse, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.WARNING); + compilerOptions.put(CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "Bug.java", + "public class Bug {\n" + + " private static final boolean TRUE = true;\n" + + " private static final boolean FALSE = false;\n" + + " void foo() throws Exception {\n" + + " if (TRUE) return;\n" + + " else System.out.println(\"\");\n" + + " System.out.println(\"\");\n" + // dead code + " }\n" + + " void foo2() {\n" + + " if (TRUE) return;\n" + + " System.out.println(\"\");\n" + // dead code + " }\n" + + " void foo3() throws Exception {\n" + + " if (TRUE) throw new Exception();\n" + + " else System.out.println(\"\");\n" + // dead code + " System.out.println(\"\");\n" + // dead code + " }\n" + + " void foo4() throws Exception {\n" + + " if (FALSE) System.out.println(\"\");\n" + + " else return;\n" + + " System.out.println(\"\");\n" + // dead code + " }\n" + + " void foo5() throws Exception {\n" + + " if (FALSE) return;\n" + // dead code + " System.out.println(\"\");\n" + + " }\n" + + " void foo6() throws Exception {\n" + + " if (false) return;\n" + // dead code + " System.out.println(\"\");\n" + + " if (true) return;\n" + + " System.out.println(\"\");\n" + // dead code + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Bug.java (at line 6)\n" + + " else System.out.println(\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in Bug.java (at line 7)\n" + + " System.out.println(\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in Bug.java (at line 11)\n" + + " System.out.println(\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "4. WARNING in Bug.java (at line 15)\n" + + " else System.out.println(\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "5. WARNING in Bug.java (at line 16)\n" + + " System.out.println(\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "6. WARNING in Bug.java (at line 19)\n" + + " if (FALSE) System.out.println(\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "7. WARNING in Bug.java (at line 21)\n" + + " System.out.println(\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "8. WARNING in Bug.java (at line 24)\n" + + " if (FALSE) return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "9. WARNING in Bug.java (at line 28)\n" + + " if (false) return;\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "10. WARNING in Bug.java (at line 31)\n" + + " System.out.println(\"\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + null, + true, + compilerOptions, + "", + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} +// Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) +public void testBug360328() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + runNegativeTest( + true, /* flushOutputDir */ + new String[] { + "X.java", + "public class X {\n" + + " void print4() {\n" + + " final String s1 = \"\";\n" + + " for (int i=0; i<4; i++)\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " if (s1 != null)\n" + + " s1.toString();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " void print16(boolean b) {\n" + + " final String s3 = b ? null : \"\";\n" + + " for (int i=0; i<16; i++)\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " s3.toString();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " void print23() {\n" + + " final String s23 = null;\n" + + " for (int i=0; i<23; i++)\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " s23.toString();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n", + + }, + null, /* classLibs */ + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (s1 != null)\n" + + " ^^\n" + + "Redundant null check: The variable s1 cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " s3.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable s3 may be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 26)\n" + + " s23.toString();\n" + + " ^^^\n" + + "Null pointer access: The variable s23 can only be null at this location\n" + + "----------\n", + "",/* expected output */ + "",/* expected error */ + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) +// constructors +public void testBug360328b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + runNegativeTest( + true, /* flushOutputDir */ + new String[] { + "X.java", + "public class X {\n" + + " void print4() {\n" + + " final String s1 = \"\";\n" + + " for (int i=0; i<4; i++) {\n" + + " class R {\n" + + " public R() {\n" + + " if (s1 != null)\n" + + " s1.toString();\n" + + " }\n" + + " };\n" + + " new R();\n" + + " }\n" + + " }\n" + + " void print16(boolean b) {\n" + + " final String s3 = b ? null : \"\";\n" + + " int i=0; while (i++<16) {\n" + + " class R {\n" + + " public R() {\n" + + " s3.toString();\n" + + " }\n" + + " };\n" + + " new R();\n" + + " };\n" + + " }\n" + + " void print23() {\n" + + " final String s23 = null;\n" + + " for (int i=0; i<23; i++) {\n" + + " class R {\n" + + " public R() {\n" + + " s23.toString();\n" + + " }\n" + + " };\n" + + " new R();\n" + + " };\n" + + " }\n" + + "}\n", + + }, + null, /* classLibs */ + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (s1 != null)\n" + + " ^^\n" + + "Redundant null check: The variable s1 cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " s3.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable s3 may be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 30)\n" + + " s23.toString();\n" + + " ^^^\n" + + "Null pointer access: The variable s23 can only be null at this location\n" + + "----------\n", + "",/* expected output */ + "",/* expected error */ + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) +// initializers +public void testBug360328c() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runNegativeTest( + true, /* flushOutputDir */ + new String[] { + "X.java", + "public class X {\n" + + " void print4() {\n" + + " final String s1 = \"\";\n" + + " for (int i=0; i<4; i++) {\n" + + " class R {\n" + + " String s1R;\n" + + " {\n" + + " if (s1 != null)\n" + + " s1R = s1;\n" + + " }\n" + + " };\n" + + " new R();\n" + + " }\n" + + " }\n" + + " void print16(boolean b) {\n" + + " final String s3 = b ? null : \"\";\n" + + " for (int i=0; i<16; i++) {\n" + + " class R {\n" + + " String s3R = s3.toString();\n" + + " };\n" + + " new R();\n" + + " };\n" + + " }\n" + + " void print23() {\n" + + " final String s23 = null;\n" + + " for (int i=0; i<23; i++) {\n" + + " class R {\n" + + " String s23R;\n" + + " {\n" + + " s23R = s23.toString();\n" + + " }\n" + + " };\n" + + " new R();\n" + + " };\n" + + " }\n" + + "}\n", + + }, + null, /* classLibs */ + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " if (s1 != null)\n" + + " ^^\n" + + "Redundant null check: The variable s1 cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " String s3R = s3.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable s3 may be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 30)\n" + + " s23R = s23.toString();\n" + + " ^^^\n" + + "Null pointer access: The variable s23 can only be null at this location\n" + + "----------\n", + "",/* expected output */ + "",/* expected error */ + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// Bug 360328 - [compiler][null] detect null problems in nested code (local class inside a loop) +// try-finally instead of loop +public void testBug360328d() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + runNegativeTest( + true, /* flushOutputDir */ + new String[] { + "X.java", + "public class X {\n" + + " void print4() {\n" + + " final String s1 = \"\";\n" + + " try { } finally {\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " if (s1 != null)\n" + + " s1.toString();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }\n" + + " void print16(boolean b) {\n" + + " final String s3 = b ? null : \"\";\n" + + " try { } finally {\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " s3.toString();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }\n" + + " void print23() {\n" + + " final String s23 = null;\n" + + " try { } finally {\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " s23.toString();\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " }\n" + + "}\n", + + }, + null, /* classLibs */ + customOptions, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " if (s1 != null)\n" + + " ^^\n" + + "Redundant null check: The variable s1 cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " s3.toString();\n" + + " ^^\n" + + "Potential null pointer access: The variable s3 may be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 28)\n" + + " s23.toString();\n" + + " ^^^\n" + + "Null pointer access: The variable s23 can only be null at this location\n" + + "----------\n", + "",/* expected output */ + "",/* expected error */ + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} +// Bug 384380 - False positive on a "Potential null pointer access" after a continue +// original test case +public void testBug384380() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public static class Container{\n" + + " public int property;\n" + + " }\n" + + " public static class CustomException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " public static void anotherMethod() throws CustomException {}\n" + + "\n" + + " public static void method(final java.util.List list) {\n" + + " for (final Container c : list) {\n" + + " if(c == null)\n" + + " continue; // return or break, are fine though\n" + + "\n" + + " // without this try-catch+for+exception block it does not fails\n" + + " try {\n" + + " for(int i = 0; i < 10 ; i++) // needs a loop here (a 'while' or a 'for') to fail\n" + + " anotherMethod(); // throwing directly CustomException make it fails too\n" + + " } catch (final CustomException e) {\n" + + " // it fails even if catch is empty\n" + + " }\n" + + " c.property += 1; // \"Potential null pointer access: The variable c may be null at this location\"\n" + + " }\n" + + "\n" + + " }\n" + + "}\n" + }, + ""); + } +} +// Bug 384380 - False positive on a "Potential null pointer access" after a continue +// variant with a finally block +public void testBug384380_a() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public static class Container{\n" + + " public int property;\n" + + " }\n" + + " public static class CustomException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " public static void anotherMethod() throws CustomException {}\n" + + "\n" + + " public static void method(final java.util.List list) {\n" + + " for (final Container c : list) {\n" + + " if(c == null)\n" + + " continue; // return or break, are fine though\n" + + "\n" + + " // without this try-catch+for+exception block it does not fails\n" + + " try {\n" + + " for(int i = 0; i < 10 ; i++) // needs a loop here (a 'while' or a 'for') to fail\n" + + " anotherMethod(); // throwing directly CustomException make it fails too\n" + + " } catch (final CustomException e) {\n" + + " // it fails even if catch is empty\n" + + " } finally {\n" + + " System.out.print(3);\n" + + " }\n" + + " c.property += 1; // \"Potential null pointer access: The variable c may be null at this location\"\n" + + " }\n" + + "\n" + + " }\n" + + "}\n" + }, + ""); + } +} +// Bug 384380 - False positive on a "Potential null pointer access" after a continue +// while & foreach loops +public void testBug384380_b() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public static class Container{\n" + + " public int property;\n" + + " }\n" + + " public static class CustomException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " public static void anotherMethod() throws CustomException {}\n" + + "\n" + + " public static void method(final java.util.List list) {\n" + + " java.util.Iterator it = list.iterator();\n" + + " while (it.hasNext()) {\n" + + " final Container c = it.next();\n" + + " if(c == null)\n" + + " continue; // return or break, are fine though\n" + + "\n" + + " // without this try-catch+for+exception block it does not fails\n" + + " try {\n" + + " for(Container c1 : list) // needs a loop here (a 'while' or a 'for') to fail\n" + + " anotherMethod(); // throwing directly CustomException make it fails too\n" + + " } catch (final CustomException e) {\n" + + " // it fails even if catch is empty\n" + + " }\n" + + " c.property += 1; // \"Potential null pointer access: The variable c may be null at this location\"\n" + + " }\n" + + "\n" + + " }\n" + + "}\n" + }, + ""); + } +} +public void testBug376263() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " private int x;\n" + + "\n" + + " static void test(Test[] array) {\n" + + " Test elem = null;\n" + + " int i = 0;\n" + + " while (i < array.length) {\n" + + " if (i == 0) {\n" + + " elem = array[0];\n" + + " }\n" + + " if (elem != null) {\n" + + " while (true) {\n" + + " if (elem.x >= 0 || i >= array.length) { // should not warn here\n" + + " break;\n" + + " }\n" + + " elem = array[i++];\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null/*classLibraries*/, + true/*shouldFlush*/, + null/*vmArgs*/, + customOptions, + null/*requestor*/); +} +//object/array allocation +public void testExpressions01() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " if (new Object() == null)\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " void goo() {\n" + + " if (null != this.new I())\n" + + " System.out.println(\"nonnull\");\n" + + " }\n" + + " void hoo() {\n" + + " if (null != new Object[3])\n" + + " System.out.println(\"nonnull\");\n" + + " }\n" + + " class I {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (new Object() == null)\n" + + " ^^^^^^^^^^^^\n" + + "Null comparison always yields false: this expression cannot be null\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " System.out.println(\"null\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " if (null != this.new I())\n" + + " ^^^^^^^^^^^^\n" + + "Redundant null check: this expression cannot be null\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " if (null != new Object[3])\n" + + " ^^^^^^^^^^^^^\n" + + "Redundant null check: this expression cannot be null\n" + + "----------\n" + ); +} +//'this' expressions (incl. qualif.) +public void testExpressions02() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " if (this == null)\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " class I {\n" + + " void goo() {\n" + + " if (null != X.this)\n" + + " System.out.println(\"nonnull\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (this == null)\n" + + " ^^^^\n" + + "Null comparison always yields false: this expression cannot be null\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " System.out.println(\"null\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " if (null != X.this)\n" + + " ^^^^^^\n" + + "Redundant null check: this expression cannot be null\n" + + "----------\n" + ); +} +//various non-null expressions: class-literal, string-literal, casted 'this' +public void testExpressions03() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " if (X.class == null)\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " void goo() {\n" + + " if (null != \"STRING\")\n" + + " System.out.println(\"nonnull\");\n" + + " if (null == (Object)this)\n" + + " System.out.println(\"I'm null\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (X.class == null)\n" + + " ^^^^^^^\n" + + "Null comparison always yields false: this expression cannot be null\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " System.out.println(\"null\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " if (null != \"STRING\")\n" + + " ^^^^^^^^\n" + + "Redundant null check: this expression cannot be null\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " if (null == (Object)this)\n" + + " ^^^^^^^^^^^^\n" + + "Null comparison always yields false: this expression cannot be null\n" + + "----------\n" + + "5. WARNING in X.java (at line 10)\n" + + " System.out.println(\"I\'m null\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + ); +} + +//a non-null ternary expression +public void testExpressions04() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " Object o1 = new Object();\n" + + " Object o2 = new Object();\n" + + " if ((b ? o1 : o2) != null)\n" + + " System.out.println(\"null\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if ((b ? o1 : o2) != null)\n" + + " ^^^^^^^^^^^^^\n" + + "Redundant null check: this expression cannot be null\n" + + "----------\n" + ); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// simplified: only try-finally involved +public void testBug345305_1() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s = null;\n" + + " try {\n" + + " s = \"hi\";\n" + + " } finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + "}\n" + }); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// original test case +public void testBug345305_2() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s = null;\n" + + " while (true) {\n" + + " try {\n" + + " s = \"hi\";\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// assignment in method argument position +public void testBug345305_3() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s = null;\n" + + " while (true) {\n" + + " try {\n" + + " check(s = \"hi\");\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + " void check(String s) {}\n" + + "}\n" + }); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// analysis of second local variable must not interfere +public void testBug345305_4() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s = \"\";\n" + + " String s2 = null;\n" + + " while (true) {\n" + + " try {\n" + + " s = null;\n" + + " bar();\n" + + " s2 = \"world\";\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + " void bar() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " s.length();\n" + + " ^\n" + + "Null pointer access: The variable s can only be null at this location\n" + + "----------\n"); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// block-less if involved - info about pot.nn. was lost when checking against loop's info (deferred check) +public void testBug345305_6() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " String s = null;\n" + + " while (true) {\n" + + " try {\n" + + " if (b)\n" + + " s = \"hi\";\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " s.length();\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// block-less if involved +public void testBug345305_7() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(boolean b) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " try {\n" + + " if (b)\n" + + " s = \"hi\";\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " s.length();\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// consider exception thrown from cast expression +public void testBug345305_8() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " try {\n" + + " s = (String) o;\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " s.length();\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// consider exception thrown from binary expression +public void testBug345305_9() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(int i, int j) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " try {\n" + + " s = ((i / j) == 3) ? \"3\" : \"not-3\";\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " s.length();\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// inner labeled block with break +public void testBug345305_10() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(int j) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " try {\n" + + " int i=0;\n" + + " block: {\n" + + " if (i++ == j)\n" + + " break block;\n" + + " s = \"\";\n" + + " return;\n" + + " }\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " s.length();\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// switch statement +public void testBug345305_11() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(int j) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " try {\n" + + " switch (j) {\n" + + " case 3:\n" + + " s = \"\";\n" + + " return;\n" + + " default: return;\n" + + " }\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " s.length();\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// assignment inside conditional expression +public void testBug345305_12() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo(boolean b) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " try {\n" + + " return b ? (s = \"be\") : \"be not\";\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " s.length();\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// explicit throw +public void testBug345305_13() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " String foo(boolean b) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " RuntimeException ex = new RuntimeException();\n" + + " try {\n" + + " if (b)\n" + + " throw ex;\n" + + " s = \"be\";\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " s.length();\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} + +// Bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" +// do-while +public void testBug345305_14() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo1(boolean b) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " try {\n" + + " do {\n" + + " s = \"be\";\n" + + " if (b)\n" + + " return;\n" + + " } while (true);\n" + + " }\n" + + " finally {\n" + + " s.length(); // don't complain here\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + " void foo2(boolean b) {\n" + + " while (true) {\n" + + " String s = null;\n" + + " try {\n" + + " do {\n" + + " if (b)\n" + + " continue;\n" + + " s = \"be\";\n" + + " b = !b;\n" + + " } while (b);\n" + + " }\n" + + " finally {\n" + + " s.length();\n" + + " s = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 30)\n" + + " s.length();\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} + +// Bug 364326 - [compiler][null] NullPointerException is not found by compiler. FindBugs finds that one +public void testBug364326() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // employs auto-unboxing + runNegativeNullTest( + new String[] { + "NPE_OnBoxing.java", + "\n" + + "public class NPE_OnBoxing\n" + + "{\n" + + " private interface IValue\n" + + " {\n" + + " boolean isSomething();\n" + + " }\n" + + "\n" + + " private final IValue m_Value;\n" + + "\n" + + " public NPE_OnBoxing()\n" + + " {\n" + + " m_Value = null;\n" + + " }\n" + + "\n" + + " public boolean isSomething()\n" + + " {\n" + + " return m_Value != null ? m_Value.isSomething() : null;\n" + + " }\n" + + "\n" + + " public static void main(final String [] args)\n" + + " {\n" + + " new NPE_OnBoxing().isSomething();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in NPE_OnBoxing.java (at line 18)\n" + + " return m_Value != null ? m_Value.isSomething() : null;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: This expression of type Boolean may be null but requires auto-unboxing\n" + + "----------\n"); +} + +// Bug 401088 - [compiler][null] Wrong warning "Redundant null check" inside nested try statement +public void testBug401088() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " private static void occasionallyThrowException() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + "\n" + + " private static void open() throws Exception {\n" + + " occasionallyThrowException();\n" + + " }\n" + + "\n" + + " private static void close() throws Exception {\n" + + " occasionallyThrowException();\n" + + " }\n" + + "\n" + + " public static void main(String s[]) {\n" + + " Exception exc = null;\n" + + " try {\n" + + " open();\n" + + " // do more things\n" + + " }\n" + + " catch (Exception e) {\n" + + " exc = e;\n" + + " }\n" + + " finally {\n" + + " try {\n" + + " close();\n" + + " }\n" + + " catch (Exception e) {\n" + + " if (exc == null) // should not warn on this line\n" + + " exc = e;\n" + + " }\n" + + " }\n" + + " if (exc != null)\n" + + " System.out.println(exc);\n" + + " }\n" + + "}\n" + }, + "java.lang.Exception"); +} +// Bug 401088 - [compiler][null] Wrong warning "Redundant null check" inside nested try statement +public void testBug401088a() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " private static void occasionallyThrowException() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + "\n" + + " private static void open() throws Exception {\n" + + " occasionallyThrowException();\n" + + " }\n" + + "\n" + + " private static void close() throws Exception {\n" + + " occasionallyThrowException();\n" + + " }\n" + + "\n" + + " public static void main(String s[]) {\n" + + " Exception exc = null;\n" + + " try {\n" + + " open();\n" + + " // do more things\n" + + " }\n" + + " catch (Exception e) {\n" + + " exc = e;\n" + + " }\n" + + " finally {\n" + + " try {\n" + + " close();\n" + + " }\n" + + " catch (Exception e) {\n" + + " if (exc == null) // should not warn on this line\n" + + " exc = e;\n" + + " }\n" + + " finally { System.out.print(1); }\n" + + " }\n" + + " if (exc != null)\n" + + " System.out.println(exc);\n" + + " }\n" + + "}\n" + }, + "1java.lang.Exception"); +} +// Bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try +public void test401092() { + runConformTest( + new String[] { + "X.java", + "import java.util.Date;\n" + + "\n" + + "public class X {\n" + + "\n" + + " private static void occasionallyThrowException() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + "\n" + + " private static Date createDate() throws Exception {\n" + + " occasionallyThrowException();\n" + + " return new Date();\n" + + " }\n" + + "\n" + + " public static void main(String s[]) {\n" + + " Date d = null;\n" + + " try {\n" + + " d = createDate();\n" + + " System.out.println(d.toString());\n" + + " try {\n" + + " occasionallyThrowException();\n" + + " }\n" + + " catch (Exception exc) {\n" + + " }\n" + + " }\n" + + " catch (Exception exc) {\n" + + " if (d != null) // should not warn in this line\n" + + " System.out.println(d.toString());\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +// Bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try +public void test401092a() { + runConformTest( + new String[] { + "X.java", + "import java.util.Date;\n" + + "\n" + + "public class X {\n" + + "\n" + + " private static void occasionallyThrowException() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + "\n" + + " private static Date createDate() throws Exception {\n" + + " occasionallyThrowException();\n" + + " return new Date();\n" + + " }\n" + + "\n" + + " public static void main(String s[]) {\n" + + " Date d = null;\n" + + " try {\n" + + " d = createDate();\n" + + " System.out.println(d.toString());\n" + + " try {\n" + + " occasionallyThrowException();\n" + + " }\n" + + " catch (Exception exc) {\n" + + " }\n" + + " finally { System.out.println(1); }\n" + + " }\n" + + " catch (Exception exc) {\n" + + " if (d != null) // should not warn in this line\n" + + " System.out.println(d.toString());\n" + + " }\n" + + " finally { System.out.println(2); }\n" + + " }\n" + + "}\n" + }); +} +// Bug 402993 - [null] Follow up of bug 401088: Missing warning about redundant null check +public void testBug402993() { + runNegativeNullTest( + new String[] { + "Test.java", + "public class Test {\n" + + "\n" + + " private static void occasionallyThrowException() throws Exception {\n" + + " if ((System.currentTimeMillis() & 1L) != 0L)\n" + + " throw new Exception();\n" + + " }\n" + + "\n" + + " private static void open() throws Exception {\n" + + " occasionallyThrowException();\n" + + " }\n" + + "\n" + + " private static void close() throws Exception {\n" + + " occasionallyThrowException();\n" + + " }\n" + + "\n" + + " public static void main(String s[]) {\n" + + " Exception exc = null;\n" + + " try {\n" + + " open();\n" + + " // do more things\n" + + " }\n" + + " catch (Exception e) {\n" + + " if (exc == null) // no warning here ??\n" + + " ;\n" + + " }\n" + + " finally {\n" + + " try {\n" + + " close();\n" + + " }\n" + + " catch (Exception e) {\n" + + " if (exc == null) // No warning here ??\n" + + " exc = e;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 23)\n" + + " if (exc == null) // no warning here ??\n" + + " ^^^\n" + + "Redundant null check: The variable exc can only be null at this location\n" + + "----------\n" + + "2. ERROR in Test.java (at line 31)\n" + + " if (exc == null) // No warning here ??\n" + + " ^^^\n" + + "Redundant null check: The variable exc can only be null at this location\n" + + "----------\n"); +} +// Bug 402993 - [null] Follow up of bug 401088: Missing warning about redundant null check +// variant with finally block in inner try +public void testBug402993a() { + runNegativeNullTest( + new String[] { + "Test.java", + "public class Test {\n" + + "\n" + + " private static void occasionallyThrowException() throws Exception {\n" + + " if ((System.currentTimeMillis() & 1L) != 0L)\n" + + " throw new Exception();\n" + + " }\n" + + "\n" + + " private static void open() throws Exception {\n" + + " occasionallyThrowException();\n" + + " }\n" + + "\n" + + " private static void close() throws Exception {\n" + + " occasionallyThrowException();\n" + + " }\n" + + "\n" + + " public static void main(String s[]) {\n" + + " Exception exc = null;\n" + + " try {\n" + + " open();\n" + + " // do more things\n" + + " }\n" + + " catch (Exception e) {\n" + + " if (exc == null) // no warning here ??\n" + + " ;\n" + + " }\n" + + " finally {\n" + + " try {\n" + + " close();\n" + + " }\n" + + " catch (Exception e) {\n" + + " if (exc == null) // No warning here ??\n" + + " exc = e;\n" + + " } finally {\n" + + " System.out.print(1);\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 23)\n" + + " if (exc == null) // no warning here ??\n" + + " ^^^\n" + + "Redundant null check: The variable exc can only be null at this location\n" + + "----------\n" + + "2. ERROR in Test.java (at line 31)\n" + + " if (exc == null) // No warning here ??\n" + + " ^^^\n" + + "Redundant null check: The variable exc can only be null at this location\n" + + "----------\n"); +} +public void testBug453305() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses foreach loop + runConformTest( + new String[] { + "NullTest.java", + "import java.util.*;\n" + + "public class NullTest {\n" + + " class SomeOtherClass {\n" + + "\n" + + " public SomeOtherClass m() {\n" + + " return new SomeOtherClass();\n" + + " }\n" + + "\n" + + " public void doSomething() {\n" + + " }\n" + + " }\n" + + "\n" + + " public Object m1() {\n" + + " SomeOtherClass result = null;\n" + + " List list = new ArrayList();\n" + + " for (Object next : list) {\n" + + " System.out.println(next);\n" + + " boolean bool = false;\n" + + " if (bool) {\n" + + " SomeOtherClass something = new SomeOtherClass();\n" + + " result = something.m();\n" + + " } else {\n" + + " result = new SomeOtherClass();\n" + + " }\n" + + " result.doSomething(); // warning is here\n" + + " break;\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug431016() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses foreach loop + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void test(Object[] values) {\n" + + " Object first = null;\n" + + " for (Object current : values) {\n" + + " if (first == null) {\n" + + " first = current;\n" + + " }\n" + + "\n" + + " if (current.hashCode() > 0) {\n" + + " System.out.println(first.hashCode());\n" + + " }\n" + + "\n" + + " System.out.println(first.hashCode());\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +// originally created for documentation purpose, see https://bugs.eclipse.org/453483#c9 +public void testBug431016_simplified() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " void test(Object input, boolean b) {\n" + + " Object o = null;\n" + + " while (true) {\n" + + " if (o == null)\n" + + " o = input;\n" + + " if (b)\n" + + " o.toString();\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +public void testBug432109() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses generics & foreach loop + runConformTest( + new String[] { + "Test.java", + "import java.util.Collection;\n" + + "public class Test {\n" + + " public void test(Collection values)\n" + + " {\n" + + " boolean condition = false;\n" + + " \n" + + " for(Object value : values)\n" + + " {\n" + + " \n" + + " if(value == null)\n" + + " {\n" + + " if( condition )\n" + + " {\n" + + " // without this continue statement, \n" + + " // there is no warning below\n" + + " continue; \n" + + " }\n" + + " \n" + + " value = getDefaultValue();\n" + + " }\n" + + " \n" + + " // IDE complains here about potential null pointer access\n" + + " value.toString();\n" + + " }\n" + + " }\n" + + "\n" + + " public String getDefaultValue() { return \"\"; }\n" + + "}\n" + }); +} +public void testBug435528_orig() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Test.java", + "public class Test\n" + + "{\n" + + " static final String a = \"A\";\n" + + "\n" + + " static void main(String args[])\n" + + " {\n" + + " String x = null;\n" + + " while (true) {\n" + + " x = Math.random() < 0.5 ? a : \"BB\";\n" + + " if (a != null) {\n" + + " System.out.println(\"s2 value: \" + x);\n" + + " }\n" + + " if (x.equals(\"A\")) {\n" + + " break;\n" + + " } else {\n" + + " x = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in Test.java (at line 10)\n" + + " if (a != null) {\n" + + " ^\n" + + "Redundant null check: The field a is a nonnull constant\n" + + "----------\n" + + "2. WARNING in Test.java (at line 15)\n" + + " } else {\n" + + " x = null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n"; + runner.customOptions = getCompilerOptions(); + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +public void testBug435528_notaconstant() { + runConformTest( + true/*flush*/, + new String[] { + "Test.java", + "public class Test\n" + + "{\n" + + " static String a ;\n" + + "\n" + + " static void main(String args[])\n" + + " {\n" + + " String x = null;\n" + + " while (true) {\n" + + " x = Math.random() < 0.5 ? a : \"BB\";\n" + + " if (a != null) {\n" + + " System.out.println(\"s2 value: \" + x);\n" + + " }\n" + + " if (x.equals(\"A\")) {\n" + + " break;\n" + + " } else {\n" + + " x = null;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Test.java (at line 15)\n" + + " } else {\n" + + " x = null;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n", + "", + "", + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} +public void testBug418500() { + runConformTest( + new String[] { + "Test.java", + "import java.util.*;\n" + + "public class Test {\n" + + (this.complianceLevel < ClassFileConstants.JDK1_5 ? "\n" : " @SuppressWarnings(\"unchecked\")\n" ) + + " void method() {\n" + + " Map topMap = new HashMap();\n" + + " List targets = null;\n" + + " \n" + + " for (int idx = 1; idx < 100; idx++) {\n" + + " String[] targetArray = (String[]) topMap.get(\"a\");\n" + + " if (targetArray != null) {\n" + + " targets = Arrays.asList(targetArray);\n" + + " } else {\n" + + " targets = new ArrayList(64);\n" + + " }\n" + + " if (targets.size() > 0) {\n" + + " topMap.put(\"b\", targets.toArray(new String[1]));\n" + + " } else {\n" + + " topMap.remove(\"b\");\n" + + " }\n" + + "\n" + + " // BUG - this statement causes null analysis to\n" + + " // report that at the targets.size() statement above\n" + + " // targets must be null. Commenting this line eliminates the error.\n" + + " targets = null;\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +public void testBug441737() { + runConformTest( + new String[] { + "Bogus.java", + "public class Bogus {\n" + + " static boolean ok = true;\n" + + " static int count = 0;\n" + + " public static void main(String[] args) {\n" + + " Thing x = new Thing();\n" + + " // if y is left uninitialized here, the warning below disappears\n" + + " Thing y = null;\n" + + " do {\n" + + " y = x;\n" + + " if (ok) {\n" + + " // if this assignment is moved out of the if statement\n" + + " // or commented out, the warning below disappears\n" + + " x = y.resolve();\n" + + " }\n" + + " // a warning about y being potentially null occurs here:\n" + + " x = y.resolve();\n" + + " } while (x != y);\n" + + " }\n" + + "\n" + + " static class Thing {\n" + + " public Thing resolve() {\n" + + " return count++ > 2 ? this : new Thing();\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +// fixed in 3.6.2, likely via bug 332637. +public void testBug195638_comment3() { + runConformTest( + new String[] { + "Test.java", + "import java.sql.Connection;\n" + + "import java.sql.SQLException;\n" + + "public class Test {\n" + + " void m() throws SQLException\n" + + " {\n" + + " Connection conn = null;\n" + + " try\n" + + " {\n" + + " conn = createConnection();\n" + + "\n" + + " for (; ; )\n" + + " {\n" + + " throwSomething();\n" + + " }\n" + + " }\n" + + " catch (MyException e)\n" + + " {\n" + + " conn.rollback(); //The variable can never be null here...\n" + + " }\n" + + " }\n" + + "\n" + + " private void throwSomething() throws MyException\n" + + " {\n" + + " throw new MyException();\n" + + " }\n" + + "\n" + + " class MyException extends Exception\n" + + " {\n" + + "\n" + + " }\n" + + "\n" + + " private Connection createConnection()\n" + + " {\n" + + " return null;\n" + + " }\n" + + "}\n" + }); +} +public void testBug195638_comment6() { + runNegativeNullTest( + new String[] { + "CanOnlyBeNullShouldBeMayBeNull.java", + "public class CanOnlyBeNullShouldBeMayBeNull {\n" + + "\n" + + " private void method() {\n" + + " String tblVarRpl = null;\n" + + " while (true) {\n" + + " boolean isOpenVariableMortageRateProduct = true;\n" + + " boolean tblVarRplAllElementAddedIndicator = false;\n" + + " if (isOpenVariableMortageRateProduct) {\n" + + " if (tblVarRplAllElementAddedIndicator == false)\n" + + " tblVarRpl = \"\";\n" + + " tblVarRpl.substring(1); //Can only be null???\n" + + " return; \n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in CanOnlyBeNullShouldBeMayBeNull.java (at line 3)\n" + + " private void method() {\n" + + " ^^^^^^^^\n" + + "The method method() from the type CanOnlyBeNullShouldBeMayBeNull is never used locally\n" + + "----------\n" + + "2. ERROR in CanOnlyBeNullShouldBeMayBeNull.java (at line 11)\n" + + " tblVarRpl.substring(1); //Can only be null???\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: The variable tblVarRpl may be null at this location\n" + + "----------\n"); +} +public void testBug195638_comment14() { + runNegativeNullTest( + new String[] { + "Test.java", + "public class Test {\n" + + " private void test() {\n" + + " boolean x = true;\n" + + " Object o = null;\n" + + " \n" + + " for (;;) {\n" + + " if (x) o = new Object();\n" + + " \n" + + " o.toString(); // warning here\n" + // bug was: Null pointer access: The variable o can only be null at this location + " \n" + + " o = null;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Test.java (at line 2)\n" + + " private void test() {\n" + + " ^^^^^^\n" + + "The method test() from the type Test is never used locally\n" + + "----------\n" + + "2. ERROR in Test.java (at line 9)\n" + + " o.toString(); // warning here\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"); +} +public void testBug195638_comment19() { + runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public void testIt() {\n" + + " Object aRole = null;\n" + + " for (;;) {\n" + + " aRole = new Object();\n" + + " if (aRole.toString() == null) {\n" + + " aRole = getObject(); // changing to \"new Object()\" makes warning disappear.\n" + + " }\n" + + " aRole.toString();\n" + + " // above line gets: \"Null pointer access: The variable aRole can only be null at this location\"\n" + + " break;\n" + + " }\n" + + " }\n" + + " private Object getObject() {\n" + + " return new Object();\n" + + " }\n" + + "}\n" + }); +} +public void testBug454031() { + runNegativeNullTest( + new String[] { + "xy/Try.java", + "package xy;\n" + + "\n" + + "public class Try {\n" + + " public static void main(String[] args) {\n" + + " foo(new Node());\n" + + " }\n" + + " static void foo(Node n) {\n" + + " Node selectedNode= n;\n" + + " if (selectedNode == null) {\n" + + " return;\n" + + " }\n" + + " while (selectedNode != null && !(selectedNode instanceof Cloneable)) {\n" + + " selectedNode= selectedNode.getParent();\n" + + " }\n" + + " if (selectedNode == null) { //wrong problem: Null comparison always yields false: The variable selectedNode cannot be null at this location\n" + + " // wrong problem: dead code\n" + + " System.out.println(selectedNode.hashCode());\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class Node {\n" + + " Node getParent() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in xy\\Try.java (at line 17)\n" + + " System.out.println(selectedNode.hashCode());\n" + + " ^^^^^^^^^^^^\n" + + "Null pointer access: The variable selectedNode can only be null at this location\n" + + "----------\n"); +} +// switch with fall-through nested in for: +public void testBug451660() { + runNegativeNullTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args)\n" + + " {\n" + + " String s = null;\n" + + " for(; true;) // ok with \"while(true)\"\n" + + " {\n" + + " switch(0)\n" + + " {\n" + + " default:\n" + + " s = \"Hello!\";\n" + + " case 1:\n" + + " System.out.println(s.toString());\n" + + " }\n" + + " return;\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " System.out.println(s.toString());\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} +public void testBug486912KnownNullInLoop() { + runNegativeNullTest( + new String[] { + "test/KnownNullInLoop.java", + "package test;\n" + + "\n" + + "public class KnownNullInLoop {\n" + + " public void testDoWhile() {\n" + + " Object o1 = null;\n" + + " do {\n" + + " o1.hashCode(); // ERROR1: known null, but no problem reported.\n" + + " } while (false);\n" + + " }\n" + + "\n" + + " public void testWhileWithBreak() {\n" + + " Object o1 = null;\n" + + " while (true) {\n" + + " o1.hashCode(); // ERROR2: known null, but no problem reported.\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + "----------\n" + + "1. ERROR in test\\KnownNullInLoop.java (at line 7)\n" + + " o1.hashCode(); // ERROR1: known null, but no problem reported.\n" + + " ^^\n" + + "Null pointer access: The variable o1 can only be null at this location\n" + + "----------\n" + + "2. ERROR in test\\KnownNullInLoop.java (at line 14)\n" + + " o1.hashCode(); // ERROR2: known null, but no problem reported.\n" + + " ^^\n" + + "Null pointer access: The variable o1 can only be null at this location\n" + + "----------\n" + ); +} +public void testBug486912PotNullInLoop_orig() { + runNegativeNullTest( + new String[] { + "test/PotNullInLoop.java", + "package test;\n" + + "\n" + + "public class PotNullInLoop {\n" + + " boolean b;\n" + + "\n" + + " public void testDoWhile1() {\n" + + " Object o1 = null;\n" + + " Object o2 = new Object();\n" + + " Object potNonNull = b ? o2 : o2;\n" + // actually: def nn + " Object potNull = b ? o1 : o1;\n" + // actually: def n + " Object ponNullOrNonNull = b ? potNull : potNonNull;\n" + + " do {\n" + + " potNonNull.hashCode(); // OK\n" + + " potNull.hashCode(); // ERROR 1: pot null, but nothing reported\n" + + " ponNullOrNonNull.hashCode(); // ERROR 2: pot null, but nothing reported\n" + + " } while (false);\n" + + " }\n" + + "\n" + + " public void testWhileWithBreak() {\n" + + " Object o1 = null;\n" + + " Object o2 = new Object();\n" + + " Object potNonNull = b ? o2 : o2;\n" + + " Object potNull = b ? o1 : o1;\n" + + " Object ponNullOrNonNull = b ? potNull : potNonNull;\n" + + " while (b) {\n" + + " potNonNull.hashCode(); // OK\n" + + " potNull.hashCode(); // ERROR 3 : pot null, but nothing reported\n" + + " ponNullOrNonNull.hashCode(); // ERROR 4: pot null, but nothing reported\n" + + " break;\n" + + " }\n" + + " }\n" + + "\n" + + " public void testWhile() {\n" + + " Object o1 = null;\n" + + " Object o2 = new Object();\n" + + " Object potNonNull = b ? o2 : o2;\n" + + " Object potNull = b ? o1 : o1;\n" + + " Object ponNullOrNonNull = b ? potNull : potNonNull;\n" + + " while (b) {\n" + + " potNonNull.hashCode(); // OK\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " ponNullOrNonNull.hashCode(); // OK: pot null, is reported\n" + + " }\n" + + " }\n" + + "\n" + + " public void testFor() {\n" + + " Object o1 = null;\n" + + " Object o2 = new Object();\n" + + " Object potNonNull = b ? o2 : o2;\n" + + " Object potNull = b ? o1 : o1;\n" + + " Object ponNullOrNonNull = b ? potNull : potNonNull;\n" + + " for (int i = 0; i < 1; i++) {\n" + + " potNonNull.hashCode(); // OK\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " ponNullOrNonNull.hashCode(); // OK: pot null, is reported\n" + + " }\n" + + " }\n" + + "\n" + + " public void testForEach() {\n" + + " Object o1 = null;\n" + + " Object o2 = new Object();\n" + + " Object potNonNull = b ? o2 : o2;\n" + + " Object potNull = b ? o1 : o1;\n" + + " Object ponNullOrNonNull = b ? potNull : potNonNull;\n" + + " for (int i = 0; i < 1; i++) {\n" + + " potNonNull.hashCode(); // OK\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " ponNullOrNonNull.hashCode(); // OK: pot null, is reported\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + + "", + }, + "----------\n" + + "1. ERROR in test\\PotNullInLoop.java (at line 14)\n" + + " potNull.hashCode(); // ERROR 1: pot null, but nothing reported\n" + + " ^^^^^^^\n" + + "Null pointer access: The variable potNull can only be null at this location\n" + + "----------\n" + + "2. ERROR in test\\PotNullInLoop.java (at line 15)\n" + + " ponNullOrNonNull.hashCode(); // ERROR 2: pot null, but nothing reported\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The variable ponNullOrNonNull may be null at this location\n" + + "----------\n" + + "3. ERROR in test\\PotNullInLoop.java (at line 27)\n" + + " potNull.hashCode(); // ERROR 3 : pot null, but nothing reported\n" + + " ^^^^^^^\n" + + "Null pointer access: The variable potNull can only be null at this location\n" + + "----------\n" + + "4. ERROR in test\\PotNullInLoop.java (at line 28)\n" + + " ponNullOrNonNull.hashCode(); // ERROR 4: pot null, but nothing reported\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The variable ponNullOrNonNull may be null at this location\n" + + "----------\n" + + "5. ERROR in test\\PotNullInLoop.java (at line 41)\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " ^^^^^^^\n" + + "Null pointer access: The variable potNull can only be null at this location\n" + + "----------\n" + + "6. ERROR in test\\PotNullInLoop.java (at line 42)\n" + + " ponNullOrNonNull.hashCode(); // OK: pot null, is reported\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The variable ponNullOrNonNull may be null at this location\n" + + "----------\n" + + "7. ERROR in test\\PotNullInLoop.java (at line 54)\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " ^^^^^^^\n" + + "Null pointer access: The variable potNull can only be null at this location\n" + + "----------\n" + + "8. ERROR in test\\PotNullInLoop.java (at line 55)\n" + + " ponNullOrNonNull.hashCode(); // OK: pot null, is reported\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The variable ponNullOrNonNull may be null at this location\n" + + "----------\n" + + "9. ERROR in test\\PotNullInLoop.java (at line 67)\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " ^^^^^^^\n" + + "Null pointer access: The variable potNull can only be null at this location\n" + + "----------\n" + + "10. ERROR in test\\PotNullInLoop.java (at line 68)\n" + + " ponNullOrNonNull.hashCode(); // OK: pot null, is reported\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The variable ponNullOrNonNull may be null at this location\n" + + "----------\n" + ); +} +// variant of testBug486912PotNullInLoop_orig spiced up with potentiality from an 'unknown' o0: +public void testBug486912PotNullInLoop() { + runNegativeNullTest( + new String[] { + "test/PotNullInLoop.java", + "package test;\n" + + "\n" + + "public class PotNullInLoop {\n" + + " boolean b;\n" + + "\n" + + " public void testDoWhile1(Object o0) {\n" + + " Object o1 = null;\n" + + " Object o2 = new Object();\n" + + " Object potNonNull = b ? o2 : o0;\n" + + " Object potNull = b ? o1 : o0;\n" + + " do {\n" + + " potNonNull.hashCode(); // OK\n" + + " potNull.hashCode(); // ERROR 1: pot null, but nothing reported\n" + + " } while (false);\n" + + " }\n" + + "\n" + + " public void testWhileWithBreak(Object o0) {\n" + + " Object o1 = null;\n" + + " Object o2 = new Object();\n" + + " Object potNonNull = b ? o2 : o0;\n" + + " Object potNull = b ? o1 : o0;\n" + + " while (b) {\n" + + " potNonNull.hashCode(); // OK\n" + + " potNull.hashCode(); // ERROR 3 : pot null, but nothing reported\n" + + " break;\n" + + " }\n" + + " }\n" + + "\n" + + " public void testWhile(Object o0) {\n" + + " Object o1 = null;\n" + + " Object o2 = new Object();\n" + + " Object potNonNull = b ? o2 : o0;\n" + + " Object potNull = b ? o1 : o0;\n" + + " while (b) {\n" + + " potNonNull.hashCode(); // OK\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " }\n" + + " }\n" + + "\n" + + " public void testFor(Object o0) {\n" + + " Object o1 = null;\n" + + " Object o2 = new Object();\n" + + " Object potNonNull = b ? o2 : o0;\n" + + " Object potNull = b ? o1 : o0;\n" + + " for (int i = 0; i < 1; i++) {\n" + + " potNonNull.hashCode(); // OK\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " }\n" + + " }\n" + + "\n" + + " public void testForEach(Object o0) {\n" + + " Object o1 = null;\n" + + " Object o2 = new Object();\n" + + " Object potNonNull = b ? o2 : o0;\n" + + " Object potNull = b ? o1 : o0;\n" + + " for (int i = 0; i < 1; i++) {\n" + + " potNonNull.hashCode(); // OK\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + + "", + }, + "----------\n" + + "1. ERROR in test\\PotNullInLoop.java (at line 13)\n" + + " potNull.hashCode(); // ERROR 1: pot null, but nothing reported\n" + + " ^^^^^^^\n" + + "Potential null pointer access: The variable potNull may be null at this location\n" + + "----------\n" + + "2. ERROR in test\\PotNullInLoop.java (at line 24)\n" + + " potNull.hashCode(); // ERROR 3 : pot null, but nothing reported\n" + + " ^^^^^^^\n" + + "Potential null pointer access: The variable potNull may be null at this location\n" + + "----------\n" + + "3. ERROR in test\\PotNullInLoop.java (at line 36)\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " ^^^^^^^\n" + + "Potential null pointer access: The variable potNull may be null at this location\n" + + "----------\n" + + "4. ERROR in test\\PotNullInLoop.java (at line 47)\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " ^^^^^^^\n" + + "Potential null pointer access: The variable potNull may be null at this location\n" + + "----------\n" + + "5. ERROR in test\\PotNullInLoop.java (at line 58)\n" + + " potNull.hashCode(); // OK: pot null, is reported\n" + + " ^^^^^^^\n" + + "Potential null pointer access: The variable potNull may be null at this location\n" + + "----------\n" + ); +} +public void testBug447695() { + runConformTest( + new String[] { + "test/Test447695.java", + "package test;\n" + + "\n" + + "public class Test447695 {\n" + + " public static void f() {\n" + + " int[] array = null;\n" + + " (array = new int[1])[0] = 42;\n" + + " }\n" + + " public static int g() {\n" + + " int[] array = null;\n" + + " return (array = new int[1])[0];\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug447695b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses foreach + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " void test(String[] ss) {\n" + + " List strings = null;\n" + + " for (String s : (strings = Arrays.asList(ss)))\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n" + }); +} +public void testBug447695c() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses autoboxing + runConformTest( + new String[] { + "test/Test447695.java", + "package test;\n" + + "\n" + + "public class Test447695 {\n" + + " void f() {\n" + + " Integer l1 = null;\n" + + " Integer l2 = null;\n" + + " int b = (l1 = new Integer(2)) + (l2 = new Integer(1));\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug447695d() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // uses reference expression + runConformTest( + new String[] { + "test/Test447695.java", + "package test;\n" + + "\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "public class Test447695 {\n" + + " void f() {\n" + + " String s = null;\n" + + " Supplier l = (s = \"\")::toString;\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug447695e() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses autoboxing + runConformTest( + new String[] { + "test/Test447695.java", + "package test;\n" + + "\n" + + "public class Test447695 {\n" + + " void f() {\n" + + " Integer i = null;\n" + + " int j = -(i = new Integer(1));\n" + + " Boolean b1 = null;\n" + + " boolean b = !(b1 = new Boolean(false));\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug447695f() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses autoboxing + runConformTest( + new String[] { + "test/Test447695.java", + "package test;\n" + + "\n" + + "public class Test447695 {\n" + + " void f() {\n" + + " int i = 0;\n" + + " Integer i1 = null;\n" + + " Integer i2 = null;\n" + + " Integer i3 = null;\n" + + " int j = (i1 = new Integer(1)) \n" + + " + (i2 = new Integer(1)) \n" + + " + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i + i \n" + + " + (i3 = new Integer(2)) + i;\n" + + " }\n" + + "}\n" + } + ); +} +public void testBug447695g() { + runNegativeNullTest( + new String[] { + "test/Test447695.java", + "package test;\n" + + "\n" + + "class X {\n" + + " int i;\n" + + "}\n" + + "\n" + + "public class Test447695 {\n" + + " void f() {\n" + + " X x1 = null;\n" + + " X x2 = null;\n" + + " X x3 = null;\n" + + " X x4 = null;\n" + + " X x5 = null;\n" + + " X x6 = null;\n" + + " X x7 = null;\n" + + " X x8 = null;\n" + + " X x9 = null;\n" + + " X x10 = null;\n" + + " X x11 = null;\n" + + " x1.i = 1; // error 1 expected\n" + + " x2.i += 1; // error 2 expected\n" + + " (x3).i = 1; // error 3 expected\n" + + " (x4).i += 1; // error 4 expected\n" + + " (x5 = new X()).i = (x6 = new X()).i;\n" + + " (x7 = new X()).i += (x8 = new X()).i;\n" + + " int i1 = x9.i; // error 5 expected\n" + + " int i2 = (x10).i; // error 6 expected\n" + + " int i3 = (x11 = new X()).i;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in test\\Test447695.java (at line 20)\n" + + " x1.i = 1; // error 1 expected\n" + + " ^^\n" + + "Null pointer access: The variable x1 can only be null at this location\n" + + "----------\n" + + "2. ERROR in test\\Test447695.java (at line 21)\n" + + " x2.i += 1; // error 2 expected\n" + + " ^^\n" + + "Null pointer access: The variable x2 can only be null at this location\n" + + "----------\n" + + "3. ERROR in test\\Test447695.java (at line 22)\n" + + " (x3).i = 1; // error 3 expected\n" + + " ^^^^\n" + + "Null pointer access: The variable x3 can only be null at this location\n" + + "----------\n" + + "4. ERROR in test\\Test447695.java (at line 23)\n" + + " (x4).i += 1; // error 4 expected\n" + + " ^^^^\n" + + "Null pointer access: The variable x4 can only be null at this location\n" + + "----------\n" + + "5. ERROR in test\\Test447695.java (at line 26)\n" + + " int i1 = x9.i; // error 5 expected\n" + + " ^^\n" + + "Null pointer access: The variable x9 can only be null at this location\n" + + "----------\n" + + "6. ERROR in test\\Test447695.java (at line 27)\n" + + " int i2 = (x10).i; // error 6 expected\n" + + " ^^^^^\n" + + "Null pointer access: The variable x10 can only be null at this location\n" + + "----------\n" + ); +} +public void testBug509188() { + runConformTest( + new String[] { + "test/Bug509188.java", + "package test;\n" + + "\n" + + "public class Bug509188 {\n" + + " public static class QuinamidCell {\n" + + " public QuinamidCell next;\n" + + " }\n" + + "\n" + + " public static void drawBoardElements() {\n" + + " Object _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z,\n" + + " _a1, _b1, _c1, _d1, _e1, _f1, _g1, _h1, _i1, _j1, _k1, _l1, _m1, _n1, _o1, _p1, _q1, _r1, _s1, _t1, _u1,\n" + + " _v1, _w1, _x1, _y1, _z_1, _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2;\n" + + "\n" + + " QuinamidCell hitCell = null;\n" + + "\n" + + " int level = 0; while (level < 1) {\n" + + " for (QuinamidCell c = new QuinamidCell(); c != null; c = c.next) {\n" + + " hitCell = c;\n" + + " } level++;\n" + + " }\n" + + " if (hitCell != null) {\n" + + " System.out.println(\"not dead\");\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " drawBoardElements();\n" + + " }\n" + + "}\n" + + "", + }, + "not dead" + ); +} +public void testBug536408() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; // uses auto unboxing + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Long s1 = null;\n" + + " long t = 0;\n" + + " t += s1;\n" + + " Long s2 = t > 0 ? 1l : null;\n" + + " t += s2;\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " t += s1;\n" + + " ^^\n" + + "Null pointer access: This expression of type Long is null but requires auto-unboxing\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " t += s2;\n" + + " ^^\n" + + "Potential null pointer access: This expression of type Long may be null but requires auto-unboxing\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +public void testBug542707_1() { + if (!checkPreviewAllowed()) return; // switch expression + Runner runner = new Runner(); + runner.customOptions = new HashMap<>(); + runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + runner.customOptions.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE); + runner.testFiles = new String[] { + "X.java", + "public class X {\n" + + " void test(int i) {\n" + + " String s = switch (i) {\n" + + " case 1 -> \"one\";\n" + + " default -> null;\n" + + " };\n" + + " System.out.println(s.toLowerCase());\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(s.toLowerCase());\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"; + runner.runNegativeTest(); +} +public void testBug544872() { + runNegativeNullTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static void f(String string) {\n" + + " if (string != null)\n" + + " string.hashCode();\n" + + " synchronized (string) {\n" + + " string.hashCode();\n" + + " }\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. ERROR in Test.java (at line 5)\n" + + " synchronized (string) {\n" + + " ^^^^^^\n" + + "Potential null pointer access: The variable string may be null at this location\n" + + "----------\n" + ); +} +public void testBug551012() { + runNegativeNullTest( + new String[] { + "NullConstants.java", + "public class NullConstants {\n" + + " protected static final String FOO = null;\n" + + "\n" + + " protected String foo = FOO;\n" + + "\n" + + " protected static final String BAR = \"\";\n" + + "\n" + + " protected String bar = BAR;\n" + + "\n" + + " public boolean notAProblemButWhyNot() {\n" + + " return FOO == null ? foo != null : !FOO.equals(foo);\n" + + " }\n" + + "\n" + + " public boolean alsoNotAProblemButThisWillAlwaysNPE() {\n" + + " return FOO != null ? foo != null : !FOO.equals(foo);\n" + + " }\n" + + "\n" + + " public boolean aProblemButHowToAvoid() {\n" + + " return BAR == null ? bar != null : !BAR.equals(bar);\n" + + " }\n" + + "\n" + + " public boolean wrongpProblemMessage() {\n" + + " return BAR != null ? !BAR.equals(bar) : bar != null;\n" + + " }\n" + + "\n" + + " public boolean howAboutThis() {\n" + + " return bar == null ? BAR != null : bar.equals(BAR);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in NullConstants.java (at line 19)\n" + + " return BAR == null ? bar != null : !BAR.equals(bar);\n" + + " ^^^\n" + + "Null comparison always yields false: The field BAR is a nonnull constant\n" + + "----------\n" + + "2. ERROR in NullConstants.java (at line 23)\n" + + " return BAR != null ? !BAR.equals(bar) : bar != null;\n" + + " ^^^\n" + + "Redundant null check: The field BAR is a nonnull constant\n" + + "----------\n" + + "3. ERROR in NullConstants.java (at line 27)\n" + + " return bar == null ? BAR != null : bar.equals(BAR);\n" + + " ^^^\n" + + "Redundant null check: The field BAR is a nonnull constant\n" + + "----------\n"); +} +public void testBug561280() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses generics + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import java.util.List;\n" + + "import java.util.Set;\n" + + "\n" + + "public class Test\n" + + "{\n" + + " protected static final String ERROR_TYPE = \"error\";\n" + + " protected static final String OBJECT_TYPE = \"object\";\n" + + " protected static final String UNKNOWN_FEATURE_TYPE = \"unknownFeature\";\n" + + " protected static final String DOCUMENT_ROOT_TYPE = \"documentRoot\";\n" + + "\n" + + " protected final static String TYPE_ATTRIB = \"\";\n" + + " protected final static String NIL_ATTRIB = \"\";\n" + + " protected final static String SCHEMA_LOCATION_ATTRIB = \"\";\n" + + " protected final static String NO_NAMESPACE_SCHEMA_LOCATION_ATTRIB = \"\";\n" + + "\n" + + " protected final static boolean DEBUG_DEMANDED_PACKAGES = false;\n" + + "\n" + + "\n" + + " protected Object xmlResource;\n" + + " protected Object helper;\n" + + " protected Object elements;\n" + + " protected Object objects;\n" + + " protected Object types;\n" + + " protected Object mixedTargets;\n" + + " protected Object prefixesToFactories;\n" + + " protected Object urisToLocations;\n" + + " protected Object externalURIToLocations;\n" + + " protected boolean processSchemaLocations;\n" + + " protected Object extent;\n" + + " protected Object deferredExtent;\n" + + " protected Object resourceSet;\n" + + " protected Object packageRegistry;\n" + + " protected Object resourceURI;\n" + + " protected boolean resolve;\n" + + " protected boolean oldStyleProxyURIs;\n" + + " protected boolean disableNotify;\n" + + " protected StringBuffer text;\n" + + " protected boolean isIDREF;\n" + + " protected boolean isSimpleFeature;\n" + + " protected Object sameDocumentProxies;\n" + + " protected Object[] identifiers;\n" + + " protected int[] positions;\n" + + " protected static final int ARRAY_SIZE = 64;\n" + + " protected static final int REFERENCE_THRESHOLD = 5;\n" + + " protected int capacity;\n" + + " protected Set notFeatures;\n" + + " protected String idAttribute;\n" + + " protected String hrefAttribute;\n" + + " protected Object xmlMap;\n" + + " protected Object extendedMetaData;\n" + + " protected Object anyType;\n" + + " protected Object anySimpleType;\n" + + " protected boolean recordUnknownFeature;\n" + + " protected boolean useNewMethods;\n" + + " protected boolean recordAnyTypeNSDecls;\n" + + " protected Object eObjectToExtensionMap;\n" + + " protected Object contextFeature;\n" + + " protected Object xmlSchemaTypePackage = null;\n" + + " protected boolean deferIDREFResolution;\n" + + " protected boolean processAnyXML;\n" + + " protected Object ecoreBuilder;\n" + + " protected boolean isRoot;\n" + + " protected Object locator;\n" + + " protected Object attribs;\n" + + " protected boolean useConfigurationCache;\n" + + " protected boolean needsPushContext;\n" + + " protected Object resourceEntityHandler;\n" + + " protected Object uriHandler;\n" + + " protected Object documentRoot;\n" + + " protected boolean usedNullNamespacePackage;\n" + + " protected boolean isNamespaceAware;\n" + + " protected boolean suppressDocumentRoot;\n" + + " protected boolean laxWildcardProcessing;\n" + + "\n" + + " protected static void processObjectx(Object object)\n" + + " {\n" + + " if (object instanceof List)\n" + + " {\n" + + " List list = ((List)object);\n" + + " list.size();\n" + + " }\n" + + "\n" + + " if (object != null)\n" + + " {\n" + + " object.hashCode();\n" + + " }\n" + + " else\n" + + " {\n" + + " System.err.println(\"#\");\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTestAsserts.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTestAsserts.java new file mode 100644 index 0000000000..79c282c546 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTestAsserts.java @@ -0,0 +1,1381 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * bug 382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions + * Bug 454031 - [compiler][null][loop] bug in null analysis; wrong "dead code" detection + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +/* See also NullReferenceTests for general null reference tests */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class NullReferenceTestAsserts extends AbstractRegressionTest { + +// class libraries including org.eclipse.equinox.common +String[] assertLib = null; +public NullReferenceTestAsserts(String name) { + super(name); +} + +// Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which does not belong to the class are skipped... +// 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[] { "testBug382069" }; +// TESTS_NUMBERS = new int[] { 561 }; +// TESTS_RANGE = new int[] { 1, 2049 }; +} + +static final String JUNIT_ASSERT_NAME = "junit/framework/Assert.java"; +static final String JUNIT_ASSERT_CONTENT = "package junit.framework;\n" + + "public class Assert {\n" + + " static public void assertNull(Object object) {}\n" + + " static public void assertNull(String message, Object object) {}\n" + + " static public void assertNotNull(Object object) {}\n" + + " static public void assertNotNull(String message, Object object) {}\n" + + " static public void assertTrue(boolean expression) {}\n" + + " static public void assertTrue(String message, boolean expression) {}\n" + + " static public void assertFalse(boolean expression) {}\n" + + " static public void assertFalse(String message, boolean expression) {}\n" + + "}\n"; + +static final String ORG_JUNIT_ASSERT_NAME = "org/junit/Assert.java"; +static final String ORG_JUNIT_ASSERT_CONTENT = "package org.junit;\n" + + "public class Assert {\n" + + " static public void assertNull(Object object) {}\n" + + " static public void assertNull(String message, Object object) {}\n" + + " static public void assertNotNull(Object object) {}\n" + + " static public void assertNotNull(String message, Object object) {}\n" + + " static public void assertTrue(boolean expression) {}\n" + + " static public void assertTrue(String message, boolean expression) {}\n" + + " static public void assertFalse(boolean expression) {}\n" + + " static public void assertFalse(String message, boolean expression) {}\n" + + "}\n"; +static final String ORG_JUNIT_JUPITER_API_ASSERTIONS_NAME = "org/junit/jupiter/api/Assertions.java"; +static final String ORG_JUNIT_JUPITER_API_ASSERTIONS_CONTENT = "package org.junit.jupiter.api;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.function.BooleanSupplier;\n" + + "public class Assertions {\n" + + " static public void assertNull(Object object) {}\n" + + " static public void assertNull(Object object, String message) {}\n" + + " static public void assertNull(Object object, Supplier messageSupplier) {}\n" + + " static public void assertNotNull(Object object) {}\n" + + " static public void assertNotNull(Object object, String message) {}\n" + + " static public void assertNotNull(Object object, Supplier messageSupplier) {}\n" + + " static public void assertTrue(boolean expression) {}\n" + + " static public void assertTrue(boolean expression, String message) {}\n" + + " static public void assertTrue(boolean expression, Supplier messageSupplier) {}\n" + + " static public void assertTrue(BooleanSupplier booleanSupplier) {}\n" + + " static public void assertTrue(BooleanSupplier booleanSupplier, String message) {}\n" + + " static public void assertTrue(BooleanSupplier booleanSupplier, Supplier messageSupplier) {}\n" + + " static public void assertFalse(boolean expression) {}\n" + + " static public void assertFalse(boolean expression, String message) {}\n" + + " static public void assertFalse(boolean expression, Supplier messageSupplier) {}\n" + + " static public void assertFalse(BooleanSupplier booleanSupplier) {}\n" + + " static public void assertFalse(BooleanSupplier booleanSupplier, String message) {}\n" + + " static public void assertFalse(BooleanSupplier booleanSupplier, Supplier messageSupplier) {}\n" + + "}\n"; + +static final String APACHE_VALIDATE_NAME = "org/apache/commons/lang/Validate.java"; +static final String APACHE_VALIDATE_CONTENT = "package org.apache.commons.lang;\n" + + "public class Validate {\n" + + " static public void notNull(Object object) {}\n" + + " static public void notNull(Object object, String message) {}\n" + + " static public void isTrue(boolean expression) {}\n" + + " static public void isTrue(boolean expression, String message) {}\n" + + " static public void isTrue(boolean expression, String message, double value) {}\n" + + " static public void isTrue(boolean expression, String message, long value) {}\n" + + " static public void isTrue(boolean expression, String message, Object value) {}\n" + + "}\n"; + +static final String APACHE_3_VALIDATE_NAME = "org/apache/commons/lang3/Validate.java"; +static final String APACHE_3_VALIDATE_CONTENT = "package org.apache.commons.lang3;\n" + + "public class Validate {\n" + + " static public T notNull(T object) { return object; }\n" + + " static public T notNull(T object, String message, Object... values) { return object; }\n" + + " static public void isTrue(boolean expression) {}\n" + + " static public void isTrue(boolean expression, String message, double value) {}\n" + + " static public void isTrue(boolean expression, String message, long value) {}\n" + + " static public void isTrue(boolean expression, String message, Object value) {}\n" + + "}\n"; + +static final String GOOGLE_PRECONDITIONS_NAME = "com/google/common/base/Preconditions.java"; +static final String GOOGLE_PRECONDITIONS_CONTENT = "package com.google.common.base;\n" + + "public class Preconditions {\n" + + " static public T checkNotNull(T object) { return object; }\n" + + " static public T checkNotNull(T object, Object message) { return object; }\n" + + " static public T checkNotNull(T object, String message, Object... values) { return object; }\n" + + " static public void checkArgument(boolean expression) {}\n" + + " static public void checkArgument(boolean expression, Object message) {}\n" + + " static public void checkArgument(boolean expression, String msgTmpl, Object... messageArgs) {}\n" + + " static public void checkState(boolean expression) {}\n" + + " static public void checkState(boolean expression, Object message) {}\n" + + " static public void checkState(boolean expression, String msgTmpl, Object... messageArgs) {}\n" + + "}\n"; + +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public static Class testClass() { + return NullReferenceTestAsserts.class; +} + +@Override +protected void setUp() throws Exception { + super.setUp(); + if (this.assertLib == null) { + String[] defaultLibs = getDefaultClassPaths(); + int len = defaultLibs.length; + this.assertLib = new String[len+1]; + System.arraycopy(defaultLibs, 0, this.assertLib, 0, len); + File bundleFile = FileLocator.getBundleFile(Platform.getBundle("org.eclipse.equinox.common")); + if (bundleFile.isDirectory()) + this.assertLib[len] = bundleFile.getPath()+"/bin"; + else + this.assertLib[len] = bundleFile.getPath(); + } +} + +// Conditionally augment problem detection settings +static boolean setNullRelatedOptions = true; +@Override +protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + if (setNullRelatedOptions) { + defaultOptions.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.ERROR); + defaultOptions.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.ERROR); + defaultOptions.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.ERROR); + defaultOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_IncludeNullInfoFromAsserts, CompilerOptions.ENABLED); + } + return defaultOptions; +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +public void testBug127575a() throws IOException { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " boolean b = o != null;\n" + // sheds doubts upon o + " org.eclipse.core.runtime.Assert.isLegal(o != null);\n" + // protection + " o.toString();\n" + // quiet + " }\n" + + "}\n"}, + "", + this.assertLib, + true, + null); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +public void testBug127575b() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " org.eclipse.core.runtime.Assert.isLegal(o == null);\n" + // forces null + " o.toString();\n" + // can only be null + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Null pointer access: The variable o can only be null at this location\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +public void testBug127575c() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o, boolean b) {\n" + + " org.eclipse.core.runtime.Assert.isLegal(o != null || b, \"FAIL\");\n" + // shed doubts + " o.toString();\n" + // complain + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +public void testBug127575d() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1, Object o2) {\n" + + " org.eclipse.core.runtime.Assert.isLegal(o1 != null && o2 == null);\n" + + " if (o1 == null) { };\n" + // complain + " if (o2 == null) { };\n" + // complain + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o1 == null) { };\n" + + " ^^\n" + + "Null comparison always yields false: The variable o1 cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o1 == null) { };\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " if (o2 == null) { };\n" + + " ^^\n" + + "Redundant null check: The variable o2 can only be null at this location\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +public void testBug127575e() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " org.eclipse.core.runtime.Assert.isLegal(false && o != null);\n" + + " if (o == null) { };\n" + // quiet + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " org.eclipse.core.runtime.Assert.isLegal(false && o != null);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runConformTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +public void testBug127575e_1() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " o = null;\n" + + " org.eclipse.core.runtime.Assert.isLegal(false && o != null);\n" + + " if (o == null) { };\n" + // warn on o because o was null above. + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " org.eclipse.core.runtime.Assert.isLegal(false && o != null);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " if (o == null) { };\n" + + " ^\n" + + "Redundant null check: The variable o can only be null at this location\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +public void testBug127575e_2() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " org.eclipse.core.runtime.Assert.isLegal(true || o != null);\n" + + " if (o == null) { };\n" + // quiet + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " org.eclipse.core.runtime.Assert.isLegal(true || o != null);\n" + + " ^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runConformTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +public void testBug127575f() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " org.eclipse.core.runtime.Assert.isLegal(false || o != null);\n" + + " if (o == null) { };\n" + // complain + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (o == null) { };\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " if (o == null) { };\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +// do warn always false comparisons even inside org.eclipse.core.runtime.Assert.isLegal +public void testBug127575g() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " Object o = null;\n" + + " org.eclipse.core.runtime.Assert.isLegal(o != null);\n" + // don't complain + " if (o == null) { };\n" + // complain + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " org.eclipse.core.runtime.Assert.isLegal(o != null);\n" + + " ^\n" + + "Null comparison always yields false: The variable o can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " if (o == null) { };\n" + + " ^\n" + + "Null comparison always yields false: The variable o cannot be null at this location\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " if (o == null) { };\n" + + " ^^^\n" + + "Dead code\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +// Test to verify that asserts are exempted from redundant null check warnings, +// but this doesn't affect the downstream info. +public void testBug127575h() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " X foo = new X();\n" + + " org.eclipse.core.runtime.Assert.isLegal (foo != null);\n" + // redundant check - don't warn + " if (foo == null) {}\n" + + " X foo2 = new X();\n" + + " org.eclipse.core.runtime.Assert.isLegal (foo2 == null);\n" + // always false check - warn + " if (foo2 == null) {}\n" + + " X bar = null;\n" + + " org.eclipse.core.runtime.Assert.isLegal (bar == null);\n" + // redundant check - don't warn + " if (bar == null) {}\n" + + " X bar2 = null;\n" + + " org.eclipse.core.runtime.Assert.isLegal (bar2 != null);\n" + // always false check - warn + " if (bar2 == null) {}\n" + + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (foo == null) {}\n" + + " ^^^\n" + + "Null comparison always yields false: The variable foo cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " if (foo == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " org.eclipse.core.runtime.Assert.isLegal (foo2 == null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable foo2 cannot be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " if (foo2 == null) {}\n" + + " ^^^^\n" + + "Redundant null check: The variable foo2 can only be null at this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 11)\n" + + " if (bar == null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable bar can only be null at this location\n" + + "----------\n" + + "6. ERROR in X.java (at line 13)\n" + + " org.eclipse.core.runtime.Assert.isLegal (bar2 != null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 can only be null at this location\n" + + "----------\n" + + "7. ERROR in X.java (at line 14)\n" + + " if (bar2 == null) {}\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + + "----------\n" + + "8. WARNING in X.java (at line 14)\n" + + " if (bar2 == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +// Test to verify that asserts are exempted from redundant null check warnings, +// but this doesn't affect the downstream info. +public void testBug127575i() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " X bar = null;\n" + + " X foo = getX();\n" + + " if (foo == null) {\n" + + " foo = new X();\n" + + " }\n" + + " org.eclipse.core.runtime.Assert.isTrue (foo != null && bar == null);\n" + // don't warn but do the null analysis + " if (foo != null) {}\n" + // warn + " if (bar == null) {}\n" + // warn + " }\n" + + " public X getX() { return new X();}\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (foo != null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable foo cannot be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " if (bar == null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable bar can only be null at this location\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +// Test to verify that asserts are exempted from redundant null check warnings in a looping context, +// but this doesn't affect the downstream info. +public void testBug127575j() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " X foo = new X();\n" + + " X foo2 = new X();\n" + + " X bar = null;\n" + + " X bar2 = null;\n" + + " while (true) {\n" + + " org.eclipse.core.runtime.Assert.isLegal (foo != null);\n" + //don't warn + " if (foo == null) {}\n" + + " org.eclipse.core.runtime.Assert.isLegal (foo2 == null);\n" + //don't warn + " if (foo2 == null) {}\n" + + " org.eclipse.core.runtime.Assert.isLegal (bar == null);\n" + //don't warn + " if (bar == null) {}\n" + + " org.eclipse.core.runtime.Assert.isLegal (bar2 != null);\n" + //don't warn + " if (bar2 == null) {}\n" + + " }\n" + + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " if (foo == null) {}\n" + + " ^^^\n" + + "Null comparison always yields false: The variable foo cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " if (foo == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " org.eclipse.core.runtime.Assert.isLegal (foo2 == null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable foo2 cannot be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " if (foo2 == null) {}\n" + + " ^^^^\n" + + "Redundant null check: The variable foo2 can only be null at this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " if (bar == null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable bar can only be null at this location\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " org.eclipse.core.runtime.Assert.isLegal (bar2 != null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 can only be null at this location\n" + + "----------\n" + + "7. ERROR in X.java (at line 15)\n" + + " if (bar2 == null) {}\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + + "----------\n" + + "8. WARNING in X.java (at line 15)\n" + + " if (bar2 == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +// Test to verify that asserts are exempted from redundant null check warnings in a finally context, +// but this doesn't affect the downstream info. +public void testBug127575k() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " X foo = new X();\n" + + " X foo2 = new X();\n" + + " X bar = null;\n" + + " X bar2 = null;\n" + + " try {\n" + + " System.out.println(\"Inside try\");\n" + + " }\n" + + " finally {\n" + + " org.eclipse.core.runtime.Assert.isLegal (foo != null);\n" + //don't warn + " if (foo == null) {}\n" + + " org.eclipse.core.runtime.Assert.isLegal (foo2 == null);\n" + //don't warn + " if (foo2 == null) {}\n" + + " org.eclipse.core.runtime.Assert.isLegal (bar == null);\n" + //don't warn + " if (bar == null) {}\n" + + " org.eclipse.core.runtime.Assert.isLegal (bar2 != null);\n" + //don't warn + " if (bar2 == null) {}\n" + + " }\n" + + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " if (foo == null) {}\n" + + " ^^^\n" + + "Null comparison always yields false: The variable foo cannot be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " if (foo == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " org.eclipse.core.runtime.Assert.isLegal (foo2 == null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable foo2 cannot be null at this location\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " if (foo2 == null) {}\n" + + " ^^^^\n" + + "Redundant null check: The variable foo2 can only be null at this location\n" + + "----------\n" + + "5. ERROR in X.java (at line 16)\n" + + " if (bar == null) {}\n" + + " ^^^\n" + + "Redundant null check: The variable bar can only be null at this location\n" + + "----------\n" + + "6. ERROR in X.java (at line 17)\n" + + " org.eclipse.core.runtime.Assert.isLegal (bar2 != null);\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 can only be null at this location\n" + + "----------\n" + + "7. ERROR in X.java (at line 18)\n" + + " if (bar2 == null) {}\n" + + " ^^^^\n" + + "Null comparison always yields false: The variable bar2 cannot be null at this location\n" + + "----------\n" + + "8. WARNING in X.java (at line 18)\n" + + " if (bar2 == null) {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +// The condition of org.eclipse.core.runtime.Assert.isLegal is considered always true +// and alters the following analysis suitably. +public void testBug127575l() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Test.java", + "public class Test {\n" + + " void foo(Object a, Object b, Object c) {\n" + + " org.eclipse.core.runtime.Assert.isLegal( a == null);\n " + + " if (a!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " System.out.println(\"a is null\");\n" + + " }\n" + + " a = null;\n" + + " if (a== null) {}\n" + + " org.eclipse.core.runtime.Assert.isLegal(b != null);\n " + + " if (b!=null) {\n" + + " System.out.println(\"b is not null\");\n" + + " } else{\n" + + " System.out.println(\"b is null\");\n" + + " }\n" + + " org.eclipse.core.runtime.Assert.isLegal(c == null);\n" + + " if (c.equals(a)) {\n" + + " System.out.println(\"\");\n" + + " } else{\n" + + " System.out.println(\"\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args){\n" + + " Test test = new Test();\n" + + " test.foo(null,null, null);\n" + + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in Test.java (at line 4)\n" + + " if (a!=null) {\n" + + " ^\n" + + "Null comparison always yields false: The variable a can only be null at this location\n" + + "----------\n" + + "2. WARNING in Test.java (at line 4)\n" + + " if (a!=null) {\n" + + " System.out.println(\"a is not null\");\n" + + " } else{\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. ERROR in Test.java (at line 9)\n" + + " a = null;\n" + + " ^\n" + + "Redundant assignment: The variable a can only be null at this location\n" + + "----------\n" + + "4. ERROR in Test.java (at line 10)\n" + + " if (a== null) {}\n" + + " ^\n" + + "Redundant null check: The variable a can only be null at this location\n" + + "----------\n" + + "5. ERROR in Test.java (at line 12)\n" + + " if (b!=null) {\n" + + " ^\n" + + "Redundant null check: The variable b cannot be null at this location\n" + + "----------\n" + + "6. WARNING in Test.java (at line 14)\n" + + " } else{\n" + + " System.out.println(\"b is null\");\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "7. ERROR in Test.java (at line 18)\n" + + " if (c.equals(a)) {\n" + + " ^\n" + + "Null pointer access: The variable c can only be null at this location\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +// NPE warnings should be given inside org.eclipse.core.runtime.Assert.isLegal too +public void testBug127575m() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Info.java", + "public class Info {\n" + + " public void test(Info[] infos) {\n" + + " for (final Info info : infos) {\n " + + " if (info != null) {\n" + + " org.eclipse.core.runtime.Assert.isLegal( info.checkSomething());\n" + + " info.doSomething();\n" + + " }\n" + + " }\n" + + " for (final Info info : infos) {\n " + + " if (info == null) {\n" + + " org.eclipse.core.runtime.Assert.isLegal(info.checkSomething());\n" + // warn NPE + " info.doSomething();\n" + + " }\n" + + " }\n" + + " }\n" + + " void doSomething() {}\n" + + " boolean checkSomething() {return true;}\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in Info.java (at line 11)\n" + + " org.eclipse.core.runtime.Assert.isLegal(info.checkSomething());\n" + + " ^^^^\n" + + "Null pointer access: The variable info can only be null at this location\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +// always false comparison in Assert.isLegal in loop should be warned against +public void testBug127575n() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "DoWhileBug.java", + "public class DoWhileBug {\n" + + " void test(boolean b1) {\n" + + " Object o1 = null;\n" + + " Object o2 = null;\n" + + " do {\n" + + " if (b1)\n" + + " o1 = null;\n" + + " org.eclipse.core.runtime.Assert.isLegal (o1 != null);\n" + + " } while (true);\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in DoWhileBug.java (at line 7)\n" + + " o1 = null;\n" + + " ^^\n" + + "Redundant assignment: The variable o1 can only be null at this location\n" + + "----------\n" + + "2. ERROR in DoWhileBug.java (at line 8)\n" + + " org.eclipse.core.runtime.Assert.isLegal (o1 != null);\n" + + " ^^\n" + + "Null comparison always yields false: The variable o1 can only be null at this location\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127575 +// "redundant null check" in Assert.isLegal in loop should not be warned against +public void testBug127575o() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "DoWhileBug.java", + "public class DoWhileBug {\n" + + " void test(boolean b1) {\n" + + " Object o1 = null;\n" + + " Object o2 = null;\n" + + " do {\n" + + " if (b1)\n" + + " o1 = null;\n" + + " org.eclipse.core.runtime.Assert.isLegal ((o2 = o1) == null);\n" + + " } while (true);\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in DoWhileBug.java (at line 7)\n" + + " o1 = null;\n" + + " ^^\n" + + "Redundant assignment: The variable o1 can only be null at this location\n" + + "----------\n"; + runner.classLibraries = + this.assertLib; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=373953 +public void testBug373953() throws IOException { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o) {\n" + + " boolean b = o != null;\n" + // sheds doubts upon o + " java.eclipse.core.runtime.Assert.isLegal(o != null);\n" + // bogus Assert + " o.toString();\n" + // warn + " }\n" + + " void foo1(Object o) {\n" + + " boolean b = o != null;\n" + // sheds doubts upon o + " org.lang.core.runtime.Assert.isLegal(o != null);\n" + // bogus Assert + " o.toString();\n" + // warn + " }\n" + + "}\n", + "java.eclipse.core.runtime/Assert.java", + "package java.eclipse.core.runtime;\n" + + "public class Assert {\n" + + " public static void isLegal(boolean b) {\n" + + " }\n" + + "}\n", + "org.lang.core.runtime/Assert.java", + "package org.lang.core.runtime;\n" + + "public class Assert {\n" + + " public static void isLegal(boolean b) {\n" + + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " o.toString();\n" + + " ^\n" + + "Potential null pointer access: The variable o may be null at this location\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); + } +} + +// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions +// junit's assertNotNull +public void testBug382069a() throws IOException { + this.runConformTest( + new String[] { + JUNIT_ASSERT_NAME, + JUNIT_ASSERT_CONTENT, + "X.java", + "public class X {\n" + + " void foo(Object o1, String o2) {\n" + + " boolean b = o1 != null;\n" + // sheds doubts upon o1 + " junit.framework.Assert.assertNotNull(o1);\n" + // protection + " o1.toString();\n" + // quiet + " b = o2 != null;\n" + // sheds doubts upon o2 + " junit.framework.Assert.assertNotNull(\"msg\", o2);\n" + // protection + " o2.toString();\n" + // quiet + " }\n" + + "}\n"}, + ""); +} + +// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions +// org.eclipse.core.runtime.Assert.isNotNull +public void testBug382069b() { + if (RUN_JAVAC && this.complianceLevel < ClassFileConstants.JDK11) + return; // Assert has class file format JDK 11 + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object o1, String o2) {\n" + + " boolean b = o1 != null;\n" + // sheds doubts upon o1 + " org.eclipse.core.runtime.Assert.isNotNull(o1);\n" + // protection + " o1.toString();\n" + // quiet + " b = o2 != null;\n" + // sheds doubts upon o2 + " org.eclipse.core.runtime.Assert.isNotNull(o2, \"msg\");\n" + // protection + " o2.toString();\n" + // quiet + " }\n" + + "}" + }, + "", + this.assertLib, + true, + null); + } +} + +// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions +// junit's assertNull and dead code analysis +public void testBug382069c() throws IOException { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + JUNIT_ASSERT_NAME, + JUNIT_ASSERT_CONTENT, + "X.java", + "public class X {\n" + + " boolean foo(String o1, String o2) {\n" + + " junit.framework.Assert.assertNull(\"something's wrong\", o1);\n" + // establish nullness + " if (o2 == null)\n" + + " return o1 != null;\n" + + " junit.framework.Assert.assertNull(o2);\n" + // will always throw + " return false; // dead code\n" + + " }\n" + + " void bar(X x) {\n" + + " if (x == null) {\n" + + " junit.framework.Assert.assertNotNull(x);\n" + + " return; // dead code\n" + + " }\n" + + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return o1 != null;\n" + + " ^^\n" + + "Null comparison always yields false: The variable o1 can only be null at this location\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " return false; // dead code\n" + + " ^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " return; // dead code\n" + + " ^^^^^^^\n" + + "Dead code\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions +// various asserts from org.apache.commons.lang.Validate +public void testBug382069d() throws IOException { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + APACHE_VALIDATE_NAME, + APACHE_VALIDATE_CONTENT, + "X.java", + "import org.apache.commons.lang.Validate;\n" + + "public class X {\n" + + " void foo(Object o1, String o2, X x) {\n" + + " boolean b = o1 != null;\n" + // sheds doubts upon o1 + " Validate.notNull(o1);\n" + // protection + " o1.toString();\n" + // quiet + " b = o2 != null;\n" + // sheds doubts upon o2 + " Validate.notNull(o2, \"msg\");\n" + // protection + " o2.toString();\n" + // quiet + " Validate.isTrue(x == null, \"ups\", x);\n" + + " x.foo(null, null, null); // definite NPE\n" + + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " x.foo(null, null, null); // definite NPE\n" + + " ^\n" + + "Null pointer access: The variable x can only be null at this location\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions +// various asserts from org.apache.commons.lang3Validate +public void testBug382069e() throws IOException { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + APACHE_3_VALIDATE_NAME, + APACHE_3_VALIDATE_CONTENT, + "X.java", + "import org.apache.commons.lang3.Validate;\n" + + "public class X {\n" + + " void foo(Object o1, String o2, X x) {\n" + + " boolean b = o1 != null;\n" + // sheds doubts upon o1 + " Validate.notNull(o1);\n" + // protection + " o1.toString();\n" + // quiet + " b = o2 != null;\n" + // sheds doubts upon o2 + " Validate.notNull(o2, \"msg\");\n" + // protection + " o2.toString();\n" + // quiet + " Validate.isTrue(x == null, \"ups\", x);\n" + + " x.foo(null, null, null); // definite NPE\n" + + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " x.foo(null, null, null); // definite NPE\n" + + " ^\n" + + "Null pointer access: The variable x can only be null at this location\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); + } +} +// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions +// various asserts from com.google.common.base.Preconditions +public void testBug382069f() throws IOException { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + GOOGLE_PRECONDITIONS_NAME, + GOOGLE_PRECONDITIONS_CONTENT, + "X.java", + "import com.google.common.base.Preconditions;\n" + + "public class X {\n" + + " void foo(Object o1, String o2, X x) {\n" + + " boolean b = o1 != null;\n" + // sheds doubts upon o1 + " Preconditions.checkNotNull(o1);\n" + // protection + " o1.toString();\n" + // quiet + " b = o2 != null;\n" + // sheds doubts upon o2 + " Preconditions.checkNotNull(o2, \"msg {0}.{1}\", o1, o2);\n" + // protection + " o2.toString();\n" + // quiet + " Preconditions.checkArgument(x == null, \"ups\");\n" + + " x.foo(null, null, null); // definite NPE\n" + + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " x.foo(null, null, null); // definite NPE\n" + + " ^\n" + + "Null pointer access: The variable x can only be null at this location\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); + } +} +// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions +// java.util.Objects#requireNonNull +public void testBug382069g() throws IOException { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runConformTest( + new String[] { + "X.java", + "import static java.util.Objects.requireNonNull;\n" + + "public class X {\n" + + " void foo(Object o1, String o2, X x) {\n" + + " boolean b = o1 != null;\n" + // sheds doubts upon o1 + " requireNonNull(o1);\n" + // protection + " o1.toString();\n" + // quiet + " b = o2 != null;\n" + // sheds doubts upon o2 + " requireNonNull(o2, \"msg\");\n" + // protection + " o2.toString();\n" + // quiet + " }\n" + + "}\n"}, + ""); + } +} + +// https://bugs.eclipse.org/382069 - [null] Make the null analysis consider JUnit's assertNotNull similarly to assertions +// junit's assertTrue / assertFalse +public void testBug382069h() throws IOException { + this.runConformTest( + new String[] { + JUNIT_ASSERT_NAME, + JUNIT_ASSERT_CONTENT, + "X.java", + "public class X {\n" + + " void foo(Object o1, String o2) {\n" + + " boolean b = o1 != null;\n" + // sheds doubts upon o1 + " junit.framework.Assert.assertTrue(o1 != null);\n" + // protection + " o1.toString();\n" + // quiet + " b = o2 != null;\n" + // sheds doubts upon o2 + " junit.framework.Assert.assertFalse(\"msg\", o2 == null);\n" + // protection + " o2.toString();\n" + // quiet + " }\n" + + "}\n"}, + ""); +} +// Bug 401159 - [null] Respect org.junit.Assert for control flow +// various asserts from org.junit.Assert +public void testBug401159() throws IOException { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + ORG_JUNIT_ASSERT_NAME, + ORG_JUNIT_ASSERT_CONTENT, + "X.java", + "import org.junit.Assert;\n" + + "public class X {\n" + + " void foo(Object o1, String o2, X x) {\n" + + " boolean b = o1 != null;\n" + // sheds doubts upon o1 + " Assert.assertNotNull(o1);\n" + // protection + " o1.toString();\n" + // quiet + " b = o2 != null;\n" + // sheds doubts upon o2 + " Assert.assertNotNull(\"msg\", o2);\n" + // protection + " o2.toString();\n" + // quiet + " Assert.assertTrue(\"ups\", x == null);\n" + + " x.foo(null, null, null); // definite NPE\n" + + " }\n" + + "}\n"}; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " x.foo(null, null, null); // definite NPE\n" + + " ^\n" + + "Null pointer access: The variable x can only be null at this location\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; +} + +// https://bugs.eclipse.org/472618 - [compiler][null] assertNotNull vs. Assert.assertNotNull +// junit's assertNotNull +public void testBug472618() throws IOException { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses auto-unboxing + this.runConformTest( + new String[] { + JUNIT_ASSERT_NAME, + JUNIT_ASSERT_CONTENT, + "AssertionTest.java", + "import junit.framework.Assert;\n" + + "\n" + + "public class AssertionTest extends Assert\n" + + "{\n" + + " void test()\n" + + " {\n" + + " Long test = null;\n" + + "\n" + + " if(Boolean.TRUE)\n" + + " {\n" + + " test = 0L;\n" + + " }\n" + + "\n" + + " assertNotNull(test);\n" + + "\n" + + " test.longValue(); // <- potential null pointer access\n" + + " }\n" + + "}\n"}, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=568542 +// junit 5's assertNotNull +public void testBug568542a() throws IOException { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // uses Supplier + this.runConformTest( + new String[] { + ORG_JUNIT_JUPITER_API_ASSERTIONS_NAME, + ORG_JUNIT_JUPITER_API_ASSERTIONS_CONTENT, + "X.java", + "import static org.junit.jupiter.api.Assertions.assertNotNull;\n" + + "public class X {\n" + + " void test(Long test1, Long test2, Long test3) {\n" + + " boolean b = (test1 != null | test2 != null | test3 != null);\n" + + " assertNotNull(test1);\n" + + " test1.longValue();\n" + + " assertNotNull(test2, \"message\");\n" + + " test2.longValue();\n" + + " assertNotNull(test3, () -> \"message\");\n" + + " test3.longValue();\n" + + " }\n" + + "}\n"}, + ""); +} +// junit 5's assertNull +public void testBug568542b() throws IOException { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // uses Supplier + runNegativeTest( + new String[] { + ORG_JUNIT_JUPITER_API_ASSERTIONS_NAME, + ORG_JUNIT_JUPITER_API_ASSERTIONS_CONTENT, + "X.java", + "import static org.junit.jupiter.api.Assertions.assertNull;\n" + + "public class X {\n" + + " void test(Long test1, Long test2, Long test3) {\n" + + " boolean b = (test1 != null | test2 != null | test3 != null);\n" + + " assertNull(test1);\n" + + " test1.longValue();\n" + + " assertNull(test2, \"message\");\n" + + " test2.longValue();\n" + + " assertNull(test3, () -> \"message\");\n" + + " test3.longValue();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " test1.longValue();\n" + + " ^^^^^\n" + + "Null pointer access: The variable test1 can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " test2.longValue();\n" + + " ^^^^^\n" + + "Null pointer access: The variable test2 can only be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " test3.longValue();\n" + + " ^^^^^\n" + + "Null pointer access: The variable test3 can only be null at this location\n" + + "----------\n" + ); +} +// junit 5's assertTrue +public void testBug568542c() throws IOException { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // uses Supplier + this.runConformTest( + new String[] { + ORG_JUNIT_JUPITER_API_ASSERTIONS_NAME, + ORG_JUNIT_JUPITER_API_ASSERTIONS_CONTENT, + "X.java", + "import static org.junit.jupiter.api.Assertions.assertTrue;\n" + + "public class X {\n" + + " void test(Long test1, Long test2, Long test3) {\n" + + " boolean b = (test1 != null | test2 != null | test3 != null);\n" + + " assertTrue(test1 != null);\n" + + " test1.longValue();\n" + + " assertTrue(test2 != null, \"message\");\n" + + " test2.longValue();\n" + + " assertTrue(test3 != null, () -> \"message\");\n" + + " test3.longValue();\n" + + " }\n" + + "}\n"}, + ""); +} +// junit 5's assertFalse +public void testBug568542d() throws IOException { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // uses Supplier + runNegativeTest( + new String[] { + ORG_JUNIT_JUPITER_API_ASSERTIONS_NAME, + ORG_JUNIT_JUPITER_API_ASSERTIONS_CONTENT, + "X.java", + "import static org.junit.jupiter.api.Assertions.assertFalse;\n" + + "public class X {\n" + + " void test(Long test1, Long test2, Long test3) {\n" + + " boolean b = (test1 != null | test2 != null | test3 != null);\n" + + " assertFalse(test1 != null);\n" + + " test1.longValue();\n" + + " assertFalse(test2 != null, \"message\");\n" + + " test2.longValue();\n" + + " assertFalse(test3 != null, () -> \"message\");\n" + + " test3.longValue();\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " test1.longValue();\n" + + " ^^^^^\n" + + "Null pointer access: The variable test1 can only be null at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " test2.longValue();\n" + + " ^^^^^\n" + + "Null pointer access: The variable test2 can only be null at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " test3.longValue();\n" + + " ^^^^^\n" + + "Null pointer access: The variable test3 can only be null at this location\n" + + "----------\n" + ); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java new file mode 100644 index 0000000000..7a7ca53b9f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java @@ -0,0 +1,18263 @@ +/******************************************************************************* + * Copyright (c) 2012, 2021 GK Software AG and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + * IBM Corporation + * Till Brychcy - Contribution for + * Bug 467032 - TYPE_USE Null Annotations: IllegalStateException with annotated arrays of Enum when accessed via BinaryTypeBinding + * Bug 467482 - TYPE_USE null annotations: Incorrect "Redundant null check"-warning + * Bug 473713 - [1.8][null] Type mismatch: cannot convert from @NonNull A1 to @NonNull A1 + * Bug 467430 - TYPE_USE Null Annotations: Confusing error message with known null value + * Pierre-Yves B. - Contribution for + * Bug 559618 - No compiler warning for import from same package + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.Excuse; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class NullTypeAnnotationTest extends AbstractNullAnnotationTest { + + public NullTypeAnnotationTest(String name) { + super(name); + } + + // Static initializer to specify tests subset using TESTS_* static variables + // All specified tests which do not belong to the class are skipped... + static { +// TESTS_NAMES = new String[] { "testBug456497" }; +// TESTS_NUMBERS = new int[] { 561 }; +// TESTS_RANGE = new int[] { 1, 2049 }; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + + public static Class testClass() { + return NullTypeAnnotationTest.class; + } + + // a list with nullable elements is used + public void test_nonnull_list_elements_01() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " void foo(List<@Nullable Object> l) {\n" + + " System.out.print(l.get(0).toString()); // problem: retrieved element can be null\n" + + " l.add(null);\n" + + " }\n" + + " void bar(java.util.List<@Nullable Object> l) {\n" + + " System.out.print(l.get(1).toString()); // problem: retrieved element can be null\n" + + " l.add(null);\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.print(l.get(0).toString()); // problem: retrieved element can be null\n" + + " ^^^^^^^^\n" + + "Potential null pointer access: The method get(int) may return null\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " System.out.print(l.get(1).toString()); // problem: retrieved element can be null\n" + + " ^^^^^^^^\n" + + "Potential null pointer access: The method get(int) may return null\n" + + "----------\n"); + } + + // a list with nullable elements is used, custom annotations + public void test_nonnull_list_elements_01a() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError, + new String[] { + CUSTOM_NULLABLE_NAME, + CUSTOM_NULLABLE_CONTENT_JSR308, + CUSTOM_NONNULL_NAME, + CUSTOM_NONNULL_CONTENT_JSR308, + "X.java", + "import org.foo.*;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " void foo(List<@Nullable Object> l) {\n" + + " System.out.print(l.get(0).toString()); // problem: retrieved element can be null\n" + + " l.add(null);\n" + + " }\n" + + " void bar(java.util.List<@Nullable Object> l) {\n" + + " System.out.print(l.get(1).toString()); // problem: retrieved element can be null\n" + + " l.add(null);\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.print(l.get(0).toString()); // problem: retrieved element can be null\n" + + " ^^^^^^^^\n" + + "Potential null pointer access: The method get(int) may return null\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " System.out.print(l.get(1).toString()); // problem: retrieved element can be null\n" + + " ^^^^^^^^\n" + + "Potential null pointer access: The method get(int) may return null\n" + + "----------\n", + null, + true, /* shouldFlush*/ + customOptions); + } + + // a list with nullable elements is used, @Nullable is second annotation + public void test_nonnull_list_elements_02() { + runNegativeTestWithLibs( + new String[] { + "Dummy.java", + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({METHOD,PARAMETER,LOCAL_VARIABLE,TYPE_USE})\n" + + "public @interface Dummy {\n" + + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " void foo(List<@Dummy @Nullable Object> l) {\n" + + " System.out.print(l.get(0).toString()); // problem: retrieved element can be null\n" + + " l.add(null);\n" + + " }\n" + + " void bar(java.util.List<@Dummy @Nullable Object> l) {\n" + + " System.out.print(l.get(1).toString()); // problem: retrieved element can be null\n" + + " l.add(null);\n" + + " }\n" + + " void bar2(java.util.List l2) {\n" + + " System.out.print(l2.get(1).toString()); // problem: retrieved element can be null\n" + + " l2.add(null);\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.print(l.get(0).toString()); // problem: retrieved element can be null\n" + + " ^^^^^^^^\n" + + "Potential null pointer access: The method get(int) may return null\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " System.out.print(l.get(1).toString()); // problem: retrieved element can be null\n" + + " ^^^^^^^^\n" + + "Potential null pointer access: The method get(int) may return null\n" + + "----------\n" + + "3. ERROR in X.java (at line 13)\n" + + " System.out.print(l2.get(1).toString()); // problem: retrieved element can be null\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: The method get(int) may return null\n" + + "----------\n"); + } + + // a list with non-null elements is used, list itself is nullable + public void test_nonnull_list_elements_03() { + runNegativeTestWithLibs( + new String[] { + "Dummy.java", + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({METHOD,PARAMETER,LOCAL_VARIABLE,TYPE_USE})\n" + + "public @interface Dummy {\n" + + "}\n", + "p/List.java", + "package p;\n" + + "public interface List {\n" + + " T get(int i);\n" + // avoid IProblem.NonNullTypeVariableFromLegacyMethod against unannotated j.u.List + " void add(T e);\n" + + " void add(int i, T e);\n" + + "}\n", + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import p.List;\n" + + "public class X {\n" + + " void foo(@Nullable List<@NonNull Object> l) {\n" + + " System.out.print(l.get(0).toString()); // problem: l may be null\n" + + " l.add(null); // problem: cannot insert 'null' into this list\n" + + " }\n" + + " void bar(@Nullable List l) {\n" + + " System.out.print(l.get(0).toString()); // problem: l may be null\n" + + " l.add(0, null); // problem: cannot insert 'null' into this list\n" + + " }\n" + + " void bar2(@Dummy p.@Nullable List l2) {\n" + + " System.out.print(l2.get(0).toString()); // problem: l2 may be null\n" + + " l2.add(0, null); // problem: cannot insert 'null' into this list\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.print(l.get(0).toString()); // problem: l may be null\n" + + " ^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " l.add(null); // problem: cannot insert \'null\' into this list\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " System.out.print(l.get(0).toString()); // problem: l may be null\n" + + " ^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " l.add(0, null); // problem: cannot insert \'null\' into this list\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "5. ERROR in X.java (at line 13)\n" + + " System.out.print(l2.get(0).toString()); // problem: l2 may be null\n" + + " ^^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " l2.add(0, null); // problem: cannot insert \'null\' into this list\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); + } + + // an outer and inner class both have a type parameter, + // client instantiates with nullable/nonnull actual type arguments + public void test_nestedType_01() { + runNegativeTestWithLibs( + new String[] { + "A.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class A {\n" + + " public class I {\n" + + " X anX;\n" + + " public X foo(Y l) {\n" + + " return anX;\n" + + " }\n" + + " public I(X x) {\n" + + " anX = x;\n" + + " }\n" + + " }\n" + + " void bar(A<@Nullable Object>.I<@NonNull Object> i) {\n" + // legal instantiation + " @NonNull Object o = i.foo(null); // problems: argument and assignment violate null contracts\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in A.java (at line 13)\n" + + " @NonNull Object o = i.foo(null); // problems: argument and assignment violate null contracts\n" + + " ^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required '@NonNull Object' but this expression has type '@Nullable Object'\n" + + "----------\n" + + "2. ERROR in A.java (at line 13)\n" + + " @NonNull Object o = i.foo(null); // problems: argument and assignment violate null contracts\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n"); + } + + // an outer and inner class both have a type parameter, + // a subclass instantiates with nullable/nonnull actual type arguments + // and correctly implements an abstract inherited method + // compile errors only inside that method + public void test_nestedType_02() { + runNegativeTestWithLibs( + new String[] { + "A.java", + "public class A {\n" + + " public abstract class I {\n" + + " public abstract X foo(Y l);\n" + + " public X idX(X in) { return in; }\n" + + " public Y idY(Y in) { return in; }\n" + + " }\n" + + "}\n", + "B.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class B extends A<@NonNull Object> {\n" + + " public class J extends I<@Nullable String> {\n" + + " @Override\n" + + " public @NonNull Object foo(@Nullable String l) {\n" + + " System.out.print(idX(null));\n" + + " return idY(null);\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in B.java (at line 6)\n" + + " System.out.print(idX(null));\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in B.java (at line 7)\n" + + " return idY(null);\n" + + " ^^^^^^^^^\n" + + "Null type mismatch (type annotations): required '@NonNull Object' but this expression has type '@Nullable String'\n" + + "----------\n"); + } + + // an outer and inner class both have a type parameter, + // a subclass instantiates with nullable/nonnull actual type arguments + // and incorrectly implements an abstract inherited method + public void test_nestedType_03() { + runNegativeTestWithLibs( + new String[] { + "A.java", + "public class A {\n" + + " public abstract class I {\n" + + " public abstract X foo(Y l);\n" + + " }\n" + + "}\n", + "B.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class B extends A<@NonNull Object> {\n" + + " public class J extends I<@Nullable String> {\n" + + " @Override\n" + + " public @Nullable Object foo(@NonNull String l) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in B.java (at line 5)\n" + + " public @Nullable Object foo(@NonNull String l) {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with '@NonNull Object' returned from A.I.foo(String) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in B.java (at line 5)\n" + + " public @Nullable Object foo(@NonNull String l) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter l, inherited method from A.I declares this parameter as @Nullable\n" + + "----------\n"); + } + + // a reference to a nested type has annotations for both types + public void test_nestedType_04() { + runNegativeTestWithLibs( + new String[] { + "A.java", + "public class A {\n" + + " public abstract class I {\n" + + " public abstract X foo(Y l);\n" + + " }\n" + + "}\n", + "B.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class B {\n" + + " public void foo(A.@Nullable I<@NonNull String> ai) {\n" + + " ai.foo(null); // problems: ai can be null, arg must not be null\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in B.java (at line 4)\n" + + " ai.foo(null); // problems: ai can be null, arg must not be null\n" + + " ^^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in B.java (at line 4)\n" + + " ai.foo(null); // problems: ai can be null, arg must not be null\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); + } + + // a reference to a nested type has annotations for both types, mismatch in detail of outer + public void test_nestedType_05() { + runNegativeTestWithLibs( + new String[] { + "A.java", + "public class A {\n" + + " public abstract class I {\n" + + " public abstract X foo(Y l);\n" + + " }\n" + + "}\n", + "B.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class B {\n" + + " public void foo(A<@NonNull Object>.@Nullable I<@NonNull String> ai1) {\n" + + " A<@Nullable Object>.@Nullable I<@NonNull String> ai2 = ai1;\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in B.java (at line 4)\n" + + " A<@Nullable Object>.@Nullable I<@NonNull String> ai2 = ai1;\n" + + " ^^^\n" + + "Null type mismatch (type annotations): required \'A<@Nullable Object>.@Nullable I<@NonNull String>\' but this expression has type \'A<@NonNull Object>.@Nullable I<@NonNull String>\'\n" + + "----------\n"); + } + + public void testMissingAnnotationTypes_01() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public class U {}\n" + + " @Missing1 X.@Missing2 U fU;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @Missing1 X.@Missing2 U fU;\n" + + " ^^^^^^^^\n" + + "Missing1 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " @Missing1 X.@Missing2 U fU;\n" + + " ^^^^^^^^\n" + + "Missing2 cannot be resolved to a type\n" + + "----------\n", + this.LIBS, + true/*shouldFlush*/); + } + + // bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types + // annotation on leaf type in 1-dim array + public void testArrayType_01() { + runNegativeTestWithLibs( + new String[] { + "Wrapper.java", + "public class Wrapper {\n" + + " T content;" + + " public Wrapper(T t) { content = t; }\n" + + " public T content() { return content; }\n" + + "}\n", + "A.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class A {\n" + +// Using Wrapper is a workaround until bug 391331 is fixed (to force the interesting annotation to be consumed as a type annotation): + " void bar(Wrapper<@NonNull String[]> realStrings, Wrapper<@Nullable String[]> maybeStrings) {\n" + + " System.out.println(realStrings.content()[0].toUpperCase()); // no problem\n" + + " realStrings.content()[0] = null; // problem: cannot assign null as @NonNull element\n" + + " System.out.println(maybeStrings.content()[0].toUpperCase()); // problem: element can be null\n" + + " maybeStrings.content()[0] = null; // no problem\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in A.java (at line 5)\n" + + " realStrings.content()[0] = null; // problem: cannot assign null as @NonNull element\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in A.java (at line 6)\n" + + " System.out.println(maybeStrings.content()[0].toUpperCase()); // problem: element can be null\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: array element may be null\n" + + "----------\n"); + } + + // bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types + // annotation on leaf type in 2-dim array + public void testArrayType_02() { + runNegativeTestWithLibs( + new String[] { + "Wrapper.java", + "public class Wrapper {\n" + + " T content;" + + " public Wrapper(T t) { content = t; }\n" + + " public T content() { return content; }\n" + + "}\n", + "A.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class A {\n" + +// Using Wrapper is a workaround until bug 391331 is fixed (to force the interesting annotation to be consumed as a type annotation): + " void bar(Wrapper<@NonNull String[][]> realStrings, Wrapper<@Nullable String[][]> maybeStrings) {\n" + + " System.out.println(realStrings.content()[0][0].toUpperCase()); // no problem\n" + + " realStrings.content()[0][0] = null; // problem: cannot assign null as @NonNull element\n" + + " System.out.println(maybeStrings.content()[0][0].toUpperCase()); // problem: element can be null\n" + + " maybeStrings.content()[0][0] = null; // no problem\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in A.java (at line 5)\n" + + " realStrings.content()[0][0] = null; // problem: cannot assign null as @NonNull element\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in A.java (at line 6)\n" + + " System.out.println(maybeStrings.content()[0][0].toUpperCase()); // problem: element can be null\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: array element may be null\n" + + "----------\n"); + } + + // bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types + // annotation on array type (1-dim array) + public void testArrayType_03() { + runNegativeTestWithLibs( + new String[] { + "A.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class A {\n" + + " void array(String @NonNull[] realStringArray, String @Nullable[] maybeStringArray) {\n" + + " @NonNull Object array;\n" + + " array = realStringArray; // no problem\n" + + " realStringArray = null; // problem: cannot assign null as @NonNull array\n" + + " array = maybeStringArray; // problem: array can be null\n" + + " maybeStringArray = null; // no problem\n" + + " }\n" + + " void leaf(String @NonNull[] realStringArray, String @Nullable[] maybeStringArray, boolean b) {\n" + + " @NonNull String string;\n" + + " string = realStringArray[0]; // problem: unchecked conversion\n" + + " realStringArray[0] = null; // no problem\n" + + " if (b)\n" + + " string = maybeStringArray[0]; // problems: indexing nullable array & unchecked conversion\n" + + " else\n" + + " maybeStringArray[0] = null; // problem: indexing nullable array\n" + + " maybeStringArray[0] = null; // problem protected by previous dereference\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in A.java (at line 6)\n" + + " realStringArray = null; // problem: cannot assign null as @NonNull array\n" + + " ^^^^\n" + + "Null type mismatch: required \'String @NonNull[]\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in A.java (at line 7)\n" + + " array = maybeStringArray; // problem: array can be null\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required '@NonNull Object' but this expression has type 'String @Nullable[]'\n" + + "----------\n" + + "3. WARNING in A.java (at line 12)\n" + + " string = realStringArray[0]; // problem: unchecked conversion\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type 'String' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n" + + "4. ERROR in A.java (at line 15)\n" + + " string = maybeStringArray[0]; // problems: indexing nullable array & unchecked conversion\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n" + + "5. WARNING in A.java (at line 15)\n" + + " string = maybeStringArray[0]; // problems: indexing nullable array & unchecked conversion\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type 'String' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n" + + "6. ERROR in A.java (at line 17)\n" + + " maybeStringArray[0] = null; // problem: indexing nullable array\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n"); + } + + // bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types + // annotation on intermediate type in 2-dim array + public void testArrayType_04() { + runNegativeTestWithLibs( + new String[] { + "A.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class A {\n" + + " void outer(String [] @NonNull[] realArrays, String [] @Nullable[] maybeArrays) {\n" + + " @NonNull Object array;\n" + + " array = realArrays; // problem: unchecked conversion\n" + + " realArrays = null; // no problem, outer array is unspecified\n" + + " array = maybeArrays; // problem: unchecked conversion\n" + + " maybeArrays = null; // no problem\n" + + " }\n" + + " void inner(String [] @NonNull[] realArrays, String [] @Nullable[] maybeArrays) {\n" + + " @NonNull Object array;\n" + + " array = realArrays[0]; // no problem\n" + + " realArrays[0] = null; // problem: cannot assign null to @NonNull array\n" + + " array = maybeArrays[0]; // problem: element can be null\n" + + " maybeArrays[0] = null; // no problem\n" + + " }\n" + + " void leaf(String [] @NonNull[] realArrays, String [] @Nullable[] maybeArrays) {\n" + + " @NonNull Object array;\n" + + " array = realArrays[0][0]; // problem: unchecked conversion\n" + + " realArrays[0][0] = null; // no problem, element type is unspecified\n" + + " array = maybeArrays[0][0]; // problems: indexing nullable array & unchecked conversion\n" + + " maybeArrays[0][0] = null; // problem: indexing nullable array\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. WARNING in A.java (at line 5)\n" + + " array = realArrays; // problem: unchecked conversion\n" + + " ^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String [] @NonNull[]\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n" + + "2. WARNING in A.java (at line 7)\n" + + " array = maybeArrays; // problem: unchecked conversion\n" + + " ^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String [] @Nullable[]\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n" + + "3. ERROR in A.java (at line 13)\n" + + " realArrays[0] = null; // problem: cannot assign null to @NonNull array\n" + + " ^^^^\n" + + "Null type mismatch: required \'String @NonNull[]\' but the provided value is null\n" + + "----------\n" + + "4. ERROR in A.java (at line 14)\n" + + " array = maybeArrays[0]; // problem: element can be null\n" + + " ^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'String @Nullable[]\'\n" + + "----------\n" + + "5. WARNING in A.java (at line 19)\n" + + " array = realArrays[0][0]; // problem: unchecked conversion\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n" + + "6. ERROR in A.java (at line 21)\n" + + " array = maybeArrays[0][0]; // problems: indexing nullable array & unchecked conversion\n" + + " ^^^^^^^^^^^^^^\n" + + "Potential null pointer access: array element may be null\n" + + "----------\n" + + "7. WARNING in A.java (at line 21)\n" + + " array = maybeArrays[0][0]; // problems: indexing nullable array & unchecked conversion\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n" + + "8. ERROR in A.java (at line 22)\n" + + " maybeArrays[0][0] = null; // problem: indexing nullable array\n" + + " ^^^^^^^^^^^^^^\n" + + "Potential null pointer access: array element may be null\n" + + "----------\n"); + } + + // bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types + // mismatches against outer array type, test display of type annotation in error messages + public void testArrayType_05() { + runNegativeTestWithLibs( + new String[] { + "A.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class A {\n" + + " void outer(String @NonNull[] @NonNull[] realArrays, String @NonNull[] @Nullable[] maybeArrays, String @Nullable[][] unknownArrays) {\n" + + " realArrays[0] = maybeArrays[0]; // problem: inner array can be null\n" + + " realArrays[0] = unknownArrays[0]; // problems: inner array is unspecified, outer can be null\n" + + " }\n" + + " void oneDim(String @Nullable[] maybeStrings, String[] unknownStrings) {\n" + + " String @NonNull[] s = maybeStrings;\n" + + " s = unknownStrings;\n" + + " consume(maybeStrings);\n" + + " consume(unknownStrings);\n" + + " }\n" + + " void consume(String @NonNull[] s) {};\n" + + "}\n"}, + "----------\n" + + "1. ERROR in A.java (at line 4)\n" + + " realArrays[0] = maybeArrays[0]; // problem: inner array can be null\n" + + " ^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'String @NonNull[]\' but this expression has type \'String @Nullable[]\'\n" + + "----------\n" + + "2. ERROR in A.java (at line 5)\n" + + " realArrays[0] = unknownArrays[0]; // problems: inner array is unspecified, outer can be null\n" + + " ^^^^^^^^^^^^^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n" + + "3. WARNING in A.java (at line 5)\n" + + " realArrays[0] = unknownArrays[0]; // problems: inner array is unspecified, outer can be null\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'String @NonNull[]\'\n" + + "----------\n" + + "4. ERROR in A.java (at line 8)\n" + + " String @NonNull[] s = maybeStrings;\n" + + " ^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'String @NonNull[]\' but this expression has type \'String @Nullable[]\'\n" + + "----------\n" + + "5. WARNING in A.java (at line 9)\n" + + " s = unknownStrings;\n" + + " ^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'String @NonNull[]\'\n" + + "----------\n" + + "6. ERROR in A.java (at line 10)\n" + + " consume(maybeStrings);\n" + + " ^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'String @NonNull[]\' but this expression has type \'String @Nullable[]\'\n" + + "----------\n" + + "7. WARNING in A.java (at line 11)\n" + + " consume(unknownStrings);\n" + + " ^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'String @NonNull[]\'\n" + + "----------\n"); + } + + // bug 392862 - [1.8][compiler][null] Evaluate null annotations on array types + // more compiler messages + public void testArrayType_10() { + runNegativeTestWithLibs( + new String[] { + "A.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class A {\n" + + " void outer(String @NonNull[] @NonNull[] realArrays, String @NonNull[] @Nullable[] maybeArrays, String @Nullable[][] unknownArrays, String @NonNull[][] mixedArrays) {\n" + + " realArrays = maybeArrays; // problem on inner dimension!\n" + + " realArrays = unknownArrays; // problems on both dimensions\n" + + " maybeArrays = realArrays; // problem on inner dimension\n" + + " unknownArrays = maybeArrays; // no problem: outer @NonNull is compatible to expected @Nullable, inner @Nullable is compatible to inner unspecified\n" + + " realArrays = mixedArrays; // problem on inner\n" + + " maybeArrays = mixedArrays; // problem on inner\n" + + " consume(maybeArrays, mixedArrays, maybeArrays);\n" + + " }\n" + + " void consume(String @NonNull[] @NonNull[] realStrings, String @NonNull[] @Nullable[] maybeArrays, String @Nullable[][] unknownArrays) {\n" + + " }\n" + + "}\n"}, + "----------\n" + + "1. ERROR in A.java (at line 4)\n" + + " realArrays = maybeArrays; // problem on inner dimension!\n" + + " ^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'String @NonNull[] @NonNull[]\' but this expression has type \'String @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "2. ERROR in A.java (at line 5)\n" + + " realArrays = unknownArrays; // problems on both dimensions\n" + + " ^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'String @NonNull[] @NonNull[]\' but this expression has type \'String @Nullable[] []\'\n" + + "----------\n" + + "3. ERROR in A.java (at line 6)\n" + + " maybeArrays = realArrays; // problem on inner dimension\n" + + " ^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'String @NonNull[] @Nullable[]\' but this expression has type \'String @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "4. WARNING in A.java (at line 8)\n" + + " realArrays = mixedArrays; // problem on inner\n" + + " ^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String @NonNull[] []\' needs unchecked conversion to conform to \'String @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "5. WARNING in A.java (at line 9)\n" + + " maybeArrays = mixedArrays; // problem on inner\n" + + " ^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String @NonNull[] []\' needs unchecked conversion to conform to \'String @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "6. ERROR in A.java (at line 10)\n" + + " consume(maybeArrays, mixedArrays, maybeArrays);\n" + + " ^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'String @NonNull[] @NonNull[]\' but this expression has type \'String @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "7. WARNING in A.java (at line 10)\n" + + " consume(maybeArrays, mixedArrays, maybeArrays);\n" + + " ^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String @NonNull[] []\' needs unchecked conversion to conform to \'String @NonNull[] @Nullable[]\'\n" + + "----------\n"); + } + + // combine flow info on outer type with annotation analysis for inners + public void testArrayType_11() { + runNegativeTestWithLibs( + new String[] { + "ArrayTest.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class ArrayTest {\n" + + " \n" + + " @NonNull Object @NonNull[] test1(@NonNull Object @Nullable[] in) {\n" + + " if (in == null) throw new NullPointerException(); \n" + + " return in; // array needs check, element is OK\n" + + " }\n" + + " @NonNull Object @NonNull[] test2(@Nullable Object @Nullable[] in) {\n" + + " if (in == null) throw new NullPointerException(); \n" + + " return in; // array needs check, element is NOK\n" + + " }\n" + + " @NonNull Object @NonNull[]@NonNull[] test3(@NonNull Object @Nullable[][] in) {\n" + + " if (in == null) throw new NullPointerException(); \n" + + " return in; // outer needs check, inner is unchecked, element is OK\n" + + " }\n" + + " @NonNull Object @NonNull[]@NonNull[] test4(@Nullable Object @Nullable[][] in) {\n" + + " if (in == null) throw new NullPointerException(); \n" + + " return in; // outer needs check, inner is unchecked, element is NOK\n" + + " }\n" + + " @NonNull Object @NonNull[]@NonNull[] test5(@NonNull Object @Nullable[]@Nullable[] in) {\n" + + " if (in == null) throw new NullPointerException(); \n" + + " return in; // outer needs check, inner is NOK, element is OK\n" + + " }\n" + + " @NonNull Object @NonNull[]@NonNull[] test6(@NonNull Object @Nullable[]@NonNull[] in) {\n" + + " if (in == null) throw new NullPointerException(); \n" + + " return in; // outer needs check, inner is OK, element is OK\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in ArrayTest.java (at line 11)\n" + + " return in; // array needs check, element is NOK\n" + + " ^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object @NonNull[]\' but this expression has type \'@Nullable Object @Nullable[]\'\n" + + "----------\n" + + "2. WARNING in ArrayTest.java (at line 15)\n" + + " return in; // outer needs check, inner is unchecked, element is OK\n" + + " ^^\n" + + "Null type safety (type annotations): The expression of type \'@NonNull Object @Nullable[] []\' needs unchecked conversion to conform to \'@NonNull Object @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "3. ERROR in ArrayTest.java (at line 19)\n" + + " return in; // outer needs check, inner is unchecked, element is NOK\n" + + " ^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object @NonNull[] @NonNull[]\' but this expression has type \'@Nullable Object @Nullable[] []\'\n" + + "----------\n" + + "4. ERROR in ArrayTest.java (at line 23)\n" + + " return in; // outer needs check, inner is NOK, element is OK\n" + + " ^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object @NonNull[] @NonNull[]\' but this expression has type \'@NonNull Object @Nullable[] @Nullable[]\'\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/403216 - [1.8][null] TypeReference#captureTypeAnnotations treats type annotations as type argument annotations + public void testBug403216_1() { + runConformTestWithLibs( + new String[] { + "Test.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "public class Test {}\n" + + "\n" + + "class X {\n" + + " class Y {\n" + + " public void foo( @A X. @B Y this) {}\n" + + " }\n" + + "}\n" + + "@Target(value={ElementType.TYPE_USE})\n" + + "@interface A {}\n" + + "@Target(value={ElementType.TYPE_USE})\n" + + "@interface B {}\n" + }, + null, + ""); + } + + // issue from https://bugs.eclipse.org/bugs/show_bug.cgi?id=403216#c7 + public void testBug403216_2() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " void test(List<@NonNull String> strings) {\n" + + " List someStrings;\n" + + " someStrings = strings;\n" + + " }\n" + + "}\n" + }, + options, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=403216#c9 + public void testBug403216_3a() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Test {}\n" + + "\n" + + "class X {\n" + + " class Y {\n" + + " public void foo( @A X. @NonNull Y this) {}\n" + + " }\n" + + "}\n" + + "@Target(value={ElementType.TYPE_USE})\n" + + "@interface A {}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Test.java (at line 9)\n" + + " public void foo( @A X. @NonNull Y this) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=403216#c9 + public void testBug403216_3b() { + runConformTestWithLibs( + new String[] { + "Test.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "public class Test {}\n" + + "\n" + + "class X {\n" + + " class Y {\n" + + " public void foo( @A X. @A Y this) {}\n" + + " }\n" + + "}\n" + + "@Target(value={ElementType.TYPE_USE})\n" + + "@interface A {}\n" + }, + getCompilerOptions(), + ""); + } + + // https://bugs.eclipse.org/403457 - [1.8][compiler] NPE in WildcardBinding.signature + public void testBug403457_1() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class X {\n" + + " void foo(Map<@Marker ? super @Marker Object, @Marker ? extends @Marker String> m){}\n" + + " void goo(Map<@Marker ? extends @Marker Object, @Marker ? super @Marker String> m){}\n" + + "}\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Marker {\n" + + " \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " void foo(Map<@Marker ? super @Marker Object, @Marker ? extends @Marker String> m){}\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " void goo(Map<@Marker ? extends @Marker Object, @Marker ? super @Marker String> m){}\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n", + this.LIBS, + true/*flush*/); + } + + // https://bugs.eclipse.org/403457 - [1.8][compiler] NPE in WildcardBinding.signature + // variant with null annotations + public void testBug403457_2() { + runNegativeTest( + new String[] { + "X.java", + "// import java.util.Map;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class X {\n" + + " void foo(Map<@Nullable ? super @Nullable Object, @Nullable ? extends @Nullable String> m){}\n" + + " void goo(Map<@Nullable ? extends @Nullable Object, @Nullable ? super @Nullable String> m){}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " void foo(Map<@Nullable ? super @Nullable Object, @Nullable ? extends @Nullable String> m){}\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " void goo(Map<@Nullable ? extends @Nullable Object, @Nullable ? super @Nullable String> m){}\n" + + " ^^^\n" + + "Map cannot be resolved to a type\n" + + "----------\n", + this.LIBS, + true/*flush*/); + } + + // storing and decoding null-type-annotations to/from classfile: RETURN_TYPE + public void testBinary01() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "p/X.java", + "package p;\n" + + "import java.util.List;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " public List<@Nullable String> getSomeStrings() { return null; }\n" + + "}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y.java", + "import p.X;\n" + + "public class Y {\n" + + " public void test(X x) {\n" + + " String s0 = x.getSomeStrings().get(0);\n" + + " System.out.println(s0.toUpperCase());\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y.java (at line 5)\n" + + " System.out.println(s0.toUpperCase());\n" + + " ^^\n" + + "Potential null pointer access: The variable s0 may be null at this location\n" + + "----------\n" + ); + } + + // storing and decoding null-type-annotations to/from classfile: METHOD_FORMAL_PARAMETER & METHOD_RECEIVER + // Note: receiver annotation is not evaluated by the compiler, this part of the test only serves debugging purposes. + public void testBinary02() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "p/X.java", + "package p;\n" + + "import java.util.List;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(TYPE_USE)\n" + + "@interface Immutable {}\n" + + "public class X {\n" + + " public void setAllStrings(@Immutable X this, int dummy, List<@NonNull String> ss) { }\n" + + "}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y.java", + "import p.X;\n" + + "import java.util.List;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " public void test(X x, List<@Nullable String> ss) {\n" + + " x.setAllStrings(-1, ss);\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y.java (at line 6)\n" + + " x.setAllStrings(-1, ss);\n" + + " ^^\n" + + "Null type mismatch (type annotations): required \'List<@NonNull String>\' but this expression has type \'List<@Nullable String>\'\n" + + "----------\n" + ); + } + + // storing and decoding null-type-annotations to/from classfile: FIELD + public void testBinary03() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public abstract class X1 {\n" + + " public static String @Nullable [] f1 = null;\n" + + " public static String [] @Nullable [] f2 = new String[] @Nullable[] { null };\n" + + "}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y1.java", + "import p.X1;\n" + + "public class Y1 {\n" + + " public void test() {\n" + + " System.out.println(p.X1.f1.length);\n" + + " System.out.println(X1.f2[0].length);\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 4)\n" + + " System.out.println(p.X1.f1.length);\n" + + " ^^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in Y1.java (at line 5)\n" + + " System.out.println(X1.f2[0].length);\n" + + " ^^^^^^^^\n" + + "Potential null pointer access: array element may be null\n" + + "----------\n" + ); + } + + // storing and decoding null-type-annotations to/from classfile: SUPER_TYPE + public void testBinary04() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@SuppressWarnings(\"serial\")\n" + + "public abstract class X1 extends ArrayList<@Nullable String> {\n" + + "}\n", + "p/X2.java", + "package p;\n" + + "import java.util.List;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public abstract class X2 implements List<@Nullable String> {\n" + + "}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y1.java", + "import p.X1;\n" + + "public class Y1 {\n" + + " public void test(X1 x) {\n" + + " String s0 = x.get(0);\n" + + " System.out.println(s0.toUpperCase());\n" + + " }\n" + + "}\n", + "Y2.java", + "import p.X2;\n" + + "public class Y2 {\n" + + " public void test(X2 x) {\n" + + " String s0 = x.get(0);\n" + + " System.out.println(s0.toUpperCase());\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 5)\n" + + " System.out.println(s0.toUpperCase());\n" + + " ^^\n" + + "Potential null pointer access: The variable s0 may be null at this location\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y2.java (at line 5)\n" + + " System.out.println(s0.toUpperCase());\n" + + " ^^\n" + + "Potential null pointer access: The variable s0 may be null at this location\n" + + "----------\n" + ); + } + + // storing and decoding null-type-annotations to/from classfile: CLASS_TYPE_PARAMETER & METHOD_TYPE_PARAMETER + public void testBinary05() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@SuppressWarnings(\"serial\")\n" + + "public abstract class X1<@NonNull T> extends ArrayList {\n" + + " public <@Nullable S> void foo(S s) {}\n" + + "}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y1.java", + "import p.X1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y1 {\n" + + " X1<@Nullable String> maybeStrings;\n" + // incompatible: T is constrained to @NonNull + " void test(X1<@NonNull String> x) {\n" + // OK + " x.<@NonNull Object>foo(new Object());\n" + // incompatible: S is constrained to @Nullable + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 4)\n" + + " X1<@Nullable String> maybeStrings;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable String\' is not a valid substitute for the type parameter \'@NonNull T extends Object\'\n" + + "----------\n" + + "2. ERROR in Y1.java (at line 6)\n" + + " x.<@NonNull Object>foo(new Object());\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull Object\' is not a valid substitute for the type parameter \'@Nullable S extends Object\'\n" + + "----------\n"); + } + + // storing and decoding null-type-annotations to/from classfile: CLASS_TYPE_PARAMETER_BOUND & METHOD_TYPE_PARAMETER_BOUND + public void testBinary06() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@SuppressWarnings(\"serial\")\n" + + "public abstract class X1 extends ArrayList {\n" + + " public void foo(U u, V v) {}\n" + + "}\n", + "p/X2.java", + "package p;\n"+ + "import org.eclipse.jdt.annotation.*;\n" + + "public class X2<@NonNull W extends @Nullable Object> {}\n" // incompatible constraints + }, + customOptions, + "----------\n" + + "1. ERROR in p\\X2.java (at line 3)\n" + + " public class X2<@NonNull W extends @Nullable Object> {}\n" + + " ^^^^^^^^^\n" + + "This nullness annotation conflicts with a \'@NonNull\' annotation which is effective on the same type parameter \n" + + "----------\n"); + // fix the bug: + runConformTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@SuppressWarnings(\"serial\")\n" + + "public abstract class X1 extends ArrayList {\n" + + " public void foo(U u, V v) {}\n" + + "}\n", + "p/X2.java", + "package p;\n"+ + "import org.eclipse.jdt.annotation.*;\n" + + "public class X2<@Nullable W extends Object> {}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y1.java", + "import p.X1;\n" + + "import p.X2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y1 {\n" + + " X1<@Nullable String> maybeStrings;\n" + // incompatible: T has a bound constrained to @NonNull + " X2<@NonNull String> strings;\n" + // incompatible: W is constrained to @Nullable + " void test(X1<@NonNull String> x) {\n" + // OK + " x.foo(this, new Object());\n" + // OK: 'extends @Nullable' is no restriction + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 5)\n" + + " X1<@Nullable String> maybeStrings;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable String\' is not a valid substitute for the type parameter \'T extends @NonNull Object\'\n" + + "----------\n" + + "2. ERROR in Y1.java (at line 6)\n" + + " X2<@NonNull String> strings;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable W extends Object\'\n" + + "----------\n" + ); + } + + // storing and decoding null-type-annotations to/from classfile: CLASS_TYPE_PARAMETER_BOUND & METHOD_TYPE_PARAMETER_BOUND + // variant: qualified type references + public void testBinary06b() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@SuppressWarnings(\"serial\")\n" + + "public abstract class X1 extends ArrayList {\n" + + " public void foo(U u, V v) {}\n" + + "}\n", + "p/X2.java", + "package p;\n"+ + "import org.eclipse.jdt.annotation.*;\n" + + "public class X2<@NonNull W extends java.lang.@Nullable Object> {}\n" // incompatible constraints + }, + customOptions, + "----------\n" + + "1. ERROR in p\\X2.java (at line 3)\n" + + " public class X2<@NonNull W extends java.lang.@Nullable Object> {}\n" + + " ^^^^^^^^^\n" + + "This nullness annotation conflicts with a \'@NonNull\' annotation which is effective on the same type parameter \n" + + "----------\n"); + // fix the bug: + runConformTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@SuppressWarnings(\"serial\")\n" + + "public abstract class X1 extends ArrayList {\n" + + " public void foo(U u, V v) {}\n" + + "}\n", + "p/X2.java", + "package p;\n"+ + "import org.eclipse.jdt.annotation.*;\n" + + "public class X2<@Nullable W extends Object> {}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y1.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y1 {\n" + + " p.X1 maybeStrings;\n" + // incompatible: T has a bound constrained to @NonNull + " p.X2 strings;\n" + // incompatible: W is constrained to @Nullable + " void test(p.X1 x) {\n" + // OK + " x.foo(this, new Object());\n" + // // OK: 'extends @Nullable' is no restriction + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 3)\n" + + " p.X1 maybeStrings;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable String\' is not a valid substitute for the type parameter \'T extends @NonNull Object\'\n" + + "----------\n" + + "2. ERROR in Y1.java (at line 4)\n" + + " p.X2 strings;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable W extends Object\'\n" + + "----------\n" + ); + } + + // storing and decoding null-type-annotations to/from classfile: method with all kinds of type annotations + public void testBinary07() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "p/List.java", + "package p;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public interface List {\n" + + " T get(int i);\n" + // avoid IProblem.NonNullTypeVariableFromLegacyMethod against unannotated j.u.List + "}\n", + "p/X1.java", + "package p;\n" + + "import java.util.Map;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(TYPE_USE)\n" + + "@interface Immutable {}\n" + + "public abstract class X1 {\n" + + " public <@NonNull U, V extends @Nullable Object> List<@NonNull Map> foo(@Immutable X1 this, U u, V v) { return null; }\n" + + "}\n" + }, + customOptions, + ""); + runNegativeTestWithLibs( + new String[] { + "Y1.java", + "import p.X1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y1 {\n" + + " void test(X1 x) {\n" + + " x.<@NonNull Y1, @NonNull Object>foo(this, new Object())\n" + // // OK: 'extends @Nullable' is no restriction + " .get(0).put(null, null);\n" + // second null is illegal + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 6)\n" + + " .get(0).put(null, null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); + } + + // storing and decoding null-type-annotations to/from classfile: details + public void testBinary08() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public abstract class X1 {\n" + + " public class Inner {}\n" + + " public Object []@NonNull[] arrays(Object @NonNull[][] oa1) { return null; }\n" + + " public void nesting(@NonNull Inner i1, X1.@Nullable Inner i2) { }\n" + + " public void wildcard1(List<@Nullable ? extends @NonNull X1> l) { } // contradiction\n" + + " public void wildcard2(List l) { }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p\\X1.java (at line 8)\n" + + " public void wildcard1(List<@Nullable ? extends @NonNull X1> l) { } // contradiction\n" + + " ^^^^^^^^\n" + + "This nullness annotation conflicts with a \'@Nullable\' annotation which is effective on the same type parameter \n" + + "----------\n"); + // fix the error: + runConformTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public abstract class X1 {\n" + + " public class Inner {}\n" + + " public Object []@NonNull[] arrays(Object @NonNull[][] oa1) { return null; }\n" + + " public void nesting(@NonNull Inner i1, X1.@Nullable Inner i2) { }\n" + + " public void wildcard1(List<@Nullable ? extends X1> l) { }\n" + + " public void wildcard2(List l) { }\n" + + "}\n" + }, + customOptions, + ""); + + runNegativeTestWithLibs( + new String[] { + "Y1.java", + "import p.X1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class Y1 {\n" + + " void test(X1 x) {\n" + + " Object @NonNull[][] a = new Object[0][]; // safe: new is never null\n" + + " x.arrays(a)[0] = null; // illegal\n" + + " x.nesting(null, null); // 1st null is illegal\n" + + " x.wildcard2(new ArrayList<@NonNull Object>());\n" + + " x.wildcard2(new ArrayList<@Nullable Object>()); // OK\n" + + " x.wildcard1(new ArrayList<@NonNull X1>()); // incompatible\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 7)\n" + + " x.arrays(a)[0] = null; // illegal\n" + + " ^^^^\n" + + "Null type mismatch: required \'Object @NonNull[]\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in Y1.java (at line 8)\n" + + " x.nesting(null, null); // 1st null is illegal\n" + + " ^^^^\n" + + "Null type mismatch: required \'X1.@NonNull Inner\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in Y1.java (at line 11)\n" + + " x.wildcard1(new ArrayList<@NonNull X1>()); // incompatible\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'List<@Nullable ? extends X1>\' but this expression has type \'@NonNull ArrayList<@NonNull X1>\', corresponding supertype is \'List<@NonNull X1>\'\n" + + "----------\n"); + } + + // storing and decoding null-type-annotations to/from classfile: details + // variant: qualified references + public void testBinary08b() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public abstract class X1 {\n" + + " public class Inner {}\n" + + " public java.lang.Object []@NonNull[] arrays(java.lang.Object @NonNull[][] oa1) { return null; }\n" + + " public void nesting(@NonNull Inner i1, X1.@Nullable Inner i2) { }\n" + + " public void wildcard1(java.util.List<@Nullable ? extends p.@NonNull X1> l) { } // contradiction\n" + + " public void wildcard2(java.util.List l) { }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in p\\X1.java (at line 7)\n" + + " public void wildcard1(java.util.List<@Nullable ? extends p.@NonNull X1> l) { } // contradiction\n" + + " ^^^^^^^^\n" + + "This nullness annotation conflicts with a \'@Nullable\' annotation which is effective on the same type parameter \n" + + "----------\n"); + // fix the error: + runConformTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public abstract class X1 {\n" + + " public class Inner {}\n" + + " public java.lang.Object []@NonNull[] arrays(java.lang.Object @NonNull[][] oa1) { return null; }\n" + + " public void nesting(@NonNull Inner i1, p.X1.@Nullable Inner i2) { }\n" + + " public void wildcard1(List<@Nullable ? extends p.X1> l) { }\n" + + " public void wildcard2(List l) { }\n" + + "}\n" + }, + customOptions, + ""); + + runNegativeTestWithLibs( + new String[] { + "Y1.java", + "import p.X1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class Y1 {\n" + + " void test(X1 x) {\n" + + " java.lang.Object @NonNull[][] a = new java.lang.Object[0][]; // safe: new is never null\n" + + " x.arrays(a)[0] = null; // illegal\n" + + " x.nesting(null, null); // 1st null is illegal\n" + + " x.wildcard2(new ArrayList());\n" + + " x.wildcard2(new ArrayList());\n" + + " x.wildcard1(new ArrayList()); // incompatible\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 7)\n" + + " x.arrays(a)[0] = null; // illegal\n" + + " ^^^^\n" + + "Null type mismatch: required \'Object @NonNull[]\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in Y1.java (at line 8)\n" + + " x.nesting(null, null); // 1st null is illegal\n" + + " ^^^^\n" + + "Null type mismatch: required \'X1.@NonNull Inner\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in Y1.java (at line 11)\n" + + " x.wildcard1(new ArrayList()); // incompatible\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'List<@Nullable ? extends X1>\' but this expression has type \'@NonNull ArrayList<@NonNull X1>\', corresponding supertype is \'List<@NonNull X1>\'\n" + + "----------\n"); + } + + // storing and decoding null-type-annotations to/from classfile: EXTENDED DIMENSIONS. + public void testBinary09() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public class X {\n" + + " @NonNull String @Nullable [] f @NonNull [] = null;\n" + + " static void foo(@NonNull String @Nullable [] p @NonNull []) {\n" + + " p = null;\n" + + " @NonNull String @Nullable [] l @NonNull [] = null;\n" + + " }\n" + + "}\n" + + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @NonNull String @Nullable [] f @NonNull [] = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String @NonNull[] @Nullable[]\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " p = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String @NonNull[] @Nullable[]\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " @NonNull String @Nullable [] l @NonNull [] = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String @NonNull[] @Nullable[]\' but the provided value is null\n" + + "----------\n"); + // fix the error: + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public class X {\n" + + " @NonNull String @Nullable [] f @NonNull [] = new @NonNull String @NonNull [0] @Nullable [];\n" + + "}\n" + }, + customOptions, + ""); + + runNegativeTestWithLibs( + new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " void test(X x) {\n" + + " x.f = null;\n" + + " x.f[0] = null;\n" + + " x.f[0][0] = null;\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. WARNING in Y.java (at line 1)\n" + + " import org.eclipse.jdt.annotation.*;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import org.eclipse.jdt.annotation is never used\n" + + "----------\n" + + "2. ERROR in Y.java (at line 4)\n" + + " x.f = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String @NonNull[] @Nullable[]\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in Y.java (at line 6)\n" + + " x.f[0][0] = null;\n" + + " ^^^^^^\n" + + "Potential null pointer access: array element may be null\n" + + "----------\n" + + "4. ERROR in Y.java (at line 6)\n" + + " x.f[0][0] = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); +} + + // storing and decoding null-type-annotations to/from classfile: array annotations. + public void testBinary10() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class X {\n" + + " void foo(ArrayList @NonNull [] p) {\n" + + " }\n" + + "}\n" + + "class Y extends X {\n" + + " void foo() {\n" + + " super.foo(null);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " super.foo(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'ArrayList @NonNull[]\' but the provided value is null\n" + + "----------\n"); + // fix the error: + runConformTestWithLibs( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class X {\n" + + " void foo(ArrayList @NonNull [] p) {\n" + + " }\n" + + "}\n" + }, + customOptions, + ""); + + runNegativeTestWithLibs( + new String[] { + "Y.java", + "public class Y extends X {\n" + + " void foo() {\n" + + " super.foo(null);\n" + + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " super.foo(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'ArrayList @NonNull[]\' but the provided value is null\n" + + "----------\n"); + } + + public void testConditional1() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " List<@NonNull String> foo(List<@NonNull String> good, List dubious, int f) {\n" + + " if (f < 2)\n" + + " return f == 0 ? good : dubious;\n" + + " if (f < 4)\n" + + " return f == 2 ? dubious : good;\n" + + " if (f < 6)\n" + + " return f == 4 ? good : good;\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " return f == 0 ? good : dubious;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@NonNull String>\'\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " return f == 2 ? dubious : good;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@NonNull String>\'\n" + + "----------\n"); + } + + public void testConditional2() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " List<@NonNull String> foo(List<@NonNull String> good, ArrayList dubious, int f) {\n" + + " if (f < 2)\n" + + " return f == 0 ? good : dubious;\n" + + " if (f < 4)\n" + + " return f == 2 ? dubious : good;\n" + + " if (f < 6)\n" + + " return f == 4 ? good : good;\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " return f == 0 ? good : dubious;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'ArrayList\' needs unchecked conversion to conform to \'List<@NonNull String>\', corresponding supertype is 'List'\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " return f == 2 ? dubious : good;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'ArrayList\' needs unchecked conversion to conform to \'List<@NonNull String>\', corresponding supertype is 'List'\n" + + "----------\n"); + } + + // conditional in argument position + public void testConditional3() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " void foo(List<@NonNull String> good, List dubious, int f) {\n" + + " consume(f == 0 ? good : dubious);\n" + + " consume(f == 2 ? dubious : good);\n" + + " consume(f == 4 ? good : good);\n" + + " }\n" + + " void consume(List<@NonNull String> strings) {}\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " consume(f == 0 ? good : dubious);\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@NonNull String>\'\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " consume(f == 2 ? dubious : good);\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@NonNull String>\'\n" + + "----------\n"); + } + + // types with null annotations on details (type parameter) are compatible to equal types + public void testCompatibility1() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " List<@NonNull String> return1(List<@NonNull String> noNulls) {\n" + + " return noNulls;\n" + + " }\n" + + " List<@Nullable String> return2(List<@Nullable String> withNulls) {\n" + + " return withNulls;\n" + + " }\n" + + " void assigns(List<@NonNull String> noNulls, List dubious, List<@Nullable String> withNulls) {\n" + + " List<@NonNull String> l1 = noNulls;\n" + + " List<@Nullable String> l2 = withNulls;\n" + + " List l3 = dubious;\n" + + " }\n" + + " void arguments(List<@NonNull String> noNulls, List dubious, List<@Nullable String> withNulls) {\n" + + " assigns(noNulls, dubious, withNulls);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + } + + // types with null annotations on details (array content) are compatible to equal types + public void testCompatibility1a() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull String[] return1(@NonNull String[] noNulls) {\n" + + " return noNulls;\n" + + " }\n" + + " @Nullable String[] return2(@Nullable String[] noNulls) {\n" + + " return noNulls;\n" + + " }\n" + + " void assigns(@NonNull String[] noNulls, String dubious[], @Nullable String[] withNulls) {\n" + + " @NonNull String[] l1 = noNulls;\n" + + " @Nullable String[] l2 = withNulls;\n" + + " String[] l3 = dubious;\n" + + " }\n" + + " void arguments(@NonNull String[] noNulls, String[] dubious, @Nullable String[] withNulls) {\n" + + " assigns(noNulls, dubious, withNulls);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + } + + // types with null annotations on details (type parameter) are compatible to types lacking the annotation + public void testCompatibility2() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " List return1(List<@NonNull String> noNulls) {\n" + + " return noNulls;\n" + + " }\n" + + " List return2(List dubious) {\n" + + " return dubious;\n" + + " }\n" + + " List return3(List<@Nullable String> withNulls) {\n" + + " return withNulls;\n" + + " }\n" + + " void assigns(List<@NonNull String> noNulls, List dubious, List<@Nullable String> withNulls) {\n" + + " List l1 = noNulls;\n" + + " List l2 = dubious;\n" + + " List l3 = withNulls;\n" + + " }\n" + + " void arguments(List<@NonNull String> noNulls, List dubious, List<@Nullable String> withNulls) {\n" + + " takeAny(noNulls);\n" + + " takeAny(dubious);\n" + + " takeAny(withNulls);\n" + + " }\n" + + " void takeAny(List any) {}\n" + + "}\n" + }, + options, + ""); + } + + // types with null annotations on details (array content) are compatible to types lacking the annotation + public void testCompatibility2a() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " String[] return1(@NonNull String[] noNulls) {\n" + + " return noNulls;\n" + + " }\n" + + " String[] return2(String[] dubious) {\n" + + " return dubious;\n" + + " }\n" + + " String[] return3(@Nullable String[] withNulls) {\n" + + " return withNulls;\n" + + " }\n" + + " void assigns(@NonNull String[] noNulls, String[] dubious, @Nullable String[] withNulls) {\n" + + " String[] l1 = noNulls;\n" + + " String[] l2 = dubious;\n" + + " String[] l3 = withNulls;\n" + + " }\n" + + " void arguments(@NonNull String[] noNulls, String[] dubious, @Nullable String[] withNulls) {\n" + + " takeAny(noNulls);\n" + + " takeAny(dubious);\n" + + " takeAny(withNulls);\n" + + " }\n" + + " void takeAny(String[] any) {}\n" + + "}\n" + }, + getCompilerOptions(), + ""); + } + + // types without null annotations are converted (unsafe) to types with detail annotations (type parameter) + public void testCompatibility3() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " List<@NonNull String> return1(List dubious) {\n" + + " return dubious;\n" + + " }\n" + + " List<@Nullable String> return2(List dubious) {\n" + + " return dubious;\n" + + " }\n" + + " void assigns(List dubious) {\n" + + " List<@Nullable String> l1 = dubious;\n" + + " List<@NonNull String> l2 = dubious;\n" + + " }\n" + + " void arguments(List dubious) {\n" + + " acceptNulls(dubious);\n" + + " acceptNoNulls(dubious);\n" + + " }\n" + + " void acceptNulls(List<@NonNull String> noNulls) {}\n" + + " void acceptNoNulls(List<@NonNull String> noNulls) {}\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " return dubious;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@NonNull String>\'\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " return dubious;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@Nullable String>\'\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " List<@Nullable String> l1 = dubious;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@Nullable String>\'\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " List<@NonNull String> l2 = dubious;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@NonNull String>\'\n" + + "----------\n" + + "5. WARNING in X.java (at line 15)\n" + + " acceptNulls(dubious);\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@NonNull String>\'\n" + + "----------\n" + + "6. WARNING in X.java (at line 16)\n" + + " acceptNoNulls(dubious);\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@NonNull String>\'\n" + + "----------\n"); + } + + // types without null annotations are converted (unsafe) to types with detail annotations (array content) + public void testCompatibility3a() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull String[] return1(String[] dubious) {\n" + + " return dubious;\n" + + " }\n" + + " @Nullable String[] return2(String[] dubious) {\n" + + " return dubious;\n" + + " }\n" + + " void assigns(String[] dubious) {\n" + + " @Nullable String[] l1 = dubious;\n" + + " @NonNull String[] l2 = dubious;\n" + + " }\n" + + " void arguments(String[] dubious) {\n" + + " acceptNulls(dubious);\n" + + " acceptNoNulls(dubious);\n" + + " }\n" + + " void acceptNulls(@Nullable String[] withNulls) {}\n" + + " void acceptNoNulls(@NonNull String[] noNulls) {}\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return dubious;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'@NonNull String []\'\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " return dubious;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'@Nullable String []\'\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " @Nullable String[] l1 = dubious;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'@Nullable String []\'\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " @NonNull String[] l2 = dubious;\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'@NonNull String []\'\n" + + "----------\n" + + "5. WARNING in X.java (at line 14)\n" + + " acceptNulls(dubious);\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'@Nullable String []\'\n" + + "----------\n" + + "6. WARNING in X.java (at line 15)\n" + + " acceptNoNulls(dubious);\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'@NonNull String []\'\n" + + "----------\n"); + } + + // types with null annotations on details (type parameter) are incompatible to opposite types + public void testCompatibility4() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " List<@Nullable String> return1(List<@NonNull String> noNulls) {\n" + + " return noNulls;\n" + + " }\n" + + " List<@NonNull String> return2(List<@Nullable String> withNulls) {\n" + + " return withNulls;\n" + + " }\n" + + " void assigns(List<@NonNull String> noNulls, List<@Nullable String> withNulls) {\n" + + " List<@NonNull String> l1 = withNulls;\n" + + " List<@Nullable String> l2 = noNulls;\n" + + " }\n" + + " void arguments(List<@NonNull String> noNulls, List<@Nullable String> withNulls) {\n" + + " assigns(withNulls, noNulls);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return noNulls;\n" + + " ^^^^^^^\n" + + "Null type mismatch (type annotations): required 'List<@Nullable String>' but this expression has type 'List<@NonNull String>'\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " return withNulls;\n" + + " ^^^^^^^^^\n" + + "Null type mismatch (type annotations): required 'List<@NonNull String>' but this expression has type 'List<@Nullable String>'\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " List<@NonNull String> l1 = withNulls;\n" + + " ^^^^^^^^^\n" + + "Null type mismatch (type annotations): required 'List<@NonNull String>' but this expression has type 'List<@Nullable String>'\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " List<@Nullable String> l2 = noNulls;\n" + + " ^^^^^^^\n" + + "Null type mismatch (type annotations): required 'List<@Nullable String>' but this expression has type 'List<@NonNull String>'\n" + + "----------\n" + + "5. ERROR in X.java (at line 15)\n" + + " assigns(withNulls, noNulls);\n" + + " ^^^^^^^^^\n" + + "Null type mismatch (type annotations): required 'List<@NonNull String>' but this expression has type 'List<@Nullable String>'\n" + + "----------\n" + + "6. ERROR in X.java (at line 15)\n" + + " assigns(withNulls, noNulls);\n" + + " ^^^^^^^\n" + + "Null type mismatch (type annotations): required 'List<@Nullable String>' but this expression has type 'List<@NonNull String>'\n" + + "----------\n"); + } + + // types with null annotations on details (array content) are incompatible to opposite types + public void testCompatibility4a() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @Nullable String[] return1(@NonNull String[] noNulls) {\n" + + " return noNulls;\n" + + " }\n" + + " @NonNull String[] return2(@Nullable String[] withNulls) {\n" + + " return withNulls;\n" + + " }\n" + + " void assigns(@NonNull String[] noNulls, @Nullable String[] withNulls) {\n" + + " @NonNull String[] l1 = withNulls;\n" + + " @Nullable String[] l2 = noNulls;\n" + + " }\n" + + " void arguments(@NonNull String[] noNulls, @Nullable String[] withNulls) {\n" + + " assigns(withNulls, noNulls);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " return noNulls;\n" + + " ^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@Nullable String []\' but this expression has type \'@NonNull String []\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " return withNulls;\n" + + " ^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String []\' but this expression has type \'@Nullable String []\'\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " @NonNull String[] l1 = withNulls;\n" + + " ^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String []\' but this expression has type \'@Nullable String []\'\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " @Nullable String[] l2 = noNulls;\n" + + " ^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@Nullable String []\' but this expression has type \'@NonNull String []\'\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " assigns(withNulls, noNulls);\n" + + " ^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String []\' but this expression has type \'@Nullable String []\'\n" + + "----------\n" + + "6. ERROR in X.java (at line 14)\n" + + " assigns(withNulls, noNulls);\n" + + " ^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@Nullable String []\' but this expression has type \'@NonNull String []\'\n" + + "----------\n"); + } + + // challenge parameterized type with partial substitution of super's type parameters + public void testCompatibility5() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "abstract public class X implements Map<@NonNull String,Y> {\n" + + " void foo(X x) {\n" + + " Map<@NonNull String, Object> m1 = x; // OK\n" + + " Map<@Nullable String, Object> m2 = x; // NOK\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Map<@Nullable String, Object> m2 = x; // NOK\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'Map<@Nullable String,Object>\' but this expression has type \'X\', corresponding supertype is \'Map<@NonNull String,Object>\'\n" + + "----------\n"); + } + + // challenge parameterized type with partial substitution of super's type parameters + public void testCompatibility6() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.Map;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "abstract public class X<@Nullable Y> implements Map<@Nullable String,Y> {\n" + + " void foo(X<@Nullable Object> x) {\n" + + " Map<@Nullable String, @Nullable Object> m1 = x; // OK\n" + + " Map<@Nullable String, @NonNull Object> m2 = x; // NOK\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Map<@Nullable String, @NonNull Object> m2 = x; // NOK\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'Map<@Nullable String,@NonNull Object>\' but this expression has type \'X<@Nullable Object>\', corresponding supertype is \'Map<@Nullable String,@Nullable Object>\'\n" + + "----------\n"); + } + + // illegal for type declaration + public void testUnsupportedLocation01() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public @NonNull class X {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public @NonNull class X {}\n" + + " ^^^^^^^^\n" + + "The nullness annotation \'NonNull\' is not applicable at this location\n" + + "----------\n"); + } + + // illegal for enclosing class (locations: field, argument, return type, local + public void testUnsupportedLocation02() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " class Inner {}\n" + + " @NonNull X.Inner f;\n" + + " @NonNull X.Inner foo(@NonNull X.Inner arg) {\n" + + " @NonNull X.Inner local = arg;\n" + + " return local;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @NonNull X.Inner f;\n" + + " ^^^^^^^^\n" + + "The nullness annotation \'NonNull\' is not applicable at this location, it must be placed directly before the nested type name.\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " @NonNull X.Inner foo(@NonNull X.Inner arg) {\n" + + " ^^^^^^^^\n" + + "The nullness annotation \'NonNull\' is not applicable at this location, it must be placed directly before the nested type name.\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " @NonNull X.Inner foo(@NonNull X.Inner arg) {\n" + + " ^^^^^^^^\n" + + "The nullness annotation \'NonNull\' is not applicable at this location, it must be placed directly before the nested type name.\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " @NonNull X.Inner local = arg;\n" + + " ^^^^^^^^\n" + + "The nullness annotation \'NonNull\' is not applicable at this location, it must be placed directly before the nested type name.\n" + + "----------\n"); + } + + // illegal / unchecked for cast & instanceof with scalar type + public void testUnsupportedLocation03() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull X foo(X arg) {\n" + + " if (!(arg instanceof @NonNull X))\n" + + " return (@NonNull X)arg;\n" + + " return arg;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (!(arg instanceof @NonNull X))\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type X is already an instance of type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " if (!(arg instanceof @NonNull X))\n" + + " ^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " return (@NonNull X)arg;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null type safety: Unchecked cast from X to @NonNull X\n" + + "----------\n"); + } + + // illegal / unchecked for cast & instanceof with complex type + public void testUnsupportedLocation04() { + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " List<@NonNull X> parameterized(List arg) {\n" + + " if (!(arg instanceof List<@NonNull X>))\n" + + " return (java.util.List<@NonNull X>)arg;\n" + + " return arg;\n" + + " }\n" + + " X @NonNull[] arrays(X[] arg) {\n" + + " if (!(arg instanceof X @NonNull[]))\n" + + " return (p.X @NonNull[])arg;\n" + + " return arg;\n" + + " }\n" + + " ArrayList<@NonNull String> foo(List<@NonNull String> l) {\n" + + " return (ArrayList<@NonNull String>) l;\n" + // OK + " }" + + " ArrayList<@NonNull String> foo2(List<@NonNull String> l) {\n" + + " return (ArrayList) l;\n" + // warn, TODO(stephan) with flow analysis (bug 415292) we might recover the original @NonNull... + " }" + + "}\n" + }, + ((this.complianceLevel >= ClassFileConstants.JDK16) ? + "----------\n" + + "1. WARNING in p\\X.java (at line 6)\n" + + " if (!(arg instanceof List<@NonNull X>))\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type List is already an instance of type List\n" + : + "----------\n" + + "1. ERROR in p\\X.java (at line 6)\n" + + " if (!(arg instanceof List<@NonNull X>))\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type List. Use the form List instead since further generic type information will be erased at runtime\n" + ) + + + "----------\n" + + "2. ERROR in p\\X.java (at line 6)\n" + + " if (!(arg instanceof List<@NonNull X>))\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n" + + "3. WARNING in p\\X.java (at line 7)\n" + + " return (java.util.List<@NonNull X>)arg;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety: Unchecked cast from List to List<@NonNull X>\n" + + "----------\n" + + "4. WARNING in p\\X.java (at line 11)\n" + + " if (!(arg instanceof X @NonNull[]))\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The expression of type X[] is already an instance of type X[]\n" + + "----------\n" + + "5. ERROR in p\\X.java (at line 11)\n" + + " if (!(arg instanceof X @NonNull[]))\n" + + " ^^^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n" + + "6. WARNING in p\\X.java (at line 12)\n" + + " return (p.X @NonNull[])arg;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety: Unchecked cast from X[] to X @NonNull[]\n" + + "----------\n" + + "7. WARNING in p\\X.java (at line 18)\n" + + " return (ArrayList) l;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'ArrayList\' needs unchecked conversion to conform to \'ArrayList<@NonNull String>\'\n" + + "----------\n", + this.LIBS, + true/*flush*/); + } + + // illegal instanceof check with annotated type argument + public void testUnsupportedLocation04a() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " boolean instanceOf2(Object o) {\n" + + " return o instanceof List<@Nullable ?>;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " return o instanceof List<@Nullable ?>;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n"); + } + + // illegal for allocation expression + public void testUnsupportedLocation05() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " X x = new @NonNull X();\n" + + " class Inner {}\n" + + " Inner i = this.new @Nullable Inner();\n" + + " java.util.List<@NonNull String> s = new java.util.ArrayList<@NonNull String>();\n" + // OK + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " X x = new @NonNull X();\n" + + " ^^^^^^^^\n" + + "The nullness annotation \'NonNull\' is not applicable at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Inner i = this.new @Nullable Inner();\n" + + " ^^^^^^^^^\n" + + "The nullness annotation \'Nullable\' is not applicable at this location\n" + + "----------\n"); + } + + // method receiver + public void testUnsupportedLocation06() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void receiver(@Nullable X this, Object o) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void receiver(@Nullable X this, Object o) {}\n" + + " ^^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n"); + } + + // receiver type in method/constructor reference + public void testUnsupportedLocation07() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.function.Supplier;\n" + + "public class X {\n" + + " void consume(Supplier c) {}\n" + + " static Object supply() { return null; }\n" + + " void consumeSupplied() {\n" + + " consume(@NonNull X::supply);\n" + + " consume(@NonNull X::new);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " consume(@NonNull X::supply);\n" + + " ^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " consume(@NonNull X::new);\n" + + " ^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n"); + } + + // exceptions (throws & catch) + public void testUnsupportedLocation08() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.io.*;\n" + + "public class X {\n" + + " void throwsDecl() throws @Nullable IOException {}\n" + + " void excParam() {\n" + + " try {\n" + + " throwsDecl();\n" + + " } catch (@NonNull IOException ioe) {}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " void throwsDecl() throws @Nullable IOException {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " } catch (@NonNull IOException ioe) {}\n" + + " ^^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n"); + } + + public void testForeach() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " void foo(List<@NonNull String> nns) {\n" + + " for(String s1 : nns) {\n" + + " logMsg(s1);\n" + + " }\n" + + " for(String s2 : getStrings()) {\n" + + " logMsg(s2);\n" + + " }\n" + + " }\n" + + " Collection<@Nullable String> getStrings() { return null; }\n" + + " void logMsg(@NonNull String msg) { }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " logMsg(s2);\n" + + " ^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is inferred as @Nullable\n" + + "----------\n"); + } + + // poly-null method + public void testNullTypeInference1() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportNonNullTypeVariableFromLegacyInvocation, CompilerOptions.IGNORE); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " List polyNullMethod(List in) { return in; }\n" + + " @NonNull String test1(List<@NonNull String> strings) {\n" + + " return polyNullMethod(strings).get(0);\n" + + " }\n" + + " @NonNull String test2(List<@Nullable String> strings) {\n" + + " return polyNullMethod(strings).get(0);\n" + + " }\n" + + " @Nullable String test3(List<@NonNull String> strings) {\n" + + " return polyNullMethod(strings).get(0);\n" + + " }\n" + + " @Nullable String test4(List<@Nullable String> strings) {\n" + + " return polyNullMethod(strings).get(0);\n" + + " }\n" + + "}\n" + }, + compilerOptions, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " return polyNullMethod(strings).get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n"); + } + + // functional interface with explicit nullness + public void testNullTypeInference2a() { + runNegativeTestWithLibs( + new String[] { + "PolyNull.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface NNFunc {\n" + + " @NonNull String a(@NonNull String i);\n" + + "}\n" + + "public class PolyNull {\n" + + " @NonNull String extract(NNFunc f, @NonNull String s) { return f.a(s); }\n" + + " @NonNull String testOK() {\n" + + " return extract(i -> i, \"hallo\");\n" + + " }\n" + + " @NonNull String testERR() {\n" + + " return extract(i -> null, \"hallo\"); // err\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in PolyNull.java (at line 12)\n" + + " return extract(i -> null, \"hallo\"); // err\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); + } + + // functional interface with nullness inferred from target type with explicit nullness + public void testNullTypeInference2b() { + runNegativeTestWithLibs( + new String[] { + "PolyNull.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface Func {\n" + + " T a(T i);\n" + + "}\n" + + "public class PolyNull {\n" + + " @NonNull String extract(Func<@NonNull String> f, @NonNull String s) { return f.a(s); }\n" + + " @NonNull String testOK() {\n" + + " return extract(i -> i, \"hallo\");\n" + + " }\n" + + " @NonNull String testERR() {\n" + + " return extract(i -> null, \"hallo\"); // err\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in PolyNull.java (at line 12)\n" + + " return extract(i -> null, \"hallo\"); // err\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); + } + + // functional interface with unspecified nullness matched against lambda parameter with explicit type & nullness + public void testNullTypeInference2c() { + runNegativeTestWithLibs( + new String[] { + "PolyNull.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface Func {\n" + + " T a(T i);\n" + + "}\n" + + "public class PolyNull {\n" + + " X extract(Func f, X s) { return f.a(s); }\n" + + " @NonNull String testOK() {\n" + + " return extract((@NonNull String i) -> i, \"hallo\");\n" + + " }\n" + + " @NonNull String testERR() {\n" + + " return extract((@NonNull String i) -> null, \"hallo\"); // err\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in PolyNull.java (at line 12)\n" + + " return extract((@NonNull String i) -> null, \"hallo\"); // err\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); + } + + // the only null annotation is on the target type, which propagates into the implicitly typed lambda argument + public void testNullTypeInference2d() { + runNegativeTestWithLibs( + new String[] { + "PolyNull.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface Func {\n" + + " T a(T i);\n" + + "}\n" + + "public class PolyNull {\n" + + " X extract(Func f, X s) { return f.a(s); }\n" + + " @NonNull String testOK() {\n" + + " return extract(i -> i, \"hallo\");\n" + + " }\n" + + " @NonNull String testERR() {\n" + + " return extract(i -> null, \"hallo\"); // err\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in PolyNull.java (at line 12)\n" + + " return extract(i -> null, \"hallo\"); // err\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); + } + + // demonstrate that null annotations from the functional interface win, resulting in successful inference but null-safety issues + public void testNullTypeInference2e() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "PolyNull.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface Func {\n" + + " T a(T i);\n" + + "}\n" + + "public class PolyNull {\n" + + " String extract(Func<@Nullable String> f, @Nullable String s) { return f.a(s); }\n" + + " @NonNull String testWARN() {\n" + + " return extract(i -> null, \"hallo\"); // OK to pass null\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in PolyNull.java (at line 9)\n" + + " return extract(i -> null, \"hallo\"); // OK to pass null\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n"); + } + + // demonstrate that null annotations from the functional interface win, resulting in successful inference but null-safety issues + public void testNullTypeInference2f() { + runNegativeTestWithLibs( + new String[] { + "PolyNull.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface Func {\n" + + " T a(T i);\n" + + "}\n" + + "public class PolyNull {\n" + + " X extract(Func<@Nullable X> f, @Nullable X s) { return f.a(s); }\n" + + " @NonNull String testERR() {\n" + + " return extract(i -> needNN(i), \"ola\");\n" + + " }\n" + + " @NonNull String needNN(@NonNull String s) { return \"\"; }\n" + + "" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in PolyNull.java (at line 7)\n" + + " X extract(Func<@Nullable X> f, @Nullable X s) { return f.a(s); }\n" + + " ^^^^^^\n" + + "Null type mismatch (type annotations): required \'X\' but this expression has type \'@Nullable X\', where 'X' is a free type variable\n" + + "----------\n" + + "2. ERROR in PolyNull.java (at line 9)\n" + + " return extract(i -> needNN(i), \"ola\");\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n"); + } + + // seemingly conflicting annotations from type variable application and type variable substitution + // -> ignore @Nullable which overrides the type variable's nullness for this one location + public void testNullTypeInference3() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "Generics.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Generics {\n" + + " X m(@Nullable X a) { return null; }\n" + + " void test(@NonNull String in) {\n" + + " @NonNull String s = m(in);\n" + // inferred OK as 'm(@Nullable String) -> @NonNull String' + " System.out.println(s.toLowerCase());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Generics().test(\"hallo\");\n" + + " }\n" + + "}\n" + }, + compilerOptions, + "----------\n" + + "1. ERROR in Generics.java (at line 4)\n" + + " X m(@Nullable X a) { return null; }\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): \'null\' is not compatible to the free type variable 'X'\n" + + "----------\n"); + } + + // conflicting annotations from type variable application and type variable substitution -> exclude null annotations from inference + public void testNullTypeInference3b() { + runNegativeTestWithLibs( + new String[] { + "Generics.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Generics {\n" + + " @Nullable X m1(@Nullable X a) { return null; }\n" + + " @Nullable X m2(X a) { return null; }\n" + + " void test(@NonNull String in) {\n" + + " @NonNull String s1 = m1(in);\n" + + " @NonNull String s2 = m2(in);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new Generics().test(\"hallo\");\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Generics.java (at line 7)\n" + + " @NonNull String s1 = m1(in);\n" + + " ^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n" + + "2. ERROR in Generics.java (at line 8)\n" + + " @NonNull String s2 = m2(in);\n" + + " ^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n"); + } + + // conflicting annotations from type variable application and type variable substitution + public void testNullTypeInference3c() { + runNegativeTestWithLibs( + new String[] { + "Generics.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "\n" + + "interface Function { }\n" + + "abstract class MyFunc implements Function<@NonNull Object, @Nullable String> { }\n" + + " \n" + + "public class Generics {\n" + + " <@NonNull I,@Nullable O> \n" + + " Collection map1(Collection in, Function f) { return null; }\n" + + " <@Nullable I,@NonNull O> \n" + + " Collection map2(Collection in, Function f) { return null; }\n" + + " void test(@NonNull List inList, MyFunc f) {\n" + + " Collection<@Nullable String> result = map1(inList, f);\n" + + " map2(inList, f);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Generics.java (at line 13)\n" + + " Collection<@Nullable String> result = map1(inList, f);\n" + + " ^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'@NonNull List\' needs unchecked conversion to conform to \'Collection<@NonNull Object>\', corresponding supertype is 'Collection'\n" + + "----------\n" + + "2. WARNING in Generics.java (at line 14)\n" + + " map2(inList, f);\n" + + " ^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'@NonNull List\' needs unchecked conversion to conform to \'Collection<@Nullable Object>\', corresponding supertype is 'Collection'\n" + + "----------\n" + + "3. ERROR in Generics.java (at line 14)\n" + + " map2(inList, f);\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'Function<@Nullable Object,@NonNull String>\' but this expression has type \'MyFunc\', corresponding supertype is \'Function<@NonNull Object,@Nullable String>\'\n" + + "----------\n"); + } + + // missing return type should not cause NPE + public void testBug415850_01() { + runNegativeTest( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @NonNull foo() {}\n" + + " ^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n", + this.LIBS, + true/*flush*/); + } + + // enum constant inside raw type: initialization must be recognized as conform to the implicitly @NonNull declaration + public void testBug415850_02(){ + runConformTestWithLibs( + new String[] { + "Callable.java", + "interface Callable {\n" + + " public enum Result {\n" + + " GOOD, BAD\n" + + " };\n" + + " public Result call(T arg);\n" + + "}\n" + }, + getCompilerOptions(), + ""); + } + + // when mapping 1st parameter to method receiver, avoid AIOOBE in ReferenceExpression#resolveType(..) + public void testBug415850_03() throws Exception { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_DEPRECATION, JavaCore.IGNORE); + runner.javacTestOptions = new JavacTestOptions.SuppressWarnings("deprecation"); + runner.classLibraries = this.LIBS; + runner.testFiles = + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.util.Date;\n" + + "import static java.lang.annotation.ElementType.*; \n" + + "@Target(TYPE_USE)\n" + + "@interface Vernal {}\n" + + "interface I {\n" + + " int f(Date d);\n" + + "}\n" + + "class X {\n" + + " static void monitorTemperature(Object myObject) {\n" + + " I i = @Vernal Date::getDay;\n" + + " }\n" + + "}\n", + }; + runner.runConformTest(); + } + + // ensure annotation type has super types connected, to avoid NPE in ImplicitNullAnnotationVerifier.collectOverriddenMethods(..) + public void testBug415850_04() throws Exception { + runConformTestWithLibs( + new String[] { + "X.java", + "public class X implements @B @C('i') J { }", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "J.java", + "interface J {}\n" + }, + getCompilerOptions(), + ""); + } + + // don't let type annotations on array dimensions spoil type compatibility + public void testBug415850_05() { + runNegativeTest( + new String[]{ + "X.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int @Marker [][][] i = new @Marker int @Marker [2] @Marker [@Marker bar()] @Marker [];\n" + + " }\n" + + " public int bar() {\n" + + " return 2;\n" + + " }\n" + + "}\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " int @Marker [][][] i = new @Marker int @Marker [2] @Marker [@Marker bar()] @Marker [];\n" + + " ^^^^^^^\n" + + "Syntax error, type annotations are illegal here\n" + + "----------\n", + this.LIBS, + true/*flush*/); + } + + // don't let type annotations on array dimensions spoil type compatibility + // case without any error + public void testBug415850_06() { + runConformTestWithLibs( + new String[]{ + "X.java", + "import java.lang.annotation.Target;\n" + + "public class X {\n" + + " public void foo() {\n" + + " int @Marker [][][] i = new @Marker int @Marker [2] @Marker [bar()] @Marker [];\n" + + " }\n" + + " public int bar() {\n" + + " return 2;\n" + + " }\n" + + "}\n" + + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface Marker {}\n" + }, + getCompilerOptions(), + ""); + } + + public void testBug416172() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class X {\n" + + " class Y {}\n" + + " X.@NonNull Y foo(X.@NonNull Y xy) {\n" + + " return new X().new Y();\n" + + " }\n" + + "}\n" + + "\n" + + "class Z extends X {\n" + + " @Override\n" + + " X.@NonNull Y foo(X.Y xy) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 12)\n" + + " X.@NonNull Y foo(X.Y xy) {\n" + + " ^^^\n" + + "Missing non-null annotation: inherited method from X specifies this parameter as @NonNull\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " return null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'X.@NonNull Y\' but the provided value is null\n" + + "----------\n"); + } + + // incompatible null constraints on parameters + public void testBug416174() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_NONNULL_PARAMETER_ANNOTATION_DROPPED, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class X {\n" + + " void foo1(List lx) {}\n" + + " void foo2(List<@NonNull X> lx) {}\n" + + " void foo3(List<@Nullable X> lx) {}\n" + + " void foo4(@NonNull List<@Nullable X> lx) {}\n" + + "}\n" + + "\n" + + "class Z extends X {\n" + + " @Override void foo1(List<@NonNull X> xy) {}\n" + + " @Override void foo2(List lx) {}\n" + + " @Override void foo3(List lx) {}\n" + + " @Override void foo4(List<@Nullable X> lx) {}\n" + // omitting annotation at toplevel can be tolerated (via option) + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " @Override void foo1(List<@NonNull X> xy) {}\n" + + " ^^^^\n" + + "Illegal redefinition of parameter xy, inherited method from X declares this parameter as \'List\' (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " @Override void foo2(List lx) {}\n" + + " ^^^^\n" + + "Illegal redefinition of parameter lx, inherited method from X declares this parameter as \'List<@NonNull X>\' (mismatching null constraints)\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " @Override void foo3(List lx) {}\n" + + " ^^^^\n" + + "Illegal redefinition of parameter lx, inherited method from X declares this parameter as \'List<@Nullable X>\' (mismatching null constraints)\n" + + "----------\n"); + } + + // incompatibility at return type, which should be shown here in the error message + public void testBug416174b() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public abstract class X {\n" + + " List foo1() {\n" + + " return null;\n" + + " }\n" + + " List<@Nullable X> foo2() {\n" + + " return null;\n" + + " }\n" + + " abstract @NonNull List<@NonNull X> foo3();\n" + + " List<@Nullable X> foo4() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Z extends X {\n" + + " @Override\n" + + " List<@NonNull X> foo1() {\n" + + " return null;\n" + + " }\n" + + " @Override\n" + + " List<@NonNull X> foo2() {\n" + + " return null;\n" + + " }\n" + + " @Override\n" + + " @NonNull List foo3() {\n" + + " return new ArrayList<>();\n" + + " }\n" + + " @Override\n" + + " @NonNull List<@Nullable X> foo4() {\n" + // OK + " return new ArrayList<>();\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " List<@NonNull X> foo1() {\n" + + " ^^^^\n" + + "The return type is incompatible with \'List\' returned from X.foo1() (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in X.java (at line 24)\n" + + " List<@NonNull X> foo2() {\n" + + " ^^^^\n" + + "The return type is incompatible with \'List<@Nullable X>\' returned from X.foo2() (mismatching null constraints)\n" + + "----------\n" + + "3. ERROR in X.java (at line 28)\n" + + " @NonNull List foo3() {\n" + + " ^^^^\n" + + "The return type is incompatible with \'@NonNull List<@NonNull X>\' returned from X.foo3() (mismatching null constraints)\n" + + "----------\n"); + } + + // overriding an unconstrained return with nullable + public void testNullableReturn() { + runConformTestWithLibs( + new String[] { + "X.java", + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public abstract class X {\n" + + " X foo1() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "abstract class Z extends X {\n" + + " @Override\n" + + " @Nullable X foo1() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + } + + public void testBug416175() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List<@NonNull ? extends @NonNull String> ls = new ArrayList();\n" + + " ls.add(null);\n" + + " @NonNull String s = ls.get(0);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " List<@NonNull ? extends @NonNull String> ls = new ArrayList();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'@NonNull ArrayList\' needs unchecked conversion to conform to \'List<@NonNull ? extends @NonNull String>\', corresponding supertype is 'List'\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " ls.add(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull ? extends @NonNull String\' but the provided value is null\n" + + "----------\n" + + "3. INFO in X.java (at line 10)\n" + + " @NonNull String s = ls.get(0);\n" + + " ^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'List<@NonNull capture#of ? extends @NonNull String>\'. Type \'List\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n"); + } + + // original test (was throwing stack overflow) + public void testBug416176() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class X<@NonNull T> {\n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + } + + // variant to challenge merging of annotation on type variable and its use + public void testBug416176a() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class X<@NonNull T> {\n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " @NonNull T bar1(@NonNull T t) {\n" + + " return t;\n" + + " }\n" + + " @NonNull T bar2(@Nullable T t) { // argument: no contradiction (1)\n" + + " return t; // mismatch (1)\n" + + " }\n" + + " @Nullable T bar3(T t) { // return type: no contradiction (2)\n" + + " @Nullable T l = t; // local: no contradiction (3)\n" + + " return l;\n" + + " }\n" + + " class Inner {\n" + + " @Nullable T f; // field: no contradiction (4)\n" + + " }\n" + + " T bar3() {\n" + + " return null; // mismatch (2)\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " return t; // mismatch (1)\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull T\' but this expression has type \'@Nullable T\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 22)\n" + + " return null; // mismatch (2)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull T\' but the provided value is null\n" + + "----------\n"); + } + + // variant to challenge duplicate methods, though with different parameter annotations + public void testBug416176b() { + runNegativeTest( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class X {\n" + + " @NonNull T bar(@NonNull T t) {\n" + + " return t;\n" + + " }\n" + + " @NonNull T bar(@Nullable T t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @NonNull T bar(@NonNull T t) {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Duplicate method bar(T) in type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " @NonNull T bar(@Nullable T t) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method bar(T) in type X\n" + + "----------\n", + this.LIBS, + true/*flush*/); + } + + public void testBug416180() { + runWarningTestWithLibs( + true, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class X {\n" + + " T foo(T t) {\n" + + " return t;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " X x = new Y();\n" + + " }\n" + + "} \n" + + "\n" + + "class Y extends X<@NonNull String> {\n" + + " @Override\n" + + " @NonNull String foo(java.lang.@NonNull String t) {\n" + + " return \"\";\n" + + " };\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. INFO in X.java (at line 9)\n" + + " X x = new Y();\n" + + " ^^^^^^^\n" + + "Unsafe null type conversion (type annotations): The value of type '@NonNull Y' is made accessible using the less-annotated type 'X', corresponding supertype is 'X<@NonNull String>'\n" + + "----------\n"); + } + + public void testBug416181() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class X {\n" + + " class Y {\n" + + " \n" + + " }\n" + + " \n" + + " X.@NonNull Y y = null; // 1st error here.\n" + + " \n" + + " @NonNull Y y2 = null; // 2nd error here.\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " X.@NonNull Y y = null; // 1st error here.\n" + + " ^^^^\n" + + "Null type mismatch: required \'X.@NonNull Y\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " @NonNull Y y2 = null; // 2nd error here.\n" + + " ^^^^\n" + + "Null type mismatch: required \'X.@NonNull Y\' but the provided value is null\n" + + "----------\n"); + } + + public void testBug416182() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class X {\n" + + " T foo(@NonNull T t) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<@Nullable String> xs = new X();\n" + + " xs.foo(null);\n" + + " }\n" + + " \n" + + " public void test(X x) {\n" + + " X<@Nullable String> xs = x;\n" + + " xs.bar(null);\n" + + " }\n" + + " public void bar(T t) {}\n" + + "\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " X<@Nullable String> xs = new X();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'@NonNull X\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " xs.foo(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in X.java (at line 14)\n" + + " X<@Nullable String> xs = x;\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'X\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" + + "----------\n"); + } + + // introduce unrelated method lookup before the bogus one + public void testBug416182a() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class X {\n" + + " T foo(@NonNull T t) {\n" + + " return t;\n" + + " }\n" + + " void foo() {}\n" + + " public static void main(String[] args) {\n" + + " X<@Nullable String> xs = new X();\n" + + " xs.foo();\n" + + " xs.foo(null);\n" + + " }\n" + + " \n" + + " public void test(X x) {\n" + + " X<@Nullable String> xs = x;\n" + + " xs.bar(null);\n" + + " }\n" + + " public void bar(T t) {}\n" + + "\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " X<@Nullable String> xs = new X();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'@NonNull X\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " xs.foo(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in X.java (at line 16)\n" + + " X<@Nullable String> xs = x;\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'X\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" + + "----------\n"); + } + + // avoid extra warning by use of diamond. + public void testBug416182b() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class X {\n" + + " T foo(@NonNull T t) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X<@Nullable String> xs = new X<>();\n" + + " xs.foo(null);\n" + + " }\n" + + " \n" + + " public void test(X x) {\n" + + " X<@Nullable String> xs = x;\n" + + " xs.bar(null);\n" + + " }\n" + + " public void bar(T t) {}\n" + + "\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " xs.foo(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " X<@Nullable String> xs = x;\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'X\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" + + "----------\n"); + } + + public void testBug416183() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class X {\n" + + " T foo(@NonNull T t) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X xs = new X();\n" + + " xs.foo(\"\");\n" + + " }\n" + + " \n" + + "}\n" + }, + getCompilerOptions(), + ""); + } + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=417113#c25, point 4. + public void testSubstitution() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import java.util.List;\n" + + "import java.util.ArrayList;\n" + + "public class X {\n" + + " T foo(@NonNull List<@NonNull T> l) {\n" + + " return l.get(0);\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " X s = new X<>();\n" + + " s.foo(new ArrayList()); // (1)\n" + + " s.foo(null); // (2)\n" + + " }\n" + + "}\n" + + }, + getCompilerOptions(), + "----------\n" + + "1. INFO in X.java (at line 6)\n" + + " return l.get(0);\n" + + " ^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull List<@NonNull T>\'. Type \'List\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " s.foo(new ArrayList()); // (1)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'@NonNull ArrayList\' needs unchecked conversion to conform to \'@NonNull List<@NonNull String>\', corresponding supertype is 'List'\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " s.foo(null); // (2)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull List<@NonNull String>\' but the provided value is null\n" + + "----------\n"); + } + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=417113#c25, point 4. + public void testSubstitution2() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public class X {\n" + + " T foo(@NonNull T @NonNull [] l) {\n" + + " return l[0];\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " X s = new X<>();\n" + + " s.foo(new String [] { null });\n" + + " s.foo(new String @Nullable [] { null });\n" + + " s.foo(new String @NonNull [] { null });\n" + + " s.foo(new @Nullable String @NonNull [] { null });\n" + + " s.foo(new @NonNull String @NonNull [] { \"\" });\n" + + " s.foo(null); // (2)\n" + + " }\n" + + "}\n" + + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " s.foo(new String [] { null });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'@NonNull String @NonNull[]\'\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " s.foo(new String @Nullable [] { null });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String @Nullable[]\' needs unchecked conversion to conform to \'@NonNull String @NonNull[]\'\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " s.foo(new String @NonNull [] { null });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String @NonNull[]\' needs unchecked conversion to conform to \'@NonNull String @NonNull[]\'\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " s.foo(new @Nullable String @NonNull [] { null });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[]\' but this expression has type \'@Nullable String @NonNull[]\'\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " s.foo(null); // (2)\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String @NonNull[]\' but the provided value is null\n" + + "----------\n"); + } + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=417113#c25, point 4. + public void testSubstitution3() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class X {\n" + + " T foo(@NonNull T l) {\n" + + " return l;\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " X s = new X<>();\n" + + " s.foo(null);\n" + + " }\n" + + "}\n" + + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " s.foo(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); + } + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=417113#c25, point 4. + public void testSubstitution4() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface TypeAnnotation {\n" + + "}\n" + + "public class X {\n" + + " class Y {}\n" + + " void foo(@TypeAnnotation X.@NonNull Y l) {\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " X s = new X<>();\n" + + " s.foo(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " s.foo(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'X.@NonNull Y\' but the provided value is null\n" + + "----------\n"); + } + // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=417113#c25, point 4. + public void testSubstitution5() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class X {\n" + + " void foo(@NonNull X<@NonNull ? extends T> p) {\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " X s = new X<>();\n" + + " X<@NonNull String> s2 = new X<@NonNull String>();\n" + + " s.foo(s);\n" + + " s.foo(s2);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " s.foo(s);\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'X\' needs unchecked conversion to conform to \'@NonNull X<@NonNull ? extends String>\'\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/417758 - [1.8][null] Null safety compromise during array creation. + // original test case + public void testArray1() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " @NonNull String @NonNull [] s = new @NonNull String [] { null };\n" + + " if (s != null && s[0] != null) {\n" + + " System.out.println(\"Not null\");\n" + + " }\n" + + " System.out.println(\"Length = \" + s[0].length());\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " @NonNull String @NonNull [] s = new @NonNull String [] { null };\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " if (s != null && s[0] != null) {\n" + + " ^\n" + + "Redundant null check: comparing \'@NonNull String @NonNull[]\' against null\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " if (s != null && s[0] != null) {\n" + + " ^^^^\n" + + "Redundant null check: comparing \'@NonNull String\' against null\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/417758 - [1.8][null] Null safety compromise during array creation. + // two-dim array with annotations on dimensions + public void testArray2() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " @NonNull String @NonNull [][] s1 = new @NonNull String @NonNull [][] { null, { null} }; // problem at inner null\n" + + " @NonNull String @NonNull [][] s2 = new @NonNull String [] @NonNull [] { null, { null} }; // problem at both nulls\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " @NonNull String @NonNull [][] s1 = new @NonNull String @NonNull [][] { null, { null} }; // problem at inner null\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "2. INFO in X.java (at line 7)\n" + + " @NonNull String @NonNull [][] s2 = new @NonNull String [] @NonNull [] { null, { null} }; // problem at both nulls\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unsafe null type conversion (type annotations): The value of type \'@NonNull String [] @NonNull[]\' is made accessible using the less-annotated type \'@NonNull String @NonNull[] []\'\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " @NonNull String @NonNull [][] s2 = new @NonNull String [] @NonNull [] { null, { null} }; // problem at both nulls\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String @NonNull[]\' but the provided value is null\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " @NonNull String @NonNull [][] s2 = new @NonNull String [] @NonNull [] { null, { null} }; // problem at both nulls\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/417758 - [1.8][null] Null safety compromise during array creation. + // three-dim array with annotations on dimensions, also assignment has a problem + public void testArray3() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.WARNING); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class X {\n" + + " \n" + + " public static void main(String[] args) {\n" + + " @NonNull String [][] @NonNull [] s = new @NonNull String []@NonNull [][] { null, { {null}, null/*ok*/ } };\n" + + " }\n" + + "}" + }, + options, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " @NonNull String [][] @NonNull [] s = new @NonNull String []@NonNull [][] { null, { {null}, null/*ok*/ } };\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unsafe null type conversion (type annotations): The value of type \'@NonNull String [] @NonNull[] []\' is made accessible using the less-annotated type \'@NonNull String [] [] @NonNull[]\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " @NonNull String [][] @NonNull [] s = new @NonNull String []@NonNull [][] { null, { {null}, null/*ok*/ } };\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String @NonNull[] []\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " @NonNull String [][] @NonNull [] s = new @NonNull String []@NonNull [][] { null, { {null}, null/*ok*/ } };\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); + } + + public void testBug417759() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class X {\n" + + " void foo(@NonNull X<@NonNull ?> l) { \n" + + " } \n" + + " public static void main(String[] args) {\n" + + " @NonNull X s = new X<>();\n" + + " s.foo(s); // String vs. @NonNull ?\n" + + " @NonNull X<@Nullable String> s2 = new X<>();\n" + + " s.foo(s2); // @Nullable String vs. @NonNull ?\n" + + " @NonNull X<@NonNull String> s3 = new X<>();\n" + + " s.foo(s3); // good\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " s.foo(s); // String vs. @NonNull ?\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'@NonNull X\' needs unchecked conversion to conform to \'@NonNull X<@NonNull ?>\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " s.foo(s2); // @Nullable String vs. @NonNull ?\n" + + " ^^\n" + + "Null type mismatch (type annotations): required \'@NonNull X<@NonNull ?>\' but this expression has type \'@NonNull X<@Nullable String>\'\n" + + "----------\n"); + } + public void testTypeVariable1() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Junk {\n" + + "}\n" + + "public class X<@NonNull T> {\n" + + " T t = null;\n" + + " @Junk T t2 = null;\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " T t = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull T\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " @Junk T t2 = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull T\' but the provided value is null\n" + + "----------\n"); + } + // free type variable does not ensure @NonNull, but cannot accept null either, unbounded type variable + public void testTypeVariable2() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void consumeAny(T t) {\n" + + " consume(t); // error, t can be null\n" + + " consumeObject(t); // error, t can be null\n" + + " }\n" + + " void consumeNullable(@Nullable T t) {\n" + + " consume(t); // error, both sides explicit, mismatch\n" + + " consumeObject(t); // error, both sides explicit, mismatch\n" + + " }\n" + + " void consume(@NonNull T t) {}\n" + + " void consumeObject(@NonNull Object o) {}\n" + + " T produce() {\n" + + " return null; // error, T may not accept null\n" + + " }\n" + + " T produceFromNullable(@Nullable T t) {\n" + + " return t; // error, T may not accept nullable\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " consume(t); // error, t can be null\n" + + " ^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " consumeObject(t); // error, t can be null\n" + + " ^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " consume(t); // error, both sides explicit, mismatch\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull T\' but this expression has type \'@Nullable T\'\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " consumeObject(t); // error, both sides explicit, mismatch\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable T\'\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " return null; // error, T may not accept null\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): \'null\' is not compatible to the free type variable 'T'\n" + + "----------\n" + + "6. ERROR in X.java (at line 17)\n" + + " return t; // error, T may not accept nullable\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'T\' but this expression has type \'@Nullable T\', where \'T\' is a free type variable\n" + + "----------\n"); + } + // free type variable does not ensure @NonNull, but cannot accept null either, type variable with upper bound + public void testTypeVariable3() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void consumeAny(T t) {\n" + + " consume(t); // error, t can be null\n" + + " consumeObject(t); // error, t can be null\n" + + " }\n" + + " void consumeNullable(@Nullable T t) {\n" + + " consume(t); // error, both sides explicit, mismatch\n" + + " consumeObject(t); // error, both sides explicit, mismatch\n" + + " }\n" + + " void consume(@NonNull T t) {}\n" + + " void consumeObject(@NonNull Object o) {}\n" + + " T produce() {\n" + + " return null; // error, T may not accept null\n" + + " }\n" + + " T produceFromNullable(@Nullable T t) {\n" + + " return t; // error, T may not accept nullable\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " consume(t); // error, t can be null\n" + + " ^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " consumeObject(t); // error, t can be null\n" + + " ^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " consume(t); // error, both sides explicit, mismatch\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull T extends Number\' but this expression has type \'@Nullable T extends Number\'\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " consumeObject(t); // error, both sides explicit, mismatch\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable T extends Number\'\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " return null; // error, T may not accept null\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): \'null\' is not compatible to the free type variable \'T\'\n" + + "----------\n" + + "6. ERROR in X.java (at line 17)\n" + + " return t; // error, T may not accept nullable\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'T\' but this expression has type \'@Nullable T extends Number\', where \'T\' is a free type variable\n" + + "----------\n"); + } + // free type variable is compatible to itself even with different not null-related type annotations + public void testTypeVariable4() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "@Target(ElementType.TYPE_USE) @interface TypeMarker {}\n" + + "public class X {\n" + + " T passThrough1(@TypeMarker T t) {\n" + + " return t; // OK\n" + + " }\n" + + " @TypeMarker T passThrough2(T t) {\n" + + " return t; // OK\n" + + " }\n" + + " @TypeMarker T passThrough3(@Nullable @TypeMarker T t) {\n" + + " return t; // Not OK\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " return t; // Not OK\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'T\' but this expression has type \'@Nullable T\', where 'T' is a free type variable\n" + + "----------\n"); + } + // https://bugs.eclipse.org/433906 + public void testTypeVariable5() { + runConformTestWithLibs( + new String[] { + "ExFunction.java", + "@FunctionalInterface\n" + + "public interface ExFunction {\n" + + " R apply(T t1) throws E;\n" + + "\n" + + " default ExFunction compose(ExFunction before) {\n" + + " java.util.Objects.requireNonNull(before);\n" + + " //warning on before.apply(v):\n" + + " //Null type safety (type annotations): The expression of type 'capture#of ? extends T' needs unchecked conversion to conform to 'T'\n" + + " return (V v) -> apply(before.apply(v));\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + } + public void testSE7AnnotationCopy() { // we were dropping annotations here, but null analysis worked already since the tagbits were not "dropped", just the same capturing in a test + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {\n" + + "}\n" + + "public class X {\n" + + " class Y {}\n" + + " void foo(@T X.@NonNull Y p) {\n" + + " foo(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " foo(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'X.@NonNull Y\' but the provided value is null\n" + + "----------\n"); + } + public void testWildcardCapture() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List ax = new ArrayList();\n" + + " ax.add(new X());\n" + + " List lx = ax;\n" + + " getAdd(lx);\n" + + " }\n" + + " static <@NonNull P> void getAdd(List

    lt) {\n" + + " lt.add(lt.get(0));\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 16)\n" + + " getAdd(lx);\n" + + " ^^\n" + + "Null type safety (type annotations): The expression of type \'List\' needs unchecked conversion to conform to \'List<@NonNull capture#of ? extends X>\'\n" + + "----------\n"); + } + public void testWildcardCapture2() { + runConformTestWithLibs( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List<@NonNull X> ax = new ArrayList<@NonNull X>();\n" + + " ax.add(new X());\n" + + " List<@NonNull ? extends X> lx = ax;\n" + + " getAdd(lx);\n" + + " }\n" + + " static <@NonNull P> void getAdd(List

    lt) {\n" + + " lt.add(lt.get(0));\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + } + public void testWildcardCapture3() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List<@Nullable X> ax = new ArrayList<@Nullable X>();\n" + + " ax.add(new X());\n" + + " List<@Nullable ? extends X> lx = ax;\n" + + " getAdd(lx);\n" + + " }\n" + + " static <@NonNull P> void getAdd(List

    lt) {\n" + + " lt.add(lt.get(0));\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " getAdd(lx);\n" + + " ^^\n" + + "Null type mismatch (type annotations): required \'List<@NonNull capture#of ? extends X>\' but this expression has type \'List<@Nullable capture#of ? extends X>\'\n" + + "----------\n"); + } + public void testLocalArrays() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " class L {};\n" + + " L @NonNull [] @Nullable [] la = new L[5][];\n" + + " L @Nullable [] @NonNull [] la2 = new L[3][];\n" + + " la = la2;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " L @NonNull [] @Nullable [] la = new L[5][];\n" + + " ^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'L[][]\' needs unchecked conversion to conform to \'L @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " L @Nullable [] @NonNull [] la2 = new L[3][];\n" + + " ^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'L[][]\' needs unchecked conversion to conform to \'L @Nullable[] @NonNull[]\'\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " la = la2;\n" + + " ^^^\n" + + "Null type mismatch (type annotations): required \'L @NonNull[] @Nullable[]\' but this expression has type \'L @Nullable[] @NonNull[]\'\n" + + "----------\n"); + + // Without annotations. + runConformTestWithLibs( + false /* don't flush output dir */, + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " class L {};\n" + + " L [] [] la = new L[5][];\n" + + " L [] [] la2 = new L[3][];\n" + + " la = la2;\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "Done"); + } + public void testRawType() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class X {\n" + + " class Y

    {}\n" + + " public static void main(String[] args) {\n" + + " @NonNull X x = null;\n" + + " X.@NonNull Y xy = null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " @NonNull X x = null;\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " @NonNull X x = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull X\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " X.@NonNull Y xy = null;\n" + + " ^^^^^^^^^^^^\n" + + "X.Y is a raw type. References to generic type X.Y

    should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " X.@NonNull Y xy = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'X.@NonNull Y\' but the provided value is null\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=420456, [1.8][null] AIOOB in null analysis code. + public void test420456() { + final Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " Integer [] array = new Integer[] { 1234, 5678, 789 };\n" + + " Arrays.sort(array, Integer::compare);\n" + + " System.out.println(\"\" + array[0] + array[1] + array[2]);\n" + + " }\n" + + "}\n" + }, + compilerOptions, + "", + "78912345678"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=422134, [1.8] NPE in NullAnnotationMatching with inlined lambda expression used with a raw type + public void test422134() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collections;\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Collections.sort(new ArrayList(), (o1, o2) -> {\n" + + " return o1.compareToIgnoreCase(o1);\n" + + " });\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " Collections.sort(new ArrayList(), (o1, o2) -> {\n" + + " return o1.compareToIgnoreCase(o1);\n" + + " });\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation sort(ArrayList, ( o1, o2) -> {})" + + " of the generic method sort(List, Comparator) of type Collections\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " Collections.sort(new ArrayList(), (o1, o2) -> {\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type safety: The expression of type ArrayList needs unchecked conversion to conform to List\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " Collections.sort(new ArrayList(), (o1, o2) -> {\n" + + " ^^^^^^^^^\n" + + "ArrayList is a raw type. References to generic type ArrayList should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " return o1.compareToIgnoreCase(o1);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The method compareToIgnoreCase(Object) is undefined for the type Object\n" + + "----------\n", + this.LIBS, + true/*flush*/); + } + + // should not try to analyze arguments of a polymorphic method call + public void testBug424725() { + runConformTestWithLibs( + new String[] { + "AnnotatedRecordMapper.java", + "import java.lang.invoke.MethodHandle;\n" + + "\n" + + "public final class AnnotatedRecordMapper {\n" + + " private MethodHandle afterLoadStore;\n" + + "\n" + + " public void invokeAfterLoadStore(Object object, Object database) {\n" + + " if(afterLoadStore != null) {\n" + + " try {\n" + + " afterLoadStore.invoke(object, database);\n" + + " }\n" + + " catch(Throwable e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + null, + ""); + } + + public void testBug424727() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "@org.eclipse.jdt.annotation.NonNull public class X {\n" + + " static X singleton = new X();\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @org.eclipse.jdt.annotation.NonNull public class X {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The nullness annotation \'NonNull\' is not applicable at this location\n" + + "----------\n"); + // note: to be updated with https://bugs.eclipse.org/415918 + } + +public void testBug424637() { + runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.nio.file.Files;\n" + + "import java.nio.file.Path;\n" + + "import java.util.function.Function;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class X {\n" + + " public static void method() {\n" + + " Function> method = Files::walk;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " Function> method = Files::walk;\n" + + " ^^^^^^^^^^^\n" + + "Unhandled exception type IOException\n" + + "----------\n", + this.LIBS, + true/*flush*/); +} + +public void testBug424637a() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.nio.file.FileVisitOption;\n" + + "import java.nio.file.Path;\n" + + "import java.util.function.BiFunction;\n" + + "import java.util.stream.Stream;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface TriFunc { D apply(A a, B b, C c); }\n" + + "public class X {\n" + + " public static Stream myWalk(Path p, @NonNull FileVisitOption ... options) { return null; }\n" + + " public static void method() {\n" + + " BiFunction> method1 = X::myWalk;\n" + // one element varargs - nullity mismatch + " BiFunction> method2 = X::myWalk;\n" + // pass-through array varargs - nullity mismatch + " BiFunction> method3 = X::myWalk;\n" + // pass-through array varargs - unchecked + " TriFunc> method4 = X::myWalk;\n" + // two-element varargs - nullity mismatch on one of them + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " BiFunction> method1 = X::myWalk;\n" + + " ^^^^^^^^^\n" + + "Null type mismatch at parameter 2: required \'@NonNull FileVisitOption\' but provided \'@Nullable FileVisitOption\' via method descriptor BiFunction>.apply(Path, FileVisitOption)\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " BiFunction> method2 = X::myWalk;\n" + + " ^^^^^^^^^\n" + + "Null type mismatch at parameter 2: required \'@NonNull FileVisitOption []\' but provided \'@Nullable FileVisitOption []\' via method descriptor BiFunction>.apply(Path, FileVisitOption[])\n" + + "----------\n" + + "3. WARNING in X.java (at line 13)\n" + + " BiFunction> method3 = X::myWalk;\n" + + " ^^^^^^^^^\n" + + "Null type safety: parameter 2 provided via method descriptor BiFunction>.apply(Path, FileVisitOption[]) needs unchecked conversion to conform to \'@NonNull FileVisitOption []\'\n" + + "----------\n" + + "4. ERROR in X.java (at line 14)\n" + + " TriFunc> method4 = X::myWalk;\n" + + " ^^^^^^^^^\n" + + "Null type mismatch at parameter 3: required \'@NonNull FileVisitOption\' but provided \'@Nullable FileVisitOption\' via method descriptor TriFunc>.apply(Path, FileVisitOption, FileVisitOption)\n" + + "----------\n"); +} + +public void testBug424637_comment3() { + runConformTestWithLibs( + new String[] { + "VarArgsMethodReferenceTest.java", + "import java.util.function.Consumer;\n" + + "public class VarArgsMethodReferenceTest {\n" + + " public static void main(String[] argv) {\n" + + " Consumer printffer;\n" + + " printffer = System.out::printf;\n" + + " }\n" + + "}" + }, + null, + ""); +} +public void testBug427163() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void consume(@NonNull String @Nullable... strings) {\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "" + ); +} +public void testBug427163b() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void consume1(@NonNull @Nullable String @Nullable[] strings) {}\n" + + " void consume2(@Nullable String @NonNull @Nullable... strings) {}\n" + + " void consume3(@Nullable String[] @NonNull @Nullable[] strings) {}\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void consume1(@NonNull @Nullable String @Nullable[] strings) {}\n" + + " ^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " void consume2(@Nullable String @NonNull @Nullable... strings) {}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " void consume3(@Nullable String[] @NonNull @Nullable[] strings) {}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + ); +} +public void testBug427163c() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " String[][] strings0 = new @NonNull String @Nullable[] @Nullable[] {};\n" + + " String[] strings1 = new String @NonNull @Nullable[] {};\n" + + " Object[] objects2 = new Object @NonNull @Nullable[1];\n" + + " String[] strings3 = new @NonNull @Nullable String [1];\n" + + " String[] strings4 = new @NonNull String @Nullable @NonNull[1];\n" + + " String[][] strings5 = new String[] @NonNull @Nullable[] {};\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " String[] strings1 = new String @NonNull @Nullable[] {};\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Object[] objects2 = new Object @NonNull @Nullable[1];\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " String[] strings3 = new @NonNull @Nullable String [1];\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " String[] strings4 = new @NonNull String @Nullable @NonNull[1];\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " String[][] strings5 = new String[] @NonNull @Nullable[] {};\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + ); +} +// assorted tests with upper-bounded wildcards with null annotations +public void testTypeBounds1() { + runNegativeTestWithLibs( + new String[] { + "C.java", + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class A { }\n" + + "class B extends A {}\n" + + "public class C {\n" + + " \n" + + " @NonNull A testExtends(List<@NonNull B> lb1, List<@Nullable B> lb2, boolean f) {\n" + + " List la1 = lb1;\n" + + " la1.add(null); // ERR1\n" + + " if (la1.size() > 0)\n" + + " return la1.get(0); // OK\n" + + " la1 = lb2; // ERR2\n" + + " List la2 = lb1; // OK\n" + + " la2.add(null); // ERR3\n" + + " if (la2.size() > 0)\n" + + " return la2.get(0); // ERR4\n" + + " la2 = lb2; // OK\n" + + " if (f)\n" + + " return mExtends1(lb1); // OK, since we infer T to @NonNull B\n" + + " return mExtends2(lb1);\n" + + " }\n" + + " T mExtends1(List t) { return null; /*ERR5*/ }\n" + + " T mExtends2(List t) { return null; /*ERR6*/ }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in C.java (at line 12)\n" + + " la1.add(null); // ERR1\n" + + " ^^^^\n" + + "Null type mismatch: required \'? extends @NonNull A\' but the provided value is null\n" + + "----------\n" + + "2. INFO in C.java (at line 14)\n" + + " return la1.get(0); // OK\n" + + " ^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'List\'. Type \'List\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n" + + "3. ERROR in C.java (at line 15)\n" + + " la1 = lb2; // ERR2\n" + + " ^^^\n" + + "Null type mismatch (type annotations): required \'List\' but this expression has type \'List<@Nullable B>\'\n" + + "----------\n" + + "4. ERROR in C.java (at line 17)\n" + + " la2.add(null); // ERR3\n" + + " ^^^^\n" + + "Null type mismatch: required \'? extends @Nullable A\' but the provided value is null\n" + + "----------\n" + + "5. ERROR in C.java (at line 19)\n" + + " return la2.get(0); // ERR4\n" + + " ^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull A\' but this expression has type \'capture#of ? extends @Nullable A\'\n" + + "----------\n" + + "6. ERROR in C.java (at line 25)\n" + + " T mExtends1(List t) { return null; /*ERR5*/ }\n" + + " ^^^^\n" + + "Null type mismatch: required \'T extends @Nullable A\' but the provided value is null\n" + + "----------\n" + + "7. ERROR in C.java (at line 26)\n" + + " T mExtends2(List t) { return null; /*ERR6*/ }\n" + + " ^^^^\n" + + "Null type mismatch: required \'T extends @NonNull A\' but the provided value is null\n" + + "----------\n" + ); +} +// assorted tests with lower-bounded wildcards with null annotations +public void testTypeBounds2() { + runNegativeTestWithLibs( + new String[] { + "C.java", + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class A { }\n" + + "class B extends A {}\n" + + "public class C {\n" + + " \n" + + " @NonNull Object testSuper(List<@Nullable A> la1, List<@NonNull A> la2, boolean f) {\n" + + " List lb1 = la1; // OK\n" + + " lb1.add(null); // ERR1\n" + + " if (lb1.size() > 0)\n" + + " return lb1.get(0); // ERR2\n" + + " lb1 = la2; // OK\n" + + " List lb2 = la1;\n" + + " lb2.add(null);\n" + + " if (lb2.size() > 0)\n" + + " return lb2.get(0); // ERR3\n" + + " lb2 = la2; // ERR4\n" + + " if (f)\n" + + " return mSuper1(la1); // ERR5\n" + + " return mSuper2(la1); // ERR6 on arg\n" + + " }\n" + + " T mSuper1(List t) { return null; /*ERR7*/ }\n" + + " T mSuper2(List t) { return null; /*ERR8*/ }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in C.java (at line 12)\n" + + " lb1.add(null); // ERR1\n" + + " ^^^^\n" + + "Null type mismatch: required \'? super @NonNull B\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in C.java (at line 14)\n" + + " return lb1.get(0); // ERR2\n" + + " ^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'capture#of ? super @NonNull B\'\n" + + "----------\n" + + "3. ERROR in C.java (at line 19)\n" + + " return lb2.get(0); // ERR3\n" + + " ^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'capture#of ? super @Nullable B\'\n" + + "----------\n" + + "4. ERROR in C.java (at line 20)\n" + + " lb2 = la2; // ERR4\n" + + " ^^^\n" + + "Null type mismatch (type annotations): required \'List\' but this expression has type \'List<@NonNull A>\'\n" + + "----------\n" + + "5. ERROR in C.java (at line 22)\n" + + " return mSuper1(la1); // ERR5\n" + + " ^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable A\'\n" + + "----------\n" + + "6. ERROR in C.java (at line 23)\n" + + " return mSuper2(la1); // ERR6 on arg\n" + + " ^^^\n" + + "Null type mismatch (type annotations): required \'List<@NonNull A>\' but this expression has type \'List<@Nullable A>\'\n" + + "----------\n" + + "7. ERROR in C.java (at line 25)\n" + + " T mSuper1(List t) { return null; /*ERR7*/ }\n" + + " ^^^^\n" + + "Null type mismatch: required \'T extends @Nullable A\' but the provided value is null\n" + + "----------\n" + + "8. ERROR in C.java (at line 26)\n" + + " T mSuper2(List t) { return null; /*ERR8*/ }\n" + + " ^^^^\n" + + "Null type mismatch: required \'T extends @NonNull A\' but the provided value is null\n" + + "----------\n" + ); +} +// assigning values upper bounded wildcard types carrying null annotations +public void testTypeBounds3() { + runNegativeTestWithLibs( + new String[] { + "C.java", + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class A { }\n" + + "class B extends A {}\n" + + "public class C {\n" + + " \n" + + " void testExtends(List lb1, List lb2) {\n" + + " List la1 = lb1;\n" + + " la1 = lb2; // ERR\n" + + " List la2 = lb1;\n" + + " la2 = lb2;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in C.java (at line 12)\n" + + " la1 = lb2; // ERR\n" + + " ^^^\n" + + "Null type mismatch (type annotations): required \'List\' but this expression has type \'List\'\n" + + "----------\n" + ); +} +// assigning values lower bounded wildcard types carrying null annotations +public void testTypeBounds4() { + runNegativeTestWithLibs( + new String[] { + "C.java", + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class A { }\n" + + "class B extends A {}\n" + + "public class C {\n" + + " \n" + + " void testSuper(List la1, List la2) {\n" + + " List lb1 = la1; // OK\n" + + " lb1 = la2; // OK\n" + + " List lb2 = la1;\n" + + " lb2 = la2; // ERR4\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in C.java (at line 14)\n" + + " lb2 = la2; // ERR4\n" + + " ^^^\n" + + "Null type mismatch (type annotations): required \'List\' but this expression has type \'List\'\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429387, [1.8][compiler] AIOOBE in AbstractMethodDeclaration.createArgumentBindings +public void test429387() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.function.BiFunction;\n" + + "import java.util.function.Supplier;\n" + + "import java.util.function.ToIntFunction;\n" + + "import java.util.stream.IntStream;\n" + + "import java.util.stream.Stream;\n" + + "public interface X {\n" + + "static IntStreamy\n" + + "internalFlatMapToInt(Functionish mapper,\n" + + "Class classOfE,\n" + + "Supplier> maker) {\n" + + "BiFunction, ToIntFunction, IntStream> func = (Stream t, ToIntFunction m) -> t.flatmmapToInt(m);\n" + + "return IntStreamy.fromFlatMap(func, mapper, classOfE, maker);\n" + + "}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " static IntStreamy\n" + + " ^^^^^^^^^^\n" + + "IntStreamy cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " internalFlatMapToInt(Functionish mapper,\n" + + " ^^^^^^^^^^^\n" + + "Functionish cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " BiFunction, ToIntFunction, IntStream> func = (Stream t, ToIntFunction m) -> t.flatmmapToInt(m);\n" + + " ^^^^^^^^^^^^^\n" + + "Incorrect number of arguments for type ToIntFunction; it cannot be parameterized with arguments \n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " BiFunction, ToIntFunction, IntStream> func = (Stream t, ToIntFunction m) -> t.flatmmapToInt(m);\n" + + " ^\n" + + "m cannot be resolved to a variable\n" + + "----------\n" + + "5. ERROR in X.java (at line 12)\n" + + " return IntStreamy.fromFlatMap(func, mapper, classOfE, maker);\n" + + " ^^^^^^^^^^\n" + + "IntStreamy cannot be resolved\n" + + "----------\n", + this.LIBS, + true/*flush*/); +} +public void testBug429403() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "class Person {}\n" + + "public class X {\n" + + " List<@NonNull Person> l = new ArrayList<@Nullable Person>();" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " List<@NonNull Person> l = new ArrayList<@Nullable Person>();}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'List<@NonNull Person>\' but this expression has type \'@NonNull ArrayList<@Nullable Person>\', corresponding supertype is \'List<@Nullable Person>\'\n" + + "----------\n"); +} +public void testBug430219() { + runNegativeTest( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void foo(int @NonNull [] x) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " void foo(int @NonNull [] x) {}\n" + + " ^^^^^^^\n" + + "NonNull cannot be resolved to a type\n" + + "----------\n", + this.LIBS, + true/*flush*/); +} +public void testBug430219a() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE) @interface Marker{}\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void foo(int @Marker[] x) {}\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} + +// apply null default to type arguments: +public void testDefault01() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "@NonNullByDefault(DefaultLocation.TYPE_ARGUMENT)\n" + + "public class X {\n" + + " List test1(List in) {\n" + + " in.add(null); // ERR\n" + + " return new ArrayList<@Nullable Number>(); // ERR\n" + + " }\n" + + " java.util.List test2(java.util.List in) {\n" + + " in.add(null); // ERR\n" + + " return new ArrayList(); // ERR\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " in.add(null); // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " return new ArrayList<@Nullable Number>(); // ERR\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'List<@NonNull Number>\' but this expression has type \'@NonNull ArrayList<@Nullable Number>\', corresponding supertype is \'List<@Nullable Number>\'\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " in.add(null); // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " return new ArrayList(); // ERR\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'List<@NonNull Number>\' but this expression has type \'@NonNull ArrayList<@Nullable Number>\', corresponding supertype is \'List<@Nullable Number>\'\n" + + "----------\n"); +} + +// apply null default to type arguments - no effect on type variable or wildcard, but apply strict checking assuming nothing +public void testDefault01b() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "@NonNullByDefault(DefaultLocation.TYPE_ARGUMENT)\n" + + "public class X {\n" + + " List test(List in) {\n" + + " in.add(null); // NOK, cannot assume nullable\n" + + " needNN(in.get(0)); // NOK, cannot assume nonnull\n" + + " return new ArrayList<@Nullable T>(); // NOK, cannot assume nullable for T in List\n" + + " }\n" + + " void needNN(@NonNull Number n) {}\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " in.add(null); // NOK, cannot assume nullable\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): \'null\' is not compatible to the free type variable \'? extends Number\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " needNN(in.get(0)); // NOK, cannot assume nonnull\n" + + " ^^^^^^^^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'capture#2-of ? extends java.lang.Number\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " return new ArrayList<@Nullable T>(); // NOK, cannot assume nullable for T in List\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'List\' but this expression has type \'@NonNull ArrayList<@Nullable T>\', corresponding supertype is \'List<@Nullable T>\'\n" + + "----------\n"); +} + +// apply null default to parameters: +public void testDefault02() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault(DefaultLocation.PARAMETER)\n" + + "public class X {\n" + + " Number test1(Number in) {\n" + + " System.out.print(in.intValue()); // OK\n" + + " test1(null); // ERR\n" + + " return null; // OK\n" + + " }\n" + + " java.lang.Number test2(java.lang.Number in) {\n" + + " System.out.print(in.intValue()); // OK\n" + + " test2(null); // ERR\n" + + " return null; // OK\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " test1(null); // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " test2(null); // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n"); +} + +// apply null default to return type - annotation at method: +public void testDefault03() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " Number test(Number in) {\n" + + " System.out.print(in.intValue());\n" + + " test(null); // OK\n" + + " return null; // ERR\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return null; // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n"); +} + +// apply null default to field +public void testDefault04() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault(DefaultLocation.FIELD)\n" + + "public class X {\n" + + " Number field; // ERR since uninitialized\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Number field; // ERR since uninitialized\n" + + " ^^^^^\n" + + "The @NonNull field field may not have been initialized\n" + + "----------\n"); +} + +// default default +public void testDefault05() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " Number field; // ERR since uninitialized\n" + + " void test1(Number[] ns) {\n" + + " ns[0] = null; // OK since not affected by default\n" + + " }\n" + + " void test2(java.lang.Number[] ns) {\n" + + " ns[0] = null; // OK since not affected by default\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Number field; // ERR since uninitialized\n" + + " ^^^^^\n" + + "The @NonNull field field may not have been initialized\n" + + "----------\n"); +} + +//default default +public void testDefault05_custom() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + runner.customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + runner.customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "org.foo.NonNullByDefault"); + runner.testFiles = + new String[] { + CUSTOM_NULLABLE_NAME, + CUSTOM_NULLABLE_CONTENT, + CUSTOM_NONNULL_NAME, + CUSTOM_NONNULL_CONTENT, + CUSTOM_NNBD_NAME, + CUSTOM_NNBD_CONTENT, + "test/package-info.java", + "@org.foo.NonNullByDefault\n" + + "package test;\n", + "test/X.java", + "package test;\n" + + "public class X {\n" + + " Number field; // ERR since uninitialized\n" + + " void test1(Number[] ns) {\n" + + " ns[0] = null; // OK since not affected by default\n" + + " }\n" + + " void test2(java.lang.Number[] ns) {\n" + + " ns[0] = null; // OK since not affected by default\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in test\\X.java (at line 3)\n" + + " Number field; // ERR since uninitialized\n" + + " ^^^^^\n" + + "The @NonNull field field may not have been initialized\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +//default default +public void testDefault05_custom2() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + runner.customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + runner.customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "org.foo.NonNullByDefault"); + runner.testFiles = + new String[] { + CUSTOM_NULLABLE_NAME, + CUSTOM_NULLABLE_CONTENT, + CUSTOM_NONNULL_NAME, + CUSTOM_NONNULL_CONTENT, + CUSTOM_NNBD_NAME, + CUSTOM_NNBD_CONTENT + }; + runner.runConformTest(); + runner.shouldFlushOutputDirectory = false; + runner.testFiles = + new String[] { + "test/package-info.java", + "@org.foo.NonNullByDefault\n" + + "package test;\n", + "test/X.java", + "package test;\n" + + "public class X {\n" + + " Number field; // ERR since uninitialized\n" + + " void test1(Number[] ns) {\n" + + " ns[0] = null; // OK since not affected by default\n" + + " }\n" + + " void test2(java.lang.Number[] ns) {\n" + + " ns[0] = null; // OK since not affected by default\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in test\\X.java (at line 3)\n" + + " Number field; // ERR since uninitialized\n" + + " ^^^^^\n" + + "The @NonNull field field may not have been initialized\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// apply default to type parameter - inner class +public void testDefault06() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault(DefaultLocation.TYPE_PARAMETER)\n" + + "public class X {\n" + + " class Inner {\n" + + " T process(T t) {\n" + + " @NonNull T t2 = t; // OK\n" + + " return null; // ERR\n" + + " }\n" + + " }\n" + + " void test(Inner inum) {\n" + + " @NonNull Number nnn = inum.process(null); // ERR on argument\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return null; // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull T\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " void test(Inner inum) {\n" + + " ^^^^^^\n" + + "Null constraint mismatch: The type \'Number\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " @NonNull Number nnn = inum.process(null); // ERR on argument\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n"); +} + +//apply default to type parameter - class above +public void testDefault06_b() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault({DefaultLocation.TYPE_PARAMETER, DefaultLocation.TYPE_ARGUMENT})\n" + + " class Inner {\n" + + " T process(T t) {\n" + + " @NonNull T t2 = t; // OK\n" + + " return null; // ERR\n" + + " }\n" + + " }\n" + + "@NonNullByDefault({DefaultLocation.TYPE_PARAMETER, DefaultLocation.TYPE_ARGUMENT})\n" + + "public class X {\n" + + " void test(Inner inum) {\n" + + " @NonNull Number nnn = inum.process(null); // ERR on argument\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return null; // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull T\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " @NonNull Number nnn = inum.process(null); // ERR on argument\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n"); +} + +// apply default to type bound - method in inner class +public void testDefault07() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "@NonNullByDefault(DefaultLocation.TYPE_BOUND)\n" + + "public class X {\n" + + " class Inner {\n" + + " T process(T t, List l) {\n" + + " @NonNull T t2 = t; // OK\n" + + " @NonNull Number n = l.get(0); // OK\n" + + " return null; // ERR\n" + + " }\n" + + " }\n" + + " void test(Inner inner) {\n" + + " @NonNull Number nnn = inner.process(Integer.valueOf(3), new ArrayList<@Nullable Integer>()); // WARN on 1. arg; ERR on 2. arg\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. INFO in X.java (at line 8)\n" + + " @NonNull Number n = l.get(0); // OK\n" + + " ^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'List\'. Type \'List\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " return null; // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'T extends @NonNull Number\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in X.java (at line 13)\n" + + " @NonNull Number nnn = inner.process(Integer.valueOf(3), new ArrayList<@Nullable Integer>()); // WARN on 1. arg; ERR on 2. arg\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'Integer\' needs unchecked conversion to conform to \'@NonNull Integer\'\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " @NonNull Number nnn = inner.process(Integer.valueOf(3), new ArrayList<@Nullable Integer>()); // WARN on 1. arg; ERR on 2. arg\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'List\' but this expression has type \'@NonNull ArrayList<@Nullable Integer>\', corresponding supertype is \'List<@Nullable Integer>\'\n" + + "----------\n"); +} + +//apply null default to type arguments: +public void testDefault01_bin() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "import java.lang.annotation.*;\n" + + "\n" + + "@Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.CLASS) @interface Important {}\n" + + "\n" + + "@NonNullByDefault(DefaultLocation.TYPE_ARGUMENT)\n" + + "public class X {\n" + + " List test1(List<@Important Number> in) {\n" + + " return new ArrayList<@NonNull Number>();\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runNegativeTestWithLibs( + new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class Y {\n" + + " void test(List in, X x) {\n" + + " x.test1(new ArrayList<@Nullable Number>()) // ERR at arg\n" + + " .add(null); // ERR\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Y.java (at line 5)\n" + + " x.test1(new ArrayList<@Nullable Number>()) // ERR at arg\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'List<@NonNull Number>\' but this expression has type \'@NonNull ArrayList<@Nullable Number>\', corresponding supertype is \'List<@Nullable Number>\'\n" + + "----------\n" + + "2. ERROR in Y.java (at line 6)\n" + + " .add(null); // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n"); +} + +//apply null default to parameters: +public void testDefault02_bin() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault(DefaultLocation.PARAMETER)\n" + + "public class X {\n" + + " Number test1(Number in) {\n" + + " return null; // OK\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runNegativeTestWithLibs( + new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " @NonNull Number test(X x) {\n" + + " return x.test1(null); // error at arg, unchecked at return\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Y.java (at line 4)\n" + + " return x.test1(null); // error at arg, unchecked at return\n" + + " ^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'Number\' needs unchecked conversion to conform to \'@NonNull Number\'\n" + + "----------\n" + + "2. ERROR in Y.java (at line 4)\n" + + " return x.test1(null); // error at arg, unchecked at return\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n"); +} + +//apply null default to return type - annotation at method: +public void testDefault03_bin() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runner.classLibraries = this.LIBS; + runner.testFiles = + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " Number test(Number in) {\n" + + " return new Integer(13);\n" + + " }\n" + + "}\n" + }; + runner.javacTestOptions = new JavacTestOptions.SuppressWarnings("deprecation"); + runner.runConformTest(); + + runner.shouldFlushOutputDirectory = false; + runner.testFiles = + new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " @NonNull Number test(X x) {\n" + + " return x.test(null); // both OK\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); +} + +// apply null default to field - also test mixing of explicit annotation with default @NonNull (other annot is not rendered in error) +public void testDefault04_bin() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runner.classLibraries = this.LIBS; + runner.testFiles = + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE) @Retention(RetentionPolicy.CLASS) @interface Important {}\n" + + "@NonNullByDefault(DefaultLocation.FIELD)\n" + + "public class X {\n" + + " @Important Number field = new Double(1.1);\n" + + "}\n" + }; + runner.javacTestOptions = new JavacTestOptions.SuppressWarnings("deprecation"); + runner.runConformTest(); + + runner.shouldFlushOutputDirectory = false; + runner.testFiles = + new String[] { + "Y.java", + "public class Y {\n" + + " void test(X x) {\n" + + " x.field = null; // ERR\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " x.field = null; // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// default default +public void testDefault05_bin() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runner.classLibraries = this.LIBS; + runner.testFiles = + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " Number field = new Long(13);\n" + + " void test1(Number[] ns) {\n" + + " ns[0] = null; // OK since not affected by default\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); + + runNegativeTestWithLibs( + new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " void test(X x, @Nullable Number @NonNull[] ns) {\n" + + " x.test1(ns); // OK since not affected by default\n" + + " x.field = null; // ERR\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Y.java (at line 5)\n" + + " x.field = null; // ERR\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n");} + +// apply default to type parameter - inner class +public void testDefault06_bin() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault(DefaultLocation.TYPE_PARAMETER)\n" + + "public class X {\n" + + " static class Inner {\n" + + " T process(T t) {\n" + + " return t;\n" + + " }\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runNegativeTestWithLibs( + new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " void test(X.Inner inum) { // illegal substitution\n" + + " @NonNull Number nnn = inum.process(null); // ERR on argument\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " void test(X.Inner inum) { // illegal substitution\n" + + " ^^^^^^\n" + + "Null constraint mismatch: The type \'Number\' is not a valid substitute for the type parameter \'@NonNull T extends Object\'\n" + + "----------\n" + + "2. ERROR in Y.java (at line 4)\n" + + " @NonNull Number nnn = inum.process(null); // ERR on argument\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Number\' but the provided value is null\n" + + "----------\n");} + +// apply default to type bound - method in inner class +public void testDefault07_bin() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "@NonNullByDefault(DefaultLocation.TYPE_BOUND)\n" + + "public class X {\n" + + " static class Inner {\n" + + " T process(T t, List l) {\n" + + " return t;\n" + + " }\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runNegativeTestWithLibs( + new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class Y {\n" + + " void test(X.Inner inner) {\n" + + " @NonNull Number nnn = inner.process(Integer.valueOf(3), new ArrayList<@Nullable Integer>()); // WARN on 1. arg; ERR on 2. arg\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Y.java (at line 5)\n" + + " @NonNull Number nnn = inner.process(Integer.valueOf(3), new ArrayList<@Nullable Integer>()); // WARN on 1. arg; ERR on 2. arg\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'Integer\' needs unchecked conversion to conform to \'@NonNull Integer\'\n" + + "----------\n" + + "2. ERROR in Y.java (at line 5)\n" + + " @NonNull Number nnn = inner.process(Integer.valueOf(3), new ArrayList<@Nullable Integer>()); // WARN on 1. arg; ERR on 2. arg\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'List\' but this expression has type \'@NonNull ArrayList<@Nullable Integer>\', corresponding supertype is \'List<@Nullable Integer>\'\n" + + "----------\n"); +} +public void testBug431269() { + runNegativeTest( + new String[] { + "p/QField.java", + "package p;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class QField, T> {\n" + + " @NonNull\n" + + " protected R m_root;\n" + + "\n" + + " public QField(@Nullable R root, @Nullable QField parent, @Nullable String propertyNameInParent) {\n" + + " m_root = root;\n" + + " }\n" + + "}\n", + "p/PLogLine.java", + "package p;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class PLogLine> extends QField {\n" + + " public PLogLine(@Nullable R root, @Nullable QField parent, @Nullable String name) {\n" + + " super(root, parent, name);\n" + + " }\n" + + "\n" + + " @NonNull\n" + + " public final QField lastName() {\n" + + " return new QField(m_root, this, \"lastName\");\n" + + " }\n" + + "\n" + + "}\n", + "p/LogLine.java", + "package p;\n" + + "\n" + + "public class LogLine {\n" + + " private String m_lastName;\n" + + "\n" + + " public String getLastName() {\n" + + " return m_lastName;\n" + + " }\n" + + "\n" + + " public void setLastName(String property) {\n" + + " m_lastName = property;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\QField.java (at line 10)\n" + + " m_root = root;\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull R extends QField,?>\' but this expression has type \'@Nullable R extends QField,?>\'\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p\\PLogLine.java (at line 12)\n" + + " return new QField(m_root, this, \"lastName\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from QField to QField\n" + + "----------\n", + this.LIBS, + true/*flush*/); +} +// was inferring null type annotations too aggressively +public void testBug432223() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " String val;\n" + + " public static @NonNull T assertNotNull(@Nullable T object) {\n" + + " return assertNotNull(null, object);\n" + + " }\n" + + "\n" + + " public static @NonNull T assertNotNull(@Nullable String message, @Nullable T object) {\n" + + " if (object == null) {\n" + + " throw new NullPointerException(message);\n" + + " }\n" + + " return object;\n" + + " }\n" + + " void test(@Nullable X x) {\n" + + " @NonNull X safe = assertNotNull(x);\n" + + " System.out.println(safe.val);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug432977() { + runConformTestWithLibs( + new String[] { + "Bar.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Bar {\n" + + " private String prop = \"\";\n" + + "\n" + + " public String getProp() {\n" + + " return prop;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runConformTestWithLibs( + false /* flush */, + new String[] { + "Fu.java", + "public class Fu {\n" + + " private Bar fubar = new Bar();\n" + + " \n" + + " public void method() {\n" + + " fubar.getProp().equals(\"\");\n" + + " } \n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug433586() { + runConformTestWithLibs( + new String[] { + "NullConversionWarning.java", + "import java.util.function.Consumer;\n" + + "public class NullConversionWarning {\n" + + "\n" + + " public Consumer peek2(Consumer action) {\n" + + " // Null type safety: parameter 1 provided via\n" + + " // method descriptor Consumer.accept(T) needs\n" + + " // unchecked conversion to conform to 'capture#of ? super T'\n" + + " Consumer action2 = action::accept;\n" + + " return action2;\n" + + " }\n" + + " void foo(Consumer action, T t) {\n" + + " Consumer action2 = t2 -> action.accept(t2);\n" + + " action.accept(t);\n" + + " action2.accept(t);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// NPE without the fix. +public void testBug433478() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault class Y { }\n" + + "\n" + + "interface I {\n" + + " @Nullable T foo();\n" + + "}\n" + + "\n" + + "@NonNullByDefault \n" + + "class X implements I {\n" + + " @Override\n" + + " public Y foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " return null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Y\' but the provided value is null\n" + + "----------\n"); +} +// https://bugs.eclipse.org/434899 +public void testTypeVariable6() { + runNegativeTestWithLibs( + new String[] { + "Assert.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Assert {\n" + + " public static void caller() {\n" + + " assertNotNull(\"not null\"); // Compiler error\n" + + " assertNotNull(null); // Compiler error\n" + + " }\n" + + " private static @NonNull T assertNotNull(@Nullable T object) {\n" + + " return object; // this IS bogus\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Assert.java (at line 8)\n" + + " return object; // this IS bogus\n" + + " ^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull T\' but this expression has type \'@Nullable T\'\n" + + "----------\n"); +} +// https://bugs.eclipse.org/434899 - variant which has always worked +public void testTypeVariable6a() { + runConformTestWithLibs( + new String[] { + "Assert.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Assert {\n" + + " public static Object caller() {\n" + + " @NonNull Object result = assertNotNull(\"not null\");\n" + + " result = assertNotNull(null);\n" + + " return result;\n" + + " }\n" + + " private static @NonNull T assertNotNull(@Nullable T object) {\n" + + " if (object == null) throw new NullPointerException();\n" + + " return object;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// Bug 438458 - [1.8][null] clean up handling of null type annotations wrt type variables +// - type parameter with explicit nullness, cannot infer otherwise +public void testTypeVariable7() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface I1 <@NonNull T> { T get(); }\n" + + "public class X {\n" + + " U m(I1 in) { return in.get(); }\n" + + " public void test(I1<@NonNull String> in) {\n" + + " @NonNull String s = m(in);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " U m(I1 in) { return in.get(); }\n" + + " ^\n" + + "Null constraint mismatch: The type \'U\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n"); +} +// Bug 438458 - [1.8][null] clean up handling of null type annotations wrt type variables +// - type parameter with explicit nullness, nullness must not spoil inference +public void testTypeVariable7a() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION, JavaCore.WARNING); // allow ignoring bad substitution + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface I1 <@NonNull T> { T get(); }\n" + + "public class X {\n" + + " U m(I1 in) { return in.get(); }\n" + + " public void test1() {\n" + + " @Nullable String s = m(() -> \"OK\");\n" + + " System.out.println(s);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().test1();\n" + + " }\n" + + "}\n" + }, + compilerOptions, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " U m(I1 in) { return in.get(); }\n" + + " ^\n" + + "Null constraint mismatch: The type \'U\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " @Nullable String s = m(() -> \"OK\");\n" + + " ^^^^^^^^^^\n" + + "Contradictory null annotations: function type was inferred as \'@NonNull @Nullable String ()\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n", + "OK"); +} +// Bug 438458 - [1.8][null] clean up handling of null type annotations wrt type variables +// - type parameter with explicit nullness, nullness must not spoil inference +public void testTypeVariable7err() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface I1 <@Nullable T> { T get(); }\n" + + "public class X {\n" + + " U m(I1 in) { return in.get(); }\n" + + " public void test1() {\n" + + " @NonNull String s = m(() -> \"\");\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " U m(I1 in) { return in.get(); }\n" + + " ^\n" + + "Null constraint mismatch: The type \'U\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " U m(I1 in) { return in.get(); }\n" + + " ^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'U\' but this expression has type \'@Nullable U\', where \'U\' is a free type variable\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " @NonNull String s = m(() -> \"\");\n" + + " ^^^^^^^^\n" + + "Contradictory null annotations: function type was inferred as \'@Nullable @NonNull String ()\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n"); +} +//Bug 435570 - [1.8][null] @NonNullByDefault illegally tries to affect "throws E" +public void testTypeVariable8() { + runConformTestWithLibs( + new String[] { + "Test.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class Test {\n" + + " void test() throws E {}\n" + // was: Nullness annotations are not applicable at this location + "}\n" + }, + getCompilerOptions(), + ""); +} +// Bug 438012 - Bogus Warning: The nullness annotation is redundant with a default that applies to this location +public void testTypeVariable9() { + runConformTestWithLibs( + new String[] { + "Bar.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" + + "\n" + + "@NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT, TYPE_PARAMETER })\n" + + "interface Bar {\n" + + " V getV(V in);\n" + + " void setV(V v);\n" + + "}" + }, + getCompilerOptions(), + ""); +} +// Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit type bound of binary type +public void testTypeVariable10() { + runConformTestWithLibs( + new String[] { + "X.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class X {\n" + + " void test(T t) {}\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runConformTestWithLibs( + false, + new String[] { + "Y.java", + "public class Y {\n" + + " void foo(X<@org.eclipse.jdt.annotation.Nullable String> xs) {\n" + + " xs.test(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit type bound of binary type +// Problem 1 from: Bug 438971 - [1.8][null] @NonNullByDefault/@Nullable on parameter of generic interface +public void testTypeVariable10a() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void test(@Nullable T t) {}\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runConformTestWithLibs( + false, + new String[] { + "Y.java", + "public class Y {\n" + + " void foo(X xs) {\n" + + " xs.test(\"OK\");\n" + // was: Contradictory null annotations: method was inferred as ... + " xs.test(null);\n" + // was: Contradictory null annotations: method was inferred as ... + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// Bug 439516 - [1.8][null] NonNullByDefault wrongly applied to implicit type bound of binary type +// warning for explicit "" +public void testTypeVariable11() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault({DefaultLocation.TYPE_BOUND})\n" + // not: PARAMETER + "public class X {\n" + + " void test(T t) {}\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " void foo(X<@org.eclipse.jdt.annotation.Nullable String> xs) {\n" + + " xs.test(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public class X {\n" + + " ^^^^^^\n" + + "The explicit type bound \'Object\' is not affected by the nullness default for DefaultLocation.TYPE_BOUND.\n" + + "----------\n"); +} +// Bug 438179 - [1.8][null] 'Contradictory null annotations' error on type variable with explicit null-annotation. +public void testTypeVariable12() { + runConformTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + " private Fu fu = new Fu<>();\n" + + " public void foo() {\n" + + " fu.method(); // 'Contradictory null annotations' error\n" + + " }\n" + + "}\n" + + "class Fu {\n" + + " @Nullable T method() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// Bug 438250 - [1.8][null] NPE trying to report bogus null annotation conflict +public void testTypeVariable13() { + runConformTestWithLibs( + new String[] { + "FooBar.java", + "@org.eclipse.jdt.annotation.NonNullByDefault(org.eclipse.jdt.annotation.DefaultLocation.TYPE_BOUND)\n" + + "public interface FooBar {\n" + + " <@org.eclipse.jdt.annotation.Nullable R extends Runnable> R foobar(R r);\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// Bug 438469 - [null] How-to use null type annotations with generic methods from interfaces in some library you only have as binary JAR? +public void testTypeVariable14() { + runConformTestWithLibs( + new String[] { + "ITest.java", + "interface ITest {\n" + + " T foo(T arg); // or arg Class or TypeToken + return TypeAdapter, etc.\n" + + "}" + }, + getCompilerOptions(), + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + runConformTestWithLibs( + false, + new String[] { + "Test.java", + "class Test implements ITest {\n" + + " @Override\n" + + " @SuppressWarnings(\"null\")\n" + + " public @org.eclipse.jdt.annotation.Nullable T foo(T arg) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + options, + ""); +} +// Bug 438467 - [compiler][null] Better error position for "The method _ cannot implement the corresponding method _ due to incompatible nullness constraints" +public void testTypeVariable15() { + runNegativeTestWithLibs( + new String[] { + "ITest.java", + "interface ITest {\n" + + " T foo(T arg); // or arg Class or TypeToken + return TypeAdapter, etc.\n" + + "}", + "Test.java", + "class Test implements ITest {\n" + + " @Override\n" + + " public @org.eclipse.jdt.annotation.Nullable T foo(T arg) {\n" + + " return null;\n" + + " }\n" + + "}\n", + "Test2.java", + "class Test2 implements ITest {\n" + + " @Override\n" + + " public T foo(@org.eclipse.jdt.annotation.NonNull T arg) {\n" + + " return arg;\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Test.java (at line 3)\n" + + " public @org.eclipse.jdt.annotation.Nullable T foo(T arg) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The return type is incompatible with the free type variable 'T' returned from ITest.foo(T) (mismatching null constraints)\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Test2.java (at line 3)\n" + + " public T foo(@org.eclipse.jdt.annotation.NonNull T arg) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter arg, inherited method from ITest does not constrain this parameter\n" + + "----------\n"); +} +// Bug 438467 - [compiler][null] Better error position for "The method _ cannot implement the corresponding method _ due to incompatible nullness constraints" +public void testTypeVariable15a() { + runNegativeTestWithLibs( + new String[] { + "ITest.java", + "import java.util.List;\n" + + "interface ITest {\n" + + " T foo(List arg); // or arg Class or TypeToken + return TypeAdapter, etc.\n" + + "}", + "Test.java", + "import java.util.List;\n" + + "class Test implements ITest {\n" + + " @Override\n" + + " public T foo(List<@org.eclipse.jdt.annotation.NonNull T> arg) {\n" + + " return arg.get(0);\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Test.java (at line 4)\n" + + " public T foo(List<@org.eclipse.jdt.annotation.NonNull T> arg) {\n" + + " ^^^^\n" + + "Illegal redefinition of parameter arg, inherited method from ITest declares this parameter as \'List\' (mismatching null constraints)\n" + + "----------\n" + + "2. INFO in Test.java (at line 5)\n" + + " return arg.get(0);\n" + + " ^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'List<@NonNull T>\'. Type \'List\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=434602 +// Possible error with inferred null annotations leading to contradictory null annotations +public void testTypeVariable16() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class Y { void doit() {} }\n" + + "@NonNullByDefault\n" + + "class X {\n" + + " void foo() {\n" + + " X x = new X();\n" + + " Y y = x.bar(); // Error: Contradictory null annotations before the fix\n" + + " y.doit(); // check that @Nullable from bar's declaration has effect on 'y'\n" + + " }\n" + + "\n" + + " public @Nullable T bar() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " y.doit(); // check that @Nullable from bar's declaration has effect on 'y'\n" + + " ^\n" + + "Potential null pointer access: The variable y may be null at this location\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=434602 +// Possible error with inferred null annotations leading to contradictory null annotations +// Method part of parameterized class. +public void testTypeVariable16a() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class Y {}\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " void foo() {\n" + + " X x = new X();\n" + + " x.bar(); // Error: Contradictory null annotations before the fix\n" + + " }\n" + + "\n" + + " public @Nullable T bar() {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testTypeVariable16b() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "class Y {}\n" + + "class Y2 extends Y {}\n" + + "\n" + + "class X {\n" + + " void foo() {\n" + + " X x = new X();\n" + + " x.bar(null); // null arg is illegal\n" + + " }\n" + + " public @Nullable T bar(T t) {\n" + + " return null; // OK\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " x.bar(null); // null arg is illegal\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Y\' but the provided value is null\n" + + "----------\n"); +} +// Bug 440143 - [1.8][null] one more case of contradictory null annotations regarding type variables +public void testTypeVariable17() { + runNegativeTestWithLibs( + new String[] { + "Test7.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Test7<@Nullable E> {\n" + + " E e;\n" + + "\n" + + " @Nullable\n" + + " E test() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " @NonNull\n" + + " E getNotNull() {\n" + + " if (e == null)\n" + + " throw new NullPointerException();\n" + + " return e;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Test7.java (at line 15)\n" + + " return e;\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull E\' but this expression has type \'@Nullable E\'\n" + + "----------\n"); +} +// Bug 440143 - [1.8][null] one more case of contradictory null annotations regarding type variables +// use local variable to avoid the null type mismatch +public void testTypeVariable17a() { + runConformTestWithLibs( + new String[] { + "Test7.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Test7<@Nullable E> {\n" + + " E e;\n" + + "\n" + + " @Nullable\n" + + " E test() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " @NonNull\n" + + " E getNotNull() {\n" + + " E el = e;\n" + + " if (el == null)\n" + + " throw new NullPointerException();\n" + + " return el;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// NPE reported in https://bugs.eclipse.org/bugs/show_bug.cgi?id=438458#c5 +public void testTypeVariable18() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface Lib1 {\n" + + " > T constrainedTypeParameter(@NonNull T in);\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " @NonNull Collection test4(Lib1 lib, @Nullable Collection in) {\n" + + " return lib.constrainedTypeParameter(in);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Test.java (at line 10)\n" + + " return lib.constrainedTypeParameter(in);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'Collection\' needs unchecked conversion to conform to \'@NonNull Collection\'\n" + + "----------\n" + + "2. ERROR in Test.java (at line 10)\n" + + " return lib.constrainedTypeParameter(in);\n" + + " ^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Collection\' but this expression has type \'@Nullable Collection\'\n" + + "----------\n"); +} +public void testTypeVariable18raw() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface Lib1 {\n" + + " > T constrainedTypeParameter(@NonNull T in);\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " @SuppressWarnings(\"rawtypes\")\n" + + " @NonNull Collection test4(Lib1 lib, @Nullable Collection in) {\n" + + " return lib.constrainedTypeParameter(in);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Test.java (at line 11)\n" + + " return lib.constrainedTypeParameter(in);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'Collection\' needs unchecked conversion to conform to \'@NonNull Collection\'\n" + + "----------\n" + + "2. ERROR in Test.java (at line 11)\n" + + " return lib.constrainedTypeParameter(in);\n" + + " ^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Collection\' but this expression has type \'@Nullable Collection\'\n" + + "----------\n"); +} +// top-level annotation is overridden at use-site, details remain - parameterized type +public void testTypeVariable19() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportNonNullTypeVariableFromLegacyInvocation, CompilerOptions.IGNORE); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "interface I> {\n" + + " U get0();\n" + + " @Nullable U get1();\n" + + " @NonNull U get2();\n" + + "}\n" + + "class X {\n" + + " static String test (I<@Nullable String, @NonNull ArrayList<@Nullable String>> i1,\n" + + " I<@NonNull String, @Nullable ArrayList<@NonNull String>> i2, int s) {\n" + + " switch(s) {\n" + + " case 0 : return i1.get0().get(0).toUpperCase(); // problem at detail\n" + + " case 1 : return i1.get1().get(0).toUpperCase(); // 2 problems\n" + + " case 2 : return i1.get2().get(0).toUpperCase(); // problem at detail\n" + + " case 3 : return i2.get0().get(0).toUpperCase(); // problem at top\n" + + " case 4 : return i2.get1().get(0).toUpperCase(); // problem at top\n" + + " case 5 : return i2.get2().get(0).toUpperCase(); // OK\n" + + " default : return \"\";" + + " }\n" + + " }\n" + + "}\n" + }, + compilerOptions, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " case 0 : return i1.get0().get(0).toUpperCase(); // problem at detail\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The method get(int) may return null\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " case 1 : return i1.get1().get(0).toUpperCase(); // 2 problems\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: The method get1() may return null\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " case 1 : return i1.get1().get(0).toUpperCase(); // 2 problems\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The method get(int) may return null\n" + + "----------\n" + + "4. ERROR in X.java (at line 17)\n" + + " case 2 : return i1.get2().get(0).toUpperCase(); // problem at detail\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential null pointer access: The method get(int) may return null\n" + + "----------\n" + + "5. ERROR in X.java (at line 18)\n" + + " case 3 : return i2.get0().get(0).toUpperCase(); // problem at top\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: The method get0() may return null\n" + + "----------\n" + + "6. ERROR in X.java (at line 19)\n" + + " case 4 : return i2.get1().get(0).toUpperCase(); // problem at top\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: The method get1() may return null\n" + + "----------\n"); +} +// top-level annotation is overridden at use-site, array with anotations on dimensions +public void testTypeVariable19a() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "interface I1 {\n" + + " T @Nullable[] get0();\n" + + " @Nullable T @NonNull[] get1();\n" + + " @Nullable T @Nullable[] get2();\n" + + "}\n" + + "interface I2 {\n" + + " T @NonNull[] get0();\n" + + " @NonNull T @NonNull[] get1();\n" + + " @NonNull T @Nullable[] get2();\n" + + "}\n" + + "class X {\n" + + " static String test (I1<@NonNull String> i1, I2<@Nullable String> i2, int s) {\n" + + " switch (s) {\n" + + " case 0: return i1.get0()[0].toUpperCase(); // problem on array\n" + + " case 1: return i1.get1()[0].toUpperCase(); // problem on element\n" + + " case 2: return i1.get2()[0].toUpperCase(); // 2 problems\n" + + " case 3: return i2.get0()[0].toUpperCase(); // problem on element\n" + + " case 4: return i2.get1()[0].toUpperCase(); // OK\n" + + " case 5: return i2.get2()[0].toUpperCase(); // problem on array\n" + + " default: return \"\";\n" + + " }\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " case 0: return i1.get0()[0].toUpperCase(); // problem on array\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: The method get0() may return null\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " case 1: return i1.get1()[0].toUpperCase(); // problem on element\n" + + " ^^^^^^^^^^^^\n" + + "Potential null pointer access: array element may be null\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " case 2: return i1.get2()[0].toUpperCase(); // 2 problems\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: The method get2() may return null\n" + + "----------\n" + + "4. ERROR in X.java (at line 18)\n" + + " case 2: return i1.get2()[0].toUpperCase(); // 2 problems\n" + + " ^^^^^^^^^^^^\n" + + "Potential null pointer access: array element may be null\n" + + "----------\n" + + "5. ERROR in X.java (at line 19)\n" + + " case 3: return i2.get0()[0].toUpperCase(); // problem on element\n" + + " ^^^^^^^^^^^^\n" + + "Potential null pointer access: array element may be null\n" + + "----------\n" + + "6. ERROR in X.java (at line 21)\n" + + " case 5: return i2.get2()[0].toUpperCase(); // problem on array\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: The method get2() may return null\n" + + "----------\n"); +} +public void testTypeVariable20() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "interface I<@Nullable T> { }\n" + + "public class X implements I {}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public class X implements I {}\n" + + " ^^^^^^\n" + + "Null constraint mismatch: The type \'String\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n"); +} +public void testBug434600() { + runConformTestWithLibs( + new String[] { + "bug/Main.java", + "package bug;\n" + + "public class Main {\n" + + " public static void main(final String[] args) {\n" + + " System.out.println(\"Hello World\");\n" + + " }\n" + + "}\n", + "bug/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package bug;\n", + "bug/ExpressionNode.java", + "package bug;\n" + + "\n" + + "public interface ExpressionNode extends CopyableNode {\n" + + " \n" + + "}\n", + "bug/ExtendedNode.java", + "package bug;\n" + + "\n" + + "public interface ExtendedNode {\n" + + " \n" + + "}\n", + "bug/CopyableNode.java", + "package bug;\n" + + "\n" + + "public interface CopyableNode extends ExtendedNode {\n" + + " \n" + + "}\n" + }, + getCompilerOptions(), + "", + "Hello World"); +} +public void testBug434600a() { + runConformTestWithLibs( + new String[] { + "I.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "interface I>> {\n" + + "}\n", + "C.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class C implements I<@Nullable String, @Nullable ArrayList<@NonNull List<@Nullable String>>> {}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug434600a_qualified() { + runConformTestWithLibs( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public interface I>> {\n" + + "}\n", + "C.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class C implements p.I>> {}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug434600b() { + runNegativeTestWithLibs( + new String[] { + "I.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "interface I>> {\n" + + "}\n", + "C.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class C implements I<@Nullable String, ArrayList<@NonNull List<@Nullable String>>> {}\n" + + "class C1 {\n" + + " I>> field;\n" + + "}\n" + + "class C2 implements I<@NonNull String, @NonNull ArrayList<@NonNull List<@Nullable String>>> {}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in C.java (at line 3)\n" + + " public class C implements I<@Nullable String, ArrayList<@NonNull List<@Nullable String>>> {}\n" + + " ^^^^^^^^^\n" + + "Null constraint mismatch: The type \'ArrayList<@NonNull List<@Nullable String>>\' is not a valid substitute for the type parameter \'T extends @NonNull List<@NonNull List>\'\n" + + "----------\n" + + "2. ERROR in C.java (at line 5)\n" + + " I>> field;\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull ArrayList<@Nullable List>\' is not a valid substitute for the type parameter \'T extends @NonNull List<@NonNull List>\'\n" + + "----------\n" + + "3. ERROR in C.java (at line 7)\n" + + " class C2 implements I<@NonNull String, @NonNull ArrayList<@NonNull List<@Nullable String>>> {}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull ArrayList<@NonNull List<@Nullable String>>\' is not a valid substitute for the type parameter \'T extends @NonNull List<@NonNull List>\'\n" + + "----------\n"); +} +public void testBug434600b_qualified() { + runNegativeTestWithLibs( + new String[] { + "p/I.java", + "package p;\n" + + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public interface I>> {\n" + + "}\n", + "C.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class C implements p.I<@Nullable String, ArrayList<@NonNull List<@Nullable String>>> {}\n" + + "class C1 {\n" + + " p.I>> field;\n" + + "}\n" + + "class C2 implements p.I<@NonNull String, @Nullable ArrayList<@NonNull List<@Nullable String>>> {}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in C.java (at line 5)\n" + + " p.I>> field;\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable ArrayList<@Nullable List>\' is not a valid substitute for the type parameter \'T extends @Nullable List<@NonNull List>\'\n" + + "----------\n" + + "2. ERROR in C.java (at line 7)\n" + + " class C2 implements p.I<@NonNull String, @Nullable ArrayList<@NonNull List<@Nullable String>>> {}\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable ArrayList<@NonNull List<@Nullable String>>\' is not a valid substitute for the type parameter \'T extends @Nullable List<@NonNull List>\'\n" + + "----------\n"); +} +public void testBug435399() { + runConformTestWithLibs( + new String[] { + "bug/Bug1.java", + "package bug;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class Bug1 {\n" + + " public static void method(@Nullable T value, T defaultValue) {\n" + + " }\n" + + " public void invoke() {\n" + + " method(Integer.valueOf(1), Boolean.TRUE);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug435962() { + runConformTestWithLibs( + new String[] { + "interfaces/CopyableNode.java", + "package interfaces;\n" + + "public interface CopyableNode extends ExtendedNode {\n" + + " public T deepCopy();\n" + + "}\n", + "interfaces/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package interfaces;\n", + "interfaces/ExtendedNode.java", + "package interfaces;\n" + + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public interface ExtendedNode {\n" + + " ExtendedNode getParent();\n" + + " void setParent(ExtendedNode newParent);\n" + + " int numChildren();\n" + + " void mutateNode(ExtendedNode root);\n" + + " void getAllNodes(ArrayList array);\n" + + " ExtendedNode getNode(int nodeIndex);\n" + + " void getNodesOfType(Class desiredType,\n" + + " ArrayList array);\n" + + " @Nullable N getRandomNodeOfType(\n" + + " Class desiredType, ExtendedNode root, ExtendedNode caller);\n" + + "}\n", + "interfaces/ValueNode.java", + "package interfaces;\n" + + "public interface ValueNode extends ExtendedNode {\n" + + "}\n", + "framework/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package framework;\n", + "framework/BinaryOpNode.java", + "package framework;\n" + + "\n" + + "import interfaces.CopyableNode;\n" + + "import interfaces.ValueNode;\n" + + "public abstract class BinaryOpNode, O>\n" + + " extends EqualBinaryNode implements ValueNode {\n" + + " @SuppressWarnings(\"unused\") private O op;\n" + + " \n" + + " protected BinaryOpNode(final T left, @org.eclipse.jdt.annotation.NonNull final O op, final T right) {\n" + + " super(left, right);\n" + + " this.op = op;\n" + + " }\n" + + "}\n", + "framework/EqualBinaryNode.java", + "package framework;\n" + + "\n" + + "import interfaces.CopyableNode;\n" + + "import interfaces.ExtendedNode;\n" + + "public abstract class EqualBinaryNode>\n" + + " implements ExtendedNode {\n" + + " protected T left;\n" + + " protected T right;\n" + + " \n" + + " protected EqualBinaryNode(final T left, final T right) {\n" + + " this.left = left;\n" + + " this.right = right;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug440462() { + runConformTestWithLibs( + new String[]{ + "CompilerError.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "import java.util.*;\n" + + "@NonNullByDefault\n" + + "public class CompilerError {\n" + + "\n" + + " List<@Nullable ? extends Integer> list = new ArrayList<@Nullable Integer>();\n" + // FIXME: should be able to use diamond! + "\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug440773() { + runConformTestWithLibs( + new String[] { + "CountingComparator.java", + "import java.util.Comparator;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "\n" + + "@NonNullByDefault\n" + + "public class CountingComparator implements Comparator {\n" + + "\n" + + " private int m_accessCount = 0;\n" + + "\n" + + " private final Comparator m_wrapped;\n" + + "\n" + + " public CountingComparator(final Comparator wrapped) {\n" + + " m_wrapped = wrapped;\n" + + " }\n" + + "\n" + + " @Override\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " public int compare(final T element1, final T element2) {\n" + + " m_accessCount++;\n" + + " return m_wrapped.compare(element1, element2);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug439298_comment2() { + runConformTestWithLibs( + new String[] { + "Extract.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "class R {\n" + + " R(@Nullable T t) {}\n" + + "}\n" + + "class A {}\n" + + "@NonNullByDefault\n" + + "public class Extract {\n" + + " R test() {\n" + + " return new R(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug439298_comment3() { + runWarningTestWithLibs( + true, + new String[] { + "Extract.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "class R {\n" + + " R(@Nullable T t) {}\n" + + "}\n" + + "class A {}\n" + + "public class Extract {\n" + + " R test() {\n" + + " return new R<@NonNull A>(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. INFO in Extract.java (at line 9)\n" + + " return new R<@NonNull A>(null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unsafe null type conversion (type annotations): The value of type '@NonNull R<@NonNull A>' is made accessible using the less-annotated type 'R'\n" + + "----------\n"); +} +public void testBug439298_comment4() { + runConformTestWithLibs( + new String[] { + "Extract.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "class R {\n" + + " R(@Nullable T t) {}\n" + + "}\n" + + "class A {}\n" + + "public class Extract {\n" + + " R<@NonNull A> test() {\n" + + " return new R<>(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// this code raised: java.lang.IllegalArgumentException: Type doesn't have its own method? +// at org.eclipse.jdt.internal.compiler.lookup.SyntheticFactoryMethodBinding.applyTypeArgumentsOnConstructor(SyntheticFactoryMethodBinding.java:40) +public void testBug440764() { + runNegativeTestWithLibs( + new String[] { + "Extract.java", + "import java.util.Comparator;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@NonNullByDefault({ DefaultLocation.TYPE_PARAMETER })\n" + + "public class Extract implements Comparator<@NonNull T> {\n" + // FIXME: annot on 'T' shouldn't be needed + " public Extract(Comparator wrapped) {\n" + + " }\n" + + "\n" + + " @Override\n" + + " public int compare(T o1, T o2) {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " void test(final Comparator<@Nullable Integer> c) {\n" + + " new Extract<>(c).compare(1, null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Extract.java (at line 16)\n" + + " new Extract<>(c).compare(1, null);\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'Comparator<@NonNull Integer>\' but this expression has type \'Comparator<@Nullable Integer>\'\n" + + "----------\n" + + "2. ERROR in Extract.java (at line 16)\n" + + " new Extract<>(c).compare(1, null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Integer\' but the provided value is null\n" + + "----------\n"); +} +public void testBug440759a() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " T test(T t) {\n" + + " @NonNull T localT = t; // err#1\n" + + " return null; // err must mention free type variable, not @NonNull\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @NonNull T localT = t; // err#1\n" + + " ^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " return null; // err must mention free type variable, not @NonNull\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): \'null\' is not compatible to the free type variable \'T\'\n" + + "----------\n"); +} +// involves overriding, work done in ImplicitNullAnnotationVerifier.checkNullSpecInheritance() +public void testBug440759b() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface Y {\n" + + " T test(T t);\n" + + "}\n" + + "@NonNullByDefault\n" + + "public class X implements Y {\n" + + " public T test(T t) {\n" + + " @NonNull T localT = t; // err#1\n" + + " return null; // err must mention free type variable, not @NonNull\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " @NonNull T localT = t; // err#1\n" + + " ^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " return null; // err must mention free type variable, not @NonNull\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): \'null\' is not compatible to the free type variable \'T\'\n" + + "----------\n"); +} +public void testBug438383() { + runConformTestWithLibs( + new String[] { + "Foo.java", + "import java.util.*;\n" + + "import java.util.function.Supplier;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault public class Foo {\n" + + " static void foo(Supplier> f) { }\n" + + " \n" + + " static void test() {\n" + + " foo(ArrayList::new);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug437270() { + runConformTestWithLibs( + new String[] { + "Foo.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Foo {\n" + + " void test(String[] arguments) {\n" + + " if (arguments != null) {\n" + + " String @NonNull [] temp = arguments;\n" + + " }\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug437270_comment3() { + runConformTestWithLibs( + new String[] { + "Foo.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Foo {\n" + + " void test() {\n" + + " @NonNull Object b = new Object();\n" + + " Object @NonNull[] c = { new Object() };\n" + + " \n" + + " test2( b );\n" + + " test3( c );\n" + + " }\n" + + " \n" + + " void test2(@Nullable Object z) { }\n" + + " \n" + + " void test3(Object @Nullable[] z) { }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug435841() { + runConformTestWithLibs( + new String[] { + "ArrayProblem.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class ArrayProblem {\n" + + " private String[] data = new String[0];\n" + + " \n" + + " void error1() {\n" + + " foo(data); // Compiler error: required 'String @Nullable[]', but this expression has type 'String @NonNull[]'\n" + + " }\n" + + " \n" + + " private String[] foo(String @Nullable[] input) {\n" + + " return new String[0];\n" + + " }\n" + + " \n" + + " String @Nullable[] error2() {\n" + + " String @NonNull[] nonnull = new String[0];\n" + + " return nonnull; // Compiler error: required 'String @Nullable[]' but this expression has type 'String @NonNull[]'\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug441693() { + runConformTestWithLibs( + new String[] { + "Foo.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault({})\n" + + "public abstract class Foo {\n" + + " \n" + + " abstract @NonNull T requireNonNull(@Nullable T obj);\n" + + " \n" + + " @NonNull Iterable<@NonNull String> iterable;\n" + + " \n" + + " Foo(@Nullable Iterable<@NonNull String> iterable) {\n" + + " this.iterable = requireNonNull(iterable); // (*)\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug441693other() { + runNegativeTestWithLibs( + new String[] { + "Foo.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "import java.util.*;\n" + + "\n" + + "@NonNullByDefault({})\n" + + "public abstract class Foo {\n" + + " \n" + + " abstract @NonNull T requireNonNull(@Nullable T obj);\n" + + " \n" + + " @NonNull String @NonNull[] array;\n" + + " \n" + + " Foo(@NonNull String @Nullable[] arr) {\n" + + " this.array = requireNonNull(arr); // (*)\n" + + " }\n" + + " @NonNull Foo testWild1(@Nullable List foos) {\n" + + " return requireNonNull(foos).get(0);\n" + + " }\n" + + " @NonNull Foo testWild2(@Nullable List<@Nullable ? extends List<@NonNull Foo>> foos) {\n" + + " return requireNonNull(foos.get(0)).get(0);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. INFO in Foo.java (at line 17)\n" + + " return requireNonNull(foos).get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull List\'. Type \'List\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n" + + "2. INFO in Foo.java (at line 20)\n" + + " return requireNonNull(foos.get(0)).get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'List<@NonNull Foo>\'. Type \'List\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n" + + "3. ERROR in Foo.java (at line 20)\n" + + " return requireNonNull(foos.get(0)).get(0);\n" + + " ^^^^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=439158, [1.8][compiler][null] Adding null annotation to return type causes IllegalStateException and sometimes InvocationTargetException +public void testBug439158() { + runConformTestWithLibs( + new String[] { + "Test.java", + "import java.util.Collection;\n" + + "import java.util.List;\n" + + "import java.util.Set;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Test {\n" + + " class X {\n" + + " \n" + + " }\n" + + " \n" + + " public static , A extends C, B extends C>\n" + + " @Nullable A transform(B arg) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " List list = null;\n" + + " Set result = transform(list);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=434579, [1.8][compiler][null] Annotation-based null analysis causes incorrect type errors +public void testBug434579() { + Map options = getCompilerOptions(); + runConformTestWithLibs( + new String[] { + "AbstractNode.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "interface ExtendedNode {\n" + + " ExtendedNode getParent();\n" + + " void setParent(ExtendedNode newParent);\n" + + "}\n" + + "@NonNullByDefault\n" + + "public class AbstractNode implements ExtendedNode {\n" + + " private ExtendedNode parent;\n" + + " protected AbstractNode() {\n" + + " parent = this;\n" + + " }\n" + + " @Override\n" + + " public ExtendedNode getParent() {\n" + + " return parent;\n" + + " }\n" + + " @Override\n" + + " public void setParent(final ExtendedNode newParent) {\n" + + " parent = newParent;\n" + + " }\n" + + "}\n" + }, + options, + ""); + runNegativeTestWithLibs( + new String[] { + "UnequalBinaryNode.java", + "public class UnequalBinaryNode\n" + + " extends AbstractNode {\n" + + " private L left;\n" + + " private R right;\n" + + " public UnequalBinaryNode(final L initialLeft, final R initialRight) {\n" + + " left = initialLeft;\n" + + " right = initialRight;\n" + + " left.setParent(this);\n" + + " right.setParent(this); // error on this line without fix\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in UnequalBinaryNode.java (at line 8)\n" + + " left.setParent(this);\n" + + " ^^^^\n" + + "Potential null pointer access: this expression has type \'L\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in UnequalBinaryNode.java (at line 9)\n" + + " right.setParent(this); // error on this line without fix\n" + + " ^^^^^\n" + + "Potential null pointer access: this expression has type \'R\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=434582, +//[1.8][compiler][null] @Nullable annotation in type parameter causes NullPointerException in JDT core +public void testBug434582() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "class ProgramNode {}\n" + + "@NonNullByDefault\n" + + "interface ConcreteNodeVisitor {\n" + + " R visit(ProgramNode node, P extraParameter);\n" + + "}\n" + + "public class X implements\n" + + " ConcreteNodeVisitor {\n" + + " public Boolean visit(ProgramNode node, Object extraParameter) {\n" + + " return Boolean.FALSE;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " public Boolean visit(ProgramNode node, Object extraParameter) {\n" + + " ^^^^^^^^^^^\n" + + "Missing non-null annotation: inherited method from ConcreteNodeVisitor specifies this parameter as @NonNull\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " public Boolean visit(ProgramNode node, Object extraParameter) {\n" + + " ^^^^^^\n" + + "Missing nullable annotation: inherited method from ConcreteNodeVisitor specifies this parameter as @Nullable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=434582, +//[1.8][compiler][null] @Nullable annotation in type parameter causes NullPointerException in JDT core +public void testBug434582a() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "@NonNullByDefault\n" + + "class ProgramNode {}\n" + + "@NonNullByDefault\n" + + "interface ConcreteNodeVisitor {\n" + + " void visit(ProgramNode node, P extraParameter);\n" + + "}\n" + + "public class X implements\n" + + " ConcreteNodeVisitor {\n" + + " public void visit(ProgramNode node, Object extraParameter) {}\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " public void visit(ProgramNode node, Object extraParameter) {}\n" + + " ^^^^^^^^^^^\n" + + "Missing non-null annotation: inherited method from ConcreteNodeVisitor specifies this parameter as @NonNull\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " public void visit(ProgramNode node, Object extraParameter) {}\n" + + " ^^^^^^\n" + + "Missing nullable annotation: inherited method from ConcreteNodeVisitor specifies this parameter as @Nullable\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=443467, [1.8][null]InternalError: Unexpected binding type +public void test443467() throws Exception { + runNegativeTest( + new String[] { + "BuildIdeMain.java", + "import java.nio.file.Path;\n" + + "import java.time.Instant;\n" + + "import java.util.AbstractMap.SimpleEntry;\n" + + "import java.util.HashMap;\n" + + "import java.util.stream.Stream;\n" + + "\n" + + "public class BuildIdeMain {\n" + + "static void writeUpdates(Stream filter2, HashMap> ideFiles, HashMap updateToFile) {\n" + + " filter2.map(p -> new SimpleEntry<>(updateToFile.get(p), p->ideFiles.get(p)));\n" + + "}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in BuildIdeMain.java (at line 9)\n" + + " filter2.map(p -> new SimpleEntry<>(updateToFile.get(p), p->ideFiles.get(p)));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot infer type arguments for SimpleEntry<>\n" + + "----------\n", + this.LIBS, + true/*flush*/); +} +public void testBug445227() { + runConformTestWithLibs( + new String[] { + "Bar.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "class Bar> {\n" + + " final Iterable list;\n" + + "\n" + + " Bar() {\n" + + " this((Iterable) emptyList());\n" + + " }\n" + + "\n" + + " Bar(Iterable list) { this.list = list; }\n" + + "\n" + + " private static > Iterable emptyList() { throw new UnsupportedOperationException(); }\n" + + "\n" + + " interface Foo> { }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Bar.java (at line 6)\n" + + " this((Iterable) emptyList());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Iterable>> to Iterable\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=446715, [compiler] org.eclipse.jdt.internal.compiler.lookup.TypeSystem.cacheDerivedType +public void test446715() { + Map options = getCompilerOptions(); + runConformTestWithLibs( + new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "public class Y {\n" + + " public Z.ZI @NonNull [] zz = new Z.ZI[0];\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " public class ZI {\n" + + " }\n" + + "}\n" + }, + options, + ""); + runNegativeTestWithLibs( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Y y = new Y();\n" + + " y.zz = null;\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " y.zz = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'Z.ZI @NonNull[]\' but the provided value is null\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=445669, java.lang.IllegalStateException at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.clone +public void test445669() { + Map options = getCompilerOptions(); + runConformTestWithLibs( + new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault(DefaultLocation.FIELD)\n" + + "public class Y {\n" + + " public Z.ZI zzi = new Z().new ZI();\n" + + " public Z z = new Z();\n" + + "}\n", + "Z.java", + "public class Z {\n" + + " public class ZI {\n" + + " }\n" + + "}\n" + }, + options, + ""); + runNegativeTestWithLibs( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Y y = new Y();\n" + + " y.zzi = null;\n" + + " y.z = null;\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " y.zzi = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'Z.@NonNull ZI\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " y.z = null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Z\' but the provided value is null\n" + + "----------\n"); +} +public void testArrayOfArrays() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Arrays;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String [] @Nullable [] @NonNull [] arr = new String[][][] {};\n" + + " ArrayList al = new ArrayList(Arrays.asList(arr));\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " String [] @Nullable [] @NonNull [] arr = new String[][][] {};\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[][][]\' needs unchecked conversion to conform to \'String [] @Nullable[] @NonNull[]\'\n" + + "----------\n"); +} +public void testBug447088() { + runConformTestWithLibs( + new String[] { + "FullyQualifiedNullable.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "public class FullyQualifiedNullable {\n" + + " java.lang.@Nullable String text;\n" + + " java.lang.@Nullable String getText() {\n" + + " return text;\n" + + " }\n" + + "}\n" + }, + null, + ""); +} +public void testBug448777() { + runNegativeTestWithLibs( + new String[] { + "DoubleInference.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class DoubleInference {\n" + + "\n" + + " @FunctionalInterface\n" + + " interface Func<@Nullable T> {\n" + + " T a(T i);\n" + + " }\n" + + "\n" + + " X applyWith(Func f, X x) { return x; }\n" + + "\n" + + " @NonNull String test1() {\n" + + " return applyWith(i -> i, \"hallo\");\n" + + " }\n" + + " void test2(Func f1, Func<@NonNull String> f2) {\n" + + " f1.a(null);\n" + + " f2.a(null);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in DoubleInference.java (at line 10)\n" + + " X applyWith(Func f, X x) { return x; }\n" + + " ^\n" + + "Null constraint mismatch: The type \'X\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "2. ERROR in DoubleInference.java (at line 13)\n" + + " return applyWith(i -> i, \"hallo\");\n" + + " ^^^^^^\n" + + "Contradictory null annotations: function type was inferred as \'@Nullable @NonNull String (@Nullable @NonNull String)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n" + + "3. ERROR in DoubleInference.java (at line 15)\n" + + " void test2(Func f1, Func<@NonNull String> f2) {\n" + + " ^^^^^^\n" + + "Null constraint mismatch: The type \'String\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "4. ERROR in DoubleInference.java (at line 15)\n" + + " void test2(Func f1, Func<@NonNull String> f2) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "5. ERROR in DoubleInference.java (at line 17)\n" + + " f2.a(null);\n" + + " ^^^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'@Nullable @NonNull String a(@Nullable @NonNull String)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n"); +} +public void testBug446442_comment2a() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface Foo {\n" + + " void m(@NonNull N arg2);\n" + + "\n" + + " void m(@Nullable T arg1);\n" + + "}\n" + + "\n" + + "interface Baz extends Foo {}\n" + + "\n" + + "class Impl implements Baz {\n" + + " public void m(@NonNull Integer i) {}\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " Baz baz= x -> {\n" + + " x= null;\n" + + " }; \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 11)\n" + + " public void m(@NonNull Integer i) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter i, inherited method from Foo declares this parameter as @Nullable\n" + + "----------\n"); +} +// swapped order of method declarations +public void testBug446442_comment2b() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface Foo {\n" + + " void m(@Nullable T arg1);\n" + + "\n" + + " void m(@NonNull N arg2);\n" + + "}\n" + + "\n" + + "interface Baz extends Foo {}\n" + + "\n" + + "class Impl implements Baz {\n" + + " public void m(@NonNull Integer i) {}\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " Baz baz= x -> {\n" + + " x= null;\n" + + " }; \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 11)\n" + + " public void m(@NonNull Integer i) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter i, inherited method from Foo declares this parameter as @Nullable\n" + + "----------\n"); +} +// inherit from two different supers +public void testBug446442_comment2c() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface Foo0 {\n" + + " void m(@Nullable T arg1);\n" + + "}\n" + + "\n" + + "interface Foo1 {\n" + + " void m(@NonNull N arg2);\n" + + "}\n" + + "\n" + + "interface Baz extends Foo1, Foo0 {}\n" + + "\n" + + "class Impl implements Baz {\n" + + " public void m(@NonNull Integer i) {}\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " Baz baz= x -> {\n" + + " x= null;\n" + + " }; \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 13)\n" + + " public void m(@NonNull Integer i) {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter i, inherited method from Foo0 declares this parameter as @Nullable\n" + + "----------\n"); +} +// merging @NonNull & unannotated in arg-position must answer unannotated +public void testBug446442_2a() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface Foo {\n" + + " void m(@NonNull N arg2);\n" + + "\n" + + " void m(T arg1);\n" + + "}\n" + + "\n" + + "interface Baz extends Foo {}\n" + + "\n" + + "public class Test {\n" + + " Baz baz= x -> {\n" + + " @NonNull Object o = x;\n" + + " }; \n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Test.java (at line 12)\n" + + " @NonNull Object o = x;\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'Integer\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n"); +} +// merging @NonNull & unannotated in arg-position must answer unannotated - swapped order +public void testBug446442_2b() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface Foo {\n" + + " void m(T arg1);\n" + + "\n" + + " void m(@NonNull N arg2);\n" + + "}\n" + + "\n" + + "interface Baz extends Foo {}\n" + + "\n" + + "public class Test {\n" + + " Baz baz= x -> {\n" + + " @NonNull Object o = x;\n" + + " }; \n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Test.java (at line 12)\n" + + " @NonNull Object o = x;\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'Integer\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n"); +} +// using inherited implementation to fulfill both contracts +public void testBug446442_3() { + runConformTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface Foo {\n" + + " void m(@NonNull N arg2);\n" + + "\n" + + " void m(T arg1);\n" + + "}\n" + + "\n" + + "interface Baz extends Foo {}\n" + + "class Impl {\n" + + " public void m(Integer a) {}\n" + + "}\n" + + "class BazImpl extends Impl implements Baz {}\n" + + "\n" + + "public class Test {\n" + + " void test(BazImpl b) {\n" + + " b.m(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// unsuccessful attempt to trigger use of MostSpecificExceptionMethodBinding +public void testBug446442_4() { + runConformTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface Foo {\n" + + " abstract void m(@NonNull N arg2) throws Exception;\n" + + "\n" + + " default void m(T arg1) throws java.io.IOException {}\n" + + "}\n" + + "\n" + + "interface Baz extends Foo {}\n" + + "abstract class Impl {\n" + + " public void m(Integer a) throws java.io.IOException {}\n" + + "}\n" + + "class BazImpl extends Impl implements Baz {}\n" + + "\n" + + "public class Test {\n" + + " void test(BazImpl b) throws java.io.IOException {\n" + + " b.m(null);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// annotated return types +public void testBug446442_5() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface Foo {\n" + + " T m(T t);\n" + + "\n" + + " @NonNull N m(N n);\n" + + "}\n" + + "\n" + + "interface Baz extends Foo {}\n" + + "\n" + + "class Impl implements Baz {\n" + + " public Integer m(Integer i) { return Integer.valueOf(0); }\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " Baz baz= x -> null;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 11)\n" + + " public Integer m(Integer i) { return Integer.valueOf(0); }\n" + + " ^^^^^^^\n" + + "The return type is incompatible with \'@NonNull Integer\' returned from Foo.m(Integer) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 15)\n" + + " Baz baz= x -> null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Integer\' but the provided value is null\n" + + "----------\n"); +} +// conflicting annotations on type arguments +public void testBug446442_6a() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "interface Foo, C2 extends List> {\n" + + " void m(C1 a1);\n" + + "\n" + + " void m(C2 a2);\n" + + "}\n" + + "\n" + + "interface Baz extends Foo, ArrayList<@Nullable Integer>> {}\n" + + "\n" + + "class Impl implements Baz {\n" + + " public void m(ArrayList<@NonNull Integer> i) {} // contradictory type cannot be implemented\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " Baz baz= x -> { // contradictory type cannot be used as SAM\n" + + " x.add(null); // contradictory type cause errors at call sites\n" + + " }; \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 12)\n" + + " public void m(ArrayList<@NonNull Integer> i) {} // contradictory type cannot be implemented\n" + + " ^^^^^^^^^\n" + + "Illegal redefinition of parameter i, inherited method from Foo,ArrayList> declares this parameter as \'ArrayList<@Nullable Integer>\' (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 16)\n" + + " Baz baz= x -> { // contradictory type cannot be used as SAM\n" + + " x.add(null); // contradictory type cause errors at call sites\n" + + " }; \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null annotations: function type was inferred as \'void (ArrayList<@NonNull @Nullable Integer>)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n" + + "3. ERROR in Test.java (at line 17)\n" + + " x.add(null); // contradictory type cause errors at call sites\n" + + " ^^^^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'boolean add(@NonNull @Nullable Integer)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n"); +} +// swapped order of method declarations + added return type +public void testBug446442_6b() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "interface Foo, C2 extends List> {\n" + + " C2 m(C2 a2);\n" + + "\n" + + " C1 m(C1 a1);\n" + + "}\n" + + "\n" + + "interface Baz extends Foo, ArrayList<@Nullable Integer>> {}\n" + + "\n" + + "class Impl implements Baz {\n" + + " public ArrayList<@NonNull Integer> m(ArrayList<@Nullable Integer> i) { return i; }\n" + + "}\n" + + "\n" + + "public class Test {\n" + + " Baz baz= x -> {\n" + + " x.add(null);\n" + + " x.get(0);\n" + + " return x;\n" + + " };\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 12)\n" + + " public ArrayList<@NonNull Integer> m(ArrayList<@Nullable Integer> i) { return i; }\n" + + " ^^^^^^^^^\n" + + "The return type is incompatible with \'ArrayList<@Nullable Integer>\' returned from Foo,ArrayList>.m(ArrayList) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in Test.java (at line 12)\n" + + " public ArrayList<@NonNull Integer> m(ArrayList<@Nullable Integer> i) { return i; }\n" + + " ^^^^^^^^^\n" + + "Illegal redefinition of parameter i, inherited method from Foo,ArrayList> declares this parameter as \'ArrayList<@NonNull Integer>\' (mismatching null constraints)\n" + + "----------\n" + + "3. ERROR in Test.java (at line 12)\n" + + " public ArrayList<@NonNull Integer> m(ArrayList<@Nullable Integer> i) { return i; }\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'ArrayList<@NonNull Integer>\' but this expression has type \'ArrayList<@Nullable Integer>\'\n" + + "----------\n" + + "4. ERROR in Test.java (at line 16)\n" + + " Baz baz= x -> {\n" + + " x.add(null);\n" + + " x.get(0);\n" + + " return x;\n" + + " };\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null annotations: function type was inferred as \'ArrayList<@NonNull @Nullable Integer> (ArrayList<@Nullable @NonNull Integer>)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n" + + "5. ERROR in Test.java (at line 17)\n" + + " x.add(null);\n" + + " ^^^^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'boolean add(@Nullable @NonNull Integer)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n" + + "6. ERROR in Test.java (at line 18)\n" + + " x.get(0);\n" + + " ^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'@Nullable @NonNull Integer get(int)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n"); +} +public void testBug453475() { + runConformTestWithLibs( + new String[] { + "TestMap.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@NonNullByDefault\n" + + "public abstract class TestMap extends AbstractMap {\n" + + "\n" + + "}\n" + }, null, ""); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "Test.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + "\n" + + " public static final void test(TestMap testMap) {\n" + + " testMap.putAll(new HashMap()); // Error: Contradictory null annotations: method was inferred as 'void putAll(Map)', but only one of '@NonNull' and '@Nullable' can be effective at any location\n" + + " }\n" + + "\n" + + "}\n" + }, null, ""); +} +// also: don't apply default to use of type variable +public void testBug453475a() { + runConformTestWithLibs( + new String[] { + "NamespaceStorage.java", + "import java.util.*;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public interface NamespaceStorage \n" + + "{\n" + + "\n" + + " Set getObjects(); \n" + // here was wrongly read from .class as <@NonNull T> + " T getObject(T in);\n" + + "}\n" + }, null, ""); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "NamespaceStorageImpl.java", + "import java.util.*;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class NamespaceStorageImpl implements NamespaceStorage\n" + + "{\n" + + " @Override\n" + + " public Set getObjects() \n" + + " {\n" + + " return new TreeSet();\n" + + " }\n" + + " @Override\n" + + " public T getObject(T in)\n" + + " {\n" + + " return in;\n" + + " }\n" + + "}\n" + }, + null, ""); +} +// also: don't apply default to wildcard +public void testBug453475b() { + runConformTestWithLibs( + new String[] { + "X.java", + "import java.util.*;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public interface X {\n" + + "\n" + + " void test(List list);\n" + // here was wrongly read from .class as <@NonNull ?> + " \n" + + "}\n" + }, null, ""); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "Y.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y {\n" + + " public void run(X x, @NonNull List<@Nullable String> s) \n" + + " {\n" + + " x.test(s);\n" + + " }\n" + + "}\n" + }, + null, ""); +} +public void testBug456236() { + runConformTestWithLibs( + new String[] { + "Nullsafe.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class Nullsafe {\n" + + " final @Nullable T t;\n" + + "\n" + + " Nullsafe(@Nullable T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public static Nullsafe of(@Nullable U u) {\n" + + " return new Nullsafe<>(u); // compile error\n" + + " }\n" + + "}\n" + }, + null, + ""); +} + +public void testBug456497() throws Exception { + runConformTestWithLibs( + new String[] { + "libs/Lib1.java", + "package libs;\n" + + "\n" + + "import java.util.Collection;\n" + + "import java.util.Iterator;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public interface Lib1 {\n" + + " Iterator unconstrainedTypeArguments1(Collection<@Nullable T> in);\n" + + " Iterator<@NonNull String> unconstrainedTypeArguments2(Collection in);\n" + + "}\n", + "tests/Test1.java", + "package tests;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "import java.util.Collection;\n" + + "import java.util.Iterator;\n" + + "\n" + + "import libs.Lib1;\n" + + "\n" + + "public class Test1 {\n" + + " Iterator<@NonNull String> test1(Lib1 lib, Collection<@Nullable String> coll) {\n" + + " return lib.unconstrainedTypeArguments1(coll);\n" + + " }\n" + + " Iterator<@NonNull String> test2(Lib1 lib, Collection<@Nullable String> coll) {\n" + + " return lib.unconstrainedTypeArguments2(coll);\n" + + " }\n" + + "}\n" + }, + null, + ""); +} +// original case +public void testBug456487a() { + runConformTestWithLibs( + new String[]{ + "Optional.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Optional<@NonNull T> {\n" + + " @Nullable T value;\n" + + " private Optional(T value) { this.value = value; }\n" + + " public static <@NonNull T> Optional of(T value) { return new Optional(value); }\n" + + " public T get() { \n" + + " @Nullable T t = this.value;\n" + + " if (t != null) return t; \n" + + " throw new RuntimeException(\"No value present\");\n" + + " }\n" + + " public @Nullable T orElse(@Nullable T other) { return (this.value != null) ? this.value : other; }\n" + + "}\n" + }, + null, + ""); +} +// witness for NPE in NullAnnotationMatching.providedNullTagBits: +public void testBug456487b() { + runNegativeTestWithLibs( + new String[]{ + "Optional.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Optional<@Nullable T> {\n" + + " @Nullable T value;\n" + + " private Optional(T value) { this.value = value; }\n" + + " public static <@NonNull T> Optional of(T value) { return new Optional(value); }\n" + + " public T get() { \n" + + " @Nullable T t = this.value;\n" + + " if (t != null) return t; \n" + + " throw new RuntimeException(\"No value present\");\n" + + " }\n" + + " public @Nullable T orElse(@Nullable T other) { return (this.value != null) ? this.value : other; }\n" + + "}\n", + "OTest.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault\n" + + "class OTest {\n" + + " public static void good() {\n" + + " Optional os1 = Optional.of(\"yes\");\n" + + " @NonNull String s = os1.get();\n" + + " @Nullable String ns = os1.orElse(null);\n" + + " }\n" + + " public static void bad() {\n" + + " Optional os = Optional.of(null);\n" + + " @NonNull String s = os.orElse(null);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Optional.java (at line 5)\n" + + " public static <@NonNull T> Optional of(T value) { return new Optional(value); }\n" + + " ^\n" + + "Null constraint mismatch: The type \'@NonNull T\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "2. ERROR in Optional.java (at line 5)\n" + + " public static <@NonNull T> Optional of(T value) { return new Optional(value); }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'void (@Nullable @NonNull T)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n" + + "3. ERROR in Optional.java (at line 5)\n" + + " public static <@NonNull T> Optional of(T value) { return new Optional(value); }\n" + + " ^\n" + + "Null constraint mismatch: The type \'@NonNull T\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "----------\n" + + "1. ERROR in OTest.java (at line 5)\n" + + " Optional os1 = Optional.of(\"yes\");\n" + + " ^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "2. ERROR in OTest.java (at line 6)\n" + + " @NonNull String s = os1.get();\n" + + " ^^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'@Nullable @NonNull String get()\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n" + + "3. ERROR in OTest.java (at line 7)\n" + + " @Nullable String ns = os1.orElse(null);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'@Nullable @NonNull String orElse(@Nullable @NonNull String)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n" + + "4. ERROR in OTest.java (at line 10)\n" + + " Optional os = Optional.of(null);\n" + + " ^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "5. ERROR in OTest.java (at line 10)\n" + + " Optional os = Optional.of(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "6. ERROR in OTest.java (at line 11)\n" + + " @NonNull String s = os.orElse(null);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'@Nullable @NonNull String orElse(@Nullable @NonNull String)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n"); +} +public void testBug454182() { + + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annot.NonNullByDefault"); + String[] libs = this.LIBS.clone(); + libs[libs.length-1] = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test454182.jar"; + runConformTest( + new String[] { + "p/package-info.java", + "@annot.NonNullByDefault package p;\n" + }, + "", + libs, + false, + null, + options, + null); +} +public void testBug443870() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface Listener {}\n" + + "interface I0> {}\n" + + "interface I1 extends I0> {}\n" + + "class Y {\n" + + " private @NonNull I0> f;\n" + + " Y (@NonNull I0> in) { this.f = in; }\n" + + " @NonNull I0> getI() { return f; }\n" + + "}\n" + + "public class X extends Y {\n" + + " private @NonNull I1 f;\n" + + " X (@NonNull I1 in) { super(in); this.f = in; }\n" + + " @Override\n" + + " @NonNull I1 getI() { return f; }\n" + + "}\n" + }, + null, + ""); +} +public void testBug437072() { + runNegativeTest( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " @NonNull int[][] ints = new int[3][4];\n" + + " @NonNull int[][] test1() { return new int[3][4]; }\n" + + " void test2(@NonNull boolean[][] bools) {\n" + + " @NonNull boolean[][] bools2 = bools;\n" + + " }\n" + + " List<@NonNull int[]> intslist;\n" + + " List<@NonNull int> intlist;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @NonNull int[][] ints = new int[3][4];\n" + + " ^^^^^^^^\n" + + "The nullness annotation @NonNull is not applicable for the primitive type int\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " @NonNull int[][] test1() { return new int[3][4]; }\n" + + " ^^^^^^^^\n" + + "The nullness annotation @NonNull is not applicable for the primitive type int\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " void test2(@NonNull boolean[][] bools) {\n" + + " ^^^^^^^^\n" + + "The nullness annotation @NonNull is not applicable for the primitive type boolean\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " @NonNull boolean[][] bools2 = bools;\n" + + " ^^^^^^^^\n" + + "The nullness annotation @NonNull is not applicable for the primitive type boolean\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " List<@NonNull int[]> intslist;\n" + + " ^^^^^^^^\n" + + "The nullness annotation @Nullable is not applicable for the primitive type int\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " List<@NonNull int> intlist;\n" + + " ^^^\n" + + "Syntax error, insert \"Dimensions\" to complete ReferenceType\n" + + "----------\n", + this.LIBS, + true/*flush*/); +} +public void testBug448709() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION, JavaCore.WARNING); // ensure program is runnable + compilerOptions.put(JavaCore.COMPILER_PB_PESSIMISTIC_NULL_ANALYSIS_FOR_FREE_TYPE_VARIABLES, JavaCore.WARNING); // ensure program is runnable + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "Test.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " /**\n" + + " * A null-annotated version of {@link Objects#requireNonNull(Object)}.\n" + + " */\n" + + " public static final @NonNull T requireNonNull(final @Nullable T obj) {\n" + + " if (obj == null) throw new NullPointerException();\n" + + " return obj;\n" + + " }\n" + + "\n" + + " /**\n" + + " * A null-annotated version of {@link Optional#map(Function)}.\n" + + " */\n" + + " public static final @NonNull Optional map(final @NonNull Optional optional, final Function<@NonNull ? super T,? extends U> mapper) {\n" + + " if (!optional.isPresent()) return requireNonNull(Optional.empty());\n" + + " final T source = optional.get();\n" + + " final U result = mapper.apply(source);\n" + + " System.out.println(source+\"->\"+result);\n" + + " return requireNonNull(Optional. ofNullable(result));\n" + + " }\n" + + "\n" + + " /**\n" + + " * A method with a {@link NonNull} {@link DefaultLocation#PARAMETER} and {@link DefaultLocation#RETURN_TYPE}.\n" + + " */\n" + + " public static final @NonNull Integer testMethod(final @NonNull String s) {\n" + + " final Integer r = Integer.valueOf(s);\n" + + " if (r == null) throw new NullPointerException();\n" + + " return r+1;\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) {\n" + + " final @NonNull Optional<@Nullable String> optNullableString = requireNonNull(Optional.ofNullable(\"1\"));\n" + + "\n" + + " final Function<@NonNull String,@NonNull Integer> testMethodRef = Test::testMethod;\n" + + " map(optNullableString, testMethodRef);\n" + + "\n" + + " map(optNullableString, Test::testMethod); // Error: Null type mismatch at parameter 1: required '@NonNull String' but provided '@Nullable String' via method descriptor Function.apply(String)\n" + + "\n" + + " map(optNullableString, (s) -> Test.testMethod(s));\n" + + " }\n" + + "\n" + + "}\n" + }, + compilerOptions, + "----------\n" + + "1. WARNING in Test.java (at line 21)\n" + + " final U result = mapper.apply(source);\n" + + " ^^^^^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. WARNING in Test.java (at line 39)\n" + + " map(optNullableString, testMethodRef);\n" + + " ^^^^^^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'@NonNull Optional<@NonNull Integer> map(@NonNull Optional<@Nullable String>, Function<@NonNull ? super @Nullable String,? extends @NonNull Integer>)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n" + + "3. WARNING in Test.java (at line 41)\n" + + " map(optNullableString, Test::testMethod); // Error: Null type mismatch at parameter 1: required \'@NonNull String\' but provided \'@Nullable String\' via method descriptor Function.apply(String)\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'@NonNull Optional<@NonNull Integer> map(@NonNull Optional<@Nullable String>, Function<@NonNull ? super @Nullable String,? extends @NonNull Integer>)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n" + + "4. WARNING in Test.java (at line 43)\n" + + " map(optNullableString, (s) -> Test.testMethod(s));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Contradictory null annotations: method was inferred as \'@NonNull Optional<@NonNull Integer> map(@NonNull Optional<@Nullable String>, Function<@NonNull ? super @Nullable String,? extends @NonNull Integer>)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + + "----------\n" + + "5. WARNING in Test.java (at line 43)\n" + + " map(optNullableString, (s) -> Test.testMethod(s));\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n", + "1->2\n" + + "1->2\n" + + "1->2"); +} +public void testBug448709b() { + runConformTestWithLibs( + new String[] { + "Test.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " public static final void map(final @NonNull Optional optional, final Function<@NonNull ? super T,? extends U> mapper) {\n" + + " final T source = optional.get();\n" + + " if (source != null) {\n" + + " final U result = mapper.apply(source);\n" + + " System.out.println(source+\"->\"+result);\n" + + " }\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug459967_Array_constructor() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface FI {\n" + + " T @NonNull[] getArray(int size);" + + "}\n" + + "public class X {\n" + + " void consumer(FI fis) {}\n" + + " void test() {\n" + + " consumer(String[]::new);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug459967_Array_constructor_b() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface FI {\n" + + " @NonNull T @NonNull[] getArray(int size);" + + "}\n" + + "public class X {\n" + + " void consumer(FI fis) {}\n" + + " void test() {\n" + + " consumer(String[]::new);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " consumer(String[]::new);\n" + + " ^^^^^^^^^^^^^\n" + + "Null type safety at method return type: Method descriptor FI.getArray(int) promises \'@NonNull String @NonNull[]\' but referenced method provides \'String @NonNull[]\'\n" + + "----------\n"); +} +public void testBug459967_Array_clone() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface FI {\n" + + " T @NonNull[] getArray(T[] orig);" + + "}\n" + + "public class X {\n" + + " void consumer(FI fis) {}\n" + + " void test() {\n" + + " consumer(String[]::clone);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug459967_Array_clone_b() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface FI {\n" + + " @NonNull T @NonNull[] getArray(T[] orig);" + + "}\n" + + "public class X {\n" + + " void consumer(FI fis) {}\n" + + " void test() {\n" + + " consumer(String[]::clone);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " consumer(String[]::clone);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null type safety at method return type: Method descriptor FI.getArray(String[]) promises \'@NonNull String @NonNull[]\' but referenced method provides \'String @NonNull[]\'\n" + + "----------\n"); +} +public void testBug448709_allocationExpression1() { + // inference prioritizes constraint (<@Nullable T>) over expected type (@NonNull String), hence a null type mismatch results + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "interface F0 {}\n" + + "class FI<@Nullable T> implements F0 {\n" + + "}\n" + + "public abstract class X {\n" + + " abstract Z zork(F0 f);\n" + + " @NonNull String test() {\n" + + " return zork(new FI<>());\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " return zork(new FI<>());\n" + + " ^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'F0<@NonNull String>\' but this expression has type \'@NonNull FI<@Nullable String>\', corresponding supertype is \'F0<@Nullable String>\'\n" + + "----------\n"); +} +public void testBug448709_allocationExpression2() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class F {\n" + + " <@Nullable U> F(U arg1, U arg2) {}\n" + + "}\n" + + "public class X {\n" + + " F f = new <@NonNull Integer>F(1,2);\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " F f = new <@NonNull Integer>F(1,2);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull Integer\' is not a valid substitute for the type parameter \'@Nullable U\'\n" + + "----------\n"); +} +public void testBug448709_allocationExpression3() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " class F {\n" + + " <@Nullable U> F(U arg1, U arg2) {}\n" + + " }\n" + + " F f = this.new <@NonNull Integer>F(1,2);\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " F f = this.new <@NonNull Integer>F(1,2);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull Integer\' is not a valid substitute for the type parameter \'@Nullable U\'\n" + + "----------\n"); +} +public void testBug465513() { + runConformTestWithLibs( + new String[] { + "pack1/A.java", + "package pack1;\r\n" + + "import java.math.BigInteger;\r\n" + + "\r\n" + + "interface A { Object m(Class c); }\r\n" + + "interface B { Object m(Class c); }\r\n" + + "interface C { Object m(Class c); }\r\n" + + "@FunctionalInterface\r\n" + + "interface D extends A, B, C {}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in pack1\\A.java (at line 4)\n" + + " interface A { Object m(Class c); }\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); +} + +public void testBug455180() { + runConformTestWithLibs( // same warning from ecj & javac + true/*flush*/, + new String[] { + "projA/GenericType.java", + "package projA;\n"+ + "public class GenericType {\n" + + "}\n", + "projA/ClassWithRawUsage.java", + "package projA;\n"+ + "@org.eclipse.jdt.annotation.NonNullByDefault\n"+ + "public class ClassWithRawUsage {\n"+ + " public java.util.List method() {\n"+ + " throw new RuntimeException();\n"+ + " }\n"+ + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in projA\\ClassWithRawUsage.java (at line 4)\n" + + " public java.util.List method() {\n" + + " ^^^^^^^^^^^\n" + + "GenericType is a raw type. References to generic type GenericType should be parameterized\n" + + "----------\n"); + runConformTestWithLibs( // same warning from ecj & javac + false/*flush*/, + new String[] { + "projB/ClassThatImports.java", + "package projB;\n" + + "import projA.ClassWithRawUsage;\n" + + "import projA.GenericType;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class ClassThatImports {\n" + + " void test(ClassWithRawUsage cwru) {\n" + + " @NonNull GenericType gt = cwru.method().get(0);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in projB\\ClassThatImports.java (at line 7)\n" + + " @NonNull GenericType gt = cwru.method().get(0);\n" + + " ^^^^^^^^^^^\n" + + "GenericType is a raw type. References to generic type GenericType should be parameterized\n" + + "----------\n" + + "2. INFO in projB\\ClassThatImports.java (at line 7)\n" + + " @NonNull GenericType gt = cwru.method().get(0);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'@NonNull List<@NonNull GenericType>\'. Type \'List\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n"); +} + +public void testBug455180WithOtherAnnotation() { + runConformTestWithLibs( + new String[] { + "proj0/MyAnnotation.java", + "package proj0;\n"+ + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.CLASS)"+ + "@java.lang.annotation.Target({ java.lang.annotation.ElementType.TYPE_USE })"+ + "public @interface MyAnnotation {}" + }, null, ""); + runConformTestWithLibs( // same warning from ecj & javac + false/*flush*/, + new String[] { + "projA/GenericType.java", + "package projA;\n"+ + "public class GenericType {\n" + + "}\n", + "projA/ClassWithRawUsage.java", + "package projA;\n"+ + "public class ClassWithRawUsage {\n"+ + " public java.util.List<@proj0.MyAnnotation GenericType> method() {\n"+ + " throw new RuntimeException();\n"+ + " }\n"+ + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in projA\\ClassWithRawUsage.java (at line 3)\n" + + " public java.util.List<@proj0.MyAnnotation GenericType> method() {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "GenericType is a raw type. References to generic type GenericType should be parameterized\n" + + "----------\n"); + runWarningTestWithLibs( + false/*flush*/, + new String[] { + "projB/ClassThatImports.java", + "package projB;\n" + + "import projA.ClassWithRawUsage;\n" + + "import projA.GenericType;\n" + + "public class ClassThatImports {\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in projB\\ClassThatImports.java (at line 2)\n" + + " import projA.ClassWithRawUsage;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The import projA.ClassWithRawUsage is never used\n" + + "----------\n" + + "2. WARNING in projB\\ClassThatImports.java (at line 3)\n" + + " import projA.GenericType;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import projA.GenericType is never used\n" + + "----------\n"); +} +// original test, witnessing NPE +public void testBug466713() { + runConformTestWithLibs( + new String[] { + "Bug.java", + "class Bug {\n" + + " java.util.Iterator x;\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// variant to ensure we are still reporting the error at the other location +public void testBug466713b() { + runNegativeTestWithLibs( + new String[] { + "Bug.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class Bug {\n" + + " java.util.Iterator<@Nullable int @Nullable []> x;\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Bug.java (at line 3)\n" + + " java.util.Iterator<@Nullable int @Nullable []> x;\n" + + " ^^^^^^^^^\n" + + "The nullness annotation @Nullable is not applicable for the primitive type int\n" + + "----------\n"); +} +// variant to ensure we are not complaining against an unrelated annotation +public void testBug466713c() { + runConformTestWithLibs( + new String[] { + "MyAnnot.java", + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface MyAnnot {}\n", + "Bug.java", + "class Bug {\n" + + " java.util.Iterator<@MyAnnot int @org.eclipse.jdt.annotation.Nullable []> x;\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +// variant for https://bugs.eclipse.org/bugs/show_bug.cgi?id=466713#c5 +public void testBug466713d() { + runNegativeTest( + new String[] { + "MyAnnot.java", + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface MyAnnot {}\n", + "Bug.java", + "class Bug {\n" + + " boolean test(Object o) {\n" + + " return o instanceof java.util.Iterator;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug.java (at line 3)\n" + + " return o instanceof java.util.Iterator;\n" + + ((this.complianceLevel >= ClassFileConstants.JDK16) ? + " ^\n" + + "Type Object cannot be safely cast to Iterator\n" + : + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type Iterator. Use the form Iterator instead since further generic type information will be erased at runtime\n" + ) + + "----------\n" + + "2. ERROR in Bug.java (at line 3)\n" + + " return o instanceof java.util.Iterator;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Nullness annotations are not applicable at this location \n" + + "----------\n", + this.LIBS, + true/*flush*/); +} +public void testBug466969() { + runConformTestWithLibs( + new String[] { + "GenericType.java", + "public abstract class GenericType {\n" + + " abstract T get();\n"+ + "}", + "WildcardUsage.java", + "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault({ ARRAY_CONTENTS, FIELD, PARAMETER, RETURN_TYPE, TYPE_ARGUMENT, TYPE_BOUND, TYPE_PARAMETER })\n" + + "public class WildcardUsage {\n" + + " void f(GenericType p) {\n" + + " p.get().run();\n" + + " }\n" + + "}" + }, getCompilerOptions(), ""); +} +public void testBug467032() { + runConformTestWithLibs( + new String[] { + "Class1.java", + "class Class1 {;\n"+ + " enum E {}\n"+ + " void m1(E @org.eclipse.jdt.annotation.Nullable [] a) {}\n"+ + "}\n" + }, getCompilerOptions(), ""); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "Class2.java", + "class Class2 {;\n"+ + " Class1 x;"+ + "}\n" + }, getCompilerOptions(), ""); +} +public void testBug467430() { + runConformTestWithLibs( + new String[] { + "A.java", + "public class A {\n" + + " @org.eclipse.jdt.annotation.NonNullByDefault\n" + + " void m(java.util.@org.eclipse.jdt.annotation.Nullable Map map) {\n" + + " }\n" + + " void m2(A a) {\n" + + " final java.util.Map v = null;\n" + + " a.m(v);\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + ""); +} +public void testBug467430mismatch() { + runConformTestWithLibs( + new String[] { + "A.java", + "public class A {\n" + + " @org.eclipse.jdt.annotation.NonNullByDefault\n" + + " void m(java.util.@org.eclipse.jdt.annotation.Nullable Map map) {\n" + + " }\n" + + " void m2(A a) {\n" + + " final java.util.Map v = null;\n" + + " a.m(v);\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + ""); +} +public void testBug467430array() { + runConformTestWithLibs( + new String[] { + "A.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class A {\n" + + " @NonNullByDefault\n" + + " void m(@NonNull String @Nullable [] array) {\n" + + " }\n" + + " void m2(A a) {\n" + + " final String[] v = null;\n" + + " a.m(v);\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + ""); +} +public void testBug467430arrayMismatch() { + runConformTestWithLibs( + new String[] { + "A.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class A {\n" + + " @NonNullByDefault\n" + + " void m(@NonNull String @Nullable [] array) {\n" + + " }\n" + + " void m2(A a) {\n" + + " final @Nullable String @Nullable [] v = null;\n" + + " a.m(v);\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + ""); +} + +public void testBug446217() { + Runner runner = new Runner(); + runner.classLibraries = this.LIBS; + runner.testFiles = + new String[] { + "sol/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package sol;", + "sol/FuncList.java", + "\n" + + "package sol;\n" + + "\n" + + "interface FuncList {}\n" + + " \n" + + "@SuppressWarnings(\"unused\")\n" + + "final class Node implements FuncList {\n" + + " private final A a;\n" + + " private final FuncList tail;\n" + + " \n" + + " Node(final A a, final FuncList tail) {\n" + + " this.a = a;\n" + + " this.tail = tail;\n" + + " }\n" + + "}\n" + + "\n" + + "final class Empty implements FuncList {\n" + + " Empty() {}\n" + + "}\n", + "sol/Test.java", + "package sol;\n" + + "\n" + + "public class Test {\n" + + " public static void main(final String[] args) {\n" + + " System.out.println(new Node<>(\"A\", new Empty<>()));\n" + + " }\n" + + "}\n" + }; + runner.javacTestOptions = new JavacTestOptions.SuppressWarnings("auxiliaryclass"); + runner.runConformTest(); +} +public void testBug456584() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_PB_PESSIMISTIC_NULL_ANALYSIS_FOR_FREE_TYPE_VARIABLES, JavaCore.WARNING); + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "Test.java", + "import java.util.*;\n" + + "import java.util.function.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + "\n" + + " public static final @NonNull R applyRequired(final T input, final Function function) { // Warning on '@NonNull R': \"The nullness annotation is redundant with a default that applies to this location\"\n" + + " return Objects.requireNonNull(function.apply(input));\n" + + " }\n" + + "\n" + + "}\n" + }, + compilerOptions, + "----------\n" + + "1. INFO in Test.java (at line 9)\n" + + " return Objects.requireNonNull(function.apply(input));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on substitution \'T=@NonNull capture#of ? extends R\'. Declaring type \'Objects\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n" + + "2. WARNING in Test.java (at line 9)\n" + + " return Objects.requireNonNull(function.apply(input));\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'capture#2-of ? extends R\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n"); +} +public void testBug447661() { + runConformTestWithLibs( + new String[] { + "Two.java", + "import java.util.*;\n" + + "public class Two {\n" + + "\n" + + " @org.eclipse.jdt.annotation.NonNullByDefault\n" + + " public static Set getSet() {\n" + + " return new HashSet<>();\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "One.java", + "import java.util.*;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class One {\n" + + "\n" + + " public void test() {\n" + + " Set set = Two.getSet();\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug436091() { + runConformTestWithLibs( + new String[] { + "p/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package p;\n", + + "p/Program.java", + "package p;\n" + + "public class Program {\n" + + " private final ProgramNode program;\n" + + " " + + " public Program(final ProgramNode astRoot) {\n" + + " program = astRoot;\n" + + " }\n" + + " " + + " public Integer execute() {\n" + + " return program.accept(ExecutionEvaluationVisitor.VISITOR);\n" + + " }\n" + + " " + + " class ProgramNode {\n" + + " public R accept(final ConcreteNodeVisitor visitor) {\n" + + " return visitor.visit(this);\n" + + " }\n" + + " }\n" + + "}\n", + + "p/ConcreteNodeVisitor.java", + "package p;\n" + + "import p.Program.ProgramNode;\n" + + "public interface ConcreteNodeVisitor {\n" + + " R visit(ProgramNode node);\n" + + "}\n", + + "p/ExecutionEvaluationVisitor.java", + "package p;\n" + + "" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "" + + "import p.Program.ProgramNode;\n" + + "" + + "public enum ExecutionEvaluationVisitor implements ConcreteNodeVisitor {\n" + + " " + + " VISITOR;\n" + + " " + + " @Override" + + " public Integer visit(final ProgramNode node) {\n" + + " @SuppressWarnings(\"null\")\n" + + " @NonNull\n" + + " final Integer i = Integer.valueOf(0);\n" + + " return i;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + // re-compile only one of the above: + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "p/Program.java", + "package p;\n" + + "public class Program {\n" + + " private final ProgramNode program;\n" + + " " + + " public Program(final ProgramNode astRoot) {\n" + + " program = astRoot;\n" + + " }\n" + + " " + + " public Integer execute() {\n" + + " return program.accept(ExecutionEvaluationVisitor.VISITOR);\n" + + " }\n" + + " " + + " class ProgramNode {\n" + + " public R accept(final ConcreteNodeVisitor visitor) {\n" + + " return visitor.visit(this);\n" + + " }\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug474239() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + "Test.java", + "public class Test {\n" + + " static String s1 = null, s2 = null;\n" + + "\n" + + " public static void main(String[] args) {\n" + + " int val = (int) System.currentTimeMillis();\n" + + " switch (val % 2) {\n" + + " case 0:\n" + + " if (s1 != null)\n" + + " s2 = \"\";\n" + + " break;\n" + + " case 1:\n" + + " if (s1 != null) // compiler thinks s1 is never null at this point\n" + + " throw new RuntimeException(\"\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + options, + ""); +} + +public void testBug467482() { + runConformTestWithLibs( + new String[]{ + "Util.java", + "public abstract class Util {\n" + + " public static @org.eclipse.jdt.annotation.Nullable T f(T[] valuesArray, java.util.Comparator comparator) {\n" + + " @org.eclipse.jdt.annotation.Nullable\n" + + " T winner = null;\n" + + " for (T value : valuesArray) {\n" + + " if (winner == null) {\n" + + " winner = value;\n" + + " } else {\n" + + " if (comparator.compare(winner, value) < 0) {\n" + + " winner = value;\n" + + " }\n" + + " }\n" + + " }\n" + + " return winner;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug467482simple() { + // reduced example without generics that still exhibits the bug + runConformTestWithLibs( + new String[]{ + "Util.java", + "public abstract class Util {\n" + + "public static void f(Object unknown) {\n" + + " @org.eclipse.jdt.annotation.Nullable\n" + + " Object winner = null;\n" + + " for (int i = 0; i < 1; i++) {\n" + + " winner = unknown;\n" + + " }\n" + + " if (winner == null) {\n" + + " assert false;\n" + + " }\n" + + "}\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug467482while() { + // even simpler with while loop + runConformTestWithLibs( + new String[]{ + "Util.java", + "public abstract class Util {\n" + + "public static void f(Object unknown, boolean flag) {\n" + + " @org.eclipse.jdt.annotation.Nullable\n" + + " Object winner = null;\n" + + " while (flag) {\n" + + " winner = unknown;\n" + + " flag = false;\n" + + " }\n" + + " if (winner == null) {\n" + + " assert false;\n" + + " }\n" + + "}\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug467482switch() { + // bug behaviour visible via switch + runConformTestWithLibs( + new String[]{ + "Util.java", + "public abstract class Util {\n" + + "public static void f(Object unknown, boolean flag) {\n" + + " @org.eclipse.jdt.annotation.Nullable\n" + + " Object winner = null;\n" + + " switch (1) {\n" + + " case 1: winner = unknown;\n" + + " }\n" + + " if (winner == null) {\n" + + " assert false;\n" + + " }\n" + + "}\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} + +public void testBug467482regression() { + // simple regression test that verifies that possibly be the patch affected messages stay unchanged + runNegativeTestWithLibs( + new String[]{ + "Check.java", + "public abstract class Check {\n" + + " public static void check(@org.eclipse.jdt.annotation.NonNull Object x) {\n" + + " }\n" + + + " public static void f(Object unknown, boolean flag) {\n" + + " check(unknown); // expected: null type safety warning\n" + + " @org.eclipse.jdt.annotation.Nullable\n" + + " Object nullable = unknown;\n" + + " check(nullable); // expected: null type mismatch error\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Check.java (at line 5)\n" + + " check(unknown); // expected: null type safety warning\n" + + " ^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'Object\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n" + + "2. ERROR in Check.java (at line 8)\n" + + " check(nullable); // expected: null type mismatch error\n" + + " ^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable Object\'\n" + + "----------\n"); +} +public void testBug484735() { + runConformTestWithLibs( + new String[] { + "test/NullabilityLoopBug.java", + "package test;\n" + + "\n" + + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class NullabilityLoopBug {\n" + + "\n" + + " public static void main(String[] args)\n" + + " {\n" + + " Map map = new HashMap<>();\n" + + " \n" + + " map.put(\"key\", \"value\");\n" + + " \n" + + " System.out.println(getKeyByValue(map, \"value\"));\n" + + " }\n" + + " \n" + + " private static K getKeyByValue(Map map, @Nullable V value)\n" + + " {\n" + + " @Nullable K result = null; // some nullability bug? assigning null results in compiler complaining 'result can only be null' below\n" + + " for (Entry entry : map.entrySet())\n" + + " {\n" + + " boolean equals;\n" + + " if (value == null)\n" + + " equals = (entry.getValue() == null);\n" + + " else\n" + + " equals = value.equals(entry.getValue());\n" + + " \n" + + " if (equals)\n" + + " {\n" + + " if (result == null) // Incorrect warning: Redundant null check: The variable result can only be null at this location\n" + + " result = entry.getKey();\n" + + " else\n" + + " throw new IllegalStateException(\"Multiple matches for looking up key via value [\" + value + \"]: [\" + result + \"] and [\" + entry.getKey() + \"]\");\n" + + " }\n" + + " }\n" + + " \n" + + " if (result == null) // Incorrect warning: Redundant null check: The variable result can only be null at this location\n" + + " throw new IllegalStateException(\"No matches for looking up key via value [\" + value + \"]\");\n" + + " \n" + + " return result; // Incorrect warning: Dead code\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "key"); +} +public void testBug474239b() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + "Test.java", + "public class Test {\n" + + " static String s2 = null;\n" + + "\n" + + " public static void main(String[] args) {\n" + + " int val = (int) System.currentTimeMillis();\n" + + " switch (val % 2) {\n" + + " case 0:\n" + + " s2 = \"\";\n" + + " break;\n" + + " case 1:\n" + + " if (s2 != null)\n" + + " throw new RuntimeException(\"\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + options, + ""); +} +public void testBug472663() { + runConformTestWithLibs( + new String[] { + "test/Callee.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Callee {\n" + + " public static String staticOtherClass(String foo) {\n" + + " return foo;\n" + + " }\n" + + "\n" + + " public String instanceOtherClass(String foo) {\n" + + " return foo;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); + // and now consume Callee.class: + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test/Caller.java", + "package test;\n" + + "\n" + + "import java.util.function.Function;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Caller {\n" + + " public void foo(final Callee callee) {\n" + + " Function function;\n" + + "\n" + + " // assignments with warnings (wrong):\n" + + " function = Callee::staticOtherClass;\n" + + " function = callee::instanceOtherClass;\n" + + "\n" + + " // assignments with no warnings (ok):\n" + + " function = foo -> Callee.staticOtherClass(foo);\n" + + " function = foo -> callee.instanceOtherClass(foo);\n" + + " function = Caller::staticSameClass;\n" + + " function = this::instanceSameClass;\n" + + " }\n" + + "\n" + + " public static String staticSameClass(String foo) {\n" + + " return foo;\n" + + " }\n" + + "\n" + + " public String instanceSameClass(String foo) {\n" + + " return foo;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug467094() { + runConformTestWithLibs( + new String[] { + "A.java", + "class A {;\n"+ + " @org.eclipse.jdt.annotation.NonNull String @org.eclipse.jdt.annotation.Nullable [] x;\n"+ + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug467094_local() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "public class X {\n"+ + " void foo(@org.eclipse.jdt.annotation.NonNull Object[] o) {\n"+ + " o.hashCode();\n"+ + " if (o != null) {\n"+ + " System.out.print(o.toString());\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + getCompilerOptions(), + "----------\n"+ + "1. ERROR in X.java (at line 4)\n" + + " if (o != null) {\n" + + " ^\n" + + "Redundant null check: The variable o cannot be null at this location\n" + + "----------\n"); +} +public void testBug467094_method() { + runConformTestWithLibs( + new String[] { + "A.java", + "class A {;\n"+ + " @org.eclipse.jdt.annotation.NonNull String @org.eclipse.jdt.annotation.Nullable [] m(){\n" + + " return null;\n" + + " }\n" + + " int usage(){\n" + + " if(m() == null) return 1; \n" + + " return 0; \n" + + " }\n"+ + "}\n" + }, getCompilerOptions(), ""); +} +public void testBug440398() { + runConformTestWithLibs( + new String[] { + "NullTest.java", + "import org.eclipse.jdt.annotation.*;\n" + + "@NonNullByDefault({})\r\n" + + "public class NullTest {\r\n" + + " public static @NonNull Object[] obj = null;\r\n" + + " public static void main(String[] args) {\r\n" + + " obj = null;\r\n" + + " if (obj == null) { // WARNING 1\r\n" + + " System.out.println(\"NULL\"); // WARNING 2\r\n" + + " }\r\n" + + " }\r\n" + + "}\n" + }, + getCompilerOptions(), + "", + "NULL"); +} +public void testBug440398_comment2() { + runConformTestWithLibs( + new String[] { + "MyClass.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@NonNullByDefault({DefaultLocation.FIELD})\n" + + "public class MyClass {\n" + + " private @NonNull String [] names = new @NonNull String[]{\"Alice\", \"Bob\", \"Charlie\"};\n" + + "\n" + + " public String getName(int index) {\n" + + " String name = names[index];\n" + + " return name; /* statement A */\n" + + " }\n" + + "}", + }, + getCompilerOptions(), + ""); +} +public void testBug440398_comment2a() { + runConformTestWithLibs( + new String[] { + "p/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault({org.eclipse.jdt.annotation.DefaultLocation.FIELD})\n" + + "package p;\n", + "p/MyClass.java", + "package p;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class MyClass {\n" + + " private @NonNull String [] names = new @NonNull String[]{\"Alice\", \"Bob\", \"Charlie\"};\n" + + "\n" + + " public String getName(int index) {\n" + + " String name = names[index];\n" + + " return name; /* statement A */\n" + + " }\n" + + "}", + }, + getCompilerOptions(), + ""); +} +public void testBug481332() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " public void foo() {\n" + + " @Nullable\n" + + " List<@NonNull String> list = new ArrayList<>();\n" + + " checkNotNull(list); // OK\n" + + "\n" + + " @Nullable\n" + + " Map<@NonNull String, @NonNull String> map = new HashMap<>();\n" + + " checkNotNull(map); // OK\n" + + "\n" + + " @NonNull\n" + + " Object @Nullable [] objects = new @NonNull Object[0];\n" + + " // Error: Null type mismatch (type annotations): required '@NonNull Object @NonNull[]' but this expression ...\n" + + " checkNotNull(objects);\n" + + " }\n" + + " \n" + + " public static <@Nullable T> T[] checkNotNull(T @Nullable [] array) {\n" + + " if (array == null) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " return array;\n" + + " }\n" + + "\n" + + " public static <@Nullable T, C extends Iterable> C checkNotNull(@Nullable C container) {\n" + + " if (container == null) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " return container;\n" + + " }\n" + + "\n" + + " public static <@Nullable K, @Nullable V, M extends Map> M checkNotNull(@Nullable M map) {\n" + + " if (map == null) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " return map;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " checkNotNull(list); // OK\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'List<@NonNull String>\' is not a valid substitute for the type parameter \'C extends Iterable<@Nullable T>\'\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " checkNotNull(map); // OK\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'Map<@NonNull String,@NonNull String>\' is not a valid substitute for the type parameter \'M extends Map<@Nullable K,@Nullable V>\'\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " checkNotNull(objects);\n" + + " ^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@Nullable Object @Nullable[]\' but this expression has type \'@NonNull Object @Nullable[]\'\n" + + "----------\n"); +} +public void testBug481322a() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class Super> {\n" + + " S pick(T list) {\n" + + " return list.get(0);\n" + + " }\n" + + "}\n" + + "public class X extends Super<@NonNull String, List<@Nullable String>> {\n" + + " @Override\n" + + " public @NonNull String pick(List<@Nullable String> list) {\n" + + " return super.pick(list);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List<@Nullable String> withNulls = new ArrayList<@Nullable String>();\n" + + " withNulls.add(null);\n" + + " System.out.println(new X().pick(withNulls).toUpperCase());\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " return list.get(0);\n" + + " ^^^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " public class X extends Super<@NonNull String, List<@Nullable String>> {\n" + + " ^^^^\n" + + "Null constraint mismatch: The type \'List<@Nullable String>\' is not a valid substitute for the type parameter \'T extends List\'\n" + + "----------\n"); +} +public void testBug477719() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonNullTypeVariableFromLegacyInvocation, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runner.classLibraries = this.LIBS; + runner.testFiles = + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull Number instantiate(@NonNull Class c) throws Exception {\n" + + " return c.newInstance();\n" + + " }\n" + + " void test(Double d) throws Exception {\n" + + " instantiate(Integer.class);\n" + + " instantiate(d.getClass());\n" + + " }\n" + + "}\n" + }; + runner.javacTestOptions = new JavacTestOptions.SuppressWarnings("deprecation"); + runner.runConformTest(); +} +public void testBug482247() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " @NonNull String @NonNull[] s1 = new String[0];\n" + // expected type drives typing + " @Nullable String @NonNull[] s2 = new String[0];\n" + // expected type drives typing + " @NonNull T first(@NonNull T @NonNull[] arr) {\n" + + " return arr[0];\n" + + " }\n" + + " void other(@Nullable String[] s) {\n" + + " s[0] = null;\n" + + " }\n" + + " @NonNull String test() {\n" + + " other(new String[0]);\n" + // unchanged semantics + " return first(new String[0]);\n" + // unchanged semantics + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in X.java (at line 12)\n" + + " other(new String[0]);\n" + + " ^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'@Nullable String []\'\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " return first(new String[0]);\n" + + " ^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String[]\' needs unchecked conversion to conform to \'@NonNull String @NonNull[]\'\n" + + "----------\n"); +} +public void testBug482247_comment5() { + runConformTestWithLibs( + new String[] { + "Snippet.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Snippet {\n" + + " @NonNull String[] s1 = new String[0]; // No warning\n" + + " public void handleIncidentBeforeCreate() {\n" + + " @NonNull String[] s = new String[0]; // Warning\n" + + " String [] @NonNull[] s2 = new String[0][];\n" + + " String [] @NonNull[] @Nullable[] s3 = new String[0][][];\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + ""); +} +public void testBug483146() { + runConformTestWithLibs( + new String[] { + "Foo.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class Foo {\n" + + "\n" + + " void example1() {\n" + + " @Nullable List container = new ArrayList<>();\n" + + " @NonNull List list = checkNotNull(container);\n" + + " }\n" + + "\n" + + " void example2() {\n" + + " @Nullable List container= new ArrayList<>();\n" + + " @NonNull List list = checkNotNull(container);\n" + + " }\n" + + " \n" + + " @NonNull > C checkNotNull(C container) {\n" + + " if (container == null) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " return container;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug483146b() { + runConformTestWithLibs( + new String[] { + "Foo.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class Foo {\n" + + "\n" + + " void example1() {\n" + + " @Nullable List container = new ArrayList<>();\n" + + " @NonNull List list = checkNotNull(container);\n" + + " }\n" + + "\n" + + " void example2() {\n" + + " @Nullable List container= new ArrayList<>();\n" + + " @NonNull List list = checkNotNull(container);\n" + + " }\n" + + " \n" + + " > @NonNull C checkNotNull(@Nullable C container) {\n" + // <- variation: param is @Nullable + " if (container == null) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " return container;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug473713() { + runConformTestWithLibs( + new String[] { + "a/A1.java", + "package a;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class A1 {\n" + + " public class NestedInA1 {\n" + + " }\n" + + "}\n", + "a/A2.java", + "package a;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class A2 {\n" + + " public static abstract class NestedInA2 {\n" + + " public final A1 a1 = new A1();\n" + + " protected abstract void handleApplicationSpecific(A1.NestedInA1 detail);\n" + + " }\n" + + "}\n", + }, getCompilerOptions(), ""); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "b/B.java", + "package b;\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class B {\n" + + " public static a.A1 m(a.A2.NestedInA2 nestedInA2) {\n" + + " return nestedInA2.a1;\n" + + " }\n" + + "}\n", + }, getCompilerOptions(), ""); +} +public void testBug482228() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class Super {\n" + + " > S pick(T list) {\n" + + " return list.get(0);\n" + + " }\n" + + "}\n" + + "public class X extends Super<@NonNull String> {\n" + + " @Override\n" + + " > @NonNull String pick(T list) {\n" + + " return super.pick(list);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List<@Nullable String> withNulls = new ArrayList<>();\n" + + " withNulls.add(null);\n" + + " System.out.println(new X().pick(withNulls).toUpperCase());\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " return list.get(0);\n" + + " ^^^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " > @NonNull String pick(T list) {\n" + + " ^\n" + + "Cannot redefine null constraints of type variable \'T extends List<@NonNull String>\' declared in \'Super.pick(T)\'\n" + + "----------\n" + + "3. ERROR in X.java (at line 15)\n" + + " return super.pick(list);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'T extends List<@Nullable String>\' is not a valid substitute for the type parameter \'T extends List<@NonNull String>\'\n" + + "----------\n"); +} +public void testBug483527() { + final Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + "Test.java", + "public class Test {\n" + + " static final short foo;\n" + + " static {\n" + + " foo = 1;\n" + + " for (int i=0; i<10; i++) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + compilerOptions, + ""); +} +public void testMultipleAnnotations1() { + Map options1 = new HashMap<>(getCompilerOptions()); + options1.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + options1.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + runConformTest( + new String[] { + "org/foo/Nullable.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ElementType.TYPE_USE})\n" + + "public @interface Nullable {}\n", + "org/foo/NonNull.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ElementType.TYPE_USE})\n" + + "public @interface NonNull {}\n", + "p1/TestNulls.java", + "package p1;\n" + + "import org.foo.*;\n" + + "\n" + + "public class TestNulls {\n" + + " public @Nullable String weaken(@NonNull String theValue) {\n" + + " return theValue;\n" + + " }\n" + + "\n" + + "}" + }, + options1); + Map options2 = getCompilerOptions(); + options2.put(CompilerOptions.OPTION_NonNullAnnotationSecondaryNames, "org.foo.NonNull"); + options2.put(CompilerOptions.OPTION_NullableAnnotationSecondaryNames, "org.foo.Nullable"); + runNegativeTestWithLibs( + new String[] { + "p2/Test.java", + "package p2;\n" + + "import p1.TestNulls;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Test {\n" + + " @NonNull String test(TestNulls test, @Nullable String input) {\n" + + " return test.weaken(input);\n" + + " }\n" + + "}\n" + }, + options2, + "----------\n" + + "1. ERROR in p2\\Test.java (at line 6)\n" + + " return test.weaken(input);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n" + + "2. ERROR in p2\\Test.java (at line 6)\n" + + " return test.weaken(input);\n" + + " ^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n"); +} +public void test483952 () { + runConformTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "import java.util.function.Function;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "public class Test {\n" + + " void test1() {\n" + + " Function function = x -> x;\n" + + " String @Nullable [] z = test2(function, \"\");\n" + + " }\n" + + " T @Nullable [] test2(Function function, T t) {\n" + + " return null;\n" + + " }\n" + + "}" + + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in test\\Test.java (at line 6)\n" + + " Function function = x -> x;\n" + + " ^^^^^^^^\n" + + "Function is a raw type. References to generic type Function should be parameterized\n" + + "----------\n" + + "2. WARNING in test\\Test.java (at line 7)\n" + + " String @Nullable [] z = test2(function, \"\");\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked invocation test2(Function, String) of the generic method test2(Function, T) of type Test\n" + + "----------\n" + + "3. WARNING in test\\Test.java (at line 7)\n" + + " String @Nullable [] z = test2(function, \"\");\n" + + " ^^^^^^^^\n" + + "Type safety: The expression of type Function needs unchecked conversion to conform to Function\n" + + "----------\n"); +} +public void test484055() { + runConformTestWithLibs( + new String[] { + "B.java", + "interface A {\n" + + " public void f(String[] x);\n" + + "\n" + + " public void f2(String x);\n" + + "}\n" + + "\n" + + "public class B implements A {\n" + + " public void f(String @org.eclipse.jdt.annotation.Nullable [] x) {\n" + + " }\n" + + "\n" + + " public void f2(@org.eclipse.jdt.annotation.Nullable String x) {\n" + + " }\n" + + "}" + }, + null, + ""); +} +public void testBug484108() { + runConformTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public interface Test {\n" + + " public void a ( @NonNull T0 test );\n" + + "}\n", + "test/Other.java", + "package test;\n" + + "\n" + + "public interface Other { }\n" + }, + getCompilerOptions(), + ""); + runConformTestWithLibs( + false /* don't flush output dir */, + new String[] { + "test/TestImpl.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import java.lang.reflect.*;\n" + + "\n" + + "public class TestImpl implements Test {\n" + + "\n" + + " /**\n" + + " * {@inheritDoc}\n" + + " *\n" + + " * @see test.Test#a(java.lang.Object)\n" + + " */\n" + + " @Override\n" + + " public void a ( @NonNull T test ) {\n" + + " }\n" + + " public static void main(String... args) {\n" + + " Class c = TestImpl.class;\n" + + " Method[] ms = c.getDeclaredMethods();\n" + + " System.out.println(ms.length);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "", + "2"); +} +public void testBug484954() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "org.foo.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "org.foo.NonNull"); + customOptions.put(JavaCore.COMPILER_PB_NULL_UNCHECKED_CONVERSION, JavaCore.ERROR); + runConformTest( + new String[] { + CUSTOM_NULLABLE_NAME, + CUSTOM_NULLABLE_CONTENT, // sic: declaration annotation + CUSTOM_NONNULL_NAME, + CUSTOM_NONNULL_CONTENT, // sic: declaration annotation + "Snippet.java", + "import java.util.function.*;\n" + + "import org.foo.*;\n" + + "\n" + + "public class Snippet {\n" + + "\n" + + " public void test() {\n" + + " doStuff((@NonNull Object[] data) -> updateSelectionData(data)); \n" + + " }\n" + + "\n" + + " private void doStuff(Consumer postAction) { }\n" + + " private void updateSelectionData(final @NonNull Object data) { }\n" + + "}\n" + }, + customOptions, + ""); +} +public void testBug484981() { + runNegativeTestWithLibs( + new String[] { + "test1/GenericWithNullableBound.java", + "package test1;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + + "@NonNullByDefault\n" + + "public class GenericWithNullableBound {\n" + + "}\n", + + "test1/GenericWithNullableBound2.java", + "package test1;\n" + + "import static java.lang.annotation.ElementType.TYPE_USE;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ TYPE_USE })\n" + + "@interface SomeAnnotation {\n" + + "}\n" + + + "@NonNullByDefault\n" + + "public class GenericWithNullableBound2<@SomeAnnotation T extends @Nullable Number> {\n" + + "}\n", + + "test1/GenericWithNullable.java", + "package test1;\n" + + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + + "@NonNullByDefault\n" + + "public class GenericWithNullable<@Nullable T> {\n" + + "}\n", + + "test1/GenericWithNonNullBound.java", + "package test1;\n" + + + "import org.eclipse.jdt.annotation.NonNull;\n" + + + "public class GenericWithNonNullBound {\n" + + "}\n", + "test1/ClassInSameProject.java", + "package test1;\n" + + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + + "public class ClassInSameProject {\n" + + " static void f1() {\n" + + " new GenericWithNullableBound<@NonNull Number>();\n" + + " }\n" + + + " static void f2() {\n" + + " new GenericWithNullableBound2<@NonNull Number>();\n" + + " }\n" + + + " static void f3() {\n" + + " new GenericWithNonNullBound<@Nullable Number>(); // error 1 expected\n" + + " }\n" + + + " static void f4() {\n" + + " new GenericWithNullable<@NonNull Number>(); // error 2 expected\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test1\\ClassInSameProject.java (at line 12)\n" + + " new GenericWithNonNullBound<@Nullable Number>(); // error 1 expected\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable Number\' is not a valid substitute for the type parameter \'T extends @NonNull Number\'\n" + + "----------\n" + + "2. ERROR in test1\\ClassInSameProject.java (at line 15)\n" + + " new GenericWithNullable<@NonNull Number>(); // error 2 expected\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull Number\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + ); + runNegativeTestWithLibs( + new String[] { + "test2/ClassInOtherProject.java", + "package test2;\n" + + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + + "import test1.GenericWithNonNullBound;\n" + + "import test1.GenericWithNullable;\n" + + "import test1.GenericWithNullableBound;\n" + + "import test1.GenericWithNullableBound2;\n" + + + "public class ClassInOtherProject {\n" + + " static void g1() {\n" + + " new GenericWithNullableBound<@NonNull Number>();\n" + + " }\n" + + + " static void g2() {\n" + + " new GenericWithNullableBound2<@NonNull Number>();\n" + + " }\n" + + + " static void g3() {\n" + + " new GenericWithNonNullBound<@Nullable Number>(); // error 3 expected\n" + + " }\n" + + + " static void g4() {\n" + + " new GenericWithNullable<@NonNull Number>(); // error 4 expected\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test2\\ClassInOtherProject.java (at line 16)\n" + + " new GenericWithNonNullBound<@Nullable Number>(); // error 3 expected\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable Number\' is not a valid substitute for the type parameter \'T extends @NonNull Number\'\n" + + "----------\n" + + "2. ERROR in test2\\ClassInOtherProject.java (at line 19)\n" + + " new GenericWithNullable<@NonNull Number>(); // error 4 expected\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull Number\' is not a valid substitute for the type parameter \'@Nullable T extends Object\'\n" + + "----------\n" + ); +} +// same testBinary06 but via SourceTypeBindings +public void testBug484981b() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public abstract class X1 extends ArrayList {\n" + + " public void foo(U u, V v) {}\n" + + "}\n", + "p/X2.java", + "package p;\n"+ + "import org.eclipse.jdt.annotation.*;\n" + + "public class X2<@Nullable W extends Object> {}\n", + "Y1.java", + "import p.X1;\n" + + "import p.X2;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y1 {\n" + + " X1<@Nullable String> maybeStrings;\n" + // incompatible: T has a bound constrained to @NonNull + " X2<@NonNull String> strings;\n" + // incompatible: W is constrained to @Nullable + " void test(X1<@NonNull String> x) {\n" + // OK + " x.foo(this, new Object());\n" + // OK: 'extends @Nullable' is no restriction + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 5)\n" + + " X1<@Nullable String> maybeStrings;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable String\' is not a valid substitute for the type parameter \'T extends @NonNull Object\'\n" + + "----------\n" + + "2. ERROR in Y1.java (at line 6)\n" + + " X2<@NonNull String> strings;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable W extends Object\'\n" + + "----------\n" + ); +} + +// same testBinary06b but via SourceTypeBindings +public void testBug484981c() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION, JavaCore.IGNORE); + // fix the bug: + runNegativeTestWithLibs( + new String[] { + "p/X1.java", + "package p;\n" + + "import java.util.ArrayList;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public abstract class X1 extends ArrayList {\n" + + " public void foo(U u, V v) {}\n" + + "}\n", + "p/X2.java", + "package p;\n"+ + "import org.eclipse.jdt.annotation.*;\n" + + "public class X2<@Nullable W extends Object> {}\n", + "Y1.java", + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y1 {\n" + + " p.X1 maybeStrings;\n" + // incompatible: T has a bound constrained to @NonNull + " p.X2 strings;\n" + // incompatible: W is constrained to @Nullable + " void test(p.X1 x) {\n" + // OK + " x.foo(this, new Object());\n" + // OK: 'extends @Nullable' is no restriction + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 3)\n" + + " p.X1 maybeStrings;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable String\' is not a valid substitute for the type parameter \'T extends @NonNull Object\'\n" + + "----------\n" + + "2. ERROR in Y1.java (at line 4)\n" + + " p.X2 strings;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable W extends Object\'\n" + + "----------\n" + ); +} + +// same testBinary07 but via SourceTypeBindings +public void testBug484981d() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.ERROR); + customOptions.put(JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "p/List.java", + "package p;\n" + + "public interface List {\n" + + " T get(int i);\n" + // avoid IProblem.NonNullTypeVariableFromLegacyMethod against unannotated j.u.List + "}\n", + "p/X1.java", + "package p;\n" + + "import java.util.Map;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target(TYPE_USE)\n" + + "@interface Immutable {}\n" + + "public abstract class X1 {\n" + + " public <@NonNull U, V extends @Nullable Object> List<@NonNull Map> foo(@Immutable X1 this, U u, V v) { return null; }\n" + + "}\n", + "Y1.java", + "import p.X1;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Y1 {\n" + + " void test(X1 x) {\n" + + " x.<@NonNull Y1, @NonNull Object>foo(this, new Object())\n" + // OK: 'extends @Nullable' is no restriction + " .get(0).put(null, null);\n" + // second null is illegal + " }\n" + + "}\n" + }, + customOptions, + "----------\n" + + "1. ERROR in Y1.java (at line 6)\n" + + " .get(0).put(null, null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n"); +} +public void testBug466562() { + runNegativeTestWithLibs( + new String[] { + "x/C.java", + "package x;\n" + + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + + "@NonNullByDefault({})\n" + + "public class C {\n" + + " String consume(T1 t) {\n" + + " @NonNull Object x = t; // error, should warn?\n" + + " x.toString();\n" + + " return t.toString(); // legal???\n" + + " }\n" + + + " void y() {\n" + + " consume(null); // illegal - OK\n" + + " @NonNull Object t = provide(); // error, should warn?\n" + + " t.toString();\n" + + " }\n" + + + " T1 provide() {\n" + + " return null; // error, should warn?\n" + + " }\n" + + + " C cString; // OK - Null constraint mismatch: The type 'Integer' is not a valid substitute for the type parameter 'T1 extends @Nullable Number'\n" + + " C<@NonNull Integer> c1String; // Wrong: Null constraint mismatch: The type '@NonNull Integer' is not a valid substitute for the type parameter 'T1 extends @Nullable Number'\n" + + " C<@Nullable Integer> c2String; // legal - OK\n" + + "}" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in x\\C.java (at line 5)\n" + + " @NonNullByDefault({})\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing package x\n" + + "----------\n" + + "2. ERROR in x\\C.java (at line 8)\n" + + " @NonNull Object x = t; // error, should warn?\n" + + " ^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T1\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "3. ERROR in x\\C.java (at line 10)\n" + + " return t.toString(); // legal???\n" + + " ^\n" + + "Potential null pointer access: this expression has type \'T1\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "4. ERROR in x\\C.java (at line 13)\n" + + " consume(null); // illegal - OK\n" + + " ^^^^\n" + + "Null type mismatch: required \'T1 extends @Nullable Number\' but the provided value is null\n" + + "----------\n" + + "5. ERROR in x\\C.java (at line 14)\n" + + " @NonNull Object t = provide(); // error, should warn?\n" + + " ^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'T1 extends @Nullable Number\'\n" + + "----------\n" + + "6. ERROR in x\\C.java (at line 18)\n" + + " return null; // error, should warn?\n" + + " ^^^^\n" + + "Null type mismatch: required \'T1 extends @Nullable Number\' but the provided value is null\n" + + "----------\n" + ); +} +public void testBug485056() { + runConformTestWithLibs( + new String[] { + "TestExplainedValue.java", + "import java.io.Serializable;\n" + + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + + "class ExplainedValue {\n" + + " public @Nullable T featureValue;\n" + + "}\n" + + + "public class TestExplainedValue {\n" + + " static @Nullable Serializable g(ExplainedValue explainedValue) {\n" + + " return explainedValue.featureValue;\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + "" + ); +} +public void testBug484741() { + runConformTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "public class Test {\n" + + " static void f(java.util.ArrayList list, E element) {\n" + + " list.add(element);" + + " }\n" + + "\n" + + " static void g(A a) {\n" + + " f(new java.util.ArrayList(), a);\n" + + " }\n" + + "\n" + + " static void h(E1 element1, java.util.ArrayList list1) {\n" + + " f(list1, element1);\n" + + " }\n" + + "}" + }, getCompilerOptions(), ""); +} +public void testBug484741b() { + runConformTestWithLibs( + new String[] { + "test/TestDep.java", + "package test;\n" + + "public class TestDep {\n" + + " static T f(E e) {\n" + + " return e;\n" + + " }\n" + + "}" + }, getCompilerOptions(), ""); +} +public void testBug484741c() { + runConformTestWithLibs( + new String[] { + "test/Test3.java", + "package test;\n" + + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + + "@NonNullByDefault({ DefaultLocation.PARAMETER, DefaultLocation.RETURN_TYPE, DefaultLocation.FIELD, DefaultLocation.TYPE_ARGUMENT })\n" + + "class Feature3 {\n" + + "}\n" + + + "@NonNullByDefault({ DefaultLocation.PARAMETER, DefaultLocation.RETURN_TYPE, DefaultLocation.FIELD, DefaultLocation.TYPE_ARGUMENT })\n" + + "public class Test3 {\n" + + " public static > T[] getValues(F feature) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + + " public static void f(Feature3 feature) {\n" + + " getValues(feature);\n" + + " }\n" + + "}" + }, getCompilerOptions(), ""); +} +public void testBug484741d() { + runConformTestWithLibs( + new String[] { + "BaseNNBD.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class BaseNNBD {\n" + + "}\n", + "DerivedNNBD.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "public class DerivedNNBD extends BaseNNBD { \n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug484741e() { + runConformTestWithLibs( + new String[] { + "test/AbstractFeature.java", + "package test;\n" + + "import java.io.Serializable;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n"+ + "abstract class AbstractFeature {\n" + + "}\n", + "test/SubFeature.java", + "package test;\n" + + "import java.io.Serializable;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n"+ + "public class SubFeature extends AbstractFeature {\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug484741Invoke() { + runNegativeTestWithLibs( + new String[] { + "test/TestInterdepInvoke.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class TestInterdepInvoke {\n" + + " static T f1(E e) {\n" + + " return e;\n" + + " }\n" + + "\n" + + " static T f2(E e) {\n" + + " return e; // error 1 expected\n" + + " }\n" + + "\n" + + " static <@Nullable T, E extends T> T f3(E e) {\n" + + " return e;\n" + + " }\n" + + "\n" + + " static <@Nullable T, @Nullable E extends T> T f4(E e) {\n" + + " return e;\n" + + " }\n" + + "\n" + + " // -------- invocations of f1 --------\n" + + "\n" + + " static T11 g11(E11 e) {\n" + + " return f1(e);\n" + + " }\n" + + "\n" + + " static T12 g12(E12 e) {\n" + + " return f1(e); // error 2 expected\n" + + " }\n" + + "\n" + + " static <@Nullable T13, E13 extends T13> T13 g13(E13 e) {\n" + + " return f1(e);\n" + + " }\n" + + "\n" + + " static <@Nullable T14, @Nullable E14 extends T14> T14 g14(E14 e) {\n" + + " return f1(e);\n" + + " }\n" + + "\n" + + " // -------- invocations of f2 --------\n" + + "\n" + + " static T21 g21(E21 e) {\n" + + " return f2(e);\n" + + " }\n" + + "\n" + + " static T22 g22(E22 e) {\n" + + " return f2(e);\n" + + " }\n" + + "\n" + + " static <@Nullable T23, E23 extends T23> T23 g23(E23 e) {\n" + + " return f2(e);\n" + + " }\n" + + "\n" + + " static <@Nullable T24, @Nullable E24 extends T24> T24 g24(E24 e) {\n" + + " return f2(e);\n" + + " }\n" + + "\n" + + " // -------- invocations of f3 --------\n" + + "\n" + + " static T31 g31(E31 e) {\n" + + " return f3(e); // error 3 expected\n" + + " }\n" + + "\n" + + " static T32 g32(E32 e) {\n" + + " return f3(e); // error 4 expected\n" + + " }\n" + + "\n" + + " static <@Nullable T33, E33 extends T33> T33 g33(E33 e) {\n" + + " return f3(e);\n" + + " }\n" + + "\n" + + " static <@Nullable T34, @Nullable E34 extends T34> T34 g34(E34 e) {\n" + + " return f3(e);\n" + + " }\n" + + "\n" + + " // -------- invocations of f4 --------\n" + + "\n" + + " static T41 g41(E41 e) {\n" + + " return f4(e); /// error 5 expected\n" + + " }\n" + + "\n" + + " static T42 g42(E42 e) {\n" + + " return f4(e); // error 6 expected\n" + + " }\n" + + "\n" + + " static <@Nullable T43, E43 extends T43> T43 g43(E43 e) {\n" + + " return f4(e);\n" + + " }\n" + + "\n" + + " static <@Nullable T44, @Nullable E44 extends T44> T44 g44(E44 e) {\n" + + " return f4(e);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\TestInterdepInvoke.java (at line 11)\n" + + " return e; // error 1 expected\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'T\' but this expression has type \'@Nullable E extends T\', where \'T\' is a free type variable\n" + + "----------\n" + + "2. ERROR in test\\TestInterdepInvoke.java (at line 29)\n" + + " return f1(e); // error 2 expected\n" + + " ^^^^^\n" + + "Null type mismatch (type annotations): required \'T12\' but this expression has type \'@Nullable E12 extends T12\', where \'T12\' is a free type variable\n" + + "----------\n" + + "3. ERROR in test\\TestInterdepInvoke.java (at line 61)\n" + + " return f3(e); // error 3 expected\n" + + " ^^^^^\n" + + "Null type mismatch (type annotations): required \'T31\' but this expression has type \'@Nullable E31 extends T31\', where \'T31\' is a free type variable\n" + + "----------\n" + + "4. ERROR in test\\TestInterdepInvoke.java (at line 65)\n" + + " return f3(e); // error 4 expected\n" + + " ^^^^^\n" + + "Null type mismatch (type annotations): required \'T32\' but this expression has type \'@Nullable E32 extends T32\', where \'T32\' is a free type variable\n" + + "----------\n" + + "5. ERROR in test\\TestInterdepInvoke.java (at line 79)\n" + + " return f4(e); /// error 5 expected\n" + + " ^^^^^\n" + + "Null type mismatch (type annotations): required \'T41\' but this expression has type \'@Nullable E41 extends T41\', where \'T41\' is a free type variable\n" + + "----------\n" + + "6. ERROR in test\\TestInterdepInvoke.java (at line 83)\n" + + " return f4(e); // error 6 expected\n" + + " ^^^^^\n" + + "Null type mismatch (type annotations): required \'T42\' but this expression has type \'@Nullable E42 extends T42\', where \'T42\' is a free type variable\n" + + "----------\n" + ); +} +public void testBug484741Invoke2() { + runNegativeTestWithLibs( + new String[] { + "test/TestInterdepInvokeNN.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "@java.lang.annotation.Target({ java.lang.annotation.ElementType.TYPE_USE })\n" + + "@interface SomeAnnotation {\n" + + " // just needed as workaround if bug 484981 is not fixed\n" + + "}\n" + + "\n" + + "public class TestInterdepInvokeNN {\n" + + " static T f1(E e) {\n" + + " return e;\n" + + " }\n" + + "\n" + + " static T f2(E e) {\n" + + " return e;\n" + + " }\n" + + "\n" + + " static <@NonNull T, @SomeAnnotation E extends T> T f3(E e) {\n" + + " return e;\n" + + " }\n" + + "\n" + + " static <@NonNull T, @NonNull E extends T> T f4(E e) {\n" + + " return e;\n" + + " }\n" + + "\n" + + " // -------- invocations of f1 --------\n" + + "\n" + + " static T11 g11(E11 e) {\n" + + " return f1(e);\n" + + " }\n" + + "\n" + + " static T12 g12(E12 e) {\n" + + " return f1(e);\n" + + " }\n" + + "\n" + + " static <@NonNull T13, @SomeAnnotation E13 extends T13> T13 g13(E13 e) {\n" + + " return f1(e);\n" + + " }\n" + + "\n" + + " static <@NonNull T14, @NonNull E14 extends T14> T14 g14(E14 e) {\n" + + " return f1(e);\n" + + " }\n" + + "\n" + + " // -------- invocations of f2 --------\n" + + "\n" + + " static T21 g21(E21 e) {\n" + + " return f2(e); // error 1 expected\n" + + " }\n" + + "\n" + + " static T22 g22(E22 e) {\n" + + " return f2(e);\n" + + " }\n" + + "\n" + + " static <@NonNull T23, @SomeAnnotation E23 extends T23> T23 g23(E23 e) {\n" + + " return f2(e);\n" + + " }\n" + + "\n" + + " static <@NonNull T24, @NonNull E24 extends T24> T24 g24(E24 e) {\n" + + " return f2(e);\n" + + " }\n" + + "\n" + + " // -------- invocations of f3 --------\n" + + "\n" + + " static T31 g31(E31 e) {\n" + + " return f3(e); // error 2 expected\n" + + " }\n" + + "\n" + + " static T32 g32(E32 e) {\n" + + " return f3(e);\n" + + " }\n" + + "\n" + + " static <@NonNull T33, @SomeAnnotation E33 extends T33> T33 g33(E33 e) {\n" + + " return f3(e);\n" + + " }\n" + + "\n" + + " static <@NonNull T34, @NonNull E34 extends T34> T34 g34(E34 e) {\n" + + " return f3(e);\n" + + " }\n" + + "\n" + + " // -------- invocations of f4 --------\n" + + "\n" + + " static T41 g41(E41 e) {\n" + + " return f4(e); // error 3 expected\n" + + " }\n" + + "\n" + + " static T42 g42(E42 e) {\n" + + " return f4(e);\n" + + " }\n" + + "\n" + + " static <@NonNull T43, @SomeAnnotation E43 extends T43> T43 g43(E43 e) {\n" + + " return f4(e);\n" + + " }\n" + + "\n" + + " static <@NonNull T44, @NonNull E44 extends T44> T44 g44(E44 e) {\n" + + " return f4(e);\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\TestInterdepInvokeNN.java (at line 48)\n" + + " return f2(e); // error 1 expected\n" + + " ^\n" + + "Null type safety: required '@NonNull' but this expression has type 'E21', a free type variable that may represent a '@Nullable' type\n" + + "----------\n" + + "2. ERROR in test\\TestInterdepInvokeNN.java (at line 66)\n" + + " return f3(e); // error 2 expected\n" + + " ^\n" + + "Null type safety: required '@NonNull' but this expression has type 'E31', a free type variable that may represent a '@Nullable' type\n" + + "----------\n" + + "3. ERROR in test\\TestInterdepInvokeNN.java (at line 84)\n" + + " return f4(e); // error 3 expected\n" + + " ^\n" + + "Null type safety: required '@NonNull' but this expression has type 'E41', a free type variable that may represent a '@Nullable' type\n" + + "----------\n" + ); +} +public void testBug484741Invoke3() { + runNegativeTestWithLibs( + new String[] { + "test/TestInterdepInvoke.java", + "package test;\n" + + "\n" + + "import java.util.ArrayList;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class TestInterdepInvoke {\n" + + " static void f1(ArrayList list, E1 e) {\n" + + " list.add(e);\n" + + " }\n" + + "\n" + + " static void f2(ArrayList list, E2 e) {\n" + + " list.add(e); // error expected\n" + + " }\n" + + "\n" + + " static void f3(ArrayList list, E3 e) {\n" + + " list.add(e);\n" + + " }\n" + + "\n" + + " static <@Nullable T4, E4 extends T4> void f4(ArrayList list, E4 e) {\n" + + " list.add(e);\n" + + " }\n" + + "\n" + + " static <@Nullable T5, @Nullable E5 extends T5> void f5(ArrayList list, E5 e) {\n" + + " list.add(e);\n" + + " }\n" + + "\n" + + " static <@Nullable T6, @NonNull E6 extends T6> void f6(ArrayList list, E6 e) {\n" + + " list.add(e);\n" + + " }\n" + + "\n" + + " static <@NonNull T7, E7 extends T7> void f7(ArrayList list, E7 e) {\n" + + " list.add(e);\n" + + " }\n" + + "\n" + + " static <@NonNull T8, @Nullable E8 extends T8> void f8(ArrayList list, E8 e) {\n" + + " list.add(e); // error expected\n" + + " }\n" + + "\n" + + " static <@NonNull T9, @NonNull E9 extends T9> void f9(ArrayList list, E9 e) {\n" + + " list.add(e);\n" + + " }\n" + + "\n" + + " // -------- invocations, but all of the 81 combinations removed, that were already handled correctly -----\n" + + "\n" + + " static void g1(ArrayList list, F1 e) {\n" + + " f1(list, e);\n" + + " f2(list, e);\n" + + " }\n" + + "\n" + + " static void g2(ArrayList list, F2 e) {\n" + + " f1(list, e);\n" + + " f2(list, e);\n" + + " }\n" + + "\n" + + " static void g3(ArrayList list, F3 e) {\n" + + " f2(list, e);\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\TestInterdepInvoke.java (at line 14)\n" + + " list.add(e); // error expected\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'T2\' but this expression has type \'@Nullable E2 extends T2\', where \'T2\' is a free type variable\n" + + "----------\n" + + "2. ERROR in test\\TestInterdepInvoke.java (at line 38)\n" + + " list.add(e); // error expected\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull T8\' but this expression has type \'@Nullable E8 extends @NonNull T8\'\n" + + "----------\n" + ); +} + + +public void testBug484471SubclassNullable() { + runNegativeTestWithLibs( + new String[] { + "test/TestInterdepSubClass.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class TestInterdepSubClass {\n" + + " static class A1 {\n" + + " }\n" + + "\n" + + " static class A2 {\n" + + " }\n" + + "\n" + + " static class A3<@Nullable T, E extends T> {\n" + + " }\n" + + "\n" + + " static class A4<@Nullable T, @Nullable E extends T> {\n" + + " }\n" + + "\n" + + " // -------- subclasses of A1 --------\n" + + "\n" + + " static class B11 extends A1 {\n" + + " }\n" + + "\n" + + " static class B12 extends A1 {\n" + + " }\n" + + "\n" + + " static class B13<@Nullable T13, E13 extends T13> extends A1 {\n" + + " }\n" + + "\n" + + " static class B14<@Nullable T14, @Nullable E14 extends T14> extends A1 {\n" + + " }\n" + + "\n" + + " // -------- subclasses of A2 --------\n" + + "\n" + + " static class B21 extends A2 { // expect error 1\n" + + " }\n" + + "\n" + + " static class B22 extends A2 {\n" + + " }\n" + + "\n" + + " static class B23<@Nullable T23, E23 extends T23> extends A2 { // expect error 2\n" + + " }\n" + + "\n" + + " static class B24<@Nullable T24, @Nullable E24 extends T24> extends A2 {\n" + + " }\n" + + "\n" + + " // -------- subclasses of A3<@Nullable T, E extends T> --------\n" + + "\n" + + " static class B31 extends A3 { // expect error 3\n" + + " }\n" + + "\n" + + " static class B32 extends A3 { // expect error 4\n" + + " }\n" + + "\n" + + " static class B33<@Nullable T33, E33 extends T33> extends A3 {\n" + + " }\n" + + "\n" + + " static class B34<@Nullable T34, @Nullable E34 extends T34> extends A3 {\n" + + " }\n" + + "\n" + + " // -------- subclasses of A4<@Nullable T, @Nullable E extends T> --------\n" + + "\n" + + " static class B41 extends A4 { // expect errors 5 & 6\n" + + " }\n" + + "\n" + + " static class B42 extends A4 { // expect error 7\n" + + " }\n" + + "\n" + + " static class B43<@Nullable T43, E43 extends T43> extends A4 { // expect error 8\n" + + " }\n" + + "\n" + + " static class B44<@Nullable T44, @Nullable E44 extends T44> extends A4 {\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\TestInterdepSubClass.java (at line 34)\n" + + " static class B21 extends A2 { // expect error 1\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'E21 extends T21\' is not a valid substitute for the type parameter \'@Nullable E extends T\'\n" + + "----------\n" + + "2. ERROR in test\\TestInterdepSubClass.java (at line 40)\n" + + " static class B23<@Nullable T23, E23 extends T23> extends A2 { // expect error 2\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'E23 extends @Nullable T23\' is not a valid substitute for the type parameter \'@Nullable E extends T\'\n" + + "----------\n" + + "3. ERROR in test\\TestInterdepSubClass.java (at line 48)\n" + + " static class B31 extends A3 { // expect error 3\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'T31\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "4. ERROR in test\\TestInterdepSubClass.java (at line 51)\n" + + " static class B32 extends A3 { // expect error 4\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'T32\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "5. ERROR in test\\TestInterdepSubClass.java (at line 62)\n" + + " static class B41 extends A4 { // expect errors 5 & 6\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'T41\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "6. ERROR in test\\TestInterdepSubClass.java (at line 62)\n" + + " static class B41 extends A4 { // expect errors 5 & 6\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'E41 extends T41\' is not a valid substitute for the type parameter \'@Nullable E extends @Nullable T\'\n" + + "----------\n" + + "7. ERROR in test\\TestInterdepSubClass.java (at line 65)\n" + + " static class B42 extends A4 { // expect error 7\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'T42\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "8. ERROR in test\\TestInterdepSubClass.java (at line 68)\n" + + " static class B43<@Nullable T43, E43 extends T43> extends A4 { // expect error 8\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'E43 extends @Nullable T43\' is not a valid substitute for the type parameter \'@Nullable E extends @Nullable T\'\n" + + "----------\n" + ); +} +public void testBug484471SubclassNonNull() { + runNegativeTestWithLibs( + new String[] { + "test/TestInterdepSubClassNN.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "@java.lang.annotation.Target({ java.lang.annotation.ElementType.TYPE_USE })\n" + + "@interface SomeAnnotation {\n" + + " // just needed as workaround if bug 484981 is not fixed\n" + + "}\n" + + "\n" + + "public class TestInterdepSubClassNN {\n" + + " static class A1 {\n" + + " }\n" + + "\n" + + " static class A2 {\n" + + " }\n" + + "\n" + + " static class A3<@NonNull T, @SomeAnnotation E extends T> {\n" + + " }\n" + + "\n" + + " static class A4<@NonNull T, @NonNull E extends T> {\n" + + " }\n" + + "\n" + + " // -------- subclasses of A1 --------\n" + + "\n" + + " static class B11 extends A1 {\n" + + " }\n" + + "\n" + + " static class B12 extends A1 {\n" + + " }\n" + + "\n" + + " static class B13<@NonNull T13, @SomeAnnotation E13 extends T13> extends A1 {\n" + + " }\n" + + "\n" + + " static class B14<@NonNull T14, @NonNull E14 extends T14> extends A1 {\n" + + " }\n" + + "\n" + + " // -------- subclasses of A2 --------\n" + + "\n" + + " static class B21 extends A2 { // expect error 1\n" + + " }\n" + + "\n" + + " static class B22 extends A2 {\n" + + " }\n" + + "\n" + + " static class B23<@NonNull T23, @SomeAnnotation E23 extends T23> extends A2 {\n" + + " }\n" + + "\n" + + " static class B24<@NonNull T24, @NonNull E24 extends T24> extends A2 {\n" + + " }\n" + + "\n" + + " // -------- subclasses of A3<@NonNull T, E extends T> --------\n" + + "\n" + + " static class B31 extends A3 { // expect errors 2 & 3\n" + + " }\n" + + "\n" + + " static class B32 extends A3 { // expect error 4\n" + + " }\n" + + "\n" + + " static class B33<@NonNull T33, @SomeAnnotation E33 extends T33> extends A3 {\n" + + " }\n" + + "\n" + + " static class B34<@NonNull T34, @NonNull E34 extends T34> extends A3 {\n" + + " }\n" + + "\n" + + " // -------- subclasses of A4<@NonNull T, @NonNull E extends T> --------\n" + + "\n" + + " static class B41 extends A4 { // expect error 5 & 6\n" + + " }\n" + + "\n" + + " static class B42 extends A4 { // expect error 7\n" + + " }\n" + + "\n" + + " static class B43<@NonNull T43, @SomeAnnotation E43 extends T43> extends A4 {\n" + + " }\n" + + "\n" + + " static class B44<@NonNull T44, @NonNull E44 extends T44> extends A4 {\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\TestInterdepSubClassNN.java (at line 39)\n" + + " static class B21 extends A2 { // expect error 1\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'E21 extends T21\' is not a valid substitute for the type parameter \'@NonNull E extends T\'\n" + + "----------\n" + + "2. ERROR in test\\TestInterdepSubClassNN.java (at line 53)\n" + + " static class B31 extends A3 { // expect errors 2 & 3\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'T31\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "3. ERROR in test\\TestInterdepSubClassNN.java (at line 53)\n" + + " static class B31 extends A3 { // expect errors 2 & 3\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'E31 extends T31\' is not a valid substitute for the type parameter \'E extends @NonNull T\'\n" + + "----------\n" + + "4. ERROR in test\\TestInterdepSubClassNN.java (at line 56)\n" + + " static class B32 extends A3 { // expect error 4\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'T32\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "5. ERROR in test\\TestInterdepSubClassNN.java (at line 67)\n" + + " static class B41 extends A4 { // expect error 5 & 6\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'T41\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "6. ERROR in test\\TestInterdepSubClassNN.java (at line 67)\n" + + " static class B41 extends A4 { // expect error 5 & 6\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'E41 extends T41\' is not a valid substitute for the type parameter \'@NonNull E extends @NonNull T\'\n" + + "----------\n" + + "7. ERROR in test\\TestInterdepSubClassNN.java (at line 70)\n" + + " static class B42 extends A4 { // expect error 7\n" + + " ^^^\n" + + "Null constraint mismatch: The type \'T42\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + ); +} +public void testBug485058() { + runNegativeTestWithLibs( + new String[] { + "test/Test4.java", + "package test;\n" + + "\n" + + "import java.io.Serializable;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault\n" + + "class Feature4 {\n" + + " Q q() {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test4 {\n" + + " public static > Q1[] getValues(F feature) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "\n" + + " public static void f(Feature4 feature) {\n" + + " getValues(feature);\n" + + " }\n" + + "\n" + + " public static void g(Feature4<@Nullable ? extends @NonNull Serializable> feature) {\n" + + " getValues(feature);\n" + + " }\n" + + "}" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\Test4.java (at line 25)\n" + + " public static void g(Feature4<@Nullable ? extends @NonNull Serializable> feature) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable ? extends @NonNull Serializable\' is not a valid substitute for the type parameter \'Q extends @NonNull Serializable\'\n" + + "----------\n" + + "2. ERROR in test\\Test4.java (at line 25)\n" + + " public static void g(Feature4<@Nullable ? extends @NonNull Serializable> feature) {\n" + + " ^^^^^^^^\n" + + "This nullness annotation conflicts with a \'@Nullable\' annotation which is effective on the same type parameter \n" + + "----------\n" + + "3. ERROR in test\\Test4.java (at line 26)\n" + + " getValues(feature);\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull Feature4<@Nullable capture#of ? extends @NonNull Serializable>\' is not a valid substitute for the type parameter \'F extends @NonNull Feature4\'\n" + + "----------\n" + ); +} +public void testBug485030() { + runConformTestWithLibs(new String[] { + "SomeAnnotation.java", + "import static java.lang.annotation.ElementType.TYPE_USE;\n" + + "import java.lang.annotation.Target;\n" + + + "@Target({ TYPE_USE })\n" + + "@interface SomeAnnotation {\n" + + "}\n", + + "TestContradictoryOnGenericArray.java", + "import java.io.Serializable;\n" + + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + + "@NonNullByDefault\n" + + "public class TestContradictoryOnGenericArray {\n" + + " public <@SomeAnnotation Q extends Serializable> void f() {\n" + + " final @Nullable Q[] array = null;\n" + + " }\n" + + "}\n" + }, getCompilerOptions(), ""); +} +public void testBug485302() { + runNegativeTestWithLibs( + new String[] { + "WildCardNullable.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class WildCardNullable {\n" + + " static class A {\n" + + " @Nullable\n" + + " T returnNull() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " void acceptNonNullT(@NonNull T t) {\n" + + " }\n" + + "\n" + + " void acceptNonNullObject(@NonNull Object x) {\n" + + " }\n" + + " }\n" + + "\n" + + " static @NonNull Number g(A a) {\n" + + " return a.returnNull(); // error 1 expected\n" + + " }\n" + + "\n" + + " public static final void map(final A<@NonNull ? super T> a, T t) {\n" + + " a.acceptNonNullT(t); // warning 2 expected\n" + + " a.acceptNonNullObject(t); // warning 3 expected\n" + + " }\n" + + "}\n" + + "" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in WildCardNullable.java (at line 21)\n" + + " return a.returnNull(); // error 1 expected\n" + + " ^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Number\' but this expression has type \'@Nullable capture#of ? extends Number\'\n" + + "----------\n" + + "2. ERROR in WildCardNullable.java (at line 25)\n" + + " a.acceptNonNullT(t); // warning 2 expected\n" + + " ^\n" + + "Null type safety: required '@NonNull' but this expression has type 'T', a free type variable that may represent a '@Nullable' type\n" + + "----------\n" + + "3. ERROR in WildCardNullable.java (at line 26)\n" + + " a.acceptNonNullObject(t); // warning 3 expected\n" + + " ^\n" + + "Null type safety: required '@NonNull' but this expression has type 'T', a free type variable that may represent a '@Nullable' type\n" + + "----------\n" + ); +} + +public void testBug485027() { + runConformTestWithLibs(new String[] { + "SomeAnnotation.java", + "import static java.lang.annotation.ElementType.TYPE_USE;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ TYPE_USE })\n" + + "@interface SomeAnnotation {\n" + + "}\n", + + "Base.java", + "import java.io.Serializable;\n" + + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + + "@NonNullByDefault\n" + + "public class Base {\n" + + " public <@SomeAnnotation Q extends Serializable> void setValuesArray(Q @Nullable [] value) {\n" + + " }\n" + + "}\n" + }, getCompilerOptions(), ""); + + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "Derived.java", + "import java.io.Serializable;\n" + + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + + "@NonNullByDefault\n" + + "public class Derived extends Base {\n" + + " @Override\n" + + " public final <@SomeAnnotation Q1 extends Serializable> void setValuesArray(Q1 @Nullable [] value) {\n" + + " }\n" + + "}" + }, getCompilerOptions(), ""); +} +public void testBug485565() { + runConformTestWithLibs( + new String[] { + "test2/ClassWithRegistry.java", + "package test2;\n" + + "\n" + + "import java.rmi.registry.Registry;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class ClassWithRegistry {\n" + + " @Nullable\n" + + " public Registry registry;\n" + + "}\n" + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test1/ClassWithLambda.java", + "package test1;\n" + + "\n" + + "import test2.ClassWithRegistry;\n" + + "\n" + + "// must be compiled before ZClassWithBug\n" + + "public class ClassWithLambda {\n" + + " interface Lambda {\n" + + " void f();\n" + + " }\n" + + "\n" + + " public static void invoke(Lambda lambda) {\n" + + " lambda.f();\n" + + " }\n" + + "\n" + + " public void f() {\n" + + " new ClassWithRegistry(); // must be accessed as class file\n" + + " invoke(() -> java.rmi.registry.Registry.class.hashCode());\n" + + " }\n" + + "}\n", + "test1/ZClassWithBug.java", + "package test1;\n" + + "\n" + + "import java.rmi.registry.Registry;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault\n" + + "public abstract class ZClassWithBug {\n" + + "\n" + + " @Nullable\n" + + " public Registry rmiregistry;\n" + + "}\n" + }, + getCompilerOptions(), + "" + ); +} +public void testBug485814() { + runConformTestWithLibs( + new String[] { + "test/ExplainedResult.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class ExplainedResult extends Result {\n" + + "\n" + + " public ExplainedResult(int score, V2 extractedValue2) {\n" + + " super(score, extractedValue2);\n" + + " }\n" + + "\n" + + " @Override\n" + + " public ExplainedResult withValue(OtherV2 otherValue2) {\n" + + " return new ExplainedResult(this.score, otherValue2);\n" + + " }\n" + + "}\n" + + "", + "test/Result.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Result {\n" + + "\n" + + " public final int score;\n" + + "\n" + + " public final V1 extractedValue;\n" + + "\n" + + " public Result(int score, V1 extractedValue1) {\n" + + " this.score = score;\n" + + " this.extractedValue = extractedValue1;\n" + + " }\n" + + "\n" + + " public Result withValue(OtherV1 otherValue1) {\n" + + " return new Result(score, otherValue1);\n" + + " }\n" + + "}\n" + + "" + }, + getCompilerOptions(), + "" + ); +} +public void testBug485581() { + runConformTestWithLibs( + new String[] { + "test/MatchResult.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class MatchResult implements Comparable> {\n" + + " public final int score;\n" + + " public final V value;\n" + + "\n" + + " public MatchResult(int score, V value) {\n" + + " this.score = score;\n" + + " this.value = value;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public int compareTo(MatchResult o) {\n" + + " return score - o.score;\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test/FVEHandler.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class FVEHandler {\n" + + " public static void process(MatchResult matchResult) {\n" + + " if (matchResult.value != null) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "" + ); +} +public void testBug482752_lambda() { + runConformTestWithLibs( + new String[] { + "test/StringProcessor.java", + "package test;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public interface StringProcessor {\n" + + " void process(String value);\n" + + "\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test/Foo.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public final class Foo {\n" + + "\n" + + " public static StringProcessor createProcessorLambdaExpression() {\n" + + " return (@NonNull String value) -> Foo.test(value);\n" + + " }\n" + + "\n" + + " public static void test(@NonNull String value) {\n" + + " System.out.println(value);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} + +public void testBug482752_methodref() { + runConformTestWithLibs( + new String[] { + "test/StringProcessor.java", + "package test;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public interface StringProcessor {\n" + + " void process(String value);\n" + + "\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test/Foo.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public final class Foo {\n" + + "\n" + + " public static StringProcessor createProcessorMethodReference() {\n" + + " return Foo::test;\n" + + " }\n" + + "\n" + + " public static void test(@NonNull String value) {\n" + + " System.out.println(value);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} + +public void testBug485374() { + runConformTestWithLibs( + new String[] { + "test/I.java", + "package test;\n" + + "public interface I {\n" + + " public class Nested {\n" + + " }\n" + + "}\n" + + "", + "test/D.java", + "package test;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class D implements I {\n" + + "}\n" + + "" + }, + getCompilerOptions(), + "" + ); + runWarningTestWithLibs( + false/*flush*/, + new String[] { + "test2/Import.java", + "package test2;\n" + + "import test.D;\n" + + "class Import {}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in test2\\Import.java (at line 2)\n" + + " import test.D;\n" + + " ^^^^^^\n" + + "The import test.D is never used\n" + + "----------\n" + ); +} + +public void testBug466556a() { + runNegativeTestWithLibs( + new String[] { + "test/C.java", + "package test;\n" + + "class C {\n" + + " int consume(T t) {\n" + + " return t.intValue(); // NOT OK since T could be nullable\n" + + " }\n" + + " T provide() {\n" + + " return null; // NOT OK since T could require nonnull\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\C.java (at line 4)\n" + + " return t.intValue(); // NOT OK since T could be nullable\n" + + " ^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in test\\C.java (at line 7)\n" + + " return null; // NOT OK since T could require nonnull\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): \'null\' is not compatible to the free type variable \'T\'\n" + + "----------\n" + ); +} +public void testBug466556nonfree() { + runNegativeTestWithLibs( + new String[] { + "test/C.java", + "package test;\n" + + "class C {\n" + + " int consume(T t) {\n" + + " return t.intValue(); // OK since T has upper bound with @NonNull\n" + + " }\n" + + " T provide() {\n" + + " return null; // NOT OK since T could require nonnull\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\C.java (at line 7)\n" + + " return null; // NOT OK since T could require nonnull\n" + + " ^^^^\n" + + "Null type mismatch: required \'T extends @NonNull Number\' but the provided value is null\n" + + "----------\n" + ); +} +public void testBug466556b() { + runNegativeTestWithLibs( + new String[] { + "test/C.java", + "package test;\n" + + "\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "class C {\n" + + " int consume(T t) {\n" + + " return t.hashCode();\n" + + " }\n" + + " void consume2(Supplier s) {\n" + + " s.get().hashCode();\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\C.java (at line 7)\n" + + " return t.hashCode();\n" + + " ^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in test\\C.java (at line 10)\n" + + " s.get().hashCode();\n" + + " ^^^^^^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + ); +} +public void testBug466556c() { + runNegativeTestWithLibs( + new String[] { + "test/C.java", + "package test;\n" + + "\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "class C {\n" + + " int consume(T t) {\n" + + " Number n = t;\n" + + " return n.intValue();\n" + + " }\n" + + "\n" + + " int consume2(Supplier s) {\n" + + " Number n = s.get();\n" + + " return n.intValue();\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\C.java (at line 8)\n" + + " return n.intValue();\n" + + " ^\n" + + "Potential null pointer access: The variable n may be null at this location\n" + + "----------\n" + + "2. ERROR in test\\C.java (at line 13)\n" + + " return n.intValue();\n" + + " ^\n" + + "Potential null pointer access: The variable n may be null at this location\n" + + "----------\n" + ); +} +public void testBug466556field() { + runNegativeTestWithLibs( + new String[] { + "test/D.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class E {\n" + + " T t;\n" + + "}\n" + + "\n" + + "class D {\n" + + " enum X {\n" + + " x\n" + + " };\n" + + "\n" + + " T t1;\n" + + " T t2;\n" + + " T t3;\n" + + " @Nullable\n" + + " T t4;\n" + + " @NonNull\n" + + " T t5;\n" + + " @NonNull\n" + + " T t6;\n" + + " @NonNull\n" + + " T t7;\n" + + "\n" + + " D(@NonNull T t) {\n" + + " t2 = t;\n" + + " switch (X.x) {\n" + + " case x:\n" + + " t1 = t;\n" + + " t5 = t;\n" + + " }\n" + + " t6 = t;\n" + + " }\n" + + "\n" + + " void f() {\n" + + " t1.hashCode();\n" + + " t2.hashCode();\n" + + " t3.hashCode();\n" + + " t4.hashCode();\n" + + " t5.hashCode();\n" + + " t6.hashCode();\n" + + " t7.hashCode();\n" + + " T t = t1;\n" + + " t.hashCode();\n" + + " }\n" + + " void g() {\n" + + " if(t1 != null)\n" + + " t1.hashCode();\n // problem report expected because syntactic null analysis for fields is off\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\D.java (at line 7)\n" + + " T t;\n" + + " ^\n" + + "The field t may not have been initialized, whereas its type \'T\' is a free type variable that may represent a \'@NonNull\' type\n" + + "----------\n" + + "2. ERROR in test\\D.java (at line 27)\n" + + " D(@NonNull T t) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The field t1 may not have been initialized, whereas its type \'T\' is a free type variable that may represent a \'@NonNull\' type. Note that a problem regarding missing \'default:\' on \'switch\' has been suppressed, which is perhaps related to this problem\n" + + "----------\n" + + "3. ERROR in test\\D.java (at line 27)\n" + + " D(@NonNull T t) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The field t3 may not have been initialized, whereas its type \'T\' is a free type variable that may represent a \'@NonNull\' type. Note that a problem regarding missing \'default:\' on \'switch\' has been suppressed, which is perhaps related to this problem\n" + + "----------\n" + + "4. ERROR in test\\D.java (at line 27)\n" + + " D(@NonNull T t) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The @NonNull field t5 may not have been initialized. Note that a problem regarding missing \'default:\' on \'switch\' has been suppressed, which is perhaps related to this problem\n" + + "----------\n" + + "5. ERROR in test\\D.java (at line 27)\n" + + " D(@NonNull T t) {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The @NonNull field t7 may not have been initialized. Note that a problem regarding missing \'default:\' on \'switch\' has been suppressed, which is perhaps related to this problem\n" + + "----------\n" + + "6. ERROR in test\\D.java (at line 38)\n" + + " t1.hashCode();\n" + + " ^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "7. ERROR in test\\D.java (at line 39)\n" + + " t2.hashCode();\n" + + " ^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "8. ERROR in test\\D.java (at line 40)\n" + + " t3.hashCode();\n" + + " ^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "9. ERROR in test\\D.java (at line 41)\n" + + " t4.hashCode();\n" + + " ^^\n" + + "Potential null pointer access: this expression has a \'@Nullable\' type\n" + + "----------\n" + + "10. ERROR in test\\D.java (at line 46)\n" + + " t.hashCode();\n" + + " ^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "11. ERROR in test\\D.java (at line 50)\n" + + " t1.hashCode();\n" + + " ^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + ); +} +public void testBug466556withRaw() { + runConformTestWithLibs( + new String[] { + "test/TestWithRaw.java", + "package test;\n" + + "\n" + + "public class TestWithRaw {\n" + + " @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n" + + " public static void uncheckedEnumValueOf(final Class valueClass, final String value) {\n" + + " Class valueClass2 = valueClass;\n" + + " Enum.valueOf(valueClass2, value).name();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug466556withPGMB() { + runNegativeTestWithLibs( + new String[] { + "test/TestWithParameterizedGenericMethodBinding.java", + "package test;\n" + + "\n" + + "public class TestWithParameterizedGenericMethodBinding {\n" + + " static T f1(E e) {\n" + + " return e;\n" + + " }\n" + + "\n" + + " static void g11(E11 e) {\n" + + " f1(e).hashCode();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\TestWithParameterizedGenericMethodBinding.java (at line 9)\n" + + " f1(e).hashCode();\n" + + " ^^^^^\n" + + "Potential null pointer access: this expression has type \'E11\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + ); +} +public void testBug466556captures() { + runNegativeTestWithLibs( + new String[] { + "test/TestCapture.java", + "package test;\n" + + "\n" + + "class I {\n" + + " int i;\n" + + "\n" + + " String s() {\n" + + " return \"\";\n" + + " }\n" + + "}\n" + + "\n" + + "class KE {\n" + + " public final E e;\n" + + "\n" + + " public E getE() {\n" + + " return e;\n" + + " }\n" + + "\n" + + " public KE(E element) {\n" + + " this.e = element;\n" + + " }\n" + + "}\n" + + "\n" + + "class TestFreeTypeVariable {\n" + + " public void test(KE ke) {\n" + + " int i1 = ke.e.i; // error 1\n" + + " ke.e.s().substring(i1); // error 2\n" + + " int i2 = ke.getE().i; // error 3\n" + + " ke.getE().s().substring(i2); // error 4\n" + + " }\n" + + "}\n" + + "\n" + + "public class TestCapture {\n" + + " public void test(KE ke) {\n" + + " int i1 = ke.e.i; // error 5\n" + + " ke.e.s().substring(i1); // error 6\n" + + " int i2 = ke.getE().i; // error 7\n" + + " ke.getE().s().substring(i2); // error 8\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\TestCapture.java (at line 25)\n" + + " int i1 = ke.e.i; // error 1\n" + + " ^\n" + + "Potential null pointer access: this expression has type \'E2\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in test\\TestCapture.java (at line 26)\n" + + " ke.e.s().substring(i1); // error 2\n" + + " ^\n" + + "Potential null pointer access: this expression has type \'E2\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "3. ERROR in test\\TestCapture.java (at line 27)\n" + + " int i2 = ke.getE().i; // error 3\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: this expression has type \'E2\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "4. ERROR in test\\TestCapture.java (at line 28)\n" + + " ke.getE().s().substring(i2); // error 4\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: this expression has type \'E2\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "5. ERROR in test\\TestCapture.java (at line 34)\n" + + " int i1 = ke.e.i; // error 5\n" + + " ^\n" + + "Potential null pointer access: this expression has type \'capture#1-of ? extends test.I\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "6. ERROR in test\\TestCapture.java (at line 35)\n" + + " ke.e.s().substring(i1); // error 6\n" + + " ^\n" + + "Potential null pointer access: this expression has type \'capture#2-of ? extends test.I\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "7. ERROR in test\\TestCapture.java (at line 36)\n" + + " int i2 = ke.getE().i; // error 7\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: this expression has type \'capture#3-of ? extends test.I\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "8. ERROR in test\\TestCapture.java (at line 37)\n" + + " ke.getE().s().substring(i2); // error 8\n" + + " ^^^^^^^^^\n" + + "Potential null pointer access: this expression has type \'capture#4-of ? extends test.I\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + ); +} +public void testBug466556Loops() { + runNegativeTestWithLibs( + new String[] { + "test/TestLoop.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class TestLoop {\n" + + " boolean b;\n" + + "\n" + + " public static void nn(@NonNull Object value) {\n" + + " assert value != null;\n" + + " }\n" + + "\n" + + " public void testDoWhile(T t1) {\n" + + " nn(t1); // 1: unchecked warning\n" + + " do {\n" + + " nn(t1); // 2: unchecked warning\n" + + " t1.hashCode(); // 3: Potential null pointer access...free type variable\n" + + " } while (b);\n" + + " }\n" + + "\n" + + " public void testWhileWithBreak(T t1) {\n" + + " while (true) {\n" + + " nn(t1); // 4: unchecked warning\n" + + " t1.hashCode(); // 5: Potential null pointer access...free type variable\n" + + " if (b)\n" + + " break;\n" + + " }\n" + + " }\n" + + "\n" + + " public void testWhile(T t1) {\n" + + " while (TestLoop.class.hashCode() == 4711) {\n" + + " nn(t1); // 6: unchecked warning\n" + + " t1.hashCode(); // 7: Potential null pointer access...free type variable\n" + + " }\n" + + " }\n" + + "\n" + + " public void testFor(T t1) {\n" + + " for (int i = 0; i < 1; i++) {\n" + + " nn(t1); // 8: unchecked warning\n" + + " t1.hashCode(); // 9: Potential null pointer access...free type variable\n" + + " }\n" + + " }\n" + + "\n" + + " public void testForEach(T t1) {\n" + + " for (int i = 0; i < 1; i++) {\n" + + " nn(t1); // 10: unchecked warning\n" + + " t1.hashCode(); // 11: Potential null pointer access: The variable t1 may be null at this location\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\TestLoop.java (at line 13)\n" + + " nn(t1); // 1: unchecked warning\n" + + " ^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in test\\TestLoop.java (at line 15)\n" + + " nn(t1); // 2: unchecked warning\n" + + " ^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "3. ERROR in test\\TestLoop.java (at line 16)\n" + + " t1.hashCode(); // 3: Potential null pointer access...free type variable\n" + + " ^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "4. ERROR in test\\TestLoop.java (at line 22)\n" + + " nn(t1); // 4: unchecked warning\n" + + " ^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "5. ERROR in test\\TestLoop.java (at line 23)\n" + + " t1.hashCode(); // 5: Potential null pointer access...free type variable\n" + + " ^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "6. ERROR in test\\TestLoop.java (at line 31)\n" + + " nn(t1); // 6: unchecked warning\n" + + " ^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "7. ERROR in test\\TestLoop.java (at line 32)\n" + + " t1.hashCode(); // 7: Potential null pointer access...free type variable\n" + + " ^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "8. ERROR in test\\TestLoop.java (at line 38)\n" + + " nn(t1); // 8: unchecked warning\n" + + " ^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "9. ERROR in test\\TestLoop.java (at line 39)\n" + + " t1.hashCode(); // 9: Potential null pointer access...free type variable\n" + + " ^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "10. ERROR in test\\TestLoop.java (at line 45)\n" + + " nn(t1); // 10: unchecked warning\n" + + " ^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "11. ERROR in test\\TestLoop.java (at line 46)\n" + + " t1.hashCode(); // 11: Potential null pointer access: The variable t1 may be null at this location\n" + + " ^^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + ); +} +public void testBug461268() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportNonNullTypeVariableFromLegacyInvocation, JavaCore.ERROR); + compilerOptions.put(CompilerOptions.OPTION_PessimisticNullAnalysisForFreeTypeVariables, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.List;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void test(List<@NonNull String> list) {\n" + + " @NonNull String s = list.get(0);\n" + + " }\n" + + "}\n" + }, + compilerOptions, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @NonNull String s = list.get(0);\n" + + " ^^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'List<@NonNull String>\'. Type \'List\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n"); +} +public void testBug461268invoke() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportNonNullTypeVariableFromLegacyInvocation, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class X {\n" + + " void test(Map map) {\n" + + " map.get(this).length();\n" + + " }\n" + + "}\n" + }, + compilerOptions, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " map.get(this).length();\n" + + " ^^^^^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'Map\'. Type \'Map\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n"); +} +public void testBug461268nnbd() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportNonNullTypeVariableFromLegacyInvocation, JavaCore.ERROR); + runConformTestWithLibs( + new String[] { + "test2/Container.java", + "package test2;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Container {\n" + + " public static T getFrom(Container container) {\n" + + " return container.get();\n" + + " }\n" + + "\n" + + " private final T t;\n" + + "\n" + + " public Container(T t) {\n" + + " this.t = t;\n" + + " }\n" + + "\n" + + " private T get() {\n" + // we really mean 'T' unannotated, believe it due to @NonNullByDefault + " return this.t;\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "import test2.Container;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + " String f(Container c) {\n" + + " return Container.getFrom(c);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug485988WildcardOverride() { + runConformTestWithLibs( + new String[] { + "test/Result.java", + "package test;\n" + + "\n" + + "public class Result implements Comparable> {\n" + + " public final int score;\n" + + " public final V value;\n" + + "\n" + + " protected Result(int score, V value) {\n" + + " this.score = score;\n" + + " this.value = value;\n" + + " }\n" + + " @Override\n" + + " public int compareTo(Result o) {\n" + + " return score - o.score;\n" + + " }\n" + + "}\n", + "test/Base.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public abstract class Base {\n" + + " public abstract Result matches();\n" + + "}\n", + "test/Derived.java", + "package test;\n" + + "\n" + + "import java.math.BigDecimal;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Derived extends Base {\n" + + " @Override\n" + + " public Result matches() {\n" + + " return new Result(0, new BigDecimal(\"1\"));\n" + + " }\n" + + "}\n", + }, + getCompilerOptions(), + "" + ); +} +public void testBug485988neutral() { + runConformTestWithLibs( + new String[] { + "neutral/WildcardTest.java", + "package neutral;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault\n" + + "class A {\n" + + "}\n" + + "\n" + + "abstract class X {\n" + + " abstract A g1();\n" + + "\n" + + " abstract A g2();\n" + + "\n" + + " abstract A g2b();\n" + + "\n" + + " abstract A g3();\n" + + "\n" + + " abstract A h1();\n" + + "\n" + + " abstract A h2();\n" + + "\n" + + " abstract A h2b();\n" + + "\n" + + " abstract A h3();\n" + + "}\n" + + "\n" + + "class Y extends X {\n" + + " @Override\n" + + " A g1() {\n" + + " return new A<@NonNull String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@NonNull ?> g2() {\n" + + " return new A<@NonNull String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A g2b() {\n" + + " return new A<@NonNull Integer>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@NonNull String> g3() {\n" + + " return new A<@NonNull String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A h1() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@Nullable ?> h2() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A h2b() {\n" + + " return new A<@Nullable Object>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@Nullable String> h3() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class WildcardTest {\n" + + " void f(A a) {\n" + + " }\n" + + "\n" + + " void g(A a) {\n" + + " }\n" + + "\n" + + " void invoke(T2 t) {\n" + + " f(new A());\n" + + " g(new A());\n" + + "\n" + + " f(new A<@NonNull T2>());\n" + + " g(new A<@NonNull T2>());\n" + + "\n" + + " f(new A<@Nullable T2>());\n" + + " g(new A<@Nullable T2>());\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug485988nonnull() { + runNegativeTestWithLibs( + new String[] { + "nonnull/WildcardNonNullTest.java", + "package nonnull;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault\n" + + "class A<@NonNull T> {\n" + + "}\n" + + "\n" + + "abstract class X {\n" + + " abstract A<@NonNull ?> g1();\n" + + "\n" + + " abstract A<@NonNull ?> g2();\n" + + "\n" + + " abstract A<@NonNull ?> g2b();\n" + + "\n" + + " abstract A<@NonNull ?> g3();\n" + + "\n" + + " abstract A<@NonNull ?> h1();\n" + + "\n" + + " abstract A<@NonNull ?> h2();\n" + + "\n" + + " abstract A<@NonNull ?> h2b();\n" + + "\n" + + " abstract A<@NonNull ?> h3();\n" + + "}\n" + + "\n" + + "class Y extends X {\n" + + " @Override\n" + + " A g1() {\n" + + " return new A<@NonNull String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@NonNull ?> g2() {\n" + + " return new A<@NonNull String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A g2b() {\n" + + " return new A<@NonNull Integer>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@NonNull String> g3() {\n" + + " return new A<@NonNull String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A h1() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@Nullable ?> h2() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A h2b() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@Nullable String> h3() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class WildcardNonNullTest {\n" + + " void f(A a) {\n" + + " }\n" + + "\n" + + " <@NonNull T1> void g(A a) {\n" + + " }\n" + + "\n" + + " void invoke(T2 t) {\n" + + " f(new A());\n" + + " g(new A());\n" + + "\n" + + " f(new A<@NonNull T2>());\n" + + " g(new A<@NonNull T2>());\n" + + "\n" + + " f(new A<@Nullable T2>());\n" + + " g(new A<@Nullable T2>());\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in nonnull\\WildcardNonNullTest.java (at line 52)\n" + + " return new A<@Nullable String>();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable String\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "2. ERROR in nonnull\\WildcardNonNullTest.java (at line 56)\n" + + " A<@Nullable ?> h2() {\n" + + " ^\n" + + "The return type is incompatible with \'A<@NonNull ?>\' returned from X.h2() (mismatching null constraints)\n" + + "----------\n" + + "3. ERROR in nonnull\\WildcardNonNullTest.java (at line 56)\n" + + " A<@Nullable ?> h2() {\n" + + " ^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable ?\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "4. ERROR in nonnull\\WildcardNonNullTest.java (at line 57)\n" + + " return new A<@Nullable String>();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable String\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "5. ERROR in nonnull\\WildcardNonNullTest.java (at line 61)\n" + + " A h2b() {\n" + + " ^\n" + + "The return type is incompatible with \'A<@NonNull ?>\' returned from X.h2b() (mismatching null constraints)\n" + + "----------\n" + + "6. ERROR in nonnull\\WildcardNonNullTest.java (at line 61)\n" + + " A h2b() {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'? super @Nullable String\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "7. ERROR in nonnull\\WildcardNonNullTest.java (at line 62)\n" + + " return new A<@Nullable String>();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable String\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "8. ERROR in nonnull\\WildcardNonNullTest.java (at line 66)\n" + + " A<@Nullable String> h3() {\n" + + " ^\n" + + "The return type is incompatible with \'A<@NonNull ?>\' returned from X.h3() (mismatching null constraints)\n" + + "----------\n" + + "9. ERROR in nonnull\\WildcardNonNullTest.java (at line 66)\n" + + " A<@Nullable String> h3() {\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable String\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "10. ERROR in nonnull\\WildcardNonNullTest.java (at line 67)\n" + + " return new A<@Nullable String>();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable String\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "11. ERROR in nonnull\\WildcardNonNullTest.java (at line 80)\n" + + " f(new A());\n" + + " ^^\n" + + "Null constraint mismatch: The type \'T2\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "12. WARNING in nonnull\\WildcardNonNullTest.java (at line 81)\n" + + " g(new A());\n" + + " ^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'@NonNull A\' needs unchecked conversion to conform to \'@NonNull A<@NonNull T2>\'\n" + + "----------\n" + + "13. ERROR in nonnull\\WildcardNonNullTest.java (at line 81)\n" + + " g(new A());\n" + + " ^^\n" + + "Null constraint mismatch: The type \'T2\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "14. ERROR in nonnull\\WildcardNonNullTest.java (at line 86)\n" + + " f(new A<@Nullable T2>());\n" + + " ^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable T2\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + + "15. ERROR in nonnull\\WildcardNonNullTest.java (at line 87)\n" + + " g(new A<@Nullable T2>());\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull A<@NonNull T2>\' but this expression has type \'@NonNull A<@Nullable T2>\'\n" + + "----------\n" + + "16. ERROR in nonnull\\WildcardNonNullTest.java (at line 87)\n" + + " g(new A<@Nullable T2>());\n" + + " ^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable T2\' is not a valid substitute for the type parameter \'@NonNull T\'\n" + + "----------\n" + ); +} +public void testBug485988nullable() { + runNegativeTestWithLibs( + new String[] { + "nullable/WildcardNullableTest.java", + "package nullable;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault\n" + + "class A<@Nullable T> {\n" + + "}\n" + + "\n" + + "abstract class X {\n" + + " abstract A<@Nullable ?> g1();\n" + + "\n" + + " abstract A<@Nullable ?> g2();\n" + + "\n" + + " abstract A<@Nullable ?> g2b();\n" + + "\n" + + " abstract A<@Nullable ?> g3();\n" + + "\n" + + " abstract A<@Nullable ?> h1();\n" + + "\n" + + " abstract A<@Nullable ?> h2();\n" + + "\n" + + " abstract A<@Nullable ?> h2b();\n" + + "\n" + + " abstract A<@Nullable ?> h3();\n" + + "}\n" + + "\n" + + "class Y extends X {\n" + + " @Override\n" + + " A g1() {\n" + + " return new A<@NonNull String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@NonNull ?> g2() {\n" + + " return new A<@NonNull String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A g2b() {\n" + + " return new A<@NonNull Integer>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@NonNull String> g3() {\n" + + " return new A<@NonNull String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A h1() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@Nullable ?> h2() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A h2b() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "\n" + + " @Override\n" + + " A<@Nullable String> h3() {\n" + + " return new A<@Nullable String>();\n" + + " }\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class WildcardNullableTest {\n" + + " void f(A a) {\n" + + " }\n" + + "\n" + + " <@Nullable T1> void g(A a) {\n" + + " }\n" + + "\n" + + " void invoke(T2 t) {\n" + + " f(new A());\n" + + " g(new A());\n" + + "\n" + + " f(new A<@NonNull T2>());\n" + + " g(new A<@NonNull T2>());\n" + + "\n" + + " f(new A<@Nullable T2>());\n" + + " g(new A<@Nullable T2>());\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in nullable\\WildcardNullableTest.java (at line 32)\n" + + " return new A<@NonNull String>();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "2. ERROR in nullable\\WildcardNullableTest.java (at line 36)\n" + + " A<@NonNull ?> g2() {\n" + + " ^\n" + + "The return type is incompatible with \'A<@Nullable ?>\' returned from X.g2() (mismatching null constraints)\n" + + "----------\n" + + "3. ERROR in nullable\\WildcardNullableTest.java (at line 36)\n" + + " A<@NonNull ?> g2() {\n" + + " ^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull ?\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "4. ERROR in nullable\\WildcardNullableTest.java (at line 37)\n" + + " return new A<@NonNull String>();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "5. ERROR in nullable\\WildcardNullableTest.java (at line 41)\n" + + " A g2b() {\n" + + " ^\n" + + "The return type is incompatible with \'A<@Nullable ?>\' returned from X.g2b() (mismatching null constraints)\n" + + "----------\n" + + "6. ERROR in nullable\\WildcardNullableTest.java (at line 41)\n" + + " A g2b() {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'? extends @NonNull Number\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "7. ERROR in nullable\\WildcardNullableTest.java (at line 42)\n" + + " return new A<@NonNull Integer>();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull Integer\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "8. ERROR in nullable\\WildcardNullableTest.java (at line 46)\n" + + " A<@NonNull String> g3() {\n" + + " ^\n" + + "The return type is incompatible with \'A<@Nullable ?>\' returned from X.g3() (mismatching null constraints)\n" + + "----------\n" + + "9. ERROR in nullable\\WildcardNullableTest.java (at line 46)\n" + + " A<@NonNull String> g3() {\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "10. ERROR in nullable\\WildcardNullableTest.java (at line 47)\n" + + " return new A<@NonNull String>();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull String\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "11. ERROR in nullable\\WildcardNullableTest.java (at line 80)\n" + + " f(new A());\n" + + " ^^\n" + + "Null constraint mismatch: The type \'T2\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "12. WARNING in nullable\\WildcardNullableTest.java (at line 81)\n" + + " g(new A());\n" + + " ^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'@NonNull A\' needs unchecked conversion to conform to \'@NonNull A<@Nullable T2>\'\n" + + "----------\n" + + "13. ERROR in nullable\\WildcardNullableTest.java (at line 81)\n" + + " g(new A());\n" + + " ^^\n" + + "Null constraint mismatch: The type \'T2\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "14. ERROR in nullable\\WildcardNullableTest.java (at line 83)\n" + + " f(new A<@NonNull T2>());\n" + + " ^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull T2\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + + "15. ERROR in nullable\\WildcardNullableTest.java (at line 84)\n" + + " g(new A<@NonNull T2>());\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull A<@Nullable T2>\' but this expression has type \'@NonNull A<@NonNull T2>\'\n" + + "----------\n" + + "16. ERROR in nullable\\WildcardNullableTest.java (at line 84)\n" + + " g(new A<@NonNull T2>());\n" + + " ^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@NonNull T2\' is not a valid substitute for the type parameter \'@Nullable T\'\n" + + "----------\n" + ); +} +public void testBug485988WildCardForTVWithNonNullBound() { + runConformTestWithLibs( + new String[] { + "test/WildCard.java", + "package test;\n" + + "\n" + + "import java.io.Serializable;\n" + + "import java.util.ArrayList;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "class F {\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class WildCard {\n" + + " void f(ArrayList> list) {\n" + + " for (F f : list) {\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug485988WildcardWithGenericBound() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "test/Test1.java", + "package test;\n" + + "import java.util.Collection;\n" + + "import java.util.Iterator;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "interface LibA {\n" + + " Iterator constrainedWildcards(Collection in);\n" + + "}\n" + + "public class Test1 {\n" + + " Iterator test3(LibA lib, Collection coll) {\n" + + " return lib.constrainedWildcards(coll);\n" + + " }\n" + + "}\n" + + "\n", + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in test\\Test1.java (at line 11)\n" + + " return lib.constrainedWildcards(coll);\n" + + " ^^^^\n" + + "Null type safety (type annotations): The expression of type \'Collection\' needs unchecked conversion to conform to \'Collection\'\n" + + "----------\n" + ); +} +public void testBug485988Contradictory() { + runNegativeTestWithLibs( + new String[] { + "test/Test1.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "interface A {\n" + + "}\n" + + "public class Test1{\n" + + " void f1(A<@Nullable @NonNull ?> a) {\n" + + " }\n" + + " void f2(A<@NonNull @Nullable ?> a) {\n" + + " }\n" + + " void f3(A<@Nullable ? extends @NonNull Object> a) {\n" + + " }\n" + + " void f4(A<@NonNull ? super @Nullable Integer> a) {\n" + + " }\n" + + " void f5(A<@Nullable ? super @Nullable Integer> a) {\n" + // OK + " }\n" + + " @NonNullByDefault void f6(A<@Nullable ? extends Integer> a) {\n" + // OK + " }\n" + + "}\n" + + "\n", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\Test1.java (at line 7)\n" + + " void f1(A<@Nullable @NonNull ?> a) {\n" + + " ^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + + "2. ERROR in test\\Test1.java (at line 9)\n" + + " void f2(A<@NonNull @Nullable ?> a) {\n" + + " ^^^^^^^^^\n" + + "Contradictory null specification; only one of @NonNull and @Nullable can be specified at any location\n" + + "----------\n" + + "3. ERROR in test\\Test1.java (at line 11)\n" + + " void f3(A<@Nullable ? extends @NonNull Object> a) {\n" + + " ^^^^^^^^\n" + + "This nullness annotation conflicts with a \'@Nullable\' annotation which is effective on the same type parameter \n" + + "----------\n" + + "4. ERROR in test\\Test1.java (at line 13)\n" + + " void f4(A<@NonNull ? super @Nullable Integer> a) {\n" + + " ^^^^^^^^^\n" + + "This nullness annotation conflicts with a \'@NonNull\' annotation which is effective on the same type parameter \n" + + "----------\n" + ); +} +public void testBug485988bound() { + runConformTestWithLibs( + new String[] { + "C.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "interface I { }\n" + + "\n" + + "public class C {\n" + + " I<@NonNull ?> m1(I i) {\n" + + " return i;\n" + + " }\n" + + " I m2(I<@NonNull ? extends C> i) {\n" + + " return i;\n" + + " }\n" + + " \n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug466585_comment_0() { + runConformTestWithLibs( + new String[] { + "C3.java", + "import org.eclipse.jdt.annotation.*;\n" + + "class C3 {\n" + + " C3 x; // Null constraint mismatch: The type '?' is not a valid substitute for the type parameter 'T extends @NonNull Number'\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug466585_comment_4() { + runNegativeTestWithLibs( + new String[] { + "C3.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "class C4 {\n" + + " C4<@Nullable ?> err1;\n" + + " C4<@Nullable ? extends Integer> err2;\n" + + " C4 err3;\n" + + " C4<@Nullable ? super Integer> err4;\n" + + " C4<@NonNull ? super Integer> ok1;\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in C3.java (at line 4)\n" + + " C4<@Nullable ?> err1;\n" + + " ^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable ?\' is not a valid substitute for the type parameter \'T extends @NonNull Number\'\n" + + "----------\n" + + "2. ERROR in C3.java (at line 5)\n" + + " C4<@Nullable ? extends Integer> err2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable ? extends Integer\' is not a valid substitute for the type parameter \'T extends @NonNull Number\'\n" + + "----------\n" + + "3. ERROR in C3.java (at line 6)\n" + + " C4 err3;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'? super @Nullable Integer\' is not a valid substitute for the type parameter \'T extends @NonNull Number\'\n" + + "----------\n" + + "4. ERROR in C3.java (at line 7)\n" + + " C4<@Nullable ? super Integer> err4;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'@Nullable ? super Integer\' is not a valid substitute for the type parameter \'T extends @NonNull Number\'\n" + + "----------\n"); +} +public void testBug489978() { + runConformTestWithLibs( + new String[] { + "test/BinaryClass.java", + "package test;\n" + + "\n" + + "import java.util.ArrayList;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class BinaryClass {\n" + + " public ArrayList list;\n" + + "\n" + + " public BinaryClass(ArrayList list) {\n" + + " this.list = list;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test/Usage.java", + "package test;\n" + + "\n" + + "import java.util.ArrayList;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Usage {\n" + + " ArrayList f(BinaryClass b) {\n" + + " return b.list;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug489245() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_PessimisticNullAnalysisForFreeTypeVariables, JavaCore.INFO); + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "test/TestBogusProblemReportOnlyAsInfo.java", + "package test;\n" + + "\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class TestBogusProblemReportOnlyAsInfo {\n" + + " static void get(Supplier supplier, @NonNull U defaultValue) {\n" + + " }\n" + + "\n" + + " static void f() {\n" + + " get(() -> {\n" + + " return null; // bogus problem report only as info\n" + + " }, \"\");\n" + + " }\n" + + "\n" + + " static void h(@NonNull T t) {\n" + + " get(() -> {\n" + + " return null; // correctly reported (but twice with the bug)\n" + + " }, t);\n" + + " }\n" + + "}\n" + + "", + }, + compilerOptions, + "----------\n" + + "1. INFO in test\\TestBogusProblemReportOnlyAsInfo.java (at line 21)\n" + + " return null; // correctly reported (but twice with the bug)\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): \'null\' is not compatible to the free type variable \'T\'\n" + + "----------\n" + ); +} +public void testBug489674() { + Map options = new HashMap<>(getCompilerOptions()); + options.put(JavaCore.COMPILER_NONNULL_ANNOTATION_SECONDARY_NAMES, "org.foo.NonNull"); + options.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_SECONDARY_NAMES, "org.foo.Nullable"); + runConformTest( + new String[] { + "org/foo/Nullable.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ FIELD, METHOD, PARAMETER, LOCAL_VARIABLE })\n" + + "public @interface Nullable {}\n", + "org/foo/NonNull.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@Target({ FIELD, METHOD, PARAMETER, LOCAL_VARIABLE })\n" + + "public @interface NonNull {}\n", + }, + options); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "with_other_nullable/P1.java", + "package with_other_nullable;\n" + + "\n" + + "import org.foo.Nullable;\n" + + "\n" + + "public class P1 {\n" + + " public static @Nullable String f0() {\n" + + " return null;\n" + + " }\n" + + "\n" + + " public static T check(T t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + + "", + "with_other_nullable/P2.java", + "package with_other_nullable;\n" + + "\n" + + "import org.foo.NonNull;\n" + + "\n" + + "public class P2 {\n" + + " public static void f(@NonNull String s) {\n" + + " }\n" + + "\n" + + " public static T check(T t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + + "", + }, + options, + "" + ); + runNegativeTestWithLibs( + false /* don't flush */, + new String[] { + "test/Test4.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "import with_other_nullable.P1;\n" + + "import with_other_nullable.P2;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test4 {\n" + + " void m1(String s) {\n" + + " P1.f0().hashCode();\n" + + " s = P1.check(s);\n" + + " }\n" + + " void m2(String s) {\n" + + " P2.f(null);\n" + + " s = P2.check(s);\n" + + " }\n" + + "}\n" + + "", + }, + options, + "----------\n" + + "1. ERROR in test\\Test4.java (at line 11)\n" + + " P1.f0().hashCode();\n" + + " ^^^^^^^\n" + + "Potential null pointer access: The method f0() may return null\n" + + "----------\n" + + "2. ERROR in test\\Test4.java (at line 15)\n" + + " P2.f(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n", + false + ); +} +public void testBug492327() { + runConformTestWithLibs( + new String[] { + "WatchEvent.java", + "public interface WatchEvent {\n" + + " public static interface Modifier {\n" + + " }\n" + + "}\n", + "Watchable.java", + "public interface Watchable {\n" + + " void register(WatchEvent.Modifier[] modifiers);\n" + + "}\n", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "Path.java", + "public interface Path extends Watchable {\n" + + " @Override\n" + + " void register(WatchEvent.Modifier[] modifiers);\n" + + "}\n", + }, + getCompilerOptions(), + "" + ); +} +public void testBug488495collector() { + runConformTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "interface Collector {\n" + + "}\n" + + "\n" + + "interface Stream {\n" + + " R1 collect(Collector collector);\n" + + "}\n" + + "\n" + + "interface List {\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + " public static Collector> toList() {\n" + + " return new Collector>(){};\n" + + " }\n" + + "\n" + + " public static List myMethod(Stream stream) {\n" + + " List list = stream.collect(toList());\n" + + " return list;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} + +public void testBug496591() { + runConformTestWithLibs( + new String[] { + "test2/Descriptors.java", + "package test2;\n" + + "\n" + + "public final class Descriptors {\n" + + " public static final class FieldDescriptor implements FieldSet.FieldDescriptorLite { }\n" + + "}\n" + + "", + "test2/FieldSet.java", + "package test2;\n" + + "\n" + + "public final class FieldSet> {\n" + + " public interface FieldDescriptorLite> { }\n" + + "\n" + + " void f(final Map.Entry entry) { }\n" + + "}\n" + + "", + "test2/Map.java", + "package test2;\n" + + "\n" + + "public class Map {\n" + + " interface Entry { }\n" + + "}\n" + + "", + "test2/MessageOrBuilder.java", + "package test2;\n" + + "\n" + + "public interface MessageOrBuilder {\n" + + " Map getAllFields();\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test1/GeneratedMessage.java", + "package test1;\n" + + "\n" + + "import test2.Descriptors.FieldDescriptor;\n" + + "import test2.Map;\n" + + "import test2.MessageOrBuilder;\n" + + "\n" + + "public abstract class GeneratedMessage implements MessageOrBuilder {\n" + + " @Override\n" + + " public abstract Map getAllFields();\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug497698() { + runNegativeTest( + new String[] { + "test/And.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class And {\n" + + " public static void createAnd() {\n" + + " Or.create();\n" + + " }\n" + + "}\n" + + "", + "test/Or.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Or {\n" + + " public static Or create() {\n" + + " return new Or();\n" + + " }\n" + + "}\n" + + "", + }, + "----------\n" + + "1. ERROR in test\\Or.java (at line 7)\n" + + " public static Or create() {\n" + + " ^^\n" + + "Incorrect number of arguments for type Or; it cannot be parameterized with arguments \n" + + "----------\n", + this.LIBS, + true/*flush*/ + ); +} +public void testBug497698raw() { + runNegativeTest( + new String[] { + "test/And.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class And {\n" + + " public static void createAnd() {\n" + + " new Or().create();\n" + + " }\n" + + "}\n" + + "", + "test/Or.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Or {\n" + + " public Or create() {\n" + + " return new Or();\n" + + " }\n" + + "}\n" + + "", + }, + "----------\n" + + "1. WARNING in test\\And.java (at line 8)\n" + + " new Or().create();\n" + + " ^^\n" + + "Or is a raw type. References to generic type Or should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. ERROR in test\\Or.java (at line 7)\n" + + " public Or create() {\n" + + " ^^\n" + + "Incorrect number of arguments for type Or; it cannot be parameterized with arguments \n" + + "----------\n", + this.LIBS, + false/*shouldFlush*/ + ); +} +public void testBug497698nestedinraw() { + runNegativeTest( + new String[] { + "test/And.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class And {\n" + + " public static void createAnd(X.Or x) {\n" + + " x.create();\n" + + " }\n" + + "}\n" + + "", + "test/X.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " public class Or {\n" + + " public Or create() {\n" + + " return new Or();\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + "----------\n" + + "1. WARNING in test\\And.java (at line 7)\n" + + " public static void createAnd(X.Or x) {\n" + + " ^^^^\n" + + "X.Or is a raw type. References to generic type X.Or should be parameterized\n" + + "----------\n" + + "----------\n" + + "1. ERROR in test\\X.java (at line 8)\n" + + " public Or create() {\n" + + " ^^\n" + + "Incorrect number of arguments for type X.Or; it cannot be parameterized with arguments \n" + + "----------\n", + this.LIBS, + true/*flush*/ + ); +} +public void testBug492322() { + runConformTestWithLibs( + new String[] { + "test1/Base.java", + "package test1;\n" + + "\n" + + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public abstract class Base {\n" + + " public class GenericInner {\n" + + " }\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " public Object method(@Nullable GenericInner nullable) {\n" + + " return new Object();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test2/Derived.java", + "package test2;\n" + + "\n" + + "import test1.Base;\n" + + "\n" + + "class Derived extends Base {\n" + + " void test() {\n" + + " method(null);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug492322field() { + runConformTestWithLibs( + new String[] { + "test1/Base.java", + "package test1;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault\n" + + "public abstract class Base {\n" + + " public class GenericInner {\n" + + " }\n" + + "\n" + + " protected @Nullable GenericInner field;\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test2/Derived.java", + "package test2;\n" + + "\n" + + "import test1.Base;\n" + + "\n" + + "class Derived extends Base {\n" + + " void test() {\n" + + " field = null;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug492322deep() { + runConformTestWithLibs( + new String[] { + "test1/Base.java", + "package test1;\n" + + "\n" + + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public abstract class Base {\n" + + " public static class Static {\n" + + " public class Middle1 {\n" + + " public class Middle2 {\n" + + " public class Middle3 {\n" + + " public class GenericInner {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " public Object method( Static.Middle1.Middle2.Middle3.@Nullable GenericInner nullable) {\n" + + " return new Object();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test2/Derived.java", + "package test2;\n" + + "\n" + + "import test1.Base;\n" + + "\n" + + "class Derived extends Base {\n" + + " void test() {\n" + + " method(null);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug492322withGenericBase() { + runConformTestWithLibs( + new String[] { + "test1/Base.java", + "package test1;\n" + + "\n" + + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public abstract class Base {\n" + + " static public class Static {\n" + + " public class Middle1 {\n" + + " public class Middle2 {\n" + + " public class Middle3 {\n" + + " public class GenericInner {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.PARAMETER)\n" + + " public Object method( Static.Middle1.Middle2.Middle3.@Nullable GenericInner nullable) {\n" + + " return new Object();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test2/Derived.java", + "package test2;\n" + + "\n" + + "import test1.Base;\n" + + "\n" + + "class Derived extends Base {\n" + + " void test() {\n" + + " method(null);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug499862a() { + runConformTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class Test {\n" + + " static void printChecked(Collection collection) {\n" + + " for(String s : collection)\n" + + " if (s != null)\n" + + " System.out.println(s.toString());\n" + + " else\n" + + " System.out.println(\"NULL\");\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug499862b() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.*;\n" + + "public class Test {\n" + + " static void printChecked(Collection collection) {\n" + + " for(String s : collection)\n" + + " System.out.println(s.toString());\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Test.java (at line 6)\n" + + " System.out.println(s.toString());\n" + + " ^\n" + + "Potential null pointer access: The variable s may be null at this location\n" + + "----------\n"); +} +public void testBug499862c() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import java.util.*;\n" + + "public class Test {\n" + + " static void printUnchecked(Collection collection) {\n" + + " for(T t : collection)\n" + + " System.out.println(t.toString());\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Test.java (at line 5)\n" + + " System.out.println(t.toString());\n" + + " ^\n" + + "Potential null pointer access: this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n"); +} +public void testBug499597simplified() { + runConformTestWithLibs( + new String[] { + "Foo2.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "class Foo2 {\n" + + " static T of(T t) {\n" + + " return t;\n" + + " }\n" + + "\n" + + " static String foo() {\n" + + " return Foo2.of(\"\"); // <-- warning here\n" + + " }\n" + + "\n" + + " static String bar() {\n" + + " return Foo2.<@NonNull String>of(\"\"); // <-- no warning\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug499597original() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "Foo.java", + "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "import java.util.Collection;\n" + + "import java.util.Collections;\n" + + "\n" + + "class Foo {\n" + + " static @NonNull String @NonNull [] X = { \"A\" };\n" + + "\n" + + " @NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS })\n" + + " @SafeVarargs\n" + + " static Collection of(@NonNull T @NonNull... elements) {\n" + + " return Collections.singleton(elements[0]);\n" + + " }\n" + + "\n" + + " @NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS })\n" + + " static Collection foo() {\n" + + " return Foo.of(X); // <-- warning here\n" + + " }\n" + + "\n" + + " @NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS })\n" + + " static Collection bar() {\n" + + " return Foo.of(X); // <-- no warning\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Foo.java (at line 12)\n" + + " static Collection of(@NonNull T @NonNull... elements) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The nullness annotation is redundant with a default that applies to this location\n" + + "----------\n" + + "2. WARNING in Foo.java (at line 13)\n" + + " return Collections.singleton(elements[0]);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'Set<@NonNull T>\' needs unchecked conversion to conform to \'@NonNull Collection<@NonNull T>\', corresponding supertype is \'Collection<@NonNull T>\'\n" + + "----------\n" + ); +} +public void testBug501031() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault(DefaultLocation.TYPE_PARAMETER)\n" + + "class X {\n" + + " @NonNull Object identity(T t) {\n" + + " return t;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} + +public void testBug501031return() { + runNegativeTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault(DefaultLocation.TYPE_PARAMETER)\n" + + "class X {\n" + + " T identity() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull T\' but the provided value is null\n" + + "----------\n" + ); +} +public void testBug501031btb() { + // this already worked without the patch for bug 501031. + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault(DefaultLocation.TYPE_PARAMETER)\n" + + "class X {\n" + + " void identity(T t) {\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runNegativeTestWithLibs( + new String[] { + "Y.java", + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault\n" + + "class Y {\n" + + " void test(X x, @Nullable String string) {\n" + + " x.identity(string);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Y.java (at line 7)\n" + + " x.identity(string);\n" + + " ^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n" + ); +} +public void testBug501449() { + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class Test {\n" + + " void f(T[] objects, @Nullable T nullableValue, T value, S subclassValue) {\n" + + " objects[0] = null;\n" + + " objects[1] = nullableValue;\n" + + " objects[2] = value;\n" + + " objects[3] = subclassValue;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Test.java (at line 5)\n" + + " objects[0] = null;\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): \'null\' is not compatible to the free type variable \'T\'\n" + + "----------\n" + + "2. ERROR in Test.java (at line 6)\n" + + " objects[1] = nullableValue;\n" + + " ^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'T\' but this expression has type \'@Nullable T\', where \'T\' is a free type variable\n" + + "----------\n" + ); +} +public void testBug502112() { + runConformTest( + new String[] { + "org/foo/Nullable.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "public @interface Nullable {}\n", + }, + getCompilerOptions()); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "util/Optional.java", + "package util;\n" + + "\n" + + "import org.foo.Nullable;\n" + + "\n" + + "public class Optional {\n" + + " public static T fromNullable(@Nullable T nullableReference, @Nullable T nullableReference2) {\n" + + " return nullableReference;\n" + + " }\n" + + " @Nullable\n" + + " public static T returnNull(T nullableReference) {\n" + + " return nullableReference;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + Map options = new HashMap<>(getCompilerOptions()); + options.put(JavaCore.COMPILER_NONNULL_ANNOTATION_SECONDARY_NAMES, "org.foo.NonNull"); + options.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_SECONDARY_NAMES, "org.foo.Nullable"); + runNegativeTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "import util.Optional;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + " void f(@Nullable String s) {\n" + + " Optional.fromNullable(s, null);\n" + + " }\n" + + " String g(@Nullable String s) {\n" + + " return Optional.returnNull(s);\n" + + " }\n" + + "}\n" + + "", + }, + options, + "----------\n" + + "1. ERROR in test\\Test.java (at line 14)\n" + + " return Optional.returnNull(s);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n" + + "2. ERROR in test\\Test.java (at line 14)\n" + + " return Optional.returnNull(s);\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n" +); +} +public void testBug502112b() { + runConformTest( + new String[] { + "org/foo/NonNull.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "public @interface NonNull {}\n", + "org/foo/Nullable.java", + "package org.foo;\n" + + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "public @interface Nullable {}\n", + }, + getCompilerOptions()); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "util/X.java", + "package util;\n" + + "\n" + + "import org.foo.NonNull;\n" + + "import org.foo.Nullable;\n" + + "\n" + + "public class X {\n" + + " @NonNull\n" + + " public T nonNull(@Nullable T t, @Nullable T t2) {\n" + + " return java.util.Objects.requireNonNull(t);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + Map options = new HashMap<>(getCompilerOptions()); + options.put(JavaCore.COMPILER_NONNULL_ANNOTATION_SECONDARY_NAMES, "org.foo.NonNull"); + options.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_SECONDARY_NAMES, "org.foo.Nullable"); + runNegativeTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "import util.X;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test extends X{\n" + + " @Override\n" + + " public @Nullable T nonNull(@NonNull T t, T t2) {\n" + + " return t;\n" + + " }\n" + + "}\n" + + "", + }, + options, + "----------\n" + + "1. ERROR in test\\Test.java (at line 12)\n" + + " public @Nullable T nonNull(@NonNull T t, T t2) {\n" + + " ^^^^^^^^^^^\n" + + "The return type is incompatible with \'@NonNull T extends Object\' returned from X.nonNull(T, T) (mismatching null constraints)\n" + + "----------\n" + + "2. ERROR in test\\Test.java (at line 12)\n" + + " public @Nullable T nonNull(@NonNull T t, T t2) {\n" + + " ^^^^^^^^^^\n" + + "Illegal redefinition of parameter t, inherited method from X declares this parameter as @Nullable\n" + + "----------\n" + + "3. ERROR in test\\Test.java (at line 12)\n" + + " public @Nullable T nonNull(@NonNull T t, T t2) {\n" + + " ^\n" + + "Missing nullable annotation: inherited method from X specifies this parameter as @Nullable\n" + + "----------\n" + ); +} +public void testBug484926locals() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "test/NNBDOnLocalOrField.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "class AtomicReference {\n" + + "\n" + + " public void set(T object) {\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class NNBDOnLocalOrField {\n" + + " void someMethod() {\n" + + " AtomicReference x1 = new AtomicReference<>();\n" + + " AtomicReference x2 = new AtomicReference<@NonNull String>(), x3=new AtomicReference<@Nullable String>();\n" + + " @NonNullByDefault({})\n" + + " AtomicReference y1 = new AtomicReference<>();\n" + + " @NonNullByDefault({})\n" + + " AtomicReference y2 = new AtomicReference<@NonNull String>(), y3=new AtomicReference<@Nullable String>();\n" + + " x1.set(null);\n" + + " x2.set(null);\n" + + " x3.set(null);\n" + + " y1.set(null);\n" + + " y2.set(null);\n" + + " y3.set(null);\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in test\\NNBDOnLocalOrField.java (at line 16)\n" + + " AtomicReference x2 = new AtomicReference<@NonNull String>(), x3=new AtomicReference<@Nullable String>();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'AtomicReference<@NonNull String>\' but this expression has type \'@NonNull AtomicReference<@Nullable String>\'\n" + + "----------\n" + + "2. ERROR in test\\NNBDOnLocalOrField.java (at line 21)\n" + + " x1.set(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in test\\NNBDOnLocalOrField.java (at line 22)\n" + + " x2.set(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "4. ERROR in test\\NNBDOnLocalOrField.java (at line 23)\n" + + " x3.set(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + ); +} +public void testBug484926fields() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.IGNORE); + runNegativeTestWithLibs( + new String[] { + "test/NNBDOnLocalOrField.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "class AtomicReference {\n" + + "\n" + + " public void set(T object) {\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class NNBDOnLocalOrField {\n" + + " AtomicReference x1 = new AtomicReference<>();\n" + + " AtomicReference x2 = new AtomicReference<@NonNull String>(), x3=new AtomicReference<@Nullable String>();\n" + + " @NonNullByDefault({})\n" + + " AtomicReference y1 = new AtomicReference<>();\n" + + " @NonNullByDefault({})\n" + + " AtomicReference y2 = new AtomicReference<@NonNull String>(), y3=new AtomicReference<@Nullable String>();\n" + + " void someMethod() {\n" + + " x1.set(null);\n" + + " x2.set(null);\n" + + " x3.set(null);\n" + + " y1.set(null);\n" + + " y2.set(null);\n" + + " y3.set(null);\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in test\\NNBDOnLocalOrField.java (at line 15)\n" + + " AtomicReference x2 = new AtomicReference<@NonNull String>(), x3=new AtomicReference<@Nullable String>();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull AtomicReference<@NonNull String>\' but this expression has type \'@NonNull AtomicReference<@Nullable String>\'\n" + + "----------\n" + + "2. ERROR in test\\NNBDOnLocalOrField.java (at line 21)\n" + + " x1.set(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in test\\NNBDOnLocalOrField.java (at line 22)\n" + + " x2.set(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "4. ERROR in test\\NNBDOnLocalOrField.java (at line 23)\n" + + " x3.set(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + ); +} +public void testBug484926() { + runConformTestWithLibs( + new String[] { + "test/NNBDOnLocalOrField.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "class AtomicReference {\n" + + "\n" + + " public void set(T object) {\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class NNBDOnLocalOrField {\n" + + " @NonNullByDefault({})\n" + + " AtomicReference f = new AtomicReference<>();\n" + + "\n" + + " {\n" + + " f.set(null);\n" + + " }\n" + + "\n" + + " @NonNullByDefault({})\n" + + " Runnable r = () -> {\n" + + " AtomicReference x1 = new AtomicReference<>();\n" + + " x1.set(null);\n" + + " };\n" + + "\n" + + " Object someMethod() {\n" + + " @NonNullByDefault({})\n" + + " AtomicReference x2 = new AtomicReference<>();\n" + + " x2.set(null);\n" + + "\n" + + " @NonNullByDefault({})\n" + + " Runnable r1 = () -> {\n" + + " AtomicReference x3 = new AtomicReference<>();\n" + + " x3.set(null);\n" + + " };\n" + + " \n" + + " return r1;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug484926nesting() { + runNegativeTestWithLibs( + new String[] { + "test/NNBDOnLocalOrField.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "class AtomicReference {\n" + + "\n" + + " public void set(T object) {\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "public class NNBDOnLocalOrField {\n" + + " @NonNullByDefault()\n" + + " Runnable r = () -> {\n" + + " @NonNullByDefault({})\n" + + " AtomicReference x1 = new AtomicReference<>();\n" + + " x1.set(null);\n" + + " };\n" + + " @NonNullByDefault\n" + + " Object someMethod() {\n" + + " @NonNullByDefault({})\n" + + " AtomicReference x2 = new AtomicReference<>();\n" + + " x2.set(null);\n" + + "\n" + + " @NonNullByDefault({})\n" + + " Runnable r1 = () -> {\n" + + " @NonNullByDefault\n" + + " AtomicReference x3 = new AtomicReference<>();\n" + + " x3.set(null);\n" + + " };\n" + + " \n" + + " return r1;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\NNBDOnLocalOrField.java (at line 29)\n" + + " x3.set(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + ); +} +public void testBug484926localDeclarationInForLoop() { + runConformTestWithLibs( + new String[] { + "test/NNBDOnLocalOrField.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "class AtomicReference {\n" + + "\n" + + " public void set(T object) {\n" + + " }\n" + + "\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "public class NNBDOnLocalOrField {\n" + + " void someMethod() {\n" + + " for(@NonNullByDefault({})\n" + + " Runnable r1 = () -> {\n" + + " AtomicReference x3 = new AtomicReference<>();\n" + + " x3.set(null);\n" + + " }, r2 = () -> {\n" + + " AtomicReference x4 = new AtomicReference<>();\n" + + " x4.set(null);\n" + + " };;) {\n" + + " r1.run();\n" + + " r2.run();\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug484926redundantNNBD() { + runNegativeTestWithLibs( + new String[] { + "testnnbd/NNBDRedundantOnLocalOrField.java", + "package testnnbd;\n" + + "\n" + + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault({})\n" + + "class AtomicReference {\n" + + " public void set(T object) {\n" + + " }\n" + + "}\n" + + "\n" + + "public class NNBDRedundantOnLocalOrField {\n" + + " @NonNullByDefault\n" + + " Runnable r1 = () -> {\n" + + " @NonNullByDefault\n" + + " AtomicReference x3 = new AtomicReference<>();\n" + + " x3.set(null);\n" + + " }, r2 = () -> {\n" + + " @NonNullByDefault({})\n" + + " AtomicReference x4 = new AtomicReference() {\n" + + " @NonNullByDefault({})\n" + + " public void set(String object) {\n" + + " }\n" + + " };\n" + + " x4.set(null);\n" + + " };\n" + + "\n" + + " @NonNullByDefault\n" + + " class X1 {\n" + + " @NonNullByDefault\n" + + " Runnable r = () -> {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " class Local extends AtomicReference {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " class X2 {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " String s;\n" + + " \n" + + " {\n" + + " set(null);\n" + + " }\n" + + " }\n" + + " {\n" + + " new X2().hashCode();\n" + + " }\n" + + " }\n" + + " Local x1 = new Local();\n" + + " x1.set(null);\n" + + " };\n" + + " }\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " Object someMethod() {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " AtomicReference x2 = new AtomicReference<>();\n" + + " x2.set(null);\n" + + "\n" + + " @NonNullByDefault({})\n" + + " Runnable r = () -> {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " AtomicReference x3 = new AtomicReference<>();\n" + + " x3.set(null);\n" + + " };\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " Runnable r2 = new Runnable() {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " @Override\n" + + " public void run() {\n" + + " }\n" + + " };\n" + + "\n" + + " r2.run();\n" + + " return r;\n" + + " }\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " void forLoopVariable() {\n" + + " {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " Runnable r = () -> {\n" + + " AtomicReference x3 = new AtomicReference<>();\n" + + " x3.set(null);\n" + + " }, r2 = () -> {\n" + + " AtomicReference x4 = new AtomicReference<>();\n" + + " x4.set(null);\n" + + " };\n" + + " r.run();\n" + + " r2.run();\n" + + " }\n" + + " for (@NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " Runnable r = () -> {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " AtomicReference x3 = new AtomicReference<>();\n" + + " x3.set(null);\n" + + " }, r2 = () -> {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " AtomicReference x4 = new AtomicReference<>();\n" + + " x4.set(null);\n" + + " };;) {\n" + + " r.run();\n" + + " r2.run();\n" + + " }\n" + + " }\n" + + "}\n" + + "", + "testnnbd/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "package testnnbd;\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 13)\n" + + " @NonNullByDefault\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing package testnnbd\n" + + "----------\n" + + "2. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 15)\n" + + " @NonNullByDefault\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the field r1\n" + + "----------\n" + + "3. ERROR in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 17)\n" + + " x3.set(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "4. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 21)\n" + + " @NonNullByDefault({})\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the variable x4\n" + + "----------\n" + + "5. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 22)\n" + + " public void set(String object) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The method set(String) of type new AtomicReference(){} should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "6. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 28)\n" + + " @NonNullByDefault\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing package testnnbd\n" + + "----------\n" + + "7. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 30)\n" + + " @NonNullByDefault\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type NNBDRedundantOnLocalOrField.X1\n" + + "----------\n" + + "8. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 34)\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type Local\n" + + "----------\n" + + "9. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 36)\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type Local.X2\n" + + "----------\n" + + "10. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 37)\n" + + " String s;\n" + + " ^\n" + + "The value of the field Local.X2.s is not used\n" + + "----------\n" + + "11. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 54)\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing method someMethod()\n" + + "----------\n" + + "12. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 65)\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing method someMethod()\n" + + "----------\n" + + "13. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 66)\n" + + " Runnable r2 = new Runnable() {\n" + + " ^^\n" + + "The local variable r2 is hiding a field from type NNBDRedundantOnLocalOrField\n" + + "----------\n" + + "14. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 67)\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the variable r2\n" + + "----------\n" + + "15. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 80)\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing method forLoopVariable()\n" + + "----------\n" + + "16. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 84)\n" + + " }, r2 = () -> {\n" + + " ^^\n" + + "The local variable r2 is hiding a field from type NNBDRedundantOnLocalOrField\n" + + "----------\n" + + "17. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 91)\n" + + " for (@NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing method forLoopVariable()\n" + + "----------\n" + + "18. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 91)\n" + + " for (@NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing method forLoopVariable()\n" + + "----------\n" + + "19. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 93)\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the variable r\n" + + "----------\n" + + "20. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 96)\n" + + " }, r2 = () -> {\n" + + " ^^\n" + + "The local variable r2 is hiding a field from type NNBDRedundantOnLocalOrField\n" + + "----------\n" + + "21. WARNING in testnnbd\\NNBDRedundantOnLocalOrField.java (at line 97)\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE)\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the variable r2\n" + + "----------\n" + ); +} +public void testBug484926BTB() { + runConformTestWithLibs( + new String[] { + "test/ClassWithNNBDOnField.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "class AtomicReference {\n" + + " public void set(T object) {\n" + + " }\n" + + "}\n" + + "\n" + + "@NonNullByDefault()\n" + + "public class ClassWithNNBDOnField {\n" + + " @NonNullByDefault({})\n" + + " AtomicReference f = new AtomicReference<>();\n" + + " {\n" + + " f.set(null);\n" + + " }\n" + + "\n" + + " public static class X {\n" + + " @NonNullByDefault({})\n" + + " AtomicReference nested = new AtomicReference<>();\n" + + " {\n" + + " nested.set(null);\n" + + " }\n" + + " }\n" + + "\n" + + " public X x = new X();\n" + + " \n" + + " void test() {\n" + + " new ClassWithNNBDOnField().f.set(null);\n" + + " new ClassWithNNBDOnField().f = null;\n" + + " new ClassWithNNBDOnField().x.nested.set(null);\n" + + " new ClassWithNNBDOnField().x.nested = null;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "public class Test {\n" + + " void test() {\n" + + " new ClassWithNNBDOnField().f.set(null);\n" + + " new ClassWithNNBDOnField().f = null;\n" + + " new ClassWithNNBDOnField().x.nested.set(null);\n" + + " new ClassWithNNBDOnField().x.nested = null;\n" + + " }\n" + + "\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug500885() { + runConformTest( + new String[] { + "annot/NonNull.java", + "package annot;\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" + + "public @interface NonNull {}\n", + "annot/NonNullByDefault.java", + "package annot;\n" + + "@annot.NonNull\n" + + "@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)\n" + + "public @interface NonNullByDefault {}\n", + "annot/package-info.java", + "@annot.NonNullByDefault package annot;\n", + "test/package-info.java", + "@annot.NonNullByDefault package test;\n", + "test/X.java", + "package test;\n" + + "public interface X {\n" + + " public String get();\n" + + "}\n" + }, + getCompilerOptions(), + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES, "annot.NonNullByDefault"); + options.put(JavaCore.COMPILER_NONNULL_ANNOTATION_SECONDARY_NAMES, "annot.NonNull"); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test2/package-info.java", + "@org.eclipse.jdt.annotation.NonNullByDefault package test2;\n", + "test2/Y.java", + "package test2;\n" + + "import test.X;\n" + + "public class Y implements X {\n" + + " public String get() {\n" + + " return \"\";\n" + + " }\n" + + "}\n" + }, + options, + ""); +} +public void testBug505671() { + runConformTestWithLibs( + new String[] { + "snippet/Pair.java", + "package snippet;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Pair {\n" + + " public static S make(S left, T right, Object x) {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runNegativeTestWithLibs( + new String[] { + "snippet/Snippet.java", + "package snippet;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class Snippet {\n" + + " public static final @NonNull Object FALSE = new Object();\n" + + "\n" + + " public static @NonNull Object abbreviateExplained0() {\n" + + " return Pair.make(null, FALSE, null);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in snippet\\Snippet.java (at line 9)\n" + + " return Pair.make(null, FALSE, null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n" + + "2. ERROR in snippet\\Snippet.java (at line 9)\n" + + " return Pair.make(null, FALSE, null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + ); +} +public void testBug501564() { + runNegativeTestWithLibs( + new String[] { + "xxx/Foo.java", + "package xxx;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "\n" + + "class Generic> { \n" + + "}\n" + + "class Foo { \n" + + " static > Bar foo() {\n" + + " return new Bar<>();\n" + + " }\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.TYPE_PARAMETER)\n" + + " static class Bar> { }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in xxx\\Foo.java (at line 8)\n" + + " static > Bar foo() {\n" + + " ^^\n" + + "Null constraint mismatch: The type \'E2 extends Generic\' is not a valid substitute for the type parameter \'@NonNull E3 extends Generic>\'\n" + + "----------\n" + ); +} +public void testBug501564interface() { + runNegativeTestWithLibs( + new String[] { + "xxx/Foo.java", + "package xxx;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "\n" + + "interface Generic> { \n" + + "}\n" + + "class Foo { \n" + + " static > Bar foo() {\n" + + " return new Bar<>();\n" + + " }\n" + + "\n" + + " @NonNullByDefault(DefaultLocation.TYPE_PARAMETER)\n" + + " static class Bar> { }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in xxx\\Foo.java (at line 8)\n" + + " static > Bar foo() {\n" + + " ^^\n" + + "Null constraint mismatch: The type \'E2 extends Generic\' is not a valid substitute for the type parameter \'@NonNull E3 extends Generic>\'\n" + + "----------\n" + ); +} +public void testBug501464() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "Foo.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface MyList { @NonNull T getAny(); }\n" + + "\n" + + "@NonNullByDefault({})\n" + + "class Foo {\n" + + " @Nullable Object b;\n" + + " \n" + + " void foo() {\n" + + " @Nullable Object f = b;\n" + + " ((@NonNull Object)f).hashCode(); // Error (unexpected): Potential null pointer access: this expression has a '@Nullable' type\n" + + " }\n" + + " \n" + + " void workaround() {\n" + + " @Nullable Object f = b;\n" + + " @NonNull Object g = (@NonNull Object)f; // Warning (expected): Null type safety: Unchecked cast from @Nullable Object to @NonNull Object\n" + + " g.hashCode();\n" + + " }\n" + + " String three(@NonNull MyList<@Nullable String> list) {\n" + + " return ((@NonNull MyList<@NonNull String>) list).getAny().toUpperCase();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Foo.java (at line 11)\n" + + " ((@NonNull Object)f).hashCode(); // Error (unexpected): Potential null pointer access: this expression has a \'@Nullable\' type\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety: Unchecked cast from @Nullable Object to @NonNull Object\n" + + "----------\n" + + "2. WARNING in Foo.java (at line 16)\n" + + " @NonNull Object g = (@NonNull Object)f; // Warning (expected): Null type safety: Unchecked cast from @Nullable Object to @NonNull Object\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Null type safety: Unchecked cast from @Nullable Object to @NonNull Object\n" + + "----------\n" + + "3. WARNING in Foo.java (at line 20)\n" + + " return ((@NonNull MyList<@NonNull String>) list).getAny().toUpperCase();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety: Unchecked cast from @NonNull MyList<@Nullable String> to @NonNull MyList<@NonNull String>\n" + + "----------\n" + ); +} +public void testBug507840() { + runConformTestWithLibs( + new String[] { + "nnbd_on_typevar/AtomicReference.java", + "package nnbd_on_typevar;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "class AtomicReference {\n" + + " public void set(T t) {\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "nnbd_on_typevar/Usage.java", + "package nnbd_on_typevar;\n" + + "\n" + + "public class Usage {\n" + + " void m(AtomicReference ref) {\n" + + " ref.set(null);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug508497() { + runConformTestWithLibs( + new String[] { + "Reference.java", + "interface Fluent> {\n" + + " SELF self();\n" + + "}\n" + + "abstract class Reference {\n" + + " abstract T get();\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "B2.java", + "class B2 {\n" + + " void b1(Fluent f) {\n" + + " f.self();\n" + + " }\n" + + "\n" + + " void b2(Reference<@org.eclipse.jdt.annotation.NonNull Fluent> ref) {\n" + + " ref.get().self();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in B2.java (at line 2)\n" + + " void b1(Fluent f) {\n" + + " ^^^^^^\n" + + "Fluent is a raw type. References to generic type Fluent should be parameterized\n" + + "----------\n" + + "2. WARNING in B2.java (at line 6)\n" + + " void b2(Reference<@org.eclipse.jdt.annotation.NonNull Fluent> ref) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Fluent is a raw type. References to generic type Fluent should be parameterized\n" + + "----------\n" + + "3. INFO in B2.java (at line 7)\n" + + " ref.get().self();\n" + + " ^^^^^^^^^\n" + + "Unsafe interpretation of method return type as \'@NonNull\' based on the receiver type \'Reference<@NonNull Fluent>\'. Type \'Reference\' doesn\'t seem to be designed with null type annotations in mind\n" + + "----------\n" + ); +} +public void testBug509025() { + runConformTestWithLibs( + new String[] { + "MyAnno.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@NonNullByDefault\n" + + "public @interface MyAnno {\n" + + " @NonNull String[] items();\n" + + "\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "AnnoLoop.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class AnnoLoop {\n" + + " @NonNull\n" + + " String[] test(MyAnno anno) {\n" + + " return anno.items();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug501598() { + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "Foo.java", + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "class Foo {\n" + + " static @NonNull List f() {\n" + + " throw new Error();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in Foo.java (at line 8)\n" + + " static @NonNull List f() {\n" + + " ^^^^^^^^^^^^^\n" + + "The nullness annotation is redundant with a default that applies to this location\n" + + "----------\n" + ); +} +public void testBug509328() { + runConformTestWithLibs( + new String[] { + "test/Feature.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Feature {\n" + + " public Feature(String name) {\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runNegativeTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + " public static void f() {\n" + + " new Feature(null) {\n" + + " // anonymous subclass\n" + + " };\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\Test.java (at line 8)\n" + + " new Feature(null) {\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + ); +} +public void testBug510799() { + runConformTestWithLibs( + new String[] { + "test/TestNNBDBreaksDimensionAnnotation.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@NonNullByDefault\n" + + "class TestNNBDBreaksDimensionAnnotation {\n" + + " Object f(String[] @NonNull [] a) {\n" + + " return a[0];\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug490403() { + runConformTestWithLibs( + new String[] { + "test/TestNullInt.java", + "package test;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class TestNullInt {\n" + + "\n" + + " public void test() {\n" + + " @NonNull Integer[] keys = new @NonNull Integer[12];\n" + + " @NonNull Integer index = 0;\n" + + " for (int i = 0; i < 10; i++) {\n" + + " keys[index] = index;\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug490403while() { + runConformTestWithLibs( + new String[] { + "test/TestNullInt.java", + "package test;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public abstract class TestNullInt {\n" + + " public abstract boolean b();\n" + + "\n" + + " public void test(@NonNull Object[] keys, @NonNull String o) {\n" + + " while (b()) {\n" + + " keys[0] = o;\n" + + " keys[1] = b() ? o : o;\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} + +public void testBug490403negative() { + runNegativeTestWithLibs( + new String[] { + "test/TestNullInt.java", + "package test;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public abstract class TestNullInt {\n" + + " public abstract boolean b();\n" + + "\n" + + " public void warning(@NonNull Object[] keys, String o) {\n" + + " while (b()) {\n" + + " keys[0] = o;\n" + + " keys[1] = b() ? o : \"\";\n" + + " }\n" + + " }\n" + + " public void error(@NonNull Object[] keys, @Nullable String o) {\n" + + " while (b()) {\n" + + " keys[0] = o;\n" + + " keys[1] = b() ? \"\" : o;\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. WARNING in test\\TestNullInt.java (at line 9)\n" + + " keys[0] = o;\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n" + + "2. WARNING in test\\TestNullInt.java (at line 10)\n" + + " keys[1] = b() ? o : \"\";\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull Object\'\n" + + "----------\n" + + "3. ERROR in test\\TestNullInt.java (at line 15)\n" + + " keys[0] = o;\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable String\'\n" + + "----------\n" + + "4. ERROR in test\\TestNullInt.java (at line 16)\n" + + " keys[1] = b() ? \"\" : o;\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull Object\' but this expression has type \'@Nullable String\'\n" + + "----------\n" + ); +} +public void testBug490403typeArgAnnotationMismatch() { + runNegativeTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "class Ref {\n" + + "}\n" + + "\n" + + "public abstract class Test {\n" + + " abstract boolean b();\n" + + "\n" + + " public void testAnnotationMismatch(@NonNull Ref<@Nullable String> x, @NonNull Ref<@NonNull String>[] keys) {\n" + + " keys[0] = x;\n" + + " while (b()) {\n" + + " keys[0] = x;\n" + + " keys[1] = b() ? keys[0] : x;\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\Test.java (at line 13)\n" + + " keys[0] = x;\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref<@NonNull String>\' but this expression has type \'@NonNull Ref<@Nullable String>\'\n" + + "----------\n" + + "2. ERROR in test\\Test.java (at line 15)\n" + + " keys[0] = x;\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref<@NonNull String>\' but this expression has type \'@NonNull Ref<@Nullable String>\'\n" + + "----------\n" + + "3. ERROR in test\\Test.java (at line 16)\n" + + " keys[1] = b() ? keys[0] : x;\n" + + " ^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref<@NonNull String>\' but this expression has type \'@NonNull Ref<@Nullable String>\'\n" + + "----------\n" + ); +} +public void testBug499589() { + runConformTestWithLibs( + new String[] { + "test/BogusWarning.java", + "package test;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.ARRAY_CONTENTS;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault({ PARAMETER, ARRAY_CONTENTS })\n" + + "class BogusWarning {\n" + + " static void a(String[] array) {\n" + + " x(array[0]); // <----- bogus warning\n" + + " }\n" + + "\n" + + " static void x(String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + "\n" + + " static void b(String[][] array) {\n" + + " y(array[0]); // <----- bogus warning\n" + + " }\n" + + "\n" + + " static void y(String[] s) {\n" + + " System.out.println(s[0]);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug499589multidim() { + runNegativeTestWithLibs( + new String[] { + "test/BogusWarning.java", + "package test;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.ARRAY_CONTENTS;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault({ PARAMETER, ARRAY_CONTENTS })\n" + + "class BogusWarning {\n" + + " static void foo(String[] @Nullable [] array) {\n" + + " x(array[0]);\n" + + " }\n" + + " static void x(String[] s) {\n" + + " System.out.println(s[0]);\n" + + " }\n" + + "\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\BogusWarning.java (at line 11)\n" + + " x(array[0]);\n" + + " ^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[]\' but this expression has type \'@NonNull String @Nullable[]\'\n" + + "----------\n" + ); +} + +public void testBug499589leafTypeNullable() { + runNegativeTestWithLibs( + new String[] { + "test/BogusWarning.java", + "package test;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.ARRAY_CONTENTS;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault({ PARAMETER, ARRAY_CONTENTS })\n" + + "class BogusWarning {\n" + + " static void foo(@Nullable String[] array) {\n" + + " x(array[0]);\n" + + " }\n" + + "\n" + + " static void x(String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\BogusWarning.java (at line 11)\n" + + " x(array[0]);\n" + + " ^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n" + ); +} + +public void testBug499589qualified() { + runConformTestWithLibs( + new String[] { + "test/BogusWarning.java", + "package test;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.ARRAY_CONTENTS;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault({ PARAMETER, ARRAY_CONTENTS })\n" + + "class BogusWarning {\n" + + " static void foo(java.lang.String[] array) {\n" + + " x(array[0]);\n" + + " }\n" + + "\n" + + " static void x(String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} + +public void testBug499589qualified_leafTypeNullable() { + runNegativeTestWithLibs( + new String[] { + "test/BogusWarning.java", + "package test;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.ARRAY_CONTENTS;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault({ PARAMETER, ARRAY_CONTENTS })\n" + + "class BogusWarning {\n" + + " static void foo(java.lang.@Nullable String[] array) {\n" + + " x(array[0]);\n" + + " }\n" + + "\n" + + " static void x(String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\BogusWarning.java (at line 11)\n" + + " x(array[0]);\n" + + " ^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String\' but this expression has type \'@Nullable String\'\n" + + "----------\n" + ); +} +public void testBug499589qualified_multidim() { + runNegativeTestWithLibs( + new String[] { + "test/BogusWarning.java", + "package test;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.ARRAY_CONTENTS;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "@NonNullByDefault({ PARAMETER, ARRAY_CONTENTS })\n" + + "class BogusWarning {\n" + + " static void foo(java.lang.String[] @Nullable [] array) {\n" + + " x(array[0]);\n" + + " }\n" + + " static void x(java.lang.String[] s) {\n" + + " System.out.println(s[0]);\n" + + " }\n" + + "\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\BogusWarning.java (at line 11)\n" + + " x(array[0]);\n" + + " ^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[]\' but this expression has type \'@NonNull String @Nullable[]\'\n" + + "----------\n" + ); +} +public void testBug499589STB() { + runNegativeTestWithLibs( + new String[] { + "test/Ref.java", + "package test;\n" + + "\n" + + "public class Ref {\n" + + " T get() {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}\n" + + "", + "test/X.java", + "package test;\n" + + "\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@SuppressWarnings({ \"unchecked\" })\n" + + "@NonNullByDefault({ FIELD, RETURN_TYPE, PARAMETER, ARRAY_CONTENTS, TYPE_ARGUMENT })\n" + + "public abstract class X {\n" + + " public final String[][] field = {};\n" + + " public final @Nullable String[][] fieldWithNullable1 = {};\n" + + " public final String[] @Nullable [] fieldWithNullable2 = {};\n" + + "\n" + + " public final Ref list = new Ref<>();\n" + + " public final Ref<@Nullable String[][]> listWithNullable1 = new Ref<>();\n" + + " public final Ref listWithNullable2 = new Ref<>();\n" + + "\n" + + " public abstract String[][] method();\n" + + " public abstract @Nullable String[][] methodWithNullable1();\n" + + " public abstract String[] @Nullable [] methodWithNullable2();\n" + + "\n" + + " public final Ref[][] genericField = new Ref[0][];\n" + + " public final @Nullable Ref<@Nullable String[][]>[][] genericFieldWithNullable1 = new Ref[0][];\n" + + " public final Ref[] @Nullable [] genericFieldWithNullable2 = new Ref[0][];\n" + + "}\n" + + "\n" + + "class SourceUsage {\n" + + " void check(@NonNull String @NonNull [] @NonNull [] s) {\n" + + " }\n" + + "\n" + + " void checkGeneric(@NonNull Ref<@NonNull String @NonNull [] @NonNull []> @NonNull [] @NonNull [] s) {\n" + + " }\n" + + "\n" + + " void f(X x) {\n" + + " check(x.field);\n" + + " check(x.fieldWithNullable1);\n" + + " check(x.fieldWithNullable2);\n" + + " check(x.list.get());\n" + + " check(x.listWithNullable1.get());\n" + + " check(x.listWithNullable2.get());\n" + + " check(x.method());\n" + + " check(x.methodWithNullable1());\n" + + " check(x.methodWithNullable2());\n" + + " checkGeneric(x.genericField);\n" + + " checkGeneric(x.genericFieldWithNullable1);\n" + + " checkGeneric(x.genericFieldWithNullable2);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\X.java (at line 36)\n" + + " check(x.fieldWithNullable1);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@Nullable String @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 37)\n" + + " check(x.fieldWithNullable2);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@NonNull String @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 39)\n" + + " check(x.listWithNullable1.get());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@Nullable String @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 40)\n" + + " check(x.listWithNullable2.get());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@NonNull String @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 42)\n" + + " check(x.methodWithNullable1());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@Nullable String @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 43)\n" + + " check(x.methodWithNullable2());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@NonNull String @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 45)\n" + + " checkGeneric(x.genericFieldWithNullable1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref<@NonNull String @NonNull[] @NonNull[]> @NonNull[] @NonNull[]\' but this expression has type \'@Nullable Ref<@Nullable String @NonNull[] @NonNull[]> @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "8. ERROR in test\\X.java (at line 46)\n" + + " checkGeneric(x.genericFieldWithNullable2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref<@NonNull String @NonNull[] @NonNull[]> @NonNull[] @NonNull[]\' but this expression has type \'@NonNull Ref<@NonNull String @NonNull[] @Nullable[]> @NonNull[] @Nullable[]\'\n" + + "----------\n" + ); +} +public void testBug499589BTB() { + Runner runner = new Runner(); + runner.classLibraries = this.LIBS; + runner.testFiles = + new String[] { + "test/Ref.java", + "package test;\n" + + "\n" + + "public class Ref {\n" + + " T get() {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}\n" + + "", + "test/X.java", + "package test;\n" + + "\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.ARRAY_CONTENTS;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.FIELD;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.RETURN_TYPE;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@SuppressWarnings({ \"unchecked\" })\n" + + "@NonNullByDefault({ FIELD, RETURN_TYPE, PARAMETER, ARRAY_CONTENTS, TYPE_ARGUMENT })\n" + + "public abstract class X {\n" + + " public final String[][] field = {};\n" + + " public final @Nullable String[][] fieldWithNullable1 = {};\n" + + " public final String[] @Nullable [] fieldWithNullable2 = {};\n" + + "\n" + + " public final Ref list = new Ref<>();\n" + + " public final Ref<@Nullable String[][]> listWithNullable1 = new Ref<>();\n" + + " public final Ref listWithNullable2 = new Ref<>();\n" + + "\n" + + " public abstract String[][] method();\n" + + " public abstract @Nullable String[][] methodWithNullable1();\n" + + " public abstract String[] @Nullable [] methodWithNullable2();\n" + + "\n" + + " public final Ref[][] genericField = new Ref[0][];\n" + + " public final @Nullable Ref<@Nullable String[][]>[][] genericFieldWithNullable1 = new Ref[0][];\n" + + " public final Ref[] @Nullable [] genericFieldWithNullable2 = new Ref[0][];\n" + + "}\n" + + "", + }; + runner.javacTestOptions = new JavacTestOptions.SuppressWarnings("rawtypes"); // javac detects rawtypes at new Ref[0][0] + runner.runConformTest(); + runNegativeTestWithLibs( + new String[] { + "test/BinaryUsage.java", + "package test;\n" + + "\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "class BinaryUsage {\n" + + " void check(@NonNull String @NonNull [] @NonNull [] s) {\n" + + " }\n" + + "\n" + + " void checkGeneric(@NonNull Ref<@NonNull String @NonNull [] @NonNull []> @NonNull [] @NonNull [] s) {\n" + + " }\n" + + "\n" + + " void f(X x) {\n" + + " check(x.field);\n" + + " check(x.fieldWithNullable1);\n" + + " check(x.fieldWithNullable2);\n" + + " check(x.list.get());\n" + + " check(x.listWithNullable1.get());\n" + + " check(x.listWithNullable2.get());\n" + + " check(x.method());\n" + + " check(x.methodWithNullable1());\n" + + " check(x.methodWithNullable2());\n" + + " checkGeneric(x.genericField);\n" + + " checkGeneric(x.genericFieldWithNullable1);\n" + + " checkGeneric(x.genericFieldWithNullable2);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\BinaryUsage.java (at line 15)\n" + + " check(x.fieldWithNullable1);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@Nullable String @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "2. ERROR in test\\BinaryUsage.java (at line 16)\n" + + " check(x.fieldWithNullable2);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@NonNull String @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "3. ERROR in test\\BinaryUsage.java (at line 18)\n" + + " check(x.listWithNullable1.get());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@Nullable String @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "4. ERROR in test\\BinaryUsage.java (at line 19)\n" + + " check(x.listWithNullable2.get());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@NonNull String @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "5. ERROR in test\\BinaryUsage.java (at line 21)\n" + + " check(x.methodWithNullable1());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@Nullable String @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "6. ERROR in test\\BinaryUsage.java (at line 22)\n" + + " check(x.methodWithNullable2());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull String @NonNull[] @NonNull[]\' but this expression has type \'@NonNull String @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "7. ERROR in test\\BinaryUsage.java (at line 24)\n" + + " checkGeneric(x.genericFieldWithNullable1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref<@NonNull String @NonNull[] @NonNull[]> @NonNull[] @NonNull[]\' but this expression has type \'@Nullable Ref<@Nullable String @NonNull[] @NonNull[]> @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "8. ERROR in test\\BinaryUsage.java (at line 25)\n" + + " checkGeneric(x.genericFieldWithNullable2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref<@NonNull String @NonNull[] @NonNull[]> @NonNull[] @NonNull[]\' but this expression has type \'@NonNull Ref<@NonNull String @NonNull[] @Nullable[]> @NonNull[] @Nullable[]\'\n" + + "----------\n" + ); +} + +public void testBug499589STBqualified() { + runNegativeTestWithLibs( + new String[] { + "test/Ref.java", + "package test;\n" + + "\n" + + "public class Ref {\n" + + " T get() {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}\n" + + "", + "test/A.java", + "package test;\n" + + "\n" + + "public class A {\n" + + " class B {\n" + + " }\n" + + "}\n" + + "", + "test/X.java", + "package test;\n" + + "\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@SuppressWarnings({ \"unchecked\" })\n" + + "@NonNullByDefault({ FIELD, RETURN_TYPE, PARAMETER, ARRAY_CONTENTS, TYPE_ARGUMENT })\n" + + "public abstract class X {\n" + + " public final test.A.B[][] field = {};\n" + + " public final test.A.@Nullable B[][] fieldWithNullable1 = {};\n" + + " public final test.A.B[] @Nullable [] fieldWithNullable2 = {};\n" + + "\n" + + " public final test.Ref list = new Ref<>();\n" + + " public final test.Ref listWithNullable1 = new Ref<>();\n" + + " public final test.Ref listWithNullable2 = new Ref<>();\n" + + "\n" + + " public abstract test.A.B[][] method();\n" + + " public abstract test.A.@Nullable B[][] methodWithNullable1();\n" + + " public abstract test.A.B[] @Nullable [] methodWithNullable2();\n" + + "\n" + + " public final test.Ref[][] genericField = new Ref[0][];\n" + + " public final test.@Nullable Ref[][] genericFieldWithNullable1 = new Ref[0][];;\n" + + " public final test.Ref[] @Nullable[] genericFieldWithNullable2 = new Ref[0][];;\n" + + "}\n" + + "\n" + + "class SourceUsage {\n" + + " void check(test.A.@NonNull B @NonNull [] @NonNull [] s) {\n" + + " }\n" + + " void checkGeneric(test.@NonNull Ref @NonNull [] @NonNull [] s) {\n" + + " }\n" + + "\n" + + " void f(X x) {\n" + + " check(x.field);\n" + + " check(x.fieldWithNullable1);\n" + + " check(x.fieldWithNullable2);\n" + + " check(x.list.get());\n" + + " check(x.listWithNullable1.get());\n" + + " check(x.listWithNullable2.get());\n" + + " check(x.method());\n" + + " check(x.methodWithNullable1());\n" + + " check(x.methodWithNullable2());\n" + + " checkGeneric(x.genericField);\n" + + " checkGeneric(x.genericFieldWithNullable1);\n" + + " checkGeneric(x.genericFieldWithNullable2);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\X.java (at line 35)\n" + + " check(x.fieldWithNullable1);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@Nullable B @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "2. ERROR in test\\X.java (at line 36)\n" + + " check(x.fieldWithNullable2);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@NonNull B @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "3. ERROR in test\\X.java (at line 38)\n" + + " check(x.listWithNullable1.get());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@Nullable B @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "4. ERROR in test\\X.java (at line 39)\n" + + " check(x.listWithNullable2.get());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@NonNull B @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "5. ERROR in test\\X.java (at line 41)\n" + + " check(x.methodWithNullable1());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@Nullable B @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "6. ERROR in test\\X.java (at line 42)\n" + + " check(x.methodWithNullable2());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@NonNull B @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "7. ERROR in test\\X.java (at line 44)\n" + + " checkGeneric(x.genericFieldWithNullable1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref @NonNull[] @NonNull[]\' but this expression has type \'@Nullable Ref @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "8. ERROR in test\\X.java (at line 45)\n" + + " checkGeneric(x.genericFieldWithNullable2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref @NonNull[] @NonNull[]\' but this expression has type \'@NonNull Ref @NonNull[] @Nullable[]\'\n" + + "----------\n" + ); +} +public void testBug499589BTBqualified() { + Runner runner = new Runner(); + runner.classLibraries = this.LIBS; + runner.testFiles = + new String[] { + "test/Ref.java", + "package test;\n" + + "\n" + + "public class Ref {\n" + + " T get() {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}\n" + + "", + "test/A.java", + "package test;\n" + + "\n" + + "public class A {\n" + + " class B {\n" + + " }\n" + + "}\n" + + "", + "test/X.java", + "package test;\n" + + "\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.*;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@SuppressWarnings({ \"unchecked\" })\n" + + "@NonNullByDefault({ FIELD, RETURN_TYPE, PARAMETER, ARRAY_CONTENTS, TYPE_ARGUMENT })\n" + + "public abstract class X {\n" + + " public final test.A.B[][] field = {};\n" + + " public final test.A.@Nullable B[][] fieldWithNullable1 = {};\n" + + " public final test.A.B[] @Nullable [] fieldWithNullable2 = {};\n" + + "\n" + + " public final test.Ref list = new Ref<>();\n" + + " public final test.Ref listWithNullable1 = new Ref<>();\n" + + " public final test.Ref listWithNullable2 = new Ref<>();\n" + + "\n" + + " public abstract test.A.B[][] method();\n" + + " public abstract test.A.@Nullable B[][] methodWithNullable1();\n" + + " public abstract test.A.B[] @Nullable [] methodWithNullable2();\n" + + "\n" + + " public final test.Ref[][] genericField = new Ref[0][];\n" + + " public final test.@Nullable Ref[][] genericFieldWithNullable1 = new Ref[0][];;\n" + + " public final test.Ref[] @Nullable[] genericFieldWithNullable2 = new Ref[0][];;\n" + + "}\n" + + "", + }; + runner.javacTestOptions = new JavacTestOptions.SuppressWarnings("rawtypes"); // javac detects rawtypes at new Ref[0][0] + runner.runConformTest(); + runNegativeTestWithLibs( + new String[] { + "test/BinaryUsage.java", + "package test;\n" + + "\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "class BinaryUsage {\n" + + " void check(test.A.@NonNull B @NonNull [] @NonNull [] s) {\n" + + " }\n" + + " void checkGeneric(test.@NonNull Ref @NonNull [] @NonNull [] s) {\n" + + " }\n" + + "\n" + + " void f(X x) {\n" + + " check(x.field);\n" + + " check(x.fieldWithNullable1);\n" + + " check(x.fieldWithNullable2);\n" + + " check(x.list.get());\n" + + " check(x.listWithNullable1.get());\n" + + " check(x.listWithNullable2.get());\n" + + " check(x.method());\n" + + " check(x.methodWithNullable1());\n" + + " check(x.methodWithNullable2());\n" + + " checkGeneric(x.genericField);\n" + + " checkGeneric(x.genericFieldWithNullable1);\n" + + " checkGeneric(x.genericFieldWithNullable2);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\BinaryUsage.java (at line 14)\n" + + " check(x.fieldWithNullable1);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@Nullable B @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "2. ERROR in test\\BinaryUsage.java (at line 15)\n" + + " check(x.fieldWithNullable2);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@NonNull B @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "3. ERROR in test\\BinaryUsage.java (at line 17)\n" + + " check(x.listWithNullable1.get());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@Nullable B @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "4. ERROR in test\\BinaryUsage.java (at line 18)\n" + + " check(x.listWithNullable2.get());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@NonNull B @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "5. ERROR in test\\BinaryUsage.java (at line 20)\n" + + " check(x.methodWithNullable1());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@Nullable B @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "6. ERROR in test\\BinaryUsage.java (at line 21)\n" + + " check(x.methodWithNullable2());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'A.@NonNull B @NonNull[] @NonNull[]\' but this expression has type \'A.@NonNull B @NonNull[] @Nullable[]\'\n" + + "----------\n" + + "7. ERROR in test\\BinaryUsage.java (at line 23)\n" + + " checkGeneric(x.genericFieldWithNullable1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref @NonNull[] @NonNull[]\' but this expression has type \'@Nullable Ref @NonNull[] @NonNull[]\'\n" + + "----------\n" + + "8. ERROR in test\\BinaryUsage.java (at line 24)\n" + + " checkGeneric(x.genericFieldWithNullable2);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch (type annotations): required \'@NonNull Ref @NonNull[] @NonNull[]\' but this expression has type \'@NonNull Ref @NonNull[] @Nullable[]\'\n" + + "----------\n" + ); +} +public void testBug499589arrayAllocation() { + runNegativeTestWithLibs( + new String[] { + "test/ArrayAllocation.java", + "package test;\n" + + "\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.ARRAY_CONTENTS;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault({ ARRAY_CONTENTS })\n" + + "public class ArrayAllocation {\n" + + " public Integer[] x1 = { 1, 2, 3, null };\n" + + " public Integer[] x2 = new Integer[] { 1, 2, 3 };\n" + + " public Integer[] x3 = new Integer[] { 1, 2, 3, null };\n" + + " public Integer[] x4 = new Integer[3];\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\ArrayAllocation.java (at line 9)\n" + + " public Integer[] x1 = { 1, 2, 3, null };\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Integer\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in test\\ArrayAllocation.java (at line 11)\n" + + " public Integer[] x3 = new Integer[] { 1, 2, 3, null };\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Integer\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in test\\ArrayAllocation.java (at line 12)\n" + + " public Integer[] x4 = new Integer[3];\n" + + " ^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'Integer[]\' needs unchecked conversion to conform to \'@NonNull Integer []\'\n" + + "----------\n" + ); +} +public void testBug499589generics() { + runNegativeTestWithLibs( + new String[] { + "test/Methods.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault({ DefaultLocation.TYPE_ARGUMENT, DefaultLocation.ARRAY_CONTENTS })\n" + + "public class Methods {\n" + + " static interface List {\n" + + " T get(int i);\n" + + " }\n" + + "\n" + + " public static List f0(List list) {\n" + + " @NonNull\n" + + " Object o = list.get(0);\n" + + " return list;\n" + + " }\n" + + "\n" + + " public static String[] f1(String[] array) {\n" + + " @NonNull\n" + + " Object o = array[0];\n" + + " return array;\n" + + " }\n" + + "\n" + + " public static List g0(List list) {\n" + + " @NonNull\n" + + " Object o = list.get(0); // problem\n" + + " return list;\n" + + " }\n" + + "\n" + + " public static T[] g1(T[] array) {\n" + + " @NonNull\n" + + " Object o = array[0]; // problem\n" + + " return array;\n" + + " }\n" + + "\n" + + " public static <@NonNull T> List<@NonNull T> h0(List list) {\n" + + " @NonNull\n" + + " Object o = list.get(0);\n" + + " return list;\n" + + " }\n" + + "\n" + + " public static <@NonNull T> @NonNull T[] h1(T[] array) {\n" + + " @NonNull\n" + + " Object o = array[0];\n" + + " return array;\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\Methods.java (at line 26)\n" + + " Object o = list.get(0); // problem\n" + + " ^^^^^^^^^^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in test\\Methods.java (at line 32)\n" + + " Object o = array[0]; // problem\n" + + " ^^^^^^^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + ); +} +public void testBug511723() { + runNegativeTestWithLibs( + new String[] { + "test/ArrayVsList.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class ArrayVsList {\n" + + " static interface List {\n" + + " T get(int i);\n" + + " }\n" + + " public static void f(List list) {\n" + + " @NonNull\n" + + " Object o = list.get(0); // problem\n" + + " o.hashCode();\n" + + " }\n" + + "\n" + + " public static void g(T[] array) {\n" + + " @NonNull\n" + + " Object o = array[0]; // problem\n" + + " o.hashCode();\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\ArrayVsList.java (at line 11)\n" + + " Object o = list.get(0); // problem\n" + + " ^^^^^^^^^^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + + "2. ERROR in test\\ArrayVsList.java (at line 17)\n" + + " Object o = array[0]; // problem\n" + + " ^^^^^^^^\n" + + "Null type safety: required \'@NonNull\' but this expression has type \'T\', a free type variable that may represent a \'@Nullable\' type\n" + + "----------\n" + ); +} +public void testBug498084() { + runConformTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "import java.util.function.Function;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + "\n" + + " protected static final V cache(final Map cache, final V value, final Function keyFunction) {\n" + + " cache.put(keyFunction.apply(value), value);\n" + + " return value;\n" + + " }\n" + + "\n" + + " public static final void main(final String[] args) {\n" + + " Map cache = new HashMap<>();\n" + + " cache(cache, \"test\", String::length); // Warning: Null type safety at\n" + + " // method return type: Method\n" + + " // descriptor\n" + + " // Function.apply(String)\n" + + " // promises '@NonNull Integer'\n" + + " // but referenced method\n" + + " // provides 'int'\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug498084b() { + runNegativeTestWithLibs( + new String[] { + "test/Test2.java", + "package test;\n" + + "\n" + + "import java.util.function.Consumer;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class Test2 {\n" + + " static void f(int i) {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Consumer<@Nullable Integer> sam = Test2::f;\n" + + " sam.accept(null); // <- NullPointerExpection when run\n" + + " Consumer sam2 = Test2::f;\n" + + " sam2.accept(null); // variation: unchecked \n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\Test2.java (at line 12)\n" + + " Consumer<@Nullable Integer> sam = Test2::f;\n" + + " ^^^^^^^^\n" + + "Null type mismatch at parameter 1: required \'int\' but provided \'@Nullable Integer\' via method descriptor Consumer.accept(Integer)\n" + + "----------\n" + + "2. WARNING in test\\Test2.java (at line 14)\n" + + " Consumer sam2 = Test2::f;\n" + + " ^^^^^^^^\n" + + "Null type safety: parameter 1 provided via method descriptor Consumer.accept(Integer) needs unchecked conversion to conform to \'int\'\n" + + "----------\n" + ); +} +public void testBug513495() { + runNegativeTestWithLibs( + new String[] { + "test/Test3.java", + "package test;\n" + + "\n" + + "import java.util.function.Function;\n" + + "\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class Test3 {\n" + + " public static void main(String[] args) {\n" + + " Function<@Nullable Integer, Object> sam = Integer::intValue;\n" + + " sam.apply(null); // <- NullPointerExpection\n" + + " Function sam2 = Integer::intValue;\n" + + " sam2.apply(null); // variation: unchecked, so intentionally no warning reported, but would give NPE too \n" + + " }\n" + + " void wildcards(Class[] params) { // unchecked case with wildcards\n" + + " java.util.Arrays.stream(params).map(Class::getName).toArray(String[]::new);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\Test3.java (at line 9)\n" + + " Function<@Nullable Integer, Object> sam = Integer::intValue;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Null type mismatch at parameter 'this': required \'@NonNull Integer\' but provided \'@Nullable Integer\' via method descriptor Function.apply(Integer)\n" + + "----------\n" + ); +} +public void testBug513855() { + runConformTestWithLibs( + new String[] { + "test1/X.java", + "package test1;\n" + + "\n" + + "import java.math.BigDecimal;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class X {\n" + + " interface Sink {\n" + + " void receive(T t);\n" + + " }\n" + + "\n" + + " interface Source {\n" + + " U get();\n" + + " }\n" + + "\n" + + " void nn(Object x) {\n" + + " }\n" + + "\n" + + " void f(Source source) {\n" + + " nn(source.get());\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug513855lambda() { + runConformTestWithLibs( + new String[] { + "test1/Lambda3.java", + "package test1;\n" + + "\n" + + "import java.math.BigDecimal;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Lambda3 {\n" + + " interface Sink {\n" + + " void receive(T t);\n" + + " }\n" + + "\n" + + " interface Source {\n" + + " void sendTo(Sink c);\n" + + " }\n" + + "\n" + + " void f(Source source) {\n" + + " source.sendTo(a -> a.scale());\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug514091() { + runConformTestWithLibs( + new String[] { + "test1/SAM.java", + "package test1;\n" + + "\n" + + "@org.eclipse.jdt.annotation.NonNullByDefault\n" + + "interface SAM {\n" + + " void f(A[] a);\n" + + "}\n" + + "" + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false /* don't flush */, + new String[] { + "test1/LambdaNN.java", + "package test1;\n" + + "\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class LambdaNN {\n" + + " void g1() {\n" + + " SAM sam = (Number @NonNull [] a) -> {};\n" + + " sam.f(new Number[0]);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug514570() { + final Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); + runConformTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class Test {\n" + + " /**\n" + + " * {@link #bug()}\n" + + " */\n" + + " > void bug() {\n" + + " }\n" + + "}\n" + + "", + }, + compilerOptions, + "" + ); +} +public void testBug514977() { + runNegativeTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import org.eclipse.jdt.annotation.DefaultLocation;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "public class Test {\n" + + " static void nn(@NonNull Object i) {\n" + + " i.hashCode();\n" + + " }\n" + + "\n" + + " static void f(@NonNull Integer @NonNull... args) {\n" + + " nn(args);\n" + + " for (Integer s : args) {\n" + + " nn(s);\n" + + " }\n" + + " }\n" + + "\n" + + " @NonNullByDefault({ DefaultLocation.ARRAY_CONTENTS, DefaultLocation.PARAMETER })\n" + + " static void g(Integer... args) {\n" + + " nn(args);\n" + + " for (Integer s : args) {\n" + + " nn(s);\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Integer i = args.length == 0 ? null : 1;\n" + + " Integer[] array = i == null ? null : new Integer[] {i};\n" + + " f(array);\n" + + " f(i);\n" + + " f(1, i);\n" + + " g(array);\n" + + " g(i);\n" + + " g(1, i);\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in test\\Test.java (at line 30)\n" + + " f(array);\n" + + " ^^^^^\n" + + "Null type mismatch: required \'@NonNull Integer @NonNull[]\' but the provided value is inferred as @Nullable\n" + + "----------\n" + + "2. ERROR in test\\Test.java (at line 31)\n" + + " f(i);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Integer\' but the provided value is inferred as @Nullable\n" + + "----------\n" + + "3. ERROR in test\\Test.java (at line 32)\n" + + " f(1, i);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Integer\' but the provided value is inferred as @Nullable\n" + + "----------\n" + + "4. ERROR in test\\Test.java (at line 33)\n" + + " g(array);\n" + + " ^^^^^\n" + + "Null type mismatch: required \'@NonNull Integer @NonNull[]\' but the provided value is inferred as @Nullable\n" + + "----------\n" + + "5. ERROR in test\\Test.java (at line 34)\n" + + " g(i);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Integer\' but the provided value is inferred as @Nullable\n" + + "----------\n" + + "6. ERROR in test\\Test.java (at line 35)\n" + + " g(1, i);\n" + + " ^\n" + + "Null type mismatch: required \'@NonNull Integer\' but the provided value is inferred as @Nullable\n" + + "----------\n" + ); +} +public void testBug515292() { + runConformTestWithLibs( + new String[] { + "test/BoundedByFinal.java", + "package test;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public abstract class BoundedByFinal {\n" + + " abstract void setSelection(T[] selectedObjects);\n" + + "\n" + + " abstract @NonNull String @NonNull [] toArray1();\n" + + "\n" + + " abstract @Nullable String @NonNull [] toArray2();\n" + + "\n" + + " void test() {\n" + + " setSelection(toArray1());\n" + + " setSelection(toArray2());\n" + + " }\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug526555() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION, JavaCore.WARNING); + + runWarningTestWithLibs( + true/*flush*/, + new String[] { + "ztest/OverrideTest.java", + "package ztest;\n" + + "\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.ARRAY_CONTENTS;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.FIELD;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.PARAMETER;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.RETURN_TYPE;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "import static org.eclipse.jdt.annotation.DefaultLocation.TYPE_BOUND;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "interface X509TrustManager {\n" + + " void checkClientTrusted(String[] arg0, String arg1);\n" + + "\n" + + "}\n" + + "\n" + + "@NonNullByDefault({ PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS })\n" + + "public class OverrideTest implements X509TrustManager {\n" + + " @Override\n" + + " public void checkClientTrusted(String @Nullable [] arg0, @Nullable String arg1) {\n" + + " }\n" + + "}", + }, + customOptions, + "----------\n" + + "1. WARNING in ztest\\OverrideTest.java (at line 21)\n" + + " public void checkClientTrusted(String @Nullable [] arg0, @Nullable String arg1) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Illegal redefinition of parameter arg0, inherited method from X509TrustManager declares this parameter as \'String[]\' (mismatching null constraints)\n" + + "----------\n" + ); +} +public void testBug530913() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.*;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runConformTestWithLibs( + false, + new String[] { + "nnbd_test2/Data.java", + "package nnbd_test2;\n" + + "\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "import annotation.DefaultLocation;\n" + + "import annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Data {\n" + + " public void f(@NonNullByDefault({}) String s1, String s2) {\n" + + " s1.equals(s2);\n" + + " }\n" + + "\n" + + " public void g(String s1, @NonNullByDefault({}) String s2) {\n" + + " s1.equals(s2);\n" + + " }\n" + + " \n" + + " @NonNullByDefault({})\n" + + " public void h(@NonNullByDefault({ DefaultLocation.PARAMETER }) Supplier s1, @NonNullByDefault Supplier s2) {\n" + + " s1.equals(s2);\n" + + " }\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runNegativeTestWithLibs( + new String[] { + "nnbd_test1/Test.java", + "package nnbd_test1;\n" + + "\n" + + "import java.util.function.Supplier;\n" + + "\n" + + "import annotation.DefaultLocation;\n" + + "import annotation.NonNullByDefault;\n" + + "import nnbd_test2.Data;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Test {\n" + + " void f(@NonNullByDefault({}) String s1, String s2) {\n" + + " if (s1 == null) {\n" + + " System.out.println(\"s is null\");\n" + + " }\n" + + " if (s2 == null) { // warning expected\n" + + " System.out.println(\"s2 is null\");\n" + + " }\n" + + " }\n" + + "\n" + + " void g(String s1, @NonNullByDefault({}) String s2) {\n" + + " if (s1 == null) { // warning expected\n" + + " System.out.println(\"s is null\");\n" + + " }\n" + + " if (s2 == null) {\n" + + " System.out.println(\"s2 is null\");\n" + + " }\n" + + " }\n" + + "\n" + + " @NonNullByDefault({})\n" + + " void h(@NonNullByDefault({ DefaultLocation.PARAMETER }) Supplier s1, @NonNullByDefault Supplier s2) {\n" + + " if (s1 == null) { // warning expected\n" + + " System.out.println(\"s is null\");\n" + + " return;\n" + + " }\n" + + " if (s2 == null) { // warning expected\n" + + " System.out.println(\"s2 is null\");\n" + + " return;\n" + + " }\n" + + " if (s1.get() == null) {\n" + + " System.out.println(\"s is null\");\n" + + " }\n" + + " if (s2.get() == null) { // warning expected\n" + + " System.out.println(\"s2 is null\");\n" + + " }\n" + + " }\n" + + "\n" + + " void checkInvocation() {\n" + + " Test d = new Test();\n" + + " d.f(null, null); // warning on the second null expected\n" + + " d.g(null, null); // warning on the first null expected\n" + + " }\n" + + "\n" + + " void checkBTBInvocation() {\n" + + " Data d = new Data();\n" + + " d.f(null, null); // warning on the second null expected\n" + + " d.g(null, null); // warning on the first null expected\n" + + " }\n" + + "\n" + + " void checkInheritance() {\n" + + " Test t = new Test() {\n" + + " @Override\n" + + " void f(String s1, String s2) { // warning on the first parameter expected\n" + + " super.f(null, null); // warning on the second null expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " void g(String s1, String s2) { // warning on the second parameter expected\n" + + " super.g(null, null); // warning on the first null expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " void h(Supplier s1, Supplier s2) { // warning on the first parameter expected\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " void checkBTBInheritance() {\n" + + " Data d = new Data() {\n" + + " @Override\n" + + " public void f(String s1, String s2) { // warning on the first parameter expected\n" + + " super.f(null, null); // warning on the second null expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void g(String s1, String s2) { // warning on the second parameter expected\n" + + " super.g(null, null); // warning on the first null expected\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void h(Supplier s1, Supplier s2) { // warning on the first parameter expected\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + + "", + }, + customOptions, + "----------\n" + + "1. ERROR in nnbd_test1\\Test.java (at line 15)\n" + + " if (s2 == null) { // warning expected\n" + + " ^^\n" + + "Redundant null check: comparing \'@NonNull String\' against null\n" + + "----------\n" + + "2. ERROR in nnbd_test1\\Test.java (at line 21)\n" + + " if (s1 == null) { // warning expected\n" + + " ^^\n" + + "Redundant null check: comparing \'@NonNull String\' against null\n" + + "----------\n" + + "3. ERROR in nnbd_test1\\Test.java (at line 31)\n" + + " if (s1 == null) { // warning expected\n" + + " ^^\n" + + "Redundant null check: comparing \'@NonNull Supplier\' against null\n" + + "----------\n" + + "4. ERROR in nnbd_test1\\Test.java (at line 35)\n" + + " if (s2 == null) { // warning expected\n" + + " ^^\n" + + "Redundant null check: comparing \'@NonNull Supplier<@NonNull String>\' against null\n" + + "----------\n" + + "5. ERROR in nnbd_test1\\Test.java (at line 42)\n" + + " if (s2.get() == null) { // warning expected\n" + + " ^^^^^^^^\n" + + "Redundant null check: comparing \'@NonNull String\' against null\n" + + "----------\n" + + "6. ERROR in nnbd_test1\\Test.java (at line 49)\n" + + " d.f(null, null); // warning on the second null expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "7. ERROR in nnbd_test1\\Test.java (at line 50)\n" + + " d.g(null, null); // warning on the first null expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "8. ERROR in nnbd_test1\\Test.java (at line 55)\n" + + " d.f(null, null); // warning on the second null expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "9. ERROR in nnbd_test1\\Test.java (at line 56)\n" + + " d.g(null, null); // warning on the first null expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "10. ERROR in nnbd_test1\\Test.java (at line 62)\n" + + " void f(String s1, String s2) { // warning on the first parameter expected\n" + + " ^^^^^^\n" + + "Illegal redefinition of parameter s1, inherited method from Test does not constrain this parameter\n" + + "----------\n" + + "11. ERROR in nnbd_test1\\Test.java (at line 63)\n" + + " super.f(null, null); // warning on the second null expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "12. ERROR in nnbd_test1\\Test.java (at line 67)\n" + + " void g(String s1, String s2) { // warning on the second parameter expected\n" + + " ^^^^^^\n" + + "Illegal redefinition of parameter s2, inherited method from Test does not constrain this parameter\n" + + "----------\n" + + "13. ERROR in nnbd_test1\\Test.java (at line 68)\n" + + " super.g(null, null); // warning on the first null expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "14. ERROR in nnbd_test1\\Test.java (at line 72)\n" + + " void h(Supplier s1, Supplier s2) { // warning on the first parameter expected\n" + + " ^^^^^^^^\n" + + "Illegal redefinition of parameter s1, inherited method from Test declares this parameter as \'@NonNull Supplier\' (mismatching null constraints)\n" + + "----------\n" + + "15. ERROR in nnbd_test1\\Test.java (at line 80)\n" + + " public void f(String s1, String s2) { // warning on the first parameter expected\n" + + " ^^^^^^\n" + + "Illegal redefinition of parameter s1, inherited method from Data does not constrain this parameter\n" + + "----------\n" + + "16. ERROR in nnbd_test1\\Test.java (at line 81)\n" + + " super.f(null, null); // warning on the second null expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "17. ERROR in nnbd_test1\\Test.java (at line 85)\n" + + " public void g(String s1, String s2) { // warning on the second parameter expected\n" + + " ^^^^^^\n" + + "Illegal redefinition of parameter s2, inherited method from Data does not constrain this parameter\n" + + "----------\n" + + "18. ERROR in nnbd_test1\\Test.java (at line 86)\n" + + " super.g(null, null); // warning on the first null expected\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "19. ERROR in nnbd_test1\\Test.java (at line 90)\n" + + " public void h(Supplier s1, Supplier s2) { // warning on the first parameter expected\n" + + " ^^^^^^^^\n" + + "Illegal redefinition of parameter s1, inherited method from Data declares this parameter as \'@NonNull Supplier\' (mismatching null constraints)\n" + + "----------\n" + ); +} +public void testBug530913b() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES, "annotation.NNBDField,annotation.NNBDParam,annotation.NNBDReturn,annotation.NNBDTypeArg,annotation.NNBDTypeBound"); + customOptions.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + customOptions.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, JavaCore.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.FIELD;\n" + + "import static annotation.DefaultLocation.PARAMETER;\n" + + "import static annotation.DefaultLocation.RETURN_TYPE;\n" + + "import static annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "import static annotation.DefaultLocation.TYPE_BOUND;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + Runner runner = new Runner(); + runner.classLibraries = this.LIBS; + runner.shouldFlushOutputDirectory = false; + runner.testFiles = + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "import annotation.*;\n" + + "\n" + + "interface C {\n" + + "}\n" + + "\n" + + "abstract class X {\n" + + " @NonNullByDefault(DefaultLocation.RETURN_TYPE) abstract void f2(@NonNullByDefault C p1);\n" + + "}\n" + }; + runner.customOptions = customOptions; + runner.javacTestOptions = new JavacTestOptions.SuppressWarnings("auxiliaryclass"); + runner.runConformTest(); + + runner.testFiles = + new String[] { + "test/ExplicitNonNull.java", + "package test;\n" + + "\n" + + "import annotation.*;\n" + + "\n" + + "\n" + + "class ExplicitNonNull extends X {\n" + + " void f2(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1) {\n" + + " }\n" + + "}\n" + + "", + }; + runner.runConformTest(); +} +public void testBug530971() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES, "annotation.NNBDField,annotation.NNBDParam,annotation.NNBDReturn,annotation.NNBDTypeArg,annotation.NNBDTypeBound"); + customOptions.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, JavaCore.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS\n" + + "}\n" + + "", + "annotation/NNBDField.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.FIELD;\n" + + " \n" + + "public @interface NNBDField {\n" + + " DefaultLocation[] value() default { FIELD };\n" + + "}\n" + + "", + "annotation/NNBDParam.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.PARAMETER;\n" + + "\n" + + "public @interface NNBDParam {\n" + + " DefaultLocation[] value() default { PARAMETER };\n" + + "}\n" + + "", + "annotation/NNBDReturn.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.RETURN_TYPE;\n" + + "\n" + + "public @interface NNBDReturn {\n" + + " DefaultLocation[] value() default { RETURN_TYPE };\n" + + "}\n" + + "", + "annotation/NNBDTypeArg.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "\n" + + "public @interface NNBDTypeArg {\n" + + " DefaultLocation[] value() default { TYPE_ARGUMENT };\n" + + "}\n" + + "", + "annotation/NNBDTypeBound.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.TYPE_BOUND;\n" + + "\n" + + "public @interface NNBDTypeBound {\n" + + " DefaultLocation[] value() default { TYPE_BOUND };\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.FIELD;\n" + + "import static annotation.DefaultLocation.PARAMETER;\n" + + "import static annotation.DefaultLocation.RETURN_TYPE;\n" + + "import static annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "import static annotation.DefaultLocation.TYPE_BOUND;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runNegativeTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import annotation.NNBDField;\n" + + "import annotation.NNBDParam;\n" + + "import annotation.NNBDReturn;\n" + + "import annotation.NNBDTypeArg;\n" + + "import annotation.NNBDTypeBound;\n" + + "import annotation.NonNull;\n" + + "\n" + + "interface C {\n" + + "}\n" + + "\n" + + "abstract class X {\n" + + " @NNBDTypeArg\n" + + " @NNBDField\n" + + " @NNBDTypeBound\n" + + " C f1; // warning 1\n" + + "\n" + + " @NonNull\n" + + " C<@NonNull Object, ? extends @NonNull Number> f2; // warning 2\n" + + "\n" + + " @NNBDTypeArg\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NNBDTypeBound\n" + + " abstract Object m1(C p1, Object p2);\n" + + "\n" + + " abstract @NNBDReturn Object m2(@NNBDParam @NNBDTypeArg @NNBDTypeBound C p1,\n" + + " @NNBDParam Object p2);\n" + + "\n" + + " abstract @NonNull Object m3(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2);\n" + + "}\n" + + "\n" + + "class ExplicitNonNull extends X {\n" + + " Object m1(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 3 on return type\n" + + " f1 = null; // warning 4\n" + + " f2 = null; // warning 5\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m2(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 6 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m3(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 7 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "}\n" + + "\n" + + "@NNBDParam\n" + + "@NNBDTypeArg\n" + + "@NNBDTypeBound\n" + + "class OnClass extends X {\n" + + " Object m1(C p1, Object p2) { // warning 8 on return type\n" + + " f1 = null; // warning 9\n" + + " f2 = null; // warning 10\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m2(C p1, Object p2) { // warning 11 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m3(C p1, Object p2) { // warning 12 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "}\n" + + "\n" + + "class Test {\n" + + " @NNBDParam\n" + + " @NNBDTypeArg\n" + + " @NNBDTypeBound\n" + + " X onField = new X() {\n" + + " Object m1(C p1, Object p2) { // warning 13 on return type\n" + + " f1 = null; // warning 14\n" + + " f2 = null; // warning 15\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m2(C p1, Object p2) { // warning 16 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m3(C p1, Object p2) { // warning 17 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + " };\n" + + "\n" + + " {\n" + + " @NNBDParam\n" + + " @NNBDTypeArg\n" + + " @NNBDTypeBound\n" + + " X onLocal = new X() {\n" + + " Object m1(C p1, Object p2) { // warning 18 on return type\n" + + " f1 = null; // warning 19\n" + + " f2 = null; // warning 20\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m2(C p1, Object p2) { // warning 21 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m3(C p1, Object p2) { // warning 22 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " @NNBDParam\n" + + " @NNBDTypeArg\n" + + " @NNBDTypeBound\n" + + " void onMethod() {\n" + + " X l1 = new X() {\n" + + " Object m1(C p1, Object p2) { // warning 23 on return type\n" + + " f1 = null; // warning 24\n" + + " f2 = null; // warning 25\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m2(C p1, Object p2) { // warning 26 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m3(C p1, Object p2) { // warning 27 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + + "", + }, + customOptions, + "----------\n" + + "1. ERROR in test\\Test.java (at line 17)\n" + + " C f1; // warning 1\n" + + " ^^\n" + + "The @NonNull field f1 may not have been initialized\n" + + "----------\n" + + "2. ERROR in test\\Test.java (at line 20)\n" + + " C<@NonNull Object, ? extends @NonNull Number> f2; // warning 2\n" + + " ^^\n" + + "The @NonNull field f2 may not have been initialized\n" + + "----------\n" + + "3. ERROR in test\\Test.java (at line 35)\n" + + " Object m1(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 3 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m1(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "4. ERROR in test\\Test.java (at line 36)\n" + + " f1 = null; // warning 4\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "5. ERROR in test\\Test.java (at line 37)\n" + + " f2 = null; // warning 5\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "6. ERROR in test\\Test.java (at line 43)\n" + + " Object m2(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 6 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m2(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "7. ERROR in test\\Test.java (at line 49)\n" + + " Object m3(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 7 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m3(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "8. ERROR in test\\Test.java (at line 60)\n" + + " Object m1(C p1, Object p2) { // warning 8 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m1(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "9. ERROR in test\\Test.java (at line 61)\n" + + " f1 = null; // warning 9\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "10. ERROR in test\\Test.java (at line 62)\n" + + " f2 = null; // warning 10\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "11. ERROR in test\\Test.java (at line 68)\n" + + " Object m2(C p1, Object p2) { // warning 11 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m2(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "12. ERROR in test\\Test.java (at line 74)\n" + + " Object m3(C p1, Object p2) { // warning 12 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m3(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "13. ERROR in test\\Test.java (at line 86)\n" + + " Object m1(C p1, Object p2) { // warning 13 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m1(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "14. ERROR in test\\Test.java (at line 87)\n" + + " f1 = null; // warning 14\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "15. ERROR in test\\Test.java (at line 88)\n" + + " f2 = null; // warning 15\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "16. ERROR in test\\Test.java (at line 94)\n" + + " Object m2(C p1, Object p2) { // warning 16 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m2(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "17. ERROR in test\\Test.java (at line 100)\n" + + " Object m3(C p1, Object p2) { // warning 17 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m3(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "18. ERROR in test\\Test.java (at line 112)\n" + + " Object m1(C p1, Object p2) { // warning 18 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m1(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "19. ERROR in test\\Test.java (at line 113)\n" + + " f1 = null; // warning 19\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "20. ERROR in test\\Test.java (at line 114)\n" + + " f2 = null; // warning 20\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "21. ERROR in test\\Test.java (at line 120)\n" + + " Object m2(C p1, Object p2) { // warning 21 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m2(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "22. ERROR in test\\Test.java (at line 126)\n" + + " Object m3(C p1, Object p2) { // warning 22 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m3(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "23. ERROR in test\\Test.java (at line 139)\n" + + " Object m1(C p1, Object p2) { // warning 23 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m1(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "24. ERROR in test\\Test.java (at line 140)\n" + + " f1 = null; // warning 24\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "25. ERROR in test\\Test.java (at line 141)\n" + + " f2 = null; // warning 25\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "26. ERROR in test\\Test.java (at line 147)\n" + + " Object m2(C p1, Object p2) { // warning 26 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m2(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "27. ERROR in test\\Test.java (at line 153)\n" + + " Object m3(C p1, Object p2) { // warning 27 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m3(C, Object) (mismatching null constraints)\n" + + "----------\n" + ); +} + +// same as testBug530971, but X is read via class file +public void testBug530971_BTB() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES, "annotation.NNBDField,annotation.NNBDParam,annotation.NNBDReturn,annotation.NNBDTypeArg,annotation.NNBDTypeBound"); + customOptions.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + customOptions.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, JavaCore.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS\n" + + "}\n" + + "", + "annotation/NNBDField.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.FIELD;\n" + + " \n" + + "public @interface NNBDField {\n" + + " DefaultLocation[] value() default { FIELD };\n" + + "}\n" + + "", + "annotation/NNBDParam.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.PARAMETER;\n" + + "\n" + + "public @interface NNBDParam {\n" + + " DefaultLocation[] value() default { PARAMETER };\n" + + "}\n" + + "", + "annotation/NNBDReturn.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.RETURN_TYPE;\n" + + "\n" + + "public @interface NNBDReturn {\n" + + " DefaultLocation[] value() default { RETURN_TYPE };\n" + + "}\n" + + "", + "annotation/NNBDTypeArg.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "\n" + + "public @interface NNBDTypeArg {\n" + + " DefaultLocation[] value() default { TYPE_ARGUMENT };\n" + + "}\n" + + "", + "annotation/NNBDTypeBound.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.TYPE_BOUND;\n" + + "\n" + + "public @interface NNBDTypeBound {\n" + + " DefaultLocation[] value() default { TYPE_BOUND };\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.FIELD;\n" + + "import static annotation.DefaultLocation.PARAMETER;\n" + + "import static annotation.DefaultLocation.RETURN_TYPE;\n" + + "import static annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "import static annotation.DefaultLocation.TYPE_BOUND;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runConformTestWithLibs( + false, + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "import annotation.NNBDField;\n" + + "import annotation.NNBDParam;\n" + + "import annotation.NNBDReturn;\n" + + "import annotation.NNBDTypeArg;\n" + + "import annotation.NNBDTypeBound;\n" + + "import annotation.NonNull;\n" + + "\n" + + "interface C {\n" + + "}\n" + + "\n" + + "@SuppressWarnings(\"null\")\n" + + "abstract class X {\n" + + " @NNBDTypeArg\n" + + " @NNBDField\n" + + " @NNBDTypeBound\n" + + " C f1; // warning 1\n" + + "\n" + + " @NonNull\n" + + " C<@NonNull Object, ? extends @NonNull Number> f2; // warning 2\n" + + "\n" + + " @NNBDTypeArg\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NNBDTypeBound\n" + + " abstract Object m1(C p1, Object p2);\n" + + "\n" + + " abstract @NNBDReturn Object m2(@NNBDParam @NNBDTypeArg @NNBDTypeBound C p1,\n" + + " @NNBDParam Object p2);\n" + + "\n" + + " abstract @NonNull Object m3(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2);\n" + + "}\n" + }, + customOptions, + "" + ); + runNegativeTestWithLibs( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import annotation.NNBDField;\n" + + "import annotation.NNBDParam;\n" + + "import annotation.NNBDReturn;\n" + + "import annotation.NNBDTypeArg;\n" + + "import annotation.NNBDTypeBound;\n" + + "import annotation.NonNull;\n" + + "\n" + + "interface C_IGNORED {\n" + + "}\n" + + "\n" + + "abstract class X_IGNORED {\n" + + " @NNBDTypeArg\n" + + " @NNBDField\n" + + " @NNBDTypeBound\n" + + " C f1; // warning 1\n" + + "\n" + + " @NonNull\n" + + " C<@NonNull Object, ? extends @NonNull Number> f2; // warning 2\n" + + "\n" + + " @NNBDTypeArg\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NNBDTypeBound\n" + + " abstract Object m1(C p1, Object p2);\n" + + "\n" + + " abstract @NNBDReturn Object m2(@NNBDParam @NNBDTypeArg @NNBDTypeBound C p1,\n" + + " @NNBDParam Object p2);\n" + + "\n" + + " abstract @NonNull Object m3(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2);\n" + + "}\n" + + "\n" + + "class ExplicitNonNull extends X {\n" + + " Object m1(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 3 on return type\n" + + " f1 = null; // warning 4\n" + + " f2 = null; // warning 5\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m2(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 6 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m3(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 7 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "}\n" + + "\n" + + "@NNBDParam\n" + + "@NNBDTypeArg\n" + + "@NNBDTypeBound\n" + + "class OnClass extends X {\n" + + " Object m1(C p1, Object p2) { // warning 8 on return type\n" + + " f1 = null; // warning 9\n" + + " f2 = null; // warning 10\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m2(C p1, Object p2) { // warning 11 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m3(C p1, Object p2) { // warning 12 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "}\n" + + "\n" + + "class Test {\n" + + " @NNBDParam\n" + + " @NNBDTypeArg\n" + + " @NNBDTypeBound\n" + + " X onField = new X() {\n" + + " Object m1(C p1, Object p2) { // warning 13 on return type\n" + + " f1 = null; // warning 14\n" + + " f2 = null; // warning 15\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m2(C p1, Object p2) { // warning 16 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m3(C p1, Object p2) { // warning 17 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + " };\n" + + "\n" + + " {\n" + + " @NNBDParam\n" + + " @NNBDTypeArg\n" + + " @NNBDTypeBound\n" + + " X onLocal = new X() {\n" + + " Object m1(C p1, Object p2) { // warning 18 on return type\n" + + " f1 = null; // warning 19\n" + + " f2 = null; // warning 20\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m2(C p1, Object p2) { // warning 21 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m3(C p1, Object p2) { // warning 22 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + " };\n" + + " }\n" + + "\n" + + " @NNBDParam\n" + + " @NNBDTypeArg\n" + + " @NNBDTypeBound\n" + + " void onMethod() {\n" + + " X l1 = new X() {\n" + + " Object m1(C p1, Object p2) { // warning 23 on return type\n" + + " f1 = null; // warning 24\n" + + " f2 = null; // warning 25\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m2(C p1, Object p2) { // warning 26 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + "\n" + + " Object m3(C p1, Object p2) { // warning 27 on return type\n" + + " f1 = p1;\n" + + " f2 = p1;\n" + + " return p2;\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + + "", + }, + customOptions, + "----------\n" + + "1. ERROR in test\\Test.java (at line 17)\n" + + " C f1; // warning 1\n" + + " ^^\n" + + "The @NonNull field f1 may not have been initialized\n" + + "----------\n" + + "2. ERROR in test\\Test.java (at line 20)\n" + + " C<@NonNull Object, ? extends @NonNull Number> f2; // warning 2\n" + + " ^^\n" + + "The @NonNull field f2 may not have been initialized\n" + + "----------\n" + + "3. ERROR in test\\Test.java (at line 35)\n" + + " Object m1(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 3 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m1(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "4. ERROR in test\\Test.java (at line 36)\n" + + " f1 = null; // warning 4\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "5. ERROR in test\\Test.java (at line 37)\n" + + " f2 = null; // warning 5\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "6. ERROR in test\\Test.java (at line 43)\n" + + " Object m2(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 6 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m2(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "7. ERROR in test\\Test.java (at line 49)\n" + + " Object m3(@NonNull C<@NonNull Object, ? extends @NonNull Number> p1, @NonNull Object p2) { // warning 7 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m3(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "8. ERROR in test\\Test.java (at line 60)\n" + + " Object m1(C p1, Object p2) { // warning 8 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m1(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "9. ERROR in test\\Test.java (at line 61)\n" + + " f1 = null; // warning 9\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "10. ERROR in test\\Test.java (at line 62)\n" + + " f2 = null; // warning 10\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "11. ERROR in test\\Test.java (at line 68)\n" + + " Object m2(C p1, Object p2) { // warning 11 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m2(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "12. ERROR in test\\Test.java (at line 74)\n" + + " Object m3(C p1, Object p2) { // warning 12 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m3(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "13. ERROR in test\\Test.java (at line 86)\n" + + " Object m1(C p1, Object p2) { // warning 13 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m1(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "14. ERROR in test\\Test.java (at line 87)\n" + + " f1 = null; // warning 14\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "15. ERROR in test\\Test.java (at line 88)\n" + + " f2 = null; // warning 15\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "16. ERROR in test\\Test.java (at line 94)\n" + + " Object m2(C p1, Object p2) { // warning 16 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m2(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "17. ERROR in test\\Test.java (at line 100)\n" + + " Object m3(C p1, Object p2) { // warning 17 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m3(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "18. ERROR in test\\Test.java (at line 112)\n" + + " Object m1(C p1, Object p2) { // warning 18 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m1(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "19. ERROR in test\\Test.java (at line 113)\n" + + " f1 = null; // warning 19\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "20. ERROR in test\\Test.java (at line 114)\n" + + " f2 = null; // warning 20\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "21. ERROR in test\\Test.java (at line 120)\n" + + " Object m2(C p1, Object p2) { // warning 21 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m2(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "22. ERROR in test\\Test.java (at line 126)\n" + + " Object m3(C p1, Object p2) { // warning 22 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m3(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "23. ERROR in test\\Test.java (at line 139)\n" + + " Object m1(C p1, Object p2) { // warning 23 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m1(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "24. ERROR in test\\Test.java (at line 140)\n" + + " f1 = null; // warning 24\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "25. ERROR in test\\Test.java (at line 141)\n" + + " f2 = null; // warning 25\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull C<@NonNull Object,? extends @NonNull Number>\' but the provided value is null\n" + + "----------\n" + + "26. ERROR in test\\Test.java (at line 147)\n" + + " Object m2(C p1, Object p2) { // warning 26 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m2(C, Object) (mismatching null constraints)\n" + + "----------\n" + + "27. ERROR in test\\Test.java (at line 153)\n" + + " Object m3(C p1, Object p2) { // warning 27 on return type\n" + + " ^^^^^^\n" + + "The return type is incompatible with \'@NonNull Object\' returned from X.m3(C, Object) (mismatching null constraints)\n" + + "----------\n" + ); +} +public void testBug530971_redundant() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES, "annotation.NNBDField,annotation.NNBDParam,annotation.NNBDReturn,annotation.NNBDTypeArg,annotation.NNBDTypeBound"); + customOptions.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, JavaCore.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS\n" + + "}\n" + + "", + "annotation/NNBDField.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.FIELD;\n" + + " \n" + + "public @interface NNBDField {\n" + + " DefaultLocation[] value() default { FIELD };\n" + + "}\n" + + "", + "annotation/NNBDParam.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.PARAMETER;\n" + + "\n" + + "public @interface NNBDParam {\n" + + " DefaultLocation[] value() default { PARAMETER };\n" + + "}\n" + + "", + "annotation/NNBDReturn.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.RETURN_TYPE;\n" + + "\n" + + "public @interface NNBDReturn {\n" + + " DefaultLocation[] value() default { RETURN_TYPE };\n" + + "}\n" + + "", + "annotation/NNBDTypeArg.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "\n" + + "public @interface NNBDTypeArg {\n" + + " DefaultLocation[] value() default { TYPE_ARGUMENT };\n" + + "}\n" + + "", + "annotation/NNBDTypeBound.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.TYPE_BOUND;\n" + + "\n" + + "public @interface NNBDTypeBound {\n" + + " DefaultLocation[] value() default { TYPE_BOUND };\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.FIELD;\n" + + "import static annotation.DefaultLocation.PARAMETER;\n" + + "import static annotation.DefaultLocation.RETURN_TYPE;\n" + + "import static annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "import static annotation.DefaultLocation.TYPE_BOUND;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + Runner runner = new Runner(); + runner.shouldFlushOutputDirectory = false; + runner.testFiles = + new String[] { + "test/X.java", + "package test;\n" + + "\n" + + "import annotation.*;\n" + + "\n" + + "@NNBDReturn\n" + + "@NNBDParam\n" + + "@NNBDField\n" + + "abstract class X {\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NNBDField // warning 1\n" + + " abstract class OnClass {\n" + + " }\n" + + "\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NNBDField // warning 2\n" + + " Object onField = \"\";\n" + + "\n" + + " {\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NNBDField // warning 3\n" + + " Object onLocal;\n" + + " }\n" + + "\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NNBDField // warning 4\n" + + " abstract void onMethod();\n" + + "\n" + + " abstract void m(//\n" + + " @NNBDReturn //\n" + + " @NNBDParam //\n" + + " @NNBDField // warning 5\n" + + " Object onParameter);\n" + + "}\n" + + "", + }; + runner.customOptions = customOptions; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in test\\X.java (at line 11)\n" + + " @NNBDField // warning 1\n" + + " ^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type X\n" + + "----------\n" + + "2. WARNING in test\\X.java (at line 17)\n" + + " @NNBDField // warning 2\n" + + " ^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type X\n" + + "----------\n" + + "3. WARNING in test\\X.java (at line 23)\n" + + " @NNBDField // warning 3\n" + + " ^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type X\n" + + "----------\n" + + "4. WARNING in test\\X.java (at line 29)\n" + + " @NNBDField // warning 4\n" + + " ^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type X\n" + + "----------\n" + + "5. WARNING in test\\X.java (at line 35)\n" + + " @NNBDField // warning 5\n" + + " ^^^^^^^^^^\n" + + "Nullness default is redundant with a default specified for the enclosing type X\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +public void testBug530971_locally_redundant() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullByDefault"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES, "annotation.NNBDField,annotation.NNBDParam,annotation.NNBDReturn,annotation.NNBDTypeArg,annotation.NNBDTypeBound"); + customOptions.put(JavaCore.COMPILER_PB_MISSING_OVERRIDE_ANNOTATION, JavaCore.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + runConformTestWithLibs( + new String[] { + "annotation/DefaultLocation.java", + "package annotation;\n" + + "\n" + + "public enum DefaultLocation {\n" + + " PARAMETER, RETURN_TYPE, FIELD, TYPE_PARAMETER, TYPE_BOUND, TYPE_ARGUMENT, ARRAY_CONTENTS\n" + + "}\n" + + "", + "annotation/NNBDField.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.FIELD;\n" + + " \n" + + "public @interface NNBDField {\n" + + " DefaultLocation[] value() default { FIELD };\n" + + "}\n" + + "", + "annotation/NNBDParam.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.PARAMETER;\n" + + "\n" + + "public @interface NNBDParam {\n" + + " DefaultLocation[] value() default { PARAMETER };\n" + + "}\n" + + "", + "annotation/NNBDReturn.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.RETURN_TYPE;\n" + + "\n" + + "public @interface NNBDReturn {\n" + + " DefaultLocation[] value() default { RETURN_TYPE };\n" + + "}\n" + + "", + "annotation/NNBDTypeArg.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "\n" + + "public @interface NNBDTypeArg {\n" + + " DefaultLocation[] value() default { TYPE_ARGUMENT };\n" + + "}\n" + + "", + "annotation/NNBDTypeBound.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.TYPE_BOUND;\n" + + "\n" + + "public @interface NNBDTypeBound {\n" + + " DefaultLocation[] value() default { TYPE_BOUND };\n" + + "}\n" + + "", + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullByDefault.java", + "package annotation;\n" + + "\n" + + "import static annotation.DefaultLocation.FIELD;\n" + + "import static annotation.DefaultLocation.PARAMETER;\n" + + "import static annotation.DefaultLocation.RETURN_TYPE;\n" + + "import static annotation.DefaultLocation.TYPE_ARGUMENT;\n" + + "import static annotation.DefaultLocation.TYPE_BOUND;\n" + + " \n" + + "public @interface NonNullByDefault {\n" + + " DefaultLocation[] value() default { PARAMETER, RETURN_TYPE, FIELD, TYPE_BOUND, TYPE_ARGUMENT };\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runConformTestWithLibs( + false, + new String[] { + "testredundant/TestRedundantOnSame.java", + "package testredundant;\n" + + "\n" + + "import annotation.DefaultLocation;\n" + + "import annotation.NNBDField;\n" + + "import annotation.NNBDParam;\n" + + "import annotation.NNBDReturn;\n" + + "import annotation.NonNullByDefault;\n" + + "\n" + + "@NNBDReturn\n" + + "@NNBDParam\n" + + "@NNBDField\n" + + "@NonNullByDefault({ DefaultLocation.RETURN_TYPE, DefaultLocation.PARAMETER, DefaultLocation.FIELD })\n" + + "abstract class TestRedundantOnSame {\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NonNullByDefault({ DefaultLocation.RETURN_TYPE, DefaultLocation.PARAMETER })\n" + + " abstract class OnClass {\n" + + " }\n" + + "\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NonNullByDefault({ DefaultLocation.RETURN_TYPE, DefaultLocation.PARAMETER })\n" + + " Object onField = \"\";\n" + + "\n" + + " {\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NonNullByDefault({ DefaultLocation.RETURN_TYPE, DefaultLocation.PARAMETER })\n" + + " Object onLocal;\n" + + " }\n" + + "\n" + + " @NNBDReturn\n" + + " @NNBDParam\n" + + " @NonNullByDefault({ DefaultLocation.RETURN_TYPE, DefaultLocation.PARAMETER })\n" + + " abstract void onMethod();\n" + + "\n" + + " abstract void m(//\n" + + " @NNBDReturn //\n" + + " @NNBDParam //\n" + + " @NonNullByDefault({ DefaultLocation.RETURN_TYPE, DefaultLocation.PARAMETER }) //\n" + + " Object onParameter);\n" + + "}\n" + + "", + }, + customOptions, + "" + ); +} +public void testBug518839() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullApi"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES, "annotation.NonNullFields"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + + runConformTestWithLibs( + new String[] { + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullApi.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "\n" + + "@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})\n" + + "public @interface NonNullApi {\n" + + "}\n" + + "", + "annotation/NonNullFields.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "\n" + + "@TypeQualifierDefault(ElementType.FIELD)\n" + + "public @interface NonNullFields {\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + "annotation/TypeQualifierDefault.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "\n" + + "public @interface TypeQualifierDefault {\n" + + " ElementType[] value();\n" + + "}\n" + + "", + }, + customOptions, + "" + ); + runNegativeTestWithLibs( + new String[] { + "nn_api/NNApi.java", + "package nn_api;\n" + + "\n" + + "public class NNApi {\n" + + " public String f;\n" + + "\n" + + " public Object m(Object p) {\n" + + " if (p != null) { // warning\n" + + " //\n" + + " }\n" + + " return null; // warning\n" + + " }\n" + + "}\n" + + "", + "nn_api/package-info.java", + "@annotation.NonNullApi\n" + + "package nn_api;\n" + + "", + "nn_api_and_fields/NNApiAndFields.java", + "package nn_api_and_fields;\n" + + "\n" + + "public class NNApiAndFields {\n" + + " public String f; // warning 1\n" + + "\n" + + " public Object m(Object p) {\n" + + " if (p != null) { // warning 2\n" + + " //\n" + + " }\n" + + " return null; // warning 3\n" + + " }\n" + + "}\n" + + "", + "nn_api_and_fields/package-info.java", + "@annotation.NonNullApi\n" + + "@annotation.NonNullFields\n" + + "package nn_api_and_fields;\n" + + "", + "nn_fields/NNFields.java", + "package nn_fields;\n" + + "\n" + + "public class NNFields {\n" + + " public String f; // warning\n" + + "\n" + + " public Object m(Object p) {\n" + + " if (p != null) {\n" + + " //\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n" + + "", + "nn_fields/package-info.java", + "@annotation.NonNullFields\n" + + "package nn_fields;\n" + + "", + }, + customOptions, + "----------\n" + + "1. ERROR in nn_api\\NNApi.java (at line 7)\n" + + " if (p != null) { // warning\n" + + " ^\n" + + "Redundant null check: The variable p is specified as @NonNull\n" + + "----------\n" + + "2. ERROR in nn_api\\NNApi.java (at line 10)\n" + + " return null; // warning\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "----------\n" + + "1. ERROR in nn_api_and_fields\\NNApiAndFields.java (at line 4)\n" + + " public String f; // warning 1\n" + + " ^\n" + + "The @NonNull field f may not have been initialized\n" + + "----------\n" + + "2. ERROR in nn_api_and_fields\\NNApiAndFields.java (at line 7)\n" + + " if (p != null) { // warning 2\n" + + " ^\n" + + "Redundant null check: The variable p is specified as @NonNull\n" + + "----------\n" + + "3. ERROR in nn_api_and_fields\\NNApiAndFields.java (at line 10)\n" + + " return null; // warning 3\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "----------\n" + + "1. ERROR in nn_fields\\NNFields.java (at line 4)\n" + + " public String f; // warning\n" + + " ^\n" + + "The @NonNull field f may not have been initialized\n" + + "----------\n" + ); +} +public void testBug518839_BTB() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_NULLABLE_ANNOTATION_NAME, "annotation.Nullable"); + customOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "annotation.NonNull"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_NAME, "annotation.NonNullApi"); + customOptions.put(JavaCore.COMPILER_NONNULL_BY_DEFAULT_ANNOTATION_SECONDARY_NAMES, "annotation.NonNullFields"); + customOptions.put(JavaCore.COMPILER_PB_DEAD_CODE, JavaCore.IGNORE); + + runConformTestWithLibs( + new String[] { + "annotation/NonNull.java", + "package annotation;\n" + + "\n" + + "public @interface NonNull {\n" + + "}\n" + + "", + "annotation/NonNullApi.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "\n" + + "@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})\n" + + "public @interface NonNullApi {\n" + + "}\n" + + "", + "annotation/NonNullFields.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "\n" + + "@TypeQualifierDefault(ElementType.FIELD)\n" + + "public @interface NonNullFields {\n" + + "}\n" + + "", + "annotation/Nullable.java", + "package annotation;\n" + + "\n" + + "public @interface Nullable {\n" + + "}\n" + + "", + "annotation/TypeQualifierDefault.java", + "package annotation;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "\n" + + "public @interface TypeQualifierDefault {\n" + + " ElementType[] value();\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + // compile with jdt annotations, so no warnings are created. + runConformTestWithLibs( + false, + new String[] { + "nn_api/NNApi.java", + "package nn_api;\n" + + "\n" + + "public class NNApi {\n" + + " public String f;\n" + + "\n" + + " public Object m(Object p) {\n" + + " if (p != null) { // warning\n" + + " //\n" + + " }\n" + + " return null; // warning\n" + + " }\n" + + "}\n" + + "", + "nn_api/package-info.java", + "@annotation.NonNullApi\n" + + "package nn_api;\n" + + "", + "nn_api_and_fields/NNApiAndFields.java", + "package nn_api_and_fields;\n" + + "\n" + + "public class NNApiAndFields {\n" + + " public String f; // warning 1\n" + + "\n" + + " public Object m(Object p) {\n" + + " if (p != null) { // warning 2\n" + + " //\n" + + " }\n" + + " return null; // warning 3\n" + + " }\n" + + "}\n" + + "", + "nn_api_and_fields/package-info.java", + "@annotation.NonNullApi\n" + + "@annotation.NonNullFields\n" + + "package nn_api_and_fields;\n" + + "", + "nn_fields/NNFields.java", + "package nn_fields;\n" + + "\n" + + "public class NNFields {\n" + + " public String f; // warning\n" + + "\n" + + " public Object m(Object p) {\n" + + " if (p != null) {\n" + + " //\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n" + + "", + "nn_fields/package-info.java", + "@annotation.NonNullFields\n" + + "package nn_fields;\n" + + "", + }, + getCompilerOptions(), + "" + ); + runNegativeTestWithLibs( + new String[] { + "btbtest/BTBTest.java", + "package btbtest;\n" + + "\n" + + "import nn_api.NNApi;\n" + + "import nn_api_and_fields.NNApiAndFields;\n" + + "import nn_fields.NNFields;\n" + + "\n" + + "public class BTBTest {\n" + + " void api(NNApi p) {\n" + + " if (p.m(null) == null) { // 2 warnings\n" + + " }\n" + + " p.f = null;\n" + + " }\n" + + "\n" + + " void apiAndFields(NNApiAndFields p) {\n" + + " if (p.m(null) == null) { // 2 warnings\n" + + " }\n" + + " p.f = null; // warning\n" + + " }\n" + + "\n" + + " void fields(NNFields p) {\n" + + " if (p.m(null) == null) {\n" + + " }\n" + + " p.f = null; // warning\n" + + " }\n" + + "}\n" + + "", + }, + customOptions, + "----------\n" + + "1. ERROR in btbtest\\BTBTest.java (at line 9)\n" + + " if (p.m(null) == null) { // 2 warnings\n" + + " ^^^^^^^^^\n" + + "Null comparison always yields false: The method m(Object) cannot return null\n" + + "----------\n" + + "2. ERROR in btbtest\\BTBTest.java (at line 9)\n" + + " if (p.m(null) == null) { // 2 warnings\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "3. ERROR in btbtest\\BTBTest.java (at line 15)\n" + + " if (p.m(null) == null) { // 2 warnings\n" + + " ^^^^^^^^^\n" + + "Null comparison always yields false: The method m(Object) cannot return null\n" + + "----------\n" + + "4. ERROR in btbtest\\BTBTest.java (at line 15)\n" + + " if (p.m(null) == null) { // 2 warnings\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Object\' but the provided value is null\n" + + "----------\n" + + "5. ERROR in btbtest\\BTBTest.java (at line 17)\n" + + " p.f = null; // warning\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "6. ERROR in btbtest\\BTBTest.java (at line 23)\n" + + " p.f = null; // warning\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + ); +} +public void testBug531040() { + if (this.complianceLevel < ClassFileConstants.JDK10) + return; + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import java.util.*;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "public class Test {\n" + + " void test() {\n" + + " var list1 = new ArrayList<@NonNull String>();\n" + + " list1.add(null);\n" + + " @NonNull String val = \"\";\n" + + " var list2 = getList(val);\n" + + " list2.add(null);\n" + + " }\n" + + " List getList(T... in) {\n" + + " return Arrays.asList(in);\n" + + " }\n" + + "}\n" + + "" + }, + "----------\n" + + "1. ERROR in Test.java (at line 8)\n" + + " list1.add(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "2. ERROR in Test.java (at line 11)\n" + + " list2.add(null);\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull String\' but the provided value is null\n" + + "----------\n" + + "3. WARNING in Test.java (at line 13)\n" + + " List getList(T... in) {\n" + + " ^^\n" + + "Type safety: Potential heap pollution via varargs parameter in\n" + + "----------\n" + ); +} +public void testBug533339() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class Test {\n" + + "\n" + + " interface Foo {\n" + + "\n" + + " @Nullable\n" + + " String getString();\n" + + " }\n" + + "\n" + + " class Bar {\n" + + "\n" + + " Bar(@NonNull String s) {\n" + + " }\n" + + " }\n" + + "\n" + + " Bar hasWarning(Foo foo) {\n" + + " @NonNull String s = checkNotNull(foo.getString());\n" + + " return new Bar(s);// Null type mismatch: required '@NonNull String' but the provided value is inferred as @Nullable\n" + + " }\n" + + "\n" + + " Bar hasNoWarning(Foo foo) {\n" + + " return new Bar(checkNotNull(foo.getString()));// no warning when s is inlined\n" + + " }\n" + + " static T checkNotNull(T reference) {\n" + + " if (reference == null) throw new NullPointerException();\n" + + " return reference;\n" + + " }\n" + + "}\n" + }; + runner.classLibraries = this.LIBS; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in Test.java (at line 19)\n" + + " @NonNull String s = checkNotNull(foo.getString());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n" + + "2. WARNING in Test.java (at line 24)\n" + + " return new Bar(checkNotNull(foo.getString()));// no warning when s is inlined\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +public void testBug534516() { + runConformTestWithLibs( + new String[] { + "testbug/nullannotations/Utility.java", + "package testbug.nullannotations;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Utility {\n" + + "\n" + + " public static String massageString(final String input) {\n" + + " return input + \" .\";\n" + + " }\n" + + "\n" + + " private Utility() {\n" + + "\n" + + " }\n" + + "\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); + runConformTestWithLibs( + false, + new String[] { + "testbug/nullannotations/ApplyIfNonNullElseGetBugDemo.java", + "package testbug.nullannotations;\n" + + "\n" + + "import java.util.function.Function;\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class ApplyIfNonNullElseGetBugDemo {\n" + + "\n" + + " public static U applyIfNonNullElse(@Nullable T value, @NonNull Function<@NonNull ? super T, ? extends U> function, U fallbackValue) {\n" + + " if (value != null)\n" + + " return function.apply(value);\n" + + " return fallbackValue;\n" + + " }\n" + + "\n" + + " public static void main(final @Nullable String[] args) {\n" + + " final @Nullable String arg = args.length == 0 ? null : args[0];\n" + + " System.out.println(applyIfNonNullElse(arg, Utility::massageString, \"\")); // incorrect warning here\n" + + " }\n" + + "\n" + + "}\n" + + "", + }, + getCompilerOptions(), + "" + ); +} +public void testBug536459() { + runConformTestWithLibs( + new String[] { + "X.java", + "import org.eclipse.jdt.annotation.Nullable;\n" + + "\n" + + "public class X {\n" + + " static void x() {\n" + + " @Nullable String x1 = \"\";\n" + + " @Nullable String[] x2 = { \"\" };\n" + + " }\n" + + "}\n" + }, + getCompilerOptions(), + ""); +} +public void testBug536555() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); + runner.testFiles = + new String[] { + "Foo.java", + "public class Foo\n" + + "{\n" + + " /** Test {@link #foo(boolean)}. */\n" + + " public static final String TEST = \"foo\";\n" + + "\n" + + " public void foo(@SuppressWarnings(TEST) final boolean test)\n" + + " {\n" + + " System.out.println(test);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in Foo.java (at line 6)\n" + + " public void foo(@SuppressWarnings(TEST) final boolean test)\n" + + " ^^^^\n" + + "Unsupported @SuppressWarnings(\"foo\")\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +public void testBug540264() { + runNegativeTest( + true, + new String[] { + "example/Example.java", + "package example;\n" + + "\n" + + "public abstract class Example {\n" + + " void f() {\n" + + " for (X.Y entry : x) {\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + this.LIBS, + getCompilerOptions(), + "----------\n" + + "1. ERROR in example\\Example.java (at line 5)\n" + + " for (X.Y entry : x) {\n" + + " ^\n" + + "X cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in example\\Example.java (at line 5)\n" + + " for (X.Y entry : x) {\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in example\\Example.java (at line 5)\n" + + " for (X.Y entry : x) {\n" + + " ^\n" + + "x cannot be resolved to a variable\n" + + "----------\n", + JavacTestOptions.DEFAULT + ); +} +public void testBug542707_1() { + if (!checkPreviewAllowed()) return; // switch expression + // switch expression has a functional type with interesting type inference and various null issues: + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, JavaCore.ENABLED); + runner.customOptions.put(JavaCore.COMPILER_PB_REPORT_PREVIEW_FEATURES, JavaCore.IGNORE); + runner.classLibraries = this.LIBS; + runner.testFiles = new String[] { + "X.java", + "import org.eclipse.jdt.annotation.*;\n" + + "import java.util.function.*;\n" + + "interface IN0 {}\n" + + "interface IN1 extends IN0 {}\n" + + "interface IN2 extends IN0 {}\n" + + "public class X {\n" + + " @NonNull IN1 n1() { return new IN1() {}; }\n" + + " IN2 n2() { return null; }\n" + + " void m(@NonNull Supplier<@NonNull M> m2) { }\n" + + " void testSw(int i) {\n" + + " m(switch(i) {\n" + + " case 1 -> this::n1;\n" + + " case 2 -> () -> n1();\n" + + " case 3 -> null;\n" + + " case 4 -> () -> n2();\n" + + " default -> this::n2; });\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 14)\n" + + " case 3 -> null;\n" + + " ^^^^\n" + + "Null type mismatch: required \'@NonNull Supplier<@NonNull IN0>\' but the provided value is null\n" + + "----------\n" + + "2. WARNING in X.java (at line 15)\n" + + " case 4 -> () -> n2();\n" + + " ^^^^\n" + + "Null type safety (type annotations): The expression of type \'IN2\' needs unchecked conversion to conform to \'@NonNull IN0\'\n" + + "----------\n" + + "3. WARNING in X.java (at line 16)\n" + + " default -> this::n2; });\n" + + " ^^^^^^^^\n" + + "Null type safety at method return type: Method descriptor Supplier.get() promises \'@NonNull IN0\' but referenced method provides \'IN2\'\n" + + "----------\n"; + runner.runNegativeTest(); +} +public void testBug499714() { + runNegativeTestWithLibs( + new String[] { + "Type.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface Type<@Nullable K> {\n" + + " K get();\n" + + "\n" + + " static <@Nullable T> void x(Type t) {\n" + + " t.get().toString();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Type.java (at line 7)\n" + + " t.get().toString();\n" + + " ^^^^^^^\n" + + "Potential null pointer access: The method get() may return null\n" + + "----------\n"); +} +public void testBug482242_simple() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "public class Test {\n" + + " static void dangerous(List list) {\n" + + " list.add(null);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " List<@NonNull String> l = new ArrayList<>();\n" + + " dangerous(l);\n" + + " for (String string : l)\n" + + " System.out.println(string.toLowerCase());\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in Test.java (at line 9)\n" + + " dangerous(l);\n" + + " ^\n" + + "Unsafe null type conversion (type annotations): The value of type \'List<@NonNull String>\' is made accessible using the less-annotated type \'List\'\n" + + "----------\n"); +} +public void testBug482242_intermediate() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import java.util.*;\n" + + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " ArrayList<@NonNull String> list = new ArrayList<>();\n" + + " collect(list, null);\n" + + " for (String s : list)\n" + + " System.out.println(s.toUpperCase());\n" + + " }\n" + + " static void collect(List<@NonNull String> list, String string) {\n" + + " list.add(string); // (1)\n" + + " insert(list, string); // (2)\n" + + " }\n" + + " static void insert(List l, String s) {\n" + + " l.add(s);\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. WARNING in Test.java (at line 12)\n" + + " list.add(string); // (1)\n" + + " ^^^^^^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'@NonNull String\'\n" + + "----------\n" + + "2. ERROR in Test.java (at line 13)\n" + + " insert(list, string); // (2)\n" + + " ^^^^\n" + + "Unsafe null type conversion (type annotations): The value of type \'List<@NonNull String>\' is made accessible using the less-annotated type \'List\'\n" + + "----------\n"); +} +public void testBug482242_annotatedTypeVariable() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface List {\n" + + " void add(T elem);" + + "}\n" + + "public class Test {\n" + + " public static void test(List<@NonNull String> list) {\n" + + " collect(list, null);\n" + + " }\n" + + " static void collect(List<@NonNull String> list, String string) {\n" + + " insert(list, string);\n" + + " }\n" + + " static void insert(List l, String s) {\n" + // type error at declaration site, no need to signal at the call site + " l.add(s);\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in Test.java (at line 12)\n" + + " static void insert(List l, String s) {\n" + + " ^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'? super String\' is not a valid substitute for the type parameter \'T extends @NonNull Object\'\n" + + "----------\n" + + "2. WARNING in Test.java (at line 13)\n" + + " l.add(s);\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'capture#of ? super String\'\n" + + "----------\n"); +} +public void testBug482242_boundedWildcard() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_ANNOTATED_TYPE_ARGUMENT_TO_UNANNOTATED, JavaCore.ERROR); + runNegativeTestWithLibs( + new String[] { + "Test.java", + "import org.eclipse.jdt.annotation.*;\n" + + "\n" + + "interface List {\n" + + " void add(T elem);" + + "}\n" + + "public class Test {\n" + + " public static void test(List<@NonNull String> list) {\n" + + " collect(list, null);\n" + + " }\n" + + " static void collect(List<@NonNull String> list, String string) {\n" + + " insert(list, string);\n" + + " }\n" + + " static void insert(List l, String s) {\n" + + " l.add(s);\n" + + " }\n" + + "}\n" + }, + options, + "----------\n" + + "1. ERROR in Test.java (at line 10)\n" + + " insert(list, string);\n" + + " ^^^^\n" + + "Null type mismatch (type annotations): required \'List\' but this expression has type \'List<@NonNull String>\'\n" + + "----------\n" + + "2. ERROR in Test.java (at line 12)\n" + + " static void insert(List l, String s) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Null constraint mismatch: The type \'? super @Nullable String\' is not a valid substitute for the type parameter \'T extends @NonNull Object\'\n" + + "----------\n" + + "3. WARNING in Test.java (at line 13)\n" + + " l.add(s);\n" + + " ^\n" + + "Null type safety (type annotations): The expression of type \'String\' needs unchecked conversion to conform to \'capture#of ? super @Nullable String\'\n" + + "----------\n"); +} +public void testBug560213source() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.classLibraries = this.LIBS; + runner.testFiles = new String[] { + "nullEnumSort/MyEnum.java", + "package nullEnumSort;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "enum MyEnum {\n" + + " x\n" + + "}\n", + "nullEnumSort/EnumProblem.java", + "package nullEnumSort;\n" + + "\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class EnumProblem {\n" + + " void f(List list) {\n" + + " Collections.sort(list);\n" + + " }\n" + + "\n}" + }; + runner.runConformTest(); +} +public void testBug560213binary() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.testFiles = new String[] { + "nullEnumSort/MyEnum.java", + "package nullEnumSort;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "enum MyEnum {\n" + + " x\n" + + "}\n" + }; + runner.classLibraries = this.LIBS; + runner.runConformTest(); + + runner.shouldFlushOutputDirectory = false; + runner.testFiles = new String[] { + "nullEnumSort/EnumProblem.java", + "package nullEnumSort;\n" + + "\n" + + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class EnumProblem {\n" + + " void f(List list) {\n" + + " Collections.sort(list);\n" + + " }\n" + + "\n}" + }; + runner.runConformTest(); +} +public void testBug560310() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.testFiles = + new String[] { + "confusing/Confusing.java", + "package confusing;\n" + + "\n" + + "import java.util.ArrayList;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "public abstract class Confusing {\n" + + " abstract int unannotated(ArrayList list);\n" + + "\n" + + " @NonNullByDefault\n" + + " public void f(boolean x) {\n" + + " ArrayList list = x ? null : new ArrayList<>();\n" + + "\n" + + " while (true) {\n" + + " unannotated(list);\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.classLibraries = this.LIBS; + runner.javacTestOptions = Excuse.EclipseHasSomeMoreWarnings; + runner.expectedCompilerLog = + "----------\n" + + "1. INFO in confusing\\Confusing.java (at line 15)\n" + + " unannotated(list);\n" + + " ^^^^\n" + + "Unsafe null type conversion (type annotations): The value of type \'ArrayList<@NonNull String>\' is made accessible using the less-annotated type \'ArrayList\'\n" + + "----------\n"; + runner.runWarningTest(); +} +public void testBug560310try_finally() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.testFiles = + new String[] { + "confusing/Confusing.java", + "package confusing;\n" + + "\n" + + "import java.util.ArrayList;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "public abstract class Confusing {\n" + + " abstract int unannotated(ArrayList list);\n" + + "\n" + + " @NonNullByDefault\n" + + " public void f(boolean x) {\n" + + " ArrayList list = x ? null : new ArrayList<>();\n" + + "\n" + + " try {\n" + + " unannotated(list);\n" + + " } finally {\n" + + " unannotated(list);\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.classLibraries = this.LIBS; + runner.javacTestOptions = Excuse.EclipseHasSomeMoreWarnings; + runner.expectedCompilerLog = + "----------\n" + + "1. INFO in confusing\\Confusing.java (at line 15)\n" + + " unannotated(list);\n" + + " ^^^^\n" + + "Unsafe null type conversion (type annotations): The value of type \'ArrayList<@NonNull String>\' is made accessible using the less-annotated type \'ArrayList\'\n" + + "----------\n" + + "2. INFO in confusing\\Confusing.java (at line 17)\n" + + " unannotated(list);\n" + + " ^^^^\n" + + "Unsafe null type conversion (type annotations): The value of type \'ArrayList<@NonNull String>\' is made accessible using the less-annotated type \'ArrayList\'\n" + + "----------\n"; + runner.runWarningTest(); +} +public void testBug562347_561280c9() { + runNegativeTestWithLibs( + new String[] { + "Example.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "@NonNullByDefault\n" + + "public class Example {\n" + + " static X f(X x) {\n" + + " return x;\n" + + " }\n" + + "\n" + + " public void g() {\n" + + " Object x0, x1, x2, x3, x4, x5, x6, x7, x8, x9;\n" + + " Object x10, x11, x12, x13, x14, x15, x16, x17, x18, x19;\n" + + " Object x20, x21, x22, x23, x24, x25, x26, x27, x28, x29;\n" + + " Object x30, x31, x32, x33, x34, x35, x36, x37, x38, x39;\n" + + " Object x40, x41, x42, x43, x44, x45, x46, x47, x48, x49;\n" + + " Object x50, x51, x52, x53, x54, x55, x56, x57, x58, x59;\n" + + " Object x60;\n" + + " Object x61;\n" + + " for (Map.Entry entry : new HashMap().entrySet()) {\n" + + " if (f(entry.getKey()) != null) {\n" + + " continue;\n" + + " }\n" + + " String x = \"asdf\";\n" + + " x.hashCode();\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + }, + getCompilerOptions(), + "----------\n" + + "1. ERROR in Example.java (at line 22)\n" + + " if (f(entry.getKey()) != null) {\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Redundant null check: comparing \'@NonNull String\' against null\n" + + "----------\n" + + "2. WARNING in Example.java (at line 25)\n" + + " String x = \"asdf\";\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"); +} +public void testBug562347() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "NotificationListingHolder.java", + "@SuppressWarnings(\"unused\")\n" + + "public final class NotificationListingHolder {\n" + + " private String f1,f2,f3,f4;\n" + + "\n" + + " private void setupActionButtons() {\n" + + " Test listItemNotificationsBinding2;\n" + + " boolean z;\n" + + " String a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47,a48,a49,a50,a51,a52,a53,a54,a55,a56,a57,a58;\n" + + " if (z) {\n" + + " String button4 = listItemNotificationsBinding2.field;\n" + + " if (listItemNotificationsBinding2 != null) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class Test {\n" + + " public final String field;\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in NotificationListingHolder.java (at line 9)\n" + + " if (z) {\n" + + " ^\n" + + "The local variable z may not have been initialized\n" + + "----------\n" + + "2. ERROR in NotificationListingHolder.java (at line 10)\n" + + " String button4 = listItemNotificationsBinding2.field;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The local variable listItemNotificationsBinding2 may not have been initialized\n" + + "----------\n" + + "3. ERROR in NotificationListingHolder.java (at line 11)\n" + + " if (listItemNotificationsBinding2 != null) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The local variable listItemNotificationsBinding2 may not have been initialized\n" + + "----------\n" + + "4. ERROR in NotificationListingHolder.java (at line 11)\n" + + " if (listItemNotificationsBinding2 != null) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant null check: The variable listItemNotificationsBinding2 cannot be null at this location\n" + + "----------\n" + + "5. ERROR in NotificationListingHolder.java (at line 19)\n" + + " public final String field;\n" + + " ^^^^^\n" + + "The blank final field field may not have been initialized\n" + + "----------\n"; + runner.classLibraries = this.LIBS; + runner.runNegativeTest(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NumericTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NumericTest.java new file mode 100644 index 0000000000..f5b5277364 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NumericTest.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2005, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class NumericTest extends AbstractRegressionTest { + +public NumericTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public void test001() { + this.runConformTest(new String[] { + "p/B.java", + "package p;\n" + + "public class B {\n" + + " public static void main(String[] args) {\n" + + " int offset = -8;\n" + + " int temp = 0 - offset;\n" + + " offset = 0 - offset; // This is the problem line\n" + + " System.out.println(\"offset: \" + offset);\n" + + " System.out.println(\"temp: \" + temp);\n" + + " if (offset != temp ) {\n" + + " System.err.println(\"offset (\" + offset + \") should be equal to temp (\" + temp + \").\");\n" + + " System.exit(-1);\n" + + " }\n" + + " }\n" + + "}\n", + }); +} + +public void test002() { + this.runConformTest(new String[] { + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " int clockend = 0;\n" + + " clockend += 128;\n" + + " if(clockend < 0) {\n" + + " System.out.println(clockend);\n" + + " System.exit(-1);\n" + + " }\n" + + " }\n" + + "}\n", + }); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133738 +public void test003() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " int i1 = -2147483648;\n" + + " int i2 = -(2147483648);\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int i2 = -(2147483648);\n" + + " ^^^^^^^^^^^^\n" + + "The literal 2147483648 of type int is out of range \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=133738 +public void test004() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " long l1 = -9223372036854775808L;\n" + + " long l2 = -(9223372036854775808L);\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " long l2 = -(9223372036854775808L);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "The literal 9223372036854775808L of type long is out of range \n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=232814 +public void test005() { + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int result;\n" + + " if (130 != (result = testShort1())) System.out.println(\"failed-testShort1():\" + result);\n" + + " if (130 != (result = testShort2())) System.out.println(\"failed-testShort2():\" + result);\n" + + " if (130 != (result = testInt1())) System.out.println(\"failed-testInt1():\" + result);\n" + + " if (130 != (result = testInt2())) System.out.println(\"failed-testInt2():\" + result);\n" + + " if (30 != (result = testByte1())) System.out.println(\"failed-testByte1():\" + result);\n" + + " if (30 != (result = testByte2())) System.out.println(\"failed-testByte2():\" + result);\n" + + " System.out.println(\"done\");\n" + + " }\n" + + " static int testShort1() {\n" + + " short min = Short.MIN_VALUE;\n" + + " int num = -32638;\n" + + " return num = num - min;\n" + + " }\n" + + " static int testShort2() {\n" + + " final short min = Short.MIN_VALUE;\n" + + " int num = -32638;\n" + + " return num = num - min;\n" + + " }\n" + + " static int testInt1() {\n" + + " short min = Short.MIN_VALUE;\n" + + " int num = -32638;\n" + + " return num = num - min;\n" + + " }\n" + + " static int testInt2() {\n" + + " final short min = Short.MIN_VALUE;\n" + + " int num = -32638;\n" + + " return num = num - min;\n" + + " } \n" + + " static int testByte1() {\n" + + " byte min = Byte.MIN_VALUE;\n" + + " int num = -98;\n" + + " return num = num - min;\n" + + " }\n" + + " static int testByte2() {\n" + + " final byte min = Byte.MIN_VALUE;\n" + + " int num = -98;\n" + + " return num = num - min;\n" + + " } \n" + + "}\n", + }, + "done"); +} +public static Class testClass() { + return NumericTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/OverloadResolutionTest8.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/OverloadResolutionTest8.java new file mode 100644 index 0000000000..d7a307d6c4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/OverloadResolutionTest8.java @@ -0,0 +1,2725 @@ +/******************************************************************************* + * Copyright (c) 2013, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) + * Bug 425156 - [1.8] Lambda as an argument is flagged with incompatible error + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; +@SuppressWarnings({ "rawtypes" }) +public class OverloadResolutionTest8 extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test007"}; +// TESTS_NUMBERS = new int[] { 50 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public OverloadResolutionTest8(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} +public static Class testClass() { + return OverloadResolutionTest8.class; +} + +public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo(int [] a);\n" + + "}\n" + + "interface J {\n" + + " int foo(int a);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo((a)->a.length));\n" + + " }\n" + + " static String foo(I i) {\n" + + " return(\"foo(I)\");\n" + + " }\n" + + " static String foo(J j) {\n" + + " return(\"foo(J)\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " System.out.println(foo((a)->a.length));\n" + + " ^^^\n" + + "The method foo(I) is ambiguous for the type X\n" + + "----------\n" + ); +} +public void test002() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"goo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final boolean x = true;\n" + + " goo(()-> goo((I)null));\n" + + " }\n" + + " int f() {\n" + + " final boolean x = true;\n" + + " while (x);\n" + + " }\n" + + "}\n", + }, + "goo(I)"); +} +public void test003() { + this.runConformTest( + new String[] { + "X.java", + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static final boolean f = true;\n" + + " static void goo(J j) {\n" + + " System.out.println(\"goo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final boolean x = true;\n" + + " goo(()-> { \n" + + " final boolean y = true;\n" + + " while (y); \n" + + " });\n" + + " goo(()-> { \n" + + " while (x); \n" + + " });\n" + + " goo(()-> { \n" + + " while (f); \n" + + " });\n" + + " }\n" + + "}\n", + }, + "goo(J)\n" + + "goo(J)\n" + + "goo(J)"); +} + +public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static boolean f = true;\n" + + " static void goo(J j) {\n" + + " System.out.println(\"goo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " boolean x = true;\n" + + " goo(()-> { \n" + + " boolean y = true;\n" + + " while (y); \n" + + " });\n" + + " goo(()-> { \n" + + " while (x); \n" + + " });\n" + + " goo(()-> { \n" + + " while (f); \n" + + " });\n" + + " }\n" + + "}\n", + }, + // none of the lambdas is compatible because none is value-compatible, whereas foo() needs to return int. + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " goo(()-> { \n" + + " ^^^\n" + + "The method goo(J) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n2. ERROR in X.java (at line 15)\n" + + " goo(()-> { \n" + + " ^^^\n" + + "The method goo(J) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " goo(()-> { \n" + + " ^^^\n" + + "The method goo(J) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n"); +} +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " final boolean f = true;\n" + + " static void goo(J j) {\n" + + " System.out.println(\"goo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final boolean x = true;\n" + + " goo(()-> { \n" + + " final boolean y = true;\n" + + " while (y); \n" + + " });\n" + + " goo(()-> { \n" + + " while (x); \n" + + " });\n" + + " goo(()-> { \n" + + " while (f); \n" + + " });\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " goo(()-> { \n" + + " ^^^\n" + + "The method goo(J) in the type X is not applicable for the arguments (() -> {})\n" + // because lambda has errors -> not valueCompatible + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " while (f); \n" + + " ^\n" + + "Cannot make a static reference to the non-static field f\n" + + "----------\n"); +} +public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static interface StringToInt {\n" + + " int stoi(String s);\n" + + " }\n" + + " public static interface ReduceInt {\n" + + " int reduce(int a, int b);\n" + + " }\n" + + " void foo(StringToInt s) { }\n" + + " void bar(ReduceInt r) { }\n" + + " void bar() {\n" + + " bar((int x, int y) -> x+y); //SingleVariableDeclarations are OK\n" + + " foo(s -> s.length());\n" + + " foo((s) -> s.length());\n" + + " foo((String s) -> s.length()); //SingleVariableDeclaration is OK\n" + + " bar((x, y) -> x+y);\n" + + " }\n" + + "}\n", + }, + ""); +} +public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(J j) {\n" + + " System.out.println(\"goo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(()-> 10); \n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " goo(()-> 10); \n" + + " ^^^\n" + + "The method goo(J) in the type X is not applicable for the arguments (() -> {})\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " goo(()-> 10); \n" + + " ^^\n" + + "Void methods cannot return a value\n" + + "----------\n"); +} +public void test008() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo();\n" + + "}\n" + + "interface J {\n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(()->null));\n" + + " }\n" + + " static String foo(I i) {\n" + + " return(\"foo(I)\");\n" + + " }\n" + + " static String foo(J j) {\n" + + " return(\"foo(J)\");\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test009() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(()-> {}));\n" + + " }\n" + + " static String foo(I i) {\n" + + " return(\"foo(I)\");\n" + + " }\n" + + " static String foo(J j) {\n" + + " return(\"foo(J)\");\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test010() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(()-> foo(()->null)));\n" + + " }\n" + + " static String foo(I i) {\n" + + " return(\"foo(I)\");\n" + + " }\n" + + " static String foo(J j) {\n" + + " return(\"foo(J)\");\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test011() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "interface J {\n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(()-> \"Hello\" ));\n" + + " }\n" + + " static String foo(I i) {\n" + + " return(\"foo(I)\");\n" + + " }\n" + + " static String foo(J j) {\n" + + " return(\"foo(J)\");\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test012() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "interface J {\n" + + " String foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(()-> 1234 ));\n" + + " }\n" + + " static String foo(I i) {\n" + + " return(\"foo(I)\");\n" + + " }\n" + + " static String foo(J j) {\n" + + " return(\"foo(J)\");\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test013() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "interface J {\n" + + " Integer foo();\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(()-> 1234 ));\n" + + " }\n" + + " static String foo(I i) {\n" + + " return(\"foo(I)\");\n" + + " }\n" + + " static String foo(J j) {\n" + + " return(\"foo(J)\");\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test014() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " \n" + + " static void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " \n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " foo(()-> new Integer(10));\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test015() { + this.runConformTest( + new String[] { + "X.java", + "interface J {\n" + + " int foo();\n" + + "}\n" + + "interface I {\n" + + " Integer foo();\n" + + "}\n" + + "public class X {\n" + + " \n" + + " static void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " \n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " foo(()-> new Integer(10));\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test016() { + this.runConformTest( + new String[] { + "X.java", + "interface O {\n" + + " Object foo();\n" + + "}\n" + + "interface S {\n" + + " String foo();\n" + + "}\n" + + "interface I {\n" + + " O foo();\n" + + "}\n" + + "interface J {\n" + + " S foo();\n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(()-> ()-> \"String\");\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test017() { + this.runConformTest( + new String[] { + "X.java", + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(()-> new Integer(10));\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test018() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " X [] foo(int x);\n" + + "}\n" + + "public class X {\n" + + " static void foo(I x) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " I i = X[]::new;\n" + + " public static void main(String[] args) {\n" + + " foo(X[]::new);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test019() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "public class X {\n" + + " static void foo(I x) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " I i = X[]::new;\n" + + " public static void main(String[] args) {\n" + + " foo(X[]::new);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} + +public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Y foo(int x);\n" + + "}\n" + + "interface J {\n" + + " Y foo();\n" + + "}\n" + + "class Y {\n" + + " Y() {\n" + + " }\n" + + " \n" + + " Y(int x) {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " }\n" + + " static void foo(J j) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(Y::new);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " foo(Y::new);\n" + + " ^^^\n" + + "The method foo(I) is ambiguous for the type X\n" + + "----------\n"); +} +public void test021() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Y foo(int x);\n" + + "}\n" + + "interface J {\n" + + " Y foo();\n" + + "}\n" + + "class Y {\n" + + " private Y() {\n" + + " }\n" + + " \n" + + " Y(int x) {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(Y::new);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test022() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Y foo(int x);\n" + + "}\n" + + "interface J {\n" + + " Y foo();\n" + + "}\n" + + "class Y {\n" + + " Y(float f) {\n" + + " System.out.println(\"Y(float)\");\n" + + " }\n" + + " \n" + + " Y(int x) {\n" + + " System.out.println(\"Y(int)\");\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " i.foo(10);\n" + + " }\n" + + " static void foo(J j) {\n" + + " j.foo();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(Y::new);\n" + + " }\n" + + "}\n", + }, + "Y(int)"); +} +public void test023() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Y foo(int x);\n" + + "}\n" + + "interface J {\n" + + " Y foo();\n" + + "}\n" + + "class Y {\n" + + " Y(int ... x) {\n" + + " }\n" + + " \n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " }\n" + + " static void foo(J j) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(Y::new);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " foo(Y::new);\n" + + " ^^^\n" + + "The method foo(I) is ambiguous for the type X\n" + + "----------\n"); +} +public void test024() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Y foo(int x);\n" + + "}\n" + + "interface J {\n" + + " Y foo(int x);\n" + + "}\n" + + "class Y {\n" + + " Y(int x) {\n" + + " }\n" + + " \n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " }\n" + + " static void foo(J j) {\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(Y::new);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " foo(Y::new);\n" + + " ^^^\n" + + "The method foo(I) is ambiguous for the type X\n" + + "----------\n"); +} +public void test025() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Y foo(int x);\n" + + "}\n" + + "interface J {\n" + + " X foo(int x);\n" + + "}\n" + + "class Y extends X {\n" + + " Y(int x) {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(Y::new);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test026() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Y foo(int x);\n" + + "}\n" + + "interface J {\n" + + " X foo(int x);\n" + + "}\n" + + "class Y extends X {\n" + + " Y(int x) {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(Y::new);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 19)\n" + + " foo(Y::new);\n" + + " ^^^\n" + + "The method foo(I) is ambiguous for the type X\n" + + "----------\n"); +} +public void test027() { // javac bug: 8b115 complains of ambiguity here. + this.runConformTest( + false /* skipJavac */, + JavacTestOptions.Excuse.JavacDoesNotCompileCorrectSource, + new String[] { + "X.java", + "interface I {\n" + + " Y foo(int x);\n" + + "}\n" + + "interface J {\n" + + " X foo(int x);\n" + + "}\n" + + "class Y extends X {\n" + + " Y(int x) {\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(Y::new);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test028() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Y [] foo(int x);\n" + + "}\n" + + "interface J {\n" + + " X [] foo();\n" + + "}\n" + + "class Y extends X {\n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(Y []::new);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test029() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " Y [] foo(int x);\n" + + "}\n" + + "interface J {\n" + + " X [] foo();\n" + + "}\n" + + "class Y extends X {\n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(X []::new);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 17)\n" + + " foo(X []::new);\n" + + " ^^^\n" + + "The method foo(I) in the type X is not applicable for the arguments (X[]::new)\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " foo(X []::new);\n" + + " ^^^^^^^^^\n" + + "Constructed array X[] cannot be assigned to Y[] as required in the interface descriptor \n" + + "----------\n"); +} +public void test030() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Y [] foo(int x);\n" + + "}\n" + + "interface J {\n" + + " X [] foo(int x);\n" + + "}\n" + + "class Y extends X {\n" + + "}\n" + + "public class X {\n" + + " static void foo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void foo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(X []::new);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401850, [1.8][compiler] Compiler fails to type poly allocation expressions in method invocation contexts +public void test031() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X s) {\n" + + " System.out.println(\"foo(X)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new X<>());\n" + + " }\n" + + "}\n", + }, + "foo(X)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401850, [1.8][compiler] Compiler fails to type poly allocation expressions in method invocation contexts +// FAIL: we no longer see that both methods are applicable... +// inference starts with X#RAW, finds the second method, then infers the diamond to Object and sees that foo is not ambiguous +public void _test032() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X s, Object o) {\n" + + " System.out.println(\"foo(X)\");\n" + + " }\n" + + " void foo(X xs, String s) {\n" + + " System.out.println(\"foo(X)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new X<>(), \"Hello\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void foo(X xs, String s) {\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " new X().foo(new X<>(), \"Hello\");\n" + + " ^^^\n" + + "The method foo(X, Object) is ambiguous for the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401850, [1.8][compiler] Compiler fails to type poly allocation expressions in method invocation contexts +public void test033() { + this.runConformTest( + new String[] { + "X.java", + "class Y {}\n" + + "public class X extends Y {\n" + + " void foo(X s) {\n" + + " System.out.println(\"foo(X)\");\n" + + " }\n" + + " void foo(Y y) {\n" + + " System.out.println(\"foo(Y)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new X<>());\n" + + " }\n" + + "}\n", + }, + "foo(X)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=422050, [1.8][compiler] Overloaded method call with poly-conditional expression rejected by the compiler +public void test422050() { + this.runConformTest( + new String[] { + "X.java", + "interface I { \n" + + " int foo(); \n" + + "}\n" + + "interface J { \n" + + " double foo(); \n" + + "}\n" + + "public class X {\n" + + " static int foo(I i) {\n" + + " return 0;\n" + + " }\n" + + " static int foo(J j) {\n" + + " return 1;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(foo (() -> true ? 0 : 1));\n" + + " }\n" + + "}\n", + }, + "0"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400871, [1.8][compiler] Overhaul overload resolution to reconcile with JLS8 15.12.2 +public void test400871() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " static int foo() {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(X::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400871, [1.8][compiler] Overhaul overload resolution to reconcile with JLS8 15.12.2 +public void test400871a() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " int foo(int x);\n" + + "}\n" + + "class Y {\n" + + " int foo(int y) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " int foo(int x) {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400871, [1.8][compiler] Overhaul overload resolution to reconcile with JLS8 15.12.2 +public void test400871b() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " int foo(int x);\n" + + "}\n" + + "class Y {\n" + + " int foo(int y) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " int foo(int x) {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400871, [1.8][compiler] Overhaul overload resolution to reconcile with JLS8 15.12.2 +public void test400871c() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " int foo(int x);\n" + + "}\n" + + "class Y {\n" + + " int foo(String y) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " int foo(int x) {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 23)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400871, [1.8][compiler] Overhaul overload resolution to reconcile with JLS8 15.12.2 +public void test400871d() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " int foo(int x);\n" + + "}\n" + + "class Y {\n" + + " int foo(String y) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " int foo(int x) {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 23)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400871, [1.8][compiler] Overhaul overload resolution to reconcile with JLS8 15.12.2 +public void test4008712() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " int foo(int x);\n" + + "}\n" + + "class Y {\n" + + " int foo(String y) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " int foo(int x) {\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 23)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n"); +} +public void test4008712e() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " int foo(int x);\n" + + "}\n" + + "class Y {\n" + + " int foo(int y) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712f() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " int foo(int x);\n" + + "}\n" + + "class Y {\n" + + " int foo(int ... x) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n"); +} +public void test4008712g() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " int foo(int x);\n" + + "}\n" + + "class Y {\n" + + " private int foo(int x) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " private int foo(int x) {\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type Y is never used locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (new X()::foo)\n" + + "----------\n" + + "3. ERROR in X.java (at line 20)\n" + + " goo(new X()::foo);\n" + + " ^^^^^^^^^^^^\n" + + "The type X does not define foo(int) that is applicable here\n" + + "----------\n"); +} +public void test4008712h() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " int foo(int x);\n" + + "}\n" + + "class Y {\n" + + " public int foo(int x) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n"); +} +public void test4008712i() { // javac bug: 8b115 complains of ambiguity here. + this.runConformTest( + false /* skipJavac */, + JavacTestOptions.Excuse.JavacDoesNotCompileCorrectSource, + new String[] { + "X.java", + "interface I {\n" + + " void foo(int x);\n" + + "}\n" + + "interface J {\n" + + " int foo(int x);\n" + + "}\n" + + "class Y {\n" + + " public int foo(int x) {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712j() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String x);\n" + + "}\n" + + "interface J {\n" + + " int foo(String x);\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test4008712k() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String x);\n" + + "}\n" + + "interface J {\n" + + " String foo(String x);\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712l() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String x);\n" + + "}\n" + + "interface J {\n" + + " String foo(String x);\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712m() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String x);\n" + + "}\n" + + "interface J {\n" + + " String foo(String x);\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " public void foo() {}\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 21)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n"); +} +public void test4008712n() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String x);\n" + + "}\n" + + "interface J {\n" + + " String foo(String x);\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " public String foo(String s) { return null; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712o() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String x);\n" + + "}\n" + + "interface J {\n" + + " String foo(String x);\n" + + "}\n" + + "interface K {\n" + + " public T foo(T x);\n" + + "}\n" + + "class Y implements K {\n" + + " public Object foo(Object x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " public Object foo(Object s) { return null; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test4008712p() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String x);\n" + + "}\n" + + "interface J {\n" + + " String foo(String x);\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " public String foo(String s) { return null; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 21)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 21)\n" + + " goo(new X()::foo);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"); +} +public void test4008712q_raw() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "interface I {\n" + + " void foo(String x);\n" + + "}\n" + + "interface J {\n" + + " String foo(String x);\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n" + + "2. WARNING in X.java (at line 20)\n" + + " goo(new X()::foo);\n" + + " ^^^^^^^^^^^^\n" + + "Type safety: The method foo(Object) belongs to the raw type Y. References to generic type Y should be parameterized\n" + + "----------\n" + + "3. WARNING in X.java (at line 20)\n" + + " goo(new X()::foo);\n" + + " ^\n" + + "X is a raw type. References to generic type X should be parameterized\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.JavacCompilesIncorrectSource; + runner.runNegativeTest(); +} +public void test4008712q_diamond() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String x);\n" + + "}\n" + + "interface J {\n" + + " String foo(String x);\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X<>()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712r() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " String foo();\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X[0]::clone);\n" + + " }\n" + + "}\n", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " goo(new X[0]::clone);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.JavacCompilesIncorrectSource; + runner.runNegativeTest(); +} +public void test4008712s() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " String foo();\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X[0]::toString);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712t() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Class foo();\n" + + "}\n" + + "interface J {\n" + + " Object foo();\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X[0]::getClass);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test4008712u() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(I::clone);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 20)\n" + + " goo(I::clone);\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (I::clone)\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " goo(I::clone);\n" + + " ^^^^^^^^\n" + + "The type I does not define clone() that is applicable here\n" + + "----------\n"); +} +public void test4008712v() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " I i = () -> {};\n" + + " goo(i::hashCode);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712w() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "public class X extends Y {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " I i = () -> {};\n" + + " goo(i::clone);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 21)\n" + + " goo(i::clone);\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (i::clone)\n" + + "----------\n" + + "2. ERROR in X.java (at line 21)\n" + + " goo(i::clone);\n" + + " ^^^^^^^^\n" + + "The type I does not define clone() that is applicable here\n" + + "----------\n"); +} +public void test4008712x() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo(String x);\n" + + "}\n" + + "interface J {\n" + + " String foo(String x);\n" + + "}\n" + + "class Y {\n" + + " public T foo(T x) {\n" + + " return null;\n" + + " }\n" + + " private void foo() {}\n" + + "}\n" + + "public class X extends Y {\n" + + " public String foo(String s) { return null; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712y() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " public int foo() { return 0; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712z() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " long foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " public int foo() { return 0; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712za() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " long foo();\n" + + "}\n" + + "interface J {\n" + + " int foo();\n" + + "}\n" + + "public class X {\n" + + " public long foo() { return 0; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test4008712zb() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "interface J {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " public long foo() { return 0; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) is ambiguous for the type X\n" + + "----------\n"); +} +public void test4008712zc() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "interface J {\n" + + " Integer foo();\n" + + "}\n" + + "public class X {\n" + + " public long foo() { return 0; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " goo(new X()::foo);\n" + + " ^^^\n" + + "The method goo(I) in the type X is not applicable for the arguments (new X()::foo)\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " goo(new X()::foo);\n" + + " ^^^^^^^^^^^^\n" + + "The type of foo() from the type X is long, this is incompatible with the descriptor\'s return type: int\n" + + "----------\n"); +} +public void test4008712zd() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "interface J {\n" + + " Long foo();\n" + + "}\n" + + "public class X {\n" + + " public long foo() { return 0; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712ze() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "interface J {\n" + + " Integer foo();\n" + + "}\n" + + "public class X {\n" + + " public int foo() { return 0; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test4008712zf() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int foo();\n" + + "}\n" + + "interface J {\n" + + " Integer foo();\n" + + "}\n" + + "public class X {\n" + + " public Integer foo() { return 0; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void test4008712zg() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo();\n" + + "}\n" + + "interface J {\n" + + " Long foo();\n" + + "}\n" + + "public class X {\n" + + " public Integer foo() { return 0; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(I)"); +} +public void test4008712zh() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Integer foo();\n" + + "}\n" + + "interface J {\n" + + " Long foo();\n" + + "}\n" + + "public class X {\n" + + " public Long foo() { return 0L; }\n" + + " static void goo(I i) {\n" + + " System.out.println(\"foo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"foo(J)\");\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " goo(new X()::foo);\n" + + " }\n" + + "}\n", + }, + "foo(J)"); +} +public void testVarargs() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I ... i) {\n" + + " i[0].foo();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(()->{ System.out.println(\"Lambda\");});\n" + + " }\n" + + "}\n", + }, + "Lambda"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401850, [1.8][compiler] Compiler fails to type poly allocation expressions in method invocation contexts +public void test401850() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X s) {\n" + + " System.out.println(\"foo(X)\");\n" + + " }\n" + + " void foo(int x) {\n" + + " System.out.println(\"foo(int)\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new X<>());\n" + + " }\n" + + "}\n", + }, + "foo(X)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427072, [1.8][compiler] Regression since fix of bug 423505: Method is ambiguous for type X +public void test427072() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object m(X t);\n" + + "}\n" + + "interface J extends I {\n" + + "}\n" + + "public class X {\n" + + " int foo() { return 0; }\n" + + " int test() {\n" + + " return foo(X::foo);\n" + + " }\n" + + " int foo(I i) {return 0;}\n" + + " int foo(J j) { return 1;}\n" + + " public static void main(String args[]) {\n" + + " X x = new X();\n" + + " int i = x.test();\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427072, [1.8][compiler] Regression since fix of bug 423505: Method is ambiguous for type X +public void test427072a() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object m(X t);\n" + + "}\n" + + "interface J extends I {\n" + + "}\n" + + "public class X {\n" + + " int foo() { return 0; }\n" + + " int test() {\n" + + " return foo((x) -> x);\n" + + " }\n" + + " int foo(I i) {return 0;}\n" + + " int foo(J j) { return 1;}\n" + + " public static void main(String args[]) {\n" + + " X x = new X();\n" + + " int i = x.test();\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427072, [1.8][compiler] Regression since fix of bug 423505: Method is ambiguous for type X +public void test427072b() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object m(X t);\n" + + "}\n" + + "interface J extends I {\n" + + "}\n" + + "public class X {\n" + + " int foo() { return 0; }\n" + + " int test() {\n" + + " return foo(true ? (x) -> x : X::foo);\n" + + " }\n" + + " int foo(I i) {return 0;}\n" + + " int foo(J j) { return 1;}\n" + + " public static void main(String args[]) {\n" + + " X x = new X();\n" + + " int i = x.test();\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427072, [1.8][compiler] Regression since fix of bug 423505: Method is ambiguous for type X +public void test427072c() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " Object m(X t);\n" + + "}\n" + + "interface J extends I {\n" + + "}\n" + + "public class X {\n" + + " int foo1() { return 0; }\n" + + " int foo2() { return 0; }\n" + + " int test() {\n" + + " return foo(true ? X::foo1 : X::foo2);\n" + + " }\n" + + " int foo(I i) {return 0;}\n" + + " int foo(J j) { return 1;}\n" + + " public static void main(String args[]) {\n" + + " X x = new X();\n" + + " int i = x.test();\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "1"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427628, regression : The method * is ambiguous for the type * +public void test427628() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " new X().error(null);\n" + + " }\n" + + " public void error(I i) {\n" + + " test(i!=null?i.getJ():null);\n" + + " }\n" + + " public void test(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public void test(J j) {\n" + + " System.out.println(\"J\" + j);\n" + + " }\n" + + " public class I{\n" + + " public J getJ() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public class J{}\n" + + "}\n", + }, + "Jnull"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427628, regression : The method * is ambiguous for the type * +public void test427628a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " new X().error(null);\n" + + " }\n" + + " public void error(I i) {\n" + + " test(i!=null?i.getJ():null);\n" + + " }\n" + + " public void test(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " public void test(K k) {\n" + + " System.out.println(\"K\" + j);\n" + + " }\n" + + " public class I{\n" + + " public J getJ() {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " public class J{}\n" + + " public class K{}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " test(i!=null?i.getJ():null);\n" + + " ^^^^\n" + + "The method test(X.I) in the type X is not applicable for the arguments (((i != null) ? i.getJ() : null))\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " test(i!=null?i.getJ():null);\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from X.J to X.I\n" + + "----------\n" + + "3. ERROR in X.java (at line 12)\n" + + " System.out.println(\"K\" + j);\n" + + " ^\n" + + "j cannot be resolved to a variable\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427628, regression : The method * is ambiguous for the type * +public void test427628b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void setSetting(String key, String value) {\n" + + " }\n" + + " public void setSetting(String key, Integer value) {\n" + + " setSetting(key, value == null ? null : Integer.toString(value));\n" + + " }\n" + + "}\n", + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=421922, [1.8][compiler] Varargs & Overload - Align to JLS8 +public void _test421922() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " test(1);\n" + + " }\n" + + " public static void test(int... a) {\n" + + " System.out.print(\"int ... = \");\n" + + " System.out.println(Arrays.toString(a));\n" + + " }\n" + + " public static void test(Object... a) {\n" + + " System.out.print(\"Object ... = \");\n" + + " System.out.println(Arrays.toString(a));\n" + + " }\n" + + "}\n", + }, + "int ... = [1]"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427748, [1.8][compiler] Cannot convert from Boolean to boolean on generic return type +public void test427748() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " getLog(doit(baction));\n" + + " }\n" + + " private static interface Action {T run();}\n" + + " private static Action baction = () -> true;\n" + + " static void getLog(int override) {}\n" + + " static void getLog(boolean override) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + " private static T doit(Action action) { return action.run(); }\n" + + "}\n", + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=427808, [1.8] Correct super() invocation is not inferred when argument is a conditional expression +public void test427808() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Foo {\n" + + " public X(I i) {\n" + + " super(i != null ? i.toString() : null);\n" + + " }\n" + + " public static void main(String [] args) {\n" + + " new X(null);\n" + + " }\n" + + "}\n" + + "class Foo implements I {\n" + + " Foo(I i) {}\n" + + " Foo(String string){ System.out.println(\"OK\"); }\n" + + "}\n" + + "interface I {}\n", + }, + "OK"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429985, [1.8][compiler] Resolution of right method signature +public void test429985() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Supplier;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " // This does not compile with ECJ\n" + + " test(() -> \"hi\");\n" + + " }\n" + + " // Note: when removing this code the main function compiles with ECJ\n" + + " static void test(String message) {\n" + + " }\n" + + " static void test(Supplier messageSupplier) {\n" + + " System.out.println(messageSupplier.get());\n" + + " }\n" + + "}\n", + }, + "hi"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=429985, [1.8][compiler] Resolution of right method signature +public void test429985a() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.function.Supplier;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " // This does not compile with ECJ\n" + + " test(() -> \"hi\");\n" + + " }\n" + + " static void test(Supplier messageSupplier) {\n" + + " System.out.println(messageSupplier.get());\n" + + " }\n" + + " // Note: when removing this code the main function compiles with ECJ\n" + + " static void test(String message) {\n" + + " }\n" + + "}\n", + }, + "hi"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=448801, [1.8][compiler] Scope.mSMB & 15.12.3 Compile-Time Step 3 +public void test448801() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private class Y {\n" + + " }\n" + + " public X(Y ...ys) {\n" + + " }\n" + + " public void foo(Y ...ys) {\n" + + " }\n" + + " public void goo() {\n" + + " }\n" + + "}\n", + "Z.java", + "interface I {\n" + + " static void ifoo() {\n" + + " }\n" + + "}\n" + + "abstract class ZSuper {\n" + + " void zSuperFoo() {\n" + + " }\n" + + " abstract void goo();\n" + + "}\n" + + "public class Z extends ZSuper implements I {\n" + + " void goo() {\n" + + " super.zSuperFoo();\n" + + " super.goo();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.foo();\n" + + " System.out.println(x.goo());\n" + + " goo();\n" + + " Z.goo();\n" + + " zoo();\n" + + " new Z().ifoo();\n" + + " super.zSuperFoo();\n" + + " }\n" + + " class ZZ {\n" + + " class ZZZ {\n" + + " void zoo() {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Z.java (at line 13)\n" + + " super.goo();\n" + + " ^^^^^^^^^^^\n" + + "Cannot directly invoke the abstract method goo() for the type ZSuper\n" + + "----------\n" + + "2. ERROR in Z.java (at line 16)\n" + + " X x = new X();\n" + + " ^^^^^^^\n" + + "The constructor X(X.Y...) of type X is not applicable as the formal varargs element type X.Y is not accessible here\n" + + "----------\n" + + "3. ERROR in Z.java (at line 17)\n" + + " x.foo();\n" + + " ^^^\n" + + "The method foo(X.Y...) of type X is not applicable as the formal varargs element type X.Y is not accessible here\n" + + "----------\n" + + "4. ERROR in Z.java (at line 18)\n" + + " System.out.println(x.goo());\n" + + " ^^^^^^^\n" + + "The method println(boolean) in the type PrintStream is not applicable for the arguments (void)\n" + + "----------\n" + + "5. ERROR in Z.java (at line 19)\n" + + " goo();\n" + + " ^^^\n" + + "Cannot make a static reference to the non-static method goo() from the type Z\n" + + "----------\n" + + "6. ERROR in Z.java (at line 20)\n" + + " Z.goo();\n" + + " ^^^^^^^\n" + + "Cannot make a static reference to the non-static method goo() from the type Z\n" + + "----------\n" + + "7. ERROR in Z.java (at line 21)\n" + + " zoo();\n" + + " ^^^\n" + + "The method zoo() is undefined for the type Z\n" + + "----------\n" + + "8. ERROR in Z.java (at line 22)\n" + + " new Z().ifoo();\n" + + " ^^^^\n" + + "The method ifoo() is undefined for the type Z\n" + + "----------\n" + + "9. ERROR in Z.java (at line 23)\n" + + " super.zSuperFoo();\n" + + " ^^^^^\n" + + "Cannot use super in a static context\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=450415, [1.8][compiler] Failure to resolve overloaded call. +public void test450415() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "interface I {\n" + + " String foo();\n" + + "}\n" + + "interface J {\n" + + " List foo();\n" + + "}\n" + + "public class X {\n" + + " static void goo(I i) {\n" + + " System.out.println(\"goo(I)\");\n" + + " }\n" + + " static void goo(J j) {\n" + + " System.out.println(\"goo(J)\");\n" + + " }\n" + + " static List loo() {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " goo(()->loo());\n" + + " }\n" + + "}\n" + }, + "goo(J)"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=450415, [1.8][compiler] Failure to resolve overloaded call. +public void test450415a() { + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void foo();\n" + + "}\n" + + "public class X {\n" + + " static void foo() {\n" + + " class Y {\n" + + " void goo(T t) {\n" + + " System.out.println(\"T\");\n" + + " }\n" + + " void goo(I i) {\n" + + " System.out.println(\"I\");\n" + + " }\n" + + " }\n" + + " new Y().goo(()->{});\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + "}\n" + }, + "I"); +} +public void test482440a() { + runNegativeTest( + new String[] { + "Test.java", + "class Test {\n" + + "\n" + + " // generic method\n" + + " interface ConsumerA {\n" + + " void accept(int i);\n" + + " }\n" + + "\n" + + " // non-generic\n" + + " interface ConsumerB {\n" + + " void accept(int i);\n" + + " }\n" + + "\n" + + " // A before B\n" + + " void execute1(ConsumerA c) {}\n" + + " void execute1(ConsumerB c) {}\n" + + "\n" + + " // B before A\n" + + " void execute2(ConsumerB c) {}\n" + + " void execute2(ConsumerA c) {}\n" + + "\n" + + " void test() {\n" + + " execute1(x -> {}); // compiles in Eclipse\n" + + " execute2(x -> {}); // doesn't compile\n" + + " }\n" + + "\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 22)\n" + + " execute1(x -> {}); // compiles in Eclipse\n" + + " ^^^^^^^^\n" + + "The method execute1(Test.ConsumerA) is ambiguous for the type Test\n" + + "----------\n" + + "2. ERROR in Test.java (at line 23)\n" + + " execute2(x -> {}); // doesn\'t compile\n" + + " ^^^^^^^^\n" + + "The method execute2(Test.ConsumerB) is ambiguous for the type Test\n" + + "----------\n"); +} +public void test482440b() { + runConformTest( + new String[] { + "Test.java", + "class Test {\n" + + "\n" + + " // generic method\n" + + " interface ConsumerA {\n" + + " void accept(int i);\n" + + " }\n" + + "\n" + + " // non-generic\n" + + " interface ConsumerB {\n" + + " void accept(int i);\n" + + " }\n" + + "\n" + + " // A before B\n" + + " void execute1(ConsumerA c) {}\n" + + " void execute1(ConsumerB c) {}\n" + + "\n" + + " // B before A\n" + + " void execute2(ConsumerB c) {}\n" + + " void execute2(ConsumerA c) {}\n" + + "\n" + + " void test() {\n" + + " execute1((int x) -> {}); // compiles in Eclipse\n" + + " execute2((int x) -> {}); // doesn't compile\n" + + " }\n" + + "\n" + + "}\n" + }); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PackageBindingTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PackageBindingTest.java new file mode 100644 index 0000000000..b0819b98be --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PackageBindingTest.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * Copyright (c) 2016, 2019 Sven Strohschein and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * Contributors: + * Sven Strohschein - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.Binding; +import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; +import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; +import org.eclipse.jdt.internal.compiler.lookup.PlainPackageBinding; +import org.eclipse.jdt.internal.core.INameEnvironmentWithProgress; + +public class PackageBindingTest extends AbstractCompilerTest +{ + public PackageBindingTest(String name) { + super(name); + } + + /** + * This test checks if it is searched for packages before searching for types. + * The search for packages is much faster than searching for types, therefore it should get executed before searching for types. + * Commented since reverted to original behaviour as per bug 495598 + */ + public void _test01() { + NameEnvironmentDummy nameEnv = new NameEnvironmentDummy(true); + + PlainPackageBinding packageBinding = new PlainPackageBinding(new LookupEnvironment(null, new CompilerOptions(), null, nameEnv)); + Binding resultBinding = packageBinding.getTypeOrPackage("java.lang".toCharArray(), null, false); + assertNotNull(resultBinding); + + assertTrue(nameEnv.isPackageSearchExecuted); + assertFalse(nameEnv.isTypeSearchExecuted); + } + + /** + * This test checks if it is searched for types when no package was found. + * The test {@link #_test01()} checks if the package search is executed before the type search. + * The search for packages is much faster than searching for types, therefore it should get executed before searching for types. + */ + public void test02() { + NameEnvironmentDummy nameEnv = new NameEnvironmentDummy(false); + + LookupEnvironment environment = new LookupEnvironment(null, new CompilerOptions(), null, nameEnv); + PlainPackageBinding packageBinding = new PlainPackageBinding(environment); + Binding resultBinding = packageBinding.getTypeOrPackage("java.lang.String".toCharArray(), environment.module, false); + assertNull(resultBinding); // (not implemented) + + assertTrue(nameEnv.isPackageSearchExecuted); + assertTrue(nameEnv.isTypeSearchExecuted); + } + + /** + * This test checks if {@link INameEnvironment#findType(char[], char[][])} is executed. + * INameEnvironment has no option to avoid the search for secondary types, therefore the search for secondary types is executed (when available). + */ + public void test03() { + NameEnvironmentDummy nameEnv = new NameEnvironmentDummy(false); + + LookupEnvironment lookupEnv = new LookupEnvironment(null, new CompilerOptions(), null, nameEnv); + PackageBinding packageBinding = lookupEnv.createPackage(new char[][]{"org/eclipse/jdt".toCharArray(), "org/eclipse/jdt/internal".toCharArray()}); + assertNotNull(packageBinding); + + assertTrue(nameEnv.isTypeSearchExecuted); //the method findType(char[], char[][]) should got executed (without an option to avoid the search for secondary types) + } + + /** + * This test checks if types are searched on creating a package, but without the search for secondary types. + * It isn't necessary to search for secondary types when creating a package, because a package name can not collide with a secondary type. + * The search for secondary types should not get executed, because the search for secondary types is very expensive regarding performance + * (all classes of a package have to get loaded, parsed and analyzed). + */ + public void test04() { + NameEnvironmentWithProgressDummy nameEnvWithProgress = new NameEnvironmentWithProgressDummy(); + + LookupEnvironment lookupEnv = new LookupEnvironment(null, new CompilerOptions(), null, nameEnvWithProgress); + PackageBinding packageBinding = lookupEnv.createPackage(new char[][]{"org/eclipse/jdt".toCharArray(), "org/eclipse/jdt/internal".toCharArray()}); + assertNotNull(packageBinding); + + assertTrue(nameEnvWithProgress.isTypeSearchExecutedWithSearchWithSecondaryTypes); //the method findType(char[], char[][], boolean) should got executed ... + assertFalse(nameEnvWithProgress.isTypeSearchWithSearchWithSecondaryTypes); //... but without the search for secondary types + } + + private static class NameEnvironmentDummy implements INameEnvironment + { + private final boolean isPackage; + boolean isPackageSearchExecuted; + boolean isTypeSearchExecuted; + + NameEnvironmentDummy(boolean isPackage) { + this.isPackage = isPackage; + } + + @Override + public NameEnvironmentAnswer findType(char[][] compoundTypeName) { + this.isTypeSearchExecuted = true; + return null; + } + + @Override + public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) { + this.isTypeSearchExecuted = true; + return null; + } + + @Override + public boolean isPackage(char[][] parentPackageName, char[] packageName) { + this.isPackageSearchExecuted = true; + return this.isPackage; + } + + @Override + public void cleanup() { + } + } + + private static class NameEnvironmentWithProgressDummy implements INameEnvironmentWithProgress + { + boolean isTypeSearchWithSearchWithSecondaryTypes; + boolean isTypeSearchExecutedWithSearchWithSecondaryTypes; + + NameEnvironmentWithProgressDummy() {} + + @Override + public NameEnvironmentAnswer findType(char[][] compoundTypeName) { + return null; + } + + @Override + public boolean isPackage(char[][] parentPackageName, char[] packageName) { + return false; + } + + @Override + public void cleanup() { + } + + @Override + public void setMonitor(IProgressMonitor monitor) { + } + + @Override + public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName, boolean searchWithSecondaryTypes, char[] moduleName) { + this.isTypeSearchExecutedWithSearchWithSecondaryTypes = true; + this.isTypeSearchWithSearchWithSecondaryTypes = searchWithSecondaryTypes; + return null; + } + + @Override + public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) { + // TODO Auto-generated method stub + return null; + } + } +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java new file mode 100644 index 0000000000..4188240bb9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PatternMatching16Test.java @@ -0,0 +1,3993 @@ +/******************************************************************************* + * Copyright (c) 2020, 2021 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.IOException; +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.core.util.ClassFormatException; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class PatternMatching16Test extends AbstractRegressionTest { + + private static final JavacTestOptions JAVAC_OPTIONS = new JavacTestOptions("-source 16 --enable-preview -Xlint:-preview"); + static { +// TESTS_NUMBERS = new int [] { 40 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] { "testBug575035" }; + } + + public static Class testClass() { + return PatternMatching16Test.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_16); + } + public PatternMatching16Test(String testName){ + super(testName); + } + // Enables the tests to run individually + protected Map getCompilerOptions(boolean preview) { + Map defaultOptions = super.getCompilerOptions(); + if (this.complianceLevel >= ClassFileConstants.getLatestJDKLevel() + && preview) { + defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + } + return defaultOptions; + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { + if(!isJRE16Plus) + return; + runConformTest(testFiles, expectedOutput, customOptions, new String[] {"--enable-preview"}, JAVAC_OPTIONS); + } + protected void runNegativeTest( + String[] testFiles, + String expectedCompilerLog, + String javacLog, + String[] classLibraries, + boolean shouldFlushOutputDirectory, + Map customOptions) { + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedCompilerLog; + runner.javacTestOptions = JAVAC_OPTIONS; + runner.customOptions = customOptions; + runner.expectedJavacOutputString = javacLog; + runner.runNegativeTest(); + } + public void test000a() { + Map options = getCompilerOptions(false); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + runNegativeTest( + new String[] { + "X1.java", + "public class X1 {\n" + + " public void foo(Object obj) {\n" + + " if (obj instanceof String s) {\n" + + " }\n " + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X1.java (at line 3)\n" + + " if (obj instanceof String s) {\n" + + " ^^^^^^^^\n" + + "The Java feature 'Pattern Matching in instanceof Expressions' is only available with source level 16 and above\n" + + "----------\n", + null, + true, + options); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16); + } + public void test000b() { + if (this.complianceLevel < ClassFileConstants.getLatestJDKLevel()) + return; + Map options = getCompilerOptions(true); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_14); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_14); + runNegativeTest( + new String[] { + "X1.java", + "public class X1 {\n" + + " public void foo(Object obj) {\n" + + " if (obj instanceof String s) {\n" + + " }\n " + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X1.java (at line 0)\n" + + " public class X1 {\n" + + " ^\n" + + "Preview features enabled at an invalid source release level 14, preview can be enabled only at source level 17\n" + + "----------\n", + null, + true, + options); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16); + } + // No longer negative since pattern matching is a standard feature now. + public void test001() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X1.java", + "public class X1 {\n" + + " public void foo(Object obj) {\n" + + " if (obj instanceof String s) {\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " }\n" + + "}\n", + }, + "", + options); + } + public void test002() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X2.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X2 {\n" + + " public void foo(Integer obj) {\n" + + " if (obj instanceof String s) {\n" + + " }\n " + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X2.java (at line 4)\n" + + " if (obj instanceof String s) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types Integer and String\n" + + "----------\n", + "", + null, + true, + options); + } + public void test003() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X3.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X3 {\n" + + " public void foo(Number num) {\n" + + " if (num instanceof Integer s) {\n" + + " } else if (num instanceof String) {\n" + + " }\n " + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X3.java (at line 5)\n" + + " } else if (num instanceof String) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types Number and String\n" + + "----------\n", + "", + null, + true, + options); + } + public void test003a() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X3.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X3 {\n" + + " public void foo(Number num) {\n" + + " if (num instanceof int) {\n" + + " }\n " + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X3.java (at line 4)\n" + + " if (num instanceof int) {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types Number and int\n" + + "----------\n", + "", + null, + true, + options); + } + public void test004() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X4.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X4 {\n" + + " public void foo(Object obj) {\n" + + " String s = null;\n" + + " if (obj instanceof Integer s) {\n" + + " } else if (obj instanceof String) {\n" + + " }\n " + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X4.java (at line 5)\n" + + " if (obj instanceof Integer s) {\n" + + " ^\n" + + "Duplicate local variable s\n" + + "----------\n", + "", + null, + true, + options); + } + public void test005() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X5.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X5 {\n" + + "@SuppressWarnings(\"preview\")\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof Integer i) {\n" + + " System.out.print(i);\n" + + " } else if (obj instanceof String s) {\n" + + " System.out.print(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(100);\n" + + " }\n" + + "}\n", + }, + "100", + options); + } + public void test006() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X6.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X6 {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof Integer i) {\n" + + " System.out.print(i);\n" + + " } else if (obj instanceof String s) {\n" + + " System.out.print(s);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "abcd", + options); + } + public void test006a() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X6a.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X6a {\n" + + " public static void foo(Object obj) {\n" + + " if (obj != null) {\n" + + " if (obj instanceof Integer i) {\n" + + " System.out.print(i);\n" + + " } else if (obj instanceof String s) {\n" + + " System.out.print(i);\n" + + " }\n " + + " }\n " + + " System.out.print(i);\n" + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X6a.java (at line 8)\n" + + " System.out.print(i);\n" + + " ^\n" + + "i cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X6a.java (at line 11)\n" + + " System.out.print(i);\n" + + " ^\n" + + "i cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test006b() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X6b.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X6b {\n" + + " public static void foo(Object obj) {\n" + + " if (obj != null) {\n" + + " if (obj instanceof Integer i) {\n" + + " System.out.print(i);\n" + + " } else if (obj instanceof String s) {\n" + + " System.out.print(i);\n" + + " }\n " + + " }\n " + + " System.out.print(s);\n" + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X6b.java (at line 8)\n" + + " System.out.print(i);\n" + + " ^\n" + + "i cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X6b.java (at line 11)\n" + + " System.out.print(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test006c() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X6c.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X6c {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof Integer i) {\n" + + " System.out.print(i);\n" + + " } else if (obj instanceof String s) {\n" + + " System.out.print(i);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X6c.java (at line 7)\n" + + " System.out.print(i);\n" + + " ^\n" + + "i cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test006d() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X6d.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X6d {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof Integer i) {\n" + + " System.out.print(i);\n" + + " } else {\n" + + " System.out.print(i);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X6d.java (at line 7)\n" + + " System.out.print(i);\n" + + " ^\n" + + "i cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test007() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X7.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X7 {\n" + + " public static void foo(Object obj) {\n" + + " if (obj instanceof Integer i) {\n" + + " System.out.print(i);\n" + + " } else if (obj instanceof String s) {\n" + + " System.out.print(i);\n" + + " }\n " + + " }\n" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X7.java (at line 7)\n" + + " System.out.print(i);\n" + + " ^\n" + + "i cannot be resolved to a variable\n" + + "----------\n", + "X7.java:4: warning: [preview] pattern matching in instanceof is a preview feature and may be removed in a future release.\n" + + " if (obj instanceof Integer i) {\n" + + " ^\n" + + "X7.java:6: warning: [preview] pattern matching in instanceof is a preview feature and may be removed in a future release.\n" + + " } else if (obj instanceof String s) {\n" + + " ^\n" + + "X7.java:7: error: cannot find symbol\n" + + " System.out.print(i);\n" + + " ^\n" + + " symbol: variable i\n" + + " location: class X7\n" + + "1 error\n" + + "2 warnings", + null, + true, + options); + } + public void test008() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X8.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X8 {\n" + + " public static void foo(Object b) {\n" + + " Object c = null;\n" + + " if (b != c) {\n" + + " if ((b instanceof String s) && (s.length() != 0))\n" + + " System.out.println(\"s:\" + s);\n" + + " else \n" + + " System.out.println(\"b:\" + b);\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(100);\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "b:100\n" + + "s:abcd", + options); + } + public void test009() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X9.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X9 {\n" + + " public static void foo(Object b) {\n" + + " Object c = null;\n" + + " if (b != c) {\n" + + " if ((b instanceof String s) && (s.length() != 0))\n" + + " System.out.println(\"s:\" + s);\n" + + " else if ((b instanceof Integer i2))\n" + + " System.out.println(\"i2:\" + i2);\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(100);\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "i2:100\n" + + "s:abcd", + options); + } + public void test010() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X10.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X10 {\n" + + " public static void foo(Object b) {\n" + + " Object c = null;\n" + + " if (b != c) {\n" + + " if (b != null && (b instanceof String s))\n" + + " System.out.println(\"s:\" + s);\n" + + " else " + + " System.out.println(\"b:\" + b);\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(100);\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "b:100\n" + + "s:abcd", + options); + } + public void test011() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X11.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X11 {\n" + + " public static void foo(Object b) {\n" + + " Object c = null;\n" + + " if (b == null && (b instanceof String s)) {\n" + + " } else {" + + " }\n" + + " System.out.println(s);\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(100);\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X11.java (at line 7)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test012() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X12.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X12 {\n" + + " public static void foo(Object b) {\n" + + " Object c = new Object();\n" + + " if (b != c) {\n" + + " if (b == null && (b instanceof String s)) {\n" + + " System.out.println(\"s:\" + s);\n" + + " } else {\n" + + " System.out.println(\"b:\" + b);\n" + + " }\n" + + " s = null;\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(100);\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X12.java (at line 11)\n" + + " s = null;\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test013() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X13.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X13 {\n" + + " public static void foo(Object b) {\n" + + " Object c = null;\n" + + " if (b != c) {\n" + + " if (b == null && (b instanceof String s))\n" + + " System.out.println(\"s:\" + s);\n" + + " else " + + " System.out.println(\"b:\" + b);\n" + + " System.out.println(s);\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(100);\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X13.java (at line 9)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test014() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X14.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X14 {\n" + + " public static void foo(Object o) {\n" + + " if (!(o instanceof String s)) {\n" + + " System.out.print(\"then:\" + s);\n" + + " } else {\n" + + " System.out.print(\"else:\" + s);\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X14.java (at line 5)\n" + + " System.out.print(\"then:\" + s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test014a() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X14a.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X14a {\n" + + " public static void foo(Object o) {\n" + + " if (!(o instanceof String s)) {\n" + + " System.out.print(\"then:\" + s);\n" + + " } else {\n" + + " System.out.print(\"else:\" + s);\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X14a.java (at line 5)\n" + + " System.out.print(\"then:\" + s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test014b() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X14b.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X14b {\n" + + " public static void foo(Object o) {\n" + + " if (!!(o instanceof String s)) {\n" + + " System.out.print(\"then:\" + s);\n" + + " } else {\n" + + " System.out.print(\"else:\" + s);\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X14b.java (at line 7)\n" + + " System.out.print(\"else:\" + s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test014c() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X14c.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X14c {\n" + + " public static void foo(Object o) {\n" + + " if (o == null) {\n" + + " System.out.print(\"null\");\n" + + " } else if(!(o instanceof String s)) {\n" + + " System.out.print(\"else:\" + s);\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X14c.java (at line 7)\n" + + " System.out.print(\"else:\" + s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test014d() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X14d.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X14d {\n" + + " public static void foo(Object o) {\n" + + " if (o == null) {\n" + + " System.out.print(\"null\");\n" + + " } else if(!!(o instanceof String s)) {\n" + + " System.out.print(\"else:\" + s);\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "else:abcd", + options); + } + public void test014e() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X14a.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X14a {\n" + + " public static void foo(Object o) {\n" + + " if (!(!(o instanceof String s))) {\n" + + " System.out.print(\"s:\" + s);\n" + + " } else {\n" + + " }\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "s:abcd", + options); + } + /* + * Test that when pattern tests for false and if doesn't complete + * normally, then the variable is available beyond the if statement + */ + public void test015() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X15.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X15 {\n" + + " public static void foo(Object o) {\n" + + " if (!(o instanceof String s)) {\n" + + " throw new IllegalArgumentException();\n" + + " } else {\n" + + " System.out.print(\"s:\" + s);\n" + + " }\n" + + " System.out.print(s);\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "s:abcdabcd", + options); + } + /* + * Test that when pattern tests for false and if doesn't complete + * normally, then the variable is available beyond the if statement + */ + public void test015a() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X15a.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X15a {\n" + + " public static void foo(Object o) {\n" + + " if (!(o instanceof String s)) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " System.out.print(s);\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "abcd", + options); + } + /* + * Test that when pattern tests for false and if completes + * normally, then the variable is not available beyond the if statement + */ + public void test015b() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X15b.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X15b {\n" + + " public static void foo(Object o) {\n" + + " if (!(o instanceof String s)) {\n" + + " //throw new IllegalArgumentException();\n" + + " } else {\n" + + " System.out.print(\"s:\" + s);\n" + + " }\n" + + " System.out.print(s);\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(\"abcd\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X15b.java (at line 9)\n" + + " System.out.print(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test016() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X16.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X16 {\n" + + " public static void foo(Object o) {\n" + + " boolean b = (o instanceof String[] s && s.length == 1);\n" + + " System.out.print(b);\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(new String[]{\"one\"});\n" + + " }\n" + + "}\n", + }, + "true", + options); + } + public void test017() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X17.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X17 {\n" + + " public static void foo(Object o) {\n" + + " boolean b = (o instanceof String[] s && s.length == 1);\n" + + " System.out.print(s[0]);\n" + + " }" + + " public static void main(String[] obj) {\n" + + " foo(new String[]{\"one\"});\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X17.java (at line 5)\n" + + " System.out.print(s[0]);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + /* Test that the scopes of pattern variable in a block doesn't affect + * another outside but declared after the block + */ + public void test018() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X18.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X18 {\n" + + " public static void main(String[] obj) {\n" + + " foo(obj);\n" + + " }\n" + + " public static void foo(Object[] obj) {\n" + + " boolean a = true;\n" + + " {\n" + + " boolean b = (obj instanceof String[] s && s.length == 0);\n" + + " System.out.print(b + \",\");\n" + + " }\n" + + " boolean b = a ? false : (obj instanceof String[] s && s.length == 0);\n" + + " System.out.print(b);\n" + + " }\n" + + "}\n", + }, + "true,false", + options); + } + /* Test that the scopes of pattern variable in a block doesn't affect + * another outside but declared before the block + */ + public void test019() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X19.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X19 {\n" + + " public static void main(String[] obj) {\n" + + " foo(obj);\n" + + " }\n" + + " public static void foo(Object[] obj) {\n" + + " boolean a = true;\n" + + " boolean b = a ? false : (obj instanceof String[] s && s.length == 0);\n" + + " System.out.print(b + \",\");\n" + + " {\n" + + " b = (obj instanceof String[] s && s.length == 0);\n" + + " System.out.print(b);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "false,true", + options); + } + /* Test that we still detect duplicate pattern variable declarations + */ + public void test019b() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X19b.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X19b {\n" + + " public static void main(String[] obj) {\n" + + " foo(obj);\n" + + " }\n" + + " public static void foo(Object[] obj) {\n" + + " boolean a = true;\n" + + " if (obj instanceof String[] s && s.length == 0) {\n" + + " boolean b = (obj instanceof String[] s && s.length == 0);\n" + + " System.out.print(b);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X19b.java (at line 9)\n" + + " boolean b = (obj instanceof String[] s && s.length == 0);\n" + + " ^\n" + + "Duplicate local variable s\n" + + "----------\n", + "", + null, + true, + options); + } + /* Test that we report subtypes of pattern variables used in the same stmt + */ + public void test020() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X20.java", + "public class X20 {\n" + + " public static void main(String[] obj) {\n" + + " foo(obj);\n" + + " }\n" + + " public static void foo(Object[] o) {\n" + + " boolean b = (o instanceof String[] s) && s instanceof CharSequence[] s2;\n" + + " System.out.print(b);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X20.java (at line 6)\n" + + " boolean b = (o instanceof String[] s) && s instanceof CharSequence[] s2;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Expression type cannot be a subtype of the Pattern type\n" + + "----------\n", + "", + null, + true, + options); + } + /* Test that we allow consequent pattern expressions in the same statement + */ + public void test020a() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X20.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X20 {\n" + + " public static void main(String[] obj) {\n" + + " foo(obj);\n" + + " }\n" + + " public static void foo(Object[] o) {\n" + + " boolean b = (o instanceof CharSequence[] s) && s instanceof String[] s2;\n" + + " System.out.print(b);\n" + + " }\n" + + "}\n", + }, + "true", + options); + } + /* Test that we allow consequent pattern expressions in the same statement + */ + public void test021() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X21.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X21 {\n" + + " public static void main(String[] obj) {\n" + + " foo(obj);\n" + + " }\n" + + " public static void foo(Object[] o) {\n" + + " boolean b = (o instanceof CharSequence[] s) && s instanceof String[] s2;\n" + + " System.out.print(s);\n" + + " System.out.print(s2);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X21.java (at line 8)\n" + + " System.out.print(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X21.java (at line 9)\n" + + " System.out.print(s2);\n" + + " ^^\n" + + "s2 cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + /* Test that we allow pattern expressions in a while statement + */ + public void test022() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X22.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X22 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " while ((o instanceof String s) && s.length() > 0) {\n" + + " o = s.substring(0, s.length() - 1);\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "one\non\no", + options); + } + public void test022a() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X22a.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X22a {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " do {\n" + + " o = s.substring(0, s.length() - 1);\n" + + " System.out.println(s);\n" + + " } while ((o instanceof String s) && s.length() > 0);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X22a.java (at line 8)\n" + + " o = s.substring(0, s.length() - 1);\n" + + " ^\n" + + "s cannot be resolved\n" + + "----------\n" + + "2. ERROR in X22a.java (at line 8)\n" + + " o = s.substring(0, s.length() - 1);\n" + + " ^\n" + + "s cannot be resolved\n" + + "----------\n" + + "3. ERROR in X22a.java (at line 9)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + null, + true, + options); + } + public void test022b() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X22b.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X22b {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " do {\n" + + " // nothing\n" + + " } while ((o instanceof String s));\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X22b.java (at line 10)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + null, + true, + options); + } + public void test022c() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X22c.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X22c {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " do {\n" + + " // nothing\n" + + " } while (!(o instanceof String s));\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "one", + options); + } + /* Test pattern expressions in a while statement with break + */ + public void test023() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X23.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X23 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " while (!(o instanceof String s) && s.length() > 0) {\n" + + " System.out.println(s);\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X23.java (at line 7)\n" + + " while (!(o instanceof String s) && s.length() > 0) {\n" + + " ^\n" + + "s cannot be resolved\n" + + "----------\n" + + "2. ERROR in X23.java (at line 8)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test023a() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X23a.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X23a {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " do {\n" + + " System.out.println(s);\n" + + " break;\n" + + " } while (!(o instanceof String s) && s.length() > 0);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X23a.java (at line 8)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X23a.java (at line 10)\n" + + " } while (!(o instanceof String s) && s.length() > 0);\n" + + " ^\n" + + "s cannot be resolved\n" + + "----------\n", + "", + null, + true, + options); + } + /* Test pattern expressions in a while statement with no break + */ + public void test023b() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X23b.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X23b {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " while (!(o instanceof String s) && s.length() > 0) {\n" + + " System.out.println(s);\n" + + " //break;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X23b.java (at line 7)\n" + + " while (!(o instanceof String s) && s.length() > 0) {\n" + + " ^\n" + + "s cannot be resolved\n" + + "----------\n" + + "2. ERROR in X23b.java (at line 8)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + // Same as above but with do while + public void test023c() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X23c.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X23c {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " do {\n" + + " System.out.println(s);\n" + + " //break;\n" + + " }while (!(o instanceof String s) && s.length() > 0);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X23c.java (at line 8)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X23c.java (at line 10)\n" + + " }while (!(o instanceof String s) && s.length() > 0);\n" + + " ^\n" + + "s cannot be resolved\n" + + "----------\n", + "", + null, + true, + options); + } + public void test024a() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X24a.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X24a {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " while (!(o instanceof String s)) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "one", + options); + } + public void test024b() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X24a.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X24a {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " for (;!(o instanceof String s);) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "one", + options); + } + /* + * It's not a problem to define the same var in two operands of a binary expression, + * but then it is not in scope below. + */ + public void test025() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X25.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X25 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\", \"two\");\n" + + " }\n" + + " public static void foo(Object o, Object p) {\n" + + " if ((o instanceof String s) != p instanceof String s) {\n" + + " System.out.print(\"s:\" + s);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X25.java (at line 8)\n" + + " System.out.print(\"s:\" + s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test025a() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X25.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X25 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " if ( (o instanceof String a) || (! (o instanceof String a)) ) {\n" + + " System.out.print(\"a:\" + a);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X25.java (at line 8)\n" + + " System.out.print(\"a:\" + a);\n" + + " ^\n" + + "a cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test025b() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X25.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X25 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " if ( (o instanceof String a) || (! (o instanceof String a)) ) {\n" + + " System.out.println(\"none\");\n" + + " } else {\n" + + " System.out.print(\"a:\" + a);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "none", + options); + } + public void test025c() { + Map options = getCompilerOptions(true); + runConformTest( + new String[] { + "X25.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X25 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\", new Integer(0));\n" + + " }\n" + + " public static void foo(Object o, Object p) {\n" + + " if ( (o instanceof String a) || (! (p instanceof String a)) ) {\n" + + " System.out.println(\"none\");\n" + + " } else {\n" + + " System.out.print(\"a:\" + a);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "none", + options); + } + /* + * It's not allowed to have two pattern variables with same name in the + * same scope + */ + public void test026() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X26.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X26 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\", \"two\");\n" + + " }\n" + + " public static void foo(Object o, Object p) {\n" + + " if ((o instanceof String s) && (p instanceof String s)) {\n" + + " System.out.print(\"s:\" + s);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X26.java (at line 7)\n" + + " if ((o instanceof String s) && (p instanceof String s)) {\n" + + " ^\n" + + "Duplicate local variable s\n" + + "----------\n", + "", + null, + true, + options); + } + /* + * It's not allowed to have two pattern variables with same name in the + * same scope + */ + public void test026a() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X26.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X26 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\", \"two\");\n" + + " }\n" + + " public static void foo(Object o, Object p) {\n" + + " if ((o instanceof String s) && (!(o instanceof String s))) {\n" + + " System.out.print(\"s:\" + s);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X26.java (at line 7)\n" + + " if ((o instanceof String s) && (!(o instanceof String s))) {\n" + + " ^\n" + + "Duplicate local variable s\n" + + "----------\n", + "", + null, + true, + options); + } + /* + * It's not a problem to define the same var in two operands of a binary expression, + * but then it is not in scope below. + */ + public void test026b() { + Map options = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X26.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X26 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\", \"two\");\n" + + " }\n" + + " public static void foo(Object o, Object p) {\n" + + " if ((o instanceof String s) == p instanceof String s) {\n" + + " System.out.print(\"s:\" + s);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X26.java (at line 8)\n" + + " System.out.print(\"s:\" + s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + options); + } + public void test027() { + runConformTest( + new String[] { + "X27.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X27 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " for(int i = 0; (obj instanceof String[] s && s.length > 0 && i < s.length); i++) {\n" + + " System.out.println(s[i]);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + getCompilerOptions(true)); + } + public void test028() { + runConformTest( + new String[] { + "X28.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X28 {\n" + + " public static void main(String[] o) {\n" + + " foo(new String[] {\"one\", \"two\"});\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " for(int i = 0; (obj instanceof String[] s && s.length > 0 && i < s.length); i++) {\n" + + " System.out.println(s[i]);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "one\ntwo", + getCompilerOptions(true)); + } + public void test029() { + runConformTest( + new String[] { + "X29.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X29 {\n" + + " public static void main(String[] o) {\n" + + " foo(new String[] {\"one\", \"two\"});\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " for(int i = 0; (obj instanceof String[] s) && s.length > 0 && i < s.length; i = (s != null ? i + 1 : i)) {\n" + + " System.out.println(s[i]);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "one\ntwo", + getCompilerOptions(true)); + } + /* + * Test that pattern variables are accepted in initialization of a for statement, + * but unavailable in the body if uncertain which if instanceof check was true + */ + public void test030() { + runNegativeTest( + new String[] { + "X30.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X30 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " for(int i = 0, length = (obj instanceof String s) ? s.length() : 0; i < length; i++) {\n" + + " System.out.print(s.charAt(i));\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X30.java (at line 8)\n" + + " System.out.print(s.charAt(i));\n" + + " ^\n" + + "s cannot be resolved\n" + + "----------\n", + "", + null, + true, + getCompilerOptions(true)); + } + public void test031() { + runNegativeTest( + new String[] { + "X31.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X31 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " for(int i = 0; !(obj instanceof String[] s) && s.length > 0 && i < s.length; i++) {\n" + + " System.out.println(s[i]);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X31.java (at line 7)\n" + + " for(int i = 0; !(obj instanceof String[] s) && s.length > 0 && i < s.length; i++) {\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X31.java (at line 7)\n" + + " for(int i = 0; !(obj instanceof String[] s) && s.length > 0 && i < s.length; i++) {\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n" + + "3. ERROR in X31.java (at line 8)\n" + + " System.out.println(s[i]);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + getCompilerOptions(true)); + } + public void test032() { + runConformTest( + new String[] { + "X32.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X32 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " String res = null;\n" + + " int i = 0;\n" + + " switch(i) {\n" + + " case 0:\n" + + " res = (obj instanceof String) ? null : null;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " System.out.println(res);\n" + + " }\n" + + "}\n", + }, + "null", + getCompilerOptions(true)); + } + public void test032a() { + runConformTest( + new String[] { + "X32.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X32 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " String res = null;\n" + + " int i = 0;\n" + + " switch(i) {\n" + + " case 0:\n" + + " res = (obj instanceof String s) ? s : null;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " System.out.println(res);\n" + + " }\n" + + "}\n", + }, + "one", + getCompilerOptions(true)); + } + public void test033() { + runNegativeTest( + new String[] { + "X33.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X33 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " String res = null;\n" + + " int i = 0;\n" + + " switch(i) {\n" + + " case 0:\n" + + " res = (obj instanceof String s) ? s : null;\n" + + " res = s.substring(1);\n" + + " default:\n" + + " break;\n" + + " }\n" + + " System.out.println(res);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X33.java (at line 12)\n" + + " res = s.substring(1);\n" + + " ^\n" + + "s cannot be resolved\n" + + "----------\n", + "", + null, + true, + getCompilerOptions(true)); + } + public void test034() { + runNegativeTest( + new String[] { + "X34.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X34 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " int i = 0;\n" + + " String result = switch(i) {\n" + + " case 0 -> {\n" + + " result = (obj instanceof String s) ? s : null;\n" + + " yield result;\n" + + " }\n" + + " default -> {\n" + + " yield result;\n" + + " }\n" + + " };\n" + + " System.out.println(result);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X34.java (at line 14)\n" + + " yield result;\n" + + " ^^^^^^\n" + + "The local variable result may not have been initialized\n" + + "----------\n", + "", + null, + true, + getCompilerOptions(true)); + } + public void test035() { + runNegativeTest( + new String[] { + "X35.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X35 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " int i = 0;\n" + + " String result = switch(i) {\n" + + " case 0 -> {\n" + + " result = (obj instanceof String s) ? s : null;\n" + + " yield s;\n" + + " }\n" + + " default -> {\n" + + " yield s;\n" + + " }\n" + + " };\n" + + " System.out.println(result);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X35.java (at line 11)\n" + + " yield s;\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X35.java (at line 14)\n" + + " yield s;\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + getCompilerOptions(true)); + } + public void test036() { + runConformTest( + new String[] { + "X36.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X36 {\n" + + " public static void main(String[] o) {\n" + + " foo(\"one\");\n" + + " }\n" + + " public static void foo(Object obj) {\n" + + " int i = 0;\n" + + " String result = switch(i) {\n" + + " default -> {\n" + + " result = (obj instanceof String s) ? s : null;\n" + + " yield result;\n" + + " }\n" + + " };\n" + + " System.out.println(result);\n" + + " }\n" + + "}\n", + }, + "one", + getCompilerOptions(true)); + } + public void test037() { + runNegativeTest( + new String[] { + "X37.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X37 {\n" + + " public static void main(String[] o) {\n" + + " foo(new String[] {\"abcd\"});\n" + + " }\n" + + " public static void foo(Object[] obj) {\n" + + " for(int i = 0; (obj[i] instanceof String s) && s.length() > 0 ; i++) {\n" + + " System.out.println(s[i]);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X37.java (at line 8)\n" + + " System.out.println(s[i]);\n" + + " ^^^^\n" + + "The type of the expression must be an array type but it resolved to String\n" + + "----------\n", + "", + null, + true, + getCompilerOptions(true)); + } + public void test038() { + runNegativeTest( + new String[] { + "X38.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X38 {\n" + + " public static void main(String[] o) {\n" + + " foo(new String[] {\"abcd\"});\n" + + " }\n" + + " public static void foo(Object[] obj) {\n" + + " for(int i = 0; (obj[i] instanceof String s) && s.length() > 0 ;) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X38.java (at line 10)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n", + "", + null, + true, + getCompilerOptions(true)); + } + public void test039() { + runConformTest( + new String[] { + "X39.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X39 {\n" + + " public static void main(String[] o) {\n" + + " foo(new String[] {\"one\"});;\n" + + " }\n" + + " public static void foo(Object[] obj) {\n" + + " for(int i = 0; i < obj.length && (obj[i] instanceof String s) && i < s.length(); i++) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "one", + getCompilerOptions(true)); + } + public void test040() { + runConformTest( + new String[] { + "X40.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X40 {\n" + + " String a;\n" + + " Object o1 = \"x\";\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(new X40().foo());\n" + + " }\n" + + " public String foo() {\n" + + " String res = \"\";\n" + + " Object o2 = \"x\";\n" + + " if (o1 instanceof String s) { \n" + + " res = \"then_\" + s;\n" + + " } else {\n" + + " res = \"else_\";\n" + + " }\n" + + " return res;\n" + + " }\n" + + "}\n", + }, + "then_x", + getCompilerOptions(true)); + } + public void test041() { + runConformTest( + new String[] { + "X41.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X41 {\n" + + " String a;\n" + + " Object o1 = \"x\";\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(new X41().foo());\n" + + " }\n" + + " public String foo() {\n" + + " String res = \"\";\n" + + " Object o2 = \"x\";\n" + + " if ( !(o1 instanceof String s) || !o1.equals(s) ) { \n" + + " res = \"then_\";\n" + + " } else {\n" + + " res = \"else_\" + s;\n" + + " }\n" + + " return res;\n" + + " }\n" + + "}\n", + }, + "else_x", + getCompilerOptions(true)); + } + public void test042() { + runConformTest( + new String[] { + "X42.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X42 {\n" + + " String a;\n" + + " Object o1 = \"x\";\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(new X42().foo());\n" + + " }\n" + + " public String foo() {\n" + + " String res = \"\";\n" + + " Object o2 = o1;\n" + + " if ( !(o1 instanceof String s) || !o1.equals(s) ) { \n" + + " res = \"then_\";\n" + + " } else {\n" + + " res = \"else_\" + s;\n" + + " }\n" + + " return res;\n" + + " }\n" + + "}\n", + }, + "else_x", + getCompilerOptions(true)); + } + public void test043() { + runConformTest( + new String[] { + "X43.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X43 {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(new X43().foo(\"foo\", \"test\"));\n" + + " }\n" + + " public boolean foo(Object obj, String s) {\n" + + " class Inner {\n" + + " public boolean foo(Object obj) {\n" + + " if (obj instanceof String s) {\n" + + " // s is shadowed now\n" + + " if (!\"foo\".equals(s))\n" + + " return false;\n" + + " }\n" + + " // s is not shadowed\n" + + " return \"test\".equals(s);\n" + + " }\n" + + " }\n" + + " return new Inner().foo(obj);\n" + + " }\n" + + "}\n", + }, + "true", + getCompilerOptions(true)); + } + public void test044() { + Map compilerOptions = getCompilerOptions(true); + String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X44.java", + "@SuppressWarnings(\"preview\")\n" + + "class Inner {\n" + + " public boolean foo(Object obj) {\n" + + " if (obj instanceof Inner p) {\n" + + " return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + "} \n" + + "public class X44 {\n" + + " public static void main(String argv[]) {\n" + + " Inner param = new Inner<>();\n" + + " System.out.println(new Inner().foo(param));\n" + + " }\n" + + "}\n", + }, + "true", + compilerOptions); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old); + } + public void test045() { + Map compilerOptions = getCompilerOptions(true); + String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X45.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X45 {\n" + + " Object s = \"test\";\n" + + " boolean result = s instanceof String s1;\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"true\");\n" + + " }\n" + + "}\n", + }, + "true", + compilerOptions); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old); + } + public void test046() { + Map compilerOptions = getCompilerOptions(true); + String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X46.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X46 {\n" + + " Object s = \"test\";\n" + + " boolean result = (s instanceof String s1 && s1 != null);\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"true\");\n" + + " }\n" + + "}\n", + }, + "true", + compilerOptions); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old); + } + public void test047() { + Map compilerOptions = getCompilerOptions(true); + String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "InstanceOfPatternTest.java", + "public class InstanceOfPatternTest {\n" + + " public static void main(String[] args) {\n" + + " if (getChars() instanceof String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " static CharSequence getChars() {\n" + + " return \"xyz\";\n" + + " }\n" + + "}\n", + }, + "xyz", + compilerOptions); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old); + } + public void test048() { + Map compilerOptions = getCompilerOptions(true); + String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "InstanceOfPatternTest.java", + "public class InstanceOfPatternTest {\n" + + " public static void main(String[] args) {\n" + + " if (getChars() instanceof String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " static CharSequence getChars() {\n" + + " return \"xyz\";\n" + + " }\n" + + "}\n", + }, + "xyz", + compilerOptions); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old); + } + public void test049() { + Map compilerOptions = getCompilerOptions(true); + String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "InstanceOfPatternTest.java", + "public class InstanceOfPatternTest {\n" + + " public static void main(String[] args) {\n" + + " if ( ((CharSequence) getChars()) instanceof String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " static Object getChars() {\n" + + " return \"xyz\";\n" + + " }\n" + + "}\n", + }, + "xyz", + compilerOptions); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old); + } + public void test050() { + Map compilerOptions = getCompilerOptions(true); + String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runNegativeTest( + new String[] { + "InstanceOfPatternTest.java", + "@SuppressWarnings(\"preview\")\n" + + "public class InstanceOfPatternTest {\n" + + " public static void main(String[] args) {\n" + + " if ( ((s) -> {return s;}) instanceof I s) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + "} \n" + + "interface I {\n" + + " public String foo(String s);\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in InstanceOfPatternTest.java (at line 4)\n" + + " if ( ((s) -> {return s;}) instanceof I s) {\n" + + " ^^^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n", + "", + null, + true, + compilerOptions); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old); + } + public void test051() { + Map compilerOptions = getCompilerOptions(true); + String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "InstanceOfPatternTest.java", + "public class InstanceOfPatternTest {\n" + + " static String STR = \"2\";\n" + + " public static void main(String[] args) {\n" + + " if ( switch(STR) {\n" + + " case \"1\" -> (CharSequence) \"one\";\n" + + " default -> (CharSequence) \"Unknown\";\n" + + " } \n" + + " instanceof String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "Unknown", + compilerOptions); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old); + } + public void test052() { + Map compilerOptions = getCompilerOptions(true); + String old = compilerOptions.get(CompilerOptions.OPTION_PreserveUnusedLocal); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"preview\")\n" + + " public static void main(String args[]) {\n" + + " String result = null;\n" + + " Object obj = \"abc\";\n" + + " int i = switch (0) {\n" + + " case 1 -> {\n" + + " yield 1;\n" + + " }\n" + + " default -> {\n" + + " for (int j = 0; !(obj instanceof String s);) {\n" + + " obj = null;\n" + + " }\n" + + " result = s;\n" + + " System.out.println(result);\n" + + " yield 2;\n" + + " }\n" + + " };\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n", + }, + "abc\n" + + "2", + compilerOptions); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, old); + } + public void testBug562392a() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public boolean foo(T obj) {\n" + + " if (obj instanceof String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + " return true;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " String s = \"x\";\n" + + " System.out.println(new X().foo(s));\n" + + " }\n" + + "}\n", + }, + "x\n" + + "true", + compilerOptions); + } + public void testBug562392b() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X {\n" + + " public boolean foo(Object obj) {\n" + + " if (obj instanceof T) {\n" + + " return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (obj instanceof T) {\n" + + " ^^^\n" + + "Type Object cannot be safely cast to T\n" + + "----------\n", + "X.java:4: error: Object cannot be safely cast to T\n" + + " if (obj instanceof T) {\n" + + " ^\n" + + " where T is a type-variable:\n" + + " T extends Object declared in class X", + null, + true, + compilerOptions); + } + public void testBug562392c() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X {\n" + + " public boolean foo(Object obj) {\n" + + " if (obj instanceof T t) {\n" + + " return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (obj instanceof T t) {\n" + + " ^^^\n" + + "Type Object cannot be safely cast to T\n" + + "----------\n", + "X.java:4: error: Object cannot be safely cast to T\n" + + " if (obj instanceof T t) {\n" + + " ^\n" + + " where T is a type-variable:\n" + + " T extends Object declared in class X", + null, + true, + compilerOptions); + } + public void testBug562392d() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X {\n" + + " public boolean foo(Object obj) {\n" + + " if (null instanceof T t) {\n" + + " return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (null instanceof T t) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Expression type cannot be a subtype of the Pattern type\n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + public void testBug562392e() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X {\n" + + " public boolean foo(X obj) {\n" + + " if (obj instanceof X p) {\n" + + " return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (obj instanceof X p) {\n" + + " ^^^\n" + + "Type X cannot be safely cast to X\n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + public void testBug562392f() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "class Outer {\n" + + " static class Inner {\n" + + " }\n" + + "}\n" + + "@SuppressWarnings({\"preview\", \"rawtypes\"})\n" + + "class X {\n" + + " public boolean foo(Outer.Inner obj) {\n" + + " if (obj instanceof Outer p) {\n" + + " return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " if (obj instanceof Outer p) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Incompatible conditional operand types Outer.Inner and Outer\n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + public void testBug562392g() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "class Outer {\n" + + " static class Inner {\n" + + " }\n" + + "}\n" + + "@SuppressWarnings({\"preview\", \"rawtypes\"})\n" + + "class X {\n" + + " public boolean foo(Object obj) {\n" + + " if (obj instanceof Outer.Inner p) {\n" + + " return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " Outer.Inner inn = new Outer.Inner();\n" + + " System.out.println(new X().foo(inn));\n" + + " }\n" + + "}\n", + }, + "true", + compilerOptions); + } + public void testBug562392h() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings({\"rawtypes\"})\n" + + "class Y extends X {}\n" + + "@SuppressWarnings({\"rawtypes\"})\n" + + "public class X {\n" + + " public boolean foo(X[] obj) {\n" + + " if (obj instanceof Y[] p) {\n" + + " return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " Object[] param = {new X()};\n" + + " System.out.println(new X().foo(param));\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " System.out.println(new X().foo(param));\n" + + " ^^^\n" + + "The method foo(X[]) in the type X is not applicable for the arguments (Object[])\n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + public void testBug562392i() { + Map options = getCompilerOptions(false); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + runNegativeTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.UnaryOperator;\n" + + "@SuppressWarnings({\"preview\"})\n" + + "public class Test {\n" + + " public boolean foo(Function, ArrayList> obj) {\n" + + " if (obj instanceof UnaryOperator>) {\n" + + " return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Test.java (at line 8)\n" + + " if (obj instanceof UnaryOperator>) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Cannot perform instanceof check against parameterized type UnaryOperator>. Use the form UnaryOperator instead since further generic type information will be erased at runtime\n" + + "----------\n", + "", + null, + true, + options); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16); + } + public void testBug562392j() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "Test.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Function;\n" + + "import java.util.function.UnaryOperator;\n" + + "@SuppressWarnings({\"preview\", \"rawtypes\"})\n" + + "public class Test {\n" + + " public boolean foo(Function, ArrayList> obj) {\n" + + " if (obj instanceof UnaryOperator>) {\n" + + " return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"\");\n" + + " }\n" + + "}\n", + }, + "", + compilerOptions); + } + public void test053() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"preview\")\n" + + " public static void main(String argv[]) {\n" + + " Object obj = \"x\";\n" + + " if (obj instanceof String s) {\n" + + " System.out.println(s);\n" + + " }\n" + + " String s = \"y\";\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "x\n" + + "y", + compilerOptions); + } + public void test054() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"preview\")\n" + + " public static void main(String argv[]) {\n" + + " Object obj = \"x\";\n" + + " while (!(obj instanceof String s)) {\n" + + " String s = \"y\";\n" + + " System.out.println(s);\n" + + " }\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "x", + compilerOptions); + } + public void test055() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void main(String argv[]) {\n" + + " String result = \"\";\n" + + " Object obj = \"abc\";\n" + + " for (; !(obj instanceof String a);) {\n" + + " String a = \"\";\n" + + " result = a;\n" + + " obj = null;\n" + + " }\n" + + " if (!result.equals(\"abc\")) {\n" + + " System.out.println(\"PASS\");\n" + + " } else {\n" + + " System.out.println(\"FAIL\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "PASS", + compilerOptions); + } + // Positive - Test conflicting pattern variable and lambda argument in for loop + public void test056() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X {\n" + + " public static int impl(I a) {\n" + + " return a.foo(\"Default\");\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " String result = \"\";\n" + + " Object obj = \"a\";\n" + + " for (int i = 0; !(obj instanceof String a); i = impl(a -> a.length())) {\n" + + " obj = null;\n" + + " }\n" + + " if (!result.equals(\"\"))\n" + + " System.out.println(\"FAIL\");\n" + + " else\n" + + " System.out.println(\"PASS\");\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " int foo(String s);\n" + + "}\n", + }, + "PASS", + compilerOptions); + } + // Positive - Test conflicting pattern variable and lambda argument in for loop (block) + public void test056a() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X {\n" + + " public static int impl(I a) {\n" + + " return a.foo(\"Default\");\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " String result = \"\";\n" + + " Object obj = \"a\";\n" + + " for (int i = 0; !(obj instanceof String a); i = impl(x -> {\n" + + " String a = \"\";\n" + + " return a.length();\n" + + " })) {\n" + + " obj = null;\n" + + " }\n" + + " if (!result.equals(\"\"))\n" + + " System.out.println(\"FAIL\");\n" + + " else\n" + + " System.out.println(\"PASS\");\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " int foo(String s);\n" + + "}\n", + }, + "PASS", + compilerOptions); + } + // Positive - Test conflicting pattern variable and lambda argument in if + public void test056b() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X {\n" + + " public static int impl(I a) {\n" + + " return a.foo(\"Default\");\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " String result = \"\";\n" + + " Object obj = \"a\";\n" + + " if (!(obj instanceof String a)) {\n" + + " int i = impl(a -> a.length());\n" + + " }\n" + + " if (!result.equals(\"\"))\n" + + " System.out.println(\"FAIL\");\n" + + " else\n" + + " System.out.println(\"PASS\");\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " int foo(String s);\n" + + "}\n", + }, + "PASS", + compilerOptions); + } + // Positive - Test conflicting pattern variable and lambda argument in if + public void test056d() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X {\n" + + " public static int impl(I a) {\n" + + " return a.foo(\"Default\");\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " String result = \"\";\n" + + " Object obj = \"a\";\n" + + " for (int i = 0; (obj instanceof String a); i = impl(a -> a.length())) {\n" + + " obj = null;\n" + + " }\n" + + " if (!result.equals(\"\"))\n" + + " System.out.println(\"FAIL\");\n" + + " else\n" + + " System.out.println(\"PASS\");\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " int foo(String s);\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " for (int i = 0; (obj instanceof String a); i = impl(a -> a.length())) {\n" + + " ^\n" + + "Lambda expression\'s parameter a cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + /* + * Test we report only one duplicate variable, i.e., in THEN stmt + * where pattern variable is in scope. + */ + public void test057() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"preview\")\n" + + " public static void main(String argv[]) {\n" + + " Object obj = \"x\";\n" + + " if (obj instanceof String s) {\n" + + " String s = \"\";\n" + + " System.out.println(s);\n" + + " }\n" + + " String s = \"y\";\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " String s = \"\";\n" + + " ^\n" + + "Duplicate local variable s\n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + public void test058() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"preview\")\n" + + " public static void main(String[] s) {\n" + + " Object obj = \"x\";\n" + + " if (obj instanceof String[] s && s.length > 0) {\n" + + " System.out.println(s[0]);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (obj instanceof String[] s && s.length > 0) {\n" + + " ^\n" + + "Duplicate local variable s\n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + public void test059() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int count;\n"+ + " public static void main(String[] args) {\n"+ + " int i = 10;\n"+ + " if (foo() instanceof String s) {\n"+ + " ++i;\n"+ + " }\n"+ + " System.out.println(\"count:\"+X.count+\" i:\"+i);\n"+ + " }\n"+ + " public static Object foo() {\n"+ + " ++X.count;\n"+ + " return new Object();\n"+ + " } \n"+ + "}", + }, + "count:1 i:10", + compilerOptions); + } + public void test060() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int count;\n"+ + " public static void main(String[] args) {\n"+ + " int i = 10;\n"+ + " if (foo() instanceof String s) {\n"+ + " ++i;\n"+ + " }\n"+ + " System.out.println(\"count:\"+X.count+\" i:\"+i);\n"+ + " }\n"+ + " public static Object foo() {\n"+ + " ++X.count;\n"+ + " return new String(\"hello\");\n"+ + " } \n"+ + "}", + }, + "count:1 i:11", + compilerOptions); + } + public void test061() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int count;\n"+ + " static String STR = \"FAIL\";\n"+ + " @SuppressWarnings(\"preview\")\n"+ + " public static void main(String[] args) {\n"+ + " if ( switch(STR) {\n"+ + " default -> (CharSequence)\"PASS\";\n"+ + " } instanceof String s) {\n"+ + " System.out.println(s);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "PASS", + compilerOptions); + } + public void test062() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings(\"preview\")\n"+ + " public void foo(Object o) {\n"+ + " int len = (o instanceof String p) ? test(p -> p.length()) : test(p -> p.length());\n"+ + " }\n"+ + " public int test(FI fi) {\n" + + " return fi.length(\"\");\n" + + " } \n" + + " interface FI {\n" + + " public int length(String str);\n" + + " }" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int len = (o instanceof String p) ? test(p -> p.length()) : test(p -> p.length());\n" + + " ^\n" + + "Lambda expression\'s parameter p cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + // Same as above, but pattern variable in scope in false of conditional expression + public void test063() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings(\"preview\")\n"+ + " public void foo(Object o) {\n"+ + " int len = !(o instanceof String p) ? test(p -> p.length()) : test(p -> p.length());\n"+ + " }\n"+ + " public int test(FI fi) {\n" + + " return fi.length(\"\");\n" + + " } \n" + + " interface FI {\n" + + " public int length(String str);\n" + + " }" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int len = !(o instanceof String p) ? test(p -> p.length()) : test(p -> p.length());\n" + + " ^\n" + + "Lambda expression\'s parameter p cannot redeclare another local variable defined in an enclosing scope. \n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + // Test that pattern variables are seen by body of lamda expressions + public void test063a() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings(\"preview\")\n"+ + " public void foo(Object o) {\n"+ + " int len = (o instanceof String p) ? test(p1 -> p.length()) : test(p2 -> p.length());\n"+ + " }\n"+ + " public int test(FI fi) {\n" + + " return fi.length(\"\");\n" + + " } \n" + + " interface FI {\n" + + " public int length(String str);\n" + + " }" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int len = (o instanceof String p) ? test(p1 -> p.length()) : test(p2 -> p.length());\n" + + " ^\n" + + "p cannot be resolved\n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + // Test that pattern variables are seen by body of anonymous class creation + public void test063b() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings(\"preview\")\n"+ + " public void foo(Object o) {\n" + + " int len = (o instanceof String p) ? test(new X.FI() {\n" + + " @Override\n" + + " public int length(String p1) {\n" + + " return p.length();\n" + + " }\n" + + " }) : test(new X.FI() {\n" + + " @Override\n" + + " public int length(String p2) {\n" + + " return p.length();\n" + + " }\n" + + " });\n" + + " }\n" + + " public int test(FI fi) {\n" + + " return fi.length(\"\");\n" + + " }\n" + + " interface FI {\n" + + " public int length(String str);\n" + + " }" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " return p.length();\n" + + " ^\n" + + "p cannot be resolved\n" + + "----------\n", + "", + null, + true, + compilerOptions); + } + // Test that pattern variables are shadowed by parameters in an anonymous class + // creation + public void test063c() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String argv[]) {\n" + + " System.out.println(new X().foo(\"test\"));\n" + + " }\n" + + " @SuppressWarnings(\"preview\")\n"+ + " public int foo(Object o) {\n" + + " int len = (o instanceof String p) ? test(new X.FI() {\n" + + " String s = p; // allowed\n" + + " @Override\n" + + " public int length(String p) {\n" + + " return p.length();\n" + + " }\n" + + " }) : test(new X.FI() {\n" + + " @Override\n" + + " public int length(String p) {\n" + + " return p.length();\n" + + " }\n" + + " });\n" + + " return len;\n" + + " }\n" + + " public int test(FI fi) {\n" + + " return fi.length(\"fi\");\n" + + " }\n" + + " interface FI {\n" + + " public int length(String str);\n" + + " }" + + "}", + }, + "2", + compilerOptions); + } + public void test064() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n"+ + " public static void main(String argv[]) {\n" + + " System.out.println(new X().foo(\"foo\", \"test\"));\n" + + " }\n" + + " public boolean foo(Object obj, String s) {\n" + + " class Inner {\n" + + " public boolean foo(Object obj) {\n" + + " if (obj instanceof String s) {\n" + + " // s is shadowed now\n" + + " if (\"foo\".equals(s))\n" + + " return false;\n" + + " } else if (obj instanceof String s) { \n" + + " }\n"+ + " // s is not shadowed\n" + + " return \"test\".equals(s);\n" + + " }\n" + + " }\n" + + " return new Inner().foo(obj);\n" + + " }" + + "}", + }, + "false", + compilerOptions); + } + public void test065() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n"+ + " public static void main(String argv[]) {\n" + + " new X().foo(\"foo\");\n" + + " }\n" + + " public void foo(Object o) {\n" + + " if ((o instanceof String s)) {\n" + + " System.out.println(\"if:\" + s);\n" + + " } else {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " System.out.println(\"after:\" + s);\n" + + " }" + + "}", + }, + "if:foo\n" + + "after:foo", + compilerOptions); + } + public void test066() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n" + + " protected Object x = \"FIELD X\";\n" + + " public void f(Object obj, boolean b) {\n" + + " if ((x instanceof String x)) {\n" + + " System.out.println(x.toLowerCase());\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().f(Integer.parseInt(\"1\"), false);\n" + + " }\n" + + "}", + }, + "field x", + compilerOptions); + } + public void test067() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n" + + " protected Object x = \"FIELD X\";\n" + + " public void f(Object obj, boolean b) {\n" + + " if ((x instanceof String x) && x.length() > 0) {\n" + + " System.out.println(x.toLowerCase());\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().f(Integer.parseInt(\"1\"), false);\n" + + " }\n" + + "}", + }, + "field x", + compilerOptions); + } + public void test068() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n" + + " static void foo(Object o) {\n" + + " if (o instanceof X x || o instanceof X) {\n" + + " System.out.println(\"X\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "X", + compilerOptions); + } + public void test069() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "class XPlus extends X {}\n" + + "public class X {\n" + + " static void foo(Object o) {\n" + + " if (o instanceof X x && x instanceof XPlus x) {\n" + + " System.out.println(\"X\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o instanceof X x && x instanceof XPlus x) {\n" + + " ^\n" + + "Duplicate local variable x\n" + + "----------\n", + null, + true, + compilerOptions); + } + // Javac rejects this. Need to check with the spec authors + public void test070() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n" + + " static void foo(Object o) {\n" + + " if (o instanceof X x || o instanceof X x) {\n" + + " System.out.println(\"X\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "X", + compilerOptions); + } + // Javac rejects the code on the IF itself (same as above) + public void test071() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n" + + " static void foo(Object o) {\n" + + " if (o instanceof X x || o instanceof X x) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.println(x);\n" + + " ^\n" + + "x cannot be resolved to a variable\n" + + "----------\n", + null, + true, + compilerOptions); + } + // Javac rejects the code on the IF itself (same as above) + public void test072() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n" + + " static void foo(Object o) {\n" + + " if (o instanceof X x || o instanceof X x) {\n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " System.out.println(x);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(x);\n" + + " ^\n" + + "x cannot be resolved to a variable\n" + + "----------\n", + null, + true, + compilerOptions); + } + public void test073() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n" + + " static void foo(Object o) {\n" + + " try {\n" + + " if (!(o instanceof X x) || x != null || x!= null) { // allowed \n" + + " throw new IllegalArgumentException();\n" + + " }\n" + + " System.out.println(x); // allowed \n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace(System.out);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "java.lang.IllegalArgumentException\n" + + " at X.foo(X.java:6)\n" + + " at X.main(X.java:14)", + compilerOptions); + } + public void test074() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n" + + " static void foo(Object o) {\n" + + " if (!(o instanceof X x) || x != null || x!= null) {\n" + + " System.out.println(x); // not allowed\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.println(x); // not allowed\n" + + " ^\n" + + "x cannot be resolved to a variable\n" + + "----------\n", + null, + true, + compilerOptions); + } + public void test075() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n" + + " public boolean isMyError(Exception e) {\n" + + " return e instanceof MyError my && (my.getMessage().contains(\"something\") || my.getMessage().contains(\"somethingelse\"));\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"hello\");\n" + + " }\n" + + "}\n" + + "class MyError extends Exception {}\n", + }, + "hello", + compilerOptions); + } + public void test076() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "@SuppressWarnings(\"preview\")\n" + + "public class X {\n" + + " static void foo(Object o) {\n" + + " if ( (! (o instanceof String a)) || (o instanceof String a) ) {\n" + + " // Nothing\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"hello\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if ( (! (o instanceof String a)) || (o instanceof String a) ) {\n" + + " ^\n" + + "Duplicate local variable a\n" + + "----------\n", + null, + true, + compilerOptions); + } + // Test that a non final pattern variable can be assigned again + public void test077() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(Object o) {\n" + + " if (o instanceof X x) {\n" + + " x = null;\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "null", + compilerOptions); + } + // Test that a final pattern variable cannot be assigned again + public void test078() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(Object o) {\n" + + " if (o instanceof final X x) {\n" + + " x = null;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " x = null;\n" + + " ^\n" + + "The pattern variable x is final and cannot be assigned again\n" + + "----------\n", + null, + true, + compilerOptions); + } + public void test079() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(Object o) {\n" + + " if (o instanceof public X x) {\n" + + " x = null;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (o instanceof public X x) {\n" + + " ^\n" + + "Illegal modifier for the pattern variable x; only final is permitted\n" + + "----------\n", + null, + true, + compilerOptions); + } + // test that we allow final for a pattern instanceof variable + public void test080() { + Map compilerOptions = getCompilerOptions(true); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(Object o) {\n" + + " if (o instanceof final X x) {\n" + + " System.out.println(\"X\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(new X());\n" + + " }\n" + + "}", + }, + "X", + compilerOptions); + } + public void test081() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(T o) {\n" + + " // Rejected\n" + + " boolean b1 = (o instanceof String a) ? (o instanceof String a) : false;\n" + + " boolean b2 = !(o instanceof String a) ? (o instanceof String a) : false;\n" + + " boolean b3 = (o instanceof String a) ? !(o instanceof String a) : false;\n" + + " boolean b4 = !(o instanceof String a) ? !(o instanceof String a) : false;\n" + + " \n" + + " boolean b5 = (o instanceof String a) ? true : (o instanceof String a);\n" + + " boolean b6 = !(o instanceof String a) ? true : (o instanceof String a);\n" + + " boolean b7 = (o instanceof String a) ? true : !(o instanceof String a);\n" + + " boolean b8 = !(o instanceof String a) ? true : !(o instanceof String a);\n" + + " \n" + + " boolean b9 = (o instanceof String) ? (o instanceof String a) : (o instanceof String a);\n" + + " boolean b10 = (o instanceof String) ? !(o instanceof String a) : !(o instanceof String a);\n" + + " \n" + + " // These are allowed\n" + + " boolean b11 = (o instanceof String) ? !(o instanceof String a) : !!(o instanceof String a);\n" + + " boolean b12 = (o instanceof String) ? !(o instanceof String a) : (o instanceof String a);\n" + + " boolean b21 = (o instanceof String a) ? false : ((o instanceof String a) ? false : true); \n" + + " } \n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " boolean b1 = (o instanceof String a) ? (o instanceof String a) : false;\n" + + " ^\n" + + "A pattern variable with the same name is already defined in the statement\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " boolean b2 = !(o instanceof String a) ? (o instanceof String a) : false;\n" + + " ^\n" + + "A pattern variable with the same name is already defined in the statement\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " boolean b3 = (o instanceof String a) ? !(o instanceof String a) : false;\n" + + " ^\n" + + "A pattern variable with the same name is already defined in the statement\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " boolean b4 = !(o instanceof String a) ? !(o instanceof String a) : false;\n" + + " ^\n" + + "A pattern variable with the same name is already defined in the statement\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " boolean b5 = (o instanceof String a) ? true : (o instanceof String a);\n" + + " ^\n" + + "A pattern variable with the same name is already defined in the statement\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " boolean b6 = !(o instanceof String a) ? true : (o instanceof String a);\n" + + " ^\n" + + "A pattern variable with the same name is already defined in the statement\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " boolean b7 = (o instanceof String a) ? true : !(o instanceof String a);\n" + + " ^\n" + + "A pattern variable with the same name is already defined in the statement\n" + + "----------\n" + + "8. ERROR in X.java (at line 12)\n" + + " boolean b8 = !(o instanceof String a) ? true : !(o instanceof String a);\n" + + " ^\n" + + "A pattern variable with the same name is already defined in the statement\n" + + "----------\n" + + "9. ERROR in X.java (at line 14)\n" + + " boolean b9 = (o instanceof String) ? (o instanceof String a) : (o instanceof String a);\n" + + " ^\n" + + "A pattern variable with the same name is already defined in the statement\n" + + "----------\n" + + "10. ERROR in X.java (at line 15)\n" + + " boolean b10 = (o instanceof String) ? !(o instanceof String a) : !(o instanceof String a);\n" + + " ^\n" + + "A pattern variable with the same name is already defined in the statement\n" + + "----------\n", + null, + true, + compilerOptions); + } + public void testBug570831a() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void run() {\n" + + " String s = \"s\";\n" + + " Object o = null;\n" + + " {\n" + + " while (!(o instanceof String v)) {\n" + + " o = null;\n" + + " }\n" + + " s = s + v; // allowed\n" + + " }\n" + + " for (int i = 0; i < 1; i++) {\n" + + " s = s + v; // not allowed\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " s = s + v; // not allowed\n" + + " ^\n" + + "v cannot be resolved to a variable\n" + + "----------\n", + null, + true, + compilerOptions); + } + public void testBug570831b() { + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void run() {\n" + + " String s = \"s\";\n" + + " Object o = null;\n" + + " {\n" + + " int local = 0;\n" + + " while (!(o instanceof String v)) {\n" + + " o = null;\n" + + " }\n" + + " s = s + v; // allowed\n" + + " }\n" + + " for (int i = 0; i < 1; i++) {\n" + + " s = s + v; // not allowed\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " s = s + v; // not allowed\n" + + " ^\n" + + "v cannot be resolved to a variable\n" + + "----------\n", + null, + true, + compilerOptions); + } + public void testBug572380_1() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X1.java", + "\n" + + "public class X1 {\n" + + " boolean b1, b2, b3;\n" + + "\n" + + " static boolean bubbleOut(Object obj) {\n" + + " return obj instanceof X1 that && that.b1 && that.b2 && that.b3;\n" + + " }\n" + + "\n" + + " static boolean propagateTrueIn(Object obj) {\n" + + " return obj instanceof X1 that && (that.b1 && that.b2 && that.b3);\n" + + " }\n" + + "\n" + + " public static void main(String[] obj) {\n" + + " var ip = new X1();\n" + + " ip.b1 = ip.b2 = ip.b3 = true;\n" + + " System.out.println(bubbleOut(ip) && propagateTrueIn(ip));\n" + + " }\n" + + "\n" + + "}\n", + }, + "true", + options); + } + public void testBug572380_2() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X1.java", + "\n" + + "public class X1 {\n" + + " boolean b1, b2, b3;\n" + + " static boolean testErrorOr(Object obj) {\n" + + " return (!(obj instanceof X1 that)) || that.b1 && that.b2;\n" + + " }\n" + + " \n" + + " public static void main(String[] obj) {\n" + + " var ip = new X1();\n" + + " ip.b1 = ip.b2 = ip.b3 = true;\n" + + " System.out.println(testErrorOr(ip));\n" + + " }\n" + + "\n" + + "}\n", + }, + "true", + options); + } + public void testBug574892() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X1.java", + "\n" + + "public class X1 {\n" + + " static boolean testConditional(Object obj) {\n" + + " return obj instanceof Integer other\n" + + " && ( other.intValue() > 100\n" + + " ? other.intValue() < 200 : other.intValue() < 50);\n" + + " }\n" + + " public static void main(String[] obj) {\n" + + " System.out.println(testConditional(101));\n" + + " }\n" + + "}\n", + }, + "true", + options); + } + public void testBug572431_1() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public void something () {\n" + + " boolean bool = true;\n" + + " Object object = null;\n" + + " if (object instanceof String string) {\n" + + " } else if (bool && object instanceof Integer integer) {\n" + + " }\n" + + " }\n" + + " static public void main (String[] args) throws Exception {\n" + + " }\n" + + " }", + }, + "", + options); + + } + public void testBug572431_2() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public void something () {\n" + + " boolean bool = true;\n" + + " Object object = null;\n" + + " if (object instanceof String string) {\n" + + " } else if (bool) {\n" + + " if (object instanceof Integer integer) {\n" + + " }\n" + + " }\n" + + " }\n" + + " static public void main (String[] args) throws Exception {\n" + + " }\n" + + "}", + }, + "", + options); + + } + public void testBug572431_3() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public void something () {\n" + + " boolean bool = true;\n" + + " Object object = null;\n" + + " if (bool && object instanceof Integer i) {\n" + + " }\n" + + " }\n" + + " static public void main (String[] args) throws Exception {\n" + + " }\n" + + "}", + }, + "", + options); + + } + public void testBug572431_4() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public void something () {\n" + + " boolean bool = true;\n" + + " Object object = null;\n" + + " if (!(object instanceof Integer i)) {\n" + + " }\n" + + " }\n" + + " static public void main (String[] args) throws Exception {\n" + + " }\n" + + "}", + }, + "", + options); + + } + public void testBug572431_5() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public void something () {\n" + + " boolean bool = true;\n" + + " Object object = null;\n" + + " if (false) {\n" + + " } else if (!(object instanceof Integer i)) {\n" + + " }\n" + + " }\n" + + " static public void main (String[] args) throws Exception {\n" + + " }\n" + + "}", + }, + "", + options); + + } + public void testBug572431_6() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static public void something () {\n" + + " boolean bool = true;\n" + + " Object object = null;\n" + + " for (int i = 0; i < 10; i++) {\n" + + " if (object instanceof String string) {\n" + + " System.out.println(i);\n" + + " } else if (bool) {\n" + + " if (i == 4) continue;\n" + + " System.out.println(i);\n" + + " }\n" + + " }\n" + + " }\n" + + " static public void main (String[] args) throws Exception {\n" + + " }\n" + + "}", + }, + "", + options); + + } + public void testBug573880() { + if (this.complianceLevel < ClassFileConstants.JDK17) + return; + Map compilerOptions = getCompilerOptions(true); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Object o) {\n" + + " if (o instanceof var s) {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (o instanceof var s) {\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n", + null, + true, + compilerOptions); + } + public void testBug574906() { + Map options = getCompilerOptions(false); + runConformTest( + new String[] { + "X1.java", + "\n" + + "public class X1 {\n" + + " static boolean testConditional(Object obj) {\n" + + " return obj instanceof Number oNum && oNum.intValue() < 0 && !(oNum instanceof Integer);\n" + + " }\n" + + " public static void main(String[] obj) {\n" + + " System.out.println(testConditional(-2f));\n" + + " }\n" + + "}\n", + }, + "true", + options); + } + public void testBug575035() throws ClassFormatException, IOException { + Map options = getCompilerOptions(false); + String source = + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + " \n" + + "public class Test {\n" + + " @Target({ ElementType.LOCAL_VARIABLE})\n" + + " @Retention(RetentionPolicy.RUNTIME)\n" + + " @interface Var {}\n" + + " @Target({ ElementType.TYPE_USE})\n" + + " @Retention(RetentionPolicy.RUNTIME)\n" + + " @interface Type {}\n" + + " public static void main(String[] args) {" + + " @Var @Type String y = \"OK: \";\n" + + " if (((Object)\"local\") instanceof @Var @Type String x) {\n" + + " System.out.println(y + x);\n" + + " }\n" + + " }\n" + + "}"; + String expectedOutput = "" + + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 4, Locals: 4\n" + + " public static void main(String[] args);\n" + + " 0 ldc [16]\n" + + " 2 astore_1 [y]\n" + + " 3 ldc [18]\n" + + " 5 astore_3 [ instanceOfPatternExpressionValue]\n" + + " 6 aload_3 [ instanceOfPatternExpressionValue]\n" + + " 7 instanceof String [20]\n" + + " 10 ifeq 50\n" + + " 13 aload_3 [ instanceOfPatternExpressionValue]\n" + + " 14 checkcast String [20]\n" + + " 17 dup\n" + + " 18 astore_2\n" + + " 19 aload_3\n" + + " 20 checkcast String [20]\n" + + " 23 if_acmpne 50\n" + + " 26 getstatic System.out : PrintStream [22]\n" + + " 29 new StringBuilder [28]\n" + + " 32 dup\n" + + " 33 aload_1 [y]\n" + + " 34 invokestatic String.valueOf(Object) : String [30]\n" + + " 37 invokespecial StringBuilder(String) [34]\n" + + " 40 aload_2 [x]\n" + + " 41 invokevirtual StringBuilder.append(String) : StringBuilder [37]\n" + + " 44 invokevirtual StringBuilder.toString() : String [41]\n" + + " 47 invokevirtual PrintStream.println(String) : void [45]\n" + + " 50 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 3, line: 14]\n" + + " [pc: 26, line: 15]\n" + + " [pc: 50, line: 17]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 51] local: args index: 0 type: String[]\n" + + " [pc: 3, pc: 51] local: y index: 1 type: String\n" + + " [pc: 26, pc: 50] local: x index: 2 type: String\n" + + " [pc: 6, pc: 20] local: instanceOfPatternExpressionValue index: 3 type: Object\n" + + " Stack map table: number of frames 1\n" + + " [pc: 50, append: {String}]\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #59 @Type(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 3, pc: 51] index: 1\n" + + " )\n" + + " #59 @Type(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 26, pc: 50] index: 2\n" + + " )\n" + + "\n"; + checkClassFile("Test", source, expectedOutput, ClassFileBytesDisassembler.DETAILED | ClassFileBytesDisassembler.COMPACT); + runConformTest( + new String[] { + "Test.java", + source, + }, + "OK: local", + options); + + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PolymorphicSignatureTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PolymorphicSignatureTest.java new file mode 100644 index 0000000000..321b2e5f36 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PolymorphicSignatureTest.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2011, 2018 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class PolymorphicSignatureTest extends AbstractRegressionTest { + static { +// TESTS_NAMES = new String[] { "testBug515863" }; + } + 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"); + } + public void test0002() { + this.runConformTest( + new String[] { + "X.java", + "import static java.lang.invoke.MethodHandles.*; \n" + + "import java.lang.invoke.MethodHandle;\n" + + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " MethodHandle mh = dropArguments(insertArguments(identity(int.class), 0, 42), 0, Object[].class);\n" + + " int value = (int)mh.invokeExact(new Object[0]);\n" + + " System.out.println(value);\n"+ + " }\n" + + "}" + }, + "42"); + } + public void testBug515863() { + runConformTest( + new String[] { + "Test.java", + "import java.lang.invoke.MethodHandle;\n" + + "import java.util.ArrayList;\n" + + "import java.util.Collections;\n" + + "\n" + + "public class Test {\n" + + " \n" + + " public void foo() throws Throwable {\n" + + " \n" + + " MethodHandle mh = null;\n" + + " mh.invoke(null); // works, no issues.\n" + + " mh.invoke(null, new ArrayList<>()); // Bug 501457 fixed this\n" + + " mh.invoke(null, Collections.emptyList()); // This triggers UOE\n" + + " \n" + + " }\n" + + "}\n" + }); + } + public void testBug475996() { + if (!isJRE9Plus) + return; // VarHandle is @since 9 + runConformTest( + new String[] { + "X.java", + "import java.lang.invoke.VarHandle;\n" + + "public class X {\n" + + " static class Token {}\n" + + " Token NIL = new Token();\n" + + " VarHandle RESULT;\n" + + " void call(T t) {\n" + + " RESULT.compareAndSet(this, null, (t==null) ? NIL : t);\n" + + " }\n" + + "" + + "}\n" + }); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PreviewFeatureTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PreviewFeatureTest.java new file mode 100644 index 0000000000..88c222f670 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PreviewFeatureTest.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * Copyright (c) 2021 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.JavaFeature; + +import junit.framework.Test; + +public class PreviewFeatureTest extends AbstractRegressionTest9 { + + static { +// TESTS_NUMBERS = new int [] { 40 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] { "test001"}; + } + + public static Class testClass() { + return PreviewFeatureTest.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_16); + } + public PreviewFeatureTest(String testName){ + super(testName); + } + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + if (isJRE17Plus) { + options.put(CompilerOptions.OPTION_Release, CompilerOptions.ENABLED); + } + return options; + } + /* + * Preview API, --enable-preview=false, SuppressWarning=No + */ + public void test001() { + if (isJRE17Plus) { + return; + } + Map options = getCompilerOptions(); + String old = options.get(CompilerOptions.OPTION_EnablePreviews); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + try { + runNegativeTest( + new String[] { + "X.java", + "import javax.lang.model.element.Modifier;\n"+ + "public class X {\n"+ + " Zork z = null;\n" + + "public Modifier getModifier() {\n"+ + " return Modifier.SEALED;\n"+ + " }\n"+ + " public Class[] getPermittedClasses() {\n"+ + " return this.getClass().getPermittedSubclasses();\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z = null;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " return Modifier.SEALED;\n" + + " ^^^^^^^^^^^^^^^\n" + + "You are using an API that is part of a preview feature and may be removed in future\n" + + "----------\n" + + "3. WARNING in X.java (at line 8)\n" + + " return this.getClass().getPermittedSubclasses();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "You are using an API that is part of a preview feature and may be removed in future\n" + + "----------\n", + null, + true, + options); + } finally { + options.put(CompilerOptions.OPTION_EnablePreviews, old); + } + } + /* + * Preview API, --enable-preview=false, SuppressWarning=yes + */ + public void test002() { + if (this.complianceLevel >= ClassFileConstants.JDK17) { + return; + } + Map options = getCompilerOptions(); + String old = options.get(CompilerOptions.OPTION_EnablePreviews); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + try { + runNegativeTest( + new String[] { + "X.java", + "import javax.lang.model.element.Modifier;\n"+ + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n"+ + " Zork z = null;\n" + + "public Modifier getModifier() {\n"+ + " return Modifier.SEALED;\n"+ + " }\n"+ + " public Class[] getPermittedClasses() {\n"+ + " return this.getClass().getPermittedSubclasses();\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z = null;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, + options); + } finally { + options.put(CompilerOptions.OPTION_EnablePreviews, old); + } + } + /* + * Preview API, --enable-preview=true, SuppressWarning=No + */ + public void test003() { + if (this.complianceLevel < ClassFileConstants.getLatestJDKLevel()) + return; + Map options = getCompilerOptions(); + String old = options.get(CompilerOptions.OPTION_EnablePreviews); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + try { + runNegativeTest( + new String[] { + "X.java", + "import javax.lang.model.element.Modifier;\n"+ + "public class X {\n"+ + " Zork z = null;\n" + + "public Modifier getModifier() {\n"+ + " return Modifier.SEALED;\n"+ + " }\n"+ + " public Class[] getPermittedClasses() {\n"+ + " return this.getClass().getPermittedSubclasses();\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z = null;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, + options); + } finally { + options.put(CompilerOptions.OPTION_EnablePreviews, old); + } + } + /* + * Preview API, --enable-preview=true, SuppressWarning=Yes + */ + public void test004() { + if (this.complianceLevel < ClassFileConstants.getLatestJDKLevel()) + return; + Map options = getCompilerOptions(); + String old = options.get(CompilerOptions.OPTION_EnablePreviews); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + try { + runNegativeTest( + new String[] { + "X.java", + "import javax.lang.model.element.Modifier;\n"+ + "@SuppressWarnings(\"preview\")\n"+ + "public class X {\n"+ + " Zork z = null;\n" + + "public Modifier getModifier() {\n"+ + " return Modifier.SEALED;\n"+ + " }\n"+ + " public Class[] getPermittedClasses() {\n"+ + " return this.getClass().getPermittedSubclasses();\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z = null;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, + options); + } finally { + options.put(CompilerOptions.OPTION_EnablePreviews, old); + } + } + public void test005() { + if (this.complianceLevel < ClassFileConstants.JDK16) + return; + Map options = getCompilerOptions(); + String old = options.get(CompilerOptions.OPTION_EnablePreviews); + if (this.complianceLevel == ClassFileConstants.getLatestJDKLevel()) + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + try { + if (this.complianceLevel < ClassFileConstants.getLatestJDKLevel()) + assertFalse(JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(new CompilerOptions(options))); + else + assertTrue(JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(new CompilerOptions(options))); + } finally { + options.put(CompilerOptions.OPTION_EnablePreviews, old); + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemConstructorTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemConstructorTest.java new file mode 100644 index 0000000000..e0acede438 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemConstructorTest.java @@ -0,0 +1,512 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 185682 - Increment/decrement operators mark local variables as read + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class ProblemConstructorTest extends AbstractRegressionTest { + +public ProblemConstructorTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} +public static Class testClass() { + return ProblemConstructorTest.class; +} + +public void test001() { + this.runNegativeTest( + new String[] { + "prs/Test1.java", + "package prs; \n" + + "import java.io.IOException; \n" + + "public class Test1 { \n" + + "String s = 3; \n" + + "Test1() throws IOException { \n" + + "} \n" + + "}" + }, + "----------\n" + + "1. ERROR in prs\\Test1.java (at line 4)\n" + + " String s = 3; \n" + + " ^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n", + null, + true, + null, + true, + false, + false); + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "prs/Test2.java", + "package prs; \n" + + "import java.io.IOException; \n" + + "public class Test2 { \n" + + "public void foo() { \n" + + "try { \n" + + "Test1 t = new Test1(); \n" + + "System.out.println(); \n" + + "} catch(IOException e) \n" + + "{ \n" + + "e.printStackTrace(); \n" + + "} \n" + + "} \n" + + "}" + }, + // compiler results + "" /* expected compiler log */, + // runtime results + null /* do not check output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.SKIP /* skip javac tests */); +} +// 49843 +public void test002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public X();\n" + + " public Y();\n" + + " \n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public X();\n" + + " ^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public Y();\n" + + " ^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " public Y();\n" + + " ^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=163443 +public void test003() { + this.runNegativeTest( + new String[] { + "Example.java", + "class Example {\n" + + " private Example() {\n" + + " }\n" + + " public Example(int i) {\n" + + " }\n" + + "}\n" + + "class E1 {\n" + + " private E1(int i) {}\n" + + " private E1(long l) {}\n" + + "}\n" + + "class E2 {\n" + + " private E2(int i) {}\n" + + "}\n" + + "class E3 {\n" + + " public E3(int i) {}\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in Example.java (at line 2)\n" + + " private Example() {\n" + + " ^^^^^^^^^\n" + + "The constructor Example() is never used locally\n" + + "----------\n" + + "2. ERROR in Example.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=201912, test to make sure that unused public members of +// private class (including constructors, fields, types and methods) get warned about. +public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private class M { \n" + // expect unused field, method, constructor and type warnings + " private int state = 0;\n" + + " public int unusedMethod() { return this.state; }\n" + + " public M (int state) { this.state = state;} \n" + + " public int unusedField = 0;\n" + + " public class N {}\n" + + " }\n" + + " private class N { \n" + // No warnings should come from within here + " private int state = 0;\n" + + " public int usedMethod() { new O(); return new N(this.state + this.usedField).state; }\n" + + " public N (int state) { this.state = state;} \n" + + " public int usedField = 0;\n" + + " public class O {}\n" + + " }\n" + + " public class P { \n" + // No warnings should come from within here. + " private int state = 0;\n" + + " public int unusedMethod() { return this.state; }\n" + + " public P (int state) { this.state = state;} \n" + + " public int unusedField = 0;\n" + + " public class N {}\n" + + " }\n" + + " public M foo(M m, N n) {\n" + + " n.usedMethod(); return m;\n" + + " }\n" + + "} \n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public int unusedMethod() { return this.state; }\n" + + " ^^^^^^^^^^^^^^\n" + + "The method unusedMethod() from the type X.M is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " public M (int state) { this.state = state;} \n" + + " ^^^^^^^^^^^^^\n" + + "The constructor X.M(int) is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " public int unusedField = 0;\n" + + " ^^^^^^^^^^^\n" + + "The value of the field X.M.unusedField is not used\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " public class N {}\n" + + " ^\n" + + "The type X.M.N is never used locally\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=264991, wrong unused warning reported. Test to ensure that +// we DON'T complain about the constructor of B not being used (as its removal would result in a compile +// error since its base class does not have a no-arg constructor for the synthesized default constructor +// to invoke. +public void test005() { + String[] testFiles = new String[] { + "A.java", + "public class A {\n" + + " public A(String s) {\n" + + " B.test();\n" + + " }\n" + + "\n" + + " private static class B extends A {\n" + + " public B () { super(\"\"); }\n" + + " private static void test() {};\n" + + " }\n" + + "}\n" + }; + if (!isMinimumCompliant(ClassFileConstants.JDK11)) { + this.runNegativeTest(testFiles, + "----------\n" + + "1. WARNING in A.java (at line 3)\n" + + " B.test();\n" + + " ^^^^^^^^\n" + + "Access to enclosing method test() from the type A.B is emulated by a synthetic accessor method\n" + + "----------\n"); + } else { + this.runConformTest(testFiles); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=265142, wrong unused warning reported. Test to ensure that +//we DO complain about the constructor of B not being used when its base class has a no-arg constructor +public void test006() { + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in A.java (at line 8)\n" + + " public B () { super(\"\"); }\n" + + " ^^^^\n" + + "The constructor A.B() is never used locally\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in A.java (at line 3)\n" + + " B.test();\n" + + " ^^^^^^^^\n" + + "Access to enclosing method test() from the type A.B is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. WARNING in A.java (at line 8)\n" + + " public B () { super(\"\"); }\n" + + " ^^^^\n" + + "The constructor A.B() is never used locally\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " public A(String s) {\n" + + " B.test();\n" + + " }\n" + + " public A() {}\n" + + "\n" + + " private static class B extends A {\n" + + " public B () { super(\"\"); }\n" + + " private static void test() {};\n" + + " }\n" + + "}\n" + }, + errMessage); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=265142, wrong unused warning reported. Test to ensure that +//we can compile the program successfully after deleting the unused constructor. +public void test007() { + this.runConformTest( + new String[] { + "A.java", + "public class A {\n" + + " public A(String s) {\n" + + " B.test();\n" + + " }\n" + + " public A() {}\n" + + "\n" + + " private static class B extends A {\n" + + " private static void test() {};\n" + + " }\n" + + "}\n" + }); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=265142, wrong unused warning reported. Test to ensure that +//we DON'T complain about unused constructor when the super class's default constructor is not visible. +public void test008() { + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " public A(String s) {this();}\n" + + " private A() {}\n" + + "}\n" + + "class C {\n" + + " private static class B extends A {\n" + + " public B () { super(\"\"); }\n" + + " static void foo() {}\n" + + " }\n" + + " C() {\n" + + " B.foo();\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=265142, wrong unused warning reported. Test to ensure that +//we DO complain about unused constructor when the super class's default constructor is visible. +public void test009() { + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " public A(String s) {}\n" + + " protected A() {}\n" + + "}\n" + + "class C {\n" + + " private static class B extends A {\n" + + " public B () { super(\"\"); }\n" + + " static void foo() {}\n" + + " }\n" + + " C() {\n" + + " B.foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in A.java (at line 7)\n" + + " public B () { super(\"\"); }\n" + + " ^^^^\n" + + "The constructor C.B() is never used locally\n" + + "----------\n"); +} +//Bug 408038 - Classes which implement Externalizable should not have an unused constructor warning +public void test408038a() { + if (this.complianceLevel < ClassFileConstants.JDK1_6) + return; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private class Y {\n" + + " static final int i = 10;\n" + + " public Y() {}\n" + + " public Y(int x) {System.out.println(x);}\n" + + " }\n" + + "\n" + + " public void zoo() {\n" + + " System.out.println(Y.i);\n" + + " Y y = new Y(5);\n" + + " System.out.println(y);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public Y() {}\n" + + " ^^^\n" + + "The constructor X.Y() is never used locally\n" + + "----------\n", + null, + true, + null + ); +} +//Bug 408038 - Classes which implement Externalizable should not have an unused constructor warning +public void test408038b() { + if (this.complianceLevel < ClassFileConstants.JDK1_6) + return; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static class Y {\n" + + " static final int i = 10;\n" + + " public Y() {}\n" + + " public Y(int x) {System.out.println(x);}\n" + + " }\n" + + "\n" + + " public void zoo() {\n" + + " System.out.println(Y.i);\n" + + " Y y = new Y(5);\n" + + " System.out.println(y);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public Y() {}\n" + + " ^^^\n" + + "The constructor X.Y() is never used locally\n" + + "----------\n", + null, + true, + null + ); +} +//Bug 408038 - Classes which implement Externalizable should not have an unused constructor warning +public void test408038c() { + if (this.complianceLevel < ClassFileConstants.JDK1_6) + return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Externalizable;\n" + + "import java.io.IOException;\n" + + "import java.io.ObjectInput;\n" + + "import java.io.ObjectOutput;\n" + + "public class X {\n" + + " private static class Y implements Externalizable {\n" + + " static final int i = 10;\n" + + " public Y() {}\n" + + " public Y(int x) {System.out.println(x);}\n" + + "\n" + + " @Override\n" + + " public void writeExternal(ObjectOutput out) throws IOException {\n" + + " }\n" + + "\n" + + " @Override \n" + + " public void readExternal(ObjectInput in) throws IOException,\n" + + " ClassNotFoundException {\n" + + " }\n" + + " }\n" + + " public void zoo() {\n" + + " System.out.println(Y.i);\n" + + " Y y = new Y(5);\n" + + " System.out.println(y);\n" + + " }\n" + + "}" + }, + "", + null, + true, + null + ); +} +//Bug 408038 - Classes which implement Externalizable should not have an unused constructor warning +public void test408038d() { + if (this.complianceLevel < ClassFileConstants.JDK1_6) + return; + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Externalizable;\n" + + "import java.io.IOException;\n" + + "import java.io.ObjectInput;\n" + + "import java.io.ObjectOutput;\n" + + "public class X {\n" + + " private class Y implements Externalizable {\n" + + " static final int i = 10;\n" + + " public Y() {}\n" + + " public Y(int x) {System.out.println(x);}\n" + + "\n" + + " @Override\n" + + " public void writeExternal(ObjectOutput out) throws IOException {\n" + + " }\n" + + "\n" + + " @Override \n" + + " public void readExternal(ObjectInput in) throws IOException,\n" + + " ClassNotFoundException {\n" + + " }\n" + + " }\n" + + " public void zoo() {\n" + + " System.out.println(Y.i);\n" + + " Y y = new Y(5);\n" + + " System.out.println(y);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " public Y() {}\n" + + " ^^^\n" + + "The constructor X.Y() is never used locally\n" + + "----------\n", + null, + true, + null + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=408038, +//Classes which implement Externalizable should not have an unused constructor warning +//The test case is not directly related to the bug. It was discovered as a result +//of the bug. Please see comment 16 bullet 4 in bugzilla. +public void test408038e() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " int i;\n" + + " private X(int x) {i = x;}\n" + + " X() {}\n" + + " public int foo() {\n" + + " X x = new X();\n" + + " return x.i;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private X(int x) {i = x;}\n" + + " ^^^^^^^^\n" + + "The constructor X(int) is never used locally\n" + + "----------\n"); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java new file mode 100644 index 0000000000..29ee0715e3 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java @@ -0,0 +1,8786 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 328281 - visibility leaks not detected when analyzing unused field in private class + * bug 379784 - [compiler] "Method can be static" is not getting reported + * bug 379834 - Wrong "method can be static" in presence of qualified super and different staticness of nested super class. + * Jesper S Moller - Contributions for + * bug 378674 - "The method can be declared as static" is wrong + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.ToolFactory; +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.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class ProblemTypeAndMethodTest extends AbstractRegressionTest { +public ProblemTypeAndMethodTest(String name) { + super(name); +} +// 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[] { "test376550" }; +// TESTS_NUMBERS = new int[] { 113 }; +// TESTS_RANGE = new int[] { 108, -1 }; +} + +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public static Class testClass() { + return ProblemTypeAndMethodTest.class; +} +public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface Moosh { void foo(); }\n" + + "\n" + + " static abstract class A implements Moosh {}\n" + + "\n" + + " static class W extends A {}\n" + + " static class Y extends A {}\n" + + " static class Z extends A {}\n" + + " public static void main(String[] args) {\n" + + " new W(); // throws ClassFormatError\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " static class W extends A {}\n" + + " ^\n" + + "The type X.W must implement the inherited abstract method X.Moosh.foo()\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " static class Y extends A {}\n" + + " ^\n" + + "The type X.Y must implement the inherited abstract method X.Moosh.foo()\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " static class Z extends A {}\n" + + " ^\n" + + "The type X.Z must implement the inherited abstract method X.Moosh.foo()\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* no custom options */, + true /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + false /* do not perform statements recovery */); + ClassFileReader reader = getClassFileReader(OUTPUT_DIR + File.separator +"X$W.class", "X$W"); + IBinaryMethod[] methods = reader.getMethods(); + assertEquals("Wrong size", 2, methods.length); + int counter = 0; + for (int i = 0; i < 2; i++) { + IBinaryMethod method = methods[i]; + if (new String(method.getSelector()).equals("foo")) { + counter++; + } + } + assertEquals("Wrong number of foo method", 1, counter); + + reader = getClassFileReader(OUTPUT_DIR + File.separator +"X$Y.class", "X$Y"); + methods = reader.getMethods(); + assertEquals("Wrong size", 2, methods.length); + counter = 0; + for (int i = 0; i < 2; i++) { + IBinaryMethod method = methods[i]; + if (new String(method.getSelector()).equals("foo")) { + counter++; + } + } + assertEquals("Wrong number of foo method", 1, counter); + + reader = getClassFileReader(OUTPUT_DIR + File.separator +"X$Z.class", "X$Z"); + methods = reader.getMethods(); + assertEquals("Wrong size", 2, methods.length); + counter = 0; + for (int i = 0; i < 2; i++) { + IBinaryMethod method = methods[i]; + if (new String(method.getSelector()).equals("foo")) { + counter++; + } + } + assertEquals("Wrong number of foo method", 1, counter); +} + +public void test002() { + this.runNegativeTest(new String[] { + "X.java", + "public class X extends Zork {\n" + + " void foo() {\n" + + " Zork z = this;\n" + + " String s = this;\n" + + " Zork2 z2 = this;\n" + + " }\n" + + " Zork fz = this;\n" + + " String fs = this;\n" + + " Zork2 fz2 = this;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z = this;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " String s = this;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from X to String\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Zork2 z2 = this;\n" + + " ^^^^^\n" + + "Zork2 cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " Zork fz = this;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " String fs = this;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from X to String\n" + + "----------\n" + + "7. ERROR in X.java (at line 9)\n" + + " Zork2 fz2 = this;\n" + + " ^^^^^\n" + + "Zork2 cannot be resolved to a type\n" + + "----------\n"); +} + +public void test003() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " Zork field;\n" + + " \n" + + " void foo(Y y) {\n" + + " Object o = y.foo();\n" + + " Object s = y.slot;\n" + + " y.bar(null);\n" + + " Object s2 = new Y().slot;\n" + + " Object f = field;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " Zork foo() { return null; }\n" + + " void bar(Zork z) {}\n" + + " Zork slot;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Zork field;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Object o = y.foo();\n" + + " ^^^\n" + + "The method foo() from the type Y refers to the missing type Zork\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " Object s = y.slot;\n" + + " ^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " y.bar(null);\n" + + " ^^^\n" + + "The method bar(Zork) from the type Y refers to the missing type Zork\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " Object s2 = new Y().slot;\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " Object f = field;\n" + + " ^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 13)\n" + + " Zork foo() { return null; }\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 14)\n" + + " void bar(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "9. ERROR in X.java (at line 15)\n" + + " Zork slot;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 +public void test004() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q.Zork;\n" + + "\n" + + "public class OtherFoo extends Zork{\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + "q/Zork.java", //----------------------------------------------------------------------- + "package q;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import p.OtherFoo;\n" + + "import q.Zork;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " OtherFoo ofoo;\n" + + " String s1 = ofoo.foo;\n" + + " String s2 = ofoo.bar();\n" + + " String s3 = ofoo.new OtherMember();\n" + + " ofoo.baz(this);\n" + + " }\n" + + " void bar() {\n" + + " OtherX ox;\n" + + " String s1 = ox.foo;\n" + + " String s2 = ox.bar();\n" + + " String s3 = ox.new OtherMember();\n" + + " ox.baz(this);\n" + + " }\n" + + "} \n" + + "\n" + + "class OtherX {\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " String s1 = ofoo.foo;\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from Zork to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " String s2 = ofoo.bar();\n" + + " ^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Zork to String\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " String s3 = ofoo.new OtherMember();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from OtherFoo.OtherMember to String\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " ofoo.baz(this);\n" + + " ^^^\n" + + "The method baz(Zork) in the type OtherFoo is not applicable for the arguments (X)\n" + + "----------\n" + + "5. ERROR in X.java (at line 14)\n" + + " String s1 = ox.foo;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from Zork to String\n" + + "----------\n" + + "6. ERROR in X.java (at line 15)\n" + + " String s2 = ox.bar();\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from Zork to String\n" + + "----------\n" + + "7. ERROR in X.java (at line 16)\n" + + " String s3 = ox.new OtherMember();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from OtherX.OtherMember to String\n" + + "----------\n" + + "8. ERROR in X.java (at line 17)\n" + + " ox.baz(this);\n" + + " ^^^\n" + + "The method baz(Zork) in the type OtherX is not applicable for the arguments (X)\n" + + "----------\n", + null, + false); + + // delete binary file Zork (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q" + File.separator + "Zork.class")); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import p.OtherFoo;\n" + + "import q.Zork;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " OtherFoo ofoo;\n" + + " String s1 = ofoo.foo;\n" + + " String s2 = ofoo.bar();\n" + + " String s3 = ofoo.new OtherMember();\n" + + " ofoo.baz(this);\n" + + " }\n" + + " void bar() {\n" + + " OtherX ox;\n" + + " String s1 = ox.foo;\n" + + " String s2 = ox.bar();\n" + + " String s3 = ox.new OtherMember();\n" + + " ox.baz(this);\n" + + " }\n" + + "} \n" + + "\n" + + "class OtherX {\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import p.OtherFoo;\n" + + " ^\n" + + "The type q.Zork cannot be resolved. It is indirectly referenced from required .class files\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " import q.Zork;\n" + + " ^^^^^^\n" + + "The import q.Zork cannot be resolved\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " String s1 = ofoo.foo;\n" + + " ^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " String s2 = ofoo.bar();\n" + + " ^^^\n" + + "The method bar() from the type OtherFoo refers to the missing type Zork\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " String s3 = ofoo.new OtherMember();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from OtherFoo.OtherMember to String\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " ofoo.baz(this);\n" + + " ^^^\n" + + "The method baz(Zork) from the type OtherFoo refers to the missing type Zork\n" + + "----------\n" + + "7. ERROR in X.java (at line 14)\n" + + " String s1 = ox.foo;\n" + + " ^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 15)\n" + + " String s2 = ox.bar();\n" + + " ^^^\n" + + "The method bar() from the type OtherX refers to the missing type Zork\n" + + "----------\n" + + "9. ERROR in X.java (at line 16)\n" + + " String s3 = ox.new OtherMember();\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from OtherX.OtherMember to String\n" + + "----------\n" + + "10. ERROR in X.java (at line 17)\n" + + " ox.baz(this);\n" + + " ^^^\n" + + "The method baz(Zork) from the type OtherX refers to the missing type Zork\n" + + "----------\n" + + "11. ERROR in X.java (at line 22)\n" + + " public class OtherMember extends Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "12. ERROR in X.java (at line 23)\n" + + " public Zork foo;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "13. ERROR in X.java (at line 24)\n" + + " public Zork bar() { return null; }\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "14. ERROR in X.java (at line 25)\n" + + " public void baz(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test005() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo extends Zork{\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // delete binary folder q1 (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q1")); + + runNegativeTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo() {\n" + + " p.OtherFoo ofoo = new p.OtherFoo();\n" + + " ofoo.bar();\n" + + " q1.q2.Zork z;\n" + + " }\n" + + "} \n", + }, + // compiler options + null /* no class libraries */, + null /* no custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 4)\n" + + " ofoo.bar();\n" + + " ^^^^^^^^^^\n" + + "The type q1.q2.Zork cannot be resolved. It is indirectly referenced from required .class files\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " ofoo.bar();\n" + + " ^^^\n" + + "The method bar() from the type OtherFoo refers to the missing type Zork\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " q1.q2.Zork z;\n" + + " ^^^^^^^^^^\n" + + "q1.q2.Zork cannot be resolved to a type\n" + + "----------\n", + // javac options + JavacTestOptions.SKIP_UNTIL_FRAMEWORK_FIX /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test006() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo extends Zork{\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // delete binary folder q1 (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q1")); + + runNegativeTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "X.java", //----------------------------------------------------------------------- + "import q1.q2.*;\n" + + "public class X {\n" + + " void foo() {\n" + + " p.OtherFoo ofoo = new p.OtherFoo();\n" + + " ofoo.bar();\n" + + " Zork z;\n" + + " }\n" + + "} \n", + }, + // compiler options + null /* no class libraries */, + null /* no custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 1)\n" + + " import q1.q2.*;\n" + + " ^^\n" + + "The import q1 cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " ofoo.bar();\n" + + " ^^^^^^^^^^\n" + + "The type q1.q2.Zork cannot be resolved. It is indirectly referenced from required .class files\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " ofoo.bar();\n" + + " ^^^\n" + + "The method bar() from the type OtherFoo refers to the missing type Zork\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + // javac options + JavacTestOptions.SKIP_UNTIL_FRAMEWORK_FIX /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test007() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo extends Zork{\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // delete binary folder q1 (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q1")); + + runNegativeTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "X.java", //----------------------------------------------------------------------- + "import q1.q2.Zork;\n" + + "public class X {\n" + + " void foo() {\n" + + " p.OtherFoo ofoo = new p.OtherFoo();\n" + + " ofoo.bar();\n" + + " Zork z;\n" + + " }\n" + + "} \n", + }, + // compiler options + null /* no class libraries */, + null /* no custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 1)\n" + + " import q1.q2.Zork;\n" + + " ^^\n" + + "The import q1 cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " ofoo.bar();\n" + + " ^^^^^^^^^^\n" + + "The type q1.q2.Zork cannot be resolved. It is indirectly referenced from required .class files\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " ofoo.bar();\n" + + " ^^^\n" + + "The method bar() from the type OtherFoo refers to the missing type Zork\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + // javac options + JavacTestOptions.SKIP_UNTIL_FRAMEWORK_FIX /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test008() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo extends Zork{\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // delete binary folder q1 (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q1")); + + runNegativeTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo() {\n" + + " q1.q2.Zork z;\n" + + " }\n" + + "} \n", + }, + // compiler options + null /* no class libraries */, + null /* no custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " q1.q2.Zork z;\n" + + " ^^\n" + + "q1 cannot be resolved to a type\n" + + "----------\n", + // javac options + JavacTestOptions.SKIP_UNTIL_FRAMEWORK_FIX /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test009() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo extends Zork{\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // delete binary folder q1 (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q1")); + + runNegativeTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "X.java", //----------------------------------------------------------------------- + "import q1.q2.*;\n" + + "public class X {\n" + + " void foo() {\n" + + " Zork z;\n" + + " }\n" + + "} \n", + }, + // compiler options + null /* no class libraries */, + null /* no custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 1)\n" + + " import q1.q2.*;\n" + + " ^^\n" + + "The import q1 cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", // javac options + JavacTestOptions.SKIP_UNTIL_FRAMEWORK_FIX /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test010() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo extends Zork{\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // delete binary folder q1 (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q1")); + + runNegativeTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "X.java", //----------------------------------------------------------------------- + "import q1.q2.Zork;\n" + + "public class X {\n" + + " void foo() {\n" + + " Zork z;\n" + + " }\n" + + "} \n", + }, + // compiler options + null /* no class libraries */, + null /* no custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 1)\n" + + " import q1.q2.Zork;\n" + + " ^^\n" + + "The import q1 cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + // javac options + JavacTestOptions.SKIP_UNTIL_FRAMEWORK_FIX /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test011() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " java[] field1;\n" + + " java.lang[] field2;\n" + + " void field3;\n" + + " void[] field4;\n" + + " \n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " java[] field1;\n" + + " ^^^^\n" + + "java cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " java.lang[] field2;\n" + + " ^^^^^^^^^\n" + + "java.lang cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " void field3;\n" + + " ^^^^^^\n" + + "void is an invalid type for the variable field3\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " void[] field4;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n"); +} +public void test012() { + String expectedResult; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + expectedResult = + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Class c1 = java[].class;\n" + + " ^^^^\n" + + "java cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Class c2 = java.lang[].class;\n" + + " ^^^^^^^^^\n" + + "java.lang cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Class c4 = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n"; + } else { + expectedResult = + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " Class c1 = java[].class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " Class c1 = java[].class;\n" + + " ^^^^\n" + + "java cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " Class c2 = java.lang[].class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " Class c2 = java.lang[].class;\n" + + " ^^^^^^^^^\n" + + "java.lang cannot be resolved to a type\n" + + "----------\n" + + "5. WARNING in X.java (at line 4)\n" + + " Class c3 = void.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "6. WARNING in X.java (at line 5)\n" + + " Class c4 = void[].class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "7. ERROR in X.java (at line 5)\n" + + " Class c4 = void[].class;\n" + + " ^^^^^^\n" + + "void[] is an invalid type\n" + + "----------\n"; + } + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " Class c1 = java[].class;\n" + + " Class c2 = java.lang[].class;\n" + + " Class c3 = void.class;\n" + + " Class c4 = void[].class;\n" + + "}\n", + }, + expectedResult); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test013() { + String expectedResult; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + expectedResult = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Class c2 = java.lang[].class;\n" + + " ^^^^^^^^^\n" + + "java.lang cannot be resolved to a type\n" + + "----------\n"; + } else { + expectedResult = + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Class c2 = java.lang[].class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Class c2 = java.lang[].class;\n" + + " ^^^^^^^^^\n" + + "java.lang cannot be resolved to a type\n" + + "----------\n"; + } + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " // check if no prior reference to missing 'java'\n" + + " Class c2 = java.lang[].class;\n" + + "}\n", + }, + expectedResult); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test014() { + String expectedResult; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + expectedResult = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Class c2 = java.lang[].class;\n" + + " ^^^^^^^^^\n" + + "java.lang cannot be resolved to a type\n" + + "----------\n"; + } else { + expectedResult = + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Class c2 = java.lang[].class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Class c2 = java.lang[].class;\n" + + " ^^^^^^^^^\n" + + "java.lang cannot be resolved to a type\n" + + "----------\n"; + } + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " // check if no prior reference to missing 'java'\n" + + " Class c2 = java.lang[].class;\n" + + "}\n", + }, + expectedResult); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test015() { + String expectedResult; + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + expectedResult = + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Class a = zork1[].class;\n" + + " ^^^^^\n" + + "zork1 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Class x = zork1.zork2[].class; // compile time error\n" + + " ^^^^^\n" + + "zork1 cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Class a2 = zork1.class;\n" + + " ^^^^^\n" + + "zork1 cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " Class x2 = zork1.zork2.class; // compile time error \n" + + " ^^^^^\n" + + "zork1 cannot be resolved to a type\n" + + "----------\n"; + } else { + expectedResult = + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " Class a = zork1[].class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " Class a = zork1[].class;\n" + + " ^^^^^\n" + + "zork1 cannot be resolved to a type\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " Class x = zork1.zork2[].class; // compile time error\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " Class x = zork1.zork2[].class; // compile time error\n" + + " ^^^^^\n" + + "zork1 cannot be resolved to a type\n" + + "----------\n" + + "5. WARNING in X.java (at line 5)\n" + + " Class a2 = zork1.class;\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "6. ERROR in X.java (at line 5)\n" + + " Class a2 = zork1.class;\n" + + " ^^^^^\n" + + "zork1 cannot be resolved to a type\n" + + "----------\n" + + "7. WARNING in X.java (at line 6)\n" + + " Class x2 = zork1.zork2.class; // compile time error \n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "8. ERROR in X.java (at line 6)\n" + + " Class x2 = zork1.zork2.class; // compile time error \n" + + " ^^^^^\n" + + "zork1 cannot be resolved to a type\n" + + "----------\n"; + } + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " Class a = zork1[].class;\n" + + " Class x = zork1.zork2[].class; // compile time error\n" + + " \n" + + " Class a2 = zork1.class;\n" + + " Class x2 = zork1.zork2.class; // compile time error \n" + + "}\n", + }, + expectedResult); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test016() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " java.langz.AClass1 field1;\n" + + " java.langz.AClass2 field2;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " java.langz.AClass1 field1;\n" + + " ^^^^^^^^^^\n" + + "java.langz cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " java.langz.AClass2 field2;\n" + + " ^^^^^^^^^^\n" + + "java.langz cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test017() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " java.langz field1;\n" + + " java.langz.AClass2 field2;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " java.langz field1;\n" + + " ^^^^^^^^^^\n" + + "java.langz cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " java.langz.AClass2 field2;\n" + + " ^^^^^^^^^^\n" + + "java.langz cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test018() { + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " java.langz.AClass1 field1;\n" + + " java.langz field2;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " java.langz.AClass1 field1;\n" + + " ^^^^^^^^^^\n" + + "java.langz cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " java.langz field2;\n" + + " ^^^^^^^^^^\n" + + "java.langz cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test019() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo extends Zork{\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // delete binary folder q1 (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q1")); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(p.OtherFoo ofoo) {\n" + // triggers OtherFoo loading, and q1.q2 pkg creation (for unresolved binary type refs) + " a.b.Missing1 m1;\n" + + " q1.q2.Missing2 m2;\n" + + " }\n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " a.b.Missing1 m1;\n" + + " ^\n" + + "a cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " q1.q2.Missing2 m2;\n" + + " ^^^^^^^^^^^^^^\n" + + "q1.q2.Missing2 cannot be resolved to a type\n" + + "----------\n", + null, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test020() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo extends Zork{\n" + + " public class OtherMember extends Zork {}\n" + + " public Zork foo;\n" + + " public Zork bar() { return null; }\n" + + " public void baz(Zork z) {}\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // no need to delete Zork actually - any lazy reference would cause q1.q2 to be created as a package + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(p.OtherFoo ofoo) {\n" + // triggers OtherFoo loading, and q1.q2 pkg creation (for unresolved binary type refs) + " a.b.Missing1 m1;\n" + + " q1.q2.Missing2 m2;\n" + + " }\n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " a.b.Missing1 m1;\n" + + " ^\n" + + "a cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " q1.q2.Missing2 m2;\n" + + " ^^^^^^^^^^^^^^\n" + + "q1.q2.Missing2 cannot be resolved to a type\n" + + "----------\n", + null, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test021() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(p.OtherFoo ofoo) {\n" + + " a.b.Missing1 m1;\n" + + " q1.q2.Missing2 m2;\n" + + " }\n" + + "} \n", + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "public class OtherFoo extends q1.q2.Zork{\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " a.b.Missing1 m1;\n" + + " ^\n" + + "a cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " q1.q2.Missing2 m2;\n" + + " ^^\n" + + "q1 cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p\\OtherFoo.java (at line 2)\n" + + " public class OtherFoo extends q1.q2.Zork{\n" + + " ^^\n" + + "q1 cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test022() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo {\n" + + " public Zork foo;\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // delete binary folder q1 (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q1")); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(q1.q2.Missing1 m1) {\n" + + " a.b.Missing1 m1a;\n" + + " p.OtherFoo ofoo;\n" + // triggers OtherFoo loading, and q1.q2 pkg creation (for unresolved binary type refs) + " q1.q2.Missing1 m11;\n" + + " }\n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(q1.q2.Missing1 m1) {\n" + + " ^^\n" + + "q1 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " a.b.Missing1 m1a;\n" + + " ^\n" + + "a cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " q1.q2.Missing1 m11;\n" + + " ^^\n" + + "q1 cannot be resolved to a type\n" + + "----------\n", + null, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test023() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo {\n" + + " public Zork foo;\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // leave package behind + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(q1.q2.Missing1 m1) {\n" + + " a.b.Missing1 m1a;\n" + + " p.OtherFoo ofoo;\n" + + " q1.q2.Missing1 m11;\n" + + " }\n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(q1.q2.Missing1 m1) {\n" + + " ^^^^^^^^^^^^^^\n" + + "q1.q2.Missing1 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " a.b.Missing1 m1a;\n" + + " ^\n" + + "a cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " q1.q2.Missing1 m11;\n" + + " ^^^^^^^^^^^^^^\n" + + "q1.q2.Missing1 cannot be resolved to a type\n" + + "----------\n", + null, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test024() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo {\n" + + " public Zork foo;\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // delete binary folder q1/q2 (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q1/q2")); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(q1.q2.Missing1 m1) {\n" + + " a.b.Missing1 m1a;\n" + + " p.OtherFoo ofoo;\n" + // triggers OtherFoo loading, and q1.q2 pkg creation (for unresolved binary type refs) + " q1.q2.Missing1 m11;\n" + + " }\n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(q1.q2.Missing1 m1) {\n" + + " ^^^^^\n" + + "q1.q2 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " a.b.Missing1 m1a;\n" + + " ^\n" + + "a cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " q1.q2.Missing1 m11;\n" + + " ^^^^^^^^^^^^^^\n" + + "q1.q2.Missing1 cannot be resolved to a type\n" + // inconsistent msg from previous one (error 1) + "----------\n", + null, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test025() { + this.runConformTest( + new String[] { + "p/OtherFoo.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "import q1.q2.Zork;\n" + + "\n" + + "public class OtherFoo {\n" + + " public Zork foo;\n" + + "}\n", + "q1/q2/Zork.java", //----------------------------------------------------------------------- + "package q1.q2;\n" + + "public class Zork {\n" + + "}\n", + }, + ""); + + // delete binary folder q1/q2 (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "q1/q2")); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(q1.q2.Missing1 m1) {\n" + + " a.b.Missing1 m1a;\n" + + " p.OtherFoo ofoo;\n" + // triggers OtherFoo loading, and q1.q2 pkg creation (for unresolved binary type refs) + " }\n" + + "} \n", + "Y.java", //----------------------------------------------------------------------- + "public class Y {\n" + + " void foo() {\n" + + " q1.q2.Missing1 m11;\n" + + " }\n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(q1.q2.Missing1 m1) {\n" + + " ^^^^^\n" + + "q1.q2 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " a.b.Missing1 m1a;\n" + + " ^\n" + + "a cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y.java (at line 3)\n" + + " q1.q2.Missing1 m11;\n" + + " ^^^^^^^^^^^^^^\n" + + "q1.q2.Missing1 cannot be resolved to a type\n" + // inconsistent msg from previous one (error 1) + "----------\n", + null, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test026() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(Missing1 m1) {\n" + + " Missing2 m2 = m1;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Missing1 m1) {\n" + + " ^^^^^^^^\n" + + "Missing1 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Missing2 m2 = m1;\n" + + " ^^^^^^^^\n" + + "Missing2 cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test027() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X x) {\n" + + " new Other().m2 = x;\n" + + " Other other = new Other();\n" + + " other.m2 = x;\n" + + " other.m2.m3 = x;\n" + + " }\n" + + "}\n" + + "\n" + + "class Other {\n" + + " Missing2 m2;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new Other().m2 = x;\n" + + " ^^^^^^^^^^^^^^\n" + + "Missing2 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " other.m2 = x;\n" + + " ^^^^^^^^\n" + + "Missing2 cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " other.m2.m3 = x;\n" + + " ^^^^^^^^\n" + + "Missing2 cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " Missing2 m2;\n" + + " ^^^^^^^^\n" + + "Missing2 cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test028() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X x) {\n" + + " System.out.println(new Other().m2.m3);\n" + + " System.out.println(new Other().m2.m3());\n" + + " Missing2.foo();\n" + + " }\n" + + "}\n" + + "\n" + + "class Other {\n" + + " Missing2 m2;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " System.out.println(new Other().m2.m3);\n" + + " ^^^^^^^^^^^^^^\n" + + "Missing2 cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " System.out.println(new Other().m2.m3());\n" + + " ^^^^^^^^^^^^^^\n" + + "Missing2 cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Missing2.foo();\n" + + " ^^^^^^^^\n" + + "Missing2 cannot be resolved\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " Missing2 m2;\n" + + " ^^^^^^^^\n" + + "Missing2 cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test029() throws Exception { + this.runNegativeTest( + new String[] { + "Y.java", //----------------------------------------------------------------------- + "public class Y extends Z {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " public class Y extends Z {\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + // check Y superclass in problem classfile: shoud not be Z otherwise the class cannot load + String expectedOutput = + "public class Y {\n"; + + File f = new File(OUTPUT_DIR + File.separator + "Y.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test030() { + this.runNegativeTest( + new String[] { + "Y.java", //----------------------------------------------------------------------- + "public class Y extends Z {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " public class Y extends Z {\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X extends Y {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y {\n" + + " ^\n" + + "The hierarchy of the type X is inconsistent\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test031() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X extends Y {\n" + + "}\n", + "Y.java", //----------------------------------------------------------------------- + "public class Y extends Z {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X extends Y {\n" + + " ^\n" + + "The hierarchy of the type X is inconsistent\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " public class Y extends Z {\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test032() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import existing.*;\n" + + "public class X {\n" + + " void foo(p.Zork z) {}\n" + + " void bar(Zork z) {} // should bind to existing.Zork\n" + + "}\n", + "p/Clyde.java", //----------------------------------------------------------------------- + "package p;\n" + // just so package p does exist + "public class Clyde {\n" + + "}\n", + "existing/Zork.java", //----------------------------------------------------------------------- + "package existing;\n" + + "public class Zork {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo(p.Zork z) {}\n" + + " ^^^^^^\n" + + "p.Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test033() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) { + return; + } + this.runNegativeTest( + new String[] { + "Y.java", //----------------------------------------------------------------------- + "@Z public class Y {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " @Z public class Y {\n" + + " ^\n" + + "Z cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + runConformTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "X.java", //----------------------------------------------------------------------- + "public class X extends Y {\n" + + "}\n", + }, + // compiler results + "" /* expected compiler log */, + // runtime results + "" /* expected output string */, + "" /* expected error string */, + // javac options + JavacTestOptions.SKIP_UNTIL_FRAMEWORK_FIX /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test034() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = x1.bar();\n" + + " }\n" + + "}\n", + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " Zork bar() { return null; } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = x1.bar();\n" + + " ^^^\n" + + "The method bar() from the type X1 refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " Zork bar() { return null; } \n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test035() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " Zork bar() { return null; } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " Zork bar() { return null; } \n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = x1.bar();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = x1.bar();\n" + + " ^^^\n" + + "The method bar() from the type X1 refers to the missing type Zork\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test036() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = x1.bar(x1);\n" + + " }\n" + + "}\n", + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " Object bar(Zork z) { return null; } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = x1.bar(x1);\n" + + " ^^^\n" + + "The method bar(Zork) from the type X1 refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " Object bar(Zork z) { return null; } \n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test037() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " Object bar(Zork z) { return null; } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " Object bar(Zork z) { return null; } \n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = x1.bar(x1);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = x1.bar(x1);\n" + + " ^^^\n" + + "The method bar(Zork) from the type X1 refers to the missing type Zork\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test038() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = x1.bar(x1);\n" + + " }\n" + + "}\n", + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " Object bar(Object o) throws Zork { return null; } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = x1.bar(x1);\n" + + " ^^^\n" + + "The method bar(Object) from the type X1 refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " Object bar(Object o) throws Zork { return null; } \n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test039() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " Object bar(Object o) throws Zork { return null; } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " Object bar(Object o) throws Zork { return null; } \n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = x1.bar(x1);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = x1.bar(x1);\n" + + " ^^^\n" + + "The method bar(Object) from the type X1 refers to the missing type Zork\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test040() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = new X1(x1);\n" + + " }\n" + + "}\n", + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new X1(x1);\n" + + " ^^^^^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test041() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = new X1(x1);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new X1(x1);\n" + + " ^^^^^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test042() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = new X1();\n" + + " }\n" + + "}\n", + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1() throws Zork {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new X1();\n" + + " ^^^^^^^^\n" + + "The constructor X1() refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1() throws Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test043() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1() throws Zork {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1() throws Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = new X1();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new X1();\n" + + " ^^^^^^^^\n" + + "The constructor X1() refers to the missing type Zork\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test044() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = new X1(x1){};\n" + + " }\n" + + "}\n", + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new X1(x1){};\n" + + " ^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test045() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = new X1(x1){};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new X1(x1){};\n" + + " ^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test046() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = new X1(){};\n" + + " }\n" + + "}\n", + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1() throws Zork {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new X1(){};\n" + + " ^^^^\n" + + "The constructor X1() refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1() throws Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test047() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1() throws Zork {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1() throws Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o = new X1(){};\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object o = new X1(){};\n" + + " ^^^^\n" + + "The constructor X1() refers to the missing type Zork\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test048() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X extends X1 {\n" + + " X(X1 x1) {\n" + + " super(x1);\n" + + " }\n" + + "}\n", + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " super(x1);\n" + + " ^^^^^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test049() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X extends X1 {\n" + + " X(X1 x1) {\n" + + " super(x1);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " super(x1);\n" + + " ^^^^^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test050() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X extends X1 {\n" + + " X(X1 x1) {\n" + + " super();\n" + + " }\n" + + "}\n", + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1() throws Zork {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " super();\n" + + " ^^^^^^^^\n" + + "The constructor X1() refers to the missing type Zork\n" + + "----------\n" + + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1() throws Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test051() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1() throws Zork {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 2)\n" + + " public X1() throws Zork {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X extends X1 {\n" + + " X(X1 x1) {\n" + + " super();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " super();\n" + + " ^^^^^^^^\n" + + "The constructor X1() refers to the missing type Zork\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test052() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o;\n" + + " o = x1.next.zork;\n" + + " o = this.zork;\n" + + " o = zork;\n" + + " o = x1.next.zork.foo();\n" + + " o = this.zork.foo();\n" + + " o = zork.foo();\n" + + " }\n" + + " Zork zork;\n" + + "}\n" + + "class X1 {\n" + + " X1 next;\n" + + " Zork zork;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o = x1.next.zork;\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " o = this.zork;\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " o = zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " o = x1.next.zork.foo();\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " o = this.zork.foo();\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " o = zork.foo();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 15)\n" + + " Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test053() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void bar(X1 x1) {\n" + + " String s;\n" + + " s = x1.next.zork;\n" + + " s = this.zork;\n" + + " s = zork;\n" + + " s = x1.next.zork.foo();\n" + + " s = this.zork.foo();\n" + + " s = zork.foo();\n" + + " } \n" + + " Zork zork;\n" + + "}\n" + + "class X1 {\n" + + " X1 next;\n" + + " Zork zork;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " s = x1.next.zork;\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " s = this.zork;\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " s = zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " s = x1.next.zork.foo();\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " s = this.zork.foo();\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " s = zork.foo();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 15)\n" + + " Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test054() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void baz(X1 x1) {\n" + + " Zork z;\n" + + " z = x1.next.zork;\n" + + " z = this.zork;\n" + + " z = zork;\n" + + " z = x1.next.zork.foo();\n" + + " z = this.zork.foo();\n" + + " z = zork.foo();\n" + + " } \n" + + " Zork zork;\n" + + "}\n" + + "class X1 {\n" + + " X1 next;\n" + + " Zork zork;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " z = x1.next.zork;\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " z = this.zork;\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " z = zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " z = x1.next.zork.foo();\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " z = this.zork.foo();\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 9)\n" + + " z = zork.foo();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 11)\n" + + " Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "9. ERROR in X.java (at line 15)\n" + + " Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test055() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1 next;\n" + + " public Zork zork;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 3)\n" + + " public Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " Object o;\n" + + " o = x1.next.zork;\n" + + " o = this.zork;\n" + + " o = zork;\n" + + " o = x1.next.zork.foo();\n" + + " o = this.zork.foo();\n" + + " o = zork.foo();\n" + + " }\n" + + " Zork zork;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " o = x1.next.zork;\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " o = this.zork;\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " o = zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " o = x1.next.zork.foo();\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " o = this.zork.foo();\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " o = zork.foo();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test056() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1 next;\n" + + " public Zork zork;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 3)\n" + + " public Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void bar(X1 x1) {\n" + + " String s;\n" + + " s = x1.next.zork;\n" + + " s = this.zork;\n" + + " s = zork;\n" + + " s = x1.next.zork.foo();\n" + + " s = this.zork.foo();\n" + + " s = zork.foo();\n" + + " } \n" + + " Zork zork;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " s = x1.next.zork;\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " s = this.zork;\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " s = zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " s = x1.next.zork.foo();\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " s = this.zork.foo();\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " s = zork.foo();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test057() { + this.runNegativeTest( + new String[] { + "X1.java", //----------------------------------------------------------------------- + "public class X1 {\n" + + " public X1 next;\n" + + " public Zork zork;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X1.java (at line 3)\n" + + " public Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + true, // flush output + null, + true, // generate output + false, + false); + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void baz(X1 x1) {\n" + + " Zork z;\n" + + " z = x1.next.zork;\n" + + " z = this.zork;\n" + + " z = zork;\n" + + " z = x1.next.zork.foo();\n" + + " z = this.zork.foo();\n" + + " z = zork.foo();\n" + + " } \n" + + " Zork zork;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " z = x1.next.zork;\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " z = this.zork;\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " z = zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "5. ERROR in X.java (at line 7)\n" + + " z = x1.next.zork.foo();\n" + + " ^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " z = this.zork.foo();\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 9)\n" + + " z = zork.foo();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 11)\n" + + " Zork zork;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + null, + false, // do not flush output + null, + true, // generate output + false, + false); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test058() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " x1.bar().baz();\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 {\n" + + " Zork bar(){}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " x1.bar().baz();\n" + + " ^^^\n" + + "The method bar() from the type X1 refers to the missing type Zork\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork bar(){}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test059() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " new X1(x1).baz();\n" + + " new X1(null).baz();\n" + + " new Zork().baz();\n" + + " new X1(x1){}.baz();\n" + + " new X1(null){}.baz();\n" + + " new Zork(){}.baz();\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 {\n" + + " X1(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X1(x1).baz();\n" + + " ^^^^^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " new X1(x1).baz();\n" + + " ^^^\n" + + "The method baz() is undefined for the type X1\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " new X1(null).baz();\n" + + " ^^^^^^^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " new X1(null).baz();\n" + + " ^^^\n" + + "The method baz() is undefined for the type X1\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " new Zork().baz();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 6)\n" + + " new X1(x1){}.baz();\n" + + " ^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n" + + "7. ERROR in X.java (at line 6)\n" + + " new X1(x1){}.baz();\n" + + " ^^^\n" + + "The method baz() is undefined for the type new X1(){}\n" + + "----------\n" + + "8. ERROR in X.java (at line 7)\n" + + " new X1(null){}.baz();\n" + + " ^^^^^^^^\n" + + "The constructor X1(Zork) refers to the missing type Zork\n" + + "----------\n" + + "9. ERROR in X.java (at line 7)\n" + + " new X1(null){}.baz();\n" + + " ^^^\n" + + "The method baz() is undefined for the type new X1(){}\n" + + "----------\n" + + "10. ERROR in X.java (at line 8)\n" + + " new Zork(){}.baz();\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "11. ERROR in X.java (at line 13)\n" + + " X1(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test060() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(Zork z) {\n" + + " z.bar();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Zork z) {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test061() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(X1 x1) {\n" + + " int i = x1.next.z;\n" + + " int j = x1.next.zArray;\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 {\n" + + " X1 next;\n" + + " Zork z;\n" + + " Zork[] zArray;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int i = x1.next.z;\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " int j = x1.next.zArray;\n" + + " ^^^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " Zork[] zArray;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test062() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " X1 x1;\n" + + " void foo() {\n" + + " int i = x1.next.z;\n" + + " int j = x1.next.zArray;\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 {\n" + + " X1 next;\n" + + " Zork z;\n" + + " Zork[] zArray;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int i = x1.next.z;\n" + + " ^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " int j = x1.next.zArray;\n" + + " ^^^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 12)\n" + + " Zork[] zArray;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test063() { + this.runNegativeTest( + new String[] { + "p/X.java", //----------------------------------------------------------------------- + "package p;\n" + + "public class X {\n" + + " void foo() {\n" + + " int i = p.X1.z;\n" + + " int j = p.X1.zArray;\n" + + " }\n" + + "}\n" + + "\n" + + "class X1 {\n" + + " static Zork z;\n" + + " static Zork[] zArray;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 4)\n" + + " int i = p.X1.z;\n" + + " ^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 5)\n" + + " int j = p.X1.zArray;\n" + + " ^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in p\\X.java (at line 10)\n" + + " static Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in p\\X.java (at line 11)\n" + + " static Zork[] zArray;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test064() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.io.*; \n" + + "public class X {\n" + + " void foo() {\n" + + " Serializable[] v= new ArrayListExtra[10];\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Serializable[] v= new ArrayListExtra[10];\n" + + " ^^^^^^^^^^^^^^\n" + + "ArrayListExtra cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test065() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.io.*; \n" + + "public class X {\n" + + " void foo() {\n" + + " int l = array.length;\n" + + " Object o = array[1];\n" + + "\n" + + " }\n" + + " Zork[] array;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int l = array.length;\n" + + " ^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Object o = array[1];\n" + + " ^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork[] array;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test066() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo() {\n" + + " Zork z1 = null;\n" + + " Object o = z1;\n" + + " Object o1 = z1.z2;\n" + + " Object o2 = bar();\n" + + " Zork[] array = null;\n" + + " int length = array.length;\n" + + " }\n" + + " Zork bar() {\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z1 = null;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Object o2 = bar();\n" + + " ^^^\n" + + "The method bar() from the type X refers to the missing type Zork\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Zork[] array = null;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " Zork bar() {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test067() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) + return; + this.runNegativeTest( + new String[] { + "E.java", //----------------------------------------------------------------------- + "public class E {\n" + + " class SomeType { }\n" + + " void foo() {\n" + + " E list= new E();\n" + + " list = new E();\n" + + " }\n" + + " E fList= new E();\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in E.java (at line 4)\n" + + " E list= new E();\n" + + " ^^^\n" + + "XYX cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in E.java (at line 7)\n" + + " E fList= new E();\n" + + " ^^^\n" + + "XYX cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test068() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) + return; + this.runNegativeTest( + new String[] { + "E.java", //----------------------------------------------------------------------- + "import java.util.Map;\n" + + "public class E {\n" + + " static class SomeType { }\n" + + " void foo() {\n" + + " E> list= new E>() {\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in E.java (at line 5)\n" + + " E> list= new E>() {\n" + + " ^^^\n" + + "XYX cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test069() { + this.runNegativeTest( + new String[] { + "p/X.java", //----------------------------------------------------------------------- + "package p;\n" + + "public class X {\n" + + " IOException foo() {}\n" + + "}\n", + "p/Y.java", //----------------------------------------------------------------------- + "package p;\n" + + "import java.io.*;\n" + + "public class Y {\n" + + " void foo(IOException e) {}\n" + + " void bar(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 3)\n" + + " IOException foo() {}\n" + + " ^^^^^^^^^^^\n" + + "IOException cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p\\Y.java (at line 5)\n" + + " void bar(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test070() { + this.runNegativeTest( + new String[] { + "p/X.java", //----------------------------------------------------------------------- + "package p;\n" + + "public class X {\n" + + " IOException foo() {}\n" + + "}\n", + "q/Y.java", //----------------------------------------------------------------------- + "package q;\n" + + "import p.*;\n" + + "import java.io.*;\n" + + "public class Y {\n" + + " void foo(IOException e) {}\n" + + " void bar(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 3)\n" + + " IOException foo() {}\n" + + " ^^^^^^^^^^^\n" + + "IOException cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. ERROR in q\\Y.java (at line 6)\n" + + " void bar(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test071() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " IOException foo() {}\n" + + "}\n", + "Y.java", //----------------------------------------------------------------------- + "import java.io.*;\n" + + "public class Y {\n" + + " void foo(IOException e) {}\n" + + " void bar(Zork z) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " IOException foo() {}\n" + + " ^^^^^^^^^^^\n" + + "IOException cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y.java (at line 4)\n" + + " void bar(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test072() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public void foo() throws Foo {\n" + + " }\n" + + " public void bar() throws Zork {\n" + + " } \n" + + "}\n" + + "\n" + + "class Foo extends Zork {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo() throws Foo {\n" + + " ^^^\n" + + "No exception of type Foo can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public void bar() throws Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " class Foo extends Zork {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test073() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " /**\n" + + " * @see Foo.Private#foo()\n" + + " * @param p\n" + + " */\n" + + " void foo(Foo.Private p) {\n" + + " p.foo();\n" + + " }\n" + + "}\n" + + "\n" + + "class Foo {\n" + + " private class Private {\n" + + " private void foo(){}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " void foo(Foo.Private p) {\n" + + " ^^^^^^^^^^^\n" + + "The type Foo.Private is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " p.foo();\n" + + " ^\n" + + "The type Foo.Private is not visible\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " private class Private {\n" + + " ^^^^^^^\n" + + "The type Foo.Private is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 13)\n" + + " private void foo(){}\n" + + " ^^^^^\n" + + "The method foo() from the type Foo.Private is never used locally\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test074() { + String expected = this.complianceLevel <= ClassFileConstants.JDK1_4 + ? "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " bar1().foo();\n" + + " ^^^^\n" + + "The method bar1() from the type X refers to the missing type Zork\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " bar2();\n" + + " ^^^^\n" + + "The method bar2() from the type X refers to the missing type Zork\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " bar3(null);\n" + + " ^^^^\n" + + "The method bar3(Zork) from the type X refers to the missing type Zork\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " bar4(null,null);\n" + + " ^^^^\n" + + "The method bar4(Zork) from the type X refers to the missing type Zork\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " Zork bar1() {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 9)\n" + + " Zork bar1() {}\n" + + " ^^^^^^\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 bar2() {}\n" + + " ^^^^\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 bar2() {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "9. ERROR in X.java (at line 11)\n" + + " void bar3(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "10. ERROR in X.java (at line 11)\n" + + " void bar3(Zork z) {}\n" + + " ^^^^^^\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 z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "12. ERROR in X.java (at line 12)\n" + + " void bar4(Zork z) {}\n" + + " ^^^^^^^^^^^^^\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" + + " bar1().foo();\n" + + " ^^^^\n" + + "The method bar1() from the type X refers to the missing type Zork\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " bar2();\n" + + " ^^^^\n" + + "The method bar2() from the type X refers to the missing type Zork\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " bar3(null);\n" + + " ^^^^\n" + + "The method bar3(Zork) from the type X refers to the missing type Zork\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " bar4(null,null);\n" + + " ^^^^\n" + + "The method bar4(Zork) from the type X refers to the missing type Zork\n" + + "----------\n" + + "5. ERROR in X.java (at line 9)\n" + + " Zork bar1() {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 10)\n" + + " List bar2() {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 11)\n" + + " void bar3(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "8. ERROR in X.java (at line 12)\n" + + " void bar4(Zork z) {}\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.List;\n" + + "public class X {\n" + + " void foo() {\n" + + " bar1().foo();\n" + + " bar2();\n" + + " bar3(null);\n" + + " bar4(null,null);\n" + + " }\n" + + " Zork bar1() {}\n" + + " List bar2() {}\n" + + " void bar3(Zork z) {}\n" + + " void bar4(Zork z) {}\n" + + "}\n",//----------------------------------------------------------------------- + }, + expected); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test075() { + String expected = this.complianceLevel <= ClassFileConstants.JDK1_4 + ? "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^\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) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^\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) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^\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" + + " Zork z = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Zork\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Zork\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(Object o) {\n" + + " Zork z = (Zork) o;\n" + + " String s = (Zork) o;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + expected); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test076() { + String expected = this.complianceLevel <= ClassFileConstants.JDK1_4 + ? "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^\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) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^\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) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^\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" + + " Zork z = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Zork\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Zork\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(Object o) {\n" + + " Zork z = (Zork) o;\n" + + " String s = (Zork) o;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + expected); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196200 - variation +public void test077() { + String expected = this.complianceLevel <= ClassFileConstants.JDK1_4 + ? "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^\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) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^\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) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^\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" + + " Zork z = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Zork\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork z = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "4. WARNING in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from Object to Zork\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "6. ERROR in X.java (at line 4)\n" + + " String s = (Zork) o;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"; + + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " void foo(Object o) {\n" + + " Zork z = (Zork) o;\n" + + " String s = (Zork) o;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + expected); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220967 +public void test078() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.List;\n" + + "interface B {\n" + + " B m(String seq);\n" + + "}\n" + + "public class X implements B {\n" + + " public Zork m(String arg0) {\n" + + " return null;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public Zork m(String arg0) {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220967 - variation +public void test079() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "public class X {\n" + + " public Zork m(X x) {\n" + + " return x;\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public Zork m(X x) {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=220967 - variation +public void test080() { + this.runNegativeTest( + new String[] { + "X.java", //----------------------------------------------------------------------- + "import java.util.List;\n" + + "interface B {\n" + + " void m() throws Exception;\n" + + "}\n" + + "public class X implements B {\n" + + " public void m() throws IOException {\n" + + " }\n" + + "}\n",//----------------------------------------------------------------------- + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public void m() throws IOException {\n" + + " ^^^^^^^^^^^\n" + + "IOException cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 +public void test081() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put( CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + runner.customOptions.put(CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportInvalidJavadocTags, CompilerOptions.ENABLED); + runner.testFiles = + new String[] { + "com/ost/util/report/Matrix.java", // ================= + "package com.ost.util.report;\n" + + "import java.io.Serializable;\n" + + "import com.ost.util.report.exceptions.InvalidRowSizeException;\n" + + "public class Matrix implements Serializable {\n" + + " /**\n" + + " * @see exceptions.InvalidRowSizeException2\n" + + " */\n" + + " public synchronized final void addRow(Object[] row){\n" + + " throw new InvalidRowSizeException();\n" + + " }\n" + + "}\n", + "com/ost/util/report/FilterConstraintSpecification.java", // ================= + "package com.ost.util.report;\n" + + "import java.io.Serializable;\n" + + "import com.ost.util.report.exceptions.MalformedFilterConstraintSpecification;\n" + + "public final class FilterConstraintSpecification implements Serializable, Cloneable {\n" + + " private final void makeConstraint(){\n" + + " throw new MalformedFilterConstraintSpecification();\n" + + " }\n" + + "}\n", + "com/ost/util/report/exceptions/MalformedFilterConstraintSpecification.java", // ================= + "package com.ost.util.report.exceptions;\n" + + "public class MalformedFilterConstraintSpecification extends RuntimeException {\n" + + " /** Creates a new instance of MalformedFilterConstraintSpecification */\n" + + " public MalformedFilterConstraintSpecification() {\n" + + " super();\n" + + " }\n" + + " /* Creates a new instance of MalformedFilterConstraintSpecification */\n" + + " public MalformedFilterConstraintSpecification(String message) {\n" + + " super(message);\n" + + " }\n" + + "}\n", + "com/ost/util/report/exceptions/InvalidRowSizeException.java", // ================= + "package com.ost.util.report.exceptions;\n" + + "public class InvalidRowSizeException extends RuntimeException {\n" + + " /** Creates a new instance of InvalidRowSizeException */\n" + + " public InvalidRowSizeException() {\n" + + " super();\n" + + " }\n" + + " /* Creates a new instance of InvalidRowSizeException */\n" + + " public InvalidRowSizeException(String message) {\n" + + " super(message);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in com\\ost\\util\\report\\Matrix.java (at line 4)\n" + + " public class Matrix implements Serializable {\n" + + " ^^^^^^\n" + + "The serializable class Matrix does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in com\\ost\\util\\report\\Matrix.java (at line 6)\n" + + " * @see exceptions.InvalidRowSizeException2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Javadoc: exceptions cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. WARNING in com\\ost\\util\\report\\FilterConstraintSpecification.java (at line 4)\n" + + " public final class FilterConstraintSpecification implements Serializable, Cloneable {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The serializable class FilterConstraintSpecification does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in com\\ost\\util\\report\\FilterConstraintSpecification.java (at line 5)\n" + + " private final void makeConstraint(){\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The method makeConstraint() from the type FilterConstraintSpecification is never used locally\n" + + "----------\n" + + "----------\n" + + "1. WARNING in com\\ost\\util\\report\\exceptions\\MalformedFilterConstraintSpecification.java (at line 2)\n" + + " public class MalformedFilterConstraintSpecification extends RuntimeException {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The serializable class MalformedFilterConstraintSpecification does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "----------\n" + + "1. WARNING in com\\ost\\util\\report\\exceptions\\InvalidRowSizeException.java (at line 2)\n" + + " public class InvalidRowSizeException extends RuntimeException {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The serializable class InvalidRowSizeException does not declare a static final serialVersionUID field of type long\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 - variation +public void test082() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runConformTest( + new String[] { + "com/ost/util/report/Matrix.java", // ================= + "package com.ost.util.report;\n" + + "import java.io.Serializable;\n" + + "import com.ost.util.report.exceptions.InvalidRowSizeException;\n" + + "public class Matrix implements Serializable {\n" + + " /**\n" + + " * @see exceptions.InvalidRowSizeException2\n" + + " */\n" + + " public synchronized final void addRow(Object[] row){\n" + + " throw new InvalidRowSizeException();\n" + + " }\n" + + "}\n", + "com/ost/util/report/FilterConstraintSpecification.java", // ================= + "package com.ost.util.report;\n" + + "import java.io.Serializable;\n" + + "import com.ost.util.report.exceptions.MalformedFilterConstraintSpecification;\n" + + "public final class FilterConstraintSpecification implements Serializable, Cloneable {\n" + + " private final void makeConstraint(){\n" + + " throw new MalformedFilterConstraintSpecification();\n" + + " }\n" + + "}\n", + "com/ost/util/report/exceptions/MalformedFilterConstraintSpecification.java", // ================= + "package com.ost.util.report.exceptions;\n" + + "public class MalformedFilterConstraintSpecification extends RuntimeException {\n" + + " /** Creates a new instance of MalformedFilterConstraintSpecification */\n" + + " public MalformedFilterConstraintSpecification() {\n" + + " super();\n" + + " }\n" + + " /* Creates a new instance of MalformedFilterConstraintSpecification */\n" + + " public MalformedFilterConstraintSpecification(String message) {\n" + + " super(message);\n" + + " }\n" + + "}\n", + "com/ost/util/report/exceptions/InvalidRowSizeException.java", // ================= + "package com.ost.util.report.exceptions;\n" + + "public class InvalidRowSizeException extends RuntimeException {\n" + + " /** Creates a new instance of InvalidRowSizeException */\n" + + " public InvalidRowSizeException() {\n" + + " super();\n" + + " }\n" + + " /* Creates a new instance of InvalidRowSizeException */\n" + + " public InvalidRowSizeException(String message) {\n" + + " super(message);\n" + + " }\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 - variation +public void test083() { + this.runConformTest( + new String[] { + "foo/X.java", // ================= + "package foo;\n" + + "import foo.exceptions.*;\n" + + "public class X {\n" + + " class exceptions {}\n" + + " exceptions E;\n" + + "}\n", + "foo/exceptions/Z.java", // ================= + "package foo.exceptions;\n" + + "public class Z {\n" + + "}\n" + }, + ""); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 - variation +public void test084() { + this.runNegativeTest( + new String[] { + "foo/X.java", // ================= + "package foo;\n" + + "import foo.exceptions.*;\n" + + "public class X {\n" + + " exceptions E;\n" + + "}\n" + + "class exceptions {}\n", + "foo/exceptions/Z.java", // ================= + "package foo.exceptions;\n" + + "public class Z {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in foo\\X.java (at line 2)\n" + + " import foo.exceptions.*;\n" + + " ^^^^^^^^^^^^^^\n" + + "The import foo.exceptions is never used\n" + + "----------\n" + + "----------\n" + + "1. ERROR in foo\\exceptions\\Z.java (at line 1)\n" + + " package foo.exceptions;\n" + + " ^^^^^^^^^^^^^^\n" + + "The package foo.exceptions collides with a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 - variation +public void test085() { + this.runNegativeTest( + new String[] { + "p/X.java", // ================= + "package p;\n" + + "public class X extends zork.Z {\n" + + "}\n", + "p/Y.java", // ================= + "package p;\n" + + "import p.zork.Z;\n" + + "public class Y {\n" + + "}\n", + "p/zork/Z.java", // ================= + "package p.zork;\n" + + "public class Z {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " public class X extends zork.Z {\n" + + " ^^^^\n" + + "zork cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\Y.java (at line 2)\n" + + " import p.zork.Z;\n" + + " ^^^^^^^^\n" + + "The import p.zork.Z is never used\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 - variation +public void test086() { + this.runNegativeTest( + new String[] { + "p/X.java", // ================= + "package p;\n" + + "public class X extends zork.Z {\n" + + "}\n", + "p/Y.java", // ================= + "package p;\n" + + "import p.zork.*;\n" + + "public class Y {\n" + + "}\n", + "p/zork/Z.java", // ================= + "package p.zork;\n" + + "public class Z {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " public class X extends zork.Z {\n" + + " ^^^^\n" + + "zork cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\Y.java (at line 2)\n" + + " import p.zork.*;\n" + + " ^^^^^^\n" + + "The import p.zork is never used\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 - variation +public void test087() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "p/X.java", // ================= + "package p;\n" + + "public class X extends zork.Z {\n" + + "}\n", + "p/Y.java", // ================= + "package p;\n" + + "import static p.zork.Z.M;\n" + + "public class Y {\n" + + "}\n", + "p/zork/Z.java", // ================= + "package p.zork;\n" + + "public class Z {\n" + + " public static class M {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " public class X extends zork.Z {\n" + + " ^^^^\n" + + "zork cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\Y.java (at line 2)\n" + + " import static p.zork.Z.M;\n" + + " ^^^^^^^^^^\n" + + "The import p.zork.Z.M is never used\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=239758 - variation +public void test088() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "p/X.java", // ================= + "package p;\n" + + "public class X extends zork.Z {\n" + + "}\n", + "p/Y.java", // ================= + "package p;\n" + + "import static p.zork.Z.*;\n" + + "public class Y {\n" + + "}\n", + "p/zork/Z.java", // ================= + "package p.zork;\n" + + "public class Z {\n" + + " static class M {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " public class X extends zork.Z {\n" + + " ^^^^\n" + + "zork cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. WARNING in p\\Y.java (at line 2)\n" + + " import static p.zork.Z.*;\n" + + " ^^^^^^^^\n" + + "The import p.zork.Z is never used\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=245304 +public void test089() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + this.runConformTest( + new String[] { + "com/foo/bar/baz/reporting/dom/ReportExceptionBase.java", // ================ + "package com.foo.bar.baz.reporting.dom;\n" + + "public class ReportExceptionBase extends Exception {\n" + + "}\n", + "com/foo/bar/baz/reporting/Report.java", // ================ + "package com.foo.bar.baz.reporting;\n" + + "import com.foo.bar.baz.reporting.dom.ReportExceptionBase;\n" + + "/**\n" + + " * {@link dom.ReportDefs.ReportType.foo foo}\n" + + " */\n" + + "public abstract class Report {\n" + + "}\n", + "com/foo/bar/baz/reporting/Derived.java", // ================ + "package com.foo.bar.baz.reporting;\n" + + "import com.foo.bar.baz.reporting.dom.ReportExceptionBase;\n" + + "public class Derived {\n" + + " public Derived() throws ReportExceptionBase {\n" + + " throw new ReportExceptionBase();\n" + + " }\n" + + "}\n", + }, + "", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=247666 +public void test090() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + " void foo(Zork z) {} \n" + + " void bar() {\n" + + " foo(null);\n" + + " } \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(Zork z) {} \n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " foo(null);\n" + + " ^^^\n" + + "The method foo(Zork) from the type X refers to the missing type Zork\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=252288 +public void test091() throws Exception { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "TypeUtils.java", + "import java.util.Collection;\n" + + "import java.util.Iterator;\n" + + "\n" + + "public final class TypeUtils {\n" + + "\n" + + " // personal\n" + + "\n" + + " private TypeUtils() {\n" + + " }\n" + + "\n" + + " // class\n" + + "\n" + + " /**\n" + + " * Returns true if a target type is exactly any one in a group of types.\n" + + " * @param target Target type. Never null.\n" + + " * @param types Group of types. If empty, returns false. Never null.\n" + + " * @return True if the target is a valid type.\n" + + " */\n" + + " public static boolean isIdenticalToAny(Class target, Collection> types) {\n" + + " if (target == null) throw new IllegalArgumentException(\n" + + " \"Target is null.\");\n" + + "\n" + + " if (types.contains(target)) return true;\n" + + " return false;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns true if a target type is the same or a subtype of (assignable to)\n" + + " * a reference type. Convenience method for completeness. Forwards to\n" + + " * Class.isAssignableFrom().\n" + + " * @param target Target type. Never null.\n" + + " * @param type Reference type. Never null.\n" + + " * @return True if condition is met.\n" + + " */\n" + + " public static boolean isAssignableTo(Class target, Class type) {\n" + + " return type.isAssignableFrom(target);\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns true if a target type is the same or a subtype of (assignable to)\n" + + " * any one reference type.\n" + + " * @param target Target type. Never null.\n" + + " * @param types Reference types (Class). Never null. If empty returns false.\n" + + " * @return True if condition is met.\n" + + " */\n" + + " public static boolean isAssignableToAny(Class target,\n" + + " Collection> types) {\n" + + " if (types.isEmpty()) return false;\n" + + "\n" + + " for(Class type : types) {\n" + + " if (type.isAssignableFrom(target)) return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns true if any one target type is the same or a subtype of\n" + + " * (assignable to) a reference type.\n" + + " * @param targets Target types (Class). Never null. If empty returns false.\n" + + " * @param type Reference type. Never null.\n" + + " * @return True if condition is met.\n" + + " */\n" + + " public static boolean areAnyAssignableTo(Collection> targets,\n" + + " Class type) {\n" + + " if (targets.isEmpty()) return false;\n" + + "\n" + + " for(Class target : targets) {\n" + + " if (type.isAssignableFrom(target)) return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns true if any one target type is the same or a subtype of\n" + + " * (assignable to) any one reference type.\n" + + " * @param targets Target types (Class). Never null. If empty returns false.\n" + + " * @param types Reference types (Class). Never null. If empty returns false.\n" + + " * @return True if condition is met.\n" + + " */\n" + + " public static boolean areAnyAssignableToAny(Collection> targets,\n" + + " Collection> types) {\n" + + " if (targets.isEmpty()) return false;\n" + + " if (types.isEmpty()) return false;\n" + + "\n" + + " for(Class target : targets) {\n" + + " if (isAssignableToAny(target, types)) return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns true if a target object\'s type is the same or a subtype of\n" + + " * (assignable to) a reference type. Convenience method for completeness.\n" + + " * Forwards to Class.isInstance().\n" + + " * @param target Target object. Never null.\n" + + " * @param type Reference type. Never null.\n" + + " * @return True if condition is met.\n" + + " */\n" + + " public static boolean isInstanceOf(Object target, Class type) {\n" + + " return type.isInstance(target);\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns true if a target object\'s type is the same or a subtype of\n" + + " * (assignable to) any one type.\n" + + " * @param target Target object. Never null.\n" + + " * @param types Reference types. Never null. If empty returns false.\n" + + " * @return True if condition is met.\n" + + " */\n" + + " public static boolean isInstanceOfAny(Object target,\n" + + " Collection> types) {\n" + + " if (types.isEmpty()) return false;\n" + + "\n" + + " for (Class type : types) {\n" + + " if (type.isInstance(target)) return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns true if any one target object\'s type is the same or a subtype of\n" + + " * (assignable to) a reference type.\n" + + " * @param targets Target objects. Never null. If empty returns false.\n" + + " * @param type Reference type. Never null.\n" + + " * @return True if condition is met.\n" + + " */\n" + + " public static boolean areAnyInstanceOf(Collection targets,\n" + + " Class type) {\n" + + " if (targets.isEmpty()) return false;\n" + + "\n" + + " for(Object target : targets) {\n" + + " if (type.isInstance(target)) return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns true if all target object types are the same or a subtype of\n" + + " * (assignable to) a reference type.\n" + + " * @param targets Target objects. Never null. If empty returns\n" + + " * false.\n" + + " * @param type Reference type. Never null.\n" + + " * @return True if condition is met.\n" + + " */\n" + + " public static boolean areAllInstanceOf(Collection targets,\n" + + " Class type) {\n" + + " if (targets.isEmpty()) return false;\n" + + "\n" + + " for(Object target : targets) {\n" + + " if (!type.isInstance(target)) return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns true if no target object types are the same or a subtype of\n" + + " * (assignable to) a reference type.\n" + + " * @param targets Target objects. Never null. If empty returns\n" + + " * false.\n" + + " * @param type Reference type. Never null.\n" + + " * @return True if condition is met.\n" + + " */\n" + + " public static boolean areNoneInstanceOf(Collection targets,\n" + + " Class type) {\n" + + " if (targets.isEmpty()) return false;\n" + + "\n" + + " for(Object target : targets) {\n" + + " if (type.isInstance(target)) return false;\n" + + " }\n" + + " return true;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns true if any one target object\'s type is the same or a subtype of\n" + + " * (assignable to) any one reference type.\n" + + " * @param targets Target objects. Never null. If empty returns\n" + + " * false.\n" + + " * @param types Reference types. Never null. If empty returns false.\n" + + " * @return True if condition is met.\n" + + " */\n" + + " public static boolean areAnyInstanceOfAny(Collection targets,\n" + + " Collection> types) {\n" + + " if (targets.isEmpty()) return false;\n" + + " if (types.isEmpty()) return false;\n" + + "\n" + + " for(Object target : targets) {\n" + + " if (isInstanceOfAny(target, types)) return true;\n" + + " }\n" + + " return false;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns only those target objects whose type is identical to the included\n" + + " * reference type.\n" + + " * @param targets Group of target objects. If empty, returns empty. Never\n" + + " * null.\n" + + " * @param type Included reference type. Never null.\n" + + " * @param retVal Return value object. The collection of valid target\n" + + " * objects. Can be {@code targets}. Never null.\n" + + " * @return Reference to retVal. Never null.\n" + + " */\n" + + " public static Collection includeIdenticalTo(Collection targets,\n" + + " Class type, Collection retVal) {\n" + + " // save targets in retVal\n" + + " if (targets != retVal) {\n" + + " retVal.clear();\n" + + " retVal.addAll(targets);\n" + + " }\n" + + "\n" + + " // remove unwanted targets, by target\n" + + " Iterator objectI = retVal.iterator();\n" + + " while (objectI.hasNext()) {\n" + + " Object object = objectI.next();\n" + + " if (!type.equals(object.getClass())) objectI.remove();\n" + + " }\n" + + "\n" + + " return retVal;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns only those target objects whose type is exactly one of the\n" + + " * included reference types.\n" + + " * @param targets Group of target objects. If empty, returns empty. Never\n" + + " * null.\n" + + " * @param types Group of included reference types. If empty, returns empty.\n" + + " * If null, all types are included (all targets are returned).\n" + + " * @param retVal Return value object. The collection of valid target\n" + + " * objects. Can be {@code targets}. Never null.\n" + + " * @return Reference to retVal. Never null.\n" + + " */\n" + + " public static Collection includeIdenticalToAny(\n" + + " Collection targets,\n" + + " Collection> types, Collection retVal) {\n" + + " // save targets in retVal\n" + + " if (targets != retVal) {\n" + + " retVal.clear();\n" + + " retVal.addAll(targets);\n" + + " }\n" + + "\n" + + " if (types == null) return retVal;\n" + + "\n" + + " // remove unwanted targets, by target\n" + + " Iterator objectI = retVal.iterator();\n" + + " while (objectI.hasNext()) {\n" + + " Object object = objectI.next();\n" + + " if (!isIdenticalToAny(object.getClass(), types)) objectI.remove();\n" + + " }\n" + + "\n" + + " return retVal;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns only those target objects whose type is NOT identical to the\n" + + " * excluded reference type.\n" + + " * @param targets Group of target objects. If empty, returns empty. Never\n" + + " * null.\n" + + " * @param type The excluded reference type. Never null.\n" + + " * @param retVal Return value object. The collection of valid target\n" + + " * objects. Can be {@code targets}. Never null.\n" + + " * @return Reference to retVal. Never null.\n" + + " */\n" + + " public static Collection excludeIdenticalTo(\n" + + " Collection targets, Class type,\n" + + " Collection retVal) {\n" + + " // save targets in retVal\n" + + " if (targets != retVal) {\n" + + " retVal.clear();\n" + + " retVal.addAll(targets);\n" + + " }\n" + + "\n" + + " // remove unwanted targets, by target\n" + + " Iterator objectI = retVal.iterator();\n" + + " while (objectI.hasNext()) {\n" + + " Object object = objectI.next();\n" + + " if (type.equals(object.getClass())) objectI.remove();\n" + + " }\n" + + "\n" + + " return retVal;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns only those target objects whose type is NOT exactly one of the\n" + + " * excluded reference types.\n" + + " * @param targets Group of target objects. If empty, returns empty. Never\n" + + " * null.\n" + + " * @param types Group of excluded reference types. If empty, returns empty.\n" + + " * If null, no types are excluded (all targets are returned).\n" + + " * @param retVal Return value object. The collection of valid target\n" + + " * objects. Can be targets. Never null.\n" + + " * @return Reference to retVal. Never null.\n" + + " */\n" + + " public static Collection excludeIdenticalToAny(\n" + + " Collection targets, Collection> types,\n" + + " Collection retVal) {\n" + + " // save targets in retVal\n" + + " if (targets != retVal) {\n" + + " retVal.clear();\n" + + " retVal.addAll(targets);\n" + + " }\n" + + "\n" + + " if (types == null) return retVal;\n" + + "\n" + + " // remove unwanted targets, by target\n" + + " Iterator objectI = retVal.iterator();\n" + + " while (objectI.hasNext()) {\n" + + " Object object = objectI.next();\n" + + " if (isIdenticalToAny(object.getClass(), types)) objectI.remove();\n" + + " }\n" + + "\n" + + " return retVal;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns only those target objects whose type is assignable to (an\n" + + " * instance of) the included reference type.\n" + + " * @param targets Group of target objects. If empty, returns empty. Never\n" + + " * null.\n" + + " * @param type Included reference type. Never null.\n" + + " * @param retVal Return value object. The collection of valid target objects\n" + + " * (Object). Can be targets. Never null.\n" + + " * @return Reference to retVal. Never null.\n" + + " */\n" + + " public static Collection includeAssignableTo(\n" + + " Collection targets, Class type, Collection retVal) {\n" + + " // save targets in retVal\n" + + " if (targets != retVal) {\n" + + " retVal.clear();\n" + + " retVal.addAll(targets);\n" + + " }\n" + + "\n" + + " // remove unwanted targets, by target\n" + + " Iterator objectI = retVal.iterator();\n" + + " while (objectI.hasNext()) {\n" + + " Object object = objectI.next();\n" + + " if (!type.isInstance(object)) objectI.remove();\n" + + " }\n" + + "\n" + + " return retVal;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns only those target objects whose type is assignable to (an\n" + + " * instance of) any one of the included reference types.\n" + + " * @param targets Group of target objects. If empty, returns empty. Never\n" + + " * null.\n" + + " * @param types Group of included reference types. If empty, returns empty.\n" + + " * If null, all types are included (all targets are returned).\n" + + " * @param retVal Return value object. The collection of valid target\n" + + " * objects. Can be targets. Never null.\n" + + " * @return Reference to retVal. Never null.\n" + + " */\n" + + " public static Collection includeAssignableToAny(\n" + + " Collection targets, Collection> types,\n" + + " Collection retVal) {\n" + + " // save targets in retVal\n" + + " if (targets != retVal) {\n" + + " retVal.clear();\n" + + " retVal.addAll(targets);\n" + + " }\n" + + "\n" + + " if (types == null) return retVal;\n" + + "\n" + + " // remove unwanted targets, by target\n" + + " Iterator objectI = retVal.iterator();\n" + + " while (objectI.hasNext()) {\n" + + " Object object = objectI.next();\n" + + " if (!isInstanceOfAny(object, types)) objectI.remove();\n" + + " }\n" + + "\n" + + " return retVal;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns only those target objects whose type is NOT assignable to (an\n" + + " * instance of) the excluded reference type.\n" + + " * @param targets Group of target objects. If empty, returns empty. Never\n" + + " * null.\n" + + " * @param type The excluded reference type. Never null.\n" + + " * @param retVal Return value object. The collection of valid target\n" + + " * objects. Never null.\n" + + " * @return Reference to retVal. Never null.\n" + + " */\n" + + " public static Collection excludeAssignableTo(\n" + + " Collection targets, Class type, Collection retVal) {\n" + + " // save targets in retVal\n" + + " if (targets != retVal) {\n" + + " retVal.clear();\n" + + " retVal.addAll(targets);\n" + + " }\n" + + "\n" + + " // remove unwanted targets, by target\n" + + " Iterator objectI = retVal.iterator();\n" + + " while (objectI.hasNext()) {\n" + + " Object object = objectI.next();\n" + + " if (type.isInstance(object)) objectI.remove();\n" + + " }\n" + + "\n" + + " return retVal;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns only those target objects whose type is NOT assignable to (an\n" + + " * instance of) any one of the excluded reference types.\n" + + " * @param targets Group of target objects. If empty, returns empty. Never\n" + + " * null.\n" + + " * @param types Group of excluded reference types. If empty, returns empty.\n" + + " * If null, no types are excluded (all targets are returned).\n" + + " * @param retVal Return value object. The collection of valid target\n" + + " * objects. Never null.\n" + + " * @return Reference to retVal. Never null.\n" + + " */\n" + + " public static Collection excludeAssignableToAny(\n" + + " Collection targets, Collection> types,\n" + + " Collection retVal) {\n" + + " // save targets in retVal\n" + + " if (targets != retVal) {\n" + + " retVal.clear();\n" + + " retVal.addAll(targets);\n" + + " }\n" + + "\n" + + " if (types == null) return retVal;\n" + + "\n" + + " // remove unwanted targets, by target\n" + + " Iterator objectI = retVal.iterator();\n" + + " while (objectI.hasNext()) {\n" + + " Object object = objectI.next();\n" + + " if (isInstanceOfAny(object, types)) objectI.remove();\n" + + " }\n" + + "\n" + + " return retVal;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns the first target object whose type is assignable to (an instance\n" + + " * of) the reference type.\n" + + " * @param targets Group of target objects. If empty, returns null.\n" + + " * Never null.\n" + + " * @param type Reference type. Never null.\n" + + " * @return The result (Object, assignable instance of type). Null if none.\n" + + " */\n" + + " public static > T getFirstAssignableTo(\n" + + " Collection targets, T type) {\n" + + " for(Object target : targets) {\n" + + " if (type.isInstance(target)) return target;\n" + + " }\n" + + "\n" + + " return null;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Returns the first target object whose type is exactly the specified type.\n" + + " * @param targets Group of target objects (Object). If empty, returns null.\n" + + " * Never null.\n" + + " * @param type The type. Never null. objects (Object). Can be targets. Never\n" + + " * null.\n" + + " * @return The result (Object, exact instance of type). Null if none.\n" + + " */\n" + + " public static Object getFirstIdenticalTo(Collection targets, Class type) {\n" + + " Iterator targetI = targets.iterator();\n" + + " while (targetI.hasNext()) {\n" + + " Object target = targetI.next();\n" + + " if (type.equals(target.getClass())) return target;\n" + + " }\n" + + "\n" + + " return null;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Gets a target object T from a source object S in a group of objects, and\n" + + " * returns the target objects in result group R. A group object is ignored\n" + + " * if it is not a source type or, if it is a source type, its target object\n" + + " * is not a target type.\n" + + " * @param group Temp input group of shared exposed objects. If null, returns\n" + + " * empty.\n" + + " * @param sourceType Desired source object type. Never null.\n" + + " * @param getter Gets a target object from a source object. Never null.\n" + + " * @param targetType Desired target object type. Never null.\n" + + " * @param retVal Temp output group of shared exposed target objects. Never\n" + + " * null.\n" + + " * @return Reference to retVal. Never null.\n" + + " */\n" + + " public static > R getAll(\n" + + " Collection group, Class sourceType, Getter getter,\n" + + " Class targetType, R retVal) {\n" + + " if (sourceType == null) throw new IllegalArgumentException(\n" + + " \"Source type is null.\");\n" + + " if (getter == null) throw new IllegalArgumentException(\n" + + " \"Getter is null.\");\n" + + " if (targetType == null) throw new IllegalArgumentException(\n" + + " \"Target type is null.\");\n" + + " if (retVal == null) throw new IllegalArgumentException(\n" + + " \"Return value is null.\");\n" + + " retVal.clear();\n" + + "\n" + + " if (group == null) return retVal;\n" + + "\n" + + " for (Object obj : group) {\n" + + " if (!sourceType.isInstance(obj)) continue; // ignore\n" + + " S source = (S) obj;\n" + + " T target = getter.getFrom(source);\n" + + " if (!targetType.isInstance(target)) continue; // ignore\n" + + " retVal.add((TT) target);\n" + + " }\n" + + "\n" + + " return retVal;\n" + + " }\n" + + "\n" + + " /**\n" + + " * Similar to getAll(Collection, Class, Getter, Class, Collection), but all\n" + + " * target objects are returned, regardless of type, including nulls.\n" + + " * @param group Temp input group of shared exposed objects. If null, returns\n" + + " * empty.\n" + + " * @param sourceType Desired source object type. Never null.\n" + + " * @param getter Gets a target object from a source object. Never null.\n" + + " * @param retVal Temp output group of shared exposed target objects. Never\n" + + " * null.\n" + + " * @return Reference to retVal. Never null.\n" + + " */\n" + + " public static > R getAll(\n" + + " Collection group, Class sourceType, Getter getter,\n" + + " R retVal) {\n" + + " if (sourceType == null) throw new IllegalArgumentException(\n" + + " \"Source type is null.\");\n" + + " if (getter == null) throw new IllegalArgumentException(\n" + + " \"Getter is null.\");\n" + + " if (retVal == null) throw new IllegalArgumentException(\n" + + " \"Return value is null.\");\n" + + " retVal.clear();\n" + + "\n" + + " if (group == null) return retVal;\n" + + "\n" + + " for (Object obj : group) {\n" + + " if (!sourceType.isInstance(obj)) continue; // ignore\n" + + " S source = (S) obj;\n" + + " T target = getter.getFrom(source);\n" + + " retVal.add(target);\n" + + " }\n" + + "\n" + + " return retVal;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in TypeUtils.java (at line 441)\n" + + " public static > T getFirstAssignableTo(\n" + + " ^^^^^\n" + + "The type parameter T should not be bounded by the final type Class. Final types cannot be further extended\n" + + "----------\n" + + "2. ERROR in TypeUtils.java (at line 444)\n" + + " if (type.isInstance(target)) return target;\n" + + " ^^^^^^\n" + + "Type mismatch: cannot convert from Object to T\n" + + "----------\n" + + "3. WARNING in TypeUtils.java (at line 458)\n" + + " public static Object getFirstIdenticalTo(Collection targets, Class type) {\n" + + " ^^^^^^^^^^\n" + + "Collection is a raw type. References to generic type Collection should be parameterized\n" + + "----------\n" + + "4. WARNING in TypeUtils.java (at line 458)\n" + + " public static Object getFirstIdenticalTo(Collection targets, Class type) {\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n" + + "5. WARNING in TypeUtils.java (at line 459)\n" + + " Iterator targetI = targets.iterator();\n" + + " ^^^^^^^^\n" + + "Iterator is a raw type. References to generic type Iterator should be parameterized\n" + + "----------\n" + + "6. ERROR in TypeUtils.java (at line 483)\n" + + " Collection group, Class sourceType, Getter getter,\n" + + " ^^^^^^\n" + + "Getter cannot be resolved to a type\n" + + "----------\n" + + "7. WARNING in TypeUtils.java (at line 499)\n" + + " S source = (S) obj;\n" + + " ^^^^^^^\n" + + "Type safety: Unchecked cast from Object to S\n" + + "----------\n" + + "8. WARNING in TypeUtils.java (at line 502)\n" + + " retVal.add((TT) target);\n" + + " ^^^^^^^^^^^\n" + + "Type safety: Unchecked cast from T to TT\n" + + "----------\n" + + "9. ERROR in TypeUtils.java (at line 520)\n" + + " Collection group, Class sourceType, Getter getter,\n" + + " ^^^^^^\n" + + "Getter cannot be resolved to a type\n" + + "----------\n" + + "10. WARNING in TypeUtils.java (at line 534)\n" + + " S source = (S) obj;\n" + + " ^^^^^^^\n" + + "Type safety: Unchecked cast from Object to S\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250297 +public void test092() { + this.runNegativeTest( + new String[] { + "p1/p2/X.java", // ================= + "package p1.p2;\n" + + "public class X {\n" + + " public p2.p3.Z z() {return null;}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p1\\p2\\X.java (at line 3)\n" + + " public p2.p3.Z z() {return null;}\n" + + " ^^\n" + + "p2 cannot be resolved to a type\n" + + "----------\n", + null, + false, + null, + true, + false, + false + ); + Runner runner = new Runner(); + runner.javacTestOptions = JavacTestOptions.SKIP; // javac did not produce p1/p2/X.class which is needed below + runner.testFiles = + new String[] { + "a/b/A.java", // ================= + "package a.b;\n" + + "public class A {\n" + + " p1.p2.X x;\n" + + " void test() { x.z(); }\n" + + " void foo(p2.p3.Z z) {}\n" + + "}\n", + "p2/p3/Z.java", // ================= + "package p2.p3;\n" + + "public class Z {}\n" + }; + runner.shouldFlushOutputDirectory = false; + runner.runConformTest(); + runner.testFiles = + new String[] { + "a/b/A.java", // ================= + "package a.b;\n" + + "public class A {\n" + + " p1.p2.X x;\n" + + " void test() { x.z(); }\n" + + " void foo(p2.p3.Z z) {}\n" + + "}\n" + }; + runner.runConformTest(); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250297 - variation +public void test093() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo() {\n" + + " List zlist = null;\n" + + " bar(zlist.get(0));\n" + + " }\n" + + " T bar(T t) { return t; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " List zlist = null;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250297 - variation +public void test094() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo(boolean b, Runnable r) {\n" + + " bar(r);\n" + + " }\n" + + " T bar(Zork z) { return z; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " bar(r);\n" + + " ^^^\n" + + "The method bar(Zork) from the type X refers to the missing type Zork\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " T bar(Zork z) { return z; }\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250297 - variation +public void test095() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "X.java", // ================= + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " void foo(boolean b, Runnable r) {\n" + + " bar(r);\n" + + " }\n" + + " bar(Zork z) { return z; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " bar(r);\n" + + " ^^^\n" + + "The method bar(Runnable) is undefined for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " bar(Zork z) { return z; }\n" + + " ^^^^^^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " bar(Zork z) { return z; }\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=257384 +public void test096() { + this.runNegativeTest( + new String[] { + "p2/B.java", // ================= + "package p2;\n" + + "import p1.A;\n" + + "public abstract class B {\n" + + " public static A foo() {}\n" + + "}\n", + "p3/C.java", // ================= + "package p3;\n" + + "import p1.A;\n" + + "public abstract class C extends p2.B {\n" + + " public static A foo() {}\n" + + "}\n", + "p/D.java", // ================= + "package p;\n" + + "public class D extends p3.C {}" + }, + "----------\n" + + "1. ERROR in p2\\B.java (at line 2)\n" + + " import p1.A;\n" + + " ^^\n" + + "The import p1 cannot be resolved\n" + + "----------\n" + + "2. ERROR in p2\\B.java (at line 4)\n" + + " public static A foo() {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p3\\C.java (at line 2)\n" + + " import p1.A;\n" + + " ^^\n" + + "The import p1 cannot be resolved\n" + + "----------\n" + + "2. ERROR in p3\\C.java (at line 4)\n" + + " public static A foo() {}\n" + + " ^\n" + + "A cannot be resolved to a type\n" + + "----------\n" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=258248 +public void test097() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runNegativeTest( + new String[] { + "X.java", // ================= + "public class X {\n" + + "\n" + + " public static interface InnerInterface {\n" + + " }\n" + + " protected , ParamType extends TheTypeMirror> void testMethod(\n" + + " TheFieldDeclaratation fieldDeclaratation, Env\n" + + " environment) {\n" + + "\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " TheFieldDeclaratation fieldDeclaratation, Env\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "TheFieldDeclaratation cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660 +public void test098() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " private class A {\n" + + " public void foo(int a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(float a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(boolean a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(Integer a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + " private class B extends A {\n" + + " public void foo(int a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(float a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(double a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(char a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void foo(int a) {\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type X.A is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public void foo(float a) {\n" + + " ^^^^^^^^^^^^\n" + + "The method foo(float) from the type X.A is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public void foo(boolean a) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo(boolean) from the type X.A is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " public void foo(Integer a) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo(Integer) from the type X.A is never used locally\n" + + "----------\n" + + "5. WARNING in X.java (at line 16)\n" + + " private class B extends A {\n" + + " ^\n" + + "The type X.B is never used locally\n" + + "----------\n" + + "6. WARNING in X.java (at line 23)\n" + + " public void foo(double a) {\n" + + " ^^^^^^^^^^^^^\n" + + "The method foo(double) from the type X.B is never used locally\n" + + "----------\n" + + "7. WARNING in X.java (at line 26)\n" + + " public void foo(char a) {\n" + + " ^^^^^^^^^^^\n" + + "The method foo(char) from the type X.B is never used locally\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void foo(int a) {\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type X.A is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public void foo(float a) {\n" + + " ^^^^^^^^^^^^\n" + + "The method foo(float) from the type X.A is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public void foo(boolean a) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo(boolean) from the type X.A is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 12)\n" + + " public void foo(Integer a) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo(Integer) from the type X.A is never used locally\n" + + "----------\n" + + "5. WARNING in X.java (at line 16)\n" + + " private class B extends A {\n" + + " ^\n" + + "The type X.B is never used locally\n" + + "----------\n" + + "6. WARNING in X.java (at line 16)\n" + + " private class B extends A {\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n" + + "7. WARNING in X.java (at line 23)\n" + + " public void foo(double a) {\n" + + " ^^^^^^^^^^^^^\n" + + "The method foo(double) from the type X.B is never used locally\n" + + "----------\n" + + "8. WARNING in X.java (at line 26)\n" + + " public void foo(char a) {\n" + + " ^^^^^^^^^^^\n" + + "The method foo(char) from the type X.B is never used locally\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660 +public void test099() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " private class A {\n" + + " public void foo(int a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(float a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(boolean a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(Integer a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + " private class B extends A {\n" + + " public void foo(int a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(float a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(double a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(char a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + " public class C extends B {\n" + + " public void foo(int a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(double a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(boolean a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(byte a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void foo(int a) {\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type X.A is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public void foo(float a) {\n" + + " ^^^^^^^^^^^^\n" + + "The method foo(float) from the type X.A is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public void foo(boolean a) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo(boolean) from the type X.A is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 23)\n" + + " public void foo(double a) {\n" + + " ^^^^^^^^^^^^^\n" + + "The method foo(double) from the type X.B is never used locally\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void foo(int a) {\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type X.A is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " public void foo(float a) {\n" + + " ^^^^^^^^^^^^\n" + + "The method foo(float) from the type X.A is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public void foo(boolean a) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo(boolean) from the type X.A is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 16)\n" + + " private class B extends A {\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n" + + "5. WARNING in X.java (at line 23)\n" + + " public void foo(double a) {\n" + + " ^^^^^^^^^^^^^\n" + + "The method foo(double) from the type X.B is never used locally\n" + + "----------\n" + + "6. WARNING in X.java (at line 30)\n" + + " public class C extends B {\n" + + " ^\n" + + "Access to enclosing constructor X.B() is emulated by a synthetic accessor method\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660 +// check independence of textual order +public void test099a() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public class C extends B {\n" + + " public void foo(int a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(double a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(boolean a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(byte a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + " private class B extends A {\n" + + " public void foo(int a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(float a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(double a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(char a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + " private class A {\n" + + " public void foo(int a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(float a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(boolean a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(Integer a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in X.java (at line 23)\n" + + " public void foo(double a) {\n" + + " ^^^^^^^^^^^^^\n" + + "The method foo(double) from the type X.B is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 31)\n" + + " public void foo(int a) {\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type X.A is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 34)\n" + + " public void foo(float a) {\n" + + " ^^^^^^^^^^^^\n" + + "The method foo(float) from the type X.A is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 37)\n" + + " public void foo(boolean a) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo(boolean) from the type X.A is never used locally\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public class C extends B {\n" + + " ^\n" + + "Access to enclosing constructor X.B() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " private class B extends A {\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n" + + "3. WARNING in X.java (at line 23)\n" + + " public void foo(double a) {\n" + + " ^^^^^^^^^^^^^\n" + + "The method foo(double) from the type X.B is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 31)\n" + + " public void foo(int a) {\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type X.A is never used locally\n" + + "----------\n" + + "5. WARNING in X.java (at line 34)\n" + + " public void foo(float a) {\n" + + " ^^^^^^^^^^^^\n" + + "The method foo(float) from the type X.A is never used locally\n" + + "----------\n" + + "6. WARNING in X.java (at line 37)\n" + + " public void foo(boolean a) {\n" + + " ^^^^^^^^^^^^^^\n" + + "The method foo(boolean) from the type X.A is never used locally\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660 +// check usage via super-call +public void test099b() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " private class A {\n" + + " public void foo(int a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(float a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(boolean a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(Integer a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + " private class B extends A {\n" + + " public void foo(int a) {\n" + + " super.foo(a);\n" + + " }\n" + + " public void foo(float a) {\n" + + " super.foo(a);\n" + + " }\n" + + " public void foo(double a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(char a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + " public class C extends B {\n" + + " public void foo(int a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public void foo(double a) {\n" + + " super.foo(a);\n" + + " }\n" + + " public void foo(boolean a) {\n" + + " super.foo(a);\n" + + " }\n" + + " public void foo(byte a) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " }\n" + + "}\n" + }; + if (!isMinimumCompliant(ClassFileConstants.JDK11)) { + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 16)\n" + + " private class B extends A {\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n" + + "2. WARNING in X.java (at line 30)\n" + + " public class C extends B {\n" + + " ^\n" + + "Access to enclosing constructor X.B() is emulated by a synthetic accessor method\n" + + "----------\n"; + runner.runWarningTest(); + } else { + runner.runConformTest(); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660 +public void test100() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " private class A {\n" + + " public void foo() {}\n" + + " }\n" + + " public class B extends A {}\n" + + "}" + }; + if (!isMinimumCompliant(ClassFileConstants.JDK11)) { + + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public class B extends A {}\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); + } else { + runner.runConformTest(); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660 +public void test101() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " private class A {\n" + + " public void foo() {}\n" + + " public void foo(int a) {}\n" + + " }\n" + + " public class B extends A {}\n" + + "}" + }; + if (!isMinimumCompliant(ClassFileConstants.JDK11)) { + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " public class B extends A {}\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); + } else { + runner.runConformTest(); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660 +public void test102() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " private class A {\n" + + " private void foo() {}\n" + + " private void foo(int a) {}\n" + + " }\n" + + " public class B extends A {}\n" + + "}" + }; + runner.expectedCompilerLog = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private void foo() {}\n" + + " ^^^^^\n" + + "The method foo() from the type X.A is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " private void foo(int a) {}\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type X.A is never used locally\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private void foo() {}\n" + + " ^^^^^\n" + + "The method foo() from the type X.A is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " private void foo(int a) {}\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type X.A is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " public class B extends A {}\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660 +public void test103() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " private class A {\n" + + " public void foo() {}\n" + + " public void foo(int a) {}\n" + + " }\n" + + " private class B extends A {}\n" + + "}" + }; + runner.expectedCompilerLog = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void foo() {}\n" + + " ^^^^^\n" + + "The method foo() from the type X.A is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public void foo(int a) {}\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type X.A is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " private class B extends A {}\n" + + " ^\n" + + "The type X.B is never used locally\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void foo() {}\n" + + " ^^^^^\n" + + "The method foo() from the type X.A is never used locally\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " public void foo(int a) {}\n" + + " ^^^^^^^^^^\n" + + "The method foo(int) from the type X.A is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " private class B extends A {}\n" + + " ^\n" + + "The type X.B is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " private class B extends A {}\n" + + " ^\n" + + "Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +public void test104() { + this.runNegativeTest( + new String[] { + "p/Bar.java", //----------------------------------------------------------------------- + "package p;\n" + + "import q.Zork;\n" + + "public abstract class Bar {\n" + + " protected abstract boolean isBaz();\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\Bar.java (at line 2)\n" + + " import q.Zork;\n" + + " ^\n" + + "The import q cannot be resolved\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* no custom options */, + true /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + false /* do not perform statements recovery */); + Runner runner = new Runner(); + runner.shouldFlushOutputDirectory = + false; + runner.testFiles = + new String[] { + "X.java", //----------------------------------------------------------------------- + "import p.Bar;\n" + + "public class X extends Bar {\n" + + " protected boolean isBaz() {\n" + + " return false;\n" + + " }\n" + + "}", + }; + runner.expectedOutputString = + ""; + runner.javacTestOptions = + JavacTestOptions.Excuse.JavacHasErrorsEclipseHasNone; // ecj can create .class from erroneous .java + runner.runConformTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=243917 +public void test105() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static {\n" + + " System.loadLibrary(\"tpbrooktrout\");\n" + + " }\n" + + " private final int time;\n" + + " private int foo() { return 0;}\n" + + " private class Inner {}\n" + + " public X(int delay) {\n" + + " time = delay;\n" + + " }\n" + + " public native void run(Inner i);\n" + + "}\n" + }, + ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=245007 +public void test106() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Listener() {\n" + + " void foo(int a) { }\n" + + " }.bar();\n" + + " new Listener() {\n" + + " void foo(int a) { }\n" + + " }.field = 10;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new Listener() {\n" + + " ^^^^^^^^\n" + + "Listener cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " new Listener() {\n" + + " ^^^^^^^^\n" + + "Listener cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=319425 +public void test107() { + this.runNegativeTest( + new String[] { + "p/OuterBogus.java", //----------------------------------------------------------------------- + "package p;\n" + + "abstract final class OuterBogus {\n" + + " public static void call() {\n" + + " System.out.println(\"Hi. I'm outer bogus.\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\OuterBogus.java (at line 2)\n" + + " abstract final class OuterBogus {\n" + + " ^^^^^^^^^^\n" + + "The class OuterBogus can be either abstract or final, not both\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + null /* no custom options */, + true /* do not generate output */, + false /* do not show category */, + false /* do not show warning token */, + false /* do not skip javac for this peculiar test */, + false /* do not perform statements recovery */); + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "p/Bogus.java", //----------------------------------------------------------------------- + "package p;\n" + + "\n" + + "public class Bogus {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " OuterBogus.call();\n" + + " } catch(ClassFormatError e) {\n" + + " System.out.println(\"Wrong error found\");\n" + + " } catch(Error e) {\n" + + " System.out.println(\"Compilation error found\");\n" + + " }\n" + + " }\n" + + "}", + }; + runner.expectedOutputString = + "Compilation error found"; + runner.shouldFlushOutputDirectory = + false; + runner.javacTestOptions = + JavacTestOptions.Excuse.JavacHasErrorsEclipseHasNone; // ecj can create .class from erroneous .java + runner.runConformTest(); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=321414 +public void test108() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in SyntheticConstructorTooManyArgs.java (at line 23)\n" + + " @SuppressWarnings(\"synthetic-access\")\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"synthetic-access\")\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in SyntheticConstructorTooManyArgs.java (at line 4)\n" + + " private A(\n" + + " /*this,*/int p01, int p02, int p03, int p04, int p05, int p06, int p07, int p08, int p09, int p0a, int p0b, int p0c, int p0d, int p0e, int p0f, \n" + + " int p10, int p11, int p12, int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p1a, int p1b, int p1c, int p1d, int p1e, int p1f, \n" + + " int p20, int p21, int p22, int p23, int p24, int p25, int p26, int p27, int p28, int p29, int p2a, int p2b, int p2c, int p2d, int p2e, int p2f, \n" + + " int p30, int p31, int p32, int p33, int p34, int p35, int p36, int p37, int p38, int p39, int p3a, int p3b, int p3c, int p3d, int p3e, int p3f, \n" + + " int p40, int p41, int p42, int p43, int p44, int p45, int p46, int p47, int p48, int p49, int p4a, int p4b, int p4c, int p4d, int p4e, int p4f, \n" + + " int p50, int p51, int p52, int p53, int p54, int p55, int p56, int p57, int p58, int p59, int p5a, int p5b, int p5c, int p5d, int p5e, int p5f, \n" + + " int p60, int p61, int p62, int p63, int p64, int p65, int p66, int p67, int p68, int p69, int p6a, int p6b, int p6c, int p6d, int p6e, int p6f, \n" + + " int p70, int p71, int p72, int p73, int p74, int p75, int p76, int p77, int p78, int p79, int p7a, int p7b, int p7c, int p7d, int p7e, int p7f, \n" + + " int p80, int p81, int p82, int p83, int p84, int p85, int p86, int p87, int p88, int p89, int p8a, int p8b, int p8c, int p8d, int p8e, int p8f, \n" + + " int p90, int p91, int p92, int p93, int p94, int p95, int p96, int p97, int p98, int p99, int p9a, int p9b, int p9c, int p9d, int p9e, int p9f, \n" + + " int pa0, int pa1, int pa2, int pa3, int pa4, int pa5, int pa6, int pa7, int pa8, int pa9, int paa, int pab, int pac, int pad, int pae, int paf, \n" + + " int pb0, int pb1, int pb2, int pb3, int pb4, int pb5, int pb6, int pb7, int pb8, int pb9, int pba, int pbb, int pbc, int pbd, int pbe, int pbf, \n" + + " int pc0, int pc1, int pc2, int pc3, int pc4, int pc5, int pc6, int pc7, int pc8, int pc9, int pca, int pcb, int pcc, int pcd, int pce, int pcf, \n" + + " int pd0, int pd1, int pd2, int pd3, int pd4, int pd5, int pd6, int pd7, int pd8, int pd9, int pda, int pdb, int pdc, int pdd, int pde, int pdf, \n" + + " int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + + " int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc, int pfd, int pfe\n" + + " ) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The synthetic method created to access A(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) of type SyntheticConstructorTooManyArgs.A has too many parameters\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "SyntheticConstructorTooManyArgs.java", //----------------------------------------------------------------------- + "public class SyntheticConstructorTooManyArgs {\n" + + "\n" + + " static class A {\n" + + " private A(\n" + + " /*this,*/int p01, int p02, int p03, int p04, int p05, int p06, int p07, int p08, int p09, int p0a, int p0b, int p0c, int p0d, int p0e, int p0f, \n" + + " int p10, int p11, int p12, int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p1a, int p1b, int p1c, int p1d, int p1e, int p1f, \n" + + " int p20, int p21, int p22, int p23, int p24, int p25, int p26, int p27, int p28, int p29, int p2a, int p2b, int p2c, int p2d, int p2e, int p2f, \n" + + " int p30, int p31, int p32, int p33, int p34, int p35, int p36, int p37, int p38, int p39, int p3a, int p3b, int p3c, int p3d, int p3e, int p3f, \n" + + " int p40, int p41, int p42, int p43, int p44, int p45, int p46, int p47, int p48, int p49, int p4a, int p4b, int p4c, int p4d, int p4e, int p4f, \n" + + " int p50, int p51, int p52, int p53, int p54, int p55, int p56, int p57, int p58, int p59, int p5a, int p5b, int p5c, int p5d, int p5e, int p5f, \n" + + " int p60, int p61, int p62, int p63, int p64, int p65, int p66, int p67, int p68, int p69, int p6a, int p6b, int p6c, int p6d, int p6e, int p6f, \n" + + " int p70, int p71, int p72, int p73, int p74, int p75, int p76, int p77, int p78, int p79, int p7a, int p7b, int p7c, int p7d, int p7e, int p7f, \n" + + " int p80, int p81, int p82, int p83, int p84, int p85, int p86, int p87, int p88, int p89, int p8a, int p8b, int p8c, int p8d, int p8e, int p8f, \n" + + " int p90, int p91, int p92, int p93, int p94, int p95, int p96, int p97, int p98, int p99, int p9a, int p9b, int p9c, int p9d, int p9e, int p9f, \n" + + " int pa0, int pa1, int pa2, int pa3, int pa4, int pa5, int pa6, int pa7, int pa8, int pa9, int paa, int pab, int pac, int pad, int pae, int paf, \n" + + " int pb0, int pb1, int pb2, int pb3, int pb4, int pb5, int pb6, int pb7, int pb8, int pb9, int pba, int pbb, int pbc, int pbd, int pbe, int pbf, \n" + + " int pc0, int pc1, int pc2, int pc3, int pc4, int pc5, int pc6, int pc7, int pc8, int pc9, int pca, int pcb, int pcc, int pcd, int pce, int pcf, \n" + + " int pd0, int pd1, int pd2, int pd3, int pd4, int pd5, int pd6, int pd7, int pd8, int pd9, int pda, int pdb, int pdc, int pdd, int pde, int pdf, \n" + + " int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + + " int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc, int pfd, int pfe\n" + + " ) {}\n" + + " }\n" + + " @SuppressWarnings(\"synthetic-access\")\n" + + " A a = new A(\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n" + + " );\n" + + " public static void main(String[] args) {\n" + + " StringBuilder params = new StringBuilder();\n" + + " params.append(\"/*this,*/\");\n" + + " for (int p = 1; p < 255; p++) {\n" + + " if (p > 1) {\n" + + " params.append(\", \");\n" + + " if (p % 16 == 0)\n" + + " params.append('\\n');\n" + + " }\n" + + " params.append(\"int p\"\n" + + " + Character.forDigit(p / 16, 16)\n" + + " + Character.forDigit(p % 16, 16)\n" + + " );\n" + + " }\n" + + " System.out.println(params);\n" + + " A.class.getName(); // ClassFormatError\n" + + " }\n" + + "}", + }, + errMessage); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=321414 +public void test109() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runConformTest( + new String[] { + "SyntheticConstructorTooManyArgs.java", //----------------------------------------------------------------------- + "public class SyntheticConstructorTooManyArgs {\n" + + "\n" + + " static class A {\n" + + " private A foo(\n" + + " /*this,*/int p01, int p02, int p03, int p04, int p05, int p06, int p07, int p08, int p09, int p0a, int p0b, int p0c, int p0d, int p0e, int p0f, \n" + + " int p10, int p11, int p12, int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p1a, int p1b, int p1c, int p1d, int p1e, int p1f, \n" + + " int p20, int p21, int p22, int p23, int p24, int p25, int p26, int p27, int p28, int p29, int p2a, int p2b, int p2c, int p2d, int p2e, int p2f, \n" + + " int p30, int p31, int p32, int p33, int p34, int p35, int p36, int p37, int p38, int p39, int p3a, int p3b, int p3c, int p3d, int p3e, int p3f, \n" + + " int p40, int p41, int p42, int p43, int p44, int p45, int p46, int p47, int p48, int p49, int p4a, int p4b, int p4c, int p4d, int p4e, int p4f, \n" + + " int p50, int p51, int p52, int p53, int p54, int p55, int p56, int p57, int p58, int p59, int p5a, int p5b, int p5c, int p5d, int p5e, int p5f, \n" + + " int p60, int p61, int p62, int p63, int p64, int p65, int p66, int p67, int p68, int p69, int p6a, int p6b, int p6c, int p6d, int p6e, int p6f, \n" + + " int p70, int p71, int p72, int p73, int p74, int p75, int p76, int p77, int p78, int p79, int p7a, int p7b, int p7c, int p7d, int p7e, int p7f, \n" + + " int p80, int p81, int p82, int p83, int p84, int p85, int p86, int p87, int p88, int p89, int p8a, int p8b, int p8c, int p8d, int p8e, int p8f, \n" + + " int p90, int p91, int p92, int p93, int p94, int p95, int p96, int p97, int p98, int p99, int p9a, int p9b, int p9c, int p9d, int p9e, int p9f, \n" + + " int pa0, int pa1, int pa2, int pa3, int pa4, int pa5, int pa6, int pa7, int pa8, int pa9, int paa, int pab, int pac, int pad, int pae, int paf, \n" + + " int pb0, int pb1, int pb2, int pb3, int pb4, int pb5, int pb6, int pb7, int pb8, int pb9, int pba, int pbb, int pbc, int pbd, int pbe, int pbf, \n" + + " int pc0, int pc1, int pc2, int pc3, int pc4, int pc5, int pc6, int pc7, int pc8, int pc9, int pca, int pcb, int pcc, int pcd, int pce, int pcf, \n" + + " int pd0, int pd1, int pd2, int pd3, int pd4, int pd5, int pd6, int pd7, int pd8, int pd9, int pda, int pdb, int pdc, int pdd, int pde, int pdf, \n" + + " int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + + " int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc, int pfd, int pfe\n" + + " ) { return new A();}\n" + + " }\n" + + " @SuppressWarnings(\"synthetic-access\")\n" + + " A a = new A().foo(\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n" + + " );\n" + + " public static void main(String[] args) {\n" + + " StringBuilder params = new StringBuilder();\n" + + " params.append(\"/*this,*/\");\n" + + " for (int p = 1; p < 255; p++) {\n" + + " if (p > 1) {\n" + + " params.append(\", \");\n" + + " if (p % 16 == 0)\n" + + " params.append('\\n');\n" + + " }\n" + + " params.append(\"int p\"\n" + + " + Character.forDigit(p / 16, 16)\n" + + " + Character.forDigit(p % 16, 16)\n" + + " );\n" + + " }\n" + + " System.out.println(params);\n" + + " A.class.getName(); // ClassFormatError\n" + + " }\n" + + "}", + }, + "/*this,*/int p01, int p02, int p03, int p04, int p05, int p06, int p07, int p08, int p09, int p0a, int p0b, int p0c, int p0d, int p0e, int p0f, \n" + + "int p10, int p11, int p12, int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p1a, int p1b, int p1c, int p1d, int p1e, int p1f, \n" + + "int p20, int p21, int p22, int p23, int p24, int p25, int p26, int p27, int p28, int p29, int p2a, int p2b, int p2c, int p2d, int p2e, int p2f, \n" + + "int p30, int p31, int p32, int p33, int p34, int p35, int p36, int p37, int p38, int p39, int p3a, int p3b, int p3c, int p3d, int p3e, int p3f, \n" + + "int p40, int p41, int p42, int p43, int p44, int p45, int p46, int p47, int p48, int p49, int p4a, int p4b, int p4c, int p4d, int p4e, int p4f, \n" + + "int p50, int p51, int p52, int p53, int p54, int p55, int p56, int p57, int p58, int p59, int p5a, int p5b, int p5c, int p5d, int p5e, int p5f, \n" + + "int p60, int p61, int p62, int p63, int p64, int p65, int p66, int p67, int p68, int p69, int p6a, int p6b, int p6c, int p6d, int p6e, int p6f, \n" + + "int p70, int p71, int p72, int p73, int p74, int p75, int p76, int p77, int p78, int p79, int p7a, int p7b, int p7c, int p7d, int p7e, int p7f, \n" + + "int p80, int p81, int p82, int p83, int p84, int p85, int p86, int p87, int p88, int p89, int p8a, int p8b, int p8c, int p8d, int p8e, int p8f, \n" + + "int p90, int p91, int p92, int p93, int p94, int p95, int p96, int p97, int p98, int p99, int p9a, int p9b, int p9c, int p9d, int p9e, int p9f, \n" + + "int pa0, int pa1, int pa2, int pa3, int pa4, int pa5, int pa6, int pa7, int pa8, int pa9, int paa, int pab, int pac, int pad, int pae, int paf, \n" + + "int pb0, int pb1, int pb2, int pb3, int pb4, int pb5, int pb6, int pb7, int pb8, int pb9, int pba, int pbb, int pbc, int pbd, int pbe, int pbf, \n" + + "int pc0, int pc1, int pc2, int pc3, int pc4, int pc5, int pc6, int pc7, int pc8, int pc9, int pca, int pcb, int pcc, int pcd, int pce, int pcf, \n" + + "int pd0, int pd1, int pd2, int pd3, int pd4, int pd5, int pd6, int pd7, int pd8, int pd9, int pda, int pdb, int pdc, int pdd, int pde, int pdf, \n" + + "int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + + "int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc, int pfd, int pfe"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=321414 +public void test110() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runConformTest( + new String[] { + "SyntheticConstructorTooManyArgs.java", //----------------------------------------------------------------------- + "public class SyntheticConstructorTooManyArgs {\n" + + "\n" + + " static class A {\n" + + " private static A foo(\n" + + " /*this,*/int p01, int p02, int p03, int p04, int p05, int p06, int p07, int p08, int p09, int p0a, int p0b, int p0c, int p0d, int p0e, int p0f, \n" + + " int p10, int p11, int p12, int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p1a, int p1b, int p1c, int p1d, int p1e, int p1f, \n" + + " int p20, int p21, int p22, int p23, int p24, int p25, int p26, int p27, int p28, int p29, int p2a, int p2b, int p2c, int p2d, int p2e, int p2f, \n" + + " int p30, int p31, int p32, int p33, int p34, int p35, int p36, int p37, int p38, int p39, int p3a, int p3b, int p3c, int p3d, int p3e, int p3f, \n" + + " int p40, int p41, int p42, int p43, int p44, int p45, int p46, int p47, int p48, int p49, int p4a, int p4b, int p4c, int p4d, int p4e, int p4f, \n" + + " int p50, int p51, int p52, int p53, int p54, int p55, int p56, int p57, int p58, int p59, int p5a, int p5b, int p5c, int p5d, int p5e, int p5f, \n" + + " int p60, int p61, int p62, int p63, int p64, int p65, int p66, int p67, int p68, int p69, int p6a, int p6b, int p6c, int p6d, int p6e, int p6f, \n" + + " int p70, int p71, int p72, int p73, int p74, int p75, int p76, int p77, int p78, int p79, int p7a, int p7b, int p7c, int p7d, int p7e, int p7f, \n" + + " int p80, int p81, int p82, int p83, int p84, int p85, int p86, int p87, int p88, int p89, int p8a, int p8b, int p8c, int p8d, int p8e, int p8f, \n" + + " int p90, int p91, int p92, int p93, int p94, int p95, int p96, int p97, int p98, int p99, int p9a, int p9b, int p9c, int p9d, int p9e, int p9f, \n" + + " int pa0, int pa1, int pa2, int pa3, int pa4, int pa5, int pa6, int pa7, int pa8, int pa9, int paa, int pab, int pac, int pad, int pae, int paf, \n" + + " int pb0, int pb1, int pb2, int pb3, int pb4, int pb5, int pb6, int pb7, int pb8, int pb9, int pba, int pbb, int pbc, int pbd, int pbe, int pbf, \n" + + " int pc0, int pc1, int pc2, int pc3, int pc4, int pc5, int pc6, int pc7, int pc8, int pc9, int pca, int pcb, int pcc, int pcd, int pce, int pcf, \n" + + " int pd0, int pd1, int pd2, int pd3, int pd4, int pd5, int pd6, int pd7, int pd8, int pd9, int pda, int pdb, int pdc, int pdd, int pde, int pdf, \n" + + " int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + + " int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc, int pfd, int pfe\n" + + " ) { return new A();}\n" + + " }\n" + + " @SuppressWarnings(\"synthetic-access\")\n" + + " A a = A.foo(\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n" + + " );\n" + + " public static void main(String[] args) {\n" + + " StringBuilder params = new StringBuilder();\n" + + " params.append(\"/*this,*/\");\n" + + " for (int p = 1; p < 255; p++) {\n" + + " if (p > 1) {\n" + + " params.append(\", \");\n" + + " if (p % 16 == 0)\n" + + " params.append('\\n');\n" + + " }\n" + + " params.append(\"int p\"\n" + + " + Character.forDigit(p / 16, 16)\n" + + " + Character.forDigit(p % 16, 16)\n" + + " );\n" + + " }\n" + + " System.out.println(params);\n" + + " A.class.getName(); // ClassFormatError\n" + + " }\n" + + "}", + }, + "/*this,*/int p01, int p02, int p03, int p04, int p05, int p06, int p07, int p08, int p09, int p0a, int p0b, int p0c, int p0d, int p0e, int p0f, \n" + + "int p10, int p11, int p12, int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p1a, int p1b, int p1c, int p1d, int p1e, int p1f, \n" + + "int p20, int p21, int p22, int p23, int p24, int p25, int p26, int p27, int p28, int p29, int p2a, int p2b, int p2c, int p2d, int p2e, int p2f, \n" + + "int p30, int p31, int p32, int p33, int p34, int p35, int p36, int p37, int p38, int p39, int p3a, int p3b, int p3c, int p3d, int p3e, int p3f, \n" + + "int p40, int p41, int p42, int p43, int p44, int p45, int p46, int p47, int p48, int p49, int p4a, int p4b, int p4c, int p4d, int p4e, int p4f, \n" + + "int p50, int p51, int p52, int p53, int p54, int p55, int p56, int p57, int p58, int p59, int p5a, int p5b, int p5c, int p5d, int p5e, int p5f, \n" + + "int p60, int p61, int p62, int p63, int p64, int p65, int p66, int p67, int p68, int p69, int p6a, int p6b, int p6c, int p6d, int p6e, int p6f, \n" + + "int p70, int p71, int p72, int p73, int p74, int p75, int p76, int p77, int p78, int p79, int p7a, int p7b, int p7c, int p7d, int p7e, int p7f, \n" + + "int p80, int p81, int p82, int p83, int p84, int p85, int p86, int p87, int p88, int p89, int p8a, int p8b, int p8c, int p8d, int p8e, int p8f, \n" + + "int p90, int p91, int p92, int p93, int p94, int p95, int p96, int p97, int p98, int p99, int p9a, int p9b, int p9c, int p9d, int p9e, int p9f, \n" + + "int pa0, int pa1, int pa2, int pa3, int pa4, int pa5, int pa6, int pa7, int pa8, int pa9, int paa, int pab, int pac, int pad, int pae, int paf, \n" + + "int pb0, int pb1, int pb2, int pb3, int pb4, int pb5, int pb6, int pb7, int pb8, int pb9, int pba, int pbb, int pbc, int pbd, int pbe, int pbf, \n" + + "int pc0, int pc1, int pc2, int pc3, int pc4, int pc5, int pc6, int pc7, int pc8, int pc9, int pca, int pcb, int pcc, int pcd, int pce, int pcf, \n" + + "int pd0, int pd1, int pd2, int pd3, int pd4, int pd5, int pd6, int pd7, int pd8, int pd9, int pda, int pdb, int pdc, int pdd, int pde, int pdf, \n" + + "int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + + "int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc, int pfd, int pfe"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=321414 +public void test111() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + String errMessage = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in SyntheticConstructorTooManyArgs.java (at line 23)\n" + + " @SuppressWarnings(\"synthetic-access\")\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"synthetic-access\")\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in SyntheticConstructorTooManyArgs.java (at line 4)\n" + + " private A(\n" + + " /*this,*/int p01, int p02, int p03, int p04, int p05, int p06, int p07, int p08, int p09, int p0a, int p0b, int p0c, int p0d, int p0e, int p0f, \n" + + " int p10, int p11, int p12, int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p1a, int p1b, int p1c, int p1d, int p1e, int p1f, \n" + + " int p20, int p21, int p22, int p23, int p24, int p25, int p26, int p27, int p28, int p29, int p2a, int p2b, int p2c, int p2d, int p2e, int p2f, \n" + + " int p30, int p31, int p32, int p33, int p34, int p35, int p36, int p37, int p38, int p39, int p3a, int p3b, int p3c, int p3d, int p3e, int p3f, \n" + + " int p40, int p41, int p42, int p43, int p44, int p45, int p46, int p47, int p48, int p49, int p4a, int p4b, int p4c, int p4d, int p4e, int p4f, \n" + + " int p50, int p51, int p52, int p53, int p54, int p55, int p56, int p57, int p58, int p59, int p5a, int p5b, int p5c, int p5d, int p5e, int p5f, \n" + + " int p60, int p61, int p62, int p63, int p64, int p65, int p66, int p67, int p68, int p69, int p6a, int p6b, int p6c, int p6d, int p6e, int p6f, \n" + + " int p70, int p71, int p72, int p73, int p74, int p75, int p76, int p77, int p78, int p79, int p7a, int p7b, int p7c, int p7d, int p7e, int p7f, \n" + + " int p80, int p81, int p82, int p83, int p84, int p85, int p86, int p87, int p88, int p89, int p8a, int p8b, int p8c, int p8d, int p8e, int p8f, \n" + + " int p90, int p91, int p92, int p93, int p94, int p95, int p96, int p97, int p98, int p99, int p9a, int p9b, int p9c, int p9d, int p9e, int p9f, \n" + + " int pa0, int pa1, int pa2, int pa3, int pa4, int pa5, int pa6, int pa7, int pa8, int pa9, int paa, int pab, int pac, int pad, int pae, int paf, \n" + + " int pb0, int pb1, int pb2, int pb3, int pb4, int pb5, int pb6, int pb7, int pb8, int pb9, int pba, int pbb, int pbc, int pbd, int pbe, int pbf, \n" + + " int pc0, int pc1, int pc2, int pc3, int pc4, int pc5, int pc6, int pc7, int pc8, int pc9, int pca, int pcb, int pcc, int pcd, int pce, int pcf, \n" + + " int pd0, int pd1, int pd2, int pd3, int pd4, int pd5, int pd6, int pd7, int pd8, int pd9, int pda, int pdb, int pdc, int pdd, int pde, int pdf, \n" + + " int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + + " int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc, int pfd\n" + + " ) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The synthetic method created to access A(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) of type SyntheticConstructorTooManyArgs.A has too many parameters\n" + + "----------\n"; + this.runNegativeTest( + new String[] { + "SyntheticConstructorTooManyArgs.java", //----------------------------------------------------------------------- + "public class SyntheticConstructorTooManyArgs {\n" + + "\n" + + " class A {\n" + + " private A(\n" + + " /*this,*/int p01, int p02, int p03, int p04, int p05, int p06, int p07, int p08, int p09, int p0a, int p0b, int p0c, int p0d, int p0e, int p0f, \n" + + " int p10, int p11, int p12, int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p1a, int p1b, int p1c, int p1d, int p1e, int p1f, \n" + + " int p20, int p21, int p22, int p23, int p24, int p25, int p26, int p27, int p28, int p29, int p2a, int p2b, int p2c, int p2d, int p2e, int p2f, \n" + + " int p30, int p31, int p32, int p33, int p34, int p35, int p36, int p37, int p38, int p39, int p3a, int p3b, int p3c, int p3d, int p3e, int p3f, \n" + + " int p40, int p41, int p42, int p43, int p44, int p45, int p46, int p47, int p48, int p49, int p4a, int p4b, int p4c, int p4d, int p4e, int p4f, \n" + + " int p50, int p51, int p52, int p53, int p54, int p55, int p56, int p57, int p58, int p59, int p5a, int p5b, int p5c, int p5d, int p5e, int p5f, \n" + + " int p60, int p61, int p62, int p63, int p64, int p65, int p66, int p67, int p68, int p69, int p6a, int p6b, int p6c, int p6d, int p6e, int p6f, \n" + + " int p70, int p71, int p72, int p73, int p74, int p75, int p76, int p77, int p78, int p79, int p7a, int p7b, int p7c, int p7d, int p7e, int p7f, \n" + + " int p80, int p81, int p82, int p83, int p84, int p85, int p86, int p87, int p88, int p89, int p8a, int p8b, int p8c, int p8d, int p8e, int p8f, \n" + + " int p90, int p91, int p92, int p93, int p94, int p95, int p96, int p97, int p98, int p99, int p9a, int p9b, int p9c, int p9d, int p9e, int p9f, \n" + + " int pa0, int pa1, int pa2, int pa3, int pa4, int pa5, int pa6, int pa7, int pa8, int pa9, int paa, int pab, int pac, int pad, int pae, int paf, \n" + + " int pb0, int pb1, int pb2, int pb3, int pb4, int pb5, int pb6, int pb7, int pb8, int pb9, int pba, int pbb, int pbc, int pbd, int pbe, int pbf, \n" + + " int pc0, int pc1, int pc2, int pc3, int pc4, int pc5, int pc6, int pc7, int pc8, int pc9, int pca, int pcb, int pcc, int pcd, int pce, int pcf, \n" + + " int pd0, int pd1, int pd2, int pd3, int pd4, int pd5, int pd6, int pd7, int pd8, int pd9, int pda, int pdb, int pdc, int pdd, int pde, int pdf, \n" + + " int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + + " int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc, int pfd\n" + + " ) {}\n" + + " }\n" + + " @SuppressWarnings(\"synthetic-access\")\n" + + " A a = new A(\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0\n" + + " );\n" + + " public static void main(String[] args) {\n" + + " StringBuilder params = new StringBuilder();\n" + + " params.append(\"/*this,*/\");\n" + + " for (int p = 1; p < 255; p++) {\n" + + " if (p > 1) {\n" + + " params.append(\", \");\n" + + " if (p % 16 == 0)\n" + + " params.append('\\n');\n" + + " }\n" + + " params.append(\"int p\"\n" + + " + Character.forDigit(p / 16, 16)\n" + + " + Character.forDigit(p % 16, 16)\n" + + " );\n" + + " }\n" + + " System.out.println(params);\n" + + " A.class.getName(); // ClassFormatError\n" + + " }\n" + + "}", + }, + errMessage); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=321414 +public void test112() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + this.runConformTest( + new String[] { + "SyntheticConstructorTooManyArgs.java", //----------------------------------------------------------------------- + "public class SyntheticConstructorTooManyArgs {\n" + + "\n" + + " class A {\n" + + " private A(\n" + + " /*this,*/int p01, int p02, int p03, int p04, int p05, int p06, int p07, int p08, int p09, int p0a, int p0b, int p0c, int p0d, int p0e, int p0f, \n" + + " int p10, int p11, int p12, int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p1a, int p1b, int p1c, int p1d, int p1e, int p1f, \n" + + " int p20, int p21, int p22, int p23, int p24, int p25, int p26, int p27, int p28, int p29, int p2a, int p2b, int p2c, int p2d, int p2e, int p2f, \n" + + " int p30, int p31, int p32, int p33, int p34, int p35, int p36, int p37, int p38, int p39, int p3a, int p3b, int p3c, int p3d, int p3e, int p3f, \n" + + " int p40, int p41, int p42, int p43, int p44, int p45, int p46, int p47, int p48, int p49, int p4a, int p4b, int p4c, int p4d, int p4e, int p4f, \n" + + " int p50, int p51, int p52, int p53, int p54, int p55, int p56, int p57, int p58, int p59, int p5a, int p5b, int p5c, int p5d, int p5e, int p5f, \n" + + " int p60, int p61, int p62, int p63, int p64, int p65, int p66, int p67, int p68, int p69, int p6a, int p6b, int p6c, int p6d, int p6e, int p6f, \n" + + " int p70, int p71, int p72, int p73, int p74, int p75, int p76, int p77, int p78, int p79, int p7a, int p7b, int p7c, int p7d, int p7e, int p7f, \n" + + " int p80, int p81, int p82, int p83, int p84, int p85, int p86, int p87, int p88, int p89, int p8a, int p8b, int p8c, int p8d, int p8e, int p8f, \n" + + " int p90, int p91, int p92, int p93, int p94, int p95, int p96, int p97, int p98, int p99, int p9a, int p9b, int p9c, int p9d, int p9e, int p9f, \n" + + " int pa0, int pa1, int pa2, int pa3, int pa4, int pa5, int pa6, int pa7, int pa8, int pa9, int paa, int pab, int pac, int pad, int pae, int paf, \n" + + " int pb0, int pb1, int pb2, int pb3, int pb4, int pb5, int pb6, int pb7, int pb8, int pb9, int pba, int pbb, int pbc, int pbd, int pbe, int pbf, \n" + + " int pc0, int pc1, int pc2, int pc3, int pc4, int pc5, int pc6, int pc7, int pc8, int pc9, int pca, int pcb, int pcc, int pcd, int pce, int pcf, \n" + + " int pd0, int pd1, int pd2, int pd3, int pd4, int pd5, int pd6, int pd7, int pd8, int pd9, int pda, int pdb, int pdc, int pdd, int pde, int pdf, \n" + + " int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + + " int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc\n" + + " ) {}\n" + + " }\n" + + " @SuppressWarnings(\"synthetic-access\")\n" + + " A a = new A(\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\n" + + " 0,0,0,0,0,0,0,0,0,0,0,0,0\n" + + " );\n" + + " public static void main(String[] args) {\n" + + " StringBuilder params = new StringBuilder();\n" + + " params.append(\"/*this,*/\");\n" + + " for (int p = 1; p < 253; p++) {\n" + + " if (p > 1) {\n" + + " params.append(\", \");\n" + + " if (p % 16 == 0)\n" + + " params.append('\\n');\n" + + " }\n" + + " params.append(\"int p\"\n" + + " + Character.forDigit(p / 16, 16)\n" + + " + Character.forDigit(p % 16, 16)\n" + + " );\n" + + " }\n" + + " System.out.println(params);\n" + + " A.class.getName(); // ClassFormatError\n" + + " }\n" + + "}", + }, + "/*this,*/int p01, int p02, int p03, int p04, int p05, int p06, int p07, int p08, int p09, int p0a, int p0b, int p0c, int p0d, int p0e, int p0f, \n" + + "int p10, int p11, int p12, int p13, int p14, int p15, int p16, int p17, int p18, int p19, int p1a, int p1b, int p1c, int p1d, int p1e, int p1f, \n" + + "int p20, int p21, int p22, int p23, int p24, int p25, int p26, int p27, int p28, int p29, int p2a, int p2b, int p2c, int p2d, int p2e, int p2f, \n" + + "int p30, int p31, int p32, int p33, int p34, int p35, int p36, int p37, int p38, int p39, int p3a, int p3b, int p3c, int p3d, int p3e, int p3f, \n" + + "int p40, int p41, int p42, int p43, int p44, int p45, int p46, int p47, int p48, int p49, int p4a, int p4b, int p4c, int p4d, int p4e, int p4f, \n" + + "int p50, int p51, int p52, int p53, int p54, int p55, int p56, int p57, int p58, int p59, int p5a, int p5b, int p5c, int p5d, int p5e, int p5f, \n" + + "int p60, int p61, int p62, int p63, int p64, int p65, int p66, int p67, int p68, int p69, int p6a, int p6b, int p6c, int p6d, int p6e, int p6f, \n" + + "int p70, int p71, int p72, int p73, int p74, int p75, int p76, int p77, int p78, int p79, int p7a, int p7b, int p7c, int p7d, int p7e, int p7f, \n" + + "int p80, int p81, int p82, int p83, int p84, int p85, int p86, int p87, int p88, int p89, int p8a, int p8b, int p8c, int p8d, int p8e, int p8f, \n" + + "int p90, int p91, int p92, int p93, int p94, int p95, int p96, int p97, int p98, int p99, int p9a, int p9b, int p9c, int p9d, int p9e, int p9f, \n" + + "int pa0, int pa1, int pa2, int pa3, int pa4, int pa5, int pa6, int pa7, int pa8, int pa9, int paa, int pab, int pac, int pad, int pae, int paf, \n" + + "int pb0, int pb1, int pb2, int pb3, int pb4, int pb5, int pb6, int pb7, int pb8, int pb9, int pba, int pbb, int pbc, int pbd, int pbe, int pbf, \n" + + "int pc0, int pc1, int pc2, int pc3, int pc4, int pc5, int pc6, int pc7, int pc8, int pc9, int pca, int pcb, int pcc, int pcd, int pce, int pcf, \n" + + "int pd0, int pd1, int pd2, int pd3, int pd4, int pd5, int pd6, int pd7, int pd8, int pd9, int pda, int pdb, int pdc, int pdd, int pde, int pdf, \n" + + "int pe0, int pe1, int pe2, int pe3, int pe4, int pe5, int pe6, int pe7, int pe8, int pe9, int pea, int peb, int pec, int ped, int pee, int pef, \n" + + "int pf0, int pf1, int pf2, int pf3, int pf4, int pf5, int pf6, int pf7, int pf8, int pf9, int pfa, int pfb, int pfc"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=325567 +public void test113() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void bar(int i) {\n" + + " final String before;\n" + + " try {\n" + + " before = foo();\n" + + " } catch (IOException e) {\n" + + " // ignore\n" + + " }\n" + + " B b = new B(new I() {\n" + + " public String bar() {\n" + + " return new String(before);\n" + + " }\n" + + " });\n" + + " try {\n" + + " b.toString();\n" + + " } catch(Exception e) {\n" + + " // ignore\n" + + " }\n" + + " }\n" + + " private static String foo() throws IOException {\n" + + " return null;\n" + + " }\n" + + " static class B {\n" + + " B(I i) {\n" + + " //ignore\n" + + " }\n" + + " }\n" + + " static interface I {\n" + + " String bar();\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " return new String(before);\n" + + " ^^^^^^\n" + + "The local variable before may not have been initialized\n" + + "----------\n"; + runner.generateOutput = + true; + runner.runNegativeTest(); + + runner = new Runner(); + runner.testFiles = + new String[] { + "Y.java", //----------------------------------------------------------------------- + "public class Y {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " X.bar(3);\n" + + " } catch(VerifyError e) {\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + " }\n" + + "}", + }; + runner.expectedOutputString = + ""; + runner.shouldFlushOutputDirectory = + false; + runner.javacTestOptions = + JavacTestOptions.Excuse.JavacHasErrorsEclipseHasNone; // ecj can create .class from erroneous .java + runner.runConformTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// QualifiedNameReference, SingleNameReference and MessageSend +// Can be static warning shown +public void test114() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public static int field1;\n" + + " public static int field2;\n" + + " public void bar(int i) {\n" + + " System.out.println(foo());\n" + + " foo();" + + " System.out.println(X.field1);\n" + + " System.out.println(field2);\n" + + " field2 = 1;\n" + + " }\n" + + " public final void bar2(int i) {\n" + + " System.out.println(foo());\n" + + " foo();" + + " System.out.println(X.field1);\n" + + " System.out.println(field2);\n" + + " field2 = 1;\n" + + " }\n" + + " private void bar3(int i) {\n" + + " System.out.println(foo());\n" + + " foo();" + + " System.out.println(X.field1);\n" + + " System.out.println(field2);\n" + + " field2 = 1;\n" + + " }\n" + + " private static String foo() {\n" + + " return null;\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public void bar(int i) {\n" + + " ^^^^^^^^^^\n" + + "The method bar(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " public final void bar2(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar2(int) from the type X can be declared as static\n" + + "----------\n" + + "3. WARNING in X.java (at line 16)\n" + + " private void bar3(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar3(int) from the type X is never used locally\n" + + "----------\n" + + "4. ERROR in X.java (at line 16)\n" + + " private void bar3(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar3(int) from the type X can be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// FieldReference and MessageSend +// Can be static warning shown +public void test115() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X extends B{\n" + + " public static int field1;\n" + + " public static int field2;\n" + + " public void bar(int i) {\n" + + " System.out.println(foo());\n" + + " X.field2 = 2;\n" + + " System.out.println(field1);\n" + + " A a = new A();\n" + + " a.a1();\n" + + " }\n" + + " private static String foo() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class A{\n" + + " public void a1() {\n" + + " }\n" + + "}\n" + + "class B{\n" + + " public void b1(){\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public void bar(int i) {\n" + + " ^^^^^^^^^^\n" + + "The method bar(int) from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// MessageSend in different ways +public void test116a() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X extends B{\n" + + " public static int field1;\n" + + " public X xfield;\n" + + " public void bar1(int i) {\n" + + " baz();\n" + + " }\n" + + " public void bar2(int i) {\n" + + " this.baz();\n" + + " }\n" + + " public void bar3(int i) {\n" + + " this.xfield.baz();\n" + + " }\n" + + " public void bar4(int i) {\n" + + " xfield.baz();\n" + + " }\n" + + " public void bar5(int i) {\n" + + " X x = new X();\n" + + " x.baz();\n" + + " }\n" + + " public void bar6(int i) {\n" + + " A.xA.baz();\n" + + " }\n" + + " public void bar7(int i) {\n" + + " b1();\n" + + " }\n" + + " public void bar8(int i) {\n" + + " this.b1();\n" + + " }\n" + + " public void bar9(int i) {\n" + + " new X().b1();\n" + + " }\n" + + " public void baz() {\n" + + " }\n" + + "}\n" + + "class A{\n" + + " public static X xA;\n" + + "}\n" + + "class B{\n" + + " public void b1(){\n" + + " }\n" + + "}", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " public void bar5(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar5(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " public void bar6(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar6(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "3. ERROR in X.java (at line 29)\n" + + " public void bar9(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar9(int) from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// MessageSend in different ways, referencing a static method. +public void test116b() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X extends B{\n" + + " public static int field1;\n" + + " public static X xfield;\n" + + " public void bar1(int i) {\n" + + " baz();\n" + + " }\n" + + " public void bar2(int i) {\n" + + " this.baz();\n" + + " }\n" + + " public void bar3(int i) {\n" + + " this.xfield.baz();\n" + + " }\n" + + " public void bar4(int i) {\n" + + " xfield.baz();\n" + + " }\n" + + " public void bar5(int i) {\n" + + " X x = new X();\n" + + " x.baz();\n" + + " }\n" + + " public void bar6(int i) {\n" + + " A.xA.baz();\n" + + " }\n" + + " public void bar7(int i) {\n" + + " b1();\n" + + " }\n" + + " public void bar8(int i) {\n" + + " this.b1();\n" + + " }\n" + + " public void bar9(int i) {\n" + + " new X().b1();\n" + + " }\n" + + " public static void baz() {\n" + + " }\n" + + "}\n" + + "class A{\n" + + " public static X xA;\n" + + "}\n" + + "class B{\n" + + " public static void b1(){\n" + + " }\n" + + "}", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public void bar1(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar1(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " public void bar4(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar4(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " public void bar5(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar5(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " public void bar6(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar6(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "5. ERROR in X.java (at line 23)\n" + + " public void bar7(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar7(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "6. ERROR in X.java (at line 29)\n" + + " public void bar9(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar9(int) from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// Referring a field in different ways, accessing non-static field. +public void test117a() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X extends B{\n" + + " public int field1;\n" + + " public X xfield;\n" + + " public void bar1(int i) {\n" + + " field1 = 1;\n" + + " }\n" + + " public void bar2(int i) {\n" + + " this.field1 = 1;\n" + + " }\n" + + " public void bar3(int i) {\n" + + " System.out.println(field1);\n" + + " }\n" + + " public void bar4(int i) {\n" + + " System.out.println(this.field1);\n" + + " }\n" + + " public void bar5(int i) {\n" + + " X x = new X();\n" + + " x.field1 = 1;\n" + + " }\n" + + " public void bar6(int i) {\n" + + " A.xA.field1 = 1;\n" + + " }\n" + + " public void bar7(int i) {\n" + + " b1 = 1;\n" + + " }\n" + + " public void bar8(int i) {\n" + + " this.b1 = 1;\n" + + " }\n" + + " public void bar9(int i) {\n" + + " new X().b1 = 1;\n" + + " }\n" + + " public void bar10(int i) {\n" + + " this.xfield.field1 = 1;\n" + + " }\n" + + " public void bar11(int i) {\n" + + " System.out.println(this.xfield.field1);\n" + + " }\n" + + " public void bar12(int i) {\n" + + " System.out.println(new X().b1);\n" + + " }\n" + + " public void bar13(int i) {\n" + + " System.out.println(b1);\n" + + " }\n" + + " public void bar14(int i) {\n" + + " System.out.println(this.b1);\n" + + " }\n" + + " public void bar15(int i) {\n" + + " xfield.field1 = 1;\n" + + " }\n" + + " public void bar16(int i) {\n" + + " System.out.println(xfield.field1);\n" + + " }\n" + + " public void baz() {\n" + + " }\n" + + "}\n" + + "class A{\n" + + " public static X xA;\n" + + "}\n" + + "class B{\n" + + " public int b1;\n" + + "}", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 16)\n" + + " public void bar5(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar5(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " public void bar6(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar6(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "3. ERROR in X.java (at line 29)\n" + + " public void bar9(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar9(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "4. ERROR in X.java (at line 38)\n" + + " public void bar12(int i) {\n" + + " ^^^^^^^^^^^^\n" + + "The method bar12(int) from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// Referring a field in different ways, accessing non-static field. +public void test117b() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X extends B{\n" + + " public static int field1;\n" + + " public static X xfield;\n" + + " public void bar1(int i) {\n" + + " field1 = 1;\n" + + " }\n" + + " public void bar2(int i) {\n" + + " this.field1 = 1;\n" + + " }\n" + + " public void bar3(int i) {\n" + + " System.out.println(field1);\n" + + " }\n" + + " public void bar4(int i) {\n" + + " System.out.println(this.field1);\n" + + " }\n" + + " public void bar5(int i) {\n" + + " X x = new X();\n" + + " x.field1 = 1;\n" + + " }\n" + + " public void bar6(int i) {\n" + + " A.xA.field1 = 1;\n" + + " }\n" + + " public void bar7(int i) {\n" + + " b1 = 1;\n" + + " }\n" + + " public void bar8(int i) {\n" + + " this.b1 = 1;\n" + + " }\n" + + " public void bar9(int i) {\n" + + " new X().b1 = 1;\n" + + " }\n" + + " public void bar10(int i) {\n" + + " this.xfield.field1 = 1;\n" + + " }\n" + + " public void bar11(int i) {\n" + + " System.out.println(this.xfield.field1);\n" + + " }\n" + + " public void bar12(int i) {\n" + + " System.out.println(new X().b1);\n" + + " }\n" + + " public void bar13(int i) {\n" + + " System.out.println(b1);\n" + + " }\n" + + " public void bar14(int i) {\n" + + " System.out.println(this.b1);\n" + + " }\n" + + " public void bar15(int i) {\n" + + " xfield.field1 = 1;\n" + + " }\n" + + " public void bar16(int i) {\n" + + " System.out.println(xfield.field1);\n" + + " }\n" + + " public void baz() {\n" + + " }\n" + + "}\n" + + "class A{\n" + + " public static X xA;\n" + + "}\n" + + "class B{\n" + + " public static int b1;\n" + + "}", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public void bar1(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar1(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " public void bar3(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar3(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " public void bar5(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar5(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "4. ERROR in X.java (at line 20)\n" + + " public void bar6(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar6(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "5. ERROR in X.java (at line 23)\n" + + " public void bar7(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar7(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "6. ERROR in X.java (at line 29)\n" + + " public void bar9(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar9(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "7. ERROR in X.java (at line 38)\n" + + " public void bar12(int i) {\n" + + " ^^^^^^^^^^^^\n" + + "The method bar12(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "8. ERROR in X.java (at line 41)\n" + + " public void bar13(int i) {\n" + + " ^^^^^^^^^^^^\n" + + "The method bar13(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "9. ERROR in X.java (at line 47)\n" + + " public void bar15(int i) {\n" + + " ^^^^^^^^^^^^\n" + + "The method bar15(int) from the type X can potentially be declared as static\n" + + "----------\n" + + "10. ERROR in X.java (at line 50)\n" + + " public void bar16(int i) {\n" + + " ^^^^^^^^^^^^\n" + + "The method bar16(int) from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// Final class -> can be static (and not potentially be static) warning shown +public void test118() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "X.java", + "final public class X {\n" + + " public static int field1;\n" + + " public static int field2;\n" + + " public void bar(int i) {\n" + + " System.out.println(foo());\n" + + " foo();" + + " System.out.println(X.field1);\n" + + " System.out.println(field2);\n" + + " field2 = 1;\n" + + " }\n" + + " public static int foo(){ return 1;}\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public void bar(int i) {\n" + + " ^^^^^^^^^^\n" + + "The method bar(int) from the type X can be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// Method of a local class -> can't be static, so no warning +// Also method with such a local class accessing a member of the outer class can't be static +public void test119() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public static int field1;\n" + + " public int field2;\n" + + " public void bar(int i) {\n" + // don't warn + " (new Object() {\n" + + " public boolean foo1() {\n" + // don't warn for foo1 + " return X.this.field2 == 1;\n" + + " }\n" + + " }).foo1();\n" + + " System.out.println(X.field1);\n" + + " }\n" + + " public void bar2(int i) {\n" + // warn + " (new Object() {\n" + + " public boolean foo1() {\n" + // don't warn for foo1 + " System.out.println(X.field1);\n" + + " return true;" + + " }\n" + + " }).foo1();\n" + + " System.out.println(X.field1);\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " public void bar2(int i) {\n" + + " ^^^^^^^^^^^\n" + + "The method bar2(int) from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// Method using type parameters declared by enclosing class can't be static, so don't warn +public void test120() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public static int field1;\n" + + " public int field2;\n" + + " public void bar(T t) {\n" + // don't warn + " X.field1 = 1;\n" + + " System.out.println(t);\n" + + " }\n" + + " public void bar2(E e) {\n" + // warn + " X.field1 = 1;\n" + + " System.out.println(e);\n" + + " }\n" + + " public void bar3() {\n" + // don't warn + " T a;\n" + + " System.out.println();\n" + + " }\n" + + " public void bar4() {\n" + // warn + " Y a;\n" + + " System.out.println();\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " public void bar2(E e) {\n" + + " ^^^^^^^^^\n" + + "The method bar2(E) from the type X can potentially be declared as static\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " public void bar4() {\n" + + " ^^^^^^\n" + + "The method bar4() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// Access to super in a method disqualifies it from being static +public void test121() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X extends A{\n" + + " public static int field1;\n" + + " public int field2;\n" + + " public void methodA() {\n" + // don't warn + " super.methodA();\n" + + " }\n" + + " public void bar() {\n" + // don't warn + " super.fieldA = 1;\n" + + " }\n" + + " public void bar2() {\n" + // don't warn + " System.out.println(super.fieldA);\n" + + " }\n" + + " public void bar3() {\n" + // warn + " System.out.println(X.fieldA);\n" + + " }\n" + + "}\n" + + "class A{\n" + + " public static int fieldA;\n" + + " public void methodA(){\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " public void bar3() {\n" + + " ^^^^^^\n" + + "The method bar3() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// Methods of non-static member types can't be static +public void test122() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " class A{\n" + + " void methodA() {\n" + // don't warn + " System.out.println();\n" + + " }\n" + + " }\n" + + " static class B{\n" + + " void methodB() {\n" + // warn + " System.out.println();\n" + + " }\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " void methodB() {\n" + + " ^^^^^^^^^\n" + + "The method methodB() from the type X.B can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=318682 +// If method returns type parameter not declared by it, it cannot be static +public void test123() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " T method1() {\n" + // don't warn + " return null;\n" + + " }\n" + + " E method2() {\n" + // warn + " return null;\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " E method2() {\n" + + " ^^^^^^^^^\n" + + "The method method2() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 +// If method allocates an inner non-static type without an enclosing object, method can't be static +public void testBug335845a() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private class Bar {\n" + + " int a = 1;\n" + + " }\n" + + " private void foo() {\n" + // don't warn + " new Bar();\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 +// If method allocates an inner non-static type without an enclosing object, method can't be static +public void testBug335845b() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private class Bar {\n" + + " int a = 1;\n" + + " }\n" + + " private void foo() {\n" + // don't warn + " int x = new Bar().a;\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 +// If method allocates an inner static type without an enclosing object, method can be static +public void testBug335845c() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " private static class Bar {\n" + + " int a = 1;\n" + + " }\n" + + " private void foo() {\n" + // warn since Bar is static + " new Bar();\n" + + " int x = new Bar().a;" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " private void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type X can be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 +// If method allocates an inner non-static type without an enclosing object, method can't be static +public void testBug335845d() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private class Bar {\n" + + " class Bar2{}\n" + + " }\n" + + " private void foo() {\n" + // don't warn + " new Bar().new Bar2();\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 +// If method allocates an inner static type without an enclosing object, method can be static +public void testBug335845e() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " private class Bar {\n" + + " int a = 1;\n" + + " }\n" + + " private void foo() {\n" + // warn since Bar is allocated via Test object + " new X().new Bar();\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " private void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type X can be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 +// If method allocates an inner static type without an enclosing object, method can be static +public void testBug335845f() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.customOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " private class Bar {\n" + + " int a = 1;\n" + + " }\n" + + " private void foo() {\n" + // warn since Bar is allocated via Test object + " X x = new X();" + + " x.new Bar().a = 2;\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " private void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type X can be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335845 +// If method allocates an inner static type without an enclosing object, method can be static +public void testBug335845g() { + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedObjectAllocation, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + compilerOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " class Bar {\n" + + " }\n" + + "}" + } + ); + this.runNegativeTest( + new String[] { + "p/Y.java", + "package p;\n" + + "public class Y extends X {\n" + + " private void foo() {\n" + // warn since Bar is allocated via Test object + " new Bar();\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + false /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780 +// For this reference as an argument of a message send, method can't be static +public void test124a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void method1() {\n" + // don't warn + " Foo.m(this);\n" + + " }\n" + + "static class Foo{\n" + + " static void m(X bug) {\n" + + " \n" + + " }\n" + + "}\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335780 +// For this reference as an argument of a message send, method can't be static +public void test124b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static X xField;" + + " public void method1() {\n" + // don't warn + " Foo.m(this.xField);\n" + + " }\n" + + "static class Foo{\n" + + " static void m(X bug) {\n" + + " \n" + + " }\n" + + "}\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Foo.m(this.xField);\n" + + " ^^^^^^\n" + + "The static field X.xField should be accessed in a static way\n" + + "----------\n", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=354502 +// Anonymous class instantiation of a non-static member type, method can't be static +public void test354502() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + + new String[] { + "X.java", + "public class X {\n" + + " public abstract class Abstract{}\n" + + " public static abstract class Abstract2{}\n" + + " private void method1() {\n" + // don't warn + " new Abstract() {};\n" + + " }\n" + + " private void method2() {\n" + // warn + " new Abstract2() {};\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " private void method2() {\n" + + " ^^^^^^^^^\n" + + "The method method2() from the type X can be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=360164 +public void test360164() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + this.runConformTest( + new String[] { + "p/B.java", + "package p;\n" + + "\n" + + "public abstract class B {\n" + + " protected abstract V foo(K element);\n" + + "}\n", + "p/C.java", + "package p;\n" + + "public class C {\n" + + "}\n", + "p/D.java", + "package p;\n" + + "public class D extends E {\n" + + "}\n", + "p/E.java", + "package p;\n" + + "public abstract class E implements I {\n" + + "}\n", + "p/I.java", + "package p;\n" + + "public interface I {\n" + + "}\n", + "p/X.java", + "package p;\n" + + "public class X {\n" + + " private final class A extends B{\n" + + " @Override\n" + + " protected D foo(C c) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + + // delete binary file I (i.e. simulate removing it from classpath for subsequent compile) + Util.delete(new File(OUTPUT_DIR, "p" + File.separator + "I.class")); + + runNegativeTest( + // test directory preparation + false /* do not flush output directory */, + new String[] { /* test files */ + "p/X.java", + "package p;\n" + + "public class X {\n" + + " private final class A extends B{\n" + + " @Override\n" + + " protected D foo(C c) {\n" + + " Zork z;\n" + + " return null;\n" + + " }\n" + + " }\n" + + "}\n", + }, + // compiler options + null /* no class libraries */, + null /* no custom options */, + // compiler results + "----------\n" + + "1. WARNING in p\\X.java (at line 3)\n" + + " private final class A extends B{\n" + + " ^\n" + + "The type X.A is never used locally\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 6)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n", + // javac options + JavacTestOptions.SKIP_UNTIL_FRAMEWORK_FIX /* javac test options */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// SingleNameReference, assignment of instance field inside a local class method +public void test376550_1a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int i = 1;\n" + + " public void upper1(){}\n" + + " public void foo(){\n" + // can't be static + " class Local{\n" + + " int i2 = 1;\n" + + " void method1() {\n" + // can't be static + " i = 1;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// SingleNameReference, assignment of instance field of local class inside a local class method +public void test376550_1b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + new Runner() {{ + this.customOptions = getCompilerOptions(); + this.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + this.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + this.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " int i = 1;\n" + + " public void upper1(){}\n" + + " public void foo(){\n" + // can be static + " class Local{\n" + + " int i2 = 1;\n" + + " void method2() {\n" + // can't be static + " i2 = 1;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }; + this.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + this.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + }}.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// LocalDeclaration with type as a type variable binding +public void test376550_2a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public void upper1(){}\n" + + " public void foo(){\n" + // can be static + " class Local{\n" + + " void method2() {\n" + // can't be static + " K k;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// LocalDeclaration with type as a type variable binding +public void test376550_2b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void upper1(){}\n" + + " public void foo(){\n" + // can't be static + " class Local{\n" + + " void method2() {\n" + // can't be static + " T t;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// MessageSend, calling outer class method inside a local class method +public void test376550_3a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void upper1(){}\n" + + " public void foo(){\n" + // can't be static + " class Local{\n" + + " void lower() {}\n" + + " void method2() {\n" + // can't be static + " upper1();\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// MessageSend, calling local class method inside a local class method +public void test376550_3b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " public void upper1(){}\n" + + " public void foo(){\n" + // can be static + " class Local{\n" + + " void lower() {}\n" + + " void method2() {\n" + // can't be static + " lower();\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// Local class instance field is an argument in messageSend in local class method +public void test376550_4a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " int i1 = 1;\n" + + " public void foo(){\n" + // can be static + " class Local{\n" + + " int i2 = 1;\n" + + " void lower(int i) {}\n" + + " void method2() {\n" + // can't be static + " lower(i2);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// Outerclass instance field is an argument in messageSend in local class method +public void test376550_4b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int i1 = 1;\n" + + " public void foo(){\n" + // can't be static + " class Local{\n" + + " int i2 = 1;\n" + + " void lower(int i) {}\n" + + " void method2() {\n" + // can't be static + " lower(i1);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// QualifiedNameReference, accessing local class instance field +public void test376550_5a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " int i1 = 1;\n" + + " public void foo(){\n" + // can be static + " class Local{\n" + + " int i2 = 1;\n" + + " void method2() {\n" + // can't be static + " Local.this.i2 = 1;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// https://bugs.eclispe.org/379784 - [compiler] "Method can be static" is not getting reported +// Variation of the above +public void test376550_5aa() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " int i1 = 1;\n" + + " public void foo(){\n" + + " class Local{\n" + + " int i2 = 1;\n" + + " }\n" + + " class Local2 extends Local {\n" + + " void method2() {\n" + + " Local2.this.i2 = 1;\n" + // required instance is of type Local (super of Local2) + " }\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// QualifiedNameReference, accessing outer class instance field +public void test376550_5b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int i1 = 1;\n" + + " public void foo(){\n" + // can't be static + " class Local{\n" + + " int i2 = 1;\n" + + " void method2() {\n" + // can't be static + " X.this.i1 = 1;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// QualifiedNameRef.analyseCode() +public void test376550_6a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " int i1 = 1;\n" + + " public void foo(){\n" + // can be static + " class Local{\n" + + " int i2 = 1;\n" + + " boolean method2() {\n" + // can't be static + " return Local.this.i2 == 1;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// QualifiedNameRef.analyseCode() +public void test376550_6b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int i1 = 1;\n" + + " public void foo(){\n" + // can't be static + " class Local{\n" + + " int i2 = 1;\n" + + " boolean method2() {\n" + // can't be static + " return X.this.i1 == 1;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// QualifiedAllocationExpression, allocating an anonymous type without an enclosing instance of parent type +// anon. type is declared in local class +public void test376550_7a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " abstract class AbsUp{}\n" + + " public void foo(){\n" + // can be static + " class Local{\n" + + " abstract class AbsLow{}\n" + + " void method2() {\n" + // can't be static + " new AbsLow(){};\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// QualifiedAllocationExpression, allocating an anonymous type without an enclosing instance of parent type +// anon. type is declared in outer class +public void test376550_7b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " abstract class AbsUp{}\n" + + " public void foo(){\n" + // can't be static + " class Local{\n" + + " abstract class AbsLow{}\n" + + " void method2() {\n" + // can't be static + " new AbsUp(){};\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// FieldRef, from object of a class in outer class +public void test376550_8a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " class AbsUp{ int a;}\n" + + " public void foo(){\n" + // can be static + " class Local{\n" + + " class AbsLow{ int a;}\n" + + " void method2() {\n" + // can't be static + " int abc = new AbsLow().a;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +//FieldRef, from object of a class in local class +public void test376550_8b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class AbsUp{ int a;}\n" + + " public void foo(){\n" + // can't be static + " class Local{\n" + + " class AbsLow{ int a;}\n" + + " void method2() {\n" + // can't be static + " int abc = new AbsUp().a;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// QualifiedNameRef, accessing a field from local class field +public void test376550_9a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " X xup;\n" + + " int i = 1;\n" + + " public void foo(){\n" + // can be static + " class Local{\n" + + " X xdown;\n" + + " class AbsLow{ int a;}\n" + + " void method2() {\n" + // can't be static + " int abc = xdown.i;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// QualifiedNameRef, accessing a field from local class field +public void test376550_9b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X xup;\n" + + " int i = 1;\n" + + " public void foo(){\n" + // can't be static + " class Local{\n" + + " X xdown;\n" + + " class AbsLow{ int a;}\n" + + " void method2() {\n" + // can't be static + " int abc = xup.i;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// QualifiedNameRef, accessing a field from local class field +public void test376550_10a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " X xup;\n" + + " int i = 1;\n" + + " public void foo(){\n" + // can be static + " class Local{\n" + + " X xdown;\n" + + " void calc(int i1){}\n" + + " void method2() {\n" + // can't be static + " calc(xdown.i);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public void foo(){\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// QualifiedNameRef, accessing a field from local class field +public void test376550_10b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X xup;\n" + + " int i = 1;\n" + + " public void foo(){\n" + // can't be static + " class Local{\n" + + " X xdown;\n" + + " void calc(int i1){}\n" + + " void method2() {\n" + // can't be static + " calc(xup.i);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + compilerOptions /* custom options */ + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// bug test case +public void test376550_11() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "public class X {\n" + + " private Object o = new Object();\n" + + " public final Collection go() {\n" + // can't be static + " return new ArrayList() {\n" + + " { add(o);}\n" + + " };\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = isMinimumCompliant(ClassFileConstants.JDK11) ? + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " return new ArrayList() {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The serializable class does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + : + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " return new ArrayList() {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The serializable class does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. WARNING in X.java (at line 7)\n" + + " { add(o);}\n" + + " ^\n" + + "Read access to enclosing field X.o is emulated by a synthetic accessor method\n" + + "----------\n"; + runner.runWarningTest(); +} + +// https://bugs.eclipse.org/376550 +// https://bugs.eclipse.org/379784 - [compiler] "Method can be static" is not getting reported +// bug test case +public void test376550_11a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "public class X {\n" + + " private Object o = new Object();\n" + + " public final Collection go() {\n" +// can be static + " return new ArrayList() {\n" + + " { add(null);}\n" + // required instance is of type ArrayList, not X + " };\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public final Collection go() {\n" + + " ^^^^\n" + + "The method go() from the type X can be declared as static\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " return new ArrayList() {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The serializable class does not declare a static final serialVersionUID field of type long\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +public void test376550_12() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runner.testFiles = + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Collection;\n" + + "public class X {\n" + + " private Object o = new Object();\n" + + " public final Collection go() {\n" + // CAN be static + " return new ArrayList() {\n" + + " { E1 e;}\n" + + " };\n" + + " }\n" + + "}" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public final Collection go() {\n" + + " ^^^^\n" + + "The method go() from the type X can be declared as static\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " return new ArrayList() {\n" + + " ^^^^^^^^^^^^^^^\n" + + "The serializable class does not declare a static final serialVersionUID field of type long\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=376550 +// https://bugs.eclipse.org/379834 - Wrong "method can be static" in presence of qualified super and different staticness of nested super class. +public void test376550_13() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "QualifiedSuper.java", + "public class QualifiedSuper {\n" + + " class InnerS {\n" + + " void flub() {}\n" + + " }\n" + + " static class InnerT extends InnerS {\n" + + " InnerT(QualifiedSuper qs) {\n" + + " qs.super();\n" + + " }\n" + + " final void schlumpf() {\n" + + " InnerT.super.flub();\n" + + " }\n" + + " } \n" + + "}\n" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null, + compilerOptions /* custom options */, + null + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=379530 +public void test379530() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " S s;\n" + + " {\n" + + " S /*[*/s/*]*/;\n" + + " s= X.this.s;" + + " }\n" + + "}" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null, + compilerOptions /* custom options */, + null + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=393781 +public void test393781() { + Map compilerOptions = getCompilerOptions(); // OPTION_ReportRawTypeReference + Object oldOption = compilerOptions.get(CompilerOptions.OPTION_ReportRawTypeReference); + compilerOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + try { + this.runNegativeTest( + new String[] { + "p/X.java", + "public class X {\n" + + " public void foo(Map map, String str) {}\n" + + " public void foo1() {}\n" + + " public void bar(java.util.Map map) {\n" + + " foo(map, \"\");\n" + + " foo(map);\n" + + " foo();\n" + + " foo1(map, \"\");\n" + + " }\n" + + "}\n" + + "class Map {}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " foo(map, \"\");\n" + + " ^^^\n" + + "The method foo(Map, java.lang.String) in the type X is not applicable for the arguments (java.util.Map, java.lang.String)\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 6)\n" + + " foo(map);\n" + + " ^^^\n" + + "The method foo(Map, String) in the type X is not applicable for the arguments (Map)\n" + + "----------\n" + + "3. ERROR in p\\X.java (at line 7)\n" + + " foo();\n" + + " ^^^\n" + + "The method foo(Map, String) in the type X is not applicable for the arguments ()\n" + + "----------\n" + + "4. ERROR in p\\X.java (at line 8)\n" + + " foo1(map, \"\");\n" + + " ^^^^\n" + + "The method foo1() in the type X is not applicable for the arguments (Map, String)\n" + + "----------\n", + null, + true, + compilerOptions /* default options */ + ); + } finally { + compilerOptions.put(CompilerOptions.OPTION_ReportRawTypeReference, oldOption); + } +} +private void runStaticWarningConformTest(String fileName, String body) { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + fileName, + body + }, + compilerOptions /* custom options */ + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +//Can be static warning shown in the wrong places, i.e. if the type parameter is used in the signature +public void test378674_comment0() { + runStaticWarningConformTest( + "Test.java", + "public class Test {\n" + + "\n" + + " @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n" + + " public static void main(String[] args) {\n" + + " new Test().method(null);\n" + + " }\n" + + "\n" + + " private static class SubClass {\n" + + "\n" + + " }\n" + + "\n" + + " private void method(SubClass s) {\n" + + " System.out.println(s);\n" + + " }\n" + + "\n" + + "}\n" + + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +public void test378674_comment1b() { + runStaticWarningConformTest( + "X.java", + "import java.util.Collection;\n" + + "class X{\n" + + " public final Collection go() { // cannot be static\n" + + " return null; \n" + + " }\n" + + "}\n" + + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +//Can be static warning shown in the wrong places +public void test378674_comment1c() { + runStaticWarningConformTest( + "X.java", + "import java.util.Collection;\n" + + "import java.util.ArrayList;\n" + + " class X{\n" + + " public final Collection go() { // cannot be static\n" + + " return new ArrayList(); \n" + + " }\n" + + "}\n" + + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +//Can be static warning shown in the wrong places +public void test378674_comment2() { + runStaticWarningConformTest( + "X.java", + "public class X {\n" + + " public final void foo() {\n" + + " java.util.List k;\n" + + " }\n" + + "}\n" + + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +public void test378674_comment3() { + runStaticWarningConformTest( + "Test.java", + "public class Test {\n" + + " //false positive of method can be declared static\n" + + " void bar() {\n" + + " foo(Test.this);\n" + + " }\n" + + "\n" + + " private static void foo(Test test) {\n" + + " System.out.println(test.getClass().getName());\n" + + " }\n" + + "}\n" + + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +//Can be static warning shown in the wrong places +public void test378674_comment5a() { + runStaticWarningConformTest( + "Test.java", + "public class Test {\n" + + "\n" + + " @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n" + + " public static void main(String[] args) {\n" + + " new Test().method2(null);\n" + + " }\n" + + "\n" + + " private static class SubClass {\n" + + "\n" + + " }\n" + + "\n" + + " private void method2(SubClass> s) {\n" + + " System.out.println(s);\n" + + " }\n" + + "\n" + + "}\n" + + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +public void test378674_comment5b() { + runStaticWarningConformTest( + "Test.java", + "public class Test {\n" + + "\n" + + " @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n" + + " public static void main(String[] args) {\n" + + " new Test().method();\n" + + " }\n" + + "\n" + + " private java.util.Collection method() {\n" + + " return null;\n" + + " }\n" + + "\n" + + "}\n" + + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +public void test378674_comment9() { + runStaticWarningConformTest( + "Test.java", + "public class Test {\n" + + "\n" + + " @SuppressWarnings({ \"rawtypes\" })\n" + + " public static void main(String[] args) {\n" + + " new Test().method();\n" + + " }\n" + + "\n" + + " private java.util.Collection method() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +public void test378674_comment11() { + runStaticWarningConformTest( + "Test.java", + "public class Test {\n" + + "\n" + + " @SuppressWarnings({ \"rawtypes\" })\n" + + " public static void main(String[] args) {\n" + + " new Test().method1();\n" + + " new Test().method2();\n" + + " }\n" + + "\n" + + " private TT method1() { \n" + + " return null;\n" + + " }\n" + + "\n" + + " private > TT method2() { \n" + + " return null;\n" + + " }\n" + + "}\n" + + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +public void test378674_comment21a() { + runStaticWarningConformTest( + "X.java", + "public class X

    {\n" + + " final void foo(T x) throws P {\n" + + " }\n" + + "}\n" + + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +public void test378674_comment21b() { + runStaticWarningConformTest( + "X.java", + "public class X

    {\n" + + " final void foo(T x) {\n" + + " Object o = (P) null;\n" + + " }\n" + + "}\n" + ); +}//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +public void test378674_comment21c() { + runStaticWarningConformTest( + "X.java", + "public class X

    {\n" + + " final void foo(T x) {\n" + + " new Outer().new Inner

    ();\n" + + " }\n" + + "}\n" + + "class Outer {\n" + + " class Inner {}\n" + + "}\n" + ); +}//https://bugs.eclipse.org/bugs/show_bug.cgi?id=378674 +public void test378674_comment21d() { + runStaticWarningConformTest( + "X.java", + "public class X

    {\n" + + " final void foo(T x) {\n" + + " class Local {\n" + + " P p;\n" + + " }\n" + + " }\n" + + "}\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406396, Method can be static analysis misses a bunch of cases... +public void test406396() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " int f;\n" + + " void foo() {\n" + + " class Y {\n" + + " int p;\n" + + " {\n" + + " class Z {\n" + + " int f = p;\n" + + " }\n" + + " }\n" + + " };\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " class Y {\n" + + " ^\n" + + "The type Y is never used locally\n" + + "----------\n" + + "3. WARNING in X.java (at line 7)\n" + + " class Z {\n" + + " ^\n" + + "The type Z is never used locally\n" + + "----------\n" + + "4. WARNING in X.java (at line 8)\n" + + " int f = p;\n" + + " ^\n" + + "The field Z.f is hiding a field from type X\n" + + "----------\n" + + "5. WARNING in X.java (at line 8)\n" + + " int f = p;\n" + + " ^\n" + + "The value of the field Z.f is not used\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406396, Method can be static analysis misses a bunch of cases... +public void test406396a() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR); + runner.customOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR); + runner.testFiles = + new String[] { + "X.java", + "public class X {\n" + + " int f;\n" + + " int foo() {\n" + + " int f = 0;\n" + + " return f;\n" + + " }\n" + + " int goo() {\n" + + " return 0;\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " int foo() {\n" + + " ^^^^^\n" + + "The method foo() from the type X can potentially be declared as static\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " int f = 0;\n" + + " ^\n" + + "The local variable f is hiding a field from type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " int goo() {\n" + + " ^^^^^\n" + + "The method goo() from the type X can potentially be declared as static\n" + + "----------\n"; + runner.javacTestOptions = + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError; + runner.runNegativeTest(); +} +public void testBug542829() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + + // m.Issing is a type that comes and goes: + String nameMissing = "m/Issing.java"; + String contentMissing = + "package m;\n" + + "public class Issing {\n" + + " g.Ood getGood() { return new g.Ood(); }\n" + + "}\n"; + + Runner runner = new Runner(); + runner.generateOutput = true; + runner.testFiles = new String[] { + "g/Ood.java", + "package g;\n" + + "public class Ood {\n" + + " @Override public String toString() {\n" + + " return \"good\";\n" + + " }\n" + + "}\n", + "g/Ontainer.java", + "package g;\n" + + "import java.util.*;\n" + + "import m.Issing;\n" + + "public class Ontainer {\n" + + " public List getElements() { return new ArrayList<>(); }\n" + // <= reference to m.Issing here (OK) + "}\n", + nameMissing, + contentMissing + }; + runner.expectedCompilerLog = null; + runner.runConformTest(); + + // now we break it: + Util.delete(new File(OUTPUT_DIR + File.separator + "m" + File.separator + "Issing.class")); + runner.shouldFlushOutputDirectory = false; + + // in this class file a MissingTypes attribute ("m/Issing") is generated: + runner.testFiles = new String[] { + "b/Roken.java", + "package b;\n" + + "import g.Ood;" + + "public class Roken {\n" + + " Ood getGood(m.Issing provider) {\n" + // <= argument type is missing (we still have the qualified name, though) + " return provider.getGood();\n" + + " }\n\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in b\\Roken.java (at line 3)\n" + + " Ood getGood(m.Issing provider) {\n" + + " ^^^^^^^^\n" + + "m.Issing cannot be resolved to a type\n" + + "----------\n"; + runner.runNegativeTest(); + + runner.javacTestOptions = JavacTestOptions.SKIP; // javac did not produce b/Roken.class which is needed below + + // restore the class as binary: + runner.testFiles = new String[] { + nameMissing, + contentMissing + }; + runner.expectedCompilerLog = null; + runner.runConformTest(); + + // next compilation has two references to m.Issing: + runner.testFiles = new String[] { + "t/Rigger.java", + "package t;\n" + + "import b.Roken;\n" + // <= Here we pull in the MissingTypes("m/Issing") attribute into an UnresolvedReferenceBinding + "public class Rigger {}\n", + "t/Est.java", + "package t;\n" + + "public class Est {\n" + + " void foo(g.Ontainer container) {\n" + + " for (m.Issing miss: container.getElements()) {\n" + // <= Here we resolve a qualified name from g/Ontainer.class but don't trust it! + " System.out.print(miss);\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java new file mode 100644 index 0000000000..8ce7a0ddf2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java @@ -0,0 +1,3325 @@ +/******************************************************************************* + * Copyright (c) 2001, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 185682 - Increment/decrement operators mark local variables as read + * bug 328281 - visibility leaks not detected when analyzing unused field in private class + * Bug 410218 - Optional warning for arguments of "unexpected" types to Map#get(Object), Collection#remove(Object) et al. + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.ICompilerRequestor; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +/* Collects potential programming problems tests that are not segregated in a + * dedicated test class (aka NullReferenceTest). */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class ProgrammingProblemsTest extends AbstractRegressionTest { + +public ProgrammingProblemsTest(String name) { + super(name); +} + + // Static initializer to specify tests subset using TESTS_* static variables + // All specified tests which does not belong to the class are skipped... + // 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[] { "test0055" }; +// TESTS_NUMBERS = new int[] { 56 }; +// TESTS_RANGE = new int[] { 1, -1 }; + } + +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public static Class testClass() { + return ProgrammingProblemsTest.class; +} +@Override +protected Map getCompilerOptions() { + Map compilerOptions = super.getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + return compilerOptions; +} +void runTest( + String[] testFiles, + String[] errorOptions, + String[] warningOptions, + String[] ignoreOptions, + boolean expectingCompilerErrors, + String expectedCompilerLog, + String expectedOutputString, + boolean forceExecution, + String[] classLib, + boolean shouldFlushOutputDirectory, + String[] vmArguments, + Map customOptions, + ICompilerRequestor clientRequestor, + boolean skipJavac) { + Map compilerOptions = customOptions; + if (errorOptions != null || warningOptions != null || + ignoreOptions != null) { + if (compilerOptions == null) { + compilerOptions = new HashMap(); + } + if (errorOptions != null) { + for (int i = 0; i < errorOptions.length; i++) { + compilerOptions.put(errorOptions[i], CompilerOptions.ERROR); + } + } + if (warningOptions != null) { + for (int i = 0; i < warningOptions.length; i++) { + compilerOptions.put(warningOptions[i], CompilerOptions.WARNING); + } + } + if (ignoreOptions != null) { + for (int i = 0; i < ignoreOptions.length; i++) { + compilerOptions.put(ignoreOptions[i], CompilerOptions.IGNORE); + } + } + } + runTest(testFiles, + expectingCompilerErrors, + expectedCompilerLog, + expectedOutputString, + "" /* expectedErrorString */, + forceExecution, + classLib, + shouldFlushOutputDirectory, + vmArguments, + compilerOptions, + clientRequestor, + skipJavac); +} + +// default behavior upon unread parameters +public void test0001_unread_parameters() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(boolean b) {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + null /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + false /* skipJavac */); +} + +// reporting unread paramaters as warning +public void test0002_unread_parameters() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(boolean b) {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedParameter + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public void foo(boolean b) {\n" + + " ^\n" + + "The value of the parameter b is not used\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + +// disabling the reporting of unread parameters using the Javadoc +// @param disables by default +public void test0003_unread_parameters() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + "/** @param b mute warning **/\n" + + " public void foo(boolean b) {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedParameter + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} + +// disabling the reporting of unread parameters using the Javadoc +// @param disabling can be disabled +public void test0004_unread_parameters() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + "/** @param b mute warning **/\n" + + " public void foo(boolean b) {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedParameter + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void foo(boolean b) {\n" + + " ^\n" + + "The value of the parameter b is not used\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} + +// disabling the reporting of unread parameters using SuppressWarnings +public void test0005_unread_parameters() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runTest( + new String[] { + "X.java", + "public class X {\n" + + "@SuppressWarnings(\"unused\")\n" + // most specific token + " public void foo(boolean b) {\n" + + " }\n" + + "@SuppressWarnings(\"all\")\n" + // least specific token + " public void foo(int i) {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedParameter + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); + } +} + +// reporting unread paramaters as error +public void test0006_unread_parameters() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(boolean b) {\n" + + " }\n" + + "}\n" + }, + new String[] { + CompilerOptions.OPTION_ReportUnusedParameter + } /* errorOptions */, + null /* warningOptions */, + null /* ignoreOptions */, + true /* expectingCompilerErrors */, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(boolean b) {\n" + + " ^\n" + + "The value of the parameter b is not used\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + +// default behavior upon unnecessary declaration of thrown checked exceptions +public void test0007_declared_thrown_checked_exceptions() { + runTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public void foo() throws IOException {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + null /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + false /* skipJavac */); +} + +// reporting unnecessary declaration of thrown checked exceptions as warning +public void test0008_declared_thrown_checked_exceptions() { + runTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public void foo() throws IOException {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void foo() throws IOException {\n" + + " ^^^^^^^^^^^\n" + + "The declared exception IOException is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + +// disabling the reporting of unnecessary declaration of thrown checked +// exceptions using the Javadoc +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=73244 +// @throws disables by default +public void test0009_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + runTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + "/** @throws IOException mute warning **/\n" + + " public void foo() throws IOException {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} + +// disabling the reporting of unnecessary declaration of thrown checked +// exceptions using the Javadoc +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=73244 +// @throws disabling can be disabled +public void test0010_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionIncludeDocCommentReference, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + "/** @throws IOException mute warning **/\n" + + " public void foo() throws IOException {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public void foo() throws IOException {\n" + + " ^^^^^^^^^^^\n" + + "The declared exception IOException is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} + +// disabling the reporting of unnecessary declaration of thrown checked +// exceptions using SuppressWarnings +public void test0011_declared_thrown_checked_exceptions() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + runTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + "@SuppressWarnings(\"all\")\n" + // no specific token + " public void foo() throws IOException {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); + } +} + +// reporting unnecessary declaration of thrown checked exceptions as error +public void test0012_declared_thrown_checked_exceptions() { + runTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public void foo() throws IOException {\n" + + " }\n" + + "}\n" + }, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* errorOptions */, + null /* warningOptions */, + null /* ignoreOptions */, + true /* expectingCompilerErrors */, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " public void foo() throws IOException {\n" + + " ^^^^^^^^^^^\n" + + "The declared exception IOException is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + +// disabling the reporting of unnecessary declaration of thrown checked +// exceptions using the Javadoc +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=73244 +// @throws disables by default, but only exact matches work +public void test0013_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + runTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.io.EOFException;\n" + + "public class X {\n" + + "/** @throws EOFException does not mute warning for IOException **/\n" + + " public void foo() throws IOException {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public void foo() throws IOException {\n" + + " ^^^^^^^^^^^\n" + + "The declared exception IOException is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// interaction between errors and warnings +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203721 +public void test0014_declared_thrown_checked_exceptions_unread_parameters() { + runTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo(int unused) throws IOException {}\n" + + "}\n" + }, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedParameter + } /* warningOptions */, + null /* ignoreOptions */, + true /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo(int unused) throws IOException {}\n" + + " ^^^^^^\n" + + "The value of the parameter unused is not used\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " void foo(int unused) throws IOException {}\n" + + " ^^^^^^^^^^^\n" + + "The declared exception IOException is not actually thrown by the method foo(int) from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} +// interaction between errors and warnings +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=203721 +// variant: both warnings show up +public void test0015_declared_thrown_checked_exceptions_unread_parameters() { + runTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo(int unused) throws IOException {}\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException, + CompilerOptions.OPTION_ReportUnusedParameter + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " void foo(int unused) throws IOException {}\n" + + " ^^^^^^\n" + + "The value of the parameter unused is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " void foo(int unused) throws IOException {}\n" + + " ^^^^^^^^^^^\n" + + "The declared exception IOException is not actually thrown by the method foo(int) from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + +// reporting unread paramaters as error on a constructor +public void test0016_unread_parameters_constructor() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public X(boolean b) {\n" + + " }\n" + + "}\n" + }, + new String[] { + CompilerOptions.OPTION_ReportUnusedParameter + } /* errorOptions */, + null /* warningOptions */, + null /* ignoreOptions */, + true /* expectingCompilerErrors */, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public X(boolean b) {\n" + + " ^\n" + + "The value of the parameter b is not used\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=208001 +public void test0017_shadowing_package_visible_methods() { + runTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " void foo() {\n" + + " }\n" + + "}\n", + "q/Y.java", + "package q;\n" + + "public class Y extends p.X {\n" + + " void foo() {\n" + + " }\n" + + "}\n", + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportOverridingPackageDefaultMethod + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in q\\Y.java (at line 3)\n" + + " void foo() {\n" + + " ^^^^^\n" + + "The method Y.foo() does not override the inherited method from X since it is private to a different package\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + new ICompilerRequestor() { + public void acceptResult(CompilationResult result) { + if (result.compilationUnit.getFileName()[0] == 'Y') { + assertEquals("unexpected problems count", 1, result.problemCount); + assertEquals("unexpected category", CategorizedProblem.CAT_NAME_SHADOWING_CONFLICT, result.problems[0].getCategoryID()); + } + } + } /* clientRequestor */, + true /* skipJavac */); +} +// default behavior upon unnecessary declaration of thrown unchecked exceptions +public void test0018_declared_thrown_unchecked_exceptions() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws ArithmeticException {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + null /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} +// default behavior upon unnecessary declaration of thrown unchecked exceptions +public void test0019_declared_thrown_unchecked_exceptions() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws RuntimeException {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + null /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} +// default behavior upon unnecessary declaration of Exception +public void test0020_declared_thrown_checked_exceptions() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws Exception {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + null /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} +// default behavior upon unnecessary declaration of Throwable +public void test0021_declared_thrown_checked_exceptions() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws Throwable {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + null /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// reporting unnecessary declaration of thrown unchecked exceptions as warning +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// suppressed the warning +public void test0022_declared_thrown_unchecked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws ArithmeticException {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// reporting unnecessary declaration of thrown unchecked exceptions as warning +// the external API uses another string literal - had it wrong in first attempt +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// suppressed the warning for unchecked exceptions, using Exception instead +public void test0023_declared_thrown_unchecked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(JavaCore.COMPILER_PB_UNUSED_DECLARED_THROWN_EXCEPTION_EXEMPT_EXCEPTION_AND_THROWABLE, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws Exception {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public void foo() throws Exception {\n" + + " ^^^^^^^^^\n" + + "The declared exception Exception is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// reporting unnecessary declaration of thrown unchecked exceptions as warning +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// suppressed the warning +public void test0024_declared_thrown_unchecked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws RuntimeException {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// reporting unnecessary declaration of thrown unchecked exceptions as warning +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// focused on Exception and Throwable, which are not unchecked but can catch +// unchecked exceptions +public void test0025_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws Exception {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public void foo() throws Exception {\n" + + " ^^^^^^^^^\n" + + "The declared exception Exception is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// reporting unnecessary declaration of thrown unchecked exceptions as warning +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// focused on Exception and Throwable, which are not unchecked but can catch +// unchecked exceptions +public void test0026_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws Throwable {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " public void foo() throws Throwable {\n" + + " ^^^^^^^^^\n" + + "The declared exception Throwable is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// disabling the reporting of unnecessary declaration of thrown unchecked +// exceptions using the Javadoc +// @throws disables by default +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// suppressed the warning for unchecked exceptions, using Exception instead +public void test0027_declared_thrown_unchecked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + "/** @throws Exception mute warning **/\n" + + " public void foo() throws Exception {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// disabling the reporting of unnecessary declaration of thrown unchecked +// exceptions using the Javadoc +// @throws disabling can be disabled +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// suppressed the warning for unchecked exceptions, using Exception instead +public void test0028_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionIncludeDocCommentReference, + CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + "/** @throws Exception mute warning **/\n" + + " public void foo() throws Exception {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void foo() throws Exception {\n" + + " ^^^^^^^^^\n" + + "The declared exception Exception is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// disabling the reporting of unnecessary declaration of thrown unchecked +// exceptions using SuppressWarnings +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// suppressed the warning for unchecked exceptions, using Exception instead +public void test0029_declared_thrown_checked_exceptions() { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + "@SuppressWarnings(\"all\")\n" + // no specific token + " public void foo() throws Exception {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// reporting unnecessary declaration of thrown unchecked exceptions as error +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// suppressed the error for unchecked exceptions, using Exception instead +public void test0030_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws Exception {\n" + + " }\n" + + "}\n" + }, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* errorOptions */, + null /* warningOptions */, + null /* ignoreOptions */, + true /* expectingCompilerErrors */, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo() throws Exception {\n" + + " ^^^^^^^^^\n" + + "The declared exception Exception is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// disabling the reporting of unnecessary declaration of thrown unchecked +// exceptions using the Javadoc +// @throws disables by default, but only exact matches work +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// suppressed the warning for unchecked exceptions, using Exception instead +public void test0031_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + "/** @throws Throwable does not mute warning for Exception **/\n" + + " public void foo() throws Exception {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public void foo() throws Exception {\n" + + " ^^^^^^^^^\n" + + "The declared exception Exception is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// reporting unnecessary declaration of thrown unchecked exceptions as warning +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// suppressed the warning for unchecked exceptions +public void test0032_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws Error {\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=100278 +// reporting unnecessary declaration of thrown unchecked exceptions as warning +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +// suppressed the warning for unchecked exceptions, using Exception instead +public void test0033_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() throws Exception {\n" + + " if (bar()) {\n" + + " throw new Exception();\n" + + " }\n" + + " }\n" + + " boolean bar() {\n" + + " return true;\n" + + " }\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=216897 +// reporting unnecessary declaration of thrown unchecked exceptions as warning +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +public void test0034_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final class MyError extends Error {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " public void foo() throws Throwable {\n" + + " try {\n" + + " bar();\n" + + " } catch (MyError e) {\n" + + " }\n" + + " }\n" + + " private void bar() {}\n" + + "}" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public void foo() throws Throwable {\n" + + " ^^^^^^^^^\n" + + "The declared exception Throwable is not actually thrown by the method foo() from type X\n" + + "----------\n" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +public void test0035_declared_thrown_checked_exceptions() { + Map customOptions = new HashMap(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + CompilerOptions.DISABLED); + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final class MyError extends Error {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " public void foo() throws Throwable {\n" + + " throw new MyError();\n" + + " }\n" + + "}" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + customOptions, + null /* clientRequestor */, + true /* skipJavac */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=219461 +public void test0036_declared_thrown_checked_exceptions() { + runTest( + new String[] { + "X.java", + "public class X {\n" + + " public static class E1 extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " public static class E2 extends E1 {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + " public void foo() throws E1 {\n" + + " throw new E2();\n" + + " }\n" + + "}" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedDeclaredThrownException + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115814 +public void test0037() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean b1 = args == args;\n" + + " boolean b2 = args != args;\n" + + " boolean b3 = b1 == b1;\n" + + " boolean b4 = b1 != b1;\n" + + " boolean b5 = b1 && b1;\n" + + " boolean b6 = b1 || b1;\n" + + " \n" + + " boolean b7 = foo() == foo();\n" + + " boolean b8 = foo() != foo();\n" + + " boolean b9 = foo() && foo();\n" + + " boolean b10 = foo() || foo();\n" + + " }\n" + + " static boolean foo() { return true; }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " boolean b1 = args == args;\n" + + " ^^^^^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " boolean b2 = args != args;\n" + + " ^^^^^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " boolean b3 = b1 == b1;\n" + + " ^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " boolean b4 = b1 != b1;\n" + + " ^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "5. WARNING in X.java (at line 7)\n" + + " boolean b5 = b1 && b1;\n" + + " ^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "6. WARNING in X.java (at line 8)\n" + + " boolean b6 = b1 || b1;\n" + + " ^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "7. ERROR in X.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +/** + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=276740" + */ +public void test0038() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean b1 = 1 == 1;\n" + + " boolean b2 = 1 != 1;\n" + + " boolean b3 = 1 == 1.0;\n" + + " boolean b4 = 1 != 1.0;\n" + + " boolean b5 = 1 == 2;\n" + + " boolean b6 = 1 != 2;\n" + + " boolean b7 = 1 == 2.0;\n" + + " boolean b8 = 1 != 2.0;\n" + + " final short s1 = 1;\n" + + " final short s2 = 2;\n" + + " boolean b9 = 1 == s1;\n" + + " boolean b10 = 1 == s2;\n" + + " boolean b91 = 1 != s1;\n" + + " boolean b101 = 1 != s2;\n" + + " final long l1 = 1;\n" + + " final long l2 = 2;\n" + + " boolean b11 = 1 == l1;\n" + + " boolean b12 = 1 == l2;\n" + + " boolean b111 = 1 != l1;\n" + + " boolean b121 = 1 != l2;\n" + + " boolean b13 = s1 == l1;\n" + + " boolean b14 = s1 == l2;\n" + + " boolean b15 = s1 != l1;\n" + + " boolean b16 = s1 != l2;\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " boolean b1 = 1 == 1;\n" + + " ^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " boolean b2 = 1 != 1;\n" + + " ^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "3. WARNING in X.java (at line 5)\n" + + " boolean b3 = 1 == 1.0;\n" + + " ^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "4. WARNING in X.java (at line 6)\n" + + " boolean b4 = 1 != 1.0;\n" + + " ^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "5. WARNING in X.java (at line 13)\n" + + " boolean b9 = 1 == s1;\n" + + " ^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "6. WARNING in X.java (at line 15)\n" + + " boolean b91 = 1 != s1;\n" + + " ^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "7. WARNING in X.java (at line 19)\n" + + " boolean b11 = 1 == l1;\n" + + " ^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "8. WARNING in X.java (at line 21)\n" + + " boolean b111 = 1 != l1;\n" + + " ^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "9. WARNING in X.java (at line 23)\n" + + " boolean b13 = s1 == l1;\n" + + " ^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "10. WARNING in X.java (at line 25)\n" + + " boolean b15 = s1 != l1;\n" + + " ^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "11. ERROR in X.java (at line 28)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} + +/** + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=276741" + */ +public void test0039() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void gain(String[] args) {\n" + + " boolean b1 = this == this;\n" + + " boolean b2 = this != this;\n" + + " boolean b3 = this != new X();\n" + + " boolean b4 = this == new X();\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " boolean b1 = this == this;\n" + + " ^^^^^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " boolean b2 = this != this;\n" + + " ^^^^^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +/** + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=281776" + * We now tolerate comparison of float and double entities against + * themselves as a legitimate idiom for NaN checking. + */ +public void test0040() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " double var = Double.NaN;\n" + + " if(var != var) {\n" + + " System.out.println(\"NaN\");\n" + + " }\n" + + " float varf = 10;\n" + + " if(varf != varf) {\n" + + " System.out.println(\"NaN\");\n" + + " }\n" + + " }\n" + + " Zork z;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=251227 +public void test0041() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(1.0 == 1.0);\n" + + " System.out.println(1.0f == 1.0f);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " System.out.println(1.0 == 1.0);\n" + + " ^^^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " System.out.println(1.0f == 1.0f);\n" + + " ^^^^^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=248897 +public void test0042() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + runTest( + new String[] { + "Test.java", + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " final String var = \"Hello\";\n" + + " final int local = 10;\n" + + " @ZAnn(var + local)\n" + + " class X {}\n" + + " new X();\n" + + " }\n" + + "}\n" + + "@interface ZAnn {\n" + + " String value();\n" + + "}\n" + }, + null /* errorOptions */, + new String[] { + CompilerOptions.OPTION_ReportUnusedLocal + } /* warningOptions */, + null /* ignoreOptions */, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "" /* expectedOutputString */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=313825 +public void test0043() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(int i) {\n" + + " foo((a));\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " foo((a));\n" + + " ^\n" + + "a cannot be resolved to a variable\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310264 +public void test0044() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " volatile int x;\n" + + " int nvx;\n" + + " void foo(int i) {\n" + + " x = x;\n" + + " nvx = nvx;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " nvx = nvx;\n" + + " ^^^^^^^^^\n" + + "The assignment to variable nvx has no effect\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=310264 +public void test0045() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " volatile int x = this.x;\n" + + " int nvx = this.nvx;\n" + + " void foo(int i) {\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " volatile int x = this.x;\n" + + " ^^^^^^^^^^\n" + + "The assignment to variable x has no effect\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " int nvx = this.nvx;\n" + + " ^^^^^^^^^^^^^^\n" + + "The assignment to variable nvx has no effect\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +public void test0046() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " int foo() {\n" + + " int i=1;\n" + + " boolean b=false;\n" + + " b|=true;\n" + // not a relevant usage + " int k = 2;\n" + + " --k;\n" + // not a relevant usage + " k+=3;\n" + // not a relevant usage + " Integer j = 3;\n" + + " j++;\n" + // relevant because unboxing is involved + " i++;\n" + // not relevant but should still not report because next is relevant + " return i++;\n" + // value after increment is used + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " boolean b=false;\n" + + " ^\n" + + "The value of the local variable b is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 6)\n" + + " int k = 2;\n" + + " ^\n" + + "The value of the local variable k is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// variant with private fields instead of locals +public void test0046_field() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " private int i=1;\n" + + " private boolean b=false;\n" + + " private int k = 2;\n" + + " private Integer j = 3;\n" + + " int foo() {\n" + + " b|=true;\n" + // not a relevant usage + " --k;\n" + // not a relevant usage + " k+=3;\n" + // not a relevant usage + " j++;\n" + // relevant because unboxing is involved + " return i++;\n" + // value after increment is used + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private boolean b=false;\n" + + " ^\n" + + "The value of the field X.b is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " private int k = 2;\n" + + " ^\n" + + "The value of the field X.k is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// variant with private fields instead of locals - this-qualified access +public void test0046_field_this_qualified() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " private int i=1;\n" + + " private boolean b=false;\n" + + " private int k = 2;\n" + + " private Integer j = 3;\n" + + " int foo() {\n" + + " this.b|=true;\n" + // not a relevant usage + " --this.k;\n" + // not a relevant usage + " getThis().k+=3;\n" + // not a relevant usage + " this.j++;\n" + // relevant because unboxing is involved + " return this.i++;\n" + // value after increment is used + " }\n" + + " X getThis() { return this; }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private boolean b=false;\n" + + " ^\n" + + "The value of the field X.b is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " private int k = 2;\n" + + " ^\n" + + "The value of the field X.k is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// variant with private fields instead of locals - regular qualified access +public void test0046_field_qualified() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " private int i=1;\n" + + " private boolean b=false;\n" + + " private int k = 2;\n" + + " private Integer j = 3;\n" + + " int foo(X that) {\n" + + " that.b|=true;\n" + // not a relevant usage + " --that.k;\n" + // not a relevant usage + " that.k+=3;\n" + // not a relevant usage + " that.j++;\n" + // relevant because unboxing is involved + " that.i++;\n"+ // not relevant but should still not report because next is relevant + " return that.i++;\n" + // value after increment is used + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " private boolean b=false;\n" + + " ^\n" + + "The value of the field X.b is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " private int k = 2;\n" + + " ^\n" + + "The value of the field X.k is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// variant with fields inside a private type +public void test0046_field_in_private_type() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " private class Y {\n" + + " int i=1;\n" + + " public boolean b=false;\n" + + " protected int k = 2;\n" + + " Integer j = 3;\n" + + " }\n" + + " int foo(Y y) {\n" + + " y.b|=true;\n" + // not a relevant usage + " --y.k;\n" + // not a relevant usage + " y.k+=3;\n" + // not a relevant usage + " y.j++;\n" + // relevant because unboxing is involved + " int result = y.i++;\n" + // value after increment is used + " y.i++;\n" + // not relevant, but previous is + " return result;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " public boolean b=false;\n" + + " ^\n" + + "The value of the field X.Y.b is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " protected int k = 2;\n" + + " ^\n" + + "The value of the field X.Y.k is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +public void test0047() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void foo(int param1, int param2, Integer param3) {\n" + + " boolean b=false;\n" + + " b|=true;\n" + // not a relevant usage + " param1++;\n" + // not a relevant usage + " {\n" + + " int val=23;\n" + + " param2 += val;\n" +// not a relevant usage of param2 + " }\n" + + " param3++;\n" + // relevant because unboxing is involved + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " void foo(int param1, int param2, Integer param3) {\n" + + " ^^^^^^\n" + + "The value of the parameter param1 is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " void foo(int param1, int param2, Integer param3) {\n" + + " ^^^^^^\n" + + "The value of the parameter param2 is not used\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " boolean b=false;\n" + + " ^\n" + + "The value of the local variable b is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// To verify that unused parameter warning is not shown for an implementing method's parameter when +// CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract is disabled +public void test0048() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends A implements Y{\n" + + " public void foo(int param1, int param2, Integer param3) {\n" + // implementing method, so dont warn + " boolean b=false;\n" + + " b|=true;\n" + // not a relevant usage + " param1++;\n" + // not a relevant usage + " param2 += 1;\n" + // not a relevant usage + " param3++;\n" + // relevant because unboxing is involved + " }\n" + + " public void foo(int param1, int param2) {\n" + // warn + " boolean b=false;\n" + + " b|=true;\n" + // not a relevant usage + " param1++;\n" + // not a relevant usage + " param2 += 1;\n" + // not a relevant usage + " }\n" + + " public void bar(int param1, int param2, Integer param3) {\n" + // implementing method, so dont warn + " param1++;\n" + // not a relevant usage + " param2 += 1;\n" + // not a relevant usage + " param3++;\n" + // relevant because unboxing is involved + " }\n" + + "}\n" + + "interface Y{\n" + + " public void foo(int param1, int param2, Integer param3);" + + "}\n" + + "abstract class A{\n" + + " public abstract void bar(int param1, int param2, Integer param3);" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " boolean b=false;\n" + + " ^\n" + + "The value of the local variable b is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " public void foo(int param1, int param2) {\n" + + " ^^^^^^\n" + + "The value of the parameter param1 is not used\n" + + "----------\n" + + "3. WARNING in X.java (at line 9)\n" + + " public void foo(int param1, int param2) {\n" + + " ^^^^^^\n" + + "The value of the parameter param2 is not used\n" + + "----------\n" + + "4. WARNING in X.java (at line 10)\n" + + " boolean b=false;\n" + + " ^\n" + + "The value of the local variable b is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// To verify that unused parameter warning is not shown for an overriding method's parameter when +// CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete is disabled +public void test0049() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X extends A {\n" + + " public void foo(int param1, int param2, Integer param3) {\n" + // overriding method, so dont warn + " boolean b=false;\n" + + " b|=true;\n" + // not a relevant usage + " param1++;\n" + // not a relevant usage + " param2 += 1;\n" + // not a relevant usage + " param3++;\n" + // relevant because unboxing is involved + " }\n" + + " public void foo(int param1, Integer param3) {\n" + // overriding method, so dont warn + " param1++;\n" + // not a relevant usage + " param3++;\n" + // relevant because unboxing is involved + " }\n" + + "}\n" + + "class A{\n" + + " public void foo(int param1, int param2, Integer param3) {\n" + + " param1 -=1;\n" + // not a relevant usage + " param2--;\n" + // not a relevant usage + " param3--;\n" + // relevant because unboxing is involved + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " boolean b=false;\n" + + " ^\n" + + "The value of the local variable b is not used\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " public void foo(int param1, Integer param3) {\n" + + " ^^^^^^\n" + + "The value of the parameter param1 is not used\n" + + "----------\n" + + "3. WARNING in X.java (at line 15)\n" + + " public void foo(int param1, int param2, Integer param3) {\n" + + " ^^^^^^\n" + + "The value of the parameter param1 is not used\n" + + "----------\n" + + "4. WARNING in X.java (at line 15)\n" + + " public void foo(int param1, int param2, Integer param3) {\n" + + " ^^^^^^\n" + + "The value of the parameter param2 is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// To verify that unused local warning is not shown for locals declared in unreachable code +public void test0050() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " int foo() {\n" + + " int i=1;\n" + + " if (false) {\n" + + " boolean b=false;\n" + // don't complain as unused + " b|=true;\n" + + " }\n" + // not a relevant usage + " int k = 2;\n" + + " --k;\n" + // not a relevant usage + " k+=3;\n" + // not a relevant usage + " Integer j = 3;\n" + + " j++;\n" + // relevant because unboxing is involved + " return i++;\n" + // value after increment is used + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (false) {\n" + + " boolean b=false;\n" + + " b|=true;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " int k = 2;\n" + + " ^\n" + + "The value of the local variable k is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=185682 +// To verify that a constructor argument is handled correctly +public void test0051() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedParameter, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " X(int abc) {\n" + + " abc++;\n" + // not a relevant usage + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " X(int abc) {\n" + + " ^^^\n" + + "The value of the parameter abc is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281 +public void test0052() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " Y y = new Y();\n" + + " private class Y {\n" + + " int abc;\n" + + " Y() {\n" + + " abc++;\n" + // not a relevant usage + " }\n" + + " }\n" + + " class Z extends Y {}\n" + // makes 'abc' externally accessible + "}" + }, + "", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null/*vmArguments*/, + customOptions, + null/*requestor*/); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281 +// multi-level inheritance +public void test0052a() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "Outer.java", + "class Outer {\n" + + " private class Inner1 {\n" + + " int foo;\n" + + " }\n" + + " private class Inner2 extends Inner1 { }\n" + + " class Inner3 extends Inner2 { }\n" + // foo is exposed here + "}\n" + }, + "", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null/*vmArguments*/, + customOptions, + null/*requestor*/); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328281 +// member type of private +public void test0052b() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "Outer.java", + "class Outer {\n" + + " private class Inner1 {\n" + + " class Foo{}\n" + + " }\n" + + " private class Inner2 extends Inner1 { }\n" + + " class Inner3 extends Inner2 { }\n" + // Foo is exposed here + "}\n" + }, + "", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null/*vmArguments*/, + customOptions, + null/*requestor*/); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test0053() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " int foo() {\n" + + " int i=1;\n" + + " i++;\n" + // value after increment is still not used + " return 0;\n" + + " }\n" + + "}" + }, + "", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null, + customOptions, + null); + String expectedOutput = + " // Method descriptor #15 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " int foo();\n" + + " 0 iconst_0\n" + + " 1 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 2] local: this index: 0 type: X\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test0054() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " int foo() {\n" + + " int i=1;\n" + + " return i+=1;\n" + // value is used as it is returned + " }\n" + + "}" + }, + "", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null, + customOptions, + null); + String expectedOutput = + " // Method descriptor #15 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " int foo();\n" + + " 0 iconst_1\n" + + " 1 istore_1 [i]\n" + + " 2 iinc 1 1 [i]\n" + + " 5 iload_1 [i]\n" + + " 6 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 7] local: this index: 0 type: X\n" + + " [pc: 2, pc: 7] local: i index: 1 type: int\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=329613 +// regression caused by https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test0055() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + this.runNegativeTest( + new String[] { + "test1/E.java", + "package test1;\n" + + "public class E {\n" + + " private void foo() {\n" + + " int a= 10;\n" + + " a++;\n" + + " a--;\n" + + " --a;\n" + + " ++a;\n" + + " for ( ; ; a++) {\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in test1\\E.java (at line 4)\n" + + " int a= 10;\n" + + " ^\n" + + "The value of the local variable a is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test0056() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int foo() {\n" + + " int i = 2;\n" + + " int j = 3;\n" + + " return (i += j *= 3);\n" + // value is used as it is returned + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo());\n" + + " }\n" + + "}" + }, + "11", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null, + customOptions, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=328519 +public void test0057() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main (String args[]) {\n" + + " int i = 0;\n" + + " i += 4 + foo();\n" + + " }\n" + + " public static int foo() {\n" + + " System.out.println(\"OK\");\n" + + " return 0;\n" + + " }\n" + + "}" + }, + "OK", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + null, + customOptions, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=336648 +public void _test0058() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(String m) {\n" + + " final String message= m;\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " if (\"x\".equals(message)) {\n" + + " bug(); // undefined method\n" + + " }\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" + }, + "----------\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" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=339139 +// Issue local variable not used warning inside deadcode +public void test0059() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object a = null;\n" + + " if (a != null){\n" + + " int j = 3;\n" + + " j++;\n" + // value is not used + " }\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (a != null){\n" + + " int j = 3;\n" + + " j++;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " int j = 3;\n" + + " ^\n" + + "The value of the local variable j is not used\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=417803, [internal] Build a build environment compiler to warn on TypeBinding comparisons +public void test0060() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUninternedIdentityComparison, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "org/eclipse/jdt/internal/compiler/lookup/X.java", + "package org.eclipse.jdt.internal.compiler.lookup;\n" + + "class TypeBinding {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void gain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void vain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " //$IDENTITY-COMPARISON$\n" + + " //$IDENTITY-COMPARISON$\n" + + " //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void cain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in org\\eclipse\\jdt\\internal\\compiler\\lookup\\X.java (at line 7)\n" + + " if (t1 == t2) { \n" + + " ^^^^^^^^\n" + + "The uninterned types TypeBinding and TypeBinding should not be compared using ==/!= operators.\n" + + "----------\n" + + "2. ERROR in org\\eclipse\\jdt\\internal\\compiler\\lookup\\X.java (at line 9)\n" + + " if (t1 == t2) {\n" + + " ^^^^^^^^\n" + + "The uninterned types TypeBinding and TypeBinding should not be compared using ==/!= operators.\n" + + "----------\n" + + "3. ERROR in org\\eclipse\\jdt\\internal\\compiler\\lookup\\X.java (at line 16)\n" + + " if (t1 == t2) { \n" + + " ^^^^^^^^\n" + + "The uninterned types TypeBinding and TypeBinding should not be compared using ==/!= operators.\n" + + "----------\n" + + "4. ERROR in org\\eclipse\\jdt\\internal\\compiler\\lookup\\X.java (at line 18)\n" + + " if (t1 == t2) {\n" + + " ^^^^^^^^\n" + + "The uninterned types TypeBinding and TypeBinding should not be compared using ==/!= operators.\n" + + "----------\n" + + "5. ERROR in org\\eclipse\\jdt\\internal\\compiler\\lookup\\X.java (at line 28)\n" + + " if (t1 == t2) { \n" + + " ^^^^^^^^\n" + + "The uninterned types TypeBinding and TypeBinding should not be compared using ==/!= operators.\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=417803, [internal] Build a build environment compiler to warn on TypeBinding comparisons +public void test0061() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUninternedIdentityComparison, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "org/eclipse/nonjdt/internal/compiler/lookup/X.java", + "package org.eclipse.nonjdt.internal.compiler.lookup;\n" + + "class TypeBinding {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void gain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void vain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " //$IDENTITY-COMPARISON$\n" + + " //$IDENTITY-COMPARISON$\n" + + " //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void cain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=417803, [internal] Build a build environment compiler to warn on TypeBinding comparisons +public void test0062() throws Exception { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "org/eclipse/jdt/internal/compiler/lookup/X.java", + "package org.eclipse.jdt.internal.compiler.lookup;\n" + + "class TypeBinding {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void gain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void vain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " //$IDENTITY-COMPARISON$\n" + + " //$IDENTITY-COMPARISON$\n" + + " //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void cain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=417803, [internal] Build a build environment compiler to warn on TypeBinding comparisons +public void test0063() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUninternedIdentityComparison, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "org/eclipse/jdt/core/dom/X.java", + "package org.eclipse.jdt.core.dom;\n" + + "interface ITypeBinding {\n" + + "}\n" + + "class TypeBinding implements ITypeBinding {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void gain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void vain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " //$IDENTITY-COMPARISON$\n" + + " //$IDENTITY-COMPARISON$\n" + + " //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { \n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void cain(String[] args) {\n" + + " TypeBinding t1 = null, t2 = null;\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " if (t2 == t1) { //$IDENTITY-COMPARISON$\n" + + " if (t1 == t2) { //$IDENTITY-COMPARISON$\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in org\\eclipse\\jdt\\core\\dom\\X.java (at line 9)\n" + + " if (t1 == t2) { \n" + + " ^^^^^^^^\n" + + "The uninterned types TypeBinding and TypeBinding should not be compared using ==/!= operators.\n" + + "----------\n" + + "2. ERROR in org\\eclipse\\jdt\\core\\dom\\X.java (at line 11)\n" + + " if (t1 == t2) {\n" + + " ^^^^^^^^\n" + + "The uninterned types TypeBinding and TypeBinding should not be compared using ==/!= operators.\n" + + "----------\n" + + "3. ERROR in org\\eclipse\\jdt\\core\\dom\\X.java (at line 18)\n" + + " if (t1 == t2) { \n" + + " ^^^^^^^^\n" + + "The uninterned types TypeBinding and TypeBinding should not be compared using ==/!= operators.\n" + + "----------\n" + + "4. ERROR in org\\eclipse\\jdt\\core\\dom\\X.java (at line 20)\n" + + " if (t1 == t2) {\n" + + " ^^^^^^^^\n" + + "The uninterned types TypeBinding and TypeBinding should not be compared using ==/!= operators.\n" + + "----------\n" + + "5. ERROR in org\\eclipse\\jdt\\core\\dom\\X.java (at line 30)\n" + + " if (t1 == t2) { \n" + + " ^^^^^^^^\n" + + "The uninterned types TypeBinding and TypeBinding should not be compared using ==/!= operators.\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// Collection: contains & remove & get +public void testBug410218a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class X {\n" + + " void test() {\n" + + " Set set = new HashSet();\n" + + " short one = 1;\n" + + " set.add(one);\n" + + "\n" + + " if (set.contains(\"ONE\")) // bad\n" + + " set.remove(\"ONE\"); // bad\n" + + " if (set.contains(1)) // bad\n" + + " set.remove(1); // bad (tries to remove \"Integer 1\")\n" + + " System.out.println(set); // shows that the \"Short 1\" is still in!\n" + + "\n" + + " if (set.contains(one)) // ok\n" + + " set.remove(one); // ok\n" + + " if (set.contains(Short.valueOf(one))) // ok\n" + + " set.remove(Short.valueOf(one)); // ok\n" + + " System.out.println(set);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " if (set.contains(\"ONE\")) // bad\n" + + " ^^^^^\n" + + "Unlikely argument type String for contains(Object) on a Collection\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " set.remove(\"ONE\"); // bad\n" + + " ^^^^^\n" + + "Unlikely argument type String for remove(Object) on a Collection\n" + + "----------\n" + + "3. WARNING in X.java (at line 10)\n" + + " if (set.contains(1)) // bad\n" + + " ^\n" + + "Unlikely argument type int for contains(Object) on a Collection\n" + + "----------\n" + + "4. WARNING in X.java (at line 11)\n" + + " set.remove(1); // bad (tries to remove \"Integer 1\")\n" + + " ^\n" + + "Unlikely argument type int for remove(Object) on a Collection\n" + + "----------\n"); +} +// HashSet vs. TreeSet +public void testBug410218b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class X {\n" + + " void test(Set> hss, TreeSet ts, LinkedHashSet lhs) {\n" + + " if (hss.contains(ts)) // bad\n" + + " hss.remove(ts); // bad\n" + + " if (hss.contains((Set)ts)) // ok\n" + + " hss.remove((Set)ts); // ok\n" + + " if (hss.contains(lhs)) // ok\n" + + " hss.remove(lhs); // ok\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (hss.contains(ts)) // bad\n" + + " ^^\n" + + "Unlikely argument type TreeSet for contains(Object) on a Collection>\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " hss.remove(ts); // bad\n" + + " ^^\n" + + "Unlikely argument type TreeSet for remove(Object) on a Collection>\n" + + "----------\n"); +} +// HashSet vs. TreeSet or: strict +public void testBug410218b2() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE_STRICT, JavaCore.ENABLED); + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class X {\n" + + " void test(Set> hss, TreeSet ts, LinkedHashSet lhs) {\n" + + " if (hss.contains(ts)) // bad\n" + + " hss.remove(ts); // bad\n" + + " if (hss.contains((Set)ts)) // bad (because of strict check)\n" + + " hss.remove((Set)ts); // bad (because of strict check)\n" + + " if (hss.contains(lhs)) // ok\n" + + " hss.remove(lhs); // ok\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (hss.contains(ts)) // bad\n" + + " ^^\n" + + "Unlikely argument type TreeSet for contains(Object) on a Collection>\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " hss.remove(ts); // bad\n" + + " ^^\n" + + "Unlikely argument type TreeSet for remove(Object) on a Collection>\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " if (hss.contains((Set)ts)) // bad (because of strict check)\n" + + " ^^^^^^^^^^\n" + + "Unlikely argument type Set for contains(Object) on a Collection>\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " hss.remove((Set)ts); // bad (because of strict check)\n" + + " ^^^^^^^^^^\n" + + "Unlikely argument type Set for remove(Object) on a Collection>\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// Map: contains* & remove & get +public void testBug410218c() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class X {\n" + + " Number test(Map m, boolean f) {\n" + + " if (m.containsKey(\"ONE\")) // bad\n" + + " m.remove(\"ONE\"); // bad\n" + + " if (m.containsValue(\"ONE\")) // bad\n" + + " m.remove(\"ONE\"); // bad\n" + + " short one = 1;\n" + + " if (m.containsKey(one)) // almost ok\n" + + " m.remove(one); // almost ok\n" + + " if (m.containsValue(Short.valueOf(one))) // ok\n" + + " m.remove(Short.valueOf(one)); // almost ok\n" + + " if (f)\n" + + " return m.get(\"ONE\"); // bad\n" + + " return m.get(one);\n // almost ok\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " if (m.containsKey(\"ONE\")) // bad\n" + + " ^^^^^\n" + + "Unlikely argument type String for containsKey(Object) on a Map\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " m.remove(\"ONE\"); // bad\n" + + " ^^^^^\n" + + "Unlikely argument type String for remove(Object) on a Map\n" + + "----------\n" + + "3. WARNING in X.java (at line 6)\n" + + " if (m.containsValue(\"ONE\")) // bad\n" + + " ^^^^^\n" + + "Unlikely argument type String for containsValue(Object) on a Map\n" + + "----------\n" + + "4. WARNING in X.java (at line 7)\n" + + " m.remove(\"ONE\"); // bad\n" + + " ^^^^^\n" + + "Unlikely argument type String for remove(Object) on a Map\n" + + "----------\n" + + "5. WARNING in X.java (at line 14)\n" + + " return m.get(\"ONE\"); // bad\n" + + " ^^^^^\n" + + "Unlikely argument type String for get(Object) on a Map\n" + + "----------\n"); +} +// Collection: {contains,remove,retain}All, non-generic sub type of Collection, configured to be ERROR +public void testBug410218d() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE, JavaCore.ERROR); + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface NumberCollection extends Collection {}\n" + + "class X {\n" + + " void test(NumberCollection numbers, List ints, Set stringSet) {\n" + + " if (numbers.containsAll(ints)) // ok\n" + + " numbers.removeAll(ints); // ok\n" + + " else\n" + + " numbers.retainAll(ints); // ok\n" + + "\n" + + " numbers.removeAll(stringSet); // bad\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " numbers.removeAll(stringSet); // bad\n" + + " ^^^^^^^^^\n" + + "Unlikely argument type Set for removeAll(Collection) on a Collection\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +// List.indexOf: w/ and w/o @SuppressWarnings +public void testBug410218e() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE, JavaCore.WARNING); + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "class X {\n" + + " int test1(List ints, Object o) {\n" + + " return ints.indexOf(\"ONE\"); // bad\n" + + " }\n" + + " @SuppressWarnings(\"unlikely-arg-type\")\n" + + " int test2(List ints, boolean f, Object o) {\n" + + " if (f)\n" + + " return ints.indexOf(\"ONE\"); // bad but suppressed\n" + + " return ints.indexOf(o); // supertype\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " return ints.indexOf(\"ONE\"); // bad\n" + + " ^^^^^\n" + + "Unlikely argument type String for indexOf(Object) on a List\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} + +// Method references, equals, wildcards +public void testBug410218f() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE, JavaCore.WARNING); + customOptions.put(JavaCore.COMPILER_PB_UNLIKELY_EQUALS_ARGUMENT_TYPE, JavaCore.INFO); + runNegativeTest( + new String[] { + "test/TestUnlikely.java", + "package test;\n" + + "\n" + + "import java.util.Collection;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "import java.util.Map;\n" + + "import java.util.Objects;\n" + + "import java.util.Set;\n" + + "import java.util.function.BiPredicate;\n" + + "import java.util.function.Predicate;\n" + + "\n" + + "public class TestUnlikely {\n" + + " interface Interface {\n" + + " }\n" + + "\n" + + " interface OtherInterface {\n" + + " }\n" + + "\n" + + " static class NonFinal implements Interface {\n" + + " }\n" + + "\n" + + " static class Sub extends NonFinal implements OtherInterface {\n" + + " }\n" + + "\n" + + " static final class Final implements Interface {\n" + + " }\n" + + "\n" + + " void f1(List c, Interface i, OtherInterface o, Final f, NonFinal nf, Sub s) {\n" + + " c.remove(i);\n" + + " c.remove(o); // warning: unrelated interface\n" + + " c.remove(f);\n" + + " c.remove(nf);\n" + + " c.remove(s);\n" + + " }\n" + + "\n" + + " void f2(List c, Interface i, OtherInterface o, Final f, NonFinal nf, Sub s) {\n" + + " c.remove(i); // warning: unrelated interface\n" + + " c.remove(o);\n" + + " c.remove(f); // warning: impossible\n" + + " c.remove(nf); // warning: castable, but not supertype\n" + + " c.remove(s);\n" + + " }\n" + + "\n" + + " void f3(List c, Interface i, OtherInterface o, Final f, NonFinal nf, Sub s) {\n" + + " c.remove(i); // supertype\n" + + " c.remove(o); // warning: impossible\n" + + " c.remove(f);\n" + + " c.remove(nf); // warning: impossible\n" + + " c.remove(s); // warning: impossible\n" + + " }\n" + + "\n" + + " void f4(List c, Interface i, OtherInterface o, Final f, NonFinal nf, Sub s) {\n" + + " c.remove(i); // supertype\n" + + " c.remove(o); // warning: unrelated interface\n" + + " c.remove(f); // warning: impossible\n" + + " c.remove(nf);\n" + + " c.remove(s);\n" + + " }\n" + + "\n" + + " void f5(List c, Interface i, OtherInterface o, Final f, NonFinal nf, Sub s) {\n" + + " c.remove(i); // supertype\n" + + " c.remove(o); // supertype\n" + + " c.remove(f); // warning: impossible\n" + + " c.remove(nf); // supertype\n" + + " c.remove(s);\n" + + " }\n" + + "\n" + + " void map(Map map, K key, V value) {\n" + + " map.containsKey(key);\n" + + " map.containsKey(value); // warning\n" + + " map.containsValue(key); // warning\n" + + " map.containsValue(value);\n" + + " }\n" + + "\n" + + " boolean wildcards(Collection c, Iterable s) {\n" + + " for (Iterator iterator = s.iterator(); iterator.hasNext();) {\n" + + " if (c.contains(iterator.next())) {\n" + + " return true;\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + "\n" + + " boolean relatedTypeVariables(Collection c, Iterable s) {\n" + + " for (Iterator iterator = s.iterator(); iterator.hasNext();) {\n" + + " if (c.contains(iterator.next())) {\n" + + " return true;\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + "\n" + + " boolean unrelatedTypeVariables(Collection c, Iterable s) {\n" + + " for (Iterator iterator = s.iterator(); iterator.hasNext();) {\n" + + " if (c.contains(iterator.next())) { // warning\n" + + " return true;\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + "\n" + + " void all(List c, Collection s, Set other) {\n" + + " c.removeAll(s);\n" + + " s.removeAll(c);\n" + + " c.removeAll(other); // warning\n" + + " }\n" + + "\n" + + " void methodRef(Set c, Interface i, OtherInterface o, Final f, NonFinal nf, Sub s) {\n" + + " Predicate p1 = c::contains;\n" + + " BiPredicate, Interface> bp1 = Collection::contains;\n" + + " Predicate p2 = c::contains; // warning\n" + + " BiPredicate, OtherInterface> bp2 = Collection::contains; // warning\n" + + " p1.test(i);\n" + + " bp1.test(c, i);\n" + + " p2.test(o);\n" + + " bp2.test(c, o);\n" + + " }\n" + + "\n" + + " void equals(String s, Integer i, Number n) {\n" + + " s.equals(i); // info\n" + + " i.equals(s); // info\n" + + " i.equals(n);\n" + + " n.equals(i);\n" + + "\n" + + " Predicate p1 = i::equals; // info\n" + + " p1.test(s);\n" + + "\n" + + " BiPredicate bp2 = Object::equals; // info\n" + + " bp2.test(s, i);\n" + + "\n" + + " Objects.equals(s, i); // info\n" + + " Objects.equals(i, s); // info\n" + + " Objects.equals(n, i);\n" + + " Objects.equals(i, n);\n" + + "\n" + + " BiPredicate bp3 = Objects::equals; // info\n" + + " bp3.test(s, i);\n" + + " }\n" + + "\n" + + "}\n" + + "", + }, + "----------\n" + + "1. WARNING in test\\TestUnlikely.java (at line 30)\n" + + " c.remove(o); // warning: unrelated interface\n" + + " ^\n" + + "Unlikely argument type TestUnlikely.OtherInterface for remove(Object) on a Collection\n" + + "----------\n" + + "2. WARNING in test\\TestUnlikely.java (at line 37)\n" + + " c.remove(i); // warning: unrelated interface\n" + + " ^\n" + + "Unlikely argument type TestUnlikely.Interface for remove(Object) on a Collection\n" + + "----------\n" + + "3. WARNING in test\\TestUnlikely.java (at line 39)\n" + + " c.remove(f); // warning: impossible\n" + + " ^\n" + + "Unlikely argument type TestUnlikely.Final for remove(Object) on a Collection\n" + + "----------\n" + + "4. WARNING in test\\TestUnlikely.java (at line 40)\n" + + " c.remove(nf); // warning: castable, but not supertype\n" + + " ^^\n" + + "Unlikely argument type TestUnlikely.NonFinal for remove(Object) on a Collection\n" + + "----------\n" + + "5. WARNING in test\\TestUnlikely.java (at line 46)\n" + + " c.remove(o); // warning: impossible\n" + + " ^\n" + + "Unlikely argument type TestUnlikely.OtherInterface for remove(Object) on a Collection\n" + + "----------\n" + + "6. WARNING in test\\TestUnlikely.java (at line 48)\n" + + " c.remove(nf); // warning: impossible\n" + + " ^^\n" + + "Unlikely argument type TestUnlikely.NonFinal for remove(Object) on a Collection\n" + + "----------\n" + + "7. WARNING in test\\TestUnlikely.java (at line 49)\n" + + " c.remove(s); // warning: impossible\n" + + " ^\n" + + "Unlikely argument type TestUnlikely.Sub for remove(Object) on a Collection\n" + + "----------\n" + + "8. WARNING in test\\TestUnlikely.java (at line 54)\n" + + " c.remove(o); // warning: unrelated interface\n" + + " ^\n" + + "Unlikely argument type TestUnlikely.OtherInterface for remove(Object) on a Collection\n" + + "----------\n" + + "9. WARNING in test\\TestUnlikely.java (at line 55)\n" + + " c.remove(f); // warning: impossible\n" + + " ^\n" + + "Unlikely argument type TestUnlikely.Final for remove(Object) on a Collection\n" + + "----------\n" + + "10. WARNING in test\\TestUnlikely.java (at line 63)\n" + + " c.remove(f); // warning: impossible\n" + + " ^\n" + + "Unlikely argument type TestUnlikely.Final for remove(Object) on a Collection\n" + + "----------\n" + + "11. WARNING in test\\TestUnlikely.java (at line 70)\n" + + " map.containsKey(value); // warning\n" + + " ^^^^^\n" + + "Unlikely argument type V for containsKey(Object) on a Map\n" + + "----------\n" + + "12. WARNING in test\\TestUnlikely.java (at line 71)\n" + + " map.containsValue(key); // warning\n" + + " ^^^\n" + + "Unlikely argument type K for containsValue(Object) on a Map\n" + + "----------\n" + + "13. WARNING in test\\TestUnlikely.java (at line 95)\n" + + " if (c.contains(iterator.next())) { // warning\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unlikely argument type U for contains(Object) on a Collection\n" + + "----------\n" + + "14. WARNING in test\\TestUnlikely.java (at line 105)\n" + + " c.removeAll(other); // warning\n" + + " ^^^^^\n" + + "Unlikely argument type Set for removeAll(Collection) on a Collection\n" + + "----------\n" + + "15. WARNING in test\\TestUnlikely.java (at line 111)\n" + + " Predicate p2 = c::contains; // warning\n" + + " ^^^^^^^^^^^\n" + + "Unlikely argument type TestUnlikely.OtherInterface for contains(Object) on a Collection\n" + + "----------\n" + + "16. WARNING in test\\TestUnlikely.java (at line 112)\n" + + " BiPredicate, OtherInterface> bp2 = Collection::contains; // warning\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unlikely argument type TestUnlikely.OtherInterface for contains(Object) on a Collection\n" + + "----------\n" + + "17. INFO in test\\TestUnlikely.java (at line 120)\n" + + " s.equals(i); // info\n" + + " ^\n" + + "Unlikely argument type for equals(): Integer seems to be unrelated to String\n" + + "----------\n" + + "18. INFO in test\\TestUnlikely.java (at line 121)\n" + + " i.equals(s); // info\n" + + " ^\n" + + "Unlikely argument type for equals(): String seems to be unrelated to Integer\n" + + "----------\n" + + "19. INFO in test\\TestUnlikely.java (at line 125)\n" + + " Predicate p1 = i::equals; // info\n" + + " ^^^^^^^^^\n" + + "Unlikely argument type for equals(): String seems to be unrelated to Integer\n" + + "----------\n" + + "20. INFO in test\\TestUnlikely.java (at line 128)\n" + + " BiPredicate bp2 = Object::equals; // info\n" + + " ^^^^^^^^^^^^^^\n" + + "Unlikely argument type for equals(): Integer seems to be unrelated to String\n" + + "----------\n" + + "21. INFO in test\\TestUnlikely.java (at line 131)\n" + + " Objects.equals(s, i); // info\n" + + " ^\n" + + "Unlikely argument type for equals(): Integer seems to be unrelated to String\n" + + "----------\n" + + "22. INFO in test\\TestUnlikely.java (at line 132)\n" + + " Objects.equals(i, s); // info\n" + + " ^\n" + + "Unlikely argument type for equals(): String seems to be unrelated to Integer\n" + + "----------\n" + + "23. INFO in test\\TestUnlikely.java (at line 136)\n" + + " BiPredicate bp3 = Objects::equals; // info\n" + + " ^^^^^^^^^^^^^^^\n" + + "Unlikely argument type for equals(): Integer seems to be unrelated to String\n" + + "----------\n" + , + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} +public void testBug514956a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNLIKELY_COLLECTION_METHOD_ARGUMENT_TYPE, JavaCore.WARNING); + customOptions.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.ERROR); + runConformTest( + new String[] { + "Unlikely.java", + "import java.util.Map;\n" + + "\n" + + "interface MApplicationElement {}\n" + + "interface EObject {}\n" + + "public class Unlikely {\n" + + " void m(Map map, EObject key) {\n" + + " map.get((MApplicationElement)key);\n" + + " }\n" + + "}\n" + }, + customOptions); +} +public void testBug514956b() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNLIKELY_EQUALS_ARGUMENT_TYPE, JavaCore.WARNING); + customOptions.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.ERROR); + runConformTest( + new String[] { + "Unlikely.java", + "interface EObject {}\n" + + "public class Unlikely {\n" + + " boolean m(EObject key) {\n" + + " return this.equals((Unlikely)key);\n" + + " }\n" + + "}\n" + }, + customOptions); +} +public void testBug514956c() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNLIKELY_EQUALS_ARGUMENT_TYPE, JavaCore.WARNING); + customOptions.put(JavaCore.COMPILER_PB_UNNECESSARY_TYPE_CHECK, JavaCore.ERROR); + runNegativeTest( + new String[] { + "Unlikely.java", + "interface I1 {}\n" + + "interface I2 {}\n" + + "interface I3 {}\n" + + "public class Unlikely implements I1 {\n" + + " boolean m1(I1 i1) {\n" + + " return i1.equals((I1)this);\n" + // not a downcast + " }\n" + + " boolean m2(I1 i1, I2 i2) {\n" + + " return i1.equals((I3)i2);\n" + // cast doesn't fix a problem + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Unlikely.java (at line 6)\n" + + " return i1.equals((I1)this);\n" + + " ^^^^^^^^\n" + + "Unnecessary cast from Unlikely to I1\n" + + "----------\n" + + "2. ERROR in Unlikely.java (at line 9)\n" + + " return i1.equals((I3)i2);\n" + + " ^^^^^^\n" + + "Unnecessary cast from I2 to I3\n" + + "----------\n" + + "3. WARNING in Unlikely.java (at line 9)\n" + + " return i1.equals((I3)i2);\n" + + " ^^^^^^\n" + + "Unlikely argument type for equals(): I3 seems to be unrelated to I1\n" + + "----------\n", + null, // classlibs + false, // flush output dir + customOptions); +} +// mixture of raw type an parametrized type +public void testBug513310() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runConformTest( + new String[] { + "test/Test.java", + "package test;\n" + + "\n" + + "import java.util.List;\n" + + "import java.util.Set;\n" + + "\n" + + "public class Test {\n" + + " void f(List dependencyList, Set set) {\n" + + " dependencyList.removeAll(set);\n" + + " }\n" + + "}\n" + + "", + } + ); +} +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java new file mode 100644 index 0000000000..0202c6c7fe --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java @@ -0,0 +1,9093 @@ +/******************************************************************************* + * Copyright (c) 2019, 2021 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.core.util.ClassFormatException; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class RecordsRestrictedClassTest extends AbstractRegressionTest { + + static { +// TESTS_NUMBERS = new int [] { 40 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] { "testBug574284"}; + } + + public static Class testClass() { + return RecordsRestrictedClassTest.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_16); + } + public RecordsRestrictedClassTest(String testName){ + super(testName); + } + + // Enables the tests to run individually + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16); + defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_16); + defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_16); + defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + return defaultOptions; + } + // Enables the tests to run individually + protected Map getCompilerOptionsWithPreview() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17); + defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17); + defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17); + defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + return defaultOptions; + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput) { + runConformTest(testFiles, expectedOutput, getCompilerOptions()); + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { + if (!isJRE16Plus) + return; + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedOutputString = expectedOutput; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.customOptions = customOptions; + runner.javacTestOptions = JavacTestOptions.forRelease("16"); + runner.runConformTest(); + } + @Override + protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) { + if (!isJRE16Plus) + return; + runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.DEFAULT); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog) { + runWarningTest(testFiles, expectedCompilerLog, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, Map customOptions) { + runWarningTest(testFiles, expectedCompilerLog, customOptions, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, + Map customOptions, String javacAdditionalTestOptions) { + if (!isJRE16Plus) + return; + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedCompilerLog; + runner.customOptions = customOptions; + runner.vmArguments = new String[] {}; + runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forRelease("16") : + JavacTestOptions.forRelease("16", javacAdditionalTestOptions); + runner.runWarningTest(); + } + + private static void verifyClassFile(String expectedOutput, String classFileName, int mode) + throws IOException, ClassFormatException { + File f = new File(OUTPUT_DIR + File.separator + classFileName); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", mode); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + System.out.println("..."); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + private void verifyOutputNegative(String result, String expectedOutput) { + verifyOutput(result, expectedOutput, false); + } + private void verifyOutput(String result, String expectedOutput, boolean positive) { + int index = result.indexOf(expectedOutput); + if (positive) { + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + System.out.println("..."); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } else { + if (index != -1) { + assertEquals("Unexpected contents", "", result); + } + } + } + private String getClassFileContents( String classFileName, int mode) throws IOException, + ClassFormatException { + File f = new File(OUTPUT_DIR + File.separator + classFileName); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", mode); + return result; + } + + public void testBug550750_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int x, int y){\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_002() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "abstract record Point(int x, int y){\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " abstract record Point(int x, int y){\n" + + " ^^^^^\n" + + "Illegal modifier for the record Point; only public, final and strictfp are permitted\n" + + "----------\n"); + } + /* A record declaration is implicitly final. It is permitted for the declaration of + * a record type to redundantly specify the final modifier. */ + public void testBug550750_003() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "final record Point(int x, int y){\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_004() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "final final record Point(int x, int y){\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " final final record Point(int x, int y){\n" + + " ^^^^^\n" + + "Duplicate modifier for the type Point\n" + + "----------\n"); + } + public void testBug550750_005() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "final record Point(int x, int y){\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_006() { + this.runNegativeTest( + new String[] { + "X.java", + "public public record X(int x, int y){\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public public record X(int x, int y){\n" + + " ^\n" + + "Duplicate modifier for the type X\n" + + "----------\n"); + } + public void testBug550750_007() { + runConformTest( + new String[] { + "X.java", + "final record Point(int x, int y){\n"+ + " public void foo() {}\n"+ + "}\n"+ + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_008() { + runConformTest( + new String[] { + "X.java", + "final record Point(int x, int y){\n"+ + " public Point {}\n"+ + "}\n"+ + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_009() { + runConformTest( + new String[] { + "X.java", + "final record Point(int x, int y){\n"+ + " public Point {}\n"+ + " public void foo() {}\n"+ + "}\n"+ + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}" + }, + "0"); + } + /* nested record implicitly static*/ + public void testBug550750_010() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + " record Point(int x, int y){\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + /* nested record explicitly static*/ + public void testBug550750_011() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + " static record Point(int x, int y){\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_012() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int ... x){\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_013() { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "record Point(@MyAnnotation int myInt, char myChar) {}\n"+ + " @Target({ElementType.FIELD, ElementType.TYPE})\n"+ + " @interface MyAnnotation {}\n" + + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_014() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) {\n"+ + " public int myInt(){\n"+ + " return this.myInt;\n" + + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_015() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) implements I {\n"+ + " public int myInt(){\n"+ + " return this.myInt;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "0"); + } + public void testBug550750_016() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) implements I {\n"+ + "}\n" + + "interface I {}\n" + }, + "0"); + } + public void testBug550750_017() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) implements I {\n"+ + " public Point(int myInt, char myChar){\n"+ + " this.myInt = myInt;\n" + + " this.myChar = myChar;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "0"); + } + public void testBug550750_018() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) implements I {\n"+ + " public Point(int myInt, char myChar){\n"+ + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public Point(int myInt, char myChar){\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The blank final field myChar may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " public Point(int myInt, char myChar){\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The blank final field myInt may not have been initialized\n" + + "----------\n"); + } + public void testBug550750_019() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) implements I {\n"+ + " private Point {\n"+ + " this.myInt = myInt;\n" + + " this.myChar = myChar;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " private Point {\n" + + " ^^^^^\n" + + "Cannot reduce the visibility of a canonical constructor Point from that of the record\n" + + "----------\n"); + } + public void testBug550750_020() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) implements I {\n"+ + " protected Point {\n"+ + " this.myInt = myInt;\n" + + " this.myChar = myChar;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " this.myInt = myInt;\n" + + " ^^^^^^^^^^\n" + + "Illegal explicit assignment of a final field myInt in compact constructor\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " this.myChar = myChar;\n" + + " ^^^^^^^^^^^\n" + + "Illegal explicit assignment of a final field myChar in compact constructor\n" + + "----------\n"); + } + public void testBug550750_022() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) implements I {\n"+ + " public Point {\n"+ + " this.myInt = myInt;\n" + + " this.myChar = myChar;\n" + + " return;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " return;\n" + + " ^^^^^^^\n" + + "The body of a compact constructor must not contain a return statement\n" + + "----------\n"); + } + public void testBug550750_023() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int finalize) implements I {\n"+ + " public Point {\n"+ + " this.myInt = myInt;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " record Point(int myInt, int finalize) implements I {\n" + + " ^^^^^^^^\n" + + "Illegal component name finalize in record Point;\n" + + "----------\n"); + } + public void testBug550750_024() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int finalize, int myZ) implements I {\n"+ + " public Point {\n"+ + " this.myInt = myInt;\n" + + " this.myZ = myZ;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " record Point(int myInt, int finalize, int myZ) implements I {\n" + + " ^^^^^^^^\n" + + "Illegal component name finalize in record Point;\n" + + "----------\n"); + } + public void testBug550750_025() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ, int myZ) implements I {\n"+ + " public Point {\n"+ + " this.myInt = myInt;\n" + + " this.myZ = myZ;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " record Point(int myInt, int myZ, int myZ) implements I {\n" + + " ^^^\n" + + "Duplicate component myZ in record\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " record Point(int myInt, int myZ, int myZ) implements I {\n" + + " ^^^\n" + + "Duplicate component myZ in record\n" + + "----------\n"); + } + public void testBug550750_026() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myInt, int myInt, int myZ) implements I {\n"+ + " public Point {\n"+ + " this.myInt = myInt;\n" + + " this.myZ = myZ;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " record Point(int myInt, int myInt, int myInt, int myZ) implements I {\n" + + " ^^^^^\n" + + "Duplicate component myInt in record\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " record Point(int myInt, int myInt, int myInt, int myZ) implements I {\n" + + " ^^^^^\n" + + "Duplicate component myInt in record\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " record Point(int myInt, int myInt, int myInt, int myZ) implements I {\n" + + " ^^^^^\n" + + "Duplicate component myInt in record\n" + + "----------\n"); + } + public void testBug550750_027() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ) implements I {\n"+ + " static final int z;\n"+ + " public Point {\n"+ + " this.myInt = myInt;\n" + + " this.myZ = myZ;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " static final int z;\n" + + " ^\n" + + "The blank final field z may not have been initialized\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " this.myInt = myInt;\n" + + " ^^^^^^^^^^\n" + + "Illegal explicit assignment of a final field myInt in compact constructor\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " this.myZ = myZ;\n" + + " ^^^^^^^^\n" + + "Illegal explicit assignment of a final field myZ in compact constructor\n" + + "----------\n"); + } + public void testBug550750_028() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ) implements I {\n"+ + " int z;\n"+ + " public Point {\n"+ + " this.myInt = myInt;\n" + + " this.myZ = myZ;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " int z;\n" + + " ^\n" + + "User declared non-static fields z are not permitted in a record\n" + + "----------\n"); + } + public void testBug550750_029() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ) implements I {\n"+ + " public Point {\n"+ + " this.myInt = myInt;\n" + + " this.myZ = myZ;\n" + + " }\n"+ + " public native void foo();\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " public native void foo();\n" + + " ^^^^^\n" + + "Illegal modifier native for method foo; native methods are not allowed in record\n" + + "----------\n"); + } + public void testBug550750_030() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ) implements I {\n"+ + " {\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " {\n" + + " System.out.println(0);\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Instance Initializer is not allowed in a record declaration\n" + + "----------\n"); + } + public void testBug550750_031() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ) implements I {\n"+ + " static {\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "0"); + } + public void testBug550750_032() { + this.runNegativeTest( + new String[] { + "X.java", + "class record {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); + } + public void testBug550750_033() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); + } + public void testBug550750_034() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + " public void foo(record args){}\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public void foo(record args){}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " public void foo(record args){}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); + } + public void testBug550750_035() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + " public void foo(record args){}\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public void foo(record args){}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); + } + public void testBug550750_036() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " I lambda = (record r) -> {};\n"+ + " }\n"+ + "}\n" + + "interface I {\n" + + " public void apply(int i);\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " I lambda = (record r) -> {};\n" + + " ^^^^^^^^^^^^^\n" + + "This lambda expression refers to the missing type record\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " I lambda = (record r) -> {};\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); + } + public void testBug550750_037() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(){\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_038() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(){\n"+ + " public Point {}\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_039() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(){\n"+ + " public Point() {}\n"+ + "}\n" + }, + "0"); + } + public void testBug550750_040() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(){\n"+ + " private int f;\n"+ + " public Point() {}\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " private int f;\n" + + " ^\n" + + "User declared non-static fields f are not permitted in a record\n" + + "----------\n"); + } + public void testBug550750_041() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(){\n"+ + " static int f;\n"+ + " public Point() {}\n"+ + "}\n" + }, + "0"); + } + public void testBug553152_001() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ) implements I {\n"+ + " public char myInt() {;\n" + + " return 'c';\n" + + " }\n"+ + " public int getmyInt() {;\n" + + " return this.myInt;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public char myInt() {;\n" + + " ^^^^\n" + + "Illegal return type of accessor; should be the same as the declared type int of the record component\n" + + "----------\n"); + } + public void testBug553152_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public java.lang.Integer myInt() {;\n" + + " return this.myInt;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "0"); + } + public void testBug553152_003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ) implements I {\n"+ + " public int myInt() {;\n" + + " return this.myInt;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public int myInt() {;\n" + + " ^^^^^^^\n" + + "The accessor method must not be generic\n" + + "----------\n"); + } + public void testBug553152_004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ) implements I {\n"+ + " private int myInt() {;\n" + + " return this.myInt;\n" + + " }\n"+ + " /* package */ int myZ() {;\n" + + " return this.myZ;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " private int myInt() {;\n" + + " ^^^^^^^\n" + + "The accessor method must be declared public\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " /* package */ int myZ() {;\n" + + " ^^^^^\n" + + "The accessor method must be declared public\n" + + "----------\n"); + } + public void testBug553152_005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ) implements I {\n"+ + " public int myInt() throws Exception {;\n" + + " return this.myInt;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public int myInt() throws Exception {;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Throws clause not allowed for explicitly declared accessor method\n" + + "----------\n"); + } + public void testBug553152_006() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public Point(Integer myInt, int myZ) {\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "0"); + } + public void testBug553152_007() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public Point(Integer myInt, int myZ) {\n" + + " this.myInt = 0;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public Point(Integer myInt, int myZ) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The blank final field myZ may not have been initialized\n" + + "----------\n"); + } + public void testBug553152_008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public Point {\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " }\n"+ + " public Point(Integer myInt, int myZ) {\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public Point {\n" + + " ^^^^^\n" + + "Duplicate method Point(Integer, int) in type Point\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " this.myInt = 0;\n" + + " ^^^^^^^^^^\n" + + "Illegal explicit assignment of a final field myInt in compact constructor\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " this.myZ = 0;\n" + + " ^^^^^^^^\n" + + "Illegal explicit assignment of a final field myZ in compact constructor\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " public Point(Integer myInt, int myZ) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate method Point(Integer, int) in type Point\n" + + "----------\n"); + } + public void testBug553152_009() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " Point(Integer myInt, int myZ) {\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "0"); + } + public void testBug553152_010() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public Point(Integer myInt, int myZ) {\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public Point(Integer myInt, int myZ) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Canonical constructor Point of a record declaration should not be generic\n" + + "----------\n"); + } + public void testBug553152_011() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public Point(Integer myInt, int myZ) throws Exception {\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public Point(Integer myInt, int myZ) throws Exception {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Throws clause not allowed for canonical constructor Point\n" + + "----------\n"); + } + public void testBug553152_012() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public Point {\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " return;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " return;\n" + + " ^^^^^^^\n" + + "The body of a compact constructor must not contain a return statement\n" + + "----------\n"); + } + public void testBug553152_013() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public Point(Integer myInt, int myZ) {\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " I i = () -> { return;};\n" + + " Zork();\n" + + " }\n"+ + " public void apply() {}\n" + + "}\n" + + "interface I { void apply();}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type Point\n" + + "----------\n"); + } + public void testBug553152_014() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public Point(Integer myInt, int myZ) {\n" + + " super();\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super();\n" + + " ^^^^^^^^\n" + + "The body of a canonical constructor must not contain an explicit constructor call\n" + + "----------\n"); + } + public void testBug553152_015() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public Point(Integer myInt, int myZ) {\n" + + " this.Point(0);\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " }\n"+ + " public Point(Integer myInt) {}\n" + + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " this.Point(0);\n" + + " ^^^^^\n" + + "The method Point(int) is undefined for the type Point\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " public Point(Integer myInt) {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "A non-canonical constructor must start with an explicit invocation to a constructor\n" + + "----------\n"); + } + public void testBug553152_016() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(Integer myInt, int myZ) implements I {\n"+ + " public Point {\n" + + " super();\n" + + " this.myInt = 0;\n" + + " this.myZ = 0;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " super();\n" + + " ^^^^^^^^\n" + + "The body of a compact constructor must not contain an explicit constructor call\n" + + "----------\n"); + } + public void testBug553152_017() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public class Inner {\n"+ + " record Point(int myInt, char myChar) {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug553152_018() { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) {}\n"+ + " @Target({ElementType.FIELD, ElementType.TYPE})\n"+ + " @interface MyAnnotation {}\n" + }, + "0"); + } + public void testBug553152_019() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, int myZ) implements I {\n"+ + " public static int myInt() {;\n" + + " return 0;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public static int myInt() {;\n" + + " ^^^^^^^\n" + + "The accessor method must not be static\n" + + "----------\n"); + } +public void testBug553153_002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) implements I {\n"+ + " public Point {\n"+ + " this.myInt = myInt;\n" + + " if (this.myInt > 0) // conditional assignment\n" + + " this.myChar = myChar;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " this.myInt = myInt;\n" + + " ^^^^^^^^^^\n" + + "Illegal explicit assignment of a final field myInt in compact constructor\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " if (this.myInt > 0) // conditional assignment\n" + + " ^^^^^\n" + + "The blank final field myInt may not have been initialized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " this.myChar = myChar;\n" + + " ^^^^^^^^^^^\n" + + "Illegal explicit assignment of a final field myChar in compact constructor\n" + + "----------\n"); +} +public void testBug553153_003() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) implements I {\n"+ + " static int f;\n"+ + " public Point {\n"+ + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "0"); +} +public void testBug553153_004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n"+ + "record Point(int myInt, char myChar) implements I {\n"+ + " public Point(int myInt, char myChar) {\n"+ + " this.myInt = myInt;\n" + + " }\n"+ + "}\n" + + "interface I {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public Point(int myInt, char myChar) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The blank final field myChar may not have been initialized\n" + + "----------\n"); +} +public void testBug558069_001() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "private record Point(){\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " private record Point(){\n" + + " ^^^^^\n" + + "Illegal modifier for the record Point; only public, final and strictfp are permitted\n" + + "----------\n"); +} +public void testBug558069_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "private record Point(){\n"+ + "}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0"); +} +public void testBug558069_003() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "private record Point(int myInt){\n"+ + "}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0"); +} +public void testBug558343_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "private record Point(int myInt){\n"+ + " @Override\n"+ + " public boolean equals(Object obj){\n"+ + " return false;\n" + + " }\n"+ + "}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0"); +} +public void testBug558343_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "private record Point(int myInt){\n"+ + " @Override\n"+ + " public int hashCode(){\n"+ + " return java.util.Arrays.hashCode(new int[]{Integer.valueOf(this.myInt).hashCode()});\n" + + " }\n"+ + "}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0"); +} +public void testBug558343_003() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "record Point(int myInt){\n"+ + " @Override\n"+ + " public String toString(){\n"+ + " return \"Point@1\";\n" + + " }\n"+ + "}\n" + }, + "0"); +} +public void testBug558343_004() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(new Point(0).myInt());\n" + + " }\n"+ + "}\n" + + "record Point(int myInt){\n"+ + " @Override\n"+ + " public String toString(){\n"+ + " return \"Point@1\";\n" + + " }\n"+ + "}\n" + }, + "0"); +} +public void testBug558494_001() throws Exception { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(new Point(0).heyPinkCity());\n" + + " }\n"+ + "}\n" + + "record Point(int heyPinkCity){\n"+ + " @Override\n"+ + " public String toString(){\n"+ + " return \"Point@1\";\n" + + " }\n"+ + "}\n" + }, + "0"); + String expectedOutput = "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int heyPinkCity;\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug558494_002() throws Exception { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(new Point().toString());\n" + + " }\n"+ + "}\n" + + "record Point(){\n"+ + " @Override\n"+ + " public String toString(){\n"+ + " return \"Point@1\";\n" + + " }\n"+ + "}\n" + }, + "Point@1"); + String expectedOutput = "Record: #Record\n" + + "Components:\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug558494_003() throws Exception { + runConformTest( + new String[] { + "X.java", + "record Forts(String...wonders){\n"+ + "}\n"+ + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " Forts p = new Forts(new String[] {\"Amber\", \"Nahargarh\", \"Jaigarh\"});\n"+ + " if (!p.toString().startsWith(\"Forts[wonders=[Ljava.lang.String;@\"))\n"+ + " System.out.println(\"Error\");\n"+ + " }\n"+ + "}\n" + }, + ""); + String expectedOutput = "Record: #Record\n" + + "Components:\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Forts.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug558494_004() throws Exception { + runConformTest( + new String[] { + "X.java", + "record Forts(int x, String[] wonders){\n"+ + "}\n"+ + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " Forts p = new Forts(3, new String[] {\"Amber\", \"Nahargarh\", \"Jaigarh\"});\n"+ + " if (!p.toString().startsWith(\"Forts[x=3, wonders=[Ljava.lang.String;@\"))\n"+ + " System.out.println(\"Error\");\n"+ + " }\n"+ + "}\n" + }, + ""); + String expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int x;\n" + + "// Component descriptor #8 [Ljava/lang/String;\n" + + "java.lang.String[] wonders;\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Forts.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug558764_001() { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "record Point(@MyAnnotation int myInt, char myChar) {}\n"+ + " @Target({ElementType.FIELD})\n"+ + " @interface MyAnnotation {}\n" + + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0"); +} +public void testBug558764_002() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "record Point(@MyAnnotation int myInt, char myChar) {}\n"+ + " @Target({ElementType.TYPE})\n"+ + " @interface MyAnnotation {}\n" + + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " record Point(@MyAnnotation int myInt, char myChar) {}\n" + + " ^^^^^^^^^^^^^\n" + + "The annotation @MyAnnotation is disallowed for this location\n" + + "----------\n"); +} +public void testBug558764_003() { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "record Point(@MyAnnotation int myInt, char myChar) {}\n"+ + " @Target({ElementType.RECORD_COMPONENT})\n"+ + " @interface MyAnnotation {}\n" + + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0"); +} +public void testBug558764_004() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "record Point(@MyAnnotation int myInt, char myChar) {}\n"+ + " @Target({ElementType.RECORD_COMPONENT})\n"+ + " @interface MyAnnotation {}\n" + + "class X {\n"+ + " public @MyAnnotation String f = \"hello\";\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " public @MyAnnotation String f = \"hello\";\n" + + " ^^^^^^^^^^^^^\n" + + "The annotation @MyAnnotation is disallowed for this location\n" + + "----------\n"); +} +public void testBug553567_001() { + this.runNegativeTest( + new String[] { + "X.java", + "class X extends Record{\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends Record{\n" + + " ^^^^^^\n" + + "The type X may not subclass Record explicitly\n" + + "----------\n"); +} +public void testBug553567_002() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "class Record {\n"+ + "}\n" + }, + "0"); +} +public void testBug559281_001() { + this.runNegativeTest( + new String[] { + "X.java", + "record X(void k) {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record X(void k) {}\n" + + " ^\n" + + "void is an invalid type for the component k of a record\n" + + "----------\n"); +} +public void testBug559281_002() { + this.runNegativeTest( + new String[] { + "X.java", + "record X(int clone, int wait) {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record X(int clone, int wait) {}\n" + + " ^^^^^\n" + + "Illegal component name clone in record X;\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " record X(int clone, int wait) {}\n" + + " ^^^^\n" + + "Illegal component name wait in record X;\n" + + "----------\n"); +} +public void testBug559448_001() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int x, int... y){\n"+ + "}\n" + }, + "0"); +} +public void testBug559448_002() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int... x, int y){\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " record Point(int... x, int y){\n" + + " ^\n" + + "The variable argument type int of the record Point must be the last parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " record Point(int... x, int y){\n" + + " ^\n" + + "The variable argument type int of the method Point must be the last parameter\n" + + "----------\n"); +} +public void testBug559448_003() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(int... x, int... y){\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " record Point(int... x, int... y){\n" + + " ^\n" + + "The variable argument type int of the record Point must be the last parameter\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " record Point(int... x, int... y){\n" + + " ^\n" + + "The variable argument type int of the method Point must be the last parameter\n" + + "----------\n"); +} +public void testBug559574_001() { + this.runNegativeTest( + new String[] { + "X.java", + "record X(int x, int XX3) {\n"+ + " public XX3 {}\n"+ + " public XX3(int x, int y, int z) {\n"+ + " this.x = x;\n"+ + " this.y = y;\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public XX3 {}\n" + + " ^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public XX3(int x, int y, int z) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " public XX3(int x, int y, int z) {\n" + + " ^\n" + + "The parameter x is hiding a field from type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " this.y = y;\n" + + " ^\n" + + "y cannot be resolved or is not a field\n" + + "----------\n"); +} +public void testBug559992_001() { + this.runNegativeTest( + new String[] { + "X.java", + "record R() {\n"+ + " public R throws Exception {\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public R throws Exception {\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Throws clause not allowed for canonical constructor R\n" + + "----------\n"); +} +public void testBug559992_002() { + this.runNegativeTest( + new String[] { + "X.java", + "record R() {\n"+ + " public R() throws Exception {\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public R() throws Exception {\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Throws clause not allowed for canonical constructor R\n" + + "----------\n"); +} +public void testBug560256_001() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "final protected record Point(int x, int y){\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " final protected record Point(int x, int y){\n" + + " ^^^^^\n" + + "Illegal modifier for the record Point; only public, final and strictfp are permitted\n" + + "----------\n"); +} +public void testBug560256_002() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "native record Point(int x, int y){\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " native record Point(int x, int y){\n" + + " ^^^^^\n" + + "Illegal modifier for the record Point; only public, final and strictfp are permitted\n" + + "----------\n"); +} +public void testBug560256_003() { + this.runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + " class Inner {\n"+ + " record Point(int x, int y){}\n"+ + " }\n" + + "}", + }, + "0"); +} +public void testBug560256_004() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " static class Inner {\n"+ + " native record Point(int x, int y){}\n"+ + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " native record Point(int x, int y){}\n" + + " ^^^^^\n" + + "Illegal modifier for the record Point; only public, private, protected, static, final and strictfp are permitted\n" + + "----------\n"); +} +public void testBug560531_001() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(T t){\n"+ + "}\n" + }, + "0"); +} +public void testBug560531_002() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record R (int x, T t, S s){\n"+ + "}\n" + }, + "0"); +} +public void testBug560569_001() throws Exception { + runConformTest( + new String[] { + "X.java", + "interface Rentable { int year(); }\n"+ + "record Car(String model, int year) implements Rentable {\n"+ + " public Car {\n"+ + " }\n"+ + " public String toString() {\n"+ + " return model + \" \" + year;\n"+ + " }\n"+ + "}\n"+ + "record Camel(int year) implements Rentable { }\n"+ + "\n"+ + "class X {\n"+ + " String model;\n"+ + " int year;\n"+ + " public String toString() {\n"+ + " return model + \" \" + year;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " Car car = new Car(\"Maruti\", 2000);\n"+ + " System.out.println(car.hashCode() != 0);\n"+ + " }\n"+ + "}\n" + }, + "true"); + String expectedOutput = + "Bootstrap methods:\n" + + " 0 : # 69 invokestatic java/lang/runtime/ObjectMethods.bootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/TypeDescriptor;Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/invoke/MethodHandle;)Ljava/lang/Object;\n" + + " Method arguments:\n" + + " #1 Car\n" + + " #70 model;year\n" + + " #72 REF_getField model:Ljava/lang/String;\n" + + " #73 REF_getField year:I\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Car.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = " // Method descriptor #12 (Ljava/lang/String;I)V\n" + + " // Stack: 2, Locals: 3\n" + + " public Car(java.lang.String model, int year);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [14]\n" + + " 4 aload_0 [this]\n" + + " 5 aload_1 [model]\n" + + " 6 putfield Car.model : java.lang.String [17]\n" + + " 9 aload_0 [this]\n" + + " 10 iload_2 [year]\n" + + " 11 putfield Car.year : int [19]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: Car\n" + + " [pc: 0, pc: 15] local: model index: 1 type: java.lang.String\n" + + " [pc: 0, pc: 15] local: year index: 2 type: int\n" + + " Method Parameters:\n" + + " model\n" + + " year\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Car.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug560496_001() throws Exception { + runConformTest( + new String[] { + "X.java", + "record R () {} \n"+ + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new R().hashCode());\n"+ + " }\n"+ + "}\n" + }, + "0"); + String expectedOutput = + "public final int hashCode();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug560496_002() throws Exception { + runConformTest( + new String[] { + "X.java", + "strictfp record R () {} \n"+ + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new R().hashCode());\n"+ + " }\n"+ + "}\n" + }, + "0"); + String expectedOutput = + "public final strictfp int hashCode();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug560797_001() throws Exception { + runConformTest( + new String[] { + "X.java", + "strictfp record R (int x, int y) {} \n"+ + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new R(100, 200).hashCode() != 0);\n"+ + " }\n"+ + "}\n" + }, + "true"); + String expectedOutput = + "public strictfp int x();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug560797_002() throws Exception { + runConformTest( + new String[] { + "X.java", + "strictfp record R (int x, int y) { \n"+ + "public int x() { return this.x;}\n"+ + "}\n"+ + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new R(100, 200).hashCode() != 0);\n"+ + " }\n"+ + "}\n" + }, + "true"); + String expectedOutput = + "public strictfp int x();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug560798_001() throws Exception { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "@Target({ElementType.PARAMETER})\n"+ + "@interface MyAnnot {}\n"+ + "record R(@MyAnnot() int i, int j) {}\n" + + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new R(100, 200).hashCode() != 0);\n"+ + " }\n"+ + "}\n" + }, + "true"); +} +public void testBug560798_002() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "@Target({ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE,\n" + + " ElementType.MODULE, ElementType.PACKAGE, ElementType.TYPE, ElementType.TYPE_PARAMETER})\n"+ + "@interface MyAnnot {}\n"+ + "record R(@MyAnnot() int i, int j) {}\n" + + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " record R(@MyAnnot() int i, int j) {}\n" + + " ^^^^^^^^\n" + + "The annotation @MyAnnot is disallowed for this location\n" + + "----------\n"); +} +public void testBug560798_003() throws Exception { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "@Target({ElementType.METHOD})\n"+ + "@interface MyAnnot {}\n"+ + "record R(@MyAnnot() int i, int j) {}\n" + + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new R(100, 200).hashCode() != 0);\n"+ + " }\n"+ + "}\n" + }, + "true"); +} +public void testBug560798_004() throws Exception { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "@Target({ElementType.RECORD_COMPONENT})\n"+ + "@interface MyAnnot {}\n"+ + "record R(@MyAnnot() int i, int j) {}\n" + + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new R(100, 200).hashCode() != 0);\n"+ + " }\n"+ + "}\n" + }, + "true"); +} +public void testBug560798_005() throws Exception { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n"+ + "import java.lang.annotation.ElementType;\n"+ + "@Target({ElementType.TYPE_USE})\n"+ + "@interface MyAnnot {}\n"+ + "record R(@MyAnnot() int i, int j) {}\n" + + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new R(100, 200).hashCode() != 0);\n"+ + " }\n"+ + "}\n" + }, + "true"); +} +public void testBug560893_001() { + runConformTest( + new String[] { + "X.java", + "interface I{\n"+ + "record R(int x, int y) {}\n"+ + "}\n" + + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n" + }, + "0"); +} +public void testBug560893_002() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " record R(int x, int y) {}\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n" + }, + "0"); +} +public void testBug560893_003() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " record R(int x, int y) {}\n"+ + " R r = new R(100,200);\n"+ + " System.out.println(r.x());\n"+ + " }\n"+ + "}\n" + }, + "100"); +} +public void testBug560893_004() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " record R(int x, int y) {\n"+ + " static int i;\n"+ + " }\n"+ + " R r = new R(100,200);\n"+ + " System.out.println(r.x());\n"+ + " }\n"+ + "}\n" + }, + "100"); +} +public void testBug560893_005() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " record R(int x, int y) {\n"+ + " static int i;\n"+ + " public void ff() {\n"+ + " int jj;\n"+ + " }\n"+ + " static int ii;\n"+ + " }\n"+ + " R r = new R(100,200);\n"+ + " System.out.println(r.x());\n"+ + " }\n"+ + "}\n" + }, + "100"); +} +public void testBug560893_006() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " record R(int x, int y) {}\n"+ + " R r = new R(100,200);\n"+ + " System.out.println(r.x());\n"+ + " }\n"+ + "}\n" + }, + "100"); +} +public void testBug560893_007() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " static int si;\n"+ + " int nsi;\n"+ + "\n"+ + " void m() {\n"+ + " int li;\n"+ + "\n"+ + " record R(int r) {\n"+ + " void print() {\n"+ + " System.out.println(li); // error, local variable\n"+ + " System.out.println(nsi); // error, non-static member\n"+ + " System.out.println(si); // ok, static member of enclosing class\n"+ + " }\n"+ + " }\n"+ + " R r = new R(10);\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " System.out.println(li); // error, local variable\n" + + " ^^\n" + + "Cannot make a static reference to the non-static variable li\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " System.out.println(nsi); // error, non-static member\n" + + " ^^^\n" + + "Cannot make a static reference to the non-static field nsi\n" + + "----------\n"); +} +@SuppressWarnings({ "unchecked", "rawtypes" }) +public void testBug558718_001() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "record R() {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record R() {}\n" + + " ^\n" + + "The Java feature \'Records\' is only available with source level 16 and above\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "unchecked", "rawtypes" }) +public void testBug558718_002() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "record R() {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record R() {}\n" + + " ^\n" + + "The Java feature \'Records\' is only available with source level 16 and above\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "unchecked", "rawtypes" }) +public void testBug558718_003() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "record R() {}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record R() {}\n" + + " ^\n" + + "The Java feature \'Records\' is only available with source level 16 and above\n" + + "----------\n", + null, + true, + options + ); +} +public void testBug56180_001() throws Exception { + runConformTest( + new String[] { + "X.java", + "record R () {} \n"+ + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new R().toString());\n"+ + " }\n"+ + "}\n" + }, + "R[]"); + String expectedOutput = + " public final java.lang.String toString();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug561528_001() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "interface Node {}\n\n"+ + "record R > (N value){\n"+ + "}\n" + }, + "0"); +} +public void testBug561528_002() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "interface Node {}\n\n"+ + "record R > (R parent, N element){\n"+ + "}\n" + }, + "0"); +} +public void testBug561528_003() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "interface Node {}\n\n"+ + "interface AB {}\n\n"+ + "record R >> (N value){\n"+ + "}\n" + }, + "0"); +} +public void testBug561528_004() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "interface Node {}\n\n"+ + "interface AB {}\n\n"+ + "interface CD {}\n\n"+ + "record R >>> (N value){\n"+ + "}\n" + }, + "0"); +} +public void testBug561528_005() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "interface Node {}\n\n"+ + "interface AB {}\n\n"+ + "interface CD {}\n\n"+ + "record R >>>> (N value){\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " record R >>>> (N value){\n" + + " ^^^\n" + + "Syntax error on token \">>>\", >> expected\n" + + "----------\n", + null, + true + ); +} +public void testBug561778_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "XTest.java", + "public class XTest{\n" + + " static T test(X box) {\n" + + " return box.value(); /* */\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n", + "X.java", + "public record X(T value) {\n" + + "}" + }, + "0"); + String expectedOutput = + " // Method descriptor #10 (Ljava/lang/Object;)V\n" + + " // Signature: (TT;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public X(java.lang.Object value);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [13]\n" + + " 4 aload_0 [this]\n" + + " 5 aload_1 [value]\n" + + " 6 putfield X.value : java.lang.Object [16]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " [pc: 0, pc: 10] local: value index: 1 type: java.lang.Object\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " [pc: 0, pc: 10] local: value index: 1 type: T\n" + + " Method Parameters:\n" + + " value\n" + + " \n" + + " // Method descriptor #25 ()Ljava/lang/Object;\n" + + " // Signature: ()TT;\n" + + " // Stack: 1, Locals: 1\n" + + " public java.lang.Object value();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug561778_002() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "XTest.java", + "public class XTest{\n" + + " static Y test(X box) {\n" + + " return box.value(); /* */\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n", + "X.java", + "public record X(Y value) {\n" + + "}\n" + + "class Y {\n" + + "}" + }, + "0"); + String expectedOutput = + " // Method descriptor #25 ()LY;\n" + + " // Signature: ()LY;\n" + + " // Stack: 1, Locals: 1\n" + + " public Y value();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562219_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " @SuppressWarnings(\"unused\")\n"+ + " class Y {\n"+ + " @SuppressWarnings(\"preview\")\n"+ + " class Z {\n"+ + " record R() {\n"+ + " \n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + ""); +} +public void testBug562219_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " @SuppressWarnings(\"unused\")\n"+ + " class Y {\n"+ + " record R() {}\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "" + ); +} +/* + * Test that annotation with implicit target as METHOD are included in the + * generated bytecode on the record component and its accessor method + */ +public void test562250a() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.lang.reflect.*;\n" + + "\n" + + "record Point(@Annot int a) {\n" + + "}\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Annot {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " Class cls = Class.forName(\"Point\");\n" + + " RecordComponent[] recordComponents = cls.getRecordComponents();\n" + + " for (RecordComponent recordComponent : recordComponents) {\n" + + " Annotation[] annotations = recordComponent.getAnnotations();\n" + + " System.out.println(\"RecordComponents:\");\n" + + " for (Annotation annot : annotations) {\n" + + " System.out.println(annot);\n" + + " }\n" + + " Method accessor = recordComponent.getAccessor();\n" + + " System.out.println(\"Accessors:\");\n" + + " annotations =accessor.getAnnotations();\n" + + " for (Annotation annot : annotations) {\n" + + " System.out.println(annot);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "RecordComponents:\n" + + "@Annot()\n" + + "Accessors:\n" + + "@Annot()"); +} +/* + * Test that annotation with explicit target as METHOD are included in the + * generated bytecode on its accessor method (and not on record component) + */ +public void test562250b() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.lang.reflect.*;\n" + + "\n" + + "record Point(@Annot int a) {\n" + + "}\n" + + "@Target({ElementType.METHOD})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Annot {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " Class cls = Class.forName(\"Point\");\n" + + " RecordComponent[] recordComponents = cls.getRecordComponents();\n" + + " for (RecordComponent recordComponent : recordComponents) {\n" + + " Annotation[] annotations = recordComponent.getAnnotations();\n" + + " System.out.println(\"RecordComponents:\");\n" + + " for (Annotation annot : annotations) {\n" + + " System.out.println(annot);\n" + + " }\n" + + " Method accessor = recordComponent.getAccessor();\n" + + " System.out.println(\"Accessors:\");\n" + + " annotations =accessor.getAnnotations();\n" + + " for (Annotation annot : annotations) {\n" + + " System.out.println(annot);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "RecordComponents:\n" + + "Accessors:\n" + + "@Annot()"); +} +/* + * Test that even though annotations with FIELD as a target are permitted by the + * compiler on a record component, the generated bytecode doesn't contain these annotations + * on the record component. + */ +public void test562250c() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import java.lang.reflect.*;\n" + + "\n" + + "record Point(@Annot int a) {\n" + + "}\n" + + "@Target({ElementType.FIELD})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Annot {\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " Class cls = Class.forName(\"Point\");\n" + + " RecordComponent[] recordComponents = cls.getRecordComponents();\n" + + " for (RecordComponent recordComponent : recordComponents) {\n" + + " Annotation[] annotations = recordComponent.getAnnotations();\n" + + " System.out.println(\"RecordComponents:\");\n" + + " for (Annotation annot : annotations) {\n" + + " System.out.println(annot);\n" + + " }\n" + + " Method accessor = recordComponent.getAccessor();\n" + + " System.out.println(\"Accessors:\");\n" + + " annotations =accessor.getAnnotations();\n" + + " for (Annotation annot : annotations) {\n" + + " System.out.println(annot);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "RecordComponents:\n" + + "Accessors:"); +} +public void testBug562439_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RC int myInt, char myChar) { \n"+ + "} \n"+ + "\n"+ + "@Target({ElementType.RECORD_COMPONENT})\n"+ + "@interface RC {}\n" + }, + "100"); + String expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #62 @RC(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_002() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RC int myInt, char myChar) { \n"+ + "} \n"+ + "\n"+ + "@Target({ElementType.RECORD_COMPONENT})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@interface RC {}\n" + }, + "100"); + String expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeVisibleAnnotations: \n" + + " #62 @RC(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_003() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RCF int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.FIELD})\n"+ + "@interface RCF {}\n" + }, + "100"); + String expectedOutput = " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @RCF(\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @RCF(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_004() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RCF int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.FIELD})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface RCF {}\n" + }, + "100"); + String expectedOutput = " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeVisibleAnnotations: \n" + + " #8 @RCF(\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeVisibleAnnotations: \n" + + " #8 @RCF(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_005() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RF int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ElementType.FIELD})\n"+ + "@interface RF {}\n" + }, + "100"); + String expectedOutput = " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @RF(\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + "// Component descriptor #10 C\n" + + "char myChar;\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_006() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RF int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ElementType.FIELD})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface RF {}\n" + }, + "100"); + String expectedOutput = " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeVisibleAnnotations: \n" + + " #8 @RF(\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + "// Component descriptor #10 C\n" + + "char myChar;\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_007() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RCFU int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.FIELD, ElementType.TYPE_USE})\n"+ + "@interface RCFU {}\n" + }, + "100"); + String expectedOutput = " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @RCFU(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @RCFU(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @RCFU(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @RCFU(\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_008() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RCFU int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.FIELD, ElementType.TYPE_USE})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface RCFU {}\n" + }, + "100"); + String expectedOutput = + " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeVisibleAnnotations: \n" + + " #8 @RCFU(\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @RCFU(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeVisibleAnnotations: \n" + + " #8 @RCFU(\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @RCFU(\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_009() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RCM int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.METHOD})\n"+ + "@interface RCM {}\n" + }, + "100"); + String expectedOutput = + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [15]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " RuntimeInvisibleAnnotations: \n" + + " #26 @RCM(\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #26 @RCM(\n" + + " )\n" + + "// Component descriptor #8 C\n" + + "char myChar;\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_010() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RCM int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.METHOD})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface RCM {}\n" + }, + "100"); + String expectedOutput = + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [15]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " RuntimeVisibleAnnotations: \n" + + " #26 @RCM(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeVisibleAnnotations: \n" + + " #26 @RCM(\n" + + " )\n" + + "// Component descriptor #8 C\n" + + "char myChar;\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_011() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@M int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ElementType.METHOD})\n"+ + "@interface M {}\n" + }, + "100"); + String expectedOutput = + " // Method descriptor #24 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [15]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " RuntimeInvisibleAnnotations: \n" + + " #26 @M(\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + "// Component descriptor #8 C\n" + + "char myChar;\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_012() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@M int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ElementType.METHOD})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface M {}\n" + }, + "100"); + String expectedOutput = + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [15]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " RuntimeVisibleAnnotations: \n" + + " #26 @M(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + "// Component descriptor #8 C\n" + + "char myChar;\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_013() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RCMU int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.METHOD, ElementType.TYPE_USE})\n"+ + "@interface RCMU {}\n" + }, + "100"); + String expectedOutput = + " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @RCMU(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " // Method descriptor #26 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [17]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @RCMU(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @RCMU(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @RCMU(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @RCMU(\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_014() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RCMU int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.METHOD, ElementType.TYPE_USE})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface RCMU {}\n" + }, + "100"); + String expectedOutput = + " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @RCMU(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " // Method descriptor #26 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [17]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " RuntimeVisibleAnnotations: \n" + + " #8 @RCMU(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeVisibleAnnotations: \n" + + " #8 @RCMU(\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @RCMU(\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_015() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@T int myInt, char myChar) { \n"+ + "} \n"+ + "\n"+ + "@Target({ElementType.TYPE_USE})\n"+ + "@interface T {}\n" + }, + "100"); + String expectedOutput = + " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " // Method descriptor #26 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [17]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + " "; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " Point(int myInt, char myChar);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [14]\n" + + " 4 aload_0 [this]\n" + + " 5 iload_1 [myInt]\n" + + " 6 putfield Point.myInt : int [17]\n" + + " 9 aload_0 [this]\n" + + " 10 iload_2 [myChar]\n" + + " 11 putfield Point.myChar : char [19]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: Point\n" + + " [pc: 0, pc: 15] local: myInt index: 1 type: int\n" + + " [pc: 0, pc: 15] local: myChar index: 2 type: char\n" + + " Method Parameters:\n" + + " myInt\n" + + " myChar\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_016() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@T int myInt, char myChar) { \n"+ + "} \n"+ + "\n"+ + "@Target({ElementType.TYPE_USE})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@interface T {}\n" + }, + "100"); + String expectedOutput = + " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [17]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + " "; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " Point(int myInt, char myChar);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [14]\n" + + " 4 aload_0 [this]\n" + + " 5 iload_1 [myInt]\n" + + " 6 putfield Point.myInt : int [17]\n" + + " 9 aload_0 [this]\n" + + " 10 iload_2 [myChar]\n" + + " 11 putfield Point.myChar : char [19]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: Point\n" + + " [pc: 0, pc: 15] local: myInt index: 1 type: int\n" + + " [pc: 0, pc: 15] local: myChar index: 2 type: char\n" + + " Method Parameters:\n" + + " myInt\n" + + " myChar\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_017() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RCP int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.PARAMETER})\n"+ + "@interface RCP {}\n" + }, + "100"); + String expectedOutput = + " Point(int myInt, char myChar);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [14]\n" + + " 4 aload_0 [this]\n" + + " 5 iload_1 [myInt]\n" + + " 6 putfield Point.myInt : int [17]\n" + + " 9 aload_0 [this]\n" + + " 10 iload_2 [myChar]\n" + + " 11 putfield Point.myChar : char [19]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: Point\n" + + " [pc: 0, pc: 15] local: myInt index: 1 type: int\n" + + " [pc: 0, pc: 15] local: myChar index: 2 type: char\n" + + " Method Parameters:\n" + + " myInt\n" + + " myChar\n" + + " RuntimeInvisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #12 @RCP(\n" + + " )\n" + + " Number of annotations for parameter 1: 0\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #12 @RCP(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_018() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@RCP int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.PARAMETER})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface RCP {}\n" + }, + "100"); + String expectedOutput = + " Point(int myInt, char myChar);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [14]\n" + + " 4 aload_0 [this]\n" + + " 5 iload_1 [myInt]\n" + + " 6 putfield Point.myInt : int [17]\n" + + " 9 aload_0 [this]\n" + + " 10 iload_2 [myChar]\n" + + " 11 putfield Point.myChar : char [19]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: Point\n" + + " [pc: 0, pc: 15] local: myInt index: 1 type: int\n" + + " [pc: 0, pc: 15] local: myChar index: 2 type: char\n" + + " Method Parameters:\n" + + " myInt\n" + + " myChar\n" + + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #12 @RCP(\n" + + " )\n" + + " Number of annotations for parameter 1: 0\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeVisibleAnnotations: \n" + + " #12 @RCP(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_019() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@Annot int myInt, char myChar) { \n"+ + "} \n"+ + "@interface Annot {}\n" + }, + "100"); + String expectedOutput = + " // Field descriptor #6 I\n" + + " private final int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @Annot(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Annot(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " Point(int myInt, char myChar);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [16]\n" + + " 4 aload_0 [this]\n" + + " 5 iload_1 [myInt]\n" + + " 6 putfield Point.myInt : int [19]\n" + + " 9 aload_0 [this]\n" + + " 10 iload_2 [myChar]\n" + + " 11 putfield Point.myChar : char [21]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: Point\n" + + " [pc: 0, pc: 15] local: myInt index: 1 type: int\n" + + " [pc: 0, pc: 15] local: myChar index: 2 type: char\n" + + " Method Parameters:\n" + + " myInt\n" + + " myChar\n" + + " RuntimeInvisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #8 @Annot(\n" + + " )\n" + + " Number of annotations for parameter 1: 0\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Annot(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " // Method descriptor #28 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [19]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @Annot(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Annot(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @Annot(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Annot(\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug562439_020() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Retention;\n"+ + "import java.lang.annotation.RetentionPolicy;\n"+ + "import java.lang.annotation.Target;\n"+ + " \n"+ + "public class X { \n"+ + " public static void main(String[] args){\n"+ + " Point p = new Point(100, 'a');\n"+ + " System.out.println(p.myInt());\n"+ + " } \n"+ + "}\n"+ + "\n"+ + "record Point(@Annot int myInt, char myChar) { \n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.PARAMETER})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Annot {}\n" + }, + "100"); + String expectedOutput = + " Point(int myInt, char myChar);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [14]\n" + + " 4 aload_0 [this]\n" + + " 5 iload_1 [myInt]\n" + + " 6 putfield Point.myInt : int [17]\n" + + " 9 aload_0 [this]\n" + + " 10 iload_2 [myChar]\n" + + " 11 putfield Point.myChar : char [19]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: this index: 0 type: Point\n" + + " [pc: 0, pc: 15] local: myInt index: 1 type: int\n" + + " [pc: 0, pc: 15] local: myChar index: 2 type: char\n" + + " Method Parameters:\n" + + " myInt\n" + + " myChar\n" + + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #12 @Annot(\n" + + " )\n" + + " Number of annotations for parameter 1: 0\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "Record: #Record\n" + + "Components:\n" + + " \n" + + "// Component descriptor #6 I\n" + + "int myInt;\n" + + " RuntimeVisibleAnnotations: \n" + + " #12 @Annot(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug563178_001() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "record Point(final int x, int y){\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " record Point(final int x, int y){\n" + + " ^\n" + + "A record component x cannot have modifiers\n" + + "----------\n"); +} +public void testBug563183_001() { + this.runConformTest( + new String[] { + "X.java", + "public record X() {\n"+ + " public X() {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_002() { + this.runConformTest( + new String[] { + "X.java", + "public record X() {\n"+ + " public X {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_003() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X() {\n"+ + " protected X() {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " protected X() {}\n" + + " ^^^\n" + + "Cannot reduce the visibility of a canonical constructor X from that of the record\n" + + "----------\n"); +} +public void testBug563183_004() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X() {\n"+ + " protected X {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " protected X {}\n" + + " ^\n" + + "Cannot reduce the visibility of a canonical constructor X from that of the record\n" + + "----------\n"); +} +public void testBug563183_005() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X() {\n"+ + " /*package */ X() {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " /*package */ X() {}\n" + + " ^^^\n" + + "Cannot reduce the visibility of a canonical constructor X from that of the record\n" + + "----------\n"); +} +public void testBug563183_006() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X() {\n"+ + " /*package */ X {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " /*package */ X {}\n" + + " ^\n" + + "Cannot reduce the visibility of a canonical constructor X from that of the record\n" + + "----------\n"); +} +public void testBug563183_007() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X() {\n"+ + " private X() {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private X() {}\n" + + " ^^^\n" + + "Cannot reduce the visibility of a canonical constructor X from that of the record\n" + + "----------\n"); +} +public void testBug563183_008() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X() {\n"+ + " private X {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private X {}\n" + + " ^\n" + + "Cannot reduce the visibility of a canonical constructor X from that of the record\n" + + "----------\n"); +} +public void testBug563183_009() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " protected record R() {\n"+ + " public R() {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_010() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " protected record R() {\n"+ + " public R {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_011() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " protected record R() {\n"+ + " protected R() {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_012() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " protected record R() {\n"+ + " protected R {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_013() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " protected record R() {\n"+ + " /*package */ R() {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " /*package */ R() {}\n" + + " ^^^\n" + + "Cannot reduce the visibility of a canonical constructor R from that of the record\n" + + "----------\n"); +} +public void testBug563183_014() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " protected record R() {\n"+ + " /*package */ R {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " /*package */ R {}\n" + + " ^\n" + + "Cannot reduce the visibility of a canonical constructor R from that of the record\n" + + "----------\n"); +} +public void testBug563183_015() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " protected record R() {\n"+ + " private R() {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private R() {}\n" + + " ^^^\n" + + "Cannot reduce the visibility of a canonical constructor R from that of the record\n" + + "----------\n"); +} +public void testBug563183_016() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " protected record R() {\n"+ + " private R {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private R {}\n" + + " ^\n" + + "Cannot reduce the visibility of a canonical constructor R from that of the record\n" + + "----------\n"); +} +public void testBug563183_017() { + this.runConformTest( + new String[] { + "X.java", + "/*package */ record X() {\n"+ + " public X() {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_018() { + this.runConformTest( + new String[] { + "X.java", + "/*package */ record X() {\n"+ + " public X {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_019() { + this.runConformTest( + new String[] { + "X.java", + "record X() {\n"+ + " protected X() {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_020() { + this.runConformTest( + new String[] { + "X.java", + "record X() {\n"+ + " protected X {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_021() { + this.runConformTest( + new String[] { + "X.java", + " record X() {\n"+ + " /*package */ X() {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_022() { + this.runConformTest( + new String[] { + "X.java", + " record X() {\n"+ + " /*package */ X {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_023() { + this.runNegativeTest( + new String[] { + "X.java", + "record X() {\n"+ + " private X() {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private X() {}\n" + + " ^^^\n" + + "Cannot reduce the visibility of a canonical constructor X from that of the record\n" + + "----------\n"); +} +public void testBug563183_024() { + this.runNegativeTest( + new String[] { + "X.java", + "record X() {\n"+ + " private X {}\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private X {}\n" + + " ^\n" + + "Cannot reduce the visibility of a canonical constructor X from that of the record\n" + + "----------\n"); +} +public void testBug563183_025() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private record R() {\n"+ + " public R() {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_026() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private record R() {\n"+ + " protected R {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_027() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private record R() {\n"+ + " /* package */ R() {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563183_028() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private record R() {\n"+ + " private R {}\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug563184_001() { + this.runNegativeTest( + new String[] { + "X.java", + "record X(int angel) {\n"+ + " X(int devil) {\n"+ + " this.angel = devil;\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X(int devil) {\n" + + " ^^^^^\n" + + "Illegal parameter name devil in canonical constructor, expected angel, the corresponding component name\n" + + "----------\n"); +} +public void testBug563184_002() { + this.runConformTest( + new String[] { + "X.java", + "record X(int myInt) {\n"+ + " X(int myInt) {\n"+ + " this.myInt = myInt;\n" + + " }\n"+ + " X(int i, int j) {\n"+ + " this(i);\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); +} +public void testBug562637_001() { + this.runConformTest( + new String[] { + "X.java", + "public record X(int i) {\n"+ + " public X {\n"+ + " i = i/2;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new X(10).i());\n"+ + " }\n"+ + "}", + }, + "5"); +} + public void testBug563181_01() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + "public class X { \n"+ + " public static void main(String[] args){}\n"+ + "}\n"+ + "record Point(@RCMU int myInt, char myChar) { \n"+ + " public int myInt(){\n"+ + " return this.myInt;\n" + + " }\n"+ + "} \n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.METHOD, ElementType.TYPE_USE})\n"+ + "@interface RCMU {}\n" + }, + ""); + String expectedOutput = + " // Method descriptor #26 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [17]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: Point\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug563181_02() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n"+ + "import java.lang.annotation.Target;\n"+ + "public class X { \n"+ + " public static void main(String[] args){}\n"+ + "}\n"+ + "record Point(@RCMU int myInt, char myChar) {\n"+ + " @RCMU public int myInt(){\n"+ + " return this.myInt;\n" + + " }\n"+ + "}\n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.METHOD, ElementType.TYPE_USE})\n"+ + "@interface RCMU {}\n" + }, + ""); + String expectedOutput = + " // Method descriptor #26 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [17]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: Point\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @RCMU(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @RCMU(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug563181_03() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n"+ + "public class X { \n"+ + " public static void main(String[] args){}\n"+ + "}\n"+ + "record Point(@TypeAnnot @SimpleAnnot int myInt, char myChar) {}\n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.METHOD})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface SimpleAnnot {}\n" + + "@Target({ ElementType.RECORD_COMPONENT, ElementType.TYPE_USE})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface TypeAnnot {}\n" + }, + ""); + String expectedOutput = + " // Method descriptor #26 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [17]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " RuntimeVisibleAnnotations: \n" + + " #28 @SimpleAnnot(\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @TypeAnnot(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug563181_04() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n"+ + "public class X { \n"+ + " public static void main(String[] args){}\n"+ + "}\n"+ + "record Point(@TypeAnnot @SimpleAnnot int myInt, char myChar) {\n"+ + " @TypeAnnot @SimpleAnnot public int myInt(){\n"+ + " return this.myInt;\n" + + " }\n"+ + "}\n"+ + "@Target({ ElementType.RECORD_COMPONENT, ElementType.METHOD})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface SimpleAnnot {}\n" + + "@Target({ ElementType.RECORD_COMPONENT, ElementType.TYPE_USE})\n"+ + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface TypeAnnot {}\n" + }, + ""); + String expectedOutput = + " // Method descriptor #26 ()I\n" + + " // Stack: 1, Locals: 1\n" + + " public int myInt();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield Point.myInt : int [17]\n" + + " 4 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: Point\n" + + " RuntimeVisibleAnnotations: \n" + + " #28 @SimpleAnnot(\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @TypeAnnot(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + " \n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "Point.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug565104_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public record R() {}\n"+ + " public static void main(String[] args){}\n"+ + "}\n" + }, + ""); + String expectedOutput = + " // Stack: 1, Locals: 1\n" + + " public X$R();\n" + + " 0 aload_0 [this]\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X$R.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug565104_002() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " record R() {}\n"+ + " public static void main(String[] args){}\n"+ + "}\n" + }, + ""); + String expectedOutput = + " // Stack: 1, Locals: 1\n" + + " X$R();\n" + + " 0 aload_0 [this]\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X$R.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug565104_003() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " protected record R() {}\n"+ + " public static void main(String[] args){}\n"+ + "}\n" + }, + ""); + String expectedOutput = + " // Stack: 1, Locals: 1\n" + + " protected X$R();\n" + + " 0 aload_0 [this]\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X$R.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug565104_004() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " private record R() {}\n"+ + " public static void main(String[] args){}\n"+ + "}\n" + }, + ""); + String expectedOutput = + " // Stack: 1, Locals: 1\n" + + " private X$R();\n" + + " 0 aload_0 [this]\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X$R.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug564146_001() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X(int i) {\n"+ + " public X() {\n"+ + " this.i = 10;\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public X() {\n" + + " ^^^\n" + + "A non-canonical constructor must start with an explicit invocation to a constructor\n" + + "----------\n"); + } + public void testBug564146_002() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X(int i) {\n"+ + " public X() {\n"+ + " super();\n"+ + " this.i = 10;\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public X() {\n" + + " ^^^\n" + + "A non-canonical constructor must start with an explicit invocation to a constructor\n" + + "----------\n"); + } + public void testBug564146_003() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X(int i) {\n"+ + " public X(int i) {\n"+ + " this.i = 10;\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug564146_004() { + runConformTest( + new String[] { + "X.java", + "public record X(int i) {\n"+ + " public X() {\n"+ + " this(10);\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new X().i());\n"+ + " }\n"+ + "}" + }, + "10"); + } + public void testBug564146_005() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X() {\n"+ + " public X(int i) {\n"+ + " this(10);\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " this(10);\n" + + " ^^^^^^^^^\n" + + "Recursive constructor invocation X(int)\n" + + "----------\n"); + } + public void testBug564146_006() { + this.runNegativeTest( + new String[] { + "X.java", + "public record X() {\n"+ + " public X() {\n"+ + " System.out.println(10);\n"+ + " this(10);\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " this(10);\n" + + " ^^^^^^^^^\n" + + "The body of a canonical constructor must not contain an explicit constructor call\n" + + "----------\n"); + } + public void testBug564146_007() { + runConformTest( + new String[] { + "X.java", + "public record X(int i) {\n"+ + " public X() {\n"+ + " this(10);\n"+ + " }\n"+ + " public X(int i, int k) {\n"+ + " this();\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new X(2, 3).i());\n"+ + " }\n"+ + "}" + }, + "10"); + } + +public void testBug564672_001() { + this.runNegativeTest( + new String[] { + "X.java", + "class X extends record {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "class record {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class record {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_002() { + this.runNegativeTest( + new String[] { + "X.java", + "class X extends record {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_003() { + this.runNegativeTest( + new String[] { + "X.java", + "class X implements record {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "interface record {}\n;" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X implements record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " interface record {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_004() { + this.runNegativeTest( + new String[] { + "X.java", + "class X implements record {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X implements record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_005() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " class Y extends record {\n"+ + " }\n" + + " class record {}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " class record {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_006() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " class Y extends record {\n"+ + " }\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_007() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " class Y implements record {\n"+ + " }\n" + + " interface record {}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y implements record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " interface record {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_008() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " class Y implements record {\n"+ + " }\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y implements record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_009() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Y extends record {\n"+ + "}\n" + + "interface record {}\n" + + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " interface record {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_010() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Y extends record {\n"+ + "}\n" + + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_011() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " interface Y extends record {\n"+ + " }\n" + + " interface record {}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " interface Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " interface record {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_012() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " interface Y extends record {\n"+ + " }\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " interface Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_013() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n"+ + " class Y extends record {\n"+ + " }\n" + + " class record {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " class record {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_014() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n"+ + " class Y extends record {\n"+ + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_015() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n"+ + " class Y implements record {\n"+ + " }\n" + + " interface record {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y implements record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " interface record {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_016() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n"+ + " class Y implements record {\n"+ + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y implements record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_017() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n"+ + " interface Y extends record {\n"+ + " }\n" + + " interface record {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " interface Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " interface record {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_018() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n"+ + " interface Y extends record {\n"+ + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " interface Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_019() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static record a(int i, int j) {\n" + + " record r=new record(i,j);\n" + + " return r;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " record r=new record(i,j);\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " record r=new record(i,j);\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " return r;\n" + + " ^^^^^^\n" + + "Syntax error on token \"return\", byte expected\n" + + "----------\n"); +} +public void testBug564672_020() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " class record {};\n" + + " static record a(int i, int j) {\n" + + " record r=new record();\n" + + " return r;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class record {};\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " record r=new record();\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " record r=new record();\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " return r;\n" + + " ^^^^^^\n" + + "Syntax error on token \"return\", byte expected\n" + + "----------\n"); +} +public void testBug564672_021() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface IPoint {\n" + + " }\n" + + " record Point(int x, int y) implements IPoint {}\n" + + " static IPoint a(int i, int j) {\n" + + " Point record=new Point(i,j);\n" + + " return record;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(a(5,10));\n" + + " }\n" + + "}\n" + }, + "Point[x=5, y=10]"); +} +public void testBug564672_022() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " record R(int i){} \n" + + " interface IPoint {\n" + + " record a(int i) {\n" + + " System.out.println(0);\n" + + " return new R(i);\n" + + " }\n" + + " }\n" + + " record Point(int x, int y) implements IPoint {}\n" + + " static IPoint a(int i, int j) {\n" + + " Point record=new Point(i,j);\n" + + " record.a(1);\n" + + " return record;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " System.out.println(0);\n" + + " ^\n" + + "Syntax error on token \".\", @ expected after this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " System.out.println(0);\n" + + " return new R(i);\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " return new R(i);\n" + + " ^\n" + + "Syntax error, insert \")\" to complete SingleMemberAnnotation\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " return new R(i);\n" + + " ^\n" + + "Syntax error, insert \"SimpleName\" to complete QualifiedName\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " return new R(i);\n" + + " ^\n" + + "Syntax error, insert \"Identifier (\" to complete MethodHeaderName\n" + + "----------\n" + + "6. ERROR in X.java (at line 6)\n" + + " return new R(i);\n" + + " ^\n" + + "Syntax error, insert \")\" to complete MethodDeclaration\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " record.a(1);\n" + + " ^\n" + + "The method a(int) is undefined for the type X.Point\n" + + "----------\n"); +} +public void testBug564672_023() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " interface IPoint {\n" + + " }\n" + + " record Point(int x, int y) implements IPoint {}\n" + + " static IPoint a(int i, int j) throws record{\n" + + " Point record=new Point(i,j);\n" + + " return record;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " static IPoint a(int i, int j) throws record{\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_024() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X() throws record {} \n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X() throws record {} \n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_025() { + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n" + + " int a() throws record; \n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int a() throws record; \n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_026() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;" + + "public class X {\n" + + " List R = new List();\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " List R = new List();\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " List R = new List();\n" + + " ^^^^\n" + + "Cannot instantiate the type List\n" + + "----------\n" + + "3. ERROR in X.java (at line 2)\n" + + " List R = new List();\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_027() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " void print(S arg);\n" + + "}\n" + + "public class X implements I{\n" + + " void print(record arg){\n" + + " System.out.println(arg);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public class X implements I{\n" + + " ^\n" + + "The type X must implement the inherited abstract method I.print(record)\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public class X implements I{\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " void print(record arg){\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_028() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " void equal(record R) {}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class Y {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " void equal(record R) {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_029() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " Y(record R) {}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class Y {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " Y(record R) {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_030() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static record i= 0;\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " static record i= 0;\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_031() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " record i=0;\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " record i=0;\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_032() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static int sum(record i, int param){\n" + + " return 1;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " static int sum(record i, int param){\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_033() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " X(record i, int param){\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " X(record i, int param){\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_034() { + this.runNegativeTest( + new String[] { + "X.java", + "interface I {\n" + + " int sum(record i, int num);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int sum(record i, int num);\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_035() { + this.runConformTest( + new String[] { + "X.java", + "interface Greetings {\n" + + " void greet(String head, String tail);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Greetings g = (record, y) -> {\n" + + " System.out.println(record + y);\n" + + " };\n" + + " g.greet(\"Hello, \", \"World!\");\n" + + " }\n" + + "}\n", + }, + "Hello, World!" + ); +} +public void testBug564672_036() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " int sum(record this, int i, int num) {}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int sum(record this, int i, int num) {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_037() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static record i;\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " static record i;\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_038() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " for (record i = 0; i<10; i++) {\n" + + " System.out.println(0);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (record i = 0; i<10; i++) {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_039() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int rec[] = {1,2,3,4,5,6,7,8,9};\n" + + " for (record i: rec) {\n" + + " System.out.println(0);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " for (record i: rec) {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " for (record i: rec) {\n" + + " ^^^\n" + + "Type mismatch: cannot convert from element type int to record\n" + + "----------\n"); +} +public void testBug564672_040() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try (record i = 0){\n" + + " }\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (record i = 0){\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_041() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try{\n" + + " }\n" + + " catch (record e) {}\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " catch (record e) {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_042() { + this.runNegativeTest( + new String[] { + "X.java", + "record Point(record x, int i) { }\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record Point(record x, int i) { }\n" + + " ^\n" + + "record cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " record Point(record x, int i) { }\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_043() { + this.runNegativeTest( + new String[] { + "X.java", + "class Point {\n" + + " Point(T i) {\n" + + " }\n" + + " Point (int i, int j) {\n" + + " this(null);\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " this(null);\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " this(null);\n" + + " ^^^^^^^^^^^\n" + + "The constructor Point(record) refers to the missing type record\n" + + "----------\n"); +} +public void testBug564672_044() { + this.runNegativeTest( + new String[] { + "X.java", + "class Point {\n" + + " Point(T i) {\n" + + " }\n" + + "}\n" + + "class PointEx extends Point {\n" + + " PointEx (int i, int j) {\n" + + " super(null);\n" + + " }\n;" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " super(null);\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " super(null);\n" + + " ^^^^^^^^^^^^\n" + + "The constructor Point(record) refers to the missing type record\n" + + "----------\n"); +} +public void testBug564672_045() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y {\n" + + " void m1() {} \n" + + " void m2() {\n" + + " this.m1();" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " this.m1(); }\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " this.m1(); }\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method m1() of type Y; it should not be parameterized with arguments \n" + + "----------\n"); +} +public void testBug564672_046() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y{\n" + + " void a() {\n" + + " System.out.println(\"1\");\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Y().a();\n" + + " System.out.println(0);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " new Y().a();\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. WARNING in X.java (at line 8)\n" + + " new Y().a();\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor Y() of type Y; it should not be parameterized with arguments \n" + + "----------\n"); +} +public void testBug564672_047() { + this.runNegativeTest( + new String[] { + "X.java", + "interface Y{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Y() {\n" + + " void a() {\n" + + " System.out.println(\"1\");\n" + + " }\n" + + " }.a();\n" + + " System.out.println(0);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new Y() {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " new Y() {\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor Object() of type Object; it should not be parameterized with arguments \n" + + "----------\n"); +} +public void testBug564672_048() { + this.runNegativeTest( + new String[] { + "X.java", + "class Y{}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Y() {\n" + + " void a() {\n" + + " System.out.println(\"1\");\n" + + " }\n" + + " }.a();\n" + + " System.out.println(0);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new Y() {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " new Y() {\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic constructor Y() of type Y; it should not be parameterized with arguments \n" + + "----------\n"); +} +public void testBug564672_049() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " record[] y= new record[3]; \n" + + " System.out.println(0);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " record[] y= new record[3]; \n" + + " ^^^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " record[] y= new record[3]; \n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_050() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s=\"Hello\";\n" + + " record y= (record)s; \n" + + " System.out.println(0);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " record y= (record)s; \n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " record y= (record)s; \n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_051() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String s=\"Hello\";\n" + + " if (s instanceof record) { \n" + + " System.out.println(1);\n" + + " }\n" + + " System.out.println(0);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (s instanceof record) { \n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +public void testBug564672_052() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List messages = Arrays.asList(\"hello\", \"java\", \"testers!\");\n" + + " messages.forEach(record::length);\n" + + " System.out.println(0);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " messages.forEach(record::length);\n" + + " ^^^^^^\n" + + "record cannot be resolved\n" + + "----------\n"); +} +public void testBug564672_053() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List messages = Arrays.asList(\"hello\", \"java\", \"testers!\");\n" + + " messages.stream().map(record::new).toArray(record[]::new);\n" + + " System.out.println(0);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " messages.stream().map(record::new).toArray(record[]::new);\n" + + " ^^^^^^\n" + + "record cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " messages.stream().map(record::new).toArray(record[]::new);\n" + + " ^^^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n"); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_001() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class X extends record {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "class record {}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_002() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X extends record {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_003() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class X implements record {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n"+ + "interface record {}\n;" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_004() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X implements record {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X implements record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_005() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " class Y extends record {\n"+ + " }\n" + + " class record {}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_006() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " class Y extends record {\n"+ + " }\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_007() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " class Y implements record {\n"+ + " }\n" + + " interface record {}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_008() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " class Y implements record {\n"+ + " }\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y implements record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_009() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "interface Y extends record {\n"+ + "}\n" + + "interface record {}\n" + + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_010() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "interface Y extends record {\n"+ + "}\n" + + "class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_011() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " interface Y extends record {\n"+ + " }\n" + + " interface record {}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_012() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " interface Y extends record {\n"+ + " }\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " interface Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_013() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "interface Z {\n"+ + " class Y extends record {\n"+ + " }\n" + + " class record {}\n" + + "}\n" + + "class X {\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_014() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n"+ + " class Y extends record {\n"+ + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_015() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "interface Z {\n"+ + " class Y implements record {\n"+ + " }\n" + + " interface record {}\n" + + "}\n" + + "class X {\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_016() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n"+ + " class Y implements record {\n"+ + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class Y implements record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_017() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "interface Z {\n"+ + " interface Y extends record {\n"+ + " }\n" + + " interface record {}\n" + + "}\n" + + "class X {\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_018() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "interface X {\n"+ + " interface Y extends record {\n"+ + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " interface Y extends record {\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_019() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static record a(int i, int j) {\n" + + " record r=new record(i,j);\n" + + " return r;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " record r=new record(i,j);\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " record r=new record(i,j);\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " return r;\n" + + " ^^^^^^\n" + + "Syntax error on token \"return\", byte expected\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_020() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " class record {}\n" + + "\n" + + " static record a(int i, int j) {\n" + + " record r = new X().new record();\n" + + " return r;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_021() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X() throws record {} \n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "\n" + + "class record extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_022() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "interface Y {\n" + + " int a() throws record;\n" + + "}\n" + + "\n" + + "class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "\n" + + "class record extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_023() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " List R = new ArrayList();\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record{}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_024() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " void print(S arg);\n" + + "}\n" + + "\n" + + "public class X implements I {\n" + + " public void print(record arg) {\n" + + " System.out.println(arg);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record {\n" + + "}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_025() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class Y {\n" + + " void equal(record R) {}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_026() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class Y {\n" + + " Y(record R) {}\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_027() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static record i;\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record {}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_028() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " record i = new record(0);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record {\n" + + " int i;\n" + + " record (int i) {\n" + + " this.i=i;\n" + + " }\n" + + "}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_029() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int sum(record i, int param) {\n" + + " return 1;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record{}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_030() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X(record i, int param){\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record{}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_031() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "interface I {\n" + + " int sum(record i, int num);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record{}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_032() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "interface Greetings {\n" + + " void greet(String head, String tail);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Greetings g = (record, y) -> {\n" + + " System.out.println(record + y);\n" + + " };\n" + + " g.greet(\"Hello, \", \"World!\");\n" + + " }\n" + + "}\n", + }, + "Hello, World!", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_033() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "\n" + + "class record {\n" + + " int sum(record this, int i, int num) {\n" + + " return 0;\n" + + " }\n" + + "}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_034() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static Rec record;\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class Rec {}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_035() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int rec[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + " String s=\"\";\n" + + " List recList= new ArrayList<>();\n" + + " for (int i:rec) {\n" + + " recList.add(new record(i));\n" + + " }\n" + + " for (Iterator i =recList.iterator(); i.hasNext();) {\n" + + " s=s+i.next()+\" \";\n" + + " }\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "\n" + + "class record {\n" + + " int i;\n" + + " record (int i) {\n" + + " this.i=i;\n" + + " }\n" + + " public String toString (){\n" + + " return Integer.toString(i);\n" + + " }\n" + + "}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_036() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int rec[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + " String s=\"\";\n" + + " List recList= new ArrayList<>();\n" + + " for (int i:rec) {\n" + + " recList.add(new record(i));\n" + + " }\n" + + " for (record i : recList) {\n" + + " s=s+i+\" \";\n" + + " }\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "\n" + + "class record {\n" + + " int i;\n" + + " record (int i) {\n" + + " this.i=i;\n" + + " }\n" + + " public String toString (){\n" + + " return Integer.toString(i);\n" + + " }\n" + + "}\n" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_037() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try (record i = new record (0)){\n" + + " } catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record implements AutoCloseable{\n" + + " int i;\n" + + " record (int i) {\n" + + " this.i=i;\n" + + " }\n" + + " @Override\n" + + " public void close() throws Exception {}\n" + + "}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_038() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new record();\n" + + " } catch (record e) {\n" + + " System.out.println(\"0\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class record extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_039() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "record Point(record x, int i) { }\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record Point(record x, int i) { }\n" + + " ^^^^^^\n" + + "'record' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " class record {}\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n", + null, + true, + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_040() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class Point {\n" + + " Point(T i) {\n" + + " }\n" + + " Point (int i, int j) {\n" + + " this(null);\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record {}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_041() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class Point {\n" + + " Point(T i) {\n" + + " }\n" + + "}\n" + + "class PointEx extends Point {\n" + + " PointEx (int i, int j) {\n" + + " super(null);\n" + + " }\n;" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record {}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_042() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class Y {\n" + + " void m1() {} \n" + + " void m2() {\n" + + " this.m1();" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record {}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_043() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class Y{\n" + + " Y() {}\n" + + " void a() {\n" + + " System.out.println(\"1\");\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Y().a();\n" + + " }\n" + + "}\n" + + "class record {}" + }, + "1", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_044() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "interface Y{\n" + + "}\n" + + "\n" + + "class Z implements Y {\n" + + " Z() {\n" + + " \n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Z() {\n" + + " void a() {\n" + + " System.out.println(\"1\");\n" + + " }\n" + + " }.a();\n" + + " }\n" + + "}\n" + + "class record {}" + }, + "1", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_045() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "class Y{" + + " Y() {\n" + + " }" + + "}\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new Y() {\n" + + " void a() {\n" + + " System.out.println(\"1\");\n" + + " }\n" + + " }.a();\n" + + " }\n" + + "}\n" + + "class record {}" + }, + "1", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_046() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " record[] y= new record[3]; \n" + + " System.out.println(0);\n" + + " }\n" + + "}" + + "class record {}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_047() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " StrRec s = new StrRec(\"Hello\");\n" + + " record y = (record) s;\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "\n" + + "class record {\n" + + "}\n" + + "\n" + + "class StrRec extends record {\n" + + " String s;\n" + + "\n" + + " StrRec(String s) {\n" + + " this.s = s;\n" + + " }\n" + + "}" + }, + "0", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_048() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " StrRec s=new StrRec(\"Hello\");\n" + + " if (s instanceof record) { \n" + + " System.out.println(1);\n" + + " }\n" + + " }\n" + + "}\n" + + "class record {}\n" + + "\n" + + "class StrRec extends record {\n" + + " String s;\n" + + "\n" + + " StrRec(String s) {\n" + + " this.s = s;\n" + + " }\n" + + "}" + }, + "1", + options + ); +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +public void testBug564672b_049() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " List messages = Arrays.asList(\"hello\", \"java\", \"testers!\");\n" + + " \n" + + " messages.stream().map(record::new).toArray(record[]::new);;\n" + + " System.out.println(0);\n" + + " }\n" + + "}\n" + + "class record {\n" + + " String s;\n" + + "\n" + + " record(String s) {\n" + + " this.s = s;\n" + + " }\n" + + "}" + }, + "0", + options + ); +} +public void testBug565388_001() { + if (this.complianceLevel < ClassFileConstants.JDK17) return; + Map options = getCompilerOptionsWithPreview(); + this.runNegativeTest( + new String[] { + "X.java", + "public non-sealed record X() {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public non-sealed record X() {}\n" + + " ^\n" + + "Illegal modifier for the record X; only public, final and strictfp are permitted\n" + + "----------\n", + null, + true, + options + ); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); +} +public void testBug565388_002() { + if (this.complianceLevel < ClassFileConstants.JDK17) return; + Map options = getCompilerOptionsWithPreview(); + this.runNegativeTest( + new String[] { + "X.java", + "public sealed record X() {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public sealed record X() {}\n" + + " ^\n" + + "Illegal modifier for the record X; only public, final and strictfp are permitted\n" + + "----------\n", + null, + true, + options + ); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); +} +public void testBug565786_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n"+ + "interface I {\n"+ + " record R() {}\n"+ + "}", + }, + "0"); + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public I$R();\n"; + verifyClassFile(expectedOutput, "I$R.class", ClassFileBytesDisassembler.SYSTEM); +} +// Test that without an explicit canonical constructor, we +// report the warning on the record type. +public void testBug563182_01() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " record Point (T ... args) { // 1\n" + + " }\n" + + " public static void main(String[] args) {}\n"+ + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " record Point (T ... args) { // 1\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter args\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + customOptions); +} +//Test that in presence of an explicit canonical constructor that is NOT annotated with @SafeVarargs, +// we don't report the warning on the record type but report on the explicit canonical constructor +public void testBug563182_02() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " record Point (T ... args) { // 1\n" + + " Point(T ... args) { // 2\n" + + " this.args = args;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {}\n"+ + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Point(T ... args) { // 2\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter args\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + customOptions); +} +//Test that in presence of an explicit canonical constructor that IS annotated with @SafeVarargs, +//we don't report the warning on neither the record type nor the explicit canonical constructor +public void testBug563182_03() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " record Point (T ... args) { // 1\n" + + " @SafeVarargs\n" + + " Point(T ... args) { // 2\n" + + " this.args = args;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {}\n"+ + "}\n", + }, + "", + null, + true, + new String[] {"--enable-preview"}, + customOptions); +} +//Test that in presence of a compact canonical constructor that is NOT annotated with @SafeVarargs, +//we don't report the warning on the compact canonical constructor but report on the record type +public void testBug563182_04() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " record Point (T ... args) { // 1\n" + + " Point { // 2\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {}\n"+ + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " record Point (T ... args) { // 1\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter args\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + customOptions); +} +//Test that in presence of a compact canonical constructor that IS annotated with @SafeVarargs, +//we don't report the warning on neither the record type nor the compact canonical constructor +public void testBug563182_05() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " record Point (T ... args) { // 1\n" + + " @SafeVarargs\n" + + " Point { // 2\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {}\n"+ + "}\n", + }, + "", + null, + true, + new String[] {"--enable-preview"}, + customOptions); +} +//Test that in presence of a non-canonical constructor that is annotated with @SafeVarargs, +//we don't report the warning on the non-canonical constructor but report on the record type +public void testBug563182_06() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " record Point (T ... args) { // 1\n" + + " @SafeVarargs\n" + + " Point (String s, T ... t) {\n" + + " this(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {}\n"+ + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " record Point (T ... args) { // 1\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter args\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + customOptions); +} +//Test that in presence of a non-canonical constructor that is NOT annotated with @SafeVarargs, +//we don't report the warning on the non-canonical constructor but report on the record type +public void testBug563182_07() { + Map customOptions = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " record Point (T ... args) { // 1\n" + + " Point (String s, T ... t) {\n" + + " this(t);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {}\n"+ + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " record Point (T ... args) { // 1\n" + + " ^^^^\n" + + "Type safety: Potential heap pollution via varargs parameter args\n" + + "----------\n" + + "2. WARNING in X.java (at line 3)\n" + + " Point (String s, T ... t) {\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter t\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + customOptions); +} + public void testBug563186_01() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private record Point(int myInt){\n"+ + " @Override\n" + + " public int myInt(){\n"+ + " return this.myInt;\n" + + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug563186_02() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private record Point(int myInt){\n"+ + " public int myInt(){\n"+ + " return this.myInt;\n" + + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug563186_03() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private record Point(int myInt){\n"+ + " @Override\n" + + " public int myInt(int i){\n"+ + " return this.myInt;\n" + + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " private record Point(int myInt){\n" + + " ^^^^^\n" + + "The type X.Point is never used locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " public int myInt(int i){\n" + + " ^^^^^^^^^^^^\n" + + "The method myInt(int) of type X.Point must override or implement a supertype method\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + getCompilerOptions()); + } + public void testBug563186_04() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private record Point(int myInt){\n"+ + " public int myInt(int i){\n"+ + " return this.myInt;\n" + + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug565732_01() { + runNegativeTest( + new String[] { + "X.java", + "public record X {\n" + + "} " + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public record X {\n" + + " ^\n" + + "Syntax error, insert \"RecordHeader\" to complete RecordHeaderPart\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + getCompilerOptions()); + } + public void testBug565732_02() { + runNegativeTest( + new String[] { + "X.java", + "public record X {\n" + + "} " + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public record X {\n" + + " ^\n" + + "Syntax error, insert \"RecordHeader\" to complete RecordHeaderPart\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + getCompilerOptions()); + } + // Test that a record without any record components was indeed compiled + // to be a record at runtime + public void testBug565732_03() { + runConformTest( + new String[] { + "X.java", + "public record X() {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.class.getSuperclass().getName());\n" + + " }\n" + + "}" + }, + "java.lang.Record"); + } + // Test that a record without any record components was indeed compiled + // to be a record at runtime + public void testBug565732_04() { + runConformTest( + new String[] { + "X.java", + "public record X() {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.class.getSuperclass().getName());\n" + + " }\n" + + "}" + }, + "java.lang.Record"); + } + // Test that a "record" can be used as a method name and invoked inside a record + public void testBug565732_05() { + runConformTest( + new String[] { + "X.java", + "public record X() {\n" + + " public static void main(String[] args) {\n" + + " record();\n" + + " }\n" + + " public static void record() {\n" + + " System.out.println(\"record()\");\n" + + " }\n" + + "}" + }, + "record()"); + } + // Test that a "record" can be used as a label and invoked inside a record + public void testBug565732_06() { + runConformTest( + new String[] { + "X.java", + "public record X() {\n" + + " public static void main(String[] args) {\n" + + " boolean flag = true;\n" + + " record: {\n" + + " if (flag) {\n" + + " System.out.println(\"record:\");\n" + + " flag = false;\n" + + " break record;\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "record:"); + } + public void testBug565732_07() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " record R {};\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " record R {};\n" + + " ^\n" + + "Syntax error, insert \"RecordHeader\" to complete RecordHeaderPart\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + getCompilerOptions()); + } + public void testBug565732_08() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(R.class.getSuperclass().getName());\n" + + " }\n" + + " record R() {};\n" + + "}" + }, + "java.lang.Record"); + } + public void testBug565830_01() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " void bar() throws Exception {\n"+ + " record Bar(int x) implements java.io.Serializable {\n"+ + " void printMyFields() {\n"+ + " for (var field : this.getClass().getDeclaredFields()) {\n"+ + " System.out.println(field);\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " var bar = new Bar(1);\n"+ + " bar.printMyFields();\n"+ + " new java.io.ObjectOutputStream(java.io.OutputStream.nullOutputStream()).writeObject(bar);\n"+ + " }\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " new X().bar();\n"+ + " }\n"+ + "}", + }, + "private final int X$1Bar.x"); + } +public void testBug566063_001() { + if (this.complianceLevel < ClassFileConstants.JDK17) return; + Map options = getCompilerOptionsWithPreview(); + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " void bar() throws Exception {\n"+ + " enum E {\n"+ + " ONE,\n"+ + " TWO\n"+ + " }\n"+ + " interface I {}\n"+ + " record Bar(E x) implements I{}\n"+ + " E e = new Bar(E.ONE).x();\n"+ + " System.out.println(e);\n"+ + " }\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " new X().bar();\n"+ + " }\n"+ + "}" + }, + "ONE", + options + ); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); +} +public void testBug566063_002() { + if (this.complianceLevel < ClassFileConstants.JDK17) return; + Map options = getCompilerOptionsWithPreview(); + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void bar() throws Exception {\n"+ + " static enum E {\n"+ + " ONE,\n"+ + " TWO\n"+ + " }\n"+ + " interface I {}\n"+ + " record Bar(E x) implements I{}\n"+ + " E e = new Bar(E.ONE).x();\n"+ + " System.out.println(e);\n"+ + " }\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " new X().bar();\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " static enum E {\n" + + " ^\n" + + "Illegal modifier for local enum E; no explicit modifier is permitted\n" + + "----------\n", + null, + true, + options + ); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); +} +public void testBug566063_003() { + if (this.complianceLevel < ClassFileConstants.JDK17) return; + Map options = getCompilerOptionsWithPreview(); + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void bar() throws Exception {\n"+ + " static enum E {\n"+ + " ONE,\n"+ + " TWO\n"+ + " }\n"+ + " static interface I {}\n"+ + " static record Bar(E x) implements I{}\n"+ + " E e = new Bar(E.ONE).x();\n"+ + " System.out.println(e);\n"+ + " }\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " new X().bar();\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " static enum E {\n" + + " ^\n" + + "Illegal modifier for local enum E; no explicit modifier is permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " static interface I {}\n" + + " ^\n" + + "Illegal modifier for the local interface I; abstract and strictfp are the only modifiers allowed explicitly \n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " static record Bar(E x) implements I{}\n" + + " ^^^\n" + + "A local class or interface Bar is implicitly static; cannot have explicit static declaration\n" + + "----------\n", + null, + true, + options + ); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); +} +public void testBug566063_004() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + this.runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " void bar() throws Exception {\n"+ + " enum E {\n"+ + " ONE,\n"+ + " TWO\n"+ + " }\n"+ + " interface I {}\n" + + " record Bar(E x) implements I{}\n"+ + " E e = new Bar(E.ONE).x();\n"+ + " System.out.println(e);\n"+ + " }\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " new X().bar();\n"+ + " }\n"+ + "}" + }, + "ONE"); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); +} +@SuppressWarnings({ "unchecked", "rawtypes" }) +public void testBug566418_001() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo() {\n"+ + " record R() {\n"+ + " static int create(int lo) {\n"+ + " return lo;\n"+ + " }\n"+ + " }\n"+ + " System.out.println(R.create(0));\n"+ + " }\n"+ + " Zork();\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n", + null, + true, + options + ); +} +public void testBug565787_01() { + runConformTest( + new String[] { + "X.java", + "public record X(String s) {\n"+ + " public X {\n"+ + " s.codePoints()\n"+ + " .forEach(cp -> System.out.println((java.util.function.Predicate) \"\"::equals));\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X a = new X(\"\");\n"+ + " a.equals(a);\n"+ + " }\n"+ + "}", + }, + ""); +} +public void testBug566554_01() { + runConformTest( + new String[] { + "Main.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " final Margin margins = new Margin(0);\n" + + " System.out.println(margins.left()); \n" + + " }\n" + + "}\n" + + "record Margin(int left) {\n" + + " public Margin left(int value) {\n" + + " return new Margin(value);\n" + + " }\n" + + " public String toString() {\n" + + " return \"Margin[left=\" + this.left + \"]\";\n" + + " }\n" + + "}", + }, + "0"); +} +public void testBug566554_02() { + runConformTest( + new String[] { + "Main.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " final Margin margins = new Margin(0);\n" + + " System.out.println(margins.left()); \n" + + " }\n" + + "}\n" + + "record Margin(int left) {\n" + + " public Margin left(int value) {\n" + + " return new Margin(value);\n" + + " }\n" + + " public int left() {\n" + + " return this.left;\n" + + " }\n" + + " public String toString() {\n" + + " return \"Margin[left=\" + this.left + \"]\";\n" + + " }\n" + + "}", + }, + "0"); +} +public void testBug566554_03() { + runConformTest( + new String[] { + "Main.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " final Margin margins = new Margin(0);\n" + + " System.out.println(margins.left(0)); \n" + + " }\n" + + "}\n" + + "record Margin(int left) {\n" + + " public Margin left(int value) {\n" + + " return new Margin(value);\n" + + " }\n" + + " public int left() {\n" + + " return this.left;\n" + + " }\n" + + " public String toString() {\n" + + " return \"Margin[left=\" + this.left + \"]\";\n" + + " }\n" + + "}", + }, + "Margin[left=0]"); +} +public void testBug566554_04() { + runNegativeTest( + new String[] { + "Main.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " final Margin margins = new Margin(0);\n" + + " int l = margins.left(0); \n" + + " }\n" + + "}\n" + + "record Margin(int left) {\n" + + " public Margin left(int value) {\n" + + " return new Margin(value);\n" + + " }\n" + + " public int left() {\n" + + " return this.left;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in Main.java (at line 5)\n" + + " int l = margins.left(0); \n" + + " ^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Margin to int\n" + + "----------\n"); +} +public void testBug567731_001() { + if (this.complianceLevel < ClassFileConstants.JDK17) return; + Map options = getCompilerOptionsWithPreview(); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " non-sealed record R() {}\n" + + " public static void main(String[] args) {\n" + + " sealed record B() { } \n" + + " }" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " non-sealed record R() {}\n" + + " ^\n" + + "Illegal modifier for the record R; only public, private, protected, static, final and strictfp are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " sealed record B() { } \n" + + " ^\n" + + "Illegal modifier for the local record B; only final and strictfp are permitted\n" + + "----------\n", + null, + true, + options + ); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); +} +public void testBug567731_002() { + if (this.complianceLevel < ClassFileConstants.JDK17) return; + Map options = getCompilerOptionsWithPreview(); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " sealed record R1() {}\n" + + " public static void main(String[] args) {\n" + + " non-sealed record R2() { } \n" + + " }" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " sealed record R1() {}\n" + + " ^^\n" + + "Illegal modifier for the record R1; only public, private, protected, static, final and strictfp are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " non-sealed record R2() { } \n" + + " ^^\n" + + "Illegal modifier for the local record R2; only final and strictfp are permitted\n" + + "----------\n", + null, + true, + options + ); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); +} +public void testBug566846_1() { + runNegativeTest( + new String[] { + "X.java", + "public record X;\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public record X;\n" + + " ^^^^^^\n" + + "Syntax error on token \"record\", package expected\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + getCompilerOptions()); +} +public void testBug566846_2() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + "} \n" + + "record R1;\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " } \n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " record R1;\n" + + " ^^^^^^\n" + + "\'record\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 16\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " record R1;\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + getCompilerOptions()); +} +public void testBug561199_001() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.ERROR); + runNegativeTest( + new String[] { + "R.java", + "record R() implements java.io.Serializable {}\n", + "X.java", + "class X implements java.io.Serializable {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X implements java.io.Serializable {}\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + options); +} +public void testBug568922_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " @SuppressWarnings(\"preview\")\n"+ + " record R() {\n"+ + " R {\n"+ + " super();\n"+ + " System.out.println(\"helo\");\n"+ + " }\n"+ + " }\n"+ + " new R();\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " super();\n" + + " ^^^^^^^^\n" + + "The body of a compact constructor must not contain an explicit constructor call\n" + + "----------\n", + null, + true, + new String[] {"--enable-preview"}, + getCompilerOptions()); +} +public void testBug568922_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " @SuppressWarnings(\"preview\")\n"+ + " record R() {\n"+ + " R {\n"+ + " System.out.println(\"helo\");\n"+ + " }\n"+ + " }\n"+ + " new R();\n"+ + " }\n"+ + "}" + }, + "helo"); +} +public void testBug570243_001() { + runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Parameter;\n"+ + " \n"+ + "public record X(int myCompOne) {\n"+ + " public static void main(String[] x1) {\n"+ + " try {\n"+ + " Parameter param = Class.forName(\"X\").getConstructors()[0].getParameters()[0];\n"+ + " System.out.println(param.getType().getSimpleName()+\" \"+ param.getName());\n"+ + " } catch(ClassNotFoundException e) {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "int myCompOne"); +} +public void testBug570243_002() { + runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Parameter;\n"+ + " \n"+ + "public record X(int myCompOne, char myCompChar) {\n"+ + " public static void main(String[] x1) {\n"+ + " try {\n"+ + " Parameter[] params = Class.forName(\"X\").getConstructors()[0].getParameters();\n"+ + " for (Parameter param : params)\n"+ + " System.out.println(param.getType().getSimpleName()+\" \"+ param.getName());\n"+ + " } catch(ClassNotFoundException e) {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "int myCompOne\n"+ + "char myCompChar"); +} +public void testBug570243_003() { + runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Parameter;\n"+ + " \n"+ + "public record X(int myCompOne, char ...myCompChar) {\n"+ + " public static void main(String[] x1) {\n"+ + " try {\n"+ + " Parameter[] params = Class.forName(\"X\").getConstructors()[0].getParameters();\n"+ + " for (Parameter param : params)\n"+ + " System.out.println(param.getType().getSimpleName()+\" \"+ param.getName());\n"+ + " } catch(ClassNotFoundException e) {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "int myCompOne\n"+ + "char[] myCompChar"); +} +public void testBug570230_001() { + runNegativeTest( + new String[] { + "X.java", + "public record X(int marr[]) {}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public record X(int marr[]) {}\n" + + " ^^^^\n" + + "Extended dimensions are illegal for a record component\n" + + "----------\n"); +} +public void testBug571015_001() { + runNegativeTest( + new String[] { + "X.java", + "record R() {\n"+ + " R(I ... t) {}\n"+ + "}\n"+ + "interface I{}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " R(I ... t) {}\n" + + " ^\n" + + "The type I is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " R(I ... t) {}\n" + + " ^\n" + + "T cannot be resolved to a type\n" + + "----------\n"); +} +public void testBug571015_002() { + runNegativeTest( + new String[] { + "X.java", + "record R() {\n"+ + " R(I ... t) {}\n"+ + "}\n"+ + "interface I{}\n"+ + "class X{}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " R(I ... t) {}\n" + + " ^^^^^^^^^^^^^\n" + + "A non-canonical constructor must start with an explicit invocation to a constructor\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " R(I ... t) {}\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter t\n" + + "----------\n"); +} +public void testBug571038_1() throws Exception { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"hello\");\n" + + " }\n" + + "}\n" + + "record MyRecord (MyIntf... t) {\n" + + " public MyRecord(MyIntf... t) {\n" + + " this.t = null;\n" + + " }\n" + + "}\n" + + "interface MyIntf {}\n" + }, + "hello"); + String expectedOutput = " // Method descriptor #25 ()[LMyIntf;\n" + + " // Signature: ()[LMyIntf;\n" + + " // Stack: 1, Locals: 1\n" + + " public MyIntf[] t();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "MyRecord.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug571038_2() throws Exception { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"hello\");\n" + + " }\n" + + "}\n" + + "record MyRecord (MyIntf... t) {\n" + + " @SafeVarargs\n" + + " public MyRecord(MyIntf... t) {\n" + + " this.t = null;\n" + + " }\n" + + "}\n" + + "interface MyIntf {}\n" + }, + "hello"); + String expectedOutput = " // Method descriptor #27 ()[LMyIntf;\n" + + " // Signature: ()[LMyIntf;\n" + + " // Stack: 1, Locals: 1\n" + + " public MyIntf[] t();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "MyRecord.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug571038_3() throws Exception { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"hello\");\n" + + " }\n" + + "}\n" + + "record MyRecord (MyIntf... t) {\n" + + " @SafeVarargs\n" + + " public MyRecord(@MyAnnot MyIntf... t) {\n" + + " this.t = null;\n" + + " }\n" + + "}\n" + + "interface MyIntf {}\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface MyAnnot {}\n" + }, + "hello"); + String expectedOutput = " // Method descriptor #30 ()[LMyIntf;\n" + + " // Signature: ()[LMyIntf;\n" + + " // Stack: 1, Locals: 1\n" + + " public MyIntf[] t();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "MyRecord.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug571038_4() throws Exception { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"hello\");\n" + + " }\n" + + "}\n" + + "record MyRecord (MyIntf... t) {\n" + + " @SafeVarargs\n" + + " public MyRecord(MyIntf<@MyAnnot T>... t) {\n" + + " this.t = null;\n" + + " }\n" + + "}\n" + + "interface MyIntf {}\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface MyAnnot {}\n" + }, + "hello"); + String expectedOutput = " // Method descriptor #29 ()[LMyIntf;\n" + + " // Signature: ()[LMyIntf;\n" + + " // Stack: 1, Locals: 1\n" + + " public MyIntf[] t();\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "MyRecord.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug571454() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String argv[]) {\n"+ + " R rec = new R(3);\n"+ + " if (rec.x() == 3) {\n" + + " // do nothing\n" + + " }\n" + + " }\n"+ + "}\n", + "R.java", + "record R(int x) {\n"+ + " R {\n"+ + " super();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in R.java (at line 3)\n" + + " super();\n" + + " ^^^^^^^^\n" + + "The body of a compact constructor must not contain an explicit constructor call\n" + + "----------\n"); +} +public void testBug570399_001() throws Exception { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " R r1 = new R( 2, 3); // Wrong error: The constructor MyRecord(int, int) is undefined\n"+ + " R r2 = new R(); // works\n"+ + " int total = r1.x()+r2.x()+r1.y()+r2.y();\n"+ + " System.out.println(\"Hi\"+total);\n"+ + " }\n"+ + "}", + "R.java", + "public record R(int x, int y) {\n"+ + " R() {\n"+ + " this(0, 0);\n"+ + " }\n"+ + "}", + }, + "Hi5"); +} +public void testBug570399_002() throws Exception { + runConformTest( + new String[] { + "X.java", + "record R(int x) {\n"+ + "}\n" + + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " R r2 = new R(5); // works\n"+ + " int total = r2.x();\n"+ + " System.out.println(\"Hi\"+total);\n"+ + " }\n"+ + "}", + }, + "Hi5"); +} +public void testBug571141_1() { + runConformTest(new String[] { "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"helo\");\n" + + " }\n" + + "}\n" + + "record MyRecord(boolean equals){\n" + + " public boolean equals() {\n" + + " return equals;\n" + + " }\n" + + "}" }, + "helo"); +} +public void testBug571141_2() { + runConformTest(new String[] { "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"helo\");\n" + + " }\n" + + "}\n" + + "record MyRecord(boolean equals){\n" + + " public boolean equals() {\n" + + " return equals;\n" + + " }\n" + + " public boolean equals(Object obj) {\n" + + " return equals;\n" + + " } \n" + + "}" }, + "helo"); +} +public void testBug571141_3() throws IOException, ClassFormatException { + runConformTest(new String[] { "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"helo\");\n" + + " }\n" + + "}\n" + + "record MyRecord(boolean b){\n" + + " public boolean equals(Object other) {\n" + + " return true;\n" + + " }\n" + + "}" }, + "helo"); + String unExpectedOutput = + " public final boolean equals(java.lang.Object arg0);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 invokedynamic 0 equals(MyRecord, java.lang.Object) : boolean [35]\n" + + " 7 ireturn\n" + + ""; + String rFile = getClassFileContents("MyRecord.class", ClassFileBytesDisassembler.SYSTEM); + verifyOutputNegative(rFile, unExpectedOutput); +} +public void testBugLazyCanon_001() throws IOException, ClassFormatException { + runConformTest(new String[] { "X.java", + "record X(int xyz, int y2k) {\n"+ + " public X(int xyz, int y2k) {\n"+ + " this.xyz = xyz;\n"+ + " this.y2k = y2k;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new X(33,1).xyz());\n"+ + " }\n"+ + "}" + }, + "33"); +} +public void testBugLazyCanon_002() throws IOException, ClassFormatException { + runConformTest(new String[] { "X.java", + "record X(int xyz, int y2k) {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new X(33,1).xyz());\n"+ + " }\n"+ + "}" + }, + "33"); +} +public void testBugLazyCanon_003() throws IOException, ClassFormatException { + runConformTest(new String[] { "X.java", + "class X {\n"+ + " record Point (int args) {\n"+ + " Point (String s, int t) {\n"+ + " this(t);\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new X.Point(null, 33).args());\n"+ + " \n"+ + " }\n"+ + "}" + }, + "33"); +} +public void testBugLazyCanon_004() throws IOException, ClassFormatException { + runConformTest(new String[] { + "X.java", + "record X (T args) {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new X(100).args());\n"+ + " \n"+ + " }\n"+ + "}" + }, + "100"); +} +public void testBugLazyCanon_005() throws IOException, ClassFormatException { + runConformTest(new String[] { + "X.java", + "record X (T args) {\n"+ + " X(String s, T t) {\n"+ + " this(t);\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(100);\n"+ + " \n"+ + " }\n"+ + "}" + }, + "100"); +} +public void testBugLazyCanon_006() throws IOException, ClassFormatException { + runConformTest(new String[] { + "X.java", + "record X (T args) {\n"+ + " X(String s, T t) {\n"+ + " this(t);\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new X(100).args());\n"+ + " \n"+ + " }\n"+ + "}" + }, + "100"); +} +public void testBug571765_001() { + this.runNegativeTest( + new String[] { + "module-info.java", + "public record R() {}\n", + }, + "----------\n" + + "1. ERROR in module-info.java (at line 1)\n" + + " public record R() {}\n" + + " ^^^^^^\n" + + "Syntax error on token \"record\", record expected\n" + + "----------\n"); +} +public void testBug571905_01() throws Exception { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "record X( int @MyAnnot [] j) {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"helo\");\n" + + " }\n" + + "}\n" + + "@Target({ElementType.TYPE_USE})\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface MyAnnot {}\n" + }, + "helo"); + String expectedOutput = // constructor + " \n" + + " // Method descriptor #10 ([I)V\n" + + " // Stack: 2, Locals: 2\n" + + " X(int[] j);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [12]\n" + + " 4 aload_0 [this]\n" + + " 5 aload_1 [j]\n" + + " 6 putfield X.j : int[] [15]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " [pc: 0, pc: 10] local: j index: 1 type: int[]\n" + + " Method Parameters:\n" + + " j\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @MyAnnot(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = // accessor + " public int[] j();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield X.j : int[] [15]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @MyAnnot(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" ; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug571905_02() throws Exception { + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "record X( int @MyAnnot ... j) {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"helo\");\n" + + " }\n" + + "}\n" + + "@Target({ElementType.TYPE_USE})\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface MyAnnot {}\n" + }, + "helo"); + String expectedOutput = // constructor + " \n" + + " // Method descriptor #10 ([I)V\n" + + " // Stack: 2, Locals: 2\n" + + " X(int... j);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [12]\n" + + " 4 aload_0 [this]\n" + + " 5 aload_1 [j]\n" + + " 6 putfield X.j : int[] [15]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " [pc: 0, pc: 10] local: j index: 1 type: int[]\n" + + " Method Parameters:\n" + + " j\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @MyAnnot(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = // accessor + " public int[] j();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield X.j : int[] [15]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @MyAnnot(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" ; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug572204_001() { + runNegativeTest( + new String[] { + "R.java", + "record R (@SafeVarargs String... s) {}\n" + }, + "----------\n" + + "1. ERROR in R.java (at line 1)\n" + + " record R (@SafeVarargs String... s) {}\n" + + " ^\n" + + "@SafeVarargs annotation cannot be applied to record component without explicit accessor method s\n" + + "----------\n"); +} +public void testBug572204_002() { + runConformTest( + new String[] { + "R.java", + "record R (@SafeVarargs String... s) {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"helo\");\n" + + " }\n" + + " public String[] s() {\n" + + " return this.s;\n" + + " }\n" + + "}\n" + }, + "helo"); +} +public void testBug572204_003() { + runNegativeTest( + new String[] { + "R.java", + "record R (@SafeVarargs String... s) {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"helo\");\n" + + " }\n" + + " R (@SafeVarargs String... s) {\n" + + " this.s=s;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in R.java (at line 1)\n" + + " record R (@SafeVarargs String... s) {\n" + + " ^\n" + + "@SafeVarargs annotation cannot be applied to record component without explicit accessor method s\n" + + "----------\n" + + "2. ERROR in R.java (at line 5)\n" + + " R (@SafeVarargs String... s) {\n" + + " ^^^^^^^^^^^^\n" + + "The annotation @SafeVarargs is disallowed for this location\n" + + "----------\n"); +} +public void testBug572204_004() { + runNegativeTest( + new String[] { + "R.java", + "record R (@SafeVarargs String... s) {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"helo\");\n" + + " }\n" + + " R (@SafeVarargs String... s) {\n" + + " this.s=s;\n" + + " }\n" + + " public String[] s() {\n" + + " return this.s;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in R.java (at line 5)\n" + + " R (@SafeVarargs String... s) {\n" + + " ^^^^^^^^^^^^\n" + + "The annotation @SafeVarargs is disallowed for this location\n" + + "----------\n"); +} +public void testBug572204_005() { + runNegativeTest( + new String[] { + "R.java", + "record R (@SafeVarargs String... s) {\n" + + "@SafeVarargs" + + " R (String... s) {\n" + + " this.s = s;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in R.java (at line 1)\n" + + " record R (@SafeVarargs String... s) {\n" + + " ^\n" + + "@SafeVarargs annotation cannot be applied to record component without explicit accessor method s\n" + + "----------\n"); +} +public void testBug572204_006() { + runConformTest( + new String[] { + "R.java", + "record R (@SafeVarargs String... s) {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"helo\");\n" + + " }\n" + + "@SafeVarargs" + + " R (String... s) {\n" + + " this.s = s;\n" + + " }\n" + + " public String[] s() {\n" + + " return this.s;\n" + + " }\n" + + "}\n" + }, + "helo"); +} +public void testBug572204_007() throws Exception { + runConformTest( + new String[] { + "R.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.PARAMETER) \n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface I {}\r\n" + + "record R(@I String... s) {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"helo\");\n" + + " }\n" + + "}\n" + }, + "helo"); + String expectedOutput = // constructor + " \n" + + " // Method descriptor #8 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " R(java.lang.String... s);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [12]\n" + + " 4 aload_0 [this]\n" + + " 5 aload_1 [s]\n" + + " 6 putfield R.s : java.lang.String[] [15]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: R\n" + + " [pc: 0, pc: 10] local: s index: 1 type: java.lang.String[]\n" + + " Method Parameters:\n" + + " s\n" + + " RuntimeVisibleParameterAnnotations: \n" + + " Number of annotations for parameter 0: 1\n" + + " #10 @I(\n" + + " )\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = // accessor + " \n" + + " // Method descriptor #38 ()[Ljava/lang/String;\n" + + " // Stack: 1, Locals: 1\n" + + " public java.lang.String[] s();\n" + + " 0 aload_0 [this]\n" + + " 1 getfield R.s : java.lang.String[] [15]\n" + + " 4 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "R.class", ClassFileBytesDisassembler.SYSTEM); +} +public void testBug572934_001() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSpecialParameterHidingField, CompilerOptions.ENABLED); + //This test should not report any error + this.runConformTest( + new String[] { + "X.java", + "public record X(int param) {\n" + + " public X(int param) {\n" + + " this.param = param;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X abc= new X(10);\n" + + " System.out.println(abc.param());\n" + + " }\n" + + "}\n" + }, + "10", + options + ); + options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSpecialParameterHidingField, CompilerOptions.DISABLED); +} +public void testBug572934_002() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSpecialParameterHidingField, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "X.java", + "public record X(int param) {\n" + + " public X(int param) {\n" + + " this.param = param;\n" + + " }\n" + + " public void main(int param) {\n" + + " System.out.println(param);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " public void main(int param) {\n" + + " ^^^^^\n" + + "The parameter param is hiding a field from type X\n" + + "----------\n", + null, + true, + options + ); + options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSpecialParameterHidingField, CompilerOptions.DISABLED); +} +public void testBug572934_003() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSpecialParameterHidingField, CompilerOptions.ENABLED); + this.runNegativeTest( + new String[] { + "X.java", + "public record X(int param) {\n" + + " public X(int param) {\n" + + " this.param = param;\n" + + " }" + + " public void setParam(int param) {\n" + + " \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " } public void setParam(int param) {\n" + + " ^^^^^\n" + + "The parameter param is hiding a field from type X\n" + + "----------\n", + null, + true, + options + ); + options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportSpecialParameterHidingField, CompilerOptions.DISABLED); +} +public void testBug573195_001() throws Exception { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " protected record R(int i) {\n"+ + " public R(int i, int j) {\n"+ + " this(i);\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " R r = new R(1, 2);\n"+ + " System.out.println(r.i());\n"+ + " }\n"+ + "}" + }, + "1"); + String expectedOutput = // constructor + " // Method descriptor #12 (I)V\n" + + " // Stack: 2, Locals: 2\n" + + " protected X$R(int arg0);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [36]\n" + + " 4 aload_0 [this]\n" + + " 5 iload_1 [arg0]\n" + + " 6 putfield X$R.i : int [20]\n" + + " 9 return\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X$R.class", ClassFileBytesDisassembler.SYSTEM); +} + +public void testBug574284_001() throws Exception { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X.Rec(false); // fails\n" + + " new X.Rec(false, new int[0]);\n" + + " System.out.println(0);\n" + + " }\n" + + "\n" + + " record Rec(boolean isHidden, int... indexes) {\n" + + " Rec(int... indexes) {\n" + + " this(false, indexes);\n" + + " }\n" + + " }\n" + + "}" + }, + "0"); + String expectedOutput = // constructor + " // Method descriptor #14 (Z[I)V\n" + + " // Stack: 2, Locals: 3\n" + + " X$Rec(boolean arg0, int... arg1);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Record() [41]\n" + + " 4 aload_0 [this]\n" + + " 5 iload_1 [arg0]\n" + + " 6 putfield X$Rec.isHidden : boolean [21]\n" + + " 9 aload_0 [this]\n" + + " 10 aload_2 [arg1]\n" + + " 11 putfield X$Rec.indexes : int[] [24]\n" + + " 14 return\n"; + RecordsRestrictedClassTest.verifyClassFile(expectedOutput, "X$Rec.class", ClassFileBytesDisassembler.SYSTEM); + +} +public void testBug574284_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " new X.Rec(false); // fails\n" + + " new X.Rec(false, new int[0]);\n" + + " System.out.println(0);\n" + + " }\n" + + "\n" + + " record Rec(boolean isHidden, int... indexes) {\n" + + " }\n" + + "}" + }, + "0"); +} + +public void testBug574282_001() { + runConformTest( + new String[] { + "X.java", + "record Rec(String name) {\n" + + "\n" + + " Rec() {\n" + + " this(\"\");\n" + + " }\n" + + "\n" + + " @Override\n" + + " public boolean equals(Object obj) {\n" + + " return false;\n" + + " }\n" + + "}\n" + + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + }, + "0"); +} + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RegressionTestSetup.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RegressionTestSetup.java new file mode 100644 index 0000000000..656d4b6f17 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RegressionTestSetup.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.core.tests.util.CompilerTestSetup; +import org.eclipse.jdt.core.tests.util.TestVerifier; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; + +public class RegressionTestSetup extends CompilerTestSetup { + + TestVerifier verifier = new TestVerifier(true); + INameEnvironment javaClassLib; + + public RegressionTestSetup(long complianceLevel) { + super(complianceLevel); + } + + @Override + protected void setUp() { + if (this.javaClassLib == null) { + // Create name environment + this.javaClassLib = new FileSystem(Util.getJavaClassLibs(), new String[0], null); + } + super.setUp(); + } + @Override + protected void tearDown() { + this.verifier.shutDown(); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RepeatableAnnotationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RepeatableAnnotationTest.java new file mode 100644 index 0000000000..da3d15acb5 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RepeatableAnnotationTest.java @@ -0,0 +1,1564 @@ +/******************************************************************************* + * Copyright (c) 2013, 2020 Jesper S Moller and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Jesper S Moller - initial API and implementation + * Bug 412151 - [1.8][compiler] Check repeating annotation's collection type + * Bug 412149 - [1.8][compiler] Emit repeated annotations into the designated container + * Bug 419209 - [1.8] Repeating container annotations should be rejected in the presence of annotation it contains + * Stephan Herrmann - Contribution for + * Bug 419209 - [1.8] Repeating container annotations should be rejected in the presence of annotation it contains + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; + +import junit.framework.Test; + +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.JavacHasABug; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.ASTVisitor; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.impl.IntConstant; +import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; + +@SuppressWarnings({ "rawtypes" }) +public class RepeatableAnnotationTest extends AbstractComparableTest { + + // Static initializer to specify tests subset using TESTS_* static variables + // All specified tests which do not belong to the class are skipped... + static { +// TESTS_NAMES = new String[] { "test006" }; +// TESTS_NUMBERS = new int[] { 297 }; +// TESTS_RANGE = new int[] { 294, -1 }; + } + boolean isJRE14 = false; + public RepeatableAnnotationTest(String name) { + super(name); + String javaVersion = System.getProperty("java.version"); + int index = javaVersion.indexOf('.'); + if (index != -1) { + javaVersion = javaVersion.substring(0, index); + } else { + index = javaVersion.indexOf('-'); + if (index != -1) + javaVersion = javaVersion.substring(0, index); + } + this.isJRE14 = Integer.parseInt(javaVersion) >= 14; + } + private String normalizeAnnotationString(String s) { + if (!this.isJRE14) return s; + if (s.indexOf("value=") != -1) { + s = s.replace("value=[", "{"); + s = s.replace("value=", ""); + } + return s; + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + + public static Class testClass() { + return RepeatableAnnotationTest.class; + } + + // check repeated occurrence of non-repeatable annotation + public void test001() { + this.runNegativeTest( + new String[] { + "X.java", + "public @Foo @Foo class X {\n" + + "}\n" + + "\n", + "Foo.java", + "public @interface Foo {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public @Foo @Foo class X {\n" + + " ^^^^\n" + + "Duplicate annotation of non-repeatable type @Foo. Only annotation types marked @Repeatable can be used multiple times at one target.\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public @Foo @Foo class X {\n" + + " ^^^^\n" + + "Duplicate annotation of non-repeatable type @Foo. Only annotation types marked @Repeatable can be used multiple times at one target.\n" + + "----------\n"); + } + + public void test002() { + this.runConformTest( + new String[] { + "X.java", + "@Foo @Foo public class X {\n" + + "}\n" + + "\n", + "Foo.java", + "@java.lang.annotation.Repeatable(FooContainer.class) public @interface Foo {\n" + + "}\n", + "FooContainer.java", + "public @interface FooContainer {\n" + + " Foo[] value();\n" + + "}\n" + }, + ""); + } + + // check repeated occurrence of annotation where annotation container is not valid for the target + public void test003() { + this.runNegativeTest( + new String[] { + "FooContainer.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target({ElementType.METHOD, ElementType.FIELD}) public @interface FooContainer {\n" + + + " Foo[] value();\n" + + "}\n", + "Foo.java", + "@java.lang.annotation.Repeatable(FooContainer.class) public @interface Foo {\n" + + "}\n", + "X.java", + "@Foo @Foo public class X { /* Problem */\n" + + " @Foo @Foo void okHere() { /* No problem */\n" + + " @Foo @Foo int local = 0; /* Problem! */\n" + + " }\n" + + " @Foo @Foo int alsoFoo = 0; /* No problem */\n" + + " @Foo class Y {} /* No problem since not repeated */\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Foo @Foo public class X { /* Problem */\n" + + " ^^^^\n" + + "The annotation @Foo cannot be repeated at this location since its container annotation type @FooContainer is disallowed at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " @Foo @Foo int local = 0; /* Problem! */\n" + + " ^^^^\n" + + "The annotation @Foo cannot be repeated at this location since its container annotation type @FooContainer is disallowed at this location\n" + + "----------\n"); + } + + // This is the same test as test003, only where the annotation info for Foo is from a class file, not from the compiler + public void test004() { + this.runConformTest( + new String[] { + "FooContainer.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target({ElementType.METHOD, ElementType.FIELD}) public @interface FooContainer {\n" + + " Foo[] value();\n" + + "}\n", + "Foo.java", + "@java.lang.annotation.Repeatable(FooContainer.class) public @interface Foo {\n" + + "}\n" + }, + ""); + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "@Foo @Foo public class X { /* Problem */\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Foo @Foo public class X { /* Problem */\n" + + " ^^^^\n" + + "The annotation @Foo cannot be repeated at this location since its container annotation type @FooContainer is disallowed at this location\n" + + "----------\n"; + runner.shouldFlushOutputDirectory = false; + runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8044196; + runner.runNegativeTest(); + } + + // Test that a single, repeatable annotation can exist just fine an occurrence of its container annotation + public void test005() { + this.runConformTest( + new String[] { + "X.java", + "@java.lang.annotation.Repeatable(FooContainer.class) @interface Foo {}\n" + + "@interface FooContainer { Foo[] value(); }\n" + + "@Foo @FooContainer({@Foo, @Foo}) public class X { /* Not a problem */ }\n" + }, + ""); + } + + // Test that an repeated annotation can't occur together with its container annotation + public void test006() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface FooContainer { Foo[] value(); }\n" + + "@java.lang.annotation.Repeatable(FooContainer.class) @interface Foo {}\n" + + "@Foo @Foo @FooContainer({@Foo, @Foo}) public class X { /* A problem */ }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " @Foo @Foo @FooContainer({@Foo, @Foo}) public class X { /* A problem */ }\n" + + " ^^^^\n" + + "The repeatable annotation @Foo may not be repeated where its container annotation type @FooContainer is also used directly\n" + + "----------\n"); + } + + // Test that an repeated annotation can't occur together with its container annotation, even if it itself is repeatable. + public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface FooContainerContainer { FooContainer[] value(); }\n" + + "@java.lang.annotation.Repeatable(FooContainerContainer.class) @interface FooContainer { Foo[] value(); }\n" + + "@java.lang.annotation.Repeatable(FooContainer.class) @interface Foo {}\n" + + "@Foo @Foo @FooContainer({@Foo, @Foo}) public class X { /* Still a problem */ }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Foo @Foo @FooContainer({@Foo, @Foo}) public class X { /* Still a problem */ }\n" + + " ^^^^\n" + + "The repeatable annotation @Foo may not be repeated where its container annotation type @FooContainer is also used directly\n" + + "----------\n"); + } + + // Test that an repeated annotation can't occur together with its container annotation, even if it itself is repeatable. + public void test007a() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface FooContainerContainer { FooContainer[] value(); }\n" + + "@java.lang.annotation.Repeatable(FooContainerContainer.class) @interface FooContainer { Foo[] value(); }\n" + + "@java.lang.annotation.Repeatable(FooContainer.class) @interface Foo {}\n" + + "@interface Bar {}\n" + + "@Foo @Foo @Bar @Bar @FooContainer({@Foo, @Foo}) public class X { /* Still a problem */ }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @Foo @Foo @Bar @Bar @FooContainer({@Foo, @Foo}) public class X { /* Still a problem */ }\n" + + " ^^^^\n" + + "The repeatable annotation @Foo may not be repeated where its container annotation type @FooContainer is also used directly\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " @Foo @Foo @Bar @Bar @FooContainer({@Foo, @Foo}) public class X { /* Still a problem */ }\n" + + " ^^^^\n" + + "Duplicate annotation of non-repeatable type @Bar. Only annotation types marked @Repeatable can be used multiple times at one target.\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " @Foo @Foo @Bar @Bar @FooContainer({@Foo, @Foo}) public class X { /* Still a problem */ }\n" + + " ^^^^\n" + + "Duplicate annotation of non-repeatable type @Bar. Only annotation types marked @Repeatable can be used multiple times at one target.\n" + + "----------\n"); + } + + // Test that repeated annotations should be contiguous (raises a warning if not) -- not yet in BETA_JAVA8 + public void _test008() { + this.runNegativeTest( + new String[] { + "X.java", + "@interface Bar {}\n" + + "@interface Baz {}\n" + + "@java.lang.annotation.Repeatable(FooContainer.class) @interface Foo {}\n" + + "@interface FooContainer { Foo[] value(); }\n" + + "@Foo @Bar @Foo /* just lexical */ @Foo public class X { /* Gives a warning */ }\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " @Foo @Bar @Foo /* just lexical */ @Foo public class X { /* Gives a warning */ }\n" + + " ^^^^\n" + + "Repeated @Foo annotations are not grouped together\n" + + "----------\n"); + } + // Test that deprecation of container annotation is reflected in the repeated annotation (disabled until specification clarification is available) + public void _test009() { + this.runConformTest( + new String[] { + "Y.java", + "@java.lang.annotation.Repeatable(FooContainer.class) @interface Foo { int value(); }\n" + + "@Deprecated @interface FooContainer { Foo[] value(); }\n" + + "@Foo(0) class X { /* Gives a warning */ }\n" + + "@Foo(1) @Foo(2) public class Y { /* Gives a warning */ }\n" + }, + new ASTVisitor() { + public boolean visit( + TypeDeclaration typeDeclaration, + CompilationUnitScope scope) { + if (new String(typeDeclaration.name).equals("X")) { + assertFalse("Foo on X should NOT be deprecated!", typeDeclaration.annotations[0].getCompilerAnnotation().getAnnotationType().isDeprecated()); + } + if (new String(typeDeclaration.name).equals("Y")) { + assertEquals("Find Foo(1) on Y", IntConstant.fromValue(1), typeDeclaration.annotations[0].getCompilerAnnotation().getElementValuePairs()[0].value); + assertTrue("1st Foo on Y should be deprecated!", typeDeclaration.annotations[0].getCompilerAnnotation().getAnnotationType().isDeprecated()); + assertEquals("Find Foo(2) on Y", IntConstant.fromValue(2), typeDeclaration.annotations[1].getCompilerAnnotation().getElementValuePairs()[0].value); + assertTrue("2nd Foo on Y should be deprecated!", typeDeclaration.annotations[1].getCompilerAnnotation().getAnnotationType().isDeprecated()); + } + return true; // do nothing by default, keep traversing + } + }); + } + // Bug 412151: [1.8][compiler] Check repeating annotation's collection type + // 412151: The collections type's (TC) declaration must have a array of Ts as its value() - with Foo and FooContainer in same compilation round + public void test010() { + this.runNegativeTest( + new String[] { + "Foo.java", + "@interface FooContainer {\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@interface Foo {}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 3)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The container annotation type @FooContainer must declare a member value()\n" + + "----------\n"); + } + // 412151: The collections type's (TC) declaration must have a array of Ts as its value() - with Foo and FooContainer in same compilation round + public void test011() { + this.runNegativeTest( + new String[] { + "Foo.java", + "@interface FooContainer {\n" + + " int[] value();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@interface Foo {}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 4)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The value method in the container annotation type @FooContainer must be of type Foo[] but is int[]\n" + + "----------\n"); + } + // 412151: The collections type's (TC) declaration must have a array of Ts as its value() - with Foo and FooContainer in same compilation round + public void test012() { + this.runNegativeTest( + new String[] { + "Foo.java", + "@interface FooContainer {\n" + + " Foo[][] value();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@interface Foo {}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 2)\n" + + " Foo[][] value();\n" + + " ^^^^^^^\n" + + "Invalid type Foo[][] for the annotation attribute FooContainer.value; only primitive type, String, Class, annotation, enumeration are permitted or 1-dimensional arrays thereof\n" + + "----------\n" + + "2. ERROR in Foo.java (at line 4)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The value method in the container annotation type @FooContainer must be of type Foo[] but is Foo[][]\n" + + "----------\n" + ); + } + // 412151: Any methods declared by TC other than value() have a default value (JLS 9.6.2). + public void test013() { + this.runNegativeTest( + new String[] { + "Foo.java", + "@interface FooContainer {\n" + + " Foo[] value();\n" + + " int hasDefaultValue() default 1337;\n" + + " int doesntHaveDefaultValue();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@interface Foo {}\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 6)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The container annotation type @FooContainer must declare a default value for the annotation attribute \'doesntHaveDefaultValue\'\n" + + "----------\n"); + } + // 412151: The @Retention meta-annotation of TC must at least include the retention of T () + public void test014() { + this.runConformTest( + new String[] { + "Foo.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface FooContainer {\n" + + " Foo[] value();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface Foo {\n" + + "}\n" + }, + ""); + } + + // + public void test015() { + // These are fine: + this.runConformTest( + new String[] { + "FooContainer.java", + "public @interface FooContainer {\n" + + " Foo[] value();\n" + + "}\n", + "Foo.java", + "@java.lang.annotation.Repeatable(FooContainer.class) public @interface Foo {\n" + + "}\n" + }, + ""); + // This changes FooContainer without re-checking Foo + this.runConformTest( + new String[] { + "FooContainer.java", + "public @interface FooContainer {\n" + + " int[] value();\n" + + "}\n" + }, + "", + null, + false, + null); + this.runNegativeTest( + new String[] { + "X.java", + "@Foo @Foo public class X { /* Problem since Foo now uses FooContainer which doesn't work anymore*/\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " @Foo @Foo public class X { /* Problem since Foo now uses FooContainer which doesn\'t work anymore*/\n" + + " ^^^^\n" + + "The value method in the container annotation type @FooContainer must be of type Foo[] but is int[]\n" + + "----------\n", + null, false /* don't flush*/); + } + + // 412151: The @Retention meta-annotation of TC must at least include the retention of T () + // Base example, both targets are specified + public void test016() { + this.runNegativeTest( + new String[] { + "Foo.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@Retention(RetentionPolicy.SOURCE)\n" + + "@interface FooContainer { Foo[] value(); }\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Foo { }\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 5)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Retention \'RUNTIME\' of @Foo is longer than the retention of its container annotation type @FooContainer, which is \'SOURCE\'\n" + + "----------\n"); + } + + // 412151: The @Retention meta-annotation of TC must at least include the retention of T () + // Only specified on FooContainer + public void test017() { + this.runNegativeTest( + new String[] { + "Foo.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@Retention(RetentionPolicy.SOURCE)\n" + + "@interface FooContainer { Foo[] value(); }\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@interface Foo { }\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 5)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Retention \'CLASS\' of @Foo is longer than the retention of its container annotation type @FooContainer, which is \'SOURCE\'\n" + + "----------\n"); + } + + // 412151: The @Retention meta-annotation of TC must at least include the retention of T () + // Only specified on Foo + public void test018() { + this.runNegativeTest( + new String[] { + "Foo.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@interface FooContainer { Foo[] value(); }\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Foo { }\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 4)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Retention \'RUNTIME\' of @Foo is longer than the retention of its container annotation type @FooContainer, which is \'CLASS\'\n" + + "----------\n"); + } + + // 412151: The @Retention meta-annotation of TC must at least include the retention of T () + // Only specified on Foo - but positive + public void test019() { + this.runConformTest( + new String[] { + "Foo.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@interface FooContainer { Foo[] value(); }\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@Retention(RetentionPolicy.SOURCE)\n" + + "@interface Foo { }\n" + }); + } + + // 412151: The @Retention meta-annotation of TC must at least include the retention of T + // Only specified on FooContainer, separate compilation + public void test020() { + this.runConformTest( + new String[] { + "FooContainer.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@Retention(RetentionPolicy.SOURCE)\n" + + "public @interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@Retention(RetentionPolicy.SOURCE)\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "public @interface Foo { }\n" + }); + this.runNegativeTest( + new String[] { + "Foo.java", + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "public @interface Foo { } // If omitted, retention is class\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 1)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Retention \'CLASS\' of @Foo is longer than the retention of its container annotation type @FooContainer, which is \'SOURCE\'\n" + + "----------\n", + null, false /* don't flush*/); + } + + // 412151: The @Retention meta-annotation of TC must at least include the retention of T () + // Only specified on Foo, separate compilation + public void test021() { + this.runConformTest( + new String[] { + "FooContainer.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "public @interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "public @interface Foo { }\n" + }); + this.runNegativeTest( + new String[] { + "Foo.java", + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Foo { }\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 3)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Retention \'RUNTIME\' of @Foo is longer than the retention of its container annotation type @FooContainer, which is \'CLASS\'\n" + + "----------\n", + null, false /* don't flush*/); + } + + // 412151: TC's @Targets, if specified, must be a subset or the same as T's @Targets + // TC's @Targets, if specified, must be a subset or the same as T's @Targets. Simple test + public void test022() { + this.runNegativeTest( + new String[] { + "FooContainer.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "public @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})\n" + + "@interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "public @java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@Target({ElementType.FIELD})\n" + + "@interface Foo { }\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 3)\n" + + " public @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The container annotation type @FooContainer is allowed at targets where the repeatable annotation type @Foo is not: TYPE, METHOD\n" + + "----------\n"); + } + + // 412151: TC's @Targets, if specified, must be a subset or the same as T's @Targets + // TC's @Targets, if specified, must be a subset or the same as T's @Targets. Test this as a separate pass, so that + // FooContainer is loaded from binary. + public void test023() { + this.runConformTest( + new String[] { + "FooContainer.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "public @Target({ElementType.METHOD})\n" + + "@interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "public @Target({ElementType.METHOD})\n" + + "@interface Foo { }\n" + }); + this.runNegativeTest( + new String[] { + "Foo.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "public @java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@java.lang.annotation.Target({ElementType.FIELD})\n" + + "@interface Foo { }\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 3)\n" + + " public @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The container annotation type @FooContainer is allowed at targets where the repeatable annotation type @Foo is not: METHOD\n" + + "----------\n", + null, false /* don't flush*/); + } + + // 412151: TC's @Targets, if specified, must be a subset or the same as T's @Targets + // TC's may target ANNOTATION_TYPE but that should match TYPE for T, since it's a superset + public void test024() { + this.runConformTest( + new String[] { + "FooContainer.java", + "import java.lang.annotation.ElementType;\n" + + "@java.lang.annotation.Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})\n" + + "@interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "import java.lang.annotation.ElementType;\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@java.lang.annotation.Target({ElementType.METHOD, ElementType.TYPE})\n" + + "@interface Foo { }\n" + }); + } + + // 412151: TC's @Targets, if specified, must be a subset or the same as T's @Targets + // Test that all ElementTypes can be reported + public void test025() { + this.runNegativeTest( + new String[] { + "FooContainer.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "public @Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE, ElementType.ANNOTATION_TYPE, ElementType.PACKAGE, ElementType.TYPE_PARAMETER, ElementType.TYPE_USE})\n" + + "@interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "public @java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@Target({})\n" + + "@interface Foo { }\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 3)\n" + + " public @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The container annotation type @FooContainer is allowed at targets where the repeatable annotation type @Foo is not: TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, PACKAGE, TYPE_PARAMETER, TYPE_USE\n" + + "----------\n"); + } + + // 412151: TC's @Targets, if specified, must be a subset or the same as T's @Targets + // TC's has no @Targets (=every SE7 location), but @Foo has, then complain. + public void test026() { + this.runConformTest( + new String[] { + "FooContainer.java", + "@interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "@interface Foo { }\n" + }); + this.runNegativeTest( + new String[] { + "Foo.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@java.lang.annotation.Target({ElementType.FIELD})\n" + + "@interface Foo { }\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 3)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class)\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The container annotation type @FooContainer is allowed at targets where the repeatable annotation type @Foo is not: TYPE, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE, ANNOTATION_TYPE, PACKAGE\n" + + "----------\n", + null, false /* don't flush*/); + } + + // 412151: If T is @Documented, then TC should also be Documented + public void test027() { + this.runConformTest( + new String[] { + "FooContainer.java", + "@java.lang.annotation.Documented @interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "@java.lang.annotation.Documented @interface Foo { }\n"}); + } + + // 412151: If T is @Documented, then TC should also be Documented, OK for TC to be documented while T is not + public void test028() { + this.runConformTest( + new String[] { + "FooContainer.java", + "@java.lang.annotation.Documented @interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "@interface Foo { }\n"}); + } + + // 412151: If T is @Documented, then TC should also be Documented + public void test029() { + this.runNegativeTest( + new String[] { + "FooContainer.java", + "@interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "@java.lang.annotation.Repeatable(FooContainer.class) @java.lang.annotation.Documented\n" + + "@interface Foo { }\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 1)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class) @java.lang.annotation.Documented\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The repeatable annotation type @Foo is marked @Documented, but its container annotation type @FooContainer is not\n" + + "----------\n"); + } + + // 412151: If T is @Documented, then TC should also be Documented - check from previous compilation + public void test030() { + this.runConformTest( + new String[] { + "FooContainer.java", + "@java.lang.annotation.Documented @interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "@java.lang.annotation.Documented @interface Foo { }\n" + }); + this.runConformTest( + new String[] { + "Foo.java", + "public @java.lang.annotation.Documented @java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@interface Foo { }\n" + }, + "", + null, + false, + null); + } + + // 412151: If T is @Inherited, then TC should also be Inherited + public void test031() { + this.runConformTest( + new String[] { + "FooContainer.java", + "@java.lang.annotation.Inherited @interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "@java.lang.annotation.Inherited @interface Foo { }\n"}); + } + + // 412151: If T is @Inherited, then TC should also be Inherited, OK for TC to be inherited while T is not. + public void test032() { + this.runConformTest( + new String[] { + "FooContainer.java", + "@java.lang.annotation.Inherited @interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "@interface Foo { }\n"}); + } + // 412151: If T is @Inherited, then TC should also be Inherited + public void test033() { + this.runNegativeTest( + new String[] { + "FooContainer.java", + "@interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "@java.lang.annotation.Repeatable(FooContainer.class) @java.lang.annotation.Inherited\n" + + "@interface Foo { }\n" + }, + "----------\n" + + "1. ERROR in Foo.java (at line 1)\n" + + " @java.lang.annotation.Repeatable(FooContainer.class) @java.lang.annotation.Inherited\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "The repeatable annotation type @Foo is marked @Inherited, but its container annotation type @FooContainer is not\n" + + "----------\n"); + } + + // 412151: If T is @Inherited, then TC should also be Inherited - check from previous compilation + public void test034() { + this.runConformTest( + new String[] { + "FooContainer.java", + "@java.lang.annotation.Inherited @interface FooContainer { Foo[] value(); }\n", + "Foo.java", + "@java.lang.annotation.Inherited @interface Foo { }\n" + }); + this.runConformTest( + new String[] { + "Foo.java", + "public @java.lang.annotation.Inherited @java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@interface Foo { }\n" + }, + "", + null, + false, + null); + } + // 412151: Ensure no double reporting for bad target. + public void test035() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Repeatable;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.FIELD)\n" + + "@interface TC {\n" + + " T [] value();\n" + + "}\n" + + "@Target(ElementType.TYPE)\n" + + "@Repeatable(TC.class)\n" + + "@interface T {\n" + + "}\n" + + "@T @T // we used to double report here.\n" + + "public class X { \n" + + " X f;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " @Repeatable(TC.class)\n" + + " ^^^^^^^^\n" + + "The container annotation type @TC is allowed at targets where the repeatable annotation type @T is not: FIELD\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " @T @T // we used to double report here.\n" + + " ^^\n" + + "The annotation @T cannot be repeated at this location since its container annotation type @TC is disallowed at this location\n" + + "----------\n"); + } + // 412149: [1.8][compiler] Emit repeated annotations into the designated container + public void test036() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Repeatable;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "\n" + + "@Retention(RUNTIME)\n" + + "@interface AttrContainer {\n" + + " public Attr[] value();\n" + + "}\n" + + "@Retention(RUNTIME)\n" + + "@Repeatable(AttrContainer.class)\n" + + "@interface Attr {\n" + + " public int value() default -1;\n" + + "}\n" + + "\n" + + "@Attr(1) @Attr(2)\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Object e[] = X.class.getAnnotationsByType(Attr.class);\n" + + " for (int i=0; i> {\n" + + "}\n" + + "\n" + + "\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " Class ci = I.class; \n" + + " printAnnotations(\"I.class\", ci);\n" + + " TypeVariable>[] typeParameters = ci.getTypeParameters();\n" + + " for (TypeVariable t: typeParameters) {\n" + + " printAnnotations(t.getName(), t);\n" + + " AnnotatedType[] bounds = t.getAnnotatedBounds();\n" + + " for (AnnotatedType bound : bounds) {\n" + + " printAnnotations(bound.getType().getTypeName(), bound);\n" + + " }\n" + + " }\n" + + " }\n" + + " \n" + + " static void printAnnotations(String name, AnnotatedElement element) {\n" + + " int [] iterations = { 0, 1 };\n" + + " for (int i : iterations) {\n" + + " Class annotation = i == 0 ? T.class : TC.class;\n" + + " for (int j: iterations) {\n" + + " Annotation [] annotations = j == 0 ? new Annotation [] { element.getAnnotation(annotation) } : element.getAnnotationsByType(annotation);\n" + + " if (annotations.length == 0 || (annotations.length == 1 && annotations[0] == null)) continue;\n" + + " System.out.print(name + (j == 0 ? \".getAnnotation(\" : \".getAnnotationByType(\") + annotation.getName() + \".class): \");\n" + + " for (Annotation a : annotations) {\n" + + " System.out.print(normalizeAnnotation(a) + \" \");\n" + + " }\n" + + " System.out.print(\"\\n\");\n" + + " }\n" + + " }\n" + + " }\n" + + " static String normalizeAnnotation(Annotation a) {\n" + + " if (a == null) return null;\n" + + " String str = a.toString();\n" + + " str = str.replace(\"value={@\", \"value=[@\");\n" + + " str = str.replace(\")}\", \")]\");\n" + + " return str;\n" + + " }\n" + + "}\n" + + }, + normalizeAnnotationString("K.getAnnotationByType(T.class): @T(value=1) @T(value=2) \n" + + "K.getAnnotation(TC.class): @TC(value=[@T(value=1), @T(value=2)]) \n" + + "K.getAnnotationByType(TC.class): @TC(value=[@T(value=1), @T(value=2)]) \n" + + "java.lang.Object.getAnnotationByType(T.class): @T(value=3) @T(value=4) \n" + + "java.lang.Object.getAnnotation(TC.class): @TC(value=[@T(value=3), @T(value=4)]) \n" + + "java.lang.Object.getAnnotationByType(TC.class): @TC(value=[@T(value=3), @T(value=4)]) \n" + + "java.lang.Comparable.getAnnotationByType(T.class): @T(value=5) @T(value=6) \n" + + "java.lang.Comparable.getAnnotation(TC.class): @TC(value=[@T(value=5), @T(value=6)]) \n" + + "java.lang.Comparable.getAnnotationByType(TC.class): @TC(value=[@T(value=5), @T(value=6)])"), + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + // Test that repeated annotations show up at various sites, both type use and declaration. + public void testVariousSites() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Annotation;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Repeatable;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import java.lang.reflect.AnnotatedArrayType;\n" + + "import java.lang.reflect.AnnotatedElement;\n" + + "import java.lang.reflect.AnnotatedParameterizedType;\n" + + "import java.lang.reflect.AnnotatedType;\n" + + "import java.lang.reflect.Constructor;\n" + + "import java.lang.reflect.Field;\n" + + "import java.lang.reflect.Method;\n" + + "import java.lang.reflect.TypeVariable;\n" + + "\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "\n" + + "@Retention(RUNTIME)\n" + + "@Target({ElementType.TYPE_USE, ElementType.TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.METHOD})\n" + + "@interface TC {\n" + + " public T[] value();\n" + + "}\n" + + "@Retention(RUNTIME)\n" + + "@Repeatable(TC.class)\n" + + "@Target({ElementType.TYPE_USE, ElementType.TYPE, ElementType.FIELD, ElementType.CONSTRUCTOR, ElementType.PARAMETER, ElementType.METHOD})\n" + + "@interface T {\n" + + " public int value() default -1;\n" + + "}\n" + + "\n" + + "interface I {\n" + + "}\n" + + "\n" + + "@T(1) @T(2)\n" + + "public class X<@T(3) @T(4) K extends @T(5) @T(6) Object & java.lang.@T(7) @T(8) Comparable, @T(9) @T(10) V> extends @T(11) @T(12) Object implements @T(13) @T(14) I {\n" + + " public @T(15) @T(16) X<@T(17) @T(18) String, @T(19) @T(20) Integer> field;\n" + + " @T(21) @T(22)\n" + + " public <@T(23) @T(24) Q> X @T(25) @T(26) [] method(@T(27) @T(28) X this, \n" + + " @T(29) @T(30) X<@T(31) @T(32) String, String> that) throws @T(33) @T(34) NullPointerException {\n" + + " return null;\n" + + " }\n" + + " @T(35) @T(36)\n" + + " public X() {\n" + + " \n" + + " }\n" + + " @T(37) @T(48)\n" + + " public class MemberType {\n" + + " \n" + + " }\n" + + " \n" + + " public static void main(String args[]) {\n" + + " Class xc = X.class; \n" + + " printAnnotations(\"Class: \" + \"X.class\", xc);\n" + + " TypeVariable>[] typeParameters = xc.getTypeParameters();\n" + + " for (TypeVariable t: typeParameters) {\n" + + " printAnnotations(\"Type Parameter: \" + t.getName(), t);\n" + + " AnnotatedType[] bounds = t.getAnnotatedBounds();\n" + + " for (AnnotatedType bound : bounds) {\n" + + " printAnnotations(\"Type parameter bound: \" + bound.getType().getTypeName(), bound);\n" + + " }\n" + + " }\n" + + " AnnotatedType annotatedSuperclass = xc.getAnnotatedSuperclass();\n" + + " printAnnotations(\"Superclass: \" + annotatedSuperclass.getType().getTypeName(), annotatedSuperclass);\n" + + " \n" + + " AnnotatedType [] annotatedSuperInterfaces = xc.getAnnotatedInterfaces();\n" + + " printAnnotations(\"Superinterface: \" + annotatedSuperInterfaces[0].getType().getTypeName(), annotatedSuperInterfaces[0]);\n" + + " \n" + + " for (Field field: xc.getFields()) {\n" + + " printAnnotations(\"Field: \" + field.getName(), field);\n" + + " AnnotatedParameterizedType fType = (AnnotatedParameterizedType) field.getAnnotatedType();\n" + + " for (AnnotatedType typeArgumentType : fType.getAnnotatedActualTypeArguments())\n" + + " printAnnotations(\"Field Type argument: \" + typeArgumentType.getType().getTypeName(), typeArgumentType);\n" + + " \n" + + " }\n" + + " for (Method method: xc.getMethods()) {\n" + + " switch (method.getName()) {\n" + + " case \"method\" :\n" + + " printAnnotations(method.getName(), method);\n" + + " AnnotatedArrayType mType = (AnnotatedArrayType) method.getAnnotatedReturnType();\n" + + " printAnnotations(\"Method return type: \" + mType.getType().getTypeName(), mType);\n" + + " AnnotatedType mTypeEtype = mType.getAnnotatedGenericComponentType();\n" + + " printAnnotations(\"Method return type, element type: \" + mTypeEtype.getType().getTypeName(), mTypeEtype);\n" + + " TypeVariable[] typeParameters2 = method.getTypeParameters();\n" + + " for (TypeVariable t: typeParameters2) {\n" + + " printAnnotations(\"Method Type Parameter: \" + t.getName(), t);\n" + + " }\n" + + " AnnotatedType annotatedReceiverType = method.getAnnotatedReceiverType();\n" + + " printAnnotations(\"Receiver: \", annotatedReceiverType);\n" + + " AnnotatedType[] annotatedParameterTypes = method.getAnnotatedParameterTypes();\n" + + " for (AnnotatedType annotatedParameterType : annotatedParameterTypes) {\n" + + " printAnnotations(\"Parameter: \", annotatedParameterType);\n" + + " }\n" + + " AnnotatedType[] annotatedExceptionTypes = method.getAnnotatedExceptionTypes();\n" + + " for (AnnotatedType annotatedType : annotatedExceptionTypes) {\n" + + " printAnnotations(\"Exception type: \", annotatedType);\n" + + " }\n" + + " break;\n" + + " }\n" + + " }\n" + + " for (Constructor constructor : xc.getConstructors()) {\n" + + " printAnnotations(\"Constructor: \", constructor);\n" + + " }\n" + + " // don't know how to get member classes.\n" + + " }\n" + + " \n" + + " static void printAnnotations(String name, AnnotatedElement element) {\n" + + " int [] iterations = { 0, 1 };\n" + + " for (int i : iterations) {\n" + + " Class annotation = i == 0 ? T.class : TC.class;\n" + + " for (int j: iterations) {\n" + + " Annotation [] annotations = j == 0 ? new Annotation [] { element.getAnnotation(annotation) } : element.getAnnotationsByType(annotation);\n" + + " if (annotations.length == 0 || (annotations.length == 1 && annotations[0] == null)) continue;\n" + + " System.out.print(name + (j == 0 ? \".getAnnotation(\" : \".getAnnotationByType(\") + annotation.getName() + \".class): \");\n" + + " for (Annotation a : annotations) {\n" + + " System.out.print(normalizeAnnotation(a) + \" \");\n" + + " }\n" + + " System.out.print(\"\\n\");\n" + + " }\n" + + " }\n" + + " }\n" + + " static String normalizeAnnotation(Annotation a) {\n" + + " if (a == null) return null;\n" + + " String str = a.toString();\n" + + " str = str.replace(\"value={@\", \"value=[@\");\n" + + " str = str.replace(\")}\", \")]\");\n" + + " return str;\n" + + " }\n" + + "}\n" + + }, + normalizeAnnotationString("Class: X.class.getAnnotationByType(T.class): @T(value=1) @T(value=2) \n" + + "Class: X.class.getAnnotation(TC.class): @TC(value=[@T(value=1), @T(value=2)]) \n" + + "Class: X.class.getAnnotationByType(TC.class): @TC(value=[@T(value=1), @T(value=2)]) \n" + + "Type Parameter: K.getAnnotationByType(T.class): @T(value=3) @T(value=4) \n" + + "Type Parameter: K.getAnnotation(TC.class): @TC(value=[@T(value=3), @T(value=4)]) \n" + + "Type Parameter: K.getAnnotationByType(TC.class): @TC(value=[@T(value=3), @T(value=4)]) \n" + + "Type parameter bound: java.lang.Object.getAnnotationByType(T.class): @T(value=5) @T(value=6) \n" + + "Type parameter bound: java.lang.Object.getAnnotation(TC.class): @TC(value=[@T(value=5), @T(value=6)]) \n" + + "Type parameter bound: java.lang.Object.getAnnotationByType(TC.class): @TC(value=[@T(value=5), @T(value=6)]) \n" + + "Type parameter bound: java.lang.Comparable.getAnnotationByType(T.class): @T(value=7) @T(value=8) \n" + + "Type parameter bound: java.lang.Comparable.getAnnotation(TC.class): @TC(value=[@T(value=7), @T(value=8)]) \n" + + "Type parameter bound: java.lang.Comparable.getAnnotationByType(TC.class): @TC(value=[@T(value=7), @T(value=8)]) \n" + + "Type Parameter: V.getAnnotationByType(T.class): @T(value=9) @T(value=10) \n" + + "Type Parameter: V.getAnnotation(TC.class): @TC(value=[@T(value=9), @T(value=10)]) \n" + + "Type Parameter: V.getAnnotationByType(TC.class): @TC(value=[@T(value=9), @T(value=10)]) \n" + + "Superclass: java.lang.Object.getAnnotationByType(T.class): @T(value=11) @T(value=12) \n" + + "Superclass: java.lang.Object.getAnnotation(TC.class): @TC(value=[@T(value=11), @T(value=12)]) \n" + + "Superclass: java.lang.Object.getAnnotationByType(TC.class): @TC(value=[@T(value=11), @T(value=12)]) \n" + + "Superinterface: I.getAnnotationByType(T.class): @T(value=13) @T(value=14) \n" + + "Superinterface: I.getAnnotation(TC.class): @TC(value=[@T(value=13), @T(value=14)]) \n" + + "Superinterface: I.getAnnotationByType(TC.class): @TC(value=[@T(value=13), @T(value=14)]) \n" + + "Field: field.getAnnotationByType(T.class): @T(value=15) @T(value=16) \n" + + "Field: field.getAnnotation(TC.class): @TC(value=[@T(value=15), @T(value=16)]) \n" + + "Field: field.getAnnotationByType(TC.class): @TC(value=[@T(value=15), @T(value=16)]) \n" + + "Field Type argument: java.lang.String.getAnnotationByType(T.class): @T(value=17) @T(value=18) \n" + + "Field Type argument: java.lang.String.getAnnotation(TC.class): @TC(value=[@T(value=17), @T(value=18)]) \n" + + "Field Type argument: java.lang.String.getAnnotationByType(TC.class): @TC(value=[@T(value=17), @T(value=18)]) \n" + + "Field Type argument: java.lang.Integer.getAnnotationByType(T.class): @T(value=19) @T(value=20) \n" + + "Field Type argument: java.lang.Integer.getAnnotation(TC.class): @TC(value=[@T(value=19), @T(value=20)]) \n" + + "Field Type argument: java.lang.Integer.getAnnotationByType(TC.class): @TC(value=[@T(value=19), @T(value=20)]) \n" + + "method.getAnnotationByType(T.class): @T(value=21) @T(value=22) \n" + + "method.getAnnotation(TC.class): @TC(value=[@T(value=21), @T(value=22)]) \n" + + "method.getAnnotationByType(TC.class): @TC(value=[@T(value=21), @T(value=22)]) \n" + + "Method return type: X[].getAnnotationByType(T.class): @T(value=25) @T(value=26) \n" + + "Method return type: X[].getAnnotation(TC.class): @TC(value=[@T(value=25), @T(value=26)]) \n" + + "Method return type: X[].getAnnotationByType(TC.class): @TC(value=[@T(value=25), @T(value=26)]) \n" + + "Method return type, element type: X.getAnnotationByType(T.class): @T(value=21) @T(value=22) \n" + + "Method return type, element type: X.getAnnotation(TC.class): @TC(value=[@T(value=21), @T(value=22)]) \n" + + "Method return type, element type: X.getAnnotationByType(TC.class): @TC(value=[@T(value=21), @T(value=22)]) \n" + + "Method Type Parameter: Q.getAnnotationByType(T.class): @T(value=23) @T(value=24) \n" + + "Method Type Parameter: Q.getAnnotation(TC.class): @TC(value=[@T(value=23), @T(value=24)]) \n" + + "Method Type Parameter: Q.getAnnotationByType(TC.class): @TC(value=[@T(value=23), @T(value=24)]) \n" + + "Receiver: .getAnnotationByType(T.class): @T(value=27) @T(value=28) \n" + + "Receiver: .getAnnotation(TC.class): @TC(value=[@T(value=27), @T(value=28)]) \n" + + "Receiver: .getAnnotationByType(TC.class): @TC(value=[@T(value=27), @T(value=28)]) \n" + + "Parameter: .getAnnotationByType(T.class): @T(value=29) @T(value=30) \n" + + "Parameter: .getAnnotation(TC.class): @TC(value=[@T(value=29), @T(value=30)]) \n" + + "Parameter: .getAnnotationByType(TC.class): @TC(value=[@T(value=29), @T(value=30)]) \n" + + "Exception type: .getAnnotationByType(T.class): @T(value=33) @T(value=34) \n" + + "Exception type: .getAnnotation(TC.class): @TC(value=[@T(value=33), @T(value=34)]) \n" + + "Exception type: .getAnnotationByType(TC.class): @TC(value=[@T(value=33), @T(value=34)]) \n" + + "Constructor: .getAnnotationByType(T.class): @T(value=35) @T(value=36) \n" + + "Constructor: .getAnnotation(TC.class): @TC(value=[@T(value=35), @T(value=36)]) \n" + + "Constructor: .getAnnotationByType(TC.class): @TC(value=[@T(value=35), @T(value=36)])"), + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + // Test that bad container specifications are handled properly. + public void testBadContainerType() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.Repeatable;\n" + + "@Repeatable(X.class)\n" + + "@interface T {\n" + + " public int value() default -1;\n" + + "}\n" + + "public class X {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " @Repeatable(X.class)\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from Class to Class\n" + + "----------\n"); + } + // Test unspecified target. + public void testUnspecifiedTarget() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Repeatable;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface TC {\n" + + " T [] value();\n" + + "}\n" + + "\n" + + "@Repeatable(TC.class)\n" + + "@interface T {\n" + + "}\n" + + "\n" + + "@T @T\n" + + "public class X { \n" + + " X f;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " @Repeatable(TC.class)\n" + + " ^^^^^^^^\n" + + "The container annotation type @TC is allowed at targets where the repeatable annotation type @T is not: TYPE_USE\n" + + "----------\n"); + } + // Test unspecified target. + public void testUnspecifiedTarget2() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Repeatable;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_PARAMETER)\n" + + "@interface TC {\n" + + " T [] value();\n" + + "}\n" + + "\n" + + "@Repeatable(TC.class)\n" + + "@interface T {\n" + + "}\n" + + "\n" + + "@T @T\n" + + "public class X { \n" + + " X f;\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " @Repeatable(TC.class)\n" + + " ^^^^^^^^\n" + + "The container annotation type @TC is allowed at targets where the repeatable annotation type @T is not: TYPE_PARAMETER\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " @T @T\n" + + " ^^\n" + + "The annotation @T cannot be repeated at this location since its container annotation type @TC is disallowed at this location\n" + + "----------\n"); + } + public void testDeprecation() { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "TC.java", + "@Deprecated\n" + + "public @interface TC {\n" + + " public T[] value();\n" + + "}\n", + "T.java", + "@java.lang.annotation.Repeatable(TC.class)\n" + + "@interface T {\n" + + " public int value() default -1;\n" + + "}\n" + + "interface I<@T(1) @T(2) K> {\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in T.java (at line 1)\n" + + " @java.lang.annotation.Repeatable(TC.class)\n" + + " ^^\n" + + "The type TC is deprecated\n" + + "----------\n" + + "2. WARNING in T.java (at line 5)\n" + + " interface I<@T(1) @T(2) K> {\n" + + " ^^\n" + + "The type TC is deprecated\n" + + "----------\n"; + runner.javacTestOptions = JavacHasABug.JavacBug8231436_EclipseWarns; + runner.runWarningTest(); + } + public void testDeprecation2() { // verify that deprecation warning does not show up when the deprecated element is used in the same file defining it. + // was negative prior to https://bugs.openjdk.java.net/browse/JDK-8231435 + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "T.java", + "@Deprecated\n" + + "@interface TC {\n" + + " public T[] value();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(TC.class)\n" + + "@interface T {\n" + + " public int value() default -1;\n" + + "}\n" + + "interface I<@T(1) @T(2) K> {\n" + + "}\n" + }; + runner.expectedCompilerLog = ""; + runner.javacTestOptions = JavacHasABug.JavacBug8231436; + runner.runConformTest(); + } + + // 419209: [1.8] Repeating container annotations should be rejected in the presence of annotation it contains + public void testRepeatableWithContaining1() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "A.java", + "@interface FooContainerContainer {\n" + + " public FooContainer[] value();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainerContainer.class)\n" + + "@interface FooContainer {\n" + + " public Foo[] value();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@interface Foo {\n" + + " public int value() default -1;\n" + + "}\n" + + "@FooContainer({@Foo(1)}) @FooContainer({@Foo(2)}) @Foo(3) class A {}\n" + }, + "----------\n" + + "1. WARNING in A.java (at line 12)\n" + + " @FooContainer({@Foo(1)}) @FooContainer({@Foo(2)}) @Foo(3) class A {}\n" + + " ^^^^\n" + + "The repeatable annotation @Foo may not be present where its container annotation type @FooContainer is repeated\n" + + "----------\n"); + } + // 419209: [1.8] Repeating container annotations should be rejected in the presence of annotation it contains + public void testRepeatableWithContaining2() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "A.java", + "@interface FooContainerContainer {\n" + + " public FooContainer[] value();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainerContainer.class)\n" + + "@interface FooContainer {\n" + + " public Foo[] value();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@interface Foo {\n" + + " public int value() default -1;\n" + + "}\n" + + "@Foo(1) @FooContainer({@Foo(2)}) @FooContainer({@Foo(3)}) class A {}\n" + }, + "----------\n" + + "1. WARNING in A.java (at line 12)\n" + + " @Foo(1) @FooContainer({@Foo(2)}) @FooContainer({@Foo(3)}) class A {}\n" + + " ^^^^\n" + + "The repeatable annotation @Foo may not be present where its container annotation type @FooContainer is repeated\n" + + "----------\n"); + } + // 419209: [1.8] Repeating container annotations should be rejected in the presence of annotation it contains + public void testRepeatableWithContaining3() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings, + new String[] { + "A.java", + "@interface FooContainerContainer {\n" + + " public FooContainer[] value();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainerContainer.class)\n" + + "@interface FooContainer {\n" + + " public Foo[] value();\n" + + "}\n" + + "@java.lang.annotation.Repeatable(FooContainer.class)\n" + + "@interface Foo {\n" + + " public int value() default -1;\n" + + "}\n" + + "@FooContainer({@Foo(2)}) @Foo(1) @FooContainer({@Foo(3)}) class A {}\n" + }, + "----------\n" + + "1. WARNING in A.java (at line 12)\n" + + " @FooContainer({@Foo(2)}) @Foo(1) @FooContainer({@Foo(3)}) class A {}\n" + + " ^^^^\n" + + "The repeatable annotation @Foo may not be present where its container annotation type @FooContainer is repeated\n" + + "----------\n"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java new file mode 100644 index 0000000000..5388cfcb40 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Requestor.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Hashtable; + +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.ClassFile; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.ICompilerRequestor; + +@SuppressWarnings({ "rawtypes" }) +public class Requestor implements ICompilerRequestor { + public boolean hasErrors = false; + public String outputPath; + private boolean forceOutputGeneration; + public Hashtable expectedProblems = new Hashtable(); + public String problemLog = ""; + public ICompilerRequestor clientRequestor; + public boolean showCategory = false; + public boolean showWarningToken = false; + +public Requestor(boolean forceOutputGeneration, ICompilerRequestor clientRequestor, boolean showCategory, boolean showWarningToken) { + this.forceOutputGeneration = forceOutputGeneration; + this.clientRequestor = clientRequestor; + this.showCategory = showCategory; + this.showWarningToken = showWarningToken; +} +public void acceptResult(CompilationResult compilationResult) { + this.hasErrors |= compilationResult.hasErrors(); + this.problemLog += Util.getProblemLog(compilationResult, this.showCategory, this.showWarningToken); + outputClassFiles(compilationResult); + if (this.clientRequestor != null) { + this.clientRequestor.acceptResult(compilationResult); + } +} +protected void outputClassFiles(CompilationResult unitResult) { + if ((unitResult != null) && (!unitResult.hasErrors() || this.forceOutputGeneration)) { + ClassFile[] classFiles = unitResult.getClassFiles(); + if (this.outputPath != null) { + for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) { + // retrieve the key and the corresponding classfile + ClassFile classFile = classFiles[i]; + String relativeName = + new String(classFile.fileName()).replace('/', File.separatorChar) + ".class"; + try { + org.eclipse.jdt.internal.compiler.util.Util.writeToDisk(true, this.outputPath, relativeName, classFile); + } catch(IOException e) { + e.printStackTrace(); + } + } + } + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java new file mode 100644 index 0000000000..3795a05b81 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ResourceLeakTests.java @@ -0,0 +1,6998 @@ +/******************************************************************************* + * Copyright (c) 2011, 2020 GK Software SE and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Stephan Herrmann - initial API and implementation + * Nikolay Metchev (nikolaymetchev@gmail.com) - Contributions for + * bug 411098 - [compiler][resource] Invalid Resource Leak Warning using ternary operator inside try-with-resource + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.IOException; +import java.net.URL; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.IrritantSet; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class ResourceLeakTests extends AbstractRegressionTest { + +// well-known helper classes: +private static final String GUAVA_CLOSEABLES_JAVA = "com/google/common/io/Closeables.java"; +private static final String GUAVA_CLOSEABLES_CONTENT = "package com.google.common.io;\n" + + "public class Closeables {\n" + + " public static void closeQuietly(java.io.Closeable closeable) {}\n" + + " public static void close(java.io.Closeable closeable, boolean flag) {}\n" + + "}\n"; +private static final String APACHE_DBUTILS_JAVA = "org/apache/commons/dbutils/DbUtils.java"; +private static final String APACHE_DBUTILS_CONTENT = "package org.apache.commons.dbutils;\n" + + "import java.sql.*;\n" + + "public class DbUtils {\n" + + " public static void close(Connection connection) {}\n" + + " public static void close(ResultSet resultSet) {}\n" + + " public static void close(Statement statement) {}\n" + + " public static void closeQuietly(Connection connection) {}\n" + + " public static void closeQuietly(ResultSet resultSet) {}\n" + + " public static void closeQuietly(Statement statement) {}\n" + + " public static void closeQuietly(Connection conn, Statement stmt, ResultSet rs) {}\n" + + "}\n"; + +// one.util.streamex.StreamEx stub +private static final String STREAMEX_JAVA = "one/util/streamex/StreamEx.java"; +private static final String STREAMEX_CONTENT = "package one.util.streamex;\n" + + "import java.util.stream.*;\n" + + "public abstract class StreamEx implements Stream {\n" + + " public static StreamEx create() { return null; }\n" + + "}\n"; + +static { +// TESTS_NAMES = new String[] { "testBug463320" }; +// TESTS_NUMBERS = new int[] { 50 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public ResourceLeakTests(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(ResourceLeakTests.class); +} + +void runTestsExpectingErrorsOnlyIn17(String[] testFiles, String errorsIn17, Map options) { + if (this.complianceLevel >= ClassFileConstants.JDK1_7) + runLeakTest(testFiles, errorsIn17, options); + else + runConformTest(testFiles, "", null, true, null, options, null); +} + +protected void runLeakTest(String[] testFiles, String expectedCompileError, Map options) { + runNegativeTest(testFiles, expectedCompileError, null, true, options, null, JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); +} + +protected void runLeakWarningTest(String[] testFiles, String expectedCompileError, Map options) { + runNegativeTest(testFiles, expectedCompileError, null, true, options, null, JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +// Bug 349326 - [1.7] new warning for missing try-with-resources +// a method uses an AutoCloseable without ever closing it. +public void test056() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + runLeakTest( + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + +// not invoking any methods on FileReader, try to avoid necessary call to superclass() in the compiler +// " char[] in = new char[50];\n" + +// " fileReader.read(in);\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " FileReader fileReader = new FileReader(file);\n" + + " ^^^^^^^^^^\n" + + "Resource leak: 'fileReader' is never closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// a method uses an AutoCloseable and closes it but not protected by t-w-r nor regular try-finally +public void test056a() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runTestsExpectingErrorsOnlyIn17( + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " fileReader.close();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " FileReader fileReader = new FileReader(file);\n" + + " ^^^^^^^^^^\n" + + "Resource 'fileReader' should be managed by try-with-resource\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// a method uses an AutoCloseable and closes it properly in a finally block +public void test056b() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " try {\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " } finally {\n" + + " fileReader.close();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().foo();\n" + + " } catch (IOException ioex) {\n" + + " System.out.println(\"caught\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "caught", /*output*/ + null/*classLibs*/, + true/*shouldFlush*/, + null/*vmargs*/, + options, + null/*requestor*/); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// a method uses an AutoCloseable properly within try-with-resources. +public void test056c() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " try (FileReader fileReader = new FileReader(file)) {\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().foo();\n" + + " } catch (IOException ioex) {\n" + + " System.out.println(\"caught\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "caught", /*output*/ + null/*classLibs*/, + true/*shouldFlush*/, + null/*vmargs*/, + options, + null/*requestor*/); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// a method uses two AutoCloseables (testing independent analysis) +//- one closeable may be unclosed at a conditional return +//- the other is only conditionally closed +public void test056d() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + runLeakTest( + 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(boolean flag1, boolean flag2) throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " char[] in = new char[50];\n" + + " FileReader fileReader1 = new FileReader(file);\n" + + " fileReader1.read(in);\n" + + " FileReader fileReader2 = new FileReader(file);\n" + + " fileReader2.read(in);\n" + + " if (flag1) {\n" + + " fileReader2.close();\n" + + " return;\n" + + " } else if (flag2) {\n" + + " fileReader2.close();\n" + + " }\n" + + " fileReader1.close();\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo(false, true);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " FileReader fileReader2 = new FileReader(file);\n" + + " ^^^^^^^^^^^\n" + + "Potential resource leak: 'fileReader2' may not be closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Resource leak: 'fileReader1' is not closed at this location\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// a method uses two AutoCloseables (testing independent analysis) +//- one closeable may be unclosed at a conditional return +//- the other is only conditionally closed +public void test056d_suppress() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // annotations used + Map options = getCompilerOptions(); + enableAllWarningsForIrritants(options, IrritantSet.RESOURCE); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + runLeakTest( + 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(boolean flag1, boolean flag2) throws IOException {\n" + + " @SuppressWarnings(\"resource\") File file = new File(\"somefile\"); // unnecessary suppress\n" + + " char[] in = new char[50];\n" + + " FileReader fileReader1 = new FileReader(file);\n" + + " fileReader1.read(in);\n" + + " @SuppressWarnings(\"resource\") FileReader fileReader2 = new FileReader(file); // useful suppress\n" + + " fileReader2.read(in);\n" + + " if (flag1) {\n" + + " fileReader2.close();\n" + + " return; // not suppressed\n" + + " } else if (flag2) {\n" + + " fileReader2.close();\n" + + " }\n" + + " fileReader1.close();\n" + + " }\n" + + " @SuppressWarnings(\"resource\") // useful suppress\n" + + " void bar() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo(false, true);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " @SuppressWarnings(\"resource\") File file = new File(\"somefile\"); // unnecessary suppress\n" + + " ^^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"resource\")\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " return; // not suppressed\n" + + " ^^^^^^^\n" + + "Resource leak: 'fileReader1' is not closed at this location\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// Bug 362332 - Only report potential leak when closeable not created in the local scope +// one method returns an AutoCleasble, a second method uses this object without ever closing it. +public void test056e() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileReader;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " FileReader getReader(String filename) throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " return fileReader;\n" + // don't complain here, pass responsibility to caller + " }\n" + + " void foo() throws IOException {\n" + + " FileReader reader = getReader(\"somefile\");\n" + + " char[] in = new char[50];\n" + + " reader.read(in);\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " FileReader reader = getReader(\"somefile\");\n" + + " ^^^^^^\n" + + "Potential resource leak: \'reader\' may not be closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// a method explicitly closes its AutoCloseable rather than using t-w-r +public void test056f() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runTestsExpectingErrorsOnlyIn17( + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = null;\n" + + " try {\n" + + " fileReader = new FileReader(file);\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " } finally {\n" + + " fileReader.close();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " FileReader fileReader = null;\n" + + " ^^^^^^^^^^\n" + + "Resource 'fileReader' should be managed by try-with-resource\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// an AutoCloseable local is re-assigned +public void test056g() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.IGNORE); + runLeakTest( + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " fileReader = new FileReader(file);\n" + + " fileReader.read(in);\n" + + " fileReader.close();\n" + + " fileReader = null;\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " fileReader = new FileReader(file);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: 'fileReader' is not closed at this location\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// an AutoCloseable local is re-assigned after null-assigned +public void test056g2() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.IGNORE); + runLeakTest( + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " fileReader = null;\n" + + " fileReader = new FileReader(file);\n" + // don't complain again, fileReader is null, so nothing can leak here + " fileReader.read(in);\n" + + " fileReader.close();\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " fileReader = null;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Resource leak: 'fileReader' is not closed at this location\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// two AutoCloseables at different nesting levels (anonymous local type) +public void test056h() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.IGNORE); + runLeakTest( + 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() throws IOException {\n" + + " final File file = new File(\"somefile\");\n" + + " final FileReader fileReader = new FileReader(file);\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " new Runnable() {\n public void run() {\n" + + " try {\n" + + " fileReader.close();\n" + + " FileReader localReader = new FileReader(file);\n" + + " } catch (IOException ex) { /* nop */ }\n" + + " }}.run();\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " final FileReader fileReader = new FileReader(file);\n" + + " ^^^^^^^^^^\n" + + "Potential resource leak: 'fileReader' may not be closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " FileReader localReader = new FileReader(file);\n" + + " ^^^^^^^^^^^\n" + + "Resource leak: 'localReader' is never closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// three AutoCloseables in different blocks of the same method +public void test056i() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.IGNORE); + runLeakTest( + 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(boolean f1, boolean f2) throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " if (f1) {\n" + + " FileReader fileReader = new FileReader(file); // err: not closed\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " while (true) {\n" + + " FileReader loopReader = new FileReader(file); // don't warn, properly closed\n" + + " loopReader.close();" + + " break;\n" + + " }\n" + + " } else {\n" + + " FileReader fileReader = new FileReader(file); // warn: not closed on all paths\n" + + " if (f2)\n" + + " fileReader.close();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo(true, true);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " FileReader fileReader = new FileReader(file); // err: not closed\n" + + " ^^^^^^^^^^\n" + + "Resource leak: 'fileReader' is never closed\n" + + "----------\n" + + "2. WARNING in X.java (at line 16)\n" + + " FileReader fileReader = new FileReader(file); // warn: not closed on all paths\n" + + " ^^^^^^^^^^\n" + + "Potential resource leak: 'fileReader' may not be closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// three AutoCloseables in different blocks of the same method - problems ignored +public void test056i_ignore() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.IGNORE); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.IGNORE); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.IGNORE); + 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(boolean f1, boolean f2) throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " if (f1) {\n" + + " FileReader fileReader = new FileReader(file); // err: not closed\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " while (true) {\n" + + " FileReader loopReader = new FileReader(file); // don't warn, properly closed\n" + + " loopReader.close();" + + " break;\n" + + " }\n" + + " } else {\n" + + " FileReader fileReader = new FileReader(file); // warn: not closed on all paths\n" + + " if (f2)\n" + + " fileReader.close();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// three AutoCloseables in different blocks of the same method +public void test056i2() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.IGNORE); + runLeakTest( + 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(boolean f1, boolean f2) throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " if (f1) {\n" + + " FileReader fileReader = new FileReader(file); // properly closed\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " while (true) {\n" + + " fileReader.close();\n" + + " FileReader loopReader = new FileReader(file); // don't warn, properly closed\n" + + " loopReader.close();\n" + + " break;\n" + + " }\n" + + " } else {\n" + + " FileReader fileReader = new FileReader(file); // warn: not closed on all paths\n" + + " if (f2)\n" + + " fileReader.close();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo(true, true);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " FileReader fileReader = new FileReader(file); // warn: not closed on all paths\n" + + " ^^^^^^^^^^\n" + + "Potential resource leak: 'fileReader' may not be closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// a method uses an AutoCloseable without closing it locally but passing as arg to another method +public void test056j() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " read(fileReader);\n" + + " }\n" + + " void read(FileReader reader) { }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " FileReader fileReader = new FileReader(file);\n" + + " ^^^^^^^^^^\n" + + "Potential resource leak: 'fileReader' may not be closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// a method uses an AutoCloseable without closing it locally but passing as arg to another method +public void test056jconditional() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + 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(boolean b) throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " synchronized (b ? this : new X()) {\n" + + " new ReadDelegator(fileReader);\n" + + " }\n" + + " }\n" + + " class ReadDelegator { ReadDelegator(FileReader reader) { } }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo(true);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " FileReader fileReader = new FileReader(file);\n" + + " ^^^^^^^^^^\n" + + "Potential resource leak: 'fileReader' may not be closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// many locals, some are AutoCloseable. +// Unfortunately analysis cannot respect how exception exits may affect ra3 and rb3, +// doing so would create false positives. +public void test056k() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + String expectedProblems = this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " ra2 = new FileReader(file);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'ra2\' is never closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 28)\n" + + " rb2 = new FileReader(file);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'rb2\' is never closed\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " FileReader ra1 = null, ra2 = null;\n" + + " ^^^\n" + + "Resource 'ra1' should be managed by try-with-resource\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " ra2 = new FileReader(file);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: 'ra2' is never closed\n" + + "----------\n" + + "3. ERROR in X.java (at line 16)\n" + + " FileReader ra3 = new FileReader(file);\n" + + " ^^^\n" + + "Resource 'ra3' should be managed by try-with-resource\n" + + "----------\n" + + "4. ERROR in X.java (at line 25)\n" + + " FileReader rb1 = null, rb2 = null;\n" + + " ^^^\n" + + "Resource 'rb1' should be managed by try-with-resource\n" + + "----------\n" + + "5. ERROR in X.java (at line 28)\n" + + " rb2 = new FileReader(file);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: 'rb2' is never closed\n" + + "----------\n" + + "6. ERROR in X.java (at line 29)\n" + + " FileReader rb3 = new FileReader(file);\n" + + " ^^^\n" + + "Resource 'rb3' should be managed by try-with-resource\n" + + "----------\n"; + runLeakTest( + 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() throws IOException {\n" + + " int i01, i02, i03, i04, i05, i06, i07, i08, i09,\n" + + " i11, i12, i13, i14, i15, i16, i17, i18, i19,\n" + + " i21, i22, i23, i24, i25, i26, i27, i28, i29,\n" + + " i31, i32, i33, i34, i35, i36, i37, i38, i39,\n" + + " i41, i42, i43, i44, i45, i46, i47, i48, i49;\n" + + " File file = new File(\"somefile\");\n" + + " FileReader ra1 = null, ra2 = null;\n" + + " try {\n" + + " ra1 = new FileReader(file);\n" + + " ra2 = new FileReader(file);\n" + + " FileReader ra3 = new FileReader(file);\n" + + " char[] in = new char[50];\n" + + " ra1.read(in);\n" + + " ra2.read(in);\n" + + " ra3.close();\n" + + " } finally {\n" + + " ra1.close();\n" + + " }\n" + + " int i51, i52, i53, i54, i55, i56, i57, i58, i59, i60;\n" + // beyond this point locals are analyzed using extraBits + " FileReader rb1 = null, rb2 = null;\n" + + " try {\n" + + " rb1 = new FileReader(file);\n" + + " rb2 = new FileReader(file);\n" + + " FileReader rb3 = new FileReader(file);\n" + + " char[] in = new char[50];\n" + + " rb1.read(in);\n" + + " rb2.read(in);\n" + + " rb3.close();\n" + + " } finally {\n" + + " rb1.close();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + expectedProblems, + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// various non-problems +public void test056l() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + String expectedProblems = this.complianceLevel >= ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " FileReader fileReader = getReader();\n" + + " ^^^^^^^^^^\n" + + "Resource 'fileReader' should be managed by try-with-resource\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " FileReader r3 = getReader();\n" + + " ^^\n" + + "Resource 'r3' should be managed by try-with-resource\n" + + "----------\n" + + "3. ERROR in X.java (at line 24)\n" + + " FileReader r2 = new FileReader(new File(\"inexist\")); // only potential problem: ctor X below might close r2\n" + + " ^^\n" + + "Potential resource leak: 'r2' may not be closed\n" + + "----------\n" + + "4. ERROR in X.java (at line 25)\n" + + " new X(r2).foo(new FileReader(new File(\"notthere\"))); // potential problem: foo may/may not close the new FileReader\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in X.java (at line 24)\n" + + " FileReader r2 = new FileReader(new File(\"inexist\")); // only potential problem: ctor X below might close r2\n" + + " ^^\n" + + "Potential resource leak: 'r2' may not be closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 25)\n" + + " new X(r2).foo(new FileReader(new File(\"notthere\"))); // potential problem: foo may/may not close the new FileReader\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n"; + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileReader;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " X(FileReader r0) {}\n" + // don't complain against argument + " FileReader getReader() { return null; }\n" + + " void foo(FileReader r1) throws IOException {\n" + + " FileReader fileReader = getReader();\n" + + " if (fileReader == null)\n" + + " return;\n" + // don't complain, resource is actually null + " FileReader r3 = getReader();\n" + + " if (r3 == null)\n" + + " r3 = new FileReader(new File(\"absent\"));\n" + // don't complain, previous resource is actually null + " try {\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " r1.read(in);\n" + + " } finally {\n" + + " fileReader.close();\n" + + " r3.close();\n" + // the effect of this close() call might be spoiled by exception in fileReader.close() above, but we ignore exception exits in the analysis + " }\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " FileReader r2 = new FileReader(new File(\"inexist\")); // only potential problem: ctor X below might close r2\n" + + " new X(r2).foo(new FileReader(new File(\"notthere\"))); // potential problem: foo may/may not close the new FileReader\n" + + " }\n" + + "}\n" + }, + expectedProblems, + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// nested try with early exit +public void test056m() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + 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\");" + + " try {\n" + + " FileReader fileReader = new FileReader(file);\n" + + " try {\n" + + " char[] in = new char[50];\n" + + " if (fileReader.read(in)==0)\n" + + " return;\n" + + " } finally {\n" + + " fileReader.close();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " System.out.println(\"caught\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "caught", /*output*/ + null/*classLibs*/, + true/*shouldFlush*/, + null/*vmargs*/, + options, + null/*requestor*/); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// nested try should not interfere with earlier analysis. +public void test056n() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileReader;\n" + + "import java.io.IOException;\n" + + "import java.io.FileNotFoundException;\n" + + "public class X {\n" + + " void foo(File someFile, char[] buf) throws IOException {\n" + + " FileReader fr1 = new FileReader(someFile);\n" + + " try {\n" + + " fr1.read(buf);\n" + + " } finally {\n" + + " fr1.close();\n" + + " }\n" + + " try {\n" + + " FileReader fr3 = new FileReader(someFile);\n" + + " try {\n" + + " } finally {\n" + + " fr3.close();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " try {\n" + + " new X().foo(new File(\"missing\"), new char[100]);\n" + + " } catch (FileNotFoundException e) {\n" + + " System.out.println(\"caught\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "caught", /*output*/ + null/*classLibs*/, + true/*shouldFlush*/, + null/*vmargs*/, + options, + null/*requestor*/); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// if close is guarded by null check this should still be recognized as definitely closed +public void test056o() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileReader;\n" + + "import java.io.IOException;\n" + + "import java.io.FileNotFoundException;\n" + + "public class X {\n" + + " void foo(File someFile, char[] buf) throws IOException {\n" + + " FileReader fr1 = null;\n" + + " try {\n" + + " fr1 = new FileReader(someFile);" + + " fr1.read(buf);\n" + + " } finally {\n" + + " if (fr1 != null)\n" + + " try {\n" + + " fr1.close();\n" + + " } catch (IOException e) { /*do nothing*/ }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " try {\n" + + " new X().foo(new File(\"missing\"), new char[100]);\n" + + " } catch (FileNotFoundException e) {\n" + + " System.out.println(\"caught\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "caught", /*output*/ + null/*classLibs*/, + true/*shouldFlush*/, + null/*vmargs*/, + options, + null/*requestor*/); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// Bug 362332 - Only report potential leak when closeable not created in the local scope +// a method uses an AutoCloseable without ever closing it, type from a type variable +public void test056p() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // generics used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileReader;\n" + + "import java.io.Reader;\n" + + "import java.io.IOException;\n" + + "public abstract class X {\n" + + " void foo() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " T fileReader = newReader(file);\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " }\n" + + " abstract T newReader(File file) throws IOException;\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X() {\n" + + " FileReader newReader(File f) throws IOException { return new FileReader(f); }\n" + + " }.foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " T fileReader = newReader(file);\n" + + " ^^^^^^^^^^\n" + + "Potential resource leak: \'fileReader\' may not be closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// closed in dead code +public void test056q() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.IGNORE); + runLeakTest( + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " if (2*2 == 4)\n" + + " return;\n" + + " fileReader.close();\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " FileReader fileReader = new FileReader(file);\n" + + " ^^^^^^^^^^\n" + + "Resource leak: 'fileReader' is never closed\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " if (2*2 == 4)\n" + + " ^^^^^^^^\n" + + "Comparing identical expressions\n" + + "----------\n" + + "3. WARNING in X.java (at line 12)\n" + + " fileReader.close();\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// properly closed, dead code in between +public void test056r() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.IGNORE); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakTest( + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fr = new FileReader(file);\n" + + " Object b = null;\n" + + " fr.close();\n" + + " if (b != null) {\n" + + " fr = new FileReader(file);\n" + + " return;\n" + + " } else {\n" + + " System.out.print(42);\n" + + " }\n" + + " return; // Should not complain about fr\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " if (b != null) {\n" + + " fr = new FileReader(file);\n" + + " return;\n" + + " } else {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " } else {\n" + + " System.out.print(42);\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Statement unnecessarily nested within else clause. The corresponding then clause does not complete normally\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// resource inside t-w-r is re-assigned, shouldn't even record an errorLocation +public void test056s() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.IGNORE); + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " try (FileReader fileReader = new FileReader(file);) {\n" + + " char[] in = new char[50];\n" + + " fileReader.read(in);\n" + + " fileReader = new FileReader(file); // debug here\n" + + " fileReader.read(in);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " fileReader = new FileReader(file); // debug here\n" + + " ^^^^^^^^^^\n" + + "The resource fileReader of a try-with-resources statement cannot be assigned\n" + + "----------\n", + null, + true, + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// resource is closed, dead code follows +public void test056t() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo31() throws IOException {\n" + + " FileReader reader = new FileReader(\"file\"); //warning\n" + + " if (reader != null) {\n" + + " reader.close();\n" + + " } else {\n" + + " // nop\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo31();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " } else {\n" + + " // nop\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// resource is reassigned within t-w-r with different resource +// was initially broken due to https://bugs.eclipse.org/358827 +public void test056u() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo() throws Exception {\n" + + " FileReader reader1 = new FileReader(\"file1\");\n" + + " FileReader reader2 = new FileReader(\"file2\");\n" + + " reader2 = reader1;// this disconnects reader 2\n" + + " try (FileReader reader3 = new FileReader(\"file3\")) {\n" + + " int ch;\n" + + " while ((ch = reader2.read()) != -1) {\n" + + " System.out.println(ch);\n" + + " reader1.read();\n" + + " }\n" + + " reader2 = reader1; // warning 1 regarding original reader1\n" + // this warning was missing + " reader2 = reader1; // warning 2 regarding original reader1\n" + + " } finally {\n" + + " if (reader2 != null) {\n" + + " reader2.close();\n" + + " } else {\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " FileReader reader2 = new FileReader(\"file2\");\n" + + " ^^^^^^^\n" + + "Resource leak: 'reader2' is never closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " reader2 = reader1; // warning 1 regarding original reader1\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Resource leak: 'reader1' is not closed at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " reader2 = reader1; // warning 2 regarding original reader1\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Resource leak: 'reader1' is not closed at this location\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// scope-related pbs reported in https://bugs.eclipse.org/349326#c70 and https://bugs.eclipse.org/349326#c82 +public void test056v() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + String expectedProblems = this.complianceLevel >= ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " FileReader reader = new FileReader(\"file\");\n" + + " ^^^^^^\n" + + "Resource leak: 'reader' is never closed\n" + + "----------\n" + + "2. WARNING in X.java (at line 19)\n" + + " FileReader reader111 = new FileReader(\"file2\");\n" + + " ^^^^^^^^^\n" + + "Resource 'reader111' should be managed by try-with-resource\n" + + "----------\n" + + "3. ERROR in X.java (at line 42)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Resource leak: 'reader2' is not closed at this location\n" + + "----------\n" + : + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " FileReader reader = new FileReader(\"file\");\n" + + " ^^^^^^\n" + + "Resource leak: 'reader' is never closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 42)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Resource leak: 'reader2' is not closed at this location\n" + + "----------\n"; + runLeakTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " boolean foo1() throws Exception {\n" + + " FileReader reader = new FileReader(\"file\");\n" + + " try {\n" + + " int ch;\n" + + " while ((ch = reader.read()) != -1) {\n" + + " System.out.println(ch);\n" + + " reader.read();\n" + + " }\n" + + " if (ch > 10) {\n" + + " return true;\n" + + " }\n" + + " return false;\n" + // return while resource from enclosing scope remains unclosed + " } finally {\n" + + " }\n" + + " }\n" + + " void foo111() throws Exception {\n" + + " FileReader reader111 = new FileReader(\"file2\");\n" + + " try {\n" + + " int ch;\n" + + " while ((ch = reader111.read()) != -1) {\n" + + " System.out.println(ch);\n" + + " reader111.read();\n" + + " }\n" + + " return;\n" + // this shouldn't spoil the warning "should be managed with t-w-r" + " } finally {\n" + + " if (reader111 != null) {\n" + + " reader111.close();\n" + + " }\n" + + " }\n" + + " }\n" + + " void foo2() throws Exception {\n" + + " FileReader reader2 = new FileReader(\"file\");\n" + + " try {\n" + + " int ch;\n" + + " while ((ch = reader2.read()) != -1) {\n" + + " System.out.println(ch);\n" + + " reader2.read();\n" + + " }\n" + + " if (ch > 10) {\n" + + " return;\n" + // potential leak + " }\n" + + " } finally {\n" + + " }\n" + + " reader2.close();\n" + // due to this close we don't say "never closed" + " }\n" + + "}\n" + }, + expectedProblems, + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// end of method is dead end, but before we have both a close() and an early return +public void test056w() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " boolean foo1() throws Exception {\n" + + " FileReader reader = new FileReader(\"file\");\n" + + " try {\n" + + " int ch;\n" + + " while ((ch = reader.read()) != -1) {\n" + + " System.out.println(ch);\n" + + " reader.read();\n" + + " }\n" + + " if (ch > 10) {\n" + + " reader.close();\n" + + " return true;\n" + + " }\n" + + " return false;\n" + + " } finally {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " return false;\n" + + " ^^^^^^^^^^^^^\n" + + "Resource leak: 'reader' is not closed at this location\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// different early exits, if no close seen report as definitely unclosed +public void test056x() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo31(boolean b) throws Exception {\n" + + " FileReader reader = new FileReader(\"file\");\n" + + " if (b) {\n" + + " reader.close();\n" + + " } else {\n" + + " return; // warning\n" + + " }\n" + + " }\n" + + " void foo32(boolean b) throws Exception {\n" + + " FileReader reader = new FileReader(\"file\"); // warn here\n" + + " return;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " return; // warning\n" + + " ^^^^^^^\n" + + "Resource leak: 'reader' is not closed at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " FileReader reader = new FileReader(\"file\"); // warn here\n" + + " ^^^^^^\n" + + "Resource leak: 'reader' is never closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// nested method passes the resource to outside code +public void test056y() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.WARNING); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakWarningTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo31(boolean b) throws Exception {\n" + + " final FileReader reader31 = new FileReader(\"file\");\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " foo18(reader31);\n" + + " }\n" + + " }.run();\n" + + " }\n" + + " void foo18(FileReader r18) {\n" + + " // could theoretically close r18;\n" + + " }\n" + + " abstract class ResourceProvider {\n" + + " abstract FileReader provide();" + + " }\n" + + " ResourceProvider provider;" + + " void foo23() throws Exception {\n" + + " final FileReader reader23 = new FileReader(\"file\");\n" + + " provider = new ResourceProvider() {\n" + + " public FileReader provide() {\n" + + " return reader23;\n" + // responsibility now lies at the caller of this method + " }\n" + + " };\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " final FileReader reader31 = new FileReader(\"file\");\n" + + " ^^^^^^^^\n" + + "Potential resource leak: 'reader31' may not be closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// resource assigned to second local and is (potentially) closed on the latter +public void test056z() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo17() throws Exception {\n" + + " FileReader reader17 = new FileReader(\"file\");\n" + + " final FileReader readerCopy = reader17;\n" + + " readerCopy.close();\n" + + " }\n" + + " void foo17a() throws Exception {\n" + + " FileReader reader17a = new FileReader(\"file\");\n" + + " FileReader readerCopya;" + + " readerCopya = reader17a;\n" + + " bar(readerCopya);\n" + // potentially closes + " }\n" + + " void bar(FileReader r) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " FileReader reader17a = new FileReader(\"file\");\n" + + " ^^^^^^^^^\n" + + "Potential resource leak: 'reader17a' may not be closed\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// multiple early exists from nested scopes (always closed) +public void test056zz() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runTestsExpectingErrorsOnlyIn17( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo16() throws Exception {\n" + + " FileReader reader16 = new FileReader(\"file\");\n" + + " try {\n" + + " reader16.close();\n " + + " return;\n" + + " } catch (RuntimeException re) {\n" + + " return;\n" + + " } catch (Error e) {\n" + + " return;\n" + + " } finally {\n" + + " reader16.close();\n " + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " FileReader reader16 = new FileReader(\"file\");\n" + + " ^^^^^^^^\n" + + "Resource 'reader16' should be managed by try-with-resource\n" + + "----------\n", + options); +} +// Bug 349326 - [1.7] new warning for missing try-with-resources +// multiple early exists from nested scopes (never closed) +public void test056zzz() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo16() throws Exception {\n" + + " FileReader reader16 = new FileReader(\"file\");\n" + + " try {\n" + + " return;\n" + + " } catch (RuntimeException re) {\n" + + " return;\n" + + " } catch (Error e) {\n" + + " return;\n" + + " } finally {\n" + + " System.out.println();\n " + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " FileReader reader16 = new FileReader(\"file\");\n" + + " ^^^^^^^^\n" + + "Resource leak: 'reader16' is never closed\n" + + "----------\n", + options); +} +// Bug 359334 - Analysis for resource leak warnings does not consider exceptions as method exit points +// explicit throw is a true method exit here +public void test056throw1() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo2(boolean a, boolean b, boolean c) throws Exception {\n" + + " FileReader reader = new FileReader(\"file\");\n" + + " if(a)\n" + + " throw new Exception(); //warning 1\n" + + " else if (b)\n" + + " reader.close();\n" + + " else if(c)\n" + + " throw new Exception(); //warning 2\n" + + " reader.close();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " throw new Exception(); //warning 1\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: 'reader' is not closed at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " throw new Exception(); //warning 2\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: 'reader' is not closed at this location\n" + + "----------\n", + options); +} +// Bug 359334 - Analysis for resource leak warnings does not consider exceptions as method exit points +// close() within finally provides protection for throw +public void test056throw2() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runTestsExpectingErrorsOnlyIn17( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo1() throws Exception {\n" + + " FileReader reader = new FileReader(\"file\"); // propose t-w-r\n" + + " try {\n" + + " reader.read();\n" + + " return;\n" + + " } catch (Exception e) {\n" + + " throw new Exception();\n" + + " } finally {\n" + + " reader.close();\n" + + " }\n" + + " }\n" + + "\n" + + " void foo2() throws Exception {\n" + + " FileReader reader = new FileReader(\"file\"); // propose t-w-r\n" + + " try {\n" + + " reader.read();\n" + + " throw new Exception(); // should not warn here\n" + + " } catch (Exception e) {\n" + + " throw new Exception();\n" + + " } finally {\n" + + " reader.close();\n" + + " }\n" + + " }\n" + + "\n" + + " void foo3() throws Exception {\n" + + " FileReader reader = new FileReader(\"file\"); // propose t-w-r\n" + + " try {\n" + + " reader.read();\n" + + " throw new Exception();\n" + + " } finally {\n" + + " reader.close();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " FileReader reader = new FileReader(\"file\"); // propose t-w-r\n" + + " ^^^^^^\n" + + "Resource 'reader' should be managed by try-with-resource\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " FileReader reader = new FileReader(\"file\"); // propose t-w-r\n" + + " ^^^^^^\n" + + "Resource 'reader' should be managed by try-with-resource\n" + + "----------\n" + + "3. ERROR in X.java (at line 28)\n" + + " FileReader reader = new FileReader(\"file\"); // propose t-w-r\n" + + " ^^^^^^\n" + + "Resource 'reader' should be managed by try-with-resource\n" + + "----------\n", + options); +} +// Bug 359334 - Analysis for resource leak warnings does not consider exceptions as method exit points +// close() nested within finally provides protection for throw +public void test056throw3() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runTestsExpectingErrorsOnlyIn17( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo2x() throws Exception {\n" + + " FileReader reader = new FileReader(\"file\"); // propose t-w-r\n" + + " try {\n" + + " reader.read();\n" + + " throw new Exception(); // should not warn here\n" + + " } catch (Exception e) {\n" + + " throw new Exception();\n" + + " } finally {\n" + + " if (reader != null)\n" + + " try {\n" + + " reader.close();\n" + + " } catch (java.io.IOException io) {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " FileReader reader = new FileReader(\"file\"); // propose t-w-r\n" + + " ^^^^^^\n" + + "Resource 'reader' should be managed by try-with-resource\n" + + "----------\n", + options); +} +// Bug 359334 - Analysis for resource leak warnings does not consider exceptions as method exit points +// additional boolean should shed doubt on whether we reach the close() call +public void test056throw4() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo2x(boolean b) throws Exception {\n" + + " FileReader reader = new FileReader(\"file\");\n" + + " try {\n" + + " reader.read();\n" + + " throw new Exception(); // should warn here\n" + + " } catch (Exception e) {\n" + + " throw new Exception(); // should warn here\n" + + " } finally {\n" + + " if (reader != null && b)\n" + // this condition is too strong to protect reader + " try {\n" + + " reader.close();\n" + + " } catch (java.io.IOException io) {}\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " throw new Exception(); // should warn here\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: 'reader' may not be closed at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " throw new Exception(); // should warn here\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: 'reader' may not be closed at this location\n" + + "----------\n", + options); +} +// Bug 359334 - Analysis for resource leak warnings does not consider exceptions as method exit points +// similar to test056throw3() but indirectly calling close(), so doubts remain. +public void test056throw5() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_EXPLICITLY_CLOSED_AUTOCLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_DEAD_CODE, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.FileReader;\n" + + "public class X {\n" + + " void foo2x() throws Exception {\n" + + " FileReader reader = new FileReader(\"file\");\n" + + " try {\n" + + " reader.read();\n" + + " throw new Exception(); // should warn 'may not' here\n" + + " } catch (Exception e) {\n" + + " throw new Exception(); // should warn 'may not' here\n" + + " } finally {\n" + + " doClose(reader);\n" + + " }\n" + + " }\n" + + " void doClose(FileReader r) { try { r.close(); } catch (java.io.IOException ex) {}}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " throw new Exception(); // should warn \'may not\' here\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: 'reader' may not be closed at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " throw new Exception(); // should warn \'may not\' here\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: 'reader' may not be closed at this location\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// Bug 360908 - Avoid resource leak warning when the underlying/chained resource is closed explicitly +// a resource wrapper is not closed but the underlying resource is +public void test061a() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileInputStream fileStream = new FileInputStream(file);\n" + + " BufferedInputStream bis = new BufferedInputStream(fileStream);\n" + + " BufferedInputStream doubleWrap = new BufferedInputStream(bis);\n" + + " System.out.println(bis.available());\n" + + " fileStream.close();\n" + + " }\n" + + " void inline() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileInputStream fileStream;\n" + + " BufferedInputStream bis = new BufferedInputStream(fileStream = new FileInputStream(file));\n" + + " System.out.println(bis.available());\n" + + " fileStream.close();\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " try {\n" + + " new X().foo();\n" + + " } catch (IOException ex) {" + + " System.out.println(\"Got IO Exception\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "Got IO Exception", + null, + true, + null, + options, + null); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a closeable without OS resource is not closed +public void test061b() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.StringReader;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " StringReader string = new StringReader(\"content\");\n" + + " System.out.println(string.read());\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "99", // character 'c' + null, + true, + null, + options, + null); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a resource wrapper is not closed but the underlying closeable is resource-free +public void test061c() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.BufferedReader;\n" + + "import java.io.StringReader;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " StringReader input = new StringReader(\"content\");\n" + + " BufferedReader br = new BufferedReader(input);\n" + + " BufferedReader doubleWrap = new BufferedReader(br);\n" + + " System.out.println(br.read());\n" + + " }\n" + + " void inline() throws IOException {\n" + + " BufferedReader br = new BufferedReader(new StringReader(\"content\"));\n" + + " System.out.println(br.read());\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "99", + null, + true, + null, + options, + null); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a resource wrapper is not closed neither is the underlying resource +public void test061d() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileInputStream fileStream = new FileInputStream(file);\n" + + " BufferedInputStream bis = new BufferedInputStream(fileStream);\n" + + " BufferedInputStream doubleWrap = new BufferedInputStream(bis);\n" + + " System.out.println(bis.available());\n" + + " }\n" + + " void inline() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " BufferedInputStream bis2 = new BufferedInputStream(new FileInputStream(file));\n" + + " System.out.println(bis2.available());\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " try {\n" + + " new X().foo();\n" + + " } catch (IOException ex) {" + + " System.out.println(\"Got IO Exception\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " BufferedInputStream doubleWrap = new BufferedInputStream(bis);\n" + + " ^^^^^^^^^^\n" + + "Resource leak: \'doubleWrap\' is never closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 15)\n" + + " BufferedInputStream bis2 = new BufferedInputStream(new FileInputStream(file));\n" + + " ^^^^\n" + + "Resource leak: \'bis2\' is never closed\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// Bug 361073 - Avoid resource leak warning when the top level resource is closed explicitly +// a resource wrapper is closed closing also the underlying resource +public void test061e() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " FileInputStream fis;" + + " void foo() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileInputStream fileStream = new FileInputStream(file);\n" + + " BufferedInputStream bis = new BufferedInputStream(fileStream);\n" + + " BufferedInputStream doubleWrap = new BufferedInputStream(bis);\n" + + " System.out.println(bis.available());\n" + + " bis.close();\n" + + " }\n" + + " void inline() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " BufferedInputStream bis2 = new BufferedInputStream(fis = new FileInputStream(file));\n" + // field assignment + " System.out.println(bis2.available());\n" + + " bis2.close();\n" + + " FileInputStream fileStream = null;\n" + + " BufferedInputStream bis3 = new BufferedInputStream(fileStream = new FileInputStream(file));\n" + + " System.out.println(bis3.available());\n" + + " bis3.close();\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " try {\n" + + " new X().foo();\n" + + " } catch (IOException ex) {" + + " System.out.println(\"Got IO Exception\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "Got IO Exception", + null, + true, + null, + options, + null); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// Bug 361073 - Avoid resource leak warning when the top level resource is closed explicitly +// a resource wrapper is closed closing also the underlying resource - original test case +public void test061f() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + URL url = FileLocator.toFileURL(FileLocator.find(Platform.getBundle("org.eclipse.jdt.core.tests.compiler"), new Path("META-INF/MANIFEST.MF"), null)); + this.runConformTest( + new String[] { + "X.java", + "import java.io.InputStream;\n" + + "import java.io.InputStreamReader;\n" + + "import java.io.BufferedReader;\n" + + "import java.io.IOException;\n" + + "import java.net.URL;\n" + + "public class X {\n" + + " boolean loadURL(final URL url) throws IOException {\n" + + " InputStream stream = null;\n" + + " BufferedReader reader = null;\n" + + " try {\n" + + " stream = url.openStream();\n" + + " reader = new BufferedReader(new InputStreamReader(stream));\n" + + " System.out.println(reader.readLine());\n" + + " } finally {\n" + + " try {\n" + + " if (reader != null)\n" + + " reader.close();\n" + + " } catch (IOException x) {\n" + + " }\n" + + " }\n" + + " return false; // 'stream' may not be closed at this location\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " try {\n" + + " new X().loadURL(new URL(\""+url.toString()+"\"));\n" + + " } catch (IOException ex) {\n" + + " System.out.println(\"Got IO Exception\"+ex);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "Manifest-Version: 1.0", + null, + true, + null, + options, + null); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// Bug 361073 - Avoid resource leak warning when the top level resource is closed explicitly +// a resource wrapper is closed closing also the underlying resource - from a real-world example +public void test061f2() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.OutputStream;\n" + + "import java.io.FileOutputStream;\n" + + "import java.io.BufferedOutputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void zork() throws IOException {\n" + + " try {\n" + + " OutputStream os = null;\n" + + " try {\n" + + " os = new BufferedOutputStream(new FileOutputStream(\"somefile\"));\n" + + " String externalForm = \"externalPath\";\n" + + " } finally {\n" + + " if (os != null)\n" + + " os.close();\n" + + " }\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// Bug 361073 - Avoid resource leak warning when the top level resource is closed explicitly +// a resource wrapper is sent to another method affecting also the underlying resource - from a real-world example +public void test061f3() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.FileNotFoundException;\n" + + "import java.io.InputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "public class X {\n" + + " String loadProfile(File profileFile) {\n" + + " try {\n" + + " InputStream stream = new BufferedInputStream(new FileInputStream(profileFile));\n" + + " return loadProfile(stream);\n" + + " } catch (FileNotFoundException e) {\n" + + " //null\n" + + " }\n" + + " return null;\n" + + " }\n" + + " private String loadProfile(InputStream stream) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " return loadProfile(stream);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'stream\' may not be closed at this location\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// Bug 360908 - Avoid resource leak warning when the underlying/chained resource is closed explicitly +// Different points in a resource chain are closed +public void test061g() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void closeMiddle() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileInputStream fileStream = new FileInputStream(file);\n" + + " BufferedInputStream bis = new BufferedInputStream(fileStream);\n" + + " BufferedInputStream doubleWrap = new BufferedInputStream(bis);\n" + + " System.out.println(bis.available());\n" + + " bis.close();\n" + + " }\n" + + " void closeOuter() throws IOException {\n" + + " File file2 = new File(\"somefile\");\n" + + " FileInputStream fileStream2 = new FileInputStream(file2);\n" + + " BufferedInputStream bis2 = new BufferedInputStream(fileStream2);\n" + + " BufferedInputStream doubleWrap2 = new BufferedInputStream(bis2);\n" + + " System.out.println(bis2.available());\n" + + " doubleWrap2.close();\n" + + " }\n" + + " void neverClosed() throws IOException {\n" + + " File file3 = new File(\"somefile\");\n" + + " FileInputStream fileStream3 = new FileInputStream(file3);\n" + + " BufferedInputStream bis3 = new BufferedInputStream(fileStream3);\n" + + " BufferedInputStream doubleWrap3 = new BufferedInputStream(bis3);\n" + + " System.out.println(doubleWrap3.available());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 26)\n" + + " BufferedInputStream doubleWrap3 = new BufferedInputStream(bis3);\n" + + " ^^^^^^^^^^^\n" + + "Resource leak: \'doubleWrap3\' is never closed\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// Bug 360908 - Avoid resource leak warning when the underlying/chained resource is closed explicitly +// Different points in a resource chain are potentially closed +public void test061h() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void closeMiddle(boolean b) throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileInputStream fileStream = new FileInputStream(file);\n" + + " BufferedInputStream bis = new BufferedInputStream(fileStream);\n" + + " BufferedInputStream doubleWrap = new BufferedInputStream(bis);\n" + + " System.out.println(bis.available());\n" + + " if (b)\n" + + " bis.close();\n" + + " }\n" + + " void closeOuter(boolean b) throws IOException {\n" + + " File file2 = new File(\"somefile\");\n" + + " FileInputStream fileStream2 = new FileInputStream(file2);\n" + + " BufferedInputStream dummy;\n" + + " BufferedInputStream bis2 = (dummy = new BufferedInputStream(fileStream2));\n" + + " BufferedInputStream doubleWrap2 = new BufferedInputStream(bis2);\n" + + " System.out.println(bis2.available());\n" + + " if (b)\n" + + " doubleWrap2.close();\n" + + " }\n" + + " void potAndDef(boolean b) throws IOException {\n" + + " File file3 = new File(\"somefile\");\n" + + " FileInputStream fileStream3 = new FileInputStream(file3);\n" + + " BufferedInputStream bis3 = new BufferedInputStream(fileStream3);\n" + + " BufferedInputStream doubleWrap3 = new BufferedInputStream(bis3);\n" + + " System.out.println(doubleWrap3.available());\n" + + " if (b) bis3.close();\n" + + " fileStream3.close();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " BufferedInputStream doubleWrap = new BufferedInputStream(bis);\n" + + " ^^^^^^^^^^\n" + + "Potential resource leak: \'doubleWrap\' may not be closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 20)\n" + + " BufferedInputStream doubleWrap2 = new BufferedInputStream(bis2);\n" + + " ^^^^^^^^^^^\n" + + "Potential resource leak: \'doubleWrap2\' may not be closed\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// local var is re-used for two levels of wrappers +public void test061i() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.InputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void closeMiddle() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " InputStream stream = new FileInputStream(file);\n" + + " stream = new BufferedInputStream(stream);\n" + + " InputStream middle;\n" + + " stream = new BufferedInputStream(middle = stream);\n" + + " System.out.println(stream.available());\n" + + " middle.close();\n" + + " }\n" + + " void closeOuter() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " InputStream stream2 = new FileInputStream(file);\n" + + " stream2 = new BufferedInputStream(stream2);\n" + + " stream2 = new BufferedInputStream(stream2);\n" + + " System.out.println(stream2.available());\n" + + " stream2.close();\n" + + " }\n" + + " void neverClosed() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " InputStream stream3 = new FileInputStream(file);\n" + + " stream3 = new BufferedInputStream(stream3);\n" + + " stream3 = new BufferedInputStream(stream3);\n" + + " System.out.println(stream3.available());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 26)\n" + + " InputStream stream3 = new FileInputStream(file);\n" + + " ^^^^^^^\n" + + "Resource leak: \'stream3\' is never closed\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// self-wrapping a method argument (caused NPE UnconditionalFlowInfo.markAsDefinitelyNull(..)). +public void test061j() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.InputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo(InputStream stream) throws IOException {\n" + + " stream = new BufferedInputStream(stream);\n" + + " System.out.println(stream.available());\n" + + " stream.close();\n" + + " }\n" + + " void boo(InputStream stream2) throws IOException {\n" + + " stream2 = new BufferedInputStream(stream2);\n" + + " System.out.println(stream2.available());\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a wrapper is created in a return statement +public void test061k() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " BufferedInputStream getReader(File file) throws IOException {\n" + + " FileInputStream stream = new FileInputStream(file);\n" + + " return new BufferedInputStream(stream);\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a closeable is assigned to a field +public void test061l() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " BufferedInputStream stream;\n" + + " void foo(File file) throws IOException {\n" + + " FileInputStream s = new FileInputStream(file);\n" + + " stream = new BufferedInputStream(s);\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 361407 - Resource leak warning when resource is assigned to a field outside of constructor +// a closeable is assigned to a field - constructor vs. method +public void test061l2() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "xy/Leaks.java", + "package xy;\n" + + "\n" + + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "\n" + + "public class Leaks {\n" + + " private FileInputStream fInput;\n" + + "\n" + + " Leaks(String name) throws IOException {\n" + + " FileInputStream fileInputStream= new FileInputStream(name);\n" + + " fInput= fileInputStream;\n" + // warning silenced by field assignment + " Objects.hashCode(fInput);\n" + + " \n" + + " init(name);\n" + + " }\n" + + " \n" + + " Leaks() throws IOException {\n" + + " this(new FileInputStream(\"default\")); // potential problem\n" + + " }\n" + + " \n" + + " Leaks(FileInputStream fis) throws IOException {\n" + + " fInput= fis;\n" + + " }\n" + + " void init(String name) throws IOException {\n" + + " FileInputStream fileInputStream= new FileInputStream(name);\n" + + " fInput= fileInputStream;\n" + // warning silenced by field assignment + " Objects.hashCode(fInput);\n" + + " }\n" + + " \n" + + " public void dispose() throws IOException {\n" + + " fInput.close();\n" + + " }\n" + + "}\n" + + "class Objects {\n" + // mock java.util.Objects (@since 1.7). + " static int hashCode(Object o) { return 13; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in xy\\Leaks.java (at line 18)\n" + + " this(new FileInputStream(\"default\")); // potential problem\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n", + options); +} +// Bug 361407 - Resource leak warning when resource is assigned to a field outside of constructor +// a closeable is not assigned to a field - constructor vs. method +public void test061l3() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "xy/Leaks.java", + "package xy;\n" + + "\n" + + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "\n" + + "public class Leaks {\n" + + "\n" + + " Leaks(String name) throws IOException {\n" + + " FileInputStream fileInputStream= new FileInputStream(name);\n" + + " Objects.hashCode(fileInputStream);\n" + + " \n" + + " init(name);\n" + + " }\n" + + " void init(String name) throws IOException {\n" + + " FileInputStream fileInputStream= new FileInputStream(name);\n" + + " Objects.hashCode(fileInputStream);\n" + + " }\n" + + "}\n" + + "class Objects {\n" + // mock java.util.Objects (@since 1.7). + " static int hashCode(Object o) { return 13; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in xy\\Leaks.java (at line 9)\n" + + " FileInputStream fileInputStream= new FileInputStream(name);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'fileInputStream\' may not be closed\n" + + "----------\n" + + "2. ERROR in xy\\Leaks.java (at line 15)\n" + + " FileInputStream fileInputStream= new FileInputStream(name);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'fileInputStream\' may not be closed\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a closeable is passed to another method in a return statement +// example constructed after org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository#getArtifact(..) +public void test061m() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.InputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " BufferedInputStream stream;\n" + + " BufferedInputStream foo(File file) throws IOException {\n" + + " FileInputStream s = new FileInputStream(file);\n" + + " return check(new BufferedInputStream(s));\n" + + " }\n" + + " BufferedInputStream foo2(FileInputStream s, File file) throws IOException {\n" + + " s = new FileInputStream(file);\n" + + " return check(s);\n" + + " }\n" + + " BufferedInputStream foo3(InputStream s) throws IOException {\n" + + " s = check(s);\n" + + " return check(s);\n" + + " }\n" + + " BufferedInputStream check(InputStream s) { return null; }\n" + + "}\n" + }, + // TODO: also these warnings *might* be avoidable by detecting check(s) as a wrapper creation?? + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " return check(new BufferedInputStream(s));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " return check(s);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'s\' may not be closed at this location\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " return check(s);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'s\' may not be closed at this location\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a resource wrapper does not wrap any provided resource +public void test061n() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.PrintWriter;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " PrintWriter writer = new PrintWriter(\"filename\");\n" + + " writer.write(1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " PrintWriter writer = new PrintWriter(\"filename\");\n" + + " ^^^^^^\n" + + "Resource leak: \'writer\' is never closed\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a resource wrapper is closed only in its local block, underlying resource may leak +public void test061o() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo(boolean bar) throws IOException {\n" + + " File file = new File(\"somefil\");\n" + + " FileInputStream fileStream = new FileInputStream(file);\n" + + " BufferedInputStream bis = new BufferedInputStream(fileStream); \n" + + " if (bar) {\n" + + " BufferedInputStream doubleWrap = new BufferedInputStream(bis);\n" + + " doubleWrap.close();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " BufferedInputStream bis = new BufferedInputStream(fileStream); \n" + + " ^^^\n" + + "Potential resource leak: \'bis\' may not be closed\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a resource wrapper is conditionally allocated but not closed - from a real-world example +public void test061f4() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.FileNotFoundException;\n" + + "import java.io.InputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "public class X {\n" + + " void foo(File location, String adviceFilePath) throws FileNotFoundException {\n" + + " InputStream stream = null;\n" + + " if (location.isDirectory()) {\n" + + " File adviceFile = new File(location, adviceFilePath);\n" + + " stream = new BufferedInputStream(new FileInputStream(adviceFile));\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " stream = new BufferedInputStream(new FileInputStream(adviceFile));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'stream\' may not be closed\n" + // message could be stronger, but the enclosing if blurs the picture + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a t-w-r wraps an existing resource +public void test061p() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.PrintWriter;\n" + + "import java.io.BufferedWriter;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " PrintWriter writer = new PrintWriter(\"filename\");\n" + + " try (BufferedWriter bw = new BufferedWriter(writer)) {\n" + + " bw.write(1);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a t-w-r potentially wraps an existing resource +// DISABLED, fails because we currently don't include t-w-r managed resources in the analysis +public void _test061q() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.PrintWriter;\n" + + "import java.io.BufferedWriter;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo(boolean b) throws IOException {\n" + + " PrintWriter writer = new PrintWriter(\"filename\");\n" + + " if (b)\n" + + " try (BufferedWriter bw = new BufferedWriter(writer)) {\n" + + " bw.write(1);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " PrintWriter writer = new PrintWriter(\\\"filename\\\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'writer\' may not be closed\n" + + "----------\n", + options); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// the inner from a wrapper is returned +public void test061r() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileInputStream;\n" + + "import java.io.File;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " FileInputStream foo() throws IOException {\n" + + " File file = new File(\"somefil\");\n" + + " FileInputStream fileStream = new FileInputStream(file);\n" + + " BufferedInputStream bis = new BufferedInputStream(fileStream); \n" + + " return fileStream;\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 358903 - Filter practically unimportant resource leak warnings +// a wrapper is forgotten, the inner is closed afterwards +public void test061s() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileInputStream;\n" + + "import java.io.File;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " File file = new File(\"somefil\");\n" + + " FileInputStream fileStream = new FileInputStream(file);\n" + + " BufferedInputStream bis = new BufferedInputStream(fileStream);\n" + + " bis = null;\n" + + " fileStream.close();\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 362331 - Resource leak not detected when closeable not assigned to variable +// a resource is never assigned +public void test062a() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileOutputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " new FileOutputStream(new File(\"C:\\temp\\foo.txt\")).write(1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new FileOutputStream(new File(\"C:\\temp\\foo.txt\")).write(1);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n", + options); +} +// Bug 362331 - Resource leak not detected when closeable not assigned to variable +// a freshly allocated resource is immediately closed +public void test062b() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileOutputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " new FileOutputStream(new File(\"C:\\temp\\foo.txt\")).close();\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 362331 - Resource leak not detected when closeable not assigned to variable +// a resource is directly passed to another method +public void test062c() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileOutputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " writeIt(new FileOutputStream(new File(\"C:\\temp\\foo.txt\")));\n" + + " }\n" + + " void writeIt(FileOutputStream fos) throws IOException {\n" + + " fos.write(1);\n" + + " fos.close();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " writeIt(new FileOutputStream(new File(\"C:\\temp\\foo.txt\")));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n", + options); +} +// Bug 362331 - Resource leak not detected when closeable not assigned to variable +// a resource is not used +public void test062d() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileOutputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo() throws IOException {\n" + + " new FileOutputStream(new File(\"C:\\temp\\foo.txt\"));\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " new FileOutputStream(new File(\"C:\\temp\\foo.txt\"));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n", + options); +} +// Bug 362332 - Only report potential leak when closeable not created in the local scope +// a wrapper is obtained from another method +public void test063a() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void read(File file) throws IOException {\n" + + " FileInputStream stream = new FileInputStream(file);\n" + + " BufferedInputStream bis = new BufferedInputStream(stream); // never since reassigned\n" + + " FileInputStream stream2 = new FileInputStream(file); // unsure since passed to method\n" + + " bis = getReader(stream2); // unsure since obtained from method\n" + + " bis.available();\n" + + " }\n" + + " BufferedInputStream getReader(FileInputStream stream) throws IOException {\n" + + " return new BufferedInputStream(stream);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " FileInputStream stream = new FileInputStream(file);\n" + + " ^^^^^^\n" + + "Resource leak: \'stream\' is never closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " FileInputStream stream2 = new FileInputStream(file); // unsure since passed to method\n" + + " ^^^^^^^\n" + + "Potential resource leak: \'stream2\' may not be closed\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " bis = getReader(stream2); // unsure since obtained from method\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'bis\' may not be closed\n" + + "----------\n", + options); +} +// Bug 362332 - Only report potential leak when closeable not created in the local scope +// a wrapper is obtained from a field read +public void test063b() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileInputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " FileInputStream stream;\n" + + " void read() throws IOException {\n" + + " FileInputStream s = this.stream;\n" + + " BufferedInputStream bis = new BufferedInputStream(s); // don't complain since s is obtained from a field\n" + + " bis.available();\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 362332 - Only report potential leak when closeable not created in the local scope +// a wrapper is assigned to a field +public void test063c() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileInputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " BufferedInputStream stream;\n" + + " void read() throws IOException {\n" + + " FileInputStream s = new FileInputStream(\"somefile\");\n" + + " BufferedInputStream bis = new BufferedInputStream(s);\n" + + " this.stream = bis;\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 362332 - Only report potential leak when closeable not created in the local scope +// a resource is obtained as a method argument and/or assigned with a cast +public void test063d() throws IOException { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runTestsExpectingErrorsOnlyIn17( + new String[] { + "X.java", + "import java.io.FileInputStream;\n" + + "import java.io.BufferedInputStream;\n" + + "import java.io.InputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " void foo( InputStream input) throws IOException {\n" + + " FileInputStream input1 = (FileInputStream)input;\n" + + " System.out.println(input1.read());\n" + + " input.close();\n" + // don't propose t-w-r for argument + " }\n" + + " void foo() throws IOException {\n" + + " InputStream input = new FileInputStream(\"somefile\");\n" + + " FileInputStream input1 = (FileInputStream)input;\n" + + " System.out.println(input1.read());\n" + + " input.close();\n" + // do propose t-w-r, not from a method argument + " }\n" + + " void foo3( InputStream input, InputStream input2) throws IOException {\n" + + " FileInputStream input1 = (FileInputStream)input;\n" + // still don't claim because obtained from outside + " System.out.println(input1.read());\n" + + " BufferedInputStream bis = new BufferedInputStream(input2);\n" + + " System.out.println(bis.read());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " InputStream input = new FileInputStream(\"somefile\");\n" + + " ^^^^^\n" + + "Resource \'input\' should be managed by try-with-resource\n" + + "----------\n", + options); +} +// Bug 362332 - Only report potential leak when closeable not created in the local scope +// a resource is obtained from a field read, then re-assigned +public void test063e() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + " FileInputStream input1;\n" + + " public void foo() throws IOException {\n" + + " FileInputStream input = input1;\n" + + " input = new FileInputStream(\"adfafd\");\n" + + " input.close();\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} +// Bug 368709 - Endless loop in FakedTrackingVariable.markPassedToOutside +// original test case from jgit +public void testBug368709a() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "import java.util.zip.*;\n" + + "public class X {\n" + + " Object db, pack;\n" + // mock + " int objectOffset, headerLength, type, size;\n" + + " public ObjectStream openStream() throws MissingObjectException, IOException {\n" + + " WindowCursor wc = new WindowCursor(db);\n" + + " InputStream in;\n" + + " try\n" + + " {\n" + + " in = new PackInputStream(pack, (objectOffset + headerLength), wc);\n" + + " }\n" + + " catch (IOException packGone)\n" + + " {\n" + + " return wc.open(getObjectId(), type).openStream();\n" + + " }\n" + + " in = new BufferedInputStream(new InflaterInputStream(in, wc.inflater(), 8192), 8192);\n" + + " return new ObjectStream.Filter(type, size, in);\n" + + " }\n" + + " String getObjectId() { return \"\"; }\n" + // mock + "}\n" + + // mock: + "class WindowCursor {\n" + + " WindowCursor(Object db) {}\n" + + " ObjectStream open(String id, int type) { return null; }\n" + + " Inflater inflater() { return null; }\n" + + "}\n" + + "class MissingObjectException extends Exception {\n" + + " public static final long serialVersionUID = 13L;\n" + + " MissingObjectException() { super();}\n" + + "}\n" + + "class PackInputStream extends InputStream {\n" + + " PackInputStream(Object pack, int offset, WindowCursor wc) throws IOException {}\n" + + " public int read() { return 0; }\n" + + "}\n" + + "class ObjectStream extends InputStream {\n" + + " static class Filter extends ObjectStream {\n" + + " Filter(int type, int size, InputStream in) { }\n" + + " }\n" + + " ObjectStream openStream() { return this; }\n" + + " public int read() { return 0; }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " return wc.open(getObjectId(), type).openStream();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 18)\n" + + " return new ObjectStream.Filter(type, size, in);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'in\' may not be closed at this location\n" + + "----------\n", + options); +} +// Bug 368709 - Endless loop in FakedTrackingVariable.markPassedToOutside +// minimal test case: constructing an indirect self-wrapper +public void testBug368709b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "import java.util.zip.*;\n" + + "public class X {\n" + + " void doit() throws IOException {\n" + + " InputStream in = new FileInputStream(\"somefile\");\n" + + " in = new BufferedInputStream(new InflaterInputStream(in, inflater(), 8192), 8192);\n" + + " process(in);\n" + + " }\n" + + " Inflater inflater() { return null; }\n" + + " void process(InputStream is) { }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " InputStream in = new FileInputStream(\"somefile\");\n" + + " ^^\n" + + "Potential resource leak: \'in\' may not be closed\n" + + "----------\n", + options); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// example from comment 3 +public void test064() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest(new String[] { + "Test064.java", + "import java.io.*;\n" + + "public class Test064 {\n" + + " void foo(File outfile) {\n" + + " OutputStream out= System.out;\n" + + " if (outfile != null) {\n" + + " try {\n" + + " out = new FileOutputStream(outfile);\n" + + " } catch (java.io.IOException e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + " setOutput(out);\n" + + " }\n" + + " private void setOutput(OutputStream out) { }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test064.java (at line 7)\n" + + " out = new FileOutputStream(outfile);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'out\' may not be closed\n" + + "----------\n", + options); +} +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// example from comment 10 +// disabled, because basic null-analysis machinery doesn't support this pattern +// see also Bug 370424 - [compiler][null] throw-catch analysis for null flow could be more precise +public void _test065() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + this.runConformTest(new String[] { + "Test065.java", + "import java.io.*;\n" + + "class MyException extends Exception{}\n" + + "public class Test065 {\n" + + " void foo(String fileName) throws IOException, MyException {\n" + + " FileReader fileRead = new FileReader(fileName);\n" + + " BufferedReader bufRead = new BufferedReader(fileRead);\n" + + " LineNumberReader lineReader = new LineNumberReader(bufRead);\n" + + " try {\n" + + " while (lineReader.readLine() != null) {\n" + + " bufRead.close();\n" + + " callSome(); // only this can throw MyException\n" + + " }\n" + + " } catch (MyException e) {\n" + + " throw e; // Pot. leak reported here\n" + + " }\n" + + " bufRead.close(); \n" + + " }\n" + + " private void callSome() throws MyException\n" + + " {\n" + + " \n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// example from comment 11 +public void test066() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + runLeakTest(new String[] { + "Test066.java", + "import java.io.*;\n" + + "class MyException extends Exception{}\n" + + "public class Test066 {\n" + + " void countFileLines(String fileName) throws IOException {\n" + + " FileReader fileRead = new FileReader(fileName);\n" + + " BufferedReader bufRead = new BufferedReader(fileRead);\n" + + " LineNumberReader lineReader = new LineNumberReader(bufRead);\n" + + " while (lineReader.readLine() != null) {\n" + + " if (lineReader.markSupported())\n" + + " throw new IOException();\n" + + " bufRead.close();\n" + + " }\n" + + " bufRead.close();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test066.java (at line 10)\n" + + " throw new IOException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'lineReader\' may not be closed at this location\n" + + "----------\n", + options); +} +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// example from comment 11 - variant with closing top-level resource +public void test066b() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + runLeakTest(new String[] { + "Test066.java", + "import java.io.*;\n" + + "class MyException extends Exception{}\n" + + "public class Test066 {\n" + + " void countFileLines(String fileName) throws IOException {\n" + + " FileReader fileRead = new FileReader(fileName);\n" + + " BufferedReader bufRead = new BufferedReader(fileRead);\n" + + " LineNumberReader lineReader = new LineNumberReader(bufRead);\n" + + " while (lineReader.readLine() != null) {\n" + + " if (lineReader.markSupported())\n" + + " throw new IOException();\n" + + " lineReader.close();\n" + + " }\n" + + " lineReader.close();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test066.java (at line 10)\n" + + " throw new IOException();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'lineReader\' may not be closed at this location\n" + + "----------\n", + options); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// example from comment 12 +// Red herring (disabled): warning says "potential" because in the exception case no resource +// would actually be allocated. +public void _test067() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + this.runConformTest(new String[] { + "Test067.java", + "import java.io.*;\n" + + "public class Test067 {\n" + + " public void comment12() throws IOException {\n" + + " LineNumberReader o = null;\n" + + " try {\n" + + " o = new LineNumberReader(null); \n" + + " } catch (NumberFormatException e) { \n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// example from comment 12 +public void test067b() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + this.runConformTest(new String[] { + "Test067.java", + "import java.io.*;\n" + + "public class Test067 {\n" + + " public void comment12b() throws IOException {\n" + + " LineNumberReader o = new LineNumberReader(null);\n" + + " try {\n" + + " o.close();\n" + + " } catch (NumberFormatException e) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// example from comment 13 +public void test068() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + this.runConformTest(new String[] { + "Test068.java", + "import java.io.*;\n" + + "public class Test068 {\n" + + " class ProcessingStep extends OutputStream {\n" + + " public void write(int b) throws IOException {}\n" + + " public OutputStream getDestination() { return null; }\n" + + " }\n" + + " class ArtifactOutputStream extends OutputStream {\n" + + " public void write(int b) throws IOException {}\n" + + " }" + + " ArtifactOutputStream comment13(OutputStream stream) {\n" + + " OutputStream current = stream;\n" + + " while (current instanceof ProcessingStep)\n" + + " current = ((ProcessingStep) current).getDestination();\n" + // we previously saw a bogus warning here. + " if (current instanceof ArtifactOutputStream)\n" + + " return (ArtifactOutputStream) current;\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// example from comment 16 +public void test069() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // generics used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + this.runConformTest(new String[] { + "Test069.java", + "import java.io.*;\n" + + "import java.util.Collection;\n" + + "public class Test069 {\n" + + " class Profile {}\n" + + " class CoreException extends Exception {}\n" + + " void writeProfilesToStream(Collection p, OutputStream s, String enc) {}\n" + + " CoreException createException(IOException ioex, String message) { return new CoreException(); }\n" + + " public void comment16(Collection profiles, File file, String encoding) throws CoreException {\n" + + " final OutputStream stream;\n" + + " try {\n" + + " stream= new FileOutputStream(file);\n" + + " try {\n" + + " writeProfilesToStream(profiles, stream, encoding);\n" + + " } finally {\n" + + " try { stream.close(); } catch (IOException e) { /* ignore */ }\n" + + " }\n" + + " } catch (IOException e) {\n" + + " throw createException(e, \"message\"); // should not shout here\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// referenced in array initializer +public void test070() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + runLeakTest(new String[] { + "Test070.java", + "import java.io.*;\n" + + "public class Test070 {\n" + + " void storeInArray(String fileName) throws IOException {\n" + + " FileReader fileRead = new FileReader(fileName);\n" + + " closeThemAll(new FileReader[] { fileRead });\n" + + " }\n" + + " void closeThemAll(FileReader[] readers) { }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test070.java (at line 4)\n" + + " FileReader fileRead = new FileReader(fileName);\n" + + " ^^^^^^^^\n" + + "Potential resource leak: \'fileRead\' may not be closed\n" + + "----------\n", + options); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// referenced in array initializer +public void test071() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + runLeakTest(new String[] { + "Test071.java", + "import java.io.*;\n" + + "public class Test071 {\n" + + " class ReaderHolder {\n" + + " FileReader reader;\n" + + " }\n" + + " private FileReader getReader() {\n" + + " return null;\n" + + " }\n" + + " void invokeCompiler(ReaderHolder readerHolder, boolean flag) throws FileNotFoundException {\n" + + " FileReader reader = readerHolder.reader;\n" + + " if (reader == null)\n" + + " reader = getReader();\n" + + " try {\n" + + " return;\n" + + " } finally {\n" + + " try {\n" + + " if (flag)\n" + + " reader.close();\n" + + " } catch (IOException e) {\n" + + " // nop\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test071.java (at line 14)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Potential resource leak: \'reader\' may not be closed at this location\n" + + "----------\n", + options); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// referenced in array initializer +// disabled because it would require correlation analysis between the tracking variable and its original +// need to pass to downstream: either (nonnull & open) or (null) +public void _test071b() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + runLeakTest(new String[] { + "Test071b.java", + "import java.io.*;\n" + + "public class Test071b {\n" + + " private FileReader getReader() {\n" + + " return null;\n" + + " }\n" + + " void invokeCompiler(boolean flag) throws FileNotFoundException {\n" + + " FileReader reader = null;\n" + + " if (flag)\n" + + " reader = new FileReader(\"file\");\n" + + " if (reader == null)\n" + + " reader = getReader();\n" + + " try {\n" + + " return;\n" + + " } finally {\n" + + " try {\n" + + " if (flag)\n" + + " reader.close();\n" + + " } catch (IOException e) {\n" + + " // nop\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test071b.java (at line 13)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Potential resource leak: \'reader\' may not be closed at this location\n" + + "----------\n", + options); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// throw inside loop inside try - while closed in finally +public void test072() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + this.runConformTest(new String[] { + "Test072.java", + "import java.io.*;\n" + + "public class Test072 {\n" + + " void readState(File file) {\n" + + " DataInputStream in = null;\n" + + " try {\n" + + " in= new DataInputStream(new BufferedInputStream(new FileInputStream(file)));\n" + + " int sizeOfFlags = in.readInt();\n" + + " for (int i = 0; i < sizeOfFlags; ++i) {\n" + + " String childPath = in.readUTF();\n" + + " if (childPath.length() == 0)\n" + + " throw new IOException();\n" + + " }\n" + + " }\n" + + " catch (IOException ioe) { /* nop */ }\n" + + " finally {\n" + + " if (in != null) {\n" + + " try {in.close();} catch (IOException ioe) {}\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// unspecific parameter is casted into a resource, yet need to mark as OWNED_BY_OUTSIDE +public void test073() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + this.runConformTest(new String[] { + "Test073.java", + "import java.io.*;\n" + + "public class Test073 {\n" + + " String getEncoding(Object reader) {\n" + + " if (reader instanceof FileReader) {\n" + + " final FileReader fr = (FileReader) reader;\n" + + " return fr.getEncoding();\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 368546 - [compiler][resource] Avoid remaining false positives found when compiling the Eclipse SDK +// status after nested try-finally +public void test074() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.IGNORE); + runLeakTest(new String[] { + "Test074.java", + "import java.io.*;\n" + + "public class Test074 {\n" + + " void foo() throws FileNotFoundException {\n" + + " FileOutputStream out = null;\n" + + " try {\n" + + " out = new FileOutputStream(\"outfile\");\n" + + " } finally {\n" + + " try {\n" + + " out.flush();\n" + + " out.close();\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " out = null;\n" + // unclosed if exception occurred on flush() + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test074.java (at line 14)\n" + + " out = null;\n" + + " ^^^^^^^^^^\n" + + "Potential resource leak: \'out\' may not be closed at this location\n" + + "----------\n", + options); +} +// Bug 370639 - [compiler][resource] restore the default for resource leak warnings +// check that the default is warning +public void test075() { + runLeakWarningTest( + 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() throws IOException {\n" + + " File file = new File(\"somefile\");\n" + + " FileReader fileReader = new FileReader(file);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " FileReader fileReader = new FileReader(file);\n" + + " ^^^^^^^^^^\n" + + "Resource leak: 'fileReader' is never closed\n" + + "----------\n", + getCompilerOptions()); +} +// Bug 385415 - Incorrect resource leak detection +public void testBug385415() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " void foo() throws FileNotFoundException {\n" + + " FileReader fileReader = new FileReader(\"somefile\");\n" + + " try {\n" + + " fileReader.close();\n" + + " } catch (Exception e) {\n" + + " e.printStackTrace();\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 361073 - Avoid resource leak warning when the top level resource is closed explicitly +// test case from comment 7 +// Duplicate of Bug 385415 - Incorrect resource leak detection +public void testBug361073c7() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public void test() {\n" + + " BufferedReader br = null;\n" + + " try {\n" + + " br = new BufferedReader(new FileReader(\"blah\"));\n" + + " String line = null;\n" + + " while ( (line = br.readLine()) != null ) {\n" + + " if ( line.startsWith(\"error\") )\n" + + " throw new Exception(\"error\"); //Resource leak: 'br' is not closed at this location\n" + + " }\n" + + " } catch (Throwable t) {\n" + + " t.printStackTrace();\n" + + " } finally {\n" + + " if ( br != null ) {\n" + + " try { br.close(); }\n" + + " catch (Throwable e) { br = null; }\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 386534 - "Potential resource leak" false positive warning +// DISABLED +public void _testBug386534() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "Bug.java", + "import java.io.FileNotFoundException;\n" + + "import java.io.IOException;\n" + + "import java.io.OutputStream;\n" + + "\n" + + "public class Bug {\n" + + " private static final String DETAILS_FILE_NAME = null;\n" + + " private static final String LOG_TAG = null;\n" + + " private static Context sContext;\n" + + " static void saveDetails(byte[] detailsData) {\n" + + " OutputStream os = null;\n" + + " try {\n" + + " os = sContext.openFileOutput(DETAILS_FILE_NAME,\n" + + " Context.MODE_PRIVATE);\n" + + " os.write(detailsData);\n" + + " } catch (IOException e) {\n" + + " Log.w(LOG_TAG, \"Unable to save details\", e);\n" + + " } finally {\n" + + " if (os != null) {\n" + + " try {\n" + + " os.close();\n" + + " } catch (IOException ignored) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " static class Context {\n" + + " public static final String MODE_PRIVATE = null;\n" + + " public OutputStream openFileOutput(String detailsFileName,\n" + + " String modePrivate) throws FileNotFoundException{\n" + + " return null;\n" + + " }\n" + + " }\n" + + " static class Log {\n" + + " public static void w(String logTag, String string, IOException e) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// https://bugs.eclipse.org/388996 - [compiler][resource] Incorrect 'potential resource leak' +public void testBug388996() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "Bug.java", + "import java.io.*;\n" + + "public class Bug {\n" + + " public void processRequest(ResponseContext responseContext) throws IOException {\n" + + " OutputStream bao = null;\n" + + "\n" + + " try {\n" + + " HttpServletResponse response = responseContext.getResponse();\n" + + "\n" + + " bao = response.getOutputStream(); // <<<<\n" + + " } finally {\n" + + " if(bao != null) {\n" + + " bao.close();\n" + + " }\n" + + " }\n" + + " }" + + "}\n" + + "class ResponseContext {\n" + + " public HttpServletResponse getResponse() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "class HttpServletResponse {\n" + + " public OutputStream getOutputStream() {\n" + + " return null;\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null); +} + +// https://bugs.eclipse.org/386534 - [compiler][resource] "Potential resource leak" false positive warning +public void testBug386534() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "Bug386534.java", + "import java.io.FileNotFoundException;\n" + + "import java.io.IOException;\n" + + "import java.io.OutputStream;\n" + + "\n" + + "public class Bug386534 {\n" + + " private static final String DETAILS_FILE_NAME = null;\n" + + " private static final String LOG_TAG = null;\n" + + " private static Context sContext;\n" + + " static void saveDetails(byte[] detailsData) {\n" + + " OutputStream os = null;\n" + + " try {\n" + + " os = sContext.openFileOutput(DETAILS_FILE_NAME,\n" + + " Context.MODE_PRIVATE);\n" + + " os.write(detailsData);\n" + + " } catch (IOException e) {\n" + + " Log.w(LOG_TAG, \"Unable to save details\", e);\n" + + " } finally {\n" + + " if (os != null) {\n" + + " try {\n" + + " os.close();\n" + + " } catch (IOException ignored) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " static class Context {\n" + + " public static final String MODE_PRIVATE = null;\n" + + " public OutputStream openFileOutput(String detailsFileName,\n" + + " String modePrivate) throws FileNotFoundException{\n" + + " return null;\n" + + " }\n" + + " }\n" + + " static class Log {\n" + + " public static void w(String logTag, String string, IOException e) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +//https://bugs.eclipse.org/386534 - [compiler][resource] "Potential resource leak" false positive warning +public void testBug394768() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "Bug394768.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.InputStream;\n" + + "\n" + + "public class Bug394768 {\n" + + " public void readFile(String path) throws Exception {\n" + + " InputStream stream = null;\n" + + " File file = new File(path);\n" + + "\n" + + " if (file.exists())\n" + + " stream = new FileInputStream(path);\n" + + " else\n" + + " stream = getClass().getClassLoader().getResourceAsStream(path);\n" + + "\n" + + " if (stream == null)\n" + + " return;\n" + + "\n" + + " try {\n" + + " // Use the opened stream here\n" + + " stream.read();\n" + + " } finally {\n" + + " stream.close();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// https://bugs.eclipse.org/386534 - [compiler][resource] "Potential resource leak" false positive warning +// variation: 2nd branch closes and nulls the newly acquired resource +public void testBug394768_1() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "Bug394768.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.InputStream;\n" + + "\n" + + "public class Bug394768 {\n" + + " public void readFile(String path) throws Exception {\n" + + " InputStream stream = null;\n" + + " File file = new File(path);\n" + + "\n" + + " if (file.exists()) {\n" + + " stream = new FileInputStream(path);\n" + + " } else {\n" + + " stream = getClass().getClassLoader().getResourceAsStream(path);" + + " stream.close();\n" + + " stream = null;\n" + + " }\n" + + "\n" + + " if (stream == null)\n" + + " return;\n" + + "\n" + + " try {\n" + + " // Use the opened stream here\n" + + " stream.read();\n" + + " } finally {\n" + + " stream.close();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 381445 - [compiler][resource] Can the resource leak check be made aware of Closeables.closeQuietly? +// A resource is closed using various known close helpers +public void testBug381445_1() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + GUAVA_CLOSEABLES_JAVA, + GUAVA_CLOSEABLES_CONTENT, + "org/apache/commons/io/IOUtils.java", + "package org.apache.commons.io;\n" + + "public class IOUtils {\n" + + " public static void closeQuietly(java.io.Closeable closeable) {}\n" + + "}\n", + "Bug381445.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.InputStream;\n" + + "\n" + + "public class Bug381445 {\n" + + " public void readFile(String path) throws Exception {\n" + + " File file = new File(path);\n" + + " InputStream stream1 = new FileInputStream(path);\n" + + " InputStream stream2 = new FileInputStream(path);\n" + + " InputStream stream3 = new FileInputStream(path);\n" + + " InputStream stream4 = new FileInputStream(path);\n" + + " try {\n" + + " // Use the opened streams here\n" + + " stream1.read();\n" + + " stream2.read();\n" + + " stream3.read();\n" + + " stream4.read();\n" + + " } finally {\n" + + " com.google.common.io.Closeables.closeQuietly(stream1);\n" + + " com.google.common.io.Closeables.close(stream2, false);\n" + + " org.apache.commons.io.IOUtils.closeQuietly(stream3);\n" + + " Closeables.closeQuietly(stream4);\n" + + " }\n" + + " }\n" + + "}\n" + + "class Closeables {\n" + // fake, should not be recognized + " public static void closeQuietly(java.io.Closeable closeable) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug381445.java (at line 11)\n" + + " InputStream stream4 = new FileInputStream(path);\n" + + " ^^^^^^^\n" + + "Potential resource leak: \'stream4\' may not be closed\n" + + "----------\n", + options); +} + +// Bug 405569 - Resource leak check false positive when using DbUtils.closeQuietly +// A resource is closed using more known close helpers +public void testBug381445_1b() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // need AutoCloseable in apache's DbUtils + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + APACHE_DBUTILS_JAVA, + APACHE_DBUTILS_CONTENT, + "Bug381445.java", + "import java.sql.*;\n" + + "\n" + + "public class Bug381445 {\n" + + " public void performQuery1(String url, String q1, String q2) throws Exception {\n" + + " Connection conn = DriverManager.getConnection(url);\n" + + " Statement stat = conn.createStatement();\n" + + " ResultSet rset = stat.executeQuery(q1);\n" + + " ResultSet rset2 = stat.executeQuery(q2);\n" + + " try {\n" + + " // empty\n" + + " } finally {\n" + + " org.apache.commons.dbutils.DbUtils.closeQuietly(conn);\n" + + " org.apache.commons.dbutils.DbUtils.close(stat);\n" + + " org.apache.commons.dbutils.DbUtils.closeQuietly(rset);\n" + + " Closeables.closeQuietly(rset2);\n" + + " }\n" + + " }\n" + + " public void performQuery2(String url, String q1, String q2) throws Exception {\n" + + " Connection conn = DriverManager.getConnection(url);\n" + + " Statement stat = conn.createStatement();\n" + + " ResultSet rset = stat.executeQuery(q1);\n" + + " try {\n" + + " // empty\n" + + " } finally {\n" + + " org.apache.commons.dbutils.DbUtils.closeQuietly(conn, stat, rset);\n" + + " }\n" + + " }\n" + + "}\n" + + "class Closeables {\n" + // fake, should not be recognized + " public static void closeQuietly(java.lang.AutoCloseable closeable) {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug381445.java (at line 8)\n" + + " ResultSet rset2 = stat.executeQuery(q2);\n" + + " ^^^^^\n" + + "Potential resource leak: \'rset2\' may not be closed\n" + + "----------\n", + options); +} + +// Bug 381445 - [compiler][resource] Can the resource leak check be made aware of Closeables.closeQuietly? +// A resource is closed in different places of the flow +public void testBug381445_2() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + GUAVA_CLOSEABLES_JAVA, + GUAVA_CLOSEABLES_CONTENT, + "Bug381445.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.InputStream;\n" + + "import com.google.common.io.Closeables;\n" + + "\n" + + "public class Bug381445 {\n" + + " public void readFile(String path) throws Exception {\n" + + " File file = new File(path);\n" + + " InputStream stream1 = new FileInputStream(path);\n" + + " InputStream stream2 = new FileInputStream(path);\n" + + " InputStream stream3 = new FileInputStream(path);\n" + + " try {\n" + + " // Use the opened streams here\n" + + " stream1.read();\n" + + " Closeables.closeQuietly(stream1);\n" + + " stream2.read();\n" + + " if (path.length() > 2)\n" + + " Closeables.closeQuietly(stream2);\n" + // close inside if is too weak + " stream3.read();\n" + + " } finally {\n" + + " }\n" + + " Closeables.closeQuietly(stream3);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug381445.java (at line 10)\n" + + " InputStream stream2 = new FileInputStream(path);\n" + + " ^^^^^^^\n" + + "Potential resource leak: \'stream2\' may not be closed\n" + + "----------\n", + options); +} + +// Bug 381445 - [compiler][resource] Can the resource leak check be made aware of Closeables.closeQuietly? +// A close helper is referenced in various ways: +public void testBug381445_3() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // using static import + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + GUAVA_CLOSEABLES_JAVA, + GUAVA_CLOSEABLES_CONTENT, + "Bug381445a.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.InputStream;\n" + + "import static com.google.common.io.Closeables.closeQuietly;\n" + + "\n" + + "public class Bug381445a {\n" + + " public void readFile(String path) throws Exception {\n" + + " File file = new File(path);\n" + + " InputStream stream = new FileInputStream(path);\n" + + " try {\n" + + " // Use the opened stream here\n" + + " stream.read();\n" + + " } finally {\n" + + " closeQuietly(stream);\n" + // via static import + " }\n" + + " }\n" + + "}\n", + "Bug381445b.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.InputStream;\n" + + "import com.google.common.io.Closeables;\n" + + "\n" + + "public class Bug381445b extends Closeables {\n" + + " public void readFile(String path) throws Exception {\n" + + " File file = new File(path);\n" + + " InputStream stream = new FileInputStream(path);\n" + + " try {\n" + + " // Use the opened streams here\n" + + " stream.read();\n" + + " } finally {\n" + + " closeQuietly(stream);\n" + // via super class + " }\n" + + " }\n" + + "}\n", + }, + "", + null, + true, + null, + options, + null); +} + +// Bug 395977 - Resource leak warning behavior possibly incorrect for anonymous inner class +// original test case +public void testBug395977() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "WriterTest.java", + "import java.io.*;\n" + + "\n" + + "public class WriterTest implements Runnable\n" + + "{\n" + + " private BufferedWriter m_Writer;\n" + + " \n" + + " public void run()\n" + + " {\n" + + " try\n" + + " {\n" + + " initializeWriter();\n" + + " \n" + + " m_Writer.write(\"string\");\n" + + " m_Writer.newLine();\n" + + " \n" + + " closeWriter();\n" + + " }\n" + + " catch (IOException ioe)\n" + + " {\n" + + " ioe.printStackTrace();\n" + + " }\n" + + " }\n" + + " \n" + + " private void initializeWriter()\n" + + " throws UnsupportedEncodingException, FileNotFoundException\n" + + " {\n" + + " m_Writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(\"file\"), \"UTF-8\"))\n" + + " {\n" + + " /**\n" + + " * Writes an LF character on all platforms, to avoid constantly flipping the line terminator style.\n" + + " */\n" + + " public void newLine() throws IOException\n" + + " {\n" + + " write('\\n');\n" + + " }\n" + + " };\n" + + " }\n" + + " \n" + + " private void closeWriter()\n" + + " throws IOException\n" + + " {\n" + + " m_Writer.close();\n" + + " }\n" + + "}" + }, + "", + null, + true, + null, + options, + null); +} + +//Bug 395977 - Resource leak warning behavior possibly incorrect for anonymous inner class +//variant with named local class - accept as a secure resource wrapper since no close method +public void testBug395977_1() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "WriterTest.java", + "import java.io.*;\n" + + "\n" + + "public class WriterTest implements Runnable\n" + + "{\n" + + " private BufferedWriter m_Writer;\n" + + " \n" + + " public void run()\n" + + " {\n" + + " try\n" + + " {\n" + + " initializeWriter();\n" + + " \n" + + " m_Writer.write(\"string\");\n" + + " m_Writer.newLine();\n" + + " \n" + + " closeWriter();\n" + + " }\n" + + " catch (IOException ioe)\n" + + " {\n" + + " ioe.printStackTrace();\n" + + " }\n" + + " }\n" + + " \n" + + " private void initializeWriter()\n" + + " throws UnsupportedEncodingException, FileNotFoundException\n" + + " {\n" + + " class MyBufferedWriter extends BufferedWriter\n" + + " {\n" + + " MyBufferedWriter(OutputStreamWriter writer) { super(writer); }\n" + + " /**\n" + + " * Writes an LF character on all platforms, to avoid constantly flipping the line terminator style.\n" + + " */\n" + + " public void newLine() throws IOException\n" + + " {\n" + + " write('\\n');\n" + + " }\n" + + " };" + + " m_Writer = new MyBufferedWriter(new OutputStreamWriter(new FileOutputStream(\"file\"), \"UTF-8\"));\n" + + " }\n" + + " \n" + + " private void closeWriter()\n" + + " throws IOException\n" + + " {\n" + + " m_Writer.close();\n" + + " }\n" + + "}" + }, + "", + options); +} +//Bug 395977 - Resource leak warning behavior possibly incorrect for anonymous inner class +//variant with named local class - don't accept as a secure resource wrapper since close() method exist +public void testBug395977_1a() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "WriterTest.java", + "import java.io.*;\n" + + "\n" + + "public class WriterTest implements Runnable\n" + + "{\n" + + " private BufferedWriter m_Writer;\n" + + " \n" + + " public void run()\n" + + " {\n" + + " try\n" + + " {\n" + + " initializeWriter();\n" + + " \n" + + " m_Writer.write(\"string\");\n" + + " m_Writer.newLine();\n" + + " \n" + + " closeWriter();\n" + + " }\n" + + " catch (IOException ioe)\n" + + " {\n" + + " ioe.printStackTrace();\n" + + " }\n" + + " }\n" + + " \n" + + " private void initializeWriter()\n" + + " throws UnsupportedEncodingException, FileNotFoundException\n" + + " {\n" + + " class MyBufferedWriter extends BufferedWriter\n" + + " {\n" + + " MyBufferedWriter(OutputStreamWriter writer) { super(writer); }\n" + + " /**\n" + + " * Writes an LF character on all platforms, to avoid constantly flipping the line terminator style.\n" + + " */\n" + + " public void newLine() throws IOException\n" + + " {\n" + + " write('\\n');\n" + + " }\n" + + " public void close() {}\n" + + " };" + + " m_Writer = new MyBufferedWriter(new OutputStreamWriter(new FileOutputStream(\"file\"), \"UTF-8\"));\n" + + " }\n" + + " \n" + + " private void closeWriter()\n" + + " throws IOException\n" + + " {\n" + + " m_Writer.close();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in WriterTest.java (at line 38)\n" + + " }; m_Writer = new MyBufferedWriter(new OutputStreamWriter(new FileOutputStream(\"file\"), \"UTF-8\"));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n", + options); +} + +// Bug 395977 - Resource leak warning behavior possibly incorrect for anonymous inner class +// anonymous class tries to "cheat" by overriding close() +public void testBug395977_2() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "WriterTest.java", + "import java.io.*;\n" + + "\n" + + "public class WriterTest implements Runnable\n" + + "{\n" + + " private BufferedWriter m_Writer;\n" + + " \n" + + " public void run()\n" + + " {\n" + + " try\n" + + " {\n" + + " initializeWriter();\n" + + " \n" + + " m_Writer.write(\"string\");\n" + + " m_Writer.newLine();\n" + + " \n" + + " closeWriter();\n" + + " }\n" + + " catch (IOException ioe)\n" + + " {\n" + + " ioe.printStackTrace();\n" + + " }\n" + + " }\n" + + " \n" + + " private void initializeWriter()\n" + + " throws UnsupportedEncodingException, FileNotFoundException\n" + + " {\n" + + " m_Writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(\"file\"), \"UTF-8\"))\n" + + " {\n" + + " public void close() { /* nop */}\n" + + " };\n" + + " }\n" + + " \n" + + " private void closeWriter()\n" + + " throws IOException\n" + + " {\n" + + " m_Writer.close();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in WriterTest.java (at line 27)\n" + + " m_Writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(\"file\"), \"UTF-8\"))\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n", + options); +} + +// Bug 376053 - [compiler][resource] Strange potential resource leak problems +// include line number when reporting against +public void testBug376053() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "Try.java", + "package xy;\n" + + "\n" + + "import java.io.FileNotFoundException;\n" + + "import java.io.PrintStream;\n" + + "\n" + + "public class Try {\n" + + " public static void main(String[] args) throws FileNotFoundException {\n" + + " System.setOut(new PrintStream(\"log.txt\"));\n" + + " \n" + + " if (Math.random() > .5) {\n" + + " return;\n" + + " }\n" + + " System.out.println(\"Hello World\");\n" + + " return;\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Try.java (at line 11)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed at this location\n" + + "----------\n" + + "2. ERROR in Try.java (at line 14)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed at this location\n" + + "----------\n", + options); +} + +// https://bugs.eclipse.org/411098 - [compiler][resource] Invalid Resource Leak Warning using ternary operator inside try-with-resource +public void testBug411098_test1() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "A.java", + "import java.io.*;\n" + + "\n" + + "class A {\n" + + " void a(boolean b) throws Exception {\n" + + " try(FileInputStream in = b ? new FileInputStream(\"a\") : null){}\n" + + " }\n" + + "}" + }, + options + ); +} + +// https://bugs.eclipse.org/411098 - [compiler][resource] Invalid Resource Leak Warning using ternary operator inside try-with-resource +public void testBug411098_test2() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "A.java", + "import java.io.*;\n"+ + "class A {\n" + + " void a(boolean b) throws Exception {\n" + + " try(FileInputStream in = create(new FileInputStream(\"a\"))){}\n" + + " }\n" + + " FileInputStream create(FileInputStream ignored) throws IOException {\n" + + " return new FileInputStream(\"b\"); \n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 4)\n" + + " try(FileInputStream in = create(new FileInputStream(\"a\"))){}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: '' may not be closed\n" + + "----------\n", + options + ); +} + +// https://bugs.eclipse.org/411098 - [compiler][resource] Invalid Resource Leak Warning using ternary operator inside try-with-resource +public void testBug411098_test3() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "A.java", + "import java.io.*;\n" + + "class A {\n" + + " void m() throws IOException {\n" + + " try (FileInputStream a = new FileInputStream(\"A\") {{\n" + + " FileInputStream b = new FileInputStream(\"B\");\n" + + " b.hashCode();\n" + + " }}){\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 5)\n" + + " FileInputStream b = new FileInputStream(\"B\");\n" + + " ^\n" + + "Resource leak: 'b' is never closed\n" + + "----------\n", + options + ); +} + +// https://bugs.eclipse.org/411098 - [compiler][resource] Invalid Resource Leak Warning using ternary operator inside try-with-resource +public void testBug411098_test4() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "A.java", + "import java.io.FileInputStream;\n" + + "class A {\n" + + " void testB(boolean b) throws Exception {\n" + + " FileInputStream in = null;\n" + + " try {\n" + + " in = b ? new FileInputStream(\"a\") : null;\n" + + " } finally {\n" + + " in.close();\n" + + " }\n" + + " }\n" + + "}" + }, + options + ); +} + +// https://bugs.eclipse.org/411098 - [compiler][resource] Invalid Resource Leak Warning using ternary operator inside try-with-resource +public void testBug411098_test5() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "A.java", + "import java.io.FileInputStream;\n" + + "class A {\n" + + " void testA(boolean b) throws Exception {\n" + + " FileInputStream in = b ? new FileInputStream(\"a\") : null;\n" + + " in.close();\n" + + " }\n" + + "}" + }, + options + ); +} + +// https://bugs.eclipse.org/411098 - [compiler][resource] Invalid Resource Leak Warning using ternary operator inside try-with-resource +public void testBug411098_test6() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "A.java", + "import java.io.FileInputStream;\n" + + "class A {\n" + + " void testA(boolean b) throws Exception {\n" + + " FileInputStream in = b ? new FileInputStream(\"a\") : new FileInputStream(\"b\");\n" + + " in.close();\n" + + " }\n" + + "}" + }, + options + ); +} + +// https://bugs.eclipse.org/411098 - [compiler][resource] Invalid Resource Leak Warning using ternary operator inside try-with-resource +// challenge nested resource allocations +public void testBug411098_test7() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "A.java", + "import java.io.*;\n" + + "class A {\n" + + " void testA(boolean b) throws Exception {\n" + + " BufferedReader in = b ? new BufferedReader(new FileReader(\"a\")) : new BufferedReader(new FileReader(\"b\"));\n" + + " in.close();\n" + + " }\n" + + "}" + }, + options + ); +} + +// https://bugs.eclipse.org/411098 - [compiler][resource] Invalid Resource Leak Warning using ternary operator inside try-with-resource +// should report potential leak only. +public void testBug411098_comment19() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "A.java", + "import java.io.PrintWriter;\n" + + "public class A {\n" + + " PrintWriter fWriter;\n" + + " void bug(boolean useField) {\n" + + " PrintWriter bug= useField ? fWriter : null;\n" + + " System.out.println(bug);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 5)\n" + + " PrintWriter bug= useField ? fWriter : null;\n" + + " ^^^\n" + + "Potential resource leak: \'bug\' may not be closed\n" + + "----------\n", + options + ); +} +// normal java.util.stream.Stream doesn't hold on to any resources +public void testStream1() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // uses JRE 8 API + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "A.java", + "import java.util.*;\n" + + "import java.util.stream.Stream;\n" + + "class A {\n" + + " long test(List ss) {\n" + + " Stream stream = ss.stream();\n" + + " return stream.count();\n" + + " }\n" + + "}" + }, + options + ); +} +// normal java.util.stream.IntStream doesn't hold on to any resources +public void testStream1_Int() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // uses JRE 8 API + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "A.java", + "import java.util.stream.*;\n" + + "class A {\n" + + " public void f(Stream s) {\n" + + " IntStream n = s.mapToInt(Object::hashCode);\n" + + " IntStream n2 = IntStream.range(23, 42);\n" + + " n.forEach(i -> System.out.println(i));\n" + + " n2.forEach(i -> System.out.println(i));\n" + + " }\n" + + "}" + }, + options + ); +} +// normal java.util.stream.{Double,Long}Stream doesn't hold on to any resources +public void testStream1_Double_Long() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // uses JRE 8 API + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "A.java", + "import java.util.stream.*;\n" + + "class A {\n" + + " public void f(Stream s) {\n" + + " DoubleStream n = s.mapToDouble(o -> 0.2);\n" + + " LongStream n2 = LongStream.range(23, 42);\n" + + " n.forEach(i -> System.out.println(i));\n" + + " n2.forEach(i -> System.out.println(i));\n" + + " }\n" + + "}" + }, + options + ); +} +// normal java.util.stream.{Double,Long}Stream doesn't hold on to any resources +public void testStreamEx_572707() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // uses JRE 8 API + + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + STREAMEX_JAVA, + STREAMEX_CONTENT, + "Bug572707.java", + "import one.util.streamex.*;\n" + + "\n" + + "public class Bug572707 {\n" + + " public void m() {\n" + + " System.out.println(StreamEx.create());\n" + + " }\n" + + "}\n" + }, + options); +} +// Functions java.nio.file.Files.x() returning *Stream* do produce a resource needing closing +public void testStream2() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // uses JRE 8 API + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "A.java", + "import java.util.stream.Stream;\n" + + "import java.nio.file.*;\n" + + "class A {\n" + + " long test(Path start, FileVisitOption... options) throws java.io.IOException {\n" + + " Stream stream = Files.walk(start, options);\n" + + " return stream.count();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 5)\n" + + " Stream stream = Files.walk(start, options);\n" + + " ^^^^^^\n" + + "Resource leak: \'stream\' is never closed\n" + + "----------\n", + options + ); +} +// closeable, but Stream, but produced by Files.m, but only potentially closed: +public void testStream3() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // uses JRE 8 API + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "A.java", + "import java.util.stream.Stream;\n" + + "import java.nio.file.*;\n" + + "class A {\n" + + " void test(Path file) throws java.io.IOException {\n" + + " Stream lines = Files.lines(file);\n" + + " if (lines.count() > 0)" + + " lines.close();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in A.java (at line 5)\n" + + " Stream lines = Files.lines(file);\n" + + " ^^^^^\n" + + "Potential resource leak: \'lines\' may not be closed\n" + + "----------\n", + options + ); +} +// special stream from Files.m is properly handled by t-w-r +public void testStream4() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; // uses JRE 8 API + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "A.java", + "import java.util.stream.Stream;\n" + + "import java.nio.file.*;\n" + + "class A {\n" + + " void test(Path dir) throws java.io.IOException {\n" + + " try (Stream list = Files.list(dir)) {\n" + + " list.forEach(child -> System.out.println(child));\n" + + " }\n" + + " }\n" + + "}" + }, + options + ); +} +public void testBug415790_ex2() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; // uses foreach + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public void example2() throws IOException {\n" + + " for (final File file : new File[] { new File(\"/\") }) {\n" + + " BufferedReader reader = null;\n" + + " try {\n" + + " reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));\n" + + " }\n" + + " finally {\n" + + " try {\n" + + " reader.close();\n" + + " }\n" + + " catch (IOException e) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "" + + "}\n" + }, + options); +} +public void testBug415790_ex4() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public void example2(File[] files) throws IOException {\n" + + " for (int i = 0; i < files.length; i++) {\n" + + " File file = files[i];\n" + + " BufferedReader reader = null;\n" + + " try {\n" + + " reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));\n" + + " }\n" + + " finally {\n" + + " try {\n" + + " reader.close();\n" + + " }\n" + + " catch (IOException e) {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "" + + "}\n" + }, + options); +} +public void testBug371614_comment0() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "C.java", + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "\n" + + "public class C {\n" + + " public static void main(String[] args) {\n" + + " FileInputStream fileInputStream= null;\n" + + " try {\n" + + " fileInputStream = new FileInputStream(args[0]);\n" + + " while (true) {\n" + + " if (fileInputStream.read() == -1) {\n" + + " System.out.println(\"done\");\n" + + "// Resource leak: 'fileInputStream' is not closed at this location\n" + + " return;\n" + + " }\n" + + " }\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " return;\n" + + " } finally {\n" + + " closeStream(fileInputStream);\n" + + " }\n" + + " }\n" + + " \n" + + " private static void closeStream(InputStream stream) {\n" + + " if (stream != null) {\n" + + " try {\n" + + " stream.close();\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 14)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Potential resource leak: \'fileInputStream\' may not be closed at this location\n" + + "----------\n", + options); +} +public void testBug371614_comment2() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "ResourceLeak.java", + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "import java.io.InputStreamReader;\n" + + "import java.io.Reader;\n" + + "\n" + + "public class ResourceLeak {\n" + + "\n" + + " boolean check(final Reader r) throws IOException {\n" + + " final int i = r.read();\n" + + " return (i != -1);\n" + + " }\n" + + "\n" + + " public void test1() throws IOException {\n" + + " try (Reader r = new InputStreamReader(System.in);) {\n" + + " while (check(r)) {\n" + + " if (check(r))\n" + + " throw new IOException(\"fail\");\n" + + " if (!check(r))\n" + + " throw new IOException(\"fail\");\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " public void test2() throws IOException {\n" + + " try (Reader r = new InputStreamReader(new FileInputStream(\"test.txt\"));) {\n" + + " while (check(r)) {\n" + + " if (check(r))\n" + + " throw new IOException(\"fail\");\n" + + " if (!check(r))\n" + + " throw new IOException(\"fail\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug371614_comment8() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "import java.net.*;\n" + + "public class X {\n" + + " Socket fSocket;\n" + + " void test() {\n" + + " try (InputStreamReader socketIn = new InputStreamReader(fSocket.getInputStream())) {\n" + + " while (true) {\n" + + " if (socketIn.read(new char[1024]) < 0)\n" + + " throw new IOException(\"Error\");\n" + + " } \n" + + " } catch (IOException e) {\n" + + " }" + + " }\n" + + "}\n" + }, + options); +} +public void testBug462371_orig() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "interface IFile {\n" + + " InputStream getContents();\n" + + " boolean exists();\n" + + "}\n" + + "public class X {\n" + + " public static String getAnnotatedSignature(String typeName, IFile file, String selector, String originalSignature) {\n" + + " if (file.exists()) {\n" + + " try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()))) {\n" + + " reader.readLine();\n" + + " while (true) {\n" + + " String line = reader.readLine(); \n" + + " // selector:\n" + + " if (selector.equals(line)) {\n" + + " // original signature:\n" + + " line = reader.readLine();\n" + + " if (originalSignature.equals(\"\")) {\n" + + " // annotated signature:\n" + + " return reader.readLine();\n" + + " }\n" + + " }\n" + + " if (line == null)\n" + + " break;\n" + + " }\n" + + " } catch (IOException e) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + options); +} +public void _testBug462371_shouldWarn() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "interface IFile {\n" + + " InputStream getContents();\n" + + " boolean exists();\n" + + "}\n" + + "public class X {\n" + + " public static String getAnnotatedSignature(String typeName, IFile file, String selector, String originalSignature) {\n" + + " if (file.exists()) {\n" + + " try {\n" + + " BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents())); \n" + + " reader.readLine();\n" + + " while (true) {\n" + + " String line = reader.readLine(); \n" + + " // selector:\n" + + " if (selector.equals(line)) {\n" + + " // original signature:\n" + + " line = reader.readLine();\n" + + " if (originalSignature.equals(\"\")) {\n" + + " // annotated signature:\n" + + " return reader.readLine();\n" + + " }\n" + + " }\n" + + " if (line == null)\n" + + " break;\n" + + " }\n" + + " } catch (IOException e) {\n" + + " return null;\n" + + " }\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 14)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Potential resource leak: \'fileInputStream\' may not be closed at this location\n" + + "----------\n", + options); +} +public void testBug421035() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "Test.java", + "import java.io.BufferedReader;\n" + + "import java.io.FileNotFoundException;\n" + + "import java.io.FileReader;\n" + + "import java.io.IOException;\n" + + "import java.io.Reader;\n" + + "\n" + + "public class Test {\n" + + " void test() throws FileNotFoundException {\n" + + " Reader a = (Reader)new BufferedReader(new FileReader(\"a\"));\n" + + " try {\n" + + " a.close();\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug444964() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "Bug444964.java", + "import java.io.*;\n" + + "\n" + + "public class Bug444964 {\n" + + " void wrong() {\n" + + " try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {\n" + + " for (;;) {\n" + + " return;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + " void right() {\n" + + " try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {\n" + + " while (true) {\n" + + " return;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + "\n" + + "}\n" + }, + options); +} +public void testBug397204() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "HostIdTest.java", + "import java.io.*;\n" + + "import java.net.InetAddress;\n" + + "import java.net.NetworkInterface;\n" + + "import java.util.Enumeration;\n" + + "import java.util.Formatter;\n" + + "import java.util.Locale;\n" + + "\n" + + "\n" + + "public class HostIdTest {\n" + + "\n" + + " public final void primaryNetworkInterface() throws IOException {\n" + + " System.out.println(InetAddress.getLocalHost());\n" + + " System.out.println(InetAddress.getLocalHost().getHostName());\n" + + " System.out.println(hostId());\n" + + " }\n" + + "\n" + + " String hostId() throws IOException {\n" + + " try (StringWriter s = new StringWriter(); PrintWriter p = new PrintWriter(s)) {\n" + + " p.print(InetAddress.getLocalHost().getHostName());\n" + + " p.print('/');\n" + + " Enumeration e = NetworkInterface.getNetworkInterfaces();\n" + + " while (e.hasMoreElements()) {\n" + + " NetworkInterface i = e.nextElement();\n" + + " System.out.println(i);\n" + + " if (i.getHardwareAddress() == null || i.getHardwareAddress().length == 0)\n" + + " continue;\n" + + " for (byte b : i.getHardwareAddress())\n" + + " p.printf(\"%02x\", b);\n" + + " return s.toString();\n" + + " }\n" + + " throw new RuntimeException(\"Unable to determine Host ID\");\n" + + " }\n" + + " }\n" + + "\n" + + " public void otherHostId() throws Exception {\n" + + " InetAddress addr = InetAddress.getLocalHost();\n" + + " byte[] ipaddr = addr.getAddress();\n" + + " if (ipaddr.length == 4) {\n" + + " int hostid = ipaddr[1] << 24 | ipaddr[0] << 16 | ipaddr[3] << 8 | ipaddr[2];\n" + + " StringBuilder sb = new StringBuilder();\n" + + " try (Formatter formatter = new Formatter(sb, Locale.US)) {\n" + + " formatter.format(\"%08x\", hostid);\n" + + " System.out.println(sb.toString());\n" + + " }\n" + + " } else {\n" + + " throw new Exception(\"hostid for IPv6 addresses not implemented yet\");\n" + + " }\n" + + " }\n" + + " \n" + + "}\n" + }, + options); +} +public void testBug397204_comment4() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "HostIdTest.java", + "import java.io.*;\n" + + "\n" + + "public class HostIdTest {\n" + + "\n" + + " void simple() throws Exception {\n" + + " try (InputStream x = new ByteArrayInputStream(null)) {\n" + + " while (Math.abs(1) == 1)\n" + + " if (Math.abs(1) == 1)\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug433510() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // t-w-r used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "Bug433510.java", + "import java.io.*;\n" + + "\n" + + "public class Bug433510 {\n" + + "\n" + + " void test() throws Exception {\n" + + " try (Reader r = new StringReader(\"Hello World!\")) {\n" + + " int c;\n" + + " while ((c = r.read()) != -1) {\n" + + " if (c == ' ')\n" + + " throw new IOException(\"Unexpected space\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug440282() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "ResourceLeakFalseNegative.java", + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "import java.io.InputStreamReader;\n" + + "\n" + + "public final class ResourceLeakFalseNegative {\n" + + "\n" + + " private static final class Foo implements AutoCloseable {\n" + + " final InputStreamReader reader;\n" + + "\n" + + " Foo(final InputStreamReader reader) {\n" + + " this.reader = reader;\n" + + " }\n" + + " \n" + + " public int read() throws IOException {\n" + + " return reader.read();\n" + + " }\n" + + "\n" + + " public void close() throws IOException {\n" + + " reader.close();\n" + + " }\n" + + " }\n" + + "\n" + + " private static final class Bar {\n" + + " final int read;\n" + + "\n" + + " Bar(final InputStreamReader reader) throws IOException {\n" + + " read = reader.read();\n" + + " }\n" + + " \n" + + " public int read() {\n" + + " return read;\n" + + " }\n" + + " }\n" + + "\n" + + " public final static int foo() throws IOException {\n" + + " final FileInputStream in = new FileInputStream(\"/dev/null\");\n" + + " final InputStreamReader reader = new InputStreamReader(in);\n" + + " try {\n" + + " return new Foo(reader).read();\n" + + " } finally {\n" + + " // even though Foo is not closed, no potential resource leak is reported.\n" + + " }\n" + + " }\n" + + "\n" + + " public final static int bar() throws IOException {\n" + + " final FileInputStream in = new FileInputStream(\"/dev/null\");\n" + + " final InputStreamReader reader = new InputStreamReader(in);\n" + + " try {\n" + + " final Bar bar = new Bar(reader);\n" + + " return bar.read();\n" + + " } finally {\n" + + " // Removing the close correctly reports potential resource leak as a warning,\n" + + " // because Bar does not implement AutoCloseable.\n" + + " reader.close();\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws IOException {\n" + + " for (;;) {\n" + + " foo();\n" + + " bar();\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in ResourceLeakFalseNegative.java (at line 39)\n" + + " return new Foo(reader).read();\n" + + " ^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n", + options); +} +public void testBug390064() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // generics used + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + runLeakTest( + new String[] { + "Redundant.java", + "public class Redundant\n" + + "{\n" + + " private static class A implements AutoCloseable\n" + + " {\n" + + " public void close()\n" + + " {\n" + + " }\n" + + " }\n" + + "\n" + + " private static class B extends A\n" + + " {\n" + + " \n" + + " }\n" + + " \n" + + " private static class C implements AutoCloseable\n" + + " {\n" + + " public void close()\n" + + " {\n" + + " }\n" + + " }\n" + + " \n" + + " private static class D extends C\n" + + " {\n" + + " \n" + + " }\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " new B();\n" + + " \n" + + " new D();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Redundant.java (at line 29)\n" + + " new B();\n" + + " ^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "2. ERROR in Redundant.java (at line 31)\n" + + " new D();\n" + + " ^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n", + options); +} +public void testBug396575() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + runLeakTest( + new String[] { + "Bug396575.java", + "import java.io.*;\n" + + "\n" + + "public class Bug396575 {\n" + + " void test1(File myFile) {\n" + + " OutputStream out = null;\n" + + " BufferedWriter bw = null;\n" + + " try {\n" + + " // code...\n" + + " out = new FileOutputStream(myFile);\n" + + " OutputStreamWriter writer = new OutputStreamWriter(out);\n" + + " bw = new BufferedWriter(writer);\n" + + " // more code...\n" + + " } catch (Exception e) {\n" + + " try {\n" + + " bw.close(); // WARN: potential null pointer access\n" + + " } catch (Exception ignored) {}\n" + + " return; // WARN: resource leak - bw may not be closed\n" + + " }\n" + + " }\n" + + " \n" + + " void test2(File myFile) {\n" + + " BufferedWriter bw = null;\n" + + " try {\n" + + " // code...\n" + + " // declare \"out\" here inside try-catch as a temp variable\n" + + " OutputStream out = new FileOutputStream(myFile); // WARN: out is never closed.\n" + + " OutputStreamWriter writer = new OutputStreamWriter(out);\n" + + " bw = new BufferedWriter(writer);\n" + + " // more code...\n" + + " } catch (Exception e) {\n" + + " try {\n" + + " bw.close(); // WARN: potential null pointer access\n" + + " } catch (Exception ignored) {}\n" + + " return; // WARN: resource leak - bw may not be closed\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Bug396575.java (at line 11)\n" + + " bw = new BufferedWriter(writer);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'bw\' is never closed\n" + + "----------\n" + + "2. ERROR in Bug396575.java (at line 28)\n" + + " bw = new BufferedWriter(writer);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'bw\' is never closed\n" + + "----------\n", + options); +} +public void testBug473317() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // using diamond + Map compilerOptions = getCompilerOptions(); + compilerOptions.put(JavaCore.COMPILER_PB_SYNTHETIC_ACCESS_EMULATION, JavaCore.IGNORE); + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "AutoCloseableEnhancedForTest.java", + "import java.util.Iterator;\n" + + "\n" + + "public class AutoCloseableEnhancedForTest\n" + + "{\n" + + " private static class MyIterator implements Iterator\n" + + " {\n" + + " private T value;\n" + + " \n" + + " public MyIterator(T value)\n" + + " {\n" + + " this.value = value;\n" + + " }\n" + + " \n" + + " @Override\n" + + " public boolean hasNext()\n" + + " {\n" + + " return false;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public T next()\n" + + " {\n" + + " return value;\n" + + " }\n" + + " }\n" + + " \n" + + " private static class MyIterable implements Iterable, AutoCloseable\n" + + " {\n" + + " @Override\n" + + " public Iterator iterator()\n" + + " {\n" + + " return new MyIterator<>(null);\n" + + " }\n" + + " \n" + + " @Override\n" + + " public void close() throws Exception\n" + + " {\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args)\n" + + " {\n" + + " // Not flagged as \"never closed.\"\n" + + " for (Object value : new MyIterable<>())\n" + + " {\n" + + " System.out.println(String.valueOf(value));\n" + + " \n" + + " break;\n" + + " }\n" + + " \n" + + " // Flagged as \"never closed.\"\n" + + " MyIterable iterable = new MyIterable<>();\n" + + " \n" + + " for (Object value : iterable)\n" + + " {\n" + + " System.out.println(String.valueOf(value));\n" + + " \n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in AutoCloseableEnhancedForTest.java (at line 44)\n" + + " for (Object value : new MyIterable<>())\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "2. WARNING in AutoCloseableEnhancedForTest.java (at line 52)\n" + + " MyIterable iterable = new MyIterable<>();\n" + + " ^^^^^^^^\n" + + "Resource leak: \'iterable\' is never closed\n" + + "----------\n"; + runner.customOptions = compilerOptions; + runner.runWarningTest(); // javac warns about exception thrown from close() method +} +public void testBug541705() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // uses diamond + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runner.testFiles = new String[] { + "Test.java", + "import java.util.*;\n" + + "import java.util.zip.*;\n" + + "import java.io.*;\n" + + "public class Test {\n" + + " private static HashMap fgZipFileCache = new HashMap<>(5);\n" + + " public static void closeArchives() {\n" + + " synchronized (fgZipFileCache) {\n" + + " for (ZipFile file : fgZipFileCache.values()) {\n" + + " synchronized (file) {\n" + + " try {\n" + + " file.close();\n" + + " } catch (IOException e) {\n" + + " System.out.println(e);\n" + + " }\n" + + " }\n" + + " }\n" + + " fgZipFileCache.clear();\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); +} +public void testBug541705b() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; // variable used in t-w-r + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runner.testFiles = new String[] { + "Test.java", + "import java.util.*;\n" + + "import java.util.zip.*;\n" + + "import java.io.*;\n" + + "public class Test {\n" + + " private static HashMap fgZipFileCache = new HashMap<>(5);\n" + + " public static void closeArchives() {\n" + + " synchronized (fgZipFileCache) {\n" + + " for (ZipFile file : fgZipFileCache.values()) {\n" + + " synchronized (file) {\n" + + " try (file) {\n" + + " } catch (IOException e) {\n" + + " System.out.println(e);\n" + + " }\n" + + " }\n" + + " }\n" + + " fgZipFileCache.clear();\n" + + " }\n" + + " }\n" + + "}\n" + }; + runner.runConformTest(); +} +public void testBug542707_001() { + if (!checkPreviewAllowed()) return; // uses switch expression + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runLeakTest( + new String[] { + "X.java", + "import java.io.Closeable;\n"+ + "import java.io.IOException;\n"+ + "\n"+ + "public class X implements Closeable{\n"+ + " public static int foo(int i) throws IOException {\n"+ + " int k = 0;\n"+ + " X x = null;\n"+ + " try {\n"+ + " x = new X();\n"+ + " x = switch (i) { \n"+ + " case 1 -> {\n"+ + " yield x;\n"+ + " }\n"+ + " default -> x;\n"+ + " };\n"+ + " } finally {\n"+ + " x.close();\n"+ + " }\n"+ + " return k ;\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " try {\n"+ + " System.out.println(foo(3));\n"+ + " } catch (IOException e) {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + " @Override\n"+ + " public void close() throws IOException {\n"+ + " Zork();\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 31)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + options); +} +public void testBug542707_002() { + if (this.complianceLevel < ClassFileConstants.JDK15) return; // uses switch expression + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runLeakTest( + new String[] { + "X.java", + "import java.io.Closeable;\n"+ + "import java.io.IOException;\n"+ + "\n"+ + "public class X implements Closeable{\n"+ + " public static int foo(int i) throws IOException {\n"+ + " int k = 0;\n"+ + " X x = null;\n"+ + " try {\n"+ + " x = new X();\n"+ + " x = switch (i) { \n"+ + " case 1 -> {\n"+ + " x = new X();\n"+ + " yield x;\n"+ + " }\n"+ + " default -> x;\n"+ + " };\n"+ + " } finally {\n"+ + " x.close();\n"+ + " }\n"+ + " return k ;\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " try {\n"+ + " System.out.println(foo(3));\n"+ + " } catch (IOException e) {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + " @Override\n"+ + " public void close() throws IOException {\n"+ + " Zork();\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " x = new X();\n" + + " ^^^^^^^^^^^\n" + + "Resource leak: \'x\' is not closed at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 32)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + options); +} +public void testBug542707_003() { + if (!checkPreviewAllowed()) return; // uses switch expression + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + runLeakTest( + new String[] { + "X.java", + "import java.io.Closeable;\n"+ + "import java.io.IOException;\n"+ + "\n"+ + "public class X implements Closeable{\n"+ + " public static int foo(int i) throws IOException {\n"+ + " int k = 0;\n"+ + " X x = null;\n"+ + " try {\n"+ + " x = new X();\n"+ + " x = switch (i) { \n"+ + " case 1 -> {\n"+ + " yield new X();\n"+ + " }\n"+ + " default -> x;\n"+ + " };\n"+ + " } finally {\n"+ + " x.close();\n"+ + " }\n"+ + " return k ;\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " try {\n"+ + " System.out.println(foo(3));\n"+ + " } catch (IOException e) {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + " @Override\n"+ + " public void close() throws IOException {\n"+ + " Zork();\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " x = switch (i) { \n" + + " case 1 -> {\n" + + " yield new X();\n" + + " }\n" + + " default -> x;\n" + + " };\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'x\' is not closed at this location\n" + + "----------\n" + + "2. ERROR in X.java (at line 31)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + options); +} +public void testBug486506() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) return; // uses switch expression + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIALLY_UNCLOSED_CLOSEABLE, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "LogMessage.java", + "import java.util.stream.*;\n" + + "import java.io.*;\n" + + "import java.nio.file.*;\n" + + "import java.nio.charset.*;\n" + + "class LogMessage {\n" + + " LogMessage(Path path, String message) {}\n" + + " public static Stream streamSingleLineLogMessages(Path path) {\n" + + " try {\n" + + " Stream lineStream = Files.lines(path, StandardCharsets.ISO_8859_1);\n" + + " Stream logMessageStream =\n" + + " lineStream.map(message -> new LogMessage(path, message));\n" + + " logMessageStream.onClose(lineStream::close);\n" + + " return logMessageStream;\n" + + " } catch (IOException e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in LogMessage.java (at line 13)\n" + + " return logMessageStream;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'lineStream\' may not be closed at this location\n" + + "----------\n", + options); +} +public void testBug463320() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "Try17.java", + "import java.util.zip.*;\n" + + "import java.io.*;\n" + + "public class Try17 {\n" + + " void potential() throws IOException {\n" + + " String name= getZipFile().getName();\n" + + " System.out.println(name);\n" + + " }\n" + + " void definite() throws IOException {\n" + + " String name= new ZipFile(\"bla.jar\").getName();\n" + + " System.out.println(name);\n" + + " }\n" + + " void withLocal() throws IOException {\n" + + " ZipFile zipFile = getZipFile();\n" + + " String name= zipFile.getName();\n" + + " System.out.println(name);\n" + + " }\n" + + "\n" + + " ZipFile getZipFile() throws IOException {\n" + + " return new ZipFile(\"bla.jar\");\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Try17.java (at line 5)\n" + + " String name= getZipFile().getName();\n" + + " ^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n" + + "2. ERROR in Try17.java (at line 9)\n" + + " String name= new ZipFile(\"bla.jar\").getName();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "2. ERROR in Try17.java (at line 13)\n" + + " ZipFile zipFile = getZipFile();\n" + + " ^^^^^^^\n" + + "Potential resource leak: \'zipFile\' may not be closed\n" + + "----------\n", + options); +} +public void testBug463320_comment8() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // required version of java.nio.file.* + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "Try17.java", + "import java.io.*;\n" + + "import java.nio.file.*;\n" + + "import java.net.*;\n" + + "public class Try17 {\n" + + " public InputStream openInputStream(URI uri) {\n" + + " try {\n" + + " System.out.println(FileSystems.getFileSystem(uri));\n" + + " return Files.newInputStream(Paths.get(uri));\n" + + " } catch (FileSystemNotFoundException e) {\n" + + " throw new IllegalArgumentException(e);\n" + + " } catch (IOException e) {\n" + + " throw new IllegalStateException(e);\n" + + " }\n" + + " }\n" + + " public InputStream delegateGet(URI uri) {\n" + + " return openInputStream(uri);\n" + // no problem here! + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Try17.java (at line 7)\n" + + " System.out.println(FileSystems.getFileSystem(uri));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n", + options); +} +public void testBug558574() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses varargs signatures + + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + + runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " void m1() throws FileNotFoundException {\n" + + " PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(\"/tmp/out\")));\n" + + " pw.printf(\"%d\", 42).close();\n" + + " }\n" + + " void m2(PrintWriter pw) throws FileNotFoundException {\n" + + " pw.printf(\"%d\", 42).append(\"end\").close();\n" + + " }\n" + + " void m3() throws FileNotFoundException {\n" + + " new PrintWriter(new OutputStreamWriter(new FileOutputStream(\"/tmp/out\")))\n" + + " .format(\"%d\", 42)\n" + + " .append(\"end\")\n" + + " .close();\n" + + " }\n" + + " void m4(PrintWriter pw) throws FileNotFoundException {\n" + + " pw.printf(\"%d\", 42).append(\"end\");\n" + + " }\n" + + "}\n" + }, + "", + options); +} +public void testBug560460() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // uses try-with-resources + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " Scanner m(String source) {\n" + + " return new Scanner(source).useDelimiter(\"foobar\");\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug463320_comment19() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + + runConformTest( + new String[] { + "Try17.java", + "import java.util.zip.*;\n" + + "import java.io.*;\n" + + "public class Try17 {\n" + + " void withLocal() throws IOException {\n" + + " ZipFile zipFile = null;\n" + + " if (zipFile != null)" + + " zipFile = getZipFile();\n" + // not reachable + " String name= zipFile.getName();\n" + + " System.out.println(name);\n" + + " }\n" + + "\n" + + " ZipFile getZipFile() throws IOException {\n" + + " return new ZipFile(\"bla.jar\");\n" + + " }\n" + + "}" + }, + options); +} +public void testBug552521() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // uses try-with-resources + + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + runLeakTest( + new String[] { + "EclipseBug552521getChannel.java", + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.FileOutputStream;\n" + + "import java.nio.channels.FileChannel;\n" + + "\n" + + "public class EclipseBug552521getChannel {\n" + + "\n" + + " @SuppressWarnings(\"unused\")\n" + + " public void copyFile(final File srcFile, final File dstFile) throws Exception {\n" + + " /*\n" + + " * TODO Eclipse Setting: Window/Preferences/Java/Compiler/Errors-Warnings/\n" + + " * Resource not managed via try-with-resource = Ignore (default)\n" + + " */\n" + + " try (\n" + + " final FileInputStream srcStream = new FileInputStream (srcFile);\n" + + " final FileChannel srcChannel = srcStream.getChannel();\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + // line 17 + " // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TODO Warning ok\n" + + " )\n" + + " {\n" + + " srcChannel.transferTo(0, srcChannel.size(), dstChannel);\n" + + " }\n" + + "\n" + + " if (srcFile.isFile()) { // \"if\" (resolved at runtime) -> Warning suppressed\n" + + " try (\n" + + " final FileInputStream srcStream = new FileInputStream (srcFile);\n" + + " final FileChannel srcChannel = srcStream.getChannel();\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + // line 28 + " // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FIXME Warning missing!\n" + + " )\n" + + " {\n" + + " srcChannel.transferTo(0, srcChannel.size(), dstChannel);\n" + + " }\n" + + " } else { // \"else\" (resolved at runtime) -> Warning suppressed\n" + + " try (\n" + + " final FileInputStream srcStream = new FileInputStream (srcFile);\n" + + " final FileChannel srcChannel = srcStream.getChannel();\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + // line 38 + " // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FIXME Warning missing!\n" + + " )\n" + + " {\n" + + " srcChannel.transferTo(0, srcChannel.size(), dstChannel);\n" + + " }\n" + + " }\n" + + "\n" + + " if (true) { // Dummy \"if\" (= constant true) -> Warning\n" + + " try (\n" + + " final FileInputStream srcStream = new FileInputStream (srcFile);\n" + + " final FileChannel srcChannel = srcStream.getChannel();\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + // line 50 + " // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TODO Warning ok\n" + + " )\n" + + " {\n" + + " srcChannel.transferTo(0, srcChannel.size(), dstChannel);\n" + + " }\n" + + " } else { // Dummy \"else\" (= constant false) -> Warning suppressed\n" + + " try (\n" + + " final FileInputStream srcStream = new FileInputStream (srcFile);\n" + + " final FileChannel srcChannel = srcStream.getChannel();\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + // line 60 + " // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FIXME Warning missing!\n" + + " )\n" + + " {\n" + + " srcChannel.transferTo(0, srcChannel.size(), dstChannel);\n" + + " }\n" + + " }\n" + + "\n" + + " if (false) { // Dummy \"if\" (= constant false) -> Warning suppressed\n" + + " try (\n" + + " final FileInputStream srcStream = new FileInputStream (srcFile);\n" + + " final FileChannel srcChannel = srcStream.getChannel();\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + // line 72 + " // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FIXME Warning missing!\n" + + " )\n" + + " {\n" + + " srcChannel.transferTo(0, srcChannel.size(), dstChannel);\n" + + " }\n" + + " } else { // Dummy \"else\" (= constant true) -> Warning\n" + + " try (\n" + + " final FileInputStream srcStream = new FileInputStream (srcFile);\n" + + " final FileChannel srcChannel = srcStream.getChannel();\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + // line 82 + " // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TODO Warning ok\n" + + " )\n" + + " {\n" + + " srcChannel.transferTo(0, srcChannel.size(), dstChannel);\n" + + " }\n" + + " }\n" + + " /*\n" + + " * Following test-case differs from all the above as follows:\n" + + " * FileInputStream is unassigned, instead of FileOutputStream\n" + + " */\n" + + " try (\n" + + " final FileChannel srcChannel = new FileInputStream (srcFile) .getChannel();\n" + // line 94 + " // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TODO Warning ok\n" + + " final FileOutputStream dstStream = new FileOutputStream(srcFile);\n" + + " final FileChannel dstChannel = dstStream.getChannel();\n" + + " )\n" + + " {\n" + + " srcChannel.transferTo(0, srcChannel.size(), dstChannel);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in EclipseBug552521getChannel.java (at line 17)\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "2. ERROR in EclipseBug552521getChannel.java (at line 28)\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "3. ERROR in EclipseBug552521getChannel.java (at line 38)\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "4. ERROR in EclipseBug552521getChannel.java (at line 50)\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "5. ERROR in EclipseBug552521getChannel.java (at line 60)\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "6. ERROR in EclipseBug552521getChannel.java (at line 72)\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "7. ERROR in EclipseBug552521getChannel.java (at line 82)\n" + + " final FileChannel dstChannel = new FileOutputStream(dstFile) .getChannel();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n" + + "8. ERROR in EclipseBug552521getChannel.java (at line 94)\n" + + " final FileChannel srcChannel = new FileInputStream (srcFile) .getChannel();\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Resource leak: \'\' is never closed\n" + + "----------\n", + options); +} +public void testBug552521_comment14() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses foreach + + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "import java.util.*;\n" + + "public class X {\n" + + " List process(InputStream is) throws IOException {\n" + + " is.close();\n" + + " return Collections.emptyList();\n" + + " }\n" + + " void test(String fileName) throws IOException {\n" + + " for (String string : process(new FileInputStream(fileName))) {\n" + + " System.out.println(string);\n" + + " }\n" + + " }\n" + + " void test2(String fileName) throws IOException {\n" + + " for (String string : process(new FileInputStream(fileName)))\n" + + " System.out.println(string);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " for (String string : process(new FileInputStream(fileName))) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " for (String string : process(new FileInputStream(fileName)))\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n", + options); +} +public void testBug552521_comment14b() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses foreach + + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " boolean check(InputStream is) throws IOException {\n" + + " is.close();\n" + + " return true;\n" + + " }\n" + + " void test1(String fileName) throws IOException {\n" + + " while (check(new FileInputStream(fileName)))\n" + + " System.out.println(\"while\");\n" + + " }\n" + + " void test2(String fileName) throws IOException {\n" + + " do {\n" + + " System.out.println(\"while\");\n" + + " } while (check(new FileInputStream(fileName)));\n" + + " }\n" + + " void test3(String fileName) throws IOException {\n" + + " for (int i=0;check(new FileInputStream(fileName));i++)\n" + + " System.out.println(i);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " while (check(new FileInputStream(fileName)))\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 14)\n" + + " } while (check(new FileInputStream(fileName)));\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n" + + "3. ERROR in X.java (at line 17)\n" + + " for (int i=0;check(new FileInputStream(fileName));i++)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n", + options); +} +public void testBug519740() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // uses try-with-resources + + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "Snippet.java", + "class Snippet {\n" + + " static void foo() throws Exception {\n" + + " try (java.util.Scanner scanner = new java.util.Scanner(new java.io.FileInputStream(\"abc\"))) {\n" + + " while (scanner.hasNext()) \n" + + " if (scanner.hasNextInt())\n" + + " throw new RuntimeException(); /* Potential resource leak: 'scanner' may not be closed at this location */\n" + + " }\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug552441() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // uses try-with-resources + + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + + runConformTest( + new String[] { + "Test.java", + "import java.io.BufferedOutputStream;\n" + + "import java.io.FileOutputStream;\n" + + "import java.io.IOException;\n" + + "import java.io.OutputStream;\n" + + "import java.util.concurrent.atomic.AtomicLong;\n" + + "\n" + + "public class Test {\n" + + " public static class CountingBufferedOutputStream extends BufferedOutputStream {\n" + + " private final AtomicLong bytesWritten;\n" + + "\n" + + " public CountingBufferedOutputStream(OutputStream out, AtomicLong bytesWritten) throws IOException {\n" + + " super(out);\n" + + " this.bytesWritten = bytesWritten;\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void write(byte[] b) throws IOException {\n" + + " super.write(b);\n" + + " bytesWritten.addAndGet(b.length);\n" + + " }\n" + + "\n" + + " @Override\n" + + " public void write(byte[] b, int off, int len) throws IOException {\n" + + " super.write(b, off, len);\n" + + " bytesWritten.addAndGet(len);\n" + + " }\n" + + "\n" + + " @Override\n" + + " public synchronized void write(int b) throws IOException {\n" + + " super.write(b);\n" + + " bytesWritten.incrementAndGet();\n" + + " }\n" + + " }\n" + + "\n" + + " public static void test(String[] args) throws IOException {\n" + + " AtomicLong uncompressedBytesOut = new AtomicLong();\n" + + " int val = 0;\n" + + " try (CountingBufferedOutputStream out = new CountingBufferedOutputStream(\n" + + " new FileOutputStream(\"outputfile\"), uncompressedBytesOut)) {\n" + + "\n" + + " for (int i = 0; i < 1; i++) {\n" + + " if (val > 2) {\n" + + " throw new RuntimeException(\"X\");\n" + + " }\n" + + " }\n" + + " if (val > 2) {\n" + + " throw new RuntimeException(\"Y\");\n" + + " }\n" + + " throw new RuntimeException(\"Z\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug400523() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + + runConformTest( + new String[] { + "LeakWarning.java", + "import java.sql.Connection;\n" + + "import java.sql.PreparedStatement;\n" + + "import java.sql.ResultSet;\n" + + "import java.sql.SQLException;\n" + + "\n" + + "public class LeakWarning {\n" + + " String value = null;\n" + + " \n" + + " public void setValue(Connection conn)\n" + + " { \n" + + " PreparedStatement stmt = null;\n" + + " ResultSet rs = null;\n" + + " try { \n" + + " stmt = conn.prepareStatement(\"SELECT 'value'\"); /* marked as potential resource leak */\n" + + " rs = stmt.executeQuery(); /* marked as potential resource leak */\n" + + " if (rs.next()) value = rs.getString(1);\n" + + " } catch(SQLException e) {\n" + + " }\n" + + " finally {\n" + + " if (null != rs) try { rs.close(); } catch (SQLException e) {} finally { rs = null; }\n" + + " if (null != stmt) try { stmt.close(); } catch (SQLException e) {} finally { stmt = null; }\n" + + " }\n" + + " }\n" + + " \n" + + " public void setValueReturn(Connection conn)\n" + + " { \n" + + " PreparedStatement stmt = null;\n" + + " ResultSet rs = null;\n" + + " try { \n" + + " stmt = conn.prepareStatement(\"SELECT 'value'\");\n" + + " rs = stmt.executeQuery();\n" + + " if (rs.next()) value = rs.getString(1);\n" + + " } catch(SQLException e) {\n" + + " }\n" + + " finally {\n" + + " if (null != rs) try { rs.close(); } catch (SQLException e) {} finally { rs = null; }\n" + + " if (null != stmt) try { stmt.close(); } catch (SQLException e) {} finally { stmt = null; }\n" + + " }\n" + + " return; /* no warning now */\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug527761() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runConformTest( + new String[] { + "X.java", + "class BAOSWrapper extends java.io.ByteArrayOutputStream {}\n" + + "public class X {\n" + + " public static void warningCauser() {\n" + + " BAOSWrapper baos = new BAOSWrapper();\n" + + " //WARNING HAS BEEN CAUSED\n" + + " baos.write(0);\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug527761_otherClose() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses generics + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + String xSource = + "public class X {\n" + + " public static void warningCauser() {\n" + + " BAOSWrapper baos = new BAOSWrapper();\n" + + " //WARNING HAS BEEN CAUSED\n" + + " baos.write(0);\n" + + " }\n" + + "}\n"; + runConformTest( + new String[] { + "BAOSWrapper.java", + "class BAOSWrapper extends java.io.ByteArrayOutputStream {\n" + + " public void close(java.util.List l) {}\n" + // not relevant, param challenges treatment of unresolved types + "}\n", + "X.java", + xSource + }, + options); + // consume BAOSWrapper from .class: + runConformTest(false, + new String[] { "X.java", xSource }, + "", "", "", null); +} +public void testBug527761_neg() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "class BAOSWrapper extends java.io.ByteArrayOutputStream {\n" + + " public void close() {}\n" + // indicates that resource could be relevant + "}\n" + + "public class X {\n" + + " public static void warningCauser() {\n" + + " BAOSWrapper baos = new BAOSWrapper();\n" + + " //WARNING HAS BEEN CAUSED\n" + + " baos.write(0);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " BAOSWrapper baos = new BAOSWrapper();\n" + + " ^^^^\n" + + "Resource leak: \'baos\' is never closed\n" + + "----------\n", + options); +} +// regression caused by Bug 527761 +public void testBug558759() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses generics + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + String ySource = + "public class Y {\n" + + " class YInner extends X {}\n" + + "}\n"; + runConformTest( + new String[] { + "I.java", + "import java.io.Closeable;\n" + + "public interface I extends Closeable {\n" + + " interface Location {}\n" + + " void m(Location l);\n" + + "}\n", + "X0.java", + "public abstract class X0 implements I {\n" + + " public void close() {}\n" + + "}\n", + "X.java", + "public class X extends X0 implements I {\n" + + " public void m(Location l) {}\n" + + "}\n", + "Y.java", + ySource + }, + options); + runConformTest(false, + new String[] { "Y.java", ySource }, + "", "", "", null); +} +public void testBug559119() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses @Override + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + runLeakWarningTest( + new String[] { + "Sequencer.java", + "interface Sequencer extends AutoCloseable {\n" + + " void close(); // no exception\n" + + "}\n", + "SequencerControl.java", + "public abstract class SequencerControl {\n" + + " public abstract Sequencer getSequencer();\n" + + " @Override\n" + + " public boolean equals(Object obj) {\n" + + " if (obj != null) {\n" + + " if (getClass().equals(obj.getClass())) {\n" + + " return ((SequencerControl)obj).getSequencer().equals(getSequencer());\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in SequencerControl.java (at line 7)\n" + + " return ((SequencerControl)obj).getSequencer().equals(getSequencer());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n" + + "2. WARNING in SequencerControl.java (at line 7)\n" + + " return ((SequencerControl)obj).getSequencer().equals(getSequencer());\n" + + " ^^^^^^^^^^^^^^\n" + + "Potential resource leak: \'\' may not be closed\n" + + "----------\n", + options); +} +public void testBug560610() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; // uses enum + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + runConformTest( + new String[] { + "A.java", + "import java.util.EnumSet;\n" + + "public abstract class A extends B implements C {\n" + + " void m(EnumSet en) {}\n" + // unResolvedMethods() when a is seen as a PTB causes bogus resolving of this method + "}\n", + "B.java", + "public abstract class B implements AutoCloseable {}\n", // this causes A to be seen as a resource requiring closer inspection + "C.java", + "public interface C {}\n", // just so we can read D as a type argument during hierarchy connecting for A + "D.java", + "public abstract class D extends A {}\n", // extends A causes searching A for a close method, A seen as a PTB + "EN.java", + "public enum EN {\n" + // when we find this via ahead-of-time resolveTypesFor("m()") we don't yet have a superclass + " One, Two;\n" + + "}\n" + }, + "", + options); +} +public void testBug560671() { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // uses t-w-r + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + runConformTest( + new String[] { + "X.java", + "import java.util.Scanner;\n" + + "public class X {\n" + + " void m(String source) {\n" + + " try (Scanner s = new Scanner(source).useDelimiter(\"foobar\")) {\n" + + " System.out.println(s.next());\n" + + " }\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug560671b() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + runConformTest( + new String[] { + "X.java", + "import java.util.Scanner;\n" + + "public class X {\n" + + " void m(String source) throws java.io.IOException {\n" + + " Scanner s = null;" + + " try {\n" + + " s = new Scanner(source).useDelimiter(\"foobar\");\n" + + " System.out.println(s.next());\n" + + " } finally {\n" + + " if (s != null) s.close();\n" + + " }\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug561259() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.WARNING); + runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " protected String m(String charset) throws IOException\n" + + " {\n" + + " InputStream contents = new FileInputStream(\"/tmp/f\");\n" + + " BufferedReader reader = new BufferedReader(new InputStreamReader(contents, charset));\n" + + " CharArrayWriter writer = new CharArrayWriter();\n" + + " int c;\n" + + " while ((c = reader.read()) != -1)\n" + + " {\n" + + " writer.write(c);\n" + + " }\n" + + " contents.close();\n" + + " return writer.toString();\n" + + " }\n" + + "}\n" + }, + options); +} +public void testBug560076() { + runNegativeTest( + new String[] { + "org/sqlite/database/sqlite/SQLiteOpenHelper.java", + "package org.sqlite.database.sqlite;\n" + + "\n" + + "public abstract class SQLiteOpenHelper {\n" + + " private void getDatabaseLocked(String name, SQLiteDatabase mDatabase) {\n" + + " SQLiteDatabase sQLiteDatabase4 = mDatabase;\n" + + " try {\n" + + " sQLiteDatabase4 = name == null ? null : openDatabase();\n" + + " } catch (Throwable e) {\n" + + " sQLiteDatabase4 = openDatabase();\n" + + " }\n" + + " }\n" + + "\n" + + " public static SQLiteDatabase openDatabase() {\n" + + " }\n" + + "}\n" + + "\n" + + "final class SQLiteDatabase implements java.io.Closeable {\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in org\\sqlite\\database\\sqlite\\SQLiteOpenHelper.java (at line 4)\n" + + " private void getDatabaseLocked(String name, SQLiteDatabase mDatabase) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method getDatabaseLocked(String, SQLiteDatabase) from the type SQLiteOpenHelper is never used locally\n" + + "----------\n" + + "2. ERROR in org\\sqlite\\database\\sqlite\\SQLiteOpenHelper.java (at line 13)\n" + + " public static SQLiteDatabase openDatabase() {\n" + + " ^^^^^^^^^^^^^^\n" + + "This method must return a result of type SQLiteDatabase\n" + + "----------\n" + + "3. ERROR in org\\sqlite\\database\\sqlite\\SQLiteOpenHelper.java (at line 17)\n" + + " final class SQLiteDatabase implements java.io.Closeable {\n" + + " ^^^^^^^^^^^^^^\n" + + "The type SQLiteDatabase must implement the inherited abstract method Closeable.close()\n" + + "----------\n"); +} +public void testBug499037_001_since_9() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " final Y y1 = new Y();\n" + + " try (y1) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "} \n" + }, + "", + options); +} +public void testBug499037_002_since_9() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " Y y1 = new Y();\n" + + " try (y1; final Y y2 = new Y()) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "} \n" + }, + "", + options); +} +public void testBug499037_003_since_9() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + runLeakTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "public class X { \n" + + " public void foo() throws IOException {\n" + + " Y y1 = new Y();\n" + + " try(y1) { \n" + + " return;\n" + + " }\n" + + " } \n" + + "} \n" + + "\n" + + "class Y implements Closeable {\n" + + " final int x = 10;\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}" + }, + "", + options); +} +public void testBug499037_004_since_9() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "class Z {\n" + + " final Y yz = new Y();\n" + + "}\n" + + "public class X extends Z {\n" + + " final Y y2 = new Y();\n" + + " \n" + + " public void foo() {\n" + + " try (super.yz; y2) {\n" + + " System.out.println(\"In Try\");\n" + + " } catch (IOException e) {\n" + + " \n" + + " }finally { \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " System.out.println(\"Closed\");\n" + + " } \n" + + "} \n" + }, + "", + options); +} +public void testBug499037_005_since_9() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.IOException;\n"+ + "\n"+ + "public class X {\n"+ + " void test(boolean b) throws IOException {\n"+ + " Y y = new Y();\n"+ + " if (b) {\n"+ + " try (y) {}\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws IOException {\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Potential resource leak: \'y\' may not be closed\n" + + "----------\n", + options); +} +// non-empty finally block - takes a different route +public void testBug499037_006_since_9() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.IOException;\n"+ + "\n"+ + "public class X {\n"+ + " void test(boolean b) throws IOException {\n"+ + " Y y = new Y();\n"+ + " if (b) {\n"+ + " try (y;Y y2 = new Y();) { \n"+ + " } finally {\n"+ + " System.out.println(\"hello\");\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws IOException {\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Potential resource leak: \'y\' may not be closed\n" + + "----------\n", + options); +} +public void testBug499037_007_since_9() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.IOException;\n"+ + "\n"+ + "public class X {\n"+ + " void test(boolean b) throws IOException {\n"+ + " Y y = new Y();\n"+ + " if (b) {\n"+ + " try (y) { \n"+ + " // nothing \n"+ + " }\n"+ + " }\n"+ + " else {\n"+ + " y.close();\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws IOException {\n"+ + " }\n"+ + "}\n" + }, + "", + options); +} +public void testBug499037_008_since_9() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.IOException;\n"+ + "\n"+ + "public class X {\n"+ + " void test(boolean b, Y yDash) throws IOException {\n"+ + " Y y = new Y();\n"+ + " if (b) {\n"+ + " try (y; yDash) { \n"+ + " // nothing \n"+ + " }\n"+ + " }\n"+ + " else {\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws IOException {\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Potential resource leak: \'y\' may not be closed\n" + + "----------\n", + options); +} +public void testBug499037_009_since_9() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.IOException;\n"+ + "\n"+ + "public class X {\n"+ + "private void foo(Y y) {}\n" + + " void test(boolean b) throws IOException {\n"+ + " Y y = new Y();\n"+ + " if (b) {\n"+ + " try (y) { \n"+ + " // nothing \n"+ + " }\n"+ + " }\n"+ + " else {\n"+ + " foo(y);\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws IOException {\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Potential resource leak: \'y\' may not be closed\n" + + "----------\n", + options); +} +public void testBug499037_010_since_9() { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, CompilerOptions.ERROR); + runLeakTest( + new String[] { + "X.java", + "import java.io.IOException;\n"+ + "\n"+ + "public class X {\n"+ + "private Y foo(Y y) {return y;}\n" + + " void test(boolean b) throws IOException {\n"+ + " Y y = new Y();\n"+ + " Y yy = foo(y);\n"+ + " if (b) {\n"+ + " try (y;yy) { \n"+ + " // do nothing \n"+ + " }\n"+ + " }\n"+ + " else {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws IOException {\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " Y y = new Y();\n" + + " ^\n" + + "Potential resource leak: \'y\' may not be closed\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Y yy = foo(y);\n" + + " ^^\n" + + "Potential resource leak: \'yy\' may not be closed\n" + + "----------\n", + options); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RunComparableTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RunComparableTests.java new file mode 100644 index 0000000000..05806e73c6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RunComparableTests.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; + +import org.eclipse.jdt.core.tests.junit.extension.TestCase; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Run all compiler regression tests + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class RunComparableTests extends junit.framework.TestCase { + + public static ArrayList ALL_CLASSES = null; + static { + ALL_CLASSES = new ArrayList(); + ALL_CLASSES.add(AmbiguousMethodTest.class); + ALL_CLASSES.add(AutoBoxingTest.class); + ALL_CLASSES.add(SuppressWarningsTest.class); + ALL_CLASSES.add(Compliance_1_5.class); + ALL_CLASSES.add(GenericTypeTest.class); + ALL_CLASSES.add(GenericsRegressionTest.class); + ALL_CLASSES.add(ForeachStatementTest.class); + ALL_CLASSES.add(StaticImportTest.class); + ALL_CLASSES.add(VarargsTest.class); + ALL_CLASSES.add(EnumTest.class); + ALL_CLASSES.add(MethodVerifyTest.class); + ALL_CLASSES.add(AnnotationTest.class); + ALL_CLASSES.add(EnclosingMethodAttributeTest.class); + // Reset forgotten subsets tests + TestCase.TESTS_PREFIX = null; + TestCase.TESTS_NAMES = null; + TestCase.TESTS_NUMBERS= null; + TestCase.TESTS_RANGE = null; + TestCase.RUN_ONLY_ID = null; + } + + public RunComparableTests(String testName) { + super(testName); + } + + public static Test suite() { + TestSuite ts = new TestSuite(RunComparableTests.class.getName()); + for (int i = 0, size=ALL_CLASSES.size(); i < size; i++) { + Class testClass = (Class) ALL_CLASSES.get(i); + try { + Method suiteMethod = testClass.getDeclaredMethod("suite", new Class[0]); //$NON-NLS-1$ + Test suite = (Test)suiteMethod.invoke(null, new Object[0]); + ts.addTest(suite); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.getTargetException().printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + return ts; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RuntimeTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RuntimeTests.java new file mode 100644 index 0000000000..978be89ba6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RuntimeTests.java @@ -0,0 +1,529 @@ +/******************************************************************************* + * Copyright (c) 2006, 2010 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +/* + * Here we focus on various aspects of the runtime behavior of the generated + * code. + */ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class RuntimeTests extends AbstractRegressionTest { + +public RuntimeTests(String name) { + super(name); +} + +// Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which does not belong to the class are skipped... +// 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[] { "test0001" }; +// TESTS_NUMBERS = new int[] { 1 }; +// TESTS_RANGE = new int[] { 1, -1 }; +} + +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public static Class testClass() { + return RuntimeTests.class; +} + +// decided not to keep this active because of negative effects on the test +// series (the OOME potentially causing grief to others) +// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=217078 +// memory exhaustion - try to allocate too big an instance +public void _test0001_memory_exhaustion() { + runTest( + new String[] { /* testFiles */ + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " try {" + + " Y y = new Y(Integer.MAX_VALUE);\n" + + " }" + + " catch (OutOfMemoryError e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILURE\");\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " long storage[];\n" + + " Y(int itemsNb) {\n" + + " storage = new long[itemsNb];\n" + + " }\n" + + "}\n"}, + false /* expectingCompilerErrors */, + "" /* expectedCompilerLog */, + "SUCCESS" /* expectedOutputString */, + null /* expectedErrorString - skip this because some JREs emit additional info to stderr in case of exception */, + false /* forceExecution */, + null /* classLib */, + true /* shouldFlushOutputDirectory */, + null /* vmArguments */, + null /* customOptions */, + null /* clientRequestor */, + true /* skipJavac */); +} + +// synchronization - concurrent access to a resource with explicit and +// implicit locks +public void test0500_synchronization() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "static public void main (String args[]) {\n" + + " new Lock().implicitLock();\n" + + "}\n" + + "}\n" + + "class Lock extends Thread {\n" + + " byte step = 0;\n" + + " void logStep(String start) {\n" + + " System.out.println(start + \" \" + this.step); //$NON-NLS-1$\n" + + " }\n" + + " public void run() {\n" + + " for (int i = 1; i < 3; i++) {\n" + + " logStep(\"explicit lock\"); //$NON-NLS-1$\n" + + " synchronized (this) {\n" + + " this.step++;\n" + + " notify();\n" + + " while(this.step < 2 * i) {\n" + + " try {\n" + + " wait();\n" + + " } catch (InterruptedException e) {\n" + + " System.out.println(\"EXCEPTION\"); //$NON-NLS-1$\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " synchronized void implicitLock() {\n" + + " this.start();\n" + + " for (int i = 0; i < 2; i++) {\n" + + " while (this.step < 1 + i * 2) {\n" + + " try {\n" + + " wait();\n" + + " } catch (InterruptedException e) {\n" + + " System.out.println(\"EXCEPTION\"); //$NON-NLS-1$\n" + + " }\n" + + " }\n" + + " logStep(\"implicit lock\"); //$NON-NLS-1$\n" + + " this.step++;\n" + + " notify();\n" + + " }\n" + + " return;\n" + + " }\n" + + "}\n"}, + "explicit lock 0\n" + + "implicit lock 1\n" + + "explicit lock 2\n" + + "implicit lock 3" + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=126712 +// reflection - access to a public method of a package visible +// class through a public extending class +public void test0600_reflection() { + runConformTest( + true, + new String[] { + "X.java", + "import java.lang.reflect.*;\n" + + "import p.*;\n" + + "public class X {\n" + + "static public void main (String args[]) {\n" + + " Y y = new Y();\n" + + " try {\n" + + " Method foo = Y.class.getMethod(\"foo\", (Class []) null);\n" + + " y.foo();\n" + + " foo.invoke(y, (Object []) null);\n" + + " } catch (NoSuchMethodException e) {\n" + + " //ignore\n" + + " } catch (InvocationTargetException e) {\n" + + " //ignore\n" + + " } catch (IllegalAccessException e) {\n" + + " System.out.print(\"FAILURE: IllegalAccessException\");\n" + + " }\n" + + "}\n" + + "}", + "p/Y.java", + "package p;\n" + + "public class Y extends Z {\n" + + " /* empty */\n" + + "}\n", + "p/Z.java", + "package p;\n" + + "class Z {\n" + + " public void foo() {\n" + + " System.out.println(\"SUCCESS\"); //$NON-NLS-1$\n" + + " }\n" + + "}\n"}, + "", + this.complianceLevel <= ClassFileConstants.JDK1_5 ? "SUCCESS\n" + "FAILURE: IllegalAccessException" : "SUCCESS\n" + "SUCCESS", + "", + JavacTestOptions.EclipseJustification.EclipseBug126712 + ); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=126712 +// reflection - access to a public field of a package visible +// class through a public extending class +public void test0601_reflection() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.*;\n" + + "import p.*;\n" + + "public class X {\n" + + "static public void main (String args[]) {\n" + + " Y y = new Y();\n" + + " try {\n" + + " Field f = Y.class.getField(\"m\");\n" + + " System.out.println(y.m);\n" + + " System.out.println(f.get(y));\n" + + " } catch (NoSuchFieldException e) {\n" + + " //ignore\n" + + " } catch (IllegalAccessException e) {\n" + + " System.out.print(\"FAILURE: IllegalAccessException\");\n" + + " }\n" + + "}\n" + + "}", + "p/Y.java", + "package p;\n" + + "public class Y extends Z {\n" + + " /* empty */\n" + + "}\n", + "p/Z.java", + "package p;\n" + + "class Z {\n" + + " public String m = \"SUCCESS\";\n" + + "}\n"}, + "SUCCESS\n" + + "FAILURE: IllegalAccessException" + ); +} + +// partial rebuild - method signature changed (return type) +public void test1000_partial_rebuild() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "static public void main(String args[]) {\n" + + " Z.go();\n" + + "}\n" + + "}\n", + "Z.java", + "public class Z {\n" + + "static public void go() {\n" + + " int flag = 0;\n" + + " try {\n" + + " new Y().random();\n" + + " flag = 1;\n" + + " }\n" + + " catch (NoSuchMethodError e) {\n" + + " flag = 2;\n" + + " }\n" + + " catch (Throwable t) {\n" + + " flag = 3;\n" + + " }\n" + + " System.out.println(flag);\n" + + "}\n" + + "}\n", + "Y.java", + "public class Y {\n" + + "java.util.Random generator = new java.util.Random();" + + "public byte random() {\n" + + " return (byte) (generator.nextInt() % Byte.MAX_VALUE);\n" + + "}\n" + + "}\n", + }, + "1"); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "static public void main(String args[]) {\n" + + " Z.go();\n" + + "}\n" + + "}\n", + "Y.java", + "public class Y {\n" + + "java.util.Random generator = new java.util.Random();" + + "public int random() {\n" + // random now returns an int + " return generator.nextInt();\n" + + "}\n" + + "}\n", + }, + "2", + null, + false, // do not purge output directory - pick old version of Z.class + null); +} + +// partial rebuild - method signature changed (parameter type) +public void test1001_partial_rebuild() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "static public void main(String args[]) {\n" + + " Z.go();\n" + + "}\n" + + "}\n", + "Z.java", + "public class Z {\n" + + "static public void go() {\n" + + " byte flag = 0;\n" + + " try {\n" + + " new Y().random(flag);\n" + + " flag = 1;\n" + + " }\n" + + " catch (NoSuchMethodError e) {\n" + + " flag = 2;\n" + + " }\n" + + " catch (Throwable t) {\n" + + " flag = 3;\n" + + " }\n" + + " System.out.println(flag);\n" + + "}\n" + + "}\n", + "Y.java", + "public class Y {\n" + + "public int random(byte seed) {\n" + + " return seed++;\n" + + "}\n" + + "}\n", + }, + "1"); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "static public void main(String args[]) {\n" + + " Z.go();\n" + + "}\n" + + "}\n", + "Y.java", + "public class Y {\n" + + "public int random(int seed) {\n" + // seed now of type int + " return seed++;\n" + + "}\n" + + "}\n", + }, + "2", + null, + false, // do not purge output directory - pick old version of Z.class + null); +} + +// partial rebuild - method signature changed (visibility) +public void test1002_partial_rebuild() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "static public void main(String args[]) {\n" + + " new Z().go();\n" + + "}\n" + + "}\n", + "Z.java", + "public class Z extends p.Y {\n" + + " class ZInner extends YInner {\n" + + " // empty\n" + + " }\n" + + "public void go() {\n" + + " byte flag = 0;\n" + + " try {\n" + + " new ZInner().foo();\n" + + " flag = 1;\n" + + " }\n" + + " catch (IllegalAccessError e) {\n" + + " flag = 2;\n" + + " }\n" + + " catch (Throwable t) {\n" + + " flag = 3;\n" + + " }\n" + + " System.out.println(flag);\n" + + "}\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " public class YInner {\n" + + " public void foo() {\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "1"); + this.runConformTest( + false, + new String[] { + "X.java", + "public class X {\n" + + "static public void main(String args[]) {\n" + + " new Z().go();\n" + + "}\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " public class YInner {\n" + + " void foo() {\n" + // now foo no more visible (package only) + " return;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + "2", + "", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} + +// partial rebuild - method signature changed (visibility) +public void test1003_partial_rebuild() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "static public void main(String args[]) {\n" + + " new Z().go();\n" + + "}\n" + + "}\n", + "Z.java", + "public class Z extends p.Y {\n" + + " class ZInner extends YInner {\n" + + " // empty\n" + + " }\n" + + "public void go() {\n" + + " byte flag = 0;\n" + + " try {\n" + + " new ZInner().foo();\n" + + " flag = 1;\n" + + " }\n" + + " catch (IllegalAccessError e) {\n" + + " flag = 2;\n" + + " }\n" + + " catch (Throwable t) {\n" + + " flag = 3;\n" + + " }\n" + + " System.out.println(flag);\n" + + "}\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " public class YInner {\n" + + " public void foo() {\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "1"); + this.runConformTest( + false, // do not purge output directory - pick old version of Z.class + new String[] { + "X.java", + "public class X {\n" + + "static public void main(String args[]) {\n" + + " new Z().go();\n" + + "}\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y {\n" + + " public class YInner {\n" + + " protected void foo() {\n" + + // now foo no more visible (package + inheriting classes only) + " return;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + "2", + "", + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); +} + +// partial rebuild - extending class now redefines extended class fields and +// methods +// was Compliance_1_x#test009 +public void test1004_partial_rebuild() { + this.runConformTest( + new String[] { + "p1/Z.java", + "package p1; \n"+ + "public class Z { \n" + + " public static void main(String[] arguments) { \n"+ + " Y y = new Y(); \n" + + " System.out.print(y.field); \n" + + " System.out.print(y.staticField); \n" + + " System.out.print(y.method()); \n" + + " System.out.println(y.staticMethod()); \n" + + " } \n"+ + "} \n", + "p1/X.java", + "package p1; \n"+ + "public class X { \n"+ + " public String field = \"X.field-\"; \n" + + " public static String staticField = \"X.staticField-\"; \n" + + " public String method(){ return \"X.method()-\"; } \n" + + " public static String staticMethod(){ return \"X.staticMethod()-\"; } \n" + + "} \n", + "p1/Y.java", + "package p1; \n"+ + "public class Y extends X { \n"+ + "} \n" + }, + "X.field-X.staticField-X.method()-X.staticMethod()-"); + String expectedOutput = + this.complianceLevel == ClassFileConstants.JDK1_3 ? + "X.field-X.staticField-Y.method()-X.staticMethod()-" : + "Y.field-Y.staticField-Y.method()-Y.staticMethod()-"; + this.runConformTest( + new String[] { + "p1/Y.java", + "package p1; \n"+ + "public class Y extends X { \n"+ + " public static void main(String[] arguments) { \n"+ + " Z.main(arguments); \n" + + " } \n" + + " public String field = \"Y.field-\"; \n" + + " public static String staticField = \"Y.staticField-\"; \n" + + " public String method(){ return \"Y.method()-\"; } \n" + + " public static String staticMethod(){ return \"Y.staticMethod()-\"; } \n" + + "} \n" + }, + expectedOutput, // expected output + null, // use default class-path + false, // do not flush previous output dir content + null); // no special vm args +} + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java new file mode 100644 index 0000000000..440350879d --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ScannerTest.java @@ -0,0 +1,1585 @@ +/******************************************************************************* + * Copyright (c) 2000, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.compiler.IScanner; +import org.eclipse.jdt.core.compiler.ITerminalSymbols; +import org.eclipse.jdt.core.compiler.InvalidInputException; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.parser.Scanner; +import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; +import org.eclipse.jdt.internal.core.util.PublicScanner; + +@SuppressWarnings({ "rawtypes" }) +public class ScannerTest extends AbstractRegressionTest { + + public ScannerTest(String name) { + super(name); + } + // 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[] { "test000" }; +// TESTS_NUMBERS = new int[] { 60 }; +// TESTS_RANGE = new int[] { 54, -1 }; + } + + public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); + } + + public static Class testClass() { + return ScannerTest.class; + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23181 + */ + public void test001() { + String sourceA001 = "\\u003b"; + IScanner scanner = ToolFactory.createScanner(false, true, false, false); + scanner.setSource(sourceA001.toCharArray()); + int token = 0; + try { + token = scanner.getNextToken(); + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong token type", ITerminalSymbols.TokenNameSEMICOLON, token); + } + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23181 + */ + public void test002() { + String sourceA002 = "// tests\n "; + IScanner scanner = ToolFactory.createScanner(false, true, false, false); + scanner.setSource(sourceA002.toCharArray()); + int token = 0; + try { + token = scanner.getNextToken(); + assertEquals("Wrong token type", ITerminalSymbols.TokenNameWHITESPACE, token); + assertEquals("Wrong size", 2, scanner.getCurrentTokenSource().length); + token = scanner.getNextToken(); + assertEquals("Wrong token type", ITerminalSymbols.TokenNameEOF, token); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23181 + */ + public void test003() { + String sourceA003 = "// tests\n "; + IScanner scanner = ToolFactory.createScanner(true, true, false, false); + scanner.setSource(sourceA003.toCharArray()); + int token = 0; + try { + token = scanner.getNextToken(); + assertEquals("Wrong token type", ITerminalSymbols.TokenNameCOMMENT_LINE, token); + token = scanner.getNextToken(); + assertEquals("Wrong token type", ITerminalSymbols.TokenNameWHITESPACE, token); + assertEquals("Wrong size", 2, scanner.getCurrentTokenSource().length); + token = scanner.getNextToken(); + assertEquals("Wrong token type", ITerminalSymbols.TokenNameEOF, token); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + + /** + * float constant can have exponent part without dot: 01e0f + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=30704 + */ + public void test004() { + String source = "01e0f"; + IScanner scanner = ToolFactory.createScanner(false, false, false, false); + scanner.setSource(source.toCharArray()); + int token = 0; + try { + token = scanner.getNextToken(); + assertEquals("Wrong token type", ITerminalSymbols.TokenNameFloatingPointLiteral, token); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=43437 + */ + public void test005() { + StringBuilder buf = new StringBuilder(); + buf.append("\"Hello\""); + String str = buf.toString(); + IScanner scanner = ToolFactory.createScanner(true, false, false, false); + scanner.setSource(str.toCharArray()); + scanner.resetTo(0, str.length() - 1); + int token = 0; + try { + token = scanner.getNextToken(); + assertEquals("Wrong token type", ITerminalSymbols.TokenNameStringLiteral, token); + token = scanner.getNextToken(); + assertEquals("Wrong token type", ITerminalSymbols.TokenNameEOF, token); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=43485 + */ + public void test006() { + IScanner scanner = ToolFactory.createScanner(false, false, false, false); + try { + scanner.setSource(null); + } catch (NullPointerException e) { + assertTrue(false); + } + } + + /* + * Check that bogus resetTo issues EOFs + */ + public void test007() { + IScanner scanner = ToolFactory.createScanner(false, false, false, false); + char[] source = "int i = 0;".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(source.length + 50, source.length - 1); + int token = -1; + try { + token = scanner.getNextToken(); + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Expecting EOF", ITerminalSymbols.TokenNameEOF, token); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test008() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0x11aa.aap-3333f".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + int token = -1; + try { + token = scanner.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameFloatingPointLiteral, token); + token = scanner.getNextToken(); + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Expecting EOF", ITerminalSymbols.TokenNameEOF, token); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test009() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_4); + char[] source = "0x11aa.aap-3333f".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + scanner.getNextToken(); + } catch (InvalidInputException e) { + assertEquals("Wrong message", PublicScanner.ILLEGAL_HEXA_LITERAL, e.getMessage()); + } + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test010() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + 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++; + } + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong number of tokens", 1, counter); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test011() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0x.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++; + } + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong number of tokens", 1, counter); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test012() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0xaap3f".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + int counter = 0; + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + counter++; + } + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong number of tokens", 1, counter); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test013() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0xaapaf".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + // ignore + } + } catch (InvalidInputException e) { + assertTrue(true); + return; + } + assertTrue(false); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test014() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0xaap.1f".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + // ignore + } + } catch (InvalidInputException e) { + assertTrue(true); + return; + } + assertTrue(false); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test015() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0xaa.p1f".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + int counter = 0; + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + counter++; + } + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong number of tokens", 1, counter); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test016() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0xaa.p1F".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + int counter = 0; + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + counter++; + } + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong number of tokens", 1, counter); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test017() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0xaa.p1D".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + int counter = 0; + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + counter++; + } + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong number of tokens", 1, counter); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74126 + */ + public void test018() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0xaa.p1d".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + int counter = 0; + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + counter++; + } + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong number of tokens", 1, counter); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74934 + */ + public void test019() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_4); + char[] source = "0x".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + // ignore + } + } catch (InvalidInputException e) { + assertTrue(true); + return; + } + assertTrue(false); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74934 + */ + public void test020() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0x".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + // ignore + } + } catch (InvalidInputException e) { + assertTrue(true); + return; + } + assertTrue(false); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74934 + */ + public void test021() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_4); + char[] source = "0x1".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + int counter = 0; + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + counter++; + } + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong number of tokens", 1, counter); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74934 + */ + public void test022() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0x1".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + int counter = 0; + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + counter++; + } + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong number of tokens", 1, counter); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78905 + */ + public void test023() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_5); + char[] source = "0x.p-2".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + } + assertTrue(false); + } catch (InvalidInputException e) { + assertTrue(true); + } + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=84398 + */ + public void test024() { + IScanner scanner = ToolFactory.createScanner(false, false, true, JavaCore.VERSION_1_5); + char[] source = "public class X {\n\n}".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + int counter = 0; + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + counter++; + } + } catch (InvalidInputException e) { + } + + assertEquals("wrong number of tokens", 5, counter); + int[] lineEnds = scanner.getLineEnds(); + assertNotNull("No line ends", lineEnds); + assertEquals("wrong length", 2, lineEnds.length); + source = "public class X {}".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + lineEnds = scanner.getLineEnds(); + assertNotNull("No line ends", lineEnds); + assertEquals("wrong length", 0, lineEnds.length); + + counter = 0; + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + counter++; + } + } catch (InvalidInputException e) { + } + + assertEquals("wrong number of tokens", 5, counter); + lineEnds = scanner.getLineEnds(); + assertNotNull("No line ends", lineEnds); + assertEquals("wrong length", 0, lineEnds.length); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=84398 + */ + public void test025() { + IScanner scanner = ToolFactory.createScanner(true, true, false, true); + scanner.setSource("String\r\nwith\r\nmany\r\nmany\r\nline\r\nbreaks".toCharArray()); + + try { + while(scanner.getNextToken()!=ITerminalSymbols.TokenNameEOF){} + } catch (InvalidInputException e) { + assertTrue(false); + } + + assertEquals("Wrong size", 5, scanner.getLineEnds().length); + + scanner.setSource("No line breaks here".toCharArray()); // expecting line breaks to reset + assertEquals("Wrong size", 0, scanner.getLineEnds().length); + } + + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=86611 + */ + public void test026() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_4); + char[] source = "0x.p-2".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + while (scanner.getNextToken() != ITerminalSymbols.TokenNameEOF) { + } + assertTrue(false); + } catch (InvalidInputException e) { + assertTrue(true); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90414 + public void test027() { + char[] source = ("class Test {\n" + + " char C = \"\\u005Cn\";\n" + + "}").toCharArray(); + Scanner scanner = new Scanner(false, false, false, ClassFileConstants.JDK1_4, null, null, false); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + int token; + StringBuffer buffer = new StringBuffer(); + while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { + try { + switch(token) { + case TerminalTokens.TokenNameEOF : + break; + default : + buffer.append(scanner.getCurrentTokenSource()); + break; + } + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + assertEquals("Wrong contents", "classTest{charC=\"\n\";}", String.valueOf(buffer)); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90414 + public void test028() { + char[] source = ("class Test {\n" + + " char C = \'\\u005Cn\';\n" + + "}").toCharArray(); + Scanner scanner = new Scanner(false, false, false, ClassFileConstants.JDK1_4, null, null, false); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + int token; + StringBuffer buffer = new StringBuffer(); + while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { + try { + switch(token) { + case TerminalTokens.TokenNameStringLiteral : + buffer.append(new String(scanner.getCurrentTokenSourceString())); + break; + case TerminalTokens.TokenNameEOF : + break; + default : + buffer.append(scanner.getCurrentTokenSource()); + break; + } + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + assertEquals("Wrong contents", "classTest{charC=\'\\n\';}", String.valueOf(buffer)); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90414 + public void test029() { + char[] source = ("class Test {\n" + + " char C = \"\\n\";\n" + + "}").toCharArray(); + Scanner scanner = new Scanner(false, false, false, ClassFileConstants.JDK1_4, null, null, false); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + int token; + StringBuffer buffer = new StringBuffer(); + while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { + try { + switch(token) { + case TerminalTokens.TokenNameEOF : + break; + default : + buffer.append(scanner.getCurrentTokenSource()); + break; + } + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + assertEquals("Wrong contents", "classTest{charC=\"\n\";}", String.valueOf(buffer)); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90414 + public void test030() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static String C = \"\\n\";\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.print(C.length());\n" + + " System.out.print(C.charAt(0) == \'\\n\');\n" + + " }\n" + + "}" + }, + "1true"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90414 + public void test031() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static String C = \"\\u005Cn\";\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.print(C.length());\n" + + " System.out.print(C.charAt(0) == \'\\n\');\n" + + " }\n" + + "}" + }, + "1true"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90414 + public void test032() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static char C = \'\\u005Cn\';\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.print(C == \'\\n\');\n" + + " }\n" + + "}" + }, + "true"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90414 + public void test033() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static char C = \\u0027\\u005Cn\\u0027;\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.print(C == \'\\n\');\n" + + " }\n" + + "}" + }, + "true"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90414 + public void test034() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + " static String C = \"\u0043\\n\\u0043\";\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.print(C.length());\n" + + " System.out.print(C.charAt(1) == \'\\n\');\n" + + " }\n" + + "}" + }, + "3true"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=90414 + public void test035() { + /* + * Corresponding source: + * + * public class Test { + * static String C = "\n"; + * public static void main(String[] args) { + * System.out.print(C.length()); + * System.out.print(C.charAt(0) == '\n'); + * } + * } + */ + this.runConformTest( + new String[] { + "Test.java", + "\\u0070\\u0075\\u0062\\u006c\\u0069\\u0063\\u0020\\u0063\\u006c\\u0061\\u0073\\u0073\\u0020\\u0054\\u0065\\u0073\\u0074\\u0020\\u007b\\u000A\n" + + "\\u0020\\u0020\\u0073\\u0074\\u0061\\u0074\\u0069\\u0063\\u0020\\u0053\\u0074\\u0072\\u0069\\u006e\\u0067\\u0020\\u0043\\u0020\\u003d\\u0020\\u0022\\u005c\\u006e\\u0022\\u003b\\u000A\n" + + "\\u0020\\u0020\\u000A\n" + + "\\u0020\\u0020\\u0070\\u0075\\u0062\\u006c\\u0069\\u0063\\u0020\\u0073\\u0074\\u0061\\u0074\\u0069\\u0063\\u0020\\u0076\\u006f\\u0069\\u0064\\u0020\\u006d\\u0061\\u0069\\u006e\\u0028\\u0053\\u0074\\u0072\\u0069\\u006e\\u0067\\u005b\\u005d\\u0020\\u0061\\u0072\\u0067\\u0073\\u0029\\u0020\\u007b\\u000A\n" + + "\\u0020\\u0020\\u0009\\u0053\\u0079\\u0073\\u0074\\u0065\\u006d\\u002e\\u006f\\u0075\\u0074\\u002e\\u0070\\u0072\\u0069\\u006e\\u0074\\u0028\\u0043\\u002e\\u006c\\u0065\\u006e\\u0067\\u0074\\u0068\\u0028\\u0029\\u0029\\u003b\\u000A\n" + + "\\u0020\\u0020\\u0009\\u0053\\u0079\\u0073\\u0074\\u0065\\u006d\\u002e\\u006f\\u0075\\u0074\\u002e\\u0070\\u0072\\u0069\\u006e\\u0074\\u0028\\u0043\\u002e\\u0063\\u0068\\u0061\\u0072\\u0041\\u0074\\u0028\\u0030\\u0029\\u0020\\u003d\\u003d\\u0020\\u0027\\u005c\\u006e\\u0027\\u0029\\u003b\\u000A\n" + + "\\u0020\\u0020\\u007d\\u0020\\u0009\\u000A\n" + + "\\u007d" + }, + "1true"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106403 + public void test036() { + try { + IScanner s = ToolFactory.createScanner(true, true, true, "1.5", "1.5"); + char[] source = { ';', ' ' }; + s.setSource(source); + s.resetTo(0, 0); + int token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameSEMICOLON, token); + char[] tokenSource = s.getCurrentTokenSource(); + assertEquals("wront size", 1, tokenSource.length); + assertEquals("Wrong character", ';', tokenSource[0]); + token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, token); + } catch (InvalidInputException e) { + assertTrue("Should not happen", false); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106403 + public void test037() { + try { + IScanner s = ToolFactory.createScanner(true, true, true, "1.5", "1.5"); + char[] source = { ';', ' ' }; + s.setSource(source); + int token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameSEMICOLON, token); + char[] tokenSource = s.getCurrentTokenSource(); + assertEquals("wront size", 1, tokenSource.length); + assertEquals("Wrong character", ';', tokenSource[0]); + token = s.getNextToken(); + tokenSource = s.getCurrentTokenSource(); + assertEquals("wront size", 1, tokenSource.length); + assertEquals("Wrong character", ' ', tokenSource[0]); + assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, token); + token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, token); + } catch (InvalidInputException e) { + assertTrue("Should not happen", false); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106403 + public void test038() { + try { + IScanner s = ToolFactory.createScanner(true, true, true, "1.5", "1.5"); + char[] source = { ';', ' ' }; + s.setSource(source); + s.resetTo(0, 1); + int token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameSEMICOLON, token); + char[] tokenSource = s.getCurrentTokenSource(); + assertEquals("wront size", 1, tokenSource.length); + assertEquals("Wrong character", ';', tokenSource[0]); + token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, token); + tokenSource = s.getCurrentTokenSource(); + assertEquals("wront size", 1, tokenSource.length); + assertEquals("Wrong character", ' ', tokenSource[0]); + token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, token); + } catch (InvalidInputException e) { + assertTrue("Should not happen", false); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106403 + public void test039() { + try { + IScanner s = ToolFactory.createScanner(true, true, true, "1.5", "1.5"); + char[] source = { ';', ' ' }; + s.setSource(source); + s.resetTo(1, 1); + int token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, token); + char[] tokenSource = s.getCurrentTokenSource(); + assertEquals("wront size", 1, tokenSource.length); + assertEquals("Wrong character", ' ', tokenSource[0]); + token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, token); + } catch (InvalidInputException e) { + assertTrue("Should not happen", false); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106403 + public void test040() { + try { + IScanner s = ToolFactory.createScanner(true, true, true, "1.5", "1.5"); + char[] source = { ';', ' ' }; + s.setSource(source); + s.resetTo(2, 1); + int token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, token); + } catch (InvalidInputException e) { + assertTrue("Should not happen", false); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106403 + public void test041() { + try { + IScanner s = ToolFactory.createScanner(true, true, true, "1.5", "1.5"); + char[] source = "\\u003B\\u0020".toCharArray(); + assertEquals("wrong size", 12, source.length); + s.setSource(source); + s.resetTo(0, 5); + int token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameSEMICOLON, token); + char[] tokenSource = s.getRawTokenSource(); + assertEquals("wront size", 6, tokenSource.length); + assertEquals("Wrong character", "\\u003B", new String(tokenSource)); + token = s.getNextToken(); + assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, token); + } catch (InvalidInputException e) { + assertTrue("Should not happen", false); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=112223 + public void test042() { + IScanner scanner = ToolFactory.createScanner(true, true, true, "1.5", "1.5"); + final char[] source = "\"a\\u000D\"".toCharArray(); + scanner.setSource(source); + final StringBuffer buffer = new StringBuffer(); + try { + int token; + while ((token = scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) { + try { + switch(token) { + case ITerminalSymbols.TokenNameEOF : + break; + default : + buffer.append(scanner.getCurrentTokenSource()); + break; + } + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + assertTrue("Should have failed", false); + } catch (InvalidInputException e) { + buffer.append(scanner.getRawTokenSource()); + assertEquals("Unexpected contents", "\"a\\u000D\"", String.valueOf(buffer)); + assertEquals("Wrong exception", PublicScanner.INVALID_CHAR_IN_STRING, e.getMessage()); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=112223 + public void test043() { + IScanner scanner = ToolFactory.createScanner(true, true, true, "1.5", "1.5"); + final char[] source = "\"\\u004Ca\\u000D\"".toCharArray(); + scanner.setSource(source); + final StringBuffer buffer = new StringBuffer(); + try { + int token; + while ((token = scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) { + try { + switch(token) { + case ITerminalSymbols.TokenNameEOF : + break; + default : + buffer.append(scanner.getCurrentTokenSource()); + break; + } + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + assertTrue("Should have failed", false); + } catch (InvalidInputException e) { + buffer.append(scanner.getRawTokenSource()); + assertEquals("Unexpected contents", "\"\\u004Ca\\u000D\"", String.valueOf(buffer)); + assertEquals("Wrong exception", PublicScanner.INVALID_CHAR_IN_STRING, e.getMessage()); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=112223 + public void test044() { + IScanner scanner = ToolFactory.createScanner(true, true, true, "1.5", "1.5"); + final char[] source = "\"\\u004Ca\\u000D\\u0022".toCharArray(); + scanner.setSource(source); + final StringBuffer buffer = new StringBuffer(); + try { + int token; + while ((token = scanner.getNextToken()) != ITerminalSymbols.TokenNameEOF) { + try { + switch(token) { + case ITerminalSymbols.TokenNameEOF : + break; + default : + buffer.append(scanner.getCurrentTokenSource()); + break; + } + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + assertTrue("Should have failed", false); + } catch (InvalidInputException e) { + buffer.append(scanner.getRawTokenSource()); + assertEquals("Unexpected contents", "\"\\u004Ca\\u000D\\u0022", String.valueOf(buffer)); + assertEquals("Wrong exception", PublicScanner.INVALID_CHAR_IN_STRING, e.getMessage()); + } + } + + public void test045() { + /* + * Corresponding source: + * + * public class Test { + * static String C = "\n"; + * public static void main(String[] args) { + * System.out.print(C.length()); + * System.out.print(C.charAt(0) == '\n'); + * } + * } + */ + this.runConformTest( + new String[] { + "_X.java", + "import java.lang.reflect.Field;\n" + + "public class _X {\n" + + " public static void main(String[] args) {\n" + + " String i\\u0000;\n" + + " String i\\u0001;\n" + + " String i\\u0002;\n" + + " String i\\u0003;\n" + + " String i\\u0004;\n" + + " String i\\u0005;\n" + + " String i\\u0006;\n" + + " String i\\u0007;\n" + + " String i\\u0008;\n" + + " String i\\u000e;\n" + + " String i\\u000f;\n" + + " String i\\u0010;\n" + + " String i\\u0011;\n" + + " String i\\u0012;\n" + + " String i\\u0013;\n" + + " String i\\u0014;\n" + + " String i\\u0015;\n" + + " String i\\u0016;\n" + + " String i\\u0017;\n" + + " String i\\u0018;\n" + + " String i\\u0019;\n" + + " String i\\u001a;\n" + + " String i\\u001b;\n" + + " String i\\u007f;\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=264950 + public void test046() { + IScanner scanner = ToolFactory.createScanner( + true, + true, + true, + JavaCore.getOption(JavaCore.COMPILER_SOURCE), + JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); + final char[] source = "{\r\n\t}".toCharArray(); + scanner.setSource(source); + scanner.resetTo(1, 3); + try { + assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken()); + assertEquals("Wrong source", "\r\n\t", new String(scanner.getCurrentTokenSource())); + assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, scanner.getNextToken()); + } catch (InvalidInputException e) { + assertTrue("Wrong exception", false); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529 + public void test047() { + IScanner scanner = ToolFactory.createScanner( + true, + true, + true, + JavaCore.getOption(JavaCore.COMPILER_SOURCE), + JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); + final char[] source = "// a comment, longer than the offset".toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, 5); + try { + assertEquals("Wrong token", ITerminalSymbols.TokenNameCOMMENT_LINE, scanner.getNextToken()); + assertEquals("Wrong source", "// a c", new String(scanner.getCurrentTokenSource())); + assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, scanner.getNextToken()); + } catch (InvalidInputException e) { + assertTrue("Wrong exception", false); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529 + public void test048() { + IScanner scanner = ToolFactory.createScanner( + true, + true, + true, + JavaCore.getOption(JavaCore.COMPILER_SOURCE), + JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); + final char[] source = "/*a comment, longer\n than the\noffset*/".toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, 5); + try { + assertEquals("Wrong token", ITerminalSymbols.TokenNameCOMMENT_BLOCK, scanner.getNextToken()); + assertTrue("Should fail with InvalidInputException", false); + } catch (InvalidInputException e) { + assertEquals("Wrong source", "/*a co", new String(scanner.getCurrentTokenSource())); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529 + public void test049() { + IScanner scanner = ToolFactory.createScanner( + true, + true, + true, + JavaCore.getOption(JavaCore.COMPILER_SOURCE), + JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); + final char[] source = "/*a coabstract, longer\n than the\noffset*/".toCharArray(); + scanner.setSource(source); + scanner.resetTo(6, 13); + try { + assertEquals("Wrong token", ITerminalSymbols.TokenNameabstract, scanner.getNextToken()); + assertEquals("Wrong source", "abstract", new String(scanner.getCurrentTokenSource())); + assertEquals("Wrong token", ITerminalSymbols.TokenNameEOF, scanner.getNextToken()); + } catch (InvalidInputException e) { + assertTrue("Wrong exception", false); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529 + public void test050() { + IScanner scanner = ToolFactory.createScanner( + true, + true, + true, + JavaCore.getOption(JavaCore.COMPILER_SOURCE), + JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); + final char[] source = "\"a comment, longer\\n than the\\noffset \"".toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, 5); + try { + assertEquals("Wrong token", ITerminalSymbols.TokenNameStringLiteral, scanner.getNextToken()); + assertTrue("Should fail with InvalidInputException", false); + } catch (InvalidInputException e) { + assertEquals("Wrong source", "\"a com", new String(scanner.getCurrentTokenSource())); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529 + public void test051() { + IScanner scanner = ToolFactory.createScanner( + true, + true, + true, + JavaCore.getOption(JavaCore.COMPILER_SOURCE), + JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); + final char[] source = "\"a co\\u00E9mment, longer\\n than the\\noffset \"".toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, 5); + try { + assertEquals("Wrong token", ITerminalSymbols.TokenNameStringLiteral, scanner.getNextToken()); + assertTrue("Should fail with InvalidInputException", false); + } catch (InvalidInputException e) { + assertEquals("Wrong source", "\"a co\\", new String(scanner.getCurrentTokenSource())); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=294529 + public void test052() { + IScanner scanner = ToolFactory.createScanner( + true, + true, + true, + JavaCore.getOption(JavaCore.COMPILER_SOURCE), + JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); + final char[] source = "\"\\u00E9mment, longer\\n than the\\noffset \"".toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, 5); + try { + assertEquals("Wrong token", ITerminalSymbols.TokenNameStringLiteral, scanner.getNextToken()); + assertTrue("Should fail with InvalidInputException", false); + } catch (InvalidInputException e) { + assertEquals("Wrong source", "\"\\u00E", new String(scanner.getCurrentTokenSource())); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=330081 + @SuppressWarnings("deprecation") // concerns ITerminalSymbols.TokenNameIdentifier + public void test053() { + IScanner scanner = ToolFactory.createScanner( + true, + true, + true, + JavaCore.VERSION_1_4, + JavaCore.VERSION_1_4); + final char[] source = "elnu".toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + assertEquals("Wrong token", ITerminalSymbols.TokenNameIdentifier, scanner.getNextToken()); + } catch (InvalidInputException e) { + 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"); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=352553 + public void test060() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final String ERROR = \"\\u000Ⅻ\";\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static final String ERROR = \"\\u000Ⅻ\";\n" + + " ^^^^^^\n" + + "Invalid unicode\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=387146 + @SuppressWarnings("deprecation") // concerns ITerminalSymbols.TokenNameIdentifier + public void test061() { + IScanner scanner = ToolFactory.createScanner( + true, + true, + true, + JavaCore.VERSION_1_4, + JavaCore.VERSION_1_4); + final char[] source = "case 1:\nsynchronized (someLock){}\n//$FALL-THROUGH$\ncase 2:".toCharArray(); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + assertEquals("Wrong token", ITerminalSymbols.TokenNamecase, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameIntegerLiteral, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameCOLON, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNamesynchronized, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameLPAREN, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameIdentifier, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameRPAREN, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameLBRACE, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameRBRACE, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameCOMMENT_LINE, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNamecase, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameWHITESPACE, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameIntegerLiteral, scanner.getNextToken()); + assertEquals("Wrong token", ITerminalSymbols.TokenNameCOLON, scanner.getNextToken()); + } catch (InvalidInputException e) { + assertTrue("Should not fail with InvalidInputException", false); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383062 + public void test062() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_4); + char[] source = "->".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + int token = 0; + try { + token = scanner.getNextToken(); + } catch (InvalidInputException e) { + // ignore ... + } + assertEquals("Expecting ->", ITerminalSymbols.TokenNameARROW, token); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383062 + public void test063() { + IScanner scanner = ToolFactory.createScanner(false, false, false, JavaCore.VERSION_1_4); + char[] source = "::".toCharArray(); //$NON-NLS-1$ + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + int token = 0; + try { + token = scanner.getNextToken(); + } catch (InvalidInputException e) { + // ignore. + } + assertEquals("Expecting ::", ITerminalSymbols.TokenNameCOLON_COLON, token); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=443854 + public void test064() { + String source = + "public enum X {\n" + + " Hello\\u205fworld;\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Hello\\u205fworld);\n" + + " System.out.println(Character.isJavaIdentifierPart('\\u205f')); // false\n" + + " }\n" + + "}"; + if (this.complianceLevel > ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " Hello\\u205fworld;\n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", , expected\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " System.out.println(Hello\\u205fworld);\n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", invalid AssignmentOperator\n" + + "----------\n"); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=458795 + public void test065() { + String source = + "public class X {\n" + + " double d = 0XP00;\n" + + "}"; + if (this.complianceLevel > ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " double d = 0XP00;\n" + + " ^^^\n" + + "Invalid hex literal number\n" + + "----------\n"); + } + } + public void test066() { + String source = + "public class X {\n" + + " double d = 0X.p02d;\n" + + "}"; + if (this.complianceLevel > ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " double d = 0X.p02d;\n" + + " ^^^\n" + + "Invalid hex literal number\n" + + "----------\n"); + } + } + public void test067() { + String source = + "public class X {\n" + + " float f = 0Xp02f;\n" + + "}"; + if (this.complianceLevel > ClassFileConstants.JDK1_4) { + this.runNegativeTest( + new String[] { + "X.java", + source + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " float f = 0Xp02f;\n" + + " ^^^\n" + + "Invalid hex literal number\n" + + "----------\n"); + } + } + public void test068() { + String source = + "public class X {\n" + + " float f = 0X0p02f;\n" + + "}"; + if (this.complianceLevel > ClassFileConstants.JDK1_4) { + this.runConformTest( + new String[] { + "X.java", + source + }); + } + } + public void testBug531716_001_since_13() { + char[] source = ("class X {\n" + + " String s = \"\"\"This is the new String\"\"\";\n" + + "}").toCharArray(); + Scanner scanner = new Scanner(false, false, false, ClassFileConstants.getLatestJDKLevel(), null, null, false); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + int token; + StringBuffer buffer = new StringBuffer(); + while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { + try { + switch(token) { + case TerminalTokens.TokenNameTextBlock : + buffer.append( new String(scanner.getCurrentTextBlock())); + break; + case TerminalTokens.TokenNameStringLiteral : + break; + case TerminalTokens.TokenNameEOF : + break; + default : + break; + } + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + assertEquals("Wrong contents", "", String.valueOf(buffer)); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + public void testBug531716_001_since_13_1() { + char[] source = ("class X {\n" + + " String s = \"\"\"\nThis is the new String\"\"\";\n" + + "}").toCharArray(); + Scanner scanner = new Scanner(false, false, false, ClassFileConstants.getLatestJDKLevel(), null, null, false); + scanner.previewEnabled = true; + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + int token; + StringBuffer buffer = new StringBuffer(); + while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { + try { + switch(token) { + case TerminalTokens.TokenNameTextBlock : + buffer.append( new String(scanner.getCurrentTextBlock())); + break; + case TerminalTokens.TokenNameStringLiteral : + break; + case TerminalTokens.TokenNameEOF : + break; + default : + break; + } + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + } + } + assertEquals("Wrong contents", "This is the new String", String.valueOf(buffer)); + } catch (InvalidInputException e) { + assertTrue(false); + } + } + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=422760 + */ + public void testBug422760() { + String sourceA001 = "\\u0660"; + IScanner scanner = ToolFactory.createScanner(false, true, false, false); + scanner.setSource(sourceA001.toCharArray()); + int token = 0; + try { + token = scanner.getNextToken(); + } catch (InvalidInputException e) { + assertTrue(false); + } + assertEquals("Wrong token type", ITerminalSymbols.TokenNameIntegerLiteral, token); + } + + public void testBug575556_at_14() { + char[] source= "\"Hello\\sworld\"".toCharArray(); + Scanner scanner = new Scanner(false, false, false, ClassFileConstants.JDK14, null, null, false); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + scanner.getNextToken(); + fail("Should have rejected \\s"); + } catch (InvalidInputException e) { + assertEquals(Scanner.INVALID_ESCAPE, e.getMessage()); + } + } + + public void testBug575556_at_15() { + char[] source= "\"Hello\\sworld\"".toCharArray(); + Scanner scanner = new Scanner(false, false, false, ClassFileConstants.JDK15, null, null, false); + scanner.setSource(source); + scanner.resetTo(0, source.length - 1); + try { + int token = scanner.getNextToken(); + assertEquals(TerminalTokens.TokenNameStringLiteral, token); + assertEquals("Unexpected string literal content", "Hello world", scanner.getCurrentStringLiteral()); + } catch (InvalidInputException e) { + fail("Should have accepted \\s"); + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypesTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypesTests.java new file mode 100644 index 0000000000..ffc9d7e7f5 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypesTests.java @@ -0,0 +1,5725 @@ +/******************************************************************************* + * Copyright (c) 2020, 2021 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +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; +import org.eclipse.jdt.core.util.ClassFormatException; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class SealedTypesTests extends AbstractRegressionTest9 { + + static { +// TESTS_NUMBERS = new int [] { 40 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] { "testBug573450"}; + } + + public static Class testClass() { + return SealedTypesTests.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_17); + } + public SealedTypesTests(String testName){ + super(testName); + } + + // Enables the tests to run individually + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17); + defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17); + defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17); + defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + return defaultOptions; + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput) { + runConformTest(testFiles, expectedOutput, getCompilerOptions()); + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedOutputString = expectedOutput; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.customOptions = customOptions; + runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview("17"); + runner.runConformTest(); + } + @Override + protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) { + runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview("17")); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog) { + runWarningTest(testFiles, expectedCompilerLog, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, Map customOptions) { + runWarningTest(testFiles, expectedCompilerLog, customOptions, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, + Map customOptions, String javacAdditionalTestOptions) { + + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedCompilerLog; + runner.customOptions = customOptions; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forReleaseWithPreview("16") : + JavacTestOptions.forReleaseWithPreview("16", javacAdditionalTestOptions); + runner.runWarningTest(); + } + + private static void verifyClassFile(String expectedOutput, String classFileName, int mode) + throws IOException, ClassFormatException { + File f = new File(OUTPUT_DIR + File.separator + classFileName); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", mode); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + System.out.println("..."); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + + public void testBug563430_001() { + runConformTest( + new String[] { + "X.java", + "sealed class Y permits X{}\n" + + "non-sealed class X extends Y {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n", + }, + "0"); + } + public void testBug563430_001a() { + runConformTest( + new String[] { + "X.java", + "non-sealed class X extends Y {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n", + "Y.java", + "sealed class Y permits X{}\n", + }, + "0"); + } + public void testBug563430_002() { + runConformTest( + new String[] { + "X.java", + "sealed interface I extends SI{}\n"+ + "non-sealed class X implements SI{\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "sealed interface SI permits X, I{}\n" + + "non-sealed interface I2 extends I{}\n" + }, + "0"); + } + public void testBug562715_001() { + runConformTest( + new String[] { + "X.java", + "sealed class X permits Y {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}\n" + + "non-sealed class Y extends X {\n"+ + "}\n" + }, + "100"); + } + public void testBug562715_002() { + runConformTest( + new String[] { + "X.java", + "public sealed class X {\n"+ + " public static void main(String[] args){\n"+ + " int sealed = 100;\n" + + " System.out.println(sealed);\n" + + " }\n"+ + "}\n" + + "non-sealed class Y extends X {\n"+ + "}\n" + }, + "100"); + } + public void testBug562715_003() { + runConformTest( + new String[] { + "X.java", + "sealed public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}\n" + + "non-sealed class Y extends X {\n"+ + "}\n" + }, + "100"); + } + public void testBug562715_004() { + runConformTest( + new String[] { + "X.java", + "sealed interface I {}\n"+ + "sealed public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}\n" + + "non-sealed class Y extends X {\n"+ + "}\n" + + "non-sealed interface I2 extends I {}\n" + }, + "100"); + } + public void testBug562715_004a() { + runConformTest( + new String[] { + "X.java", + "sealed public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}\n" + + "non-sealed class Y extends X {\n"+ + "}\n" + }, + "100"); + } + public void testBug562715_005() { + this.runNegativeTest( + new String[] { + "X.java", + "sealed public sealed class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " sealed public sealed class X {\n" + + " ^\n" + + "Duplicate modifier for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " sealed public sealed class X {\n" + + " ^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares X as its direct superclass or superinterface\n" + + "----------\n"); + } + public void testBug562715_006() { + this.runNegativeTest( + new String[] { + "X.java", + "public sealed class X {\n"+ + " public static sealed void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public sealed class X {\n" + + " ^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares X as its direct superclass or superinterface\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public static sealed void main(String[] args){\n" + + " ^^^^^^\n" + + "Syntax error on token \"sealed\", static expected\n" + + "----------\n"); + } + public void testBug562715_007() { + runConformTest( + new String[] { + "X.java", + "sealed @MyAnnot public class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}\n" + + "@interface MyAnnot {}\n" + + "non-sealed class Y extends X{}" + }, + "100"); + } + public void testBug562715_008() { + runConformTest( + new String[] { + "X.java", + "sealed class X permits Y {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}\n"+ + "sealed class Y extends X {}\n" + + "final class Z extends Y {}\n" + }, + "100"); + } + public void testBug562715_009() { + runConformTest( + new String[] { + "X.java", + "sealed class X permits Y,Z {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}\n"+ + "sealed class Y extends X {}\n" + + "final class Z extends X {}\n" + + "final class Y2 extends Y {}\n" + }, + "100"); + } + public void testBug562715_010() { + this.runNegativeTest( + new String[] { + "X.java", + "public sealed class X permits {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public sealed class X permits {\n" + + " ^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares X as its direct superclass or superinterface\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public sealed class X permits {\n" + + " ^^^^^^^\n" + + "Syntax error on token \"permits\", { expected\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " public sealed class X permits {\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete Block\n" + + "----------\n"); + } + // TODO : Enable after error flag code implemented + public void testBug562715_011() { + this.runNegativeTest( + new String[] { + "X.java", + "sealed enum Natural {ONE, TWO}\n"+ + "public sealed class X {\n"+ + " public static sealed void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " sealed enum Natural {ONE, TWO}\n" + + " ^^^^^^^\n" + + "Illegal modifier for the enum Natural; only public is permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public sealed class X {\n" + + " ^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares X as its direct superclass or superinterface\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " public static sealed void main(String[] args){\n" + + " ^^^^^^\n" + + "Syntax error on token \"sealed\", static expected\n" + + "----------\n"); + } + public void testBug562715_xxx() { + this.runNegativeTest( + new String[] { + "X.java", + "sealed record R() {}\n"+ + "public sealed class X {\n"+ + " public static sealed void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " sealed record R() {}\n" + + " ^\n" + + "Illegal modifier for the record R; only public, final and strictfp are permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public sealed class X {\n" + + " ^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares X as its direct superclass or superinterface\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " public static sealed void main(String[] args){\n" + + " ^^^^^^\n" + + "Syntax error on token \"sealed\", static expected\n" + + "----------\n"); + } + public void testBug563806_001() { + this.runNegativeTest( + new String[] { + "X.java", + "public sealed class X permits Y, Z{\n"+ + "}\n"+ + "class Y {}\n"+ + "class Z {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public sealed class X permits Y, Z{\n" + + " ^\n" + + "Permitted class Y does not declare X as direct super class\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public sealed class X permits Y, Z{\n" + + " ^\n" + + "Permitted class Z does not declare X as direct super class\n" + + "----------\n"); + } + public void testBug563806_002() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits Y{\n"+ + "}\n"+ + "class Y {}\n"+ + "class Z extends X{}", + "p1/A.java", + "package p1;\n"+ + "public sealed class A extends X{}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed class X permits Y{\n" + + " ^\n" + + "Permitted class Y does not declare p1.X as direct super class\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 5)\n" + + " class Z extends X{}\n" + + " ^\n" + + "The class Z with a sealed direct superclass or a sealed direct superinterface X should be declared either final, sealed, or non-sealed\n" + + "----------\n" + + "3. ERROR in p1\\X.java (at line 5)\n" + + " class Z extends X{}\n" + + " ^\n" + + "The type Z extending a sealed class X should be a permitted subtype of X\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p1\\A.java (at line 2)\n" + + " public sealed class A extends X{}\n" + + " ^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares A as its direct superclass or superinterface\n" + + "----------\n" + + "2. ERROR in p1\\A.java (at line 2)\n" + + " public sealed class A extends X{}\n" + + " ^\n" + + "The type A extending a sealed class X should be a permitted subtype of X\n" + + "----------\n"); + } + public void testBug563806_003() { + this.runNegativeTest( + new String[] { + "X.java", + "public sealed interface X permits Y, Z{\n"+ + "}\n"+ + "class Y implements X{}\n"+ + "class Z {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public sealed interface X permits Y, Z{\n" + + " ^\n" + + "Permitted type Z does not declare X as direct super interface \n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " class Y implements X{}\n" + + " ^\n" + + "The class Y with a sealed direct superclass or a sealed direct superinterface X should be declared either final, sealed, or non-sealed\n" + + "----------\n"); + } + public void testBug563806_004() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed interface X permits Y, Z, Q{\n"+ + "}\n"+ + "class Y implements X{}\n" + + "interface Z {}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed interface X permits Y, Z, Q{\n" + + " ^\n" + + "Permitted type Z does not declare p1.X as direct super interface \n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 2)\n" + + " public sealed interface X permits Y, Z, Q{\n" + + " ^\n" + + "Q cannot be resolved to a type\n" + + "----------\n" + + "3. ERROR in p1\\X.java (at line 4)\n" + + " class Y implements X{}\n" + + " ^\n" + + "The class Y with a sealed direct superclass or a sealed direct superinterface X should be declared either final, sealed, or non-sealed\n" + + "----------\n"); + } + public void testBug563806_005() { + this.runNegativeTest( + new String[] { + "X.java", + "public sealed class X permits Y, Y{\n"+ + "}\n"+ + "class Y extends X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public sealed class X permits Y, Y{\n" + + " ^\n" + + "Duplicate type Y for the type X in the permits clause\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " class Y extends X {}\n" + + " ^\n" + + "The class Y with a sealed direct superclass or a sealed direct superinterface X should be declared either final, sealed, or non-sealed\n" + + "----------\n"); + } + public void testBug563806_006() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits Y, p1.Y{\n"+ + "}\n"+ + "class Y extends X {}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed class X permits Y, p1.Y{\n" + + " ^^^^\n" + + "Duplicate type Y for the type X in the permits clause\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 4)\n" + + " class Y extends X {}\n" + + " ^\n" + + "The class Y with a sealed direct superclass or a sealed direct superinterface X should be declared either final, sealed, or non-sealed\n" + + "----------\n"); + } + public void testBug563806_007() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + "}\n"+ + "non-sealed class Y extends X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " non-sealed class Y extends X {}\n" + + " ^\n" + + "A class Y declared as non-sealed should have either a sealed direct superclass or a sealed direct superinterface\n" + + "----------\n"); + } + public void testBug563806_008() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed interface X permits Y {\n"+ + "}\n"+ + "class Y implements X{}\n", + "p2/Y.java", + "package p2;\n"+ + "non-sealed public interface Y {}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " class Y implements X{}\n" + + " ^\n" + + "The class Y with a sealed direct superclass or a sealed direct superinterface X should be declared either final, sealed, or non-sealed\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p2\\Y.java (at line 2)\n" + + " non-sealed public interface Y {}\n" + + " ^\n" + + "An interface Y declared as non-sealed should have a sealed direct superinterface\n" + + "----------\n"); + } + public void testBug563806_009() { + this.runConformTest( + new String[] { + "X.java", + "public sealed class X {\n"+ + " public static void main(String[] args){\n"+ + " System.out.println(100);\n" + + " }\n"+ + "}\n"+ + "final class Y extends X {}", + }, + "100"); + } + public void testBug563806_010() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits Y {\n"+ + "}\n"+ + "final class Y extends X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public final class Y extends p1.X{}", + }, + "----------\n" + + "1. ERROR in p2\\Y.java (at line 2)\n" + + " public final class Y extends p1.X{}\n" + + " ^^^^\n" + + "Sealed type X and sub type Y in an unnamed module should be declared in the same package p1\n" + + "----------\n"); + } + public void testBug563806_011() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) { \n" + + " System.out.println(\"0\");\n" + + " }\n" + + "}\n" + + "sealed interface Y {\n"+ + "}\n"+ + "final class Z implements Y {}", + }, + "0"); + } + public void testBug563806_012() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed interface X permits Y {\n"+ + "}\n"+ + "final class Y implements X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public final class Y implements p1.X{}", + }, + "----------\n" + + "1. ERROR in p2\\Y.java (at line 2)\n" + + " public final class Y implements p1.X{}\n" + + " ^^^^\n" + + "Sealed type X and sub type Y in an unnamed module should be declared in the same package p1\n" + + "----------\n"); + } + public void testBug563806_013() { + this.runNegativeTest( + new String[] { + "X.java", + "public sealed interface X {\n"+ + "}\n"+ + "interface Y extends X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " interface Y extends X {}\n" + + " ^\n" + + "The interface Y with a sealed direct superinterface X should be declared either sealed or non-sealed\n" + + "----------\n"); + } + public void testBug563806_014() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed interface X permits Y {\n"+ + "}\n"+ + "interface Y extends X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public interface Y extends p1.X{}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " interface Y extends X{}\n" + + " ^\n" + + "The interface Y with a sealed direct superinterface X should be declared either sealed or non-sealed\n" + + "----------\n" + + "----------\n" + + "1. ERROR in p2\\Y.java (at line 2)\n" + + " public interface Y extends p1.X{}\n" + + " ^\n" + + "The interface Y with a sealed direct superinterface X should be declared either sealed or non-sealed\n" + + "----------\n" + + "2. ERROR in p2\\Y.java (at line 2)\n" + + " public interface Y extends p1.X{}\n" + + " ^^^^\n" + + "Sealed type X and sub type Y in an unnamed module should be declared in the same package p1\n" + + "----------\n"); + } + public void testBug563806_015() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X permits Y{\n"+ + "}\n"+ + "final class Y extends X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X permits Y{\n" + + " ^\n" + + "A type declaration X that has a permits clause should have a sealed modifier\n" + + "----------\n"); + } + public void testBug563806_016() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public class X permits Y {\n"+ + "}\n"+ + "final class Y extends X{}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public class X permits Y {\n" + + " ^\n" + + "A type declaration X that has a permits clause should have a sealed modifier\n" + + "----------\n"); + } + public void testBug563806_017() { + this.runNegativeTest( + new String[] { + "X.java", + "public interface X permits Y{\n"+ + "}\n"+ + "final class Y implements X {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public interface X permits Y{\n" + + " ^\n" + + "A type declaration X that has a permits clause should have a sealed modifier\n" + + "----------\n"); + } + public void testBug563806_018() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public interface X permits Y {\n"+ + "}\n"+ + "final class Y implements X{}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public interface X permits Y {\n" + + " ^\n" + + "A type declaration X that has a permits clause should have a sealed modifier\n" + + "----------\n"); + } + public void testBug563806_019() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits Y, p2.Y {\n"+ + "}\n"+ + "final class Y extends X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public final class Y extends p1.X{}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed class X permits Y, p2.Y {\n" + + " ^^^^\n" + + "Permitted type Y in an unnamed module should be declared in the same package p1 of declaring type X\n" + + "----------\n"); + } + public void testBug563806_020() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed interface X permits Y, p2.Y {\n"+ + "}\n"+ + "final class Y implements X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public final class Y implements p1.X{}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed interface X permits Y, p2.Y {\n" + + " ^^^^\n" + + "Permitted type Y in an unnamed module should be declared in the same package p1 of declaring type X\n" + + "----------\n"); + } + public void testBug563806_021() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed interface X permits Y, p2.Y {\n"+ + "}\n"+ + "non-sealed interface Y extends X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public non-sealed interface Y extends p1.X{}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed interface X permits Y, p2.Y {\n" + + " ^^^^\n" + + "Permitted type Y in an unnamed module should be declared in the same package p1 of declaring type X\n" + + "----------\n"); + } + public void testBug563806_022() { + associateToModule("mod.one", "p1/X.java"); + associateToModule("mod.two", "p2/Y.java"); + Runner runner = new Runner(); + runner.testFiles = new String[] { + "mod.one/module-info.java", + "module mod.one {\n"+ + "requires mod.two;\n"+ + "}\n", + "mod.two/module-info.java", + "module mod.two {\n" + + "exports p2;\n"+ + "}\n", + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits Y, p2.Y {\n"+ + "}\n"+ + "final class Y extends X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public final class Y {}", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed class X permits Y, p2.Y {\n" + + " ^^^^\n" + + "Permitted type Y in a named module mod.one should be declared in the same module mod.one of declaring type X\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 2)\n" + + " public sealed class X permits Y, p2.Y {\n" + + " ^^^^\n" + + "Permitted class Y does not declare p1.X as direct super class\n" + + "----------\n"; + runner.runNegativeTest(); + } + public void testBug563806_023() { + associateToModule("mod.one", "p1/X.java"); + associateToModule("mod.two", "p2/Y.java"); + Runner runner = new Runner(); + runner.testFiles = new String[] { + "mod.one/module-info.java", + "module mod.one {\n"+ + "requires mod.two;\n"+ + "}\n", + "mod.two/module-info.java", + "module mod.two {\n" + + "exports p2;\n"+ + "}\n", + "p1/X.java", + "package p1;\n"+ + "public sealed interface X permits Y, p2.Y {\n"+ + "}\n"+ + "final class Y implements X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public final class Y {}", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed interface X permits Y, p2.Y {\n" + + " ^^^^\n" + + "Permitted type Y in a named module mod.one should be declared in the same module mod.one of declaring type X\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 2)\n" + + " public sealed interface X permits Y, p2.Y {\n" + + " ^^^^\n" + + "Permitted type Y does not declare p1.X as direct super interface \n" + + "----------\n"; + runner.runNegativeTest(); + } + public void testBug563806_024() { + associateToModule("mod.one", "p1/X.java"); + associateToModule("mod.two", "p2/Y.java"); + Runner runner = new Runner(); + runner.testFiles = new String[] { + "mod.one/module-info.java", + "module mod.one {\n"+ + "requires mod.two;\n"+ + "}\n", + "mod.two/module-info.java", + "module mod.two {\n" + + "exports p2;\n"+ + "}\n", + "p1/X.java", + "package p1;\n"+ + "public sealed interface X permits Y, p2.Y {\n"+ + "}\n"+ + "non-sealed interface Y extends X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public interface Y {}", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed interface X permits Y, p2.Y {\n" + + " ^^^^\n" + + "Permitted type Y in a named module mod.one should be declared in the same module mod.one of declaring type X\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 2)\n" + + " public sealed interface X permits Y, p2.Y {\n" + + " ^^^^\n" + + "Permitted type Y does not declare p1.X as direct super interface \n" + + "----------\n"; + runner.runNegativeTest(); + } + public void testBug563806_025() { + associateToModule("mod.one", "p1/X.java"); + associateToModule("mod.one", "p2/Y.java"); + Runner runner = new Runner(); + runner.testFiles = new String[] { + "mod.one/module-info.java", + "module mod.one {\n"+ + "}\n", + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits Y, p2.Y {\n"+ + "}\n"+ + "final class Y extends X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public final class Y extends p1.X{}", + }; + runner.runConformTest(); + } + public void testBug563806_026() { + associateToModule("mod.one", "p1/X.java", "p2/Y.java"); + Runner runner = new Runner(); + runner.testFiles = new String[] { + "mod.one/module-info.java", + "module mod.one {\n"+ + "}\n", + "p1/X.java", + "package p1;\n"+ + "public sealed interface X permits Y, p2.Y {\n"+ + "}\n"+ + "final class Y implements X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public final class Y implements p1.X{}", + }; + runner.runConformTest(); + } + public void testBug563806_027() { + associateToModule("mod.one", "p1/X.java"); + associateToModule("mod.one", "p2/Y.java"); + Runner runner = new Runner(); + runner.testFiles = new String[] { + "mod.one/module-info.java", + "module mod.one {\n"+ + "}\n", + "p1/X.java", + "package p1;\n"+ + "public sealed interface X permits Y, p2.Y {\n"+ + "}\n"+ + "non-sealed interface Y extends X{}\n", + "p2/Y.java", + "package p2;\n"+ + "public non-sealed interface Y extends p1.X {}", + }; + runner.runConformTest(); + } + public void testBug563806_028() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public non-sealed enum X {\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public non-sealed enum X {\n" + + " ^\n" + + "Illegal modifier for the enum X; only public is permitted\n" + + "----------\n"); + } + public void testBug563806_029() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed enum X {\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed enum X {\n" + + " ^\n" + + "Illegal modifier for the enum X; only public is permitted\n" + + "----------\n"); + } + public void testBug563806_030() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public class X {\n"+ + "static sealed enum Y {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 3)\n" + + " static sealed enum Y {}\n" + + " ^\n" + + "Illegal modifier for the member enum Y; only public, protected, private & static are permitted\n" + + "----------\n"); + } + public void testBug563806_031() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public class X {\n"+ + "static non-sealed enum Y {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 3)\n" + + " static non-sealed enum Y {}\n" + + " ^\n" + + "Illegal modifier for the member enum Y; only public, protected, private & static are permitted\n" + + "----------\n"); + } + public void testBug563806_032() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed non-sealed interface X {\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed non-sealed interface X {\n" + + " ^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares X as its direct superclass or superinterface\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 2)\n" + + " public sealed non-sealed interface X {\n" + + " ^\n" + + "An interface X is declared both sealed and non-sealed\n" + + "----------\n"); + } + public void testBug563806_033() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed @interface X {\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public sealed @interface X {\n" + + " ^^^^^^\n" + + "Syntax error on token \"sealed\", static expected\n" + + "----------\n"); + } + public void testBug563806_034() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public non-sealed @interface X {\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public non-sealed @interface X {\n" + + " ^\n" + + "An interface X declared as non-sealed should have a sealed direct superinterface\n" + + "----------\n"); + } + public void testBug563806_035() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public non-sealed interface X {\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " public non-sealed interface X {\n" + + " ^\n" + + "An interface X declared as non-sealed should have a sealed direct superinterface\n" + + "----------\n"); + } + public void testBug563806_036() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public class X {\n"+ + " public void foo() {\n"+ + " sealed class Y{}\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " sealed class Y{}\n" + + " ^\n" + + "Illegal modifier for the local class Y; only abstract or final is permitted\n" + + "----------\n"); + } + public void testBug563806_037() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public class X {\n"+ + " public void foo() {\n"+ + " non-sealed class Y{}\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " non-sealed class Y{}\n" + + " ^\n" + + "Illegal modifier for the local class Y; only abstract or final is permitted\n" + + "----------\n"); + } + public void testBug563806_038() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public class X {\n"+ + " public void foo() {\n"+ + " non-sealed sealed class Y{}\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " non-sealed sealed class Y{}\n" + + " ^\n" + + "Illegal modifier for the local class Y; only abstract or final is permitted\n" + + "----------\n"); + } + public void testBug563806_039() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "sealed class A{}\n"+ + "public class X {\n"+ + " public void foo() {\n"+ + " class Y extends A{}\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " sealed class A{}\n" + + " ^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares A as its direct superclass or superinterface\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 5)\n" + + " class Y extends A{}\n" + + " ^\n" + + "A local class Y cannot have a sealed direct superclass or a sealed direct superinterface A\n" + + "----------\n"); + } + public void testBug564191_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "sealed class X permits Y, Z{\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "final class Y extends X{}\n" + + "final class Z extends X{}\n", + }, + "0"); + String expectedOutput = + "PermittedSubclasses:\n" + + " #33 p1/Y,\n" + + " #35 p1/Z\n" + + "}"; + verifyClassFile(expectedOutput, "p1/X.class", ClassFileBytesDisassembler.SYSTEM); + } + // Test that implicit permitted (top-level) types make it to the .class file + public void testBug564190_1() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "sealed class X {\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "final class Y extends X{}\n" + + "final class Z extends X{}\n", + }, + "0"); + String expectedOutput = + "PermittedSubclasses:\n" + + " #33 p1/Y,\n" + + " #35 p1/Z\n" + + "}"; + verifyClassFile(expectedOutput, "p1/X.class", ClassFileBytesDisassembler.SYSTEM); + } + // Test that implicit permitted final (member) types make it to the .class file + public void testBug564190_2() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "sealed class X {\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + " final class Y extends X{}\n" + + " final class Z extends X{}\n" + + "}", + }, + "0"); + String expectedOutput = + "PermittedSubclasses:\n" + + " #33 p1/X$Y,\n" + + " #35 p1/X$Z\n" + + "}"; + verifyClassFile(expectedOutput, "p1/X.class", ClassFileBytesDisassembler.SYSTEM); + } + // Test that implicit permitted non-sealed (member) types make it to the .class file + public void testBug564190_3() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "sealed class X {\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + " non-sealed class Y extends X{}\n" + + " non-sealed class Z extends X{}\n" + + "}", + }, + "0"); + String expectedOutput = + "PermittedSubclasses:\n" + + " #33 p1/X$Y,\n" + + " #35 p1/X$Z\n" + + "}"; + verifyClassFile(expectedOutput, "p1/X.class", ClassFileBytesDisassembler.SYSTEM); + } + // Test that implicit permitted member type is reported without final, sealed or non-sealed + public void testBug564190_4() throws IOException, ClassFormatException { + runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "sealed class X {\n" + + " class Y extends X {}\n" + + " final class Z extends Y {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 3)\n" + + " class Y extends X {}\n" + + " ^\n" + + "The class Y with a sealed direct superclass or a sealed direct superinterface X should be declared either final, sealed, or non-sealed\n" + + "----------\n"); + } + // Test that implicit permitted member type with implicit permitted types + // is reported when its permitted type doesn't extend the member type + public void testBug564190_5() throws IOException, ClassFormatException { + runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "sealed class X {\n" + + " sealed class Y extends X {}\n" + + " final class Z {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 3)\n" + + " sealed class Y extends X {}\n" + + " ^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares Y as its direct superclass or superinterface\n" + + "----------\n"); + } + // Test that implicit permitted member type with explicit permits clause + // is reported when its permitted type doesn't extend the member type + public void testBug564190_6() throws IOException, ClassFormatException { + runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "sealed class X {\n" + + " sealed class Y extends X permits Z {}\n" + + " final class Z {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 3)\n" + + " sealed class Y extends X permits Z {}\n" + + " ^\n" + + "Permitted class Z does not declare p1.X.Y as direct super class\n" + + "----------\n"); + } + // Test that implicit permitted member type with explicit permits clause + // is reported when its permitted type doesn't extend the member type + public void testBug564190_7() throws IOException, ClassFormatException { + runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "sealed interface SI {}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 2)\n" + + " sealed interface SI {}\n" + + " ^^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares SI as its direct superclass or superinterface\n" + + "----------\n"); + } + public void testBug564450_001() throws IOException, ClassFormatException { + runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "sealed class X permits Y{\n" + + "}", + "p1/Y.java", + "package p1;\n"+ + "class Y extends X {\n" + + "}", + }, + "----------\n" + + "1. ERROR in p1\\Y.java (at line 2)\n" + + " class Y extends X {\n" + + " ^\n" + + "The class Y with a sealed direct superclass or a sealed direct superinterface X should be declared either final, sealed, or non-sealed\n" + + "----------\n"); + } + public void testBug564047_001() throws CoreException, IOException { + String outputDirectory = Util.getOutputDirectory(); + String lib1Path = outputDirectory + File.separator + "lib1.jar"; + try { + Util.createJar( + new String[] { + "p/Y.java", + "package p;\n" + + "public sealed class Y permits Z{}", + "p/Z.java", + "package p;\n" + + "public final class Z extends Y{}", + }, + lib1Path, + JavaCore.VERSION_17, + true); + String[] libs = getDefaultClassPaths(); + int len = libs.length; + System.arraycopy(libs, 0, libs = new String[len+1], 0, len); + libs[len] = lib1Path; + this.runNegativeTest( + new String[] { + "src/p/X.java", + "package p;\n" + + "public class X extends Y {\n" + + " public static void main(String[] args){\n" + + " System.out.println(0);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in src\\p\\X.java (at line 2)\n" + + " public class X extends Y {\n" + + " ^\n" + + "The class X with a sealed direct superclass or a sealed direct superinterface Y should be declared either final, sealed, or non-sealed\n" + + "----------\n" + + "2. ERROR in src\\p\\X.java (at line 2)\n" + + " public class X extends Y {\n" + + " ^\n" + + "The type X extending a sealed class Y should be a permitted subtype of Y\n" + + "----------\n", + libs, + true); + } catch (IOException e) { + System.err.println("could not write to current working directory "); + } finally { + new File(lib1Path).delete(); + } + + } + public void testBug564492_001() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args){\n"+ + " new Y(){};\n" + + " }\n"+ + "}\n"+ + "sealed class Y{}\n"+ + "final class Z extends Y {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new Y(){};\n" + + " ^\n" + + "An anonymous class cannot subclass a sealed type Y\n" + + "----------\n"); + } + public void testBug564492_002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " IY y = new IY(){};\n"+ + " }\n"+ + "}\n"+ + "sealed interface I {}\n"+ + "sealed interface IY extends I {}\n"+ + "final class Z implements IY{}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " IY y = new IY(){};\n" + + " ^^\n" + + "An anonymous class cannot subclass a sealed type IY\n" + + "----------\n"); + } + public void testBug564492_003() { + this.runNegativeTest( + new String[] { + "X.java", + "public sealed class X permits A.Y {\n"+ + " public static void main(String[] args) {\n"+ + " new A.Y() {};\n"+ + " }\n"+ + "}\n"+ + " \n"+ + "class A {\n"+ + " static sealed class Y extends X permits Z {}\n"+ + " final class Z extends Y{}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new A.Y() {};\n" + + " ^^^\n" + + "An anonymous class cannot subclass a sealed type A.Y\n" + + "----------\n"); + } + public void testBug564492_004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new A.IY() {};\n"+ + " }\n"+ + "}\n"+ + " \n"+ + "class A {\n"+ + " sealed interface I permits IY{}\n"+ + " sealed interface IY extends I permits Z {}\n"+ + " final class Z implements IY{}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new A.IY() {};\n" + + " ^^^^\n" + + "An anonymous class cannot subclass a sealed type A.IY\n" + + "----------\n"); + } + public void testBug564498_1() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits A.Y {\n" + + " public static void main(String[] args) {}\n" + + "}\n" + + "class A {\n" + + " sealed class Y extends X {\n" + + " final class SubInnerY extends Y {}\n" + + " } \n" + + " final class Z extends Y {}\n" + + "}", + }, + ""); + String expectedOutput = + "PermittedSubclasses:\n" + + " #24 p1/A$Y$SubInnerY,\n" + + " #26 p1/A$Z\n" + + "}"; + verifyClassFile(expectedOutput, "p1/A$Y.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "PermittedSubclasses:\n" + + " #21 p1/A$Y\n"; + verifyClassFile(expectedOutput, "p1/X.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug564498_2() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits A.Y {\n" + + " public static void main(String[] args) {}\n" + + "}\n" + + "class A {\n" + + " sealed class Y extends X {} \n" + + " final class Z extends Y {}\n" + + " final class SubY extends Y {}" + + "}", + }, + ""); + String expectedOutput = + "PermittedSubclasses:\n" + + " #22 p1/A$Z,\n" + + " #24 p1/A$SubY\n" + + "}"; + verifyClassFile(expectedOutput, "p1/A$Y.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + "PermittedSubclasses:\n" + + " #21 p1/A$Y\n"; + verifyClassFile(expectedOutput, "p1/X.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug564498_3() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits A.Y {\n" + + " public static void main(String[] args) {}\n" + + "}\n" + + "class A {\n" + + " sealed class Y extends X {\n" + + " final class SubInnerY extends Y {}\n" + + " } \n" + + " final class Z extends Y {}\n" + + " final class SubY extends Y {}" + + "}", + }, + ""); + String expectedOutput = + "PermittedSubclasses:\n" + + " #24 p1/A$Y$SubInnerY,\n" + + " #26 p1/A$Z,\n" + + " #28 p1/A$SubY\n"; + verifyClassFile(expectedOutput, "p1/A$Y.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug564498_4() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits A.Y {\n" + + " public static void main(String[] args) {}\n" + + "}\n" + + "class A {\n" + + " sealed class Y extends X permits Y.SubInnerY {\n" + + " final class SubInnerY extends Y {}\n" + + " } \n" + + "}", + }, + ""); + String expectedOutput = + "PermittedSubclasses:\n" + + " #24 p1/A$Y$SubInnerY\n"; + verifyClassFile(expectedOutput, "p1/A$Y.class", ClassFileBytesDisassembler.SYSTEM); + } + // Reject references of membertype without qualifier of enclosing type in permits clause + public void testBug564498_5() throws IOException, ClassFormatException { + runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "public sealed class X permits A.Y {\n" + + " public static void main(String[] args) {}\n" + + "}\n" + + "class A {\n" + + " sealed class Y extends X permits SubInnerY {\n" + + " final class SubInnerY extends Y {}\n" + + " } \n" + + "}", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 6)\n" + + " sealed class Y extends X permits SubInnerY {\n" + + " ^^^^^^^^^\n" + + "SubInnerY cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in p1\\X.java (at line 7)\n" + + " final class SubInnerY extends Y {}\n" + + " ^\n" + + "The type SubInnerY extending a sealed class A.Y should be a permitted subtype of A.Y\n" + + "----------\n"); + } + // accept references of membertype without qualifier of enclosing type in permits clause + // provided it is imported + public void testBug564498_6() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "p1/X.java", + "package p1;\n"+ + "import p1.Y.Z;\n" + + "public class X {\n" + + " public static void main(String[] args) {}\n" + + "}\n" + + "sealed class Y permits Z {\n" + + " final class Z extends Y {}\n" + + "}", + }, + ""); + } + public void testBug564613_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " public boolean permits( String s ) {\n"+ + " return true;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " boolean b = new X().permits(\"hello\");\n"+ + " System.out.println(b ? \"Hello\" : \"World\");\n"+ + " }\n"+ + "}", + }, + "Hello"); + } + public void testBug564613_002() { + runNegativeTest( + new String[] { + "X.java", + "public sealed class X permits permits Y, Z {}\n"+ + "final class Y extends X{}\n" + + "final class Z extends X{}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public sealed class X permits permits Y, Z {}\n" + + " ^^^^^^^\n" + + "Syntax error on token \"permits\", delete this token\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_001() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class permits {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type permits\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_002() { + runNegativeTest( + new String[] { + "X.java", + "class permits {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type permits\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_003() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " permits p;\n" + + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + "permits.java", + "public class permits {\n"+ + "}", + }, + "----------\n" + + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " permits p;\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "----------\n" + + "1. ERROR in permits.java (at line 1)\n" + + " public class permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_004() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " permits p;\n" + + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + "permits.java", + "public class permits {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " permits p;\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "----------\n" + + "1. ERROR in permits.java (at line 1)\n" + + " public class permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_005() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_006() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug564638_007() { + runNegativeTest( + new String[] { + "X.java", + "class X extends permits {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "class permits {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " class permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_008() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X extends permits {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "class permits {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " class permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_009() { + runNegativeTest( + new String[] { + "X.java", + "class X implements permits {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "interface permits {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X implements permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " interface permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_010() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X implements permits {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "interface permits {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X implements permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " interface permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_011() { + runNegativeTest( + new String[] { + "X.java", + "interface X extends permits {\n"+ + " default void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "interface permits {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface X extends permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " interface permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_012() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "interface X extends permits {\n"+ + " default void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "interface permits {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface X extends permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " interface permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_013() { + runNegativeTest( + new String[] { + "X.java", + "class X extends {\n"+ + " permits foo() {\n" + + " Zork();\n" + + " return null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends {\n" + + " ^^^^^^^\n" + + "Syntax error on token \"extends\", Type expected after this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " permits foo() {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_014() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " permits foo() {\n" + + " Zork();\n" + + " return null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " permits foo() {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_015() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() throws permits{\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo() throws permits{\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_016() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() throws permits{\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo() throws permits{\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_017() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo(T extends permits) {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "3. WARNING in X.java (at line 2)\n" + + " void foo(T extends permits) {\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "4. ERROR in X.java (at line 2)\n" + + " void foo(T extends permits) {\n" + + " ^^^^^^^\n" + + "Syntax error on token \"extends\", delete this token\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_018() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo(T extends permits) {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "4. WARNING in X.java (at line 2)\n" + + " void foo(T extends permits) {\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "5. ERROR in X.java (at line 2)\n" + + " void foo(T extends permits) {\n" + + " ^^^^^^^\n" + + "Syntax error on token \"extends\", delete this token\n" + + "----------\n" + + "6. ERROR in X.java (at line 5)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_019() { + runNegativeTest( + new String[] { + "X.java", + "enum X {\n"+ + " ONE(1);\n" + + " private final permits p;\n" + + " X(int p) {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private final permits p;\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_020() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "enum X {\n"+ + " ONE(1);\n" + + " private final permits p;\n" + + " X(int p) {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private final permits p;\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_021() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " I i = (permits p)-> {};\n" + +// " Zork();\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void apply(Object o);\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I i = (permits p)-> {};\n" + + " ^^^^^^^^^^^^^\n" + + "This lambda expression refers to the missing type permits\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I i = (permits p)-> {};\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_022() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " I i = (permits p)-> {};\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void apply(Object o);\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I i = (permits p)-> {};\n" + + " ^^^^^^^^^^^^^\n" + + "This lambda expression refers to the missing type permits\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I i = (permits p)-> {};\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_023() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(permits this) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(permits this) {}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_024() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(permits this) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(permits this) {}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_025() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(permits this) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(permits this) {}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_026() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(permits this) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(permits this) {}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_027() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " class permits {\n"+ + " public void foo(permits this) {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public void foo(permits this) {}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_028() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " class permits {\n"+ + " public void foo(permits this) {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public void foo(permits this) {}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_029() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " permits p;\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " permits p;\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_030() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " permits p;\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " permits p;\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_031() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " for (permits i = 0; i < 10; ++i) {} \n" + + " }\n" + + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (permits i = 0; i < 10; ++i) {} \n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_032() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " for (permits i = 0; i < 10; ++i) {} \n" + + " }\n" + + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (permits i = 0; i < 10; ++i) {} \n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_033() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(permits[] args) {\n" + + " for (permits p : args) {} \n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static void main(permits[] args) {\n" + + " ^^^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " for (permits p : args) {} \n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_034() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(permits[] args) {\n" + + " for (permits p : args) {} \n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static void main(permits[] args) {\n" + + " ^^^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " for (permits p : args) {} \n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_035() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " try (permits y = new Y()) {\n"+ + " \n"+ + " } catch (Exception e) {\n"+ + " e.printStackTrace();\n"+ + " } finally {\n"+ + " \n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (permits y = new Y()) {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_036() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " try (permits y = new Y()) {\n"+ + " \n"+ + " } catch (Exception e) {\n"+ + " e.printStackTrace();\n"+ + " } finally {\n"+ + " \n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (permits y = new Y()) {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_037() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " try (Y y = new Y()) {\n"+ + " \n"+ + " } catch (permits e) {\n"+ + " e.printStackTrace();\n"+ + " } finally {\n"+ + " \n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " } catch (permits e) {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_038() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " try (Y y = new Y()) {\n"+ + " \n"+ + " } catch (permits e) {\n"+ + " e.printStackTrace();\n"+ + " } finally {\n"+ + " \n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " } catch (permits e) {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_039() { + runNegativeTest( + new String[] { + "X.java", + "record X(permits p) {\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record X(permits p) {\n" + + " ^\n" + + "permits cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " record X(permits p) {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_040() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "record X(permits p) {\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record X(permits p) {\n" + + " ^\n" + + "permits cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " record X(permits p) {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 17\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_041() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X(T t) {}\n"+ + " \n"+ + " public X(int t, char c) {\n"+ + " this(t);\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " this(t);\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " this(t);\n" + + " ^^^^^^^^\n" + + "The parameterized constructor X(permits) of type X is not applicable for the arguments (Integer)\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_042() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X(T t) {}\n"+ + " \n"+ + " public X(int t, char c) {\n"+ + " this(t);\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " this(t);\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " this(t);\n" + + " ^^^^^^^^\n" + + "The parameterized constructor X(permits) of type X is not applicable for the arguments (Integer)\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_043() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X(T t) {}\n"+ + " \n"+ + " public X(int t, char c) {\n"+ + " new X(t).foo();\n"+ + " }\n"+ + " public void foo() {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new X(t).foo();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The parameterized constructor X(permits) of type X is not applicable for the arguments (Integer)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " new X(t).foo();\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_044() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X(T t) {}\n"+ + " \n"+ + " public X(int t, char c) {\n"+ + " new X(t).foo();\n"+ + " }\n"+ + " public void foo() {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new X(t).foo();\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The parameterized constructor X(permits) of type X is not applicable for the arguments (Integer)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " new X(t).foo();\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_045() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(T t) {}\n"+ + " \n"+ + " public X() {\n"+ + " X x = new X();\n"+ + " x.foo(0);\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x.foo(0);\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " x.foo(0);\n" + + " ^^^\n" + + "The parameterized method foo(permits) of type X is not applicable for the arguments (Integer)\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_046() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(T t) {}\n"+ + " \n"+ + " public X() {\n"+ + " X x = new X();\n"+ + " x.foo(0);\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x.foo(0);\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " x.foo(0);\n" + + " ^^^\n" + + "The parameterized method foo(permits) of type X is not applicable for the arguments (Integer)\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_047() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(T t) {}\n"+ + " \n"+ + " public X() {\n"+ + " X x = new permits();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X x = new permits();\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_048() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(T t) {}\n"+ + " \n"+ + " public X() {\n"+ + " X x = new permits();\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X x = new permits();\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_049() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X() {\n"+ + " new permits() {\n"+ + " @Override\n"+ + " void foo() {}\n"+ + " }.foo();\n"+ + " }\n"+ + "}\n"+ + "abstract class permits {\n"+ + " abstract void foo();\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new permits() {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " abstract class permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_050() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X() {\n"+ + " new permits() {\n"+ + " @Override\n"+ + " void foo() {\n"+ + " Zork();\n"+ + " }\n"+ + " }.foo();\n"+ + " }\n"+ + "}\n"+ + "abstract class permits {\n"+ + " abstract void foo();\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new permits() {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type new permits(){}\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " abstract class permits {\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_051() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X() {\n"+ + " Object[] p = new permits[10];\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object[] p = new permits[10];\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_052() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X() {\n"+ + " Object[] p = new permits[10];\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object[] p = new permits[10];\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_053() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo((permits) null);\n"+ + " }\n"+ + " private void foo(permits o) {}\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X().foo((permits) null);\n" + + " ^^^\n" + + "The method foo(permits) from the type X refers to the missing type permits\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " new X().foo((permits) null);\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " private void foo(permits o) {}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_054() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo((permits) null);\n"+ + " }\n"+ + " private void foo(permits o) {}\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X().foo((permits) null);\n" + + " ^^^\n" + + "The method foo(permits) from the type X refers to the missing type permits\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " new X().foo((permits) null);\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " private void foo(permits o) {}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_055() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " private void foo(Object o) {\n"+ + " if (o instanceof permits) {}\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (o instanceof permits) {}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_056() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " private void foo(Object o) {\n"+ + " if (o instanceof permits) {}\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (o instanceof permits) {}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638_057() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " @SuppressWarnings(\"unused\")\n"+ + " I i = permits :: new;\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class permits{}\n" + + "interface I {\n"+ + " Object gen();\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " class permits{}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638_058() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " @SuppressWarnings(\"unused\")\n"+ + " I i = permits :: new;\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class permits{}\n" + + "interface I {\n"+ + " Object gen();\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " class permits{}\n" + + " ^^^^^^^\n" + + "\'permits\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_001() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class sealed {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type sealed\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_002() { + runNegativeTest( + new String[] { + "X.java", + "class sealed {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type sealed\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_003() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " sealed p;\n" + + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + "sealed.java", + "public class sealed {\n"+ + "}", + }, + "----------\n" + + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " sealed p;\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "----------\n" + + "1. ERROR in sealed.java (at line 1)\n" + + " public class sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_004() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " sealed p;\n" + + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + "sealed.java", + "public class sealed {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " sealed p;\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "----------\n" + + "1. ERROR in sealed.java (at line 1)\n" + + " public class sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_005() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_006() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug564638b_007() { + runNegativeTest( + new String[] { + "X.java", + "class X extends sealed {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "class sealed {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " class sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_008() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X extends sealed {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "class sealed {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " class sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_009() { + runNegativeTest( + new String[] { + "X.java", + "class X implements sealed {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "interface sealed {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X implements sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " interface sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_010() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X implements sealed {\n"+ + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "interface sealed {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X implements sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " interface sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_011() { + runNegativeTest( + new String[] { + "X.java", + "interface X extends sealed {\n"+ + " default void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "interface sealed {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface X extends sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " interface sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_012() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "interface X extends sealed {\n"+ + " default void foo() {\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "interface sealed {\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " interface X extends sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " interface sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_013() { + runNegativeTest( + new String[] { + "X.java", + "class X extends {\n"+ + " sealed foo() {\n" + + " Zork();\n" + + " return null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X extends {\n" + + " ^^^^^^^\n" + + "Syntax error on token \"extends\", Type expected after this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " sealed foo() {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_014() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " sealed foo() {\n" + + " Zork();\n" + + " return null;\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " sealed foo() {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_015() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() throws sealed{\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo() throws sealed{\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_016() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo() throws sealed{\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo() throws sealed{\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_017() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo(T extends sealed) {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "3. WARNING in X.java (at line 2)\n" + + " void foo(T extends sealed) {\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "4. ERROR in X.java (at line 2)\n" + + " void foo(T extends sealed) {\n" + + " ^^^^^^^\n" + + "Syntax error on token \"extends\", delete this token\n" + + "----------\n" + + "5. ERROR in X.java (at line 5)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_018() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " void foo(T extends sealed) {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 1)\n" + + " class X {\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n" + + "4. WARNING in X.java (at line 2)\n" + + " void foo(T extends sealed) {\n" + + " ^\n" + + "The type parameter T is hiding the type T\n" + + "----------\n" + + "5. ERROR in X.java (at line 2)\n" + + " void foo(T extends sealed) {\n" + + " ^^^^^^^\n" + + "Syntax error on token \"extends\", delete this token\n" + + "----------\n" + + "6. ERROR in X.java (at line 5)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_019() { + runNegativeTest( + new String[] { + "X.java", + "enum X {\n"+ + " ONE(1);\n" + + " private final sealed p;\n" + + " X(int p) {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private final sealed p;\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_020() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "enum X {\n"+ + " ONE(1);\n" + + " private final sealed p;\n" + + " X(int p) {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " private final sealed p;\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_021() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " I i = (sealed p)-> {};\n" + +// " Zork();\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void apply(Object o);\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I i = (sealed p)-> {};\n" + + " ^^^^^^^^^^^^\n" + + "This lambda expression refers to the missing type sealed\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I i = (sealed p)-> {};\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_022() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " I i = (sealed p)-> {};\n" + + " Zork();\n" + + " }\n" + + "}\n" + + "interface I {\n" + + " void apply(Object o);\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " I i = (sealed p)-> {};\n" + + " ^^^^^^^^^^^^\n" + + "This lambda expression refers to the missing type sealed\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " I i = (sealed p)-> {};\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_023() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(sealed this) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(sealed this) {}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_024() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(sealed this) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(sealed this) {}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_025() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(sealed this) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(sealed this) {}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_026() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(sealed this) {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public void foo(sealed this) {}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_027() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " class sealed {\n"+ + " public void foo(sealed this) {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public void foo(sealed this) {}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_028() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " class sealed {\n"+ + " public void foo(sealed this) {}\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " public void foo(sealed this) {}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_029() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " sealed p;\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " sealed p;\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_030() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " sealed p;\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " sealed p;\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_031() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " for (sealed i = 0; i < 10; ++i) {} \n" + + " }\n" + + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (sealed i = 0; i < 10; ++i) {} \n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_032() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n" + + " for (sealed i = 0; i < 10; ++i) {} \n" + + " }\n" + + " void foo() {\n" + + " Zork();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " for (sealed i = 0; i < 10; ++i) {} \n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_033() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(sealed[] args) {\n" + + " for (sealed p : args) {} \n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static void main(sealed[] args) {\n" + + " ^^^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " for (sealed p : args) {} \n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_034() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(sealed[] args) {\n" + + " for (sealed p : args) {} \n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static void main(sealed[] args) {\n" + + " ^^^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " for (sealed p : args) {} \n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_035() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " try (sealed y = new Y()) {\n"+ + " \n"+ + " } catch (Exception e) {\n"+ + " e.printStackTrace();\n"+ + " } finally {\n"+ + " \n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (sealed y = new Y()) {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_036() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " try (sealed y = new Y()) {\n"+ + " \n"+ + " } catch (Exception e) {\n"+ + " e.printStackTrace();\n"+ + " } finally {\n"+ + " \n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " try (sealed y = new Y()) {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_037() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " try (Y y = new Y()) {\n"+ + " \n"+ + " } catch (sealed e) {\n"+ + " e.printStackTrace();\n"+ + " } finally {\n"+ + " \n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " } catch (sealed e) {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_038() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " try (Y y = new Y()) {\n"+ + " \n"+ + " } catch (sealed e) {\n"+ + " e.printStackTrace();\n"+ + " } finally {\n"+ + " \n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " } catch (sealed e) {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_039() { + runNegativeTest( + new String[] { + "X.java", + "record X(sealed p) {\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record X(sealed p) {\n" + + " ^\n" + + "sealed cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " record X(sealed p) {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_040() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "record X(sealed p) {\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record X(sealed p) {\n" + + " ^\n" + + "sealed cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " record X(sealed p) {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 17\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_041() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X(T t) {}\n"+ + " \n"+ + " public X(int t, char c) {\n"+ + " this(t);\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " this(t);\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " this(t);\n" + + " ^^^^^^^^\n" + + "The parameterized constructor X(sealed) of type X is not applicable for the arguments (Integer)\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_042() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X(T t) {}\n"+ + " \n"+ + " public X(int t, char c) {\n"+ + " this(t);\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " this(t);\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " this(t);\n" + + " ^^^^^^^^\n" + + "The parameterized constructor X(sealed) of type X is not applicable for the arguments (Integer)\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_043() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X(T t) {}\n"+ + " \n"+ + " public X(int t, char c) {\n"+ + " new X(t).foo();\n"+ + " }\n"+ + " public void foo() {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new X(t).foo();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The parameterized constructor X(sealed) of type X is not applicable for the arguments (Integer)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " new X(t).foo();\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_044() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X(T t) {}\n"+ + " \n"+ + " public X(int t, char c) {\n"+ + " new X(t).foo();\n"+ + " }\n"+ + " public void foo() {}\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new X(t).foo();\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The parameterized constructor X(sealed) of type X is not applicable for the arguments (Integer)\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " new X(t).foo();\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_045() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(T t) {}\n"+ + " \n"+ + " public X() {\n"+ + " X x = new X();\n"+ + " x.foo(0);\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x.foo(0);\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " x.foo(0);\n" + + " ^^^\n" + + "The parameterized method foo(sealed) of type X is not applicable for the arguments (Integer)\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_046() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(T t) {}\n"+ + " \n"+ + " public X() {\n"+ + " X x = new X();\n"+ + " x.foo(0);\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x.foo(0);\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " x.foo(0);\n" + + " ^^^\n" + + "The parameterized method foo(sealed) of type X is not applicable for the arguments (Integer)\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_047() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(T t) {}\n"+ + " \n"+ + " public X() {\n"+ + " X x = new sealed();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X x = new sealed();\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_048() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo(T t) {}\n"+ + " \n"+ + " public X() {\n"+ + " X x = new sealed();\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " X x = new sealed();\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_049() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X() {\n"+ + " new sealed() {\n"+ + " @Override\n"+ + " void foo() {}\n"+ + " }.foo();\n"+ + " }\n"+ + "}\n"+ + "abstract class sealed {\n"+ + " abstract void foo();\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new sealed() {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " abstract class sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_050() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X() {\n"+ + " new sealed() {\n"+ + " @Override\n"+ + " void foo() {\n"+ + " Zork();\n"+ + " }\n"+ + " }.foo();\n"+ + " }\n"+ + "}\n"+ + "abstract class sealed {\n"+ + " abstract void foo();\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new sealed() {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type new sealed(){}\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " abstract class sealed {\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_051() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X() {\n"+ + " Object[] p = new sealed[10];\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object[] p = new sealed[10];\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_052() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public X() {\n"+ + " Object[] p = new sealed[10];\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Object[] p = new sealed[10];\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_053() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo((sealed) null);\n"+ + " }\n"+ + " private void foo(sealed o) {}\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X().foo((sealed) null);\n" + + " ^^^\n" + + "The method foo(sealed) from the type X refers to the missing type sealed\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " new X().foo((sealed) null);\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " private void foo(sealed o) {}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_054() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo((sealed) null);\n"+ + " }\n"+ + " private void foo(sealed o) {}\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new X().foo((sealed) null);\n" + + " ^^^\n" + + "The method foo(sealed) from the type X refers to the missing type sealed\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " new X().foo((sealed) null);\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " private void foo(sealed o) {}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_055() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " private void foo(Object o) {\n"+ + " if (o instanceof sealed) {}\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (o instanceof sealed) {}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_056() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " private void foo(Object o) {\n"+ + " if (o instanceof sealed) {}\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " if (o instanceof sealed) {}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug564638b_057() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " @SuppressWarnings(\"unused\")\n"+ + " I i = sealed :: new;\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class sealed{}\n" + + "interface I {\n"+ + " Object gen();\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " class sealed{}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n"); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug564638b_058() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " @SuppressWarnings(\"unused\")\n"+ + " I i = sealed :: new;\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class sealed{}\n" + + "interface I {\n"+ + " Object gen();\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " class sealed{}\n" + + " ^^^^^^\n" + + "\'sealed\' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java "+ AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL +"\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug565561_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "public sealed class X permits Outer.Inner {\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n" + + "class Outer{\n" + + " final class Inner extends X{}\n"+ + "}", + }, + "0"); + String expectedOutput = + " Inner classes:\n" + + " [inner class info: #33 Outer$Inner, outer class info: #36 Outer\n" + + " inner name: #38 Inner, accessflags: 16 final]\n" + + "\n" + + "PermittedSubclasses:\n" + + " #33 Outer$Inner\n" + + "}"; + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug565116_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "permits/X.java", + "package permits;\n"+ + "class X {\n"+ + " public static void main(String[] args) {\n"+ + " X x = new permits.X();\n"+ + " }\n"+ + "}", + }, + ""); + } + public void testBug565638_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "sealed class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}\n"+ + "final class Outer {\n"+ + " final class Inner extends X{\n"+ + " }\n"+ + "}", + }, + "0"); + } + public void testBug565782_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "sealed interface I permits X {}\n"+ + "enum X implements I {\n"+ + " ONE {};\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}", + }, + "0"); + String expectedOutput = + "PermittedSubclasses:\n" + + " #14 X$1\n" + + "}"; + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug565782_002() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "sealed interface I permits X {}\n"+ + "public enum X implements I {\n"+ + " ONE ;\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}", + }, + "0"); + String expectedOutput = "public final enum X implements I {\n"; + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug565782_003() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "sealed interface I {}\n"+ + "enum X implements I {\n"+ + " ONE {};\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}", + }, + "0"); + String expectedOutput = + "PermittedSubclasses:\n" + + " #14 X$1\n" + + "}"; + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug565782_004() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "sealed interface I {}\n"+ + "class X {\n"+ + " enum E implements I {\n"+ + " ONE {};\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}", + }, + "0"); + String expectedOutput = + "PermittedSubclasses:\n" + + " #14 X$E$1\n" + + "}"; + verifyClassFile(expectedOutput, "X$E.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug565782_005() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "sealed interface I permits X {}\n"+ + "enum X implements I {\n"+ + " ONE {},\n"+ + " TWO {},\n"+ + " THREE {};\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(0);\n"+ + " }\n"+ + "}", + }, + "0"); + String expectedOutput = + "PermittedSubclasses:\n" + + " #16 X$1,\n" + + " #25 X$2,\n" + + " #31 X$3\n" + + "}"; + verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug565847_001() { + Map options =getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING); + + this.runNegativeTest( + new String[] { + "X.java", + "public sealed class X permits Y {" + + "Zork();\n" + + "}\n" + + "final class Y extends X{}\n" + + "sealed interface I{}\n" + + "final class Z implements I{}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public sealed class X permits Y {Zork();\n" + + " ^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n" + + "2. ERROR in X.java (at line 1)\n" + + " public sealed class X permits Y {Zork();\n" + + " ^^^^^^\n" + + "This method requires a body instead of a semicolon\n" + + "----------\n", + null, + true, + options + ); + } + @SuppressWarnings({ "rawtypes" }) + public void testBug566979_001() { + Map options = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public sealed void main(String[] args){ }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public sealed void main(String[] args){ }\n" + + " ^^^^^^\n" + + "Syntax error on token \"sealed\", static expected\n" + + "----------\n", + null, + true, + options + ); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug566979_002() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public sealed void main(String[] args){ }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public sealed void main(String[] args){ }\n" + + " ^^^^^^\n" + + "Syntax error on token \"sealed\", static expected\n" + + "----------\n", + null, + true, + options + ); + } + @SuppressWarnings({ "rawtypes" }) + public void testBug566980_001() { + Map options = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public permits void main(String[] args){ }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public permits void main(String[] args){ }\n" + + " ^^^^\n" + + "Syntax error on token \"void\", delete this token\n" + + "----------\n", + null, + true, + options + ); + } + @SuppressWarnings({ "unchecked", "rawtypes" }) + public void testBug566980_002() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public permits void main(String[] args){ }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public permits void main(String[] args){ }\n" + + " ^^^^\n" + + "Syntax error on token \"void\", delete this token\n" + + "----------\n", + null, + true, + options + ); + } + @SuppressWarnings({ "rawtypes" }) + public void testBug566846_001() { + Map options = getCompilerOptions(); + this.runNegativeTest( + new String[] { + "X.java", + "record X;\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " record X;\n" + + " ^^^^^^\n" + + "Syntax error on token \"record\", package expected\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug568428_001() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo() {\n" + + " sealed interface I {}\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " sealed interface I {}\n" + + " ^\n" + + "Illegal modifier for the local interface I; abstract and strictfp are the only modifiers allowed explicitly \n" + + "----------\n" + ); + } + public void testBug568428_002() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo() {\n" + + " non-sealed interface I {}\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " non-sealed interface I {}\n" + + " ^\n" + + "Illegal modifier for the local interface I; abstract and strictfp are the only modifiers allowed explicitly \n" + + "----------\n" + ); + } + public void testBug568514_001() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo() {\n" + + " sealed enum I {}\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " sealed enum I {}\n" + + " ^\n" + + "Illegal modifier for local enum I; no explicit modifier is permitted\n" + + "----------\n" + ); + } + public void testBug568514_002() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " public void foo() {\n" + + " non-sealed enum I {}\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " non-sealed enum I {}\n" + + " ^\n" + + "Illegal modifier for local enum I; no explicit modifier is permitted\n" + + "----------\n" + ); + } + public void testBug568758_001() { + this.runNegativeTest( + new String[] { + "X.java", + "public sealed interface X{}\n", + "Y.java", + "public final class Y implements X{}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public sealed interface X{}\n" + + " ^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares X as its direct superclass or superinterface\n" + + "----------\n" + + "----------\n" + + "1. ERROR in Y.java (at line 1)\n" + + " public final class Y implements X{}\n" + + " ^\n" + + "The type Y that implements a sealed interface X should be a permitted subtype of X\n" + + "----------\n"); + } + public void testBug569522_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " sealed interface Foo permits Bar { }\n"+ + " final class Bar implements Foo { }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"\");\n"+ + " }\n"+ + "}", + }, + ""); + } + public void testBug569522_002() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " sealed class Foo permits Bar { }\n"+ + " final class Bar extends Foo { }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"\");\n"+ + " }\n"+ + "}", + }, + ""); + } + public void testBug570359_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "import java.lang.reflect.Modifier;\n"+ + "\n"+ + "sealed interface I {\n"+ + " void foo();\n"+ + "}\n"+ + "\n"+ + "class Y {\n"+ + " enum E implements I {\n"+ + " ONE() {\n"+ + " public void foo() {\n"+ + " }\n"+ + " };\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "public class X {\n"+ + " public static void main(String argv[]) {\n"+ + " Class c = Y.E.ONE.getClass();\n"+ + " System.out.println(c != null ? (c.getModifiers() & Modifier.FINAL) != 0 : false);\n"+ + " }\n"+ + "}", + }, + "true"); + String expectedOutput = "final enum Y$E$1 {\n"; + SealedTypesTests.verifyClassFile(expectedOutput, "Y$E$1.class", ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " Inner classes:\n" + + " [inner class info: #3 Y$E, outer class info: #20 Y\n" + + " inner name: #22 E, accessflags: 17416 abstract static],\n" + + " [inner class info: #1 Y$E$1, outer class info: #0\n" + + " inner name: #0, accessflags: 16400 final]\n" + + " Enclosing Method: #3 #0 Y$E\n"; + SealedTypesTests.verifyClassFile(expectedOutput, "Y$E$1.class", ClassFileBytesDisassembler.SYSTEM); + } + public void testBug568854_001() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n"+ + " sealed interface Foo permits A {}\n"+ + " record A() implements Foo {}\n"+ + " record B() implements Foo {}\n"+ + " }", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " record B() implements Foo {}\n" + + " ^^^\n" + + "The type B that implements a sealed interface X.Foo should be a permitted subtype of X.Foo\n" + + "----------\n"); + } + public void testBug568854_002() { + this.runNegativeTest( + new String[] { + "X.java", + " sealed interface Foo permits X.A {}\n"+ + " public class X {\n"+ + " record A() implements Foo {}\n"+ + " record B() implements Foo {}\n"+ + " }", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " record B() implements Foo {}\n" + + " ^^^\n" + + "The type B that implements a sealed interface Foo should be a permitted subtype of Foo\n" + + "----------\n"); + } + public void testBug568854_003() { + this.runNegativeTest( + new String[] { + "X.java", + " sealed interface Foo permits A {}\n"+ + " record A() implements Foo {}\n"+ + " record B() implements Foo {}\n"+ + " public class X {\n"+ + " }", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " record B() implements Foo {}\n" + + " ^^^\n" + + "The type B that implements a sealed interface Foo should be a permitted subtype of Foo\n" + + "----------\n"); + } + public void testBug568854_004() { + this.runNegativeTest( + new String[] { + "X.java", + " public class X {\n"+ + " sealed interface Foo permits A {}\n"+ + " class A implements Foo {}\n"+ + " final class B implements Foo {}\n"+ + " }", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class A implements Foo {}\n" + + " ^\n" + + "The class A with a sealed direct superclass or a sealed direct superinterface X.Foo should be declared either final, sealed, or non-sealed\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " final class B implements Foo {}\n" + + " ^^^\n" + + "The type B that implements a sealed interface X.Foo should be a permitted subtype of X.Foo\n" + + "----------\n"); + } + public void testBug568854_005() { + this.runNegativeTest( + new String[] { + "X.java", + " sealed interface Foo permits X.A {}\n"+ + " public class X {\n"+ + " class A implements Foo {}\n"+ + " final class B implements Foo {}\n"+ + " }", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class A implements Foo {}\n" + + " ^\n" + + "The class A with a sealed direct superclass or a sealed direct superinterface Foo should be declared either final, sealed, or non-sealed\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " final class B implements Foo {}\n" + + " ^^^\n" + + "The type B that implements a sealed interface Foo should be a permitted subtype of Foo\n" + + "----------\n"); + } + public void testBug568854_006() { + this.runNegativeTest( + new String[] { + "X.java", + " sealed interface Foo permits A {}\n"+ + " class A implements Foo {}\n"+ + " final class B implements Foo {}\n"+ + " public class X {\n"+ + " }", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " class A implements Foo {}\n" + + " ^\n" + + "The class A with a sealed direct superclass or a sealed direct superinterface Foo should be declared either final, sealed, or non-sealed\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " final class B implements Foo {}\n" + + " ^^^\n" + + "The type B that implements a sealed interface Foo should be a permitted subtype of Foo\n" + + "----------\n"); + } + public void testBug568854_007() { + this.runNegativeTest( + new String[] { + "X.java", + "sealed interface I permits A {}\n"+ + "final class A implements I {}\n"+ + "enum B {\n"+ + " ONE {\n"+ + " class Y implements I {}\n"+ + " }\n"+ + "}\n"+ + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " class Z implements I{}\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " class Y implements I {}\n" + + " ^\n" + + "A local class Y cannot have a sealed direct superclass or a sealed direct superinterface I\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " class Z implements I{}\n" + + " ^\n" + + "A local class Z cannot have a sealed direct superclass or a sealed direct superinterface I\n" + + "----------\n"); + } + public void testBug568854_008() { + this.runNegativeTest( + new String[] { + "X.java", + "sealed interface I permits X.A {}\n"+ + "public class X {\n"+ + "final class A implements I {}\n"+ + "enum B {\n"+ + " ONE {\n"+ + " class Y implements I {}\n"+ + " }\n"+ + "}\n"+ + " public static void main(String[] args) {\n"+ + " class Z implements I{}\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " class Y implements I {}\n" + + " ^\n" + + "A local class Y cannot have a sealed direct superclass or a sealed direct superinterface I\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " class Z implements I{}\n" + + " ^\n" + + "A local class Z cannot have a sealed direct superclass or a sealed direct superinterface I\n" + + "----------\n"); + } + public void testBug571332_001() { + this.runNegativeTest( + new String[] { + "X.java", + "sealed interface I {\n"+ + " void foo();\n"+ + "}\n"+ + "non-sealed interface I1 extends I {}\n"+ + "public class X {\n"+ + " public static void main(String argv[]) {\n"+ + " I lambda = () -> {};\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " I lambda = () -> {};\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); + } + public void testBug570605_001() { + runNegativeTest( + new String[] { + "X.java", + "sealed class Y {}\n"+ + "non-sealed class Z extends Y {}\n"+ + "public class X {\n"+ + " public void foo() {\n"+ + " record R() {\n"+ + " class L extends Y {}\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " class L extends Y {}\n" + + " ^\n" + + "A local class L cannot have a sealed direct superclass or a sealed direct superinterface Y\n" + + "----------\n"); + } + public void testBug570218_001() { + runConformTest( + new String[] { + "X.java", + "interface I {}\n" + + "sealed class A permits X {}\n"+ + "final class X extends A implements I { \n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n", + }, + "0"); + } + public void testBug570218_002() { + runConformTest( + new String[] { + "X.java", + "sealed interface I permits X{}\n" + + "class A {}\n"+ + "final class X extends A implements I { \n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}\n", + }, + "0"); + } + public void testBug572205_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X{\n" + + " public static void main(String[] args) {\n" + + " class Circle implements Shape{}\n" + + " }\n" + + " sealed interface Shape {}\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " class Circle implements Shape{}\n" + + " ^^^^^\n" + + "A local class Circle cannot have a sealed direct superclass or a sealed direct superinterface X.Shape\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " sealed interface Shape {}\n" + + " ^^^^^\n" + + "Sealed class or interface lacks the permits clause and no class or interface from the same compilation unit declares Shape as its direct superclass or superinterface\n" + + "----------\n"); + } + public void testBug573450_001() { + runConformTest( + new String[] { + "X.java", + "sealed interface Foo permits Foo.Bar {\n" + + " interface Interface {}\n" + + " record Bar() implements Foo, Interface { }\n" + + "}\n" + + "public class X { \n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}", + }, + "0"); + } + + public void testBug573450_002() { + runConformTest( + new String[] { + "X.java", + "interface Interface {}\n" + + "sealed interface Foo extends Interface permits Foo.Bar {\n" + + " record Bar() implements Foo, Interface {}\n" + + "}\n" + + "public class X { \n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}" + }, + "0"); + } + public void testBug573450_003() { + runNegativeTest( + new String[] { + "X.java", + "sealed interface Interface extends Foo{}\n" + + "sealed interface Foo extends Interface permits Foo.Bar, Interface {\n" + + " record Bar() implements Foo, Interface {} \n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " sealed interface Interface extends Foo{}\n" + + " ^^^^^^^^^\n" + + "The hierarchy of the type Interface is inconsistent\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " sealed interface Foo extends Interface permits Foo.Bar, Interface {\n" + + " ^^^^^^^^^\n" + + "Cycle detected: a cycle exists in the type hierarchy between Foo and Interface\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " record Bar() implements Foo, Interface {} \n" + + " ^^^\n" + + "The hierarchy of the type Bar is inconsistent\n" + + "----------\n"); + } + public void testBug573450_004() { + runConformTest( + new String[] { + "X.java", + "public sealed class X permits X.Y {\n" + + " final class Y extends X {}\n" + + " public static void main(String[] args){\n"+ + " System.out.println(0);\n" + + " }\n"+ + "}" + }, + "0"); + } + public void testBug573450_005() { + runNegativeTest( + new String[] { + "X.java", + "public sealed class X permits Y {\n" + + " final class Y extends X {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public sealed class X permits Y {\n" + + " ^\n" + + "Y cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " final class Y extends X {}\n" + + " ^\n" + + "The type Y extending a sealed class X should be a permitted subtype of X\n" + + "----------\n"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerialVersionUIDTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerialVersionUIDTests.java new file mode 100644 index 0000000000..7946d0be8f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerialVersionUIDTests.java @@ -0,0 +1,358 @@ +/******************************************************************************* + * Copyright (c) 2006, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +/* + * Here we focus on various aspects of the runtime behavior of the generated + * code. + */ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class SerialVersionUIDTests extends AbstractRegressionTest { + +public SerialVersionUIDTests(String name) { + super(name); +} +// Static initializer to specify tests subset using TESTS_* static variables +// All specified tests which does not belong to the class are skipped... +// 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[] { "test0001" }; +// TESTS_NUMBERS = new int[] { 1 }; +// TESTS_RANGE = new int[] { 1, -1 }; +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} +public static Class testClass() { + return SerialVersionUIDTests.class; +} +@Override +protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingSerialVersion, CompilerOptions.ERROR); + return options; +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "\n" + + "public class X implements Serializable {\n" + + " private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException {}\n" + + " private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {}\n" + + "}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 +public void test002() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements java.io.Externalizable {\n" + + " public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {}\n" + + " public void readExternal(java.io.ObjectInput in) throws java.io.IOException, ClassNotFoundException {}\n" + + "}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 +public void test003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements java.io.Serializable {\n" + + " private void writeObject(java.io.ObjectOutputStream stream) throws java.io.IOException {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements java.io.Serializable {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 +public void test004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements java.io.Serializable {\n" + + " private void readObject(java.io.ObjectInputStream stream) throws java.io.IOException {}\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements java.io.Serializable {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 +public void test005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X implements java.io.Serializable {\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements java.io.Serializable {\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=101476 +public void test006() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements java.io.Serializable {\n" + + " Object writeReplace() throws java.io.ObjectStreamException { return null;}\n" + + "}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=203241 +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=116733 +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=94352 +public void test007() { + this.runNegativeTest( + new String[] { + "X.java", + "abstract class A implements java.io.Serializable {}\n" + + "public class X extends A {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " abstract class A implements java.io.Serializable {}\n" + + " ^\n" + + "The serializable class A does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public class X extends A {}\n" + + " ^\n" + + "The serializable class X does not declare a static final serialVersionUID field of type long\n" + + "----------\n", + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285124 +public void _test008() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends javax.rmi.CORBA.Stub {\n" + + " public String[] _ids() { return null; }\n" + + "}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285124 +public void _test009() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " public String[] _ids() { return null; }\n" + + "}", + "Y.java", + "public abstract class Y extends javax.rmi.CORBA.Stub {\n" + + "}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=285124 +public void _test010() { + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y {\n" + + " public String[] _ids() { return null; }\n" + + "}", + "Y.java", + "public abstract class Y extends Z {\n" + + "}", + "Z.java", + "public abstract class Z extends javax.rmi.CORBA.Stub {\n" + + "}" + }, + "" + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=341475 +public void test011() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private static final long serialVersionUID = 1L;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The value of the field X.serialVersionUID is not used\n" + + "----------\n", + null, + true, + options + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=341475 +public void test012() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " private static final long serialVersionUID = 1L;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The value of the field X.serialVersionUID is not used\n" + + "----------\n", + null, + true, + options + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=341475 +public void test013() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static final long serialPersistentFields = 1L;\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, + true, + options + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=341475 +public void test014() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static final long serialPersistentFields = 1L;\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, + true, + options + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=341475 +public void test015() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.ObjectStreamField;\n" + + "public class X implements java.io.Serializable {\n" + + " private static final long serialVersionUID = 1L;\n" + + " private final static ObjectStreamField[] serialPersistentFields = null;\n" + + " private int i;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " private int i;\n" + + " ^\n" + + "The value of the field X.i is not used\n" + + "----------\n", + null, + true, + options + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=341475 +public void test016() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.ObjectStreamField;\n" + + "public class X implements java.io.Serializable {\n" + + " private static final long serialVersionUID = 1L;\n" + + " private final static ObjectStreamField[] serialPersistentFields = null;\n" + + " private int i;\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " private int i;\n" + + " ^\n" + + "The value of the field X.i is not used\n" + + "----------\n", + null, + true, + options + ); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java new file mode 100644 index 0000000000..71464a211e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SerializableLambdaTest.java @@ -0,0 +1,2390 @@ +/******************************************************************************* + * Copyright (c) 2014, 2017 GoPivotal, Inc. and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for + * Bug 405104 - [1.8][compiler][codegen] Implement support for serializeable lambdas + * Bug 439889 - [1.8][compiler] [lambda] Deserializing lambda fails with IllegalArgumentException: "Invalid lambda deserialization" + * Bug 442416 - $deserializeLambda$ missing cases for nested lambdas + * Bug 442418 - $deserializeLambda$ off-by-one error when deserializing the captured arguments of a lambda that also capture this + * Bug 449467 - [1.8][compiler] Invalid lambda deserialization with anonymous class + * Olivier Tardieu tardieu@us.ibm.com - Contributions for + * Bug 442416 - $deserializeLambda$ missing cases for nested lambdas + * Bug 442418 - $deserializeLambda$ off-by-one error when deserializing the captured arguments of a lambda that also capture this + * IBM Corporation - Additional tests + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.lang.reflect.Modifier; +import java.util.Map; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.core.util.IBootstrapMethodsEntry; +import org.eclipse.jdt.core.util.IClassFileAttribute; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.IConstantPool; +import org.eclipse.jdt.core.util.IConstantPoolConstant; +import org.eclipse.jdt.core.util.IConstantPoolEntry; +import org.eclipse.jdt.core.util.IConstantPoolEntry2; +import org.eclipse.jdt.core.util.IMethodInfo; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.core.util.BootstrapMethodsAttribute; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class SerializableLambdaTest extends AbstractRegressionTest { + + static { +// TESTS_NUMBERS = new int [] { 40 }; +// TESTS_NAMES = new String[] { "testTypeVariable" }; + } + + public static Class testClass() { + return SerializableLambdaTest.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + public SerializableLambdaTest(String testName){ + super(testName); + } + + // Enables the tests to run individually + @Override + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); + defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + return defaultOptions; + } + + public static final String RUNNER_CLASS = + "public class Y {\n"+ + " public static void main(String[]args) {\n"+ + " com.foo.X.main(args);\n"+ + " }\n"+ + "}"; + + private static final String HELPER_CLASS = + "package util;\n"+ + "import java.io.*;\n"+ + "public class Helper {\n"+ + "public static void print(Object o ) {System.err.println(o);}\n"+ + "static byte[][] data;\n"+ + "\n"+ + "public static void write(Object o) { write(0,o); }\n"+ + "public static void write(int i, Object o) {\n"+ + " if (data==null) data=new byte[10][];\n"+ + " try {\n"+ + " ByteArrayOutputStream baos = new ByteArrayOutputStream();\n"+ + " ObjectOutputStream oos = new ObjectOutputStream(baos);\n"+ + " oos.writeObject(o);\n"+ + " oos.flush();\n"+ + " oos.close();\n"+ + " data[i] = baos.toByteArray();\n"+ + " } catch (Exception e) {\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "public static Object read() { return read(0); }\n"+ + "public static Object read(int i) {\n"+ + " try {\n"+ + " ByteArrayInputStream bais = new ByteArrayInputStream(data[i]);\n"+ + " ObjectInputStream ois = new ObjectInputStream(bais);\n"+ + " Object o = ois.readObject();\n"+ + " ois.close();\n"+ + " return o;\n"+ + " } catch (Exception e) {\n"+ + " }\n"+ + " return null;\n"+ + "}\n"+ + "}\n"; + + /** + * Verifies that after deserializing it is usable, also that the bootstrap methods attribute indicates use of altMetafactory + */ + public void test001_simple() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { int m(); }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " Foo f1 = null;\n"+ + " f1 = () -> 3;\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m());\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "3", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + /** + * Sanity test, non serializable should have bootstrap methods attribute reference to metafactory. + */ + public void test002_simpleNonSerializable() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo { int m(); }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " Foo f1 = null;\n"+ + " f1 = () -> 3;\n"+ + " System.out.println(f1.m());\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "3"); + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + /** + * Basic test that deserializeLambda can cope with two lambda expressions. + */ + public void test003_twoSerializedLambdas() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { int m(); }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " Foo f1 = null, f2 = null;\n"+ + " f1 = () -> 33;\n"+ + " f2 = () -> 99;\n"+ + " util.Helper.write(0,f1);\n"+ + " util.Helper.write(1,f2);\n"+ + " f2 = (Foo)util.Helper.read(1);\n"+ + " f1 = (Foo)util.Helper.read(0);\n"+ + " System.out.println(f1.m());\n"+ + " System.out.println(f2.m());\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "33\n99", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 1\n"+ + "1: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$1:()I\n"+ + " ()I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + public void test004_lambdaWithParameterInPackage() throws Exception { + this.runConformTest( + new String[]{ + "Y.java", + "public class Y {\n"+ + " public static void main(String[]args) {\n"+ + " com.foo.X.main(args);\n"+ + " }\n"+ + "}", + "X.java", + "package com.foo;\n"+ + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { int m(int i); }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " Foo f1 = null, f2 = null;\n"+ + " f1 = (i) -> i*2;\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m(4));\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "8", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " (I)I\n"+ + " invokestatic com/foo/X.lambda$0:(I)I\n"+ + " (I)I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "com"+File.separator+"foo"+File.separator+"X.class"); + checkExpected(expectedOutput,data); + } + + public void test005_capturingVariableLambdaWithParameterInPackage() throws Exception { + this.runConformTest( + new String[]{ + "Y.java", + "public class Y {\n"+ + " public static void main(String[]args) {\n"+ + " com.foo.X.main(args);\n"+ + " }\n"+ + "}", + "X.java", + "package com.foo;\n"+ + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { int m(int i); }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " Foo f1 = null;\n"+ + " int multiplier = 3;\n"+ + " f1 = (i) -> i * multiplier;\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m(4));\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "12", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " (I)I\n"+ + " invokestatic com/foo/X.lambda$0:(II)I\n"+ + " (I)I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "com"+File.separator+"foo"+File.separator+"X.class"); + checkExpected(expectedOutput,data); + } + + // differing types, not just int + public void test006_capturingVariableLambdaWithParameterInPackage() throws Exception { + this.runConformTest( + new String[]{ + "Y.java", + "public class Y {\n"+ + " public static void main(String[]args) {\n"+ + " com.foo.X.main(args);\n"+ + " }\n"+ + "}", + "X.java", + "package com.foo;\n"+ + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { int m(String n); }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " Foo f1 = null;\n"+ + " int multiplier = 3;\n"+ + " f1 = (n) -> Integer.valueOf(n) * multiplier;\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m(\"33\"));\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "99", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " (Ljava/lang/String;)I\n"+ + " invokestatic com/foo/X.lambda$0:(ILjava/lang/String;)I\n"+ + " (Ljava/lang/String;)I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "com"+File.separator+"foo"+File.separator+"X.class"); + checkExpected(expectedOutput,data); + } + + // Fails the same way as javac right now... with NPE (b120) + public void xtest007_capturingFieldLambdaWithParameterInPackage() throws Exception { + this.runConformTest( + new String[]{ + "Y.java", + "public class Y {\n"+ + " public static void main(String[]args) {\n"+ + " com.foo.X.main(args);\n"+ + " }\n"+ + "}", + "X.java", + "package com.foo;\n"+ + "import java.io.*;\n"+ + "public class X {\n"+ + " int multiplier = 3;\n"+ + " interface Foo extends Serializable { int m(int i); }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " new X().run();\n"+ + " }\n"+ + " public void run() {\n"+ + " Foo f1 = null;\n"+ + " f1 = (i) -> i * this.multiplier;\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m(4));\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "12", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " (I)I\n"+ + " invokestatic com/foo/X.lambda$0:(II)I\n"+ + " (I)I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "com"+File.separator+"foo"+File.separator+"X.class"); + checkExpected(expectedOutput,data); + } + + public void test008_capturingTwoVariableLambdaWithParameterInPackage() throws Exception { + this.runConformTest( + new String[]{ + "Y.java", + "public class Y {\n"+ + " public static void main(String[]args) {\n"+ + " com.foo.X.main(args);\n"+ + " }\n"+ + "}", + "X.java", + "package com.foo;\n"+ + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { float m(int i, float f); }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " new X().run();\n"+ + " }\n"+ + " public void run() {\n"+ + " Foo f1 = null;\n"+ + " f1 = (i,f) -> ((float)i) * f;\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m(3,4.0f));\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "12.0", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " (IF)F\n"+ + " invokestatic com/foo/X.lambda$0:(IF)F\n"+ + " (IF)F\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "com"+File.separator+"foo"+File.separator+"X.class"); + checkExpected(expectedOutput,data); + } + + public void test009_capturingTwoSlotVariablesLambdaWithParameterInPackage() throws Exception { + this.runConformTest( + new String[]{ + "Y.java",RUNNER_CLASS, + "X.java", + "package com.foo;\n"+ + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { double m(int i, long l); }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " new X().run();\n"+ + " }\n"+ + " public void run() {\n"+ + " Foo f1 = null;\n"+ + " f1 = (i,l) -> (double)(i*l);\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m(3,40L));\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "120.0", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " (IJ)D\n"+ + " invokestatic com/foo/X.lambda$0:(IJ)D\n"+ + " (IJ)D\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "com"+File.separator+"foo"+File.separator+"X.class"); + checkExpected(expectedOutput,data); + } + + public void test010_VarargsLambdaExpression() throws Exception { + this.runConformTest( + new String[]{ + "Y.java",RUNNER_CLASS, + "X.java", + "package com.foo;\n"+ + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { String m(String... ss); }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " new X().run();\n"+ + " }\n"+ + " public void run() {\n"+ + " Foo f1 = null;\n"+ + " f1 = (strings) -> strings[0]+strings[1];\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m(\"abc\",\"def\"));\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "abcdef", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ([Ljava/lang/String;)Ljava/lang/String;\n"+ + " invokestatic com/foo/X.lambda$0:([Ljava/lang/String;)Ljava/lang/String;\n"+ + " ([Ljava/lang/String;)Ljava/lang/String;\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "com"+File.separator+"foo"+File.separator+"X.class"); + checkExpected(expectedOutput,data); + } + + // Fails same way as javac right now... with an NPE (b120) + public void xtest011_CapturingInstance() throws Exception { + this.runConformTest( + new String[]{ + "Y.java",RUNNER_CLASS, + "X.java", + "package com.foo;\n"+ + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { String m(); }\n"+ + "\n"+ + " String fieldValue = \"hello\";\n"+ + " public static void main(String[] args) {\n"+ + " new X().run();\n"+ + " }\n"+ + " public void run() {\n"+ + " Foo f1 = null;\n"+ + " f1 = () -> this.fieldValue;\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m());\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "abcdef", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ([Ljava/lang/String;)Ljava/lang/String;\n"+ + " invokestatic com/foo/X.lambda$0:([Ljava/lang/String;)Ljava/lang/String;\n"+ + " ([Ljava/lang/String;)Ljava/lang/String;\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "com"+File.separator+"foo"+File.separator+"X.class"); + checkExpected(expectedOutput,data); + } + + public void test012_intersectionCast() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.*;\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { int m(); }\n"+ + " interface Marker {}\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " Foo f1 = null;\n"+ + " f1 = (Foo & Marker) () -> 3;\n"+ + " System.out.println(\"isMarker?\"+(f1 instanceof Marker));\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m());\n"+ + " System.out.println(\"isMarker?\"+(f1 instanceof Marker));\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "isMarker?true\n3\nisMarker?true", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 3\n"+ // BitFlags: 0x01 = FLAG_SERIALIZABLE 0x02 = FLAG_MARKER + " 1\n"+ // Marker interface count + " X$Marker\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + public void test013_intersectionCast() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.*;\n"+ + "interface Goo {}\n"+ + "public class X {\n"+ + " interface Foo extends Serializable { int m(); }\n"+ + " interface Marker {}\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " Foo f1 = null;\n"+ + " f1 = (Foo & Goo & Serializable & Marker) () -> 3;\n"+ + " System.out.println(\"isMarker?\"+(f1 instanceof Marker));\n"+ + " System.out.println(\"isGoo?\"+(f1 instanceof Goo));\n"+ + " System.out.println(\"isSerializable?\"+(f1 instanceof Serializable));\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m());\n"+ + " System.out.println(\"isMarker?\"+(f1 instanceof Marker));\n"+ + " System.out.println(\"isGoo?\"+(f1 instanceof Goo));\n"+ + " System.out.println(\"isSerializable?\"+(f1 instanceof Serializable));\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "isMarker?true\nisGoo?true\nisSerializable?true\n3\nisMarker?true\nisGoo?true\nisSerializable?true", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 3\n"+ // BitFlags: 0x01 = FLAG_SERIALIZABLE 0x02 = FLAG_MARKER + " 2\n"+ // Marker interface count + " Goo\n"+ + " X$Marker\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + public void test014_intersectionCastAndNotSerializable() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.*;\n"+ + "interface Goo {}\n"+ + "public class X {\n"+ + " interface Foo { int m(); }\n"+ + " interface Marker {}\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " Foo f1 = null;\n"+ + " f1 = (Foo & Goo & Marker) () -> 3;\n"+ + " System.out.println(\"isMarker?\"+(f1 instanceof Marker));\n"+ + " System.out.println(\"isGoo?\"+(f1 instanceof Goo));\n"+ + " System.out.println(\"isSerializable?\"+(f1 instanceof Serializable));\n"+ + " System.out.println(f1.m());\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "isMarker?true\nisGoo?true\nisSerializable?false\n3", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 2\n"+ // BitFlags: 0x02 = FLAG_MARKER + " 2\n"+ // Marker interface count + " Goo\n"+ + " X$Marker\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + public void test015_serializableViaIntersectionCast() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.*;\n"+ + "interface Goo {}\n"+ + "public class X {\n"+ + " interface Foo { int m(); }\n"+ + " interface Marker {}\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " Foo f1 = null;\n"+ + " f1 = (Foo & Goo & Serializable & Marker) () -> 3;\n"+ + " System.out.println(\"isMarker?\"+(f1 instanceof Marker));\n"+ + " System.out.println(\"isGoo?\"+(f1 instanceof Goo));\n"+ + " System.out.println(\"isSerializable?\"+(f1 instanceof Serializable));\n"+ + " util.Helper.write(f1);\n"+ + " f1 = (Foo)util.Helper.read();\n"+ + " System.out.println(f1.m());\n"+ + " System.out.println(\"isMarker?\"+(f1 instanceof Marker));\n"+ + " System.out.println(\"isGoo?\"+(f1 instanceof Goo));\n"+ + " System.out.println(\"isSerializable?\"+(f1 instanceof Serializable));\n"+ + " }\n"+ + "}\n", + "Helper.java",HELPER_CLASS, + }, + "isMarker?true\nisGoo?true\nisSerializable?true\n3\nisMarker?true\nisGoo?true\nisSerializable?true", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 3\n"+ // BitFlags: 0x01 = FLAG_SERIALIZABLE 0x02 = FLAG_MARKER + " 2\n"+ // Marker interface count + " Goo\n"+ + " X$Marker\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + // SAM type not first in intersection cast + public void test016_bug424211() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "public class X {\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " AutoCloseable one = ((Serializable & AutoCloseable) (() -> {}));\n"+ + " one.close();\n"+ + " }\n"+ + "}" + }, + "", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()V\n"+ + " invokestatic X.lambda$0:()V\n"+ + " ()V\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + // Now SAM type first + public void test017_bug424211() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "public class X {\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " AutoCloseable one = ((AutoCloseable & Serializable) (() -> {}));\n"+ + " one.close();\n"+ + " }\n"+ + "}" + }, + "", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()V\n"+ + " invokestatic X.lambda$0:()V\n"+ + " ()V\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + // Not Serializable but a regular marker interface + public void test018_bug424211() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "interface Marker {}\n"+ + "public class X {\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " AutoCloseable one = ((Marker & AutoCloseable) (() -> {}));\n"+ + " one.close();\n"+ + " }\n"+ + "}" + }, + "", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()V\n"+ + " invokestatic X.lambda$0:()V\n"+ + " ()V\n"+ + " 2\n"+ + " 1\n"+ + " Marker\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + // Now SAM type not first and serialization occurring + public void test019_bug424211() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "interface SAM {int m();}\n"+ + "public class X {\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " SAM one = ((Serializable & SAM) (() -> 3));\n"+ + " System.out.println(one.m());\n"+ + " util.Helper.write(one);\n"+ + " one = (SAM)util.Helper.read();\n"+ + " System.out.println(one.m());\n"+ + " }\n"+ + "}", + "Helper.java",HELPER_CLASS, + }, + "3\n3", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + public void test020_lambdaNames() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "interface Foo {int m();}\n"+ + "interface FooN extends Serializable {int m();}\n"+ + "public class X {\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " AutoCloseable one = () -> {};\n"+ + " new X().m();\n"+ + " one.close();\n"+ + " }\n"+ + " public void m() { Foo f = () -> 3; System.out.println(f.m());}\n"+ + " public void n() { FooN f = () -> 3; System.out.println(f.m());}\n"+ + "}" + }, + "3", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + " private static synthetic void lambda$0() throws java.lang.Exception;\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " private static synthetic int lambda$1();\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test021_lambdaNamesVariants() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "interface Foo {int m();}\n"+ + "interface FooSer extends Serializable {int m();}\n"+ + "interface FooI {int m(int i);}\n"+ + "interface FooSerI extends Serializable {int m(int i);}\n"+ + "public class X {\n"+ + "\n"+ + " Foo instanceField = () -> 1;\n"+ + " FooSer instanceFieldSer = () -> 2;\n"+ + " static Foo staticField = () -> 3;\n"+ + " static FooSer staticFieldSer = () -> 4;\n"+ + " FooI instanceFieldI = (i) -> 5;\n"+ + " FooSerI instanceFieldSerI = (i) -> 6;\n"+ + "\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " int x = 4;\n"+ + " Foo a = () -> 1;\n"+ + " FooSer b = () -> 2;\n"+ + " FooI c = (i) -> 3;\n"+ + " FooSerI d = (i) -> 4;\n"+ + " Foo e = () -> x;\n"+ + " FooSer f = () -> x+1;\n"+ + " FooI g = (i) -> x+2;\n"+ + " FooSerI h = (i) -> x+3;\n"+ + " }\n"+ + "}" + }, + "", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "static lambda$2()I\n"+ + "static lambda$3()I\n"+ + "static lambda$0()I\n"+ + "static lambda$1()I\n"+ + "static lambda$4(I)I\n"+ + "static lambda$5(I)I\n"+ + "static lambda$6()I\n"+ + "static lambda$7()I\n"+ + "static lambda$8(I)I\n"+ + "static lambda$9(I)I\n"+ + "static lambda$10(I)I\n"+ + "static lambda$11(I)I\n"+ + "static lambda$12(II)I\n"+ + "static lambda$13(II)I\n"; + String actualOutput = printLambdaMethods(OUTPUT_DIR + File.separator + "X.class"); + if (!actualOutput.equals(expectedOutput)) { + printIt(actualOutput); + assertEquals(expectedOutput,actualOutput); + } + } + + public void test022_nestedLambdas() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "interface Foo extends Serializable {int m();}\n"+ + "public class X {\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " Foo f = () -> { return ((Foo)()->33).m();};\n"+ + " System.out.println(f.m());\n"+ + " util.Helper.write(f);\n"+ + " f = (Foo)util.Helper.read();\n"+ + " System.out.println(f.m());\n"+ + " }\n"+ + "}", + "Helper.java",HELPER_CLASS, + }, + "33\n33", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 1\n"+ + "1: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$1:()I\n"+ + " ()I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + public void test023_lambdasInOtherPlaces_Field() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "interface Foo extends Serializable {int m();}\n"+ + "public class X {\n"+ + " Foo f = () -> 99;\n" + + " public static void main(String argv[]) throws Exception {\n"+ + " new X().run();\n"+ + " }\n"+ + " public void run() {\n"+ + " System.out.println(f.m());\n"+ + " util.Helper.write(f);\n"+ + " f = (Foo)util.Helper.read();\n"+ + " System.out.println(f.m());\n"+ + " }\n"+ + "}", + "Helper.java",HELPER_CLASS, + }, + "99\n99", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + public void test024_lambdasInOtherPlaces_MethodParameter() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "interface Foo extends Serializable {int m();}\n"+ + "public class X {\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " new X().run(()->33);\n"+ + " }\n"+ + " public void run(Foo f) {\n"+ + " System.out.println(f.m());\n"+ + " util.Helper.write(f);\n"+ + " f = (Foo)util.Helper.read();\n"+ + " System.out.println(f.m());\n"+ + " }\n"+ + "}", + "Helper.java",HELPER_CLASS, + }, + "33\n33", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + public void test025_lambdasWithGenericInferencing() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "import java.util.function.*;\n"+ + "public class X {\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " new X().run();\n"+ + " }\n"+ + " public void run() {\n"+ + " IntFunction times3 = (IntFunction & Serializable) (triple) -> 3 * triple;\n"+ + " System.out.println(times3.apply(4));\n"+ + " util.Helper.write(times3);\n"+ + " times3 = (IntFunction)util.Helper.read();\n"+ + " System.out.println(times3.apply(4));\n"+ + " }\n"+ + "}", + "Helper.java",HELPER_CLASS, + }, + "12\n12", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " (I)Ljava/lang/Object;\n"+ + " invokestatic X.lambda$0:(I)Ljava/lang/Integer;\n"+ + " (I)Ljava/lang/Integer;\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + public void test026_lambdasInOtherPlaces_Clinit() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.Serializable;\n"+ + "interface Foo extends Serializable {int m();}\n"+ + "public class X {\n"+ + " static {\n"+ + " Foo f = () -> 99;\n" + + " }\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " new X().run();\n"+ + " }\n"+ + " public void run() {\n"+ + " Foo f = ()->99;\n"+ + " System.out.println(f.m());\n"+ + " util.Helper.write(f);\n"+ + " f = (Foo)util.Helper.read();\n"+ + " System.out.println(f.m());\n"+ + " }\n"+ + "}", + "Helper.java",HELPER_CLASS, + }, + "99\n99", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$0:()I\n"+ + " ()I\n"+ + " 1\n"+ + "1: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()I\n"+ + " invokestatic X.lambda$1:()I\n"+ + " ()I\n"+ + " 1\n"; + String data = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "X.class"); + checkExpected(expectedOutput,data); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=449467 - [1.8][compiler] Invalid lambda deserialization with anonymous class + public void test449467() throws Exception { + this.runConformTest( + new String[]{ + "TestClass.java", + "import java.io.ByteArrayInputStream;\n"+ + "import java.io.ByteArrayOutputStream;\n"+ + "import java.io.ObjectInputStream;\n"+ + "import java.io.ObjectOutputStream;\n"+ + "import java.io.Serializable;\n"+ + "\n"+ + "public class TestClass implements Serializable {\n"+ + " String msg = \"HEY!\";\n"+ + " OtherClass other;\n"+ + "\n"+ + " public TestClass(StringBuilder sb) {\n"+ + " other = new OtherClass() {\n"+ + " {\n"+ + " other2 = new OtherClass2((Runnable & Serializable) () -> {\n"+ + " sb.length();\n"+ + " say();\n"+ + " });\n"+ + " }\n"+ + " };\n"+ + " }\n"+ + "\n"+ + " public void say() {\n"+ + " System.out.println(msg);\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " ByteArrayOutputStream buffer = new ByteArrayOutputStream();\n"+ + " try (ObjectOutputStream out = new ObjectOutputStream(buffer)) {\n"+ + " out.writeObject(new TestClass(new StringBuilder()));\n"+ + " }\n"+ + " try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()))) {\n"+ + " TestClass s = (TestClass) in.readObject();\n"+ + " s.say();\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class OtherClass implements Serializable {\n"+ + " OtherClass2 other2;\n"+ + "}\n"+ + "\n"+ + "class OtherClass2 implements Serializable {\n"+ + " Runnable runnable;\n"+ + "\n"+ + " public OtherClass2(Runnable runnable) {\n"+ + " this.runnable = runnable;\n"+ + " }\n"+ + "}\n" + }, + "HEY!", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + public void test449467_2() throws Exception { + this.runConformTest( + new String[]{ + "com/foo/TestClass.java", + "package com.foo;\n"+ + "import java.io.ByteArrayInputStream;\n"+ + "import java.io.ByteArrayOutputStream;\n"+ + "import java.io.ObjectInputStream;\n"+ + "import java.io.ObjectOutputStream;\n"+ + "import java.io.Serializable;\n"+ + "public class TestClass implements Serializable {\n"+ + " String msg = \"HEY!\";\n"+ + " OtherClass other;\n"+ + "\n"+ + " public TestClass(StringBuilder sb) {\n"+ + " other = new OtherClass() {\n"+ + " {\n"+ + " other2 = new OtherClass2((Runnable & Serializable) () -> {\n"+ + " sb.length();\n"+ + " say();\n"+ + " });\n"+ + " }\n"+ + " };\n"+ + " }\n"+ + "\n"+ + " public void say() {\n"+ + " System.out.println(msg);\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " ByteArrayOutputStream buffer = new ByteArrayOutputStream();\n"+ + " try (ObjectOutputStream out = new ObjectOutputStream(buffer)) {\n"+ + " out.writeObject(new TestClass(new StringBuilder()));\n"+ + " }\n"+ + " try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()))) {\n"+ + " TestClass s = (TestClass) in.readObject();\n"+ + " s.say();\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class OtherClass implements Serializable {\n"+ + " OtherClass2 other2;\n"+ + "}\n"+ + "\n"+ + "class OtherClass2 implements Serializable {\n"+ + " Runnable runnable;\n"+ + "\n"+ + " public OtherClass2(Runnable runnable) {\n"+ + " this.runnable = runnable;\n"+ + " }\n"+ + "}\n" + }, + "HEY!", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=428552, [1.8][compiler][codegen] Serialization does not work for method references + public void test428552() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " interface Example extends Serializable {\n" + + " String convert(X o);\n" + + " }\n" + + " public static void main(String[] args) throws IOException {\n" + + " Example e=X::toString;\n" + + " util.Helper.write(e);\n"+ + " e = (Example)util.Helper.read();\n"+ + " System.out.println(e.convert(new X()));\n"+ + " }\n" + + " public String toString() {\n" + + " return \"XItIs\";\n" + + " }\n" + + "}\n", + "Helper.java",HELPER_CLASS, + }, + "XItIs", + null, + true, + new String [] { "-Ddummy" }); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=428642 + public void test428642() throws Exception { + this.runConformTest( + new String[]{ + "QuickSerializedLambdaTest.java", + "import java.io.*;\n"+ + "import java.util.function.IntConsumer;\n"+ + "\n"+ + "public class QuickSerializedLambdaTest {\n"+ + " interface X extends IntConsumer,Serializable{}\n"+ + " public static void main(String[] args) throws IOException, ClassNotFoundException {\n"+ + " X x2 = System::exit; // method reference\n"+ + " ByteArrayOutputStream debug=new ByteArrayOutputStream();\n"+ + " try(ObjectOutputStream oo=new ObjectOutputStream(debug))\n"+ + " {\n"+ + " oo.writeObject(x2);\n"+ + " }\n"+ + " try(ObjectInputStream oi=new ObjectInputStream(new ByteArrayInputStream(debug.toByteArray())))\n"+ + " {\n"+ + " X x=(X)oi.readObject();\n"+ + " x.accept(0);// shall exit\n"+ + " }\n"+ + " throw new AssertionError(\"should not reach this point\");\n"+ + " }\n"+ + "}\n", + "Helper.java", + "public class Helper {\n"+ + " public static String tostring(java.lang.invoke.SerializedLambda sl) {\n"+ + " return sl.toString();\n"+ + " }\n"+ + "}" + }, + "", + null,true, + new String[]{"-Ddummy"}); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + public void test428642_2() throws Exception { + this.runConformTest( + new String[]{ + "Helper.java", + "public class Helper {\n"+ + " public static String tostring(java.lang.invoke.SerializedLambda sl) {\n"+ + " return sl.toString();\n"+ + " }\n"+ + " public static void main(String[]argv) throws Exception {\n"+ + " foo.QuickSerializedLambdaTest.main(argv);\n"+ + " }\n"+ + "}", + "QuickSerializedLambdaTest.java", + "package foo;\n"+ + "import java.io.*;\n"+ + "import java.util.function.IntConsumer;\n"+ + "\n"+ + "public class QuickSerializedLambdaTest {\n"+ + " interface X extends IntConsumer,Serializable{}\n"+ + " public static void main(String[] args) throws IOException, ClassNotFoundException {\n"+ + " X x1 = i -> System.out.println(i);// lambda expression\n"+ + " X x2 = System::exit; // method reference\n"+ + " ByteArrayOutputStream debug=new ByteArrayOutputStream();\n"+ + " try(ObjectOutputStream oo=new ObjectOutputStream(debug))\n"+ + " {\n"+ + " oo.writeObject(x1);\n"+ + " oo.writeObject(x2);\n"+ + " }\n"+ + " try(ObjectInputStream oi=new ObjectInputStream(new ByteArrayInputStream(debug.toByteArray())))\n"+ + " {\n"+ + " X x=(X)oi.readObject();\n"+ + " x.accept(42);// shall print \"42\"\n"+ + " x=(X)oi.readObject();\n"+ + " x.accept(0);// shall exit\n"+ + " }\n"+ + " throw new AssertionError(\"should not reach this point\");\n"+ + " }\n"+ + "}\n" + }, + "42", + null,true, + new String[]{"-Ddummy"}); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=429112, [1.8][compiler] Exception when compiling Serializable array constructor reference + public void test429112() throws Exception { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.*;\n" + + "import java.util.function.IntFunction;\n" + + "public class X {\n" + + " interface IF extends IntFunction, Serializable {}\n" + + " public static void main(String[] args) throws IOException, ClassNotFoundException {\n" + + " IF factory=String[]::new;\n" + + " Object o = factory.apply(1234);\n" + + " ByteArrayOutputStream debug=new ByteArrayOutputStream();\n"+ + " try(ObjectOutputStream oo=new ObjectOutputStream(debug))\n"+ + " {\n"+ + " oo.writeObject(factory);\n"+ + " }\n"+ + " try(ObjectInputStream oi=new ObjectInputStream(new ByteArrayInputStream(debug.toByteArray())))\n"+ + " {\n"+ + " IF x = (IF)oi.readObject();\n"+ + " Object p = x.apply(1234);\n"+ + " System.out.println(p.getClass());\n" + + " String [] sa = (String []) p;\n" + + " System.out.println(sa.length);\n" + + " }\n"+ + " }\n"+ + "}\n", + }, + "class [Ljava.lang.String;\n" + + "1234", + null,true, + new String[]{"-Ddummy"}); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=439889 - [1.8][compiler] [lambda] Deserializing lambda fails with IllegalArgumentException: "Invalid lambda deserialization" + public void test439889() throws Exception { + this.runConformTest( + new String[]{ + "SerializationTest.java", + "import java.io.*;\n"+ + "\n"+ + "public class SerializationTest implements Serializable {\n"+ + " interface SerializableRunnable extends Runnable, Serializable {\n"+ + " }\n"+ + "\n"+ + " SerializableRunnable runnable;\n"+ + "\n"+ + " public SerializationTest() {\n"+ + " final SerializationTest self = this;\n"+ + " // runnable = () -> self.doSomething();\n"+ + " runnable = () -> this.doSomething();\n"+ // results in this method handle: #166 invokespecial SerializationTest.lambda$0:()V + " }\n"+ + "\n"+ + " public void doSomething() {\n"+ + " System.out.println(\"Hello,world!\");\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " final ByteArrayOutputStream buffer = new ByteArrayOutputStream();\n"+ + " try (ObjectOutputStream out = new ObjectOutputStream(buffer) ) {\n"+ + " out.writeObject(new SerializationTest());\n"+ + " }\n"+ + " try (ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()))) {\n"+ + " final SerializationTest s = (SerializationTest) in.readObject();\n"+ + " s.doSomething();\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "Hello,world!", + null,true, + new String[]{"-Ddummy"}); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + public void test439889_2() throws Exception { + this.runConformTest( + new String[]{ + "SerializationTest.java", + "import java.io.*;\n"+ + "\n"+ + "public class SerializationTest implements Serializable {\n"+ + " interface SerializableRunnable extends Runnable, Serializable {\n"+ + " }\n"+ + "\n"+ + " SerializableRunnable runnable;\n"+ + "\n"+ + " public SerializationTest() {\n"+ + " final SerializationTest self = this;\n"+ + " runnable = () -> self.doSomething();\n"+ // results in this method handle: #168 invokestatic SerializationTest.lambda$0:(LSerializationTest;)V + " // runnable = () -> this.doSomething();\n"+ + " }\n"+ + "\n"+ + " public void doSomething() {\n"+ + " System.out.println(\"Hello,world!\");\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " final ByteArrayOutputStream buffer = new ByteArrayOutputStream();\n"+ + " try (ObjectOutputStream out = new ObjectOutputStream(buffer) ) {\n"+ + " out.writeObject(new SerializationTest());\n"+ + " }\n"+ + " try (ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()))) {\n"+ + " final SerializationTest s = (SerializationTest) in.readObject();\n"+ + " s.doSomething();\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "Hello,world!", + null,true, + new String[]{"-Ddummy"}); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + public void testNestedLambdas_442416() throws Exception { + this.runConformTest( + new String[]{ + "Foo.java", + "import java.io.*;\n"+ + "public class Foo {\n"+ + " static byte[] toSer(Object o) {\n"+ + " try {\n"+ + " final ByteArrayOutputStream buffer = new ByteArrayOutputStream();\n"+ + " try (ObjectOutputStream out = new ObjectOutputStream(buffer) ) {\n"+ + " out.writeObject(o);\n"+ + " }\n"+ + " return buffer.toByteArray();\n"+ + " } catch (Exception e) {e.printStackTrace();return null;}\n"+ + " }\n"+ + " static Object fromSer(byte[] bs) {\n"+ + " try {\n"+ + " try (ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream(bs))) {\n"+ + " final Object s = in.readObject();\n"+ + " return s;\n"+ + " }\n"+ + " } catch (Exception e) {e.printStackTrace();return null;}\n"+ + " }\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " Runnable nested1,nested2;\n"+ + " Runnable lambda0 = (java.io.Serializable & Runnable) () -> {\n"+ + " Runnable lambda1 = (java.io.Serializable & Runnable) () -> {\n"+ + " Runnable lambda2 = (java.io.Serializable & Runnable) () -> {\n"+ + " System.out.println(\"Hello,world!\");\n"+ + " };\n"+ + " byte[] bs = toSer(lambda2);\n"+ + " Runnable r = (Runnable)fromSer(bs);\n"+ + " r.run();\n"+ + " };\n"+ + " byte[] bs = toSer(lambda1);\n"+ + " Runnable r = (Runnable)fromSer(bs);\n"+ + " r.run();\n"+ + " };\n"+ + " byte[] bs = toSer(lambda0);\n"+ + " Runnable r = (Runnable)fromSer(bs);\n"+ + " r.run();\n"+ + " }\n"+ + "}\n", + }, + "Hello,world!", + null,true, + new String[]{"-Ddummy"}); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + public void testBindingThis_442418() throws Exception { + this.runConformTest( + new String[]{ + "Foo.java", + "import java.io.*;\n"+ + "public class Foo implements Serializable {\n"+ + " static byte[] toSer(Object o) {\n"+ + " try {\n"+ + " final ByteArrayOutputStream buffer = new ByteArrayOutputStream();\n"+ + " try (ObjectOutputStream out = new ObjectOutputStream(buffer) ) {\n"+ + " out.writeObject(o);\n"+ + " }\n"+ + " return buffer.toByteArray();\n"+ + " } catch (Exception e) {e.printStackTrace();return null;}\n"+ + " }\n"+ + " static Object fromSer(byte[] bs) {\n"+ + " try {\n"+ + " try (ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream(bs))) {\n"+ + " final Object s = in.readObject();\n"+ + " return s;\n"+ + " }\n"+ + " } catch (Exception e) {e.printStackTrace();return null;}\n"+ + " }\n"+ + " void m(int i) {\n"+ + " System.out.println(i);\n"+ + " }\n"+ + " void n(int i) {\n"+ + " Runnable lambda = (java.io.Serializable & Runnable) () -> { this.m(i); };\n"+ + " byte[] bs = toSer(lambda);\n"+ + " Runnable r = (Runnable)fromSer(bs);\n"+ + " r.run();\n"+ + " }\n"+ + " public static void main(String[] args) throws Exception {\n"+ + " new Foo().n(42);\n"+ + " }\n"+ + "}\n", + }, + "42", + null,true, + new String[]{"-Ddummy"}); // Not sure, unless we force the VM to not be reused by passing dummy vm argument, the generated program aborts midway through its execution. + } + + public void testbug479119() { + this.runConformTest( + new String[]{ + "Testbed.java", + "import java.io.ObjectStreamClass;\n" + + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Method;\n" + + "import java.util.function.IntFunction;\n" + + "import java.util.stream.Stream;\n" + + "public class Testbed {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(getMethod(Testbed::foo).equals(getMethod(Testbed::foo)));\n" + + " }\n" + + " private static void foo() { }\n" + + " static interface MethodRef extends Runnable, Serializable { }\n" + + " private static Method getMethod(MethodRef methodRef) {\n" + + " try {\n" + + " final Method invokeWriteReplaceMethod = ObjectStreamClass.class.getDeclaredMethod(\"invokeWriteReplace\", Object.class);\n" + + " invokeWriteReplaceMethod.setAccessible(true);\n" + + " final SerializedLambda l = (SerializedLambda)invokeWriteReplaceMethod.invoke(\n" + + " ObjectStreamClass.lookupAny(methodRef.getClass()),\n" + + " methodRef\n" + + " );\n" + + " System.out.println(\"Looking for \" + l.getImplClass() + \".\" + l.getImplMethodName());\n" + + " final Method[] methods = Stream.of(Class.forName(l.getImplClass()).getDeclaredMethods()).\n" + + " filter(m -> m.getName().equals(l.getImplMethodName())).\n" + + " toArray(Method[]::new);\n" + + " if(methods.length != 1) throw new AssertionError(\"TODO: check signature\");\n" + + " return methods[0];\n" + + " } catch(Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "Looking for Testbed.foo\n" + + "Looking for Testbed.foo\n" + + "true", + null,true, + (isJRE9Plus + ? new String[] { "--add-opens", "java.base/java.io=ALL-UNNAMED" } + : new String [] { "-Ddummy" }) + ); + + + String bootstrapEntries = printBootstrapMethodsAttribute(OUTPUT_DIR + File.separator + "Testbed.class"); + String expectedOutput = + "0: invokestatic java/lang/invoke/LambdaMetafactory.altMetafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " ()V\n"+ + " invokestatic Testbed.foo:()V\n"+ + " ()V\n"+ + " 1\n"+ + "1: invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " (Ljava/lang/Object;)Z\n"+ + " invokestatic Testbed.lambda$2:(Ljava/lang/invoke/SerializedLambda;Ljava/lang/reflect/Method;)Z\n"+ + " (Ljava/lang/reflect/Method;)Z\n"+ + "2: invokestatic java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n"+ + " Method arguments:\n"+ + " (I)Ljava/lang/Object;\n"+ + " invokestatic Testbed.lambda$3:(I)[Ljava/lang/reflect/Method;\n"+ + " (I)[Ljava/lang/reflect/Method;\n"; + + checkExpected(expectedOutput, bootstrapEntries); + } + + public void testbug479119a() { + this.runConformTest( + new String[]{ + "Testbed.java", + "import java.io.ObjectStreamClass;\n" + + "import java.io.Serializable;\n" + + "import java.lang.invoke.SerializedLambda;\n" + + "import java.lang.reflect.Constructor;\n" + + "import java.lang.reflect.Executable;\n" + + "import java.lang.reflect.Method;\n" + + "import java.util.function.IntFunction;\n" + + "import java.util.stream.Stream;\n" + + "public class Testbed {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(getMethod(Testbed::foo).equals(getMethod(Testbed::foo)));\n" + + " System.out.println(getMethod(new Foo()::method).equals(getMethod(new Bar()::method)));\n" + + " System.out.println(getMethod(MethodRefImpl::new).equals(getMethod(MethodRefImpl::new)));\n" + + " }\n" + + " static class MethodRefImpl implements MethodRef {\n" + + " @Override\n" + + " public void run() {}\n" + + " }\n" + + " public static class Base {\n" + + " public void method () {}\n" + + " }\n" + + " public static class Foo extends Base {}\n" + + " public static class Bar extends Base {}\n" + + " private static void foo() { }\n" + + " static interface MethodRef extends Runnable, Serializable { }\n" + + " private static Executable getMethod(MethodRef methodRef) {\n" + + " try {\n" + + " final Method invokeWriteReplaceMethod = ObjectStreamClass.class.getDeclaredMethod(\"invokeWriteReplace\", Object.class);\n" + + " invokeWriteReplaceMethod.setAccessible(true);\n" + + " final SerializedLambda l = (SerializedLambda)invokeWriteReplaceMethod.invoke(\n" + + " ObjectStreamClass.lookupAny(methodRef.getClass()),\n" + + " methodRef\n" + + " );\n" + + " System.out.println(\"Looking for \" + l.getImplClass() + \".\" + l.getImplMethodName());\n" + + " boolean isConstructor = l.getImplMethodName().indexOf(\"\") >= 0;\n" + + " final Executable[] methods = Stream.of(isConstructor ? Class.forName(l.getImplClass()).getDeclaredConstructors() : Class.forName(l.getImplClass()).getDeclaredMethods()).\n" + + " filter(m -> m.getName().equals(isConstructor ? l.getImplClass() : l.getImplMethodName())).\n" + + " toArray(isConstructor ? Constructor[]::new : Method[]::new);\n" + + " if(methods.length != 1) throw new AssertionError(\"TODO: check signature\");\n" + + " return methods[0];\n" + + " } catch(Exception e) {\n" + + " throw new RuntimeException(e);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "Looking for Testbed.foo\n" + + "Looking for Testbed.foo\n" + + "true\n" + + "Looking for Testbed$Base.method\n" + + "Looking for Testbed$Base.method\n" + + "true\n" + + "Looking for Testbed$MethodRefImpl.\n" + + "Looking for Testbed$MethodRefImpl.\n" + + "true", + null,true, + (isJRE9Plus + ? new String[] { "--add-opens", "java.base/java.io=ALL-UNNAMED" } + : new String [] { "-Ddummy" }) + ); + } + + // Serializable reference expressions that share the same name + public void testbug479119b() { + this.runConformTest( + new String[]{ + "X.java", + "import java.io.ByteArrayInputStream;\n" + + "import java.io.ByteArrayOutputStream;\n" + + "import java.io.IOException;\n" + + "import java.io.ObjectInputStream;\n" + + "import java.io.ObjectOutputStream;\n" + + "import java.io.Serializable;\n" + + "public class X {\n" + + " public static interface Consumer extends Serializable {\n" + + " void accept(T t);\n" + + " }\n" + + " public static class Foo {\n" + + " public void method () {\n" + + " System.out.println(\"Foo\");\n" + + " }\n" + + " }\n" + + " public static class Bar {\n" + + " public void method () {\n" + + " System.out.println(\"Bar\");\n" + + " }\n" + + " }\n" + + " public static void main (String[] args) throws IOException, ClassNotFoundException {\n" + + " Consumer foo = Foo::method;\n" + + " Consumer bar = Bar::method;\n" + + " Consumer baz = (b) -> {b.method();};\n" + + " ByteArrayOutputStream debug=new ByteArrayOutputStream();\n" + + " try(ObjectOutputStream oo=new ObjectOutputStream(debug)) {\n" + + " oo.writeObject(bar);\n" + + " }\n" + + " try(ObjectInputStream oi=new ObjectInputStream(new ByteArrayInputStream(debug.toByteArray()))) {\n" + + " Consumer x = (Consumer)oi.readObject();\n" + + " x.accept(new Bar());\n" + + " }\n" + + " debug.reset();\n" + + " try(ObjectOutputStream oo=new ObjectOutputStream(debug)) {\n" + + " oo.writeObject(foo);\n" + + " }\n" + + " try(ObjectInputStream oi=new ObjectInputStream(new ByteArrayInputStream(debug.toByteArray()))) {\n" + + " Consumer x = (Consumer)oi.readObject();\n" + + " x.accept(new Foo());\n" + + " }\n" + + " }\n" + + "}\n" + }, + "Bar\n" + + "Foo", + null,true, + new String[]{"-Ddummy"}); + } + public void testbug479119_comment20() { + this.runConformTest( + new String[]{ + "Testbed.java", + "import java.io.ByteArrayInputStream;\n" + + "import java.io.ByteArrayOutputStream;\n" + + "import java.io.IOException;\n" + + "import java.io.ObjectInputStream;\n" + + "import java.io.ObjectOutputStream;\n" + + "import java.io.Serializable;\n" + + "interface FI extends Serializable{\n" + + " void run(Testbed args);\n" + + "}\n" + + "interface IF extends Serializable{\n" + + " void run();\n" + + "}\n" + + "public class Testbed implements Serializable{\n" + + " String f;\n" + + " Testbed(String str) {\n" + + " f = str;\n" + + " }\n" + + " void test() throws IOException, ClassNotFoundException {\n" + + " accept(Testbed::foo);\n" + + " accept(this::foo); \n" + + " }\n" + + " void foo() {\n" + + " System.out.println(this.f);\n" + + " }\n" + + " void accept(FI fi) {\n" + + " fi.run(this);\n" + + " }\n" + + " void accept(IF i) {\n" + + " i.run();\n" + + " }\n" + + " public static void main(String[] args) throws ClassNotFoundException, IOException {\n" + + " Testbed t = new Testbed(\"IF\");\n" + + " Testbed t2 = new Testbed(\"FI\");\n" + + " IF i = t::foo;\n" + + " FI f = Testbed::foo;\n" + + " ByteArrayOutputStream debug=new ByteArrayOutputStream();\n" + + " try(ObjectOutputStream oo=new ObjectOutputStream(debug))\n" + + " {\n" + + " oo.writeObject(i);\n" + + " }\n" + + " try(ObjectInputStream oi=new ObjectInputStream(new ByteArrayInputStream(debug.toByteArray())))\n" + + " {\n" + + " IF x = (IF)oi.readObject();\n" + + " t.accept(x);\n" + + " }\n" + + " debug=new ByteArrayOutputStream();\n" + + " try(ObjectOutputStream oo=new ObjectOutputStream(debug))\n" + + " {\n" + + " oo.writeObject(f);\n" + + " }\n" + + " try(ObjectInputStream oi=new ObjectInputStream(new ByteArrayInputStream(debug.toByteArray())))\n" + + " {\n" + + " FI x = (FI)oi.readObject();\n" + + " t2.accept(x);\n" + + " }\n" + + " }\n" + + "}" + }, + "IF\n" + + "FI", + null,true, + new String[]{"-Ddummy"}); + } + public void testbug485333() { + this.runConformTest( + new String[]{ + "Test.java", + "import java.io.ByteArrayInputStream;\n" + + "import java.io.ByteArrayOutputStream;\n" + + "import java.io.ObjectInputStream;\n" + + "import java.io.ObjectOutputStream;\n" + + "import java.io.Serializable;\n" + + "interface Func extends Serializable {\n" + + " T get();\n" + + "}\n" + + "class Impl implements Serializable {\n" + + " int val = 0;\n" + + " public int next() {\n" + + " val += 1;\n" + + " return val;\n" + + " }\n" + + "}\n" + + "public class Test {\n" + + " final Impl impl = new Impl();\n" + + " final Func func = (Func & Cloneable)impl::next;\n" + + " public void test() throws Throwable {\n" + + " byte[] bytes = write(func);//25\n" + + " Func func = read(bytes);\n" + + " System.out.println(func.get());\n" + + " }\n" + + " public static void main(String[] args) throws Throwable {\n" + + " new Test().test();\n" + + "}\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " private static Func read(byte[] bytes) throws Exception {\n" + + " ByteArrayInputStream bis = new ByteArrayInputStream(bytes);\n" + + " try (ObjectInputStream ois = new ObjectInputStream(bis)) {\n" + + " return (Func) ois.readObject();\n" + + " }\n" + + " }\n" + + " private static byte[] write(Func func) throws Exception {\n" + + " ByteArrayOutputStream bos = new ByteArrayOutputStream();\n" + + " System.out.println(func.get());\n" + + " try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {\n" + + " oos.writeObject(func);//42\n" + + " }\n" + + " return bos.toByteArray();\n" + + " }\n" + + "}" + }, + "1\n" + + "2", + null,true, + new String[]{"-Ddummy"}); + } + public void testbug494487() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); + this.runConformTest( + new String[]{ + "Test.java", + "import java.io.IOException;\n" + + "import java.io.Serializable;\n" + + "public class Test {\n" + + " class AnException extends Exception {\n" + + " }\n" + + " class Asd {\n" + + " public Asd(String asd) { data = asd; }\n" + + " private final String data;\n" + + " @Override\n" + + " public String toString() {\n" + + " return data;\n" + + " }\n" + + " }\n" + + " public interface Test1 extends Serializable {\n" + + " void test() throws IOException;\n" + + " }\n" + + " public interface Test2 {\n" + + " void test() throws AnException;\n" + + " }\n" + + " public void test1( Test1 test ) {\n" + + " try {\n" + + " test.test();\n" + + " } catch( IOException e ) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " public void test2( Test2 test ) {\n" + + " try {\n" + + " test.test();\n" + + " } catch( AnException e ) {\n" + + " System.out.println( e );\n" + + " }\n" + + " }\n" + + " public void lambdas() {\n" + + " test1( () -> System.out.println( \"test a\" ) );\n" + + " test1( () -> System.out.println( \"test b\" ) );\n" + + " test2( () -> System.out.println( \"test c\" ) );\n" + + " test2( () -> System.out.println( \"test d\" ) );\n" + + " }\n" + + " public void print( CharSequence a, String b, long c ) {\n" + + " System.out.println( a );\n" + + " System.out.println( b );\n" + + " System.out.println( c );\n" + + " }\n" + + " public void filler() {\n" + + " System.out.println( \"Now we need to get this class file closer to 3000 bytes boundary\" );\n" + + " filler1();\n" + + " filler2();\n" + + " filler3();\n" + + " filler4();\n" + + " filler5();\n" + + " filler6();\n" + + " filler7();\n" + + " filler8();\n" + + " filler9();\n" + + " filler10();\n" + + " filler11();\n" + + " filler12();\n" + + " filler13();\n" + + " filler14();\n" + + " filler15();\n" + + " filler16();\n" + + " filler17();\n" + + " filler18();\n" + + " filler19();\n" + + " filler20();\n" + + " filler21();\n" + + " filler22();\n" + + " filler23();\n" + + " filler24();\n" + + " filler25();\n" + + " filler26();\n" + + " filler27();\n" + + " filler28();\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler28() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler27() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler26() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler25() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler24() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler23() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler22() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler21() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler20() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler19() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler18() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler17() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler16() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler15() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler14() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler13() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler12() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler11() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler10() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler9() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler8() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler7() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler6() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private void filler5() {\n" + + " print( c.toString(), d.toString(), System.currentTimeMillis() );\n" + + " }\n" + + " private void filler4() {\n" + + " print( a.toString(), b.toString(), System.currentTimeMillis() );\n" + + " }\n" + + " private void filler3() {\n" + + " print( \"a\", System.getenv( \"asd\" ), System.currentTimeMillis() );\n" + + " }\n" + + " private void filler2() {\n" + + " print( \"a\", System.lineSeparator(), System.currentTimeMillis() );\n" + + " }\n" + + " private void filler1() {\n" + + " print( \"a\", \"b\", System.currentTimeMillis() );\n" + + " }\n" + + " private final Asd a = new Asd(\"a\");\n" + + " private final Asd b = new Asd(\"b\");\n" + + " private final Asd c = new Asd(\"c\");\n" + + " private final Asd d = new Asd(\"d\");\n" + + "}\n" + }, + options); + } + public void testbug497879() { + this.runConformTest( + new String[]{ + "LambdaSerializationTest.java", + "import java.io.ByteArrayInputStream;\n" + + "import java.io.ByteArrayOutputStream;\n" + + "import java.io.IOException;\n" + + "import java.io.ObjectInputStream;\n" + + "import java.io.ObjectOutputStream;\n" + + "import java.io.Serializable;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Supplier;\n" + + "public class LambdaSerializationTest {\n" + + " interface SerializableSupplier extends Supplier, Serializable {}\n" + + " public static void constructorReferenceSerialization() throws IOException, ClassNotFoundException {\n" + + " SerializableSupplier> function = ArrayList::new; //Collections::emptyList;\n" + + " Object result = serializeDeserialize(function);\n" + + " Class[] infs = result.getClass().getInterfaces();\n" + + " for(int i = 0; i < infs.length; i++) {\n" + + " System.out.println(infs[i]);\n" + + " }\n" + + " }\n" + + " private static Object serializeDeserialize(Object obj) throws IOException, ClassNotFoundException {\n" + + " try (\n" + + " ByteArrayOutputStream buffer = new ByteArrayOutputStream(); //\n" + + " ObjectOutputStream output = new ObjectOutputStream(buffer)) {\n" + + " output.writeObject(obj);\n" + + " try (ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()))) {\n" + + " return input.readObject();\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " LambdaSerializationTest.constructorReferenceSerialization();\n" + + " } catch (ClassNotFoundException | IOException e) {\n" + + " // TODO Auto-generated catch block\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}" + }, + "interface LambdaSerializationTest$SerializableSupplier", + null,true, + new String[]{"-Ddummy"}); + } + public void testbug497879a() { + this.runConformTest( + new String[]{ + "LambdaSerializationTest.java", + "import java.io.ByteArrayInputStream;\n" + + "import java.io.ByteArrayOutputStream;\n" + + "import java.io.IOException;\n" + + "import java.io.ObjectInputStream;\n" + + "import java.io.ObjectOutputStream;\n" + + "import java.io.Serializable;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Supplier;\n" + + "public class LambdaSerializationTest {\n" + + " interface SerializableSupplier extends Supplier, Serializable {}\n" + + " static class Junk {\n" + + " private Junk() {}\n" + + " }\n" + + " public static void constructorReferenceSerialization() throws IOException, ClassNotFoundException {\n" + + " SerializableSupplier function = Junk::new;\n" + + " Object result = serializeDeserialize(function);\n" + + " Class[] infs = result.getClass().getInterfaces();\n" + + " for(int i = 0; i < infs.length; i++) {\n" + + " System.out.println(infs[i]);\n" + + " }\n" + + " }\n" + + " private static Object serializeDeserialize(Object obj) throws IOException, ClassNotFoundException {\n" + + " try (\n" + + " ByteArrayOutputStream buffer = new ByteArrayOutputStream(); //\n" + + " ObjectOutputStream output = new ObjectOutputStream(buffer)) {\n" + + " output.writeObject(obj);\n" + + " try (ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()))) {\n" + + " return input.readObject();\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " LambdaSerializationTest.constructorReferenceSerialization();\n" + + " } catch (ClassNotFoundException | IOException e) {\n" + + " // TODO Auto-generated catch block\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}" + }, + "interface LambdaSerializationTest$SerializableSupplier", + null,true, + new String[]{"-Ddummy"}); + } + public void testbug497879b() { + this.runConformTest( + new String[]{ + "LambdaSerializationTest.java", + "import java.io.ByteArrayInputStream;\n" + + "import java.io.ByteArrayOutputStream;\n" + + "import java.io.IOException;\n" + + "import java.io.ObjectInputStream;\n" + + "import java.io.ObjectOutputStream;\n" + + "import java.io.Serializable;\n" + + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "import java.util.function.Supplier;\n" + + "public class LambdaSerializationTest {\n" + + " interface SerializableSupplier extends Serializable {\n" + + " T get(int count);\n" + + " }\n" + + " public static void constructorReferenceSerialization() throws IOException, ClassNotFoundException {\n" + + " SerializableSupplier function = ArrayList[]::new;\n" + + " Object result = serializeDeserialize(function);\n" + + " Class[] infs = result.getClass().getInterfaces();\n" + + " for(int i = 0; i < infs.length; i++) {\n" + + " System.out.println(infs[i]);\n" + + " }\n" + + " }\n" + + " private static Object serializeDeserialize(Object obj) throws IOException, ClassNotFoundException {\n" + + " try (\n" + + " ByteArrayOutputStream buffer = new ByteArrayOutputStream(); //\n" + + " ObjectOutputStream output = new ObjectOutputStream(buffer)) {\n" + + " output.writeObject(obj);\n" + + " try (ObjectInputStream input = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()))) {\n" + + " return input.readObject();\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " LambdaSerializationTest.constructorReferenceSerialization();\n" + + " } catch (ClassNotFoundException | IOException e) {\n" + + " // TODO Auto-generated catch block\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}" + }, + "interface LambdaSerializationTest$SerializableSupplier", + null,true, + new String[]{"-Ddummy"}); + } + public void testbug503118() { + this.runConformTest( + new String[]{ + "lambdabug/App.java", + "package lambdabug;\n" + + "import java.io.ByteArrayInputStream;\n" + + "import java.io.ByteArrayOutputStream;\n" + + "import java.io.ObjectInputStream;\n" + + "import java.io.ObjectOutputStream;\n" + + "import java.io.Serializable;\n" + + "import java.util.function.Function;\n" + + "public class App {\n" + + " public static interface SerialFunction extends Function, Serializable {\n" + + " }\n" + + " public static interface TestInterface extends Serializable {\n" + + " public Integer method(Integer i);\n" + + " }\n" + + " public static class TestClass implements TestInterface {\n" + + " private static final long serialVersionUID = 1L;\n" + + " @Override\n" + + " public Integer method(Integer i) {\n" + + " return i;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " TestInterface testService = getService();\n" + + " SerialFunction sf = testService::method;\n" + + " ByteArrayOutputStream bos = new ByteArrayOutputStream();\n" + + " new ObjectOutputStream(bos).writeObject(sf);\n" + + " Object o = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())).readObject();\n" + + " System.out.println(o.getClass().getInterfaces()[0]);\n" + + " }\n" + + " private static TestInterface getService() {\n" + + " return new TestClass();\n" + + " }\n" + + "}\n" + }, + "interface lambdabug.App$SerialFunction", + null,true, + new String[]{"-Ddummy"}); + } + public void testbug507011() { + this.runConformTest( + new String[]{ + "VerifyErrorDerived.java", + "import java.io.Serializable;\n" + + "import java.util.function.Function;\n" + + "public class VerifyErrorDerived extends VerifyErrorBase {\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"hello world\");\n" + + " }\n" + + " public int derivedMethod(String param) {\n" + + " SerializableFunction f = super::baseMethod;\n" + + " return f.apply(param);\n" + + " }\n" + + "}\n" + + "interface SerializableFunction extends Function, Serializable {}", + "VerifyErrorBase.java", + "public class VerifyErrorBase {\n" + + " public int baseMethod(String param) {\n" + + " return 7;\n" + + " }\n" + + "}\n" + }, + "hello world", + null,true, + new String[]{"-Ddummy"}); + } + public void testbug509782() { + this.runConformTest( + new String[]{ + "compilertest/BaseType.java", + "package compilertest;\n" + + "import java.io.ByteArrayInputStream;\n" + + "import java.io.ByteArrayOutputStream;\n" + + "import java.io.ObjectInputStream;\n" + + "import java.io.ObjectOutputStream;\n" + + "import java.io.Serializable;\n" + + "import compilertest.sub.SubType;\n" + + "public class BaseType implements Serializable {\n" + + " protected void doSomething() {\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " SubType instance = new SubType();\n" + + " ByteArrayOutputStream bs = new ByteArrayOutputStream();\n" + + " ObjectOutputStream out = new ObjectOutputStream(bs);\n" + + " out.writeObject(instance);\n" + + " byte[] data = bs.toByteArray();\n" + + " ObjectInputStream in = new ObjectInputStream(\n" + + " new ByteArrayInputStream(data));\n" + + " in.readObject();\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}", + "compilertest/sub/SubType.java", + "package compilertest.sub;\n" + + "import java.io.Serializable;\n" + + "import compilertest.BaseType;\n" + + "public class SubType extends BaseType {\n" + + " Runnable task = (Runnable & Serializable) this::doSomething;\n" + + "}\n" + }, + "Done", + null,true, + new String[]{"-Ddummy"}); + } + // --- + + private void checkExpected(String expected, String actual) { + if (!expected.equals(actual)) { + printIt(actual); + } + assertEquals(expected,actual); + } + + /** + * Print a piece of text with the necessary extra quotes and newlines so that it can be cut/pasted into + * the test source file. + */ + private void printIt(String text) { + String quotedText = text; + if (!quotedText.startsWith("\"")) { + quotedText = "\""+quotedText.replaceAll("\n", "\\\\n\"+\n\""); + quotedText = quotedText.substring(0,quotedText.length()-3); + } + System.out.println(quotedText); + } + + /** + * Print the bootstrap methods attribute in a very similar fashion to javap for checking. + * Unlike javap the constant pool indexes are not included, to make the test a little less + * fragile. + */ + private String printBootstrapMethodsAttribute(String filepath) { + IClassFileReader cfr = ToolFactory.createDefaultClassFileReader(filepath, IClassFileReader.CLASSFILE_ATTRIBUTES); + BootstrapMethodsAttribute bootstrapMethodsAttribute = null; + IClassFileAttribute[] attrs = cfr.getAttributes(); + for (int i=0,max=attrs.length;i 0 ? null : new Object());\n" + + " try {\n" + + " foo(6, false);\n" + + " } catch(Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " X(Object o) {}\n" + + " int foo(int i, boolean b) {\n" + + " try {\n" + + " if (b) {\n" + + " return i;\n" + + " }\n" + + " return i + 1;\n" + + " } catch(Exception e) {\n" + + " return 5;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(2, false);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #14 (D)V\n" + + " // Stack: 5, Locals: 4\n" + + " X(double i);\n" + + " 0 aload_0 [this]\n" + + " 1 dload_1 [i]\n" + + " 2 dconst_0\n" + + " 3 dcmpl\n" + + " 4 ifle 11\n" + + " 7 aconst_null\n" + + " 8 goto 18\n" + + " 11 new java.lang.Object [3]\n" + + " 14 dup\n" + + " 15 invokespecial java.lang.Object() [8]\n" + + " 18 invokespecial X(java.lang.Object) [15]\n" + + " 21 aload_0 [this]\n" + + " 22 bipush 6\n" + + " 24 iconst_0\n" + + " 25 invokevirtual X.foo(int, boolean) : int [18]\n" + + " 28 pop\n" + + " 29 goto 37\n" + + " 32 astore_3 [e]\n" + + " 33 aload_3 [e]\n" + + " 34 invokevirtual java.lang.Exception.printStackTrace() : void [22]\n" + + " 37 return\n" + + " Exception Table:\n" + + " [pc: 21, pc: 29] -> 32 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 21, line: 6]\n" + + " [pc: 29, line: 7]\n" + + " [pc: 33, line: 8]\n" + + " [pc: 37, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 38] local: this index: 0 type: X\n" + + " [pc: 0, pc: 38] local: i index: 1 type: double\n" + + " [pc: 33, pc: 37] local: e index: 3 type: java.lang.Exception\n" + + " Stack map table: number of frames 4\n" + + " [pc: 11, same_locals_1_stack_item, stack: {uninitialized_this}]\n" + + " [pc: 18, full, stack: {uninitialized_this, java.lang.Object}, locals: {uninitialized_this, double}]\n" + + " [pc: 32, full, stack: {java.lang.Exception}, locals: {X, double}]\n" + + " [pc: 37, same]\n" + + " \n" + + " // Method descriptor #17 (Ljava/lang/Object;)V\n" + + " // Stack: 1, Locals: 2\n" + + " X(java.lang.Object o);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " [pc: 0, pc: 5] local: o index: 1 type: java.lang.Object\n" + + " \n" + + " // Method descriptor #21 (IZ)I\n" + + " // Stack: 2, Locals: 4\n" + + " int foo(int i, boolean b);\n" + + " 0 iload_2 [b]\n" + + " 1 ifeq 6\n" + + " 4 iload_1 [i]\n" + + " 5 ireturn\n" + + " 6 iload_1 [i]\n" + + " 7 iconst_1\n" + + " 8 iadd\n" + + " 9 ireturn\n" + + " 10 astore_3 [e]\n" + + " 11 iconst_5\n" + + " 12 ireturn\n" + + " Exception Table:\n" + + " [pc: 0, pc: 5] -> 10 when : java.lang.Exception\n" + + " [pc: 6, pc: 9] -> 10 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 4, line: 15]\n" + + " [pc: 6, line: 17]\n" + + " [pc: 10, line: 18]\n" + + " [pc: 11, line: 19]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 13] local: this index: 0 type: X\n" + + " [pc: 0, pc: 13] local: i index: 1 type: int\n" + + " [pc: 0, pc: 13] local: b index: 2 type: boolean\n" + + " [pc: 11, pc: 13] local: e index: 3 type: java.lang.Exception\n" + + " Stack map table: number of frames 2\n" + + " [pc: 6, same]\n" + + " [pc: 10, same_locals_1_stack_item, stack: {java.lang.Exception}]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + public void test002() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(double d, boolean b) {\n" + + " double i;\n" + + " try {\n" + + " i = 0;\n" + + " i++;\n" + + " int j = (int) (i - 1);\n" + + " if (b) {\n" + + " double d1 = 0;\n" + + " if (!b) {\n" + + " d1 = 0;\n" + + " }\n" + + " double d2 = d + d1;\n" + + " }\n" + + " bar(j);\n" + + " } catch(NullPointerException e) {\n" + + " i = 2;\n" + + " } finally {\n" + + " i = 1;\n" + + " }\n" + + " long j = (long) (i + 1);\n" + + " int k = (int) j;\n" + + " k += j;\n" + + " }\n" + + " public static void bar(int i) {}\n" + + " public static void main(String[] args) {\n" + + " foo(0, true);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 (DZ)V\n" + + " // Stack: 4, Locals: 11\n" + + " public static void foo(double d, boolean b);\n" + + " 0 dconst_0\n" + + " 1 dstore_3 [i]\n" + + " 2 dload_3 [i]\n" + + " 3 dconst_1\n" + + " 4 dadd\n" + + " 5 dstore_3 [i]\n" + + " 6 dload_3 [i]\n" + + " 7 dconst_1\n" + + " 8 dsub\n" + + " 9 d2i\n" + + " 10 istore 5 [j]\n" + + " 12 iload_2 [b]\n" + + " 13 ifeq 32\n" + + " 16 dconst_0\n" + + " 17 dstore 6 [d1]\n" + + " 19 iload_2 [b]\n" + + " 20 ifne 26\n" + + " 23 dconst_0\n" + + " 24 dstore 6 [d1]\n" + + " 26 dload_0 [d]\n" + + " 27 dload 6 [d1]\n" + + " 29 dadd\n" + + " 30 dstore 8\n" + + " 32 iload 5 [j]\n" + + " 34 invokestatic X.bar(int) : void [16]\n" + + " 37 goto 58\n" + + " 40 astore 5 [e]\n" + + " 42 ldc2_w [20]\n" + + " 45 dstore_3 [i]\n" + + " 46 dconst_1\n" + + " 47 dstore_3 [i]\n" + + " 48 goto 60\n" + + " 51 astore 10\n" + + " 53 dconst_1\n" + + " 54 dstore_3 [i]\n" + + " 55 aload 10\n" + + " 57 athrow\n" + + " 58 dconst_1\n" + + " 59 dstore_3 [i]\n" + + " 60 dload_3 [i]\n" + + " 61 dconst_1\n" + + " 62 dadd\n" + + " 63 d2l\n" + + " 64 lstore 5 [j]\n" + + " 66 lload 5 [j]\n" + + " 68 l2i\n" + + " 69 istore 7 [k]\n" + + " 71 iload 7 [k]\n" + + " 73 i2l\n" + + " 74 lload 5 [j]\n" + + " 76 ladd\n" + + " 77 l2i\n" + + " 78 istore 7 [k]\n" + + " 80 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 37] -> 40 when : java.lang.NullPointerException\n" + + " [pc: 0, pc: 46] -> 51 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 2, line: 6]\n" + + " [pc: 6, line: 7]\n" + + " [pc: 12, line: 8]\n" + + " [pc: 16, line: 9]\n" + + " [pc: 19, line: 10]\n" + + " [pc: 23, line: 11]\n" + + " [pc: 26, line: 13]\n" + + " [pc: 32, line: 15]\n" + + " [pc: 37, line: 16]\n" + + " [pc: 42, line: 17]\n" + + " [pc: 46, line: 19]\n" + + " [pc: 51, line: 18]\n" + + " [pc: 53, line: 19]\n" + + " [pc: 55, line: 20]\n" + + " [pc: 58, line: 19]\n" + + " [pc: 60, line: 21]\n" + + " [pc: 66, line: 22]\n" + + " [pc: 71, line: 23]\n" + + " [pc: 80, line: 24]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 81] local: d index: 0 type: double\n" + + " [pc: 0, pc: 81] local: b index: 2 type: boolean\n" + + " [pc: 2, pc: 40] local: i index: 3 type: double\n" + + " [pc: 46, pc: 51] local: i index: 3 type: double\n" + + " [pc: 55, pc: 81] local: i index: 3 type: double\n" + + " [pc: 12, pc: 37] local: j index: 5 type: int\n" + + " [pc: 19, pc: 32] local: d1 index: 6 type: double\n" + + " [pc: 42, pc: 46] local: e index: 5 type: java.lang.NullPointerException\n" + + " [pc: 66, pc: 81] local: j index: 5 type: long\n" + + " [pc: 71, pc: 81] local: k index: 7 type: int\n" + + " Stack map table: number of frames 6\n" + + " [pc: 26, append: {double, int, double}]\n" + + " [pc: 32, chop 1 local(s)]\n" + + " [pc: 40, full, stack: {java.lang.NullPointerException}, locals: {double, int}]\n" + + " [pc: 51, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 58, append: {double}]\n" + + " [pc: 60, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + public void test003() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(boolean b) {\n" + + " int i = 0;\n" + + " try {\n" + + " System.out.println(\"FINALLY\");\n" + + " i++;\n" + + " int j = i -1;\n" + + " bar(j);\n" + + " } catch(NullPointerException e) {\n" + + " e.printStackTrace();\n" + + " } finally {\n" + + " System.out.println(\"FINALLY\");\n" + + " }\n" + + " }\n" + + " public static void bar(int i) {}\n" + + " \n" + + " public static void main(String[] args) {\n" + + " foo(true);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "FINALLY\n" + + "FINALLY\n" + + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 (Z)V\n" + + " // Stack: 2, Locals: 4\n" + + " public static void foo(boolean b);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 5 ldc [22]\n" + + " 7 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 10 iinc 1 1 [i]\n" + + " 13 iload_1 [i]\n" + + " 14 iconst_1\n" + + " 15 isub\n" + + " 16 istore_2 [j]\n" + + " 17 iload_2 [j]\n" + + " 18 invokestatic X.bar(int) : void [30]\n" + + " 21 goto 51\n" + + " 24 astore_2 [e]\n" + + " 25 aload_2 [e]\n" + + " 26 invokevirtual java.lang.NullPointerException.printStackTrace() : void [34]\n" + + " 29 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 32 ldc [22]\n" + + " 34 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 37 goto 59\n" + + " 40 astore_3\n" + + " 41 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 44 ldc [22]\n" + + " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 49 aload_3\n" + + " 50 athrow\n" + + " 51 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 54 ldc [22]\n" + + " 56 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 59 return\n" + + " Exception Table:\n" + + " [pc: 2, pc: 21] -> 24 when : java.lang.NullPointerException\n" + + " [pc: 2, pc: 29] -> 40 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 10, line: 6]\n" + + " [pc: 13, line: 7]\n" + + " [pc: 17, line: 8]\n" + + " [pc: 21, line: 9]\n" + + " [pc: 25, line: 10]\n" + + " [pc: 29, line: 12]\n" + + " [pc: 40, line: 11]\n" + + " [pc: 41, line: 12]\n" + + " [pc: 49, line: 13]\n" + + " [pc: 51, line: 12]\n" + + " [pc: 59, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 60] local: b index: 0 type: boolean\n" + + " [pc: 2, pc: 60] local: i index: 1 type: int\n" + + " [pc: 17, pc: 21] local: j index: 2 type: int\n" + + " [pc: 25, pc: 29] local: e index: 2 type: java.lang.NullPointerException\n" + + " Stack map table: number of frames 4\n" + + " [pc: 24, full, stack: {java.lang.NullPointerException}, locals: {int, int}]\n" + + " [pc: 40, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 51, same]\n" + + " [pc: 59, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test004() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(boolean b) {\n" + + " C c;\n" + + " if (b) {\n" + + " c = new C1();\n" + + " } else {\n" + + " c = new C2();\n" + + " }\n" + + " System.out.println();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(true);\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "class C {\n" + + " void foo() {}\n" + + "}\n" + + "class C1 extends C {\n" + + "}\n" + + "class C2 extends C {\n" + + "}", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 (Z)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void foo(boolean b);\n" + + " 0 iload_0 [b]\n" + + " 1 ifeq 15\n" + + " 4 new C1 [16]\n" + + " 7 dup\n" + + " 8 invokespecial C1() [18]\n" + + " 11 astore_1 [c]\n" + + " 12 goto 23\n" + + " 15 new C2 [19]\n" + + " 18 dup\n" + + " 19 invokespecial C2() [21]\n" + + " 22 astore_1 [c]\n" + + " 23 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 26 invokevirtual java.io.PrintStream.println() : void [28]\n" + + " 29 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 12, line: 6]\n" + + " [pc: 15, line: 7]\n" + + " [pc: 23, line: 9]\n" + + " [pc: 29, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 30] local: b index: 0 type: boolean\n" + + " [pc: 12, pc: 15] local: c index: 1 type: C\n" + + " [pc: 23, pc: 30] local: c index: 1 type: C\n" + + " Stack map table: number of frames 2\n" + + " [pc: 15, same]\n" + + " [pc: 23, append: {C}]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + public void test005() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " int i = 0, j, k, l;\n" + + " boolean b;\n" + + " if (i == 0 && (j = ++i) > 0)\n" + + " i += j;\n" + + " while (true) {\n" + + " k = 3;\n" + + " break;\n" + + " } \n" + + " i -= k;\n" + + " b = false && (i = l) > 0;\n" + + " if (i > 0)\n" + + " l = i;\n" + + " else\n" + + " l = k;\n" + + " j = l;\n" + + " if (i != -1 || j != 3 || k != 3 || l != 3)\n" + + " System.out.println(\"FAILED\");\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 6\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 iload_1 [i]\n" + + " 3 ifne 19\n" + + " 6 iinc 1 1 [i]\n" + + " 9 iload_1 [i]\n" + + " 10 dup\n" + + " 11 istore_2 [j]\n" + + " 12 ifle 19\n" + + " 15 iload_1 [i]\n" + + " 16 iload_2 [j]\n" + + " 17 iadd\n" + + " 18 istore_1 [i]\n" + + " 19 iconst_3\n" + + " 20 istore_3 [k]\n" + + " 21 iload_1 [i]\n" + + " 22 iload_3 [k]\n" + + " 23 isub\n" + + " 24 istore_1 [i]\n" + + " 25 iconst_0\n" + + " 26 istore 5 [b]\n" + + " 28 iload_1 [i]\n" + + " 29 ifle 38\n" + + " 32 iload_1 [i]\n" + + " 33 istore 4 [l]\n" + + " 35 goto 41\n" + + " 38 iload_3 [k]\n" + + " 39 istore 4 [l]\n" + + " 41 iload 4 [l]\n" + + " 43 istore_2 [j]\n" + + " 44 iload_1 [i]\n" + + " 45 iconst_m1\n" + + " 46 if_icmpne 65\n" + + " 49 iload_2 [j]\n" + + " 50 iconst_3\n" + + " 51 if_icmpne 65\n" + + " 54 iload_3 [k]\n" + + " 55 iconst_3\n" + + " 56 if_icmpne 65\n" + + " 59 iload 4 [l]\n" + + " 61 iconst_3\n" + + " 62 if_icmpeq 73\n" + + " 65 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 68 ldc [22]\n" + + " 70 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 73 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 76 ldc [30]\n" + + " 78 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 81 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 15, line: 6]\n" + + " [pc: 19, line: 8]\n" + + " [pc: 21, line: 9]\n" + + " [pc: 22, line: 11]\n" + + " [pc: 25, line: 12]\n" + + " [pc: 28, line: 13]\n" + + " [pc: 32, line: 14]\n" + + " [pc: 38, line: 16]\n" + + " [pc: 41, line: 17]\n" + + " [pc: 44, line: 18]\n" + + " [pc: 65, line: 19]\n" + + " [pc: 73, line: 20]\n" + + " [pc: 81, line: 21]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 82] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 82] local: i index: 1 type: int\n" + + " [pc: 12, pc: 19] local: j index: 2 type: int\n" + + " [pc: 44, pc: 82] local: j index: 2 type: int\n" + + " [pc: 21, pc: 82] local: k index: 3 type: int\n" + + " [pc: 35, pc: 38] local: l index: 4 type: int\n" + + " [pc: 41, pc: 82] local: l index: 4 type: int\n" + + " [pc: 28, pc: 82] local: b index: 5 type: boolean\n" + + " Stack map table: number of frames 5\n" + + " [pc: 19, append: {int}]\n" + + " [pc: 38, full, stack: {}, locals: {java.lang.String[], int, _, int, _, int}]\n" + + " [pc: 41, full, stack: {}, locals: {java.lang.String[], int, _, int, int, int}]\n" + + " [pc: 65, full, stack: {}, locals: {java.lang.String[], int, int, int, int, int}]\n" + + " [pc: 73, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test006() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo (int n) {\n" + + " synchronized (this) {\n" + + " switch (n) {\n" + + " case 1:\n" + + " throw new NullPointerException();\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " try {\n" + + " new X().foo(1);\n" + + " } catch(Exception e) {\n" + + " System.out.println(\"SUCCESS\"); \n" + + " }\n" + + " } \n" + + "}", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 (I)V\n" + + " // Stack: 2, Locals: 3\n" + + " void foo(int n);\n" + + " 0 aload_0 [this]\n" + + " 1 dup\n" + + " 2 astore_2\n" + + " 3 monitorenter\n" + + " 4 iload_1 [n]\n" + + " 5 tableswitch default: 32\n" + + " case 1: 24\n" + + " 24 new java.lang.NullPointerException [16]\n" + + " 27 dup\n" + + " 28 invokespecial java.lang.NullPointerException() [18]\n" + + " 31 athrow\n" + + " 32 aload_2\n" + + " 33 monitorexit\n" + + " 34 goto 40\n" + + " 37 aload_2\n" + + " 38 monitorexit\n" + + " 39 athrow\n" + + " 40 return\n" + + " Exception Table:\n" + + " [pc: 4, pc: 34] -> 37 when : any\n" + + " [pc: 37, pc: 39] -> 37 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 24, line: 6]\n" + + " [pc: 32, line: 3]\n" + + " [pc: 40, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 41] local: this index: 0 type: X\n" + + " [pc: 0, pc: 41] local: n index: 1 type: int\n" + + " Stack map table: number of frames 4\n" + + " [pc: 24, append: {X}]\n" + + " [pc: 32, same]\n" + + " [pc: 37, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 40, chop 1 local(s)]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test007() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " StringBuffer foo2(boolean b) {\n" + + " System.out.println(\"foo2\");\n" + + " return new StringBuffer(b ? \"true\" : \"false\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 (Z)Ljava/lang/StringBuffer;\n" + + " // Stack: 3, Locals: 2\n" + + " java.lang.StringBuffer foo2(boolean b);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 ldc [22]\n" + + " 5 invokevirtual java.io.PrintStream.println(java.lang.String) : void [23]\n" + + " 8 new java.lang.StringBuffer [29]\n" + + " 11 dup\n" + + " 12 iload_1 [b]\n" + + " 13 ifeq 21\n" + + " 16 ldc [31]\n" + + " 18 goto 23\n" + + " 21 ldc [33]\n" + + " 23 invokespecial java.lang.StringBuffer(java.lang.String) [35]\n" + + " 26 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 8, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 27] local: this index: 0 type: X\n" + + " [pc: 0, pc: 27] local: b index: 1 type: boolean\n" + + " Stack map table: number of frames 2\n" + + " [pc: 21, full, stack: {uninitialized(8), uninitialized(8)}, locals: {X, int}]\n" + + " [pc: 23, full, stack: {uninitialized(8), uninitialized(8), java.lang.String}, locals: {X, int}]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=141252 + public void test008() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int foo = 0;\n" + + " String bar = \"zero\";\n" + + " System.out.println((foo != 0) ? foo : bar);\n" + + " }\n" + + " > void foo(T foo) {\n" + + " T bar = null;\n" + + " System.out.println((foo != null) ? foo : bar);\n" + + " } \n" + + "}\n", + }, + "zero"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [foo]\n" + + " 2 ldc [16]\n" + + " 4 astore_2 [bar]\n" + + " 5 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + + " 8 iload_1 [foo]\n" + + " 9 ifeq 19\n" + + " 12 iload_1 [foo]\n" + + " 13 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [24]\n" + + " 16 goto 20\n" + + " 19 aload_2 [bar]\n" + + " 20 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [30]\n" + + " 23 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 4]\n" + + " [pc: 5, line: 5]\n" + + " [pc: 23, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 24] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 24] local: foo index: 1 type: int\n" + + " [pc: 5, pc: 24] local: bar index: 2 type: java.lang.String\n" + + " Stack map table: number of frames 2\n" + + " [pc: 19, full, stack: {java.io.PrintStream}, locals: {java.lang.String[], int, java.lang.String}]\n" + + " [pc: 20, full, stack: {java.io.PrintStream, java.lang.Comparable}, locals: {java.lang.String[], int, java.lang.String}]\n" + + " \n" + + " // Method descriptor #48 (Ljava/lang/Comparable;)V\n" + + " // Signature: ;>(TT;)V\n" + + " // Stack: 2, Locals: 3\n" + + " void foo(java.lang.Comparable foo);\n" + + " 0 aconst_null\n" + + " 1 astore_2 [bar]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [18]\n" + + " 5 aload_1 [foo]\n" + + " 6 ifnull 13\n" + + " 9 aload_1 [foo]\n" + + " 10 goto 14\n" + + " 13 aload_2 [bar]\n" + + " 14 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [30]\n" + + " 17 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 2, line: 9]\n" + + " [pc: 17, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 18] local: this index: 0 type: X\n" + + " [pc: 0, pc: 18] local: foo index: 1 type: java.lang.Comparable\n" + + " [pc: 2, pc: 18] local: bar index: 2 type: java.lang.Comparable\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 18] local: foo index: 1 type: T\n" + + " [pc: 2, pc: 18] local: bar index: 2 type: T\n" + + " Stack map table: number of frames 2\n" + + " [pc: 13, full, stack: {java.io.PrintStream}, locals: {X, java.lang.Comparable, java.lang.Comparable}]\n" + + " [pc: 14, full, stack: {java.io.PrintStream, java.lang.Comparable}, locals: {X, java.lang.Comparable, java.lang.Comparable}]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test009() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String s;\n" + + " X() {\n" + + " int i = 0;\n" + + " if (s == null) {\n" + + " System.out.print(\"PASSED\");\n" + + " } else {\n" + + " System.out.print(\"FAILED\");\n" + + " }\n" + + " System.out.print(\"DONE\" + i);\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " new X();\n" + + " }\n" + + "}", + }, + "PASSEDDONE0"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #8 ()V\n" + + " // Stack: 4, Locals: 2\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 iconst_0\n" + + " 5 istore_1 [i]\n" + + " 6 aload_0 [this]\n" + + " 7 getfield X.s : java.lang.String [12]\n" + + " 10 ifnonnull 24\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [14]\n" + + " 16 ldc [20]\n" + + " 18 invokevirtual java.io.PrintStream.print(java.lang.String) : void [22]\n" + + " 21 goto 32\n" + + " 24 getstatic java.lang.System.out : java.io.PrintStream [14]\n" + + " 27 ldc [28]\n" + + " 29 invokevirtual java.io.PrintStream.print(java.lang.String) : void [22]\n" + + " 32 getstatic java.lang.System.out : java.io.PrintStream [14]\n" + + " 35 new java.lang.StringBuilder [30]\n" + + " 38 dup\n" + + " 39 ldc [32]\n" + + " 41 invokespecial java.lang.StringBuilder(java.lang.String) [34]\n" + + " 44 iload_1 [i]\n" + + " 45 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [36]\n" + + " 48 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [40]\n" + + " 51 invokevirtual java.io.PrintStream.print(java.lang.String) : void [22]\n" + + " 54 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 6, line: 5]\n" + + " [pc: 13, line: 6]\n" + + " [pc: 21, line: 7]\n" + + " [pc: 24, line: 8]\n" + + " [pc: 32, line: 10]\n" + + " [pc: 54, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 55] local: this index: 0 type: X\n" + + " [pc: 6, pc: 55] local: i index: 1 type: int\n" + + " Stack map table: number of frames 2\n" + + " [pc: 24, full, stack: {}, locals: {X, int}]\n" + + " [pc: 32, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test010() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int[] tab = new int[0];\n" + + " Object o = tab;\n" + + " Object o1 = null;\n" + + " if (tab.length == 0) {\n" + + " System.out.println(tab.getClass());\n" + + " }\n" + + " o1 = tab.clone();\n" + + " }\n" + + "}", + }, + "class [I"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 newarray int [10]\n" + + " 3 astore_1 [tab]\n" + + " 4 aload_1 [tab]\n" + + " 5 astore_2 [o]\n" + + " 6 aconst_null\n" + + " 7 astore_3 [o1]\n" + + " 8 aload_1 [tab]\n" + + " 9 arraylength\n" + + " 10 ifne 23\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 16 aload_1 [tab]\n" + + " 17 invokevirtual java.lang.Object.getClass() : java.lang.Class [22]\n" + + " 20 invokevirtual java.io.PrintStream.println(java.lang.Object) : void [26]\n" + + " 23 aload_1 [tab]\n" + + " 24 invokevirtual int[].clone() : java.lang.Object [32]\n" + + " 27 astore_3 [o1]\n" + + " 28 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 6, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 13, line: 7]\n" + + " [pc: 23, line: 9]\n" + + " [pc: 28, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 29] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 4, pc: 29] local: tab index: 1 type: int[]\n" + + " [pc: 6, pc: 29] local: o index: 2 type: java.lang.Object\n" + + " [pc: 8, pc: 29] local: o1 index: 3 type: java.lang.Object\n" + + " Stack map table: number of frames 1\n" + + " [pc: 23, append: {int[], java.lang.Object, java.lang.Object}]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test011() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Object o;\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X x;\n" + + " for (int i = 0; i < 10; i++) {\n" + + " if (i < 90) {\n" + + " x = new X();\n" + + " if (i > 4) {\n" + + " x.o = new Object();\n" + + " } else {\n" + + " x.o = \"0\";\n" + + " }\n" + + " switch (i) {\n" + + " case 0:\n" + + " if (x.o instanceof String) {\n" + + " System.out.print(\"1\");\n" + + " }\n" + + " break;\n" + + " default: {\n" + + " Object diff = x.o;\n" + + " if (diff != null) {\n" + + " System.out.print(\"2\");\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + "1222222222"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #17 ([Ljava/lang/String;)V\n" + + " // Stack: 3, Locals: 4\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_2 [i]\n" + + " 2 goto 105\n" + + " 5 iload_2 [i]\n" + + " 6 bipush 90\n" + + " 8 if_icmpge 102\n" + + " 11 new X [1]\n" + + " 14 dup\n" + + " 15 invokespecial X() [18]\n" + + " 18 astore_1 [x]\n" + + " 19 iload_2 [i]\n" + + " 20 iconst_4\n" + + " 21 if_icmple 38\n" + + " 24 aload_1 [x]\n" + + " 25 new java.lang.Object [3]\n" + + " 28 dup\n" + + " 29 invokespecial java.lang.Object() [10]\n" + + " 32 putfield X.o : java.lang.Object [19]\n" + + " 35 goto 44\n" + + " 38 aload_1 [x]\n" + + " 39 ldc [21]\n" + + " 41 putfield X.o : java.lang.Object [19]\n" + + " 44 iload_2 [i]\n" + + " 45 tableswitch default: 85\n" + + " case 0: 64\n" + + " 64 aload_1 [x]\n" + + " 65 getfield X.o : java.lang.Object [19]\n" + + " 68 instanceof java.lang.String [23]\n" + + " 71 ifeq 102\n" + + " 74 getstatic java.lang.System.out : java.io.PrintStream [25]\n" + + " 77 ldc [31]\n" + + " 79 invokevirtual java.io.PrintStream.print(java.lang.String) : void [33]\n" + + " 82 goto 102\n" + + " 85 aload_1 [x]\n" + + " 86 getfield X.o : java.lang.Object [19]\n" + + " 89 astore_3 [diff]\n" + + " 90 aload_3 [diff]\n" + + " 91 ifnull 102\n" + + " 94 getstatic java.lang.System.out : java.io.PrintStream [25]\n" + + " 97 ldc [39]\n" + + " 99 invokevirtual java.io.PrintStream.print(java.lang.String) : void [33]\n" + + " 102 iinc 2 1 [i]\n" + + " 105 iload_2 [i]\n" + + " 106 bipush 10\n" + + " 108 if_icmplt 5\n" + + " 111 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 5, line: 7]\n" + + " [pc: 11, line: 8]\n" + + " [pc: 19, line: 9]\n" + + " [pc: 24, line: 10]\n" + + " [pc: 35, line: 11]\n" + + " [pc: 38, line: 12]\n" + + " [pc: 44, line: 14]\n" + + " [pc: 64, line: 16]\n" + + " [pc: 74, line: 17]\n" + + " [pc: 82, line: 19]\n" + + " [pc: 85, line: 21]\n" + + " [pc: 90, line: 22]\n" + + " [pc: 94, line: 23]\n" + + " [pc: 102, line: 6]\n" + + " [pc: 111, line: 29]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 112] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 19, pc: 102] local: x index: 1 type: X\n" + + " [pc: 2, pc: 111] local: i index: 2 type: int\n" + + " [pc: 90, pc: 102] local: diff index: 3 type: java.lang.Object\n" + + " Stack map table: number of frames 7\n" + + " [pc: 5, full, stack: {}, locals: {java.lang.String[], _, int}]\n" + + " [pc: 38, full, stack: {}, locals: {java.lang.String[], X, int}]\n" + + " [pc: 44, same]\n" + + " [pc: 64, same]\n" + + " [pc: 85, same]\n" + + " [pc: 102, full, stack: {}, locals: {java.lang.String[], _, int}]\n" + + " [pc: 105, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test012() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X x;\n" + + " Object o;\n" + + " for (int i = 0; i < 10; i++) {\n" + + " if (i < 90) {\n" + + " x = new X();\n" + + " if (i > 4) {\n" + + " o = new Object();\n" + + " } else {\n" + + " o = null;\n" + + " }\n" + + " switch (i) {\n" + + " case 0:\n" + + " if (o instanceof String) {\n" + + " System.out.print(\"1\");\n" + + " return;\n" + + " } else {\n" + + " break;\n" + + " }\n" + + " default: {\n" + + " Object diff = o;\n" + + " if (diff != null) {\n" + + " System.out.print(\"2\");\n" + + " }\n" + + " break;\n" + + " }\n" + + " }\n" + + " System.out.print(\"3\");\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + "333332323232323"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 5\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_0\n" + + " 1 istore_3 [i]\n" + + " 2 goto 99\n" + + " 5 iload_3 [i]\n" + + " 6 bipush 90\n" + + " 8 if_icmpge 96\n" + + " 11 new X [1]\n" + + " 14 dup\n" + + " 15 invokespecial X() [16]\n" + + " 18 astore_1 [x]\n" + + " 19 iload_3 [i]\n" + + " 20 iconst_4\n" + + " 21 if_icmple 35\n" + + " 24 new java.lang.Object [3]\n" + + " 27 dup\n" + + " 28 invokespecial java.lang.Object() [8]\n" + + " 31 astore_2 [o]\n" + + " 32 goto 37\n" + + " 35 aconst_null\n" + + " 36 astore_2 [o]\n" + + " 37 iload_3 [i]\n" + + " 38 tableswitch default: 72\n" + + " case 0: 56\n" + + " 56 aload_2 [o]\n" + + " 57 instanceof java.lang.String [17]\n" + + " 60 ifeq 88\n" + + " 63 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 66 ldc [25]\n" + + " 68 invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + + " 71 return\n" + + " 72 aload_2 [o]\n" + + " 73 astore 4 [diff]\n" + + " 75 aload 4 [diff]\n" + + " 77 ifnull 88\n" + + " 80 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 83 ldc [33]\n" + + " 85 invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + + " 88 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 91 ldc [35]\n" + + " 93 invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + + " 96 iinc 3 1 [i]\n" + + " 99 iload_3 [i]\n" + + " 100 bipush 10\n" + + " 102 if_icmplt 5\n" + + " 105 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 5, line: 6]\n" + + " [pc: 11, line: 7]\n" + + " [pc: 19, line: 8]\n" + + " [pc: 24, line: 9]\n" + + " [pc: 32, line: 10]\n" + + " [pc: 35, line: 11]\n" + + " [pc: 37, line: 13]\n" + + " [pc: 56, line: 15]\n" + + " [pc: 63, line: 16]\n" + + " [pc: 71, line: 17]\n" + + " [pc: 72, line: 22]\n" + + " [pc: 75, line: 23]\n" + + " [pc: 80, line: 24]\n" + + " [pc: 88, line: 29]\n" + + " [pc: 96, line: 5]\n" + + " [pc: 105, line: 32]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 106] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 19, pc: 96] local: x index: 1 type: X\n" + + " [pc: 32, pc: 35] local: o index: 2 type: java.lang.Object\n" + + " [pc: 37, pc: 96] local: o index: 2 type: java.lang.Object\n" + + " [pc: 2, pc: 105] local: i index: 3 type: int\n" + + " [pc: 75, pc: 88] local: diff index: 4 type: java.lang.Object\n" + + " Stack map table: number of frames 8\n" + + " [pc: 5, full, stack: {}, locals: {java.lang.String[], _, _, int}]\n" + + " [pc: 35, full, stack: {}, locals: {java.lang.String[], X, _, int}]\n" + + " [pc: 37, full, stack: {}, locals: {java.lang.String[], X, java.lang.Object, int}]\n" + + " [pc: 56, same]\n" + + " [pc: 72, same]\n" + + " [pc: 88, same]\n" + + " [pc: 96, full, stack: {}, locals: {java.lang.String[], _, _, int}]\n" + + " [pc: 99, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test013() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " void foo() {\n" + + " synchronized (this) {\n" + + " int n=0;\n" + + " try {\n" + + " Thread.sleep(n); \n" + + " } catch (Exception e ) {\n" + + " }\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {}\n" + + "}", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 4\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 dup\n" + + " 2 astore_1\n" + + " 3 monitorenter\n" + + " 4 iconst_0\n" + + " 5 istore_2 [n]\n" + + " 6 iload_2 [n]\n" + + " 7 i2l\n" + + " 8 invokestatic java.lang.Thread.sleep(long) : void [15]\n" + + " 11 goto 15\n" + + " 14 astore_3\n" + + " 15 aload_1\n" + + " 16 monitorexit\n" + + " 17 goto 23\n" + + " 20 aload_1\n" + + " 21 monitorexit\n" + + " 22 athrow\n" + + " 23 return\n" + + " Exception Table:\n" + + " [pc: 6, pc: 11] -> 14 when : java.lang.Exception\n" + + " [pc: 4, pc: 17] -> 20 when : any\n" + + " [pc: 20, pc: 22] -> 20 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 6, line: 7]\n" + + " [pc: 11, line: 8]\n" + + " [pc: 15, line: 4]\n" + + " [pc: 23, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 24] local: this index: 0 type: X\n" + + " [pc: 6, pc: 15] local: n index: 2 type: int\n" + + " Stack map table: number of frames 4\n" + + " [pc: 14, full, stack: {java.lang.Exception}, locals: {X, X, int}]\n" + + " [pc: 15, chop 1 local(s)]\n" + + " [pc: 20, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 23, chop 1 local(s)]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test014() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X() {\n" + + " final int i;\n" + + " synchronized (this) {\n" + + " i = 8;\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {}\n" + + "}", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 3\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 aload_0 [this]\n" + + " 5 dup\n" + + " 6 astore_2\n" + + " 7 monitorenter\n" + + " 8 bipush 8\n" + + " 10 istore_1 [i]\n" + + " 11 aload_2\n" + + " 12 monitorexit\n" + + " 13 goto 19\n" + + " 16 aload_2\n" + + " 17 monitorexit\n" + + " 18 athrow\n" + + " 19 return\n" + + " Exception Table:\n" + + " [pc: 8, pc: 13] -> 16 when : any\n" + + " [pc: 16, pc: 18] -> 16 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 2]\n" + + " [pc: 4, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 11, line: 4]\n" + + " [pc: 19, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 20] local: this index: 0 type: X\n" + + " [pc: 11, pc: 16] local: i index: 1 type: int\n" + + " [pc: 19, pc: 20] local: i index: 1 type: int\n" + + " Stack map table: number of frames 2\n" + + " [pc: 16, full, stack: {java.lang.Throwable}, locals: {X, _, X}]\n" + + " [pc: 19, full, stack: {}, locals: {X, int}]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test015() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " a1(1), a2(5), a3(11);\n" + + " int value;\n" + + " X(int a) {\n" + + " value = a;\n" + + " }\n" + + " int value () {\n" + + " return value;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " }\n" + + " public static int foo() {\n" + + " int val;\n" + + " int res = 0;\n" + + " int n = 0;\n" + + " X[] vals = X.values();\n" + + " for (int i = 0, max = vals.length; i < max; i++) {\n" + + " X e = vals[i];\n" + + " if ( n == 1) {\n" + + " continue;\n" + + " }\n" + + " val = e.value();\n" + + " System.out.println(val);\n" + + " }\n" + + " return res;\n" + + " }\n" + + "}", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #40 ()I\n" + + " // Stack: 2, Locals: 7\n" + + " public static int foo();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [res]\n" + + " 2 iconst_0\n" + + " 3 istore_2 [n]\n" + + " 4 invokestatic X.values() : X[] [46]\n" + + " 7 astore_3 [vals]\n" + + " 8 iconst_0\n" + + " 9 istore 4 [i]\n" + + " 11 aload_3 [vals]\n" + + " 12 arraylength\n" + + " 13 istore 5 [max]\n" + + " 15 goto 48\n" + + " 18 aload_3 [vals]\n" + + " 19 iload 4 [i]\n" + + " 21 aaload\n" + + " 22 astore 6 [e]\n" + + " 24 iload_2 [n]\n" + + " 25 iconst_1\n" + + " 26 if_icmpne 32\n" + + " 29 goto 45\n" + + " 32 aload 6 [e]\n" + + " 34 invokevirtual X.value() : int [50]\n" + + " 37 istore_0 [val]\n" + + " 38 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + + " 41 iload_0 [val]\n" + + " 42 invokevirtual java.io.PrintStream.println(int) : void [58]\n" + + " 45 iinc 4 1 [i]\n" + + " 48 iload 4 [i]\n" + + " 50 iload 5 [max]\n" + + " 52 if_icmplt 18\n" + + " 55 iload_1 [res]\n" + + " 56 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 2, line: 15]\n" + + " [pc: 4, line: 16]\n" + + " [pc: 8, line: 17]\n" + + " [pc: 18, line: 18]\n" + + " [pc: 24, line: 19]\n" + + " [pc: 29, line: 20]\n" + + " [pc: 32, line: 22]\n" + + " [pc: 38, line: 23]\n" + + " [pc: 45, line: 17]\n" + + " [pc: 55, line: 25]\n" + + " Local variable table:\n" + + " [pc: 38, pc: 45] local: val index: 0 type: int\n" + + " [pc: 2, pc: 57] local: res index: 1 type: int\n" + + " [pc: 4, pc: 57] local: n index: 2 type: int\n" + + " [pc: 8, pc: 57] local: vals index: 3 type: X[]\n" + + " [pc: 11, pc: 55] local: i index: 4 type: int\n" + + " [pc: 15, pc: 55] local: max index: 5 type: int\n" + + " [pc: 24, pc: 45] local: e index: 6 type: X\n" + + " Stack map table: number of frames 4\n" + + " [pc: 18, full, stack: {}, locals: {_, int, int, X[], int, int}]\n" + + " [pc: 32, append: {X}]\n" + + " [pc: 45, chop 1 local(s)]\n" + + " [pc: 48, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test016() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " a1(1), a2(5), a3(11);\n" + + " int value;\n" + + " X(int a) {\n" + + " value = a;\n" + + " }\n" + + " int value () {\n" + + " return value;\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " }\n" + + " public static int foo() {\n" + + " int val;\n" + + " int res = 0;\n" + + " int n = 0;\n" + + " for (X e : X.values()) {\n" + + " if ( n == 1) {\n" + + " continue;\n" + + " }\n" + + " val = e.value();\n" + + " System.out.println(val);\n" + + " }\n" + + " return res;\n" + + " }\n" + + "}", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #40 ()I\n" + + " // Stack: 2, Locals: 7\n" + + " public static int foo();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [res]\n" + + " 2 iconst_0\n" + + " 3 istore_2 [n]\n" + + " 4 invokestatic X.values() : X[] [46]\n" + + " 7 dup\n" + + " 8 astore 6\n" + + " 10 arraylength\n" + + " 11 istore 5\n" + + " 13 iconst_0\n" + + " 14 istore 4\n" + + " 16 goto 48\n" + + " 19 aload 6\n" + + " 21 iload 4\n" + + " 23 aaload\n" + + " 24 astore_3 [e]\n" + + " 25 iload_2 [n]\n" + + " 26 iconst_1\n" + + " 27 if_icmpne 33\n" + + " 30 goto 45\n" + + " 33 aload_3 [e]\n" + + " 34 invokevirtual X.value() : int [50]\n" + + " 37 istore_0 [val]\n" + + " 38 getstatic java.lang.System.out : java.io.PrintStream [52]\n" + + " 41 iload_0 [val]\n" + + " 42 invokevirtual java.io.PrintStream.println(int) : void [58]\n" + + " 45 iinc 4 1\n" + + " 48 iload 4\n" + + " 50 iload 5\n" + + " 52 if_icmplt 19\n" + + " 55 iload_1 [res]\n" + + " 56 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " [pc: 2, line: 15]\n" + + " [pc: 4, line: 16]\n" + + " [pc: 25, line: 17]\n" + + " [pc: 30, line: 18]\n" + + " [pc: 33, line: 20]\n" + + " [pc: 38, line: 21]\n" + + " [pc: 45, line: 16]\n" + + " [pc: 55, line: 23]\n" + + " Local variable table:\n" + + " [pc: 38, pc: 45] local: val index: 0 type: int\n" + + " [pc: 2, pc: 57] local: res index: 1 type: int\n" + + " [pc: 4, pc: 57] local: n index: 2 type: int\n" + + " [pc: 25, pc: 45] local: e index: 3 type: X\n" + + " Stack map table: number of frames 4\n" + + " [pc: 19, full, stack: {}, locals: {_, int, int, _, int, int, X[]}]\n" + + " [pc: 33, full, stack: {}, locals: {_, int, int, X, int, int, X[]}]\n" + + " [pc: 45, full, stack: {}, locals: {_, int, int, _, int, int, X[]}]\n" + + " [pc: 48, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test017() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " int i;\n" + + " \n" + + " switch (i = 0) {\n" + + " case 0 :\n" + + " i = 1;\n" + + " break;\n" + + " default :\n" + + " ;\n" + + " }\n" + + " System.out.print(i);\n" + + " }\n" + + "}", + }, + "1"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] argv);\n" + + " 0 iconst_0\n" + + " 1 dup\n" + + " 2 istore_1 [i]\n" + + " 3 tableswitch default: 22\n" + + " case 0: 20\n" + + " 20 iconst_1\n" + + " 21 istore_1 [i]\n" + + " 22 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 25 iload_1 [i]\n" + + " 26 invokevirtual java.io.PrintStream.print(int) : void [22]\n" + + " 29 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 20, line: 7]\n" + + " [pc: 22, line: 12]\n" + + " [pc: 29, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 30] local: argv index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 30] local: i index: 1 type: int\n" + + " Stack map table: number of frames 2\n" + + " [pc: 20, append: {int}]\n" + + " [pc: 22, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test018() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "interface Sequence extends Iterable{\n" + + "\n" + + " Value_Type get(int i);\n" + + " int length();\n" + + " Value_Type set(int i, Value_Type value);\n" + + "}\n" + + "\n" + + "class ArraySequence implements Sequence {\n" + + "\n" + + " public ArraySequence(int length) {}\n" + + " public Value_Type get(int i) {\n" + + " return null;\n" + + " }\n" + + " public int length() {\n" + + " return 0;\n" + + " }\n" + + " public Value_Type set(int i, Value_Type value) {\n" + + " return value;\n" + + " }\n" + + " public Iterator iterator() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "class BirBlock {\n" + + " void setRole(IrBlock.Role role) {}\n" + + "}\n" + + "\n" + + "class CatchChain {\n" + + " int dispatcherAddress() {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "\n" + + "class ExceptionHandlerInfo {\n" + + " int handlerProgramCounter() {\n" + + " return 0;\n" + + " }\n" + + "}\n" + + "\n" + + "interface IrBlock {\n" + + " enum Role {\n" + + " EXCEPTION_DISPATCHER\n" + + " }\n" + + "}\n" + + "\n" + + "class ClassMethodActor {\n" + + " Sequence exceptionHandlerInfos() {\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public class X {\n" + + "\n" + + " private Sequence _catchChains;\n" + + " private ClassMethodActor _classMethodActor;\n" + + "\n" + + " public Sequence getExceptionDispatchers(final BirBlock[] blockMap) {\n" + + " final ArraySequence dispatchers = new ArraySequence(_catchChains.length());\n" + + " for (int i = 0; i < _catchChains.length(); i++) {\n" + + " final BirBlock dispatcher = blockMap[_catchChains.get(i).dispatcherAddress()];\n" + + " dispatcher.setRole(IrBlock.Role.EXCEPTION_DISPATCHER);\n" + + " dispatchers.set(i, dispatcher);\n" + + " }\n" + + " for (ExceptionHandlerInfo exceptionHandlerInfo : _classMethodActor.exceptionHandlerInfos()) {\n" + + " blockMap[exceptionHandlerInfo.handlerProgramCounter()].setRole(IrBlock.Role.EXCEPTION_DISPATCHER);\n" + + " }\n" + + " return dispatchers;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + public void test019() { + this.runConformTest( + new String[] { + "X.java", + "final public class X\n" + + "{\n" + + " final class MyClass\n" + + " {\n" + + " void method1(final String s)\n" + + " {\n" + + " }\n" + + " }\n" + + "\n" + + " Object method1()\n" + + " {\n" + + " try\n" + + " {\n" + + " final MyClass myClass = null;\n" + + "\n" + + " try\n" + + " {\n" + + " return null;\n" + + " }\n" + + " catch (final Throwable ex)\n" + + " {\n" + + " myClass.method1(this == null ? \"\" : \"\");\n" + + " }\n" + + "\n" + + " return null;\n" + + " }\n" + + " finally\n" + + " {\n" + + " {\n" + + " }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + public void test020() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static Map make(boolean sorted) {\n" + + " return (sorted) ? new TreeMap() : new HashMap();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " make(false);\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + // 155423 + public void test021() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " {\n" + + " if (true) throw new NullPointerException();\n" + + " }\n" + + " X() {\n" + + " System.out.println();\n" + + " }\n" + + "}", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 new java.lang.NullPointerException [10]\n" + + " 7 dup\n" + + " 8 invokespecial java.lang.NullPointerException() [12]\n" + + " 11 athrow\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 4, line: 3]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + // 157247 + public void test022() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String errorMessage;\n" + + " try {\n" + + " foo();\n" + + " errorMessage = \"No exception thrown\";\n" + + " } catch (Exception e) {\n" + + " if (e instanceof NullPointerException) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " errorMessage = \"Exception thrown\" + e;\n" + + " }\n" + + " System.out.println(errorMessage);\n" + + " }\n" + + " public static void foo() {\n" + + " throw new NullPointerException();\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=162965 + public void test023() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean a = true, x;\n" + + " if (a ? false : (x = true))\n" + + " a = x;\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + public void test024() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final int MAX_PROPERTIES = 25;\n" + + " public C c = new C();\n" + + " void foo(int i) {\n" + + " final int len = c.foo2();\n" + + " A f = new A(\" Test \", i, 1, MAX_PROPERTIES) {\n" + + " @Override\n" + + " public double bar() {\n" + + " return len;\n" + + " }\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " };\n" + + " System.out.println(f);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(0);\n" + + " }\n" + + "}", + "A.java", + "class A {\n" + + " A(String s, double d, double d1, double d2) {}\n" + + " public double bar() {\n" + + " return 0.0;\n" + + " }\n" + + "}", + "C.java", + "class C {\n" + + " public int foo2() {\n" + + " return 0;\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=169596 + public void test025() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " \n" + + " void foo(Object[] o) {}\n" + + "\n" + + " void bar(boolean b) {\n" + + " foo(new Object[] {\"\", \"\", b ? \"\" : \"\"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ \n" + + " }\n" + + "}" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=169017 + public void test026() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static final Object EXIT_OK = new Object();\n" + + " public static final Object EXIT_RELAUNCH = new Object();\n" + + " public static final Object EXIT_RESTART = new Object();\n" + + " public static final int RETURN_RESTART = 1;\n" + + " public static final String PROP_EXIT_CODE = \"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " private static int createAndRunWorkbench(Display display, IDEWorkbenchAdvisor advisor) {\n" + + " return 0;\n" + + " }\n" + + " \n" + + " public Object run(Object args) throws Exception {\n" + + " Display display = createDisplay();\n" + + " try {\n" + + " Shell shell = new Shell(display, SWT.ON_TOP);\n" + + " try {\n" + + " if (!checkInstanceLocation(shell)) {\n" + + " Platform.endSplash();\n" + + " return EXIT_OK;\n" + + " }\n" + + " } finally {\n" + + " if (shell != null) {\n" + + " shell.dispose();\n" + + " }\n" + + " }\n" + + " int returnCode = X.createAndRunWorkbench(display,\n" + + " new IDEWorkbenchAdvisor());\n" + + " if (returnCode != X.RETURN_RESTART) {\n" + + " return EXIT_OK;\n" + + " }\n" + + " return EXIT_RELAUNCH.equals(Integer.getInteger(PROP_EXIT_CODE)) ? EXIT_RELAUNCH\n" + + " : EXIT_RESTART;\n" + + " } finally {\n" + + " if (display != null) {\n" + + " display.dispose();\n" + + " }\n" + + " }\n" + + " }\n" + + " private boolean checkInstanceLocation(Shell shell) {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " private Display createDisplay() {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "}", + "Display.java", + "class Display {\n" + + "\n" + + " public void dispose() {\n" + + " // TODO Auto-generated method stub\n" + + " \n" + + " }\n" + + "}", + "Shell.java", + "class Shell {\n" + + " public Shell(Display display, int i) {\n" + + " // TODO Auto-generated constructor stub\n" + + " }\n" + + "\n" + + " public void dispose() {\n" + + " // TODO Auto-generated method stub\n" + + " \n" + + " }\n" + + "}", + "Platform.java", + "class Platform {\n" + + "\n" + + " public static void endSplash() {\n" + + " // TODO Auto-generated method stub\n" + + " \n" + + " }\n" + + "}", + "SWT.java", + "class SWT {\n" + + " public static final int ON_TOP = 1; \n" + + "}", + "IDEWorkbenchAdvisor.java", + "class IDEWorkbenchAdvisor {\n" + + "}" + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=169017 + public void test027() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "public class X {\n" + + " private static final int BUF_SIZE = 8192;\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " BundleActivator activator;\n" + + " BundleHost bundle;\n" + + " public byte[] getBytes() throws IOException {\n" + + " InputStream in = getInputStream();\n" + + " int length = (int) getSize();\n" + + " byte[] classbytes;\n" + + " int bytesread = 0;\n" + + " int readcount;\n" + + " if (Debug.DEBUG && Debug.DEBUG_LOADER)\n" + + " Debug.println(\" about to read \" + length + \" bytes from \" + getName()); //$NON-NLS-1$ //$NON-NLS-2$\n" + + " try {\n" + + " if (length > 0) {\n" + + " classbytes = new byte[length];\n" + + " for (; bytesread < length; bytesread += readcount) {\n" + + " readcount = in.read(classbytes, bytesread, length - bytesread);\n" + + " if (readcount <= 0)\n" + + " break;\n" + + " }\n" + + " } else {\n" + + " length = BUF_SIZE;\n" + + " classbytes = new byte[length];\n" + + " readloop: while (true) {\n" + + " for (; bytesread < length; bytesread += readcount) {\n" + + " readcount = in.read(classbytes, bytesread, length - bytesread);\n" + + " if (readcount <= 0)\n" + + " break readloop;\n" + + " }\n" + + " byte[] oldbytes = classbytes;\n" + + " length += BUF_SIZE;\n" + + " classbytes = new byte[length];\n" + + " System.arraycopy(oldbytes, 0, classbytes, 0, bytesread);\n" + + " }\n" + + " }\n" + + " if (classbytes.length > bytesread) {\n" + + " byte[] oldbytes = classbytes;\n" + + " classbytes = new byte[bytesread];\n" + + " System.arraycopy(oldbytes, 0, classbytes, 0, bytesread);\n" + + " }\n" + + " } finally {\n" + + " try {\n" + + " in.close();\n" + + " } catch (IOException ee) {\n" + + " // ignore\n" + + " }\n" + + " }\n" + + " return classbytes;\n" + + " }\n" + + " protected void stop(Throwable t) throws BundleException {\n" + + " String clazz = \"\";//(activator == null) ? \"\" : activator.getClass().getName(); //$NON-NLS-1$\n" + + " throw new BundleException(NLS.bind(Msg.BUNDLE_ACTIVATOR_EXCEPTION, new Object[] {clazz, \"stop\", bundle.getSymbolicName() == null ? \"\" + bundle.getBundleId() : bundle.getSymbolicName()}), t); //$NON-NLS-1$ //$NON-NLS-2$ \n" + + " }\n" + + " private String getName() {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + " private int getSize() {\n" + + " // TODO Auto-generated method stub\n" + + " return 0;\n" + + " }\n" + + " private InputStream getInputStream() {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "}", + "Debug.java", + "class Debug {\n" + + " public static final boolean DEBUG = false;\n" + + " public static final boolean DEBUG_LOADER = false;\n" + + " public static final boolean DEBUG_GENERAL = false;\n" + + " public static void println(String string) {\n" + + " // TODO Auto-generated method stub\n" + + " \n" + + " }\n" + + " public static void printStackTrace(Throwable t) {\n" + + " // TODO Auto-generated method stub\n" + + " \n" + + " }\n" + + "}", + "AccessController.java", + "class AccessController {\n" + + " static void doPrivileged(Object o) {\n" + + " }\n" + + "}", + "BundleException.java", + "class BundleException extends Exception {\n" + + " private static final long serialVersionUID = 5758882959559471648L;\n" + + "\n" + + " public BundleException(String bind, Throwable t) {\n" + + " // TODO Auto-generated constructor stub\n" + + " }\n" + + "}", + "PrivilegedExceptionAction.java", + "class PrivilegedExceptionAction {\n" + + "}", + "BundleActivator.java", + "class BundleActivator {\n" + + " public void stop(X x) {\n" + + " // TODO Auto-generated method stub\n" + + " \n" + + " }\n" + + "}", + "BundleHost.java", + "class BundleHost {\n" + + " public Object getSymbolicName() {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + " public String getBundleId() {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "}", + "NLS.java", + "class NLS {\n" + + " public static String bind(String bundleActivatorException, Object[] objects) {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "}", + "PrivilegedActionException.java", + "class PrivilegedActionException extends Exception {\n" + + " private static final long serialVersionUID = 3919969055057660822L;\n" + + " public Throwable getException() {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "}", + "Msg.java", + "class Msg {\n" + + " public static final String BUNDLE_ACTIVATOR_EXCEPTION = \"\";\n" + + "}" + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=169017 + public void test028() { + this.runConformTest( + new String[] { + "X.java", + "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" + + " }\n" + + "}" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=171472 + public void test029() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public Object foo() {\n" + + " Object status;\n" + + " try {\n" + + " status= bar();\n" + + " } catch (RuntimeException x) {\n" + + " status= foo2(x);\n" + + " } finally {\n" + + " System.out.println();\n" + + " }\n" + + " return status;\n" + + " }\n" + + " public Object bar() {\n" + + " return null;\n" + + " }\n" + + " public Object foo2(Exception e) {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=171472 + public void test030() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Collections;\n" + + "import java.util.List;\n" + + "public class X {\n" + + "\n" + + " private static final String COMPUTE_COMPLETION_PROPOSALS= \"computeCompletionProposals()\"; //$NON-NLS-1$\n" + + " private Object fLastError;\n" + + " private boolean fIsReportingDelay;\n" + + " private CompletionProposalComputerRegistry fRegistry;\n" + + " public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {\n" + + " if (!isEnabled())\n" + + " return Collections.EMPTY_LIST;\n" + + "\n" + + " IStatus status;\n" + + " try {\n" + + " IJavaCompletionProposalComputer computer= getComputer();\n" + + " if (computer == null) // not active yet\n" + + " return Collections.EMPTY_LIST;\n" + + " \n" + + " try {\n" + + " PerformanceStats stats= startMeter(context, computer);\n" + + " List proposals= computer.computeCompletionProposals(context, monitor);\n" + + " stopMeter(stats, COMPUTE_COMPLETION_PROPOSALS);\n" + + " \n" + + " if (proposals != null) {\n" + + " fLastError= computer.getErrorMessage();\n" + + " return proposals;\n" + + " }\n" + + " } finally {\n" + + " fIsReportingDelay= true;\n" + + " }\n" + + " status= createAPIViolationStatus(COMPUTE_COMPLETION_PROPOSALS);\n" + + " } catch (InvalidRegistryObjectException x) {\n" + + " status= createExceptionStatus(x);\n" + + " } catch (CoreException x) {\n" + + " status= createExceptionStatus(x);\n" + + " } catch (RuntimeException x) {\n" + + " status= createExceptionStatus(x);\n" + + " } finally {\n" + + " monitor.done();\n" + + " }\n" + + "\n" + + " fRegistry.informUser(this, status);\n" + + "\n" + + " return Collections.EMPTY_LIST;\n" + + " }\n" + + "\n" + + " private IStatus createExceptionStatus(Exception x) {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "\n" + + " private IStatus createAPIViolationStatus(String computeCompletionProposals) {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "\n" + + " private void stopMeter(PerformanceStats stats, String computeCompletionProposals) {\n" + + " // TODO Auto-generated method stub\n" + + " \n" + + " }\n" + + "\n" + + " private PerformanceStats startMeter(ContentAssistInvocationContext context, IJavaCompletionProposalComputer computer) {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "\n" + + " private IJavaCompletionProposalComputer getComputer() throws CoreException, InvalidRegistryObjectException {\n" + + " // TODO Auto-generated method stub\n" + + " return null;\n" + + " }\n" + + "\n" + + " private boolean isEnabled() {\n" + + " // TODO Auto-generated method stub\n" + + " return false;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + "IProgressMonitor.java", + "interface IProgressMonitor {\n" + + " void done();\n" + + "}", + "ContentAssistInvocationContext.java", + "class ContentAssistInvocationContext {\n" + + "}", + "IStatus.java", + "interface IStatus {}", + "IJavaCompletionProposalComputer.java", + "import java.util.List;\n" + + "interface IJavaCompletionProposalComputer {\n" + + " List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor);\n" + + " Object getErrorMessage();\n" + + "}", + "PerformanceStats.java", + "class PerformanceStats {}", + "CompletionProposalComputerRegistry.java", + "class CompletionProposalComputerRegistry {\n" + + " public void informUser(X x, IStatus status) {\n" + + " }\n" + + "}", + "InvalidRegistryObjectException.java", + "class InvalidRegistryObjectException extends Exception {\n" + + " private static final long serialVersionUID = 8943194846421947853L;\n" + + "}", + "CoreException.java", + "class CoreException extends Exception {\n" + + " private static final long serialVersionUID = 3996792687633449517L;\n" + + "}" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=168665 + public void test031() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String s;\n" + + " X() {\n" + + " this.s = \"\";\n" + + " }\n" + + " X(String s, double d, double d2, double i) {\n" + + " this.s = s;\n" + + " }\n" + + " public static final int CONST = 1;\n" + + " public int foo() {\n" + + " return 0;\n" + + " }\n" + + " public double value(double d1) {\n" + + " return d1;\n" + + " }\n" + + " public void bar(int start) {\n" + + " final int len = foo();\n" + + " X x = new X(\"SUCCESS\", start, 1, CONST) {\n" + + " @Override\n" + + " public double value(double newValue) {\n" + + " return len;\n" + + " }\n" + + " };\n" + + " System.out.println(x);\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar(1);\n" + + " }\n" + + " public String toString() {\n" + + " return this.s;\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + public void test032() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " int i = args.length;\n" + + " X[] array = new X[] { i == 0 ? null : null };\n" + + " System.out.print(\"SUCCESS\" + array.length);\n" + + " }\n" + + "}", + }, + "SUCCESS1"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=184102 + public void test033() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " C { @Override public boolean test() { return true; } };\n" + + " static {\n" + + " for (int i = 0; i < 1; i++) {}\n" + + " }\n" + + " public boolean test() {\n" + + " return false;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=184102 + public void test034() { + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " C;\n" + + " static {\n" + + " for (int i = 0; i < 1; i++) {}\n" + + " }\n" + + " public boolean test() {\n" + + " return false;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // add more bytecode coverage: fneg, lneg, dneg, dstore_0, f2l, fstore_0, fstore_2, lstore_0 and saload + public void test035() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static double foo() {\n" + + " double d = 3.0;\n" + + " d = -d;\n" + + " return d > 1.0 ? d : -d;\n" + + " }\n" + + "\n" + + " static float foo2() {\n" + + " float f = 3.0f;\n" + + " int i = 0;\n" + + " float f2 = f+ i;\n" + + " long l = (long) f;\n" + + " l += f2;\n" + + " return i == 0 ? f : -f + (float) l;\n" + + " }\n" + + "\n" + + " static long foo3() {\n" + + " long l = Long.MAX_VALUE - 3;\n" + + " boolean b = true;\n" + + " return b ? l : -l;\n" + + " }\n" + + " \n" + + " static short foo4() {\n" + + " short[] tab = new short[] { 1, 2, 3 };\n" + + " return tab.length == 3 ? tab[2] : (tab.length == 2 ? tab[1] : tab[0]);\n" + + " }\n" + + "\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " foo2();\n" + + " foo3();\n" + + " foo4();\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // fix verify error + public void test036() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.Set;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + " public void foo(Object o, boolean b) {\n" + + " String[] models = new String[] {};\n" + + " Map map = null;\n" + + " Set set = null;\n" + + " for (int n = 0; n < models.length; n++) { bar(models[n]); }\n" + + " foo2(new Object(),\n" + + " set,\n" + + " map,\n" + + " !b);\n" + + " }\n" + + " void bar(String s) {}\n" + + " void foo2(Object o, Object s, Object m, boolean b) {}\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236336 + public void test037() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + " String field;\n" + + " String field2;\n" + + " public void foo(int index, Object[] objs, Object[] objs2) {\n" + + " String methodName = \"foo\";\n" + + " int i = -1;\n" + + " try {\n" + + " switch (index) {\n" + + " case 1130: {\n" + + " int j = ((Integer) objs[0]).intValue();\n" + + " int k = ((Integer) objs[0]).intValue();\n" + + " {\n" + + " String s = field;\n" + + " String s2 = field2;\n" + + " synchronized (s2) {\n" + + " String s3 = s2;\n" + + " try {\n" + + " System.out.println(s);\n" + + " System.out.println(s2);\n" + + " System.out.println(s3);\n" + + " } finally {\n" + + " s2.toString();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " break;\n" + + " case 0 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 2 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 3 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 4 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 5 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 6 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 7 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 8 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 9 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 10 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 11 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 12 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 13 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 14 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 15 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 16 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 17 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 18 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 19 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 20 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 21 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 22 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 23 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 24 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 25 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 26 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 27 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 28 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 29 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 30 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 31 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 32 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 33 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 34 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 35 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 36 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 37 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 38 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 39 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 40 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 41 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 42 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 43 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 44 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 45 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 46 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 47 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 48 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 49 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 50 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 51 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 52 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 53 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 54 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 55 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 56 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 57 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 58 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 59 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 60 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 61 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 62 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 63 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 64 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 65 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 66 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 67 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 68 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 69 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 70 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 71 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 72 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 73 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 74 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 75 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 76 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 77 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 78 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 79 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 80 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 81 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 82 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 83 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 84 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 85 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 86 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 87 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 88 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 89 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 90 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 91 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 92 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 93 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 94 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 95 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 96 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 97 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 98 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 99 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 100 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 101 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 102 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 103 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 104 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 105 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 106 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 107 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 108 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 109 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 110 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 111 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 112 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 113 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 114 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 115 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 116 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 117 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 118 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 119 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 120 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 121 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 122 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 123 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 124 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 125 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 126 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 127 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 128 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 129 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 130 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 131 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 132 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 133 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 134 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 135 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 136 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 137 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 138 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 139 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 140 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 141 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 142 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 143 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 144 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 145 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 146 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 147 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 148 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 149 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 150 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 151 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 152 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 153 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 154 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 155 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 156 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 157 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 158 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 159 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 160 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 161 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 162 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 163 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 164 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 165 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 166 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 167 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 168 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 169 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 170 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 171 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 172 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 173 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 174 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 175 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 176 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 177 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 178 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 179 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 180 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 181 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 182 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 183 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 184 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 185 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 186 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 187 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 188 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 189 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 190 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 191 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 192 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 193 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 194 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 195 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 196 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 197 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 198 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 199 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 200 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 201 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 202 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 203 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 204 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 205 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 206 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 207 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 208 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 209 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 210 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 211 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 212 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 213 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 214 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 215 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 216 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 217 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 218 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 219 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 220 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 221 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 222 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 223 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 224 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 225 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 226 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 227 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 228 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 229 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 230 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 231 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 232 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 233 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 234 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 235 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 236 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 237 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 238 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 239 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 240 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 241 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 242 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 243 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 244 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 245 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 246 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 247 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 248 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 249 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 250 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 251 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 252 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 253 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 254 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 255 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 256 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 257 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 258 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 259 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 260 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 261 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 262 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 263 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 264 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 265 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 266 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 267 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 268 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 269 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 270 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 271 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 272 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 273 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 274 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 275 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 276 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 277 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 278 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 279 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 280 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 281 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 282 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 283 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 284 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 285 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 286 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 287 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 288 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 289 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 290 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 291 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 292 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 293 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 294 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 295 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 296 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 297 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 298 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 299 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 300 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 301 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 302 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 303 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 304 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 305 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 306 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 307 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 308 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 309 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 310 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 311 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 312 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 313 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 314 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 315 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 316 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 317 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 318 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 319 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 320 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 321 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 322 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 323 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 324 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 325 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 326 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 327 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 328 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 329 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 330 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 331 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 332 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 333 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 334 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 335 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 336 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 337 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 338 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 339 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 340 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 341 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 342 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 343 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 344 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 345 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 346 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 347 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 348 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 349 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 350 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 351 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 352 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 353 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 354 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 355 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 356 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 357 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 358 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 359 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 360 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 361 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 362 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 363 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 364 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 365 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 366 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 367 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 368 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 369 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 370 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 371 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 372 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 373 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 374 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 375 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 376 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 377 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 378 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 379 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 380 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 381 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 382 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 383 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 384 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 385 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 386 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 387 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 388 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 389 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 390 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 391 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 392 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 393 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 394 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 395 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 396 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 397 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 398 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 399 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 400 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 401 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 402 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 403 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 404 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 405 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 406 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 407 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 408 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 409 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 410 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 411 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 412 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 413 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 414 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 415 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 416 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 417 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 418 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 419 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 420 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 421 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 422 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 423 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 424 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 425 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 426 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 427 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 428 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 429 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 430 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 431 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 432 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 433 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 434 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 435 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 436 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 437 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 438 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 439 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 440 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 441 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 442 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 443 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 444 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 445 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 446 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 447 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 448 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 449 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 450 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 451 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 452 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 453 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 454 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 455 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 456 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 457 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 458 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 459 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 460 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 461 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 462 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 463 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 464 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 465 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 466 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 467 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 468 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 469 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 470 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 471 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 472 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 473 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 474 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 475 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 476 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 477 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 478 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 479 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 480 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 481 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 482 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 483 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 484 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 485 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 486 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 487 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 488 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 489 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 490 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 491 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 492 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 493 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 494 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 495 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 496 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 497 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 498 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 499 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 500 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 501 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 502 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 503 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 504 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 505 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 506 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 507 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 508 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 509 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 510 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 511 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 512 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 513 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 514 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 515 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 516 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 517 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 518 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 519 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 520 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 521 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 522 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 523 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 524 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 525 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 526 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 527 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 528 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 529 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 530 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 531 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 532 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 533 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 534 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 535 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 536 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 537 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 538 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 539 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 540 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 541 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 542 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 543 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 544 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 545 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 546 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 547 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 548 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 549 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 550 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 551 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 552 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 553 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 554 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 555 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 556 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 557 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 558 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 559 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 560 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 561 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 562 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 563 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 564 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 565 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 566 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 567 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 568 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 569 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 570 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 571 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 572 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 573 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 574 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 575 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 576 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 577 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 578 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 579 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 580 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 581 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 582 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 583 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 584 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 585 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 586 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 587 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 588 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 589 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 590 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 591 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 592 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 593 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 594 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 595 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 596 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 597 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 598 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 599 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 600 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 601 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 602 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 603 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 604 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 605 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 606 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 607 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 608 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 609 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 610 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 611 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 612 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 613 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 614 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 615 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 616 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 617 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 618 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 619 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 620 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 621 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 622 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 623 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 624 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 625 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 626 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 627 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 628 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 629 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 630 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 631 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 632 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 633 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 634 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 635 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 636 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 637 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 638 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 639 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 640 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 641 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 642 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 643 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 644 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 645 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 646 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 647 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 648 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 649 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 650 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 651 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 652 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 653 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 654 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 655 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 656 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 657 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 658 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 659 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 660 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 661 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 662 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 663 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 664 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 665 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 666 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 667 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 668 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 669 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 670 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 671 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 672 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 673 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 674 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 675 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 676 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 677 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 678 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 679 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 680 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 681 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 682 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 683 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 684 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 685 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 686 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 687 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 688 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 689 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 690 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 691 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 692 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 693 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 694 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 695 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 696 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 697 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 698 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 699 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 700 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 701 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 702 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 703 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 704 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 705 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 706 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 707 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 708 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 709 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 710 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 711 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 712 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 713 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 714 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 715 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 716 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 717 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 718 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 719 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 720 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 721 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 722 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 723 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 724 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 725 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 726 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 727 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 728 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 729 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 730 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 731 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 732 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 733 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 734 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 735 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 736 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 737 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 738 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 739 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 740 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 741 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 742 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 743 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 744 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 745 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 746 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 747 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 748 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 749 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 750 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 751 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 752 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 753 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 754 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 755 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 756 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 757 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 758 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 759 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 760 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 761 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 762 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 763 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 764 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 765 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 766 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 767 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 768 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 769 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 770 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 771 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 772 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 773 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 774 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 775 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 776 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 777 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 778 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 779 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 780 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 781 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 782 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 783 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 784 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 785 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 786 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 787 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 788 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 789 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 790 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 791 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 792 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 793 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 794 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 795 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 796 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 797 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 798 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 799 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 800 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 801 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 802 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 803 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 804 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 805 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 806 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 807 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 808 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 809 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 810 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 811 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 812 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 813 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 814 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 815 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 816 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 817 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 818 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 819 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 820 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 821 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 822 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 823 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 824 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 825 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 826 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 827 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 828 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 829 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 830 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 831 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 832 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 833 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 834 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 835 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 836 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 837 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 838 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 839 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 840 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 841 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 842 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 843 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 844 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 845 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 846 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 847 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 848 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 849 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 850 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 851 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 852 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 853 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 854 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 855 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 856 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 857 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 858 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 859 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 860 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 861 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 862 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 863 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 864 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 865 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 866 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 867 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 868 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 869 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 870 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 871 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 872 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 873 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 874 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 875 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 876 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 877 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 878 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 879 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 880 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 881 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 882 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 883 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 884 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 885 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 886 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 887 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 888 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 889 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 890 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 891 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 892 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 893 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 894 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 895 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 896 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 897 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 898 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 899 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 900 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 901 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 902 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 903 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 904 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 905 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 906 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 907 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 908 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 909 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 910 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 911 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 912 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 913 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 914 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 915 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 916 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 917 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 918 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 919 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 920 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 921 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 922 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 923 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 924 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 925 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 926 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 927 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 928 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 929 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 930 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 931 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 932 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 933 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 934 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 935 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 936 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 937 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 938 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 939 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 940 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 941 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 942 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 943 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 944 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 945 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 946 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 947 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 948 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 949 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 950 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 951 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 952 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 953 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 954 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 955 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 956 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 957 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 958 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 959 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 960 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 961 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 962 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 963 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 964 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 965 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 966 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 967 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 968 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 969 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 970 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 971 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 972 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 973 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 974 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 975 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 976 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 977 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 978 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 979 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 980 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 981 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 982 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 983 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 984 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 985 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 986 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 987 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 988 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 989 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 990 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 991 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 992 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 993 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 994 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 995 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 996 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 997 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 998 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 999 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1000 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1001 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1002 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1003 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1004 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1005 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1006 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1007 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1008 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1009 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1010 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1011 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1012 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1013 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1014 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1015 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1016 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1017 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1018 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1019 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1020 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1021 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1022 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1023 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1024 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1025 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1026 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1027 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1028 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1029 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1030 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1031 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1032 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1033 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1034 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1035 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1036 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1037 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1038 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1039 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1040 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1041 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1042 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1043 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1044 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1045 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1046 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1047 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1048 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1049 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1050 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1051 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1052 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1053 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1054 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1055 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1056 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1057 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1058 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1059 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1060 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1061 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1062 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1063 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1064 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1065 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1066 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1067 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1068 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1069 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1070 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1071 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1072 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1073 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1074 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1075 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1076 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1077 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1078 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1079 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1080 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1081 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1082 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1083 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1084 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1085 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1086 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1087 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1088 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1089 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1090 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1091 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1092 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1093 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1094 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1095 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1096 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1097 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1098 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1099 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1100 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1101 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1102 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1103 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1104 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1105 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1106 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1107 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1108 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1109 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1110 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1111 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1112 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1113 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1114 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1115 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1116 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1117 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1118 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1119 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1120 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1121 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1122 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1123 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1124 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1125 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1126 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1127 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1128 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " case 1129 :\n" + + " System.out.println(methodName + i);\n" + + " break;\n" + + " }\n" + + " } catch(Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=238923 + public void test038() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " {\n" + + " for (boolean b : new boolean[] {}) {}\n" + + " }\n" + + " public X() {}\n" + + " public X(boolean b) {}\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=237931 + public void test039() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public String[][] foo(String s) {\n" + + " return\n" + + " new String[][] { {\" \", s != null ? s : \"\" },\n" + + " {\" \", s != null ? s : \"\" },\n" + + " {\" \", s != null ? s : \"\" },\n" + + " {\" \", s != null ? s : \"\" } };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=251539 + public void test040() throws Exception { + this.runConformTest( + new String[] { + "I.java", + "public interface I {\n" + + "\n" + + " public Object foo();\n" + + "\n" + + " public static class B implements I {\n" + + " public Object foo() {\n" + + " return X.myI.foo();\n" + + " }\n" + + " }\n" + + "}", + "X.java", + "public class X {\n" + + " public static final I myI = new I.B() {\n" + + " int a = 0;\n" + + " int b = 1;\n" + + " };\n" + + "\n" + + " private Object bar2() {\n" + + " return null;\n" + + " }\n" + + " private Object bar() {\n" + + " Object o = bar2();\n" + + " if (o != null) {\n" + + " o.toString();\n" + + " }\n" + + " return null;\n" + + " }\n" + + "\n" + + "}", + }, + ""); + String expectedOutput = + " // Method descriptor #23 ()Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 2\n" + + " private java.lang.Object bar();\n" + + " 0 aload_0 [this]\n" + + " 1 " + + (isMinimumCompliant(ClassFileConstants.JDK11) ? "invokevirtual" : "invokespecial") + + " X.bar2() : java.lang.Object [25]\n" + + " 4 astore_1 [o]\n" + + " 5 aload_1 [o]\n" + + " 6 ifnull 14\n" + + " 9 aload_1 [o]\n" + + " 10 invokevirtual java.lang.Object.toString() : java.lang.String [27]\n" + + " 13 pop\n" + + " 14 aconst_null\n" + + " 15 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " [pc: 5, line: 12]\n" + + " [pc: 9, line: 13]\n" + + " [pc: 14, line: 15]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 16] local: this index: 0 type: X\n" + + " [pc: 5, pc: 16] local: o index: 1 type: java.lang.Object\n" + + " Stack map table: number of frames 1\n" + + " [pc: 14, append: {java.lang.Object}]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=251539 + public void test041() throws Exception { + this.runConformTest( + new String[] { + "I.java", + "public interface I {\n" + + "\n" + + " public Object foo();\n" + + "\n" + + " public static class B implements I {\n" + + " public Object foo() {\n" + + " return String.valueOf(X.myI.foo()) + String.valueOf(X.myU.foo());\n" + + " }\n" + + " }\n" + + "}", + "X.java", + "public class X {\n" + + " public static final I myI = new I.B() {\n" + + " int a = 0;\n" + + " int b = 1;\n" + + " };\n" + + " public static final I myU = new I.B() {\n" + + " int a = 0;\n" + + " int b = 1;\n" + + " int c = 2;\n" + + " };\n" + + " private Object bar2() {\n" + + " return null;\n" + + " }\n" + + " private Object bar() {\n" + + " Object o = bar2();\n" + + " if (o != null) {\n" + + " o.toString();\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}", + }, + ""); + + String expectedOutput = + " // Method descriptor #29 ()Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 2\n" + + " private java.lang.Object bar();\n" + + " 0 aload_0 [this]\n" + + " 1 " + + (isMinimumCompliant(ClassFileConstants.JDK11) ? "invokevirtual" : "invokespecial") + + " X.bar2() : java.lang.Object [31]\n" + + " 4 astore_1 [o]\n" + + " 5 aload_1 [o]\n" + + " 6 ifnull 14\n" + + " 9 aload_1 [o]\n" + + " 10 invokevirtual java.lang.Object.toString() : java.lang.String [33]\n" + + " 13 pop\n" + + " 14 aconst_null\n" + + " 15 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 15]\n" + + " [pc: 5, line: 16]\n" + + " [pc: 9, line: 17]\n" + + " [pc: 14, line: 19]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 16] local: this index: 0 type: X\n" + + " [pc: 5, pc: 16] local: o index: 1 type: java.lang.Object\n" + + " Stack map table: number of frames 1\n" + + " [pc: 14, append: {java.lang.Object}]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=260031 + public void test042() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private static void foo(Class c, int n) { }\n" + + " public static void main(String... args) {\n" + + " foo(Integer.class, (args == null ? -1 : 1));\n" + + " }\n" + + "}", + }, + ""); + + String expectedOutput = + " // Stack: 2, Locals: 1\n" + + " public static void main(java.lang.String... args);\n" + + " 0 ldc [26]\n" + + " 2 aload_0 [args]\n" + + " 3 ifnonnull 10\n" + + " 6 iconst_m1\n" + + " 7 goto 11\n" + + " 10 iconst_1\n" + + " 11 invokestatic X.foo(java.lang.Class, int) : void [28]\n" + + " 14 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 14, line: 5]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 15] local: args index: 0 type: java.lang.String[]\n" + + " Stack map table: number of frames 2\n" + + " [pc: 10, same_locals_1_stack_item, stack: {java.lang.Class}]\n" + + " [pc: 11, full, stack: {java.lang.Class, int}, locals: {java.lang.String[]}]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=279183 + public void test043() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"ok\");\n" + + " }\n" + + " private static int willNotVerify() {\n" + + " int limit = 100;\n" + + " int match;\n" + + " int result = 200;\n" + + " do {\n" + + " if (limit > 0) {\n" + + " continue;\n" + + " }\n" + + " match = 0;\n" + + " while (++match < 100) {\n" + + " System.out.println();\n" + + " }\n" + + " } while (--limit != 0);\n" + + " return result;\n" + + " }\n" + + "}", + }, + "ok"); + + String expectedOutput = + " // Method descriptor #33 ()I\n" + + " // Stack: 2, Locals: 3\n" + + " private static int willNotVerify();\n" + + " 0 bipush 100\n" + + " 2 istore_0 [limit]\n" + + " 3 sipush 200\n" + + " 6 istore_2 [result]\n" + + " 7 iload_0 [limit]\n" + + " 8 ifle 14\n" + + " 11 goto 34\n" + + " 14 iconst_0\n" + + " 15 istore_1 [match]\n" + + " 16 goto 25\n" + + " 19 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 22 invokevirtual java.io.PrintStream.println() : void [34]\n" + + " 25 iinc 1 1 [match]\n" + + " 28 iload_1 [match]\n" + + " 29 bipush 100\n" + + " 31 if_icmplt 19\n" + + " 34 iinc 0 -1 [limit]\n" + + " 37 iload_0 [limit]\n" + + " 38 ifne 7\n" + + " 41 iload_2 [result]\n" + + " 42 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 3, line: 8]\n" + + " [pc: 7, line: 10]\n" + + " [pc: 11, line: 11]\n" + + " [pc: 14, line: 13]\n" + + " [pc: 16, line: 14]\n" + + " [pc: 19, line: 15]\n" + + " [pc: 25, line: 14]\n" + + " [pc: 34, line: 17]\n" + + " [pc: 41, line: 18]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 43] local: limit index: 0 type: int\n" + + " [pc: 16, pc: 34] local: match index: 1 type: int\n" + + " [pc: 7, pc: 43] local: result index: 2 type: int\n" + + " Stack map table: number of frames 5\n" + + " [pc: 7, full, stack: {}, locals: {int, _, int}]\n" + + " [pc: 14, same]\n" + + " [pc: 19, full, stack: {}, locals: {int, int, int}]\n" + + " [pc: 25, same]\n" + + " [pc: 34, full, stack: {}, locals: {int, _, int}]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=279183 + public void test044() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"ok\");\n" + + " }\n" + + " private static int willNotVerify() {\n" + + " int limit = 100;\n" + + " int match;\n" + + " int result = 200;\n" + + " do {\n" + + " if (limit > 0) {\n" + + " continue;\n" + + " }\n" + + " match = 0;\n" + + " while (++match < 100) {\n" + + " // empty\n" + + " }\n" + + " } while (--limit != 0);\n" + + " return result;\n" + + " }\n" + + "}", + }, + "ok"); + + String expectedOutput = + " // Method descriptor #33 ()I\n" + + " // Stack: 2, Locals: 3\n" + + " private static int willNotVerify();\n" + + " 0 bipush 100\n" + + " 2 istore_0 [limit]\n" + + " 3 sipush 200\n" + + " 6 istore_2 [result]\n" + + " 7 iload_0 [limit]\n" + + " 8 ifle 14\n" + + " 11 goto 25\n" + + " 14 iconst_0\n" + + " 15 istore_1 [match]\n" + + " 16 iinc 1 1 [match]\n" + + " 19 iload_1 [match]\n" + + " 20 bipush 100\n" + + " 22 if_icmplt 16\n" + + " 25 iinc 0 -1 [limit]\n" + + " 28 iload_0 [limit]\n" + + " 29 ifne 7\n" + + " 32 iload_2 [result]\n" + + " 33 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 3, line: 8]\n" + + " [pc: 7, line: 10]\n" + + " [pc: 11, line: 11]\n" + + " [pc: 14, line: 13]\n" + + " [pc: 16, line: 14]\n" + + " [pc: 25, line: 17]\n" + + " [pc: 32, line: 18]\n" + + " Local variable table:\n" + + " [pc: 3, pc: 34] local: limit index: 0 type: int\n" + + " [pc: 16, pc: 25] local: match index: 1 type: int\n" + + " [pc: 7, pc: 34] local: result index: 2 type: int\n" + + " Stack map table: number of frames 4\n" + + " [pc: 7, full, stack: {}, locals: {int, _, int}]\n" + + " [pc: 14, same]\n" + + " [pc: 16, full, stack: {}, locals: {int, int, int}]\n" + + " [pc: 25, full, stack: {}, locals: {int, _, int}]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=279183 + public void test045() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " int i;\n" + + " do {\n" + + " } while ((i = 2) < 0);\n" + + " if (i != 2) {\n" + + " System.out.println(\"FAILED\");\n" + + " } else {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_2\n" + + " 1 dup\n" + + " 2 istore_1 [i]\n" + + " 3 iflt 0\n" + + " 6 iload_1 [i]\n" + + " 7 iconst_2\n" + + " 8 if_icmpeq 22\n" + + " 11 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 14 ldc [22]\n" + + " 16 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 19 goto 30\n" + + " 22 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 25 ldc [30]\n" + + " 27 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 30 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 3, line: 4]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 11, line: 7]\n" + + " [pc: 19, line: 8]\n" + + " [pc: 22, line: 9]\n" + + " [pc: 30, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 31] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 31] local: i index: 1 type: int\n" + + " Stack map table: number of frames 3\n" + + " [pc: 0, same]\n" + + " [pc: 22, append: {int}]\n" + + " [pc: 30, same]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput); + } + // 298250 + public void test046() { + Map customOptions = getCompilerOptions(); + customOptions.put(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.IGNORE); + this.runNegativeTest( + new String[] { + "X.java", + "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" + + "1. ERROR in X.java (at line 9)\n" + + " throw new E1();\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); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=324848 + public void test047() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void test() {\n" + + " final boolean x = true;\n" + + " new Runnable() {\n" + + " @Override\n" + + " public void run() {\n" + + " synchronized (X.this) {\n" + + " System.out.println(x);\n" + + " }\n" + + " }\n" + + " };\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " synchronized (X.this) {\n" + + " ^^^^^^\n" + + "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 copyDir(List 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(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 copyDir(int j, List 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); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=354052 + public void test054() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void foo() {\n" + + " X z;\n" + + " while ((z = getObject()) != null) {\n" + + " z.bar();\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void bar() {}\n" + + " public static X getObject() {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n"+ + " new X().foo();\n"+ + " }\n"+ + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=359495 + public void testBug359495a() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.concurrent.locks.Lock;\n" + + "import java.util.Arrays;\n" + + "import java.util.concurrent.locks.ReentrantLock;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final Lock lock = new ReentrantLock();\n" + + " final List strings = Arrays.asList(args);\n" + + " lock.lock();\n" + + " try{\n" + + " for (final String string:strings){\n" + + " return;\n" + + " }\n" + + " return;\n" + + " } finally {\n" + + " lock.unlock();\n" + + " }" + + " }\n" + + "}", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 6\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new java.util.concurrent.locks.ReentrantLock [16]\n" + + " 3 dup\n" + + " 4 invokespecial java.util.concurrent.locks.ReentrantLock() [18]\n" + + " 7 astore_1 [lock]\n" + + " 8 aload_0 [args]\n" + + " 9 invokestatic java.util.Arrays.asList(java.lang.Object[]) : java.util.List [19]\n" + + " 12 astore_2 [strings]\n" + + " 13 aload_1 [lock]\n" + + " 14 invokeinterface java.util.concurrent.locks.Lock.lock() : void [25] [nargs: 1]\n" + + " 19 aload_2 [strings]\n" + + " 20 invokeinterface java.util.List.iterator() : java.util.Iterator [30] [nargs: 1]\n" + + " 25 astore 4\n" + + " 27 aload 4\n" + + " 29 invokeinterface java.util.Iterator.hasNext() : boolean [36] [nargs: 1]\n" + + " 34 ifeq 55\n" + + " 37 aload 4\n" + + " 39 invokeinterface java.util.Iterator.next() : java.lang.Object [42] [nargs: 1]\n" + + " 44 checkcast java.lang.String [46]\n" + + " 47 astore_3 [string]\n" + + " 48 aload_1 [lock]\n" + + " 49 invokeinterface java.util.concurrent.locks.Lock.unlock() : void [48] [nargs: 1]\n" + + " 54 return\n" + + " 55 aload_1 [lock]\n" + + " 56 invokeinterface java.util.concurrent.locks.Lock.unlock() : void [48] [nargs: 1]\n" + + " 61 return\n" + + " 62 astore 5\n" + + " 64 aload_1 [lock]\n" + + " 65 invokeinterface java.util.concurrent.locks.Lock.unlock() : void [48] [nargs: 1]\n" + + " 70 aload 5\n" + + " 72 athrow\n" + + " Exception Table:\n" + + " [pc: 19, pc: 48] -> 62 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 13, line: 9]\n" + + " [pc: 19, line: 11]\n" + + " [pc: 48, line: 16]\n" + + " [pc: 54, line: 12]\n" + + " [pc: 55, line: 16]\n" + + " [pc: 61, line: 14]\n" + + " [pc: 62, line: 15]\n" + + " [pc: 64, line: 16]\n" + + " [pc: 70, line: 17]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 73] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 73] local: lock index: 1 type: java.util.concurrent.locks.Lock\n" + + " [pc: 13, pc: 73] local: strings index: 2 type: java.util.List\n" + + " [pc: 48, pc: 55] local: string index: 3 type: java.lang.String\n" + + " Local variable type table:\n" + + " [pc: 13, pc: 73] local: strings index: 2 type: java.util.List\n" + + " Stack map table: number of frames 2\n" + + " [pc: 55, append: {java.util.concurrent.locks.Lock, java.util.List}]\n" + + " [pc: 62, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" ; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=359495 + public void testBug359495b() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "import java.util.Iterator;\n" + + "import java.util.concurrent.locks.Lock;\n" + + "import java.util.Arrays;\n" + + "import java.util.concurrent.locks.ReentrantLock;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " final Lock lock = new ReentrantLock();\n" + + " final List strings = Arrays.asList(args);\n" + + " lock.lock();\n" + + " try{\n" + + " for (Iterator i = strings.iterator(); i.hasNext();){\n" + + " return;\n" + + " }\n" + + " return;\n" + + " } finally {\n" + + " lock.unlock();\n" + + " }" + + " }\n" + + "}", + }, + ""); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 5\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 new java.util.concurrent.locks.ReentrantLock [16]\n" + + " 3 dup\n" + + " 4 invokespecial java.util.concurrent.locks.ReentrantLock() [18]\n" + + " 7 astore_1 [lock]\n" + + " 8 aload_0 [args]\n" + + " 9 invokestatic java.util.Arrays.asList(java.lang.Object[]) : java.util.List [19]\n" + + " 12 astore_2 [strings]\n" + + " 13 aload_1 [lock]\n" + + " 14 invokeinterface java.util.concurrent.locks.Lock.lock() : void [25] [nargs: 1]\n" + + " 19 aload_2 [strings]\n" + + " 20 invokeinterface java.util.List.iterator() : java.util.Iterator [30] [nargs: 1]\n" + + " 25 astore_3 [i]\n" + + " 26 aload_3 [i]\n" + + " 27 invokeinterface java.util.Iterator.hasNext() : boolean [36] [nargs: 1]\n" + + " 32 ifeq 42\n" + + " 35 aload_1 [lock]\n" + + " 36 invokeinterface java.util.concurrent.locks.Lock.unlock() : void [42] [nargs: 1]\n" + + " 41 return\n" + + " 42 aload_1 [lock]\n" + + " 43 invokeinterface java.util.concurrent.locks.Lock.unlock() : void [42] [nargs: 1]\n" + + " 48 return\n" + + " 49 astore 4\n" + + " 51 aload_1 [lock]\n" + + " 52 invokeinterface java.util.concurrent.locks.Lock.unlock() : void [42] [nargs: 1]\n" + + " 57 aload 4\n" + + " 59 athrow\n" + + " Exception Table:\n" + + " [pc: 19, pc: 35] -> 49 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 8]\n" + + " [pc: 8, line: 9]\n" + + " [pc: 13, line: 10]\n" + + " [pc: 19, line: 12]\n" + + " [pc: 35, line: 17]\n" + + " [pc: 41, line: 13]\n" + + " [pc: 42, line: 17]\n" + + " [pc: 48, line: 15]\n" + + " [pc: 49, line: 16]\n" + + " [pc: 51, line: 17]\n" + + " [pc: 57, line: 18]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 60] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 8, pc: 60] local: lock index: 1 type: java.util.concurrent.locks.Lock\n" + + " [pc: 13, pc: 60] local: strings index: 2 type: java.util.List\n" + + " [pc: 26, pc: 42] local: i index: 3 type: java.util.Iterator\n" + + " Local variable type table:\n" + + " [pc: 13, pc: 60] local: strings index: 2 type: java.util.List\n" + + " Stack map table: number of frames 2\n" + + " [pc: 42, append: {java.util.concurrent.locks.Lock, java.util.List}]\n" + + " [pc: 49, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=362591 + public void test055() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " testError(3, 4, \"d\");\n" + + " }\n" + + " public static void testError(Number n0, Number n1, String refValue) {\n" + + " Number result = refValue.equals(\"ttt\") ? n0 : (n1 == null ? null : n1.intValue());\n" + + " System.out.println(String.valueOf(result));\n" + + " }\n" + + "}", + }, + "4"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #27 (Ljava/lang/Number;Ljava/lang/Number;Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 4\n" + + " public static void testError(java.lang.Number n0, java.lang.Number n1, java.lang.String refValue);\n" + + " 0 aload_2 [refValue]\n" + + " 1 ldc [30]\n" + + " 3 invokevirtual java.lang.String.equals(java.lang.Object) : boolean [32]\n" + + " 6 ifeq 13\n" + + " 9 aload_0 [n0]\n" + + " 10 goto 28\n" + + " 13 aload_1 [n1]\n" + + " 14 ifnonnull 21\n" + + " 17 aconst_null\n" + + " 18 goto 28\n" + + " 21 aload_1 [n1]\n" + + " 22 invokevirtual java.lang.Number.intValue() : int [38]\n" + + " 25 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [16]\n" + + " 28 astore_3 [result]\n" + + " 29 getstatic java.lang.System.out : java.io.PrintStream [44]\n" + + " 32 aload_3 [result]\n" + + " 33 invokestatic java.lang.String.valueOf(java.lang.Object) : java.lang.String [50]\n" + + " 36 invokevirtual java.io.PrintStream.println(java.lang.String) : void [53]\n" + + " 39 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 29, line: 7]\n" + + " [pc: 39, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 40] local: n0 index: 0 type: java.lang.Number\n" + + " [pc: 0, pc: 40] local: n1 index: 1 type: java.lang.Number\n" + + " [pc: 0, pc: 40] local: refValue index: 2 type: java.lang.String\n" + + " [pc: 29, pc: 40] local: result index: 3 type: java.lang.Number\n" + + " Stack map table: number of frames 3\n" + + " [pc: 13, same]\n" + + " [pc: 21, same]\n" + + " [pc: 28, same_locals_1_stack_item, stack: {java.lang.Number}]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test055a() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Object o = args != null ? args : (args == null ? null : args.length);\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=366999 + public void test056() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; + this.runConformTest( + new String[] { + "X.java", + "import java.io.BufferedReader;\n" + + "import java.io.Closeable;\n" + + "import java.io.File;\n" + + "import java.io.FileReader;\n" + + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + "\n" + + " static class C implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " //\n" + + " }\n" + + " }\n" + + "\n" + + " int run() throws IOException {\n" + + " int lcnt = 0;\n" + + " try (C c = new C();) {\n" + + " try (final BufferedReader br = new BufferedReader(new FileReader(\n" + + " new File(\"logging.properties\")))) {\n" + + " String s = null;\n" + + " while ((s = br.readLine()) != null)\n" + + " lcnt++;\n" + + " return lcnt;\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"read \" + lcnt + \" lines\");\n" + + " }\n" + + " }\n" + + "\n" + + " public static void main(final String[] args) throws IOException {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test057() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " String s;\n" + + " label1: do {\n" + + " for (;;) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test058() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " String s;\n" + + " label1: do {\n" + + " for (;true;) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test059() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " String s;\n" + + " label1: do {\n" + + " for (;false;) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " label1: do {\n" + + " ^^^^^^\n" + + "The label label1 is never explicitly referenced\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " for (;false;) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " } while (s != null);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test060() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " String s;\n" + + " label1: do {\n" + + " for (; 5 < 10;) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test061() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " int five = 5, ten = 10;\n" + + " String s;\n" + + " label1: do {\n" + + " for (; five < ten;) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " continue label1;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " } while (s != null);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test062() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " final int five = 5, ten = 10;\n" + + " String s;\n" + + " label1: do {\n" + + " for (; five < ten;) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test063() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " final int five = 5, ten = 10;\n" + + " String s;\n" + + " label1: do {\n" + + " for (; five > ten;) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " label1: do {\n" + + " ^^^^^^\n" + + "The label label1 is never explicitly referenced\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " for (; five > ten;) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " } while (s != null);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test064() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " String s;\n" + + " label1: do {\n" + + " while (true) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test065() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " String s;\n" + + " label1: do {\n" + + " while (false) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " label1: do {\n" + + " ^^^^^^\n" + + "The label label1 is never explicitly referenced\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " while (false) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " } while (s != null);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test066() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " String s;\n" + + " label1: do {\n" + + " while(5 < 10) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test067() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " int five = 5, ten = 10;\n" + + " String s;\n" + + " label1: do {\n" + + " while (five < ten) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in X.java (at line 9)\n" + + " continue label1;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " } while (s != null);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test068() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " final int five = 5, ten = 10;\n" + + " String s;\n" + + " label1: do {\n" + + " while (five < ten) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test069() throws Exception { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void run() {\n" + + " final int five = 5, ten = 10;\n" + + " String s;\n" + + " label1: do {\n" + + " while (five > ten) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " } while (s != null);\n" + + "}\n" + + " public static void main(String [] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " label1: do {\n" + + " ^^^^^^\n" + + "The label label1 is never explicitly referenced\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " while (five > ten) {\n" + + " s = \"\";\n" + + " if (s == null) \n" + + " continue label1;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable code\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " } while (s != null);\n" + + " ^\n" + + "The local variable s may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367023 + public void test070() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Arrays;\n" + + "import java.util.Iterator;\n" + + "import java.util.List;\n" + + "import java.util.Properties;\n" + + "import org.w3c.dom.*;\n" + + "public class X extends Object {\n" + + " public static void main(String [] args) {\n" + + " System.out.println (\"SUCCESS\");\n" + + " }\n" + + " private static class Handler extends Object {\n" + + " public int getStuff() {\n" + + " return 1;\n" + + " }\n" + + " public void handle(Element element) {\n" + + " Properties properties = new Properties();\n" + + " NamedNodeMap atts = element.getAttributes();\n" + + " if (atts != null) {\n" + + " for (int a = 0; a < atts.getLength(); a++) {\n" + + " Node att = atts.item(a);\n" + + " String name = att.getNodeName();\n" + + " String value = att.getNodeValue();\n" + + " if (\"foo\".equals(name)) {\n" + + " name = value;\n" + + " } else {\n" + + " if (!\"bar\".equals(name))\n" + + " continue;\n" + + " name = value;\n" + + " }\n" + + " properties.put(name, value);\n" + + " }\n" + + " }\n" + + " label0: do {\n" + + " Node node;\n" + + " String nodeName;\n" + + " label1: do {\n" + + " for (Iterator i = (new ArrayList(1)).iterator(); i\n" + + " .hasNext(); members.add(equals(node))) {\n" + + " node = (Node) i.next();\n" + + " nodeName = \"\" + equals(node.getNodeName());\n" + + " if (!\"foo\".equals(nodeName))\n" + + " continue label1;\n" + + " }\n" + + " break label0;\n" + + " } while (!\"bar\".equals(nodeName));\n" + + " Iterator i = (new ArrayList(1)).iterator();\n" + + " while (i.hasNext()) {\n" + + " Node n = (Node) i.next();\n" + + " String name = toString() + n.getNodeName();\n" + + " if (\"wtf\".equals(name)) {\n" + + " String propertyName = (toString() + n.getAttributes()\n" + + " .getNamedItem(\"broken\")).trim();\n" + + " String value = toString() + n;\n" + + " properties.put(propertyName, value);\n" + + " }\n" + + " }\n" + + " } while (true);\n" + + " propertiesBuilder.equals(properties);\n" + + " builder.equals(propertiesBuilder.hashCode());\n" + + " builder.equals(members);\n" + + " }\n" + + " private final Object c;\n" + + " private Object builder;\n" + + " private List members;\n" + + " private Object propertiesBuilder;\n" + + " public Handler(Object c) {\n" + + " this.c = c;\n" + + " builder = Arrays.asList(Object.class);\n" + + " builder.equals(\"foo\");\n" + + " builder.equals(\"bar\");\n" + + " members = new ArrayList();\n" + + " propertiesBuilder = Arrays.asList(Object.class);\n" + + " Object beanDefinition = propertiesBuilder.toString();\n" + + " Object holder = new String(\"stirng\");\n" + + " Arrays.asList(holder, c.toString());\n" + + " }\n" + + " }\n" + + " public X() {\n" + + " }\n" + + " protected Object parseInternal(Element element, Object c) {\n" + + " Handler h = new Handler(c);\n" + + " h.handle(element);\n" + + " return h.getStuff();\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=380313 + // Verify the generated code does not have same branch target for the 2 return statements + public void testBug380313() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public void foo() throws Exception {\n" + + " int i = 1;\n" + + " try {\n" + + " if (i == 1) {\n" + + " int n = bar();\n" + + " if (n == 35)\n" + + " return;\n" + + " } else {\n" + + " throw new Exception();\n" + + " }\n" + + " if (i == 0)\n" + + " return;\n" + + " } finally {\n" + + " bar();\n" + + " }\n" + + " }\n" + + "\n" + + " private int bar() {\n" + + " return 0;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String xBarCall = isMinimumCompliant(ClassFileConstants.JDK11) ? + "invokevirtual X.bar() : int [18]\n" : "invokespecial X.bar() : int [18]\n"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 4\n" + + " public void foo() throws java.lang.Exception;\n" + + " 0 iconst_1\n" + + " 1 istore_1 [i]\n" + + " 2 iload_1 [i]\n" + + " 3 iconst_1\n" + + " 4 if_icmpne 24\n" + + " 7 aload_0 [this]\n" + + " 8 " + xBarCall + + " 11 istore_2 [n]\n" + + " 12 iload_2 [n]\n" + + " 13 bipush 35\n" + + " 15 if_icmpne 32\n" + + " 18 aload_0 [this]\n" + + " 19 " + xBarCall + + " 22 pop\n" + + " 23 return\n" + + " 24 new java.lang.Exception [16]\n" + + " 27 dup\n" + + " 28 invokespecial java.lang.Exception() [22]\n" + + " 31 athrow\n" + + " 32 iload_1 [i]\n" + + " 33 ifne 50\n" + + " 36 aload_0 [this]\n" + + " 37 " + xBarCall + + " 40 pop\n" + + " 41 return\n" + + " 42 astore_3\n" + + " 43 aload_0 [this]\n" + + " 44 " + xBarCall + + " 47 pop\n" + + " 48 aload_3\n" + + " 49 athrow\n" + + " 50 aload_0 [this]\n" + + " 51 " + xBarCall + + " 54 pop\n" + + " 55 return\n" + + " Exception Table:\n" + + " [pc: 2, pc: 18] -> 42 when : any\n" + + " [pc: 24, pc: 36] -> 42 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 12, line: 7]\n" + + " [pc: 18, line: 15]\n" + + " [pc: 23, line: 8]\n" + + " [pc: 24, line: 10]\n" + + " [pc: 32, line: 12]\n" + + " [pc: 36, line: 15]\n" + + " [pc: 41, line: 13]\n" + + " [pc: 42, line: 14]\n" + + " [pc: 43, line: 15]\n" + + " [pc: 48, line: 16]\n" + + " [pc: 50, line: 15]\n" + + " [pc: 55, line: 17]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 56] local: this index: 0 type: X\n" + + " [pc: 2, pc: 56] local: i index: 1 type: int\n" + + " [pc: 12, pc: 24] local: n index: 2 type: int\n" + + " Stack map table: number of frames 4\n" + + " [pc: 24, append: {int}]\n" + + " [pc: 32, same]\n" + + " [pc: 42, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 50, same]\n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=380313 + // Verify the generated code does not have same branch target for the 2 return statements + public void testBug380313b() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) + return; + this.runConformTest( + new String[] { + "X.java", + "import java.io.FileInputStream;\n" + + "import java.io.IOException;\n" + + "public class X {\n" + + "public void foo() throws Exception {\n" + + " int i = 1;\n" + + " try {\n" + + " try (FileInputStream fis = new FileInputStream(\"\")) {\n" + + " if (i == 2)" + + " return;\n" + + " }\n" + + " if (i == 35) \n" + + " return;\n" + + " } catch(IOException e) {\n" + + " bar();\n" + + " } finally {\n" + + " bar();\n" + + " }\n" + + " }\n" + + "\n" + + " private int bar() {\n" + + " return 0;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String xBarCall = (isMinimumCompliant(ClassFileConstants.JDK11) ? + "invokevirtual" : "invokespecial") + " X.bar() : int [28]\n"; + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 3, Locals: 6\n" + + " public void foo() throws java.lang.Exception;\n" + + " 0 iconst_1\n" + + " 1 istore_1 [i]\n" + + " 2 aconst_null\n" + + " 3 astore_2\n" + + " 4 aconst_null\n" + + " 5 astore_3\n" + + " 6 new java.io.FileInputStream [18]\n" + + " 9 dup\n" + + " 10 ldc [20]\n" + + " 12 invokespecial java.io.FileInputStream(java.lang.String) [22]\n" + + " 15 astore 4 [fis]\n" + + " 17 iload_1 [i]\n" + + " 18 iconst_2\n" + + " 19 if_icmpne 38\n" + + " 22 aload 4 [fis]\n" + + " 24 ifnull 32\n" + + " 27 aload 4 [fis]\n" + + " 29 invokevirtual java.io.FileInputStream.close() : void [25]\n" + + " 32 aload_0 [this]\n" + // return 1 + " 33 " + xBarCall + + " 36 pop\n" + + " 37 return\n" + + " 38 aload 4 [fis]\n" + + " 40 ifnull 86\n" + + " 43 aload 4 [fis]\n" + + " 45 invokevirtual java.io.FileInputStream.close() : void [25]\n" + + " 48 goto 86\n" + + " 51 astore_2\n" + + " 52 aload 4 [fis]\n" + + " 54 ifnull 62\n" + + " 57 aload 4 [fis]\n" + + " 59 invokevirtual java.io.FileInputStream.close() : void [25]\n" + + " 62 aload_2\n" + + " 63 athrow\n" + + " 64 astore_3\n" + + " 65 aload_2\n" + + " 66 ifnonnull 74\n" + + " 69 aload_3\n" + + " 70 astore_2\n" + + " 71 goto 84\n" + + " 74 aload_2\n" + + " 75 aload_3\n" + + " 76 if_acmpeq 84\n" + + " 79 aload_2\n" + + " 80 aload_3\n" + + " 81 invokevirtual java.lang.Throwable.addSuppressed(java.lang.Throwable) : void [32]\n" + + " 84 aload_2\n" + + " 85 athrow\n" + + " 86 iload_1 [i]\n" + + " 87 bipush 35\n" + + " 89 if_icmpne 122\n" + + " 92 aload_0 [this]\n" + // return 2 + " 93 " + xBarCall + + " 96 pop\n" + + " 97 return\n" + + " 98 astore_2 [e]\n" + + " 99 aload_0 [this]\n" + + " 100 " + xBarCall + + " 103 pop\n" + + " 104 aload_0 [this]\n" + + " 105 " + xBarCall + + " 108 pop\n" + + " 109 goto 127\n" + + " 112 astore 5\n" + + " 114 aload_0 [this]\n" + + " 115 " + xBarCall + + " 118 pop\n" + + " 119 aload 5\n" + + " 121 athrow\n" + + " 122 aload_0 [this]\n" + + " 123 " + xBarCall + + " 126 pop\n" + + " 127 return\n" + + " Exception Table:\n" + + " [pc: 17, pc: 22] -> 51 when : any\n" + + " [pc: 6, pc: 32] -> 64 when : any\n" + + " [pc: 38, pc: 64] -> 64 when : any\n" + + " [pc: 2, pc: 32] -> 98 when : java.io.IOException\n" + + " [pc: 38, pc: 92] -> 98 when : java.io.IOException\n" + + " [pc: 2, pc: 32] -> 112 when : any\n" + + " [pc: 38, pc: 92] -> 112 when : any\n" + + " [pc: 98, pc: 104] -> 112 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 2, line: 7]\n" + + " [pc: 17, line: 8]\n" + + " [pc: 22, line: 9]\n" + + " [pc: 32, line: 15]\n" + + " [pc: 37, line: 8]\n" + + " [pc: 38, line: 9]\n" + + " [pc: 86, line: 10]\n" + + " [pc: 92, line: 15]\n" + + " [pc: 97, line: 11]\n" + + " [pc: 98, line: 12]\n" + + " [pc: 99, line: 13]\n" + + " [pc: 104, line: 15]\n" + + " [pc: 112, line: 14]\n" + + " [pc: 114, line: 15]\n" + + " [pc: 119, line: 16]\n" + + " [pc: 122, line: 15]\n" + + " [pc: 127, line: 17]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 128] local: this index: 0 type: X\n" + + " [pc: 2, pc: 128] local: i index: 1 type: int\n" + + " [pc: 17, pc: 62] local: fis index: 4 type: java.io.FileInputStream\n" + + " [pc: 99, pc: 104] local: e index: 2 type: java.io.IOException\n" + + " Stack map table: number of frames 12\n" + + " [pc: 32, full, stack: {}, locals: {X, int, java.lang.Throwable, java.lang.Throwable, java.io.FileInputStream}]\n" + + " [pc: 38, same]\n" + + " [pc: 51, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 62, chop 1 local(s)]\n" + + " [pc: 64, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 74, same]\n" + + " [pc: 84, same]\n" + + " [pc: 86, chop 2 local(s)]\n" + + " [pc: 98, same_locals_1_stack_item, stack: {java.io.IOException}]\n" + + " [pc: 112, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 122, same]\n" + + " [pc: 127, same]\n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=380927 + // Verify the reduced range of locals. + public void testBug380927() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public final static Object f() {\n" + + " final Object a = null;\n" + + " Object b;\n" + + " label: do {\n" + + " switch (0) {\n" + + " case 1: {\n" + + " b = a;\n" + + " }\n" + + " break;\n" + + " default:\n" + + " break label;\n" + + " }\n" + + " } while (true);\n" + + " return a;\n" + + " }\n" + + " public static void main(final String[] args) {\n" + + " f();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 ()Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 2\n" + + " public static final java.lang.Object f();\n" + + " 0 aconst_null\n" + + " 1 astore_0 [a]\n" + + " 2 iconst_0\n" + + " 3 tableswitch default: 25\n" + + " case 1: 20\n" + + " 20 aload_0 [a]\n" + + " 21 astore_1 [b]\n" + + " 22 goto 2\n" + + " 25 aload_0 [a]\n" + + " 26 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 6]\n" + + " [pc: 20, line: 8]\n" + + " [pc: 22, line: 10]\n" + + " [pc: 25, line: 15]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 27] local: a index: 0 type: java.lang.Object\n" + + " [pc: 22, pc: 25] local: b index: 1 type: java.lang.Object\n" + + " Stack map table: number of frames 3\n" + + " [pc: 2, append: {java.lang.Object}]\n" + + " [pc: 20, same]\n" + + " [pc: 25, same]\n" + + " \n"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + // from https://bugs.eclipse.org/bugs/show_bug.cgi?id=385593#c1 + public void test385593_1() throws Exception { + this.runConformTest( + new String[] { + "stackmap/StackMapTableFormatError.java", + "package stackmap;\n" + + "\n" + + "import java.util.Collection;\n" + + "import java.util.Collections;\n" + + "\n" + + "/**\n" + + " * If compiled with Eclipse (compiler target >= 1.6) this snippet causes the\n" + + " * error \"java.lang.ClassFormatError: StackMapTable format error: bad\n" + + " * verification type\" when executed with JaCoCo code coverage. JaCoCo seems to\n" + + " * get confused by unexpected stackmap frames generated by ECJ.\n" + + " */\n" + + "public class StackMapTableFormatError {\n" + + "\n" + + " public static Object exec(Collection set, Object a,\n" + + " boolean b) {\n" + + " for (Object e : set) {\n" + + " if (a != null && (e == null || b)) {\n" + + " continue;\n" + + " }\n" + + " return null;\n" + + " }\n" + + " return null;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " exec(Collections.emptySet(), null, false);\n" + + " }\n" + + "\n" + + "}\n" + }); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR+File.separator+"stackmap"+File.separator+"StackMapTableFormatError.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #15 (Ljava/util/Collection;Ljava/lang/Object;Z)Ljava/lang/Object;\n" + + " // Signature: (Ljava/util/Collection;Ljava/lang/Object;Z)Ljava/lang/Object;\n" + + " // Stack: 1, Locals: 5\n" + + " public static java.lang.Object exec(java.util.Collection set, java.lang.Object a, boolean b);\n" + + " 0 aload_0 [set]\n" + + " 1 invokeinterface java.util.Collection.iterator() : java.util.Iterator [18] [nargs: 1]\n" + + " 6 astore 4\n" + + " 8 goto 36\n" + + " 11 aload 4\n" + + " 13 invokeinterface java.util.Iterator.next() : java.lang.Object [24] [nargs: 1]\n" + + " 18 astore_3 [e]\n" + + " 19 aload_1 [a]\n" + + " 20 ifnull 34\n" + + " 23 aload_3 [e]\n" + + " 24 ifnull 36\n" + + " 27 iload_2 [b]\n" + + " 28 ifeq 34\n" + + " 31 goto 36\n" + + " 34 aconst_null\n" + + " 35 areturn\n" + + " 36 aload 4\n" + + " 38 invokeinterface java.util.Iterator.hasNext() : boolean [30] [nargs: 1]\n" + + " 43 ifne 11\n" + + " 46 aconst_null\n" + + " 47 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 16]\n" + + " [pc: 19, line: 17]\n" + + " [pc: 31, line: 18]\n" + + " [pc: 34, line: 20]\n" + + " [pc: 36, line: 16]\n" + + " [pc: 46, line: 22]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 48] local: set index: 0 type: java.util.Collection\n" + + " [pc: 0, pc: 48] local: a index: 1 type: java.lang.Object\n" + + " [pc: 0, pc: 48] local: b index: 2 type: boolean\n" + + " [pc: 19, pc: 36] local: e index: 3 type: java.lang.Object\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 48] local: set index: 0 type: java.util.Collection\n" + + " Stack map table: number of frames 3\n" + + " [pc: 11, full, stack: {}, locals: {java.util.Collection, java.lang.Object, int, _, java.util.Iterator}]\n" + + " [pc: 34, full, stack: {}, locals: {java.util.Collection, java.lang.Object, int, java.lang.Object, java.util.Iterator}]\n" + + " [pc: 36, full, stack: {}, locals: {java.util.Collection, java.lang.Object, int, _, java.util.Iterator}]"; + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + // from https://bugs.eclipse.org/bugs/show_bug.cgi?id=385593#c11 + public void test385593_2() throws Exception { + this.runConformTest( + new String[] { + "snippet/X.java", + "package snippet;\n" + + "\n" + + "\n" + + "public class X { \n" + + " private void foo(boolean delete) { \n" + + " \n" + + " String s = bar(); \n" + + " StringBuffer buffer =new StringBuffer(); \n" + + " \n" + + " try { \n" + + " \n" + + " String[] datas = new String[] { \"\" }; \n" + + " Object[] data= new Object[] { s }; \n" + + " try { \n" + + " buffer.append(datas).append(data); \n" + + " } catch (Exception e) { \n" + + " if (e != null) \n" + + " throw e; \n" + + " return; \n" + + " } \n" + + " \n" + + " if (delete) \n" + + " buffer.delete(0, buffer.length()); \n" + + " \n" + + " } catch (Exception x) { \n" + + " } finally { \n" + + " buffer = null; \n" + + " } \n" + + " } \n" + + " \n" + + " String bar() { \n" + + " return \"\"; \n" + + " } \n" + + " \n" + + " public static void main(String[] args) { \n" + + " new X().foo(false); \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + "}\n" + }); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR+File.separator+"snippet"+File.separator+"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + "Stack map table: number of frames 7\n" + + " [pc: 49, full, stack: {java.lang.Exception}, locals: {snippet.X, int, java.lang.String, java.lang.StringBuffer, java.lang.String[], java.lang.Object[]}]\n" + + " [pc: 59, append: {java.lang.Exception}]\n" + + " [pc: 62, chop 1 local(s)]\n" + + " [pc: 79, full, stack: {java.lang.Exception}, locals: {snippet.X, int, java.lang.String, java.lang.StringBuffer}]\n" + + " [pc: 86, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 93, same]\n" + + " [pc: 95, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + // from https://bugs.eclipse.org/bugs/show_bug.cgi?id=394718 + public void test394718() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " public static Boolean test() throws Exception\n" + + " {\n" + + " try\n" + + " {\n" + + " for (int i = 0; i < 1; i++)\n" + + " {\n" + + " long status = System.currentTimeMillis();\n" + + " if (status < 0)\n" + + " return false;\n" + + " if (status == 1)\n" + + " return false;\n" + + " }\n" + + " \n" + + " return false;\n" + + " }\n" + + " finally\n" + + " {\n" + + " System.currentTimeMillis();\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) throws Exception\n" + + " {\n" + + " System.out.print(\"Starting\");\n" + + " test();\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}" + }, + "StartingDone"); + } + + // https://bugs.eclipse.org/412203 + public void testBug412203_a() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_7) return; // using <> + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_NULL_REFERENCE, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + this.runConformTest( + new String[] { + "X2.java", + "import java.util.*;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNullByDefault;\n" + + "\n" + + "class Y {\n" + + " public Y() { }\n" + + "}\n" + + "\n" + + "@NonNullByDefault\n" + + "abstract class X1 {\n" + + "\n" + + " private Object a;\n" + + " private Object b;\n" + + " private Object c;\n" + + " private Object d;\n" + + " private Object e;\n" + + " private Object f;\n" + + "\n" + + " protected Object name;\n" + + "\n" + + " @SuppressWarnings(\"null\")\n" + + " protected X1() {\n" + + " super ();\n" + + " }\n" + + "\n" + + "}\n" + + "public class X2 extends X1 {\n" + + "\n" + + "\n" + + " public static final int ID = 4711;\n" + + "\n" + + " private Object x;\n" + + " private Object y;\n" + + " private Object z;\n" + + "\n" + + " private Runnable runable = new Runnable () {\n" + + " @Override\n" + + " public void run () {\n" + + " // whatever\n" + + " }\n" + + " };\n" + + "\n" + + " private void init () {\n" + + " final Object selector = new Object ();\n" + + " this.name = new Object ();\n" + + " LinkedList invalidCharactersList = new LinkedList<> ();\n" + + " char[] invalidCharacters = new char[invalidCharactersList.size ()];\n" + + " for (int i = 0; i < invalidCharacters.length; i++) {\n" + + " invalidCharacters[i] = invalidCharactersList.get (i).charValue ();\n" + + " }\n" + + " Y inputVerifier = new Y();\n" + + " }\n" + + "\n" + + "}\n", + }, + "", + getLibsWithNullAnnotations(ClassFileConstants.JDK1_7), + true/*flush*/, + null/*vmArgs*/, + options, + null/*requestor*/, + true/*skipJavac*/); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X2.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #16 ()V\n" + + " // Stack: 4, Locals: 5\n" + + " private void init();\n" + + " 0 new java.lang.Object [32]\n" + + " 3 dup\n" + + " 4 invokespecial java.lang.Object() [34]\n" + + " 7 astore_1 [selector]\n" + + " 8 aload_0 [this]\n" + + " 9 new java.lang.Object [32]\n" + + " 12 dup\n" + + " 13 invokespecial java.lang.Object() [34]\n" + + " 16 putfield X2.name : java.lang.Object [35]\n" + + " 19 new java.util.LinkedList [38]\n" + + " 22 dup\n" + + " 23 invokespecial java.util.LinkedList() [40]\n" + + " 26 astore_2 [invalidCharactersList]\n" + + " 27 aload_2 [invalidCharactersList]\n" + + " 28 invokevirtual java.util.LinkedList.size() : int [41]\n" + + " 31 newarray char [5]\n" + + " 33 astore_3 [invalidCharacters]\n" + + " 34 iconst_0\n" + + " 35 istore 4 [i]\n" + + " 37 goto 59\n" + + " 40 aload_3 [invalidCharacters]\n" + + " 41 iload 4 [i]\n" + + " 43 aload_2 [invalidCharactersList]\n" + + " 44 iload 4 [i]\n" + + " 46 invokevirtual java.util.LinkedList.get(int) : java.lang.Object [45]\n" + + " 49 checkcast java.lang.Character [49]\n" + + " 52 invokevirtual java.lang.Character.charValue() : char [51]\n" + + " 55 castore\n" + + " 56 iinc 4 1 [i]\n" + + " 59 iload 4 [i]\n" + + " 61 aload_3 [invalidCharacters]\n" + + " 62 arraylength\n" + + " 63 if_icmplt 40\n" + + " 66 new Y [55]\n" + + " 69 dup\n" + + " 70 invokespecial Y() [57]\n" + + " 73 astore 4 [inputVerifier]\n" + + " 75 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 44]\n" + + " [pc: 8, line: 45]\n" + + " [pc: 19, line: 46]\n" + + " [pc: 27, line: 47]\n" + + " [pc: 34, line: 48]\n" + + " [pc: 40, line: 49]\n" + + " [pc: 56, line: 48]\n" + + " [pc: 66, line: 51]\n" + + " [pc: 75, line: 52]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 76] local: this index: 0 type: X2\n" + + " [pc: 8, pc: 76] local: selector index: 1 type: java.lang.Object\n" + + " [pc: 27, pc: 76] local: invalidCharactersList index: 2 type: java.util.LinkedList\n" + + " [pc: 34, pc: 76] local: invalidCharacters index: 3 type: char[]\n" + + " [pc: 37, pc: 66] local: i index: 4 type: int\n" + + " [pc: 75, pc: 76] local: inputVerifier index: 4 type: Y\n" + + " Local variable type table:\n" + + " [pc: 27, pc: 76] local: invalidCharactersList index: 2 type: java.util.LinkedList\n" + + " Stack map table: number of frames 2\n" + + " [pc: 40, full, stack: {}, locals: {X2, java.lang.Object, java.util.LinkedList, char[], int}]\n" + + " [pc: 59, same]\n"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + // https://bugs.eclipse.org/412203 + // yet simplified version - using FieldReference + public void testBug412203_b() throws Exception { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_NULL_REFERENCE, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + this.runConformTest( + new String[] { + "X2.java", + "import java.util.LinkedList;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "abstract class X1 {\n" + + " protected @NonNull Object name = new Object();\n" + + "}\n" + + "\n" + + "public class X2 extends X1 {\n" + + " void init () {\n" + + " this.name = new Object ();\n" + + " LinkedList l = new LinkedList ();\n" + + " char[] cs = new char[l.size ()];\n" + + " for (int i = 0; i < cs.length; i++) {\n" + + " cs[i] = l.get (i).charValue ();\n" + + " }\n" + + " Object o2 = new Object();\n" + + " }\n" + + "}\n", + }, + "", + getLibsWithNullAnnotations(ClassFileConstants.JDK1_7), + true/*flush*/, + null/*vmArgs*/, + options, + null/*requestor*/, + true/*skipJavac*/); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X2.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 4, Locals: 4\n" + + " void init();\n" + + " 0 aload_0 [this]\n" + + " 1 new java.lang.Object [15]\n" + + " 4 dup\n" + + " 5 invokespecial java.lang.Object() [17]\n" + + " 8 putfield X2.name : java.lang.Object [18]\n" + + " 11 new java.util.LinkedList [22]\n" + + " 14 dup\n" + + " 15 invokespecial java.util.LinkedList() [24]\n" + + " 18 astore_1 [l]\n" + + " 19 aload_1 [l]\n" + + " 20 invokevirtual java.util.LinkedList.size() : int [25]\n" + + " 23 newarray char [5]\n" + + " 25 astore_2 [cs]\n" + + " 26 iconst_0\n" + + " 27 istore_3 [i]\n" + + " 28 goto 48\n" + + " 31 aload_2 [cs]\n" + + " 32 iload_3 [i]\n" + + " 33 aload_1 [l]\n" + + " 34 iload_3 [i]\n" + + " 35 invokevirtual java.util.LinkedList.get(int) : java.lang.Object [29]\n" + + " 38 checkcast java.lang.Character [33]\n" + + " 41 invokevirtual java.lang.Character.charValue() : char [35]\n" + + " 44 castore\n" + + " 45 iinc 3 1 [i]\n" + + " 48 iload_3 [i]\n" + + " 49 aload_2 [cs]\n" + + " 50 arraylength\n" + + " 51 if_icmplt 31\n" + + " 54 new java.lang.Object [15]\n" + + " 57 dup\n" + + " 58 invokespecial java.lang.Object() [17]\n" + + " 61 astore_3 [o2]\n" + + " 62 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " [pc: 11, line: 12]\n" + + " [pc: 19, line: 13]\n" + + " [pc: 26, line: 14]\n" + + " [pc: 31, line: 15]\n" + + " [pc: 45, line: 14]\n" + + " [pc: 54, line: 17]\n" + + " [pc: 62, line: 18]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 63] local: this index: 0 type: X2\n" + + " [pc: 19, pc: 63] local: l index: 1 type: java.util.LinkedList\n" + + " [pc: 26, pc: 63] local: cs index: 2 type: char[]\n" + + " [pc: 28, pc: 54] local: i index: 3 type: int\n" + + " [pc: 62, pc: 63] local: o2 index: 3 type: java.lang.Object\n" + + " Local variable type table:\n" + + " [pc: 19, pc: 63] local: l index: 1 type: java.util.LinkedList\n" + + " Stack map table: number of frames 2\n" + + " [pc: 31, append: {java.util.LinkedList, char[], int}]\n" + + " [pc: 48, same]\n" + + "}"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + // https://bugs.eclipse.org/412203 + // yet simplified version - using SingleNameReference + public void testBug412203_c() throws Exception { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, JavaCore.ENABLED); + options.put(JavaCore.COMPILER_PB_NULL_REFERENCE, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_VIOLATION, JavaCore.ERROR); + options.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.WARNING); + options.put(JavaCore.COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS, JavaCore.ENABLED); + this.runConformTest( + new String[] { + "X2.java", + "import java.util.LinkedList;\n" + + "\n" + + "import org.eclipse.jdt.annotation.NonNull;\n" + + "\n" + + "abstract class X1 {\n" + + " protected @NonNull Object name = new Object();\n" + + "}\n" + + "\n" + + "public class X2 extends X1 {\n" + + " void init () {\n" + + " name = new Object ();\n" + + " LinkedList l = new LinkedList ();\n" + + " char[] cs = new char[l.size ()];\n" + + " for (int i = 0; i < cs.length; i++) {\n" + + " cs[i] = l.get (i).charValue ();\n" + + " }\n" + + " Object o2 = new Object();\n" + + " }\n" + + "}\n", + }, + "", + getLibsWithNullAnnotations(ClassFileConstants.JDK1_7), + true/*flush*/, + null/*vmArgs*/, + options, + null/*requestor*/, + true/*skipJavac*/); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X2.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 4, Locals: 4\n" + + " void init();\n" + + " 0 aload_0 [this]\n" + + " 1 new java.lang.Object [15]\n" + + " 4 dup\n" + + " 5 invokespecial java.lang.Object() [17]\n" + + " 8 putfield X2.name : java.lang.Object [18]\n" + + " 11 new java.util.LinkedList [22]\n" + + " 14 dup\n" + + " 15 invokespecial java.util.LinkedList() [24]\n" + + " 18 astore_1 [l]\n" + + " 19 aload_1 [l]\n" + + " 20 invokevirtual java.util.LinkedList.size() : int [25]\n" + + " 23 newarray char [5]\n" + + " 25 astore_2 [cs]\n" + + " 26 iconst_0\n" + + " 27 istore_3 [i]\n" + + " 28 goto 48\n" + + " 31 aload_2 [cs]\n" + + " 32 iload_3 [i]\n" + + " 33 aload_1 [l]\n" + + " 34 iload_3 [i]\n" + + " 35 invokevirtual java.util.LinkedList.get(int) : java.lang.Object [29]\n" + + " 38 checkcast java.lang.Character [33]\n" + + " 41 invokevirtual java.lang.Character.charValue() : char [35]\n" + + " 44 castore\n" + + " 45 iinc 3 1 [i]\n" + + " 48 iload_3 [i]\n" + + " 49 aload_2 [cs]\n" + + " 50 arraylength\n" + + " 51 if_icmplt 31\n" + + " 54 new java.lang.Object [15]\n" + + " 57 dup\n" + + " 58 invokespecial java.lang.Object() [17]\n" + + " 61 astore_3 [o2]\n" + + " 62 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " [pc: 11, line: 12]\n" + + " [pc: 19, line: 13]\n" + + " [pc: 26, line: 14]\n" + + " [pc: 31, line: 15]\n" + + " [pc: 45, line: 14]\n" + + " [pc: 54, line: 17]\n" + + " [pc: 62, line: 18]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 63] local: this index: 0 type: X2\n" + + " [pc: 19, pc: 63] local: l index: 1 type: java.util.LinkedList\n" + + " [pc: 26, pc: 63] local: cs index: 2 type: char[]\n" + + " [pc: 28, pc: 54] local: i index: 3 type: int\n" + + " [pc: 62, pc: 63] local: o2 index: 3 type: java.lang.Object\n" + + " Local variable type table:\n" + + " [pc: 19, pc: 63] local: l index: 1 type: java.util.LinkedList\n" + + " Stack map table: number of frames 2\n" + + " [pc: 31, append: {java.util.LinkedList, char[], int}]\n" + + " [pc: 48, same]\n" + + "}"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + public void testBug5409021() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X error = new X();\n" + + " error.reproduce(\"hello\");\n" + + " System.out.println(\"DONE\");\n" + + " }\n" + + " \n" + + " public Object reproduce(Object param) throws RuntimeException {\n" + + " Object local;\n" + + " try {\n" + + " return param; \n" + + " } \n" + + " catch (RuntimeException e) {\n" + + " return null;\n" + + " } \n" + + " finally {\n" + + " if (param != null) {\n" + + " System.out.println(\"FINALLY\");\n" + + " }\n" + + " local = null;\n" + + " }\n" + + " }\n" + + "}\n" + + "", + }, + "FINALLY\n" + + "DONE"); + + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator +"X.class")); + String actualOutput = + disassembler.disassemble( + classFileBytes, + "\n", + ClassFileBytesDisassembler.DETAILED); + String expectedOutput = + " // Stack: 2, Locals: 6\n" + + " public java.lang.Object reproduce(java.lang.Object param) throws java.lang.RuntimeException;\n" + + " 0 aload_1 [param]\n" + + " 1 astore 5\n" + + " 3 aload_1 [param]\n" + + " 4 ifnull 15\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [23]\n" + + " 10 ldc [43]\n" + + " 12 invokevirtual java.io.PrintStream.println(java.lang.String) : void [31]\n" + + " 15 aconst_null\n" + + " 16 astore_2 [local]\n" + + " 17 aload 5\n" + + " 19 areturn\n" + + " 20 astore_3 [e]\n" + + " 21 aload_1 [param]\n" + + " 22 ifnull 33\n" + + " 25 getstatic java.lang.System.out : java.io.PrintStream [23]\n" + + " 28 ldc [43]\n" + + " 30 invokevirtual java.io.PrintStream.println(java.lang.String) : void [31]\n" + + " 33 aconst_null\n" + + " 34 astore_2 [local]\n" + + " 35 aconst_null\n" + + " 36 areturn\n" + + " 37 astore 4\n" + + " 39 aload_1 [param]\n" + + " 40 ifnull 51\n" + + " 43 getstatic java.lang.System.out : java.io.PrintStream [23]\n" + + " 46 ldc [43]\n" + + " 48 invokevirtual java.io.PrintStream.println(java.lang.String) : void [31]\n" + + " 51 aconst_null\n" + + " 52 astore_2 [local]\n" + + " 53 aload 4\n" + + " 55 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 3] -> 20 when : java.lang.RuntimeException\n" + + " [pc: 0, pc: 3] -> 37 when : any\n" + + " [pc: 20, pc: 21] -> 37 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 12]\n" + + " [pc: 3, line: 18]\n" + + " [pc: 7, line: 19]\n" + + " [pc: 15, line: 21]\n" + + " [pc: 17, line: 12]\n" + + " [pc: 20, line: 14]\n" + + " [pc: 21, line: 18]\n" + + " [pc: 25, line: 19]\n" + + " [pc: 33, line: 21]\n" + + " [pc: 35, line: 15]\n" + + " [pc: 37, line: 17]\n" + + " [pc: 39, line: 18]\n" + + " [pc: 43, line: 19]\n" + + " [pc: 51, line: 21]\n" + + " [pc: 53, line: 22]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 56] local: this index: 0 type: X\n" + + " [pc: 0, pc: 56] local: param index: 1 type: java.lang.Object\n" + + " [pc: 17, pc: 20] local: local index: 2 type: java.lang.Object\n" + + " [pc: 35, pc: 37] local: local index: 2 type: java.lang.Object\n" + + " [pc: 53, pc: 56] local: local index: 2 type: java.lang.Object\n" + + " [pc: 21, pc: 37] local: e index: 3 type: java.lang.RuntimeException\n" + + " Stack map table: number of frames 5\n" + + " [pc: 15, full, stack: {}, locals: {X, java.lang.Object, _, _, _, java.lang.Object}]\n" + + " [pc: 20, full, stack: {java.lang.RuntimeException}, locals: {X, java.lang.Object}]\n" + + " [pc: 33, full, stack: {}, locals: {X, java.lang.Object, _, java.lang.RuntimeException}]\n" + + " [pc: 37, full, stack: {java.lang.Throwable}, locals: {X, java.lang.Object}]\n" + + " [pc: 51, full, stack: {}, locals: {X, java.lang.Object, _, _, java.lang.Throwable}]\n" + + "}"; + + int index = actualOutput.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(actualOutput, 2)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, actualOutput); + } + } + + public void test551368() { + this.runConformTest( + new String[] { + "X.java", + "interface A {\n" + + "}\n" + + "class B implements A {\n" + + " public C c;\n" + + " \n" + + " protected B original() {\n" + + " return this;\n" + + " }\n" + + "}\n" + + "class C {\n" + + " C parent;\n" + + " A context;\n" + + "}\n" + + "class F extends C {\n" + + " \n" + + "}\n" + + "class G extends C {\n" + + " \n" + + "}\n" + + "abstract class D implements A {\n" + + " public F c;\n" + + "}\n" + + "class E implements A {\n" + + " public G c;\n" + + "}\n" + + "public class X {\n" + + " boolean foo(A a) {\n" + + " if (a instanceof B && a != ((B) a).original())\n" + + " return true;\n" + + " C aC = a instanceof D ? ((D) a).c :\n" + + " a instanceof E ? ((E) a).c : \n" + + " a instanceof B ? ((B) a).c :\n" + + " null;\n" + + " return aC != null ? foo(aC.parent.context) : false;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + public void test551368_2() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " int size;\n" + + " char[][][] elements;\n" + + "\n" + + " public X() {\n" + + " this.size = 0;\n" + + " this.elements = new char[10][][];\n" + + " }\n" + + "\n" + + " public void insertIntoArray(char[][][] target) {\n" + + " }\n" + + "\n" + + " public void add(char[][] newElement) {\n" + + " insertIntoArray(this.size < this.elements.length ? this.elements : new char[this.elements.length * 2][][]);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + public void test551368_3() { + this.runConformTest( + new String[] { + "X.java", + "class B {\n" + + " public boolean bar() {\n" + + " return false;\n" + + " }\n" + + " public void foo() {}\n" + + "}\n" + + "public class X {\n" + + " \n" + + " public B foo(boolean test) {\n" + + " B b =\n" + + " test ?\n" + + " new B() {\n" + + " @Override\n" + + " public boolean bar() {\n" + + " return true;\n" + + " }\n" + + " } :\n" + + " new B();\n" + + " b.foo();\n" + + " return b;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + public void test558844() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static void main( String[] args ) {\n" + + " System.out.println(new X().getText());\n" + + " }\n" + + "\n" + + " public String getText() {\n" + + " Long lValue1 = getValue1();\n" + + " Long lValue2 = getValue2();\n" + + " return ( isValue1() ? \"\" : ( lValue1 == null ? \"\" : lValue1.toString() ) + \"-\" ) + ( lValue2 == null ? \"\" : lValue2.toString() );\n" + + " }\n" + + "\n" + + " private Long getValue1() {\n" + + " return Long.valueOf( 1 );\n" + + " }\n" + + "\n" + + " private Long getValue2() {\n" + + " return Long.valueOf( 1 );\n" + + " }\n" + + "\n" + + " private boolean isValue1() {\n" + + " return false;\n" + + " }\n" + + "}", + }, + "1-1"); + } + public void test562854() { + this.runConformTest( + new String[] { + "bug/Bug.java", + "package bug;\n" + + "public class Bug {\n" + + " public static void main(String[] args) {\n" + + " F(args.length > 1 ? pkg.Base.derived1() : pkg.Base.derived2());\n" + " }\n" + "\n" + + " static void F(pkg.Base base) {\n" + + " System.out.println(base.getClass().getCanonicalName());\n" + + " }\n" + + "}", + "pkg/Base.java", + "package pkg;\n" + + "public abstract class Base {\n" + + " public static Derived1 derived1() {\n" + + " return new Derived1();\n" + + " }\n" + + "\n" + + " public static Derived2 derived2() {\n" + + " return new Derived2();\n" + + " }\n" + + "}", + "pkg/Derived1.java", + "package pkg;\n" + + "class Derived1 extends Base {}", + "pkg/Derived2.java", + "package pkg;\n" + + "class Derived2 extends Derived1 {}", + }, + "pkg.Derived2"); + } + public void test562854_2() { + this.runConformTest( + new String[] { + "bug/Bug.java", + "package bug;\n" + + "public class Bug {\n" + + " public static void main(String[] args) {\n" + + " F(args.length > 1 ? pkg.Base.derived1() : pkg.Base.derived2());\n" + " }\n" + "\n" + + " static void F(pkg.Base base) {\n" + + " System.out.println(base.getClass().getCanonicalName());\n" + + " }\n" + + "}", + "pkg/Base.java", + "package pkg;\n" + + "public abstract class Base {\n" + + " public static Derived1 derived1() {\n" + + " return new Derived1();\n" + + " }\n" + + "\n" + + " public static Derived2 derived2() {\n" + + " return new Derived2();\n" + + " }\n" + + "}", + "pkg/Derived1.java", + "package pkg;\n" + + "public class Derived1 extends Base {}", + "pkg/Derived2.java", + "package pkg;\n" + + "public class Derived2 extends Derived1 {}", + }, + "pkg.Derived2"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java new file mode 100644 index 0000000000..d76b71d28d --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java @@ -0,0 +1,3421 @@ +/******************************************************************************* + * Copyright (c) 2000, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 185682 - Increment/decrement operators mark local variables as read + * bug 401271 - StackOverflowError when searching for a methods references + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class StaticImportTest extends AbstractComparableTest { + + // Static initializer to specify tests subset using TESTS_* static variables + // All specified tests which do not belong to the class are skipped... + static { +// TESTS_NAMES = new String[] { "test075" }; +// TESTS_NAMES = new String[] { "test085c" }; +// TESTS_NUMBERS = new int[] { 80 }; +// TESTS_RANGE = new int[] { 75, -1 }; + } + + public StaticImportTest(String name) { + super(name); + } + + public static Test suite() { + return buildComparableTestSuite(testClass()); + } + + public static Class testClass() { + return StaticImportTest.class; + } + + + public void test001() { + this.runConformTest( + new String[] { + "X.java", + "import static java.lang.Math.*;\n" + + "import static java.lang.Math.PI;\n" + + "public class X { double pi = abs(PI); }\n", + }, + ""); + } + + public void test002() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p2.Y.*;\n" + + "import static p2.Z.Zint;\n" + + "import static p2.Z.ZMember;\n" + + "public class X {\n" + + " int x = y(1);\n" + + " int y = Yint;\n" + + " int z = Zint;\n" + + " void m1(YMember m) {}\n" + + " void m2(ZMember m) {}\n" + + "}\n", + "p2/Y.java", + "package p2;\n" + + "public class Y {\n" + + " public static int Yint = 1;\n" + + " public static int y(int y) { return y; }\n" + + " public static class YMember {}\n" + + "}\n", + "p2/Z.java", + "package p2;\n" + + "public class Z {\n" + + " public static int Zint = 1;\n" + + " public static class ZMember {}\n" + + "}\n", + }, + ""); + } + + public void test003() { // test inheritance + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p2.Y.*;\n" + + "import static p2.Z.Zint;\n" + + "import static p2.Z.ZMember;\n" + + "public class X {\n" + + " int x = y(1);\n" + + " int y = Yint;\n" + + " int z = Zint;\n" + + " void m1(YMember m) {}\n" + + " void m2(ZMember m) {}\n" + + "}\n", + "p2/YY.java", + "package p2;\n" + + "public class YY {\n" + + " public static int Yint = 1;\n" + + " public static int y(int y) { return y; }\n" + + " public static class YMember {}\n" + + "}\n", + "p2/Y.java", + "package p2;\n" + + "public class Y extends YY {}\n", + "p2/ZZ.java", + "package p2;\n" + + "public class ZZ {\n" + + " public static int Zint = 1;\n" + + " public static class ZMember {}\n" + + "}\n", + "p2/Z.java", + "package p2;\n" + + "public class Z extends ZZ {}\n", + }, + ""); + this.runConformTest( + new String[] { + "X.java", + "import static p.A.C;\n" + + "public class X { int i = C; }\n", + "p/A.java", + "package p;\n" + + "public class A extends B implements I {}\n" + + "class B implements I {}\n", + "p/I.java", + "package p;\n" + + "public interface I { public static int C = 1; }\n" + }, + "" + ); + this.runConformTest( + new String[] { + "X.java", + "import static p.A.C;\n" + + "public class X { \n" + + " int i = C; \n" + + " int j = p.A.C; \n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A implements I {}\n" + + "interface I { public static int C = 1; }\n" + }, + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); + } + + public void test004() { // test static vs. instance + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p2.Y.*;\n" + + "import static p2.Z.Zint;\n" + + "import static p2.Z.ZMember;\n" + + "public class X {\n" + + " int x = y(1);\n" + + " int y = Yint;\n" + + " int z = Zint;\n" + + " void m1(YMember m) {}\n" + + " void m2(ZMember m) {}\n" + + "}\n", + "p2/Y.java", + "package p2;\n" + + "public class Y {\n" + + " public int Yint = 1;\n" + + " public int y(int y) { return y; }\n" + + " public class YMember {}\n" + + "}\n", + "p2/Z.java", + "package p2;\n" + + "public class Z {\n" + + " public int Zint = 1;\n" + + " public class ZMember {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 3)\n" + + " import static p2.Z.Zint;\n" + + " ^^^^^^^^^\n" + + "The import p2.Z.Zint cannot be resolved\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 4)\n" + + " import static p2.Z.ZMember;\n" + + " ^^^^^^^^^^^^\n" + + "The import p2.Z.ZMember cannot be resolved\n" + + "----------\n" + + "3. ERROR in p\\X.java (at line 6)\n" + + " int x = y(1);\n" + + " ^\n" + + "The method y(int) is undefined for the type X\n" + + "----------\n" + + "4. ERROR in p\\X.java (at line 7)\n" + + " int y = Yint;\n" + + " ^^^^\n" + + "Yint cannot be resolved to a variable\n" + + "----------\n" + + "5. ERROR in p\\X.java (at line 8)\n" + + " int z = Zint;\n" + + " ^^^^\n" + + "Zint cannot be resolved to a variable\n" + + "----------\n" + + "6. ERROR in p\\X.java (at line 9)\n" + + " void m1(YMember m) {}\n" + + " ^^^^^^^\n" + + "YMember cannot be resolved to a type\n" + + "----------\n" + + "7. ERROR in p\\X.java (at line 10)\n" + + " void m2(ZMember m) {}\n" + + " ^^^^^^^\n" + + "ZMember cannot be resolved to a type\n" + + "----------\n"); + } + + public void test005() { // test visibility + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p2.Y.*;\n" + + "import static p2.Z.Zint;\n" + + "import static p2.Z.ZMember;\n" + + "public class X {\n" + + " int x = y(1);\n" + + " int y = Yint;\n" + + " int z = Zint;\n" + + " void m1(YMember m) {}\n" + + " void m2(ZMember m) {}\n" + + "}\n", + "p2/Y.java", + "package p2;\n" + + "public class Y {\n" + + " static int Yint = 1;\n" + + " static int y(int y) { return y; }\n" + + " static class YMember {}\n" + + "}\n", + "p2/Z.java", + "package p2;\n" + + "public class Z {\n" + + " static int Zint = 1;\n" + + " static class ZMember {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 3)\n" + + " import static p2.Z.Zint;\n" + + " ^^^^^^^^^\n" + + "The field Z.p2.Z.Zint is not visible\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 4)\n" + + " import static p2.Z.ZMember;\n" + + " ^^^^^^^^^^^^\n" + + "The type p2.Z.ZMember is not visible\n" + + "----------\n" + + "3. ERROR in p\\X.java (at line 6)\n" + + " int x = y(1);\n" + + " ^\n" + + "The method y(int) from the type Y is not visible\n" + + "----------\n" + + "4. ERROR in p\\X.java (at line 7)\n" + + " int y = Yint;\n" + + " ^^^^\n" + + "The field Y.Yint is not visible\n" + + "----------\n" + + "5. ERROR in p\\X.java (at line 8)\n" + + " int z = Zint;\n" + + " ^^^^\n" + + "Zint cannot be resolved to a variable\n" + + "----------\n" + + "6. ERROR in p\\X.java (at line 9)\n" + + " void m1(YMember m) {}\n" + + " ^^^^^^^\n" + + "The type YMember is not visible\n" + + "----------\n" + + "7. ERROR in p\\X.java (at line 10)\n" + + " void m2(ZMember m) {}\n" + + " ^^^^^^^\n" + + "ZMember cannot be resolved to a type\n" + + "----------\n"); + } + + public void test006() { // test non static member types + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p2.Z.ZStatic;\n" + + "import static p2.Z.ZNonStatic;\n" + + "import p2.Z.ZNonStatic;\n" + + "public class X {\n" + + " void m2(ZStatic m) {}\n" + + " void m3(ZNonStatic m) {}\n" + + "}\n", + "p2/Z.java", + "package p2;\n" + + "public class Z {\n" + + " public static class ZStatic {}\n" + + " public class ZNonStatic {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 3)\n" + + " import static p2.Z.ZNonStatic;\n" + + " ^^^^^^^^^^^^^^^\n" + + "The import p2.Z.ZNonStatic cannot be resolved\n" + + "----------\n"); + } + + public void test007() { // test non static member types vs. static field + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p2.Z.ZFieldOverMember;\n" + + "public class X {\n" + + " int z = ZFieldOverMember;\n" + + "}\n", + "p2/Z.java", + "package p2;\n" + + "public class Z {\n" + + " public static int ZFieldOverMember = 1;\n" + + " public class ZFieldOverMember {}\n" + + "}\n", + }, + ""); + } + + public void test008() { // test static top level types + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static java.lang.System;\n" + + "public class X {}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " import static java.lang.System;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The static import java.lang.System must be a field or member type\n" + + "----------\n"); + } + + public void test009() { // test static top level types + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static java.lang.reflect.Method.*;\n" + + "public class X {Method m;}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 3)\n" + + " public class X {Method m;}\n" + + " ^^^^^^\n" + + "Method cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76174 + public void test010() { + this.runNegativeTest( + new String[] { + "X.java", + "import static java.lang.System.*;\n" + + "public class X {\n" + + " void foo() { arraycopy(); }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo() { arraycopy(); }\n" + + " ^^^^^^^^^\n" + + "The method arraycopy(Object, int, Object, int, int) in the type System is not applicable for the arguments ()\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=76360 + public void test011() { + this.runNegativeTest( + new String[] { + "X.java", + "import static p.Y.*;\n" + + "public class X extends p.Z {}\n" + + "class XX extends M.N {}\n" + + "class XXX extends M.Missing {}\n", + "p/YY.java", + "package p;\n" + + "public class YY {\n" + + " public static class M {\n" + + " public static class N {}\n" + + " }\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y extends YY {}\n", + "p/Z.java", + "package p;\n" + + "public class Z {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " class XXX extends M.Missing {}\n" + + " ^^^^^^^^^\n" + + "M.Missing cannot be resolved to a type\n" + + "----------\n"); + } + + public void test012() { + this.runConformTest( + new String[] { + "X.java", + "import static java.lang.Math.*;\n" + + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.println(max(1, 2));\n" + + " }\n" + + "}\n", + }, + "2"); + this.runConformTest( + new String[] { + "X.java", + "import static java.lang.Math.max;\n" + + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.println(max(1, 3));\n" + + " }\n" + + "}\n", + }, + "3"); + this.runConformTest( + new String[] { + "X.java", + "import static p1.C.F;\n" + + "import p2.*;\n" + + "public class X implements F {" + + " int i = F();" + + "}\n", + "p1/C.java", + "package p1;\n" + + "public class C {\n" + + " public static int F() { return 0; }\n" + + "}\n", + "p2/F.java", + "package p2;\n" + + "public interface F {}\n" + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77955 + public void test013() { + this.runNegativeTest( + new String[] { + "X.java", + "import static p.Y.ZZ;\n" + // found if ZZ is static + "import static p.Z.ZZ.WW;\n" + // found if WW is static + "import static p.Z.Zz.WW;\n" + // found if WW is static + "import static p.Z.Zz.*;\n" + // legal + "import static p.Z.Zz.Zzz;\n" + // legal + + "import static p.Y.Zz;\n" + // Zz is not static + "import static p.Z.Zz.WW.*;\n" + // import requires canonical name for p.W.WW + + "import p.Y.ZZ;\n" + // import requires canonical name for p.Z.ZZ + "import static p.Y.ZZ.*;\n" + // import requires canonical name for p.Z.ZZ + "import static p.Y.ZZ.WW;\n" + // import requires canonical name for p.Z.ZZ + "import static p.Y.ZZ.WW.*;\n" + // import requires canonical name for p.W.WW + "import static p.Y.ZZ.ZZZ;\n" + // import requires canonical name for p.Z.ZZ + "import static p.Y.ZZ.WW.WWW;\n" + // import requires canonical name for p.W.WW + "public class X {\n" + + " int i = Zzz + Zzzz;\n" + + " ZZ z;\n" + + " WW w;\n" + + "}\n", + "p/Y.java", + "package p;\n" + + "public class Y extends Z {}\n", + "p/Z.java", + "package p;\n" + + "public class Z {\n" + + " public class Zz extends W { public static final int Zzz = 0; public static final int Zzzz = 1; }\n" + + " public static class ZZ extends W { public static final int ZZZ = 0; }\n" + + "}\n", + "p/W.java", + "package p;\n" + + "public class W {\n" + + " public static class WW { public static final int WWW = 0; }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " import static p.Y.Zz;\n" + + " ^^^^^^\n" + + "The import p.Y.Zz cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " import static p.Z.Zz.WW.*;\n" + + " ^^^^^^^^^\n" + + "The import p.Z.Zz.WW cannot be resolved\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " import p.Y.ZZ;\n" + + " ^^^^^^\n" + + "The import p.Y.ZZ cannot be resolved\n" + + "----------\n" + + "4. ERROR in X.java (at line 9)\n" + + " import static p.Y.ZZ.*;\n" + + " ^^^^^^\n" + + "The import p.Y.ZZ cannot be resolved\n" + + "----------\n" + + "5. ERROR in X.java (at line 10)\n" + + " import static p.Y.ZZ.WW;\n" + + " ^^^^^^\n" + + "The import p.Y.ZZ cannot be resolved\n" + + "----------\n" + + "6. ERROR in X.java (at line 11)\n" + + " import static p.Y.ZZ.WW.*;\n" + + " ^^^^^^\n" + + "The import p.Y.ZZ cannot be resolved\n" + + "----------\n" + + "7. ERROR in X.java (at line 12)\n" + + " import static p.Y.ZZ.ZZZ;\n" + + " ^^^^^^\n" + + "The import p.Y.ZZ cannot be resolved\n" + + "----------\n" + + "8. ERROR in X.java (at line 13)\n" + + " import static p.Y.ZZ.WW.WWW;\n" + + " ^^^^^^\n" + + "The import p.Y.ZZ cannot be resolved\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78056 + public void test014() { + this.runConformTest( + new String[] { + "X.java", + "import static p.Z.ZZ.ZZZ;\n" + + "public class X {}\n", + "p/Z.java", + "package p;\n" + + "public class Z {\n" + + " public class ZZ { public static final int ZZZ = 0; }\n" + + "}\n", + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78075 + public void test015() { + this.runConformTest( + new String[] { + "X.java", + "import p.Z.*;\n" + + "import static p.Z.*;\n" + + "public class X { int i = COUNT; }\n", + "p/Z.java", + "package p;\n" + + "public class Z {\n" + + " public static final int COUNT = 0;\n" + + "}\n", + }, + "" + ); + this.runConformTest( + new String[] { + "X.java", + "import static p.Z.*;\n" + + "import p.Z.*;\n" + + "public class X { int i = COUNT; }\n", + "p/Z.java", + "package p;\n" + + "public class Z {\n" + + " public static final int COUNT = 0;\n" + + "}\n", + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77630 + public void test016() { + this.runNegativeTest( + new String[] { + "X.java", + "import static java.lang.*;\n" + + "public class X {}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static java.lang.*;\n" + + " ^^^^^^^^^\n" + + "Only a type can be imported. java.lang resolves to a package\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81724 + public void test017() { + this.runConformTest( + new String[] { + "bug/A.java", + "package bug;\n" + + "import static bug.C.*;\n" + + "public class A {\n" + + " private B b;\n" + + "}\n", + "bug/B.java", + "package bug;\n" + + "import static bug.C.*;\n" + + "public class B {\n" + + "}\n", + "bug/C.java", + "package bug;\n" + + "public class C {\n" + + " private B b;\n" + + "}\n", + }, + "" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81724 - variation + public void test018() { + this.runNegativeTest( + new String[] { + "bug/A.java", + "package bug;\n" + + "import static bug.C.*;\n" + + "public class A {\n" + + " private B b2 = b;\n" + + "}\n", + "bug/B.java", + "package bug;\n" + + "import static bug.C.*;\n" + + "public class B {\n" + + "}\n", + "bug/C.java", + "package bug;\n" + + "public class C {\n" + + " private static B b;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in bug\\A.java (at line 4)\n" + + " private B b2 = b;\n" + + " ^\n" + + "The field C.b is not visible\n" + + "----------\n" + + "----------\n" + + "1. WARNING in bug\\B.java (at line 2)\n" + + " import static bug.C.*;\n" + + " ^^^^^\n" + + "The import bug.C is never used\n" + + "----------\n" + + "----------\n" + + "1. WARNING in bug\\C.java (at line 3)\n" + + " private static B b;\n" + + " ^\n" + + "The value of the field C.b is not used\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81718 + public void test019() { + this.runNegativeTest( + new String[] { + "X.java", + "import static java.lang.Math.PI;\n" + + "\n" + + "public class X {\n" + + " boolean PI;\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. 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=82754 + public void test020() { + this.runNegativeTest( + new String[] { + "X.java", + "import static java.lang.Math.round;\n" + + "public class X {\n" + + " void foo() { cos(0); }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " void foo() { cos(0); }\n" + + " ^^^\n" + + "The method cos(int) is undefined for the type X\n" + + "----------\n" ); + } + + public void test021() { + this.runConformTest( + new String[] { + "X.java", + "import static p.B.foo;\n" + + "public class X {\n" + + " void test() { foo(); }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A { public static void foo() {} }\n", + "p/B.java", + "package p;\n" + + "public class B extends A { }\n" + }, + "" + ); + this.runNegativeTest( + new String[] { + "X.java", + "import static p.B.foo;\n" + + "public class X {\n" + + " void test() { foo(); }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A { public void foo() {} }\n", + "p/B.java", + "package p;\n" + + "public class B extends A { static void foo(int i) {} }\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static p.B.foo;\n" + + " ^^^^^^^\n" + + "The import p.B.foo cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " void test() { foo(); }\n" + + " ^^^\n" + + "The method foo() is undefined for the type X\n" + + "----------\n" + ); + } + + public void test022() { // test field/method collisions + this.runConformTest( + new String[] { + "X.java", + "import static p.A.F;\n" + + "import static p.B.F;\n" + + "public class X {\n" + + " int i = F;\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A { public static class F {} }\n", + "p/B.java", + "package p;\n" + + "public class B { public static int F = 2; }\n", + }, + "" + // no collision between field and member type + ); + this.runConformTest( + new String[] { + "X.java", + "import static p.A.F;\n" + + "import static p.B.F;\n" + + "public class X {\n" + + " int i = F + F();\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A { public static int F() { return 1; } }\n", + "p/B.java", + "package p;\n" + + "public class B { public static int F = 2; }\n", + }, + "" + // no collision between field and method + ); + this.runConformTest( + new String[] { + "X.java", + "import static p.A.F;\n" + + "import static p.B.F;\n" + + "public class X {\n" + + " int i = F;\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A { public static int F = 1; }\n", + "p/B.java", + "package p;\n" + + "public class B extends A {}\n", + }, + "" + // no collision between 2 fields that are the same + ); + this.runNegativeTest( + new String[] { + "X.java", + "import static p.A.F;\n" + + "import static p.B.F;\n" + + "public class X {\n" + + " int i = F;\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A { public static int F = 1; }\n", + "p/B.java", + "package p;\n" + + "public class B { public static int F = 2; }\n", + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " import static p.B.F;\n" + + " ^^^^^\n" + + "The import p.B.F collides with another import statement\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int i = F;\n" + + " ^\n" + + "The field F is ambiguous\n" + + "----------\n" + // F is already defined in a single-type import + ); + } + + public void test023() { + this.runConformTest( + new String[] { + "X.java", + "import static p.A.C;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(C);\n" + + " System.out.print(C());\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static int C = 1;\n" + + " public static int C() { return C + 3; }\n" + + "}\n" + }, + "14" + ); + this.runConformTest( // extra inheritance hiccup for method lookup + new String[] { + "X.java", + "import static p.A.C;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.print(C);\n" + + " System.out.print(C());\n" + + " }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A extends B {\n" + + " public static int C() { return C + 3; }\n" + + "}\n", + "p/B.java", + "package p;\n" + + "public class B {\n" + + " public static int C = 1;\n" + + "}\n" + }, + "14" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83376 + public void test024() { + this.runNegativeTest( + new String[] { + "p/B.java", + "package p;\n" + + "import static p.A.m;\n" + + "import static p2.C.m;\n" + + "class A { static void m() {} }\n" + + "public class B { public static void main(String[] args) { m(); } }\n", + "p2/C.java", + "package p2;\n" + + "public class C { public static void m() {} }\n" + }, + "----------\n" + + "1. ERROR in p\\B.java (at line 5)\n" + + " public class B { public static void main(String[] args) { m(); } }\n" + + " ^\n" + + "The method m() is ambiguous for the type B\n" + + "----------\n" + ); + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.A.m;\n" + + "import static p.B.m;\n" + + "public class X { void test() { m(); } }\n" + + "class B extends A {}\n", + "p/A.java", + "package p;\n" + + "public class A { public static int m() { return 0; } }\n" + }, + "" + ); + } + + public void test025() { + this.runConformTest( + new String[] { + "X.java", + "import static java.lang.Math.*;\n" + + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print(max(PI, 4));\n" + + " new Runnable() {\n" + + " public void run() {\n" + + " System.out.println(max(PI, 5));\n" + + " }\n" + + " }.run();\n" + + " }\n" + + "}\n" + }, + "4.05.0" + ); + } + + public void test026() { // ensure inherited problem fields do not stop package resolution + this.runConformTest( + new String[] { + "X.java", + "public class X extends Y { static void test() { java.lang.String.valueOf(0); } }\n" + + "class Y { private String java; }\n" + }, + "" + ); + } + + public void test027() { + this.runNegativeTest( + new String[] { + "X.java", + "import static p.ST.foo;\n" + + "public class X {\n" + + " \n" + + " foo bar;\n" + + "}\n", + "p/ST.java", + "package p; \n" + + "public class ST {\n" + + " public static int foo;\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " foo bar;\n" + + " ^^^\n" + + "foo cannot be resolved to a type\n" + + "----------\n"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87490 + public void test028() { + this.runConformTest( + new String[] { + "p1/Z.java",//==================== + "package p1;\n" + + "public class Z {\n" + + " public interface I {\n" + + " }\n" + + "}\n", + "q/Y.java",//==================== + "package q;\n" + + "import static p.X.I;\n" + + "import static p1.Z.I;\n" + + "public class Y implements I {\n" + + "}\n", + "p/X.java",//==================== + "package p;\n" + + "public enum X {\n" + + " I, J, K\n" + + "}\n" , + }, + ""); + // recompile Y against binaries + this.runConformTest( + new String[] { + "q/Y.java",//==================== + "package q;\n" + + "import static p.X.I;\n" + + "import static p1.Z.I;\n" + + "public class Y implements I {\n" + + "}\n", + }, + "", + null, + false, + null); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93913 + public void test029() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "import static p2.C.B;\n" + + "public class A extends B {\n" + + " void test() {" + + " int i = B();\n" + + " B b = null;\n" + + " b.fooB();\n" + + " b.fooC();\n" + + " fooC();\n" + + " }\n" + + "}\n", + "p1/B.java", + "package p1;\n" + + "public class B {\n" + + " public void fooB() {}\n" + + "}\n", + "p2/C.java", + "package p2;\n" + + "public class C {\n" + + " public static class B { public void fooC() {} }\n" + + " public static int B() { return 0; }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\A.java (at line 6)\n" + + " b.fooB();\n" + + " ^^^^\n" + + "The method fooB() is undefined for the type C.B\n" + + "----------\n" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=94262 + public void test030() { + this.runNegativeTest( + new String[] { + "p2/Test.java", + "package p2;\n" + + "import static p1.A.*;\n" + + "public class Test {\n" + + " Inner1 i; // not found\n" + + " Inner2 j;\n" + + "}\n", + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class Inner1 {}\n" + + " public static class Inner2 {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p2\\Test.java (at line 4)\n" + + " Inner1 i; // not found\n" + + " ^^^^^^\n" + + "Inner1 cannot be resolved to a type\n" + + "----------\n" + ); + this.runConformTest( + new String[] { + "p2/Test.java", + "package p2;\n" + + "import p1.A.*;\n" + + "import static p1.A.*;\n" + + "import static p1.A.*;\n" + + "public class Test {\n" + + " Inner1 i;\n" + + " Inner2 j;\n" + + "}\n", + "p1/A.java", + "package p1;\n" + + "public class A {\n" + + " public class Inner1 {}\n" + + " public static class Inner2 {}\n" + + "}\n", + }, + "" + ); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=95909 + public void test031() { + this.runNegativeTest( + new String[] { + "PointRadius.java", + "import static java.lang.Math.sqrt;\n" + + "\n" + + "public class PointRadius {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " double radius = 0;\n" + + " radius = sqrt(pondArea / Math.PI);\n" + + "\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in PointRadius.java (at line 7)\n" + + " radius = sqrt(pondArea / Math.PI);\n" + + " ^^^^^^^^\n" + + "pondArea cannot be resolved to a variable\n" + + "----------\n"); + } + + //http://bugs.eclipse.org/bugs/show_bug.cgi?id=97809 + public void test032() { + this.runConformTest( + new String[] { + "X.java", + "import static p.A.*;\n" + + "import static p.B.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {foo();}\n" + + "}\n", + "p/A.java", + "package p;" + + "public class A {\n" + + " public static void foo() {System.out.print(false);}\n" + + "}\n", + "p/B.java", + "package p;" + + "public class B extends A {\n" + + " public static void foo() {System.out.print(true);}\n" + + "}\n" + }, + "true"); + } + + //http://bugs.eclipse.org/bugs/show_bug.cgi?id=97809 + public void test032b() { + this.runNegativeTest( + new String[] { + "X2.java", + "import static p2.A.*;\n" + + "import static p2.B.*;\n" + + "public class X2 { void test() {foo();} }\n", + "p2/A.java", + "package p2;" + + "public class A {\n" + + " public static void foo() {}\n" + + "}\n", + "p2/B.java", + "package p2;" + + "public class B {\n" + + " public static void foo() {}\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X2.java (at line 3)\n" + + " public class X2 { void test() {foo();} }\n" + + " ^^^\n" + + "The method foo() is ambiguous for the type X2\n" + + "----------\n" + // reference to foo is ambiguous, both method foo() in p.B and method foo() in p.A match + ); + } + + //http://bugs.eclipse.org/bugs/show_bug.cgi?id=97809 + public void test032c() { + this.runConformTest( + new String[] { + "X3.java", + "import static p3.A.*;\n" + + "import static p3.B.foo;\n" + + "public class X3 {\n" + + " public static void main(String[] args) {foo();}\n" + + "}\n", + "p3/A.java", + "package p3;" + + "public class A {\n" + + " public static void foo() {System.out.print(false);}\n" + + "}\n", + "p3/B.java", + "package p3;" + + "public class B {\n" + + " public static void foo() {System.out.print(true);}\n" + + "}\n" + }, + "true"); + } + + //http://bugs.eclipse.org/bugs/show_bug.cgi?id=97809 + public void test032d() { + this.runConformTest( + new String[] { + "X4.java", + "import static p4.A.foo;\n" + + "import static p4.B.*;\n" + + "public class X4 {\n" + + " public static void main(String[] args) {foo();}\n" + + "}\n", + "p4/A.java", + "package p4;" + + "public class A {\n" + + " public static void foo() {System.out.print(true);}\n" + + "}\n", + "p4/B.java", + "package p4;" + + "public class B extends A {\n" + + " public static void foo() {System.out.print(false);}\n" + + "}\n" + }, + "true"); + } + + public void test033() { + this.runConformTest( + new String[] { + "X.java", + "import static p.A.*;\n" + + "import static p.B.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {foo(\"aa\");}\n" + + "}\n", + "p/A.java", + "package p;" + + "public class A {\n" + + " public static void foo(U u) {System.out.print(false);}\n" + + "}\n", + "p/B.java", + "package p;" + + "public class B extends A {\n" + + " public static void foo(String s) {System.out.print(true);}\n" + + "}\n" + }, + "true"); + } + + public void test033b() { + this.runConformTest( + new String[] { + "X2.java", + "import static p2.A.*;\n" + + "import static p2.B.*;\n" + + "public class X2 {\n" + + " public static void main(String[] args) {foo(\"aa\");}\n" + + "}\n", + "p2/A.java", + "package p2;" + + "public class A {\n" + + " public static void foo(String s) {System.out.print(true);}\n" + + "}\n", + "p2/B.java", + "package p2;" + + "public class B extends A {\n" + + " public static void foo(V v) {System.out.print(false);}\n" + + "}\n" + }, + "true"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=104198 + public void test034() { + this.runConformTest( + new String[] { + "test/AbstractTest.java", + "package test;\n" + + "public abstract class AbstractTest {\n" + + " \n" + + " public abstract MyEnum m(Z z);\n" + + " \n" + + " public enum MyEnum {\n" + + " A,B\n" + + " }\n" + + "}\n", + "test/X.java", + "package test;\n" + + "import static test.AbstractTest.MyEnum.*;\n" + + "public class X extends AbstractTest {\n" + + " @Override public MyEnum m(String s) {\n" + + " return A;\n" + + " }\n" + + "}\n" + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=117861 + public void test035() { + this.runConformTest( + new String[] { + "Bug.java", + "import static java.lang.String.format;\n" + + "public class Bug extends p.TestCase {\n" + + " public static void main(String[] args) {\n" + + " String msg = \"test\";\n" + + " System.out.print(format(msg));\n" + + " System.out.print(format(msg, 1, 2));\n" + + " }\n" + + "}\n", + "p/TestCase.java", + "package p;\n" + + "public class TestCase {\n" + + " static String format(String message, Object expected, Object actual) {return null;}\n" + + "}\n" + }, + "testtest"); + this.runNegativeTest( + new String[] { + "C.java", + "class A {\n" + + " static class B { void foo(Object o, String s) {} }\n" + + " void foo(int i) {}\n" + + "}\n" + + "class C extends A.B {\n" + + " void test() { foo(1); }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in C.java (at line 6)\n" + + " void test() { foo(1); }\n" + + " ^^^\n" + + "The method foo(Object, String) in the type A.B is not applicable for the arguments (int)\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "A.java", + "public class A {\n" + + " void foo(int i, long j) {}\n" + + " class B {\n" + + " void foo() { foo(1, 1); }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in A.java (at line 4)\n" + + " void foo() { foo(1, 1); }\n" + + " ^^^\n" + + "The method foo() in the type A.B is not applicable for the arguments (int, int)\n" + + "----------\n" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=126564 + public void test036() { + this.runNegativeTest( + new String[] { + "X.java", + "import static p.A.CONSTANT_I;\n" + + "import static p.A.CONSTANT_B;\n" + + "public class X {\n" + + " static int i = p.A.CONSTANT_I;\n" + + " static int j = p.A.CONSTANT_B;\n" + + " static int m = CONSTANT_I;\n" + + " static int n = CONSTANT_B;\n" + + "}", + "p/A.java", + "package p;\n" + + "public class A extends B implements I {}\n" + + "interface I { int CONSTANT_I = 1; }\n" + + "class B { int CONSTANT_B = 1; }", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " import static p.A.CONSTANT_B;\n" + + " ^^^^^^^^^^^^^^\n" + + "The field B.p.A.CONSTANT_B is not visible\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " static int j = p.A.CONSTANT_B;\n" + + " ^^^^^^^^^^\n" + + "The field B.CONSTANT_B is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " static int n = CONSTANT_B;\n" + + " ^^^^^^^^^^\n" + + "CONSTANT_B cannot be resolved to a variable\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=126564 - variation + public void test037() { + this.runConformTest( + new String[] { + "X.java", + "import static p.A.CONSTANT_I;\n" + + "import static p.A.CONSTANT_B;\n" + + "public class X {\n" + + " static int i = p.A.CONSTANT_I;\n" + + " static int j = p.A.CONSTANT_B;\n" + + " static int m = CONSTANT_I;\n" + + " static int n = CONSTANT_B;\n" + + "}", + "p/A.java", + "package p;\n" + + "public class A extends B implements I {}\n" + + "interface I { int CONSTANT_I = 1; }\n" + + "class B { public static int CONSTANT_B = 1; }", + }, + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=126564 - variation + public void test038() { + this.runNegativeTest( + new String[] { + "X.java", + "import static p.A.foo_I;\n" + + "import static p.A.foo_B;\n" + + "public class X {\n" + + " static int i = p.A.foo_I();\n" + + " static int j = p.A.foo_B();\n" + + " static int m = foo_I();\n" + + " static int n = foo_B();\n" + + "}", + "p/A.java", + "package p;\n" + + "public abstract class A extends B implements I {}\n" + + "interface I { int foo_I(); }\n" + + "class B { int foo_B() { return 2;} }", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static p.A.foo_I;\n" + + " ^^^^^^^^^\n" + + "The import p.A.foo_I cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " import static p.A.foo_B;\n" + + " ^^^^^^^^^\n" + + "The import p.A.foo_B cannot be resolved\n" + + "----------\n" + + "3. ERROR in X.java (at line 4)\n" + + " static int i = p.A.foo_I();\n" + + " ^^^^^^^^^^^\n" + + "Cannot make a static reference to the non-static method foo_I() from the type I\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " static int j = p.A.foo_B();\n" + + " ^^^^^\n" + + "The method foo_B() from the type B is not visible\n" + + "----------\n" + + "5. ERROR in X.java (at line 6)\n" + + " static int m = foo_I();\n" + + " ^^^^^\n" + + "The method foo_I() is undefined for the type X\n" + + "----------\n" + + "6. ERROR in X.java (at line 7)\n" + + " static int n = foo_B();\n" + + " ^^^^^\n" + + "The method foo_B() is undefined for the type X\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=126564 - variation + public void test039() { + this.runNegativeTest( + new String[] { + "X.java", + "import static p.A.foo_I;\n" + + "import static p.A.foo_B;\n" + + "public class X {\n" + + " static int i = p.A.foo_I();\n" + + " static int j = p.A.foo_B();\n" + + " static int m = foo_I();\n" + + " static int n = foo_B();\n" + + "}", + "p/A.java", + "package p;\n" + + "public abstract class A extends B implements I {}\n" + + "interface I { int foo_I(); }\n" + + "class B { public static int foo_B() { return 2;} }", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static p.A.foo_I;\n" + + " ^^^^^^^^^\n" + + "The import p.A.foo_I cannot be resolved\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " static int i = p.A.foo_I();\n" + + " ^^^^^^^^^^^\n" + + "Cannot make a static reference to the non-static method foo_I() from the type I\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " static int m = foo_I();\n" + + " ^^^^^\n" + + "The method foo_I() is undefined for the type X\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=87490 - variation + public void test040() { + this.runConformTest( + new String[] { + "p1/Z.java",//==================== + "package p1;\n" + + "public class Z {\n" + + " public interface I {\n" + + " }\n" + + "}\n", + "q/Y.java",//==================== + "package q;\n" + + "import static p.X.foo;\n" + + "import static p1.Z.I;\n" + + "public class Y implements I {\n" + + "}\n", + "p/X.java",//==================== + "package p;\n" + + "public class X {\n" + + " public static void foo() {}\n" + + "}\n" , + }, + ""); + // recompile Y against binaries + this.runConformTest( + new String[] { + "q/Y.java",//==================== + "package q;\n" + + "import static p.X.foo;\n" + + "import static p1.Z.I;\n" + + "public class Y implements I {\n" + + "}\n", + }, + "", + null, + false, + null); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=134118 + public void test041() { + this.runConformTest( + true, + new String[] { + "Test.java", + "import static p.I.*;\n" + + "import static p.J.*;\n" + + "public class Test {\n" + + " int i = Constant;\n" + + "}\n", + "p/I.java", + "package p;\n" + + "public interface I { static int Constant = 1; }\n", + "p/J.java", + "package p;\n" + + "public interface J extends I {}\n" , + }, + "----------\n" + + "1. WARNING in Test.java (at line 2)\n" + + " import static p.J.*;\n" + + " ^^^\n" + + "The import p.J is never used\n" + + "----------\n", + null, + null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=133737 + public void test042() { + this.runNegativeTest( + new String[] { + "ImportTest.java", + "import static p.ArrayTest.toString2;\n" + + "public class ImportTest extends SuperTest {\n" + + " public static void main(String[] args) { printArgs(1, 2, 3, 4, 5); }\n" + + " static void printArgs(Object... args) { toString2(args); }\n" + + "}\n" + + "class SuperTest {\n" + + " static void toString2() {}\n" + + "}\n", + "p/ArrayTest.java", + "package p;\n" + + "public class ArrayTest {\n" + + " public static void toString2(String[] args) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in ImportTest.java (at line 4)\n" + + " static void printArgs(Object... args) { toString2(args); }\n" + + " ^^^^^^^^^\n" + + "The method toString2() in the type SuperTest is not applicable for the arguments (Object[])\n" + + "----------\n" + // toString2() in SuperTest cannot be applied to (java.lang.Object[]) + ); + this.runNegativeTest( + new String[] { + "ImportTest.java", + "import static java.util.Arrays.toString;\n" + + "public class ImportTest {\n" + + " public static void main(String[] args) { printArgs(1, 2, 3, 4, 5); }\n" + + " static void printArgs(Object... args) { toString(args); }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in ImportTest.java (at line 4)\n" + + " static void printArgs(Object... args) { toString(args); }\n" + + " ^^^^^^^^\n" + + "The method toString() in the type Object is not applicable for the arguments (Object[])\n" + + "----------\n" + // toString() in java.lang.Object cannot be applied to (java.lang.Object[]) + ); + } + public void test042b() { + this.runConformTest( + new String[] { + "ImportTest.java", + "import static p.DefinesFoo.foo;\n" + + "public class ImportTest extends SuperImportTest {\n" + + " void test() { foo(\"fails?\"); }\n" + + "}\n" + + "class SuperImportTest {\n" + + " private void foo() {}\n" + + "}\n", + "p/DefinesFoo.java", + "package p;\n" + + "public class DefinesFoo {\n" + + " public static void foo(String s) {}\n" + + "}\n", + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=129388 + public void test043() { + this.runConformTest( + new String[] { + "B.java", + "import static java.lang.String.format;\n" + + "public class B extends p.A {\n" + + " void test() { format(\"fails?\"); }\n" + + " void test2() { format(\"fails?\", null); }\n" + + " void test3() { format(\"fails?\", null, null); }\n" + + " void test4() { format(\"fails?\", null, null, null); }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " static String format(String message, Object expected, Object actual) { return null; }\n" + + "}\n", + }, + "" + ); + } + // names potential confusion + public void test044() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.X.B.E;\n" + + "import static p.X.B.*;\n" + + "\n" + + "public class X {\n" + + " public static class Y {\n" + + " public enum E { FOO; }\n" + + " public static Object E() { return null; }\n" + + " public enum F { FOO; }\n" + + " public static Object F() { return null; }\n" + + " }\n" + + " public static class B extends Y {}\n" + + " Object f1 = E.FOO;\n" + + " Object f2 = E();\n" + + " Object f3 = F.FOO;\n" + + " Object f4 = F();\n" + + "}\n", + }, + "" + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=142772 + public void test045() { + this.runNegativeTest( + new String[] { + "X.java", + "import static test.Y.arrayList;\n" + + "public class X { static void arrayList(int x) { arrayList(); } }\n", + "test/Y.java", + "package test;\n" + + "public class Y { public static void arrayList() {} }\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public class X { static void arrayList(int x) { arrayList(); } }\n" + + " ^^^^^^^^^\n" + + "The method arrayList(int) in the type X is not applicable for the arguments ()\n" + + "----------\n" + // arrayList(int) in X cannot be applied to () + ); + } + public void test045b() { + this.runNegativeTest( + new String[] { + "test/One.java", + "package test;\n" + + "public class One { public static void arrayList(String s) {} }\n", + "test/Two.java", + "package test;\n" + + "public class Two { public void arrayList(int i) {} }\n", + "test/Three.java", + "package test;\n" + + "import static test.One.arrayList;\n" + + "public class Three extends Two { public static void test(String s) { arrayList(s); } }\n", + }, + "----------\n" + + "1. ERROR in test\\Three.java (at line 3)\n" + + " public class Three extends Two { public static void test(String s) { arrayList(s); } }\n" + + " ^^^^^^^^^\n" + + "The method arrayList(int) in the type Two is not applicable for the arguments (String)\n" + + "----------\n" + // arrayList(int) in test.Two cannot be applied to (java.lang.String) + ); + this.runNegativeTest( + new String[] { + "test/One.java", + "package test;\n" + + "public class One { public static void arrayList(String s) {} }\n", + "test/Two.java", + "package test;\n" + + "public class Two { public static void arrayList(int i) {} }\n", + "test/Three.java", + "package test;\n" + + "import static test.One.arrayList;\n" + + "public class Three extends Two { public static void test(String s) { arrayList(s); } }\n", + }, + "----------\n" + + "1. ERROR in test\\Three.java (at line 3)\n" + + " public class Three extends Two { public static void test(String s) { arrayList(s); } }\n" + + " ^^^^^^^^^\n" + + "The method arrayList(int) in the type Two is not applicable for the arguments (String)\n" + + "----------\n" + // arrayList(int) in test.Two cannot be applied to (java.lang.String) + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=133737 + public void test046() { + this.runNegativeTest( + new String[] { + "error/Exporter.java", + "package error;\n" + + "public class Exporter {\n" + + " public static String getName(Class c) {\n" + + " return null;\n" + + " }\n" + + "}", + "error/Importer.java", + "package error;\n" + + "import static error.Exporter.getName;\n" + + "public class Importer extends Base {\n" + + " public void testSomething() {\n" + + " getName();\n" + + " getName(Importer.class);\n" + + " }\n" + + "}", + "error/Base.java", + "package error;\n" + + "public class Base {\n" + + " public String getName() {\n" + + " return \"name\";\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in error\\Importer.java (at line 6)\n" + + " getName(Importer.class);\n" + + " ^^^^^^^\n" + + "The method getName() in the type Base is not applicable for the arguments (Class)\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=165069 + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=165081 + public void test047() { + this.runNegativeTest( + new String[] { + "sample/X.java", + "package sample;\n" + + "import static sample.X.TestEnum.V1;\n" + + "import static sample.X.TestEnum.V2;\n" + + "\n" + + "public class X {\n" + + " public static enum TestEnum {\n" + + " V1,\n" + + " V2\n" + + " }\n" + + "\n" + + " public void test(final TestEnum value) {\n" + + " switch (value) {\n" + + " case V1:\n" + + " case V2:\n" + + " }\n" + + " }\n" + + "\n" + + " public void ref() {\n" + + " final TestEnum v1 = TestEnum.V1;\n" + + " final TestEnum v2 = TestEnum.V2;\n" + + " int i;\n" + + " i++;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in sample\\X.java (at line 2)\n" + + " import static sample.X.TestEnum.V1;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The import sample.X.TestEnum.V1 is never used\n" + + "----------\n" + + "2. WARNING in sample\\X.java (at line 3)\n" + + " import static sample.X.TestEnum.V2;\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The import sample.X.TestEnum.V2 is never used\n" + + "----------\n" + + "3. ERROR in sample\\X.java (at line 22)\n" + + " i++;\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=165069 - variation + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=165081 - variation + public void test048() { + this.runNegativeTest( + new String[] { + "sample/X.java", + "package sample;\n" + + "import static sample.X.TestEnum.*;\n" + + "\n" + + "public class X {\n" + + " public static enum TestEnum {\n" + + " V1,\n" + + " V2\n" + + " }\n" + + "\n" + + " public void test(final TestEnum value) {\n" + + " switch (value) {\n" + + " case V1:\n" + + " case V2:\n" + + " }\n" + + " }\n" + + "\n" + + " public void ref() {\n" + + " final TestEnum v1 = TestEnum.V1;\n" + + " final TestEnum v2 = TestEnum.V2;\n" + + " int i;\n" + + " i++;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in sample\\X.java (at line 2)\n" + + " import static sample.X.TestEnum.*;\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "The import sample.X.TestEnum is never used\n" + + "----------\n" + + "2. ERROR in sample\\X.java (at line 21)\n" + + " i++;\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=165081 - variation + public void test049() { + this.runNegativeTest( + new String[] { + "sample/X.java", + "package sample;\n" + + "import static sample.X.*;\n" + + "public class X {\n" + + " public class Member {}\n" + + " public void ref() {\n" + + " int i;\n" + + " i++;\n" + + " }\n" + + "}", // ================= + }, + "----------\n" + + "1. WARNING in sample\\X.java (at line 2)\n" + + " import static sample.X.*;\n" + + " ^^^^^^^^\n" + + "The import sample.X is never used\n" + + "----------\n" + + "2. ERROR in sample\\X.java (at line 7)\n" + + " i++;\n" + + " ^\n" + + "The local variable i may not have been initialized\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=187329 + public void test050() { + this.runConformTest( + new String[] { + "p/A.java", + "package p;\n" + + "import static p.B.bar3;\n" + + "public class A { int a = bar3; }" , + "p/B.java", + "package p;\n" + + "import static p.Util.someStaticMethod;\n" + + "public class B {\n" + + " static final int bar = someStaticMethod();\n" + + " static final int bar2 = someStaticMethod();\n" + + " static final int bar3 = someStaticMethod();\n" + + "}" , + "p/C.java", + "package p;\n" + + "import static p.B.bar;\n" + + "public class C { int c = bar; }" , + "p/Util.java", + "package p;\n" + + "class Util { static int someStaticMethod() { return 0; } }" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=207433 + public void test051() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static r.Y.Z;\n" + + "import q.*;\n" + + "public class X extends Z {\n" + + " Z getZ() { return null; } \n" + + " void bar() {\n" + + " System.out.println(getZ().value);\n" + + " }\n" + + "}\n", + "q/Z.java", + "package q;\n" + + "import r.Y;\n" + + "public class Z extends Y {\n" + + "}\n", + "r/Y.java", + "package r;\n" + + "public class Y {\n" + + " public static String foo;\n" + + " public String value;\n" + + " public static String Z;\n" + + "}\n" , + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=207433 - variation + public void test052() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static r.Y.*;\n" + + "import q.*;\n" + + "public class X extends Z {\n" + + " Z getZ() { return null; } \n" + + " void bar() {\n" + + " System.out.println(getZ().value);\n" + + " }\n" + + "}\n", + "q/Z.java", + "package q;\n" + + "import r.Y;\n" + + "public class Z extends Y {\n" + + "}\n", + "r/Y.java", + "package r;\n" + + "public class Y {\n" + + " public static String foo;\n" + + " public String value;\n" + + " public static String Z;\n" + + "}\n" , + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=207433 - variation + public void test053() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static q.Y.foo;\n" + + "public class X extends Z {\n" + + " Z getZ() { return null; } \n" + + " void bar() {\n" + + " System.out.println(getZ().value);\n" + + " }\n" + + "}\n", + "p/Z.java", + "package p;\n" + + "import q.Y;\n" + + "public class Z extends Y {\n" + + "}\n", + "q/Y.java", + "package q;\n" + + "public class Y {\n" + + " public static int foo;\n" + + " public int value;\n" + + "}\n" , + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=193210 + public void test055() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static r.Y.Z;\n" + + "import q.*;\n" + + "import r.*;\n" + + "public class X extends Z {\n" + + " V getV() { return null; } \n" + + " void bar() {\n" + + " System.out.println(getV().value);\n" + + " }\n" + + "}\n", + "q/Z.java", + "package q;\n" + + "import r.Y;\n" + + "public class Z extends Y {\n" + + "}\n", + "r/Y.java", + "package r;\n" + + "public class Y extends V{\n" + + " public static class Z {}\n" + + "}\n" , + "r/V.java", + "package r;\n" + + "public class V {\n" + + " public Runnable value;\n" + + "}\n" , + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=193210 - variation + public void test056() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static r.Y.Z;\n" + + "import q.*;\n" + + "public class X extends Z {\n" + + " Z getZ() { return null; } \n" + + " void bar() {\n" + + " System.out.println(getZ().value);\n" + + " }\n" + + "}\n", + "q/Z.java", + "package q;\n" + + "import r.Y;\n" + + "public class Z extends Y {\n" + + "}\n", + "r/Y.java", + "package r;\n" + + "public class Y extends V{\n" + + " public static class Z {}\n" + + "}\n" , + "r/V.java", + "package r;\n" + + "public class V {\n" + + " public Runnable value;\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 7)\n" + + " System.out.println(getZ().value);\n" + + " ^^^^^\n" + + "value cannot be resolved or is not a field\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=193210 - variation + public void test057() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static r.Y.Z;\n" + + "import q.*;\n" + + "public class X extends Z {\n" + + " Z getZ() { return null; } \n" + + " void bar() {\n" + + " System.out.println(getZ().value);\n" + + " }\n" + + "}\n", + "q/Z.java", + "package q;\n" + + "import r.Y;\n" + + "public class Z extends Y {\n" + + "}\n", + "r/Y.java", + "package r;\n" + + "public class Y extends V{\n" + + " public static class Z {}\n" + + "}\n" , + "r/V.java", + "package r;\n" + + "public class V {\n" + + " public Runnable value;\n" + + "}\n" , + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 4)\n" + + " public class X extends Z {\n" + + " ^\n" + + "The type Y.Z is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 5)\n" + + " Z getZ() { return null; } \n" + + " ^\n" + + "The type Y.Z is not generic; it cannot be parameterized with arguments \n" + + "----------\n" + + "3. ERROR in p\\X.java (at line 7)\n" + + " System.out.println(getZ().value);\n" + + " ^^^^\n" + + "The method getZ() is undefined for the type X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=216930 + public void test058() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.A.a;\n" + + "public class X {\n" + + " void foo(W w) { a(w).a(w); }\n" + + "}\n", + "p/A.java", + "package p;\n" + + "public class A {\n" + + " public static A a(W... w) { return null; }\n" + + " public A a(W w) { return null; }\n" + + "}\n", + "p/W.java", + "package p;\n" + + "public class W {}\n" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=183211 + public void test059() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static q.A.a;\n" + + "public class X {\n" + + "}\n", + "q/A.java", + "package q;\n" + + "interface I {\n" + + " String a = \"\";\n" + + "}\n" + + "class B {\n" + + " public static String a;\n" + + "}\n" + + "public class A extends B implements I{\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=183211 - variation + public void test060() { + this.runConformTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static q.A.a;\n" + + "public class X {\n" + + "}\n", + "q/A.java", + "package q;\n" + + "interface I {\n" + + " String a(Object o);\n" + + "}\n" + + "class B {\n" + + " public static void a(){}\n" + + "}\n" + + "public abstract class A extends B implements I{\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=183211 - variation + public void test061() { + runConformTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "p/X.java", + "package p;\n" + + "import static q.A.a;\n" + + "public class X {\n" + + "}\n", + "q/A.java", + "package q;\n" + + "interface I {\n" + + " String a = \"\";\n" + + "}\n" + + "interface B {\n" + + " String a = \"2\";\n" + + "}\n" + + "public class A implements B, I {\n" + + "}\n", + }, + // compiler results + null /* do not check compiler log */, + // runtime results + "" /* expected output string */, + null /* do not check error string */, + // javac options + JavacTestOptions.DEFAULT /* javac test options */); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=183211 - variation + public void test062() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static q.A.a;\n" + + "public class X {\n" + + "}\n", + "q/A.java", + "package q;\n" + + "interface I {\n" + + " String a(Object o);\n" + + "}\n" + + "interface B {\n" + + " void a();\n" + + "}\n" + + "public abstract class A implements B, I{\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " import static q.A.a;\n" + + " ^^^^^\n" + + "The import q.A.a cannot be resolved\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=183211 - variation + public void test063() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static q.A.a;\n" + + "import static q.A.b;\n" + + "public class X {\n" + + " void test() {\n" + + " System.out.println(a);\n" + + " System.out.println(b);\n" + + " System.out.println(b(1));\n" + + " }\n" + + "}\n", + "q/A.java", + "package q;\n" + + "interface I {\n" + + " String a = \"1\";\n" + + " String b = \"2\";\n" + + "}\n" + + "interface J {\n" + + " String a = \"3\";\n" + + "}\n" + + "class B {\n" + + " public static String a = \"4\";\n" + + " public static String b = \"5\";\n" + + " public static String b(int i) { return \"6\"; }\n" + + "}\n" + + "public class A extends B implements J, I {}\n", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 6)\n" + + " System.out.println(a);\n" + + " ^\n" + + "The field a is ambiguous\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 7)\n" + + " System.out.println(b);\n" + + " ^\n" + + "The field b is ambiguous\n" + + "----------\n", + JavacTestOptions.DEFAULT + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=183211 - variation + public void test064() { + this.runNegativeTest( + new String[] { + "p1/X.java", + "package p1;\n" + + "import static p2.A.M;\n" + + "public class X {\n" + + " M m;\n" + + "}\n", + "p2/A.java", + "package p2;\n" + + "interface I { class M {} }\n" + + "class B { public static class M {} }\n" + + "public class A extends B implements I {}\n", + }, + "----------\n" + + "1. ERROR in p1\\X.java (at line 4)\n" + + " M m;\n" + + " ^\n" + + "The type M is ambiguous\n" + + "----------\n", + JavacTestOptions.DEFAULT + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=230026 + public void test065() { + this.runConformTest( + new String[] { + "X.java", + "import static p.I.E.C;\n" + + "\n" + + "class C {}\n" + + "class B {}\n" + + "public class X extends B{\n" + + "}", + "p/I.java", + "package p;\n" + + "\n" + + "public interface I {\n" + + " enum E { C }\n" + + "}", + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=230026 - variation + public void test066() { + this.runConformTest( + new String[] { + "X.java", + "import static p.I.E.C;\n" + + "\n" + + "class C {}\n" + + "class B {}\n" + + "public class X extends B{\n" + + "}", + "p/I.java", + "package p;\n" + + "\n" + + "public interface I {\n" + + " enum E { ; public static void C(){} }\n" + + "}", + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=230026 - variation + public void test067() { + this.runNegativeTest( + new String[] { + "X.java", + "import static p.I.E.C;\n" + + "\n" + + "class C {}\n" + + "class B {}\n" + + "public class X extends B{\n" + + "}", + "p/I.java", + "package p;\n" + + "\n" + + "public interface I {\n" + + " enum E { ; static void C(){} }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " import static p.I.E.C;\n" + + " ^^^^^^^\n" + + "The import p.I.E.C cannot be resolved\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=230026 - variation + public void test068() { + this.runConformTest( + new String[] { + "X.java", + "import static p.I.E.C;\n" + + "class C {}\n" + + "class B {}\n" + + "public class X extends B{\n" + + " static void test() { int i = C; }\n" + + "}", + "p/I.java", + "package p;\n" + + "public interface I {\n" + + " public static class E extends F {}\n" + + " public static class F { public static int C; }\n" + + "}", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=230026 - variation + public void test069() { + this.runConformTest( + new String[] { + "X.java", + "import static p.I.E.C;\n" + + "class C {}\n" + + "class B {}\n" + + "public class X extends B{\n" + + " static void test() { C(); }\n" + + "}", + "p/I.java", + "package p;\n" + + "public interface I {\n" + + " public static class E extends F {}\n" + + " public static class F { public static void C() {} }\n" + + "}", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 + public void test070() { + this.runConformTest( + new String[] { + "node/Test.java",//------------------------------ + "package node;\n" + + "public class Test {\n" + + " public static void node() {}\n" + + "}\n", + "node2/Test2.java",//------------------------------ + "package node2;\n" + + "import static node.Test.node;\n" + + "public class Test2 {\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 - variation + public void test071() { + this.runNegativeTest( + new String[] { + "node/Test/node.java",//------------------------------ + "package node.Test;\n" + + "public class node {\n" + + "}\n", + "node/Test.java",//------------------------------ + "package node;\n" + + "public class Test {\n" + + " public static void node() {}\n" + + "}\n", + "node2/Test2.java",//------------------------------ + "package node2;\n" + + "import node.Test;\n" + + "import static Test.node;\n" + + "public class Test2 {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in node\\Test.java (at line 2)\n" + + " public class Test {\n" + + " ^^^^\n" + + "The type Test collides with a package\n" + + "----------\n" + + "----------\n" + + "1. ERROR in node2\\Test2.java (at line 3)\n" + + " import static Test.node;\n" + + " ^^^^\n" + + "The import Test cannot be resolved\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=93913 - variation + public void test072() { + this.runNegativeTest( + new String[] { + "p1/A.java", + "package p1;\n" + + "import static p2.C.B;\n" + + "public class A extends B {\n" + + " void test() {" + + " int i = B;\n" + + " B b = null;\n" + + " int v1 = b.fooB;\n" + + " int v2 = b.fooC;\n" + + " int v3 = fooC;\n" + + " }\n" + + "}\n", + "p1/B.java", + "package p1;\n" + + "public class B {\n" + + " public int fooB;\n" + + "}\n", + "p2/C.java", + "package p2;\n" + + "public class C {\n" + + " public static class B { public int fooC; }\n" + + " public static int B;\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p1\\A.java (at line 6)\n" + + " int v1 = b.fooB;\n" + + " ^^^^\n" + + "fooB cannot be resolved or is not a field\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=256375 + public void test073() { + this.runNegativeTest( + new String[] { + "test/Outer.java", + "package test;\n" + + "import static test.Outer.Inner.VALUE;\n" + + "public class Outer {\n" + + " int i = VALUE;\n" + + " int i2 = Inner.VALUE;\n" + + " static class Inner {\n" + + " private static final int VALUE = 0;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in test\\Outer.java (at line 2)\n" + + " import static test.Outer.Inner.VALUE;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "The field Outer.Inner.test.Outer.Inner.VALUE is not visible\n" + + "----------\n" + + "2. ERROR in test\\Outer.java (at line 4)\n" + + " int i = VALUE;\n" + + " ^^^^^\n" + + "VALUE cannot be resolved to a variable\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=256375 - variation + public void test074() { + this.runConformTest( + new String[] { + "test/Outer.java", + "package test;\n" + + "import static test.Outer.Inner.*;\n" + + "public class Outer {\n" + + " int i = VALUE;\n" + + " int i2 = Inner.VALUE;\n" + + " static class Inner {\n" + + " private static final int VALUE = 0;\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865 + // To verify that a static import importing a type which has already been + // imported by a single type import is reported as duplicate + // while the other static members imported by it are not shadowed. + public void test075() { + this.runNegativeTest( + new String[] { + "A/A.java", + "package A;\n" + + "import B.B.C1;\n" + + "import static B.B.C1;\n" + + "public abstract class A {\n" + + " protected void A1(Object task) {\n" + + " C1 c = C1(task);\n" + + " }\n" + + "}\n", + "B/B.java", + "package B;\n" + + "final public class B {\n" + + " private B() {}\n" + + " public static class C1 {}\n" + + " public static C1 C1(Object o) {\n" + + " return new C1();\n" + + " }\n" + + "}\n", + }, + "" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865 + // To verify that a static import importing a static method doesn't collide + // with a single type import importing a non-static type with the same name as the method + public void test076() { + this.runConformTest( + new String[] { + "A/A.java", + "package A;\n" + + "import B.B.C1;\n" + + "import static B.B.C1;\n" + + "public class A {\n" + + " protected void A1(Object task) {\n" + + " C1 c1;\n" + + " int c = C1(task);\n" + + " }\n" + + "}\n", + "B/B.java", + "package B;\n" + + "final public class B {\n" + + " private B() {}\n" + + " public class C1 {}\n" + + " public static int C1(Object o) {\n" + + " return 1;\n" + + " }\n" + + "}\n", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865 + // To verify that two static imports importing the same type don't collide + public void test077() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1;\n" + + "import p2.A;\n" + + "import static p2.A.C;\n" + + "import static p1.B.C;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " if (C.CONST == 1) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + "}\n" + + "class B extends A {}", + "p2/A.java", + "package p2;\n" + + "public class A {\n" + + " public static class C {\n" + + " public static int CONST = 1;\n" + + " }\n" + + "}" + }, + "SUCCESS"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865 + // To verify that a static import importing a type which has already been + // imported by a single type import is reported as duplicate + // while the other static members imported by it are not shadowed. + public void test078() { + this.runNegativeTest( + new String[] { + "A/A.java", + "package A;\n" + + "import static B.B.C1;\n" + + "import B.B.C1;\n" + + "public abstract class A {\n" + + " protected void A1(Object task) {\n" + + " C1 c = C1(task);\n" + + " }\n" + + "}\n", + "B/B.java", + "package B;\n" + + "final public class B {\n" + + " private B() {}\n" + + " public static class C1 {}\n" + + " public static C1 C1(Object o) {\n" + + " return new C1();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in A\\A.java (at line 3)\n" + + " import B.B.C1;\n" + + " ^^^^^^\n" + + "The import B.B.C1 collides with another import statement\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865 + // To verify that a static import importing a type which has already been + // imported by a single type import is not reported as duplicate + // if they are just the same type + public void test079() { + this.runNegativeTest( + new String[] { + "A/A.java", + "package A;\n" + + "import static B.B.C1;\n" + + "import B.B.C1;\n" + + "public abstract class A {\n" + + " protected void A1(C1 c) {\n" + + " }\n" + + "}\n", + "B/B.java", + "package B;\n" + + "final public class B {\n" + + " public static class C1 {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in A\\A.java (at line 2)\n" + + " import static B.B.C1;\n" + + " ^^^^^^\n" + + "The import B.B.C1 is never used\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=336934 + public void test080() { + this.runNegativeTest( + new String[] { + "a/B.java", + "package a;\n" + + "public class B {}", + "external/Lib.java", + "package external;\n" + + "public class Lib {\n" + + " public static void m() {}\n" + + "}", + "a/B/C.java", + "package a.B;\n" + + "import static external.Lib.m;\n" + + "public class C {\n" + + " public void main() {\n" + + " m();\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in a\\B\\C.java (at line 1)\n" + + " package a.B;\n" + + " ^^^\n" + + "The package a.B collides with a type\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318401 + public void test081() { + this.runConformTest( + new String[] { + "Test.java", + "import static p1.Bar.B;\n" + + "import p3.Foo.*;\n" + + "public class Test {\n" + + " public static void main(String [] args){\n" + + " new Test().beginTest();" + + " }\n" + + " public void beginTest(){\n" + + " System.out.print(\"1 + 1 = \");\n" + + " if(alwaysTrue()) System.out.println(\"2\");\n" + + " else System.out.println(\"3\"); " + + " }\n" + + " public boolean alwaysTrue(){\n" + + " String myB = B.class.getCanonicalName();;\n" + // refers to p1.Bar.B (class) + " String realB = p1.Bar.B.class.getCanonicalName();;\n" + // refers to p1.Bar.B (class) + " B();\n" + // refers to p1.Bar.B() (method) + " return myB.equals(realB);\n" + + " }\n" + + "}\n", + "p1/Bar.java", + "package p1;\n" + + "public class Bar{\n" + + " public static class B{}\n" + + " final public static String B = new String(\"random\");\n" + + " public static void B(){}\n" + + "}\n", + "p3/Foo.java", + "package p3;\n" + + "public class Foo {\n" + + " public class B{\n" + + " public int a;\n" + + " }\n" + + "}\n" + }, + "1 + 1 = 2"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318401 + public void test082() { + this.runNegativeTest( + new String[] { + "p1/Bar.java", + "package p1;\n" + + "public class Bar{\n" + + " public static class B{}\n" + + " final public static String B = new String(\"random\");\n" + + " public static void B(){}\n" + + "}\n", + "p3/Foo.java", + "package p3;\n" + + "public class Foo {\n" + + " public class B{\n" + + " public int a;\n" + + " }\n" + + "}\n", + "p2/Test.java", + "package p2;\n" + + "import static p1.Bar.B;\n" + + "import p3.Foo.*;\n" + + "public class Test {\n" + + " public static void main(String [] args){\n" + + " new Test().beginTest();" + + " }\n" + + " public void beginTest(){\n" + + " System.out.print(\"1 + 1 = \");\n" + + " if(alwaysTrue()) System.out.println(\"2\");\n" + + " else System.out.println(\"3\"); " + + " }\n" + + " public boolean alwaysTrue(){\n" + + " B b = null;\n" + // refers to p1.Bar.B (class) + " String realB = B;\n" + // refers to p1.Bar.B (field) + " B();\n" + // refers to p1.Bar.B() (method) + " int abc = b.a;\n;" + // static import for Bar.B overshadows on demand import Foo.B + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in p2\\Test.java (at line 15)\n" + + " int abc = b.a;\n" + + " ^\n" + + "a cannot be resolved or is not a field\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318401 + public void test083() { + this.runConformTest( + new String[] { + "Test.java", + "import static p1.Bar.B;\n" + + "import p3.Foo.*;\n" + + "public class Test {\n" + + " public static void main(String [] args){\n" + + " new Test().test2();" + + " }\n" + + " public void test2(){\n" + + " System.out.println(B.toString());\n" + // Field obscures class B + " System.out.println(p1.Bar.B.toString());\n" + // Field obscures the class B + " System.out.println(B.class.getCanonicalName().toString());\n" + // the class B + " System.out.println(p1.Bar.B.class.getCanonicalName().toString());" + // class B + " }\n" + + "}\n", + "p1/Bar.java", + "package p1;\n" + + "public class Bar{\n" + + " public static class B{}\n" + + " final public static String B = new String(\"random\");\n" + + " public static void B(){}\n" + + "}\n", + "p3/Foo.java", + "package p3;\n" + + "public class Foo {\n" + + " public class B{\n" + + " public int a;\n" + + " }\n" + + "}\n" + }, + "random\n" + + "random\n" + + "p1.Bar.B\n" + + "p1.Bar.B"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318401 + // Check if we're able to find the correct static member type being imported, + // even though the import originally resolved to the static field of the same name, + // coming from the supertype + public void test084() { + this.runConformTest( + new String[] { + "Test.java", + "import static p1.Bar.B;\n" + + "import p3.Foo.*;\n" + + "public class Test {\n" + + " public static void main(String [] args){\n" + + " new Test().test2();" + + " }\n" + + " public void test2(){\n" + + " System.out.println(B.class.getCanonicalName().toString());\n" + // the class B + " System.out.println(p1.Bar.B.class.getCanonicalName().toString());" + // class B + " }\n" + + "}\n", + "p1/Bar.java", + "package p1;\n" + + "public class Bar extends SuperBar{\n" + + " public static class B{}\n" + + " public static void B(){}\n" + + "}\n", + "p1/SuperBar.java", + "package p1;\n" + + "public class SuperBar {\n" + + " final public static String B = new String(\"random\");\n" + + "}\n", + "p3/Foo.java", + "package p3;\n" + + "public class Foo {\n" + + " public class B{\n" + + " public int a;\n" + + " }\n" + + "}\n" + }, + "p1.Bar.B\n" + + "p1.Bar.B"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=361327 + // To verify that all static members are imported with a single static import statement + public void test085() { + this.runNegativeTest( + new String[] { + "Test.java", + "import static p1.Bar.B;\n" + + "import static p3.Foo.B;\n" + + "public class Test {\n" + + " public static void main(String [] args){\n" + + " new Test().test2();" + + " }\n" + + " public void test2(){\n" + + " System.out.println(B.class.getCanonicalName().toString());\n" + + " System.out.println(p1.Bar.B.class.getCanonicalName().toString());" + + " }\n" + + "}\n", + "p1/Bar.java", + "package p1;\n" + + "public class Bar{\n" + + " public static class B{}\n" + + " public static String B = new String(\"random\");\n" + + "}\n", + "p3/Foo.java", + "package p3;\n" + + "public class Foo {\n" + + " public static class B{\n" + + " }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " import static p3.Foo.B;\n" + + " ^^^^^^^^\n" + + "The import p3.Foo.B collides with another import statement\n" + + "----------\n" : + "----------\n" + + "1. ERROR in Test.java (at line 7)\n" + + " System.out.println(B.class.getCanonicalName().toString());\n" + + " ^\n" + + "The type B is ambiguous\n" + + "----------\n" + + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=361327 + // To verify that all static members are imported with a single static import statement, + // even from a supertype + public void test085a() { + this.runNegativeTest( + new String[] { + "Test.java", + "import static p1.Bar.B;\n" + + "import static p3.Foo.B;\n" + + "public class Test {\n" + + " public static void main(String [] args){\n" + + " new Test().test2();" + + " }\n" + + " public void test2(){\n" + + " System.out.println(B.class.getCanonicalName().toString());\n" + + " System.out.println(p1.Bar.B.class.getCanonicalName().toString());" + + " }\n" + + "}\n", + "p1/Bar.java", + "package p1;\n" + + "public class Bar extends SuperBar{\n" + + " public static void B(){}\n" + + "}\n", + "p1/SuperBar.java", + "package p1;\n" + + "public class SuperBar {\n" + + " public static class B{}\n" + + " final public static String B = new String(\"random\");\n" + + "}\n", + "p3/Foo.java", + "package p3;\n" + + "public class Foo {\n" + + " public static class B{\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " import static p3.Foo.B;\n" + + " ^^^^^^^^\n" + + "The import p3.Foo.B collides with another import statement\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=361327 + // To verify that all static members are imported with a single static import statement + // this tests checks collision with single type import + public void test085b() { + this.runNegativeTest( + new String[] { + "Test.java", + "import static p1.Bar.B;\n" + + "import p3.Foo.B;\n" + + "public class Test {\n" + + " public static void main(String [] args){\n" + + " new Test().test2();" + + " }\n" + + " public void test2(){\n" + + " System.out.println(B.class.getCanonicalName().toString());\n" + + " System.out.println(p1.Bar.B.class.getCanonicalName().toString());" + + " }\n" + + "}\n", + "p1/Bar.java", + "package p1;\n" + + "public class Bar{\n" + + " public static class B{}\n" + + " public static String B = new String(\"random\");\n" + + "}\n", + "p3/Foo.java", + "package p3;\n" + + "public class Foo {\n" + + " public class B{\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in Test.java (at line 2)\n" + + " import p3.Foo.B;\n" + + " ^^^^^^^^\n" + + "The import p3.Foo.B collides with another import statement\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=361327 + // To verify that all static members are imported with a single static import statement + // this tests checks collision with top level type + public void test085c() { + this.runNegativeTest( + new String[] { + "Test.java", + "import static p1.Bar.B;\n" + + "public class Test {\n" + + " public static void main(String [] args){\n" + + " new Test().test2();" + + " }\n" + + " public void test2(){\n" + + " System.out.println(B.class.getCanonicalName().toString());\n" + + " System.out.println(p1.Bar.B.class.getCanonicalName().toString());" + + " }\n" + + "}\n" + + "class B{\n" + + "}\n", + "p1/Bar.java", + "package p1;\n" + + "public class Bar{\n" + + " public static class B{}\n" + + " public static String B = new String(\"random\");\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Test.java (at line 1)\n" + + " import static p1.Bar.B;\n" + + " ^^^^^^^^\n" + + "The import p1.Bar.B conflicts with a type defined in the same file\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=361327 + // Test obscuring rules defined in JLS 7.5.3 + public void test086() { + this.runConformTest( + new String[] { + "Test.java", + "import static p1.Bar.B;\n" + + "import static p3.Foo.*;\n" + + "public class Test {\n" + + " public static void main(String [] args){\n" + + " new Test().test2();" + + " }\n" + + " public void test2(){\n" + + " B();\n" + // should be p1.Bar.B() and not p3.Foo.B() + " System.out.println(B.toString());\n" + // should be p1.Bar.B + " }\n" + + "}\n", + "p1/Bar.java", + "package p1;\n" + + "public class Bar{\n" + + " public static void B(){ System.out.println(\"Bar's method B\");}\n" + + " public static String B = new String(\"Bar's field B\");\n" + + "}\n", + "p3/Foo.java", + "package p3;\n" + + "public class Foo {\n" + + " public static void B(){ System.out.println(\"Foo's method B\");}\n" + + " public static String B = new String(\"Foo's field B\");\n" + + "}\n" + }, + "Bar\'s method B\n" + + "Bar\'s field B"); + } + + // https://bugs.eclipse.org/401271 - StackOverflowError when searching for a methods references + public void testBug401271() { + runNegativeTest( + new String[] { + "a/b/c/a.java", + "package a.b.c;\n" + + "public class a {}\n", + "a/b/c/C.java", + "package a.b.c;\n" + + "public class C {\n" + + " public static final int a = 3;\n" + + "}\n", + "x/y/R.java", + "package x.y;\n" + + "import static a.b.c.C.a;\n" + + "//import a.b.c.a;\n" + + "\n" + + "public class R { \n" + + " a b; \n" + + " char h = a; \n" + + "}" + }, + "----------\n" + + "1. ERROR in x\\y\\R.java (at line 6)\n" + + " a b; \n" + + " ^\n" + + "a cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=426544 - [1.8][compiler] Compiler over-eagerly detects collision of single static imports + public void test426544() { + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static int f;\n" + + " public static class C {}\n" + + " public static class I {}\n" + + "}\n", + "q/X.java", + "package q;\n" + + "public class X {\n" + + " public static int f;\n" + + " public static class C {}\n" + + " public static class I {}\n" + + "}\n", + "X.java", + "import static p.X.f;\n" + + "import static q.X.f;\n" + + "import static p.X.C;\n" + + "import static p.X.I;\n" + + "import static q.X.C;\n" + + "import static q.X.I;\n" + + "public class X { \n" + + " { f = 0; }\n" + + " { C c = null; }\n" + + " { I i = null; }\n" + + "}\n" + }, + this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " import static q.X.f;\n" + + " ^^^^^\n" + + "The import q.X.f collides with another import statement\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " import static q.X.C;\n" + + " ^^^^^\n" + + "The import q.X.C collides with another import statement\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " import static q.X.I;\n" + + " ^^^^^\n" + + "The import q.X.I collides with another import statement\n" + + "----------\n" : + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " { f = 0; }\n" + + " ^\n" + + "The field f is ambiguous\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " { C c = null; }\n" + + " ^\n" + + "The type C is ambiguous\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " { I i = null; }\n" + + " ^\n" + + "The type I is ambiguous\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=479287 + // erroneous compile error using static imports and generics + public void testBug479287() { + this.runConformTest( + new String[] { + "joetest/GenericsIssue.java", + "package joetest;\n" + + "import static joetest.GenericsIssueCollaborator.takesAnything;\n" + + "import java.util.Collection;\n" + + "import java.util.Collections;\n" + + "public class GenericsIssue {\n" + + " private void oddCompileError() {\n" + + " takesAnything(returnThings(\"works without wildcard in return value\"));\n" + + " GenericsIssueCollaborator.takesAnything(returnThingsWildcard(\"works without static import\"));\n" + + " takesAnything(returnThingsWildcard(\"doesn\'t work with static import\"));\n" + + " }\n" + + " private Collection returnThings(T thing) {\n" + + " return Collections.singleton(thing);\n" + + " }\n" + + " \n" + + " private Collection returnThingsWildcard(T toReturn) {\n" + + " return Collections.singleton(toReturn);\n" + + " }\n" + + "}", + "joetest/GenericsIssueCollaborator.java", + "package joetest;\n" + + "public class GenericsIssueCollaborator {\n" + + " public static void takesAnything(T thing) {\n" + + " System.out.println(\"TOOK IT: \" + thing);\n" + + " }\n" + + "}" + }); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=442580 + // Explicit static import after two wildcard imports is ambiguous (works in javac) + public void testBug442580() { + this.runConformTest(new String [] { + "a/A.java", + "package a;\n" + + "\n" + + "public class A {\n" + + " public static void foo() {\n" + + " System.out.println(\"A.foo\");\n" + + " }\n" + + "}", + "b/B.java", + "package b;\n" + + "\n" + + "public class B {\n" + + " public static void foo() {\n" + + " System.out.println(\"B.foo\");\n" + + " }\n" + + "}", + "Test.java", + "import static a.A.*;\n" + + "import static b.B.*;\n" + + "import static b.B.foo;\n" + + "\n" + + "public class Test {\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " }\n" + + "}" + }); + } + public void testBug520874a() { + if (this.complianceLevel <= ClassFileConstants.JDK1_8) { + return; + } + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.A1.Outer.*;\n" + + "import static p.A1.AnotherOuter.Inner;\n" + + "public class X {}\n" + + "class A1 {\n" + + " static class Outer {\n" + + " private static interface Inner {}\n" + + " }\n" + + " static class AnotherOuter {\n" + + " private static class Inner {}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 3)\n" + + " import static p.A1.AnotherOuter.Inner;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type p.A1.AnotherOuter.Inner is not visible\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 6)\n" + + " static class Outer {\n" + + " ^^^^^\n" + + "The type Inner is not visible\n" + + "----------\n"); + } + public void testBug520874b() { + if (this.complianceLevel <= ClassFileConstants.JDK1_8) { + return; + } + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import p.A1.Outer.*;\n" + + "public class X {}\n" + + "class A1 {\n" + + " static class Outer {\n" + + " private static interface Inner {}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " static class Outer {\n" + + " ^^^^^\n" + + "The type Inner is not visible\n" + + "----------\n"); + } + public void testBug520874c() { + if (this.complianceLevel <= ClassFileConstants.JDK1_8) { + return; + } + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.A1.Outer.Inner;\n" + + "import static p.A1.AnotherOuter.Inner;\n" + + "public class X {}\n" + + "class A1 {\n" + + " static class Outer {\n" + + " private static interface Inner {}\n" + + " }\n" + + " static class AnotherOuter {\n" + + " private static class Inner {}\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 2)\n" + + " import static p.A1.Outer.Inner;\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The type p.A1.Outer.Inner is not visible\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 3)\n" + + " import static p.A1.AnotherOuter.Inner;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The type p.A1.AnotherOuter.Inner is not visible\n" + + "----------\n" + + "3. ERROR in p\\X.java (at line 6)\n" + + " static class Outer {\n" + + " ^^^^^\n" + + "Inner cannot be resolved to a type\n" + + "----------\n" + + "4. ERROR in p\\X.java (at line 9)\n" + + " static class AnotherOuter {\n" + + " ^^^^^\n" + + "Inner cannot be resolved to a type\n" + + "----------\n"); + } + public void testBug520874d() { + if (this.complianceLevel <= ClassFileConstants.JDK1_8) { + return; + } + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.A.B.Inner;\n" + + "import p.Bar.Inner;\n" + + "public class X {}\n" + + "class A {\n" + + " static class B extends Bar {}\n" + + "}\n", + "p/Bar.java", + "package p;\n" + + "public class Bar {;\n" + + " public static class Inner {}\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 2)\n" + + " import static p.A.B.Inner;\n" + + " ^^^^^^^^^^^\n" + + "The import p.A.B.Inner is never used\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 3)\n" + + " import p.Bar.Inner;\n" + + " ^^^^^^^^^^^\n" + + "The import p.Bar.Inner is never used\n" + + "----------\n"); + } + public void testBug520874e() { + if (this.complianceLevel <= ClassFileConstants.JDK1_8) { + return; + } + runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "import static p.A.B.Inner;\n" + + "import p.Bar.*;\n" + + "public class X {}\n" + + "class A {\n" + + " static class B extends Bar {}\n" + + "}\n", + "p/Bar.java", + "package p;\n" + + "public class Bar {;\n" + + " public static class Inner {}\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 2)\n" + + " import static p.A.B.Inner;\n" + + " ^^^^^^^^^^^\n" + + "The import p.A.B.Inner is never used\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 3)\n" + + " import p.Bar.*;\n" + + " ^^^^^\n" + + "The import p.Bar is never used\n" + + "----------\n"); + } +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuperTypeTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuperTypeTest.java new file mode 100644 index 0000000000..3aa4f96a13 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuperTypeTest.java @@ -0,0 +1,650 @@ +/******************************************************************************* + * Copyright (c) 2006, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import java.util.Map; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class SuperTypeTest extends AbstractRegressionTest { + + public SuperTypeTest(String name) { + super(name); + } + // 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[] { "test000" }; +// TESTS_NUMBERS = new int[] { 42, 43, 44 }; +// TESTS_RANGE = new int[] { 11, -1 }; + } + + public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); + } + + public static Class testClass() { + return SuperTypeTest.class; + } + + /** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=136106 + */ + public void test001() { + this.runConformTest( + new String[] { + /* org.eclipse.curiosity.A */ + "org/eclipse/curiosity/A.java", + "package org.eclipse.curiosity;\n" + + "public abstract class A implements InterfaceA {\n" + + " private void e() {\n" + + " }\n" + + " public void f() {\n" + + " this.e();\n" + + " }\n" + + "}", + /* org.eclipse.curiosity.InterfaceA */ + "org/eclipse/curiosity/InterfaceA.java", + "package org.eclipse.curiosity;\n" + + "public interface InterfaceA extends InterfaceBase {}\n", + "org/eclipse/curiosity/InterfaceBase.java", + /* org.eclipse.curiosity.InterfaceBase */ + "package org.eclipse.curiosity;\n" + + "public interface InterfaceBase {\n" + + " public void a();\n" + + " public void b();\n" + + " public void c();\n" + + " public void d();\n" + + "}" + } + ); + } +// was Compliance_1_x#test001 +public void test002() { + String[] sources = new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " class M { \n"+ + " } \n"+ + " void foo(){ \n"+ + " class Y extends Secondary { \n"+ + " M m; \n"+ + " }; \n"+ + " System.out.println(\"SUCCESS\"); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " class M {} \n" + + "} \n" + }; + if (this.complianceLevel == ClassFileConstants.JDK1_3) { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in p1\\Test.java (at line 10)\n" + + " M m; \n" + + " ^\n" + + "The type M is defined in an inherited type and an enclosing scope\n" + + "----------\n"); + } else { + runConformTest( + sources, + "SUCCESS"); + } +} + +// was Compliance_1_x#test002 +public void test003() { + String[] sources = new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar() { \n"+ + " return \"FAILED\"; \n" + + " } \n"+ + " void foo(){ \n"+ + " class Y extends Secondary { \n"+ + " String z = bar(); \n" + + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " String bar(){ return \"SUCCESS\"; } \n" + + "} \n" + }; + if (this.complianceLevel == ClassFileConstants.JDK1_3) { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in p1\\Test.java (at line 11)\n" + + " String z = bar(); \n" + + " ^^^\n" + + "The method bar is defined in an inherited type and an enclosing scope\n" + + "----------\n"); + } else { + runConformTest( + sources, + "SUCCESS"); + } +} + +// was Compliance_1_x#test003 +public void test004() { + String[] sources = new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar = \"FAILED\";"+ + " void foo(){ \n"+ + " class Y extends Secondary { \n"+ + " String z = bar; \n"+ + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " String bar = \"SUCCESS\"; \n" + + "} \n" + }; + if (this.complianceLevel == ClassFileConstants.JDK1_3) { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in p1\\Test.java (at line 8)\n" + + " String z = bar; \n" + + " ^^^\n" + + "The field bar is defined in an inherited type and an enclosing scope \n" + + "----------\n"); + } else { + runConformTest( + sources, + "SUCCESS"); + } +} + +// was Compliance_1_x#test004 +public void test005() { + this.runConformTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar() { \n"+ + " return \"SUCCESS\"; \n" + + " } \n"+ + " void foo(){ \n"+ + " class Y extends Secondary { \n"+ + " String z = bar(); \n" + + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " private String bar(){ return \"FAILED\"; } \n" + + "} \n" + }, + "SUCCESS"); +} + +// was Compliance_1_x#test005 +public void test006() { + this.runConformTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar = \"SUCCESS\";"+ + " void foo(){ \n"+ + " class Y extends Secondary { \n"+ + " String z = bar; \n"+ + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " private String bar = \"FAILED\"; \n" + + "} \n" + }, + "SUCCESS"); +} + +// was Compliance_1_x#test006 +public void test007() { + this.runNegativeTest( + new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " new Test().foo(); \n"+ + " } \n"+ + " String bar() { \n"+ + " return \"FAILED\"; \n" + + " } \n"+ + " void foo(){ \n"+ + " class Y extends Secondary { \n"+ + " String z = bar(); \n" + + " }; \n"+ + " System.out.println(new Y().z); \n" + + " } \n"+ + "} \n" + + "class Secondary { \n" + + " String bar(int i){ return \"SUCCESS\"; } \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p1\\Test.java (at line 11)\n" + + " String z = bar(); \n" + + " ^^^\n" + + "The method bar(int) in the type Secondary is not applicable for the arguments ()\n" + + "----------\n" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 +// default is silent +public void test008() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {}\n" + + "class Y extends X implements I, J {}" + + "interface I {}\n" + + "interface J {}\n" + }, + "" + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 +// raising an error +public void test009() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X implements I {}\n" + + "class Y extends X implements I, J {}\n" + + "interface I {}\n" + + "interface J {}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X implements I, J {}\n" + + " ^\n" + + "Redundant superinterface I for the type Y, already defined by X\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 +// raising an error - deeper hierarchy +public void test010() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X implements I {}\n" + + "class Y extends X {}\n" + + "class Z extends Y implements J, I {}\n" + + "interface I {}\n" + + "interface J {}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 3)\n" + + " class Z extends Y implements J, I {}\n" + + " ^\n" + + "Redundant superinterface I for the type Z, already defined by X\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 +// no error - deeper hierarchy +public void test011() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + this.runConformTest( + new String[] { + "X.java", + "public class X implements I {}\n" + + "class Y extends X {}\n" + + "class Z extends Y implements J {}" + + "interface I {}\n" + + "interface J {}\n" + }, + "", + null /* no extra class libraries */, + true /* flush output directory */, + null /* no vm arguments */, + customOptions, + null /* no custom requestor*/); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=77918 +// error - extending interfaces +public void test012() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X implements J {}\n" + + "class Y extends X implements I {}\n" + + "interface I {}\n" + + "interface J extends I {}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 2)\n" + + " class Y extends X implements I {}\n" + + " ^\n" + + "Redundant superinterface I for the type Y, already defined by J\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=288749 +public void test013() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.util.*;\n" + + "interface X extends List, Collection, Iterable {}\n" + + "interface Y extends Collection, List {}\n" + + "interface XXX extends Iterable, List, Collection {}\n" + + "abstract class Z implements List, Collection {}\n" + + "abstract class ZZ implements Collection, List {}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " interface X extends List, Collection, Iterable {}\n" + + " ^^^^^^^^^^\n" + + "Redundant superinterface Collection for the type X, already defined by List\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " interface X extends List, Collection, Iterable {}\n" + + " ^^^^^^^^\n" + + "Redundant superinterface Iterable for the type X, already defined by List\n" + + "----------\n" + + "3. ERROR in X.java (at line 3)\n" + + " interface Y extends Collection, List {}\n" + + " ^^^^^^^^^^\n" + + "Redundant superinterface Collection for the type Y, already defined by List\n" + + "----------\n" + + "4. ERROR in X.java (at line 4)\n" + + " interface XXX extends Iterable, List, Collection {}\n" + + " ^^^^^^^^\n" + + "Redundant superinterface Iterable for the type XXX, already defined by List\n" + + "----------\n" + + "5. ERROR in X.java (at line 4)\n" + + " interface XXX extends Iterable, List, Collection {}\n" + + " ^^^^^^^^^^\n" + + "Redundant superinterface Collection for the type XXX, already defined by List\n" + + "----------\n" + + "6. ERROR in X.java (at line 5)\n" + + " abstract class Z implements List, Collection {}\n" + + " ^^^^^^^^^^\n" + + "Redundant superinterface Collection for the type Z, already defined by List\n" + + "----------\n" + + "7. ERROR in X.java (at line 6)\n" + + " abstract class ZZ implements Collection, List {}\n" + + " ^^^^^^^^^^\n" + + "Redundant superinterface Collection for the type ZZ, already defined by List\n" + + "----------\n", + JavacTestOptions.SKIP); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=288749 +public void test014() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X implements I, J {}", + "I.java", + "public interface I {}", + "J.java", + "public interface J extends I {}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X implements I, J {}\n" + + " ^\n" + + "Redundant superinterface I for the type X, already defined by J\n" + + "----------\n", + JavacTestOptions.SKIP); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320911 (as is) +public void test015() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "interface IVerticalRulerColumn {}\n" + + "interface IVerticalRulerInfo {}\n" + + "interface IVerticalRulerInfoExtension {}\n" + + "interface IChangeRulerColumn extends IVerticalRulerColumn, IVerticalRulerInfoExtension {}\n" + + "interface IRevisionRulerColumn extends IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + "public final class X implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn, IRevisionRulerColumn {}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " public final class X implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn, IRevisionRulerColumn {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerColumn for the type X, already defined by IChangeRulerColumn\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " public final class X implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn, IRevisionRulerColumn {}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerInfo for the type X, already defined by IRevisionRulerColumn\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " public final class X implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn, IRevisionRulerColumn {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerInfoExtension for the type X, already defined by IChangeRulerColumn\n" + + "----------\n", + JavacTestOptions.SKIP); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320911 (variation) +public void test016() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "interface IVerticalRulerColumn {}\n" + + "interface IVerticalRulerInfo {}\n" + + "interface IVerticalRulerInfoExtension {}\n" + + "interface IChangeRulerColumn extends IVerticalRulerColumn, IVerticalRulerInfoExtension {}\n" + + "interface IRevisionRulerColumn extends IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + "class Z implements IChangeRulerColumn {}\n" + + "class Y extends Z implements IRevisionRulerColumn {}\n" + + "public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerColumn for the type X, already defined by IRevisionRulerColumn\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerInfo for the type X, already defined by IRevisionRulerColumn\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerInfoExtension for the type X, already defined by IRevisionRulerColumn\n" + + "----------\n", + JavacTestOptions.SKIP); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320911 (variation) +public void test017() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "interface IVerticalRulerColumn {}\n" + + "interface IVerticalRulerInfo {}\n" + + "interface IVerticalRulerInfoExtension {}\n" + + "interface IChangeRulerColumn extends IVerticalRulerColumn, IVerticalRulerInfoExtension {}\n" + + "interface IRevisionRulerColumn extends IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + "class Z implements IRevisionRulerColumn{}\n" + + "class C extends Z {}\n" + + "class B extends C implements IChangeRulerColumn {}\n" + + "class H extends B {}\n" + + "class Y extends H {}\n" + + "public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerColumn for the type X, already defined by IRevisionRulerColumn\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerInfo for the type X, already defined by IRevisionRulerColumn\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerInfoExtension for the type X, already defined by IRevisionRulerColumn\n" + + "----------\n", + JavacTestOptions.SKIP); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=320911 (variation) +public void test018() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportRedundantSuperinterface, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "interface IVerticalRulerColumn {}\n" + + "interface IVerticalRulerInfo {}\n" + + "interface IVerticalRulerInfoExtension {}\n" + + "interface IChangeRulerColumn extends IVerticalRulerColumn, IVerticalRulerInfoExtension {}\n" + + "interface IRevisionRulerColumn extends IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + "class Z implements IVerticalRulerInfoExtension {}\n" + + "class C extends Z {}\n" + + "class B extends C implements IChangeRulerColumn {}\n" + + "class H extends B implements IVerticalRulerInfo {}\n" + + "class Y extends H implements IVerticalRulerColumn {}\n" + + "public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " class Y extends H implements IVerticalRulerColumn {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerColumn for the type Y, already defined by IChangeRulerColumn\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerColumn for the type X, already defined by Y\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerInfo for the type X, already defined by H\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\n" + + " public final class X extends Y implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {}\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Redundant superinterface IVerticalRulerInfoExtension for the type X, already defined by Z\n" + + "----------\n", + JavacTestOptions.SKIP); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuppressWarningsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuppressWarningsTest.java new file mode 100644 index 0000000000..95d6ff97a2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SuppressWarningsTest.java @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2020 Thomas Wolf and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class SuppressWarningsTest extends AbstractBatchCompilerTest { + + public SuppressWarningsTest(String name) { + super(name); + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); + } + + public static Class testClass() { + return SuppressWarningsTest.class; + } + + @SuppressWarnings("unchecked") + @Override + protected Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_ReportAutoboxing, CompilerOptions.WARNING); + return options; + } + + public void testSimpleSuppressWarnings() { + this.runTest(true, + new String[] { + "p/SuppressTest.java", + "package p;\n" + + "public class SuppressTest {\n" + + "@SuppressWarnings(\"boxing\")\n" + + "public Long get(long l) {\n" + + " Long result = l * 2;\n" + + " return result;\n" + + "}\n}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "p/SuppressTest.java\"" + + " -warn:+unused -warn:+boxing " + + " -1.5 -g -preserveAllLocals" + + " -d \"" + OUTPUT_DIR + "\" ", + "", "", true, null); + } + + public void testNestedSuppressWarnings() { + this.runTest(true, + new String[] { + "p/SuppressTest.java", + "package p;\n" + + "@SuppressWarnings(\"unused\")\n" + + "public class SuppressTest {\n" + + "private String unused=\"testUnused\";\n" + + "@SuppressWarnings(\"boxing\")\n" + + "public Long get(long l) {\n" + + " Long result = l * 2;\n" + + " return result;\n" + + "}\n}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "p/SuppressTest.java\"" + + " -warn:+unused -warn:+boxing " + + " -1.5 -g -preserveAllLocals" + + " -d \"" + OUTPUT_DIR + "\" ", + "", "", true, null); + } + + public void testUnrelatedSuppressWarnings() { + this.runTest(true, + new String[] { + "p/SuppressTest.java", + "package p;\n" + + "@SuppressWarnings(\"unused\")\n" + + "public class SuppressTest {\n" + + "private String unused=\"testUnused\";\n" + + "public Long get(long l) {\n" + + " Long result = l * 2;\n" + + " return result;\n" + + "}\n}\n" + }, + "\"" + OUTPUT_DIR + File.separator + "p/SuppressTest.java\"" + + " -warn:+unused -warn:+boxing " + + " -1.5 -g -preserveAllLocals" + + " -d \"" + OUTPUT_DIR + "\" ", + "", + "----------\n" + + "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/p/SuppressTest.java (at line 6)\n" + + " Long result = l * 2;\n" + + " ^^^^^\n" + + "The expression of type long is boxed into Long\n" + + "----------\n" + + "1 problem (1 warning)\n", + true, null); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java new file mode 100644 index 0000000000..9bfd9e196b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchExpressionsYieldTest.java @@ -0,0 +1,6118 @@ +/******************************************************************************* + * Copyright (c) 2019, 2021 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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 org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.JavacHasABug; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + + +public class SwitchExpressionsYieldTest extends AbstractRegressionTest { + static { +// TESTS_NUMBERS = new int [] { 40 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] { "571833" }; + } + + public static Class testClass() { + return SwitchExpressionsYieldTest.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_14); + } + public SwitchExpressionsYieldTest(String testName){ + super(testName); + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput) { + runConformTest(testFiles, expectedOutput, getCompilerOptions()); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedOutputString = expectedOutput; + runner.customOptions = customOptions; + runner.javacTestOptions = JavacTestOptions.forRelease(JavaCore.VERSION_14); + runner.runConformTest(); + } + @Override + protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) { + runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forRelease(JavaCore.VERSION_14)); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog) { + runWarningTest(testFiles, expectedCompilerLog, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, Map customOptions) { + runWarningTest(testFiles, expectedCompilerLog, customOptions, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, + Map customOptions, String javacAdditionalTestOptions) { + + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedCompilerLog; + runner.customOptions = customOptions; + runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forRelease(JavaCore.VERSION_14) : + JavacTestOptions.forRelease(JavaCore.VERSION_14, javacAdditionalTestOptions); + runner.runWarningTest(); + } + public void testBug544073_000() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " public static int yield() {\n"+ + " return 1;\n"+ + " }\n"+ + " public static int foo(int val) {\n"+ + " int k = switch (val) {\n"+ + " case 1 -> { yield 1; }\n"+ + " default -> { yield 2; }\n"+ + " };\n"+ + " return k;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(1));\n"+ + " }\n"+ + "}\n" + }, + "1"); + } + public void testBug544073_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int twice(int i) {\n" + + " int tw = switch (i) {\n" + + " case 0 -> i * 0;\n" + + " case 1 -> 2;\n" + + " default -> 3;\n" + + " };\n" + + " return tw;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(twice(3));\n" + + " }\n" + + "}\n" + }, + "3"); + } + public void testBug544073_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int twice(int i) throws Exception {\n"+ + " int tw = switch (i) {\n"+ + " case 0 -> 0;\n"+ + " case 1 -> { \n"+ + " System.out.println(\"do_not_print\");\n"+ + " yield 1;\n"+ + " } \n"+ + " case 3 -> throw new Exception();\n"+ + " default -> throw new Exception();\n"+ + " };\n"+ + " return tw;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " try {\n"+ + " try {\n"+ + " System.out.print(twice(3));\n"+ + " } catch (Exception e) {\n"+ + " System.out.print(\"Got Exception - expected\");\n"+ + " }\n"+ + " } catch (Exception e) {\n"+ + " System.out.print(\"Got Exception\");\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "Got Exception - expected"); + } + public void testBug544073_003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " twice(1);\n" + + " }\n" + + " public static int twice(int i) {\n" + + " int tw = switch (i) {\n" + + " };\n" + + " return tw;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int tw = switch (i) {\n" + + " };\n" + + " ^^^^^^^^^^^^^^^^\n" + + "A switch expression should have a non-empty switch block\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " int tw = switch (i) {\n" + + " ^\n" + + "A switch expression should have a default case\n" + + "----------\n"); + } + public void testBug544073_004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " twice(1);\n" + + " }\n" + + " public static int twice(int i) {\n" + + " int tw = switch (i) {\n" + + " case 0 -> 0;\n" + + " case 1 -> { \n" + + " System.out.println(\"heel\");\n" + + " yield 1;\n" + + " } \n" + + " case \"hello\" -> throw new java.io.IOException(\"hello\");\n" + + " default -> throw new java.io.IOException(\"world\");\n" + + " };\n" + + " return tw;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 12)\n" + + " case \"hello\" -> throw new java.io.IOException(\"hello\");\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n"); + } + public void testBug544073_005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " twice(1);\n" + + " }\n" + + " public static int twice(int i) {\n" + + " int tw = switch (i) {\n" + + " case 0 -> 0;\n" + + " case 1 -> { \n" + + " System.out.println(\"heel\");\n" + + " yield 1;\n" + + " } \n" + + " case 2 -> 2;\n" + + " };\n" + + " return tw;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int tw = switch (i) {\n" + + " ^\n" + + "A switch expression should have a default case\n" + + "----------\n"); + } + /** + * Add a test case for enum + * If the type of the selector expression is an enum type, + * then the set of all the case constants associated with the switch block + * must contain all the enum constants of that enum type + * Add a missing enum test case + */ + public void testBug544073_006() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public static int twice(int i) {\n" + + " int tw = switch (i) {\n" + + " case 0 -> 0;\n" + + " case 1 -> { \n" + + " System.out.println(\"heel\");\n" + + " yield 1;\n" + + " } \n" + + " // case 2 -> 2;\n" + + " case \"hello\" -> throw new IOException(\"hello\");\n" + + " };\n" + + " return tw;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " int tw = switch (i) {\n" + + " ^\n" + + "A switch expression should have a default case\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " case \"hello\" -> throw new IOException(\"hello\");\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n"); + } + /* + * should compile - test for adding additional nesting in variables + * dev note: ref consumeToken().case Switch + */ + public void testBug544073_007() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(int i) {\n"+ + " int tw = \n"+ + " switch (i) {\n"+ + " case 1 -> \n"+ + " {\n"+ + " int z = 100;\n"+ + " yield z;\n"+ + " }\n"+ + " default -> {\n"+ + " yield 12;\n"+ + " }\n"+ + " };\n"+ + " return tw;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.print(foo(1));\n"+ + " }\n"+ + "}\n" + }, + "100"); + } + public void testBug544073_009() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void bar(int i) {\n" + + " switch (i) {\n" + + " case 1 -> System.out.println(\"hello\");\n" + + " default -> System.out.println(\"DEFAULT\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " bar(1);\n" + + " }\n" + + "}\n" + }, + "hello"); + } + public void testBug544073_010() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " static int twice(int i) {\n" + + " switch (i) {\n" + + " case 0 -> i * 0;\n" + + " case 1 -> 2;\n" + + " default -> 3;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(twice(3));\n" + + " }\n" + + "}\n", + }; + + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case 0 -> i * 0;\n" + + " ^^^^^\n" + + "Invalid expression as statement\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " case 1 -> 2;\n" + + " ^\n" + + "Invalid expression as statement\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " default -> 3;\n" + + " ^\n" + + "Invalid expression as statement\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_011() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " static int twice(int i) {\n" + + " switch (i) {\n" + + " default -> 3;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(twice(3));\n" + + " }\n" + + "}\n", + }; + + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " default -> 3;\n" + + " ^\n" + + "Invalid expression as statement\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_012() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + "\n" + + " static int twice(int i) {\n" + + " switch (i) {\n" + + " default -> 3;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(twice(3));\n" + + " }\n" + + "}\n", + }; + + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " default -> 3;\n" + + " ^\n" + + "Invalid expression as statement\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_013() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING); + String release = options.get(CompilerOptions.OPTION_Release); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_11); + try { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " static int twice(int i) {\n" + + " switch (i) {\n" + + " default -> 3;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(twice(3));\n" + + " }\n" + + "}\n", + }; + + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 0)\n" + + " public class X {\n" + + " ^\n" + + "Preview features enabled at an invalid source release level "+CompilerOptions.VERSION_11+", preview can be enabled only at source level "+AbstractRegressionTest.PREVIEW_ALLOWED_LEVEL+"\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true, + options); + } finally { + options.put(CompilerOptions.OPTION_Source, release); + } + } + public void testBug544073_014() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " int v;\n" + + " int t = switch (i) {\n" + + " case 0 : {\n" + + " yield 0;\n" + + " }\n" + + " default :v = 2;\n" + + " };\n" + + " return t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(3));\n" + + " }\n" + + "}\n", + }; + + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " default :v = 2;\n" + + " ^^\n" + + "A switch labeled block in a switch expression should not complete normally\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_015() { + // switch expression is not a Primary + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.testFiles = new String[] { + "X.java", + "public class X {\n" + + " void test(int i) {\n" + + " System.out.println(switch (i) {\n" + + " case 1 -> \"one\";\n" + + " default -> null;\n" + + " }.toLowerCase());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().test(1);\n" + + " }\n" + + "}\n" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " }.toLowerCase());\n" + + " ^\n" + + "Syntax error on token \".\", , expected\n" + + "----------\n"; + runner.runNegativeTest(); + } + public void testBug544073_016() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(Day day) {\n" + + "\n" + + " var len= switch (day) {\n" + + " case SUNDAY-> 6;\n" + + " default -> 10;\n" + + " };\n" + + "\n" + + " return len;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(Day.SUNDAY));\n" + + " }\n" + + "}\n" + + "enum Day {\n" + + " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" + + "}\n" + }, + "6"); + } + /* + * A simple multi constant case statement, compiled and run as expected + */ + public void testBug544073_017() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + "public static void bar(Day day) {\n" + + " switch (day) {\n" + + " case SATURDAY, SUNDAY: \n" + + " System.out.println(Day.SUNDAY);\n" + + " break;\n" + + " case MONDAY : System.out.println(Day.MONDAY);\n" + + " break;\n" + + " }\n" + + " }" + + " public static void main(String[] args) {\n" + + " bar(Day.SATURDAY);\n" + + " }\n" + + "}\n" + + "enum Day { SATURDAY, SUNDAY, MONDAY;}", + }; + + String expectedProblemLog = + "SUNDAY"; + this.runConformTest( + testFiles, + expectedProblemLog); + } + /* + * A simple multi constant case statement, compiler reports missing enum constants + */ + public void testBug544073_018() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + "public static void bar(Day day) {\n" + + " switch (day) {\n" + + " case SATURDAY, SUNDAY: \n" + + " System.out.println(Day.SUNDAY);\n" + + " break;\n" + + " case MONDAY : System.out.println(Day.MONDAY);\n" + + " break;\n" + + " }\n" + + " }" + + "}\n" + + "enum Day { SATURDAY, SUNDAY, MONDAY, TUESDAY;}", + }; + + String expectedProblemLog = + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " switch (day) {\n" + + " ^^^\n" + + "The enum constant TUESDAY needs a corresponding case label in this enum switch on Day\n" + + "----------\n"; + this.runWarningTest( + testFiles, + expectedProblemLog); + } + /* + * A simple multi constant case statement with duplicate enums + */ + public void testBug544073_019() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + "public static void bar(Day day) {\n" + + " switch (day) {\n" + + " case SATURDAY, SUNDAY: \n" + + " System.out.println(Day.SUNDAY);\n" + + " break;\n" + + " case SUNDAY : System.out.println(Day.SUNDAY);\n" + + " break;\n" + + " }\n" + + " }" + + " public static void main(String[] args) {\n" + + " bar(Day.SATURDAY);\n" + + " }\n" + + "}\n" + + "enum Day { SATURDAY, SUNDAY, MONDAY;}", + }; + + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case SATURDAY, SUNDAY: \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " case SUNDAY : System.out.println(Day.SUNDAY);\n" + + " ^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + /* + * A simple multi constant case statement with duplicate enums + */ + public void testBug544073_020() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + "public static void bar(Day day) {\n" + + " switch (day) {\n" + + " case SATURDAY, SUNDAY: \n" + + " System.out.println(Day.SUNDAY);\n" + + " break;\n" + + " case SUNDAY, SATURDAY : \n" + + " System.out.println(Day.SUNDAY);\n" + + " break;\n" + + " }\n" + + " }" + + "}\n" + + "enum Day { SATURDAY, SUNDAY, MONDAY;}", + }; + + String expectedProblemLog = + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " switch (day) {\n" + + " ^^^\n" + + "The enum constant MONDAY needs a corresponding case label in this enum switch on Day\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " case SATURDAY, SUNDAY: \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " case SUNDAY, SATURDAY : \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " case SUNDAY, SATURDAY : \n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + /* + * + */ + public void testBug544073_021() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + "public static void bar(Day day) {\n" + + " switch (day) {\n" + + " case SATURDAY, SUNDAY: \n" + + " System.out.println(Day.SUNDAY);\n" + + " break;\n" + + " case TUESDAY : System.out.println(Day.SUNDAY);\n" + + " break;\n" + + " }\n" + + " }" + + " public static void main(String[] args) {\n" + + " bar(Day.SATURDAY);\n" + + " }\n" + + "}\n" + + "enum Day { SATURDAY, SUNDAY, MONDAY, TUESDAY;}", + }; + + String expectedProblemLog = + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " switch (day) {\n" + + " ^^^\n" + + "The enum constant MONDAY needs a corresponding case label in this enum switch on Day\n" + + "----------\n"; + this.runWarningTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_022() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + "public static void bar(Day day) {\n" + + " switch (day) {\n" + + " case SATURDAY, SUNDAY: \n" + + " System.out.println(day);\n" + + " break;\n" + + " case MONDAY : System.out.println(0);\n" + + " break;\n" + + " }\n" + + " }" + + " public static void main(String[] args) {\n" + + " bar(Day.SATURDAY);\n" + + " bar(Day.MONDAY);\n" + + " bar(Day.SUNDAY);\n" + + " }\n" + + "}\n" + + "enum Day { SATURDAY, SUNDAY, MONDAY;}", + }; + + String expectedProblemLog = + "SATURDAY\n" + + "0\n" + + "SUNDAY"; + this.runConformTest( + testFiles, + expectedProblemLog); + } + /* + * Simple switch case with string literals + */ + public void testBug544073_023() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " bar(\"a\");\n" + + " bar(\"b\");\n" + + " bar(\"c\");\n" + + " bar(\"d\");\n" + + " }\n" + + " public static void bar(String s) {\n" + + " switch(s) {\n" + + " case \"a\":\n" + + " case \"b\":\n" + + " System.out.println(\"A/B\");\n" + + " break;\n" + + " case \"c\":\n" + + " System.out.println(\"C\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"NA\");\n" + + " }\n" + + " }\n" + + "}", + }; + String expectedProblemLog = + "A/B\n" + + "A/B\n" + + "C\n" + + "NA"; + this.runConformTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_024() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " bar(\"a\");\n" + + " bar(\"b\");\n" + + " bar(\"c\");\n" + + " bar(\"d\");\n" + + " }\n" + + " public static void bar(String s) {\n" + + " switch(s) {\n" + + " case \"a\", \"b\":\n" + + " System.out.println(\"A/B\");\n" + + " break;\n" + + " case \"c\":\n" + + " System.out.println(\"C\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"NA\");\n" + + " }\n" + + " }\n" + + "}", + }; + String expectedProblemLog = + "A/B\n" + + "A/B\n" + + "C\n" + + "NA"; + this.runConformTest( + testFiles, + expectedProblemLog); + } + /* + * Switch with multi constant case statements with string literals + * two string literals with same hashcode + */ + public void testBug544073_025() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " bar(\"FB\");\n" + + " bar(\"Ea\");\n" + + " bar(\"c\");\n" + + " bar(\"D\");\n" + + " }\n" + + " public static void bar(String s) {\n" + + " switch(s) {\n" + + " case \"FB\", \"c\":\n" + + " System.out.println(\"A\");\n" + + " break;\n" + + " case \"Ea\":\n" + + " System.out.println(\"B\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"NA\");\n" + + " }\n" + + " }\n" + + "}", + }; + String expectedProblemLog = + "A\n" + + "B\n" + + "A\n" + + "NA"; + this.runConformTest( + testFiles, + expectedProblemLog); + } + /* + * Switch with multi constant case statements with integer constants + */ + public void testBug544073_026() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " bar(1);\n" + + " bar(2);\n" + + " bar(3);\n" + + " bar(4);\n" + + " bar(5);\n" + + " }\n" + + " public static void bar(int i) {\n" + + " switch (i) {\n" + + " case 1, 3: \n" + + " System.out.println(\"Odd\");\n" + + " break;\n" + + " case 2, 4: \n" + + " System.out.println(\"Even\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"Out of range\");\n" + + " }\n" + + " }\n" + + "}", + }; + String expectedProblemLog = + "Odd\n" + + "Even\n" + + "Odd\n" + + "Even\n" + + "Out of range"; + this.runConformTest( + testFiles, + expectedProblemLog); + } + /* + * Switch multi-constant with mixed constant types, reported + */ + public void testBug544073_027() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public static void bar(int i) {\n" + + " switch (i) {\n" + + " case 1, 3: \n" + + " System.out.println(\"Odd\");\n" + + " break;\n" + + " case \"2\": \n" + + " System.out.println(\"Even\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"Out of range\");\n" + + " }\n" + + " }\n" + + "}", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " case \"2\": \n" + + " ^^^\n" + + "Type mismatch: cannot convert from String to int\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + /* + * Switch multi-constant without break statement, reported + */ + public void testBug544073_028() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.WARNING); + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public static void bar(int i) {\n" + + " switch (i) {\n" + + " case 1, 3: \n" + + " System.out.println(\"Odd\");\n" + + " case 2, 4: \n" + + " System.out.println(\"Even\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"Out of range\");\n" + + " }\n" + + " }\n" + + "}", + }; + String expectedProblemLog = + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " case 2, 4: \n" + + " ^^^^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n"; + this.runWarningTest( + testFiles, + expectedProblemLog, + options, + "-Xlint:fallthrough"); + } + /* + * Switch multi-constant without yield statement, reported + */ + public void testBug544073_029() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.WARNING); + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public static void bar(int i) {\n" + + " switch (i) {\n" + + " case 1, 3: \n" + + " System.out.println(\"Odd\");\n" + + " case 2, 4: \n" + + " System.out.println(\"Even\");\n" + + " }\n" + + " }\n" + + "}", + }; + String expectedProblemLog = + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " switch (i) {\n" + + " ^\n" + + "The switch statement should have a default case\n" + + "----------\n"; + this.runWarningTest( + testFiles, + expectedProblemLog, + options); + } + /* + * Switch multi-constant with duplicate int constants + */ + public void testBug544073_030() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public static void bar(int i) {\n" + + " switch (i) {\n" + + " case 1, 3: \n" + + " System.out.println(\"Odd\");\n" + + " case 3, 4: \n" + + " System.out.println(\"Odd\");\n" + + " }\n" + + " }\n" + + "}", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case 1, 3: \n" + + " ^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " case 3, 4: \n" + + " ^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + /* + * Switch multi-constant with duplicate String literals + */ + public void testBug544073_031() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public static void bar(String s) {\n" + + " switch (s) {\n" + + " case \"a\", \"b\": \n" + + " System.out.println(\"Odd\");\n" + + " case \"b\", \"c\": \n" + + " System.out.println(\"Odd\");\n" + + " }\n" + + " }\n" + + "}", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case \"a\", \"b\": \n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " case \"b\", \"c\": \n" + + " ^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + /* + * Switch multi-constant with illegal qualified enum constant + */ + public void testBug544073_032() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public static void bar(Num s) {\n" + + " switch (s) {\n" + + " case ONE, Num.TWO: \n" + + " System.out.println(\"Odd\");\n" + + " }\n" + + " }\n" + + "}\n" + + "enum Num { ONE, TWO}\n", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case ONE, Num.TWO: \n" + + " ^^^^^^^\n" + + "The qualified case label Num.TWO must be replaced with the unqualified enum constant TWO\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_033() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public void bar(int s) {\n" + + " int j = switch (s) {\n" + + " case 1, 2, 3 -> (s+1);\n" + + " default -> j;\n" + + " };\n" + + " }\n" + + "}\n", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " default -> j;\n" + + " ^\n" + + "The local variable j may not have been initialized\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_034() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " }\n" + + " public void bar(int s) {\n" + + " int j = 0;" + + " j = switch (s) {\n" + + " case 1, 2, 3 -> (s+1);\n" + + " default -> j;\n" + + " };\n" + + " }\n" + + "}\n", + }; + this.runConformTest( + testFiles, + ""); + } + public void testBug544073_035() { + // TODO: Fix me + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " public static int foo(int i) throws IOException {\n" + + " int t = switch (i) {\n" + + " case 0 : {\n" + + " yield 0;\n" + + " }\n" + + " case 2 : {\n" + + " break;\n" + + " }\n" + + " default : yield 10;\n" + + " };\n" + + " return t;\n" + + " }\n" + + " \n" + + " public boolean bar() {\n" + + " return true;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(foo(3));\n" + + " } catch (IOException e) {\n" + + " // TODO Auto-generated catch block\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " break;\n" + + " ^^^^^^\n" + + "break out of switch expression not allowed\n" + + "----------\n"); + } + public void testBug544073_036() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void bar(int i) {\n" + + " i = switch (i+0) {\n" + + " default: System.out.println(0);\n" + + " }; " + + " }\n" + + "}", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " i = switch (i+0) {\n" + + " default: System.out.println(0);\n" + + " }; }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "A switch expression should have at least one result expression\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_037() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " void test(int i) {\n" + + " need(switch (i) {\n" + + " case 1 -> \"\";\n" + + " default -> i == 3 ? null : \"\";\n" + + " }); \n" + + " }\n" + + " void need(String s) {\n" + + " System.out.println(s.toLowerCase());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().need(\"Hello World\");\n" + + " }\n" + + "}\n" + }; + String expectedOutput = "hello world"; + runConformTest(testFiles, expectedOutput); + } + public void testBug544073_038() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " void test(int i) {\n" + + " need(switch (i) {\n" + + " case 1: yield \"\";\n" + + " default: yield i == 3 ? null : \"\";\n" + + " }); \n" + + " }\n" + + " void need(String s) {\n" + + " System.out.println(s.toLowerCase());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().need(\"Hello World\");\n" + + " }\n" + + "}\n" + }; + String expectedOutput = "hello world"; + runConformTest(testFiles, expectedOutput); + } + public void testBug544073_039() { + String[] testFiles = new String[] { + "X.java", + "interface I0 { void i(); }\n" + + "interface I1 extends I0 {}\n" + + "interface I2 extends I0 {}\n" + + "public class X {\n" + + " I1 n1() { return null; }\n" + + " I n2() { return null; }\n" + + " M m(M m) { return m; }\n" + + " void test(int i, boolean b) {\n" + + " m(switch (i) {\n" + + " case 1 -> n1();\n" + + " default -> b ? n1() : n2();\n" + + " }).i(); \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().test(1, true);\n" + + " } catch (NullPointerException e) {\n" + + " System.out.println(\"NPE as expected\");\n" + + " }\n" + + " }\n" + + "}\n" + }; + String expectedOutput = "NPE as expected"; + runConformTest(testFiles, expectedOutput); + } + public void testBug544073_040() { + String[] testFiles = new String[] { + "X.java", + "import java.util.function.Supplier;\n" + + "interface I0 { void i(); }\n" + + "interface I1 extends I0 {}\n" + + "interface I2 extends I0 {}\n" + + "public class X {\n" + + " I1 n1() { return null; }\n" + + " I n2() { return null; }\n" + + " M m(Supplier m) { return m.get(); }\n" + + " void test(int i, boolean b) {\n" + + " m(switch (i) {\n" + + " case 1 -> this::n1;\n" + + " default -> this::n2;\n" + + " }).i(); \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().test(1, true);\n" + + " } catch (NullPointerException e) {\n" + + " System.out.println(\"NPE as expected\");\n" + + " }\n" + + " }\n" + + "}\n" + }; + String expectedOutput = "NPE as expected"; + runConformTest(testFiles, expectedOutput); + } + public void testBug544073_041() { + // require resolving/inferring of poly-switch-expression during ASTNode.resolvePolyExpressionArguments() + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " void test(int i) {\n" + + " need(switch (i) {\n" + + " case 1 -> 1.0f;\n" + + " default -> i == 3 ? 3 : 5.0d;\n" + + " }); \n" + + " }\n" + + " void need(N s) {\n" + + " System.out.println(s.toString());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().need(3);\n" + + " }\n" + + "}\n" + }; + String expectedOutput = "3"; + runConformTest(testFiles, expectedOutput); + } + public void testBug544073_042() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static int twice(int i) throws Exception {\n" + + " switch (i) {\n" + + " case 0 -> System.out.println(\"hellow\");\n" + + " case 1 -> foo();\n" + + " default -> throw new Exception();\n" + + " };\n" + + " return 0;\n" + + " }\n" + + "\n" + + " static int foo() {\n" + + " System.out.println(\"inside foo\");\n" + + " return 1;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.print(twice(1));\n" + + " } catch (Exception e) {\n" + + " System.out.print(\"Got Exception\");\n" + + " }\n" + + " }\n" + + "}" + }, + "inside foo\n" + + "0"); + } + public void testBug544073_043() { + runConformTest( + new String[] { + "X.java", + "enum SomeDays {\n" + + " Mon, Wed, Fri\n" + + "}\n" + + "\n" + + "public class X {\n" + + " int testEnum(boolean b) {\n" + + " SomeDays day = b ? SomeDays.Mon : null;\n" + + " return switch(day) {\n" + + " case Mon -> 1;\n" + + " case Wed -> 2;\n" + + " case Fri -> 3;\n" + + " };\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().testEnum(true));\n" + + " }\n" + + "}\n" + + "" + }, + "1"); + } + public void testBug544073_044() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " static int foo(int i) {\n" + + " switch (i) {\n" + + " default -> 3; // should flag an error\n" + + " \n" + + " };\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(1);\n" + + " }\n" + + "}\n", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " default -> 3; // should flag an error\n" + + " ^\n" + + "Invalid expression as statement\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_045() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(int i) {\n" + + " int j = switch (i) {\n" + + " case 1 -> i;\n" + + " default -> i;\n" + + " };\n" + + " System.out.println(j);\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().foo(1);\n" + + " }\n" + + "}" + }, + "1"); + } + public void testBug544073_046() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(int i) {\n" + + " long j = switch (i) {\n" + + " case 1 -> 10L;\n" + + " default -> 20L;\n" + + " };\n" + + " System.out.println(j);\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " new X().foo(1);\n" + + " }\n" + + "}" + }, + "10"); + } + public void testBug544073_047() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int foo(String s) throws Exception {\n" + + " int i = switch (s) {\n" + + " case \"hello\" -> 1;\n" + + " default -> throw new Exception();\n" + + " };\n" + + " return i;\n" + + " }\n" + + "\n" + + " public static void main(String[] argv) {\n" + + " try {\n" + + " System.out.print(new X().foo(\"hello\"));\n" + + " } catch (Exception e) {\n" + + " //\n" + + " }\n" + + " }\n" + + "}" + }, + "1"); + } + public void testBug544073_048() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Day day) {\n" + + " var today = 1;\n" + + " today = switch (day) {\n" + + " case SATURDAY,SUNDAY :\n" + + " today=1;\n" + + " yield today;\n" + + " case MONDAY,TUESDAY,WEDNESDAY,THURSDAY :\n" + + " today=2;\n" + + " yield today;\n" + + " };\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(Day.FRIDAY);\n" + + " }\n" + + "}\n" + + "\n" + + "enum Day {\n" + + " SUNDAY,\n" + + " MONDAY,\n" + + " TUESDAY,\n" + + " WEDNESDAY,\n" + + " THURSDAY,\n" + + " FRIDAY,\n" + + " SATURDAY\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " today = switch (day) {\n" + + " ^^^\n" + + "A Switch expression should cover all possible values\n" + + "----------\n"); + } + public void testBug544073_049() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(int i ) {\n" + + " boolean b = switch (i) {\n" + + " case 0 -> i == 1;\n" + + " default -> true;\n" + + " };\n" + + " System.out.println( b ? \" true\" : \"false\");\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " new X().foo(0);\n" + + " }\n" + + "}" + }, + "false"); + } + public void testBug544073_050() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) {\n" + + " try {\n" + + " int i = switch (s) {\n" + + " case \"hello\" -> 0;\n" + + " default -> 2;\n" + + " };\n" + + " } finally {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(\"hello\");\n" + + " }\n" + + "}" + }, + "hello"); + } + public void testBug544073_051() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) {\n" + + " try {\n" + + " int i = switch (s) {\n" + + " case \"hello\" -> 0;\n" + + " default -> 2;\n" + + " };\n" + + " } finally {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(\"hello\");\n" + + " }\n" + + "}" + }, + "hello"); + } + public void testBug544073_052() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String s) {\n" + + " try {\n" + + " long l = switch (s) {\n" + + " case \"hello\" -> 0;\n" + + " default -> 2;\n" + + " };\n" + + " } finally {\n" + + " System.out.println(s);\n" + + " }\n" + + " }\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(\"hello\");\n" + + " }\n" + + "}" + }, + "hello"); + } + public void testBug544073_053() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int foo(int i) {\n" + + " int j = (switch (i) {\n" + + " case 1 -> 1;\n" + + " default -> 2;\n" + + " });\n" + + " return j;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " new X().foo(1);\n" + + " }\n" + + "}\n" + }, + "", + customOptions); + } + public void testBug544073_054() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum MyEnum {\n" + + " FIRST;\n" + + " }\n" + + "\n" + + " public void foo(MyEnum myEnum) {\n" + + " int i = switch (myEnum) {\n" + + " case FIRST -> 1;\n" + + " };\n" + + " System.out.println( \"i:\" + i);\n" + + " }\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(MyEnum.FIRST);\n" + + " }\n" + + "}" + }, + "i:1"); + } + public void testBug544073_055() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum MyEnum {\n" + + " FIRST;\n" + + " }\n" + + "\n" + + " public void foo(MyEnum myEnum) {\n" + + " int i = switch (myEnum) {\n" + + " case FIRST -> 1;\n" + + " default -> 0;\n" + + " };\n" + + " System.out.println( \"i:\" + i);\n" + + " }\n" + + "\n" + + " public static void main(String argv[]) {\n" + + " new X().foo(MyEnum.FIRST);\n" + + " }\n" + + "}" + }, + "i:1"); + } + public void testBug544073_056() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " public int foo(int i) {\n" + + " var v = switch(i) {\n" + + " case 0 -> x;\n" + + " default -> 1;\n" + + " };\n" + + " return v;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(new X().foo(0));\n" + + " }\n" + + "}", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case 0 -> x;\n" + + " ^\n" + + "x cannot be resolved to a variable\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug544073_057() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int foo(int i) {\n" + + " int v = switch(i) {\n" + + " case 0 -> switch(i) {\n" + + " case 0 -> 0;\n" + + " default -> 1;\n" + + " };\n" + + " default -> 1;\n" + + " };\n" + + " return v;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(new X().foo(0));\n" + + " }\n" + + "}" + }, + "0"); + } + public void testBug544073_058() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int foo(int i) {\n" + + " int v = switch(switch(i) {\n" + + " default -> 1;\n" + + " }) {\n" + + " default -> 1;\n" + + " };\n" + + " return v;\n" + + " }\n" + + "\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(new X().foo(0));\n" + + " }\n" + + "}\n" + }, + "1"); + } + public void testBug544073_059() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1: i = 10; yield true;\n" + + " default: yield false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(X.foo(0));\n" + + " }\n" + + "}" + }, + "1"); + } + public void testBug544073_060() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1: i++; yield true;\n" + + " default: yield false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(X.foo(1));\n" + + " }\n" + + "}" + }, + "0"); + } + public void testBug544073_061() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1: i+= 10; yield true;\n" + + " default: yield false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(X.foo(1));\n" + + " }\n" + + "}" + }, + "0"); + } + public void testBug544073_062() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1: switch(i) {case 4: break;}; yield true;\n" + + " default: yield false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(X.foo(1));\n" + + " }\n" + + "}" + }, + "0"); + } + public void testBug544073_063() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1: foo(5); yield true;\n" + + " default: yield false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(X.foo(1));\n" + + " }\n" + + "}" + }, + "0"); + } + public void testBug544073_064() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int foo(int i) {\n" + + " boolean v = switch (i) {\n" + + " case 1:\n" + + " switch (i) {\n" + + " case 1 : i = 10;\n" + + " break;\n" + + " default :\n" + + " i = 2;\n" + + " break;\n" + + " }\n" + + " yield true;\n" + + " default: yield false;\n" + + " };\n" + + " return v ? 0 : 1;\n" + + " }\n" + + "\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(new X().foo(0));\n" + + " }\n" + + "}\n" + }, + "1"); + } + public void testBug544073_065() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int foo(int i) {\n" + + " int v =\n" + + " switch(switch(i) {\n" + + " case 0 -> { yield 2; }\n" + + " default -> { yield 3; }\n" + + " }) {\n" + + " case 0 -> { yield 0; }\n" + + " default -> { yield 1; }\n" + + " };\n" + + " return v == 1 ? v : 0;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(new X().foo(0));\n" + + " }\n" + + "}" + }, + "1"); + } + public void testBug544073_066() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int foo(int i) {\n" + + " int k = 10;\n" + + " switch (i) {\n" + + " case 0 -> { k = 0;}\n" + + " default -> k = -1;\n" + + " }\n" + + " return k;\n" + + " }\n" + + " public static void main(String[] argv) {\n" + + " System.out.println(new X().foo(0) == 0 ? \"Success\" : \"Failure\");\n" + + " }\n" + + "\n" + + "}\n" + }, + "Success"); + } + public void testBug544073_067() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Day day) {\n" + + " switch (day) {\n" + + " case MONDAY, FRIDAY -> System.out.println(Day.SUNDAY);\n" + + " case TUESDAY -> System.out.println(7);\n" + + " case THURSDAY, SATURDAY -> System.out.println(8);\n" + + " case WEDNESDAY -> System.out.println(9);\n" + + " default -> {}\n" + + " } \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X.foo(Day.WEDNESDAY);\n" + + " }\n" + + "}\n" + + "\n" + + "enum Day {\n" + + " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" + + "}\n" + }, + "9"); + } + public void testBug544073_068() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void foo (int i) {\n"+ + " int v = switch (i) {\n"+ + " case 60, 600: yield 6;\n"+ + " case 70: yield 7;\n"+ + " case 80: yield 8;\n"+ + " case 90, 900: yield 9;\n"+ + " default: yield 0;\n"+ + " };\n"+ + " System.out.println(v);\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo(10);\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + // see comment 12 in the bug + public void testBug513766_01() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "X.java", + "public class X {\n"+ + "\n" + + " public void foo(int i) {\n"+ + " if (switch(i) { default -> magic(); })\n"+ + " System.out.println(\"true\");\n"+ + " if (magic())\n"+ + " System.out.println(\"true, too\");\n"+ + " }\n"+ + " T magic() { return null; }\n"+ + "}\n", + }; + runner.expectedCompilerLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (switch(i) { default -> magic(); })\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Object to boolean\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " if (magic())\n" + + " ^^^^^^^\n" + + "Type mismatch: cannot convert from Object to boolean\n" + + "----------\n"; + runner.javacTestOptions = JavacHasABug.JavacBug8179483_switchExpression; + runner.runNegativeTest(); + } + public void testBug544073_070() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n" + + " public static int foo(int i) throws MyException {\n"+ + " int v = switch (i) {\n"+ + " default -> throw new MyException();\n"+ + " };\n"+ + " return v;\n"+ + " }\n"+ + " public static void main(String argv[]) {\n"+ + " try {\n"+ + " System.out.println(X.foo(1));\n"+ + " } catch (MyException e) {\n"+ + " System.out.println(\"Exception thrown as expected\");\n"+ + " }\n"+ + " }\n"+ + "}\n"+ + "class MyException extends Exception {\n"+ + " private static final long serialVersionUID = 3461899582505930473L; \n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " int v = switch (i) {\n" + + " default -> throw new MyException();\n" + + " };\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "A switch expression should have at least one result expression\n" + + "----------\n"); + } + public void testBug544073_071() { + if (this.complianceLevel < ClassFileConstants.JDK12) + return; + String message = + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"; + + this.runWarningTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " String arg = \"ABD\";\n" + + " switch(arg) {\n" + + " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + message, + getCompilerOptions(), + "-Xlint:preview"); + } + public void testBug544073_072() { + if (this.complianceLevel < ClassFileConstants.JDK12) + return; + String message = + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" + + " ^^^^^^^^^^^^\n" + + "Dead code\n" + + "----------\n"; + + this.runWarningTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " String arg = \"ABD\";\n" + + " switch(arg) {\n" + + " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + message); + } + public void testBug544073_074() { + runConformTest( + new String[] { + "X.java", + "public enum X {\n"+ + " A, B; \n"+ + " public static void main(String[] args) {\n"+ + " X myEnum = X.A;\n"+ + " int o;\n"+ + " switch(myEnum) {\n"+ + " case A -> o = 5;\n"+ + " case B -> o = 10;\n"+ + " default -> o = 0;\n"+ + " }\n"+ + " System.out.println(o);\n"+ + " }\n"+ + "}\n" + }, + "5"); + } + public void testBug544073_075() { + runConformTest( + new String[] { + "X.java", + "public enum X {\n"+ + " A, B;\n"+ + " \n"+ + " public static void main(String[] args) {\n"+ + " X myEnum = X.A;\n"+ + " int o;\n"+ + " var f = switch(myEnum) {\n"+ + " case A -> o = 5;\n"+ + " case B -> o = 10;\n"+ + " };\n"+ + " System.out.println(o);\n"+ + " }\n"+ + "} \n" + }, + "5"); + } + public void testBug544073_076() { + this.runNegativeTest( + new String[] { + "X.java", + "\n"+ + "public class X {\n"+ + "\n"+ + "\n" + + " public static int foo() {\n"+ + " for (int i = 0; i < 1; ++i) {\n"+ + " int k = switch (i) {\n"+ + " case 0:\n"+ + " yield 1;\n"+ + " default:\n"+ + " continue;\n"+ + " };\n"+ + " System.out.println(k);\n"+ + " }\n"+ + " return 1;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo();\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " continue;\n" + + " ^^^^^^^^^\n" + + "'continue' or 'return' cannot be the last statement in a Switch expression case body\n" + + "----------\n"); + } + public void testBug544073_077() { + this.runNegativeTest( + new String[] { + "X.java", + "\n"+ + "public class X {\n"+ + "\n"+ + "\n" + + " public static int foo() {\n"+ + " for (int i = 0; i < 1; ++i) {\n"+ + " int k = switch (i) {\n"+ + " case 0:\n"+ + " yield 1;\n"+ + " default:\n"+ + " return 2;\n"+ + " };\n"+ + " System.out.println(k);\n"+ + " }\n"+ + " return 100;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo();\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " return 2;\n" + + " ^^^^^^^^^\n" + + "Return within switch expressions not permitted\n" + + "----------\n"); + } + public void testBug544073_078() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Day day) {\n" + + " switch (day) {\n" + + " case SATURDAY, SUNDAY, SUNDAY:\n" + + " System.out.println(\"Weekend\");\n" + + " case MONDAY:\n" + + " System.out.println(\"Weekday\");\n" + + " default: \n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "enum Day {\n" + + " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case SATURDAY, SUNDAY, SUNDAY:\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n"); + } + public void testBug544073_079() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Day day) {\n" + + " switch (day) {\n" + + " case SATURDAY, SUNDAY, MONDAY:\n" + + " System.out.println(\"Weekend\");\n" + + " case MONDAY, SUNDAY:\n" + + " System.out.println(\"Weekday\");\n" + + " default: \n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "enum Day {\n" + + " MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case SATURDAY, SUNDAY, MONDAY:\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " case MONDAY, SUNDAY:\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " case MONDAY, SUNDAY:\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n"); + } + public void testBug544073_80() { + runConformTest( + new String[] { + "X.java", + "\n"+ + "public class X {\n"+ + "\n"+ + " public static int yield() {\n"+ + " return 1;\n"+ + " }\n"+ + " public static int foo(int val) {\n"+ + " return bar (switch (val) {\n"+ + " case 1 : { yield val == 1 ? 2 : 3; }\n"+ + " default : { yield 2; }\n"+ + " });\n"+ + " }\n"+ + " public static int bar(int val) {\n"+ + " return val;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(1));\n"+ + " }\n"+ + "}\n" + }, + "2"); + } + public void testBug544073_81() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + "\n" + + " public static int foo(int val) {\n"+ + " int k = switch (val) {\n"+ + " case 1 : { break 1; }\n"+ + " default : { break 2; }\n"+ + " };\n"+ + " return k;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(1));\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case 1 : { break 1; }\n" + + " ^\n" + + "Syntax error on token \"1\", delete this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " default : { break 2; }\n" + + " ^\n" + + "Syntax error on token \"2\", delete this token\n" + + "----------\n"); + } + public void testBug547891_01() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void yield() {}\n"+ + " public static void main(String[] args) {\n"+ + " yield();\n"+ + " X.yield();\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " yield();\n" + + " ^^^^^^^\n" + + "restricted identifier yield not allowed here - method calls need to be qualified\n" + + "----------\n"); + } + public void testBug547891_02() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n"+ + " public static void yield() {}\n"+ + " public static void main(String[] args) {\n"+ + " yield();\n"+ + " }\n"+ + " public static void bar() {\n"+ + " Zork();\n"+ + " }\n"+ + "}\n", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " yield();\n" + + " ^^^^^^^\n" + + "restricted identifier yield not allowed here - method calls need to be qualified\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug547891_03() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " yield 1;\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " yield 1;\n" + + " ^^^^^\n" + + "Syntax error on token \"yield\", AssignmentOperator expected after this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"); + } + public void testBug547891_04() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " yield 1;\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " yield 1;\n" + + " ^^^^^\n" + + "Syntax error on token \"yield\", AssignmentOperator expected after this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug547891_05() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " yield y;\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " yield y;\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"); + } + public void testBug547891_06() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " yield y;\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " yield y;\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug547891_07() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " yield y = null;\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " yield y = null;\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"); + } + public void testBug547891_08() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " yield y = null;\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " yield y = null;\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug547891_09() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"); + } + public void testBug547891_10() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug547891_11() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new yield();\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new yield();\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"); + } + public void testBug547891_12() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new yield();\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " new yield();\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug547891_13() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " yield[] y;\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " yield[] y;\n" + + " ^^^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"); + } + public void testBug547891_14() { + String[] testFiles = new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " yield[] y;\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class yield {\n" + + "}\n", + }; + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " yield[] y;\n" + + " ^^^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " class yield {\n" + + " ^^^^^\n" + + "'yield' is not a valid type name; it is a restricted identifier and not allowed as a type identifier in Java 14\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog); + } + public void testBug547891_15() { + if (this.complianceLevel < ClassFileConstants.JDK12) + return; + String message = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case 1 -> yield();\n" + + " ^^^^^^^\n" + + "restricted identifier yield not allowed here - method calls need to be qualified\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " case 3 -> {yield yield();}\n" + + " ^^^^^^^\n" + + "restricted identifier yield not allowed here - method calls need to be qualified\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " default -> { yield yield();}\n" + + " ^^^^^^^\n" + + "restricted identifier yield not allowed here - method calls need to be qualified\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int r = switch(i) {\n"+ + " case 1 -> yield();\n"+ + " case 2 -> X.yield();\n"+ + " case 3 -> {yield yield();}\n"+ + " case 4 -> {yield X.yield();}\n"+ + " default -> { yield yield();}\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public static int yield() {\n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}\n" + }, + message); + } + public void testBug547891_16() { + if (this.complianceLevel < ClassFileConstants.JDK12) + return; + String message = + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " case 3 -> {yield yield();}\n" + + " ^^^^^^^\n" + + "restricted identifier yield not allowed here - method calls need to be qualified\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " default -> { yield yield();}\n" + + " ^^^^^^^\n" + + "restricted identifier yield not allowed here - method calls need to be qualified\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " \n"+ + " public int foo(int i) {\n"+ + " X x = new X();\n"+ + " int r = switch(i) {\n"+ + " case 1 -> this.yield();\n"+ + " case 2 -> x.new Y().yield();\n"+ + " case 3 -> {yield yield();}\n"+ + " case 4 -> {yield new X().yield() + x.new Y().yield();}\n"+ + " default -> { yield yield();}\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public int yield() {\n"+ + " return 0;\n"+ + " }\n"+ + " class Y {\n"+ + " public int yield() {\n"+ + " return 0;\n"+ + " } \n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new X().foo(0));\n"+ + " }\n"+ + "}\n" + }, + message); + } + public void testBug547891_17() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int yield = 100;\n"+ + " int r = switch(i) {\n"+ + " default -> yield - 1;\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public int yield() {\n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + "99"); + } + public void testBug547891_18() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int yield = 100;\n"+ + " int r = switch(i) {\n"+ + " default -> {yield - 1;}\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public int yield() {\n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + "-1"); + } + public void testBug547891_19() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int yield = 100;\n"+ + "\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int r = switch(i) {\n"+ + " default -> yield - 1;\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public int yield() {\n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + "99"); + } + public void testBug547891_20() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int yield = 100;\n"+ + "\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int r = switch(i) {\n"+ + " default -> {yield - 1;}\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public int yield() {\n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + "-1"); + } + public void testBug547891_21() { + if (this.complianceLevel < ClassFileConstants.JDK12) + return; + String message = + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " default -> yield - 1;\n" + + " ^^^^^\n" + + "Cannot make a static reference to the non-static field yield\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n"+ + " int yield = 100;\n"+ + "\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int r = switch(i) {\n"+ + " default -> yield - 1;\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public int yield() {\n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + message); + } + public void testBug547891_22() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " static int yield = 100;\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int r = switch(i) {\n"+ + " default -> X.yield();\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public static int yield() {\n"+ + " yield: while (X.yield == 100) {\n"+ + " yield = 256;\n"+ + " break yield;\n"+ + " }\n"+ + " return yield;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}\n" + }, + "256"); + } + public void testBug547891_23() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " static int yield =100 ;\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int r = switch(i) {\n"+ + " default -> X.yield();\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public static int yield() {\n"+ + " int yield = 500 ;\n"+ + " yield: while (yield == 500) {\n"+ + " yield = 1024;\n"+ + " break yield;\n"+ + " }\n"+ + " return yield;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}\n" + }, + "1024"); + } + public void testBug547891_24() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int yield = 100;\n"+ + " int r = switch(i) {\n"+ + " default -> {yield yield + 1;}\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + "101"); + } + public void testBug547891_25() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int yield = 100;\n"+ + " int r = switch(i) {\n"+ + " default -> {yield yield + yield + yield * yield;}\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + "10200"); + } + public void testBug547891_26() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int yield = 100;\n"+ + " int r = switch(i) {\n"+ + " default -> {yield + yield + yield + yield * yield;}\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + "10200"); + } + public void testBug547891_27() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int yield = 100;\n"+ + " int r = switch(i) {\n"+ + " default ->0 + yield + 10;\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + "110"); + } + public void testBug547891_28() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int yield = 100;\n"+ + " int r = switch(i) {\n"+ + " case 0 : yield 100;\n"+ + " case 1 : yield yield;\n"+ + " default: yield 0;\n"+ + " };\n"+ + " return r;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + "100"); + } + public void testBug547891_29() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " \n"+ + " public static int foo(int i) {\n"+ + " int yield = 100;\n"+ + " int r = switch(i) {\n"+ + " case 0 : yield 100;\n"+ + " case 1 : yield yield;\n"+ + " default: yield 0;\n"+ + " };\n"+ + " return r > 100 ? yield + 1 : yield + 200;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}" + }, + "300"); + } + public void testBug550354_01() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " \n"+ + " public static int foo(int i) throws Exception {\n"+ + " int v = switch (i) {\n"+ + " default -> {if (i > 0) yield 1;\n"+ + " else yield 2;}\n"+ + " };\n"+ + " return v;\n"+ + " }\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " System.out.println(X.foo(1));\n"+ + " }\n"+ + "}" + }, + "1"); + } + public void testBug548418_01() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({\"unused\" })\n"+ + " public static void main(String[] args) {\n"+ + " int day =10;\n"+ + " int i = switch (day) {\n"+ + " default -> {\n"+ + " for(int j = 0; j < 3; j++) {\n"+ + " yield 99;\n"+ + " }\n"+ + " yield 0;\n"+ + " }\n"+ + " };\n"+ + " System.out.println(i);\n"+ + " }\n"+ + "}\n" + }, + "99"); + } + public void testBug550853_01() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " \n"+ + " public static int foo(int i) throws Exception {\n"+ + " int v = switch (i) {\n"+ + " default : {yield switch (i) {\n"+ + " default -> { yield 0; } \n"+ + " };\n"+ + " }\n"+ + " };\n"+ + " return v;\n"+ + " }\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " System.out.println(X.foo(1));\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug550861_01() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " \n"+ + " public static void foo(int i) throws Exception {\n"+ + " System.out.println(switch(0) {\n"+ + " default -> {\n"+ + " do yield 1; while(false);\n"+ + " }\n"+ + " });\n"+ + " }\n"+ + " public static void main(String argv[]) throws Exception {\n"+ + " X.foo(1);\n"+ + " }\n"+ + "}\n" + }, + "1"); + } + public void testBug551030a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"nls\")\n" + + " static final String MONDAY = \"MONDAY\";\n" + + " public static void main(String[] args) {\n" + + " int num = switch (day) {\n" + + " case MONDAY: \n" + + " // Nothing\n" + + " default:\n" + + " yield \"; \n" + + " }; \n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " yield \"; \n" + + " ^^^^^^^\n" + + "String literal is not properly closed by a double-quote\n" + + "----------\n"); + } + public void testBug551030b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings(\"nls\")\n" + + " static final String MONDAY = \"MONDAY\";\n" + + " public static void main(String[] args) {\n" + + " int num = switch (day) {\n" + + " case MONDAY: \n" + + " // Nothing\n" + + " default:\n" + + " yield \"\"\"; \n" + + " }; \n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " yield \"\"\"; \n" + + " ^^^^^^^\n" + + "String literal is not properly closed by a double-quote\n" + + "----------\n"); + } + public void testBug544943() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static int foo(int i) throws MyException {\n" + + " int v = -1;\n" + + " try {\n" + + " v = switch (i) {\n" + + " case 0 -> switch(i) {\n" + + " case 0 -> 1;\n" + + " default -> throw new MyException();\n" + + " };\n" + + " default -> 1;\n" + + " };\n" + + " } finally {\n" + + " // do nothing\n" + + " }\n" + + " return v;\n" + + " } \n" + + " public static void main(String argv[]) {\n" + + " try {\n" + + " System.out.println(X.foo(0));\n" + + " } catch (MyException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}\n" + + "class MyException extends Exception {\n" + + " private static final long serialVersionUID = 3461899582505930473L; \n" + + "}" + }, + "1"); + } + public void testBug544943_2() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " \n" + + " public static int foo(int i) throws Exception {\n" + + " int v = switch (i) {\n" + + " case 0 -> switch (i) {\n" + + " case 0 -> 0;\n" + + " default-> throw new Exception();\n" + + " case 3 -> 3;\n" + + " case 2 -> throw new Exception();\n" + + " };\n" + + " default -> 0;\n" + + " };\n" + + " return v;\n" + + " }\n" + + " public static void main(String argv[]) throws Exception {\n" + + " System.out.println(X.foo(1));\n" + + " }\n" + + "}" + }, + "0"); + } + public void testBug552764_001() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13); + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " static int twice(int i) {\n" + + " switch (i) {\n" + + " default -> 3;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(twice(3));\n" + + " }\n" + + "}\n", + }; + + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " default -> 3;\n" + + " ^^^^^^^\n" + + "Arrow in case statement supported from Java 14 onwards only\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true, + options); + } + public void testBug552764_002() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13); + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " static int twice(int i) {\n" + + " return switch (i) {\n" + + " default -> 3;\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(twice(3));\n" + + " }\n" + + "}\n", + }; + + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return switch (i) {\n" + + " default -> 3;\n" + + " };\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Switch Expressions are supported from Java 14 onwards only\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " default -> 3;\n" + + " ^^^^^^^\n" + + "Arrow in case statement supported from Java 14 onwards only\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true, + options); + } + public void testBug552764_003() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_13); + String[] testFiles = new String[] { + "X.java", + "public class X {\n" + + " static int twice(int i) {\n" + + " switch (i) {\n" + + " case 1, 2 : break;\n" + + " default : break;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(twice(3));\n" + + " }\n" + + "}\n", + }; + + String expectedProblemLog = + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case 1, 2 : break;\n" + + " ^^^^^^^^^\n" + + "Multi-constant case labels supported from Java 14 onwards only\n" + + "----------\n"; + this.runNegativeTest( + testFiles, + expectedProblemLog, + null, + true, + options); + } + public void testBug558067_001() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int foo(int i, int e) {\n"+ + " LABEL: while (i == 0) {\n"+ + " i = switch (e) {\n"+ + " case 0 : {\n"+ + " for (;;) {\n"+ + " break LABEL; // NO error flagged\n"+ + " }\n"+ + " yield 1;\n"+ + " }\n"+ + " default : yield 2;\n"+ + " };\n"+ + " }\n"+ + " return i;\n"+ + " }\n"+ + " public static void main(String argv[]) {\n"+ + " new X().foo(0, 1);\n"+ + " }\n"+ + "}\n" + }, "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " break LABEL; // NO error flagged\n" + + " ^^^^^^^^^^^^\n" + + "Breaking out of switch expressions not permitted\n" + + "----------\n"); + } + public void testBug558067_002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int foo(int i, int e) {\n"+ + " TOP:System.out.println(\"hello\");\n"+ + " int x = switch(i) {\n"+ + " case 0:\n"+ + " LABEL: while (i == 0) {\n"+ + " i = switch (e) {\n"+ + " case 0 : {\n"+ + " for (;;) {\n"+ + " break LABEL;\n"+ + " }\n"+ + " yield 1;\n"+ + " }\n"+ + " default : yield 2;\n"+ + " };\n"+ + " }\n"+ + " case 2: for(;;) break TOP;\n"+ + " default: yield 0;\n"+ + " };\n"+ + " return i;\n"+ + " }\n"+ + " public static void main(String argv[]) {\n"+ + " new X().foo(0, 1);\n"+ + " }\n"+ + "} \n" + }, "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " break LABEL;\n" + + " ^^^^^^^^^^^^\n" + + "Breaking out of switch expressions not permitted\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " case 2: for(;;) break TOP;\n" + + " ^^^^^^^^^^\n" + + "Breaking out of switch expressions not permitted\n" + + "----------\n"); + } + public void testBug558067_003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int foo(int i, int e) {\n"+ + " LABEL: while (i == 0) {\n"+ + " i = switch (e) {\n"+ + " case 0 : {\n"+ + " for (;;) {\n"+ + " continue LABEL;\n"+ + " }\n"+ + " yield 1;\n"+ + " }\n"+ + " default : yield 2;\n"+ + " };\n"+ + " }\n"+ + " return i;\n"+ + " }\n"+ + " public static void main(String argv[]) {\n"+ + " new X().foo(0, 1);\n"+ + " }\n"+ + "}\n" + }, "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " continue LABEL;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Continue out of switch expressions not permitted\n" + + "----------\n"); + } + public void testBug558067_004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int foo(int i, int e) {\n"+ + " LABEL: while (i == 0) {\n"+ + " i = switch (e) {\n"+ + " case 0 : {\n"+ + " switch(e) {\n"+ + " case 0 : {\n"+ + " break LABEL;\n"+ + " }\n"+ + " }\n"+ + " yield 1;\n"+ + " }\n"+ + " default : yield 2;\n"+ + " };\n"+ + " }\n"+ + " return i;\n"+ + " }\n"+ + " public static void main(String argv[]) {\n"+ + " new X().foo(0, 1);\n"+ + " }\n"+ + "}\n" + }, "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " break LABEL;\n" + + " ^^^^^^^^^^^^\n" + + "Breaking out of switch expressions not permitted\n" + + "----------\n"); + } + public void testBug558067_005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int foo(int i, int e) {\n"+ + " LABEL: while (i == 0) {\n"+ + " i = switch (e) {\n"+ + " case 0 : {\n"+ + " switch(e) {\n"+ + " case 0 : {\n"+ + " continue LABEL;\n"+ + " }\n"+ + " }\n"+ + " yield 1;\n"+ + " }\n"+ + " default : yield 2;\n"+ + " };\n"+ + " }\n"+ + " return i;\n"+ + " }\n"+ + " public static void main(String argv[]) {\n"+ + " new X().foo(0, 1);\n"+ + " }\n"+ + "}\n" + }, "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " continue LABEL;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Continue out of switch expressions not permitted\n" + + "----------\n"); + } + public void testConversion1() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int i = 0;\n" + + " private static String typeName(byte arg){ return \"byte\"; }\n" + + " private static String typeName(char arg){ return \"char\"; }\n" + + " private static String typeName(short arg){ return \"short\"; }\n" + + " private static String typeName(int arg){ return \"int\"; }\n" + + " private static String typeName(float arg){ return \"float\"; }\n" + + " private static String typeName(long arg){ return \"long\"; }\n" + + " private static String typeName(double arg){ return \"double\"; }\n" + + " private static String typeName(String arg){ return \"String\"; }\n" + + " public static void main(String[] args) {\n" + + " byte v1 = (byte)0;\n" + + " char v2 = ' ';\n" + + " var v = switch(i+1){\n" + + " case 1 -> v2;\n" + + " case 5 -> v1;\n" + + " default -> v2;\n" + + " };\n" + + " System.out.print(typeName(v));\n" + + " }\n" + + "}\n" + }, + "int"); + } + public void testConversion2() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int i = 0;\n" + + " private static String typeName(byte arg){ return \"byte\"; }\n" + + " private static String typeName(char arg){ return \"char\"; }\n" + + " private static String typeName(short arg){ return \"short\"; }\n" + + " private static String typeName(int arg){ return \"int\"; }\n" + + " private static String typeName(float arg){ return \"float\"; }\n" + + " private static String typeName(long arg){ return \"long\"; }\n" + + " private static String typeName(double arg){ return \"double\"; }\n" + + " private static String typeName(String arg){ return \"String\"; }\n" + + " public static void main(String[] args) {\n" + + " long v1 = 0L;\n" + + " double v2 = 0.;\n" + + " var v = switch(i+1){\n" + + " case 1 -> v2;\n" + + " case 5 -> v1;\n" + + " default -> v2;\n" + + " };\n" + + " System.out.print(typeName(v));\n" + + " }\n" + + "}\n" + }, + "double"); + } + public void testConversion3() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int i = 0;\n" + + " private static String typeName(byte arg){ return \"byte\"; }\n" + + " private static String typeName(char arg){ return \"char\"; }\n" + + " private static String typeName(short arg){ return \"short\"; }\n" + + " private static String typeName(int arg){ return \"int\"; }\n" + + " private static String typeName(float arg){ return \"float\"; }\n" + + " private static String typeName(long arg){ return \"long\"; }\n" + + " private static String typeName(double arg){ return \"double\"; }\n" + + " private static String typeName(String arg){ return \"String\"; }\n" + + " public static void main(String[] args) {\n" + + " long v1 = 0L;\n" + + " float v2 = 0.f;\n" + + " var v = switch(i+1){\n" + + " case 1 -> v2;\n" + + " case 5 -> v1;\n" + + " default -> v2;\n" + + " };\n" + + " System.out.print(typeName(v));\n" + + " }\n" + + "}\n" + }, + "float"); + } + public void testConversion4() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int i = 0;\n" + + " private static String typeName(byte arg){ return \"byte\"; }\n" + + " private static String typeName(char arg){ return \"char\"; }\n" + + " private static String typeName(short arg){ return \"short\"; }\n" + + " private static String typeName(int arg){ return \"int\"; }\n" + + " private static String typeName(float arg){ return \"float\"; }\n" + + " private static String typeName(long arg){ return \"long\"; }\n" + + " private static String typeName(double arg){ return \"double\"; }\n" + + " private static String typeName(String arg){ return \"String\"; }\n" + + " public static void main(String[] args) {\n" + + " short v1 = 0;\n" + + " char v2 = ' ';\n" + + " var v = switch(i+1){\n" + + " case 1 -> v2;\n" + + " case 5 -> v1;\n" + + " default -> v2;\n" + + " };\n" + + " System.out.print(typeName(v));\n" + + " }\n" + + "}\n" + }, + "int"); + } + public void testConversion5() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int i = 0;\n" + + " private static String typeName(char arg){ return \"char\"; }\n" + + " private static String typeName(int arg){ return \"int\"; }\n" + + " private static String typeName(float arg){ return \"float\"; }\n" + + " private static String typeName(long arg){ return \"long\"; }\n" + + " private static String typeName(double arg){ return \"double\"; }\n" + + " private static String typeName(String arg){ return \"String\"; }\n" + + " public static void main(String[] args) {\n" + + " char v1 = 'a';\n" + + " var v = switch(i+1){\n" + + " case 1 -> 200;\n" + + " case 5 -> v1;\n" + + " default -> v1;\n" + + " };\n" + + " System.out.print(typeName(v));\n" + + " }\n" + + "}\n" + }, + "char"); + } + public void testBug545567_1() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({\"finally\"})\n" + + " public static void main(String[] args) {\n" + + " int t = switch (0) {\n" + + " default -> {\n" + + " try {\n" + + " yield 1;\n" + + " }\n" + + " finally {\n" + + " yield 3;\n" + + " }\n" + + " }\n" + + " };\n" + + " System.out.println(t);\n" + + " }\n" + + "}\n" + + "\n" + }, + "3"); + } + public void testBug545567_2() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({ \"finally\"})\n" + + " public static void main(String[] args) {\n" + + " float t = switch (0) {\n" + + " default -> {\n" + + " try {\n" + + " yield 1;\n" + + " }\n" + + " finally {\n" + + " yield 3;\n" + + " }\n" + + " }\n" + + " };\n" + + " System.out.println(t);\n" + + " }\n" + + "}\n" + + "\n" + }, + "3.0"); + } + public void testBug545567_3() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({ \"finally\"})\n" + + " public static void main(String[] args) {\n" + + " String t = switch (0) {\n" + + " default -> {\n" + + " try {\n" + + " yield \"one\";\n" + + " }\n" + + " finally {\n" + + " yield \"three\";\n" + + " }\n" + + " }\n" + + " };\n" + + " System.out.println(t);\n" + + " }\n" + + "}\n" + + "\n" + }, + "three"); + } + public void testBug545567_4() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({\"finally\" })\n" + + " public static void main(String[] args) {\n" + + " String t = switch (0) {\n" + + " default -> {\n" + + " try {\n" + + " yield \"one\";\n" + + " }\n" + + " catch (Exception ex) {\n" + + " yield \"two\";\n" + + " }\n" + + " finally {\n" + + " yield \"three\";\n" + + " }\n" + + " }\n" + + " };\n" + + " System.out.println(t);\n" + + " }\n" + + "}\n" + + "\n" + }, + "three"); + } + public void testBug545567_5() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({ \"finally\" })\n" + + " public static void main(String[] args) {\n" + + " String t = switch (0) {\n" + + " default -> {\n" + + " try {\n" + + " yield \"one\";\n" + + " }\n" + + " catch (Exception ex) {\n" + + " }\n" + + " yield \"zero\";\n" + + " }\n" + + " };\n" + + " System.out.print(t);\n" + + " }\n" + + "}\n" + + "\n" + }, + "one"); + } + public void testBug545567_6() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({ \"finally\"})\n" + + " public static void main(String[] args) {\n" + + " (new X()).foo(switch (0) {\n" + + " default -> {\n" + + " try {\n" + + " yield \"one\";\n" + + " }\n" + + " finally {\n" + + " yield \"zero\";\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + " public void foo (String str) {\n" + + " System.out.print(str);\n" + + " }\n" + + "}\n" + + "\n" + }, + "zero"); + } + public void testBug545567_7() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({ \"finally\"})\n" + + " public static void main(String[] args) {\n" + + " System.out.print(switch (0) {\n" + + " default -> {\n" + + " try {\n" + + " yield \"one\";\n" + + " }\n" + + " finally {\n" + + " yield \"zero\";\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + + "\n" + }, + "zero"); + } + public void testBug545567_8() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @SuppressWarnings({ \"finally\"})\n" + + " public static void main(String[] args) {\n" + + " System.out.print(switch (0) {\n" + + " default -> {\n" + + " try {\n" + + " yield 1;\n" + + " }\n" + + " catch (Exception ex) {\n" + + " yield 2;\n" + + " }\n" + + " finally {\n" + + " yield 3;\n" + + " }\n" + + " }\n" + + " });\n" + + " }\n" + + "}\n" + + "\n" + }, + "3"); + } + public void testBug545567_9() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo(args);\n"+ + " }\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public void foo(String[] args) {\n"+ + " int t = switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 1;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 2; \n"+ + " }\n"+ + " finally {\n"+ + " yield 3;\n"+ + " }\n"+ + " } \n"+ + " };\n"+ + " t += switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 1;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 2; \n"+ + " }\n"+ + " finally {\n"+ + " yield 3;\n"+ + " }\n"+ + " } \n"+ + " };\n"+ + " System.out.println(t);\n"+ + " } \n"+ + "}\n" + }, + "6"); + } + public void testBug545567_10() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo(args);\n"+ + " }\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public void foo(String[] args) {\n"+ + " int k = 0;\n"+ + " int t = switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " k = switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 10;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 20; \n"+ + " }\n"+ + " finally {\n"+ + " yield 30;\n"+ + " }\n"+ + " } \n"+ + " };\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 2; \n"+ + " }\n"+ + " finally {\n"+ + " yield 3;\n"+ + " }\n"+ + " } \n"+ + " };\n"+ + " System.out.println(t + k);\n"+ + " } \n"+ + "}\n" + }, + "33"); + } + public void testBug545567_11() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo(args);\n"+ + " }\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public void foo(String[] args) {\n"+ + " int k = 0;\n"+ + " int t = switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " k = switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 10;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 20; \n"+ + " }\n"+ + " } \n"+ + " };\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 2; \n"+ + " }\n"+ + " finally {\n"+ + " yield 3;\n"+ + " }\n"+ + " } \n"+ + " };\n"+ + " System.out.println(t + k);\n"+ + " } \n"+ + "}\n" + }, + "13"); + } + public void testBug545567_12() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo(args);\n"+ + " }\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public void foo(String[] args) {\n"+ + " int k = 0;\n"+ + " int t = switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " k = switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 10;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 20; \n"+ + " }\n"+ + " finally {\n"+ + " yield 30;\n"+ + " }\n"+ + " } \n"+ + " };\n"+ + " }\n"+ + " finally {\n"+ + " yield 3;\n"+ + " }\n"+ + " } \n"+ + " };\n"+ + " System.out.println(t + k);\n"+ + " } \n"+ + "}\n" + }, + "33"); + } + public void testBug545567_13() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (1) {\n"+ + " case 0 -> {yield 100;}\n"+ + " default -> { \n"+ + " try {\n"+ + " yield 1;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 2;\n"+ + " }\n"+ + " finally {\n"+ + " yield 3; \n"+ + " }\n"+ + " } \n"+ + " } + switch (10) {\n"+ + " case 0 -> {yield 1024;}\n"+ + " default -> { \n"+ + " try {\n"+ + " yield 10;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 20;\n"+ + " }\n"+ + " finally {\n"+ + " yield 30; \n"+ + " }\n"+ + " } \n"+ + " }); \n"+ + " }\n"+ + "}\n" + }, + "33"); + } + public void testBug545567_14() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (1) {\n"+ + " case 0 -> {yield 100;}\n"+ + " default -> { \n"+ + " try {\n"+ + " yield 1;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 2;\n"+ + " }\n"+ + " finally {\n"+ + " yield switch (10) {\n"+ + " case 0 -> {yield 1024;}\n"+ + " default -> { \n"+ + " try {\n"+ + " yield 10;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 20;\n"+ + " }\n"+ + " finally {\n"+ + " yield 30; \n"+ + " }\n"+ + " } \n"+ + " }; }\n"+ + " } \n"+ + " }); \n"+ + " }\n"+ + "}\n" + }, + "30"); + } + public void testBug545567_15() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (1) {\n"+ + " case 0 -> {yield 100;}\n"+ + " default -> { \n"+ + " try {\n"+ + " yield 1;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 2;\n"+ + " }\n"+ + " finally {\n"+ + " System.out.println(switch (1) {\n"+ + " default -> {yield 100;}});\n"+ + " yield 1;\n"+ + " }\n"+ + " } \n"+ + " }); \n"+ + " }\n"+ + "}\n" + }, + "100\n1"); + } + public void testBug545567_16() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (1) {\n"+ + " case 0 -> {yield 100;}\n"+ + " default -> { \n"+ + " try {\n"+ + " yield switch (10) {\n"+ + " case 0 -> {yield 1024;}\n"+ + " default -> { \n"+ + " try {\n"+ + " yield 10; \n"+ + " } \n"+ + " catch (Exception ex) {\n"+ + " yield 20; \n"+ + " } \n"+ + " finally {\n"+ + " yield 30; \n"+ + " } \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " catch (Exception ex) {\n"+ + " yield 2;\n"+ + " } \n"+ + " finally {\n"+ + " yield 3; } \n"+ + " } \n"+ + " }); \n"+ + " } \n"+ + "}\n" + }, + "3"); + } + public void testBug545567_17() { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (1) {\n"+ + " case 0 -> {yield 100;}\n"+ + " default -> { \n"+ + " try {\n"+ + " System.out.println( switch (10) {\n"+ + " case 0 -> {yield 1024;}\n"+ + " default -> { \n"+ + " try {\n"+ + " yield 10; \n"+ + " } \n"+ + " catch (Exception ex) {\n"+ + " yield 20; \n"+ + " } \n"+ + " finally {\n"+ + " yield 30; \n"+ + " } \n"+ + " } \n"+ + " }); \n"+ + " yield 1; \n"+ + " } \n"+ + " catch (Exception ex) {\n"+ + " yield 2;\n"+ + " } \n"+ + " finally {\n"+ + " yield 3; } \n"+ + " } \n"+ + " }); \n"+ + " } \n"+ + "}\n" + }, + "30\n"+ + "3"); + } + public void testBug545567_18() { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static void main(String[] args) {\n"+ + " new X().foo(args);\n"+ + " } \n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public void foo(String[] args) {\n"+ + " int t = 0;\n"+ + " t += switch (200) {\n"+ + " case 0 -> {yield 100;}\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 1;\n"+ + " } \n"+ + " catch (Exception ex) {\n"+ + " yield 2; \n"+ + " } \n"+ + " finally {\n"+ + " yield 3;\n"+ + " } \n"+ + " }\n"+ + " };\n"+ + " System.out.println(t);\n"+ + " } \n"+ + "}\n" + }, + "3"); + } + public void testBug545567_19() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (1) {\n"+ + " default -> { \n"+ + " try { \n"+ + " yield switch (10) {\n"+ + " default -> { \n"+ + " try {\n"+ + " yield 10; \n"+ + " } \n"+ + " catch (Exception ex) {\n"+ + " yield 20; \n"+ + " } \n"+ + " finally {\n"+ + " yield 30; \n"+ + " } \n"+ + " } \n"+ + " }; \n"+ + " } \n"+ + " catch (Exception ex) {\n"+ + " yield 2;\n"+ + " } \n"+ + " finally {\n"+ + " yield 3; } \n"+ + " } \n"+ + " }); \n"+ + " } \n"+ + "} \n"+ + "\n" + }, + "3"); + } + // test with Autocloseable + public void testBug545567_20() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (1) {\n"+ + " default -> { \n"+ + " try(Y y = new Y();) { \n"+ + " yield 1;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 2;\n"+ + " } \n"+ + " finally {\n"+ + " yield 3;\n" + + " }\n"+ + " }\n"+ + " });\n"+ + " }\n"+ + "} \n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {\n"+ + " // do nothing\n"+ + " }\n"+ + "}\n" + }, + "3"); + } + public void testBug545567_21() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (1) {\n"+ + " default -> { \n"+ + " try(Y y = new Y();) { \n"+ + " yield 10;\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " } \n"+ + " yield 3;\n" + + " }\n"+ + " });\n"+ + " }\n"+ + "} \n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {\n"+ + " // do nothing\n"+ + " }\n"+ + "}\n" + }, + "10"); + } + public void testBug545567_22() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " int argslength = args.length;\n"+ + " int t = switch (1) {\n"+ + " case 0 -> {\n"+ + " yield 100;\n"+ + " }\n"+ + " default -> {\n"+ + " try (Y y = new Y();){\n"+ + " if (argslength < 1)\n"+ + " yield 10;\n"+ + " else\n"+ + " yield 12;\n"+ + " } catch (Exception ex) {\n"+ + " yield 2;\n"+ + " } finally {\n"+ + " yield 3;\n"+ + " }\n"+ + " }\n"+ + " }; \n"+ + " System.out.println(t);\n"+ + " }\n"+ + "}\n"+ + " \n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {\n"+ + " // do nothing\n"+ + " } \n"+ + "}\n" + }, + "3"); + } + public void testBug545567_23() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " int t = switch (1) {\n"+ + " case 0 -> {\n"+ + " yield 100;\n"+ + " }\n"+ + " default -> {\n"+ + " try {\n"+ + " throw new Exception();\n"+ + " } catch (Exception ex) {\n"+ + " yield 2;\n"+ + " } finally {\n"+ + " yield 3;\n"+ + " }\n"+ + " }\n"+ + " }; \n"+ + " System.out.println(t);\n"+ + " }\n"+ + "}\n"+ + " \n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {\n"+ + " // do nothing\n"+ + " } \n"+ + "}\n" + }, + "3"); + } + public void testBug545567_24() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo();\n"+ + " }\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public void foo() {\n"+ + " int t = switch (1) {\n"+ + " case 0 -> {\n"+ + " yield bar(100);\n"+ + " }\n"+ + " default -> {\n"+ + " final Y y2 = new Y();\n"+ + " try (Y y = new Y(); y2){\n"+ + " yield bar(10);\n"+ + " } catch (Exception ex) {\n"+ + " yield bar(2);\n"+ + " } finally {\n"+ + " yield bar(3);\n"+ + " }\n"+ + " }\n"+ + " }; \n"+ + " System.out.println(t);\n"+ + " }\n"+ + " public int bar(int i) {\n"+ + " return i;\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {\n"+ + " // do nothing\n"+ + " }\n"+ + "}" + }, + "3"); + } + public void testBug545567_25() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo();\n"+ + " }\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public void foo() {\n"+ + " int t = switch (1) {\n"+ + " case 0 -> {\n"+ + " yield bar(100);\n"+ + " }\n"+ + " default -> {\n"+ + " final Y y2 = new Y();\n"+ + " try (Y y = new Y(); y2){\n"+ + " yield new X().bar(10);\n"+ + " } catch (Exception ex) {\n"+ + " yield bar(2);\n"+ + " } finally {\n"+ + " yield new X().bar(3);\n"+ + " }\n"+ + " }\n"+ + " }; \n"+ + " System.out.println(t);\n"+ + " }\n"+ + " public int bar(int i) {\n"+ + " return i;\n"+ + " }\n"+ + "}\n"+ + "\n"+ + "class Y implements AutoCloseable {\n"+ + " @Override\n"+ + " public void close() throws Exception {\n"+ + " // do nothing\n"+ + " }\n"+ + "}" + }, + "3"); + } + public void testBug571929_normal() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(\"a\"));\n" + + " }\n" + + " private static boolean foo(String s) {\n" + + " bar(0L);\n" + + " return switch (s) {\n" + + " case \"a\" -> {\n" + + " try {\n" + + " yield true;\n" + + " } finally {\n" + + " }\n" + + " }\n" + + " default -> false;\n" + + " };\n" + + " }\n" + + " private static void bar(long l) {}\n" + + "}" + }, + "true"); + } + public void testBug571929_lambda() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(\"a\"));\n" + + " }\n" + + " static long m = 0L;\n" + + " private static boolean foo(String s) {\n" + + " long l = m;\n" + + " // capture l\n" + + " Runnable r = () -> bar(l);\n" + + " return switch (s) {\n" + + " case \"a\" -> {\n" + + " try {\n" + + " yield true;\n" + + " } finally {\n" + + " }\n" + + " }\n" + + " default -> false;\n" + + " };\n" + + " }\n" + + " private static void bar(long l) {}\n" + + "}" + }, + "true"); + } + public void testBug561762_001() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo(1);\n"+ + " }\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public void foo(int i) {\n"+ + " int t = switch (1) { \n"+ + " case 0 -> {\n"+ + " yield 0;\n"+ + " }\n"+ + " default -> {\n"+ + " I lam2 = (x) -> {\n"+ + " yield 2000;\n"+ + " };\n"+ + " yield 1;\n"+ + " }\n"+ + " };\n"+ + " System.out.println(t);\n"+ + " }\n"+ + "}\n"+ + "interface I {\n"+ + " public int apply(int i);\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " yield 2000;\n" + + " ^^^^^^^^^^^\n" + + "yield outside of switch expression\n" + + "----------\n"); + + } + public void testBug561766_001() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (1) {\n"+ + " case 0 -> {yield switch(0) {}\n"+ + " } \n"+ + " default -> {\n"+ + " yield 3;\n"+ + " }\n"+ + " });\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case 0 -> {yield switch(0) {}\n" + + " ^\n" + + "Syntax error, insert \";\" to complete BlockStatements\n" + + "----------\n"); + + } + public void testBug561766_002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (1) {\n"+ + " case 0 -> {yield 100;}\n"+ + " default -> { \n"+ + " try {\n"+ + " yield switch(0) {\n"+ + " }\n"+ + " catch (Exception ex) {\n"+ + " yield 2;\n"+ + " }\n"+ + " finally {\n"+ + " yield 3;\n"+ + " }\n"+ + " } \n"+ + " }); \n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \";\" to complete YieldStatement\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete Block\n" + + "----------\n" + + "3. ERROR in X.java (at line 18)\n" + + " }\n" + + " ^\n" + + "Syntax error on token \"}\", delete this token\n" + + "----------\n" + + "4. ERROR in X.java (at line 19)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \"}\" to complete ClassBody\n" + + "----------\n"); + + } + + public void testBug562129() { + if (this.complianceLevel < ClassFileConstants.JDK14) return; + runNegativeTest( + new String[] { + "SwitchExpressionError.java", + "class SwitchExpressionError {\n" + + "\n" + + " static boolean howMany(int k) {\n" + + " return false || switch (k) {\n" + + " case 1 -> true;\n" + + " case 2 -> Boolean.FALSE;\n" + + " case 3 -> r;\n" + + " };\n" + + " }\n" + + "\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in SwitchExpressionError.java (at line 4)\n" + + " return false || switch (k) {\n" + + " ^\n" + + "A switch expression should have a default case\n" + + "----------\n" + + "2. ERROR in SwitchExpressionError.java (at line 7)\n" + + " case 3 -> r;\n" + + " ^\n" + + "r cannot be resolved to a variable\n" + + "----------\n"); + } + public void testBug572121() { + Map compilerOptions = getCompilerOptions(); + // must disable this option to trigger compilation restart + compilerOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.DISABLED); + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private void foo(int i) {\n" + + " }\n" + + "\n" + + " private static void bar() {\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " if (f) {\n" + + " Object o = switch (j) {\n" + + " default -> {\n" + + " try {\n" + + " bar();\n" + + " } catch (Throwable e) {\n" + + " }\n" + + " yield null;\n" + + " }\n" + + " };\n" + + " }\n" + + " int i = 0;\n" + + " x.foo(i++);\n" + + " }\n" + + "\n" + + " private static boolean f = true;\n" + + " private static int j;\n" + + " private static X x = new X();\n" + + "}" + }, + "", + compilerOptions + ); + } + public void testBug562198_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " int a[] = {1, 2, 3};\n"+ + " public int foo() {\n"+ + " return switch (0) {\n"+ + " case 0 -> {\n"+ + " yield a[0];\n"+ + " }\n"+ + " default -> {\n"+ + " try {\n"+ + " // do nothing\n"+ + " } finally {\n"+ + " // do nothing\n"+ + " }\n"+ + " yield 0;\n"+ + " }\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(new X().foo());\n"+ + " }\n"+ + "}\n" + }, + "1"); + } + public void testBug562728_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static public void main (String[] args) {\n"+ + " int a = 0x21;\n"+ + " int b = 0xff;\n"+ + " switch (a) {\n"+ + " case 0x21 -> {\n"+ + " switch (b) {\n"+ + " default -> System.out.println(\"default\");\n"+ + " }\n"+ + " }\n"+ + " case 0x3b -> System.out.println(\"3b <- WTH?\");\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "default"); + } + public void testBug562728_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static public void main (String[] args) {\n"+ + " int a = 0x21;\n"+ + " int b = 0xff;\n"+ + " switch (a) {\n"+ + " case 0x21 -> {\n"+ + " switch (b) {\n"+ + " default -> System.out.println(\"default\");\n"+ + " }\n"+ + " return;\n"+ + " }\n"+ + " case 0x3b -> System.out.println(\"3b <- WTH?\");\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "default"); + } + public void testBug562728_003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static public void main (String[] args) throws Exception {\n"+ + " int a = 0x21;\n"+ + " int b = 0xff;\n"+ + " switch (a) {\n"+ + " case 0x21 -> {\n"+ + " switch (b) {\n"+ + " default -> throw new Exception();\n"+ + " }\n"+ + " return; \n"+ + " }\n"+ + " case 0x3b -> System.out.println(\"3b <- WTH?\");\n"+ + " }\n"+ + " }\n"+ + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " return; \n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); + + } + public void testBug562728_004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static public void main (String[] args) throws Exception {\n"+ + " int a = 0x21;\n"+ + " int b = 0xff;\n"+ + " Zork();\n"+ + " switch (a) {\n"+ + " case 0x21 -> {\n"+ + " switch (b) {\n"+ + " default -> {\n"+ + " for (;;) {\n"+ + " if (b > 1)\n"+ + " throw new Exception();\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " case 0x3b -> System.out.println(\"3b <- WTH?\");\n"+ + " }\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug562728_005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static int foo(int i) { \n"+ + " int v; \n"+ + " int t = switch (i) { \n"+ + " case 0 : { \n"+ + " yield 0; \n"+ + " } \n"+ + " case 2 :v = 2;\n"+ + " default :v = 2;\n"+ + " }; \n"+ + " return t; \n"+ + " } \n"+ + " \n"+ + " public boolean bar() { \n"+ + " return true; \n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(3));\n"+ + " } \n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " default :v = 2;\n" + + " ^^\n" + + "A switch labeled block in a switch expression should not complete normally\n" + + "----------\n"); + } + public void testBug562728_006() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static int foo(int i) { \n"+ + " int v; \n"+ + " int t = switch (i) { \n"+ + " case 0 -> { \n"+ + " yield 0; \n"+ + " } \n"+ + " case 2 ->{v = 2;}\n"+ + " default ->{v = 2;}\n"+ + " }; \n"+ + " return t; \n"+ + " } \n"+ + " \n"+ + " public boolean bar() { \n"+ + " return true; \n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(3));\n"+ + " } \n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " case 2 ->{v = 2;}\n" + + " ^^\n" + + "A switch labeled block in a switch expression should not complete normally\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " default ->{v = 2;}\n" + + " ^^\n" + + "A switch labeled block in a switch expression should not complete normally\n" + + "----------\n"); + } + public void testBug562728_007() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " public static int foo(int i) { \n"+ + " int v; \n"+ + " int t = switch (i) { \n"+ + " case 0 -> { \n"+ + " return 1;\n"+ + " } \n"+ + " default ->100;\n"+ + " }; \n"+ + " return t; \n"+ + " } \n"+ + " \n"+ + " public boolean bar() { \n"+ + " return true; \n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(3));\n"+ + " } \n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " return 1;\n" + + " ^^^^^^^^^\n" + + "Return within switch expressions not permitted\n" + + "----------\n"); +} + public void testBug563023_001() { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " static public int foo(int a, int b){\n"+ + " int t = switch (a) {\n"+ + " default -> {\n"+ + " switch (b) {\n"+ + " default -> {\n"+ + " yield 0;\n"+ + " }\n"+ + " } \n"+ + " }\n"+ + " };\n"+ + " return t;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0, 0));\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug563023_002() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " static public int foo(int a, int b){\n"+ + " int t = switch (a) {\n"+ + " default -> {\n"+ + " switch (b) {\n"+ + " case 0 -> {\n"+ + " break;\n"+ + " }\n"+ + " default -> {\n"+ + " yield 0;\n"+ + " }\n"+ + " } \n"+ + " }\n"+ + " };\n"+ + " return t;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0, 0));\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " }\n" + + " ^^\n" + + "A switch labeled block in a switch expression should not complete normally\n" + + "----------\n"); +} + public void testBug563023_003() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " static public int foo(int a, int b){\n"+ + " int t = switch (a) {\n"+ + " default -> {\n"+ + " switch (b) {\n"+ + " case 0 -> {\n"+ + " yield 0;\n"+ + " }\n"+ + " } \n"+ + " }\n"+ + " };\n"+ + " return t;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0, 0));\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " }\n" + + " ^^\n" + + "A switch labeled block in a switch expression should not complete normally\n" + + "----------\n"); +} + public void testBug563023_004() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " static public int foo(int a, int b){\n"+ + " int t = switch (a) {\n"+ + " default -> {\n"+ + " switch (b) {\n"+ + " case 0 -> {\n"+ + " break;\n"+ + " }\n"+ + " default -> yield 0;\n"+ + " } \n"+ + " }\n"+ + " };\n"+ + " return t;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0, 0));\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " default -> yield 0;\n" + + " ^\n" + + "Syntax error on token \"0\", delete this token\n" + + "----------\n"); +} + public void testBug563023_005() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " static public int foo(int a, int b){\n"+ + " int t = switch (a) {\n"+ + " default -> {\n"+ + " switch (b) {\n"+ + " case 0 -> {\n"+ + " break;\n"+ + " }\n"+ + " default ->{ yield 0;}\n"+ + " } \n"+ + " }\n"+ + " };\n"+ + " return t;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0, 0));\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " }\n" + + " ^^\n" + + "A switch labeled block in a switch expression should not complete normally\n" + + "----------\n"); +} + public void testBug563023_006() { + runConformTest( + new String[] { + "X.java", + "public class X { \n"+ + " static public int foo(MyEnum a, MyEnum b){\n"+ + " int t = switch (a) {\n"+ + " default -> {\n"+ + " switch (b) {\n"+ + " case ONE -> { \n"+ + " yield 0;\n"+ + " }\n"+ + " default -> {yield 1;}\n"+ + " } \n"+ + " }\n"+ + " };\n"+ + " return t;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(MyEnum.ONE, MyEnum.TWO));\n"+ + " }\n"+ + "} \n"+ + "enum MyEnum {\n"+ + " ONE,\n"+ + " TWO\n"+ + "}\n" + }, + "1"); + } + public void testBug563023_007() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X { \n"+ + " static public int foo(MyEnum a, MyEnum b){\n"+ + " int t = switch (a) {\n"+ + " default -> {\n"+ + " switch (b) {\n"+ + " case ONE -> { \n"+ + " yield 0;\n"+ + " }\n"+ + " } \n"+ + " }\n"+ + " };\n"+ + " return t;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(MyEnum.ONE, MyEnum.TWO));\n"+ + " }\n"+ + "} \n"+ + "enum MyEnum {\n"+ + " ONE,\n"+ + " TWO\n"+ + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " switch (b) {\n" + + " ^\n" + + "The enum constant TWO needs a corresponding case label in this enum switch on MyEnum\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " }\n" + + " ^^\n" + + "A switch labeled block in a switch expression should not complete normally\n" + + "----------\n"); +} + public void testBug563147_001() { + runConformTest( + new String[] { + "X.java", + "interface I {\n"+ + " public int apply();\n"+ + "}\n"+ + "public class X { \n"+ + " static public int foo(int a){\n"+ + " int t = switch (a) {\n"+ + " default -> {\n"+ + " I lambda = () -> { return 0;};\n"+ + " yield lambda.apply();\n"+ + " }\n"+ + " };\n"+ + " return t;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(1));\n"+ + " }\n"+ + "} \n" + }, + "0"); + } + public void testBug563147_002() { + runConformTest( + new String[] { + "X.java", + "interface FI {\n"+ + " public int foo();\n"+ + "}\n"+ + "public class X {\n"+ + " public int field = 0;\n"+ + " public int test() {\n"+ + " var v = switch (field) {\n"+ + " case 0 -> {\n"+ + " yield ((FI ) () -> {\n"+ + " int i = 0;\n"+ + " while (true) {\n"+ + " i++;\n"+ + " if (i == 7) {\n"+ + " break;\n"+ + " }\n"+ + " }\n"+ + " return i;\n"+ + " }); \n"+ + " }\n"+ + " default -> {\n"+ + " yield null;\n"+ + " }\n"+ + " }; \n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " int t = new X().test();\n"+ + " System.out.println(t);\n"+ + "}\n"+ + "}\n" + }, + "0"); + } + public void testBug563147_003() { + this.runNegativeTest( + new String[] { + "X.java", + "interface FI {\n"+ + " public int foo();\n"+ + "}\n"+ + "public class X {\n"+ + " public int field = 0;\n"+ + " public int test() {\n"+ + " var v = switch (field) {\n"+ + " case 0 -> {\n"+ + " yield ((F ) () -> {\n"+ + " int i = 0;\n"+ + " while (true) {\n"+ + " i++;\n"+ + " if (i == 7) {\n"+ + " break;\n"+ + " }\n"+ + " }\n"+ + " return i;\n"+ + " }); \n"+ + " }\n"+ + " default -> {\n"+ + " yield null;\n"+ + " }\n"+ + " }; \n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " int t = new X().test();\n"+ + " System.out.println(t);\n"+ + "}\n"+ + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " yield ((F ) () -> {\n" + + " ^\n" + + "F cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " yield ((F ) () -> {\n" + + " ^^^^^\n" + + "The target type of this expression must be a functional interface\n" + + "----------\n"); + } + public void testBug565156_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int test() {\n"+ + " return switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 0;\n"+ + " }\n"+ + " catch (RuntimeException e) {\n"+ + " throw e;\n"+ + " }\n"+ + " }\n"+ + " };\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " int i = new X().test();\n"+ + " System.out.println(i);\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug565156_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int test() {\n"+ + " return switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 0;\n"+ + " }\n"+ + " finally {\n"+ + " //do nothing\n"+ + " }\n"+ + " }\n"+ + " };\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " int i = new X().test();\n"+ + " System.out.println(i);\n"+ + " }\n"+ + "}\n" + }, + "0"); + } + public void testBug565156_003() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int test() {\n"+ + " return switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 0;\n"+ + " }\n"+ + " finally {\n"+ + " int i = 20;"+ + " yield 20;"+ + " }\n"+ + " }\n"+ + " };\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " int i = new X().test();\n"+ + " System.out.println(i);\n"+ + " }\n"+ + "}\n" + }, + "20"); + } + public void testBug565156_004() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int test() {\n"+ + " return switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 100;\n"+ + " }\n"+ + " finally {\n"+ + " yield 200; \n"+ + " }\n"+ + " }\n"+ + " };\n"+ + " }\n"+ + " finally {\n"+ + " yield 20;\n"+ + " }\n"+ + " }\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " int i = new X().test();\n"+ + " System.out.println(i);\n"+ + " }\n"+ + "}" + }, + "20"); + } + public void testBug565156_005() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int test() {\n"+ + " return switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 100;\n"+ + " }\n"+ + " finally {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + " };\n"+ + " }\n"+ + " finally {\n"+ + " // do nothing\n"+ + " }\n"+ + " }\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args){\n"+ + " int i = new X().test();\n"+ + " System.out.println(i);\n"+ + " }\n"+ + "}" + }, + "100"); + } + public void testBug565156_006() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo(args);\n"+ + " }\n"+ + "\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public void foo(String[] args) {\n"+ + " int t = switch (0) {\n"+ + " default -> {\n"+ + " try {\n"+ + " if (args == null)\n"+ + " yield 1;\n"+ + " else if (args.length ==2)\n"+ + " yield 2; \n"+ + " else if (args.length == 4)\n"+ + " yield 4;\n"+ + " else yield 5; \n"+ + " } finally {\n"+ + " yield 3; \n"+ + " }\n"+ + " }\n"+ + " }; \n"+ + " t = switch (100) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 10;\n"+ + " } finally {\n"+ + " }\n"+ + " } \n"+ + " }; \n"+ + " System.out.println(t);\n"+ + " }\n"+ + "}" + }, + "10"); + } + public void testBug565156_007() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " new X().foo(args);\n"+ + " }\n"+ + "\n"+ + " @SuppressWarnings({ \"finally\" })\n"+ + " public void foo(String[] args) {\n"+ + " int t = switch (0) {\n"+ + " case 101 -> {yield 101;}\n"+ + " default -> {\n"+ + " try {\n"+ + " if (args == null)\n"+ + " yield 1;\n"+ + " else if (args.length ==2)\n"+ + " yield 2; \n"+ + " else if (args.length == 4)\n"+ + " yield 4;\n"+ + " else yield 5; \n"+ + " } finally {\n"+ + " yield 3; \n"+ + " }\n"+ + " }\n"+ + " }; \n"+ + " t = switch (100) {\n"+ + " default -> {\n"+ + " try {\n"+ + " yield 10;\n"+ + " } finally {\n"+ + " }\n"+ + " } \n"+ + " }; \n"+ + " System.out.println(t);\n"+ + " }\n"+ + "}" + }, + "10"); + } + public void testBug547193_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(switch (0) {default -> {\n"+ + " try {\n"+ + " yield 1;\n"+ + " } catch (Exception ex) {\n"+ + " yield 2;\n"+ + " }\n"+ + " }});\n"+ + " }\n"+ + "}" + }, + "1"); + } + public void testBug565844_01() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public final static int j = 5;\n" + + " public static void main(String argv[]) {\n" + + " boolean b = \n" + + " switch (j) {\n" + + " case j != 1 ? 2 : 3 -> true;\n" + + " default -> false;\n" + + " }; \n" + + " System.out.println(b);\n" + + " }\n"+ + "}" + }, + "false"); + } + public void testBug565844_02() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public final static int j = 2;\n" + + " public static void main(String argv[]) {\n" + + " boolean b = \n" + + " switch (j) {\n" + + " case j != 1 ? 2 : (j == 2 ? 4 : 5) -> true;\n" + + " default -> false;\n" + + " }; \n" + + " System.out.println(b);\n" + + " }\n"+ + "}" + }, + "true"); + } + public void testBug565844_03() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public final static int j = 5;\n" + + " public static void main(String argv[]) {\n" + + " boolean b = \n" + + " switch (j) {\n" + + " case j != 1 ? 2 : 3 -> {\n" + + " yield true;\n" + + " }\n" + + " default -> { yield false;}\n" + + " }; \n" + + " System.out.println(b);\n" + + " }\n"+ + "}" + }, + "false"); + } + public void testBug565844_04() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public final static int j = 5;\n" + + " public static void main(String argv[]) {\n" + + " boolean b = \n" + + " switch (j) {\n" + + " case j != 1 ? 2 : 3 : {\n" + + " yield true;\n" + + " }\n" + + " default : { yield false;}\n" + + " }; \n" + + " System.out.println(b);\n" + + " }\n"+ + "}" + }, + "false"); + } + public void testBug565844_05() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int j = 5;\n" + + " public static void main(String argv[]) {\n" + + " boolean b = \n" + + " switch (j) {\n" + + " case j != 1 ? 2 : 3 -> {\n" + + " yield true;\n" + + " }\n" + + " default -> { yield false;}\n" + + " }; \n" + + " System.out.println(b);\n" + + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case j != 1 ? 2 : 3 -> {\n" + + " ^^^^^^^^^^^^^^\n" + + "case expressions must be constant expressions\n" + + "----------\n"); + } + public void testBug565844_06() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public final static int j = 5;\n" + + " public static void main(String argv[]) {\n" + + " boolean b = \n" + + " switch (j) {\n" + + " case j != 1 ? ( j != 1 ? 2: 3 ) : 3 -> false;\n" + + " default -> false;\n" + + " }; \n" + + " System.out.println(b);\n" + + " }\n"+ + "}" + }, + "false"); + } + public void testBug565844_07() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + "\n"+ + " void foo() {\n"+ + " Object value2 = switch(1) {\n"+ + " case AAABBB -> 1;\n"+ + " (I)()->();\n"+ + " default -> 0;\n"+ + " };\n"+ + " }\n"+ + "}\n"+ + "interface I {\n"+ + " void apply();\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case AAABBB -> 1;\n" + + " ^\n" + + "Syntax error on token \";\", case expected after this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " (I)()->();\n" + + " ^^^^^\n" + + "Syntax error on token(s), misplaced construct(s)\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " (I)()->();\n" + + " ^\n" + + "Syntax error, insert \")\" to complete Expression\n" + + "----------\n" + + "4. ERROR in X.java (at line 6)\n" + + " (I)()->();\n" + + " ^\n" + + "Syntax error, insert \":\" to complete SwitchLabel\n" + + "----------\n"); + } + public void _testBug565844SwitchConst_07() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public final static int j = 5;\n" + + " public static void main(String argv[]) {\n" + + " boolean b = \n" + + " switch (j) {\n" + + " case switch(1) {default -> 2;} -> false;\n" + + " default -> false;\n" + + " }; \n" + + " System.out.println(b);\n" + + " }\n"+ + "}" + }, + "false"); + } + public void _testBug565844SwitchConst_08() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public final static int j = 5;\n" + + " public static void main(String argv[]) {\n" + + " boolean b = \n" + + " switch (j) {\n" + + " case switch(1) {case 1 -> 2; default -> 0;} -> false;\n" + + " default -> false;\n" + + " }; \n" + + " System.out.println(b);\n" + + " }\n"+ + "}" + }, + "false"); + } + public void _testBug565844SwitchConst_09() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public final static int j = 5;\n" + + " public static void main(String argv[]) {\n" + + " boolean b = \n" + + " switch (j) {\n" + + " case switch(1) {default -> 2;}, switch(2) {default -> 3;} -> false;\n" + + " default -> false;\n" + + " }; \n" + + " System.out.println(b);\n" + + " }\n"+ + "}" + }, + "false"); + } + public void _testBug565844SwitchConst_10() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public final static int j = 5;\n" + + " public static void main(String argv[]) {\n" + + " boolean b = \n" + + " switch (j) {\n" + + " case switch(1) {case 1 -> 2; default -> 0;}," + + " switch(2) {case 1 -> 3; default -> 4;} -> false;\n" + + " default -> false;\n" + + " }; \n" + + " System.out.println(b);\n" + + " }\n"+ + "}" + }, + "false"); + } + public void testBug566125_01() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().bar(0);\n" + + " }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public void bar(int i) {\n" + + " boolean b = foo( switch(i+1) {\n" + + " case 0 -> new Short((short)0);\n" + + " case 2 -> new Double(2.0d);\n" + + " default -> new Integer((short)6);\n" + + " });\n" + + " System.out.println(b);\n" + + " }\n" + + " boolean foo(short data){ return false; }\n" + + " boolean foo(byte data){ return false; }\n" + + " boolean foo(int data){ return false; }\n" + + " boolean foo(float data){ return false; }\n" + + " boolean foo(long data){ return false; }\n" + + " boolean foo(double data){ return true; }\n" + + "}" + }, + "true"); + + } + // Same as above, but with explicit yield + public void testBug566125_02() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().bar(0);\n" + + " }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public void bar(int i) {\n" + + " boolean b = foo( switch(i+1) {\n" + + " case 0 : yield new Short((short)0);\n" + + " case 2 : yield new Double(2.0d);\n" + + " default : yield new Integer((short)6);\n" + + " });\n" + + " System.out.println(b);\n" + + " }\n" + + " boolean foo(short data){ return false; }\n" + + " boolean foo(byte data){ return false; }\n" + + " boolean foo(int data){ return false; }\n" + + " boolean foo(float data){ return false; }\n" + + " boolean foo(long data){ return false; }\n" + + " boolean foo(double data){ return true; }\n" + + "}" + }, + "true"); + + } + public void testBug566125_03() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().bar(0);\n" + + " }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public void bar(int i) {\n" + + " boolean b = foo( switch(i+1) {\n" + + " case 0 -> new Short((short)0);\n" + + " case 2 -> 2.0d;\n" + + " default -> new Integer((short)6);\n" + + " });\n" + + " System.out.println(b);\n" + + " }\n" + + " boolean foo(short data){ return false; }\n" + + " boolean foo(byte data){ return false; }\n" + + " boolean foo(int data){ return false; }\n" + + " boolean foo(float data){ return false; }\n" + + " boolean foo(long data){ return false; }\n" + + " boolean foo(double data){ return true; }\n" + + "}" + }, + "true"); + + } + // Long -> float is accepted + public void testBug566125_04() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().bar(0);\n" + + " }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public void bar(int i) {\n" + + " boolean b = foo( switch(i+1) {\n" + + " case 0 -> new Integer((short)0);\n" + + " default -> 2l;\n" + + " });\n" + + " System.out.println(b);\n" + + " }\n" + + " boolean foo(int data){ return false; }\n" + + " boolean foo(long data){ return true; }\n" + + "}" + }, + "true"); + + } + public void testBug566125_05() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().bar(0);\n" + + " }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public void bar(int i) {\n" + + " boolean b = foo(\n" + + " switch(i%2) {\n" + + " case 1 -> switch(i) {\n" + + " case 1 -> new Byte((byte)1);\n" + + " case 3 -> new Float(3);\n" + + " case 5 -> new Long(5);\n" + + " default -> new Short((short)6);\n" + + " }; \n" + + " default -> switch(i) {\n" + + " case 0 -> new Integer((byte)2);\n" + + " case 2 -> new Double(4);\n" + + " case 4 -> new Long(6);\n" + + " default -> new Short((short)8);\n" + + " };\n" + + " }\n" + + " );\n" + + " System.out.println(b);\n" + + " }\n" + + " boolean foo(short data){ return false; }\n" + + " boolean foo(byte data){ return false; }\n" + + " boolean foo(int data){ return false; }\n" + + " boolean foo(float data){ return false; }\n" + + " boolean foo(long data){ return false; }\n" + + " boolean foo(double data){ return true; }\n" + + "}" + }, + "true" + ); + + } + public void testBug566125_06() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().bar(0);\n" + + " }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public void bar(int i) {\n" + + " boolean b = foo( switch(i+1) {\n" + + " case 0 -> Short.valueOf((short)0);\n" + + " default -> Double.valueOf(2.0d);\n" + + " });\n" + + " System.out.println(b);\n" + + " }\n" + + " boolean foo(short data){ return false; }\n" + + " boolean foo(byte data){ return false; }\n" + + " boolean foo(int data){ return false; }\n" + + " boolean foo(float data){ return false; }\n" + + " boolean foo(long data){ return false; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " boolean b = foo( switch(i+1) {\n" + + " ^^^\n" + + "The method foo(short) in the type X is not applicable for the arguments (double)\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " default -> Double.valueOf(2.0d);\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Type mismatch: cannot convert from Double to short\n" + + "----------\n" + ); + } + public void testBug566125_07() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().bar(0);\n" + + " }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public void bar(int i) {\n" + + " boolean b = foo( switch(i+1) {\n" + + " case 0 -> Short.valueOf((short)0);\n" + + " default -> 2.0d;\n" + + " });\n" + + " System.out.println(b);\n" + + " }\n" + + " boolean foo(short data){ return false; }\n" + + " boolean foo(byte data){ return false; }\n" + + " boolean foo(int data){ return false; }\n" + + " boolean foo(float data){ return false; }\n" + + " boolean foo(long data){ return false; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " boolean b = foo( switch(i+1) {\n" + + " ^^^\n" + + "The method foo(short) in the type X is not applicable for the arguments (double)\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " default -> 2.0d;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from double to short\n" + + "----------\n" + ); + } + // Same as 07() but with explicit yield + public void testBug566125_08() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " new X().bar(0);\n" + + " }\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " public void bar(int i) {\n" + + " boolean b = foo( switch(i+1) {\n" + + " case 0 : yield Short.valueOf((short)0);\n" + + " default : yield 2.0d;\n" + + " });\n" + + " System.out.println(b);\n" + + " }\n" + + " boolean foo(short data){ return false; }\n" + + " boolean foo(byte data){ return false; }\n" + + " boolean foo(int data){ return false; }\n" + + " boolean foo(float data){ return false; }\n" + + " boolean foo(long data){ return false; }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " boolean b = foo( switch(i+1) {\n" + + " ^^^\n" + + "The method foo(short) in the type X is not applicable for the arguments (double)\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " default : yield 2.0d;\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from double to short\n" + + "----------\n" + ); + } + public void testBug567112_001() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n"+ + "\n"+ + "public class X {\n"+ + " public void foo() {\n"+ + " new ArrayList<>().stream().filter(p -> p != null)\n"+ + " switch (\"\") {\n"+ + " case \"\":\n"+ + " }\n"+ + " }\n"+ + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " new ArrayList<>().stream().filter(p -> p != null)\n" + + " ^^^^^\n" + + "Syntax error on tokens, delete these tokens\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \")\" to complete Expression\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " }\n" + + " ^\n" + + "Syntax error, insert \";\" to complete BlockStatements\n" + + "----------\n" + ); + } + public void testBug571833_01() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static int foo(int a) {\n"+ + " int b = (int) switch (a) {\n"+ + " case 1 -> 1.0;\n"+ + " default -> 0;\n"+ + " };\n"+ + " return b;\n"+ + " }\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " int b = foo(2);\n"+ + " System.out.println(b);\n"+ + " }\n"+ + "}" + }, + "0" + ); + + } + public void testBug572382() { + runConformTest( + new String[] { + "X.java", + "import java.lang.invoke.MethodHandle;\n"+ + "\n"+ + "public class X {\n"+ + "\n"+ + " Object triggerBug(MethodHandle method) throws Throwable {\n"+ + " return switch (0) {\n"+ + " case 0 -> method.invoke(\"name\");\n"+ + " default -> null;\n"+ + " };\n"+ + " }\n"+ + "}\n" + }, + (String)null + ); + + } + public void testBug576026() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " enum E { A }\n" + + " static class C {\n" + + " E e = E.A;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " C c = new C();\n" + + " switch (c.e) {\n" + + " case A -> {\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + " default -> System.out.println(\"Wrong\");\n" + + " }\n" + + " }\n" + + "}", + }, + "Success"); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java new file mode 100644 index 0000000000..66d81ff517 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java @@ -0,0 +1,4103 @@ +/******************************************************************************* + * Copyright (c) 2021 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 + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.io.IOException; +import java.util.Map; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.core.util.ClassFormatException; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +public class SwitchPatternTest extends AbstractRegressionTest9 { + + static { +// TESTS_NUMBERS = new int [] { 40 }; +// TESTS_RANGE = new int[] { 1, -1 }; +// TESTS_NAMES = new String[] { "testBug575737"}; + } + + private static String previewLevel = "17"; + + public static Class testClass() { + return SwitchPatternTest.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_17); + } + public SwitchPatternTest(String testName){ + super(testName); + } + + // Enables the tests to run individually + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_17); // FIXME + defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_17); + defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_17); + defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + return defaultOptions; + } + + @Override + protected void runConformTest(String[] testFiles, String expectedOutput) { + runConformTest(testFiles, expectedOutput, "", getCompilerOptions()); + } + @Override + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { + runConformTest(testFiles, expectedOutput, "", customOptions); + } + protected void runConformTest(String[] testFiles, String expectedOutput, String errorOutput) { + runConformTest(testFiles, expectedOutput, errorOutput, getCompilerOptions()); + } + protected void runConformTest(String[] testFiles, String expectedOutput, String expectedErrorOutput, Map customOptions) { + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedOutputString = expectedOutput; + runner.expectedErrorString = expectedErrorOutput; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.customOptions = customOptions; + runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel); + runner.runConformTest(); + } + @Override + protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) { + runNegativeTest(testFiles, expectedCompilerLog, ""); + } + protected void runNegativeTest(String[] testFiles, String expectedCompilerLog, String javacLog) { + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedCompilerLog; + runner.expectedJavacOutputString = expectedCompilerLog; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.customOptions = getCompilerOptions(); + runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel); + runner.runNegativeTest(); + runNegativeTest(testFiles, expectedCompilerLog, JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel)); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog) { + runWarningTest(testFiles, expectedCompilerLog, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, Map customOptions) { + runWarningTest(testFiles, expectedCompilerLog, customOptions, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, + Map customOptions, String javacAdditionalTestOptions) { + + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedCompilerLog; + runner.customOptions = customOptions; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel) : + JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel, javacAdditionalTestOptions); + runner.runWarningTest(); + } + + private static void verifyClassFile(String expectedOutput, String classFileName, int mode) + throws IOException, ClassFormatException { + File f = new File(OUTPUT_DIR + File.separator + classFileName); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", mode); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + System.out.println("..."); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } + } + public void testBug573516_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer i -> System.out.println(\"String:\");\n"+ + " case String s -> System.out.println(\"String: Hello World!\");\n"+ + " default -> System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " }\n"+ + "}", + }, + "String: Hello World!"); + } + public void testBug573516_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case String s -> System.out.println(\"String:\");\n"+ + " default -> System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug573516_003() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case String s : System.out.println(\"String:\"); break;\n"+ + " case Integer i : System.out.println(\"Integer:\");break;\n"+ + " default : System.out.println(\"Object\");break;\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug573516_004() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer t && t > 0 -> System.out.println(\"Integer && t > 0\");\n"+ + " default -> System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug573516_005() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer t, String s, X x : System.out.println(\"Integer, String or X\");\n"+ + " default : System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class Y {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case Integer t, String s, X x : System.out.println(\"Integer, String or X\");\n" + + " ^^^^^^^^\n" + + "A switch label may not have more than one pattern case label element\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug573516_006() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer t, String s && s.length > 0, X x && x.hashCode() > 10 : System.out.println(\"Integer, String or X\");\n"+ + " default : System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class Y {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case Integer t, String s && s.length > 0, X x && x.hashCode() > 10 : System.out.println(\"Integer, String or X\");\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "A switch label may not have more than one pattern case label element\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " case Integer t, String s && s.length > 0, X x && x.hashCode() > 10 : System.out.println(\"Integer, String or X\");\n" + + " ^^^^^^\n" + + "length cannot be resolved or is not a field\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug573516_007() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer t, String : System.out.println(\"Error should be flagged for String\");\n"+ + " default : System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class Y {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case Integer t, String : System.out.println(\"Error should be flagged for String\");\n" + + " ^^^^^^\n" + + "String cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug573516_008() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o.hashCode()) {\n"+ + " case Integer t, String : System.out.println(\"Error should be flagged for Integer and String\");\n"+ + " default : System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class Y {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case Integer t, String : System.out.println(\"Error should be flagged for Integer and String\");\n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from int to Integer\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " case Integer t, String : System.out.println(\"Error should be flagged for Integer and String\");\n" + + " ^^^^^^\n" + + "String cannot be resolved to a variable\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug573516_009() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o.hashCode()) {\n"+ + " case default : System.out.println(\"Default\");\n"+ + " default : System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class Y {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " default : System.out.println(\"Object\");\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug573516_010() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o.hashCode()) {\n"+ + " case String s, default : System.out.println(\"Error should be flagged for String and default\");\n"+ + " default : System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class Y {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case String s, default : System.out.println(\"Error should be flagged for String and default\");\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " case String s, default : System.out.println(\"Error should be flagged for String and default\");\n" + + " ^^^^^^^\n" + + "A switch label may not have both a pattern case label element and a default case label element\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " default : System.out.println(\"Object\");\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n" + + "4. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug573516_011() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o.hashCode()) {\n"+ + " case var s : System.out.println(\"Error should be ANY_PATTERN\");\n"+ + " default : System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class Y {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case var s : System.out.println(\"Error should be ANY_PATTERN\");\n" + + " ^^^\n" + + "'var' is not allowed here\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug574228_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case 1: System.out.println(\"Integer\"); break;\n"+ + " default : System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case 1: System.out.println(\"Integer\"); break;\n" + + " ^\n" + + "Type mismatch: cannot convert from int to Object\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + + public void testBug573936_01() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer I: \n"+ + " System.out.println(\"Integer\"); \n"+ + " System.out.println(I); \n"+ + " case String s && s.length()>1: \n"+ + " System.out.println(\"String s && s.length()>1\"); \n"+ + " System.out.println(s); \n"+ + " break;// error no fallthrough allowed in pattern\n"+ + " case X x:\n"+ + " System.out.println(\"X\"); \n"+ + " System.out.println(x);\n"+ + " break;\n"+ + " default : System.out.println(\"Object\"); \n"+ + " }\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World!\");\n"+ + " foo(\"H\");\n"+ + " foo(bar());\n"+ + " }\n"+ + " public static Object bar() { return new Object();}\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case String s && s.length()>1: \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Illegal fall-through to a pattern\n" + + "----------\n"); + } + public void testBug573939_01() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer s : System.out.println(\"Integer\");\n"+ + " case String s1: System.out.println(\"String \");\n"+ + " default : System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World\");\n"+ + " Zork();\n"+ + " }\n"+ + "}\n"+ + "class Y {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case String s1: System.out.println(\"String \");\n" + + " ^^^^^^^^^^^^^^\n" + + "Illegal fall-through to a pattern\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug573939_02() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer I: System.out.println(\"Integer\"); break;\n"+ + " case String s && s.length()>1: System.out.println(\"String > 1\"); break;\n"+ + " case String s1: System.out.println(\"String\"); break;\n"+ + " case X x: System.out.println(\"X\"); break;\n"+ + " default : System.out.println(\"Object\");\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World!\");\n"+ + " foo(\"H\");\n"+ + " foo(bar());\n"+ + " }\n"+ + " public static Object bar() { return new Object();}\n"+ + "}", + }, + "String > 1\n" + + "String\n" + + "Object"); + } + public void testBug573939_03() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer I: \n"+ + " System.out.println(\"Integer\"); \n"+ + " System.out.println(I); \n"+ + " break; \n"+ + " case String s && s.length()>1: \n"+ + " System.out.println(\"String s && s.length()>1\"); \n"+ + " System.out.println(s); \n"+ + " break;\n"+ + " case String s1: \n"+ + " System.out.println(\"String\"); \n"+ + " System.out.println(s1);\n"+ + " break; \n"+ + " case X x:\n"+ + " System.out.println(\"X\"); \n"+ + " System.out.println(x);\n"+ + " break;\n"+ + " default : System.out.println(\"Object\"); \n"+ + " }\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World!\");\n"+ + " foo(\"H\");\n"+ + " foo(bar());\n"+ + " }\n"+ + " public static Object bar() { return new Object();}\n"+ + "}", + }, + "String s && s.length()>1\n" + + "Hello World!\n" + + "String\n" + + "H\n" + + "Object"); + } + public void testBug573939_03b() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer I: \n"+ + " System.out.println(\"Integer\"); \n"+ + " System.out.println(I); \n"+ + " break; \n"+ + " case String s && s.length()>1: \n"+ + " System.out.println(\"String s && s.length()>1\"); \n"+ + " System.out.println(s); \n"+ + " break;\n"+ + " case String s: \n"+ + " System.out.println(\"String\"); \n"+ + " System.out.println(s);\n"+ + " break; \n"+ + " case X x:\n"+ + " System.out.println(\"X\"); \n"+ + " System.out.println(x);\n"+ + " break;\n"+ + " default : System.out.println(\"Object\"); \n"+ + " }\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World!\");\n"+ + " foo(\"H\");\n"+ + " foo(bar());\n"+ + " }\n"+ + " public static Object bar() { return new Object();}\n"+ + "}", + }, + "String s && s.length()>1\n" + + "Hello World!\n" + + "String\n" + + "H\n" + + "Object"); + } + public void test045() { + this.runNegativeTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " public static void main(String[] args) {\n" + + " switch (args.length) {\n" + + " case 1:\n" + + " final int j = 1;\n" + + " case 2:\n" + + " switch (5) {\n" + + " case j:\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " case j:\n" + + " ^\n" + + "The local variable j may not have been initialized\n" + + "----------\n"); + } + public void testBug574525_01() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer I: \n"+ + " System.out.println(\"Integer\"); \n"+ + " System.out.println(I); \n"+ + " break; \n"+ + " case null:\n"+ + " System.out.println(\"NULL\"); \n"+ + " break;\n"+ + " default : System.out.println(\"Object\"); \n"+ + " }\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " foo(null);\n"+ + " }\n"+ + "}", + }, + "NULL"); + } + public void testBug574525_02() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer I: \n"+ + " System.out.println(\"Integer\"); \n"+ + " System.out.println(I); \n"+ + " break; \n"+ + " case String s && s.length()>1: \n"+ + " System.out.println(\"String s && s.length()>1\"); \n"+ + " System.out.println(s); \n"+ + " break;\n"+ + " case String s1: \n"+ + " System.out.println(\"String\"); \n"+ + " System.out.println(s1);\n"+ + " break; \n"+ + " case X x:\n"+ + " System.out.println(\"X\"); \n"+ + " System.out.println(x);\n"+ + " break;\n"+ + " case null:\n"+ + " System.out.println(\"NULL\"); \n"+ + " break;\n"+ + " default : System.out.println(\"Object\"); \n"+ + " }\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World!\");\n"+ + " foo(null);\n"+ + " foo(bar());\n"+ + " }\n"+ + " public static Object bar() { return new Object();}\n"+ + "}", + }, + "String s && s.length()>1\n" + + "Hello World!\n" + + "NULL\n" + + "Object"); + } + public void testBug574525_03() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Integer o) {\n"+ + " switch (o) {\n"+ + " case 10: \n"+ + " System.out.println(\"Integer\"); \n"+ + " System.out.println(o); \n"+ + " break; \n"+ + " case null:\n"+ + " System.out.println(\"NULL\"); \n"+ + " break;\n"+ + " default : System.out.println(o); \n"+ + " }\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " foo(0);\n"+ + " }\n"+ + "}", + }, + "0"); + } + public void testBug574525_04() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(int o) {\n"+ + " switch (o) {\n"+ + " case 10: \n"+ + " System.out.println(\"Integer\"); \n"+ + " System.out.println(o); \n"+ + " break; \n"+ + " case null:\n"+ + " System.out.println(\"NULL\"); \n"+ + " break;\n"+ + " default : System.out.println(o); \n"+ + " }\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " foo(0);\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " case null:\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from null to int\n" + + "----------\n"); + } + public void testBug574538_01() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(Integer.valueOf(11));\n"+ + " foo(Integer.valueOf(9));\n"+ + " }\n"+ + "\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer i && i>10:\n"+ + " System.out.println(\"Greater than 10:\" + o);\n"+ + " break;\n"+ + " case Integer j && j>0:\n"+ + " System.out.println(\"Greater than 0:\" + o);\n"+ + " break;\n"+ + " default:\n"+ + " System.out.println(\"Object\" + o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "Greater than 10:11\n" + + "Greater than 0:9"); + } + public void testBug574538_02() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo1(Integer.valueOf(10));\n"+ + " foo1(Integer.valueOf(11));\n"+ + " foo1(\"Hello World!\");\n"+ + " }\n"+ + "\n"+ + " private static void foo1(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer i&&i>10 -> System.out.println(\"Greater than 10:\");\n"+ + " case String s&&s.equals(\"ff\") -> System.out.println(\"String:\" + s);\n"+ + " default -> System.out.println(\"Object:\" + o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "Object:10\n" + + "Greater than 10:\n" + + "Object:Hello World!"); + } + + public void testBug574549_01() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World!\");\n"+ + " }\n"+ + "\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case default:\n"+ + " System.out.println(\"Object: \" + o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "Object: Hello World!"); + } + public void testBug574549_02() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(Integer.valueOf(11));\n"+ + " foo(Integer.valueOf(9));\n"+ + " foo(\"Hello World!\");\n"+ + " }\n"+ + "\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer i && i>10:\n"+ + " System.out.println(\"Greater than 10:\" + o);\n"+ + " break;\n"+ + " case Integer j && j>0:\n"+ + " System.out.println(\"Greater than 0:\" + o);\n"+ + " break;\n"+ + " case default:\n"+ + " System.out.println(\"Give Me Some SunShine:\" + o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "Greater than 10:11\n" + + "Greater than 0:9\n" + + "Give Me Some SunShine:Hello World!"); + } + public void testBug574549_03() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World!\");\n"+ + " }\n"+ + "\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer i :\n"+ + " System.out.println(\"Integer:\" + o);\n"+ + " break;\n"+ + " case default:\n"+ + " System.out.println(\"Object\" + o);\n"+ + " case default:\n"+ + " System.out.println(\"Give me Some Sunshine\" + o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " case default:\n" + + " ^^^^^^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"); + } + public void testBug574549_04() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World!\");\n"+ + " }\n"+ + "\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer i :\n"+ + " System.out.println(\"Integer:\" + o);\n"+ + " break;\n"+ + " case default:\n"+ + " System.out.println(\"Object\" + o);\n"+ + " default:\n"+ + " System.out.println(\"Give me Some Sunshine\" + o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " default:\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"); + } + // Test that when a pattern variable is unused and when the OPTION_PreserveUnusedLocal + // option is used, no issue is reported at runtime. + public void testBug573937_1() { + Map options = getCompilerOptions(); + String opt = options.get(CompilerOptions.OPTION_PreserveUnusedLocal); + try { + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.DISABLED); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Hello\");\n" + + " }\n" + + " public static void foo(Object o) {\n" + + " switch (o) {\n" + + " case String s:\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "Hello", + options); + } finally { + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, opt); + } + } + // A simple pattern variable in a case is not visible in the + // following case statement + public void testBug573937_2() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " switch (o) {\n" + + " case String s:\n" + + " System.out.println(s);\n" + + " break;\n" + + " case Integer i:\n" + + " System.out.println(s);\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n"); + } + // Same as above, but without break statement + public void testBug573937_3() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " switch (o) {\n" + + " case String s:\n" + + " System.out.println(s);\n" + + " case Integer i:\n" + + " System.out.println(s);\n" + + " default:\n" + + " System.out.println(s);\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " System.out.println(s);\n" + + " ^\n" + + "s cannot be resolved to a variable\n" + + "----------\n"); + } + // Test that compiler rejects attempts to redeclare local variable + // with same name as a pattern variable + public void testBug573937_4() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " switch (o) {\n" + + " case String s:\n" + + " String s = null;\n" + + " System.out.println(s);\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " String s = null;\n" + + " ^\n" + + "Duplicate local variable s\n" + + "----------\n"); + } + // Test that compiler allows local variable with same name as a + // pattern variable in a different case statement + public void testBug573937_5() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " switch (o) {\n" + + " case String s:\n" + + " System.out.println(s);\n" + + " break;\n" + + " default:\n" + + " String s = null;\n" + + " break;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(\"hello\");\n" + + " }\n" + + "}", + }, + "hello"); + } + // Test that a pattern variable can't use name of an already existing local + // variable + public void testBug573937_6() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " switch (o) {\n" + + " case String o:\n" + + " System.out.println(o);\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case String o:\n" + + " ^\n" + + "Duplicate local variable o\n" + + "----------\n"); + } + // Test that compiler rejects attempts to redeclare another pattern + // variable (instanceof) with same name as that a pattern variable in + // that case statement + public void testBug573937_7() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " switch (o) {\n" + + " case String s1:\n" + + " if (o instanceof String s1) {\n" + + " System.out.println(s1);\n" + + " }\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + "} ", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " if (o instanceof String s1) {\n" + + " ^^\n" + + "Duplicate local variable s1\n" + + "----------\n"); + } + // Test that when multiple case statements declare pattern variables + // with same name, correct ones are used in their respective scopes. + public void testBug573937_8() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " switch (o) {\n" + + " case String s1:\n" + + " System.out.println(s1.length());\n" + + " break;\n" + + " case Integer s1:\n" + + " System.out.println(s1.length());\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + "} ", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " System.out.println(s1.length());\n" + + " ^^^^^^\n" + + "The method length() is undefined for the type Integer\n" + + "----------\n"); + } + // Test that a pattern variable declared in the preceding case statement + // can't be used in the case statement itself + public void testBug573937_9() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " switch (o) {\n" + + " case Integer i1:\n" + + " break;\n" + + " case String s1 && s1.length() > i1:\n" + + " System.out.println(s1.length());\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + "} ", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case String s1 && s1.length() > i1:\n" + + " ^^\n" + + "i1 cannot be resolved to a variable\n" + + "----------\n"); + } + // Test that redefining pattern variables with null is allowed + // and produce expected result (NPE) when run. + public void testBug573937_10() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "X.java", + "public class X {\n" + + "@SuppressWarnings(\"null\")" + + " public static void foo(Object o) {\n" + + " try {\n" + + " switch (o) {\n" + + " case String s1 && s1.length() == 0:\n" + + " break;" + + " case String s1:\n" + + " s1 = null;\n" + + " System.out.println(s1.length());\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " } catch(Exception e) {\n" + + " System.out.println(e.getMessage());\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(\"hello\");\n" + + " }\n" + + "}", + }; + runner.expectedOutputString = "Cannot invoke \"String.length()\" because \"s1\" is null"; + runner.expectedJavacOutputString = "Cannot invoke \"String.length()\" because \"\" is null"; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.customOptions = getCompilerOptions(); + runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel); + runner.runConformTest(); + } + // Test that a pattern variable is allowed in a switch label throw + // statement and when run, produces expected result + public void testBug573937_11() { + Runner runner = new Runner(); + runner.testFiles = new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) throws Exception {\n" + + " switch (o) {\n" + + " case String s1:\n" + + " throw new Exception(s1);\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " try {\n" + + " foo(\"hello\");\n" + + " } catch(Exception e) {\n" + + " e.printStackTrace(System.out);\n" + + " };\n" + + " }\n" + + "} ", + }; + runner.expectedOutputString = "java.lang.Exception: hello\n" + + " at X.foo(X.java:5)\n" + + " at X.main(X.java:12)"; + runner.expectedJavacOutputString = "java.lang.Exception: hello\n" + + " at X.foo(X.java:5)\n" + + " at X.main(X.java:12)"; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.customOptions = getCompilerOptions(); + runner.javacTestOptions = JavacTestOptions.forReleaseWithPreview(SwitchPatternTest.previewLevel); + runner.runConformTest(); + } + // A non effectively final referenced from the RHS of the guarding expression + // is reported by the compiler. + public void testBug574612_1() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " int len = 2;\n" + + " switch (o) {\n" + + " case String o1 && o1.length() > len:\n" + + " len = 0;\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + "} ", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case String o1 && o1.length() > len:\n" + + " ^^^\n" + + "Local variable len referenced from a guard must be final or effectively final\n" + + "----------\n"); + } + // A non effectively final referenced from the LHS of the guarding expression + // is reported by the compiler. + public void testBug574612_2() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " int len = 2;\n" + + " switch (o) {\n" + + " case String o1 && len < o1.length():\n" + + " len = 0;\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + "} ", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case String o1 && len < o1.length():\n" + + " ^^^\n" + + "Local variable len referenced from a guard must be final or effectively final\n" + + "----------\n"); + } + // An explicitly final local variable, also referenced in a guarding expression of a pattern + // and later on re-assigned is only reported for the explicit final being modified + public void testBug574612_3() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " final int len = 2;\n" + + " switch (o) {\n" + + " case String o1 && len < o1.length():\n" + + " len = 0;\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + "} ", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " len = 0;\n" + + " ^^^\n" + + "The final local variable len cannot be assigned. It must be blank and not using a compound assignment\n" + + "----------\n"); + } + public void testBug574612_4() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Object o) {\n" + + " int len = 2;\n" + + " switch (o) {\n" + + " case String o1 && len < o1.length():\n" + + " System.out.println(o1);\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) throws Exception {\n" + + " foo(\"hello\");\n" + + " }\n" + + "} ", + }, + "hello"); + } + public void testBug574719_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int foo(Integer o) {\n"+ + " int k = 0;\n"+ + " switch (o) {\n"+ + " case 0, default : k = 1;\n"+ + " }\n"+ + " return k;\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(100 ));\n"+ + " }\n"+ + "}", + }, + "1"); + } + public void testBug574719_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int foo(Integer o) {\n"+ + " int k = 0;\n"+ + " switch (o) {\n"+ + " case 0, default, 1 : k = 1;\n"+ + " }\n"+ + " return k;\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(100 ));\n"+ + " }\n"+ + "}", + }, + "1"); + } + public void testBug574719_003() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int foo(Integer o) {\n"+ + " int k = 0;\n"+ + " switch (o) {\n"+ + " case default, 1 : k = 1;\n"+ + " }\n"+ + " return k;\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(100));\n"+ + " System.out.println(foo(0));\n"+ + " }\n"+ + "}", + }, + "1\n" + + "1"); + } + public void testBug574719_004() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int foo(Integer o) {\n"+ + " int k = 0;\n"+ + " switch (o) {\n"+ + " case 0 : k = 2; break;\n"+ + " case default, 1 : k = 1;\n"+ + " }\n"+ + " return k;\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(100));\n"+ + " System.out.println(foo(0));\n"+ + " }\n"+ + "}", + }, + "1\n" + + "2"); + } + public void testBug574719_005() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int foo(Integer o) {\n"+ + " int k = 0;\n"+ + " switch (o) {\n"+ + " case 0 : k = 2; break;\n"+ + " case 1, default : k = 1;\n"+ + " }\n"+ + " return k;\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(100));\n"+ + " System.out.println(foo(0));\n"+ + " }\n"+ + "}", + }, + "1\n" + + "2"); + } + public void testBug574719_006() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int foo(Integer o) {\n"+ + " int k = 0;\n"+ + " switch (o) {\n"+ + " case 0 : k = 2; break;\n"+ + " case 1, default, default : k = 1;\n"+ + " }\n"+ + " return k;\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(100));\n"+ + " System.out.println(foo(0));\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case 1, default, default : k = 1;\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"); + } + public void testBug574719_007() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int foo(Integer o) {\n"+ + " int k = 0;\n"+ + " switch (o) {\n"+ + " case 10, default: k = 1;break;\n"+ + " case 0 : k = 2; break;\n"+ + " }\n"+ + " return k;\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(100));\n"+ + " System.out.println(foo(0));\n"+ + " System.out.println(foo(10));\n"+ + " }\n"+ + "}", + }, + "1\n"+ + "2\n"+ + "1"); + } + public void testBug574561_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int foo(Integer o) {\n"+ + " int k = 0;\n"+ + " switch (o) {\n"+ + " default, default : k = 2; break;\n"+ + " }\n"+ + " return k;\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(100));\n"+ + " System.out.println(foo(0));\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " default, default : k = 2; break;\n" + + " ^\n" + + "Syntax error on token \",\", : expected\n" + + "----------\n"); + } + public void testBug574561_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int foo(Integer o) {\n"+ + " int k = 0;\n"+ + " switch (o) {\n"+ + " case default, 1, default : k = 1;\n"+ + " }\n"+ + " return k;\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(100));\n"+ + " System.out.println(foo(0));\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case default, 1, default : k = 1;\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"); + } + public void testBug574561_003() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static int foo(Integer o) {\n"+ + " int k = 0;\n"+ + " switch (o) {\n"+ + " case default, 1, default : k = 1;\n"+ + " }\n"+ + " return k;\n"+ + " } \n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(100));\n"+ + " System.out.println(foo(0));\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case default, 1, default : k = 1;\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"); + } + public void testBug574793_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {}\n"+ + " private static void foo1(int o) {\n"+ + " switch (o) {\n"+ + " case null -> System.out.println(\"null\");\n"+ + " case 20 -> System.out.println(\"20\");\n"+ + " }\n"+ + " }\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case \"F\" :\n"+ + " break;\n"+ + " case 2 :\n"+ + " break;\n"+ + " default:\n"+ + " break;\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " switch (o) {\n" + + " ^\n" + + "An enhanced switch statement should be exhaustive; a default label expected\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " case null -> System.out.println(\"null\");\n" + + " ^^^^\n" + + "Type mismatch: cannot convert from null to int\n" + + "----------\n" + + "3. ERROR in X.java (at line 11)\n" + + " case \"F\" :\n" + + " ^^^\n" + + "Type mismatch: cannot convert from String to Object\n" + + "----------\n" + + "4. ERROR in X.java (at line 13)\n" + + " case 2 :\n" + + " ^\n" + + "Type mismatch: cannot convert from int to Object\n" + + "----------\n"); + } + public void testBug574559_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {}\n"+ + " public static void foo1(Integer o) {\n"+ + " switch (o) {\n"+ + " case 1, Integer i -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case 1, Integer i -> System.out.println(o);\n" + + " ^^^^^^^^^\n" + + "Illegal fall-through to a pattern\n" + + "----------\n"); + } + public void testBug574559_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {}\n"+ + " private static void foo1(Integer o) {\n"+ + " switch (o) {\n"+ + " case Integer i, 30 -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case Integer i, 30 -> System.out.println(o);\n" + + " ^^\n" + + "This case label is dominated by one of the preceding case label\n" + + "----------\n"); + } + // Test that fall-through to a pattern is not allowed (label statement group has one statement) + public void testBug573940_1() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + "public void foo(Number n) {\n" + + " switch (n) {\n" + + " case Integer i :\n" + + " System.out.println(i);\n" + + " case Float f :\n" + + " System.out.println(f);\n" + + " case Object o : break;\n" + + " }\n" + + "}\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case Float f :\n" + + " ^^^^^^^^^^^^\n" + + "Illegal fall-through to a pattern\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " case Object o : break;\n" + + " ^^^^^^^^^^^^^\n" + + "Illegal fall-through to a pattern\n" + + "----------\n"); + } + // Test that fall-through to a pattern is not allowed (label statement group has zero statement) + public void testBug573940_2() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + "public void foo(Number n) {\n" + + " switch (n) {\n" + + " case Integer i :\n" + + " case Float f :\n" + + " System.out.println(f);\n" + + " break;\n" + + " default : break;\n" + + " }\n" + + "}\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case Float f :\n" + + " ^^^^^^^^^^^^\n" + + "Illegal fall-through to a pattern\n" + + "----------\n"); + } + // Test that fall-through to a pattern is not allowed (label statement group has zero statement) + public void testBug573940_2a() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + "public void foo(Number n) {\n" + + " switch (n) {\n" + + " default :\n" + + " case Float f :\n" + + " System.out.println(f);\n" + + " break;\n" + + " }\n" + + "}\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case Float f :\n" + + " ^^^^^^^^^^^^\n" + + "Illegal fall-through to a pattern\n" + + "----------\n"); + } + // Test that falling through from a pattern to a default is allowed + public void testBug573940_3() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void foo(Number n) {\n" + + " switch (n) {\n" + + " case Integer i :\n" + + " System.out.println(i);\n" + + " default:\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " }\n" + + "public static void main(String[] args) {\n" + + " foo(Integer.valueOf(5));\n" + + " }\n" + + "}", + }, + "5\n" + + "null"); + } + // Test that a case statement with pattern is allowed when statement group ends + // with an Throw statement instead of a break statement + public void testBug573940_4() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "public static void foo(Number n) {\n" + + " switch (n) {\n" + + " case Integer i :\n" + + " throw new IllegalArgumentException();\n" + + " default:\n" + + " System.out.println(\"null\");\n" + + " }\n" + + " }\n" + + "public static void main(String[] args) {\n" + + " try{\n" + + " foo(Integer.valueOf(5));\n" + + " } catch(Exception e) {\n" + + " e.printStackTrace(System.out);\n" + + " }\n" + + " }\n" + + "}", + }, + "java.lang.IllegalArgumentException\n" + + " at X.foo(X.java:5)\n" + + " at X.main(X.java:12)"); + } + // Test that switch expression with pattern variables is reported when a case statement + // doesn't return any value. + public void testBug573940_5() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(Number n) {\n" + + " int j = \n" + + " switch (n) {\n" + + " case Integer i -> {\n" + + " }\n" + + " default -> {\n" + + " yield 1;\n" + + " }\n" + + " };\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " }\n" + + " ^^\n" + + "A switch labeled block in a switch expression should not complete normally\n" + + "----------\n"); + } + public void testBug574564_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(new String(\"Hello\"));\n"+ + " }\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case var i -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case var i -> System.out.println(0);\n" + + " ^^^\n" + + "'var' is not allowed here\n" + + "----------\n"); + } + public void testBug574564_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(new String(\"Hello\"));\n"+ + " }\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case var i, var j, var k -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case var i, var j, var k -> System.out.println(0);\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " case var i, var j, var k -> System.out.println(0);\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " case var i, var j, var k -> System.out.println(0);\n" + + " ^^^^^\n" + + "A switch label may not have more than one pattern case label element\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " case var i, var j, var k -> System.out.println(0);\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n"); + } + public void testBug574564_003() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(10);\n"+ + " }\n"+ + " private static void foo(Integer o) {\n"+ + " switch (o) {\n"+ + " case var i, 10 -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case var i, 10 -> System.out.println(0);\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n"); + } + public void testBug574564_004() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(10);\n"+ + " }\n"+ + " private static void foo(Integer o) {\n"+ + " switch (o) {\n"+ + " case var i, 10, var k -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case var i, 10, var k -> System.out.println(0);\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " case var i, 10, var k -> System.out.println(0);\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " case var i, 10, var k -> System.out.println(0);\n" + + " ^^^^^\n" + + "A switch label may not have more than one pattern case label element\n" + + "----------\n"); + } + public void testBug574564_005() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(10);\n"+ + " }\n"+ + " private static void foo(Integer o) {\n"+ + " switch (o) {\n"+ + " case 10, null, var k -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case 10, null, var k -> System.out.println(0);\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n"); + } + public void testBug574564_006() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(10);\n"+ + " }\n"+ + " private static void foo(Integer o) {\n"+ + " switch (o) {\n"+ + " case default, var k -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case default, var k -> System.out.println(0);\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " case default, var k -> System.out.println(0);\n" + + " ^^^^^\n" + + "A switch label may not have both a pattern case label element and a default case label element\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " default -> System.out.println(o);\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"); + } + public void testBug574564_007() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(10);\n"+ + " }\n"+ + " private static void foo(Integer o) {\n"+ + " switch (o) {\n"+ + " case default, default, var k -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case default, default, var k -> System.out.println(0);\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " case default, default, var k -> System.out.println(0);\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " case default, default, var k -> System.out.println(0);\n" + + " ^^^^^\n" + + "A switch label may not have both a pattern case label element and a default case label element\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " default -> System.out.println(o);\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"); + } + public void testBug574564_008() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(10);\n"+ + " }\n"+ + " private static void foo(Integer o) {\n"+ + " switch (o) {\n"+ + " case default, 1, var k -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case default, 1, var k -> System.out.println(0);\n" + + " ^^^\n" + + "\'var\' is not allowed here\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " case default, 1, var k -> System.out.println(0);\n" + + " ^^^^^\n" + + "A switch label may not have both a pattern case label element and a default case label element\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " default -> System.out.println(o);\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"); + } + public void testBug574564_009() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case String s, default, Integer i -> System.out.println(0);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case String s, default, Integer i -> System.out.println(0);\n" + + " ^^^^^^^\n" + + "A switch label may not have both a pattern case label element and a default case label element\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " case String s, default, Integer i -> System.out.println(0);\n" + + " ^^^^^^^^^\n" + + "A switch label may not have more than one pattern case label element\n" + + "----------\n"); + } + public void testBug574564_010() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case String s, default, Integer i -> System.out.println(0);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case String s, default, Integer i -> System.out.println(0);\n" + + " ^\n" + + "Syntax error on token \"s\", delete this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " case String s, default, Integer i -> System.out.println(0);\n" + + " ^\n" + + "Syntax error on token \"i\", delete this token\n" + + "----------\n", + null, + true, + options); + } + public void testBug574564_011() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Integer o) {\n"+ + " switch (o) {\n"+ + " case null -> System.out.println(0);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case null -> System.out.println(0);\n" + + " ^^^^\n" + + "Pattern Matching in Switch is a preview feature and disabled by default. Use --enable-preview to enable\n" + + "----------\n", + null, + true, + options); + } + public void testBug574564_012() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Integer o) {\n"+ + " switch (o) {\n"+ + " case 1, default, null -> System.out.println(0);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case 1, default, null -> System.out.println(0);\n" + + " ^^^^^^^\n" + + "Pattern Matching in Switch is a preview feature and disabled by default. Use --enable-preview to enable\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " case 1, default, null -> System.out.println(0);\n" + + " ^^^^\n" + + "Pattern Matching in Switch is a preview feature and disabled by default. Use --enable-preview to enable\n" + + "----------\n", + null, + true, + options); + } + public void testBug574564_013() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case default, default -> System.out.println(0);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case default, default -> System.out.println(0);\n" + + " ^^^^^^^\n" + + "The default case is already defined\n" + + "----------\n"); + } + public void testBug574563_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {}\n"+ + " private static void foo1(Integer o) {\n"+ + " switch (o) {\n"+ + " case null, null -> System.out.println(o);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case null, null -> System.out.println(o);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n"); + } + public void testBug574563_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case null, Integer i -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug574563_003() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer i, null -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug574563_004() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case null, Integer i && i > 10 -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case null, Integer i && i > 10 -> System.out.println(0);\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "A null case label and patterns can co-exist only if the pattern is a type pattern\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug574563_005() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer i && i > 10, null -> System.out.println(0);\n"+ + " default -> System.out.println(o);\n"+ + " }\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case Integer i && i > 10, null -> System.out.println(0);\n" + + " ^^^^\n" + + "A null case label and patterns can co-exist only if the pattern is a type pattern\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug575030_01() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello World!\");\n"+ + " }\n"+ + "\n"+ + " private static void foo(String o) {\n"+ + " switch (o) {\n"+ + " case String s -> System.out.println(s);\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "Hello World!"); + } + public void testBug574614_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(Long.valueOf(10));\n"+ + " }\n"+ + " private static void foo(Object o) {\n"+ + " String s1 = \" Hello \";\n"+ + " String s2 = \"World!\";\n"+ + " switch (o) {\n"+ + " case Integer I && I > 10: break;\n"+ + " case X J: break;\n"+ + " case String s : break;\n"+ + " default:\n"+ + " s1 = new StringBuilder(String.valueOf(s1)).append(String.valueOf(s2)).toString();\n"+ + " System.out.println(s1);\n"+ + " break; \n"+ + " }\n"+ + " }\n"+ + "}", + }, + "Hello World!"); + } + public void testBug574614_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(Long.valueOf(0));\n"+ + " }\n"+ + " private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer I:\n"+ + " break;\n"+ + " case String s :\n"+ + " break;\n"+ + " case X J:\n"+ + " break;\n"+ + " default:\n"+ + " String s1 = \"Hello \";\n"+ + " String s2 = \"World!\";\n"+ + " s1 = s1 +s2; \n"+ + " System.out.println(s1);\n"+ + " break;\n"+ + " }\n"+ + " } \n"+ + "}", + }, + "Hello World!"); + } + public void testBug573921_1() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch(o) {\n" + + " case CharSequence cs ->\n" + + " System.out.println(\"A sequence of length \" + cs.length());\n" + + " case String s && s.length() > 0 -> \n" + + " System.out.println(\"A string: \" + s);\n" + + " default -> {\n" + + " break;\n" + + " } \n" + + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case String s && s.length() > 0 -> \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "This case label is dominated by one of the preceding case label\n" + + "----------\n"); + } + public void testBug573921_2() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static void foo(Object o) {\n"+ + " switch(o) {\n" + + " case CharSequence cs:\n" + + " System.out.println(\"A sequence of length \" + cs.length());\n" + + " break;\n" + + " case String s:\n" + + " System.out.println(\"A string: \" + s);\n" + + " break;\n" + + " default: \n" + + " break;\n" + + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " case String s:\n" + + " ^^^^^^^^\n" + + "This case label is dominated by one of the preceding case label\n" + + "----------\n"); + } + public void testBug573921_3() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello!\");\n"+ + " }\n"+ + " private static void foo(Object o) {\n"+ + " switch(o) {\n" + + " case String s:\n" + + " System.out.println(\"String:\" + s);\n" + + " break;\n" + + " case CharSequence cs:\n" + + " System.out.println(\"A CS:\" + cs);\n" + + " break;\n" + + " default: \n" + + " break;\n" + + " }\n"+ + " }\n"+ + "}", + }, + "String:Hello!"); + } + public void testBug573921_4() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(new StringBuffer(\"Hello!\"));\n"+ + " }\n"+ + " private static void foo(Object o) {\n"+ + " switch(o) {\n" + + " case String s:\n" + + " System.out.println(\"String:\" + s);\n" + + " break;\n" + + " case CharSequence cs:\n" + + " System.out.println(\"A CS:\" + cs.toString());\n" + + " break;\n" + + " default: \n" + + " break;\n" + + " }\n"+ + " }\n"+ + "}", + }, + "A CS:Hello!"); + } + public void testBug573921_5() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello\");\n"+ + " }\n"+ + " private static void foo(Object o) {\n"+ + " switch(o) {\n" + + " case String s && s.length() < 5 :\n" + + " System.out.println(\"1:\" + s);\n" + + " break;\n" + + " case String s && s.length() == 5:\n" + + " System.out.println(\"2:\" + s);\n" + + " break;\n" + + " default : System.out.println(\"Object\");\n" + + " }\n"+ + " }\n"+ + "}", + }, + "2:Hello"); + } + public void testBug573921_6() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"\");\n"+ + " }\n"+ + " private static void foo(Object o) {\n"+ + " switch(o) {\n" + + " case String s && s.length() < 5 :\n" + + " System.out.println(\"1:\" + s);\n" + + " break;\n" + + " case String s && s.length() == 5:\n" + + " System.out.println(\"2:\" + s);\n" + + " break;\n" + + " default : System.out.println(\"Object\");\n" + + " }\n"+ + " }\n"+ + "}", + }, + "1:"); + } + public void testBug573921_7() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n"+ + " @SuppressWarnings(\"rawtypes\")\n" + + " private static void foo(Object o) {\n"+ + " switch(o) {\n"+ + " case List cs:\n"+ + " System.out.println(\"A sequence of length \" + cs.size());\n"+ + " break;\n"+ + " case List s: \n"+ + " System.out.println(\"A string: \" + s);\n"+ + " break;\n"+ + " } "+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " switch(o) {\n" + + " ^\n" + + "An enhanced switch statement should be exhaustive; a default label expected\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " case List s: \n" + + " ^^^^^^^^^^^^^^\n" + + "Type Object cannot be safely cast to List\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " case List s: \n" + + " ^^^^^^^^^^^^^^\n" + + "This case label is dominated by one of the preceding case label\n" + + "----------\n"); + } + public void testBug573921_8() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n"+ + " @SuppressWarnings(\"rawtypes\")\n" + + " private static void foo(Object o) {\n"+ + " switch(o.hashCode()) {\n"+ + " case String s:\n"+ + " break;\n"+ + " default: \n"+ + " break;\n"+ + " } "+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case String s:\n" + + " ^^^^^^^^\n" + + "Type mismatch: cannot convert from int to String\n" + + "----------\n"); + } + public void testBug573921_9() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n"+ + " @SuppressWarnings(\"rawtypes\")\n" + + " private static void foo(Object o) {\n"+ + " switch(o) {\n"+ + " case Object o1:\n"+ + " break;\n"+ + " default: \n"+ + " break;\n"+ + " } "+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " default: \n" + + " ^^^^^^^\n" + + "Switch case cannot have both a total pattern and default label\n" + + "----------\n"); + } + public void testBug573921_10() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n"+ + " @SuppressWarnings(\"rawtypes\")\n" + + " private static void foo(List o) {\n"+ + " switch(o) {\n"+ + " case List o1:\n"+ + " break;\n"+ + " default: \n"+ + " break;\n"+ + " } "+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " default: \n" + + " ^^^^^^^\n" + + "Switch case cannot have both a total pattern and default label\n" + + "----------\n"); + } + public void testBug573921_11() { + runNegativeTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n"+ + " @SuppressWarnings(\"rawtypes\")\n" + + " private static void foo(String s) {\n"+ + " switch(s) {\n"+ + " case CharSequence cs:\n"+ + " break;\n"+ + " default: \n"+ + " break;\n"+ + " } "+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " default: \n" + + " ^^^^^^^\n" + + "Switch case cannot have both a total pattern and default label\n" + + "----------\n"); + } + public void testBug575049_001() { + runConformTest( + new String[] { + "X.java", + "sealed interface I permits A,B,C {}\n"+ + "final class A implements I {}\n"+ + "final class B implements I {}\n"+ + "record C(int j) implements I {} // Implicitly final\n"+ + "public class X {\n"+ + " static int testSealedCoverage(I i) {\n"+ + " return switch (i) {\n"+ + " case A a -> 0;\n"+ + " case B b -> 1;\n"+ + " case C c -> 2; // No default required!\n"+ + " default -> 3;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " A a = new A();\n"+ + " System.out.println(testSealedCoverage(a));\n"+ + " }\n"+ + "}", + }, + "0"); + } + public void testBug575049_002() { + runConformTest( + new String[] { + "X.java", + "sealed interface I permits A,B,C {}\n"+ + "final class A implements I {}\n"+ + "final class B implements I {}\n"+ + "record C(int j) implements I {} // Implicitly final\n"+ + "public class X {\n"+ + " static int testSealedCoverage(I i) {\n"+ + " return switch (i) {\n"+ + " case A a -> 0;\n"+ + " case B b -> 1;\n"+ + " case C c -> 2; // No default required!\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " A a = new A();\n"+ + " System.out.println(testSealedCoverage(a));\n"+ + " }\n"+ + "}", + }, + "0"); + } + public void testBug575049_003() { + runConformTest( + new String[] { + "X.java", + "sealed interface I permits A,B,C {}\n"+ + "final class A implements I {}\n"+ + "final class B implements I {}\n"+ + "record C(int j) implements I {} // Implicitly final\n"+ + "public class X {\n"+ + " static int testSealedCoverage(I i) {\n"+ + " return switch (i) {\n"+ + " case A a -> 0;\n"+ + " case B b -> 1;\n"+ + " default -> 2; // No default required!\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " A a = new A();\n"+ + " System.out.println(testSealedCoverage(a));\n"+ + " }\n"+ + "}", + }, + "0"); + } + public void testBug575049_004() { + runNegativeTest( + new String[] { + "X.java", + "sealed interface I permits A,B,C {}\n"+ + "final class A implements I {}\n"+ + "final class B implements I {}\n"+ + "record C(int j) implements I {} // Implicitly final\n"+ + "public class X {\n"+ + " static int testSealedCoverage(I i) {\n"+ + " return switch (i) {\n"+ + " case A a -> 0;\n"+ + " case B b -> 1;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " A a = new A();\n"+ + " System.out.println(testSealedCoverage(a));\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " return switch (i) {\n" + + " ^\n" + + "A switch expression should have a default case\n" + + "----------\n"); + } + public void testBug575048_01() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Integer i) {\n"+ + " return switch (i) {\n"+ + " default -> 2;\n"+ + " case Integer i1 -> 0;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(1));\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case Integer i1 -> 0;\n" + + " ^^^^^^^^^^^^^^^\n" + + "Switch case cannot have both a total pattern and default label\n" + + "----------\n"); + } + public void testBug575053_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(String o) {\n" + + " switch (o) {\n" + + " case String s && s.length() > 0 -> {}\n" + + " default -> {}\n" + + " } \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try{\n" + + " (new X()).foo(null);\n" + + " } catch(Exception e) {\n" + + " e.printStackTrace(System.out);\n" + + " }\n" + + " }\n"+ + "}", + }, + "java.lang.NullPointerException\n" + + " at java.base/java.util.Objects.requireNonNull(Objects.java:208)\n" + + " at X.foo(X.java:3)\n" + + " at X.main(X.java:10)"); + } + public void testBug575053_002() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Object o) {\n" + + " switch (o) {\n" + + " case String s -> {}\n" + + " default -> {}\n" + + " } \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try{\n" + + " (new X()).foo(null);\n" + + " } catch(Exception t) {\n" + + " t.printStackTrace();\n" + + " }\n" + + " }\n"+ + "}", + }, + "", + "java.lang.NullPointerException\n" + + " at java.base/java.util.Objects.requireNonNull(Objects.java:208)\n" + + " at X.foo(X.java:3)\n" + + " at X.main(X.java:10)"); + } + public void testBug575249_01() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(Object o) {\n" + + " return switch (o) {\n" + + " case (String s) : yield 0;\n" + + " default : yield 1;\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(\"Hello\"));\n" + + " }\n"+ + "}", + }, + "0"); + } + public void testBug575249_02() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(Object o) {\n" + + " return switch (o) {\n" + + " case (String s && s.length() < 10) : yield 0;\n" + + " default : yield 1;\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(\"Hello\"));\n" + + " }\n"+ + "}", + }, + "0"); + } + public void testBug575249_03() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(Object o) {\n" + + " return switch (o) {\n" + + " case (String s) -> 0;\n" + + " default -> 1;\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(\"Hello\"));\n" + + " }\n"+ + "}", + }, + "0"); + } + public void testBug575249_04() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(Object o) {\n" + + " return switch (o) {\n" + + " case (String s && s.length() < 10) -> 0;\n" + + " default -> 1;\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(\"Hello\"));\n" + + " }\n"+ + "}", + }, + "0"); + } + public void testBug575241_01() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Integer i) {\n"+ + " return switch (i) {\n"+ + " case Integer i1 -> 0;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(1));\n"+ + " }\n"+ + "}", + }, + "0"); + } + public void testBug575241_02() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Integer i) {\n"+ + " return switch (i) {\n"+ + " case Object o -> 0;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(1));\n"+ + " }\n"+ + "}", + }, + "0"); + } + public void testBug575241_03() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Object myVar) {\n"+ + " return switch (myVar) {\n"+ + " case null -> 0;\n"+ + " case Integer o -> 1;\n"+ + " case Object obj ->2;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(Integer.valueOf(0)));\n"+ + " System.out.println(foo(null));\n"+ + " }\n"+ + "}", + }, + "1\n" + + "0"); + } + public void testBug575241_04() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Object myVar) {\n"+ + " return switch (myVar) {\n"+ + " case Integer o -> 1;\n"+ + " case Object obj ->2;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(Integer.valueOf(0)));\n"+ + " System.out.println(foo(null));\n"+ + " }\n"+ + "}", + }, + "1\n" + + "2"); + } + public void testBug575241_05() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(Integer myVar) {\n"+ + " switch (myVar) {\n"+ + " case null -> System.out.println(100);\n"+ + " case Integer o -> System.out.println(o);\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(Integer.valueOf(0));\n"+ + " foo(null);\n"+ + " }\n"+ + "}", + }, + "0\n" + + "100"); + } + public void testBug575241_06() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(Integer myVar) {\n"+ + " switch (myVar) {\n"+ + " case Integer o -> System.out.println(o);\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(Integer.valueOf(0));\n"+ + " foo(null);\n"+ + " }\n"+ + "}", + }, + "0\n" + + "null"); + } + public void testBug575241_07() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(String myVar) {\n"+ + " switch (myVar) {\n"+ + " case null -> System.out.println(100);\n"+ + " case String o -> System.out.println(o);\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello\");\n"+ + " foo(null);\n"+ + " }\n"+ + "}", + }, + "Hello\n" + + "100"); + } + public void testBug575241_08() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(String myVar) {\n"+ + " switch (myVar) {\n"+ + " case String o -> System.out.println(o);\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello\");\n"+ + " foo(null);\n"+ + " }\n"+ + "}", + }, + "Hello\n" + + "null"); + } + public void testBug575356_01() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(Integer myVar) {\n"+ + " switch (myVar) {\n"+ + " case default -> System.out.println(\"hello\");\n"+ + " }; \n"+ + " } \n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " foo(Integer.valueOf(10)); \n"+ + " } \n"+ + "}", + }, + "hello"); + } + public void testBug575356_02() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(Integer myVar) {\n"+ + " switch (myVar) {\n"+ + " case null, default -> System.out.println(\"hello\");\n"+ + " }; \n"+ + " } \n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " foo(Integer.valueOf(10)); \n"+ + " } \n"+ + "}", + }, + "hello"); + } + public void testBug575356_03() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(Integer myVar) {\n"+ + " switch (myVar) {\n"+ + " case default, null -> System.out.println(\"hello\");\n"+ + " }; \n"+ + " } \n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " foo(Integer.valueOf(10)); \n"+ + " } \n"+ + "}", + }, + "hello"); + } + public void testBug575356_04() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + "private static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Integer i ->\n"+ + " System.out.println(\"Integer:\"+ i );\n"+ + " case default -> System.out.println(o.toString() );\n"+ + " }\n"+ + "}\n"+ + "\n"+ + " public static void main(String[] args) {\n"+ + " foo(Integer.valueOf(10)); \n"+ + " foo(new String(\"Hello\")); \n"+ + " } \n"+ + "}", + }, + "Integer:10\n" + + "Hello"); + } + public void testBug575052_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case String s -> System.out.println(s);\n"+ + " default -> System.out.println(0);\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello\");\n"+ + " }\n"+ + "}", + }, + "Hello"); + } + public void testBug575052_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(Object o) {\n"+ + " switch (o) {\n"+ + " case String s -> System.out.println(s);\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello\");\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " switch (o) {\n" + + " ^\n" + + "An enhanced switch statement should be exhaustive; a default label expected\n" + + "----------\n"); + } + public void testBug575052_003() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Object o) {\n"+ + " switch (o) {\n"+ + " case null -> System.out.println(0);\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello\");\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " switch (o) {\n" + + " ^\n" + + "An enhanced switch statement should be exhaustive; a default label expected\n" + + "----------\n"); + } + public void testBug575052_004() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " private static int foo(int i) {\n"+ + " switch (i) {\n"+ + " case 1:\n"+ + " break;\n"+ + " }\n"+ + " return 0;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(X.foo(0));\n"+ + " }\n"+ + "}", + }, + "0"); + } + public void testBug575050_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Object o) {\n"+ + " return switch (o) {\n"+ + " case String s -> 0;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello\");\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return switch (o) {\n" + + " ^\n" + + "A switch expression should have a default case\n" + + "----------\n"); + } + public void testBug575050_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Object o) {\n"+ + " return switch (o) {\n"+ + " case null -> 0;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " foo(\"Hello\");\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return switch (o) {\n" + + " ^\n" + + "A switch expression should have a default case\n" + + "----------\n"); + } + // From 14.11.1: A switch label that has a pattern case label element p that is + // total for the type of the selector expression of the enclosing + // switch statement or switch expression dominates a switch label that has + // a null case label element. + public void testBug575047_01() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Integer i) {\n"+ + " return switch (i) {\n"+ + " case Integer i1 -> 0;\n"+ + " case null -> 2;\n"+ + " };\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case null -> 2;\n" + + " ^^^^\n" + + "This case label is dominated by one of the preceding case label\n" + + "----------\n"); + } + // A switch label that has a pattern case label element p dominates another + // switch label that has a constant case label element c if either of the + // following is true: + // * the type of c is a primitive type and its wrapper class (5.1.7) is a subtype of the erasure of the type of p. + // * the type of c is a reference type and is a subtype of the erasure of the type of p. + public void testBug575047_02() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Integer i) {\n"+ + " return switch (i) {\n"+ + " case Integer i1 -> i1;\n"+ + " case 0 -> 0;\n"+ + " };\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case 0 -> 0;\n" + + " ^\n" + + "This case label is dominated by one of the preceding case label\n" + + "----------\n"); + } + public void testBug575047_03() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(Color c) {\n"+ + " switch (c) {\n" + + " case Color c1 : \n" + + " break;\n" + + " case Blue :\n" + + " break;\n" + + " }\n"+ + " }\n"+ + "enum Color { Blue, Red; }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case Blue :\n" + + " ^^^^\n" + + "This case label is dominated by one of the preceding case label\n" + + "----------\n"); + } + public void testBug575047_04() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Integer i) {\n"+ + " return switch (i) {\n"+ + " case null -> 2;\n"+ + " case Integer i1 -> 0;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(null));\n"+ + " System.out.println(foo(Integer.valueOf(0)));\n"+ + " }\n"+ + "}", + }, + "2\n" + + "0"); + } + public void testBug575047_05() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(float c) {\n"+ + " switch (c) {\n" + + " case 0 : \n" + + " break;\n" + + " default :\n" + + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case 0 : \n" + + " ^\n" + + "Type mismatch: cannot convert from int to float\n" + + "----------\n"); + } + public void testBug575047_06() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(String o) {\n"+ + " return switch (o) {\n" + + " case String s && s.length() > 0 -> 3;\n" + + " case String s1 -> 1;\n" + + " case String s -> -1;\n"+ + " };\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " case String s -> -1;\n" + + " ^^^^^^^^\n" + + "The switch statement cannot have more than one total pattern\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " case String s -> -1;\n" + + " ^^^^^^^^\n" + + "This case label is dominated by one of the preceding case label\n" + + "----------\n"); + } + // Test that when a literal is used as case constant + // we report type mismatch error against the literal's type and + // not on other types the case statement may have resolved too + public void testBug575047_07() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(Number i) {\n"+ + " switch (i) {\n"+ + " case Integer j, \"\":\n"+ + " System.out.println(0);\n"+ + " default:\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case Integer j, \"\":\n" + + " ^^\n" + + "Type mismatch: cannot convert from String to Number\n" + + "----------\n"); + } + public void testBug575047_08() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(Integer i) {\n"+ + " return switch (i) {\n"+ + " case 0 -> 0;\n"+ + " case Integer i1 -> i1;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(3));\n"+ + " System.out.println(foo(0));\n"+ + " }\n"+ + "}", + }, + "3\n"+ + "0"); + } + public void testBug575047_09() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static int foo(String i) {\n"+ + " return switch (i) {\n"+ + " case \"\" -> 0;\n"+ + " case String s -> -1;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(foo(\"\"));\n"+ + " System.out.println(foo(\"abc\"));\n"+ + " }\n"+ + "}", + }, + "0\n" + + "-1"); + } + public void testBug575047_10() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static String foo(Object o) {\n" + + " return switch (o) {\n" + + " case String i && i.length() == 0 -> \"empty\";\n" + + " case String i && i.length() > 0 -> \"zero+\";\n" + + " case Color s -> s.toString();\n" + + " default -> \"unknown\";\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(\"abc\"));\n" + + " System.out.println(foo(\"\"));\n" + + " System.out.println(Color.Blue);\n" + + " System.out.println(foo(args));\n" + + " }\n" + + "} \n" + + "enum Color {\n" + + " Blue, Red; \n" + + "}", + }, + "zero+\n" + + "empty\n" + + "Blue\n" + + "unknown"); + } + // Positive - Mix enum constants as well as suitable pattern var + public void testBug575047_11() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static String foo(Color o) {\n" + + " return switch (o) {\n" + + " case Red -> \"Red\";\n" + + " case Color s -> s.toString();\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Color.Red);\n" + + " System.out.println(Color.Blue);\n" + + " }\n" + + "} \n" + + "enum Color {\n" + + " Blue, Red; \n" + + "}", + }, + "Red\n" + + "Blue"); + } + public void testBug575047_12() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static String foo(Color o) {\n" + + " return switch (o) {\n" + + " case Red -> \"Red\";\n" + + " case Color s && s == Color.Blue -> s.toString();" + + " case Color s -> s.toString();\n" + + " };\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(Color.Red);\n" + + " System.out.println(Color.Blue);\n" + + " }\n" + + "} \n" + + "enum Color {\n" + + " Blue, Red; \n" + + "}", + }, + "Red\n" + + "Blue"); + } + public void testBug575047_13() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static String foo(Color o) {\n" + + " return switch (o) {\n" + + " case Color s && s == Color.Blue -> s.toString();" + + " case Red -> \"Red\";\n" + + " case null -> \"\";\n" + + " };\n" + + " }\n" + + "} \n" + + "enum Color {\n" + + " Blue, Red; \n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return switch (o) {\n" + + " ^\n" + + "A Switch expression should cover all possible values\n" + + "----------\n"); + } + public void testBug575047_14() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static String foo(Color o) {\n" + + " return switch (o) {\n" + + " case Color s && s == Color.Blue -> s.toString();" + + " case Red -> \"Red\";\n" + + " };\n" + + " }\n" + + "} \n" + + "enum Color {\n" + + " Blue, Red; \n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " return switch (o) {\n" + + " ^\n" + + "A Switch expression should cover all possible values\n" + + "----------\n"); + } + public void testBug575047_15() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static void foo(Integer o) {\n" + + " switch (o) {\n" + + " case 1: break;\n" + + " case Integer s && s == 2:\n" + + " System.out.println(s);break;\n" + + " case null, default:\n" + + " System.out.println(\"null/default\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " foo(null);\n" + + " }\n" + + "}", + }, + "null/default"); + } + public void testBug575360_001() { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo(String myVar) { // String\n"+ + " switch (myVar) {\n"+ + " case null, default : System.out.println(\"hello\");\n"+ + " }; \n"+ + " }\n"+ + " public static void main(String[] args) { \n"+ + " foo(new String(\"Hello\")); \n"+ + " }\n"+ + "}", + }, + "hello"); + } + public void testBug575055_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " public int foo(CharSequence c) {\n" + + " return switch (c) {\n" + + " case CharSequence c1 && (c instanceof String c1 && c1.length() > 0) -> 0;\n" + + " default -> 0;\n" + + " };\n" + + " }" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case CharSequence c1 && (c instanceof String c1 && c1.length() > 0) -> 0;\n" + + " ^^\n" + + "Duplicate local variable c1\n" + + "----------\n"); + } + // Fails with Javac as it prints Javac instead of throwing NPE + // https://bugs.openjdk.java.net/browse/JDK-8272776 + public void testBug575051_1() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Object o) {\n" + + " try{\n" + + " switch (o) {\n" + + " default:\n" + + " break;\n" + + " case String s :\n" + + " System.out.println(s);\n" + + " } \n" + + " } catch(Exception t) {\n" + + " t.printStackTrace(System.out);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " (new X()).foo(null);\n" + + " }\n" + + "}", + }, + "java.lang.NullPointerException\n" + + " at java.base/java.util.Objects.requireNonNull(Objects.java:208)\n" + + " at X.foo(X.java:4)\n" + + " at X.main(X.java:15)"); + } + // Test we don't report any illegal fall-through to null case + public void testBug575051_2() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Object o) {\n" + + " switch (o) {\n" + + " case String s :\n" + + " System.out.println(s);\n" + + " //$FALL-THROUGH$\n" + + " case null:\n" + + " break;\n" + + " default : \n" + + " break;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " (new X()).foo(null);\n" + + " }\n" + + "}", + }, + ""); + } + // Test we do report illegal fall-through to pattern + public void testBug575051_3() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Object o) {\n" + + " switch (o) {\n" + + " default : \n" + + " case String s :\n" + + " System.out.println();\n" + + " break;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " (new X()).foo(null);\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case String s :\n" + + " ^^^^^^^^^^^^^\n" + + "Illegal fall-through to a pattern\n" + + "----------\n", + ""); + } + public void testBug575571_1() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingDefaultCase, CompilerOptions.WARNING); + runWarningTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Color o) {\n" + + " switch (o) {\n" + + " case Blue:\n" + + " break;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {}\n" + + "}\n" + + "enum Color { Blue; }\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " switch (o) {\n" + + " ^\n" + + "The switch over the enum type Color should have a default case\n" + + "----------\n", + options); + } + public void testBug575571_2() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Color o) {\n" + + " switch (o) {\n" + + " case Blue:\n" + + " case Color c:\n" + + " break;\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {}\n" + + "}\n" + + "enum Color { Blue, Red; }\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case Color c:\n" + + " ^^^^^^^^^^^^\n" + + "Illegal fall-through to a pattern\n" + + "----------\n"); + } + public void testBug575714_01() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " static Object foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Object __ -> throw new AssertionError(); \n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n"); + } + public void testBug575714_02() { + runNegativeTest( + new String[] { + "X.java", + "class X {\n"+ + " static Object foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Object __ -> System.out.println(\"Hello\"); \n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo(new X());\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " static Object foo(Object o) {\n" + + " ^^^^^^^^^^^^^\n" + + "This method must return a result of type Object\n" + + "----------\n"); + } + public void testBug575714_03() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " static Object foo(Object o) {\n"+ + " switch (o) {\n"+ + " case Object __ -> System.out.println(\"Hello\"); \n"+ + " }\n"+ + " return null;\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " X.foo(new X());\n"+ + " }\n"+ + "}", + }, + "Hello"); + } + public void testBug575714_04() { + runConformTest( + new String[] { + "X.java", + "class X {\n"+ + " static Object foo(Object o) throws Exception {\n"+ + " switch (o) {\n"+ + " case Object __ -> throw new Exception(); \n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " try {\n"+ + " X.foo(new X());\n"+ + " } catch (Exception e) {\n"+ + " System.out.println(\"Hello\");\n"+ + " }\n"+ + " }\n"+ + "}", + }, + "Hello"); + } + public void testBug575687_1() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " static void number(Number i) {\n" + + " switch (i) {\n" + + " case Integer i2, 4.5:\n" + + " case 4.3: System.out.println();\n" + + " default: System.out.println(\"nothing\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {}\n" + + "}\n" + + "enum Color { Blue, Red; }\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case Integer i2, 4.5:\n" + + " ^^^\n" + + "Type mismatch: cannot convert from double to Number\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " case 4.3: System.out.println();\n" + + " ^^^\n" + + "Type mismatch: cannot convert from double to Number\n" + + "----------\n"); + } + public void testBug575686_1() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void m(Object o) {\n" + + " switch (o) {\n" + + " case Integer i1, String s1 ->\n" + + " System.out.print(s1);\n" + + " default -> System.out.print(\"default\");\n" + + " case Number n, null ->\n" + + " System.out.print(o);\n" + + " case null, Class c ->\n" + + " System.out.print(o);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {}\n" + + "}\n" + + "enum Color { Blue, Red; }\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case Integer i1, String s1 ->\n" + + " ^^^^^^^^^\n" + + "A switch label may not have more than one pattern case label element\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " case Number n, null ->\n" + + " ^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " case null, Class c ->\n" + + " ^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " case null, Class c ->\n" + + " ^^^^^\n" + + "Class is a raw type. References to generic type Class should be parameterized\n" + + "----------\n"); + } + public void testBug575737_001() { + Map options =getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.WARNING); + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo1(String o) {\n"+ + " switch (o) {\n"+ + " case null -> System.out.println(\"null\");\n"+ + " case String s -> String.format(\"String %s\", s);\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " case null -> System.out.println(\"null\");\n" + + " ^^^^\n" + + "You are using a preview language feature that may or may not be supported in a future release\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " case String s -> String.format(\"String %s\", s);\n" + + " ^^^^^^^^\n" + + "You are using a preview language feature that may or may not be supported in a future release\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug575737_002() { + Map options =getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.INFO); + + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n"+ + " static void foo1(String o) {\n"+ + " switch (o) {\n"+ + " case null -> System.out.println(\"null\");\n"+ + " case String s -> String.format(\"String %s\", s);\n"+ + " }\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " Zork();\n"+ + " }\n"+ + "}", + }, + "----------\n" + + "1. INFO in X.java (at line 4)\n" + + " case null -> System.out.println(\"null\");\n" + + " ^^^^\n" + + "You are using a preview language feature that may or may not be supported in a future release\n" + + "----------\n" + + "2. INFO in X.java (at line 5)\n" + + " case String s -> String.format(\"String %s\", s);\n" + + " ^^^^^^^^\n" + + "You are using a preview language feature that may or may not be supported in a future release\n" + + "----------\n" + + "3. ERROR in X.java (at line 9)\n" + + " Zork();\n" + + " ^^^^\n" + + "The method Zork() is undefined for the type X\n" + + "----------\n", + null, + true, + options + ); + } + public void testBug575738_001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static void foo(Object o) {\n" + + " switch (o.hashCode()) {\n" + + " case int t: System.out.println(\"Integer\"); \n" + + " default : System.out.println(\"Object\"); \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " foo(\"Hello World\");\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case int t: System.out.println(\"Integer\"); \n" + + " ^^^^^\n" + + "Unexpected type int, expected class or array type\n" + + "----------\n"); + } + public void testBug575738_002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " private static void foo(Object o) {\n" + + " switch (o.hashCode()) {\n" + + " case Integer t: System.out.println(\"Integer\"); \n" + + " default : System.out.println(\"Object\"); \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) { \n" + + " foo(\"Hello World\");\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " case Integer t: System.out.println(\"Integer\"); \n" + + " ^^^^^^^^^\n" + + "Type mismatch: cannot convert from int to Integer\n" + + "----------\n"); + } + + public void testBug576075_001() throws Exception { + runConformTest( + new String[] { + "p/Rec.java", + "package p;\n"+ + "import p.Rec.MyInterface.MyClass1;\n"+ + "import p.Rec.MyInterface.MyClass2;\n"+ + "public record Rec(MyInterface c) {\n"+ + " public static sealed interface MyInterface permits MyClass1, MyClass2 {\n"+ + " public static final class MyClass1 implements MyInterface { }\n"+ + " public static final class MyClass2 implements MyInterface { }\n"+ + " }\n"+ + " public boolean bla() {\n"+ + " return switch (c) {\n"+ + " case MyClass1 mc1 -> true;\n"+ + " case MyClass2 mc2 -> false;\n"+ + " };\n"+ + " }\n"+ + " public static void main(String[] args) {\n"+ + " new Rec(new MyClass1()).hashCode();\n"+ + " System.out.println(\"works\");\n"+ + " }\n"+ + "}\n" + }, + "works"); + String expectedOutput = + "Bootstrap methods:\n" + + " 0 : # 93 invokestatic java/lang/runtime/SwitchBootstraps.typeSwitch:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;[Ljava/lang/Object;)Ljava/lang/invoke/CallSite;\n" + + " Method arguments:\n" + + " #32 p/Rec$MyInterface$MyClass1\n" + + " #34 p/Rec$MyInterface$MyClass2,\n" + + " 1 : # 100 invokestatic java/lang/runtime/ObjectMethods.bootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/TypeDescriptor;Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/invoke/MethodHandle;)Ljava/lang/Object;\n" + + " Method arguments:\n" + + " #1 p/Rec\n" + + " #101 c\n" + + " #102 REF_getField c:Lp/Rec$MyInterface;"; + SwitchPatternTest.verifyClassFile(expectedOutput, "p/Rec.class", ClassFileBytesDisassembler.SYSTEM); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java new file mode 100644 index 0000000000..c90cfeacd8 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java @@ -0,0 +1,3193 @@ +/******************************************************************************* + * Copyright (c) 2005, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 374605 - Unreasonable warning for enum-based switch statements + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +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; +import org.eclipse.jdt.internal.compiler.ASTVisitor; +import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; +import org.eclipse.jdt.internal.compiler.lookup.BlockScope; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class SwitchTest extends AbstractRegressionTest { + + private static final long JDKLevelSupportingStringSwitch = ClassFileConstants.JDK1_7; + +static { +// TESTS_NUMBERS = new int[] { 22 }; +// TESTS_NAMES = new String[] { "testFor356002", "testFor356002_2", "testFor356002_3" }; +} +public SwitchTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +public void test001() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " }\n" + + " public static void foo() {\n" + + " try {\n" + + " switch(0) {\n" + + " case 0 :\n" + + " case 1 - (1 << 31) :\n" + + " case (1 << 30) :\n" + + " }\n" + + " } catch (OutOfMemoryError e) {\n" + + " }\n" + + " }\n" + + "}\n", + }); +} +public void test002() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " int k;\n" + + " public void foo() {\n" + + " int c;\n" + + " switch (k) {\n" + + " default :\n" + + " c = 2;\n" + + " break;\n" + + " case 2 :\n" + + " c = 3;\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }); +} + +public void test003() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " int i = 0;\n" + + " void foo() {\n" + + " switch (i) {\n" + + " case 1 :\n" + + " {\n" + + " int j;\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }); +} + +public void test004() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static int foo() {\n" + + " int i = 0, j;\n" + + " switch (i) {\n" + + " default :\n" + + " int k = 2;\n" + + " j = k;\n" + + " }\n" + + " if (j != -2) {\n" + + " return 1;\n" + + " }\n" + + " return 0;\n" + + " }\n" + + "}\n", + }); +} + +public void test005() { + this.runConformTest(new String[] { + "p/BugJavaCase.java", + "package p;\n" + + "class BugJavaCase {\n" + + " public static final int BC_ZERO_ARG = 1;\n" + + " public void test01(int i) {\n" + + " switch (i) {\n" + + " case BC_ZERO_ARG :\n" + + " System.out.println(\"i = \" + i);\n" + + " break;\n" + + " }\n" + + " }\n" + + "}\n", + }); +} + + +public void test006() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " foo(); \n" + + " } \n" + + " \n" + + " public static void foo() { \n" + + " char x = 5;\n" + + " final short b = 5;\n" + + " int a;\n" + + " \n" + + " switch (x) {\n" + + " case b: // compile time error\n" + + " a = 0;\n" + + " break; \n" + + " default:\n" + + " a=1;\n" + + " }\n" + + " \n" + + " }\n" + + "}\n", + }); +} + +public void test007() { + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "class X {\n" + + " void v() {\n" + + " switch (1) {\n" + + " case (int) (1.0 / 0.0) :\n" + + " break;\n" + + " case (int) (2.0 / 0.0) :\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 5)\n" + + " case (int) (1.0 / 0.0) :\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + + "2. ERROR in p\\X.java (at line 7)\n" + + " case (int) (2.0 / 0.0) :\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Duplicate case\n" + + "----------\n" + ); +} +public void test008() { + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " switch(args.length){\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +public void test009() { + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " switch (81391861) {\n" + + " case (81391861) :\n" + + " System.out.println(\"SUCCESS\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "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 variables 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 variables 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" + + " \n" + + " void foo(){\n" + + " switch(this){\n" + + " case 0 : \n" + + " Zork z;\n" + + " }\n" + + " }\n" + + " \n" + + " void bar(){\n" + + " switch(x){\n" + + " case 0 : \n" + + " Zork z;\n" + + " }\n" + + " } \n" + + "}\n", + }, + this.complianceLevel >= JDKLevelSupportingStringSwitch ? newMessage : oldMessage); + +} +public void test011() { + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String args[]) {\n" + + " switch (args.length) {\n" + + " case 1 :\n" + + " System.out.println();\n" + + " case 3 :\n" + + " break;\n" + + " default :\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=86813 +public void test012() throws Exception { + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " boolean x= true;\n" + + " try {\n" + + " int i= 1;\n" + + " switch (i) { // <-- breakpoint here\n" + + " case 1:\n" + + " break; //step 1 \n" + + " case 2:\n" + + " x = false; //step 2 \n" + + " break;\n" + + " }\n" + + " }catch(Exception e) {\n" + + " }\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 iconst_1\n" + + " 1 istore_1 [x]\n" + + " 2 iconst_1\n" + + " 3 istore_2 [i]\n" + + " 4 iload_2 [i]\n" + + " 5 tableswitch default: 33\n" + + " case 1: 28\n" + + " case 2: 31\n" + + " 28 goto 37\n" + + " 31 iconst_0\n" + + " 32 istore_1 [x]\n" + + " 33 goto 37\n" + + " 36 astore_2\n" + + " 37 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 40 ldc [22]\n" + + " 42 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 45 return\n" + + " Exception Table:\n" + + " [pc: 2, pc: 33] -> 36 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 4, line: 6]\n" + + " [pc: 28, line: 8]\n" + + " [pc: 31, line: 10]\n" + + " [pc: 33, line: 13]\n" + + " [pc: 37, line: 15]\n" + + " [pc: 45, line: 16]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 46] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 46] local: x index: 1 type: boolean\n" + + " [pc: 4, pc: 33] local: i index: 2 type: int\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test013() throws Exception { + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " X x;\n" + + " Object o = null;\n" + + " for (int i = 0; i < 10; i++) {\n" + + " if (i < 90) {\n" + + " x = new X();\n" + + " if (i > 4) {\n" + + " o = new Object();\n" + + " } else {\n" + + " o = null;\n" + + " }\n" + + " switch (2) {\n" + + " case 0:\n" + + " if (o instanceof String) {\n" + + " System.out.print(\"1\");\n" + + " return;\n" + + " } else {\n" + + " break;\n" + + " }\n" + + " default: {\n" + + " Object diff = o;\n" + + " if (diff != null) {\n" + + " System.out.print(\"2\");\n" + + " }\n" + + " break;\n" + + " }\n" + + " }\n" + + " System.out.print(\"3\"); \n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "333332323232323"); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6 + ? " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 5\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 aconst_null\n" + + " 1 astore_2 [o]\n" + + " 2 iconst_0\n" + + " 3 istore_3 [i]\n" + + " 4 goto 103\n" + + " 7 iload_3 [i]\n" + + " 8 bipush 90\n" + + " 10 if_icmpge 100\n" + + " 13 new X [1]\n" + + " 16 dup\n" + + " 17 invokespecial X() [16]\n" + + " 20 astore_1 [x]\n" + + " 21 iload_3 [i]\n" + + " 22 iconst_4\n" + + " 23 if_icmple 37\n" + + " 26 new java.lang.Object [3]\n" + + " 29 dup\n" + + " 30 invokespecial java.lang.Object() [8]\n" + + " 33 astore_2 [o]\n" + + " 34 goto 39\n" + + " 37 aconst_null\n" + + " 38 astore_2 [o]\n" + + " 39 iconst_2\n" + + " 40 tableswitch default: 76\n" + + " case 0: 60\n" + + " 60 aload_2 [o]\n" + + " 61 instanceof java.lang.String [17]\n" + + " 64 ifeq 92\n" + + " 67 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 70 ldc [25]\n" + + " 72 invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + + " 75 return\n" + + " 76 aload_2 [o]\n" + + " 77 astore 4 [diff]\n" + + " 79 aload 4 [diff]\n" + + " 81 ifnull 92\n" + + " 84 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 87 ldc [33]\n" + + " 89 invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + + " 92 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 95 ldc [35]\n" + + " 97 invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + + " 100 iinc 3 1 [i]\n" + + " 103 iload_3 [i]\n" + + " 104 bipush 10\n" + + " 106 if_icmplt 7\n" + + " 109 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 2, line: 6]\n" + + " [pc: 7, line: 7]\n" + + " [pc: 13, line: 8]\n" + + " [pc: 21, line: 9]\n" + + " [pc: 26, line: 10]\n" + + " [pc: 34, line: 11]\n" + + " [pc: 37, line: 12]\n" + + " [pc: 39, line: 14]\n" + + " [pc: 60, line: 16]\n" + + " [pc: 67, line: 17]\n" + + " [pc: 75, line: 18]\n" + + " [pc: 76, line: 23]\n" + + " [pc: 79, line: 24]\n" + + " [pc: 84, line: 25]\n" + + " [pc: 92, line: 30]\n" + + " [pc: 100, line: 6]\n" + + " [pc: 109, line: 33]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 110] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 21, pc: 100] local: x index: 1 type: X\n" + + " [pc: 2, pc: 110] local: o index: 2 type: java.lang.Object\n" + + " [pc: 4, pc: 109] local: i index: 3 type: int\n" + + " [pc: 79, pc: 92] local: diff index: 4 type: java.lang.Object\n" + : + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 5\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 aconst_null\n" + + " 1 astore_2 [o]\n" + + " 2 iconst_0\n" + + " 3 istore_3 [i]\n" + + " 4 goto 103\n" + + " 7 iload_3 [i]\n" + + " 8 bipush 90\n" + + " 10 if_icmpge 100\n" + + " 13 new X [1]\n" + + " 16 dup\n" + + " 17 invokespecial X() [16]\n" + + " 20 astore_1 [x]\n" + + " 21 iload_3 [i]\n" + + " 22 iconst_4\n" + + " 23 if_icmple 37\n" + + " 26 new java.lang.Object [3]\n" + + " 29 dup\n" + + " 30 invokespecial java.lang.Object() [8]\n" + + " 33 astore_2 [o]\n" + + " 34 goto 39\n" + + " 37 aconst_null\n" + + " 38 astore_2 [o]\n" + + " 39 iconst_2\n" + + " 40 tableswitch default: 76\n" + + " case 0: 60\n" + + " 60 aload_2 [o]\n" + + " 61 instanceof java.lang.String [17]\n" + + " 64 ifeq 92\n" + + " 67 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 70 ldc [25]\n" + + " 72 invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + + " 75 return\n" + + " 76 aload_2 [o]\n" + + " 77 astore 4 [diff]\n" + + " 79 aload 4 [diff]\n" + + " 81 ifnull 92\n" + + " 84 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 87 ldc [33]\n" + + " 89 invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + + " 92 getstatic java.lang.System.out : java.io.PrintStream [19]\n" + + " 95 ldc [35]\n" + + " 97 invokevirtual java.io.PrintStream.print(java.lang.String) : void [27]\n" + + " 100 iinc 3 1 [i]\n" + + " 103 iload_3 [i]\n" + + " 104 bipush 10\n" + + " 106 if_icmplt 7\n" + + " 109 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 2, line: 6]\n" + + " [pc: 7, line: 7]\n" + + " [pc: 13, line: 8]\n" + + " [pc: 21, line: 9]\n" + + " [pc: 26, line: 10]\n" + + " [pc: 34, line: 11]\n" + + " [pc: 37, line: 12]\n" + + " [pc: 39, line: 14]\n" + + " [pc: 60, line: 16]\n" + + " [pc: 67, line: 17]\n" + + " [pc: 75, line: 18]\n" + + " [pc: 76, line: 23]\n" + + " [pc: 79, line: 24]\n" + + " [pc: 84, line: 25]\n" + + " [pc: 92, line: 30]\n" + + " [pc: 100, line: 6]\n" + + " [pc: 109, line: 33]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 110] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 21, pc: 100] local: x index: 1 type: X\n" + + " [pc: 2, pc: 110] local: o index: 2 type: java.lang.Object\n" + + " [pc: 4, pc: 109] local: i index: 3 type: int\n" + + " [pc: 79, pc: 92] local: diff index: 4 type: java.lang.Object\n" + + " Stack map table: number of frames 8\n" + + " [pc: 7, full, stack: {}, locals: {java.lang.String[], _, java.lang.Object, int}]\n" + + " [pc: 37, full, stack: {}, locals: {java.lang.String[], X, java.lang.Object, int}]\n" + + " [pc: 39, same]\n" + + " [pc: 60, same]\n" + + " [pc: 76, same]\n" + + " [pc: 92, same]\n" + + " [pc: 100, full, stack: {}, locals: {java.lang.String[], _, java.lang.Object, int}]\n" + + " [pc: 103, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=245257 +public void test014() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " void foo1(int i) {\n" + + " switch (i) {\n" + + " case 0://OK\n" + + " case 1://OK\n" + + " System.out.println();\n" + + " //$FALL-THROUGH$\n" + + " case 2://OK\n" + + " System.out.println(); //$FALL-THROUGH$\n" + + " case 3://OK\n" + + " System.out.println();\n" + + " //$FALL-THROUGH$ - some allowed explanation\n" + + " case 4://OK\n" + + " case 5://OK\n" + + " System.out.println();\n" + + " //$FALL-THROUGH$ - not last comment, thus inoperant\n" + + " // last comment is not fall-through explanation\n" + + " case 6://WRONG\n" + + " //$FALL-THROUGH$ - useless since not leading the case\n" + + " System.out.println();\n" + + " /*$FALL-THROUGH$ - block comment, is also allowed */\n" + + " case 7://OK\n" + + " System.out.println(\"aa\"); //$NON-NLS-1$\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " case 6://WRONG\n" + + " ^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=245257 - variation +public void test015() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " void foo1(int i) {\n" + + " switch (i) {\n" + + " case 0://OK\n" + + " case 1://OK\n" + + " System.out.println();\n" + + " // $FALL-THROUGH$\n" + + " case 2://OK\n" + + " System.out.println(); // $FALL-THROUGH$\n" + + " case 3://OK\n" + + " System.out.println();\n" + + " // $FALL-THROUGH$ - some allowed explanation\n" + + " case 4://OK\n" + + " case 5://OK\n" + + " System.out.println();\n" + + " // $FALL-THROUGH$ - not last comment, thus inoperant\n" + + " // last comment is not fall-through explanation\n" + + " case 6://WRONG\n" + + " // $FALL-THROUGH$ - useless since not leading the case\n" + + " System.out.println();\n" + + " /* $FALL-THROUGH$ - block comment, is also allowed */\n" + + " case 7://OK\n" + + " System.out.println(\"aa\"); //$NON-NLS-1$\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 18)\n" + + " case 6://WRONG\n" + + " ^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=245257 - variation +public void test016() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " void foo1(int i) {\n" + + " switch (i) {\n" + + " case 0://OK\n" + + " case 1://OK\n" + + " System.out.println();\n" + + " // $FALL-THROUGH - missing trailing $ in tag\n" + + " case 2://WRONG\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\n" + + " case 2://WRONG\n" + + " ^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=245257 - variation +public void test017() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " void foo1(char previousChar) {\n" + + " switch(previousChar) {\n" + + " case \'/\':\n" + + " if (previousChar == \'*\') {\n" + + " // End of javadoc\n" + + " break;\n" + + " //$FALL-THROUGH$ into default case\n" + + " }\n" + + " default :\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " default :\n" + + " ^^^^^^^\n" + + "Switch case may be entered by falling through previous case. If intended, add a new comment //$FALL-THROUGH$ on the line above\n" + + "----------\n", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=286682 +public void test018() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void foo(int i) { \n" + + " switch (i) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + new ASTVisitor() { + public boolean visit(SingleNameReference reference, BlockScope scope) { + assertNotNull("No scope", scope); + return true; + } + } + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=314830 +public void test019() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " switch((Integer) null) {};\n" + + " System.out.println(\"FAILED\");\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=314830 +public void test020() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " switch(foo()) {};\n" + + " System.out.println(\"FAILED\");\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }" + + " static Integer foo() {\n" + + " return (Integer) null;\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=314830 +public void test021() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " switch((Character) null) {\n" + + " default: System.out.println(\"FAILED\");\n" + + " }\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=314830 +public void test022() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.math.RoundingMode mode = null;\n" + + " try {\n" + + " switch (mode) {}\n" + + " System.out.println(\"FAILED\");\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=314830 +public void test023() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + this.runConformTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " java.math.RoundingMode mode = java.math.RoundingMode.FLOOR;\n" + + " try {\n" + + " switch (mode) {\n" + + " default: System.out.println(\"SUCCESS\");\n" + + " }\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "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 variables 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 variables 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 variables 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 (Integer.valueOf(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 variables 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 variables 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 variables 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 variables 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 variables 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 variables 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 variables 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" + + " outer: 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" + + " break outer;\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 variables 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" + + " outer: 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" + + " break outer;\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 variables 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 variables 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 variables 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 variables 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 variables 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 variables 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 variables 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" + + " outer: 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" + + " break outer;\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 variables 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" + + " outer: 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" + + " break outer;\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 variables 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 variables 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" + + " break junk;\n" + + " }\n" + + " }\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 variables 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 variables 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 variables 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 variables 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 variables 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 variables 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 void testFor356002() { + String errorMsg = + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " switch (foo()) {\n" + + " ^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " private static String foo() {\n" + + " return \"\";\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " switch (foo()) {\n" + + " default: {\n" + + " int j = 0;\n" + + " if (j <= 0)\n" + + " System.out.println(\"DONE\");\n" + + " }\n" + + " return;\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "DONE"); + } +} +public void testFor356002_2() { + String errorMsg = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " switch (\"\") {\n" + + " ^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " switch (\"\") {\n" + + " default: {\n" + + " int j = 0;\n" + + " if (j <= 0)\n" + + " System.out.println(\"DONE\");\n" + + " }\n" + + " return;\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "DONE"); + } +} +public void testFor356002_3() { + String errorMsg = + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " switch (foo()) {\n" + + " ^^^^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " private static String foo() {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " switch (foo()) {\n" + + " default: {\n" + + " int j = 0;\n" + + " if (j <= 0)\n" + + " ;\n" + + " }\n" + + " return;\n" + + " }\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"DONE\");\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, "DONE"); + } +} +public void testBug374605() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE, JavaCore.WARNING); + this.runNegativeTest( + new String[] { + "p/X.java", + "package p;\n" + + "class X {\n" + + " void v(int i) {\n" + + " switch (i) {\n" + + " case 1 :\n" + + " break;\n" + + " case 2 :\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in p\\X.java (at line 4)\n" + + " switch (i) {\n" + + " ^\n" + + "The switch statement should have a default case\n" + + "----------\n", + null, + true, + options + ); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380927 +public void testBug380927() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public final static Object f() {\n" + + " final Object a = null;\n" + + " Object b;\n" + + " label: do {\n" + + " switch (0) {\n" + + " case 1: {\n" + + " b = a;\n" + + " }\n" + + " break;\n" + + " default:\n" + + " break label;\n" + + " }\n" + + " } while (true);\n" + + " return a;\n" + + " }\n" + + " public static void main(final String[] args) {\n" + + " f();\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + "}\n", + }, + "Success"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380927 +public void testBug380927a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public final static Object f() {\n" + + " final Object a = null;\n" + + " Object b;\n" + + " label: while (true) {\n" + + " switch (0) {\n" + + " case 1: {\n" + + " b = a;\n" + + " }\n" + + " break;\n" + + " default:\n" + + " break label;\n" + + " }\n" + + " }\n" + + " return a;\n" + + " }\n" + + " public static void main(final String[] args) {\n" + + " f();\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + "}\n", + }, + "Success"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380927 +public void testBug380927b() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public final static Object f() {\n" + + " final Object a = null;\n" + + " Object b;\n" + + " label: for(;;) {\n" + + " switch (0) {\n" + + " case 1: {\n" + + " b = a;\n" + + " }\n" + + " break;\n" + + " default:\n" + + " break label;\n" + + " }\n" + + " }\n" + + " return a;\n" + + " }\n" + + " public static void main(final String[] args) {\n" + + " f();\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + "}\n", + }, + "Success"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380927 +public void testBug380927c() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public final static Object f() {\n" + + " final Object a = null;\n" + + " Object b;\n" + + " label: for(int i : new int [] { 10 }) {\n" + + " switch (0) {\n" + + " case 1: {\n" + + " b = a;\n" + + " }\n" + + " break;\n" + + " default:\n" + + " break label;\n" + + " }\n" + + " }\n" + + " return a;\n" + + " }\n" + + " public static void main(final String[] args) {\n" + + " f();\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + "}\n", + }, + "Success"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380927 +public void testBug380927d() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " Object b;\n" + + " label: do {\n" + + " switch (0) {\n" + + " case 1:\n" + + " b = null;\n" + + " break;\n" + + " default:\n" + + " break label;\n" + + " }\n" + + " } while (true);\n" + + " System.out.println(b);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " System.out.println(b);\n" + + " ^\n" + + "The local variable b may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380927 +public void testBug380927e() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " Object b;\n" + + " label: while (true) {\n" + + " switch (0) {\n" + + " case 1:\n" + + " b = null;\n" + + " break;\n" + + " default:\n" + + " break label;\n" + + " }\n" + + " }\n" + + " System.out.println(b);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " System.out.println(b);\n" + + " ^\n" + + "The local variable b may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380927 +public void testBug380927f() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " Object b;\n" + + " label: for(;;) {\n" + + " switch (0) {\n" + + " case 1:\n" + + " b = null;\n" + + " break;\n" + + " default:\n" + + " break label;\n" + + " }\n" + + " }\n" + + " System.out.println(b);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " System.out.println(b);\n" + + " ^\n" + + "The local variable b may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=380927 +public void testBug380927g() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " Object b;\n" + + " label: for(int i : new int [] { 10 }) {\n" + + " switch (0) {\n" + + " case 1:\n" + + " b = null;\n" + + " break;\n" + + " default:\n" + + " break label;\n" + + " }\n" + + " }\n" + + " System.out.println(b);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " System.out.println(b);\n" + + " ^\n" + + "The local variable b may not have been initialized\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383629 +// To check that code gen is ok +public void testBug383629() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " char chc; \n" + + " do { \n" + + " if (args == null) { \n" + + " switch ('a') { \n" + + " case '\\n': \n" + + " chc = 'b';\n" + + " } \n" + + " } else { \n" + + " switch ('a') { \n" + + " case '\\r':\n" + + " } \n" + + " }\n" + + " } while (false);\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}", + }); // custom requestor + + String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_6 ? + " Local variable table:\n" + + " [pc: 0, pc: 61] local: args index: 0 type: java.lang.String[]\n": + " Local variable table:\n" + + " [pc: 0, pc: 61] local: args index: 0 type: java.lang.String[]\n" + + " Stack map table: number of frames 4\n" + + " [pc: 24, same]\n" + + " [pc: 27, same]\n" + + " [pc: 30, same]\n" + + " [pc: 52, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=381172 +// To check that code gen is ok +public void testBug381172() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args){\n" + + " System.out.println(\"Test\");\n" + + " }\n" + + " public void method() {\n" + + " try {\n" + + " int rc;\n" + + " switch ( 0 )\n" + + " {\n" + + " case 0:\n" + + " rc = 0;\n" + + " setRC( rc );\n" + + " break;\n" + + " case 1:\n" + + " rc = 1;\n" + + " setRC( 0 );\n" + + " break;\n" + + " case 2:\n" + + " rc = 2;\n" + + " setRC( 0 );\n" + + " break;\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + " catch ( final Exception ex ) {}\n" + + " }\n" + + " private void setRC(int rc) {}\n" + + "}", + }); // custom requestor + + String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_6 ? + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: rc index: 1 type: int\n": + " Local variable table:\n" + + " [pc: 0, pc: 63] local: this index: 0 type: X\n" + + " [pc: 30, pc: 38] local: rc index: 1 type: int\n" + + " [pc: 40, pc: 48] local: rc index: 1 type: int\n" + + " [pc: 50, pc: 58] local: rc index: 1 type: int\n" + + " Stack map table: number of frames 6\n" + + " [pc: 28, same]\n" + + " [pc: 38, same]\n" + + " [pc: 48, same]\n" + + " [pc: 58, same]\n" + + " [pc: 61, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 62, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=383643, NPE in problem reporter. +public void test383643() { + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_SWITCH_MISSING_DEFAULT_CASE, JavaCore.WARNING); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " String s;\n" + + " switch (p) {\n" + + " case ONE:\n" + + " s= \"1\";\n" + + " break;\n" + + " case TWO:\n" + + " s= \"2\";\n" + + " break;\n" + + " }\n" + + "\n" + + " s.toString();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " switch (p) {\n" + + " ^\n" + + "p cannot be resolved to a variable\n" + + "----------\n" + + "2. WARNING in X.java (at line 4)\n" + + " switch (p) {\n" + + " ^\n" + + "The switch statement should have a default case\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " case ONE:\n" + + " ^^^\n" + + "ONE cannot be resolved to a variable\n" + + "----------\n" + + "4. ERROR in X.java (at line 8)\n" + + " case TWO:\n" + + " ^^^\n" + + "TWO cannot be resolved to a variable\n" + + "----------\n", + null, + true, + options + ); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=387146 - the fall-through comment is ignored +public void test387146a() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " private Object someLock;\n" + + " public void foo1(int i) {\n" + + " switch (i) {\n" + + " case 1:\n" + + " synchronized (someLock) {\n" + + " System.out.println();\n" + + " }\n" + + " //$FALL-THROUGH$\n" + + " case 2:\n" + + " System.out.println();\n" + + " break;\n" + + " default:\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, + true, + options); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=387146 - the fall-through comment is respected +public void test387146b() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportFallthroughCase, CompilerOptions.ERROR); + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " private boolean someFlag;\n" + + " public void foo1(int i) {\n" + + " switch (i) {\n" + + " case 1:\n" + + " if (someFlag) {\n" + + " System.out.println();\n" + + " }\n" + + " //$FALL-THROUGH$\n" + + " case 2:\n" + + " System.out.println();\n" + + " break;\n" + + " default:\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, + true, + options); +} +//JDK7: Strings in Switch. +public void test393537() { + String errorMsg = + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " switch (\"\") {\n" + + " ^^\n" + + "Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " switch (\"\") {\n" + + " case \"\":\n" + + " default:\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + this.runConformTest(sourceFiles, ""); + } +} +//JDK7: Strings in Switch. +public void test410892() { + String errorMsg = + "----------\n" + + "1. ERROR in X.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 variables are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " public void testFunction(String s) {\n" + + " int var1 = 0;\n" + + " int var2 = 0;\n" + + " switch (s) {\n" + + " case \"test\": \n" + + " var2 = ++var1 % 2;\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest(sourceFiles, options); + } +} +//JDK7: Strings in Switch. +public void test410892_2() { + String errorMsg = + "----------\n" + + "1. ERROR in X.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 variables are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " public X(String s) {\n" + + " int var1 = 0;\n" + + " int var2 = 0;\n" + + " switch (s) {\n" + + " case \"test\": \n" + + " var2 = ++var1 % 2;\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest(sourceFiles, options); + } +} +//JDK7: Strings in Switch. +public void test410892_3() { + 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 variables are permitted\n" + + "----------\n"; + + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " static {\n" + + " int var1 = 0;\n" + + " int var2 = 0;\n" + + " String s = \"test2\";\n" + + " switch (s) {\n" + + " case \"test\": \n" + + " var2 = ++var1 % 2;\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel < JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, errorMsg); + } else { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + this.runConformTest(sourceFiles, options); + } +} +//JDK7: Strings in Switch. +public void test410892_4() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + String errorMsg = + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " int var2 = 0;\n" + + " ^^^^\n" + + "The value of the local variable var2 is not used\n" + + "----------\n"; + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " public void testFunction(String s) {\n" + + " int var1 = 0;\n" + + " int var2 = 0;\n" + + " switch (s) {\n" + + " case \"test\": \n" + + " var2 = ++var1 % 2;\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel >= JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, + errorMsg, + null, + true, + options); + } +} +//JDK7: Strings in Switch. +public void test410892_5() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + String errorMsg = + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " int var2 = 0;\n" + + " ^^^^\n" + + "The value of the local variable var2 is not used\n" + + "----------\n"; + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " public X(String s) {\n" + + " int var1 = 0;\n" + + " int var2 = 0;\n" + + " switch (s) {\n" + + " case \"test\": \n" + + " var2 = ++var1 % 2;\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel >= JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, + errorMsg, + null, + true, + options); + } +} +//JDK7: Strings in Switch. +public void test410892_6() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + String errorMsg = + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " int var2 = 0;\n" + + " ^^^^\n" + + "The value of the local variable var2 is not used\n" + + "----------\n"; + String [] sourceFiles = + new String[] { + "X.java", + "public class X {\n" + + " static {\n" + + " int var1 = 0;\n" + + " int var2 = 0;\n" + + " String s = \"Test2\";\n" + + " switch (s) {\n" + + " case \"test\": \n" + + " var2 = ++var1 % 2;\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel >= JDKLevelSupportingStringSwitch) { + this.runNegativeTest(sourceFiles, + errorMsg, + null, + true, + options); + } +} +public void test526911() { + String [] sourceFiles = + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " new Main().run();\n" + + " }\n" + + " \n" + + " private void run() {\n" + + " V v = new VA();\n" + + " I i = I.create(v);\n" + + " System.out.printf(\"%d %d\", i.m1(), i.m2());\n" + + " }\n" + + "}\n", + "XI.java", + "public class XI implements I {\n" + + " V v;\n" + + " public XI(V v) {\n" + + " this.v = v;\n" + + " }\n" + + " @Override\n" + + " public int m1() {\n" + + " return 1;\n" + + " }\n" + + " @Override\n" + + " public int m2() {\n" + + " return 11;\n" + + " }\n" + + "}\n", + "YI.java", + "public class YI implements I {\n" + + " V v;\n" + + " public YI(V v) {\n" + + " this.v = v;\n" + + " }\n" + + " @Override\n" + + " public int m1() {\n" + + " return 2;\n" + + " }\n" + + " @Override\n" + + " public int m2() {\n" + + " return 22;\n" + + " }\n" + + "}\n", + "V.java", + "public class V {\n" + + " public enum T { A, B, C }\n" + + " private T t;\n" + + " public V(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public T getT() { return t; }\n" + + "}\n" + + "class VA extends V {\n" + + " VA() {\n" + + " super(T.A);\n" + + " }\n" + + "}", + "I.java", + "enum H { X, Y }\n" + + "public interface I {\n" + + " public static final int i = 0;\n" + + " public int m1();\n" + + " public int m2();\n" + + " public static I create(V v) { \n" + + " V.T t = v.getT();\n" + + " H h = getH(t);\n" + + " switch (h) { // depending on H i need different implementations of I. XI and YI provide them\n" + + " case X:\n" + + " return new XI(v);\n" + + " case Y:\n" + + " return new YI(v);\n" + + " default:\n" + + " throw new Error();\n" + + " } \n" + + " }\n" + + " static H getH(V.T t) { // different T's require different H's to handle them\n" + + " switch (t) {\n" + + " case A:\n" + + " return H.X;\n" + + " case B:\n" + + " case C:\n" + + " return H.Y;\n" + + " }\n" + + " throw new Error();\n" + + " }\n" + + "}", + "X.java", + "public class X {\n" + + " static {\n" + + " int var1 = 0;\n" + + " int var2 = 0;\n" + + " String s = \"Test2\";\n" + + " switch (s) {\n" + + " case \"test\": \n" + + " var2 = ++var1 % 2;\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }; + if (this.complianceLevel >= ClassFileConstants.JDK1_8) { + this.runConformTest(sourceFiles, "1 11"); + } +} +public void test526911a() { + // target 1.8, run with 9, should work fine + if (this.complianceLevel < ClassFileConstants.JDK9) + return; + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + String [] sourceFiles = + new String[] { + "Main.java", + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " new Main().run();\n" + + " }\n" + + " \n" + + " private void run() {\n" + + " V v = new VA();\n" + + " I i = I.create(v);\n" + + " System.out.printf(\"%d %d\", i.m1(), i.m2());\n" + + " }\n" + + "}\n", + "XI.java", + "public class XI implements I {\n" + + " V v;\n" + + " public XI(V v) {\n" + + " this.v = v;\n" + + " }\n" + + " @Override\n" + + " public int m1() {\n" + + " return 1;\n" + + " }\n" + + " @Override\n" + + " public int m2() {\n" + + " return 11;\n" + + " }\n" + + "}\n", + "YI.java", + "public class YI implements I {\n" + + " V v;\n" + + " public YI(V v) {\n" + + " this.v = v;\n" + + " }\n" + + " @Override\n" + + " public int m1() {\n" + + " return 2;\n" + + " }\n" + + " @Override\n" + + " public int m2() {\n" + + " return 22;\n" + + " }\n" + + "}\n", + "V.java", + "public class V {\n" + + " public enum T { A, B, C }\n" + + " private T t;\n" + + " public V(T t) {\n" + + " this.t = t;\n" + + " }\n" + + " public T getT() { return t; }\n" + + "}\n" + + "class VA extends V {\n" + + " VA() {\n" + + " super(T.A);\n" + + " }\n" + + "}", + "I.java", + "enum H { X, Y }\n" + + "public interface I {\n" + + " public static final int i = 0;\n" + + " public int m1();\n" + + " public int m2();\n" + + " public static I create(V v) { \n" + + " V.T t = v.getT();\n" + + " H h = getH(t);\n" + + " switch (h) { // depending on H i need different implementations of I. XI and YI provide them\n" + + " case X:\n" + + " return new XI(v);\n" + + " case Y:\n" + + " return new YI(v);\n" + + " default:\n" + + " throw new Error();\n" + + " } \n" + + " }\n" + + " static H getH(V.T t) { // different T's require different H's to handle them\n" + + " switch (t) {\n" + + " case A:\n" + + " return H.X;\n" + + " case B:\n" + + " case C:\n" + + " return H.Y;\n" + + " }\n" + + " throw new Error();\n" + + " }\n" + + "}", + "X.java", + "public class X {\n" + + " static {\n" + + " int var1 = 0;\n" + + " int var2 = 0;\n" + + " String s = \"Test2\";\n" + + " switch (s) {\n" + + " case \"test\": \n" + + " var2 = ++var1 % 2;\n" + + " break;\n" + + " }\n" + + " }\n" + + "}", + }; + this.runConformTest(sourceFiles, "1 11", options); +} +public void testBug533475() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + runConformTest( + new String[] { + "SwitchBug.java", + "public class SwitchBug {\n" + + " static class MyClass {\n" + + " private static final Object C = \"\";\n" + + "\n" + + " public enum State {\n" + + " ENABLED(C); // pass null constant\n" + + "\n" + + " State(Object value) {\n" + + " } // value can be ignored\n" + + " }\n" + + "\n" + + " /* unused method with switch statement IN SAME CLASS */\n" + + " private void unusedMethod() {\n" + + " switch (State.ENABLED) {\n" + + " case ENABLED:\n" + + " break;\n" + + " }\n" + + " }\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " // access enum values from an other class\n" + + " MyClass.State.values();\n" + + " System.out.println(\"It runs.\");\n" + + " }\n" + + "}\n" + }); +} +public void testBug545518() { + if (this.complianceLevel < ClassFileConstants.JDK1_8 || this.complianceLevel >= ClassFileConstants.JDK12) + return; + String message = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Multi-constant case labels supported from Java 14 onwards only\n" + + "----------\n"; + + this.runNegativeTest(new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " String arg = \"ABD\";\n" + + " switch(arg) {\n" + + " case \"ABC\", (false ? (String) \"c\" : (String) \"d\") : break;\n" + + " }\n" + + " }\n" + + "}\n" + }, + message); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=576093 +public void testBug576093a() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Map map = new HashMap<>();\n" + + " for (Entry entry : map.entrySet()) {\n" + + " switch (entry.getKey()) {\n" + + " default:\n" + + " break;\n" + + " }\n" + + " }\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + " enum Z {\n" + + " A\n" + + " }\n" + + "}", + }, + "Success"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=576093 +public void testBug576093b() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + this.runConformTest( + new String[] { + "X2.java", + "import java.util.Optional;\n" + + "\n" + + "public class X2 {\n" + + " public static void main(String[] args) {\n" + + " Optional o = Optional.of(Z.A);\n" + + " switch (o.get()) {\n" + + " default:\n" + + " break;\n" + + " }\n" + + " System.out.println(\"Success\");\n" + + " }\n" + + " enum Z {\n" + + " A\n" + + " }\n" + + "}", + }, + "Success"); +} +public static Class testClass() { + return SwitchTest.class; +} +} + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java new file mode 100644 index 0000000000..26ce171052 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java @@ -0,0 +1,422 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 186342 - [compiler][null] Using annotations for null checking + * bug 358903 - Filter practically unimportant resource leak warnings + * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) + * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for + * Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) + * bug 407191 - [1.8] Binary access support for type annotations + * Jesper Steen Moeller - Contributions for: + * Bug 406973 - [compiler] Parse MethodParameters attribute + * Bug 412153 - [1.8][compiler] Check validity of annotations which may be repeatable + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.ArrayList; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.jdt.core.tests.dom.StandAloneASTParserTest; +import org.eclipse.jdt.core.tests.junit.extension.TestCase; +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo; + +/** + * Run all compiler regression tests + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class TestAll extends junit.framework.TestCase { + +public TestAll(String testName) { + super(testName); +} +public static Test suite() { + + // Common test suites + ArrayList standardTests = new ArrayList(); + standardTests.add(ArrayTest.class); + standardTests.add(AssignmentTest.class); + standardTests.add(BooleanTest.class); + standardTests.add(CastTest.class); + standardTests.add(ClassFileComparatorTest.class); + standardTests.add(CollisionCase.class); + standardTests.add(ConstantTest.class); + standardTests.add(DeprecatedTest.class); + standardTests.add(LocalVariableTest.class); + standardTests.add(LookupTest.class); + standardTests.add(NumericTest.class); + standardTests.add(ProblemConstructorTest.class); + standardTests.add(ProblemTypeAndMethodTest.class); + standardTests.add(ScannerTest.class); + standardTests.add(SwitchTest.class); + standardTests.add(TryStatementTest.class); + standardTests.add(UtilTest.class); + standardTests.add(XLargeTest.class); + standardTests.add(InternalScannerTest.class); + standardTests.add(ConditionalExpressionTest.class); + standardTests.add(ExternalizeStringLiteralsTest.class); + standardTests.add(NonFatalErrorTest.class); + standardTests.add(FlowAnalysisTest.class); + standardTests.add(CharOperationTest.class); + standardTests.add(RuntimeTests.class); + standardTests.add(DebugAttributeTest.class); + standardTests.add(NullReferenceTest.class); + standardTests.add(NullReferenceTestAsserts.class); + if (UnconditionalFlowInfo.COVERAGE_TEST_FLAG) { + standardTests.add(NullReferenceImplTests.class); + } + standardTests.add(CompilerInvocationTests.class); + standardTests.add(InnerEmulationTest.class); + standardTests.add(SuperTypeTest.class); + standardTests.add(ForStatementTest.class); + standardTests.add(FieldAccessTest.class); + standardTests.add(SerialVersionUIDTests.class); + standardTests.add(LineNumberAttributeTest.class); + standardTests.add(ProgrammingProblemsTest.class); + standardTests.add(ManifestAnalyzerTest.class); + standardTests.add(InitializationTests.class); + standardTests.add(ResourceLeakTests.class); + standardTests.add(PackageBindingTest.class); + + // add all javadoc tests + for (int i=0, l=JavadocTest.ALL_CLASSES.size(); i testClass() { + return TextBlockTest.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_15); + } + public TextBlockTest(String testName){ + super(testName); + } + protected Map getCompilerOptions() { + return getCompilerOptions(true); + } + // Enables the tests to run individually + protected Map getCompilerOptions(boolean previewFlag) { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_15); + defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_15); + defaultOptions.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + return defaultOptions; + } + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions, String[] vmArguments) { + runConformTest(testFiles, expectedOutput, customOptions, vmArguments, new JavacTestOptions("-source 15 ")); + } + protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { + runConformTest(true, testFiles, null, expectedOutput, null, new JavacTestOptions("-source 15")); + } + protected void runConformTest( + // test directory preparation + boolean shouldFlushOutputDirectory, + String[] testFiles, + //compiler options + String[] classLibraries /* class libraries */, + Map customOptions /* custom options */, + // compiler results + String expectedCompilerLog, + // runtime results + String expectedOutputString, + String expectedErrorString, + String[] vmarguments, + // javac options + JavacTestOptions javacTestOptions) { + runTest( + // test directory preparation + shouldFlushOutputDirectory /* should flush output directory */, + testFiles /* test files */, + // compiler options + classLibraries /* class libraries */, + customOptions /* custom options */, + false /* do not perform statements recovery */, + null /* no custom requestor */, + // compiler results + false /* expecting no compiler errors */, + expectedCompilerLog /* expected compiler log */, + // runtime options + false /* do not force execution */, + vmarguments /* no vm arguments */, + // runtime results + expectedOutputString /* expected output string */, + expectedErrorString /* expected error string */, + // javac options + javacTestOptions /* javac test options */); + } + public void test001() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static String textb = \"\"\"\"\"\";\n" + + " ^^\n" + + "Syntax error on token \"\"\"\", invalid AssignmentOperator\n" + + "----------\n"); + } + public void test002() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\" \"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static String textb = \"\"\" \"\"\";\n" + + " ^^^\n" + + "Syntax error on token \"\" \"\", invalid AssignmentOperator\n" + + "----------\n"); + } + public void test003() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static String textb = \"\"\"\n" + + "\";\n" + + " ^^^^^\n" + + "Text block is not properly closed with the delimiter\n" + + "----------\n"); + } + public void test003a() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static String textb = \"\"\"\n" + + "\n" + + " ^^^^\n" + + "Text block is not properly closed with the delimiter\n" + + "----------\n"); + } + /* + * negative - unescaped '\' in a text block + */ + public void test004() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "abc\\def" + + "\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static String textb = \"\"\"\n" + + "abc\\def\"\"\";\n" + + " ^^^^^^^^^\n" + + "Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\\" \\\' \\\\ )\n" + + "----------\n"); + } + /* empty text block */ + public void test005() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "", + null); + } + /* + * positive - escaped '\' + */ + public void test006() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "abc\\\\def" + + "\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.print(textb);\n" + + " }\n" + + "}\n" + }, + "abc\\def", + null); + } + /* + * Positive - Multi line text block with varying indentation + * and \n + */ + public void test007() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + " line 1\n" + + " line 2\n" + + " \n" + + " line 3\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.print(textb);\n" + + " }\n" + + "}\n" + }, + "line 1\n" + // test framework trims the leading whitespace + " line 2\n" + + "\n" + + "line 3", + null); + } + /* + * Positive - Multi line text block with varying indentation + * and \n and \r + */ + public void test008() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + " line 1\n" + + " line 2\r" + + " \r" + + " line 3\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "line 1\n" + + " line 2\n" + + "\n" + + "line 3", // the trailing whitespace is trimmed by the test framework + null); + } + /* + * Positive - Multi line text block with varying indentation + * and \n and \r + */ + public void test008a() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + " line 1\n" + + " line 2\r" + + " \r" + + " line 3\n\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"<\");\n" + + " System.out.print(textb);\n" + + " System.out.print(\">\");\n" + + " }\n" + + "}\n" + }, + "< line 1\n" + + " line 2\n" + + "\n" + + " line 3\n" + + ">", // the trailing whitespace is trimmed by the test framework + null); + } + /* + * positive - using unescaped '"' in text block + */ + public void test009() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "\"abc-def" + + "\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "\"abc-def", + null); + } + /* + * positive - using escaped '"' in text block + */ + public void test010() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "\"abc-def\\\"\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "\"abc-def\"", + null); + } + /* + * positive - using escaped \ and escaped " in text block + */ + public void test011() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "\"abc\\\"\"\"def\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "\"abc\"\"\"def", + null); + } + /* + * positive - using Unicode in text block + * and compare with an equal String literal + */ + public void test012() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "\\u0ba4\\u0bae\\u0bbf\\u0bb4\"\"\";\n" + + " public static String str = \"\\u0ba4\\u0bae\\u0bbf\\u0bb4\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(str.equals(textb));\n" + + " }\n" + + "}\n" + }, + "true", + null); + } + /* + * positive - bigger piece of code as text block + */ + public void test013() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "static String code = \"\"\"\n" + + " public void print(Object o) {\n" + + " System.out.println(Objects.toString(o));\n" + + " }\n" + + " \"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.print(code);\n" + + " }\n" + + "}\n" + }, + "public void print(Object o) {\n" + + " System.out.println(Objects.toString(o));\n" + + "}", + null); + } + /* + * positive - concatenation of string with text block + */ + public void test014() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static String code = \"public void print(Object o) {\\n\" +\n" + + " \"\"\"\n" + + " System.out.println(Objects.toString(o));\n" + + " }\n" + + " \"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.print(code);\n" + + " }\n" + + "}\n" + }, + "public void print(Object o) {\n" + + " System.out.println(Objects.toString(o));\n" + + "}", + null); + } + /* + * positive - freely using quotes + */ + public void test015() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static String story = \"\"\"\n" + + " \"When I use a word,\" Humpty Dumpty said,\n" + + " in rather a scornful tone, \"it means just what I\n" + + " choose it to mean - neither more nor less.\"\n" + + " \"The question is,\" said Alice, \"whether you\n" + + " can make words mean so many different things.\"\n" + + " \"The question is,\" said Humpty Dumpty,\n" + + " \"which is to be master - that's all.\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.print(story);\n" + + " }\n" + + "}\n" + }, + "\"When I use a word,\" Humpty Dumpty said,\n" + + "in rather a scornful tone, \"it means just what I\n" + + "choose it to mean - neither more nor less.\"\n" + + "\"The question is,\" said Alice, \"whether you\n" + + "can make words mean so many different things.\"\n" + + "\"The question is,\" said Humpty Dumpty,\n" + + "\"which is to be master - that's all.", + null); + } + /* + * positive - html code with indentation + */ + public void test016() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static String html = \"\"\"\n" + + " \n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + " \"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.print(html);\n" + + " }\n" + + "}\n" + }, + "\n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + "", + null); + } + /* + * positive - html code with indentation with empty lines + */ + public void test016a() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static String html = \"\"\"\n" + + " \\r\\n" + + " \\r\\n" + + "

    Hello, world

    \\r\\n" + + " \\r\\n" + + " \\r\\n" + + " \"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(html);\n" + + " }\n" + + "}\n" + }, + "\n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + " ", + null); + } + /* + * positive - html code with indentation with \r as terminator + */ + public void test016c() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static String html = \"\"\"\n" + + " \n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + " \n" + + " \"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(html);\n" + + " }\n" + + "}\n" + }, + "\n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + "", + null); + } + /* + * positive - html code with indentation and trailing whitespace + */ + public void test017() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static String html = \"\"\"\n" + + " \n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + " \n" + + " \"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(html);\n" + + " }\n" + + "}\n" + }, + "\n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + "", + null); + } + /* + * positive - using octal escape char for trailing whitespace + */ + public void test018() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static String html = \"\"\"\n" + + " \\040\\040\n" + + " \\040\\040\n" + + "

    Hello, world

    \\040\\040\\040\n" + + " \\040\\040\n" + + " \"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.print(html);\n" + + " }\n" + + "}\n" + }, + " \n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + "", + null); + } + /* + * positive - using text block as a method argument + */ + public void test019() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"\"\"\n" + + " \\n" + + " \\n" + + "

    Hello, world

    \\n" + + " \\n" + + " \\n" + + " \"\"\");\n" + + " }\n" + + "}\n" + }, + "\n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + " ", + null); + } + /* + * positive - using variable assigned with text block as a method argument + */ + public void test020() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String html = \"\"\"\n" + + " \n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + " \n" + + " \"\"\";\n" + + " System.out.println(html);\n" + + " }\n" + + "}\n" + }, + "\n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + "", + null); + } + /* + * positive - assigning strings and text blocks interchangeably. + */ + public void test021() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String html = \"\"\"\n" + + " \n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + " \n" + + " \"\"\";\n" + + " String s = html;\n" + + " System.out.println(s);\n" + + " }\n" + + "}\n" + }, + "\n" + + " \n" + + "

    Hello, world

    \n" + + " \n" + + "", + null); + } + public void test024() { + runConformTest( + true, + new String[] { + "Main.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Main {\n" + + " public static void main(String[] args) {\n" + + " runConformTest(\n" + + " new String[] {\n" + + " \"XYZ.java\",\n" + + " \"\"\"\n" + + " public class XYZ {\n" + + " public static String textb = \\\"\"\"\n" + + " abc\\\\\\\"\"\"def\" \n" + + " \\\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + " }\"\"\"" + + " }, \n" + + " \"\",\n" + + " null,\n" + + " new String[] {\"--enable-preview\"});\n" + + " }\n" + + " private static void runConformTest(String[] strings, String text, Object object, String[] strings2) {\n" + + " System.out.println(strings[1]);\n" + + " }\n" + + "}" + }, + null, + "public class XYZ {\n" + + " public static String textb = \"\"\"\n" + + " abc\\\"\"\"def\"\n" + + " \"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}", + null, + JavacTestOptions.DEFAULT); + } + public void test025() { + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + " abc\\def\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + " }" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static String textb = \"\"\"\n" + + " abc\\def\"\"\";\n" + + " ^^^^^^^^^^^^\n" + + "Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\\" \\\' \\\\ )\n" + + "----------\n", + null, + true, + getCompilerOptions()); + } + + public void test027() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main (String[] args) {\n" + + " String xyz = \n" + + " \"\"\"\n" + + " public class Switch {\n" + + " public static void bar(int arg0) {\n" + + " int arg1 = 0;\n" + + " pointer: foo(\n" + + " switch (0 + arg0) {\n" + + " case 1 -> 1;\n" + + " default -> {break p;}\\n\"\n" + + " }\n" + + " });\n" + + " public static void foo(int arg0) {\n" + + " bar(MyDay.SUNDAY);\n" + + " }\n" + + " }\\n\"\"\"; \n" + + " System.out.println(xyz);\n" + + " }\n" + + "}" + }, + "public class Switch {\n" + + " public static void bar(int arg0) {\n" + + " int arg1 = 0;\n" + + " pointer: foo(\n" + + " switch (0 + arg0) {\n" + + " case 1 -> 1;\n" + + " default -> {break p;}\n" + + "\"\n" + + " }\n" + + " });\n" + + " public static void foo(int arg0) {\n" + + " bar(MyDay.SUNDAY);\n" + + " }\n" + + " }", + getCompilerOptions()); + } + // An empty text block + public void test028() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main (String[] args) {\n" + + " String xyz = \n" + + " \"\"\"\n" + + " \\n\"\"\"; \n" + + " System.out.println(xyz);\n" + + " }\n" + + "}" + }, + "", + getCompilerOptions()); + } + // An empty text block + public void test029() { + runConformTest( + new String[] { + "Cls2.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Cls2 {\n" + + " public static String str = \"\"\"\n" + + " Hello Guru \n" + + " \n" + + " \"\"\";\n" + + " public static void main (String[] args) {\n" + + " System.out.println(str);\n" + + " }\n" + + "}" + }, + "Hello Guru", // output comparison tool strips off all trailing whitespace + getCompilerOptions()); + } + public void testBug551948_1() { + runConformTest( + new String[] { + "Cls2.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Cls2 {\n" + + "static String text = \"\"\"\n" + + " Lorem ipsum dolor sit amet, consectetur adipiscing \\\n" + + " elit, sed do eiusmod tempor incididunt ut labore \\\n" + + " et dolore magna aliqua.\\\n" + + " \"\"\";\n" + + " public static void main (String[] args) {\n" + + " System.out.print(text);\n" + + " }\n" + + "}" + }, + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.", // output comparison tool strips off all trailing whitespace + getCompilerOptions()); + } + public void testBug551948_2() { + runConformTest( + new String[] { + "Cls2.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Cls2 {\n" + + "static String noLastLF = \"\"\"\n" + + " abc\n" + + " def\\\n" + + " ghi\"\"\";\n" + + " public static void main (String[] args) {\n" + + " System.out.print(noLastLF);\n" + + " }\n" + + "}" + }, + "abc\n defghi", + getCompilerOptions()); + } + public void testBug551948_3() { + runConformTest( + new String[] { + "Cls2.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Cls2 {\n" + + "static String python = \"\"\"\n" + + " if x == True and \\\\\n" + + " y == False\n" + + " \"\"\";\n" + + " public static void main (String[] args) {\n" + + " System.out.print(python);\n" + + " }\n" + + "}" + }, + "if x == True and \\\n" + + " y == False", + getCompilerOptions()); + } + public void testBug551948_4() { + runConformTest( + new String[] { + "Cls2.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Cls2 {\n" + + "static String colors = \"\"\"\n" + + " red \\\n" + + " green \\\n" + + " blue \\\n" + + " orange\"\"\"; \n" + + " public static void main (String[] args) {\n" + + " System.out.print(colors);\n" + + " }\n" + + "}" + }, + "red green blue orange", + getCompilerOptions()); + } + public void testBug551948_5() { + runNegativeTest( + new String[] { + "Cls2.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Cls2 {\n" + + "static String colors = \"\"\"\n" + + " \\red \n" + + " \\green \n" + + " \\blue \n" + + " \\orange\"\"\"; \n" + + " public static void main (String[] args) {\n" + + " System.out.print(colors);\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in Cls2.java (at line 3)\n" + + " static String colors = \"\"\"\n" + + " \\red \n" + + " \\green \n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "Invalid escape sequence (valid ones are \\b \\t \\n \\f \\r \\\" \\\' \\\\ )\n" + + "----------\n", + null, + true, + getCompilerOptions(true)); + } + public void testBug551948_6() { + runConformTest( + new String[] { + "Cls2.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Cls2 {\n" + + "static String str = \"A\\sline\\swith\\sspaces\";\n" + + " public static void main (String[] args) {\n" + + " System.out.print(str);\n" + + " }\n" + + "}" + }, + "A line with spaces", + getCompilerOptions()); + } + public void testBug551948_7() { + runConformTest( + new String[] { + "Cls2.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Cls2 {\n" + + "static String colors = \"\"\"\n" + + " red \\s\n" + + " green\\s\n" + + " blue \\s\n" + + " \"\"\";\n" + + " public static void main (String[] args) {\n" + + " System.out.print(colors);\n" + + " }\n" + + "}" + }, + "red \ngreen \nblue", // trailing whitespaces are trimmed + getCompilerOptions()); + } + public void testBug551948_8() { + runConformTest( + new String[] { + "Cls2.java", + "@SuppressWarnings(\"preview\")\n" + + "public class Cls2 {\n" + + "static String s = \"\"\"\n" + + "aaa\n" + + "\n" + + "bbb\n" + + "\n" + + "\n" + + "ccc" + + "\"\"\";\n" + + " public static void main (String[] args) {\n" + + " System.out.print(s);\n" + + " }\n" + + "}" + }, + "aaa\n\n" + + "bbb\n\n\n" + + "ccc", + getCompilerOptions()); + } + public void testCompliances_1() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "\n" + + " aa\"\"\";\n" + + " System.out.print(compare(textBlock));\n" + + " }\n" + + " private static boolean compare(String textBlock) {\n" + + " char LF = (char) 0x000A;\n" + + " String str = \"\" + LF + \"aa\";\n" + + " return textBlock.equals(str);\n" + + " }\n" + + "}" + }, + "true", + getCompilerOptions()); + } + public void testCompliances_2() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "\\n" + + "\\n" + + "\"\"\";\n" + + " System.out.print(compare(textBlock));\n" + + " }\n" + + " private static boolean compare(String textBlock) {\n" + + " char LF = (char) 0x000A;\n" + + " String str = \"\" + LF + LF + \"\";\n" + + " return textBlock.equals(str);\n" + + " }\n" + + "}" + }, + "true", + getCompilerOptions()); + } + public void testCompliances_3() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "\n" + + "\"\"\";\n" + + " System.out.print(textBlock);\n" + + " System.out.print(compare(textBlock));\n" + + " }\n" + + " private static boolean compare(String textBlock) {\n" + + " char LF = (char) 0x000A;\n" + + " String str = \"\" + '\\u0015' + LF + \"\";\n" + + " return textBlock.equals(str.stripIndent());\n" + + " }\n" + + "}" + }, + "true", + getCompilerOptions()); + } + public void testCompliances_4() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "v\r" + + "\r" + + "vaa\"\"\";\n" + + " char[] cs = textBlock.toCharArray();\n" + + " for (char c : cs) {\n" + + " //System.out.print((int)c);\n" + + " //System.out.print(',');\n" + + " }\n" + + " //System.out.println();\n" + + " System.out.print(compare(textBlock));\n" + + " }\n" + + " private static boolean compare(String textBlock) {\n" + + " char LF = (char) 0x000A;\n" + + " String str = \"v\" + LF + LF + '\\u0076' + \"aa\";\n" + + " return textBlock.equals(str.stripIndent());\n" + + " }\n" + + "}" + }, + "true", + getCompilerOptions()); + } + public void testCompliances_5() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "aa\f" + + "\f" + + "\"\"\";\n" + + " System.out.print(compare(textBlock));\n" + + " }\n" + + " private static boolean compare(String textBlock) {\n" + + " char LF = (char) 0x000A;\n" + + " String str = \"aa\" + LF + LF + \"\";\n" + + " return textBlock.equals(str);\n" + + " }\n" + + "}" + }, + "false", + getCompilerOptions()); + } + public void testCompliances_6() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "\n" + + "\"\"\";\n" + + " System.out.print(compare(textBlock));\n" + + " }\n" + + " private static boolean compare(String textBlock) {\n" + + " char LF = (char) 0x000A;\n" + + " String str = \"\" + '\\u0015' + LF + \"\";\n" + + " return textBlock.equals(str);\n" + + " }\n" + + "}" + }, + "true", + getCompilerOptions()); + } + public void testCompliances_7() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "aav\n" + + "\"\"\";\n" + + " System.out.print(compare(textBlock));\n" + + " }\n" + + " private static boolean compare(String textBlock) {\n" + + " char LF = (char) 0x000A;\n" + + " String str = \"aa\" + '\\u0076' + LF + \"\";\n" + + " return textBlock.equals(str.stripIndent());\n" + + " }\n" + + "}" + }, + "true", + getCompilerOptions()); + } + public void testCompliances_8() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "\\\"some\\\"\\n \\\"string\\\" \\n \\\"here\\\"\\n\"\"\";\n" + + " System.out.print(textBlock.length());\n" + + " }\n" + + "}" + }, + "26", + getCompilerOptions()); + } + // Escaped """ with escaping at the first '"' + public void testCompliances_9() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "some string ends with \\\"\"\"\\n\"\"\";\n" + + " System.out.print(textBlock.length());\n" + + " }\n" + + "}" + }, + "26", + getCompilerOptions()); + } + // Escaped """ with escaping at the second '"' + public void testCompliances_10() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "some string ends with \"\\\"\"\\n\"\"\";\n" + + " System.out.print(textBlock.length());\n" + + " }\n" + + "}" + }, + "26", + getCompilerOptions()); + } + // Escaped """ with escaping at the third '"' + public void testCompliances_11() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "some string ends with \"\"\\\"\\n\"\"\";\n" + + " System.out.print(textBlock.length());\n" + + " }\n" + + "}" + }, + "26", + getCompilerOptions()); + } + public void testCompliances_12() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\n" + + "\r\n" + + " aa\"\"\";\n" + + " System.out.print(compare(textBlock));\n" + + " }\n" + + " private static boolean compare(String textBlock) {\n" + + " char LF = (char) 0x000A;\n" + + " String str = \"\" + LF + \"aa\";\n" + + " return textBlock.equals(str);\n" + + " }\n" + + "}" + }, + "true", + getCompilerOptions()); + } + public void testCompliances_13() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textb = \"\"\"\n" + + "\\0\\1\\2\\3\\4\\5\\6\\7\\10\\11\\12\\13\\14\\15\\16\\17\\20\\21\\22\\23\\24\\25\\26\\27\\30\\31\\32\\33\\34\\35\\36\\37\\40\\41\\42\\43\\44\\45\\46\\47\\50\\51\\52\\53\\54\\55\\56\\57\\60\\61\\62\\63\\64\\65\\66\\67\\70\\71\\72\\73\\74\\75\\76\\77\\100\\101\\102\\103\\104\\105\\106\\107\\110\\111\\112\\113\\114\\115\\116\\117\\120\\121\\122\\123\\124\\125\\126\\127\\130\\131\\132\\133\\134\\135\\136\\137\\140\\141\\142\\143\\144\\145\\146\\147\\150\\151\\152\\153\\154\\155\\156\\157\\160\\161\\162\\163\\164\\165\\166\\167\\170\\171\\172\\173\\174\\175\\176\\177\\200\\201\\202\\203\\204\\205\\206\\207\\210\\211\\212\\213\\214\\215\\216\\217\\220\\221\\222\\223\\224\\225\\226\\227\\230\\231\\232\\233\\234\\235\\236\\237\\240\\241\\242\\243\\244\\245\\246\\247\\250\\251\\252\\253\\254\\255\\256\\257\\260\\261\\262\\263\\264\\265\\266\\267\\270\\271\\272\\273\\274\\275\\276\\277\\300\\301\\302\\303\\304\\305\\306\\307\\310\\311\\312\\313\\314\\315\\316\\317\\320\\321\\322\\323\\324\\325\\326\\327\\330\\331\\332\\333\\334\\335\\336\\337\\340\\341\\342\\343\\344\\345\\346\\347\\350\\351\\352\\353\\354\\355\\356\\357\\360\\361\\362\\363\\364\\365\\366\\367\\370\\371\\372\\373\\374\\375\\376\\377\"\"\";\n" + + " System.out.println(textb.length());\n" + + " for (int i=0; i<=0xFF; i++) {\n" + + " if (i != (int)textb.charAt(i)) {\n" + + " System.out.println(\"Error in octal escape :\" + i);\n" + + " }\n" + + " }\n" + + " }\n" + + "}" + }, + "256", + getCompilerOptions()); + } + public void testCompliances_14() { + runConformTest( + new String[] { + "C.java", + "@SuppressWarnings(\"preview\")\n" + + "public class C {\n" + + " public static void main(String argv[]) {\n" + + " String textBlock = \"\"\"\r\n" + + " This is a multi-line\n" + + " message that is super-\n" + + " exciting!\"\"\";\n" + + " System.out.print(compare(textBlock));\n" + + " }\n" + + " private static boolean compare(String textBlock) {\n" + + " String str = \"This is a multi-line\\n\" + \n" + + " \"message that is super-\\n\" + \n" + + " \"exciting!\";\n" + + " return textBlock.equals(str);\n" + + " }\n" + + "}" + }, + "true", + getCompilerOptions()); + } + public void testBug553252() { + Map defaultOptions = super.getCompilerOptions(); + Map copy = new HashMap(defaultOptions); + copy.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_14); + copy.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_14); + copy.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_14); + copy.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.DISABLED); + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public static String textb = \"\"\"\n" + + "\"\"\";\n" + + " ^^^^^^^\n" + + "The Java feature \'Text Blocks\' is only available with source level 15 and above\n" + + "----------\n", + null, + true, + new String[] {"-source 14 "}, + copy); + } + public void testBug562460() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "a\\sb\\sc\"\"\";\n" + + " public static void main(String[] args) {\n" + + " System.out.println(textb.equals(\"a b c\"));\n" + + " }\n" + + "}\n" + }, + "true", + getCompilerOptions()); + } + public void testCompliances_15() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + " \\baa\"\"\";\n" + + " public static void main(String[] args) {\n" + + " print(textb.toCharArray());\n" + + " }\n" + + " private static void print(char[] val) {\n" + + " for (char c : val) {\n" + + " System.out.print((int)c + \",\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "8,97,97,", + getCompilerOptions()); + } + public void testCompliances_16() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + " \\baa\"\"\";\n" + + " public static void main(String[] args) {\n" + + " print(textb.toCharArray());\n" + + " }\n" + + " private static void print(char[] val) {\n" + + " for (char c : val) {\n" + + " System.out.print((int)c + \",\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "8,97,97,", + getCompilerOptions()); + } + public void testCompliances_17() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "\\t\\baa\"\"\";\n" + + " public static void main(String[] args) {\n" + + " print(textb.toCharArray());\n" + + " }\n" + + " private static void print(char[] val) {\n" + + " for (char c : val) {\n" + + " System.out.print((int)c + \",\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "9,8,97,97,", + getCompilerOptions()); + } + public void testCompliances_18() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String textb = \"\"\"\n" + + "\\013\\baa\"\"\";\n" + + " public static void main(String[] args) {\n" + + " print(textb.toCharArray());\n" + + " }\n" + + " private static void print(char[] val) {\n" + + " for (char c : val) {\n" + + " System.out.print((int)c + \",\");\n" + + " }\n" + + " }\n" + + "}\n" + }, + "11,8,97,97,", + getCompilerOptions()); + } + public void testBug565639_1() { + runConformTest(true, + new String[]{ + "X.java", + "public class X {\n" + + " static final String TEXT_BLOCK = \"\"\"\n" + + " 1\n" + + " 2\n" + + " 3\n" + + " 4\n" + + " 5\n" + + " \"\"\";\n" + + " public static void main(String[] args) {\n" + + " throw new RuntimeException(\"This is line 10.\");\n" + + " }\n" + + "}\n" + }, + null, + getCompilerOptions(), + "", + "", + "java.lang.RuntimeException: This is line 10.\n" + + " at X.main(X.java:10)", + new String[] {"--enable-preview"}, + new JavacTestOptions("-source 14 --enable-preview")); + } + public void testBug565639_2() { + runConformTest(true, + new String[]{ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String TEXT_BLOCK = \"\"\"\n" + + " 1\n" + + " 2\n" + + " 3\n" + + " 4\n" + + " 5\n" + + " \"\"\";\n" + + " throw new RuntimeException(\"This is line 10.\");\n" + + " }\n" + + "}\n" + }, + null, + getCompilerOptions(), + "", + "", + "java.lang.RuntimeException: This is line 10.\n" + + " at X.main(X.java:10)", + new String[] {"--enable-preview"}, + new JavacTestOptions("-source 14 --enable-preview")); + } + public void testBug565639_3() { + runNegativeTest(new String[]{ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String TEXT_BLOCK = \"\"\"\n" + + " 1\n" + + " 2\n" + + " 3\n" + + " 4\n" + + " 5\n" + + " \"\"\"\";\n" + + " throw new RuntimeException(\"This is line 10.\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " \"\"\"\";\n" + + " ^^\n" + + "String literal is not properly closed by a double-quote\n" + + "----------\n"); + } + public void testBug565639_4() { + runNegativeTest(new String[]{ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String TEXT_BLOCK = \"\"\"\n" + + " 1\n" + + " 2\n" + + " 3\n" + + " 4\n" + + " 5\n" + + " \"\"\"\"\";\n" + + " throw new RuntimeException(\"This is line 10.\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " \"\"\"\"\";\n" + + " ^^\n" + + "Syntax error on token \"\"\"\", delete this token\n" + + "----------\n"); + } + public void testBug565639_5() { + runNegativeTest(new String[]{ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String TEXT_BLOCK = \"\"\"\n" + + " 1\n" + + " 2\n" + + " 3\n" + + " 4\n" + + " 5\n" + + " \\\"\"\"\"\"\";\n" + + " throw new RuntimeException(\"This is line 10.\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " \\\"\"\"\"\"\";\n" + + " ^^\n" + + "Syntax error on token \"\"\"\", delete this token\n" + + "----------\n"); + } + public void testBug565639_6() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String TEXT_BLOCK = \"\"\"\n" + + " 1\n" + + " 2\n" + + " 3\n" + + " 4\n" + + " \\\"\"\"\n" + + " \"\"\";\n" + + " System.out.println(TEXT_BLOCK);\n" + + " }\n" + + "}\n" + }, + "1\n" + + "2\n" + + "3\n" + + "4\n" + + "\"\"\"", + getCompilerOptions(), + new String[] {"--enable-preview"}); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java new file mode 100644 index 0000000000..7e3a22a963 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement17Test.java @@ -0,0 +1,1328 @@ +/******************************************************************************* + * Copyright (c) 2003, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Jesper Steen Moller - bug 404146 nested try-catch-finally-blocks leads to unrunnable Java byte code + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; +@SuppressWarnings({ "rawtypes" }) +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 {\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 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 | NullPointerException e) {}\n" + + "}\n" + + "}\n"}, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " public class X 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 extends Exception {\n" + + " ^^^^^^^^^\n" + + "The generic class X may not subclass java.lang.Throwable\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " } catch (X | NullPointerException e) {}\n" + + " ^\n" + + "Cannot use the parameterized type X 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"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=391092 +public void testBug391092() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) {\n" + + " try {\n" + + " } catch (NullPointerException | ArrayIndexOutOfBoundsException e []) {\n" + + " } catch (ClassCastException [] c) {\n" + + " } catch (ArrayStoreException a[]) {\n" + + " } catch (ArithmeticException | NegativeArraySizeException b[][] ) {\n" + + " } catch (ClassCastException[][] | ClassNotFoundException[] g) {\n" + + " }\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " } catch (NullPointerException | ArrayIndexOutOfBoundsException e []) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Illegal attempt to create arrays of union types\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " } catch (ClassCastException [] c) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "No exception of type ClassCastException[] can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " } catch (ArrayStoreException a[]) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "No exception of type ArrayStoreException[] can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "4. ERROR in X.java (at line 7)\n" + + " } catch (ArithmeticException | NegativeArraySizeException b[][] ) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Illegal attempt to create arrays of union types\n" + + "----------\n" + + "5. ERROR in X.java (at line 8)\n" + + " } catch (ClassCastException[][] | ClassNotFoundException[] g) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^\n" + + "No exception of type ClassCastException[][] can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "6. ERROR in X.java (at line 8)\n" + + " } catch (ClassCastException[][] | ClassNotFoundException[] g) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "No exception of type ClassNotFoundException[] can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n"); + } + +//Bug 404146 - nested try-catch-finally-blocks leads to unrunnable Java byte code +public void testBug404146() { + runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import javax.naming.NamingException;\n" + + + "\n" + + "public final class X {\n" + + "\n" + + " public static final void illegalStackMap() {\n" + + " try {\n" + + " try {\n" + + " Y.decoy1();\n" + + " } finally {\n" + + " try {\n" + + " Y.decoy2();\n" + + " } catch (final IOException e) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " } finally {\n" + + " try {\n" + + " Y.decoy3();\n" + + " } catch (final NamingException e) {\n" + + " return;\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + "Y.java", + "import java.io.IOException;\n" + + "import javax.naming.NamingException;\n" + + "public final class Y {\n" + + "\n" + + " public static void decoy1() {}\n" + + " public static void decoy2() throws IOException {}\n" + + " public static void decoy3() throws NamingException {}\n" + + "}\n" + }); +} +public void testBug488569_001() { + if (this.complianceLevel < ClassFileConstants.JDK9) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " Z z1 = new Z();\n" + + " try (Y y1 = new Y(); z1;) {\n" + + " } \n" + + " } \n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public void close() throws Exception {\n" + + " }\n" + + "}\n" + + "\n" + + "class Z implements AutoCloseable {\n" + + " public void close() throws Exception {\n" + + " } \n" + + "}\n" + + "\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " try (Y y1 = new Y(); z1;) {\n" + + " ^^\n" + + "Variable resource not allowed here for source level below 9\n" + + "----------\n"); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " Z z1 = new Z();\n" + + " try (Y y1 = new Y(); z1;) {\n" + + " } \n" + + " } \n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public void close() throws Exception {\n" + + " }\n" + + "}\n" + + "\n" + + "class Z implements AutoCloseable {\n" + + " public void close() throws Exception {\n" + + " } \n" + + "}\n" + + "\n" + }, + ""); + + } +} + +public static Class testClass() { + return TryStatement17Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement9Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement9Test.java new file mode 100644 index 0000000000..f73b28f385 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatement9Test.java @@ -0,0 +1,718 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; +@SuppressWarnings({ "rawtypes" }) +public class TryStatement9Test extends AbstractRegressionTest { + +static { +/// TESTS_NAMES = new String[] { "testBug488569_019" }; +// TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public TryStatement9Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); +} + +public void testBug488569_001() { // vanilla test case + this.runConformTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " final Y y1 = new Y();\n" + + " try (y1) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "} \n" + }, + "Done"); +} + +// vanilla with a delimiter +public void testBug488569_002() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " final Y y1 = new Y();\n" + + " try (y1;) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "} \n" + }, + "Done"); +} + +public void testBug488569_003() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " final Y y1 = new Y();\n" + + " final Y y2 = new Y();\n" + + " try (y1; y2) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "} \n" + }, + "Done"); +} +public void testBug488569_004() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " final Y y1 = new Y();\n" + + " try (y1; final Y y2 = new Y()) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "} \n" + }, + "Done"); +} + +public void testBug488569_005() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " final Y y1 = new Y();\n" + + " try (final Y y = new Y(); y1; final Y y2 = new Y()) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "} \n" + }, + "Done"); +} +public void testBug488569_006() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "public class X { \n" + + " public void foo() throws IOException {\n" + + " Y y1 = new Y();\n" + + " try(y1) { \n" + + " return;\n" + + " }\n" + + " } \n" + + "} \n" + + "\n" + + "class Y implements Closeable {\n" + + " final int x = 10;\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}", + }, + ""); +} + +// check for the error for non-effectively final variable. +public void testBug488569_007() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " Y y1 = new Y();\n" + + " y1 = new Y();\n" + + " try (y1) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 15)\n" + + " try (y1) { \n" + + " ^^\n" + + "Local variable y1 defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +//check for the error for combination of NameRef and LocalVarDecl. +public void testBug488569_008() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " try (y1; Y y1 = new Y()) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 13)\n" + + " try (y1; Y y1 = new Y()) { \n" + + " ^^\n" + + "y1 cannot be resolved\n" + + "----------\n"); +} + +//check for the warning for combination of LocalVarDecl and NameRef. +public void testBug488569_009() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " try (Y y1 = new Y(); y1) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " try (Y y1 = new Y(); y1) { \n" + + " ^^\n" + + "Duplicate resource reference y1\n" + + "----------\n"); +} +//check for the warning for combination of NameRef and NameRef. +public void testBug488569_010() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " Y y1 = new Y();\n" + + " try (y1; y1) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in X.java (at line 14)\n" + + " try (y1; y1) { \n" + + " ^^\n" + + "Duplicate resource reference y1\n" + + "----------\n"); +} +public void testBug488569_011() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " try (Y y1 = new Y();y1) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "} \n" + }, + "Done"); +} + +public void testBug488569_012() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Closeable;\n" + + "import java.io.IOException;\n" + + "\n" + + "class Y implements Closeable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " // nothing\n" + + " }\n" + + "}\n" + + "public class X {\n" + + "\n" + + " public void foo() throws IOException {\n" + + " Y y = new Y();\n" + + " try (Y y1 = new Y();y;y1) { \n" + + " //\n" + + " }\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "} \n" + }, + "Done"); +} + +// Confirm the behavior as described in https://bugs.eclipse.org/bugs/show_bug.cgi?id=338402#c16 even with the +// presence of a duplicate variable in-line with javac9. +public void testBug488569_013() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " Z z1 = new Z();\n" + + " try (Y y = new Y();z1;y) {\n" + + " }\n" + + " } \n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Y CLOSE\");\n" + + " }\n" + + "}\n" + + "\n" + + "class Z implements AutoCloseable {\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Z CLOSE\");\n" + + " }\n" + + "}\n" + }, + "Y CLOSE\n" + + "Z CLOSE\n" + + "Y CLOSE" + ); +} + +// check for unhandled-exception error +public void testBug488569_014() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Y y1 = new Y(); \n" + + " try (y1) {\n" + + " System.out.println(\"In Try\");\n" + + " } finally {\n" + + " }\n" + + " }\n" + + "}\n" + + " \n" + + "class Y implements AutoCloseable {\n" + + " public void close() throws IOException {\n" + + " System.out.println(\"Closed\");\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " try (y1) {\n" + + " ^^\n" + + "Unhandled exception type IOException thrown by automatic close() invocation on y1\n" + + "----------\n"); +} + +// field to be legal +public void testBug488569_015(){ + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " final Y y = new Y();\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " try (y) {\n" + + " System.out.println(\"In Try\");\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally { \n" + + " } \n" + + " //y1 = new Y(); \n" + + " } \n" + + "} \n" + + " \n" + + "class Y implements AutoCloseable {\n" + + " public void close() throws IOException {\n" + + " System.out.println(\"Closed\");\n" + + " }\n" + + "}\n" + }, + "In Try\n" + + "Closed" + ); +} +//field to be legal - but null field not to be called for close +public void testBug488569_016(){ + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " final Y y = null;\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + " public void foo() {\n" + + " try (y) {\n" + + " System.out.println(\"In Try\");\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " finally { \n" + + " } \n" + + " } \n" + + "} \n" + + " \n" + + "class Y implements AutoCloseable {\n" + + " public void close() throws IOException {\n" + + " System.out.println(\"Closed\");\n" + + " }\n" + + "}\n" + }, + "In Try" + ); +} + +// field in various avatars +public void testBug488569_017(){ + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "class Z {\n" + + " final Y yz = new Y();\n" + + "}\n" + + "public class X extends Z {\n" + + " final Y y2 = new Y();\n" + + " \n" + + " public void foo() {\n" + + " try (super.yz; y2) {\n" + + " System.out.println(\"In Try\");\n" + + " } catch (IOException e) {\n" + + " \n" + + " }finally { \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " System.out.println(\"Closed\");\n" + + " } \n" + + "} \n" + }, + "In Try\n" + + "Closed\n" + + "Closed" + ); +} + +// negative tests: non-final fields +public void testBug488569_018() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "class Z {\n" + + " Y yz = new Y();\n" + + "}\n" + + "public class X extends Z {\n" + + " Y y2 = new Y();\n" + + " \n" + + " public void foo() {\n" + + " try (this.y2; super.yz;y2) { \n" + + " System.out.println(\"In Try\");\n" + + " } catch (IOException e) { \n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " System.out.println(\"Closed\");\n" + + " } \n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " try (this.y2; super.yz;y2) { \n" + + " ^^\n" + + "Field y2 must be final\n" + + "----------\n" + + "2. ERROR in X.java (at line 10)\n" + + " try (this.y2; super.yz;y2) { \n" + + " ^^\n" + + "Field yz must be final\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " try (this.y2; super.yz;y2) { \n" + + " ^^\n" + + "Local variable y2 defined in an enclosing scope must be final or effectively final\n" + + "----------\n"); +} +//negative tests: duplicate fields +public void testBug488569_019() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "class Z {\n" + + " final Y yz = new Y();\n" + + "}\n" + + "public class X extends Z {\n" + + " final Y y2 = new Y();\n" + + " \n" + + " Y bar() {\n" + + " return new Y();\n" + + " }\n" + + " public void foo() {\n" + + " Y y3 = new Y();\n" + + " try (y3; y3;super.yz;super.yz;this.y2;) { \n" + + " System.out.println(\"In Try\");\n" + + " } catch (IOException e) { \n" + + " } \n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + + "class Y implements AutoCloseable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " System.out.println(\"Closed\");\n" + + " } \n" + + "} \n", + }, + "----------\n" + + "1. WARNING in X.java (at line 14)\n" + + " try (y3; y3;super.yz;super.yz;this.y2;) { \n" + + " ^^\n" + + "Duplicate resource reference y3\n" + + "----------\n" + + "2. WARNING in X.java (at line 14)\n" + + " try (y3; y3;super.yz;super.yz;this.y2;) { \n" + + " ^^^^^^^^\n" + + "Duplicate resource reference super.yz\n" + + "----------\n"); +} + +public void testBug488569_020() { // vanilla test case + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " final Z y2 = new Z();\n" + + " public static void main(String[] args) throws Exception {\n" + + " X t = new X();\n" + + " try (t.y2) { \n" + + " } \n" + + " } \n" + + "}\n" + + "\n" + + "class Z implements AutoCloseable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "} \n" + }, + "Done"); +} + +//negative tests: duplicate fields +public void testBug488569_021() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " final Z z = new Z();\n" + + " public X() {\n" + + " try(this.z) {\n" + + " \n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "class Z implements AutoCloseable {\n" + + " @Override\n" + + " public void close() throws IOException {\n" + + " System.out.println(\"Closed\");\n" + + " } \n" + + "} \n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " try(this.z) {\n" + + " ^^^^^^\n" + + "Unhandled exception type IOException thrown by automatic close() invocation on z\n" + + "----------\n"); +} + + +public static Class testClass() { + return TryStatement9Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java new file mode 100644 index 0000000000..ec1a41f01a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryStatementTest.java @@ -0,0 +1,6267 @@ +/******************************************************************************* + * Copyright (c) 2003, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" + * bug 387612 - Unreachable catch block...exception is never thrown from the try + * Jesper Steen Moller - Contribution for + * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import org.eclipse.jdt.core.ToolFactory; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.core.tests.util.Util; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class TryStatementTest extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "testBug387612" }; +// TESTS_NUMBERS = new int[] { 74, 75 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public TryStatementTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} +@Override +protected Map getCompilerOptions() { + Map compilerOptions = super.getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ShareCommonFinallyBlocks, CompilerOptions.ENABLED); + return compilerOptions; +} +public void test001() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public class X1 {\n" + + " public X1() throws Exception {\n" + + " }\n" + + " }\n" + + " public void method1(){\n" + + " try {\n" + + " new X1() {\n" + + " };\n" + + " } catch(Exception e){\n" + + " }\n" + + " }\n" + + "}\n", + }); +} + +public void test002() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "import java.io.*;\n" + + "import java.util.zip.*;\n" + + "class X {\n" + + " void bar() throws ZipException, IOException {}\n" + + " void foo() {\n" + + " try {\n" + + " bar();\n" + + " } catch (ZipException e) {\n" + + " } catch (IOException e) {\n" + + " }\n" + + " }\n" + + "}\n", + }); +} + +public void test003() { + this.runConformTest(new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public class A1 {\n" + + " public A1() throws Exception {\n" + + " }\n" + + " }\n" + + " public void method1(){\n" + + " try {\n" + + " new A1() {\n" + + " };\n" + + " } catch(Exception e){\n" + + " }\n" + + " }\n" + + "}\n", + }); +} + +public void test004() { + this.runConformTest(new String[] { + "p/ATC.java", + "package p;\n" + + "public class ATC {\n" + + " \n" + + " public class B extends Exception {\n" + + " public B(String msg) { super(msg); }\n" + + " }\n" + + " \n" + + " void foo() throws ATC.B {\n" + + " Object hello$1 = null;\n" + + " try {\n" + + " throw new B(\"Inside foo()\");\n" + + " } catch(B e) {\n" + + " System.out.println(\"Caught B\");\n" + + " } \n" + + " } \n" + + "}\n", + }); +} + +public void test005() { + this.runConformTest(new String[] { + "p/A.java", + "package p;\n" + + "import java.io.IOException;\n" + + "import java.util.Vector;\n" + + "/**\n" + + " * This test0 should run without producing a java.lang.ClassFormatError\n" + + " */\n" + + "public class A {\n" + + " public Vector getComponents () {\n" + + " try{\n" + + " throw new IOException();\n" + + " }\n" + + " catch (IOException ioe) {\n" + + " }\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new A().getComponents();\n" + + " }\n" + + "}\n", + }); +} + +public void test006() { + this.runConformTest(new String[] { + "p/T.java", + "package p;\n" + + "import java.lang.reflect.*;\n" + + "public class T extends InvocationTargetException {\n" + + " public static void main(String[] args) {\n" + + " T ct = new T();\n" + + " ct.getTargetException();\n" + + " }\n" + + " public Throwable getTargetException() {\n" + + " Runnable runnable = new Runnable() {\n" + + " public void run() {\n" + + " System.out.println(\"we got here\");\n" + + " T.super.getTargetException();\n" + + " }\n" + + " };\n" + + " runnable.run();\n" + + " return new Throwable();\n" + + " }\n" + + "}\n", + }); +} +public void test007() { + this.runConformTest(new String[] { + "TryFinally.java", + "class TryFinally { \n"+ + " public int readFile(String filename) throws Exception { \n"+ + " int interfaceID = -1; \n"+ + " int iNdx = 0; \n"+ + " try { \n"+ + " try { \n"+ + " return interfaceID; \n"+ + " } // end try \n"+ + " finally { \n"+ + " iNdx = 1; \n"+ + " } // end finally \n"+ + " } // end try \n"+ + " catch (Exception ex) { \n"+ + " throw new Exception(\"general exception \" + ex.getMessage() + \" on processing file \" + filename); \n"+ + " } // end catch \n"+ + " finally { \n"+ + " } // end finally \n"+ + " } // end readFile method \n"+ + "} \n" +}); +} +/* + * 1FZR1TO: IVJCOM:WIN - Class does not compile in VAJava 3.02-Java2 + */ +public void test008() { + this.runConformTest( + new String[] { + "RedundantException.java", + "import java.io.*;\n" + + "public class RedundantException {\n" + + " /**\n" + + " * Runs the class as an application.\n" + + " */\n" + + " public static void main(String[] args) {\n" + + " RedundantException re = new RedundantException();\n" + + " re.catchIt();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " /**\n" + + " * Defines a method that lists an exception twice.\n" + + " * This can be buried in a much longer list.\n" + + " */\n" + + " void throwIt() throws IOException, IOException {\n" + + " throw new IOException();\n" + + " }\n" + + " /**\n" + + " * Catches the redundantly defined exception.\n" + + " */\n" + + " void catchIt() {\n" + + " try {\n" + + " throwIt(); // compile error here\n" + + " } catch (IOException e) {\n" + + " System.out.println(\"Caught.\");\n" + + " }\n" + + " }\n" + + "}" + }, + "Caught.\n" + + "SUCCESS"); +} +public void test009() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + "public void save() {\n" + + " int a = 3;\n" + + " try {\n" + + " Object warnings = null;\n" + + " try {\n" + + " Object contexts = null;\n" + + " try {\n" + + " System.out.println(warnings);\n" + + " return;\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(contexts);\n" + + " return;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " return;\n" + + " }\n" + + " } finally {\n" + + " int b = 4;\n" + + " System.out.println(\"#save -> \" + b + a);\n" + + " }\n" + + "}\n" + + "public static void main(String[] args) {\n" + + " new Test().save();\n"+ + "}\n" + + "}" + }, + "null\n" + + "#save -> 43"); +} +public void test010() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + "public void save() {\n" + + " int a = 3;\n" + + " try {\n" + + " Object warnings = null;\n" + + " try {\n" + + " Object contexts = null;\n" + + " try {\n" + + " System.out.println(warnings);\n" + + " return;\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(contexts);\n" + + " return;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " return;\n" + + " }\n" + + " } catch(Exception e){\n"+ + " Object dummy1 = null;\n" + + " System.out.println(dummy1);\n" + + " Object dummy2 = null;\n" + + " System.out.println(dummy2);\n" + + " return;\n"+ + " } finally {\n" + + " int b = 4;\n" + + " System.out.println(\"#save -> \" + b + a);\n" + + " }\n" + + "}\n" + + "public static void main(String[] args) {\n" + + " new Test().save();\n"+ + "}\n" + + "}" + }, + "null\n" + + "#save -> 43"); +} + +public void test011() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + "public void save() {\n" + + " int a = 3;\n" + + " try {\n" + + " Object warnings = null;\n" + + " try {\n" + + " Object contexts = null;\n" + + " try {\n" + + " System.out.println(warnings);\n" + + " return;\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(contexts);\n" + + " return;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " return;\n" + + " }\n" + + " } catch(Exception e){\n"+ + " int dummy1 = 11;\n" + + " System.out.println(dummy1);\n" + + " int dummy2 = 12;\n" + + " System.out.println(dummy2);\n" + + " return;\n"+ + " } finally {\n" + + " int b = 4;\n" + + " System.out.println(\"#save -> \" + b + a);\n" + + " }\n" + + "}\n" + + "public static void main(String[] args) {\n" + + " new Test().save();\n"+ + "}\n" + + "}" + }, + "null\n" + + "#save -> 43"); +} +/* + * 4943 Verification error + */ +public void test012() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().delete(args);\n" + + " System.out.println(\"success\");\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + " void bar(int i) {\n" + + " }\n" + + " public Object delete(String[] resources) throws IOException {\n" + + " try {\n" + + " int totalWork = 3;\n" + + " Object result = \"aaa\";\n" + + " try {\n" + + " return result;\n" + + " } catch (Exception e) {\n" + + " throw new IOException();\n" + + " } finally {\n" + + " bar(totalWork);\n" + + " }\n" + + " } finally {\n" + + " bar(0);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "success"); +} + +/* + * 4943 Verification error + */ +public void test013() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().delete(args);\n" + + " System.out.println(\"success\");\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + " void bar(int i) {\n" + + " }\n" + + " public Object delete(String[] resources) throws IOException {\n" + + " try {\n" + + " int totalWork = 3;\n" + + " Object result = \"aaa\";\n" + + " try {\n" + + " return result;\n" + + " } catch (Exception e) {\n" + + " throw new IOException();\n" + + " } finally {\n" + + " bar(totalWork);\n" + + " }\n" + + " } finally {\n" + + " int totalWork = 4;\n" + + " bar(totalWork);\n" + + " }\n" + + " }\n" + + "}\n" + }, + "success"); +} +public void test014() { + this.runConformTest( + new String[] { + "Test.java", + "public class Test {\n" + + "public void save() {\n" + + " int a = 3;\n" + + " try {\n" + + " Object warnings = null;\n" + + " try {\n" + + " int contexts = 17;\n" + + " try {\n" + + " Object dummy = null;\n" + + " System.out.println(warnings);\n" + + " System.out.println(dummy);\n" + + " return;\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.println(contexts);\n" + + " return;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " return;\n" + + " } finally { \n" + + " int c = 34; \n"+ + " System.out.println(\"#inner-finally ->\" + a + c);\n"+ + " }\n" + + " } finally {\n" + + " int b = 4;\n" + + " System.out.println(\"#save -> \" + b + a);\n" + + " }\n" + + "}\n" + + "public static void main(String[] args) {\n" + + " new Test().save();\n"+ + "}\n" + + "}" + }, + "null\n" + + "null\n" + + "#inner-finally ->334\n" + + "#save -> 43"); +} + +public void test015() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n" + + "import java.io.IOException; \n" + + "public class X { \n" + + " public static void main(String args[]) { \n" + + " try { \n" + + " new Object(){ \n" + + " { \n" + + " if (true) throw new IOException(); \n" + + " if (true) throw new Exception(); \n" + + " } \n" + + " }; \n" + + " System.out.println(\"FAILED\"); \n" + + " } catch(Exception e){ \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + "} \n", + }, + "SUCCESS"); +} +public void test016() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n" + + "import java.io.IOException; \n" + + "public class X { \n" + + " public static void main(String args[]) { \n" + + " class SomeClass { \n" + + " SomeClass () throws IOException { \n" + + " } \n" + + " } \n" + + " try { \n" + + " new Object(){ \n" + + " { \n" + + " if (true) throw new IOException(); \n" + + " if (true) throw new Exception(); \n" + + " } \n" + + " }; \n" + + " System.out.println(\"FAILED\"); \n" + + " } catch(Exception e){ \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + "} \n", + }, + "SUCCESS"); +} +public void test017() { + this.runConformTest( + new String[] { + "p1/X.java", + "package p1; \n" + + "public class X { \n" + + " public static void main(String args[]) { \n" + + " try { \n" + + " new Object(){ \n" + + " { \n" + + " foo(); \n" + + " } \n" + + " }; \n" + + " System.out.println(\"FAILED\"); \n" + + " } catch(Exception e){ \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n" + + " static class AEx extends Exception {} \n" + + " static class BEx extends Exception {} \n" + + " static void foo() throws AEx, BEx { \n" + + " throw new AEx(); \n"+ + " } \n" + + "} \n", + }, + "SUCCESS"); +} + +// 8773 verification error +public void test018() { + this.runConformTest( + new String[] { + "VerifyEr.java", + "public class VerifyEr { \n" + + " protected boolean err(boolean b) { \n" + + " try { \n" + + " System.out.print(\"SUCC\"); \n" + + " } catch (Throwable t) { \n" + + " return b; \n" + + " } finally { \n" + + " try { \n" + + " if (b) { \n" + + " return b; \n" + + " } \n" + + " } finally { \n" + + " System.out.println(\"ESS\"); \n" + + " } \n" + + " } \n" + + " return false; \n" + + " } \n" + + " public static void main(String[] args) { \n" + + " new VerifyEr().err(false); \n" + + " } \n" + + "} \n", + }, + "SUCCESS"); +} +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=16279 + */ +public void test019() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " String logger; \n" + + " public static void main(String[] args) { \n" + + " new X().foo(); \n" + + " } \n"+ + " public void foo() { \n" + + " try { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } catch (Exception ce) { \n" + + " String s = null; \n" + + " try { \n" + + " return; \n" + + " } catch (Exception ex) { \n" + + " } \n" + + " s.hashCode(); \n" + + " } finally { \n" + + " if (this.logger == null) { \n" + + " String loggerManager = null; \n" + + " System.out.println(loggerManager); \n" + + " } \n" + + " } \n" + + " } \n" + + "} \n" + }, + "SUCCESS\n" + + "null"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=16279 + * shifting of finaly scopes against try/catch ones makes the custom ret address shifting + * unnecessary. + */ +public void test020() { + this.runConformTest( + new String[] { + "X.java", + "public class X { \n" + + " String logger; \n" + + " public static void main(String[] args) { \n" + + " new X().foo(); \n" + + " } \n"+ + " public void foo() { \n" + + " try { \n" + + " System.out.println(\"try1\"); \n" + + " try { \n" + + " System.out.println(\"try2\"); \n" + + " } finally { \n" + + " System.out.println(\"finally2\"); \n" + + " } \n" + + " } catch (Exception ce) { \n" + + " String s = null; \n" + + " try { \n" + + " return; \n" + + " } catch (Exception ex) { \n" + + " } \n" + + " s.hashCode(); \n" + + " } finally { \n" + + " System.out.println(\"finally1\"); \n" + + " try { \n" + + " System.out.println(\"try3\"); \n" + + " if (this.logger == null) { \n" + + " String loggerManager = null; \n" + + " } \n" + + " } finally { \n" + + " System.out.println(\"finally3\"); \n" + + " } \n" + + " } \n" + + " int i1 = 0; \n" + + " int i2 = 0; \n" + + " int i3 = 0; \n" + + " int i4 = 0; \n" + + " int i5 = 0; \n" + + " int i6 = 0; \n" + + " int i7 = 0; \n" + + " int i8 = 0; \n" + + " int i9 = 0; \n" + + " } \n" + + "} \n" + }, + "try1\n" + + "try2\n" + + "finally2\n" + + "finally1\n" + + "try3\n" + + "finally3"); +} + +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=21116 + * protected type visibility check + */ +public void test021() { + this.runConformTest( + new String[] { + "pa/A.java", + "package pa; \n" + + "public abstract class A { \n" + + " public static void main(String[] args) { \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n"+ + " protected AIC memberA; \n" + + " protected class AIC { \n" + + " public void methodAIC(String parameter) { \n" + + " // ....do something \n" + + " } \n" + + " } \n" + + "} \n", + "pb/B.java", + "package pb; \n" + + "public class B extends pa.A { \n" + + " private class BIC { \n" + + " public void methodBIC(String param) { \n" + + " memberA.methodAIC(param); \n" + + " } \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); +} + +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=19916 + * nested try/synchronized statements (local var index alloc) + */ +public void test022() { + this.runConformTest( + new String[] { + "pa/A.java", + "package pa; \n" + + "public class A { \n" + + " public static void main(String[] args) { \n" + + " new A().f(); \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n"+ + " boolean b = false; \n" + + " private Integer f() { \n" + + " while (true) { \n" + + " try { \n" + + " int x = 3; \n" + + " synchronized (this) { \n" + + " return null; \n" + + " } \n" + + " } finally { \n" + + " if (b) \n" + + " synchronized (this) { \n" + + " int y = 3; \n" + + " } \n" + + " } \n" + + " } \n" + + " } \n" + + "} \n" + }, + "SUCCESS"); +} + +public void test023() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportHiddenCatchBlock, CompilerOptions.ERROR); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " throw new BX();\n" + + " } catch(BX e) {\n" + + " } catch(AX e) {\n" + + " }\n" + + " }\n" + + "} \n" + + "class AX extends Exception {}\n" + + "class BX extends AX {}\n" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 6)\n" + + " } catch(AX e) {\n" + + " ^^\n" + + "Unreachable catch block for AX. Only more specific exceptions are thrown and they are handled by previous catch block(s).\n" + + "----------\n" + + "2. WARNING in X.java (at line 10)\n" + + " class AX extends Exception {}\n" + + " ^^\n" + + "The serializable class AX does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in X.java (at line 11)\n" + + " class BX extends AX {}\n" + + " ^^\n" + + "The serializable class BX does not declare a static final serialVersionUID field of type long\n" + + "----------\n", + // javac options + JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */); +} + + /* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=21203 + * NPE in ExceptionFlowContext + */ +public void test024() { + + this.runNegativeTest( + new String[] { + "p/X.java", + "package p; \n" + + "public class X { \n" + + " public void myMethod() { \n" + + " System.out.println(\"starting\"); \n" + + " try { \n" + + " if (true) throw new LookupException(); \n" + + " } catch(DataException de) { \n" + + " System.out.println(\"DataException occurred\"); \n" + + " } catch(LookupException le) { \n" + + " System.out.println(\"LookupException occurred\"); \n" + + " } catch(Throwable t) { \n" + + " System.out.println(\"Throwable occurred\"); \n" + + " } \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + "} \n" + + "class DataException extends Throwable { \n" + + "} \n" + + "class LookupException extends DataException { \n" + + "} \n" + }, + "----------\n" + + "1. ERROR in p\\X.java (at line 9)\n" + + " } catch(LookupException le) { \n" + + " ^^^^^^^^^^^^^^^\n" + + "Unreachable catch block for LookupException. It is already handled by the catch block for DataException\n" + + "----------\n" + + "2. WARNING in p\\X.java (at line 17)\n" + + " class DataException extends Throwable { \n" + + " ^^^^^^^^^^^^^\n" + + "The serializable class DataException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "3. WARNING in p\\X.java (at line 19)\n" + + " class LookupException extends DataException { \n" + + " ^^^^^^^^^^^^^^^\n" + + "The serializable class LookupException does not declare a static final serialVersionUID field of type long\n" + + "----------\n"); +} +// 60081 +public void test025() { + + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X\n" + + "{\n" + + " {\n" + + " String licenseFileName = \"C:/Program Files/Jatt/bin/license.key\";\n" + + " File licenseFile = new File(licenseFileName);\n" + + " try {\n" + + " BufferedReader licenseReader = new BufferedReader(\n" + + " new FileReader(licenseFile));\n" + + " StringBuffer buf = new StringBuffer();\n" + + " String line = null;\n" + + " while ((line = licenseReader.readLine()) != null) {\n" + + " char[] chars = line.toCharArray();\n" + + " for (int i = 0; i < line.length(); i++) {\n" + + " if (!Character.isSpace(line.charAt(i))) {\n" + + " buf.append(line.charAt(i));\n" + + " }\n" + + " }\n" + + " }\n" + + " \n" + + " } catch (FileNotFoundException e) {\n" + + " throw new Error(\"License file not found\", e);\n" + + " } catch (IOException e) {\n" + + " throw new Error(\"License file cannot be read\", e);\n" + + " }\n" + + " }\n" + + " public X()\n" + + " {\n" + + " }\n" + + " \n" + + " public X(X r) \n" + + " {\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=89710 +public void test026() throws Exception { + + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " \n" + + " static private ResourceBundle bundle = null;\n" + + " static {\n" + + " int i = 0;\n" + + " try {\n" + + " bundle = foo();\n" + + " } catch(Throwable e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "\n" + + " static ResourceBundle foo() {\n" + + " return null;\n" + + " }\n" + + "}\n", + }, + "", + null, + true, + null, + customOptions, + null); // custom requestor + + String expectedOutput = + " Local variable table:\n" + + " [pc: 6, pc: 20] local: i index: 0 type: int\n" + + " [pc: 16, pc: 20] local: e index: 1 type: java.lang.Throwable\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=89710 - variation +public void test027() throws Exception { + + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "\n" + + "public class X {\n" + + " \n" + + " void bar(boolean b) {\n" + + " if (b) {\n" + + " try {\n" + + " int i = 0;\n" + + " } catch(Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " } else {\n" + + " int j = 0;\n" + + " }\n" + + " }\n" + + "}\n", + }, + "", + null, + true, + null, + customOptions, + null); // custom requestor + + String expectedOutput = + " Local variable table:\n" + + " [pc: 0, pc: 20] local: this index: 0 type: X\n" + + " [pc: 0, pc: 20] local: b index: 1 type: boolean\n" + + " [pc: 10, pc: 14] local: e index: 2 type: java.lang.Exception\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98892 +public void test028() { + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().start();\n" + + " } catch(Exception e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " public Object start() {\n" + + " try {\n" + + " return null;\n" + + " } finally {\n" + + " System.out.print(\"ONCE:\");\n" + + " foo();\n" + + " }\n" + + " }\n" + + "\n" + + " private void foo() {\n" + + " throw new IllegalStateException(\"Gah!\");\n" + + " } \n" + + "}\n", + }, + "ONCE:SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98892 - variation +public void test029() { + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().start();\n" + + " } catch(Exception e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " public Object start() {\n" + + " try {\n" + + " return null;\n" + + " } finally {\n" + + " System.out.print(\"ONCE:\");\n" + + " foo();\n" + + " return this;\n" + + " }\n" + + " }\n" + + "\n" + + " private void foo() {\n" + + " throw new IllegalStateException(\"Gah!\");\n" + + " } \n" + + "}\n", + }, + "ONCE:SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=98892 - variation +public void test030() { + + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().start();\n" + + " } catch(Exception e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + " public Object start() {\n" + + " try {\n" + + " Object o = null;\n" + + " o.toString();\n" + + " return null;\n" + + " } catch(Exception e) {\n" + + " System.out.print(\"EXCEPTION:\");\n" + + " return e; \n" + + " } finally {\n" + + " System.out.print(\"ONCE:\");\n" + + " foo();\n" + + " }\n" + + " }\n" + + "\n" + + " private void foo() {\n" + + " throw new IllegalStateException(\"Gah!\");\n" + + " } \n" + + "}\n", + }, + "EXCEPTION:ONCE:SUCCESS"); +} +/* + * Try block is never reached + */ +public void test031() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + runNegativeTest( + // test directory preparation + true /* flush output directory */, + new String[] { /* test files */ + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + " static void foo(Object o) {}\n" + + " \n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " foo(new Object() {\n" + + " public void bar() throws IOException {\n" + + " bar1();\n" + + " }\n" + + " });\n" + + " } catch(IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " \n" + + " static void bar1() throws IOException {}\n" + + "}" + }, + // compiler options + null /* no class libraries */, + customOptions /* custom options */, + // compiler results + "----------\n" + /* expected compiler log */ + "1. ERROR in X.java (at line 13)\n" + + " } catch(IOException e) {\n" + + " ^^^^^^^^^^^\n" + + "Unreachable catch block for IOException. This exception is never thrown from the try statement body\n" + + "----------\n", + // javac options + JavacTestOptions.JavacHasABug.JavacBugFixed_6_10 /* javac test options */); +} +/* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=114855 + */ +public void test032() { + this.runConformTest( + new String[] { + "X.java", + "public class X\n" + + "{\n" + + " static int except_count;\n" + + "\n" + + " static boolean test_result = true;\n" + + " \n" + + " static Throwable all_except[] =\n" + + " {\n" + + " new AbstractMethodError(), // 0\n" + + " new ArithmeticException(), // 1\n" + + " new ArrayIndexOutOfBoundsException(), // 2\n" + + " new ArrayStoreException(), // 3\n" + + " new ClassCastException(), // 4\n" + + " new ClassCircularityError(), // 5\n" + + " new ClassFormatError(), // 6\n" + + " new ClassNotFoundException(), // 7\n" + + " new CloneNotSupportedException(), // 8\n" + + " new Error(), // 9\n" + + " new Exception(), // 10\n" + + " new IllegalAccessError(), // 11\n" + + " new IllegalAccessException(), // 12\n" + + " new IllegalArgumentException(), // 13\n" + + " new IllegalMonitorStateException(), // 14\n" + + " new IllegalThreadStateException(), // 15\n" + + " new IncompatibleClassChangeError(), // 16\n" + + " new IndexOutOfBoundsException(), // 17\n" + + " new InstantiationError(), // 18\n" + + " new InstantiationException(), // 19\n" + + " new InternalError(), // 20\n" + + " new InterruptedException(), // 21\n" + + " new LinkageError(), // 22\n" + + " new NegativeArraySizeException(), // 23\n" + + " new NoClassDefFoundError(), // 24\n" + + " new NoSuchFieldError(), // 25\n" + + " new NoSuchMethodError(), // 26\n" + + " new NoSuchMethodException(), // 27\n" + + " new NullPointerException(), // 28\n" + + " new NumberFormatException(), // 29\n" + + " new OutOfMemoryError(), // 30\n" + + " new StackOverflowError(), // 31\n" + + " new RuntimeException(), // 32\n" + + " new SecurityException(), // 33\n" + + " new StringIndexOutOfBoundsException(), // 34\n" + + " new ThreadDeath(), // 35\n" + + " new UnknownError(), // 36\n" + + " new UnsatisfiedLinkError(), // 37\n" + + " new VerifyError(), // 38\n" + + " };\n" + + "\n" + + " private static void check_except(int i)\n" + + " throws Throwable\n" + + " {\n" + + " if (except_count != i)\n" + + " {\n" + + " System.out.println(\"Error \"+except_count+\" != \"+i+\";\");\n" + + " test_result=false;\n" + + " }\n" + + " throw all_except[++except_count];\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws Throwable\n" + + " {\n" + + " try {\n" + + " except_count = 0;\n" + + " throw all_except[except_count];\n" + + " } catch (AbstractMethodError e0) {\n" + + " try {\n" + + " check_except(0);\n" + + " } catch (ArithmeticException e1) {\n" + + " try {\n" + + " check_except(1);\n" + + " } catch (ArrayIndexOutOfBoundsException e2) {\n" + + " try {\n" + + " check_except(2);\n" + + " } catch (ArrayStoreException e3) {\n" + + " try {\n" + + " check_except(3);\n" + + " } catch (ClassCastException e4) {\n" + + " try {\n" + + " check_except(4);\n" + + " } catch (ClassCircularityError e5) {\n" + + " try {\n" + + " check_except(5);\n" + + " } catch (ClassFormatError e6) {\n" + + " try {\n" + + " check_except(6);\n" + + " } catch (ClassNotFoundException e7) {\n" + + " try {\n" + + " check_except(7);\n" + + " } catch (CloneNotSupportedException e8) {\n" + + " try {\n" + + " check_except(8);\n" + + " } catch (Error e9) {\n" + + " try {\n" + + " check_except(9);\n" + + " } catch (Exception e10) {\n" + + " try {\n" + + " check_except(10);\n" + + " } catch (IllegalAccessError e11) {\n" + + " try {\n" + + " check_except(11);\n" + + " } catch (IllegalAccessException e12) {\n" + + " try {\n" + + " check_except(12);\n" + + " } catch (IllegalArgumentException e13) {\n" + + " try {\n" + + " check_except(13);\n" + + " } catch (IllegalMonitorStateException e14) {\n" + + " try {\n" + + " check_except(14);\n" + + " } catch (IllegalThreadStateException e15) {\n" + + " try {\n" + + " check_except(15);\n" + + " } catch (IncompatibleClassChangeError e16) {\n" + + " try {\n" + + " check_except(16);\n" + + " } catch (IndexOutOfBoundsException e17) {\n" + + " try {\n" + + " check_except(17);\n" + + " } catch (InstantiationError e18) {\n" + + " try {\n" + + " check_except(18);\n" + + " } catch (InstantiationException e19) {\n" + + " try {\n" + + " check_except(19);\n" + + " } catch (InternalError e20) {\n" + + " try {\n" + + " check_except(20);\n" + + " } catch (InterruptedException \n" + + "e21) {\n" + + " try {\n" + + " check_except(21);\n" + + " } catch (LinkageError e22) {\n" + + " try {\n" + + " check_except(22);\n" + + " } catch \n" + + "(NegativeArraySizeException e23) {\n" + + " try {\n" + + " check_except(23);\n" + + " } catch \n" + + "(NoClassDefFoundError e24) {\n" + + " try {\n" + + " check_except(24);\n" + + " } catch (NoSuchFieldError \n" + + "e25) {\n" + + " try {\n" + + " check_except(25);\n" + + " } catch \n" + + "(NoSuchMethodError e26) {\n" + + " try {\n" + + " check_except(26);\n" + + " } catch \n" + + "(NoSuchMethodException e27) {\n" + + " try {\n" + + " check_except(27);\n" + + " } catch \n" + + "(NullPointerException e28) {\n" + + " try {\n" + + " check_except\n" + + "(28);\n" + + " } catch \n" + + "(NumberFormatException e29) {\n" + + " try {\n" + + " check_except\n" + + "(29);\n" + + " } catch \n" + + "(OutOfMemoryError e30) {\n" + + " try {\n" + + " check_except\n" + + "(30);\n" + + " } catch \n" + + "(StackOverflowError e31) {\n" + + " try {\n" + + " \n" + + "check_except(31);\n" + + " } catch \n" + + "(RuntimeException e32) {\n" + + " try {\n" + + " \n" + + "check_except(32);\n" + + " } catch \n" + + "(SecurityException e33) {\n" + + " try {\n" + + " \n" + + "check_except(33);\n" + + " } catch \n" + + "(StringIndexOutOfBoundsException e34) {\n" + + " try {\n" + + " \n" + + "check_except(34);\n" + + " } \n" + + "catch (ThreadDeath e35) {\n" + + " try \n" + + "{\n" + + " \n" + + "check_except(35);\n" + + " } \n" + + "catch (UnknownError e36) {\n" + + " \n" + + "try {\n" + + " \n" + + "check_except(36);\n" + + " } \n" + + "catch (UnsatisfiedLinkError e37) {\n" + + " \n" + + "try {\n" + + " \n" + + " check_except(37);\n" + + " \n" + + "} catch (VerifyError e38) {\n" + + " \n" + + " ++except_count;\n" + + " \n" + + "}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}\n" + + " System.out.print(test_result & (except_count == all_except.length));\n" + + " }\n" + + "}", + }, + "true"); +} +public void test033() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " interface IActionSetContributionItem {\n" + + " String getActionSetId();\n" + + " }\n" + + " public interface IAction {\n" + + " }\n" + + " interface IContributionItem {\n" + + " String getId();\n" + + " boolean isSeparator();\n" + + " boolean isGroupMarker();\n" + + " }\n" + + " public static void findInsertionPoint(String startId,\n" + + " String sortId, IContributionItem[] items) {\n" + + " // Find the reference item.\n" + + " try {\n" + + " int insertIndex = 0;\n" + + " while (insertIndex < items.length) {\n" + + " if (startId.equals(items[insertIndex].getId()))\n" + + " break;\n" + + " ++insertIndex;\n" + + " }\n" + + " if (insertIndex >= items.length)\n" + + " return;\n" + + " \n" + + " int compareMetric = 0;\n" + + " \n" + + " // Find the insertion point for the new item.\n" + + " // We do this by iterating through all of the previous\n" + + " // action set contributions define within the current group.\n" + + " for (int nX = insertIndex + 1; nX < items.length; nX++) {\n" + + " IContributionItem item = items[nX];\n" + + " if (item.isSeparator() || item.isGroupMarker()) {\n" + + " // Fix for bug report 18357\n" + + " break;\n" + + " }\n" + + " if (item instanceof IActionSetContributionItem) {\n" + + " if (sortId != null) {\n" + + " String testId = ((IActionSetContributionItem) item)\n" + + " .getActionSetId();\n" + + " if (sortId.compareTo(testId) < compareMetric)\n" + + " break;\n" + + " }\n" + + " insertIndex = nX;\n" + + " } else {\n" + + " break;\n" + + " }\n" + + " }\n" + + " } catch(Exception e) {}\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " findInsertionPoint(\"\", \"\", null);\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " // Method descriptor #15 (Ljava/lang/String;Ljava/lang/String;[LX$IContributionItem;)V\n" + + " // Stack: 3, Locals: 8\n" + + " public static void findInsertionPoint(java.lang.String startId, java.lang.String sortId, X.IContributionItem[] items);\n" + + " 0 iconst_0\n" + + " 1 istore_3 [insertIndex]\n" + + " 2 goto 26\n" + + " 5 aload_0 [startId]\n" + + " 6 aload_2 [items]\n" + + " 7 iload_3 [insertIndex]\n" + + " 8 aaload\n" + + " 9 invokeinterface X$IContributionItem.getId() : java.lang.String [16] [nargs: 1]\n" + + " 14 invokevirtual java.lang.String.equals(java.lang.Object) : boolean [22]\n" + + " 17 ifeq 23\n" + + " 20 goto 32\n" + + " 23 iinc 3 1 [insertIndex]\n" + + " 26 iload_3 [insertIndex]\n" + + " 27 aload_2 [items]\n" + + " 28 arraylength\n" + + " 29 if_icmplt 5\n" + + " 32 iload_3 [insertIndex]\n" + + " 33 aload_2 [items]\n" + + " 34 arraylength\n" + + " 35 if_icmplt 39\n" + + " 38 return\n" + + " 39 iconst_0\n" + + " 40 istore 4 [compareMetric]\n" + + " 42 iload_3 [insertIndex]\n" + + " 43 iconst_1\n" + + " 44 iadd\n" + + " 45 istore 5 [nX]\n" + + " 47 goto 123\n" + + " 50 aload_2 [items]\n" + + " 51 iload 5 [nX]\n" + + " 53 aaload\n" + + " 54 astore 6 [item]\n" + + " 56 aload 6 [item]\n" + + " 58 invokeinterface X$IContributionItem.isSeparator() : boolean [28] [nargs: 1]\n" + + " 63 ifne 134\n" + + " 66 aload 6 [item]\n" + + " 68 invokeinterface X$IContributionItem.isGroupMarker() : boolean [32] [nargs: 1]\n" + + " 73 ifeq 79\n" + + " 76 goto 134\n" + + " 79 aload 6 [item]\n" + + " 81 instanceof X$IActionSetContributionItem [35]\n" + + " 84 ifeq 134\n" + + " 87 aload_1 [sortId]\n" + + " 88 ifnull 117\n" + + " 91 aload 6 [item]\n" + + " 93 checkcast X$IActionSetContributionItem [35]\n" + + " 96 invokeinterface X$IActionSetContributionItem.getActionSetId() : java.lang.String [37] [nargs: 1]\n" + + " 101 astore 7 [testId]\n" + + " 103 aload_1 [sortId]\n" + + " 104 aload 7 [testId]\n" + + " 106 invokevirtual java.lang.String.compareTo(java.lang.String) : int [40]\n" + + " 109 iload 4 [compareMetric]\n" + + " 111 if_icmpge 117\n" + + " 114 goto 134\n" + + " 117 iload 5 [nX]\n" + + " 119 istore_3 [insertIndex]\n" + + " 120 iinc 5 1 [nX]\n" + + " 123 iload 5 [nX]\n" + + " 125 aload_2 [items]\n" + + " 126 arraylength\n" + + " 127 if_icmplt 50\n" + + " 130 goto 134\n" + + " 133 astore_3\n" + + " 134 return\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=124853 +public void test034() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private static int scenario(){\n" + + " try {\n" + + " int i = 1;\n" + + " System.out.print(\"[i: \" + i+\"]\");\n" + + " if (i > 5) {\n" + + " return i;\n" + + " }\n" + + " return -i;\n" + + " } catch (Exception e) {\n" + + " System.out.print(\"[WRONG CATCH]\");\n" + + " return 2;\n" + + " } finally {\n" + + " System.out.print(\"[finally]\");\n" + + " try {\n" + + " throwRuntime();\n" + + " } finally {\n" + + " clean();\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " private static void throwRuntime() {\n" + + " throw new RuntimeException(\"error\");\n" + + " }\n" + + "\n" + + " private static void clean() {\n" + + " System.out.print(\"[clean]\");\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " scenario();\n" + + " } catch(Exception e){\n" + + " System.out.println(\"[end]\");\n" + + " }\n" + + " }\n" + + "\n" + + "}\n", + }, + "[i: 1][finally][clean][end]"); + +// if (this.complianceLevel.compareTo(COMPLIANCE_1_6) >= 0) return; + String expectedOutput = new CompilerOptions(getCompilerOptions()).inlineJsrBytecode + ? " // Method descriptor #15 ()I\n" + + " // Stack: 4, Locals: 4\n" + + " private static int scenario();\n" + + " 0 iconst_1\n" + + " 1 istore_0 [i]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 5 new java.lang.StringBuilder [22]\n" + + " 8 dup\n" + + " 9 ldc [24]\n" + + " 11 invokespecial java.lang.StringBuilder(java.lang.String) [26]\n" + + " 14 iload_0 [i]\n" + + " 15 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [29]\n" + + " 18 ldc [33]\n" + + " 20 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [35]\n" + + " 23 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 26 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 29 iload_0 [i]\n" + + " 30 iconst_5\n" + + " 31 if_icmple 61\n" + + " 34 iload_0 [i]\n" + + " 35 istore_2\n" + + " 36 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 39 ldc [47]\n" + + " 41 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 44 invokestatic X.throwRuntime() : void [49]\n" + + " 47 goto 56\n" + + " 50 astore_3\n" + + " 51 invokestatic X.clean() : void [52]\n" + + " 54 aload_3\n" + + " 55 athrow\n" + + " 56 invokestatic X.clean() : void [52]\n" + + " 59 iload_2\n" + + " 60 ireturn\n" + + " 61 iload_0 [i]\n" + + " 62 ineg\n" + + " 63 istore_2\n" + + " 64 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 67 ldc [47]\n" + + " 69 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 72 invokestatic X.throwRuntime() : void [49]\n" + + " 75 goto 84\n" + + " 78 astore_3\n" + + " 79 invokestatic X.clean() : void [52]\n" + + " 82 aload_3\n" + + " 83 athrow\n" + + " 84 invokestatic X.clean() : void [52]\n" + + " 87 iload_2\n" + + " 88 ireturn\n" + + " 89 astore_0 [e]\n" + + " 90 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 93 ldc [55]\n" + + " 95 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 98 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 101 ldc [47]\n" + + " 103 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 106 invokestatic X.throwRuntime() : void [49]\n" + + " 109 goto 118\n" + + " 112 astore_3\n" + + " 113 invokestatic X.clean() : void [52]\n" + + " 116 aload_3\n" + + " 117 athrow\n" + + " 118 invokestatic X.clean() : void [52]\n" + + " 121 iconst_2\n" + + " 122 ireturn\n" + + " 123 astore_1\n" + + " 124 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 127 ldc [47]\n" + + " 129 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 132 invokestatic X.throwRuntime() : void [49]\n" + + " 135 goto 144\n" + + " 138 astore_3\n" + + " 139 invokestatic X.clean() : void [52]\n" + + " 142 aload_3\n" + + " 143 athrow\n" + + " 144 invokestatic X.clean() : void [52]\n" + + " 147 aload_1\n" + + " 148 athrow\n" + + " Exception Table:\n" + + " [pc: 44, pc: 50] -> 50 when : any\n" + + " [pc: 72, pc: 78] -> 78 when : any\n" + + " [pc: 0, pc: 36] -> 89 when : java.lang.Exception\n" + + " [pc: 61, pc: 64] -> 89 when : java.lang.Exception\n" + + " [pc: 106, pc: 112] -> 112 when : any\n" + + " [pc: 0, pc: 36] -> 123 when : any\n" + + " [pc: 61, pc: 64] -> 123 when : any\n" + + " [pc: 89, pc: 98] -> 123 when : any\n" + + " [pc: 132, pc: 138] -> 138 when : any\n" + : " // Method descriptor #15 ()I\n" + + " // Stack: 4, Locals: 6\n" + + " private static int scenario();\n" + + " 0 iconst_1\n" + + " 1 istore_0 [i]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 5 new java.lang.StringBuffer [22]\n" + + " 8 dup\n" + + " 9 ldc [24]\n" + + " 11 invokespecial java.lang.StringBuffer(java.lang.String) [26]\n" + + " 14 iload_0 [i]\n" + + " 15 invokevirtual java.lang.StringBuffer.append(int) : java.lang.StringBuffer [29]\n" + + " 18 ldc [33]\n" + + " 20 invokevirtual java.lang.StringBuffer.append(java.lang.String) : java.lang.StringBuffer [35]\n" + + " 23 invokevirtual java.lang.StringBuffer.toString() : java.lang.String [38]\n" + + " 26 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 29 iload_0 [i]\n" + + " 30 iconst_5\n" + + " 31 if_icmple 41\n" + + " 34 iload_0 [i]\n" + + " 35 istore_3\n" + + " 36 jsr 69\n" + + " 39 iload_3\n" + + " 40 ireturn\n" + + " 41 iload_0 [i]\n" + + " 42 ineg\n" + + " 43 istore_3\n" + + " 44 jsr 69\n" + + " 47 iload_3\n" + + " 48 ireturn\n" + + " 49 astore_0 [e]\n" + + " 50 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 53 ldc [47]\n" + + " 55 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 58 jsr 69\n" + + " 61 iconst_2\n" + + " 62 ireturn\n" + + " 63 astore_2\n" + + " 64 jsr 69\n" + + " 67 aload_2\n" + + " 68 athrow\n" + + " 69 astore_1\n" + + " 70 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 73 ldc [49]\n" + + " 75 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 78 invokestatic X.throwRuntime() : void [51]\n" + + " 81 goto 99\n" + + " 84 astore 5\n" + + " 86 jsr 92\n" + + " 89 aload 5\n" + + " 91 athrow\n" + + " 92 astore 4\n" + + " 94 invokestatic X.clean() : void [54]\n" + + " 97 ret 4\n" + + " 99 jsr 92\n" + + " 102 ret 1\n" + + " Exception Table:\n" + + " [pc: 0, pc: 39] -> 49 when : java.lang.Exception\n" + + " [pc: 41, pc: 47] -> 49 when : java.lang.Exception\n" + + " [pc: 0, pc: 39] -> 63 when : any\n" + + " [pc: 41, pc: 47] -> 63 when : any\n" + + " [pc: 49, pc: 61] -> 63 when : any\n" + + " [pc: 78, pc: 84] -> 84 when : any\n" + + " [pc: 99, pc: 102] -> 84 when : any\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=124853 - variation +public void test035() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().bar();\n" + + " } catch(Exception e){\n" + + " System.out.println(\"[end]\");\n" + + " }\n" + + " }\n" + + " Object bar() {\n" + + " try {\n" + + " System.out.print(\"[try]\");\n" + + " return this;\n" + + " } catch(Exception e){\n" + + " System.out.print(\"[WRONG CATCH]\");\n" + + " } finally {\n" + + " System.out.print(\"[finally]\");\n" + + " foo();\n" + + " }\n" + + " return this;\n" + + " }\n" + + " Object foo() {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}\n", + }, + "[try][finally][end]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=124853 - variation +public void test036() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().bar();\n" + + " } catch(Exception e){\n" + + " System.out.println(\"[end]\");\n" + + " }\n" + + " }\n" + + " Object bar() {\n" + + " try {\n" + + " System.out.print(\"[try]\");\n" + + " throw new RuntimeException();\n" + + " } catch(Exception e){\n" + + " System.out.print(\"[catch]\");\n" + + " return this;\n" + + " } finally {\n" + + " System.out.print(\"[finally]\");\n" + + " foo();\n" + + " }\n" + + " }\n" + + " Object foo() {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}\n", + }, + "[try][catch][finally][end]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=124853 - variation +public void test037() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " scenario();\n" + + " } catch(Exception e){\n" + + " System.out.println(\"[end]\");\n" + + " }\n" + + " }\n" + + "\n" + + " private static void scenario() throws Exception {\n" + + " try {\n" + + " System.out.print(\"[try1]\");\n" + + " try {\n" + + " System.out.print(\"[try2]\");\n" + + " return;\n" + + " } catch(Exception e) {\n" + + " System.out.print(\"[catch2]\");\n" + + " } finally {\n" + + " System.out.print(\"[finally2]\");\n" + + " throwRuntime();\n" + + " }\n" + + " } catch(Exception e) {\n" + + " System.out.print(\"[catch1]\");\n" + + " throw e;\n" + + " } finally {\n" + + " System.out.print(\"[finally1]\");\n" + + " }\n" + + " }\n" + + "\n" + + " private static void throwRuntime() {\n" + + " throw new RuntimeException(\"error\");\n" + + " }\n" + + "}\n", + }, + "[try1][try2][finally2][catch1][finally1][end]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=87423 +public void test038() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " int hasLoop() {\n" + + " int l, m, n;\n" + + " for (m = 0; m < 10; m++) {\n" + + " n = 2;\n" + + " try {\n" + + " n = 3;\n" + + " try {\n" + + " n = 4;\n" + + " } catch (ArithmeticException e1) {\n" + + " n = 11;\n" + + " } finally {\n" + + " for (l = 0; l < 10; l++) {\n" + + " n++;\n" + + " }\n" + + " if (n == 12) {\n" + + " n = 13;\n" + + " break;\n" + + " }\n" + + " n = 15;\n" + + " }\n" + + " } catch (OutOfMemoryError e2) {\n" + + " n = 18;\n" + + " }\n" + + " }\n" + + " return 0;\n" + + " }\n" + + "\n" + + " public static void main(String args[]) {\n" + + " System.out.println(\"Loaded fine\");\n" + + " }\n" + + "}\n", + }, + "Loaded fine"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=127603 +public void test039() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void someMethod() {\n" + + " int count = 0;\n" + + " int code = -1;\n" + + " while (count < 2 && (code == -1 || code == 2)) {\n" + + " count++;\n" + + " try {\n" + + " {\n" + + " System.out.print(\"[Try:\" + count + \";\" + code+\"]\");\n" + + " }\n" + + " code = 0;\n" + + "\n" + + " } finally {\n" + + " System.out.print(\"[Finally\" + count + \";\" + code+\"]\");\n" + + " }\n" + + " }\n" + + " System.out.print(\"[Outering\");\n" + + "\n" + + " if (code == 0) {\n" + + " System.out.print(\"[Return:\" + count + \";\" + code+\"]\");\n" + + " return;\n" + + " }\n" + + " throw new RuntimeException(null + \"a\");\n" + + " }\n" + + "\n" + + " public static void main(String[] args) throws Exception {\n" + + " for (int i = 0; i < 1; i++) {\n" + + " someMethod();\n" + + " System.out.println();\n" + + " }\n" + + " }\n" + + "}\n", + }, + "[Try:1;-1][Finally1;0][Outering[Return:1;0]"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128705 +public void test040() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(boolean b) {\n" + + " try { \n" + + " if (b){ \n" + + " int i = 0;\n" + + " return;\n" + + " } else {\n" + + " Object o = null;\n" + + " return;\n" + + " }\n" + + " } finally {\n" + + " System.out.println(\"done\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(true);\n" + + " }\n" + + "}\n", + }, + "done"); + + CompilerOptions compilerOptions = new CompilerOptions(getCompilerOptions()); + String expectedOutput = !compilerOptions.inlineJsrBytecode + ? " // Method descriptor #15 (Z)V\n" + + " // Stack: 2, Locals: 5\n" + + " public void foo(boolean b);\n" + + " 0 iload_1 [b]\n" + + " 1 ifeq 10\n" + + " 4 iconst_0\n" + + " 5 istore_2 [i]\n" + + " 6 jsr 23\n" + + " 9 return\n" + + " 10 aconst_null\n" + + " 11 astore_2 [o]\n" + + " 12 goto 6\n" + + " 15 astore 4\n" + + " 17 jsr 23\n" + + " 20 aload 4\n" + + " 22 athrow\n" + + " 23 astore_3\n" + + " 24 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 27 ldc [22]\n" + + " 29 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 32 ret 3\n" + + " Exception Table:\n" + + " [pc: 0, pc: 9] -> 15 when : any\n" + + " [pc: 10, pc: 15] -> 15 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 10, line: 8]\n" + + " [pc: 12, line: 9]\n" + + " [pc: 15, line: 11]\n" + + " [pc: 20, line: 13]\n" + + " [pc: 23, line: 11]\n" + + " [pc: 24, line: 12]\n" + + " [pc: 32, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 34] local: this index: 0 type: X\n" + + " [pc: 0, pc: 34] local: b index: 1 type: boolean\n" + + " [pc: 6, pc: 10] local: i index: 2 type: int\n" + + " [pc: 12, pc: 15] local: o index: 2 type: java.lang.Object\n" + : null; + if (expectedOutput == null) { + if (compilerOptions.targetJDK == ClassFileConstants.JDK1_5) { + expectedOutput = " // Method descriptor #15 (Z)V\n" + + " // Stack: 2, Locals: 4\n" + + " public void foo(boolean b);\n" + + " 0 iload_1 [b]\n" + + " 1 ifeq 15\n" + + " 4 iconst_0\n" + + " 5 istore_2 [i]\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 ldc [22]\n" + + " 11 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 14 return\n" + + " 15 aconst_null\n" + + " 16 astore_2 [o]\n" + + " 17 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 20 ldc [22]\n" + + " 22 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 25 return\n" + + " 26 astore_3\n" + + " 27 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 30 ldc [22]\n" + + " 32 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 35 aload_3\n" + + " 36 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 6] -> 26 when : any\n" + + " [pc: 15, pc: 17] -> 26 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 6, line: 12]\n" + + " [pc: 14, line: 6]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 17, line: 12]\n" + + " [pc: 25, line: 9]\n" + + " [pc: 26, line: 11]\n" + + " [pc: 27, line: 12]\n" + + " [pc: 35, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 37] local: this index: 0 type: X\n" + + " [pc: 0, pc: 37] local: b index: 1 type: boolean\n" + + " [pc: 6, pc: 15] local: i index: 2 type: int\n" + + " [pc: 17, pc: 26] local: o index: 2 type: java.lang.Object\n"; + } else { + expectedOutput = " // Method descriptor #15 (Z)V\n" + + " // Stack: 2, Locals: 4\n" + + " public void foo(boolean b);\n" + + " 0 iload_1 [b]\n" + + " 1 ifeq 15\n" + + " 4 iconst_0\n" + + " 5 istore_2 [i]\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 9 ldc [22]\n" + + " 11 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 14 return\n" + + " 15 aconst_null\n" + + " 16 astore_2 [o]\n" + + " 17 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 20 ldc [22]\n" + + " 22 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 25 return\n" + + " 26 astore_3\n" + + " 27 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 30 ldc [22]\n" + + " 32 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 35 aload_3\n" + + " 36 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 6] -> 26 when : any\n" + + " [pc: 15, pc: 17] -> 26 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 4, line: 5]\n" + + " [pc: 6, line: 12]\n" + + " [pc: 14, line: 6]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 17, line: 12]\n" + + " [pc: 25, line: 9]\n" + + " [pc: 26, line: 11]\n" + + " [pc: 27, line: 12]\n" + + " [pc: 35, line: 13]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 37] local: this index: 0 type: X\n" + + " [pc: 0, pc: 37] local: b index: 1 type: boolean\n" + + " [pc: 6, pc: 15] local: i index: 2 type: int\n" + + " [pc: 17, pc: 26] local: o index: 2 type: java.lang.Object\n" + + " Stack map table: number of frames 2\n" + + " [pc: 15, same]\n" + + " [pc: 26, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n"; + } + } + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128705 - variation +public void test041() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(boolean b) {\n" + + " try {\n" + + " int i = 0;\n" + + " return;\n" + + " } catch(Exception e) {\n" + + " return;\n" + + " } finally {\n" + + " System.out.println(\"done\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo(true);\n" + + " }\n" + + "}\n", + }, + "done"); + + CompilerOptions compilerOptions = new CompilerOptions(getCompilerOptions()); + String expectedOutput = !compilerOptions.inlineJsrBytecode + ? " // Method descriptor #15 (Z)V\n" + + " // Stack: 2, Locals: 5\n" + + " public void foo(boolean b);\n" + + " 0 iconst_0\n" + + " 1 istore_2 [i]\n" + + " 2 jsr 18\n" + + " 5 return\n" + + " 6 astore_2 [e]\n" + + " 7 goto 2\n" + + " 10 astore 4\n" + + " 12 jsr 18\n" + + " 15 aload 4\n" + + " 17 athrow\n" + + " 18 astore_3\n" + + " 19 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 22 ldc [22]\n" + + " 24 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 27 ret 3\n" + + " Exception Table:\n" + + " [pc: 0, pc: 5] -> 6 when : java.lang.Exception\n" + + " [pc: 0, pc: 5] -> 10 when : any\n" + + " [pc: 6, pc: 10] -> 10 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 6, line: 6]\n" + + " [pc: 7, line: 7]\n" + + " [pc: 10, line: 8]\n" + + " [pc: 15, line: 10]\n" + + " [pc: 18, line: 8]\n" + + " [pc: 19, line: 9]\n" + + " [pc: 27, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 29] local: this index: 0 type: X\n" + + " [pc: 0, pc: 29] local: b index: 1 type: boolean\n" + + " [pc: 2, pc: 6] local: i index: 2 type: int\n" + + " [pc: 7, pc: 10] local: e index: 2 type: java.lang.Exception\n" + : null; + if (expectedOutput == null) { + if (compilerOptions.targetJDK == ClassFileConstants.JDK1_5) { + expectedOutput = " // Method descriptor #15 (Z)V\n" + + " // Stack: 2, Locals: 4\n" + + " public void foo(boolean b);\n" + + " 0 iconst_0\n" + + " 1 istore_2 [i]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 5 ldc [22]\n" + + " 7 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 10 return\n" + + " 11 astore_2 [e]\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 15 ldc [22]\n" + + " 17 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 20 return\n" + + " 21 astore_3\n" + + " 22 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 25 ldc [22]\n" + + " 27 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 30 aload_3\n" + + " 31 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 2] -> 11 when : java.lang.Exception\n" + + " [pc: 0, pc: 2] -> 21 when : any\n" + + " [pc: 11, pc: 12] -> 21 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 2, line: 9]\n" + + " [pc: 10, line: 5]\n" + + " [pc: 11, line: 6]\n" + + " [pc: 12, line: 9]\n" + + " [pc: 20, line: 7]\n" + + " [pc: 21, line: 8]\n" + + " [pc: 22, line: 9]\n" + + " [pc: 30, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 32] local: this index: 0 type: X\n" + + " [pc: 0, pc: 32] local: b index: 1 type: boolean\n" + + " [pc: 2, pc: 11] local: i index: 2 type: int\n" + + " [pc: 12, pc: 21] local: e index: 2 type: java.lang.Exception\n"; + } else { + expectedOutput = " // Method descriptor #15 (Z)V\n" + + " // Stack: 2, Locals: 4\n" + + " public void foo(boolean b);\n" + + " 0 iconst_0\n" + + " 1 istore_2 [i]\n" + + " 2 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 5 ldc [22]\n" + + " 7 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 10 return\n" + + " 11 astore_2 [e]\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 15 ldc [22]\n" + + " 17 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 20 return\n" + + " 21 astore_3\n" + + " 22 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 25 ldc [22]\n" + + " 27 invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]\n" + + " 30 aload_3\n" + + " 31 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 2] -> 11 when : java.lang.Exception\n" + + " [pc: 0, pc: 2] -> 21 when : any\n" + + " [pc: 11, pc: 12] -> 21 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 2, line: 9]\n" + + " [pc: 10, line: 5]\n" + + " [pc: 11, line: 6]\n" + + " [pc: 12, line: 9]\n" + + " [pc: 20, line: 7]\n" + + " [pc: 21, line: 8]\n" + + " [pc: 22, line: 9]\n" + + " [pc: 30, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 32] local: this index: 0 type: X\n" + + " [pc: 0, pc: 32] local: b index: 1 type: boolean\n" + + " [pc: 2, pc: 11] local: i index: 2 type: int\n" + + " [pc: 12, pc: 21] local: e index: 2 type: java.lang.Exception\n" + + " Stack map table: number of frames 2\n" + + " [pc: 11, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 21, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n"; + } + } + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128705 - variation +public void test042() throws Exception { + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(args));\n" + + " }\n" + + " String foo(String[] args) {\n" + + " try {\n" + + " if (args == null) return \"KO\";\n" + + " switch(args.length) {\n" + + " case 0:\n" + + " return \"OK\";\n" + + " case 1:\n" + + " return \"KO\";\n" + + " case 3:\n" + + " return \"OK\";\n" + + " default:\n" + + " return \"KO\";\n" + + " }\n" + + " } finally {\n" + + " System.out.print(\"FINALLY:\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "FINALLY:OK"); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).inlineJsrBytecode + ? " // Method descriptor #26 ([Ljava/lang/String;)Ljava/lang/String;\n" + + " // Stack: 2, Locals: 3\n" + + " java.lang.String foo(java.lang.String[] args);\n" + + " 0 aload_1 [args]\n" + + " 1 ifnonnull 15\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 7 ldc [35]\n" + + " 9 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 12 ldc [40]\n" + + " 14 areturn\n" + + " 15 aload_1 [args]\n" + + " 16 arraylength\n" + + " 17 tableswitch default: 65\n" + + " case 0: 48\n" + + " case 1: 59\n" + + " case 2: 65\n" + + " case 3: 62\n" + + " 48 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 51 ldc [35]\n" + + " 53 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 56 ldc [42]\n" + + " 58 areturn\n" + + " 59 goto 4\n" + + " 62 goto 48\n" + + " 65 goto 4\n" + + " 68 astore_2\n" + + " 69 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 72 ldc [35]\n" + + " 74 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 77 aload_2\n" + + " 78 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 4] -> 68 when : any\n" + + " [pc: 15, pc: 48] -> 68 when : any\n" + + " [pc: 59, pc: 68] -> 68 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 4, line: 19]\n" + + " [pc: 12, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 48, line: 19]\n" + + " [pc: 56, line: 10]\n" + + " [pc: 59, line: 12]\n" + + " [pc: 62, line: 14]\n" + + " [pc: 65, line: 16]\n" + + " [pc: 68, line: 18]\n" + + " [pc: 69, line: 19]\n" + + " [pc: 77, line: 20]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 79] local: this index: 0 type: X\n" + + " [pc: 0, pc: 79] local: args index: 1 type: java.lang.String[]\n" + : " // Method descriptor #26 ([Ljava/lang/String;)Ljava/lang/String;\n" + + " // Stack: 2, Locals: 4\n" + + " java.lang.String foo(java.lang.String[] args);\n" + + " 0 aload_1 [args]\n" + + " 1 ifnonnull 10\n" + + " 4 jsr 65\n" + + " 7 ldc [35]\n" + + " 9 areturn\n" + + " 10 aload_1 [args]\n" + + " 11 arraylength\n" + + " 12 tableswitch default: 56\n" + + " case 0: 44\n" + + " case 1: 50\n" + + " case 2: 56\n" + + " case 3: 53\n" + + " 44 jsr 65\n" + + " 47 ldc [37]\n" + + " 49 areturn\n" + + " 50 goto 4\n" + + " 53 goto 44\n" + + " 56 goto 4\n" + + " 59 astore_3\n" + + " 60 jsr 65\n" + + " 63 aload_3\n" + + " 64 athrow\n" + + " 65 astore_2\n" + + " 66 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 69 ldc [39]\n" + + " 71 invokevirtual java.io.PrintStream.print(java.lang.String) : void [41]\n" + + " 74 ret 2\n" + + " Exception Table:\n" + + " [pc: 0, pc: 7] -> 59 when : any\n" + + " [pc: 10, pc: 47] -> 59 when : any\n" + + " [pc: 50, pc: 59] -> 59 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 10, line: 8]\n" + + " [pc: 44, line: 10]\n" + + " [pc: 50, line: 12]\n" + + " [pc: 53, line: 14]\n" + + " [pc: 56, line: 16]\n" + + " [pc: 59, line: 18]\n" + + " [pc: 63, line: 20]\n" + + " [pc: 65, line: 18]\n" + + " [pc: 66, line: 19]\n" + + " [pc: 74, line: 20]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 76] local: this index: 0 type: X\n" + + " [pc: 0, pc: 76] local: args index: 1 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=404146 - variation without sharing of inlined escaping finally-blocks +public void test042_not_shared() throws Exception { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ShareCommonFinallyBlocks, CompilerOptions.DISABLED); + customOptions.put(CompilerOptions.OPTION_InlineJsr, CompilerOptions.ENABLED); + + this.runConformTest( + new String[] { + "X.java", + " public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().foo(args));\n" + + " }\n" + + " String foo(String[] args) {\n" + + " try {\n" + + " if (args == null) return \"KO\";\n" + + " switch(args.length) {\n" + + " case 0:\n" + + " return \"OK\";\n" + + " case 1:\n" + + " return \"KO\";\n" + + " case 3:\n" + + " return \"OK\";\n" + + " default:\n" + + " return \"KO\";\n" + + " }\n" + + " } finally {\n" + + " System.out.print(\"FINALLY:\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "FINALLY:OK", + null, + true, + null, + customOptions, + null); + + String expectedOutput = + " // Method descriptor #26 ([Ljava/lang/String;)Ljava/lang/String;\n" + + " // Stack: 2, Locals: 3\n" + + " java.lang.String foo(java.lang.String[] args);\n" + + " 0 aload_1 [args]\n" + + " 1 ifnonnull 15\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 7 ldc [35]\n" + + " 9 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 12 ldc [40]\n" + + " 14 areturn\n" + + " 15 aload_1 [args]\n" + + " 16 arraylength\n" + + " 17 tableswitch default: 81\n" + + " case 0: 48\n" + + " case 1: 59\n" + + " case 2: 81\n" + + " case 3: 70\n" + + " 48 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 51 ldc [35]\n" + + " 53 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 56 ldc [42]\n" + + " 58 areturn\n" + + " 59 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 62 ldc [35]\n" + + " 64 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 67 ldc [40]\n" + + " 69 areturn\n" + + " 70 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 73 ldc [35]\n" + + " 75 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 78 ldc [42]\n" + + " 80 areturn\n" + + " 81 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 84 ldc [35]\n" + + " 86 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 89 ldc [40]\n" + + " 91 areturn\n" + + " 92 astore_2\n" + + " 93 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 96 ldc [35]\n" + + " 98 invokevirtual java.io.PrintStream.print(java.lang.String) : void [37]\n" + + " 101 aload_2\n" + + " 102 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 4] -> 92 when : any\n" + + " [pc: 15, pc: 48] -> 92 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 4, line: 19]\n" + + " [pc: 12, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 48, line: 19]\n" + + " [pc: 56, line: 10]\n" + + " [pc: 59, line: 19]\n" + + " [pc: 67, line: 12]\n" + + " [pc: 70, line: 19]\n" + + " [pc: 78, line: 14]\n" + + " [pc: 81, line: 19]\n" + + " [pc: 89, line: 16]\n" + + " [pc: 92, line: 18]\n" + + " [pc: 93, line: 19]\n" + + " [pc: 101, line: 20]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 103] local: this index: 0 type: X\n" + + " [pc: 0, pc: 103] local: args index: 1 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} + + + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=128705 - variation +public void test043() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void save() {\n" + + " int a = 3;\n" + + " try {\n" + + " Object warnings = null;\n" + + " Object contexts = null;\n" + + " try {\n" + + " System.out.print(warnings);\n" + + " return;\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.print(contexts);\n" + + " return;\n" + + " } finally {\n" + + " System.out.print(\"#inner -> \" + a);\n" + + " }\n" + + " } catch (Exception e) {\n" + + " return;\n" + + " } finally {\n" + + " int var = 0;\n" + + " System.out.println(\"#save -> \" + a);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().save();\n" + + " }\n" + + "}\n", + }, + "null#inner -> 3#save -> 3"); + + CompilerOptions compilerOptions = new CompilerOptions(getCompilerOptions()); + String expectedOutput = !compilerOptions.inlineJsrBytecode + ? " // Method descriptor #6 ()V\n" + + " // Stack: 4, Locals: 10\n" + + " public void save();\n" + + " 0 iconst_3\n" + + " 1 istore_1 [a]\n" + + " 2 aconst_null\n" + + " 3 astore_2 [warnings]\n" + + " 4 aconst_null\n" + + " 5 astore_3 [contexts]\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 9 aload_2 [warnings]\n" + + " 10 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [21]\n" + + " 13 jsr 40\n" + + " 16 jsr 78\n" + + " 19 return\n" + + " 20 astore 4 [npe]\n" + + " 22 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 25 aload_3 [contexts]\n" + + " 26 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [21]\n" + + " 29 goto 13\n" + + " 32 astore 6\n" + + " 34 jsr 40\n" + + " 37 aload 6\n" + + " 39 athrow\n" + + " 40 astore 5\n" + + " 42 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 45 new java.lang.StringBuffer [27]\n" + + " 48 dup\n" + + " 49 ldc \"> [29]\n" + + " 51 invokespecial java.lang.StringBuffer(java.lang.String) [31]\n" + + " 54 iload_1 [a]\n" + + " 55 invokevirtual java.lang.StringBuffer.append(int) : java.lang.StringBuffer [34]\n" + + " 58 invokevirtual java.lang.StringBuffer.toString() : java.lang.String [38]\n" + + " 61 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 64 ret 5\n" + + " 66 astore_2 [e]\n" + + " 67 goto 16\n" + + " 70 astore 8\n" + + " 72 jsr 78\n" + + " 75 aload 8\n" + + " 77 athrow\n" + + " 78 astore 7\n" + + " 80 iconst_0\n" + + " 81 istore 9 [var]\n" + + " 83 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 86 new java.lang.StringBuffer [27]\n" + + " 89 dup\n" + + " 90 ldc \"> [44]\n" + + " 92 invokespecial java.lang.StringBuffer(java.lang.String) [31]\n" + + " 95 iload_1 [a]\n" + + " 96 invokevirtual java.lang.StringBuffer.append(int) : java.lang.StringBuffer [34]\n" + + " 99 invokevirtual java.lang.StringBuffer.toString() : java.lang.String [38]\n" + + " 102 invokevirtual java.io.PrintStream.println(java.lang.String) : void [46]\n" + + " 105 ret 7\n" + + " Exception Table:\n" + + " [pc: 6, pc: 16] -> 20 when : java.lang.NullPointerException\n" + + " [pc: 6, pc: 16] -> 32 when : any\n" + + " [pc: 20, pc: 32] -> 32 when : any\n" + + " [pc: 2, pc: 19] -> 66 when : java.lang.Exception\n" + + " [pc: 20, pc: 66] -> 66 when : java.lang.Exception\n" + + " [pc: 2, pc: 19] -> 70 when : any\n" + + " [pc: 20, pc: 70] -> 70 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 4, line: 6]\n" + + " [pc: 6, line: 8]\n" + + " [pc: 13, line: 9]\n" + + " [pc: 20, line: 10]\n" + + " [pc: 22, line: 11]\n" + + " [pc: 29, line: 12]\n" + + " [pc: 32, line: 13]\n" + + " [pc: 37, line: 15]\n" + + " [pc: 40, line: 13]\n" + + " [pc: 42, line: 14]\n" + + " [pc: 64, line: 15]\n" + + " [pc: 66, line: 16]\n" + + " [pc: 67, line: 17]\n" + + " [pc: 70, line: 18]\n" + + " [pc: 75, line: 21]\n" + + " [pc: 78, line: 18]\n" + + " [pc: 80, line: 19]\n" + + " [pc: 83, line: 20]\n" + + " [pc: 105, line: 21]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 107] local: this index: 0 type: X\n" + + " [pc: 2, pc: 107] local: a index: 1 type: int\n" + + " [pc: 4, pc: 66] local: warnings index: 2 type: java.lang.Object\n" + + " [pc: 6, pc: 66] local: contexts index: 3 type: java.lang.Object\n" + + " [pc: 22, pc: 32] local: npe index: 4 type: java.lang.NullPointerException\n" + + " [pc: 67, pc: 70] local: e index: 2 type: java.lang.Exception\n" + + " [pc: 83, pc: 105] local: var index: 9 type: int\n" + : null; + + if (expectedOutput == null) { + if (compilerOptions.targetJDK == ClassFileConstants.JDK1_5) { + expectedOutput = " // Method descriptor #6 ()V\n" + + " // Stack: 4, Locals: 8\n" + + " public void save();\n" + + " 0 iconst_3\n" + + " 1 istore_1 [a]\n" + + " 2 aconst_null\n" + + " 3 astore_2 [warnings]\n" + + " 4 aconst_null\n" + + " 5 astore_3 [contexts]\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 9 aload_2 [warnings]\n" + + " 10 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [21]\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 16 new java.lang.StringBuilder [27]\n" + + " 19 dup\n" + + " 20 ldc \"> [29]\n" + + " 22 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 25 iload_1 [a]\n" + + " 26 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 29 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 32 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 35 iconst_0\n" + + " 36 istore 7 [var]\n" + + " 38 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 41 new java.lang.StringBuilder [27]\n" + + " 44 dup\n" + + " 45 ldc \"> [44]\n" + + " 47 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 50 iload_1 [a]\n" + + " 51 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 54 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 57 invokevirtual java.io.PrintStream.println(java.lang.String) : void [46]\n" + + " 60 return\n" + + " 61 astore 4 [npe]\n" + + " 63 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 66 aload_3 [contexts]\n" + + " 67 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [21]\n" + + " 70 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 73 new java.lang.StringBuilder [27]\n" + + " 76 dup\n" + + " 77 ldc \"> [29]\n" + + " 79 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 82 iload_1 [a]\n" + + " 83 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 86 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 89 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 92 iconst_0\n" + + " 93 istore 7 [var]\n" + + " 95 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 98 new java.lang.StringBuilder [27]\n" + + " 101 dup\n" + + " 102 ldc \"> [44]\n" + + " 104 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 107 iload_1 [a]\n" + + " 108 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 111 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 114 invokevirtual java.io.PrintStream.println(java.lang.String) : void [46]\n" + + " 117 return\n" + + " 118 astore 5\n" + + " 120 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 123 new java.lang.StringBuilder [27]\n" + + " 126 dup\n" + + " 127 ldc \"> [29]\n" + + " 129 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 132 iload_1 [a]\n" + + " 133 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 136 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 139 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 142 aload 5\n" + + " 144 athrow\n" + + " 145 astore_2 [e]\n" + + " 146 iconst_0\n" + + " 147 istore 7 [var]\n" + + " 149 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 152 new java.lang.StringBuilder [27]\n" + + " 155 dup\n" + + " 156 ldc \"> [44]\n" + + " 158 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 161 iload_1 [a]\n" + + " 162 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 165 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 168 invokevirtual java.io.PrintStream.println(java.lang.String) : void [46]\n" + + " 171 return\n" + + " 172 astore 6\n" + + " 174 iconst_0\n" + + " 175 istore 7 [var]\n" + + " 177 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 180 new java.lang.StringBuilder [27]\n" + + " 183 dup\n" + + " 184 ldc \"> [44]\n" + + " 186 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 189 iload_1 [a]\n" + + " 190 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 193 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 196 invokevirtual java.io.PrintStream.println(java.lang.String) : void [46]\n" + + " 199 aload 6\n" + + " 201 athrow\n" + + " Exception Table:\n" + + " [pc: 6, pc: 13] -> 61 when : java.lang.NullPointerException\n" + + " [pc: 6, pc: 13] -> 118 when : any\n" + + " [pc: 61, pc: 70] -> 118 when : any\n" + + " [pc: 2, pc: 35] -> 145 when : java.lang.Exception\n" + + " [pc: 61, pc: 92] -> 145 when : java.lang.Exception\n" + + " [pc: 118, pc: 145] -> 145 when : java.lang.Exception\n" + + " [pc: 2, pc: 35] -> 172 when : any\n" + + " [pc: 61, pc: 92] -> 172 when : any\n" + + " [pc: 118, pc: 146] -> 172 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 4, line: 6]\n" + + " [pc: 6, line: 8]\n" + + " [pc: 13, line: 14]\n" + + " [pc: 35, line: 19]\n" + + " [pc: 38, line: 20]\n" + + " [pc: 60, line: 9]\n" + + " [pc: 61, line: 10]\n" + + " [pc: 63, line: 11]\n" + + " [pc: 70, line: 14]\n" + + " [pc: 92, line: 19]\n" + + " [pc: 95, line: 20]\n" + + " [pc: 117, line: 12]\n" + + " [pc: 118, line: 13]\n" + + " [pc: 120, line: 14]\n" + + " [pc: 142, line: 15]\n" + + " [pc: 145, line: 16]\n" + + " [pc: 146, line: 19]\n" + + " [pc: 149, line: 20]\n" + + " [pc: 171, line: 17]\n" + + " [pc: 172, line: 18]\n" + + " [pc: 174, line: 19]\n" + + " [pc: 177, line: 20]\n" + + " [pc: 199, line: 21]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 202] local: this index: 0 type: X\n" + + " [pc: 2, pc: 202] local: a index: 1 type: int\n" + + " [pc: 4, pc: 145] local: warnings index: 2 type: java.lang.Object\n" + + " [pc: 6, pc: 145] local: contexts index: 3 type: java.lang.Object\n" + + " [pc: 63, pc: 118] local: npe index: 4 type: java.lang.NullPointerException\n" + + " [pc: 146, pc: 172] local: e index: 2 type: java.lang.Exception\n" + + " [pc: 38, pc: 60] local: var index: 7 type: int\n" + + " [pc: 95, pc: 117] local: var index: 7 type: int\n" + + " [pc: 149, pc: 171] local: var index: 7 type: int\n" + + " [pc: 177, pc: 199] local: var index: 7 type: int\n"; + } else { + expectedOutput = " // Method descriptor #6 ()V\n" + + " // Stack: 4, Locals: 8\n" + + " public void save();\n" + + " 0 iconst_3\n" + + " 1 istore_1 [a]\n" + + " 2 aconst_null\n" + + " 3 astore_2 [warnings]\n" + + " 4 aconst_null\n" + + " 5 astore_3 [contexts]\n" + + " 6 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 9 aload_2 [warnings]\n" + + " 10 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [21]\n" + + " 13 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 16 new java.lang.StringBuilder [27]\n" + + " 19 dup\n" + + " 20 ldc \"> [29]\n" + + " 22 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 25 iload_1 [a]\n" + + " 26 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 29 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 32 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 35 iconst_0\n" + + " 36 istore 7 [var]\n" + + " 38 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 41 new java.lang.StringBuilder [27]\n" + + " 44 dup\n" + + " 45 ldc \"> [44]\n" + + " 47 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 50 iload_1 [a]\n" + + " 51 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 54 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 57 invokevirtual java.io.PrintStream.println(java.lang.String) : void [46]\n" + + " 60 return\n" + + " 61 astore 4 [npe]\n" + + " 63 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 66 aload_3 [contexts]\n" + + " 67 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [21]\n" + + " 70 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 73 new java.lang.StringBuilder [27]\n" + + " 76 dup\n" + + " 77 ldc \"> [29]\n" + + " 79 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 82 iload_1 [a]\n" + + " 83 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 86 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 89 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 92 iconst_0\n" + + " 93 istore 7 [var]\n" + + " 95 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 98 new java.lang.StringBuilder [27]\n" + + " 101 dup\n" + + " 102 ldc \"> [44]\n" + + " 104 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 107 iload_1 [a]\n" + + " 108 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 111 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 114 invokevirtual java.io.PrintStream.println(java.lang.String) : void [46]\n" + + " 117 return\n" + + " 118 astore 5\n" + + " 120 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 123 new java.lang.StringBuilder [27]\n" + + " 126 dup\n" + + " 127 ldc \"> [29]\n" + + " 129 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 132 iload_1 [a]\n" + + " 133 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 136 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 139 invokevirtual java.io.PrintStream.print(java.lang.String) : void [42]\n" + + " 142 aload 5\n" + + " 144 athrow\n" + + " 145 astore_2 [e]\n" + + " 146 iconst_0\n" + + " 147 istore 7 [var]\n" + + " 149 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 152 new java.lang.StringBuilder [27]\n" + + " 155 dup\n" + + " 156 ldc \"> [44]\n" + + " 158 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 161 iload_1 [a]\n" + + " 162 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 165 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 168 invokevirtual java.io.PrintStream.println(java.lang.String) : void [46]\n" + + " 171 return\n" + + " 172 astore 6\n" + + " 174 iconst_0\n" + + " 175 istore 7 [var]\n" + + " 177 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 180 new java.lang.StringBuilder [27]\n" + + " 183 dup\n" + + " 184 ldc \"> [44]\n" + + " 186 invokespecial java.lang.StringBuilder(java.lang.String) [31]\n" + + " 189 iload_1 [a]\n" + + " 190 invokevirtual java.lang.StringBuilder.append(int) : java.lang.StringBuilder [34]\n" + + " 193 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [38]\n" + + " 196 invokevirtual java.io.PrintStream.println(java.lang.String) : void [46]\n" + + " 199 aload 6\n" + + " 201 athrow\n" + + " Exception Table:\n" + + " [pc: 6, pc: 13] -> 61 when : java.lang.NullPointerException\n" + + " [pc: 6, pc: 13] -> 118 when : any\n" + + " [pc: 61, pc: 70] -> 118 when : any\n" + + " [pc: 2, pc: 35] -> 145 when : java.lang.Exception\n" + + " [pc: 61, pc: 92] -> 145 when : java.lang.Exception\n" + + " [pc: 118, pc: 145] -> 145 when : java.lang.Exception\n" + + " [pc: 2, pc: 35] -> 172 when : any\n" + + " [pc: 61, pc: 92] -> 172 when : any\n" + + " [pc: 118, pc: 146] -> 172 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 3]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 4, line: 6]\n" + + " [pc: 6, line: 8]\n" + + " [pc: 13, line: 14]\n" + + " [pc: 35, line: 19]\n" + + " [pc: 38, line: 20]\n" + + " [pc: 60, line: 9]\n" + + " [pc: 61, line: 10]\n" + + " [pc: 63, line: 11]\n" + + " [pc: 70, line: 14]\n" + + " [pc: 92, line: 19]\n" + + " [pc: 95, line: 20]\n" + + " [pc: 117, line: 12]\n" + + " [pc: 118, line: 13]\n" + + " [pc: 120, line: 14]\n" + + " [pc: 142, line: 15]\n" + + " [pc: 145, line: 16]\n" + + " [pc: 146, line: 19]\n" + + " [pc: 149, line: 20]\n" + + " [pc: 171, line: 17]\n" + + " [pc: 172, line: 18]\n" + + " [pc: 174, line: 19]\n" + + " [pc: 177, line: 20]\n" + + " [pc: 199, line: 21]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 202] local: this index: 0 type: X\n" + + " [pc: 2, pc: 202] local: a index: 1 type: int\n" + + " [pc: 4, pc: 145] local: warnings index: 2 type: java.lang.Object\n" + + " [pc: 6, pc: 145] local: contexts index: 3 type: java.lang.Object\n" + + " [pc: 63, pc: 118] local: npe index: 4 type: java.lang.NullPointerException\n" + + " [pc: 146, pc: 172] local: e index: 2 type: java.lang.Exception\n" + + " [pc: 38, pc: 60] local: var index: 7 type: int\n" + + " [pc: 95, pc: 117] local: var index: 7 type: int\n" + + " [pc: 149, pc: 171] local: var index: 7 type: int\n" + + " [pc: 177, pc: 199] local: var index: 7 type: int\n" + + " Stack map table: number of frames 4\n" + + " [pc: 61, full, stack: {java.lang.NullPointerException}, locals: {X, int, java.lang.Object, java.lang.Object}]\n" + + " [pc: 118, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n" + + " [pc: 145, full, stack: {java.lang.Exception}, locals: {X, int}]\n" + + " [pc: 172, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n"; + } + } + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129305 +public void test044() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " foo();\n" + + " } \n" + + " static Object foo() {\n" + + " try {\n" + + " return null;\n" + + " } catch(Exception e) {\n" + + " return null;\n" + + " } finally {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + CompilerOptions compilerOptions = new CompilerOptions(getCompilerOptions()); + String expectedOutput = !compilerOptions.inlineJsrBytecode ? + " // Method descriptor #19 ()Ljava/lang/Object;\n" + + " // Stack: 2, Locals: 3\n" + + " static java.lang.Object foo();\n" + + " 0 jsr 15\n" + + " 3 aconst_null\n" + + " 4 areturn\n" + + " 5 astore_0 [e]\n" + + " 6 goto 0\n" + + " 9 astore_2\n" + + " 10 jsr 15\n" + + " 13 aload_2\n" + + " 14 athrow\n" + + " 15 astore_1\n" + + " 16 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 19 ldc [28]\n" + + " 21 invokevirtual java.io.PrintStream.println(java.lang.String) : void [30]\n" + + " 24 ret 1\n" + + " Exception Table:\n" + + " [pc: 0, pc: 3] -> 5 when : java.lang.Exception\n" + + " [pc: 0, pc: 3] -> 9 when : any\n" + + " [pc: 5, pc: 9] -> 9 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 5, line: 8]\n" + + " [pc: 6, line: 9]\n" + + " [pc: 9, line: 10]\n" + + " [pc: 13, line: 12]\n" + + " [pc: 15, line: 10]\n" + + " [pc: 16, line: 11]\n" + + " [pc: 24, line: 12]\n" + + " Local variable table:\n" + + " [pc: 6, pc: 9] local: e index: 0 type: java.lang.Exception\n" + : null; + + if (expectedOutput == null) { + if (compilerOptions.targetJDK == ClassFileConstants.JDK1_5) { + expectedOutput = + " // Method descriptor #19 ()Ljava/lang/Object;\n" + + " // Stack: 2, Locals: 0\n" + + " static java.lang.Object foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 3 ldc [28]\n" + + " 5 invokevirtual java.io.PrintStream.println(java.lang.String) : void [30]\n" + + " 8 aconst_null\n" + + " 9 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " [pc: 8, line: 7]\n"; + } else { + expectedOutput = " // Method descriptor #19 ()Ljava/lang/Object;\n" + + " // Stack: 2, Locals: 0\n" + + " static java.lang.Object foo();\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [22]\n" + + " 3 ldc [28]\n" + + " 5 invokevirtual java.io.PrintStream.println(java.lang.String) : void [30]\n" + + " 8 aconst_null\n" + + " 9 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " [pc: 8, line: 7]\n"; + } + } + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=129306 +public void test045() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void save() {\n" + + " try {\n" + + " Object warnings = null;\n" + + " Object contexts = null;\n" + + " try {\n" + + " System.out.print(\"[try]\");\n" + + " System.out.print(warnings); \n" + + " return;\n" + + " } catch (NullPointerException npe) {\n" + + " System.out.print(\"[npe]\");\n" + + " System.out.print(contexts); \n" + + " return;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " System.out.print(\"[e]\");\n" + + " return;\n" + + " } finally { \n" + + " int var = 0;\n" + + " System.out.print(\"[finally]\");\n" + + " Object o = null;\n" + + " o.toString();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " new X().save();\n" + + " } catch(NullPointerException e) {\n" + + " System.out.println(\"[caught npe]\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "[try]null[finally][caught npe]"); + + CompilerOptions compilerOptions = new CompilerOptions(getCompilerOptions()); + String expectedOutput = !compilerOptions.inlineJsrBytecode + ? " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 8\n" + + " public void save();\n" + + " 0 aconst_null\n" + + " 1 astore_1 [warnings]\n" + + " 2 aconst_null\n" + + " 3 astore_2 [contexts]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 7 ldc [21]\n" + + " 9 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 15 aload_1 [warnings]\n" + + " 16 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [29]\n" + + " 19 jsr 62\n" + + " 22 return\n" + + " 23 astore_3 [npe]\n" + + " 24 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 27 ldc [32]\n" + + " 29 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 32 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 35 aload_2 [contexts]\n" + + " 36 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [29]\n" + + " 39 goto 19\n" + + " 42 astore_1 [e]\n" + + " 43 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 46 ldc [34]\n" + + " 48 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 51 goto 19\n" + + " 54 astore 5\n" + + " 56 jsr 62\n" + + " 59 aload 5\n" + + " 61 athrow\n" + + " 62 astore 4\n" + + " 64 iconst_0\n" + + " 65 istore 6 [var]\n" + + " 67 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 70 ldc [36]\n" + + " 72 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 75 aconst_null\n" + + " 76 astore 7 [o]\n" + + " 78 aload 7 [o]\n" + + " 80 invokevirtual java.lang.Object.toString() : java.lang.String [38]\n" + + " 83 pop\n" + + " 84 ret 4\n" + + " Exception Table:\n" + + " [pc: 4, pc: 19] -> 23 when : java.lang.NullPointerException\n" + + " [pc: 0, pc: 22] -> 42 when : java.lang.Exception\n" + + " [pc: 23, pc: 42] -> 42 when : java.lang.Exception\n" + + " [pc: 0, pc: 22] -> 54 when : any\n" + + " [pc: 23, pc: 54] -> 54 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 4, line: 7]\n" + + " [pc: 12, line: 8]\n" + + " [pc: 19, line: 9]\n" + + " [pc: 23, line: 10]\n" + + " [pc: 24, line: 11]\n" + + " [pc: 32, line: 12]\n" + + " [pc: 39, line: 13]\n" + + " [pc: 42, line: 15]\n" + + " [pc: 43, line: 16]\n" + + " [pc: 51, line: 17]\n" + + " [pc: 54, line: 18]\n" + + " [pc: 59, line: 23]\n" + + " [pc: 62, line: 18]\n" + + " [pc: 64, line: 19]\n" + + " [pc: 67, line: 20]\n" + + " [pc: 75, line: 21]\n" + + " [pc: 78, line: 22]\n" + + " [pc: 84, line: 23]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 86] local: this index: 0 type: X\n" + + " [pc: 2, pc: 42] local: warnings index: 1 type: java.lang.Object\n" + + " [pc: 4, pc: 42] local: contexts index: 2 type: java.lang.Object\n" + + " [pc: 24, pc: 42] local: npe index: 3 type: java.lang.NullPointerException\n" + + " [pc: 43, pc: 54] local: e index: 1 type: java.lang.Exception\n" + + " [pc: 67, pc: 84] local: var index: 6 type: int\n" + + " [pc: 78, pc: 84] local: o index: 7 type: java.lang.Object\n" + : null; + + if (expectedOutput == null) { + if (compilerOptions.targetJDK == ClassFileConstants.JDK1_5) { + expectedOutput = " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 7\n" + + " public void save();\n" + + " 0 aconst_null\n" + + " 1 astore_1 [warnings]\n" + + " 2 aconst_null\n" + + " 3 astore_2 [contexts]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 7 ldc [21]\n" + + " 9 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 15 aload_1 [warnings]\n" + + " 16 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [29]\n" + + " 19 iconst_0\n" + + " 20 istore 5 [var]\n" + + " 22 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 25 ldc [32]\n" + + " 27 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 30 aconst_null\n" + + " 31 astore 6 [o]\n" + + " 33 aload 6 [o]\n" + + " 35 invokevirtual java.lang.Object.toString() : java.lang.String [34]\n" + + " 38 pop\n" + + " 39 return\n" + + " 40 astore_3 [npe]\n" + + " 41 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 44 ldc [38]\n" + + " 46 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 49 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 52 aload_2 [contexts]\n" + + " 53 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [29]\n" + + " 56 iconst_0\n" + + " 57 istore 5 [var]\n" + + " 59 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 62 ldc [32]\n" + + " 64 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 67 aconst_null\n" + + " 68 astore 6 [o]\n" + + " 70 aload 6 [o]\n" + + " 72 invokevirtual java.lang.Object.toString() : java.lang.String [34]\n" + + " 75 pop\n" + + " 76 return\n" + + " 77 astore_1 [e]\n" + + " 78 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 81 ldc [40]\n" + + " 83 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 86 iconst_0\n" + + " 87 istore 5 [var]\n" + + " 89 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 92 ldc [32]\n" + + " 94 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 97 aconst_null\n" + + " 98 astore 6 [o]\n" + + " 100 aload 6 [o]\n" + + " 102 invokevirtual java.lang.Object.toString() : java.lang.String [34]\n" + + " 105 pop\n" + + " 106 return\n" + + " 107 astore 4\n" + + " 109 iconst_0\n" + + " 110 istore 5 [var]\n" + + " 112 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 115 ldc [32]\n" + + " 117 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 120 aconst_null\n" + + " 121 astore 6 [o]\n" + + " 123 aload 6 [o]\n" + + " 125 invokevirtual java.lang.Object.toString() : java.lang.String [34]\n" + + " 128 pop\n" + + " 129 aload 4\n" + + " 131 athrow\n" + + " Exception Table:\n" + + " [pc: 4, pc: 19] -> 40 when : java.lang.NullPointerException\n" + + " [pc: 0, pc: 19] -> 77 when : java.lang.Exception\n" + + " [pc: 40, pc: 56] -> 77 when : java.lang.Exception\n" + + " [pc: 0, pc: 19] -> 107 when : any\n" + + " [pc: 40, pc: 56] -> 107 when : any\n" + + " [pc: 77, pc: 86] -> 107 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 4, line: 7]\n" + + " [pc: 12, line: 8]\n" + + " [pc: 19, line: 19]\n" + + " [pc: 22, line: 20]\n" + + " [pc: 30, line: 21]\n" + + " [pc: 33, line: 22]\n" + + " [pc: 39, line: 9]\n" + + " [pc: 40, line: 10]\n" + + " [pc: 41, line: 11]\n" + + " [pc: 49, line: 12]\n" + + " [pc: 56, line: 19]\n" + + " [pc: 59, line: 20]\n" + + " [pc: 67, line: 21]\n" + + " [pc: 70, line: 22]\n" + + " [pc: 76, line: 13]\n" + + " [pc: 77, line: 15]\n" + + " [pc: 78, line: 16]\n" + + " [pc: 86, line: 19]\n" + + " [pc: 89, line: 20]\n" + + " [pc: 97, line: 21]\n" + + " [pc: 100, line: 22]\n" + + " [pc: 106, line: 17]\n" + + " [pc: 107, line: 18]\n" + + " [pc: 109, line: 19]\n" + + " [pc: 112, line: 20]\n" + + " [pc: 120, line: 21]\n" + + " [pc: 123, line: 22]\n" + + " [pc: 129, line: 23]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 132] local: this index: 0 type: X\n" + + " [pc: 2, pc: 77] local: warnings index: 1 type: java.lang.Object\n" + + " [pc: 4, pc: 77] local: contexts index: 2 type: java.lang.Object\n" + + " [pc: 41, pc: 77] local: npe index: 3 type: java.lang.NullPointerException\n" + + " [pc: 78, pc: 107] local: e index: 1 type: java.lang.Exception\n" + + " [pc: 22, pc: 39] local: var index: 5 type: int\n" + + " [pc: 59, pc: 76] local: var index: 5 type: int\n" + + " [pc: 89, pc: 106] local: var index: 5 type: int\n" + + " [pc: 112, pc: 129] local: var index: 5 type: int\n" + + " [pc: 33, pc: 39] local: o index: 6 type: java.lang.Object\n" + + " [pc: 70, pc: 76] local: o index: 6 type: java.lang.Object\n" + + " [pc: 100, pc: 106] local: o index: 6 type: java.lang.Object\n" + + " [pc: 123, pc: 129] local: o index: 6 type: java.lang.Object\n"; + } else { + expectedOutput = " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 7\n" + + " public void save();\n" + + " 0 aconst_null\n" + + " 1 astore_1 [warnings]\n" + + " 2 aconst_null\n" + + " 3 astore_2 [contexts]\n" + + " 4 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 7 ldc [21]\n" + + " 9 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 15 aload_1 [warnings]\n" + + " 16 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [29]\n" + + " 19 iconst_0\n" + + " 20 istore 5 [var]\n" + + " 22 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 25 ldc [32]\n" + + " 27 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 30 aconst_null\n" + + " 31 astore 6 [o]\n" + + " 33 aload 6 [o]\n" + + " 35 invokevirtual java.lang.Object.toString() : java.lang.String [34]\n" + + " 38 pop\n" + + " 39 return\n" + + " 40 astore_3 [npe]\n" + + " 41 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 44 ldc [38]\n" + + " 46 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 49 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 52 aload_2 [contexts]\n" + + " 53 invokevirtual java.io.PrintStream.print(java.lang.Object) : void [29]\n" + + " 56 iconst_0\n" + + " 57 istore 5 [var]\n" + + " 59 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 62 ldc [32]\n" + + " 64 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 67 aconst_null\n" + + " 68 astore 6 [o]\n" + + " 70 aload 6 [o]\n" + + " 72 invokevirtual java.lang.Object.toString() : java.lang.String [34]\n" + + " 75 pop\n" + + " 76 return\n" + + " 77 astore_1 [e]\n" + + " 78 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 81 ldc [40]\n" + + " 83 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 86 iconst_0\n" + + " 87 istore 5 [var]\n" + + " 89 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 92 ldc [32]\n" + + " 94 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 97 aconst_null\n" + + " 98 astore 6 [o]\n" + + " 100 aload 6 [o]\n" + + " 102 invokevirtual java.lang.Object.toString() : java.lang.String [34]\n" + + " 105 pop\n" + + " 106 return\n" + + " 107 astore 4\n" + + " 109 iconst_0\n" + + " 110 istore 5 [var]\n" + + " 112 getstatic java.lang.System.out : java.io.PrintStream [15]\n" + + " 115 ldc [32]\n" + + " 117 invokevirtual java.io.PrintStream.print(java.lang.String) : void [23]\n" + + " 120 aconst_null\n" + + " 121 astore 6 [o]\n" + + " 123 aload 6 [o]\n" + + " 125 invokevirtual java.lang.Object.toString() : java.lang.String [34]\n" + + " 128 pop\n" + + " 129 aload 4\n" + + " 131 athrow\n" + + " Exception Table:\n" + + " [pc: 4, pc: 19] -> 40 when : java.lang.NullPointerException\n" + + " [pc: 0, pc: 19] -> 77 when : java.lang.Exception\n" + + " [pc: 40, pc: 56] -> 77 when : java.lang.Exception\n" + + " [pc: 0, pc: 19] -> 107 when : any\n" + + " [pc: 40, pc: 56] -> 107 when : any\n" + + " [pc: 77, pc: 86] -> 107 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 4, line: 7]\n" + + " [pc: 12, line: 8]\n" + + " [pc: 19, line: 19]\n" + + " [pc: 22, line: 20]\n" + + " [pc: 30, line: 21]\n" + + " [pc: 33, line: 22]\n" + + " [pc: 39, line: 9]\n" + + " [pc: 40, line: 10]\n" + + " [pc: 41, line: 11]\n" + + " [pc: 49, line: 12]\n" + + " [pc: 56, line: 19]\n" + + " [pc: 59, line: 20]\n" + + " [pc: 67, line: 21]\n" + + " [pc: 70, line: 22]\n" + + " [pc: 76, line: 13]\n" + + " [pc: 77, line: 15]\n" + + " [pc: 78, line: 16]\n" + + " [pc: 86, line: 19]\n" + + " [pc: 89, line: 20]\n" + + " [pc: 97, line: 21]\n" + + " [pc: 100, line: 22]\n" + + " [pc: 106, line: 17]\n" + + " [pc: 107, line: 18]\n" + + " [pc: 109, line: 19]\n" + + " [pc: 112, line: 20]\n" + + " [pc: 120, line: 21]\n" + + " [pc: 123, line: 22]\n" + + " [pc: 129, line: 23]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 132] local: this index: 0 type: X\n" + + " [pc: 2, pc: 77] local: warnings index: 1 type: java.lang.Object\n" + + " [pc: 4, pc: 77] local: contexts index: 2 type: java.lang.Object\n" + + " [pc: 41, pc: 77] local: npe index: 3 type: java.lang.NullPointerException\n" + + " [pc: 78, pc: 107] local: e index: 1 type: java.lang.Exception\n" + + " [pc: 22, pc: 39] local: var index: 5 type: int\n" + + " [pc: 59, pc: 76] local: var index: 5 type: int\n" + + " [pc: 89, pc: 106] local: var index: 5 type: int\n" + + " [pc: 112, pc: 129] local: var index: 5 type: int\n" + + " [pc: 33, pc: 39] local: o index: 6 type: java.lang.Object\n" + + " [pc: 70, pc: 76] local: o index: 6 type: java.lang.Object\n" + + " [pc: 100, pc: 106] local: o index: 6 type: java.lang.Object\n" + + " [pc: 123, pc: 129] local: o index: 6 type: java.lang.Object\n" + + " Stack map table: number of frames 3\n" + + " [pc: 40, full, stack: {java.lang.NullPointerException}, locals: {X, java.lang.Object, java.lang.Object}]\n" + + " [pc: 77, full, stack: {java.lang.Exception}, locals: {X}]\n" + + " [pc: 107, same_locals_1_stack_item, stack: {java.lang.Throwable}]\n"; + } + } + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=108180 +public void test046() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static Object sanityCheckBug() {\n" + + " Object obj;\n" + + " try {\n" + + " obj = new Object();\n" + + " return obj;\n" + + " } finally {\n" + + " obj = null;\n" + + " }\n" + + " }\n" + + " public static void main(String[] arguments) {\n" + + " X.sanityCheckBug();\n" + + " }\n" + + "}\n", + }, + ""); + + CompilerOptions compilerOptions = new CompilerOptions(getCompilerOptions()); + String expectedOutput = !compilerOptions.inlineJsrBytecode + ? " // Method descriptor #15 ()Ljava/lang/Object;\n" + + " // Stack: 2, Locals: 4\n" + + " public static java.lang.Object sanityCheckBug();\n" + + " 0 new java.lang.Object [3]\n" + + " 3 dup\n" + + " 4 invokespecial java.lang.Object() [8]\n" + + " 7 astore_0 [obj]\n" + + " 8 aload_0 [obj]\n" + + " 9 astore_3\n" + + " 10 jsr 21\n" + + " 13 aload_3\n" + + " 14 areturn\n" + + " 15 astore_2\n" + + " 16 jsr 21\n" + + " 19 aload_2\n" + + " 20 athrow\n" + + " 21 astore_1\n" + + " 22 aconst_null\n" + + " 23 astore_0 [obj]\n" + + " 24 ret 1\n" + + " Exception Table:\n" + + " [pc: 0, pc: 13] -> 15 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 15, line: 7]\n" + + " [pc: 19, line: 9]\n" + + " [pc: 21, line: 7]\n" + + " [pc: 22, line: 8]\n" + + " [pc: 24, line: 9]\n" + + " Local variable table:\n" + + " [pc: 8, pc: 15] local: obj index: 0 type: java.lang.Object\n" + + " [pc: 24, pc: 26] local: obj index: 0 type: java.lang.Object\n" + : null; + + if (expectedOutput == null) { + if (compilerOptions.targetJDK == ClassFileConstants.JDK1_5) { + expectedOutput = " // Method descriptor #15 ()Ljava/lang/Object;\n" + + " // Stack: 2, Locals: 3\n" + + " public static java.lang.Object sanityCheckBug();\n" + + " 0 new java.lang.Object [3]\n" + + " 3 dup\n" + + " 4 invokespecial java.lang.Object() [8]\n" + + " 7 astore_0 [obj]\n" + + " 8 aload_0 [obj]\n" + + " 9 astore_2\n" + + " 10 aconst_null\n" + + " 11 astore_0 [obj]\n" + + " 12 aload_2\n" + + " 13 areturn\n" + + " 14 astore_1\n" + + " 15 aconst_null\n" + + " 16 astore_0 [obj]\n" + + " 17 aload_1\n" + + " 18 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 10] -> 14 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 10, line: 8]\n" + + " [pc: 12, line: 6]\n" + + " [pc: 14, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 17, line: 9]\n" + + " Local variable table:\n" + + " [pc: 8, pc: 14] local: obj index: 0 type: java.lang.Object\n" + + " [pc: 17, pc: 19] local: obj index: 0 type: java.lang.Object\n"; + } else { + expectedOutput = " // Method descriptor #15 ()Ljava/lang/Object;\n" + + " // Stack: 2, Locals: 3\n" + + " public static java.lang.Object sanityCheckBug();\n" + + " 0 new java.lang.Object [3]\n" + + " 3 dup\n" + + " 4 invokespecial java.lang.Object() [8]\n" + + " 7 astore_0 [obj]\n" + + " 8 aload_0 [obj]\n" + + " 9 astore_2\n" + + " 10 aconst_null\n" + + " 11 astore_0 [obj]\n" + + " 12 aload_2\n" + + " 13 areturn\n" + + " 14 astore_1\n" + + " 15 aconst_null\n" + + " 16 astore_0 [obj]\n" + + " 17 aload_1\n" + + " 18 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 10] -> 14 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 10, line: 8]\n" + + " [pc: 12, line: 6]\n" + + " [pc: 14, line: 7]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 17, line: 9]\n" + + " Local variable table:\n" + + " [pc: 8, pc: 14] local: obj index: 0 type: java.lang.Object\n" + + " [pc: 17, pc: 19] local: obj index: 0 type: java.lang.Object\n"; + } + } + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void test047() { + if (new CompilerOptions(getCompilerOptions()).complianceLevel <= ClassFileConstants.JDK1_3) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " if (false) throw null;\n" + + " throw new Object();\n" + + " } catch(Object o) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " if (false) throw null;\n" + + " ^^^^\n" + + "Cannot throw null as an exception\n" + + "----------\n" + + "2. ERROR in X.java (at line 5)\n" + + " throw new Object();\n" + + " ^^^^^^^^^^^^\n" + + "No exception of type Object can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "3. ERROR in X.java (at line 6)\n" + + " } catch(Object o) {\n" + + " ^^^^^^\n" + + "No exception of type Object can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n"); + return; + } + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " if (false) throw null;\n" + + " throw new Object();\n" + + " } catch(Object o) {\n" + + " }\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " throw new Object();\n" + + " ^^^^^^^^^^^^\n" + + "No exception of type Object can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " } catch(Object o) {\n" + + " ^^^^^^\n" + + "No exception of type Object can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 +public void test048() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bool() { return true; }\n" + + " void foo() {\n" + + " try {\n" + + " if (bool()) {\n" + + " return;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + " int foo2() {\n" + + " try {\n" + + " while (bool()) {\n" + + " return 0;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " return 1;\n" + + " }\n" + + " long foo3() {\n" + + " try {\n" + + " do {\n" + + " if (true) return 0L;\n" + + " } while (bool());\n" + + " } catch (Exception e) {\n" + + " }\n" + + " return 1L;\n" + + " } \n" + + " float foo4() {\n" + + " try {\n" + + " for (int i = 0; bool(); i++) {\n" + + " return 0.0F;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " return 1.0F;\n" + + " } \n" + + " double bar() {\n" + + " if (bool()) {\n" + + " if (bool())\n" + + " return 0.0;\n" + + " } else {\n" + + " if (bool()) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " }\n" + + " return 1.0;\n" + + " }\n" + + " void baz(int i) {\n" + + " if (bool()) {\n" + + " switch(i) {\n" + + " case 0 : return;\n" + + " default : break;\n" + + " }\n" + + " } else {\n" + + " bool();\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6 + ? " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 9\n" + + " 7 return\n" + + " 8 astore_1\n" + + " 9 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 7] -> 8 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 9, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #22 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " int foo2();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 10\n" + + " 7 iconst_0\n" + + " 8 ireturn\n" + + " 9 astore_1\n" + + " 10 iconst_1\n" + + " 11 ireturn\n" + + " Exception Table:\n" + + " [pc: 0, pc: 7] -> 9 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 7, line: 14]\n" + + " [pc: 9, line: 16]\n" + + " [pc: 10, line: 18]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #24 ()J\n" + + " // Stack: 2, Locals: 1\n" + + " long foo3();\n" + + " 0 lconst_0\n" + + " 1 lreturn\n" + + " 2 lconst_1\n" + + " 3 lreturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 23]\n" + + " [pc: 2, line: 27]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #26 ()F\n" + + " // Stack: 1, Locals: 2\n" + + " float foo4();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 aload_0 [this]\n" + + " 3 invokevirtual X.bool() : boolean [17]\n" + + " 6 ifeq 12\n" + + " 9 fconst_0\n" + + " 10 freturn\n" + + " 11 astore_1\n" + + " 12 fconst_1\n" + + " 13 freturn\n" + + " Exception Table:\n" + + " [pc: 0, pc: 9] -> 11 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 31]\n" + + " [pc: 9, line: 32]\n" + + " [pc: 11, line: 34]\n" + + " [pc: 12, line: 36]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " [pc: 2, pc: 11] local: i index: 1 type: int\n" + + " \n" + + " // Method descriptor #30 ()D\n" + + " // Stack: 2, Locals: 1\n" + + " double bar();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 16\n" + + " 7 aload_0 [this]\n" + + " 8 invokevirtual X.bool() : boolean [17]\n" + + " 11 ifeq 31\n" + + " 14 dconst_0\n" + + " 15 dreturn\n" + + " 16 aload_0 [this]\n" + + " 17 invokevirtual X.bool() : boolean [17]\n" + + " 20 ifeq 31\n" + + " 23 new java.lang.NullPointerException [31]\n" + + " 26 dup\n" + + " 27 invokespecial java.lang.NullPointerException() [33]\n" + + " 30 athrow\n" + + " 31 dconst_1\n" + + " 32 dreturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 39]\n" + + " [pc: 7, line: 40]\n" + + " [pc: 14, line: 41]\n" + + " [pc: 16, line: 43]\n" + + " [pc: 23, line: 44]\n" + + " [pc: 31, line: 47]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 33] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #35 (I)V\n" + + " // Stack: 1, Locals: 2\n" + + " void baz(int i);\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 32\n" + + " 7 iload_1 [i]\n" + + " 8 tableswitch default: 29\n" + + " case 0: 28\n" + + " 28 return\n" + + " 29 goto 37\n" + + " 32 aload_0 [this]\n" + + " 33 invokevirtual X.bool() : boolean [17]\n" + + " 36 pop\n" + + " 37 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 50]\n" + + " [pc: 7, line: 51]\n" + + " [pc: 28, line: 52]\n" + + " [pc: 29, line: 55]\n" + + " [pc: 32, line: 56]\n" + + " [pc: 37, line: 58]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 38] local: this index: 0 type: X\n" + + " [pc: 0, pc: 38] local: i index: 1 type: int\n" + : + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 9\n" + + " 7 return\n" + + " 8 astore_1\n" + + " 9 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 7] -> 8 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 8, line: 8]\n" + + " [pc: 9, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " Stack map table: number of frames 2\n" + + " [pc: 8, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 9, same]\n" + + " \n" + + " // Method descriptor #23 ()I\n" + + " // Stack: 1, Locals: 2\n" + + " int foo2();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 10\n" + + " 7 iconst_0\n" + + " 8 ireturn\n" + + " 9 astore_1\n" + + " 10 iconst_1\n" + + " 11 ireturn\n" + + " Exception Table:\n" + + " [pc: 0, pc: 7] -> 9 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 7, line: 14]\n" + + " [pc: 9, line: 16]\n" + + " [pc: 10, line: 18]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n" + + " Stack map table: number of frames 2\n" + + " [pc: 9, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 10, same]\n" + + " \n" + + " // Method descriptor #25 ()J\n" + + " // Stack: 2, Locals: 1\n" + + " long foo3();\n" + + " 0 lconst_0\n" + + " 1 lreturn\n" + + " 2 lconst_1\n" + + " 3 lreturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 23]\n" + + " [pc: 2, line: 27]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 4] local: this index: 0 type: X\n" + + " Stack map table: number of frames 1\n" + + " [pc: 2, same]\n" + + " \n" + + " // Method descriptor #27 ()F\n" + + " // Stack: 1, Locals: 2\n" + + " float foo4();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 aload_0 [this]\n" + + " 3 invokevirtual X.bool() : boolean [17]\n" + + " 6 ifeq 12\n" + + " 9 fconst_0\n" + + " 10 freturn\n" + + " 11 astore_1\n" + + " 12 fconst_1\n" + + " 13 freturn\n" + + " Exception Table:\n" + + " [pc: 0, pc: 9] -> 11 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 31]\n" + + " [pc: 9, line: 32]\n" + + " [pc: 11, line: 34]\n" + + " [pc: 12, line: 36]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " [pc: 2, pc: 11] local: i index: 1 type: int\n" + + " Stack map table: number of frames 2\n" + + " [pc: 11, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 12, same]\n" + + " \n" + + " // Method descriptor #31 ()D\n" + + " // Stack: 2, Locals: 1\n" + + " double bar();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 16\n" + + " 7 aload_0 [this]\n" + + " 8 invokevirtual X.bool() : boolean [17]\n" + + " 11 ifeq 31\n" + + " 14 dconst_0\n" + + " 15 dreturn\n" + + " 16 aload_0 [this]\n" + + " 17 invokevirtual X.bool() : boolean [17]\n" + + " 20 ifeq 31\n" + + " 23 new java.lang.NullPointerException [32]\n" + + " 26 dup\n" + + " 27 invokespecial java.lang.NullPointerException() [34]\n" + + " 30 athrow\n" + + " 31 dconst_1\n" + + " 32 dreturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 39]\n" + + " [pc: 7, line: 40]\n" + + " [pc: 14, line: 41]\n" + + " [pc: 16, line: 43]\n" + + " [pc: 23, line: 44]\n" + + " [pc: 31, line: 47]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 33] local: this index: 0 type: X\n" + + " Stack map table: number of frames 2\n" + + " [pc: 16, same]\n" + + " [pc: 31, same]\n" + + " \n" + + " // Method descriptor #36 (I)V\n" + + " // Stack: 1, Locals: 2\n" + + " void baz(int i);\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 32\n" + + " 7 iload_1 [i]\n" + + " 8 tableswitch default: 29\n" + + " case 0: 28\n" + + " 28 return\n" + + " 29 goto 37\n" + + " 32 aload_0 [this]\n" + + " 33 invokevirtual X.bool() : boolean [17]\n" + + " 36 pop\n" + + " 37 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 50]\n" + + " [pc: 7, line: 51]\n" + + " [pc: 28, line: 52]\n" + + " [pc: 29, line: 55]\n" + + " [pc: 32, line: 56]\n" + + " [pc: 37, line: 58]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 38] local: this index: 0 type: X\n" + + " [pc: 0, pc: 38] local: i index: 1 type: int\n" + + " Stack map table: number of frames 4\n" + + " [pc: 28, same]\n" + + " [pc: 29, same]\n" + + " [pc: 32, same]\n" + + " [pc: 37, same]\n"; + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation +public void test049() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bool() { return true; }\n" + + " void foo() {\n" + + " try {\n" + + " if (bool()) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + " void foo2() {\n" + + " try {\n" + + " while (bool()) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + " void foo3() {\n" + + " try {\n" + + " do {\n" + + " if (true) throw new NullPointerException();\n" + + " } while (bool());\n" + + " } catch (Exception e) {\n" + + " }\n" + + " } \n" + + " void foo4() {\n" + + " try {\n" + + " for (int i = 0; bool(); i++) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " } \n" + + " void bar() {\n" + + " if (bool()) {\n" + + " if (bool())\n" + + " throw new NullPointerException();\n" + + " } else {\n" + + " if (bool()) {\n" + + " throw new NullPointerException();\n" + + " }\n" + + " }\n" + + " }\n" + + " void baz(int i) {\n" + + " if (bool()) {\n" + + " switch(i) {\n" + + " case 0 : throw new NullPointerException();\n" + + " default : break;\n" + + " }\n" + + " } else {\n" + + " bool();\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6 + ? " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 16\n" + + " 7 new java.lang.NullPointerException [19]\n" + + " 10 dup\n" + + " 11 invokespecial java.lang.NullPointerException() [21]\n" + + " 14 athrow\n" + + " 15 astore_1\n" + + " 16 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 15] -> 15 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 16, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " void foo2();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 16\n" + + " 7 new java.lang.NullPointerException [19]\n" + + " 10 dup\n" + + " 11 invokespecial java.lang.NullPointerException() [21]\n" + + " 14 athrow\n" + + " 15 astore_1\n" + + " 16 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 15] -> 15 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 7, line: 14]\n" + + " [pc: 15, line: 16]\n" + + " [pc: 16, line: 18]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " void foo3();\n" + + " 0 new java.lang.NullPointerException [19]\n" + + " 3 dup\n" + + " 4 invokespecial java.lang.NullPointerException() [21]\n" + + " 7 athrow\n" + + " 8 astore_1\n" + + " 9 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 8] -> 8 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 22]\n" + + " [pc: 8, line: 24]\n" + + " [pc: 9, line: 26]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " void foo4();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 aload_0 [this]\n" + + " 3 invokevirtual X.bool() : boolean [17]\n" + + " 6 ifeq 18\n" + + " 9 new java.lang.NullPointerException [19]\n" + + " 12 dup\n" + + " 13 invokespecial java.lang.NullPointerException() [21]\n" + + " 16 athrow\n" + + " 17 astore_1\n" + + " 18 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 17] -> 17 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 29]\n" + + " [pc: 9, line: 30]\n" + + " [pc: 17, line: 32]\n" + + " [pc: 18, line: 34]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: this index: 0 type: X\n" + + " [pc: 2, pc: 17] local: i index: 1 type: int\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " void bar();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 22\n" + + " 7 aload_0 [this]\n" + + " 8 invokevirtual X.bool() : boolean [17]\n" + + " 11 ifeq 37\n" + + " 14 new java.lang.NullPointerException [19]\n" + + " 17 dup\n" + + " 18 invokespecial java.lang.NullPointerException() [21]\n" + + " 21 athrow\n" + + " 22 aload_0 [this]\n" + + " 23 invokevirtual X.bool() : boolean [17]\n" + + " 26 ifeq 37\n" + + " 29 new java.lang.NullPointerException [19]\n" + + " 32 dup\n" + + " 33 invokespecial java.lang.NullPointerException() [21]\n" + + " 36 athrow\n" + + " 37 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 36]\n" + + " [pc: 7, line: 37]\n" + + " [pc: 14, line: 38]\n" + + " [pc: 22, line: 40]\n" + + " [pc: 29, line: 41]\n" + + " [pc: 37, line: 44]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 38] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #31 (I)V\n" + + " // Stack: 2, Locals: 2\n" + + " void baz(int i);\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 39\n" + + " 7 iload_1 [i]\n" + + " 8 tableswitch default: 36\n" + + " case 0: 28\n" + + " 28 new java.lang.NullPointerException [19]\n" + + " 31 dup\n" + + " 32 invokespecial java.lang.NullPointerException() [21]\n" + + " 35 athrow\n" + + " 36 goto 44\n" + + " 39 aload_0 [this]\n" + + " 40 invokevirtual X.bool() : boolean [17]\n" + + " 43 pop\n" + + " 44 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 46]\n" + + " [pc: 7, line: 47]\n" + + " [pc: 28, line: 48]\n" + + " [pc: 36, line: 51]\n" + + " [pc: 39, line: 52]\n" + + " [pc: 44, line: 54]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 45] local: this index: 0 type: X\n" + + " [pc: 0, pc: 45] local: i index: 1 type: int\n" + : + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 16\n" + + " 7 new java.lang.NullPointerException [19]\n" + + " 10 dup\n" + + " 11 invokespecial java.lang.NullPointerException() [21]\n" + + " 14 athrow\n" + + " 15 astore_1\n" + + " 16 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 15] -> 15 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 16, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: this index: 0 type: X\n" + + " Stack map table: number of frames 2\n" + + " [pc: 15, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 16, same]\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " void foo2();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 16\n" + + " 7 new java.lang.NullPointerException [19]\n" + + " 10 dup\n" + + " 11 invokespecial java.lang.NullPointerException() [21]\n" + + " 14 athrow\n" + + " 15 astore_1\n" + + " 16 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 15] -> 15 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 7, line: 14]\n" + + " [pc: 15, line: 16]\n" + + " [pc: 16, line: 18]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: this index: 0 type: X\n" + + " Stack map table: number of frames 2\n" + + " [pc: 15, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 16, same]\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " void foo3();\n" + + " 0 new java.lang.NullPointerException [19]\n" + + " 3 dup\n" + + " 4 invokespecial java.lang.NullPointerException() [21]\n" + + " 7 athrow\n" + + " 8 astore_1\n" + + " 9 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 8] -> 8 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 22]\n" + + " [pc: 8, line: 24]\n" + + " [pc: 9, line: 26]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " Stack map table: number of frames 1\n" + + " [pc: 8, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 2\n" + + " void foo4();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 aload_0 [this]\n" + + " 3 invokevirtual X.bool() : boolean [17]\n" + + " 6 ifeq 18\n" + + " 9 new java.lang.NullPointerException [19]\n" + + " 12 dup\n" + + " 13 invokespecial java.lang.NullPointerException() [21]\n" + + " 16 athrow\n" + + " 17 astore_1\n" + + " 18 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 17] -> 17 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 29]\n" + + " [pc: 9, line: 30]\n" + + " [pc: 17, line: 32]\n" + + " [pc: 18, line: 34]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: this index: 0 type: X\n" + + " [pc: 2, pc: 17] local: i index: 1 type: int\n" + + " Stack map table: number of frames 2\n" + + " [pc: 17, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 18, same]\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " void bar();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 22\n" + + " 7 aload_0 [this]\n" + + " 8 invokevirtual X.bool() : boolean [17]\n" + + " 11 ifeq 37\n" + + " 14 new java.lang.NullPointerException [19]\n" + + " 17 dup\n" + + " 18 invokespecial java.lang.NullPointerException() [21]\n" + + " 21 athrow\n" + + " 22 aload_0 [this]\n" + + " 23 invokevirtual X.bool() : boolean [17]\n" + + " 26 ifeq 37\n" + + " 29 new java.lang.NullPointerException [19]\n" + + " 32 dup\n" + + " 33 invokespecial java.lang.NullPointerException() [21]\n" + + " 36 athrow\n" + + " 37 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 36]\n" + + " [pc: 7, line: 37]\n" + + " [pc: 14, line: 38]\n" + + " [pc: 22, line: 40]\n" + + " [pc: 29, line: 41]\n" + + " [pc: 37, line: 44]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 38] local: this index: 0 type: X\n" + + " Stack map table: number of frames 2\n" + + " [pc: 22, same]\n" + + " [pc: 37, same]\n" + + " \n" + + " // Method descriptor #32 (I)V\n" + + " // Stack: 2, Locals: 2\n" + + " void baz(int i);\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 39\n" + + " 7 iload_1 [i]\n" + + " 8 tableswitch default: 36\n" + + " case 0: 28\n" + + " 28 new java.lang.NullPointerException [19]\n" + + " 31 dup\n" + + " 32 invokespecial java.lang.NullPointerException() [21]\n" + + " 35 athrow\n" + + " 36 goto 44\n" + + " 39 aload_0 [this]\n" + + " 40 invokevirtual X.bool() : boolean [17]\n" + + " 43 pop\n" + + " 44 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 46]\n" + + " [pc: 7, line: 47]\n" + + " [pc: 28, line: 48]\n" + + " [pc: 36, line: 51]\n" + + " [pc: 39, line: 52]\n" + + " [pc: 44, line: 54]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 45] local: this index: 0 type: X\n" + + " [pc: 0, pc: 45] local: i index: 1 type: int\n" + + " Stack map table: number of frames 4\n" + + " [pc: 28, same]\n" + + " [pc: 36, same]\n" + + " [pc: 39, same]\n" + + " [pc: 44, same]\n"; + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation +public void test050() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " boolean bool() { return true; }\n" + + " void foo() {\n" + + " check: try {\n" + + " if (bool()) {\n" + + " break check;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + " void foo2() {\n" + + " check: try {\n" + + " while (bool()) {\n" + + " break check;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + " void foo3() {\n" + + " check: try {\n" + + " do {\n" + + " if (true) break check;\n" + + " } while (bool());\n" + + " } catch (Exception e) {\n" + + " }\n" + + " } \n" + + " void foo4() {\n" + + " check: try {\n" + + " for (int i = 0; bool(); i++) {\n" + + " break check;\n" + + " }\n" + + " } catch (Exception e) {\n" + + " }\n" + + " }\n" + + " void bar() {\n" + + " check: if (bool()) {\n" + + " if (bool())\n" + + " break check;\n" + + " } else {\n" + + " if (bool()) {\n" + + " break check;\n" + + " }\n" + + " }\n" + + " }\n" + + " void baz(int i) {\n" + + " check: if (bool()) {\n" + + " switch(i) {\n" + + " case 0 : break check;\n" + + " default : break;\n" + + " }\n" + + " } else {\n" + + " bool();\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6 + ? " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 11\n" + + " 7 goto 11\n" + + " 10 astore_1\n" + + " 11 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 7] -> 10 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 10, line: 8]\n" + + " [pc: 11, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo2();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 11\n" + + " 7 goto 11\n" + + " 10 astore_1\n" + + " 11 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 7] -> 10 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 7, line: 14]\n" + + " [pc: 10, line: 16]\n" + + " [pc: 11, line: 18]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo3();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 26]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo4();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 aload_0 [this]\n" + + " 3 invokevirtual X.bool() : boolean [17]\n" + + " 6 ifeq 13\n" + + " 9 goto 13\n" + + " 12 astore_1\n" + + " 13 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 9] -> 12 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 29]\n" + + " [pc: 9, line: 30]\n" + + " [pc: 12, line: 32]\n" + + " [pc: 13, line: 34]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " [pc: 2, pc: 12] local: i index: 1 type: int\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " void bar();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 17\n" + + " 7 aload_0 [this]\n" + + " 8 invokevirtual X.bool() : boolean [17]\n" + + " 11 ifeq 24\n" + + " 14 goto 24\n" + + " 17 aload_0 [this]\n" + + " 18 invokevirtual X.bool() : boolean [17]\n" + + " 21 ifeq 24\n" + + " 24 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 36]\n" + + " [pc: 7, line: 37]\n" + + " [pc: 14, line: 38]\n" + + " [pc: 17, line: 40]\n" + + " [pc: 24, line: 44]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 25] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #28 (I)V\n" + + " // Stack: 1, Locals: 2\n" + + " void baz(int i);\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 34\n" + + " 7 iload_1 [i]\n" + + " 8 tableswitch default: 31\n" + + " case 0: 28\n" + + " 28 goto 39\n" + + " 31 goto 39\n" + + " 34 aload_0 [this]\n" + + " 35 invokevirtual X.bool() : boolean [17]\n" + + " 38 pop\n" + + " 39 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 46]\n" + + " [pc: 7, line: 47]\n" + + " [pc: 28, line: 48]\n" + + " [pc: 31, line: 51]\n" + + " [pc: 34, line: 52]\n" + + " [pc: 39, line: 54]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 40] local: this index: 0 type: X\n" + + " [pc: 0, pc: 40] local: i index: 1 type: int\n" + : + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 11\n" + + " 7 goto 11\n" + + " 10 astore_1\n" + + " 11 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 7] -> 10 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 10, line: 8]\n" + + " [pc: 11, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n" + + " Stack map table: number of frames 2\n" + + " [pc: 10, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 11, same]\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo2();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 11\n" + + " 7 goto 11\n" + + " 10 astore_1\n" + + " 11 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 7] -> 10 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 13]\n" + + " [pc: 7, line: 14]\n" + + " [pc: 10, line: 16]\n" + + " [pc: 11, line: 18]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 12] local: this index: 0 type: X\n" + + " Stack map table: number of frames 2\n" + + " [pc: 10, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 11, same]\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo3();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 26]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo4();\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 aload_0 [this]\n" + + " 3 invokevirtual X.bool() : boolean [17]\n" + + " 6 ifeq 13\n" + + " 9 goto 13\n" + + " 12 astore_1\n" + + " 13 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 9] -> 12 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 29]\n" + + " [pc: 9, line: 30]\n" + + " [pc: 12, line: 32]\n" + + " [pc: 13, line: 34]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " [pc: 2, pc: 12] local: i index: 1 type: int\n" + + " Stack map table: number of frames 2\n" + + " [pc: 12, same_locals_1_stack_item, stack: {java.lang.Exception}]\n" + + " [pc: 13, same]\n" + + " \n" + + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " void bar();\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 17\n" + + " 7 aload_0 [this]\n" + + " 8 invokevirtual X.bool() : boolean [17]\n" + + " 11 ifeq 24\n" + + " 14 goto 24\n" + + " 17 aload_0 [this]\n" + + " 18 invokevirtual X.bool() : boolean [17]\n" + + " 21 ifeq 24\n" + + " 24 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 36]\n" + + " [pc: 7, line: 37]\n" + + " [pc: 14, line: 38]\n" + + " [pc: 17, line: 40]\n" + + " [pc: 24, line: 44]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 25] local: this index: 0 type: X\n" + + " Stack map table: number of frames 2\n" + + " [pc: 17, same]\n" + + " [pc: 24, same]\n" + + " \n" + + " // Method descriptor #29 (I)V\n" + + " // Stack: 1, Locals: 2\n" + + " void baz(int i);\n" + + " 0 aload_0 [this]\n" + + " 1 invokevirtual X.bool() : boolean [17]\n" + + " 4 ifeq 34\n" + + " 7 iload_1 [i]\n" + + " 8 tableswitch default: 31\n" + + " case 0: 28\n" + + " 28 goto 39\n" + + " 31 goto 39\n" + + " 34 aload_0 [this]\n" + + " 35 invokevirtual X.bool() : boolean [17]\n" + + " 38 pop\n" + + " 39 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 46]\n" + + " [pc: 7, line: 47]\n" + + " [pc: 28, line: 48]\n" + + " [pc: 31, line: 51]\n" + + " [pc: 34, line: 52]\n" + + " [pc: 39, line: 54]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 40] local: this index: 0 type: X\n" + + " [pc: 0, pc: 40] local: i index: 1 type: int\n" + + " Stack map table: number of frames 4\n" + + " [pc: 28, same]\n" + + " [pc: 31, same]\n" + + " [pc: 34, same]\n" + + " [pc: 39, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation +public void test051() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " System.out.println(\"[count=\" + count() + \"]\");\n" + + " }\n" + + " static int count() {\n" + + " int count = 0;\n" + + " try {\n" + + " for (int i = 0;;) {\n" + + " count++;\n" + + " if (i++ > 10) \n" + + " break; \n" + + " }\n" + + " } catch(Exception e) {\n" + + " }\n" + + " return count;\n" + + " }\n" + + "}\n", + }, + "[count=12]"); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6 + ? " // Method descriptor #32 ()I\n" + + " // Stack: 2, Locals: 2\n" + + " static int count();\n" + + " 0 iconst_0\n" + + " 1 istore_0 [count]\n" + + " 2 iconst_0\n" + + " 3 istore_1 [i]\n" + + " 4 iinc 0 1 [count]\n" + + " 7 iload_1 [i]\n" + + " 8 iinc 1 1 [i]\n" + + " 11 bipush 10\n" + + " 13 if_icmple 4\n" + + " 16 goto 20\n" + + " 19 astore_1\n" + + " 20 iload_0 [count]\n" + + " 21 ireturn\n" + + " Exception Table:\n" + + " [pc: 2, pc: 16] -> 19 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 2, line: 8]\n" + + " [pc: 4, line: 9]\n" + + " [pc: 7, line: 10]\n" + + " [pc: 16, line: 13]\n" + + " [pc: 20, line: 15]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 22] local: count index: 0 type: int\n" + + " [pc: 4, pc: 16] local: i index: 1 type: int\n" + : + " // Method descriptor #32 ()I\n" + + " // Stack: 2, Locals: 2\n" + + " static int count();\n" + + " 0 iconst_0\n" + + " 1 istore_0 [count]\n" + + " 2 iconst_0\n" + + " 3 istore_1 [i]\n" + + " 4 iinc 0 1 [count]\n" + + " 7 iload_1 [i]\n" + + " 8 iinc 1 1 [i]\n" + + " 11 bipush 10\n" + + " 13 if_icmple 4\n" + + " 16 goto 20\n" + + " 19 astore_1\n" + + " 20 iload_0 [count]\n" + + " 21 ireturn\n" + + " Exception Table:\n" + + " [pc: 2, pc: 16] -> 19 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 6]\n" + + " [pc: 2, line: 8]\n" + + " [pc: 4, line: 9]\n" + + " [pc: 7, line: 10]\n" + + " [pc: 16, line: 13]\n" + + " [pc: 20, line: 15]\n" + + " Local variable table:\n" + + " [pc: 2, pc: 22] local: count index: 0 type: int\n" + + " [pc: 4, pc: 16] local: i index: 1 type: int\n" + + " Stack map table: number of frames 3\n" + + " [pc: 4, append: {int, int}]\n" + + " [pc: 19, full, stack: {java.lang.Exception}, locals: {int}]\n" + + " [pc: 20, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation +public void test052() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " try {\n" + + " for (int i = 0; i < 0; i++)\n" + + " do ; while (true);\n" + + " } catch(Exception e) {\n" + + " }\n" + + " } \n" + + "}\n", + }, + ""); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6 + ? " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] argv);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 iload_1 [i]\n" + + " 3 ifge 10\n" + + " 6 goto 6\n" + + " 9 astore_1\n" + + " 10 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 9] -> 9 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 6, line: 5]\n" + + " [pc: 9, line: 6]\n" + + " [pc: 10, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: argv index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 9] local: i index: 1 type: int\n" + : + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 1, Locals: 2\n" + + " public static void main(java.lang.String[] argv);\n" + + " 0 iconst_0\n" + + " 1 istore_1 [i]\n" + + " 2 iload_1 [i]\n" + + " 3 ifge 10\n" + + " 6 goto 6\n" + + " 9 astore_1\n" + + " 10 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 9] -> 9 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 6, line: 5]\n" + + " [pc: 9, line: 6]\n" + + " [pc: 10, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: argv index: 0 type: java.lang.String[]\n" + + " [pc: 2, pc: 9] local: i index: 1 type: int\n" + + " Stack map table: number of frames 3\n" + + " [pc: 6, append: {int}]\n" + + " [pc: 9, full, stack: {java.lang.Exception}, locals: {java.lang.String[]}]\n" + + " [pc: 10, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation +public void test053() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " final int val;\n" + + " for (val = 7; val > 0;) break;\n" + + " System.out.println(val);\n" + + " } catch(Exception e) {\n" + + " }\n" + + " } \n" + + "}\n", + }, + "7"); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6 + ? " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 7\n" + + " 2 istore_1 [val]\n" + + " 3 iload_1 [val]\n" + + " 4 ifle 7\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 10 iload_1 [val]\n" + + " 11 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 14 goto 18\n" + + " 17 astore_1\n" + + " 18 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 14] -> 17 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 14, line: 7]\n" + + " [pc: 18, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 14] local: val index: 1 type: int\n" + : + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 2\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 bipush 7\n" + + " 2 istore_1 [val]\n" + + " 3 iload_1 [val]\n" + + " 4 ifle 7\n" + + " 7 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 10 iload_1 [val]\n" + + " 11 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 14 goto 18\n" + + " 17 astore_1\n" + + " 18 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 14] -> 17 when : java.lang.Exception\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 7, line: 6]\n" + + " [pc: 14, line: 7]\n" + + " [pc: 18, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 19] local: args index: 0 type: java.lang.String[]\n" + + " [pc: 3, pc: 14] local: val index: 1 type: int\n" + + " Stack map table: number of frames 3\n" + + " [pc: 7, append: {int}]\n" + + " [pc: 17, full, stack: {java.lang.Exception}, locals: {java.lang.String[]}]\n" + + " [pc: 18, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation +public void test054() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " X parent;\n" + + " int kind;\n" + + " static boolean F = false;\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.kind = 2; \n" + + " try {\n" + + " x.foo();\n" + + " } catch(NullPointerException e) { \n" + + " System.out.println(\"SUCCESS\");\n" + + " return;\n" + + " }\n" + + " System.out.println(\"FAILED\"); \n" + + " }\n" + + " void foo() {\n" + + " X x = this;\n" + + " done : while (true) {\n" + + " switch (x.kind) {\n" + + " case 2 :\n" + + " if (F) {\n" + + " return;\n" + + " }\n" + + " break;\n" + + " case 3 :\n" + + " break done;\n" + + " }\n" + + " x = x.parent; // should throw npe\n" + + " }\n" + + " } \n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6 + ? " // Method descriptor #12 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 astore_1 [x]\n" + + " 2 aload_1 [x]\n" + + " 3 getfield X.kind : int [25]\n" + + " 6 tableswitch default: 38\n" + + " case 2: 28\n" + + " case 3: 35\n" + + " 28 getstatic X.F : boolean [14]\n" + + " 31 ifeq 38\n" + + " 34 return\n" + + " 35 goto 46\n" + + " 38 aload_1 [x]\n" + + " 39 getfield X.parent : X [53]\n" + + " 42 astore_1 [x]\n" + + " 43 goto 2\n" + + " 46 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 17]\n" + + " [pc: 2, line: 19]\n" + + " [pc: 28, line: 21]\n" + + " [pc: 34, line: 22]\n" + + " [pc: 35, line: 26]\n" + + " [pc: 38, line: 27]\n" + + " [pc: 39, line: 28]\n" + + " [pc: 43, line: 18]\n" + + " [pc: 46, line: 30]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 47] local: this index: 0 type: X\n" + + " [pc: 2, pc: 47] local: x index: 1 type: X\n" + : + " // Method descriptor #12 ()V\n" + + " // Stack: 1, Locals: 2\n" + + " void foo();\n" + + " 0 aload_0 [this]\n" + + " 1 astore_1 [x]\n" + + " 2 aload_1 [x]\n" + + " 3 getfield X.kind : int [25]\n" + + " 6 tableswitch default: 38\n" + + " case 2: 28\n" + + " case 3: 35\n" + + " 28 getstatic X.F : boolean [14]\n" + + " 31 ifeq 38\n" + + " 34 return\n" + + " 35 goto 46\n" + + " 38 aload_1 [x]\n" + + " 39 getfield X.parent : X [55]\n" + + " 42 astore_1 [x]\n" + + " 43 goto 2\n" + + " 46 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 17]\n" + + " [pc: 2, line: 19]\n" + + " [pc: 28, line: 21]\n" + + " [pc: 34, line: 22]\n" + + " [pc: 35, line: 26]\n" + + " [pc: 38, line: 27]\n" + + " [pc: 39, line: 28]\n" + + " [pc: 43, line: 18]\n" + + " [pc: 46, line: 30]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 47] local: this index: 0 type: X\n" + + " [pc: 2, pc: 47] local: x index: 1 type: X\n" + + " Stack map table: number of frames 5\n" + + " [pc: 2, append: {X}]\n" + + " [pc: 28, same]\n" + + " [pc: 35, same]\n" + + " [pc: 38, same]\n" + + " [pc: 46, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=114894 - variation +public void test055() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + "void foo5() {\n" + + " L : for (;;) {\n" + + " continue L; // good\n" + + " }\n" + + "}\n" + + "}\n", + }, + ""); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_6 + ? " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo5();\n" + + " 0 goto 0\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 3] local: this index: 0 type: X\n" + : + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " void foo5();\n" + + " 0 goto 0\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 3] local: this index: 0 type: X\n" + + " Stack map table: number of frames 1\n" + + " [pc: 0, same]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +public void _test056() { + this.runNegativeTest( + new String[] { + "p/BytecodeA.java", + "package p;\n" + + "class BytecodeA {\n" + + " \n" + + "int foo() { // good\n" + + " boolean b = true;\n" + + " if (b) {\n" + + " if (true)\n" + + " return 0;\n" + + " } else {\n" + + " if (true)\n" + + " return 1;\n" + + " }\n" + + " return 5;\n" + + "}\n" + + "int foo10() {\n" + + " try {\n" + + " //if (true)\n" + + " return 0;\n" + + " } catch (Exception e) {\n" + + " if (true)\n" + + " return 1;\n" + + " } finally {\n" + + " if (true)\n" + + " return 2;\n" + + " };\n" + + " return 1;\n" + + "} \n" + + "int foo11() {\n" + + " synchronized (this) {\n" + + " if (true)\n" + + " return 1;\n" + + " };\n" + + " return 2;\n" + + "} \n" + + "int foo12() {\n" + + " for (;;)\n" + + " return 1;\n" + + "}\n" + + "int foo13() {\n" + + " for (;;)\n" + + " if (true)\n" + + " return 1;\n" + + "}\n" + + "int foo14() {\n" + + " for (int i = 1; i < 10; i++)\n" + + " if (true)\n" + + " return 1;\n" + + " return 2;\n" + + "} \n" + + "int foo15() {\n" + + " for (int i = 1; i < 10; i++)\n" + + " return 1;\n" + + " return 2;\n" + + "}\n" + + "int foo16() {\n" + + " final int i;\n" + + " while (true) {\n" + + " i = 1;\n" + + " if (true)\n" + + " break;\n" + + " };\n" + + " return 1;\n" + + "} \n" + + "int foo17() {\n" + + " final int i;\n" + + " for (;;) {\n" + + " i = 1;\n" + + " if (true)\n" + + " break;\n" + + " };\n" + + " return 1;\n" + + "} \n" + + "void foo2() {\n" + + " L1 :; // good\n" + + "}\n" + + "void foo20() {\n" + + " if (true)\n" + + " return;\n" + + "} \n" + + "void foo3() {\n" + + " L : if (true) {\n" + + " for (;;) {\n" + + " continue L; // bad\n" + + " }\n" + + " }\n" + + "} \n" + + "void foo4() {\n" + + " L : if (true) {\n" + + " try {\n" + + " for (;;) {\n" + + " continue L; // bad\n" + + " }\n" + + " } finally {\n" + + " return;\n" + + " }\n" + + " } \n" + + "}\n" + + "void foo5() {\n" + + " L : for (;;) {\n" + + " continue L; // good\n" + + " }\n" + + "}\n" + + "void foo5bis() {\n" + + " L : K : for (;;) {\n" + + " continue L; // good\n" + + " }\n" + + "}\n" + + "void foo6(){\n" + + " int i;\n" + + " boolean a[] = new boolean[5];\n" + + " a[i=1] = i > 0; // good\n" + + "} \n" + + "void foo7(){\n" + + " Object x[];\n" + + " x [1] = (x = new Object[5]); // bad\n" + + "} \n" + + "void foo8() {\n" + + " try {\n" + + " } catch (java.io.IOException e) {\n" + + " foo(); // unreachable\n" + + " }\n" + + "}\n" + + "void foo9() {\n" + + " try {\n" + + " } catch (NullPointerException e) {\n" + + " foo(); // ok\n" + + " }\n" + + "}\n" + + " public static void main(String args[]) {\n" + + " BytecodeA a = new BytecodeA();\n" + + " a.foo10();\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. WARNING in p\\BytecodeA.java (at line 74)\n" + + " L1 :; // good\n" + + " ^^\n" + + "The label L1 is never explicitly referenced\n" + + "----------\n" + + "2. ERROR in p\\BytecodeA.java (at line 83)\n" + + " continue L; // bad\n" + + " ^^^^^^^^^^\n" + + "continue cannot be used outside of a loop\n" + + "----------\n" + + "3. ERROR in p\\BytecodeA.java (at line 91)\n" + + " continue L; // bad\n" + + " ^^^^^^^^^^\n" + + "continue cannot be used outside of a loop\n" + + "----------\n" + + "4. WARNING in p\\BytecodeA.java (at line 93)\n" + + " } finally {\n" + + " return;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^\n" + + "finally block does not complete normally\n" + + "----------\n" + + "5. WARNING in p\\BytecodeA.java (at line 104)\n" + + " L : K : for (;;) {\n" + + " ^\n" + + "The label K is never explicitly referenced\n" + + "----------\n" + + "6. ERROR in p\\BytecodeA.java (at line 105)\n" + + " continue L; // good\n" + + " ^^^^^^^^^^\n" + + "continue cannot be used outside of a loop\n" + + "----------\n" + + "7. ERROR in p\\BytecodeA.java (at line 115)\n" + + " x [1] = (x = new Object[5]); // bad\n" + + " ^\n" + + "The local variable x may not have been initialized\n" + + "----------\n" + + "8. ERROR in p\\BytecodeA.java (at line 119)\n" + + " } catch (java.io.IOException e) {\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Unreachable catch block for IOException. This exception is never thrown from the try statement body\n" + + "----------\n"); +} + +// was Compliance_1_x#test007 +public void test057() { + String[] sources = new String[] { + "p1/Test.java", + "package p1; \n"+ + "public class Test { \n"+ + " public static void main(String[] arguments) { \n"+ + " try { \n" + + " throw null; \n"+ + " } catch(NullPointerException e){ \n" + + " System.out.println(\"SUCCESS\"); \n" + + " } \n" + + " } \n"+ + "} \n" + }; + if (this.complianceLevel == ClassFileConstants.JDK1_3) { + runNegativeTest( + sources, + "----------\n" + + "1. ERROR in p1\\Test.java (at line 5)\n" + + " throw null; \n" + + " ^^^^\n" + + "Cannot throw null as an exception\n" + + "----------\n"); + } else { + runConformTest( + sources, + "SUCCESS"); + } +} +//https://bugs.eclpse.org/bugs/show_bug.cgi?id=3184 +public void test058() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "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"); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel <= ClassFileConstants.JDK1_4 + ? " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 5\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 ldc [22]\n" + + " 5 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 8 goto 28\n" + + " 11 astore_2\n" + + " 12 jsr 17\n" + + " 15 aload_2\n" + + " 16 athrow\n" + + " 17 astore_1\n" + + " 18 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 21 ldc [30]\n" + + " 23 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 26 ret 1\n" + + " 28 jsr 17\n" + + " 31 goto 53\n" + + " 34 astore 4\n" + + " 36 jsr 42\n" + + " 39 aload 4\n" + + " 41 athrow\n" + + " 42 astore_3\n" + + " 43 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 46 ldc [32]\n" + + " 48 invokevirtual java.io.PrintStream.println(java.lang.String) : void [34]\n" + + " 51 ret 3\n" + + " 53 jsr 42\n" + + " 56 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 11] -> 11 when : any\n" + + " [pc: 28, pc: 31] -> 11 when : any\n" + + " [pc: 0, pc: 34] -> 34 when : any\n" + + " [pc: 53, pc: 56] -> 34 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 15, line: 8]\n" + + " [pc: 17, line: 6]\n" + + " [pc: 18, line: 7]\n" + + " [pc: 26, line: 8]\n" + + " [pc: 31, line: 9]\n" + + " [pc: 39, line: 11]\n" + + " [pc: 42, line: 9]\n" + + " [pc: 43, line: 10]\n" + + " [pc: 51, line: 11]\n" + + " [pc: 56, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 57] local: args index: 0 type: java.lang.String[]\n" + : + " // Method descriptor #15 ([Ljava/lang/String;)V\n" + + " // Stack: 2, Locals: 3\n" + + " public static void main(java.lang.String[] args);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 ldc [22]\n" + + " 5 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 8 goto 22\n" + + " 11 astore_1\n" + + " 12 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 15 ldc [30]\n" + + " 17 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 20 aload_1\n" + + " 21 athrow\n" + + " 22 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 25 ldc [30]\n" + + " 27 invokevirtual java.io.PrintStream.print(java.lang.String) : void [24]\n" + + " 30 goto 44\n" + + " 33 astore_2\n" + + " 34 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 37 ldc [32]\n" + + " 39 invokevirtual java.io.PrintStream.println(java.lang.String) : void [34]\n" + + " 42 aload_2\n" + + " 43 athrow\n" + + " 44 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 47 ldc [32]\n" + + " 49 invokevirtual java.io.PrintStream.println(java.lang.String) : void [34]\n" + + " 52 return\n" + + " Exception Table:\n" + + " [pc: 0, pc: 11] -> 11 when : any\n" + + " [pc: 0, pc: 33] -> 33 when : any\n" + + " Line numbers:\n" + + " [pc: 0, line: 5]\n" + + " [pc: 8, line: 6]\n" + + " [pc: 12, line: 7]\n" + + " [pc: 20, line: 8]\n" + + " [pc: 22, line: 7]\n" + + " [pc: 30, line: 9]\n" + + " [pc: 34, line: 10]\n" + + " [pc: 42, line: 11]\n" + + " [pc: 44, line: 10]\n" + + " [pc: 52, line: 12]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 53] local: args index: 0 type: java.lang.String[]\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=183395 +public void test059() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(args.length);\n" + + " } catch(Exception[] e) {\n" + + " // ignore\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\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=183395 +public void test060() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(args.length);\n" + + " } catch(int e) {\n" + + " // ignore\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " } catch(int e) {\n" + + " ^^^\n" + + "No exception of type int can be thrown; an exception type must be a subclass of Throwable\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190209 - variation +public void test062() throws Exception { + if (new CompilerOptions(getCompilerOptions()).complianceLevel < ClassFileConstants.JDK1_5) return; // need autoboxing + this.runConformTest( + new String[] { + "X.java", + "final public class X {\n" + + " final class MyClass {\n" + + " /** @param s */\n" + + " void foo(final String s) {\n" + + " /* do nothing */\n" + + " }\n" + + " }\n" + + " Object bar() {\n" + + " try {\n" + + " final MyClass myClass = new MyClass();\n" + + " try {\n" + + " return 0;\n" + + " } catch (final Throwable ex) {\n" + + " myClass.foo(this == null ? \"\" : \"\");\n" + + " }\n" + + " \n" + + " return this;\n" + + " } finally {\n" + + " { /* do nothing */ }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = + " // Method descriptor #15 ()Ljava/lang/Object;\n" + + " // Stack: 3, Locals: 5\n" + + " java.lang.Object bar();\n" + + " 0 new X$MyClass [16]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 invokespecial X$MyClass(X) [18]\n" + + " 8 astore_1 [myClass]\n" + + " 9 iconst_0\n" + + " 10 invokestatic java.lang.Integer.valueOf(int) : java.lang.Integer [21]\n" + + " 13 astore 4\n" + + " 15 aload 4\n" + + " 17 areturn\n" + + " 18 astore_2 [ex]\n" + + " 19 aload_1 [myClass]\n" + + " 20 aload_0 [this]\n" + + " 21 ifnonnull 29\n" + + " 24 ldc [27]\n" + + " 26 goto 31\n" + + " 29 ldc [27]\n" + + " 31 invokevirtual X$MyClass.foo(java.lang.String) : void [29]\n" + + " 34 aload_0 [this]\n" + + " 35 astore 4\n" + + " 37 aload 4\n" + + " 39 areturn\n" + + " 40 astore_3\n" + + " 41 aload_3\n" + + " 42 athrow\n" + + " Exception Table:\n" + + " [pc: 9, pc: 15] -> 18 when : java.lang.Throwable\n" + + " [pc: 0, pc: 15] -> 40 when : any\n" + + " [pc: 18, pc: 37] -> 40 when : any\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190209 - variation +public void test063() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "final public class X {\n" + + " final class MyClass {\n" + + " /** @param s */\n" + + " void foo(final String s) {\n" + + " /* do nothing */\n" + + " }\n" + + " }\n" + + " void bar() {\n" + + " try {\n" + + " final MyClass myClass = new MyClass();\n" + + " try {\n" + + " return;\n" + + " } catch (final Throwable ex) {\n" + + " myClass.foo(this == null ? \"\" : \"\");\n" + + " }\n" + + " return;\n" + + " } finally {\n" + + " { /* do nothing */ }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel <= ClassFileConstants.JDK1_4 + ? " // Method descriptor #6 ()V\n" + + " // Stack: 3, Locals: 5\n" + + " void bar();\n" + + " 0 new X$MyClass [15]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 invokespecial X$MyClass(X) [17]\n" + + " 8 astore_1 [myClass]\n" + + " 9 jsr 21\n" + + " 12 return\n" + + " 13 astore 4\n" + + " 15 jsr 21\n" + + " 18 aload 4\n" + + " 20 athrow\n" + + " 21 astore_3\n" + + " 22 ret 3\n" + + " Exception Table:\n" + + " [pc: 0, pc: 12] -> 13 when : any\n" + : + " // Method descriptor #6 ()V\n" + + " // Stack: 3, Locals: 4\n" + + " void bar();\n" + + " 0 new X$MyClass [15]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 invokespecial X$MyClass(X) [17]\n" + + " 8 astore_1 [myClass]\n" + + " 9 return\n" + + " 10 return\n" + + " 11 astore_3\n" + + " 12 aload_3\n" + + " 13 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 9] -> 11 when : any\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=190209 - variation +public void test064() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "final public class X {\n" + + " final class MyClass {\n" + + " /** @param s */\n" + + " void foo(final String s) {\n" + + " /* do nothing */\n" + + " }\n" + + " }\n" + + " Object bar() {\n" + + " try {\n" + + " final MyClass myClass = new MyClass();\n" + + " try {\n" + + " return null;\n" + + " } catch (final Throwable ex) {\n" + + " myClass.foo(this == null ? \"\" : \"\");\n" + + " }\n" + + " return null;\n" + + " } finally {\n" + + " { /* do nothing */ }\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().bar();\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + + String expectedOutput = new CompilerOptions(getCompilerOptions()).complianceLevel <= ClassFileConstants.JDK1_4 + ? " // Method descriptor #15 ()Ljava/lang/Object;\n" + + " // Stack: 3, Locals: 5\n" + + " java.lang.Object bar();\n" + + " 0 new X$MyClass [16]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 invokespecial X$MyClass(X) [18]\n" + + " 8 astore_1 [myClass]\n" + + " 9 jsr 22\n" + + " 12 aconst_null\n" + + " 13 areturn\n" + + " 14 astore 4\n" + + " 16 jsr 22\n" + + " 19 aload 4\n" + + " 21 athrow\n" + + " 22 astore_3\n" + + " 23 ret 3\n" + + " Exception Table:\n" + + " [pc: 0, pc: 12] -> 14 when : any\n" + : " // Method descriptor #15 ()Ljava/lang/Object;\n" + + " // Stack: 3, Locals: 4\n" + + " java.lang.Object bar();\n" + + " 0 new X$MyClass [16]\n" + + " 3 dup\n" + + " 4 aload_0 [this]\n" + + " 5 invokespecial X$MyClass(X) [18]\n" + + " 8 astore_1 [myClass]\n" + + " 9 aconst_null\n" + + " 10 areturn\n" + + " 11 aconst_null\n" + + " 12 areturn\n" + + " 13 astore_3\n" + + " 14 aload_3\n" + + " 15 athrow\n" + + " Exception Table:\n" + + " [pc: 0, pc: 9] -> 13 when : any\n"; + + File f = new File(OUTPUT_DIR + File.separator + "X.class"); + byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); + ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); + String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED); + int index = result.indexOf(expectedOutput); + if (index == -1 || expectedOutput.length() == 0) { + System.out.println(Util.displayString(result, 3)); + } + if (index == -1) { + assertEquals("Wrong contents", expectedOutput, result); + } +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=191865 +public void test065() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo() {\n" + + " try {\n" + + " System.out.println(\"Hello\");\n" + + " } finally {\n" + + " if (true)\n" + + " return;\n" + + " }\n" + + " return;\n" + + " }\n" + + " void bar() {\n" + + " try {\n" + + " System.out.println(\"Hello\");\n" + + " } finally {\n" + + " return;\n" + + " }\n" + + " return;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 14)\n" + + " } finally {\n" + + " return;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^\n" + + "finally block does not complete normally\n" + + "----------\n" + + "2. ERROR in X.java (at line 17)\n" + + " return;\n" + + " ^^^^^^^\n" + + "Unreachable code\n" + + "----------\n"); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=196653 +public void test066() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void bar() {\n" + + " try {\n" + + " Zork z = null;\n" + + " z.foo();\n" + + " } catch(Zork z) {\n" + + " z.foo();\n" + + " } \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " Zork z = null;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\n" + + " } catch(Zork z) {\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=248319 +public void test067() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(final String[] args) {\n" + + " System.out.println(new X().verifyError());\n" + + " }\n" + + " private Object verifyError() {\n" + + " try {\n" + + " if (someBooleanMethod()) {\n" + + " return null;\n" + + " }\n" + + " return getStuff();\n" + + " } catch (final Exception ex) {\n" + + " return null;\n" + + " } finally {\n" + + " while (someBooleanMethod()) {\n" + + " anyMethod();\n" + + " }\n" + + " }\n" + + " }\n" + + " private void anyMethod() { /*empty*/ }\n" + + " private Object getStuff() { return null; }\n" + + " private boolean someBooleanMethod() { return false; }\n" + + "}\n" + + "", + }, + "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"); +} +// test for regression during work on bug 345305 +// saw "The local variable name may not have been initialized" against last code line +public void test074() { + runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " Class test(String name) throws ClassNotFoundException {\n" + + " Class c= findClass(name);\n" + + " if (c != null)\n" + + " return c;\n" + + " if (isExcluded(name)) {\n" + + " try {\n" + + " c= findClass(name);\n" + + " return c;\n" + + " } catch (ClassNotFoundException e) {\n" + + " // keep searching\n" + + " }\n" + + " }\n" + + " return findClass(name);\n" + + " }\n" + + " boolean isExcluded(String name) { return false; }\n" + + " Class findClass(String name) throws ClassNotFoundException { return null; }\n" + + "}\n" + }); +} + +// Bug 387612 - Unreachable catch block...exception is never thrown from the try +// redundant exception in throws must not confuse downstream analysis +public void testBug387612() { + String serialUID = "private static final long serialVersionUID=1L;"; + runNegativeTest( + new String[] { + "E.java", + "public class E extends Exception {"+serialUID+"}\n", + "E1.java", + "public class E1 extends E {"+serialUID+"}\n", + "E2.java", + "public class E2 extends E {"+serialUID+"}\n", + "E3.java", + "public class E3 extends E {"+serialUID+"}\n", + "A.java", + "interface A {\n" + + " void foo(String a1, String a2) throws E1, E;\n" + + "}\n", + "B.java", + "interface B extends A {\n" + + " void foo(String a1, String a2) throws E;\n" + + "}\n", + "Client.java", + "public class Client {\n" + + " void test() {\n" + + " B b = new B() {\n" + + " public void foo(String a1, String a2) {}\n" + + " };\n" + + " try {\n" + + " b.foo(null, null);\n" + + " }\n" + + " catch (E1 e) {}\n" + + " catch (E2 e) {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Client.java (at line 7)\n" + + " b.foo(null, null);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type E\n" + + "----------\n"); +} + +// Bug 387612 - Unreachable catch block...exception is never thrown from the try +// - changed order in redundant 'throws' clause. +public void testBug387612b() { + String serialUID = "private static final long serialVersionUID=1L;"; + runNegativeTest( + new String[] { + "E.java", + "public class E extends Exception {"+serialUID+"}\n", + "E1.java", + "public class E1 extends E {"+serialUID+"}\n", + "E2.java", + "public class E2 extends E {"+serialUID+"}\n", + "E3.java", + "public class E3 extends E {"+serialUID+"}\n", + "A.java", + "interface A {\n" + + " void foo(String a1, String a2) throws E, E1;\n" + + "}\n", + "B.java", + "interface B extends A {\n" + + " void foo(String a1, String a2) throws E;\n" + + "}\n", + "Client.java", + "public class Client {\n" + + " void test() {\n" + + " B b = new B() {\n" + + " public void foo(String a1, String a2) {}\n" + + " };\n" + + " try {\n" + + " b.foo(null, null);\n" + + " }\n" + + " catch (E1 e) {}\n" + + " catch (E2 e) {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Client.java (at line 7)\n" + + " b.foo(null, null);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type E\n" + + "----------\n"); +} + +// Bug 387612 - Unreachable catch block...exception is never thrown from the try +// interface with redundant exceptions in throws is read from class file. +public void testBug387612c() { + String serialUID = "private static final long serialVersionUID=1L;"; + runConformTest( + new String[] { + "E.java", + "public class E extends Exception {"+serialUID+"}\n", + "E1.java", + "public class E1 extends E {"+serialUID+"}\n", + "E2.java", + "public class E2 extends E {"+serialUID+"}\n", + "A.java", + "interface A {\n" + + " void foo(String a1, String a2) throws E1, E;\n" + + "}\n", + "B.java", + "interface B extends A {\n" + + " void foo(String a1, String a2) throws E;\n" + + "}\n" + }); + runNegativeTest( + new String[] { + "Client.java", + "public class Client {\n" + + " void test() {\n" + + " B b = new B() {\n" + + " public void foo(String a1, String a2) {}\n" + + " };\n" + + " try {\n" + + " b.foo(null, null);\n" + + " }\n" + + " catch (E1 e) {}\n" + + " catch (E2 e) {}\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in Client.java (at line 7)\n" + + " b.foo(null, null);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Unhandled exception type E\n" + + "----------\n", + null, + false/*shouldFlush*/); +} + +public static Class testClass() { + return TryStatementTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java new file mode 100644 index 0000000000..83620d722b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java @@ -0,0 +1,4326 @@ +/******************************************************************************* + * Copyright (c) 2011, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contributions for + * bug 358827 - [1.7] exception analysis for t-w-r spoils null analysis + * bug 349326 - [1.7] new warning for missing try-with-resources + * bug 359334 - Analysis for resource leak warnings does not consider exceptions as method exit points + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class TryWithResourcesStatementTest extends AbstractRegressionTest { + +static { +// TESTS_NAMES = new String[] { "test380112e"}; +// 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 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 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() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.WARNING); + 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. WARNING in X.java (at line 5)\n" + + " Y why = new Y();\n" + + " ^^^\n" + + "Resource leak: 'why' is never closed\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Y why = new Y();\n" + + " ^^^^^^^\n" + + "Unhandled exception type WeirdException\n" + + "----------\n" + + "5. 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", + null, true, options); +} +// Resource nullness tests +public void test015() { + Runner runner = new Runner(); + runner.testFiles = + 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" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +// Dead code tests, resource nullness, unhandled exception tests +public void test016() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.WARNING); + 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. WARNING in X.java (at line 5)\n" + + " Y why = new Y();\n" + + " ^^^\n" + + "Resource leak: 'why' is never closed\n" + + "----------\n" + + "4. ERROR in X.java (at line 5)\n" + + " Y why = new Y();\n" + + " ^^^^^^^\n" + + "Unhandled exception type WeirdException\n" + + "----------\n" + + "5. 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", + null, + true, + options); +} +// Dead code tests +public void test017() { + Runner runner = new Runner(); + runner.testFiles = + 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" + }; + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " {}\n" + + " ^^\n" + + "Dead code\n" + + "----------\n"; + runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings; + runner.runWarningTest(); +} +// 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() { + Runner runner = new Runner(); + runner.customOptions = getCompilerOptions(); + runner.customOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + runner.customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + runner.customOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + runner.testFiles = + 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" + }; + runner.expectedCompilerLog = + "----------\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"; + runner.javacTestOptions = JavacTestOptions.forRelease("5"); + runner.runNegativeTest(); +} +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=348705 +// Variant of the above, witness for https://bugs.eclipse.org/358827#c6 +public void test053a() { + 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" + + " } finally {\n" + + " System.out.println();\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"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353535 (verify error with try with resources) +public void test055() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.ByteArrayInputStream;\n" + + "import java.io.InputStream;\n" + + "public class X {\n" + + "public static void main(String[] args) throws Exception {\n" + + " int b;\n" + + " try (final InputStream in = new ByteArrayInputStream(new byte[] { 42 })) {\n" + + " b = in.read();\n" + + " }\n" + + " System.out.println(\"Done\");\n" + + "}\n" + + "}\n", + }, + "Done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=353535 (verify error with try with resources) +public void test055a() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Throwable {\n" + + " int tmp;\n" + + " try (A a = null) {\n" + + " try (A b = null) {\n" + + " tmp = 0;\n" + + " }\n" + + " }\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + "}\n" + + "class A implements AutoCloseable {\n" + + " @Override\n" + + " public void close() {\n" + + " }\n" + + "}\n", + }, + "Done"); +} + +// Note: test056* have been moved to ResourceLeakTests.java + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=361053 +public void test057() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " @Override\n" + + " public void close() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " final boolean foo;\n" + + " try (X a = new X(); X b = new X()) {\n" + + " foo = true;\n" + + " } catch (final Exception exception) {\n" + + " return;\n" + + " }\n" + + " }\n" + + "}\n" + }, ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=364008 +public void test058() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.ByteArrayOutputStream;\n" + + "import java.io.FileOutputStream;\n" + + "import java.io.IOException;\n" + + "\n" + + "public class X {\n" + + "\n" + + " public static void main(final String[] args) throws IOException {\n" + + " byte[] data;\n" + + " try (final ByteArrayOutputStream os = new ByteArrayOutputStream();\n" + + " final FileOutputStream out = new FileOutputStream(\"test.dat\")) {\n" + + " data = os.toByteArray();\n" + + " }\n" + + " }\n" + + "}\n" + }, ""); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=367566 - In try-with-resources statement close() method of resource is not called +public void test059() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "\n" + + "public class X implements java.lang.AutoCloseable {\n" + + " static boolean isOpen = true;\n" + + " public static void main(final String[] args) throws IOException {\n" + + " foo();\n" + + " System.out.println(isOpen);\n" + + " }\n" + + " static boolean foo() {\n" + + " try (final X x = new X()) {\n" + + " return x.num() >= 1;\n" + + " }\n" + + " }\n" + + " int num() { return 2; }\n" + + " public void close() {\n" + + " isOpen = false;\n" + + " }\n" + + "}\n" + }, + "false"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=367566 - In try-with-resources statement close() method of resource is not called +public void test060() { + this.runConformTest( + new String[] { + "X.java", + "public class X implements AutoCloseable {\n" + + " static int num = 10 ;\n" + + " public static void main(String [] args) throws Exception { \n" + + " System.out.println(foo(1));\n" + + " System.out.println(foo(2));\n" + + " System.out.println(foo(3));\n" + + " }\n" + + " private static boolean foo(int where) throws Exception {\n" + + " final boolean getOut = true;\n" + + " System.out.println(\"Main\");\n" + + " try (X x1 = new X(); X x2 = new X()) {\n" + + " if (where == 1) {\n" + + " return where == 1;\n" + + " }\n" + + " System.out.println(\"Outer Try\");\n" + + " while (true) {\n" + + " try (Y y1 = new Y(); Y y2 = new Y()) { \n" + + " if (where == 2) {\n" + + " return where == 2;\n" + + " } \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 num >= 10;\n" + + " else\n" + + " break; \n" + + " }\n" + + " }\n" + + " }\n" + + " System.out.println(\"Out of while\");\n" + + " }\n" + + " return false;\n" + + " }\n" + + " public X() {\n" + + " System.out.println(\"X::X\");\n" + + " }\n" + + " @Override\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" + + " @Override\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" + + " @Override\n" + + " public void close() throws Exception {\n" + + " System.out.println(\"Z::~Z\");\n" + + " }\n" + + "}\n" + }, + "Main\n" + + "X::X\n" + + "X::X\n" + + "X::~X\n" + + "X::~X\n" + + "true\n" + + "Main\n" + + "X::X\n" + + "X::X\n" + + "Outer Try\n" + + "Y::Y\n" + + "Y::Y\n" + + "Y::~Y\n" + + "Y::~Y\n" + + "X::~X\n" + + "X::~X\n" + + "true\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" + + "true"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources) +public void test375248() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "import java.net.MalformedURLException;\n" + + "import java.net.URL;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " public void foo() throws MalformedURLException {\n" + + " URL url = new URL(\"dummy\"); //$NON-NLS-1$\n" + + " try (InputStream is = url.openStream()) {\n" + + " } catch (IOException e) {\n" + + " return;\n" + + " } finally {\n" + + " try {\n" + + " java.nio.file.Files.delete(null);\n" + + " } catch (IOException e1) {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "Done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources) +public void test375248a() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "import java.net.MalformedURLException;\n" + + "import java.net.URL;\n" + + "import java.nio.file.Path;\n" + + "import java.nio.file.StandardCopyOption;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " public void executeImports() throws MalformedURLException {\n" + + " for (int i = 0; i < 3; i++) {\n" + + " URL url = new URL(\"dummy\"); //$NON-NLS-1$\n" + + " if (url != null) {\n" + + " Path target = new File(\"dummy\").toPath();\n" + + " try (InputStream is = url.openStream()) {\n" + + " java.nio.file.Files.copy(is, target,\n" + + " StandardCopyOption.REPLACE_EXISTING);\n" + + " } catch (IOException e) {\n" + + " break;\n" + + " } finally {\n" + + " try {\n" + + " java.nio.file.Files.delete(target);\n" + + " } catch (IOException e1) {\n" + + "\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "Done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources) +public void test375248b() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "import java.net.MalformedURLException;\n" + + "import java.net.URL;\n" + + "import java.nio.file.Path;\n" + + "import java.nio.file.StandardCopyOption;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " System.out.println(\"Done\");\n" + + " }\n" + + " public void executeImports() throws MalformedURLException {\n" + + " for (int i = 0; i < 3; i++) {\n" + + " URL url = new URL(\"dummy\"); //$NON-NLS-1$\n" + + " if (url != null) {\n" + + " Path target = new File(\"dummy\").toPath();\n" + + " try (InputStream is = url.openStream()) {\n" + + " java.nio.file.Files.copy(is, target,\n" + + " StandardCopyOption.REPLACE_EXISTING);\n" + + " } catch (IOException e) {\n" + + " continue;\n" + + " } finally {\n" + + " try {\n" + + " java.nio.file.Files.delete(target);\n" + + " } catch (IOException e1) {\n" + + "\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n", + }, + "Done"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources) +public void test375248c() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "import java.net.MalformedURLException;\n" + + "import java.net.URL;\n" + + "import java.nio.file.Path;\n" + + "import java.nio.file.StandardCopyOption;\n" + + "\n" + + "public class X implements AutoCloseable {\n" + + " public void foo() {\n" + + " try (X x = new X()) {\n" + + " System.out.println(\"Try\");\n" + + " throw new Exception();\n" + + " } catch (Exception e) {\n" + + " System.out.println(\"Catch\");\n"+ + " return;\n" + + " } finally {\n" + + " System.out.println(\"Finally\");\n" + + " }\n" + + " }\n" + + " public void close() {\n" + + " System.out.println(\"Close\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "Try\n" + + "Close\n" + + "Catch\n" + + "Finally"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources) +public void test375248d() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.File;\n" + + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "import java.net.MalformedURLException;\n" + + "import java.net.URL;\n" + + "import java.nio.file.Path;\n" + + "import java.nio.file.StandardCopyOption;\n" + + "\n" + + "public class X implements AutoCloseable {\n" + + " public void foo() {\n" + + " try (X x = new X()) {\n" + + " System.out.println(\"Try\");\n" + + " } catch (Exception e) {\n" + + " System.out.println(\"Catch\");\n"+ + " return;\n" + + " } finally {\n" + + " System.out.println(\"Finally\");\n" + + " return;\n" + + " }\n" + + " }\n" + + " public void close() {\n" + + " System.out.println(\"Close\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new X().foo();\n" + + " }\n" + + "}\n" + }, + "Try\n" + + "Close\n" + + "Finally"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326 +public void test375326() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " HasAutoCloseable a;\n" + + " try(AutoCloseable b=(a=new HasAutoCloseable()).a) {\n" + + " }\n" + + " System.out.println(a);\n" + + " }\n" + + " public static class AutoCloseableA implements AutoCloseable {\n" + + " @Override\n" + + " public void close() {\n" + + " // TODO Auto-generated method stub\n" + + " }\n" + + " }\n" + + " public static class HasAutoCloseable {\n" + + " AutoCloseable a = new AutoCloseableA();\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326 +public void test375326a() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " HasAutoCloseable aLocal;\n" + + " try(AutoCloseable b=(new HasAutoCloseable()).a){\n" + + " aLocal = new HasAutoCloseable();\n" + + " }\n" + + " catch (Throwable e) {\n" + + " }\n" + + " System.out.println(aLocal.toString()); \n" + + " } \n" + + " public static class AutoCloseableA implements AutoCloseable{\n" + + " @Override\n" + + " public void close() {\n" + + " }\n" + + " }\n" + + " public static class HasAutoCloseable{\n" + + " AutoCloseable a=new AutoCloseableA(); \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " System.out.println(aLocal.toString()); \n" + + " ^^^^^^\n" + + "The local variable aLocal may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326 +public void test375326b() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " HasAutoCloseable aLocal;\n" + + " try(AutoCloseable b=(aLocal = new HasAutoCloseable()).a){\n" + + " \n" + + " }\n" + + " catch (Throwable e) {\n" + + " }\n" + + " System.out.println(aLocal.toString()); \n" + + " } \n" + + " public static class AutoCloseableA implements AutoCloseable{\n" + + " @Override\n" + + " public void close() {\n" + + " }\n" + + " }\n" + + " public static class HasAutoCloseable{\n" + + " AutoCloseable a=new AutoCloseableA(); \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " System.out.println(aLocal.toString()); \n" + + " ^^^^^^\n" + + "The local variable aLocal may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326 +public void test375326c() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) throws Exception {\n" + + " HasAutoCloseable a;\n" + + " try(AutoCloseable b=(a=new HasAutoCloseable()).a) {\n" + + " } finally {\n" + + " System.out.println(\"Finally\");\n" + + " }\n" + + " System.out.println(a);\n" + + " }\n" + + " public static class AutoCloseableA implements AutoCloseable {\n" + + " @Override\n" + + " public void close() {\n" + + " // TODO Auto-generated method stub\n" + + " }\n" + + " }\n" + + " public static class HasAutoCloseable {\n" + + " AutoCloseable a = new AutoCloseableA();\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " }\n" + + "}" + }, + "Finally\n" + + "SUCCESS"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326 +public void test375326d() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " HasAutoCloseable aLocal;\n" + + " try(AutoCloseable b=(new HasAutoCloseable()).a){\n" + + " aLocal = new HasAutoCloseable();\n" + + " }\n" + + " catch (Throwable e) {\n" + + " } finally {\n" + + " System.out.println(\"Finally\");\n" + + " }\n" + + " System.out.println(aLocal.toString()); \n" + + " } \n" + + " public static class AutoCloseableA implements AutoCloseable{\n" + + " @Override\n" + + " public void close() {\n" + + " }\n" + + " }\n" + + " public static class HasAutoCloseable{\n" + + " AutoCloseable a=new AutoCloseableA(); \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " System.out.println(aLocal.toString()); \n" + + " ^^^^^^\n" + + "The local variable aLocal may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326 +public void test375326e() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String [] args) throws Exception {\n" + + " HasAutoCloseable aLocal;\n" + + " try(AutoCloseable b=(aLocal = new HasAutoCloseable()).a){\n" + + " \n" + + " }\n" + + " catch (Throwable e) {\n" + + " } finally {\n" + + " System.out.println(\"Finally\");\n" + + " }\n" + + " System.out.println(aLocal.toString()); \n" + + " } \n" + + " public static class AutoCloseableA implements AutoCloseable{\n" + + " @Override\n" + + " public void close() {\n" + + " }\n" + + " }\n" + + " public static class HasAutoCloseable{\n" + + " AutoCloseable a=new AutoCloseableA(); \n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " System.out.println(aLocal.toString()); \n" + + " ^^^^^^\n" + + "The local variable aLocal may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326 +public void test375326f() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void testWithResourcesAssignment() throws Exception{\n" + + " HasAutoCloseable a;\n" + + " try(AutoCloseable b=(a=new HasAutoCloseable()).a){\n" + + " } finally {\n" + + " System.out.println(a);\n" + + " }\n" + + " }\n" + + " public class AutoCloseableA implements AutoCloseable{\n" + + " @Override\n" + + " public void close() {\n" + + " }\n" + + " }\n" + + " public class HasAutoCloseable{\n" + + " AutoCloseable a=new AutoCloseableA();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " System.out.println(a);\n" + + " ^\n" + + "The local variable a may not have been initialized\n" + + "----------\n"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326 +public void test375326g() { + this.runNegativeTest( + new String[] { + "X.java", + "class CheckedException extends Throwable {}\n" + + "public class X {\n" + + " public void testWithResourcesAssignment() throws Exception{\n" + + " HasAutoCloseable a;\n" + + " try(AutoCloseable b=(a=new HasAutoCloseable()).a){\n" + + " throw new CheckedException();\n" + + " } catch (CheckedException e) {\n" + + " System.out.println(a);\n" + + " } finally {\n" + + " System.out.println(a);\n" + + " }\n" + + " }\n" + + " public class AutoCloseableA implements AutoCloseable{\n" + + " @Override\n" + + " public void close() {\n" + + " }\n" + + " }\n" + + " public class HasAutoCloseable{\n" + + " AutoCloseable a=new AutoCloseableA();\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " class CheckedException extends Throwable {}\n" + + " ^^^^^^^^^^^^^^^^\n" + + "The serializable class CheckedException does not declare a static final serialVersionUID field of type long\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " System.out.println(a);\n" + + " ^\n" + + "The local variable a may not have been initialized\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " System.out.println(a);\n" + + " ^\n" + + "The local variable a may not have been initialized\n" + + "----------\n"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=380112 +public void test380112a() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "interface I extends Closeable, Serializable {}\n" + + "public class X {\n"+ + " public static void main(String [] args) {\n" + + " try (I i = getX()) {\n" + + " } catch (IOException x) {\n" + + " }\n"+ + " System.out.println(\"Done\");\n" + + " }\n" + + " public static I getX() { return null;}\n"+ + " public X(){}\n" + + "}\n" + }, + "Done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=380112 +//variant with finally +public void test380112b() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "interface I extends Closeable, Serializable {}\n" + + "public class X {\n"+ + " public static void main(String [] args) {\n" + + " try (I i = getX()) {\n" + + " } catch (IOException x) {\n" + + " } finally {\n"+ + " System.out.println(\"Done\");\n" + + " }\n" + + " }\n" + + " public static I getX() { return null;}\n"+ + " public X(){}\n" + + "}\n" + }, + "Done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=380112 +//variant with two methods throwing different Exceptions (one subtype of other) +//subtype should be the one to be caught +public void test380112c() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "interface I2 { public void close() throws FileNotFoundException; }\n"+ + "interface I extends Closeable, I2 {}\n" + + "public class X {\n"+ + " public static void main(String [] args) {\n" + + " try (I i = getX()) {\n" + + " } catch (FileNotFoundException x) {\n" + + " }\n"+ + " System.out.println(\"Done\");\n" + + " }\n" + + " public static I getX() { return null;}\n"+ + " public X(){}\n" + + "}\n" + }, + "Done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=380112 +//test380112c's variant with finally +public void test380112d() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "interface I2 { public void close() throws FileNotFoundException; }\n"+ + "interface I extends Closeable, I2 {}\n" + + "public class X {\n"+ + " public static void main(String [] args) {\n" + + " try (I i = getX()) {\n" + + " } catch (FileNotFoundException x) {\n" + + " } finally {\n"+ + " System.out.println(\"Done\");\n" + + " }\n" + + " }\n" + + " public static I getX() { return null;}\n"+ + " public X(){}\n" + + "}\n" + }, + "Done"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=380112 +//test380112a variant moving the Interface into a binary +public void test380112e() { + String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test380112.jar"; + String[] defaultLibs = getDefaultClassPaths(); + String[] libs = new String[defaultLibs.length + 1]; + System.arraycopy(defaultLibs, 0, libs, 0, defaultLibs.length); + libs[defaultLibs.length] = path; + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "import pkg380112.I;\n" + + "public class X {\n"+ + " public static void main(String [] args) {\n" + + " try (I i = getX()) {\n" + + " } catch (IOException x) {\n" + + " }\n"+ + " System.out.println(\"Done\");\n" + + " }\n" + + " public static I getX() { return null;}\n"+ + " public X(){}\n" + + "}\n" + }, "Done", libs, true, new String[] {"-cp", "."+File.pathSeparator+path}); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=394780 +public void test394780() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " X m = new X<>();\n" + + " m.tryWithResource(new ResourceImpl());\n" + + " }\n" + + " public void tryWithResource(R resource) {\n" + + " try (R r = resource) {\n" + + " r.compute();\n" + + " }\n" + + " }\n" + + "}", + "Resource.java", + "public interface Resource extends AutoCloseable {\n" + + " void compute();\n" + + " @Override\n" + + " public void close();\n" + + "}", + "ResourceImpl.java", + "public class ResourceImpl implements Resource {\n" + + " @Override\n" + + " public void close() {\n" + + " System.out.print(\"close\");\n" + + " }\n" + + " @Override\n" + + " public void compute() {\n" + + " System.out.print(\"compute\");\n" + + " }\n" + + "}" + }, + "computeclose"); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=533187 +public void testBug533187() { + this.runConformTest( + true, + new String[] { + "Stuck.java", + "public class Stuck {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(snippet1());\n" + + " }\n" + + " public static String snippet1() {\n" + + " try {\n" + + " synchronized (String.class) {\n" + + " try (AutoCloseable scope = null) { \n" + + " return \"RETURN\";\n" + + " } catch (Throwable t) {\n" + + " return t.toString();\n" + + " }\n" + + " }\n" + + " } finally {\n" + + " raise();\n" + + " }\n" + + " }\n" + + " public static void raise() {\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}" + }, + null, + null, + null, + null, + "java.lang.RuntimeException\n" + + " at Stuck.raise(Stuck.java:19)\n" + + " at Stuck.snippet1(Stuck.java:15)\n" + + " at Stuck.main(Stuck.java:3)\n", + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=467230 +public void testBug467230() { + this.runConformTest( + true, + new String[] { + "Test.java", + "public class Test {\n" + + " static class C implements AutoCloseable {\n" + + " @Override\n" + + " public void close() {\n" + + " System.out.println(\"close\");\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " try (C c = new C()) {\n" + + " return;\n" + + " } catch (Exception e) {\n" + + " System.out.println(\"catch\");\n" + + " } finally {\n" + + " f();\n" + + " }\n" + + " }\n" + + " private static void f() {\n" + + " System.out.println(\"finally\");\n" + + " throw new RuntimeException();\n" + + " }\n" + + "}" + }, + null, + null, + null, + "close\n" + + "finally", + "java.lang.RuntimeException\n" + + " at Test.f(Test.java:19)\n" + + " at Test.main(Test.java:14)\n", + null); +} +public static Class testClass() { + return TryWithResourcesStatementTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java new file mode 100644 index 0000000000..29b91a9510 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java @@ -0,0 +1,6967 @@ +/******************************************************************************* + * Copyright (c) 2011, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Andy Clement (GoPivotal, Inc) aclement@gopivotal.com - Contributions for + * Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work) + * Bug 409236 - [1.8][compiler] Type annotations on intersection cast types dropped by code generator + * Bug 409246 - [1.8][compiler] Type annotations on catch parameters not handled properly + * Bug 409517 - [1.8][compiler] Type annotation problems on more elaborate array references + * Bug 415821 - [1.8][compiler] CLASS_EXTENDS target type annotation missing for anonymous classes + * Bug 426616 - [1.8][compiler] Type Annotations, multiple problems + * Stephan Herrmann - Contribution for + * Bug 415911 - [1.8][compiler] NPE when TYPE_USE annotated method with missing return type + * Bug 416176 - [1.8][compiler][null] null type annotations cause grief on type variables + * Jesper S Moller - Contributions for + * Bug 416885 - [1.8][compiler]IncompatibleClassChange error (edit) + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; +import java.util.Map; + +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest.JavacTestOptions.JavacHasABug; +import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; +import org.eclipse.jdt.internal.compiler.Compiler; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding; +import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; +import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class TypeAnnotationTest extends AbstractRegressionTest { + + static { +// TESTS_NUMBERS = new int [] { 40 }; +// TESTS_NAMES = new String[] { "testTypeVariable" }; + } + public static Class testClass() { + return TypeAnnotationTest.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); + } + public TypeAnnotationTest(String testName){ + super(testName); + } + + // Enables the tests to run individually + @Override + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + defaultOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); + defaultOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + return defaultOptions; + } + + private static final String HELPER_CLASS = + "import java.lang.annotation.*;\n"+ + "import java.lang.reflect.*;\n"+ + "class Helper {\n"+ + "\n"+ + // Print type annotations on super types + " public static void printTypeAnnotations(Class clazz) {\n"+ + " System.out.print(\"Annotations on superclass of \"+clazz.getName() +\"\\n\");\n"+ + " AnnotatedType superat = clazz.getAnnotatedSuperclass();\n"+ + " Helper.printAnnos(\" \", superat.getType(),superat.getAnnotations());\n"+ + " AnnotatedType[] superinterfaces = clazz.getAnnotatedInterfaces();\n"+ + " if (superinterfaces.length!=0) {\n"+ + " System.out.print(\"Annotations on superinterfaces of \"+clazz.getName() +\"\\n\");\n"+ + " for (int j=0;j clazz) {\n"+ + " System.out.print(clazz.getName()+\"<\");\n"+ + " TypeVariable[] tvs = clazz.getTypeParameters();\n"+ + " for (int t=0;t tv = tvs[t];\n"+ + " Annotation[] annos = tv.getAnnotations();\n"+ + " for (int a=0;a\\n\");\n"+ + " }\n"+ + " public static String toStringAnno(Annotation anno) {\n"+ + " String s = anno.toString();\n"+ + " s = s.replace(\"\\\"\", \"\");\n" + + " s = s.replace(\"'\", \"\");\n" + + " if (s.endsWith(\"()\")) return s.substring(0,s.length()-2); else return s;\n"+ + " }\n"+ + " \n"+ + " public static void printAnnos(String header, Type t, Annotation[] annos) {\n"+ + " if (annos.length==0) { System.out.print(header+t+\":no annotations\\n\"); return;} \n"+ + " System.out.print(header+t+\":\");\n"+ + " for (int i=0;i {}", + + "Marker.java", + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@Target(ElementType.TYPE_PARAMETER)\n" + + "@interface Marker {}", + }, + ""); + // javac-b81: 9[0 1 0 0 0 0 13 0 0] (13=Marker annotation) + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @Marker(\n" + + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test002_classTypeParameter_reflection() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X<@Marker T> {\n"+ + " public static void main(String[] argv) { Helper.printTypeAnnotations2(X.class);}\n"+ + "}", + + "Helper.java",HELPER_CLASS, + "Marker.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@Target(TYPE_PARAMETER)\n" + + "@interface Marker {}", + }, + "X<@Marker T>"); + } + + public void test003_classTypeParameter() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X<@A1 T1,@A2 @A3 T2> {}", + + "A1.java", + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@Target(ElementType.TYPE_PARAMETER)\n" + + "@interface A1 {}", + + "A2.java", + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@Target(ElementType.TYPE_PARAMETER)\n" + + "@interface A2 {}", + + "A3.java", + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@Target(ElementType.TYPE_PARAMETER)\n" + + "@interface A3 {}", + + }, + ""); + // javac-b81: 9[0 1 0 0 0 0 13 0 0] (13=Marker) + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @A1(\n" + + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 0\n" + + " )\n" + + " #22 @A2(\n" + + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 1\n" + + " )\n" + + " #23 @A3(\n" + + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test004_classTypeParameter_reflection() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X<@A1 T1,@A2 @A3 T2> {\n"+ + " public static void main(String[] argv) { Helper.printTypeAnnotations2(X.class); }\n"+ + "}", + + "Helper.java",HELPER_CLASS, + "A1.java", + "import java.lang.annotation.*;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@Target(ElementType.TYPE_PARAMETER)\n" + + "@interface A1 {}", + "A2.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@Target(TYPE_PARAMETER)\n" + + "@interface A2 {}", + "A3.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@Target(TYPE_PARAMETER)\n" + + "@interface A3 {}", + }, + "X<@A1 T1,@A2 @A3 T2>"); + } + + public void test005_classTypeParameter() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_PARAMETER)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_PARAMETER)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X<@A @B(3) T> {}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #25 @A(\n" + + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 0\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @B(\n" + + " #22 value=(int) 3 (constant type)\n" + + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test006_classTypeParameter() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_PARAMETER)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_PARAMETER)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X {}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #25 @A(\n" + + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 2\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @B(\n" + + " #22 value=(int) 3 (constant type)\n" + + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 2\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test007_methodTypeParameter() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_PARAMETER)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_PARAMETER)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X {\n" + + " <@A @B(3) T> void foo(T t) {}\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #27 @A(\n" + + " target type = 0x1 METHOD_TYPE_PARAMETER\n" + + " type parameter index = 0\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #23 @B(\n" + + " #24 value=(int) 3 (constant type)\n" + + " target type = 0x1 METHOD_TYPE_PARAMETER\n" + + " type parameter index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test008_methodTypeParameter() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_PARAMETER)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_PARAMETER)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X {\n" + + " void foo(T1 t1,T2 t2) {}\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #29 @A(\n" + + " target type = 0x1 METHOD_TYPE_PARAMETER\n" + + " type parameter index = 1\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #25 @B(\n" + + " #26 value=(int) 3 (constant type)\n" + + " target type = 0x1 METHOD_TYPE_PARAMETER\n" + + " type parameter index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test009_classExtends() throws Exception { + this.runConformTest( + new String[] { + "Marker.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Target(TYPE_USE)\n" + + "@interface Marker {}", + "X.java", + "public class X extends @Marker Object {}", + }, + ""); + // javac-b81 annotation contents: len:10[0 1 16 -1 -1 0 0 17 0 0] + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #17 @Marker(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = -1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test010_classExtends() throws Exception { + this.runConformTest( + new String[] { + "Marker.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@Target(TYPE_USE)\n" + + "@interface Marker {}", + "X.java", + "public class X extends @Marker Object {}", + }, + ""); + // Bytes:10[0 1 16 -1 -1 0 0 17 0 0] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #17 @Marker(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = -1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test011_classExtends_reflection() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X extends @Marker Object {public static void main(String[] argv) {Helper.printTypeAnnotations(X.class);}}", + "Helper.java",HELPER_CLASS, + "Marker.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Target(TYPE_USE)\n" + + "@interface Marker {}" + }, + "Annotations on superclass of X\n"+ + " class java.lang.Object:no annotations"); + } + + public void test012_classExtends_reflection() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X extends @Marker Object {public static void main(String[] argv) {Helper.printTypeAnnotations(X.class);}}", + "Helper.java",HELPER_CLASS, + "Marker.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n"+ + "@interface Marker {}" + }, + "Annotations on superclass of X\n"+ + " class java.lang.Object:@Marker"); + } + + public void test013_classExtends_interfaces() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String id() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X implements @A(id=\"Hello, World!\") I, @B @C('(') J {}", + }, + ""); + // Output from javac b81 lambda + // RuntimeVisibleTypeAnnotations + // Bytes:28[0 2 16 0 0 0 0 13 0 1 0 14 115 0 15 16 0 1 0 0 16 0 1 0 17 67 0 18] + // RuntimeInvisibleTypeAnnotations + // Bytes:10[0 1 16 0 1 0 0 20 0 0] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #23 @A(\n" + + " #24 id=\"Hello, World!\" (constant type)\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " )\n" + + " #26 @C(\n" + + " #27 value=\'(\' (constant type)\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 1\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @B(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test014_classExtends_interfaces_reflection() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X implements @A I {public static void main(String[]argv) {Helper.printTypeAnnotations(X.class);}}", + "Helper.java",HELPER_CLASS, + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + "}\n", + "I.java", + "interface I {}\n" + }, + "Annotations on superclass of X\n" + + " class java.lang.Object:no annotations\n" + + "Annotations on superinterfaces of X\n" + + " interface I:@A"); + } + + public void test015_classExtends_interfaces_reflection() throws Exception { + String javaVersion = System.getProperty("java.version"); + int index = javaVersion.indexOf('.'); + if (index != -1) { + javaVersion = javaVersion.substring(0, index); + } else { + index = javaVersion.indexOf('-'); + if (index != -1) + javaVersion = javaVersion.substring(0, index); + } + int v = Integer.parseInt(javaVersion); + this.runConformTest( + new String[] { + "X.java", + "public class X implements @A(id=\"Hello, World!\") I, @B @C('i') J {public static void main(String[] argv) { Helper.printTypeAnnotations(X.class);}}", + "Helper.java",HELPER_CLASS, + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String id() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + }, + "Annotations on superclass of X\n" + + " class java.lang.Object:no annotations\n" + + "Annotations on superinterfaces of X\n" + + " interface I:@A(id=Hello, World!) \n" + + " interface J:@C(" + (v < 14 ? "value=" : "") + "i)"); + } + + public void test016_classExtends() throws Exception { + this.runConformTest( + new String[] { + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "Y.java", + "class Y {}\n", + "X.java", + "public class X extends Y<@B String> {\n" + + "}", + }, + ""); + // javac-b81: Bytes:12[0 1 16 -1 -1 1 3 0 0 13 0 0] // type path: 1,3,0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #19 @B(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = -1\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test017_classExtends() throws Exception { + this.runConformTest( + new String[] { + "Marker.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Marker { }\n", + "I.java", + "interface I {}\n", + "X.java", + "public class X implements I<@Marker String> {\n" + + "}", + }, + ""); + // javac-b81: Bytes:12[0 1 16 0 0 1 3 0 0 14 0 0] // type path: 1,3,0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @Marker(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test018_classExtends() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A { }\n", + + "I.java", + "interface I {}\n", + + "X.java", + "public class X implements I {}\n" + }, + ""); + // javac-b81: Bytes:12[0 1 16 0 0 1 3 1 0 14 0 0] // type path: 1,3,1 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @A(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test019_classExtends() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A { }\n", + + "J.java", + "interface J {}\n", + + "I.java", + "interface I {}\n", + + "X.java", + "public class X implements I> {}\n" + }, + ""); + // javac-b81: Bytes:14[0 1 16 0 0 2 3 0 3 0 0 14 0 0] // type path: 2,3,0,3,0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @A(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(0), TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test020_classExtends() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A { }\n", + + "I.java", + "interface I {}\n", + + "X.java", + "public class X implements I<@A String[]> {}\n" + }, + ""); + // javac-b81: Bytes:14[0 1 16 0 0 2 3 0 0 0 0 14 0 0] // type path: 2,3,0,0,0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @A(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(0), ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test021_classExtends() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A { }\n", + + "I.java", + "interface I {}\n", + + "X.java", + "public class X implements I {}\n" + }, + ""); + // javac-b81: Bytes:12[0 1 16 0 0 1 3 0 0 14 0 0] // type path: 1,3,0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @A(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test022_classExtends() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A { }\n", + + "I.java", + "interface I {}\n", + + "X.java", + "public class X implements I {}\n" + }, + ""); + // javac-b81: Bytes:14[0 1 16 0 0 2 3 0 0 0 0 14 0 0] // type path: 2,3,0,0,0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @A(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(0), ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test023_classExtends() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A { }\n", + + "I.java", + "interface I {}\n", + + "X.java", + "public class X implements I<@A String [][][]> {}\n" + }, + ""); + // javac-b81: Bytes:10[0 1 16 0 0 0 0 12 0 0] // type path: 4,3,0,0,0,0,0,0,0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @A(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + + public void test024_classExtends() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X implements I<@A(\"Hello, World!\") String>, @B J {}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #25 @A(\n" + + " #26 value=\"Hello, World!\" (constant type)\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #28 @C(\n" + + " #26 value=\'(\' (constant type)\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 1\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #23 @B(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test025_classTypeParameterBound() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {}", + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {}\n" + }, + ""); + // javac-b81: Bytes:10[0 1 17 0 0 0 0 13 0 0] + // [17 0 0] is CLASS_PARAMETER_BOUND type_parameter_index=0 bound_index=0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @A(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test026_classTypeParameterBound() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X {}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #25 @A(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 0\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @B(\n" + + " #22 value=(int) 3 (constant type)\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 1\n" + + " )\n" ; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test027_classTypeParameterBound_complex() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "Y.java", + "public class Y {}", + "X.java", + "public class X & @B(3) Cloneable> {}", + }, + ""); + // javac-b81: + // Bytes:28[0 2 17 1 0 1 3 0 0 13 0 0 17 1 0 4 3 0 0 0 0 0 0 0 0 14 0 0] + // Bytes:29[0 2 17 1 0 3 3 0 0 0 0 0 0 16 0 0 17 1 1 0 0 16 0 1 0 17 73 0 18] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #25 @A(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 1 type parameter bound index = 0\n" + + " location = [TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #26 @C(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 1 type parameter bound index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @B(\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 1 type parameter bound index = 0\n" + + " location = [TYPE_ARGUMENT(0), ARRAY, ARRAY]\n" + + " )\n" + + " #21 @B(\n" + + " #22 value=(int) 3 (constant type)\n" + + " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 1 type parameter bound index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test028_methodTypeParameterBound() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "Z.java", + "public class Z {}", + "X.java", + "public class X {\n" + + " void foo(T t) {}\n" + + "}", + }, + ""); + // javac-b81: Bytes:10[0 1 18 0 0 0 0 13 0 0] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #23 @A(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test029_methodTypeParameterBound() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "Z.java", + "public class Z {}", + "X.java", + "public class X {\n" + + " void foo(T t) {}\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #27 @A(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 0\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #23 @B(\n" + + " #24 value=(int) 3 (constant type)\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test030_methodTypeParameterBound() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "Z.java", + "public class Z {}", + "Y.java", + "public class Y {}", + "X.java", + "public class X {\n" + + " & Cloneable> void foo(T t) {}\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #23 @B(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 0\n" + + " location = [TYPE_ARGUMENT(0), ARRAY, ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test031_methodTypeParameterBound_complex() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "Z.java", + "public class Z {}", + "Y.java", + "public class Y {}", + "X.java", + "public class X {\n" + + " & @B(3) Cloneable> void foo(T t) {}\n" + + "}", + }, + ""); + // javac-b81: + // Bytes:28[0 2 18 0 0 1 3 0 0 13 0 0 18 0 0 4 3 0 0 0 0 0 0 0 0 14 0 0] + // Bytes:29[0 2 18 0 0 3 3 0 0 0 0 0 0 16 0 0 18 0 1 0 0 16 0 1 0 17 73 0 18] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #27 @A(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 0\n" + + " location = [TYPE_ARGUMENT(0), ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #28 @C(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #23 @B(\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 0\n" + + " location = [TYPE_ARGUMENT(0), ARRAY, ARRAY]\n" + + " )\n" + + " #23 @B(\n" + + " #24 value=(int) 3 (constant type)\n" + + " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" + + " type parameter index = 0 type parameter bound index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test032_field() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {}\n", + + "X.java", + "public class X {\n" + + " @A int field;\n" + + "}", + }, + ""); + // javac-b81: Bytes:8[0 1 19 0 0 7 0 0] 19 = 0x13 (FIELD) + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @A(\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test033_field() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {}\n", + + "X.java", + "public class X {\n" + + " java.util.List<@A String> field;\n" + + "}", + }, + ""); + // javac-b81: Bytes:10[0 1 19 1 3 0 0 9 0 0] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @A(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test034_field() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X {\n" + + " @B(3) @A int field;\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #12 @A(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test035_field() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {}\n", + + "X.java", + "public class X {\n" + + " java.util.Map field;\n" + + "}", + }, + ""); + // javac-b81: Bytes:10[0 1 19 1 3 1 0 9 0 0] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @A(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test036_field() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {}\n", + + "X.java", + "public class X {\n" + + " java.util.List field;\n" + + "}", + }, + ""); + // javac-b81: Bytes:14[0 1 19 3 3 0 0 0 0 0 0 9 0 0] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @A(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), ARRAY, ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test037_field() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " java.util.List field;\n" + + "}", + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {}\n", + }, + ""); + // javac-b81: Bytes:12[0 1 19 2 3 0 2 0 0 9 0 0] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @A(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), WILDCARD]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test038_field() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class AA { class BB {}}" + + "class X {\n" + + " AA.@A BB field;\n" + + "}\n", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A { }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @A(\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test038a_field() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class AA { class BB {}}" + + "class X {\n" + + " @B AA.@A BB[] @C[] field;\n" + + "}\n", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A { }\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { }\n", + + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C { }\n", + }, + ""); + + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #9 @A(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE]\n" + + " )\n" + + " #10 @C(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test039_field() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X {\n" + + " @A int [] @B(3) [] field;\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #12 @A(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test040_field_complex() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Map;\n" + + "import java.util.List;\n" + + "public class X {\n" + + " @H String @E[] @F[] @G[] field;\n" + + " @A Map<@B String, @C List<@D Object>> field2;\n" + + " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" + + "}", + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "D.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface D {\n" + + " String value() default \"default\";\n" + + "}\n", + "E.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface E {\n" + + " int value() default -1;\n" + + "}", + "F.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface F {\n" + + " char value() default '-';\n" + + "}\n", + "G.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface G {\n" + + " int value() default -1;\n" + + "}", + "H.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface H {\n" + + " char value() default '-';\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Field descriptor #6 [[[Ljava/lang/String;\n" + + " java.lang.String[][][] field;\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #11 @H(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #12 @F(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @E(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #9 @G(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " \n" + + " // Field descriptor #14 Ljava/util/Map;\n" + + " // Signature: Ljava/util/Map;>;\n" + + " java.util.Map field2;\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #18 @A(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #19 @C(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n" + + " #20 @D(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1), TYPE_ARGUMENT(0)]\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #17 @B(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " \n" + + " // Field descriptor #14 Ljava/util/Map;\n" + + " // Signature: Ljava/util/Map;\n" + + " java.util.Map field3;\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #18 @A(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #11 @H(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1), ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #12 @F(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1), ARRAY]\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #17 @B(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #8 @E(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n" + + " #9 @G(\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1), ARRAY, ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test041_field() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " java.lang.@H String @E[] @F[] @G[] field;\n" + + "}", + "E.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface E {\n" + + " int value() default -1;\n" + + "}", + "F.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface F {\n" + + " char value() default '-';\n" + + "}\n", + "G.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface G {\n" + + " int value() default -1;\n" + + "}", + "H.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface H {\n" + + " char value() default '-';\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #11 @H(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #12 @F(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @E(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #9 @G(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test042_methodReturnType() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X {\n" + + " @B(3) @A(value=\"test\") int foo() {\n" + + " return 1;\n" + + " }\n" + + "}", + }, + ""); + // javac-b81: + // Bytes:13[0 1 20 0 0 11 0 1 0 12 115 0 13] + // Bytes:13[0 1 20 0 0 15 0 1 0 12 73 0 16] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @A(\n" + + " #18 value=\"test\" (constant type)\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #17 @B(\n" + + " #18 value=(int) 3 (constant type)\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test043_methodReceiver() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X {\n" + + " void foo(@B(3) X this) {}\n" + + "}", + }, + ""); + // javac-b81: Bytes:13[0 1 21 0 0 10 0 1 0 11 73 0 12] + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #16 @B(\n" + + " #17 value=(int) 3 (constant type)\n" + + " target type = 0x15 METHOD_RECEIVER\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test044_methodReceiver() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(X<@B(3) T> this) {}\n" + + "}", + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + }, + ""); + // javac-b81: Bytes:15[0 1 21 1 3 0 0 10 0 1 0 11 73 0 12] + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #18 @B(\n" + + " #19 value=(int) 3 (constant type)\n" + + " target type = 0x15 METHOD_RECEIVER\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + + public void test045_methodParameter() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int foo(@B(3) String s) {\n" + + " return s.length();\n" + + " }\n" + + "}", + + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + }, + ""); + // javac-b81: Bytes:14[0 1 22 0 0 0 11 0 1 0 12 73 0 13] + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #25 @B(\n" + + " #26 value=(int) 3 (constant type)\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test046_methodParameter() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int foo(int i, double d, @B(3) String s) {\n" + + " return s.length();\n" + + " }\n" + + "}", + + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + }, + ""); + // javac-b81: Bytes:14[0 1 22 1 0 0 11 0 1 0 12 73 0 13] + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #29 @B(\n" + + " #30 value=(int) 3 (constant type)\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 2\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test047_methodParameterArray() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X {\n" + + " int foo(String @A [] @B(3) [] s) {\n" + + " return s.length;\n" + + " }\n" + + "}", + }, + ""); + // javac-b81: + // Bytes:9[0 1 22 0 0 0 11 0 0] + // Bytes:16[0 1 22 0 1 0 0 0 13 0 1 0 14 73 0 15] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #23 @A(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #19 @B(\n" + + " #20 value=(int) 3 (constant type)\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test048_throws() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n"+ + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n"+ + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.*;\n"+ + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "E.java", + "class E extends RuntimeException {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n", + "E1.java", + "class E1 extends RuntimeException {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n", + "E2.java", + "class E2 extends RuntimeException {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n", + "X.java", + "public class X {\n" + + " void foo() throws @A(\"Hello, World!\") E, E1, @B @C('(') E2 {}\n" + + "}", + }, + ""); + // javac-b81: + // Bytes:28[0 2 23 0 0 0 0 14 0 1 0 15 115 0 16 23 0 2 0 0 17 0 1 0 15 67 0 18] + // Bytes:10[0 1 23 0 2 0 0 20 0 0] + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #25 @A(\n" + + " #26 value=\"Hello, World!\" (constant type)\n" + + " target type = 0x17 THROWS\n" + + " throws index = 0\n" + + " )\n" + + " #28 @C(\n" + + " #26 value=\'(\' (constant type)\n" + + " target type = 0x17 THROWS\n" + + " throws index = 2\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #23 @B(\n" + + " target type = 0x17 THROWS\n" + + " throws index = 2\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + + public void test049_codeblocks_localVariable() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " @B int j = 9;\n" + + " try {\n" + + " System.out.print(\"SUCCESS\" + j);\n" + + " } catch(@A Exception e) {\n" + + " }\n" + + " @B int k = 3;\n" + + " System.out.println(k);\n" + + " }\n" + + "}", + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " String value() default \"default\";\n" + + "}\n", + }, + "SUCCESS93"); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #56 @B(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 3, pc: 39] index: 1\n" + + " )\n" + + " #56 @B(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 31, pc: 39] index: 2\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test050_codeblocks_localVariable() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "X.java", + "public class X {\n" + + " String[][] bar() {\n" + + " return new String[][] {};" + + " }\n" + + " void foo(String s) {\n" + + " @C int i;\n" + + " @A String [] @B(3)[] tab = bar();\n" + + " if (tab != null) {\n" + + " i = 0;\n" + + " System.out.println(i + tab.length);\n" + + " } else {\n" + + " System.out.println(tab.length);\n" + + " }\n" + + " i = 4;\n" + + " System.out.println(-i + tab.length);\n" + + " }\n" + + "}", + }, + ""); + // javac-b81: + // Bytes:34[0 2 64 0 1 0 34 0 12 0 2 0 0 19 0 0 64 0 1 0 5 0 41 0 3 2 0 0 0 0 0 20 0 0] + // Bytes:23[0 1 64 0 1 0 5 0 41 0 3 1 0 0 0 22 0 1 0 23 73 0 24] + // ECJ data varies a little here as it is splitting the range + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #45 @B(\n" + + " #46 value=(int) 3 (constant type)\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 5, pc: 46] index: 3\n" + + " location = [ARRAY]\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #49 @C(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 11, pc: 24] index: 2\n" + + " [pc: 34, pc: 46] index: 2\n" + + " )\n" + + " #50 @A(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 5, pc: 46] index: 3\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test051_codeblocks_resourceVariable() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "import java.io.*;\n"+ + "public class X {\n" + + " public static void main(String[] argv) throws Exception {\n"+ + " try (@A BufferedReader br1 = new BufferedReader(new FileReader(\"a\"));\n"+ + " @B(99) BufferedReader br2 = new BufferedReader(new FileReader(\"b\"))) {\n"+ + " System.out.println(br1.readLine()+br2.readLine());\n" + + " }\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #81 @B(\n" + + " #82 value=(int) 99 (constant type)\n" + + " target type = 0x41 RESOURCE_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 39, pc: 94] index: 4\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #85 @A(\n" + + " target type = 0x41 RESOURCE_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 21, pc: 135] index: 3\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test052_codeblocks_exceptionParameter() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " Exception test = new Exception() {\n" + + " private static final long serialVersionUID = 1L;\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " };\n" + + " try {\n" + + " System.out.println(test);\n" + + " } catch(@A Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + }, + "SUCCESS"); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #44 @A(\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test053_codeblocks_exceptionParameter() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " @A Exception test = new Exception() {\n" + + " private static final long serialVersionUID = 1L;\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"SUCCESS\";\n" + + " }\n" + + " };\n" + + " try {\n" + + " System.out.println(test);\n" + + " } catch(@A Exception e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + }, + "SUCCESS"); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #44 @A(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 8, pc: 24] index: 1\n" + + " )\n" + + " #44 @A(\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test054_codeblocks_exceptionParameter() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(42);\n" + + " } catch(@B(1) RuntimeException e) {\n" + + " e.printStackTrace();\n" + + " } catch(@B(2) Throwable t) {\n" + + " t.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface B {\n" + + " int value() default 99;\n" + + "}\n", + }, + "42"); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #44 @B(\n" + + " #45 value=(int) 1 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n" + + " #44 @B(\n" + + " #45 value=(int) 2 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test055_codeblocks_exceptionParameterMultiCatch() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "class Exc1 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "class Exc2 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "class Exc3 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(42);\n" + + // @B(1) is attached to the argument, the others are attached to the type reference in the union type reference + // During Parsing the @B(1) is moved from the argument to Exc1 + " } catch(@B(1) Exc1 | Exc2 | @B(2) Exc3 t) {\n" + + " t.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface B {\n" + + " int value() default 99;\n" + + "}\n", + }, + "42"); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #45 @B(\n" + + " #46 value=(int) 1 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n" + + " #45 @B(\n" + + " #46 value=(int) 2 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 2\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test056_codeblocks_instanceof() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Object o) {\n" + + " if (o instanceof @A String) {\n" + + " String tab = (String) o;\n" + + " System.out.println(tab);\n" + + " }\n" + + " System.out.println(o);\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #38 @A(\n" + + " target type = 0x43 INSTANCEOF\n" + + " offset = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + + expectedOutput = " 1 instanceof java.lang.String [16]\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test057_codeblocks_new() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " Object o = new @B(3) Object();\n" + + " return true;\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #35 @B(\n" + + " #36 value=(int) 3 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 8\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test058_codeblocks_new2() throws Exception { + this.runConformTest( + new String[] { + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Outer o = new Outer();\n" + + " o.new @B(1) Inner();\n" + + " }\n" + + "}\n" + + "class Outer { class Inner {}}\n" + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #30 @B(\n" + + " #31 value=(int) 1 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 8\n" + + " location = [INNER_TYPE]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test057_codeblocks_new3_415821() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface X { }\n" + + "\n" + + "class Foo {}\n", + "C.java", + "class C { void m() { new @X Foo() {}; } }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @X(\n" + + " target type = 0x44 NEW\n" + + " offset = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "C.class", "C", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #28 @X(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = -1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "C$1.class", "C$1", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test057_codeblocks_new4_415821() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface X { }\n" + + "\n", + "C.java", + "class C { void m() { new @X Runnable() { public void run() {}}; } }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #21 @X(\n" + + " target type = 0x44 NEW\n" + + " offset = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "C.class", "C", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #31 @X(\n" + + " target type = 0x10 CLASS_EXTENDS\n" + + " type index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "C$1.class", "C$1", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test059_codeblocks_new_newArray() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " Object o = new @A String [1];\n" + + " return true;\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #37 @A(\n" + + " target type = 0x44 NEW\n" + + " offset = 9\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test060_codeblocks_new_multiNewArray() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " Object o = new @A String [2][3];\n" + + " return true;\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #37 @A(\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test060a_codeblocks_new_newArrayWithInitializer() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " X[][] x = new @A X @B [] @C[]{ { null }, { null } };\n" + + " return true;\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " String value() default \"default\";\n" + + "}\n", + + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface C {\n" + + " String value() default \"default\";\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #37 @A(\n" + + " target type = 0x44 NEW\n" + + " offset = 9\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #38 @B(\n" + + " target type = 0x44 NEW\n" + + " offset = 9\n" + + " )\n" + + " #39 @C(\n" + + " target type = 0x44 NEW\n" + + " offset = 9\n" + + " location = [ARRAY]\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test060b_codeblocks_new_multiNewArray() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " X[][] x = new @A X @B [1] @C[2];\n" + + " return true;\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " String value() default \"default\";\n" + + "}\n", + + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface C {\n" + + " String value() default \"default\";\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #36 @A(\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #37 @B(\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " )\n" + + " #38 @C(\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " location = [ARRAY]\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test060c_codeblocks_new_multiNewArray() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " X [][][] x = new @A X @B[10] @C[10] @D[];\n" + + " return true;\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " String value() default \"default\";\n" + + "}\n", + + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface C {\n" + + " String value() default \"default\";\n" + + "}\n", + + "D.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface D {\n" + + " String value() default \"default\";\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #36 @A(\n" + + " target type = 0x44 NEW\n" + + " offset = 12\n" + + " location = [ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #37 @B(\n" + + " target type = 0x44 NEW\n" + + " offset = 12\n" + + " )\n" + + " #38 @C(\n" + + " target type = 0x44 NEW\n" + + " offset = 12\n" + + " location = [ARRAY]\n" + + " )\n" + + " #39 @D(\n" + + " target type = 0x44 NEW\n" + + " offset = 12\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test060d_codeblocks_new_arraysWithNestedTypes() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " Object o = new @B(1) Outer.@B(2) Inner @B(3) [2];\n" + + " return true;\n" + + " }\n" + + "}\n" + + "class Outer { class Inner {}}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default 99;\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #37 @B(\n" + + " #38 value=(int) 1 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 9\n" + + " location = [ARRAY]\n" + + " )\n" + + " #37 @B(\n" + + " #38 value=(int) 2 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 9\n" + + " location = [ARRAY, INNER_TYPE]\n" + + " )\n" + + " #37 @B(\n" + + " #38 value=(int) 3 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 9\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test060e_codeblocks_new_arraysWithNestedTypes() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " Object o = new @B(1) Outer.@B(2) Inner @B(3) [2] @B(4)[4];\n" + + " return true;\n" + + " }\n" + + "}\n" + + "class Outer { class Inner {}}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default 99;\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #37 @B(\n" + + " #38 value=(int) 1 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #37 @B(\n" + + " #38 value=(int) 2 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " location = [ARRAY, ARRAY, INNER_TYPE]\n" + + " )\n" + + " #37 @B(\n" + + " #38 value=(int) 3 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " )\n" + + " #37 @B(\n" + + " #38 value=(int) 4 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test060f_codeblocks_new_arraysWithQualifiedNestedTypes() throws Exception { + this.runConformTest( + new String[] { + "Z.java", + "public class Z {}", + "X.java", + "package org.foo.bar;\n" + + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " Object o = new org.foo.bar.@B(1) Outer.@B(2) Inner @B(3) [2] @B(4)[4];\n" + + " return true;\n" + + " }\n" + + "}\n" + + "class Outer { class Inner {}}\n", + "B.java", + "package org.foo.bar;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default 99;\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #37 @org.foo.bar.B(\n" + + " #38 value=(int) 1 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #37 @org.foo.bar.B(\n" + + " #38 value=(int) 2 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " location = [ARRAY, ARRAY, INNER_TYPE]\n" + + " )\n" + + " #37 @org.foo.bar.B(\n" + + " #38 value=(int) 3 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " )\n" + + " #37 @org.foo.bar.B(\n" + + " #38 value=(int) 4 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 10\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "org" + File.separator + "foo" + File.separator + "bar" + File.separator + "X.class", + "org.foo.bar.X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test061_codeblocks_new_newArrayWithInitializer() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " Object o = new @A String []{\"xyz\"};\n" + + " return true;\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #37 @A(\n" + + " target type = 0x44 NEW\n" + + " offset = 9\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test062_codeblocks_newArray() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " Object o = new String @A[1];\n" + + " return true;\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #37 @A(\n" + + " target type = 0x44 NEW\n" + + " offset = 9\n" + + // no type path expected here + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test062_codeblocks_newArrayWithInitializer() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X {\n" + + " public boolean foo(String s) {\n" + + " System.out.println(\"xyz\");\n" + + " Object o = new String @A[] { \"Hello\" };\n" + + " return true;\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #39 @A(\n" + + " target type = 0x44 NEW\n" + + " offset = 9\n" + + // no type path expected here + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test063_codeblocks_new_instanceof() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X {\n" + + " public boolean foo(Object o) {\n" + + " boolean b = (o instanceof @C('_') Object[]);\n" + + " Object o1 = new @B(3) @A(\"new Object\") Object[] {};\n" + + " return b;\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #24 @B(\n" + + " #25 value=(int) 3 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 6\n" + + " location = [ARRAY]\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #28 @C(\n" + + " #25 value=\'_\' (constant type)\n" + + " target type = 0x43 INSTANCEOF\n" + + " offset = 1\n" + + " location = [ARRAY]\n" + + " )\n" + + " #30 @A(\n" + + " #25 value=\"new Object\" (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 6\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + + public void test064_codeblocks_constructorReference() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface MR { X process(String input); }\n"+ + "public class X {\n" + + " public X(T t) {}\n" + + " public static String foo(String bar) { return bar; }\n"+ + " public void bar() {\n" + + " System.out.println(\"abc\");\n" + + " MR ref = @A X::new;\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #48 @A(\n" + + " target type = 0x45 CONSTRUCTOR_REFERENCE\n" + + " offset = 8\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + + public void test065_codeblocks_methodReference() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface MR { String process(String input); }\n"+ + "public class X {\n" + + " public static String foo(String bar) { return bar; }\n"+ + " public void bar() {\n" + + " System.out.println(\"abc\");\n" + + " MR ref = @A X::foo;\n" + + " ref.process(\"abc\");\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #47 @A(\n" + + " target type = 0x46 METHOD_REFERENCE\n" + + " offset = 8\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test066_codeblocks_methodReference() throws Exception { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "interface I {\n" + + " Object copy(int [] ia);\n" + + "}\n" + + "public class X {\n" + + " public static void main(String [] args) {\n" + + " I i = @B(1) int @B(2)[]::clone;\n" + + " i.copy(new int[10]); \n" + + " }\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}\n", + }; + if (this.complianceLevel < ClassFileConstants.JDK9) { // luckily introduction of ecj warning and javac crash coincide + runner.runConformTest(); + } else { + runner.expectedCompilerLog = + "----------\n" + + "1. WARNING in X.java (at line 6)\n" + + " I i = @B(1) int @B(2)[]::clone;\n" + + " ^^^^^^\n" + + "Unused type arguments for the non generic method clone() of type Object; it should not be parameterized with arguments \n" + + "----------\n"; + runner.javacTestOptions = JavacHasABug.JavacThrowsAnExceptionForJava_since9_EclipseWarns; + runner.runWarningTest(); + } + + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #30 @B(\n" + + " #31 value=(int) 1 (constant type)\n" + + " target type = 0x46 METHOD_REFERENCE\n" + + " offset = 0\n" + + " location = [ARRAY]\n" + + " )\n" + + " #30 @B(\n" + + " #31 value=(int) 2 (constant type)\n" + + " target type = 0x46 METHOD_REFERENCE\n" + + " offset = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test067_codeblocks_constructorReferenceTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface MR { X process(String input); }\n" + + "public class X {\n" + + " public X(T s) {};\n" + + " public static String foo(String bar) { return bar; }\n"+ + " public void bar() {\n" + + " System.out.println(\"abc\");\n" + + " MR ref = X::<@A String>new;\n" + + " ref.process(\"abc\");\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #53 @A(\n" + + " target type = 0x4a CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT\n" + + " offset = 8\n" + + " type argument index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test068_codeblocks_methodReferenceTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "interface MR { String process(String input); }\n"+ + "public class X {\n" + + " public static String foo(String bar) { return bar; }\n"+ + " public void bar() {\n" + + " System.out.println(\"abc\");\n" + + " MR ref = X::<@A String>foo;\n" + + " ref.process(\"abc\");\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #47 @A(\n" + + " target type = 0x4b METHOD_REFERENCE_TYPE_ARGUMENT\n" + + " offset = 8\n" + + " type argument index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test069_codeblocks_cast() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo(Object o) {\n" + + " if (o instanceof String) {\n" + + " String tab = (@A String) o;\n" + + " System.out.println(tab);\n" + + " }\n" + + " System.out.println(o);\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + // javac-b81: Bytes:11[0 1 71 0 7 0 0 0 16 0 0] + // relevant numbers '71 0 7 0' which mean 0x47 (CAST) at offset 7 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #38 @A(\n" + + " target type = 0x47 CAST\n" + + " offset = 8\n" + + " type argument index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test070_codeblocks_cast_complex() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "I.java", + "interface I {}\n", + "J.java", + "interface J {}\n", + "X.java", + "public class X {\n" + + " public void foo(Object o) {\n" + + " if (o instanceof String[][]) {\n" + + " String[][] tab = (@C('_') @B(3) String[] @A[]) o;\n" + + " System.out.println(tab.length);\n" + + " }\n" + + " System.out.println(o);\n" + + " }\n" + + "}", + }, + ""); + // javac-b81: + // Bytes:31[0 2 71 0 7 0 1 0 0 0 16 0 0 71 0 7 0 2 0 0 0 0 0 17 0 1 0 18 67 0 19] + // Bytes:20[0 1 71 0 7 0 2 0 0 0 0 0 21 0 1 0 18 73 0 22] + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #37 @B(\n" + + " #38 value=(int) 3 (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 8\n" + + " type argument index = 0\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #41 @C(\n" + + " #38 value=\'_\' (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 8\n" + + " type argument index = 0\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #43 @A(\n" + + " target type = 0x47 CAST\n" + + " offset = 8\n" + + " type argument index = 0\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test070a_codeblocks_castWithIntersectionCast() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public void foo(Object o) {\n" + + " I i = (@B(1) I & J) o;\n" + + " J j = (I & @B(2) J) o;\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default 1;\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #15 (Ljava/lang/Object;)V\n" + + " // Stack: 1, Locals: 4\n" + + " public void foo(java.lang.Object o);\n" + + " 0 aload_1 [o]\n" + + " 1 checkcast J [16]\n" + + " 4 checkcast I [18]\n" + + " 7 astore_2 [i]\n" + + " 8 aload_1 [o]\n" + + " 9 checkcast J [16]\n" + + " 12 checkcast I [18]\n" + + " 15 astore_3 [j]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: this index: 0 type: X\n" + + " [pc: 0, pc: 17] local: o index: 1 type: java.lang.Object\n" + + " [pc: 8, pc: 17] local: i index: 2 type: I\n" + + " [pc: 16, pc: 17] local: j index: 3 type: J\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #27 @B(\n" + + " #28 value=(int) 1 (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 4\n" + + " type argument index = 0\n" + + " )\n" + + " #27 @B(\n" + + " #28 value=(int) 2 (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 9\n" + + " type argument index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test070b_codeblocks_castWithIntersectionCast() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public void foo(Object o) {\n" + + " System.out.println(123);\n" + + " I i = (I<@B(1) String> & @B(2) J) o;\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default 1;\n" + + "}\n", + }, + ""); + String expectedOutput = + " public void foo(java.lang.Object o);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 bipush 123\n" + + " 5 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 8 aload_1 [o]\n" + + " 9 checkcast J [28]\n" + + " 12 checkcast I [30]\n" + + " 15 astore_2 [i]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: this index: 0 type: X\n" + + " [pc: 0, pc: 17] local: o index: 1 type: java.lang.Object\n" + + " [pc: 16, pc: 17] local: i index: 2 type: I\n" + + " Local variable type table:\n" + + " [pc: 16, pc: 17] local: i index: 2 type: I\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #39 @B(\n" + + " #40 value=(int) 2 (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 9\n" + + " type argument index = 1\n" + + " )\n" + + " #39 @B(\n" + + " #40 value=(int) 1 (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 12\n" + + " type argument index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test070c_codeblocks_castTwiceInExpression() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public void foo(Object o) {\n" + + " System.out.println(123);\n" + + " I i = (@B(1) I)(@B(2) J) o;\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default 1;\n" + + "}\n", + }, + ""); + String expectedOutput = + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 bipush 123\n" + + " 5 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 8 aload_1 [o]\n" + + " 9 checkcast J [28]\n" + + " 12 checkcast I [30]\n" + + " 15 astore_2 [i]\n" + + " 16 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 16, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 17] local: this index: 0 type: X\n" + + " [pc: 0, pc: 17] local: o index: 1 type: java.lang.Object\n" + + " [pc: 16, pc: 17] local: i index: 2 type: I\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #37 @B(\n" + + " #38 value=(int) 2 (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 9\n" + + " type argument index = 0\n" + + " )\n" + + " #37 @B(\n" + + " #38 value=(int) 1 (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 12\n" + + " type argument index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test070d_codeblocks_castDoubleIntersectionCastInExpression() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.io.*;\n" + + "public class X {\n" + + " public void foo(Object o) {\n" + + " System.out.println(123);\n" + + " I i = (@B(1) I & J)(K & @B(2) L) o;\n" + + " }\n" + + "}\n" + + "interface I {}\n" + + "interface J {}\n" + + "interface K {}\n" + + "interface L {}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default 1;\n" + + "}\n", + }, + ""); + String expectedOutput = + " public void foo(java.lang.Object o);\n" + + " 0 getstatic java.lang.System.out : java.io.PrintStream [16]\n" + + " 3 bipush 123\n" + + " 5 invokevirtual java.io.PrintStream.println(int) : void [22]\n" + + " 8 aload_1 [o]\n" + + " 9 checkcast L [28]\n" + + " 12 checkcast K [30]\n" + + " 15 checkcast J [32]\n" + + " 18 checkcast I [34]\n" + + " 21 astore_2 [i]\n" + + " 22 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 8, line: 5]\n" + + " [pc: 22, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 23] local: this index: 0 type: X\n" + + " [pc: 0, pc: 23] local: o index: 1 type: java.lang.Object\n" + + " [pc: 22, pc: 23] local: i index: 2 type: I\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #41 @B(\n" + + " #42 value=(int) 2 (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 9\n" + + " type argument index = 1\n" + + " )\n" + + " #41 @B(\n" + + " #42 value=(int) 1 (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 18\n" + + " type argument index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test071_codeblocks_constructorInvocationTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "X.java", + "public class X {\n" + + " X(T t) {\n" + + " }\n" + + " public Object foo() {\n" + + " X x = new <@A @B(1) String>X(null);\n" + + " return x;\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #27 @B(\n" + + " #28 value=(int) 1 (constant type)\n" + + " target type = 0x48 CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 5\n" + + " type argument index = 0\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #31 @A(\n" + + " target type = 0x48 CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 5\n" + + " type argument index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test072_codeblocks_constructorInvocationTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + "X.java", + "public class X {\n" + + " X(T t, U u) {\n" + + " }\n" + + " public Object foo() {\n" + + " X x = new <@A Integer, @A String @C [] @B(1)[]>X(null, null);\n" + + " return x;\n" + + " }\n" + + "}", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #29 @B(\n" + + " #30 value=(int) 1 (constant type)\n" + + " target type = 0x48 CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 6\n" + + " type argument index = 1\n" + + " location = [ARRAY]\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #33 @A(\n" + + " target type = 0x48 CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 6\n" + + " type argument index = 0\n" + + " )\n" + + " #33 @A(\n" + + " target type = 0x48 CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 6\n" + + " type argument index = 1\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #34 @C(\n" + + " target type = 0x48 CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 6\n" + + " type argument index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void test073_codeblocks_constructorInvocationTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void bar() {\n" + + " new X();\n"+ + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + // Example bytes:11[0 1 73 0 0 0 0 0 13 0 0] this would be for offset 0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #19 @A(\n" + + " target type = 0x48 CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 3\n" + + " type argument index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test074_codeblocks_constructorInvocationTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int i) {}\n"+ + " public void bar() {\n" + + " new , T2>X();\n"+ + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + // Example bytes:11[0 1 73 0 0 0 0 0 13 0 0] this would be for offset 0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #23 @A(\n" + + " target type = 0x48 CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 3\n" + + " type argument index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test075_codeblocks_constructorInvocationTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public void bar() {\n" + + " new <@A T>X();\n"+ + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + // Example bytes:11[0 1 73 0 0 0 0 0 13 0 0] this would be for offset 0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #19 @A(\n" + + " target type = 0x48 CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 3\n" + + " type argument index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test076_codeblocks_methodInvocationTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " static T foo(T t, U u) {\n" + + " return t;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(X.<@A @B(1) String[], @C('-') X>foo(new String[]{\"SUCCESS\"}, null)[0]);\n" + + " }\n" + + "}\n", + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(CLASS)\n" + + "@interface B {\n" + + " int value() default -1;\n" + + "}", + "C.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface C {\n" + + " char value() default '-';\n" + + "}\n", + }, + "SUCCESS"); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #48 @B(\n" + + " #49 value=(int) 1 (constant type)\n" + + " target type = 0x49 METHOD_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 13\n" + + " type argument index = 0\n" + + " location = [ARRAY]\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #52 @A(\n" + + " target type = 0x49 METHOD_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 13\n" + + " type argument index = 0\n" + + " location = [ARRAY]\n" + + " )\n" + + " #53 @C(\n" + + " #49 value=\'-\' (constant type)\n" + + " target type = 0x49 METHOD_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 13\n" + + " type argument index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test077_codeblocks_methodInvocationTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int i) {}\n"+ + " public void bar() {\n" + + " X.foo(42);\n"+ + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + // Example bytes:11[0 1 73 0 0 0 0 0 13 0 0] this would be for offset 0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #24 @A(\n" + + " target type = 0x49 METHOD_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 2\n" + + " type argument index = 1\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test078_codeblocks_methodInvocationTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int i) {}\n"+ + " public void bar() {\n" + + " X., T2>foo(42);\n"+ + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + + }, + ""); + // Example bytes:11[0 1 73 0 0 0 0 0 13 0 0] this would be for offset 0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #24 @A(\n" + + " target type = 0x49 METHOD_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 2\n" + + " type argument index = 0\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test079_codeblocks_methodInvocationTypeArgument() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int i) {}\n"+ + " public void bar() {\n" + + " X.<@A T>foo(42);\n"+ + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface A {\n" + + " String value() default \"default\";\n" + + "}\n", + }, + ""); + // Example bytes:11[0 1 73 0 0 0 0 0 13 0 0] this would be for offset 0 + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #24 @A(\n" + + " target type = 0x49 METHOD_INVOCATION_TYPE_ARGUMENT\n" + + " offset = 2\n" + + " type argument index = 0\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + + // Annotation should appear twice in this case + public void test080_multiuseAnnotations() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @B(1) int foo() { return 0; }\n" + + "}", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target({ElementType.METHOD, ElementType.TYPE_USE})\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default 99;\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleAnnotations: \n" + + " #17 @B(\n" + + " #18 value=(int) 1 (constant type)\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #17 @B(\n" + + " #18 value=(int) 1 (constant type)\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test081_multiuseAnnotations() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "@Target({ElementType.METHOD, ElementType.TYPE_USE})\n" + + "@interface Annot {\n" + + " int value() default 0;\n" + + "}\n" + + "public class X {\n" + + " @Annot(4) public String foo() { return \"hello\"; }" + + "}", + }, + ""); + String expectedOutput = + " RuntimeInvisibleAnnotations: \n" + + " #17 @Annot(\n" + + " #18 value=(int) 4 (constant type)\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #17 @Annot(\n" + + " #18 value=(int) 4 (constant type)\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + // When not annotated with any TYPE it assumes the Java7 set (i.e. not TYPE_USE/TYPE_PARAMETER) + public void test082_multiuseAnnotations() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "@interface Annot {\r\n" + + " int value() default 0;\r\n" + + "}\r\n" + + "public class X {\r\n" + + " @Annot(4)\r\n" + + " public void foo() {\r\n" + + " }\r\n" + + "}", + }, + ""); + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 0, Locals: 1\n" + + " public void foo();\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " RuntimeInvisibleAnnotations: \n" + + " #16 @Annot(\n" + + " #17 value=(int) 4 (constant type)\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + // as of https://bugs.openjdk.java.net/browse/JDK-8231435 no-@Target annotations are legal also in TYPE_USE/TYPE_PARAMETER position + public void test083_multiuseAnnotations() throws Exception { + Runner runner = new Runner(); + runner.testFiles = + new String[] { + "X.java", + "@interface Annot {\n" + + " int value() default 0;\n" + + "}\n" + + "public class X<@Annot(1) T> {\n" + + " java.lang. @Annot(2)String f;\n" + + " public void foo(String @Annot(3)[] args) {\n" + + " }\n" + + "}\n", + }; + runner.expectedCompilerLog = ""; + runner.javacTestOptions = JavacTestOptions.JavacHasABug.JavacBug8231436; + runner.runConformTest(); + + String expectedOutput = + " // Field descriptor #6 Ljava/lang/String;\n" + + " java.lang.String f;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Annot(\n" + + " #9 value=(int) 2 (constant type)\n" + // <-2- + " target type = 0x13 FIELD\n" + + " )\n" + + " \n" + + " // Method descriptor #12 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [14]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #23 ([Ljava/lang/String;)V\n" + + " // Stack: 0, Locals: 2\n" + + " public void foo(java.lang.String[] args);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: args index: 1 type: java.lang.String[]\n" + + " Local variable type table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Annot(\n" + + " #9 value=(int) 3 (constant type)\n" + // <-3- + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + "\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @Annot(\n" + + " #9 value=(int) 1 (constant type)\n" + // <-1- + " target type = 0x0 CLASS_TYPE_PARAMETER\n" + + " type parameter index = 0\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100_pqtr() throws Exception { // PQTR (ParameterizedQualifiedTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " java.util.@B(2) List field2;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100a_pqtr() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " java.util.@B(2) List[] field3;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100b_pqtr() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " java.util.List<@B(3) String>[] field3;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100c_pqtr() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " java.util.List @B(3)[] field3;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100d_pqtr() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " java.util.@B(2) List<@B(5) String> @B(3)[]@B(4)[] field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 4 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 5 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + + public void test100e_pqtr() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " java.util.Map.@B(2) Entry field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100f_pqtr() throws Exception { + this.runConformTest( + new String[] { + "Foo.java", + "class Foo {}\n", + + "Levels.java", + "package one.two.three;\n" + + "class Level1 { static class Level2 { class Level3 { class Level4 { class Level5 { } } } } }\n", + + "X.java", + "package one.two.three;\n" + + "class X {\n" + + " one.two.three.Level1.Level2.@B(2) Level3.Level4.@B(3) Level5 instance;\n" + + "}\n", + + "B.java", + "package one.two.three;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @one.two.three.B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " #10 @one.two.three.B(\n" + + " #11 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE, INNER_TYPE, INNER_TYPE]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "one" + File.separator + "two" + File.separator + "three" + File.separator + "X.class", "one.two.three.X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100g_pqtr() throws Exception { + this.runConformTest( + new String[] { + "Foo.java", + "class Foo {}\n", + + "Levels.java", + "package one.two.three;\n" + + "class Level1 { static class Level2 { class Level3 { class Level4 { class Level5 { } } } } }\n", + + "X.java", + "package one.two.three;\n" + + "class X {\n" + + " one.two.three.Level1.Level2.@B(2) Level3.Level4.@B(3) Level5[][] instance;\n" + + "}\n", + + "B.java", + "package one.two.three;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @one.two.three.B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE]\n" + + " )\n" + + " #10 @one.two.three.B(\n" + + " #11 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, INNER_TYPE, INNER_TYPE]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "one" + File.separator + "two" + File.separator + "three" + File.separator + "X.class", "one.two.three.X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100h_pqtr() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " Level1.Level2.@B(2) Level3.Level4.@B(3) Level5[][] instance;\n" + + "}\n", + + "Levels.java", + "class Level1 { static class Level2 { class Level3 { class Level4 { class Level5 { } } } } }\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE]\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, INNER_TYPE, INNER_TYPE]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100i_pqtr() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " Level1.Level2.Level3.Level4.Level5<@B(1) String>[][] instance;\n" + + "}\n", + + "Levels.java", + "class Level1 { static class Level2 { class Level3 { class Level4 { class Level5 { } } } } }\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, INNER_TYPE, INNER_TYPE, TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100j_pqtr() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " Level1.Level2.Level3<@B(1) String>.Level4.Level5<@B(2) String>[][] instance;\n" + + "}\n", + + "Levels.java", + "class Level1 { static class Level2 { class Level3 { class Level4 { class Level5 { } } } } }\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, INNER_TYPE, INNER_TYPE, TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test100k_pqtr() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " Level1.@B(5) Level2.Level3<@B(1) String>.Level4.Level5<@B(2) String>[][] instance;\n" + + "}\n", + + "Levels.java", + "class Level1 { static class Level2 { class Level3 { class Level4 { class Level5 { } } } } }\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 5 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, INNER_TYPE, INNER_TYPE, TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test101a_qtr() throws Exception { // QTR (QualifiedTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " com.foo.@B(2) List field2;\n" + + "}\n", + + "List.java", + "package com.foo;\n"+ + "public class List {}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + + public void test101b_qtr() throws Exception { // QTR (QualifiedTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " java.util.Map.@B(2) Entry field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test101c_qtr() throws Exception { // QTR (QualifiedTypeReference) + this.runConformTest( + new String[] { + "Runner.java", + "public class Runner {}\n", + + "B.java", + "package one.two.three;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + + "X.java", + "package one.two.three;\n" + + "class X {\n" + + " one.two.three.Level1.Level2.@B(2) Level3.Level4.@B(3) Level5 instance;\n" + + "}\n", + + "Level1.java", + "package one.two.three;\n" + + "public class Level1 { static class Level2 { class Level3 { class Level4 { class Level5 { } } } } }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @one.two.three.B(\n" + + " #9 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " #8 @one.two.three.B(\n" + + " #9 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [INNER_TYPE, INNER_TYPE, INNER_TYPE]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "one" + File.separator + "two" + File.separator + "three" + File.separator + "X.class", "one.two.three.X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test102a_str() throws Exception { // STR (SingleTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " @B(1) X field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test102b_str() throws Exception { // STR (SingleTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " @B(1) int field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test103a_atr() throws Exception { // ATR (ArrayTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " @B(1) X[] field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test103b_atr() throws Exception { // ATR (ArrayTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " X @B(2)[] field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test103c_atr() throws Exception { // ATR (ArrayTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " X []@B(3)[] field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test103d_atr() throws Exception { // ATR (ArrayTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " X []@B(3)[][] field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test103e_atr() throws Exception { // ATR (ArrayTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " @B(1) int []@B(3)[][] field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @B(\n" + + " #9 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #8 @B(\n" + + " #9 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test104a_pstr() throws Exception { // PSTR (ParameterizedSingleTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " @B(1) X<@B(2) String, @B(3) Integer, @B(4) Boolean> field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(1)]\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 4 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(2)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test104b_pstr() throws Exception { // PSTR (ParameterizedSingleTypeReference) + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " @B(1) X<@B(2) String> @B(3)[] field;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #10 @B(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test105a_aqtr() throws Exception { // AQTR (ArrayQualifiedTypeReference) + this.runConformTest( + new String[] { + "Y.java", + "class Y {}", + + "X.java", + "package one.two.three;\n" + + "class X {\n" + + " one.two.three.@B(1) List[] field;\n" + + "}\n", + + "List.java", + "package one.two.three;\n" + + "class List {}\n", + + "B.java", + "package one.two.three;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @one.two.three.B(\n" + + " #9 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "one" + File.separator + "two" + File.separator + "three" + File.separator +"X.class", + "one.two.three.X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test105b_aqtr() throws Exception { // AQTR (ArrayQualifiedTypeReference) + this.runConformTest( + new String[] { + "Y.java", + "class Y {}", + + "X.java", + "package one.two.three;\n" + + "class X {\n" + + " one.two.three.@B(2) List @B(3)[]@B(4)[] field;\n" + + "}\n", + + "List.java", + "package one.two.three;\n" + + "class List {}\n", + + "B.java", + "package one.two.three;\n" + + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @one.two.three.B(\n" + + " #9 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #8 @one.two.three.B(\n" + + " #9 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #8 @one.two.three.B(\n" + + " #9 value=(int) 4 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "one" + File.separator + "two" + File.separator + "three" + File.separator +"X.class", + "one.two.three.X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test106a_wtr() throws Exception { // WTR (WildcardTypeReference) + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class X {\n" + + " List field;\n" + + "}\n", + + "List.java", + "class List {}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), WILDCARD]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator +"X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test106b_wtr() throws Exception { // WTR (WildcardTypeReference) + this.runConformTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "class X {\n" + + " List field;\n" + + "}\n", + + "List.java", + "class List {}\n", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B { int value() default -1; }\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @B(\n" + + " #11 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [TYPE_ARGUMENT(0), WILDCARD, ARRAY]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=409244, [1.8][compiler] Type annotations on redundant casts dropped. + public void testAnnotatedRedundantCast() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " String s = (@NonNull String) \"Hello\";\n" + + "}\n", + + "NonNull.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface NonNull {}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 ldc [12]\n" + + " 7 checkcast java.lang.String [14]\n" + + " 10 putfield X.s : java.lang.String [16]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 13, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #23 @NonNull(\n" + + " target type = 0x47 CAST\n" + + " offset = 7\n" + + " type argument index = 0\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=409244, [1.8][compiler] Type annotations on redundant casts dropped. + public void testAnnotatedRedundantCast2() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "class X {\n" + + " String s = (String) \"Hello\";\n" + + "}\n", + + "NonNull.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface NonNull {}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #8 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [10]\n" + + " 4 aload_0 [this]\n" + + " 5 ldc [12]\n" + + " 7 putfield X.s : java.lang.String [14]\n" + + " 10 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 10, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 11] local: this index: 0 type: X\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test055a_codeblocks_exceptionParameterNestedType() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " foo();\n" + + " } catch(@B(1) Outer.@B(2) MyException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " static void foo() throws Outer.MyException {}\n" + + "}\n" + + "class Outer {\n" + + " class MyException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}", + + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default 0;\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #30 @B(\n" + + " #31 value=(int) 1 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n" + + " #30 @B(\n" + + " #31 value=(int) 2 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " \n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test055b_codeblocks_exceptionParameterMultiCatchNestedType() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " foo();\n" + + " } catch(@B(1) Outer.@B(2) MyException | @B(3) Outer2.@B(4) MyException2 e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " static void foo() throws Outer.MyException, Outer2.MyException2 {}\n" + + "}\n" + + "class Outer {\n" + + " class MyException extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}\n" + + "class Outer2 {\n" + + " class MyException2 extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + " }\n" + + "}", + "B.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface B {\n" + + " int value() default 0;\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #34 @B(\n" + + " #35 value=(int) 1 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n" + + " #34 @B(\n" + + " #35 value=(int) 2 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + " #34 @B(\n" + + " #35 value=(int) 3 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 1\n" + + " )\n" + + " #34 @B(\n" + + " #35 value=(int) 4 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 1\n" + + " location = [INNER_TYPE]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test055c_codeblocks_exceptionParameterMultiCatch() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "class Exc1 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "class Exc2 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "class Exc3 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(42);\n" + + " } catch(Exc1 | @B(1) Exc2 | @B(2) Exc3 t) {\n" + + " t.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface B {\n" + + " int value() default 99;\n" + + "}\n", + }, + "42"); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #45 @B(\n" + + " #46 value=(int) 1 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 1\n" + + " )\n" + + " #45 @B(\n" + + " #46 value=(int) 2 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 2\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test055d_codeblocks_exceptionParameterMultiCatch() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "class Exc1 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "class Exc2 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "class Exc3 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(42);\n" + + " } catch(@A(1) @B(2) Exc1 | Exc2 | @A(3) @B(4) Exc3 t) {\n" + + " t.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " int value() default 99;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface B {\n" + + " int value() default 99;\n" + + "}\n", + }, + "42"); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #45 @A(\n" + + " #46 value=(int) 1 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n" + + " #48 @B(\n" + + " #46 value=(int) 2 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n" + + " #45 @A(\n" + + " #46 value=(int) 3 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 2\n" + + " )\n" + + " #48 @B(\n" + + " #46 value=(int) 4 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 2\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test055e_codeblocks_exceptionParameterMultiCatch() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "class Exc1 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "class Exc2 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "class Exc3 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(42);\n" + + " } catch(@A(1) @B(2) Exc1 | Exc2 | @A(3) @B(4) Exc3 t) {\n" + + " t.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + + "A.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface A {\n" + + " int value() default 99;\n" + + "}\n", + + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface B {\n" + + " int value() default 99;\n" + + "}\n", + }, + "42"); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #45 @A(\n" + + " #46 value=(int) 1 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n" + + " #48 @B(\n" + + " #46 value=(int) 2 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n" + + " #45 @A(\n" + + " #46 value=(int) 3 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 2\n" + + " )\n" + + " #48 @B(\n" + + " #46 value=(int) 4 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 2\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void test055f_codeblocks_exceptionParameterComplex() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "class Exc1 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "class Exc2 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "class Exc3 extends RuntimeException {" + + " private static final long serialVersionUID = 1L;\n" + + "}\n"+ + "public class X {\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " System.out.println(42);\n" + + " } catch(@B(1) Exc1 | Exc2 | @B(2) Exc3 t) {\n" + + " t.printStackTrace();\n" + + " }\n" + + " try {\n" + + " System.out.println(43);\n" + + " } catch(@B(1) Exc1 t) {\n" + + " t.printStackTrace();\n" + + " }\n" + + " try {\n" + + " System.out.println(44);\n" + + " } catch(@B(1) Exc1 | @B(2) Exc2 t) {\n" + + " t.printStackTrace();\n" + + " }\n" + + " }\n" + + "}", + "B.java", + "import java.lang.annotation.Target;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import java.lang.annotation.Retention;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface B {\n" + + " int value() default 99;\n" + + "}\n", + }, + "42\n43\n44"); + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + " #47 @B(\n" + + " #48 value=(int) 1 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 0\n" + + " )\n" + + " #47 @B(\n" + + " #48 value=(int) 2 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 2\n" + + " )\n" + + " #47 @B(\n" + + " #48 value=(int) 1 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 3\n" + + " )\n" + + " #47 @B(\n" + + " #48 value=(int) 1 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 4\n" + + " )\n" + + " #47 @B(\n" + + " #48 value=(int) 2 (constant type)\n" + + " target type = 0x42 EXCEPTION_PARAMETER\n" + + " exception table index = 5\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void testBug415911() { + runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface Marker {\n" + + "}\n" + + "\n" + + "public class X {\n" + + " @Marker\n" + + " foo(String s) {\n" + + "\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " foo(String s) {\n" + + " ^^^^^^^^^^^^^\n" + + "Return type for the method is missing\n" + + "----------\n"); + } + + public void testBug426616() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n"+ + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Retention(RUNTIME)\n" + + "@Target(TYPE_USE)\n" + + "@interface SizeHolder { Size[] value();}\n"+ + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@Repeatable(SizeHolder.class)\n"+ + "@interface Size { int max(); }\n"+ + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface Nonnull {}\n"+ + "\n"+ + "public class X {\n" + + " public static void main(String[]argv) {}\n"+ + " public static String testArrays() {\n"+ + " List<@Size(max = 41) CharSequence>[] @Size(max = 42) [] @Nonnull @Size(max = 43) [][] test = new @Size(max = 44) ArrayList @Size(max = 45) [10][][] @Size(max = 47) @Size(max = 48) [];\n"+ + " return (@Size(max = 49) String) test[0][1][2][3].get(0);\n"+ + " }\n"+ + "}", + }, + ""); + // Javac output + // 0: Size(45): NEW, offset=0 + // 1: SizeHolder([@Size(max=47),@Size(max=48)]): NEW, offset=0, location=[ARRAY, ARRAY, ARRAY] + // 2: Size(44): NEW, offset=0, location=[ARRAY, ARRAY, ARRAY, ARRAY] + // 3: Size(49): CAST, offset=6, type_index=0 + // 4: Size(42): LOCAL_VARIABLE, {start_pc=6, length=19, index=0}, location=[ARRAY] + // 5: NonNull: LOCAL_VARIABLE, {start_pc=6, length=19, index=0}, location=[ARRAY, ARRAY] + // 6: Size(43): LOCAL_VARIABLE, {start_pc=6, length=19, index=0}, location=[ARRAY, ARRAY] + // 7: Size(41): LOCAL_VARIABLE, {start_pc=6, length=19, index=0}, location=[ARRAY, ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0)] + + String expectedOutput = + " RuntimeVisibleTypeAnnotations: \n" + + + // X Maps to javac entry (2): location OK, target type OK, offset different, our offset is 2 and not 0 + " #33 @Size(\n" + + " #34 max=(int) 44 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 2\n" + + " location = [ARRAY, ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + + // X Maps to javac entry (0), location OK, target type OK, offset different, our offset is 2 and not 0 + " #33 @Size(\n" + + " #34 max=(int) 45 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 2\n" + + " )\n" + + + // X Maps to javac entry (1), location OK, target type OK, offset different, our offset is 2 and not 0 + " #37 @SizeHolder(\n" + + " #38 value=[\n" + + " annotation value =\n" + + " #33 @Size(\n" + + " #34 max=(int) 47 (constant type)\n" + + " )\n" + + " annotation value =\n" + + " #33 @Size(\n" + + " #34 max=(int) 48 (constant type)\n" + + " )\n" + + " ]\n" + + " target type = 0x44 NEW\n" + + " offset = 2\n" + + " location = [ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + + // X Maps to javac entry (3), location OK, target type OK, offset different, our offset is 24 (not 6), type index OK + " #33 @Size(\n" + + " #34 max=(int) 49 (constant type)\n" + + " target type = 0x47 CAST\n" + + " offset = 24\n" + + " type argument index = 0\n" + + " )\n" + + + // Maps to javac entry (4), location OK, target type OK, lvar diff, slight position difference (we seem to have an extra CHECKCAST) + " #33 @Size(\n" + + " #34 max=(int) 42 (constant type)\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 6, pc: 28] index: 0\n" + + " location = [ARRAY]\n" + + " )\n" + + + // Maps to javac entry (5), location OK, taret type OK, lvar diff, slight position difference (we seem to have an extra CHECKCAST) + " #43 @Nonnull(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 6, pc: 28] index: 0\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + + // Maps to javac entry (6), location OK, target type OK, slight position difference (we seem to have an extra CHECKCAST) + " #33 @Size(\n" + + " #34 max=(int) 43 (constant type)\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 6, pc: 28] index: 0\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + + // Maps to javac entry (7), location OK, target type OK, slight position difference (we seem to have an extra CHECKCAST) + " #33 @Size(\n" + + " #34 max=(int) 41 (constant type)\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 6, pc: 28] index: 0\n" + + " location = [ARRAY, ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0)]\n" + + " )\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void testBug426616a() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n"+ + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "import static java.lang.annotation.RetentionPolicy.*;\n" + + "@Retention(RUNTIME)\n" + + "@Target(TYPE_USE)\n" + + "@interface SizeHolder { Size[] value();}\n"+ + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@Repeatable(SizeHolder.class)\n"+ + "@interface Size { int max(); }\n"+ + "@Target(TYPE_USE)\n" + + "@Retention(RUNTIME)\n" + + "@interface Nonnull {}\n"+ + "\n"+ + "public class X {\n" + + " List<@Size(max = 41) CharSequence>[] @Size(max = 42) [] @Nonnull @Size(max = 43) [][] test = new @Size(max = 44) ArrayList @Size(max = 45) [10][][] @Size(max = 47) @Size(max = 48) [];\n" + + " public static void main(String[]argv) {}\n"+ + "}", + }, + ""); + + String expectedOutput = + " // Field descriptor #6 [[[[Ljava/util/List;\n" + + " // Signature: [[[[Ljava/util/List;\n" + + " java.util.List[][][][] test;\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @Size(\n" + + " #11 max=(int) 42 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n" + + " #13 @Nonnull(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #10 @Size(\n" + + " #11 max=(int) 43 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #10 @Size(\n" + + " #11 max=(int) 41 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, ARRAY, ARRAY, TYPE_ARGUMENT(0)]\n" + + " )\n" + + " \n" + + " // Method descriptor #17 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [19]\n" + + " 4 aload_0 [this]\n" + + " 5 bipush 10\n" + + " 7 anewarray java.util.ArrayList[][][] [21]\n" + + " 10 putfield X.test : java.util.List[][][][] [23]\n" + + " 13 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 16]\n" + + " [pc: 4, line: 17]\n" + + " [pc: 13, line: 16]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 14] local: this index: 0 type: X\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #10 @Size(\n" + + " #11 max=(int) 44 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 7\n" + + " location = [ARRAY, ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " #10 @Size(\n" + + " #11 max=(int) 45 (constant type)\n" + + " target type = 0x44 NEW\n" + + " offset = 7\n" + + " )\n" + + " #31 @SizeHolder(\n" + + " #32 value=[\n" + + " annotation value =\n" + + " #10 @Size(\n" + + " #11 max=(int) 47 (constant type)\n" + + " )\n" + + " annotation value =\n" + + " #10 @Size(\n" + + " #11 max=(int) 48 (constant type)\n" + + " )\n" + + " ]\n" + + " target type = 0x44 NEW\n" + + " offset = 7\n" + + " location = [ARRAY, ARRAY, ARRAY]\n" + + " )\n" + + " \n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + public void testTypeVariable() { + runNegativeTest( + new String[] { + "X.java", + "public class X<@Missing T> {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public class X<@Missing T> {\n" + + " ^^^^^^^\n" + + "Missing cannot be resolved to a type\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=417660, [1.8][compiler] Incorrect parsing of Annotations with array dimensions in arguments + public void test417660() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Documented;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "public class X {\n" + + " int bar(int [] @TakeType(int[].class)[] x) { \n" + + " return x[0][0]; \n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().bar(new int [][] { { 1234 }}));\n" + + " }\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Documented\n" + + "@interface TakeType {\n" + + " Class value() default int[].class;\n" + + "}\n" + }, + "1234"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=417660, [1.8][compiler] Incorrect parsing of Annotations with array dimensions in arguments + public void test417660b() { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Documented;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "import java.lang.annotation.Target;\n" + + "public class X {\n" + + " int bar(int [][] @TakeType(int[].class)[][] x @TakeType(int[].class)[]) { \n" + + " return x[0][0][0][0][0]; \n" + + " } \n" + + " public static void main(String[] args) {\n" + + " System.out.println(new X().bar(new int [][][][][] { { { { { 1234 } } } } }));\n" + + " }\n" + + "}\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Documented\n" + + "@interface TakeType {\n" + + " Class value() default int[].class;\n" + + "}\n" + }, + "1234"); + } + + public void testAnnotatedExtendedDimensions() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " @NonNull String @Nullable [] f @NonNull [] = null;\n" + + " static @NonNull String @Nullable [] foo(@NonNull String @Nullable [] p @NonNull []) @NonNull [] {\n" + + " p = null;\n" + + " @NonNull String @Nullable [] l @NonNull [] = null;\n" + + " return p;\n" + + " }\n" + + "}\n", + + "NonNull.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface NonNull {}\n", + + "Nullable.java", + "import java.lang.annotation.*;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@interface Nullable {}\n", + }, + ""); + String expectedOutput = + " // Field descriptor #6 [[Ljava/lang/String;\n" + + " java.lang.String[][] f;\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @NonNull(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #9 @Nullable(\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n" + + " #8 @NonNull(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n" + + " // Method descriptor #11 ()V\n" + + " // Stack: 2, Locals: 1\n" + + " public X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [13]\n" + + " 4 aload_0 [this]\n" + + " 5 aconst_null\n" + + " 6 putfield X.f : java.lang.String[][] [15]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 1]\n" + + " [pc: 4, line: 2]\n" + + " [pc: 9, line: 1]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X\n" + + " \n" + + " // Method descriptor #22 ([[Ljava/lang/String;)[[Ljava/lang/String;\n" + + " // Stack: 1, Locals: 2\n" + + " static java.lang.String[][] foo(java.lang.String[][] p);\n" + + " 0 aconst_null\n" + + " 1 astore_0 [p]\n" + + " 2 aconst_null\n" + + " 3 astore_1 [l]\n" + + " 4 aload_0 [p]\n" + + " 5 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 4]\n" + + " [pc: 2, line: 5]\n" + + " [pc: 4, line: 6]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 6] local: p index: 0 type: java.lang.String[][]\n" + + " [pc: 4, pc: 6] local: l index: 1 type: java.lang.String[][]\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @NonNull(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 4, pc: 6] index: 1\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #9 @Nullable(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 4, pc: 6] index: 1\n" + + " location = [ARRAY]\n" + + " )\n" + + " #8 @NonNull(\n" + + " target type = 0x40 LOCAL_VARIABLE\n" + + " local variable entries:\n" + + " [pc: 4, pc: 6] index: 1\n" + + " )\n" + + " RuntimeVisibleTypeAnnotations: \n" + + " #8 @NonNull(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #9 @Nullable(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [ARRAY]\n" + + " )\n" + + " #8 @NonNull(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " #8 @NonNull(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #9 @Nullable(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " location = [ARRAY]\n" + + " )\n" + + " #8 @NonNull(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=418347, [1.8][compiler] Type annotations dropped during code generation. + public void testPQTRArray() throws Exception { + this.runConformTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " class Inner

    {\n" + + " }\n" + + " public @T(1) Outer<@T(2) String>.@T(3) Inner<@T(4) Integer> @T(5) [] omi @T(6) [];\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface T {\n" + + " int value();\n" + + "}\n", + }, + ""); + String expectedOutput = + " public Outer$Inner[][] omi;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @T(\n" + + " #11 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 5 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 6 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 4 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, TYPE_ARGUMENT(0)]\n" + + " )\n" + + " \n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "Outer.class", "Outer", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=418347, [1.8][compiler] Type annotations dropped during code generation. + public void testPQTRArray2() throws Exception { + this.runConformTest( + new String[] { + "Outer.java", + "public class Outer {\n" + + " class Inner {\n" + + " }\n" + + " public @T(1) Outer<@T(2) String, @T(3) Inner>.@T(4) Inner<@T(5) Integer, @T(6) Outer.@T(7) Inner> @T(7) [] omi @T(8) [];\n" + + "}\n" + + "@java.lang.annotation.Target (java.lang.annotation.ElementType.TYPE_USE)\n" + + "@interface T {\n" + + " int value();\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Field descriptor #6 [[LOuter$Inner;\n" + + " // Signature: [[LOuter.Inner;\n" + + " public Outer$Inner[][] omi;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #10 @T(\n" + + " #11 value=(int) 1 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 4 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 7 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 8 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 2 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 3 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, TYPE_ARGUMENT(1), INNER_TYPE]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 5 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, TYPE_ARGUMENT(0)]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 6 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, TYPE_ARGUMENT(1)]\n" + + " )\n" + + " #10 @T(\n" + + " #11 value=(int) 7 (constant type)\n" + + " target type = 0x13 FIELD\n" + + " location = [ARRAY, ARRAY, INNER_TYPE, TYPE_ARGUMENT(1), INNER_TYPE]\n" + + " )\n" + + " \n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "Outer.class", "Outer", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=418347, [1.8][compiler] Type annotations dropped during code generation. + public void testConstructorResult() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface T {\n" + + "}\n" + + "public class X {\n" + + " @T X() {}\n" + + " class Y {\n" + + " @T Y () {\n" + + " }\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Method descriptor #6 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [8]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #15 @T(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + "\n"; + String expectedOutForY = + " // Method descriptor #8 (LX;)V\n" + + " // Stack: 2, Locals: 2\n" + + " X$Y(X arg0);\n" + + " 0 aload_0 [this]\n" + + " 1 aload_1 [arg0]\n" + + " 2 putfield X$Y.this$0 : X [10]\n" + + " 5 aload_0 [this]\n" + + " 6 invokespecial java.lang.Object() [12]\n" + + " 9 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " [pc: 9, line: 10]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 10] local: this index: 0 type: X.Y\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #20 @T(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + "\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X$Y.class", "Y", expectedOutForY, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=418347, [1.8][compiler] Type annotations dropped during code generation. + public void test418347() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Target({TYPE_USE}) @interface P { }\n" + + "@Target({TYPE_USE}) @interface O { }\n" + + "@Target({TYPE_USE}) @interface I { }\n" + + "public abstract class X {\n" + + " class Y {\n" + + " }\n" + + " void foo(@P Y

    p) {}\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #24 @P(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [INNER_TYPE]\n" + + " )\n" + + "\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=418347, [1.8][compiler] Type annotations dropped during code generation. + public void test418347a() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.*;\n" + + "import static java.lang.annotation.ElementType.*;\n" + + "@Target({TYPE_USE}) @interface P { }\n" + + "@Target({TYPE_USE}) @interface O { }\n" + + "@Target({TYPE_USE}) @interface I { }\n" + + "public abstract class X {\n" + + " class Y {\n" + + " class Z {}\n" + + " }\n" + + " void foo(@P X.@O Y.@I Z[] p) {}\n" + + "}\n", + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #19 @P(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [ARRAY]\n" + + " )\n" + + " #20 @O(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [ARRAY, INNER_TYPE]\n" + + " )\n" + + " #21 @I(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " location = [ARRAY, INNER_TYPE, INNER_TYPE]\n" + + " )\n" + + "\n"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=418347, [1.8][compiler] Type annotations dropped during code generation. + public void test418347b() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public abstract class X {\n" + + " java.util.List [][] l = new java.util.ArrayList @pkg.NonNull [0] @pkg.NonNull[]; \n" + + "}\n", + "pkg/NonNull.java", + "package pkg;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE_USE)\n" + + "public @interface NonNull {\n" + + "}\n" + }, + ""); + String expectedOutput = + " RuntimeInvisibleTypeAnnotations: \n" + + " #21 @pkg.NonNull(\n" + + " target type = 0x44 NEW\n" + + " offset = 6\n" + + " )\n" + + " #21 @pkg.NonNull(\n" + + " target type = 0x44 NEW\n" + + " offset = 6\n" + + " location = [ARRAY]\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=419331, [1.8][compiler] Weird error on forward reference to type annotations from type parameter declarations + public void testForwardReference() { + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.JavacHasWarningsEclipseNotConfigured, + new String[] { + "T.java", + "import java.lang.annotation.Annotation;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@R(TC.class)\n" + + "@Target(ElementType.TYPE_PARAMETER)\n" + + "@interface T {\n" + + "}\n" + + "\n" + + "interface I<@T K> {\n" + + "}\n" + + "\n" + + "@Deprecated\n" + + "@interface TC {\n" + + "\n" + + "}\n" + + "\n" + + "@Target(ElementType.ANNOTATION_TYPE)\n" + + "@interface R {\n" + + " Class value();\n" + + "}\n", + }, + ""); + } + public void testHybridTargets() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target({ElementType.TYPE_USE, ElementType.PACKAGE})\n" + + "@interface T {\n" + + "}\n" + + "@T\n" + + "public class X {\n" + + " @T\n" + + " X() {}\n" + + " @T String x;\n" + + " @T \n" + + " int foo(@T int p) { \n" + + " @T int l;\n" + + " return 0;\n" + + " }\n" + + "}\n", + }, + ""); + String expectedOutput = + " // Field descriptor #6 Ljava/lang/String;\n" + + " java.lang.String x;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n" + + " // Method descriptor #10 ()V\n" + + " // Stack: 1, Locals: 1\n" + + " X();\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 9]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + " \n" + + " // Method descriptor #19 (I)I\n" + + " // Stack: 1, Locals: 2\n" + + " int foo(int p);\n" + + " 0 iconst_0\n" + + " 1 ireturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 2] local: this index: 0 type: X\n" + + " [pc: 0, pc: 2] local: p index: 1 type: int\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @T(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " #8 @T(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + "\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @T(\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void testHybridTargets2() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "@Target({ ElementType.TYPE_USE, ElementType.METHOD })\n" + + "@interface SillyAnnotation { }\n" + + "public class X {\n" + + " @SillyAnnotation\n" + + " X(@SillyAnnotation int x) {\n" + + " }\n" + + " @SillyAnnotation\n" + + " void foo(@SillyAnnotation int x) {\n" + + " }\n" + + " @SillyAnnotation\n" + + " String goo(@SillyAnnotation int x) {\n" + + " return null;\n" + + " }\n" + + " @SillyAnnotation\n" + + " X field;\n" + + "}\n" + }, + ""); + String expectedOutput = + " // Field descriptor #6 LX;\n" + + " X field;\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @SillyAnnotation(\n" + + " target type = 0x13 FIELD\n" + + " )\n" + + " \n" + + " // Method descriptor #10 (I)V\n" + + " // Stack: 1, Locals: 2\n" + + " X(int x);\n" + + " 0 aload_0 [this]\n" + + " 1 invokespecial java.lang.Object() [12]\n" + + " 4 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 7]\n" + + " [pc: 4, line: 8]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 5] local: this index: 0 type: X\n" + + " [pc: 0, pc: 5] local: x index: 1 type: int\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @SillyAnnotation(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " #8 @SillyAnnotation(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + " \n" + + " // Method descriptor #10 (I)V\n" + + " // Stack: 0, Locals: 2\n" + + " void foo(int x);\n" + + " 0 return\n" + + " Line numbers:\n" + + " [pc: 0, line: 11]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 1] local: this index: 0 type: X\n" + + " [pc: 0, pc: 1] local: x index: 1 type: int\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @SillyAnnotation(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @SillyAnnotation(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " \n" + + " // Method descriptor #23 (I)Ljava/lang/String;\n" + + " // Stack: 1, Locals: 2\n" + + " java.lang.String goo(int x);\n" + + " 0 aconst_null\n" + + " 1 areturn\n" + + " Line numbers:\n" + + " [pc: 0, line: 14]\n" + + " Local variable table:\n" + + " [pc: 0, pc: 2] local: this index: 0 type: X\n" + + " [pc: 0, pc: 2] local: x index: 1 type: int\n" + + " RuntimeInvisibleAnnotations: \n" + + " #8 @SillyAnnotation(\n" + + " )\n" + + " RuntimeInvisibleTypeAnnotations: \n" + + " #8 @SillyAnnotation(\n" + + " target type = 0x16 METHOD_FORMAL_PARAMETER\n" + + " method parameter index = 0\n" + + " )\n" + + " #8 @SillyAnnotation(\n" + + " target type = 0x14 METHOD_RETURN\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + public void testDeprecated() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Deprecated\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@interface X {\n" + + " int value() default 0;\n" + + "}\n" + }, + ""); + String expectedOutput = + "// Compiled from X.java (version 1.8 : 52.0, no super bit, deprecated)\n" + + "abstract @interface X extends java.lang.annotation.Annotation {\n" + + " Constant pool:\n" + + " constant #1 class: #2 X\n" + + " constant #2 utf8: \"X\"\n" + + " constant #3 class: #4 java/lang/Object\n" + + " constant #4 utf8: \"java/lang/Object\"\n" + + " constant #5 class: #6 java/lang/annotation/Annotation\n" + + " constant #6 utf8: \"java/lang/annotation/Annotation\"\n" + + " constant #7 utf8: \"value\"\n" + + " constant #8 utf8: \"()I\"\n" + + " constant #9 utf8: \"AnnotationDefault\"\n" + + " constant #10 integer: 0\n" + + " constant #11 utf8: \"SourceFile\"\n" + + " constant #12 utf8: \"X.java\"\n" + + " constant #13 utf8: \"Deprecated\"\n" + + " constant #14 utf8: \"RuntimeVisibleAnnotations\"\n" + + " constant #15 utf8: \"Ljava/lang/Deprecated;\"\n" + + " constant #16 utf8: \"Ljava/lang/annotation/Target;\"\n" + + " constant #17 utf8: \"Ljava/lang/annotation/ElementType;\"\n" + + " constant #18 utf8: \"TYPE_USE\"\n" + + " \n" + + " // Method descriptor #8 ()I\n" + + " public abstract int value();\n" + + " Annotation Default: \n" + + " (int) 0 (constant type)\n" + + "\n" + + " RuntimeVisibleAnnotations: \n" + + " #15 @java.lang.Deprecated(\n" + + " )\n" + + " #16 @java.lang.annotation.Target(\n" + + " #7 value=[\n" + + " java.lang.annotation.ElementType.TYPE_USE(enum type #17.#18)\n" + + " ]\n" + + " )\n" + + "}"; + checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421148, [1.8][compiler] Verify error with annotated casts and unused locals. + public void test421148() { + + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "@Target(ElementType.TYPE_USE) @interface T {}\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " Object o = (@T Object) new Object(); \n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK", + customOptions); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421620, [1.8][compiler] wrong compile error with TYPE_USE annotation on exception + public void test421620() { + + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.Documented;\n" + + "import java.lang.annotation.Retention;\n" + + "import java.lang.annotation.Target;\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.RetentionPolicy;\n" + + "class E1 extends Exception {\n" + + " private static final long serialVersionUID = 1L;\n" + + "}\n" + + "\n" + + "@Target(ElementType.TYPE_USE)\n" + + "@Retention(RetentionPolicy.RUNTIME)\n" + + "@Documented\n" + + "@interface NonCritical { }\n" + + "public class X {\n" + + " @NonCritical E1 e1; // looks like this field's type binding is reused\n" + + "//wrong error:\n" + + "//Cannot use the parameterized type E1 either in catch block or throws clause\n" + + " void f1 (int a) throws /*@NonCritical*/ E1 {\n" + + " throw new E1();\n" + + " }\n" + + " void foo() {\n" + + " try {\n" + + " f1(0);\n" + + "//wrong error: Unreachable catch block for E1.\n" + + "// This exception is never thrown from the try statement body\n" + + " } catch (@NonCritical final RuntimeException | @NonCritical E1 ex) {\n" + + " System.out.println(ex);\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + }, + "OK", + customOptions); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=425599, [1.8][compiler] ISE when trying to compile qualified and annotated class instance creation + public void _test425599() { + + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + runConformTest( + new String[] { + "X.java", + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "public class X {\n" + + " Object ax = new @A Outer().new Middle();\n" + + " public static void main(String args[]) {\n" + + " System.out.println(\"OK\");\n" + + " }\n" + + "}\n" + + "@Target(ElementType.TYPE_USE) @interface A {}\n" + + "class Outer {\n" + + " class Middle {\n" + + " class Inner {}\n" + + " @A Middle.@A Inner ax = new pack.@A Outer().new @A Middle<@A Object>().new @A Inner<@A Character>(null);\n" + + " }\n" + + "}\n" + }, + "OK", + customOptions); + } + public void testBug485386() { + String javaVersion = System.getProperty("java.version"); + int index = javaVersion.indexOf('.'); + if (index != -1) { + javaVersion = javaVersion.substring(0, index); + } else { + index = javaVersion.indexOf('-'); + if (index != -1) + javaVersion = javaVersion.substring(0, index); + } + int v = Integer.parseInt(javaVersion); + runConformTest( + new String[] { + "Test.java", + "import java.lang.annotation.*;\n" + + "import java.lang.reflect.*;\n" + + "\n" + + "@Retention(value = RetentionPolicy.RUNTIME)\n" + + "@java.lang.annotation.Target(ElementType.TYPE_USE)\n" + + "@interface TestAnn1 {\n" + + " String value() default \"1\";\n" + + "}\n" + + "\n" + + "public class Test {\n" + + "\n" + + " class Inner {\n" + + " public @TestAnn1() Inner() {\n" + + " System.out.println(\"New\");\n" + + " }\n" + + " }\n" + + "\n" + + " public void test() throws SecurityException, NoSuchMethodException {\n" + + " Executable f = Test.Inner.class.getDeclaredConstructor(Test.class);\n" + + " AnnotatedType ae = f.getAnnotatedReturnType();\n" + + " Object o = ae.getAnnotation(TestAnn1.class);\n" + + " System.out.println(o);\n" + + " }\n" + + " \n" + + " public static void main(String... args) throws Exception {\n" + + " new Test().test();\n" + + " }\n" + + "}\n" + }, + "@TestAnn1(" + (v < 14 ? "value=" : "") + decorateAnnotationValueLiteral("1") + ")"); + } + public void testBug492322readFromClass() { + runConformTest( + new String[] { + "test1/Base.java", + "package test1;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE) @interface A2 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A3 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A4 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A5 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A6 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A7 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A8 {}\n" + + "@Target(ElementType.TYPE_USE) @interface B1 {}\n" + + "@Target(ElementType.TYPE_USE) @interface B2 {}\n" + + "@Target(ElementType.TYPE_USE) @interface B3 {}\n" + + "@Target(ElementType.TYPE_USE) @interface C1 {}\n" + + "@Target(ElementType.TYPE_USE) @interface C2 {}\n" + + "\n" + + "public abstract class Base {\n" + + " static public class Static {\n" + + " public class Middle1 {\n" + + " public class Middle2 {\n" + + " public class Middle3 {\n" + + " public class GenericInner {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " public Object method1(Base.@A2 Static.@A3 Middle1.@A4 Middle2.@A5 Middle3.@A6 GenericInner nullable) {\n" + + " return new Object();\n" + + " }\n" + + " public Object method2(Base.@A2 Static.@A3 Middle1.@A4 Middle2<@B1 Object>.@A5 Middle3.@A6 GenericInner<@B2 String> @A7 [] @A8 [] nullable) {\n" + + " return new Object();\n" + + " }\n" + + " public Object method3(Base.@A2 Static.@A3 Middle1.@A4 Middle2<@B1 Class<@C1 Object @C2 []> @B2 []>.@A5 Middle3.@A6 GenericInner<@B3 String> @A7 [] @A8 [] nullable) {\n" + + " return new Object();\n" + + " }\n" + + "}\n" + + "", + } + ); + + // get compiled type via binarytypebinding + Requestor requestor = new Requestor(false, null /*no custom requestor*/, false, /* show category */ false /* show warning token*/); + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + Compiler compiler = new Compiler(getNameEnvironment(new String[0], null), getErrorHandlingPolicy(), + new CompilerOptions(customOptions), requestor, getProblemFactory()); + char [][] compoundName = new char [][] { "test1".toCharArray(), "Base".toCharArray()}; + ReferenceBinding type = compiler.lookupEnvironment.askForType(compoundName, compiler.lookupEnvironment.UnNamedModule); + assertNotNull(type); + MethodBinding[] methods1 = type.getMethods("method1".toCharArray()); + assertEquals("Base.@A2 Static.@A3 Middle1.@A4 Middle2.@A5 Middle3.@A6 GenericInner", + new String(methods1[0].parameters[0].annotatedDebugName())); + + MethodBinding[] methods2 = type.getMethods("method2".toCharArray()); + assertEquals("Base.@A2 Static.@A3 Middle1.@A4 Middle2<@B1 Object>.@A5 Middle3.@A6 GenericInner<@B2 String> @A7 [] @A8 []", + new String(methods2[0].parameters[0].annotatedDebugName())); + + MethodBinding[] methods3 = type.getMethods("method3".toCharArray()); + assertEquals("Base.@A2 Static.@A3 Middle1.@A4 Middle2<@B1 Class<@C1 Object @C2 []> @B2 []>.@A5 Middle3.@A6 GenericInner<@B3 String> @A7 [] @A8 []", + new String(methods3[0].parameters[0].annotatedDebugName())); + } + + public void testBug492322readFromClassWithGenericBase() { + runConformTest( + new String[] { + "test1/Base.java", + "package test1;\n" + + "\n" + + "import java.lang.annotation.ElementType;\n" + + "import java.lang.annotation.Target;\n" + + "\n" + + "@Target(ElementType.TYPE_USE) @interface A2 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A3 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A4 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A5 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A6 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A7 {}\n" + + "@Target(ElementType.TYPE_USE) @interface A8 {}\n" + + "@Target(ElementType.TYPE_USE) @interface B1 {}\n" + + "@Target(ElementType.TYPE_USE) @interface B2 {}\n" + + "@Target(ElementType.TYPE_USE) @interface B3 {}\n" + + "@Target(ElementType.TYPE_USE) @interface C1 {}\n" + + "@Target(ElementType.TYPE_USE) @interface C2 {}\n" + + "\n" + + "public abstract class Base {\n" + + " static public class Static {\n" + + " public class Middle1 {\n" + + " public class Middle2 {\n" + + " public class Middle3 {\n" + + " public class GenericInner {\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " public Object method1(Base.@A2 Static.@A3 Middle1.@A4 Middle2.@A5 Middle3.@A6 GenericInner nullable) {\n" + + " return new Object();\n" + + " }\n" + + " public Object method2(Base.@A2 Static.@A3 Middle1.@A4 Middle2<@B1 Object>.@A5 Middle3.@A6 GenericInner<@B2 String> @A7 [] @A8 [] nullable) {\n" + + " return new Object();\n" + + " }\n" + + " public Object method3(Base.@A2 Static.@A3 Middle1.@A4 Middle2<@B1 Class<@C1 Object @C2 []> @B2 []>.@A5 Middle3.@A6 GenericInner<@B3 String> @A7 [] @A8 [] nullable) {\n" + + " return new Object();\n" + + " }\n" + + "}\n" + + "", + } + ); + + // get compiled type via binarytypebinding + Requestor requestor = new Requestor(false, null /*no custom requestor*/, false, /* show category */ false /* show warning token*/); + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + Compiler compiler = new Compiler(getNameEnvironment(new String[0], null), getErrorHandlingPolicy(), + new CompilerOptions(customOptions), requestor, getProblemFactory()); + char [][] compoundName = new char [][] { "test1".toCharArray(), "Base".toCharArray()}; + ReferenceBinding type = compiler.lookupEnvironment.askForType(compoundName, compiler.lookupEnvironment.UnNamedModule); + assertNotNull(type); + MethodBinding[] methods1 = type.getMethods("method1".toCharArray()); + assertEquals("Base.@A2 Static.@A3 Middle1.@A4 Middle2.@A5 Middle3.@A6 GenericInner", + new String(methods1[0].parameters[0].annotatedDebugName())); + + MethodBinding[] methods2 = type.getMethods("method2".toCharArray()); + assertEquals("Base.@A2 Static.@A3 Middle1.@A4 Middle2<@B1 Object>.@A5 Middle3.@A6 GenericInner<@B2 String> @A7 [] @A8 []", + new String(methods2[0].parameters[0].annotatedDebugName())); + + MethodBinding[] methods3 = type.getMethods("method3".toCharArray()); + assertEquals("Base.@A2 Static.@A3 Middle1.@A4 Middle2<@B1 Class<@C1 Object @C2 []> @B2 []>.@A5 Middle3.@A6 GenericInner<@B3 String> @A7 [] @A8 []", + new String(methods3[0].parameters[0].annotatedDebugName())); + } + public void testBug492322WithOldBinary() { + // bug492322-compiled-with-4.6.jar contains classes compiled with eclipse 4.6: + /*- + package test1; + + import java.lang.annotation.ElementType; + import java.lang.annotation.Target; + + @Target(ElementType.TYPE_USE) @interface A2 {} + @Target(ElementType.TYPE_USE) @interface A3 {} + @Target(ElementType.TYPE_USE) @interface A4 {} + @Target(ElementType.TYPE_USE) @interface A5 {} + @Target(ElementType.TYPE_USE) @interface A6 {} + @Target(ElementType.TYPE_USE) @interface A7 {} + @Target(ElementType.TYPE_USE) @interface A8 {} + @Target(ElementType.TYPE_USE) @interface B1 {} + @Target(ElementType.TYPE_USE) @interface B2 {} + @Target(ElementType.TYPE_USE) @interface B3 {} + @Target(ElementType.TYPE_USE) @interface B4 {} + @Target(ElementType.TYPE_USE) @interface C1 {} + @Target(ElementType.TYPE_USE) @interface C2 {} + + public abstract class Base { + static public class Static { + public static class Static2 { + public class Middle1 { + public class Middle2 { + public class Middle3 { + public class GenericInner { + } + } + } + } + } + } + + public Object method1(Static.@A2 Static2.@A3 Middle1.@A4 Middle2.@A5 Middle3.@A6 GenericInner nullable) { + return new Object(); + } + public Object method2(Static.@A2 Static2<@B1 Exception>.@A3 Middle1.@A4 Middle2<@B2 Object>.@A5 Middle3.@A6 GenericInner<@B3 String> @A7 [] @A8 [] nullable) { + return new Object(); + } + public Object method3(Static.@A2 Static2<@B1 Exception>.@A3 Middle1.@A4 Middle2<@B2 Class<@C1 Object @C2 []> @B3 []>.@A5 Middle3.@A6 GenericInner<@B4 String> @A7 [] @A8 [] nullable) { + return new Object(); + } + } + */ + // get compiled type via binarytypebinding + Requestor requestor = new Requestor(false, null /*no custom requestor*/, false, /* show category */ false /* show warning token*/); + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + String[] defaultClassPaths = getDefaultClassPaths(); + String jarpath = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "bug492322-compiled-with-4.6.jar"; + String[] paths = new String[defaultClassPaths.length + 1]; + System.arraycopy(defaultClassPaths, 0, paths, 0, defaultClassPaths.length); + paths[defaultClassPaths.length] = jarpath; + Compiler compiler = new Compiler(getNameEnvironment(new String[0], paths), getErrorHandlingPolicy(), + new CompilerOptions(customOptions), requestor, getProblemFactory()); + char [][] compoundName = new char [][] { "test1".toCharArray(), "Base".toCharArray()}; + ReferenceBinding type = compiler.lookupEnvironment.askForType(compoundName, compiler.lookupEnvironment.UnNamedModule); + assertNotNull(type); + MethodBinding[] methods1 = type.getMethods("method1".toCharArray()); + assertEquals("Base.Static.@A2 Static2.@A3 Middle1.@A4 Middle2.@A5 Middle3.@A6 GenericInner", + new String(methods1[0].parameters[0].annotatedDebugName())); + + MethodBinding[] methods2 = type.getMethods("method2".toCharArray()); + assertEquals("Base.Static.@A2 Static2<@B1 Exception>.@A3 Middle1.@A4 Middle2<@B2 Object>.@A5 Middle3.@A6 GenericInner<@B3 String> @A7 [] @A8 []", + new String(methods2[0].parameters[0].annotatedDebugName())); + + MethodBinding[] methods3 = type.getMethods("method3".toCharArray()); + assertEquals("Base.Static.@A2 Static2<@B1 Exception>.@A3 Middle1.@A4 Middle2<@B2 Class<@C1 Object @C2 []> @B3 []>.@A5 Middle3.@A6 GenericInner<@B4 String> @A7 [] @A8 []", + new String(methods3[0].parameters[0].annotatedDebugName())); + } + + public void testBug594561_ParameterizedTypeAnnotations() { + runConformTest(new String[] { + "p/C.java", + "package p;" + + "@Deprecated\n" + + "abstract class A {}\n" + + "class C extends A {}\n", + }); + + Requestor requestor = new Requestor(false, null, false, false); + Map customOptions = getCompilerOptions(); customOptions.put(CompilerOptions.OPTION_Store_Annotations, CompilerOptions.ENABLED); + Compiler compiler = new Compiler(getNameEnvironment(new String[0], null), getErrorHandlingPolicy(), new CompilerOptions(customOptions), requestor, getProblemFactory()); + + ReferenceBinding type = compiler.lookupEnvironment.askForType(new char[][] {"p".toCharArray(), "C".toCharArray()}, compiler.lookupEnvironment.UnNamedModule); + assertNotNull(type); + + AnnotationBinding[] annos = type.superclass().getAnnotations(); + assertEquals(1, annos.length); + assertEquals("java.lang.Deprecated", annos[0].getAnnotationType().debugName()); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UnderscoresInLiteralsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UnderscoresInLiteralsTest.java new file mode 100644 index 0000000000..41127d9a88 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UnderscoresInLiteralsTest.java @@ -0,0 +1,443 @@ +/******************************************************************************* + * Copyright (c) 2011, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * 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; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +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/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode10Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode10Test.java new file mode 100644 index 0000000000..19badb2bed --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode10Test.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +public class Unicode10Test extends AbstractRegressionTest { +public Unicode10Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_11); +} +public void test1() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int a\u0860; // new unicode character in unicode 10.0 \n" + + "}", + }, + "", + options); +} +public static Class testClass() { + return Unicode10Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode11Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode11Test.java new file mode 100644 index 0000000000..99940b1397 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode11Test.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +public class Unicode11Test extends AbstractRegressionTest { +public Unicode11Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_12); +} +public void test1() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int a\u0560; // new unicode character in unicode 11.0 \n" + + "}", + }, + "", + options); +} +public void test2() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_11); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public int a\\u0560; // new unicode character in unicode 11.0 \n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public int a\\u0560; // new unicode character in unicode 11.0 \n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n", + null, + true, + options); +} +public static Class testClass() { + return Unicode11Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode12_1Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode12_1Test.java new file mode 100644 index 0000000000..11f4a39819 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode12_1Test.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +public class Unicode12_1Test extends AbstractRegressionTest { +public Unicode12_1Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_13); +} +public void test1() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_13); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int a\\uA7BA; // new unicode character in unicode 12.0 \n" + + "}", + }, + "", + options); +} +public void test2() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_12); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public int a\\uA7BA; // new unicode character in unicode 12.0 \n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " public int a\\uA7BA; // new unicode character in unicode 12.0 \n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n", + null, + true, + options); +} +public static Class testClass() { + return Unicode12_1Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode13Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode13Test.java new file mode 100644 index 0000000000..eb0a5b1f14 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode13Test.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2019, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +public class Unicode13Test extends AbstractRegressionTest { +public Unicode13Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_15); +} +public void test1() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int a\\u08BE; // new unicode character in unicode 13 \n" + + "}", + }, + "", + options); +} +public void test2() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int a\\ud880\\udc00; // new unicode character in unicode 13 using high and low surrogate\n" + + "}", + }, + "", + options); +} +public static Class testClass() { + return Unicode13Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode18Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode18Test.java new file mode 100644 index 0000000000..a315405193 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode18Test.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2014, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Unicode18Test extends AbstractRegressionTest { +public Unicode18Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_8); +} +public void test426214() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " int a\\u058f = 0; // new unicode character in 6.2.0 \n" + + " String a41\\u08fc; // new unicode character in 6.2.0\n" + + " float a\\u057f = 1;\n" + + "}", + }, + "", + options); +} +public void test426214_2() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.JavacCompilesIncorrectSource, + new String[] { + "X.java", + "public class X {\n" + + " int a\\u058f = 0; // new unicode character in 6.2.0 \n" + + " String a41\\u08fc; // new unicode character in 6.2.0\n" + + " float a\\u057f = 1;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int a\\u058f = 0; // new unicode character in 6.2.0 \n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " String a41\\u08fc; // new unicode character in 6.2.0\n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n", + null, + true, + options); +} +public void test426214_3() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + this.runNegativeTest( + false /* skipJavac */, + JavacTestOptions.Excuse.JavacCompilesIncorrectSource, + new String[] { + "X.java", + "public class X {\n" + + " int a\\u058f = 0; // new unicode character in 6.2.0 \n" + + " String a41\\u08fc; // new unicode character in 6.2.0\n" + + " float a\\u057f = 1;\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int a\\u058f = 0; // new unicode character in 6.2.0 \n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n" + + "2. ERROR in X.java (at line 3)\n" + + " String a41\\u08fc; // new unicode character in 6.2.0\n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n", + null, + true, + options); +} +public void test426214_4() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " int a\\u061C = 0; // new unicode character in 6.3.0 \n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " int a\\u061C = 0; // new unicode character in 6.3.0 \n" + + " ^^^^^^\n" + + "Syntax error on token \"Invalid Character\", delete this token\n" + + "----------\n", + null, + true, + options); +} +public static Class testClass() { + return Unicode18Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode9Test.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode9Test.java new file mode 100644 index 0000000000..a77892c4cb --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Unicode9Test.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2015, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +public class Unicode9Test extends AbstractRegressionTest { +public Unicode9Test(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); +} +public void test1() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_9); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public int a\u20BE; // new unicode character in unicode 8.0 \n" + + "}", + }, + "", + options); +} +public static Class testClass() { + return Unicode9Test.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UnnamedModuleTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UnnamedModuleTest.java new file mode 100644 index 0000000000..0374092e13 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UnnamedModuleTest.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2017 Till Brychcy and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Till Brychcy - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import junit.framework.Test; + +public class UnnamedModuleTest extends AbstractRegressionTest9 { + +static { +// TESTS_NAMES = new String[] { "testBugXXX" }; +// TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 }; +// TESTS_RANGE = new int[] { 11, -1 }; +} +public UnnamedModuleTest(String name) { + super(name); +} +public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_9); +} + +public static Class testClass() { + return UnnamedModuleTest.class; +} + +public void testBug522327() { + runConformTest( + new String[] { + "nonmodular/ProblemWithThrowable.java", + "package nonmodular;\n" + + "\n" + + "import java.io.IOException;\n" + + "import java.sql.SQLException;\n" + + "\n" + + "public class ProblemWithThrowable {\n" + + " public void saveProperties() throws IOException {\n" + + " }\n" + + "}\n" + + "", + } + ); +} + +public void testBug522326() { + runConformTest( + new String[] { + "nonmodular/ProblemWithNested.java", + "package nonmodular;\n" + + "\n" + + "import java.sql.Connection;\n" + + "import java.util.Map.Entry;\n" + + "\n" + + "public class ProblemWithNested {\n" + + "}\n" + + "", + } + ); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UtilTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UtilTest.java new file mode 100644 index 0000000000..32e7e8a329 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/UtilTest.java @@ -0,0 +1,749 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.io.File; + +//import org.apache.tools.ant.types.selectors.SelectorUtils; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.compiler.CharOperation; + +//import junit.framework.AssertionFailedError; +import junit.framework.Test; + +@SuppressWarnings({ "rawtypes" }) +public class UtilTest extends AbstractRegressionTest { + +StringBuffer camelCaseErrors; + +public UtilTest(String name) { + super(name); +} +static { +// TESTS_RANGE = new int[] { 62, -1 }; +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} +/** + * Assert that a pattern and a name matches or not. + * If result is invalid then store warning in buffer and display it. + */ +void assertCamelCase(String pattern, String name, boolean match) { + assertCamelCase(pattern, name, false /* name may have more parts*/, match); +} +/** + * Assert that a pattern and a name matches or not. + * If result is invalid then store warning in buffer and display it. + */ +void assertCamelCase(String pattern, String name, boolean prefixMatch, boolean match) { + boolean camelCase = CharOperation.camelCaseMatch(pattern==null?null:pattern.toCharArray(), name==null?null:name.toCharArray(), prefixMatch); + if (match != camelCase) { + StringBuffer line = new StringBuffer("'"); + line.append(name); + line.append("' SHOULD"); + if (!match) line.append(" NOT"); + line.append(" match pattern '"); + line.append(pattern); + line.append("', but it DOES"); + if (!camelCase) line.append(" NOT"); + if (this.camelCaseErrors.length() == 0) { + System.out.println("Invalid results in test "+getName()+":"); + } + System.out.println(" - "+line); + this.camelCaseErrors.append('\n'); + this.camelCaseErrors.append(line); + } +} +/* (non-Javadoc) + * @see org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest#setUp() + */ +@Override +protected void setUp() throws Exception { + super.setUp(); + this.camelCaseErrors = new StringBuffer(); +} + +public boolean checkPathMatch(char[] pattern, char[] path, boolean isCaseSensitive) { + + CharOperation.replace(pattern, '/', File.separatorChar); + CharOperation.replace(pattern, '\\', File.separatorChar); + CharOperation.replace(path, '/', File.separatorChar); + CharOperation.replace(path, '\\', File.separatorChar); + + boolean result = CharOperation.pathMatch(pattern, path, isCaseSensitive, File.separatorChar); + +// boolean antResult = SelectorUtils.matchPath(new String(pattern), new String(path), isCaseSensitive); +// if (antResult != result) { +// new AssertionFailedError("WARNING : Ant expectation for patchMatch(\""+new String(pattern)+"\", \""+new String(path)+"\", ...) is: "+antResult).printStackTrace(); +// } + + return result; +} + +public void test01() { + + assertTrue("Pattern matching failure", + !CharOperation.match("X".toCharArray(), "Xyz".toCharArray(), true)); +} +public void test02() { + + assertTrue("Pattern matching failure", + CharOperation.match("X*".toCharArray(), "Xyz".toCharArray(), true)); +} +public void test03() { + + assertTrue("Pattern matching failure", + CharOperation.match("X".toCharArray(), "X".toCharArray(), true)); +} +public void test04() { + + assertTrue("Pattern matching failure", + CharOperation.match("X*X".toCharArray(), "XYX".toCharArray(), true)); +} +public void test05() { + + assertTrue("Pattern matching failure", + CharOperation.match("XY*".toCharArray(), "XYZ".toCharArray(), true)); +} +public void test06() { + + assertTrue("Pattern matching failure", + CharOperation.match("*XY*".toCharArray(), "XYZ".toCharArray(), true)); +} +public void test07() { + + assertTrue("Pattern matching failure", + CharOperation.match("*".toCharArray(), "XYZ".toCharArray(), true)); +} +public void test08() { + + assertTrue("Pattern matching failure", + !CharOperation.match("a*".toCharArray(), "XYZ".toCharArray(), true)); +} +public void test09() { + + assertTrue("Pattern matching failure", + !CharOperation.match("abc".toCharArray(), "XYZ".toCharArray(), true)); +} +public void test10() { + + assertTrue("Pattern matching failure", + !CharOperation.match("ab*c".toCharArray(), "abX".toCharArray(), true)); +} +public void test11() { + + assertTrue("Pattern matching failure", + CharOperation.match("a*b*c".toCharArray(), "aXXbYYc".toCharArray(), true)); +} +public void test12() { + + assertTrue("Pattern matching failure", + !CharOperation.match("*a*bc".toCharArray(), "aXXbYYc".toCharArray(), true)); +} +public void test13() { + + assertTrue("Pattern matching failure", + !CharOperation.match("*foo*bar".toCharArray(), "".toCharArray(), true)); +} +public void test14() { + + assertTrue("Pattern matching failure", + CharOperation.match("*foo*bar".toCharArray(), "ffoobabar".toCharArray(), true)); +} +public void test15() { + + assertTrue("Pattern matching failure", + !CharOperation.match("*fol*bar".toCharArray(), "ffoobabar".toCharArray(), true)); +} +public void test16() { + + assertTrue("Pattern matching failure", + CharOperation.match("*X*Y*".toCharArray(), "XY".toCharArray(), true)); +} +public void test17() { + + assertTrue("Pattern matching failure", + CharOperation.match("*X*Y*".toCharArray(), "XYZ".toCharArray(), true)); +} +public void test18() { + + assertTrue("Pattern matching failure", + CharOperation.match("main(*)".toCharArray(), "main(java.lang.String[] argv)".toCharArray(), true)); +} +public void test19() { + + assertTrue("Pattern matching failure", + CharOperation.match("*rr*".toCharArray(), "ARRAY".toCharArray(), false)); +} + +public void test20() { + + assertTrue("Pattern matching failure", + CharOperation.match("hello*World".toCharArray(), "helloWorld".toCharArray(), true)); +} + +public void test21() { + assertEquals("Trim failure", "hello", new String(CharOperation.trim("hello".toCharArray()))); +} +public void test22() { + assertEquals("Trim failure", "hello", new String(CharOperation.trim(" hello".toCharArray()))); +} +public void test23() { + assertEquals("Trim failure", "hello", new String(CharOperation.trim(" hello ".toCharArray()))); +} +public void test24() { + assertEquals("Trim failure", "hello", new String(CharOperation.trim("hello ".toCharArray()))); +} +public void test25() { + assertEquals("Trim failure", "", new String(CharOperation.trim(" ".toCharArray()))); +} +public void test26() { + assertEquals("Trim failure", "hello world", new String(CharOperation.trim(" hello world ".toCharArray()))); +} +public void test27() { + char [][] tokens = CharOperation.splitAndTrimOn(','," hello,world".toCharArray()); + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < tokens.length; i++){ + buffer.append('[').append(tokens[i]).append(']'); + } + assertEquals("SplitTrim failure", "[hello][world]", buffer.toString()); +} +public void test28() { + char [][] tokens = CharOperation.splitAndTrimOn(','," hello , world".toCharArray()); + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < tokens.length; i++){ + buffer.append('[').append(tokens[i]).append(']'); + } + assertEquals("SplitTrim failure", "[hello][world]", buffer.toString()); +} +public void test29() { + char [][] tokens = CharOperation.splitAndTrimOn(','," hello, world ".toCharArray()); + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < tokens.length; i++){ + buffer.append('[').append(tokens[i]).append(']'); + } + assertEquals("SplitTrim failure", "[hello][world]", buffer.toString()); +} +public void test30() { + char [][] tokens = CharOperation.splitAndTrimOn(','," hello, world ,zork/, aaa bbb".toCharArray()); + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < tokens.length; i++){ + buffer.append('[').append(tokens[i]).append(']'); + } + assertEquals("SplitTrim failure", "[hello][world][zork/][aaa bbb]", buffer.toString()); +} +public void test31() { + char [][] tokens = CharOperation.splitAndTrimOn(','," , ".toCharArray()); + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < tokens.length; i++){ + buffer.append('[').append(tokens[i]).append(']'); + } + assertEquals("SplitTrim failure", "[][]", buffer.toString()); +} +public void test32() { + char [][] tokens = CharOperation.splitAndTrimOn(','," ".toCharArray()); + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < tokens.length; i++){ + buffer.append('[').append(tokens[i]).append(']'); + } + assertEquals("SplitTrim failure", "[]", buffer.toString()); +} +public void test33() { + char [][] tokens = CharOperation.splitAndTrimOn(','," , hello ".toCharArray()); + StringBuilder buffer = new StringBuilder(); + for (int i = 0; i < tokens.length; i++){ + buffer.append('[').append(tokens[i]).append(']'); + } + assertEquals("SplitTrim failure", "[][hello]", buffer.toString()); +} + +public void test34() { + + assertTrue("Path pattern matching failure", + checkPathMatch("hello/*/World".toCharArray(), "hello/zzz/World".toCharArray(), true)); +} + +public void test35() { + + assertTrue("Path pattern matching failure", + checkPathMatch("hello/**/World".toCharArray(), "hello/x/y/z/World".toCharArray(), true)); +} + +public void test36() { + + assertTrue("Path pattern matching failure", + checkPathMatch("hello/**/World/**/*.java".toCharArray(), "hello/x/y/z/World/X.java".toCharArray(), true)); +} + +public void test37() { + + assertTrue("Path pattern matching failure", + checkPathMatch("**/World/**/*.java".toCharArray(), "hello/x/y/z/World/X.java".toCharArray(), true)); +} + +public void test38() { + + assertTrue("Path pattern matching failure", + !checkPathMatch("/*.java".toCharArray(), "/hello/x/y/z/World/X.java".toCharArray(), true)); +} + +/* + * From Ant pattern set examples + */ +public void test39() { + + assertTrue("Path pattern matching failure-1", + checkPathMatch("**/CVS/*".toCharArray(), "CVS/Repository".toCharArray(), true)); + assertTrue("Path pattern matching failure-2", + checkPathMatch("**/CVS/*".toCharArray(), "org/apache/CVS/Entries".toCharArray(), true)); + assertTrue("Path pattern matching failure-3", + checkPathMatch("**/CVS/*".toCharArray(), "org/apache/jakarta/tools/ant/CVS/Entries".toCharArray(), true)); + assertTrue("Path pattern matching failure-4", + !checkPathMatch("**/CVS/*".toCharArray(), "org/apache/CVS/foo/bar/Entries".toCharArray(), true)); +} + +/* + * From Ant pattern set examples + */ +public void test40() { + + assertTrue("Path pattern matching failure-1", + checkPathMatch("org/apache/jakarta/**".toCharArray(), "org/apache/jakarta/tools/ant/docs/index.html".toCharArray(), true)); + assertTrue("Path pattern matching failure-2", + checkPathMatch("org/apache/jakarta/**".toCharArray(), "org/apache/jakarta/test.xml".toCharArray(), true)); + assertTrue("Path pattern matching failure-3", + !checkPathMatch("org/apache/jakarta/**".toCharArray(), "org/apache/xyz.java".toCharArray(), true)); +} + +/* + * From Ant pattern set examples + */ +public void test41() { + + assertTrue("Path pattern matching failure-1", + checkPathMatch("org/apache/**/CVS/*".toCharArray(), "org/apache/CVS/Entries".toCharArray(), true)); + assertTrue("Path pattern matching failure-2", + checkPathMatch("org/apache/**/CVS/*".toCharArray(), "org/apache/jakarta/tools/ant/CVS/Entries".toCharArray(), true)); + assertTrue("Path pattern matching failure-3", + !checkPathMatch("org/apache/**/CVS/*".toCharArray(), "org/apache/CVS/foo/bar/Entries".toCharArray(), true)); +} + +/* + * From Ant pattern set examples + */ +public void test42() { + + assertTrue("Path pattern matching failure-1", + checkPathMatch("**/test/**".toCharArray(), "org/apache/test/CVS/Entries".toCharArray(), true)); + assertTrue("Path pattern matching failure-2", + checkPathMatch("**/test/**".toCharArray(), "test".toCharArray(), true)); + assertTrue("Path pattern matching failure-3", + checkPathMatch("**/test/**".toCharArray(), "a/test".toCharArray(), true)); + assertTrue("Path pattern matching failure-4", + checkPathMatch("**/test/**".toCharArray(), "test/a.java".toCharArray(), true)); + assertTrue("Path pattern matching failure-5", + !checkPathMatch("**/test/**".toCharArray(), "org/apache/test.java".toCharArray(), true)); +} +/* + * Corner cases + */ +public void test43() { + + assertTrue("Path pattern matching failure-1", + checkPathMatch("/test/".toCharArray(), "/test/CVS/Entries".toCharArray(), true)); + assertTrue("Path pattern matching failure-2", + checkPathMatch("/test/**".toCharArray(), "/test/CVS/Entries".toCharArray(), true)); +} +/* + * Corner cases + */ +public void test44() { + + assertTrue("Path pattern matching failure-1", + !checkPathMatch("test".toCharArray(), "test/CVS/Entries".toCharArray(), true)); + assertTrue("Path pattern matching failure-2", + !checkPathMatch("**/test".toCharArray(), "test/CVS/Entries".toCharArray(), true)); +} +/* + * Corner cases + */ +public void test45() { + + assertTrue("Path pattern matching failure-1", + checkPathMatch("/test/test1/".toCharArray(), "/test/test1/test/test1".toCharArray(), true)); + assertTrue("Path pattern matching failure-2", + !checkPathMatch("/test/test1".toCharArray(), "/test/test1/test/test1".toCharArray(), true)); +} +public void test46() { + + assertTrue("Path pattern matching failure", + checkPathMatch("hello/**/World".toCharArray(), "hello/World".toCharArray(), true)); +} +/* + * Regression test for 28316 Missing references to constructor + */ +public void test47() { + + assertTrue("Pattern matching failure", + CharOperation.match("*x".toCharArray(), "x.X".toCharArray(), false)); +} +public void test48() { + + assertTrue("Pattern matching failure", + CharOperation.match("*a*".toCharArray(), "abcd".toCharArray(), false)); +} +public void test49() { + + assertTrue("Path pattern matching failure", + checkPathMatch("**/hello".toCharArray(), "hello/hello".toCharArray(), true)); +} +public void test50() { + + assertTrue("Path pattern matching failure", + checkPathMatch("**/hello/**".toCharArray(), "hello/hello".toCharArray(), true)); +} +public void test51() { + + assertTrue("Path pattern matching failure", + checkPathMatch("**/hello/".toCharArray(), "hello/hello".toCharArray(), true)); +} +public void test52() { + + assertTrue("Path pattern matching failure", + checkPathMatch("hello/".toCharArray(), "hello/hello".toCharArray(), true)); +} +public void test53() { + + assertTrue("Path pattern matching failure", + !checkPathMatch("/".toCharArray(), "hello/hello".toCharArray(), true)); +} +public void test54() { + + assertTrue("Path pattern matching failure-1", + !checkPathMatch("x/".toCharArray(), "hello/x".toCharArray(), true)); // 29761 + + assertTrue("Path pattern matching failure-2", + checkPathMatch("**/x/".toCharArray(), "hello/x".toCharArray(), true)); + + assertTrue("Path pattern matching failure-3", + !checkPathMatch("/x/".toCharArray(), "hello/x".toCharArray(), true)); +} +public void test56() { + + assertTrue("Path pattern matching failure", + !checkPathMatch("/**".toCharArray(), "hello/hello".toCharArray(), true)); +} +public void test57() { + + assertTrue("Path pattern matching failure", + checkPathMatch("/".toCharArray(), "/hello/hello".toCharArray(), true)); +} +public void test58() { + + assertTrue("Path pattern matching failure", + checkPathMatch("/**".toCharArray(), "/hello/hello".toCharArray(), true)); +} +public void test59() { + + assertTrue("Path pattern matching failure", + !checkPathMatch("**".toCharArray(), "/hello/hello".toCharArray(), true)); +} +public void test60() { + + assertTrue("Path pattern matching failure-1", + !checkPathMatch("/P/src".toCharArray(), "/P/src/X".toCharArray(), true)); + assertTrue("Path pattern matching failure-2", + !checkPathMatch("/P/**/src".toCharArray(), "/P/src/X".toCharArray(), true)); + assertTrue("Path pattern matching failure-3", + checkPathMatch("/P/src".toCharArray(), "/P/src".toCharArray(), true)); + assertTrue("Path pattern matching failure-4", + !checkPathMatch("A.java".toCharArray(), "/P/src/A.java".toCharArray(), true)); +} +public void test61() { + + assertTrue("Path pattern matching failure-1", + checkPathMatch("/P/src/**/CVS".toCharArray(), "/P/src/CVS".toCharArray(), true)); + assertTrue("Path pattern matching failure-2", + checkPathMatch("/P/src/**/CVS/".toCharArray(), "/P/src/CVS".toCharArray(), true)); +} +public void test62() { + assertCamelCase("NPE", "NullPointerException", true/* should match */); + assertCamelCase("NPExc", "NullPointerException", true/* should match */); + assertCamelCase("NPoE", "NullPointerException", true/* should match */); + assertCamelCase("NuPExc", "NullPointerException", true/* should match */); + // Verify that there were no unexpected results + assertTrue(this.camelCaseErrors.toString(), this.camelCaseErrors.length()==0); +} +public void test63() { + assertCamelCase("NPEX", "NullPointerException", false/* should not match */); + assertCamelCase("NPex", "NullPointerException", false/* should not match */); + assertCamelCase("npe", "NullPointerException", false/* should not match */); + assertCamelCase("npe", "NPException", false/* should not match */); + assertCamelCase("NPointerE", "NullPointerException", true/* should match */); + // Verify that there were no unexpected results + assertTrue(this.camelCaseErrors.toString(), this.camelCaseErrors.length()==0); +} +public void test64() { + assertCamelCase("IAE", "IgnoreAllErrorHandler", true/* should match */); + assertCamelCase("IAE", "IAnchorElement", true/* should match */); + assertCamelCase("IAnchorEleme", "IAnchorElement", true/* should match */); + assertCamelCase("", "IAnchorElement", false/* should not match */); + assertCamelCase(null, "IAnchorElement", true/* should match */); + assertCamelCase("", "", true/* should match */); + assertCamelCase("IAnchor", null, false/* should not match */); + // Verify that there were no unexpected results + assertTrue(this.camelCaseErrors.toString(), this.camelCaseErrors.length()==0); +} +public void test65() { + assertCamelCase("iSCDCo", "invokeStringConcatenationDefaultConstructor", true/* should match */); + assertCamelCase("inVOke", "invokeStringConcatenationDefaultConstructor", false/* should not match */); + assertCamelCase("i", "invokeStringConcatenationDefaultConstructor", true/* should match */); + assertCamelCase("I", "invokeStringConcatenationDefaultConstructor", false/* should not match */); + assertCamelCase("iStringCD", "invokeStringConcatenationDefaultConstructor", true/* should match */); + assertCamelCase("NPE", "NullPointerException/java.lang", true/* should match */); + assertCamelCase("NPE", "NullPointer/lang.Exception", false/* should not match */); + assertCamelCase("NPE", "Null_Pointer$Exception", true/* should match */); + assertCamelCase("NPE", "Null1Pointer2Exception", true/* should match */); + assertCamelCase("NPE", "Null.Pointer.Exception", false/* should not match */); + assertCamelCase("NPE", "aNullPointerException", false/* should not match */); + assertCamelCase("nullP", "nullPointerException", true/* should match */); + assertCamelCase("nP", "nullPointerException", true/* should match */); + // Verify that there were no unexpected results + assertTrue(this.camelCaseErrors.toString(), this.camelCaseErrors.length()==0); +} + +/** + * Bug 130390: CamelCase algorithm cleanup and improvement + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=130390" + */ +public void test66() { + String[][] MATCHES = { + {"TZ","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"TiZ","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"TiZon","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"TZon","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"TZone","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"TimeZone","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"TimeZ","TimeZ"}, //$NON-NLS-1$//$NON-NLS-2$ + {"TZ","TimeZ"}, //$NON-NLS-1$//$NON-NLS-2$ + {"T","TimeZ"}, //$NON-NLS-1$//$NON-NLS-2$ + {"T","TimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"TZ","TZ"}, //$NON-NLS-1$//$NON-NLS-2$ + {"aT","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"aTi","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"aTiZ","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"aTZ","aTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"aT","artTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"aTi","artTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"aTiZ","artTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + {"aTZ","artTimeZone"}, //$NON-NLS-1$//$NON-NLS-2$ + }; + + for (int i = 0; i testClass() { + return ValueBasedAnnotationTests.class; + } + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_16); + } + public ValueBasedAnnotationTests(String testName){ + super(testName); + } + // Enables the tests to run individually + @Override + protected Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + if (this.complianceLevel >= ClassFileConstants.getLatestJDKLevel()) { + defaultOptions.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + } + return defaultOptions; + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog) { + runWarningTest(testFiles, expectedCompilerLog, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, Map customOptions) { + runWarningTest(testFiles, expectedCompilerLog, customOptions, null); + } + protected void runWarningTest(String[] testFiles, String expectedCompilerLog, + Map customOptions, String javacAdditionalTestOptions) { + if (!isJRE16Plus) + return; + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.expectedCompilerLog = expectedCompilerLog; + runner.customOptions = customOptions; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forReleaseWithPreview("16") : + JavacTestOptions.forReleaseWithPreview("16", javacAdditionalTestOptions); + runner.runWarningTest(); + } + protected void runConformTest(String[] testFiles) { + runConformTest(testFiles, (Map)null, null); + } + protected void runConformTest(String[] testFiles, Map customOptions, String javacAdditionalTestOptions) { + if (!isJRE16Plus) + return; + Runner runner = new Runner(); + runner.testFiles = testFiles; + runner.customOptions = customOptions; + runner.vmArguments = new String[] {"--enable-preview"}; + runner.javacTestOptions = javacAdditionalTestOptions == null ? JavacTestOptions.forReleaseWithPreview("16") : + JavacTestOptions.forReleaseWithPreview("16", javacAdditionalTestOptions); + runner.runConformTest(); + } + public void testBug571507_001() { + this.runWarningTest( + new String[] { + "X.java", + "class X {\n" + + " public static void main(String[] args){\n" + + " Integer abc= Integer.valueOf(10);\n" + + " synchronized(abc) {\n" + + " \n" + + " }" + + " }\n"+ + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " synchronized(abc) {\n" + + " ^^^\n" + + "Integer is a value-based type which is a discouraged argument for the synchronized statement\n" + + "----------\n"); + } + public void testBug571507_002() { + this.runWarningTest( + new String[] { + "X.java", + "import java.util.Optional;\n\n" + + "class X {\n" + + " public static void main(String[] args){\n" + + " String[] sentence = new String[10];\n" + + " Optional abc = Optional.ofNullable(sentence[9]); \n" + + " synchronized (abc) { // no error given here.\n" + + " }\n" + + " }\n"+ + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " synchronized (abc) { // no error given here.\n" + + " ^^^\n" + + "Optional is a value-based type which is a discouraged argument for the synchronized statement\n" + + "----------\n"); + } + public void testBug571507_003() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashSet;\n\n" + + "class X {\n" + + " public static void main(String[] args){\n" + + " String[] sentence = new String[10];\n" + + " HashSet abc = new HashSet<>(); \n" + + " synchronized (abc) { // no error given here.\n" + + " }\n" + + " }\n"+ + "}\n", + }); + } +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java new file mode 100644 index 0000000000..64a71cf253 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/VarargsTest.java @@ -0,0 +1,3649 @@ +/******************************************************************************* + * Copyright (c) 2005, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 423505 - [1.8] Implement "18.5.4 More Specific Method Inference" + *******************************************************************************/ +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; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.IMethodInfo; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class VarargsTest extends AbstractComparableTest { + + public VarargsTest(String name) { + super(name); + } + + // 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[] { "test068" }; +// TESTS_NUMBERS = new int[] { 61 }; +// TESTS_RANGE = new int[] { 11, -1 }; + } + public static Test suite() { + return buildComparableTestSuite(testClass()); + } + + public static Class testClass() { + return VarargsTest.class; + } + @Override + protected String intersection(String... types) { + if (this.complianceLevel >= ClassFileConstants.JDK1_8) + return String.join(" & ", types); + return String.join("&", types); + } + public void test001() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y y = new Y();\n" + + " y = new Y(null);\n" + + " y = new Y(1);\n" + + " y = new Y(1, 2, (byte) 3, 4);\n" + + " y = new Y(new int[] {1, 2, 3, 4 });\n" + + " \n" + + " Y.count();\n" + + " Y.count(null);\n" + + " Y.count(1);\n" + + " Y.count(1, 2, (byte) 3, 4);\n" + + " Y.count(new int[] {1, 2, 3, 4 });\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " public Y(int ... values) {\n" + + " int result = 0;\n" + + " for (int i = 0, l = values == null ? 0 : values.length; i < l; i++)\n" + + " result += values[i];\n" + + " System.out.print(result);\n" + + " System.out.print(' ');\n" + + " }\n" + + " public static void count(int ... values) {\n" + + " int result = 0;\n" + + " for (int i = 0, l = values == null ? 0 : values.length; i < l; i++)\n" + + " result += values[i];\n" + + " System.out.print(result);\n" + + " System.out.print(' ');\n" + + " }\n" + + "}\n", + }, + "<0 0 1 10 10 0 0 1 10 10 >"); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y y = new Y();\n" + + " y = new Y(null);\n" + + " y = new Y(1);\n" + + " y = new Y(1, 2, (byte) 3, 4);\n" + + " y = new Y(new int[] {1, 2, 3, 4 });\n" + + " \n" + + " Y.count();\n" + + " Y.count(null);\n" + + " Y.count(1);\n" + + " Y.count(1, 2, (byte) 3, 4);\n" + + " Y.count(new int[] {1, 2, 3, 4 });\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n", + }, + "<0 0 1 10 10 0 0 1 10 10 >", + null, + false, + null); + } + + public void test002() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y y = new Y();\n" + + " y = new Y(null);\n" + + " y = new Y(1);\n" + + " y = new Y(1, 2, (byte) 3, 4);\n" + + " y = new Y(new int[] {1, 2, 3, 4 });\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y extends Z {\n" + + " public Y(int ... values) { super(values); }\n" + + "}\n" + + "class Z {\n" + + " public Z(int ... values) {\n" + + " int result = 0;\n" + + " for (int i = 0, l = values == null ? 0 : values.length; i < l; i++)\n" + + " result += values[i];\n" + + " System.out.print(result);\n" + + " System.out.print(' ');\n" + + " }\n" + + "}\n", + }, + "<0 0 1 10 10 >"); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y y = new Y();\n" + + " y = new Y(null);\n" + + " y = new Y(1);\n" + + " y = new Y(1, 2, (byte) 3, 4);\n" + + " y = new Y(new int[] {1, 2, 3, 4 });\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n", + }, + "<0 0 1 10 10 >", + null, + false, + null); + } + + public void test003() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y.count();\n" + + " Y.count((int[]) null);\n" + + " Y.count((int[][]) null);\n" + + " Y.count(new int[] {1});\n" + + " Y.count(new int[] {1, 2}, new int[] {3, 4});\n" + + " Y.count(new int[][] {new int[] {1, 2, 3}, new int[] {4}});\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " public static int count(int[] values) {\n" + + " int result = 0;\n" + + " for (int i = 0, l = values == null ? 0 : values.length; i < l; i++)\n" + + " result += values[i];\n" + + " System.out.print(' ');\n" + + " System.out.print(result);\n" + + " return result;\n" + + " }\n" + + " public static void count(int[] ... values) {\n" + + " int result = 0;\n" + + " for (int i = 0, l = values == null ? 0 : values.length; i < l; i++)\n" + + " result += count(values[i]);\n" + + " System.out.print('=');\n" + + " System.out.print(result);\n" + + " }\n" + + "}\n", + }, + "<=0 0=0 1 3 7=10 6 4=10>"); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y.count();\n" + + " Y.count((int[]) null);\n" + + " Y.count((int[][]) null);\n" + + " Y.count(new int[] {1});\n" + + " Y.count(new int[] {1, 2}, new int[] {3, 4});\n" + + " Y.count(new int[][] {new int[] {1, 2, 3}, new int[] {4}});\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n" + }, + "<=0 0=0 1 3 7=10 6 4=10>", + null, + false, + null); + } + + public void test004() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y.count(0);\n" + + " Y.count(-1, (int[]) null);\n" + + " Y.count(-2, (int[][]) null);\n" + + " Y.count(1);\n" + + " Y.count(2, new int[] {1});\n" + + " Y.count(3, new int[] {1}, new int[] {2, 3}, new int[] {4});\n" + + " Y.count((byte) 4, new int[][] {new int[] {1}, new int[] {2, 3}, new int[] {4}});\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " public static int count(int j, int[] values) {\n" + + " int result = j;\n" + + " System.out.print(' ');\n" + + " System.out.print('[');\n" + + " for (int i = 0, l = values == null ? 0 : values.length; i < l; i++)\n" + + " result += values[i];\n" + + " System.out.print(result);\n" + + " System.out.print(']');\n" + + " return result;\n" + + " }\n" + + " public static void count(int j, int[] ... values) {\n" + + " int result = j;\n" + + " System.out.print(' ');\n" + + " System.out.print(result);\n" + + " System.out.print(':');\n" + + " for (int i = 0, l = values == null ? 0 : values.length; i < l; i++)\n" + + " result += count(j, values[i]);\n" + + " System.out.print('=');\n" + + " System.out.print(result);\n" + + " }\n" + + "}\n", + }, + "< 0:=0 [-1] -2:=-2 1:=1 [3] 3: [4] [8] [7]=22 4: [5] [9] [8]=26>"); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y.count(0);\n" + + " Y.count(-1, (int[]) null);\n" + + " Y.count(-2, (int[][]) null);\n" + + " Y.count(1);\n" + + " Y.count(2, new int[] {1});\n" + + " Y.count(3, new int[] {1}, new int[] {2, 3}, new int[] {4});\n" + + " Y.count((byte) 4, new int[][] {new int[] {1}, new int[] {2, 3}, new int[] {4}});\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n" + }, + "< 0:=0 [-1] -2:=-2 1:=1 [3] 3: [4] [8] [7]=22 4: [5] [9] [8]=26>", + null, + false, + null); + } + + public void test005() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y.print();\n" + + " Y.print(Integer.valueOf(1));\n" + + " Y.print(Integer.valueOf(1), Byte.valueOf((byte) 3), Integer.valueOf(7));\n" + + " Y.print(new Integer[] {Integer.valueOf(11) });\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n", + "Y.java", + "public class Y {\n" + + " public static void print(Number ... values) {\n" + + " for (int i = 0, l = values.length; i < l; i++) {\n" + + " System.out.print(' ');\n" + + " System.out.print(values[i]);\n" + + " }\n" + + " System.out.print(',');\n" + + " }\n" + + "}\n", + }, + "<, 1, 1 3 7, 11,>"); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y.print();\n" + + " Y.print(Integer.valueOf(1));\n" + + " Y.print(Integer.valueOf(1), Byte.valueOf((byte) 3), Integer.valueOf(7));\n" + + " Y.print(new Integer[] {Integer.valueOf(11) });\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n", + }, + "<, 1, 1 3 7, 11,>", + null, + false, + null); + } + + public void test006() { // 70056 + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " String[] T_NAMES = new String[] {\"foo\"};\n" + + " String error = \"error\";\n" + + " Y.format(\"E_UNSUPPORTED_CONV\", Integer.valueOf(0));\n" + + " Y.format(\"E_SAVE\", T_NAMES[0], error);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static String format(String key) { return null; }\n" + + " public static String format(String key, Object ... args) { return null; }\n" + + "}\n", + }, + ""); + } + + public void test007() { // array dimension test compatibility with Object + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.byte2(null);\n" + // warning: inexact argument type for last parameter + " Y.byte2((byte) 1);\n" + // error + " Y.byte2(new byte[] {});\n" + + " Y.byte2(new byte[][] {});\n" + + " Y.byte2(new byte[][][] {});\n" + // error + "\n" + + " Y.object(null);\n" + // warning + " Y.object((byte) 1);\n" + + " Y.object(new byte[] {});\n" + + " Y.object(new byte[][] {});\n" + // warning + " Y.object(new byte[][][] {});\n" + // warning + "\n" + + " Y.object(new String());\n" + + " Y.object(new String[] {});\n" + // warning + " Y.object(new String[][] {});\n" + // warning + "\n" + + " Y.object2(null);\n" + // warning + " Y.object2((byte) 1);\n" + // error + " Y.object2(new byte[] {});\n" + // error + " Y.object2(new byte[][] {});\n" + + " Y.object2(new byte[][][] {});\n" + // warning + "\n" + + " Y.object2(new String());\n" + // error + " Y.object2(new String[] {});\n" + + " Y.object2(new String[][] {});\n" + // warning + "\n" + + " Y.string(null);\n" + // warning + " Y.string(new String());\n" + + " Y.string(new String[] {});\n" + + " Y.string(new String[][] {});\n" + // error + "\n" + + " Y.string(new Object());\n" + // error + " Y.string(new Object[] {});\n" + // error + " Y.string(new Object[][] {});\n" + // error + " }\n" + + "}\n" + + "class Y {\n" + + " public static void byte2(byte[] ... values) {}\n" + + " public static void object(Object ... values) {}\n" + + " public static void object2(Object[] ... values) {}\n" + + " public static void string(String ... values) {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " Y.byte2(null);\n" + + " ^^^^^^^^^^^^^\n" + + "Type null of the last argument to method byte2(byte[]...) doesn't exactly match the vararg parameter type. Cast to byte[][] to confirm the non-varargs invocation, or pass individual arguments of type byte[] for a varargs invocation.\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Y.byte2((byte) 1);\n" + + " ^^^^^\n" + + "The method byte2(byte[]...) in the type Y is not applicable for the arguments (byte)\n" + + "----------\n" + + "3. ERROR in X.java (at line 7)\n" + + " Y.byte2(new byte[][][] {});\n" + + " ^^^^^\n" + + "The method byte2(byte[]...) in the type Y is not applicable for the arguments (byte[][][])\n" + + "----------\n" + + "4. WARNING in X.java (at line 9)\n" + + " Y.object(null);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type null of the last argument to method object(Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "5. WARNING in X.java (at line 12)\n" + + " Y.object(new byte[][] {});\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type byte[][] of the last argument to method object(Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "6. WARNING in X.java (at line 13)\n" + + " Y.object(new byte[][][] {});\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type byte[][][] of the last argument to method object(Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "7. WARNING in X.java (at line 16)\n" + + " Y.object(new String[] {});\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type String[] of the last argument to method object(Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "8. WARNING in X.java (at line 17)\n" + + " Y.object(new String[][] {});\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type String[][] of the last argument to method object(Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "9. WARNING in X.java (at line 19)\n" + + " Y.object2(null);\n" + + " ^^^^^^^^^^^^^^^\n" + + "Type null of the last argument to method object2(Object[]...) doesn't exactly match the vararg parameter type. Cast to Object[][] to confirm the non-varargs invocation, or pass individual arguments of type Object[] for a varargs invocation.\n" + + "----------\n" + + "10. ERROR in X.java (at line 20)\n" + + " Y.object2((byte) 1);\n" + + " ^^^^^^^\n" + + "The method object2(Object[]...) in the type Y is not applicable for the arguments (byte)\n" + + "----------\n" + + "11. ERROR in X.java (at line 21)\n" + + " Y.object2(new byte[] {});\n" + + " ^^^^^^^\n" + + "The method object2(Object[]...) in the type Y is not applicable for the arguments (byte[])\n" + + "----------\n" + + "12. WARNING in X.java (at line 23)\n" + + " Y.object2(new byte[][][] {});\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type byte[][][] of the last argument to method object2(Object[]...) doesn't exactly match the vararg parameter type. Cast to Object[][] to confirm the non-varargs invocation, or pass individual arguments of type Object[] for a varargs invocation.\n" + + "----------\n" + + "13. ERROR in X.java (at line 25)\n" + + " Y.object2(new String());\n" + + " ^^^^^^^\n" + + "The method object2(Object[]...) in the type Y is not applicable for the arguments (String)\n" + + "----------\n" + + "14. WARNING in X.java (at line 27)\n" + + " Y.object2(new String[][] {});\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type String[][] of the last argument to method object2(Object[]...) doesn't exactly match the vararg parameter type. Cast to Object[][] to confirm the non-varargs invocation, or pass individual arguments of type Object[] for a varargs invocation.\n" + + "----------\n" + + "15. WARNING in X.java (at line 29)\n" + + " Y.string(null);\n" + + " ^^^^^^^^^^^^^^\n" + + "Type null of the last argument to method string(String...) doesn't exactly match the vararg parameter type. Cast to String[] to confirm the non-varargs invocation, or pass individual arguments of type String for a varargs invocation.\n" + + "----------\n" + + "16. ERROR in X.java (at line 32)\n" + + " Y.string(new String[][] {});\n" + + " ^^^^^^\n" + + "The method string(String...) in the type Y is not applicable for the arguments (String[][])\n" + + "----------\n" + + "17. ERROR in X.java (at line 34)\n" + + " Y.string(new Object());\n" + + " ^^^^^^\n" + + "The method string(String...) in the type Y is not applicable for the arguments (Object)\n" + + "----------\n" + + "18. ERROR in X.java (at line 35)\n" + + " Y.string(new Object[] {});\n" + + " ^^^^^^\n" + + "The method string(String...) in the type Y is not applicable for the arguments (Object[])\n" + + "----------\n" + + "19. ERROR in X.java (at line 36)\n" + + " Y.string(new Object[][] {});\n" + + " ^^^^^^\n" + + "The method string(String...) in the type Y is not applicable for the arguments (Object[][])\n" + + "----------\n"); + } + + public void test008() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y y = new Y(null);\n" + + " y = new Y(true, null);\n" + // null warning + " y = new Y('i', null);\n" + // null warning + " }\n" + + "}\n" + + "class Y {\n" + + " public Y(int ... values) {}\n" + + " public Y(boolean b, Object ... values) {}\n" + + " public Y(char c, int[] ... values) {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " y = new Y(true, null);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type null of the last argument to constructor Y(boolean, Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " y = new Y(\'i\', null);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type null of the last argument to constructor Y(char, int[]...) doesn't exactly match the vararg parameter type. Cast to int[][] to confirm the non-varargs invocation, or pass individual arguments of type int[] for a varargs invocation.\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y y = new Y(null);\n" + + " y = new Y(true, null);\n" + // null warning + " y = new Y('i', null);\n" + // null warning + " }\n" + + "}\n" + + "class Y extends Z {\n" + + " public Y(int ... values) { super(values); }\n" + + " public Y(boolean b, Object ... values) { super(b, values); }\n" + + " public Y(char c, int[] ... values) {}\n" + + "}\n" + + "class Z {\n" + + " public Z(int ... values) {}\n" + + " public Z(boolean b, Object ... values) {}\n" + + " public Z(char c, int[] ... values) {}\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " y = new Y(true, null);\n" + + " ^^^^^^^^^^^^^^^^^\n" + + "Type null of the last argument to constructor Y(boolean, Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "2. WARNING in X.java (at line 5)\n" + + " y = new Y(\'i\', null);\n" + + " ^^^^^^^^^^^^^^^^\n" + + "Type null of the last argument to constructor Y(char, int[]...) doesn't exactly match the vararg parameter type. Cast to int[][] to confirm the non-varargs invocation, or pass individual arguments of type int[] for a varargs invocation.\n" + + "----------\n"); + } + + public void test009() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y.count(null);\n" + + " Y.count(1);\n" + + " Y.count(1, 2);\n" + + "\n" + + " Z.count(1L, 1);\n" + // only choice is Z.count(long, int) + " Z.count(1, 1);\n" + // chooses Z.count(long, long) over Z.count(int,int...) + " Z.count(1, null);\n" + // only choice is Z.count(int,int...) + " Z.count2(1, null);\n" + // better choice is Z.count(int,int[]) + " Z.count2(1L, null);\n" + // better choice is Z.count(long,int...) + " System.out.print('>');\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static void count(int values) { System.out.print('1'); }\n" + + " public static void count(int ... values) { System.out.print('2'); }\n" + + "}\n" + + "class Z {\n" + + " public static void count(long l, long values) { System.out.print('3'); }\n" + + " public static void count(int i, int ... values) { System.out.print('4'); }\n" + + " public static void count2(int i, int values) { System.out.print('5'); }\n" + + " public static void count2(long l, int ... values) { System.out.print('6'); }\n" + + "}\n", + }, + "<21233466>"); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y.test((Object[]) null);\n" + // cast to avoid null warning + " Y.test(null, null);\n" + + " Y.test(null, null, null);\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static void test(Object o, Object o2) { System.out.print('1'); }\n" + + " public static void test(Object ... values) { System.out.print('2'); }\n" + + "}\n", + }, + "<212>"); + } + + public void test010() { + // according to spec this should find count(Object) since it should consider count(Object...) as count(Object[]) until all fixed arity methods are ruled out + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y.count((Object) Integer.valueOf(1));\n" + + " Y.count(Integer.valueOf(1));\n" + + "\n" + + " Y.count((Object) null);\n" + + " Y.count((Object[]) null);\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static void count(Object values) { System.out.print('1'); }\n" + + " public static void count(Object ... values) { System.out.print('2'); }\n" + + "}\n", + }, + "<1112>"); + // according to spec this should find count(Object[]) since it should consider count(Object[]...) as count(Object[][]) until all fixed arity methods are ruled out + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " System.out.print('<');\n" + + " Y.count(new Object[] {Integer.valueOf(1)});\n" + + " Y.count(new Integer[] {Integer.valueOf(1)});\n" + + "\n" + + " Y.count((Object[]) null);\n" + + " Y.count((Object[][]) null);\n" + + " System.out.print('>');\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static void count(Object[] values) { System.out.print('1'); }\n" + + " public static void count(Object[] ... values) { System.out.print('2'); }\n" + + "}\n", + }, + "<1112>"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.string(null);\n" + + " Y.string2(null);\n" + + " Y.int2(null);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static void string(String values) { System.out.print('1'); }\n" + + " public static void string(String ... values) { System.out.print('2'); }\n" + + " public static void string2(String[] values) { System.out.print('1'); }\n" + + " public static void string2(String[] ... values) { System.out.print('2'); }\n" + + " public static void int2(int[] values) { System.out.print('1'); }\n" + + " public static void int2(int[] ... values) { System.out.print('2'); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y.string(null);\n" + + " ^^^^^^\n" + + "The method string(String) is ambiguous for the type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Y.string2(null);\n" + + " ^^^^^^^\n" + + "The method string2(String[]) is ambiguous for the type Y\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Y.int2(null);\n" + + " ^^^^\n" + + "The method int2(int[]) is ambiguous for the type Y\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83379 + public void test011() { + runConformTest( + true, + new String[] { + "X.java", + "public class X { void count(int ... values) {} }\n" + + "class Y extends X { void count(int[] values) {} }\n" + + "class Z extends Y { void count(int... values) {} }\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " class Y extends X { void count(int[] values) {} }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike Y.count(int[]) and X.count(int...)\n" + + "----------\n" + + "2. WARNING in X.java (at line 2)\n" + + " class Y extends X { void count(int[] values) {} }\n" + + " ^^^^^^^^^^^^^^^^^^^\n" + + "The method count(int[]) of type Y should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n" + + "3. WARNING in X.java (at line 3)\n" + + " class Z extends Y { void count(int... values) {} }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "Varargs methods should only override or be overridden by other varargs methods unlike Z.count(int...) and Y.count(int[])\n" + + "----------\n" + + "4. WARNING in X.java (at line 3)\n" + + " class Z extends Y { void count(int... values) {} }\n" + + " ^^^^^^^^^^^^^^^^^^^^\n" + + "The method count(int...) of type Z should be tagged with @Override since it actually overrides a superclass method\n" + + "----------\n", + null, + null, + JavacTestOptions.EclipseHasABug.EclipseBug236379); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=77084 + public void test012() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main (String ... args) {\n" + + " for (String a:args) {\n" + + " System.out.println(a);\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + } + ); + } + + public void test013() { // check behaviour of Scope.mostSpecificMethodBinding() + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.count(1, 1);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static void count(long i, int j) { System.out.print(1); }\n" + + " public static void count(int ... values) { System.out.print(2); }\n" + + "}\n", + }, + "1"); + } + + public void test014() { // check behaviour of Scope.mostSpecificMethodBinding() + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.count(new int[0], 1);\n" + + " Y.count(new int[0], 1, 1);\n" + + " }\n" + + "}\n" + + "class Y {\n" + + " public static void count(int[] array, int ... values) { System.out.print(1); }\n" + + " public static void count(Object o, int ... values) { System.out.print(2); }\n" + + "}\n", + }, + "11" + ); + } + + public void test015() { // check behaviour of Scope.mostSpecificMethodBinding() + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.count(new int[0]);\n" + // for some reason this is not ambiguous + " }\n" + + "}\n" + + "class Y {\n" + + " public static void count(int[] array, int ... values) { System.out.print(1); }\n" + + " public static void count(int[] array, int[] ... values) { System.out.print(2); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y.count(new int[0]);\n" + + " ^^^^^\n" + + "The method count(int[], int[]) is ambiguous for the type Y\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 + public void test015_tolerate() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + try { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.count(new int[0]);\n" + // for some reason this is not ambiguous + " }\n" + + "}\n" + + "class Y {\n" + + " public static void count(int[] array, int ... values) { System.out.print(1); }\n" + + " public static void count(int[] array, int[] ... values) { System.out.print(2); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y.count(new int[0]);\n" + + " ^^^^^\n" + + "The method count(int[], int[]) is ambiguous for the type Y\n" + + "----------\n", + null, true, options); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.count(new int[0]);\n" + // for some reason this is not ambiguous + " }\n" + + "}\n" + + "class Y {\n" + + " public static void count(int[] array, int ... values) { System.out.print(1); }\n" + + " public static void count(int[] array, int[] ... values) { System.out.print(2); }\n" + + "}\n", + }, + "1", + null, true, null, options, null); + } + } finally { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); + } + } + + public void test016() { // check behaviour of Scope.mostSpecificMethodBinding() + this.runNegativeTest( // but this call is ambiguous + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.count(new int[0]);\n" + // reference to count is ambiguous, both method count(int[],int...) in Y and method count(int[],int[][]...) in Y match + " Y.count(new int[0], null);\n" + // reference to count is ambiguous, both method count(int[],int...) in Y and method count(int[],int[]...) in Y match + " }\n" + + "}\n" + + "class Y {\n" + + " public static void count(int[] array, int ... values) { System.out.print(0); }\n" + + " public static void count(int[] array, int[][] ... values) { System.out.print(1); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y.count(new int[0]);\n" + + " ^^^^^\n" + + "The method count(int[], int[]) is ambiguous for the type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Y.count(new int[0], null);\n" + + " ^^^^^\n" + + "The method count(int[], int[]) is ambiguous for the type Y\n" + + "----------\n" + ); + } + + public void test017() { // check behaviour of Scope.mostSpecificMethodBinding() + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " Y.count(new int[0], 1);\n" + // reference to count is ambiguous, both method count(int[],int...) in Y and method count(int[],int,int...) in Y match + " Y.count(new int[0], 1, 1);\n" + // reference to count is ambiguous, both method count(int[],int...) in Y and method count(int[],int,int...) in Y match + " Y.count(new int[0], 1, 1, 1);\n" + // reference to count is ambiguous, both method count(int[],int...) in Y and method count(int[],int,int...) in Y match + " }\n" + + "}\n" + + "class Y {\n" + + " public static void count(int[] array, int ... values) {}\n" + + " public static void count(int[] array, int[] ... values) {}\n" + + " public static void count(int[] array, int i, int ... values) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " Y.count(new int[0], 1);\n" + + " ^^^^^\n" + + "The method count(int[], int[]) is ambiguous for the type Y\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " Y.count(new int[0], 1, 1);\n" + + " ^^^^^\n" + + "The method count(int[], int[]) is ambiguous for the type Y\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " Y.count(new int[0], 1, 1, 1);\n" + + " ^^^^^\n" + + "The method count(int[], int[]) is ambiguous for the type Y\n" + + "----------\n" + ); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81590 + public void test018() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String[][] x = {{\"X\"}, {\"Y\"}};\n" + + " List l = Arrays.asList(x);\n" + + " System.out.println(l.size() + \" \" + l.get(0).getClass().getName());\n" + + " }\n" + + "}\n", + }, + "2 [Ljava.lang.String;"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81590 - variation + public void test019() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String[][] x = {{\"X\"}, {\"Y\"}};\n" + + " System.out.println(asList(x[0], x[1]).get(1).getClass().getName());\n" + + " }\n" + + " static List asList(U u1, U... us) {\n" + + " List result = new ArrayList();\n" + + " result.add(u1);\n" + + " result.add(us[0]);\n" + + " return result;\n" + + " }\n" + + "}\n", + }, + "java.lang.String"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81590 - variation + public void test020() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String[][] x = {{\"X\"}, {\"Y\"}};\n" + + " System.out.println(asList(x[0], x).get(1).getClass().getName());\n" + + " }\n" + + " static List asList(U u1, U... us) {\n" + + " List result = new ArrayList();\n" + + " result.add(u1);\n" + + " result.add(us[0]);\n" + + " return result;\n" + + " }\n" + + "}\n", + }, + "[Ljava.lang.String;"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81911 + public void test021() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.ArrayList;\n" + + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " String[][] arr = new String[][] { args };\n" + + " ArrayList al = new ArrayList(Arrays.asList(arr));\n" + + " }\n" + + "}\n", + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83032 + public void test022() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " String[] args;\n" + + " public X(String... args) {\n" + + " this.args = args;\n" + + " }\n" + + " public static X foo() {\n" + + " return new X(\"SU\", \"C\", \"CE\", \"SS\"){};\n" + + " }\n" + + " public String bar() {\n" + + " if (this.args != null) {\n" + + " StringBuffer buffer = new StringBuffer();\n" + + " for (String s : this.args) {\n" + + " buffer.append(s);\n" + + " }\n" + + " return String.valueOf(buffer);\n" + + " }\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.print(foo().bar());\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83536 + public void test023() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main (String[] args) {\n" + + " new X().test (new byte[5]);\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + " private void test (Object... params) {\n" + + " }\n" + + "}", + }, + "SUCCESS"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87042 + public void test024() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static boolean foo(Object... args) {\n" + + " return args == null;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(null, null));\n" + + " }\n" + + "}", + }, + "false"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87042 + public void test025() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " static boolean foo(Object... args) {\n" + + " return args == null;\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(null));\n" + + " }\n" + + "}", + }, + "true"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87318 + public void test026() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " static void foo(int[] intarray) {\n" + + " List l = Arrays.asList(intarray);\n" + + " System.out.print(l.get(0).length);\n" + + " }\n" + + " static void foo(String[] strarray) {\n" + + " List l = Arrays.asList(strarray);\n" + + " System.out.print(l);\n" + + " } \n" + + " public static void main(String[] args) {\n" + + " foo(new int[]{0, 1});\n" + + " foo(new String[]{\"a\",\"b\"});\n" + + " System.out.println(\"done\");\n" + + " }\n" + + "}\n", + }, + "2[a, b]done"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87900 + public void test027() { // ensure AccVarargs does not collide + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " transient private X() {}\n" + + " void test() { X x = new X(); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\r\n" + + " transient private X() {}\r\n" + + " ^^^\n" + + "Illegal modifier for the constructor in type X; only public, protected & private are permitted\n" + + "----------\n" + ); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " transient private X(Object... o) {}\n" + + " void test() { X x = new X(1, 2); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " transient private X(Object... o) {}\n" + + " ^^^^^^^^^^^^^^\n" + + "Illegal modifier for the constructor in type X; only public, protected & private are permitted\n" + + "----------\n" + ); + } + // check no offending unnecessary varargs cast gets diagnosed + public void test028() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.reflect.Method;\n" + + "\n" + + "public class X {\n" + + " void test(Method method){ \n" + + " try {\n" + + " method.invoke(this);\n" + + " method.invoke(this, new Class[0]);\n" + + " method.invoke(this, (Object[])new Class[0]);\n" + + " } catch (Exception e) {\n" + + " } \n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 7)\n" + + " method.invoke(this, new Class[0]);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type Class[] of the last argument to method invoke(Object, Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "2. ERROR in X.java (at line 12)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=91467 + public void test029() { + this.runNegativeTest( + new String[] { + "X.java", + "/**\n" + + " * Whatever you do, eclipse doesn\'t like it.\n" + + " */\n" + + "public class X {\n" + + "\n" + + " /**\n" + + " * Passing a String vararg to a method needing an Object array makes eclipse\n" + + " * either ask for a cast or complain that it is unnecessary. You cannot do\n" + + " * it right.\n" + + " * \n" + + " * @param s\n" + + " */\n" + + " public static void q(String... s) {\n" + + " // OK reports: Varargs argument String[] should be cast to Object[] when passed to the method printf(String, Object...) from type PrintStream\n" + + " System.out.printf(\"\", s);\n" + + " // WRONG reports: Unnecessary cast from String[] to Object[]\n" + + " System.out.printf(\"\", (Object[]) s); \n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 15)\n" + + " System.out.printf(\"\", s);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type String[] of the last argument to method printf(String, Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "2. ERROR in X.java (at line 19)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=99260 + public void test030() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " audit(\"osvaldo\", \"localhost\", \"logged\", \"X\", Integer.valueOf(0));\n" + + " audit(\"osvaldo\", \"localhost\", \"logged\", \"X\", \"Y\");\n" + + " audit(\"osvaldo\", \"localhost\", \"logged\", new Float(0), new java.awt.Point(0, 0));\n" + + " }\n" + + " public static void audit(String login,\n" + + " String address, String event, A... args) {\n" + + " for (A a : args) {\n" + + " System.out.println(a.getClass());\n" + + " }\n" + + " }\n" + + "}", + }, + "class java.lang.String\n" + + "class java.lang.Integer\n" + + "class java.lang.String\n" + + "class java.lang.String\n" + + "class java.lang.Float\n" + + "class java.awt.Point"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=102181 + public void test031() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " public static void main(String[] args) {\n" + + " Test t = new Tester();\n" + + " t.method(\"SUCCESS\");\n" + + " }\n" + + "\n" + + " static abstract class Test {\n" + + " abstract void method(A... args);\n" + + " }\n" + + "\n" + + " static class Tester extends Test {\n" + + "\n" + + " @Override void method(String... args) {\n" + + " call(args);\n" + + " }\n" + + "\n" + + " void call(String[] args) {\n" + + " for (String str : args)\n" + + " System.out.println(str);\n" + + " }\n" + + " }\n" + + "}\n", + }, + "SUCCESS"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=102278 + public void test032() { + this.runConformTest( + new String[] { + "Functor.java", + "public class Functor {\n" + + " public void func(T... args) {\n" + + " // do noting;\n" + + " }\n" + + " \n" + + " public static void main(String... args) {\n" + + " Functor functor = new Functor() {\n" + + " public void func(String... args) {\n" + + " System.out.println(args.length);\n" + + " }\n" + + " };\n" + + " functor.func(\"Hello!\");\n" + + " }\n" + + "}\n", + }, + "1"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=102631 + public void test033() { + this.runNegativeTest( + false /* skipJavac */, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + JavacTestOptions.Excuse.JavacCompilesIncorrectSource : null, + new String[] { + "X.java", + "public class X {\n" + + " void a(boolean b, Object... o) {System.out.print(1);}\n" + + " void a(Object... o) {System.out.print(2);}\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.a(true);\n" + + " x.a(true, \"foobar\");\n" + + " x.a(\"foo\", \"bar\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x.a(true);\n" + + " ^\n" + + "The method a(boolean, Object[]) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " x.a(true, \"foobar\");\n" + + " ^\n" + + "The method a(boolean, Object[]) is ambiguous for the type X\n" + + "----------\n"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void b(boolean b, Object... o) {}\n" + + " void b(Boolean... o) {}\n" + + " void c(boolean b, boolean b2, Object... o) {}\n" + + " void c(Boolean b, Object... o) {}\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.b(true);\n" + + " x.b(true, false);\n" + + " x.c(true, true, true);\n" + + " x.c(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\r\n" + + " x.b(true);\r\n" + + " ^\n" + + "The method b(boolean, Object[]) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\r\n" + + " x.b(true, false);\r\n" + + " ^\n" + + "The method b(boolean, Object[]) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\r\n" + + " x.c(true, true, true);\r\n" + + " ^\n" + + "The method c(boolean, boolean, Object[]) is ambiguous for the type X\n" + + "----------\n" + + "4. ERROR in X.java (at line 11)\r\n" + + " x.c(Boolean.TRUE, Boolean.TRUE, Boolean.TRUE);\r\n" + + " ^\n" + + "The method c(boolean, boolean, Object[]) is ambiguous for the type X\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 + public void test033_tolerate() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + try { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + false /* skipJavac */, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + JavacTestOptions.Excuse.JavacCompilesIncorrectSource : null, + new String[] { + "X.java", + "public class X {\n" + + " void a(boolean b, Object... o) {System.out.print(1);}\n" + + " void a(Object... o) {System.out.print(2);}\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.a(true);\n" + + " x.a(true, \"foobar\");\n" + + " x.a(\"foo\", \"bar\");\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " x.a(true);\n" + + " ^\n" + + "The method a(boolean, Object[]) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " x.a(true, \"foobar\");\n" + + " ^\n" + + "The method a(boolean, Object[]) is ambiguous for the type X\n" + + "----------\n", + null, true, options); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void a(boolean b, Object... o) {System.out.print(1);}\n" + + " void a(Object... o) {System.out.print(2);}\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.a(true);\n" + + " x.a(true, \"foobar\");\n" + + " x.a(\"foo\", \"bar\");\n" + + " }\n" + + "}\n", + }, + "112", + null, true, null, options, null); + } + } finally { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); + } + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=106106 + public void test034() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*; \n" + + "\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " double[][] d = { { 1 } , { 2 } }; \n" + + " List l = Arrays.asList(d); // List asList(T... a)\n" + + " System.out.println(\"List size: \" + l.size());\n" + + " }\n" + + "}\n", + }, + "List size: 2"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=108095 + public void test035() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(T ... values) {\n" + + " System.out.print(values.getClass());\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " X.foo(\"monkey\", \"cat\");\n" + + " X.foo(new String[] { \"monkey\", \"cat\" });\n" + + " }\n" + + "}", + }, + "class [Ljava.lang.String;class [Ljava.lang.String;"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=110563 + public void test036() { + this.runConformTest( + new String[] { + "X.java", + "import java.util.*;\n" + + "public class X {\n" + + " public void testBreak() {\n" + + " Collection classes = new ArrayList();\n" + + " classes.containsAll(Arrays.asList(String.class, Integer.class, Long.class));\n" + + " }\n" + + "}\n", + }, + ""); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=110783 + public void test037() { + this.runConformTest( + new String[] { + "V.java", + "public class V {\n" + + " public static void main(String[] s) {\n" + + " V v = new V();\n" + + " v.foo(\"\", v, null, \"\");\n" + + " v.foo(\"\", v, null, \"\", 1);\n" + + " v.foo2(\"\");\n" + + " v.foo2(\"\", null);\n" + + " v.foo2(\"\", null, null);\n" + + " v.foo3(\"\", v, null, \"\", null);\n" + + " }\n" + + " void foo(String s, V v, Object... obs) {System.out.print(1);}\n" + + " void foo(String s, V v, String r, Object o, Object... obs) {System.out.print(2);}\n" + + " void foo2(Object... a) {System.out.print(1);}\n" + + " void foo2(String s, Object... a) {System.out.print(2);}\n" + + " void foo2(String s, Object o, Object... a) {System.out.print(3);}\n" + + " void foo3(String s, V v, String... obs) {System.out.print(1);}\n" + + " void foo3(String s, V v, String r, Object o, Object... obs) {System.out.print(2);}\n" + + "}\n", + }, + "222232"); + this.runNegativeTest( + new String[] { + "V.java", + "public class V {\n" + + " public static void main(String[] s) {\n" + + " V v = new V();\n" + + " v.foo2(null, \"\");\n" + + " v.foo2(null, \"\", \"\");\n" + + " v.foo3(\"\", v, null, \"\");\n" + + " }\n" + + " void foo2(String s, Object... a) {System.out.print(2);}\n" + + " void foo2(String s, Object o, Object... a) {System.out.print(3);}\n" + + " void foo3(String s, V v, String... obs) {System.out.print(1);}\n" + + " void foo3(String s, V v, String r, Object o, Object... obs) {System.out.print(2);}\n" + + "}\n", + }, + (this.complianceLevel < ClassFileConstants.JDK1_8 ? + "----------\n" + + "1. ERROR in V.java (at line 4)\r\n" + + " v.foo2(null, \"\");\r\n" + + " ^^^^\n" + + "The method foo2(String, Object[]) is ambiguous for the type V\n" + + "----------\n" + + "2. ERROR in V.java (at line 5)\r\n" + + " v.foo2(null, \"\", \"\");\r\n" + + " ^^^^\n" + + "The method foo2(String, Object[]) is ambiguous for the type V\n" + + "----------\n" + + "3. ERROR in V.java (at line 6)\r\n" + + " v.foo3(\"\", v, null, \"\");\r\n" + + " ^^^^\n" + + "The method foo3(String, V, String[]) is ambiguous for the type V\n" + + "----------\n" + : // one fewer ambiguity in 1.8: + "----------\n" + + "1. ERROR in V.java (at line 4)\n" + + " v.foo2(null, \"\");\n" + + " ^^^^\n" + + "The method foo2(String, Object[]) is ambiguous for the type V\n" + + "----------\n" + + "2. ERROR in V.java (at line 5)\n" + + " v.foo2(null, \"\", \"\");\n" + + " ^^^^\n" + + "The method foo2(String, Object[]) is ambiguous for the type V\n" + + "----------\n") + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=105801 + public void test038() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " static void varargs(Serializable... items) {\n" + + " System.out.println(Arrays.deepToString(items) + \" (argument wrapped)\");\n" + + " }\n" + + " @SuppressWarnings({\"boxing\"})\n" + + " public static void main(String[] args) {\n" + + " varargs(new Object[] {1, 2}); //warns \"Varargs argument Object[] \n" + + " //should be cast to Serializable[] ..\", but proposed cast to\n" + + " //Serializable[] fails at runtime (javac does not warn here)\n" + + " varargs((Serializable[])new Object[] {1, 2}); //warns \"Varargs argument Object[] \n" + + " //should be cast to Serializable[] ..\", but proposed cast to\n" + + " //Serializable[] fails at runtime (javac does not warn here)\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + // check no varargs warning + "----------\n" + + "1. WARNING in X.java (at line 13)\n" + + " varargs((Serializable[])new Object[] {1, 2}); //warns \"Varargs argument Object[] \n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object[] to Serializable[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=105801 - variation + public void test039() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " static void varargs(Serializable... items) {\n" + + " System.out.print(Arrays.deepToString(items) + \" (argument wrapped)\");\n" + + " }\n" + + " @SuppressWarnings({\"boxing\"})\n" + + " public static void main(String[] args) {\n" + + " try {\n" + + " varargs(new Object[] {1, 2}); //warns \"Varargs argument Object[] \n" + + " //should be cast to Serializable[] ..\", but proposed cast to\n" + + " //Serializable[] fails at runtime (javac does not warn here)\n" + + " varargs((Serializable[])new Object[] {1, 2}); //warns \"Varargs argument Object[] \n" + + " //should be cast to Serializable[] ..\", but proposed cast to\n" + + " //Serializable[] fails at runtime (javac does not warn here)\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "[[1, 2]] (argument wrapped)SUCCESS"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=105801 - variation + public void test040() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " static void array(Serializable... items) {\n" + + " System.out.print(Arrays.deepToString(items));\n" + + " }\n" + + " @SuppressWarnings({\"boxing\"})\n" + + " public static void main(String[] args) {\n" + + " array(new Serializable[] {3, 4});\n" + + " array(new Integer[] {5, 6}); //warns (as javac does)\n" + + " array(null); //warns (as javac does)\n" + + " }\n" + + "}\n", + }, + "[3, 4][5, 6]null"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=105801 - variation + public void test041() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " static void array(Serializable... items) {\n" + + " System.out.print(Arrays.deepToString(items));\n" + + " }\n" + + " @SuppressWarnings({\"boxing\"})\n" + + " public static void main(String[] args) {\n" + + " array(new Serializable[] {3, 4});\n" + + " array(new Integer[] {5, 6}); //warns (as javac does)\n" + + " array(null); //warns (as javac does)\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 11)\n" + + " array(new Integer[] {5, 6}); //warns (as javac does)\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type Integer[] of the last argument to method array(Serializable...) doesn't exactly match the vararg parameter type. Cast to Serializable[] to confirm the non-varargs invocation, or pass individual arguments of type Serializable for a varargs invocation.\n" + + "----------\n" + + "2. WARNING in X.java (at line 12)\n" + + " array(null); //warns (as javac does)\n" + + " ^^^^^^^^^^^\n" + + "Type null of the last argument to method array(Serializable...) doesn't exactly match the vararg parameter type. Cast to Serializable[] to confirm the non-varargs invocation, or pass individual arguments of type Serializable for a varargs invocation.\n" + + "----------\n" + + "3. 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=105801 - variation + public void test042() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " static void varargs(Serializable... items) {\n" + + " System.out.print(Arrays.deepToString(items) + \" (argument wrapped)\");\n" + + " }\n" + + " @SuppressWarnings({\"boxing\"})\n" + + " public static void main(String[] args) {\n" + + " varargs((Serializable) new Object[] {1, 2});\n" + + " varargs((Serializable) new Serializable[] {3, 4}); //warns about\n" + + " //unnecessary cast, although cast is necessary (causes varargs call)\n" + + " varargs((Serializable) new Integer[] {5, 6});\n" + + " varargs((Serializable) null);\n" + + " }\n" + + "}\n", + }, + "[[1, 2]] (argument wrapped)[[3, 4]] (argument wrapped)[[5, 6]] (argument wrapped)[null] (argument wrapped)"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=105801 - variation + public void test043() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " static void varargs(Serializable... items) {\n" + + " System.out.print(Arrays.deepToString(items) + \" (argument wrapped)\");\n" + + " }\n" + + " @SuppressWarnings({\"boxing\"})\n" + + " public static void main(String[] args) {\n" + + " varargs((Serializable) new Object[] {1, 2});\n" + + " varargs((Serializable) new Serializable[] {3, 4}); //warns about\n" + + " //unnecessary cast, although cast is necessary (causes varargs call)\n" + + " varargs((Serializable) new Integer[] {5, 6});\n" + + " varargs((Serializable) null);\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " varargs((Serializable) new Object[] {1, 2});\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object[] to Serializable\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=105801 - variation + public void test044() { + this.runConformTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " static void array(Serializable... items) {\n" + + " System.out.print(Arrays.deepToString(items));\n" + + " }\n" + + " @SuppressWarnings({\"boxing\"})\n" + + " public static void main(String[] args) {\n" + + " array((Serializable[]) new Serializable[] {3, 4}); //warns about unnecessary cast\n" + + " array((Serializable[]) new Integer[] {5, 6});\n" + + " array((Serializable[]) null);\n" + + " try {\n" + + " array((Serializable[]) new Object[] {1, 2}); // CCE at run time\n" + + " } catch(ClassCastException e) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " }\n" + + "}\n", + }, + "[3, 4][5, 6]nullSUCCESS"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=105801 - variation + public void test045() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.io.Serializable;\n" + + "import java.util.Arrays;\n" + + "\n" + + "public class X {\n" + + " static void array(Serializable... items) {\n" + + " System.out.print(Arrays.deepToString(items));\n" + + " }\n" + + " @SuppressWarnings({\"boxing\"})\n" + + " public static void main(String[] args) {\n" + + " array((Serializable[]) new Serializable[] {3, 4}); //warns about unnecessary cast\n" + + " array((Serializable[]) new Integer[] {5, 6});\n" + + " array((Serializable[]) null);\n" + + " array((Serializable[]) new Object[] {1, 2}); // CCE at run time\n" + + " Zork z;\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " array((Serializable[]) new Serializable[] {3, 4}); //warns about unnecessary cast\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Serializable[] to Serializable[]\n" + + "----------\n" + + "2. WARNING in X.java (at line 13)\n" + + " array((Serializable[]) new Object[] {1, 2}); // CCE at run time\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Object[] to Serializable[]\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=133918 + public void test046() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Throwable... exceptions) {\n" + + " }\n" + + " void bar(Exception[] exceptions) {\n" + + " foo((Throwable[])exceptions);\n" + + " }\n" + + " Zork z;\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " foo((Throwable[])exceptions);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Exception[] to Throwable[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=140168 + public void test047() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Object id, Object value, String... groups) {}\n" + + " void foo(Y y, String... groups) {System.out.println(true);}\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new Y(), \"a\", \"b\");\n" + + " }\n" + + "}\n" + + "class Y {}", + }, + "true"); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(Y y, Object value, String... groups) {}\n" + + " void foo(Object id, String... groups) {}\n" + + " public static void main(String[] args) {\n" + + " new X().foo(new Y(), \"a\", \"b\");\n" + + " }\n" + + "}\n" + + "class Y {}", + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\r\n" + + " new X().foo(new Y(), \"a\", \"b\");\r\n" + + " ^^^\n" + + "The method foo(Y, Object, String[]) is ambiguous for the type X\n" + + "----------\n" + //reference to foo is ambiguous, both method foo(Y,java.lang.Object,java.lang.String...) in X and method foo(java.lang.Object,java.lang.String...) in X match + ); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=139931 + public void test048() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Y [] foo() {\n" + + " return null;\n" + + " }\n" + + " void bar(Y... y) {\n" + + " }\n" + + " void fred() {\n" + + " bar(foo());\n" + + " bar((Y[])foo());\n" + + " Zork z;\n" + + " }\n" + + "}\n" + + "class Y {\n" + + "}\n", + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " void bar(Y... y) {\n" + + " ^\n" + + "Y is a raw type. References to generic type Y should be parameterized\n" + + "----------\n" + + "2. WARNING in X.java (at line 9)\n" + + " bar((Y[])foo());\n" + + " ^^^^^^^^^^\n" + + "Unnecessary cast from Y[] to Y[]\n" + + "----------\n" + + "3. ERROR in X.java (at line 10)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=141704 + public void test049() { + this.runConformTest( + new String[] { + "Y.java", + "public class Y extends X {\n" + + " public static void main(String[] args) {\n" + + " Y y = new Y();\n" + + " y.a(null, \"\");\n" + + " y.a(null);\n" + + " y.a(y, \"\");\n" + + " y.a(y);\n" + + " y.a(y, \"\", y, y);\n" + + " y.a(y, y, y);\n" + + " }\n" + + " @Override public void a(Object anObject, String aString, Object... args) { super.a(anObject, aString, this, args); }\n" + + " @Override public void a(Object anObject, Object... args) { super.a(anObject, this, args); }\n" + + "}\n" + + "class X implements I {\n" + + " public void a(Object anObject, String aString, Object... args) { System.out.print(1); }\n" + + " public void a(Object anObject, Object... args) { System.out.print(2); }\n" + + "}\n" + + "interface I {\n" + + " void a(Object anObject, String aString, Object... args);\n" + + " void a(Object anObject, Object... args);\n" + + "}\n", + }, + "121212"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=141800 + public void test050() { + this.runNegativeTest( + new String[] { + "X.java", + " import java.util.Arrays;\n" + + " public class X {\n" + + " public static void main( String args[] ) {\n" + + " Object test = new Object[] { \"Hello\", \"World\" };\n" + + " System.out.println(Arrays.asList(test));\n" + + " System.out.println(Arrays.asList((Object[])test)); // Warning here\n" + + " Zork z;\n" + + " }\n" + + "}", + }, + // ensure no complaint about unnecessary cast + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=141800 - variation + public void test051() { + this.runConformTest( + new String[] { + "X.java", + " import java.util.Arrays;\n" + + " public class X {\n" + + " public static void main( String args[] ) {\n" + + " Object test = new Object[] { \"Hello\", \"World\" };\n" + + " System.out.print(Arrays.asList(test).size());\n" + + " System.out.println(Arrays.asList((Object[])test).size()); // Warning here\n" + + " }\n" + + "}", + }, + "12"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=159607 + public void test052() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void addChildren(Widget w) {\n" + + " if (w instanceof Composite) {\n" + + " Composite composite = (Composite) w;\n" + + " addAll((Widget[]) composite.getChildren());\n" + + " addAll(composite.getChildren());\n" + + " }\n" + + " Zork z;\n" + + " }\n" + + " void addAll(Widget... widgets) {\n" + + " }\n" + + "}\n" + + "\n" + + "class Widget {}\n" + + "class Control extends Widget {}\n" + + "class Composite extends Control {\n" + + " Control[] getChildren() {\n" + + " return null;\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " addAll((Widget[]) composite.getChildren());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Control[] to Widget[]\n" + + "----------\n" + + "2. 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=159607 - variation + public void test053() { + this.runNegativeTest( + new String[] { + "X.java", + "class X {\n" + + " void addChildren(Widget w) {\n" + + " if (w instanceof Composite) {\n" + + " Composite composite = (Composite) w;\n" + + " addAll((Control[]) composite.getChildren());\n" + + " addAll(composite.getChildren());\n" + + " }\n" + + " Zork z;\n" + + " }\n" + + " void addAll(Control... widgets) {\n" + + " }\n" + + "}\n" + + "\n" + + "class Widget {}\n" + + "class Control extends Widget {}\n" + + "class Composite extends Control {\n" + + " Control[] getChildren() {\n" + + " return null;\n" + + " }\n" + + "}", // =================, + }, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " addAll((Control[]) composite.getChildren());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from Control[] to Control[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 8)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + public void test054() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " public static void varargs(Object... args) {\n" + + " if (args == null) {\n" + + " System.out.println(\"args is null\");\n" + + " return;\n" + + " }\n" + + " if (args.length == 0) {\n" + + " System.out.println(\"args is of length 0\");\n" + + " return;\n" + + " }\n" + + "\n" + + " System.out.println(args.length + \" \" + args[0]);\n" + + " }\n" + + "\n" + + " public static void main(String[] args) {\n" + + " @SuppressWarnings(\"boxing\")\n" + + " Integer[] i = { 0, 1, 2, 3, 4 };\n" + + " varargs(i);\n" + + " varargs((Object[]) i);\n" + + " varargs((Object) i);\n" + + " varargs(i.clone());\n" + + " }\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" + + "2. WARNING in X.java (at line 19)\n" + + " varargs(i);\n" + + " ^^^^^^^^^^\n" + + "Type Integer[] of the last argument to method varargs(Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n" + + "3. WARNING in X.java (at line 22)\n" + + " varargs(i.clone());\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type Integer[] of the last argument to method varargs(Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n"); + } + public void test055() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private static int elementCount(Object... elements) {\n" + + " return elements == null ? 0 : elements.length;\n" + + " }\n" + + " public static void main(String... args) {\n" + + " System.out.print(\"null length array: \" + elementCount(null));\n" + + " System.out.print(\"/[null] length array: \" + elementCount((Object)null));\n" + + " System.out.print(\"/empty length array: \" + elementCount());\n" + + " System.out.println(\"/[a,b,c] length array: \" + elementCount(\"a\", \"b\", \"c\"));\n" + + " }\n" + + "}", // ================= + }, + "null length array: 0/[null] length array: 1/empty length array: 0/[a,b,c] length array: 3"); + } + public void test056() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " Zork z;\n" + + " private static int elementCount(Object... elements) {\n" + + " return elements == null ? 0 : elements.length;\n" + + " }\n" + + " public static void main(String... args) {\n" + + " System.out.print(\"null length array: \" + elementCount(null));\n" + + " System.out.print(\"/[null] length array: \" + elementCount((Object)null));\n" + + " System.out.print(\"/empty length array: \" + elementCount());\n" + + " System.out.println(\"/[a,b,c] length array: \" + elementCount(\"a\", \"b\", \"c\"));\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" + + "2. WARNING in X.java (at line 7)\n" + + " System.out.print(\"null length array: \" + elementCount(null));\n" + + " ^^^^^^^^^^^^^^^^^^\n" + + "Type null of the last argument to method elementCount(Object...) doesn't exactly match the vararg parameter type. Cast to Object[] to confirm the non-varargs invocation, or pass individual arguments of type Object for a varargs invocation.\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=163889 + public void test057() { + this.runNegativeTest( + new String[] { + "X.java", + "import java.lang.annotation.RetentionPolicy;\n" + + "\n" + + "public class X {\n" + + "\n" + + " void a(Enum...enums) {}\n" + + "\n" + + " void b () {\n" + + " RetentionPolicy[] t = null;\n" + + " a(t);\n" + + " a((Enum[])t);\n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 10)\n" + + " a((Enum[])t);\n" + + " ^^^^^^^^^^^^\n" + + "Unnecessary cast from RetentionPolicy[] to Enum[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 11)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=162171 + public void test058() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void testPassingSubclassArrayAsVararg() {\n" + + " // The argument of type VarargsTest.Subclass[] should explicitly be\n" + + " // cast to VarargsTest.Parent[] for the invocation of the varargs\n" + + " // method processVararg(VarargsTest.Parent...) from type VarargsTest.\n" + + " // It could alternatively be cast to VarargsTest.Parent for a varargs\n" + + " // invocation\n" + + " processVararg(new Subclass[] {});\n" + + " }\n" + + "\n" + + " public void testPassingSubclassArrayAsVarargWithCast() {\n" + + " // Unnecessary cast from VarargsTest.Subclass[] to\n" + + " // VarargsTest.Parent[]\n" + + " processVararg((Parent[]) new Subclass[] {});\n" + + " processVararg(new Subclass[] {});\n" + + " Zork z;\n" + + " }\n" + + "\n" + + " private void processVararg(Parent... objs) {\n" + + " }\n" + + "\n" + + " class Parent {\n" + + " }\n" + + "\n" + + " class Subclass extends Parent {\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 14)\n" + + " processVararg((Parent[]) new Subclass[] {});\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Unnecessary cast from X.Subclass[] to X.Parent[]\n" + + "----------\n" + + "2. ERROR in X.java (at line 16)\n" + + " Zork z;\n" + + " ^^^^\n" + + "Zork cannot be resolved to a type\n" + + "----------\n"); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=170765 + public void test059() { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public void foo() {\n" + + " Integer[] array = null;\n" + + " varargs(array);\n" + + " }\n" + + "\n" + + " public void varargs(Number... o) {\n" + + " }\n" + + " Zork z;\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=186181 + public void test060() { + 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_4); + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static String varargMethod( Object... objects ) {\r\n" + + " String s = \"\";\n" + + " for (Object object : objects)\n" + + " s += \",\" + object.toString();\n" + + " return s;\n" + + " }\n" + + "}", + }, + "", + null, + true, + null, + options, + null); + + // make sure that this file contains the varargs attribute + IClassFileReader reader = ToolFactory.createDefaultClassFileReader(OUTPUT_DIR + File.separator + "X.class", IClassFileReader.ALL); + IMethodInfo[] methodInfos = reader.getMethodInfos(); + assertEquals("Wrong size", 2, methodInfos.length); + IMethodInfo methodInfo = null; + if (CharOperation.equals(methodInfos[0].getName(), "varargMethod".toCharArray())) { + methodInfo = methodInfos[0]; + } else if (CharOperation.equals(methodInfos[1].getName(), "varargMethod".toCharArray())) { + methodInfo = methodInfos[1]; + } + assertTrue("ACC_VARARGS is not set", (methodInfo.getAccessFlags() & ClassFileConstants.AccVarargs) == 0); + assertNotNull("Method varargMethodshould be there", methodInfo); + assertEquals("2", 2, methodInfo.getAttributeCount()); + IClassFileAttribute[] attributes = methodInfo.getAttributes(); + assertTrue("varargs attribute not found", CharOperation.equals(attributes[0].getAttributeName(), "Varargs".toCharArray()) + || CharOperation.equals(attributes[1].getAttributeName(), "Varargs".toCharArray())); + + 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.runConformTest( + new String[] { + "UseVararg.java", + "public class UseVararg {\r\n" + + " public static void main( String[] args ) {\n" + + " String arg = \"SUCCESS\";\n" + + " String results = X.varargMethod(arg);\n" + + " System.out.println( results );\n" + + " }\r\n" + + "}", + }, + ",SUCCESS", + null, + false, + null, + options, + null); + } + //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 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", + "import java.util.*;\n" + + "public class X {\n" + + " public static void main(String[] args) {\n" + + " HashSet> constantClassSet = new HashSet>();\n" + + " Collections.addAll(constantClassSet, String.class, Object.class);\n" + + " Zork z;\n" + + " }\n" + + "}\n", // ================= + }, + expectedOutput); + } + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=328247 + public void test062() throws Exception { + this.runConformTest( + new String[] { + "X.java", + "public class X {\r\n" + + " private static final String CONST = \"\";\r\n" + + "\r\n" + + " public static class A {\r\n" + + " A(Integer i, String... tab) {}\r\n" + + " }\r\n" + + " \r\n" + + " Object foo(final Float f) {\r\n" + + " return new A(Integer.valueOf(0), CONST) {\r\n" + + " public String toString() {\r\n" + + " return f.toString();\r\n" + + " }\r\n" + + " };\r\n" + + " }\r\n" + + "}", + }, + ""); + String expectedOutput = + " // Method descriptor #10 (LX;Ljava/lang/Integer;[Ljava/lang/String;Ljava/lang/Float;)V\n" + + " // Stack: 3, Locals: 5\n" + + " 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[] { + "Y.java", + "import java.util.ArrayList;\n" + + "import java.util.List;\n" + + "public class Y {\r\n" + + " @SafeVarargs\n" + + " public static List 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> 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; + 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 List asList(T... a) {\n" + + " return null;\n" + + " }\n" + + " public void bar() {\n" + + " List> 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; + 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 List asList(T... a) {\n" + + " return null;\n" + + " }\n" + + " public void bar() {\n" + + " List> 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 test066() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.DISABLED); + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.Collection;\n" + + "import java.util.Iterator;\n" + + "public class X {\n" + + " public static class IteratorChain implements Iterator {\n" + + " public IteratorChain(Collection a, Collection b, Collection ... collections) {\n" + + " }\n" + + " public boolean hasNext() {\n" + + " return false;\n" + + " }\n" + + " public T next() {\n" + + " return null;\n" + + " }\n" + + " public void remove() {\n" + + " throw new UnsupportedOperationException();\n" + + " }\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " new IteratorChain(null, null);\n" + + " }\n" + + "}\n", // ================= + }, + this.complianceLevel < ClassFileConstants.JDK1_7 ? + "----------\n" + + "1. WARNING in X.java (at line 18)\n" + + " new IteratorChain(null, null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Collection is created for a varargs parameter\n" + + "----------\n": + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " public IteratorChain(Collection a, Collection b, Collection ... 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(null, null);\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "Type safety: A generic array of Collection 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; + 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 List asList() { // Error, not varargs\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public List asList2(T ... a) { // error not static or final\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public static List asList3(T ... a) { // OK, varargs & static\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public final List asList4(T ... a) { // OK varargs & final\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public final static List 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 List asList(T ... t);\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " public static List 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 List 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 List 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; + 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 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; + 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 X(String ... a) {\n" + + " }\n" + + " public X(int i, String ... a) {\n" + + " }\n" + + " public List asList(String ... a) {\n" + + " return null;\n" + + " }\n" + + " public List asList(Zork t, String ... a) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " public List 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; + 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 X(T ... a) {\n" + + " }\n" + + " public X(int i, T ... a) {\n" + + " }\n" + + " public List asList(T ... a) {\n" + + " return null;\n" + + " }\n" + + " public List asList(T t, T ... a) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 3)\n" + + " public 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 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 List 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 List 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; + 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(T ... a) {\n" + + " }\n" + + " @SafeVarargs\n" + + " public X(int i, T ... a) {\n" + + " }\n" + + " @SafeVarargs\n" + + " public List asList(T ... a) {\n" + + " return null;\n" + + " }\n" + + " @SafeVarargs\n" + + " public List asList(T t, T ... a) {\n" + + " return null;\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " public List 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 List 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; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + + String[] bounds = new String[] { "Object","Serializable","Comparable"}; + String[] bounds15 = new String[] { "Object","Serializable","Comparable", "Constable"}; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " @SafeVarargs\n" + + " public static List asList(T ... a) {\n" + + " return null;\n" + + " }\n" + + " public static List asList2(T ... a) {\n" + + " return null;\n" + + " }\n" + + " List> 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 List 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 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; + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + String[] bounds = new String[] { "Object","Serializable","Comparable"}; + String[] bounds15 = new String[] { "Object","Serializable","Comparable", "Constable"}; + this.runNegativeTest( + new String[] { + "X.java", + "import java.util.List;\n" + + "public class X {\n" + + " @SafeVarargs\n" + + " public static List asList(T ... a) {\n" + + " return null;\n" + + " }\n" + + " @SuppressWarnings(\"unchecked\")\n" + + " public static List asList2(T ... a) {\n" + + " return null;\n" + + " }\n" + + " List> 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 is created for a varargs parameter\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346042 + public void test069() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + this.runNegativeTest( + new String[] { + "p1/B.java", + "package p1;\n" + + "class A {\n" + + "}\n" + + "public class B extends A {\n" + + " public void foo(A... args) {\n" + + " }\n" + + "}\n", + "p2/C.java", + "package p2;\n" + + "import p1.B;\n" + + "public class C {\n" + + "\n" + + " public static final void main(String[] args) {\n" + + " (new B()).foo(new B(), new B());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p2\\C.java (at line 6)\n" + + " (new B()).foo(new B(), new B());\n" + + " ^^^\n" + + "The method foo(A...) of type B is not applicable as the formal varargs element type A is not accessible here\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346038 + public void test070() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int ...i) {}\n" + + " public static void foo(double...d) {}\n" + + " public static void main(String[] args) {\n" + + " foo(1, 2, 3);\n" + + " System.out.println (\"Done\");\n" + + " }\n" + + "}\n" + }, + "Done"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 + public void test070_tolerate() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + try { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int ...i) {}\n" + + " public static void foo(double...d) {}\n" + + " public static void main(String[] args) {\n" + + " foo(1, 2, 3);\n" + + " System.out.println (\"Done\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " foo(1, 2, 3);\n" + + " ^^^\n" + + "The method foo(int[]) is ambiguous for the type X\n" + + "----------\n", + null, true, options); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int ...i) {}\n" + + " public static void foo(double...d) {}\n" + + " public static void main(String[] args) {\n" + + " foo(1, 2, 3);\n" + + " System.out.println (\"Done\");\n" + + " }\n" + + "}\n" + }, + "Done", + null, true, null, options, null); + } + } finally { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); + } + + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 + public void test070_tolerate2() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + try { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runNegativeTest( + false /* skipJavac */, + this.complianceLevel == ClassFileConstants.JDK1_7 ? + JavacTestOptions.Excuse.JavacCompilesIncorrectSource : null, + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n" + + " public static void test(int... a) {\n" + + " System.out.println(Arrays.toString(a));\n}\n" + + " public static void test(Object... a) {\n" + + " System.out.println(Arrays.toString(a));\n}\n" + + " public static void main(String[] args) {\n" + + " test(1);\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 10)\n" + + " test(1);\n" + + " ^^^^\n" + + "The method test(int[]) is ambiguous for the type X\n" + + "----------\n", + null, true, options); + } else { + this.runConformTest( + new String[] { + "X.java", + "import java.util.Arrays;\n" + + "public class X {\n" + + " public static void test(int... a) {\n" + + " System.out.println(Arrays.toString(a));\n}\n" + + " public static void test(Object... a) {\n" + + " System.out.println(Arrays.toString(a));\n}\n" + + " public static void main(String[] args) {\n" + + " test(1);\n" + + " }\n" + + "}\n" + }, + "[1]", + null, true, null, options, null); + } + } finally { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); + } + + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346038 + public void test070a() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int ...i) {}\n" + + " public static void foo(double...d) {}\n" + + " public static void main(String[] args) {\n" + + " foo(1, 2, 3);\n" + + " System.out.println (\"Done\");\n" + + " }\n" + + "}\n" + }, + "Done"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 + public void test070a_tolerate() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + Map options = getCompilerOptions(); + try { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int ...i) {}\n" + + " public static void foo(double...d) {}\n" + + " public static void main(String[] args) {\n" + + " foo(1, 2, 3);\n" + + " System.out.println (\"Done\");\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " foo(1, 2, 3);\n" + + " ^^^\n" + + "The method foo(int[]) is ambiguous for the type X\n" + + "----------\n", + null, true, options); + } else { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int ...i) {}\n" + + " public static void foo(double...d) {}\n" + + " public static void main(String[] args) {\n" + + " foo(1, 2, 3);\n" + + " System.out.println (\"Done\");\n" + + " }\n" + + "}\n" + }, + "Done", + null, true, null, options, null); + } + } finally { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346038 + public void test070b() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int ...i) {}\n" + + " public static void foo(double d1, double...d) {}\n" + + " public static void main(String[] args) {\n" + + " foo(1, 2, 3); // foo NOT flagged ambiguous\n" + + " }\n" + + "}\n" + }, + ""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 + public void test070b_tolerate() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + String[] src = new String[] { + "X.java", + "public class X {\n" + + " public static void foo(int ...i) {}\n" + + " public static void foo(double d1, double...d) {}\n" + + " public static void main(String[] args) {\n" + + " foo(1, 2, 3); // foo NOT flagged ambiguous\n" + + " }\n" + + "}\n" + }; + try { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runConformTest( + src, + ""); + } else { + this.runNegativeTest( + src, + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " foo(1, 2, 3); // foo NOT flagged ambiguous\n" + + " ^^^\n" + + "The method foo(int[]) is ambiguous for the type X\n" + + "----------\n"); + } + } finally { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346038 + public void test070c() { // check behaviour of Scope.mostSpecificMethodBinding() + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void main(String[] s) {\n" + + " count(1);\n" + + " count(1, 1);\n" + + " count(1, 1, 1);\n" + + " }\n" + + " public static void count(int ... values) {}\n" + + " public static void count(int i, int ... values) {}\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 3)\n" + + " count(1);\n" + + " ^^^^^\n" + + "The method count(int[]) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 4)\n" + + " count(1, 1);\n" + + " ^^^^^\n" + + "The method count(int[]) is ambiguous for the type X\n" + + "----------\n" + + "3. ERROR in X.java (at line 5)\n" + + " count(1, 1, 1);\n" + + " ^^^^^\n" + + "The method count(int[]) is ambiguous for the type X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346038 + public void test070d() { // check behaviour of Scope.mostSpecificMethodBinding() + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void b(boolean b, Object... o) {}\n" + + " void b(Boolean... o) {}\n" + + " void c(boolean b, boolean b2, Object... o) {}\n" + + " void c(Boolean b, Object... o) {}\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.b(true);\n" + + " x.b(true, false);\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 8)\r\n" + + " x.b(true);\r\n" + + " ^\n" + + "The method b(boolean, Object[]) is ambiguous for the type X\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\r\n" + + " x.b(true, false);\r\n" + + " ^\n" + + "The method b(boolean, Object[]) is ambiguous for the type X\n" + + "----------\n"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=346039 + public void test071() { // check behaviour of Scope.mostSpecificMethodBinding() + this.runConformTest( + new String[] { + "X.java", + "public class X implements IClass{\n" + + " X(IClass c, X t, IType... args) {\n" + + " System.out.println (\"1\");\n" + + " }\n" + + " X(IClass c, IType... args) {\n" + + " System.out.println (\"2\");\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " IClass c = null;\n" + + " X t = null;\n" + + " X t2 = new X(c, t); // incorrectly flagged ambiguous\n" + + " }\n" + + "}\n" + + "interface IType{}\n" + + "interface IClass extends IType{}\n" + }, + "1"); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=383780 + public void test071_tolerate() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + String[] src = + new String[] { + "X.java", + "public class X implements IClass{\n" + + " X(IClass c, X t, IType... args) {\n" + + " System.out.println (\"1\");\n" + + " }\n" + + " X(IClass c, IType... args) {\n" + + " System.out.println (\"2\");\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " IClass c = null;\n" + + " X t = null;\n" + + " X t2 = new X(c, t); // incorrectly flagged ambiguous\n" + + " }\n" + + "}\n" + + "interface IType{}\n" + + "interface IClass extends IType{}\n" + }; + try { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); + if (this.complianceLevel >= ClassFileConstants.JDK1_7) { + this.runConformTest( + src, + "1"); + } else { + this.runNegativeTest( + src, + "----------\n" + + "1. ERROR in X.java (at line 11)\n" + + " X t2 = new X(c, t); // incorrectly flagged ambiguous\n" + + " ^^^^^^^^^^^\n" + + "The constructor X(IClass, X, IType[]) is ambiguous\n" + + "----------\n"); + } + } finally { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=364672 + public void test072() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " private class Z {}\n" + + " public void foo() {\n" + + " Z[] zs = null;\n" + + " Y.bar(zs, new Z());\n" + + " }\n" + + " public static void main(String[] args) {}\n" + + "}", + "Y.java", + "public class Y {\n" + + " public native static void bar(T[] t, T t1, T... t2);\n" + + "}" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=364672 + public void test073() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static final String CONSTANT = \"\";\n" + + " private static class A {\n" + + " A(String s, String s2, String s3, A... a) {}\n" + + " }\n" + + " private static class B extends A {\n" + + " B(String s, String s2) {\n" + + " super(s, s2, CONSTANT);\n" + + " }\n" + + " }\n" + + " private static void foo(Object o, A ... a) {\n" + + " }\n" + + " private static B bar() {\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Object o = null;\n" + + " foo(o, bar(), bar());\n" + + " }\n" + + "}" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=364672 + public void test074() throws Exception { + this.runNegativeTest( + new String[] { + "p1/B.java", + "package p1;\n" + + "class A {}\n" + + "public class B extends A {\n" + + " public B(A... args) {}\n" + + " public B() {}\n" + + "}\n", + "p2/C.java", + "package p2;\n" + + "import p1.B;\n" + + "public class C {\n" + + " public static final void main(String[] args) {\n" + + " new B(new B(), new B());\n" + + " }\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p2\\C.java (at line 5)\n" + + " new B(new B(), new B());\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The constructor B(A...) of type B is not applicable as the formal varargs element type A is not accessible here\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=382469 + public void testBug382469() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + String[] src = + new String[] { + "X.java", + "public class X {\n" + + " private static void bar(Object... objs) {\n" + + " System.out.println (\"1\");\n" + + " }\n" + + " private static void bar(int intValue, Object... objs) {\n" + + " System.out.println (\"2\");\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " bar(5);\n" + + " }\n" + + "}\n" + }; + try { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runConformTest( + src, + "2"); + } else { + this.runNegativeTest( + src, + "----------\n" + + "1. WARNING in X.java (at line 5)\n" + + " private static void bar(int intValue, Object... objs) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The method bar(int, Object...) from the type X is never used locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 9)\n" + + " bar(5);\n" + + " ^^^\n" + + "The method bar(Object[]) is ambiguous for the type X\n" + + "----------\n"); + } + } finally { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); + } + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=386361 + public void testBug386361() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + String[] src = + new String[] { + "X.java", + "public class X {\n" + + " public static void test(int i, Object... objects) {\n" + + " System.out.println (\"1\");\n" + + " }\n" + + " public static void test(Object... objects) {\n" + + " System.out.println (\"2\");\n" + + " }\n" + + " public static void main(String args[]) {\n" + + " test(1,\"test\");\n" + + " }\n" + + "}\n" + }; + try { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "true"); + if (this.complianceLevel < ClassFileConstants.JDK1_7) { + this.runConformTest( + src, + "1"); + } else { + this.runNegativeTest( + src, + "----------\n" + + "1. ERROR in X.java (at line 9)\n" + + " test(1,\"test\");\n" + + " ^^^^\n" + + "The method test(int, Object[]) is ambiguous for the type X\n" + + "----------\n"); + } + } finally { + System.setProperty("tolerateIllegalAmbiguousVarargsInvocation", "false"); + } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=426678, [1.8][compiler] Another issue with vararg type element accessibility + public void test426678() { + runNegativeTest( + new String[] { + "X.java", + "import p.*;\n" + + "public class X {\n" + + " public static void main(String argv[]) {\n" + + " new B().foo(null, null);\n" + + " }\n" + + "}\n", + + "p/B.java", + "package p;\n" + + "class A {\n" + + "}\n" + + "public class B extends A {\n" + + " public void foo(A ... o) { System.out.println(\"MB:A\"); }\n" + + " public void foo(Object... o) { System.out.println(\"MB:O\"); }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in X.java (at line 4)\n" + + " new B().foo(null, null);\n" + + " ^^^\n" + + "The method foo(A...) of type B is not applicable as the formal varargs element type A is not accessible here\n" + + "----------\n"); // check and adjust, + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=436474, [codegen]Problem with varargs and List.toString + public void test436474() { + runConformTest( + new String[] { + "Scratch.java", + "import java.util.Arrays;\n" + + "import java.util.List;\n" + + "public class Scratch {\n" + + " public static void vararg(String... strs) {\n" + + " System.out.println(strs[0]);\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " List l = Arrays.asList(\"a\");\n" + + " vararg(l.toArray(new String[0]));\n" + + " }\n" + + "}", + }, + "a"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=437973, [1.8][compiler] Missing implementation of JLS 15.12.2.5 Third Bullet - Part 2 + public void test437973() { + runConformTest( + new String[] { + "X.java", + "class W {}\n" + + "class Y extends W {}\n" + + "class Z extends Y {}\n" + + "class A{}\n" + + "public class X {\n" + + " void foo(String format, Object ... args) {\n" + + " System.out.println(\"foo Object Varargs\");\n" + + " }\n" + + " void foo(String ... s) {\n" + + " System.out.println(\"foo String Varargs\");\n" + + " }\n" + + " void foo1(Z ... z) {\n" + + " System.out.println(\"foo1 Z varargs\");\n" + + " }\n" + + " void foo1(Z z, Y ... y) {\n" + + " System.out.println(\"foo1 Y varargs\");\n" + + " }\n" + + " void foo2(Z z, W ... w) {\n" + + " System.out.println(\"foo2 W varargs\");\n" + + " }\n" + + " void foo2(Z z, Y ... y) {\n" + + " System.out.println(\"foo2 Y varargs\");\n" + + " }\n" + + " void foo3(A a, W ... w) {\n" + + " System.out.println(\"foo3 W varargs\");\n" + + " }\n" + + " void foo3(A a, Y ... y) {\n" + + " System.out.println(\"foo3 Y varargs\");\n" + + " }\n" + + " void foo4(W w) {\n" + + " System.out.println(\"foo4 W\");\n" + + " }\n" + + " void foo4(W w, A ... a) {\n" + + " System.out.println(\"foo4 A varargs\");\n" + + " }\n" + + " void foo5(W w) {\n" + + " System.out.println(\"foo5 W\");\n" + + " }\n" + + " void foo5(W ... w) {\n" + + " System.out.println(\"foo5 W varargs\");\n" + + " }\n" + + " void foo6(W ... w) {\n" + + " System.out.println(\"foo6 W varargs\");\n" + + " }\n" + + " void foo6(Y ... y) {\n" + + " System.out.println(\"foo6 Y varargs\");\n" + + " }\n" + + " void foo7(String format, Object ... args) {\n" + + " System.out.println(\"foo7 Object Varargs\");\n" + + " }\n" + + " void foo8(String ... s) {\n" + + " System.out.println(\"foo8 String Varargs\");\n" + + " }\n" + + " void bar() {\n" + + " foo(\"f\");\n" + // Original Test Case : Error without fix + " foo(\"f\", 12);\n" + + " foo1(new Z());\n" + + " foo2(new Z());\n" + + " foo3(new A());\n" + + " foo4(new W());\n" + + " foo5(new W());\n" + + " foo6(new W());\n" + + " foo6(new Y());\n" + + " foo7(\"f\", 12);\n" + + " foo8(\"f\");\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.bar();\n" + + " }\n" + + "}\n", + }, + "foo String Varargs\n" + + "foo Object Varargs\n" + + "foo1 Z varargs\n" + + "foo2 Y varargs\n" + + "foo3 Y varargs\n" + + "foo4 W\n" + + "foo5 W\n" + + "foo6 W varargs\n" + + "foo6 Y varargs\n" + + "foo7 Object Varargs\n" + + "foo8 String Varargs"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=437973, [1.8][compiler] Missing implementation of JLS 15.12.2.5 Third Bullet - Part 2 + public void test437973a() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + runConformTest( + new String[] { + "X.java", + "class W {}\n" + + "class Y extends W {}\n" + + "public class X {\n" + + " void foo(W w, Y ... y) {\n" + + " System.out.println(\"foo Y varargs\");\n" + + " }\n" + + " void foo(W ... w) {\n" + + " System.out.println(\"foo W varargs\");\n" + + " }\n" + + " void bar() {\n" + + " foo(new W(), new W(), new W());\n" + + + //Error with 1.8 without fix for all these three test cases. + " foo(new Y(), new Y(), new Y());\n" + + " foo(new W());\n" + + " foo(new Y());\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " X x = new X();\n" + + " x.bar();\n" + + " }\n" + + "}\n"}, + "foo W varargs\n" + + "foo Y varargs\n" + + "foo Y varargs\n" + + "foo Y varargs"); + } + + //https://bugs.eclipse.org/bugs/show_bug.cgi?id=437973, [1.8][compiler] Missing implementation of JLS 15.12.2.5 Third Bullet - Part 2 + //The parameter of one method is not a subtype of the other. + public void test437973b() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + runNegativeTest( + new String[] { + "X.java", + "class W {}\n" + + "class A {}\n" + + "public class X {\n" + + " void foo(W ... w) {}\n" + + " void foo(W w, A ... a) {}\n" + + " void bar() {\n" + + " foo(new W()); // 1.8 Error: Ambiguous method error\n" + + " }\n" + + " public static void main(String[] args) {}\n" + + "}\n"}, + "----------\n" + + "1. ERROR in X.java (at line 7)\n" + + " foo(new W()); // 1.8 Error: Ambiguous method error\n" + + " ^^^\n" + + "The method foo(W[]) is ambiguous for the type X\n" + + "----------\n"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=437973, [1.8][compiler] Missing implementation of JLS 15.12.2.5 Third Bullet - Part 2 + // Lambda functions + public void test437973c() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) + return; + runNegativeTest( + new String[] { + "X.java", + "class W {}\n" + + "class Y extends W {}\n" + + "class Z extends Y {}\n" + + "class A{}\n" + + "\n" + + "interface I1 {\n" + + " void foo (Y ... y); \n" + + " default void foo (Y y, W ... w) {}\n" + + "}\n" + + "\n" + + "public class X {\n" + + " void bar() {\n" + + " I1 i1 = (x) -> {};\n" + + " i1.foo(new Y());\n" + + " }\n" + + "}\n"},""); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=437973, [1.8][compiler] Missing implementation of JLS 15.12.2.5 Third Bullet - Part 2 + // Original Test Case - Comment 0 + public void test437973d() { + runConformTest( + new String[] { + "Junk16.java", + "public class Junk16 {\n" + + " public static String junk(String format, Object... args) {\n" + + " System.out.println(\"junk 1\");\n" + + " return null;\n" + + " }\n" + + " public static String junk(String... s) {\n" + + " System.out.println(\"junk 2\");\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " // COMPILE ERROR IN ECLIPSE (none in JDK) WITHOUT FIX\n" + + " junk(\"fred\");\n" + + " //NO COMPILE ERROR\n" + + " junk(\"fred\", 12);\n" + + " }\n" + + "}\n"}, + "junk 2\n" + + "junk 1"); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=443596, [1.8][compiler] Failure for overload resolution in case of Generics and Varags + public void _test443596() { + runConformTest( + new String[] { + "Collections2.java", + "public final class Collections2 {\n" + + " static interface Predicate { boolean test(T object); }\n" + + " public static Predicate in(Predicate arg) { return null; }\n" + + " public static Predicate and(Predicate... arg) { return null; }\n" + + " public static Predicate and(Predicate arg0, Predicate arg1) { return null; }\n" + + " static class FilteredCollection {\n" + + " Predicate predicate;\n" + + " public void error(Predicate arg) { and(predicate, in(arg)); } // no compile\n" + + " }\n" + + "}\n"}); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=470370, [1.8] Wrong varargs behaviour causes ArrayStoreException + public void test470370() { + runConformTest( + new String[] { + "TestVarargs.java", + "import java.util.*;\n" + + "public class TestVarargs {\n" + + " public static void main(String[] args) {\n" + + " bar(new Class[]{});\n" + + " foo(new Class[]{});\n" + + " }\n" + + " public static Object foo(Class[] sig) {\n" + + " return Arrays.asList(Arrays.copyOfRange(sig, 0, sig.length));\n" + + " }\n" + + " public static List> bar(Class[] sig) {\n" + + " return Arrays.asList(Arrays.copyOfRange(sig, 0, sig.length));\n" + + " }\n" + + "}" + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=488658 + public void testBug488658_001() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK9) return; + this.runConformTest( + new String[] { + "X.java", + "class Y {}\n"+ + "@SuppressWarnings(\"unused\")\n" + + "public class X {\n"+ + " @SafeVarargs\n"+ + " private Y foo(T ... a) {\n"+ + " return null;\n"+ + " }\n"+ + "}\n", + }, + ""); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.ERROR); + this.runNegativeTest( + new String[] { + "X.java", + "class Y {}\n"+ + "public class X {\n"+ + "@SuppressWarnings(\"unused\")\n" + + " private Y foo(T ... a) {\n"+ + " return null;\n"+ + " }\n"+ + "}\n" + }, + "----------\n" + + "1. WARNING in X.java (at line 4)\n" + + " private Y foo(T ... a) {\n" + + " ^\n" + + "Type safety: Potential heap pollution via varargs parameter a\n" + + "----------\n"); + + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java new file mode 100644 index 0000000000..60ce9b7c0b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest.java @@ -0,0 +1,20720 @@ +/******************************************************************************* + * Copyright (c) 2005, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Jesper Steen Moller - Contributions for + * bug 404146 - [1.7][compiler] nested try-catch-finally-blocks leads to unrunnable Java byte code + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import java.util.Map; +import java.util.Random; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.Test; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class XLargeTest extends AbstractRegressionTest { + static { +// TESTS_NUMBERS = new int[] { 17 }; +// TESTS_NAMES = new String[] { "testBug519070" }; + } + +public XLargeTest(String name) { + super(name); +} +public static Test suite() { + return buildAllCompliancesTestSuite(testClass()); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=368435 +public void test368435() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + StringBuilder sourceCode = new StringBuilder( + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public void print() {\n" + + " int i = 0;\n" + + " if (System.currentTimeMillis() > 17000L) {\n" + + " System.out.println(i++);\n"); + + for (int i = 0; i < 5000; i++) { + sourceCode.append("\t\t System.out.println(\"xyz\");\n"); + } + sourceCode.append("}\n}\n}\n"); + + this.runConformTest( + new String[] { + "X.java", + sourceCode.toString() + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=368435 +public void test368435b() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + StringBuilder sourceCode = new StringBuilder( + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " public X() {\n" + + " int i = 0;\n" + + " if (System.currentTimeMillis() > 17000L) {\n" + + " System.out.println(i++);\n"); + + for (int i = 0; i < 5000; i++) { + sourceCode.append("\t\t System.out.println(\"xyz\");\n"); + } + sourceCode.append("}\n}\n}\n"); + + this.runConformTest( + new String[] { + "X.java", + sourceCode.toString() + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=368435 +public void test368435c() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT); + StringBuilder sourceCode = new StringBuilder( + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " {\n" + + " int i = 0;\n" + + " if (System.currentTimeMillis() > 17000L) {\n" + + " System.out.println(i++);\n"); + + for (int i = 0; i < 5000; i++) { + sourceCode.append("\t\t System.out.println(\"xyz\");\n"); + } + sourceCode.append("}\n}\n}\n"); + + this.runConformTest( + new String[] { + "X.java", + sourceCode.toString() + }, + "SUCCESS", + null, + true, + null, + settings, + null); +} + +public void test001() { + this.runConformTest( + new String[] { + "X.java", + "\n" + + "public class X {\n" + + " public static int i,j;\n" + + " public static long l;\n" + + "\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " }\n" + + " \n" + + " public static void foo() {\n" + + " byte b = 0;\n" + + " while ( b < 4 ) {\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " b++;\n" + + " }\n" + + " if (b == 4 && i == 0) System.out.println(\"SUCCESS\");\n" + + " else System.out.println(\"FAILED\");\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} + +public void test002() { + this.runConformTest( + new String[] { + "X2.java", + "public class X2 {\n" + + " public static boolean b = false;\n" + + " public static int i, l, j;\n" + + "\n" + + " public static void main(String args[]) {\n" + + " }\n" + + " \n" + + " static {\n" + + " while (b) {\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " b = false;\n" + + " }\n" + + " if (i == 0) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } else {\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} + +public void test003() { + this.runConformTest( + new String[] { + "X3.java", + "\n" + + "public class X3 {\n" + + " public int i,j;\n" + + " public long l;\n" + + "\n" + + " public static void main(String args[]) {\n" + + " X3 x = new X3();\n" + + " }\n" + + " \n" + + " public X3() {\n" + + " byte b = 0;\n" + + " i = j = 0;\n" + + " l = 0L;\n" + + " while ( b < 4 ) {\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " b++;\n" + + " }\n" + + " if (b == 4 && i == 0) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " } else {\n" + + " System.out.println(\"FAILED\");\n" + + " }\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} + +public void test004() { + this.runConformTest( + new String[] { + "X.java", + "\n" + + "public class X {\n" + + " public static int i,j;\n" + + " public static long l;\n" + + "\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " }\n" + + " \n" + + " public static void foo() {\n" + + " byte b = 0;\n" + + " for (int i = 0; i < 1; i++) {\n" + + " while ( b < 4 ) {\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " b++;\n" + + " }\n" + + " }\n" + + " if (b == 4 && i == 0) System.out.println(\"SUCCESS\");\n" + + " else System.out.println(\"FAILED\");\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} + +public void test005() { + runConformTest( + true, + new String[] { + "p/X.java", + "package p;\n" + + "public class X {\n" + + " public static void main(String args[]) {\n" + + " System.out.println(\"\" + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' \n" + + " + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\' + \'a\');\n" + + " }\n" + + "}\n", + }, + "", + null, + null, + JavacTestOptions.JavacHasABug.JavacThrowsAnException /* stack overflow */); // transient, platform-dependent +} + +/* + * http://dev.eclipse.org/bugs/show_bug.cgi?id=26129 + */ +public void test006() { + this.runConformTest( + new String[] { + "A.java", + "public class A {" + // $NON-NLS-1$ + " public static void main(String[] args) {" + // $NON-NLS-1$ + " int i = 1;" + // $NON-NLS-1$ + " try {" + // $NON-NLS-1$ + " if (i == 0)" + // $NON-NLS-1$ + " throw new Exception();" + // $NON-NLS-1$ + " return;" + // $NON-NLS-1$ + " } catch (Exception e) {" + // $NON-NLS-1$ + " i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;i = 366 * i % 534;" + // $NON-NLS-1$ + " } finally {" + // $NON-NLS-1$ + " if (i == 1)" + // $NON-NLS-1$ + " System.out.print(\"OK\");" + // $NON-NLS-1$ + " else" + // $NON-NLS-1$ + " System.out.print(\"FAIL\");" + // $NON-NLS-1$ + " }" + // $NON-NLS-1$ + " }" + // $NON-NLS-1$ + "}"// $NON-NLS-1$ + }, + "OK"); +} + +/* + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=31811 + */ +public void test007() { + this.runConformTest( + new String[] { + "X.java", + "\n" + + "public class X {\n" + + " public static int i,j;\n" + + " public static long l;\n" + + "\n" + + " public static void main(String args[]) {\n" + + " foo();\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + " \n" + + " public static void foo() {\n" + + " byte b = 0;\n" + + " for(;;) {\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;i*=l+j;\n" + + " b++;\n" + + " if (b > 1) {\n" + + " break;" + + " };\n" + + " };\n" + + " }\n" + + "}" + }, + "SUCCESS"); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=115408 +public void test008() { + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE); + options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); + options.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE); + this.runConformTest(new String[] { + "X.java", + "public class X extends B implements IToken {\n" + + " public X( int t, int endOffset, char [] filename, int line ) {\n" + + " super( t, filename, line );\n" + + " setOffsetAndLength( endOffset );\n" + + " }\n" + + " protected int offset;\n" + + " public int getOffset() { \n" + + " return offset; \n" + + " }\n" + + " public int getLength() {\n" + + " return getCharImage().length;\n" + + " }\n" + + " protected void setOffsetAndLength( int endOffset ) {\n" + + " this.offset = endOffset - getLength();\n" + + " }\n" + + " public String foo() { \n" + + " switch ( getType() ) {\n" + + " case IToken.tCOLONCOLON :\n" + + " return \"::\" ; //$NON-NLS-1$\n" + + " case IToken.tCOLON :\n" + + " return \":\" ; //$NON-NLS-1$\n" + + " case IToken.tSEMI :\n" + + " return \";\" ; //$NON-NLS-1$\n" + + " case IToken.tCOMMA :\n" + + " return \",\" ; //$NON-NLS-1$\n" + + " case IToken.tQUESTION :\n" + + " return \"?\" ; //$NON-NLS-1$\n" + + " case IToken.tLPAREN :\n" + + " return \"(\" ; //$NON-NLS-1$\n" + + " case IToken.tRPAREN :\n" + + " return \")\" ; //$NON-NLS-1$\n" + + " case IToken.tLBRACKET :\n" + + " return \"[\" ; //$NON-NLS-1$\n" + + " case IToken.tRBRACKET :\n" + + " return \"]\" ; //$NON-NLS-1$\n" + + " case IToken.tLBRACE :\n" + + " return \"{\" ; //$NON-NLS-1$\n" + + " case IToken.tRBRACE :\n" + + " return \"}\"; //$NON-NLS-1$\n" + + " case IToken.tPLUSASSIGN :\n" + + " return \"+=\"; //$NON-NLS-1$\n" + + " case IToken.tINCR :\n" + + " return \"++\" ; //$NON-NLS-1$\n" + + " case IToken.tPLUS :\n" + + " return \"+\"; //$NON-NLS-1$\n" + + " case IToken.tMINUSASSIGN :\n" + + " return \"-=\" ; //$NON-NLS-1$\n" + + " case IToken.tDECR :\n" + + " return \"--\" ; //$NON-NLS-1$\n" + + " case IToken.tARROWSTAR :\n" + + " return \"->*\" ; //$NON-NLS-1$\n" + + " case IToken.tARROW :\n" + + " return \"->\" ; //$NON-NLS-1$\n" + + " case IToken.tMINUS :\n" + + " return \"-\" ; //$NON-NLS-1$\n" + + " case IToken.tSTARASSIGN :\n" + + " return \"*=\" ; //$NON-NLS-1$\n" + + " case IToken.tSTAR :\n" + + " return \"*\" ; //$NON-NLS-1$\n" + + " case IToken.tMODASSIGN :\n" + + " return \"%=\" ; //$NON-NLS-1$\n" + + " case IToken.tMOD :\n" + + " return \"%\" ; //$NON-NLS-1$\n" + + " case IToken.tXORASSIGN :\n" + + " return \"^=\" ; //$NON-NLS-1$\n" + + " case IToken.tXOR :\n" + + " return \"^\" ; //$NON-NLS-1$\n" + + " case IToken.tAMPERASSIGN :\n" + + " return \"&=\" ; //$NON-NLS-1$\n" + + " case IToken.tAND :\n" + + " return \"&&\" ; //$NON-NLS-1$\n" + + " case IToken.tAMPER :\n" + + " return \"&\" ; //$NON-NLS-1$\n" + + " case IToken.tBITORASSIGN :\n" + + " return \"|=\" ; //$NON-NLS-1$\n" + + " case IToken.tOR :\n" + + " return \"||\" ; //$NON-NLS-1$\n" + + " case IToken.tBITOR :\n" + + " return \"|\" ; //$NON-NLS-1$\n" + + " case IToken.tCOMPL :\n" + + " return \"~\" ; //$NON-NLS-1$\n" + + " case IToken.tNOTEQUAL :\n" + + " return \"!=\" ; //$NON-NLS-1$\n" + + " case IToken.tNOT :\n" + + " return \"!\" ; //$NON-NLS-1$\n" + + " case IToken.tEQUAL :\n" + + " return \"==\" ; //$NON-NLS-1$\n" + + " case IToken.tASSIGN :\n" + + " return \"=\" ; //$NON-NLS-1$\n" + + " case IToken.tSHIFTL :\n" + + " return \"<<\" ; //$NON-NLS-1$\n" + + " case IToken.tLTEQUAL :\n" + + " return \"<=\" ; //$NON-NLS-1$\n" + + " case IToken.tLT :\n" + + " return \"<\"; //$NON-NLS-1$\n" + + " case IToken.tSHIFTRASSIGN :\n" + + " return \">>=\" ; //$NON-NLS-1$\n" + + " case IToken.tSHIFTR :\n" + + " return \">>\" ; //$NON-NLS-1$\n" + + " case IToken.tGTEQUAL :\n" + + " return \">=\" ; //$NON-NLS-1$\n" + + " case IToken.tGT :\n" + + " return \">\" ; //$NON-NLS-1$\n" + + " case IToken.tSHIFTLASSIGN :\n" + + " return \"<<=\" ; //$NON-NLS-1$\n" + + " case IToken.tELLIPSIS :\n" + + " return \"...\" ; //$NON-NLS-1$\n" + + " case IToken.tDOTSTAR :\n" + + " return \".*\" ; //$NON-NLS-1$\n" + + " case IToken.tDOT :\n" + + " return \".\" ; //$NON-NLS-1$\n" + + " case IToken.tDIVASSIGN :\n" + + " return \"/=\" ; //$NON-NLS-1$\n" + + " case IToken.tDIV :\n" + + " return \"/\" ; //$NON-NLS-1$\n" + + " case IToken.t_and :\n" + + " return Keywords.AND;\n" + + " case IToken.t_and_eq :\n" + + " return Keywords.AND_EQ ;\n" + + " case IToken.t_asm :\n" + + " return Keywords.ASM ;\n" + + " case IToken.t_auto :\n" + + " return Keywords.AUTO ;\n" + + " case IToken.t_bitand :\n" + + " return Keywords.BITAND ;\n" + + " case IToken.t_bitor :\n" + + " return Keywords.BITOR ;\n" + + " case IToken.t_bool :\n" + + " return Keywords.BOOL ;\n" + + " case IToken.t_break :\n" + + " return Keywords.BREAK ;\n" + + " case IToken.t_case :\n" + + " return Keywords.CASE ;\n" + + " case IToken.t_catch :\n" + + " return Keywords.CATCH ;\n" + + " case IToken.t_char :\n" + + " return Keywords.CHAR ;\n" + + " case IToken.t_class :\n" + + " return Keywords.CLASS ;\n" + + " case IToken.t_compl :\n" + + " return Keywords.COMPL ;\n" + + " case IToken.t_const :\n" + + " return Keywords.CONST ;\n" + + " case IToken.t_const_cast :\n" + + " return Keywords.CONST_CAST ;\n" + + " case IToken.t_continue :\n" + + " return Keywords.CONTINUE ;\n" + + " case IToken.t_default :\n" + + " return Keywords.DEFAULT ;\n" + + " case IToken.t_delete :\n" + + " return Keywords.DELETE ;\n" + + " case IToken.t_do :\n" + + " return Keywords.DO;\n" + + " case IToken.t_double :\n" + + " return Keywords.DOUBLE ;\n" + + " case IToken.t_dynamic_cast :\n" + + " return Keywords.DYNAMIC_CAST ;\n" + + " case IToken.t_else :\n" + + " return Keywords.ELSE;\n" + + " case IToken.t_enum :\n" + + " return Keywords.ENUM ;\n" + + " case IToken.t_explicit :\n" + + " return Keywords.EXPLICIT ;\n" + + " case IToken.t_export :\n" + + " return Keywords.EXPORT ;\n" + + " case IToken.t_extern :\n" + + " return Keywords.EXTERN;\n" + + " case IToken.t_false :\n" + + " return Keywords.FALSE;\n" + + " case IToken.t_float :\n" + + " return Keywords.FLOAT;\n" + + " case IToken.t_for :\n" + + " return Keywords.FOR;\n" + + " case IToken.t_friend :\n" + + " return Keywords.FRIEND;\n" + + " case IToken.t_goto :\n" + + " return Keywords.GOTO;\n" + + " case IToken.t_if :\n" + + " return Keywords.IF ;\n" + + " case IToken.t_inline :\n" + + " return Keywords.INLINE ;\n" + + " case IToken.t_int :\n" + + " return Keywords.INT ;\n" + + " case IToken.t_long :\n" + + " return Keywords.LONG ;\n" + + " case IToken.t_mutable :\n" + + " return Keywords.MUTABLE ;\n" + + " case IToken.t_namespace :\n" + + " return Keywords.NAMESPACE ;\n" + + " case IToken.t_new :\n" + + " return Keywords.NEW ;\n" + + " case IToken.t_not :\n" + + " return Keywords.NOT ;\n" + + " case IToken.t_not_eq :\n" + + " return Keywords.NOT_EQ; \n" + + " case IToken.t_operator :\n" + + " return Keywords.OPERATOR ;\n" + + " case IToken.t_or :\n" + + " return Keywords.OR ;\n" + + " case IToken.t_or_eq :\n" + + " return Keywords.OR_EQ;\n" + + " case IToken.t_private :\n" + + " return Keywords.PRIVATE ;\n" + + " case IToken.t_protected :\n" + + " return Keywords.PROTECTED ;\n" + + " case IToken.t_public :\n" + + " return Keywords.PUBLIC ;\n" + + " case IToken.t_register :\n" + + " return Keywords.REGISTER ;\n" + + " case IToken.t_reinterpret_cast :\n" + + " return Keywords.REINTERPRET_CAST ;\n" + + " case IToken.t_return :\n" + + " return Keywords.RETURN ;\n" + + " case IToken.t_short :\n" + + " return Keywords.SHORT ;\n" + + " case IToken.t_sizeof :\n" + + " return Keywords.SIZEOF ;\n" + + " case IToken.t_static :\n" + + " return Keywords.STATIC ;\n" + + " case IToken.t_static_cast :\n" + + " return Keywords.STATIC_CAST ;\n" + + " case IToken.t_signed :\n" + + " return Keywords.SIGNED ;\n" + + " case IToken.t_struct :\n" + + " return Keywords.STRUCT ;\n" + + " case IToken.t_switch :\n" + + " return Keywords.SWITCH ;\n" + + " case IToken.t_template :\n" + + " return Keywords.TEMPLATE ;\n" + + " case IToken.t_this :\n" + + " return Keywords.THIS ;\n" + + " case IToken.t_throw :\n" + + " return Keywords.THROW ;\n" + + " case IToken.t_true :\n" + + " return Keywords.TRUE ;\n" + + " case IToken.t_try :\n" + + " return Keywords.TRY ;\n" + + " case IToken.t_typedef :\n" + + " return Keywords.TYPEDEF ;\n" + + " case IToken.t_typeid :\n" + + " return Keywords.TYPEID ;\n" + + " case IToken.t_typename :\n" + + " return Keywords.TYPENAME ;\n" + + " case IToken.t_union :\n" + + " return Keywords.UNION ;\n" + + " case IToken.t_unsigned :\n" + + " return Keywords.UNSIGNED ;\n" + + " case IToken.t_using :\n" + + " return Keywords.USING ;\n" + + " case IToken.t_virtual :\n" + + " return Keywords.VIRTUAL ;\n" + + " case IToken.t_void :\n" + + " return Keywords.VOID ;\n" + + " case IToken.t_volatile :\n" + + " return Keywords.VOLATILE;\n" + + " case IToken.t_wchar_t :\n" + + " return Keywords.WCHAR_T ;\n" + + " case IToken.t_while :\n" + + " return Keywords.WHILE ;\n" + + " case IToken.t_xor :\n" + + " return Keywords.XOR ;\n" + + " case IToken.t_xor_eq :\n" + + " return Keywords.XOR_EQ ;\n" + + " case IToken.t__Bool :\n" + + " return Keywords._BOOL ;\n" + + " case IToken.t__Complex :\n" + + " return Keywords._COMPLEX ;\n" + + " case IToken.t__Imaginary :\n" + + " return Keywords._IMAGINARY ;\n" + + " case IToken.t_restrict :\n" + + " return Keywords.RESTRICT ;\n" + + " case IScanner.tPOUND:\n" + + " return \"#\"; //$NON-NLS-1$\n" + + " case IScanner.tPOUNDPOUND:\n" + + " return \"##\"; //$NON-NLS-1$\n" + + " case IToken.tEOC:\n" + + " return \"EOC\"; //$NON-NLS-1$\n" + + " default :\n" + + " return \"\"; //$NON-NLS-1$ \n" + + " } \n" + + " }\n" + + " public char[] getCharImage() {\n" + + " return getCharImage( getType() );\n" + + " }\n" + + " static public char[] getCharImage( int type ){\n" + + " return null;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n" + + "}\n" + + "interface IToken {\n" + + " static public final int tIDENTIFIER = 1;\n" + + " static public final int tINTEGER = 2;\n" + + " static public final int tCOLONCOLON = 3;\n" + + " static public final int tCOLON = 4;\n" + + " static public final int tSEMI = 5;\n" + + " static public final int tCOMMA = 6;\n" + + " static public final int tQUESTION = 7;\n" + + " static public final int tLPAREN = 8;\n" + + " static public final int tRPAREN = 9;\n" + + " static public final int tLBRACKET = 10;\n" + + " static public final int tRBRACKET = 11;\n" + + " static public final int tLBRACE = 12;\n" + + " static public final int tRBRACE = 13;\n" + + " static public final int tPLUSASSIGN = 14;\n" + + " static public final int tINCR = 15;\n" + + " static public final int tPLUS = 16;\n" + + " static public final int tMINUSASSIGN = 17;\n" + + " static public final int tDECR = 18;\n" + + " static public final int tARROWSTAR = 19;\n" + + " static public final int tARROW = 20;\n" + + " static public final int tMINUS = 21;\n" + + " static public final int tSTARASSIGN = 22;\n" + + " static public final int tSTAR = 23;\n" + + " static public final int tMODASSIGN = 24;\n" + + " static public final int tMOD = 25;\n" + + " static public final int tXORASSIGN = 26;\n" + + " static public final int tXOR = 27;\n" + + " static public final int tAMPERASSIGN = 28;\n" + + " static public final int tAND = 29;\n" + + " static public final int tAMPER = 30;\n" + + " static public final int tBITORASSIGN = 31;\n" + + " static public final int tOR = 32;\n" + + " static public final int tBITOR = 33;\n" + + " static public final int tCOMPL = 34;\n" + + " static public final int tNOTEQUAL = 35;\n" + + " static public final int tNOT = 36;\n" + + " static public final int tEQUAL = 37;\n" + + " static public final int tASSIGN = 38;\n" + + " static public final int tSHIFTL = 40;\n" + + " static public final int tLTEQUAL = 41;\n" + + " static public final int tLT = 42;\n" + + " static public final int tSHIFTRASSIGN = 43;\n" + + " static public final int tSHIFTR = 44;\n" + + " static public final int tGTEQUAL = 45;\n" + + " static public final int tGT = 46;\n" + + " static public final int tSHIFTLASSIGN = 47;\n" + + " static public final int tELLIPSIS = 48;\n" + + " static public final int tDOTSTAR = 49;\n" + + " static public final int tDOT = 50;\n" + + " static public final int tDIVASSIGN = 51;\n" + + " static public final int tDIV = 52;\n" + + " static public final int t_and = 54;\n" + + " static public final int t_and_eq = 55;\n" + + " static public final int t_asm = 56;\n" + + " static public final int t_auto = 57;\n" + + " static public final int t_bitand = 58;\n" + + " static public final int t_bitor = 59;\n" + + " static public final int t_bool = 60;\n" + + " static public final int t_break = 61;\n" + + " static public final int t_case = 62;\n" + + " static public final int t_catch = 63;\n" + + " static public final int t_char = 64;\n" + + " static public final int t_class = 65;\n" + + " static public final int t_compl = 66;\n" + + " static public final int t_const = 67;\n" + + " static public final int t_const_cast = 69;\n" + + " static public final int t_continue = 70;\n" + + " static public final int t_default = 71;\n" + + " static public final int t_delete = 72;\n" + + " static public final int t_do = 73;\n" + + " static public final int t_double = 74;\n" + + " static public final int t_dynamic_cast = 75;\n" + + " static public final int t_else = 76;\n" + + " static public final int t_enum = 77;\n" + + " static public final int t_explicit = 78;\n" + + " static public final int t_export = 79;\n" + + " static public final int t_extern = 80;\n" + + " static public final int t_false = 81;\n" + + " static public final int t_float = 82;\n" + + " static public final int t_for = 83;\n" + + " static public final int t_friend = 84;\n" + + " static public final int t_goto = 85;\n" + + " static public final int t_if = 86;\n" + + " static public final int t_inline = 87;\n" + + " static public final int t_int = 88;\n" + + " static public final int t_long = 89;\n" + + " static public final int t_mutable = 90;\n" + + " static public final int t_namespace = 91;\n" + + " static public final int t_new = 92;\n" + + " static public final int t_not = 93;\n" + + " static public final int t_not_eq = 94;\n" + + " static public final int t_operator = 95;\n" + + " static public final int t_or = 96;\n" + + " static public final int t_or_eq = 97;\n" + + " static public final int t_private = 98;\n" + + " static public final int t_protected = 99;\n" + + " static public final int t_public = 100;\n" + + " static public final int t_register = 101;\n" + + " static public final int t_reinterpret_cast = 102;\n" + + " static public final int t_return = 103;\n" + + " static public final int t_short = 104;\n" + + " static public final int t_sizeof = 105;\n" + + " static public final int t_static = 106;\n" + + " static public final int t_static_cast = 107;\n" + + " static public final int t_signed = 108;\n" + + " static public final int t_struct = 109;\n" + + " static public final int t_switch = 110;\n" + + " static public final int t_template = 111;\n" + + " static public final int t_this = 112;\n" + + " static public final int t_throw = 113;\n" + + " static public final int t_true = 114;\n" + + " static public final int t_try = 115;\n" + + " static public final int t_typedef = 116;\n" + + " static public final int t_typeid = 117;\n" + + " static public final int t_typename = 118;\n" + + " static public final int t_union = 119;\n" + + " static public final int t_unsigned = 120;\n" + + " static public final int t_using = 121;\n" + + " static public final int t_virtual = 122;\n" + + " static public final int t_void = 123;\n" + + " static public final int t_volatile = 124;\n" + + " static public final int t_wchar_t = 125;\n" + + " static public final int t_while = 126;\n" + + " static public final int t_xor = 127;\n" + + " static public final int t_xor_eq = 128;\n" + + " static public final int tFLOATINGPT = 129;\n" + + " static public final int tSTRING = 130;\n" + + " static public final int tLSTRING = 131;\n" + + " static public final int tCHAR = 132;\n" + + " static public final int tLCHAR = 133;\n" + + " static public final int t__Bool = 134;\n" + + " static public final int t__Complex = 135;\n" + + " static public final int t__Imaginary = 136;\n" + + " static public final int t_restrict = 137;\n" + + " static public final int tMACROEXP = 138;\n" + + " static public final int tPOUNDPOUND = 139;\n" + + " static public final int tCOMPLETION = 140;\n" + + " static public final int tEOC = 141; // End of Completion\\n\" + \n" + + " static public final int tLAST = 141;\n" + + "}\n" + + "class Keywords {\n" + + " public static final String CAST = \"cast\"; //$NON-NLS-1$\n" + + " public static final String ALIGNOF = \"alignof\"; //$NON-NLS-1$\n" + + " public static final String TYPEOF = \"typeof\"; //$NON-NLS-1$\n" + + " public static final String cpMIN = \"?\"; //$NON-NLS-1$\n" + + " public static final String _BOOL = \"_Bool\"; //$NON-NLS-1$\n" + + " public static final String _COMPLEX = \"_Complex\"; //$NON-NLS-1$\n" + + " public static final String _IMAGINARY = \"_Imaginary\"; //$NON-NLS-1$\n" + + " public static final String AND = \"and\"; //$NON-NLS-1$\n" + + " public static final String AND_EQ = \"and_eq\"; //$NON-NLS-1$\n" + + " public static final String ASM = \"asm\"; //$NON-NLS-1$\n" + + " public static final String AUTO = \"auto\"; //$NON-NLS-1$\n" + + " public static final String BITAND = \"bitand\"; //$NON-NLS-1$\n" + + " public static final String BITOR = \"bitor\"; //$NON-NLS-1$\n" + + " public static final String BOOL = \"bool\"; //$NON-NLS-1$\n" + + " public static final String BREAK = \"break\"; //$NON-NLS-1$\n" + + " public static final String CASE = \"case\"; //$NON-NLS-1$\n" + + " public static final String CATCH = \"catch\"; //$NON-NLS-1$\n" + + " public static final String CHAR = \"char\"; //$NON-NLS-1$\n" + + " public static final String CLASS = \"class\"; //$NON-NLS-1$\n" + + " public static final String COMPL = \"compl\"; //$NON-NLS-1$\n" + + " public static final String CONST = \"const\"; //$NON-NLS-1$\n" + + " public static final String CONST_CAST = \"const_cast\"; //$NON-NLS-1$\n" + + " public static final String CONTINUE = \"continue\"; //$NON-NLS-1$\n" + + " public static final String DEFAULT = \"default\"; //$NON-NLS-1$\n" + + " public static final String DELETE = \"delete\"; //$NON-NLS-1$\n" + + " public static final String DO = \"do\"; //$NON-NLS-1$\n" + + " public static final String DOUBLE = \"double\"; //$NON-NLS-1$\n" + + " public static final String DYNAMIC_CAST = \"dynamic_cast\"; //$NON-NLS-1$\n" + + " public static final String ELSE = \"else\"; //$NON-NLS-1$\n" + + " public static final String ENUM = \"enum\"; //$NON-NLS-1$\n" + + " public static final String EXPLICIT = \"explicit\"; //$NON-NLS-1$\n" + + " public static final String EXPORT = \"export\"; //$NON-NLS-1$\n" + + " public static final String EXTERN = \"extern\"; //$NON-NLS-1$\n" + + " public static final String FALSE = \"false\"; //$NON-NLS-1$\n" + + " public static final String FLOAT = \"float\"; //$NON-NLS-1$\n" + + " public static final String FOR = \"for\"; //$NON-NLS-1$\n" + + " public static final String FRIEND = \"friend\"; //$NON-NLS-1$\n" + + " public static final String GOTO = \"goto\"; //$NON-NLS-1$\n" + + " public static final String IF = \"if\"; //$NON-NLS-1$\n" + + " public static final String INLINE = \"inline\"; //$NON-NLS-1$\n" + + " public static final String INT = \"int\"; //$NON-NLS-1$\n" + + " public static final String LONG = \"long\"; //$NON-NLS-1$\n" + + " public static final String LONG_LONG = \"long long\"; //$NON-NLS-1$\n" + + " public static final String MUTABLE = \"mutable\"; //$NON-NLS-1$\n" + + " public static final String NAMESPACE = \"namespace\"; //$NON-NLS-1$\n" + + " public static final String NEW = \"new\"; //$NON-NLS-1$\n" + + " public static final String NOT = \"not\"; //$NON-NLS-1$\n" + + " public static final String NOT_EQ = \"not_eq\"; //$NON-NLS-1$\n" + + " public static final String OPERATOR = \"operator\"; //$NON-NLS-1$\n" + + " public static final String OR = \"or\"; //$NON-NLS-1$\n" + + " public static final String OR_EQ = \"or_eq\"; //$NON-NLS-1$\n" + + " public static final String PRIVATE = \"private\"; //$NON-NLS-1$\n" + + " public static final String PROTECTED = \"protected\"; //$NON-NLS-1$\n" + + " public static final String PUBLIC = \"public\"; //$NON-NLS-1$\n" + + " public static final String REGISTER = \"register\"; //$NON-NLS-1$\n" + + " public static final String REINTERPRET_CAST = \"reinterpret_cast\"; //$NON-NLS-1$\n" + + " public static final String RESTRICT = \"restrict\"; //$NON-NLS-1$\n" + + " public static final String RETURN = \"return\"; //$NON-NLS-1$\n" + + " public static final String SHORT = \"short\"; //$NON-NLS-1$\n" + + " public static final String SIGNED = \"signed\"; //$NON-NLS-1$\n" + + " public static final String SIZEOF = \"sizeof\"; //$NON-NLS-1$\n" + + " public static final String STATIC = \"static\"; //$NON-NLS-1$\n" + + " public static final String STATIC_CAST = \"static_cast\"; //$NON-NLS-1$\n" + + " public static final String STRUCT = \"struct\"; //$NON-NLS-1$\n" + + " public static final String SWITCH = \"switch\"; //$NON-NLS-1$\n" + + " public static final String TEMPLATE = \"template\"; //$NON-NLS-1$\n" + + " public static final String THIS = \"this\"; //$NON-NLS-1$\n" + + " public static final String THROW = \"throw\"; //$NON-NLS-1$\n" + + " public static final String TRUE = \"true\"; //$NON-NLS-1$\n" + + " public static final String TRY = \"try\"; //$NON-NLS-1$\n" + + " public static final String TYPEDEF = \"typedef\"; //$NON-NLS-1$\n" + + " public static final String TYPEID = \"typeid\"; //$NON-NLS-1$\n" + + " public static final String TYPENAME = \"typename\"; //$NON-NLS-1$\n" + + " public static final String UNION = \"union\"; //$NON-NLS-1$\n" + + " public static final String UNSIGNED = \"unsigned\"; //$NON-NLS-1$\n" + + " public static final String USING = \"using\"; //$NON-NLS-1$\n" + + " public static final String VIRTUAL = \"virtual\"; //$NON-NLS-1$\n" + + " public static final String VOID = \"void\"; //$NON-NLS-1$\n" + + " public static final String VOLATILE = \"volatile\"; //$NON-NLS-1$\n" + + " public static final String WCHAR_T = \"wchar_t\"; //$NON-NLS-1$\n" + + " public static final String WHILE = \"while\"; //$NON-NLS-1$\n" + + " public static final String XOR = \"xor\"; //$NON-NLS-1$\n" + + " public static final String XOR_EQ = \"xor_eq\"; //$NON-NLS-1$\n" + + " public static final char[] c_BOOL = \"_Bool\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] c_COMPLEX = \"_Complex\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] c_IMAGINARY = \"_Imaginary\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cAND = \"and\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cAND_EQ = \"and_eq\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cASM = \"asm\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cAUTO = \"auto\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cBITAND = \"bitand\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cBITOR = \"bitor\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cBOOL = \"bool\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cBREAK = \"break\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cCASE = \"case\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cCATCH = \"catch\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cCHAR = \"char\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cCLASS = \"class\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cCOMPL = \"compl\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cCONST = \"const\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cCONST_CAST = \"const_cast\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cCONTINUE = \"continue\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cDEFAULT = \"default\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cDELETE = \"delete\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cDO = \"do\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cDOUBLE = \"double\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cDYNAMIC_CAST = \"dynamic_cast\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cELSE = \"else\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cENUM = \"enum\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cEXPLICIT = \"explicit\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cEXPORT = \"export\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cEXTERN = \"extern\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cFALSE = \"false\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cFLOAT = \"float\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cFOR = \"for\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cFRIEND = \"friend\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cGOTO = \"goto\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cIF = \"if\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cINLINE = \"inline\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cINT = \"int\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cLONG = \"long\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cMUTABLE = \"mutable\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cNAMESPACE = \"namespace\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cNEW = \"new\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cNOT = \"not\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cNOT_EQ = \"not_eq\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cOPERATOR = \"operator\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cOR = \"or\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cOR_EQ = \"or_eq\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cPRIVATE = \"private\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cPROTECTED = \"protected\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cPUBLIC = \"public\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cREGISTER = \"register\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cREINTERPRET_CAST = \"reinterpret_cast\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cRESTRICT = \"restrict\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cRETURN = \"return\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cSHORT = \"short\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cSIGNED = \"signed\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cSIZEOF = \"sizeof\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cSTATIC = \"static\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cSTATIC_CAST = \"static_cast\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cSTRUCT = \"struct\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cSWITCH = \"switch\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cTEMPLATE = \"template\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cTHIS = \"this\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cTHROW = \"throw\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cTRUE = \"true\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cTRY = \"try\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cTYPEDEF = \"typedef\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cTYPEID = \"typeid\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cTYPENAME = \"typename\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cUNION = \"union\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cUNSIGNED = \"unsigned\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cUSING = \"using\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cVIRTUAL = \"virtual\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cVOID = \"void\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cVOLATILE = \"volatile\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cWCHAR_T = \"wchar_t\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cWHILE = \"while\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cXOR = \"xor\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cXOR_EQ = \"xor_eq\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpCOLONCOLON = \"::\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpCOLON = \":\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpSEMI = \";\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpCOMMA = \",\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpQUESTION = \"?\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpLPAREN = \"(\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpRPAREN = \")\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpLBRACKET = \"[\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpRBRACKET = \"]\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpLBRACE = \"{\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpRBRACE = \"}\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpPLUSASSIGN = \"+=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpINCR = \"++\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpPLUS = \"+\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpMINUSASSIGN = \"-=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpDECR = \"--\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpARROWSTAR = \"->*\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpARROW = \"->\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpMINUS = \"-\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpSTARASSIGN = \"*=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpSTAR = \"*\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpMODASSIGN = \"%=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpMOD = \"%\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpXORASSIGN = \"^=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpXOR = \"^\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpAMPERASSIGN = \"&=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpAND = \"&&\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpAMPER = \"&\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpBITORASSIGN = \"|=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpOR = \"||\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpBITOR = \"|\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpCOMPL = \"~\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpNOTEQUAL = \"!=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpNOT = \"!\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpEQUAL = \"==\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpASSIGN =\"=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpSHIFTL = \"<<\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpLTEQUAL = \"<=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpLT = \"<\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpSHIFTRASSIGN = \">>=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpSHIFTR = \">>\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpGTEQUAL = \">=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpGT = \">\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpSHIFTLASSIGN = \"<<=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpELLIPSIS = \"...\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpDOTSTAR = \".*\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpDOT = \".\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpDIVASSIGN = \"/=\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpDIV = \"/\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpPOUND = \"#\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cpPOUNDPOUND = \"##\".toCharArray(); //$NON-NLS-1$\n" + + " // preprocessor keywords\\n\" + \n" + + " public static final char[] cIFDEF = \"ifdef\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cIFNDEF = \"ifndef\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cELIF = \"elif\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cENDIF = \"endif\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cINCLUDE = \"include\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cDEFINE = \"define\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cUNDEF = \"undef\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cERROR = \"error\".toCharArray(); //$NON-NLS-1$\n" + + " public static final char[] cINCLUDE_NEXT = \"include_next\".toCharArray(); //$NON-NLS-1$\n" + + "}\n" + + "interface IScanner {\n" + + " public static final int tPOUNDPOUND = -6;\n" + + " public static final int tPOUND = -7;\n" + + "}\n" + + "abstract class B {\n" + + " public B( int type, char [] filename, int lineNumber ) {\n" + + " }\n" + + " public int getType() { return 0; }\n" + + "}", + }, + "SUCCESS", + null, + true, + null, + options, + null); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126744 +public void test009() { + runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public static String CONSTANT = \n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n" + + " \"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy12\";\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.print(CONSTANT == CONSTANT);\n" + + " }\n" + + "}" + }, + null, + "true", + null, + JavacTestOptions.EclipseJustification.EclipseBug126744); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// Failed before using a non recursive implementation of deep binary +// expressions. +public void test010() { + StringBuilder sourceCode = new StringBuilder( + "public class X {\n" + + " void foo(String a, String b, String c, String d, String e) {\n" + + " String s = \n"); + for (int i = 0; i < 350; i++) { + sourceCode.append( + " \"abcdef\" + a + b + c + d + e + " + + "\" ghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmno" + + "pqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n"); + } + sourceCode.append( + " \"abcdef\" + a + b + c + d + e + \" ghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxy12\";\n" + + " }\n" + + "}"); + this.runConformTest( + true, + new String[] { + "X.java", + sourceCode.toString() + }, + null, + "", + null, + JavacTestOptions.JavacHasABug.JavacThrowsAnException /* stack overflow */); // transient, platform-dependent +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// check if we hit the 64Kb limit on method code lenth in class files before +// filling the stack +// need to use a computed string (else this source file will get blown away +// as well) +public void test011() { + int length = 3 * 54 * 1000; + // the longer the slower, but still needs to reach the limit... + StringBuilder veryLongString = new StringBuilder(length + 20); + veryLongString.append('"'); + Random random = new Random(); + while (veryLongString.length() < length) { + veryLongString.append("\"+a+\""); + veryLongString.append(random.nextLong()); + } + veryLongString.append('"'); + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " void foo(String a, String b, String c, String d, String e) {\n" + + " String s = \n" + + veryLongString.toString() + + " + \"abcdef\" + a + b + c + d + e + \" ghiABCDEFGHIJKLMNOPQRSTUVWXYZjklmnopqrstuvwxyzabcdefghiABCDEFGHIJKLMNOPQRSTUVWXYZjklmnopqrstuvwxyzabcdefghiABCDEFGHIJKLMNOPQRSTUVWXYZjklmnopqrstuvwxyzabcdefghiABCDEFGHIJKLMNOPQRSTUVWXYZjklmnopqrstuvwxy12\";\n" + + " }\n" + + "}" + }, + "----------\n" + + "1. ERROR in X.java (at line 2)\n" + + " void foo(String a, String b, String c, String d, String e) {\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The code of method foo(String, String, String, String, String) is " + + "exceeding the 65535 bytes limit\n" + + "----------\n"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +// variant: right member of the topmost expression is left-deep +public void test012() { + StringBuilder sourceCode = new StringBuilder( + "public class X {\n" + + " void foo(String a, String b, String c, String d, String e) {\n" + + " String s = a + (\n"); + for (int i = 0; i < 1000; i++) { + sourceCode.append( + " \"abcdef\" + a + b + c + d + e + " + + "\" ghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmno" + + "pqrstuvwxyzabcdefghijklmnopqrstuvwxyz\" +\n"); + } + sourceCode.append( + " \"abcdef\" + a + b + c + d + e + \" ghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + + "abcdefghijklmnopqrstuvwxy12\");\n" + + " }\n" + + "}"); + this.runConformTest( + true, + new String[] { + "X.java", + sourceCode.toString() + }, + null, + "", + null, + JavacTestOptions.JavacHasABug.JavacThrowsAnException /* stack overflow */); // transient, platform-dependent +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=102728 +//variant: right member of the topmost expression is left-deep +public void test013() { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + "\n" + + " // left to right marker\n" + + " protected static char LRM = \'\\u200e\';\n" + + " // left to right embedding\n" + + " protected static char LRE = \'\\u202a\';\n" + + " // pop directional format \n" + + " protected static char PDF = \'\\u202c\';\n" + + "\n" + + " private static String PATH_1_RESULT = LRE + \"d\" + PDF + \":\" + LRM + \"\\\\\" + LRM + LRE + \"test\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05d0\\u05d1\\u05d2\\u05d3 \\u05d4\\u05d5\" + PDF + \"\\\\\" + LRM + LRE + \"segment\" + PDF;\n" + + " private static String PATH_2_RESULT = LRM + \"\\\\\" + LRM + LRE + \"test\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05d0\\u05d1\\u05d2\\u05d3 \\u05d4\\u05d5\" + PDF + \"\\\\\" + LRM + LRE + \"segment\" + PDF;\n" + + " private static String PATH_3_RESULT = LRE + \"d\" + PDF + \":\" + LRM + \"\\\\\" + LRM + LRE + \"\\u05ea\\u05e9\\u05e8\\u05e7\\u05e6 abcdef-\\u05e5\\u05e4\\u05e3\" + PDF + \"\\\\\" + LRM + LRE + \"xyz\" + PDF + \"\\\\\" + LRM + LRE + \"abcdef\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05e2\\u05e1\\u05e0\" + PDF;\n" + + " private static String PATH_4_RESULT = LRM + \"\\\\\" + LRM + LRE + \"\\u05ea\\u05e9\\u05e8\\u05e7\\u05e6 abcdef-\\u05e5\\u05e4\\u05e3\" + PDF + \"\\\\\" + LRM + LRE + \"xyz\" + PDF + \"\\\\\" + LRM + LRE + \"abcdef\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05e2\\u05e1\\05e0\" + PDF;\n" + + " private static String PATH_5_RESULT = LRE + \"d\" + PDF + \":\" + LRM + \"\\\\\" + LRM + LRE + \"\\u05ea\\u05e9\\u05e8\\u05e7\\u05e6 abcdef-\\u05e5\\u05e4\\u05e3\" + PDF + \"\\\\\" + LRM + LRE + \"xyz\" + PDF + \"\\\\\" + LRM + LRE + \"abcdef\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05e2\\u05e1\\05e0\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05df\\u05fd\\u05dd\" + PDF + \".\" + LRM + LRE + \"java\" + PDF;\n" + + " private static String PATH_6_RESULT = LRE + \"d\" + PDF + \":\" + LRM + \"\\\\\" + LRM + LRE + \"\\u05ea\\u05e9\\u05e8\\u05e7\\u05e6 abcdef-\\u05e5\\u05e4\\u05e3\" + PDF + \"\\\\\" + LRM + LRE + \"xyz\" + PDF + \"\\\\\" + LRM + LRE + \"abcdef\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05e2\\u05e1\\05e0\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05df\\u05fd\\u05dd\" + PDF + \".\" + LRM + LRE + \"\\u05dc\\u05db\\u05da\" + PDF;\n" + + " private static String PATH_7_RESULT = LRE + \"d\" + PDF + \":\" + LRM + \"\\\\\" + LRM + LRE + \"\\u05ea\\u05e9\\u05e8\\u05e7\\u05e6 abcdef-\\u05e5\\u05e4\\u05e3\" + PDF + \"\\\\\" + LRM + LRE + \"xyz\" + PDF + \"\\\\\" + LRM + LRE + \"abcdef\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05e2\\u05e1\\05e0\" + PDF + \"\\\\\" + LRM + LRE + \"Test\" + PDF + \".\" + LRM + LRE + \"java\" + PDF;\n" + + " private static String PATH_8_RESULT = LRM + \"\\\\\" + LRM + LRE + \"test\" + PDF + \"\\\\\" + LRM + LRE + \"jkl\\u05d0\\u05d1\\u05d2\\u05d3 \\u05d4\\u05d5\" + PDF + \"\\\\\" + LRM + LRE + \"segment\" + PDF;\n" + + " private static String PATH_9_RESULT = LRM + \"\\\\\" + LRM + LRE + \"test\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05d0\\u05d1\\u05d2\\u05d3 \\u05d4\\u05d5jkl\" + PDF + \"\\\\\" + LRM + LRE + \"segment\" + PDF;\n" + + " private static String PATH_10_RESULT = LRE + \"d\" + PDF + \":\" + LRM + \"\\\\\" + LRM + LRE + \"t\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05d0\" + PDF + \"\\\\\" + LRM + LRE + \"segment\" + PDF;\n" + + " private static String PATH_11_RESULT = \"\\\\\" + LRM + LRE + \"t\" + PDF + \"\\\\\" + LRM + LRE + \"\\u05d0\" + PDF + \"\\\\\" + LRM + LRE + \"segment\" + PDF;\n" + + " private static String PATH_12_RESULT = LRE + \"d\" + PDF + \":\" + LRM + \"\\\\\" + LRM;\n" + + " private static String PATH_13_RESULT = LRM + \"\\\\\" + LRM + LRE + \"test\" + PDF;\n" + + "\n" + + " private static String OTHER_STRING_NO_DELIM = \"\\u05ea\\u05e9\\u05e8\\u05e7\\u05e6 abcdef-\\u05e5\\u05e4\\u05e3\";\n" + + "\n" + + " private static String OTHER_STRING_1_RESULT = LRM + \"*\" + LRM + \".\" + LRM + LRE + \"java\" + PDF;\n" + + " private static String OTHER_STRING_2_RESULT = LRM + \"*\" + LRM + \".\" + LRM + LRE + \"\\u05d0\\u05d1\\u05d2\" + PDF;\n" + + " private static String OTHER_STRING_3_RESULT = LRE + \"\\u05d0\\u05d1\\u05d2 \" + PDF + \"=\" + LRM + LRE + \" \\u05ea\\u05e9\\u05e8\\u05e7\\u05e6\" + PDF;\n" + + " // result strings if null delimiter is passed for *. texts\n" + + " private static String OTHER_STRING_1_ND_RESULT = LRE + \"*\" + PDF + \".\" + LRM + LRE + \"java\" + PDF;\n" + + " private static String OTHER_STRING_2_ND_RESULT = LRE + \"*\" + PDF + \".\" + LRM + LRE + \"\\u05d0\\u05d1\\u05d2\" + PDF;\n" + + "\n" + + " private static String[] RESULT_DEFAULT_PATHS = {PATH_1_RESULT, PATH_2_RESULT, PATH_3_RESULT, PATH_4_RESULT, PATH_5_RESULT, PATH_6_RESULT, PATH_7_RESULT, PATH_8_RESULT, PATH_9_RESULT, PATH_10_RESULT, PATH_11_RESULT, PATH_12_RESULT, PATH_13_RESULT};\n" + + "\n" + + " private static String[] RESULT_STAR_PATHS = {OTHER_STRING_1_RESULT, OTHER_STRING_2_RESULT};\n" + + " private static String[] RESULT_EQUALS_PATHS = {OTHER_STRING_3_RESULT};\n" + + " private static String[] RESULT_STAR_PATHS_ND = {OTHER_STRING_1_ND_RESULT, OTHER_STRING_2_ND_RESULT};\n" + + "\n" + + " /**\n" + + " * Constructor.\n" + + " * \n" + + " * @param name test name\n" + + " */\n" + + " public X(String name) {\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " System.out.print(\"SUCCESS\");\n" + + " }\n" + + "}\n" + }, + "SUCCESS"); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=124099 +// Undue partial reset of receiver in +// UnconditionalFlowInfo#addInitializationsFrom. +public void test014() { + this.runConformTest(new String[] { + "X.java", + "class X {\n" + + " int i01, i02, i03, i04, i05, i06, i07, i08, i09,\n" + + " i10, i11, i12, i13, i14, i15, i16, i17, i18, i19,\n" + + " i20, i21, i22, i23, i24, i25, i26, i27, i28, i29,\n" + + " i30, i31, i32, i33, i34, i35, i36, i37, i38, i39,\n" + + " i40, i41, i42, i43, i44, i45, i46, i47, i48, i49,\n" + + " i50, i51, i52, i53, i54, i55, i56, i57, i58, i59,\n" + + " i60, i61, i62, i63, i64, i65 = 1;\n" + + "public X() {\n" + + " new Object() {\n" + + " int \n" + + " k01, k02, k03, k04, k05, k06, k07, k08, k09,\n" + + " k10, k11, k12, k13, k14, k15, k16, k17, k18, k19,\n" + + " k20, k21, k22, k23, k24, k25, k26, k27, k28, k29,\n" + + " k30, k31, k32, k33, k34, k35, k36, k37, k38, k39,\n" + + " k40, k41, k42, k43, k44, k45, k46, k47, k48, k49,\n" + + " k50, k51, k52, k53, k54, k55, k56, k57, k58, k59,\n" + + " k60, k61, k62, k63, k64;\n" + + " int \n" + + " k101, k102, k103, k104, k105, k106, k107, k108, k109,\n" + + " k110, k111, k112, k113, k114, k115, k116, k117, k118, k119,\n" + + " k120, k121, k122, k123, k124, k125, k126, k127, k128, k129,\n" + + " k130, k131, k132, k133, k134, k135, k136, k137, k138, k139,\n" + + " k140, k141, k142, k143, k144, k145, k146, k147, k148, k149,\n" + + " k150, k151, k152, k153, k154, k155, k156, k157, k158, k159,\n" + + " k160, k161, k162, k163, k164;\n" + + " final int l = 1;\n" + + " public int hashCode() {\n" + + " return\n" + + " k01 + k02 + k03 + k04 + k05 + k06 + k07 + k08 + k09 +\n" + + " k10 + k11 + k12 + k13 + k14 + k15 + k16 + k17 + k18 + k19 +\n" + + " k20 + k21 + k22 + k23 + k24 + k25 + k26 + k27 + k28 + k29 +\n" + + " k30 + k31 + k32 + k33 + k34 + k35 + k36 + k37 + k38 + k39 +\n" + + " k40 + k41 + k42 + k43 + k44 + k45 + k46 + k47 + k48 + k49 +\n" + + " k50 + k51 + k52 + k53 + k54 + k55 + k56 + k57 + k58 + k59 +\n" + + " k60 + k61 + k62 + k63 + k64 +\n" + + " k101 + k102 + k103 + k104 + k105 + k106 + k107 + k108 + k109 +\n" + + " k110 + k111 + k112 + k113 + k114 + k115 + k116 + k117 + k118 + k119 +\n" + + " k120 + k121 + k122 + k123 + k124 + k125 + k126 + k127 + k128 + k129 +\n" + + " k130 + k131 + k132 + k133 + k134 + k135 + k136 + k137 + k138 + k139 +\n" + + " k140 + k141 + k142 + k143 + k144 + k145 + k146 + k147 + k148 + k149 +\n" + + " k150 + k151 + k152 + k153 + k154 + k155 + k156 + k157 + k158 + k159 +\n" + + " k160 + k161 + k162 + k163 + k164 +\n" + + " l;\n" + + " }\n" + + " };\n" + + "}\n" + + "\n" + + "}\n" + + "\n", + }, + ""); +} +public void test015() { + Map settings = getCompilerOptions(); + settings.put(CompilerOptions.OPTION_ShareCommonFinallyBlocks, CompilerOptions.ENABLED); + runConformTest( + true, + new String[] { + "X.java", + "public class X {\n" + + " public static int foo(int i) {\n" + + " try {\n" + + " switch(i) {\n" + + " case 0 :\n" + + " return 3;\n" + + " case 1 :\n" + + " return 3;\n" + + " case 2 :\n" + + " return 3;\n" + + " case 3 :\n" + + " return 3;\n" + + " case 4 :\n" + + " return 3;\n" + + " case 5 :\n" + + " return 3;\n" + + " case 6 :\n" + + " return 3;\n" + + " case 7 :\n" + + " return 3;\n" + + " case 8 :\n" + + " return 3;\n" + + " case 9 :\n" + + " return 3;\n" + + " case 10 :\n" + + " return 3;\n" + + " case 11 :\n" + + " return 3;\n" + + " case 12 :\n" + + " return 3;\n" + + " case 13 :\n" + + " return 3;\n" + + " case 14 :\n" + + " return 3;\n" + + " case 15 :\n" + + " return 3;\n" + + " case 16 :\n" + + " return 3;\n" + + " case 17 :\n" + + " return 3;\n" + + " case 18 :\n" + + " return 3;\n" + + " case 19 :\n" + + " return 3;\n" + + " case 20 :\n" + + " return 3;\n" + + " case 21 :\n" + + " return 3;\n" + + " case 22 :\n" + + " return 3;\n" + + " case 23 :\n" + + " return 3;\n" + + " case 24 :\n" + + " return 3;\n" + + " case 25 :\n" + + " return 3;\n" + + " case 26 :\n" + + " return 3;\n" + + " case 27 :\n" + + " return 3;\n" + + " case 28 :\n" + + " return 3;\n" + + " case 29 :\n" + + " return 3;\n" + + " case 30 :\n" + + " return 3;\n" + + " case 31 :\n" + + " return 3;\n" + + " case 32 :\n" + + " return 3;\n" + + " case 33 :\n" + + " return 3;\n" + + " case 34 :\n" + + " return 3;\n" + + " case 35 :\n" + + " return 3;\n" + + " case 36 :\n" + + " return 3;\n" + + " case 37 :\n" + + " return 3;\n" + + " case 38 :\n" + + " return 3;\n" + + " case 39 :\n" + + " return 3;\n" + + " case 40 :\n" + + " return 3;\n" + + " case 41 :\n" + + " return 3;\n" + + " case 42 :\n" + + " return 3;\n" + + " case 43 :\n" + + " return 3;\n" + + " case 44 :\n" + + " return 3;\n" + + " case 45 :\n" + + " return 3;\n" + + " case 46 :\n" + + " return 3;\n" + + " case 47 :\n" + + " return 3;\n" + + " case 48 :\n" + + " return 3;\n" + + " case 49 :\n" + + " return 3;\n" + + " case 50 :\n" + + " return 3;\n" + + " case 51 :\n" + + " return 3;\n" + + " case 52 :\n" + + " return 3;\n" + + " case 53 :\n" + + " return 3;\n" + + " case 54 :\n" + + " return 3;\n" + + " case 55 :\n" + + " return 3;\n" + + " case 56 :\n" + + " return 3;\n" + + " case 57 :\n" + + " return 3;\n" + + " case 58 :\n" + + " return 3;\n" + + " case 59 :\n" + + " return 3;\n" + + " case 60 :\n" + + " return 3;\n" + + " case 61 :\n" + + " return 3;\n" + + " case 62 :\n" + + " return 3;\n" + + " case 63 :\n" + + " return 3;\n" + + " case 64 :\n" + + " return 3;\n" + + " case 65 :\n" + + " return 3;\n" + + " case 66 :\n" + + " return 3;\n" + + " case 67 :\n" + + " return 3;\n" + + " case 68 :\n" + + " return 3;\n" + + " case 69 :\n" + + " return 3;\n" + + " case 70 :\n" + + " return 3;\n" + + " case 71 :\n" + + " return 3;\n" + + " case 72 :\n" + + " return 3;\n" + + " case 73 :\n" + + " return 3;\n" + + " case 74 :\n" + + " return 3;\n" + + " case 75 :\n" + + " return 3;\n" + + " case 76 :\n" + + " return 3;\n" + + " case 77 :\n" + + " return 3;\n" + + " case 78 :\n" + + " return 3;\n" + + " case 79 :\n" + + " return 3;\n" + + " case 80 :\n" + + " return 3;\n" + + " case 81 :\n" + + " return 3;\n" + + " case 82 :\n" + + " return 3;\n" + + " case 83 :\n" + + " return 3;\n" + + " case 84 :\n" + + " return 3;\n" + + " case 85 :\n" + + " return 3;\n" + + " case 86 :\n" + + " return 3;\n" + + " case 87 :\n" + + " return 3;\n" + + " case 88 :\n" + + " return 3;\n" + + " case 89 :\n" + + " return 3;\n" + + " case 90 :\n" + + " return 3;\n" + + " case 91 :\n" + + " return 3;\n" + + " case 92 :\n" + + " return 3;\n" + + " case 93 :\n" + + " return 3;\n" + + " case 94 :\n" + + " return 3;\n" + + " case 95 :\n" + + " return 3;\n" + + " case 96 :\n" + + " return 3;\n" + + " case 97 :\n" + + " return 3;\n" + + " case 98 :\n" + + " return 3;\n" + + " case 99 :\n" + + " return 3;\n" + + " case 100 :\n" + + " return 3;\n" + + " case 101 :\n" + + " return 3;\n" + + " case 102 :\n" + + " return 3;\n" + + " case 103 :\n" + + " return 3;\n" + + " case 104 :\n" + + " return 3;\n" + + " case 105 :\n" + + " return 3;\n" + + " case 106 :\n" + + " return 3;\n" + + " case 107 :\n" + + " return 3;\n" + + " case 108 :\n" + + " return 3;\n" + + " case 109 :\n" + + " return 3;\n" + + " case 110 :\n" + + " return 3;\n" + + " case 111 :\n" + + " return 3;\n" + + " case 112 :\n" + + " return 3;\n" + + " case 113 :\n" + + " return 3;\n" + + " case 114 :\n" + + " return 3;\n" + + " case 115 :\n" + + " return 3;\n" + + " case 116 :\n" + + " return 3;\n" + + " case 117 :\n" + + " return 3;\n" + + " case 118 :\n" + + " return 3;\n" + + " case 119 :\n" + + " return 3;\n" + + " case 120 :\n" + + " return 3;\n" + + " case 121 :\n" + + " return 3;\n" + + " case 122 :\n" + + " return 3;\n" + + " case 123 :\n" + + " return 3;\n" + + " case 124 :\n" + + " return 3;\n" + + " case 125 :\n" + + " return 3;\n" + + " case 126 :\n" + + " return 3;\n" + + " case 127 :\n" + + " return 3;\n" + + " case 128 :\n" + + " return 3;\n" + + " case 129 :\n" + + " return 3;\n" + + " case 130 :\n" + + " return 3;\n" + + " case 131 :\n" + + " return 3;\n" + + " case 132 :\n" + + " return 3;\n" + + " case 133 :\n" + + " return 3;\n" + + " case 134 :\n" + + " return 3;\n" + + " case 135 :\n" + + " return 3;\n" + + " case 136 :\n" + + " return 3;\n" + + " case 137 :\n" + + " return 3;\n" + + " case 138 :\n" + + " return 3;\n" + + " case 139 :\n" + + " return 3;\n" + + " case 140 :\n" + + " return 3;\n" + + " case 141 :\n" + + " return 3;\n" + + " case 142 :\n" + + " return 3;\n" + + " case 143 :\n" + + " return 3;\n" + + " case 144 :\n" + + " return 3;\n" + + " case 145 :\n" + + " return 3;\n" + + " case 146 :\n" + + " return 3;\n" + + " case 147 :\n" + + " return 3;\n" + + " case 148 :\n" + + " return 3;\n" + + " case 149 :\n" + + " return 3;\n" + + " case 150 :\n" + + " return 3;\n" + + " case 151 :\n" + + " return 3;\n" + + " case 152 :\n" + + " return 3;\n" + + " case 153 :\n" + + " return 3;\n" + + " case 154 :\n" + + " return 3;\n" + + " case 155 :\n" + + " return 3;\n" + + " case 156 :\n" + + " return 3;\n" + + " case 157 :\n" + + " return 3;\n" + + " case 158 :\n" + + " return 3;\n" + + " case 159 :\n" + + " return 3;\n" + + " case 160 :\n" + + " return 3;\n" + + " case 161 :\n" + + " return 3;\n" + + " case 162 :\n" + + " return 3;\n" + + " case 163 :\n" + + " return 3;\n" + + " case 164 :\n" + + " return 3;\n" + + " case 165 :\n" + + " return 3;\n" + + " case 166 :\n" + + " return 3;\n" + + " case 167 :\n" + + " return 3;\n" + + " case 168 :\n" + + " return 3;\n" + + " case 169 :\n" + + " return 3;\n" + + " case 170 :\n" + + " return 3;\n" + + " case 171 :\n" + + " return 3;\n" + + " case 172 :\n" + + " return 3;\n" + + " case 173 :\n" + + " return 3;\n" + + " case 174 :\n" + + " return 3;\n" + + " case 175 :\n" + + " return 3;\n" + + " case 176 :\n" + + " return 3;\n" + + " case 177 :\n" + + " return 3;\n" + + " case 178 :\n" + + " return 3;\n" + + " case 179 :\n" + + " return 3;\n" + + " case 180 :\n" + + " return 3;\n" + + " case 181 :\n" + + " return 3;\n" + + " case 182 :\n" + + " return 3;\n" + + " case 183 :\n" + + " return 3;\n" + + " case 184 :\n" + + " return 3;\n" + + " case 185 :\n" + + " return 3;\n" + + " case 186 :\n" + + " return 3;\n" + + " case 187 :\n" + + " return 3;\n" + + " case 188 :\n" + + " return 3;\n" + + " case 189 :\n" + + " return 3;\n" + + " case 190 :\n" + + " return 3;\n" + + " case 191 :\n" + + " return 3;\n" + + " case 192 :\n" + + " return 3;\n" + + " case 193 :\n" + + " return 3;\n" + + " case 194 :\n" + + " return 3;\n" + + " case 195 :\n" + + " return 3;\n" + + " case 196 :\n" + + " return 3;\n" + + " case 197 :\n" + + " return 3;\n" + + " case 198 :\n" + + " return 3;\n" + + " case 199 :\n" + + " return 3;\n" + + " case 200 :\n" + + " return 3;\n" + + " case 201 :\n" + + " return 3;\n" + + " case 202 :\n" + + " return 3;\n" + + " case 203 :\n" + + " return 3;\n" + + " case 204 :\n" + + " return 3;\n" + + " case 205 :\n" + + " return 3;\n" + + " case 206 :\n" + + " return 3;\n" + + " case 207 :\n" + + " return 3;\n" + + " case 208 :\n" + + " return 3;\n" + + " case 209 :\n" + + " return 3;\n" + + " case 210 :\n" + + " return 3;\n" + + " case 211 :\n" + + " return 3;\n" + + " case 212 :\n" + + " return 3;\n" + + " case 213 :\n" + + " return 3;\n" + + " case 214 :\n" + + " return 3;\n" + + " case 215 :\n" + + " return 3;\n" + + " case 216 :\n" + + " return 3;\n" + + " case 217 :\n" + + " return 3;\n" + + " case 218 :\n" + + " return 3;\n" + + " case 219 :\n" + + " return 3;\n" + + " case 220 :\n" + + " return 3;\n" + + " case 221 :\n" + + " return 3;\n" + + " case 222 :\n" + + " return 3;\n" + + " case 223 :\n" + + " return 3;\n" + + " case 224 :\n" + + " return 3;\n" + + " case 225 :\n" + + " return 3;\n" + + " case 226 :\n" + + " return 3;\n" + + " case 227 :\n" + + " return 3;\n" + + " case 228 :\n" + + " return 3;\n" + + " case 229 :\n" + + " return 3;\n" + + " case 230 :\n" + + " return 3;\n" + + " case 231 :\n" + + " return 3;\n" + + " case 232 :\n" + + " return 3;\n" + + " case 233 :\n" + + " return 3;\n" + + " case 234 :\n" + + " return 3;\n" + + " case 235 :\n" + + " return 3;\n" + + " case 236 :\n" + + " return 3;\n" + + " case 237 :\n" + + " return 3;\n" + + " case 238 :\n" + + " return 3;\n" + + " case 239 :\n" + + " return 3;\n" + + " case 240 :\n" + + " return 3;\n" + + " case 241 :\n" + + " return 3;\n" + + " case 242 :\n" + + " return 3;\n" + + " case 243 :\n" + + " return 3;\n" + + " case 244 :\n" + + " return 3;\n" + + " case 245 :\n" + + " return 3;\n" + + " case 246 :\n" + + " return 3;\n" + + " case 247 :\n" + + " return 3;\n" + + " case 248 :\n" + + " return 3;\n" + + " case 249 :\n" + + " return 3;\n" + + " case 250 :\n" + + " return 3;\n" + + " case 251 :\n" + + " return 3;\n" + + " case 252 :\n" + + " return 3;\n" + + " case 253 :\n" + + " return 3;\n" + + " case 254 :\n" + + " return 3;\n" + + " case 255 :\n" + + " return 3;\n" + + " case 256 :\n" + + " return 3;\n" + + " case 257 :\n" + + " return 3;\n" + + " case 258 :\n" + + " return 3;\n" + + " case 259 :\n" + + " return 3;\n" + + " case 260 :\n" + + " return 3;\n" + + " case 261 :\n" + + " return 3;\n" + + " case 262 :\n" + + " return 3;\n" + + " case 263 :\n" + + " return 3;\n" + + " case 264 :\n" + + " return 3;\n" + + " case 265 :\n" + + " return 3;\n" + + " case 266 :\n" + + " return 3;\n" + + " case 267 :\n" + + " return 3;\n" + + " case 268 :\n" + + " return 3;\n" + + " case 269 :\n" + + " return 3;\n" + + " case 270 :\n" + + " return 3;\n" + + " case 271 :\n" + + " return 3;\n" + + " case 272 :\n" + + " return 3;\n" + + " case 273 :\n" + + " return 3;\n" + + " case 274 :\n" + + " return 3;\n" + + " case 275 :\n" + + " return 3;\n" + + " case 276 :\n" + + " return 3;\n" + + " case 277 :\n" + + " return 3;\n" + + " case 278 :\n" + + " return 3;\n" + + " case 279 :\n" + + " return 3;\n" + + " case 280 :\n" + + " return 3;\n" + + " case 281 :\n" + + " return 3;\n" + + " case 282 :\n" + + " return 3;\n" + + " case 283 :\n" + + " return 3;\n" + + " case 284 :\n" + + " return 3;\n" + + " case 285 :\n" + + " return 3;\n" + + " case 286 :\n" + + " return 3;\n" + + " case 287 :\n" + + " return 3;\n" + + " case 288 :\n" + + " return 3;\n" + + " case 289 :\n" + + " return 3;\n" + + " case 290 :\n" + + " return 3;\n" + + " case 291 :\n" + + " return 3;\n" + + " case 292 :\n" + + " return 3;\n" + + " case 293 :\n" + + " return 3;\n" + + " case 294 :\n" + + " return 3;\n" + + " case 295 :\n" + + " return 3;\n" + + " case 296 :\n" + + " return 3;\n" + + " case 297 :\n" + + " return 3;\n" + + " case 298 :\n" + + " return 3;\n" + + " case 299 :\n" + + " return 3;\n" + + " case 300 :\n" + + " return 3;\n" + + " case 301 :\n" + + " return 3;\n" + + " case 302 :\n" + + " return 3;\n" + + " case 303 :\n" + + " return 3;\n" + + " case 304 :\n" + + " return 3;\n" + + " case 305 :\n" + + " return 3;\n" + + " case 306 :\n" + + " return 3;\n" + + " case 307 :\n" + + " return 3;\n" + + " case 308 :\n" + + " return 3;\n" + + " case 309 :\n" + + " return 3;\n" + + " case 310 :\n" + + " return 3;\n" + + " case 311 :\n" + + " return 3;\n" + + " case 312 :\n" + + " return 3;\n" + + " case 313 :\n" + + " return 3;\n" + + " case 314 :\n" + + " return 3;\n" + + " case 315 :\n" + + " return 3;\n" + + " case 316 :\n" + + " return 3;\n" + + " case 317 :\n" + + " return 3;\n" + + " case 318 :\n" + + " return 3;\n" + + " case 319 :\n" + + " return 3;\n" + + " case 320 :\n" + + " return 3;\n" + + " case 321 :\n" + + " return 3;\n" + + " case 322 :\n" + + " return 3;\n" + + " case 323 :\n" + + " return 3;\n" + + " case 324 :\n" + + " return 3;\n" + + " case 325 :\n" + + " return 3;\n" + + " case 326 :\n" + + " return 3;\n" + + " case 327 :\n" + + " return 3;\n" + + " case 328 :\n" + + " return 3;\n" + + " case 329 :\n" + + " return 3;\n" + + " case 330 :\n" + + " return 3;\n" + + " case 331 :\n" + + " return 3;\n" + + " case 332 :\n" + + " return 3;\n" + + " case 333 :\n" + + " return 3;\n" + + " case 334 :\n" + + " return 3;\n" + + " case 335 :\n" + + " return 3;\n" + + " case 336 :\n" + + " return 3;\n" + + " case 337 :\n" + + " return 3;\n" + + " case 338 :\n" + + " return 3;\n" + + " case 339 :\n" + + " return 3;\n" + + " case 340 :\n" + + " return 3;\n" + + " case 341 :\n" + + " return 3;\n" + + " case 342 :\n" + + " return 3;\n" + + " case 343 :\n" + + " return 3;\n" + + " case 344 :\n" + + " return 3;\n" + + " case 345 :\n" + + " return 3;\n" + + " case 346 :\n" + + " return 3;\n" + + " case 347 :\n" + + " return 3;\n" + + " case 348 :\n" + + " return 3;\n" + + " case 349 :\n" + + " return 3;\n" + + " case 350 :\n" + + " return 3;\n" + + " case 351 :\n" + + " return 3;\n" + + " case 352 :\n" + + " return 3;\n" + + " case 353 :\n" + + " return 3;\n" + + " case 354 :\n" + + " return 3;\n" + + " case 355 :\n" + + " return 3;\n" + + " case 356 :\n" + + " return 3;\n" + + " case 357 :\n" + + " return 3;\n" + + " case 358 :\n" + + " return 3;\n" + + " case 359 :\n" + + " return 3;\n" + + " case 360 :\n" + + " return 3;\n" + + " case 361 :\n" + + " return 3;\n" + + " case 362 :\n" + + " return 3;\n" + + " case 363 :\n" + + " return 3;\n" + + " case 364 :\n" + + " return 3;\n" + + " case 365 :\n" + + " return 3;\n" + + " case 366 :\n" + + " return 3;\n" + + " case 367 :\n" + + " return 3;\n" + + " case 368 :\n" + + " return 3;\n" + + " case 369 :\n" + + " return 3;\n" + + " case 370 :\n" + + " return 3;\n" + + " case 371 :\n" + + " return 3;\n" + + " case 372 :\n" + + " return 3;\n" + + " case 373 :\n" + + " return 3;\n" + + " case 374 :\n" + + " return 3;\n" + + " case 375 :\n" + + " return 3;\n" + + " case 376 :\n" + + " return 3;\n" + + " case 377 :\n" + + " return 3;\n" + + " case 378 :\n" + + " return 3;\n" + + " case 379 :\n" + + " return 3;\n" + + " case 380 :\n" + + " return 3;\n" + + " case 381 :\n" + + " return 3;\n" + + " case 382 :\n" + + " return 3;\n" + + " case 383 :\n" + + " return 3;\n" + + " case 384 :\n" + + " return 3;\n" + + " case 385 :\n" + + " return 3;\n" + + " case 386 :\n" + + " return 3;\n" + + " case 387 :\n" + + " return 3;\n" + + " case 388 :\n" + + " return 3;\n" + + " case 389 :\n" + + " return 3;\n" + + " case 390 :\n" + + " return 3;\n" + + " case 391 :\n" + + " return 3;\n" + + " case 392 :\n" + + " return 3;\n" + + " case 393 :\n" + + " return 3;\n" + + " case 394 :\n" + + " return 3;\n" + + " case 395 :\n" + + " return 3;\n" + + " case 396 :\n" + + " return 3;\n" + + " case 397 :\n" + + " return 3;\n" + + " case 398 :\n" + + " return 3;\n" + + " case 399 :\n" + + " return 3;\n" + + " case 400 :\n" + + " return 3;\n" + + " case 401 :\n" + + " return 3;\n" + + " case 402 :\n" + + " return 3;\n" + + " case 403 :\n" + + " return 3;\n" + + " case 404 :\n" + + " return 3;\n" + + " case 405 :\n" + + " return 3;\n" + + " case 406 :\n" + + " return 3;\n" + + " case 407 :\n" + + " return 3;\n" + + " case 408 :\n" + + " return 3;\n" + + " case 409 :\n" + + " return 3;\n" + + " case 410 :\n" + + " return 3;\n" + + " case 411 :\n" + + " return 3;\n" + + " case 412 :\n" + + " return 3;\n" + + " case 413 :\n" + + " return 3;\n" + + " case 414 :\n" + + " return 3;\n" + + " case 415 :\n" + + " return 3;\n" + + " case 416 :\n" + + " return 3;\n" + + " case 417 :\n" + + " return 3;\n" + + " case 418 :\n" + + " return 3;\n" + + " case 419 :\n" + + " return 3;\n" + + " case 420 :\n" + + " return 3;\n" + + " case 421 :\n" + + " return 3;\n" + + " case 422 :\n" + + " return 3;\n" + + " case 423 :\n" + + " return 3;\n" + + " case 424 :\n" + + " return 3;\n" + + " case 425 :\n" + + " return 3;\n" + + " case 426 :\n" + + " return 3;\n" + + " case 427 :\n" + + " return 3;\n" + + " case 428 :\n" + + " return 3;\n" + + " case 429 :\n" + + " return 3;\n" + + " case 430 :\n" + + " return 3;\n" + + " case 431 :\n" + + " return 3;\n" + + " case 432 :\n" + + " return 3;\n" + + " case 433 :\n" + + " return 3;\n" + + " case 434 :\n" + + " return 3;\n" + + " case 435 :\n" + + " return 3;\n" + + " case 436 :\n" + + " return 3;\n" + + " case 437 :\n" + + " return 3;\n" + + " case 438 :\n" + + " return 3;\n" + + " case 439 :\n" + + " return 3;\n" + + " case 440 :\n" + + " return 3;\n" + + " case 441 :\n" + + " return 3;\n" + + " case 442 :\n" + + " return 3;\n" + + " case 443 :\n" + + " return 3;\n" + + " case 444 :\n" + + " return 3;\n" + + " case 445 :\n" + + " return 3;\n" + + " case 446 :\n" + + " return 3;\n" + + " case 447 :\n" + + " return 3;\n" + + " case 448 :\n" + + " return 3;\n" + + " case 449 :\n" + + " return 3;\n" + + " case 450 :\n" + + " return 3;\n" + + " case 451 :\n" + + " return 3;\n" + + " case 452 :\n" + + " return 3;\n" + + " case 453 :\n" + + " return 3;\n" + + " case 454 :\n" + + " return 3;\n" + + " case 455 :\n" + + " return 3;\n" + + " case 456 :\n" + + " return 3;\n" + + " case 457 :\n" + + " return 3;\n" + + " case 458 :\n" + + " return 3;\n" + + " case 459 :\n" + + " return 3;\n" + + " case 460 :\n" + + " return 3;\n" + + " case 461 :\n" + + " return 3;\n" + + " case 462 :\n" + + " return 3;\n" + + " case 463 :\n" + + " return 3;\n" + + " case 464 :\n" + + " return 3;\n" + + " case 465 :\n" + + " return 3;\n" + + " case 466 :\n" + + " return 3;\n" + + " case 467 :\n" + + " return 3;\n" + + " case 468 :\n" + + " return 3;\n" + + " case 469 :\n" + + " return 3;\n" + + " case 470 :\n" + + " return 3;\n" + + " case 471 :\n" + + " return 3;\n" + + " case 472 :\n" + + " return 3;\n" + + " case 473 :\n" + + " return 3;\n" + + " case 474 :\n" + + " return 3;\n" + + " case 475 :\n" + + " return 3;\n" + + " case 476 :\n" + + " return 3;\n" + + " case 477 :\n" + + " return 3;\n" + + " case 478 :\n" + + " return 3;\n" + + " case 479 :\n" + + " return 3;\n" + + " case 480 :\n" + + " return 3;\n" + + " case 481 :\n" + + " return 3;\n" + + " case 482 :\n" + + " return 3;\n" + + " case 483 :\n" + + " return 3;\n" + + " case 484 :\n" + + " return 3;\n" + + " case 485 :\n" + + " return 3;\n" + + " case 486 :\n" + + " return 3;\n" + + " case 487 :\n" + + " return 3;\n" + + " case 488 :\n" + + " return 3;\n" + + " case 489 :\n" + + " return 3;\n" + + " case 490 :\n" + + " return 3;\n" + + " case 491 :\n" + + " return 3;\n" + + " case 492 :\n" + + " return 3;\n" + + " case 493 :\n" + + " return 3;\n" + + " case 494 :\n" + + " return 3;\n" + + " case 495 :\n" + + " return 3;\n" + + " case 496 :\n" + + " return 3;\n" + + " case 497 :\n" + + " return 3;\n" + + " case 498 :\n" + + " return 3;\n" + + " case 499 :\n" + + " return 3;\n" + + " case 500 :\n" + + " return 3;\n" + + " case 501 :\n" + + " return 3;\n" + + " case 502 :\n" + + " return 3;\n" + + " case 503 :\n" + + " return 3;\n" + + " case 504 :\n" + + " return 3;\n" + + " case 505 :\n" + + " return 3;\n" + + " case 506 :\n" + + " return 3;\n" + + " case 507 :\n" + + " return 3;\n" + + " case 508 :\n" + + " return 3;\n" + + " case 509 :\n" + + " return 3;\n" + + " case 510 :\n" + + " return 3;\n" + + " case 511 :\n" + + " return 3;\n" + + " case 512 :\n" + + " return 3;\n" + + " case 513 :\n" + + " return 3;\n" + + " case 514 :\n" + + " return 3;\n" + + " case 515 :\n" + + " return 3;\n" + + " case 516 :\n" + + " return 3;\n" + + " case 517 :\n" + + " return 3;\n" + + " case 518 :\n" + + " return 3;\n" + + " case 519 :\n" + + " return 3;\n" + + " case 520 :\n" + + " return 3;\n" + + " case 521 :\n" + + " return 3;\n" + + " case 522 :\n" + + " return 3;\n" + + " case 523 :\n" + + " return 3;\n" + + " case 524 :\n" + + " return 3;\n" + + " case 525 :\n" + + " return 3;\n" + + " case 526 :\n" + + " return 3;\n" + + " case 527 :\n" + + " return 3;\n" + + " case 528 :\n" + + " return 3;\n" + + " case 529 :\n" + + " return 3;\n" + + " case 530 :\n" + + " return 3;\n" + + " case 531 :\n" + + " return 3;\n" + + " case 532 :\n" + + " return 3;\n" + + " case 533 :\n" + + " return 3;\n" + + " case 534 :\n" + + " return 3;\n" + + " case 535 :\n" + + " return 3;\n" + + " case 536 :\n" + + " return 3;\n" + + " case 537 :\n" + + " return 3;\n" + + " case 538 :\n" + + " return 3;\n" + + " case 539 :\n" + + " return 3;\n" + + " case 540 :\n" + + " return 3;\n" + + " case 541 :\n" + + " return 3;\n" + + " case 542 :\n" + + " return 3;\n" + + " case 543 :\n" + + " return 3;\n" + + " case 544 :\n" + + " return 3;\n" + + " case 545 :\n" + + " return 3;\n" + + " case 546 :\n" + + " return 3;\n" + + " case 547 :\n" + + " return 3;\n" + + " case 548 :\n" + + " return 3;\n" + + " case 549 :\n" + + " return 3;\n" + + " case 550 :\n" + + " return 3;\n" + + " case 551 :\n" + + " return 3;\n" + + " case 552 :\n" + + " return 3;\n" + + " case 553 :\n" + + " return 3;\n" + + " case 554 :\n" + + " return 3;\n" + + " case 555 :\n" + + " return 3;\n" + + " case 556 :\n" + + " return 3;\n" + + " case 557 :\n" + + " return 3;\n" + + " case 558 :\n" + + " return 3;\n" + + " case 559 :\n" + + " return 3;\n" + + " case 560 :\n" + + " return 3;\n" + + " case 561 :\n" + + " return 3;\n" + + " case 562 :\n" + + " return 3;\n" + + " case 563 :\n" + + " return 3;\n" + + " case 564 :\n" + + " return 3;\n" + + " case 565 :\n" + + " return 3;\n" + + " case 566 :\n" + + " return 3;\n" + + " case 567 :\n" + + " return 3;\n" + + " case 568 :\n" + + " return 3;\n" + + " case 569 :\n" + + " return 3;\n" + + " case 570 :\n" + + " return 3;\n" + + " case 571 :\n" + + " return 3;\n" + + " case 572 :\n" + + " return 3;\n" + + " case 573 :\n" + + " return 3;\n" + + " case 574 :\n" + + " return 3;\n" + + " case 575 :\n" + + " return 3;\n" + + " case 576 :\n" + + " return 3;\n" + + " case 577 :\n" + + " return 3;\n" + + " case 578 :\n" + + " return 3;\n" + + " case 579 :\n" + + " return 3;\n" + + " case 580 :\n" + + " return 3;\n" + + " case 581 :\n" + + " return 3;\n" + + " case 582 :\n" + + " return 3;\n" + + " case 583 :\n" + + " return 3;\n" + + " case 584 :\n" + + " return 3;\n" + + " case 585 :\n" + + " return 3;\n" + + " case 586 :\n" + + " return 3;\n" + + " case 587 :\n" + + " return 3;\n" + + " case 588 :\n" + + " return 3;\n" + + " case 589 :\n" + + " return 3;\n" + + " case 590 :\n" + + " return 3;\n" + + " case 591 :\n" + + " return 3;\n" + + " case 592 :\n" + + " return 3;\n" + + " case 593 :\n" + + " return 3;\n" + + " case 594 :\n" + + " return 3;\n" + + " case 595 :\n" + + " return 3;\n" + + " case 596 :\n" + + " return 3;\n" + + " case 597 :\n" + + " return 3;\n" + + " case 598 :\n" + + " return 3;\n" + + " case 599 :\n" + + " return 3;\n" + + " case 600 :\n" + + " return 3;\n" + + " case 601 :\n" + + " return 3;\n" + + " case 602 :\n" + + " return 3;\n" + + " case 603 :\n" + + " return 3;\n" + + " case 604 :\n" + + " return 3;\n" + + " case 605 :\n" + + " return 3;\n" + + " case 606 :\n" + + " return 3;\n" + + " case 607 :\n" + + " return 3;\n" + + " case 608 :\n" + + " return 3;\n" + + " case 609 :\n" + + " return 3;\n" + + " case 610 :\n" + + " return 3;\n" + + " case 611 :\n" + + " return 3;\n" + + " case 612 :\n" + + " return 3;\n" + + " case 613 :\n" + + " return 3;\n" + + " case 614 :\n" + + " return 3;\n" + + " case 615 :\n" + + " return 3;\n" + + " case 616 :\n" + + " return 3;\n" + + " case 617 :\n" + + " return 3;\n" + + " case 618 :\n" + + " return 3;\n" + + " case 619 :\n" + + " return 3;\n" + + " case 620 :\n" + + " return 3;\n" + + " case 621 :\n" + + " return 3;\n" + + " case 622 :\n" + + " return 3;\n" + + " case 623 :\n" + + " return 3;\n" + + " case 624 :\n" + + " return 3;\n" + + " case 625 :\n" + + " return 3;\n" + + " case 626 :\n" + + " return 3;\n" + + " case 627 :\n" + + " return 3;\n" + + " case 628 :\n" + + " return 3;\n" + + " case 629 :\n" + + " return 3;\n" + + " case 630 :\n" + + " return 3;\n" + + " case 631 :\n" + + " return 3;\n" + + " case 632 :\n" + + " return 3;\n" + + " case 633 :\n" + + " return 3;\n" + + " case 634 :\n" + + " return 3;\n" + + " case 635 :\n" + + " return 3;\n" + + " case 636 :\n" + + " return 3;\n" + + " case 637 :\n" + + " return 3;\n" + + " case 638 :\n" + + " return 3;\n" + + " case 639 :\n" + + " return 3;\n" + + " case 640 :\n" + + " return 3;\n" + + " case 641 :\n" + + " return 3;\n" + + " case 642 :\n" + + " return 3;\n" + + " case 643 :\n" + + " return 3;\n" + + " case 644 :\n" + + " return 3;\n" + + " case 645 :\n" + + " return 3;\n" + + " case 646 :\n" + + " return 3;\n" + + " case 647 :\n" + + " return 3;\n" + + " case 648 :\n" + + " return 3;\n" + + " case 649 :\n" + + " return 3;\n" + + " case 650 :\n" + + " return 3;\n" + + " case 651 :\n" + + " return 3;\n" + + " case 652 :\n" + + " return 3;\n" + + " case 653 :\n" + + " return 3;\n" + + " case 654 :\n" + + " return 3;\n" + + " case 655 :\n" + + " return 3;\n" + + " case 656 :\n" + + " return 3;\n" + + " case 657 :\n" + + " return 3;\n" + + " case 658 :\n" + + " return 3;\n" + + " case 659 :\n" + + " return 3;\n" + + " case 660 :\n" + + " return 3;\n" + + " case 661 :\n" + + " return 3;\n" + + " case 662 :\n" + + " return 3;\n" + + " case 663 :\n" + + " return 3;\n" + + " case 664 :\n" + + " return 3;\n" + + " case 665 :\n" + + " return 3;\n" + + " case 666 :\n" + + " return 3;\n" + + " case 667 :\n" + + " return 3;\n" + + " case 668 :\n" + + " return 3;\n" + + " case 669 :\n" + + " return 3;\n" + + " case 670 :\n" + + " return 3;\n" + + " case 671 :\n" + + " return 3;\n" + + " case 672 :\n" + + " return 3;\n" + + " case 673 :\n" + + " return 3;\n" + + " case 674 :\n" + + " return 3;\n" + + " case 675 :\n" + + " return 3;\n" + + " case 676 :\n" + + " return 3;\n" + + " case 677 :\n" + + " return 3;\n" + + " case 678 :\n" + + " return 3;\n" + + " case 679 :\n" + + " return 3;\n" + + " case 680 :\n" + + " return 3;\n" + + " case 681 :\n" + + " return 3;\n" + + " case 682 :\n" + + " return 3;\n" + + " case 683 :\n" + + " return 3;\n" + + " case 684 :\n" + + " return 3;\n" + + " case 685 :\n" + + " return 3;\n" + + " case 686 :\n" + + " return 3;\n" + + " case 687 :\n" + + " return 3;\n" + + " case 688 :\n" + + " return 3;\n" + + " case 689 :\n" + + " return 3;\n" + + " case 690 :\n" + + " return 3;\n" + + " case 691 :\n" + + " return 3;\n" + + " case 692 :\n" + + " return 3;\n" + + " case 693 :\n" + + " return 3;\n" + + " case 694 :\n" + + " return 3;\n" + + " case 695 :\n" + + " return 3;\n" + + " case 696 :\n" + + " return 3;\n" + + " case 697 :\n" + + " return 3;\n" + + " case 698 :\n" + + " return 3;\n" + + " case 699 :\n" + + " return 3;\n" + + " case 700 :\n" + + " return 3;\n" + + " case 701 :\n" + + " return 3;\n" + + " case 702 :\n" + + " return 3;\n" + + " case 703 :\n" + + " return 3;\n" + + " case 704 :\n" + + " return 3;\n" + + " case 705 :\n" + + " return 3;\n" + + " case 706 :\n" + + " return 3;\n" + + " case 707 :\n" + + " return 3;\n" + + " case 708 :\n" + + " return 3;\n" + + " case 709 :\n" + + " return 3;\n" + + " case 710 :\n" + + " return 3;\n" + + " case 711 :\n" + + " return 3;\n" + + " case 712 :\n" + + " return 3;\n" + + " case 713 :\n" + + " return 3;\n" + + " case 714 :\n" + + " return 3;\n" + + " case 715 :\n" + + " return 3;\n" + + " case 716 :\n" + + " return 3;\n" + + " case 717 :\n" + + " return 3;\n" + + " case 718 :\n" + + " return 3;\n" + + " case 719 :\n" + + " return 3;\n" + + " case 720 :\n" + + " return 3;\n" + + " case 721 :\n" + + " return 3;\n" + + " case 722 :\n" + + " return 3;\n" + + " case 723 :\n" + + " return 3;\n" + + " case 724 :\n" + + " return 3;\n" + + " case 725 :\n" + + " return 3;\n" + + " case 726 :\n" + + " return 3;\n" + + " case 727 :\n" + + " return 3;\n" + + " case 728 :\n" + + " return 3;\n" + + " case 729 :\n" + + " return 3;\n" + + " case 730 :\n" + + " return 3;\n" + + " case 731 :\n" + + " return 3;\n" + + " case 732 :\n" + + " return 3;\n" + + " case 733 :\n" + + " return 3;\n" + + " case 734 :\n" + + " return 3;\n" + + " case 735 :\n" + + " return 3;\n" + + " case 736 :\n" + + " return 3;\n" + + " case 737 :\n" + + " return 3;\n" + + " case 738 :\n" + + " return 3;\n" + + " case 739 :\n" + + " return 3;\n" + + " case 740 :\n" + + " return 3;\n" + + " case 741 :\n" + + " return 3;\n" + + " case 742 :\n" + + " return 3;\n" + + " case 743 :\n" + + " return 3;\n" + + " case 744 :\n" + + " return 3;\n" + + " case 745 :\n" + + " return 3;\n" + + " case 746 :\n" + + " return 3;\n" + + " case 747 :\n" + + " return 3;\n" + + " case 748 :\n" + + " return 3;\n" + + " case 749 :\n" + + " return 3;\n" + + " case 750 :\n" + + " return 3;\n" + + " case 751 :\n" + + " return 3;\n" + + " case 752 :\n" + + " return 3;\n" + + " case 753 :\n" + + " return 3;\n" + + " case 754 :\n" + + " return 3;\n" + + " case 755 :\n" + + " return 3;\n" + + " case 756 :\n" + + " return 3;\n" + + " case 757 :\n" + + " return 3;\n" + + " case 758 :\n" + + " return 3;\n" + + " case 759 :\n" + + " return 3;\n" + + " case 760 :\n" + + " return 3;\n" + + " case 761 :\n" + + " return 3;\n" + + " case 762 :\n" + + " return 3;\n" + + " case 763 :\n" + + " return 3;\n" + + " case 764 :\n" + + " return 3;\n" + + " case 765 :\n" + + " return 3;\n" + + " case 766 :\n" + + " return 3;\n" + + " case 767 :\n" + + " return 3;\n" + + " case 768 :\n" + + " return 3;\n" + + " case 769 :\n" + + " return 3;\n" + + " case 770 :\n" + + " return 3;\n" + + " case 771 :\n" + + " return 3;\n" + + " case 772 :\n" + + " return 3;\n" + + " case 773 :\n" + + " return 3;\n" + + " case 774 :\n" + + " return 3;\n" + + " case 775 :\n" + + " return 3;\n" + + " case 776 :\n" + + " return 3;\n" + + " case 777 :\n" + + " return 3;\n" + + " case 778 :\n" + + " return 3;\n" + + " case 779 :\n" + + " return 3;\n" + + " case 780 :\n" + + " return 3;\n" + + " case 781 :\n" + + " return 3;\n" + + " case 782 :\n" + + " return 3;\n" + + " case 783 :\n" + + " return 3;\n" + + " case 784 :\n" + + " return 3;\n" + + " case 785 :\n" + + " return 3;\n" + + " case 786 :\n" + + " return 3;\n" + + " case 787 :\n" + + " return 3;\n" + + " case 788 :\n" + + " return 3;\n" + + " case 789 :\n" + + " return 3;\n" + + " case 790 :\n" + + " return 3;\n" + + " case 791 :\n" + + " return 3;\n" + + " case 792 :\n" + + " return 3;\n" + + " case 793 :\n" + + " return 3;\n" + + " case 794 :\n" + + " return 3;\n" + + " case 795 :\n" + + " return 3;\n" + + " case 796 :\n" + + " return 3;\n" + + " case 797 :\n" + + " return 3;\n" + + " case 798 :\n" + + " return 3;\n" + + " case 799 :\n" + + " return 3;\n" + + " case 800 :\n" + + " return 3;\n" + + " case 801 :\n" + + " return 3;\n" + + " case 802 :\n" + + " return 3;\n" + + " case 803 :\n" + + " return 3;\n" + + " case 804 :\n" + + " return 3;\n" + + " case 805 :\n" + + " return 3;\n" + + " case 806 :\n" + + " return 3;\n" + + " case 807 :\n" + + " return 3;\n" + + " case 808 :\n" + + " return 3;\n" + + " case 809 :\n" + + " return 3;\n" + + " case 810 :\n" + + " return 3;\n" + + " case 811 :\n" + + " return 3;\n" + + " case 812 :\n" + + " return 3;\n" + + " case 813 :\n" + + " return 3;\n" + + " case 814 :\n" + + " return 3;\n" + + " case 815 :\n" + + " return 3;\n" + + " case 816 :\n" + + " return 3;\n" + + " case 817 :\n" + + " return 3;\n" + + " case 818 :\n" + + " return 3;\n" + + " case 819 :\n" + + " return 3;\n" + + " case 820 :\n" + + " return 3;\n" + + " case 821 :\n" + + " return 3;\n" + + " case 822 :\n" + + " return 3;\n" + + " case 823 :\n" + + " return 3;\n" + + " case 824 :\n" + + " return 3;\n" + + " case 825 :\n" + + " return 3;\n" + + " case 826 :\n" + + " return 3;\n" + + " case 827 :\n" + + " return 3;\n" + + " case 828 :\n" + + " return 3;\n" + + " case 829 :\n" + + " return 3;\n" + + " case 830 :\n" + + " return 3;\n" + + " case 831 :\n" + + " return 3;\n" + + " case 832 :\n" + + " return 3;\n" + + " case 833 :\n" + + " return 3;\n" + + " case 834 :\n" + + " return 3;\n" + + " case 835 :\n" + + " return 3;\n" + + " case 836 :\n" + + " return 3;\n" + + " case 837 :\n" + + " return 3;\n" + + " case 838 :\n" + + " return 3;\n" + + " case 839 :\n" + + " return 3;\n" + + " case 840 :\n" + + " return 3;\n" + + " case 841 :\n" + + " return 3;\n" + + " case 842 :\n" + + " return 3;\n" + + " case 843 :\n" + + " return 3;\n" + + " case 844 :\n" + + " return 3;\n" + + " case 845 :\n" + + " return 3;\n" + + " case 846 :\n" + + " return 3;\n" + + " case 847 :\n" + + " return 3;\n" + + " case 848 :\n" + + " return 3;\n" + + " case 849 :\n" + + " return 3;\n" + + " case 850 :\n" + + " return 3;\n" + + " case 851 :\n" + + " return 3;\n" + + " case 852 :\n" + + " return 3;\n" + + " case 853 :\n" + + " return 3;\n" + + " case 854 :\n" + + " return 3;\n" + + " case 855 :\n" + + " return 3;\n" + + " case 856 :\n" + + " return 3;\n" + + " case 857 :\n" + + " return 3;\n" + + " case 858 :\n" + + " return 3;\n" + + " case 859 :\n" + + " return 3;\n" + + " case 860 :\n" + + " return 3;\n" + + " case 861 :\n" + + " return 3;\n" + + " case 862 :\n" + + " return 3;\n" + + " case 863 :\n" + + " return 3;\n" + + " case 864 :\n" + + " return 3;\n" + + " case 865 :\n" + + " return 3;\n" + + " case 866 :\n" + + " return 3;\n" + + " case 867 :\n" + + " return 3;\n" + + " case 868 :\n" + + " return 3;\n" + + " case 869 :\n" + + " return 3;\n" + + " case 870 :\n" + + " return 3;\n" + + " case 871 :\n" + + " return 3;\n" + + " case 872 :\n" + + " return 3;\n" + + " case 873 :\n" + + " return 3;\n" + + " case 874 :\n" + + " return 3;\n" + + " case 875 :\n" + + " return 3;\n" + + " case 876 :\n" + + " return 3;\n" + + " case 877 :\n" + + " return 3;\n" + + " case 878 :\n" + + " return 3;\n" + + " case 879 :\n" + + " return 3;\n" + + " case 880 :\n" + + " return 3;\n" + + " case 881 :\n" + + " return 3;\n" + + " case 882 :\n" + + " return 3;\n" + + " case 883 :\n" + + " return 3;\n" + + " case 884 :\n" + + " return 3;\n" + + " case 885 :\n" + + " return 3;\n" + + " case 886 :\n" + + " return 3;\n" + + " case 887 :\n" + + " return 3;\n" + + " case 888 :\n" + + " return 3;\n" + + " case 889 :\n" + + " return 3;\n" + + " case 890 :\n" + + " return 3;\n" + + " case 891 :\n" + + " return 3;\n" + + " case 892 :\n" + + " return 3;\n" + + " case 893 :\n" + + " return 3;\n" + + " case 894 :\n" + + " return 3;\n" + + " case 895 :\n" + + " return 3;\n" + + " case 896 :\n" + + " return 3;\n" + + " case 897 :\n" + + " return 3;\n" + + " case 898 :\n" + + " return 3;\n" + + " case 899 :\n" + + " return 3;\n" + + " case 900 :\n" + + " return 3;\n" + + " case 901 :\n" + + " return 3;\n" + + " case 902 :\n" + + " return 3;\n" + + " case 903 :\n" + + " return 3;\n" + + " case 904 :\n" + + " return 3;\n" + + " case 905 :\n" + + " return 3;\n" + + " case 906 :\n" + + " return 3;\n" + + " case 907 :\n" + + " return 3;\n" + + " case 908 :\n" + + " return 3;\n" + + " case 909 :\n" + + " return 3;\n" + + " case 910 :\n" + + " return 3;\n" + + " case 911 :\n" + + " return 3;\n" + + " case 912 :\n" + + " return 3;\n" + + " case 913 :\n" + + " return 3;\n" + + " case 914 :\n" + + " return 3;\n" + + " case 915 :\n" + + " return 3;\n" + + " case 916 :\n" + + " return 3;\n" + + " case 917 :\n" + + " return 3;\n" + + " case 918 :\n" + + " return 3;\n" + + " case 919 :\n" + + " return 3;\n" + + " case 920 :\n" + + " return 3;\n" + + " case 921 :\n" + + " return 3;\n" + + " case 922 :\n" + + " return 3;\n" + + " case 923 :\n" + + " return 3;\n" + + " case 924 :\n" + + " return 3;\n" + + " case 925 :\n" + + " return 3;\n" + + " case 926 :\n" + + " return 3;\n" + + " case 927 :\n" + + " return 3;\n" + + " case 928 :\n" + + " return 3;\n" + + " case 929 :\n" + + " return 3;\n" + + " case 930 :\n" + + " return 3;\n" + + " case 931 :\n" + + " return 3;\n" + + " case 932 :\n" + + " return 3;\n" + + " case 933 :\n" + + " return 3;\n" + + " case 934 :\n" + + " return 3;\n" + + " case 935 :\n" + + " return 3;\n" + + " case 936 :\n" + + " return 3;\n" + + " case 937 :\n" + + " return 3;\n" + + " case 938 :\n" + + " return 3;\n" + + " case 939 :\n" + + " return 3;\n" + + " case 940 :\n" + + " return 3;\n" + + " case 941 :\n" + + " return 3;\n" + + " case 942 :\n" + + " return 3;\n" + + " case 943 :\n" + + " return 3;\n" + + " case 944 :\n" + + " return 3;\n" + + " case 945 :\n" + + " return 3;\n" + + " case 946 :\n" + + " return 3;\n" + + " case 947 :\n" + + " return 3;\n" + + " case 948 :\n" + + " return 3;\n" + + " case 949 :\n" + + " return 3;\n" + + " case 950 :\n" + + " return 3;\n" + + " case 951 :\n" + + " return 3;\n" + + " case 952 :\n" + + " return 3;\n" + + " case 953 :\n" + + " return 3;\n" + + " case 954 :\n" + + " return 3;\n" + + " case 955 :\n" + + " return 3;\n" + + " case 956 :\n" + + " return 3;\n" + + " case 957 :\n" + + " return 3;\n" + + " case 958 :\n" + + " return 3;\n" + + " case 959 :\n" + + " return 3;\n" + + " case 960 :\n" + + " return 3;\n" + + " case 961 :\n" + + " return 3;\n" + + " case 962 :\n" + + " return 3;\n" + + " case 963 :\n" + + " return 3;\n" + + " case 964 :\n" + + " return 3;\n" + + " case 965 :\n" + + " return 3;\n" + + " case 966 :\n" + + " return 3;\n" + + " case 967 :\n" + + " return 3;\n" + + " case 968 :\n" + + " return 3;\n" + + " case 969 :\n" + + " return 3;\n" + + " case 970 :\n" + + " return 3;\n" + + " case 971 :\n" + + " return 3;\n" + + " case 972 :\n" + + " return 3;\n" + + " case 973 :\n" + + " return 3;\n" + + " case 974 :\n" + + " return 3;\n" + + " case 975 :\n" + + " return 3;\n" + + " case 976 :\n" + + " return 3;\n" + + " case 977 :\n" + + " return 3;\n" + + " case 978 :\n" + + " return 3;\n" + + " case 979 :\n" + + " return 3;\n" + + " case 980 :\n" + + " return 3;\n" + + " case 981 :\n" + + " return 3;\n" + + " case 982 :\n" + + " return 3;\n" + + " case 983 :\n" + + " return 3;\n" + + " case 984 :\n" + + " return 3;\n" + + " case 985 :\n" + + " return 3;\n" + + " case 986 :\n" + + " return 3;\n" + + " case 987 :\n" + + " return 3;\n" + + " case 988 :\n" + + " return 3;\n" + + " case 989 :\n" + + " return 3;\n" + + " case 990 :\n" + + " return 3;\n" + + " case 991 :\n" + + " return 3;\n" + + " case 992 :\n" + + " return 3;\n" + + " case 993 :\n" + + " return 3;\n" + + " case 994 :\n" + + " return 3;\n" + + " case 995 :\n" + + " return 3;\n" + + " case 996 :\n" + + " return 3;\n" + + " case 997 :\n" + + " return 3;\n" + + " case 998 :\n" + + " return 3;\n" + + " case 999 :\n" + + " return 3;\n" + + " case 1000 :\n" + + " return 3;\n" + + " case 1001 :\n" + + " return 3;\n" + + " case 1002 :\n" + + " return 3;\n" + + " case 1003 :\n" + + " return 3;\n" + + " case 1004 :\n" + + " return 3;\n" + + " case 1005 :\n" + + " return 3;\n" + + " case 1006 :\n" + + " return 3;\n" + + " case 1007 :\n" + + " return 3;\n" + + " case 1008 :\n" + + " return 3;\n" + + " case 1009 :\n" + + " return 3;\n" + + " case 1010 :\n" + + " return 3;\n" + + " case 1011 :\n" + + " return 3;\n" + + " case 1012 :\n" + + " return 3;\n" + + " case 1013 :\n" + + " return 3;\n" + + " case 1014 :\n" + + " return 3;\n" + + " case 1015 :\n" + + " return 3;\n" + + " case 1016 :\n" + + " return 3;\n" + + " case 1017 :\n" + + " return 3;\n" + + " case 1018 :\n" + + " return 3;\n" + + " case 1019 :\n" + + " return 3;\n" + + " case 1020 :\n" + + " return 3;\n" + + " case 1021 :\n" + + " return 3;\n" + + " case 1022 :\n" + + " return 3;\n" + + " case 1023 :\n" + + " return 3;\n" + + " case 1024 :\n" + + " return 3;\n" + + " case 1025 :\n" + + " return 3;\n" + + " case 1026 :\n" + + " return 3;\n" + + " case 1027 :\n" + + " return 3;\n" + + " case 1028 :\n" + + " return 3;\n" + + " case 1029 :\n" + + " return 3;\n" + + " case 1030 :\n" + + " return 3;\n" + + " case 1031 :\n" + + " return 3;\n" + + " case 1032 :\n" + + " return 3;\n" + + " case 1033 :\n" + + " return 3;\n" + + " case 1034 :\n" + + " return 3;\n" + + " case 1035 :\n" + + " return 3;\n" + + " case 1036 :\n" + + " return 3;\n" + + " case 1037 :\n" + + " return 3;\n" + + " case 1038 :\n" + + " return 3;\n" + + " case 1039 :\n" + + " return 3;\n" + + " case 1040 :\n" + + " return 3;\n" + + " case 1041 :\n" + + " return 3;\n" + + " case 1042 :\n" + + " return 3;\n" + + " case 1043 :\n" + + " return 3;\n" + + " case 1044 :\n" + + " return 3;\n" + + " case 1045 :\n" + + " return 3;\n" + + " case 1046 :\n" + + " return 3;\n" + + " case 1047 :\n" + + " return 3;\n" + + " case 1048 :\n" + + " return 3;\n" + + " case 1049 :\n" + + " return 3;\n" + + " case 1050 :\n" + + " return 3;\n" + + " case 1051 :\n" + + " return 3;\n" + + " case 1052 :\n" + + " return 3;\n" + + " case 1053 :\n" + + " return 3;\n" + + " case 1054 :\n" + + " return 3;\n" + + " case 1055 :\n" + + " return 3;\n" + + " case 1056 :\n" + + " return 3;\n" + + " case 1057 :\n" + + " return 3;\n" + + " case 1058 :\n" + + " return 3;\n" + + " case 1059 :\n" + + " return 3;\n" + + " case 1060 :\n" + + " return 3;\n" + + " case 1061 :\n" + + " return 3;\n" + + " case 1062 :\n" + + " return 3;\n" + + " case 1063 :\n" + + " return 3;\n" + + " case 1064 :\n" + + " return 3;\n" + + " case 1065 :\n" + + " return 3;\n" + + " case 1066 :\n" + + " return 3;\n" + + " case 1067 :\n" + + " return 3;\n" + + " case 1068 :\n" + + " return 3;\n" + + " case 1069 :\n" + + " return 3;\n" + + " case 1070 :\n" + + " return 3;\n" + + " case 1071 :\n" + + " return 3;\n" + + " case 1072 :\n" + + " return 3;\n" + + " case 1073 :\n" + + " return 3;\n" + + " case 1074 :\n" + + " return 3;\n" + + " case 1075 :\n" + + " return 3;\n" + + " case 1076 :\n" + + " return 3;\n" + + " case 1077 :\n" + + " return 3;\n" + + " case 1078 :\n" + + " return 3;\n" + + " case 1079 :\n" + + " return 3;\n" + + " case 1080 :\n" + + " return 3;\n" + + " case 1081 :\n" + + " return 3;\n" + + " case 1082 :\n" + + " return 3;\n" + + " case 1083 :\n" + + " return 3;\n" + + " case 1084 :\n" + + " return 3;\n" + + " case 1085 :\n" + + " return 3;\n" + + " case 1086 :\n" + + " return 3;\n" + + " case 1087 :\n" + + " return 3;\n" + + " case 1088 :\n" + + " return 3;\n" + + " case 1089 :\n" + + " return 3;\n" + + " case 1090 :\n" + + " return 3;\n" + + " case 1091 :\n" + + " return 3;\n" + + " case 1092 :\n" + + " return 3;\n" + + " case 1093 :\n" + + " return 3;\n" + + " case 1094 :\n" + + " return 3;\n" + + " case 1095 :\n" + + " return 3;\n" + + " case 1096 :\n" + + " return 3;\n" + + " case 1097 :\n" + + " return 3;\n" + + " case 1098 :\n" + + " return 3;\n" + + " case 1099 :\n" + + " return 3;\n" + + " case 1100 :\n" + + " return 3;\n" + + " case 1101 :\n" + + " return 3;\n" + + " case 1102 :\n" + + " return 3;\n" + + " case 1103 :\n" + + " return 3;\n" + + " case 1104 :\n" + + " return 3;\n" + + " case 1105 :\n" + + " return 3;\n" + + " case 1106 :\n" + + " return 3;\n" + + " case 1107 :\n" + + " return 3;\n" + + " case 1108 :\n" + + " return 3;\n" + + " case 1109 :\n" + + " return 3;\n" + + " case 1110 :\n" + + " return 3;\n" + + " case 1111 :\n" + + " return 3;\n" + + " case 1112 :\n" + + " return 3;\n" + + " case 1113 :\n" + + " return 3;\n" + + " case 1114 :\n" + + " return 3;\n" + + " case 1115 :\n" + + " return 3;\n" + + " case 1116 :\n" + + " return 3;\n" + + " case 1117 :\n" + + " return 3;\n" + + " case 1118 :\n" + + " return 3;\n" + + " case 1119 :\n" + + " return 3;\n" + + " case 1120 :\n" + + " return 3;\n" + + " case 1121 :\n" + + " return 3;\n" + + " case 1122 :\n" + + " return 3;\n" + + " case 1123 :\n" + + " return 3;\n" + + " case 1124 :\n" + + " return 3;\n" + + " case 1125 :\n" + + " return 3;\n" + + " case 1126 :\n" + + " return 3;\n" + + " case 1127 :\n" + + " return 3;\n" + + " case 1128 :\n" + + " return 3;\n" + + " case 1129 :\n" + + " return 3;\n" + + " case 1130 :\n" + + " return 3;\n" + + " case 1131 :\n" + + " return 3;\n" + + " case 1132 :\n" + + " return 3;\n" + + " case 1133 :\n" + + " return 3;\n" + + " case 1134 :\n" + + " return 3;\n" + + " case 1135 :\n" + + " return 3;\n" + + " case 1136 :\n" + + " return 3;\n" + + " case 1137 :\n" + + " return 3;\n" + + " case 1138 :\n" + + " return 3;\n" + + " case 1139 :\n" + + " return 3;\n" + + " case 1140 :\n" + + " return 3;\n" + + " case 1141 :\n" + + " return 3;\n" + + " case 1142 :\n" + + " return 3;\n" + + " case 1143 :\n" + + " return 3;\n" + + " case 1144 :\n" + + " return 3;\n" + + " case 1145 :\n" + + " return 3;\n" + + " case 1146 :\n" + + " return 3;\n" + + " case 1147 :\n" + + " return 3;\n" + + " case 1148 :\n" + + " return 3;\n" + + " case 1149 :\n" + + " return 3;\n" + + " case 1150 :\n" + + " return 3;\n" + + " case 1151 :\n" + + " return 3;\n" + + " case 1152 :\n" + + " return 3;\n" + + " case 1153 :\n" + + " return 3;\n" + + " case 1154 :\n" + + " return 3;\n" + + " case 1155 :\n" + + " return 3;\n" + + " case 1156 :\n" + + " return 3;\n" + + " case 1157 :\n" + + " return 3;\n" + + " case 1158 :\n" + + " return 3;\n" + + " case 1159 :\n" + + " return 3;\n" + + " case 1160 :\n" + + " return 3;\n" + + " case 1161 :\n" + + " return 3;\n" + + " case 1162 :\n" + + " return 3;\n" + + " case 1163 :\n" + + " return 3;\n" + + " case 1164 :\n" + + " return 3;\n" + + " case 1165 :\n" + + " return 3;\n" + + " case 1166 :\n" + + " return 3;\n" + + " case 1167 :\n" + + " return 3;\n" + + " case 1168 :\n" + + " return 3;\n" + + " case 1169 :\n" + + " return 3;\n" + + " case 1170 :\n" + + " return 3;\n" + + " case 1171 :\n" + + " return 3;\n" + + " case 1172 :\n" + + " return 3;\n" + + " case 1173 :\n" + + " return 3;\n" + + " case 1174 :\n" + + " return 3;\n" + + " case 1175 :\n" + + " return 3;\n" + + " case 1176 :\n" + + " return 3;\n" + + " case 1177 :\n" + + " return 3;\n" + + " case 1178 :\n" + + " return 3;\n" + + " case 1179 :\n" + + " return 3;\n" + + " case 1180 :\n" + + " return 3;\n" + + " case 1181 :\n" + + " return 3;\n" + + " case 1182 :\n" + + " return 3;\n" + + " case 1183 :\n" + + " return 3;\n" + + " case 1184 :\n" + + " return 3;\n" + + " case 1185 :\n" + + " return 3;\n" + + " case 1186 :\n" + + " return 3;\n" + + " case 1187 :\n" + + " return 3;\n" + + " case 1188 :\n" + + " return 3;\n" + + " case 1189 :\n" + + " return 3;\n" + + " case 1190 :\n" + + " return 3;\n" + + " case 1191 :\n" + + " return 3;\n" + + " case 1192 :\n" + + " return 3;\n" + + " case 1193 :\n" + + " return 3;\n" + + " case 1194 :\n" + + " return 3;\n" + + " case 1195 :\n" + + " return 3;\n" + + " case 1196 :\n" + + " return 3;\n" + + " case 1197 :\n" + + " return 3;\n" + + " case 1198 :\n" + + " return 3;\n" + + " case 1199 :\n" + + " return 3;\n" + + " case 1200 :\n" + + " return 3;\n" + + " case 1201 :\n" + + " return 3;\n" + + " case 1202 :\n" + + " return 3;\n" + + " case 1203 :\n" + + " return 3;\n" + + " case 1204 :\n" + + " return 3;\n" + + " case 1205 :\n" + + " return 3;\n" + + " case 1206 :\n" + + " return 3;\n" + + " case 1207 :\n" + + " return 3;\n" + + " case 1208 :\n" + + " return 3;\n" + + " case 1209 :\n" + + " return 3;\n" + + " case 1210 :\n" + + " return 3;\n" + + " case 1211 :\n" + + " return 3;\n" + + " case 1212 :\n" + + " return 3;\n" + + " case 1213 :\n" + + " return 3;\n" + + " case 1214 :\n" + + " return 3;\n" + + " case 1215 :\n" + + " return 3;\n" + + " case 1216 :\n" + + " return 3;\n" + + " case 1217 :\n" + + " return 3;\n" + + " case 1218 :\n" + + " return 3;\n" + + " case 1219 :\n" + + " return 3;\n" + + " case 1220 :\n" + + " return 3;\n" + + " case 1221 :\n" + + " return 3;\n" + + " case 1222 :\n" + + " return 3;\n" + + " case 1223 :\n" + + " return 3;\n" + + " case 1224 :\n" + + " return 3;\n" + + " case 1225 :\n" + + " return 3;\n" + + " case 1226 :\n" + + " return 3;\n" + + " case 1227 :\n" + + " return 3;\n" + + " case 1228 :\n" + + " return 3;\n" + + " case 1229 :\n" + + " return 3;\n" + + " case 1230 :\n" + + " return 3;\n" + + " case 1231 :\n" + + " return 3;\n" + + " case 1232 :\n" + + " return 3;\n" + + " case 1233 :\n" + + " return 3;\n" + + " case 1234 :\n" + + " return 3;\n" + + " case 1235 :\n" + + " return 3;\n" + + " case 1236 :\n" + + " return 3;\n" + + " case 1237 :\n" + + " return 3;\n" + + " case 1238 :\n" + + " return 3;\n" + + " case 1239 :\n" + + " return 3;\n" + + " case 1240 :\n" + + " return 3;\n" + + " case 1241 :\n" + + " return 3;\n" + + " case 1242 :\n" + + " return 3;\n" + + " case 1243 :\n" + + " return 3;\n" + + " case 1244 :\n" + + " return 3;\n" + + " case 1245 :\n" + + " return 3;\n" + + " case 1246 :\n" + + " return 3;\n" + + " case 1247 :\n" + + " return 3;\n" + + " case 1248 :\n" + + " return 3;\n" + + " case 1249 :\n" + + " return 3;\n" + + " case 1250 :\n" + + " return 3;\n" + + " case 1251 :\n" + + " return 3;\n" + + " case 1252 :\n" + + " return 3;\n" + + " case 1253 :\n" + + " return 3;\n" + + " case 1254 :\n" + + " return 3;\n" + + " case 1255 :\n" + + " return 3;\n" + + " case 1256 :\n" + + " return 3;\n" + + " case 1257 :\n" + + " return 3;\n" + + " case 1258 :\n" + + " return 3;\n" + + " case 1259 :\n" + + " return 3;\n" + + " case 1260 :\n" + + " return 3;\n" + + " case 1261 :\n" + + " return 3;\n" + + " case 1262 :\n" + + " return 3;\n" + + " case 1263 :\n" + + " return 3;\n" + + " case 1264 :\n" + + " return 3;\n" + + " case 1265 :\n" + + " return 3;\n" + + " case 1266 :\n" + + " return 3;\n" + + " case 1267 :\n" + + " return 3;\n" + + " case 1268 :\n" + + " return 3;\n" + + " case 1269 :\n" + + " return 3;\n" + + " case 1270 :\n" + + " return 3;\n" + + " case 1271 :\n" + + " return 3;\n" + + " case 1272 :\n" + + " return 3;\n" + + " case 1273 :\n" + + " return 3;\n" + + " case 1274 :\n" + + " return 3;\n" + + " case 1275 :\n" + + " return 3;\n" + + " case 1276 :\n" + + " return 3;\n" + + " case 1277 :\n" + + " return 3;\n" + + " case 1278 :\n" + + " return 3;\n" + + " case 1279 :\n" + + " return 3;\n" + + " case 1280 :\n" + + " return 3;\n" + + " case 1281 :\n" + + " return 3;\n" + + " case 1282 :\n" + + " return 3;\n" + + " case 1283 :\n" + + " return 3;\n" + + " case 1284 :\n" + + " return 3;\n" + + " case 1285 :\n" + + " return 3;\n" + + " case 1286 :\n" + + " return 3;\n" + + " case 1287 :\n" + + " return 3;\n" + + " case 1288 :\n" + + " return 3;\n" + + " case 1289 :\n" + + " return 3;\n" + + " case 1290 :\n" + + " return 3;\n" + + " case 1291 :\n" + + " return 3;\n" + + " case 1292 :\n" + + " return 3;\n" + + " case 1293 :\n" + + " return 3;\n" + + " case 1294 :\n" + + " return 3;\n" + + " case 1295 :\n" + + " return 3;\n" + + " case 1296 :\n" + + " return 3;\n" + + " case 1297 :\n" + + " return 3;\n" + + " case 1298 :\n" + + " return 3;\n" + + " case 1299 :\n" + + " return 3;\n" + + " case 1300 :\n" + + " return 3;\n" + + " case 1301 :\n" + + " return 3;\n" + + " case 1302 :\n" + + " return 3;\n" + + " case 1303 :\n" + + " return 3;\n" + + " case 1304 :\n" + + " return 3;\n" + + " case 1305 :\n" + + " return 3;\n" + + " case 1306 :\n" + + " return 3;\n" + + " case 1307 :\n" + + " return 3;\n" + + " case 1308 :\n" + + " return 3;\n" + + " case 1309 :\n" + + " return 3;\n" + + " case 1310 :\n" + + " return 3;\n" + + " case 1311 :\n" + + " return 3;\n" + + " case 1312 :\n" + + " return 3;\n" + + " case 1313 :\n" + + " return 3;\n" + + " case 1314 :\n" + + " return 3;\n" + + " case 1315 :\n" + + " return 3;\n" + + " case 1316 :\n" + + " return 3;\n" + + " case 1317 :\n" + + " return 3;\n" + + " case 1318 :\n" + + " return 3;\n" + + " case 1319 :\n" + + " return 3;\n" + + " case 1320 :\n" + + " return 3;\n" + + " case 1321 :\n" + + " return 3;\n" + + " case 1322 :\n" + + " return 3;\n" + + " case 1323 :\n" + + " return 3;\n" + + " case 1324 :\n" + + " return 3;\n" + + " case 1325 :\n" + + " return 3;\n" + + " case 1326 :\n" + + " return 3;\n" + + " case 1327 :\n" + + " return 3;\n" + + " case 1328 :\n" + + " return 3;\n" + + " case 1329 :\n" + + " return 3;\n" + + " case 1330 :\n" + + " return 3;\n" + + " case 1331 :\n" + + " return 3;\n" + + " case 1332 :\n" + + " return 3;\n" + + " case 1333 :\n" + + " return 3;\n" + + " case 1334 :\n" + + " return 3;\n" + + " case 1335 :\n" + + " return 3;\n" + + " case 1336 :\n" + + " return 3;\n" + + " case 1337 :\n" + + " return 3;\n" + + " case 1338 :\n" + + " return 3;\n" + + " case 1339 :\n" + + " return 3;\n" + + " case 1340 :\n" + + " return 3;\n" + + " case 1341 :\n" + + " return 3;\n" + + " case 1342 :\n" + + " return 3;\n" + + " case 1343 :\n" + + " return 3;\n" + + " case 1344 :\n" + + " return 3;\n" + + " case 1345 :\n" + + " return 3;\n" + + " case 1346 :\n" + + " return 3;\n" + + " case 1347 :\n" + + " return 3;\n" + + " case 1348 :\n" + + " return 3;\n" + + " case 1349 :\n" + + " return 3;\n" + + " case 1350 :\n" + + " return 3;\n" + + " case 1351 :\n" + + " return 3;\n" + + " case 1352 :\n" + + " return 3;\n" + + " case 1353 :\n" + + " return 3;\n" + + " case 1354 :\n" + + " return 3;\n" + + " case 1355 :\n" + + " return 3;\n" + + " case 1356 :\n" + + " return 3;\n" + + " case 1357 :\n" + + " return 3;\n" + + " case 1358 :\n" + + " return 3;\n" + + " case 1359 :\n" + + " return 3;\n" + + " case 1360 :\n" + + " return 3;\n" + + " case 1361 :\n" + + " return 3;\n" + + " case 1362 :\n" + + " return 3;\n" + + " case 1363 :\n" + + " return 3;\n" + + " case 1364 :\n" + + " return 3;\n" + + " case 1365 :\n" + + " return 3;\n" + + " case 1366 :\n" + + " return 3;\n" + + " case 1367 :\n" + + " return 3;\n" + + " case 1368 :\n" + + " return 3;\n" + + " case 1369 :\n" + + " return 3;\n" + + " case 1370 :\n" + + " return 3;\n" + + " case 1371 :\n" + + " return 3;\n" + + " case 1372 :\n" + + " return 3;\n" + + " case 1373 :\n" + + " return 3;\n" + + " case 1374 :\n" + + " return 3;\n" + + " case 1375 :\n" + + " return 3;\n" + + " case 1376 :\n" + + " return 3;\n" + + " case 1377 :\n" + + " return 3;\n" + + " case 1378 :\n" + + " return 3;\n" + + " case 1379 :\n" + + " return 3;\n" + + " case 1380 :\n" + + " return 3;\n" + + " case 1381 :\n" + + " return 3;\n" + + " case 1382 :\n" + + " return 3;\n" + + " case 1383 :\n" + + " return 3;\n" + + " case 1384 :\n" + + " return 3;\n" + + " case 1385 :\n" + + " return 3;\n" + + " case 1386 :\n" + + " return 3;\n" + + " case 1387 :\n" + + " return 3;\n" + + " case 1388 :\n" + + " return 3;\n" + + " case 1389 :\n" + + " return 3;\n" + + " case 1390 :\n" + + " return 3;\n" + + " case 1391 :\n" + + " return 3;\n" + + " case 1392 :\n" + + " return 3;\n" + + " case 1393 :\n" + + " return 3;\n" + + " case 1394 :\n" + + " return 3;\n" + + " case 1395 :\n" + + " return 3;\n" + + " case 1396 :\n" + + " return 3;\n" + + " case 1397 :\n" + + " return 3;\n" + + " case 1398 :\n" + + " return 3;\n" + + " case 1399 :\n" + + " return 3;\n" + + " case 1400 :\n" + + " return 3;\n" + + " case 1401 :\n" + + " return 3;\n" + + " case 1402 :\n" + + " return 3;\n" + + " case 1403 :\n" + + " return 3;\n" + + " case 1404 :\n" + + " return 3;\n" + + " case 1405 :\n" + + " return 3;\n" + + " case 1406 :\n" + + " return 3;\n" + + " case 1407 :\n" + + " return 3;\n" + + " case 1408 :\n" + + " return 3;\n" + + " case 1409 :\n" + + " return 3;\n" + + " case 1410 :\n" + + " return 3;\n" + + " case 1411 :\n" + + " return 3;\n" + + " case 1412 :\n" + + " return 3;\n" + + " case 1413 :\n" + + " return 3;\n" + + " case 1414 :\n" + + " return 3;\n" + + " case 1415 :\n" + + " return 3;\n" + + " case 1416 :\n" + + " return 3;\n" + + " case 1417 :\n" + + " return 3;\n" + + " case 1418 :\n" + + " return 3;\n" + + " case 1419 :\n" + + " return 3;\n" + + " case 1420 :\n" + + " return 3;\n" + + " case 1421 :\n" + + " return 3;\n" + + " case 1422 :\n" + + " return 3;\n" + + " case 1423 :\n" + + " return 3;\n" + + " case 1424 :\n" + + " return 3;\n" + + " case 1425 :\n" + + " return 3;\n" + + " case 1426 :\n" + + " return 3;\n" + + " case 1427 :\n" + + " return 3;\n" + + " case 1428 :\n" + + " return 3;\n" + + " case 1429 :\n" + + " return 3;\n" + + " case 1430 :\n" + + " return 3;\n" + + " case 1431 :\n" + + " return 3;\n" + + " case 1432 :\n" + + " return 3;\n" + + " case 1433 :\n" + + " return 3;\n" + + " case 1434 :\n" + + " return 3;\n" + + " case 1435 :\n" + + " return 3;\n" + + " case 1436 :\n" + + " return 3;\n" + + " case 1437 :\n" + + " return 3;\n" + + " case 1438 :\n" + + " return 3;\n" + + " case 1439 :\n" + + " return 3;\n" + + " case 1440 :\n" + + " return 3;\n" + + " case 1441 :\n" + + " return 3;\n" + + " case 1442 :\n" + + " return 3;\n" + + " case 1443 :\n" + + " return 3;\n" + + " case 1444 :\n" + + " return 3;\n" + + " case 1445 :\n" + + " return 3;\n" + + " case 1446 :\n" + + " return 3;\n" + + " case 1447 :\n" + + " return 3;\n" + + " case 1448 :\n" + + " return 3;\n" + + " case 1449 :\n" + + " return 3;\n" + + " case 1450 :\n" + + " return 3;\n" + + " case 1451 :\n" + + " return 3;\n" + + " case 1452 :\n" + + " return 3;\n" + + " case 1453 :\n" + + " return 3;\n" + + " case 1454 :\n" + + " return 3;\n" + + " case 1455 :\n" + + " return 3;\n" + + " case 1456 :\n" + + " return 3;\n" + + " case 1457 :\n" + + " return 3;\n" + + " case 1458 :\n" + + " return 3;\n" + + " case 1459 :\n" + + " return 3;\n" + + " case 1460 :\n" + + " return 3;\n" + + " case 1461 :\n" + + " return 3;\n" + + " case 1462 :\n" + + " return 3;\n" + + " case 1463 :\n" + + " return 3;\n" + + " case 1464 :\n" + + " return 3;\n" + + " case 1465 :\n" + + " return 3;\n" + + " case 1466 :\n" + + " return 3;\n" + + " case 1467 :\n" + + " return 3;\n" + + " case 1468 :\n" + + " return 3;\n" + + " case 1469 :\n" + + " return 3;\n" + + " case 1470 :\n" + + " return 3;\n" + + " case 1471 :\n" + + " return 3;\n" + + " case 1472 :\n" + + " return 3;\n" + + " case 1473 :\n" + + " return 3;\n" + + " case 1474 :\n" + + " return 3;\n" + + " case 1475 :\n" + + " return 3;\n" + + " case 1476 :\n" + + " return 3;\n" + + " case 1477 :\n" + + " return 3;\n" + + " case 1478 :\n" + + " return 3;\n" + + " case 1479 :\n" + + " return 3;\n" + + " case 1480 :\n" + + " return 3;\n" + + " case 1481 :\n" + + " return 3;\n" + + " case 1482 :\n" + + " return 3;\n" + + " case 1483 :\n" + + " return 3;\n" + + " case 1484 :\n" + + " return 3;\n" + + " case 1485 :\n" + + " return 3;\n" + + " case 1486 :\n" + + " return 3;\n" + + " case 1487 :\n" + + " return 3;\n" + + " case 1488 :\n" + + " return 3;\n" + + " case 1489 :\n" + + " return 3;\n" + + " case 1490 :\n" + + " return 3;\n" + + " case 1491 :\n" + + " return 3;\n" + + " case 1492 :\n" + + " return 3;\n" + + " case 1493 :\n" + + " return 3;\n" + + " case 1494 :\n" + + " return 3;\n" + + " case 1495 :\n" + + " return 3;\n" + + " case 1496 :\n" + + " return 3;\n" + + " case 1497 :\n" + + " return 3;\n" + + " case 1498 :\n" + + " return 3;\n" + + " case 1499 :\n" + + " return 3;\n" + + " case 1500 :\n" + + " return 3;\n" + + " case 1501 :\n" + + " return 3;\n" + + " case 1502 :\n" + + " return 3;\n" + + " case 1503 :\n" + + " return 3;\n" + + " case 1504 :\n" + + " return 3;\n" + + " case 1505 :\n" + + " return 3;\n" + + " case 1506 :\n" + + " return 3;\n" + + " case 1507 :\n" + + " return 3;\n" + + " case 1508 :\n" + + " return 3;\n" + + " case 1509 :\n" + + " return 3;\n" + + " case 1510 :\n" + + " return 3;\n" + + " case 1511 :\n" + + " return 3;\n" + + " case 1512 :\n" + + " return 3;\n" + + " case 1513 :\n" + + " return 3;\n" + + " case 1514 :\n" + + " return 3;\n" + + " case 1515 :\n" + + " return 3;\n" + + " case 1516 :\n" + + " return 3;\n" + + " case 1517 :\n" + + " return 3;\n" + + " case 1518 :\n" + + " return 3;\n" + + " case 1519 :\n" + + " return 3;\n" + + " case 1520 :\n" + + " return 3;\n" + + " case 1521 :\n" + + " return 3;\n" + + " case 1522 :\n" + + " return 3;\n" + + " case 1523 :\n" + + " return 3;\n" + + " case 1524 :\n" + + " return 3;\n" + + " case 1525 :\n" + + " return 3;\n" + + " case 1526 :\n" + + " return 3;\n" + + " case 1527 :\n" + + " return 3;\n" + + " case 1528 :\n" + + " return 3;\n" + + " case 1529 :\n" + + " return 3;\n" + + " case 1530 :\n" + + " return 3;\n" + + " case 1531 :\n" + + " return 3;\n" + + " case 1532 :\n" + + " return 3;\n" + + " case 1533 :\n" + + " return 3;\n" + + " case 1534 :\n" + + " return 3;\n" + + " case 1535 :\n" + + " return 3;\n" + + " case 1536 :\n" + + " return 3;\n" + + " case 1537 :\n" + + " return 3;\n" + + " case 1538 :\n" + + " return 3;\n" + + " case 1539 :\n" + + " return 3;\n" + + " case 1540 :\n" + + " return 3;\n" + + " case 1541 :\n" + + " return 3;\n" + + " case 1542 :\n" + + " return 3;\n" + + " case 1543 :\n" + + " return 3;\n" + + " case 1544 :\n" + + " return 3;\n" + + " case 1545 :\n" + + " return 3;\n" + + " case 1546 :\n" + + " return 3;\n" + + " case 1547 :\n" + + " return 3;\n" + + " case 1548 :\n" + + " return 3;\n" + + " case 1549 :\n" + + " return 3;\n" + + " case 1550 :\n" + + " return 3;\n" + + " case 1551 :\n" + + " return 3;\n" + + " case 1552 :\n" + + " return 3;\n" + + " case 1553 :\n" + + " return 3;\n" + + " case 1554 :\n" + + " return 3;\n" + + " case 1555 :\n" + + " return 3;\n" + + " case 1556 :\n" + + " return 3;\n" + + " case 1557 :\n" + + " return 3;\n" + + " case 1558 :\n" + + " return 3;\n" + + " case 1559 :\n" + + " return 3;\n" + + " case 1560 :\n" + + " return 3;\n" + + " case 1561 :\n" + + " return 3;\n" + + " case 1562 :\n" + + " return 3;\n" + + " case 1563 :\n" + + " return 3;\n" + + " case 1564 :\n" + + " return 3;\n" + + " case 1565 :\n" + + " return 3;\n" + + " case 1566 :\n" + + " return 3;\n" + + " case 1567 :\n" + + " return 3;\n" + + " case 1568 :\n" + + " return 3;\n" + + " case 1569 :\n" + + " return 3;\n" + + " case 1570 :\n" + + " return 3;\n" + + " case 1571 :\n" + + " return 3;\n" + + " case 1572 :\n" + + " return 3;\n" + + " case 1573 :\n" + + " return 3;\n" + + " case 1574 :\n" + + " return 3;\n" + + " case 1575 :\n" + + " return 3;\n" + + " case 1576 :\n" + + " return 3;\n" + + " case 1577 :\n" + + " return 3;\n" + + " case 1578 :\n" + + " return 3;\n" + + " case 1579 :\n" + + " return 3;\n" + + " case 1580 :\n" + + " return 3;\n" + + " case 1581 :\n" + + " return 3;\n" + + " case 1582 :\n" + + " return 3;\n" + + " case 1583 :\n" + + " return 3;\n" + + " case 1584 :\n" + + " return 3;\n" + + " case 1585 :\n" + + " return 3;\n" + + " case 1586 :\n" + + " return 3;\n" + + " case 1587 :\n" + + " return 3;\n" + + " case 1588 :\n" + + " return 3;\n" + + " case 1589 :\n" + + " return 3;\n" + + " case 1590 :\n" + + " return 3;\n" + + " case 1591 :\n" + + " return 3;\n" + + " case 1592 :\n" + + " return 3;\n" + + " case 1593 :\n" + + " return 3;\n" + + " case 1594 :\n" + + " return 3;\n" + + " case 1595 :\n" + + " return 3;\n" + + " case 1596 :\n" + + " return 3;\n" + + " case 1597 :\n" + + " return 3;\n" + + " case 1598 :\n" + + " return 3;\n" + + " case 1599 :\n" + + " return 3;\n" + + " case 1600 :\n" + + " return 3;\n" + + " case 1601 :\n" + + " return 3;\n" + + " case 1602 :\n" + + " return 3;\n" + + " case 1603 :\n" + + " return 3;\n" + + " case 1604 :\n" + + " return 3;\n" + + " case 1605 :\n" + + " return 3;\n" + + " case 1606 :\n" + + " return 3;\n" + + " case 1607 :\n" + + " return 3;\n" + + " case 1608 :\n" + + " return 3;\n" + + " case 1609 :\n" + + " return 3;\n" + + " case 1610 :\n" + + " return 3;\n" + + " case 1611 :\n" + + " return 3;\n" + + " case 1612 :\n" + + " return 3;\n" + + " case 1613 :\n" + + " return 3;\n" + + " case 1614 :\n" + + " return 3;\n" + + " case 1615 :\n" + + " return 3;\n" + + " case 1616 :\n" + + " return 3;\n" + + " case 1617 :\n" + + " return 3;\n" + + " case 1618 :\n" + + " return 3;\n" + + " case 1619 :\n" + + " return 3;\n" + + " case 1620 :\n" + + " return 3;\n" + + " case 1621 :\n" + + " return 3;\n" + + " case 1622 :\n" + + " return 3;\n" + + " case 1623 :\n" + + " return 3;\n" + + " case 1624 :\n" + + " return 3;\n" + + " case 1625 :\n" + + " return 3;\n" + + " case 1626 :\n" + + " return 3;\n" + + " case 1627 :\n" + + " return 3;\n" + + " case 1628 :\n" + + " return 3;\n" + + " case 1629 :\n" + + " return 3;\n" + + " case 1630 :\n" + + " return 3;\n" + + " case 1631 :\n" + + " return 3;\n" + + " case 1632 :\n" + + " return 3;\n" + + " case 1633 :\n" + + " return 3;\n" + + " case 1634 :\n" + + " return 3;\n" + + " case 1635 :\n" + + " return 3;\n" + + " case 1636 :\n" + + " return 3;\n" + + " case 1637 :\n" + + " return 3;\n" + + " case 1638 :\n" + + " return 3;\n" + + " case 1639 :\n" + + " return 3;\n" + + " case 1640 :\n" + + " return 3;\n" + + " case 1641 :\n" + + " return 3;\n" + + " case 1642 :\n" + + " return 3;\n" + + " case 1643 :\n" + + " return 3;\n" + + " case 1644 :\n" + + " return 3;\n" + + " case 1645 :\n" + + " return 3;\n" + + " case 1646 :\n" + + " return 3;\n" + + " case 1647 :\n" + + " return 3;\n" + + " case 1648 :\n" + + " return 3;\n" + + " case 1649 :\n" + + " return 3;\n" + + " case 1650 :\n" + + " return 3;\n" + + " case 1651 :\n" + + " return 3;\n" + + " case 1652 :\n" + + " return 3;\n" + + " case 1653 :\n" + + " return 3;\n" + + " case 1654 :\n" + + " return 3;\n" + + " case 1655 :\n" + + " return 3;\n" + + " case 1656 :\n" + + " return 3;\n" + + " case 1657 :\n" + + " return 3;\n" + + " case 1658 :\n" + + " return 3;\n" + + " case 1659 :\n" + + " return 3;\n" + + " case 1660 :\n" + + " return 3;\n" + + " case 1661 :\n" + + " return 3;\n" + + " case 1662 :\n" + + " return 3;\n" + + " case 1663 :\n" + + " return 3;\n" + + " case 1664 :\n" + + " return 3;\n" + + " case 1665 :\n" + + " return 3;\n" + + " case 1666 :\n" + + " return 3;\n" + + " case 1667 :\n" + + " return 3;\n" + + " case 1668 :\n" + + " return 3;\n" + + " case 1669 :\n" + + " return 3;\n" + + " case 1670 :\n" + + " return 3;\n" + + " case 1671 :\n" + + " return 3;\n" + + " case 1672 :\n" + + " return 3;\n" + + " case 1673 :\n" + + " return 3;\n" + + " case 1674 :\n" + + " return 3;\n" + + " case 1675 :\n" + + " return 3;\n" + + " case 1676 :\n" + + " return 3;\n" + + " case 1677 :\n" + + " return 3;\n" + + " case 1678 :\n" + + " return 3;\n" + + " case 1679 :\n" + + " return 3;\n" + + " case 1680 :\n" + + " return 3;\n" + + " case 1681 :\n" + + " return 3;\n" + + " case 1682 :\n" + + " return 3;\n" + + " case 1683 :\n" + + " return 3;\n" + + " case 1684 :\n" + + " return 3;\n" + + " case 1685 :\n" + + " return 3;\n" + + " case 1686 :\n" + + " return 3;\n" + + " case 1687 :\n" + + " return 3;\n" + + " case 1688 :\n" + + " return 3;\n" + + " case 1689 :\n" + + " return 3;\n" + + " case 1690 :\n" + + " return 3;\n" + + " case 1691 :\n" + + " return 3;\n" + + " case 1692 :\n" + + " return 3;\n" + + " case 1693 :\n" + + " return 3;\n" + + " case 1694 :\n" + + " return 3;\n" + + " case 1695 :\n" + + " return 3;\n" + + " case 1696 :\n" + + " return 3;\n" + + " case 1697 :\n" + + " return 3;\n" + + " case 1698 :\n" + + " return 3;\n" + + " case 1699 :\n" + + " return 3;\n" + + " case 1700 :\n" + + " return 3;\n" + + " case 1701 :\n" + + " return 3;\n" + + " case 1702 :\n" + + " return 3;\n" + + " case 1703 :\n" + + " return 3;\n" + + " case 1704 :\n" + + " return 3;\n" + + " case 1705 :\n" + + " return 3;\n" + + " case 1706 :\n" + + " return 3;\n" + + " case 1707 :\n" + + " return 3;\n" + + " case 1708 :\n" + + " return 3;\n" + + " case 1709 :\n" + + " return 3;\n" + + " case 1710 :\n" + + " return 3;\n" + + " case 1711 :\n" + + " return 3;\n" + + " case 1712 :\n" + + " return 3;\n" + + " case 1713 :\n" + + " return 3;\n" + + " case 1714 :\n" + + " return 3;\n" + + " case 1715 :\n" + + " return 3;\n" + + " case 1716 :\n" + + " return 3;\n" + + " case 1717 :\n" + + " return 3;\n" + + " case 1718 :\n" + + " return 3;\n" + + " case 1719 :\n" + + " return 3;\n" + + " case 1720 :\n" + + " return 3;\n" + + " case 1721 :\n" + + " return 3;\n" + + " case 1722 :\n" + + " return 3;\n" + + " case 1723 :\n" + + " return 3;\n" + + " case 1724 :\n" + + " return 3;\n" + + " case 1725 :\n" + + " return 3;\n" + + " case 1726 :\n" + + " return 3;\n" + + " case 1727 :\n" + + " return 3;\n" + + " case 1728 :\n" + + " return 3;\n" + + " case 1729 :\n" + + " return 3;\n" + + " case 1730 :\n" + + " return 3;\n" + + " case 1731 :\n" + + " return 3;\n" + + " case 1732 :\n" + + " return 3;\n" + + " case 1733 :\n" + + " return 3;\n" + + " case 1734 :\n" + + " return 3;\n" + + " case 1735 :\n" + + " return 3;\n" + + " case 1736 :\n" + + " return 3;\n" + + " case 1737 :\n" + + " return 3;\n" + + " case 1738 :\n" + + " return 3;\n" + + " case 1739 :\n" + + " return 3;\n" + + " case 1740 :\n" + + " return 3;\n" + + " case 1741 :\n" + + " return 3;\n" + + " case 1742 :\n" + + " return 3;\n" + + " case 1743 :\n" + + " return 3;\n" + + " case 1744 :\n" + + " return 3;\n" + + " case 1745 :\n" + + " return 3;\n" + + " case 1746 :\n" + + " return 3;\n" + + " case 1747 :\n" + + " return 3;\n" + + " case 1748 :\n" + + " return 3;\n" + + " case 1749 :\n" + + " return 3;\n" + + " case 1750 :\n" + + " return 3;\n" + + " case 1751 :\n" + + " return 3;\n" + + " case 1752 :\n" + + " return 3;\n" + + " case 1753 :\n" + + " return 3;\n" + + " case 1754 :\n" + + " return 3;\n" + + " case 1755 :\n" + + " return 3;\n" + + " case 1756 :\n" + + " return 3;\n" + + " case 1757 :\n" + + " return 3;\n" + + " case 1758 :\n" + + " return 3;\n" + + " case 1759 :\n" + + " return 3;\n" + + " case 1760 :\n" + + " return 3;\n" + + " case 1761 :\n" + + " return 3;\n" + + " case 1762 :\n" + + " return 3;\n" + + " case 1763 :\n" + + " return 3;\n" + + " case 1764 :\n" + + " return 3;\n" + + " case 1765 :\n" + + " return 3;\n" + + " case 1766 :\n" + + " return 3;\n" + + " case 1767 :\n" + + " return 3;\n" + + " case 1768 :\n" + + " return 3;\n" + + " case 1769 :\n" + + " return 3;\n" + + " case 1770 :\n" + + " return 3;\n" + + " case 1771 :\n" + + " return 3;\n" + + " case 1772 :\n" + + " return 3;\n" + + " case 1773 :\n" + + " return 3;\n" + + " case 1774 :\n" + + " return 3;\n" + + " case 1775 :\n" + + " return 3;\n" + + " case 1776 :\n" + + " return 3;\n" + + " case 1777 :\n" + + " return 3;\n" + + " case 1778 :\n" + + " return 3;\n" + + " case 1779 :\n" + + " return 3;\n" + + " case 1780 :\n" + + " return 3;\n" + + " case 1781 :\n" + + " return 3;\n" + + " case 1782 :\n" + + " return 3;\n" + + " case 1783 :\n" + + " return 3;\n" + + " case 1784 :\n" + + " return 3;\n" + + " case 1785 :\n" + + " return 3;\n" + + " case 1786 :\n" + + " return 3;\n" + + " case 1787 :\n" + + " return 3;\n" + + " case 1788 :\n" + + " return 3;\n" + + " case 1789 :\n" + + " return 3;\n" + + " case 1790 :\n" + + " return 3;\n" + + " case 1791 :\n" + + " return 3;\n" + + " case 1792 :\n" + + " return 3;\n" + + " case 1793 :\n" + + " return 3;\n" + + " case 1794 :\n" + + " return 3;\n" + + " case 1795 :\n" + + " return 3;\n" + + " case 1796 :\n" + + " return 3;\n" + + " case 1797 :\n" + + " return 3;\n" + + " case 1798 :\n" + + " return 3;\n" + + " case 1799 :\n" + + " return 3;\n" + + " case 1800 :\n" + + " return 3;\n" + + " case 1801 :\n" + + " return 3;\n" + + " case 1802 :\n" + + " return 3;\n" + + " case 1803 :\n" + + " return 3;\n" + + " case 1804 :\n" + + " return 3;\n" + + " case 1805 :\n" + + " return 3;\n" + + " case 1806 :\n" + + " return 3;\n" + + " case 1807 :\n" + + " return 3;\n" + + " case 1808 :\n" + + " return 3;\n" + + " case 1809 :\n" + + " return 3;\n" + + " case 1810 :\n" + + " return 3;\n" + + " case 1811 :\n" + + " return 3;\n" + + " case 1812 :\n" + + " return 3;\n" + + " case 1813 :\n" + + " return 3;\n" + + " case 1814 :\n" + + " return 3;\n" + + " case 1815 :\n" + + " return 3;\n" + + " case 1816 :\n" + + " return 3;\n" + + " case 1817 :\n" + + " return 3;\n" + + " case 1818 :\n" + + " return 3;\n" + + " case 1819 :\n" + + " return 3;\n" + + " case 1820 :\n" + + " return 3;\n" + + " case 1821 :\n" + + " return 3;\n" + + " case 1822 :\n" + + " return 3;\n" + + " case 1823 :\n" + + " return 3;\n" + + " case 1824 :\n" + + " return 3;\n" + + " case 1825 :\n" + + " return 3;\n" + + " case 1826 :\n" + + " return 3;\n" + + " case 1827 :\n" + + " return 3;\n" + + " case 1828 :\n" + + " return 3;\n" + + " case 1829 :\n" + + " return 3;\n" + + " case 1830 :\n" + + " return 3;\n" + + " case 1831 :\n" + + " return 3;\n" + + " case 1832 :\n" + + " return 3;\n" + + " case 1833 :\n" + + " return 3;\n" + + " case 1834 :\n" + + " return 3;\n" + + " case 1835 :\n" + + " return 3;\n" + + " case 1836 :\n" + + " return 3;\n" + + " case 1837 :\n" + + " return 3;\n" + + " case 1838 :\n" + + " return 3;\n" + + " case 1839 :\n" + + " return 3;\n" + + " case 1840 :\n" + + " return 3;\n" + + " case 1841 :\n" + + " return 3;\n" + + " case 1842 :\n" + + " return 3;\n" + + " case 1843 :\n" + + " return 3;\n" + + " case 1844 :\n" + + " return 3;\n" + + " case 1845 :\n" + + " return 3;\n" + + " case 1846 :\n" + + " return 3;\n" + + " case 1847 :\n" + + " return 3;\n" + + " case 1848 :\n" + + " return 3;\n" + + " case 1849 :\n" + + " return 3;\n" + + " case 1850 :\n" + + " return 3;\n" + + " case 1851 :\n" + + " return 3;\n" + + " case 1852 :\n" + + " return 3;\n" + + " case 1853 :\n" + + " return 3;\n" + + " case 1854 :\n" + + " return 3;\n" + + " case 1855 :\n" + + " return 3;\n" + + " case 1856 :\n" + + " return 3;\n" + + " case 1857 :\n" + + " return 3;\n" + + " case 1858 :\n" + + " return 3;\n" + + " case 1859 :\n" + + " return 3;\n" + + " case 1860 :\n" + + " return 3;\n" + + " case 1861 :\n" + + " return 3;\n" + + " case 1862 :\n" + + " return 3;\n" + + " case 1863 :\n" + + " return 3;\n" + + " case 1864 :\n" + + " return 3;\n" + + " case 1865 :\n" + + " return 3;\n" + + " case 1866 :\n" + + " return 3;\n" + + " case 1867 :\n" + + " return 3;\n" + + " case 1868 :\n" + + " return 3;\n" + + " case 1869 :\n" + + " return 3;\n" + + " case 1870 :\n" + + " return 3;\n" + + " case 1871 :\n" + + " return 3;\n" + + " case 1872 :\n" + + " return 3;\n" + + " case 1873 :\n" + + " return 3;\n" + + " case 1874 :\n" + + " return 3;\n" + + " case 1875 :\n" + + " return 3;\n" + + " case 1876 :\n" + + " return 3;\n" + + " case 1877 :\n" + + " return 3;\n" + + " case 1878 :\n" + + " return 3;\n" + + " case 1879 :\n" + + " return 3;\n" + + " case 1880 :\n" + + " return 3;\n" + + " case 1881 :\n" + + " return 3;\n" + + " case 1882 :\n" + + " return 3;\n" + + " case 1883 :\n" + + " return 3;\n" + + " case 1884 :\n" + + " return 3;\n" + + " case 1885 :\n" + + " return 3;\n" + + " case 1886 :\n" + + " return 3;\n" + + " case 1887 :\n" + + " return 3;\n" + + " case 1888 :\n" + + " return 3;\n" + + " case 1889 :\n" + + " return 3;\n" + + " case 1890 :\n" + + " return 3;\n" + + " case 1891 :\n" + + " return 3;\n" + + " case 1892 :\n" + + " return 3;\n" + + " case 1893 :\n" + + " return 3;\n" + + " case 1894 :\n" + + " return 3;\n" + + " case 1895 :\n" + + " return 3;\n" + + " case 1896 :\n" + + " return 3;\n" + + " case 1897 :\n" + + " return 3;\n" + + " case 1898 :\n" + + " return 3;\n" + + " case 1899 :\n" + + " return 3;\n" + + " case 1900 :\n" + + " return 3;\n" + + " case 1901 :\n" + + " return 3;\n" + + " case 1902 :\n" + + " return 3;\n" + + " case 1903 :\n" + + " return 3;\n" + + " case 1904 :\n" + + " return 3;\n" + + " case 1905 :\n" + + " return 3;\n" + + " case 1906 :\n" + + " return 3;\n" + + " case 1907 :\n" + + " return 3;\n" + + " case 1908 :\n" + + " return 3;\n" + + " case 1909 :\n" + + " return 3;\n" + + " case 1910 :\n" + + " return 3;\n" + + " case 1911 :\n" + + " return 3;\n" + + " case 1912 :\n" + + " return 3;\n" + + " case 1913 :\n" + + " return 3;\n" + + " case 1914 :\n" + + " return 3;\n" + + " case 1915 :\n" + + " return 3;\n" + + " case 1916 :\n" + + " return 3;\n" + + " case 1917 :\n" + + " return 3;\n" + + " case 1918 :\n" + + " return 3;\n" + + " case 1919 :\n" + + " return 3;\n" + + " case 1920 :\n" + + " return 3;\n" + + " case 1921 :\n" + + " return 3;\n" + + " case 1922 :\n" + + " return 3;\n" + + " case 1923 :\n" + + " return 3;\n" + + " case 1924 :\n" + + " return 3;\n" + + " case 1925 :\n" + + " return 3;\n" + + " case 1926 :\n" + + " return 3;\n" + + " case 1927 :\n" + + " return 3;\n" + + " case 1928 :\n" + + " return 3;\n" + + " case 1929 :\n" + + " return 3;\n" + + " case 1930 :\n" + + " return 3;\n" + + " case 1931 :\n" + + " return 3;\n" + + " case 1932 :\n" + + " return 3;\n" + + " case 1933 :\n" + + " return 3;\n" + + " case 1934 :\n" + + " return 3;\n" + + " case 1935 :\n" + + " return 3;\n" + + " case 1936 :\n" + + " return 3;\n" + + " case 1937 :\n" + + " return 3;\n" + + " case 1938 :\n" + + " return 3;\n" + + " case 1939 :\n" + + " return 3;\n" + + " case 1940 :\n" + + " return 3;\n" + + " case 1941 :\n" + + " return 3;\n" + + " case 1942 :\n" + + " return 3;\n" + + " case 1943 :\n" + + " return 3;\n" + + " case 1944 :\n" + + " return 3;\n" + + " case 1945 :\n" + + " return 3;\n" + + " case 1946 :\n" + + " return 3;\n" + + " case 1947 :\n" + + " return 3;\n" + + " case 1948 :\n" + + " return 3;\n" + + " case 1949 :\n" + + " return 3;\n" + + " case 1950 :\n" + + " return 3;\n" + + " case 1951 :\n" + + " return 3;\n" + + " case 1952 :\n" + + " return 3;\n" + + " case 1953 :\n" + + " return 3;\n" + + " case 1954 :\n" + + " return 3;\n" + + " case 1955 :\n" + + " return 3;\n" + + " case 1956 :\n" + + " return 3;\n" + + " case 1957 :\n" + + " return 3;\n" + + " case 1958 :\n" + + " return 3;\n" + + " case 1959 :\n" + + " return 3;\n" + + " case 1960 :\n" + + " return 3;\n" + + " case 1961 :\n" + + " return 3;\n" + + " case 1962 :\n" + + " return 3;\n" + + " case 1963 :\n" + + " return 3;\n" + + " case 1964 :\n" + + " return 3;\n" + + " case 1965 :\n" + + " return 3;\n" + + " case 1966 :\n" + + " return 3;\n" + + " case 1967 :\n" + + " return 3;\n" + + " case 1968 :\n" + + " return 3;\n" + + " case 1969 :\n" + + " return 3;\n" + + " case 1970 :\n" + + " return 3;\n" + + " case 1971 :\n" + + " return 3;\n" + + " case 1972 :\n" + + " return 3;\n" + + " case 1973 :\n" + + " return 3;\n" + + " case 1974 :\n" + + " return 3;\n" + + " case 1975 :\n" + + " return 3;\n" + + " case 1976 :\n" + + " return 3;\n" + + " case 1977 :\n" + + " return 3;\n" + + " case 1978 :\n" + + " return 3;\n" + + " case 1979 :\n" + + " return 3;\n" + + " case 1980 :\n" + + " return 3;\n" + + " case 1981 :\n" + + " return 3;\n" + + " case 1982 :\n" + + " return 3;\n" + + " case 1983 :\n" + + " return 3;\n" + + " case 1984 :\n" + + " return 3;\n" + + " case 1985 :\n" + + " return 3;\n" + + " case 1986 :\n" + + " return 3;\n" + + " case 1987 :\n" + + " return 3;\n" + + " case 1988 :\n" + + " return 3;\n" + + " case 1989 :\n" + + " return 3;\n" + + " case 1990 :\n" + + " return 3;\n" + + " case 1991 :\n" + + " return 3;\n" + + " case 1992 :\n" + + " return 3;\n" + + " case 1993 :\n" + + " return 3;\n" + + " case 1994 :\n" + + " return 3;\n" + + " case 1995 :\n" + + " return 3;\n" + + " case 1996 :\n" + + " return 3;\n" + + " case 1997 :\n" + + " return 3;\n" + + " case 1998 :\n" + + " return 3;\n" + + " case 1999 :\n" + + " return 3;\n" + + " case 2000 :\n" + + " return 3;\n" + + " case 2001 :\n" + + " return 3;\n" + + " case 2002 :\n" + + " return 3;\n" + + " case 2003 :\n" + + " return 3;\n" + + " case 2004 :\n" + + " return 3;\n" + + " case 2005 :\n" + + " return 3;\n" + + " case 2006 :\n" + + " return 3;\n" + + " case 2007 :\n" + + " return 3;\n" + + " case 2008 :\n" + + " return 3;\n" + + " case 2009 :\n" + + " return 3;\n" + + " case 2010 :\n" + + " return 3;\n" + + " case 2011 :\n" + + " return 3;\n" + + " case 2012 :\n" + + " return 3;\n" + + " case 2013 :\n" + + " return 3;\n" + + " case 2014 :\n" + + " return 3;\n" + + " case 2015 :\n" + + " return 3;\n" + + " case 2016 :\n" + + " return 3;\n" + + " case 2017 :\n" + + " return 3;\n" + + " case 2018 :\n" + + " return 3;\n" + + " case 2019 :\n" + + " return 3;\n" + + " case 2020 :\n" + + " return 3;\n" + + " case 2021 :\n" + + " return 3;\n" + + " case 2022 :\n" + + " return 3;\n" + + " case 2023 :\n" + + " return 3;\n" + + " case 2024 :\n" + + " return 3;\n" + + " case 2025 :\n" + + " return 3;\n" + + " case 2026 :\n" + + " return 3;\n" + + " case 2027 :\n" + + " return 3;\n" + + " case 2028 :\n" + + " return 3;\n" + + " case 2029 :\n" + + " return 3;\n" + + " case 2030 :\n" + + " return 3;\n" + + " case 2031 :\n" + + " return 3;\n" + + " case 2032 :\n" + + " return 3;\n" + + " case 2033 :\n" + + " return 3;\n" + + " case 2034 :\n" + + " return 3;\n" + + " case 2035 :\n" + + " return 3;\n" + + " case 2036 :\n" + + " return 3;\n" + + " case 2037 :\n" + + " return 3;\n" + + " case 2038 :\n" + + " return 3;\n" + + " case 2039 :\n" + + " return 3;\n" + + " case 2040 :\n" + + " return 3;\n" + + " case 2041 :\n" + + " return 3;\n" + + " case 2042 :\n" + + " return 3;\n" + + " case 2043 :\n" + + " return 3;\n" + + " case 2044 :\n" + + " return 3;\n" + + " case 2045 :\n" + + " return 3;\n" + + " case 2046 :\n" + + " return 3;\n" + + " case 2047 :\n" + + " return 3;\n" + + " case 2048 :\n" + + " return 3;\n" + + " case 2049 :\n" + + " return 3;\n" + + " case 2050 :\n" + + " return 3;\n" + + " case 2051 :\n" + + " return 3;\n" + + " case 2052 :\n" + + " return 3;\n" + + " case 2053 :\n" + + " return 3;\n" + + " case 2054 :\n" + + " return 3;\n" + + " case 2055 :\n" + + " return 3;\n" + + " case 2056 :\n" + + " return 3;\n" + + " case 2057 :\n" + + " return 3;\n" + + " case 2058 :\n" + + " return 3;\n" + + " case 2059 :\n" + + " return 3;\n" + + " case 2060 :\n" + + " return 3;\n" + + " case 2061 :\n" + + " return 3;\n" + + " case 2062 :\n" + + " return 3;\n" + + " case 2063 :\n" + + " return 3;\n" + + " case 2064 :\n" + + " return 3;\n" + + " case 2065 :\n" + + " return 3;\n" + + " case 2066 :\n" + + " return 3;\n" + + " case 2067 :\n" + + " return 3;\n" + + " case 2068 :\n" + + " return 3;\n" + + " case 2069 :\n" + + " return 3;\n" + + " case 2070 :\n" + + " return 3;\n" + + " case 2071 :\n" + + " return 3;\n" + + " case 2072 :\n" + + " return 3;\n" + + " case 2073 :\n" + + " return 3;\n" + + " case 2074 :\n" + + " return 3;\n" + + " case 2075 :\n" + + " return 3;\n" + + " case 2076 :\n" + + " return 3;\n" + + " case 2077 :\n" + + " return 3;\n" + + " case 2078 :\n" + + " return 3;\n" + + " case 2079 :\n" + + " return 3;\n" + + " case 2080 :\n" + + " return 3;\n" + + " case 2081 :\n" + + " return 3;\n" + + " case 2082 :\n" + + " return 3;\n" + + " case 2083 :\n" + + " return 3;\n" + + " case 2084 :\n" + + " return 3;\n" + + " case 2085 :\n" + + " return 3;\n" + + " case 2086 :\n" + + " return 3;\n" + + " case 2087 :\n" + + " return 3;\n" + + " case 2088 :\n" + + " return 3;\n" + + " case 2089 :\n" + + " return 3;\n" + + " case 2090 :\n" + + " return 3;\n" + + " case 2091 :\n" + + " return 3;\n" + + " case 2092 :\n" + + " return 3;\n" + + " case 2093 :\n" + + " return 3;\n" + + " case 2094 :\n" + + " return 3;\n" + + " case 2095 :\n" + + " return 3;\n" + + " case 2096 :\n" + + " return 3;\n" + + " case 2097 :\n" + + " return 3;\n" + + " case 2098 :\n" + + " return 3;\n" + + " case 2099 :\n" + + " return 3;\n" + + " case 2100 :\n" + + " return 3;\n" + + " case 2101 :\n" + + " return 3;\n" + + " case 2102 :\n" + + " return 3;\n" + + " case 2103 :\n" + + " return 3;\n" + + " case 2104 :\n" + + " return 3;\n" + + " case 2105 :\n" + + " return 3;\n" + + " case 2106 :\n" + + " return 3;\n" + + " case 2107 :\n" + + " return 3;\n" + + " case 2108 :\n" + + " return 3;\n" + + " case 2109 :\n" + + " return 3;\n" + + " case 2110 :\n" + + " return 3;\n" + + " case 2111 :\n" + + " return 3;\n" + + " case 2112 :\n" + + " return 3;\n" + + " case 2113 :\n" + + " return 3;\n" + + " case 2114 :\n" + + " return 3;\n" + + " case 2115 :\n" + + " return 3;\n" + + " case 2116 :\n" + + " return 3;\n" + + " case 2117 :\n" + + " return 3;\n" + + " case 2118 :\n" + + " return 3;\n" + + " case 2119 :\n" + + " return 3;\n" + + " case 2120 :\n" + + " return 3;\n" + + " case 2121 :\n" + + " return 3;\n" + + " case 2122 :\n" + + " return 3;\n" + + " case 2123 :\n" + + " return 3;\n" + + " case 2124 :\n" + + " return 3;\n" + + " case 2125 :\n" + + " return 3;\n" + + " case 2126 :\n" + + " return 3;\n" + + " case 2127 :\n" + + " return 3;\n" + + " case 2128 :\n" + + " return 3;\n" + + " case 2129 :\n" + + " return 3;\n" + + " case 2130 :\n" + + " return 3;\n" + + " case 2131 :\n" + + " return 3;\n" + + " case 2132 :\n" + + " return 3;\n" + + " case 2133 :\n" + + " return 3;\n" + + " case 2134 :\n" + + " return 3;\n" + + " case 2135 :\n" + + " return 3;\n" + + " case 2136 :\n" + + " return 3;\n" + + " case 2137 :\n" + + " return 3;\n" + + " case 2138 :\n" + + " return 3;\n" + + " case 2139 :\n" + + " return 3;\n" + + " case 2140 :\n" + + " return 3;\n" + + " case 2141 :\n" + + " return 3;\n" + + " case 2142 :\n" + + " return 3;\n" + + " case 2143 :\n" + + " return 3;\n" + + " case 2144 :\n" + + " return 3;\n" + + " case 2145 :\n" + + " return 3;\n" + + " case 2146 :\n" + + " return 3;\n" + + " case 2147 :\n" + + " return 3;\n" + + " case 2148 :\n" + + " return 3;\n" + + " case 2149 :\n" + + " return 3;\n" + + " case 2150 :\n" + + " return 3;\n" + + " case 2151 :\n" + + " return 3;\n" + + " case 2152 :\n" + + " return 3;\n" + + " case 2153 :\n" + + " return 3;\n" + + " case 2154 :\n" + + " return 3;\n" + + " case 2155 :\n" + + " return 3;\n" + + " case 2156 :\n" + + " return 3;\n" + + " case 2157 :\n" + + " return 3;\n" + + " case 2158 :\n" + + " return 3;\n" + + " case 2159 :\n" + + " return 3;\n" + + " case 2160 :\n" + + " return 3;\n" + + " case 2161 :\n" + + " return 3;\n" + + " case 2162 :\n" + + " return 3;\n" + + " case 2163 :\n" + + " return 3;\n" + + " case 2164 :\n" + + " return 3;\n" + + " case 2165 :\n" + + " return 3;\n" + + " case 2166 :\n" + + " return 3;\n" + + " case 2167 :\n" + + " return 3;\n" + + " case 2168 :\n" + + " return 3;\n" + + " case 2169 :\n" + + " return 3;\n" + + " case 2170 :\n" + + " return 3;\n" + + " case 2171 :\n" + + " return 3;\n" + + " case 2172 :\n" + + " return 3;\n" + + " case 2173 :\n" + + " return 3;\n" + + " case 2174 :\n" + + " return 3;\n" + + " case 2175 :\n" + + " return 3;\n" + + " case 2176 :\n" + + " return 3;\n" + + " case 2177 :\n" + + " return 3;\n" + + " case 2178 :\n" + + " return 3;\n" + + " case 2179 :\n" + + " return 3;\n" + + " case 2180 :\n" + + " return 3;\n" + + " case 2181 :\n" + + " return 3;\n" + + " case 2182 :\n" + + " return 3;\n" + + " case 2183 :\n" + + " return 3;\n" + + " case 2184 :\n" + + " return 3;\n" + + " case 2185 :\n" + + " return 3;\n" + + " case 2186 :\n" + + " return 3;\n" + + " case 2187 :\n" + + " return 3;\n" + + " case 2188 :\n" + + " return 3;\n" + + " case 2189 :\n" + + " return 3;\n" + + " case 2190 :\n" + + " return 3;\n" + + " case 2191 :\n" + + " return 3;\n" + + " case 2192 :\n" + + " return 3;\n" + + " case 2193 :\n" + + " return 3;\n" + + " case 2194 :\n" + + " return 3;\n" + + " case 2195 :\n" + + " return 3;\n" + + " case 2196 :\n" + + " return 3;\n" + + " case 2197 :\n" + + " return 3;\n" + + " case 2198 :\n" + + " return 3;\n" + + " case 2199 :\n" + + " return 3;\n" + + " case 2200 :\n" + + " return 3;\n" + + " case 2201 :\n" + + " return 3;\n" + + " case 2202 :\n" + + " return 3;\n" + + " case 2203 :\n" + + " return 3;\n" + + " case 2204 :\n" + + " return 3;\n" + + " case 2205 :\n" + + " return 3;\n" + + " case 2206 :\n" + + " return 3;\n" + + " case 2207 :\n" + + " return 3;\n" + + " case 2208 :\n" + + " return 3;\n" + + " case 2209 :\n" + + " return 3;\n" + + " case 2210 :\n" + + " return 3;\n" + + " case 2211 :\n" + + " return 3;\n" + + " case 2212 :\n" + + " return 3;\n" + + " case 2213 :\n" + + " return 3;\n" + + " case 2214 :\n" + + " return 3;\n" + + " case 2215 :\n" + + " return 3;\n" + + " case 2216 :\n" + + " return 3;\n" + + " case 2217 :\n" + + " return 3;\n" + + " case 2218 :\n" + + " return 3;\n" + + " case 2219 :\n" + + " return 3;\n" + + " case 2220 :\n" + + " return 3;\n" + + " case 2221 :\n" + + " return 3;\n" + + " case 2222 :\n" + + " return 3;\n" + + " case 2223 :\n" + + " return 3;\n" + + " case 2224 :\n" + + " return 3;\n" + + " case 2225 :\n" + + " return 3;\n" + + " case 2226 :\n" + + " return 3;\n" + + " case 2227 :\n" + + " return 3;\n" + + " case 2228 :\n" + + " return 3;\n" + + " case 2229 :\n" + + " return 3;\n" + + " case 2230 :\n" + + " return 3;\n" + + " case 2231 :\n" + + " return 3;\n" + + " case 2232 :\n" + + " return 3;\n" + + " case 2233 :\n" + + " return 3;\n" + + " case 2234 :\n" + + " return 3;\n" + + " case 2235 :\n" + + " return 3;\n" + + " case 2236 :\n" + + " return 3;\n" + + " case 2237 :\n" + + " return 3;\n" + + " case 2238 :\n" + + " return 3;\n" + + " case 2239 :\n" + + " return 3;\n" + + " case 2240 :\n" + + " return 3;\n" + + " case 2241 :\n" + + " return 3;\n" + + " case 2242 :\n" + + " return 3;\n" + + " case 2243 :\n" + + " return 3;\n" + + " case 2244 :\n" + + " return 3;\n" + + " case 2245 :\n" + + " return 3;\n" + + " case 2246 :\n" + + " return 3;\n" + + " case 2247 :\n" + + " return 3;\n" + + " case 2248 :\n" + + " return 3;\n" + + " case 2249 :\n" + + " return 3;\n" + + " case 2250 :\n" + + " return 3;\n" + + " case 2251 :\n" + + " return 3;\n" + + " case 2252 :\n" + + " return 3;\n" + + " case 2253 :\n" + + " return 3;\n" + + " case 2254 :\n" + + " return 3;\n" + + " case 2255 :\n" + + " return 3;\n" + + " case 2256 :\n" + + " return 3;\n" + + " case 2257 :\n" + + " return 3;\n" + + " case 2258 :\n" + + " return 3;\n" + + " case 2259 :\n" + + " return 3;\n" + + " case 2260 :\n" + + " return 3;\n" + + " case 2261 :\n" + + " return 3;\n" + + " case 2262 :\n" + + " return 3;\n" + + " case 2263 :\n" + + " return 3;\n" + + " case 2264 :\n" + + " return 3;\n" + + " case 2265 :\n" + + " return 3;\n" + + " case 2266 :\n" + + " return 3;\n" + + " case 2267 :\n" + + " return 3;\n" + + " case 2268 :\n" + + " return 3;\n" + + " case 2269 :\n" + + " return 3;\n" + + " case 2270 :\n" + + " return 3;\n" + + " case 2271 :\n" + + " return 3;\n" + + " case 2272 :\n" + + " return 3;\n" + + " case 2273 :\n" + + " return 3;\n" + + " case 2274 :\n" + + " return 3;\n" + + " case 2275 :\n" + + " return 3;\n" + + " case 2276 :\n" + + " return 3;\n" + + " case 2277 :\n" + + " return 3;\n" + + " case 2278 :\n" + + " return 3;\n" + + " case 2279 :\n" + + " return 3;\n" + + " case 2280 :\n" + + " return 3;\n" + + " case 2281 :\n" + + " return 3;\n" + + " case 2282 :\n" + + " return 3;\n" + + " case 2283 :\n" + + " return 3;\n" + + " case 2284 :\n" + + " return 3;\n" + + " case 2285 :\n" + + " return 3;\n" + + " case 2286 :\n" + + " return 3;\n" + + " case 2287 :\n" + + " return 3;\n" + + " case 2288 :\n" + + " return 3;\n" + + " case 2289 :\n" + + " return 3;\n" + + " case 2290 :\n" + + " return 3;\n" + + " case 2291 :\n" + + " return 3;\n" + + " case 2292 :\n" + + " return 3;\n" + + " case 2293 :\n" + + " return 3;\n" + + " case 2294 :\n" + + " return 3;\n" + + " case 2295 :\n" + + " return 3;\n" + + " case 2296 :\n" + + " return 3;\n" + + " case 2297 :\n" + + " return 3;\n" + + " case 2298 :\n" + + " return 3;\n" + + " case 2299 :\n" + + " return 3;\n" + + " case 2300 :\n" + + " return 3;\n" + + " case 2301 :\n" + + " return 3;\n" + + " case 2302 :\n" + + " return 3;\n" + + " case 2303 :\n" + + " return 3;\n" + + " case 2304 :\n" + + " return 3;\n" + + " case 2305 :\n" + + " return 3;\n" + + " case 2306 :\n" + + " return 3;\n" + + " case 2307 :\n" + + " return 3;\n" + + " case 2308 :\n" + + " return 3;\n" + + " case 2309 :\n" + + " return 3;\n" + + " case 2310 :\n" + + " return 3;\n" + + " case 2311 :\n" + + " return 3;\n" + + " case 2312 :\n" + + " return 3;\n" + + " case 2313 :\n" + + " return 3;\n" + + " case 2314 :\n" + + " return 3;\n" + + " case 2315 :\n" + + " return 3;\n" + + " case 2316 :\n" + + " return 3;\n" + + " case 2317 :\n" + + " return 3;\n" + + " case 2318 :\n" + + " return 3;\n" + + " case 2319 :\n" + + " return 3;\n" + + " case 2320 :\n" + + " return 3;\n" + + " case 2321 :\n" + + " return 3;\n" + + " case 2322 :\n" + + " return 3;\n" + + " case 2323 :\n" + + " return 3;\n" + + " case 2324 :\n" + + " return 3;\n" + + " case 2325 :\n" + + " return 3;\n" + + " case 2326 :\n" + + " return 3;\n" + + " case 2327 :\n" + + " return 3;\n" + + " case 2328 :\n" + + " return 3;\n" + + " case 2329 :\n" + + " return 3;\n" + + " case 2330 :\n" + + " return 3;\n" + + " case 2331 :\n" + + " return 3;\n" + + " case 2332 :\n" + + " return 3;\n" + + " case 2333 :\n" + + " return 3;\n" + + " case 2334 :\n" + + " return 3;\n" + + " case 2335 :\n" + + " return 3;\n" + + " case 2336 :\n" + + " return 3;\n" + + " case 2337 :\n" + + " return 3;\n" + + " case 2338 :\n" + + " return 3;\n" + + " case 2339 :\n" + + " return 3;\n" + + " case 2340 :\n" + + " return 3;\n" + + " case 2341 :\n" + + " return 3;\n" + + " case 2342 :\n" + + " return 3;\n" + + " case 2343 :\n" + + " return 3;\n" + + " case 2344 :\n" + + " return 3;\n" + + " case 2345 :\n" + + " return 3;\n" + + " case 2346 :\n" + + " return 3;\n" + + " case 2347 :\n" + + " return 3;\n" + + " case 2348 :\n" + + " return 3;\n" + + " case 2349 :\n" + + " return 3;\n" + + " case 2350 :\n" + + " return 3;\n" + + " case 2351 :\n" + + " return 3;\n" + + " case 2352 :\n" + + " return 3;\n" + + " case 2353 :\n" + + " return 3;\n" + + " case 2354 :\n" + + " return 3;\n" + + " case 2355 :\n" + + " return 3;\n" + + " case 2356 :\n" + + " return 3;\n" + + " case 2357 :\n" + + " return 3;\n" + + " case 2358 :\n" + + " return 3;\n" + + " case 2359 :\n" + + " return 3;\n" + + " case 2360 :\n" + + " return 3;\n" + + " case 2361 :\n" + + " return 3;\n" + + " case 2362 :\n" + + " return 3;\n" + + " case 2363 :\n" + + " return 3;\n" + + " case 2364 :\n" + + " return 3;\n" + + " case 2365 :\n" + + " return 3;\n" + + " case 2366 :\n" + + " return 3;\n" + + " case 2367 :\n" + + " return 3;\n" + + " case 2368 :\n" + + " return 3;\n" + + " case 2369 :\n" + + " return 3;\n" + + " case 2370 :\n" + + " return 3;\n" + + " case 2371 :\n" + + " return 3;\n" + + " case 2372 :\n" + + " return 3;\n" + + " case 2373 :\n" + + " return 3;\n" + + " case 2374 :\n" + + " return 3;\n" + + " case 2375 :\n" + + " return 3;\n" + + " case 2376 :\n" + + " return 3;\n" + + " case 2377 :\n" + + " return 3;\n" + + " case 2378 :\n" + + " return 3;\n" + + " case 2379 :\n" + + " return 3;\n" + + " case 2380 :\n" + + " return 3;\n" + + " case 2381 :\n" + + " return 3;\n" + + " case 2382 :\n" + + " return 3;\n" + + " case 2383 :\n" + + " return 3;\n" + + " case 2384 :\n" + + " return 3;\n" + + " case 2385 :\n" + + " return 3;\n" + + " case 2386 :\n" + + " return 3;\n" + + " case 2387 :\n" + + " return 3;\n" + + " case 2388 :\n" + + " return 3;\n" + + " case 2389 :\n" + + " return 3;\n" + + " case 2390 :\n" + + " return 3;\n" + + " case 2391 :\n" + + " return 3;\n" + + " case 2392 :\n" + + " return 3;\n" + + " case 2393 :\n" + + " return 3;\n" + + " case 2394 :\n" + + " return 3;\n" + + " case 2395 :\n" + + " return 3;\n" + + " case 2396 :\n" + + " return 3;\n" + + " case 2397 :\n" + + " return 3;\n" + + " case 2398 :\n" + + " return 3;\n" + + " case 2399 :\n" + + " return 3;\n" + + " case 2400 :\n" + + " return 3;\n" + + " case 2401 :\n" + + " return 3;\n" + + " case 2402 :\n" + + " return 3;\n" + + " case 2403 :\n" + + " return 3;\n" + + " case 2404 :\n" + + " return 3;\n" + + " case 2405 :\n" + + " return 3;\n" + + " case 2406 :\n" + + " return 3;\n" + + " case 2407 :\n" + + " return 3;\n" + + " case 2408 :\n" + + " return 3;\n" + + " case 2409 :\n" + + " return 3;\n" + + " case 2410 :\n" + + " return 3;\n" + + " case 2411 :\n" + + " return 3;\n" + + " case 2412 :\n" + + " return 3;\n" + + " case 2413 :\n" + + " return 3;\n" + + " case 2414 :\n" + + " return 3;\n" + + " case 2415 :\n" + + " return 3;\n" + + " case 2416 :\n" + + " return 3;\n" + + " case 2417 :\n" + + " return 3;\n" + + " case 2418 :\n" + + " return 3;\n" + + " case 2419 :\n" + + " return 3;\n" + + " case 2420 :\n" + + " return 3;\n" + + " case 2421 :\n" + + " return 3;\n" + + " case 2422 :\n" + + " return 3;\n" + + " case 2423 :\n" + + " return 3;\n" + + " case 2424 :\n" + + " return 3;\n" + + " case 2425 :\n" + + " return 3;\n" + + " case 2426 :\n" + + " return 3;\n" + + " case 2427 :\n" + + " return 3;\n" + + " case 2428 :\n" + + " return 3;\n" + + " case 2429 :\n" + + " return 3;\n" + + " case 2430 :\n" + + " return 3;\n" + + " case 2431 :\n" + + " return 3;\n" + + " case 2432 :\n" + + " return 3;\n" + + " case 2433 :\n" + + " return 3;\n" + + " case 2434 :\n" + + " return 3;\n" + + " case 2435 :\n" + + " return 3;\n" + + " case 2436 :\n" + + " return 3;\n" + + " case 2437 :\n" + + " return 3;\n" + + " case 2438 :\n" + + " return 3;\n" + + " case 2439 :\n" + + " return 3;\n" + + " case 2440 :\n" + + " return 3;\n" + + " case 2441 :\n" + + " return 3;\n" + + " case 2442 :\n" + + " return 3;\n" + + " case 2443 :\n" + + " return 3;\n" + + " case 2444 :\n" + + " return 3;\n" + + " case 2445 :\n" + + " return 3;\n" + + " case 2446 :\n" + + " return 3;\n" + + " case 2447 :\n" + + " return 3;\n" + + " case 2448 :\n" + + " return 3;\n" + + " case 2449 :\n" + + " return 3;\n" + + " case 2450 :\n" + + " return 3;\n" + + " case 2451 :\n" + + " return 3;\n" + + " case 2452 :\n" + + " return 3;\n" + + " case 2453 :\n" + + " return 3;\n" + + " case 2454 :\n" + + " return 3;\n" + + " case 2455 :\n" + + " return 3;\n" + + " case 2456 :\n" + + " return 3;\n" + + " case 2457 :\n" + + " return 3;\n" + + " case 2458 :\n" + + " return 3;\n" + + " case 2459 :\n" + + " return 3;\n" + + " case 2460 :\n" + + " return 3;\n" + + " case 2461 :\n" + + " return 3;\n" + + " case 2462 :\n" + + " return 3;\n" + + " case 2463 :\n" + + " return 3;\n" + + " case 2464 :\n" + + " return 3;\n" + + " case 2465 :\n" + + " return 3;\n" + + " case 2466 :\n" + + " return 3;\n" + + " case 2467 :\n" + + " return 3;\n" + + " case 2468 :\n" + + " return 3;\n" + + " case 2469 :\n" + + " return 3;\n" + + " case 2470 :\n" + + " return 3;\n" + + " case 2471 :\n" + + " return 3;\n" + + " case 2472 :\n" + + " return 3;\n" + + " case 2473 :\n" + + " return 3;\n" + + " case 2474 :\n" + + " return 3;\n" + + " case 2475 :\n" + + " return 3;\n" + + " case 2476 :\n" + + " return 3;\n" + + " case 2477 :\n" + + " return 3;\n" + + " case 2478 :\n" + + " return 3;\n" + + " case 2479 :\n" + + " return 3;\n" + + " case 2480 :\n" + + " return 3;\n" + + " case 2481 :\n" + + " return 3;\n" + + " case 2482 :\n" + + " return 3;\n" + + " case 2483 :\n" + + " return 3;\n" + + " case 2484 :\n" + + " return 3;\n" + + " case 2485 :\n" + + " return 3;\n" + + " case 2486 :\n" + + " return 3;\n" + + " case 2487 :\n" + + " return 3;\n" + + " case 2488 :\n" + + " return 3;\n" + + " case 2489 :\n" + + " return 3;\n" + + " case 2490 :\n" + + " return 3;\n" + + " case 2491 :\n" + + " return 3;\n" + + " case 2492 :\n" + + " return 3;\n" + + " case 2493 :\n" + + " return 3;\n" + + " case 2494 :\n" + + " return 3;\n" + + " case 2495 :\n" + + " return 3;\n" + + " case 2496 :\n" + + " return 3;\n" + + " case 2497 :\n" + + " return 3;\n" + + " case 2498 :\n" + + " return 3;\n" + + " case 2499 :\n" + + " return 3;\n" + + " case 2500 :\n" + + " return 3;\n" + + " case 2501 :\n" + + " return 3;\n" + + " case 2502 :\n" + + " return 3;\n" + + " case 2503 :\n" + + " return 3;\n" + + " case 2504 :\n" + + " return 3;\n" + + " case 2505 :\n" + + " return 3;\n" + + " case 2506 :\n" + + " return 3;\n" + + " case 2507 :\n" + + " return 3;\n" + + " case 2508 :\n" + + " return 3;\n" + + " case 2509 :\n" + + " return 3;\n" + + " case 2510 :\n" + + " return 3;\n" + + " case 2511 :\n" + + " return 3;\n" + + " case 2512 :\n" + + " return 3;\n" + + " case 2513 :\n" + + " return 3;\n" + + " case 2514 :\n" + + " return 3;\n" + + " case 2515 :\n" + + " return 3;\n" + + " case 2516 :\n" + + " return 3;\n" + + " case 2517 :\n" + + " return 3;\n" + + " case 2518 :\n" + + " return 3;\n" + + " case 2519 :\n" + + " return 3;\n" + + " case 2520 :\n" + + " return 3;\n" + + " case 2521 :\n" + + " return 3;\n" + + " case 2522 :\n" + + " return 3;\n" + + " case 2523 :\n" + + " return 3;\n" + + " case 2524 :\n" + + " return 3;\n" + + " case 2525 :\n" + + " return 3;\n" + + " case 2526 :\n" + + " return 3;\n" + + " case 2527 :\n" + + " return 3;\n" + + " case 2528 :\n" + + " return 3;\n" + + " case 2529 :\n" + + " return 3;\n" + + " case 2530 :\n" + + " return 3;\n" + + " case 2531 :\n" + + " return 3;\n" + + " case 2532 :\n" + + " return 3;\n" + + " case 2533 :\n" + + " return 3;\n" + + " case 2534 :\n" + + " return 3;\n" + + " case 2535 :\n" + + " return 3;\n" + + " case 2536 :\n" + + " return 3;\n" + + " case 2537 :\n" + + " return 3;\n" + + " case 2538 :\n" + + " return 3;\n" + + " case 2539 :\n" + + " return 3;\n" + + " case 2540 :\n" + + " return 3;\n" + + " case 2541 :\n" + + " return 3;\n" + + " case 2542 :\n" + + " return 3;\n" + + " case 2543 :\n" + + " return 3;\n" + + " case 2544 :\n" + + " return 3;\n" + + " case 2545 :\n" + + " return 3;\n" + + " case 2546 :\n" + + " return 3;\n" + + " case 2547 :\n" + + " return 3;\n" + + " case 2548 :\n" + + " return 3;\n" + + " case 2549 :\n" + + " return 3;\n" + + " case 2550 :\n" + + " return 3;\n" + + " case 2551 :\n" + + " return 3;\n" + + " case 2552 :\n" + + " return 3;\n" + + " case 2553 :\n" + + " return 3;\n" + + " case 2554 :\n" + + " return 3;\n" + + " case 2555 :\n" + + " return 3;\n" + + " case 2556 :\n" + + " return 3;\n" + + " case 2557 :\n" + + " return 3;\n" + + " case 2558 :\n" + + " return 3;\n" + + " case 2559 :\n" + + " return 3;\n" + + " case 2560 :\n" + + " return 3;\n" + + " case 2561 :\n" + + " return 3;\n" + + " case 2562 :\n" + + " return 3;\n" + + " case 2563 :\n" + + " return 3;\n" + + " case 2564 :\n" + + " return 3;\n" + + " case 2565 :\n" + + " return 3;\n" + + " case 2566 :\n" + + " return 3;\n" + + " case 2567 :\n" + + " return 3;\n" + + " case 2568 :\n" + + " return 3;\n" + + " case 2569 :\n" + + " return 3;\n" + + " case 2570 :\n" + + " return 3;\n" + + " case 2571 :\n" + + " return 3;\n" + + " case 2572 :\n" + + " return 3;\n" + + " case 2573 :\n" + + " return 3;\n" + + " case 2574 :\n" + + " return 3;\n" + + " case 2575 :\n" + + " return 3;\n" + + " case 2576 :\n" + + " return 3;\n" + + " case 2577 :\n" + + " return 3;\n" + + " case 2578 :\n" + + " return 3;\n" + + " case 2579 :\n" + + " return 3;\n" + + " case 2580 :\n" + + " return 3;\n" + + " case 2581 :\n" + + " return 3;\n" + + " case 2582 :\n" + + " return 3;\n" + + " case 2583 :\n" + + " return 3;\n" + + " case 2584 :\n" + + " return 3;\n" + + " case 2585 :\n" + + " return 3;\n" + + " case 2586 :\n" + + " return 3;\n" + + " case 2587 :\n" + + " return 3;\n" + + " case 2588 :\n" + + " return 3;\n" + + " case 2589 :\n" + + " return 3;\n" + + " case 2590 :\n" + + " return 3;\n" + + " case 2591 :\n" + + " return 3;\n" + + " case 2592 :\n" + + " return 3;\n" + + " case 2593 :\n" + + " return 3;\n" + + " case 2594 :\n" + + " return 3;\n" + + " case 2595 :\n" + + " return 3;\n" + + " case 2596 :\n" + + " return 3;\n" + + " case 2597 :\n" + + " return 3;\n" + + " case 2598 :\n" + + " return 3;\n" + + " case 2599 :\n" + + " return 3;\n" + + " case 2600 :\n" + + " return 3;\n" + + " case 2601 :\n" + + " return 3;\n" + + " case 2602 :\n" + + " return 3;\n" + + " case 2603 :\n" + + " return 3;\n" + + " case 2604 :\n" + + " return 3;\n" + + " case 2605 :\n" + + " return 3;\n" + + " case 2606 :\n" + + " return 3;\n" + + " case 2607 :\n" + + " return 3;\n" + + " case 2608 :\n" + + " return 3;\n" + + " case 2609 :\n" + + " return 3;\n" + + " case 2610 :\n" + + " return 3;\n" + + " case 2611 :\n" + + " return 3;\n" + + " case 2612 :\n" + + " return 3;\n" + + " case 2613 :\n" + + " return 3;\n" + + " case 2614 :\n" + + " return 3;\n" + + " case 2615 :\n" + + " return 3;\n" + + " case 2616 :\n" + + " return 3;\n" + + " case 2617 :\n" + + " return 3;\n" + + " case 2618 :\n" + + " return 3;\n" + + " case 2619 :\n" + + " return 3;\n" + + " case 2620 :\n" + + " return 3;\n" + + " case 2621 :\n" + + " return 3;\n" + + " case 2622 :\n" + + " return 3;\n" + + " case 2623 :\n" + + " return 3;\n" + + " case 2624 :\n" + + " return 3;\n" + + " case 2625 :\n" + + " return 3;\n" + + " case 2626 :\n" + + " return 3;\n" + + " case 2627 :\n" + + " return 3;\n" + + " case 2628 :\n" + + " return 3;\n" + + " case 2629 :\n" + + " return 3;\n" + + " case 2630 :\n" + + " return 3;\n" + + " case 2631 :\n" + + " return 3;\n" + + " case 2632 :\n" + + " return 3;\n" + + " case 2633 :\n" + + " return 3;\n" + + " case 2634 :\n" + + " return 3;\n" + + " case 2635 :\n" + + " return 3;\n" + + " case 2636 :\n" + + " return 3;\n" + + " case 2637 :\n" + + " return 3;\n" + + " case 2638 :\n" + + " return 3;\n" + + " case 2639 :\n" + + " return 3;\n" + + " case 2640 :\n" + + " return 3;\n" + + " case 2641 :\n" + + " return 3;\n" + + " case 2642 :\n" + + " return 3;\n" + + " case 2643 :\n" + + " return 3;\n" + + " case 2644 :\n" + + " return 3;\n" + + " case 2645 :\n" + + " return 3;\n" + + " case 2646 :\n" + + " return 3;\n" + + " case 2647 :\n" + + " return 3;\n" + + " case 2648 :\n" + + " return 3;\n" + + " case 2649 :\n" + + " return 3;\n" + + " case 2650 :\n" + + " return 3;\n" + + " case 2651 :\n" + + " return 3;\n" + + " case 2652 :\n" + + " return 3;\n" + + " case 2653 :\n" + + " return 3;\n" + + " case 2654 :\n" + + " return 3;\n" + + " case 2655 :\n" + + " return 3;\n" + + " case 2656 :\n" + + " return 3;\n" + + " case 2657 :\n" + + " return 3;\n" + + " case 2658 :\n" + + " return 3;\n" + + " case 2659 :\n" + + " return 3;\n" + + " case 2660 :\n" + + " return 3;\n" + + " case 2661 :\n" + + " return 3;\n" + + " case 2662 :\n" + + " return 3;\n" + + " case 2663 :\n" + + " return 3;\n" + + " case 2664 :\n" + + " return 3;\n" + + " case 2665 :\n" + + " return 3;\n" + + " case 2666 :\n" + + " return 3;\n" + + " case 2667 :\n" + + " return 3;\n" + + " case 2668 :\n" + + " return 3;\n" + + " case 2669 :\n" + + " return 3;\n" + + " case 2670 :\n" + + " return 3;\n" + + " case 2671 :\n" + + " return 3;\n" + + " case 2672 :\n" + + " return 3;\n" + + " case 2673 :\n" + + " return 3;\n" + + " case 2674 :\n" + + " return 3;\n" + + " case 2675 :\n" + + " return 3;\n" + + " case 2676 :\n" + + " return 3;\n" + + " case 2677 :\n" + + " return 3;\n" + + " case 2678 :\n" + + " return 3;\n" + + " case 2679 :\n" + + " return 3;\n" + + " case 2680 :\n" + + " return 3;\n" + + " case 2681 :\n" + + " return 3;\n" + + " case 2682 :\n" + + " return 3;\n" + + " case 2683 :\n" + + " return 3;\n" + + " case 2684 :\n" + + " return 3;\n" + + " case 2685 :\n" + + " return 3;\n" + + " case 2686 :\n" + + " return 3;\n" + + " case 2687 :\n" + + " return 3;\n" + + " case 2688 :\n" + + " return 3;\n" + + " case 2689 :\n" + + " return 3;\n" + + " case 2690 :\n" + + " return 3;\n" + + " case 2691 :\n" + + " return 3;\n" + + " case 2692 :\n" + + " return 3;\n" + + " case 2693 :\n" + + " return 3;\n" + + " case 2694 :\n" + + " return 3;\n" + + " case 2695 :\n" + + " return 3;\n" + + " case 2696 :\n" + + " return 3;\n" + + " case 2697 :\n" + + " return 3;\n" + + " case 2698 :\n" + + " return 3;\n" + + " case 2699 :\n" + + " return 3;\n" + + " case 2700 :\n" + + " return 3;\n" + + " case 2701 :\n" + + " return 3;\n" + + " case 2702 :\n" + + " return 3;\n" + + " case 2703 :\n" + + " return 3;\n" + + " case 2704 :\n" + + " return 3;\n" + + " case 2705 :\n" + + " return 3;\n" + + " case 2706 :\n" + + " return 3;\n" + + " case 2707 :\n" + + " return 3;\n" + + " case 2708 :\n" + + " return 3;\n" + + " case 2709 :\n" + + " return 3;\n" + + " case 2710 :\n" + + " return 3;\n" + + " case 2711 :\n" + + " return 3;\n" + + " case 2712 :\n" + + " return 3;\n" + + " case 2713 :\n" + + " return 3;\n" + + " case 2714 :\n" + + " return 3;\n" + + " case 2715 :\n" + + " return 3;\n" + + " case 2716 :\n" + + " return 3;\n" + + " case 2717 :\n" + + " return 3;\n" + + " case 2718 :\n" + + " return 3;\n" + + " case 2719 :\n" + + " return 3;\n" + + " case 2720 :\n" + + " return 3;\n" + + " case 2721 :\n" + + " return 3;\n" + + " case 2722 :\n" + + " return 3;\n" + + " case 2723 :\n" + + " return 3;\n" + + " case 2724 :\n" + + " return 3;\n" + + " case 2725 :\n" + + " return 3;\n" + + " case 2726 :\n" + + " return 3;\n" + + " case 2727 :\n" + + " return 3;\n" + + " case 2728 :\n" + + " return 3;\n" + + " case 2729 :\n" + + " return 3;\n" + + " case 2730 :\n" + + " return 3;\n" + + " case 2731 :\n" + + " return 3;\n" + + " case 2732 :\n" + + " return 3;\n" + + " case 2733 :\n" + + " return 3;\n" + + " case 2734 :\n" + + " return 3;\n" + + " case 2735 :\n" + + " return 3;\n" + + " case 2736 :\n" + + " return 3;\n" + + " case 2737 :\n" + + " return 3;\n" + + " case 2738 :\n" + + " return 3;\n" + + " case 2739 :\n" + + " return 3;\n" + + " case 2740 :\n" + + " return 3;\n" + + " case 2741 :\n" + + " return 3;\n" + + " case 2742 :\n" + + " return 3;\n" + + " case 2743 :\n" + + " return 3;\n" + + " case 2744 :\n" + + " return 3;\n" + + " case 2745 :\n" + + " return 3;\n" + + " case 2746 :\n" + + " return 3;\n" + + " case 2747 :\n" + + " return 3;\n" + + " case 2748 :\n" + + " return 3;\n" + + " case 2749 :\n" + + " return 3;\n" + + " case 2750 :\n" + + " return 3;\n" + + " case 2751 :\n" + + " return 3;\n" + + " case 2752 :\n" + + " return 3;\n" + + " case 2753 :\n" + + " return 3;\n" + + " case 2754 :\n" + + " return 3;\n" + + " case 2755 :\n" + + " return 3;\n" + + " case 2756 :\n" + + " return 3;\n" + + " case 2757 :\n" + + " return 3;\n" + + " case 2758 :\n" + + " return 3;\n" + + " case 2759 :\n" + + " return 3;\n" + + " case 2760 :\n" + + " return 3;\n" + + " case 2761 :\n" + + " return 3;\n" + + " case 2762 :\n" + + " return 3;\n" + + " case 2763 :\n" + + " return 3;\n" + + " case 2764 :\n" + + " return 3;\n" + + " case 2765 :\n" + + " return 3;\n" + + " case 2766 :\n" + + " return 3;\n" + + " case 2767 :\n" + + " return 3;\n" + + " case 2768 :\n" + + " return 3;\n" + + " case 2769 :\n" + + " return 3;\n" + + " case 2770 :\n" + + " return 3;\n" + + " case 2771 :\n" + + " return 3;\n" + + " case 2772 :\n" + + " return 3;\n" + + " case 2773 :\n" + + " return 3;\n" + + " case 2774 :\n" + + " return 3;\n" + + " case 2775 :\n" + + " return 3;\n" + + " case 2776 :\n" + + " return 3;\n" + + " case 2777 :\n" + + " return 3;\n" + + " case 2778 :\n" + + " return 3;\n" + + " case 2779 :\n" + + " return 3;\n" + + " case 2780 :\n" + + " return 3;\n" + + " case 2781 :\n" + + " return 3;\n" + + " case 2782 :\n" + + " return 3;\n" + + " case 2783 :\n" + + " return 3;\n" + + " case 2784 :\n" + + " return 3;\n" + + " case 2785 :\n" + + " return 3;\n" + + " case 2786 :\n" + + " return 3;\n" + + " case 2787 :\n" + + " return 3;\n" + + " case 2788 :\n" + + " return 3;\n" + + " case 2789 :\n" + + " return 3;\n" + + " case 2790 :\n" + + " return 3;\n" + + " case 2791 :\n" + + " return 3;\n" + + " case 2792 :\n" + + " return 3;\n" + + " case 2793 :\n" + + " return 3;\n" + + " case 2794 :\n" + + " return 3;\n" + + " case 2795 :\n" + + " return 3;\n" + + " case 2796 :\n" + + " return 3;\n" + + " case 2797 :\n" + + " return 3;\n" + + " case 2798 :\n" + + " return 3;\n" + + " case 2799 :\n" + + " return 3;\n" + + " case 2800 :\n" + + " return 3;\n" + + " case 2801 :\n" + + " return 3;\n" + + " case 2802 :\n" + + " return 3;\n" + + " case 2803 :\n" + + " return 3;\n" + + " case 2804 :\n" + + " return 3;\n" + + " case 2805 :\n" + + " return 3;\n" + + " case 2806 :\n" + + " return 3;\n" + + " case 2807 :\n" + + " return 3;\n" + + " case 2808 :\n" + + " return 3;\n" + + " case 2809 :\n" + + " return 3;\n" + + " case 2810 :\n" + + " return 3;\n" + + " case 2811 :\n" + + " return 3;\n" + + " case 2812 :\n" + + " return 3;\n" + + " case 2813 :\n" + + " return 3;\n" + + " case 2814 :\n" + + " return 3;\n" + + " case 2815 :\n" + + " return 3;\n" + + " case 2816 :\n" + + " return 3;\n" + + " case 2817 :\n" + + " return 3;\n" + + " case 2818 :\n" + + " return 3;\n" + + " case 2819 :\n" + + " return 3;\n" + + " case 2820 :\n" + + " return 3;\n" + + " case 2821 :\n" + + " return 3;\n" + + " case 2822 :\n" + + " return 3;\n" + + " case 2823 :\n" + + " return 3;\n" + + " case 2824 :\n" + + " return 3;\n" + + " case 2825 :\n" + + " return 3;\n" + + " case 2826 :\n" + + " return 3;\n" + + " case 2827 :\n" + + " return 3;\n" + + " case 2828 :\n" + + " return 3;\n" + + " case 2829 :\n" + + " return 3;\n" + + " case 2830 :\n" + + " return 3;\n" + + " case 2831 :\n" + + " return 3;\n" + + " case 2832 :\n" + + " return 3;\n" + + " case 2833 :\n" + + " return 3;\n" + + " case 2834 :\n" + + " return 3;\n" + + " case 2835 :\n" + + " return 3;\n" + + " case 2836 :\n" + + " return 3;\n" + + " case 2837 :\n" + + " return 3;\n" + + " case 2838 :\n" + + " return 3;\n" + + " case 2839 :\n" + + " return 3;\n" + + " case 2840 :\n" + + " return 3;\n" + + " case 2841 :\n" + + " return 3;\n" + + " case 2842 :\n" + + " return 3;\n" + + " case 2843 :\n" + + " return 3;\n" + + " case 2844 :\n" + + " return 3;\n" + + " case 2845 :\n" + + " return 3;\n" + + " case 2846 :\n" + + " return 3;\n" + + " case 2847 :\n" + + " return 3;\n" + + " case 2848 :\n" + + " return 3;\n" + + " case 2849 :\n" + + " return 3;\n" + + " case 2850 :\n" + + " return 3;\n" + + " case 2851 :\n" + + " return 3;\n" + + " case 2852 :\n" + + " return 3;\n" + + " case 2853 :\n" + + " return 3;\n" + + " case 2854 :\n" + + " return 3;\n" + + " case 2855 :\n" + + " return 3;\n" + + " case 2856 :\n" + + " return 3;\n" + + " case 2857 :\n" + + " return 3;\n" + + " case 2858 :\n" + + " return 3;\n" + + " case 2859 :\n" + + " return 3;\n" + + " case 2860 :\n" + + " return 3;\n" + + " case 2861 :\n" + + " return 3;\n" + + " case 2862 :\n" + + " return 3;\n" + + " case 2863 :\n" + + " return 3;\n" + + " case 2864 :\n" + + " return 3;\n" + + " case 2865 :\n" + + " return 3;\n" + + " case 2866 :\n" + + " return 3;\n" + + " case 2867 :\n" + + " return 3;\n" + + " case 2868 :\n" + + " return 3;\n" + + " case 2869 :\n" + + " return 3;\n" + + " case 2870 :\n" + + " return 3;\n" + + " case 2871 :\n" + + " return 3;\n" + + " case 2872 :\n" + + " return 3;\n" + + " case 2873 :\n" + + " return 3;\n" + + " case 2874 :\n" + + " return 3;\n" + + " case 2875 :\n" + + " return 3;\n" + + " case 2876 :\n" + + " return 3;\n" + + " case 2877 :\n" + + " return 3;\n" + + " case 2878 :\n" + + " return 3;\n" + + " case 2879 :\n" + + " return 3;\n" + + " case 2880 :\n" + + " return 3;\n" + + " case 2881 :\n" + + " return 3;\n" + + " case 2882 :\n" + + " return 3;\n" + + " case 2883 :\n" + + " return 3;\n" + + " case 2884 :\n" + + " return 3;\n" + + " case 2885 :\n" + + " return 3;\n" + + " case 2886 :\n" + + " return 3;\n" + + " case 2887 :\n" + + " return 3;\n" + + " case 2888 :\n" + + " return 3;\n" + + " case 2889 :\n" + + " return 3;\n" + + " case 2890 :\n" + + " return 3;\n" + + " case 2891 :\n" + + " return 3;\n" + + " case 2892 :\n" + + " return 3;\n" + + " case 2893 :\n" + + " return 3;\n" + + " case 2894 :\n" + + " return 3;\n" + + " case 2895 :\n" + + " return 3;\n" + + " case 2896 :\n" + + " return 3;\n" + + " case 2897 :\n" + + " return 3;\n" + + " case 2898 :\n" + + " return 3;\n" + + " case 2899 :\n" + + " return 3;\n" + + " case 2900 :\n" + + " return 3;\n" + + " case 2901 :\n" + + " return 3;\n" + + " case 2902 :\n" + + " return 3;\n" + + " case 2903 :\n" + + " return 3;\n" + + " case 2904 :\n" + + " return 3;\n" + + " case 2905 :\n" + + " return 3;\n" + + " case 2906 :\n" + + " return 3;\n" + + " case 2907 :\n" + + " return 3;\n" + + " case 2908 :\n" + + " return 3;\n" + + " case 2909 :\n" + + " return 3;\n" + + " case 2910 :\n" + + " return 3;\n" + + " case 2911 :\n" + + " return 3;\n" + + " case 2912 :\n" + + " return 3;\n" + + " case 2913 :\n" + + " return 3;\n" + + " case 2914 :\n" + + " return 3;\n" + + " case 2915 :\n" + + " return 3;\n" + + " case 2916 :\n" + + " return 3;\n" + + " case 2917 :\n" + + " return 3;\n" + + " case 2918 :\n" + + " return 3;\n" + + " case 2919 :\n" + + " return 3;\n" + + " case 2920 :\n" + + " return 3;\n" + + " case 2921 :\n" + + " return 3;\n" + + " case 2922 :\n" + + " return 3;\n" + + " case 2923 :\n" + + " return 3;\n" + + " case 2924 :\n" + + " return 3;\n" + + " case 2925 :\n" + + " return 3;\n" + + " case 2926 :\n" + + " return 3;\n" + + " case 2927 :\n" + + " return 3;\n" + + " case 2928 :\n" + + " return 3;\n" + + " case 2929 :\n" + + " return 3;\n" + + " case 2930 :\n" + + " return 3;\n" + + " case 2931 :\n" + + " return 3;\n" + + " case 2932 :\n" + + " return 3;\n" + + " case 2933 :\n" + + " return 3;\n" + + " case 2934 :\n" + + " return 3;\n" + + " case 2935 :\n" + + " return 3;\n" + + " case 2936 :\n" + + " return 3;\n" + + " case 2937 :\n" + + " return 3;\n" + + " case 2938 :\n" + + " return 3;\n" + + " case 2939 :\n" + + " return 3;\n" + + " case 2940 :\n" + + " return 3;\n" + + " case 2941 :\n" + + " return 3;\n" + + " case 2942 :\n" + + " return 3;\n" + + " case 2943 :\n" + + " return 3;\n" + + " case 2944 :\n" + + " return 3;\n" + + " case 2945 :\n" + + " return 3;\n" + + " case 2946 :\n" + + " return 3;\n" + + " case 2947 :\n" + + " return 3;\n" + + " case 2948 :\n" + + " return 3;\n" + + " case 2949 :\n" + + " return 3;\n" + + " case 2950 :\n" + + " return 3;\n" + + " case 2951 :\n" + + " return 3;\n" + + " case 2952 :\n" + + " return 3;\n" + + " case 2953 :\n" + + " return 3;\n" + + " case 2954 :\n" + + " return 3;\n" + + " case 2955 :\n" + + " return 3;\n" + + " case 2956 :\n" + + " return 3;\n" + + " case 2957 :\n" + + " return 3;\n" + + " case 2958 :\n" + + " return 3;\n" + + " case 2959 :\n" + + " return 3;\n" + + " case 2960 :\n" + + " return 3;\n" + + " case 2961 :\n" + + " return 3;\n" + + " case 2962 :\n" + + " return 3;\n" + + " case 2963 :\n" + + " return 3;\n" + + " case 2964 :\n" + + " return 3;\n" + + " case 2965 :\n" + + " return 3;\n" + + " case 2966 :\n" + + " return 3;\n" + + " case 2967 :\n" + + " return 3;\n" + + " case 2968 :\n" + + " return 3;\n" + + " case 2969 :\n" + + " return 3;\n" + + " case 2970 :\n" + + " return 3;\n" + + " case 2971 :\n" + + " return 3;\n" + + " case 2972 :\n" + + " return 3;\n" + + " case 2973 :\n" + + " return 3;\n" + + " case 2974 :\n" + + " return 3;\n" + + " case 2975 :\n" + + " return 3;\n" + + " case 2976 :\n" + + " return 3;\n" + + " case 2977 :\n" + + " return 3;\n" + + " case 2978 :\n" + + " return 3;\n" + + " case 2979 :\n" + + " return 3;\n" + + " case 2980 :\n" + + " return 3;\n" + + " case 2981 :\n" + + " return 3;\n" + + " case 2982 :\n" + + " return 3;\n" + + " case 2983 :\n" + + " return 3;\n" + + " case 2984 :\n" + + " return 3;\n" + + " case 2985 :\n" + + " return 3;\n" + + " case 2986 :\n" + + " return 3;\n" + + " case 2987 :\n" + + " return 3;\n" + + " case 2988 :\n" + + " return 3;\n" + + " case 2989 :\n" + + " return 3;\n" + + " case 2990 :\n" + + " return 3;\n" + + " case 2991 :\n" + + " return 3;\n" + + " case 2992 :\n" + + " return 3;\n" + + " case 2993 :\n" + + " return 3;\n" + + " case 2994 :\n" + + " return 3;\n" + + " case 2995 :\n" + + " return 3;\n" + + " case 2996 :\n" + + " return 3;\n" + + " case 2997 :\n" + + " return 3;\n" + + " case 2998 :\n" + + " return 3;\n" + + " case 2999 :\n" + + " return 3;\n" + + " case 3000 :\n" + + " return 3;\n" + + " case 3001 :\n" + + " return 3;\n" + + " case 3002 :\n" + + " return 3;\n" + + " case 3003 :\n" + + " return 3;\n" + + " case 3004 :\n" + + " return 3;\n" + + " case 3005 :\n" + + " return 3;\n" + + " case 3006 :\n" + + " return 3;\n" + + " case 3007 :\n" + + " return 3;\n" + + " case 3008 :\n" + + " return 3;\n" + + " case 3009 :\n" + + " return 3;\n" + + " case 3010 :\n" + + " return 3;\n" + + " case 3011 :\n" + + " return 3;\n" + + " case 3012 :\n" + + " return 3;\n" + + " case 3013 :\n" + + " return 3;\n" + + " case 3014 :\n" + + " return 3;\n" + + " case 3015 :\n" + + " return 3;\n" + + " case 3016 :\n" + + " return 3;\n" + + " case 3017 :\n" + + " return 3;\n" + + " case 3018 :\n" + + " return 3;\n" + + " case 3019 :\n" + + " return 3;\n" + + " case 3020 :\n" + + " return 3;\n" + + " case 3021 :\n" + + " return 3;\n" + + " case 3022 :\n" + + " return 3;\n" + + " case 3023 :\n" + + " return 3;\n" + + " case 3024 :\n" + + " return 3;\n" + + " case 3025 :\n" + + " return 3;\n" + + " case 3026 :\n" + + " return 3;\n" + + " case 3027 :\n" + + " return 3;\n" + + " case 3028 :\n" + + " return 3;\n" + + " case 3029 :\n" + + " return 3;\n" + + " case 3030 :\n" + + " return 3;\n" + + " case 3031 :\n" + + " return 3;\n" + + " case 3032 :\n" + + " return 3;\n" + + " case 3033 :\n" + + " return 3;\n" + + " case 3034 :\n" + + " return 3;\n" + + " case 3035 :\n" + + " return 3;\n" + + " case 3036 :\n" + + " return 3;\n" + + " case 3037 :\n" + + " return 3;\n" + + " case 3038 :\n" + + " return 3;\n" + + " case 3039 :\n" + + " return 3;\n" + + " case 3040 :\n" + + " return 3;\n" + + " case 3041 :\n" + + " return 3;\n" + + " case 3042 :\n" + + " return 3;\n" + + " case 3043 :\n" + + " return 3;\n" + + " case 3044 :\n" + + " return 3;\n" + + " case 3045 :\n" + + " return 3;\n" + + " case 3046 :\n" + + " return 3;\n" + + " case 3047 :\n" + + " return 3;\n" + + " case 3048 :\n" + + " return 3;\n" + + " case 3049 :\n" + + " return 3;\n" + + " case 3050 :\n" + + " return 3;\n" + + " case 3051 :\n" + + " return 3;\n" + + " case 3052 :\n" + + " return 3;\n" + + " case 3053 :\n" + + " return 3;\n" + + " case 3054 :\n" + + " return 3;\n" + + " case 3055 :\n" + + " return 3;\n" + + " case 3056 :\n" + + " return 3;\n" + + " case 3057 :\n" + + " return 3;\n" + + " case 3058 :\n" + + " return 3;\n" + + " case 3059 :\n" + + " return 3;\n" + + " case 3060 :\n" + + " return 3;\n" + + " case 3061 :\n" + + " return 3;\n" + + " case 3062 :\n" + + " return 3;\n" + + " case 3063 :\n" + + " return 3;\n" + + " case 3064 :\n" + + " return 3;\n" + + " case 3065 :\n" + + " return 3;\n" + + " case 3066 :\n" + + " return 3;\n" + + " case 3067 :\n" + + " return 3;\n" + + " case 3068 :\n" + + " return 3;\n" + + " case 3069 :\n" + + " return 3;\n" + + " case 3070 :\n" + + " return 3;\n" + + " case 3071 :\n" + + " return 3;\n" + + " case 3072 :\n" + + " return 3;\n" + + " case 3073 :\n" + + " return 3;\n" + + " case 3074 :\n" + + " return 3;\n" + + " case 3075 :\n" + + " return 3;\n" + + " case 3076 :\n" + + " return 3;\n" + + " case 3077 :\n" + + " return 3;\n" + + " case 3078 :\n" + + " return 3;\n" + + " case 3079 :\n" + + " return 3;\n" + + " case 3080 :\n" + + " return 3;\n" + + " case 3081 :\n" + + " return 3;\n" + + " case 3082 :\n" + + " return 3;\n" + + " case 3083 :\n" + + " return 3;\n" + + " case 3084 :\n" + + " return 3;\n" + + " case 3085 :\n" + + " return 3;\n" + + " case 3086 :\n" + + " return 3;\n" + + " case 3087 :\n" + + " return 3;\n" + + " case 3088 :\n" + + " return 3;\n" + + " case 3089 :\n" + + " return 3;\n" + + " case 3090 :\n" + + " return 3;\n" + + " case 3091 :\n" + + " return 3;\n" + + " case 3092 :\n" + + " return 3;\n" + + " case 3093 :\n" + + " return 3;\n" + + " case 3094 :\n" + + " return 3;\n" + + " case 3095 :\n" + + " return 3;\n" + + " case 3096 :\n" + + " return 3;\n" + + " case 3097 :\n" + + " return 3;\n" + + " case 3098 :\n" + + " return 3;\n" + + " case 3099 :\n" + + " return 3;\n" + + " case 3100 :\n" + + " return 3;\n" + + " case 3101 :\n" + + " return 3;\n" + + " case 3102 :\n" + + " return 3;\n" + + " case 3103 :\n" + + " return 3;\n" + + " case 3104 :\n" + + " return 3;\n" + + " case 3105 :\n" + + " return 3;\n" + + " case 3106 :\n" + + " return 3;\n" + + " case 3107 :\n" + + " return 3;\n" + + " case 3108 :\n" + + " return 3;\n" + + " case 3109 :\n" + + " return 3;\n" + + " case 3110 :\n" + + " return 3;\n" + + " case 3111 :\n" + + " return 3;\n" + + " case 3112 :\n" + + " return 3;\n" + + " case 3113 :\n" + + " return 3;\n" + + " case 3114 :\n" + + " return 3;\n" + + " case 3115 :\n" + + " return 3;\n" + + " case 3116 :\n" + + " return 3;\n" + + " case 3117 :\n" + + " return 3;\n" + + " case 3118 :\n" + + " return 3;\n" + + " case 3119 :\n" + + " return 3;\n" + + " case 3120 :\n" + + " return 3;\n" + + " case 3121 :\n" + + " return 3;\n" + + " case 3122 :\n" + + " return 3;\n" + + " case 3123 :\n" + + " return 3;\n" + + " case 3124 :\n" + + " return 3;\n" + + " case 3125 :\n" + + " return 3;\n" + + " case 3126 :\n" + + " return 3;\n" + + " case 3127 :\n" + + " return 3;\n" + + " case 3128 :\n" + + " return 3;\n" + + " case 3129 :\n" + + " return 3;\n" + + " case 3130 :\n" + + " return 3;\n" + + " case 3131 :\n" + + " return 3;\n" + + " case 3132 :\n" + + " return 3;\n" + + " case 3133 :\n" + + " return 3;\n" + + " case 3134 :\n" + + " return 3;\n" + + " case 3135 :\n" + + " return 3;\n" + + " case 3136 :\n" + + " return 3;\n" + + " case 3137 :\n" + + " return 3;\n" + + " case 3138 :\n" + + " return 3;\n" + + " case 3139 :\n" + + " return 3;\n" + + " case 3140 :\n" + + " return 3;\n" + + " case 3141 :\n" + + " return 3;\n" + + " case 3142 :\n" + + " return 3;\n" + + " case 3143 :\n" + + " return 3;\n" + + " case 3144 :\n" + + " return 3;\n" + + " case 3145 :\n" + + " return 3;\n" + + " case 3146 :\n" + + " return 3;\n" + + " case 3147 :\n" + + " return 3;\n" + + " case 3148 :\n" + + " return 3;\n" + + " case 3149 :\n" + + " return 3;\n" + + " case 3150 :\n" + + " return 3;\n" + + " case 3151 :\n" + + " return 3;\n" + + " case 3152 :\n" + + " return 3;\n" + + " case 3153 :\n" + + " return 3;\n" + + " case 3154 :\n" + + " return 3;\n" + + " case 3155 :\n" + + " return 3;\n" + + " case 3156 :\n" + + " return 3;\n" + + " case 3157 :\n" + + " return 3;\n" + + " case 3158 :\n" + + " return 3;\n" + + " case 3159 :\n" + + " return 3;\n" + + " case 3160 :\n" + + " return 3;\n" + + " case 3161 :\n" + + " return 3;\n" + + " case 3162 :\n" + + " return 3;\n" + + " case 3163 :\n" + + " return 3;\n" + + " case 3164 :\n" + + " return 3;\n" + + " case 3165 :\n" + + " return 3;\n" + + " case 3166 :\n" + + " return 3;\n" + + " case 3167 :\n" + + " return 3;\n" + + " case 3168 :\n" + + " return 3;\n" + + " case 3169 :\n" + + " return 3;\n" + + " case 3170 :\n" + + " return 3;\n" + + " case 3171 :\n" + + " return 3;\n" + + " case 3172 :\n" + + " return 3;\n" + + " case 3173 :\n" + + " return 3;\n" + + " case 3174 :\n" + + " return 3;\n" + + " case 3175 :\n" + + " return 3;\n" + + " case 3176 :\n" + + " return 3;\n" + + " case 3177 :\n" + + " return 3;\n" + + " case 3178 :\n" + + " return 3;\n" + + " case 3179 :\n" + + " return 3;\n" + + " case 3180 :\n" + + " return 3;\n" + + " case 3181 :\n" + + " return 3;\n" + + " case 3182 :\n" + + " return 3;\n" + + " case 3183 :\n" + + " return 3;\n" + + " case 3184 :\n" + + " return 3;\n" + + " case 3185 :\n" + + " return 3;\n" + + " case 3186 :\n" + + " return 3;\n" + + " case 3187 :\n" + + " return 3;\n" + + " case 3188 :\n" + + " return 3;\n" + + " case 3189 :\n" + + " return 3;\n" + + " case 3190 :\n" + + " return 3;\n" + + " case 3191 :\n" + + " return 3;\n" + + " case 3192 :\n" + + " return 3;\n" + + " case 3193 :\n" + + " return 3;\n" + + " case 3194 :\n" + + " return 3;\n" + + " case 3195 :\n" + + " return 3;\n" + + " case 3196 :\n" + + " return 3;\n" + + " case 3197 :\n" + + " return 3;\n" + + " case 3198 :\n" + + " return 3;\n" + + " case 3199 :\n" + + " return 3;\n" + + " case 3200 :\n" + + " return 3;\n" + + " case 3201 :\n" + + " return 3;\n" + + " case 3202 :\n" + + " return 3;\n" + + " case 3203 :\n" + + " return 3;\n" + + " case 3204 :\n" + + " return 3;\n" + + " case 3205 :\n" + + " return 3;\n" + + " case 3206 :\n" + + " return 3;\n" + + " case 3207 :\n" + + " return 3;\n" + + " case 3208 :\n" + + " return 3;\n" + + " case 3209 :\n" + + " return 3;\n" + + " case 3210 :\n" + + " return 3;\n" + + " case 3211 :\n" + + " return 3;\n" + + " case 3212 :\n" + + " return 3;\n" + + " case 3213 :\n" + + " return 3;\n" + + " case 3214 :\n" + + " return 3;\n" + + " case 3215 :\n" + + " return 3;\n" + + " case 3216 :\n" + + " return 3;\n" + + " case 3217 :\n" + + " return 3;\n" + + " case 3218 :\n" + + " return 3;\n" + + " case 3219 :\n" + + " return 3;\n" + + " case 3220 :\n" + + " return 3;\n" + + " case 3221 :\n" + + " return 3;\n" + + " case 3222 :\n" + + " return 3;\n" + + " case 3223 :\n" + + " return 3;\n" + + " case 3224 :\n" + + " return 3;\n" + + " case 3225 :\n" + + " return 3;\n" + + " case 3226 :\n" + + " return 3;\n" + + " case 3227 :\n" + + " return 3;\n" + + " case 3228 :\n" + + " return 3;\n" + + " case 3229 :\n" + + " return 3;\n" + + " case 3230 :\n" + + " return 3;\n" + + " case 3231 :\n" + + " return 3;\n" + + " case 3232 :\n" + + " return 3;\n" + + " case 3233 :\n" + + " return 3;\n" + + " case 3234 :\n" + + " return 3;\n" + + " case 3235 :\n" + + " return 3;\n" + + " case 3236 :\n" + + " return 3;\n" + + " case 3237 :\n" + + " return 3;\n" + + " case 3238 :\n" + + " return 3;\n" + + " case 3239 :\n" + + " return 3;\n" + + " case 3240 :\n" + + " return 3;\n" + + " case 3241 :\n" + + " return 3;\n" + + " case 3242 :\n" + + " return 3;\n" + + " case 3243 :\n" + + " return 3;\n" + + " case 3244 :\n" + + " return 3;\n" + + " case 3245 :\n" + + " return 3;\n" + + " case 3246 :\n" + + " return 3;\n" + + " case 3247 :\n" + + " return 3;\n" + + " case 3248 :\n" + + " return 3;\n" + + " case 3249 :\n" + + " return 3;\n" + + " case 3250 :\n" + + " return 3;\n" + + " case 3251 :\n" + + " return 3;\n" + + " case 3252 :\n" + + " return 3;\n" + + " case 3253 :\n" + + " return 3;\n" + + " case 3254 :\n" + + " return 3;\n" + + " case 3255 :\n" + + " return 3;\n" + + " case 3256 :\n" + + " return 3;\n" + + " case 3257 :\n" + + " return 3;\n" + + " case 3258 :\n" + + " return 3;\n" + + " case 3259 :\n" + + " return 3;\n" + + " case 3260 :\n" + + " return 3;\n" + + " case 3261 :\n" + + " return 3;\n" + + " case 3262 :\n" + + " return 3;\n" + + " case 3263 :\n" + + " return 3;\n" + + " case 3264 :\n" + + " return 3;\n" + + " case 3265 :\n" + + " return 3;\n" + + " case 3266 :\n" + + " return 3;\n" + + " case 3267 :\n" + + " return 3;\n" + + " case 3268 :\n" + + " return 3;\n" + + " case 3269 :\n" + + " return 3;\n" + + " case 3270 :\n" + + " return 3;\n" + + " case 3271 :\n" + + " return 3;\n" + + " case 3272 :\n" + + " return 3;\n" + + " case 3273 :\n" + + " return 3;\n" + + " case 3274 :\n" + + " return 3;\n" + + " case 3275 :\n" + + " return 3;\n" + + " case 3276 :\n" + + " return 3;\n" + + " case 3277 :\n" + + " return 3;\n" + + " case 3278 :\n" + + " return 3;\n" + + " case 3279 :\n" + + " return 3;\n" + + " case 3280 :\n" + + " return 3;\n" + + " case 3281 :\n" + + " return 3;\n" + + " case 3282 :\n" + + " return 3;\n" + + " case 3283 :\n" + + " return 3;\n" + + " case 3284 :\n" + + " return 3;\n" + + " case 3285 :\n" + + " return 3;\n" + + " case 3286 :\n" + + " return 3;\n" + + " case 3287 :\n" + + " return 3;\n" + + " case 3288 :\n" + + " return 3;\n" + + " case 3289 :\n" + + " return 3;\n" + + " case 3290 :\n" + + " return 3;\n" + + " case 3291 :\n" + + " return 3;\n" + + " case 3292 :\n" + + " return 3;\n" + + " case 3293 :\n" + + " return 3;\n" + + " case 3294 :\n" + + " return 3;\n" + + " case 3295 :\n" + + " return 3;\n" + + " case 3296 :\n" + + " return 3;\n" + + " case 3297 :\n" + + " return 3;\n" + + " case 3298 :\n" + + " return 3;\n" + + " case 3299 :\n" + + " return 3;\n" + + " case 3300 :\n" + + " return 3;\n" + + " case 3301 :\n" + + " return 3;\n" + + " case 3302 :\n" + + " return 3;\n" + + " case 3303 :\n" + + " return 3;\n" + + " case 3304 :\n" + + " return 3;\n" + + " case 3305 :\n" + + " return 3;\n" + + " case 3306 :\n" + + " return 3;\n" + + " case 3307 :\n" + + " return 3;\n" + + " case 3308 :\n" + + " return 3;\n" + + " case 3309 :\n" + + " return 3;\n" + + " case 3310 :\n" + + " return 3;\n" + + " case 3311 :\n" + + " return 3;\n" + + " case 3312 :\n" + + " return 3;\n" + + " case 3313 :\n" + + " return 3;\n" + + " case 3314 :\n" + + " return 3;\n" + + " case 3315 :\n" + + " return 3;\n" + + " case 3316 :\n" + + " return 3;\n" + + " case 3317 :\n" + + " return 3;\n" + + " case 3318 :\n" + + " return 3;\n" + + " case 3319 :\n" + + " return 3;\n" + + " case 3320 :\n" + + " return 3;\n" + + " case 3321 :\n" + + " return 3;\n" + + " case 3322 :\n" + + " return 3;\n" + + " case 3323 :\n" + + " return 3;\n" + + " case 3324 :\n" + + " return 3;\n" + + " case 3325 :\n" + + " return 3;\n" + + " case 3326 :\n" + + " return 3;\n" + + " case 3327 :\n" + + " return 3;\n" + + " case 3328 :\n" + + " return 3;\n" + + " case 3329 :\n" + + " return 3;\n" + + " case 3330 :\n" + + " return 3;\n" + + " case 3331 :\n" + + " return 3;\n" + + " case 3332 :\n" + + " return 3;\n" + + " case 3333 :\n" + + " return 3;\n" + + " case 3334 :\n" + + " return 3;\n" + + " case 3335 :\n" + + " return 3;\n" + + " case 3336 :\n" + + " return 3;\n" + + " case 3337 :\n" + + " return 3;\n" + + " case 3338 :\n" + + " return 3;\n" + + " case 3339 :\n" + + " return 3;\n" + + " case 3340 :\n" + + " return 3;\n" + + " case 3341 :\n" + + " return 3;\n" + + " case 3342 :\n" + + " return 3;\n" + + " case 3343 :\n" + + " return 3;\n" + + " case 3344 :\n" + + " return 3;\n" + + " case 3345 :\n" + + " return 3;\n" + + " case 3346 :\n" + + " return 3;\n" + + " case 3347 :\n" + + " return 3;\n" + + " case 3348 :\n" + + " return 3;\n" + + " case 3349 :\n" + + " return 3;\n" + + " case 3350 :\n" + + " return 3;\n" + + " case 3351 :\n" + + " return 3;\n" + + " case 3352 :\n" + + " return 3;\n" + + " case 3353 :\n" + + " return 3;\n" + + " case 3354 :\n" + + " return 3;\n" + + " case 3355 :\n" + + " return 3;\n" + + " case 3356 :\n" + + " return 3;\n" + + " case 3357 :\n" + + " return 3;\n" + + " case 3358 :\n" + + " return 3;\n" + + " case 3359 :\n" + + " return 3;\n" + + " case 3360 :\n" + + " return 3;\n" + + " case 3361 :\n" + + " return 3;\n" + + " case 3362 :\n" + + " return 3;\n" + + " case 3363 :\n" + + " return 3;\n" + + " case 3364 :\n" + + " return 3;\n" + + " case 3365 :\n" + + " return 3;\n" + + " case 3366 :\n" + + " return 3;\n" + + " case 3367 :\n" + + " return 3;\n" + + " case 3368 :\n" + + " return 3;\n" + + " case 3369 :\n" + + " return 3;\n" + + " case 3370 :\n" + + " return 3;\n" + + " case 3371 :\n" + + " return 3;\n" + + " case 3372 :\n" + + " return 3;\n" + + " case 3373 :\n" + + " return 3;\n" + + " case 3374 :\n" + + " return 3;\n" + + " case 3375 :\n" + + " return 3;\n" + + " case 3376 :\n" + + " return 3;\n" + + " case 3377 :\n" + + " return 3;\n" + + " case 3378 :\n" + + " return 3;\n" + + " case 3379 :\n" + + " return 3;\n" + + " case 3380 :\n" + + " return 3;\n" + + " case 3381 :\n" + + " return 3;\n" + + " case 3382 :\n" + + " return 3;\n" + + " case 3383 :\n" + + " return 3;\n" + + " case 3384 :\n" + + " return 3;\n" + + " case 3385 :\n" + + " return 3;\n" + + " case 3386 :\n" + + " return 3;\n" + + " case 3387 :\n" + + " return 3;\n" + + " case 3388 :\n" + + " return 3;\n" + + " case 3389 :\n" + + " return 3;\n" + + " case 3390 :\n" + + " return 3;\n" + + " case 3391 :\n" + + " return 3;\n" + + " case 3392 :\n" + + " return 3;\n" + + " case 3393 :\n" + + " return 3;\n" + + " case 3394 :\n" + + " return 3;\n" + + " case 3395 :\n" + + " return 3;\n" + + " case 3396 :\n" + + " return 3;\n" + + " case 3397 :\n" + + " return 3;\n" + + " case 3398 :\n" + + " return 3;\n" + + " case 3399 :\n" + + " return 3;\n" + + " case 3400 :\n" + + " return 3;\n" + + " case 3401 :\n" + + " return 3;\n" + + " case 3402 :\n" + + " return 3;\n" + + " case 3403 :\n" + + " return 3;\n" + + " case 3404 :\n" + + " return 3;\n" + + " case 3405 :\n" + + " return 3;\n" + + " case 3406 :\n" + + " return 3;\n" + + " case 3407 :\n" + + " return 3;\n" + + " case 3408 :\n" + + " return 3;\n" + + " case 3409 :\n" + + " return 3;\n" + + " case 3410 :\n" + + " return 3;\n" + + " case 3411 :\n" + + " return 3;\n" + + " case 3412 :\n" + + " return 3;\n" + + " case 3413 :\n" + + " return 3;\n" + + " case 3414 :\n" + + " return 3;\n" + + " case 3415 :\n" + + " return 3;\n" + + " case 3416 :\n" + + " return 3;\n" + + " case 3417 :\n" + + " return 3;\n" + + " case 3418 :\n" + + " return 3;\n" + + " case 3419 :\n" + + " return 3;\n" + + " case 3420 :\n" + + " return 3;\n" + + " case 3421 :\n" + + " return 3;\n" + + " case 3422 :\n" + + " return 3;\n" + + " case 3423 :\n" + + " return 3;\n" + + " case 3424 :\n" + + " return 3;\n" + + " case 3425 :\n" + + " return 3;\n" + + " case 3426 :\n" + + " return 3;\n" + + " case 3427 :\n" + + " return 3;\n" + + " case 3428 :\n" + + " return 3;\n" + + " case 3429 :\n" + + " return 3;\n" + + " case 3430 :\n" + + " return 3;\n" + + " case 3431 :\n" + + " return 3;\n" + + " case 3432 :\n" + + " return 3;\n" + + " case 3433 :\n" + + " return 3;\n" + + " case 3434 :\n" + + " return 3;\n" + + " case 3435 :\n" + + " return 3;\n" + + " case 3436 :\n" + + " return 3;\n" + + " case 3437 :\n" + + " return 3;\n" + + " case 3438 :\n" + + " return 3;\n" + + " case 3439 :\n" + + " return 3;\n" + + " case 3440 :\n" + + " return 3;\n" + + " case 3441 :\n" + + " return 3;\n" + + " case 3442 :\n" + + " return 3;\n" + + " case 3443 :\n" + + " return 3;\n" + + " case 3444 :\n" + + " return 3;\n" + + " case 3445 :\n" + + " return 3;\n" + + " case 3446 :\n" + + " return 3;\n" + + " case 3447 :\n" + + " return 3;\n" + + " case 3448 :\n" + + " return 3;\n" + + " case 3449 :\n" + + " return 3;\n" + + " case 3450 :\n" + + " return 3;\n" + + " case 3451 :\n" + + " return 3;\n" + + " case 3452 :\n" + + " return 3;\n" + + " case 3453 :\n" + + " return 3;\n" + + " case 3454 :\n" + + " return 3;\n" + + " case 3455 :\n" + + " return 3;\n" + + " case 3456 :\n" + + " return 3;\n" + + " case 3457 :\n" + + " return 3;\n" + + " case 3458 :\n" + + " return 3;\n" + + " case 3459 :\n" + + " return 3;\n" + + " case 3460 :\n" + + " return 3;\n" + + " case 3461 :\n" + + " return 3;\n" + + " case 3462 :\n" + + " return 3;\n" + + " case 3463 :\n" + + " return 3;\n" + + " case 3464 :\n" + + " return 3;\n" + + " case 3465 :\n" + + " return 3;\n" + + " case 3466 :\n" + + " return 3;\n" + + " case 3467 :\n" + + " return 3;\n" + + " case 3468 :\n" + + " return 3;\n" + + " case 3469 :\n" + + " return 3;\n" + + " case 3470 :\n" + + " return 3;\n" + + " case 3471 :\n" + + " return 3;\n" + + " case 3472 :\n" + + " return 3;\n" + + " case 3473 :\n" + + " return 3;\n" + + " case 3474 :\n" + + " return 3;\n" + + " case 3475 :\n" + + " return 3;\n" + + " case 3476 :\n" + + " return 3;\n" + + " case 3477 :\n" + + " return 3;\n" + + " case 3478 :\n" + + " return 3;\n" + + " case 3479 :\n" + + " return 3;\n" + + " case 3480 :\n" + + " return 3;\n" + + " case 3481 :\n" + + " return 3;\n" + + " case 3482 :\n" + + " return 3;\n" + + " case 3483 :\n" + + " return 3;\n" + + " case 3484 :\n" + + " return 3;\n" + + " case 3485 :\n" + + " return 3;\n" + + " case 3486 :\n" + + " return 3;\n" + + " case 3487 :\n" + + " return 3;\n" + + " case 3488 :\n" + + " return 3;\n" + + " case 3489 :\n" + + " return 3;\n" + + " case 3490 :\n" + + " return 3;\n" + + " case 3491 :\n" + + " return 3;\n" + + " case 3492 :\n" + + " return 3;\n" + + " case 3493 :\n" + + " return 3;\n" + + " case 3494 :\n" + + " return 3;\n" + + " case 3495 :\n" + + " return 3;\n" + + " case 3496 :\n" + + " return 3;\n" + + " case 3497 :\n" + + " return 3;\n" + + " case 3498 :\n" + + " return 3;\n" + + " case 3499 :\n" + + " return 3;\n" + + " case 3500 :\n" + + " return 3;\n" + + " case 3501 :\n" + + " return 3;\n" + + " case 3502 :\n" + + " return 3;\n" + + " case 3503 :\n" + + " return 3;\n" + + " case 3504 :\n" + + " return 3;\n" + + " case 3505 :\n" + + " return 3;\n" + + " case 3506 :\n" + + " return 3;\n" + + " case 3507 :\n" + + " return 3;\n" + + " case 3508 :\n" + + " return 3;\n" + + " case 3509 :\n" + + " return 3;\n" + + " case 3510 :\n" + + " return 3;\n" + + " case 3511 :\n" + + " return 3;\n" + + " case 3512 :\n" + + " return 3;\n" + + " case 3513 :\n" + + " return 3;\n" + + " case 3514 :\n" + + " return 3;\n" + + " case 3515 :\n" + + " return 3;\n" + + " case 3516 :\n" + + " return 3;\n" + + " case 3517 :\n" + + " return 3;\n" + + " case 3518 :\n" + + " return 3;\n" + + " case 3519 :\n" + + " return 3;\n" + + " case 3520 :\n" + + " return 3;\n" + + " case 3521 :\n" + + " return 3;\n" + + " case 3522 :\n" + + " return 3;\n" + + " case 3523 :\n" + + " return 3;\n" + + " case 3524 :\n" + + " return 3;\n" + + " case 3525 :\n" + + " return 3;\n" + + " case 3526 :\n" + + " return 3;\n" + + " case 3527 :\n" + + " return 3;\n" + + " case 3528 :\n" + + " return 3;\n" + + " case 3529 :\n" + + " return 3;\n" + + " case 3530 :\n" + + " return 3;\n" + + " case 3531 :\n" + + " return 3;\n" + + " case 3532 :\n" + + " return 3;\n" + + " case 3533 :\n" + + " return 3;\n" + + " case 3534 :\n" + + " return 3;\n" + + " case 3535 :\n" + + " return 3;\n" + + " case 3536 :\n" + + " return 3;\n" + + " case 3537 :\n" + + " return 3;\n" + + " case 3538 :\n" + + " return 3;\n" + + " case 3539 :\n" + + " return 3;\n" + + " case 3540 :\n" + + " return 3;\n" + + " case 3541 :\n" + + " return 3;\n" + + " case 3542 :\n" + + " return 3;\n" + + " case 3543 :\n" + + " return 3;\n" + + " case 3544 :\n" + + " return 3;\n" + + " case 3545 :\n" + + " return 3;\n" + + " case 3546 :\n" + + " return 3;\n" + + " case 3547 :\n" + + " return 3;\n" + + " case 3548 :\n" + + " return 3;\n" + + " case 3549 :\n" + + " return 3;\n" + + " case 3550 :\n" + + " return 3;\n" + + " case 3551 :\n" + + " return 3;\n" + + " case 3552 :\n" + + " return 3;\n" + + " case 3553 :\n" + + " return 3;\n" + + " case 3554 :\n" + + " return 3;\n" + + " case 3555 :\n" + + " return 3;\n" + + " case 3556 :\n" + + " return 3;\n" + + " case 3557 :\n" + + " return 3;\n" + + " case 3558 :\n" + + " return 3;\n" + + " case 3559 :\n" + + " return 3;\n" + + " case 3560 :\n" + + " return 3;\n" + + " case 3561 :\n" + + " return 3;\n" + + " case 3562 :\n" + + " return 3;\n" + + " case 3563 :\n" + + " return 3;\n" + + " case 3564 :\n" + + " return 3;\n" + + " case 3565 :\n" + + " return 3;\n" + + " case 3566 :\n" + + " return 3;\n" + + " case 3567 :\n" + + " return 3;\n" + + " case 3568 :\n" + + " return 3;\n" + + " case 3569 :\n" + + " return 3;\n" + + " case 3570 :\n" + + " return 3;\n" + + " case 3571 :\n" + + " return 3;\n" + + " case 3572 :\n" + + " return 3;\n" + + " case 3573 :\n" + + " return 3;\n" + + " case 3574 :\n" + + " return 3;\n" + + " case 3575 :\n" + + " return 3;\n" + + " case 3576 :\n" + + " return 3;\n" + + " case 3577 :\n" + + " return 3;\n" + + " case 3578 :\n" + + " return 3;\n" + + " case 3579 :\n" + + " return 3;\n" + + " case 3580 :\n" + + " return 3;\n" + + " case 3581 :\n" + + " return 3;\n" + + " case 3582 :\n" + + " return 3;\n" + + " case 3583 :\n" + + " return 3;\n" + + " case 3584 :\n" + + " return 3;\n" + + " case 3585 :\n" + + " return 3;\n" + + " case 3586 :\n" + + " return 3;\n" + + " case 3587 :\n" + + " return 3;\n" + + " case 3588 :\n" + + " return 3;\n" + + " case 3589 :\n" + + " return 3;\n" + + " case 3590 :\n" + + " return 3;\n" + + " case 3591 :\n" + + " return 3;\n" + + " case 3592 :\n" + + " return 3;\n" + + " case 3593 :\n" + + " return 3;\n" + + " case 3594 :\n" + + " return 3;\n" + + " case 3595 :\n" + + " return 3;\n" + + " case 3596 :\n" + + " return 3;\n" + + " case 3597 :\n" + + " return 3;\n" + + " case 3598 :\n" + + " return 3;\n" + + " case 3599 :\n" + + " return 3;\n" + + " case 3600 :\n" + + " return 3;\n" + + " case 3601 :\n" + + " return 3;\n" + + " case 3602 :\n" + + " return 3;\n" + + " case 3603 :\n" + + " return 3;\n" + + " case 3604 :\n" + + " return 3;\n" + + " case 3605 :\n" + + " return 3;\n" + + " case 3606 :\n" + + " return 3;\n" + + " case 3607 :\n" + + " return 3;\n" + + " case 3608 :\n" + + " return 3;\n" + + " case 3609 :\n" + + " return 3;\n" + + " case 3610 :\n" + + " return 3;\n" + + " case 3611 :\n" + + " return 3;\n" + + " case 3612 :\n" + + " return 3;\n" + + " case 3613 :\n" + + " return 3;\n" + + " case 3614 :\n" + + " return 3;\n" + + " case 3615 :\n" + + " return 3;\n" + + " case 3616 :\n" + + " return 3;\n" + + " case 3617 :\n" + + " return 3;\n" + + " case 3618 :\n" + + " return 3;\n" + + " case 3619 :\n" + + " return 3;\n" + + " case 3620 :\n" + + " return 3;\n" + + " case 3621 :\n" + + " return 3;\n" + + " case 3622 :\n" + + " return 3;\n" + + " case 3623 :\n" + + " return 3;\n" + + " case 3624 :\n" + + " return 3;\n" + + " case 3625 :\n" + + " return 3;\n" + + " case 3626 :\n" + + " return 3;\n" + + " case 3627 :\n" + + " return 3;\n" + + " case 3628 :\n" + + " return 3;\n" + + " case 3629 :\n" + + " return 3;\n" + + " case 3630 :\n" + + " return 3;\n" + + " case 3631 :\n" + + " return 3;\n" + + " case 3632 :\n" + + " return 3;\n" + + " case 3633 :\n" + + " return 3;\n" + + " case 3634 :\n" + + " return 3;\n" + + " case 3635 :\n" + + " return 3;\n" + + " case 3636 :\n" + + " return 3;\n" + + " case 3637 :\n" + + " return 3;\n" + + " case 3638 :\n" + + " return 3;\n" + + " case 3639 :\n" + + " return 3;\n" + + " case 3640 :\n" + + " return 3;\n" + + " case 3641 :\n" + + " return 3;\n" + + " case 3642 :\n" + + " return 3;\n" + + " case 3643 :\n" + + " return 3;\n" + + " case 3644 :\n" + + " return 3;\n" + + " case 3645 :\n" + + " return 3;\n" + + " case 3646 :\n" + + " return 3;\n" + + " case 3647 :\n" + + " return 3;\n" + + " case 3648 :\n" + + " return 3;\n" + + " case 3649 :\n" + + " return 3;\n" + + " case 3650 :\n" + + " return 3;\n" + + " case 3651 :\n" + + " return 3;\n" + + " case 3652 :\n" + + " return 3;\n" + + " case 3653 :\n" + + " return 3;\n" + + " case 3654 :\n" + + " return 3;\n" + + " case 3655 :\n" + + " return 3;\n" + + " case 3656 :\n" + + " return 3;\n" + + " case 3657 :\n" + + " return 3;\n" + + " case 3658 :\n" + + " return 3;\n" + + " case 3659 :\n" + + " return 3;\n" + + " case 3660 :\n" + + " return 3;\n" + + " case 3661 :\n" + + " return 3;\n" + + " case 3662 :\n" + + " return 3;\n" + + " case 3663 :\n" + + " return 3;\n" + + " case 3664 :\n" + + " return 3;\n" + + " case 3665 :\n" + + " return 3;\n" + + " case 3666 :\n" + + " return 3;\n" + + " case 3667 :\n" + + " return 3;\n" + + " case 3668 :\n" + + " return 3;\n" + + " case 3669 :\n" + + " return 3;\n" + + " case 3670 :\n" + + " return 3;\n" + + " case 3671 :\n" + + " return 3;\n" + + " case 3672 :\n" + + " return 3;\n" + + " case 3673 :\n" + + " return 3;\n" + + " case 3674 :\n" + + " return 3;\n" + + " case 3675 :\n" + + " return 3;\n" + + " case 3676 :\n" + + " return 3;\n" + + " case 3677 :\n" + + " return 3;\n" + + " case 3678 :\n" + + " return 3;\n" + + " case 3679 :\n" + + " return 3;\n" + + " case 3680 :\n" + + " return 3;\n" + + " case 3681 :\n" + + " return 3;\n" + + " case 3682 :\n" + + " return 3;\n" + + " case 3683 :\n" + + " return 3;\n" + + " case 3684 :\n" + + " return 3;\n" + + " case 3685 :\n" + + " return 3;\n" + + " case 3686 :\n" + + " return 3;\n" + + " case 3687 :\n" + + " return 3;\n" + + " case 3688 :\n" + + " return 3;\n" + + " case 3689 :\n" + + " return 3;\n" + + " case 3690 :\n" + + " return 3;\n" + + " case 3691 :\n" + + " return 3;\n" + + " case 3692 :\n" + + " return 3;\n" + + " case 3693 :\n" + + " return 3;\n" + + " case 3694 :\n" + + " return 3;\n" + + " case 3695 :\n" + + " return 3;\n" + + " case 3696 :\n" + + " return 3;\n" + + " case 3697 :\n" + + " return 3;\n" + + " case 3698 :\n" + + " return 3;\n" + + " case 3699 :\n" + + " return 3;\n" + + " case 3700 :\n" + + " return 3;\n" + + " case 3701 :\n" + + " return 3;\n" + + " case 3702 :\n" + + " return 3;\n" + + " case 3703 :\n" + + " return 3;\n" + + " case 3704 :\n" + + " return 3;\n" + + " case 3705 :\n" + + " return 3;\n" + + " case 3706 :\n" + + " return 3;\n" + + " case 3707 :\n" + + " return 3;\n" + + " case 3708 :\n" + + " return 3;\n" + + " case 3709 :\n" + + " return 3;\n" + + " case 3710 :\n" + + " return 3;\n" + + " case 3711 :\n" + + " return 3;\n" + + " case 3712 :\n" + + " return 3;\n" + + " case 3713 :\n" + + " return 3;\n" + + " case 3714 :\n" + + " return 3;\n" + + " case 3715 :\n" + + " return 3;\n" + + " case 3716 :\n" + + " return 3;\n" + + " case 3717 :\n" + + " return 3;\n" + + " case 3718 :\n" + + " return 3;\n" + + " case 3719 :\n" + + " return 3;\n" + + " case 3720 :\n" + + " return 3;\n" + + " case 3721 :\n" + + " return 3;\n" + + " case 3722 :\n" + + " return 3;\n" + + " case 3723 :\n" + + " return 3;\n" + + " case 3724 :\n" + + " return 3;\n" + + " case 3725 :\n" + + " return 3;\n" + + " case 3726 :\n" + + " return 3;\n" + + " case 3727 :\n" + + " return 3;\n" + + " case 3728 :\n" + + " return 3;\n" + + " case 3729 :\n" + + " return 3;\n" + + " case 3730 :\n" + + " return 3;\n" + + " case 3731 :\n" + + " return 3;\n" + + " case 3732 :\n" + + " return 3;\n" + + " case 3733 :\n" + + " return 3;\n" + + " case 3734 :\n" + + " return 3;\n" + + " case 3735 :\n" + + " return 3;\n" + + " case 3736 :\n" + + " return 3;\n" + + " case 3737 :\n" + + " return 3;\n" + + " case 3738 :\n" + + " return 3;\n" + + " case 3739 :\n" + + " return 3;\n" + + " case 3740 :\n" + + " return 3;\n" + + " case 3741 :\n" + + " return 3;\n" + + " case 3742 :\n" + + " return 3;\n" + + " case 3743 :\n" + + " return 3;\n" + + " case 3744 :\n" + + " return 3;\n" + + " case 3745 :\n" + + " return 3;\n" + + " case 3746 :\n" + + " return 3;\n" + + " case 3747 :\n" + + " return 3;\n" + + " case 3748 :\n" + + " return 3;\n" + + " case 3749 :\n" + + " return 3;\n" + + " case 3750 :\n" + + " return 3;\n" + + " case 3751 :\n" + + " return 3;\n" + + " case 3752 :\n" + + " return 3;\n" + + " case 3753 :\n" + + " return 3;\n" + + " case 3754 :\n" + + " return 3;\n" + + " case 3755 :\n" + + " return 3;\n" + + " case 3756 :\n" + + " return 3;\n" + + " case 3757 :\n" + + " return 3;\n" + + " case 3758 :\n" + + " return 3;\n" + + " case 3759 :\n" + + " return 3;\n" + + " case 3760 :\n" + + " return 3;\n" + + " case 3761 :\n" + + " return 3;\n" + + " case 3762 :\n" + + " return 3;\n" + + " case 3763 :\n" + + " return 3;\n" + + " case 3764 :\n" + + " return 3;\n" + + " case 3765 :\n" + + " return 3;\n" + + " case 3766 :\n" + + " return 3;\n" + + " case 3767 :\n" + + " return 3;\n" + + " case 3768 :\n" + + " return 3;\n" + + " case 3769 :\n" + + " return 3;\n" + + " case 3770 :\n" + + " return 3;\n" + + " case 3771 :\n" + + " return 3;\n" + + " case 3772 :\n" + + " return 3;\n" + + " case 3773 :\n" + + " return 3;\n" + + " case 3774 :\n" + + " return 3;\n" + + " case 3775 :\n" + + " return 3;\n" + + " case 3776 :\n" + + " return 3;\n" + + " case 3777 :\n" + + " return 3;\n" + + " case 3778 :\n" + + " return 3;\n" + + " case 3779 :\n" + + " return 3;\n" + + " case 3780 :\n" + + " return 3;\n" + + " case 3781 :\n" + + " return 3;\n" + + " case 3782 :\n" + + " return 3;\n" + + " case 3783 :\n" + + " return 3;\n" + + " case 3784 :\n" + + " return 3;\n" + + " case 3785 :\n" + + " return 3;\n" + + " case 3786 :\n" + + " return 3;\n" + + " case 3787 :\n" + + " return 3;\n" + + " case 3788 :\n" + + " return 3;\n" + + " case 3789 :\n" + + " return 3;\n" + + " case 3790 :\n" + + " return 3;\n" + + " case 3791 :\n" + + " return 3;\n" + + " case 3792 :\n" + + " return 3;\n" + + " case 3793 :\n" + + " return 3;\n" + + " case 3794 :\n" + + " return 3;\n" + + " case 3795 :\n" + + " return 3;\n" + + " case 3796 :\n" + + " return 3;\n" + + " case 3797 :\n" + + " return 3;\n" + + " case 3798 :\n" + + " return 3;\n" + + " case 3799 :\n" + + " return 3;\n" + + " case 3800 :\n" + + " return 3;\n" + + " case 3801 :\n" + + " return 3;\n" + + " case 3802 :\n" + + " return 3;\n" + + " case 3803 :\n" + + " return 3;\n" + + " case 3804 :\n" + + " return 3;\n" + + " case 3805 :\n" + + " return 3;\n" + + " case 3806 :\n" + + " return 3;\n" + + " case 3807 :\n" + + " return 3;\n" + + " case 3808 :\n" + + " return 3;\n" + + " case 3809 :\n" + + " return 3;\n" + + " case 3810 :\n" + + " return 3;\n" + + " case 3811 :\n" + + " return 3;\n" + + " case 3812 :\n" + + " return 3;\n" + + " case 3813 :\n" + + " return 3;\n" + + " case 3814 :\n" + + " return 3;\n" + + " case 3815 :\n" + + " return 3;\n" + + " case 3816 :\n" + + " return 3;\n" + + " case 3817 :\n" + + " return 3;\n" + + " case 3818 :\n" + + " return 3;\n" + + " case 3819 :\n" + + " return 3;\n" + + " case 3820 :\n" + + " return 3;\n" + + " case 3821 :\n" + + " return 3;\n" + + " case 3822 :\n" + + " return 3;\n" + + " case 3823 :\n" + + " return 3;\n" + + " case 3824 :\n" + + " return 3;\n" + + " case 3825 :\n" + + " return 3;\n" + + " case 3826 :\n" + + " return 3;\n" + + " case 3827 :\n" + + " return 3;\n" + + " case 3828 :\n" + + " return 3;\n" + + " case 3829 :\n" + + " return 3;\n" + + " case 3830 :\n" + + " return 3;\n" + + " case 3831 :\n" + + " return 3;\n" + + " case 3832 :\n" + + " return 3;\n" + + " case 3833 :\n" + + " return 3;\n" + + " case 3834 :\n" + + " return 3;\n" + + " case 3835 :\n" + + " return 3;\n" + + " case 3836 :\n" + + " return 3;\n" + + " case 3837 :\n" + + " return 3;\n" + + " case 3838 :\n" + + " return 3;\n" + + " case 3839 :\n" + + " return 3;\n" + + " case 3840 :\n" + + " return 3;\n" + + " case 3841 :\n" + + " return 3;\n" + + " case 3842 :\n" + + " return 3;\n" + + " case 3843 :\n" + + " return 3;\n" + + " case 3844 :\n" + + " return 3;\n" + + " case 3845 :\n" + + " return 3;\n" + + " case 3846 :\n" + + " return 3;\n" + + " case 3847 :\n" + + " return 3;\n" + + " case 3848 :\n" + + " return 3;\n" + + " case 3849 :\n" + + " return 3;\n" + + " case 3850 :\n" + + " return 3;\n" + + " case 3851 :\n" + + " return 3;\n" + + " case 3852 :\n" + + " return 3;\n" + + " case 3853 :\n" + + " return 3;\n" + + " case 3854 :\n" + + " return 3;\n" + + " case 3855 :\n" + + " return 3;\n" + + " case 3856 :\n" + + " return 3;\n" + + " case 3857 :\n" + + " return 3;\n" + + " case 3858 :\n" + + " return 3;\n" + + " case 3859 :\n" + + " return 3;\n" + + " case 3860 :\n" + + " return 3;\n" + + " case 3861 :\n" + + " return 3;\n" + + " case 3862 :\n" + + " return 3;\n" + + " case 3863 :\n" + + " return 3;\n" + + " case 3864 :\n" + + " return 3;\n" + + " case 3865 :\n" + + " return 3;\n" + + " case 3866 :\n" + + " return 3;\n" + + " case 3867 :\n" + + " return 3;\n" + + " case 3868 :\n" + + " return 3;\n" + + " case 3869 :\n" + + " return 3;\n" + + " case 3870 :\n" + + " return 3;\n" + + " case 3871 :\n" + + " return 3;\n" + + " case 3872 :\n" + + " return 3;\n" + + " case 3873 :\n" + + " return 3;\n" + + " case 3874 :\n" + + " return 3;\n" + + " case 3875 :\n" + + " return 3;\n" + + " case 3876 :\n" + + " return 3;\n" + + " case 3877 :\n" + + " return 3;\n" + + " case 3878 :\n" + + " return 3;\n" + + " case 3879 :\n" + + " return 3;\n" + + " case 3880 :\n" + + " return 3;\n" + + " case 3881 :\n" + + " return 3;\n" + + " case 3882 :\n" + + " return 3;\n" + + " case 3883 :\n" + + " return 3;\n" + + " case 3884 :\n" + + " return 3;\n" + + " case 3885 :\n" + + " return 3;\n" + + " case 3886 :\n" + + " return 3;\n" + + " case 3887 :\n" + + " return 3;\n" + + " case 3888 :\n" + + " return 3;\n" + + " case 3889 :\n" + + " return 3;\n" + + " case 3890 :\n" + + " return 3;\n" + + " case 3891 :\n" + + " return 3;\n" + + " case 3892 :\n" + + " return 3;\n" + + " case 3893 :\n" + + " return 3;\n" + + " case 3894 :\n" + + " return 3;\n" + + " case 3895 :\n" + + " return 3;\n" + + " case 3896 :\n" + + " return 3;\n" + + " case 3897 :\n" + + " return 3;\n" + + " case 3898 :\n" + + " return 3;\n" + + " case 3899 :\n" + + " return 3;\n" + + " case 3900 :\n" + + " return 3;\n" + + " case 3901 :\n" + + " return 3;\n" + + " case 3902 :\n" + + " return 3;\n" + + " case 3903 :\n" + + " return 3;\n" + + " case 3904 :\n" + + " return 3;\n" + + " case 3905 :\n" + + " return 3;\n" + + " case 3906 :\n" + + " return 3;\n" + + " case 3907 :\n" + + " return 3;\n" + + " case 3908 :\n" + + " return 3;\n" + + " case 3909 :\n" + + " return 3;\n" + + " case 3910 :\n" + + " return 3;\n" + + " case 3911 :\n" + + " return 3;\n" + + " case 3912 :\n" + + " return 3;\n" + + " case 3913 :\n" + + " return 3;\n" + + " case 3914 :\n" + + " return 3;\n" + + " case 3915 :\n" + + " return 3;\n" + + " case 3916 :\n" + + " return 3;\n" + + " case 3917 :\n" + + " return 3;\n" + + " case 3918 :\n" + + " return 3;\n" + + " case 3919 :\n" + + " return 3;\n" + + " case 3920 :\n" + + " return 3;\n" + + " case 3921 :\n" + + " return 3;\n" + + " case 3922 :\n" + + " return 3;\n" + + " case 3923 :\n" + + " return 3;\n" + + " case 3924 :\n" + + " return 3;\n" + + " case 3925 :\n" + + " return 3;\n" + + " case 3926 :\n" + + " return 3;\n" + + " case 3927 :\n" + + " return 3;\n" + + " case 3928 :\n" + + " return 3;\n" + + " case 3929 :\n" + + " return 3;\n" + + " case 3930 :\n" + + " return 3;\n" + + " case 3931 :\n" + + " return 3;\n" + + " case 3932 :\n" + + " return 3;\n" + + " case 3933 :\n" + + " return 3;\n" + + " case 3934 :\n" + + " return 3;\n" + + " case 3935 :\n" + + " return 3;\n" + + " case 3936 :\n" + + " return 3;\n" + + " case 3937 :\n" + + " return 3;\n" + + " case 3938 :\n" + + " return 3;\n" + + " case 3939 :\n" + + " return 3;\n" + + " case 3940 :\n" + + " return 3;\n" + + " case 3941 :\n" + + " return 3;\n" + + " case 3942 :\n" + + " return 3;\n" + + " case 3943 :\n" + + " return 3;\n" + + " case 3944 :\n" + + " return 3;\n" + + " case 3945 :\n" + + " return 3;\n" + + " case 3946 :\n" + + " return 3;\n" + + " case 3947 :\n" + + " return 3;\n" + + " case 3948 :\n" + + " return 3;\n" + + " case 3949 :\n" + + " return 3;\n" + + " case 3950 :\n" + + " return 3;\n" + + " case 3951 :\n" + + " return 3;\n" + + " case 3952 :\n" + + " return 3;\n" + + " case 3953 :\n" + + " return 3;\n" + + " case 3954 :\n" + + " return 3;\n" + + " case 3955 :\n" + + " return 3;\n" + + " case 3956 :\n" + + " return 3;\n" + + " case 3957 :\n" + + " return 3;\n" + + " case 3958 :\n" + + " return 3;\n" + + " case 3959 :\n" + + " return 3;\n" + + " case 3960 :\n" + + " return 3;\n" + + " case 3961 :\n" + + " return 3;\n" + + " case 3962 :\n" + + " return 3;\n" + + " case 3963 :\n" + + " return 3;\n" + + " case 3964 :\n" + + " return 3;\n" + + " case 3965 :\n" + + " return 3;\n" + + " case 3966 :\n" + + " return 3;\n" + + " case 3967 :\n" + + " return 3;\n" + + " case 3968 :\n" + + " return 3;\n" + + " case 3969 :\n" + + " return 3;\n" + + " case 3970 :\n" + + " return 3;\n" + + " case 3971 :\n" + + " return 3;\n" + + " case 3972 :\n" + + " return 3;\n" + + " case 3973 :\n" + + " return 3;\n" + + " case 3974 :\n" + + " return 3;\n" + + " case 3975 :\n" + + " return 3;\n" + + " case 3976 :\n" + + " return 3;\n" + + " case 3977 :\n" + + " return 3;\n" + + " case 3978 :\n" + + " return 3;\n" + + " case 3979 :\n" + + " return 3;\n" + + " case 3980 :\n" + + " return 3;\n" + + " case 3981 :\n" + + " return 3;\n" + + " case 3982 :\n" + + " return 3;\n" + + " case 3983 :\n" + + " return 3;\n" + + " case 3984 :\n" + + " return 3;\n" + + " case 3985 :\n" + + " return 3;\n" + + " case 3986 :\n" + + " return 3;\n" + + " case 3987 :\n" + + " return 3;\n" + + " case 3988 :\n" + + " return 3;\n" + + " case 3989 :\n" + + " return 3;\n" + + " case 3990 :\n" + + " return 3;\n" + + " case 3991 :\n" + + " return 3;\n" + + " case 3992 :\n" + + " return 3;\n" + + " case 3993 :\n" + + " return 3;\n" + + " case 3994 :\n" + + " return 3;\n" + + " case 3995 :\n" + + " return 3;\n" + + " case 3996 :\n" + + " return 3;\n" + + " case 3997 :\n" + + " return 3;\n" + + " case 3998 :\n" + + " return 3;\n" + + " case 3999 :\n" + + " return 3;\n" + + " default:\n" + + " return -1;\n" + + " }\n" + + " } catch(Exception e) {\n" + + " //ignore\n" + + " } finally {\n" + + " System.out.println(\"Enter finally block\");\n" + + " System.out.println(\"Inside finally block\");\n" + + " System.out.println(\"Leave finally block\");\n" + + " }\n" + + " return -1;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(foo(1));\n" + + " }\n" + + "}"}, + null, + settings, + null, + "Enter finally block\n" + + "Inside finally block\n" + + "Leave finally block\n" + + "3", + null, + JavacTestOptions.EclipseJustification.EclipseBug169017); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=350095 +public void test0016() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + // only run in 1.5 or above + StringBuilder buffer = new StringBuilder(); + buffer + .append("0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119") + .append("1201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022") + .append("0320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528") + .append("6287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369") + .append("3703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524") + .append("5345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553") + .append("6537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619") + .append("6206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027") + .append("0370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578") + .append("6787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869") + .append("8708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529") + .append("5395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610") + .append("2710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089") + .append("1090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111") + .append("5211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214") + .append("1215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612") + .append("7712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339") + .append("1340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114") + .append("0214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464") + .append("1465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615") + .append("2715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589") + .append("1590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116") + .append("5216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714") + .append("1715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617") + .append("7717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839") + .append("1840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119") + .append("0219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964") + .append("1965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620") + .append("2720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089") + .append("2090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121") + .append("5221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214") + .append("2215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622") + .append("7722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339") + .append("2340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124") + .append("0224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464") + .append("246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500"); + + String[] src = { + "X.java", + "public enum X {\n" + + " X0(0),\n" + + " X1(1),\n" + + " X2(2),\n" + + " X3(3),\n" + + " X4(4),\n" + + " X5(5),\n" + + " X6(6),\n" + + " X7(7),\n" + + " X8(8),\n" + + " X9(9),\n" + + " X10(10),\n" + + " X11(11),\n" + + " X12(12),\n" + + " X13(13),\n" + + " X14(14),\n" + + " X15(15),\n" + + " X16(16),\n" + + " X17(17),\n" + + " X18(18),\n" + + " X19(19),\n" + + " X20(20),\n" + + " X21(21),\n" + + " X22(22),\n" + + " X23(23),\n" + + " X24(24),\n" + + " X25(25),\n" + + " X26(26),\n" + + " X27(27),\n" + + " X28(28),\n" + + " X29(29),\n" + + " X30(30),\n" + + " X31(31),\n" + + " X32(32),\n" + + " X33(33),\n" + + " X34(34),\n" + + " X35(35),\n" + + " X36(36),\n" + + " X37(37),\n" + + " X38(38),\n" + + " X39(39),\n" + + " X40(40),\n" + + " X41(41),\n" + + " X42(42),\n" + + " X43(43),\n" + + " X44(44),\n" + + " X45(45),\n" + + " X46(46),\n" + + " X47(47),\n" + + " X48(48),\n" + + " X49(49),\n" + + " X50(50),\n" + + " X51(51),\n" + + " X52(52),\n" + + " X53(53),\n" + + " X54(54),\n" + + " X55(55),\n" + + " X56(56),\n" + + " X57(57),\n" + + " X58(58),\n" + + " X59(59),\n" + + " X60(60),\n" + + " X61(61),\n" + + " X62(62),\n" + + " X63(63),\n" + + " X64(64),\n" + + " X65(65),\n" + + " X66(66),\n" + + " X67(67),\n" + + " X68(68),\n" + + " X69(69),\n" + + " X70(70),\n" + + " X71(71),\n" + + " X72(72),\n" + + " X73(73),\n" + + " X74(74),\n" + + " X75(75),\n" + + " X76(76),\n" + + " X77(77),\n" + + " X78(78),\n" + + " X79(79),\n" + + " X80(80),\n" + + " X81(81),\n" + + " X82(82),\n" + + " X83(83),\n" + + " X84(84),\n" + + " X85(85),\n" + + " X86(86),\n" + + " X87(87),\n" + + " X88(88),\n" + + " X89(89),\n" + + " X90(90),\n" + + " X91(91),\n" + + " X92(92),\n" + + " X93(93),\n" + + " X94(94),\n" + + " X95(95),\n" + + " X96(96),\n" + + " X97(97),\n" + + " X98(98),\n" + + " X99(99),\n" + + " X100(100),\n" + + " X101(101),\n" + + " X102(102),\n" + + " X103(103),\n" + + " X104(104),\n" + + " X105(105),\n" + + " X106(106),\n" + + " X107(107),\n" + + " X108(108),\n" + + " X109(109),\n" + + " X110(110),\n" + + " X111(111),\n" + + " X112(112),\n" + + " X113(113),\n" + + " X114(114),\n" + + " X115(115),\n" + + " X116(116),\n" + + " X117(117),\n" + + " X118(118),\n" + + " X119(119),\n" + + " X120(120),\n" + + " X121(121),\n" + + " X122(122),\n" + + " X123(123),\n" + + " X124(124),\n" + + " X125(125),\n" + + " X126(126),\n" + + " X127(127),\n" + + " X128(128),\n" + + " X129(129),\n" + + " X130(130),\n" + + " X131(131),\n" + + " X132(132),\n" + + " X133(133),\n" + + " X134(134),\n" + + " X135(135),\n" + + " X136(136),\n" + + " X137(137),\n" + + " X138(138),\n" + + " X139(139),\n" + + " X140(140),\n" + + " X141(141),\n" + + " X142(142),\n" + + " X143(143),\n" + + " X144(144),\n" + + " X145(145),\n" + + " X146(146),\n" + + " X147(147),\n" + + " X148(148),\n" + + " X149(149),\n" + + " X150(150),\n" + + " X151(151),\n" + + " X152(152),\n" + + " X153(153),\n" + + " X154(154),\n" + + " X155(155),\n" + + " X156(156),\n" + + " X157(157),\n" + + " X158(158),\n" + + " X159(159),\n" + + " X160(160),\n" + + " X161(161),\n" + + " X162(162),\n" + + " X163(163),\n" + + " X164(164),\n" + + " X165(165),\n" + + " X166(166),\n" + + " X167(167),\n" + + " X168(168),\n" + + " X169(169),\n" + + " X170(170),\n" + + " X171(171),\n" + + " X172(172),\n" + + " X173(173),\n" + + " X174(174),\n" + + " X175(175),\n" + + " X176(176),\n" + + " X177(177),\n" + + " X178(178),\n" + + " X179(179),\n" + + " X180(180),\n" + + " X181(181),\n" + + " X182(182),\n" + + " X183(183),\n" + + " X184(184),\n" + + " X185(185),\n" + + " X186(186),\n" + + " X187(187),\n" + + " X188(188),\n" + + " X189(189),\n" + + " X190(190),\n" + + " X191(191),\n" + + " X192(192),\n" + + " X193(193),\n" + + " X194(194),\n" + + " X195(195),\n" + + " X196(196),\n" + + " X197(197),\n" + + " X198(198),\n" + + " X199(199),\n" + + " X200(200),\n" + + " X201(201),\n" + + " X202(202),\n" + + " X203(203),\n" + + " X204(204),\n" + + " X205(205),\n" + + " X206(206),\n" + + " X207(207),\n" + + " X208(208),\n" + + " X209(209),\n" + + " X210(210),\n" + + " X211(211),\n" + + " X212(212),\n" + + " X213(213),\n" + + " X214(214),\n" + + " X215(215),\n" + + " X216(216),\n" + + " X217(217),\n" + + " X218(218),\n" + + " X219(219),\n" + + " X220(220),\n" + + " X221(221),\n" + + " X222(222),\n" + + " X223(223),\n" + + " X224(224),\n" + + " X225(225),\n" + + " X226(226),\n" + + " X227(227),\n" + + " X228(228),\n" + + " X229(229),\n" + + " X230(230),\n" + + " X231(231),\n" + + " X232(232),\n" + + " X233(233),\n" + + " X234(234),\n" + + " X235(235),\n" + + " X236(236),\n" + + " X237(237),\n" + + " X238(238),\n" + + " X239(239),\n" + + " X240(240),\n" + + " X241(241),\n" + + " X242(242),\n" + + " X243(243),\n" + + " X244(244),\n" + + " X245(245),\n" + + " X246(246),\n" + + " X247(247),\n" + + " X248(248),\n" + + " X249(249),\n" + + " X250(250),\n" + + " X251(251),\n" + + " X252(252),\n" + + " X253(253),\n" + + " X254(254),\n" + + " X255(255),\n" + + " X256(256),\n" + + " X257(257),\n" + + " X258(258),\n" + + " X259(259),\n" + + " X260(260),\n" + + " X261(261),\n" + + " X262(262),\n" + + " X263(263),\n" + + " X264(264),\n" + + " X265(265),\n" + + " X266(266),\n" + + " X267(267),\n" + + " X268(268),\n" + + " X269(269),\n" + + " X270(270),\n" + + " X271(271),\n" + + " X272(272),\n" + + " X273(273),\n" + + " X274(274),\n" + + " X275(275),\n" + + " X276(276),\n" + + " X277(277),\n" + + " X278(278),\n" + + " X279(279),\n" + + " X280(280),\n" + + " X281(281),\n" + + " X282(282),\n" + + " X283(283),\n" + + " X284(284),\n" + + " X285(285),\n" + + " X286(286),\n" + + " X287(287),\n" + + " X288(288),\n" + + " X289(289),\n" + + " X290(290),\n" + + " X291(291),\n" + + " X292(292),\n" + + " X293(293),\n" + + " X294(294),\n" + + " X295(295),\n" + + " X296(296),\n" + + " X297(297),\n" + + " X298(298),\n" + + " X299(299),\n" + + " X300(300),\n" + + " X301(301),\n" + + " X302(302),\n" + + " X303(303),\n" + + " X304(304),\n" + + " X305(305),\n" + + " X306(306),\n" + + " X307(307),\n" + + " X308(308),\n" + + " X309(309),\n" + + " X310(310),\n" + + " X311(311),\n" + + " X312(312),\n" + + " X313(313),\n" + + " X314(314),\n" + + " X315(315),\n" + + " X316(316),\n" + + " X317(317),\n" + + " X318(318),\n" + + " X319(319),\n" + + " X320(320),\n" + + " X321(321),\n" + + " X322(322),\n" + + " X323(323),\n" + + " X324(324),\n" + + " X325(325),\n" + + " X326(326),\n" + + " X327(327),\n" + + " X328(328),\n" + + " X329(329),\n" + + " X330(330),\n" + + " X331(331),\n" + + " X332(332),\n" + + " X333(333),\n" + + " X334(334),\n" + + " X335(335),\n" + + " X336(336),\n" + + " X337(337),\n" + + " X338(338),\n" + + " X339(339),\n" + + " X340(340),\n" + + " X341(341),\n" + + " X342(342),\n" + + " X343(343),\n" + + " X344(344),\n" + + " X345(345),\n" + + " X346(346),\n" + + " X347(347),\n" + + " X348(348),\n" + + " X349(349),\n" + + " X350(350),\n" + + " X351(351),\n" + + " X352(352),\n" + + " X353(353),\n" + + " X354(354),\n" + + " X355(355),\n" + + " X356(356),\n" + + " X357(357),\n" + + " X358(358),\n" + + " X359(359),\n" + + " X360(360),\n" + + " X361(361),\n" + + " X362(362),\n" + + " X363(363),\n" + + " X364(364),\n" + + " X365(365),\n" + + " X366(366),\n" + + " X367(367),\n" + + " X368(368),\n" + + " X369(369),\n" + + " X370(370),\n" + + " X371(371),\n" + + " X372(372),\n" + + " X373(373),\n" + + " X374(374),\n" + + " X375(375),\n" + + " X376(376),\n" + + " X377(377),\n" + + " X378(378),\n" + + " X379(379),\n" + + " X380(380),\n" + + " X381(381),\n" + + " X382(382),\n" + + " X383(383),\n" + + " X384(384),\n" + + " X385(385),\n" + + " X386(386),\n" + + " X387(387),\n" + + " X388(388),\n" + + " X389(389),\n" + + " X390(390),\n" + + " X391(391),\n" + + " X392(392),\n" + + " X393(393),\n" + + " X394(394),\n" + + " X395(395),\n" + + " X396(396),\n" + + " X397(397),\n" + + " X398(398),\n" + + " X399(399),\n" + + " X400(400),\n" + + " X401(401),\n" + + " X402(402),\n" + + " X403(403),\n" + + " X404(404),\n" + + " X405(405),\n" + + " X406(406),\n" + + " X407(407),\n" + + " X408(408),\n" + + " X409(409),\n" + + " X410(410),\n" + + " X411(411),\n" + + " X412(412),\n" + + " X413(413),\n" + + " X414(414),\n" + + " X415(415),\n" + + " X416(416),\n" + + " X417(417),\n" + + " X418(418),\n" + + " X419(419),\n" + + " X420(420),\n" + + " X421(421),\n" + + " X422(422),\n" + + " X423(423),\n" + + " X424(424),\n" + + " X425(425),\n" + + " X426(426),\n" + + " X427(427),\n" + + " X428(428),\n" + + " X429(429),\n" + + " X430(430),\n" + + " X431(431),\n" + + " X432(432),\n" + + " X433(433),\n" + + " X434(434),\n" + + " X435(435),\n" + + " X436(436),\n" + + " X437(437),\n" + + " X438(438),\n" + + " X439(439),\n" + + " X440(440),\n" + + " X441(441),\n" + + " X442(442),\n" + + " X443(443),\n" + + " X444(444),\n" + + " X445(445),\n" + + " X446(446),\n" + + " X447(447),\n" + + " X448(448),\n" + + " X449(449),\n" + + " X450(450),\n" + + " X451(451),\n" + + " X452(452),\n" + + " X453(453),\n" + + " X454(454),\n" + + " X455(455),\n" + + " X456(456),\n" + + " X457(457),\n" + + " X458(458),\n" + + " X459(459),\n" + + " X460(460),\n" + + " X461(461),\n" + + " X462(462),\n" + + " X463(463),\n" + + " X464(464),\n" + + " X465(465),\n" + + " X466(466),\n" + + " X467(467),\n" + + " X468(468),\n" + + " X469(469),\n" + + " X470(470),\n" + + " X471(471),\n" + + " X472(472),\n" + + " X473(473),\n" + + " X474(474),\n" + + " X475(475),\n" + + " X476(476),\n" + + " X477(477),\n" + + " X478(478),\n" + + " X479(479),\n" + + " X480(480),\n" + + " X481(481),\n" + + " X482(482),\n" + + " X483(483),\n" + + " X484(484),\n" + + " X485(485),\n" + + " X486(486),\n" + + " X487(487),\n" + + " X488(488),\n" + + " X489(489),\n" + + " X490(490),\n" + + " X491(491),\n" + + " X492(492),\n" + + " X493(493),\n" + + " X494(494),\n" + + " X495(495),\n" + + " X496(496),\n" + + " X497(497),\n" + + " X498(498),\n" + + " X499(499),\n" + + " X500(500),\n" + + " X501(501),\n" + + " X502(502),\n" + + " X503(503),\n" + + " X504(504),\n" + + " X505(505),\n" + + " X506(506),\n" + + " X507(507),\n" + + " X508(508),\n" + + " X509(509),\n" + + " X510(510),\n" + + " X511(511),\n" + + " X512(512),\n" + + " X513(513),\n" + + " X514(514),\n" + + " X515(515),\n" + + " X516(516),\n" + + " X517(517),\n" + + " X518(518),\n" + + " X519(519),\n" + + " X520(520),\n" + + " X521(521),\n" + + " X522(522),\n" + + " X523(523),\n" + + " X524(524),\n" + + " X525(525),\n" + + " X526(526),\n" + + " X527(527),\n" + + " X528(528),\n" + + " X529(529),\n" + + " X530(530),\n" + + " X531(531),\n" + + " X532(532),\n" + + " X533(533),\n" + + " X534(534),\n" + + " X535(535),\n" + + " X536(536),\n" + + " X537(537),\n" + + " X538(538),\n" + + " X539(539),\n" + + " X540(540),\n" + + " X541(541),\n" + + " X542(542),\n" + + " X543(543),\n" + + " X544(544),\n" + + " X545(545),\n" + + " X546(546),\n" + + " X547(547),\n" + + " X548(548),\n" + + " X549(549),\n" + + " X550(550),\n" + + " X551(551),\n" + + " X552(552),\n" + + " X553(553),\n" + + " X554(554),\n" + + " X555(555),\n" + + " X556(556),\n" + + " X557(557),\n" + + " X558(558),\n" + + " X559(559),\n" + + " X560(560),\n" + + " X561(561),\n" + + " X562(562),\n" + + " X563(563),\n" + + " X564(564),\n" + + " X565(565),\n" + + " X566(566),\n" + + " X567(567),\n" + + " X568(568),\n" + + " X569(569),\n" + + " X570(570),\n" + + " X571(571),\n" + + " X572(572),\n" + + " X573(573),\n" + + " X574(574),\n" + + " X575(575),\n" + + " X576(576),\n" + + " X577(577),\n" + + " X578(578),\n" + + " X579(579),\n" + + " X580(580),\n" + + " X581(581),\n" + + " X582(582),\n" + + " X583(583),\n" + + " X584(584),\n" + + " X585(585),\n" + + " X586(586),\n" + + " X587(587),\n" + + " X588(588),\n" + + " X589(589),\n" + + " X590(590),\n" + + " X591(591),\n" + + " X592(592),\n" + + " X593(593),\n" + + " X594(594),\n" + + " X595(595),\n" + + " X596(596),\n" + + " X597(597),\n" + + " X598(598),\n" + + " X599(599),\n" + + " X600(600),\n" + + " X601(601),\n" + + " X602(602),\n" + + " X603(603),\n" + + " X604(604),\n" + + " X605(605),\n" + + " X606(606),\n" + + " X607(607),\n" + + " X608(608),\n" + + " X609(609),\n" + + " X610(610),\n" + + " X611(611),\n" + + " X612(612),\n" + + " X613(613),\n" + + " X614(614),\n" + + " X615(615),\n" + + " X616(616),\n" + + " X617(617),\n" + + " X618(618),\n" + + " X619(619),\n" + + " X620(620),\n" + + " X621(621),\n" + + " X622(622),\n" + + " X623(623),\n" + + " X624(624),\n" + + " X625(625),\n" + + " X626(626),\n" + + " X627(627),\n" + + " X628(628),\n" + + " X629(629),\n" + + " X630(630),\n" + + " X631(631),\n" + + " X632(632),\n" + + " X633(633),\n" + + " X634(634),\n" + + " X635(635),\n" + + " X636(636),\n" + + " X637(637),\n" + + " X638(638),\n" + + " X639(639),\n" + + " X640(640),\n" + + " X641(641),\n" + + " X642(642),\n" + + " X643(643),\n" + + " X644(644),\n" + + " X645(645),\n" + + " X646(646),\n" + + " X647(647),\n" + + " X648(648),\n" + + " X649(649),\n" + + " X650(650),\n" + + " X651(651),\n" + + " X652(652),\n" + + " X653(653),\n" + + " X654(654),\n" + + " X655(655),\n" + + " X656(656),\n" + + " X657(657),\n" + + " X658(658),\n" + + " X659(659),\n" + + " X660(660),\n" + + " X661(661),\n" + + " X662(662),\n" + + " X663(663),\n" + + " X664(664),\n" + + " X665(665),\n" + + " X666(666),\n" + + " X667(667),\n" + + " X668(668),\n" + + " X669(669),\n" + + " X670(670),\n" + + " X671(671),\n" + + " X672(672),\n" + + " X673(673),\n" + + " X674(674),\n" + + " X675(675),\n" + + " X676(676),\n" + + " X677(677),\n" + + " X678(678),\n" + + " X679(679),\n" + + " X680(680),\n" + + " X681(681),\n" + + " X682(682),\n" + + " X683(683),\n" + + " X684(684),\n" + + " X685(685),\n" + + " X686(686),\n" + + " X687(687),\n" + + " X688(688),\n" + + " X689(689),\n" + + " X690(690),\n" + + " X691(691),\n" + + " X692(692),\n" + + " X693(693),\n" + + " X694(694),\n" + + " X695(695),\n" + + " X696(696),\n" + + " X697(697),\n" + + " X698(698),\n" + + " X699(699),\n" + + " X700(700),\n" + + " X701(701),\n" + + " X702(702),\n" + + " X703(703),\n" + + " X704(704),\n" + + " X705(705),\n" + + " X706(706),\n" + + " X707(707),\n" + + " X708(708),\n" + + " X709(709),\n" + + " X710(710),\n" + + " X711(711),\n" + + " X712(712),\n" + + " X713(713),\n" + + " X714(714),\n" + + " X715(715),\n" + + " X716(716),\n" + + " X717(717),\n" + + " X718(718),\n" + + " X719(719),\n" + + " X720(720),\n" + + " X721(721),\n" + + " X722(722),\n" + + " X723(723),\n" + + " X724(724),\n" + + " X725(725),\n" + + " X726(726),\n" + + " X727(727),\n" + + " X728(728),\n" + + " X729(729),\n" + + " X730(730),\n" + + " X731(731),\n" + + " X732(732),\n" + + " X733(733),\n" + + " X734(734),\n" + + " X735(735),\n" + + " X736(736),\n" + + " X737(737),\n" + + " X738(738),\n" + + " X739(739),\n" + + " X740(740),\n" + + " X741(741),\n" + + " X742(742),\n" + + " X743(743),\n" + + " X744(744),\n" + + " X745(745),\n" + + " X746(746),\n" + + " X747(747),\n" + + " X748(748),\n" + + " X749(749),\n" + + " X750(750),\n" + + " X751(751),\n" + + " X752(752),\n" + + " X753(753),\n" + + " X754(754),\n" + + " X755(755),\n" + + " X756(756),\n" + + " X757(757),\n" + + " X758(758),\n" + + " X759(759),\n" + + " X760(760),\n" + + " X761(761),\n" + + " X762(762),\n" + + " X763(763),\n" + + " X764(764),\n" + + " X765(765),\n" + + " X766(766),\n" + + " X767(767),\n" + + " X768(768),\n" + + " X769(769),\n" + + " X770(770),\n" + + " X771(771),\n" + + " X772(772),\n" + + " X773(773),\n" + + " X774(774),\n" + + " X775(775),\n" + + " X776(776),\n" + + " X777(777),\n" + + " X778(778),\n" + + " X779(779),\n" + + " X780(780),\n" + + " X781(781),\n" + + " X782(782),\n" + + " X783(783),\n" + + " X784(784),\n" + + " X785(785),\n" + + " X786(786),\n" + + " X787(787),\n" + + " X788(788),\n" + + " X789(789),\n" + + " X790(790),\n" + + " X791(791),\n" + + " X792(792),\n" + + " X793(793),\n" + + " X794(794),\n" + + " X795(795),\n" + + " X796(796),\n" + + " X797(797),\n" + + " X798(798),\n" + + " X799(799),\n" + + " X800(800),\n" + + " X801(801),\n" + + " X802(802),\n" + + " X803(803),\n" + + " X804(804),\n" + + " X805(805),\n" + + " X806(806),\n" + + " X807(807),\n" + + " X808(808),\n" + + " X809(809),\n" + + " X810(810),\n" + + " X811(811),\n" + + " X812(812),\n" + + " X813(813),\n" + + " X814(814),\n" + + " X815(815),\n" + + " X816(816),\n" + + " X817(817),\n" + + " X818(818),\n" + + " X819(819),\n" + + " X820(820),\n" + + " X821(821),\n" + + " X822(822),\n" + + " X823(823),\n" + + " X824(824),\n" + + " X825(825),\n" + + " X826(826),\n" + + " X827(827),\n" + + " X828(828),\n" + + " X829(829),\n" + + " X830(830),\n" + + " X831(831),\n" + + " X832(832),\n" + + " X833(833),\n" + + " X834(834),\n" + + " X835(835),\n" + + " X836(836),\n" + + " X837(837),\n" + + " X838(838),\n" + + " X839(839),\n" + + " X840(840),\n" + + " X841(841),\n" + + " X842(842),\n" + + " X843(843),\n" + + " X844(844),\n" + + " X845(845),\n" + + " X846(846),\n" + + " X847(847),\n" + + " X848(848),\n" + + " X849(849),\n" + + " X850(850),\n" + + " X851(851),\n" + + " X852(852),\n" + + " X853(853),\n" + + " X854(854),\n" + + " X855(855),\n" + + " X856(856),\n" + + " X857(857),\n" + + " X858(858),\n" + + " X859(859),\n" + + " X860(860),\n" + + " X861(861),\n" + + " X862(862),\n" + + " X863(863),\n" + + " X864(864),\n" + + " X865(865),\n" + + " X866(866),\n" + + " X867(867),\n" + + " X868(868),\n" + + " X869(869),\n" + + " X870(870),\n" + + " X871(871),\n" + + " X872(872),\n" + + " X873(873),\n" + + " X874(874),\n" + + " X875(875),\n" + + " X876(876),\n" + + " X877(877),\n" + + " X878(878),\n" + + " X879(879),\n" + + " X880(880),\n" + + " X881(881),\n" + + " X882(882),\n" + + " X883(883),\n" + + " X884(884),\n" + + " X885(885),\n" + + " X886(886),\n" + + " X887(887),\n" + + " X888(888),\n" + + " X889(889),\n" + + " X890(890),\n" + + " X891(891),\n" + + " X892(892),\n" + + " X893(893),\n" + + " X894(894),\n" + + " X895(895),\n" + + " X896(896),\n" + + " X897(897),\n" + + " X898(898),\n" + + " X899(899),\n" + + " X900(900),\n" + + " X901(901),\n" + + " X902(902),\n" + + " X903(903),\n" + + " X904(904),\n" + + " X905(905),\n" + + " X906(906),\n" + + " X907(907),\n" + + " X908(908),\n" + + " X909(909),\n" + + " X910(910),\n" + + " X911(911),\n" + + " X912(912),\n" + + " X913(913),\n" + + " X914(914),\n" + + " X915(915),\n" + + " X916(916),\n" + + " X917(917),\n" + + " X918(918),\n" + + " X919(919),\n" + + " X920(920),\n" + + " X921(921),\n" + + " X922(922),\n" + + " X923(923),\n" + + " X924(924),\n" + + " X925(925),\n" + + " X926(926),\n" + + " X927(927),\n" + + " X928(928),\n" + + " X929(929),\n" + + " X930(930),\n" + + " X931(931),\n" + + " X932(932),\n" + + " X933(933),\n" + + " X934(934),\n" + + " X935(935),\n" + + " X936(936),\n" + + " X937(937),\n" + + " X938(938),\n" + + " X939(939),\n" + + " X940(940),\n" + + " X941(941),\n" + + " X942(942),\n" + + " X943(943),\n" + + " X944(944),\n" + + " X945(945),\n" + + " X946(946),\n" + + " X947(947),\n" + + " X948(948),\n" + + " X949(949),\n" + + " X950(950),\n" + + " X951(951),\n" + + " X952(952),\n" + + " X953(953),\n" + + " X954(954),\n" + + " X955(955),\n" + + " X956(956),\n" + + " X957(957),\n" + + " X958(958),\n" + + " X959(959),\n" + + " X960(960),\n" + + " X961(961),\n" + + " X962(962),\n" + + " X963(963),\n" + + " X964(964),\n" + + " X965(965),\n" + + " X966(966),\n" + + " X967(967),\n" + + " X968(968),\n" + + " X969(969),\n" + + " X970(970),\n" + + " X971(971),\n" + + " X972(972),\n" + + " X973(973),\n" + + " X974(974),\n" + + " X975(975),\n" + + " X976(976),\n" + + " X977(977),\n" + + " X978(978),\n" + + " X979(979),\n" + + " X980(980),\n" + + " X981(981),\n" + + " X982(982),\n" + + " X983(983),\n" + + " X984(984),\n" + + " X985(985),\n" + + " X986(986),\n" + + " X987(987),\n" + + " X988(988),\n" + + " X989(989),\n" + + " X990(990),\n" + + " X991(991),\n" + + " X992(992),\n" + + " X993(993),\n" + + " X994(994),\n" + + " X995(995),\n" + + " X996(996),\n" + + " X997(997),\n" + + " X998(998),\n" + + " X999(999),\n" + + " X1000(1000),\n" + + " X1001(1001),\n" + + " X1002(1002),\n" + + " X1003(1003),\n" + + " X1004(1004),\n" + + " X1005(1005),\n" + + " X1006(1006),\n" + + " X1007(1007),\n" + + " X1008(1008),\n" + + " X1009(1009),\n" + + " X1010(1010),\n" + + " X1011(1011),\n" + + " X1012(1012),\n" + + " X1013(1013),\n" + + " X1014(1014),\n" + + " X1015(1015),\n" + + " X1016(1016),\n" + + " X1017(1017),\n" + + " X1018(1018),\n" + + " X1019(1019),\n" + + " X1020(1020),\n" + + " X1021(1021),\n" + + " X1022(1022),\n" + + " X1023(1023),\n" + + " X1024(1024),\n" + + " X1025(1025),\n" + + " X1026(1026),\n" + + " X1027(1027),\n" + + " X1028(1028),\n" + + " X1029(1029),\n" + + " X1030(1030),\n" + + " X1031(1031),\n" + + " X1032(1032),\n" + + " X1033(1033),\n" + + " X1034(1034),\n" + + " X1035(1035),\n" + + " X1036(1036),\n" + + " X1037(1037),\n" + + " X1038(1038),\n" + + " X1039(1039),\n" + + " X1040(1040),\n" + + " X1041(1041),\n" + + " X1042(1042),\n" + + " X1043(1043),\n" + + " X1044(1044),\n" + + " X1045(1045),\n" + + " X1046(1046),\n" + + " X1047(1047),\n" + + " X1048(1048),\n" + + " X1049(1049),\n" + + " X1050(1050),\n" + + " X1051(1051),\n" + + " X1052(1052),\n" + + " X1053(1053),\n" + + " X1054(1054),\n" + + " X1055(1055),\n" + + " X1056(1056),\n" + + " X1057(1057),\n" + + " X1058(1058),\n" + + " X1059(1059),\n" + + " X1060(1060),\n" + + " X1061(1061),\n" + + " X1062(1062),\n" + + " X1063(1063),\n" + + " X1064(1064),\n" + + " X1065(1065),\n" + + " X1066(1066),\n" + + " X1067(1067),\n" + + " X1068(1068),\n" + + " X1069(1069),\n" + + " X1070(1070),\n" + + " X1071(1071),\n" + + " X1072(1072),\n" + + " X1073(1073),\n" + + " X1074(1074),\n" + + " X1075(1075),\n" + + " X1076(1076),\n" + + " X1077(1077),\n" + + " X1078(1078),\n" + + " X1079(1079),\n" + + " X1080(1080),\n" + + " X1081(1081),\n" + + " X1082(1082),\n" + + " X1083(1083),\n" + + " X1084(1084),\n" + + " X1085(1085),\n" + + " X1086(1086),\n" + + " X1087(1087),\n" + + " X1088(1088),\n" + + " X1089(1089),\n" + + " X1090(1090),\n" + + " X1091(1091),\n" + + " X1092(1092),\n" + + " X1093(1093),\n" + + " X1094(1094),\n" + + " X1095(1095),\n" + + " X1096(1096),\n" + + " X1097(1097),\n" + + " X1098(1098),\n" + + " X1099(1099),\n" + + " X1100(1100),\n" + + " X1101(1101),\n" + + " X1102(1102),\n" + + " X1103(1103),\n" + + " X1104(1104),\n" + + " X1105(1105),\n" + + " X1106(1106),\n" + + " X1107(1107),\n" + + " X1108(1108),\n" + + " X1109(1109),\n" + + " X1110(1110),\n" + + " X1111(1111),\n" + + " X1112(1112),\n" + + " X1113(1113),\n" + + " X1114(1114),\n" + + " X1115(1115),\n" + + " X1116(1116),\n" + + " X1117(1117),\n" + + " X1118(1118),\n" + + " X1119(1119),\n" + + " X1120(1120),\n" + + " X1121(1121),\n" + + " X1122(1122),\n" + + " X1123(1123),\n" + + " X1124(1124),\n" + + " X1125(1125),\n" + + " X1126(1126),\n" + + " X1127(1127),\n" + + " X1128(1128),\n" + + " X1129(1129),\n" + + " X1130(1130),\n" + + " X1131(1131),\n" + + " X1132(1132),\n" + + " X1133(1133),\n" + + " X1134(1134),\n" + + " X1135(1135),\n" + + " X1136(1136),\n" + + " X1137(1137),\n" + + " X1138(1138),\n" + + " X1139(1139),\n" + + " X1140(1140),\n" + + " X1141(1141),\n" + + " X1142(1142),\n" + + " X1143(1143),\n" + + " X1144(1144),\n" + + " X1145(1145),\n" + + " X1146(1146),\n" + + " X1147(1147),\n" + + " X1148(1148),\n" + + " X1149(1149),\n" + + " X1150(1150),\n" + + " X1151(1151),\n" + + " X1152(1152),\n" + + " X1153(1153),\n" + + " X1154(1154),\n" + + " X1155(1155),\n" + + " X1156(1156),\n" + + " X1157(1157),\n" + + " X1158(1158),\n" + + " X1159(1159),\n" + + " X1160(1160),\n" + + " X1161(1161),\n" + + " X1162(1162),\n" + + " X1163(1163),\n" + + " X1164(1164),\n" + + " X1165(1165),\n" + + " X1166(1166),\n" + + " X1167(1167),\n" + + " X1168(1168),\n" + + " X1169(1169),\n" + + " X1170(1170),\n" + + " X1171(1171),\n" + + " X1172(1172),\n" + + " X1173(1173),\n" + + " X1174(1174),\n" + + " X1175(1175),\n" + + " X1176(1176),\n" + + " X1177(1177),\n" + + " X1178(1178),\n" + + " X1179(1179),\n" + + " X1180(1180),\n" + + " X1181(1181),\n" + + " X1182(1182),\n" + + " X1183(1183),\n" + + " X1184(1184),\n" + + " X1185(1185),\n" + + " X1186(1186),\n" + + " X1187(1187),\n" + + " X1188(1188),\n" + + " X1189(1189),\n" + + " X1190(1190),\n" + + " X1191(1191),\n" + + " X1192(1192),\n" + + " X1193(1193),\n" + + " X1194(1194),\n" + + " X1195(1195),\n" + + " X1196(1196),\n" + + " X1197(1197),\n" + + " X1198(1198),\n" + + " X1199(1199),\n" + + " X1200(1200),\n" + + " X1201(1201),\n" + + " X1202(1202),\n" + + " X1203(1203),\n" + + " X1204(1204),\n" + + " X1205(1205),\n" + + " X1206(1206),\n" + + " X1207(1207),\n" + + " X1208(1208),\n" + + " X1209(1209),\n" + + " X1210(1210),\n" + + " X1211(1211),\n" + + " X1212(1212),\n" + + " X1213(1213),\n" + + " X1214(1214),\n" + + " X1215(1215),\n" + + " X1216(1216),\n" + + " X1217(1217),\n" + + " X1218(1218),\n" + + " X1219(1219),\n" + + " X1220(1220),\n" + + " X1221(1221),\n" + + " X1222(1222),\n" + + " X1223(1223),\n" + + " X1224(1224),\n" + + " X1225(1225),\n" + + " X1226(1226),\n" + + " X1227(1227),\n" + + " X1228(1228),\n" + + " X1229(1229),\n" + + " X1230(1230),\n" + + " X1231(1231),\n" + + " X1232(1232),\n" + + " X1233(1233),\n" + + " X1234(1234),\n" + + " X1235(1235),\n" + + " X1236(1236),\n" + + " X1237(1237),\n" + + " X1238(1238),\n" + + " X1239(1239),\n" + + " X1240(1240),\n" + + " X1241(1241),\n" + + " X1242(1242),\n" + + " X1243(1243),\n" + + " X1244(1244),\n" + + " X1245(1245),\n" + + " X1246(1246),\n" + + " X1247(1247),\n" + + " X1248(1248),\n" + + " X1249(1249),\n" + + " X1250(1250),\n" + + " X1251(1251),\n" + + " X1252(1252),\n" + + " X1253(1253),\n" + + " X1254(1254),\n" + + " X1255(1255),\n" + + " X1256(1256),\n" + + " X1257(1257),\n" + + " X1258(1258),\n" + + " X1259(1259),\n" + + " X1260(1260),\n" + + " X1261(1261),\n" + + " X1262(1262),\n" + + " X1263(1263),\n" + + " X1264(1264),\n" + + " X1265(1265),\n" + + " X1266(1266),\n" + + " X1267(1267),\n" + + " X1268(1268),\n" + + " X1269(1269),\n" + + " X1270(1270),\n" + + " X1271(1271),\n" + + " X1272(1272),\n" + + " X1273(1273),\n" + + " X1274(1274),\n" + + " X1275(1275),\n" + + " X1276(1276),\n" + + " X1277(1277),\n" + + " X1278(1278),\n" + + " X1279(1279),\n" + + " X1280(1280),\n" + + " X1281(1281),\n" + + " X1282(1282),\n" + + " X1283(1283),\n" + + " X1284(1284),\n" + + " X1285(1285),\n" + + " X1286(1286),\n" + + " X1287(1287),\n" + + " X1288(1288),\n" + + " X1289(1289),\n" + + " X1290(1290),\n" + + " X1291(1291),\n" + + " X1292(1292),\n" + + " X1293(1293),\n" + + " X1294(1294),\n" + + " X1295(1295),\n" + + " X1296(1296),\n" + + " X1297(1297),\n" + + " X1298(1298),\n" + + " X1299(1299),\n" + + " X1300(1300),\n" + + " X1301(1301),\n" + + " X1302(1302),\n" + + " X1303(1303),\n" + + " X1304(1304),\n" + + " X1305(1305),\n" + + " X1306(1306),\n" + + " X1307(1307),\n" + + " X1308(1308),\n" + + " X1309(1309),\n" + + " X1310(1310),\n" + + " X1311(1311),\n" + + " X1312(1312),\n" + + " X1313(1313),\n" + + " X1314(1314),\n" + + " X1315(1315),\n" + + " X1316(1316),\n" + + " X1317(1317),\n" + + " X1318(1318),\n" + + " X1319(1319),\n" + + " X1320(1320),\n" + + " X1321(1321),\n" + + " X1322(1322),\n" + + " X1323(1323),\n" + + " X1324(1324),\n" + + " X1325(1325),\n" + + " X1326(1326),\n" + + " X1327(1327),\n" + + " X1328(1328),\n" + + " X1329(1329),\n" + + " X1330(1330),\n" + + " X1331(1331),\n" + + " X1332(1332),\n" + + " X1333(1333),\n" + + " X1334(1334),\n" + + " X1335(1335),\n" + + " X1336(1336),\n" + + " X1337(1337),\n" + + " X1338(1338),\n" + + " X1339(1339),\n" + + " X1340(1340),\n" + + " X1341(1341),\n" + + " X1342(1342),\n" + + " X1343(1343),\n" + + " X1344(1344),\n" + + " X1345(1345),\n" + + " X1346(1346),\n" + + " X1347(1347),\n" + + " X1348(1348),\n" + + " X1349(1349),\n" + + " X1350(1350),\n" + + " X1351(1351),\n" + + " X1352(1352),\n" + + " X1353(1353),\n" + + " X1354(1354),\n" + + " X1355(1355),\n" + + " X1356(1356),\n" + + " X1357(1357),\n" + + " X1358(1358),\n" + + " X1359(1359),\n" + + " X1360(1360),\n" + + " X1361(1361),\n" + + " X1362(1362),\n" + + " X1363(1363),\n" + + " X1364(1364),\n" + + " X1365(1365),\n" + + " X1366(1366),\n" + + " X1367(1367),\n" + + " X1368(1368),\n" + + " X1369(1369),\n" + + " X1370(1370),\n" + + " X1371(1371),\n" + + " X1372(1372),\n" + + " X1373(1373),\n" + + " X1374(1374),\n" + + " X1375(1375),\n" + + " X1376(1376),\n" + + " X1377(1377),\n" + + " X1378(1378),\n" + + " X1379(1379),\n" + + " X1380(1380),\n" + + " X1381(1381),\n" + + " X1382(1382),\n" + + " X1383(1383),\n" + + " X1384(1384),\n" + + " X1385(1385),\n" + + " X1386(1386),\n" + + " X1387(1387),\n" + + " X1388(1388),\n" + + " X1389(1389),\n" + + " X1390(1390),\n" + + " X1391(1391),\n" + + " X1392(1392),\n" + + " X1393(1393),\n" + + " X1394(1394),\n" + + " X1395(1395),\n" + + " X1396(1396),\n" + + " X1397(1397),\n" + + " X1398(1398),\n" + + " X1399(1399),\n" + + " X1400(1400),\n" + + " X1401(1401),\n" + + " X1402(1402),\n" + + " X1403(1403),\n" + + " X1404(1404),\n" + + " X1405(1405),\n" + + " X1406(1406),\n" + + " X1407(1407),\n" + + " X1408(1408),\n" + + " X1409(1409),\n" + + " X1410(1410),\n" + + " X1411(1411),\n" + + " X1412(1412),\n" + + " X1413(1413),\n" + + " X1414(1414),\n" + + " X1415(1415),\n" + + " X1416(1416),\n" + + " X1417(1417),\n" + + " X1418(1418),\n" + + " X1419(1419),\n" + + " X1420(1420),\n" + + " X1421(1421),\n" + + " X1422(1422),\n" + + " X1423(1423),\n" + + " X1424(1424),\n" + + " X1425(1425),\n" + + " X1426(1426),\n" + + " X1427(1427),\n" + + " X1428(1428),\n" + + " X1429(1429),\n" + + " X1430(1430),\n" + + " X1431(1431),\n" + + " X1432(1432),\n" + + " X1433(1433),\n" + + " X1434(1434),\n" + + " X1435(1435),\n" + + " X1436(1436),\n" + + " X1437(1437),\n" + + " X1438(1438),\n" + + " X1439(1439),\n" + + " X1440(1440),\n" + + " X1441(1441),\n" + + " X1442(1442),\n" + + " X1443(1443),\n" + + " X1444(1444),\n" + + " X1445(1445),\n" + + " X1446(1446),\n" + + " X1447(1447),\n" + + " X1448(1448),\n" + + " X1449(1449),\n" + + " X1450(1450),\n" + + " X1451(1451),\n" + + " X1452(1452),\n" + + " X1453(1453),\n" + + " X1454(1454),\n" + + " X1455(1455),\n" + + " X1456(1456),\n" + + " X1457(1457),\n" + + " X1458(1458),\n" + + " X1459(1459),\n" + + " X1460(1460),\n" + + " X1461(1461),\n" + + " X1462(1462),\n" + + " X1463(1463),\n" + + " X1464(1464),\n" + + " X1465(1465),\n" + + " X1466(1466),\n" + + " X1467(1467),\n" + + " X1468(1468),\n" + + " X1469(1469),\n" + + " X1470(1470),\n" + + " X1471(1471),\n" + + " X1472(1472),\n" + + " X1473(1473),\n" + + " X1474(1474),\n" + + " X1475(1475),\n" + + " X1476(1476),\n" + + " X1477(1477),\n" + + " X1478(1478),\n" + + " X1479(1479),\n" + + " X1480(1480),\n" + + " X1481(1481),\n" + + " X1482(1482),\n" + + " X1483(1483),\n" + + " X1484(1484),\n" + + " X1485(1485),\n" + + " X1486(1486),\n" + + " X1487(1487),\n" + + " X1488(1488),\n" + + " X1489(1489),\n" + + " X1490(1490),\n" + + " X1491(1491),\n" + + " X1492(1492),\n" + + " X1493(1493),\n" + + " X1494(1494),\n" + + " X1495(1495),\n" + + " X1496(1496),\n" + + " X1497(1497),\n" + + " X1498(1498),\n" + + " X1499(1499),\n" + + " X1500(1500),\n" + + " X1501(1501),\n" + + " X1502(1502),\n" + + " X1503(1503),\n" + + " X1504(1504),\n" + + " X1505(1505),\n" + + " X1506(1506),\n" + + " X1507(1507),\n" + + " X1508(1508),\n" + + " X1509(1509),\n" + + " X1510(1510),\n" + + " X1511(1511),\n" + + " X1512(1512),\n" + + " X1513(1513),\n" + + " X1514(1514),\n" + + " X1515(1515),\n" + + " X1516(1516),\n" + + " X1517(1517),\n" + + " X1518(1518),\n" + + " X1519(1519),\n" + + " X1520(1520),\n" + + " X1521(1521),\n" + + " X1522(1522),\n" + + " X1523(1523),\n" + + " X1524(1524),\n" + + " X1525(1525),\n" + + " X1526(1526),\n" + + " X1527(1527),\n" + + " X1528(1528),\n" + + " X1529(1529),\n" + + " X1530(1530),\n" + + " X1531(1531),\n" + + " X1532(1532),\n" + + " X1533(1533),\n" + + " X1534(1534),\n" + + " X1535(1535),\n" + + " X1536(1536),\n" + + " X1537(1537),\n" + + " X1538(1538),\n" + + " X1539(1539),\n" + + " X1540(1540),\n" + + " X1541(1541),\n" + + " X1542(1542),\n" + + " X1543(1543),\n" + + " X1544(1544),\n" + + " X1545(1545),\n" + + " X1546(1546),\n" + + " X1547(1547),\n" + + " X1548(1548),\n" + + " X1549(1549),\n" + + " X1550(1550),\n" + + " X1551(1551),\n" + + " X1552(1552),\n" + + " X1553(1553),\n" + + " X1554(1554),\n" + + " X1555(1555),\n" + + " X1556(1556),\n" + + " X1557(1557),\n" + + " X1558(1558),\n" + + " X1559(1559),\n" + + " X1560(1560),\n" + + " X1561(1561),\n" + + " X1562(1562),\n" + + " X1563(1563),\n" + + " X1564(1564),\n" + + " X1565(1565),\n" + + " X1566(1566),\n" + + " X1567(1567),\n" + + " X1568(1568),\n" + + " X1569(1569),\n" + + " X1570(1570),\n" + + " X1571(1571),\n" + + " X1572(1572),\n" + + " X1573(1573),\n" + + " X1574(1574),\n" + + " X1575(1575),\n" + + " X1576(1576),\n" + + " X1577(1577),\n" + + " X1578(1578),\n" + + " X1579(1579),\n" + + " X1580(1580),\n" + + " X1581(1581),\n" + + " X1582(1582),\n" + + " X1583(1583),\n" + + " X1584(1584),\n" + + " X1585(1585),\n" + + " X1586(1586),\n" + + " X1587(1587),\n" + + " X1588(1588),\n" + + " X1589(1589),\n" + + " X1590(1590),\n" + + " X1591(1591),\n" + + " X1592(1592),\n" + + " X1593(1593),\n" + + " X1594(1594),\n" + + " X1595(1595),\n" + + " X1596(1596),\n" + + " X1597(1597),\n" + + " X1598(1598),\n" + + " X1599(1599),\n" + + " X1600(1600),\n" + + " X1601(1601),\n" + + " X1602(1602),\n" + + " X1603(1603),\n" + + " X1604(1604),\n" + + " X1605(1605),\n" + + " X1606(1606),\n" + + " X1607(1607),\n" + + " X1608(1608),\n" + + " X1609(1609),\n" + + " X1610(1610),\n" + + " X1611(1611),\n" + + " X1612(1612),\n" + + " X1613(1613),\n" + + " X1614(1614),\n" + + " X1615(1615),\n" + + " X1616(1616),\n" + + " X1617(1617),\n" + + " X1618(1618),\n" + + " X1619(1619),\n" + + " X1620(1620),\n" + + " X1621(1621),\n" + + " X1622(1622),\n" + + " X1623(1623),\n" + + " X1624(1624),\n" + + " X1625(1625),\n" + + " X1626(1626),\n" + + " X1627(1627),\n" + + " X1628(1628),\n" + + " X1629(1629),\n" + + " X1630(1630),\n" + + " X1631(1631),\n" + + " X1632(1632),\n" + + " X1633(1633),\n" + + " X1634(1634),\n" + + " X1635(1635),\n" + + " X1636(1636),\n" + + " X1637(1637),\n" + + " X1638(1638),\n" + + " X1639(1639),\n" + + " X1640(1640),\n" + + " X1641(1641),\n" + + " X1642(1642),\n" + + " X1643(1643),\n" + + " X1644(1644),\n" + + " X1645(1645),\n" + + " X1646(1646),\n" + + " X1647(1647),\n" + + " X1648(1648),\n" + + " X1649(1649),\n" + + " X1650(1650),\n" + + " X1651(1651),\n" + + " X1652(1652),\n" + + " X1653(1653),\n" + + " X1654(1654),\n" + + " X1655(1655),\n" + + " X1656(1656),\n" + + " X1657(1657),\n" + + " X1658(1658),\n" + + " X1659(1659),\n" + + " X1660(1660),\n" + + " X1661(1661),\n" + + " X1662(1662),\n" + + " X1663(1663),\n" + + " X1664(1664),\n" + + " X1665(1665),\n" + + " X1666(1666),\n" + + " X1667(1667),\n" + + " X1668(1668),\n" + + " X1669(1669),\n" + + " X1670(1670),\n" + + " X1671(1671),\n" + + " X1672(1672),\n" + + " X1673(1673),\n" + + " X1674(1674),\n" + + " X1675(1675),\n" + + " X1676(1676),\n" + + " X1677(1677),\n" + + " X1678(1678),\n" + + " X1679(1679),\n" + + " X1680(1680),\n" + + " X1681(1681),\n" + + " X1682(1682),\n" + + " X1683(1683),\n" + + " X1684(1684),\n" + + " X1685(1685),\n" + + " X1686(1686),\n" + + " X1687(1687),\n" + + " X1688(1688),\n" + + " X1689(1689),\n" + + " X1690(1690),\n" + + " X1691(1691),\n" + + " X1692(1692),\n" + + " X1693(1693),\n" + + " X1694(1694),\n" + + " X1695(1695),\n" + + " X1696(1696),\n" + + " X1697(1697),\n" + + " X1698(1698),\n" + + " X1699(1699),\n" + + " X1700(1700),\n" + + " X1701(1701),\n" + + " X1702(1702),\n" + + " X1703(1703),\n" + + " X1704(1704),\n" + + " X1705(1705),\n" + + " X1706(1706),\n" + + " X1707(1707),\n" + + " X1708(1708),\n" + + " X1709(1709),\n" + + " X1710(1710),\n" + + " X1711(1711),\n" + + " X1712(1712),\n" + + " X1713(1713),\n" + + " X1714(1714),\n" + + " X1715(1715),\n" + + " X1716(1716),\n" + + " X1717(1717),\n" + + " X1718(1718),\n" + + " X1719(1719),\n" + + " X1720(1720),\n" + + " X1721(1721),\n" + + " X1722(1722),\n" + + " X1723(1723),\n" + + " X1724(1724),\n" + + " X1725(1725),\n" + + " X1726(1726),\n" + + " X1727(1727),\n" + + " X1728(1728),\n" + + " X1729(1729),\n" + + " X1730(1730),\n" + + " X1731(1731),\n" + + " X1732(1732),\n" + + " X1733(1733),\n" + + " X1734(1734),\n" + + " X1735(1735),\n" + + " X1736(1736),\n" + + " X1737(1737),\n" + + " X1738(1738),\n" + + " X1739(1739),\n" + + " X1740(1740),\n" + + " X1741(1741),\n" + + " X1742(1742),\n" + + " X1743(1743),\n" + + " X1744(1744),\n" + + " X1745(1745),\n" + + " X1746(1746),\n" + + " X1747(1747),\n" + + " X1748(1748),\n" + + " X1749(1749),\n" + + " X1750(1750),\n" + + " X1751(1751),\n" + + " X1752(1752),\n" + + " X1753(1753),\n" + + " X1754(1754),\n" + + " X1755(1755),\n" + + " X1756(1756),\n" + + " X1757(1757),\n" + + " X1758(1758),\n" + + " X1759(1759),\n" + + " X1760(1760),\n" + + " X1761(1761),\n" + + " X1762(1762),\n" + + " X1763(1763),\n" + + " X1764(1764),\n" + + " X1765(1765),\n" + + " X1766(1766),\n" + + " X1767(1767),\n" + + " X1768(1768),\n" + + " X1769(1769),\n" + + " X1770(1770),\n" + + " X1771(1771),\n" + + " X1772(1772),\n" + + " X1773(1773),\n" + + " X1774(1774),\n" + + " X1775(1775),\n" + + " X1776(1776),\n" + + " X1777(1777),\n" + + " X1778(1778),\n" + + " X1779(1779),\n" + + " X1780(1780),\n" + + " X1781(1781),\n" + + " X1782(1782),\n" + + " X1783(1783),\n" + + " X1784(1784),\n" + + " X1785(1785),\n" + + " X1786(1786),\n" + + " X1787(1787),\n" + + " X1788(1788),\n" + + " X1789(1789),\n" + + " X1790(1790),\n" + + " X1791(1791),\n" + + " X1792(1792),\n" + + " X1793(1793),\n" + + " X1794(1794),\n" + + " X1795(1795),\n" + + " X1796(1796),\n" + + " X1797(1797),\n" + + " X1798(1798),\n" + + " X1799(1799),\n" + + " X1800(1800),\n" + + " X1801(1801),\n" + + " X1802(1802),\n" + + " X1803(1803),\n" + + " X1804(1804),\n" + + " X1805(1805),\n" + + " X1806(1806),\n" + + " X1807(1807),\n" + + " X1808(1808),\n" + + " X1809(1809),\n" + + " X1810(1810),\n" + + " X1811(1811),\n" + + " X1812(1812),\n" + + " X1813(1813),\n" + + " X1814(1814),\n" + + " X1815(1815),\n" + + " X1816(1816),\n" + + " X1817(1817),\n" + + " X1818(1818),\n" + + " X1819(1819),\n" + + " X1820(1820),\n" + + " X1821(1821),\n" + + " X1822(1822),\n" + + " X1823(1823),\n" + + " X1824(1824),\n" + + " X1825(1825),\n" + + " X1826(1826),\n" + + " X1827(1827),\n" + + " X1828(1828),\n" + + " X1829(1829),\n" + + " X1830(1830),\n" + + " X1831(1831),\n" + + " X1832(1832),\n" + + " X1833(1833),\n" + + " X1834(1834),\n" + + " X1835(1835),\n" + + " X1836(1836),\n" + + " X1837(1837),\n" + + " X1838(1838),\n" + + " X1839(1839),\n" + + " X1840(1840),\n" + + " X1841(1841),\n" + + " X1842(1842),\n" + + " X1843(1843),\n" + + " X1844(1844),\n" + + " X1845(1845),\n" + + " X1846(1846),\n" + + " X1847(1847),\n" + + " X1848(1848),\n" + + " X1849(1849),\n" + + " X1850(1850),\n" + + " X1851(1851),\n" + + " X1852(1852),\n" + + " X1853(1853),\n" + + " X1854(1854),\n" + + " X1855(1855),\n" + + " X1856(1856),\n" + + " X1857(1857),\n" + + " X1858(1858),\n" + + " X1859(1859),\n" + + " X1860(1860),\n" + + " X1861(1861),\n" + + " X1862(1862),\n" + + " X1863(1863),\n" + + " X1864(1864),\n" + + " X1865(1865),\n" + + " X1866(1866),\n" + + " X1867(1867),\n" + + " X1868(1868),\n" + + " X1869(1869),\n" + + " X1870(1870),\n" + + " X1871(1871),\n" + + " X1872(1872),\n" + + " X1873(1873),\n" + + " X1874(1874),\n" + + " X1875(1875),\n" + + " X1876(1876),\n" + + " X1877(1877),\n" + + " X1878(1878),\n" + + " X1879(1879),\n" + + " X1880(1880),\n" + + " X1881(1881),\n" + + " X1882(1882),\n" + + " X1883(1883),\n" + + " X1884(1884),\n" + + " X1885(1885),\n" + + " X1886(1886),\n" + + " X1887(1887),\n" + + " X1888(1888),\n" + + " X1889(1889),\n" + + " X1890(1890),\n" + + " X1891(1891),\n" + + " X1892(1892),\n" + + " X1893(1893),\n" + + " X1894(1894),\n" + + " X1895(1895),\n" + + " X1896(1896),\n" + + " X1897(1897),\n" + + " X1898(1898),\n" + + " X1899(1899),\n" + + " X1900(1900),\n" + + " X1901(1901),\n" + + " X1902(1902),\n" + + " X1903(1903),\n" + + " X1904(1904),\n" + + " X1905(1905),\n" + + " X1906(1906),\n" + + " X1907(1907),\n" + + " X1908(1908),\n" + + " X1909(1909),\n" + + " X1910(1910),\n" + + " X1911(1911),\n" + + " X1912(1912),\n" + + " X1913(1913),\n" + + " X1914(1914),\n" + + " X1915(1915),\n" + + " X1916(1916),\n" + + " X1917(1917),\n" + + " X1918(1918),\n" + + " X1919(1919),\n" + + " X1920(1920),\n" + + " X1921(1921),\n" + + " X1922(1922),\n" + + " X1923(1923),\n" + + " X1924(1924),\n" + + " X1925(1925),\n" + + " X1926(1926),\n" + + " X1927(1927),\n" + + " X1928(1928),\n" + + " X1929(1929),\n" + + " X1930(1930),\n" + + " X1931(1931),\n" + + " X1932(1932),\n" + + " X1933(1933),\n" + + " X1934(1934),\n" + + " X1935(1935),\n" + + " X1936(1936),\n" + + " X1937(1937),\n" + + " X1938(1938),\n" + + " X1939(1939),\n" + + " X1940(1940),\n" + + " X1941(1941),\n" + + " X1942(1942),\n" + + " X1943(1943),\n" + + " X1944(1944),\n" + + " X1945(1945),\n" + + " X1946(1946),\n" + + " X1947(1947),\n" + + " X1948(1948),\n" + + " X1949(1949),\n" + + " X1950(1950),\n" + + " X1951(1951),\n" + + " X1952(1952),\n" + + " X1953(1953),\n" + + " X1954(1954),\n" + + " X1955(1955),\n" + + " X1956(1956),\n" + + " X1957(1957),\n" + + " X1958(1958),\n" + + " X1959(1959),\n" + + " X1960(1960),\n" + + " X1961(1961),\n" + + " X1962(1962),\n" + + " X1963(1963),\n" + + " X1964(1964),\n" + + " X1965(1965),\n" + + " X1966(1966),\n" + + " X1967(1967),\n" + + " X1968(1968),\n" + + " X1969(1969),\n" + + " X1970(1970),\n" + + " X1971(1971),\n" + + " X1972(1972),\n" + + " X1973(1973),\n" + + " X1974(1974),\n" + + " X1975(1975),\n" + + " X1976(1976),\n" + + " X1977(1977),\n" + + " X1978(1978),\n" + + " X1979(1979),\n" + + " X1980(1980),\n" + + " X1981(1981),\n" + + " X1982(1982),\n" + + " X1983(1983),\n" + + " X1984(1984),\n" + + " X1985(1985),\n" + + " X1986(1986),\n" + + " X1987(1987),\n" + + " X1988(1988),\n" + + " X1989(1989),\n" + + " X1990(1990),\n" + + " X1991(1991),\n" + + " X1992(1992),\n" + + " X1993(1993),\n" + + " X1994(1994),\n" + + " X1995(1995),\n" + + " X1996(1996),\n" + + " X1997(1997),\n" + + " X1998(1998),\n" + + " X1999(1999),\n" + + " X2000(2000),\n" + + " X2001(2001),\n" + + " X2002(2002),\n" + + " X2003(2003),\n" + + " X2004(2004),\n" + + " X2005(2005),\n" + + " X2006(2006),\n" + + " X2007(2007),\n" + + " X2008(2008),\n" + + " X2009(2009),\n" + + " X2010(2010),\n" + + " X2011(2011),\n" + + " X2012(2012),\n" + + " X2013(2013),\n" + + " X2014(2014),\n" + + " X2015(2015),\n" + + " X2016(2016),\n" + + " X2017(2017),\n" + + " X2018(2018),\n" + + " X2019(2019),\n" + + " X2020(2020),\n" + + " X2021(2021),\n" + + " X2022(2022),\n" + + " X2023(2023),\n" + + " X2024(2024),\n" + + " X2025(2025),\n" + + " X2026(2026),\n" + + " X2027(2027),\n" + + " X2028(2028),\n" + + " X2029(2029),\n" + + " X2030(2030),\n" + + " X2031(2031),\n" + + " X2032(2032),\n" + + " X2033(2033),\n" + + " X2034(2034),\n" + + " X2035(2035),\n" + + " X2036(2036),\n" + + " X2037(2037),\n" + + " X2038(2038),\n" + + " X2039(2039),\n" + + " X2040(2040),\n" + + " X2041(2041),\n" + + " X2042(2042),\n" + + " X2043(2043),\n" + + " X2044(2044),\n" + + " X2045(2045),\n" + + " X2046(2046),\n" + + " X2047(2047),\n" + + " X2048(2048),\n" + + " X2049(2049),\n" + + " X2050(2050),\n" + + " X2051(2051),\n" + + " X2052(2052),\n" + + " X2053(2053),\n" + + " X2054(2054),\n" + + " X2055(2055),\n" + + " X2056(2056),\n" + + " X2057(2057),\n" + + " X2058(2058),\n" + + " X2059(2059),\n" + + " X2060(2060),\n" + + " X2061(2061),\n" + + " X2062(2062),\n" + + " X2063(2063),\n" + + " X2064(2064),\n" + + " X2065(2065),\n" + + " X2066(2066),\n" + + " X2067(2067),\n" + + " X2068(2068),\n" + + " X2069(2069),\n" + + " X2070(2070),\n" + + " X2071(2071),\n" + + " X2072(2072),\n" + + " X2073(2073),\n" + + " X2074(2074),\n" + + " X2075(2075),\n" + + " X2076(2076),\n" + + " X2077(2077),\n" + + " X2078(2078),\n" + + " X2079(2079),\n" + + " X2080(2080),\n" + + " X2081(2081),\n" + + " X2082(2082),\n" + + " X2083(2083),\n" + + " X2084(2084),\n" + + " X2085(2085),\n" + + " X2086(2086),\n" + + " X2087(2087),\n" + + " X2088(2088),\n" + + " X2089(2089),\n" + + " X2090(2090),\n" + + " X2091(2091),\n" + + " X2092(2092),\n" + + " X2093(2093),\n" + + " X2094(2094),\n" + + " X2095(2095),\n" + + " X2096(2096),\n" + + " X2097(2097),\n" + + " X2098(2098),\n" + + " X2099(2099),\n" + + " X2100(2100),\n" + + " X2101(2101),\n" + + " X2102(2102),\n" + + " X2103(2103),\n" + + " X2104(2104),\n" + + " X2105(2105),\n" + + " X2106(2106),\n" + + " X2107(2107),\n" + + " X2108(2108),\n" + + " X2109(2109),\n" + + " X2110(2110),\n" + + " X2111(2111),\n" + + " X2112(2112),\n" + + " X2113(2113),\n" + + " X2114(2114),\n" + + " X2115(2115),\n" + + " X2116(2116),\n" + + " X2117(2117),\n" + + " X2118(2118),\n" + + " X2119(2119),\n" + + " X2120(2120),\n" + + " X2121(2121),\n" + + " X2122(2122),\n" + + " X2123(2123),\n" + + " X2124(2124),\n" + + " X2125(2125),\n" + + " X2126(2126),\n" + + " X2127(2127),\n" + + " X2128(2128),\n" + + " X2129(2129),\n" + + " X2130(2130),\n" + + " X2131(2131),\n" + + " X2132(2132),\n" + + " X2133(2133),\n" + + " X2134(2134),\n" + + " X2135(2135),\n" + + " X2136(2136),\n" + + " X2137(2137),\n" + + " X2138(2138),\n" + + " X2139(2139),\n" + + " X2140(2140),\n" + + " X2141(2141),\n" + + " X2142(2142),\n" + + " X2143(2143),\n" + + " X2144(2144),\n" + + " X2145(2145),\n" + + " X2146(2146),\n" + + " X2147(2147),\n" + + " X2148(2148),\n" + + " X2149(2149),\n" + + " X2150(2150),\n" + + " X2151(2151),\n" + + " X2152(2152),\n" + + " X2153(2153),\n" + + " X2154(2154),\n" + + " X2155(2155),\n" + + " X2156(2156),\n" + + " X2157(2157),\n" + + " X2158(2158),\n" + + " X2159(2159),\n" + + " X2160(2160),\n" + + " X2161(2161),\n" + + " X2162(2162),\n" + + " X2163(2163),\n" + + " X2164(2164),\n" + + " X2165(2165),\n" + + " X2166(2166),\n" + + " X2167(2167),\n" + + " X2168(2168),\n" + + " X2169(2169),\n" + + " X2170(2170),\n" + + " X2171(2171),\n" + + " X2172(2172),\n" + + " X2173(2173),\n" + + " X2174(2174),\n" + + " X2175(2175),\n" + + " X2176(2176),\n" + + " X2177(2177),\n" + + " X2178(2178),\n" + + " X2179(2179),\n" + + " X2180(2180),\n" + + " X2181(2181),\n" + + " X2182(2182),\n" + + " X2183(2183),\n" + + " X2184(2184),\n" + + " X2185(2185),\n" + + " X2186(2186),\n" + + " X2187(2187),\n" + + " X2188(2188),\n" + + " X2189(2189),\n" + + " X2190(2190),\n" + + " X2191(2191),\n" + + " X2192(2192),\n" + + " X2193(2193),\n" + + " X2194(2194),\n" + + " X2195(2195),\n" + + " X2196(2196),\n" + + " X2197(2197),\n" + + " X2198(2198),\n" + + " X2199(2199),\n" + + " X2200(2200),\n" + + " X2201(2201),\n" + + " X2202(2202),\n" + + " X2203(2203),\n" + + " X2204(2204),\n" + + " X2205(2205),\n" + + " X2206(2206),\n" + + " X2207(2207),\n" + + " X2208(2208),\n" + + " X2209(2209),\n" + + " X2210(2210),\n" + + " X2211(2211),\n" + + " X2212(2212),\n" + + " X2213(2213),\n" + + " X2214(2214),\n" + + " X2215(2215),\n" + + " X2216(2216),\n" + + " X2217(2217),\n" + + " X2218(2218),\n" + + " X2219(2219),\n" + + " X2220(2220),\n" + + " X2221(2221),\n" + + " X2222(2222),\n" + + " X2223(2223),\n" + + " X2224(2224),\n" + + " X2225(2225),\n" + + " X2226(2226),\n" + + " X2227(2227),\n" + + " X2228(2228),\n" + + " X2229(2229),\n" + + " X2230(2230),\n" + + " X2231(2231),\n" + + " X2232(2232),\n" + + " X2233(2233),\n" + + " X2234(2234),\n" + + " X2235(2235),\n" + + " X2236(2236),\n" + + " X2237(2237),\n" + + " X2238(2238),\n" + + " X2239(2239),\n" + + " X2240(2240),\n" + + " X2241(2241),\n" + + " X2242(2242),\n" + + " X2243(2243),\n" + + " X2244(2244),\n" + + " X2245(2245),\n" + + " X2246(2246),\n" + + " X2247(2247),\n" + + " X2248(2248),\n" + + " X2249(2249),\n" + + " X2250(2250),\n" + + " X2251(2251),\n" + + " X2252(2252),\n" + + " X2253(2253),\n" + + " X2254(2254),\n" + + " X2255(2255),\n" + + " X2256(2256),\n" + + " X2257(2257),\n" + + " X2258(2258),\n" + + " X2259(2259),\n" + + " X2260(2260),\n" + + " X2261(2261),\n" + + " X2262(2262),\n" + + " X2263(2263),\n" + + " X2264(2264),\n" + + " X2265(2265),\n" + + " X2266(2266),\n" + + " X2267(2267),\n" + + " X2268(2268),\n" + + " X2269(2269),\n" + + " X2270(2270),\n" + + " X2271(2271),\n" + + " X2272(2272),\n" + + " X2273(2273),\n" + + " X2274(2274),\n" + + " X2275(2275),\n" + + " X2276(2276),\n" + + " X2277(2277),\n" + + " X2278(2278),\n" + + " X2279(2279),\n" + + " X2280(2280),\n" + + " X2281(2281),\n" + + " X2282(2282),\n" + + " X2283(2283),\n" + + " X2284(2284),\n" + + " X2285(2285),\n" + + " X2286(2286),\n" + + " X2287(2287),\n" + + " X2288(2288),\n" + + " X2289(2289),\n" + + " X2290(2290),\n" + + " X2291(2291),\n" + + " X2292(2292),\n" + + " X2293(2293),\n" + + " X2294(2294),\n" + + " X2295(2295),\n" + + " X2296(2296),\n" + + " X2297(2297),\n" + + " X2298(2298),\n" + + " X2299(2299),\n" + + " X2300(2300),\n" + + " X2301(2301),\n" + + " X2302(2302),\n" + + " X2303(2303),\n" + + " X2304(2304),\n" + + " X2305(2305),\n" + + " X2306(2306),\n" + + " X2307(2307),\n" + + " X2308(2308),\n" + + " X2309(2309),\n" + + " X2310(2310),\n" + + " X2311(2311),\n" + + " X2312(2312),\n" + + " X2313(2313),\n" + + " X2314(2314),\n" + + " X2315(2315),\n" + + " X2316(2316),\n" + + " X2317(2317),\n" + + " X2318(2318),\n" + + " X2319(2319),\n" + + " X2320(2320),\n" + + " X2321(2321),\n" + + " X2322(2322),\n" + + " X2323(2323),\n" + + " X2324(2324),\n" + + " X2325(2325),\n" + + " X2326(2326),\n" + + " X2327(2327),\n" + + " X2328(2328),\n" + + " X2329(2329),\n" + + " X2330(2330),\n" + + " X2331(2331),\n" + + " X2332(2332),\n" + + " X2333(2333),\n" + + " X2334(2334),\n" + + " X2335(2335),\n" + + " X2336(2336),\n" + + " X2337(2337),\n" + + " X2338(2338),\n" + + " X2339(2339),\n" + + " X2340(2340),\n" + + " X2341(2341),\n" + + " X2342(2342),\n" + + " X2343(2343),\n" + + " X2344(2344),\n" + + " X2345(2345),\n" + + " X2346(2346),\n" + + " X2347(2347),\n" + + " X2348(2348),\n" + + " X2349(2349),\n" + + " X2350(2350),\n" + + " X2351(2351),\n" + + " X2352(2352),\n" + + " X2353(2353),\n" + + " X2354(2354),\n" + + " X2355(2355),\n" + + " X2356(2356),\n" + + " X2357(2357),\n" + + " X2358(2358),\n" + + " X2359(2359),\n" + + " X2360(2360),\n" + + " X2361(2361),\n" + + " X2362(2362),\n" + + " X2363(2363),\n" + + " X2364(2364),\n" + + " X2365(2365),\n" + + " X2366(2366),\n" + + " X2367(2367),\n" + + " X2368(2368),\n" + + " X2369(2369),\n" + + " X2370(2370),\n" + + " X2371(2371),\n" + + " X2372(2372),\n" + + " X2373(2373),\n" + + " X2374(2374),\n" + + " X2375(2375),\n" + + " X2376(2376),\n" + + " X2377(2377),\n" + + " X2378(2378),\n" + + " X2379(2379),\n" + + " X2380(2380),\n" + + " X2381(2381),\n" + + " X2382(2382),\n" + + " X2383(2383),\n" + + " X2384(2384),\n" + + " X2385(2385),\n" + + " X2386(2386),\n" + + " X2387(2387),\n" + + " X2388(2388),\n" + + " X2389(2389),\n" + + " X2390(2390),\n" + + " X2391(2391),\n" + + " X2392(2392),\n" + + " X2393(2393),\n" + + " X2394(2394),\n" + + " X2395(2395),\n" + + " X2396(2396),\n" + + " X2397(2397),\n" + + " X2398(2398),\n" + + " X2399(2399),\n" + + " X2400(2400),\n" + + " X2401(2401),\n" + + " X2402(2402),\n" + + " X2403(2403),\n" + + " X2404(2404),\n" + + " X2405(2405),\n" + + " X2406(2406),\n" + + " X2407(2407),\n" + + " X2408(2408),\n" + + " X2409(2409),\n" + + " X2410(2410),\n" + + " X2411(2411),\n" + + " X2412(2412),\n" + + " X2413(2413),\n" + + " X2414(2414),\n" + + " X2415(2415),\n" + + " X2416(2416),\n" + + " X2417(2417),\n" + + " X2418(2418),\n" + + " X2419(2419),\n" + + " X2420(2420),\n" + + " X2421(2421),\n" + + " X2422(2422),\n" + + " X2423(2423),\n" + + " X2424(2424),\n" + + " X2425(2425),\n" + + " X2426(2426),\n" + + " X2427(2427),\n" + + " X2428(2428),\n" + + " X2429(2429),\n" + + " X2430(2430),\n" + + " X2431(2431),\n" + + " X2432(2432),\n" + + " X2433(2433),\n" + + " X2434(2434),\n" + + " X2435(2435),\n" + + " X2436(2436),\n" + + " X2437(2437),\n" + + " X2438(2438),\n" + + " X2439(2439),\n" + + " X2440(2440),\n" + + " X2441(2441),\n" + + " X2442(2442),\n" + + " X2443(2443),\n" + + " X2444(2444),\n" + + " X2445(2445),\n" + + " X2446(2446),\n" + + " X2447(2447),\n" + + " X2448(2448),\n" + + " X2449(2449),\n" + + " X2450(2450),\n" + + " X2451(2451),\n" + + " X2452(2452),\n" + + " X2453(2453),\n" + + " X2454(2454),\n" + + " X2455(2455),\n" + + " X2456(2456),\n" + + " X2457(2457),\n" + + " X2458(2458),\n" + + " X2459(2459),\n" + + " X2460(2460),\n" + + " X2461(2461),\n" + + " X2462(2462),\n" + + " X2463(2463),\n" + + " X2464(2464),\n" + + " X2465(2465),\n" + + " X2466(2466),\n" + + " X2467(2467),\n" + + " X2468(2468),\n" + + " X2469(2469),\n" + + " X2470(2470),\n" + + " X2471(2471),\n" + + " X2472(2472),\n" + + " X2473(2473),\n" + + " X2474(2474),\n" + + " X2475(2475),\n" + + " X2476(2476),\n" + + " X2477(2477),\n" + + " X2478(2478),\n" + + " X2479(2479),\n" + + " X2480(2480),\n" + + " X2481(2481),\n" + + " X2482(2482),\n" + + " X2483(2483),\n" + + " X2484(2484),\n" + + " X2485(2485),\n" + + " X2486(2486),\n" + + " X2487(2487),\n" + + " X2488(2488),\n" + + " X2489(2489),\n" + + " X2490(2490),\n" + + " X2491(2491),\n" + + " X2492(2492),\n" + + " X2493(2493),\n" + + " X2494(2494),\n" + + " X2495(2495),\n" + + " X2496(2496),\n" + + " X2497(2497),\n" + + " X2498(2498),\n" + + " X2499(2499),\n" + + " ;\n" + + "\n" + + " private int value;\n" + + " X(int i) {\n" + + " this.value = i;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int i = 0;\n" + + " for (X x : X.values()) {\n" + + " i++;\n" + + " System.out.print(x);\n" + + " }\n" + + " System.out.print(i);\n" + + " }\n" + + " \n" + + " public String toString() {\n" + + " return Integer.toString(this.value);\n" + + " }\n" + + "}" + }; + if (this.complianceLevel < ClassFileConstants.JDK9) { + this.runConformTest(src, buffer.toString()); + } else { + this.runNegativeTest(src, + "----------\n" + + "1. ERROR in X.java (at line 1)\n" + + " public enum X {\n" + + " ^\n" + + "The code for the static initializer is exceeding the 65535 bytes limit\n" + + "----------\n"); + } +} +public void test0017() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + // only run in 1.5 or above + StringBuilder buffer = new StringBuilder(); + buffer + .append("123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119") + .append("1201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022") + .append("0320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528") + .append("6287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369") + .append("3703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524") + .append("5345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553") + .append("6537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619") + .append("6206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027") + .append("0370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578") + .append("6787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869") + .append("8708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529") + .append("5395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610") + .append("2710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089") + .append("1090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111") + .append("5211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214") + .append("1215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612") + .append("7712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339") + .append("1340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114") + .append("0214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464") + .append("1465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615") + .append("2715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589") + .append("1590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116") + .append("5216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714") + .append("1715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617") + .append("7717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839") + .append("1840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119") + .append("0219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964") + .append("19651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012001"); + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " X1(1),\n" + + " X2(2),\n" + + " X3(3),\n" + + " X4(4),\n" + + " X5(5),\n" + + " X6(6),\n" + + " X7(7),\n" + + " X8(8),\n" + + " X9(9),\n" + + " X10(10),\n" + + " X11(11),\n" + + " X12(12),\n" + + " X13(13),\n" + + " X14(14),\n" + + " X15(15),\n" + + " X16(16),\n" + + " X17(17),\n" + + " X18(18),\n" + + " X19(19),\n" + + " X20(20),\n" + + " X21(21),\n" + + " X22(22),\n" + + " X23(23),\n" + + " X24(24),\n" + + " X25(25),\n" + + " X26(26),\n" + + " X27(27),\n" + + " X28(28),\n" + + " X29(29),\n" + + " X30(30),\n" + + " X31(31),\n" + + " X32(32),\n" + + " X33(33),\n" + + " X34(34),\n" + + " X35(35),\n" + + " X36(36),\n" + + " X37(37),\n" + + " X38(38),\n" + + " X39(39),\n" + + " X40(40),\n" + + " X41(41),\n" + + " X42(42),\n" + + " X43(43),\n" + + " X44(44),\n" + + " X45(45),\n" + + " X46(46),\n" + + " X47(47),\n" + + " X48(48),\n" + + " X49(49),\n" + + " X50(50),\n" + + " X51(51),\n" + + " X52(52),\n" + + " X53(53),\n" + + " X54(54),\n" + + " X55(55),\n" + + " X56(56),\n" + + " X57(57),\n" + + " X58(58),\n" + + " X59(59),\n" + + " X60(60),\n" + + " X61(61),\n" + + " X62(62),\n" + + " X63(63),\n" + + " X64(64),\n" + + " X65(65),\n" + + " X66(66),\n" + + " X67(67),\n" + + " X68(68),\n" + + " X69(69),\n" + + " X70(70),\n" + + " X71(71),\n" + + " X72(72),\n" + + " X73(73),\n" + + " X74(74),\n" + + " X75(75),\n" + + " X76(76),\n" + + " X77(77),\n" + + " X78(78),\n" + + " X79(79),\n" + + " X80(80),\n" + + " X81(81),\n" + + " X82(82),\n" + + " X83(83),\n" + + " X84(84),\n" + + " X85(85),\n" + + " X86(86),\n" + + " X87(87),\n" + + " X88(88),\n" + + " X89(89),\n" + + " X90(90),\n" + + " X91(91),\n" + + " X92(92),\n" + + " X93(93),\n" + + " X94(94),\n" + + " X95(95),\n" + + " X96(96),\n" + + " X97(97),\n" + + " X98(98),\n" + + " X99(99),\n" + + " X100(100),\n" + + " X101(101),\n" + + " X102(102),\n" + + " X103(103),\n" + + " X104(104),\n" + + " X105(105),\n" + + " X106(106),\n" + + " X107(107),\n" + + " X108(108),\n" + + " X109(109),\n" + + " X110(110),\n" + + " X111(111),\n" + + " X112(112),\n" + + " X113(113),\n" + + " X114(114),\n" + + " X115(115),\n" + + " X116(116),\n" + + " X117(117),\n" + + " X118(118),\n" + + " X119(119),\n" + + " X120(120),\n" + + " X121(121),\n" + + " X122(122),\n" + + " X123(123),\n" + + " X124(124),\n" + + " X125(125),\n" + + " X126(126),\n" + + " X127(127),\n" + + " X128(128),\n" + + " X129(129),\n" + + " X130(130),\n" + + " X131(131),\n" + + " X132(132),\n" + + " X133(133),\n" + + " X134(134),\n" + + " X135(135),\n" + + " X136(136),\n" + + " X137(137),\n" + + " X138(138),\n" + + " X139(139),\n" + + " X140(140),\n" + + " X141(141),\n" + + " X142(142),\n" + + " X143(143),\n" + + " X144(144),\n" + + " X145(145),\n" + + " X146(146),\n" + + " X147(147),\n" + + " X148(148),\n" + + " X149(149),\n" + + " X150(150),\n" + + " X151(151),\n" + + " X152(152),\n" + + " X153(153),\n" + + " X154(154),\n" + + " X155(155),\n" + + " X156(156),\n" + + " X157(157),\n" + + " X158(158),\n" + + " X159(159),\n" + + " X160(160),\n" + + " X161(161),\n" + + " X162(162),\n" + + " X163(163),\n" + + " X164(164),\n" + + " X165(165),\n" + + " X166(166),\n" + + " X167(167),\n" + + " X168(168),\n" + + " X169(169),\n" + + " X170(170),\n" + + " X171(171),\n" + + " X172(172),\n" + + " X173(173),\n" + + " X174(174),\n" + + " X175(175),\n" + + " X176(176),\n" + + " X177(177),\n" + + " X178(178),\n" + + " X179(179),\n" + + " X180(180),\n" + + " X181(181),\n" + + " X182(182),\n" + + " X183(183),\n" + + " X184(184),\n" + + " X185(185),\n" + + " X186(186),\n" + + " X187(187),\n" + + " X188(188),\n" + + " X189(189),\n" + + " X190(190),\n" + + " X191(191),\n" + + " X192(192),\n" + + " X193(193),\n" + + " X194(194),\n" + + " X195(195),\n" + + " X196(196),\n" + + " X197(197),\n" + + " X198(198),\n" + + " X199(199),\n" + + " X200(200),\n" + + " X201(201),\n" + + " X202(202),\n" + + " X203(203),\n" + + " X204(204),\n" + + " X205(205),\n" + + " X206(206),\n" + + " X207(207),\n" + + " X208(208),\n" + + " X209(209),\n" + + " X210(210),\n" + + " X211(211),\n" + + " X212(212),\n" + + " X213(213),\n" + + " X214(214),\n" + + " X215(215),\n" + + " X216(216),\n" + + " X217(217),\n" + + " X218(218),\n" + + " X219(219),\n" + + " X220(220),\n" + + " X221(221),\n" + + " X222(222),\n" + + " X223(223),\n" + + " X224(224),\n" + + " X225(225),\n" + + " X226(226),\n" + + " X227(227),\n" + + " X228(228),\n" + + " X229(229),\n" + + " X230(230),\n" + + " X231(231),\n" + + " X232(232),\n" + + " X233(233),\n" + + " X234(234),\n" + + " X235(235),\n" + + " X236(236),\n" + + " X237(237),\n" + + " X238(238),\n" + + " X239(239),\n" + + " X240(240),\n" + + " X241(241),\n" + + " X242(242),\n" + + " X243(243),\n" + + " X244(244),\n" + + " X245(245),\n" + + " X246(246),\n" + + " X247(247),\n" + + " X248(248),\n" + + " X249(249),\n" + + " X250(250),\n" + + " X251(251),\n" + + " X252(252),\n" + + " X253(253),\n" + + " X254(254),\n" + + " X255(255),\n" + + " X256(256),\n" + + " X257(257),\n" + + " X258(258),\n" + + " X259(259),\n" + + " X260(260),\n" + + " X261(261),\n" + + " X262(262),\n" + + " X263(263),\n" + + " X264(264),\n" + + " X265(265),\n" + + " X266(266),\n" + + " X267(267),\n" + + " X268(268),\n" + + " X269(269),\n" + + " X270(270),\n" + + " X271(271),\n" + + " X272(272),\n" + + " X273(273),\n" + + " X274(274),\n" + + " X275(275),\n" + + " X276(276),\n" + + " X277(277),\n" + + " X278(278),\n" + + " X279(279),\n" + + " X280(280),\n" + + " X281(281),\n" + + " X282(282),\n" + + " X283(283),\n" + + " X284(284),\n" + + " X285(285),\n" + + " X286(286),\n" + + " X287(287),\n" + + " X288(288),\n" + + " X289(289),\n" + + " X290(290),\n" + + " X291(291),\n" + + " X292(292),\n" + + " X293(293),\n" + + " X294(294),\n" + + " X295(295),\n" + + " X296(296),\n" + + " X297(297),\n" + + " X298(298),\n" + + " X299(299),\n" + + " X300(300),\n" + + " X301(301),\n" + + " X302(302),\n" + + " X303(303),\n" + + " X304(304),\n" + + " X305(305),\n" + + " X306(306),\n" + + " X307(307),\n" + + " X308(308),\n" + + " X309(309),\n" + + " X310(310),\n" + + " X311(311),\n" + + " X312(312),\n" + + " X313(313),\n" + + " X314(314),\n" + + " X315(315),\n" + + " X316(316),\n" + + " X317(317),\n" + + " X318(318),\n" + + " X319(319),\n" + + " X320(320),\n" + + " X321(321),\n" + + " X322(322),\n" + + " X323(323),\n" + + " X324(324),\n" + + " X325(325),\n" + + " X326(326),\n" + + " X327(327),\n" + + " X328(328),\n" + + " X329(329),\n" + + " X330(330),\n" + + " X331(331),\n" + + " X332(332),\n" + + " X333(333),\n" + + " X334(334),\n" + + " X335(335),\n" + + " X336(336),\n" + + " X337(337),\n" + + " X338(338),\n" + + " X339(339),\n" + + " X340(340),\n" + + " X341(341),\n" + + " X342(342),\n" + + " X343(343),\n" + + " X344(344),\n" + + " X345(345),\n" + + " X346(346),\n" + + " X347(347),\n" + + " X348(348),\n" + + " X349(349),\n" + + " X350(350),\n" + + " X351(351),\n" + + " X352(352),\n" + + " X353(353),\n" + + " X354(354),\n" + + " X355(355),\n" + + " X356(356),\n" + + " X357(357),\n" + + " X358(358),\n" + + " X359(359),\n" + + " X360(360),\n" + + " X361(361),\n" + + " X362(362),\n" + + " X363(363),\n" + + " X364(364),\n" + + " X365(365),\n" + + " X366(366),\n" + + " X367(367),\n" + + " X368(368),\n" + + " X369(369),\n" + + " X370(370),\n" + + " X371(371),\n" + + " X372(372),\n" + + " X373(373),\n" + + " X374(374),\n" + + " X375(375),\n" + + " X376(376),\n" + + " X377(377),\n" + + " X378(378),\n" + + " X379(379),\n" + + " X380(380),\n" + + " X381(381),\n" + + " X382(382),\n" + + " X383(383),\n" + + " X384(384),\n" + + " X385(385),\n" + + " X386(386),\n" + + " X387(387),\n" + + " X388(388),\n" + + " X389(389),\n" + + " X390(390),\n" + + " X391(391),\n" + + " X392(392),\n" + + " X393(393),\n" + + " X394(394),\n" + + " X395(395),\n" + + " X396(396),\n" + + " X397(397),\n" + + " X398(398),\n" + + " X399(399),\n" + + " X400(400),\n" + + " X401(401),\n" + + " X402(402),\n" + + " X403(403),\n" + + " X404(404),\n" + + " X405(405),\n" + + " X406(406),\n" + + " X407(407),\n" + + " X408(408),\n" + + " X409(409),\n" + + " X410(410),\n" + + " X411(411),\n" + + " X412(412),\n" + + " X413(413),\n" + + " X414(414),\n" + + " X415(415),\n" + + " X416(416),\n" + + " X417(417),\n" + + " X418(418),\n" + + " X419(419),\n" + + " X420(420),\n" + + " X421(421),\n" + + " X422(422),\n" + + " X423(423),\n" + + " X424(424),\n" + + " X425(425),\n" + + " X426(426),\n" + + " X427(427),\n" + + " X428(428),\n" + + " X429(429),\n" + + " X430(430),\n" + + " X431(431),\n" + + " X432(432),\n" + + " X433(433),\n" + + " X434(434),\n" + + " X435(435),\n" + + " X436(436),\n" + + " X437(437),\n" + + " X438(438),\n" + + " X439(439),\n" + + " X440(440),\n" + + " X441(441),\n" + + " X442(442),\n" + + " X443(443),\n" + + " X444(444),\n" + + " X445(445),\n" + + " X446(446),\n" + + " X447(447),\n" + + " X448(448),\n" + + " X449(449),\n" + + " X450(450),\n" + + " X451(451),\n" + + " X452(452),\n" + + " X453(453),\n" + + " X454(454),\n" + + " X455(455),\n" + + " X456(456),\n" + + " X457(457),\n" + + " X458(458),\n" + + " X459(459),\n" + + " X460(460),\n" + + " X461(461),\n" + + " X462(462),\n" + + " X463(463),\n" + + " X464(464),\n" + + " X465(465),\n" + + " X466(466),\n" + + " X467(467),\n" + + " X468(468),\n" + + " X469(469),\n" + + " X470(470),\n" + + " X471(471),\n" + + " X472(472),\n" + + " X473(473),\n" + + " X474(474),\n" + + " X475(475),\n" + + " X476(476),\n" + + " X477(477),\n" + + " X478(478),\n" + + " X479(479),\n" + + " X480(480),\n" + + " X481(481),\n" + + " X482(482),\n" + + " X483(483),\n" + + " X484(484),\n" + + " X485(485),\n" + + " X486(486),\n" + + " X487(487),\n" + + " X488(488),\n" + + " X489(489),\n" + + " X490(490),\n" + + " X491(491),\n" + + " X492(492),\n" + + " X493(493),\n" + + " X494(494),\n" + + " X495(495),\n" + + " X496(496),\n" + + " X497(497),\n" + + " X498(498),\n" + + " X499(499),\n" + + " X500(500),\n" + + " X501(501),\n" + + " X502(502),\n" + + " X503(503),\n" + + " X504(504),\n" + + " X505(505),\n" + + " X506(506),\n" + + " X507(507),\n" + + " X508(508),\n" + + " X509(509),\n" + + " X510(510),\n" + + " X511(511),\n" + + " X512(512),\n" + + " X513(513),\n" + + " X514(514),\n" + + " X515(515),\n" + + " X516(516),\n" + + " X517(517),\n" + + " X518(518),\n" + + " X519(519),\n" + + " X520(520),\n" + + " X521(521),\n" + + " X522(522),\n" + + " X523(523),\n" + + " X524(524),\n" + + " X525(525),\n" + + " X526(526),\n" + + " X527(527),\n" + + " X528(528),\n" + + " X529(529),\n" + + " X530(530),\n" + + " X531(531),\n" + + " X532(532),\n" + + " X533(533),\n" + + " X534(534),\n" + + " X535(535),\n" + + " X536(536),\n" + + " X537(537),\n" + + " X538(538),\n" + + " X539(539),\n" + + " X540(540),\n" + + " X541(541),\n" + + " X542(542),\n" + + " X543(543),\n" + + " X544(544),\n" + + " X545(545),\n" + + " X546(546),\n" + + " X547(547),\n" + + " X548(548),\n" + + " X549(549),\n" + + " X550(550),\n" + + " X551(551),\n" + + " X552(552),\n" + + " X553(553),\n" + + " X554(554),\n" + + " X555(555),\n" + + " X556(556),\n" + + " X557(557),\n" + + " X558(558),\n" + + " X559(559),\n" + + " X560(560),\n" + + " X561(561),\n" + + " X562(562),\n" + + " X563(563),\n" + + " X564(564),\n" + + " X565(565),\n" + + " X566(566),\n" + + " X567(567),\n" + + " X568(568),\n" + + " X569(569),\n" + + " X570(570),\n" + + " X571(571),\n" + + " X572(572),\n" + + " X573(573),\n" + + " X574(574),\n" + + " X575(575),\n" + + " X576(576),\n" + + " X577(577),\n" + + " X578(578),\n" + + " X579(579),\n" + + " X580(580),\n" + + " X581(581),\n" + + " X582(582),\n" + + " X583(583),\n" + + " X584(584),\n" + + " X585(585),\n" + + " X586(586),\n" + + " X587(587),\n" + + " X588(588),\n" + + " X589(589),\n" + + " X590(590),\n" + + " X591(591),\n" + + " X592(592),\n" + + " X593(593),\n" + + " X594(594),\n" + + " X595(595),\n" + + " X596(596),\n" + + " X597(597),\n" + + " X598(598),\n" + + " X599(599),\n" + + " X600(600),\n" + + " X601(601),\n" + + " X602(602),\n" + + " X603(603),\n" + + " X604(604),\n" + + " X605(605),\n" + + " X606(606),\n" + + " X607(607),\n" + + " X608(608),\n" + + " X609(609),\n" + + " X610(610),\n" + + " X611(611),\n" + + " X612(612),\n" + + " X613(613),\n" + + " X614(614),\n" + + " X615(615),\n" + + " X616(616),\n" + + " X617(617),\n" + + " X618(618),\n" + + " X619(619),\n" + + " X620(620),\n" + + " X621(621),\n" + + " X622(622),\n" + + " X623(623),\n" + + " X624(624),\n" + + " X625(625),\n" + + " X626(626),\n" + + " X627(627),\n" + + " X628(628),\n" + + " X629(629),\n" + + " X630(630),\n" + + " X631(631),\n" + + " X632(632),\n" + + " X633(633),\n" + + " X634(634),\n" + + " X635(635),\n" + + " X636(636),\n" + + " X637(637),\n" + + " X638(638),\n" + + " X639(639),\n" + + " X640(640),\n" + + " X641(641),\n" + + " X642(642),\n" + + " X643(643),\n" + + " X644(644),\n" + + " X645(645),\n" + + " X646(646),\n" + + " X647(647),\n" + + " X648(648),\n" + + " X649(649),\n" + + " X650(650),\n" + + " X651(651),\n" + + " X652(652),\n" + + " X653(653),\n" + + " X654(654),\n" + + " X655(655),\n" + + " X656(656),\n" + + " X657(657),\n" + + " X658(658),\n" + + " X659(659),\n" + + " X660(660),\n" + + " X661(661),\n" + + " X662(662),\n" + + " X663(663),\n" + + " X664(664),\n" + + " X665(665),\n" + + " X666(666),\n" + + " X667(667),\n" + + " X668(668),\n" + + " X669(669),\n" + + " X670(670),\n" + + " X671(671),\n" + + " X672(672),\n" + + " X673(673),\n" + + " X674(674),\n" + + " X675(675),\n" + + " X676(676),\n" + + " X677(677),\n" + + " X678(678),\n" + + " X679(679),\n" + + " X680(680),\n" + + " X681(681),\n" + + " X682(682),\n" + + " X683(683),\n" + + " X684(684),\n" + + " X685(685),\n" + + " X686(686),\n" + + " X687(687),\n" + + " X688(688),\n" + + " X689(689),\n" + + " X690(690),\n" + + " X691(691),\n" + + " X692(692),\n" + + " X693(693),\n" + + " X694(694),\n" + + " X695(695),\n" + + " X696(696),\n" + + " X697(697),\n" + + " X698(698),\n" + + " X699(699),\n" + + " X700(700),\n" + + " X701(701),\n" + + " X702(702),\n" + + " X703(703),\n" + + " X704(704),\n" + + " X705(705),\n" + + " X706(706),\n" + + " X707(707),\n" + + " X708(708),\n" + + " X709(709),\n" + + " X710(710),\n" + + " X711(711),\n" + + " X712(712),\n" + + " X713(713),\n" + + " X714(714),\n" + + " X715(715),\n" + + " X716(716),\n" + + " X717(717),\n" + + " X718(718),\n" + + " X719(719),\n" + + " X720(720),\n" + + " X721(721),\n" + + " X722(722),\n" + + " X723(723),\n" + + " X724(724),\n" + + " X725(725),\n" + + " X726(726),\n" + + " X727(727),\n" + + " X728(728),\n" + + " X729(729),\n" + + " X730(730),\n" + + " X731(731),\n" + + " X732(732),\n" + + " X733(733),\n" + + " X734(734),\n" + + " X735(735),\n" + + " X736(736),\n" + + " X737(737),\n" + + " X738(738),\n" + + " X739(739),\n" + + " X740(740),\n" + + " X741(741),\n" + + " X742(742),\n" + + " X743(743),\n" + + " X744(744),\n" + + " X745(745),\n" + + " X746(746),\n" + + " X747(747),\n" + + " X748(748),\n" + + " X749(749),\n" + + " X750(750),\n" + + " X751(751),\n" + + " X752(752),\n" + + " X753(753),\n" + + " X754(754),\n" + + " X755(755),\n" + + " X756(756),\n" + + " X757(757),\n" + + " X758(758),\n" + + " X759(759),\n" + + " X760(760),\n" + + " X761(761),\n" + + " X762(762),\n" + + " X763(763),\n" + + " X764(764),\n" + + " X765(765),\n" + + " X766(766),\n" + + " X767(767),\n" + + " X768(768),\n" + + " X769(769),\n" + + " X770(770),\n" + + " X771(771),\n" + + " X772(772),\n" + + " X773(773),\n" + + " X774(774),\n" + + " X775(775),\n" + + " X776(776),\n" + + " X777(777),\n" + + " X778(778),\n" + + " X779(779),\n" + + " X780(780),\n" + + " X781(781),\n" + + " X782(782),\n" + + " X783(783),\n" + + " X784(784),\n" + + " X785(785),\n" + + " X786(786),\n" + + " X787(787),\n" + + " X788(788),\n" + + " X789(789),\n" + + " X790(790),\n" + + " X791(791),\n" + + " X792(792),\n" + + " X793(793),\n" + + " X794(794),\n" + + " X795(795),\n" + + " X796(796),\n" + + " X797(797),\n" + + " X798(798),\n" + + " X799(799),\n" + + " X800(800),\n" + + " X801(801),\n" + + " X802(802),\n" + + " X803(803),\n" + + " X804(804),\n" + + " X805(805),\n" + + " X806(806),\n" + + " X807(807),\n" + + " X808(808),\n" + + " X809(809),\n" + + " X810(810),\n" + + " X811(811),\n" + + " X812(812),\n" + + " X813(813),\n" + + " X814(814),\n" + + " X815(815),\n" + + " X816(816),\n" + + " X817(817),\n" + + " X818(818),\n" + + " X819(819),\n" + + " X820(820),\n" + + " X821(821),\n" + + " X822(822),\n" + + " X823(823),\n" + + " X824(824),\n" + + " X825(825),\n" + + " X826(826),\n" + + " X827(827),\n" + + " X828(828),\n" + + " X829(829),\n" + + " X830(830),\n" + + " X831(831),\n" + + " X832(832),\n" + + " X833(833),\n" + + " X834(834),\n" + + " X835(835),\n" + + " X836(836),\n" + + " X837(837),\n" + + " X838(838),\n" + + " X839(839),\n" + + " X840(840),\n" + + " X841(841),\n" + + " X842(842),\n" + + " X843(843),\n" + + " X844(844),\n" + + " X845(845),\n" + + " X846(846),\n" + + " X847(847),\n" + + " X848(848),\n" + + " X849(849),\n" + + " X850(850),\n" + + " X851(851),\n" + + " X852(852),\n" + + " X853(853),\n" + + " X854(854),\n" + + " X855(855),\n" + + " X856(856),\n" + + " X857(857),\n" + + " X858(858),\n" + + " X859(859),\n" + + " X860(860),\n" + + " X861(861),\n" + + " X862(862),\n" + + " X863(863),\n" + + " X864(864),\n" + + " X865(865),\n" + + " X866(866),\n" + + " X867(867),\n" + + " X868(868),\n" + + " X869(869),\n" + + " X870(870),\n" + + " X871(871),\n" + + " X872(872),\n" + + " X873(873),\n" + + " X874(874),\n" + + " X875(875),\n" + + " X876(876),\n" + + " X877(877),\n" + + " X878(878),\n" + + " X879(879),\n" + + " X880(880),\n" + + " X881(881),\n" + + " X882(882),\n" + + " X883(883),\n" + + " X884(884),\n" + + " X885(885),\n" + + " X886(886),\n" + + " X887(887),\n" + + " X888(888),\n" + + " X889(889),\n" + + " X890(890),\n" + + " X891(891),\n" + + " X892(892),\n" + + " X893(893),\n" + + " X894(894),\n" + + " X895(895),\n" + + " X896(896),\n" + + " X897(897),\n" + + " X898(898),\n" + + " X899(899),\n" + + " X900(900),\n" + + " X901(901),\n" + + " X902(902),\n" + + " X903(903),\n" + + " X904(904),\n" + + " X905(905),\n" + + " X906(906),\n" + + " X907(907),\n" + + " X908(908),\n" + + " X909(909),\n" + + " X910(910),\n" + + " X911(911),\n" + + " X912(912),\n" + + " X913(913),\n" + + " X914(914),\n" + + " X915(915),\n" + + " X916(916),\n" + + " X917(917),\n" + + " X918(918),\n" + + " X919(919),\n" + + " X920(920),\n" + + " X921(921),\n" + + " X922(922),\n" + + " X923(923),\n" + + " X924(924),\n" + + " X925(925),\n" + + " X926(926),\n" + + " X927(927),\n" + + " X928(928),\n" + + " X929(929),\n" + + " X930(930),\n" + + " X931(931),\n" + + " X932(932),\n" + + " X933(933),\n" + + " X934(934),\n" + + " X935(935),\n" + + " X936(936),\n" + + " X937(937),\n" + + " X938(938),\n" + + " X939(939),\n" + + " X940(940),\n" + + " X941(941),\n" + + " X942(942),\n" + + " X943(943),\n" + + " X944(944),\n" + + " X945(945),\n" + + " X946(946),\n" + + " X947(947),\n" + + " X948(948),\n" + + " X949(949),\n" + + " X950(950),\n" + + " X951(951),\n" + + " X952(952),\n" + + " X953(953),\n" + + " X954(954),\n" + + " X955(955),\n" + + " X956(956),\n" + + " X957(957),\n" + + " X958(958),\n" + + " X959(959),\n" + + " X960(960),\n" + + " X961(961),\n" + + " X962(962),\n" + + " X963(963),\n" + + " X964(964),\n" + + " X965(965),\n" + + " X966(966),\n" + + " X967(967),\n" + + " X968(968),\n" + + " X969(969),\n" + + " X970(970),\n" + + " X971(971),\n" + + " X972(972),\n" + + " X973(973),\n" + + " X974(974),\n" + + " X975(975),\n" + + " X976(976),\n" + + " X977(977),\n" + + " X978(978),\n" + + " X979(979),\n" + + " X980(980),\n" + + " X981(981),\n" + + " X982(982),\n" + + " X983(983),\n" + + " X984(984),\n" + + " X985(985),\n" + + " X986(986),\n" + + " X987(987),\n" + + " X988(988),\n" + + " X989(989),\n" + + " X990(990),\n" + + " X991(991),\n" + + " X992(992),\n" + + " X993(993),\n" + + " X994(994),\n" + + " X995(995),\n" + + " X996(996),\n" + + " X997(997),\n" + + " X998(998),\n" + + " X999(999),\n" + + " X1000(1000),\n" + + " X1001(1001),\n" + + " X1002(1002),\n" + + " X1003(1003),\n" + + " X1004(1004),\n" + + " X1005(1005),\n" + + " X1006(1006),\n" + + " X1007(1007),\n" + + " X1008(1008),\n" + + " X1009(1009),\n" + + " X1010(1010),\n" + + " X1011(1011),\n" + + " X1012(1012),\n" + + " X1013(1013),\n" + + " X1014(1014),\n" + + " X1015(1015),\n" + + " X1016(1016),\n" + + " X1017(1017),\n" + + " X1018(1018),\n" + + " X1019(1019),\n" + + " X1020(1020),\n" + + " X1021(1021),\n" + + " X1022(1022),\n" + + " X1023(1023),\n" + + " X1024(1024),\n" + + " X1025(1025),\n" + + " X1026(1026),\n" + + " X1027(1027),\n" + + " X1028(1028),\n" + + " X1029(1029),\n" + + " X1030(1030),\n" + + " X1031(1031),\n" + + " X1032(1032),\n" + + " X1033(1033),\n" + + " X1034(1034),\n" + + " X1035(1035),\n" + + " X1036(1036),\n" + + " X1037(1037),\n" + + " X1038(1038),\n" + + " X1039(1039),\n" + + " X1040(1040),\n" + + " X1041(1041),\n" + + " X1042(1042),\n" + + " X1043(1043),\n" + + " X1044(1044),\n" + + " X1045(1045),\n" + + " X1046(1046),\n" + + " X1047(1047),\n" + + " X1048(1048),\n" + + " X1049(1049),\n" + + " X1050(1050),\n" + + " X1051(1051),\n" + + " X1052(1052),\n" + + " X1053(1053),\n" + + " X1054(1054),\n" + + " X1055(1055),\n" + + " X1056(1056),\n" + + " X1057(1057),\n" + + " X1058(1058),\n" + + " X1059(1059),\n" + + " X1060(1060),\n" + + " X1061(1061),\n" + + " X1062(1062),\n" + + " X1063(1063),\n" + + " X1064(1064),\n" + + " X1065(1065),\n" + + " X1066(1066),\n" + + " X1067(1067),\n" + + " X1068(1068),\n" + + " X1069(1069),\n" + + " X1070(1070),\n" + + " X1071(1071),\n" + + " X1072(1072),\n" + + " X1073(1073),\n" + + " X1074(1074),\n" + + " X1075(1075),\n" + + " X1076(1076),\n" + + " X1077(1077),\n" + + " X1078(1078),\n" + + " X1079(1079),\n" + + " X1080(1080),\n" + + " X1081(1081),\n" + + " X1082(1082),\n" + + " X1083(1083),\n" + + " X1084(1084),\n" + + " X1085(1085),\n" + + " X1086(1086),\n" + + " X1087(1087),\n" + + " X1088(1088),\n" + + " X1089(1089),\n" + + " X1090(1090),\n" + + " X1091(1091),\n" + + " X1092(1092),\n" + + " X1093(1093),\n" + + " X1094(1094),\n" + + " X1095(1095),\n" + + " X1096(1096),\n" + + " X1097(1097),\n" + + " X1098(1098),\n" + + " X1099(1099),\n" + + " X1100(1100),\n" + + " X1101(1101),\n" + + " X1102(1102),\n" + + " X1103(1103),\n" + + " X1104(1104),\n" + + " X1105(1105),\n" + + " X1106(1106),\n" + + " X1107(1107),\n" + + " X1108(1108),\n" + + " X1109(1109),\n" + + " X1110(1110),\n" + + " X1111(1111),\n" + + " X1112(1112),\n" + + " X1113(1113),\n" + + " X1114(1114),\n" + + " X1115(1115),\n" + + " X1116(1116),\n" + + " X1117(1117),\n" + + " X1118(1118),\n" + + " X1119(1119),\n" + + " X1120(1120),\n" + + " X1121(1121),\n" + + " X1122(1122),\n" + + " X1123(1123),\n" + + " X1124(1124),\n" + + " X1125(1125),\n" + + " X1126(1126),\n" + + " X1127(1127),\n" + + " X1128(1128),\n" + + " X1129(1129),\n" + + " X1130(1130),\n" + + " X1131(1131),\n" + + " X1132(1132),\n" + + " X1133(1133),\n" + + " X1134(1134),\n" + + " X1135(1135),\n" + + " X1136(1136),\n" + + " X1137(1137),\n" + + " X1138(1138),\n" + + " X1139(1139),\n" + + " X1140(1140),\n" + + " X1141(1141),\n" + + " X1142(1142),\n" + + " X1143(1143),\n" + + " X1144(1144),\n" + + " X1145(1145),\n" + + " X1146(1146),\n" + + " X1147(1147),\n" + + " X1148(1148),\n" + + " X1149(1149),\n" + + " X1150(1150),\n" + + " X1151(1151),\n" + + " X1152(1152),\n" + + " X1153(1153),\n" + + " X1154(1154),\n" + + " X1155(1155),\n" + + " X1156(1156),\n" + + " X1157(1157),\n" + + " X1158(1158),\n" + + " X1159(1159),\n" + + " X1160(1160),\n" + + " X1161(1161),\n" + + " X1162(1162),\n" + + " X1163(1163),\n" + + " X1164(1164),\n" + + " X1165(1165),\n" + + " X1166(1166),\n" + + " X1167(1167),\n" + + " X1168(1168),\n" + + " X1169(1169),\n" + + " X1170(1170),\n" + + " X1171(1171),\n" + + " X1172(1172),\n" + + " X1173(1173),\n" + + " X1174(1174),\n" + + " X1175(1175),\n" + + " X1176(1176),\n" + + " X1177(1177),\n" + + " X1178(1178),\n" + + " X1179(1179),\n" + + " X1180(1180),\n" + + " X1181(1181),\n" + + " X1182(1182),\n" + + " X1183(1183),\n" + + " X1184(1184),\n" + + " X1185(1185),\n" + + " X1186(1186),\n" + + " X1187(1187),\n" + + " X1188(1188),\n" + + " X1189(1189),\n" + + " X1190(1190),\n" + + " X1191(1191),\n" + + " X1192(1192),\n" + + " X1193(1193),\n" + + " X1194(1194),\n" + + " X1195(1195),\n" + + " X1196(1196),\n" + + " X1197(1197),\n" + + " X1198(1198),\n" + + " X1199(1199),\n" + + " X1200(1200),\n" + + " X1201(1201),\n" + + " X1202(1202),\n" + + " X1203(1203),\n" + + " X1204(1204),\n" + + " X1205(1205),\n" + + " X1206(1206),\n" + + " X1207(1207),\n" + + " X1208(1208),\n" + + " X1209(1209),\n" + + " X1210(1210),\n" + + " X1211(1211),\n" + + " X1212(1212),\n" + + " X1213(1213),\n" + + " X1214(1214),\n" + + " X1215(1215),\n" + + " X1216(1216),\n" + + " X1217(1217),\n" + + " X1218(1218),\n" + + " X1219(1219),\n" + + " X1220(1220),\n" + + " X1221(1221),\n" + + " X1222(1222),\n" + + " X1223(1223),\n" + + " X1224(1224),\n" + + " X1225(1225),\n" + + " X1226(1226),\n" + + " X1227(1227),\n" + + " X1228(1228),\n" + + " X1229(1229),\n" + + " X1230(1230),\n" + + " X1231(1231),\n" + + " X1232(1232),\n" + + " X1233(1233),\n" + + " X1234(1234),\n" + + " X1235(1235),\n" + + " X1236(1236),\n" + + " X1237(1237),\n" + + " X1238(1238),\n" + + " X1239(1239),\n" + + " X1240(1240),\n" + + " X1241(1241),\n" + + " X1242(1242),\n" + + " X1243(1243),\n" + + " X1244(1244),\n" + + " X1245(1245),\n" + + " X1246(1246),\n" + + " X1247(1247),\n" + + " X1248(1248),\n" + + " X1249(1249),\n" + + " X1250(1250),\n" + + " X1251(1251),\n" + + " X1252(1252),\n" + + " X1253(1253),\n" + + " X1254(1254),\n" + + " X1255(1255),\n" + + " X1256(1256),\n" + + " X1257(1257),\n" + + " X1258(1258),\n" + + " X1259(1259),\n" + + " X1260(1260),\n" + + " X1261(1261),\n" + + " X1262(1262),\n" + + " X1263(1263),\n" + + " X1264(1264),\n" + + " X1265(1265),\n" + + " X1266(1266),\n" + + " X1267(1267),\n" + + " X1268(1268),\n" + + " X1269(1269),\n" + + " X1270(1270),\n" + + " X1271(1271),\n" + + " X1272(1272),\n" + + " X1273(1273),\n" + + " X1274(1274),\n" + + " X1275(1275),\n" + + " X1276(1276),\n" + + " X1277(1277),\n" + + " X1278(1278),\n" + + " X1279(1279),\n" + + " X1280(1280),\n" + + " X1281(1281),\n" + + " X1282(1282),\n" + + " X1283(1283),\n" + + " X1284(1284),\n" + + " X1285(1285),\n" + + " X1286(1286),\n" + + " X1287(1287),\n" + + " X1288(1288),\n" + + " X1289(1289),\n" + + " X1290(1290),\n" + + " X1291(1291),\n" + + " X1292(1292),\n" + + " X1293(1293),\n" + + " X1294(1294),\n" + + " X1295(1295),\n" + + " X1296(1296),\n" + + " X1297(1297),\n" + + " X1298(1298),\n" + + " X1299(1299),\n" + + " X1300(1300),\n" + + " X1301(1301),\n" + + " X1302(1302),\n" + + " X1303(1303),\n" + + " X1304(1304),\n" + + " X1305(1305),\n" + + " X1306(1306),\n" + + " X1307(1307),\n" + + " X1308(1308),\n" + + " X1309(1309),\n" + + " X1310(1310),\n" + + " X1311(1311),\n" + + " X1312(1312),\n" + + " X1313(1313),\n" + + " X1314(1314),\n" + + " X1315(1315),\n" + + " X1316(1316),\n" + + " X1317(1317),\n" + + " X1318(1318),\n" + + " X1319(1319),\n" + + " X1320(1320),\n" + + " X1321(1321),\n" + + " X1322(1322),\n" + + " X1323(1323),\n" + + " X1324(1324),\n" + + " X1325(1325),\n" + + " X1326(1326),\n" + + " X1327(1327),\n" + + " X1328(1328),\n" + + " X1329(1329),\n" + + " X1330(1330),\n" + + " X1331(1331),\n" + + " X1332(1332),\n" + + " X1333(1333),\n" + + " X1334(1334),\n" + + " X1335(1335),\n" + + " X1336(1336),\n" + + " X1337(1337),\n" + + " X1338(1338),\n" + + " X1339(1339),\n" + + " X1340(1340),\n" + + " X1341(1341),\n" + + " X1342(1342),\n" + + " X1343(1343),\n" + + " X1344(1344),\n" + + " X1345(1345),\n" + + " X1346(1346),\n" + + " X1347(1347),\n" + + " X1348(1348),\n" + + " X1349(1349),\n" + + " X1350(1350),\n" + + " X1351(1351),\n" + + " X1352(1352),\n" + + " X1353(1353),\n" + + " X1354(1354),\n" + + " X1355(1355),\n" + + " X1356(1356),\n" + + " X1357(1357),\n" + + " X1358(1358),\n" + + " X1359(1359),\n" + + " X1360(1360),\n" + + " X1361(1361),\n" + + " X1362(1362),\n" + + " X1363(1363),\n" + + " X1364(1364),\n" + + " X1365(1365),\n" + + " X1366(1366),\n" + + " X1367(1367),\n" + + " X1368(1368),\n" + + " X1369(1369),\n" + + " X1370(1370),\n" + + " X1371(1371),\n" + + " X1372(1372),\n" + + " X1373(1373),\n" + + " X1374(1374),\n" + + " X1375(1375),\n" + + " X1376(1376),\n" + + " X1377(1377),\n" + + " X1378(1378),\n" + + " X1379(1379),\n" + + " X1380(1380),\n" + + " X1381(1381),\n" + + " X1382(1382),\n" + + " X1383(1383),\n" + + " X1384(1384),\n" + + " X1385(1385),\n" + + " X1386(1386),\n" + + " X1387(1387),\n" + + " X1388(1388),\n" + + " X1389(1389),\n" + + " X1390(1390),\n" + + " X1391(1391),\n" + + " X1392(1392),\n" + + " X1393(1393),\n" + + " X1394(1394),\n" + + " X1395(1395),\n" + + " X1396(1396),\n" + + " X1397(1397),\n" + + " X1398(1398),\n" + + " X1399(1399),\n" + + " X1400(1400),\n" + + " X1401(1401),\n" + + " X1402(1402),\n" + + " X1403(1403),\n" + + " X1404(1404),\n" + + " X1405(1405),\n" + + " X1406(1406),\n" + + " X1407(1407),\n" + + " X1408(1408),\n" + + " X1409(1409),\n" + + " X1410(1410),\n" + + " X1411(1411),\n" + + " X1412(1412),\n" + + " X1413(1413),\n" + + " X1414(1414),\n" + + " X1415(1415),\n" + + " X1416(1416),\n" + + " X1417(1417),\n" + + " X1418(1418),\n" + + " X1419(1419),\n" + + " X1420(1420),\n" + + " X1421(1421),\n" + + " X1422(1422),\n" + + " X1423(1423),\n" + + " X1424(1424),\n" + + " X1425(1425),\n" + + " X1426(1426),\n" + + " X1427(1427),\n" + + " X1428(1428),\n" + + " X1429(1429),\n" + + " X1430(1430),\n" + + " X1431(1431),\n" + + " X1432(1432),\n" + + " X1433(1433),\n" + + " X1434(1434),\n" + + " X1435(1435),\n" + + " X1436(1436),\n" + + " X1437(1437),\n" + + " X1438(1438),\n" + + " X1439(1439),\n" + + " X1440(1440),\n" + + " X1441(1441),\n" + + " X1442(1442),\n" + + " X1443(1443),\n" + + " X1444(1444),\n" + + " X1445(1445),\n" + + " X1446(1446),\n" + + " X1447(1447),\n" + + " X1448(1448),\n" + + " X1449(1449),\n" + + " X1450(1450),\n" + + " X1451(1451),\n" + + " X1452(1452),\n" + + " X1453(1453),\n" + + " X1454(1454),\n" + + " X1455(1455),\n" + + " X1456(1456),\n" + + " X1457(1457),\n" + + " X1458(1458),\n" + + " X1459(1459),\n" + + " X1460(1460),\n" + + " X1461(1461),\n" + + " X1462(1462),\n" + + " X1463(1463),\n" + + " X1464(1464),\n" + + " X1465(1465),\n" + + " X1466(1466),\n" + + " X1467(1467),\n" + + " X1468(1468),\n" + + " X1469(1469),\n" + + " X1470(1470),\n" + + " X1471(1471),\n" + + " X1472(1472),\n" + + " X1473(1473),\n" + + " X1474(1474),\n" + + " X1475(1475),\n" + + " X1476(1476),\n" + + " X1477(1477),\n" + + " X1478(1478),\n" + + " X1479(1479),\n" + + " X1480(1480),\n" + + " X1481(1481),\n" + + " X1482(1482),\n" + + " X1483(1483),\n" + + " X1484(1484),\n" + + " X1485(1485),\n" + + " X1486(1486),\n" + + " X1487(1487),\n" + + " X1488(1488),\n" + + " X1489(1489),\n" + + " X1490(1490),\n" + + " X1491(1491),\n" + + " X1492(1492),\n" + + " X1493(1493),\n" + + " X1494(1494),\n" + + " X1495(1495),\n" + + " X1496(1496),\n" + + " X1497(1497),\n" + + " X1498(1498),\n" + + " X1499(1499),\n" + + " X1500(1500),\n" + + " X1501(1501),\n" + + " X1502(1502),\n" + + " X1503(1503),\n" + + " X1504(1504),\n" + + " X1505(1505),\n" + + " X1506(1506),\n" + + " X1507(1507),\n" + + " X1508(1508),\n" + + " X1509(1509),\n" + + " X1510(1510),\n" + + " X1511(1511),\n" + + " X1512(1512),\n" + + " X1513(1513),\n" + + " X1514(1514),\n" + + " X1515(1515),\n" + + " X1516(1516),\n" + + " X1517(1517),\n" + + " X1518(1518),\n" + + " X1519(1519),\n" + + " X1520(1520),\n" + + " X1521(1521),\n" + + " X1522(1522),\n" + + " X1523(1523),\n" + + " X1524(1524),\n" + + " X1525(1525),\n" + + " X1526(1526),\n" + + " X1527(1527),\n" + + " X1528(1528),\n" + + " X1529(1529),\n" + + " X1530(1530),\n" + + " X1531(1531),\n" + + " X1532(1532),\n" + + " X1533(1533),\n" + + " X1534(1534),\n" + + " X1535(1535),\n" + + " X1536(1536),\n" + + " X1537(1537),\n" + + " X1538(1538),\n" + + " X1539(1539),\n" + + " X1540(1540),\n" + + " X1541(1541),\n" + + " X1542(1542),\n" + + " X1543(1543),\n" + + " X1544(1544),\n" + + " X1545(1545),\n" + + " X1546(1546),\n" + + " X1547(1547),\n" + + " X1548(1548),\n" + + " X1549(1549),\n" + + " X1550(1550),\n" + + " X1551(1551),\n" + + " X1552(1552),\n" + + " X1553(1553),\n" + + " X1554(1554),\n" + + " X1555(1555),\n" + + " X1556(1556),\n" + + " X1557(1557),\n" + + " X1558(1558),\n" + + " X1559(1559),\n" + + " X1560(1560),\n" + + " X1561(1561),\n" + + " X1562(1562),\n" + + " X1563(1563),\n" + + " X1564(1564),\n" + + " X1565(1565),\n" + + " X1566(1566),\n" + + " X1567(1567),\n" + + " X1568(1568),\n" + + " X1569(1569),\n" + + " X1570(1570),\n" + + " X1571(1571),\n" + + " X1572(1572),\n" + + " X1573(1573),\n" + + " X1574(1574),\n" + + " X1575(1575),\n" + + " X1576(1576),\n" + + " X1577(1577),\n" + + " X1578(1578),\n" + + " X1579(1579),\n" + + " X1580(1580),\n" + + " X1581(1581),\n" + + " X1582(1582),\n" + + " X1583(1583),\n" + + " X1584(1584),\n" + + " X1585(1585),\n" + + " X1586(1586),\n" + + " X1587(1587),\n" + + " X1588(1588),\n" + + " X1589(1589),\n" + + " X1590(1590),\n" + + " X1591(1591),\n" + + " X1592(1592),\n" + + " X1593(1593),\n" + + " X1594(1594),\n" + + " X1595(1595),\n" + + " X1596(1596),\n" + + " X1597(1597),\n" + + " X1598(1598),\n" + + " X1599(1599),\n" + + " X1600(1600),\n" + + " X1601(1601),\n" + + " X1602(1602),\n" + + " X1603(1603),\n" + + " X1604(1604),\n" + + " X1605(1605),\n" + + " X1606(1606),\n" + + " X1607(1607),\n" + + " X1608(1608),\n" + + " X1609(1609),\n" + + " X1610(1610),\n" + + " X1611(1611),\n" + + " X1612(1612),\n" + + " X1613(1613),\n" + + " X1614(1614),\n" + + " X1615(1615),\n" + + " X1616(1616),\n" + + " X1617(1617),\n" + + " X1618(1618),\n" + + " X1619(1619),\n" + + " X1620(1620),\n" + + " X1621(1621),\n" + + " X1622(1622),\n" + + " X1623(1623),\n" + + " X1624(1624),\n" + + " X1625(1625),\n" + + " X1626(1626),\n" + + " X1627(1627),\n" + + " X1628(1628),\n" + + " X1629(1629),\n" + + " X1630(1630),\n" + + " X1631(1631),\n" + + " X1632(1632),\n" + + " X1633(1633),\n" + + " X1634(1634),\n" + + " X1635(1635),\n" + + " X1636(1636),\n" + + " X1637(1637),\n" + + " X1638(1638),\n" + + " X1639(1639),\n" + + " X1640(1640),\n" + + " X1641(1641),\n" + + " X1642(1642),\n" + + " X1643(1643),\n" + + " X1644(1644),\n" + + " X1645(1645),\n" + + " X1646(1646),\n" + + " X1647(1647),\n" + + " X1648(1648),\n" + + " X1649(1649),\n" + + " X1650(1650),\n" + + " X1651(1651),\n" + + " X1652(1652),\n" + + " X1653(1653),\n" + + " X1654(1654),\n" + + " X1655(1655),\n" + + " X1656(1656),\n" + + " X1657(1657),\n" + + " X1658(1658),\n" + + " X1659(1659),\n" + + " X1660(1660),\n" + + " X1661(1661),\n" + + " X1662(1662),\n" + + " X1663(1663),\n" + + " X1664(1664),\n" + + " X1665(1665),\n" + + " X1666(1666),\n" + + " X1667(1667),\n" + + " X1668(1668),\n" + + " X1669(1669),\n" + + " X1670(1670),\n" + + " X1671(1671),\n" + + " X1672(1672),\n" + + " X1673(1673),\n" + + " X1674(1674),\n" + + " X1675(1675),\n" + + " X1676(1676),\n" + + " X1677(1677),\n" + + " X1678(1678),\n" + + " X1679(1679),\n" + + " X1680(1680),\n" + + " X1681(1681),\n" + + " X1682(1682),\n" + + " X1683(1683),\n" + + " X1684(1684),\n" + + " X1685(1685),\n" + + " X1686(1686),\n" + + " X1687(1687),\n" + + " X1688(1688),\n" + + " X1689(1689),\n" + + " X1690(1690),\n" + + " X1691(1691),\n" + + " X1692(1692),\n" + + " X1693(1693),\n" + + " X1694(1694),\n" + + " X1695(1695),\n" + + " X1696(1696),\n" + + " X1697(1697),\n" + + " X1698(1698),\n" + + " X1699(1699),\n" + + " X1700(1700),\n" + + " X1701(1701),\n" + + " X1702(1702),\n" + + " X1703(1703),\n" + + " X1704(1704),\n" + + " X1705(1705),\n" + + " X1706(1706),\n" + + " X1707(1707),\n" + + " X1708(1708),\n" + + " X1709(1709),\n" + + " X1710(1710),\n" + + " X1711(1711),\n" + + " X1712(1712),\n" + + " X1713(1713),\n" + + " X1714(1714),\n" + + " X1715(1715),\n" + + " X1716(1716),\n" + + " X1717(1717),\n" + + " X1718(1718),\n" + + " X1719(1719),\n" + + " X1720(1720),\n" + + " X1721(1721),\n" + + " X1722(1722),\n" + + " X1723(1723),\n" + + " X1724(1724),\n" + + " X1725(1725),\n" + + " X1726(1726),\n" + + " X1727(1727),\n" + + " X1728(1728),\n" + + " X1729(1729),\n" + + " X1730(1730),\n" + + " X1731(1731),\n" + + " X1732(1732),\n" + + " X1733(1733),\n" + + " X1734(1734),\n" + + " X1735(1735),\n" + + " X1736(1736),\n" + + " X1737(1737),\n" + + " X1738(1738),\n" + + " X1739(1739),\n" + + " X1740(1740),\n" + + " X1741(1741),\n" + + " X1742(1742),\n" + + " X1743(1743),\n" + + " X1744(1744),\n" + + " X1745(1745),\n" + + " X1746(1746),\n" + + " X1747(1747),\n" + + " X1748(1748),\n" + + " X1749(1749),\n" + + " X1750(1750),\n" + + " X1751(1751),\n" + + " X1752(1752),\n" + + " X1753(1753),\n" + + " X1754(1754),\n" + + " X1755(1755),\n" + + " X1756(1756),\n" + + " X1757(1757),\n" + + " X1758(1758),\n" + + " X1759(1759),\n" + + " X1760(1760),\n" + + " X1761(1761),\n" + + " X1762(1762),\n" + + " X1763(1763),\n" + + " X1764(1764),\n" + + " X1765(1765),\n" + + " X1766(1766),\n" + + " X1767(1767),\n" + + " X1768(1768),\n" + + " X1769(1769),\n" + + " X1770(1770),\n" + + " X1771(1771),\n" + + " X1772(1772),\n" + + " X1773(1773),\n" + + " X1774(1774),\n" + + " X1775(1775),\n" + + " X1776(1776),\n" + + " X1777(1777),\n" + + " X1778(1778),\n" + + " X1779(1779),\n" + + " X1780(1780),\n" + + " X1781(1781),\n" + + " X1782(1782),\n" + + " X1783(1783),\n" + + " X1784(1784),\n" + + " X1785(1785),\n" + + " X1786(1786),\n" + + " X1787(1787),\n" + + " X1788(1788),\n" + + " X1789(1789),\n" + + " X1790(1790),\n" + + " X1791(1791),\n" + + " X1792(1792),\n" + + " X1793(1793),\n" + + " X1794(1794),\n" + + " X1795(1795),\n" + + " X1796(1796),\n" + + " X1797(1797),\n" + + " X1798(1798),\n" + + " X1799(1799),\n" + + " X1800(1800),\n" + + " X1801(1801),\n" + + " X1802(1802),\n" + + " X1803(1803),\n" + + " X1804(1804),\n" + + " X1805(1805),\n" + + " X1806(1806),\n" + + " X1807(1807),\n" + + " X1808(1808),\n" + + " X1809(1809),\n" + + " X1810(1810),\n" + + " X1811(1811),\n" + + " X1812(1812),\n" + + " X1813(1813),\n" + + " X1814(1814),\n" + + " X1815(1815),\n" + + " X1816(1816),\n" + + " X1817(1817),\n" + + " X1818(1818),\n" + + " X1819(1819),\n" + + " X1820(1820),\n" + + " X1821(1821),\n" + + " X1822(1822),\n" + + " X1823(1823),\n" + + " X1824(1824),\n" + + " X1825(1825),\n" + + " X1826(1826),\n" + + " X1827(1827),\n" + + " X1828(1828),\n" + + " X1829(1829),\n" + + " X1830(1830),\n" + + " X1831(1831),\n" + + " X1832(1832),\n" + + " X1833(1833),\n" + + " X1834(1834),\n" + + " X1835(1835),\n" + + " X1836(1836),\n" + + " X1837(1837),\n" + + " X1838(1838),\n" + + " X1839(1839),\n" + + " X1840(1840),\n" + + " X1841(1841),\n" + + " X1842(1842),\n" + + " X1843(1843),\n" + + " X1844(1844),\n" + + " X1845(1845),\n" + + " X1846(1846),\n" + + " X1847(1847),\n" + + " X1848(1848),\n" + + " X1849(1849),\n" + + " X1850(1850),\n" + + " X1851(1851),\n" + + " X1852(1852),\n" + + " X1853(1853),\n" + + " X1854(1854),\n" + + " X1855(1855),\n" + + " X1856(1856),\n" + + " X1857(1857),\n" + + " X1858(1858),\n" + + " X1859(1859),\n" + + " X1860(1860),\n" + + " X1861(1861),\n" + + " X1862(1862),\n" + + " X1863(1863),\n" + + " X1864(1864),\n" + + " X1865(1865),\n" + + " X1866(1866),\n" + + " X1867(1867),\n" + + " X1868(1868),\n" + + " X1869(1869),\n" + + " X1870(1870),\n" + + " X1871(1871),\n" + + " X1872(1872),\n" + + " X1873(1873),\n" + + " X1874(1874),\n" + + " X1875(1875),\n" + + " X1876(1876),\n" + + " X1877(1877),\n" + + " X1878(1878),\n" + + " X1879(1879),\n" + + " X1880(1880),\n" + + " X1881(1881),\n" + + " X1882(1882),\n" + + " X1883(1883),\n" + + " X1884(1884),\n" + + " X1885(1885),\n" + + " X1886(1886),\n" + + " X1887(1887),\n" + + " X1888(1888),\n" + + " X1889(1889),\n" + + " X1890(1890),\n" + + " X1891(1891),\n" + + " X1892(1892),\n" + + " X1893(1893),\n" + + " X1894(1894),\n" + + " X1895(1895),\n" + + " X1896(1896),\n" + + " X1897(1897),\n" + + " X1898(1898),\n" + + " X1899(1899),\n" + + " X1900(1900),\n" + + " X1901(1901),\n" + + " X1902(1902),\n" + + " X1903(1903),\n" + + " X1904(1904),\n" + + " X1905(1905),\n" + + " X1906(1906),\n" + + " X1907(1907),\n" + + " X1908(1908),\n" + + " X1909(1909),\n" + + " X1910(1910),\n" + + " X1911(1911),\n" + + " X1912(1912),\n" + + " X1913(1913),\n" + + " X1914(1914),\n" + + " X1915(1915),\n" + + " X1916(1916),\n" + + " X1917(1917),\n" + + " X1918(1918),\n" + + " X1919(1919),\n" + + " X1920(1920),\n" + + " X1921(1921),\n" + + " X1922(1922),\n" + + " X1923(1923),\n" + + " X1924(1924),\n" + + " X1925(1925),\n" + + " X1926(1926),\n" + + " X1927(1927),\n" + + " X1928(1928),\n" + + " X1929(1929),\n" + + " X1930(1930),\n" + + " X1931(1931),\n" + + " X1932(1932),\n" + + " X1933(1933),\n" + + " X1934(1934),\n" + + " X1935(1935),\n" + + " X1936(1936),\n" + + " X1937(1937),\n" + + " X1938(1938),\n" + + " X1939(1939),\n" + + " X1940(1940),\n" + + " X1941(1941),\n" + + " X1942(1942),\n" + + " X1943(1943),\n" + + " X1944(1944),\n" + + " X1945(1945),\n" + + " X1946(1946),\n" + + " X1947(1947),\n" + + " X1948(1948),\n" + + " X1949(1949),\n" + + " X1950(1950),\n" + + " X1951(1951),\n" + + " X1952(1952),\n" + + " X1953(1953),\n" + + " X1954(1954),\n" + + " X1955(1955),\n" + + " X1956(1956),\n" + + " X1957(1957),\n" + + " X1958(1958),\n" + + " X1959(1959),\n" + + " X1960(1960),\n" + + " X1961(1961),\n" + + " X1962(1962),\n" + + " X1963(1963),\n" + + " X1964(1964),\n" + + " X1965(1965),\n" + + " X1966(1966),\n" + + " X1967(1967),\n" + + " X1968(1968),\n" + + " X1969(1969),\n" + + " X1970(1970),\n" + + " X1971(1971),\n" + + " X1972(1972),\n" + + " X1973(1973),\n" + + " X1974(1974),\n" + + " X1975(1975),\n" + + " X1976(1976),\n" + + " X1977(1977),\n" + + " X1978(1978),\n" + + " X1979(1979),\n" + + " X1980(1980),\n" + + " X1981(1981),\n" + + " X1982(1982),\n" + + " X1983(1983),\n" + + " X1984(1984),\n" + + " X1985(1985),\n" + + " X1986(1986),\n" + + " X1987(1987),\n" + + " X1988(1988),\n" + + " X1989(1989),\n" + + " X1990(1990),\n" + + " X1991(1991),\n" + + " X1992(1992),\n" + + " X1993(1993),\n" + + " X1994(1994),\n" + + " X1995(1995),\n" + + " X1996(1996),\n" + + " X1997(1997),\n" + + " X1998(1998),\n" + + " X1999(1999),\n" + + " X2000(2000),\n" + + " X2001(2001),\n" + + " ;\n" + + "\n" + + " private int value;\n" + + " X(int i) {\n" + + " this.value = i;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int i = 0;\n" + + " for (X x : X.values()) {\n" + + " i++;\n" + + " System.out.print(x);\n" + + " }\n" + + " System.out.print(i);\n" + + " }\n" + + " \n" + + " public String toString() {\n" + + " return Integer.toString(this.value);\n" + + " }\n" + + "}" + }, + buffer.toString()); +} +public void test0018() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + // only run in 1.5 or above + StringBuilder buffer = new StringBuilder(); + buffer + .append("123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119") + .append("1201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022") + .append("0320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528") + .append("6287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369") + .append("3703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524") + .append("5345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553") + .append("6537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619") + .append("6206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027") + .append("0370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578") + .append("6787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869") + .append("8708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529") + .append("5395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610") + .append("2710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089") + .append("1090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111") + .append("5211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214") + .append("1215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612") + .append("7712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339") + .append("1340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114") + .append("0214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464") + .append("1465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615") + .append("2715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589") + .append("1590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116") + .append("5216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714") + .append("1715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617") + .append("7717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839") + .append("1840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119") + .append("0219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964") + .append("196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022002"); + this.runConformTest( + new String[] { + "X.java", + "public enum X {\n" + + " X1(1),\n" + + " X2(2),\n" + + " X3(3),\n" + + " X4(4),\n" + + " X5(5),\n" + + " X6(6),\n" + + " X7(7),\n" + + " X8(8),\n" + + " X9(9),\n" + + " X10(10),\n" + + " X11(11),\n" + + " X12(12),\n" + + " X13(13),\n" + + " X14(14),\n" + + " X15(15),\n" + + " X16(16),\n" + + " X17(17),\n" + + " X18(18),\n" + + " X19(19),\n" + + " X20(20),\n" + + " X21(21),\n" + + " X22(22),\n" + + " X23(23),\n" + + " X24(24),\n" + + " X25(25),\n" + + " X26(26),\n" + + " X27(27),\n" + + " X28(28),\n" + + " X29(29),\n" + + " X30(30),\n" + + " X31(31),\n" + + " X32(32),\n" + + " X33(33),\n" + + " X34(34),\n" + + " X35(35),\n" + + " X36(36),\n" + + " X37(37),\n" + + " X38(38),\n" + + " X39(39),\n" + + " X40(40),\n" + + " X41(41),\n" + + " X42(42),\n" + + " X43(43),\n" + + " X44(44),\n" + + " X45(45),\n" + + " X46(46),\n" + + " X47(47),\n" + + " X48(48),\n" + + " X49(49),\n" + + " X50(50),\n" + + " X51(51),\n" + + " X52(52),\n" + + " X53(53),\n" + + " X54(54),\n" + + " X55(55),\n" + + " X56(56),\n" + + " X57(57),\n" + + " X58(58),\n" + + " X59(59),\n" + + " X60(60),\n" + + " X61(61),\n" + + " X62(62),\n" + + " X63(63),\n" + + " X64(64),\n" + + " X65(65),\n" + + " X66(66),\n" + + " X67(67),\n" + + " X68(68),\n" + + " X69(69),\n" + + " X70(70),\n" + + " X71(71),\n" + + " X72(72),\n" + + " X73(73),\n" + + " X74(74),\n" + + " X75(75),\n" + + " X76(76),\n" + + " X77(77),\n" + + " X78(78),\n" + + " X79(79),\n" + + " X80(80),\n" + + " X81(81),\n" + + " X82(82),\n" + + " X83(83),\n" + + " X84(84),\n" + + " X85(85),\n" + + " X86(86),\n" + + " X87(87),\n" + + " X88(88),\n" + + " X89(89),\n" + + " X90(90),\n" + + " X91(91),\n" + + " X92(92),\n" + + " X93(93),\n" + + " X94(94),\n" + + " X95(95),\n" + + " X96(96),\n" + + " X97(97),\n" + + " X98(98),\n" + + " X99(99),\n" + + " X100(100),\n" + + " X101(101),\n" + + " X102(102),\n" + + " X103(103),\n" + + " X104(104),\n" + + " X105(105),\n" + + " X106(106),\n" + + " X107(107),\n" + + " X108(108),\n" + + " X109(109),\n" + + " X110(110),\n" + + " X111(111),\n" + + " X112(112),\n" + + " X113(113),\n" + + " X114(114),\n" + + " X115(115),\n" + + " X116(116),\n" + + " X117(117),\n" + + " X118(118),\n" + + " X119(119),\n" + + " X120(120),\n" + + " X121(121),\n" + + " X122(122),\n" + + " X123(123),\n" + + " X124(124),\n" + + " X125(125),\n" + + " X126(126),\n" + + " X127(127),\n" + + " X128(128),\n" + + " X129(129),\n" + + " X130(130),\n" + + " X131(131),\n" + + " X132(132),\n" + + " X133(133),\n" + + " X134(134),\n" + + " X135(135),\n" + + " X136(136),\n" + + " X137(137),\n" + + " X138(138),\n" + + " X139(139),\n" + + " X140(140),\n" + + " X141(141),\n" + + " X142(142),\n" + + " X143(143),\n" + + " X144(144),\n" + + " X145(145),\n" + + " X146(146),\n" + + " X147(147),\n" + + " X148(148),\n" + + " X149(149),\n" + + " X150(150),\n" + + " X151(151),\n" + + " X152(152),\n" + + " X153(153),\n" + + " X154(154),\n" + + " X155(155),\n" + + " X156(156),\n" + + " X157(157),\n" + + " X158(158),\n" + + " X159(159),\n" + + " X160(160),\n" + + " X161(161),\n" + + " X162(162),\n" + + " X163(163),\n" + + " X164(164),\n" + + " X165(165),\n" + + " X166(166),\n" + + " X167(167),\n" + + " X168(168),\n" + + " X169(169),\n" + + " X170(170),\n" + + " X171(171),\n" + + " X172(172),\n" + + " X173(173),\n" + + " X174(174),\n" + + " X175(175),\n" + + " X176(176),\n" + + " X177(177),\n" + + " X178(178),\n" + + " X179(179),\n" + + " X180(180),\n" + + " X181(181),\n" + + " X182(182),\n" + + " X183(183),\n" + + " X184(184),\n" + + " X185(185),\n" + + " X186(186),\n" + + " X187(187),\n" + + " X188(188),\n" + + " X189(189),\n" + + " X190(190),\n" + + " X191(191),\n" + + " X192(192),\n" + + " X193(193),\n" + + " X194(194),\n" + + " X195(195),\n" + + " X196(196),\n" + + " X197(197),\n" + + " X198(198),\n" + + " X199(199),\n" + + " X200(200),\n" + + " X201(201),\n" + + " X202(202),\n" + + " X203(203),\n" + + " X204(204),\n" + + " X205(205),\n" + + " X206(206),\n" + + " X207(207),\n" + + " X208(208),\n" + + " X209(209),\n" + + " X210(210),\n" + + " X211(211),\n" + + " X212(212),\n" + + " X213(213),\n" + + " X214(214),\n" + + " X215(215),\n" + + " X216(216),\n" + + " X217(217),\n" + + " X218(218),\n" + + " X219(219),\n" + + " X220(220),\n" + + " X221(221),\n" + + " X222(222),\n" + + " X223(223),\n" + + " X224(224),\n" + + " X225(225),\n" + + " X226(226),\n" + + " X227(227),\n" + + " X228(228),\n" + + " X229(229),\n" + + " X230(230),\n" + + " X231(231),\n" + + " X232(232),\n" + + " X233(233),\n" + + " X234(234),\n" + + " X235(235),\n" + + " X236(236),\n" + + " X237(237),\n" + + " X238(238),\n" + + " X239(239),\n" + + " X240(240),\n" + + " X241(241),\n" + + " X242(242),\n" + + " X243(243),\n" + + " X244(244),\n" + + " X245(245),\n" + + " X246(246),\n" + + " X247(247),\n" + + " X248(248),\n" + + " X249(249),\n" + + " X250(250),\n" + + " X251(251),\n" + + " X252(252),\n" + + " X253(253),\n" + + " X254(254),\n" + + " X255(255),\n" + + " X256(256),\n" + + " X257(257),\n" + + " X258(258),\n" + + " X259(259),\n" + + " X260(260),\n" + + " X261(261),\n" + + " X262(262),\n" + + " X263(263),\n" + + " X264(264),\n" + + " X265(265),\n" + + " X266(266),\n" + + " X267(267),\n" + + " X268(268),\n" + + " X269(269),\n" + + " X270(270),\n" + + " X271(271),\n" + + " X272(272),\n" + + " X273(273),\n" + + " X274(274),\n" + + " X275(275),\n" + + " X276(276),\n" + + " X277(277),\n" + + " X278(278),\n" + + " X279(279),\n" + + " X280(280),\n" + + " X281(281),\n" + + " X282(282),\n" + + " X283(283),\n" + + " X284(284),\n" + + " X285(285),\n" + + " X286(286),\n" + + " X287(287),\n" + + " X288(288),\n" + + " X289(289),\n" + + " X290(290),\n" + + " X291(291),\n" + + " X292(292),\n" + + " X293(293),\n" + + " X294(294),\n" + + " X295(295),\n" + + " X296(296),\n" + + " X297(297),\n" + + " X298(298),\n" + + " X299(299),\n" + + " X300(300),\n" + + " X301(301),\n" + + " X302(302),\n" + + " X303(303),\n" + + " X304(304),\n" + + " X305(305),\n" + + " X306(306),\n" + + " X307(307),\n" + + " X308(308),\n" + + " X309(309),\n" + + " X310(310),\n" + + " X311(311),\n" + + " X312(312),\n" + + " X313(313),\n" + + " X314(314),\n" + + " X315(315),\n" + + " X316(316),\n" + + " X317(317),\n" + + " X318(318),\n" + + " X319(319),\n" + + " X320(320),\n" + + " X321(321),\n" + + " X322(322),\n" + + " X323(323),\n" + + " X324(324),\n" + + " X325(325),\n" + + " X326(326),\n" + + " X327(327),\n" + + " X328(328),\n" + + " X329(329),\n" + + " X330(330),\n" + + " X331(331),\n" + + " X332(332),\n" + + " X333(333),\n" + + " X334(334),\n" + + " X335(335),\n" + + " X336(336),\n" + + " X337(337),\n" + + " X338(338),\n" + + " X339(339),\n" + + " X340(340),\n" + + " X341(341),\n" + + " X342(342),\n" + + " X343(343),\n" + + " X344(344),\n" + + " X345(345),\n" + + " X346(346),\n" + + " X347(347),\n" + + " X348(348),\n" + + " X349(349),\n" + + " X350(350),\n" + + " X351(351),\n" + + " X352(352),\n" + + " X353(353),\n" + + " X354(354),\n" + + " X355(355),\n" + + " X356(356),\n" + + " X357(357),\n" + + " X358(358),\n" + + " X359(359),\n" + + " X360(360),\n" + + " X361(361),\n" + + " X362(362),\n" + + " X363(363),\n" + + " X364(364),\n" + + " X365(365),\n" + + " X366(366),\n" + + " X367(367),\n" + + " X368(368),\n" + + " X369(369),\n" + + " X370(370),\n" + + " X371(371),\n" + + " X372(372),\n" + + " X373(373),\n" + + " X374(374),\n" + + " X375(375),\n" + + " X376(376),\n" + + " X377(377),\n" + + " X378(378),\n" + + " X379(379),\n" + + " X380(380),\n" + + " X381(381),\n" + + " X382(382),\n" + + " X383(383),\n" + + " X384(384),\n" + + " X385(385),\n" + + " X386(386),\n" + + " X387(387),\n" + + " X388(388),\n" + + " X389(389),\n" + + " X390(390),\n" + + " X391(391),\n" + + " X392(392),\n" + + " X393(393),\n" + + " X394(394),\n" + + " X395(395),\n" + + " X396(396),\n" + + " X397(397),\n" + + " X398(398),\n" + + " X399(399),\n" + + " X400(400),\n" + + " X401(401),\n" + + " X402(402),\n" + + " X403(403),\n" + + " X404(404),\n" + + " X405(405),\n" + + " X406(406),\n" + + " X407(407),\n" + + " X408(408),\n" + + " X409(409),\n" + + " X410(410),\n" + + " X411(411),\n" + + " X412(412),\n" + + " X413(413),\n" + + " X414(414),\n" + + " X415(415),\n" + + " X416(416),\n" + + " X417(417),\n" + + " X418(418),\n" + + " X419(419),\n" + + " X420(420),\n" + + " X421(421),\n" + + " X422(422),\n" + + " X423(423),\n" + + " X424(424),\n" + + " X425(425),\n" + + " X426(426),\n" + + " X427(427),\n" + + " X428(428),\n" + + " X429(429),\n" + + " X430(430),\n" + + " X431(431),\n" + + " X432(432),\n" + + " X433(433),\n" + + " X434(434),\n" + + " X435(435),\n" + + " X436(436),\n" + + " X437(437),\n" + + " X438(438),\n" + + " X439(439),\n" + + " X440(440),\n" + + " X441(441),\n" + + " X442(442),\n" + + " X443(443),\n" + + " X444(444),\n" + + " X445(445),\n" + + " X446(446),\n" + + " X447(447),\n" + + " X448(448),\n" + + " X449(449),\n" + + " X450(450),\n" + + " X451(451),\n" + + " X452(452),\n" + + " X453(453),\n" + + " X454(454),\n" + + " X455(455),\n" + + " X456(456),\n" + + " X457(457),\n" + + " X458(458),\n" + + " X459(459),\n" + + " X460(460),\n" + + " X461(461),\n" + + " X462(462),\n" + + " X463(463),\n" + + " X464(464),\n" + + " X465(465),\n" + + " X466(466),\n" + + " X467(467),\n" + + " X468(468),\n" + + " X469(469),\n" + + " X470(470),\n" + + " X471(471),\n" + + " X472(472),\n" + + " X473(473),\n" + + " X474(474),\n" + + " X475(475),\n" + + " X476(476),\n" + + " X477(477),\n" + + " X478(478),\n" + + " X479(479),\n" + + " X480(480),\n" + + " X481(481),\n" + + " X482(482),\n" + + " X483(483),\n" + + " X484(484),\n" + + " X485(485),\n" + + " X486(486),\n" + + " X487(487),\n" + + " X488(488),\n" + + " X489(489),\n" + + " X490(490),\n" + + " X491(491),\n" + + " X492(492),\n" + + " X493(493),\n" + + " X494(494),\n" + + " X495(495),\n" + + " X496(496),\n" + + " X497(497),\n" + + " X498(498),\n" + + " X499(499),\n" + + " X500(500),\n" + + " X501(501),\n" + + " X502(502),\n" + + " X503(503),\n" + + " X504(504),\n" + + " X505(505),\n" + + " X506(506),\n" + + " X507(507),\n" + + " X508(508),\n" + + " X509(509),\n" + + " X510(510),\n" + + " X511(511),\n" + + " X512(512),\n" + + " X513(513),\n" + + " X514(514),\n" + + " X515(515),\n" + + " X516(516),\n" + + " X517(517),\n" + + " X518(518),\n" + + " X519(519),\n" + + " X520(520),\n" + + " X521(521),\n" + + " X522(522),\n" + + " X523(523),\n" + + " X524(524),\n" + + " X525(525),\n" + + " X526(526),\n" + + " X527(527),\n" + + " X528(528),\n" + + " X529(529),\n" + + " X530(530),\n" + + " X531(531),\n" + + " X532(532),\n" + + " X533(533),\n" + + " X534(534),\n" + + " X535(535),\n" + + " X536(536),\n" + + " X537(537),\n" + + " X538(538),\n" + + " X539(539),\n" + + " X540(540),\n" + + " X541(541),\n" + + " X542(542),\n" + + " X543(543),\n" + + " X544(544),\n" + + " X545(545),\n" + + " X546(546),\n" + + " X547(547),\n" + + " X548(548),\n" + + " X549(549),\n" + + " X550(550),\n" + + " X551(551),\n" + + " X552(552),\n" + + " X553(553),\n" + + " X554(554),\n" + + " X555(555),\n" + + " X556(556),\n" + + " X557(557),\n" + + " X558(558),\n" + + " X559(559),\n" + + " X560(560),\n" + + " X561(561),\n" + + " X562(562),\n" + + " X563(563),\n" + + " X564(564),\n" + + " X565(565),\n" + + " X566(566),\n" + + " X567(567),\n" + + " X568(568),\n" + + " X569(569),\n" + + " X570(570),\n" + + " X571(571),\n" + + " X572(572),\n" + + " X573(573),\n" + + " X574(574),\n" + + " X575(575),\n" + + " X576(576),\n" + + " X577(577),\n" + + " X578(578),\n" + + " X579(579),\n" + + " X580(580),\n" + + " X581(581),\n" + + " X582(582),\n" + + " X583(583),\n" + + " X584(584),\n" + + " X585(585),\n" + + " X586(586),\n" + + " X587(587),\n" + + " X588(588),\n" + + " X589(589),\n" + + " X590(590),\n" + + " X591(591),\n" + + " X592(592),\n" + + " X593(593),\n" + + " X594(594),\n" + + " X595(595),\n" + + " X596(596),\n" + + " X597(597),\n" + + " X598(598),\n" + + " X599(599),\n" + + " X600(600),\n" + + " X601(601),\n" + + " X602(602),\n" + + " X603(603),\n" + + " X604(604),\n" + + " X605(605),\n" + + " X606(606),\n" + + " X607(607),\n" + + " X608(608),\n" + + " X609(609),\n" + + " X610(610),\n" + + " X611(611),\n" + + " X612(612),\n" + + " X613(613),\n" + + " X614(614),\n" + + " X615(615),\n" + + " X616(616),\n" + + " X617(617),\n" + + " X618(618),\n" + + " X619(619),\n" + + " X620(620),\n" + + " X621(621),\n" + + " X622(622),\n" + + " X623(623),\n" + + " X624(624),\n" + + " X625(625),\n" + + " X626(626),\n" + + " X627(627),\n" + + " X628(628),\n" + + " X629(629),\n" + + " X630(630),\n" + + " X631(631),\n" + + " X632(632),\n" + + " X633(633),\n" + + " X634(634),\n" + + " X635(635),\n" + + " X636(636),\n" + + " X637(637),\n" + + " X638(638),\n" + + " X639(639),\n" + + " X640(640),\n" + + " X641(641),\n" + + " X642(642),\n" + + " X643(643),\n" + + " X644(644),\n" + + " X645(645),\n" + + " X646(646),\n" + + " X647(647),\n" + + " X648(648),\n" + + " X649(649),\n" + + " X650(650),\n" + + " X651(651),\n" + + " X652(652),\n" + + " X653(653),\n" + + " X654(654),\n" + + " X655(655),\n" + + " X656(656),\n" + + " X657(657),\n" + + " X658(658),\n" + + " X659(659),\n" + + " X660(660),\n" + + " X661(661),\n" + + " X662(662),\n" + + " X663(663),\n" + + " X664(664),\n" + + " X665(665),\n" + + " X666(666),\n" + + " X667(667),\n" + + " X668(668),\n" + + " X669(669),\n" + + " X670(670),\n" + + " X671(671),\n" + + " X672(672),\n" + + " X673(673),\n" + + " X674(674),\n" + + " X675(675),\n" + + " X676(676),\n" + + " X677(677),\n" + + " X678(678),\n" + + " X679(679),\n" + + " X680(680),\n" + + " X681(681),\n" + + " X682(682),\n" + + " X683(683),\n" + + " X684(684),\n" + + " X685(685),\n" + + " X686(686),\n" + + " X687(687),\n" + + " X688(688),\n" + + " X689(689),\n" + + " X690(690),\n" + + " X691(691),\n" + + " X692(692),\n" + + " X693(693),\n" + + " X694(694),\n" + + " X695(695),\n" + + " X696(696),\n" + + " X697(697),\n" + + " X698(698),\n" + + " X699(699),\n" + + " X700(700),\n" + + " X701(701),\n" + + " X702(702),\n" + + " X703(703),\n" + + " X704(704),\n" + + " X705(705),\n" + + " X706(706),\n" + + " X707(707),\n" + + " X708(708),\n" + + " X709(709),\n" + + " X710(710),\n" + + " X711(711),\n" + + " X712(712),\n" + + " X713(713),\n" + + " X714(714),\n" + + " X715(715),\n" + + " X716(716),\n" + + " X717(717),\n" + + " X718(718),\n" + + " X719(719),\n" + + " X720(720),\n" + + " X721(721),\n" + + " X722(722),\n" + + " X723(723),\n" + + " X724(724),\n" + + " X725(725),\n" + + " X726(726),\n" + + " X727(727),\n" + + " X728(728),\n" + + " X729(729),\n" + + " X730(730),\n" + + " X731(731),\n" + + " X732(732),\n" + + " X733(733),\n" + + " X734(734),\n" + + " X735(735),\n" + + " X736(736),\n" + + " X737(737),\n" + + " X738(738),\n" + + " X739(739),\n" + + " X740(740),\n" + + " X741(741),\n" + + " X742(742),\n" + + " X743(743),\n" + + " X744(744),\n" + + " X745(745),\n" + + " X746(746),\n" + + " X747(747),\n" + + " X748(748),\n" + + " X749(749),\n" + + " X750(750),\n" + + " X751(751),\n" + + " X752(752),\n" + + " X753(753),\n" + + " X754(754),\n" + + " X755(755),\n" + + " X756(756),\n" + + " X757(757),\n" + + " X758(758),\n" + + " X759(759),\n" + + " X760(760),\n" + + " X761(761),\n" + + " X762(762),\n" + + " X763(763),\n" + + " X764(764),\n" + + " X765(765),\n" + + " X766(766),\n" + + " X767(767),\n" + + " X768(768),\n" + + " X769(769),\n" + + " X770(770),\n" + + " X771(771),\n" + + " X772(772),\n" + + " X773(773),\n" + + " X774(774),\n" + + " X775(775),\n" + + " X776(776),\n" + + " X777(777),\n" + + " X778(778),\n" + + " X779(779),\n" + + " X780(780),\n" + + " X781(781),\n" + + " X782(782),\n" + + " X783(783),\n" + + " X784(784),\n" + + " X785(785),\n" + + " X786(786),\n" + + " X787(787),\n" + + " X788(788),\n" + + " X789(789),\n" + + " X790(790),\n" + + " X791(791),\n" + + " X792(792),\n" + + " X793(793),\n" + + " X794(794),\n" + + " X795(795),\n" + + " X796(796),\n" + + " X797(797),\n" + + " X798(798),\n" + + " X799(799),\n" + + " X800(800),\n" + + " X801(801),\n" + + " X802(802),\n" + + " X803(803),\n" + + " X804(804),\n" + + " X805(805),\n" + + " X806(806),\n" + + " X807(807),\n" + + " X808(808),\n" + + " X809(809),\n" + + " X810(810),\n" + + " X811(811),\n" + + " X812(812),\n" + + " X813(813),\n" + + " X814(814),\n" + + " X815(815),\n" + + " X816(816),\n" + + " X817(817),\n" + + " X818(818),\n" + + " X819(819),\n" + + " X820(820),\n" + + " X821(821),\n" + + " X822(822),\n" + + " X823(823),\n" + + " X824(824),\n" + + " X825(825),\n" + + " X826(826),\n" + + " X827(827),\n" + + " X828(828),\n" + + " X829(829),\n" + + " X830(830),\n" + + " X831(831),\n" + + " X832(832),\n" + + " X833(833),\n" + + " X834(834),\n" + + " X835(835),\n" + + " X836(836),\n" + + " X837(837),\n" + + " X838(838),\n" + + " X839(839),\n" + + " X840(840),\n" + + " X841(841),\n" + + " X842(842),\n" + + " X843(843),\n" + + " X844(844),\n" + + " X845(845),\n" + + " X846(846),\n" + + " X847(847),\n" + + " X848(848),\n" + + " X849(849),\n" + + " X850(850),\n" + + " X851(851),\n" + + " X852(852),\n" + + " X853(853),\n" + + " X854(854),\n" + + " X855(855),\n" + + " X856(856),\n" + + " X857(857),\n" + + " X858(858),\n" + + " X859(859),\n" + + " X860(860),\n" + + " X861(861),\n" + + " X862(862),\n" + + " X863(863),\n" + + " X864(864),\n" + + " X865(865),\n" + + " X866(866),\n" + + " X867(867),\n" + + " X868(868),\n" + + " X869(869),\n" + + " X870(870),\n" + + " X871(871),\n" + + " X872(872),\n" + + " X873(873),\n" + + " X874(874),\n" + + " X875(875),\n" + + " X876(876),\n" + + " X877(877),\n" + + " X878(878),\n" + + " X879(879),\n" + + " X880(880),\n" + + " X881(881),\n" + + " X882(882),\n" + + " X883(883),\n" + + " X884(884),\n" + + " X885(885),\n" + + " X886(886),\n" + + " X887(887),\n" + + " X888(888),\n" + + " X889(889),\n" + + " X890(890),\n" + + " X891(891),\n" + + " X892(892),\n" + + " X893(893),\n" + + " X894(894),\n" + + " X895(895),\n" + + " X896(896),\n" + + " X897(897),\n" + + " X898(898),\n" + + " X899(899),\n" + + " X900(900),\n" + + " X901(901),\n" + + " X902(902),\n" + + " X903(903),\n" + + " X904(904),\n" + + " X905(905),\n" + + " X906(906),\n" + + " X907(907),\n" + + " X908(908),\n" + + " X909(909),\n" + + " X910(910),\n" + + " X911(911),\n" + + " X912(912),\n" + + " X913(913),\n" + + " X914(914),\n" + + " X915(915),\n" + + " X916(916),\n" + + " X917(917),\n" + + " X918(918),\n" + + " X919(919),\n" + + " X920(920),\n" + + " X921(921),\n" + + " X922(922),\n" + + " X923(923),\n" + + " X924(924),\n" + + " X925(925),\n" + + " X926(926),\n" + + " X927(927),\n" + + " X928(928),\n" + + " X929(929),\n" + + " X930(930),\n" + + " X931(931),\n" + + " X932(932),\n" + + " X933(933),\n" + + " X934(934),\n" + + " X935(935),\n" + + " X936(936),\n" + + " X937(937),\n" + + " X938(938),\n" + + " X939(939),\n" + + " X940(940),\n" + + " X941(941),\n" + + " X942(942),\n" + + " X943(943),\n" + + " X944(944),\n" + + " X945(945),\n" + + " X946(946),\n" + + " X947(947),\n" + + " X948(948),\n" + + " X949(949),\n" + + " X950(950),\n" + + " X951(951),\n" + + " X952(952),\n" + + " X953(953),\n" + + " X954(954),\n" + + " X955(955),\n" + + " X956(956),\n" + + " X957(957),\n" + + " X958(958),\n" + + " X959(959),\n" + + " X960(960),\n" + + " X961(961),\n" + + " X962(962),\n" + + " X963(963),\n" + + " X964(964),\n" + + " X965(965),\n" + + " X966(966),\n" + + " X967(967),\n" + + " X968(968),\n" + + " X969(969),\n" + + " X970(970),\n" + + " X971(971),\n" + + " X972(972),\n" + + " X973(973),\n" + + " X974(974),\n" + + " X975(975),\n" + + " X976(976),\n" + + " X977(977),\n" + + " X978(978),\n" + + " X979(979),\n" + + " X980(980),\n" + + " X981(981),\n" + + " X982(982),\n" + + " X983(983),\n" + + " X984(984),\n" + + " X985(985),\n" + + " X986(986),\n" + + " X987(987),\n" + + " X988(988),\n" + + " X989(989),\n" + + " X990(990),\n" + + " X991(991),\n" + + " X992(992),\n" + + " X993(993),\n" + + " X994(994),\n" + + " X995(995),\n" + + " X996(996),\n" + + " X997(997),\n" + + " X998(998),\n" + + " X999(999),\n" + + " X1000(1000),\n" + + " X1001(1001),\n" + + " X1002(1002),\n" + + " X1003(1003),\n" + + " X1004(1004),\n" + + " X1005(1005),\n" + + " X1006(1006),\n" + + " X1007(1007),\n" + + " X1008(1008),\n" + + " X1009(1009),\n" + + " X1010(1010),\n" + + " X1011(1011),\n" + + " X1012(1012),\n" + + " X1013(1013),\n" + + " X1014(1014),\n" + + " X1015(1015),\n" + + " X1016(1016),\n" + + " X1017(1017),\n" + + " X1018(1018),\n" + + " X1019(1019),\n" + + " X1020(1020),\n" + + " X1021(1021),\n" + + " X1022(1022),\n" + + " X1023(1023),\n" + + " X1024(1024),\n" + + " X1025(1025),\n" + + " X1026(1026),\n" + + " X1027(1027),\n" + + " X1028(1028),\n" + + " X1029(1029),\n" + + " X1030(1030),\n" + + " X1031(1031),\n" + + " X1032(1032),\n" + + " X1033(1033),\n" + + " X1034(1034),\n" + + " X1035(1035),\n" + + " X1036(1036),\n" + + " X1037(1037),\n" + + " X1038(1038),\n" + + " X1039(1039),\n" + + " X1040(1040),\n" + + " X1041(1041),\n" + + " X1042(1042),\n" + + " X1043(1043),\n" + + " X1044(1044),\n" + + " X1045(1045),\n" + + " X1046(1046),\n" + + " X1047(1047),\n" + + " X1048(1048),\n" + + " X1049(1049),\n" + + " X1050(1050),\n" + + " X1051(1051),\n" + + " X1052(1052),\n" + + " X1053(1053),\n" + + " X1054(1054),\n" + + " X1055(1055),\n" + + " X1056(1056),\n" + + " X1057(1057),\n" + + " X1058(1058),\n" + + " X1059(1059),\n" + + " X1060(1060),\n" + + " X1061(1061),\n" + + " X1062(1062),\n" + + " X1063(1063),\n" + + " X1064(1064),\n" + + " X1065(1065),\n" + + " X1066(1066),\n" + + " X1067(1067),\n" + + " X1068(1068),\n" + + " X1069(1069),\n" + + " X1070(1070),\n" + + " X1071(1071),\n" + + " X1072(1072),\n" + + " X1073(1073),\n" + + " X1074(1074),\n" + + " X1075(1075),\n" + + " X1076(1076),\n" + + " X1077(1077),\n" + + " X1078(1078),\n" + + " X1079(1079),\n" + + " X1080(1080),\n" + + " X1081(1081),\n" + + " X1082(1082),\n" + + " X1083(1083),\n" + + " X1084(1084),\n" + + " X1085(1085),\n" + + " X1086(1086),\n" + + " X1087(1087),\n" + + " X1088(1088),\n" + + " X1089(1089),\n" + + " X1090(1090),\n" + + " X1091(1091),\n" + + " X1092(1092),\n" + + " X1093(1093),\n" + + " X1094(1094),\n" + + " X1095(1095),\n" + + " X1096(1096),\n" + + " X1097(1097),\n" + + " X1098(1098),\n" + + " X1099(1099),\n" + + " X1100(1100),\n" + + " X1101(1101),\n" + + " X1102(1102),\n" + + " X1103(1103),\n" + + " X1104(1104),\n" + + " X1105(1105),\n" + + " X1106(1106),\n" + + " X1107(1107),\n" + + " X1108(1108),\n" + + " X1109(1109),\n" + + " X1110(1110),\n" + + " X1111(1111),\n" + + " X1112(1112),\n" + + " X1113(1113),\n" + + " X1114(1114),\n" + + " X1115(1115),\n" + + " X1116(1116),\n" + + " X1117(1117),\n" + + " X1118(1118),\n" + + " X1119(1119),\n" + + " X1120(1120),\n" + + " X1121(1121),\n" + + " X1122(1122),\n" + + " X1123(1123),\n" + + " X1124(1124),\n" + + " X1125(1125),\n" + + " X1126(1126),\n" + + " X1127(1127),\n" + + " X1128(1128),\n" + + " X1129(1129),\n" + + " X1130(1130),\n" + + " X1131(1131),\n" + + " X1132(1132),\n" + + " X1133(1133),\n" + + " X1134(1134),\n" + + " X1135(1135),\n" + + " X1136(1136),\n" + + " X1137(1137),\n" + + " X1138(1138),\n" + + " X1139(1139),\n" + + " X1140(1140),\n" + + " X1141(1141),\n" + + " X1142(1142),\n" + + " X1143(1143),\n" + + " X1144(1144),\n" + + " X1145(1145),\n" + + " X1146(1146),\n" + + " X1147(1147),\n" + + " X1148(1148),\n" + + " X1149(1149),\n" + + " X1150(1150),\n" + + " X1151(1151),\n" + + " X1152(1152),\n" + + " X1153(1153),\n" + + " X1154(1154),\n" + + " X1155(1155),\n" + + " X1156(1156),\n" + + " X1157(1157),\n" + + " X1158(1158),\n" + + " X1159(1159),\n" + + " X1160(1160),\n" + + " X1161(1161),\n" + + " X1162(1162),\n" + + " X1163(1163),\n" + + " X1164(1164),\n" + + " X1165(1165),\n" + + " X1166(1166),\n" + + " X1167(1167),\n" + + " X1168(1168),\n" + + " X1169(1169),\n" + + " X1170(1170),\n" + + " X1171(1171),\n" + + " X1172(1172),\n" + + " X1173(1173),\n" + + " X1174(1174),\n" + + " X1175(1175),\n" + + " X1176(1176),\n" + + " X1177(1177),\n" + + " X1178(1178),\n" + + " X1179(1179),\n" + + " X1180(1180),\n" + + " X1181(1181),\n" + + " X1182(1182),\n" + + " X1183(1183),\n" + + " X1184(1184),\n" + + " X1185(1185),\n" + + " X1186(1186),\n" + + " X1187(1187),\n" + + " X1188(1188),\n" + + " X1189(1189),\n" + + " X1190(1190),\n" + + " X1191(1191),\n" + + " X1192(1192),\n" + + " X1193(1193),\n" + + " X1194(1194),\n" + + " X1195(1195),\n" + + " X1196(1196),\n" + + " X1197(1197),\n" + + " X1198(1198),\n" + + " X1199(1199),\n" + + " X1200(1200),\n" + + " X1201(1201),\n" + + " X1202(1202),\n" + + " X1203(1203),\n" + + " X1204(1204),\n" + + " X1205(1205),\n" + + " X1206(1206),\n" + + " X1207(1207),\n" + + " X1208(1208),\n" + + " X1209(1209),\n" + + " X1210(1210),\n" + + " X1211(1211),\n" + + " X1212(1212),\n" + + " X1213(1213),\n" + + " X1214(1214),\n" + + " X1215(1215),\n" + + " X1216(1216),\n" + + " X1217(1217),\n" + + " X1218(1218),\n" + + " X1219(1219),\n" + + " X1220(1220),\n" + + " X1221(1221),\n" + + " X1222(1222),\n" + + " X1223(1223),\n" + + " X1224(1224),\n" + + " X1225(1225),\n" + + " X1226(1226),\n" + + " X1227(1227),\n" + + " X1228(1228),\n" + + " X1229(1229),\n" + + " X1230(1230),\n" + + " X1231(1231),\n" + + " X1232(1232),\n" + + " X1233(1233),\n" + + " X1234(1234),\n" + + " X1235(1235),\n" + + " X1236(1236),\n" + + " X1237(1237),\n" + + " X1238(1238),\n" + + " X1239(1239),\n" + + " X1240(1240),\n" + + " X1241(1241),\n" + + " X1242(1242),\n" + + " X1243(1243),\n" + + " X1244(1244),\n" + + " X1245(1245),\n" + + " X1246(1246),\n" + + " X1247(1247),\n" + + " X1248(1248),\n" + + " X1249(1249),\n" + + " X1250(1250),\n" + + " X1251(1251),\n" + + " X1252(1252),\n" + + " X1253(1253),\n" + + " X1254(1254),\n" + + " X1255(1255),\n" + + " X1256(1256),\n" + + " X1257(1257),\n" + + " X1258(1258),\n" + + " X1259(1259),\n" + + " X1260(1260),\n" + + " X1261(1261),\n" + + " X1262(1262),\n" + + " X1263(1263),\n" + + " X1264(1264),\n" + + " X1265(1265),\n" + + " X1266(1266),\n" + + " X1267(1267),\n" + + " X1268(1268),\n" + + " X1269(1269),\n" + + " X1270(1270),\n" + + " X1271(1271),\n" + + " X1272(1272),\n" + + " X1273(1273),\n" + + " X1274(1274),\n" + + " X1275(1275),\n" + + " X1276(1276),\n" + + " X1277(1277),\n" + + " X1278(1278),\n" + + " X1279(1279),\n" + + " X1280(1280),\n" + + " X1281(1281),\n" + + " X1282(1282),\n" + + " X1283(1283),\n" + + " X1284(1284),\n" + + " X1285(1285),\n" + + " X1286(1286),\n" + + " X1287(1287),\n" + + " X1288(1288),\n" + + " X1289(1289),\n" + + " X1290(1290),\n" + + " X1291(1291),\n" + + " X1292(1292),\n" + + " X1293(1293),\n" + + " X1294(1294),\n" + + " X1295(1295),\n" + + " X1296(1296),\n" + + " X1297(1297),\n" + + " X1298(1298),\n" + + " X1299(1299),\n" + + " X1300(1300),\n" + + " X1301(1301),\n" + + " X1302(1302),\n" + + " X1303(1303),\n" + + " X1304(1304),\n" + + " X1305(1305),\n" + + " X1306(1306),\n" + + " X1307(1307),\n" + + " X1308(1308),\n" + + " X1309(1309),\n" + + " X1310(1310),\n" + + " X1311(1311),\n" + + " X1312(1312),\n" + + " X1313(1313),\n" + + " X1314(1314),\n" + + " X1315(1315),\n" + + " X1316(1316),\n" + + " X1317(1317),\n" + + " X1318(1318),\n" + + " X1319(1319),\n" + + " X1320(1320),\n" + + " X1321(1321),\n" + + " X1322(1322),\n" + + " X1323(1323),\n" + + " X1324(1324),\n" + + " X1325(1325),\n" + + " X1326(1326),\n" + + " X1327(1327),\n" + + " X1328(1328),\n" + + " X1329(1329),\n" + + " X1330(1330),\n" + + " X1331(1331),\n" + + " X1332(1332),\n" + + " X1333(1333),\n" + + " X1334(1334),\n" + + " X1335(1335),\n" + + " X1336(1336),\n" + + " X1337(1337),\n" + + " X1338(1338),\n" + + " X1339(1339),\n" + + " X1340(1340),\n" + + " X1341(1341),\n" + + " X1342(1342),\n" + + " X1343(1343),\n" + + " X1344(1344),\n" + + " X1345(1345),\n" + + " X1346(1346),\n" + + " X1347(1347),\n" + + " X1348(1348),\n" + + " X1349(1349),\n" + + " X1350(1350),\n" + + " X1351(1351),\n" + + " X1352(1352),\n" + + " X1353(1353),\n" + + " X1354(1354),\n" + + " X1355(1355),\n" + + " X1356(1356),\n" + + " X1357(1357),\n" + + " X1358(1358),\n" + + " X1359(1359),\n" + + " X1360(1360),\n" + + " X1361(1361),\n" + + " X1362(1362),\n" + + " X1363(1363),\n" + + " X1364(1364),\n" + + " X1365(1365),\n" + + " X1366(1366),\n" + + " X1367(1367),\n" + + " X1368(1368),\n" + + " X1369(1369),\n" + + " X1370(1370),\n" + + " X1371(1371),\n" + + " X1372(1372),\n" + + " X1373(1373),\n" + + " X1374(1374),\n" + + " X1375(1375),\n" + + " X1376(1376),\n" + + " X1377(1377),\n" + + " X1378(1378),\n" + + " X1379(1379),\n" + + " X1380(1380),\n" + + " X1381(1381),\n" + + " X1382(1382),\n" + + " X1383(1383),\n" + + " X1384(1384),\n" + + " X1385(1385),\n" + + " X1386(1386),\n" + + " X1387(1387),\n" + + " X1388(1388),\n" + + " X1389(1389),\n" + + " X1390(1390),\n" + + " X1391(1391),\n" + + " X1392(1392),\n" + + " X1393(1393),\n" + + " X1394(1394),\n" + + " X1395(1395),\n" + + " X1396(1396),\n" + + " X1397(1397),\n" + + " X1398(1398),\n" + + " X1399(1399),\n" + + " X1400(1400),\n" + + " X1401(1401),\n" + + " X1402(1402),\n" + + " X1403(1403),\n" + + " X1404(1404),\n" + + " X1405(1405),\n" + + " X1406(1406),\n" + + " X1407(1407),\n" + + " X1408(1408),\n" + + " X1409(1409),\n" + + " X1410(1410),\n" + + " X1411(1411),\n" + + " X1412(1412),\n" + + " X1413(1413),\n" + + " X1414(1414),\n" + + " X1415(1415),\n" + + " X1416(1416),\n" + + " X1417(1417),\n" + + " X1418(1418),\n" + + " X1419(1419),\n" + + " X1420(1420),\n" + + " X1421(1421),\n" + + " X1422(1422),\n" + + " X1423(1423),\n" + + " X1424(1424),\n" + + " X1425(1425),\n" + + " X1426(1426),\n" + + " X1427(1427),\n" + + " X1428(1428),\n" + + " X1429(1429),\n" + + " X1430(1430),\n" + + " X1431(1431),\n" + + " X1432(1432),\n" + + " X1433(1433),\n" + + " X1434(1434),\n" + + " X1435(1435),\n" + + " X1436(1436),\n" + + " X1437(1437),\n" + + " X1438(1438),\n" + + " X1439(1439),\n" + + " X1440(1440),\n" + + " X1441(1441),\n" + + " X1442(1442),\n" + + " X1443(1443),\n" + + " X1444(1444),\n" + + " X1445(1445),\n" + + " X1446(1446),\n" + + " X1447(1447),\n" + + " X1448(1448),\n" + + " X1449(1449),\n" + + " X1450(1450),\n" + + " X1451(1451),\n" + + " X1452(1452),\n" + + " X1453(1453),\n" + + " X1454(1454),\n" + + " X1455(1455),\n" + + " X1456(1456),\n" + + " X1457(1457),\n" + + " X1458(1458),\n" + + " X1459(1459),\n" + + " X1460(1460),\n" + + " X1461(1461),\n" + + " X1462(1462),\n" + + " X1463(1463),\n" + + " X1464(1464),\n" + + " X1465(1465),\n" + + " X1466(1466),\n" + + " X1467(1467),\n" + + " X1468(1468),\n" + + " X1469(1469),\n" + + " X1470(1470),\n" + + " X1471(1471),\n" + + " X1472(1472),\n" + + " X1473(1473),\n" + + " X1474(1474),\n" + + " X1475(1475),\n" + + " X1476(1476),\n" + + " X1477(1477),\n" + + " X1478(1478),\n" + + " X1479(1479),\n" + + " X1480(1480),\n" + + " X1481(1481),\n" + + " X1482(1482),\n" + + " X1483(1483),\n" + + " X1484(1484),\n" + + " X1485(1485),\n" + + " X1486(1486),\n" + + " X1487(1487),\n" + + " X1488(1488),\n" + + " X1489(1489),\n" + + " X1490(1490),\n" + + " X1491(1491),\n" + + " X1492(1492),\n" + + " X1493(1493),\n" + + " X1494(1494),\n" + + " X1495(1495),\n" + + " X1496(1496),\n" + + " X1497(1497),\n" + + " X1498(1498),\n" + + " X1499(1499),\n" + + " X1500(1500),\n" + + " X1501(1501),\n" + + " X1502(1502),\n" + + " X1503(1503),\n" + + " X1504(1504),\n" + + " X1505(1505),\n" + + " X1506(1506),\n" + + " X1507(1507),\n" + + " X1508(1508),\n" + + " X1509(1509),\n" + + " X1510(1510),\n" + + " X1511(1511),\n" + + " X1512(1512),\n" + + " X1513(1513),\n" + + " X1514(1514),\n" + + " X1515(1515),\n" + + " X1516(1516),\n" + + " X1517(1517),\n" + + " X1518(1518),\n" + + " X1519(1519),\n" + + " X1520(1520),\n" + + " X1521(1521),\n" + + " X1522(1522),\n" + + " X1523(1523),\n" + + " X1524(1524),\n" + + " X1525(1525),\n" + + " X1526(1526),\n" + + " X1527(1527),\n" + + " X1528(1528),\n" + + " X1529(1529),\n" + + " X1530(1530),\n" + + " X1531(1531),\n" + + " X1532(1532),\n" + + " X1533(1533),\n" + + " X1534(1534),\n" + + " X1535(1535),\n" + + " X1536(1536),\n" + + " X1537(1537),\n" + + " X1538(1538),\n" + + " X1539(1539),\n" + + " X1540(1540),\n" + + " X1541(1541),\n" + + " X1542(1542),\n" + + " X1543(1543),\n" + + " X1544(1544),\n" + + " X1545(1545),\n" + + " X1546(1546),\n" + + " X1547(1547),\n" + + " X1548(1548),\n" + + " X1549(1549),\n" + + " X1550(1550),\n" + + " X1551(1551),\n" + + " X1552(1552),\n" + + " X1553(1553),\n" + + " X1554(1554),\n" + + " X1555(1555),\n" + + " X1556(1556),\n" + + " X1557(1557),\n" + + " X1558(1558),\n" + + " X1559(1559),\n" + + " X1560(1560),\n" + + " X1561(1561),\n" + + " X1562(1562),\n" + + " X1563(1563),\n" + + " X1564(1564),\n" + + " X1565(1565),\n" + + " X1566(1566),\n" + + " X1567(1567),\n" + + " X1568(1568),\n" + + " X1569(1569),\n" + + " X1570(1570),\n" + + " X1571(1571),\n" + + " X1572(1572),\n" + + " X1573(1573),\n" + + " X1574(1574),\n" + + " X1575(1575),\n" + + " X1576(1576),\n" + + " X1577(1577),\n" + + " X1578(1578),\n" + + " X1579(1579),\n" + + " X1580(1580),\n" + + " X1581(1581),\n" + + " X1582(1582),\n" + + " X1583(1583),\n" + + " X1584(1584),\n" + + " X1585(1585),\n" + + " X1586(1586),\n" + + " X1587(1587),\n" + + " X1588(1588),\n" + + " X1589(1589),\n" + + " X1590(1590),\n" + + " X1591(1591),\n" + + " X1592(1592),\n" + + " X1593(1593),\n" + + " X1594(1594),\n" + + " X1595(1595),\n" + + " X1596(1596),\n" + + " X1597(1597),\n" + + " X1598(1598),\n" + + " X1599(1599),\n" + + " X1600(1600),\n" + + " X1601(1601),\n" + + " X1602(1602),\n" + + " X1603(1603),\n" + + " X1604(1604),\n" + + " X1605(1605),\n" + + " X1606(1606),\n" + + " X1607(1607),\n" + + " X1608(1608),\n" + + " X1609(1609),\n" + + " X1610(1610),\n" + + " X1611(1611),\n" + + " X1612(1612),\n" + + " X1613(1613),\n" + + " X1614(1614),\n" + + " X1615(1615),\n" + + " X1616(1616),\n" + + " X1617(1617),\n" + + " X1618(1618),\n" + + " X1619(1619),\n" + + " X1620(1620),\n" + + " X1621(1621),\n" + + " X1622(1622),\n" + + " X1623(1623),\n" + + " X1624(1624),\n" + + " X1625(1625),\n" + + " X1626(1626),\n" + + " X1627(1627),\n" + + " X1628(1628),\n" + + " X1629(1629),\n" + + " X1630(1630),\n" + + " X1631(1631),\n" + + " X1632(1632),\n" + + " X1633(1633),\n" + + " X1634(1634),\n" + + " X1635(1635),\n" + + " X1636(1636),\n" + + " X1637(1637),\n" + + " X1638(1638),\n" + + " X1639(1639),\n" + + " X1640(1640),\n" + + " X1641(1641),\n" + + " X1642(1642),\n" + + " X1643(1643),\n" + + " X1644(1644),\n" + + " X1645(1645),\n" + + " X1646(1646),\n" + + " X1647(1647),\n" + + " X1648(1648),\n" + + " X1649(1649),\n" + + " X1650(1650),\n" + + " X1651(1651),\n" + + " X1652(1652),\n" + + " X1653(1653),\n" + + " X1654(1654),\n" + + " X1655(1655),\n" + + " X1656(1656),\n" + + " X1657(1657),\n" + + " X1658(1658),\n" + + " X1659(1659),\n" + + " X1660(1660),\n" + + " X1661(1661),\n" + + " X1662(1662),\n" + + " X1663(1663),\n" + + " X1664(1664),\n" + + " X1665(1665),\n" + + " X1666(1666),\n" + + " X1667(1667),\n" + + " X1668(1668),\n" + + " X1669(1669),\n" + + " X1670(1670),\n" + + " X1671(1671),\n" + + " X1672(1672),\n" + + " X1673(1673),\n" + + " X1674(1674),\n" + + " X1675(1675),\n" + + " X1676(1676),\n" + + " X1677(1677),\n" + + " X1678(1678),\n" + + " X1679(1679),\n" + + " X1680(1680),\n" + + " X1681(1681),\n" + + " X1682(1682),\n" + + " X1683(1683),\n" + + " X1684(1684),\n" + + " X1685(1685),\n" + + " X1686(1686),\n" + + " X1687(1687),\n" + + " X1688(1688),\n" + + " X1689(1689),\n" + + " X1690(1690),\n" + + " X1691(1691),\n" + + " X1692(1692),\n" + + " X1693(1693),\n" + + " X1694(1694),\n" + + " X1695(1695),\n" + + " X1696(1696),\n" + + " X1697(1697),\n" + + " X1698(1698),\n" + + " X1699(1699),\n" + + " X1700(1700),\n" + + " X1701(1701),\n" + + " X1702(1702),\n" + + " X1703(1703),\n" + + " X1704(1704),\n" + + " X1705(1705),\n" + + " X1706(1706),\n" + + " X1707(1707),\n" + + " X1708(1708),\n" + + " X1709(1709),\n" + + " X1710(1710),\n" + + " X1711(1711),\n" + + " X1712(1712),\n" + + " X1713(1713),\n" + + " X1714(1714),\n" + + " X1715(1715),\n" + + " X1716(1716),\n" + + " X1717(1717),\n" + + " X1718(1718),\n" + + " X1719(1719),\n" + + " X1720(1720),\n" + + " X1721(1721),\n" + + " X1722(1722),\n" + + " X1723(1723),\n" + + " X1724(1724),\n" + + " X1725(1725),\n" + + " X1726(1726),\n" + + " X1727(1727),\n" + + " X1728(1728),\n" + + " X1729(1729),\n" + + " X1730(1730),\n" + + " X1731(1731),\n" + + " X1732(1732),\n" + + " X1733(1733),\n" + + " X1734(1734),\n" + + " X1735(1735),\n" + + " X1736(1736),\n" + + " X1737(1737),\n" + + " X1738(1738),\n" + + " X1739(1739),\n" + + " X1740(1740),\n" + + " X1741(1741),\n" + + " X1742(1742),\n" + + " X1743(1743),\n" + + " X1744(1744),\n" + + " X1745(1745),\n" + + " X1746(1746),\n" + + " X1747(1747),\n" + + " X1748(1748),\n" + + " X1749(1749),\n" + + " X1750(1750),\n" + + " X1751(1751),\n" + + " X1752(1752),\n" + + " X1753(1753),\n" + + " X1754(1754),\n" + + " X1755(1755),\n" + + " X1756(1756),\n" + + " X1757(1757),\n" + + " X1758(1758),\n" + + " X1759(1759),\n" + + " X1760(1760),\n" + + " X1761(1761),\n" + + " X1762(1762),\n" + + " X1763(1763),\n" + + " X1764(1764),\n" + + " X1765(1765),\n" + + " X1766(1766),\n" + + " X1767(1767),\n" + + " X1768(1768),\n" + + " X1769(1769),\n" + + " X1770(1770),\n" + + " X1771(1771),\n" + + " X1772(1772),\n" + + " X1773(1773),\n" + + " X1774(1774),\n" + + " X1775(1775),\n" + + " X1776(1776),\n" + + " X1777(1777),\n" + + " X1778(1778),\n" + + " X1779(1779),\n" + + " X1780(1780),\n" + + " X1781(1781),\n" + + " X1782(1782),\n" + + " X1783(1783),\n" + + " X1784(1784),\n" + + " X1785(1785),\n" + + " X1786(1786),\n" + + " X1787(1787),\n" + + " X1788(1788),\n" + + " X1789(1789),\n" + + " X1790(1790),\n" + + " X1791(1791),\n" + + " X1792(1792),\n" + + " X1793(1793),\n" + + " X1794(1794),\n" + + " X1795(1795),\n" + + " X1796(1796),\n" + + " X1797(1797),\n" + + " X1798(1798),\n" + + " X1799(1799),\n" + + " X1800(1800),\n" + + " X1801(1801),\n" + + " X1802(1802),\n" + + " X1803(1803),\n" + + " X1804(1804),\n" + + " X1805(1805),\n" + + " X1806(1806),\n" + + " X1807(1807),\n" + + " X1808(1808),\n" + + " X1809(1809),\n" + + " X1810(1810),\n" + + " X1811(1811),\n" + + " X1812(1812),\n" + + " X1813(1813),\n" + + " X1814(1814),\n" + + " X1815(1815),\n" + + " X1816(1816),\n" + + " X1817(1817),\n" + + " X1818(1818),\n" + + " X1819(1819),\n" + + " X1820(1820),\n" + + " X1821(1821),\n" + + " X1822(1822),\n" + + " X1823(1823),\n" + + " X1824(1824),\n" + + " X1825(1825),\n" + + " X1826(1826),\n" + + " X1827(1827),\n" + + " X1828(1828),\n" + + " X1829(1829),\n" + + " X1830(1830),\n" + + " X1831(1831),\n" + + " X1832(1832),\n" + + " X1833(1833),\n" + + " X1834(1834),\n" + + " X1835(1835),\n" + + " X1836(1836),\n" + + " X1837(1837),\n" + + " X1838(1838),\n" + + " X1839(1839),\n" + + " X1840(1840),\n" + + " X1841(1841),\n" + + " X1842(1842),\n" + + " X1843(1843),\n" + + " X1844(1844),\n" + + " X1845(1845),\n" + + " X1846(1846),\n" + + " X1847(1847),\n" + + " X1848(1848),\n" + + " X1849(1849),\n" + + " X1850(1850),\n" + + " X1851(1851),\n" + + " X1852(1852),\n" + + " X1853(1853),\n" + + " X1854(1854),\n" + + " X1855(1855),\n" + + " X1856(1856),\n" + + " X1857(1857),\n" + + " X1858(1858),\n" + + " X1859(1859),\n" + + " X1860(1860),\n" + + " X1861(1861),\n" + + " X1862(1862),\n" + + " X1863(1863),\n" + + " X1864(1864),\n" + + " X1865(1865),\n" + + " X1866(1866),\n" + + " X1867(1867),\n" + + " X1868(1868),\n" + + " X1869(1869),\n" + + " X1870(1870),\n" + + " X1871(1871),\n" + + " X1872(1872),\n" + + " X1873(1873),\n" + + " X1874(1874),\n" + + " X1875(1875),\n" + + " X1876(1876),\n" + + " X1877(1877),\n" + + " X1878(1878),\n" + + " X1879(1879),\n" + + " X1880(1880),\n" + + " X1881(1881),\n" + + " X1882(1882),\n" + + " X1883(1883),\n" + + " X1884(1884),\n" + + " X1885(1885),\n" + + " X1886(1886),\n" + + " X1887(1887),\n" + + " X1888(1888),\n" + + " X1889(1889),\n" + + " X1890(1890),\n" + + " X1891(1891),\n" + + " X1892(1892),\n" + + " X1893(1893),\n" + + " X1894(1894),\n" + + " X1895(1895),\n" + + " X1896(1896),\n" + + " X1897(1897),\n" + + " X1898(1898),\n" + + " X1899(1899),\n" + + " X1900(1900),\n" + + " X1901(1901),\n" + + " X1902(1902),\n" + + " X1903(1903),\n" + + " X1904(1904),\n" + + " X1905(1905),\n" + + " X1906(1906),\n" + + " X1907(1907),\n" + + " X1908(1908),\n" + + " X1909(1909),\n" + + " X1910(1910),\n" + + " X1911(1911),\n" + + " X1912(1912),\n" + + " X1913(1913),\n" + + " X1914(1914),\n" + + " X1915(1915),\n" + + " X1916(1916),\n" + + " X1917(1917),\n" + + " X1918(1918),\n" + + " X1919(1919),\n" + + " X1920(1920),\n" + + " X1921(1921),\n" + + " X1922(1922),\n" + + " X1923(1923),\n" + + " X1924(1924),\n" + + " X1925(1925),\n" + + " X1926(1926),\n" + + " X1927(1927),\n" + + " X1928(1928),\n" + + " X1929(1929),\n" + + " X1930(1930),\n" + + " X1931(1931),\n" + + " X1932(1932),\n" + + " X1933(1933),\n" + + " X1934(1934),\n" + + " X1935(1935),\n" + + " X1936(1936),\n" + + " X1937(1937),\n" + + " X1938(1938),\n" + + " X1939(1939),\n" + + " X1940(1940),\n" + + " X1941(1941),\n" + + " X1942(1942),\n" + + " X1943(1943),\n" + + " X1944(1944),\n" + + " X1945(1945),\n" + + " X1946(1946),\n" + + " X1947(1947),\n" + + " X1948(1948),\n" + + " X1949(1949),\n" + + " X1950(1950),\n" + + " X1951(1951),\n" + + " X1952(1952),\n" + + " X1953(1953),\n" + + " X1954(1954),\n" + + " X1955(1955),\n" + + " X1956(1956),\n" + + " X1957(1957),\n" + + " X1958(1958),\n" + + " X1959(1959),\n" + + " X1960(1960),\n" + + " X1961(1961),\n" + + " X1962(1962),\n" + + " X1963(1963),\n" + + " X1964(1964),\n" + + " X1965(1965),\n" + + " X1966(1966),\n" + + " X1967(1967),\n" + + " X1968(1968),\n" + + " X1969(1969),\n" + + " X1970(1970),\n" + + " X1971(1971),\n" + + " X1972(1972),\n" + + " X1973(1973),\n" + + " X1974(1974),\n" + + " X1975(1975),\n" + + " X1976(1976),\n" + + " X1977(1977),\n" + + " X1978(1978),\n" + + " X1979(1979),\n" + + " X1980(1980),\n" + + " X1981(1981),\n" + + " X1982(1982),\n" + + " X1983(1983),\n" + + " X1984(1984),\n" + + " X1985(1985),\n" + + " X1986(1986),\n" + + " X1987(1987),\n" + + " X1988(1988),\n" + + " X1989(1989),\n" + + " X1990(1990),\n" + + " X1991(1991),\n" + + " X1992(1992),\n" + + " X1993(1993),\n" + + " X1994(1994),\n" + + " X1995(1995),\n" + + " X1996(1996),\n" + + " X1997(1997),\n" + + " X1998(1998),\n" + + " X1999(1999),\n" + + " X2000(2000),\n" + + " X2001(2001),\n" + + " X2002(2002),\n" + + " ;\n" + + "\n" + + " private int value;\n" + + " X(int i) {\n" + + " this.value = i;\n" + + " }\n" + + " \n" + + " public static void main(String[] args) {\n" + + " int i = 0;\n" + + " for (X x : X.values()) {\n" + + " i++;\n" + + " System.out.print(x);\n" + + " }\n" + + " System.out.print(i);\n" + + " }\n" + + " \n" + + " public String toString() {\n" + + " return Integer.toString(this.value);\n" + + " }\n" + + "}" + }, + buffer.toString()); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=393749 +public void test0019() { + if (this.complianceLevel <= ClassFileConstants.JDK1_4) return; + // only run in 1.5 or above + this.runConformTest( + new String[] { + "X.java", + "import java.util.HashMap;\n" + + "import java.util.Map;\n" + + "\n" + + "public enum X {\n" + + " C0,\n" + + " C1,\n" + + " C2,\n" + + " C3,\n" + + " C4,\n" + + " C5,\n" + + " C6,\n" + + " C7,\n" + + " C8,\n" + + " C9,\n" + + " C10,\n" + + " C11,\n" + + " C12,\n" + + " C13,\n" + + " C14,\n" + + " C15,\n" + + " C16,\n" + + " C17,\n" + + " C18,\n" + + " C19,\n" + + " C20,\n" + + " C21,\n" + + " C22,\n" + + " C23,\n" + + " C24,\n" + + " C25,\n" + + " C26,\n" + + " C27,\n" + + " C28,\n" + + " C29,\n" + + " C30,\n" + + " C31,\n" + + " C32,\n" + + " C33,\n" + + " C34,\n" + + " C35,\n" + + " C36,\n" + + " C37,\n" + + " C38,\n" + + " C39,\n" + + " C40,\n" + + " C41,\n" + + " C42,\n" + + " C43,\n" + + " C44,\n" + + " C45,\n" + + " C46,\n" + + " C47,\n" + + " C48,\n" + + " C49,\n" + + " C50,\n" + + " C51,\n" + + " C52,\n" + + " C53,\n" + + " C54,\n" + + " C55,\n" + + " C56,\n" + + " C57,\n" + + " C58,\n" + + " C59,\n" + + " C60,\n" + + " C61,\n" + + " C62,\n" + + " C63,\n" + + " C64,\n" + + " C65,\n" + + " C66,\n" + + " C67,\n" + + " C68,\n" + + " C69,\n" + + " C70,\n" + + " C71,\n" + + " C72,\n" + + " C73,\n" + + " C74,\n" + + " C75,\n" + + " C76,\n" + + " C77,\n" + + " C78,\n" + + " C79,\n" + + " C80,\n" + + " C81,\n" + + " C82,\n" + + " C83,\n" + + " C84,\n" + + " C85,\n" + + " C86,\n" + + " C87,\n" + + " C88,\n" + + " C89,\n" + + " C90,\n" + + " C91,\n" + + " C92,\n" + + " C93,\n" + + " C94,\n" + + " C95,\n" + + " C96,\n" + + " C97,\n" + + " C98,\n" + + " C99,\n" + + " C100,\n" + + " C101,\n" + + " C102,\n" + + " C103,\n" + + " C104,\n" + + " C105,\n" + + " C106,\n" + + " C107,\n" + + " C108,\n" + + " C109,\n" + + " C110,\n" + + " C111,\n" + + " C112,\n" + + " C113,\n" + + " C114,\n" + + " C115,\n" + + " C116,\n" + + " C117,\n" + + " C118,\n" + + " C119,\n" + + " C120,\n" + + " C121,\n" + + " C122,\n" + + " C123,\n" + + " C124,\n" + + " C125,\n" + + " C126,\n" + + " C127,\n" + + " C128,\n" + + " C129,\n" + + " C130,\n" + + " C131,\n" + + " C132,\n" + + " C133,\n" + + " C134,\n" + + " C135,\n" + + " C136,\n" + + " C137,\n" + + " C138,\n" + + " C139,\n" + + " C140,\n" + + " C141,\n" + + " C142,\n" + + " C143,\n" + + " C144,\n" + + " C145,\n" + + " C146,\n" + + " C147,\n" + + " C148,\n" + + " C149,\n" + + " C150,\n" + + " C151,\n" + + " C152,\n" + + " C153,\n" + + " C154,\n" + + " C155,\n" + + " C156,\n" + + " C157,\n" + + " C158,\n" + + " C159,\n" + + " C160,\n" + + " C161,\n" + + " C162,\n" + + " C163,\n" + + " C164,\n" + + " C165,\n" + + " C166,\n" + + " C167,\n" + + " C168,\n" + + " C169,\n" + + " C170,\n" + + " C171,\n" + + " C172,\n" + + " C173,\n" + + " C174,\n" + + " C175,\n" + + " C176,\n" + + " C177,\n" + + " C178,\n" + + " C179,\n" + + " C180,\n" + + " C181,\n" + + " C182,\n" + + " C183,\n" + + " C184,\n" + + " C185,\n" + + " C186,\n" + + " C187,\n" + + " C188,\n" + + " C189,\n" + + " C190,\n" + + " C191,\n" + + " C192,\n" + + " C193,\n" + + " C194,\n" + + " C195,\n" + + " C196,\n" + + " C197,\n" + + " C198,\n" + + " C199,\n" + + " C200,\n" + + " C201,\n" + + " C202,\n" + + " C203,\n" + + " C204,\n" + + " C205,\n" + + " C206,\n" + + " C207,\n" + + " C208,\n" + + " C209,\n" + + " C210,\n" + + " C211,\n" + + " C212,\n" + + " C213,\n" + + " C214,\n" + + " C215,\n" + + " C216,\n" + + " C217,\n" + + " C218,\n" + + " C219,\n" + + " C220,\n" + + " C221,\n" + + " C222,\n" + + " C223,\n" + + " C224,\n" + + " C225,\n" + + " C226,\n" + + " C227,\n" + + " C228,\n" + + " C229,\n" + + " C230,\n" + + " C231,\n" + + " C232,\n" + + " C233,\n" + + " C234,\n" + + " C235,\n" + + " C236,\n" + + " C237,\n" + + " C238,\n" + + " C239,\n" + + " C240,\n" + + " C241,\n" + + " C242,\n" + + " C243,\n" + + " C244,\n" + + " C245,\n" + + " C246,\n" + + " C247,\n" + + " C248,\n" + + " C249,\n" + + " C250,\n" + + " C251,\n" + + " C252,\n" + + " C253,\n" + + " C254,\n" + + " C255,\n" + + " C256,\n" + + " C257,\n" + + " C258,\n" + + " C259,\n" + + " C260,\n" + + " C261,\n" + + " C262,\n" + + " C263,\n" + + " C264,\n" + + " C265,\n" + + " C266,\n" + + " C267,\n" + + " C268,\n" + + " C269,\n" + + " C270,\n" + + " C271,\n" + + " C272,\n" + + " C273,\n" + + " C274,\n" + + " C275,\n" + + " C276,\n" + + " C277,\n" + + " C278,\n" + + " C279,\n" + + " C280,\n" + + " C281,\n" + + " C282,\n" + + " C283,\n" + + " C284,\n" + + " C285,\n" + + " C286,\n" + + " C287,\n" + + " C288,\n" + + " C289,\n" + + " C290,\n" + + " C291,\n" + + " C292,\n" + + " C293,\n" + + " C294,\n" + + " C295,\n" + + " C296,\n" + + " C297,\n" + + " C298,\n" + + " C299,\n" + + " C300,\n" + + " C301,\n" + + " C302,\n" + + " C303,\n" + + " C304,\n" + + " C305,\n" + + " C306,\n" + + " C307,\n" + + " C308,\n" + + " C309,\n" + + " C310,\n" + + " C311,\n" + + " C312,\n" + + " C313,\n" + + " C314,\n" + + " C315,\n" + + " C316,\n" + + " C317,\n" + + " C318,\n" + + " C319,\n" + + " C320,\n" + + " C321,\n" + + " C322,\n" + + " C323,\n" + + " C324,\n" + + " C325,\n" + + " C326,\n" + + " C327,\n" + + " C328,\n" + + " C329,\n" + + " C330,\n" + + " C331,\n" + + " C332,\n" + + " C333,\n" + + " C334,\n" + + " C335,\n" + + " C336,\n" + + " C337,\n" + + " C338,\n" + + " C339,\n" + + " C340,\n" + + " C341,\n" + + " C342,\n" + + " C343,\n" + + " C344,\n" + + " C345,\n" + + " C346,\n" + + " C347,\n" + + " C348,\n" + + " C349,\n" + + " C350,\n" + + " C351,\n" + + " C352,\n" + + " C353,\n" + + " C354,\n" + + " C355,\n" + + " C356,\n" + + " C357,\n" + + " C358,\n" + + " C359,\n" + + " C360,\n" + + " C361,\n" + + " C362,\n" + + " C363,\n" + + " C364,\n" + + " C365,\n" + + " C366,\n" + + " C367,\n" + + " C368,\n" + + " C369,\n" + + " C370,\n" + + " C371,\n" + + " C372,\n" + + " C373,\n" + + " C374,\n" + + " C375,\n" + + " C376,\n" + + " C377,\n" + + " C378,\n" + + " C379,\n" + + " C380,\n" + + " C381,\n" + + " C382,\n" + + " C383,\n" + + " C384,\n" + + " C385,\n" + + " C386,\n" + + " C387,\n" + + " C388,\n" + + " C389,\n" + + " C390,\n" + + " C391,\n" + + " C392,\n" + + " C393,\n" + + " C394,\n" + + " C395,\n" + + " C396,\n" + + " C397,\n" + + " C398,\n" + + " C399,\n" + + " C400,\n" + + " C401,\n" + + " C402,\n" + + " C403,\n" + + " C404,\n" + + " C405,\n" + + " C406,\n" + + " C407,\n" + + " C408,\n" + + " C409,\n" + + " C410,\n" + + " C411,\n" + + " C412,\n" + + " C413,\n" + + " C414,\n" + + " C415,\n" + + " C416,\n" + + " C417,\n" + + " C418,\n" + + " C419,\n" + + " C420,\n" + + " C421,\n" + + " C422,\n" + + " C423,\n" + + " C424,\n" + + " C425,\n" + + " C426,\n" + + " C427,\n" + + " C428,\n" + + " C429,\n" + + " C430,\n" + + " C431,\n" + + " C432,\n" + + " C433,\n" + + " C434,\n" + + " C435,\n" + + " C436,\n" + + " C437,\n" + + " C438,\n" + + " C439,\n" + + " C440,\n" + + " C441,\n" + + " C442,\n" + + " C443,\n" + + " C444,\n" + + " C445,\n" + + " C446,\n" + + " C447,\n" + + " C448,\n" + + " C449,\n" + + " C450,\n" + + " C451,\n" + + " C452,\n" + + " C453,\n" + + " C454,\n" + + " C455,\n" + + " C456,\n" + + " C457,\n" + + " C458,\n" + + " C459,\n" + + " C460,\n" + + " C461,\n" + + " C462,\n" + + " C463,\n" + + " C464,\n" + + " C465,\n" + + " C466,\n" + + " C467,\n" + + " C468,\n" + + " C469,\n" + + " C470,\n" + + " C471,\n" + + " C472,\n" + + " C473,\n" + + " C474,\n" + + " C475,\n" + + " C476,\n" + + " C477,\n" + + " C478,\n" + + " C479,\n" + + " C480,\n" + + " C481,\n" + + " C482,\n" + + " C483,\n" + + " C484,\n" + + " C485,\n" + + " C486,\n" + + " C487,\n" + + " C488,\n" + + " C489,\n" + + " C490,\n" + + " C491,\n" + + " C492,\n" + + " C493,\n" + + " C494,\n" + + " C495,\n" + + " C496,\n" + + " C497,\n" + + " C498,\n" + + " C499,\n" + + " C500,\n" + + " C501,\n" + + " C502,\n" + + " C503,\n" + + " C504,\n" + + " C505,\n" + + " C506,\n" + + " C507,\n" + + " C508,\n" + + " C509,\n" + + " C510,\n" + + " C511,\n" + + " C512,\n" + + " C513,\n" + + " C514,\n" + + " C515,\n" + + " C516,\n" + + " C517,\n" + + " C518,\n" + + " C519,\n" + + " C520,\n" + + " C521,\n" + + " C522,\n" + + " C523,\n" + + " C524,\n" + + " C525,\n" + + " C526,\n" + + " C527,\n" + + " C528,\n" + + " C529,\n" + + " C530,\n" + + " C531,\n" + + " C532,\n" + + " C533,\n" + + " C534,\n" + + " C535,\n" + + " C536,\n" + + " C537,\n" + + " C538,\n" + + " C539,\n" + + " C540,\n" + + " C541,\n" + + " C542,\n" + + " C543,\n" + + " C544,\n" + + " C545,\n" + + " C546,\n" + + " C547,\n" + + " C548,\n" + + " C549,\n" + + " C550,\n" + + " C551,\n" + + " C552,\n" + + " C553,\n" + + " C554,\n" + + " C555,\n" + + " C556,\n" + + " C557,\n" + + " C558,\n" + + " C559,\n" + + " C560,\n" + + " C561,\n" + + " C562,\n" + + " C563,\n" + + " C564,\n" + + " C565,\n" + + " C566,\n" + + " C567,\n" + + " C568,\n" + + " C569,\n" + + " C570,\n" + + " C571,\n" + + " C572,\n" + + " C573,\n" + + " C574,\n" + + " C575,\n" + + " C576,\n" + + " C577,\n" + + " C578,\n" + + " C579,\n" + + " C580,\n" + + " C581,\n" + + " C582,\n" + + " C583,\n" + + " C584,\n" + + " C585,\n" + + " C586,\n" + + " C587,\n" + + " C588,\n" + + " C589,\n" + + " C590,\n" + + " C591,\n" + + " C592,\n" + + " C593,\n" + + " C594,\n" + + " C595,\n" + + " C596,\n" + + " C597,\n" + + " C598,\n" + + " C599,\n" + + " C600,\n" + + " C601,\n" + + " C602,\n" + + " C603,\n" + + " C604,\n" + + " C605,\n" + + " C606,\n" + + " C607,\n" + + " C608,\n" + + " C609,\n" + + " C610,\n" + + " C611,\n" + + " C612,\n" + + " C613,\n" + + " C614,\n" + + " C615,\n" + + " C616,\n" + + " C617,\n" + + " C618,\n" + + " C619,\n" + + " C620,\n" + + " C621,\n" + + " C622,\n" + + " C623,\n" + + " C624,\n" + + " C625,\n" + + " C626,\n" + + " C627,\n" + + " C628,\n" + + " C629,\n" + + " C630,\n" + + " C631,\n" + + " C632,\n" + + " C633,\n" + + " C634,\n" + + " C635,\n" + + " C636,\n" + + " C637,\n" + + " C638,\n" + + " C639,\n" + + " C640,\n" + + " C641,\n" + + " C642,\n" + + " C643,\n" + + " C644,\n" + + " C645,\n" + + " C646,\n" + + " C647,\n" + + " C648,\n" + + " C649,\n" + + " C650,\n" + + " C651,\n" + + " C652,\n" + + " C653,\n" + + " C654,\n" + + " C655,\n" + + " C656,\n" + + " C657,\n" + + " C658,\n" + + " C659,\n" + + " C660,\n" + + " C661,\n" + + " C662,\n" + + " C663,\n" + + " C664,\n" + + " C665,\n" + + " C666,\n" + + " C667,\n" + + " C668,\n" + + " C669,\n" + + " C670,\n" + + " C671,\n" + + " C672,\n" + + " C673,\n" + + " C674,\n" + + " C675,\n" + + " C676,\n" + + " C677,\n" + + " C678,\n" + + " C679,\n" + + " C680,\n" + + " C681,\n" + + " C682,\n" + + " C683,\n" + + " C684,\n" + + " C685,\n" + + " C686,\n" + + " C687,\n" + + " C688,\n" + + " C689,\n" + + " C690,\n" + + " C691,\n" + + " C692,\n" + + " C693,\n" + + " C694,\n" + + " C695,\n" + + " C696,\n" + + " C697,\n" + + " C698,\n" + + " C699,\n" + + " C700,\n" + + " C701,\n" + + " C702,\n" + + " C703,\n" + + " C704,\n" + + " C705,\n" + + " C706,\n" + + " C707,\n" + + " C708,\n" + + " C709,\n" + + " C710,\n" + + " C711,\n" + + " C712,\n" + + " C713,\n" + + " C714,\n" + + " C715,\n" + + " C716,\n" + + " C717,\n" + + " C718,\n" + + " C719,\n" + + " C720,\n" + + " C721,\n" + + " C722,\n" + + " C723,\n" + + " C724,\n" + + " C725,\n" + + " C726,\n" + + " C727,\n" + + " C728,\n" + + " C729,\n" + + " C730,\n" + + " C731,\n" + + " C732,\n" + + " C733,\n" + + " C734,\n" + + " C735,\n" + + " C736,\n" + + " C737,\n" + + " C738,\n" + + " C739,\n" + + " C740,\n" + + " C741,\n" + + " C742,\n" + + " C743,\n" + + " C744,\n" + + " C745,\n" + + " C746,\n" + + " C747,\n" + + " C748,\n" + + " C749,\n" + + " C750,\n" + + " C751,\n" + + " C752,\n" + + " C753,\n" + + " C754,\n" + + " C755,\n" + + " C756,\n" + + " C757,\n" + + " C758,\n" + + " C759,\n" + + " C760,\n" + + " C761,\n" + + " C762,\n" + + " C763,\n" + + " C764,\n" + + " C765,\n" + + " C766,\n" + + " C767,\n" + + " C768,\n" + + " C769,\n" + + " C770,\n" + + " C771,\n" + + " C772,\n" + + " C773,\n" + + " C774,\n" + + " C775,\n" + + " C776,\n" + + " C777,\n" + + " C778,\n" + + " C779,\n" + + " C780,\n" + + " C781,\n" + + " C782,\n" + + " C783,\n" + + " C784,\n" + + " C785,\n" + + " C786,\n" + + " C787,\n" + + " C788,\n" + + " C789,\n" + + " C790,\n" + + " C791,\n" + + " C792,\n" + + " C793,\n" + + " C794,\n" + + " C795,\n" + + " C796,\n" + + " C797,\n" + + " C798,\n" + + " C799,\n" + + " C800,\n" + + " C801,\n" + + " C802,\n" + + " C803,\n" + + " C804,\n" + + " C805,\n" + + " C806,\n" + + " C807,\n" + + " C808,\n" + + " C809,\n" + + " C810,\n" + + " C811,\n" + + " C812,\n" + + " C813,\n" + + " C814,\n" + + " C815,\n" + + " C816,\n" + + " C817,\n" + + " C818,\n" + + " C819,\n" + + " C820,\n" + + " C821,\n" + + " C822,\n" + + " C823,\n" + + " C824,\n" + + " C825,\n" + + " C826,\n" + + " C827,\n" + + " C828,\n" + + " C829,\n" + + " C830,\n" + + " C831,\n" + + " C832,\n" + + " C833,\n" + + " C834,\n" + + " C835,\n" + + " C836,\n" + + " C837,\n" + + " C838,\n" + + " C839,\n" + + " C840,\n" + + " C841,\n" + + " C842,\n" + + " C843,\n" + + " C844,\n" + + " C845,\n" + + " C846,\n" + + " C847,\n" + + " C848,\n" + + " C849,\n" + + " C850,\n" + + " C851,\n" + + " C852,\n" + + " C853,\n" + + " C854,\n" + + " C855,\n" + + " C856,\n" + + " C857,\n" + + " C858,\n" + + " C859,\n" + + " C860,\n" + + " C861,\n" + + " C862,\n" + + " C863,\n" + + " C864,\n" + + " C865,\n" + + " C866,\n" + + " C867,\n" + + " C868,\n" + + " C869,\n" + + " C870,\n" + + " C871,\n" + + " C872,\n" + + " C873,\n" + + " C874,\n" + + " C875,\n" + + " C876,\n" + + " C877,\n" + + " C878,\n" + + " C879,\n" + + " C880,\n" + + " C881,\n" + + " C882,\n" + + " C883,\n" + + " C884,\n" + + " C885,\n" + + " C886,\n" + + " C887,\n" + + " C888,\n" + + " C889,\n" + + " C890,\n" + + " C891,\n" + + " C892,\n" + + " C893,\n" + + " C894,\n" + + " C895,\n" + + " C896,\n" + + " C897,\n" + + " C898,\n" + + " C899,\n" + + " C900,\n" + + " C901,\n" + + " C902,\n" + + " C903,\n" + + " C904,\n" + + " C905,\n" + + " C906,\n" + + " C907,\n" + + " C908,\n" + + " C909,\n" + + " C910,\n" + + " C911,\n" + + " C912,\n" + + " C913,\n" + + " C914,\n" + + " C915,\n" + + " C916,\n" + + " C917,\n" + + " C918,\n" + + " C919,\n" + + " C920,\n" + + " C921,\n" + + " C922,\n" + + " C923,\n" + + " C924,\n" + + " C925,\n" + + " C926,\n" + + " C927,\n" + + " C928,\n" + + " C929,\n" + + " C930,\n" + + " C931,\n" + + " C932,\n" + + " C933,\n" + + " C934,\n" + + " C935,\n" + + " C936,\n" + + " C937,\n" + + " C938,\n" + + " C939,\n" + + " C940,\n" + + " C941,\n" + + " C942,\n" + + " C943,\n" + + " C944,\n" + + " C945,\n" + + " C946,\n" + + " C947,\n" + + " C948,\n" + + " C949,\n" + + " C950,\n" + + " C951,\n" + + " C952,\n" + + " C953,\n" + + " C954,\n" + + " C955,\n" + + " C956,\n" + + " C957,\n" + + " C958,\n" + + " C959,\n" + + " C960,\n" + + " C961,\n" + + " C962,\n" + + " C963,\n" + + " C964,\n" + + " C965,\n" + + " C966,\n" + + " C967,\n" + + " C968,\n" + + " C969,\n" + + " C970,\n" + + " C971,\n" + + " C972,\n" + + " C973,\n" + + " C974,\n" + + " C975,\n" + + " C976,\n" + + " C977,\n" + + " C978,\n" + + " C979,\n" + + " C980,\n" + + " C981,\n" + + " C982,\n" + + " C983,\n" + + " C984,\n" + + " C985,\n" + + " C986,\n" + + " C987,\n" + + " C988,\n" + + " C989,\n" + + " C990,\n" + + " C991,\n" + + " C992,\n" + + " C993,\n" + + " C994,\n" + + " C995,\n" + + " C996,\n" + + " C997,\n" + + " C998,\n" + + " C999,\n" + + " C1000,\n" + + " C1001,\n" + + " C1002,\n" + + " C1003,\n" + + " C1004,\n" + + " C1005,\n" + + " C1006,\n" + + " C1007,\n" + + " C1008,\n" + + " C1009,\n" + + " C1010,\n" + + " C1011,\n" + + " C1012,\n" + + " C1013,\n" + + " C1014,\n" + + " C1015,\n" + + " C1016,\n" + + " C1017,\n" + + " C1018,\n" + + " C1019,\n" + + " C1020,\n" + + " C1021,\n" + + " C1022,\n" + + " C1023,\n" + + " C1024,\n" + + " C1025,\n" + + " C1026,\n" + + " C1027,\n" + + " C1028,\n" + + " C1029,\n" + + " C1030,\n" + + " C1031,\n" + + " C1032,\n" + + " C1033,\n" + + " C1034,\n" + + " C1035,\n" + + " C1036,\n" + + " C1037,\n" + + " C1038,\n" + + " C1039,\n" + + " C1040,\n" + + " C1041,\n" + + " C1042,\n" + + " C1043,\n" + + " C1044,\n" + + " C1045,\n" + + " C1046,\n" + + " C1047,\n" + + " C1048,\n" + + " C1049,\n" + + " C1050,\n" + + " C1051,\n" + + " C1052,\n" + + " C1053,\n" + + " C1054,\n" + + " C1055,\n" + + " C1056,\n" + + " C1057,\n" + + " C1058,\n" + + " C1059,\n" + + " C1060,\n" + + " C1061,\n" + + " C1062,\n" + + " C1063,\n" + + " C1064,\n" + + " C1065,\n" + + " C1066,\n" + + " C1067,\n" + + " C1068,\n" + + " C1069,\n" + + " C1070,\n" + + " C1071,\n" + + " C1072,\n" + + " C1073,\n" + + " C1074,\n" + + " C1075,\n" + + " C1076,\n" + + " C1077,\n" + + " C1078,\n" + + " C1079,\n" + + " C1080,\n" + + " C1081,\n" + + " C1082,\n" + + " C1083,\n" + + " C1084,\n" + + " C1085,\n" + + " C1086,\n" + + " C1087,\n" + + " C1088,\n" + + " C1089,\n" + + " C1090,\n" + + " C1091,\n" + + " C1092,\n" + + " C1093,\n" + + " C1094,\n" + + " C1095,\n" + + " C1096,\n" + + " C1097,\n" + + " C1098,\n" + + " C1099,\n" + + " C1100,\n" + + " C1101,\n" + + " C1102,\n" + + " C1103,\n" + + " C1104,\n" + + " C1105,\n" + + " C1106,\n" + + " C1107,\n" + + " C1108,\n" + + " C1109,\n" + + " C1110,\n" + + " C1111,\n" + + " C1112,\n" + + " C1113,\n" + + " C1114,\n" + + " C1115,\n" + + " C1116,\n" + + " C1117,\n" + + " C1118,\n" + + " C1119,\n" + + " C1120,\n" + + " C1121,\n" + + " C1122,\n" + + " C1123,\n" + + " C1124,\n" + + " C1125,\n" + + " C1126,\n" + + " C1127,\n" + + " C1128,\n" + + " C1129,\n" + + " C1130,\n" + + " C1131,\n" + + " C1132,\n" + + " C1133,\n" + + " C1134,\n" + + " C1135,\n" + + " C1136,\n" + + " C1137,\n" + + " C1138,\n" + + " C1139,\n" + + " C1140,\n" + + " C1141,\n" + + " C1142,\n" + + " C1143,\n" + + " C1144,\n" + + " C1145,\n" + + " C1146,\n" + + " C1147,\n" + + " C1148,\n" + + " C1149,\n" + + " C1150,\n" + + " C1151,\n" + + " C1152,\n" + + " C1153,\n" + + " C1154,\n" + + " C1155,\n" + + " C1156,\n" + + " C1157,\n" + + " C1158,\n" + + " C1159,\n" + + " C1160,\n" + + " C1161,\n" + + " C1162,\n" + + " C1163,\n" + + " C1164,\n" + + " C1165,\n" + + " C1166,\n" + + " C1167,\n" + + " C1168,\n" + + " C1169,\n" + + " C1170,\n" + + " C1171,\n" + + " C1172,\n" + + " C1173,\n" + + " C1174,\n" + + " C1175,\n" + + " C1176,\n" + + " C1177,\n" + + " C1178,\n" + + " C1179,\n" + + " C1180,\n" + + " C1181,\n" + + " C1182,\n" + + " C1183,\n" + + " C1184,\n" + + " C1185,\n" + + " C1186,\n" + + " C1187,\n" + + " C1188,\n" + + " C1189,\n" + + " C1190,\n" + + " C1191,\n" + + " C1192,\n" + + " C1193,\n" + + " C1194,\n" + + " C1195,\n" + + " C1196,\n" + + " C1197,\n" + + " C1198,\n" + + " C1199,\n" + + " C1200,\n" + + " C1201,\n" + + " C1202,\n" + + " C1203,\n" + + " C1204,\n" + + " C1205,\n" + + " C1206,\n" + + " C1207,\n" + + " C1208,\n" + + " C1209,\n" + + " C1210,\n" + + " C1211,\n" + + " C1212,\n" + + " C1213,\n" + + " C1214,\n" + + " C1215,\n" + + " C1216,\n" + + " C1217,\n" + + " C1218,\n" + + " C1219,\n" + + " C1220,\n" + + " C1221,\n" + + " C1222,\n" + + " C1223,\n" + + " C1224,\n" + + " C1225,\n" + + " C1226,\n" + + " C1227,\n" + + " C1228,\n" + + " C1229,\n" + + " C1230,\n" + + " C1231,\n" + + " C1232,\n" + + " C1233,\n" + + " C1234,\n" + + " C1235,\n" + + " C1236,\n" + + " C1237,\n" + + " C1238,\n" + + " C1239,\n" + + " C1240,\n" + + " C1241,\n" + + " C1242,\n" + + " C1243,\n" + + " C1244,\n" + + " C1245,\n" + + " C1246,\n" + + " C1247,\n" + + " C1248,\n" + + " C1249,\n" + + " C1250,\n" + + " C1251,\n" + + " C1252,\n" + + " C1253,\n" + + " C1254,\n" + + " C1255,\n" + + " C1256,\n" + + " C1257,\n" + + " C1258,\n" + + " C1259,\n" + + " C1260,\n" + + " C1261,\n" + + " C1262,\n" + + " C1263,\n" + + " C1264,\n" + + " C1265,\n" + + " C1266,\n" + + " C1267,\n" + + " C1268,\n" + + " C1269,\n" + + " C1270,\n" + + " C1271,\n" + + " C1272,\n" + + " C1273,\n" + + " C1274,\n" + + " C1275,\n" + + " C1276,\n" + + " C1277,\n" + + " C1278,\n" + + " C1279,\n" + + " C1280,\n" + + " C1281,\n" + + " C1282,\n" + + " C1283,\n" + + " C1284,\n" + + " C1285,\n" + + " C1286,\n" + + " C1287,\n" + + " C1288,\n" + + " C1289,\n" + + " C1290,\n" + + " C1291,\n" + + " C1292,\n" + + " C1293,\n" + + " C1294,\n" + + " C1295,\n" + + " C1296,\n" + + " C1297,\n" + + " C1298,\n" + + " C1299,\n" + + " C1300,\n" + + " C1301,\n" + + " C1302,\n" + + " C1303,\n" + + " C1304,\n" + + " C1305,\n" + + " C1306,\n" + + " C1307,\n" + + " C1308,\n" + + " C1309,\n" + + " C1310,\n" + + " C1311,\n" + + " C1312,\n" + + " C1313,\n" + + " C1314,\n" + + " C1315,\n" + + " C1316,\n" + + " C1317,\n" + + " C1318,\n" + + " C1319,\n" + + " C1320,\n" + + " C1321,\n" + + " C1322,\n" + + " C1323,\n" + + " C1324,\n" + + " C1325,\n" + + " C1326,\n" + + " C1327,\n" + + " C1328,\n" + + " C1329,\n" + + " C1330,\n" + + " C1331,\n" + + " C1332,\n" + + " C1333,\n" + + " C1334,\n" + + " C1335,\n" + + " C1336,\n" + + " C1337,\n" + + " C1338,\n" + + " C1339,\n" + + " C1340,\n" + + " C1341,\n" + + " C1342,\n" + + " C1343,\n" + + " C1344,\n" + + " C1345,\n" + + " C1346,\n" + + " C1347,\n" + + " C1348,\n" + + " C1349,\n" + + " C1350,\n" + + " C1351,\n" + + " C1352,\n" + + " C1353,\n" + + " C1354,\n" + + " C1355,\n" + + " C1356,\n" + + " C1357,\n" + + " C1358,\n" + + " C1359,\n" + + " C1360,\n" + + " C1361,\n" + + " C1362,\n" + + " C1363,\n" + + " C1364,\n" + + " C1365,\n" + + " C1366,\n" + + " C1367,\n" + + " C1368,\n" + + " C1369,\n" + + " C1370,\n" + + " C1371,\n" + + " C1372,\n" + + " C1373,\n" + + " C1374,\n" + + " C1375,\n" + + " C1376,\n" + + " C1377,\n" + + " C1378,\n" + + " C1379,\n" + + " C1380,\n" + + " C1381,\n" + + " C1382,\n" + + " C1383,\n" + + " C1384,\n" + + " C1385,\n" + + " C1386,\n" + + " C1387,\n" + + " C1388,\n" + + " C1389,\n" + + " C1390,\n" + + " C1391,\n" + + " C1392,\n" + + " C1393,\n" + + " C1394,\n" + + " C1395,\n" + + " C1396,\n" + + " C1397,\n" + + " C1398,\n" + + " C1399,\n" + + " C1400,\n" + + " C1401,\n" + + " C1402,\n" + + " C1403,\n" + + " C1404,\n" + + " C1405,\n" + + " C1406,\n" + + " C1407,\n" + + " C1408,\n" + + " C1409,\n" + + " C1410,\n" + + " C1411,\n" + + " C1412,\n" + + " C1413,\n" + + " C1414,\n" + + " C1415,\n" + + " C1416,\n" + + " C1417,\n" + + " C1418,\n" + + " C1419,\n" + + " C1420,\n" + + " C1421,\n" + + " C1422,\n" + + " C1423,\n" + + " C1424,\n" + + " C1425,\n" + + " C1426,\n" + + " C1427,\n" + + " C1428,\n" + + " C1429,\n" + + " C1430,\n" + + " C1431,\n" + + " C1432,\n" + + " C1433,\n" + + " C1434,\n" + + " C1435,\n" + + " C1436,\n" + + " C1437,\n" + + " C1438,\n" + + " C1439,\n" + + " C1440,\n" + + " C1441,\n" + + " C1442,\n" + + " C1443,\n" + + " C1444,\n" + + " C1445,\n" + + " C1446,\n" + + " C1447,\n" + + " C1448,\n" + + " C1449,\n" + + " C1450,\n" + + " C1451,\n" + + " C1452,\n" + + " C1453,\n" + + " C1454,\n" + + " C1455,\n" + + " C1456,\n" + + " C1457,\n" + + " C1458,\n" + + " C1459,\n" + + " C1460,\n" + + " C1461,\n" + + " C1462,\n" + + " C1463,\n" + + " C1464,\n" + + " C1465,\n" + + " C1466,\n" + + " C1467,\n" + + " C1468,\n" + + " C1469,\n" + + " C1470,\n" + + " C1471,\n" + + " C1472,\n" + + " C1473,\n" + + " C1474,\n" + + " C1475,\n" + + " C1476,\n" + + " C1477,\n" + + " C1478,\n" + + " C1479,\n" + + " C1480,\n" + + " C1481,\n" + + " C1482,\n" + + " C1483,\n" + + " C1484,\n" + + " C1485,\n" + + " C1486,\n" + + " C1487,\n" + + " C1488,\n" + + " C1489,\n" + + " C1490,\n" + + " C1491,\n" + + " C1492,\n" + + " C1493,\n" + + " C1494,\n" + + " C1495,\n" + + " C1496,\n" + + " C1497,\n" + + " C1498,\n" + + " C1499,\n" + + " C1500,\n" + + " C1501,\n" + + " C1502,\n" + + " C1503,\n" + + " C1504,\n" + + " C1505,\n" + + " C1506,\n" + + " C1507,\n" + + " C1508,\n" + + " C1509,\n" + + " C1510,\n" + + " C1511,\n" + + " C1512,\n" + + " C1513,\n" + + " C1514,\n" + + " C1515,\n" + + " C1516,\n" + + " C1517,\n" + + " C1518,\n" + + " C1519,\n" + + " C1520,\n" + + " C1521,\n" + + " C1522,\n" + + " C1523,\n" + + " C1524,\n" + + " C1525,\n" + + " C1526,\n" + + " C1527,\n" + + " C1528,\n" + + " C1529,\n" + + " C1530,\n" + + " C1531,\n" + + " C1532,\n" + + " C1533,\n" + + " C1534,\n" + + " C1535,\n" + + " C1536,\n" + + " C1537,\n" + + " C1538,\n" + + " C1539,\n" + + " C1540,\n" + + " C1541,\n" + + " C1542,\n" + + " C1543,\n" + + " C1544,\n" + + " C1545,\n" + + " C1546,\n" + + " C1547,\n" + + " C1548,\n" + + " C1549,\n" + + " C1550,\n" + + " C1551,\n" + + " C1552,\n" + + " C1553,\n" + + " C1554,\n" + + " C1555,\n" + + " C1556,\n" + + " C1557,\n" + + " C1558,\n" + + " C1559,\n" + + " C1560,\n" + + " C1561,\n" + + " C1562,\n" + + " C1563,\n" + + " C1564,\n" + + " C1565,\n" + + " C1566,\n" + + " C1567,\n" + + " C1568,\n" + + " C1569,\n" + + " C1570,\n" + + " C1571,\n" + + " C1572,\n" + + " C1573,\n" + + " C1574,\n" + + " C1575,\n" + + " C1576,\n" + + " C1577,\n" + + " C1578,\n" + + " C1579,\n" + + " C1580,\n" + + " C1581,\n" + + " C1582,\n" + + " C1583,\n" + + " C1584,\n" + + " C1585,\n" + + " C1586,\n" + + " C1587,\n" + + " C1588,\n" + + " C1589,\n" + + " C1590,\n" + + " C1591,\n" + + " C1592,\n" + + " C1593,\n" + + " C1594,\n" + + " C1595,\n" + + " C1596,\n" + + " C1597,\n" + + " C1598,\n" + + " C1599,\n" + + " C1600,\n" + + " C1601,\n" + + " C1602,\n" + + " C1603,\n" + + " C1604,\n" + + " C1605,\n" + + " C1606,\n" + + " C1607,\n" + + " C1608,\n" + + " C1609,\n" + + " C1610,\n" + + " C1611,\n" + + " C1612,\n" + + " C1613,\n" + + " C1614,\n" + + " C1615,\n" + + " C1616,\n" + + " C1617,\n" + + " C1618,\n" + + " C1619,\n" + + " C1620,\n" + + " C1621,\n" + + " C1622,\n" + + " C1623,\n" + + " C1624,\n" + + " C1625,\n" + + " C1626,\n" + + " C1627,\n" + + " C1628,\n" + + " C1629,\n" + + " C1630,\n" + + " C1631,\n" + + " C1632,\n" + + " C1633,\n" + + " C1634,\n" + + " C1635,\n" + + " C1636,\n" + + " C1637,\n" + + " C1638,\n" + + " C1639,\n" + + " C1640,\n" + + " C1641,\n" + + " C1642,\n" + + " C1643,\n" + + " C1644,\n" + + " C1645,\n" + + " C1646,\n" + + " C1647,\n" + + " C1648,\n" + + " C1649,\n" + + " C1650,\n" + + " C1651,\n" + + " C1652,\n" + + " C1653,\n" + + " C1654,\n" + + " C1655,\n" + + " C1656,\n" + + " C1657,\n" + + " C1658,\n" + + " C1659,\n" + + " C1660,\n" + + " C1661,\n" + + " C1662,\n" + + " C1663,\n" + + " C1664,\n" + + " C1665,\n" + + " C1666,\n" + + " C1667,\n" + + " C1668,\n" + + " C1669,\n" + + " C1670,\n" + + " C1671,\n" + + " C1672,\n" + + " C1673,\n" + + " C1674,\n" + + " C1675,\n" + + " C1676,\n" + + " C1677,\n" + + " C1678,\n" + + " C1679,\n" + + " C1680,\n" + + " C1681,\n" + + " C1682,\n" + + " C1683,\n" + + " C1684,\n" + + " C1685,\n" + + " C1686,\n" + + " C1687,\n" + + " C1688,\n" + + " C1689,\n" + + " C1690,\n" + + " C1691,\n" + + " C1692,\n" + + " C1693,\n" + + " C1694,\n" + + " C1695,\n" + + " C1696,\n" + + " C1697,\n" + + " C1698,\n" + + " C1699,\n" + + " C1700,\n" + + " C1701,\n" + + " C1702,\n" + + " C1703,\n" + + " C1704,\n" + + " C1705,\n" + + " C1706,\n" + + " C1707,\n" + + " C1708,\n" + + " C1709,\n" + + " C1710,\n" + + " C1711,\n" + + " C1712,\n" + + " C1713,\n" + + " C1714,\n" + + " C1715,\n" + + " C1716,\n" + + " C1717,\n" + + " C1718,\n" + + " C1719,\n" + + " C1720,\n" + + " C1721,\n" + + " C1722,\n" + + " C1723,\n" + + " C1724,\n" + + " C1725,\n" + + " C1726,\n" + + " C1727,\n" + + " C1728,\n" + + " C1729,\n" + + " C1730,\n" + + " C1731,\n" + + " C1732,\n" + + " C1733,\n" + + " C1734,\n" + + " C1735,\n" + + " C1736,\n" + + " C1737,\n" + + " C1738,\n" + + " C1739,\n" + + " C1740,\n" + + " C1741,\n" + + " C1742,\n" + + " C1743,\n" + + " C1744,\n" + + " C1745,\n" + + " C1746,\n" + + " C1747,\n" + + " C1748,\n" + + " C1749,\n" + + " C1750,\n" + + " C1751,\n" + + " C1752,\n" + + " C1753,\n" + + " C1754,\n" + + " C1755,\n" + + " C1756,\n" + + " C1757,\n" + + " C1758,\n" + + " C1759,\n" + + " C1760,\n" + + " C1761,\n" + + " C1762,\n" + + " C1763,\n" + + " C1764,\n" + + " C1765,\n" + + " C1766,\n" + + " C1767,\n" + + " C1768,\n" + + " C1769,\n" + + " C1770,\n" + + " C1771,\n" + + " C1772,\n" + + " C1773,\n" + + " C1774,\n" + + " C1775,\n" + + " C1776,\n" + + " C1777,\n" + + " C1778,\n" + + " C1779,\n" + + " C1780,\n" + + " C1781,\n" + + " C1782,\n" + + " C1783,\n" + + " C1784,\n" + + " C1785,\n" + + " C1786,\n" + + " C1787,\n" + + " C1788,\n" + + " C1789,\n" + + " C1790,\n" + + " C1791,\n" + + " C1792,\n" + + " C1793,\n" + + " C1794,\n" + + " C1795,\n" + + " C1796,\n" + + " C1797,\n" + + " C1798,\n" + + " C1799,\n" + + " C1800,\n" + + " C1801,\n" + + " C1802,\n" + + " C1803,\n" + + " C1804,\n" + + " C1805,\n" + + " C1806,\n" + + " C1807,\n" + + " C1808,\n" + + " C1809,\n" + + " C1810,\n" + + " C1811,\n" + + " C1812,\n" + + " C1813,\n" + + " C1814,\n" + + " C1815,\n" + + " C1816,\n" + + " C1817,\n" + + " C1818,\n" + + " C1819,\n" + + " C1820,\n" + + " C1821,\n" + + " C1822,\n" + + " C1823,\n" + + " C1824,\n" + + " C1825,\n" + + " C1826,\n" + + " C1827,\n" + + " C1828,\n" + + " C1829,\n" + + " C1830,\n" + + " C1831,\n" + + " C1832,\n" + + " C1833,\n" + + " C1834,\n" + + " C1835,\n" + + " C1836,\n" + + " C1837,\n" + + " C1838,\n" + + " C1839,\n" + + " C1840,\n" + + " C1841,\n" + + " C1842,\n" + + " C1843,\n" + + " C1844,\n" + + " C1845,\n" + + " C1846,\n" + + " C1847,\n" + + " C1848,\n" + + " C1849,\n" + + " C1850,\n" + + " C1851,\n" + + " C1852,\n" + + " C1853,\n" + + " C1854,\n" + + " C1855,\n" + + " C1856,\n" + + " C1857,\n" + + " C1858,\n" + + " C1859,\n" + + " C1860,\n" + + " C1861,\n" + + " C1862,\n" + + " C1863,\n" + + " C1864,\n" + + " C1865,\n" + + " C1866,\n" + + " C1867,\n" + + " C1868,\n" + + " C1869,\n" + + " C1870,\n" + + " C1871,\n" + + " C1872,\n" + + " C1873,\n" + + " C1874,\n" + + " C1875,\n" + + " C1876,\n" + + " C1877,\n" + + " C1878,\n" + + " C1879,\n" + + " C1880,\n" + + " C1881,\n" + + " C1882,\n" + + " C1883,\n" + + " C1884,\n" + + " C1885,\n" + + " C1886,\n" + + " C1887,\n" + + " C1888,\n" + + " C1889,\n" + + " C1890,\n" + + " C1891,\n" + + " C1892,\n" + + " C1893,\n" + + " C1894,\n" + + " C1895,\n" + + " C1896,\n" + + " C1897,\n" + + " C1898,\n" + + " C1899,\n" + + " C1900,\n" + + " C1901,\n" + + " C1902,\n" + + " C1903,\n" + + " C1904,\n" + + " C1905,\n" + + " C1906,\n" + + " C1907,\n" + + " C1908,\n" + + " C1909,\n" + + " C1910,\n" + + " C1911,\n" + + " C1912,\n" + + " C1913,\n" + + " C1914,\n" + + " C1915,\n" + + " C1916,\n" + + " C1917,\n" + + " C1918,\n" + + " C1919,\n" + + " C1920,\n" + + " C1921,\n" + + " C1922,\n" + + " C1923,\n" + + " C1924,\n" + + " C1925,\n" + + " C1926,\n" + + " C1927,\n" + + " C1928,\n" + + " C1929,\n" + + " C1930,\n" + + " C1931,\n" + + " C1932,\n" + + " C1933,\n" + + " C1934,\n" + + " C1935,\n" + + " C1936,\n" + + " C1937,\n" + + " C1938,\n" + + " C1939,\n" + + " C1940,\n" + + " C1941,\n" + + " C1942,\n" + + " C1943,\n" + + " C1944,\n" + + " C1945,\n" + + " C1946,\n" + + " C1947,\n" + + " C1948,\n" + + " C1949,\n" + + " C1950,\n" + + " C1951,\n" + + " C1952,\n" + + " C1953,\n" + + " C1954,\n" + + " C1955,\n" + + " C1956,\n" + + " C1957,\n" + + " C1958,\n" + + " C1959,\n" + + " C1960,\n" + + " C1961,\n" + + " C1962,\n" + + " C1963,\n" + + " C1964,\n" + + " C1965,\n" + + " C1966,\n" + + " C1967,\n" + + " C1968,\n" + + " C1969,\n" + + " C1970,\n" + + " C1971,\n" + + " C1972,\n" + + " C1973,\n" + + " C1974,\n" + + " C1975,\n" + + " C1976,\n" + + " C1977,\n" + + " C1978,\n" + + " C1979,\n" + + " C1980,\n" + + " C1981,\n" + + " C1982,\n" + + " C1983,\n" + + " C1984,\n" + + " C1985,\n" + + " C1986,\n" + + " C1987,\n" + + " C1988,\n" + + " C1989,\n" + + " C1990,\n" + + " C1991,\n" + + " C1992,\n" + + " C1993,\n" + + " C1994,\n" + + " C1995,\n" + + " C1996,\n" + + " C1997,\n" + + " C1998,\n" + + " C1999,\n" + + " C2000,\n" + + " C2001,\n" + + " C2002,\n" + + " C2003,\n" + + " C2004\n" + + " ;\n" + + " \n" + + " private static Map nameToInstanceMap = new HashMap();\n" + + "\n" + + " static {\n" + + " for (X b : values()) {\n" + + " nameToInstanceMap.put(b.name(), b);\n" + + " }\n" + + " }\n" + + "\n" + + " public static X fromName(String n) {\n" + + " X b = nameToInstanceMap.get(n);\n" + + "\n" + + " return b;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " System.out.println(fromName(\"C0\"));\n" + + " }\n" + + "}" + }, + "C0"); +} +public void testBug519070() { + int N = 1000; + StringBuilder sourceCode = new StringBuilder( + "public class X {\n" + + " public static void main(String[] args) {\n" + + " System.out.println(\"SUCCESS\");\n" + + " }\n"); + for (int m = 0; m < N; m++) { + sourceCode.append("\tvoid test"+m+"() {\n"); + for (int i = 0; i < N; i++) + sourceCode.append("\t\tSystem.out.println(\"xyz\");\n"); + sourceCode.append("\t}\n"); + } + sourceCode.append("}\n"); + + this.runConformTest( + new String[] { + "X.java", + sourceCode.toString() + }, + "SUCCESS"); +} +public static Class testClass() { + return XLargeTest.class; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest2.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest2.java new file mode 100644 index 0000000000..49a9c058dc --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/XLargeTest2.java @@ -0,0 +1,425 @@ +/******************************************************************************* + * Copyright (c) 2018, 2020 Andrey Loskutov and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Andrey Loskutov - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.compiler.regression; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; + +import junit.framework.Test; + +public class XLargeTest2 extends AbstractRegressionTest { + static { +// TESTS_NAMES = new String[] { "testBug550063" }; + } + + public XLargeTest2(String name) { + super(name); + } + + public static Test suite() { + return buildMinimalComplianceTestSuite(testClass(), F_1_5); + } + + public static Class testClass() { + return XLargeTest2.class; + } + + /** + * Check if we hit the 64Kb limit on generated table switch method code in + * class files. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=542084 + */ + public void testBug542084_error() { + + int enumsCount = getEnumsCountForError(); + StringBuilder lotOfEnums = new StringBuilder(enumsCount * 7); + for (int i = 0; i < enumsCount; i++) { + lotOfEnums.append("A").append(i).append(", "); + } + + String expectedCompilerLog; + if (this.complianceLevel > ClassFileConstants.JDK1_8) { + expectedCompilerLog = + "1. ERROR in X.java (at line 2)\n" + + " enum Y {\n" + + " ^\n" + + "The code for the static initializer is exceeding the 65535 bytes limit\n"; + } else { + expectedCompilerLog = + "1. ERROR in X.java (at line 6)\n" + + " switch(y){\n" + + " case A0:\n" + + " System.out.println(\"a\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"default\");\n" + + " break;\n" + + " }\n" + + " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + + "The code for the switch table on enum X.Y is exceeding the 65535 bytes limit\n"; + } + runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " enum Y {\n" + + lotOfEnums.toString() + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y y = X.Y.A0;\n" + + " switch(y){\n" + // Reported error should be here + " case A0:\n" + + " System.out.println(\"a\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"default\");\n" + + " break;\n" + + " }\n" + + " }\n" + + " public void z2(Y y) {\n" + // Should not report error on second switch + " switch(y){\n" + + " case A0:\n" + + " System.out.println(\"a\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"default\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}" + }, + "----------\n" + + expectedCompilerLog + + "----------\n"); + } + + /** + * Check if we don't hit the 64Kb limit on generated table switch method code in + * class files. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=542084 + */ + public void testBug542084_no_error() { + int enumsCount = getEnumsCountForSuccess(); + StringBuilder lotOfEnums = new StringBuilder(enumsCount * 7); + for (int i = 0; i < enumsCount; i++) { + lotOfEnums.append("A").append(i).append(", "); + } + + // Javac can't compile such big enums + runConformTest( + true, + JavacTestOptions.SKIP, + new String[] { + "X.java", + "public class X {\n" + + " enum Y {\n" + + lotOfEnums.toString() + + " }\n" + + " public static void main(String[] args) {\n" + + " X.Y y = X.Y.A0;\n" + + " switch(y){\n" + + " case A0:\n" + + " System.out.println(\"SUCCESS\");\n" + + " break;\n" + + " default:\n" + + " System.out.println(\"default\");\n" + + " break;\n" + + " }\n" + + " }\n" + + "}" + }, + "SUCCESS"); + } + + /** + * @return Generated code for enums that exceeds the limit + */ + private int getEnumsCountForError() { + if(this.complianceLevel > ClassFileConstants.JDK1_8) { + return 2800; + } + return 4500; + } + + /** + * @return Generated code for enums that does not exceeds the limit + */ + private int getEnumsCountForSuccess() { + if(this.complianceLevel > ClassFileConstants.JDK1_8) { + return 2300; + } + return 4300; + } + + public void testBug550063() { + runConformTest( + new String[] { + "p001/bip.java", + "package p001;\n" + + "\n" + + getManyInterfaceDeclarations() + + "\n" + + "class bip implements brj, brk, cem, cen, cey, cez, cfk, cfl, cgu, cgx, che, chh, chq, chr, cji, cjj, ckk, ckl, clb, clc, clf, cli, cnk,\n" + + " cnl, cok, cqa, cqd, cqw, cqx, crs, crv, csu, csv, ctq, ctt, cvg, cvj, cvo, cvp, cwk, cwn, cwu, cww, cxh, cxk, daz, dba, dbr, dbu, dck,\n" + + " dcl, deh, dei, dep, deq, dff, dfg, dfl, dfo, dsp, dss, dtp, dtq, dtt, dtw, duj, duk, dvm, dvp, dvs, dvv, dwe, dwh, dxd, dxg, dyq, dys,\n" + + " dyv, dyw, dzh, dzk, dzn, dzo, dzx, eaa, ecw, ecx, edr, eds, efc, efd, eiw, eiz, ejy, ekb, emi, eml, eor, eou, epe, eph, epk, epl, eqi,\n" + + " eqj, erv, erw, etd, etg, etm, eto, fbc, fbd, feu, fev, ffc, fff, fgf, fgh, fgo, fgp, fhm, fhn, fib, fki, fkj, fkw, fkx, fmh, fmk, fnk,\n" + + " fnl, fnz, foc, fof, foi, fvk, fvn, fvv, fvw, fwy, fxb, fyb, fye, fyl, fym, fyv, fyy, fzq, fzs, gad, gag, gaq, gas, gav, gax, gbc, gbd,\n" + + " gco, gcr, gdc, gdf, gdn, gdq, gei, gej, gih, gik, gku, gkx, gln, glo, gmi, gmj, gmu, gmv, gpx, gpy, gqb, gqe, gqp, gqs, grb, grc, grh,\n" + + " gri, grn, gro, grv, grw, gtr, gtu, gxc, gvt, gvw, gwz {\n" + + "}\n" + }); + } + + public void testBug550063_b() { + runNegativeTest( + new String[] { + "p001/bip.java", + "package p001;\n" + + "\n" + + getManyInterfaceDeclarations() + + "\n" + + "class bop implements missing,\n" + + " brj, brk, cem, cen, cey, cez, cfk, cfl, cgu, cgx, che, chh, chq, chr, cji, cjj, ckk, ckl, clb, clc, clf, cli, cnk,\n" + + " cnl, cok, cqa, cqd, cqw, cqx, crs, crv, csu, csv, ctq, ctt, cvg, cvj, cvo, cvp, cwk, cwn, cwu, cww, cxh, cxk, daz, dba, dbr, dbu, dck,\n" + + " dcl, deh, dei, dep, deq, dff, dfg, dfl, dfo, dsp, dss, dtp, dtq, dtt, dtw, duj, duk, dvm, dvp, dvs, dvv, dwe, dwh, dxd, dxg, dyq, dys,\n" + + " dyv, dyw, dzh, dzk, dzn, dzo, dzx, eaa, ecw, ecx, edr, eds, efc, efd, eiw, eiz, ejy, ekb, emi, eml, eor, eou, epe, eph, epk, epl, eqi,\n" + + " eqj, erv, erw, etd, etg, etm, eto, fbc, fbd, feu, fev, ffc, fff, fgf, fgh, fgo, fgp, fhm, fhn, fib, fki, fkj, fkw, fkx, fmh, fmk, fnk,\n" + + " fnl, fnz, foc, fof, foi, fvk, fvn, fvv, fvw, fwy, fxb, fyb, fye, fyl, fym, fyv, fyy, fzq, fzs, gad, gag, gaq, gas, gav, gax, gbc, gbd,\n" + + " gco, gcr, gdc, gdf, gdn, gdq, gei, gej, gih, gik, gku, gkx, gln, glo, gmi, gmj, gmu, gmv, gpx, gpy, gqb, gqe, gqp, gqs, grb, grc, grh,\n" + + " gri, grn, gro, grv, grw, gtr, gtu, gxc, gvt, gvw, gwz {\n" + + "}\n" + }, + "----------\n" + + "1. ERROR in p001\\bip.java (at line 200)\n" + + " class bop implements missing,\n" + + " ^^^^^^^\n" + + "missing cannot be resolved to a type\n" + + "----------\n"); + } + + private String getManyInterfaceDeclarations() { + return "interface brj {}\n" + + "interface brk {}\n" + + "interface cem {}\n" + + "interface cen {}\n" + + "interface cey {}\n" + + "interface cez {}\n" + + "interface cfk {}\n" + + "interface cfl {}\n" + + "interface cgu {}\n" + + "interface cgx {}\n" + + "interface che {}\n" + + "interface chh {}\n" + + "interface chq {}\n" + + "interface chr {}\n" + + "interface cji {}\n" + + "interface cjj {}\n" + + "interface ckk {}\n" + + "interface ckl {}\n" + + "interface clb {}\n" + + "interface clc {}\n" + + "interface clf {}\n" + + "interface cli {}\n" + + "interface cnk {}\n" + + "interface cnl {}\n" + + "interface cok {}\n" + + "interface cqa {}\n" + + "interface cqd {}\n" + + "interface cqw {}\n" + + "interface cqx {}\n" + + "interface crs {}\n" + + "interface crv {}\n" + + "interface csu {}\n" + + "interface csv {}\n" + + "interface ctq {}\n" + + "interface ctt {}\n" + + "interface cvg {}\n" + + "interface cvj {}\n" + + "interface cvo {}\n" + + "interface cvp {}\n" + + "interface cwk {}\n" + + "interface cwn {}\n" + + "interface cwu {}\n" + + "interface cww {}\n" + + "interface cxh {}\n" + + "interface cxk {}\n" + + "interface daz {}\n" + + "interface dba {}\n" + + "interface dbr {}\n" + + "interface dbu {}\n" + + "interface dck {}\n" + + "interface dcl {}\n" + + "interface deh {}\n" + + "interface dei {}\n" + + "interface dep {}\n" + + "interface deq {}\n" + + "interface dff {}\n" + + "interface dfg {}\n" + + "interface dfl {}\n" + + "interface dfo {}\n" + + "interface dsp {}\n" + + "interface dss {}\n" + + "interface dtp {}\n" + + "interface dtq {}\n" + + "interface dtt {}\n" + + "interface dtw {}\n" + + "interface duj {}\n" + + "interface duk {}\n" + + "interface dvm {}\n" + + "interface dvp {}\n" + + "interface dvs {}\n" + + "interface dvv {}\n" + + "interface dwe {}\n" + + "interface dwh {}\n" + + "interface dxd {}\n" + + "interface dxg {}\n" + + "interface dyq {}\n" + + "interface dys {}\n" + + "interface dyv {}\n" + + "interface dyw {}\n" + + "interface dzh {}\n" + + "interface dzk {}\n" + + "interface dzn {}\n" + + "interface dzo {}\n" + + "interface dzx {}\n" + + "interface eaa {}\n" + + "interface ecw {}\n" + + "interface ecx {}\n" + + "interface edr {}\n" + + "interface eds {}\n" + + "interface efc {}\n" + + "interface efd {}\n" + + "interface eiw {}\n" + + "interface eiz {}\n" + + "interface ejy {}\n" + + "interface ekb {}\n" + + "interface emi {}\n" + + "interface eml {}\n" + + "interface eor {}\n" + + "interface eou {}\n" + + "interface epe {}\n" + + "interface eph {}\n" + + "interface epk {}\n" + + "interface epl {}\n" + + "interface eqi {}\n" + + "interface eqj {}\n" + + "interface erv {}\n" + + "interface erw {}\n" + + "interface etd {}\n" + + "interface etg {}\n" + + "interface etm {}\n" + + "interface eto {}\n" + + "interface fbc {}\n" + + "interface fbd {}\n" + + "interface feu {}\n" + + "interface fev {}\n" + + "interface ffc {}\n" + + "interface fff {}\n" + + "interface fgf {}\n" + + "interface fgh {}\n" + + "interface fgo {}\n" + + "interface fgp {}\n" + + "interface fhm {}\n" + + "interface fhn {}\n" + + "interface fib {}\n" + + "interface fki {}\n" + + "interface fkj {}\n" + + "interface fkw {}\n" + + "interface fkx {}\n" + + "interface fmh {}\n" + + "interface fmk {}\n" + + "interface fnk {}\n" + + "interface fnl {}\n" + + "interface fnz {}\n" + + "interface foc {}\n" + + "interface fof {}\n" + + "interface foi {}\n" + + "interface fvk {}\n" + + "interface fvn {}\n" + + "interface fvv {}\n" + + "interface fvw {}\n" + + "interface fwy {}\n" + + "interface fxb {}\n" + + "interface fyb {}\n" + + "interface fye {}\n" + + "interface fyl {}\n" + + "interface fym {}\n" + + "interface fyv {}\n" + + "interface fyy {}\n" + + "interface fzq {}\n" + + "interface fzs {}\n" + + "interface gad {}\n" + + "interface gag {}\n" + + "interface gaq {}\n" + + "interface gas {}\n" + + "interface gav {}\n" + + "interface gax {}\n" + + "interface gbc {}\n" + + "interface gbd {}\n" + + "interface gco {}\n" + + "interface gcr {}\n" + + "interface gdc {}\n" + + "interface gdf {}\n" + + "interface gdn {}\n" + + "interface gdq {}\n" + + "interface gei {}\n" + + "interface gej {}\n" + + "interface gih {}\n" + + "interface gik {}\n" + + "interface gku {}\n" + + "interface gkx {}\n" + + "interface gln {}\n" + + "interface glo {}\n" + + "interface gmi {}\n" + + "interface gmj {}\n" + + "interface gmu {}\n" + + "interface gmv {}\n" + + "interface gpx {}\n" + + "interface gpy {}\n" + + "interface gqb {}\n" + + "interface gqe {}\n" + + "interface gqp {}\n" + + "interface gqs {}\n" + + "interface grb {}\n" + + "interface grc {}\n" + + "interface grh {}\n" + + "interface gri {}\n" + + "interface grn {}\n" + + "interface gro {}\n" + + "interface grv {}\n" + + "interface grw {}\n" + + "interface gtr {}\n" + + "interface gtu {}\n" + + "interface gvt {}\n" + + "interface gvw {}\n" + + "interface gwz {}\n" + + "interface gxc {}\n"; + } + public void testBug550480() { + StringBuilder source = new StringBuilder(); + source.append("package p;\n"); + String[] names = new String[571]; + for (int i = 0; i < 571; i++) { + names[i] = "I"+i; + source.append("interface ").append(names[i]).append(" {}\n"); + } + source.append("public abstract class hft implements "); + source.append(String.join(", ", names)); + source.append("\n{\n}\n"); + runConformTest( + new String[] { + "p/hft.java", + source.toString() + }); + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java new file mode 100644 index 0000000000..3401e5dfd9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/dom/StandAloneASTParserTest.java @@ -0,0 +1,1884 @@ +/******************************************************************************* + * Copyright (c) 2010, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 461250 - ArrayIndexOutOfBoundsException in SourceTypeBinding.fields + * Carmi Grushko - Bug 465048 - Binding is null for class literals in synchronized blocks + *******************************************************************************/ +package org.eclipse.jdt.core.tests.dom; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.Writer; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.core.dom.AST; +import org.eclipse.jdt.core.dom.ASTNode; +import org.eclipse.jdt.core.dom.ASTParser; +import org.eclipse.jdt.core.dom.Block; +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jdt.core.dom.Expression; +import org.eclipse.jdt.core.dom.ExpressionStatement; +import org.eclipse.jdt.core.dom.FieldDeclaration; +import org.eclipse.jdt.core.dom.FileASTRequestor; +import org.eclipse.jdt.core.dom.IBinding; +import org.eclipse.jdt.core.dom.IMethodBinding; +import org.eclipse.jdt.core.dom.IPackageBinding; +import org.eclipse.jdt.core.dom.ITypeBinding; +import org.eclipse.jdt.core.dom.IVariableBinding; +import org.eclipse.jdt.core.dom.MethodDeclaration; +import org.eclipse.jdt.core.dom.MethodInvocation; +import org.eclipse.jdt.core.dom.ModuleDeclaration; +import org.eclipse.jdt.core.dom.Name; +import org.eclipse.jdt.core.dom.NodeFinder; +import org.eclipse.jdt.core.dom.SimpleName; +import org.eclipse.jdt.core.dom.SimpleType; +import org.eclipse.jdt.core.dom.SwitchExpression; +import org.eclipse.jdt.core.dom.Type; +import org.eclipse.jdt.core.dom.TypeDeclaration; +import org.eclipse.jdt.core.dom.VariableDeclarationFragment; +import org.eclipse.jdt.core.dom.VariableDeclarationStatement; +import org.eclipse.jdt.core.dom.YieldStatement; +import org.eclipse.jdt.core.tests.compiler.regression.AbstractRegressionTest; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +@SuppressWarnings({ "rawtypes" }) +public class StandAloneASTParserTest extends AbstractRegressionTest { + public StandAloneASTParserTest(String name) { + super(name); + } + + private static final int AST_JLS_LATEST = AST.getJLSLatest(); + + public ASTNode runConversion( + int astLevel, + String source, + boolean resolveBindings, + boolean statementsRecovery, + boolean bindingsRecovery, + String unitName) { + + ASTParser parser = ASTParser.newParser(astLevel); + parser.setSource(source.toCharArray()); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(resolveBindings); + parser.setStatementsRecovery(statementsRecovery); + parser.setBindingsRecovery(bindingsRecovery); + parser.setCompilerOptions(getCompilerOptions()); + parser.setUnitName(unitName); + return parser.createAST(null); + } + protected File createFile(File dir, String fileName, String contents) throws IOException { + File file = new File(dir, fileName); + try (Writer writer = new BufferedWriter(new FileWriter(file))) { + writer.write(contents); + } + return file; + } + public void testBug529654_001() { + String contents = + "module m {\n" + + "}"; + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setSource(contents.toCharArray()); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setUnitName("module-info.java"); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_9); + options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_9); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_9); + parser.setCompilerOptions(options); + + ASTNode node = parser.createAST(null); + assertTrue("Should be a compilation unit", node instanceof CompilationUnit); + CompilationUnit unit = (CompilationUnit) node; + ModuleDeclaration module = unit.getModule(); + assertTrue("Incorrect Module Name", module.getName().getFullyQualifiedName().equals("m")); + } + public void test1() { + String contents = + "package p;\n" + + "public class X {\n" + + " public int i;\n" + + " public static void main(String[] args) {\n" + + " int length = args.length;\n" + + " System.out.println(length);\n" + + " }\n" + + "}"; + ASTNode node = runConversion(AST_JLS_LATEST, contents, true, true, true, "p/X.java"); + assertTrue("Should be a compilation unit", node instanceof CompilationUnit); + CompilationUnit unit = (CompilationUnit) node; + List types = unit.types(); + TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0); + ITypeBinding binding = typeDeclaration.resolveBinding(); + assertNotNull("No binding", binding); + assertNull("Got a java element", binding.getJavaElement()); + assertEquals("Wrong name", "p.X", binding.getQualifiedName()); + MethodDeclaration methodDeclaration = (MethodDeclaration) typeDeclaration.bodyDeclarations().get(1); + IMethodBinding methodBinding = methodDeclaration.resolveBinding(); + assertNotNull("No binding", methodBinding); + assertNull("Got a java element", methodBinding.getJavaElement()); + Block body = methodDeclaration.getBody(); + VariableDeclarationStatement statement = (VariableDeclarationStatement) body.statements().get(0); + VariableDeclarationFragment fragment = (VariableDeclarationFragment) statement.fragments().get(0); + IVariableBinding variableBinding = fragment.resolveBinding(); + assertNotNull("No binding", variableBinding); + assertNull("Got a java element", variableBinding.getJavaElement()); + ExpressionStatement statement2 = (ExpressionStatement) body.statements().get(1); + Expression expression = statement2.getExpression(); + MethodInvocation invocation = (MethodInvocation) expression; + Expression expression2 = invocation.getExpression(); + assertNotNull("No binding", expression2.resolveTypeBinding()); + + FieldDeclaration fieldDeclaration = (FieldDeclaration) typeDeclaration.bodyDeclarations().get(0); + VariableDeclarationFragment fragment2 = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0); + IVariableBinding variableBinding2 = fragment2.resolveBinding(); + assertNotNull("No binding", variableBinding2); + assertNull("Got a java element", variableBinding2.getJavaElement()); + } + + public void test2() { + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setCompilerOptions(getCompilerOptions()); + + final String key = "Ljava/lang/String;"; + final IBinding[] bindings = new IBinding[1]; + + FileASTRequestor requestor = new FileASTRequestor() { + public void acceptBinding(String bindingKey, IBinding binding) { + if (key.equals(bindingKey)) { + bindings[0] = binding; + } + } + }; + + parser.createASTs(new String[] {}, null, new String[] {key}, requestor, null); + + assertNotNull("No binding", bindings[0]); + assertEquals("Wrong type of binding", IBinding.TYPE, bindings[0].getKind()); + ITypeBinding typeBinding = (ITypeBinding) bindings[0]; + assertEquals("Wrong binding", "java.lang.String", typeBinding.getQualifiedName()); + assertNull("No java element", typeBinding.getJavaElement()); + } + + public void test3() throws IOException { + File rootDir = new File(System.getProperty("java.io.tmpdir")); + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setCompilerOptions(getCompilerOptions()); + + final String key = "Lp/X;"; + final IBinding[] bindings = new IBinding[1]; + + String contents = + "package p;\n" + + "public class X extends Y {\n" + + " public int i;\n" + + " public static void main(String[] args) {\n" + + " int length = args.length;\n" + + " System.out.println(length);\n" + + " }\n" + + "}"; + + File packageDir = new File(rootDir, "p"); + packageDir.mkdir(); + File file = new File(packageDir, "X.java"); + Writer writer = null; + try { + writer = new BufferedWriter(new FileWriter(file)); + writer.write(contents); + } finally { + if (writer != null) { + try { + writer.close(); + } catch(IOException e) { + // ignore + } + } + } + + String contents2 = + "package p;\n" + + "public class Y {}"; + File fileY = new File(packageDir, "Y.java"); + Writer writer2 = null; + try { + writer2 = new BufferedWriter(new FileWriter(fileY)); + writer2.write(contents2); + } finally { + if (writer2 != null) { + try { + writer2.close(); + } catch(IOException e) { + // ignore + } + } + } + + try { + final String canonicalPath = file.getCanonicalPath(); + final CompilationUnit[] units = new CompilationUnit[1]; + + FileASTRequestor requestor = new FileASTRequestor() { + public void acceptBinding(String bindingKey, IBinding binding) { + if (key.equals(bindingKey)) { + bindings[0] = binding; + } + } + public void acceptAST(String sourceFilePath, CompilationUnit ast) { + if (canonicalPath.equals(sourceFilePath)) { + units[0] = ast; + } + } + }; + + parser.setEnvironment(null, new String[] { rootDir.getCanonicalPath() }, null, true); + + parser.createASTs(new String[] {canonicalPath}, null, new String[] {key}, requestor, null); + + assertNotNull("No binding", bindings[0]); + assertEquals("Wrong type of binding", IBinding.TYPE, bindings[0].getKind()); + ITypeBinding typeBinding = (ITypeBinding) bindings[0]; + assertEquals("Wrong binding", "p.X", typeBinding.getQualifiedName()); + assertNull("No java element", typeBinding.getJavaElement()); + assertNotNull("No ast", units[0]); + assertEquals("No problem", 0, units[0].getProblems().length); + } finally { + file.delete(); + fileY.delete(); + } + } + + public void test4() { + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + try { + parser.setEnvironment(null, null, new String[] {"UTF-8"}, true); + assertTrue("Should have failed", false); + } catch(IllegalArgumentException e) { + // ignore + } + } + + public void test5() { + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + try { + parser.setEnvironment(null, new String[] {}, new String[] {"UTF-8"}, true); + assertTrue("Should have failed", false); + } catch(IllegalArgumentException e) { + // ignore + } + } + + public void test6() throws IOException { + File rootDir = new File(System.getProperty("java.io.tmpdir")); + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setCompilerOptions(getCompilerOptions()); + + final String key = "Lp/X;"; + final IBinding[] bindings = new IBinding[2]; + + String contents = + "package p;\n" + + "public class X extends Y {\n" + + " public int i;\n" + + " public static void main(String[] args) {\n" + + " int length = args.length;\n" + + " System.out.println(length);\n" + + " }\n" + + "}"; + + File packageDir = new File(rootDir, "p"); + packageDir.mkdir(); + File file = new File(packageDir, "X.java"); + Writer writer = null; + try { + writer = new BufferedWriter(new FileWriter(file)); + writer.write(contents); + } finally { + if (writer != null) { + try { + writer.close(); + } catch(IOException e) { + // ignore + } + } + } + + String contents2 = + "package p;\n" + + "public class Y {}"; + File fileY = new File(packageDir, "Y.java"); + Writer writer2 = null; + try { + writer2 = new BufferedWriter(new FileWriter(fileY)); + writer2.write(contents2); + } finally { + if (writer2 != null) { + try { + writer2.close(); + } catch(IOException e) { + // ignore + } + } + } + + try { + final String canonicalPath = file.getCanonicalPath(); + final CompilationUnit[] units = new CompilationUnit[1]; + + FileASTRequestor requestor = new FileASTRequestor() { + public void acceptBinding(String bindingKey, IBinding binding) { + if (key.equals(bindingKey)) { + bindings[0] = binding; + IBinding[] temp = createBindings(new String[] {"Ljava/lang/Object;"}); + for (int i = 0; i < temp.length; ++i) { + bindings[i + 1] = temp[i]; + } + } + } + public void acceptAST(String sourceFilePath, CompilationUnit ast) { + if (canonicalPath.equals(sourceFilePath)) { + units[0] = ast; + } + } + }; + + parser.setEnvironment(null, new String[] { rootDir.getCanonicalPath() }, null, true); + + parser.createASTs(new String[] {canonicalPath}, null, new String[] {key}, requestor, null); + + assertNotNull("No binding", bindings[0]); + assertEquals("Wrong type of binding", IBinding.TYPE, bindings[0].getKind()); + ITypeBinding typeBinding = (ITypeBinding) bindings[0]; + assertEquals("Wrong binding", "p.X", typeBinding.getQualifiedName()); + assertNull("No java element", typeBinding.getJavaElement()); + IPackageBinding packageBinding = typeBinding.getPackage(); + assertNull("No java element", packageBinding.getJavaElement()); + assertNotNull("No ast", units[0]); + assertEquals("No problem", 0, units[0].getProblems().length); + assertNotNull("No binding", bindings[1]); + assertEquals("Wrong type of binding", IBinding.TYPE, bindings[1].getKind()); + typeBinding = (ITypeBinding) bindings[1]; + assertEquals("Wrong binding", "java.lang.Object", typeBinding.getQualifiedName()); + } finally { + file.delete(); + fileY.delete(); + } + } + + /** + * @deprecated + * @throws IOException + */ + public void testBug415066_001() throws IOException { + File rootDir = new File(System.getProperty("java.io.tmpdir")); + ASTParser parser = ASTParser.newParser(AST.JLS4); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setCompilerOptions(getCompilerOptions()); + + final String key = "Lp/C;"; + final IBinding[] bindings = new IBinding[2]; + + String contents = + "package p;\n" + + "public class A{}\n" + + "class B{}"; + + File packageDir = new File(rootDir, "p"); + packageDir.mkdir(); + File file = new File(packageDir, "A.java"); + Writer writer = null; + try { + writer = new BufferedWriter(new FileWriter(file)); + writer.write(contents); + } finally { + if (writer != null) { + try { + writer.close(); + } catch(IOException e) { + // ignore + } + } + } + + String contents2 = + "package p;\n" + + "public class C extends B {}"; + File fileY = new File(packageDir, "C.java"); + Writer writer2 = null; + try { + writer2 = new BufferedWriter(new FileWriter(fileY)); + writer2.write(contents2); + } finally { + if (writer2 != null) { + try { + writer2.close(); + } catch(IOException e) { + // ignore + } + } + } + + try { + final String canonicalPath = fileY.getCanonicalPath(); + final CompilationUnit[] units = new CompilationUnit[1]; + + FileASTRequestor requestor = new FileASTRequestor() { + public void acceptBinding(String bindingKey, IBinding binding) { + if (key.equals(bindingKey)) { + bindings[0] = binding; + IBinding[] temp = createBindings(new String[] {"Lp/C;"}); + for (int i = 0; i < temp.length; ++i) { + bindings[i + 1] = temp[i]; + } + } + } + public void acceptAST(String sourceFilePath, CompilationUnit ast) { + if (canonicalPath.equals(sourceFilePath)) { + units[0] = ast; + } + } + }; + + parser.setEnvironment(null, new String[] { rootDir.getCanonicalPath() }, null, true); + org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.MAX_AT_ONCE = 0; + parser.createASTs(new String[] {canonicalPath}, null, new String[] {key}, requestor, null); + assertNotNull("No ast", units[0]); + assertEquals("No problem", 0, units[0].getProblems().length); + } finally { + file.delete(); + fileY.delete(); + } + } + + /** + * Negative test case + * @deprecated + * @throws IOException + */ + public void testBug415066_002() throws IOException { + File rootDir = new File(System.getProperty("java.io.tmpdir")); + ASTParser parser = ASTParser.newParser(AST.JLS4); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setCompilerOptions(getCompilerOptions()); + + final String key = "Lp/C;"; + final IBinding[] bindings = new IBinding[2]; + + String contents = + "package p;\n" + + "public class A{}\n" + + "class B{}"; + + File packageDir = new File(rootDir, "p"); + packageDir.mkdir(); + File file = new File(packageDir, "A.java"); + Writer writer = null; + try { + writer = new BufferedWriter(new FileWriter(file)); + writer.write(contents); + } finally { + if (writer != null) { + try { + writer.close(); + } catch(IOException e) { + // ignore + } + } + } + + String contents2 = + "package q;\n" + + "import p.*;\n" + + "public class C extends B {}"; + File fileY = new File(packageDir, "C.java"); + Writer writer2 = null; + try { + writer2 = new BufferedWriter(new FileWriter(fileY)); + writer2.write(contents2); + } finally { + if (writer2 != null) { + try { + writer2.close(); + } catch(IOException e) { + // ignore + } + } + } + + try { + final String canonicalPath = fileY.getCanonicalPath(); + final CompilationUnit[] units = new CompilationUnit[1]; + + FileASTRequestor requestor = new FileASTRequestor() { + public void acceptBinding(String bindingKey, IBinding binding) { + if (key.equals(bindingKey)) { + bindings[0] = binding; + IBinding[] temp = createBindings(new String[] {"Lq/C;"}); + for (int i = 0; i < temp.length; ++i) { + bindings[i + 1] = temp[i]; + } + } + } + public void acceptAST(String sourceFilePath, CompilationUnit ast) { + if (canonicalPath.equals(sourceFilePath)) { + units[0] = ast; + } + } + }; + + parser.setEnvironment(null, new String[] { rootDir.getCanonicalPath() }, null, true); + parser.createASTs(new String[] {canonicalPath}, null, new String[] {key}, requestor, null); + assertNotNull("No ast", units[0]); + IProblem[] problems = units[0].getProblems(); + assertEquals("No problem", 1, problems.length); + assertEquals("Pb(3) The type B is not visible", problems[0].toString()); + } finally { + file.delete(); + fileY.delete(); + } + } + + public void test7() throws IOException { + File rootDir = new File(System.getProperty("java.io.tmpdir")); + + String contents = + "enum X {\n" + + " /** */\n" + + " FOO\n" + + "}"; + + File file = new File(rootDir, "X.java"); + Writer writer = null; + try { + writer = new BufferedWriter(new FileWriter(file)); + writer.write(contents); + } finally { + if (writer != null) { + try { + writer.close(); + } catch(IOException e) { + // ignore + } + } + } + + String contents2 = + "package p;\n" + + "class Y {}"; + File packageDir = new File(rootDir, "p"); + packageDir.mkdir(); + File fileY = new File(packageDir, "Y.java"); + Writer writer2 = null; + try { + writer2 = new BufferedWriter(new FileWriter(fileY)); + writer2.write(contents2); + } finally { + if (writer2 != null) { + try { + writer2.close(); + } catch(IOException e) { + // ignore + } + } + } + + try { + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setCompilerOptions(JavaCore.getOptions()); + parser.createASTs( + new String[] { file.getCanonicalPath(), fileY.getCanonicalPath() }, + null, + new String[] {}, + new FileASTRequestor() {}, + null); + } finally { + file.delete(); + fileY.delete(); + } + } + + public void testBug461250() { + String source = + "class QH implements QR.Q {\n" + + " QR.Q q;\n" + + " @V(v = A, d = \"\") Map p;\n" + + "}\n"; + Map options = JavaCore.getOptions(); + JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options); + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setCompilerOptions(options); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setSource(source.toCharArray()); + parser.setResolveBindings(true); + String[] emptyStringArray = new String[0]; + parser.setEnvironment(emptyStringArray, emptyStringArray, emptyStringArray, true /* includeRunningVMBootclasspath */); + parser.setUnitName("dontCare"); + ASTNode ast = parser.createAST(null); + assertTrue("should have parsed a CUD", ast instanceof CompilationUnit); + } + + @Deprecated + public void testBug465048() { + String source = + "class A {\n" + + " void f(OtherClass otherClass) {\n" + + " synchronized (otherClass) {\n" + + " Class c = InnerClass.class;\n" + // Line = 4 + " }\n" + + " }\n" + + " class InnerClass { }\n" + + "}\n"; + Map options = JavaCore.getOptions(); + JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options); + ASTParser parser = ASTParser.newParser(AST.JLS9); + parser.setCompilerOptions(options); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setSource(source.toCharArray()); + parser.setResolveBindings(true); + String[] emptyStringArray = new String[0]; + parser.setEnvironment(emptyStringArray, emptyStringArray, emptyStringArray, + true /* includeRunningVMBootclasspath */); + parser.setUnitName("dontCare"); + + CompilationUnit cu = (CompilationUnit) parser.createAST(null); + SimpleName innerClassLiteral = (SimpleName) NodeFinder.perform(cu, cu.getPosition(4, 16), 1 /* length */); + ITypeBinding innerClassBinding = (ITypeBinding) innerClassLiteral.resolveBinding(); + + assertEquals("InnerClass", innerClassBinding.getName()); + } + + /** + * Verifies that ASTParser doesn't throw an IllegalArgumentException when given + * this valid input. + * @deprecated + */ + public void testBug480545() { + String input = "class Test2 { void f(Test2... xs) {} }"; + ASTParser parser = ASTParser.newParser(AST.JLS9); + parser.setSource(input.toCharArray()); + Map options = JavaCore.getOptions(); + JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); + parser.setCompilerOptions(options); + assertNotNull(parser.createAST(null)); + } + @Deprecated + public void testBug493336_001() { + String input = "public class X implements á¼³ {\n" + + " public static final class if {\n"+ + " public static final if ËŠ = new if(null, null, null, null);\n"+ + " }\n" + + "}"; + ASTParser parser = ASTParser.newParser(AST.JLS9); + parser.setSource(input.toCharArray()); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setEnvironment(null, new String[] {null}, null, true); + + Hashtable options1 = JavaCore.getDefaultOptions(); + options1.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8); + options1.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8); + options1.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_8); + parser.setCompilerOptions(options1); + assertNotNull(parser.createAST(null)); + } + @Deprecated + public void testBug526996_001() { + File rootDir = new File(System.getProperty("java.io.tmpdir")); + String contents = + "public class X {\n" + + " public X() {\n" + + " this.f16132b =\n" + + "/*\n" + + " at jadx.api.JavaClass.decompile(JavaClass.java:62)\n" + + "*/\n" + + "\n" + + " /* JADX WARNING: inconsistent code. */\n" + + " /* Code decompiled incorrectly, please refer to instructions dump. */\n" + + " public final C1984r m22030a() {\n" + + " }\n" + + " }\n" + + "\n"; + + File file = new File(rootDir, "X.java"); + Writer writer = null; + try { + try { + writer = new BufferedWriter(new FileWriter(file)); + writer.write(contents); + } catch (IOException e1) { + // ignore + } + } finally { + if (writer != null) { + try { + writer.close(); + } catch(IOException e) { + // ignore + } + } + } + String contents2 = + "public class Y {\n" + + "\n" + + " /* JADX WARNING: inconsistent code. */\n" + + " protected void finalize() {\n" + + " for (i =\n" + + "/*\n" + + " at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:220)\n" + + "*/\n" + + " public void close() { }\n" + + " }\n" ; + + File fileY = new File(rootDir, "Y.java"); + Writer writer2 = null; + try { + try { + writer2 = new BufferedWriter(new FileWriter(fileY)); + writer2.write(contents2); + } catch (IOException e) { + // ignore + } + } finally { + try { + if (writer2 != null) writer2.close(); + } catch(IOException e) { + // ignore + } + } + try { + final FileASTRequestor astRequestor = new FileASTRequestor() { + @Override + public void acceptAST(String sourceFilePath, CompilationUnit ast) { + super.acceptAST(sourceFilePath, ast); + } + }; + ASTParser parser = ASTParser.newParser(AST.JLS9); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setEnvironment(new String[0], new String[] { rootDir.getAbsolutePath() }, null, true); + String[] files = null; + try { + files = new String[] {file.getCanonicalPath(), fileY.getCanonicalPath()}; + parser.createASTs(files, + null, + new String[0], + astRequestor, + null); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } finally { + file.delete(); + fileY.delete(); + } + } + public void testBug526996_002() { + File rootDir = new File(System.getProperty("java.io.tmpdir")); + String contents = + "public class zzei {\n"+ + " private final Context mContext;\n"+ + " private final String zzAg;\n"+ + " private zzb zzAh;\n"+ + " private zzb zzAi;\n"+ + " private zze zzAj;\n"+ + " private int zzAk;\n"+ + " private final VersionInfoParcel zzpI;\n"+ + " private final Object zzpK;\n"+ + "\n"+ + " public interface zzb {\n"+ + " void zzc(T t);\n"+ + " }\n"+ + "\n"+ + " class zza {\n"+ + " static int zzAu = 60000;\n"+ + " static int zzAv = 10000;\n"+ + " }\n"+ + "\n"+ + " public class zzc implements zzb {\n"+ + " public void zzc(T t) {\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public class zzd extends zzjh {\n"+ + " private final zze zzAw;\n"+ + " private boolean zzAx;\n"+ + " private final Object zzpK = new Object();\n"+ + "\n"+ + " public zzd(zze com_google_android_gms_internal_zzei_zze) {\n"+ + " this.zzAw = com_google_android_gms_internal_zzei_zze;\n"+ + " }\n"+ + "\n"+ + " public void release() {\n"+ + " synchronized (this.zzpK) {\n"+ + " if (this.zzAx) {\n"+ + " return;\n"+ + " }\n"+ + " this.zzAx = true;\n"+ + " zza(new com.google.android.gms.internal.zzjg.zzc(this) {\n"+ + " final /* synthetic */ zzd zzAy;\n"+ + "\n"+ + " {\n"+ + " this.zzAy = r1;\n"+ + " }\n"+ + "\n"+ + " public void zzb(zzbe com_google_android_gms_internal_zzbe) {\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(\"Ending javascript session.\");\n"+ + " ((zzbf) com_google_android_gms_internal_zzbe).zzcs();\n"+ + " }\n"+ + "\n"+ + " public /* synthetic */ void zzc(Object obj) {\n"+ + " zzb((zzbe) obj);\n"+ + " }\n"+ + " }, new com.google.android.gms.internal.zzjg.zzb());\n"+ + " zza(new com.google.android.gms.internal.zzjg.zzc(this) {\n"+ + " final /* synthetic */ zzd zzAy;\n"+ + "\n"+ + " {\n"+ + " this.zzAy = r1;\n"+ + " }\n"+ + "\n"+ + " public void zzb(zzbe com_google_android_gms_internal_zzbe) {\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(\"Releasing engine reference.\");\n"+ + " this.zzAy.zzAw.zzek();\n"+ + " }\n"+ + "\n"+ + " public /* synthetic */ void zzc(Object obj) {\n"+ + " zzb((zzbe) obj);\n"+ + " }\n"+ + " }, new com.google.android.gms.internal.zzjg.zza(this) {\n"+ + " final /* synthetic */ zzd zzAy;\n"+ + "\n"+ + " {\n"+ + " this.zzAy = r1;\n"+ + " }\n"+ + "\n"+ + " public void run() {\n"+ + " this.zzAy.zzAw.zzek();\n"+ + " }\n"+ + " });\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public class zze extends zzjh {\n"+ + " private int zzAA;\n"+ + " private zzb zzAi;\n"+ + " private boolean zzAz;\n"+ + " private final Object zzpK = new Object();\n"+ + "\n"+ + " public zze(zzb com_google_android_gms_internal_zzei_zzb_com_google_android_gms_internal_zzbb) {\n"+ + " this.zzAi = com_google_android_gms_internal_zzei_zzb_com_google_android_gms_internal_zzbb;\n"+ + " this.zzAz = false;\n"+ + " this.zzAA = 0;\n"+ + " }\n"+ + "\n"+ + " public zzd zzej() {\n"+ + " final zzd com_google_android_gms_internal_zzei_zzd = new zzd(this);\n"+ + " synchronized (this.zzpK) {\n"+ + " zza(new com.google.android.gms.internal.zzjg.zzc(this) {\n"+ + " final /* synthetic */ zze zzAC;\n"+ + "\n"+ + " public void zza(zzbb com_google_android_gms_internal_zzbb) {\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(\"Getting a new session for JS Engine.\");\n"+ + " com_google_android_gms_internal_zzei_zzd.zzg(com_google_android_gms_internal_zzbb.zzcq());\n"+ + " }\n"+ + "\n"+ + " public /* synthetic */ void zzc(Object obj) {\n"+ + " zza((zzbb) obj);\n"+ + " }\n"+ + " }, new com.google.android.gms.internal.zzjg.zza(this) {\n"+ + " final /* synthetic */ zze zzAC;\n"+ + "\n"+ + " public void run() {\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(\"Rejecting reference for JS Engine.\");\n"+ + " com_google_android_gms_internal_zzei_zzd.reject();\n"+ + " }\n"+ + " });\n"+ + " zzx.zzaa(this.zzAA >= 0);\n"+ + " this.zzAA++;\n"+ + " }\n"+ + " return com_google_android_gms_internal_zzei_zzd;\n"+ + " }\n"+ + "\n"+ + " protected void zzek() {\n"+ + " boolean z = true;\n"+ + " synchronized (this.zzpK) {\n"+ + " if (this.zzAA < 1) {\n"+ + " z = false;\n"+ + " }\n"+ + " zzx.zzaa(z);\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(\"Releasing 1 reference for JS Engine\");\n"+ + " this.zzAA--;\n"+ + " zzem();\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public void zzel() {\n"+ + " boolean z = true;\n"+ + " synchronized (this.zzpK) {\n"+ + " if (this.zzAA < 0) {\n"+ + " z = false;\n"+ + " }\n"+ + " zzx.zzaa(z);\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(\"Releasing root reference. JS Engine will be destroyed once other references are released.\");\n"+ + " this.zzAz = true;\n"+ + " zzem();\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " protected void zzem() {\n"+ + " synchronized (this.zzpK) {\n"+ + " zzx.zzaa(this.zzAA >= 0);\n"+ + " if (this.zzAz && this.zzAA == 0) {\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(\"No reference is left (including root). Cleaning up engine.\");\n"+ + " zza(new com.google.android.gms.internal.zzjg.zzc(this) {\n"+ + " final /* synthetic */ zze zzAC;\n"+ + "\n"+ + " {\n"+ + " this.zzAC = r1;\n"+ + " }\n"+ + "\n"+ + " public void zza(final zzbb com_google_android_gms_internal_zzbb) {\n"+ + " zzip.runOnUiThread(new Runnable(this) {\n"+ + " final /* synthetic */ AnonymousClass3 zzAD;\n"+ + "\n"+ + " public void run() {\n"+ + " this.zzAD.zzAC.zzAi.zzc(com_google_android_gms_internal_zzbb);\n"+ + " com_google_android_gms_internal_zzbb.destroy();\n"+ + " }\n"+ + " });\n"+ + " }\n"+ + "\n"+ + " public /* synthetic */ void zzc(Object obj) {\n"+ + " zza((zzbb) obj);\n"+ + " }\n"+ + " }, new com.google.android.gms.internal.zzjg.zzb());\n"+ + " } else {\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(\"There are still references to the engine. Not destroying.\");\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public zzei(Context context, VersionInfoParcel versionInfoParcel, String str) {\n"+ + " this.zzpK = new Object();\n"+ + " this.zzAk = 1;\n"+ + " this.zzAg = str;\n"+ + " this.mContext = context.getApplicationContext();\n"+ + " this.zzpI = versionInfoParcel;\n"+ + " this.zzAh = new zzc();\n"+ + " this.zzAi = new zzc();\n"+ + " }\n"+ + "\n"+ + " public zzei(Context context, VersionInfoParcel versionInfoParcel, String str, zzb com_google_android_gms_internal_zzei_zzb_com_google_android_gms_internal_zzbb, zzb com_google_android_gms_internal_zzei_zzb_com_google_android_gms_internal_zzbb2) {\n"+ + " this(context, versionInfoParcel, str);\n"+ + " this.zzAh = com_google_android_gms_internal_zzei_zzb_com_google_android_gms_internal_zzbb;\n"+ + " this.zzAi = com_google_android_gms_internal_zzei_zzb_com_google_android_gms_internal_zzbb2;\n"+ + " }\n"+ + "\n"+ + " private zze zzeg() {\n"+ + " final zze com_google_android_gms_internal_zzei_zze = new zze(this.zzAi);\n"+ + " zzip.runOnUiThread(new Runnable(this) {\n"+ + " final /* synthetic */ zzei zzAm;\n"+ + "\n"+ + " public void run() {\n"+ + " final zzbb zza = this.zzAm.zza(this.zzAm.mContext, this.zzAm.zzpI);\n"+ + " zza.zza(new com.google.android.gms.internal.zzbb.zza(this) {\n"+ + " final /* synthetic */ AnonymousClass1 zzAo;\n"+ + "\n"+ + " public void zzcr() {\n"+ + " zzip.zzKO.postDelayed(new Runnable(this) {\n"+ + " final /* synthetic */ AnonymousClass1 zzAp;\n"+ + "\n"+ + " {\n"+ + " this.zzAp = r1;\n"+ + " }\n"+ + "\n"+ + " /* JADX WARNING: inconsistent code. */\n"+ + " /* Code decompiled incorrectly, please refer to instructions dump. */\n"+ + " public void run() {\n"+ + " /*\n"+ + " r3 = this;\n"+ + " r0 = r3.zzAp;\n"+ + " r0 = r0.zzAo;\n"+ + " r0 = r0.zzAm;\n"+ + " r1 = r0.zzpK;\n"+ + " monitor-enter(r1);\n"+ + " r0 = r3.zzAp; Catch:{ all -> 0x003f }\n"+ + " r0 = r0.zzAo; Catch:{ all -> 0x003f }\n"+ + " r0 = r0; Catch:{ all -> 0x003f }\n"+ + " r0 = r0.getStatus(); Catch:{ all -> 0x003f }\n"+ + " r2 = -1;\n"+ + " if (r0 == r2) throw GOTO_REPLACEMENT_1_L_0x0025;\n"+ + " L_0x0018:\n"+ + " r0 = r3.zzAp; Catch:{ all -> 0x003f }\n"+ + " r0 = r0.zzAo; Catch:{ all -> 0x003f }\n"+ + " r0 = r0; Catch:{ all -> 0x003f }\n"+ + " r0 = r0.getStatus(); Catch:{ all -> 0x003f }\n"+ + " r2 = 1;\n"+ + " if (r0 != r2) throw GOTO_REPLACEMENT_2_L_0x0027;\n"+ + " L_0x0025:\n"+ + " monitor-exit(r1); Catch:{ all -> 0x003f }\n"+ + " L_0x0026:\n"+ + " return;\n"+ + " L_0x0027:\n"+ + " r0 = r3.zzAp; Catch:{ all -> 0x003f }\n"+ + " r0 = r0.zzAo; Catch:{ all -> 0x003f }\n"+ + " r0 = r0; Catch:{ all -> 0x003f }\n"+ + " r0.reject(); Catch:{ all -> 0x003f }\n"+ + " r0 = new com.google.android.gms.internal.zzei$1$1$1$1; Catch:{ all -> 0x003f }\n"+ + " r0.(r3); Catch:{ all -> 0x003f }\n"+ + " com.google.android.gms.internal.zzip.runOnUiThread(r0); Catch:{ all -> 0x003f }\n"+ + " r0 = \"Could not receive loaded message in a timely manner. Rejecting.\";\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(r0); Catch:{ all -> 0x003f }\n"+ + " monitor-exit(r1); Catch:{ all -> 0x003f }\n"+ + " throw GOTO_REPLACEMENT_3_L_0x0026;\n"+ + " L_0x003f:\n"+ + " r0 = move-exception;\n"+ + " monitor-exit(r1); Catch:{ all -> 0x003f }\n"+ + " throw r0;\n"+ + " */\n"+ + " throw new UnsupportedOperationException(\"Method not decompiled: com.google.android.gms.internal.zzei.1.1.1.run():void\");\n"+ + " }\n"+ + " }, (long) zza.zzAv);\n"+ + " }\n"+ + " });\n"+ + " zza.zza(\"/jsLoaded\", new zzdl(this) {\n"+ + " final /* synthetic */ AnonymousClass1 zzAo;\n"+ + "\n"+ + " /* JADX WARNING: inconsistent code. */\n"+ + " /* Code decompiled incorrectly, please refer to instructions dump. */\n"+ + " public void zza(com.google.android.gms.internal.zzjn r4, java.util.Map r5) {\n"+ + " /*\n"+ + " r3 = this;\n"+ + " r0 = r3.zzAo;\n"+ + " r0 = r0.zzAm;\n"+ + " r1 = r0.zzpK;\n"+ + " monitor-enter(r1);\n"+ + " r0 = r3.zzAo; Catch:{ all -> 0x0051 }\n"+ + " r0 = r0; Catch:{ all -> 0x0051 }\n"+ + " r0 = r0.getStatus(); Catch:{ all -> 0x0051 }\n"+ + " r2 = -1;\n"+ + " if (r0 == r2) throw GOTO_REPLACEMENT_4_L_0x001f;\n"+ + " L_0x0014:\n"+ + " r0 = r3.zzAo; Catch:{ all -> 0x0051 }\n"+ + " r0 = r0; Catch:{ all -> 0x0051 }\n"+ + " r0 = r0.getStatus(); Catch:{ all -> 0x0051 }\n"+ + " r2 = 1;\n"+ + " if (r0 != r2) throw GOTO_REPLACEMENT_5_L_0x0021;\n"+ + " L_0x001f:\n"+ + " monitor-exit(r1); Catch:{ all -> 0x0051 }\n"+ + " L_0x0020:\n"+ + " return;\n"+ + " L_0x0021:\n"+ + " r0 = r3.zzAo; Catch:{ all -> 0x0051 }\n"+ + " r0 = r0.zzAm; Catch:{ all -> 0x0051 }\n"+ + " r2 = 0;\n"+ + " r0.zzAk = r2; Catch:{ all -> 0x0051 }\n"+ + " r0 = r3.zzAo; Catch:{ all -> 0x0051 }\n"+ + " r0 = r0.zzAm; Catch:{ all -> 0x0051 }\n"+ + " r0 = r0.zzAh; Catch:{ all -> 0x0051 }\n"+ + " r2 = r0; Catch:{ all -> 0x0051 }\n"+ + " r0.zzc(r2); Catch:{ all -> 0x0051 }\n"+ + " r0 = r3.zzAo; Catch:{ all -> 0x0051 }\n"+ + " r0 = r0; Catch:{ all -> 0x0051 }\n"+ + " r2 = r0; Catch:{ all -> 0x0051 }\n"+ + " r0.zzg(r2); Catch:{ all -> 0x0051 }\n"+ + " r0 = r3.zzAo; Catch:{ all -> 0x0051 }\n"+ + " r0 = r0.zzAm; Catch:{ all -> 0x0051 }\n"+ + " r2 = r3.zzAo; Catch:{ all -> 0x0051 }\n"+ + " r2 = r0; Catch:{ all -> 0x0051 }\n"+ + " r0.zzAj = r2; Catch:{ all -> 0x0051 }\n"+ + " r0 = \"Successfully loaded JS Engine.\";\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(r0); Catch:{ all -> 0x0051 }\n"+ + " monitor-exit(r1); Catch:{ all -> 0x0051 }\n"+ + " throw GOTO_REPLACEMENT_6_L_0x0020;\n"+ + " L_0x0051:\n"+ + " r0 = move-exception;\n"+ + " monitor-exit(r1); Catch:{ all -> 0x0051 }\n"+ + " throw r0;\n"+ + " */\n"+ + " throw new UnsupportedOperationException(\"Method not decompiled: com.google.android.gms.internal.zzei.1.2.zza(com.google.android.gms.internal.zzjn, java.util.Map):void\");\n"+ + " }\n"+ + " });\n"+ + " final zziy com_google_android_gms_internal_zziy = new zziy();\n"+ + " zzdl anonymousClass3 = new zzdl(this) {\n"+ + " final /* synthetic */ AnonymousClass1 zzAo;\n"+ + "\n"+ + " public void zza(zzjn com_google_android_gms_internal_zzjn, Map map) {\n"+ + " synchronized (this.zzAo.zzAm.zzpK) {\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.zzaG(\"JS Engine is requesting an update\");\n"+ + " if (this.zzAo.zzAm.zzAk == 0) {\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.zzaG(\"Starting reload.\");\n"+ + " this.zzAo.zzAm.zzAk = 2;\n"+ + " this.zzAo.zzAm.zzeh();\n"+ + " }\n"+ + " zza.zzb(\"/requestReload\", (zzdl) com_google_android_gms_internal_zziy.get());\n"+ + " }\n"+ + " }\n"+ + " };\n"+ + " com_google_android_gms_internal_zziy.set(anonymousClass3);\n"+ + " zza.zza(\"/requestReload\", anonymousClass3);\n"+ + " if (this.zzAm.zzAg.endsWith(\".js\")) {\n"+ + " zza.zzs(this.zzAm.zzAg);\n"+ + " } else if (this.zzAm.zzAg.startsWith(\"\")) {\n"+ + " zza.zzu(this.zzAm.zzAg);\n"+ + " } else {\n"+ + " zza.zzt(this.zzAm.zzAg);\n"+ + " }\n"+ + " zzip.zzKO.postDelayed(new Runnable(this) {\n"+ + " final /* synthetic */ AnonymousClass1 zzAo;\n"+ + "\n"+ + " /* JADX WARNING: inconsistent code. */\n"+ + " /* Code decompiled incorrectly, please refer to instructions dump. */\n"+ + " public void run() {\n"+ + " /*\n"+ + " r3 = this;\n"+ + " r0 = r3.zzAo;\n"+ + " r0 = r0.zzAm;\n"+ + " r1 = r0.zzpK;\n"+ + " monitor-enter(r1);\n"+ + " r0 = r3.zzAo; Catch:{ all -> 0x0037 }\n"+ + " r0 = r0; Catch:{ all -> 0x0037 }\n"+ + " r0 = r0.getStatus(); Catch:{ all -> 0x0037 }\n"+ + " r2 = -1;\n"+ + " if (r0 == r2) throw GOTO_REPLACEMENT_7_L_0x001f;\n"+ + " L_0x0014:\n"+ + " r0 = r3.zzAo; Catch:{ all -> 0x0037 }\n"+ + " r0 = r0; Catch:{ all -> 0x0037 }\n"+ + " r0 = r0.getStatus(); Catch:{ all -> 0x0037 }\n"+ + " r2 = 1;\n"+ + " if (r0 != r2) throw GOTO_REPLACEMENT_8_L_0x0021;\n"+ + " L_0x001f:\n"+ + " monitor-exit(r1); Catch:{ all -> 0x0037 }\n"+ + " L_0x0020:\n"+ + " return;\n"+ + " L_0x0021:\n"+ + " r0 = r3.zzAo; Catch:{ all -> 0x0037 }\n"+ + " r0 = r0; Catch:{ all -> 0x0037 }\n"+ + " r0.reject(); Catch:{ all -> 0x0037 }\n"+ + " r0 = new com.google.android.gms.internal.zzei$1$4$1; Catch:{ all -> 0x0037 }\n"+ + " r0.(r3); Catch:{ all -> 0x0037 }\n"+ + " com.google.android.gms.internal.zzip.runOnUiThread(r0); Catch:{ all -> 0x0037 }\n"+ + " r0 = \"Could not receive loaded message in a timely manner. Rejecting.\";\n"+ + " com.google.android.gms.ads.internal.util.client.zzb.v(r0); Catch:{ all -> 0x0037 }\n"+ + " monitor-exit(r1); Catch:{ all -> 0x0037 }\n"+ + " throw GOTO_REPLACEMENT_9_L_0x0020;\n"+ + " L_0x0037:\n"+ + " r0 = move-exception;\n"+ + " monitor-exit(r1); Catch:{ all -> 0x0037 }\n"+ + " throw r0;\n"+ + " */\n"+ + " throw new UnsupportedOperationException(\"Method not decompiled: com.google.android.gms.internal.zzei.1.4.run():void\");\n"+ + " }\n"+ + " }, (long) zza.zzAu);\n"+ + " }\n"+ + " });\n"+ + " return com_google_android_gms_internal_zzei_zze;\n"+ + " }\n"+ + "}\n"; + + File file = new File(rootDir, "zzei.java"); + Writer writer = null; + try { + try { + writer = new BufferedWriter(new FileWriter(file)); + writer.write(contents); + } catch (IOException e1) { + // ignore + } + } finally { + if (writer != null) { + try { + writer.close(); + } catch(IOException e) { + // ignore + } + } + } + String contents2 = + "public final class dm {\n"+ + " private final byte[] a;\n"+ + " private final boolean b;\n"+ + " private int c;\n"+ + " private int d;\n"+ + " private int e;\n"+ + " private final InputStream f;\n"+ + " private int g;\n"+ + " private boolean h;\n"+ + " private int i;\n"+ + " private int j;\n"+ + " private int k;\n"+ + " private int l;\n"+ + " private int m;\n"+ + " private a n;\n"+ + "\n"+ + " public static dm a(byte[] bArr, int i) {\n"+ + " dm dmVar = new dm(bArr, i);\n"+ + " try {\n"+ + " dmVar.b(i);\n"+ + " return dmVar;\n"+ + " } catch (Throwable e) {\n"+ + " throw new IllegalArgumentException(e);\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public final int a() {\n"+ + " int i = 1;\n"+ + " if (this.e != this.c || d(1)) {\n"+ + " i = 0;\n"+ + " }\n"+ + " if (i != 0) {\n"+ + " this.g = 0;\n"+ + " return 0;\n"+ + " }\n"+ + " this.g = e();\n"+ + " if (ed.b(this.g) != 0) {\n"+ + " return this.g;\n"+ + " }\n"+ + " throw dr.d();\n"+ + " }\n"+ + "\n"+ + " public final void a(int i) {\n"+ + " if (this.g != i) {\n"+ + " throw dr.e();\n"+ + " }\n"+ + " }\n"+ + "\n"+ + " public final dv a(dx dxVar, do doVar) {\n"+ + " int e = e();\n"+ + " if (this.k >= this.l) {\n"+ + " throw dr.g();\n"+ + " }\n"+ + " int b = b(e);\n"+ + " this.k++;\n"+ + " dv dvVar = (dv) dxVar.a(this, doVar);\n"+ + " a(0);\n"+ + " this.k--;\n"+ + " this.j = b;\n"+ + " i();\n"+ + " return dvVar;\n"+ + " }\n"+ + "\n"+ + " /* JADX WARNING: inconsistent code. */\n"+ + " /* Code decompiled incorrectly, please refer to instructions dump. */\n"+ + " public final int e() {\n"+ + " /*\n"+ + " r8 = this;\n"+ + " r6 = 0;\n"+ + " r0 = r8.e;\n"+ + " r1 = r8.c;\n"+ + " if (r1 == r0) throw GOTO_REPLACEMENT_1_L_0x0081;\n"+ + " L_0x0008:\n"+ + " r3 = r8.a;\n"+ + " r2 = r0 + 1;\n"+ + " r0 = r3[r0];\n"+ + " if (r0 < 0) throw GOTO_REPLACEMENT_2_L_0x0013;\n"+ + " L_0x0010:\n"+ + " r8.e = r2;\n"+ + " L_0x0012:\n"+ + " return r0;\n"+ + " L_0x0013:\n"+ + " r1 = r8.c;\n"+ + " r1 = r1 - r2;\n"+ + " r4 = 9;\n"+ + " if (r1 < r4) throw GOTO_REPLACEMENT_3_L_0x0081;\n"+ + " L_0x001a:\n"+ + " r1 = r2 + 1;\n"+ + " r2 = r3[r2];\n"+ + " r2 = r2 << 7;\n"+ + " r0 = r0 ^ r2;\n"+ + " r4 = (long) r0;\n"+ + " r2 = (r4 > r6 ? 1 : (r4 == r6 ? 0 : -1));\n"+ + " if (r2 >= 0) throw GOTO_REPLACEMENT_4_L_0x002e;\n"+ + " L_0x0026:\n"+ + " r2 = (long) r0;\n"+ + " r4 = -128; // 0xffffffffffffff80 float:NaN double:NaN;\n"+ + " r2 = r2 ^ r4;\n"+ + " r0 = (int) r2;\n"+ + " L_0x002b:\n"+ + " r8.e = r1;\n"+ + " throw GOTO_REPLACEMENT_5_L_0x0012;\n"+ + " L_0x002e:\n"+ + " r2 = r1 + 1;\n"+ + " r1 = r3[r1];\n"+ + " r1 = r1 << 14;\n"+ + " r0 = r0 ^ r1;\n"+ + " r4 = (long) r0;\n"+ + " r1 = (r4 > r6 ? 1 : (r4 == r6 ? 0 : -1));\n"+ + " if (r1 < 0) throw GOTO_REPLACEMENT_6_L_0x0041;\n"+ + " L_0x003a:\n"+ + " r0 = (long) r0;\n"+ + " r4 = 16256; // 0x3f80 float:2.278E-41 double:8.0315E-320;\n"+ + " r0 = r0 ^ r4;\n"+ + " r0 = (int) r0;\n"+ + " r1 = r2;\n"+ + " throw GOTO_REPLACEMENT_7_L_0x002b;\n"+ + " L_0x0041:\n"+ + " r1 = r2 + 1;\n"+ + " r2 = r3[r2];\n"+ + " r2 = r2 << 21;\n"+ + " r0 = r0 ^ r2;\n"+ + " r4 = (long) r0;\n"+ + " r2 = (r4 > r6 ? 1 : (r4 == r6 ? 0 : -1));\n"+ + " if (r2 >= 0) throw GOTO_REPLACEMENT_8_L_0x0054;\n"+ + " L_0x004d:\n"+ + " r2 = (long) r0;\n"+ + " r4 = -2080896; // 0xffffffffffe03f80 float:NaN double:NaN;\n"+ + " r2 = r2 ^ r4;\n"+ + " r0 = (int) r2;\n"+ + " throw GOTO_REPLACEMENT_9_L_0x002b;\n"+ + " L_0x0054:\n"+ + " r2 = r1 + 1;\n"+ + " r1 = r3[r1];\n"+ + " r4 = r1 << 28;\n"+ + " r0 = r0 ^ r4;\n"+ + " r4 = (long) r0;\n"+ + " r6 = 266354560; // 0xfe03f80 float:2.2112565E-29 double:1.315966377E-315;\n"+ + " r4 = r4 ^ r6;\n"+ + " r0 = (int) r4;\n"+ + " if (r1 >= 0) throw GOTO_REPLACEMENT_10_L_0x0087;\n"+ + " L_0x0063:\n"+ + " r1 = r2 + 1;\n"+ + " r2 = r3[r2];\n"+ + " if (r2 >= 0) throw GOTO_REPLACEMENT_11_L_0x002b;\n"+ + " L_0x0069:\n"+ + " r2 = r1 + 1;\n"+ + " r1 = r3[r1];\n"+ + " if (r1 >= 0) throw GOTO_REPLACEMENT_12_L_0x0087;\n"+ + " L_0x006f:\n"+ + " r1 = r2 + 1;\n"+ + " r2 = r3[r2];\n"+ + " if (r2 >= 0) throw GOTO_REPLACEMENT_13_L_0x002b;\n"+ + " L_0x0075:\n"+ + " r2 = r1 + 1;\n"+ + " r1 = r3[r1];\n"+ + " if (r1 >= 0) throw GOTO_REPLACEMENT_14_L_0x0087;\n"+ + " L_0x007b:\n"+ + " r1 = r2 + 1;\n"+ + " r2 = r3[r2];\n"+ + " if (r2 >= 0) throw GOTO_REPLACEMENT_15_L_0x002b;\n"+ + " L_0x0081:\n"+ + " r0 = r8.h();\n"+ + " r0 = (int) r0;\n"+ + " throw GOTO_REPLACEMENT_16_L_0x0012;\n"+ + " L_0x0087:\n"+ + " r1 = r2;\n"+ + " throw GOTO_REPLACEMENT_17_L_0x002b;\n"+ + " */\n"+ + " throw new UnsupportedOperationException(\"Method not decompiled: com.tapjoy.internal.dm.e():int\");\n"+ + " }\n"+ + "\n"+ + " /* JADX WARNING: inconsistent code. */\n"+ + " /* Code decompiled incorrectly, please refer to instructions dump. */\n"+ + " public final long f() {\n"+ + " /*\n"+ + " r10 = this;\n"+ + " r8 = 0;\n"+ + " r0 = r10.e;\n"+ + " r1 = r10.c;\n"+ + " if (r1 == r0) throw GOTO_REPLACEMENT_18_L_0x00bb;\n"+ + " L_0x0008:\n"+ + " r4 = r10.a;\n"+ + " r1 = r0 + 1;\n"+ + " r0 = r4[r0];\n"+ + " if (r0 < 0) throw GOTO_REPLACEMENT_19_L_0x0014;\n"+ + " L_0x0010:\n"+ + " r10.e = r1;\n"+ + " r0 = (long) r0;\n"+ + " L_0x0013:\n"+ + " return r0;\n"+ + " L_0x0014:\n"+ + " r2 = r10.c;\n"+ + " r2 = r2 - r1;\n"+ + " r3 = 9;\n"+ + " if (r2 < r3) throw GOTO_REPLACEMENT_20_L_0x00bb;\n"+ + " L_0x001b:\n"+ + " r2 = r1 + 1;\n"+ + " r1 = r4[r1];\n"+ + " r1 = r1 << 7;\n"+ + " r0 = r0 ^ r1;\n"+ + " r0 = (long) r0;\n"+ + " r3 = (r0 > r8 ? 1 : (r0 == r8 ? 0 : -1));\n"+ + " if (r3 >= 0) throw GOTO_REPLACEMENT_21_L_0x002d;\n"+ + " L_0x0027:\n"+ + " r4 = -128; // 0xffffffffffffff80 float:NaN double:NaN;\n"+ + " r0 = r0 ^ r4;\n"+ + " L_0x002a:\n"+ + " r10.e = r2;\n"+ + " throw GOTO_REPLACEMENT_22_L_0x0013;\n"+ + " L_0x002d:\n"+ + " r3 = r2 + 1;\n"+ + " r2 = r4[r2];\n"+ + " r2 = r2 << 14;\n"+ + " r6 = (long) r2;\n"+ + " r0 = r0 ^ r6;\n"+ + " r2 = (r0 > r8 ? 1 : (r0 == r8 ? 0 : -1));\n"+ + " if (r2 < 0) throw GOTO_REPLACEMENT_23_L_0x003e;\n"+ + " L_0x0039:\n"+ + " r4 = 16256; // 0x3f80 float:2.278E-41 double:8.0315E-320;\n"+ + " r0 = r0 ^ r4;\n"+ + " r2 = r3;\n"+ + " throw GOTO_REPLACEMENT_24_L_0x002a;\n"+ + " L_0x003e:\n"+ + " r2 = r3 + 1;\n"+ + " r3 = r4[r3];\n"+ + " r3 = r3 << 21;\n"+ + " r6 = (long) r3;\n"+ + " r0 = r0 ^ r6;\n"+ + " r3 = (r0 > r8 ? 1 : (r0 == r8 ? 0 : -1));\n"+ + " if (r3 >= 0) throw GOTO_REPLACEMENT_25_L_0x004f;\n"+ + " L_0x004a:\n"+ + " r4 = -2080896; // 0xffffffffffe03f80 float:NaN double:NaN;\n"+ + " r0 = r0 ^ r4;\n"+ + " throw GOTO_REPLACEMENT_26_L_0x002a;\n"+ + " L_0x004f:\n"+ + " r3 = r2 + 1;\n"+ + " r2 = r4[r2];\n"+ + " r6 = (long) r2;\n"+ + " r2 = 28;\n"+ + " r6 = r6 << r2;\n"+ + " r0 = r0 ^ r6;\n"+ + " r2 = (r0 > r8 ? 1 : (r0 == r8 ? 0 : -1));\n"+ + " if (r2 < 0) throw GOTO_REPLACEMENT_27_L_0x0062;\n"+ + " L_0x005c:\n"+ + " r4 = 266354560; // 0xfe03f80 float:2.2112565E-29 double:1.315966377E-315;\n"+ + " r0 = r0 ^ r4;\n"+ + " r2 = r3;\n"+ + " throw GOTO_REPLACEMENT_28_L_0x002a;\n"+ + " L_0x0062:\n"+ + " r2 = r3 + 1;\n"+ + " r3 = r4[r3];\n"+ + " r6 = (long) r3;\n"+ + " r3 = 35;\n"+ + " r6 = r6 << r3;\n"+ + " r0 = r0 ^ r6;\n"+ + " r3 = (r0 > r8 ? 1 : (r0 == r8 ? 0 : -1));\n"+ + " if (r3 >= 0) throw GOTO_REPLACEMENT_29_L_0x0076;\n"+ + " L_0x006f:\n"+ + " r4 = -34093383808; // 0xfffffff80fe03f80 float:2.2112565E-29 double:NaN;\n"+ + " r0 = r0 ^ r4;\n"+ + " throw GOTO_REPLACEMENT_30_L_0x002a;\n"+ + " L_0x0076:\n"+ + " r3 = r2 + 1;\n"+ + " r2 = r4[r2];\n"+ + " r6 = (long) r2;\n"+ + " r2 = 42;\n"+ + " r6 = r6 << r2;\n"+ + " r0 = r0 ^ r6;\n"+ + " r2 = (r0 > r8 ? 1 : (r0 == r8 ? 0 : -1));\n"+ + " if (r2 < 0) throw GOTO_REPLACEMENT_31_L_0x008b;\n"+ + " L_0x0083:\n"+ + " r4 = 4363953127296; // 0x3f80fe03f80 float:2.2112565E-29 double:2.1560793202584E-311;\n"+ + " r0 = r0 ^ r4;\n"+ + " r2 = r3;\n"+ + " throw GOTO_REPLACEMENT_32_L_0x002a;\n"+ + " L_0x008b:\n"+ + " r2 = r3 + 1;\n"+ + " r3 = r4[r3];\n"+ + " r6 = (long) r3;\n"+ + " r3 = 49;\n"+ + " r6 = r6 << r3;\n"+ + " r0 = r0 ^ r6;\n"+ + " r3 = (r0 > r8 ? 1 : (r0 == r8 ? 0 : -1));\n"+ + " if (r3 >= 0) throw GOTO_REPLACEMENT_33_L_0x009f;\n"+ + " L_0x0098:\n"+ + " r4 = -558586000294016; // 0xfffe03f80fe03f80 float:2.2112565E-29 double:NaN;\n"+ + " r0 = r0 ^ r4;\n"+ + " throw GOTO_REPLACEMENT_34_L_0x002a;\n"+ + " L_0x009f:\n"+ + " r3 = r2 + 1;\n"+ + " r2 = r4[r2];\n"+ + " r6 = (long) r2;\n"+ + " r2 = 56;\n"+ + " r6 = r6 << r2;\n"+ + " r0 = r0 ^ r6;\n"+ + " r6 = 71499008037633920; // 0xfe03f80fe03f80 float:2.2112565E-29 double:6.838959413692434E-304;\n"+ + " r0 = r0 ^ r6;\n"+ + " r2 = (r0 > r8 ? 1 : (r0 == r8 ? 0 : -1));\n"+ + " if (r2 >= 0) throw GOTO_REPLACEMENT_35_L_0x00c1;\n"+ + " L_0x00b2:\n"+ + " r2 = r3 + 1;\n"+ + " r3 = r4[r3];\n"+ + " r4 = (long) r3;\n"+ + " r3 = (r4 > r8 ? 1 : (r4 == r8 ? 0 : -1));\n"+ + " if (r3 >= 0) throw GOTO_REPLACEMENT_36_L_0x002a;\n"+ + " L_0x00bb:\n"+ + " r0 = r10.h();\n"+ + " throw GOTO_REPLACEMENT_37_L_0x0013;\n"+ + " L_0x00c1:\n"+ + " r2 = r3;\n"+ + " throw GOTO_REPLACEMENT_38_L_0x002a;\n"+ + " */\n"+ + " throw new UnsupportedOperationException(\"Method not decompiled: com.tapjoy.internal.dm.f():long\");\n"+ + " }\n"+ + "\n"+ + " private long h() {\n"+ + " long j = 0;\n"+ + " for (int i = 0; i < 64; i += 7) {\n"+ + " if (this.e == this.c) {\n"+ + " c(1);\n"+ + " }\n"+ + " byte[] bArr = this.a;\n"+ + " int i2 = this.e;\n"+ + " this.e = i2 + 1;\n"+ + " byte b = bArr[i2];\n"+ + " j |= ((long) (b & 127)) << i;\n"+ + " if ((b & 128) == 0) {\n"+ + " return j;\n"+ + " }\n"+ + " }\n"+ + " throw dr.c();\n"+ + " }\n"+ + "}\n"; + + File fileY = new File(rootDir, "dm.java"); + Writer writer2 = null; + try { + try { + writer2 = new BufferedWriter(new FileWriter(fileY)); + writer2.write(contents2); + } catch (IOException e) { + // ignore + } + } finally { + try { + if (writer2 != null) writer2.close(); + } catch(IOException e) { + // ignore + } + } + try { + final FileASTRequestor astRequestor = new FileASTRequestor() { + @Override + public void acceptAST(String sourceFilePath, CompilationUnit ast) { + super.acceptAST(sourceFilePath, ast); + } + }; + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setEnvironment(new String[0], new String[] { rootDir.getAbsolutePath() }, null, true); + String[] files = null; + try { + files = new String[] {file.getCanonicalPath(), fileY.getCanonicalPath()}; + parser.createASTs(files, + null, + new String[0], + astRequestor, + null); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } finally { + file.delete(); + fileY.delete(); + } + } + public void testBug530299_001() { + String contents = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var x = new X();\n" + + " for (var i = 0; i < 10; ++i) {}\n" + + " }\n" + + "}"; + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setSource(contents.toCharArray()); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setEnvironment(null, new String[] {null}, null, true); + parser.setResolveBindings(true); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_10); + options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_10); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_10); + parser.setCompilerOptions(options); + ASTNode node = parser.createAST(null); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit cu = (CompilationUnit) node; + assertTrue("Problems in compilation", cu.getProblems().length == 0); + TypeDeclaration typeDeclaration = (TypeDeclaration) cu.types().get(0); + MethodDeclaration[] methods = typeDeclaration.getMethods(); + MethodDeclaration methodDeclaration = methods[0]; + VariableDeclarationStatement vStmt = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0); + Type type = vStmt.getType(); + assertNotNull(type); + assertTrue("not a var", type.isVar()); + } + public void testBug482254() throws IOException { + File rootDir = new File(System.getProperty("java.io.tmpdir")); + + String contents = + "enum X {\n" + + " /** */\n" + + " FOO\n" + + "}"; + + File file = new File(rootDir, "X.java"); + Writer writer = null; + try { + writer = new BufferedWriter(new FileWriter(file)); + writer.write(contents); + } finally { + if (writer != null) { + try { + writer.close(); + } catch(IOException e) { + // ignore + } + } + } + + File packageDir = new File(rootDir, "p"); + packageDir.mkdir(); + File fileY = new File(packageDir, "Y.java"); + String canonicalPath = fileY.getCanonicalPath(); + + packageDir = new File(rootDir, "p"); + packageDir.mkdir(); + fileY = new File(packageDir, "Z.java"); + String canonicalPath2 = fileY.getCanonicalPath(); + + contents = + "enum X {\n" + + " /** */\n" + + " FOO\n" + + "}"; + + File file2 = new File(rootDir, "X.java"); + writer = null; + try { + writer = new BufferedWriter(new FileWriter(file2)); + writer.write(contents); + } finally { + if (writer != null) { + try { + writer.close(); + } catch(IOException e) { + // ignore + } + } + } + + try { + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setKind(ASTParser.K_COMPILATION_UNIT); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(true); + parser.setCompilerOptions(JavaCore.getOptions()); + parser.createASTs( + new String[] { file.getCanonicalPath(), canonicalPath, canonicalPath2, file2.getCanonicalPath() }, + null, + new String[] {}, + new FileASTRequestor() {}, + null); + } finally { + file.delete(); + fileY.delete(); + } + } + + /* + * To test isVar returning false for ast level 10 and compliance 9 + */ + public void testBug533210_0001() throws JavaModelException { + String contents = + "public class X {\n" + + " public static void main(String[] args) {\n" + + " var s = new Y();\n" + + " }\n" + + "}\n" + + "class Y {}"; + + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setSource(contents.toCharArray()); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(true); + parser.setStatementsRecovery(true); + parser.setBindingsRecovery(true); + parser.setUnitName("module-info.java"); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_9); + options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_9); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_9); + parser.setCompilerOptions(options); + + ASTNode node = parser.createAST(null); + assertTrue("Should be a compilation unit", node instanceof CompilationUnit); + CompilationUnit cu = (CompilationUnit) node; + TypeDeclaration typeDeclaration = (TypeDeclaration) cu.types().get(0); + MethodDeclaration[] methods = typeDeclaration.getMethods(); + MethodDeclaration methodDeclaration = methods[0]; + VariableDeclarationStatement vStmt = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0); + Type type = vStmt.getType(); + SimpleType simpleType = (SimpleType) type; + assertFalse("A var", simpleType.isVar()); + Name name = simpleType.getName(); + SimpleName simpleName = (SimpleName) name; + assertFalse("A var", simpleName.isVar()); + } + // no longer a preview feature, test is not relevant + @Deprecated + public void _testBug545383_01() throws JavaModelException { + String contents = + "class X {\n"+ + " public static int foo(int i) {\n"+ + " int result = switch (i) {\n"+ + " case 1 -> {break 5;}\n"+ + " default -> 0;\n"+ + " };\n"+ + " return result;\n"+ + " }\n"+ + "}\n"; + + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setSource(contents.toCharArray()); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(false); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_12); + options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_12); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_12); + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + options.put(CompilerOptions.OPTION_ReportPreviewFeatures, CompilerOptions.IGNORE); + parser.setCompilerOptions(options); + + ASTNode node = parser.createAST(null); + assertTrue("Should be a compilation unit", node instanceof CompilationUnit); + CompilationUnit cu = (CompilationUnit) node; + IProblem[] problems = cu.getProblems(); + assertTrue(problems.length > 0); + assertTrue(problems[0].toString().contains("preview")); + } + public void testBug547900_01() throws JavaModelException { + String contents = + "class X {\n"+ + " public static int foo(int i) {\n"+ + " int result = switch (i) {\n"+ + " case 1 -> {yield 5;}\n"+ + " default -> 0;\n"+ + " };\n"+ + " return result;\n"+ + " }\n"+ + "}\n"; + + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setSource(contents.toCharArray()); + parser.setEnvironment(null, null, null, true); + parser.setResolveBindings(false); + Map options = getCompilerOptions(); + options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_14); + options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_14); + options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_14); + parser.setCompilerOptions(options); + + ASTNode node = parser.createAST(null); + assertTrue("Should be a compilation unit", node instanceof CompilationUnit); + CompilationUnit cu = (CompilationUnit) node; + TypeDeclaration typeDeclaration = (TypeDeclaration) cu.types().get(0); + MethodDeclaration[] methods = typeDeclaration.getMethods(); + MethodDeclaration methodDeclaration = methods[0]; + VariableDeclarationStatement stmt = (VariableDeclarationStatement) methodDeclaration.getBody().statements().get(0); + VariableDeclarationFragment fragment = (VariableDeclarationFragment) stmt.fragments().get(0); + SwitchExpression se = (SwitchExpression) fragment.getInitializer(); + YieldStatement yieldStatement = (YieldStatement) ((Block)se.statements().get(1)).statements().get(0); + assertNotNull("Expression null", yieldStatement.getExpression()); + } + public void testBug558517() throws IOException { + File f1 = null, f2 = null, packDir = null; + try { + File rootDir = new File(System.getProperty("java.io.tmpdir")); + packDir = new File(rootDir, "P/src/x"); + packDir.mkdirs(); + + String fileName1 = "EnsureImpl$1.java"; + String fileName2 = "C9947f.java"; + f1 = createFile( + packDir, fileName1, + "package x;\n" + + "\n" + + "class EnsureImpl$1 {\n" + + "}\n"); + f2 = createFile( + packDir, fileName2, + "package x;\n" + + "public final class C9947f {\n" + + " public C9947f() {\n" + + " try {\n" + + " new x.EnsureImpl$1();\n" + + " } catch (Throwable unused) {\n" + + " }\n" + + " }\n" + + "}\n"); + ASTParser parser = ASTParser.newParser(AST_JLS_LATEST); + parser.setResolveBindings(true); + Map options = new HashMap<>(); + JavaCore.setComplianceOptions(JavaCore.VERSION_1_8, options); + parser.setCompilerOptions(options ); + parser.setEnvironment(null, + new String[] { rootDir + "/P/src" }, + null, + true); + parser.createASTs(new String[] { packDir + "/" + fileName1, packDir + "/" + fileName2 }, + null, + new String[] { "Lx/C9947f;" }, + new FileASTRequestor() { + }, + null); + // just ensure the above doesn't throw NPE + } finally { + f1.delete(); + f2.delete(); + packDir.delete(); + } + } +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java new file mode 100644 index 0000000000..5e4a7c5a26 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/CodeSnippetTest.java @@ -0,0 +1,1049 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; +import org.eclipse.jdt.internal.eval.EvaluationResult; +import org.eclipse.jdt.internal.eval.IRequestor; +/** + * Test the code snippet evaluation. + * This assumes that the EvaluationContext class and that the EvaluationResult class + * are working correctly. + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class CodeSnippetTest extends EvaluationTest { +/** + * Creates a new CodeSnippetTest. + */ +public CodeSnippetTest(String name) { + super(name); +} +/** + * Returns a requestor that expects no result. + */ +private IRequestor getNoResultRequestor() { + return new Requestor() { + @Override + public void acceptResult(EvaluationResult result) { + assertTrue("No result", false); + } + }; +} +static { +// TESTS_NAMES = new String[] {"testDiamond"}; +} +public static Test suite() { + return setupSuite(testClass()); +} +@Override +public Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); + defaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE); + defaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, CompilerOptions.WARNING); + return defaultOptions; +} +/** + * Tests code snippet that throws a checked exception. + * (Regression test for 1G0T5XK) + */ +public void testCheckedException() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "try {", + " throw new java.io.IOException();", + "} finally {", + " System.err.println(\"This is an expected exception printed by the target VM:\");", + "}"}), + null); +} +public static Class testClass() { + return CodeSnippetTest.class; +} +/** + * Tests that no errors are reported for an empty statement followed by an expression. + * (Regression test for PR #1G1HGHE) + */ +public void testEmptyStatement() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X {", + " public int fact(int n){", + " return fact0(n, 1);", + " }", + " public int fact0(int n, int acc){", + " if (n <= 1) return acc;", + " return fact0(n - 1, acc * n);", + " }", + "};", + "new X().fact(10)"}), + "3628800".toCharArray()); +} +/** + * Tests that an error is reported for an empty import. + */ +public void testEvaluateEmptyImport() { + try { + char[] importName = new char[0]; + this.context.setImports(new char[][] {importName}); + Requestor requestor = new Requestor(); + this.context.evaluateImports(getEnv(), requestor, getProblemFactory()); + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Problems", result.hasProblems()); + assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType()); + assertEquals("Evaluation ID", importName, result.getEvaluationID()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests that an error is reported for an existing package and a non existing type imports. + */ +public void testEvaluateExistingPackageAndNonExistingTypeImports() { + try { + char[] importName = "non.existing.Type".toCharArray(); + this.context.setImports(new char[][] {"java.lang.reflect.*".toCharArray(), importName}); + Requestor requestor = new Requestor(); + this.context.evaluateImports(getEnv(), requestor, getProblemFactory()); + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Problems", result.hasProblems()); + assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType()); + assertEquals("Evaluation ID", importName, result.getEvaluationID()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests that an error is reported for a non existing package and an existing type imports. + */ +public void testEvaluateNonExistingPackageAndExistingTypeImports() { + try { + char[] importName = "non.existing.*".toCharArray(); + this.context.setImports(new char[][] {importName, "java.math.BigInteger".toCharArray()}); + Requestor requestor = new Requestor(); + this.context.evaluateImports(getEnv(), requestor, getProblemFactory()); + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Problems", result.hasProblems()); + assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType()); + assertEquals("Evaluation ID", importName, result.getEvaluationID()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests that an error is reported for a non existing package import. + */ +public void testEvaluateNonExistingPackageImport() { + try { + char[] importName = "non.existing.*".toCharArray(); + this.context.setImports(new char[][] {importName}); + Requestor requestor = new Requestor(); + this.context.evaluateImports(getEnv(), requestor, getProblemFactory()); + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Problems", result.hasProblems()); + assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType()); + assertEquals("Evaluation ID", importName, result.getEvaluationID()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests that an error is reported for a non existing type import. + */ +public void testEvaluateNonExistingTypeImport() { + try { + char[] importName = "non.existing.Type".toCharArray(); + this.context.setImports(new char[][] {importName}); + Requestor requestor = new Requestor(); + this.context.evaluateImports(getEnv(), requestor, getProblemFactory()); + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Problems", result.hasProblems()); + assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType()); + assertEquals("Evaluation ID", importName, result.getEvaluationID()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests that no errors are reported for valid package and type imports. + */ +public void testEvaluateValidPackageAndTypeImports() { + try { + this.context.setImports(new char[][] {"java.util.Enumeration".toCharArray(), "java.lang.reflect.*".toCharArray()}); + this.context.evaluateImports(getEnv(), getNoResultRequestor(), getProblemFactory()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests that no errors are reported for a valid package import. + */ +public void testEvaluateValidPackageImport() { + try { + this.context.setImports(new char[][] {"java.io.*".toCharArray()}); + this.context.evaluateImports(getEnv(), getNoResultRequestor(), getProblemFactory()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests that no errors are reported for a valid type import. + */ +public void testEvaluateValidTypeImport() { + try { + this.context.setImports(new char[][] {"java.math.BigInteger".toCharArray()}); + this.context.evaluateImports(getEnv(), getNoResultRequestor(), getProblemFactory()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests code snippet that include a finally block triggered by an error. + */ +public void testFinallyError() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "try {", + " throw new Error();", + "} finally {", + " System.err.println(\"This is an expected error printed by the target VM:\");", + "}"}), + null); +} +/** + * Tests code snippet that include one finally block. + */ +public void testFinallyOneBlock() { + evaluateWithExpectedWarningAndDisplayString(buildCharArray(new String[] { + "try {", + " return 1;", + "} finally {", + " return 2;", + "}"}), + new CategorizedProblem[] { + newProblem(IProblem.FinallyMustCompleteNormally, ProblemSeverities.Warning, 30, 40, 4), + }, + "2".toCharArray()); +} +/** + * Tests code snippet that include 2 finally blocks. + */ +public void testFinallyTwoBlock() { + evaluateWithExpectedWarningAndDisplayString(buildCharArray(new String[] { + "try {", + " try {", + " return 1;", + " } finally {", + " return 2;", + " }", + "} finally {", + " return 3;", + "}"}), + new CategorizedProblem[] { + newProblem(IProblem.FinallyMustCompleteNormally, ProblemSeverities.Warning, 40, 51, 5), + newProblem(IProblem.FinallyMustCompleteNormally, ProblemSeverities.Warning, 66, 76, 8), + }, + "3".toCharArray()); +} +/** + * Tests the free return addition at the end of the code snippet + * for an anonymous inner class. + */ +public void testFreeReturnAnonymous() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "new Object() {", + " public String toString() {", + " return \"an object\";", + " }", + "}"}), + "an object".toCharArray()); +} +/** + * Tests the free return addition at the end of the code snippet + * for a class declaration followed by an expression. + */ +public void testFreeReturnClassDeclaration() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class Point {", + " int x;", + " int y;", + " Point(int x, int y) {", + " this.x = x;", + " this.y = y;", + " }", + "}", + "new Point(56, 99).x"}), + "56".toCharArray()); +} +/** + * Tests the free return addition at the end of the code snippet + * for an expression. + */ +public void testFreeReturnExpression() { + evaluateWithExpectedDisplayString("(1 + 2) * 3.0 / 4".toCharArray(), "2.25".toCharArray()); +} +/** + * Tests the free return addition at the end of the code snippet + * for an integer. + */ +public void testFreeReturnInteger() { + evaluateWithExpectedDisplayString("1".toCharArray(), "1".toCharArray()); +} +/** + * Tests the free return addition at the end of the code snippet + * for a local variable declaration followed by an expression. + */ +public void testFreeReturnLocalVar() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "int i = 99;", + "i + 4"}), + "103".toCharArray()); +} +/** + * Tests the free return addition at the end of the code snippet + * for a statement followed by an expression. + */ +public void testFreeReturnStatement() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "int i = 2;", + "for (int j=0;j<10;j++) {", + " i++;", + "}", + "i"}), + "12".toCharArray()); +} +/** + * Tests code snippet that include a package import. + */ +public void testImportPackage() { + try { + this.context.setImports(new char[][] {"java.io.*".toCharArray()}); + evaluateWithExpectedDisplayString("return new File(\"!@#%\").exists();".toCharArray(), "false".toCharArray()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests code snippet that include a type import. + */ +public void testImportType() { + try { + this.context.setImports(new char[][] {"java.math.BigInteger".toCharArray()}); + evaluateWithExpectedDisplayString("return new BigInteger(\"123456789012345678901234567890\");".toCharArray(), "123456789012345678901234567890".toCharArray()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests code snippet that include a type import and a package import. + */ +public void testImportTypeAndPackage() { + try { + this.context.setImports(new char[][] {"java.util.Enumeration".toCharArray(), "java.lang.reflect.*".toCharArray()}); + evaluateWithExpectedDisplayString("Field[] fields = Enumeration.class.getDeclaredFields(); return fields.length;".toCharArray(), "0".toCharArray()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests code snippet that include an anonymous inner class. + */ +public void testInnerClassAnonymous() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "return new Object() {", + " public String toString() {", + " return \"an inner class\";", + " }", + "};"}), + "an inner class".toCharArray()); +} +/** + * Tests code snippet that include a named inner class. + */ +public void testInnerClassNamed() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X {", + " int foo = 1;", + "}", + "return new X().foo;"}), + "1".toCharArray()); +} +/** + * Tests code snippet that include a package declaration. + */ +public void _testPackage() { + if (isJRockitVM()) return; + // TBD: Test access to package private member + // TBD: Test access to package class and members in another package than a java.* package + try { + // declare that the code snippet is run in java.util.zip and access a package private class + this.context.setPackageName("java.util.zip".toCharArray()); + evaluateWithExpectedDisplayString("return ZipConstants.LOCSIG;".toCharArray(), "67324752".toCharArray()); + } finally { + // clean up + this.context.setPackageName(new char[0]); + } +} +/** + * Tests the return value display strings for a boolean. + */ +public void testReturnDisplayStringBoolean() { + evaluateWithExpectedDisplayString("return true;".toCharArray(), "true".toCharArray()); +} +/** + * Tests the return value display strings for a character. + */ +public void testReturnDisplayStringCharacter() { + evaluateWithExpectedDisplayString("return 'c';".toCharArray(), "c".toCharArray()); +} +/** + * Tests the return value display strings for a double. + */ +public void testReturnDisplayStringDouble() { + evaluateWithExpectedDisplayString("return 1.0;".toCharArray(), "1.0".toCharArray()); +} +/** + * Tests the return value display strings for no explicit returned value + * because of an empty code snippet. + */ +public void testReturnDisplayStringEmptyCodeSnippet() { + evaluateWithExpectedDisplayString(new char[0], null); +} +/** + * Tests the return value display strings for a float. + */ +public void testReturnDisplayStringFloat() { + evaluateWithExpectedDisplayString("return (float)1.0;".toCharArray(), "1.0".toCharArray()); +} +/** + * Tests the return value display strings for an integer. + */ +public void testReturnDisplayStringInteger() { + evaluateWithExpectedDisplayString("return 1;".toCharArray(), "1".toCharArray()); +} +/** + * Tests the return value display strings for a long. + */ +public void testReturnDisplayStringLong() { + evaluateWithExpectedDisplayString("return (long)1;".toCharArray(), "1".toCharArray()); +} +/** + * Tests the return value display strings for a code snippet + * with no explicit returned value (implicitly the last expression is + * wrapped inside a return statement). + */ +public void testReturnDisplayStringNoExplicitReturnedValue() { + evaluateWithExpectedDisplayString("new String(\"hello\".toCharArray());".toCharArray(), "hello".toCharArray()); +} +/** + * Tests the return value display strings for an object. + */ +public void testReturnDisplayStringObject() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "return new Object() {", + " public String toString() {", + " return \"an object\";", + " }", + "};"}), + "an object".toCharArray()); +} +/** + * Tests the return value display strings for a short. + */ +public void testReturnDisplayStringShort() { + evaluateWithExpectedDisplayString("return (short)1;".toCharArray(), "1".toCharArray()); +} +/** + * Tests the return value display strings for a String. + */ +public void testReturnDisplayStringString() { + evaluateWithExpectedDisplayString("return \"hello\";".toCharArray(), "hello".toCharArray()); +} +/** + * Tests the return value display strings for a code snippet + * with a void returned value. + */ +public void testReturnDisplayStringVoid() { + evaluateWithExpectedDisplayString("new Thread().start()".toCharArray(), null); +} +/** + * Tests the return type for a boolean. + */ +public void testReturnTypeBoolean() { + evaluateWithExpectedType("return true;".toCharArray(), "boolean".toCharArray()); +} +/** + * Tests the return type for a boolean array. + */ +public void testReturnTypeBooleanArray() { + evaluateWithExpectedType("return new boolean[] {true};".toCharArray(), "[Z".toCharArray()); +} +/** + * Tests the return type for a Boolean object. + */ +public void testReturnTypeBooleanObject() { + evaluateWithExpectedType("return Boolean.valueOf(true);".toCharArray(), "java.lang.Boolean".toCharArray()); +} +/** + * Tests the return type for a char. + */ +public void testReturnTypeChar() { + evaluateWithExpectedType("return 'c';".toCharArray(), "char".toCharArray()); +} +/** + * Tests the return type for a Character object. + */ +public void testReturnTypeCharacterObject() { + evaluateWithExpectedType("return Character.valueOf('c');".toCharArray(), "java.lang.Character".toCharArray()); +} +/** + * Tests the return type for a char array. + */ +public void testReturnTypeCharArray() { + evaluateWithExpectedType("return new char[] {'c'};".toCharArray(), "[C".toCharArray()); +} +/** + * Tests the return type for a double. + */ +public void testReturnTypeDouble() { + evaluateWithExpectedType("return 1.0;".toCharArray(), "double".toCharArray()); +} +/** + * Tests the return type for a double array. + */ +public void testReturnTypeDoubleArray() { + evaluateWithExpectedType("return new double[] {1.0};".toCharArray(), "[D".toCharArray()); +} +/** + * Tests the return type for a Double object. + */ +public void testReturnTypeDoubleObject() { + evaluateWithExpectedType("return Double.valueOf(1.0);".toCharArray(), "java.lang.Double".toCharArray()); +} +/** + * Tests the return type for an empty code snippet. + */ +public void testReturnTypeEmptyCodeSnippet() { + evaluateWithExpectedType(new char[0], null); +} +/** + * Tests the return type for a float. + */ +public void testReturnTypeFloat() { + evaluateWithExpectedType("return (float)1.0;".toCharArray(), "float".toCharArray()); +} +/** + * Tests the return type for a float array. + */ +public void testReturnTypeFloatArray() { + evaluateWithExpectedType("return new float[] {(float)1.0};".toCharArray(), "[F".toCharArray()); +} +/** + * Tests the return type for a Float object. + */ +public void testReturnTypeFloatObject() { + evaluateWithExpectedType("return Float.valueOf(1.0f);".toCharArray(), "java.lang.Float".toCharArray()); +} +/** + * Tests the return type for an int. + */ +public void testReturnTypeInt() { + evaluateWithExpectedType("return 1;".toCharArray(), "int".toCharArray()); +} +/** + * Tests the return type for an Integer object. + */ +public void testReturnTypeIntegerObject() { + evaluateWithExpectedType("return Integer.valueOf(1);".toCharArray(), "java.lang.Integer".toCharArray()); +} +/** + * Tests the return type for a long. + */ +public void testReturnTypeLong() { + evaluateWithExpectedType("return (long)1;".toCharArray(), "long".toCharArray()); +} +/** + * Tests the return type for a long array. + */ +public void testReturnTypeLongArray() { + evaluateWithExpectedType("return new long[] {(long)1};".toCharArray(), "[J".toCharArray()); +} +/** + * Tests the return type for a Long object. + */ +public void testReturnTypeLongObject() { + evaluateWithExpectedType("return Long.valueOf(1);".toCharArray(), "java.lang.Long".toCharArray()); +} +/** + * Tests the return type for no explicit returned value. + */ +public void testReturnTypeNoExplicitReturnedValue() { + evaluateWithExpectedType("new Object();".toCharArray(), "java.lang.Object".toCharArray()); +} +/** + * Tests the return type for an Object. + */ +public void testReturnTypeObject() { + evaluateWithExpectedType("return new Object();".toCharArray(), "java.lang.Object".toCharArray()); +} +/** + * Tests the return type for an Object array. + */ +public void testReturnTypeObjectArray() { + evaluateWithExpectedType("return new Object[] {new Object()};".toCharArray(), "[Ljava.lang.Object;".toCharArray()); +} +/** + * Tests the return type for a short. + */ +public void testReturnTypeShort() { + evaluateWithExpectedType("return (short)1;".toCharArray(), "short".toCharArray()); +} +/** + * Tests the return type for a short array. + */ +public void testReturnTypeShortArray() { + evaluateWithExpectedType("return new short[] {(short)1};".toCharArray(), "[S".toCharArray()); +} +/** + * Tests the return type for a Short object. + */ +public void testReturnTypeShortObject() { + evaluateWithExpectedType("return Short.valueOf((short)1);".toCharArray(), "java.lang.Short".toCharArray()); +} +/** + * Tests the return type for an int array. + */ +public void testReturnTypesIntArray() { + evaluateWithExpectedType("return new int[] {1};".toCharArray(), "[I".toCharArray()); +} +/** + * Tests the return type for a String. + */ +public void testReturnTypeString() { + evaluateWithExpectedType("return \"hello\";".toCharArray(), "java.lang.String".toCharArray()); +} +/** + * Tests the return type for a String array. + */ +public void testReturnTypeStringArray() { + evaluateWithExpectedType("return new String[] {\"hello\"};".toCharArray(), "[Ljava.lang.String;".toCharArray()); +} +/** + * Tests the return type for a void value. + */ +public void testReturnTypeVoid() { + evaluateWithExpectedType("new Thread().start()".toCharArray(), null); +} +/** + * Tests that the run() method defined in an anonymous class doesn't interfer with the + * code snippet support (see PR #1G1C0HR). + */ +public void testRunMethodInAnonymous() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X {", + " public int i = 0;", + " public boolean finished = false;", + "}", + "final X x = new X();", + "(new Thread() {", + " public void run() {", + " for (int i=0;i<10;i++) {", + " try {", + " Thread.currentThread().sleep(10);", + " } catch (InterruptedException e) {", + " }", + " x.i++;", + " }", + " x.finished = true;", + " }", + "}).start();", + "while (!x.finished) Thread.currentThread().sleep(100);", + "x.i"}), + "10".toCharArray()); +} +/** + * Tests that the run() method defined in an anonymous class doesn't interfer with the + * code snippet support (see PR #1G1C0HR). + */ +public void testRunMethodInAnonymous2() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X {", + " public int i = 0;", + " public boolean finished = false;", + "}", + "final X x = new X();", + "(new Thread() {", + " public void run() {", + " for (int i=0;i<10;i++) {", + " try {", + " Thread.currentThread().sleep(10);", + " } catch (InterruptedException e) {", + " }", + " ++x.i;", + " }", + " x.finished = true;", + " }", + "}).start();", + "while (!x.finished) Thread.currentThread().sleep(100);", + "x.i"}), + "10".toCharArray()); +} +/** + * Tests that the run() method defined in an anonymous class doesn't interfer with the + * code snippet support (see PR #1G1C0HR). + */ +public void testRunMethodInAnonymous3() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X {", + " public int i = 0;", + " public boolean finished = false;", + "}", + "final X x = new X();", + "(new Thread() {", + " public void run() {", + " for (int i=0;i<10;i++) {", + " try {", + " Thread.currentThread().sleep(10);", + " } catch (InterruptedException e) {", + " }", + " x.i += 1;", + " }", + " x.finished = true;", + " }", + "}).start();", + "while (!x.finished) Thread.currentThread().sleep(100);", + "x.i"}), + "10".toCharArray()); +} +/** + * Tests that the run() method defined in an anonymous class doesn't interfer with the + * code snippet support (see PR #1G1C0HR). + */ +public void testRunMethodInAnonymous4() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X {", + " public int i = 0;", + " public boolean finished = false;", + "}", + "final X x = new X();", + "(new Thread() {", + " public void run() {", + " for (int i=0;i<10;i++) {", + " try {", + " Thread.currentThread().sleep(10);", + " } catch (InterruptedException e) {", + " }", + " x.i = x.i + 1;", + " }", + " x.finished = true;", + " }", + "}).start();", + "while (!x.finished) Thread.currentThread().sleep(100);", + "x.i"}), + "10".toCharArray()); +} +/** + * Tests that the run() method defined in an anonymous class doesn't interfer with the + * code snippet support (see PR #1G1C0HR). + */ +public void testRunMethodInAnonymous5() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X {", + " public int i = 0;", + " public boolean finished = false;", + " public X self() { return this; }", + "}", + "final X x = new X();", + "(new Thread() {", + " public void run() {", + " for (int i=0;i<10;i++) {", + " try {", + " Thread.currentThread().sleep(10);", + " } catch (InterruptedException e) {", + " }", + " x.self().i++;", + " }", + " x.finished = true;", + " }", + "}).start();", + "while (!x.finished) Thread.currentThread().sleep(100);", + "x.i"}), + "10".toCharArray()); +} +/** + * Tests that the run() method defined in an anonymous class doesn't interfer with the + * code snippet support (see PR #1G1C0HR). + */ +public void testRunMethodInAnonymous6() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X {", + " public int i = 0;", + " public boolean finished = false;", + " public X self() { return this; }", + "}", + "final X x = new X();", + "(new Thread() {", + " public void run() {", + " for (int i=0;i<10;i++) {", + " try {", + " Thread.currentThread().sleep(10);", + " } catch (InterruptedException e) {", + " }", + " ++ (x.self().i);", + " }", + " x.finished = true;", + " }", + "}).start();", + "while (!x.finished) Thread.currentThread().sleep(100);", + "x.i"}), + "10".toCharArray()); +} +/** + * Tests that the run() method defined in an anonymous class doesn't interfer with the + * code snippet support (see PR #1G1C0HR). + */ +public void testRunMethodInAnonymous7() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X {", + " public int i = 0;", + " public boolean finished = false;", + " public X self() { return this; }", + "}", + "final X x = new X();", + "(new Thread() {", + " public void run() {", + " for (int i=0;i<10;i++) {", + " try {", + " Thread.currentThread().sleep(10);", + " } catch (InterruptedException e) {", + " }", + " x.self().i += 1;", + " }", + " x.finished = true;", + " }", + "}).start();", + "while (!x.finished) Thread.currentThread().sleep(100);", + "x.i"}), + "10".toCharArray()); +} +/** + * Tests that the run() method defined in an anonymous class doesn't interfer with the + * code snippet support (see PR #1G1C0HR). + */ +public void testRunMethodInAnonymous8() { + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class X {", + " public int i = 0;", + " public boolean finished = false;", + " public X self() { return this; }", + "}", + "final X x = new X();", + "(new Thread() {", + " public void run() {", + " for (int i=0;i<10;i++) {", + " try {", + " Thread.currentThread().sleep(10);", + " } catch (InterruptedException e) {", + " }", + " x.self().i = x.self().i + 1;", + " }", + " x.finished = true;", + " }", + "}).start();", + "while (!x.finished) Thread.currentThread().sleep(100);", + "x.i"}), + "10".toCharArray()); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=89632 + */ +public void testFor89632() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + try { + this.context.setImports(new char[][] {"java.util.*".toCharArray()}); + evaluateWithExpectedDisplayString( + buildCharArray(new String[] { + "Collection c = new ArrayList();\n" + + "c.add(\"a\");\n" + + "c.add(\"b\");\n" + + "c.add(\"c\"); \n" + + "Iterator i = c.iterator();\n" + + "StringBuffer buffer = new StringBuffer();\n" + + "while (i.hasNext()) {\n" + + " buffer.append(i.next());\n" + + "}" + + "return String.valueOf(buffer);" + }), + "abc".toCharArray()); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=345334 + */ +public void testBug345334() { + Map options = getCompilerOptions(); + if (this.complianceLevel == ClassFileConstants.JDK1_5) { + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotation, CompilerOptions.ERROR); + } else if (this.complianceLevel >= ClassFileConstants.JDK1_6) { + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotation, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, CompilerOptions.ERROR); + } + evaluateWithExpectedDisplayString( + options, + buildCharArray(new String[] { + "return \"SUCCESS\";\n", + }), + "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 field;", + " public X(T param) {", + " field = param;", + " }", + " public T foo() {", + " return field;", + " }", + "};", + "new X<>(\"SUCCESS\").foo();\n"}), + "SUCCESS".toCharArray()); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=464656 + */ +public void testBug464656() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "java.util.stream.Stream s = java.util.stream.Stream.of(\"a\",\"b\");\n" + + "return s.findFirst();"}), + "Optional[a]".toCharArray()); +} + +public void testBug571310_ThisReciever() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class Outer {", + " public int outerFoo() {", + " return 10;", + " }", + " public int boo() {", + " java.util.function.Function f = i -> this.outerFoo() + i;", + " return f.apply(5);", + " }", + "};", + "(new Outer()).boo();"}), + "15".toCharArray()); +} + +public void testBug571310_LocalVarReciever() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class Outer {", + " public int outerFoo(){", + " return 10;", + " }", + " public int boo() {", + " Outer thisVar = this;", + " java.util.function.Function f = (i) -> thisVar.outerFoo() + i;", + " return f.apply(5);", + " }", + "};", + "new Outer().boo();"}), + "15".toCharArray()); +} + +public void testBug571310_QualifiedReciever() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class Outer {", + " public int outerFoo(){", + " return 10;", + " }", + " public java.util.function.Supplier boo() {", + " return new java.util.function.Supplier() {", + " public Integer get() {", + " java.util.function.Function f = (i) -> Outer.this.outerFoo() + i;", + " return f.apply(5);", + " }", + " };", + " }", + "};", + "new Outer().boo().get();"}), + "15".toCharArray()); +} +public void testBug571310_SynthVarReciever() { + if (this.complianceLevel < ClassFileConstants.JDK1_8) { + return; + } + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "class Outer {", + " Integer intField = 10;", + " public java.util.function.Supplier boo() {", + " intField ++;", + " return new java.util.function.Supplier() {", + " public Integer get() {", + " java.util.function.Function f = (i) -> intField.intValue() + i;", + " return f.apply(5);", + " }", + " };", + " }", + "};", + "new Outer().boo().get();"}), + "16".toCharArray()); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationSetup.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationSetup.java new file mode 100644 index 0000000000..aea34aaa02 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationSetup.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.io.InputStream; +import java.net.ServerSocket; +import java.time.Duration; +import java.time.Instant; +import java.util.List; +import java.util.Map; + +import org.eclipse.jdt.core.tests.runtime.LocalVMLauncher; +import org.eclipse.jdt.core.tests.runtime.TargetException; +import org.eclipse.jdt.core.tests.runtime.TargetInterface; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.eval.EvaluationContext; + +import com.sun.jdi.VirtualMachine; +import com.sun.jdi.VirtualMachineManager; +import com.sun.jdi.connect.AttachingConnector; +import com.sun.jdi.connect.Connector; +import com.sun.jdi.connect.IllegalConnectorArgumentsException; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class DebugEvaluationSetup extends EvaluationSetup { + + VirtualMachine vm; + + public DebugEvaluationSetup(long complianceLevel) { + super(complianceLevel); + } + + @Override + protected void setUp() { + if (this.context == null) { + // Launch VM in evaluation mode + try (ServerSocket evalServer = new ServerSocket(0)) { + int debugPort = Util.getFreePort(); + int evalPort = evalServer.getLocalPort(); + LocalVMLauncher launcher; + try { + launcher = LocalVMLauncher.getLauncher(); + launcher.setVMArguments(new String[]{"-verify"}); + launcher.setVMPath(JRE_PATH); + launcher.setEvalPort(evalPort); + launcher.setEvalTargetPath(EVAL_DIRECTORY); + launcher.setDebugPort(debugPort); + this.launchedVM = launcher.launch(); + } catch (TargetException e) { + e.printStackTrace(System.out); + throw new Error(e.getMessage(), e); + } + + // Thread that read the stout of the VM so that the VM doesn't block + try { + startReader("VM's stdout reader", this.launchedVM.getInputStream(), System.out); + } catch (TargetException e) { + e.printStackTrace(System.out); + } + + // Thread that read the sterr of the VM so that the VM doesn't block + try { + startReader("VM's sterr reader", this.launchedVM.getErrorStream(), System.out); + } catch (TargetException e) { + e.printStackTrace(System.out); + } + + // Start JDI connection + int attempts = 30; + Instant start = Instant.now(); + for (int i = 0; i < attempts; i++) { + try { + VirtualMachineManager manager = org.eclipse.jdi.Bootstrap.virtualMachineManager(); + List connectors = manager.attachingConnectors(); + if (connectors.size() == 0) { + System.out.println(getName() + ": could not get attachingConnectors() from VM"); + break; + } + AttachingConnector connector = (AttachingConnector)connectors.get(0); + Map args = connector.defaultArguments(); + Connector.Argument argument = (Connector.Argument)args.get("port"); + if (argument != null) { + argument.setValue(String.valueOf(debugPort)); + } + argument = (Connector.Argument)args.get("hostname"); + if (argument != null) { + argument.setValue(launcher.getTargetAddress()); + } + argument = (Connector.Argument)args.get("timeout"); + if (argument != null) { + argument.setValue("30000"); + } + this.vm = connector.attach(args); + System.out.println(getName() + ": connected to VM using port " + debugPort); + + // workaround pb with some VMs + this.vm.resume(); + + break; + } catch (IllegalConnectorArgumentsException | IOException e) { + e.printStackTrace(System.out); + try { + System.out.println(getName() + ": could not contact the VM at " + launcher.getTargetAddress() + ":" + debugPort + ". Retrying..."); + Thread.sleep(1000); + } catch (InterruptedException e2) { + e2.printStackTrace(System.out); + } + } + } + if (this.vm == null) { + Duration duration = Duration.between(start, Instant.now()); + System.out.println(getName() + ": could NOT contact the VM at " + launcher.getTargetAddress() + ":" + + debugPort + ". Stop trying after " + attempts + " attempts, took " + duration.getSeconds() + + " seconds"); + if (this.launchedVM != null) { + // If the VM is not running, output error stream + try { + if (!this.launchedVM.isRunning()) { + InputStream in = this.launchedVM.getErrorStream(); + int read; + do { + read = in.read(); + if (read != -1) + System.out.print((char)read); + } while (read != -1); + } + } catch (TargetException | IOException e) { + e.printStackTrace(System.out); + } + + // Shut it down + try { + if (this.target != null) { + this.target.disconnect(); // Close the socket first so that the OS resource has a chance to be freed. + } + int retry = 0; + while (this.launchedVM.isRunning() && (++retry < 20)) { + try { + Thread.sleep(retry * 100); + } catch (InterruptedException e) { + e.printStackTrace(System.out); + } + } + if (this.launchedVM.isRunning()) { + this.launchedVM.shutDown(); + } + } catch (TargetException e) { + e.printStackTrace(System.out); + } + } + System.out.println(getName() + ": could not contact the VM at port " + debugPort); + return; + } + + // Create context + this.context = new EvaluationContext(); + + // Create target + this.target = new TargetInterface(); + + // allow 30s max to connect (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=188127) + // Increased to 60 s for https://bugs.eclipse.org/bugs/show_bug.cgi?id=547417 + this.target.connect(evalServer, 60000); + + assertTrue(getName() + ": failed to connect VM server", this.target.isConnected()); + + System.out.println(getName() + ": connected to target using port " + debugPort); + + // Create name environment + this.env = new FileSystem(Util.getJavaClassLibs(), new String[0], null); + } catch (IOException e1) { + e1.printStackTrace(System.out); + throw new Error(getName() + ": Failed to open socket", e1); + } + } + super.setUp(); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java new file mode 100644 index 0000000000..0318b093d9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java @@ -0,0 +1,3114 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.core.compiler.batch.BatchCompiler; +import org.eclipse.jdt.core.tests.runtime.LocalVMLauncher; +import org.eclipse.jdt.core.tests.runtime.TargetInterface; +import org.eclipse.jdt.core.tests.util.CompilerTestSetup; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.eval.EvaluationResult; +import org.eclipse.jdt.internal.eval.InstallException; + +import com.sun.jdi.VirtualMachine; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class DebugEvaluationTest extends EvaluationTest { + static { +// TESTS_NAMES = new String[] { "test069" }; + } + class DebugRequestor extends Requestor { + @Override + public boolean acceptClassFiles(org.eclipse.jdt.internal.compiler.ClassFile[] classFiles, char[] codeSnippetClassName) { + if (DebugEvaluationTest.this.jdiStackFrame == null) { + return super.acceptClassFiles(classFiles, codeSnippetClassName); + } + // Send but don't run + super.acceptClassFiles(classFiles, null); + + // Run if needed + if (codeSnippetClassName != null) { + boolean success = DebugEvaluationTest.this.jdiStackFrame.run(new String(codeSnippetClassName)); + if (success) { + TargetInterface.Result result = DebugEvaluationTest.this.target.getResult(); + if (result.displayString == null) { + acceptResult(new EvaluationResult(null, EvaluationResult.T_CODE_SNIPPET, null, null)); + } else { + acceptResult(new EvaluationResult(null, EvaluationResult.T_CODE_SNIPPET, result.displayString, result.typeName)); + } + } + return success; + } + return true; + } + } + + protected static final String SOURCE_DIRECTORY = Util.getOutputDirectory() + File.separator + "source"; + + public JDIStackFrame jdiStackFrame; + VirtualMachine jdiVM; + + public DebugEvaluationTest(String name) { + super(name); + } + public static Test setupSuite(Class clazz) { + ArrayList testClasses = new ArrayList(); + testClasses.add(clazz); + return buildAllCompliancesTestSuite(clazz, DebugEvaluationSetup.class, testClasses); + } + public static Test suite() { + return setupSuite(testClass()); + } + public static Class testClass() { + return DebugEvaluationTest.class; + } + public void compileAndDeploy(String source, String className) { + resetEnv(); // needed to reinitialize the caches + File directory = new File(SOURCE_DIRECTORY); + if (!directory.exists()) { + if (!directory.mkdir()) { + System.out.println("Could not create " + SOURCE_DIRECTORY); + return; + } + } + String fileName = SOURCE_DIRECTORY + File.separator + className + ".java"; + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); + writer.write(source); + writer.flush(); + writer.close(); + } catch(IOException e) { + e.printStackTrace(); + return; + } + StringBuilder buffer = new StringBuilder(); + buffer + .append("\"") + .append(fileName) + .append("\" -d \"") + .append(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY) + .append("\" -nowarn -g -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append(SOURCE_DIRECTORY) + .append("\""); + BatchCompiler.compile(buffer.toString(), new PrintWriter(System.out), new PrintWriter(System.err), null/*progress*/); + } + public void compileAndDeploy15(String source, String className) { + resetEnv(); // needed to reinitialize the caches + File directory = new File(SOURCE_DIRECTORY); + if (!directory.exists()) { + if (!directory.mkdir()) { + System.out.println("Could not create " + SOURCE_DIRECTORY); + return; + } + } + String fileName = SOURCE_DIRECTORY + File.separator + className + ".java"; + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); + writer.write(source); + writer.flush(); + writer.close(); + } catch(IOException e) { + e.printStackTrace(); + return; + } + StringBuilder buffer = new StringBuilder(); + buffer + .append("\"") + .append(fileName) + .append("\" -d \"") + .append(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY) + .append("\" -nowarn -1.5 -g -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append(SOURCE_DIRECTORY) + .append("\""); + BatchCompiler.compile(buffer.toString(), new PrintWriter(System.out), new PrintWriter(System.err), null/*progress*/); + } + private void evaluate(JDIStackFrame stackFrame, DebugRequestor requestor, char[] snippet) throws InstallException { + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + stackFrame.isStatic(), + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + } + /** + * Generate local variable attribute for these tests. + */ + @Override + public Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return options; + } + @Override + public void initialize(CompilerTestSetup setUp) { + super.initialize(setUp); + this.jdiVM = ((DebugEvaluationSetup)setUp).vm; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + assertNotNull("VM is null, probably VM connection error", this.jdiVM); + } + + public void removeTempClass(String className) { + resetEnv(); // needed to reinitialize the caches + Util.delete(SOURCE_DIRECTORY + File.separator + className + ".java"); + Util.delete(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY + File.separator + className + ".class"); + } + /*public static Test suite(Class evaluationTestClass) { + junit.framework.TestSuite suite = new junit.framework.TestSuite(); + suite.addTest(new DebugEvaluationTest("test018")); + return suite; + }*/ + /** + * Sanity test of IEvaluationContext.evaluate(char[], char[][], char[][], int[], char[], boolean, boolean, IRunner, INameEnvironment, ConfigurableOption[], IRequestor , IProblemFactory) + */ + public void test001() throws Exception { + String userCode = + ""; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return 1;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "1".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); +} +/** + * Return 'this'. + */ +public void test002() throws Exception { + try { + String sourceA002 = + "public class A002 {\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + " public String toString() {\n" + + " return \"hello\";\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA002, "A002"); + String userCode = + "new A002().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A002", + "foo", + -1); + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return this;".toCharArray(); + this.context.evaluate( + snippet, + null, // local var type names + null, // local var names + null, // local modifiers + stackFrame.declaringTypeName(), + stackFrame.isStatic(), + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "hello".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "A002".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A002"); + } +} +/** + * Return 'this'. + */ +public void test003() throws Exception { + try { + String sourceA003 = + "public class A003 {\n" + + " public int foo() {\n" + + " return 2;\n" + + " }\n" + + " public String toString() {\n" + + " return \"hello\";\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA003, "A003"); + String userCode = + "new A003().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A003", + "foo", + -1); + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return this;".toCharArray(); + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + null, // declaring type -- NO DELEGATE THIS + stackFrame.isStatic(), + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should have a problem", result.hasProblems()); // 'this' cannot be referenced since there is no declaring type + assertTrue("Result should not have a value", !result.hasValue()); + } finally { + removeTempClass("A003"); + } +} +/** + * Return 'thread'. + */ +public void test004() throws Exception { + String userCode = + "java.lang.Thread thread = new Thread() {\n" + + " public String toString() {\n" + + " return \"my thread\";\n" + + " }\n" + + "};"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return thread;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "my thread".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "java.lang.Thread".toCharArray(), result.getValueTypeName()); +} +/** + * Return 'x'. + */ +public void test005() throws Exception { + try { + String sourceA005 = + "public class A005 {\n" + + " public int x = 0;\n" + + " public int foo() {\n" + + " x++;\n" + // workaround pb with JDK 1.4.1 that doesn't stop if only return + " return x;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA005, "A005"); + String userCode = + "new A005().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A005", + "foo", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return x;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "0".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A005"); + } +} +/** + * Return 'x' + new Object(){ int foo(){ return 17; }}.foo(); + */ +public void test006() throws Exception { + try { + String sourceA006 = + "public class A006 {\n" + + " public int x = 0;\n" + + " public int foo() {\n" + + " x++;\n" + // workaround pb with JDK 1.4.1 that doesn't stop if only return + " return x;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA006, "A006"); + String userCode = + "new A006().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A006", + "foo", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return x + new Object(){ int foo(){ return 17; }}.foo();".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "17".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A006"); + } +} +/** + * Return a static field. + */ +public void test007() throws Exception { + try { + String sourceA007 = + "public class A007 {\n" + + " public static int X = 1;\n" + + " public int foo() {\n" + + " X++;\n" + // workaround pb with JDK 1.4.1 that doesn't stop if only return + " return X;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA007, "A007"); + String userCode = + "new A007().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A007", + "foo", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return X;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "1".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A007"); + } +} +/** + * Return x + new Object(){ int foo(int x){ return x; }}.foo(14); + */ +public void test008() throws Exception { + try { + String sourceA008 = + "public class A008 {\n" + + " public int x = 0;\n" + + " public int foo() {\n" + + " x++;\n" + // workaround pb with JDK 1.4.1 that doesn't stop if only return + " return x;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA008, "A008"); + String userCode = + "new A008().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A008", + "foo", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return x + new Object(){ int foo(int x){ return x; }}.foo(14);".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "14".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A008"); + } +} +/** + * Free return of local variable 's'. + */ +public void test009() throws Exception { + String userCode = + "String s = \"test009\";\n"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "s".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "test009".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "java.lang.String".toCharArray(), result.getValueTypeName()); +} +/** + * Return 'this'. + */ +public void test010() throws Exception { + try { + String sourceA010 = + "public class A010 {\n" + + " public int foo() {\n" + + " new Object().toString();\n" + // workaround pb with JDK 1.4.1 that doesn't stop if only return + " return -1;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA010, "A010"); + String userCode = + "A010 a = new A010() {\n" + + " public String toString() {\n" + + " return \"my object\";\n" + + " }\n" + + "};\n" + + "a.foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A010", + "foo", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return this;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "my object".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "A010".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A010"); + } +} +/** + * Return local variable 'v'. + */ +public void test011() throws Exception { + String userCode = + "String s = \"s\";\n" + + "java.util.Vector v = new java.util.Vector();\n" + + "v.addElement(s);\n"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return v;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "[s]".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "java.util.Vector".toCharArray(), result.getValueTypeName()); +} +/** + * Set local variable 'date'. + */ +public void _test012() throws Exception { + String userCode = + "java.util.GregorianCalendar cal = new java.util.GregorianCalendar();\n" + + "java.util.Date date = cal.getGregorianChange();\n" + + "System.out.println(\"Old date =\t\" + date.toString());"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "date = new java.util.Date();".toCharArray(); + evaluate(stackFrame, requestor, snippet); + requestor = new DebugRequestor(); + userCode = "System.out.println(\"new date =\t\" + date.toString());\n" + + "System.out.println(\"cal.getGregorianChange() =\t\" + cal.getGregorianChange());\n" + + "return date.after(cal.getGregorianChange());"; + snippet = userCode.toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "true".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "boolean".toCharArray(), result.getValueTypeName()); +} +/** + * Set local variable 'i'. + */ +// disabled since result has problem: Pb(2) int cannot be resolved to a type +public void _test013() throws Exception { + String userCode = "int i = 0;"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "i = -1;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + requestor = new DebugRequestor(); + snippet = "return i != 0;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "true".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "boolean".toCharArray(), result.getValueTypeName()); +} +/** + * Set local variable 'i'. + */ +// disabled since result has problem: Pb(2) int cannot be resolved to a type +public void _test014() throws Exception { + String userCode = "int i = 0;"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "i++;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + requestor = new DebugRequestor(); + snippet = "return i!= 0;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "true".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "boolean".toCharArray(), result.getValueTypeName()); +} +/** + * Check java.lang.System.out != null + */ +// disabled since result has problem: Pb(2) int cannot be resolved to a type +public void _test015() throws Exception { + String userCode = "int i = 0;"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "java.lang.System.setOut(new java.io.PrintStream(new java.io.OutputStream()));".toCharArray(); + evaluate(stackFrame, requestor, snippet); + + requestor = new DebugRequestor(); + snippet = "return java.lang.System.out != null;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "true".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "boolean".toCharArray(), result.getValueTypeName()); +} +/** + * Check java.lang.System.out == null + */ +public void test016() throws Exception { + String userCode = ""; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "java.lang.System.setOut(null);".toCharArray(); + evaluate(stackFrame, requestor, snippet); + requestor = new DebugRequestor(); + snippet = "return java.lang.System.out == null;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "true".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "boolean".toCharArray(), result.getValueTypeName()); +} +/** + * Check the third prime number is 5 + */ +public void test017() throws Exception { + String userCode = ""; + + JDIStackFrame stackFrame = new JDIStackFrame(this.jdiVM, this, userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = + ("class Eratosthenes {\n" + + " int[] primeNumbers;\n" + + "\n" + + " public Eratosthenes(int n) {\n" + + " primeNumbers = new int[n + 1];\n" + + "\n" + + " for (int i = 2; i <= n; i++) {\n" + + " primeNumbers[i] = i;\n" + + " }\n" + + " int p = 2;\n" + + " while (p * p <= n) {\n" + + " int j = 2 * p;\n" + + " while (j <= n) {\n" + + " primeNumbers[j] = 0;\n" + + " j += p;\n" + + " }\n" + + " do {\n" + + " p++;\n" + + " } while (primeNumbers[p] == 1);\n" + + " }\n" + + " }\n" + + "}\n" + + "int[] primes = new Eratosthenes(10).primeNumbers;\n" + + "int i = 0;\n" + + "int max = primes.length;\n" + + "int j = 0;\n" + + "for (; i < max && j != 3; i++) {\n" + + " if (primes[i] != 0) {\n" + + " j++;\n" + + " }\n" + + "}\n" + + "return primes[i-1];").toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "5".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); +} +/** + * changing the value of a public field + */ +public void test018() throws Exception { + try { + String sourceA018 = + "public class A018 {\n" + + " public int x = 1;\n" + + " public int foo() {\n" + + " x++;\n" + // workaround pb with JDK 1.4.1 that doesn't stop if only return + " return x;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA018, "A018"); + String userCode = + "new A018().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A018", + "foo", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "x = 5;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + requestor = new DebugRequestor(); + snippet = "return x;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "5".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A018"); + } +} +/** + * Access to super reference + */ +// disabled since result has problem: Pb(422) super cannot be used in the code snippet code +public void test019() throws Exception { + try { + String sourceA019 = + "public class A019 {\n" + + " public int x = 1;\n" + + " public int foo() {\n" + + " x++;\n" + // workaround pb with JDK 1.4.1 that doesn't stop if only return + " return x;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA019, "A019"); + String userCode = + "new A019().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A019", + "foo", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return super.clone().equals(this);".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should have problems", result.hasProblems()); + assertTrue("Code snippet should have problems", result.hasProblems()); + assertEquals("Wrong size", 1, result.getProblems().length); + assertEquals("Wrong pb", 422, result.getProblems()[0].getID() & IProblem.IgnoreCategoriesMask); + } finally { + removeTempClass("A019"); + } +} +/** + * Implicit message expression + */ +public void test020() throws Exception { + try { + String sourceA = + "public class A {\n" + + "\tObject o = null;\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "\tpublic Object bar2() {\n" + + "\t\treturn new Object();\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA, "A"); + + String userCode = "new A().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return foo();".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A"); + } +} +/** + * Implicit message expression + */ +public void test021() throws Exception { + try { + String sourceA21 = + "public class A21 {\n" + + "\tObject o = null;\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "\tpublic Object bar2() {\n" + + "\t\treturn \"toto\";\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA21, "A21"); + + String userCode = "new A21().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A21", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "o = bar2();".toCharArray(); + evaluate(stackFrame, requestor, snippet); + requestor = new DebugRequestor(); + snippet = "return o;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "toto".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "java.lang.Object".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A21"); + } +} +/** + * Qualified Name Reference: b.s + */ +public void test022() throws Exception { + try { + String sourceB22 = + "public class B22 {\n" + + "\tpublic String s = null;\n" + + "}"; + compileAndDeploy(sourceB22, "B22"); + + String sourceA22 = + "public class A22 {\n" + + "\tpublic B22 b = new B22();\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "\tpublic Object bar2() {\n" + + "\t\treturn \"toto\";\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA22, "A22"); + + String userCode = "new A22().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A22", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "b.s = \"toto\"".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + + requestor = new DebugRequestor(); + snippet = "return b.s;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "toto".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "java.lang.String".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("B22"); + removeTempClass("A22"); + } +} +/** + * Qualified Name Reference: b.c.c + */ +public void test023() throws Exception { + try { + String sourceC23 = + "public class C23 {\n" + + "\tpublic String c = null;\n" + + "}"; + compileAndDeploy(sourceC23, "C23"); + String sourceB23 = + "public class B23 {\n" + + "\tpublic C23 c = new C23();\n" + + "}"; + compileAndDeploy(sourceB23, "B23"); + + String sourceA23 = + "public class A23 {\n" + + "\tpublic B23 b = new B23();\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "\tpublic Object bar2() {\n" + + "\t\treturn \"toto\";\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA23, "A23"); + + String userCode = "new A23().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A23", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "b.c.c = \"toto\"".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + + requestor = new DebugRequestor(); + snippet = "return b.c.c;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "toto".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "java.lang.String".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("C23"); + removeTempClass("B23"); + removeTempClass("A23"); + } +} +/** + * Array Reference + */ +public void test024() throws Exception { + try { + String sourceC24 = + "public class C24 {\n" + + "\tpublic int[] tab = {1,2,3,4,5};\n" + + "}"; + compileAndDeploy(sourceC24, "C24"); + + + String sourceB24 = + "public class B24 {\n" + + "\tpublic C24 c = new C24();\n" + + "}"; + compileAndDeploy(sourceB24, "B24"); + + String sourceA24 = + "public class A24 {\n" + + "\tpublic B24 b = new B24();\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "\tpublic Object bar2() {\n" + + "\t\treturn \"toto\";\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA24, "A24"); + + String userCode = "new A24().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A24", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "b.c.tab[3] = 8".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + + requestor = new DebugRequestor(); + snippet = "return b.c.tab[3];".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "8".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("C24"); + removeTempClass("B24"); + removeTempClass("A24"); + } +} +/** + * Array Reference + */ +public void test025() throws Exception { + try { + String sourceA25 = + "public class A25 {\n" + + "\tpublic String[] tabString = new String[2];\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "\tpublic Object bar2() {\n" + + "\t\treturn \"toto\";\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA25, "A25"); + + String userCode = "new A25().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A25", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "tabString[1] = \"toto\"".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + + requestor = new DebugRequestor(); + snippet = "return tabString[1];".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "toto".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "java.lang.String".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A25"); + } +} +/** + * Array Reference + */ +public void test026() throws Exception { + try { + String sourceA26 = + "public class A26 {\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA26, "A26"); + + String userCode = "new A26().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A26", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = + ("int[] tab = new int[1];\n" + + "tab[0] = foo();\n" + + "tab[0]").toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A26"); + } +} +/** + * Array Reference + */ +public void test027() throws Exception { + try { + String sourceA27 = + "public class A27 {\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "\tpublic int bar2(int i) {\n" + + "\t\tif (i == 2) {\n" + + "\t\t\treturn 3;\n" + + "\t\t} else {\n" + + "\t\t\treturn 4;\n" + + "\t\t}\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA27, "A27"); + + String userCode = "new A27().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A27", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = + ("int[] tab = new int[] { 1, 2, 3, 4, 5};\n" + + "switch(foo()) {\n" + + "case 1 : return -1;\n" + + "case 2 : return tab[bar2(foo())];\n" + + "default: return -5;}").toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "4".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A27"); + } +} +/** + * Array Reference + */ +public void test028() throws Exception { + try { + String sourceA28 = + "public class A28 {\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "\tpublic int bar2(int i) {\n" + + "\t\tif (i == 2) {\n" + + "\t\t\treturn 3;\n" + + "\t\t} else {\n" + + "\t\t\treturn 4;\n" + + "\t\t}\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA28, "A28"); + + String userCode = "new A28().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A28", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = + ("int[] tab = new int[] { 1, 2, 3, 4, 5};\n" + + "int i =3;\n" + + "switch(foo()) {\n" + + "case 0 : return -1;\n" + + "case 1 : return tab[bar2(foo())];\n" + + "}\n" + + "return tab[i++];").toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "4".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A28"); + } +} +/** + * Array Reference + */ +public void test029() throws Exception { + try { + String sourceA29 = + "public class A29 {\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "\tpublic int bar2(int i) {\n" + + "\t\tif (i == 2) {\n" + + "\t\t\treturn 3;\n" + + "\t\t} else {\n" + + "\t\t\treturn 4;\n" + + "\t\t}\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA29, "A29"); + + String userCode = "new A29().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A29", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = + ("int[] tab = new int[] { 1, 2, 3, 4, 5};\n" + + "int i =3;\n" + + "switch(foo()) {\n" + + "case 0 : return -1;\n" + + "case 1 : return tab[bar2(foo())];\n" + + "}\n" + + "return tab[++i];").toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "5".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A29"); + } +} +/** + * Array Reference: ArrayIndexOutOfBoundException + */ +public void test030() throws Exception { + try { + String sourceA30 = + "public class A30 {\n" + + "\tpublic int foo() {\n" + + "\t\treturn 2;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "\tpublic int bar2(int i) {\n" + + "\t\tif (i == 2) {\n" + + "\t\t\treturn 3;\n" + + "\t\t} else {\n" + + "\t\t\treturn 4;\n" + + "\t\t}\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA30, "A30"); + + String userCode = "new A30().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A30", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = + ("try {\n" + + "int[] tab = new int[] { 1, 2, 3, 4};\n" + + "int i =3;\n" + + "switch(foo()) {\n" + + "case 0 : return -1;\n" + + "case 1 : return tab[bar2(foo())];\n" + + "}\n" + + "return tab[++i];" + + "} catch(ArrayIndexOutOfBoundsException e) {\n" + + "return -2;\n" + + "}").toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "-2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A30"); + } +} +/** + * Read access to an instance private member of the enclosing class + */ +public void test031() throws Exception { + try { + String sourceA31 = + "public class A31 {\n" + + "\tprivate int i = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA31, "A31"); + + String userCode = "new A31().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A31", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return i;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A31"); + } +} +/** + * Read access to a instance private member of the class different from the enclosing class + */ +public void test032() throws Exception { + try { + String sourceA32 = + "public class A32 {\n" + + "\tprivate int i = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA32, "A32"); + + String sourceB32 = + "public class B32 {\n" + + "\tprivate int j = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceB32, "B32"); + + String userCode = "new A32().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A32", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return new B32().j;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", result.hasProblems()); + CategorizedProblem[] problems = result.getProblems(); + StringBuilder buffer = null; + for (int i = 0, max = problems.length; i < max; i++){ + if (problems[i].isError()){ + if (buffer == null) buffer = new StringBuilder(10); + buffer.append(problems[i].getMessage()); + buffer.append('|'); + } + } + assertEquals("Unexpected errors", + "The field B32.j is not visible|", + buffer == null ? "none" : buffer.toString()); + } finally { + removeTempClass("B32"); + removeTempClass("A32"); + } +} +/** + * Read access to an instance private member of the enclosing class + */ +public void test033() throws Exception { + try { + String sourceA33 = + "public class A33 {\n" + + "\tprivate long l = 2000000L;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA33, "A33"); + + String userCode = "new A33().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A33", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = + ("try {\n" + + "Class c = Class.forName(\"A33\");\n" + + "java.lang.reflect.Field field = c.getDeclaredField(\"l\");\n" + + "field.setAccessible(true);\n" + + "java.lang.reflect.Constructor constr = c.getConstructor(new Class[] {});\n" + + "Object o = constr.newInstance(new Object[]{});\n" + + "System.out.println(field.getInt(o));\n" + + "} catch(Exception e) {}\n" + + "return l;").toCharArray(); + final Map compilerOptions = getCompilerOptions(); + compilerOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.IGNORE); + + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + stackFrame.isStatic(), + stackFrame.isConstructorCall(), + getEnv(), + compilerOptions, + requestor, + getProblemFactory()); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2000000".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "long".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A33"); + } +} +/** + * Write access to an instance private member of the enclosing class + */ +public void test034() throws Exception { + try { + String sourceA34 = + "public class A34 {\n" + + "\tprivate long l = 2000000L;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA34, "A34"); + + String userCode = "new A34().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A34", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = + ("l = 100L;\n" + + "return l;").toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "100".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "long".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A34"); + } +} +/** + * Read access to a static private member of the enclosing class + */ +public void test035() throws Exception { + try { + String sourceA35 = + "public class A35 {\n" + + "\tstatic private int i = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA35, "A35"); + + String userCode = "new A35().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame( + this.jdiVM, + this, + userCode, + "A35", + "bar", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return i;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A35"); + } +} +/** + * Coumpound assignement to an instance private member of the enclosing class + */ +public void test036() throws Exception { + try { + String sourceA36 = + "public class A36 {\n" + + "\tprivate long l = 2000000L;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA36, "A36"); + + String userCode = "new A36().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A36", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = + ("l+=4;\n" + + "return l;").toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2000004".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "long".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A36"); + } +} +/** + * Coumpound assignement to an instance private member of the enclosing class + */ +public void test037() throws Exception { + try { + String sourceA37 = + "public class A37 {\n" + + "\tprivate long l = 2000000L;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA37, "A37"); + + String userCode = "new A37().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A37", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = + ("l++;\n" + + "return l;").toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2000001".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "long".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A37"); + } +} +/** + * Coumpound assignement to an instance private member of the enclosing class + */ +public void test038() throws Exception { + try { + String sourceA38 = + "public class A38 {\n" + + "\tprivate long l = 2000000L;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA38, "A38"); + + String userCode = "new A38().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A38", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return l++;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2000000".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "long".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A38"); + } +} +/** + * Coumpound assignement to an static private member of the enclosing class + */ +public void test039() throws Exception { + try { + String sourceA39 = + "public class A39 {\n" + + "\tstatic private int i = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA39, "A39"); + + String userCode = "new A39().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A39", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return A39.i;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A39"); + } +} +/** + * Coumpound assignement to an static private member of the enclosing class + */ +public void test040() throws Exception { + try { + String sourceA40 = + "public class A40 {\n" + + "\tstatic private int[] tab = new int[] {1, 2};\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA40, "A40"); + + String userCode = "new A40().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A40", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return A40.tab.length;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A40"); + } +} +/** + * Coumpound assignement to an static private final member of the enclosing class + */ +public void test041() throws Exception { + try { + String sourceA41 = + "public class A41 {\n" + + "\tstatic private final int[] tab = new int[] {1, 2};\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA41, "A41"); + + String userCode = "new A41().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A41", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return A41.tab.length;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A41"); + } +} +/** + * Coumpound assignement to an static private final member of the enclosing class + */ +public void test042() throws Exception { + try { + String sourceA42 = + "public class A42 {\n" + + "\tstatic private int Counter = 0;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA42, "A42"); + + String userCode = "new A42().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A42", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return ++A42.Counter;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "1".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A42"); + } +} +/** + * Coumpound assignement to an static private final member of the enclosing class + */ +public void test043() throws Exception { + try { + String sourceA43 = + "public class A43 {\n" + + "\tstatic private int Counter = 0;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA43, "A43"); + + String userCode = "new A43().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A43", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "A43.Counter++; return A43.Counter;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "1".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A43"); + } +} +/** + * Coumpound assignement to an static private final member of the enclosing class + */ +public void test044() throws Exception { + try { + String sourceA44 = + "public class A44 {\n" + + "\tstatic private int Counter = 0;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA44, "A44"); + + String userCode = "new A44().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A44", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "int j = A44.Counter++; return A44.Counter + j;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "1".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A44"); + } +} +/** + * Coumpound assignement to an static private final member of the enclosing class + */ +public void test045() throws Exception { + try { + String sourceA45 = + "public class A45 {\n" + + "\tstatic private int Counter = 0;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA45, "A45"); + + String userCode = "new A45().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A45", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "int j = ++A45.Counter; return A45.Counter + j;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A45"); + } +} +/** + * Coumpound assignement to an static protected final member of the enclosing class + */ +public void test046() throws Exception { + try { + String sourceA46 = + "public class A46 {\n" + + "\tstatic protected int Counter = 0;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA46, "A46"); + + String userCode = "new A46().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A46", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "int j = ++A46.Counter; return A46.Counter + j;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A46"); + } +} +/** + * Return the value of a private static field throught a private static field + */ +public void test047() throws Exception { + try { + String sourceA47 = + "public class A47 {\n" + + "\tstatic private A47 instance = new A47();\n" + + "\tstatic private int Counter = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA47, "A47"); + + String userCode = "new A47().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A47", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return A47.instance.Counter;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A47"); + } +} +/** + * Return the value of a private static field throught a private static field + * Using private field emulation on a field reference. + */ +public void test048() throws Exception { + try { + String sourceA48 = + "public class A48 {\n" + + "\tstatic private A48 instance = new A48();\n" + + "\tstatic private int Counter = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA48, "A48"); + + String userCode = "new A48().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A48", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return new A48().instance.Counter;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A48"); + } +} +/** + * Compound assignment of a private field. + * Using private field emulation on a field reference. + */ +public void test049() throws Exception { + try { + String sourceA49 = + "public class A49 {\n" + + "\tstatic private A49 instance = new A49();\n" + + "\tstatic private int Counter = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA49, "A49"); + + String userCode = "new A49().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A49", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return ++(new A49().Counter);".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A49"); + } +} +/** + * Compound assignment of a private field. + * Using private field emulation on a field reference. + */ +public void test050() throws Exception { + try { + String sourceA50 = + "public class A50 {\n" + + "\tstatic private A50 instance = new A50();\n" + + "\tstatic private int Counter = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA50, "A50"); + + String userCode = "new A50().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A50", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "A50 a = new A50(); a.Counter = 5; return a.Counter;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "5".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A50"); + } +} +/** + * Assignment of a private field. + * Using private field emulation on a field reference. + */ +public void test051() throws Exception { + try { + String sourceA51 = + "public class A51 {\n" + + "\tstatic private A51 instance = new A51();\n" + + "\tstatic private int Counter = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA51, "A51"); + + String userCode = "new A51().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A51", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "Counter = 5; return Counter;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "5".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A51"); + } +} +/** + * Assignment of a private field. + * Using private field emulation on a field reference. + */ +public void test052() throws Exception { + try { + String sourceA52 = + "public class A52 {\n" + + "\tstatic private A52 instance = new A52();\n" + + "\tstatic private int Counter = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA52, "A52"); + + String userCode = "new A52().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A52", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "this.Counter = 5; return this.Counter;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "5".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A52"); + } +} +/** + * Post assignement of a private field. + * Using private field emulation on a field reference. + */ +public void test053() throws Exception { + try { + String sourceA53 = + "public class A53 {\n" + + "\tstatic private A53 instance = new A53();\n" + + "\tstatic private int Counter = 2;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA53, "A53"); + + String userCode = "new A53().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A53", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "this.Counter++; return this.Counter;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A53"); + } +} +/** + * Post assignement of a private field. + * Using private field emulation on a field reference. + */ +public void test054() throws Exception { + try { + String sourceA54 = + "public class A54 {\n" + + "\tstatic private A54 instance = new A54();\n" + + "\tstatic private long Counter = 2L;\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA54, "A54"); + + String userCode = "new A54().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A54", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "this.Counter++; return this.Counter;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "long".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A54"); + } +} +/** + * Read access to a private method. + */ +public void test055() throws Exception { + try { + String sourceA55 = + "public class A55 {\n" + + "\tprivate int foo() {;\n" + + "\t\treturn 3;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA55, "A55"); + + String userCode = "new A55().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A55", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return foo();".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A55"); + } +} +/** + * Read access to a private method. + */ +public void test056() throws Exception { + try { + String sourceA56 = + "public class A56 {\n" + + "\tprivate Integer foo() {;\n" + + "\t\treturn new Integer(3);\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA56, "A56"); + + String userCode = "new A56().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A56", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return foo().intValue();".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A56"); + } +} +/** + * Read access to a private method. + */ +public void test057() throws Exception { + try { + String sourceA57 = + "public class A57 {\n" + + "\tprivate Integer foo(int i) {;\n" + + "\t\treturn new Integer(i);\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA57, "A57"); + + String userCode = "new A57().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A57", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return foo(3).intValue();".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A57"); + } +} +/** + * Read access to a private method. + */ +public void test058() throws Exception { + try { + String sourceA58 = + "public class A58 {\n" + + "\tprivate Integer foo(int i, int[] tab) {;\n" + + "\t\treturn new Integer(i + tab.length);\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA58, "A58"); + + String userCode = "new A58().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A58", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "int[] tab = new int[] {1,2,3};return foo(0, tab).intValue();".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A58"); + } +} +/** + * Read access to a private method. + */ +public void test059() throws Exception { + try { + String sourceA59 = + "public class A59 {\n" + + "\tprivate Integer foo(int i, Object[][] tab) {;\n" + + "\t\treturn new Integer(i + tab.length);\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA59, "A59"); + + String userCode = "new A59().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A59", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "Object[][] tab = new Object[0][0];return foo(3, tab).intValue();".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A59"); + } +} +/** + * Read access to a private method. + */ +public void test060() throws Exception { + try { + String sourceA60 = + "public class A60 {\n" + + "\tprivate int i;\n" + + "\tpublic A60() {;\n" + + "\t}\n" + + "\tprivate A60(int i) {;\n" + + "\t\tthis.i = i;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA60, "A60"); + + String userCode = "new A60().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A60", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return new A60(3).i;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A60"); + } +} +/** + * Read access to a private method. + */ +public void test061() throws Exception { + try { + String sourceA61 = + "public class A61 {\n" + + "\tprivate int i;\n" + + "\tpublic A61() {;\n" + + "\t}\n" + + "\tprivate A61(int[] tab) {;\n" + + "\t\tthis.i = tab.length;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy(sourceA61, "A61"); + + String userCode = "new A61().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A61", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return new A61(new int[] {1,2,3}).i;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A61"); + } +} +/** + * Static context with a declaring type. + */ +public void test062() throws Exception { + try { + String sourceA62 = + "public class A62 {\n" + + " public static void bar() {\n" + + " }\n" + + "}"; + compileAndDeploy(sourceA62, "A62"); + + String userCode = "new A62().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A62", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "1 + 1".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "2".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A62"); + } +} +/** + * Return non-static field in static environment. + */ +public void testNegative001() throws InstallException { + try { + String sourceANegative001 = + "public class ANegative001 {\n" + + " public int x = 1;\n" + + " public int foo() {\n" + + " x++;\n" + // workaround pb with JDK 1.4.1 that doesn't stop if only return + " return x;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceANegative001, "ANegative001"); + String userCode = + "new ANegative001().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "ANegative001", + "foo", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return this.x;".toCharArray(); + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + true, // force is static + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + CategorizedProblem[] problems = result.getProblems(); + StringBuilder buffer = null; + for (int i = 0, max = problems.length; i < max; i++){ + if (problems[i].isError()){ + if (buffer == null) buffer = new StringBuilder(10); + buffer.append(problems[i].getMessage()); + buffer.append('|'); + } + } + assertEquals("Unexpected errors", + "Cannot use this in a static context|", + buffer == null ? "none" : buffer.toString()); + } finally { + removeTempClass("ANegative001"); + } +} +/** + * Return non-static field in static environment. + */ +public void testNegative002() throws Exception { + try { + String sourceANegative002 = + "public class ANegative002 {\n" + + " public int x = 1;\n" + + " public int foo() {\n" + + " x++;\n" + // workaround pb with JDK 1.4.1 that doesn't stop if only return + " return x;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceANegative002, "ANegative002"); + String userCode = + "new ANegative002().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "ANegative002", + "foo", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return x;".toCharArray(); + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + true, // force is static + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + CategorizedProblem[] problems = result.getProblems(); + StringBuilder buffer = null; + for (int i = 0, max = problems.length; i < max; i++){ + if (problems[i].isError()){ + if (buffer == null) buffer = new StringBuilder(10); + buffer.append(problems[i].getMessage()); + buffer.append('|'); + } + } + assertEquals("Unexpected errors", + "Cannot make a static reference to the non-static field x|", + buffer == null ? "none" : buffer.toString()); + } finally { + removeTempClass("ANegative002"); + } +} +/** + * Return inexisting field in static environment. + */ +public void testNegative003() throws InstallException { + try { + String sourceANegative003 = + "public class ANegative003 {\n" + + " public int x = 1;\n" + + " public int foo() {\n" + + " x++;\n" + // workaround pb with JDK 1.4.1 that doesn't stop if only return + " return x;\n" + + " }\n" + + "}"; + compileAndDeploy(sourceANegative003, "ANegative003"); + String userCode = + "new ANegative003().foo();"; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode, + "ANegative003", + "foo", + -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return zork;".toCharArray(); + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + true, // force is static + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + CategorizedProblem[] problems = result.getProblems(); + StringBuilder buffer = null; + for (int i = 0, max = problems.length; i < max; i++){ + if (problems[i].isError()){ + if (buffer == null) buffer = new StringBuilder(10); + buffer.append(problems[i].getMessage()); + buffer.append('|'); + } + } + assertEquals("Unexpected errors", + "zork cannot be resolved to a variable|", + buffer == null ? "none" : buffer.toString()); + } finally { + removeTempClass("ANegative003"); + } +} +/** + * Check java.lang.System.out = null returns an error + */ +public void testNegative004() throws InstallException { + String userCode = ""; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "java.lang.System.out = null;".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + CategorizedProblem[] problems = result.getProblems(); + StringBuilder buffer = null; + for (int i = 0, max = problems.length; i < max; i++){ + if (problems[i].isError()){ + if (buffer == null) buffer = new StringBuilder(10); + buffer.append(problems[i].getMessage()); + buffer.append('|'); + } + } + assertEquals("Unexpected errors", + "The final field System.out cannot be assigned|", + buffer == null ? "none" : buffer.toString()); +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=102778 + */ +public void test063() throws Exception { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + try { + String sourceA63 = + "public class A63 {\n" + + " public static void bar() {\n" + + " }\n" + + "}"; + compileAndDeploy15(sourceA63, "A63"); + + String userCode = "new A63().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A63", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = ("int[] tab = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9 };\n" + + "int sum = 0;\n" + + "for (int i : tab) {\n" + + " sum += i;\n" + + "}\n" + + "sum").toCharArray(); + Map compilerOpts = getCompilerOptions(); + compilerOpts.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + compilerOpts.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + compilerOpts.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_2); + + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + stackFrame.isStatic(), + stackFrame.isConstructorCall(), + getEnv(), + compilerOpts, + requestor, + getProblemFactory()); + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "45".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A62"); + } +} +public void test065() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + try { + String sourceA65 = + "public class A65 {\n" + + "\tprivate int i;\n" + + "\tpublic A65() {;\n" + + "\t}\n" + + "\tprivate A65(int i) {;\n" + + "\t\tthis.i = i;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy15(sourceA65, "A65"); + + String userCode = "new A65().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A65", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return new A65(3).i;".toCharArray(); + try { + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + stackFrame.isStatic(), + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + } catch (InstallException e) { + assertTrue("No targetException " + e.getMessage(), false); + } + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A65"); + } +} +public void test066() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + try { + String sourceA66 = + "public class A66 {\n" + + "\tprivate int i;\n" + + "\tpublic A66() {;\n" + + "\t}\n" + + "\tprivate int foo(int i) {;\n" + + "\t\treturn i;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy15(sourceA66, "A66"); + + String userCode = "new A66().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A66", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return this.foo(3);".toCharArray(); + try { + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + stackFrame.isStatic(), + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + } catch (InstallException e) { + assertTrue("No targetException " + e.getMessage(), false); + } + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "3".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A66"); + } +} +public void test067() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + try { + String sourceA67 = + "import java.util.List;\n" + + "public class A67 {\n" + + " public static String toString(List list) {\n" + + " StringBuilder builder = new StringBuilder(\"{\");\n" + + " for (Object o : list) {" + + " builder.append(o);\n" + + " }\n" + + " builder.append(\"}\");\n" + + " return String.valueOf(builder);\n" + + " }\n" + + " public void bar() {\n" + + " }\n" + + "}"; + compileAndDeploy15(sourceA67, "A67"); + + String userCode = "new A67().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A67", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = ("java.util.ArrayList list = new java.util.ArrayList();\n" + + "list.add(\"Test\");\n" + + "list.add(\"Hello\");\n" + + "list.add(\"World\");\n" + + "return A67.toString(list);").toCharArray(); + try { + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + stackFrame.isStatic(), + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + } catch (InstallException e) { + assertTrue("No targetException " + e.getMessage(), false); + } + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", !result.hasProblems()); + assertTrue("Result should have a value", result.hasValue()); + assertEquals("Value", "{TestHelloWorld}".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "java.lang.String".toCharArray(), result.getValueTypeName()); + } finally { + removeTempClass("A67"); + } +} +public void test068() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + try { + String sourceSuperA68 = + "public class SuperA68 {\n" + + "\tprivate int i;\n" + + "\tpublic SuperA68() {\n" + + "\t}\n" + + "\tpublic int foo(int i) {;\n" + + "\t\treturn i;\n" + + "\t}\n" + + "}"; + compileAndDeploy15(sourceSuperA68, "SuperA68"); + String sourceA68 = + "public class A68 extends SuperA68 {\n" + + "\tprivate int i;\n" + + "\tpublic A68() {\n" + + "\t}\n" + + "\tpublic int foo(int i) {\n" + + "\t\treturn i;\n" + + "\t}\n" + + "\tpublic void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy15(sourceA68, "A68"); + + String userCode = "new A68().bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A68", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "return super.foo(3);".toCharArray(); + try { + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + stackFrame.isStatic(), + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + } catch (InstallException e) { + assertTrue("No targetException " + e.getMessage(), false); + } + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should have problems", result.hasProblems()); + assertEquals("Wrong size", 1, result.getProblems().length); + assertEquals("Wrong pb", 422, result.getProblems()[0].getID() & IProblem.IgnoreCategoriesMask); + } finally { + removeTempClass("A68"); + removeTempClass("SuperA68"); + } +} +public void test069() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) return; + try { + String sourceA69 = + "public enum A69 {\n" + + "\tA(2), B(1);\n" + + "\tprivate int i;\n" + + "\tprivate A69(int i) {\n" + + "\t\tthis.i = i;\n" + + "\t}\n" + + "\tpublic String toString() {\n" + + "\t\treturn String.valueOf(this.i);\n" + + "\t}\n" + + "\tpublic static void bar() {\n" + + "\t}\n" + + "}"; + compileAndDeploy15(sourceA69, "A69"); + + String userCode = "A69.bar();"; + JDIStackFrame stackFrame = + new JDIStackFrame(this.jdiVM, this, userCode, "A69", "bar", -1); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "enum E { C }; return String.toString(E.C.getName());".toCharArray(); + try { + this.context.evaluate( + snippet, + stackFrame.localVariableTypeNames(), + stackFrame.localVariableNames(), + stackFrame.localVariableModifiers(), + stackFrame.declaringTypeName(), + stackFrame.isStatic(), + stackFrame.isConstructorCall(), + getEnv(), + getCompilerOptions(), + requestor, + getProblemFactory()); + } catch (InstallException e) { + assertTrue("No targetException " + e.getMessage(), false); + } + boolean is16Plus = this.complianceLevel >= ClassFileConstants.JDK16; + if (is16Plus) { + assertTrue( + "Should get one result but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 0); + } else { + assertTrue( + "Should get two results but got " + (requestor.resultIndex + 1), + requestor.resultIndex == 1); + } + EvaluationResult result = requestor.results[0]; + assertTrue("Code snippet should not have problems", result.hasProblems()); + assertEquals("Wrong size", 1, result.getProblems().length); + assertEquals("Wrong pb", is16Plus ? 100 : 31, result.getProblems()[0].getID() & IProblem.IgnoreCategoriesMask); + if (!is16Plus) { + result = requestor.results[1]; + assertTrue("Code snippet should not have problems", result.hasProblems()); + assertEquals("Wrong size", 1, result.getProblems().length); + assertEquals("Wrong pb", 50, result.getProblems()[0].getID() & IProblem.IgnoreCategoriesMask); + } + } finally { + removeTempClass("A69"); + } +} +/** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=178861 + */ +public void testNegative005() throws InstallException { + String userCode = ""; + JDIStackFrame stackFrame = new JDIStackFrame( + this.jdiVM, + this, + userCode); + + DebugRequestor requestor = new DebugRequestor(); + char[] snippet = "run()".toCharArray(); + evaluate(stackFrame, requestor, snippet); + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + CategorizedProblem[] problems = result.getProblems(); + StringBuilder buffer = null; + for (int i = 0, max = problems.length; i < max; i++){ + if (problems[i].isError()){ + if (buffer == null) buffer = new StringBuilder(10); + buffer.append(problems[i].getMessage()); + buffer.append('|'); + } + } + assertEquals("Unexpected errors", + "Cannot use this in a static context|", + buffer == null ? "none" : buffer.toString()); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationContextWrapperTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationContextWrapperTest.java new file mode 100644 index 0000000000..87c6d95fb3 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationContextWrapperTest.java @@ -0,0 +1,350 @@ +/******************************************************************************* + * Copyright (c) 2021 Gayan Perera and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Gayan Perera - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import org.eclipse.core.resources.ICommand; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.compiler.batch.BatchCompiler; +import org.eclipse.jdt.core.eval.ICodeSnippetRequestor; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.core.ClasspathEntry; +import org.eclipse.jdt.internal.core.JavaProject; +import org.eclipse.jdt.internal.core.eval.EvaluationContextWrapper; +import org.eclipse.jdt.internal.eval.InstallException; + +import junit.framework.Test; + +public class EvaluationContextWrapperTest extends EvaluationTest { + + private static final String SOURCE_DIRECTORY = "src"; + private static final String BIN_DIR = "bin"; + + private IJavaProject project; + + static { +// TESTS_NAMES = new String[] { "testBug573589_StaticImport" }; + } + + public EvaluationContextWrapperTest(String name) { + super(name); + } + + public static Test setupSuite(Class clazz) { + List> testClasses = new ArrayList<>(); + testClasses.add(clazz); + return buildAllCompliancesTestSuite(clazz, DebugEvaluationSetup.class, testClasses); + } + public static Test suite() { + return setupSuite(testClass()); + } + public static Class testClass() { + return EvaluationContextWrapperTest.class; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + this.project = createProject("EvaluationContextWrapperTest"); + } + + @Override + protected void tearDown() throws Exception { + delete(this.project); + this.project = null; + super.tearDown(); + } + + public void testBug573589_StaticImport() throws JavaModelException, InstallException { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + try { + StringBuilder source = new StringBuilder(); + source.append("import static java.lang.Math.max;\n"); + source.append("class Bug573589 {\n"); + source.append(" public int fooMax() {\n"); + source.append(" return max(10, 11);\n"); + source.append(" }\n"); + source.append(" public static void call() {\n"); + source.append(" new Bug573589().fooMax();\n"); + source.append(" }\n"); + source.append("}\n"); + + compileAndDeploy15(source.toString(), "Bug573589"); + refreshProject(); + + Optional problem = evaluate("Bug573589", "1+1"); + assertTrue("Evaluation should not have problems : " + .concat(problem.map(p -> p.getAttribute(IMarker.MESSAGE, "")).orElse("")), + problem.isEmpty()); + } finally { + removeTempClass("Bug573589"); + } + } + + public void testBug573589_StaticImport_AttachedSource() throws JavaModelException, InstallException { + if (this.complianceLevel < ClassFileConstants.JDK1_5) { + return; + } + try { + StringBuilder source = new StringBuilder(); + source.append("import static java.lang.Math.max;\n"); + source.append("class Bug573589 {\n"); + source.append(" public int fooMax() {\n"); + source.append(" return max(10, 11);\n"); + source.append(" }\n"); + source.append(" public static void call() {\n"); + source.append(" new Bug573589().fooMax();\n"); + source.append(" }\n"); + source.append("}\n"); + + Map result = compileAndDeploy15(source.toString(), "Bug573589", "attached"); + addLibrary(this.project, result.get(BIN_DIR), result.get(SOURCE_DIRECTORY)); + refreshProject(); + + Optional problem = evaluate("Bug573589", "1+1"); + assertTrue("Evaluation should not have problems : " + .concat(problem.map(p -> p.getAttribute(IMarker.MESSAGE, "")).orElse("")), + problem.isEmpty()); + } finally { + removeTempClass("Bug573589", "attached"); + } + } + + private void compileAndDeploy15(String source, String className) { + compileAndDeploy15(source, className, ""); + } + + private Map compileAndDeploy15(String source, String className, String locationPrefix) { + resetEnv(); // needed to reinitialize the caches + String srcDir = this.project.getProject().getLocation().toFile().getAbsolutePath() + File.separator + SOURCE_DIRECTORY.concat(locationPrefix); + String binDir = this.project.getProject().getLocation().toFile().getAbsolutePath() + File.separator + BIN_DIR.concat(locationPrefix); + Map result = new HashMap<>(); + result.put(SOURCE_DIRECTORY, srcDir); + result.put(BIN_DIR, binDir); + + File directory = new File(srcDir); + if (!directory.exists()) { + if (!directory.mkdir()) { + System.out.println("Could not create " + srcDir); + return result; + } + } + + String fileName = srcDir + File.separator + className + ".java"; + try { + BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); + writer.write(source); + writer.flush(); + writer.close(); + } catch(IOException e) { + e.printStackTrace(); + return result; + } + StringBuffer buffer = new StringBuffer(); + buffer + .append("\"") + .append(fileName) + .append("\" -d \"") + .append(binDir) + .append("\" -nowarn -1.5 -g -classpath \"") + .append(Util.getJavaClassLibsAsString()) + .append(srcDir) + .append("\""); + BatchCompiler.compile(buffer.toString(), new PrintWriter(System.out), new PrintWriter(System.err), null/*progress*/); + return result; + } + + private void refreshProject() { + try { + this.project.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e1) { + e1.printStackTrace(); + } + } + + private void removeTempClass(String className) { + removeTempClass(className, ""); + } + + private void removeTempClass(String className, String locationPrefix) { + resetEnv(); + String srcDir = this.project.getProject().getLocation().toFile().getAbsolutePath() + File.separator + SOURCE_DIRECTORY.concat(locationPrefix); + String binDir = this.project.getProject().getLocation().toFile().getAbsolutePath() + File.separator + BIN_DIR.concat(locationPrefix); + + Util.delete(srcDir + File.separator + className + ".java"); + Util.delete(binDir + File.separator + className + ".class"); + } + + private Optional evaluate(String declaringTypeName, String snippet) throws InstallException, JavaModelException { + IType type = this.project.findType(declaringTypeName); + assertNotNull("declaringType is not compiled", type); + + String source = type.getSource(); + assertNotNull("declaringType source mapper is not ready.", source); + assertFalse("declaringType source mapper is not ready.", source.isEmpty()); + + IMarker[] problem = new IMarker[1]; + ICodeSnippetRequestor requestor = new ICodeSnippetRequestor() { + + @Override + public void acceptProblem(IMarker problemMarker, String fragmentSource, int fragmentKind) { + if (problemMarker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) >= IMarker.SEVERITY_ERROR) { + problem[0] = problemMarker; + } + } + + @Override + public boolean acceptClassFiles(byte[][] classFileBytes, String[][] classFileCompoundNames, + String codeSnippetClassName) { + return true; + } + }; + + EvaluationContextWrapper wrapper = new EvaluationContextWrapper(this.context, (JavaProject) this.project); + wrapper.evaluateCodeSnippet( + snippet, + new String[0], + new String[0], + new int[0], + type, + true, + false, + requestor, + null); + return Optional.ofNullable(problem[0]); + } + + @Override + public Map getCompilerOptions() { + Map options = super.getCompilerOptions(); + options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); + options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE); + return options; + } + + private IJavaProject createProject(String name) throws Exception { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IProject proj = root.getProject(name); + if (proj.exists()) { + try { + proj.delete(true, true, null); + } + catch(Exception e) {} + } + proj = root.getProject(name); + proj.create(null); + proj.open(null); + + // disable build and set nature + IProjectDescription description = proj.getDescription(); + description.setNatureIds(new String[] {JavaCore.NATURE_ID}); + description.setBuildConfigs(new String[0]); + description.setBuildSpec(new ICommand[0]); + proj.setDescription(description, IResource.FORCE, null); + + IFolder binFolder= proj.getFolder(BIN_DIR); + if (!binFolder.exists()) { + binFolder.create(false, true, null); + } + IPath outputLocation = binFolder.getFullPath(); + IJavaProject jproject= JavaCore.create(proj); + jproject.setRawClasspath(new IClasspathEntry[0], null); + jproject.setOutputLocation(outputLocation, null); + + Map map = JavaCore.getOptions(); + map.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); + map.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); + map.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); + jproject.setOptions(map); + + + addSourceContainer(jproject, SOURCE_DIRECTORY); + for (String path : Util.getJavaClassLibs()) { + addLibrary(jproject, path, null); + } + return jproject; + } + + private void addSourceContainer(IJavaProject prj, String name) { + IFolder folder = prj.getProject().getFolder(name); + if(!folder.exists()) { + try { + folder.create(false, true, null); + } catch (CoreException e) { + throw new AssertionError(e); + } + } + IClasspathEntry entry = JavaCore.newSourceEntry(prj.getPackageFragmentRoot(folder).getPath()); + try { + prj.setRawClasspath(addToClasspath(prj.getRawClasspath(), entry), null); + } catch (JavaModelException e) { + throw new AssertionError(e); + } + } + + private void addLibrary(IJavaProject prj, String path, String sourcePath) { + IClasspathEntry entry = JavaCore.newLibraryEntry(new Path(path), Optional.ofNullable(sourcePath).map(Path::new).orElse(null), + Optional.ofNullable(sourcePath).map(p -> new Path(path)).orElse(null)); + try { + prj.setRawClasspath(addToClasspath(prj.getRawClasspath(), entry), null); + } catch (JavaModelException e) { + throw new AssertionError(e); + } + } + + private static IClasspathEntry[] addToClasspath(IClasspathEntry[] original, IClasspathEntry add) { + IClasspathEntry[] copy = new ClasspathEntry[original.length + 1]; + System.arraycopy(original, 0, copy, 0, original.length); + copy[copy.length - 1] = add; + return copy; + } + + private static void delete(IJavaProject jproject) throws CoreException { + jproject.setRawClasspath(new ClasspathEntry[0], jproject.getProject().getFullPath(), null); + jproject.getProject().delete(true, true, null); + } + + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationSetup.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationSetup.java new file mode 100644 index 0000000000..c2838b7cc7 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationSetup.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.net.ServerSocket; + +import org.eclipse.jdt.core.tests.runtime.LocalVirtualMachine; + +import org.eclipse.jdt.core.tests.runtime.LocalVMLauncher; +import org.eclipse.jdt.core.tests.runtime.TargetException; +import org.eclipse.jdt.core.tests.runtime.TargetInterface; +import org.eclipse.jdt.core.tests.util.CompilerTestSetup; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.eval.EvaluationContext; + +public class EvaluationSetup extends CompilerTestSetup { + + public static final String EVAL_DIRECTORY = Util.getOutputDirectory() + File.separator + "evaluation"; + public static final String JRE_PATH = Util.getJREDirectory(); + + EvaluationContext context; + TargetInterface target; + LocalVirtualMachine launchedVM; + INameEnvironment env; + + public EvaluationSetup(long complianceLevel) { + super(complianceLevel); + } + + @Override + protected void setUp() { + if (this.context == null) { // non null if called from subclass + try (ServerSocket server = new ServerSocket(0)) { + // Launch VM in evaluation mode + int evalPort = server.getLocalPort(); + try { + LocalVMLauncher launcher = LocalVMLauncher.getLauncher(); + launcher.setVMPath(JRE_PATH); + launcher.setEvalPort(evalPort); + launcher.setEvalTargetPath(EVAL_DIRECTORY); + this.launchedVM = launcher.launch(); + } catch (TargetException e) { + e.printStackTrace(); + throw new Error(e.getMessage(), e); + } + + // Thread that read the stout of the VM so that the VM doesn't block + try { + startReader("VM's stdout reader", this.launchedVM.getInputStream(), System.out); + } catch (TargetException e) { + e.printStackTrace(); + } + + // Thread that read the sterr of the VM so that the VM doesn't block + try { + startReader("VM's sterr reader", this.launchedVM.getErrorStream(), System.err); + } catch (TargetException e) { + e.printStackTrace(); + } + + // Create context + this.context = new EvaluationContext(); + + // Create target + this.target = new TargetInterface(); + // allow 30s max to connect (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=188127) + // Increased to 60 s for https://bugs.eclipse.org/bugs/show_bug.cgi?id=547417 + this.target.connect(server, 60000); + + assertTrue("Failed to connect VM server", this.target.isConnected()); + + System.out.println(getName() + ": connected to target"); + + // Create name environment + this.env = new FileSystem(Util.getJavaClassLibs(), new String[0], null); + } catch (IOException e1) { + e1.printStackTrace(); + throw new Error("Failed to open socket", e1); + } + } + super.setUp(); + } + + protected void startReader(String name, final InputStream in, final PrintStream out) { + (new Thread(name) { + @Override + public void run() { + int read = 0; + while (read != -1) { + try { + read = in.read(); + } catch (java.io.IOException e) { + read = -1; + } + if (read != -1) { + out.print((char)read); + } + } + } + }).start(); + } + + @Override + final protected void tearDown() { + if (this.context != null) { + LocalVirtualMachine vm = this.launchedVM; + if (vm != null) { + try { + if (this.target != null) { + this.target.disconnect(); // Close the socket first so that the OS resource has a chance to be freed. + } + int retry = 0; + while (vm.isRunning() && (++retry < 20)) { + try { + Thread.sleep(retry * 100); + } catch (InterruptedException e) { + } + } + if (vm.isRunning()) { + vm.shutDown(); + } + this.context = null; + } catch (TargetException e) { + e.printStackTrace(); + throw new Error(e.getMessage(), e); + } + } + } + if (this.env != null) { + this.env.cleanup(); + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationTest.java new file mode 100644 index 0000000000..be3650066c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/EvaluationTest.java @@ -0,0 +1,572 @@ +/******************************************************************************* + * Copyright (c) 2000, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import java.io.File; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.junit.extension.StopableTestCase; +import org.eclipse.jdt.core.tests.runtime.LocalVMLauncher; +import org.eclipse.jdt.core.tests.runtime.LocalVirtualMachine; +import org.eclipse.jdt.core.tests.runtime.TargetException; +import org.eclipse.jdt.core.tests.runtime.TargetInterface; +import org.eclipse.jdt.core.tests.util.*; +import org.eclipse.jdt.internal.compiler.ClassFile; +import org.eclipse.jdt.internal.compiler.IProblemFactory; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.env.IBinaryField; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.eval.EvaluationContext; +import org.eclipse.jdt.internal.eval.EvaluationResult; +import org.eclipse.jdt.internal.eval.GlobalVariable; +import org.eclipse.jdt.internal.eval.IRequestor; +import org.eclipse.jdt.internal.eval.InstallException; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class EvaluationTest extends AbstractCompilerTest implements StopableTestCase { + + public class Requestor implements IRequestor { + public int resultIndex = -1; + public EvaluationResult[] results = new EvaluationResult[5]; + public boolean acceptClassFiles(ClassFile[] classFiles, char[] codeSnippetClassName) { + try { + EvaluationTest.this.target.sendClasses(codeSnippetClassName != null, classFiles); + } catch (TargetException e) { + return false; + } + if (codeSnippetClassName != null) { + TargetInterface.Result result = EvaluationTest.this.target.getResult(); + if (result.displayString == null) { + acceptResult(new EvaluationResult(null, EvaluationResult.T_CODE_SNIPPET, null, null)); + } else { + acceptResult(new EvaluationResult(null, EvaluationResult.T_CODE_SNIPPET, result.displayString, result.typeName)); + } + } else { + for (int i = 0, length = classFiles.length; i < length; i++) { + char[][] compoundName = classFiles[i].getCompoundName(); + if (new String(compoundName[compoundName.length - 1]).startsWith("GlobalVariable")) { + try { + IBinaryField[] fields = new ClassFileReader(classFiles[i].getBytes(), null).getFields(); + if (fields != null) { + for (int j = 0; j < fields.length; j++) { + IBinaryField field = fields[j]; + if (Modifier.isPublic(field.getModifiers())) { + TargetInterface.Result result = EvaluationTest.this.target.getResult(); + if (result.displayString == null) { + acceptResult(new EvaluationResult(field.getName(), EvaluationResult.T_VARIABLE, null, null)); + } else { + acceptResult(new EvaluationResult(field.getName(), EvaluationResult.T_VARIABLE, result.displayString, result.typeName)); + } + } + } + } + } catch (ClassFormatException e) { + e.printStackTrace(); + } + } + } + } + return true; + } + public void acceptProblem(CategorizedProblem problem, char[] fragmentSource, int fragmentKind) { + acceptResult(new EvaluationResult(fragmentSource, fragmentKind, new CategorizedProblem[]{problem})); + } + public void acceptResult(EvaluationResult result) { + try { + this.results[++this.resultIndex] = result; + } catch (ArrayIndexOutOfBoundsException e) { + int oldResultLength = this.results.length; + System.arraycopy(this.results, 0, (this.results = new EvaluationResult[oldResultLength * 2]), 0, oldResultLength); + this.results[this.resultIndex] = result; + } + } + } + + String[] classPath; + public EvaluationContext context; + INameEnvironment env; + LocalVirtualMachine launchedVM; + TargetInterface target; + + /** + * Creates a new EvaluationTest. + */ + public EvaluationTest(String name) { + super(name); + } + + public static Test setupSuite(Class clazz) { + ArrayList testClasses = new ArrayList(); + testClasses.add(clazz); + return buildAllCompliancesTestSuite(clazz, EvaluationSetup.class, testClasses); + } + + public static Test suite(Class evaluationTestClass) { + TestSuite suite = new TestSuite(evaluationTestClass); + return suite; + } + + /** + * Asserts that two char arrays are equal. If they are not an AssertionFailedError is thrown. + * + * @param message + * the detail message for this assertion + * @param expected + * the expected value of a char array + * @param actual + * the actual value of a char array + */ + public void assertEquals(String message, char[] expected, char[] actual) { + if (expected == null && actual == null) + return; + if (expected != null) { + if (actual == null) { + failNotEquals(message, expected, actual); + return; + } + if (expected.length == actual.length) { + for (int i = 0; i < expected.length; i++) { + if (expected[i] != actual[i]) { + failNotEquals(message, expected, actual); + return; + } + } + return; + } + } + failNotEquals(message, expected, actual); + } + + /** + * Build a char array from the given lines + */ + protected char[] buildCharArray(String[] lines) { + String buffer = String.join("\n", lines); + int length = buffer.length(); + char[] result = new char[length]; + buffer.getChars(0, length, result, 0); + return result; + } + + /** + * Returns whether the 2 given problems are equals. + */ + public boolean equals(CategorizedProblem pb1, CategorizedProblem pb2) { + if ((pb1 == null) && (pb2 == null)) { + return true; + } + if ((pb1 == null) || (pb2 == null)) { + return false; + } + return (pb1.getID() == pb2.getID()) && (pb1.isError() == pb2.isError()) && (pb1.getSourceStart() == pb2.getSourceStart()) && (pb1.getSourceEnd() == pb2.getSourceEnd()) && (pb1.getSourceLineNumber() == pb2.getSourceLineNumber()); + } + + /** + * Evaluates the given code snippet and makes sure it returns a result with the given display string. + */ + public void evaluateWithExpectedDisplayString(Map compilerOptions, char[] codeSnippet, char[] displayString) { + Requestor requestor = new Requestor(); + try { + this.context.evaluate(codeSnippet, getEnv(), compilerOptions, requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception " + e.getMessage(), false); + } + if (requestor.resultIndex != 0) { + for (int i = 0; i < requestor.resultIndex; i++) { + System.out.println("unexpected result[" + i + "]: " + requestor.results[i]); + } + } + assertTrue("Unexpected result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Has problem", !result.hasProblems()); + assertTrue("Empty problem list", result.getProblems().length == 0); + if (displayString == null) { + assertTrue("Has value", !result.hasValue()); + } else { + assertTrue("Has value", result.hasValue()); + assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType()); + //assertEquals("Evaluation id", codeSnippet, result.getEvaluationID()); + assertEquals("Value display string", displayString, result.getValueDisplayString()); + } + } + + /** + * Evaluates the given code snippet and makes sure it returns a result with the given display string. + */ + public void evaluateWithExpectedDisplayString(char[] codeSnippet, char[] displayString) { + Requestor requestor = new Requestor(); + try { + this.context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception " + e.getMessage(), false); + } + if (requestor.resultIndex != 0) { + for (int i = 0; i < requestor.resultIndex; i++) { + System.out.println("unexpected result[" + i + "]: " + requestor.results[i]); + } + } + assertTrue("Unexpected result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Has problem", !result.hasProblems()); + assertTrue("Empty problem list", result.getProblems().length == 0); + if (displayString == null) { + assertTrue("Has value", !result.hasValue()); + } else { + assertTrue("Does not have expected value", result.hasValue()); + assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType()); + //assertEquals("Evaluation id", codeSnippet, result.getEvaluationID()); + assertEquals("Value display string", displayString, result.getValueDisplayString()); + } + } + + /** + * Evaluates the given code snippet and makes sure the evaluation result has at least the given problem on the given import. + */ + protected void evaluateWithExpectedImportProblem(char[] codeSnippet, char[] importDeclaration, CategorizedProblem expected) { + evaluateWithExpectedImportProblem(codeSnippet, importDeclaration, getCompilerOptions(), expected); + } + + /** + * Evaluates the given code snippet and makes sure the evaluation result has at least the given problem on the given import. + */ + protected void evaluateWithExpectedImportProblem(char[] codeSnippet, char[] importDeclaration, Map options, CategorizedProblem expected) { + Requestor requestor = new Requestor(); + try { + this.context.evaluate(codeSnippet, getEnv(), options, requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception " + e.getMessage(), false); + } + for (int i = 0; i <= requestor.resultIndex; i++) { + EvaluationResult result = requestor.results[i]; + assertTrue("Has value", !result.hasValue()); + assertTrue("Has problem", result.hasProblems()); + assertEquals("Evaluation type", EvaluationResult.T_IMPORT, result.getEvaluationType()); + assertEquals("Evaluation id", importDeclaration, result.getEvaluationID()); + CategorizedProblem[] problems = result.getProblems(); + if (equals(expected, problems[0])) { + return; + } + } + assertTrue("Expected problem not found", false); + } + + /** + * Evaluates the given code snippet and makes sure the evaluation result has at least the given problem. + */ + protected void evaluateWithExpectedProblem(char[] codeSnippet, CategorizedProblem expected) { + Requestor requestor = new Requestor(); + try { + this.context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception " + e.getMessage(), false); + } + for (int i = 0; i <= requestor.resultIndex; i++) { + EvaluationResult result = requestor.results[i]; + assertTrue("Has value", !result.hasValue()); + assertTrue("Has problem", result.hasProblems()); + assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType()); + assertEquals("Evaluation id", codeSnippet, result.getEvaluationID()); + CategorizedProblem[] problems = result.getProblems(); + if (equals(expected, problems[0])) { + return; + } + } + assertTrue("Expected problem not found", false); + } + + /** + * Evaluates the given code snippet and makes sure the evaluation result has at least the given problem. + */ + protected void evaluateWithExpectedProblem(char[] codeSnippet, String problemsString) { + Requestor requestor = new Requestor(); + try { + this.context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception " + e.getMessage(), false); + } + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Has value", !result.hasValue()); + assertTrue("Has problem", result.hasProblems()); + assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType()); + assertEquals("Evaluation id", codeSnippet, result.getEvaluationID()); + StringBuilder problemBuffer = new StringBuilder(20); + CategorizedProblem[] problems = result.getProblems(); + for (int i = 0; i < problems.length; i++) { + problemBuffer.append(problems[i].getMessage()).append('\n'); + } + assertEquals("Unexpected problems", problemsString, problemBuffer.toString()); + } + + /** + * Evaluates the given variable and makes sure the evaluation result has at least the given problem. + */ + protected void evaluateWithExpectedProblem(GlobalVariable var, CategorizedProblem expected) { + Requestor requestor = new Requestor(); + try { + this.context.evaluateVariables(getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception " + e.getMessage(), false); + } + for (int i = 0; i <= requestor.resultIndex; i++) { + EvaluationResult result = requestor.results[i]; + assertTrue("Has value", !result.hasValue()); + assertTrue("Has problem", result.hasProblems()); + assertEquals("Evaluation type", EvaluationResult.T_VARIABLE, result.getEvaluationType()); + assertEquals("Evaluation id", var.getName(), result.getEvaluationID()); + CategorizedProblem[] problems = result.getProblems(); + if (equals(expected, problems[0])) { + return; + } + } + assertTrue("Expected problem not found", false); + } + + /** + * Evaluates the given code snippet and makes sure it returns a result with the given type name. + */ + protected void evaluateWithExpectedType(char[] codeSnippet, char[] expectedTypeName) { + Requestor requestor = new Requestor(); + try { + this.context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception " + e.getMessage(), false); + } + if (requestor.resultIndex != 0) { + for (int i = 0; i < requestor.resultIndex; i++) { + System.out.println("unexpected result[" + i + "]: " + requestor.results[i]); + } + } + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + if (expectedTypeName == null) { + assertTrue("Has value", !result.hasValue()); + } else { + assertTrue("Does not have expected value", result.hasValue()); + assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType()); + //assertEquals("Evaluation id", codeSnippet, result.getEvaluationID()); + assertEquals("Value type name", expectedTypeName, result.getValueTypeName()); + } + } + + /** + * Evaluates the given code snippet and makes sure it returns a result with the given display string and type name. + */ + protected void evaluateWithExpectedValue(char[] codeSnippet, char[] displayString, char[] typeName) { + Requestor requestor = new Requestor(); + try { + this.context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception " + e.getMessage(), false); + } + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + if (displayString == null) { + assertTrue("Missing value", !result.hasValue()); + } else { + assertTrue("Has value", result.hasValue()); + assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType()); + //assertEquals("Evaluation id", codeSnippet, result.getEvaluationID()); + assertEquals("Value display string", displayString, result.getValueDisplayString()); + assertEquals("Value type name", typeName, result.getValueTypeName()); + } + } + + /** + * Evaluates the given variable and makes sure it returns a result with the given display string and type name. + */ + protected void evaluateWithExpectedValue(GlobalVariable var, char[] displayString, char[] typeName) { + Requestor requestor = new Requestor(); + try { + this.context.evaluateVariable(var, getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception " + e.getMessage(), false); + } + if (requestor.resultIndex != 0) { + for (int i = 0; i < requestor.resultIndex; i++) { + System.out.println("unexpected result[" + i + "]: " + requestor.results[i]); + } + } + assertTrue("Unexpected result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + if (displayString == null) { + assertTrue("Has value", !result.hasValue()); + } else { + assertTrue("Has value", result.hasValue()); + assertEquals("Value display string", displayString, result.getValueDisplayString()); + assertEquals("Value type name", typeName, result.getValueTypeName()); + } + } + + /** + * Evaluates the given code snippet and makes sure an evaluation result has at least the given warning, and that another evaluation result has the given display string. + */ + protected void evaluateWithExpectedWarningAndDisplayString(final char[] codeSnippet, final CategorizedProblem[] expected, final char[] displayString) { + class ResultRequestor extends Requestor { + ArrayList collectedProblems = new ArrayList(); + boolean gotDisplayString = false; + @Override + public void acceptResult(EvaluationResult result) { + assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, result.getEvaluationType()); + //assertEquals("Evaluation id", codeSnippet, result.getEvaluationID()); + if (result.hasValue()) { + if (CharOperation.equals(result.getValueDisplayString(), displayString)) { + this.gotDisplayString = true; + } + } else { + assertTrue("Has problem", result.hasProblems()); + CategorizedProblem[] problems = result.getProblems(); + this.collectedProblems.addAll(Arrays.asList(problems)); + } + } + } + ResultRequestor requestor = new ResultRequestor(); + try { + this.context.evaluate(codeSnippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception " + e.getMessage(), false); + } + if (expected.length == requestor.collectedProblems.size()) { + for (int i = 0; i < expected.length; i++) { + assertTrue("Problem mismatch" + requestor.collectedProblems.get(i), this.equals(expected[i], (CategorizedProblem)requestor.collectedProblems.get(i))); + } + } else { + assertTrue("Wrong problem count", false); + } + assertTrue("Expected display string", requestor.gotDisplayString); + } + + private void failNotEquals(String message, char[] expected, char[] actual) { + String formatted = ""; + if (message != null) + formatted = message + " "; + String expectedString = expected == null ? "null" : new String(expected); + String actualString = actual == null ? "null" : new String(actual); + fail(formatted + "expected:<" + expectedString + "> but was:<" + actualString + ">"); + } + + @Override + public Map getCompilerOptions() { + Map defaultOptions = super.getCompilerOptions(); + defaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); + defaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE); + defaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute, CompilerOptions.DO_NOT_GENERATE); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING); + defaultOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + defaultOptions.put(CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, CompilerOptions.WARNING); + return defaultOptions; + } + + public INameEnvironment getEnv() { + return this.env; + } + + public IProblemFactory getProblemFactory() { + return new DefaultProblemFactory(java.util.Locale.getDefault()); + } + + @Override + public void initialize(CompilerTestSetup setUp) { + super.initialize(setUp); + EvaluationSetup evalSetUp = (EvaluationSetup)setUp; + this.context = evalSetUp.context; + this.target = evalSetUp.target; + this.launchedVM = evalSetUp.launchedVM; + this.env = evalSetUp.env; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + assertNotNull("Evaluation context is null, probably VM connection error", this.context); + } + + /** + * Installs all the variables and check that the number of installed variables is the given number. + */ + protected void installVariables(final int expectedNumber) { + class InstallRequestor extends Requestor { + int count = 0; + @Override + public void acceptResult(EvaluationResult result) { + assertTrue("Has problems", !result.hasProblems()); + assertTrue("Has value", result.hasValue()); + this.count++; + } + } + + InstallRequestor installRequestor = new InstallRequestor(); + try { + this.context.evaluateVariables(getEnv(), getCompilerOptions(), installRequestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("Target exception: " + e.getMessage(), false); + } + assertEquals("Number of installed variables", expectedNumber, installRequestor.count); + } + + public boolean isJRockitVM() { + final String vmName = System.getProperty("java.vm.name"); + return vmName != null && vmName.indexOf("JRockit") != -1; + } + /** + * Returns a new problem with the given id, severity, source positions and line number. + */ + protected DefaultProblem newProblem(int id, int severity, int startPos, int endPos, int line) { + return new DefaultProblem(null, null, id, null, severity, startPos, endPos, line, 0); + } + + public void resetEnv() { + String encoding = (String)getCompilerOptions().get(CompilerOptions.OPTION_Encoding); + if ("".equals(encoding)) + encoding = null; + this.env = new FileSystem(Util.concatWithClassLibs(EvaluationSetup.EVAL_DIRECTORY + File.separator + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY, false), new String[0], encoding); + } + + @Override + public void stop() { + if (this.target != null) { + this.target.disconnect(); // Close the socket first so that the OS resource has a chance to be freed. + } + if (this.launchedVM != null) { + try { + int retry = 0; + while (this.launchedVM.isRunning() && (++retry < 20)) { + try { + Thread.sleep(retry * 100); + } catch (InterruptedException e) { + } + } + if (this.launchedVM.isRunning()) { + this.launchedVM.shutDown(); + } + } catch (TargetException e) { + } + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/JDIStackFrame.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/JDIStackFrame.java new file mode 100644 index 0000000000..a07548a83e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/JDIStackFrame.java @@ -0,0 +1,382 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +import org.eclipse.jdt.core.tests.runtime.RuntimeConstants; +import org.eclipse.jdt.internal.eval.EvaluationConstants; +import org.eclipse.jdt.internal.eval.EvaluationResult; +import org.eclipse.jdt.internal.eval.InstallException; + +import com.sun.jdi.AbsentInformationException; +import com.sun.jdi.ClassNotLoadedException; +import com.sun.jdi.ClassType; +import com.sun.jdi.Field; +import com.sun.jdi.IncompatibleThreadStateException; +import com.sun.jdi.InvalidTypeException; +import com.sun.jdi.InvocationException; +import com.sun.jdi.LocalVariable; +import com.sun.jdi.Location; +import com.sun.jdi.Method; +import com.sun.jdi.ObjectReference; +import com.sun.jdi.ReferenceType; +import com.sun.jdi.StackFrame; +import com.sun.jdi.ThreadReference; +import com.sun.jdi.Value; +import com.sun.jdi.VirtualMachine; +import com.sun.jdi.event.BreakpointEvent; +import com.sun.jdi.event.Event; +import com.sun.jdi.event.EventSet; +import com.sun.jdi.request.BreakpointRequest; +import com.sun.jdi.request.EventRequest; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class JDIStackFrame implements EvaluationConstants, RuntimeConstants { + VirtualMachine jdiVM; + ThreadReference jdiThread; + String userCode; + String breakpointClassName; + String breakpointMethodName; + int breakpointLine; + long timeout; +public JDIStackFrame(VirtualMachine jdiVM, DebugEvaluationTest test, String userCode) { + this(jdiVM, test, userCode, "_JDIStackFrame_", "foo", Integer.MAX_VALUE); +} +public JDIStackFrame( + VirtualMachine jdiVM, + DebugEvaluationTest test, + String userCode, + String breakpointClassName, + String breakpointMethodName, + int breakpointLine) { + + this(jdiVM, test, userCode, breakpointClassName, breakpointMethodName, breakpointLine, 10000/*timeout*/); + +} +public JDIStackFrame( + VirtualMachine jdiVM, + DebugEvaluationTest test, + String userCode, + String breakpointClassName, + String breakpointMethodName, + int breakpointLine, + long timeout) { + + this.jdiVM = jdiVM; + this.userCode = userCode; + this.breakpointClassName = breakpointClassName; + this.breakpointMethodName = breakpointMethodName; + this.breakpointLine = breakpointLine; + this.timeout = timeout; + + test.jdiStackFrame = null; + this.jdiThread = getDebuggedThread(test); + test.jdiStackFrame = this; +} +public char[] declaringTypeName() { + if (this.breakpointLine != Integer.MAX_VALUE) { // if not in a code snippet + StackFrame frame = getStackFrame(); + return frame.location().declaringType().name().toCharArray(); + } + return null; +} +protected ThreadReference getDebuggedThread(DebugEvaluationTest test) { + try { + // desintall previous breakpoints + this.jdiVM.eventRequestManager().deleteAllBreakpoints(); + + // install a breakpoint at the breakpointLine + List classes = this.jdiVM.classesByName(this.breakpointClassName); + if (classes.size() == 0) { + if (this.breakpointClassName.equals("_JDIStackFrame_")) { + // install special class + String source = + "public class _JDIStackFrame_ {\n" + + " public int foo() {\n" + + " return -1;\n" + + " }\n" + + "}"; + test.compileAndDeploy(source, "_JDIStackFrame_"); + } + + // force load of class + test.evaluateWithExpectedDisplayString( + ("return Class.forName(\"" + this.breakpointClassName + "\");").toCharArray(), + ("class " + this.breakpointClassName).toCharArray() + ); + classes = this.jdiVM.classesByName(this.breakpointClassName); + if (classes.size() == 0) { + // workaround bug in Standard VM + Iterator iterator = this.jdiVM.allClasses().iterator(); + while (iterator.hasNext()) { + ReferenceType type = (ReferenceType)iterator.next(); + if (type.name().equals(this.breakpointClassName)) { + classes = new ArrayList(1); + classes.add(type); + break; + } + } + if (classes.size() == 0) { + throw new Error("JDI could not retrieve class for " + this.breakpointClassName); + } + } + } + ClassType clazz = (ClassType)classes.get(0); + Method method = clazz.methodsByName(this.breakpointMethodName).get(0); + Location location; + if (this.breakpointLine < 0 || this.breakpointLine == Integer.MAX_VALUE) { + location = method.location(); + } else { + location = method.locationsOfLine(this.breakpointLine).get(0); + } + BreakpointRequest request = this.jdiVM.eventRequestManager().createBreakpointRequest(location); + request.setSuspendPolicy(EventRequest.SUSPEND_EVENT_THREAD); + request.enable(); + + // create a new thread that hit the breakpoint + EvaluationTest.Requestor requestor = test.new Requestor(); + try { + test.resetEnv(); + test.context.evaluate( + ("(new Thread() {\n" + + " public void run() {\n" + + this.userCode + "\n" + + (this.breakpointClassName.equals("_JDIStackFrame_") ? " new _JDIStackFrame_().foo();\n" : "") + + " }\n" + + " public String toString() {\n" + + " return \"my thread\";\n" + + " }\n" + + "}).start();\n").toCharArray(), + test.getEnv(), + test.getCompilerOptions(), + requestor, + test.getProblemFactory()); + } catch (InstallException e) { + TestCase.assertTrue("Target exception " + e.getMessage(), false); + } + EvaluationResult[] results = requestor.results; + for (int i = 0; i < requestor.resultIndex + 1; i++){ + if (results[i].hasErrors()) { + TestCase.assertTrue("Compilation error in user code", false); + } + } + + // Wait for the breakpoint event + Event event = null; + do { + EventSet set = this.jdiVM.eventQueue().remove(); + Iterator iterator = set.eventIterator(); + while (iterator.hasNext()) { + event = (Event)iterator.next(); + if (event instanceof BreakpointEvent) + break; + } + } while (!(event instanceof BreakpointEvent)); + + // Return the suspended thread + return ((BreakpointEvent)event).thread(); + } catch (AbsentInformationException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return null; +} +protected StackFrame getStackFrame() { + try { + if (this.breakpointLine == Integer.MAX_VALUE) { + return this.jdiThread.frame(1); + } + return this.jdiThread.frame(0); + } catch (IncompatibleThreadStateException e) { + e.printStackTrace(); + return null; + } +} +public boolean isConstructorCall() { + if (this.breakpointLine != Integer.MAX_VALUE) { // if not in a code snippet + StackFrame frame = getStackFrame(); + return frame.location().method().isConstructor(); + } + return false; +} +public boolean isStatic() { + if (this.breakpointLine != Integer.MAX_VALUE) { // if not in a code snippet + StackFrame frame = getStackFrame(); + return frame.location().method().isStatic(); + } + return false; +} +public int[] localVariableModifiers() { + try { + StackFrame frame = getStackFrame(); + List variables = frame.visibleVariables(); + int[] modifiers = new int[variables.size()]; +/* Iterator iterator = variables.iterator(); + int i = 0; + while (iterator.hasNext()) { + LocalVariable var = (LocalVariable)iterator.next(); + // TBD modifiers[i++] = var. ??? ; + } +*/ return modifiers; + } catch (AbsentInformationException e) { + return null; + } +} +public char[][] localVariableNames() { + try { + StackFrame frame = getStackFrame(); + Iterator variables = frame.visibleVariables().iterator(); + List names = new ArrayList<>(); + while (variables.hasNext()) { + LocalVariable var = (LocalVariable)variables.next(); + names.add(var.name().toCharArray()); + } + char[][] result = new char[names.size()][]; + names.toArray(result); + return result; + } catch (AbsentInformationException e) { + return null; + } +} +public char[][] localVariableTypeNames() { + try { + StackFrame frame = getStackFrame(); + Iterator variables = frame.visibleVariables().iterator(); + List names = new ArrayList(); + while (variables.hasNext()) { + LocalVariable var = (LocalVariable)variables.next(); + names.add(var.typeName().toCharArray()); + } + char[][] result = new char[names.size()][]; + names.toArray(result); + return result; + } catch (AbsentInformationException e) { + return null; + } +} +public boolean run(String codeSnippetClassName) { + ClassType codeSnippetClass; + ObjectReference codeSnippet; + Method method; + List arguments; + ObjectReference codeSnippetRunner; + try { + // Get the code snippet class + long start = System.currentTimeMillis(); + List classes = this.jdiVM.classesByName(codeSnippetClassName); + while (classes.size() == 0) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + classes = this.jdiVM.classesByName(codeSnippetClassName); + if (classes.size() == 0) { + // workaround bug in Standard VM + Iterator iterator = this.jdiVM.allClasses().iterator(); + while (iterator.hasNext()) { + ReferenceType type = (ReferenceType)iterator.next(); + if (type.name().equals(codeSnippetClassName)) { + classes = new ArrayList(1); + classes.add(type); + break; + } + } + if (classes.size() == 0 && (System.currentTimeMillis()-start) > this.timeout) { + return false; + } + } + } + codeSnippetClass = (ClassType)classes.get(0); + + // Create a new code snippet + Method constructor = codeSnippetClass.methodsByName("").get(0); + codeSnippet = codeSnippetClass.newInstance(this.jdiThread, constructor, new ArrayList(), ClassType.INVOKE_SINGLE_THREADED); + + // Install local variables and "this" into generated fields + StackFrame stackFrame = getStackFrame(); + try { + Iterator variables = stackFrame.visibleVariables().iterator(); + while (variables.hasNext()) { + LocalVariable jdiVariable = (LocalVariable)variables.next(); + Value value = stackFrame.getValue(jdiVariable); + Field field = codeSnippetClass.fieldByName(new String(LOCAL_VAR_PREFIX) + jdiVariable.name()); + codeSnippet.setValue(field, value); + } + } catch (AbsentInformationException e) { + // No variables + } + Field delegateThis = codeSnippetClass.fieldByName(new String(DELEGATE_THIS)); + ObjectReference thisObject; + if (delegateThis != null && ((thisObject = stackFrame.thisObject()) != null)) { + codeSnippet.setValue(delegateThis, thisObject); + } + + // Get the code snippet runner + ClassType codeSnippetRunnerClass = (ClassType)this.jdiVM.classesByName(CODE_SNIPPET_RUNNER_CLASS_NAME).get(0); + Field theRunner = codeSnippetRunnerClass.fieldByName(THE_RUNNER_FIELD); + codeSnippetRunner = (ObjectReference)codeSnippetRunnerClass.getValue(theRunner); + + // Get the method 'runCodeSnippet' and its arguments + method = codeSnippetRunnerClass.methodsByName(RUN_CODE_SNIPPET_METHOD).get(0); + arguments = new ArrayList(); + arguments.add(codeSnippet); + } catch (ClassNotLoadedException e) { + e.printStackTrace(); + return false; + } catch (IncompatibleThreadStateException e) { + e.printStackTrace(); + return false; + } catch (InvalidTypeException e) { + e.printStackTrace(); + return false; + } catch (InvocationException e) { + e.printStackTrace(); + return false; + } + + try { + // Invoke runCodeSnippet(CodeSnippet) + codeSnippetRunner.invokeMethod(this.jdiThread, method, arguments, ClassType.INVOKE_SINGLE_THREADED); + + // Retrieve values of local variables and put them back in the stack frame + StackFrame stackFrame = getStackFrame(); + try { + Iterator variables = stackFrame.visibleVariables().iterator(); + while (variables.hasNext()) { + LocalVariable jdiVariable = (LocalVariable)variables.next(); + Field field = codeSnippetClass.fieldByName(new String(LOCAL_VAR_PREFIX) + jdiVariable.name()); + Value value = codeSnippet.getValue(field); + stackFrame.setValue(jdiVariable, value); + } + } catch (AbsentInformationException e) { + // No variables + } + } catch (ClassNotLoadedException e) { + e.printStackTrace(); + } catch (IncompatibleThreadStateException e) { + e.printStackTrace(); + } catch (InvalidTypeException e) { + e.printStackTrace(); + } catch (InvocationException e) { + e.printStackTrace(); + } + return true; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java new file mode 100644 index 0000000000..5853639ec4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java @@ -0,0 +1,370 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; +import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; +import org.eclipse.jdt.internal.eval.GlobalVariable; +/** + * Negative tests for code snippet. Only compilation problems should be reported in + * these tests. + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class NegativeCodeSnippetTest extends EvaluationTest implements ProblemSeverities, ProblemReasons { +/** + * Creates a new NegativeCodeSnippetTest. + */ +public NegativeCodeSnippetTest(String name) { + super(name); +} +public static Test suite() { + return setupSuite(testClass()); +} +/** + * Test a scenario where the change of the package declaration causes a problem in a code snippet. + */ +public void _testChangePackage() { + if (isJRockitVM()) return; + try { + // define the package + this.context.setPackageName("java.util.zip".toCharArray()); + + // evaluate a code snippet that uses this variable + char[] codeSnippet = "new InflaterInputStream(new java.io.ByteArrayInputStream(new byte[0])).len".toCharArray(); + evaluateWithExpectedDisplayString( + codeSnippet, + "0".toCharArray()); + + // back to the default package but with correct import + this.context.setPackageName(new char[0]); + this.context.setImports(new char[][] {"java.util.zip.*".toCharArray()}); + + // evaluate same code snippet + evaluateWithExpectedProblem( + codeSnippet, + newProblem(IProblem.NotVisibleField, Error, 71, 73, 1)); // The field len is not visible + + // back to the default package and with no imports + this.context.setImports(new char[0][]); + + // evaluate same code snippet + evaluateWithExpectedProblem( + codeSnippet, + newProblem(IProblem.UndefinedType, Error, 4, 22, 1)); // The type InflaterInputStream is undefined + } finally { + // Clean up + this.context.setPackageName(new char[0]); + this.context.setImports(new char[0][]); + } +} +public static Class testClass() { + return NegativeCodeSnippetTest.class; +} +/** + * Test a code snippet which declares a class that uses an expression as a returned statement + * in one of its methods. + */ +public void testExpressionInInnerClass() { + //TODO (david) Syntax error diagnose should be improved in this case. + evaluateWithExpectedProblem(buildCharArray(new String[] { + "class X {", + " int foo() {", + " 1 + 1", + " }", + "}", + "return new X().foo();"}), + newProblem(IProblem.ParsingError, Error, 21, 21, 2)); // Syntax error on token "+" +} +/** + * Test extra closing curly bracket. + */ +public void testExtraClosingCurlyBracket() { + //TODO (david) Syntax error diagnose should be improved in this case. + // just an expression with an extra curly bracket + evaluateWithExpectedProblem( + "1 + 2}".toCharArray(), + newProblem(IProblem.ParsingError, Error, 0, 0, 1)); // Unmatched bracket + + // a statement followed by an unreachable expression with an extra curly bracket + evaluateWithExpectedProblem(buildCharArray(new String[] { + "return 1 + 1;", + " 2 + 2}"}), + newProblem(IProblem.ParsingError, Error, 15, 15, 2)); // Unmatched bracket +} +/** + * Test extra open round bracket. + */ +public void testExtraOpenRoundBracket() { + evaluateWithExpectedProblem( + "foo((a);".toCharArray(), + newProblem(IProblem.ParsingErrorInsertToComplete, Error, 6, 6, 1)); // Unmatched bracket +} +/** + * Test a code snippet that contains an expression followed by a semi-colon. + */ +public void testExtraSemiColonInExpression() { + evaluateWithExpectedProblem( + "1;".toCharArray(), + newProblem(IProblem.ParsingErrorInsertToComplete, Error, 0, 0, 1)); // Syntax error on token EOF +} +/** + * Test access to a non existing field. + * (regression test for bug 25250 Scrapbook shows wrong error message) + */ +public void testInvalidField() { + evaluateWithExpectedProblem( + ("String s = \"\";\n" + + "s.length").toCharArray(), + "length cannot be resolved or is not a field\n"); +} +/** + * Test a code snippet which is valid but the evaluation context imports have problems. + */ +public void testInvalidImport() { + try { + // problem on the first import + this.context.setImports(new char[][] {"bar.Y".toCharArray()}); + evaluateWithExpectedImportProblem(buildCharArray(new String[] { + "class X {", + " Y foo = new Y();", + "}", + "return new X().foo;"}), + "bar.Y".toCharArray(), + newProblem(IProblem.ImportNotFound, Error, 0, 4, 1)); // The import bar.Y could not be resolved + + // problem on the second import + this.context.setImports(new char[][] {"java.io.*".toCharArray(), "{".toCharArray()}); + evaluateWithExpectedImportProblem(buildCharArray(new String[] { + "new File(\"c:\\temp\")"}), + "{".toCharArray(), + newProblem(IProblem.ParsingErrorInvalidToken, Error, 0, 0, 1)); // Syntax error on token "{", "Identifier" expected + } finally { + // Clean up + this.context.setImports(new char[0][]); + } +} +/** + * Test use of this. + */ +public void testInvalidUseOfThisInSnippet() { + evaluateWithExpectedProblem( + "this".toCharArray(), + "Cannot use this in a static context\n"); +} +/** + * Test use of this. + */ +public void testInvalidUseOfThisInSnippet2() { + // just an expression with an extra curly bracket + evaluateWithExpectedProblem( + "return this;".toCharArray(), + "Cannot use this in a static context\n"); +} +/** + * Test a code snippet that misses a closing round bracket. + */ +public void testMissingClosingRoundBracket() { + evaluateWithExpectedProblem(buildCharArray(new String[] { + "System.out.println(\"3 + 3\";"}), + newProblem(IProblem.ParsingErrorInsertToComplete, Error, 19, 25, 1)); // Unmatched bracket +} +/** + * Test a code snippet that contains a string that misses the closing double quote . + */ +public void testMissingDoubleQuote() { + evaluateWithExpectedProblem(buildCharArray(new String[] { + "System.out.println(\"3 + 3 = );", + "3 + 3"}), + newProblem(IProblem.UnterminatedString , Error, 19, 29, 1)); // String literal is not properly closed by a double-quote +} +/** + * Test an expression which is not the last statement. + */ +public void testNonLastExpressionStatement() { + evaluateWithExpectedProblem(buildCharArray(new String[] { + "1 == '1';", + "true"}), + newProblem(IProblem.ParsingErrorInvalidToken, Error, 2, 3, 1)); // Syntax error on token "==" +} +/** + * Test a problem in the returned expression. + */ +public void testProblemInExpression() { + evaluateWithExpectedProblem( + "new Object(); 3 + ".toCharArray(), + newProblem(IProblem.ParsingErrorDeleteToken, Error, 16, 16, 1)); // Syntax error on token '+' +} +/** + * Test a problem in the returned expression. + */ +public void testProblemInExpression2() { + evaluateWithExpectedProblem( + "new UnknownClass()".toCharArray(), + newProblem(IProblem.UndefinedType, Error, 4, 15, 1)); // UnknownClass cannot be resolved to a type +} +/** + * Test a code snippet which declares a class that has a problem. + */ +public void testProblemInInnerClass() { + // class declared before the last expression + evaluateWithExpectedProblem(buildCharArray(new String[] { + "class X {", + " Y foo = new Y();", + "}", + "return new X().foo;"}), + newProblem(IProblem.UndefinedType, Error, 11, 11, 2)); // The type Y is undefined + + // class declared as part of the last expression + evaluateWithExpectedWarningAndDisplayString(buildCharArray(new String[] { + "return new Object() {", + " public String toString() {", + " int i = 0;", + " return \"an inner class\";", + " }", + "};"}), + new CategorizedProblem[] { + newProblem(IProblem.LocalVariableIsNeverUsed, Warning, 56, 56, 3), // The local variable i is never used + }, + "an inner class".toCharArray()); +} +/** + * Test a problem in the statement before the returned expression. + */ +public void testProblemInPreviousStatement() { + //TODO (david) Syntax error diagnose should be improved in this case. + evaluateWithExpectedProblem(buildCharArray(new String[] { + "return foo(a a);", + "1 + 3"}), + newProblem(IProblem.ParsingErrorDeleteToken, Error, 13, 13, 1)); // Syntax error on token "a" +} +/** + * Test a code snippet that has a problem in a return statement. + */ +public void testProblemInReturnStatement() { + evaluateWithExpectedProblem( + "return 1 ++ 1;".toCharArray(), + newProblem(IProblem.InvalidUnaryExpression, Error, 7, 7, 1)); // Invalid argument to operation ++/-- +} +/** + * Test a scenario where the removal of an import causes a problem in a code snippet. + */ +public void testRemoveImport() { + try { + // define the import + this.context.setImports(new char[][] {"java.io.*".toCharArray()}); + + // evaluate a code snippet that uses this variable + char[] codeSnippet = "new File(\"c:\\\\temp\")".toCharArray(); + evaluateWithExpectedDisplayString( + codeSnippet, + "c:\\temp".toCharArray()); + + // remove the import + this.context.setImports(new char[0][]); + + // evaluate same code snippet + evaluateWithExpectedProblem( + codeSnippet, + newProblem(IProblem.UndefinedType, Error, 4, 7, 1)); // The type File is undefined + } finally { + // Clean up + this.context.setImports(new char[0][]); + } +} +/** + * Test a scenario where the removal of a variable causes a problem in a code snippet. + */ +public void testRemoveVariable() { + GlobalVariable var = null; + try { + // define the variable + var = this.context.newVariable("int".toCharArray(), "i".toCharArray(), "1".toCharArray()); + installVariables(1); + + // evaluate a code snippet that uses this variable + char[] codeSnippet = "i".toCharArray(); + evaluateWithExpectedDisplayString( + codeSnippet, + "1".toCharArray()); + + // remove the variable + this.context.deleteVariable(var); + installVariables(0); + + // evaluate same code snippet + evaluateWithExpectedProblem( + codeSnippet, + newProblem(IProblem.UnresolvedVariable, Error, 0, 0, 1)); // i cannot be resolved to a variable + } finally { + // Clean up + if (var != null) { + this.context.deleteVariable(var); + } + } +} +/** + * Test a code snippet that contains an expression which is not reachable. + */ +public void testUnreachableExpression() { + evaluateWithExpectedProblem(buildCharArray(new String[] { + "return 1 + 1;", + "2 + 2"}), + newProblem(IProblem.CodeCannotBeReached, Error, 14, 18, 2)); // Unreachable code +} +/** + * Test a code snippet which is valid but never uses the evaluation context imports. + * (regression test for bug 18922 Scrapbook does not come back when errors in snippet) + */ +public void testUnusedImport() { + try { + this.context.setImports(new char[][] {"java.util.*".toCharArray()}); + + // evaluate with import as error + Map options = getCompilerOptions(); + options.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.ERROR); + + // force evaluation so that the following evaluation will use a CodeSnippetEvaluator instead + // of a VariableEvualator + evaluateWithExpectedValue("1".toCharArray(), "1".toCharArray(), "int".toCharArray()); + + evaluateWithExpectedImportProblem( + "new String(\"NOPE\")".toCharArray(), + "java.util.*".toCharArray(), + options, + newProblem(IProblem.UnusedImport, Error, 0, 10, 1)); // The import java.util.* is unused + } finally { + // Clean up + this.context.setImports(new char[0][]); + } +} +/** + * Test a code snippet that has warnings but no errors. + */ +public void testWarning() { + evaluateWithExpectedWarningAndDisplayString(buildCharArray(new String[] { + "int i;", + "1 + 1"}), + new CategorizedProblem[] { + newProblem(IProblem.LocalVariableIsNeverUsed, Warning, 4, 4, 1), // The local variable i is never used + }, + "2".toCharArray()); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeVariableTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeVariableTest.java new file mode 100644 index 0000000000..867330e1e1 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeVariableTest.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import junit.framework.Test; + +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons; +import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; +import org.eclipse.jdt.internal.eval.GlobalVariable; +/** + * Negative tests for variables. Only compilation problems should be reported in + * these tests. + */ +@SuppressWarnings({ "rawtypes" }) +public class NegativeVariableTest extends EvaluationTest implements ProblemSeverities, ProblemReasons { +/** + * Creates a new NegativeVariableTest. + */ +public NegativeVariableTest(String name) { + super(name); +} +public static Test suite() { + return setupSuite(testClass()); +} +public static Class testClass() { + return NegativeVariableTest.class; +} +/** + * Test a variable that has a problem in its initializer. + */ +public void testInitializerProblem() { + // Problem in first variable + GlobalVariable var = null; + try { + var = this.context.newVariable("int".toCharArray(), "i".toCharArray(), buildCharArray(new String[] { + "(1 + 1) *", + "(j + 2)"})); + evaluateWithExpectedProblem( + var, + newProblem(IProblem.UnresolvedVariable, Error, 11, 11, 2)); // j cannot be resolved to a variable + } finally { + if (var != null) { + this.context.deleteVariable(var); + } + } + + // Problem in second variable + GlobalVariable var1 = null; + GlobalVariable var2 = null; + try { + var1 = this.context.newVariable("Object".toCharArray(), "o".toCharArray(), "new Object()".toCharArray()); + var2 = this.context.newVariable("int".toCharArray(), "i".toCharArray(), buildCharArray(new String[] { + "(1 + 1) *", + "(1 ++ 2)"})); + evaluateWithExpectedProblem( + var2, + newProblem(IProblem.InvalidUnaryExpression, Error, 11, 11, 2)); // Invalid argument to operation ++/-- + } finally { + if (var1 != null) { + this.context.deleteVariable(var1); + } + if (var2 != null) { + this.context.deleteVariable(var2); + } + } + +} +/** + * Test a variable that has a problem in its name. + * TODO (david) investigate why changes in enum recovery caused this test to fail + */ +public void _testInvalidName() { + // Problem in first variable + GlobalVariable var = null; + try { + var = this.context.newVariable("int".toCharArray(), "!@#$%^&*()_".toCharArray(), "1".toCharArray()); + evaluateWithExpectedProblem( + var, + newProblem(IProblem.ParsingErrorDeleteTokens, Error, 0, 9, 0)); // Syntax error, delete these tokens + } finally { + if (var != null) { + this.context.deleteVariable(var); + } + } + + // Problem in second variable + GlobalVariable var1 = null; + GlobalVariable var2 = null; + try { + var1 = this.context.newVariable("String".toCharArray(), "foo".toCharArray(), "\"bar\"".toCharArray()); + var2 = this.context.newVariable("int".toCharArray(), "!@#$%^&*()_".toCharArray(), "1".toCharArray()); + evaluateWithExpectedProblem( + var2, + newProblem(IProblem.ParsingErrorDeleteTokens, Error, 0, 9, 0)); // Syntax error, delete these tokens + } finally { + if (var1 != null) { + this.context.deleteVariable(var1); + } + if (var2 != null) { + this.context.deleteVariable(var2); + } + } +} +/** + * Test a variable that has a problem in its type declaration. + */ +public void testUnknownType() { + // Problem in first variable + GlobalVariable var = null; + try { + var = this.context.newVariable("foo.Bar".toCharArray(), "var".toCharArray(), null); + evaluateWithExpectedProblem( + var, + newProblem(IProblem.UndefinedType, Error, 0, 2, -1)); // The type foo is undefined + } finally { + if (var != null) { + this.context.deleteVariable(var); + } + } + + // Problem in second variable + GlobalVariable var1 = null; + GlobalVariable var2 = null; + try { + var1 = this.context.newVariable("int".toCharArray(), "x".toCharArray(), null); + var2 = this.context.newVariable("foo.Bar".toCharArray(), "var".toCharArray(), null); + evaluateWithExpectedProblem( + var2, + newProblem(IProblem.UndefinedType, Error, 0, 2, -1)); // The type foo is undefined + } finally { + if (var1 != null) { + this.context.deleteVariable(var1); + } + if (var2 != null) { + this.context.deleteVariable(var2); + } + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SanityTestEvaluationContext.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SanityTestEvaluationContext.java new file mode 100644 index 0000000000..ded86dd7a9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SanityTestEvaluationContext.java @@ -0,0 +1,239 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.eval.EvaluationResult; +import org.eclipse.jdt.internal.eval.GlobalVariable; +import org.eclipse.jdt.internal.eval.IRequestor; +import org.eclipse.jdt.internal.eval.InstallException; +/** + * Sanity test the IEvaluationContext interface. + * For in depth tests, see VariableTest or CodeSnippetTest. + */ +@SuppressWarnings({ "rawtypes" }) +public class SanityTestEvaluationContext extends EvaluationTest { +/** + * Creates a new SanityEvaluationContextTest. + */ +public SanityTestEvaluationContext(String name) { + super(name); +} +public static Test suite() { + return setupSuite(testClass()); +} +/** + * Sanity test of IEvaluationContext.allVariables() + */ +public void testAllVariables() { + // No variables defined yet + GlobalVariable[] vars = this.context.allVariables(); + assertEquals("No variables should be defined", 0, vars.length); + + // Define 3 variables + this.context.newVariable("int".toCharArray(), "foo".toCharArray(), "1".toCharArray()); + this.context.newVariable("Object".toCharArray(), "bar".toCharArray(), null); + this.context.newVariable("String".toCharArray(), "zip".toCharArray(), "\"abcdefg\"".toCharArray()); + vars = this.context.allVariables(); + assertEquals("3 variables should be defined", 3, vars.length); + assertEquals("1st variable", "foo".toCharArray(), vars[0].getName()); + assertEquals("2nd variable", "bar".toCharArray(), vars[1].getName()); + assertEquals("3rd variable", "zip".toCharArray(), vars[2].getName()); + + // Remove 2nd variable + this.context.deleteVariable(vars[1]); + vars = this.context.allVariables(); + assertEquals("2 variables should be defined", 2, vars.length); + assertEquals("1st variable", "foo".toCharArray(), vars[0].getName()); + assertEquals("2nd variable", "zip".toCharArray(), vars[1].getName()); + + // Remove last variable + this.context.deleteVariable(vars[1]); + vars = this.context.allVariables(); + assertEquals("1 variable should be defined", 1, vars.length); + assertEquals("1st variable", "foo".toCharArray(), vars[0].getName()); + + // Remove 1st variable + this.context.deleteVariable(vars[0]); + vars = this.context.allVariables(); + assertEquals("No variables should be defined", 0, vars.length); +} +public static Class testClass() { + return SanityTestEvaluationContext.class; +} +/** + * Sanity test of IEvaluationContext.evaluate(char[], INameEnvironment, ConfigurableOption[], IRequestor , IProblemFactory) + */ +public void testEvaluate() { + Requestor requestor = new Requestor(); + char[] snippet = "return 1;".toCharArray(); + try { + this.context.evaluate(snippet, getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("No targetException " + e.getMessage(), false); + } + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("No problems with the code snippet", !result.hasProblems()); + assertTrue("Result has a value", result.hasValue()); + assertEquals("Value", "1".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); +} +/** + * Sanity test of IEvaluationContext.evaluateImports(INameEnvironment, IRequestor , IProblemFactory) + */ +public void testEvaluateImports() { + try { + // Define imports + this.context.setImports(new char[][] {"java.util.*".toCharArray(), "java.lang.reflect.Method".toCharArray()}); + + // Evaluate them + IRequestor requestor = new Requestor() { + @Override + public void acceptResult(EvaluationResult result) { + assertTrue("No problems with the imports", !result.hasProblems()); + } + }; + this.context.evaluateImports(getEnv(), requestor, getProblemFactory()); + } finally { + // Clean up + this.context.setImports(new char[0][]); + } +} +/** + * Sanity test of IEvaluationContext.evaluateVariable(IGlobalVariable, IRequestor) + */ +public void testEvaluateVariable() { + GlobalVariable var = null; + try { + // Create the variable + var = this.context.newVariable("int".toCharArray(), "foo".toCharArray(), "1".toCharArray()); + + // Install it + class NoPbRequestor extends Requestor { + @Override + public void acceptResult(EvaluationResult result) { + assertTrue("No problems with the variable", !result.hasProblems()); + } + } + try { + this.context.evaluateVariables(getEnv(), getCompilerOptions(), new NoPbRequestor(), getProblemFactory()); + } catch (InstallException e) { + assertTrue("No targetException " + e.getMessage(), false); + } + + // Get its value + Requestor requestor = new Requestor(); + try { + this.context.evaluateVariable(var, getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("No targetException " + e.getMessage(), false); + } + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("Result has value", result.hasValue()); + assertEquals("Value", "1".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + // Clean up + if (var != null) { + this.context.deleteVariable(var); + } + } +} +/** + * Sanity test of IEvaluationContext.evaluateVariables(INameEnvironment, ConfigurableOption[], IRequestor, IProblemFactory) + */ +public void testEvaluateVariables() { + GlobalVariable var = null; + try { + // Create 1 variable + var = this.context.newVariable("int".toCharArray(), "foo".toCharArray(), "1".toCharArray()); + + // Install it and get its value + Requestor requestor = new Requestor(); + try { + this.context.evaluateVariables(getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + assertTrue("No targetException " + e.getMessage(), false); + } + assertTrue("Got one result", requestor.resultIndex == 0); + EvaluationResult result = requestor.results[0]; + assertTrue("No problems with the variable", !result.hasProblems()); + assertTrue("Result has value", result.hasValue()); + assertEquals("Value", "1".toCharArray(), result.getValueDisplayString()); + assertEquals("Type", "int".toCharArray(), result.getValueTypeName()); + } finally { + // Clean up + if (var != null) { + this.context.deleteVariable(var); + } + } +} +/** + * Sanity test of IEvaluationContext.getImports() and IEvaluationContext.setImports(char[][]) + */ +public void testGetSetImports() { + try { + // No imports + assertTrue("No imports defined", this.context.getImports().length == 0); + + // Define some imports + char[][] imports = new char[][] {"java.util".toCharArray(), "java.lang.reflect.Method".toCharArray()}; + this.context.setImports(imports); + char[][] storedImports = this.context.getImports(); + assertEquals("Same length", imports.length, storedImports.length); + for (int i = 0; i < imports.length; i++){ + assertEquals("Import #" + i, imports[i], storedImports[i]); + } + } finally { + // Clean up + this.context.setImports(new char[0][]); + } +} +/** + * Sanity test of IEvaluationContext.getPackageName() and IEvaluationContext.setPackageName(char[]) + */ +public void testGetSetPackageName() { + try { + // Default package + assertTrue("Default package", this.context.getPackageName().length == 0); + + // Define a package + char[] packageName = "x.y.z".toCharArray(); + this.context.setPackageName(packageName); + char[] storedPackageName = this.context.getPackageName(); + assertEquals("Same package name", packageName, storedPackageName); + } finally { + // Clean up + this.context.setPackageName(new char[0]); + } +} +/** + * Sanity test of IEvaluationContext.newVariable(char[], char[], char[]) and + * IEvaluationContext.deleteVariable(IGlobalVariable) + */ +public void testNewDeleteVariable() { + // Define 1 variable + GlobalVariable var = this.context.newVariable("int".toCharArray(), "deleted".toCharArray(), null); + + // Delete it + this.context.deleteVariable(var); + GlobalVariable[] vars = this.context.allVariables(); + for (int i = 0; i < vars.length; i++) { + assertTrue("Variable should not exist", !var.getName().equals(vars[i].getName())); + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SanityTestEvaluationResult.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SanityTestEvaluationResult.java new file mode 100644 index 0000000000..b7a270910a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SanityTestEvaluationResult.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import junit.framework.Test; + +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.internal.eval.EvaluationResult; +import org.eclipse.jdt.internal.eval.IRequestor; +import org.eclipse.jdt.internal.eval.InstallException; +/** + * Sanity test the IEvaluationResult interface. + * For in depth tests, see VariableTest or CodeSnippetTest. + */ +@SuppressWarnings({ "rawtypes" }) +public class SanityTestEvaluationResult extends EvaluationTest { + EvaluationResult result; +/** + * Creates a new SanityEvaluationResultTest. + */ +public SanityTestEvaluationResult(String name) { + super(name); +} +/** + * Initializes this test with an evaluation result coming from the + * evaluation of the following code snippet: "return 1;". + */ +@Override +protected void setUp() throws Exception { + super.setUp(); + IRequestor requestor = new Requestor() { + @Override + public void acceptResult(EvaluationResult evalResult) { + SanityTestEvaluationResult.this.result = evalResult; + } + }; + try { + this.context.evaluate("return 1;".toCharArray(), getEnv(), getCompilerOptions(), requestor, getProblemFactory()); + } catch (InstallException e) { + throw new Error(e.getMessage()); + } +} +public static Test suite() { + return setupSuite(testClass()); +} +public static Class testClass() { + return SanityTestEvaluationResult.class; +} +/** + * Sanity test of IEvaluationResult.getEvaluationType() + */ +public void testGetEvaluationType() { + int evaluationType = this.result.getEvaluationType(); + assertEquals("Evaluation type", EvaluationResult.T_CODE_SNIPPET, evaluationType); +} +/** + * Sanity test of IEvaluationResult.getProblems() + */ +public void testGetProblems() { + CategorizedProblem[] problems = this.result.getProblems(); + assertTrue("Problems", problems == null || problems.length == 0); +} +/** + * Sanity test of IEvaluationResult.getValue() + */ +public void testGetValue() { + // TBD: Not implemented yet +} +/** + * Sanity test of IEvaluationResult.getValueDisplayString() + */ +public void testGetValueDisplayString() { + char[] displayString = this.result.getValueDisplayString(); + assertEquals("Value display string", "1".toCharArray(), displayString); +} +/** + * Sanity test of IEvaluationResult.getValueTypeName() + */ +public void testGetValueTypeName() { + char[] typeName = this.result.getValueTypeName(); + assertEquals("Value type name", "int".toCharArray(), typeName); +} +/** + * Sanity test of IEvaluationResult.hasErrors() + */ +public void testHasErrors() { + assertTrue("Result has no errors", !this.result.hasErrors()); +} +/** + * Sanity test of IEvaluationResult.hasProblems() + */ +public void testHasProblems() { + assertTrue("Result has no problems", !this.result.hasProblems()); +} +/** + * Sanity test of IEvaluationResult.hasValue() + */ +public void testHasValue() { + assertTrue("Result has a value", this.result.hasValue()); +} +/** + * Sanity test of IEvaluationResult.hasWarnings() + */ +public void testHasWarnings() { + assertTrue("Result has no warnings", !this.result.hasWarnings()); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleCodeSnippetTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleCodeSnippetTest.java new file mode 100644 index 0000000000..aaaa4062ae --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleCodeSnippetTest.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import org.eclipse.jdt.core.tests.runtime.TargetException; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.eval.InstallException; + + +public class SimpleCodeSnippetTest + extends SimpleTest { + public char[] getCodeSnippetSource() { + + return buildCharArray(new String[] { "1 + 1" }); + } + + public static void main(String[] args) + throws TargetException, InstallException { + + SimpleCodeSnippetTest test = new SimpleCodeSnippetTest(); + test.runCodeSnippet(); + } + + void runCodeSnippet() + throws TargetException, InstallException { + startEvaluationContext(); + + char[] snippet = getCodeSnippetSource(); + INameEnvironment env = getEnv(); + this.context.evaluate(snippet, env, null, this.requestor, + getProblemFactory()); + stopEvaluationContext(); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleTest.java new file mode 100644 index 0000000000..f8c9cf16f9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleTest.java @@ -0,0 +1,318 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import java.io.File; +import java.io.IOException; +import java.net.ServerSocket; + +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.tests.runtime.LocalVMLauncher; +import org.eclipse.jdt.core.tests.runtime.LocalVirtualMachine; + +import org.eclipse.jdt.core.tests.runtime.TargetException; +import org.eclipse.jdt.core.tests.runtime.TargetInterface; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.ClassFile; +import org.eclipse.jdt.internal.compiler.IProblemFactory; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.env.IBinaryField; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.eval.EvaluationContext; +import org.eclipse.jdt.internal.eval.EvaluationResult; +import org.eclipse.jdt.internal.eval.GlobalVariable; +import org.eclipse.jdt.internal.eval.IRequestor; + +public class SimpleTest { + static final String JRE_PATH = Util.getJREDirectory(); + static final String[] COMPILATION_CLASSPATH = Util.concatWithClassLibs(Util.getOutputDirectory(), false); + static final String[] RUNTIME_CLASSPATH = new String[] {Util.getOutputDirectory()}; + static final String TARGET_PATH = Util.getOutputDirectory() + File.separator + "evaluation"; + protected EvaluationContext context; + protected LocalVirtualMachine launchedVM; + protected TargetInterface target; + protected Requestor requestor; + + class Requestor implements IRequestor { + int globalProblemCount = 0; + public boolean acceptClassFiles(ClassFile[] classFiles, char[] codeSnippetClassName) { + try { + SimpleTest.this.target.sendClasses(codeSnippetClassName != null, classFiles); + } catch (TargetException e) { + return false; + } + if (codeSnippetClassName != null) { + TargetInterface.Result result = SimpleTest.this.target.getResult(); + if (result.displayString == null) { + System.out.println("(No explicit return value)"); + } else { + System.out.print("("); + System.out.print(result.typeName); + System.out.print(") "); + System.out.println(result.displayString); + } + } else { + for (int i = 0, length = classFiles.length; i < length; i++) { + char[][] compoundName = classFiles[i].getCompoundName(); + if (new String(compoundName[compoundName.length-1]).startsWith("GlobalVariable")) { + try { + IBinaryField[] fields = new ClassFileReader(classFiles[i].getBytes(), null).getFields(); + if (fields != null) { + for (int j = 0; j < fields.length; j++) { + TargetInterface.Result result = SimpleTest.this.target.getResult(); + if (result.displayString == null) { + System.out.println("(No explicit return value)"); + } else { + System.out.print("("); + System.out.print(result.typeName); + System.out.print(") "); + System.out.println(result.displayString); + } + } + } + } catch (ClassFormatException e) { + e.printStackTrace(); + } + } + } + } + return true; + } + public void acceptProblem(CategorizedProblem problem, char[] fragmentSource, int fragmentKind) { + int localErrorCount = 0; + this.globalProblemCount++; + char[] source = fragmentSource; + if (localErrorCount == 0) + System.out.println("----------"); + if (fragmentKind == EvaluationResult.T_INTERNAL) { + System.out.print(this.globalProblemCount + (problem.isError() ? ". INTERNAL ERROR" : ". INTERNAL WARNING")); + System.out.print(" in generated compilation unit"); + } else { + System.out.print(this.globalProblemCount + (problem.isError() ? ". ERROR" : ". WARNING")); + System.out.print(" in "); + switch (fragmentKind) { + case EvaluationResult.T_PACKAGE: + System.out.print("package"); + break; + case EvaluationResult.T_IMPORT: + System.out.print("import"); + break; + case EvaluationResult.T_CODE_SNIPPET: + System.out.print("code snippet"); + break; + case EvaluationResult.T_VARIABLE: + int line = problem.getSourceLineNumber(); + if (line == -1) { + System.out.print("variable type"); + source = findVar(fragmentSource).getTypeName(); + } else if (line == 0) { + System.out.print("variable name"); + source = findVar(fragmentSource).getName(); + } else { + System.out.print("variable initializer"); + source = findVar(fragmentSource).getInitializer(); + } + break; + } + } + System.out.println(errorReportSource((DefaultProblem)problem, source)); + System.out.println(problem.getMessage()); + System.out.println("----------"); + if (problem.isError()) + localErrorCount++; + } + } +/** + * Build a char array from the given lines + */ +protected char[] buildCharArray(String[] lines) { + String buffer = String.join("\n", lines); + int length = buffer.length(); + char[] result = new char[length]; + buffer.getChars(0, length, result, 0); + return result; +} +protected String errorReportSource(DefaultProblem problem, char[] source) { + //extra from the source the innacurate token + //and "highlight" it using some underneath ^^^^^ + //put some context around too. + + //this code assumes that the font used in the console is fixed size + + //sanity ..... + if ((problem.getSourceStart() > problem.getSourceEnd()) || ((problem.getSourceStart() < 0) && (problem.getSourceEnd() < 0))) + return "\n!! no source information available !!"; + + //regular behavior....(slow code) + + final char SPACE = '\u0020'; + final char MARK = '^'; + final char TAB = '\t'; + //the next code tries to underline the token..... + //it assumes (for a good display) that token source does not + //contain any \r \n. This is false on statements ! + //(the code still works but the display is not optimal !) + + //compute the how-much-char we are displaying around the inaccurate token + int begin = problem.getSourceStart() >= source.length ? source.length - 1 : problem.getSourceStart(); + int relativeStart = 0; + int end = problem.getSourceEnd() >= source.length ? source.length - 1 : problem.getSourceEnd(); + label : for (relativeStart = 0;; relativeStart++) { + if (begin == 0) + break label; + if ((source[begin - 1] == '\n') || (source[begin - 1] == '\r')) + break label; + begin--; + } + label : for (;;) { + if ((end + 1) >= source.length) + break label; + if ((source[end + 1] == '\r') || (source[end + 1] == '\n')) { + break label; + } + end++; + } + //extract the message form the source + char[] extract = new char[end - begin + 1]; + System.arraycopy(source, begin, extract, 0, extract.length); + char c; + //remove all SPACE and TAB that begin the error message... + int trimLeftIndex = 0; + while (((c = extract[trimLeftIndex++]) == TAB) || (c == SPACE)) { + } + System.arraycopy(extract, trimLeftIndex - 1, extract = new char[extract.length - trimLeftIndex + 1], 0, extract.length); + relativeStart -= trimLeftIndex; + //buffer spaces and tabs in order to reach the error position + int pos = 0; + char[] underneath = new char[extract.length]; // can't be bigger + for (int i = 0; i <= relativeStart; i++) { + if (extract[i] == TAB) { + underneath[pos++] = TAB; + } else { + underneath[pos++] = SPACE; + } + } + //mark the error position + for (int i = problem.getSourceStart(); i <= (problem.getSourceEnd() >= source.length ? source.length - 1 : problem.getSourceEnd()); i++) + underneath[pos++] = MARK; + //resize underneathto remove 'null' chars + System.arraycopy(underneath, 0, underneath = new char[pos], 0, pos); + return + ((problem.getSourceLineNumber() > 0) ? + (" (at line " + String.valueOf(problem.getSourceLineNumber()) + ")") : + "" + ) + + "\n\t" + new String(extract) + "\n\t" + new String(underneath); +} +protected GlobalVariable findVar(char[] varName) { + GlobalVariable[] vars = this.context.allVariables(); + for (int i = 0; i < vars.length; i++) { + GlobalVariable var = vars[i]; + if (CharOperation.equals(var.getName(), varName)) { + return var; + } + } + return null; +} +protected INameEnvironment getEnv() { + + return new FileSystem(COMPILATION_CLASSPATH, new String[0], null); +} +protected IProblemFactory getProblemFactory() { + return new DefaultProblemFactory(java.util.Locale.getDefault()); +} +protected void startEvaluationContext() throws TargetException { + try (ServerSocket server = new ServerSocket(0)) { + LocalVMLauncher launcher = LocalVMLauncher.getLauncher(); + launcher.setVMPath(JRE_PATH); + launcher.setClassPath(RUNTIME_CLASSPATH); + int evalPort = server.getLocalPort(); + launcher.setEvalPort(evalPort); + launcher.setEvalTargetPath(TARGET_PATH); + this.launchedVM = launcher.launch(); + + (new Thread() { + @Override + public void run() { + try { + java.io.InputStream in = SimpleTest.this.launchedVM.getInputStream(); + int read = 0; + while (read != -1) { + try { + read = in.read(); + } catch (java.io.IOException e) { + read = -1; + } + if (read != -1) { + System.out.print((char)read); + } + } + } catch (TargetException e) { + } + } + }).start(); + + (new Thread() { + @Override + public void run() { + try { + java.io.InputStream in = SimpleTest.this.launchedVM.getErrorStream(); + int read = 0; + while (read != -1) { + try { + read = in.read(); + } catch (java.io.IOException e) { + read = -1; + } + if (read != -1) { + System.out.print((char)read); + } + } + } catch (TargetException e) { + } + } + }).start(); + + this.requestor = new Requestor(); + this.target = new TargetInterface(); + this.target.connect(server, 30000); // allow 30s max to connect (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=188127) + this.context = new EvaluationContext(); + } catch (IOException e) { + throw new Error("Failed to open socket", e); + } +} +protected void stopEvaluationContext() { + try { + this.target.disconnect(); // Close the socket first so that the OS resource has a chance to be freed. + int retry = 0; + while (this.launchedVM.isRunning() && (++retry < 20)) { + try { + Thread.sleep(retry * 100); + } catch (InterruptedException e) { + } + } + if (this.launchedVM.isRunning()) { + this.launchedVM.shutDown(); + } + this.context = null; + } catch (TargetException e) { + throw new Error(e.getMessage()); + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleVariableTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleVariableTest.java new file mode 100644 index 0000000000..6748a7b946 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/SimpleVariableTest.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import org.eclipse.jdt.core.tests.runtime.TargetException; +import org.eclipse.jdt.internal.compiler.env.INameEnvironment; +import org.eclipse.jdt.internal.eval.GlobalVariable; +import org.eclipse.jdt.internal.eval.InstallException; + +public class SimpleVariableTest extends SimpleTest { +void evaluateVariable() throws TargetException, InstallException { + startEvaluationContext(); + GlobalVariable var = getVariable(); + INameEnvironment env = getEnv(); + this.context.evaluateVariables(env, null, this.requestor, getProblemFactory()); + this.context.deleteVariable(var); + stopEvaluationContext(); +} +public GlobalVariable getVariable() { + return this.context.newVariable( + "int".toCharArray(), + "var".toCharArray(), + "1".toCharArray()); +} +public static void main(String[] args) throws TargetException, InstallException { + SimpleVariableTest test = new SimpleVariableTest(); + test.evaluateVariable(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/TestAll.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/TestAll.java new file mode 100644 index 0000000000..2e655b1ea6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/TestAll.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import java.util.ArrayList; + +import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; + +import junit.framework.Test; +/** + * Run all tests defined in this package. + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class TestAll extends EvaluationTest { +public TestAll(String name) { + super(name); +} +public static Test suite() { + ArrayList testClasses = new ArrayList(); + testClasses.add(SanityTestEvaluationContext.class); + testClasses.add(SanityTestEvaluationResult.class); + testClasses.add(VariableTest.class); + testClasses.add(CodeSnippetTest.class); + testClasses.add(NegativeCodeSnippetTest.class); + testClasses.add(NegativeVariableTest.class); + testClasses.add(DebugEvaluationTest.class); + + return AbstractCompilerTest.buildAllCompliancesTestSuite(TestAll.class, DebugEvaluationSetup.class, testClasses); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/VariableTest.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/VariableTest.java new file mode 100644 index 0000000000..b415fb937a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/VariableTest.java @@ -0,0 +1,299 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval; + +import junit.framework.Test; + +import org.eclipse.jdt.internal.eval.GlobalVariable; +/** + * Test the global variable evaluation. + * This assumes that the EvaluationContext class and that the GlobalVariable class + * are working correctly. + */ +@SuppressWarnings({ "rawtypes" }) +public class VariableTest extends EvaluationTest { +/** + * Creates a new EvaluationContextTest. + */ +public VariableTest(String name) { + super(name); +} +public static Test suite() { + return setupSuite(testClass()); +} +/** + * Tests the individual evaluation of variables with expected values of all kind of types. + */ +public void testAllKindOfValues() { + try { + // Creates the variables + GlobalVariable var1 = this.context.newVariable("int".toCharArray(), "var1".toCharArray(), "1".toCharArray()); + GlobalVariable var2 = this.context.newVariable("boolean".toCharArray(), "var2".toCharArray(), "true".toCharArray()); + GlobalVariable var3 = this.context.newVariable("char".toCharArray(), "var3".toCharArray(), "'c'".toCharArray()); + GlobalVariable var4 = this.context.newVariable("float".toCharArray(), "var4".toCharArray(), "(float)1.0".toCharArray()); + GlobalVariable var5 = this.context.newVariable("double".toCharArray(), "var5".toCharArray(), "1.0".toCharArray()); + GlobalVariable var6 = this.context.newVariable("short".toCharArray(), "var6".toCharArray(), "(short)1".toCharArray()); + GlobalVariable var7 = this.context.newVariable("long".toCharArray(), "var7".toCharArray(), "(long)1".toCharArray()); + GlobalVariable var8 = this.context.newVariable("String".toCharArray(), "var8".toCharArray(), "\"hello\"".toCharArray()); + GlobalVariable var9 = this.context.newVariable("Object".toCharArray(), "var9".toCharArray(), buildCharArray(new String[] { + "new Object() {", + " public String toString() {", + " return \"an object\";", + " }", + "}"})); + GlobalVariable var10 = this.context.newVariable("Object".toCharArray(), "var10".toCharArray(), null); + + // Install them + installVariables(10); + + // Get values one by one + evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray()); + evaluateWithExpectedValue(var2, "true".toCharArray(), "boolean".toCharArray()); + evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray()); + evaluateWithExpectedValue(var4, "1.0".toCharArray(), "float".toCharArray()); + evaluateWithExpectedValue(var5, "1.0".toCharArray(), "double".toCharArray()); + evaluateWithExpectedValue(var6, "1".toCharArray(), "short".toCharArray()); + evaluateWithExpectedValue(var7, "1".toCharArray(), "long".toCharArray()); + evaluateWithExpectedValue(var8, "hello".toCharArray(), "java.lang.String".toCharArray()); + evaluateWithExpectedValue(var9, "an object".toCharArray(), "java.lang.Object".toCharArray()); + evaluateWithExpectedValue(var10, "null".toCharArray(), "java.lang.Object".toCharArray()); + } finally { + // Clean up + GlobalVariable[] vars = this.context.allVariables(); + for (int i = 0; i < vars.length; i++) { + this.context.deleteVariable(vars[i]); + } + } +} +public static Class testClass() { + return VariableTest.class; +} +/** + * Tests the assignment of a global variable in a code snippet. + */ +public void testCodeSnippetVarAssign() { + try { + // Creates the variables + GlobalVariable var1 = this.context.newVariable("int".toCharArray(), "var1".toCharArray(), null); + GlobalVariable var2 = this.context.newVariable("boolean".toCharArray(), "var2".toCharArray(), null); + GlobalVariable var3 = this.context.newVariable("char".toCharArray(), "var3".toCharArray(), null); + GlobalVariable var4 = this.context.newVariable("float".toCharArray(), "var4".toCharArray(), null); + GlobalVariable var5 = this.context.newVariable("double".toCharArray(), "var5".toCharArray(), null); + GlobalVariable var6 = this.context.newVariable("short".toCharArray(), "var6".toCharArray(), null); + GlobalVariable var7 = this.context.newVariable("long".toCharArray(), "var7".toCharArray(), null); + GlobalVariable var8 = this.context.newVariable("String".toCharArray(), "var8".toCharArray(), null); + GlobalVariable var9 = this.context.newVariable("Object".toCharArray(), "var9".toCharArray(), null); + GlobalVariable var10 = this.context.newVariable("Object".toCharArray(), "var10".toCharArray(), null); + + // Install them + installVariables(10); + + // Assign each of the variable and get its value + evaluateWithExpectedDisplayString("var1 = 1;".toCharArray(), "1".toCharArray()); + evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray()); + + evaluateWithExpectedDisplayString("var2 = true;".toCharArray(), "true".toCharArray()); + evaluateWithExpectedValue(var2, "true".toCharArray(), "boolean".toCharArray()); + + evaluateWithExpectedDisplayString("var3 = 'c';".toCharArray(), "c".toCharArray()); + evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray()); + + evaluateWithExpectedDisplayString("var4 = (float)1.0;".toCharArray(), "1.0".toCharArray()); + evaluateWithExpectedValue(var4, "1.0".toCharArray(), "float".toCharArray()); + + evaluateWithExpectedDisplayString("var5 = 1.0;".toCharArray(), "1.0".toCharArray()); + evaluateWithExpectedValue(var5, "1.0".toCharArray(), "double".toCharArray()); + + evaluateWithExpectedDisplayString("var6 = (short)1;".toCharArray(), "1".toCharArray()); + evaluateWithExpectedValue(var6, "1".toCharArray(), "short".toCharArray()); + + evaluateWithExpectedDisplayString("var7 = (long)1;".toCharArray(), "1".toCharArray()); + evaluateWithExpectedValue(var7, "1".toCharArray(), "long".toCharArray()); + + evaluateWithExpectedDisplayString("var8 = \"hello\";".toCharArray(), "hello".toCharArray()); + evaluateWithExpectedValue(var8, "hello".toCharArray(), "java.lang.String".toCharArray()); + + evaluateWithExpectedDisplayString(buildCharArray(new String[] { + "var9 = new Object() {", + " public String toString() {", + " return \"an object\";", + " }", + "};"}), "an object".toCharArray()); + evaluateWithExpectedValue(var9, "an object".toCharArray(), "java.lang.Object".toCharArray()); + + evaluateWithExpectedDisplayString("var10 = null;".toCharArray(), "null".toCharArray()); + evaluateWithExpectedValue(var10, "null".toCharArray(), "java.lang.Object".toCharArray()); + } finally { + // Clean up + GlobalVariable[] vars = this.context.allVariables(); + for (int i = 0; i < vars.length; i++) { + this.context.deleteVariable(vars[i]); + } + } +} +/** + * Tests the retrieval of a global variable from a code snippet. + */ +public void testCodeSnippetVarRetrieval() { + try { + // Creates the variables + GlobalVariable var1 = this.context.newVariable("int".toCharArray(), "var1".toCharArray(), "1".toCharArray()); + GlobalVariable var2 = this.context.newVariable("boolean".toCharArray(), "var2".toCharArray(), "true".toCharArray()); + GlobalVariable var3 = this.context.newVariable("char".toCharArray(), "var3".toCharArray(), "'c'".toCharArray()); + GlobalVariable var4 = this.context.newVariable("float".toCharArray(), "var4".toCharArray(), "(float)1.0".toCharArray()); + GlobalVariable var5 = this.context.newVariable("double".toCharArray(), "var5".toCharArray(), "1.0".toCharArray()); + GlobalVariable var6 = this.context.newVariable("short".toCharArray(), "var6".toCharArray(), "(short)1".toCharArray()); + GlobalVariable var7 = this.context.newVariable("long".toCharArray(), "var7".toCharArray(), "(long)1".toCharArray()); + GlobalVariable var8 = this.context.newVariable("String".toCharArray(), "var8".toCharArray(), "\"hello\"".toCharArray()); + GlobalVariable var9 = this.context.newVariable("Object".toCharArray(), "var9".toCharArray(), buildCharArray(new String[] { + "new Object() {", + " public String toString() {", + " return \"an object\";", + " }", + "}"})); + GlobalVariable var10 = this.context.newVariable("Object".toCharArray(), "var10".toCharArray(), null); + + // Install them + installVariables(10); + + // Get values one by one + evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray()); + evaluateWithExpectedValue(var2, "true".toCharArray(), "boolean".toCharArray()); + evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray()); + evaluateWithExpectedValue(var4, "1.0".toCharArray(), "float".toCharArray()); + evaluateWithExpectedValue(var5, "1.0".toCharArray(), "double".toCharArray()); + evaluateWithExpectedValue(var6, "1".toCharArray(), "short".toCharArray()); + evaluateWithExpectedValue(var7, "1".toCharArray(), "long".toCharArray()); + evaluateWithExpectedValue(var8, "hello".toCharArray(), "java.lang.String".toCharArray()); + evaluateWithExpectedValue(var9, "an object".toCharArray(), "java.lang.Object".toCharArray()); + evaluateWithExpectedValue(var10, "null".toCharArray(), "java.lang.Object".toCharArray()); + } finally { + // Clean up + GlobalVariable[] vars = this.context.allVariables(); + for (int i = 0; i < vars.length; i++) { + this.context.deleteVariable(vars[i]); + } + } +} +/** + * Tests variables that include one or more imports. + */ +public void testImports() { + try { + // import a package + this.context.setImports(new char[][] {"java.io.*".toCharArray()}); + GlobalVariable file = this.context.newVariable("boolean".toCharArray(), "file".toCharArray(), "new File(\"!@#%\").exists()".toCharArray()); + installVariables(1); + evaluateWithExpectedValue(file, "false".toCharArray(), "boolean".toCharArray()); + this.context.deleteVariable(file); + + // import a type + this.context.setImports(new char[][] {"java.math.BigInteger".toCharArray()}); + GlobalVariable big = this.context.newVariable("BigInteger".toCharArray(), "big".toCharArray(), "new BigInteger(\"123456789012345678901234567890\")".toCharArray()); + installVariables(1); + evaluateWithExpectedValue(big, "123456789012345678901234567890".toCharArray(), "java.math.BigInteger".toCharArray()); + this.context.deleteVariable(big); + + // import a type and a package + this.context.setImports(new char[][] {"java.util.Enumeration".toCharArray(), "java.lang.reflect.*".toCharArray()}); + GlobalVariable fields = this.context.newVariable("Field[]".toCharArray(), "fields".toCharArray(), "Enumeration.class.getDeclaredFields()".toCharArray()); + installVariables(1); + evaluateWithExpectedType("return fields;".toCharArray(), "[Ljava.lang.reflect.Field;".toCharArray()); + this.context.deleteVariable(fields); + } finally { + // clean up + this.context.setImports(new char[0][]); + } +} +/** + * Tests the additions and deletion of variables, installing them each time. + */ +public void testSeveralVariableInstallations() { + try { + // Creates 6 variables + GlobalVariable var1 = this.context.newVariable("int".toCharArray(), "var1".toCharArray(), "1".toCharArray()); + GlobalVariable var2 = this.context.newVariable("boolean".toCharArray(), "var2".toCharArray(), "true".toCharArray()); + GlobalVariable var3 = this.context.newVariable("char".toCharArray(), "var3".toCharArray(), "'c'".toCharArray()); + GlobalVariable var4 = this.context.newVariable("float".toCharArray(), "var4".toCharArray(), "(float)1.0".toCharArray()); + GlobalVariable var5 = this.context.newVariable("double".toCharArray(), "var5".toCharArray(), "1.0".toCharArray()); + GlobalVariable var6 = this.context.newVariable("short".toCharArray(), "var6".toCharArray(), "(short)1".toCharArray()); + + // Install the variables + installVariables(6); + + // Get their values + evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray()); + evaluateWithExpectedValue(var2, "true".toCharArray(), "boolean".toCharArray()); + evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray()); + evaluateWithExpectedValue(var4, "1.0".toCharArray(), "float".toCharArray()); + evaluateWithExpectedValue(var5, "1.0".toCharArray(), "double".toCharArray()); + evaluateWithExpectedValue(var6, "1".toCharArray(), "short".toCharArray()); + + // Delete 3 variables + this.context.deleteVariable(var2); + this.context.deleteVariable(var5); + this.context.deleteVariable(var6); + + // Install the variables + installVariables(3); + + // Get their values + evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray()); + evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray()); + evaluateWithExpectedValue(var4, "1.0".toCharArray(), "float".toCharArray()); + + // Add 4 more variables + GlobalVariable var7 = this.context.newVariable("long".toCharArray(), "var7".toCharArray(), "(long)1".toCharArray()); + GlobalVariable var8 = this.context.newVariable("String".toCharArray(), "var8".toCharArray(), "\"hello\"".toCharArray()); + GlobalVariable var9 = this.context.newVariable("Object".toCharArray(), "var9".toCharArray(), buildCharArray(new String[] { + "new Object() {", + " public String toString() {", + " return \"an object\";", + " }", + "}"})); + GlobalVariable var10 = this.context.newVariable("Object".toCharArray(), "var10".toCharArray(), null); + + // Install the variables + installVariables(7); + + // Change value of a variable using a code snippet and move it + evaluateWithExpectedValue("var3 = 'z'; return var3;".toCharArray(), "z".toCharArray(), "char".toCharArray()); + this.context.deleteVariable(var3); + + // Change the type of another variable to an incompatible type + this.context.deleteVariable(var4); + installVariables(5); + + // Recreate the variables + var3 = this.context.newVariable(var3.getTypeName(), var3.getName(), var3.getInitializer()); + var4 = this.context.newVariable("java.net.URL".toCharArray(), "var4".toCharArray(), "new java.net.URL(\"http://www.ibm.com/index.html\")".toCharArray()); + installVariables(7); + + // Get their values + evaluateWithExpectedValue(var1, "1".toCharArray(), "int".toCharArray()); + evaluateWithExpectedValue(var3, "c".toCharArray(), "char".toCharArray()); + evaluateWithExpectedValue(var4, "http://www.ibm.com/index.html".toCharArray(), "java.net.URL".toCharArray()); + evaluateWithExpectedValue(var7, "1".toCharArray(), "long".toCharArray()); + evaluateWithExpectedValue(var8, "hello".toCharArray(), "java.lang.String".toCharArray()); + evaluateWithExpectedValue(var9, "an object".toCharArray(), "java.lang.Object".toCharArray()); + evaluateWithExpectedValue(var10, "null".toCharArray(), "java.lang.Object".toCharArray()); + } finally { + // Clean up + GlobalVariable[] vars = this.context.allVariables(); + for (int i = 0; i < vars.length; i++) { + this.context.deleteVariable(vars[i]); + } + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/CodeSnippetClassLoader.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/CodeSnippetClassLoader.java new file mode 100644 index 0000000000..17296cdc5d --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/CodeSnippetClassLoader.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval.target; + +import java.util.*; + +/** + * A code snippet class loader is a class loader that loads code snippet classes and global + * variable classes. + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class CodeSnippetClassLoader extends ClassLoader { + /** + * Whether the code snippet support classes should be given by the IDE + * or should be found on disk. + */ + static boolean DEVELOPMENT_MODE = false; + + Hashtable loadedClasses = new Hashtable(); +/** + * Asks the class loader that loaded this class to load the given class. + * @throws ClassNotFoundException if it could not be loaded. + */ +private Class delegateLoadClass(String name) throws ClassNotFoundException { + ClassLoader myLoader = getClass().getClassLoader(); + if (myLoader == null) { + return Class.forName(name); + } + return myLoader.loadClass(name); +} +/** + * Loads the given class. If the class is known to this runner, returns it. + * If only the class definition is known to this runner, makes it a class and returns it. + * Otherwise delegates to the real class loader. + */ +@Override +protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + if (DEVELOPMENT_MODE) { + try { + return delegateLoadClass(name); + } catch (ClassNotFoundException e) { + Class clazz = makeClass(name, resolve); + if (clazz == null) { + throw e; + } + return clazz; + } + } + Class clazz = makeClass(name, resolve); + if (clazz == null) { + return delegateLoadClass(name); + } + return clazz; +} +/** + * Loads the given class either from the stored class definition or from the system. + * Returns the existing class if it has already been loaded. + * Returns null if no class definition can be found. + */ +Class loadIfNeeded(String className) { + Class clazz = null; + if (!supportsHotCodeReplacement()) { + clazz = findLoadedClass(className); + } + if (clazz == null) { + try { + clazz = loadClass(className, true); + } catch (NoClassDefFoundError e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + return clazz; +} +/** + * Makes the class definition known by this code snippet runner a real class and + * returns it. + * Returns null if there is no class definition. + */ +private Class makeClass(String name, boolean resolve) { + Object o = this.loadedClasses.get(name); + if (o == null) { + return null; + } + if (o instanceof Class) { + return (Class) o; + } + byte[] classDefinition = (byte[]) o; + Class clazz = defineClass(null, classDefinition, 0, classDefinition.length); + if (resolve) { + resolveClass(clazz); + } + this.loadedClasses.put(name, clazz); + return clazz; +} +/** + * Stores the given class definition for the given class. + */ +void storeClassDefinition(String className, byte[] classDefinition) { + Object clazz = this.loadedClasses.get(className); + if (clazz == null || supportsHotCodeReplacement()) { + this.loadedClasses.put(className, classDefinition); + } +} +/** + * Returns whether this class loader supports Hot Code Replacement. + */ +protected boolean supportsHotCodeReplacement() { + return false; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/CodeSnippetRunner.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/CodeSnippetRunner.java new file mode 100644 index 0000000000..9098ddbe60 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/CodeSnippetRunner.java @@ -0,0 +1,518 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval.target; + +import java.lang.reflect.*; +import java.io.*; +import java.util.*; + +/** + * A code snippet runner loads code snippet classes and global + * variable classes, and that run the code snippet classes. + *

    + * When started, this runner first connects using TCP/IP to the provided port number. + * If a regular classpath directory is provided, it writes the class definitions it gets from the IDE + * to this directory (or to the bootclasspath directory if the class name starts with "java") and it + * lets the system class loader (or the bootstrap class loader if it is a "java" class) load + * the class. + * If the regular classpath directory is null, it uses a code snippet class loader to load the classes + * it gets from the IDE. + *

    + * IMPORTANT NOTE: + * Using a code snippet class loader has the following limitation when the code snippet is ran: + *

      + *
    • The code snippet class can access only public classes, and public members or these classes. + * This is because the "runtime package" of the code snippet class is always different from + * the "runtime package" of the class it is trying to access since the class loaders are + * different. + *
    • The code snippet class cannot be defined in a "java.*" package. Only the bootstrap class + * loader can load such a class. + *
    + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class CodeSnippetRunner { + public static CodeSnippetRunner theRunner; + static final String CODE_SNIPPET_CLASS_NAME = "org.eclipse.jdt.internal.eval.target.CodeSnippet"; + static final String RUN_METHOD_NAME = "run"; + static final String GET_RESULT_TYPE_METHOD_NAME = "getResultType"; + static final String GET_RESULT_VALUE_METHOD_NAME = "getResultValue"; + + IDEInterface ide; + String classPathDirectory; + String bootclassPathDirectory; + CodeSnippetClassLoader loader; + Class codeSnippetClass = null; +/** + * Creates a new code snippet runner. + */ +public CodeSnippetRunner(int portNumber, String classPathDirectory, String bootclassPathDirectory) { + this.ide = new IDEInterface(portNumber); + if (classPathDirectory != null) { + this.classPathDirectory = classPathDirectory; + if (bootclassPathDirectory != null) { + this.bootclassPathDirectory = bootclassPathDirectory; + } + } else { + this.loader = new CodeSnippetClassLoader(); + } +} +/** + * Returns the forward slash separated class name from the given class definition. + */ +private String className(byte[] classDefinition) { + // NB: The following code was copied from org.eclipse.jdt.internal.compiler.cfmt, + // thus it is highly dependent on the class file format. + int readOffset = 10; + try { + int constantPoolCount = u2At(8, classDefinition); + int[] constantPoolOffsets = new int[constantPoolCount]; + for (int i = 1; i < constantPoolCount; i++) { + int tag = u1At(readOffset, classDefinition); + switch (tag) { + case 1 : // Utf8Tag + constantPoolOffsets[i] = readOffset; + readOffset += u2At(readOffset + 1, classDefinition); + readOffset += 3; // ConstantUtf8.fixedSize + break; + case 3 : // IntegerTag + constantPoolOffsets[i] = readOffset; + readOffset += 5; // ConstantInteger.fixedSize + break; + case 4 : // FloatTag + constantPoolOffsets[i] = readOffset; + readOffset += 5; // ConstantFloat.fixedSize + break; + case 5 : // LongTag + constantPoolOffsets[i] = readOffset; + readOffset += 9; // ConstantLong.fixedSize + i++; + break; + case 6 : // DoubleTag + constantPoolOffsets[i] = readOffset; + readOffset += 9; // ConstantDouble.fixedSize + i++; + break; + case 7 : // ClassTag + constantPoolOffsets[i] = readOffset; + readOffset += 3; // ConstantClass.fixedSize + break; + case 8 : // StringTag + constantPoolOffsets[i] = readOffset; + readOffset += 3; // ConstantString.fixedSize + break; + case 9 : // FieldRefTag + constantPoolOffsets[i] = readOffset; + readOffset += 5; // ConstantFieldRef.fixedSize + break; + case 10 : // MethodRefTag + constantPoolOffsets[i] = readOffset; + readOffset += 5; // ConstantMethodRef.fixedSize + break; + case 11 : // InterfaceMethodRefTag + constantPoolOffsets[i] = readOffset; + readOffset += 5; // ConstantInterfaceMethodRef.fixedSize + break; + case 12 : // NameAndTypeTag + constantPoolOffsets[i] = readOffset; + readOffset += 5; // ConstantNameAndType.fixedSize + break; + case 15 : // MethodHandleTag + constantPoolOffsets[i] = readOffset; + readOffset += 4; // MethodHandle.fixedSize + break; + case 16 : // MethodTypeTag + constantPoolOffsets[i] = readOffset; + readOffset += 3; // MethodType.fixedSize + break; + case 17 : // DynamicTag + constantPoolOffsets[i] = readOffset; + readOffset += 5; // Dynamic.fixedSize + break; + case 18 : // InvokeDynamicTag + constantPoolOffsets[i] = readOffset; + readOffset += 5; // InvokeDynamic.fixedSize + break; + case 19 : // ModuleTag + constantPoolOffsets[i] = readOffset; + readOffset += 3; // Module.fixedSize + break; + case 20 : // PackageTag + constantPoolOffsets[i] = readOffset; + readOffset += 3; // Package.fixedSize + } + } + // Skip access flags + readOffset += 2; + + // Read the classname, use exception handlers to catch bad format + int constantPoolIndex = u2At(readOffset, classDefinition); + int utf8Offset = constantPoolOffsets[u2At(constantPoolOffsets[constantPoolIndex] + 1, classDefinition)]; + char[] className = utf8At(utf8Offset + 3, u2At(utf8Offset + 1, classDefinition), classDefinition); + return new String(className); + } catch (ArrayIndexOutOfBoundsException e) { + e.printStackTrace(); + return null; + } +} +/** + * Creates a new instance of the given class. It is + * assumed that it is a subclass of CodeSnippet. + */ +Object createCodeSnippet(Class snippetClass) { + Object object = null; + try { + object = snippetClass.getDeclaredConstructor().newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + this.ide.sendResult(void.class, null); + return null; + } catch (IllegalAccessException e) { + e.printStackTrace(); + this.ide.sendResult(void.class, null); + return null; + } catch (IllegalArgumentException e) { + e.printStackTrace(); + this.ide.sendResult(void.class, null); + return null; + } catch (InvocationTargetException e) { + e.printStackTrace(); + this.ide.sendResult(void.class, null); + return null; + } catch (NoSuchMethodException e) { + e.printStackTrace(); + this.ide.sendResult(void.class, null); + return null; + } catch (SecurityException e) { + e.printStackTrace(); + this.ide.sendResult(void.class, null); + return null; + } + return object; +} +/** + * Whether this code snippet runner is currently running. + */ +public boolean isRunning() { + return this.ide.isConnected(); +} +/** + * Starts a new CodeSnippetRunner that will serve code snippets from the IDE. + * It waits for a connection on the given evaluation port number. + *

    + * Usage: java org.eclipse.jdt.tests.eval.target.CodeSnippetRunner -evalport [-options] [] [] + * where options include: + * -cscp the the classpath directory for the code snippet classes. + * that are not defined in a "java.*" package. + * -csbp the bootclasspath directory for the code snippet classes + * that are defined in a "java.*" package. + *

    + * The mainClassName and its arguments are optional: when not present only the server will start + * and run until the VM is shut down, when present the server will start, the main class will run + * but the server will exit when the main class has finished running. + */ +public static void main(String[] args) { + int length = args.length; + if (length < 2 || !args[0].toLowerCase().equals("-evalport")) { + printUsage(); + return; + } + int evalPort = Integer.parseInt(args[1]); + String classPath = null; + String bootPath = null; + int mainClass = -1; + for (int i = 2; i < length; i++) { + String arg = args[i]; + if (arg.startsWith("-")) { + if (arg.toLowerCase().equals("-cscp")) { + if (++i < length) { + classPath = args[i]; + } else { + printUsage(); + return; + } + } else if (arg.toLowerCase().equals("-csbp")) { + if (++i < length) { + bootPath = args[i]; + } else { + printUsage(); + return; + } + } + } else { + mainClass = i; + break; + } + } + theRunner = new CodeSnippetRunner(evalPort, classPath, bootPath); + if (mainClass == -1) { + theRunner.start(); + } else { + Thread server = new Thread() { + @Override + public void run() { + theRunner.start(); + } + }; + server.setDaemon(true); + server.start(); + int mainArgsLength = length-mainClass-1; + String[] mainArgs = new String[mainArgsLength]; + System.arraycopy(args, mainClass+1, mainArgs, 0, mainArgsLength); + try { + Class clazz = Class.forName(args[mainClass]); + Method mainMethod = clazz.getMethod("main", new Class[] {String[].class}); + mainMethod.invoke(null, (Object[]) mainArgs); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } +} +private static void printUsage() { + System.out.println("Usage: java org.eclipse.jdt.tests.eval.target.CodeSnippetRunner -evalport [-options] [] []"); + System.out.println("where options include:"); + System.out.println("-cscp the the classpath directory for the code snippet classes."); + System.out.println("that are not defined in a \"java.*\" package."); + System.out.println("-csbp the bootclasspath directory for the code snippet classes"); + System.out.println("that are defined in a \"java.*\" package."); +} +/** + * Loads the given class definitions. The way these class definitions are loaded is described + * in the CodeSnippetRunner constructor. + * The class definitions are code snippet classes and/or global variable classes. + * Code snippet classes are assumed be direct or indirect subclasses of CodeSnippet and implement + * only the run()V method. + * They are instanciated and run. + * Global variable classes are assumed to be direct subclasses of CodeSnippet. Their fields are assumed + * to be static. The value of each field is sent back to the IDE. + */ +void processClasses(boolean mustRun, byte[][] classDefinitions) { + // store the class definitions (either in the code snippet class loader or on disk) + String[] newClasses = new String[classDefinitions.length]; + for (int i = 0; i < classDefinitions.length; i++) { + byte[] classDefinition = classDefinitions[i]; + String classFileName = className(classDefinition); + String className = classFileName.replace('/', '.'); + if (this.loader != null) { + this.loader.storeClassDefinition(className, classDefinition); + } else { + writeClassOnDisk(classFileName, classDefinition); + } + newClasses[i] = className; + } + + // load the classes and collect code snippet classes + List codeSnippetClasses = new ArrayList<>(); + for (int i = 0; i < newClasses.length; i++) { + String className = newClasses[i]; + Class clazz = null; + if (this.loader != null) { + clazz = this.loader.loadIfNeeded(className); + if (clazz == null) { + System.err.println("Could not find class definition for " + className); + break; + } + } else { + // use the system class loader + try { + clazz = Class.forName(className); + } catch (ClassNotFoundException e) { + e.printStackTrace(); // should never happen since we just wrote it on disk + this.ide.sendResult(void.class, null); + break; + } + } + + Class superclass = clazz.getSuperclass(); + Method[] methods = clazz.getDeclaredMethods(); + if (this.codeSnippetClass == null) { + if (superclass.equals(Object.class) && clazz.getName().equals(CODE_SNIPPET_CLASS_NAME)) { + // The CodeSnippet class is being deployed + this.codeSnippetClass = clazz; + } else { + System.out.println("Expecting CodeSnippet class to be deployed first"); + } + } else if (superclass.equals(this.codeSnippetClass)) { + // It may be a code snippet class with no global variable + if (methods.length == 1 && methods[0].getName().equals(RUN_METHOD_NAME)) { + codeSnippetClasses.add(clazz); + } + // Evaluate global variables and send result back + Field[] fields = clazz.getDeclaredFields(); + for (int j = 0; j < fields.length; j++) { + Field field = fields[j]; + if (Modifier.isPublic(field.getModifiers())) { + try { + this.ide.sendResult(field.getType(), field.get(null)); + } catch (IllegalAccessException e) { + e.printStackTrace(); // Cannot happen because the field is public + this.ide.sendResult(void.class, null); + break; + } + } + } + } else if (this.codeSnippetClass.equals(superclass.getSuperclass()) && methods.length == 1 && methods[0].getName().equals("run")) { + // It is a code snippet class with a global variable superclass + codeSnippetClasses.add(clazz); + } + } + + // run the code snippet classes + if (codeSnippetClasses.size() != 0 && mustRun) { + for (Class class1 : codeSnippetClasses) { + Object codeSnippet = createCodeSnippet(class1); + if (codeSnippet != null) { + runCodeSnippet(codeSnippet); + } + } + } +} +/** + * Runs the given code snippet in a new thread and send the result back to the IDE. + */ +void runCodeSnippet(final Object snippet) { + Thread thread = new Thread() { + @Override + public void run() { + try { + try { + Method runMethod = CodeSnippetRunner.this.codeSnippetClass.getMethod(RUN_METHOD_NAME, new Class[] {}); + runMethod.invoke(snippet, new Object[] {}); + } finally { + Method getResultTypeMethod = CodeSnippetRunner.this.codeSnippetClass.getMethod(GET_RESULT_TYPE_METHOD_NAME, new Class[] {}); + Class resultType = (Class)getResultTypeMethod.invoke(snippet, new Object[] {}); + Method getResultValueMethod = CodeSnippetRunner.this.codeSnippetClass.getMethod(GET_RESULT_VALUE_METHOD_NAME, new Class[] {}); + Object resultValue = getResultValueMethod.invoke(snippet, new Object[] {}); + CodeSnippetRunner.this.ide.sendResult(resultType, resultValue); + } + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + System.out.println("codeSnippetClass = " + CodeSnippetRunner.this.codeSnippetClass.getName()); + System.out.println("snippet.class = " + snippet.getClass().getName()); + Class superclass = snippet.getClass().getSuperclass(); + System.out.println("snippet.superclass = " + (superclass == null ? "null" : superclass.getName())); + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.getTargetException().printStackTrace(); + } + } + }; + thread.setDaemon(true); + thread.start(); +} +/** + * Starts this code snippet runner in a different thread. + */ +public void start() { + Thread thread = new Thread("Code snippet runner") { + @Override + public void run() { + try { + CodeSnippetRunner.this.ide.connect(); + } catch (IOException e) { + e.printStackTrace(); + } + while (CodeSnippetRunner.this.ide.isConnected()) { + try { + processClasses(CodeSnippetRunner.this.ide.getRunFlag(), CodeSnippetRunner.this.ide.getNextClasses()); + } catch (Error e) { + CodeSnippetRunner.this.ide.sendResult(void.class, null); + e.printStackTrace(); + } catch (RuntimeException e) { + CodeSnippetRunner.this.ide.sendResult(void.class, null); + e.printStackTrace(); + } + } + } + }; + thread.start(); +} +/** + * Stops this code snippet runner. + */ +public void stop() { + this.ide.disconnect(); +} +private int u1At(int position, byte[] bytes) { + return bytes[position] & 0xFF; +} +private int u2At(int position, byte[] bytes) { + return ((bytes[position++] & 0xFF) << 8) + (bytes[position] & 0xFF); +} +private char[] utf8At(int readOffset, int bytesAvailable, byte[] bytes) { + int x, y, z; + int length = bytesAvailable; + char outputBuf[] = new char[bytesAvailable]; + int outputPos = 0; + while (length != 0) { + x = bytes[readOffset++] & 0xFF; + length--; + if ((0x80 & x) != 0) { + y = bytes[readOffset++] & 0xFF; + length--; + if ((x & 0x20) != 0) { + z = bytes[readOffset++] & 0xFF; + length--; + x = ((x & 0x1F) << 12) + ((y & 0x3F) << 6) + (z & 0x3F); + } else { + x = ((x & 0x1F) << 6) + (y & 0x3F); + } + } + outputBuf[outputPos++] = (char) x; + } + + if (outputPos != bytesAvailable) { + System.arraycopy(outputBuf, 0, (outputBuf = new char[outputPos]), 0, outputPos); + } + return outputBuf; +} +/** + * Writes the given class definition on disk. The give name is the forward slash separated + * fully qualified name of the class. + */ +private void writeClassOnDisk(String className, byte[] classDefinition) { + try { + String fileName = className.replace('/', File.separatorChar) + ".class"; + File classFile = new File( + (this.bootclassPathDirectory != null && + (className.startsWith("java") || className.replace('/', '.').equals(CODE_SNIPPET_CLASS_NAME))) ? + this.bootclassPathDirectory : + this.classPathDirectory, fileName); + File parent = new File(classFile.getParent()); + parent.mkdirs(); + if (!parent.exists()) { + throw new IOException("Could not create directory " + parent.getPath()); + } + FileOutputStream out = null; + try { + out = new FileOutputStream(classFile); + out.write(classDefinition); + } finally { + if (out != null) { + out.close(); + } + } + } catch (IOException e) { + e.printStackTrace(); + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/IDEInterface.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/IDEInterface.java new file mode 100644 index 0000000000..f4be47dc0e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/target/IDEInterface.java @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.eval.target; + +import java.io.*; +import java.net.*; +/** + * The interface to the IDE. When connected, it uses TCP/IP sockets + * to get code snippet classes and global variable classes from the IDE. + * It sends the result of the evaluation back using the same socket. + *

    + * The format from the socket input stream is the following: + *

    + *		[run flag: boolean coded on 1 byte]
    + * 		[number of class files: int coded on 4 bytes]
    + *		*[
    + *			[length of class file: int coded on 4 bytes]
    + *      	[class file: Java Class file format]
    + *       ]
    + * 
    + * This sequence is infinitely repeated until the input socket stream is closed. + *

    + * The format from the socket output stream is the following: + *

    + * 		[has result flag: 1 if there is a result, 0 otherwise]
    + * 		if there is a result:
    + *		[fully qualified type name of result: utf8 encoded string]
    + *      [toString representation of result: utf8 encoded string]
    + * 
    + * This sequence is infinitely repeated until the output socket stream is closed. + */ +@SuppressWarnings({ "rawtypes" }) +public class IDEInterface { + /** + * Whether timing info should be printed to stdout + */ + static final boolean TIMING = false; + long startTime; + + int portNumber = 0; + Socket socket; +/** + * Creates a new IDEInterface. + */ +IDEInterface(int portNumber) { + this.portNumber = portNumber; +} +/** + * Waits for a connection from the ide on the given port. + * @throws IOException if the connection could not be established. + */ +void connect() throws IOException { + this.socket = new Socket("localhost", this.portNumber); + this.socket.setTcpNoDelay(true); +} +/** + * Disconnects this interface from the IDE. + */ +void disconnect() { + if (this.socket != null) { + try { + this.socket.close(); + } catch (IOException e2) { + // Ignore + } + this.socket = null; + } +} +/** + * Returns the class definitions of the classes that compose the next code snippet to evaluate. + */ +protected byte[][] getNextClasses() { + if (this.socket == null) { + return new byte[0][]; + } + if (TIMING) { + this.startTime = System.currentTimeMillis(); + } + try { + DataInputStream in = new DataInputStream(this.socket.getInputStream()); + int numberOfClasses = in.readInt(); + byte[][] result = new byte[numberOfClasses][]; + for (int i = 0; i < numberOfClasses; i++) { + int lengthOfClassFile = in.readInt(); + byte[] classFile = new byte[lengthOfClassFile]; + int read = 0; + while (read < lengthOfClassFile && read != -1) { + read += in.read(classFile, read, lengthOfClassFile - read); + } + result[i] = classFile; + } + return result; + } catch (IOException e) { + // The socket has likely been closed on the other end, close this end too. + disconnect(); + return new byte[0][]; + } +} +/** + * Returns whether the code snippet classes that follow should be run or just loaded. + */ +protected boolean getRunFlag() { + if (this.socket == null) { + return false; + } + if (TIMING) { + this.startTime = System.currentTimeMillis(); + } + try { + DataInputStream in = new DataInputStream(this.socket.getInputStream()); + return in.readBoolean(); + } catch (IOException e) { + // The socket has likely been closed on the other end, close this end too. + disconnect(); + return false; + } +} +/** + * Returns whether this interface is connected to the IDE. + */ +boolean isConnected() { + return this.socket != null; +} +/** + * Sends the result of the evaluation to the IDE. + */ +protected void sendResult(Class resultType, Object resultValue) { + if (this.socket == null) { + return; + } + try { + DataOutputStream out = new DataOutputStream(this.socket.getOutputStream()); + if (resultType == void.class) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); + out.writeUTF(resultType.isPrimitive() ? resultType.toString() : resultType.getName()); + out.writeUTF(resultValue == null ? "null" : resultValue.toString()); + } + } catch (IOException e) { + // The socket has likely been closed on the other end, disconnect this end too + disconnect(); + } + if (TIMING) { + System.out.println("Time to run on target is " + (System.currentTimeMillis() - this.startTime) + "ms"); + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/PerformanceTestSuite.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/PerformanceTestSuite.java new file mode 100644 index 0000000000..f25cbb7b49 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/PerformanceTestSuite.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2004, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.junit.extension; + +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +@SuppressWarnings({ "rawtypes" }) +public class PerformanceTestSuite extends TestSuite { + + /** + * Constructs a TestSuite from the given class. Adds all the methods + * starting with "testPerf" as test cases to the suite. + */ + public PerformanceTestSuite(final Class theClass) { + setName(theClass.getName()); + try { + getTestConstructor(theClass); // Avoid generating multiple error messages + } catch (NoSuchMethodException e) { + addTest(addWarningTest("Class "+theClass.getName()+" has no public constructor TestCase(String name) or TestCase()")); + return; + } + + if (!Modifier.isPublic(theClass.getModifiers())) { + addTest(addWarningTest("Class "+theClass.getName()+" is not public")); + return; + } + + Class superClass= theClass; + List names= new ArrayList<>(); + while (Test.class.isAssignableFrom(superClass)) { + Method[] methods= superClass.getDeclaredMethods(); + for (int i= 0; i < methods.length; i++) { + addTestMethod(methods[i], names, theClass); + } + superClass= superClass.getSuperclass(); + } + if (countTestCases() == 0) + addTest(addWarningTest("No tests found in "+theClass.getName())); + } + + public PerformanceTestSuite(String name) { + setName(name); + } + + private void addTestMethod(Method m, List names, Class theClass) { + String name= m.getName(); + if (names.contains(name)) + return; + if (! isPublicTestMethod(m)) { + if (isTestMethod(m)) + addTest(addWarningTest("Test method isn't public: "+m.getName())); + return; + } + names.add(name); + addTest(createTest(theClass, name)); + } + + public void addTestSuite(Class theClass) { + addTest(new PerformanceTestSuite(theClass)); + } + + private boolean isPublicTestMethod(Method m) { + return isTestMethod(m) && Modifier.isPublic(m.getModifiers()); + } + + private boolean isTestMethod(Method m) { + String name= m.getName(); + Class[] parameters= m.getParameterTypes(); + Class returnType= m.getReturnType(); + return parameters.length == 0 && name.startsWith("testPerf") && returnType.equals(Void.TYPE); + } + + /** + * Returns a test which will fail and log a warning message. + */ + private static Test addWarningTest(final String message) { + return new TestCase("warning") { + protected void runTest() { + fail(message); + } + }; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/StopableTestCase.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/StopableTestCase.java new file mode 100644 index 0000000000..ff7eeab758 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/StopableTestCase.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.junit.extension; + +/** + * A test case that is being sent stop() when the user presses 'Stop' or 'Exit'. + */ +public interface StopableTestCase { + /** + * Invoked when this test needs to be stoped. + */ + public void stop(); +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java new file mode 100644 index 0000000000..a0f7ee5cd5 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java @@ -0,0 +1,991 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Jesper S Moller - Contributions for + * bug 527554 - [18.3] Compiler support for JEP 286 Local-Variable Type + *******************************************************************************/ +package org.eclipse.jdt.core.tests.junit.extension; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.text.DateFormat; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.StringTokenizer; + +import org.eclipse.jdt.core.Flags; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.batch.Main; +import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.test.OrderedTestSuite; +import org.eclipse.test.internal.performance.PerformanceMeterFactory; +import org.eclipse.test.performance.Performance; +import org.eclipse.test.performance.PerformanceTestCase; + +import junit.framework.AssertionFailedError; +import junit.framework.ComparisonFailure; +import junit.framework.Test; +import junit.framework.TestSuite; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class TestCase extends PerformanceTestCase { + + // Filters + public static final String METHOD_PREFIX = "test"; + public static String RUN_ONLY_ID = "ONLY_"; + + // Ordering + public static final int NO_ORDER = 0; + public static final int ALPHABETICAL_SORT = 1; + public static final int ALPHA_REVERSE_SORT = 2; + public static final int RANDOM_ORDER_JDT = 3; + public static final int RANDOM_ORDER_TIME = 4; + public static final int BYTECODE_DECLARATION_ORDER = 5; + + /** + * Expected tests order while building tests list for test suites. + * @see #buildTestsList(Class, int, long) + *
    + * User may use following different values: + *
      + *
    • {@link #NO_ORDER}: none (this is the default)
    • + *
    • {@link #ALPHABETICAL_SORT}: alphabetical order (i.e. ascending)
    • + *
    • {@link #ALPHA_REVERSE_SORT}: alpha reverse order (i.e. descending)
    • + *
    • {@link #RANDOM_ORDER_JDT}: random order using JDT/Core current version as seed
    • + *
    • {@link #RANDOM_ORDER_TIME}: random order using current time as seed (used time value is displayed in console)
    • + *
    • {@link #BYTECODE_DECLARATION_ORDER}: bytecode declaration order (same as source declaration order if compiled with ECJ)
    • + *
    • other values: random order using given long value as seed
    • + *
    + * This value is initialized with "ordering" system property. + */ + public static final long ORDERING; + static { + long ordering = ALPHABETICAL_SORT; // default is alphabetical order + try { + long seed = Long.parseLong(System.getProperty("ordering", "0")); + try { + int kind = Integer.parseInt(System.getProperty("ordering", "0")); + switch (kind) { + case NO_ORDER: + break; + case ALPHABETICAL_SORT: + ordering = kind; + System.err.println("Note that tests will be run sorted using alphabetical order..."); + break; + case ALPHA_REVERSE_SORT: + ordering = kind; + System.err.println("Note that tests will be run sorted using alphabetical reverse order..."); + break; + case RANDOM_ORDER_JDT: + String version = new Main(null/*outWriter*/, null/*errWriter*/, false/*systemExit*/, null/*options*/, null/*progress*/).bind("compiler.version"); + version = version.substring(0, version.indexOf(',')); + try { + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=384531 + // compiler.version is a timestamp since the the above fix (of the format: v20120725-181921) + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < version.length(); i++) { + if (Character.isDigit(version.charAt(i))) { + buffer.append(version.charAt(i)); + } + } + ordering = Long.parseLong(buffer.toString()); + System.err.println("Note that tests will be run in random order using seed="+ordering+" (ie. JDT/Core version)"); + } + catch (NumberFormatException nfe) { + System.err.println("Cannot extract valid JDT/Core version number from 'compiler.version': "+version+" => no order will be finally used..."); + ordering = NO_ORDER; + } + break; + case RANDOM_ORDER_TIME: + ordering = System.currentTimeMillis(); + System.err.println("Note that tests will be run in random order using seed="+ordering+" (ie. current time)"); + break; + case BYTECODE_DECLARATION_ORDER: + ordering = kind; + System.err.println("Note that tests will be run in bytecode declaration order..."); + break; + default: + ordering = seed; + System.err.println("Note that tests will be run in random order using seed="+seed+" (ie. given value)"); + break; + } + } catch (NumberFormatException nfe) { + // ordering value is over int range but is a valid long => keep the value + ordering = seed; + System.err.println("Note that tests will be run in random order using seed="+seed+" (ie. given value)"); + } + } + catch (NumberFormatException nfe) { + System.err.println("Only integer or long values are allowed for 'ordering' system property: "+System.getProperty("ordering", "0")+" is not valid ! => no order will be finally used..."); + ordering = NO_ORDER; + } + ORDERING = ordering; + } + + // Garbage collect constants + final static int MAX_GC = 5; // Max gc iterations + final static int TIME_GC = 200; // Sleep to wait gc to run (in ms) + final static int DELTA_GC = 1000; // Threshold to remaining free memory + + // Debug Log Information + public final static File MEM_LOG_FILE; + public final static File MEM_LOG_DIR; + public static Class CURRENT_CLASS; + public static String CURRENT_CLASS_NAME; + public final static String STORE_MEMORY; + public final static boolean ALL_TESTS_LOG; + public final static boolean RUN_GC; + private static final NumberFormat DIGIT_FORMAT = NumberFormat.getNumberInstance(); + + /* + * Static initializer for memory trace. + * This functionality is activated using system property "storeMemory". + * Here's possible format for this property: + * -DstoreMemory=[,all][,gc][,dir=] + * : name of the file where memory data will be stored + * optional parameters: + * all: flag to store memory data for all tests. If not specified, + * then data will be stored only per test suite + * gc: flag to run garbage collection before each test or test suite + * (depending of "all" parameter) + * dir=: + * specify directory where to put the file. Default is the directory + * specified in 'user.home' property + * Example: + * -DstoreMemory=RunAllJDTCoreTests,d:/tmp + */ + static { + String storeMemory = System.getProperty("storeMemory"); + boolean allTestsLog = false; + boolean runGc = false; + File memLogDir = new File(System.getProperty("user.home")); + if (storeMemory != null) { + int index = storeMemory.indexOf(','); + if (index>0) { + StringTokenizer parameters = new StringTokenizer(storeMemory.substring(storeMemory.indexOf(',')+1), ","); + while (parameters.hasMoreTokens()) { + String param = parameters.nextToken(); + if ("all".equals(param)) { + allTestsLog = true; + } else if ("gc".equals(param)) { + runGc = true; + } else if (param.startsWith("dir=")) { + memLogDir = new File(param.substring(4)); + } + } + storeMemory = storeMemory.substring(0, index); + } + } + STORE_MEMORY = storeMemory; + ALL_TESTS_LOG = allTestsLog; + RUN_GC = runGc; + if (!verifyLogDir(memLogDir)) { + memLogDir = null; + } + MEM_LOG_DIR = memLogDir; + MEM_LOG_FILE = createMemLogFile(); + if (STORE_MEMORY != null && MEM_LOG_FILE != null) { + System.out.println("Memory storage activated:"); + System.out.println(" data stored in file "+MEM_LOG_FILE); + System.out.println(" all tests log: "+ALL_TESTS_LOG); + System.out.println(" gc activated: "+RUN_GC); + } + DIGIT_FORMAT.setMinimumIntegerDigits(3); + } + /* + * Flag telling if current test is the first of TestSuite it belongs or not. + */ + private boolean first; + + /** + * Flag telling whether test execution must stop on failure or not. + * Default is true; + */ + protected boolean abortOnFailure = true; + + // static variables for subsets tests + public static String TESTS_PREFIX = null; // prefix of test names to perform + public static String[] TESTS_NAMES = null; // list of test names to perform + public static int[] TESTS_NUMBERS = null; // list of test numbers to perform + public static int[] TESTS_RANGE = null; // range of test numbers to perform + + public TestCase(String name) { + setName(name); + } + +public static void assertEquals(String expected, String actual) { + assertEquals(null, expected, actual); +} +public static void assertEquals(String message, String expected, String actual) { + assertStringEquals(message, expected, actual, true); +} +public static void assertStringEquals(String expected, String actual, boolean showLineSeparators) { + assertStringEquals(null, expected, actual, showLineSeparators); +} +public static void assertStringEquals(String message, String expected, String actual, boolean showLineSeparators) { + if (expected == null && actual == null) + return; + if (expected != null && actual.matches("\\Q" + expected.replace("##", "\\E.*\\Q") + "\\E")) + return; + final StringBuffer formatted; + if (message != null) { + formatted = new StringBuffer(message).append('.'); + } else { + formatted = new StringBuffer(); + } + if (showLineSeparators) { + final String expectedWithLineSeparators = showLineSeparators(expected); + final String actualWithLineSeparators = showLineSeparators(actual); + formatted.append("\n----------- Expected ------------\n"); //$NON-NLS-1$ + formatted.append(expectedWithLineSeparators); + formatted.append("\n------------ but was ------------\n"); //$NON-NLS-1$ + formatted.append(actualWithLineSeparators); + formatted.append("\n--------- Difference is ----------\n"); //$NON-NLS-1$ + throw new ComparisonFailure(formatted.toString(), + expectedWithLineSeparators, + actualWithLineSeparators); + } else { + formatted.append("\n----------- Expected ------------\n"); //$NON-NLS-1$ + formatted.append(expected); + formatted.append("\n------------ but was ------------\n"); //$NON-NLS-1$ + formatted.append(actual); + formatted.append("\n--------- Difference is ----------\n"); //$NON-NLS-1$ + throw new ComparisonFailure(formatted.toString(), expected, actual); + } +} +/** + * Same method as {@link #assertEquals(Object, Object)} if the flag + * {@link #abortOnFailure} has been set to true. + * Otherwise, the thrown exception {@link AssertionFailedError} is caught + * and its message is only displayed in the console hence producing no JUnit failure. + */ +protected void assumeEquals(String expected, String actual) { + assumeEquals(null, expected, actual); +} +/** + * Same method as {@link #assertEquals(String, Object, Object)} if the flag + * {@link #abortOnFailure} has been set to true. + * Otherwise, the thrown exception {@link AssertionFailedError} is caught + * and its message is only displayed in the console hence producing no JUnit failure. + */ +protected void assumeEquals(String msg, String expected, String actual) { + try { + assertStringEquals(msg, expected, actual, false); + } catch (ComparisonFailure cf) { + System.out.println("Failure while running test "+Performance.getDefault().getDefaultScenarioId(this)+"!!!"); + System.out.println("Actual output is:"); + System.out.println(Util.displayString(cf.getActual(), 2)); + System.out.println(); + System.out.println("Expected output is:"); + System.out.println(Util.displayString(cf.getExpected(), 2)); + System.out.println(); + if (this.abortOnFailure) { + throw cf; + } + } catch (AssertionFailedError afe) { + if (this.abortOnFailure) { + throw afe; + } + printAssertionFailure(afe); + } +} + +/** + * Same method as {@link #assertEquals(String, int, int)} if the flag + * {@link #abortOnFailure} has been set to true. + * Otherwise, the thrown exception {@link AssertionFailedError} is caught + * and its message is only displayed in the console hence producing no JUnit failure. + */ +protected void assumeEquals(String msg, int expected, int actual) { + try { + assertEquals(msg, expected, actual); + } catch (AssertionFailedError afe) { + if (this.abortOnFailure) { + throw afe; + } + printAssertionFailure(afe); + } +} + +/** + * Same method as {@link #assertEquals(String, long, long)} if the flag + * {@link #abortOnFailure} has been set to true. + * Otherwise, the thrown exception {@link AssertionFailedError} is caught + * and its message is only displayed in the console hence producing no JUnit failure. + */ +protected void assumeEquals(String msg, long expected, long actual) { + try { + assertEquals(msg, expected, actual); + } catch (AssertionFailedError afe) { + if (this.abortOnFailure) { + throw afe; + } + printAssertionFailure(afe); + } +} + +/** + * Same method as {@link #assertTrue(String, boolean)} if the flag + * {@link #abortOnFailure} has been set to true. + * Otherwise, the thrown exception {@link AssertionFailedError} is caught + * and its message is only displayed in the console hence producing no JUnit failure. + */ +protected void assumeTrue(String msg, boolean cond) { + try { + assertTrue(msg, cond); + } catch (AssertionFailedError afe) { + if (this.abortOnFailure) { + throw afe; + } + printAssertionFailure(afe); + } +} + +private void printAssertionFailure(AssertionFailedError afe) { + System.out.println("\n!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!!---!"); + System.out.println("Caught assertion failure while running test "+getName()+":"); + System.out.println(" "+afe.getMessage()); + System.out.println("--------------------------------------------------------------------------------\n"); +} + +/** + * Build a list of methods to run for a test suite. + * There's no recursion in given class hierarchy, methods are only + * public method starting with "test" of it. + *

    + * Note that this list may be reduced using 2 different mechanism: + *

    + * 1) TESTS* static variables: + *
      + *
    • {@link #TESTS_PREFIX}: only methods starting with this prefix (after "test" of course) + * will be put in test suite. + *
    • + *
    • {@link #TESTS_NAMES}: only methods with these names will be put in test suite. + *
    • + *
    • {@link #TESTS_NUMBERS}: only methods including these numbers will be put in test suite.
      + * For example, TESTS_NUMBERS = new int[] { 10, 100, 125678 }; will put + * test010(), test100() and testBug125678() + * methods in test suite. + *
    • + *
    • {@link #TESTS_RANGE}: only methods which numbers are between first and second value + * of this int array will be put in the suite. + * For example: TESTS_RANGE = new int[] { 10, 12 }; will put + * test010(), test011() and test012() + * methods in test suite.
      + * Note that -1 will clean min or max value, for example TESTS_RANGE = new int[] { 10, -1 }; + * will put all methods after test010() in the test suite. + *
    • + *
    + *

    + * 2) testONLY_ methods
    + * As static variables needs a static initializer usually put at the beginning of the test suite, + * it could be a little be boring while adding tests at the end of the file to modify this static initializer. + * One solution to avoid this was to introduced specific methods name which will be only executed + * when test suite is run alone. + * For example: + *
    + * 	public class MyTest extends TestCase {
    + * 		public MyTest(String name) {
    + * 			super(name);
    + * 		}
    + * 		public test001() {
    + * 			...
    + * 		}
    + * 		public test002() {
    + * 			...
    + * 		}
    + * 		...
    + * 		public testONLY_100() {
    + * 			...
    + * 		}
    + * 	}
    + * 
    + * This test suite will have only test "testONLY_100" put in test suite while running it. + * + * Note that these 2 mechanisms should be reset while executing "global" test suites. + * For example: + *
    + * 	public class TestAll extends junit.framework.TestCase {
    + * 		public TestAll(String testName) {
    + * 			super(testName);
    + * 		}
    + * 		public static Test suite() {
    + * 			TestCase.TESTS_PREFIX = null;
    + * 			TestCase.TESTS_NAMES = null;
    + * 			TestCase.TESTS_NUMBERS= null;
    + * 			TestCase.TESTS_RANGE = null;
    + * 			TestCase.RUN_ONLY_ID = null;
    + * 			return buildTestSuite(MyTest.class);
    + * 		}
    + * 	}
    + * 
    + * This will insure you that all tests will be put in TestAll test suite, even if static variables + * values are set or some methods start as testONLY_... + * + * @param evaluationTestClass the test suite class + * @return a list ({@link List}) of tests ({@link Test}). + */ +public static List buildTestsList(Class evaluationTestClass) { + return buildTestsList(evaluationTestClass, 0/*only one level*/, ORDERING); +} + +/** + * Build a list of methods to run for a test suite. + *
    + * Differ from {@link #buildTestsList(Class)} in the fact that one + * can specify level of recursion in hierarchy to find additional tests. + * + * @param evaluationTestClass the test suite class + * @param inheritedDepth level of recursion in top-level hierarchy to find other tests + * @return a {@link List list} of {@link Test tests}. + */ +public static List buildTestsList(Class evaluationTestClass, int inheritedDepth) { + return buildTestsList(evaluationTestClass, inheritedDepth, ORDERING); +} + +/** + * Build a list of methods to run for a test suite. + *
    + * This list may be ordered in different ways using {@link #ORDERING}. + *
    + * Example + *
    + * 	public class AbstractTest extends TestCase {
    + * 		public MyTest(String name) {
    + * 			super(name);
    + * 		}
    + * 		public testOne() {
    + * 			...
    + * 		}
    + * 		public testTwo() {
    + * 			...
    + * 		}
    + * 	}
    + * 	public class MyTest extends AbstractTest {
    + * 		public MyTest(String name) {
    + * 			super(name);
    + * 		}
    + * 		public test001() {
    + * 			...
    + * 		}
    + * 		public test002() {
    + * 			...
    + * 		}
    + * 		...
    + * 		public testONLY_100() {
    + * 			...
    + * 		}
    + * 	}
    + * 
    + * Returned list will have 5 tests if inheritedDepth is equals to 1 instead of + * 3 if it was 0 as while calling by {@link #buildTestsList(Class)}. + * + * @see #buildTestsList(Class) for complete explanation of subsets mechanisms. + * + * @param evaluationTestClass the test suite class + * @param inheritedDepth level of recursion in top-level hierarchy to find other tests + * @param ordering kind of sort use for the list (see {@link #ORDERING} for possible values) + * @return a {@link List list } of {@link Test tests} + */ +public static List buildTestsList(Class evaluationTestClass, int inheritedDepth, long ordering) { + List tests = new ArrayList(); + List testNames = new ArrayList(); + List onlyNames = new ArrayList(); + Constructor constructor = null; + try { + // Get class constructor + Class[] paramTypes = new Class[] { String.class }; + constructor = evaluationTestClass.getConstructor(paramTypes); + } + catch (Exception e) { + // cannot get constructor, skip suite + return tests; + } + + // Get all tests from "test%" methods + Method[] methods = evaluationTestClass.getDeclaredMethods(); + Class evaluationTestSuperclass = evaluationTestClass.getSuperclass(); + for (int i=0; i add method + if (TESTS_PREFIX == null && TESTS_NAMES == null && TESTS_NUMBERS == null && TESTS_RANGE == null) { + if (!testNames.contains(methName)) { + testNames.add(methName); + } + continue nextMethod; + } + + // no prefix or method matches prefix + if (TESTS_PREFIX == null || methName.startsWith(TESTS_PREFIX)) { + int numStart = TESTS_PREFIX==null ? methodPrefixLength : TESTS_PREFIX.length(); + // tests names subset + if (TESTS_NAMES != null) { + for (int i = 0, imax= TESTS_NAMES.length; i= 0) { + if (!testNames.contains(methName)) { + testNames.add(methName); + } + continue nextMethod; + } + } + } + // look for test number + int length = methName.length(); + if (numStart < length) { + // get test number + while (numStartnumStart && n <= length) { + try { + int num = Integer.parseInt(methName.substring(numStart, n)); + // tests numbers subset + if (TESTS_NUMBERS != null && !testNames.contains(methName)) { + for (int i = 0; i < TESTS_NUMBERS.length; i++) { + if (TESTS_NUMBERS[i] == num) { + testNames.add(methName); + continue nextMethod; + } + } + } + // tests range subset + if (TESTS_RANGE != null && TESTS_RANGE.length == 2 && !testNames.contains(methName)) { + if ((TESTS_RANGE[0]==-1 || num>=TESTS_RANGE[0]) && (TESTS_RANGE[1]==-1 || num<=TESTS_RANGE[1])) { + testNames.add(methName); + continue nextMethod; + } + } + } catch (NumberFormatException e) { + System.out.println("Method "+methods[m]+" has an invalid number format: "+e.getMessage()); + } + } + } + + // no subset, add all tests + if (TESTS_NAMES==null && TESTS_NUMBERS==null && TESTS_RANGE==null) { + if (!testNames.contains(methName)) { + testNames.add(methName); + } + } + } + } + } + } + + // Order tests + List names = onlyNames.size() > 0 ? onlyNames : testNames; + if (ordering == ALPHA_REVERSE_SORT) { + Collections.sort(names, Collections.reverseOrder()); + } else if (ordering == ALPHABETICAL_SORT) { + Collections.sort(names); + } else if (ordering == BYTECODE_DECLARATION_ORDER) { + try { + List bytecodeOrderedTestNames = OrderedTestSuite.getBytecodeOrderedTestNames(evaluationTestClass); + bytecodeOrderedTestNames.retainAll(names); + if (bytecodeOrderedTestNames.size() != names.size()) { + System.err.println("not all test names found in bytecode: " + evaluationTestClass.getName()); + } + names = bytecodeOrderedTestNames; + } catch (IOException e) { + System.err.println("suite failed to detect test order: " + evaluationTestClass.getName()); + } + } else if (ordering != NO_ORDER) { + Collections.shuffle(names, new Random(ordering)); + } + + // Add corresponding tests + Iterator iterator = names.iterator(); + while (iterator.hasNext()) { + String testName = (String) iterator.next(); + try { + tests.add(constructor.newInstance(new Object[] { testName } )); + } + catch (Exception e) { + System.err.println("Method "+testName+" removed from suite due to exception: "+e.getMessage()); + } + } + return tests; +} + +/** + * Build a test suite with all tests computed from public methods starting with "test" + * found in the given test class. + * Test suite name is the name of the given test class. + * + * Note that this lis maybe reduced using some mechanisms detailed in {@link #buildTestsList(Class)} method. + * + * @param evaluationTestClass + * @return a {@link Test test suite} + */ +public static Test buildTestSuite(Class evaluationTestClass) { + return buildTestSuite(evaluationTestClass, null); //$NON-NLS-1$ +} + +/** + * Build a test suite with all tests computed from public methods starting with "test" + * found in the given test class. + * Test suite name is the given name. + * + * Note that this lis maybe reduced using some mechanisms detailed in {@link #buildTestsList(Class)} method. + * + * @param evaluationTestClass + * @param suiteName + * @return a test suite ({@link Test}) + */ +public static Test buildTestSuite(Class evaluationTestClass, String suiteName) { + TestSuite suite = new TestSuite(suiteName==null?evaluationTestClass.getName():suiteName); + List tests = buildTestsList(evaluationTestClass); + for (int index=0, size=tests.size(); index DELTA_GC) { + // perhaps gc was not well executed + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // do nothing + } + } +} + +public void commitMeasurements() { + super.commitMeasurements(); +} + +/** + * Return whether current test is on a new {@link Test test} class or not. + * + * @return true if it's the first test of a {@link TestSuite}, + * false otherwise. + */ +protected boolean isFirst() { + return this.first; +} + +/** true by default */ +protected boolean indexDisabledForTest = true; + +/** @return true by default */ +public boolean isIndexDisabledForTest() { + return this.indexDisabledForTest; +} + +protected void setUp() throws Exception { + if (JavaCore.getPlugin() != null && isIndexDisabledForTest()) { + JavaModelManager.getIndexManager().disable(); + } + super.setUp(); + + // Store test class and its name when changing + this.first = false; + boolean isFirstTestRun = CURRENT_CLASS == null; + if (isFirstTestRun || CURRENT_CLASS != getClass()) { + if (CURRENT_CLASS != null && RUN_GC) runGarbageCollection(); + CURRENT_CLASS = getClass(); + this.first = true; + CURRENT_CLASS_NAME = getClass().getName(); + CURRENT_CLASS_NAME = CURRENT_CLASS_NAME.substring(CURRENT_CLASS_NAME.indexOf(".tests.")+7, CURRENT_CLASS_NAME.length()); + } + + // Memory storage if specified + if (STORE_MEMORY != null && MEM_LOG_FILE != null) { + if (isFirstTestRun) runGarbageCollection(); + if (ALL_TESTS_LOG && MEM_LOG_FILE.exists()) { + PrintStream stream = new PrintStream(new FileOutputStream(MEM_LOG_FILE, true)); + stream.print(CURRENT_CLASS_NAME); + stream.print('\t'); + String testName = getName(); + stream.print(testName); + stream.print('\t'); + long total = Runtime.getRuntime().totalMemory(); + long used = total - Runtime.getRuntime().freeMemory(); + stream.print(format(used)); + stream.print('\t'); + stream.print(format(total)); + stream.print('\t'); + stream.print(format(Runtime.getRuntime().maxMemory())); + stream.println(); + stream.close(); + if (isFirstTestRun) { + System.out.println(" "+format(used)); + } + } else { + if (isFirstTestRun) { + long total = Runtime.getRuntime().totalMemory(); + long used = total - Runtime.getRuntime().freeMemory(); + System.out.println(" already used while starting: "+format(used)); + } + } + } +} +private String format(long number) { + long n = number; + long q = n; + int[] values = new int[10]; + int m = -1; + while ((n=q) > 0) { + q = n / 1000L; + values[++m] = (int) (n - q*1000); + } + StringBuilder buffer = new StringBuilder(); + buffer.append(values[m]); + for (int i=m-1; i>=0; i--) { + buffer.append(',').append(DIGIT_FORMAT.format(values[i])); + } + return buffer.toString(); +} + +/** + * This method is called by the Eclipse JUnit test runner when a test is re-run from the + * JUnit view's context menu (with "Keep JUnit running after a test run when debugging") + * enabled in the launch configuration). + */ +public static Test setUpTest(Test test) throws Exception { + // reset the PerformanceMeterFactory, so that the same scenario can be run again: + Field field = PerformanceMeterFactory.class.getDeclaredField("fScenarios"); + field.setAccessible(true); + Set set = (Set) field.get(null); + set.clear(); + + return test; +} + +public void startMeasuring() { + // make it public to avoid compiler warning about synthetic access + super.startMeasuring(); +} +public void stopMeasuring() { + // make it public to avoid compiler warning about synthetic access + super.stopMeasuring(); +} + +protected void tearDown() throws Exception { + super.tearDown(); + + if (JavaCore.getPlugin() != null && isIndexDisabledForTest()) { + JavaModelManager.getIndexManager().enable(); + } + + // Memory storage if specified + if (STORE_MEMORY != null && MEM_LOG_FILE != null) { + if ((this.first || ALL_TESTS_LOG) && MEM_LOG_FILE.exists()) { + PrintStream stream = new PrintStream(new FileOutputStream(MEM_LOG_FILE, true)); + stream.print(CURRENT_CLASS_NAME); + stream.print('\t'); + if (ALL_TESTS_LOG) { + String testName = getName(); + String str = ""; + int length = testName.length()-4; + for (int i=0; i was not:<").append(actual).append(">"); + fail(String.valueOf(formatted)); +} +protected void runTest() throws Throwable { + try { + super.runTest(); + } finally { + // clear interrupt status. + Thread.interrupted(); + } +} + +public static void resetForgottenFilters(List> testClasses) { + for (Class clazz : testClasses) { + try { + Class.forName(clazz.getName(), true, clazz.getClassLoader()); // force initialization + } catch (ClassNotFoundException e) { + // "cannot happen" + } + } + // Reset forgotten subsets tests + TESTS_PREFIX = null; + TESTS_NAMES = null; + TESTS_NUMBERS= null; + TESTS_RANGE = null; + RUN_ONLY_ID = null; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestListener.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestListener.java new file mode 100644 index 0000000000..86cb4cf7eb --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestListener.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.junit.extension; + +import junit.framework.Test; +import junit.framework.TestFailure; +/** + * A Listener for test progress + */ +public interface TestListener extends junit.framework.TestListener { + /** + * An error occurred. + */ + public void addError(Test test, TestFailure testFailure); + /** + * A failure occurred. + */ + public void addFailure(Test test, TestFailure testFailure); +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestResult.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestResult.java new file mode 100644 index 0000000000..753db3a028 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestResult.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.junit.extension; + +import java.util.*; +import junit.framework.*; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class TestResult extends junit.framework.TestResult { + TestCase currentTest; +/** + * TestResult constructor comment. + */ +public TestResult() { + super(); +} + /** + * Adds an error to the list of errors. The passed in exception + * caused the error. + */ + public synchronized void addError(Test test, Throwable t) { + TestFailure testFailure= new TestFailure(test, t); + this.fErrors.add(testFailure); + for (Iterator e= cloneListeners().iterator(); e.hasNext(); ) { + ((TestListener)e.next()).addError(test, testFailure); + } + } + /** + * Adds a failure to the list of failures. The passed in exception + * caused the failure. + */ + public synchronized void addFailure(Test test, AssertionFailedError t) { + TestFailure testFailure= new TestFailure(test, t); + this.fFailures.add(testFailure); + for (Iterator e= cloneListeners().iterator(); e.hasNext(); ) { + ((TestListener)e.next()).addFailure(test, testFailure); + } + } + /** + * Returns a copy of the listeners. + */ + private synchronized List cloneListeners() { + List result = new ArrayList(); + result.addAll(this.fListeners); + return result; + } + protected void run(final TestCase test) { + this.currentTest = test; + super.run(test); + this.currentTest = null; + } +public synchronized void stop() { + super.stop(); + if (this.currentTest != null && this.currentTest instanceof StopableTestCase) { + ((StopableTestCase)this.currentTest).stop(); + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/AbstractReader.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/AbstractReader.java new file mode 100644 index 0000000000..3a2a2188a4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/AbstractReader.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +/** + * An abstract reader that continuously reads. + */ + +abstract public class AbstractReader { + protected String name; + protected Thread readerThread; + protected boolean isStopping= false; +/* + * Creates a new reader with the given name. + */ +public AbstractReader(String name) { + this.name = name; +} +/** + * Continuously reads. Note that if the read involves waiting + * it can be interrupted and a InterruptedException will be thrown. + */ +abstract protected void readerLoop(); +/** + * Start the thread that reads events. + * + */ +public void start() { + this.readerThread = new Thread( + new Runnable() { + @Override + public void run () { + readerLoop(); + } + }, + AbstractReader.this.name); + this.readerThread.start(); +} +/** + * Tells the reader loop that it should stop. + */ +public void stop() { + this.isStopping= true; + if (this.readerThread != null) + this.readerThread.interrupt(); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/DRLVMLauncher.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/DRLVMLauncher.java new file mode 100644 index 0000000000..fe722ebfa4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/DRLVMLauncher.java @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API + * Nina Rinskaya + * Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=172820. + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +/** + * This is a new vm launcher to support Apache Harmony + * (http://harmony.apache.org) settings + */ +public class DRLVMLauncher extends StandardVMLauncher { + +/** + * @see LocalVMLauncher#getCommandLine + */ +@Override +public String[] getCommandLine() { + List commandLine= new ArrayList<>(); + + // VM binary + String vmLocation = this.vmPath + + (this.vmPath.endsWith(File.separator) ? "" : File.separator) + + "bin" + + File.separator + + "javaw"; + final String osName = System.getProperty("os.name"); + if (osName.indexOf("win32") == -1 && !new File(vmLocation).exists()) { + vmLocation = vmLocation.substring(0, vmLocation.length()-1); + } + commandLine.add(vmLocation); + + // VM arguments + if (this.vmArguments != null) { + for (int i = 0; i < this.vmArguments.length; i++) { + commandLine.add(this.vmArguments[i]); + } + } + + // boot classpath + commandLine.add("-Xbootclasspath/a:" + buildBootClassPath()); + + // debug mode + if (this.debugPort != -1) { + commandLine.add("-Xdebug"); + commandLine.add("-Xnoagent"); + // commandLine.addElement("-Djava.compiler=NONE"); + commandLine.add( + "-Xrunjdwp:transport=dt_socket,address=" + + this.debugPort + + ",server=y,suspend=n"); + } + + // regular classpath + commandLine.add("-classpath"); + commandLine.add(buildClassPath()); + + // code snippet runner class + if (this.evalPort != -1) { + commandLine.add(CODE_SNIPPET_RUNNER_CLASS_NAME); + } + + // code snippet runner arguments + if (this.evalPort != -1) { + commandLine.add(EVALPORT_ARG); + commandLine.add(Integer.toString(this.evalPort)); + if (TARGET_HAS_FILE_SYSTEM) { + commandLine.add(CODESNIPPET_CLASSPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + REGULAR_CLASSPATH_DIRECTORY); + commandLine.add(CODESNIPPET_BOOTPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + BOOT_CLASSPATH_DIRECTORY); + } + } + + // program class + if (this.programClass != null) { + commandLine.add(this.programClass); + } + + // program arguments + if (this.programArguments != null) { + for (int i=0;i + * Unlike with the StandardVMLauncher, a debugger would have to + * connect to the J9 Proxy instead of connecting to the VM directly. In this case, + * the Proxy port is the specified debug port. Note that an internal debug port + * must also be specified. This port is used for the communication between the + * Proxy and the VM. + */ +public class J9VMLauncher extends LocalVMLauncher { + int internalDebugPort = -1; + String proxyOutFile; + String symbolPath; +/** + * Creates a new J9VMLauncher that launches a J9 VM + * (and J9 Proxy if needed) on the same machine. + */ +public J9VMLauncher() { + super(); +} +/** + * Builds the actual boot class path that is going to be passed to the VM. + */ +protected String buildBootClassPath() { + StringBuilder bootPathString = new StringBuilder(); + char pathSeparator = File.pathSeparatorChar; + + if (this.bootPath != null) { + // Add boot class path given by client + int length = this.bootPath.length; + for (int i = 0; i < length; i++){ + bootPathString.append(this.bootPath[i]); + bootPathString.append(pathSeparator); + } + } else { + // Add regular classes.zip + bootPathString.append(this.vmPath); + bootPathString.append(File.separator); + bootPathString.append("lib"); + bootPathString.append(File.separator); + bootPathString.append("jclMax"); + bootPathString.append(File.separator); + bootPathString.append("classes.zip"); + bootPathString.append(pathSeparator); + } + + // Add boot class path directory if needed + if (this.evalTargetPath != null && TARGET_HAS_FILE_SYSTEM) { + bootPathString.append(this.evalTargetPath); + bootPathString.append(File.separatorChar); + bootPathString.append(BOOT_CLASSPATH_DIRECTORY); + } + + return bootPathString.toString(); +} +/** + * @see LocalVMLauncher#execCommandLine + */ +@Override +protected Process execCommandLine() throws TargetException { + // Check that the internal debug port has been specified if in debug mode + if (this.debugPort != -1 && this.internalDebugPort == -1) { + throw new TargetException("Internal debug port has not been specified"); + } + + return super.execCommandLine(); +} +/** + * @see LocalVMLauncher#getCommandLine + */ +@Override +public String[] getCommandLine() { + List commandLine = new ArrayList<>(); + + // VM binary + commandLine.add( + this.vmPath + + (this.vmPath.endsWith(File.separator) ? "" : File.separator) + + "bin" + + File.separator + + "j9"); + + // VM arguments + if (this.vmArguments != null) { + for (int i = 0; i < this.vmArguments.length; i++) { + commandLine.add(this.vmArguments[i]); + } + } + + // debug mode + if (this.debugPort != -1 && this.internalDebugPort != -1) { + commandLine.add("-debug:" + this.internalDebugPort); + } + + // boot class path + commandLine.add("-Xbootclasspath:" + buildBootClassPath()); + + // regular class path + commandLine.add("-classpath"); + commandLine.add(buildClassPath()); + + // code snippet runner class + if (this.evalPort != -1) { + commandLine.add(CODE_SNIPPET_RUNNER_CLASS_NAME); + } + + // code snippet runner arguments + if (this.evalPort != -1) { + commandLine.add(EVALPORT_ARG); + commandLine.add(Integer.toString(this.evalPort)); + if (TARGET_HAS_FILE_SYSTEM) { + commandLine.add(CODESNIPPET_CLASSPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + REGULAR_CLASSPATH_DIRECTORY); + commandLine.add(CODESNIPPET_BOOTPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + BOOT_CLASSPATH_DIRECTORY); + } + } + + // program class + if (this.programClass != null) { + commandLine.add(this.programClass); + } + + // program arguments + if (this.programArguments != null) { + for (int i=0;i commandLine = new ArrayList<>(); + + // Proxy binary + commandLine.add( + this.vmPath + + (this.vmPath.endsWith(File.separator) ? "" : File.separator) + + "bin" + + File.separator + + "j9proxy"); + + // Arguments + commandLine.add(getTargetAddress() + ":" + this.internalDebugPort); + commandLine.add(Integer.toString(this.debugPort)); + if (this.symbolPath != null && this.symbolPath != "") { + commandLine.add(this.symbolPath); + } + + String[] result= new String[commandLine.size()]; + commandLine.toArray(result); + return result; +} +/** + * Returns the full path name to the file where the proxy output is redirected. + * Returns "con" if the proxy output is redirected to the stdout. + * Returns null if the proxy output is not redirected. + */ +public String getProxyOutFile() { + return this.proxyOutFile; +} +/** + * Returns the full path name to the symbol file used by the J9 Proxy. + * Returns null if the no symbol file is passed to the J9 Proxy. + */ +public String getSymbolPath() { + return this.symbolPath; +} +/** + * @see LocalVMLauncher#launch + */ +@Override +public LocalVirtualMachine launch() throws TargetException { + // Launch VM + LocalVirtualMachine localVM = super.launch(); + + // Launch Proxy if needed + Process proxyProcess= null; + if (this.debugPort != -1) { + try { + // Use Runtime.exec(String[]) with tokens because Runtime.exec(String) with commandLineString + // does not properly handle spaces in arguments on Unix/Linux platforms. + String[] commandLine = getProxyCommandLine(); + + // DEBUG + /* + for (int i = 0; i < commandLine.length; i++) { + System.out.print(commandLine[i] + " "); + } + System.out.println(); + */ + + proxyProcess= Runtime.getRuntime().exec(commandLine); + } catch (IOException e) { + localVM.shutDown(); + throw new TargetException("Error launching J9 Proxy at " + this.vmPath); + } + } + + // Transform launched VM into J9 VM + Process vmProcess = localVM.process; + this.runningVMs.remove(localVM); + J9VirtualMachine vm= new J9VirtualMachine(vmProcess, this.debugPort, this.evalTargetPath, proxyProcess, this.proxyOutFile); + this.runningVMs.add(vm); + return vm; +} +/* (non-Javadoc) + * @see org.eclipse.jdt.core.tests.runtime.LocalVMLauncher#setDebugPort(int) + */ +@Override +public void setDebugPort(int debugPort) { + super.setDebugPort(debugPort); + + // specify default internal debug port as well + setInternalDebugPort(Util.getFreePort()); +} + +/** + * Sets the debug port the J9 Proxy uses to connect to the J9 VM. + * This is mandatory if debug mode is enabled. + * This is ignored if debug mode is disabled. + * Note that the regular debug port is the port used to connect the J9 Proxy and + * the IDE in the case of the J9 VM Launcher. + */ +public void setInternalDebugPort(int internalDebugPort) { + this.internalDebugPort = internalDebugPort; +} +/** + * Sets the full path name to the file where the proxy output must be redirected. + * Specify "con" if the proxy output must be redirected to the stdout. + * Specify null if the proxy output must not be redirected (default value). + * This is ignored if debug mode is disabled. + */ +public void setProxyOutFile(String proxyOutFile) { + this.proxyOutFile = proxyOutFile; +} +/** + * Sets the full path name to the symbol file used by the J9 Proxy. + * Specify null if the no symbol file must be passed to the J9 Proxy (default value). + * This is ignored if debug mode is disabled. + */ +public void setSymbolPath(String symbolPath) { + this.symbolPath = symbolPath; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/J9VirtualMachine.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/J9VirtualMachine.java new file mode 100644 index 0000000000..2ebdd8acbe --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/J9VirtualMachine.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +/** + * Wrapper around the external processes that are running a J9 VM + * and a J9 Proxy. + * This allows to kill these processes when we exit this vm. + */ +class J9VirtualMachine extends LocalVirtualMachine { + private Process proxyProcess; + private AbstractReader proxyConsoleReader; + private String proxyOutputFile; +/** + * Creates a new J9VirtualMachine from the Processes that runs this VM + * and its J9 Proxy and with the given info. + */ +public J9VirtualMachine(Process vmProcess, int debugPort, String evalTargetPath, Process proxyProcess, String proxyOutputFile) { + super(vmProcess, debugPort, evalTargetPath); + this.proxyProcess = proxyProcess; + this.proxyOutputFile = proxyOutputFile; + + // Start the Proxy console reader so that the proxy is not blocked on its stdout. + if (this.proxyProcess != null) { + if (this.proxyOutputFile == null) { + this.proxyConsoleReader= + new NullConsoleReader( + "J9 Proxy Console Reader", + this.proxyProcess.getInputStream()); + } else { + this.proxyConsoleReader= + new ProxyConsoleReader( + "J9 Proxy Console Reader", + this.proxyProcess.getInputStream(), + this.proxyOutputFile); + } + this.proxyConsoleReader.start(); + } + +} +/** + * @see LocalVirtualMachine#shutDown + */ +@Override +public synchronized void shutDown() throws TargetException { + super.shutDown(); + if (this.proxyConsoleReader != null) + this.proxyConsoleReader.stop(); + if (this.proxyProcess != null) { + this.proxyProcess.destroy(); + this.proxyProcess = null; + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/JRockitVMLauncher.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/JRockitVMLauncher.java new file mode 100644 index 0000000000..4247704be9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/JRockitVMLauncher.java @@ -0,0 +1,200 @@ +/******************************************************************************* + * Copyright (c) 2006, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +/** + * A standard VM launcher launches an external standard VM with + * the given arguments on the same machine. + */ +public class JRockitVMLauncher extends LocalVMLauncher { + String batchFileName; +/** + * Creates a new StandardVMLauncher that launches a standard VM + * on the same machine. + */ +public JRockitVMLauncher() { + super(); +} +/** + * Builds the actual boot class path that is going to be passed to the VM. + */ +protected String buildBootClassPath() { + StringBuilder bootPathString = new StringBuilder(); + + // Add boot class path directory if needed + if (this.evalTargetPath != null && TARGET_HAS_FILE_SYSTEM) { + bootPathString.append(this.evalTargetPath); + bootPathString.append(File.separatorChar); + bootPathString.append(BOOT_CLASSPATH_DIRECTORY); + } + + return bootPathString.toString(); +} +/** + * Returns the name of the batch file used to launch the VM. + */ +public String getBatchFileName() { + return this.batchFileName; +} +/** + * @see LocalVMLauncher#getCommandLine + */ +@Override +public String[] getCommandLine() { + List commandLine = new ArrayList<>(); + + // VM binary + if (System.getProperty("java.vm.version").startsWith("1.4.2")) { + commandLine.add( + this.vmPath + + (this.vmPath.endsWith(File.separator) ? "" : File.separator) + + "bin" + + File.separator + + "java"); + } else { + String vmLocation = this.vmPath + + (this.vmPath.endsWith(File.separator) ? "" : File.separator) + + "bin" + + File.separator + + "javaw"; + final String osName = System.getProperty("os.name"); + if (osName.indexOf("win32") != -1) { + vmLocation += ".exe"; + } + if (!new File(vmLocation).exists()) { + vmLocation = + this.vmPath + + (this.vmPath.endsWith(File.separator) ? "" : File.separator) + + "bin" + + File.separator + + "java"; + } + commandLine.add(vmLocation); + } + + // VM arguments + if (this.vmArguments != null) { + for (int i = 0; i < this.vmArguments.length; i++) { + commandLine.add(this.vmArguments[i]); + } + } + + // debug mode + if (this.debugPort != -1) { + commandLine.add("-Xdebug"); + commandLine.add("-Xnoagent"); + commandLine.add( + "-Xrunjdwp:transport=dt_socket,address=" + + this.debugPort + + ",server=y,suspend=n"); + } + + // set the classpath + // we don't set the bootclasspath as for StandardVMLauncher as this breaks the debug mode of JRockit + // we would get: [JRockit] ERROR: failed to set up MAPI gc reporting + commandLine.add("-classpath"); + String classpath = buildBootClassPath() + File.pathSeparator + buildClassPath(); + System.out.println(classpath); + commandLine.add(classpath); + + // code snippet runner class + if (this.evalPort != -1) { + commandLine.add(CODE_SNIPPET_RUNNER_CLASS_NAME); + } + + // code snippet runner arguments + if (this.evalPort != -1) { + commandLine.add(EVALPORT_ARG); + commandLine.add(Integer.toString(this.evalPort)); + if (TARGET_HAS_FILE_SYSTEM) { + commandLine.add(CODESNIPPET_CLASSPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + REGULAR_CLASSPATH_DIRECTORY); + commandLine.add(CODESNIPPET_BOOTPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + BOOT_CLASSPATH_DIRECTORY); + } + } + + // program class + if (this.programClass != null) { + commandLine.add(this.programClass); + } + + // program arguments + if (this.programArguments != null) { + for (int i=0;i commandLine) { + FileOutputStream output = null; + try { + output = new FileOutputStream(fileName); + PrintWriter out= new PrintWriter(output); + for (String string : commandLine) { + out.print(string); + out.print(" "); + } + out.println("pause"); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (output != null) { + try { + output.close(); + } catch (IOException e2) { + // ignore + } + } + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVMLauncher.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVMLauncher.java new file mode 100644 index 0000000000..36f810bda8 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVMLauncher.java @@ -0,0 +1,476 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Nina Rinskaya + * Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=172820. + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +import java.io.*; +import java.util.*; + +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.util.Util; + +/** + * The root of the VM launchers that launch VMs on the same machine. + *

    + * A local VM launcher has the following limitations: + *

      + *
    • It can only retrieve the running virtual machines that it has launched. So if + * a client is using 2 instances of LocalVMLauncher, each of these + * instances will be able to retrieve only a part of the running VMs. + *
    + */ +public abstract class LocalVMLauncher implements RuntimeConstants { + + static final String[] env = System.getenv().entrySet().stream() + .filter(e -> !"JAVA_TOOL_OPTIONS".equals(e.getKey())) + .map(e -> e.getKey() + "=" + e.getValue()) + .toArray(String[]::new); + + /** + * Whether the target has a file system and thus whether it supports writing + * class files to disk. See org.eclipse.jdt.core.tests.eval.target.CodeSnippetRunner for more + * information. + */ + public static final boolean TARGET_HAS_FILE_SYSTEM = true; + public static final String REGULAR_CLASSPATH_DIRECTORY = "regularPath"; + public static final String BOOT_CLASSPATH_DIRECTORY = "bootPath"; + + protected String[] bootPath; + protected String[] classPath; + protected int debugPort = -1; + protected int evalPort = -1; + protected String evalTargetPath; + protected String[] programArguments; + protected String programClass; + protected List runningVMs = new ArrayList<>(); // a Vector of LocalVirtualMachine + protected String[] vmArguments; + protected String vmPath; + +/** + * Returns a launcher that will launch the same kind of VM that is currently running + */ +public static LocalVMLauncher getLauncher() { + final String vmName = System.getProperty("java.vm.name"); + if ("J9".equals(vmName)) { + return new J9VMLauncher(); + } + if (vmName != null && vmName.indexOf("JRockit") != -1) { + return new JRockitVMLauncher(); + } + final String osName = System.getProperty("os.name"); + if (osName.startsWith("Mac")) { + return new MacVMLauncher(); + } + String javaVersion = System.getProperty("java.version"); + boolean isJrt = javaVersion != null && javaVersion.length() > 0 && JavaCore.compareJavaVersions(javaVersion, "9") >= 0; + File file = new File(Util.getJREDirectory() + (isJrt ? "/lib/jrt-fs.jar" : "/lib/rt.jar")); + if (file.exists()) { + return new StandardVMLauncher(); + } + if ("IBM J9SE VM".equals(vmName)) { + return new SideCarJ9VMLauncher(); + } + if ("DRLVM".equals(vmName)) { + return new DRLVMLauncher(); + } + return new SideCarVMLauncher(); +} +/** + * Builds the actual class path that is going to be passed to the VM. + */ +protected String buildClassPath() { + StringBuilder classPathString = new StringBuilder(); + char pathSeparator = File.pathSeparatorChar; + + // Add jar support if in evaluation mode + if (this.evalPort != -1) { + classPathString.append(new File(this.evalTargetPath, SUPPORT_ZIP_FILE_NAME).getPath()); + classPathString.append(pathSeparator); + } + + // Add class path given by client + if (this.classPath != null) { + int length = this.classPath.length; + for (int i = 0; i < length; i++){ + classPathString.append(this.classPath[i]); + classPathString.append(pathSeparator); + } + } + + // Add regular classpath directory if needed + if (this.evalPort != -1 && TARGET_HAS_FILE_SYSTEM) { + classPathString.append(this.evalTargetPath); + classPathString.append(File.separatorChar); + classPathString.append(REGULAR_CLASSPATH_DIRECTORY); + } + + return classPathString.toString(); +} +/** + * Launches the VM by exec'ing the command line and returns the resulting Process. + */ +protected Process execCommandLine() throws TargetException { + // Check that the VM path has been specified + if (this.vmPath == null) { + throw new TargetException("Path to the VM has not been specified"); + } + + // Check that the program class has been specified if not in evaluation mode + if ((this.programClass == null) && (this.evalPort == -1)) { + throw new TargetException("Program class has not been specified"); + } + + // Launch VM + Process vmProcess= null; + try { + // Use Runtime.exec(String[]) with tokens because Runtime.exec(String) with commandLineString + // does not properly handle spaces in arguments on Unix/Linux platforms. + String[] commandLine = getCommandLine(); + vmProcess= Runtime.getRuntime().exec(commandLine, env); + } catch (IOException e) { + throw new TargetException("Error launching VM at " + this.vmPath); + } + return vmProcess; +} +/** + * Returns the boot class path used when a VM is launched. + */ +public String[] getBootClassPath() { + return this.bootPath; +} +/** + * Returns the class path used when a VM is launched. + */ +public String[] getClassPath() { + return this.classPath; +} +/** + * Returns the command line which will be used to launch the VM. + * The segments are in the following order: + *

      + *
    • VM path, + *
    • VM arguments, + *
    • the class path, + *
    • the program class + *
    • the program arguments + *
    + */ +public abstract String[] getCommandLine(); +/** + * Returns the debug port, or -1 if debug mode is disabled. + * The default is -1. + */ +public int getDebugPort() { + return this.debugPort; +} +/** + * Returns the evaluation port for evaluation support. + * The default is -1, indicating no evaluation support. + * + * @see #setEvalPort(int) + */ +public int getEvalPort() { + return this.evalPort; +} +/** + * Returns the evaluation target path for evaluation support. + * + * @see #setEvalTargetPath(String) + */ +public String getEvalTargetPath() { + return this.evalTargetPath; +} +/** + * Returns the arguments passed to the program class. + * Returns null if the VM is being launched for evaluation support only. + */ +public String[] getProgramArguments() { + if (this.evalPort != -1) { + return null; + } + return this.programArguments; +} +/** + * Returns the dot-separated, fully qualified name of the class to run. + * It must implement main(String[] args). + * Returns null if the VM is being launched for evaluation support only. + */ +public String getProgramClass() { + if (this.evalPort != -1) { + return null; + } + return this.programClass; +} +/** + * Returns all the target VMs that are running at this launcher's target + * address. + * Note that these target VMs may or may not have been launched by this + * launcher. + * Note also that if the list of running VMs doesn't change on the target, + * two calls to this method return VMs that are equal. + * + * @return the list of running target VMs + */ +public LocalVirtualMachine[] getRunningVirtualMachines() { + // Select the VMs that are actually running + List actuallyRunning = new ArrayList<>(); + for (LocalVirtualMachine vm : this.runningVMs) { + if (vm.isRunning()) + actuallyRunning.add(vm); + } + this.runningVMs = actuallyRunning; + + // Return the running VMs + int size = actuallyRunning.size(); + LocalVirtualMachine[] result = new LocalVirtualMachine[size]; + for (int i=0; i"localhost:2010", or "joe.ibm.com". + * + * @return transport specific address of the target + */ +public String getTargetAddress() { + return "localhost"; +} +/** + * Returns the VM-specific arguments. This does not include: + *

      + *
    • the VM path + *
    • the class path or the boot class path + *
    • the program class or program arguments + *
    + */ +public String[] getVMArguments() { + return this.vmArguments; +} +/** + * Returns the path on disk of the VM to launch. + */ +public String getVMPath() { + return this.vmPath; +} +/** + * Initializes this context's target path by copying the jar file for the code snippet support + * and by creating the 2 directories that will contain the code snippet classes (see TARGET_HAS_FILE_SYSTEM). + * Add the code snipport root class to the boot path directory so that code snippets can be run in + * java.* packages + * + * @throws TargetException if the path could not be initialized with the code snippet support + */ +protected void initTargetPath() throws TargetException { + // create directories + File directory = new File(this.evalTargetPath); + directory.mkdirs(); + if (!directory.exists()) { + throw new TargetException("Could not create directory " + this.evalTargetPath); + } + if (TARGET_HAS_FILE_SYSTEM) { + File classesDirectory = new File(directory, REGULAR_CLASSPATH_DIRECTORY); + classesDirectory.mkdir(); + if (!classesDirectory.exists()) { + throw new TargetException("Could not create directory " + classesDirectory.getPath()); + } + File bootDirectory = new File(directory, BOOT_CLASSPATH_DIRECTORY); + bootDirectory.mkdir(); + if (!bootDirectory.exists()) { + throw new TargetException("Could not create directory " + bootDirectory.getPath()); + } + /* + // add the code snippet root class to the boot path directory + InputStream in = null; + try { + in = EvaluationContext.class.getResourceAsStream("/" + SUPPORT_ZIP_FILE_NAME); + ZipInputStream zip = new ZipInputStream(in); + String rootClassFileName = ROOT_FULL_CLASS_NAME.replace('.', '/') + ".class"; + while (true) { + ZipEntry entry = zip.getNextEntry(); + if (entry.getName().equals(rootClassFileName)) { + // read root class file contents + int size = (int)entry.getSize(); + byte[] buffer = new byte[size]; + int totalRead = 0; + int read = 0; + while (totalRead < size) { + read = zip.read(buffer, totalRead, size - totalRead); + if (read != -1) { + totalRead += read; + } + } + // write root class file contents + FileOutputStream out = null; + try { + File rootFile = new File(bootDirectory, rootClassFileName.replace('/', File.separatorChar)); + File parent = new File(rootFile.getParent()); + parent.mkdirs(); + out = new FileOutputStream(rootFile); + out.write(buffer); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + if (out != null) { + try { + out.close(); + } catch (IOException e2) { + } + } + } + break; + } + } + in.close(); + } catch (IOException e) { + e.printStackTrace(); + if (in != null) { + try { + in.close(); + } catch (IOException e2) { + } + } + }*/ + } + + // copy jar file + InputStream in = null; + FileOutputStream out = null; + try { + in = getClass().getResourceAsStream("/" + SUPPORT_ZIP_FILE_NAME); + if (in == null) { + throw new TargetException("Could not find resource /" + SUPPORT_ZIP_FILE_NAME); + } + int bufferLength = 1024; + byte[] buffer = new byte[bufferLength]; + File file = new File(directory, SUPPORT_ZIP_FILE_NAME); + out = new FileOutputStream(file); + int read = 0; + while (read != -1) { + read = in.read(buffer, 0, bufferLength); + if (read != -1) { + out.write(buffer, 0, read); + } + } + } catch (IOException e) { + throw new TargetException("IOException while copying " + SUPPORT_ZIP_FILE_NAME + ": " + e.getMessage()); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + } + } + if (out != null) { + try { + out.close(); + } catch (IOException e) { + } + } + } +} +/** + * Launches a new target VM with the registered arguments. + * This operation returns once a new target VM has been launched. + * + * @exception TargetException if the target VM could not be launched. + */ +public LocalVirtualMachine launch() throws TargetException { + // evaluation mode + if (this.evalTargetPath != null) { + // init target path + initTargetPath(); + } + + // launch VM + LocalVirtualMachine vm; + Process p = execCommandLine(); + vm = new LocalVirtualMachine(p, this.debugPort, this.evalTargetPath); + + // TBD: Start reading VM stdout and stderr right away otherwise this may prevent the connection + // from happening. + + // add VM to list of known running VMs + this.runningVMs.add(vm); + return vm; +} +/** + * Sets the boot class path used when a VM is launched. + */ +public void setBootClassPath(java.lang.String[] bootClassPath) { + this.bootPath = bootClassPath; +} +/** + * Sets the class path used when a VM is launched. + */ +public void setClassPath(String[] classPath) { + this.classPath = classPath; +} +/** + * Sets the debug port to use for debug support. + * Specify -1 to disable debug mode. + */ +public void setDebugPort(int debugPort) { + this.debugPort = debugPort; +} +/** + * Sets the evaluation port to use for evaluation support. + * Setting the port enables evaluation support. + * Specify null to disable evaluation support. + */ +public void setEvalPort(int evalPort) { + this.evalPort = evalPort; +} +/** + * Sets the evaluation target path to use for evaluation support. + */ +public void setEvalTargetPath(String evalTargetPath) { + this.evalTargetPath = evalTargetPath; +} +/** + * Sets the arguments passed to the program class. + * This is ignored if the VM is being launched for evaluation support only. + */ +public void setProgramArguments(String[] args) { + this.programArguments = args; +} +/** + * Sets the dot-separated, fully qualified name of the class to run. + * It must implement main(String[] args). + * This is ignored if the VM is being launched for evaluation support only. + */ +public void setProgramClass(String programClass) { + this.programClass = programClass; +} +/** + * Sets the VM-specific arguments. This does not include: + *

      + *
    • the VM path + *
    • the class path or the boot class path + *
    • the program class or program arguments + *
    + */ +public void setVMArguments(String[] args) { + this.vmArguments = args; +} +/** + * Sets the path on disk of the VM to launch. + */ +public void setVMPath(String vmPath) { + this.vmPath = vmPath; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java new file mode 100644 index 0000000000..d46a60779f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/LocalVirtualMachine.java @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2000, 2008 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +import java.io.*; + +import org.eclipse.jdt.core.tests.util.Util; + +/** + * Wrapper around the external process that is running a local VM. + * This allows to kill this process when we exit this vm. + */ +public class LocalVirtualMachine { + protected Process process; + protected int debugPort; + protected String evalTargetPath; +/** + * Creates a new LocalVirtualMachine that doesn't run and that cannot be debugged nor used to + * evaluate. + */ +public LocalVirtualMachine() { + this.process = null; + this.debugPort = -1; + this.evalTargetPath = null; +} +/** + * Creates a new LocalVirtualMachine from the Process that runs this VM + * and with the given debug port number. + */ +public LocalVirtualMachine(Process p, int debugPort, String evalTargetPath) { + this.process = p; + this.debugPort = debugPort; + this.evalTargetPath = evalTargetPath; +} +/* + * Cleans up the given directory by removing all the files it contains as well + * but leaving the directory. + * @throws TargetException if the target path could not be cleaned up + * +private void cleanupDirectory(File directory) throws TargetException { + if (!directory.exists()) { + return; + } + String[] fileNames = directory.list(); + for (int i = 0; i < fileNames.length; i++) { + File file = new File(directory, fileNames[i]); + if (file.isDirectory()) { + cleanupDirectory(file); + if (!file.delete()) { + throw new TargetException("Could not delete directory " + directory.getPath()); + } + } else { + if (!file.delete()) { + throw new TargetException("Could not delete file " + file.getPath()); + } + } + } +} +*/ +/** + * Cleans up this context's target path by removing all the files it contains + * but leaving the directory. + * @throws TargetException if the target path could not be cleaned up + */ +protected void cleanupTargetPath() throws TargetException { + if (this.evalTargetPath == null) return; + String targetPath = this.evalTargetPath; + if (LocalVMLauncher.TARGET_HAS_FILE_SYSTEM) { + Util.delete(new File(targetPath, LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY)); + Util.delete(new File(targetPath, LocalVMLauncher.BOOT_CLASSPATH_DIRECTORY)); + File file = new File(targetPath, RuntimeConstants.SUPPORT_ZIP_FILE_NAME); + + /* workaround pb with Process.exitValue() that returns the process has exited, but it has not free the file yet + int count = 10; + for (int i = 0; i < count; i++) { + if (file.delete()) { + break; + } + try { + Thread.sleep(count * 100); + } catch (InterruptedException e) { + } + } + */ + if (!Util.delete(file)) { + throw new TargetException("Could not delete " + file.getPath()); + } + } else { + Util.delete(targetPath); + } +} +/** + * Returns the debug port number for this VM. This is the port number that was + * passed as the "-debug" option if this VM was launched using a LocalVMLauncher. + * Returns -1 if this information is not available or if this VM is not running in + * debug mode. + */ +public int getDebugPortNumber() { + return this.debugPort; +} +/** + * Returns an input stream that is connected to the standard error + * (System.err) of this target VM. + * Bytes that are written to System.err by the target + * program become available in the input stream. + *

    + * Note 1: This stream is usually unbuffered. + *

    + * Note 2: Two calls to this method return the same identical input stream. + *

    + * See also java.lang.Process.getErrorStream(). + * + * @return an input stream connected to the target VM's System.err. + * @exception TargetException if the target VM is not reachable. + */ +public InputStream getErrorStream() throws TargetException { + if (this.process == null) + throw new TargetException("The VM is not running"); + return this.process.getErrorStream(); +} +/** + * Returns an input stream that is connected to the standard output + * (System.out) of this target VM. + * Bytes that are written to System.out by the target + * program become available in the input stream. + *

    + * Note 1: This stream is usually buffered. + *

    + * Note 2: Two calls to this method return the same identical input stream. + *

    + * See also java.lang.Process.getInputStream(). + * + * @return an input stream connected to the target VM's System.out. + * @exception TargetException if the target VM is not reachable. + */ +public InputStream getInputStream() throws TargetException { + if (this.process == null) + throw new TargetException("The VM is not running"); + // Workaround problem with input stream of a Process + return new VMInputStream(this.process, this.process.getInputStream()); +} +/** + * Returns an output stream that is connected to the standard input + * (System.in) of this target VM. + * Bytes that are written to the output stream by a client become available to the target + * program in System.in. + *

    + * Note 1: This stream is usually buffered. + *

    + * Note 2: Two calls to this method return the same identical output stream. + *

    + * See also java.lang.Process.getOutputStream(). + * + * @return an output stream connected to the target VM's System.in. + * @exception TargetException if the target VM is not reachable. + */ +public OutputStream getOutputStream() throws TargetException { + if (this.process == null) + throw new TargetException("The VM is not running"); + return this.process.getOutputStream(); +} +/** + * Returns whether this target VM is still running. + *

    + * Note: This operation may require contacting the target VM to find out + * if it is still running. + */ +public boolean isRunning() { + if (this.process == null) { + return false; + } + boolean hasExited; + try { + this.process.exitValue(); + hasExited = true; + } catch (IllegalThreadStateException e) { + hasExited = false; + } + return !hasExited; +} +/** + * Shuts down this target VM. + * This causes the VM to exit. This operation is ignored + * if the VM has already shut down. + * + * @throws TargetException if the target path could not be cleaned up + */ +public synchronized void shutDown() throws TargetException { + if (this.process != null) { + this.process.destroy(); + this.process = null; + cleanupTargetPath(); + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/MacVMLauncher.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/MacVMLauncher.java new file mode 100644 index 0000000000..b32f0a318c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/MacVMLauncher.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +/** + * This is a new vm launcher to support sidecar settings + */ +public class MacVMLauncher extends StandardVMLauncher { +/** + * @see LocalVMLauncher#getCommandLine + */ +@Override +public String[] getCommandLine() { + List commandLine = new ArrayList<>(); + + // VM binary + commandLine.add( + this.vmPath + + (this.vmPath.endsWith(File.separator) ? "" : File.separator) + + "bin" + + File.separator + + "java"); + + // VM arguments + if (this.vmArguments != null) { + for (int i = 0; i < this.vmArguments.length; i++) { + commandLine.add(this.vmArguments[i]); + } + } + + // boot classpath + commandLine.add("-Xbootclasspath/a:" + buildBootClassPath()); + + // debug mode + if (this.debugPort != -1) { + commandLine.add("-Xdebug"); + commandLine.add("-Xnoagent"); + // commandLine.add("-Djava.compiler=NONE"); + commandLine.add( + "-Xrunjdwp:transport=dt_socket,address=" + + this.debugPort + + ",server=y,suspend=n"); + } else { + commandLine.add("-Xdebug"); + } + + // regular classpath + commandLine.add("-classpath"); + commandLine.add(buildClassPath()); + + // code snippet runner class + if (this.evalPort != -1) { + commandLine.add(CODE_SNIPPET_RUNNER_CLASS_NAME); + } + + // code snippet runner arguments + if (this.evalPort != -1) { + commandLine.add(EVALPORT_ARG); + commandLine.add(Integer.toString(this.evalPort)); + if (TARGET_HAS_FILE_SYSTEM) { + commandLine.add(CODESNIPPET_CLASSPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + REGULAR_CLASSPATH_DIRECTORY); + commandLine.add(CODESNIPPET_BOOTPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + BOOT_CLASSPATH_DIRECTORY); + } + } + + // program class + if (this.programClass != null) { + commandLine.add(this.programClass); + } + + // program arguments + if (this.programArguments != null) { + for (int i=0;iProxyConsoleReader reads the ouput from the proxy and + * redirects it to a file or to the stdout if "con" is the name of the file. + */ +class ProxyConsoleReader extends AbstractReader { + private InputStream input; + private OutputStream output; +/* + * Creates a new proxy console reader that will read from the given input stream + * and rewrite what's read to the given file (or the stdout is the file name is + * "con") + */ +public ProxyConsoleReader(String name, InputStream input, String fileName) { + super(name); + this.input = input; + if (fileName.equals("con")) { + this.output= System.out; + } else { + try { + this.output= new FileOutputStream(fileName); + } catch (IOException e) { + System.out.println("Could not create file " + fileName + ". Redirecting to stdout"); + this.output= System.out; + } + } +} +/** + * Continuously reads from the proxy output and redirect what's read to + * this reader's file. + */ +@Override +protected void readerLoop() { + try { + byte[] buffer= new byte[1024]; + int read= 0; + while (!this.isStopping && read != -1) { + read= this.input.read(buffer); + if (read != -1) + this.output.write(buffer, 0, read); + } + } catch (java.io.IOException e) { + } +} +/** + * Stop this reader + */ +@Override +public void stop() { + super.stop(); + try { + if (this.output != System.out) + this.output.close(); + } catch (IOException e) { + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/RuntimeConstants.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/RuntimeConstants.java new file mode 100644 index 0000000000..0335ec60d1 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/RuntimeConstants.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +public interface RuntimeConstants { + public static final String SUPPORT_ZIP_FILE_NAME = "EvalTestsTarget.zip"; + public static final String CODE_SNIPPET_RUNNER_CLASS_NAME = "org.eclipse.jdt.core.tests.eval.target.CodeSnippetRunner"; + public static final String RUN_CODE_SNIPPET_METHOD = "runCodeSnippet"; + public static final String THE_RUNNER_FIELD = "theRunner"; + public static final String EVALPORT_ARG = "-evalport"; + public static final String CODESNIPPET_CLASSPATH_ARG = "-cscp"; + public static final String CODESNIPPET_BOOTPATH_ARG = "-csbp"; +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/SideCarJ9VMLauncher.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/SideCarJ9VMLauncher.java new file mode 100644 index 0000000000..aaef8e4403 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/SideCarJ9VMLauncher.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +/** + * This is a new vm launcher to support sidecar settings + */ +public class SideCarJ9VMLauncher extends StandardVMLauncher { +/** + * @see LocalVMLauncher#getCommandLine + */ +@Override +public String[] getCommandLine() { + List commandLine = new ArrayList<>(); + + // VM binary + commandLine.add( + this.vmPath + + (this.vmPath.endsWith(File.separator) ? "" : File.separator) + + "bin" + + File.separator + + "javaw"); + + // VM arguments + if (this.vmArguments != null) { + for (int i = 0; i < this.vmArguments.length; i++) { + commandLine.add(this.vmArguments[i]); + } + } + + // boot classpath + commandLine.add("-Xbootclasspath/a:" + buildBootClassPath()); + + // debug mode + commandLine.add("-Xdebug"); + if (this.debugPort != -1) { + commandLine.add("-Xnoagent"); + // commandLine.add("-Djava.compiler=NONE"); + commandLine.add( + "-Xrunjdwp:transport=dt_socket,address=" + + this.debugPort + + ",server=y,suspend=n"); + } + + commandLine.add("-Xj9"); + commandLine.add("-Xprod"); + + // regular classpath + commandLine.add("-classpath"); + commandLine.add(buildClassPath()); + + // code snippet runner class + if (this.evalPort != -1) { + commandLine.add(CODE_SNIPPET_RUNNER_CLASS_NAME); + } + + // code snippet runner arguments + if (this.evalPort != -1) { + commandLine.add(EVALPORT_ARG); + commandLine.add(Integer.toString(this.evalPort)); + if (TARGET_HAS_FILE_SYSTEM) { + commandLine.add(CODESNIPPET_CLASSPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + REGULAR_CLASSPATH_DIRECTORY); + commandLine.add(CODESNIPPET_BOOTPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + BOOT_CLASSPATH_DIRECTORY); + } + } + + // program class + if (this.programClass != null) { + commandLine.add(this.programClass); + } + + // program arguments + if (this.programArguments != null) { + for (int i=0;i commandLine = new ArrayList<>(); + + // VM binary + commandLine.add( + this.vmPath + + (this.vmPath.endsWith(File.separator) ? "" : File.separator) + + "bin" + + File.separator + + "javaw"); + + // VM arguments + if (this.vmArguments != null) { + for (int i = 0; i < this.vmArguments.length; i++) { + commandLine.add(this.vmArguments[i]); + } + } + + // boot classpath + commandLine.add("-Xbootclasspath/a:" + buildBootClassPath()); + + // debug mode + if (this.debugPort != -1) { + commandLine.add("-Xdebug"); + commandLine.add("-Xnoagent"); + // commandLine.add("-Djava.compiler=NONE"); + commandLine.add( + "-Xrunjdwp:transport=dt_socket,address=" + + this.debugPort + + ",server=y,suspend=n"); + } + + // regular classpath + commandLine.add("-classpath"); + commandLine.add(buildClassPath()); + + // code snippet runner class + if (this.evalPort != -1) { + commandLine.add(CODE_SNIPPET_RUNNER_CLASS_NAME); + } + + // code snippet runner arguments + if (this.evalPort != -1) { + commandLine.add(EVALPORT_ARG); + commandLine.add(Integer.toString(this.evalPort)); + if (TARGET_HAS_FILE_SYSTEM) { + commandLine.add(CODESNIPPET_CLASSPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + REGULAR_CLASSPATH_DIRECTORY); + commandLine.add(CODESNIPPET_BOOTPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + BOOT_CLASSPATH_DIRECTORY); + } + } + + // program class + if (this.programClass != null) { + commandLine.add(this.programClass); + } + + // program arguments + if (this.programArguments != null) { + for (int i=0;i commandLine = new ArrayList<>(); + + // VM binary + StringBuffer vmLocation = new StringBuffer(this.vmPath); + vmLocation + .append(this.vmPath.endsWith(File.separator) ? "" : File.separator) + .append("bin") + .append(File.separator) + .append("java"); + commandLine.add(String.valueOf(vmLocation)); + + // VM arguments + if (this.vmArguments != null) { + for (int i = 0; i < this.vmArguments.length; i++) { + commandLine.add(this.vmArguments[i]); + } + } + + long vmVersion = Util.getMajorMinorVMVersion(); + if (vmVersion != -1) { + if (vmVersion < ClassFileConstants.JDK13) { // FailOverToOldVerifier deprecated from 13 + commandLine.add("-XX:-FailOverToOldVerifier"); + } + if (vmVersion >= ClassFileConstants.JDK1_6) { + commandLine.add("-Xverify:all"); + } + if (vmVersion >= ClassFileConstants.JDK1_7) { + commandLine.add("-XX:+UnlockExperimentalVMOptions"); + } + } + + // debug mode + if (this.debugPort != -1) { + commandLine.add("-Xdebug"); + commandLine.add("-Xnoagent"); + // commandLine.add("-Djava.compiler=NONE"); + commandLine.add( + "-Xrunjdwp:transport=dt_socket,address=" + + this.debugPort + + ",server=y,suspend=n"); + } + + // boot classpath + commandLine.add("-Xbootclasspath/a:" + buildBootClassPath()); + + // regular classpath + commandLine.add("-classpath"); + commandLine.add(buildClassPath()); + + // code snippet runner class + if (this.evalPort != -1) { + commandLine.add(CODE_SNIPPET_RUNNER_CLASS_NAME); + } + + // code snippet runner arguments + if (this.evalPort != -1) { + commandLine.add(EVALPORT_ARG); + commandLine.add(Integer.toString(this.evalPort)); + if (TARGET_HAS_FILE_SYSTEM) { + commandLine.add(CODESNIPPET_CLASSPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + REGULAR_CLASSPATH_DIRECTORY); + commandLine.add(CODESNIPPET_BOOTPATH_ARG); + commandLine.add(this.evalTargetPath + File.separator + BOOT_CLASSPATH_DIRECTORY); + } + } + + // program class + if (this.programClass != null) { + commandLine.add(this.programClass); + } + + // program arguments + if (this.programArguments != null) { + for (int i=0;i commandLine) { + FileOutputStream output = null; + try { + output = new FileOutputStream(fileName); + PrintWriter out= new PrintWriter(output); + for (String string : commandLine) { + out.print(string); + out.print(" "); + } + out.println("pause"); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (output != null) { + try { + output.close(); + } catch (IOException e2) { + // ignore + } + } + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetException.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetException.java new file mode 100644 index 0000000000..3a0b67ed6b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetException.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +/** + * A TargetException is thrown when an operation on a target has failed + * for any reason. + */ +public class TargetException extends Exception { +private static final long serialVersionUID = 1L; +/** + * Constructs a TargetException with no detail message. + */ +public TargetException() { + super(); +} +/** + * Constructs a TargetException with the specified + * detail message. + * + * @param s the detail message. + */ +public TargetException(String s) { + super(s); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetInterface.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetInterface.java new file mode 100644 index 0000000000..b61c7e5592 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/TargetInterface.java @@ -0,0 +1,200 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +import org.eclipse.jdt.internal.compiler.ClassFile; +import org.eclipse.jdt.internal.compiler.util.Util; + +import java.io.*; +import java.net.*; +/** + * This is the interface to the target VM. It connects to an IDEInterface on the target side + * using TCP/IO to send request for code snippet evaluation and to get the result back. + * + * @see org.eclipse.jdt.core.tests.eval.target.IDEInterface for details about the protocol. + */ +public class TargetInterface { + /** + * Whether class files should be written in d:\eval\ instead of sending them to the target + * NB: d:\eval should contain a batch file TestCodeSnippet.bat with the following contents: + * SET JDK=c:\jdk1.2.2 + * SET EVAL=d:\eval + * %JDK%\bin\java -Xbootclasspath:%JDK%\jre\lib\rt.jar;%EVAL%\javaClasses; -classpath c:\temp;%EVAL%\snippets;%EVAL%\classes;"d:\ide\project_resources\Eclipse Java Evaluation\CodeSnippetSupport.jar" CodeSnippetTester %1 + */ + static final boolean DEBUG = false; + String codeSnippetClassName; + + /** + * Whether timing info should be printed to stdout + */ + static final boolean TIMING = false; + long sentTime; + + /** + * The connection to the target's ide interface. + */ + Socket socket; + + public static class Result { + public char[] displayString; + public char[] typeName; + } + +/** + * (PRIVATE API) + * Connects this interface to the target. + * Try as long as the given time (in ms) has not expired. + * Use isConnected() to find out if the connection was successful. + */ +public void connect(ServerSocket server, int timeout) { + if (isConnected()) { + return; + } + if (server != null) { + long startTime = System.currentTimeMillis(); + do { + try { + this.socket = server.accept(); + this.socket.setTcpNoDelay(true); + break; + } catch (IOException e) { + e.printStackTrace(); + } + if (this.socket == null) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + } + } while (!isConnected() && (System.currentTimeMillis() - startTime) < timeout); + } +} +/** + * (PRIVATE API) + * Disconnects this interface from the target. + */ +public void disconnect() { + if (this.socket != null) { + try { + this.socket.close(); + } catch (IOException e) { + e.printStackTrace(); + // Already closed. Nothing more to do + } + this.socket = null; + } +} +/** + * Returns the result of the evaluation sent previously to the target. + */ +public Result getResult() { + boolean hasValue = false; + String typeName = null; + String toString = null; + if (DEBUG) { + hasValue = true; + typeName = "TargetInterface in debug mode. Run d:\\eval\\TestCodeSnippet.bat d:\\eval\\snippets\\" + this.codeSnippetClassName; + toString = ""; + } else { + if (isConnected()) { + // TBD: Read type name and toString as a character array + try { + DataInputStream in = new DataInputStream(this.socket.getInputStream()); + hasValue = in.readBoolean(); + if (hasValue) { + typeName = in.readUTF(); + toString = in.readUTF(); + } else { + typeName = null; + toString = null; + } + } catch (IOException e) { + // The socket has likely been closed on the other end. So the code snippet runner has stopped. + hasValue = true; + typeName = e.getMessage(); + toString = ""; + disconnect(); + } + } else { + hasValue = true; + typeName = "Connection has been lost"; + toString = ""; + } + } + if (TIMING) { + System.out.println("Time to send compiled classes, run on target and get result is " + (System.currentTimeMillis() - this.sentTime) + "ms"); + } + Result result = new Result(); + result.displayString = toString == null ? null : toString.toCharArray(); + result.typeName = typeName == null ? null : typeName.toCharArray(); + return result; +} +/** + * Returns whether this interface is connected to the target. + */ +public boolean isConnected() { + return this.socket != null; +} +/** + * Sends the given class definitions to the target for loading and (if specified) for running. + */ +public void sendClasses(boolean mustRun, ClassFile[] classes) throws TargetException { + if (DEBUG) { + for (int i = 0; i < classes.length; i++) { + String className = new String(classes[i].fileName()).replace('/', '\\') + ".class"; + if ((i == 0) && (className.indexOf("CodeSnippet") != -1)) { + this.codeSnippetClassName = className; + try { + Util.writeToDisk(true, "d:\\eval\\snippets", className, classes[0]); + } catch(IOException e) { + e.printStackTrace(); + } + } else { + String dirName; + if (className.startsWith("java")) { + dirName = "d:\\eval\\" + LocalVMLauncher.BOOT_CLASSPATH_DIRECTORY; + } else { + dirName = "d:\\eval\\" + LocalVMLauncher.REGULAR_CLASSPATH_DIRECTORY; + } + try { + Util.writeToDisk(true, dirName, className, classes[i]); + } catch(IOException e) { + e.printStackTrace(); + } + } + } + } else { + if (TIMING) { + this.sentTime = System.currentTimeMillis(); + } + if (!isConnected()) { + throw new TargetException("Connection to the target VM has been lost"); + } + try { + DataOutputStream out = new DataOutputStream(this.socket.getOutputStream()); + out.writeBoolean(mustRun); + out.writeInt(classes.length); + for (int i = 0; i < classes.length; i++) { + byte[] classDefinition = classes[i].getBytes(); + out.writeInt(classDefinition.length); + out.write(classDefinition); + } + } catch (IOException e) { + e.printStackTrace(); + // The socket has likely been closed on the other end. So the code snippet runner has stopped. + disconnect(); + } + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/VMInputStream.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/VMInputStream.java new file mode 100644 index 0000000000..8671e60d22 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/runtime/VMInputStream.java @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.runtime; + +import java.io.*; + +/** + * Workaround problem with input stream from a java.lang.Process + * that throws an IOException even if there is something to read. + */ +public class VMInputStream extends InputStream { + InputStream input; + Process process; +public VMInputStream(Process process, InputStream input) { + this.process= process; + this.input= input; +} +@Override +public int available() throws IOException { + return this.input.available(); +} +@Override +public void close() throws IOException { + this.input.close(); +} +private boolean isRunning() { + if (this.process == null) { + return false; + } + boolean hasExited; + try { + this.process.exitValue(); + hasExited = true; + } catch (IllegalThreadStateException e) { + hasExited = false; + } + return !hasExited; +} +@Override +public synchronized void mark(int readlimit) { + this.input.mark(readlimit); +} +@Override +public boolean markSupported() { + return this.input.markSupported(); +} +@Override +public int read() throws IOException { + try { + return this.input.read(); + } catch (IOException e) { + if (isRunning()) { + return read(); + } + throw e; + } +} +@Override +public int read(byte b[]) throws IOException { + // Make sure the byte array is initialized (value of 0 is used in the workaround below) + for (int i=0;i 0) { + complianceString = CompilerOptions.versionFromJdkLevel(highestLevel); + } else { + complianceString = "unknown"; + } + + } + + System.err.println("Cannot run "+evaluationTestClass.getName()+" at compliance "+complianceString+"!"); + return new TestSuite(); + } + TestSuite complianceSuite = new RegressionTestSetup(uniqueCompliance); + List tests = buildTestsList(evaluationTestClass); + for (int index=0, size=tests.size(); index= 0; i-- ) { + int[] map = complianceTestLevelMapping[i]; + if ((complianceLevels & map[0]) != 0) { + return ClassFileConstants.getComplianceLevelForJavaVersion(map[1]); + } + } + return ClassFileConstants.JDK1_3; + } + + static void initReflectionVersion() { + if (isJRE9Plus) { + reflectNestedClassUseDollar = true; + System.out.println("reflectNestedClassUseDollar="+reflectNestedClassUseDollar+" due to isJRE9Plus"); + } else { + String version = System.getProperty("java.version"); + if (version.startsWith("1.8.0_")) { + int build = Integer.parseInt(version.substring("1.8.0_".length())); + reflectNestedClassUseDollar = build >= 171; + } else if (version.startsWith("1.8.0-")) { + // Some versions start with 1.8.0- but don't have build qualifier. + // Just assume they are > 171 build. Nothing much can be done. + reflectNestedClassUseDollar = true; + } else { + throw new IllegalStateException("Unrecognized Java version: "+version); + } + System.out.println("reflectNestedClassUseDollar="+reflectNestedClassUseDollar+" based on version="+version); + } + } + + /* + * Returns the possible compliance levels this VM instance can run. + */ + public static int getPossibleComplianceLevels() { + if (possibleComplianceLevels == UNINITIALIZED) { + String specVersion = System.getProperty("java.specification.version"); + isJRE17Plus = CompilerOptions.VERSION_17.equals(specVersion); + isJRE16Plus = isJRE17Plus || CompilerOptions.VERSION_16.equals(specVersion); + isJRE15Plus = isJRE16Plus || CompilerOptions.VERSION_15.equals(specVersion); + isJRE14Plus = isJRE15Plus || CompilerOptions.VERSION_14.equals(specVersion); + isJRE13Plus = isJRE14Plus || CompilerOptions.VERSION_13.equals(specVersion); + isJRE12Plus = isJRE13Plus || CompilerOptions.VERSION_12.equals(specVersion); + isJRE11Plus = isJRE12Plus || CompilerOptions.VERSION_11.equals(specVersion); + isJRE10Plus = isJRE11Plus || CompilerOptions.VERSION_10.equals(specVersion); + isJRE9Plus = isJRE10Plus || CompilerOptions.VERSION_9.equals(specVersion); + initReflectionVersion(); + String key = "compliance.jre." + specVersion; + String compliances = System.getProperty(key); + if (compliances == null) { + compliances = System.getProperty("compliance"); + } + if (compliances != null) { + possibleComplianceLevels = 0; + for (String compliance : compliances.split(",")) { + if (CompilerOptions.VERSION_1_3.equals(compliance)) { + possibleComplianceLevels |= RUN_JAVAC ? NONE : F_1_3; + } else if (CompilerOptions.VERSION_1_4.equals(compliance)) { + possibleComplianceLevels |= RUN_JAVAC ? NONE : F_1_4; + } else if (CompilerOptions.VERSION_1_5.equals(compliance)) { + possibleComplianceLevels |= F_1_5; + } else if (CompilerOptions.VERSION_1_6.equals(compliance)) { + possibleComplianceLevels |= F_1_6; + } else if (CompilerOptions.VERSION_1_7.equals(compliance)) { + possibleComplianceLevels |= F_1_7; + } else if (CompilerOptions.VERSION_1_8.equals(compliance)) { + possibleComplianceLevels |= F_1_8; + } else if (CompilerOptions.VERSION_9.equals(compliance)) { + if (isJRE9Plus) + possibleComplianceLevels |= F_9; + } else if (CompilerOptions.VERSION_10.equals(compliance)) { + if (isJRE10Plus) + possibleComplianceLevels |= F_10; + } else if (CompilerOptions.VERSION_11.equals(compliance)) { + if (isJRE11Plus) + possibleComplianceLevels |= F_11; + } else if (CompilerOptions.VERSION_12.equals(compliance)) { + if (isJRE12Plus) + possibleComplianceLevels |= F_12; + } else if (CompilerOptions.VERSION_13.equals(compliance)) { + if (isJRE13Plus) + possibleComplianceLevels |= F_13; + } else if (CompilerOptions.VERSION_14.equals(compliance)) { + if (isJRE14Plus) + possibleComplianceLevels |= F_14; + } else if (CompilerOptions.VERSION_15.equals(compliance)) { + if (isJRE15Plus) + possibleComplianceLevels |= F_15; + } else if (CompilerOptions.VERSION_16.equals(compliance)) { + if (isJRE16Plus) + possibleComplianceLevels |= F_16; + } else if (CompilerOptions.VERSION_17.equals(compliance)) { + if (isJRE17Plus) + possibleComplianceLevels |= F_17; + } else { + System.out.println("Ignoring invalid compliance (" + compliance + ")"); + System.out.print("Use one of "); + System.out.print(CompilerOptions.VERSION_1_3 + ", "); + System.out.print(CompilerOptions.VERSION_1_4 + ", "); + System.out.print(CompilerOptions.VERSION_1_5 + ", "); + System.out.print(CompilerOptions.VERSION_1_6 + ", "); + System.out.print(CompilerOptions.VERSION_1_7 + ", "); + System.out.print(CompilerOptions.VERSION_1_8 + ", "); + System.out.print(CompilerOptions.VERSION_1_8 + ", "); + System.out.print(CompilerOptions.VERSION_9 + ", "); + System.out.print(CompilerOptions.VERSION_10 + ", "); + System.out.print(CompilerOptions.VERSION_11 + ", "); + System.out.print(CompilerOptions.VERSION_12 + ", "); + System.out.print(CompilerOptions.VERSION_13 + ", "); + System.out.println(CompilerOptions.VERSION_14 + ", "); + System.out.println(CompilerOptions.VERSION_15 + ", "); + System.out.println(CompilerOptions.VERSION_16); + } + } + if (possibleComplianceLevels == 0) { + System.out.println("Defaulting to all possible compliances"); + possibleComplianceLevels = UNINITIALIZED; + } + } + if (possibleComplianceLevels == UNINITIALIZED) { + if (!RUN_JAVAC) { + possibleComplianceLevels = F_1_3; + boolean canRun1_4 = !"1.0".equals(specVersion) + && !CompilerOptions.VERSION_1_1.equals(specVersion) + && !CompilerOptions.VERSION_1_2.equals(specVersion) + && !CompilerOptions.VERSION_1_3.equals(specVersion); + if (canRun1_4) { + possibleComplianceLevels |= F_1_4; + } + boolean canRun1_5 = canRun1_4 && !CompilerOptions.VERSION_1_4.equals(specVersion); + if (canRun1_5) { + possibleComplianceLevels |= F_1_5; + } + boolean canRun1_6 = canRun1_5 && !CompilerOptions.VERSION_1_5.equals(specVersion); + if (canRun1_6) { + possibleComplianceLevels |= F_1_6; + } + boolean canRun1_7 = canRun1_6 && !CompilerOptions.VERSION_1_6.equals(specVersion); + if (canRun1_7) { + possibleComplianceLevels |= F_1_7; + } + boolean canRun1_8 = canRun1_7 && !CompilerOptions.VERSION_1_7.equals(specVersion); + if (canRun1_8) { + possibleComplianceLevels |= F_1_8; + } + boolean canRun9 = canRun1_8 && !CompilerOptions.VERSION_1_8.equals(specVersion); + if (canRun9) { + possibleComplianceLevels |= F_9; + } + boolean canRun10 = canRun9 && !CompilerOptions.VERSION_9.equals(specVersion); + if (canRun10) { + possibleComplianceLevels |= F_10; + } + boolean canRun11 = canRun10 && !CompilerOptions.VERSION_10.equals(specVersion); + if (canRun11) { + possibleComplianceLevels |= F_11; + } + boolean canRun12 = canRun11 && !CompilerOptions.VERSION_11.equals(specVersion); + if (canRun12) { + possibleComplianceLevels |= F_12; + } + boolean canRun13 = canRun12 && !CompilerOptions.VERSION_12.equals(specVersion); + if (canRun13) { + possibleComplianceLevels |= F_13; + } + boolean canRun14 = canRun13 && !CompilerOptions.VERSION_13.equals(specVersion); + if (canRun14) { + possibleComplianceLevels |= F_14; + } + boolean canRun15 = canRun14 && !CompilerOptions.VERSION_14.equals(specVersion); + if (canRun15) { + possibleComplianceLevels |= F_15; + } + boolean canRun16 = canRun15 && !CompilerOptions.VERSION_15.equals(specVersion); + if (canRun16) { + possibleComplianceLevels |= F_16; + } + boolean canRun17 = canRun16 && !CompilerOptions.VERSION_16.equals(specVersion); + if (canRun17) { + possibleComplianceLevels |= F_17; + } + } else if ("1.0".equals(specVersion) + || CompilerOptions.VERSION_1_1.equals(specVersion) + || CompilerOptions.VERSION_1_2.equals(specVersion) + || CompilerOptions.VERSION_1_3.equals(specVersion) + || CompilerOptions.VERSION_1_4.equals(specVersion)) { + possibleComplianceLevels = NONE; + } else { + possibleComplianceLevels = F_1_5; + if (!CompilerOptions.VERSION_1_5.equals(specVersion)) { + possibleComplianceLevels |= F_1_6; + if (!CompilerOptions.VERSION_1_6.equals(specVersion)) { + possibleComplianceLevels |= F_1_7; + if (!CompilerOptions.VERSION_1_7.equals(specVersion)) { + possibleComplianceLevels |= F_1_8; + if (!CompilerOptions.VERSION_1_8.equals(specVersion)) { + possibleComplianceLevels |= F_9; + if (!CompilerOptions.VERSION_9.equals(specVersion)) { + possibleComplianceLevels |= F_10; + if (!CompilerOptions.VERSION_10.equals(specVersion)) { + possibleComplianceLevels |= F_11; + if (!CompilerOptions.VERSION_11.equals(specVersion)) { + possibleComplianceLevels |= F_12; + if (!CompilerOptions.VERSION_12.equals(specVersion)) { + possibleComplianceLevels |= F_13; + if (!CompilerOptions.VERSION_13.equals(specVersion)) { + possibleComplianceLevels |= F_14; + if (!CompilerOptions.VERSION_14.equals(specVersion)) { + possibleComplianceLevels |= F_15; + if (!CompilerOptions.VERSION_15.equals(specVersion)) { + possibleComplianceLevels |= F_16; + if (!CompilerOptions.VERSION_16.equals(specVersion)) { + possibleComplianceLevels |= F_17; + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + if (possibleComplianceLevels == NONE) { + System.out.println("Skipping all compliances (found none compatible with run.javac=enabled)."); + } + return possibleComplianceLevels; + } + + /* + * Returns a test suite including the tests defined by the given classes for all possible complianceLevels + * and using the given setup class (CompilerTestSetup or a subclass) + */ + public static Test suite(String suiteName, Class setupClass, ArrayList testClasses) { + TestSuite all = new TestSuite(suiteName); + int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels(); + if ((complianceLevels & AbstractCompilerTest.F_1_3) != 0) { + all.addTest(suiteForComplianceLevel(ClassFileConstants.JDK1_3, setupClass, testClasses)); + } + if ((complianceLevels & AbstractCompilerTest.F_1_4) != 0) { + all.addTest(suiteForComplianceLevel(ClassFileConstants.JDK1_4, setupClass, testClasses)); + } + if ((complianceLevels & AbstractCompilerTest.F_1_5) != 0) { + all.addTest(suiteForComplianceLevel(ClassFileConstants.JDK1_5, setupClass, testClasses)); + } + return all; + } + + /* + * Returns a test suite including the tests defined by the given classes for the given complianceLevel + * (see AbstractCompilerTest for valid values) and using the given setup class (CompilerTestSetup or a subclass) + */ + public static Test suiteForComplianceLevel(long complianceLevel, Class setupClass, ArrayList testClasses) { + // call the setup constructor with the compliance level + TestSuite suite = null; + try { + Constructor constructor = setupClass.getConstructor(new Class[]{String.class}); + suite = (TestSuite)constructor.newInstance(new Object[]{CompilerOptions.versionFromJdkLevel(complianceLevel)}); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.getTargetException().printStackTrace(); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + if (suite == null) + return null; + + // add tests + Class testClass; + if (testClasses.size() == 1) { + suite = new TestSuite(testClass = (Class)testClasses.get(0), CompilerOptions.versionFromJdkLevel(complianceLevel)); + TESTS_COUNTERS.put(testClass.getName(), Integer.valueOf(suite.countTestCases())); + } else { + suite = new TestSuite(CompilerOptions.versionFromJdkLevel(complianceLevel)); + for (int i = 0, length = testClasses.size(); i < length; i++) { + TestSuite innerSuite = new TestSuite(testClass = (Class)testClasses.get(i)); + TESTS_COUNTERS.put(testClass.getName(), Integer.valueOf(innerSuite.countTestCases())); + suite.addTest(innerSuite); + } + } + return suite; + } + + public static Test setupSuite(Class clazz) { + ArrayList testClasses = new ArrayList(); + testClasses.add(clazz); + return suite(clazz.getName(), RegressionTestSetup.class, testClasses); + } + + public static Test buildTestSuite(Class evaluationTestClass) { + if (TESTS_PREFIX != null || TESTS_NAMES != null || TESTS_NUMBERS!=null || TESTS_RANGE !=null) { + return buildTestSuite(evaluationTestClass, highestComplianceLevels()); + } + return setupSuite(evaluationTestClass); + } + + public static Test buildTestSuite(Class evaluationTestClass, long complianceLevel) { + TestSuite suite = new RegressionTestSetup(complianceLevel); + List tests = buildTestsList(evaluationTestClass); + for (int index=0, size=tests.size(); index ClassFileConstants.JDK10) { + String ver = CompilerOptions.versionFromJdkLevel(compliance); + int major = Integer.parseInt(ver) + ClassFileConstants.MAJOR_VERSION_0; + return "version " + ver + " : " + major + ".0"; + } + if (compliance >= ClassFileConstants.getComplianceLevelForJavaVersion(ClassFileConstants.MAJOR_VERSION_17)) return version; // keep this stmt for search for next bump up + return version; + } + + public void initialize(CompilerTestSetup setUp) { + this.complianceLevel = setUp.complianceLevel; + this.enableAPT = System.getProperty("enableAPT") != null; + } + + protected String testName() { + return super.getName(); + } + + // Output files management + protected IPath outputRootDirectoryPath = new Path(Util.getOutputDirectory()); + protected File outputTestDirectory; + + /** + * Create a test specific output directory as a subdirectory of + * outputRootDirectory, given a subdirectory path. The whole + * subtree is created as needed. outputTestDirectoryPath is + * modified according to the latest call to this method. + * @param suffixPath a valid relative path for the subdirectory + */ + protected void createOutputTestDirectory(String suffixPath) { + this.outputTestDirectory = new File(this.outputRootDirectoryPath.toFile(), suffixPath); + if (!this.outputTestDirectory.exists()) { + this.outputTestDirectory.mkdirs(); + } + } + /* + * Write given source test files in current output sub-directory. + * Use test name for this sub-directory name (ie. test001, test002, etc...) + */ + protected void writeFiles(String[] testFiles) { + createOutputTestDirectory(testName()); + + // Write each given test file + for (int i = 0, length = testFiles.length; i < length; ) { + String fileName = testFiles[i++]; + String contents = testFiles[i++]; + File file = new File(this.outputTestDirectory, fileName); + if (fileName.lastIndexOf('/') >= 0) { + File dir = file.getParentFile(); + if (!dir.exists()) { + dir.mkdirs(); + } + } + Util.writeToFile(contents, file.getPath()); + } + } + + // Summary display + // Used by AbstractRegressionTest for javac comparison tests + protected static Map TESTS_COUNTERS = new HashMap(); +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/CompilerTestSetup.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/CompilerTestSetup.java new file mode 100644 index 0000000000..d0da5697ff --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/CompilerTestSetup.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2000, 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.util; + +import java.util.Enumeration; + +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; + +import junit.framework.TestResult; +import junit.framework.TestSuite; + +@SuppressWarnings({ "rawtypes" }) +public class CompilerTestSetup extends TestSuite { + + long complianceLevel; + + public CompilerTestSetup(long complianceLevel) { + super(CompilerOptions.versionFromJdkLevel(complianceLevel)); + this.complianceLevel = complianceLevel; + } + + protected void initTest(Object test) { + if (test instanceof AbstractCompilerTest) { + AbstractCompilerTest compilerTest = (AbstractCompilerTest)test; + compilerTest.initialize(this); + return; + } + if (test instanceof TestSuite) { + TestSuite testSuite = (TestSuite)test; + Enumeration evaluationTestClassTests = testSuite.tests(); + while (evaluationTestClassTests.hasMoreElements()) { + initTest(evaluationTestClassTests.nextElement()); + } + return; + } + if (test instanceof Enumeration) { + Enumeration evaluationTestClassTests = (Enumeration) test; + while (evaluationTestClassTests.hasMoreElements()) { + initTest(evaluationTestClassTests.nextElement()); + } + return; + } + } + + public void run(TestResult result) { + try { + setUp(); + super.run(result); + } finally { + tearDown(); + } + } + + protected void setUp() { + // Init wrapped suite + initTest(tests()); + } + + protected void tearDown() { + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java new file mode 100644 index 0000000000..22678bd54d --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java @@ -0,0 +1,675 @@ +/******************************************************************************* + * Copyright (c) 2000, 2012 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.util; + +import org.eclipse.jdt.core.compiler.batch.BatchCompiler; +import org.eclipse.jdt.core.tests.runtime.*; +import java.io.*; +import java.net.*; +import java.util.*; +/** + * Verifies that the .class files resulting from a compilation can be loaded + * in a VM and that they can be run. + */ +public class TestVerifier { + public String failureReason; + + boolean reuseVM = true; + String[] classpathCache; + LocalVirtualMachine vm; + StringBuffer outputBuffer; + StringBuffer errorBuffer; + Socket socket; +public TestVerifier(boolean reuseVM) { + this.reuseVM = reuseVM; +} +private boolean checkBuffers(String outputString, String errorString, + String sourceFileName, String expectedOutputString, String expectedErrorStringStart) { + boolean didMatchExpectation = true; + String platformIndependantString; + this.failureReason = null; + if (expectedOutputString != null) { + platformIndependantString = Util.convertToIndependantLineDelimiter(outputString.trim()); + if (!Util.convertToIndependantLineDelimiter(expectedOutputString).equals(platformIndependantString)) { + System.out.println(Util.displayString(platformIndependantString, 2)); + this.failureReason = + "Unexpected output running resulting class file for " + + sourceFileName + + ":\n" + + "--[START]--\n" + + outputString + + "---[END]---\n"; + didMatchExpectation = false; + } + } + String trimmedErrorString = errorString.trim().replaceFirst("^Exception in thread \"main\" ", ""); + if (expectedErrorStringStart != null) { + platformIndependantString = Util.convertToIndependantLineDelimiter(trimmedErrorString); + if (expectedErrorStringStart.length() == 0 && platformIndependantString.length() > 0 || + !platformIndependantString.startsWith(Util.convertToIndependantLineDelimiter(expectedErrorStringStart))) { + /* + * This is an opportunistic heuristic for error strings comparison: + * - null means skip test; + * - empty means exactly empty; + * - other means starts with. + * If this became insufficient, we could envision using specific + * matchers for specific needs. + */ + System.out.println(Util.displayString(platformIndependantString, 2)); + this.failureReason = + "Unexpected error running resulting class file for " + + sourceFileName + + ":\n" + + "--[START]--\n" + + errorString + + "---[END]---\n"; + didMatchExpectation = false; + } + } else if (trimmedErrorString.length() != 0){ + platformIndependantString = Util.convertToIndependantLineDelimiter(trimmedErrorString); + System.out.println(Util.displayString(platformIndependantString, 2)); + this.failureReason = + "Unexpected error running resulting class file for " + + sourceFileName + + ":\n" + + "--[START]--\n" + + errorString + + "---[END]---\n"; + didMatchExpectation = false; + } + return didMatchExpectation; +} + +private void compileVerifyTests(String verifierDir) { + String fullyQualifiedName = VerifyTests.class.getName(); + + int lastDot = fullyQualifiedName.lastIndexOf('.'); + String packageName = fullyQualifiedName.substring(0, lastDot); + String simpleName = fullyQualifiedName.substring(lastDot + 1); + + String dirName = verifierDir.replace('\\', '/') + "/" + packageName.replace('.', '/'); + File dir = new File(dirName.replace('/', File.separatorChar)); + if (!dir.exists() && !dir.mkdirs()) { + System.out.println("Could not create " + dir); + return; + } + String fileName = dir + File.separator + simpleName + ".java"; + Util.writeToFile(getVerifyTestsCode(), fileName); + BatchCompiler.compile("\"" + fileName + "\" -d \"" + verifierDir + "\" -warn:-resource -classpath \"" + Util.getJavaClassLibsAsString() + "\"", new PrintWriter(System.out), new PrintWriter(System.err), null/*progress*/); +} +public void execute(String className, String[] classpaths) { + this.outputBuffer = new StringBuffer(); + this.errorBuffer = new StringBuffer(); + + launchAndRun(className, classpaths, null, null); +} +@Override @SuppressWarnings("deprecation") +protected void finalize() throws Throwable { + shutDown(); +} +public String getExecutionOutput(){ + return this.outputBuffer.toString(); +} + +public String getExecutionError(){ + return this.errorBuffer.toString(); +} +/** + * Returns the code of the VerifyTests class. + * + * IMPORTANT NOTE: DO NOTE EDIT BUT GENERATE INSTEAD (see below) + * + * To generate: + * - export VerifyTests.java to d:/temp + * - inspect org.eclipse.jdt.core.tests.util.Util.fileContentToDisplayString("d:/temp/VerifyTests.java", 2, true) + */ +private String getVerifyTestsCode() { + return + "/*******************************************************************************\n" + + " * Copyright (c) 2000, 2017 IBM Corporation and others.\n" + + " * All rights reserved. This program and the accompanying materials\n" + + " * are made available under the terms of the Eclipse Public License v1.0\n" + + " * which accompanies this distribution, and is available at\n" + + " * http://www.eclipse.org/legal/epl-v10.html\n" + + " *\n" + + " * Contributors:\n" + + " * IBM Corporation - initial API and implementation\n" + + " *******************************************************************************/\n" + + "package org.eclipse.jdt.core.tests.util;\n" + + "\n" + + "import java.io.DataInputStream;\n" + + "import java.io.DataOutputStream;\n" + + "import java.io.File;\n" + + "import java.io.FileInputStream;\n" + + "import java.io.FileNotFoundException;\n" + + "import java.io.IOException;\n" + + "import java.io.InputStream;\n" + + "import java.lang.reflect.InvocationTargetException;\n" + + "import java.lang.reflect.Method;\n" + + "import java.net.Socket;\n" + + "import java.util.StringTokenizer;\n" + + "\n" + + "/******************************************************\n" + + " *\n" + + " * IMPORTANT NOTE: If modifying this class, copy the source to TestVerifier#getVerifyTestsCode()\n" + + " * (see this method for details)\n" + + " *\n" + + " ******************************************************/\n" + + "\n" + + "public class VerifyTests {\n" + + " int portNumber;\n" + + " Socket socket;\n" + + "\n" + + "/**\n" + + " * NOTE: Code copied from junit.util.TestCaseClassLoader.\n" + + " *\n" + + " * A custom class loader which enables the reloading\n" + + " * of classes for each test run. The class loader\n" + + " * can be configured with a list of package paths that\n" + + " * should be excluded from loading. The loading\n" + + " * of these packages is delegated to the system class\n" + + " * loader. They will be shared across test runs.\n" + + " *

    \n" + + " * The list of excluded package paths is specified in\n" + + " * a properties file \"excluded.properties\" that is located in\n" + + " * the same place as the TestCaseClassLoader class.\n" + + " *

    \n" + + " * Known limitation: the VerifyClassLoader cannot load classes\n" + + " * from jar files.\n" + + " */\n" + + "\n" + + "\n" + + "public class VerifyClassLoader extends ClassLoader {\n" + + " /** scanned class path */\n" + + " private String[] pathItems;\n" + + "\n" + + " /** excluded paths */\n" + + " private String[] excluded= {\"groovy\",\"org.codehaus.groovy\"};\n" + + "\n" + + " /**\n" + + " * Constructs a VerifyClassLoader. It scans the class path\n" + + " * and the excluded package paths\n" + + " */\n" + + " public VerifyClassLoader() {\n" + + " super();\n" + + " String classPath= System.getProperty(\"java.class.path\");\n" + + " String separator= System.getProperty(\"path.separator\");\n" + + "\n" + + " // first pass: count elements\n" + + " StringTokenizer st= new StringTokenizer(classPath, separator);\n" + + " int i= 0;\n" + + " while (st.hasMoreTokens()) {\n" + + " st.nextToken();\n" + + " i++;\n" + + " }\n" + + " // second pass: split\n" + + " this.pathItems= new String[i];\n" + + " st= new StringTokenizer(classPath, separator);\n" + + " i= 0;\n" + + " while (st.hasMoreTokens()) {\n" + + " this.pathItems[i++]= st.nextToken();\n" + + " }\n" + + "\n" + + " }\n" + + " public java.net.URL getResource(String name) {\n" + + " return ClassLoader.getSystemResource(name);\n" + + " }\n" + + " public InputStream getResourceAsStream(String name) {\n" + + " return ClassLoader.getSystemResourceAsStream(name);\n" + + " }\n" + + " protected boolean isExcluded(String name) {\n" + + " // exclude the \"java\" packages.\n" + + " // They always need to be excluded so that they are loaded by the system class loader\n" + + " if (name.startsWith(\"java\") || name.startsWith(\"[Ljava\"))\n" + + " return true;\n" + + "\n" + + " // exclude the user defined package paths\n" + + " for (int i= 0; i < this.excluded.length; i++) {\n" + + " if (name.startsWith(this.excluded[i])) {\n" + + " return true;\n" + + " }\n" + + " }\n" + + " return false;\n" + + " }\n" + + " public synchronized Class loadClass(String name, boolean resolve)\n" + + " throws ClassNotFoundException {\n" + + "\n" + + " Class c= findLoadedClass(name);\n" + + " if (c != null)\n" + + " return c;\n" + + " //\n" + + " // Delegate the loading of excluded classes to the\n" + + " // standard class loader.\n" + + " //\n" + + " if (isExcluded(name)) {\n" + + " try {\n" + + " c= findSystemClass(name);\n" + + " return c;\n" + + " } catch (ClassNotFoundException e) {\n" + + " // keep searching\n" + + " }\n" + + " }\n" + + " File file= locate(name);\n" + + " if (file == null)\n" + + " throw new ClassNotFoundException(name);\n" + + " byte data[]= loadClassData(file);\n" + + " c= defineClass(name, data, 0, data.length);\n" + + " if (resolve)\n" + + " resolveClass(c);\n" + + " return c;\n" + + " }\n" + + " private byte[] loadClassData(File f) throws ClassNotFoundException {\n" + + " FileInputStream stream = null;\n" + + " try {\n" + + " //System.out.println(\"loading: \"+f.getPath());\n" + + " stream = new FileInputStream(f);\n" + + "\n" + + " try {\n" + + " byte[] b= new byte[stream.available()];\n" + + " stream.read(b);\n" + + " return b;\n" + + " }\n" + + " catch (IOException e) {\n" + + " throw new ClassNotFoundException();\n" + + " }\n" + + " }\n" + + " catch (FileNotFoundException e) {\n" + + " throw new ClassNotFoundException();\n" + + " } finally {\n" + + " if (stream != null) {\n" + + " try {\n" + + " stream.close();\n" + + " } catch (IOException e) {\n" + + " /* ignore */\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " /**\n" + + " * Locate the given file.\n" + + " * @return Returns null if file couldn't be found.\n" + + " */\n" + + " private File locate(String fileName) {\n" + + " if (fileName != null) {\n" + + " fileName= fileName.replace('.', '/')+\".class\";\n" + + " File path= null;\n" + + " for (int i= 0; i < this.pathItems.length; i++) {\n" + + " path= new File(this.pathItems[i], fileName);\n" + + " if (path.exists())\n" + + " return path;\n" + + " }\n" + + " }\n" + + " return null;\n" + + " }\n" + + "}\n" + + "\n" + + "public void loadAndRun(String className) throws Throwable {\n" + + " //System.out.println(\"Loading \" + className + \"...\");\n" + + " Class testClass = new VerifyClassLoader().loadClass(className);\n" + + " //System.out.println(\"Loaded \" + className);\n" + + " try {\n" + + " Method main = testClass.getMethod(\"main\", new Class[] {String[].class});\n" + + " //System.out.println(\"Running \" + className);\n" + + " main.invoke(null, new Object[] {new String[] {}});\n" + + " //System.out.println(\"Finished running \" + className);\n" + + " } catch (NoSuchMethodException e) {\n" + + " return;\n" + + " } catch (InvocationTargetException e) {\n" + + " throw e.getTargetException();\n" + + " }\n" + + "}\n" + + "public static void main(String[] args) throws IOException {\n" + + " VerifyTests verify = new VerifyTests();\n" + + " verify.portNumber = Integer.parseInt(args[0]);\n" + + " verify.run();\n" + + "}\n" + + "public void run() throws IOException {\n" + + " this.socket = new Socket(\"localhost\", this.portNumber);\n" + + " this.socket.setTcpNoDelay(true);\n" + + "\n" + + " DataInputStream in = new DataInputStream(this.socket.getInputStream());\n" + + " final DataOutputStream out = new DataOutputStream(this.socket.getOutputStream());\n" + + " while (true) {\n" + + " final String className = in.readUTF();\n" + + " Thread thread = new Thread() {\n" + + " public void run() {\n" + + " try {\n" + + " loadAndRun(className);\n" + + " out.writeBoolean(true);\n" + + " System.err.println(VerifyTests.class.getName());\n" + + " System.out.println(VerifyTests.class.getName());\n" + + " } catch (Throwable e) {\n" + + " e.printStackTrace();\n" + + " try {\n" + + " System.err.println(VerifyTests.class.getName());\n" + + " System.out.println(VerifyTests.class.getName());\n" + + " out.writeBoolean(false);\n" + + " } catch (IOException e1) {\n" + + " e1.printStackTrace();\n" + + " }\n" + + " }\n" + + " try {\n" + + " out.flush();\n" + + " } catch (IOException e) {\n" + + " e.printStackTrace();\n" + + " }\n" + + " }\n" + + " };\n" + + " thread.start();\n" + + " }\n" + + "}\n" + + "}"; +} +private String[] getVMArguments(String[] vmArguments) { + List completeVmArguments = new ArrayList(); + + if (Float.parseFloat(System.getProperty("java.specification.version")) > 8) { + Collections.addAll(completeVmArguments, "--add-opens", "java.base/java.io=ALL-UNNAMED"); + Collections.addAll(completeVmArguments, "--add-opens", "java.base/java.net=ALL-UNNAMED"); + Collections.addAll(completeVmArguments, "--add-opens", "java.base/java.lang=ALL-UNNAMED"); + Collections.addAll(completeVmArguments, "--add-opens", "java.base/java.math=ALL-UNNAMED"); + Collections.addAll(completeVmArguments, "--add-opens", "java.base/java.text=ALL-UNNAMED"); + Collections.addAll(completeVmArguments, "--add-opens", "java.base/java.util=ALL-UNNAMED"); + Collections.addAll(completeVmArguments, "--add-opens", "java.base/java.util.regex=ALL-UNNAMED"); + Collections.addAll(completeVmArguments, "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED"); + Collections.addAll(completeVmArguments, "--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED"); + } + + if (vmArguments != null) { + Collections.addAll(completeVmArguments, vmArguments); + } + completeVmArguments.add("-verify"); + + return completeVmArguments.toArray(new String[0]); +} +private void launchAndRun(String className, String[] classpaths, String[] programArguments, String[] vmArguments) { + // we won't reuse the vm, shut the existing one if running + if (this.vm != null) { + try { + this.vm.shutDown(); + } catch (TargetException e) { + } + } + this.classpathCache = null; + + // launch a new one + LocalVMLauncher launcher = LocalVMLauncher.getLauncher(); + launcher.setClassPath(classpaths); + launcher.setVMPath(Util.getJREDirectory()); + launcher.setVMArguments(getVMArguments(vmArguments)); + launcher.setProgramClass(className); + launcher.setProgramArguments(programArguments); + Thread outputThread; + Thread errorThread; + try { + this.vm = launcher.launch(); + final InputStream input = this.vm.getInputStream(); + outputThread = new Thread(new Runnable() { + @Override + public void run() { + try { + int c = input.read(); + while (c != -1) { + TestVerifier.this.outputBuffer.append((char) c); + c = input.read(); + } + } catch(IOException e) { + } + } + }); + final InputStream errorStream = this.vm.getErrorStream(); + errorThread = new Thread(new Runnable() { + @Override + public void run() { + try { + int c = errorStream.read(); + while (c != -1) { + TestVerifier.this.errorBuffer.append((char) c); + c = errorStream.read(); + } + } catch(IOException e) { + } + } + }); + outputThread.start(); + errorThread.start(); + } catch(TargetException e) { + throw new Error(e.getMessage()); + } + + // wait for vm to shut down by itself + try { + outputThread.join(10000); // we shut VMs down forcefully downstream, + errorThread.join(10000); // hence let's have some slack here + } catch (InterruptedException e) { + } +} +private void launchVerifyTestsIfNeeded(String[] classpaths, String[] vmArguments) { + // determine if we can reuse the vm + if (this.vm != null && this.vm.isRunning() && this.classpathCache != null) { + if (classpaths.length == this.classpathCache.length) { + boolean sameClasspaths = true; + for (int i = 0; i < classpaths.length; i++) { + if (!this.classpathCache[i].equals(classpaths[i])) { + sameClasspaths = false; + break; + } + } + if (sameClasspaths) { + return; + } + } + } + + // we could not reuse the vm, shut the existing one if running + if (this.vm != null) { + try { + this.vm.shutDown(); + } catch (TargetException e) { + } + } + + this.classpathCache = classpaths; + + // launch a new one + LocalVMLauncher launcher = LocalVMLauncher.getLauncher(); + int length = classpaths.length; + String[] cp = new String[length + 1]; + System.arraycopy(classpaths, 0, cp, 0, length); + String verifierDir = Util.getOutputDirectory() + File.separator + "verifier"; + compileVerifyTests(verifierDir); + cp[length] = verifierDir; + launcher.setClassPath(cp); + launcher.setVMPath(Util.getJREDirectory()); + launcher.setVMArguments(getVMArguments(vmArguments)); + launcher.setProgramClass(VerifyTests.class.getName()); + try (ServerSocket server = new ServerSocket(0)) { + int portNumber = server.getLocalPort(); + + launcher.setProgramArguments(new String[] {Integer.toString(portNumber)}); + try { + this.vm = launcher.launch(); + final InputStream input = this.vm.getInputStream(); + Thread outputThread = new Thread(new Runnable() { + @Override + public void run() { + try { + int c = input.read(); + while (c != -1) { + TestVerifier.this.outputBuffer.append((char) c); + c = input.read(); + } + } catch(IOException ioEx) { + ioEx.printStackTrace(); + } finally { + try { + input.close(); + } catch (IOException e) {} + } + } + }); + final InputStream errorStream = this.vm.getErrorStream(); + Thread errorThread = new Thread(new Runnable() { + @Override + public void run() { + try { + int c = errorStream.read(); + while (c != -1) { + TestVerifier.this.errorBuffer.append((char) c); + c = errorStream.read(); + } + } catch(IOException ioEx) { + ioEx.printStackTrace(); + } finally { + try { + errorStream.close(); + } catch (IOException e) {} + } + } + }); + outputThread.start(); + errorThread.start(); + } catch(TargetException e) { + e.printStackTrace(); + throw new Error(e.getMessage()); + } + + // connect to the vm + this.socket = null; + boolean isVMRunning = false; + do { + try { + this.socket = server.accept(); + this.socket.setTcpNoDelay(true); + break; + } catch (UnknownHostException e) { + } catch (IOException e) { + } + if (this.socket == null) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + isVMRunning = this.vm.isRunning(); + } + } while (this.socket == null && isVMRunning); + } catch (IOException e) { + e.printStackTrace(); + throw new Error(e.getMessage()); + } +} +/** + * Loads and runs the given class. + * Return whether no exception was thrown while running the class. + */ +private boolean loadAndRun(String className) { + if (this.socket != null) { + try { + DataOutputStream out = new DataOutputStream(this.socket.getOutputStream()); + out.writeUTF(className); + DataInputStream in = new DataInputStream(this.socket.getInputStream()); + try { + boolean result = in.readBoolean(); + waitForFullBuffers(); + return result; + } catch (SocketException e) { + // connection was reset because target program has exited + return true; + } + } catch (IOException e) { + e.printStackTrace(); + } + } + return true; +} +public void shutDown() { + // Close the socket first so that the OS resource has a chance to be freed. + if (this.socket != null) { + try { + this.socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + // Wait for the vm to shut down by itself for 2 seconds. If not succesfull, force the shut down. + if (this.vm != null) { + try { + int retry = 0; + while (this.vm.isRunning() && (++retry < 20)) { + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + } + if (this.vm.isRunning()) { + this.vm.shutDown(); + } + } catch (TargetException e) { + e.printStackTrace(); + } + } +} +/** + * Verify that the class files created for the given test file can be loaded by + * a virtual machine. + */ +public boolean verifyClassFiles(String sourceFilePath, String className, String expectedSuccessOutputString, String[] classpaths) { + return verifyClassFiles(sourceFilePath, className, expectedSuccessOutputString, "", classpaths, null, null); +} +/** + * Verify that the class files created for the given test file can be loaded by + * a virtual machine. + */ +public boolean verifyClassFiles(String sourceFilePath, String className, String expectedSuccessOutputString, String[] classpaths, String[] programArguments, String[] vmArguments) { + return verifyClassFiles(sourceFilePath, className, expectedSuccessOutputString, "", classpaths, programArguments, vmArguments); +} +public boolean verifyClassFiles(String sourceFilePath, String className, String expectedOutputString, + String expectedErrorStringStart, String[] classpaths, String[] programArguments, String[] vmArguments) { + this.outputBuffer = new StringBuffer(); + this.errorBuffer = new StringBuffer(); + if (this.reuseVM && programArguments == null) { + launchVerifyTestsIfNeeded(classpaths, vmArguments); + loadAndRun(className); + } else { + launchAndRun(className, classpaths, programArguments, vmArguments); + } + + this.failureReason = null; + return checkBuffers(this.outputBuffer.toString(), this.errorBuffer.toString(), sourceFilePath, expectedOutputString, expectedErrorStringStart); +} + +/** + * Wait until there is nothing more to read from the stdout or sterr. + */ +private void waitForFullBuffers() { + String endString = VerifyTests.class.getName(); + int count = 60; + int waitMs = 1; + int errorEndStringStart = this.errorBuffer.toString().indexOf(endString); + int outputEndStringStart = this.outputBuffer.toString().indexOf(endString); + while (errorEndStringStart == -1 || outputEndStringStart == -1) { + try { + Thread.sleep(waitMs); + } catch (InterruptedException e) { + } finally { + if(waitMs < 100) waitMs *= 2; + } + if (--count == 0) return; + errorEndStringStart = this.errorBuffer.toString().indexOf(endString); + outputEndStringStart = this.outputBuffer.toString().indexOf(endString); + } + this.errorBuffer.setLength(errorEndStringStart); + this.outputBuffer.setLength(outputEndStringStart); +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java new file mode 100644 index 0000000000..b9f9454e90 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java @@ -0,0 +1,1606 @@ +/******************************************************************************* + * Copyright (c) 2000, 2020 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Nina Rinskaya + * Fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=172820. + *******************************************************************************/ +package org.eclipse.jdt.core.tests.util; + +import java.io.*; +import java.net.ServerSocket; +import java.nio.file.Files; +import java.util.*; +import java.util.zip.*; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.core.tests.compiler.regression.Requestor; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.Compiler; +import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; +import org.eclipse.jdt.internal.compiler.IProblemFactory; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.batch.BasicModule; +import org.eclipse.jdt.internal.compiler.batch.CompilationUnit; +import org.eclipse.jdt.internal.compiler.batch.FileSystem; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class Util { + // Trace for delete operation + /* + * Maximum time wasted repeating delete operations while running JDT/Core tests. + */ + private static int DELETE_MAX_TIME = 0; + /** + * Trace deletion operations while running JDT/Core tests. + */ + public static boolean DELETE_DEBUG = false; + /** + * Maximum of time in ms to wait in deletion operation while running JDT/Core tests. + * Default is 10 seconds. This number cannot exceed 1 minute (ie. 60000). + *
    + * To avoid too many loops while waiting, the ten first ones are done waiting + * 10ms before repeating, the ten loops after are done waiting 100ms and + * the other loops are done waiting 1s... + *
    + * If you wish to avoid retrying file deletion during tests altogether, activate + * {@link #SKIP_RETRY_DELETE_FILE}. + */ + public static int DELETE_MAX_WAIT = 10000; + /** + * If you wish to avoid retrying file deletion during tests altogether, set the value to true. + * Then each undeleted file will be registered for deletion during JVM shutdown via + * {@link File#deleteOnExit()} instead of waiting for {@link #DELETE_MAX_WAIT} ms. + *
    + * Please note: This flag only influences the behaviour of {@link #delete(File)} and + * {@link #delete(String)}. It is being ignored by {@link #delete(IResource)}. + */ + public static boolean SKIP_RETRY_DELETE_FILE = false; + + private static final boolean DEBUG = false; + /** + * Initially, output directory was located in System.getProperty("java.io.tmpdir")+"\comptest". + * To allow user to run several compiler tests at the same time, main output directory + * is now located in a sub-directory of "comptest" which name is "run."+System.currentMilliseconds. + * + * @see #DELAY_BEFORE_CLEAN_PREVIOUS + */ + private final static String OUTPUT_DIRECTORY; + /** + * Let user specify the delay in hours before output directories are removed from file system + * while starting a new test run. Default value is 2 hours. + *

    + * Note that this value may be a float and so have time less than one hour. + * If value is 0 or negative, then all previous run directories will be removed... + * + * @see #OUTPUT_DIRECTORY + */ + private final static String DELAY_BEFORE_CLEAN_PREVIOUS = System.getProperty("delay"); + /* + * Static initializer to clean directories created while running previous test suites. + */ + static { + // Get delay for cleaning sub-directories + long millisecondsPerHour = 1000L * 3600L; + long delay = millisecondsPerHour * 2; // default is to keep previous run directories for 2 hours + try { + if (DELAY_BEFORE_CLEAN_PREVIOUS != null) { + float hours = Float.parseFloat(DELAY_BEFORE_CLEAN_PREVIOUS); + delay = (int) (millisecondsPerHour * hours); + } + } + catch (NumberFormatException nfe) { + // use default + } + + // Get output directory root from system properties + String container = System.getProperty("jdt.test.output_directory"); + if (container == null){ + container = System.getProperty("java.io.tmpdir"); + } + if (container == null) { + container = "."; // use current directory + } + + // Get file for root directory + if (Character.isLowerCase(container.charAt(0)) && container.charAt(1) == ':') { + container = Character.toUpperCase(container.charAt(0)) + container.substring(1); + } + File dir = new File(new File(container), "comptest"); + + // If root directory already exists, clean it + if (dir.exists()) { + long now = System.currentTimeMillis(); + if ((now - dir.lastModified()) > delay) { + // remove all directory content + flushDirectoryContent(dir); + } else { + // remove only old sub-dirs + File[] testDirs = dir.listFiles(); + for (int i=0,l=testDirs.length; i delay) { + delete(testDirs[i]); + } + } + } + } + } + + // Computed test run directory name based on current time + File dateDir = new File(dir, "run."+System.currentTimeMillis()); + String pathDir = null; + try { + pathDir = dateDir.getCanonicalPath(); + } catch (IOException e) { + pathDir = dateDir.getAbsolutePath(); + } + OUTPUT_DIRECTORY = pathDir; + } + +public static void appendProblem(StringBuffer problems, IProblem problem, char[] source, int problemCount) { + problems.append(problemCount + (problem.isError() ? ". ERROR" : problem.isWarning() ? ". WARNING" : ". INFO")); + problems.append(" in " + new String(problem.getOriginatingFileName())); + if (source != null) { + problems.append(((DefaultProblem)problem).errorReportSource(source)); + } + problems.append("\n"); + problems.append(problem.getMessage()); + problems.append("\n"); +} + +public static CompilationUnit[] compilationUnits(String[] testFiles) { + int length = testFiles.length / 2; + CompilationUnit[] result = new CompilationUnit[length]; + int index = 0; + for (int i = 0; i < length; i++) { + result[i] = new CompilationUnit(testFiles[index + 1].toCharArray(), testFiles[index], null); + index += 2; + } + return result; +} +// -------- +// reduced version of org.eclipse.jdt.internal.compiler.batch.Main.getCompilationUnits() +// (need to associate ordinary compilation units with preceding modular compilation units) +public static CompilationUnit[] compilationUnits9(String[] testFiles, String compliance, + IErrorHandlingPolicy errorHandlingPolicy, IProblemFactory problemFactory) +{ + int fileCount = testFiles.length / 2; + CompilationUnit[] units = new CompilationUnit[fileCount]; + + String modName = null; + CompilationUnit modCU = null; + for (int i = 0; i < fileCount; i++) { + String fileName = testFiles[i*2]; + boolean isModuleInfo = fileName.endsWith(TypeConstants.MODULE_INFO_FILE_NAME_STRING); + units[i] = new CompilationUnit(testFiles[i*2+1].toCharArray(), fileName, null, "", false, modName); + if (isModuleInfo) { + IModule mod = extractModuleDesc(testFiles[i*2+1], compliance, errorHandlingPolicy, problemFactory); + if (mod != null) { + modName = String.valueOf(mod.name()); + modCU = units[i]; + modCU.module = mod.name(); + } + } else { + if (modCU != null) + units[i].module = modCU.getModuleName(); + } + } + return units; +} +private static IModule extractModuleDesc(String contents, String compliance, + IErrorHandlingPolicy errorHandlingPolicy, IProblemFactory problemFactory) +{ + Map opts = new HashMap<>(); + opts.put(CompilerOptions.OPTION_Source, compliance); + Parser parser = new Parser(new ProblemReporter(errorHandlingPolicy, new CompilerOptions(opts), problemFactory), false); + ICompilationUnit cu = new CompilationUnit(contents.toCharArray(), "module-info.java", null); + CompilationResult compilationResult = new CompilationResult(cu, 0, 1, 10); + CompilationUnitDeclaration unit = parser.parse(cu, compilationResult); + if (unit.isModuleInfo() && unit.moduleDeclaration != null) { + return new BasicModule(unit.moduleDeclaration, null); + } + return null; +} +//-------- +public static void compile(String[] pathsAndContents, Map options, String outputPath) { + compile(pathsAndContents, options, null, outputPath); +} +public static void compile(String[] pathsAndContents, Map options, String[] classpath, String outputPath) { + IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); + Requestor requestor = + new Requestor( + false, + null /*no custom requestor*/, + false, /* show category */ + false /* show warning token*/); + requestor.outputPath = outputPath.endsWith(File.separator) ? outputPath : outputPath + File.separator; + + String[] classLibs = getJavaClassLibs(); + if (classpath != null) { + int length = classpath.length; + int classLibsLength = classLibs.length; + System.arraycopy(classpath, 0, classpath = new String[length + classLibsLength], 0, length); + System.arraycopy(classLibs, 0, classpath, length, classLibsLength); + } else { + classpath = classLibs; + } + + FileSystem nameEnvironment = new FileSystem(classpath, new String[] {}, null); + if (CompilerOptions.versionToJdkLevel((String) options.get(CompilerOptions.OPTION_Compliance)) >= ClassFileConstants.JDK9) { + nameEnvironment.scanForModules(createParser9()); + } + IErrorHandlingPolicy errorHandlingPolicy = + new IErrorHandlingPolicy() { + public boolean proceedOnErrors() { + return true; + } + public boolean stopOnFirstError() { + return false; + } + public boolean ignoreAllErrors() { + return false; + } + }; + CompilerOptions compilerOptions = new CompilerOptions(options); + compilerOptions.performMethodsFullRecovery = false; + compilerOptions.performStatementsRecovery = false; + Compiler batchCompiler = + new Compiler( + nameEnvironment, + errorHandlingPolicy, + compilerOptions, + requestor, + problemFactory); + batchCompiler.options.produceReferenceInfo = true; + CompilationUnit[] compilationUnits; + if (compilerOptions.complianceLevel >= ClassFileConstants.JDK9) { + String compliance = (String)options.get(CompilerOptions.OPTION_Compliance); + compilationUnits = compilationUnits9(pathsAndContents, compliance, errorHandlingPolicy, problemFactory); + } else { + compilationUnits = compilationUnits(pathsAndContents); + } + batchCompiler.compile(compilationUnits); // compile all files together + // cleanup + nameEnvironment.cleanup(); + if (requestor.hasErrors) + System.err.print(requestor.problemLog); // problem log empty if no problems +} +private static Parser createParser9() { + Map opts = new HashMap(); + opts.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); + return new Parser( + new ProblemReporter(new IErrorHandlingPolicy() { + public boolean stopOnFirstError() { + return false; + } + public boolean proceedOnErrors() { + return true; + } + public boolean ignoreAllErrors() { + return false; + } + }, + new CompilerOptions(opts), + new DefaultProblemFactory(Locale.getDefault())), + false); +} +public static String[] concatWithClassLibs(String[] classpaths, boolean inFront) { + String[] classLibs = getJavaClassLibs(); + if (classpaths == null) return classLibs; + final int classLibsLength = classLibs.length; + final int classpathsLength = classpaths.length; + String[] defaultClassPaths = new String[classLibsLength + classpathsLength]; + if (inFront) { + System.arraycopy(classLibs, 0, defaultClassPaths, classpathsLength, classLibsLength); + System.arraycopy(classpaths, 0, defaultClassPaths, 0, classpathsLength); + } else { + System.arraycopy(classLibs, 0, defaultClassPaths, 0, classLibsLength); + System.arraycopy(classpaths, 0, defaultClassPaths, classLibsLength, classpathsLength); + } + for (int i = 0; i < classpathsLength; i++) { + File file = new File(classpaths[i]); + if (!file.exists()) { + file.mkdirs(); + } + } + return defaultClassPaths; +} +public static String[] concatWithClassLibs(String classpath, boolean inFront) { + String[] classLibs = getJavaClassLibs(); + final int length = classLibs.length; + File dir = new File(classpath); + if (!dir.exists()) + dir.mkdirs(); + String[] defaultClassPaths = new String[length + 1]; + if (inFront) { + System.arraycopy(classLibs, 0, defaultClassPaths, 1, length); + defaultClassPaths[0] = classpath; + } else { + System.arraycopy(classLibs, 0, defaultClassPaths, 0, length); + defaultClassPaths[length] = classpath; + } + return defaultClassPaths; +} +public static String convertToIndependantLineDelimiter(String source) { + if (source == null) return ""; + if (source.indexOf('\n') == -1 && source.indexOf('\r') == -1) return source; + StringBuilder buffer = new StringBuilder(); + for (int i = 0, length = source.length(); i < length; i++) { + char car = source.charAt(i); + if (car == '\r') { + buffer.append('\n'); + if (i < length-1 && source.charAt(i+1) == '\n') { + i++; // skip \n after \r + } + } else { + buffer.append(car); + } + } + return buffer.toString(); +} +/** + * Copy the given source (a file or a directory that must exists) to the given destination (a directory that must exists). + */ +public static void copy(String sourcePath, String destPath) { + sourcePath = toNativePath(sourcePath); + destPath = toNativePath(destPath); + File source = new File(sourcePath); + if (!source.exists()) return; + File dest = new File(destPath); + if (!dest.exists()) return; + if (source.isDirectory()) { + String[] files = source.list(); + if (files != null) { + for (int i = 0; i < files.length; i++) { + String file = files[i]; + File sourceFile = new File(source, file); + if (sourceFile.isDirectory()) { + File destSubDir = new File(dest, file); + destSubDir.mkdir(); + copy(sourceFile.getPath(), destSubDir.getPath()); + } else { + copy(sourceFile.getPath(), dest.getPath()); + } + } + } + } else { + FileInputStream in = null; + FileOutputStream out = null; + try { + in = new FileInputStream(source); + File destFile = new File(dest, source.getName()); + if (destFile.exists()) { + if (!Util.delete(destFile)) { + throw new IOException(destFile + " is in use"); + } + } + out = new FileOutputStream(destFile); + int bufferLength = 1024; + byte[] buffer = new byte[bufferLength]; + int read = 0; + while (read != -1) { + read = in.read(buffer, 0, bufferLength); + if (read != -1) { + out.write(buffer, 0, read); + } + } + } catch (IOException e) { + throw new Error(e.toString()); + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + } + } + if (out != null) { + try { + out.close(); + } catch (IOException e) { + } + } + } + } +} +public static void createFile(String path, String contents) throws IOException { + FileOutputStream output = new FileOutputStream(path); + try { + output.write(contents.getBytes()); + } finally { + output.close(); + } +} +public static void createClassFolder(String[] pathsAndContents, String folderPath, String compliance) throws IOException { + File classesDir = new File(folderPath); + flushDirectoryContent(classesDir); + compile(pathsAndContents, getCompileOptions(compliance), folderPath); +} +public static void createEmptyJar(String jarPath, String compliance) throws IOException { + org.eclipse.jdt.core.tests.util.Util.createJar( + null, + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n", + }, + jarPath, + null, + compliance); +} +public static void createJar(String[] pathsAndContents, Map options, String jarPath) throws IOException { + createJar(pathsAndContents, null, options, null, jarPath); +} +public static void createJar(String[] pathsAndContents, String[] extraPathsAndContents, Map options, String[] classpath, String jarPath) throws IOException { + String classesPath = getOutputDirectory() + File.separator + "classes"; + File classesDir = new File(classesPath); + flushDirectoryContent(classesDir); + if (pathsAndContents != null) { + compile(pathsAndContents, options, classpath, classesPath); + } + if (extraPathsAndContents != null) { + for (int i = 0, l = extraPathsAndContents == null ? 0 : extraPathsAndContents.length; i < l; /* inc in loop */) { + File outputFile = new File(classesPath, extraPathsAndContents[i++]); + outputFile.getParentFile().mkdirs(); + Util.writeToFile(extraPathsAndContents[i++], outputFile.getAbsolutePath()); + } + } + zip(classesDir, jarPath); +} +public static void createJar(String[] javaPathsAndContents, String jarPath, String compliance, boolean preview) throws IOException { + Map options = getCompileOptions(compliance); + if (preview) + options.put(CompilerOptions.OPTION_EnablePreviews, CompilerOptions.ENABLED); + createJar(javaPathsAndContents, null, options, null, jarPath); +} +public static void createJar(String[] javaPathsAndContents, String jarPath, String compliance) throws IOException { + createJar(javaPathsAndContents, null, jarPath, compliance); +} +public static void createJar(String[] javaPathsAndContents, String[] extraPathsAndContents, String jarPath, String compliance) throws IOException { + createJar(javaPathsAndContents, extraPathsAndContents, jarPath, null/*no classpath*/, compliance); +} +public static void createJar(String[] javaPathsAndContents, String[] extraPathsAndContents, String jarPath, String[] classpath, String compliance) throws IOException { + createJar(javaPathsAndContents, extraPathsAndContents, getCompileOptions(compliance), classpath, jarPath); +} +public static void createJar(String[] javaPathsAndContents, String[] extraPathsAndContents, String jarPath, String[] classpath, String compliance, Map options) throws IOException { + Map compileOptions = getCompileOptions(compliance); + if (options != null) { + compileOptions.putAll(options); + } + createJar(javaPathsAndContents, extraPathsAndContents, compileOptions, classpath, jarPath); +} +public static void createSourceZip(String[] pathsAndContents, String zipPath) throws IOException { + String sourcesPath = getOutputDirectory() + File.separator + "sources"; + createSourceDir(pathsAndContents, sourcesPath); + zip(new File(sourcesPath), zipPath); +} + +public static void createSourceDir(String[] pathsAndContents, String sourcesPath) throws IOException { + flushDirectoryContent(new File(sourcesPath)); + for (int i = 0, length = pathsAndContents.length; i < length; i+=2) { + String sourcePath = sourcesPath + File.separator + pathsAndContents[i]; + File sourceFile = new File(sourcePath); + sourceFile.getParentFile().mkdirs(); + createFile(sourcePath, pathsAndContents[i+1]); + } +} +/** + * Delete a file or directory and insure that the file is no longer present + * on file system. In case of directory, delete all the hierarchy underneath. + * + * @param file The file or directory to delete + * @return true if the file was really deleted, false otherwise + */ +public static boolean delete(File file) { + // flush all directory content + if (file.isDirectory() && !flushDirectoryContent(file)) { + return false; + } + // remove file or empty directory + if (file.delete()) { + return true; + } else { + if (SKIP_RETRY_DELETE_FILE) { + System.out.println(); + System.out.println("WARNING in test: "+getTestName()); + System.out.println(" - cannot delete " + file + " -> registering for deletion on JVM exit"); + file.deleteOnExit(); + return false; + } else { + return waitUntilFileDeleted(file); + } + } +} +/** + * Delete a file or directory and insure that the file is no longer present + * on file system. In case of directory, delete all the hierarchy underneath. + * + * @param resource The resource to delete + * @return true iff the file was really delete, false otherwise + */ +public static IStatus delete(IResource resource) { + IStatus status = null; + try { + resource.delete(true, null); + if (isResourceDeleted(resource)) { + return Status.OK_STATUS; + } + } catch (CoreException e) { + status = e.getStatus(); + } + boolean deleted = waitUntilResourceDeleted(resource); + if (deleted) { + return Status.OK_STATUS; + } + if (status != null) { + return status; + } + return new Status(IStatus.ERROR, JavaCore.PLUGIN_ID, "Cannot delete resource "+resource); +} +/** + * Delete a file or directory and insure that the file is no longer present + * on file system. In case of directory, delete all the hierarchy underneath. + * + * @param path The path of the file or directory to delete + * @return true iff the file was really delete, false otherwise + */ +public static boolean delete(String path) { + return delete(new File(path)); +} +/** + * Generate a display string from the given String. + * @param inputString the given input string + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.displayString("abc\ndef\tghi")] +*/ +public static String displayString(String inputString){ + return displayString(inputString, 0); +} +/** + * Generate a display string from the given String. + * It converts: + *

      + *
    • \t to \t
    • + *
    • \r to \\r
    • + *
    • \n to \n
    • + *
    • \b to \\b
    • + *
    • \f to \\f
    • + *
    • \" to \\\"
    • + *
    • \' to \\'
    • + *
    • \\ to \\\\
    • + *
    • All other characters are unchanged.
    • + *
    + * This method doesn't convert \r\n to \n. + *

    + * Example of use: + * + *

  • + *
    + * input string = "abc\ndef\tghi",
    + * indent = 3
    + * result = "\"\t\t\tabc\\n" +
    + * 			"\t\t\tdef\tghi\""
    + * 
    + *
  • + *
  • + *
    + * input string = "abc\ndef\tghi\n",
    + * indent = 3
    + * result = "\"\t\t\tabc\\n" +
    + * 			"\t\t\tdef\tghi\\n\""
    + * 
    + *
  • + *
  • + *
    + * input string = "abc\r\ndef\tghi\r\n",
    + * indent = 3
    + * result = "\"\t\t\tabc\\r\\n" +
    + * 			"\t\t\tdef\tghi\\r\\n\""
    + * 
    + *
  • + * + *

    + * + * @param inputString the given input string + * @param indent number of tabs are added at the begining of each line. + * + * @return the displayed string +*/ +public static String displayString(String inputString, int indent) { + return displayString(inputString, indent, false); +} +public static String displayString(String inputString, int indent, boolean shift) { + if (inputString == null) + return "null"; + int length = inputString.length(); + StringBuilder buffer = new StringBuilder(length); + java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(inputString, "\n\r", true); + for (int i = 0; i < indent; i++) buffer.append("\t"); + if (shift) indent++; + buffer.append("\""); + while (tokenizer.hasMoreTokens()){ + + String token = tokenizer.nextToken(); + if (token.equals("\r")) { + buffer.append("\\r"); + if (tokenizer.hasMoreTokens()) { + token = tokenizer.nextToken(); + if (token.equals("\n")) { + buffer.append("\\n"); + if (tokenizer.hasMoreTokens()) { + buffer.append("\" + \n"); + for (int i = 0; i < indent; i++) buffer.append("\t"); + buffer.append("\""); + } + continue; + } + buffer.append("\" + \n"); + for (int i = 0; i < indent; i++) buffer.append("\t"); + buffer.append("\""); + } else { + continue; + } + } else if (token.equals("\n")) { + buffer.append("\\n"); + if (tokenizer.hasMoreTokens()) { + buffer.append("\" + \n"); + for (int i = 0; i < indent; i++) buffer.append("\t"); + buffer.append("\""); + } + continue; + } + + StringBuilder tokenBuffer = new StringBuilder(); + for (int i = 0; i < token.length(); i++){ + char c = token.charAt(i); + switch (c) { + case '\r' : + tokenBuffer.append("\\r"); + break; + case '\n' : + tokenBuffer.append("\\n"); + break; + case '\b' : + tokenBuffer.append("\\b"); + break; + case '\t' : + tokenBuffer.append("\t"); + break; + case '\f' : + tokenBuffer.append("\\f"); + break; + case '\"' : + tokenBuffer.append("\\\""); + break; + case '\'' : + tokenBuffer.append("\\'"); + break; + case '\\' : + tokenBuffer.append("\\\\"); + break; + default : + tokenBuffer.append(c); + } + } + buffer.append(tokenBuffer.toString()); + } + buffer.append("\""); + return buffer.toString(); +} +/** + * Reads the content of the given source file. + * Returns null if enable to read given source file. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.fileContent("c:/temp/X.java")] +*/ +public static String fileContent(String sourceFilePath) { + File sourceFile = new File(sourceFilePath); + if (!sourceFile.exists()) { + if (DEBUG) System.out.println("File " + sourceFilePath + " does not exists."); + return null; + } + if (!sourceFile.isFile()) { + if (DEBUG) System.out.println(sourceFilePath + " is not a file."); + return null; + } + StringBuilder sourceContentBuffer = new StringBuilder(); + FileInputStream input = null; + try { + input = new FileInputStream(sourceFile); + } catch (FileNotFoundException e) { + return null; + } + try { + int read; + do { + read = input.read(); + if (read != -1) { + sourceContentBuffer.append((char)read); + } + } while (read != -1); + input.close(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } finally { + try { + input.close(); + } catch (IOException e2) { + } + } + return sourceContentBuffer.toString(); +} + +/** + * Reads the content of the given source file and converts it to a display string. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.fileContentToDisplayString("c:/temp/X.java", 0)] +*/ +public static String fileContentToDisplayString(String sourceFilePath, int indent, boolean independantLineDelimiter) { + String sourceString = fileContent(sourceFilePath); + if (independantLineDelimiter) { + sourceString = convertToIndependantLineDelimiter(sourceString); + } + return displayString(sourceString, indent); +} +/** + * Reads the content of the given source file, converts it to a display string. + * If the destination file path is not null, writes the result to this file. + * Otherwise writes it to the console. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.fileContentToDisplayString("c:/temp/X.java", 0, null)] +*/ +public static void fileContentToDisplayString(String sourceFilePath, int indent, String destinationFilePath, boolean independantLineDelimiter) { + String displayString = fileContentToDisplayString(sourceFilePath, indent, independantLineDelimiter); + if (destinationFilePath == null) { + System.out.println(displayString); + return; + } + writeToFile(displayString, destinationFilePath); +} +/** + * Flush content of a given directory (leaving it empty), + * no-op if not a directory. + * + * @return {@code true} if all files (if any) inside the directory were deleted successfully; + * {@code false} if there are leftover files or if {@code dir} is not itself a directory + */ +public static boolean flushDirectoryContent(File dir) { + File[] files = dir.listFiles(); + if (files == null) { + return false; + } + boolean allDeleted = true; + for (File file : files) { + if (!delete(file)) { + allDeleted = false; + } +} + return allDeleted; +} +private static Map getCompileOptions(String compliance) { + Map options = new HashMap(); + options.put(CompilerOptions.OPTION_Compliance, compliance); + options.put(CompilerOptions.OPTION_Source, compliance); + options.put(CompilerOptions.OPTION_TargetPlatform, compliance); + // Ignore options with new defaults (since bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=76530) + options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_ReportTypeParameterHiding, CompilerOptions.IGNORE); + options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); + options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE); + return options; +} +/** + * Returns the next available port number on the local host. + */ +public static int getFreePort() { + ServerSocket socket = null; + try { + socket = new ServerSocket(0); + return socket.getLocalPort(); + } catch (IOException e) { + // ignore + } finally { + if (socket != null) { + try { + socket.close(); + } catch (IOException e) { + // ignore + } + } + } + return -1; +} +/** + * Search the user hard-drive for a Java class library. + * Returns null if none could be found. +*/ +public static String[] getJavaClassLibs() { + String javaVersion = System.getProperty("java.version"); + int index = javaVersion.indexOf('.'); + if (index != -1) { + javaVersion = javaVersion.substring(0, index); + } else { + index = javaVersion.indexOf('-'); + if (index != -1) + javaVersion = javaVersion.substring(0, index); + } + long jdkLevel = CompilerOptions.versionToJdkLevel(javaVersion); + if (jdkLevel >= ClassFileConstants.JDK9) { + String jreDir = getJREDirectory(); + return new String[] { + toNativePath(jreDir + "/lib/jrt-fs.jar") + }; + } + + // check bootclasspath properties for Sun, JRockit and Harmony VMs + String bootclasspathProperty = System.getProperty("sun.boot.class.path"); //$NON-NLS-1$ + if ((bootclasspathProperty == null) || (bootclasspathProperty.length() == 0)) { + // IBM J9 VMs + bootclasspathProperty = System.getProperty("vm.boot.class.path"); //$NON-NLS-1$ + if ((bootclasspathProperty == null) || (bootclasspathProperty.length() == 0)) { + // Harmony using IBM VME + bootclasspathProperty = System.getProperty("org.apache.harmony.boot.class.path"); //$NON-NLS-1$ + } + } + String[] jars = null; + if ((bootclasspathProperty != null) && (bootclasspathProperty.length() != 0)) { + StringTokenizer tokenizer = new StringTokenizer(bootclasspathProperty, File.pathSeparator); + final int size = tokenizer.countTokens(); + jars = new String[size]; + int i = 0; + while (tokenizer.hasMoreTokens()) { + final String fileName = toNativePath(tokenizer.nextToken()); + if (new File(fileName).exists()) { + jars[i] = fileName; + i++; + } + } + if (size != i) { + // resize + System.arraycopy(jars, 0, (jars = new String[i]), 0, i); + } + } else { + String jreDir = getJREDirectory(); + final String osName = System.getProperty("os.name"); + if (jreDir == null) { + return new String[] {}; + } + if (osName.startsWith("Mac")) { + return new String[] { + toNativePath(jreDir + "/../Classes/classes.jar") + }; + } + final String vmName = System.getProperty("java.vm.name"); + if ("J9".equals(vmName)) { + return new String[] { + toNativePath(jreDir + "/lib/jclMax/classes.zip") + }; + } + String[] jarsNames = null; + ArrayList paths = new ArrayList(); + if ("DRLVM".equals(vmName)) { + FilenameFilter jarFilter = new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return name.endsWith(".jar") & !name.endsWith("-src.jar"); + } + }; + jarsNames = new File(jreDir + "/lib/boot/").list(jarFilter); + addJarEntries(jreDir + "/lib/boot/", jarsNames, paths); + } else { + jarsNames = new String[] { + "/lib/vm.jar", + "/lib/rt.jar", + "/lib/core.jar", + "/lib/security.jar", + "/lib/xml.jar", + "/lib/graphics.jar" + }; + addJarEntries(jreDir, jarsNames, paths); + } + jars = new String[paths.size()]; + paths.toArray(jars); + } + return jars; +} +private static void addJarEntries(String jreDir, String[] jarNames, ArrayList paths) { + for (int i = 0, max = jarNames.length; i < max; i++) { + final String currentName = jreDir + jarNames[i]; + File f = new File(currentName); + if (f.exists()) { + paths.add(toNativePath(currentName)); + } + } +} +public static String getJavaClassLibsAsString() { + String[] classLibs = getJavaClassLibs(); + StringBuilder buffer = new StringBuilder(); + for (int i = 0, max = classLibs.length; i < max; i++) { + buffer + .append(classLibs[i]) + .append(File.pathSeparatorChar); + } + return buffer.toString(); +} +/** + * Returns the JRE directory this tests are running on. + * Returns null if none could be found. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.getJREDirectory()] + */ +public static String getJREDirectory() { + return System.getProperty("java.home"); +} +/** + * Search the user hard-drive for a possible output directory. + * Returns null if none could be found. + * + * Example of use: [org.eclipse.jdt.core.tests.util.Util.getOutputDirectory()] + */ +public static String getOutputDirectory() { + return OUTPUT_DIRECTORY; +} +/** + * Returns the parent's child file matching the given file or null if not found. + * + * @param file The searched file in parent + * @return The parent's child matching the given file or null if not found. + */ +private static File getParentChildFile(File file) { + File parent = file.getParentFile(); + if (parent == null || !parent.exists()) return null; + File[] files = parent.listFiles(); + int length = files==null ? 0 : files.length; + if (length > 0) { + for (int i=0; i 0) { + for (int i=0; i + *
  • read {@link File#canRead()}
  • + *
  • write {@link File#canWrite()}
  • + *
  • exists {@link File#exists()}
  • + *
  • is file {@link File#isFile()}
  • + *
  • is directory {@link File#isDirectory()}
  • + *
  • is hidden {@link File#isHidden()}
  • + * + * May recurse several level in parents hierarchy. + * May also display children, but then will not recusre in parent + * hierarchy to avoid infinite loop... + * + * @param file The file to display information + * @param indent Number of tab to print before the information + * @param recurse Display also information on recurseth parents in hierarchy. + * If negative then display children information instead. + */ +private static void printFileInfo(File file, int indent, int recurse) { + String tab = ""; + for (int i=0; i 0) { + boolean children = recurse < 0; + System.out.print(tab+" + children: "); + if (children) System.out.println(); + for (int i=0; i0) System.out.print(", "); + System.out.print(files[i].getName()); + if (files[i].isDirectory()) System.out.print("[dir]"); + else if (files[i].isFile()) System.out.print("[file]"); + else System.out.print("[?]"); + } + } + if (!children) System.out.println(); + } + if (recurse > 0) { + File parent = file.getParentFile(); + if (parent != null) printFileInfo(parent, indent+1, recurse-1); + } +} +/** + * Print stack trace with only JDT/Core elements. + * + * @param exception Exception of the stack trace. May be null, then a fake exception is used. + * @param indent Number of tab to display before the stack elements to display. + */ +private static void printJdtCoreStackTrace(Exception exception, int indent) { + String tab = ""; + for (int i=0; i "+testElement); + } + } else { + exception.printStackTrace(System.out); + } +} +/** + * Makes the given path a path using native path separators as returned by File.getPath() + * and trimming any extra slash. + */ +public static String toNativePath(String path) { + String nativePath = path.replace('\\', File.separatorChar).replace('/', File.separatorChar); + return + nativePath.endsWith("/") || nativePath.endsWith("\\") ? + nativePath.substring(0, nativePath.length() - 1) : + nativePath; +} +public static String toString(String[] strings, boolean addExtraNewLine) { + if (strings == null) return "null"; + StringBuilder buffer = new StringBuilder(); + for (int i = 0, length = strings.length; i < length; i++){ + buffer.append(strings[i]); + if (addExtraNewLine || i < length - 1) + buffer.append("\n"); + } + return buffer.toString(); +} +private static String getZipEntryFileName(File destDir, ZipEntry e, String canonicalDestDirPath) throws IOException { + String result = e.getName(); + File destfile = new File(destDir, result); + String canonicalDestFile = destfile.getCanonicalPath(); + if (!canonicalDestFile.startsWith(canonicalDestDirPath + File.separator)) { + throw new ZipEntryStorageException("Entry is outside of the target dir: " + e.getName()); + } + return result; +} +/** + * Unzip the contents of the given zip in the given directory (create it if it doesn't exist) + */ +public static void unzip(String zipPath, String destDirPath) throws IOException { + + InputStream zipIn = new FileInputStream(zipPath); + byte[] buf = new byte[8192]; + File destDir = new File(destDirPath); + String canonicalDestDirPath = destDir.getCanonicalPath(); + ZipInputStream zis = new ZipInputStream(zipIn); + FileOutputStream fos = null; + try { + ZipEntry zEntry; + while ((zEntry = zis.getNextEntry()) != null) { + // if it is empty directory, create it + if (zEntry.isDirectory()) { + new File(destDir, zEntry.getName()).mkdirs(); + continue; + } + // if it is a file, extract it + String filePath = getZipEntryFileName(destDir, zEntry, canonicalDestDirPath); + int lastSeparator = filePath.lastIndexOf("/"); //$NON-NLS-1$ + String fileDir = ""; //$NON-NLS-1$ + if (lastSeparator >= 0) { + fileDir = filePath.substring(0, lastSeparator); + } + //create directory for a file + new File(destDir, fileDir).mkdirs(); + //write file + File outFile = new File(destDir, filePath); + fos = new FileOutputStream(outFile); + int n = 0; + while ((n = zis.read(buf)) >= 0) { + fos.write(buf, 0, n); + } + fos.close(); + } + } catch (IOException ioe) { + if (fos != null) { + try { + fos.close(); + } catch (IOException ioe2) { + } + } + } finally { + try { + zipIn.close(); + if (zis != null) + zis.close(); + } catch (IOException ioe) { + } + } +} +public static void waitAtLeast(int time) { + long start = System.currentTimeMillis(); + do { + try { + Thread.sleep(time); + } catch (InterruptedException e) { + } + } while ((System.currentTimeMillis() - start) < time); +} + +/** + * Wait until the file is _really_ deleted on file system. + * + * @param file Deleted file + * @return true if the file was finally deleted, false otherwise + */ +private static boolean waitUntilFileDeleted(File file) { + if (DELETE_DEBUG) { + System.out.println(); + System.out.println("WARNING in test: "+getTestName()); + System.out.println(" - problems occured while deleting "+file); + printJdtCoreStackTrace(null, 1); + printFileInfo(file.getParentFile(), 1, -1); // display parent with its children + System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); + } + int count = 0; + int delay = 10; // ms + int maxRetry = DELETE_MAX_WAIT / delay; + int time = 0; + while (count < maxRetry) { + try { + count++; + Thread.sleep(delay); + time += delay; + if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time; + if (DELETE_DEBUG) System.out.print('.'); + if (file.exists()) { + if (file.delete()) { + // SUCCESS + if (DELETE_DEBUG) { + System.out.println(); + System.out.println(" => file really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); + System.out.println(); + } + return true; + } + } + if (isFileDeleted(file)) { + // SUCCESS + if (DELETE_DEBUG) { + System.out.println(); + System.out.println(" => file disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); + System.out.println(); + } + return true; + } + // Increment waiting delay exponentially + if (count >= 10 && delay <= 100) { + count = 1; + delay *= 10; + maxRetry = DELETE_MAX_WAIT / delay; + if ((DELETE_MAX_WAIT%delay) != 0) { + maxRetry++; + } + } + } + catch (InterruptedException ie) { + break; // end loop + } + } + if (!DELETE_DEBUG) { + System.out.println(); + System.out.println("WARNING in test: "+getTestName()); + System.out.println(" - problems occured while deleting "+file); + printJdtCoreStackTrace(null, 1); + printFileInfo(file.getParentFile(), 1, -1); // display parent with its children + } + System.out.println(); + System.out.println(" !!! ERROR: "+file+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!"); + System.out.println(); + return false; +} +/** + * Wait until a resource is _really_ deleted on file system. + * + * @param resource Deleted resource + * @return true if the file was finally deleted, false otherwise + */ +public static boolean waitUntilResourceDeleted(IResource resource) { + IPath location = resource.getLocation(); + if (location == null) { + System.out.println(); + System.out.println(" !!! ERROR: "+resource+" getLocation() returned null!!!"); + System.out.println(); + return false; + } + File file = location.toFile(); + if (DELETE_DEBUG) { + System.out.println(); + System.out.println("WARNING in test: "+getTestName()); + System.out.println(" - problems occured while deleting resource "+resource); + printJdtCoreStackTrace(null, 1); + printFileInfo(file.getParentFile(), 1, -1); // display parent with its children + System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): "); + } + int count = 0; + int delay = 10; // ms + int maxRetry = DELETE_MAX_WAIT / delay; + int time = 0; + while (count < maxRetry) { + try { + count++; + Thread.sleep(delay); + time += delay; + if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time; + if (DELETE_DEBUG) System.out.print('.'); + if (resource.isAccessible()) { + try { + resource.delete(true, null); + if (isResourceDeleted(resource) && isFileDeleted(file)) { + // SUCCESS + if (DELETE_DEBUG) { + System.out.println(); + System.out.println(" => resource really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); + System.out.println(); + } + return true; + } + } + catch (CoreException e) { + // skip + } + } + if (isResourceDeleted(resource) && isFileDeleted(file)) { + // SUCCESS + if (DELETE_DEBUG) { + System.out.println(); + System.out.println(" => resource disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)"); + System.out.println(); + } + return true; + } + // Increment waiting delay exponentially + if (count >= 10 && delay <= 100) { + count = 1; + delay *= 10; + maxRetry = DELETE_MAX_WAIT / delay; + if ((DELETE_MAX_WAIT%delay) != 0) { + maxRetry++; + } + } + } + catch (InterruptedException ie) { + break; // end loop + } + } + if (!DELETE_DEBUG) { + System.out.println(); + System.out.println("WARNING in test: "+getTestName()); + System.out.println(" - problems occured while deleting resource "+resource); + printJdtCoreStackTrace(null, 1); + printFileInfo(file.getParentFile(), 1, -1); // display parent with its children + } + System.out.println(); + System.out.println(" !!! ERROR: "+resource+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!"); + System.out.println(); + return false; +} +public static void writeToFile(String contents, String destinationFilePath) { + File destFile = new File(destinationFilePath); + FileOutputStream output = null; + PrintWriter writer = null; + try { + output = new FileOutputStream(destFile); + writer = new PrintWriter(output); + writer.print(contents); + writer.flush(); + } catch (IOException e) { + e.printStackTrace(); + return; + } finally { + if (writer != null) { + writer.close(); + } + } +} +public static void zip(File rootDir, String zipPath) throws IOException { + ZipOutputStream zip = null; + long lastModified=0; + File zipFile = new File(zipPath); + try { + lastModified = zipFile.lastModified(); + if (lastModified != 0) { // zipFile.exists() + if (!delete(zipFile)) { + Files.deleteIfExists(zipFile.toPath()); + } + } else { + zipFile.getParentFile().mkdirs(); + } + zip = new ZipOutputStream(new BufferedOutputStream( new FileOutputStream(zipFile))); + zip(rootDir, zip, rootDir.getPath().length()+1); // 1 for last slash + } finally { + if (zip != null) { + zip.close(); + } + } + if (lastModified != 0 && lastModified == zipFile.lastModified()) { + // ensure the new zip file has a different timestamp than the previous one + zipFile.setLastModified(lastModified + 1000); + } +} +private static void zip(File dir, ZipOutputStream zip, int rootPathLength) throws IOException { + File[] files = dir.listFiles(); + if (files != null) { + for (int i = 0, length = files.length; i < length; i++) { + File file = files[i]; + if (file.isFile()) { + String path = file.getPath(); + path = path.substring(rootPathLength); + ZipEntry entry = new ZipEntry(path.replace('\\', '/')); + zip.putNextEntry(entry); + zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file)); + zip.closeEntry(); + } else { + zip(file, zip, rootPathLength); + } + } + } +} + +/** + * Zips the given files into the given jar. All the files are kept at the root of the zip. + */ +public static void zipFiles(File[] files, String zipPath) throws IOException { + File zipFile = new File(zipPath); + if (zipFile.exists()) { + if (!delete(zipFile)) { + Files.deleteIfExists(zipFile.toPath()); + } + // ensure the new zip file has a different timestamp than the previous one + int timeToWait = 1000; // some platform (like Linux) have a 1s granularity) + waitAtLeast(timeToWait); + } else { + zipFile.getParentFile().mkdirs(); + } + ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(zipFile)); + try { + for (int i = 0, length = files.length; i < length; i++) { + File file = files[i]; + ZipEntry entry = new ZipEntry(file.getName()); + zip.putNextEntry(entry); + zip.write(org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(file)); + zip.closeEntry(); + } + } finally { + zip.close(); + } +} +/** + * Returns the compilation errors / warnings for the given CompilationResult. + * + * @param compilationResult the compilation result + * @param showCategory + * @param showWarningToken + * @return String the problem log + */ +public static String getProblemLog(CompilationResult compilationResult, boolean showCategory, boolean showWarningToken) { + StringBuilder buffer = new StringBuilder(100); + if (compilationResult.hasProblems() || compilationResult.hasTasks()) { + CategorizedProblem[] problems = compilationResult.getAllProblems(); + int count = problems.length; + int problemCount = 0; + char[] unitSource = compilationResult.compilationUnit.getContents(); + for (int i = 0; i < count; i++) { + DefaultProblem problem = (DefaultProblem) problems[i]; + if (problem != null) { + if (problemCount == 0) + buffer.append("----------\n"); + problemCount++; + buffer.append(problemCount + (problem.isError() ? ". ERROR" : problem.isWarning() ? ". WARNING" : ". INFO")); + buffer.append(" in " + new String(problem.getOriginatingFileName()).replace('/', '\\')); + try { + buffer.append(problem.errorReportSource(unitSource)); + buffer.append("\n"); + if (showCategory) { + String category = problem.getInternalCategoryMessage(); + if (category != null) { + buffer.append("[@cat:").append(category).append("] "); + } + } + if (showWarningToken) { + int irritant = ProblemReporter.getIrritant(problem.getID()); + if (irritant != 0) { + String warningToken = CompilerOptions.warningTokenFromIrritant(irritant); + if (warningToken != null) { + buffer.append("[@sup:").append(warningToken).append("] "); + } + } + } + buffer.append(problem.getMessage()); + buffer.append("\n"); + } catch (Exception e) { + } + buffer.append("----------\n"); + } + } + } + return buffer.toString(); +} +public static long getMajorMinorVMVersion() { + String classFileVersion = System.getProperty("java.class.version"); //$NON-NLS-1$ + if (classFileVersion != null) { + String[] versionParts = classFileVersion.split("\\."); //$NON-NLS-1$ + if (versionParts.length >= 2) { + int majorVersion = -1; + try { + majorVersion = Integer.parseInt(versionParts[0]); + } catch (NumberFormatException e) { + // ignore + } + int minorVersion = -1; + try { + minorVersion = Integer.parseInt(versionParts[1]); + } catch (NumberFormatException e) { + // ignore + } + if (minorVersion != -1 && majorVersion != -1) { + return ((long) majorVersion << 16) + minorVersion; + } + } + } + return -1; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java new file mode 100644 index 0000000000..67a3d172ae --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java @@ -0,0 +1,246 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.util; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.net.Socket; +import java.util.StringTokenizer; + +/****************************************************** + * + * IMPORTANT NOTE: If modifying this class, copy the source to TestVerifier#getVerifyTestsCode() + * (see this method for details) + * + ******************************************************/ + +@SuppressWarnings({ "unchecked", "rawtypes" }) +public class VerifyTests { + int portNumber; + Socket socket; + +/** + * NOTE: Code copied from junit.util.TestCaseClassLoader. + * + * A custom class loader which enables the reloading + * of classes for each test run. The class loader + * can be configured with a list of package paths that + * should be excluded from loading. The loading + * of these packages is delegated to the system class + * loader. They will be shared across test runs. + *

    + * The list of excluded package paths is specified in + * a properties file "excluded.properties" that is located in + * the same place as the TestCaseClassLoader class. + *

    + * Known limitation: the VerifyClassLoader cannot load classes + * from jar files. + */ + + +public class VerifyClassLoader extends ClassLoader { + /** scanned class path */ + private String[] pathItems; + + /** excluded paths */ + private String[] excluded= {}; + + /** + * Constructs a VerifyClassLoader. It scans the class path + * and the excluded package paths + */ + public VerifyClassLoader() { + super(); + String classPath= System.getProperty("java.class.path"); + String separator= System.getProperty("path.separator"); + + // first pass: count elements + StringTokenizer st= new StringTokenizer(classPath, separator); + int i= 0; + while (st.hasMoreTokens()) { + st.nextToken(); + i++; + } + // second pass: split + this.pathItems= new String[i]; + st= new StringTokenizer(classPath, separator); + i= 0; + while (st.hasMoreTokens()) { + this.pathItems[i++]= st.nextToken(); + } + + } + @Override + public java.net.URL getResource(String name) { + return ClassLoader.getSystemResource(name); + } + @Override + public InputStream getResourceAsStream(String name) { + return ClassLoader.getSystemResourceAsStream(name); + } + protected boolean isExcluded(String name) { + // exclude the "java" packages. + // They always need to be excluded so that they are loaded by the system class loader + if (name.startsWith("java") || name.startsWith("[Ljava")) + return true; + + // exclude the user defined package paths + for (int i= 0; i < this.excluded.length; i++) { + if (name.startsWith(this.excluded[i])) { + return true; + } + } + return false; + } + @Override + public synchronized Class loadClass(String name, boolean resolve) + throws ClassNotFoundException { + + Class c= findLoadedClass(name); + if (c != null) + return c; + // + // Delegate the loading of excluded classes to the + // standard class loader. + // + if (isExcluded(name)) { + try { + c= findSystemClass(name); + return c; + } catch (ClassNotFoundException e) { + // keep searching + } + } + File file= locate(name); + if (file == null) + throw new ClassNotFoundException(); + byte data[]= loadClassData(file); + c= defineClass(name, data, 0, data.length); + if (resolve) + resolveClass(c); + return c; + } + private byte[] loadClassData(File f) throws ClassNotFoundException { + FileInputStream stream = null; + try { + //System.out.println("loading: "+f.getPath()); + stream = new FileInputStream(f); + + try { + byte[] b= new byte[stream.available()]; + stream.read(b); + return b; + } + catch (IOException e) { + throw new ClassNotFoundException(); + } + } + catch (FileNotFoundException e) { + throw new ClassNotFoundException(); + } finally { + if (stream != null) { + try { + stream.close(); + } catch (IOException e) { + /* ignore */ + } + } + } + } + /** + * Locate the given file. + * @return Returns null if file couldn't be found. + */ + private File locate(String fileName) { + if (fileName != null) { + fileName= fileName.replace('.', '/')+".class"; + File path= null; + for (int i= 0; i < this.pathItems.length; i++) { + path= new File(this.pathItems[i], fileName); + if (path.exists()) + return path; + } + } + return null; + } +} + +public void loadAndRun(String className) throws Throwable { + //System.out.println("Loading " + className + "..."); + Class testClass = new VerifyClassLoader().loadClass(className); + //System.out.println("Loaded " + className); + try { + Method main = testClass.getMethod("main", new Class[] {String[].class}); + //System.out.println("Running " + className); + main.invoke(null, new Object[] {new String[] {}}); + //System.out.println("Finished running " + className); + } catch (NoSuchMethodException e) { + return; + } catch (InvocationTargetException e) { + throw e.getTargetException(); + } +} +public static void main(String[] args) throws IOException { + VerifyTests verify = new VerifyTests(); + verify.portNumber = Integer.parseInt(args[0]); + verify.run(); +} +public void run() throws IOException { + this.socket = new Socket("localhost", this.portNumber); + this.socket.setTcpNoDelay(true); + + DataInputStream in = new DataInputStream(this.socket.getInputStream()); + final DataOutputStream out = new DataOutputStream(this.socket.getOutputStream()); + while (true) { + final String className = in.readUTF(); + Thread thread = new Thread() { + @Override + public void run() { + try { + loadAndRun(className); + out.writeBoolean(true); + System.out.println(VerifyTests.class.getName()); + System.err.println(VerifyTests.class.getName()); + } catch (Throwable e) { + e.printStackTrace(); + try { + out.writeBoolean(false); + System.out.println(VerifyTests.class.getName()); + System.err.println(VerifyTests.class.getName()); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + // Flush all streams, in case the test executor VM is shut down before + // the controlling VM receives the responses it depends on + try { + out.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.flush(); + System.err.flush(); + } + }; + thread.start(); + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/ZipEntryStorageException.java b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/ZipEntryStorageException.java new file mode 100644 index 0000000000..16506bf0f7 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/ZipEntryStorageException.java @@ -0,0 +1,12 @@ +package org.eclipse.jdt.core.tests.util; + +import java.io.IOException; + +public class ZipEntryStorageException extends IOException { + + private static final long serialVersionUID = 1L; + + public ZipEntryStorageException(String message) { + super(message); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/test.xml b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/test.xml new file mode 100644 index 0000000000..53a33770d2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/test.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Bug422832ClassFile/aspose.pdf.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Bug422832ClassFile/aspose.pdf.jar new file mode 100644 index 0000000000..5c32d6450a Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Bug422832ClassFile/aspose.pdf.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/ParameterNames$1.class b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/ParameterNames$1.class new file mode 100644 index 0000000000..0b38bb0d83 Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/ParameterNames$1.class differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/ParameterNames$1Local.class b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/ParameterNames$1Local.class new file mode 100644 index 0000000000..92ba68bfe5 Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/ParameterNames$1Local.class differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/ParameterNames.class b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/ParameterNames.class new file mode 100644 index 0000000000..9b92bf5ba2 Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/ParameterNames.class differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test372011.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test372011.jar new file mode 100644 index 0000000000..d867315e9a Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test372011.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test374129.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test374129.jar new file mode 100644 index 0000000000..93409d6611 Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test374129.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test374129_1.8.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test374129_1.8.jar new file mode 100644 index 0000000000..815848ff8f Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test374129_1.8.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test380112.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test380112.jar new file mode 100644 index 0000000000..856a7110ce Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test380112.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test388281.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test388281.jar new file mode 100644 index 0000000000..7c66b721c9 Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test388281.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test388281_1.8.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test388281_1.8.jar new file mode 100644 index 0000000000..661301c3dc Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test388281_1.8.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test454182.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test454182.jar new file mode 100644 index 0000000000..d26c471ac9 Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test454182.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test548596.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test548596.jar new file mode 100644 index 0000000000..e51ef396dc Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test548596.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test571363.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test571363.jar new file mode 100644 index 0000000000..fccdbfee9f Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/Test571363.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/TestBootstrapMethodAtt.class b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/TestBootstrapMethodAtt.class new file mode 100644 index 0000000000..b2693d7eae Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/TestBootstrapMethodAtt.class differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/bug492322-compiled-with-4.6.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/bug492322-compiled-with-4.6.jar new file mode 100644 index 0000000000..660df18dd1 Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/bug492322-compiled-with-4.6.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/multi.jar b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/multi.jar new file mode 100644 index 0000000000..c28b088a36 Binary files /dev/null and b/jdt-patch/e422/org.eclipse.jdt.core.tests.compiler/workspace/multi.jar differ diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.classpath b/jdt-patch/e422/org.eclipse.jdt.core/.classpath new file mode 100644 index 0000000000..0241bc22e0 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.classpath @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.gitignore b/jdt-patch/e422/org.eclipse.jdt.core/.gitignore new file mode 100644 index 0000000000..8cc0e6c8c4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.gitignore @@ -0,0 +1,3 @@ +/antbin +/bin +/target diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.options b/jdt-patch/e422/org.eclipse.jdt.core/.options new file mode 100644 index 0000000000..0262c1e3a1 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.options @@ -0,0 +1,102 @@ +# Turn on debug tracing for org.eclipse.jdt.core plugin +org.eclipse.jdt.core/debug=false + +# Reports buffer manager activity +org.eclipse.jdt.core/debug/buffermanager=false + +# Reports java builder activity : nature of build, built state reading, indictment process +org.eclipse.jdt.core/debug/builder=false + +# Reports java builder stats +org.eclipse.jdt.core/debug/builder/stats=false + +# Reports compiler activity +org.eclipse.jdt.core/debug/compiler=false + +# Reports codeassist completion activity : recovered unit, inferred completions +org.eclipse.jdt.core/debug/completion=false + +# Reports classpath variable initialization, and classpath container resolution +org.eclipse.jdt.core/debug/cpresolution=false + +# Reports internals of classpath variable initialization, and classpath container resolution (to be used on the JDT/Core team request only) +org.eclipse.jdt.core/debug/cpresolution/advanced=false + +# Reports failures during classpath variable initialization, and classpath container resolution +org.eclipse.jdt.core/debug/cpresolution/failure=false + +# Reports bad node nesting in DOM AST (for interactive usage) +org.eclipse.jdt.core/debug/dom/ast=false + +# Throws an exception in case of bad node nesting in DOM AST (enabled in tests) +org.eclipse.jdt.core/debug/dom/ast/throw=false + +# Reports type errors when using ASTRewrite (throws exceptions; not enabled by default, since some non-typesafe operations are fine in practice) +org.eclipse.jdt.core/debug/dom/rewrite=false + +# Report type hierarchy connections, refreshes and deltas +org.eclipse.jdt.core/debug/hierarchy=false + +# Reports background indexer activity: indexing, saving index file, index queries +org.eclipse.jdt.core/debug/indexmanager=false + +# Reports internals of indexer activity (to be used on the JDT/Core team request only) +org.eclipse.jdt.core/debug/indexmanager/advanced=false + +# Print notified Java element deltas +org.eclipse.jdt.core/debug/javadelta=false +org.eclipse.jdt.core/debug/javadelta/verbose=false + +# Reports various Java model activities +org.eclipse.jdt.core/debug/javamodel=false + +# Reports Java model elements opening/closing +org.eclipse.jdt.core/debug/javamodel/cache=false + +# Reports changes in the Java classpath and classpath resolution +org.eclipse.jdt.core/debug/javamodel/classpath=false + +# Reports all insertions and removals from the java model cache +org.eclipse.jdt.core/debug/javamodel/insertions=false + +# Records information about the invalid archive cache +org.eclipse.jdt.core/debug/javamodel/invalid_archives=false + +# Reports post actions addition/run +org.eclipse.jdt.core/debug/postaction=false + +# Reports name resolution activity +org.eclipse.jdt.core/debug/resolution=false + +# Reports java search activity +org.eclipse.jdt.core/debug/search=false + +# Reports source mapper activity +org.eclipse.jdt.core/debug/sourcemapper=false + +# Reports code formatter activity +org.eclipse.jdt.core/debug/formatter=false + +# Reports open on selection activity : recovered unit, inferred selection +org.eclipse.jdt.core/debug/selection=false + +# Reports access to zip and jar files through the Java model +org.eclipse.jdt.core/debug/zipaccess=false + +# Reports the time to perform code completion. +org.eclipse.jdt.core/perf/completion=300 + +# Reports the time to perform code selection. +org.eclipse.jdt.core/perf/selection=300 + +# Reports the time to process a java element delta. +org.eclipse.jdt.core/perf/javadeltalistener=500 + +# Reports the time to perform an initialization of a classpath variable. +org.eclipse.jdt.core/perf/variableinitializer=5000 + +# Reports the time to perform an initialization of a classpath container. +org.eclipse.jdt.core/perf/containerinitializer=5000 + +# Reports the time to perform a reconcile operation. +org.eclipse.jdt.core/perf/reconcile=1000 diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.project b/jdt-patch/e422/org.eclipse.jdt.core/.project new file mode 100644 index 0000000000..63121f26f9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.project @@ -0,0 +1,34 @@ + + + org.eclipse.jdt.core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.pde.PluginNature + org.eclipse.pde.api.tools.apiAnalysisNature + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.settings/.api_filters b/jdt-patch/e422/org.eclipse.jdt.core/.settings/.api_filters new file mode 100644 index 0000000000..0cbe37737e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.settings/.api_filters @@ -0,0 +1,398 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.core.resources.prefs b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000000..796937ca48 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +encoding//scripts/ecj.1=ISO-8859-1 +encoding/=UTF-8 diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.core.runtime.prefs b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.core.runtime.prefs new file mode 100644 index 0000000000..5a0ad22d2a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.core.runtime.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +line.separator=\n diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.jdt.core.prefs b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..19d7cb9d28 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,395 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.builder.cleanOutputFolder=clean +org.eclipse.jdt.core.builder.duplicateResourceTask=warning +org.eclipse.jdt.core.builder.invalidClasspath=abort +org.eclipse.jdt.core.builder.recreateModifiedClassFileInOutputFolder=ignore +org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch,.svn/ +org.eclipse.jdt.core.circularClasspath=error +org.eclipse.jdt.core.classpath.exclusionPatterns=enabled +org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled +org.eclipse.jdt.core.codeComplete.argumentPrefixes= +org.eclipse.jdt.core.codeComplete.argumentSuffixes= +org.eclipse.jdt.core.codeComplete.fieldPrefixes= +org.eclipse.jdt.core.codeComplete.fieldSuffixes= +org.eclipse.jdt.core.codeComplete.localPrefixes= +org.eclipse.jdt.core.codeComplete.localSuffixes= +org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= +org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= +org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled +org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore +org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull +org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault +org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable +org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.doc.comment.support=enabled +org.eclipse.jdt.core.compiler.maxProblemPerUnit=100 +org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.autoboxing=ignore +org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning +org.eclipse.jdt.core.compiler.problem.deadCode=warning +org.eclipse.jdt.core.compiler.problem.deprecation=warning +org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled +org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning +org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore +org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning +org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled +org.eclipse.jdt.core.compiler.problem.fieldHiding=warning +org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning +org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning +org.eclipse.jdt.core.compiler.problem.forbiddenReference=error +org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning +org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled +org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning +org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning +org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning +org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled +org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private +org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning +org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning +org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore +org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore +org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled +org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=warning +org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=enabled +org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public +org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=enabled +org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=error +org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled +org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning +org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning +org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning +org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning +org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning +org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning +org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error +org.eclipse.jdt.core.compiler.problem.nullReference=warning +org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error +org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning +org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning +org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore +org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning +org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore +org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore +org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning +org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning +org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning +org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore +org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning +org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore +org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled +org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning +org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled +org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled +org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled +org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning +org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning +org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=disabled +org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning +org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=warning +org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning +org.eclipse.jdt.core.compiler.problem.uninternedIdentityComparison=enabled +org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore +org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning +org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=warning +org.eclipse.jdt.core.compiler.problem.unsafeTypeOperation=warning +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled +org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedImport=error +org.eclipse.jdt.core.compiler.problem.unusedLabel=warning +org.eclipse.jdt.core.compiler.problem.unusedLocal=warning +org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled +org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled +org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning +org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore +org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning +org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning +org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assignment=0 +org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_field=0 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 +org.eclipse.jdt.core.formatter.blank_lines_before_method=1 +org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 +org.eclipse.jdt.core.formatter.blank_lines_before_package=0 +org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 +org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false +org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true +org.eclipse.jdt.core.formatter.comment.format_header=false +org.eclipse.jdt.core.formatter.comment.format_html=true +org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true +org.eclipse.jdt.core.formatter.comment.format_line_comments=true +org.eclipse.jdt.core.formatter.comment.format_source_code=true +org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true +org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert +org.eclipse.jdt.core.formatter.comment.line_length=120 +org.eclipse.jdt.core.formatter.compact_else_if=true +org.eclipse.jdt.core.formatter.continuation_indentation=2 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true +org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_empty_lines=false +org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true +org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true +org.eclipse.jdt.core.formatter.indentation.size=4 +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert +org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert +org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert +org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert +org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert +org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert +org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert +org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.lineSplit=120 +org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false +org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true +org.eclipse.jdt.core.formatter.tabulation.char=tab +org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.incompatibleJDKLevel=ignore +org.eclipse.jdt.core.incompleteClasspath=error diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.jdt.ui.prefs b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000000..d05be548db --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,113 @@ +cleanup.add_default_serial_version_id=true +cleanup.add_generated_serial_version_id=false +cleanup.add_missing_annotations=true +cleanup.add_missing_deprecated_annotations=true +cleanup.add_missing_nls_tags=false +cleanup.add_missing_override_annotations=true +cleanup.add_serial_version_id=false +cleanup.always_use_blocks=true +cleanup.always_use_parentheses_in_expressions=false +cleanup.always_use_this_for_non_static_field_access=true +cleanup.always_use_this_for_non_static_method_access=false +cleanup.convert_to_enhanced_for_loop=false +cleanup.format_comment=false +cleanup.format_javadoc=true +cleanup.format_multi_line_comment=true +cleanup.format_single_line_comment=true +cleanup.format_source_code=false +cleanup.make_local_variable_final=true +cleanup.make_parameters_final=false +cleanup.make_private_fields_final=true +cleanup.make_variable_declarations_final=false +cleanup.never_use_blocks=false +cleanup.never_use_parentheses_in_expressions=true +cleanup.organize_imports=true +cleanup.qualify_static_field_accesses_with_declaring_class=true +cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +cleanup.qualify_static_member_accesses_with_declaring_class=true +cleanup.qualify_static_method_accesses_with_declaring_class=false +cleanup.remove_private_constructors=true +cleanup.remove_unnecessary_casts=true +cleanup.remove_unnecessary_nls_tags=true +cleanup.remove_unused_imports=true +cleanup.remove_unused_local_variables=false +cleanup.remove_unused_private_fields=true +cleanup.remove_unused_private_members=false +cleanup.remove_unused_private_methods=true +cleanup.remove_unused_private_types=true +cleanup.use_blocks=false +cleanup.use_blocks_only_for_return_and_throw=false +cleanup.use_parentheses_in_expressions=false +cleanup.use_this_for_non_static_field_access=true +cleanup.use_this_for_non_static_field_access_only_if_necessary=false +cleanup.use_this_for_non_static_method_access=false +cleanup.use_this_for_non_static_method_access_only_if_necessary=true +cleanup_profile=_Numbat +cleanup_settings_version=2 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +formatter_profile=_Jdtcore [built-in + Indent switch body + LineWidth\:120] +formatter_settings_version=11 +org.eclipse.jdt.ui.exception.name=e +org.eclipse.jdt.ui.gettersetter.use.is=true +org.eclipse.jdt.ui.keywordthis=true +org.eclipse.jdt.ui.overrideannotation=true +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=false +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=false +sp_cleanup.add_missing_override_annotations_interface_methods=false +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_functional_interfaces=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=false +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.insert_inferred_type_arguments=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=false +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_redundant_type_arguments=false +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=false +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.update_ibm_copyright_to_current_year=true +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_lambda=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.pde.api.tools.prefs b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.pde.api.tools.prefs new file mode 100644 index 0000000000..27d88d036d --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.pde.api.tools.prefs @@ -0,0 +1,93 @@ +ANNOTATION_ELEMENT_TYPE_ADDED_METHOD_WITHOUT_DEFAULT_VALUE=Error +ANNOTATION_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +ANNOTATION_ELEMENT_TYPE_REMOVED_FIELD=Error +ANNOTATION_ELEMENT_TYPE_REMOVED_METHOD=Error +ANNOTATION_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +API_COMPONENT_ELEMENT_TYPE_REMOVED_API_TYPE=Error +API_COMPONENT_ELEMENT_TYPE_REMOVED_REEXPORTED_API_TYPE=Error +API_COMPONENT_ELEMENT_TYPE_REMOVED_REEXPORTED_TYPE=Error +API_COMPONENT_ELEMENT_TYPE_REMOVED_TYPE=Error +CLASS_ELEMENT_TYPE_ADDED_METHOD=Error +CLASS_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error +CLASS_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +CLASS_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error +CLASS_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +CLASS_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error +CLASS_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error +CLASS_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +CLASS_ELEMENT_TYPE_REMOVED_CONSTRUCTOR=Error +CLASS_ELEMENT_TYPE_REMOVED_FIELD=Error +CLASS_ELEMENT_TYPE_REMOVED_METHOD=Error +CLASS_ELEMENT_TYPE_REMOVED_SUPERCLASS=Error +CLASS_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +CLASS_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +CONSTRUCTOR_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +CONSTRUCTOR_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +CONSTRUCTOR_ELEMENT_TYPE_CHANGED_VARARGS_TO_ARRAY=Error +CONSTRUCTOR_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +ENUM_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error +ENUM_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +ENUM_ELEMENT_TYPE_REMOVED_ENUM_CONSTANT=Error +ENUM_ELEMENT_TYPE_REMOVED_FIELD=Error +ENUM_ELEMENT_TYPE_REMOVED_METHOD=Error +ENUM_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +FIELD_ELEMENT_TYPE_ADDED_VALUE=Error +FIELD_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +FIELD_ELEMENT_TYPE_CHANGED_FINAL_TO_NON_FINAL_STATIC_CONSTANT=Error +FIELD_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error +FIELD_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error +FIELD_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error +FIELD_ELEMENT_TYPE_CHANGED_TYPE=Error +FIELD_ELEMENT_TYPE_CHANGED_VALUE=Error +FIELD_ELEMENT_TYPE_REMOVED_TYPE_ARGUMENT=Error +FIELD_ELEMENT_TYPE_REMOVED_VALUE=Error +ILLEGAL_EXTEND=Warning +ILLEGAL_IMPLEMENT=Warning +ILLEGAL_INSTANTIATE=Warning +ILLEGAL_OVERRIDE=Warning +ILLEGAL_REFERENCE=Warning +INTERFACE_ELEMENT_TYPE_ADDED_FIELD=Error +INTERFACE_ELEMENT_TYPE_ADDED_METHOD=Error +INTERFACE_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error +INTERFACE_ELEMENT_TYPE_ADDED_SUPER_INTERFACE_WITH_METHODS=Error +INTERFACE_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +INTERFACE_ELEMENT_TYPE_CHANGED_CONTRACTED_SUPERINTERFACES_SET=Error +INTERFACE_ELEMENT_TYPE_CHANGED_TYPE_CONVERSION=Error +INTERFACE_ELEMENT_TYPE_REMOVED_FIELD=Error +INTERFACE_ELEMENT_TYPE_REMOVED_METHOD=Error +INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_MEMBER=Error +INTERFACE_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +INVALID_JAVADOC_TAG=Warning +INVALID_REFERENCE_IN_SYSTEM_LIBRARIES=Warning +LEAK_EXTEND=Ignore +LEAK_FIELD_DECL=Warning +LEAK_IMPLEMENT=Ignore +LEAK_METHOD_PARAM=Ignore +LEAK_METHOD_RETURN_TYPE=Ignore +METHOD_ELEMENT_TYPE_ADDED_RESTRICTIONS=Error +METHOD_ELEMENT_TYPE_ADDED_TYPE_PARAMETER=Error +METHOD_ELEMENT_TYPE_CHANGED_DECREASE_ACCESS=Error +METHOD_ELEMENT_TYPE_CHANGED_NON_ABSTRACT_TO_ABSTRACT=Error +METHOD_ELEMENT_TYPE_CHANGED_NON_FINAL_TO_FINAL=Error +METHOD_ELEMENT_TYPE_CHANGED_NON_STATIC_TO_STATIC=Error +METHOD_ELEMENT_TYPE_CHANGED_STATIC_TO_NON_STATIC=Error +METHOD_ELEMENT_TYPE_CHANGED_VARARGS_TO_ARRAY=Error +METHOD_ELEMENT_TYPE_REMOVED_ANNOTATION_DEFAULT_VALUE=Error +METHOD_ELEMENT_TYPE_REMOVED_TYPE_PARAMETER=Error +TYPE_PARAMETER_ELEMENT_TYPE_ADDED_CLASS_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_ADDED_INTERFACE_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_CHANGED_CLASS_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_CHANGED_INTERFACE_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_CLASS_BOUND=Error +TYPE_PARAMETER_ELEMENT_TYPE_REMOVED_INTERFACE_BOUND=Error +UNUSED_PROBLEM_FILTERS=Warning +automatically_removed_unused_problem_filters=false +eclipse.preferences.version=1 +incompatible_api_component_version=Error +incompatible_api_component_version_include_major_without_breaking_change=Disabled +incompatible_api_component_version_include_minor_without_api_change=Disabled +invalid_since_tag_version=Error +malformed_since_tag=Error +missing_since_tag=Error +report_api_breakage_when_major_version_incremented=Disabled +report_resolution_errors_api_component=Warning diff --git a/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.pde.prefs b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.pde.prefs new file mode 100644 index 0000000000..9251e60d8c --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/.settings/org.eclipse.pde.prefs @@ -0,0 +1,35 @@ +#Fri May 21 10:24:08 EDT 2010 +compilers.f.unresolved-features=1 +compilers.f.unresolved-plugins=1 +compilers.incompatible-environment=1 +compilers.p.build=1 +compilers.p.build.bin.includes=1 +compilers.p.build.encodings=2 +compilers.p.build.java.compiler=2 +compilers.p.build.java.compliance=2 +compilers.p.build.missing.output=2 +compilers.p.build.output.library=2 +compilers.p.build.source.library=2 +compilers.p.build.src.includes=1 +compilers.p.deprecated=1 +compilers.p.discouraged-class=1 +compilers.p.internal=1 +compilers.p.missing-bundle-classpath-entries=2 +compilers.p.missing-packages=2 +compilers.p.missing-version-export-package=2 +compilers.p.missing-version-import-package=2 +compilers.p.missing-version-require-bundle=2 +compilers.p.no-required-att=0 +compilers.p.not-externalized-att=2 +compilers.p.unknown-attribute=1 +compilers.p.unknown-class=1 +compilers.p.unknown-element=1 +compilers.p.unknown-identifier=1 +compilers.p.unknown-resource=1 +compilers.p.unresolved-ex-points=1 +compilers.p.unresolved-import=0 +compilers.s.create-docs=false +compilers.s.doc-folder=doc +compilers.s.open-tags=1 +compilers.use-project=true +eclipse.preferences.version=1 diff --git a/jdt-patch/e422/org.eclipse.jdt.core/META-INF/MANIFEST.MF b/jdt-patch/e422/org.eclipse.jdt.core/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..3c2b63fee8 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/META-INF/MANIFEST.MF @@ -0,0 +1,73 @@ +Manifest-Version: 1.0 +Main-Class: org.eclipse.jdt.internal.compiler.batch.Main +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.jdt.core; singleton:=true +Bundle-Version: 3.28.0.qualifier +Bundle-Activator: org.eclipse.jdt.core.JavaCore +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Export-Package: org.eclipse.jdt.core, + org.eclipse.jdt.core.compiler, + org.eclipse.jdt.core.compiler.batch, + org.eclipse.jdt.core.dom, + org.eclipse.jdt.core.dom.rewrite, + org.eclipse.jdt.core.eval, + org.eclipse.jdt.core.formatter, + org.eclipse.jdt.core.index, + org.eclipse.jdt.core.jdom, + org.eclipse.jdt.core.provisional;x-friends:="org.eclipse.jdt.debug.ui,org.eclipse.jdt.launching,org.eclipse.jdt.ui", + org.eclipse.jdt.core.search, + org.eclipse.jdt.core.util, + org.eclipse.jdt.internal.codeassist;x-internal:=true, + org.eclipse.jdt.internal.codeassist.complete;x-internal:=true, + org.eclipse.jdt.internal.codeassist.impl;x-internal:=true, + org.eclipse.jdt.internal.codeassist.select;x-internal:=true, + org.eclipse.jdt.internal.compiler;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core", + org.eclipse.jdt.internal.compiler.ast;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core", + org.eclipse.jdt.internal.compiler.batch;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core", + org.eclipse.jdt.internal.compiler.classfmt;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core,org.eclipse.pde.api.tools", + org.eclipse.jdt.internal.compiler.codegen;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core,org.eclipse.pde.api.tools", + org.eclipse.jdt.internal.compiler.env;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core", + org.eclipse.jdt.internal.compiler.flow;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core", + org.eclipse.jdt.internal.compiler.impl;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core,org.eclipse.jdt.debug", + org.eclipse.jdt.internal.compiler.lookup;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core", + org.eclipse.jdt.internal.compiler.parser;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core", + org.eclipse.jdt.internal.compiler.parser.diagnose;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core", + org.eclipse.jdt.internal.compiler.problem;x-friends:="org.eclipse.jdt.compiler.tool,org.eclipse.jdt.apt.pluggable.core", + org.eclipse.jdt.internal.compiler.util; + x-friends:="org.eclipse.jdt.apt.pluggable.core, + org.eclipse.jdt.compiler.tool, + org.eclipse.pde.api.tools, + org.eclipse.jdt.apt.core, + org.eclipse.jdt.debug", + org.eclipse.jdt.internal.core;x-friends:="org.eclipse.jdt.apt.pluggable.core,org.eclipse.pde.api.tools,org.eclipse.jdt.launching", + org.eclipse.jdt.internal.core.builder;x-friends:="org.eclipse.jdt.apt.pluggable.core,org.eclipse.pde.api.tools", + org.eclipse.jdt.internal.core.dom;x-internal:=true, + org.eclipse.jdt.internal.core.dom.rewrite;x-internal:=true, + org.eclipse.jdt.internal.core.dom.util;x-internal:=true, + org.eclipse.jdt.internal.core.eval;x-internal:=true, + org.eclipse.jdt.internal.core.hierarchy;x-internal:=true, + org.eclipse.jdt.internal.core.index;x-internal:=true, + org.eclipse.jdt.internal.core.jdom;x-internal:=true, + org.eclipse.jdt.internal.core.nd.java.model;x-internal:=true, + org.eclipse.jdt.internal.core.search;x-internal:=true, + org.eclipse.jdt.internal.core.search.indexing;x-internal:=true, + org.eclipse.jdt.internal.core.search.matching;x-internal:=true, + org.eclipse.jdt.internal.core.search.processing;x-internal:=true, + org.eclipse.jdt.internal.core.util;x-friends:="org.eclipse.jdt.apt.pluggable.core,org.eclipse.pde.api.tools,org.eclipse.jdt.debug", + org.eclipse.jdt.internal.eval;x-internal:=true, + org.eclipse.jdt.internal.formatter;x-internal:=true, + org.eclipse.jdt.internal.formatter.linewrap;x-internal:=true, + org.eclipse.jdt.internal.formatter.old;x-internal:=true, + org.codehaus.jdt.groovy.integration +Require-Bundle: org.eclipse.core.resources;bundle-version="[3.14.0,4.0.0)", + org.eclipse.core.runtime;bundle-version="[3.13.0,4.0.0)", + org.eclipse.core.filesystem;bundle-version="[1.7.0,2.0.0)", + org.eclipse.text;bundle-version="[3.6.0,4.0.0)", + org.eclipse.team.core;bundle-version="[3.1.0,4.0.0)";resolution:=optional +Bundle-RequiredExecutionEnvironment: JavaSE-11 +Eclipse-BuddyPolicy: registered +Eclipse-ExtensibleAPI: true +Bundle-ActivationPolicy: lazy +Automatic-Module-Name: org.eclipse.jdt.core diff --git a/jdt-patch/e422/org.eclipse.jdt.core/META-INF/eclipse.inf b/jdt-patch/e422/org.eclipse.jdt.core/META-INF/eclipse.inf new file mode 100644 index 0000000000..43380da055 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/META-INF/eclipse.inf @@ -0,0 +1,2 @@ +jarprocessor.exclude.children=true +jarprocessor.exclude.pack=true diff --git a/jdt-patch/e422/org.eclipse.jdt.core/about.html b/jdt-patch/e422/org.eclipse.jdt.core/about.html new file mode 100644 index 0000000000..f0810d12f3 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/about.html @@ -0,0 +1,42 @@ + + + + +About + + +

    About This Content

    + +

    November 30, 2017

    +

    License

    + +

    + The Eclipse Foundation makes available all content in this plug-in + ("Content"). Unless otherwise indicated below, the Content + is provided to you under the terms and conditions of the Eclipse + Public License Version 2.0 ("EPL"). A copy of the EPL is + available at http://www.eclipse.org/legal/epl-2.0. + For purposes of the EPL, "Program" will mean the Content. +

    + +

    + If you did not receive this Content directly from the Eclipse + Foundation, the Content is being redistributed by another party + ("Redistributor") and different terms and conditions may + apply to your use of any object code in the Content. Check the + Redistributor's license that was provided with the Content. If no such + license exists, contact the Redistributor. Unless otherwise indicated + below, the terms and conditions of the EPL still apply to any source + code in the Content and such source code may be obtained at http://www.eclipse.org. +

    + + +

    Disassembler

    +

    This plug-in contains a bytecode disassembler ("Disassembler") that can produce a listing of the Java assembler mnemonics ("Assembler Mnemonics") for a Java method. If you +use the Disassembler to view the Assembler Mnemonics for a method, you should ensure that doing so will not violate the terms of any licenses that apply to your use of that method, as +such licenses may not permit you to reverse engineer, decompile, or disassemble method bytecodes.

    + + + \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core/antadapter/META-INF/eclipse.inf b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/META-INF/eclipse.inf new file mode 100644 index 0000000000..4dc37a0f20 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/META-INF/eclipse.inf @@ -0,0 +1,2 @@ +jarprocessor.exclude.children=true +jarprocessor.exclude.pack=true \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/BuildJarIndex.java b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/BuildJarIndex.java new file mode 100644 index 0000000000..51d6be8c72 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/BuildJarIndex.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2011 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core; + +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.eclipse.jdt.core.index.JavaIndexer; +import org.eclipse.jdt.internal.antadapter.AntAdapterMessages; + +/** + *

    + * An Ant task to generate the index file for the given jar path. + *

    + *

    + * <eclipse.buildJarIndex jarPath="Test.jar" indexPath="Test.index"/> + *

    + *

    + * For more information on Ant check out the website at http://jakarta.apache.org/ant/ . + *

    + *

    + * This is not intended to be subclassed by users. + *

    + * @since 3.8 + */ +public class BuildJarIndex extends Task { + + private String jarPath; + private String indexPath; + + @Override + public void execute() throws BuildException { + if (this.jarPath == null) { + throw new BuildException(AntAdapterMessages.getString("buildJarIndex.jarFile.cannot.be.null")); //$NON-NLS-1$ + } + if (this.indexPath == null) { + throw new BuildException(AntAdapterMessages.getString("buildJarIndex.indexFile.cannot.be.null")); //$NON-NLS-1$ + } + + try { + JavaIndexer.generateIndexForJar(this.jarPath, this.indexPath); + } catch (IOException e) { + throw new BuildException(AntAdapterMessages.getString("buildJarIndex.ioexception.occured", e.getLocalizedMessage()), e); //$NON-NLS-1$ + } + } + + public void setJarPath(String path) { + this.jarPath = path; + } + + public void setIndexPath(String path) { + this.indexPath = path; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/CheckDebugAttributes.java b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/CheckDebugAttributes.java new file mode 100644 index 0000000000..9d38412df6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/CheckDebugAttributes.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2000, 2013 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core; + +import java.io.IOException; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.eclipse.jdt.core.util.IClassFileReader; +import org.eclipse.jdt.core.util.ICodeAttribute; +import org.eclipse.jdt.core.util.IMethodInfo; +import org.eclipse.jdt.internal.antadapter.AntAdapterMessages; + +/** + *

    An Ant task to find out if a class file or a jar contains debug attributes. If this is the case, + * the property contains the value "has debug" after the call. + *

    + *

    + * <eclipse.checkDebugAttributes property="hasDebug" file="${basedir}/bin/p/A.class"/> + *

    + *

    + * For more information on Ant check out the website at http://jakarta.apache.org/ant/ . + *

    + * + * This is not intended to be subclassed by users. + * @since 2.0 + */ +@SuppressWarnings("rawtypes") +public final class CheckDebugAttributes extends Task { + + private String file; + private String property; + + @Override + public void execute() throws BuildException { + if (this.file == null) { + throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.file.argument.cannot.be.null")); //$NON-NLS-1$ + } + if (this.property == null) { + throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.property.argument.cannot.be.null")); //$NON-NLS-1$ + } + try { + boolean hasDebugAttributes = false; + if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(this.file)) { + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(this.file, IClassFileReader.ALL); + hasDebugAttributes = checkClassFile(classFileReader); + } else { + ZipFile jarFile = null; + try { + jarFile = new ZipFile(this.file); + } catch (ZipException e) { + throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.file.argument.must.be.a.classfile.or.a.jarfile"), e); //$NON-NLS-1$ + } finally { + if (jarFile != null) { + jarFile.close(); + } + } + for (Enumeration entries = jarFile.entries(); !hasDebugAttributes && entries.hasMoreElements(); ) { + ZipEntry entry = (ZipEntry) entries.nextElement(); + if (org.eclipse.jdt.internal.compiler.util.Util.isClassFileName(entry.getName())) { + IClassFileReader classFileReader = ToolFactory.createDefaultClassFileReader(this.file, entry.getName(), IClassFileReader.ALL); + hasDebugAttributes = checkClassFile(classFileReader); + } + } + } + if (hasDebugAttributes) { + getProject().setUserProperty(this.property, "has debug"); //$NON-NLS-1$ + } + } catch (IOException e) { + throw new BuildException(AntAdapterMessages.getString("checkDebugAttributes.ioexception.occured") + this.file, e); //$NON-NLS-1$ + } + } + + private boolean checkClassFile(IClassFileReader classFileReader) { + IMethodInfo[] methodInfos = classFileReader.getMethodInfos(); + for (int i = 0, max = methodInfos.length; i < max; i++) { + ICodeAttribute codeAttribute = methodInfos[i].getCodeAttribute(); + if (codeAttribute != null && codeAttribute.getLineNumberAttribute() != null) { + return true; + } + } + return false; + } + + public void setFile(String value) { + this.file = value; + } + + public void setProperty(String value) { + this.property = value; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/JDTCompilerAdapter.java b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/JDTCompilerAdapter.java new file mode 100644 index 0000000000..033a106fa1 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/core/JDTCompilerAdapter.java @@ -0,0 +1,587 @@ +/******************************************************************************* + * Copyright (c) 2000, 2013 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Javac; +import org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Commandline.Argument; +import org.apache.tools.ant.util.JavaEnvUtils; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.antadapter.AntAdapterMessages; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; +import org.eclipse.jdt.internal.compiler.util.Util; + +/** + * Ant 1.5 compiler adapter for the Eclipse Java compiler. This adapter permits the + * Eclipse Java compiler to be used with the javac task in Ant scripts. In order + * to use it, just set the property build.compiler as follows: + *

    + * <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/> + *

    + *

    + * For more information on Ant check out the website at http://jakarta.apache.org/ant/ . + *

    + * + * @since 2.0 + */ +@SuppressWarnings({ "rawtypes", "unchecked" }) +public class JDTCompilerAdapter extends DefaultCompilerAdapter { + private static final char[] SEPARATOR_CHARS = new char[] { '/', '\\' }; + private static final char[] ADAPTER_PREFIX = "#ADAPTER#".toCharArray(); //$NON-NLS-1$ + private static final char[] ADAPTER_ENCODING = "ENCODING#".toCharArray(); //$NON-NLS-1$ + private static final char[] ADAPTER_ACCESS = "ACCESS#".toCharArray(); //$NON-NLS-1$ + private static String compilerClass = "org.eclipse.jdt.internal.compiler.batch.Main"; //$NON-NLS-1$ + String logFileName; + Map customDefaultOptions; + private Map fileEncodings = null; + private Map dirEncodings = null; + private List accessRules = null; + + /** + * Performs a compile using the JDT batch compiler + * @throws BuildException if anything wrong happen during the compilation + * @return boolean true if the compilation is ok, false otherwise + */ + @Override + public boolean execute() throws BuildException { + this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.usingJDTCompiler"), Project.MSG_VERBOSE); //$NON-NLS-1$ + Commandline cmd = setupJavacCommand(); + + try { + Class c = Class.forName(compilerClass); + Constructor batchCompilerConstructor = c.getConstructor(new Class[] { PrintWriter.class, PrintWriter.class, Boolean.TYPE, Map.class}); + Object batchCompilerInstance = batchCompilerConstructor.newInstance(new Object[] {new PrintWriter(System.out), new PrintWriter(System.err), Boolean.TRUE, this.customDefaultOptions}); + Method compile = c.getMethod("compile", new Class[] {String[].class}); //$NON-NLS-1$ + Object result = compile.invoke(batchCompilerInstance, new Object[] { cmd.getArguments()}); + final boolean resultValue = ((Boolean) result).booleanValue(); + if (!resultValue && this.logFileName != null) { + this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.error.compilationFailed", this.logFileName)); //$NON-NLS-1$ + } + return resultValue; + } catch (ClassNotFoundException cnfe) { + throw new BuildException(AntAdapterMessages.getString("ant.jdtadapter.error.cannotFindJDTCompiler"), cnfe); //$NON-NLS-1$ + } catch (Exception ex) { + throw new BuildException(ex); + } + } + + + @Override + protected Commandline setupJavacCommand() throws BuildException { + Commandline cmd = new Commandline(); + this.customDefaultOptions = new CompilerOptions().getMap(); + + Class javacClass = Javac.class; + + /* + * Read in the compiler arguments first since we might need to modify + * the classpath if any access rules were specified + */ + String [] compilerArgs = processCompilerArguments(javacClass); + + /* + * This option is used to never exit at the end of the ant task. + */ + cmd.createArgument().setValue("-noExit"); //$NON-NLS-1$ + + if (this.bootclasspath != null) { + cmd.createArgument().setValue("-bootclasspath"); //$NON-NLS-1$ + if (this.bootclasspath.size() != 0) { + /* + * Set the bootclasspath for the Eclipse compiler. + */ + cmd.createArgument().setPath(this.bootclasspath); + } else { + cmd.createArgument().setValue(Util.EMPTY_STRING); + } + } + + /* + * Eclipse compiler doesn't support -extdirs. + * It is emulated using the classpath. We add extdirs entries after the + * bootclasspath. + */ + if (this.extdirs != null) { + cmd.createArgument().setValue("-extdirs"); //$NON-NLS-1$ + cmd.createArgument().setPath(this.extdirs); + } + + Path classpath = new Path(this.project); + /* + * The java runtime is already handled, so we simply want to retrieve the + * ant runtime and the compile classpath. + */ + classpath.append(getCompileClasspath()); + /* + * Set the classpath for the Eclipse compiler. + */ + cmd.createArgument().setValue("-classpath"); //$NON-NLS-1$ + createClasspathArgument(cmd, classpath); + + // For -sourcepath, use the "sourcepath" value if present. + // Otherwise default to the "srcdir" value. + Path sourcepath = null; + + // retrieve the method getSourcepath() using reflect + // This is done to improve the compatibility to ant 1.5 + Method getSourcepathMethod = null; + try { + getSourcepathMethod = javacClass.getMethod("getSourcepath", (Class[]) null); //$NON-NLS-1$ + } catch(NoSuchMethodException e) { + // if not found, then we cannot use this method (ant 1.5) + } + Path compileSourcePath = null; + if (getSourcepathMethod != null) { + try { + compileSourcePath = (Path) getSourcepathMethod.invoke(this.attributes, (Object[]) null); + } catch (IllegalAccessException | InvocationTargetException e) { + // should never happen + } + } + if (compileSourcePath != null) { + sourcepath = compileSourcePath; + } else { + sourcepath = this.src; + } + cmd.createArgument().setValue("-sourcepath"); //$NON-NLS-1$ + createClasspathArgument(cmd, sourcepath); + + final String javaVersion = JavaEnvUtils.getJavaVersion(); + String memoryParameterPrefix = javaVersion.equals(JavaEnvUtils.JAVA_1_1) ? "-J-" : "-J-X";//$NON-NLS-1$//$NON-NLS-2$ + if (this.memoryInitialSize != null) { + if (!this.attributes.isForkedJavac()) { + this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.ignoringMemoryInitialSize"), Project.MSG_WARN); //$NON-NLS-1$ + } else { + cmd.createArgument().setValue(memoryParameterPrefix + + "ms" + this.memoryInitialSize); //$NON-NLS-1$ + } + } + + if (this.memoryMaximumSize != null) { + if (!this.attributes.isForkedJavac()) { + this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.ignoringMemoryMaximumSize"), Project.MSG_WARN); //$NON-NLS-1$ + } else { + cmd.createArgument().setValue(memoryParameterPrefix + + "mx" + this.memoryMaximumSize); //$NON-NLS-1$ + } + } + + if (this.debug) { + // retrieve the method getSourcepath() using reflect + // This is done to improve the compatibility to ant 1.5 + Method getDebugLevelMethod = null; + try { + getDebugLevelMethod = javacClass.getMethod("getDebugLevel", (Class[]) null); //$NON-NLS-1$ + } catch(NoSuchMethodException e) { + // if not found, then we cannot use this method (ant 1.5) + // debug level is only available with ant 1.5.x + } + String debugLevel = null; + if (getDebugLevelMethod != null) { + try { + debugLevel = (String) getDebugLevelMethod.invoke(this.attributes, (Object[]) null); + } catch (IllegalAccessException | InvocationTargetException e) { + // should never happen + } + } + if (debugLevel != null) { + this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); + this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE); + this.customDefaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute , CompilerOptions.DO_NOT_GENERATE); + if (debugLevel.length() != 0) { + if (debugLevel.indexOf("vars") != -1) {//$NON-NLS-1$ + this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); + } + if (debugLevel.indexOf("lines") != -1) {//$NON-NLS-1$ + this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE); + } + if (debugLevel.indexOf("source") != -1) {//$NON-NLS-1$ + this.customDefaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute , CompilerOptions.GENERATE); + } + } + } else { + this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); + this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE); + this.customDefaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute , CompilerOptions.GENERATE); + } + } else { + this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE); + this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE); + this.customDefaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute , CompilerOptions.DO_NOT_GENERATE); + } + + /* + * Handle the nowarn option. If none, then we generate all warnings. + */ + if (this.attributes.getNowarn()) { + // disable all warnings + Object[] entries = this.customDefaultOptions.entrySet().toArray(); + for (int i = 0, max = entries.length; i < max; i++) { + Map.Entry entry = (Map.Entry) entries[i]; + if (!(entry.getKey() instanceof String)) + continue; + if (!(entry.getValue() instanceof String)) + continue; + if (((String) entry.getValue()).equals(CompilerOptions.WARNING)) { + this.customDefaultOptions.put(entry.getKey(), CompilerOptions.IGNORE); + } + } + this.customDefaultOptions.put(CompilerOptions.OPTION_TaskTags, Util.EMPTY_STRING); + if (this.deprecation) { + this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ENABLED); + this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.ENABLED); + } + } else if (this.deprecation) { + this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ENABLED); + this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.ENABLED); + } else { + this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE); + this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.DISABLED); + this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.DISABLED); + } + + /* + * destDir option. + */ + if (this.destDir != null) { + cmd.createArgument().setValue("-d"); //$NON-NLS-1$ + cmd.createArgument().setFile(this.destDir.getAbsoluteFile()); + } + + /* + * verbose option + */ + if (this.verbose) { + cmd.createArgument().setValue("-verbose"); //$NON-NLS-1$ + } + + /* + * failnoerror option + */ + if (!this.attributes.getFailonerror()) { + cmd.createArgument().setValue("-proceedOnError"); //$NON-NLS-1$ + } + + /* + * target option. + */ + if (this.target != null) { + this.customDefaultOptions.put(CompilerOptions.OPTION_TargetPlatform, this.target); + } + + /* + * source option + */ + String source = this.attributes.getSource(); + if (source != null) { + this.customDefaultOptions.put(CompilerOptions.OPTION_Source, source); + this.customDefaultOptions.put(CompilerOptions.OPTION_Compliance, source); + } + + /* + * release option. + */ + if (this.release != null) { + this.customDefaultOptions.put(CompilerOptions.OPTION_Release, this.release); + } + + + if (compilerArgs != null) { + /* + * Add extra argument on the command line + */ + final int length = compilerArgs.length; + if (length != 0) { + for (int i = 0, max = length; i < max; i++) { + String arg = compilerArgs[i]; + if (this.logFileName == null && "-log".equals(arg) && ((i + 1) < max)) { //$NON-NLS-1$ + this.logFileName = compilerArgs[i + 1]; + } + cmd.createArgument().setValue(arg); + } + } + } + /* + * encoding option. javac task encoding property must be the last encoding on the command + * line as compiler arg might also specify an encoding. + */ + if (this.encoding != null) { + cmd.createArgument().setValue("-encoding"); //$NON-NLS-1$ + cmd.createArgument().setValue(this.encoding); + } + + /* + * Eclipse compiler doesn't have a -sourcepath option. This is + * handled through the javac task that collects all source files in + * srcdir option. + */ + logAndAddFilesToCompile(cmd); + return cmd; + } + + /** + * Get the compiler arguments + * @param javacClass + * @return String[] the array of arguments + */ + private String[] processCompilerArguments(Class javacClass) { + // retrieve the method getCurrentCompilerArgs() using reflect + // This is done to improve the compatibility to ant 1.5 + Method getCurrentCompilerArgsMethod = null; + try { + getCurrentCompilerArgsMethod = javacClass.getMethod("getCurrentCompilerArgs", (Class[]) null); //$NON-NLS-1$ + } catch (NoSuchMethodException e) { + // if not found, then we cannot use this method (ant 1.5) + // debug level is only available with ant 1.5.x + } + String[] compilerArgs = null; + if (getCurrentCompilerArgsMethod != null) { + try { + compilerArgs = (String[]) getCurrentCompilerArgsMethod.invoke(this.attributes, (Object[]) null); + } catch (IllegalAccessException | InvocationTargetException e) { + // should never happen + } + } + //check the compiler arguments for anything requiring extra processing + if (compilerArgs != null) checkCompilerArgs(compilerArgs); + return compilerArgs; + } + /** + * check the compiler arguments. + * Extract from files specified using @, lines marked with ADAPTER_PREFIX + * These lines specify information that needs to be interpreted by us. + * @param args compiler arguments to process + */ + private void checkCompilerArgs(String[] args) { + for (int i = 0; i < args.length; i++) { + if (args[i].charAt(0) == '@') { + try { + char[] content = Util.getFileCharContent(new File(args[i].substring(1)), null); + int offset = 0; + int prefixLength = ADAPTER_PREFIX.length; + while ((offset = CharOperation.indexOf(ADAPTER_PREFIX, content, true, offset)) > -1) { + int start = offset + prefixLength; + int end = CharOperation.indexOf('\n', content, start); + if (end == -1) + end = content.length; + while (CharOperation.isWhitespace(content[end])) { + end--; + } + + // end is inclusive, but in the API end is exclusive + if (CharOperation.equals(ADAPTER_ENCODING, content, start, start + ADAPTER_ENCODING.length)) { + CharOperation.replace(content, SEPARATOR_CHARS, File.separatorChar, start, end + 1); + // file or folder level custom encoding + start += ADAPTER_ENCODING.length; + int encodeStart = CharOperation.lastIndexOf('[', content, start, end); + if (start < encodeStart && encodeStart < end) { + boolean isFile = CharOperation.equals(SuffixConstants.SUFFIX_java, content, encodeStart - 5, encodeStart, false); + + String str = String.valueOf(content, start, encodeStart - start); + String enc = String.valueOf(content, encodeStart, end - encodeStart + 1); + if (isFile) { + if (this.fileEncodings == null) + this.fileEncodings = new HashMap(); + //use File to translate the string into a path with the correct File.seperator + this.fileEncodings.put(str, enc); + } else { + if (this.dirEncodings == null) + this.dirEncodings = new HashMap(); + this.dirEncodings.put(str, enc); + } + } + } else if (CharOperation.equals(ADAPTER_ACCESS, content, start, start + ADAPTER_ACCESS.length)) { + // access rules for the classpath + start += ADAPTER_ACCESS.length; + int accessStart = CharOperation.indexOf('[', content, start, end); + CharOperation.replace(content, SEPARATOR_CHARS, File.separatorChar, start, accessStart); + if (start < accessStart && accessStart < end) { + String path = String.valueOf(content, start, accessStart - start); + String access = String.valueOf(content, accessStart, end - accessStart + 1); + if (this.accessRules == null) + this.accessRules = new ArrayList(); + this.accessRules.add(path); + this.accessRules.add(access); + } + } + offset = end; + } + } catch (IOException e) { + //ignore + } + } + } + + } + + /** + * Copy the classpath to the command line with access rules included. + * @param cmd the given command line + * @param classpath the given classpath entry + */ + private void createClasspathArgument(Commandline cmd, Path classpath) { + Argument arg = cmd.createArgument(); + final String[] pathElements = classpath.list(); + + // empty path return empty string + if (pathElements.length == 0) { + arg.setValue(Util.EMPTY_STRING); + return; + } + + // no access rules, can set the path directly + if (this.accessRules == null) { + arg.setPath(classpath); + return; + } + + int rulesLength = this.accessRules.size(); + String[] rules = (String[]) this.accessRules.toArray(new String[rulesLength]); + int nextRule = 0; + final StringBuilder result = new StringBuilder(); + + //access rules are expected in the same order as the classpath, but there could + //be elements in the classpath not in the access rules or access rules not in the classpath + for (int i = 0, max = pathElements.length; i < max; i++) { + if (i > 0) + result.append(File.pathSeparatorChar); + String pathElement = pathElements[i]; + result.append(pathElement); + //the rules list is [path, rule, path, rule, ...] + for (int j = nextRule; j < rulesLength; j += 2) { + String rule = rules[j]; + if (pathElement.endsWith(rule)) { + result.append(rules[j + 1]); + nextRule = j + 2; + break; + } + // if the path doesn't match, it could be due to a trailing file separatorChar in the rule + if (rule.endsWith(File.separator)) { + // rule ends with the File.separator, but pathElement might not + // otherwise it would match on the first endsWith + int ruleLength = rule.length(); + if (pathElement.regionMatches(false, pathElement.length() - ruleLength + 1, rule, 0, ruleLength - 1)) { + result.append(rules[j + 1]); + nextRule = j + 2; + break; + } + } else if (pathElement.endsWith(File.separator)) { + // rule doesn't end with the File.separator, but pathElement might + int ruleLength = rule.length(); + if (pathElement.regionMatches(false, pathElement.length() - ruleLength - 1, rule, 0, ruleLength)) { + result.append(rules[j + 1]); + nextRule = j + 2; + break; + } + } + } + } + + arg.setValue(result.toString()); + } + /** + * Modified from base class, Logs the compilation parameters, adds the files + * to compile and logs the "niceSourceList" + * Appends encoding information at the end of arguments + * + * @param cmd the given command line + */ + @Override + protected void logAndAddFilesToCompile(Commandline cmd) { + this.attributes.log("Compilation " + cmd.describeArguments(), //$NON-NLS-1$ + Project.MSG_VERBOSE); + + StringBuilder niceSourceList = new StringBuilder("File"); //$NON-NLS-1$ + if (this.compileList.length != 1) { + niceSourceList.append("s"); //$NON-NLS-1$ + } + niceSourceList.append(" to be compiled:"); //$NON-NLS-1$ + niceSourceList.append(System.lineSeparator()); + + String[] encodedFiles = null, encodedDirs = null; + int encodedFilesLength = 0, encodedDirsLength = 0; + if (this.fileEncodings != null) { + encodedFilesLength = this.fileEncodings.size(); + encodedFiles = new String[encodedFilesLength]; + this.fileEncodings.keySet().toArray(encodedFiles); + } + if (this.dirEncodings != null) { + encodedDirsLength = this.dirEncodings.size(); + encodedDirs = new String[encodedDirsLength]; + this.dirEncodings.keySet().toArray(encodedDirs); + //we need the directories sorted, longest first,since sub directories can + //override encodings for their parent directories + Comparator comparator = new Comparator() { + @Override + public int compare(Object o1, Object o2) { + return ((String) o2).length() - ((String) o1).length(); + } + }; + Arrays.sort(encodedDirs, comparator); + } + + for (int i = 0; i < this.compileList.length; i++) { + String arg = this.compileList[i].getAbsolutePath(); + boolean encoded = false; + if (encodedFiles != null) { + //check for file level custom encoding + for (int j = 0; j < encodedFilesLength; j++) { + if (arg.endsWith(encodedFiles[j])) { + //found encoding, remove it from the list to speed things up next time around + arg = arg + (String) this.fileEncodings.get(encodedFiles[j]); + if (j < encodedFilesLength - 1) { + System.arraycopy(encodedFiles, j + 1, encodedFiles, j, encodedFilesLength - j - 1); + } + encodedFiles[--encodedFilesLength] = null; + encoded = true; + break; + } + } + } + if (!encoded && encodedDirs != null) { + //check folder level custom encoding + for (int j = 0; j < encodedDirsLength; j++) { + if (arg.lastIndexOf(encodedDirs[j]) != -1) { + arg = arg + (String) this.dirEncodings.get(encodedDirs[j]); + break; + } + } + } + cmd.createArgument().setValue(arg); + niceSourceList.append(" " + arg + System.lineSeparator()); //$NON-NLS-1$ + } + + this.attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/AntAdapterMessages.java b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/AntAdapterMessages.java new file mode 100644 index 0000000000..482f84d00f --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/AntAdapterMessages.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.antadapter; + +import java.text.MessageFormat; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class AntAdapterMessages { + + private static final String BUNDLE_NAME = "org.eclipse.jdt.internal.antadapter.messages"; //$NON-NLS-1$ + + private static ResourceBundle RESOURCE_BUNDLE; + + static { + try { + RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault()); + } catch(MissingResourceException e) { + System.out.println("Missing resource : " + BUNDLE_NAME.replace('.', '/') + ".properties for locale " + Locale.getDefault()); //$NON-NLS-1$//$NON-NLS-2$ + throw e; + } + } + + private AntAdapterMessages() { + // cannot be instantiated + } + + public static String getString(String key) { + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } + + public static String getString(String key, String argument) { + try { + String message = RESOURCE_BUNDLE.getString(key); + MessageFormat messageFormat = new MessageFormat(message); + return messageFormat.format(new String[] { argument } ); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/messages.properties b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/messages.properties new file mode 100644 index 0000000000..bf307a85ae --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/antadapter/org/eclipse/jdt/internal/antadapter/messages.properties @@ -0,0 +1,28 @@ +############################################################################### +# Copyright (c) 2000, 2011 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +### ant tasks messages. +ant.jdtadapter.info.usingJDTCompiler=Using JDT compiler +ant.jdtadapter.error.compilationFailed=Compilation failed. Compiler errors are available in {0} +ant.jdtadapter.error.cannotFindJDTCompiler=Cannot find the JDT compiler +ant.jdtadapter.info.ignoringMemoryInitialSize=Since fork is false, ignoring memoryInitialSize setting +ant.jdtadapter.info.ignoringMemoryMaximumSize=Since fork is false, ignoring memoryMaximumSize setting + +checkDebugAttributes.file.argument.cannot.be.null=The file argument cannot be null +checkDebugAttributes.property.argument.cannot.be.null=The property argument cannot be null +checkDebugAttributes.ioexception.occured=IOException occurred while reading +checkDebugAttributes.file.argument.must.be.a.classfile.or.a.jarfile=The file argument must be a .class or a .jar file + +buildJarIndex.jarFile.cannot.be.null=The jar file argument cannot be null +buildJarIndex.indexFile.cannot.be.null=The index file argument cannot be null +buildJarIndex.ioexception.occured=IOException - {0} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/core/compiler/batch/BatchCompiler.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/core/compiler/batch/BatchCompiler.java new file mode 100644 index 0000000000..7e4ca11bf2 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/core/compiler/batch/BatchCompiler.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2008, 2019 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.core.compiler.batch; + +import java.io.PrintWriter; + +import org.eclipse.jdt.core.compiler.CompilationProgress; +import org.eclipse.jdt.internal.compiler.batch.Main; + +/** + * A public API for invoking the Eclipse Compiler for Java. E.g. + *
    + * BatchCompiler.compile("C:\\mySources\\X.java -d C:\\myOutput", new PrintWriter(System.out), new PrintWriter(System.err), null);
    + * 
    + * + * @since 3.4 + * @noinstantiate This class is not intended to be instantiated by clients. + */ +public final class BatchCompiler { + + /** + * Invokes the Eclipse Compiler for Java with the given command line arguments, using the given writers + * to print messages, and reporting progress to the given compilation progress. Returns whether + * the compilation completed successfully. + *

    + * Reasons for a compilation failing to complete successfully include:

    + *
      + *
    • an error was reported
    • + *
    • a runtime exception occurred
    • + *
    • the compilation was canceled using the compilation progress
    • + *
    + *

    + * The specification of the command line arguments is defined by running the batch compiler's help + *

    BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);
    + * + * @param commandLine the command line arguments passed to the compiler + * @param outWriter the writer used to print standard messages + * @param errWriter the writer used to print error messages + * @param progress the object to report progress to and to provide cancellation, or null if no progress is needed + * @return whether the compilation completed successfully + */ + public static boolean compile(String commandLine, PrintWriter outWriter, PrintWriter errWriter, CompilationProgress progress) { + return compile(Main.tokenize(commandLine), outWriter, errWriter, progress); + } + + /** + * Invokes the Eclipse Compiler for Java with the given command line arguments, using the given writers + * to print messages, and reporting progress to the given compilation progress. Returns whether + * the compilation completed successfully. + *

    + * Reasons for a compilation failing to complete successfully include:

    + *
      + *
    • an error was reported
    • + *
    • a runtime exception occurred
    • + *
    • the compilation was canceled using the compilation progress
    • + *
    + *

    + * The specification of the command line arguments is defined by running the batch compiler's help + *

    BatchCompiler.compile("-help", new PrintWriter(System.out), new PrintWriter(System.err), null);
    + *

    + * Note that a true returned value indicates that no errors were reported, no runtime exceptions + * occurred and that the compilation was not canceled. + * + * @param commandLineArguments the command line arguments passed to the compiler + * @param outWriter the writer used to print standard messages + * @param errWriter the writer used to print error messages + * @param progress the object to report progress to and to provide cancellation, or null if no progress is needed + * @return whether the compilation completed successfully + */ + public static boolean compile(String[] commandLineArguments, PrintWriter outWriter, PrintWriter errWriter, CompilationProgress progress) { + return Main.compile(commandLineArguments, outWriter, errWriter, progress); + } + + private BatchCompiler() { + // prevent instantiation + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/core/compiler/batch/package.html b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/core/compiler/batch/package.html new file mode 100644 index 0000000000..cf3bc8ac2d --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/core/compiler/batch/package.html @@ -0,0 +1,16 @@ + + + + + + + Package-level Javadoc + + +This package contains the batch compiler API. +

    +Package Specification

    + +


    This package contains the batch compiler API. + + diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BasicModule.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BasicModule.java new file mode 100644 index 0000000000..2f027f835a --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BasicModule.java @@ -0,0 +1,252 @@ +/******************************************************************************* + * Copyright (c) 2016 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.util.Arrays; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.ast.ExportsStatement; +import org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration; +import org.eclipse.jdt.internal.compiler.ast.ModuleReference; +import org.eclipse.jdt.internal.compiler.ast.OpensStatement; +import org.eclipse.jdt.internal.compiler.ast.ProvidesStatement; +import org.eclipse.jdt.internal.compiler.ast.RequiresStatement; +import org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.eclipse.jdt.internal.compiler.ast.UsesStatement; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.IModulePathEntry; +import org.eclipse.jdt.internal.compiler.env.ISourceModule; +import org.eclipse.jdt.internal.compiler.env.ModuleReferenceImpl; +import org.eclipse.jdt.internal.compiler.env.PackageExportImpl; + +/** + * Retrofit a {@link ModuleDeclaration} into an {@link ISourceModule}. + * It remembers the underlying {@link ICompilationUnit} so the full structure + * can be recreated if needed. + */ +public class BasicModule implements ISourceModule { + static class Service implements IModule.IService { + char[] provides; + char[][] with; + @Override + public char[] name() { + return this.provides; + } + + @Override + public char[][] with() { + return this.with; + } + @Override + public String toString() { + StringBuilder buffer = new StringBuilder(); + buffer.append("provides"); //$NON-NLS-1$ + buffer.append(this.provides); + buffer.append(" with "); //$NON-NLS-1$ + buffer.append(this.with); + buffer.append(';'); + return buffer.toString(); + } + } + private static PackageExportImpl createPackageExport(ExportsStatement[] refs, int i) { + ExportsStatement ref = refs[i]; + PackageExportImpl exp = new PackageExportImpl(); + exp.pack = ref.pkgName; + ModuleReference[] imp = ref.targets; + if (imp != null) { + exp.exportedTo = new char[imp.length][]; + for(int j = 0; j < imp.length; j++) { + exp.exportedTo = imp[j].tokens; + } + } + return exp; + } + private static Service createService(TypeReference service, TypeReference[] with) { + Service ser = new Service(); + ser.provides = CharOperation.concatWith(service.getTypeName(), '.'); + ser.with = new char[with.length][]; + for (int i = 0; i < with.length; i++) { + ser.with[i] = CharOperation.concatWith(with[i].getTypeName(), '.'); + } + return ser; + } + private static PackageExportImpl createPackageOpen(OpensStatement ref) { + PackageExportImpl exp = new PackageExportImpl(); + exp.pack = ref.pkgName; + ModuleReference[] imp = ref.targets; + if (imp != null) { + exp.exportedTo = new char[imp.length][]; + for(int j = 0; j < imp.length; j++) { + exp.exportedTo = imp[j].tokens; + } + } + return exp; + } + + private boolean isOpen = false; + char[] name; + IModule.IModuleReference[] requires; + IModule.IPackageExport[] exports; + char[][] uses; + Service[] provides; + IModule.IPackageExport[] opens; + private ICompilationUnit compilationUnit; + + public BasicModule(ModuleDeclaration descriptor, IModulePathEntry root) { + this.compilationUnit = descriptor.compilationResult().compilationUnit; + this.name = descriptor.moduleName; + if (descriptor.requiresCount > 0) { + RequiresStatement[] refs = descriptor.requires; + this.requires = new ModuleReferenceImpl[refs.length]; + for (int i = 0; i < refs.length; i++) { + ModuleReferenceImpl ref = new ModuleReferenceImpl(); + ref.name = CharOperation.concatWith(refs[i].module.tokens, '.'); + ref.modifiers = refs[i].modifiers; + this.requires[i] = ref; + } + } else { + this.requires = new ModuleReferenceImpl[0]; + } + if (descriptor.exportsCount > 0) { + ExportsStatement[] refs = descriptor.exports; + this.exports = new PackageExportImpl[refs.length]; + for (int i = 0; i < refs.length; i++) { + PackageExportImpl exp = createPackageExport(refs, i); + this.exports[i] = exp; + } + } else { + this.exports = new PackageExportImpl[0]; + } + if (descriptor.usesCount > 0) { + UsesStatement[] u = descriptor.uses; + this.uses = new char[u.length][]; + for(int i = 0; i < u.length; i++) { + this.uses[i] = CharOperation.concatWith(u[i].serviceInterface.getTypeName(), '.'); + } + } + if (descriptor.servicesCount > 0) { + ProvidesStatement[] services = descriptor.services; + this.provides = new Service[descriptor.servicesCount]; + for (int i = 0; i < descriptor.servicesCount; i++) { + this.provides[i] = createService(services[i].serviceInterface, services[i].implementations); + } + } + if (descriptor.opensCount > 0) { + OpensStatement[] refs = descriptor.opens; + this.opens = new PackageExportImpl[refs.length]; + for (int i = 0; i < refs.length; i++) { + PackageExportImpl exp = createPackageOpen(refs[i]); + this.opens[i] = exp; + } + } else { + this.opens = new PackageExportImpl[0]; + } + this.isOpen = descriptor.isOpen(); + } + @Override + public ICompilationUnit getCompilationUnit() { + return this.compilationUnit; + } + @Override + public char[] name() { + return this.name; + } + @Override + public IModule.IModuleReference[] requires() { + return this.requires; + } + @Override + public IModule.IPackageExport[] exports() { + return this.exports; + } + @Override + public char[][] uses() { + return this.uses; + } + @Override + public IService[] provides() { + return this.provides; + } + @Override + public IModule.IPackageExport[] opens() { + return this.opens; + } + @Override + public boolean isOpen() { + return this.isOpen; + } + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof IModule)) + return false; + IModule mod = (IModule) o; + if (!CharOperation.equals(this.name, mod.name())) + return false; + return Arrays.equals(this.requires, mod.requires()); + } + @Override + public int hashCode() { + int result = 17; + int c = CharOperation.hashCode(this.name); + result = 31 * result + c; + c = Arrays.hashCode(this.requires); + result = 31 * result + c; + return result; + } + @Override + public String toString() { + StringBuffer buffer = new StringBuffer(getClass().getName()); + toStringContent(buffer); + return buffer.toString(); + } + protected void toStringContent(StringBuffer buffer) { + buffer.append("\nmodule "); //$NON-NLS-1$ + buffer.append(this.name).append(' '); + buffer.append('{').append('\n'); + if (this.requires != null) { + for(int i = 0; i < this.requires.length; i++) { + buffer.append("\trequires "); //$NON-NLS-1$ + if (this.requires[i].isTransitive()) { + buffer.append(" public "); //$NON-NLS-1$ + } + buffer.append(this.requires[i].name()); + buffer.append(';').append('\n'); + } + } + if (this.exports != null) { + buffer.append('\n'); + for(int i = 0; i < this.exports.length; i++) { + buffer.append("\texports "); //$NON-NLS-1$ + buffer.append(this.exports[i].toString()); + } + } + if (this.uses != null) { + buffer.append('\n'); + for (char[] cs : this.uses) { + buffer.append(cs); + buffer.append(';').append('\n'); + } + } + if (this.provides != null) { + buffer.append('\n'); + for(Service ser : this.provides) { + buffer.append(ser.toString()); + } + } + buffer.append('\n').append('}').toString(); + } +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BatchCompilerRequestor.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BatchCompilerRequestor.java new file mode 100644 index 0000000000..63530f38bd --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/BatchCompilerRequestor.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2014 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Gauthier JACQUES - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.ICompilerRequestor; + +public class BatchCompilerRequestor implements ICompilerRequestor { + + private Main compiler; + private int lineDelta = 0; + + public BatchCompilerRequestor(Main compiler) { + this.compiler = compiler; + } + + @Override + public void acceptResult(CompilationResult compilationResult) { + if (compilationResult.lineSeparatorPositions != null) { + int unitLineCount = compilationResult.lineSeparatorPositions.length; + this.lineDelta += unitLineCount; + if (this.compiler.showProgress && this.lineDelta > 2000) { + // in -log mode, dump a dot every 2000 lines compiled + this.compiler.logger.logProgress(); + this.lineDelta = 0; + } + } + this.compiler.logger.startLoggingSource(compilationResult); + if (compilationResult.hasProblems() || compilationResult.hasTasks()) { + this.compiler.logger.logProblems(compilationResult.getAllProblems(), compilationResult.compilationUnit.getContents(), this.compiler); + reportProblems(compilationResult); + } + this.compiler.outputClassFiles(compilationResult); + this.compiler.logger.endLoggingSource(); + } + + protected void reportProblems(CompilationResult result) { + // Nothing to do + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java new file mode 100644 index 0000000000..b59f9fc4bf --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathDirectory.java @@ -0,0 +1,392 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 440687 - [compiler][batch][null] improve command line option for external annotations + * Lars Vogel - Contributions for + * Bug 473178 + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import org.eclipse.jdt.core.compiler.CharOperation; +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.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationProvider; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.parser.ScannerHelper; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.internal.compiler.util.Util; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Stream; + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class ClasspathDirectory extends ClasspathLocation { + +private Hashtable directoryCache; +private String[] missingPackageHolder = new String[1]; +private int mode; // ability to only consider one kind of files (source vs. binaries), by default use both +private String encoding; // only useful if referenced in the source path +private Hashtable> packageSecondaryTypes = null; +Map options; + +ClasspathDirectory(File directory, String encoding, int mode, + AccessRuleSet accessRuleSet, String destinationPath, Map options) { + super(accessRuleSet, destinationPath); + this.mode = mode; + this.options = options; + try { + this.path = directory.getCanonicalPath(); + } catch (IOException e) { + // should not happen as we know that the file exists + this.path = directory.getAbsolutePath(); + } + if (!this.path.endsWith(File.separator)) + this.path += File.separator; + this.directoryCache = new Hashtable(11); + this.encoding = encoding; +} +String[] directoryList(String qualifiedPackageName) { + String[] dirList = (String[]) this.directoryCache.get(qualifiedPackageName); + if (dirList == this.missingPackageHolder) return null; // package exists in another classpath directory or jar + if (dirList != null) return dirList; + + File dir = new File(this.path + qualifiedPackageName); + notFound : if (dir.isDirectory()) { + // must protect against a case insensitive File call + // walk the qualifiedPackageName backwards looking for an uppercase character before the '/' + int index = qualifiedPackageName.length(); + int last = qualifiedPackageName.lastIndexOf(File.separatorChar); + while (--index > last && !ScannerHelper.isUpperCase(qualifiedPackageName.charAt(index))){/*empty*/} + if (index > last) { + if (last == -1) { + if (!doesFileExist(qualifiedPackageName, Util.EMPTY_STRING)) + break notFound; + } else { + String packageName = qualifiedPackageName.substring(last + 1); + String parentPackage = qualifiedPackageName.substring(0, last); + if (!doesFileExist(packageName, parentPackage)) + break notFound; + } + } + if ((dirList = dir.list()) == null) + dirList = CharOperation.NO_STRINGS; + this.directoryCache.put(qualifiedPackageName, dirList); + return dirList; + } + this.directoryCache.put(qualifiedPackageName, this.missingPackageHolder); + return null; +} +boolean doesFileExist(String fileName, String qualifiedPackageName) { + String[] dirList = directoryList(qualifiedPackageName); + if (dirList == null) return false; // most common case + + for (int i = dirList.length; --i >= 0;) + if (fileName.equals(dirList[i])) + return true; + return false; +} +@Override +public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) { + return null; +} +private NameEnvironmentAnswer findClassInternal(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + if (!isPackage(qualifiedPackageName, null)) return null; // most common case TODO(SHMOD): use module name from this.module? + String fileName = new String(typeName); + boolean binaryExists = ((this.mode & BINARY) != 0) && doesFileExist(fileName + SUFFIX_STRING_class, qualifiedPackageName); + boolean sourceExists = ((this.mode & SOURCE) != 0) && doesFileExist(fileName + SUFFIX_STRING_java, qualifiedPackageName); + if (sourceExists && !asBinaryOnly) { + String fullSourcePath = this.path + qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java; + CompilationUnit unit = new CompilationUnit(null, fullSourcePath, this.encoding, this.destinationPath); + unit.module = this.module == null ? null : this.module.name(); + if (!binaryExists) + return new NameEnvironmentAnswer(unit, + fetchAccessRestriction(qualifiedBinaryFileName)); + String fullBinaryPath = this.path + qualifiedBinaryFileName; + long binaryModified = new File(fullBinaryPath).lastModified(); + long sourceModified = new File(fullSourcePath).lastModified(); + if (sourceModified > binaryModified) + return new NameEnvironmentAnswer(unit, + fetchAccessRestriction(qualifiedBinaryFileName)); + } + if (binaryExists) { + try { + ClassFileReader reader = ClassFileReader.read(this.path + qualifiedBinaryFileName); + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=321115, package names are to be treated case sensitive. + String typeSearched = qualifiedPackageName.length() > 0 ? + qualifiedPackageName.replace(File.separatorChar, '/') + "/" + fileName //$NON-NLS-1$ + : fileName; + if (!CharOperation.equals(reader.getName(), typeSearched.toCharArray())) { + reader = null; + } + if (reader != null) { + char[] modName = reader.moduleName != null ? reader.moduleName : this.module != null ? this.module.name() : null; + return new NameEnvironmentAnswer( + reader, + fetchAccessRestriction(qualifiedBinaryFileName), + modName); + } + } catch (IOException | ClassFormatException e) { + // treat as if file is missing + } + } + return null; +} +public NameEnvironmentAnswer findSecondaryInClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) { + //"package-info" is a reserved class name and can never be a secondary type (it is much faster to stop the search here). + if(CharOperation.equals(TypeConstants.PACKAGE_INFO_NAME, typeName)) { + return null; + } + + String typeNameString = new String(typeName); + String moduleName = this.module != null ? String.valueOf(this.module.name()) : null; // TODO(SHMOD): test for ModuleBinding.ANY & UNNAMED + boolean prereqs = this.options != null && isPackage(qualifiedPackageName, moduleName) && ((this.mode & SOURCE) != 0) && doesFileExist(typeNameString + SUFFIX_STRING_java, qualifiedPackageName); + return prereqs ? null : findSourceSecondaryType(typeNameString, qualifiedPackageName, qualifiedBinaryFileName); /* only secondary types */ +} + +@Override +public boolean hasAnnotationFileFor(String qualifiedTypeName) { + int pos = qualifiedTypeName.lastIndexOf('/'); + if (pos != -1 && (pos + 1 < qualifiedTypeName.length())) { + String fileName = qualifiedTypeName.substring(pos + 1) + ExternalAnnotationProvider.ANNOTATION_FILE_SUFFIX; + return doesFileExist(fileName, qualifiedTypeName.substring(0, pos)); + } + return false; +} +@Override +public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { + return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false); +} +@Override +public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + if (File.separatorChar == '/') + return findClassInternal(typeName, qualifiedPackageName, qualifiedBinaryFileName, asBinaryOnly); + + return findClassInternal(typeName, qualifiedPackageName.replace('/', File.separatorChar), + qualifiedBinaryFileName.replace('/', File.separatorChar), asBinaryOnly); +} +/** + * Add all the secondary types in the package + */ +private Hashtable getSecondaryTypes(String qualifiedPackageName) { + Hashtable packageEntry = new Hashtable<>(); + + String[] dirList = (String[]) this.directoryCache.get(qualifiedPackageName); + if (dirList == this.missingPackageHolder // package exists in another classpath directory or jar + || dirList == null) + return packageEntry; + + File dir = new File(this.path + qualifiedPackageName); + File[] listFiles = dir.isDirectory() ? dir.listFiles() : null; + if (listFiles == null) return packageEntry; + + for (int i = 0, l = listFiles.length; i < l; ++i) { + File f = listFiles[i]; + if (f.isDirectory()) continue; + String s = f.getAbsolutePath(); + if (s == null) continue; + if (!(s.endsWith(SUFFIX_STRING_java) || s.endsWith(SUFFIX_STRING_JAVA))) continue; + CompilationUnit cu = new CompilationUnit(null, s, this.encoding, this.destinationPath); + CompilationResult compilationResult = new CompilationResult(s.toCharArray(), 1, 1, 10); + ProblemReporter problemReporter = + new ProblemReporter( + DefaultErrorHandlingPolicies.proceedWithAllProblems(), + new CompilerOptions(this.options), + new DefaultProblemFactory()); + Parser parser = new Parser(problemReporter, false); + parser.reportSyntaxErrorIsRequired = false; + + CompilationUnitDeclaration unit = parser.parse(cu, compilationResult); + org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = unit != null ? unit.types : null; + if (types == null) continue; + for (int j = 0, k = types.length; j < k; j++) { + TypeDeclaration type = types[j]; + char[] name = type.isSecondary() ? type.name : null; // add only secondary types + if (name != null) + packageEntry.put(new String(name), s); + } + } + return packageEntry; +} +private NameEnvironmentAnswer findSourceSecondaryType(String typeName, String qualifiedPackageName, String qualifiedBinaryFileName) { + + if (this.packageSecondaryTypes == null) this.packageSecondaryTypes = new Hashtable<>(); + Hashtable packageEntry = this.packageSecondaryTypes.get(qualifiedPackageName); + if (packageEntry == null) { + packageEntry = getSecondaryTypes(qualifiedPackageName); + this.packageSecondaryTypes.put(qualifiedPackageName, packageEntry); + } + String fileName = packageEntry.get(typeName); + return fileName != null ? new NameEnvironmentAnswer(new CompilationUnit(null, + fileName, this.encoding, this.destinationPath), + fetchAccessRestriction(qualifiedBinaryFileName)) : null; +} + + +@Override +public char[][][] findTypeNames(String qualifiedPackageName, String moduleName) { + if (!isPackage(qualifiedPackageName, moduleName)) { + return null; // most common case + } + File dir = new File(this.path + qualifiedPackageName); + if (!dir.exists() || !dir.isDirectory()) { + return null; + } + String[] listFiles = dir.list(new FilenameFilter() { + @Override + public boolean accept(File directory1, String name) { + String fileName = name.toLowerCase(); + return fileName.endsWith(".class") || fileName.endsWith(".java"); //$NON-NLS-1$ //$NON-NLS-2$ + } + }); + int length; + if (listFiles == null || (length = listFiles.length) == 0) { + return null; + } + Set secondary = getSecondaryTypes(qualifiedPackageName).keySet(); + char[][][] result = new char[length + secondary.size()][][]; + char[][] packageName = CharOperation.splitOn(File.separatorChar, qualifiedPackageName.toCharArray()); + for (int i = 0; i < length; i++) { + String fileName = listFiles[i]; + int indexOfLastDot = fileName.indexOf('.'); + String typeName = indexOfLastDot > 0 ? fileName.substring(0, indexOfLastDot) : fileName; + result[i] = CharOperation.arrayConcat(packageName, typeName.toCharArray()); + } + if (secondary.size() > 0) { + int idx = length; + for (String type : secondary) { + result[idx++] = CharOperation.arrayConcat(packageName, type.toCharArray()); + } + } + return result; +} +@Override +public void initialize() throws IOException { + // nothing to do +} +@Override +public char[][] getModulesDeclaringPackage(String qualifiedPackageName, /*@Nullable*/String moduleName) { + String qp2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar); + return singletonModuleNameIf(directoryList(qp2) != null); +} +@Override +public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName) { + String qp2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar); + String[] dirList = directoryList(qp2); + if (dirList != null) { + for (String entry : dirList) { + String entryLC = entry.toLowerCase(); + if (entryLC.endsWith(SUFFIX_STRING_java) || entryLC.endsWith(SUFFIX_STRING_class)) + return true; + } + } + return false; +} +@Override +public boolean hasCUDeclaringPackage(String qualifiedPackageName, Function pkgNameExtractor) { + String qp2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar); + String[] directoryList = directoryList(qp2); + if(directoryList == null) + return false; + return Stream.of(directoryList).anyMatch(entry -> { + String entryLC = entry.toLowerCase(); + boolean hasDeclaration = false; + String fullPath = this.path + qp2 + "/" + entry; //$NON-NLS-1$ + String pkgName = null; + if (entryLC.endsWith(SUFFIX_STRING_class)) { + return true; + } else if (entryLC.endsWith(SUFFIX_STRING_java)) { + CompilationUnit cu = new CompilationUnit(null, fullPath, this.encoding); + pkgName = pkgNameExtractor.apply(cu); + } + if (pkgName != null && pkgName.equals(qp2.replace(File.separatorChar, '.'))) + hasDeclaration = true; + return hasDeclaration; + }); +} + +@Override +public char[][] listPackages() { + Set packageNames = new HashSet<>(); + try { + Path basePath = FileSystems.getDefault().getPath(this.path); + Files.walkFileTree(basePath, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { + if (file.toString().toLowerCase().endsWith(SUFFIX_STRING_class)) { + packageNames.add(file.getParent().relativize(basePath).toString().replace('/', '.')); + } + return FileVisitResult.CONTINUE; + } + }); + } catch (IOException e) { + // treat as if files are missing + } + return packageNames.stream().map(String::toCharArray).toArray(char[][]::new); +} + +@Override +public void reset() { + super.reset(); + this.directoryCache = new Hashtable(11); +} +@Override +public String toString() { + return "ClasspathDirectory " + this.path; //$NON-NLS-1$ +} +@Override +public char[] normalizedPath() { + if (this.normalizedPath == null) { + this.normalizedPath = this.path.toCharArray(); + if (File.separatorChar == '\\') { + CharOperation.replace(this.normalizedPath, '\\', '/'); + } + } + return this.normalizedPath; +} +@Override +public String getPath() { + return this.path; +} +@Override +public int getMode() { + return this.mode; +} +@Override +public IModule getModule() { + return this.module; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java new file mode 100644 index 0000000000..f04669c6cf --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java @@ -0,0 +1,336 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 440477 - [null] Infrastructure for feeding external annotations into compilation + * Bug 440687 - [compiler][batch][null] improve command line option for external annotations + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationDecorator; +import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationProvider; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.env.IBinaryType; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.ExternalAnnotationStatus; +import org.eclipse.jdt.internal.compiler.util.ManifestAnalyzer; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; +import org.eclipse.jdt.internal.compiler.util.Util; + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class ClasspathJar extends ClasspathLocation { + +protected File file; +protected ZipFile zipFile; +protected ZipFile annotationZipFile; +protected boolean closeZipFileAtEnd; +protected Set packageCache; +protected List annotationPaths; + +public ClasspathJar(File file, boolean closeZipFileAtEnd, + AccessRuleSet accessRuleSet, String destinationPath) { + super(accessRuleSet, destinationPath); + this.file = file; + this.closeZipFileAtEnd = closeZipFileAtEnd; +} + +@Override +public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) { + // expected to be called once only - if multiple calls desired, consider + // using a cache + InputStream inputStream = null; + try { + initialize(); + ArrayList result = new ArrayList<>(); + ZipEntry manifest = this.zipFile.getEntry(TypeConstants.META_INF_MANIFEST_MF); + if (manifest != null) { // non-null implies regular file + inputStream = this.zipFile.getInputStream(manifest); + ManifestAnalyzer analyzer = new ManifestAnalyzer(); + boolean success = analyzer.analyzeManifestContents(inputStream); + List calledFileNames = analyzer.getCalledFileNames(); + if (problemReporter != null) { + if (!success || analyzer.getClasspathSectionsCount() == 1 && calledFileNames == null) { + problemReporter.invalidClasspathSection(getPath()); + } else if (analyzer.getClasspathSectionsCount() > 1) { + problemReporter.multipleClasspathSections(getPath()); + } + } + if (calledFileNames != null) { + Iterator calledFilesIterator = calledFileNames.iterator(); + String directoryPath = getPath(); + int lastSeparator = directoryPath.lastIndexOf(File.separatorChar); + directoryPath = directoryPath.substring(0, lastSeparator + 1); // potentially empty (see bug 214731) + while (calledFilesIterator.hasNext()) { + result.add(new ClasspathJar(new File(directoryPath + (String) calledFilesIterator.next()), this.closeZipFileAtEnd, this.accessRuleSet, this.destinationPath)); + } + } + } + return result; + } catch (IOException | IllegalArgumentException e) { + // JRE 9 could throw an IAE if the path is incorrect. We are to ignore such + // linked jars + return null; + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + // best effort + } + } + } +} +@Override +public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { + return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false); +} +@Override +public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + if (!isPackage(qualifiedPackageName, moduleName)) + return null; // most common case + + try { + IBinaryType reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName); + if (reader != null) { + char[] modName = this.module == null ? null : this.module.name(); + if (reader instanceof ClassFileReader) { + ClassFileReader classReader = (ClassFileReader) reader; + if (classReader.moduleName == null) + classReader.moduleName = modName; + else + modName = classReader.moduleName; + } + searchPaths: + if (this.annotationPaths != null) { + String qualifiedClassName = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length()-SuffixConstants.EXTENSION_CLASS.length()-1); + for (String annotationPath : this.annotationPaths) { + try { + if (this.annotationZipFile == null) { + this.annotationZipFile = ExternalAnnotationDecorator.getAnnotationZipFile(annotationPath, null); + } + reader = ExternalAnnotationDecorator.create(reader, annotationPath, qualifiedClassName, this.annotationZipFile); + + if (reader.getExternalAnnotationStatus() == ExternalAnnotationStatus.TYPE_IS_ANNOTATED) { + break searchPaths; + } + } catch (IOException e) { + // don't let error on annotations fail class reading + } + } + // location is configured for external annotations, but no .eea found, decorate in order to answer NO_EEA_FILE: + reader = new ExternalAnnotationDecorator(reader, null); + } + return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName), modName); + } + } catch (ClassFormatException | IOException e) { + // treat as if class file is missing + } + return null; +} +@Override +public boolean hasAnnotationFileFor(String qualifiedTypeName) { + if (this.zipFile == null) + return false; + return this.zipFile.getEntry(qualifiedTypeName+ExternalAnnotationProvider.ANNOTATION_FILE_SUFFIX) != null; +} +@Override +public char[][][] findTypeNames(final String qualifiedPackageName, String moduleName) { + if (!isPackage(qualifiedPackageName, moduleName)) + return null; // most common case + final char[] packageArray = qualifiedPackageName.toCharArray(); + final ArrayList answers = new ArrayList(); + nextEntry : for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { + String fileName = ((ZipEntry) e.nextElement()).getName(); + + // add the package name & all of its parent packages + int last = fileName.lastIndexOf('/'); + if (last > 0) { + // extract the package name + String packageName = fileName.substring(0, last); + if (!qualifiedPackageName.equals(packageName)) + continue nextEntry; + int indexOfDot = fileName.lastIndexOf('.'); + if (indexOfDot != -1) { + String typeName = fileName.substring(last + 1, indexOfDot); + answers.add( + CharOperation.arrayConcat( + CharOperation.splitOn('/', packageArray), + typeName.toCharArray())); + } + } + } + int size = answers.size(); + if (size != 0) { + char[][][] result = new char[size][][]; + answers.toArray(result); + return result; + } + return null; +} + +@Override +public void initialize() throws IOException { + if (this.zipFile == null) { + this.zipFile = new ZipFile(this.file); + } +} +void acceptModule(ClassFileReader reader) { + if (reader != null) { + acceptModule(reader.getModuleDeclaration()); + } +} +void acceptModule(byte[] content) { + if (content == null) + return; + ClassFileReader reader = null; + try { + reader = new ClassFileReader(content, IModule.MODULE_INFO_CLASS.toCharArray()); + } catch (ClassFormatException e) { + e.printStackTrace(); + } + if (reader != null && reader.getModuleDeclaration() != null) { + acceptModule(reader); + } +} +protected void addToPackageCache(String fileName, boolean endsWithSep) { + int last = endsWithSep ? fileName.length() : fileName.lastIndexOf('/'); + while (last > 0) { + // extract the package name + String packageName = fileName.substring(0, last); + if (this.packageCache.contains(packageName)) + return; + this.packageCache.add(packageName); + last = packageName.lastIndexOf('/'); + } +} +@Override +public synchronized char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { + if (this.packageCache != null) + return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); + + this.packageCache = new HashSet<>(41); + this.packageCache.add(Util.EMPTY_STRING); + + for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { + String fileName = ((ZipEntry) e.nextElement()).getName(); + addToPackageCache(fileName, false); + } + return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); +} +@Override +public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName) { + qualifiedPackageName += '/'; + for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { + String fileName = e.nextElement().getName(); + if (fileName.startsWith(qualifiedPackageName) && fileName.length() > qualifiedPackageName.length()) { + String tail = fileName.substring(qualifiedPackageName.length()); + if (tail.indexOf('/') != -1) + continue; + if (tail.toLowerCase().endsWith(SUFFIX_STRING_class)) + return true; + } + } + return false; +} + +@Override +public char[][] listPackages() { + Set packageNames = new HashSet<>(); + for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { + String fileName = e.nextElement().getName(); + int lastSlash = fileName.lastIndexOf('/'); + if (lastSlash != -1 && fileName.toLowerCase().endsWith(SUFFIX_STRING_class)) + packageNames.add(fileName.substring(0, lastSlash).replace('/', '.')); + } + return packageNames.stream().map(String::toCharArray).toArray(char[][]::new); +} + +@Override +public void reset() { + super.reset(); + if (this.closeZipFileAtEnd) { + if (this.zipFile != null) { + try { + this.zipFile.close(); + } catch(IOException e) { + // ignore + } + this.zipFile = null; + } + if (this.annotationZipFile != null) { + try { + this.annotationZipFile.close(); + } catch(IOException e) { + // ignore + } + this.annotationZipFile = null; + } + } + this.packageCache = null; + this.annotationPaths = null; +} +@Override +public String toString() { + return "Classpath for jar file " + this.file.getPath(); //$NON-NLS-1$ +} +@Override +public char[] normalizedPath() { + if (this.normalizedPath == null) { + String path2 = this.getPath(); + char[] rawName = path2.toCharArray(); + if (File.separatorChar == '\\') { + CharOperation.replace(rawName, '\\', '/'); + } + this.normalizedPath = CharOperation.subarray(rawName, 0, CharOperation.lastIndexOf('.', rawName)); + } + return this.normalizedPath; +} +@Override +public String getPath() { + if (this.path == null) { + try { + this.path = this.file.getCanonicalPath(); + } catch (IOException e) { + // in case of error, simply return the absolute path + this.path = this.file.getAbsolutePath(); + } + } + return this.path; +} +@Override +public int getMode() { + return BINARY; +} + +@Override +public IModule getModule() { + return this.module; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java new file mode 100644 index 0000000000..19346c2482 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247.java @@ -0,0 +1,304 @@ +/******************************************************************************* + * Copyright (c) 2018, 2021 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.DirectoryStream; +import java.nio.file.FileSystemAlreadyExistsException; +import java.nio.file.FileSystemNotFoundException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.util.CtSym; +import org.eclipse.jdt.internal.compiler.util.JRTUtil; +import org.eclipse.jdt.internal.compiler.util.Util; + +public class ClasspathJep247 extends ClasspathJrt { + + protected java.nio.file.FileSystem fs = null; + protected String compliance = null; + protected long jdklevel; + protected String releaseInHex = null; + protected String[] subReleases = null; + protected Path releasePath = null; + protected Set packageCache; + protected File jdkHome; + protected String modulePath = null; + + public ClasspathJep247(File jdkHome, String release, AccessRuleSet accessRuleSet) { + super(jdkHome, false, accessRuleSet, null); + this.compliance = release; + this.jdklevel = CompilerOptions.releaseToJDKLevel(this.compliance); + this.jdkHome = jdkHome; + this.file = new File(new File(jdkHome, "lib"), "jrt-fs.jar"); //$NON-NLS-1$ //$NON-NLS-2$ + } + @Override + public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) { + return null; + } + @Override + public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { + return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false); + } + @Override + public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + if (!isPackage(qualifiedPackageName, moduleName)) + return null; // most common case + + try { + //TODO: Check if any conversion needed for path separator + ClassFileReader reader = null; + byte[] content = null; + qualifiedBinaryFileName = qualifiedBinaryFileName.replace(".class", ".sig"); //$NON-NLS-1$ //$NON-NLS-2$ + if (this.subReleases != null && this.subReleases.length > 0) { + for (String rel : this.subReleases) { + Path p = this.fs.getPath(rel, qualifiedBinaryFileName); + if (Files.exists(p)) { + content = JRTUtil.safeReadBytes(p); + if (content != null) + break; + } + } + } else { + content = JRTUtil.safeReadBytes(this.fs.getPath(this.releaseInHex, qualifiedBinaryFileName)); + } + if (content != null) { + reader = new ClassFileReader(content, qualifiedBinaryFileName.toCharArray()); + char[] modName = moduleName != null ? moduleName.toCharArray() : null; + return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName), modName); + } + } catch (ClassFormatException | IOException e) { + // continue + } + return null; + } + + @Override + public void initialize() throws IOException { + if (this.compliance == null) { + return; + } + this.releaseInHex = CtSym.getReleaseCode(this.compliance); + Path filePath = this.jdkHome.toPath().resolve("lib").resolve("ct.sym"); //$NON-NLS-1$ //$NON-NLS-2$ + URI t = filePath.toUri(); + if (!Files.exists(filePath)) { + return; + } + URI uri = URI.create("jar:file:" + t.getRawPath()); //$NON-NLS-1$ + try { + this.fs = FileSystems.getFileSystem(uri); + } catch(FileSystemNotFoundException fne) { + // Ignore and move on + } + if (this.fs == null) { + HashMap env = new HashMap<>(); + try { + this.fs = FileSystems.newFileSystem(uri, env); + } catch (FileSystemAlreadyExistsException e) { + this.fs = FileSystems.getFileSystem(uri); + } + } + this.releasePath = this.fs.getPath("/"); //$NON-NLS-1$ + if (!Files.exists(this.fs.getPath(this.releaseInHex))) { + throw new IllegalArgumentException("release " + this.compliance + " is not found in the system"); //$NON-NLS-1$//$NON-NLS-2$ + } + super.initialize(); + } + @Override + public void loadModules() { + // Modules below level 9 are not dealt with here. Leave it to ClasspathJrt + if (this.jdklevel <= ClassFileConstants.JDK1_8) { + super.loadModules(); + return; + } + final Path modPath = this.fs.getPath(this.releaseInHex + "-modules"); //$NON-NLS-1$ + if (!Files.exists(modPath)) { + throw new IllegalArgumentException("release " + this.compliance + " is not found in the system"); //$NON-NLS-1$//$NON-NLS-2$ + } + this.modulePath = this.file.getPath() + "|" + modPath.toString(); //$NON-NLS-1$ + Map cache = ModulesCache.get(this.modulePath); + if (cache == null) { + try (DirectoryStream stream = Files.newDirectoryStream(modPath)) { + HashMap newCache = new HashMap<>(); + for (final java.nio.file.Path subdir: stream) { + Files.walkFileTree(subdir, new FileVisitor() { + + @Override + public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) + throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) throws IOException { + byte[] content = null; + if (Files.exists(f)) { + content = JRTUtil.safeReadBytes(f); + if (content == null) + return FileVisitResult.CONTINUE; + ClasspathJep247.this.acceptModule(content, newCache); + ClasspathJep247.this.moduleNamesCache.add(JRTUtil.sanitizedFileName(f)); + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + }); + } + synchronized(ModulesCache) { + if (ModulesCache.get(this.modulePath) == null) { + ModulesCache.put(this.modulePath, Collections.unmodifiableMap(newCache)); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } else { + this.moduleNamesCache.addAll(cache.keySet()); + } + } + @Override + void acceptModule(ClassFileReader reader, Map cache) { + // Modules below level 9 are not dealt with here. Leave it to ClasspathJrt + if (this.jdklevel <= ClassFileConstants.JDK1_8) { + super.acceptModule(reader, cache); + return; + } + if (reader != null) { + IModule moduleDecl = reader.getModuleDeclaration(); + if (moduleDecl != null) { + cache.put(String.valueOf(moduleDecl.name()), moduleDecl); + } + } + } + protected void addToPackageCache(String packageName, boolean endsWithSep) { + if (this.packageCache.contains(packageName)) + return; + this.packageCache.add(packageName); + } + @Override + public synchronized char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { + if (this.packageCache == null) { + this.packageCache = new HashSet<>(41); + this.packageCache.add(Util.EMPTY_STRING); + List sub = new ArrayList<>(); + try (DirectoryStream stream = Files.newDirectoryStream(this.releasePath)) { + for (final java.nio.file.Path subdir: stream) { + String rel = JRTUtil.sanitizedFileName(subdir); + if (rel.contains(this.releaseInHex)) { + sub.add(rel); + } else { + continue; + } + Files.walkFileTree(subdir, new FileVisitor() { + @Override + public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) throws IOException { + if (dir.getNameCount() <= 1) + return FileVisitResult.CONTINUE; + Path relative = dir.subpath(1, dir.getNameCount()); + addToPackageCache(relative.toString(), false); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + }); + } + } catch (IOException e) { + e.printStackTrace(); + // Rethrow + } + this.subReleases = sub.toArray(new String[sub.size()]); + } + if (moduleName == null) { + // Delegate to the boss, even if it means inaccurate error reporting at times + List mods = JRTUtil.getModulesDeclaringPackage(this.file, qualifiedPackageName, moduleName); + return CharOperation.toCharArrays(mods); + } + return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); + } + + @Override + public String toString() { + return "Classpath for JEP 247 for JDK " + this.file.getPath(); //$NON-NLS-1$ + } + @Override + public char[] normalizedPath() { + if (this.normalizedPath == null) { + String path2 = this.getPath(); + char[] rawName = path2.toCharArray(); + if (File.separatorChar == '\\') { + CharOperation.replace(rawName, '\\', '/'); + } + this.normalizedPath = CharOperation.subarray(rawName, 0, CharOperation.lastIndexOf('.', rawName)); + } + return this.normalizedPath; + } + @Override + public String getPath() { + if (this.path == null) { + try { + this.path = this.file.getCanonicalPath(); + } catch (IOException e) { + // in case of error, simply return the absolute path + this.path = this.file.getAbsolutePath(); + } + } + return this.path; + } + @Override + public int getMode() { + return BINARY; + } + +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java new file mode 100644 index 0000000000..67efa5e0f9 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJep247Jdk12.java @@ -0,0 +1,316 @@ +/******************************************************************************* + * Copyright (c) 2019, 2021 IBM Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.DirectoryStream; +import java.nio.file.FileSystemNotFoundException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.util.CtSym; +import org.eclipse.jdt.internal.compiler.util.JRTUtil; +import org.eclipse.jdt.internal.compiler.util.Util; + +public class ClasspathJep247Jdk12 extends ClasspathJep247 { + + Map modules; + static String MODULE_INFO = "module-info.sig"; //$NON-NLS-1$ + + public ClasspathJep247Jdk12(File jdkHome, String release, AccessRuleSet accessRuleSet) { + super(jdkHome, release, accessRuleSet); + } + @Override + public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) { + return null; + } + @Override + public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { + return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false); + } + @Override + public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + if (!isPackage(qualifiedPackageName, moduleName)) + return null; // most common case + + try { + ClassFileReader reader = null; + byte[] content = null; + char[] foundModName = null; + qualifiedBinaryFileName = qualifiedBinaryFileName.replace(".class", ".sig"); //$NON-NLS-1$ //$NON-NLS-2$ + if (this.subReleases != null && this.subReleases.length > 0) { + done: for (String rel : this.subReleases) { + if (moduleName == null) { + Path p = this.fs.getPath(rel); + try (DirectoryStream stream = Files.newDirectoryStream(p)) { + for (final java.nio.file.Path subdir: stream) { + Path f = this.fs.getPath(rel, JRTUtil.sanitizedFileName(subdir), qualifiedBinaryFileName); + if (Files.exists(f)) { + content = JRTUtil.safeReadBytes(f); + foundModName = JRTUtil.sanitizedFileName(subdir).toCharArray(); + if (content != null) + break done; + } + } + } + } else { + Path p = this.fs.getPath(rel, moduleName, qualifiedBinaryFileName); + if (Files.exists(p)) { + content = JRTUtil.safeReadBytes(p); + if (content != null) + break; + } + } + } + } else { + content = JRTUtil.safeReadBytes(this.fs.getPath(this.releaseInHex, qualifiedBinaryFileName)); + } + if (content != null) { + reader = new ClassFileReader(content, qualifiedBinaryFileName.toCharArray()); + char[] modName = moduleName != null ? moduleName.toCharArray() : foundModName; + return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName), modName); + } + } catch (ClassFormatException | IOException e) { + // continue + } + return null; + } + + @Override + public void initialize() throws IOException { + if (this.compliance == null) { + return; + } + if (this.fs != null) { + super.initialize(); + return; + } + this.releaseInHex = CtSym.getReleaseCode(this.compliance); + Path filePath = this.jdkHome.toPath().resolve("lib").resolve("ct.sym"); //$NON-NLS-1$ //$NON-NLS-2$ + URI t = filePath.toUri(); + if (!Files.exists(filePath)) { + return; + } + URI uri = URI.create("jar:file:" + t.getRawPath()); //$NON-NLS-1$ + try { + this.fs = FileSystems.getFileSystem(uri); + } catch(FileSystemNotFoundException fne) { + // Ignore and move on + } + if (this.fs == null) { + HashMap env = new HashMap<>(); + this.fs = FileSystems.newFileSystem(uri, env); + } + this.releasePath = this.fs.getPath("/"); //$NON-NLS-1$ + if (!Files.exists(this.fs.getPath(this.releaseInHex))) { + throw new IllegalArgumentException("release " + this.compliance + " is not found in the system"); //$NON-NLS-1$//$NON-NLS-2$ + } + List sub = new ArrayList<>(); + try (DirectoryStream stream = Files.newDirectoryStream(this.releasePath)) { + for (final java.nio.file.Path subdir: stream) { + String rel = JRTUtil.sanitizedFileName(subdir); + if (rel.contains(this.releaseInHex)) + sub.add(rel); + } + this.subReleases = sub.toArray(new String[sub.size()]); + } catch (IOException e) { + //e.printStackTrace(); + } + super.initialize(); + } + @Override + public void loadModules() { + // Modules below level 9 are not dealt with here. Leave it to ClasspathJrt + if (this.jdklevel <= ClassFileConstants.JDK1_8) { + super.loadModules(); + return; + } + final Path modPath = this.fs.getPath(this.releaseInHex); + this.modulePath = this.file.getPath() + "|" + modPath.toString(); //$NON-NLS-1$ + this.modules = ModulesCache.get(this.modulePath); + if (this.modules == null) { + try (DirectoryStream stream = Files.newDirectoryStream(this.releasePath)) { + HashMap newCache = new HashMap<>(); + for (final java.nio.file.Path subdir: stream) { + String rel = JRTUtil.sanitizedFileName(subdir); + if (!rel.contains(this.releaseInHex)) { + continue; + } + Files.walkFileTree(subdir, Collections.EMPTY_SET, 2, new FileVisitor() { + + @Override + public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) + throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) throws IOException { + if (attrs.isDirectory() || f.getNameCount() < 3) + return FileVisitResult.CONTINUE; + if (f.getFileName().toString().equals(MODULE_INFO) && Files.exists(f)) { + byte[] content = JRTUtil.safeReadBytes(f); + if (content == null) + return FileVisitResult.CONTINUE; + Path m = f.subpath(1, f.getNameCount() - 1); + String name = JRTUtil.sanitizedFileName(m); + ClasspathJep247Jdk12.this.acceptModule(name, content, newCache); + ClasspathJep247Jdk12.this.moduleNamesCache.add(name); + } + return FileVisitResult.SKIP_SIBLINGS; + } + + @Override + public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + }); + } + synchronized(ModulesCache) { + if (ModulesCache.get(this.modulePath) == null) { + this.modules = Collections.unmodifiableMap(newCache); + ModulesCache.put(this.modulePath, this.modules); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } else { + this.moduleNamesCache.addAll(this.modules.keySet()); + } + } + @Override + public Collection getModuleNames(Collection limitModule, Function getModule) { + return selectModules(this.moduleNamesCache, limitModule, getModule); + } + @Override + public IModule getModule(char[] moduleName) { + // Modules below level 9 are not dealt with here. Leave it to ClasspathJrt + if (this.jdklevel <= ClassFileConstants.JDK1_8) { + return super.getModule(moduleName); + } + if (this.modules != null) { + return this.modules.get(String.valueOf(moduleName)); + } + return null; + } + void acceptModule(String name, byte[] content, Map cache) { + if (content == null) + return; + + if (cache.containsKey(name)) + return; + + ClassFileReader reader = null; + try { + reader = new ClassFileReader(content, IModule.MODULE_INFO_CLASS.toCharArray()); + } catch (ClassFormatException e) { + e.printStackTrace(); + } + if (reader != null) { + acceptModule(reader, cache); + } + } + @Override + void acceptModule(ClassFileReader reader, Map cache) { + // Modules below level 9 are not dealt with here. Leave it to ClasspathJrt + if (this.jdklevel <= ClassFileConstants.JDK1_8) { + super.acceptModule(reader, cache); + return; + } + if (reader != null) { + IModule moduleDecl = reader.getModuleDeclaration(); + if (moduleDecl != null) { + cache.put(String.valueOf(moduleDecl.name()), moduleDecl); + } + } + } + @Override + public synchronized char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { + if (this.jdklevel >= ClassFileConstants.JDK9) { + // Delegate to the boss, even if it means inaccurate error reporting at times + List mods = JRTUtil.getModulesDeclaringPackage(this.file, qualifiedPackageName, moduleName); + return CharOperation.toCharArrays(mods); + } + if (this.packageCache == null) { + this.packageCache = new HashSet<>(41); + this.packageCache.add(Util.EMPTY_STRING); + try (DirectoryStream stream = Files.newDirectoryStream(this.releasePath)) { + for (final java.nio.file.Path subdir: stream) { + String rel = JRTUtil.sanitizedFileName(subdir); + if (!rel.contains(this.releaseInHex)) { + continue; + } + try (DirectoryStream stream2 = Files.newDirectoryStream(subdir)) { + for (final java.nio.file.Path subdir2: stream2) { + Files.walkFileTree(subdir2, new FileVisitor() { + @Override + public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) throws IOException { + if (dir.getNameCount() <= 2) + return FileVisitResult.CONTINUE; + Path relative = dir.subpath(2, dir.getNameCount()); + addToPackageCache(relative.toString(), false); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + }); + } + } + } + } catch (IOException e) { + e.printStackTrace(); + // Rethrow + } + } + return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJmod.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJmod.java new file mode 100644 index 0000000000..09786d6681 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJmod.java @@ -0,0 +1,189 @@ +/******************************************************************************* + * Copyright (c) 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.List; +import java.util.zip.ZipEntry; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationDecorator; +import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationProvider; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.env.IBinaryType; +import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.ExternalAnnotationStatus; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; +import org.eclipse.jdt.internal.compiler.util.Util; + +public class ClasspathJmod extends ClasspathJar { + + public static char[] CLASSES = "classes".toCharArray(); //$NON-NLS-1$ + public static char[] CLASSES_FOLDER = "classes/".toCharArray(); //$NON-NLS-1$ + +public ClasspathJmod(File file, boolean closeZipFileAtEnd, + AccessRuleSet accessRuleSet, String destinationPath) { + super(file, closeZipFileAtEnd, accessRuleSet, destinationPath); +} + +@Override +public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) { + // don't do anything + return null; +} +@Override +public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + if (!isPackage(qualifiedPackageName, moduleName)) + return null; // most common case + + try { + qualifiedBinaryFileName = new String(CharOperation.append(CLASSES_FOLDER, qualifiedBinaryFileName.toCharArray())); + IBinaryType reader = ClassFileReader.read(this.zipFile, qualifiedBinaryFileName); + if (reader != null) { + char[] modName = this.module == null ? null : this.module.name(); + if (reader instanceof ClassFileReader) { + ClassFileReader classReader = (ClassFileReader) reader; + if (classReader.moduleName == null) + classReader.moduleName = modName; + else + modName = classReader.moduleName; + } + searchPaths: + if (this.annotationPaths != null) { + String qualifiedClassName = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length()-SuffixConstants.EXTENSION_CLASS.length()-1); + for (String annotationPath : this.annotationPaths) { + try { + if (this.annotationZipFile == null) { + this.annotationZipFile = ExternalAnnotationDecorator.getAnnotationZipFile(annotationPath, null); + } + reader = ExternalAnnotationDecorator.create(reader, annotationPath, qualifiedClassName, this.annotationZipFile); + + if (reader.getExternalAnnotationStatus() == ExternalAnnotationStatus.TYPE_IS_ANNOTATED) { + break searchPaths; + } + } catch (IOException e) { + // don't let error on annotations fail class reading + } + } + // location is configured for external annotations, but no .eea found, decorate in order to answer NO_EEA_FILE: + reader = new ExternalAnnotationDecorator(reader, null); + } + return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName), modName); + } + } catch (ClassFormatException | IOException e) { + // treat as if class file is missing + } + return null; +} +@Override +public boolean hasAnnotationFileFor(String qualifiedTypeName) { + qualifiedTypeName = new String(CharOperation.append(CLASSES_FOLDER, qualifiedTypeName.toCharArray())); + return this.zipFile.getEntry(qualifiedTypeName+ExternalAnnotationProvider.ANNOTATION_FILE_SUFFIX) != null; +} +@SuppressWarnings({ "rawtypes", "unchecked" }) +@Override +public char[][][] findTypeNames(final String qualifiedPackageName, String moduleName) { + if (!isPackage(qualifiedPackageName, moduleName)) + return null; // most common case + final char[] packageArray = qualifiedPackageName.toCharArray(); + final ArrayList answers = new ArrayList(); + nextEntry : for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { + String fileName = ((ZipEntry) e.nextElement()).getName(); + + // add the package name & all of its parent packages + int first = CharOperation.indexOf(CLASSES_FOLDER, fileName.toCharArray(), false); + int last = fileName.lastIndexOf('/'); + if (last > 0) { + // extract the package name + String packageName = fileName.substring(first + 1, last); + if (!qualifiedPackageName.equals(packageName)) + continue nextEntry; + int indexOfDot = fileName.lastIndexOf('.'); + if (indexOfDot != -1) { + String typeName = fileName.substring(last + 1, indexOfDot); + answers.add( + CharOperation.arrayConcat( + CharOperation.splitOn('/', packageArray), + typeName.toCharArray())); + } + } + } + int size = answers.size(); + if (size != 0) { + char[][][] result = new char[size][][]; + answers.toArray(result); + return result; + } + return null; +} +@Override +public synchronized char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { + if (this.packageCache != null) + return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); + + this.packageCache = new HashSet<>(41); + this.packageCache.add(Util.EMPTY_STRING); + + for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { + char[] entryName = e.nextElement().getName().toCharArray(); + int index = CharOperation.indexOf('/', entryName); + if (index != -1) { + char[] folder = CharOperation.subarray(entryName, 0, index); + if (CharOperation.equals(CLASSES, folder)) { + char[] fileName = CharOperation.subarray(entryName, index + 1, entryName.length); + addToPackageCache(new String(fileName), false); + } + } + } + return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); +} +@Override +public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName) { + qualifiedPackageName += '/'; + for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { + char[] entryName = e.nextElement().getName().toCharArray(); + int index = CharOperation.indexOf('/', entryName); + if (index != -1) { + char[] folder = CharOperation.subarray(entryName, 0, index); + if (CharOperation.equals(CLASSES, folder)) { + String fileName = new String(CharOperation.subarray(entryName, index + 1, entryName.length)); + if (fileName.startsWith(qualifiedPackageName) && fileName.length() > qualifiedPackageName.length()) { + String tail = fileName.substring(qualifiedPackageName.length()); + if (tail.indexOf('/') != -1) + continue; + if (tail.toLowerCase().endsWith(SUFFIX_STRING_class)) + return true; + } + } + } + } + return false; +} +@Override +public String toString() { + return "Classpath for JMod file " + this.file.getPath(); //$NON-NLS-1$ +} +@Override +public IModule getModule() { + return this.module; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java new file mode 100644 index 0000000000..17e47e63ad --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJrt.java @@ -0,0 +1,410 @@ +/******************************************************************************* + * Copyright (c) 2016, 2018 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.io.IOException; + +import java.nio.file.FileVisitResult; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Function; +import java.util.zip.ZipFile; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationDecorator; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.IBinaryType; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.IMultiModuleEntry; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.env.IModule.IPackageExport; +import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.ExternalAnnotationStatus; +import org.eclipse.jdt.internal.compiler.util.JRTUtil; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; + +@SuppressWarnings({"rawtypes", "unchecked"}) +public class ClasspathJrt extends ClasspathLocation implements IMultiModuleEntry { + public File file; + protected ZipFile annotationZipFile; + protected boolean closeZipFileAtEnd; + protected static HashMap> ModulesCache = new HashMap<>(); + public final Set moduleNamesCache; + //private Set packageCache; + protected List annotationPaths; + + public ClasspathJrt(File file, boolean closeZipFileAtEnd, + AccessRuleSet accessRuleSet, String destinationPath) { + super(accessRuleSet, destinationPath); + this.file = file; + this.closeZipFileAtEnd = closeZipFileAtEnd; + this.moduleNamesCache = new HashSet<>(); + } + + @Override + public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) { + return null; + } + @Override + public char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { + List modules = JRTUtil.getModulesDeclaringPackage(this.file, qualifiedPackageName, moduleName); + return CharOperation.toCharArrays(modules); + } + @Override + public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName) { + return JRTUtil.hasCompilationUnit(this.file, qualifiedPackageName, moduleName); + } + @Override + public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName) { + return findClass(typeName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, false); + } + @Override + public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + if (!isPackage(qualifiedPackageName, moduleName)) + return null; // most common case + + try { + IBinaryType reader = ClassFileReader.readFromModule(this.file, moduleName, qualifiedBinaryFileName, this.moduleNamesCache::contains); + + if (reader != null) { + searchPaths: + if (this.annotationPaths != null) { + String qualifiedClassName = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length()-SuffixConstants.EXTENSION_CLASS.length()-1); + for (String annotationPath : this.annotationPaths) { + try { + if (this.annotationZipFile == null) { + this.annotationZipFile = ExternalAnnotationDecorator.getAnnotationZipFile(annotationPath, null); + } + reader = ExternalAnnotationDecorator.create(reader, annotationPath, qualifiedClassName, this.annotationZipFile); + + if (reader.getExternalAnnotationStatus() == ExternalAnnotationStatus.TYPE_IS_ANNOTATED) { + break searchPaths; + } + } catch (IOException e) { + // don't let error on annotations fail class reading + } + } + // location is configured for external annotations, but no .eea found, decorate in order to answer NO_EEA_FILE: + reader = new ExternalAnnotationDecorator(reader, null); + } + char[] answerModuleName = reader.getModule(); + if (answerModuleName == null && moduleName != null) + answerModuleName = moduleName.toCharArray(); + return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName), answerModuleName); + } + } catch (ClassFormatException | IOException e) { + // treat as if class file is missing + } + return null; + } + @Override + public boolean hasAnnotationFileFor(String qualifiedTypeName) { + return false; // TODO(SHMOD): implement + } + @Override + public char[][][] findTypeNames(final String qualifiedPackageName, final String moduleName) { + if (!isPackage(qualifiedPackageName, moduleName)) + return null; // most common case + final char[] packageArray = qualifiedPackageName.toCharArray(); + final ArrayList answers = new ArrayList(); + + try { + JRTUtil.walkModuleImage(this.file, new JRTUtil.JrtFileVisitor() { + + @Override + public FileVisitResult visitPackage(java.nio.file.Path dir, java.nio.file.Path modPath, BasicFileAttributes attrs) throws IOException { + if (qualifiedPackageName.startsWith(dir.toString())) { + return FileVisitResult.CONTINUE; + } + return FileVisitResult.SKIP_SUBTREE; + } + + @Override + public FileVisitResult visitFile(java.nio.file.Path dir, java.nio.file.Path modPath, BasicFileAttributes attrs) throws IOException { + Path parent = dir.getParent(); + if (parent == null) + return FileVisitResult.CONTINUE; + if (!parent.toString().equals(qualifiedPackageName)) { + return FileVisitResult.CONTINUE; + } + String fileName = dir.getName(dir.getNameCount() - 1).toString(); + // The path already excludes the folders and all the '/', hence the -1 for last index of '/' + addTypeName(answers, fileName, -1, packageArray); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitModule(Path p, String name) throws IOException { + if (moduleName == null) + return FileVisitResult.CONTINUE; + if (!moduleName.equals(name)) { + return FileVisitResult.SKIP_SUBTREE; + } + return FileVisitResult.CONTINUE; + } + + }, JRTUtil.NOTIFY_ALL); + } catch (IOException e) { + // Ignore and move on + } + + int size = answers.size(); + if (size != 0) { + char[][][] result = new char[size][][]; + answers.toArray(result); + return result; + } + return null; + } + + protected void addTypeName(final ArrayList answers, String fileName, int last, char[] packageName) { + int indexOfDot = fileName.lastIndexOf('.'); + if (indexOfDot != -1) { + String typeName = fileName.substring(last + 1, indexOfDot); + answers.add( + CharOperation.arrayConcat( + CharOperation.splitOn('/', packageName), + typeName.toCharArray())); + } + } + @Override + public void initialize() throws IOException { + loadModules(); + } +// public void acceptModule(IModuleDeclaration mod) { +// if (this.isJrt) +// return; +// this.module = mod; +// } + public void loadModules() { + Map cache = ModulesCache.get(this.file.getPath()); + + if (cache == null) { + try { + HashMap newCache = new HashMap<>(); + org.eclipse.jdt.internal.compiler.util.JRTUtil.walkModuleImage(this.file, + new org.eclipse.jdt.internal.compiler.util.JRTUtil.JrtFileVisitor() { + + @Override + public FileVisitResult visitPackage(Path dir, Path mod, BasicFileAttributes attrs) + throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path f, Path mod, BasicFileAttributes attrs) + throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitModule(Path p, String name) throws IOException { + ClasspathJrt.this.acceptModule(JRTUtil.getClassfileContent(ClasspathJrt.this.file, IModule.MODULE_INFO_CLASS, name), newCache); + ClasspathJrt.this.moduleNamesCache.add(name); + return FileVisitResult.SKIP_SUBTREE; + } + }, JRTUtil.NOTIFY_MODULES); + + synchronized(ModulesCache) { + if (ModulesCache.get(this.file.getPath()) == null) { + ModulesCache.put(this.file.getPath(), Collections.unmodifiableMap(newCache)); + } + } + } catch (IOException e) { + // TODO: Java 9 Should report better + } + } else { + this.moduleNamesCache.addAll(cache.keySet()); + } + } + void acceptModule(ClassFileReader reader, Map cache) { + if (reader != null) { + IModule moduleDecl = reader.getModuleDeclaration(); + if (moduleDecl != null) { + cache.put(String.valueOf(moduleDecl.name()), moduleDecl); + } + } + } + + void acceptModule(byte[] content, Map cache) { + if (content == null) + return; + ClassFileReader reader = null; + try { + reader = new ClassFileReader(content, IModule.MODULE_INFO_CLASS.toCharArray()); + } catch (ClassFormatException e) { + e.printStackTrace(); + } + if (reader != null) { + acceptModule(reader, cache); + } + } + + @Override + public Collection getModuleNames(Collection limitModule, Function getModule) { + Map cache = ModulesCache.get(this.file.getPath()); + return selectModules(cache.keySet(), limitModule, getModule); + } + @Override + protected List allModules(Iterable allSystemModules, Function getModuleName, Function getModule) { + List result = new ArrayList<>(); + boolean hasJavaDotSE = false; + for (T mod : allSystemModules) { + String moduleName = getModuleName.apply(mod); + if ("java.se".equals(moduleName)) { //$NON-NLS-1$ + result.add(moduleName); + hasJavaDotSE = true; + break; + } + } + for (T mod : allSystemModules) { + String moduleName = getModuleName.apply(mod); + boolean isJavaDotStart = moduleName.startsWith("java."); //$NON-NLS-1$ + boolean isPotentialRoot = !isJavaDotStart; // always include non-java.* + if (!hasJavaDotSE) + isPotentialRoot |= isJavaDotStart; // no java.se => add all java.* + + if (isPotentialRoot) { + IModule m = getModule.apply(mod); + if (m != null) { + for (IPackageExport packageExport : m.exports()) { + if (!packageExport.isQualified()) { + result.add(moduleName); + break; + } + } + } + } + } + return result; + } +// protected void addToPackageCache(String fileName, boolean endsWithSep) { +// int last = endsWithSep ? fileName.length() : fileName.lastIndexOf('/'); +// while (last > 0) { +// // extract the package name +// String packageName = fileName.substring(0, last); +// if (this.packageCache.contains(packageName)) +// return; +// this.packageCache.add(packageName); +// last = packageName.lastIndexOf('/'); +// } +// } +// public synchronized boolean isPackage(String qualifiedPackageName) { +// if (this.packageCache != null) +// return this.packageCache.contains(qualifiedPackageName); +// +// this.packageCache = new HashSet<>(41); +// this.packageCache.add(Util.EMPTY_STRING); +// +// try { +// JRTUtil.walkModuleImage(this.file, new JRTUtil.JrtFileVisitor() { +// +// @Override +// public FileVisitResult visitPackage(java.nio.file.Path dir, java.nio.file.Path mod, BasicFileAttributes attrs) throws IOException { +// addToPackageCache(dir.toString(), true); +// return FileVisitResult.CONTINUE; +// } +// +// @Override +// public FileVisitResult visitFile(java.nio.file.Path dir, java.nio.file.Path mod, BasicFileAttributes attrs) throws IOException { +// return FileVisitResult.CONTINUE; +// } +// +// @Override +// public FileVisitResult visitModule(java.nio.file.Path mod) throws IOException { +// return FileVisitResult.CONTINUE; +// } +// +// }, JRTUtil.NOTIFY_PACKAGES); +// } catch (IOException e) { +// // Ignore and move on +// } +// return this.packageCache.contains(qualifiedPackageName); +// } + @Override + public void reset() { + if (this.closeZipFileAtEnd) { + if (this.annotationZipFile != null) { + try { + this.annotationZipFile.close(); + } catch(IOException e) { + // ignore + } + this.annotationZipFile = null; + } + } + if (this.annotationPaths != null) { + //this.packageCache = null; + this.annotationPaths = null; + } + } + @Override + public String toString() { + return "Classpath for JRT System " + this.file.getPath(); //$NON-NLS-1$ + } + @Override + public char[] normalizedPath() { + if (this.normalizedPath == null) { + String path2 = this.getPath(); + char[] rawName = path2.toCharArray(); + if (File.separatorChar == '\\') { + CharOperation.replace(rawName, '\\', '/'); + } + this.normalizedPath = CharOperation.subarray(rawName, 0, CharOperation.lastIndexOf('.', rawName)); + } + return this.normalizedPath; + } + @Override + public String getPath() { + if (this.path == null) { + try { + this.path = this.file.getCanonicalPath(); + } catch (IOException e) { + // in case of error, simply return the absolute path + this.path = this.file.getAbsolutePath(); + } + } + return this.path; + } + @Override + public int getMode() { + return BINARY; + } + @Override + public boolean hasModule() { + return true; + } + @Override + public IModule getModule(char[] moduleName) { + Map modules = ModulesCache.get(this.file.getPath()); + if (modules != null) { + return modules.get(String.valueOf(moduleName)); + } + return null; + } + @Override + public boolean servesModule(char[] moduleName) { + return getModule(moduleName) != null; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java new file mode 100644 index 0000000000..125fa61877 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathLocation.java @@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2000, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.function.Function; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.env.AccessRestriction; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.IModule.IModuleReference; +import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; + +public abstract class ClasspathLocation implements FileSystem.Classpath, + SuffixConstants { + + public static final int SOURCE = 1; + public static final int BINARY = 2; + + String path; + char[] normalizedPath; + public AccessRuleSet accessRuleSet; + IModule module; + + public String destinationPath; + // destination path for compilation units that are reached through this + // classpath location; the coding is consistent with the one of + // Main.destinationPath: + // == null: unspecified, use whatever value is set by the enclosing + // context, id est Main; + // == Main.NONE: absorbent element, do not output class files; + // else: use as the path of the directory into which class files must + // be written. + // potentially carried by any entry that contains to be compiled files + + protected ClasspathLocation(AccessRuleSet accessRuleSet, + String destinationPath) { + this.accessRuleSet = accessRuleSet; + this.destinationPath = destinationPath; + } + + /** + * Return the first access rule which is violated when accessing a given + * type, or null if no 'non accessible' access rule applies. + * + * @param qualifiedBinaryFileName + * tested type specification, formed as: + * "org/eclipse/jdt/core/JavaCore.class"; on systems that + * use \ as File.separator, the + * "org\eclipse\jdt\core\JavaCore.class" is accepted as well + * @return the first access rule which is violated when accessing a given + * type, or null if none applies + */ + protected AccessRestriction fetchAccessRestriction(String qualifiedBinaryFileName) { + if (this.accessRuleSet == null) + return null; + char [] qualifiedTypeName = qualifiedBinaryFileName. + substring(0, qualifiedBinaryFileName.length() - SUFFIX_CLASS.length) + .toCharArray(); + if (File.separatorChar == '\\') { + CharOperation.replace(qualifiedTypeName, File.separatorChar, '/'); + } + return this.accessRuleSet.getViolatedRestriction(qualifiedTypeName); + } + + public int getMode() { + return SOURCE | BINARY; + } + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + this.getMode(); + result = prime * result + ((this.path == null) ? 0 : this.path.hashCode()); + return result; + } + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ClasspathLocation other = (ClasspathLocation) obj; + String localPath = this.getPath(); + String otherPath = other.getPath(); + if (localPath == null) { + if (otherPath != null) + return false; + } else if (!localPath.equals(otherPath)) + return false; + if (this.getMode() != other.getMode()) + return false; + return true; + } + @Override + public String getPath() { + return this.path; + } + @Override + public String getDestinationPath() { + return this.destinationPath; + } + + @Override + public void acceptModule(IModule mod) { + this.module = mod; + } + @Override + public boolean isAutomaticModule() { + return this.module == null ? false : this.module.isAutomatic(); + } + @Override + public Collection getModuleNames(Collection limitModules) { + return getModuleNames(limitModules, m -> getModule(m.toCharArray())); + } + @Override + public Collection getModuleNames(Collection limitModules, Function getModule) { + if (this.module != null) { + String name = String.valueOf(this.module.name()); + return selectModules(Collections.singleton(name), limitModules, getModule); + } + return Collections.emptyList(); + } + protected Collection selectModules(Set modules, Collection limitModules, Function getModule) { + Collection rootModules; + if (limitModules != null) { + Set result = new HashSet<>(modules); + result.retainAll(limitModules); + rootModules = result; + } else { + rootModules = allModules(modules, s -> s, m -> getModule(m.toCharArray())); + } + Set allModules = new HashSet<>(rootModules); + for (String mod : rootModules) + addRequired(mod, allModules, getModule); + return allModules; + } + + private void addRequired(String mod, Set allModules, Function getModule) { + IModule iMod = getModule(mod.toCharArray()); + if (iMod != null) { + for (IModuleReference requiredRef : iMod.requires()) { + IModule reqMod = getModule.apply(new String(requiredRef.name())); + if (reqMod != null) { + String reqModName = String.valueOf(reqMod.name()); + if (allModules.add(reqModName)) + addRequired(reqModName, allModules, getModule); + } + } + } + } + protected List allModules(Iterable allSystemModules, Function getModuleName, Function getModule) { + List result = new ArrayList<>(); + for (T mod : allSystemModules) { + String moduleName = getModuleName.apply(mod); + result.add(moduleName); + } + return result; + } + + @Override + public boolean isPackage(String qualifiedPackageName, String moduleName) { + return getModulesDeclaringPackage(qualifiedPackageName, moduleName) != null; + } + + protected char[][] singletonModuleNameIf(boolean condition) { + if (!condition) + return null; + if (this.module != null) + return new char[][] { this.module.name() }; + return new char[][] { ModuleBinding.UNNAMED }; + } + + @Override + public void reset() { + this.module = null; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathMultiReleaseJar.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathMultiReleaseJar.java new file mode 100644 index 0000000000..cf8d7b69d5 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathMultiReleaseJar.java @@ -0,0 +1,166 @@ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.nio.file.DirectoryStream; +import java.nio.file.FileSystemAlreadyExistsException; +import java.nio.file.FileSystems; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.zip.ZipEntry; + +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationDecorator; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.IBinaryType; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.ExternalAnnotationStatus; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; +import org.eclipse.jdt.internal.compiler.util.Util; + +public class ClasspathMultiReleaseJar extends ClasspathJar { + private java.nio.file.FileSystem fs = null; + Path releasePath = null; + String compliance = null; + + public ClasspathMultiReleaseJar(File file, boolean closeZipFileAtEnd, + AccessRuleSet accessRuleSet, String destinationPath, String compliance) { + super(file, closeZipFileAtEnd, accessRuleSet, destinationPath); + this.compliance = compliance; + } + @Override + public void initialize() throws IOException { + super.initialize(); + URI t = this.file.toURI(); + if (this.file.exists()) { + URI uri = URI.create("jar:file:" + t.getRawPath()); //$NON-NLS-1$ + + try { + HashMap env = new HashMap<>(); + this.fs = FileSystems.newFileSystem(uri, env); + } catch (FileSystemAlreadyExistsException e) { + this.fs = FileSystems.getFileSystem(uri); + } + this.releasePath = this.fs.getPath("/", "META-INF", "versions", this.compliance); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + if (!Files.exists(this.releasePath)) { + this.releasePath = null; + } + } + } + @SuppressWarnings("rawtypes") + @Override + public synchronized char[][] getModulesDeclaringPackage(String qualifiedPackageName, String moduleName) { + if (this.releasePath == null) { + return super.getModulesDeclaringPackage(qualifiedPackageName, moduleName); + } + if (this.packageCache != null) + return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); + + this.packageCache = new HashSet<>(41); + this.packageCache.add(Util.EMPTY_STRING); + + for (Enumeration e = this.zipFile.entries(); e.hasMoreElements(); ) { + String fileName = ((ZipEntry) e.nextElement()).getName(); + addToPackageCache(fileName, false); + } + try { + if (this.releasePath != null && Files.exists(this.releasePath)) { + // go through the packages + try (DirectoryStream stream = Files.newDirectoryStream(this.releasePath)) { + for (final java.nio.file.Path subdir: stream) { + Files.walkFileTree(subdir, new FileVisitor() { + @Override + public FileVisitResult preVisitDirectory(java.nio.file.Path dir, BasicFileAttributes attrs) + throws IOException { + return FileVisitResult.CONTINUE; + } + @Override + public FileVisitResult visitFile(java.nio.file.Path f, BasicFileAttributes attrs) + throws IOException { + Path p = ClasspathMultiReleaseJar.this.releasePath.relativize(f); + addToPackageCache(p.toString(), false); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFileFailed(java.nio.file.Path f, IOException exc) throws IOException { + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) + throws IOException { + return FileVisitResult.CONTINUE; + } + }); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + // move on; + } + return singletonModuleNameIf(this.packageCache.contains(qualifiedPackageName)); + } + @Override + public NameEnvironmentAnswer findClass(char[] binaryFileName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + if (!isPackage(qualifiedPackageName, moduleName)) return null; // most common case + if (this.releasePath != null) { + try { + Path p = this.releasePath.resolve(qualifiedBinaryFileName); + byte[] content = Files.readAllBytes(p); + IBinaryType reader = null; + if (content != null) { + reader = new ClassFileReader(content, qualifiedBinaryFileName.toCharArray()); + } + if (reader != null) { + char[] modName = this.module == null ? null : this.module.name(); + if (reader instanceof ClassFileReader) { + ClassFileReader classReader = (ClassFileReader) reader; + if (classReader.moduleName == null) + classReader.moduleName = modName; + else + modName = classReader.moduleName; + } + String fileNameWithoutExtension = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - SuffixConstants.SUFFIX_CLASS.length); + searchPaths: + if (this.annotationPaths != null) { + String qualifiedClassName = qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length()-SuffixConstants.EXTENSION_CLASS.length()-1); + for (String annotationPath : this.annotationPaths) { + try { + if (this.annotationZipFile == null) { + this.annotationZipFile = ExternalAnnotationDecorator.getAnnotationZipFile(annotationPath, null); + } + reader = ExternalAnnotationDecorator.create(reader, annotationPath, qualifiedClassName, this.annotationZipFile); + + if (reader.getExternalAnnotationStatus() == ExternalAnnotationStatus.TYPE_IS_ANNOTATED) { + break searchPaths; + } + } catch (IOException e) { + // don't let error on annotations fail class reading + } + } + // location is configured for external annotations, but no .eea found, decorate in order to answer NO_EEA_FILE: + reader = new ExternalAnnotationDecorator(reader, null); + } + if (this.accessRuleSet == null) + return new NameEnvironmentAnswer(reader, null, modName); + return new NameEnvironmentAnswer(reader, + this.accessRuleSet.getViolatedRestriction(fileNameWithoutExtension.toCharArray()), + modName); + } + } catch (IOException | ClassFormatException e) { + // treat as if class file is missing + } + } + return super.findClass(binaryFileName, qualifiedPackageName, moduleName, qualifiedBinaryFileName, asBinaryOnly); + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathSourceJar.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathSourceJar.java new file mode 100644 index 0000000000..d906d7bb4b --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ClasspathSourceJar.java @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2006, 2017 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.io.InputStream; +import java.io.IOException; +import java.util.zip.ZipEntry; + +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.util.Util; + +public class ClasspathSourceJar extends ClasspathJar { + private String encoding; + + public ClasspathSourceJar(File file, boolean closeZipFileAtEnd, + AccessRuleSet accessRuleSet, String encoding, + String destinationPath) { + super(file, closeZipFileAtEnd, accessRuleSet, destinationPath); + this.encoding = encoding; + } + + @Override + public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly) { + if (!isPackage(qualifiedPackageName, moduleName)) + return null; // most common case + + ZipEntry sourceEntry = this.zipFile.getEntry(qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java); + if (sourceEntry != null) { + try { + InputStream stream = null; + char[] contents = null; + try { + stream = this.zipFile.getInputStream(sourceEntry); + contents = Util.getInputStreamAsCharArray(stream, this.encoding); + } finally { + if (stream != null) + stream.close(); + } + CompilationUnit compilationUnit = new CompilationUnit( + contents, + qualifiedBinaryFileName.substring(0, qualifiedBinaryFileName.length() - 6) + SUFFIX_STRING_java, + this.encoding, + this.destinationPath); + compilationUnit.module = this.module == null ? null : this.module.name(); + return new NameEnvironmentAnswer( + compilationUnit, + fetchAccessRestriction(qualifiedBinaryFileName)); + } catch (IOException e) { + // treat as if source file is missing + } + } + return null; + } + + @Override + public int getMode() { + return SOURCE; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java new file mode 100644 index 0000000000..aa9c1d100e --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/CompilationUnit.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2000, 2018 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.io.IOException; +import java.util.function.Function; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; +import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding; +import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit; +import org.eclipse.jdt.internal.compiler.util.Util; + +public class CompilationUnit implements ICompilationUnit { + public char[] contents; + public char[] fileName; + public char[] mainTypeName; + String encoding; + public String destinationPath; + public char[] module; + // a specific destination path for this compilation unit; coding is + // aligned with Main.destinationPath: + // == null: unspecified, use whatever value is set by the enclosing + // context, id est Main; + // == Main.NONE: absorbent element, do not output class files; + // else: use as the path of the directory into which class files must + // be written. + private boolean ignoreOptionalProblems; + private ModuleBinding moduleBinding; + /** + * annotation path can only be retrieved once the qualified type name is known. + * This is the provided function for computing the annotation path from that type name. + */ + private Function annotationPathProvider; + +public CompilationUnit(char[] contents, String fileName, String encoding) { + this(contents, fileName, encoding, null); +} +public CompilationUnit(char[] contents, String fileName, String encoding, + String destinationPath) { + this(contents, fileName, encoding, destinationPath, false, null); +} +public CompilationUnit(char[] contents, String fileName, String encoding, + String destinationPath, boolean ignoreOptionalProblems, String modName) { + this(contents, fileName, encoding, destinationPath, ignoreOptionalProblems, modName, null); +} +public CompilationUnit(char[] contents, String fileName, String encoding, String destinationPath, + boolean ignoreOptionalProblems, String modName, Function annotationPathProvider) +{ + this.annotationPathProvider = annotationPathProvider; + this.contents = contents; + if (modName != null) + this.module = modName.toCharArray(); + char[] fileNameCharArray = fileName.toCharArray(); + switch(File.separatorChar) { + case '/' : + if (CharOperation.indexOf('\\', fileNameCharArray) != -1) { + CharOperation.replace(fileNameCharArray, '\\', '/'); + } + break; + case '\\' : + if (CharOperation.indexOf('/', fileNameCharArray) != -1) { + CharOperation.replace(fileNameCharArray, '/', '\\'); + } + } + this.fileName = fileNameCharArray; + int start = CharOperation.lastIndexOf(File.separatorChar, fileNameCharArray) + 1; + + int end = CharOperation.lastIndexOf('.', fileNameCharArray); + if (end == -1) { + end = fileNameCharArray.length; + } + + this.mainTypeName = CharOperation.subarray(fileNameCharArray, start, end); + this.encoding = encoding; + this.destinationPath = destinationPath; + this.ignoreOptionalProblems = ignoreOptionalProblems; +} +@Override +public char[] getContents() { + if (this.contents != null) + return this.contents; // answer the cached source + + // otherwise retrieve it + try { + return Util.getFileCharContent(new File(new String(this.fileName)), this.encoding); + } catch (IOException e) { + this.contents = CharOperation.NO_CHAR; // assume no source if asked again + throw new AbortCompilationUnit(null, e, this.encoding); + } +} +/** + * @see org.eclipse.jdt.internal.compiler.env.IDependent#getFileName() + */ +@Override +public char[] getFileName() { + return this.fileName; +} +@Override +public char[] getMainTypeName() { + return this.mainTypeName; +} +@Override +public char[][] getPackageName() { + return null; +} +@Override +public boolean ignoreOptionalProblems() { + return this.ignoreOptionalProblems; +} +@Override +public String toString() { + return "CompilationUnit[" + new String(this.fileName) + "]"; //$NON-NLS-2$ //$NON-NLS-1$ +} +@Override +public char[] getModuleName() { + return this.module; +} +@Override +public ModuleBinding module(LookupEnvironment rootEnvironment) { + if (this.moduleBinding != null) + return this.moduleBinding; + this.moduleBinding = rootEnvironment.getModule(this.module); + if (this.moduleBinding == null) + throw new IllegalStateException("Module should be known"); //$NON-NLS-1$ + return this.moduleBinding; +} +@Override +public String getDestinationPath() { + return this.destinationPath; +} +@Override +public String getExternalAnnotationPath(String qualifiedTypeName) { + if (this.annotationPathProvider != null) + return this.annotationPathProvider.apply(qualifiedTypeName); + return null; +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileFinder.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileFinder.java new file mode 100644 index 0000000000..280cc810f4 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileFinder.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2000, 2016 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jdt.internal.compiler.env.IModule; + +public class FileFinder { + +/** + * Although the file finder is meant to be generic for any file name patters, + * at the moment it is used only for *.java files. This method handles the + * module-info.java in a special way by always placing it as the first element + * of the resulting array. + */ +public static String[] find(File f, String pattern) { + List files = new ArrayList<>(); + find0(f, pattern, files); + String[] result = new String[files.size()]; + files.toArray(result); + return result; +} +private static void find0(File f, String pattern, List collector) { + if (f.isDirectory()) { + String[] files = f.list(); + if (files == null) return; + for (int i = 0, max = files.length; i < max; i++) { + File current = new File(f, files[i]); + if (current.isDirectory()) { + find0(current, pattern, collector); + } else { + String name = current.getName().toLowerCase(); + if (name.endsWith(pattern)) { + // NOTE: This handles only the lower case name. Check with the spec about + // Naming of the module descriptor before making this code code insensitive. + if (name.endsWith(IModule.MODULE_INFO_JAVA)) { + collector.add(0, current.getAbsolutePath()); + } else { + collector.add(current.getAbsolutePath()); + } + } + } + } + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java new file mode 100644 index 0000000000..f8fa2b7a73 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/FileSystem.java @@ -0,0 +1,741 @@ +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for + * Bug 440687 - [compiler][batch][null] improve command line option for external annotations + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.io.IOException; +import java.nio.file.InvalidPathException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.zip.ZipFile; + +import javax.lang.model.SourceVersion; + +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationDecorator; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.IModulePathEntry; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.IModuleAwareNameEnvironment; +import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; +import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.internal.compiler.env.IUpdatableModule; +import org.eclipse.jdt.internal.compiler.env.IUpdatableModule.UpdateKind; +import org.eclipse.jdt.internal.compiler.env.IUpdatableModule.UpdatesByKind; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.util.JRTUtil; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; +import org.eclipse.jdt.internal.compiler.util.Util; + +public class FileSystem implements IModuleAwareNameEnvironment, SuffixConstants { + + // Keep the type as ArrayList and not List as there are clients that are already written to expect ArrayList. + public static ArrayList EMPTY_CLASSPATH = new ArrayList<>(); + + /** + * A Classpath, even though an IModuleLocation, can represent a plain + * classpath location too. The FileSystem tells the Classpath whether to behave as a module or regular class + * path via {@link Classpath#acceptModule(IModule)}. + * + * Sub types of classpath are responsible for appropriate behavior based on this. + */ + public interface Classpath extends IModulePathEntry { + char[][][] findTypeNames(String qualifiedPackageName, String moduleName); + NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName); + NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String moduleName, String qualifiedBinaryFileName, boolean asBinaryOnly); + boolean isPackage(String qualifiedPackageName, /*@Nullable*/String moduleName); + default boolean hasModule() { return getModule() != null; } + default boolean hasCUDeclaringPackage(String qualifiedPackageName, Function pkgNameExtractor) { + return hasCompilationUnit(qualifiedPackageName, null); + } + /** + * Return a list of the jar file names defined in the Class-Path section + * of the jar file manifest if any, null else. Only ClasspathJar (and + * extending classes) instances may return a non-null result. + * @param problemReporter problem reporter with which potential + * misconfiguration issues are raised + * @return a list of the jar file names defined in the Class-Path + * section of the jar file manifest if any + */ + List fetchLinkedJars(ClasspathSectionProblemReporter problemReporter); + /** + * This method resets the environment. The resulting state is equivalent to + * a new name environment without creating a new object. + */ + void reset(); + /** + * Return a normalized path for file based classpath entries. This is an + * absolute path in which file separators are transformed to the + * platform-agnostic '/', ending with a '/' for directories. This is an + * absolute path in which file separators are transformed to the + * platform-agnostic '/', deprived from the '.jar' (resp. '.zip') + * extension for jar (resp. zip) files. + * @return a normalized path for file based classpath entries + */ + char[] normalizedPath(); + /** + * Return the path for file based classpath entries. This is an absolute path + * ending with a file separator for directories, an absolute path including the '.jar' + * (resp. '.zip') extension for jar (resp. zip) files. + * @return the path for file based classpath entries + */ + String getPath(); + /** + * Initialize the entry + */ + void initialize() throws IOException; + /** + * Can the current location provide an external annotation file for the given type? + * @param qualifiedTypeName type name in qualified /-separated notation. + */ + boolean hasAnnotationFileFor(String qualifiedTypeName); + /** + * Accepts to represent a module location with the given module description. + * + * @param module + */ + public void acceptModule(IModule module); + public String getDestinationPath(); + Collection getModuleNames(Collection limitModules); + Collection getModuleNames(Collection limitModules, Function getModule); + } + public interface ClasspathSectionProblemReporter { + void invalidClasspathSection(String jarFilePath); + void multipleClasspathSections(String jarFilePath); + } + + /** + * This class is defined how to normalize the classpath entries. + * It removes duplicate entries. + */ + public static class ClasspathNormalizer { + /** + * Returns the normalized classpath entries (no duplicate). + *

    The given classpath entries are FileSystem.Classpath. We check the getPath() in order to find + * duplicate entries.

    + * + * @param classpaths the given classpath entries + * @return the normalized classpath entries + */ + public static ArrayList normalize(ArrayList classpaths) { + ArrayList normalizedClasspath = new ArrayList<>(); + HashSet cache = new HashSet<>(); + for (Iterator iterator = classpaths.iterator(); iterator.hasNext(); ) { + FileSystem.Classpath classpath = iterator.next(); + if (!cache.contains(classpath)) { + normalizedClasspath.add(classpath); + cache.add(classpath); + } + } + return normalizedClasspath; + } + } + + protected Classpath[] classpaths; + // Used only in single-module mode when the module descriptor is + // provided via command line. + protected IModule module; + Set knownFileNames; + protected boolean annotationsFromClasspath; // should annotation files be read from the classpath (vs. explicit separate path)? + private static HashMap JRT_CLASSPATH_CACHE = null; + protected Map moduleLocations = new HashMap<>(); + + /** Tasks resulting from --add-reads or --add-exports command line options. */ + Map moduleUpdates = new HashMap<>(); + static boolean isJRE12Plus = false; + + private boolean hasLimitModules = false; + + static { + try { + isJRE12Plus = SourceVersion.valueOf("RELEASE_12") != null; //$NON-NLS-1$ + } catch(IllegalArgumentException iae) { + // fall back to default + } + } + +/* + classPathNames is a collection is Strings representing the full path of each class path + initialFileNames is a collection is Strings, the trailing '.java' will be removed if its not already. +*/ +public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding) { + this(classpathNames, initialFileNames, encoding, null, null); +} +public FileSystem(String[] classpathNames, String[] initialFileNames, String encoding, String release) { + this(classpathNames, initialFileNames, encoding, null, release); +} +protected FileSystem(String[] classpathNames, String[] initialFileNames, String encoding, Collection limitModules) { + this(classpathNames,initialFileNames, encoding, limitModules, null); +} +protected FileSystem(String[] classpathNames, String[] initialFileNames, String encoding, Collection limitModules, String release) { + final int classpathSize = classpathNames.length; + this.classpaths = new Classpath[classpathSize]; + int counter = 0; + this.hasLimitModules = limitModules != null && !limitModules.isEmpty(); + for (int i = 0; i < classpathSize; i++) { + Classpath classpath = getClasspath(classpathNames[i], encoding, null, null, release); + try { + classpath.initialize(); + for (String moduleName : classpath.getModuleNames(limitModules)) + this.moduleLocations.put(moduleName, classpath); + this.classpaths[counter++] = classpath; + } catch (IOException e) { + // ignore + } + } + if (counter != classpathSize) { + System.arraycopy(this.classpaths, 0, (this.classpaths = new Classpath[counter]), 0, counter); + } + initializeKnownFileNames(initialFileNames); +} +protected FileSystem(Classpath[] paths, String[] initialFileNames, boolean annotationsFromClasspath, Set limitedModules) { + final int length = paths.length; + int counter = 0; + this.classpaths = new FileSystem.Classpath[length]; + this.hasLimitModules = limitedModules != null && !limitedModules.isEmpty(); + for (int i = 0; i < length; i++) { + final Classpath classpath = paths[i]; + try { + classpath.initialize(); + for (String moduleName : classpath.getModuleNames(limitedModules)) + this.moduleLocations.put(moduleName, classpath); + this.classpaths[counter++] = classpath; + } catch(IOException | InvalidPathException exception) { + // JRE 9 could throw an IAE if the linked JAR paths have invalid chars, such as ":" + // ignore + } + } + if (counter != length) { + // should not happen + System.arraycopy(this.classpaths, 0, (this.classpaths = new FileSystem.Classpath[counter]), 0, counter); + } + initializeModuleLocations(limitedModules); + initializeKnownFileNames(initialFileNames); + this.annotationsFromClasspath = annotationsFromClasspath; +} +private void initializeModuleLocations(Set limitedModules) { + // First create the mapping of all module/Classpath + // since the second iteration of getModuleNames() can't be relied on for + // to get the right origin of module + if (limitedModules == null) { + for (Classpath c : this.classpaths) { + for (String moduleName : c.getModuleNames(null)) + this.moduleLocations.put(moduleName, c); + } + } else { + Map moduleMap = new HashMap<>(); + for (Classpath c : this.classpaths) { + for (String moduleName : c.getModuleNames(null)) { + moduleMap.put(moduleName, c); + } + } + for (Classpath c : this.classpaths) { + for (String moduleName : c.getModuleNames(limitedModules, m -> getModuleFromEnvironment(m.toCharArray()))) { + Classpath classpath = moduleMap.get(moduleName); + this.moduleLocations.put(moduleName, classpath); + } + } + } +} +protected FileSystem(Classpath[] paths, String[] initialFileNames, boolean annotationsFromClasspath) { + this(paths, initialFileNames, annotationsFromClasspath, null); +} +public static Classpath getClasspath(String classpathName, String encoding, AccessRuleSet accessRuleSet) { + return getClasspath(classpathName, encoding, false, accessRuleSet, null, null, null); +} +public static Classpath getClasspath(String classpathName, String encoding, AccessRuleSet accessRuleSet, Map options, String release) { + return getClasspath(classpathName, encoding, false, accessRuleSet, null, options, release); +} +public static Classpath getJrtClasspath(String jdkHome, String encoding, AccessRuleSet accessRuleSet, Map options) { + return new ClasspathJrt(new File(convertPathSeparators(jdkHome)), true, accessRuleSet, null); +} +public static Classpath getOlderSystemRelease(String jdkHome, String release, AccessRuleSet accessRuleSet) { + return isJRE12Plus ? + new ClasspathJep247Jdk12(new File(convertPathSeparators(jdkHome)), release, accessRuleSet) : + new ClasspathJep247(new File(convertPathSeparators(jdkHome)), release, accessRuleSet); +} +public static Classpath getClasspath(String classpathName, String encoding, + boolean isSourceOnly, AccessRuleSet accessRuleSet, + String destinationPath, Map options, String release) { + Classpath result = null; + File file = new File(convertPathSeparators(classpathName)); + if (file.isDirectory()) { + if (file.exists()) { + result = new ClasspathDirectory(file, encoding, + isSourceOnly ? ClasspathLocation.SOURCE : + ClasspathLocation.SOURCE | ClasspathLocation.BINARY, + accessRuleSet, + destinationPath == null || destinationPath == Main.NONE ? + destinationPath : // keep == comparison valid + convertPathSeparators(destinationPath), options); + } + } else { + int format = Util.archiveFormat(classpathName); + if (format == Util.ZIP_FILE) { + if (isSourceOnly) { + // source only mode + result = new ClasspathSourceJar(file, true, accessRuleSet, + encoding, + destinationPath == null || destinationPath == Main.NONE ? + destinationPath : // keep == comparison valid + convertPathSeparators(destinationPath)); + } else if (destinationPath == null) { + // class file only mode + if (classpathName.endsWith(JRTUtil.JRT_FS_JAR)) { + if (JRT_CLASSPATH_CACHE == null) { + JRT_CLASSPATH_CACHE = new HashMap<>(); + } else { + result = JRT_CLASSPATH_CACHE.get(file); + } + if (result == null) { + result = new ClasspathJrt(file, true, accessRuleSet, null); + try { + result.initialize(); + } catch (IOException e) { + // Broken entry, but let clients have it anyway. + } + JRT_CLASSPATH_CACHE.put(file, result); + } + } else { + result = + (release == null) ? + new ClasspathJar(file, true, accessRuleSet, null) : + new ClasspathMultiReleaseJar(file, true, accessRuleSet, destinationPath, release); + } + } + } else if (format == Util.JMOD_FILE) { + return new ClasspathJmod(file, true, accessRuleSet, null); + } + + } + return result; +} +private void initializeKnownFileNames(String[] initialFileNames) { + if (initialFileNames == null) { + this.knownFileNames = new HashSet<>(0); + return; + } + this.knownFileNames = new HashSet<>(initialFileNames.length * 2); + for (int i = initialFileNames.length; --i >= 0;) { + File compilationUnitFile = new File(initialFileNames[i]); + char[] fileName = null; + try { + fileName = compilationUnitFile.getCanonicalPath().toCharArray(); + } catch (IOException e) { + // this should not happen as the file exists + continue; + } + char[] matchingPathName = null; + final int lastIndexOf = CharOperation.lastIndexOf('.', fileName); + if (lastIndexOf != -1) { + fileName = CharOperation.subarray(fileName, 0, lastIndexOf); + } + CharOperation.replace(fileName, '\\', '/'); + boolean globalPathMatches = false; + // the most nested path should be the selected one + for (Classpath classpath : this.classpaths) { + char[] matchCandidate = classpath.normalizedPath(); + boolean currentPathMatch = false; + if (classpath instanceof ClasspathDirectory + && CharOperation.prefixEquals(matchCandidate, fileName)) { + currentPathMatch = true; + if (matchingPathName == null) { + matchingPathName = matchCandidate; + } else { + if (currentPathMatch) { + // we have a second source folder that matches the path of the source file + if (matchCandidate.length > matchingPathName.length) { + // we want to preserve the shortest possible path + matchingPathName = matchCandidate; + } + } else { + // we want to preserve the shortest possible path + if (!globalPathMatches && matchCandidate.length < matchingPathName.length) { + matchingPathName = matchCandidate; + } + } + } + if (currentPathMatch) { + globalPathMatches = true; + } + } + } + if (matchingPathName == null) { + this.knownFileNames.add(new String(fileName)); // leave as is... + } else { + this.knownFileNames.add(new String(CharOperation.subarray(fileName, matchingPathName.length, fileName.length))); + } + matchingPathName = null; + } +} +/** TESTS ONLY */ +public void scanForModules(Parser parser) { + for (int i = 0, max = this.classpaths.length; i < max; i++) { + File file = new File(this.classpaths[i].getPath()); + IModule iModule = ModuleFinder.scanForModule(this.classpaths[i], file, parser, false, null); + if (iModule != null) + this.moduleLocations.put(String.valueOf(iModule.name()), this.classpaths[i]); + } +} +@Override +public void cleanup() { + for (int i = 0, max = this.classpaths.length; i < max; i++) + this.classpaths[i].reset(); +} +private static String convertPathSeparators(String path) { + return File.separatorChar == '/' + ? path.replace('\\', '/') + : path.replace('/', '\\'); +} +private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName, boolean asBinaryOnly, /*NonNull*/char[] moduleName) { + NameEnvironmentAnswer answer = internalFindClass(qualifiedTypeName, typeName, asBinaryOnly, moduleName); + if (this.annotationsFromClasspath && answer != null && answer.getBinaryType() instanceof ClassFileReader) { + for (int i = 0, length = this.classpaths.length; i < length; i++) { + Classpath classpathEntry = this.classpaths[i]; + if (classpathEntry.hasAnnotationFileFor(qualifiedTypeName)) { + // in case of 'this.annotationsFromClasspath' we indeed search for .eea entries inside the main zipFile of the entry: + ZipFile zip = classpathEntry instanceof ClasspathJar ? ((ClasspathJar) classpathEntry).zipFile : null; + boolean shouldClose = false; // don't close classpathEntry.zipFile, which we don't own + try { + if (zip == null) { + zip = ExternalAnnotationDecorator.getAnnotationZipFile(classpathEntry.getPath(), null); + shouldClose = true; + } + answer.setBinaryType(ExternalAnnotationDecorator.create(answer.getBinaryType(), classpathEntry.getPath(), + qualifiedTypeName, zip)); + return answer; + } catch (IOException e) { + // ignore broken entry, keep searching + } finally { + if (shouldClose && zip != null) + try { + zip.close(); + } catch (IOException e) { /* nothing */ } + } + } + } + // globally configured (annotationsFromClasspath), but no .eea found, decorate in order to answer NO_EEA_FILE: + answer.setBinaryType(new ExternalAnnotationDecorator(answer.getBinaryType(), null)); + } + return answer; +} +private NameEnvironmentAnswer internalFindClass(String qualifiedTypeName, char[] typeName, boolean asBinaryOnly, /*NonNull*/char[] moduleName) { + if (this.knownFileNames.contains(qualifiedTypeName)) return null; // looking for a file which we know was provided at the beginning of the compilation + + String qualifiedBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class; + String qualifiedPackageName = + qualifiedTypeName.length() == typeName.length + ? Util.EMPTY_STRING + : qualifiedBinaryFileName.substring(0, qualifiedTypeName.length() - typeName.length - 1); + + LookupStrategy strategy = LookupStrategy.get(moduleName); + if (strategy == LookupStrategy.Named) { + if (this.moduleLocations != null) { + // searching for a specific named module: + String moduleNameString = String.valueOf(moduleName); + Classpath classpath = this.moduleLocations.get(moduleNameString); + if (classpath != null) { + return classpath.findClass(typeName, qualifiedPackageName, moduleNameString, qualifiedBinaryFileName); + } + } + return null; + } + String qp2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar); + NameEnvironmentAnswer suggestedAnswer = null; + if (qualifiedPackageName == qp2) { + for (int i = 0, length = this.classpaths.length; i < length; i++) { + if (!strategy.matches(this.classpaths[i], Classpath::hasModule)) + continue; + NameEnvironmentAnswer answer = this.classpaths[i].findClass(typeName, qualifiedPackageName, null, qualifiedBinaryFileName, asBinaryOnly); + if (answer != null) { + if (answer.moduleName() != null && !this.moduleLocations.containsKey(String.valueOf(answer.moduleName()))) + continue; // type belongs to an unobservable module + if (!answer.ignoreIfBetter()) { + if (answer.isBetter(suggestedAnswer)) + return answer; + } else if (answer.isBetter(suggestedAnswer)) + // remember suggestion and keep looking + suggestedAnswer = answer; + } + } + } else { + String qb2 = qualifiedBinaryFileName.replace('/', File.separatorChar); + for (int i = 0, length = this.classpaths.length; i < length; i++) { + Classpath p = this.classpaths[i]; + if (!strategy.matches(p, Classpath::hasModule)) + continue; + NameEnvironmentAnswer answer = !(p instanceof ClasspathDirectory) + ? p.findClass(typeName, qualifiedPackageName, null, qualifiedBinaryFileName, asBinaryOnly) + : p.findClass(typeName, qp2, null, qb2, asBinaryOnly); + if (answer != null) { + if (answer.moduleName() != null && !this.moduleLocations.containsKey(String.valueOf(answer.moduleName()))) + continue; // type belongs to an unobservable module + if (!answer.ignoreIfBetter()) { + if (answer.isBetter(suggestedAnswer)) + return answer; + } else if (answer.isBetter(suggestedAnswer)) + // remember suggestion and keep looking + suggestedAnswer = answer; + } + } + } + return suggestedAnswer; +} + +@Override +public NameEnvironmentAnswer findType(char[][] compoundName, char[] moduleName) { + if (compoundName != null) + return findClass( + new String(CharOperation.concatWith(compoundName, '/')), + compoundName[compoundName.length - 1], + false, + moduleName); + return null; +} +public char[][][] findTypeNames(char[][] packageName) { + char[][][] result = null; + if (packageName != null) { + String qualifiedPackageName = new String(CharOperation.concatWith(packageName, '/')); + String qualifiedPackageName2 = File.separatorChar == '/' ? qualifiedPackageName : qualifiedPackageName.replace('/', File.separatorChar); + if (qualifiedPackageName == qualifiedPackageName2) { + for (int i = 0, length = this.classpaths.length; i < length; i++) { + char[][][] answers = this.classpaths[i].findTypeNames(qualifiedPackageName, null); + if (answers != null) { + // concat with previous answers + if (result == null) { + result = answers; + } else { + int resultLength = result.length; + int answersLength = answers.length; + System.arraycopy(result, 0, (result = new char[answersLength + resultLength][][]), 0, resultLength); + System.arraycopy(answers, 0, result, resultLength, answersLength); + } + } + } + } else { + for (int i = 0, length = this.classpaths.length; i < length; i++) { + Classpath p = this.classpaths[i]; + char[][][] answers = !(p instanceof ClasspathDirectory) ? p.findTypeNames(qualifiedPackageName, null) + : p.findTypeNames(qualifiedPackageName2, null); + if (answers != null) { + // concat with previous answers + if (result == null) { + result = answers; + } else { + int resultLength = result.length; + int answersLength = answers.length; + System.arraycopy(result, 0, (result = new char[answersLength + resultLength][][]), 0, + resultLength); + System.arraycopy(answers, 0, result, resultLength, answersLength); + } + } + } + } + } + return result; +} + +@Override +public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName, char[] moduleName) { + if (typeName != null) + return findClass( + new String(CharOperation.concatWith(packageName, typeName, '/')), + typeName, + false, + moduleName); + return null; +} + +@Override +public char[][] getModulesDeclaringPackage(char[][] packageName, char[] moduleName) { + String qualifiedPackageName = new String(CharOperation.concatWith(packageName, '/')); + String moduleNameString = String.valueOf(moduleName); + + LookupStrategy strategy = LookupStrategy.get(moduleName); + if (strategy == LookupStrategy.Named) { + if (this.moduleLocations != null) { + // specific search in a given module: + Classpath classpath = this.moduleLocations.get(moduleNameString); + if (classpath != null) { + if (classpath.isPackage(qualifiedPackageName, moduleNameString)) + return new char[][] {moduleName}; + } + } + return null; + } + // search the entire environment and answer which modules declare that package: + char[][] allNames = null; + boolean hasUnobserable = false; + for (Classpath cp : this.classpaths) { + if (strategy.matches(cp, Classpath::hasModule)) { + if (strategy == LookupStrategy.Unnamed) { + // short-cut + if (cp.isPackage(qualifiedPackageName, moduleNameString)) + return new char[][] { ModuleBinding.UNNAMED }; + } else { + char[][] declaringModules = cp.getModulesDeclaringPackage(qualifiedPackageName, null); + if (declaringModules != null) { + if (cp instanceof ClasspathJrt && this.hasLimitModules) { + declaringModules = filterModules(declaringModules); + hasUnobserable |= declaringModules == null; + } + if (allNames == null) + allNames = declaringModules; + else + allNames = CharOperation.arrayConcat(allNames, declaringModules); + } + } + } + } + if (allNames == null && hasUnobserable) + return new char[][] { ModuleBinding.UNOBSERVABLE }; + return allNames; +} +private char[][] filterModules(char[][] declaringModules) { + char[][] filtered = Arrays.stream(declaringModules).filter(m -> this.moduleLocations.containsKey(new String(m))).toArray(char[][]::new); + if (filtered.length == 0) + return null; + return filtered; +} +private Parser getParser() { + Map opts = new HashMap(); + opts.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); + return new Parser( + new ProblemReporter(DefaultErrorHandlingPolicies.exitOnFirstError(), new CompilerOptions(opts), new DefaultProblemFactory(Locale.getDefault())), + false); +} +@Override +public boolean hasCompilationUnit(char[][] qualifiedPackageName, char[] moduleName, boolean checkCUs) { + String qPackageName = String.valueOf(CharOperation.concatWith(qualifiedPackageName, '/')); + String moduleNameString = String.valueOf(moduleName); + LookupStrategy strategy = LookupStrategy.get(moduleName); + Parser parser = checkCUs ? getParser() : null; + Function pkgNameExtractor = (sourceUnit) -> { + String pkgName = null; + CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 1); + char[][] name = parser.parsePackageDeclaration(sourceUnit.getContents(), compilationResult); + if (name != null) { + pkgName = CharOperation.toString(name); + } + return pkgName; + }; + switch (strategy) { + case Named: + if (this.moduleLocations != null) { + Classpath location = this.moduleLocations.get(moduleNameString); + if (location != null) + return checkCUs ? location.hasCUDeclaringPackage(qPackageName, pkgNameExtractor) + : location.hasCompilationUnit(qPackageName, moduleNameString); + } + return false; + default: + for (int i = 0; i < this.classpaths.length; i++) { + Classpath location = this.classpaths[i]; + if (strategy.matches(location, Classpath::hasModule)) + if (location.hasCompilationUnit(qPackageName, moduleNameString)) + return true; + } + return false; + } +} + +@Override +public IModule getModule(char[] name) { + if (this.module != null && CharOperation.equals(name, this.module.name())) { + return this.module; + } + if (this.moduleLocations.containsKey(new String(name))) { + for (Classpath classpath : this.classpaths) { + IModule mod = classpath.getModule(name); + if (mod != null) { + return mod; + } + } + } + return null; +} +public IModule getModuleFromEnvironment(char[] name) { + if (this.module != null && CharOperation.equals(name, this.module.name())) { + return this.module; + } + for (Classpath classpath : this.classpaths) { + IModule mod = classpath.getModule(name); + if (mod != null) { + return mod; + } + } + return null; +} + +@Override +public char[][] getAllAutomaticModules() { + Set set = new HashSet<>(); + for (int i = 0, l = this.classpaths.length; i < l; i++) { + if (this.classpaths[i].isAutomaticModule()) { + set.add(this.classpaths[i].getModule().name()); + } + } + return set.toArray(new char[set.size()][]); +} + +@Override +public char[][] listPackages(char[] moduleName) { + switch (LookupStrategy.get(moduleName)) { + case Named: + Classpath classpath = this.moduleLocations.get(new String(moduleName)); + if (classpath != null) + return classpath.listPackages(); + return CharOperation.NO_CHAR_CHAR; + default: + throw new UnsupportedOperationException("can list packages only of a named module"); //$NON-NLS-1$ + } +} + +void addModuleUpdate(String moduleName, Consumer update, UpdateKind kind) { + UpdatesByKind updates = this.moduleUpdates.get(moduleName); + if (updates == null) { + this.moduleUpdates.put(moduleName, updates = new UpdatesByKind()); + } + updates.getList(kind, true).add(update); +} +@Override +public void applyModuleUpdates(IUpdatableModule compilerModule, IUpdatableModule.UpdateKind kind) { + char[] name = compilerModule.name(); + if (name != ModuleBinding.UNNAMED) { // can't update the unnamed module + UpdatesByKind updates = this.moduleUpdates.get(String.valueOf(name)); + if (updates != null) { + for (Consumer update : updates.getList(kind, false)) + update.accept(compilerModule); + } + } +} +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java new file mode 100644 index 0000000000..a9a01c78e6 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -0,0 +1,5696 @@ +// GROOVY PATCHED +/******************************************************************************* + * Copyright (c) 2000, 2021 IBM Corporation and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + * Tom Tromey - Contribution for bug 125961 + * Tom Tromey - Contribution for bug 159641 + * Benjamin Muskalla - Contribution for bug 239066 + * Stephan Herrmann - Contributions for + * bug 236385 - [compiler] Warn for potential programming problem if an object is created but not used + * bug 295551 - Add option to automatically promote all warnings to errors + * bug 359721 - [options] add command line option for new warning token "resource" + * bug 365208 - [compiler][batch] command line options for annotation based null analysis + * bug 374605 - Unreasonable warning for enum-based switch statements + * bug 375366 - ECJ ignores unusedParameterIncludeDocCommentReference unless enableJavadoc option is set + * bug 388281 - [compiler][null] inheritance of null annotations as an option + * bug 381443 - [compiler][null] Allow parameter widening from @NonNull to unannotated + * Bug 440477 - [null] Infrastructure for feeding external annotations into compilation + * Bug 440687 - [compiler][batch][null] improve command line option for external annotations + * Bug 408815 - [batch][null] Add CLI option for COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS + * Jesper S Moller - Contributions for + * bug 407297 - [1.8][compiler] Control generation of parameter names by option + * Mat Booth - Contribution for bug 405176 + * Frits Jalvingh - fix for bug 533830. + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.BufferedInputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.DateFormat; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; +import java.util.MissingResourceException; +import java.util.Properties; +import java.util.ResourceBundle; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.function.Function; + +import org.eclipse.jdt.core.compiler.CategorizedProblem; +import org.eclipse.jdt.core.compiler.CharOperation; +import org.eclipse.jdt.core.compiler.CompilationProgress; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.core.compiler.batch.BatchCompiler; +import org.eclipse.jdt.internal.compiler.AbstractAnnotationProcessorManager; +import org.eclipse.jdt.internal.compiler.ClassFile; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.Compiler; +import org.eclipse.jdt.internal.compiler.ICompilerRequestor; +import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; +import org.eclipse.jdt.internal.compiler.IProblemFactory; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; +import org.eclipse.jdt.internal.compiler.batch.ModuleFinder.AddExport; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationProvider; +import org.eclipse.jdt.internal.compiler.env.AccessRestriction; +import org.eclipse.jdt.internal.compiler.env.AccessRule; +import org.eclipse.jdt.internal.compiler.env.AccessRuleSet; +import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.IModule.IPackageExport; +import org.eclipse.jdt.internal.compiler.env.IUpdatableModule.UpdateKind; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.CompilerStats; +import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; +import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding; +import org.eclipse.jdt.internal.compiler.lookup.PackageBinding; +import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; +import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; +import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; +import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; +import org.eclipse.jdt.internal.compiler.util.GenericXMLWriter; +import org.eclipse.jdt.internal.compiler.util.HashtableOfInt; +import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; +import org.eclipse.jdt.internal.compiler.util.Messages; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; +import org.eclipse.jdt.internal.compiler.util.Util; + +public class Main implements ProblemSeverities, SuffixConstants { + + public static class Logger { + private PrintWriter err; + private PrintWriter log; + private Main main; + private PrintWriter out; + int tagBits; + private static final String CLASS = "class"; //$NON-NLS-1$ + private static final String CLASS_FILE = "classfile"; //$NON-NLS-1$ + private static final String CLASSPATH = "classpath"; //$NON-NLS-1$ + private static final String CLASSPATH_FILE = "FILE"; //$NON-NLS-1$ + private static final String CLASSPATH_FOLDER = "FOLDER"; //$NON-NLS-1$ + private static final String CLASSPATH_ID = "id"; //$NON-NLS-1$ + private static final String CLASSPATH_JAR = "JAR"; //$NON-NLS-1$ + private static final String CLASSPATHS = "classpaths"; //$NON-NLS-1$ + private static final String COMMAND_LINE_ARGUMENT = "argument"; //$NON-NLS-1$ + private static final String COMMAND_LINE_ARGUMENTS = "command_line"; //$NON-NLS-1$ + private static final String COMPILER = "compiler"; //$NON-NLS-1$ + private static final String COMPILER_COPYRIGHT = "copyright"; //$NON-NLS-1$ + private static final String COMPILER_NAME = "name"; //$NON-NLS-1$ + private static final String COMPILER_VERSION = "version"; //$NON-NLS-1$ + public static final int EMACS = 2; + private static final String ERROR = "ERROR"; //$NON-NLS-1$ + private static final String ERROR_TAG = "error"; //$NON-NLS-1$ + private static final String WARNING_TAG = "warning"; //$NON-NLS-1$ + private static final String EXCEPTION = "exception"; //$NON-NLS-1$ + private static final String EXTRA_PROBLEM_TAG = "extra_problem"; //$NON-NLS-1$ + private static final String EXTRA_PROBLEMS = "extra_problems"; //$NON-NLS-1$ + private static final HashtableOfInt FIELD_TABLE = new HashtableOfInt(); + private static final String KEY = "key"; //$NON-NLS-1$ + private static final String MESSAGE = "message"; //$NON-NLS-1$ + private static final String NUMBER_OF_CLASSFILES = "number_of_classfiles"; //$NON-NLS-1$ + private static final String NUMBER_OF_ERRORS = "errors"; //$NON-NLS-1$ + private static final String NUMBER_OF_LINES = "number_of_lines"; //$NON-NLS-1$ + private static final String NUMBER_OF_PROBLEMS = "problems"; //$NON-NLS-1$ + private static final String NUMBER_OF_TASKS = "tasks"; //$NON-NLS-1$ + private static final String NUMBER_OF_WARNINGS = "warnings"; //$NON-NLS-1$ + private static final String NUMBER_OF_INFOS = "infos"; //$NON-NLS-1$ + private static final String OPTION = "option"; //$NON-NLS-1$ + private static final String OPTIONS = "options"; //$NON-NLS-1$ + private static final String OUTPUT = "output"; //$NON-NLS-1$ + private static final String PACKAGE = "package"; //$NON-NLS-1$ + private static final String PATH = "path"; //$NON-NLS-1$ + private static final String PROBLEM_ARGUMENT = "argument"; //$NON-NLS-1$ + private static final String PROBLEM_ARGUMENT_VALUE = "value"; //$NON-NLS-1$ + private static final String PROBLEM_ARGUMENTS = "arguments"; //$NON-NLS-1$ + private static final String PROBLEM_CATEGORY_ID = "categoryID"; //$NON-NLS-1$ + private static final String ID = "id"; //$NON-NLS-1$ + private static final String PROBLEM_ID = "problemID"; //$NON-NLS-1$ + private static final String PROBLEM_LINE = "line"; //$NON-NLS-1$ + private static final String PROBLEM_OPTION_KEY = "optionKey"; //$NON-NLS-1$ + private static final String PROBLEM_MESSAGE = "message"; //$NON-NLS-1$ + private static final String PROBLEM_SEVERITY = "severity"; //$NON-NLS-1$ + private static final String PROBLEM_SOURCE_END = "charEnd"; //$NON-NLS-1$ + private static final String PROBLEM_SOURCE_START = "charStart"; //$NON-NLS-1$ + private static final String PROBLEM_SUMMARY = "problem_summary"; //$NON-NLS-1$ + private static final String PROBLEM_TAG = "problem"; //$NON-NLS-1$ + private static final String PROBLEMS = "problems"; //$NON-NLS-1$ + private static final String SOURCE = "source"; //$NON-NLS-1$ + private static final String SOURCE_CONTEXT = "source_context"; //$NON-NLS-1$ + private static final String SOURCE_END = "sourceEnd"; //$NON-NLS-1$ + private static final String SOURCE_START = "sourceStart"; //$NON-NLS-1$ + private static final String SOURCES = "sources"; //$NON-NLS-1$ + + private static final String STATS = "stats"; //$NON-NLS-1$ + + private static final String TASK = "task"; //$NON-NLS-1$ + private static final String TASKS = "tasks"; //$NON-NLS-1$ + private static final String TIME = "time"; //$NON-NLS-1$ + private static final String VALUE = "value"; //$NON-NLS-1$ + private static final String WARNING = "WARNING"; //$NON-NLS-1$ + private static final String INFO = "INFO"; //$NON-NLS-1$ + + public static final int XML = 1; + private static final String XML_DTD_DECLARATION = ""; //$NON-NLS-1$ + static { + try { + Class c = IProblem.class; + Field[] fields = c.getFields(); + for (int i = 0, max = fields.length; i < max; i++) { + Field field = fields[i]; + if (field.getType().equals(Integer.TYPE)) { + Integer value = (Integer) field.get(null); + int key2 = value.intValue() & IProblem.IgnoreCategoriesMask; + if (key2 == 0) { + key2 = Integer.MAX_VALUE; + } + Logger.FIELD_TABLE.put(key2, field.getName()); + } + } + } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { + e.printStackTrace(); + } + } + public Logger(Main main, PrintWriter out, PrintWriter err) { + this.out = out; + this.err = err; + this.main = main; + } + + public String buildFileName( + String outputPath, + String relativeFileName) { + char fileSeparatorChar = File.separatorChar; + String fileSeparator = File.separator; + + outputPath = outputPath.replace('/', fileSeparatorChar); + // To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name + StringBuilder outDir = new StringBuilder(outputPath); + if (!outputPath.endsWith(fileSeparator)) { + outDir.append(fileSeparator); + } + StringTokenizer tokenizer = + new StringTokenizer(relativeFileName, fileSeparator); + String token = tokenizer.nextToken(); + while (tokenizer.hasMoreTokens()) { + outDir.append(token).append(fileSeparator); + token = tokenizer.nextToken(); + } + // token contains the last one + return outDir.append(token).toString(); + } + + public void close() { + if (this.log != null) { + if ((this.tagBits & Logger.XML) != 0) { + endTag(Logger.COMPILER); + flush(); + } + this.log.close(); + } + } + + /** + * + */ + public void compiling() { + printlnOut(this.main.bind("progress.compiling")); //$NON-NLS-1$ + } + private void endLoggingExtraProblems() { + endTag(Logger.EXTRA_PROBLEMS); + } + /** + * Used to stop logging problems. + * Only use in xml mode. + */ + private void endLoggingProblems() { + endTag(Logger.PROBLEMS); + } + public void endLoggingSource() { + if ((this.tagBits & Logger.XML) != 0) { + endTag(Logger.SOURCE); + } + } + + public void endLoggingSources() { + if ((this.tagBits & Logger.XML) != 0) { + endTag(Logger.SOURCES); + } + } + + public void endLoggingTasks() { + if ((this.tagBits & Logger.XML) != 0) { + endTag(Logger.TASKS); + } + } + private void endTag(String name) { + if (this.log != null) { + ((GenericXMLWriter) this.log).endTag(name, true, true); + } + } + private String errorReportSource(CategorizedProblem problem, char[] unitSource, int bits) { + //extra from the source the innacurate token + //and "highlight" it using some underneath ^^^^^ + //put some context around too. + + //this code assumes that the font used in the console is fixed size + + //sanity ..... + int startPosition = problem.getSourceStart(); + int endPosition = problem.getSourceEnd(); + if (unitSource == null) { + if (problem.getOriginatingFileName() != null) { + try { + unitSource = Util.getFileCharContent(new File(new String(problem.getOriginatingFileName())), null); + } catch (IOException e) { + // ignore; + } + } + } + int length; + if ((startPosition > endPosition) + || ((startPosition < 0) && (endPosition < 0)) + || (unitSource == null) + || (length = unitSource.length) == 0) + return Messages.problem_noSourceInformation; + + StringBuilder errorBuffer = new StringBuilder(); + if ((bits & Main.Logger.EMACS) == 0) { + errorBuffer.append(' ').append(Messages.bind(Messages.problem_atLine, String.valueOf(problem.getSourceLineNumber()))); + errorBuffer.append(Util.LINE_SEPARATOR); + } + errorBuffer.append('\t'); + + char c; + final char SPACE = '\u0020'; + final char MARK = '^'; + final char TAB = '\t'; + //the next code tries to underline the token..... + //it assumes (for a good display) that token source does not + //contain any \r \n. This is false on statements ! + //(the code still works but the display is not optimal !) + + // expand to line limits + int begin; + int end; + for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) { + if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break; + } + for (end = endPosition >= length ? length - 1 : endPosition ; end+1 < length; end++) { + if ((c = unitSource[end + 1]) == '\r' || c == '\n') break; + } + + // trim left and right spaces/tabs + while ((c = unitSource[begin]) == ' ' || c == '\t') begin++; + //while ((c = unitSource[end]) == ' ' || c == '\t') end--; TODO (philippe) should also trim right, but all tests are to be updated + + // copy source + errorBuffer.append(unitSource, begin, end-begin+1); + errorBuffer.append(Util.LINE_SEPARATOR).append("\t"); //$NON-NLS-1$ + + // compute underline + for (int i = begin; i = length ? length - 1 : endPosition); i++) { + errorBuffer.append(MARK); + } + return errorBuffer.toString(); + } + + private void extractContext(CategorizedProblem problem, char[] unitSource) { + //sanity ..... + int startPosition = problem.getSourceStart(); + int endPosition = problem.getSourceEnd(); + if (unitSource == null) { + if (problem.getOriginatingFileName() != null) { + try { + unitSource = Util.getFileCharContent(new File(new String(problem.getOriginatingFileName())), null); + } catch(IOException e) { + // ignore + } + } + } + int length; + if ((startPosition > endPosition) + || ((startPosition < 0) && (endPosition < 0)) + || (unitSource == null) + || ((length = unitSource.length) <= 0) + || (endPosition > length)) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.VALUE, Messages.problem_noSourceInformation); + parameters.put(Logger.SOURCE_START, "-1"); //$NON-NLS-1$ + parameters.put(Logger.SOURCE_END, "-1"); //$NON-NLS-1$ + printTag(Logger.SOURCE_CONTEXT, parameters, true, true); + return; + } + + char c; + //the next code tries to underline the token..... + //it assumes (for a good display) that token source does not + //contain any \r \n. This is false on statements ! + //(the code still works but the display is not optimal !) + + // expand to line limits + int begin, end; + for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) { + if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break; + } + for (end = endPosition >= length ? length - 1 : endPosition ; end+1 < length; end++) { + if ((c = unitSource[end + 1]) == '\r' || c == '\n') break; + } + + // trim left and right spaces/tabs + while ((c = unitSource[begin]) == ' ' || c == '\t') begin++; + while ((c = unitSource[end]) == ' ' || c == '\t') end--; + + // copy source + StringBuffer buffer = new StringBuffer(); + buffer.append(unitSource, begin, end - begin + 1); + HashMap parameters = new HashMap<>(); + parameters.put(Logger.VALUE, String.valueOf(buffer)); + parameters.put(Logger.SOURCE_START, Integer.toString(startPosition - begin)); + parameters.put(Logger.SOURCE_END, Integer.toString(endPosition - begin)); + printTag(Logger.SOURCE_CONTEXT, parameters, true, true); + } + public void flush() { + this.out.flush(); + this.err.flush(); + if (this.log != null) { + this.log.flush(); + } + } + + private String getFieldName(int id) { + int key2 = id & IProblem.IgnoreCategoriesMask; + if (key2 == 0) { + key2 = Integer.MAX_VALUE; + } + return (String) Logger.FIELD_TABLE.get(key2); + } + + // find out an option name controlling a given problemID + private String getProblemOptionKey(int problemID) { + int irritant = ProblemReporter.getIrritant(problemID); + return CompilerOptions.optionKeyFromIrritant(irritant); + } + + public void logAverage() { + Arrays.sort(this.main.compilerStats); + long lineCount = this.main.compilerStats[0].lineCount; + final int length = this.main.maxRepetition; + long sum = 0; + long parseSum = 0, resolveSum = 0, analyzeSum = 0, generateSum = 0; + for (int i = 1, max = length - 1; i < max; i++) { + CompilerStats stats = this.main.compilerStats[i]; + sum += stats.elapsedTime(); + parseSum += stats.parseTime; + resolveSum += stats.resolveTime; + analyzeSum += stats.analyzeTime; + generateSum += stats.generateTime; + } + long time = sum / (length - 2); + long parseTime = parseSum/(length - 2); + long resolveTime = resolveSum/(length - 2); + long analyzeTime = analyzeSum/(length - 2); + long generateTime = generateSum/(length - 2); + printlnOut(this.main.bind( + "compile.averageTime", //$NON-NLS-1$ + new String[] { + String.valueOf(lineCount), + String.valueOf(time), + String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0), + })); + if ((this.main.timing & Main.TIMING_DETAILED) != 0) { + printlnOut( + this.main.bind("compile.detailedTime", //$NON-NLS-1$ + new String[] { + String.valueOf(parseTime), + String.valueOf(((int) (parseTime * 1000.0 / time)) / 10.0), + String.valueOf(resolveTime), + String.valueOf(((int) (resolveTime * 1000.0 / time)) / 10.0), + String.valueOf(analyzeTime), + String.valueOf(((int) (analyzeTime * 1000.0 / time)) / 10.0), + String.valueOf(generateTime), + String.valueOf(((int) (generateTime * 1000.0 / time)) / 10.0), + })); + } + } + public void logClassFile(boolean generatePackagesStructure, String outputPath, String relativeFileName) { + if ((this.tagBits & Logger.XML) != 0) { + String fileName = null; + if (generatePackagesStructure) { + fileName = buildFileName(outputPath, relativeFileName); + } else { + char fileSeparatorChar = File.separatorChar; + String fileSeparator = File.separator; + // First we ensure that the outputPath exists + outputPath = outputPath.replace('/', fileSeparatorChar); + // To be able to pass the mkdirs() method we need to remove the extra file separator at the end of the outDir name + int indexOfPackageSeparator = relativeFileName.lastIndexOf(fileSeparatorChar); + if (indexOfPackageSeparator == -1) { + if (outputPath.endsWith(fileSeparator)) { + fileName = outputPath + relativeFileName; + } else { + fileName = outputPath + fileSeparator + relativeFileName; + } + } else { + int length = relativeFileName.length(); + if (outputPath.endsWith(fileSeparator)) { + fileName = outputPath + relativeFileName.substring(indexOfPackageSeparator + 1, length); + } else { + fileName = outputPath + fileSeparator + relativeFileName.substring(indexOfPackageSeparator + 1, length); + } + } + } + File f = new File(fileName); + try { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.PATH, f.getCanonicalPath()); + printTag(Logger.CLASS_FILE, parameters, true, true); + } catch (IOException e) { + logNoClassFileCreated(outputPath, relativeFileName, e); + } + } + } + public void logClasspath(FileSystem.Classpath[] classpaths) { + if (classpaths == null) return; + if ((this.tagBits & Logger.XML) != 0) { + final int length = classpaths.length; + if (length != 0) { + // generate xml output + printTag(Logger.CLASSPATHS, new HashMap<>(), true, false); + HashMap parameters = new HashMap<>(); + for (int i = 0; i < length; i++) { + String classpath = classpaths[i].getPath(); + parameters.put(Logger.PATH, classpath); + File f = new File(classpath); + String id = null; + if (f.isFile()) { + int kind = Util.archiveFormat(classpath); + switch (kind) { + case Util.ZIP_FILE: + id = Logger.CLASSPATH_JAR; + break; + default: + id = Logger.CLASSPATH_FILE; + break; + } + } else if (f.isDirectory()) { + id = Logger.CLASSPATH_FOLDER; + } + if (id != null) { + parameters.put(Logger.CLASSPATH_ID, id); + printTag(Logger.CLASSPATH, parameters, true, true); + } + } + endTag(Logger.CLASSPATHS); + } + } + + } + + public void logCommandLineArguments(String[] commandLineArguments) { + if (commandLineArguments == null) return; + if ((this.tagBits & Logger.XML) != 0) { + final int length = commandLineArguments.length; + if (length != 0) { + // generate xml output + printTag(Logger.COMMAND_LINE_ARGUMENTS, new HashMap<>(), true, false); + for (int i = 0; i < length; i++) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.VALUE, commandLineArguments[i]); + printTag(Logger.COMMAND_LINE_ARGUMENT, parameters, true, true); + } + endTag(Logger.COMMAND_LINE_ARGUMENTS); + } + } + } + + /** + * @param e the given exception to log + */ + public void logException(Exception e) { + StringWriter writer = new StringWriter(); + PrintWriter printWriter = new PrintWriter(writer); + e.printStackTrace(printWriter); + printWriter.flush(); + printWriter.close(); + final String stackTrace = writer.toString(); + if ((this.tagBits & Logger.XML) != 0) { + LineNumberReader reader = new LineNumberReader(new StringReader(stackTrace)); + String line; + int i = 0; + StringBuilder buffer = new StringBuilder(); + String message = e.getMessage(); + if (message != null) { + buffer.append(message).append(Util.LINE_SEPARATOR); + } + try { + while ((line = reader.readLine()) != null && i < 4) { + buffer.append(line).append(Util.LINE_SEPARATOR); + i++; + } + reader.close(); + } catch (IOException e1) { + // ignore + } + message = buffer.toString(); + HashMap parameters = new HashMap<>(); + parameters.put(Logger.MESSAGE, message); + parameters.put(Logger.CLASS, e.getClass()); + printTag(Logger.EXCEPTION, parameters, true, true); + } + String message = e.getMessage(); + if (message == null) { + this.printlnErr(stackTrace); + } else { + this.printlnErr(message); + } + } + + private void logExtraProblem(CategorizedProblem problem, int localErrorCount, int globalErrorCount) { + char[] originatingFileName = problem.getOriginatingFileName(); + if (originatingFileName == null) { + // simplified message output + String severity = problem.isError() ? "requestor.extraerror" //$NON-NLS-1$ + : problem.isInfo() ? "requestor.extrainfo" : "requestor.extrawarning"; //$NON-NLS-1$ //$NON-NLS-2$ + printErr(this.main.bind( + severity, + Integer.toString(globalErrorCount))); + printErr(" "); //$NON-NLS-1$ + this.printlnErr(problem.getMessage()); + } else { + String fileName = new String(originatingFileName); + if ((this.tagBits & Logger.EMACS) != 0) { + String severity = problem.isError() ? "output.emacs.error" : //$NON-NLS-1$ + problem.isInfo() ? "output.emacs.info" //$NON-NLS-1$ + : "output.emacs.warning"; //$NON-NLS-1$ + String result = fileName + + ":" //$NON-NLS-1$ + + problem.getSourceLineNumber() + + ": " //$NON-NLS-1$ + + this.main.bind(severity) + + ": " //$NON-NLS-1$ + + problem.getMessage(); + this.printlnErr(result); + final String errorReportSource = errorReportSource(problem, null, this.tagBits); + this.printlnErr(errorReportSource); + } else { + if (localErrorCount == 0) { + this.printlnErr("----------"); //$NON-NLS-1$ + } + String severity = problem.isError() ? "requestor.error" //$NON-NLS-1$ + : problem.isInfo() ? "requestor.info" : "requestor.warning"; //$NON-NLS-1$ //$NON-NLS-2$ + printErr(this.main.bind( + severity, + Integer.toString(globalErrorCount), + fileName)); + final String errorReportSource = errorReportSource(problem, null, 0); + this.printlnErr(errorReportSource); + this.printlnErr(problem.getMessage()); + this.printlnErr("----------"); //$NON-NLS-1$ + } + } + } + + public void loggingExtraProblems(Main currentMain) { + ArrayList problems = currentMain.extraProblems; + final int count = problems.size(); + int localProblemCount = 0; + if (count != 0) { + int errors = 0; + int warnings = 0; + int infos = 0; + for (int i = 0; i < count; i++) { + CategorizedProblem problem = problems.get(i); + if (!this.main.isIgnored(problem)) { + currentMain.globalProblemsCount++; + logExtraProblem(problem, localProblemCount, currentMain.globalProblemsCount); + localProblemCount++; + if (problem.isError()) { + errors++; + currentMain.globalErrorsCount++; + } else if (problem.isInfo()) { + currentMain.globalInfoCount++; + infos++; + } else { + currentMain.globalWarningsCount++; + warnings++; + } + } + } + if ((this.tagBits & Logger.XML) != 0) { + if ((errors + warnings + infos) != 0) { + startLoggingExtraProblems(count); + for (int i = 0; i < count; i++) { + CategorizedProblem problem = problems.get(i); + if (!this.main.isIgnored(problem)) { + if (problem.getID() != IProblem.Task) { + logXmlExtraProblem(problem, localProblemCount, currentMain.globalProblemsCount); + } + } + } + endLoggingExtraProblems(); + } + } + } + } + + public void logUnavaibleAPT(String className) { + if ((this.tagBits & Logger.XML) != 0) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.MESSAGE, this.main.bind("configure.unavailableAPT", className)); //$NON-NLS-1$ + printTag(Logger.ERROR_TAG, parameters, true, true); + } + this.printlnErr(this.main.bind("configure.unavailableAPT", className)); //$NON-NLS-1$ + } + + public void logIncorrectVMVersionForAnnotationProcessing() { + if ((this.tagBits & Logger.XML) != 0) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.MESSAGE, this.main.bind("configure.incorrectVMVersionforAPT")); //$NON-NLS-1$ + printTag(Logger.ERROR_TAG, parameters, true, true); + } + this.printlnErr(this.main.bind("configure.incorrectVMVersionforAPT")); //$NON-NLS-1$ + } + + /** + * + */ + public void logNoClassFileCreated(String outputDir, String relativeFileName, IOException e) { + if ((this.tagBits & Logger.XML) != 0) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.MESSAGE, this.main.bind("output.noClassFileCreated", //$NON-NLS-1$ + new String[] { + outputDir, + relativeFileName, + e.getMessage() + })); + printTag(Logger.ERROR_TAG, parameters, true, true); + } + this.printlnErr(this.main.bind("output.noClassFileCreated", //$NON-NLS-1$ + new String[] { + outputDir, + relativeFileName, + e.getMessage() + })); + } + + /** + * @param exportedClassFilesCounter + */ + public void logNumberOfClassFilesGenerated(int exportedClassFilesCounter) { + if ((this.tagBits & Logger.XML) != 0) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.VALUE, Integer.valueOf(exportedClassFilesCounter)); + printTag(Logger.NUMBER_OF_CLASSFILES, parameters, true, true); + } + if (exportedClassFilesCounter == 1) { + printlnOut(this.main.bind("compile.oneClassFileGenerated")); //$NON-NLS-1$ + } else { + printlnOut(this.main.bind("compile.severalClassFilesGenerated", //$NON-NLS-1$ + String.valueOf(exportedClassFilesCounter))); + } + } + + /** + * @param options the given compiler options + */ + public void logOptions(Map options) { + if ((this.tagBits & Logger.XML) != 0) { + printTag(Logger.OPTIONS, new HashMap<>(), true, false); + final Set> entriesSet = options.entrySet(); + Map.Entry[] entries = entriesSet.toArray(new Map.Entry[entriesSet.size()]); + Arrays.sort(entries, new Comparator>() { + @Override + public int compare(Map.Entry o1, Map.Entry o2) { + Map.Entry entry1 = o1; + Map.Entry entry2 = o2; + return entry1.getKey().compareTo(entry2.getKey()); + } + }); + HashMap parameters = new HashMap<>(); + for (int i = 0, max = entries.length; i < max; i++) { + Map.Entry entry = entries[i]; + String key = entry.getKey(); + parameters.put(Logger.KEY, key); + parameters.put(Logger.VALUE, entry.getValue()); + printTag(Logger.OPTION, parameters, true, true); + } + endTag(Logger.OPTIONS); + } + } + + /** + * @param error the given error + */ + public void logPendingError(String error) { + if ((this.tagBits & Logger.XML) != 0) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.MESSAGE, error); + printTag(Logger.ERROR_TAG, parameters, true, true); + } + this.printlnErr(error); + } + + /** + * @param message the given message + */ + public void logWarning(String message) { + if ((this.tagBits & Logger.XML) != 0) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.MESSAGE, message); + printTag(Logger.WARNING_TAG, parameters, true, true); + } + this.printlnOut(message); + } + + private void logProblem(CategorizedProblem problem, int localErrorCount, + int globalErrorCount, char[] unitSource) { + if(problem instanceof DefaultProblem) { + ((DefaultProblem) problem).reportError(); + } + if ((this.tagBits & Logger.EMACS) != 0) { + String severity = problem.isError() ? "output.emacs.error" : //$NON-NLS-1$ + problem.isInfo() ? "output.emacs.info" //$NON-NLS-1$ + : "output.emacs.warning"; //$NON-NLS-1$ + String result = (new String(problem.getOriginatingFileName()) + + ":" //$NON-NLS-1$ + + problem.getSourceLineNumber() + + ": " //$NON-NLS-1$ + + (this.main.bind(severity)) + + ": " //$NON-NLS-1$ + + problem.getMessage()); + this.printlnErr(result); + final String errorReportSource = errorReportSource(problem, unitSource, this.tagBits); + if (errorReportSource.length() != 0) this.printlnErr(errorReportSource); + } else { + if (localErrorCount == 0) { + this.printlnErr("----------"); //$NON-NLS-1$ + } + String severity = problem.isError() ? "requestor.error" : problem.isInfo() ? "requestor.info" : "requestor.warning"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + printErr(this.main.bind(severity, + Integer.toString(globalErrorCount), + new String(problem.getOriginatingFileName()))); + try { + final String errorReportSource = errorReportSource(problem, unitSource, 0); + this.printlnErr(errorReportSource); + this.printlnErr(problem.getMessage()); + } catch (Exception e) { + this.printlnErr(this.main.bind( + "requestor.notRetrieveErrorMessage", problem.toString())); //$NON-NLS-1$ + } + this.printlnErr("----------"); //$NON-NLS-1$ + } + } + + public int logProblems(CategorizedProblem[] problems, char[] unitSource, Main currentMain) { + final int count = problems.length; + int localErrorCount = 0; + int localProblemCount = 0; + if (count != 0) { + int errors = 0; + int warnings = 0; + int infos = 0; + int tasks = 0; + for (int i = 0; i < count; i++) { + CategorizedProblem problem = problems[i]; + if (problem != null) { + currentMain.globalProblemsCount++; + logProblem(problem, localProblemCount, currentMain.globalProblemsCount, unitSource); + localProblemCount++; + if (problem.isError()) { + localErrorCount++; + errors++; + currentMain.globalErrorsCount++; + } else if (problem.getID() == IProblem.Task) { + currentMain.globalTasksCount++; + tasks++; + } else if (problem.isInfo()) { + currentMain.globalInfoCount++; + infos++; + } else { + currentMain.globalWarningsCount++; + warnings++; + } + } + } + if ((this.tagBits & Logger.XML) != 0) { + if ((errors + warnings + infos) != 0) { + startLoggingProblems(errors, warnings, infos); + for (int i = 0; i < count; i++) { + CategorizedProblem problem = problems[i]; + if (problem!= null) { + if (problem.getID() != IProblem.Task) { + logXmlProblem(problem, unitSource); + } + } + } + endLoggingProblems(); + } + if (tasks != 0) { + startLoggingTasks(tasks); + for (int i = 0; i < count; i++) { + CategorizedProblem problem = problems[i]; + if (problem!= null) { + if (problem.getID() == IProblem.Task) { + logXmlTask(problem, unitSource); + } + } + } + endLoggingTasks(); + } + } + } + return localErrorCount; + } + + /** + * @param globalProblemsCount + * @param globalErrorsCount + * @param globalWarningsCount + */ + public void logProblemsSummary(int globalProblemsCount, + int globalErrorsCount, int globalWarningsCount, int globalInfoCount, int globalTasksCount) { + if ((this.tagBits & Logger.XML) != 0) { + // generate xml + HashMap parameters = new HashMap<>(); + parameters.put(Logger.NUMBER_OF_PROBLEMS, Integer.valueOf(globalProblemsCount)); + parameters.put(Logger.NUMBER_OF_ERRORS, Integer.valueOf(globalErrorsCount)); + parameters.put(Logger.NUMBER_OF_WARNINGS, Integer.valueOf(globalWarningsCount)); + parameters.put(Logger.NUMBER_OF_INFOS, Integer.valueOf(globalInfoCount)); + parameters.put(Logger.NUMBER_OF_TASKS, Integer.valueOf(globalTasksCount)); + printTag(Logger.PROBLEM_SUMMARY, parameters, true, true); + } + if (globalProblemsCount == 1) { + String message = null; + if (globalErrorsCount == 1) { + message = this.main.bind("compile.oneError"); //$NON-NLS-1$ + } else if (globalInfoCount == 1) { + message = this.main.bind("compile.oneInfo"); //$NON-NLS-1$ + } else { + message = this.main.bind("compile.oneWarning"); //$NON-NLS-1$ + } + printErr(this.main.bind("compile.oneProblem", message)); //$NON-NLS-1$ + } else { + String errorMessage = null; + String warningMessage = null; + String infoMessage = null; + if (globalErrorsCount > 0) { + if (globalErrorsCount == 1) { + errorMessage = this.main.bind("compile.oneError"); //$NON-NLS-1$ + } else { + errorMessage = this.main.bind("compile.severalErrors", String.valueOf(globalErrorsCount)); //$NON-NLS-1$ + } + } + int warningsNumber = globalWarningsCount + globalTasksCount; + if (warningsNumber > 0) { + if (warningsNumber == 1) { + warningMessage = this.main.bind("compile.oneWarning"); //$NON-NLS-1$ + } else { + warningMessage = this.main.bind("compile.severalWarnings", String.valueOf(warningsNumber)); //$NON-NLS-1$ + } + } + if (globalInfoCount == 1) { + infoMessage = this.main.bind("compile.oneInfo"); //$NON-NLS-1$ + } else if (globalInfoCount > 1) { + infoMessage = this.main.bind("compile.severalInfos", String.valueOf(globalInfoCount)); //$NON-NLS-1$ + } + if (globalProblemsCount == globalInfoCount || globalProblemsCount == globalErrorsCount || globalProblemsCount == globalWarningsCount) { + String msg = errorMessage != null ? errorMessage : warningMessage != null ? warningMessage : infoMessage; + printErr(this.main.bind( + "compile.severalProblemsErrorsOrWarnings", //$NON-NLS-1$ + String.valueOf(globalProblemsCount), + msg)); + } else { + if (globalInfoCount == 0) { + printErr(this.main.bind( + "compile.severalProblemsErrorsAndWarnings", //$NON-NLS-1$ + new String[] { + String.valueOf(globalProblemsCount), + errorMessage, + warningMessage + })); + } else { + if (errorMessage == null) { + errorMessage = this.main.bind("compile.severalErrors", String.valueOf(globalErrorsCount)); //$NON-NLS-1$ + } + if (warningMessage == null) { + warningMessage = this.main.bind("compile.severalWarnings", String.valueOf(warningsNumber)); //$NON-NLS-1$ + } + printErr(this.main.bind( + "compile.severalProblems", //$NON-NLS-1$ + new String[] { + String.valueOf(globalProblemsCount), + errorMessage, + warningMessage, + infoMessage + })); + } + } + } + if (this.main.failOnWarning && globalWarningsCount > 0) { + printErr("\n"); //$NON-NLS-1$ + printErr(this.main.bind("compile.failOnWarning")); //$NON-NLS-1$ + } + if ((this.tagBits & Logger.XML) == 0) { + this.printlnErr(); + } + } + + /** + * + */ + public void logProgress() { + printOut('.'); + } + + /** + * @param i + * the current repetition number + * @param repetitions + * the given number of repetitions + */ + public void logRepetition(int i, int repetitions) { + printlnOut(this.main.bind("compile.repetition", //$NON-NLS-1$ + String.valueOf(i + 1), String.valueOf(repetitions))); + } + /** + * @param compilerStats + */ + public void logTiming(CompilerStats compilerStats) { + long time = compilerStats.elapsedTime(); + long lineCount = compilerStats.lineCount; + if ((this.tagBits & Logger.XML) != 0) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.VALUE, Long.valueOf(time)); + printTag(Logger.TIME, parameters, true, true); + parameters.put(Logger.VALUE, Long.valueOf(lineCount)); + printTag(Logger.NUMBER_OF_LINES, parameters, true, true); + } + if (lineCount != 0) { + printlnOut( + this.main.bind("compile.instantTime", //$NON-NLS-1$ + new String[] { + String.valueOf(lineCount), + String.valueOf(time), + String.valueOf(((int) (lineCount * 10000.0 / time)) / 10.0), + })); + } else { + printlnOut( + this.main.bind("compile.totalTime", //$NON-NLS-1$ + new String[] { + String.valueOf(time), + })); + } + if ((this.main.timing & Main.TIMING_DETAILED) != 0) { + printlnOut( + this.main.bind("compile.detailedTime", //$NON-NLS-1$ + new String[] { + String.valueOf(compilerStats.parseTime), + String.valueOf(((int) (compilerStats.parseTime * 1000.0 / time)) / 10.0), + String.valueOf(compilerStats.resolveTime), + String.valueOf(((int) (compilerStats.resolveTime * 1000.0 / time)) / 10.0), + String.valueOf(compilerStats.analyzeTime), + String.valueOf(((int) (compilerStats.analyzeTime * 1000.0 / time)) / 10.0), + String.valueOf(compilerStats.generateTime), + String.valueOf(((int) (compilerStats.generateTime * 1000.0 / time)) / 10.0), + })); + } + } + + /** + * Print the usage of the compiler + * @param usage + */ + public void logUsage(String usage) { + printlnOut(usage); + } + + /** + * Print the version of the compiler in the log and/or the out field + */ + public void logVersion(final boolean printToOut) { + if (this.log != null && (this.tagBits & Logger.XML) == 0) { + final String version = this.main.bind("misc.version", //$NON-NLS-1$ + new String[] { + this.main.bind("compiler.name"), //$NON-NLS-1$ + this.main.bind("compiler.version"), //$NON-NLS-1$ + this.main.bind("compiler.copyright") //$NON-NLS-1$ + } + ); + this.log.println("# " + version); //$NON-NLS-1$ + if (printToOut) { + this.out.println(version); + this.out.flush(); + } + } else if (printToOut) { + final String version = this.main.bind("misc.version", //$NON-NLS-1$ + new String[] { + this.main.bind("compiler.name"), //$NON-NLS-1$ + this.main.bind("compiler.version"), //$NON-NLS-1$ + this.main.bind("compiler.copyright") //$NON-NLS-1$ + } + ); + this.out.println(version); + this.out.flush(); + } + } + + /** + * Print the usage of wrong JDK + */ + public void logWrongJDK() { + if ((this.tagBits & Logger.XML) != 0) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.MESSAGE, this.main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$ + printTag(Logger.ERROR, parameters, true, true); + } + this.printlnErr(this.main.bind("configure.requiresJDK1.2orAbove")); //$NON-NLS-1$ + } + + private void logXmlExtraProblem(CategorizedProblem problem, int globalErrorCount, int localErrorCount) { + final int sourceStart = problem.getSourceStart(); + final int sourceEnd = problem.getSourceEnd(); + boolean isError = problem.isError(); + HashMap parameters = new HashMap<>(); + parameters.put(Logger.PROBLEM_SEVERITY, isError ? Logger.ERROR : (problem.isInfo() ? Logger.INFO : Logger.WARNING)); + parameters.put(Logger.PROBLEM_LINE, Integer.valueOf(problem.getSourceLineNumber())); + parameters.put(Logger.PROBLEM_SOURCE_START, Integer.valueOf(sourceStart)); + parameters.put(Logger.PROBLEM_SOURCE_END, Integer.valueOf(sourceEnd)); + printTag(Logger.EXTRA_PROBLEM_TAG, parameters, true, false); + parameters.put(Logger.VALUE, problem.getMessage()); + printTag(Logger.PROBLEM_MESSAGE, parameters, true, true); + extractContext(problem, null); + endTag(Logger.EXTRA_PROBLEM_TAG); + } + /** + * @param problem + * the given problem to log + * @param unitSource + * the given unit source + */ + private void logXmlProblem(CategorizedProblem problem, char[] unitSource) { + final int sourceStart = problem.getSourceStart(); + final int sourceEnd = problem.getSourceEnd(); + final int id = problem.getID(); + HashMap parameters = new HashMap<>(); + parameters.put(Logger.ID, getFieldName(id)); // ID as field name + parameters.put(Logger.PROBLEM_ID, Integer.valueOf(id)); // ID as numeric value + boolean isError = problem.isError(); + int severity = isError ? ProblemSeverities.Error : ProblemSeverities.Warning; + parameters.put(Logger.PROBLEM_SEVERITY, isError ? Logger.ERROR : (problem.isInfo() ? Logger.INFO : Logger.WARNING)); + parameters.put(Logger.PROBLEM_LINE, Integer.valueOf(problem.getSourceLineNumber())); + parameters.put(Logger.PROBLEM_SOURCE_START, Integer.valueOf(sourceStart)); + parameters.put(Logger.PROBLEM_SOURCE_END, Integer.valueOf(sourceEnd)); + String problemOptionKey = getProblemOptionKey(id); + if (problemOptionKey != null) { + parameters.put(Logger.PROBLEM_OPTION_KEY, problemOptionKey); + } + int categoryID = ProblemReporter.getProblemCategory(severity, id); + parameters.put(Logger.PROBLEM_CATEGORY_ID, Integer.valueOf(categoryID)); + printTag(Logger.PROBLEM_TAG, parameters, true, false); + parameters.put(Logger.VALUE, problem.getMessage()); + printTag(Logger.PROBLEM_MESSAGE, parameters, true, true); + extractContext(problem, unitSource); + String[] arguments = problem.getArguments(); + final int length = arguments.length; + if (length != 0) { + parameters = new HashMap<>(); + printTag(Logger.PROBLEM_ARGUMENTS, parameters, true, false); + for (int i = 0; i < length; i++) { + parameters = new HashMap<>(); + parameters.put(Logger.PROBLEM_ARGUMENT_VALUE, arguments[i]); + printTag(Logger.PROBLEM_ARGUMENT, parameters, true, true); + } + endTag(Logger.PROBLEM_ARGUMENTS); + } + endTag(Logger.PROBLEM_TAG); + } + /** + * @param problem + * the given problem to log + * @param unitSource + * the given unit source + */ + private void logXmlTask(CategorizedProblem problem, char[] unitSource) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.PROBLEM_LINE, Integer.valueOf(problem.getSourceLineNumber())); + parameters.put(Logger.PROBLEM_SOURCE_START, Integer.valueOf(problem.getSourceStart())); + parameters.put(Logger.PROBLEM_SOURCE_END, Integer.valueOf(problem.getSourceEnd())); + String problemOptionKey = getProblemOptionKey(problem.getID()); + if (problemOptionKey != null) { + parameters.put(Logger.PROBLEM_OPTION_KEY, problemOptionKey); + } + printTag(Logger.TASK, parameters, true, false); + parameters.put(Logger.VALUE, problem.getMessage()); + printTag(Logger.PROBLEM_MESSAGE, parameters, true, true); + extractContext(problem, unitSource); + endTag(Logger.TASK); + } + + private void printErr(String s) { + this.err.print(s); + if ((this.tagBits & Logger.XML) == 0 && this.log != null) { + this.log.print(s); + } + } + + private void printlnErr() { + this.err.println(); + if ((this.tagBits & Logger.XML) == 0 && this.log != null) { + this.log.println(); + } + } + + private void printlnErr(String s) { + this.err.println(s); + if ((this.tagBits & Logger.XML) == 0 && this.log != null) { + this.log.println(s); + } + } + + private void printlnOut(String s) { + this.out.println(s); + if ((this.tagBits & Logger.XML) == 0 && this.log != null) { + this.log.println(s); + } + } + + /** + * + */ + public void printNewLine() { + this.out.println(); + } + + private void printOut(char c) { + this.out.print(c); + } + + public void printStats() { + final boolean isTimed = (this.main.timing & TIMING_ENABLED) != 0; + if ((this.tagBits & Logger.XML) != 0) { + printTag(Logger.STATS, new HashMap<>(), true, false); + } + if (isTimed) { + CompilerStats compilerStats = this.main.batchCompiler.stats; + compilerStats.startTime = this.main.startTime; // also include batch initialization times + compilerStats.endTime = System.currentTimeMillis(); // also include batch output times + logTiming(compilerStats); + } + if (this.main.globalProblemsCount > 0) { + logProblemsSummary(this.main.globalProblemsCount, this.main.globalErrorsCount, this.main.globalWarningsCount, + this.main.globalInfoCount, this.main.globalTasksCount); + } + if (this.main.exportedClassFilesCounter != 0 + && (this.main.showProgress || isTimed || this.main.verbose)) { + logNumberOfClassFilesGenerated(this.main.exportedClassFilesCounter); + } + if ((this.tagBits & Logger.XML) != 0) { + endTag(Logger.STATS); + } + } + + private void printTag(String name, HashMap params, boolean insertNewLine, boolean closeTag) { + if (this.log != null) { + ((GenericXMLWriter) this.log).printTag(name, params, true, insertNewLine, closeTag); + } + if (params != null) params.clear(); + } + + public void setEmacs() { + this.tagBits |= Logger.EMACS; + } + public void setLog(String logFileName) { + final Date date = new Date(); + final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG, Locale.getDefault()); + try { + int index = logFileName.lastIndexOf('.'); + if (index != -1) { + if (logFileName.substring(index).toLowerCase().equals(".xml")) { //$NON-NLS-1$ + this.log = new GenericXMLWriter(new OutputStreamWriter(new FileOutputStream(logFileName, false), Util.UTF_8), Util.LINE_SEPARATOR, true); + this.tagBits |= Logger.XML; + // insert time stamp as comment + this.log.println("");//$NON-NLS-1$//$NON-NLS-2$ + this.log.println(Logger.XML_DTD_DECLARATION); + HashMap parameters = new HashMap<>(); + parameters.put(Logger.COMPILER_NAME, this.main.bind("compiler.name")); //$NON-NLS-1$ + parameters.put(Logger.COMPILER_VERSION, this.main.bind("compiler.version")); //$NON-NLS-1$ + parameters.put(Logger.COMPILER_COPYRIGHT, this.main.bind("compiler.copyright")); //$NON-NLS-1$ + printTag(Logger.COMPILER, parameters, true, false); + } else { + this.log = new PrintWriter(new FileOutputStream(logFileName, false)); + this.log.println("# " + dateFormat.format(date));//$NON-NLS-1$ + } + } else { + this.log = new PrintWriter(new FileOutputStream(logFileName, false)); + this.log.println("# " + dateFormat.format(date));//$NON-NLS-1$ + } + } catch (FileNotFoundException e) { + throw new IllegalArgumentException(this.main.bind("configure.cannotOpenLog", logFileName), e); //$NON-NLS-1$ + } catch (UnsupportedEncodingException e) { + throw new IllegalArgumentException(this.main.bind("configure.cannotOpenLogInvalidEncoding", logFileName), e); //$NON-NLS-1$ + } + } + private void startLoggingExtraProblems(int count) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.NUMBER_OF_PROBLEMS, Integer.valueOf(count)); + printTag(Logger.EXTRA_PROBLEMS, parameters, true, false); + } + + /** + * Used to start logging problems. + * Only use in xml mode. + */ + private void startLoggingProblems(int errors, int warnings, int infos) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.NUMBER_OF_PROBLEMS, Integer.valueOf(errors + warnings)); + parameters.put(Logger.NUMBER_OF_ERRORS, Integer.valueOf(errors)); + parameters.put(Logger.NUMBER_OF_WARNINGS, Integer.valueOf(warnings)); + parameters.put(Logger.NUMBER_OF_INFOS, Integer.valueOf(infos)); + printTag(Logger.PROBLEMS, parameters, true, false); + } + + public void startLoggingSource(CompilationResult compilationResult) { + if ((this.tagBits & Logger.XML) != 0) { + ICompilationUnit compilationUnit = compilationResult.compilationUnit; + HashMap parameters = new HashMap<>(); + if (compilationUnit != null) { + char[] fileName = compilationUnit.getFileName(); + File f = new File(new String(fileName)); + if (fileName != null) { + parameters.put(Logger.PATH, f.getAbsolutePath()); + } + char[][] packageName = compilationResult.packageName; + if (packageName != null) { + parameters.put( + Logger.PACKAGE, + new String(CharOperation.concatWith(packageName, File.separatorChar))); + } + CompilationUnit unit = (CompilationUnit) compilationUnit; + String destinationPath = unit.destinationPath; + if (destinationPath == null) { + destinationPath = this.main.destinationPath; + } + if (destinationPath != null && destinationPath != NONE) { + if (File.separatorChar == '/') { + parameters.put(Logger.OUTPUT, destinationPath); + } else { + parameters.put(Logger.OUTPUT, destinationPath.replace('/', File.separatorChar)); + } + } + } + printTag(Logger.SOURCE, parameters, true, false); + } + } + + public void startLoggingSources() { + if ((this.tagBits & Logger.XML) != 0) { + printTag(Logger.SOURCES, new HashMap<>(), true, false); + } + } + + public void startLoggingTasks(int tasks) { + if ((this.tagBits & Logger.XML) != 0) { + HashMap parameters = new HashMap<>(); + parameters.put(Logger.NUMBER_OF_TASKS, Integer.valueOf(tasks)); + printTag(Logger.TASKS, parameters, true, false); + } + } + } + + /** + * Resource bundle factory to share bundles for the same locale + */ + public static class ResourceBundleFactory { + private static HashMap Cache = new HashMap<>(); + public static synchronized ResourceBundle getBundle(Locale locale) { + ResourceBundle bundle = Cache.get(locale); + if (bundle == null) { + bundle = ResourceBundle.getBundle(Main.bundleName, locale); + Cache.put(locale, bundle); + } + return bundle; + } + } + + // used with -annotationpath to declare that annotations should be read from the classpath: + private static final String ANNOTATION_SOURCE_CLASSPATH = "CLASSPATH"; //$NON-NLS-1$ + + // javadoc analysis tuning + boolean enableJavadocOn; + + boolean warnJavadocOn; + boolean warnAllJavadocOn; + + public Compiler batchCompiler; + /* Bundle containing messages */ + public ResourceBundle bundle; + protected FileSystem.Classpath[] checkedClasspaths; + // For single module mode + protected IModule module; + private String moduleVersion; + // paths to external annotations: + protected List annotationPaths; + protected boolean annotationsFromClasspath; + + private List addonExports = Collections.EMPTY_LIST; + private List addonReads = Collections.EMPTY_LIST; + public Set rootModules = Collections.EMPTY_SET; + public Set limitedModules; + + public Locale compilerLocale; + public CompilerOptions compilerOptions; // read-only + public CompilationProgress progress; + public String destinationPath; + public String[] destinationPaths; + // destination path for compilation units that get no more specific + // one (through directory arguments or various classpath options); + // coding is: + // == null: unspecified, write class files close to their respective + // source files; + // == Main.NONE: absorbent element, do not output class files; + // else: use as the path of the directory into which class files must + // be written. + protected boolean enablePreview; + protected String releaseVersion; + private boolean didSpecifySource; + private boolean didSpecifyTarget; + public String[] encodings; + public int exportedClassFilesCounter; + public String[] filenames; + public String[] modNames; + public String[] classNames; + // overrides of destinationPath on a directory argument basis + public int globalErrorsCount; + public int globalProblemsCount; + public int globalTasksCount; + public int globalWarningsCount; + public int globalInfoCount; + + private File javaHomeCache; + + private boolean javaHomeChecked = false; + private boolean primaryNullAnnotationsSeen = false; + public long lineCount0; + + public String log; + + public Logger logger; + public int maxProblems; + public Map options; + protected long complianceLevel; + public char[][] ignoreOptionalProblemsFromFolders; + protected PrintWriter out; + public boolean proceed = true; + public boolean proceedOnError = false; + public boolean failOnWarning = false; + public boolean produceRefInfo = false; + public int currentRepetition, maxRepetition; + public boolean showProgress = false; + public long startTime; + public ArrayList pendingErrors; + public boolean systemExitWhenFinished = true; + + public static final int TIMING_DISABLED = 0; + public static final int TIMING_ENABLED = 1; + public static final int TIMING_DETAILED = 2; + + public int timing = TIMING_DISABLED; + public CompilerStats[] compilerStats; + public boolean verbose = false; + private String[] expandedCommandLine; + + private PrintWriter err; + + protected ArrayList extraProblems; + + public final static String bundleName = "org.eclipse.jdt.internal.compiler.batch.messages"; //$NON-NLS-1$ + // two uses: recognize 'none' in options; code the singleton none + // for the '-d none' option (wherever it may be found) + public static final int DEFAULT_SIZE_CLASSPATH = 4; + + public static final String NONE = "none"; //$NON-NLS-1$ + +/** + * @deprecated - use {@link BatchCompiler#compile(String, PrintWriter, PrintWriter, CompilationProgress)} instead + * e.g. BatchCompiler.compile(commandLine, new PrintWriter(System.out), new PrintWriter(System.err), null); + */ +public static boolean compile(String commandLine) { + return new Main(new PrintWriter(System.out), new PrintWriter(System.err), false /* systemExit */, null /* options */, null /* progress */).compile(tokenize(commandLine)); +} + +/** + * @deprecated - use {@link BatchCompiler#compile(String, PrintWriter, PrintWriter, CompilationProgress)} instead + * e.g. BatchCompiler.compile(commandLine, outWriter, errWriter, null); + */ +public static boolean compile(String commandLine, PrintWriter outWriter, PrintWriter errWriter) { + return new Main(outWriter, errWriter, false /* systemExit */, null /* options */, null /* progress */).compile(tokenize(commandLine)); +} + +/* + * Internal API for public API BatchCompiler#compile(String[], PrintWriter, PrintWriter, CompilationProgress) + */ +public static boolean compile(String[] commandLineArguments, PrintWriter outWriter, PrintWriter errWriter, CompilationProgress progress) { + return new Main(outWriter, errWriter, false /* systemExit */, null /* options */, progress).compile(commandLineArguments); +} +public static File[][] getLibrariesFiles(File[] files) { + FilenameFilter filter = new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + return Util.archiveFormat(name) > -1; + } + }; + final int filesLength = files.length; + File[][] result = new File[filesLength][]; + for (int i = 0; i < filesLength; i++) { + File currentFile = files[i]; + if (currentFile.exists() && currentFile.isDirectory()) { + result[i] = currentFile.listFiles(filter); + } + } + return result; +} + +public static void main(String[] argv) { + // GROOVY add + if (System.getProperty("groovy.antlr4") == null) System.setProperty("groovy.antlr4", "true"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + // GROOVY end + new Main(new PrintWriter(System.out), new PrintWriter(System.err), true/*systemExit*/, null/*options*/, null/*progress*/).compile(argv); +} + +public static String[] tokenize(String commandLine) { + + int count = 0; + String[] arguments = new String[10]; + StringTokenizer tokenizer = new StringTokenizer(commandLine, " \"", true); //$NON-NLS-1$ + String token = Util.EMPTY_STRING; + boolean insideQuotes = false; + boolean startNewToken = true; + + // take care to quotes on the command line + // 'xxx "aaa bbb";ccc yyy' ---> {"xxx", "aaa bbb;ccc", "yyy" } + // 'xxx "aaa bbb;ccc" yyy' ---> {"xxx", "aaa bbb;ccc", "yyy" } + // 'xxx "aaa bbb";"ccc" yyy' ---> {"xxx", "aaa bbb;ccc", "yyy" } + // 'xxx/"aaa bbb";"ccc" yyy' ---> {"xxx/aaa bbb;ccc", "yyy" } + while (tokenizer.hasMoreTokens()) { + token = tokenizer.nextToken(); + + if (token.equals(" ")) { //$NON-NLS-1$ + if (insideQuotes) { + arguments[count - 1] += token; + startNewToken = false; + } else { + startNewToken = true; + } + } else if (token.equals("\"")) { //$NON-NLS-1$ + if (!insideQuotes && startNewToken) { + if (count == arguments.length) + System.arraycopy(arguments, 0, (arguments = new String[count * 2]), 0, count); + arguments[count++] = Util.EMPTY_STRING; + } + insideQuotes = !insideQuotes; + startNewToken = false; + } else { + if (insideQuotes) { + arguments[count - 1] += token; + } else { + if (token.length() > 0 && !startNewToken) { + arguments[count - 1] += token; + } else { + if (count == arguments.length) + System.arraycopy(arguments, 0, (arguments = new String[count * 2]), 0, count); + String trimmedToken = token.trim(); + if (trimmedToken.length() != 0) { + arguments[count++] = trimmedToken; + } + } + } + startNewToken = false; + } + } + System.arraycopy(arguments, 0, arguments = new String[count], 0, count); + return arguments; +} + +/** + * @deprecated - use {@link #Main(PrintWriter, PrintWriter, boolean, Map, CompilationProgress)} instead + * e.g. Main(outWriter, errWriter, systemExitWhenFinished, null, null) + */ +public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished) { + this(outWriter, errWriter, systemExitWhenFinished, null /* options */, null /* progress */); +} + +/** + * @deprecated - use {@link #Main(PrintWriter, PrintWriter, boolean, Map, CompilationProgress)} instead + * e.g. Main(outWriter, errWriter, systemExitWhenFinished, customDefaultOptions, null) + */ +public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished, Map customDefaultOptions) { + this(outWriter, errWriter, systemExitWhenFinished, customDefaultOptions, null /* progress */); +} + +public Main(PrintWriter outWriter, PrintWriter errWriter, boolean systemExitWhenFinished, Map customDefaultOptions, CompilationProgress compilationProgress) { + this.initialize(outWriter, errWriter, systemExitWhenFinished, customDefaultOptions, compilationProgress); + this.relocalize(); +} + +public void addExtraProblems(CategorizedProblem problem) { + if (this.extraProblems == null) { + this.extraProblems = new ArrayList<>(); + } + this.extraProblems.add(problem); +} +protected void addNewEntry(ArrayList paths, String currentClasspathName, + ArrayList currentRuleSpecs, String customEncoding, + String destPath, boolean isSourceOnly, + boolean rejectDestinationPathOnJars) { + + int rulesSpecsSize = currentRuleSpecs.size(); + AccessRuleSet accessRuleSet = null; + if (rulesSpecsSize != 0) { + AccessRule[] accessRules = new AccessRule[currentRuleSpecs.size()]; + boolean rulesOK = true; + Iterator i = currentRuleSpecs.iterator(); + int j = 0; + while (i.hasNext()) { + String ruleSpec = i.next(); + char key = ruleSpec.charAt(0); + String pattern = ruleSpec.substring(1); + if (pattern.length() > 0) { + switch (key) { + case '+': + accessRules[j++] = new AccessRule(pattern + .toCharArray(), 0); + break; + case '~': + accessRules[j++] = new AccessRule(pattern + .toCharArray(), + IProblem.DiscouragedReference); + break; + case '-': + accessRules[j++] = new AccessRule(pattern + .toCharArray(), + IProblem.ForbiddenReference); + break; + case '?': + accessRules[j++] = new AccessRule(pattern + .toCharArray(), + IProblem.ForbiddenReference, true/*keep looking for accessible type*/); + break; + default: + rulesOK = false; + } + } else { + rulesOK = false; + } + } + if (rulesOK) { + accessRuleSet = new AccessRuleSet(accessRules, AccessRestriction.COMMAND_LINE, currentClasspathName); + } else { + if (currentClasspathName.length() != 0) { + // we go on anyway + addPendingErrors(this.bind("configure.incorrectClasspath", currentClasspathName));//$NON-NLS-1$ + } + return; + } + } + if (NONE.equals(destPath)) { + destPath = NONE; // keep == comparison valid + } + + if (rejectDestinationPathOnJars && destPath != null && + Util.archiveFormat(currentClasspathName) > -1) { + throw new IllegalArgumentException( + this.bind("configure.unexpectedDestinationPathEntryFile", //$NON-NLS-1$ + currentClasspathName)); + } + FileSystem.Classpath currentClasspath = FileSystem.getClasspath( + currentClasspathName, + customEncoding, + isSourceOnly, + accessRuleSet, + destPath, + this.options, + this.releaseVersion); + if (currentClasspath != null) { + paths.add(currentClasspath); + } else if (currentClasspathName.length() != 0) { + // we go on anyway + addPendingErrors(this.bind("configure.incorrectClasspath", currentClasspathName));//$NON-NLS-1$ + } +} +void addPendingErrors(String message) { + if (this.pendingErrors == null) { + this.pendingErrors = new ArrayList<>(); + } + this.pendingErrors.add(message); +} +/* + * Lookup the message with the given ID in this catalog + */ +public String bind(String id) { + return bind(id, (String[]) null); +} +/* + * Lookup the message with the given ID in this catalog and bind its + * substitution locations with the given string. + */ +public String bind(String id, String binding) { + return bind(id, new String[] { binding }); +} + +/* + * Lookup the message with the given ID in this catalog and bind its + * substitution locations with the given strings. + */ +public String bind(String id, String binding1, String binding2) { + return bind(id, new String[] { binding1, binding2 }); +} + +/* + * Lookup the message with the given ID in this catalog and bind its + * substitution locations with the given string values. + */ +public String bind(String id, String[] arguments) { + if (id == null) + return "No message available"; //$NON-NLS-1$ + String message = null; + try { + message = this.bundle.getString(id); + } catch (MissingResourceException e) { + // If we got an exception looking for the message, fail gracefully by just returning + // the id we were looking for. In most cases this is semi-informative so is not too bad. + return "Missing message: " + id + " in: " + Main.bundleName; //$NON-NLS-2$ //$NON-NLS-1$ + } + return MessageFormat.format(message, (Object[]) arguments); +} +/** + * Return true if and only if the running VM supports the given minimal version. + * + *

    This only checks the major version, since the minor version is always 0 (at least for the useful cases).

    + *

    The given minimalSupportedVersion is one of the constants:

    + *
      + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_1
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_2
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_3
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_4
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_6
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_7
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_8
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK9
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK10
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK11
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK12
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK13
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK14
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK15
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK16
    • + *
    • org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK17
    • + *
    + * @param minimalSupportedVersion the given minimal version + * @return true if and only if the running VM supports the given minimal version, false otherwise + */ +private boolean checkVMVersion(long minimalSupportedVersion) { + // the format of this property is supposed to be xx.x where x are digits. + String classFileVersion = System.getProperty("java.class.version"); //$NON-NLS-1$ + if (classFileVersion == null) { + // by default we don't support a class file version we cannot recognize + return false; + } + int index = classFileVersion.indexOf('.'); + if (index == -1) { + // by default we don't support a class file version we cannot recognize + return false; + } + int majorVersion; + try { + majorVersion = Integer.parseInt(classFileVersion.substring(0, index)); + } catch (NumberFormatException e) { + // by default we don't support a class file version we cannot recognize + return false; + } + return ClassFileConstants.getComplianceLevelForJavaVersion(majorVersion) >=minimalSupportedVersion; +} +/* + * Low-level API performing the actual compilation + */ +public boolean compile(String[] argv) { + // decode command line arguments + try { + configure(argv); + if (this.progress != null) + this.progress.begin(this.filenames == null ? 0 : this.filenames.length * this.maxRepetition); + if (this.proceed) { +// if (this.verbose) { +// System.out.println(new CompilerOptions(this.options)); +// } + if (this.showProgress) this.logger.compiling(); + for (this.currentRepetition = 0; this.currentRepetition < this.maxRepetition; this.currentRepetition++) { + this.globalProblemsCount = 0; + this.globalErrorsCount = 0; + this.globalWarningsCount = 0; + this.globalInfoCount = 0; + this.globalTasksCount = 0; + this.exportedClassFilesCounter = 0; + + if (this.maxRepetition > 1) { + this.logger.flush(); + this.logger.logRepetition(this.currentRepetition, this.maxRepetition); + } + // request compilation + performCompilation(); + } + if (this.compilerStats != null) { + this.logger.logAverage(); + } + if (this.showProgress) this.logger.printNewLine(); + } + if (this.systemExitWhenFinished) { + this.logger.flush(); + this.logger.close(); + if (this.failOnWarning && this.globalWarningsCount > 0) { + System.exit(-1); + } + System.exit(this.globalErrorsCount > 0 ? -1 : 0); + } + } catch (Exception e) { // internal compiler failure + this.logger.logException(e); + if (this.systemExitWhenFinished) { + this.logger.flush(); + this.logger.close(); + System.exit(-1); + } + return false; + } finally { + this.logger.flush(); + this.logger.close(); + if (this.progress != null) + this.progress.done(); + } + if (this.progress == null || !this.progress.isCanceled()) { + if (this.failOnWarning && (this.globalWarningsCount > 0)) + return false; + if (this.globalErrorsCount == 0) + return true; + } + + return false; +} + +/* +Decode the command line arguments + */ +public void configure(String[] argv) { + + if ((argv == null) || (argv.length == 0)) { + printUsage(); + return; + } + + final int INSIDE_CLASSPATH_start = 1; + final int INSIDE_DESTINATION_PATH = 3; + final int INSIDE_TARGET = 4; + final int INSIDE_LOG = 5; + final int INSIDE_REPETITION = 6; + final int INSIDE_SOURCE = 7; + final int INSIDE_DEFAULT_ENCODING = 8; + final int INSIDE_BOOTCLASSPATH_start = 9; + final int INSIDE_MAX_PROBLEMS = 11; + final int INSIDE_EXT_DIRS = 12; + final int INSIDE_SOURCE_PATH_start = 13; + final int INSIDE_ENDORSED_DIRS = 15; + final int INSIDE_SOURCE_DIRECTORY_DESTINATION_PATH = 16; + final int INSIDE_PROCESSOR_PATH_start = 17; + final int INSIDE_PROCESSOR_start = 18; + final int INSIDE_S_start = 19; + final int INSIDE_CLASS_NAMES = 20; + final int INSIDE_WARNINGS_PROPERTIES = 21; + final int INSIDE_ANNOTATIONPATH_start = 22; + final int INSIDE_MODULEPATH_start = 23; + final int INSIDE_MODULESOURCEPATH_start = 24; + final int INSIDE_ADD_EXPORTS = 25; + final int INSIDE_ADD_READS = 26; + final int INSIDE_SYSTEM = 27; + final int INSIDE_PROCESSOR_MODULE_PATH_start = 28; + final int INSIDE_ADD_MODULES = 29; + final int INSIDE_RELEASE = 30; + final int INSIDE_LIMIT_MODULES = 31; + final int INSIDE_MODULE_VERSION = 32; + // GROOVY add + final int INSIDE_CONFIG_SCRIPT = 100; + // GROOVY end + + final int DEFAULT = 0; + ArrayList bootclasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH); + String sourcepathClasspathArg = null; + String modulepathArg = null; + String moduleSourcepathArg = null; + ArrayList sourcepathClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH); + ArrayList classpaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH); + ArrayList extdirsClasspaths = null; + ArrayList endorsedDirClasspaths = null; + this.annotationPaths = null; + this.annotationsFromClasspath = false; + + int index = -1; + int filesCount = 0; + int classCount = 0; + int argCount = argv.length; + int mode = DEFAULT; + this.maxRepetition = 0; + boolean printUsageRequired = false; + String usageSection = null; + boolean printVersionRequired = false; + + boolean didSpecifyDeprecation = false; + boolean didSpecifyCompliance = false; + boolean didSpecifyDisabledAnnotationProcessing = false; + // GROOVY add + boolean encounteredGroovySourceFile = false; + // GROOVY end + + String customEncoding = null; + String customDestinationPath = null; + String currentSourceDirectory = null; + String currentArg = Util.EMPTY_STRING; + String moduleName = null; + + Set specifiedEncodings = null; + + // expand the command line if necessary + boolean needExpansion = false; + loop: for (int i = 0; i < argCount; i++) { + if (argv[i].startsWith("@")) { //$NON-NLS-1$ + needExpansion = true; + break loop; + } + } + + String[] newCommandLineArgs = null; + if (needExpansion) { + newCommandLineArgs = new String[argCount]; + index = 0; + for (int i = 0; i < argCount; i++) { + String[] newArgs = null; + String arg = argv[i].trim(); + if (arg.startsWith("@")) { //$NON-NLS-1$ + try { + LineNumberReader reader = new LineNumberReader(new StringReader(new String(Util.getFileCharContent(new File(arg.substring(1)), null)))); + StringBuilder buffer = new StringBuilder(); + String line; + while((line = reader.readLine()) != null) { + line = line.trim(); + if (!line.startsWith("#")) { //$NON-NLS-1$ + buffer.append(line).append(" "); //$NON-NLS-1$ + } + } + newArgs = tokenize(buffer.toString()); + } catch(IOException e) { + throw new IllegalArgumentException( + this.bind("configure.invalidexpansionargumentname", arg)); //$NON-NLS-1$ + } + } + if (newArgs != null) { + int newCommandLineArgsLength = newCommandLineArgs.length; + int newArgsLength = newArgs.length; + System.arraycopy(newCommandLineArgs, 0, (newCommandLineArgs = new String[newCommandLineArgsLength + newArgsLength - 1]), 0, index); + System.arraycopy(newArgs, 0, newCommandLineArgs, index, newArgsLength); + index += newArgsLength; + } else { + newCommandLineArgs[index++] = arg; + } + } + index = -1; + } else { + newCommandLineArgs = argv; + for (int i = 0; i < argCount; i++) { + newCommandLineArgs[i] = newCommandLineArgs[i].trim(); + } + } + argCount = newCommandLineArgs.length; + this.expandedCommandLine = newCommandLineArgs; + while (++index < argCount) { + + if (customEncoding != null) { + throw new IllegalArgumentException( + this.bind("configure.unexpectedCustomEncoding", currentArg, customEncoding)); //$NON-NLS-1$ + } + + currentArg = newCommandLineArgs[index]; + + switch(mode) { + case DEFAULT : + if (currentArg.startsWith("-nowarn")) { //$NON-NLS-1$ + switch (currentArg.length()) { + case 7: + disableAll(ProblemSeverities.Warning); + break; + case 8: + throw new IllegalArgumentException(this.bind( + "configure.invalidNowarnOption", currentArg)); //$NON-NLS-1$ + default: + int foldersStart = currentArg.indexOf('[') + 1; + int foldersEnd = currentArg.lastIndexOf(']'); + if (foldersStart <= 8 || foldersEnd == -1 || foldersStart > foldersEnd + || foldersEnd < currentArg.length() - 1) { + throw new IllegalArgumentException(this.bind( + "configure.invalidNowarnOption", currentArg)); //$NON-NLS-1$ + } + String folders = currentArg.substring(foldersStart, foldersEnd); + if (folders.length() > 0) { + char[][] currentFolders = decodeIgnoreOptionalProblemsFromFolders(folders); + if (this.ignoreOptionalProblemsFromFolders != null) { + int length = this.ignoreOptionalProblemsFromFolders.length + currentFolders.length; + char[][] tempFolders = new char[length][]; + System.arraycopy(this.ignoreOptionalProblemsFromFolders, 0, tempFolders, 0, this.ignoreOptionalProblemsFromFolders.length); + System.arraycopy(currentFolders, 0, tempFolders, this.ignoreOptionalProblemsFromFolders.length, currentFolders.length); + this.ignoreOptionalProblemsFromFolders = tempFolders; + } else { + this.ignoreOptionalProblemsFromFolders = currentFolders; + } + } else { + throw new IllegalArgumentException(this.bind( + "configure.invalidNowarnOption", currentArg)); //$NON-NLS-1$ + } + } + mode = DEFAULT; + continue; + } + if (currentArg.startsWith("[")) { //$NON-NLS-1$ + throw new IllegalArgumentException( + this.bind("configure.unexpectedBracket", //$NON-NLS-1$ + currentArg)); + } + if (currentArg.endsWith("]")) { //$NON-NLS-1$ + // look for encoding specification + int encodingStart = currentArg.indexOf('[') + 1; + if (encodingStart <= 1) { + throw new IllegalArgumentException( + this.bind("configure.unexpectedBracket", currentArg)); //$NON-NLS-1$ + } + int encodingEnd = currentArg.length() - 1; + if (encodingStart >= 1) { + if (encodingStart < encodingEnd) { + customEncoding = currentArg.substring(encodingStart, encodingEnd); + try { // ensure encoding is supported + new InputStreamReader(new ByteArrayInputStream(new byte[0]), customEncoding); + } catch (UnsupportedEncodingException e) { + throw new IllegalArgumentException( + this.bind("configure.unsupportedEncoding", customEncoding), e); //$NON-NLS-1$ + } + } + currentArg = currentArg.substring(0, encodingStart - 1); + } + } + + // GROOVY add + if (currentArg.endsWith(".groovy")) { //$NON-NLS-1$ + encounteredGroovySourceFile = true; + } + // GROOVY end + if (encounteredGroovySourceFile || currentArg.endsWith(SuffixConstants.SUFFIX_STRING_java)) { + if (moduleName == null) { + // If the module-info.java was supplied via command line, that will be the + // de facto module for the other source files supplied via command line. + // TODO: This needs revisit in case a source file specified in command line is + // part of a --module-source-path + IModule mod = extractModuleDesc(currentArg); + if (mod != null) { + moduleName = new String(mod.name()); + this.module = mod; + } + } + if (this.filenames == null) { + this.filenames = new String[argCount - index]; + this.encodings = new String[argCount - index]; + this.modNames = new String[argCount - index]; + this.destinationPaths = new String[argCount - index]; + } else if (filesCount == this.filenames.length) { + int length = this.filenames.length; + System.arraycopy( + this.filenames, + 0, + (this.filenames = new String[length + argCount - index]), + 0, + length); + System.arraycopy( + this.encodings, + 0, + (this.encodings = new String[length + argCount - index]), + 0, + length); + System.arraycopy( + this.destinationPaths, + 0, + (this.destinationPaths = new String[length + argCount - index]), + 0, + length); + System.arraycopy( + this.modNames, + 0, + (this.modNames = new String[length + argCount - index]), + 0, + length); + } + this.filenames[filesCount] = currentArg; + this.modNames[filesCount] = moduleName; + this.encodings[filesCount++] = customEncoding; + // destination path cannot be specified upon an individual file + customEncoding = null; + mode = DEFAULT; + continue; + } + // GROOVY add + if (currentArg.equals("-configScript")) { //$NON-NLS-1$ + mode = INSIDE_CONFIG_SCRIPT; + continue; + } + if (currentArg.equals("-indy")) { //$NON-NLS-1$ + this.options.merge(CompilerOptions.OPTIONG_GroovyFlags, String.valueOf(CompilerOptions.InvokeDynamic), (String one, String two) -> { + return String.valueOf(Integer.parseInt(one) | Integer.parseInt(two)); + }); + continue; + } + // GROOVY end + if (currentArg.equals("-log")) { //$NON-NLS-1$ + if (this.log != null) + throw new IllegalArgumentException( + this.bind("configure.duplicateLog", currentArg)); //$NON-NLS-1$ + mode = INSIDE_LOG; + continue; + } + if (currentArg.equals("-repeat")) { //$NON-NLS-1$ + if (this.maxRepetition > 0) + throw new IllegalArgumentException( + this.bind("configure.duplicateRepeat", currentArg)); //$NON-NLS-1$ + mode = INSIDE_REPETITION; + continue; + } + if (currentArg.equals("-maxProblems")) { //$NON-NLS-1$ + if (this.maxProblems > 0) + throw new IllegalArgumentException( + this.bind("configure.duplicateMaxProblems", currentArg)); //$NON-NLS-1$ + mode = INSIDE_MAX_PROBLEMS; + continue; + } + if (currentArg.equals("--release")) { //$NON-NLS-1$ + mode = INSIDE_RELEASE; + continue; + } + if (currentArg.equals("-source")) { //$NON-NLS-1$ + mode = INSIDE_SOURCE; + continue; + } + if (currentArg.equals("-encoding")) { //$NON-NLS-1$ + mode = INSIDE_DEFAULT_ENCODING; + continue; + } + if (currentArg.startsWith("-")) { //$NON-NLS-1$ + String version = optionStringToVersion(currentArg.substring(1)); + if (version != null) { + if (didSpecifyCompliance) { + throw new IllegalArgumentException( + this.bind("configure.duplicateCompliance", currentArg));//$NON-NLS-1$ + } + didSpecifyCompliance = true; + this.options.put(CompilerOptions.OPTION_Compliance, version); + mode = DEFAULT; + continue; + } + } + if (currentArg.equals("-15") || currentArg.equals("-15.0")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (didSpecifyCompliance) { + throw new IllegalArgumentException( + this.bind("configure.duplicateCompliance", currentArg)); //$NON-NLS-1$ + } + didSpecifyCompliance = true; + this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_15); + mode = DEFAULT; + continue; + } + if (currentArg.equals("-16") || currentArg.equals("-16.0")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (didSpecifyCompliance) { + throw new IllegalArgumentException( + this.bind("configure.duplicateCompliance", currentArg)); //$NON-NLS-1$ + } + didSpecifyCompliance = true; + this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16); + mode = DEFAULT; + continue; + } + if (currentArg.equals("-17") || currentArg.equals("-17.0")) { //$NON-NLS-1$ //$NON-NLS-2$ + if (didSpecifyCompliance) { + throw new IllegalArgumentException( + this.bind("configure.duplicateCompliance", currentArg)); //$NON-NLS-1$ + } + didSpecifyCompliance = true; + this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_16); + mode = DEFAULT; + continue; + } + if (currentArg.equals("-d")) { //$NON-NLS-1$ + if (this.destinationPath != null) { + StringBuilder errorMessage = new StringBuilder(); + errorMessage.append(currentArg); + if ((index + 1) < argCount) { + errorMessage.append(' '); + errorMessage.append(newCommandLineArgs[index + 1]); + } + throw new IllegalArgumentException( + this.bind("configure.duplicateOutputPath", errorMessage.toString())); //$NON-NLS-1$ + } + mode = INSIDE_DESTINATION_PATH; + continue; + } + if (currentArg.equals("-classpath") //$NON-NLS-1$ + || currentArg.equals("-cp")) { //$NON-NLS-1$ + mode = INSIDE_CLASSPATH_start; + continue; + } + if (currentArg.equals("-bootclasspath")) {//$NON-NLS-1$ + if (bootclasspaths.size() > 0) { + StringBuilder errorMessage = new StringBuilder(); + errorMessage.append(currentArg); + if ((index + 1) < argCount) { + errorMessage.append(' '); + errorMessage.append(newCommandLineArgs[index + 1]); + } + throw new IllegalArgumentException( + this.bind("configure.duplicateBootClasspath", errorMessage.toString())); //$NON-NLS-1$ + } + mode = INSIDE_BOOTCLASSPATH_start; + continue; + } + if (currentArg.equals("--enable-preview")) { //$NON-NLS-1$ + this.enablePreview = true; + mode = DEFAULT; + continue; + } + if (currentArg.equals("--system")) { //$NON-NLS-1$ + mode = INSIDE_SYSTEM; + continue; + } + if (currentArg.equals("--module-path") || currentArg.equals("-p")) { //$NON-NLS-1$ //$NON-NLS-2$ + mode = INSIDE_MODULEPATH_start; + continue; + } + if (currentArg.equals("--module-source-path")) { //$NON-NLS-1$ + if (sourcepathClasspathArg != null) { + throw new IllegalArgumentException(this.bind("configure.OneOfModuleOrSourcePath")); //$NON-NLS-1$ + } + mode = INSIDE_MODULESOURCEPATH_start; + continue; + } + if (currentArg.equals("--add-exports")) { //$NON-NLS-1$ + mode = INSIDE_ADD_EXPORTS; + continue; + } + if (currentArg.equals("--add-reads")) { //$NON-NLS-1$ + mode = INSIDE_ADD_READS; + continue; + } + if (currentArg.equals("--add-modules")) { //$NON-NLS-1$ + mode = INSIDE_ADD_MODULES; + continue; + } + if (currentArg.equals("--limit-modules")) { //$NON-NLS-1$ + mode = INSIDE_LIMIT_MODULES; + continue; + } + if (currentArg.equals("--module-version")) { //$NON-NLS-1$ + mode = INSIDE_MODULE_VERSION; + continue; + } + if (currentArg.equals("-sourcepath")) {//$NON-NLS-1$ + if (sourcepathClasspathArg != null) { + StringBuilder errorMessage = new StringBuilder(); + errorMessage.append(currentArg); + if ((index + 1) < argCount) { + errorMessage.append(' '); + errorMessage.append(newCommandLineArgs[index + 1]); + } + throw new IllegalArgumentException( + this.bind("configure.duplicateSourcepath", errorMessage.toString())); //$NON-NLS-1$ + } + if (moduleSourcepathArg != null) { + throw new IllegalArgumentException(this.bind("configure.OneOfModuleOrSourcePath")); //$NON-NLS-1$ + } + mode = INSIDE_SOURCE_PATH_start; + continue; + } + if (currentArg.equals("-extdirs")) {//$NON-NLS-1$ + if (extdirsClasspaths != null) { + StringBuilder errorMessage = new StringBuilder(); + errorMessage.append(currentArg); + if ((index + 1) < argCount) { + errorMessage.append(' '); + errorMessage.append(newCommandLineArgs[index + 1]); + } + throw new IllegalArgumentException( + this.bind("configure.duplicateExtDirs", errorMessage.toString())); //$NON-NLS-1$ + } + mode = INSIDE_EXT_DIRS; + continue; + } + if (currentArg.equals("-endorseddirs")) { //$NON-NLS-1$ + if (endorsedDirClasspaths != null) { + StringBuilder errorMessage = new StringBuilder(); + errorMessage.append(currentArg); + if ((index + 1) < argCount) { + errorMessage.append(' '); + errorMessage.append(newCommandLineArgs[index + 1]); + } + throw new IllegalArgumentException( + this.bind("configure.duplicateEndorsedDirs", errorMessage.toString())); //$NON-NLS-1$ + } + mode = INSIDE_ENDORSED_DIRS; + continue; + } + if (currentArg.equals("-progress")) { //$NON-NLS-1$ + mode = DEFAULT; + this.showProgress = true; + continue; + } + if (currentArg.startsWith("-proceedOnError")) { //$NON-NLS-1$ + mode = DEFAULT; + int length = currentArg.length(); + if (length > 15) { + if (currentArg.equals("-proceedOnError:Fatal")) { //$NON-NLS-1$ + this.options.put(CompilerOptions.OPTION_FatalOptionalError, CompilerOptions.ENABLED); + } else { + throw new IllegalArgumentException( + this.bind("configure.invalidWarningConfiguration", currentArg)); //$NON-NLS-1$ + } + } else { + this.options.put(CompilerOptions.OPTION_FatalOptionalError, CompilerOptions.DISABLED); + } + this.proceedOnError = true; + continue; + } + if (currentArg.equals("-failOnWarning")) { //$NON-NLS-1$ + mode = DEFAULT; + this.failOnWarning = true; + continue; + } + if (currentArg.equals("-time")) { //$NON-NLS-1$ + mode = DEFAULT; + this.timing = TIMING_ENABLED; + continue; + } + if (currentArg.equals("-time:detail")) { //$NON-NLS-1$ + mode = DEFAULT; + this.timing = TIMING_ENABLED|TIMING_DETAILED; + continue; + } + if (currentArg.equals("-version") //$NON-NLS-1$ + || currentArg.equals("-v")) { //$NON-NLS-1$ + this.logger.logVersion(true); + this.proceed = false; + return; + } + if (currentArg.equals("-showversion")) { //$NON-NLS-1$ + printVersionRequired = true; + mode = DEFAULT; + continue; + } + if ("-deprecation".equals(currentArg)) { //$NON-NLS-1$ + didSpecifyDeprecation = true; + this.options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + mode = DEFAULT; + continue; + } + if (currentArg.equals("-help") || currentArg.equals("-?")) { //$NON-NLS-1$ //$NON-NLS-2$ + printUsageRequired = true; + mode = DEFAULT; + continue; + } + if (currentArg.equals("-help:warn") || //$NON-NLS-1$ + currentArg.equals("-?:warn")) { //$NON-NLS-1$ + printUsageRequired = true; + usageSection = "misc.usage.warn"; //$NON-NLS-1$ + continue; + } + if (currentArg.equals("-noExit")) { //$NON-NLS-1$ + this.systemExitWhenFinished = false; + mode = DEFAULT; + continue; + } + if (currentArg.equals("-verbose")) { //$NON-NLS-1$ + this.verbose = true; + mode = DEFAULT; + continue; + } + if (currentArg.equals("-referenceInfo")) { //$NON-NLS-1$ + this.produceRefInfo = true; + mode = DEFAULT; + continue; + } + if (currentArg.equals("-inlineJSR")) { //$NON-NLS-1$ + mode = DEFAULT; + this.options.put( + CompilerOptions.OPTION_InlineJsr, + CompilerOptions.ENABLED); + continue; + } + if (currentArg.equals("-parameters")) { //$NON-NLS-1$ + mode = DEFAULT; + this.options.put( + CompilerOptions.OPTION_MethodParametersAttribute, + CompilerOptions.GENERATE); + continue; + } + if (currentArg.equals("-genericsignature")) { //$NON-NLS-1$ + mode = DEFAULT; + this.options.put( + CompilerOptions.OPTION_LambdaGenericSignature, + CompilerOptions.GENERATE); + continue; + } + if (currentArg.startsWith("-g")) { //$NON-NLS-1$ + mode = DEFAULT; + String debugOption = currentArg; + int length = currentArg.length(); + if (length == 2) { + this.options.put( + CompilerOptions.OPTION_LocalVariableAttribute, + CompilerOptions.GENERATE); + this.options.put( + CompilerOptions.OPTION_LineNumberAttribute, + CompilerOptions.GENERATE); + this.options.put( + CompilerOptions.OPTION_SourceFileAttribute, + CompilerOptions.GENERATE); + continue; + } + if (length > 3) { + this.options.put( + CompilerOptions.OPTION_LocalVariableAttribute, + CompilerOptions.DO_NOT_GENERATE); + this.options.put( + CompilerOptions.OPTION_LineNumberAttribute, + CompilerOptions.DO_NOT_GENERATE); + this.options.put( + CompilerOptions.OPTION_SourceFileAttribute, + CompilerOptions.DO_NOT_GENERATE); + if (length == 7 && debugOption.equals("-g:" + NONE)) //$NON-NLS-1$ + continue; + StringTokenizer tokenizer = + new StringTokenizer(debugOption.substring(3, debugOption.length()), ","); //$NON-NLS-1$ + while (tokenizer.hasMoreTokens()) { + String token = tokenizer.nextToken(); + if (token.equals("vars")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_LocalVariableAttribute, + CompilerOptions.GENERATE); + } else if (token.equals("lines")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_LineNumberAttribute, + CompilerOptions.GENERATE); + } else if (token.equals("source")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_SourceFileAttribute, + CompilerOptions.GENERATE); + } else { + throw new IllegalArgumentException( + this.bind("configure.invalidDebugOption", debugOption)); //$NON-NLS-1$ + } + } + continue; + } + throw new IllegalArgumentException( + this.bind("configure.invalidDebugOption", debugOption)); //$NON-NLS-1$ + } + if (currentArg.startsWith("-info")) { //$NON-NLS-1$ + mode = DEFAULT; + String infoOption = currentArg; + int length = currentArg.length(); + if (length == 10 && infoOption.equals("-info:" + NONE)) { //$NON-NLS-1$ + disableAll(ProblemSeverities.Info); + continue; + } + if (length <= 6) { + throw new IllegalArgumentException( + this.bind("configure.invalidInfoConfiguration", infoOption)); //$NON-NLS-1$ + } + int infoTokenStart; + boolean isEnabling; + switch (infoOption.charAt(6)) { + case '+' : + infoTokenStart = 7; + isEnabling = true; + break; + case '-' : + infoTokenStart = 7; + isEnabling = false; // specified warnings are disabled + break; + default: + disableAll(ProblemSeverities.Info); + infoTokenStart = 6; + isEnabling = true; + } + + StringTokenizer tokenizer = + new StringTokenizer(infoOption.substring(infoTokenStart, infoOption.length()), ","); //$NON-NLS-1$ + int tokenCounter = 0; + + while (tokenizer.hasMoreTokens()) { + String token = tokenizer.nextToken(); + tokenCounter++; + switch(token.charAt(0)) { + case '+' : + isEnabling = true; + token = token.substring(1); + break; + case '-' : + isEnabling = false; + token = token.substring(1); + } + handleInfoToken(token, isEnabling); + } + if (tokenCounter == 0) { + throw new IllegalArgumentException( + this.bind("configure.invalidInfoOption", currentArg)); //$NON-NLS-1$ + } + continue; + } + if (currentArg.startsWith("-warn")) { //$NON-NLS-1$ + mode = DEFAULT; + String warningOption = currentArg; + int length = currentArg.length(); + if (length == 10 && warningOption.equals("-warn:" + NONE)) { //$NON-NLS-1$ + disableAll(ProblemSeverities.Warning); + continue; + } + if (length <= 6) { + throw new IllegalArgumentException( + this.bind("configure.invalidWarningConfiguration", warningOption)); //$NON-NLS-1$ + } + int warnTokenStart; + boolean isEnabling; + switch (warningOption.charAt(6)) { + case '+' : + warnTokenStart = 7; + isEnabling = true; + break; + case '-' : + warnTokenStart = 7; + isEnabling = false; // specified warnings are disabled + break; + default: + disableAll(ProblemSeverities.Warning); + warnTokenStart = 6; + isEnabling = true; + } + + StringTokenizer tokenizer = + new StringTokenizer(warningOption.substring(warnTokenStart, warningOption.length()), ","); //$NON-NLS-1$ + int tokenCounter = 0; + + if (didSpecifyDeprecation) { // deprecation could have also been set through -deprecation option + this.options.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING); + } + + while (tokenizer.hasMoreTokens()) { + String token = tokenizer.nextToken(); + tokenCounter++; + switch(token.charAt(0)) { + case '+' : + isEnabling = true; + token = token.substring(1); + break; + case '-' : + isEnabling = false; + token = token.substring(1); + } + handleWarningToken(token, isEnabling); + } + if (tokenCounter == 0) { + throw new IllegalArgumentException( + this.bind("configure.invalidWarningOption", currentArg)); //$NON-NLS-1$ + } + continue; + } + if (currentArg.startsWith("-err")) { //$NON-NLS-1$ + mode = DEFAULT; + String errorOption = currentArg; + int length = currentArg.length(); + if (length <= 5) { + throw new IllegalArgumentException( + this.bind("configure.invalidErrorConfiguration", errorOption)); //$NON-NLS-1$ + } + int errorTokenStart; + boolean isEnabling; + switch (errorOption.charAt(5)) { + case '+' : + errorTokenStart = 6; + isEnabling = true; + break; + case '-' : + errorTokenStart = 6; + isEnabling = false; // specified errors are disabled + break; + default: + disableAll(ProblemSeverities.Error); + errorTokenStart = 5; + isEnabling = true; + } + + StringTokenizer tokenizer = + new StringTokenizer(errorOption.substring(errorTokenStart, errorOption.length()), ","); //$NON-NLS-1$ + int tokenCounter = 0; + + while (tokenizer.hasMoreTokens()) { + String token = tokenizer.nextToken(); + tokenCounter++; + switch(token.charAt(0)) { + case '+' : + isEnabling = true; + token = token.substring(1); + break; + case '-' : + isEnabling = false; + token = token.substring(1); + break; + } + handleErrorToken(token, isEnabling); + } + if (tokenCounter == 0) { + throw new IllegalArgumentException( + this.bind("configure.invalidErrorOption", currentArg)); //$NON-NLS-1$ + } + continue; + } + if (currentArg.equals("-target")) { //$NON-NLS-1$ + mode = INSIDE_TARGET; + continue; + } + if (currentArg.equals("-preserveAllLocals")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_PreserveUnusedLocal, + CompilerOptions.PRESERVE); + mode = DEFAULT; + continue; + } + if (currentArg.equals("-enableJavadoc")) {//$NON-NLS-1$ + mode = DEFAULT; + this.enableJavadocOn = true; + continue; + } + if (currentArg.equals("-Xemacs")) { //$NON-NLS-1$ + mode = DEFAULT; + this.logger.setEmacs(); + continue; + } + // annotation processing + if (currentArg.startsWith("-A")) { //$NON-NLS-1$ + mode = DEFAULT; + continue; + } + if (currentArg.equals("-processorpath")) { //$NON-NLS-1$ + mode = INSIDE_PROCESSOR_PATH_start; + continue; + } + if (currentArg.equals("-processor")) { //$NON-NLS-1$ + mode = INSIDE_PROCESSOR_start; + continue; + } + if (currentArg.equals("--processor-module-path")) { //$NON-NLS-1$ + mode = INSIDE_PROCESSOR_MODULE_PATH_start; + continue; + } + if (currentArg.equals("-proc:only")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_GenerateClassFiles, + CompilerOptions.DISABLED); + mode = DEFAULT; + continue; + } + if (currentArg.equals("-proc:none")) { //$NON-NLS-1$ + didSpecifyDisabledAnnotationProcessing = true; + this.options.put( + CompilerOptions.OPTION_Process_Annotations, + CompilerOptions.DISABLED); + mode = DEFAULT; + continue; + } + if (currentArg.equals("-s")) { //$NON-NLS-1$ + mode = INSIDE_S_start; + continue; + } + if (currentArg.equals("-XprintProcessorInfo") //$NON-NLS-1$ + || currentArg.equals("-XprintRounds")) { //$NON-NLS-1$ + mode = DEFAULT; + continue; + } + // tolerated javac options - quietly filtered out + if (currentArg.startsWith("-X")) { //$NON-NLS-1$ + mode = DEFAULT; + continue; + } + if (currentArg.startsWith("-J")) { //$NON-NLS-1$ + mode = DEFAULT; + continue; + } + if (currentArg.equals("-O")) { //$NON-NLS-1$ + mode = DEFAULT; + continue; + } + if (currentArg.equals("-classNames")) { //$NON-NLS-1$ + mode = INSIDE_CLASS_NAMES; + continue; + } + if (currentArg.equals("-properties")) { //$NON-NLS-1$ + mode = INSIDE_WARNINGS_PROPERTIES; + continue; + } + if (currentArg.equals("-missingNullDefault")) { //$NON-NLS-1$ + this.options.put(CompilerOptions.OPTION_ReportMissingNonNullByDefaultAnnotation, CompilerOptions.WARNING); + continue; + } + if (currentArg.equals("-annotationpath")) { //$NON-NLS-1$ + mode = INSIDE_ANNOTATIONPATH_start; + continue; + } + break; + case INSIDE_TARGET : + if (this.didSpecifyTarget) { + throw new IllegalArgumentException( + this.bind("configure.duplicateTarget", currentArg));//$NON-NLS-1$ + } + if (this.releaseVersion != null) { + throw new IllegalArgumentException( + this.bind("configure.unsupportedWithRelease", "-target"));//$NON-NLS-1$ //$NON-NLS-2$ + } + this.didSpecifyTarget = true; + if (currentArg.equals("1.1")) { //$NON-NLS-1$ + this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1); + } else if (currentArg.equals("1.2")) { //$NON-NLS-1$ + this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2); + } else if (currentArg.equals("jsr14")) { //$NON-NLS-1$ + this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_JSR14); + } else if (currentArg.equals("cldc1.1")) { //$NON-NLS-1$ + this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_CLDC1_1); + this.options.put(CompilerOptions.OPTION_InlineJsr, CompilerOptions.ENABLED); + } else { + String version = optionStringToVersion(currentArg); + if (version != null) { + this.options.put(CompilerOptions.OPTION_TargetPlatform, version); + } else { + throw new IllegalArgumentException(this.bind("configure.targetJDK", currentArg)); //$NON-NLS-1$ + } + } + mode = DEFAULT; + continue; + case INSIDE_LOG : + this.log = currentArg; + mode = DEFAULT; + continue; + case INSIDE_REPETITION : + try { + this.maxRepetition = Integer.parseInt(currentArg); + if (this.maxRepetition <= 0) { + throw new IllegalArgumentException(this.bind("configure.repetition", currentArg)); //$NON-NLS-1$ + } + } catch (NumberFormatException e) { + throw new IllegalArgumentException(this.bind("configure.repetition", currentArg), e); //$NON-NLS-1$ + } + mode = DEFAULT; + continue; + case INSIDE_MAX_PROBLEMS : + try { + this.maxProblems = Integer.parseInt(currentArg); + if (this.maxProblems <= 0) { + throw new IllegalArgumentException(this.bind("configure.maxProblems", currentArg)); //$NON-NLS-1$ + } + this.options.put(CompilerOptions.OPTION_MaxProblemPerUnit, currentArg); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(this.bind("configure.maxProblems", currentArg), e); //$NON-NLS-1$ + } + mode = DEFAULT; + continue; + case INSIDE_RELEASE: + // If release is < 9, the following are disallowed: + // bootclasspath, -Xbootclasspath, -Xbootclasspath/a:, -Xbootclasspath/p:, + // -endorseddirs, -Djava.endorsed.dirs, -extdirs, -Djava.ext.dirs + + // If release >= 9, the following are disallowed + // --system and --upgrade-module-path + + // -source and -target are disallowed for any --release + this.releaseVersion = currentArg; + long releaseToJDKLevel = CompilerOptions.releaseToJDKLevel(currentArg); + if (releaseToJDKLevel == 0) { + throw new IllegalArgumentException( + this.bind("configure.unsupportedReleaseVersion", currentArg)); //$NON-NLS-1$ + } + // Let's treat it as regular compliance mode + this.complianceLevel = releaseToJDKLevel; + String versionAsString = CompilerOptions.versionFromJdkLevel(releaseToJDKLevel); + this.options.put(CompilerOptions.OPTION_Compliance, versionAsString); + this.options.put(CompilerOptions.OPTION_Source, versionAsString); + this.options.put(CompilerOptions.OPTION_TargetPlatform, versionAsString); + mode = DEFAULT; + continue; + case INSIDE_SOURCE : + if (this.didSpecifySource) { + throw new IllegalArgumentException( + this.bind("configure.duplicateSource", currentArg));//$NON-NLS-1$ + } + if (this.releaseVersion != null) { + throw new IllegalArgumentException( + this.bind("configure.unsupportedWithRelease", "-source"));//$NON-NLS-1$ //$NON-NLS-2$ + } + this.didSpecifySource = true; + String version = optionStringToVersion(currentArg); + if (version != null) { + this.options.put(CompilerOptions.OPTION_Source, version); + } else { + throw new IllegalArgumentException(this.bind("configure.source", currentArg)); //$NON-NLS-1$ + } + mode = DEFAULT; + continue; + case INSIDE_DEFAULT_ENCODING : + if (specifiedEncodings != null) { + // check already defined encoding + if (!specifiedEncodings.contains(currentArg)) { + if (specifiedEncodings.size() > 1) { + this.logger.logWarning( + this.bind("configure.differentencodings", //$NON-NLS-1$ + currentArg, + getAllEncodings(specifiedEncodings))); + } else { + this.logger.logWarning( + this.bind("configure.differentencoding", //$NON-NLS-1$ + currentArg, + getAllEncodings(specifiedEncodings))); + } + } + } else { + specifiedEncodings = new HashSet<>(); + } + try { // ensure encoding is supported + new InputStreamReader(new ByteArrayInputStream(new byte[0]), currentArg); + } catch (UnsupportedEncodingException e) { + throw new IllegalArgumentException( + this.bind("configure.unsupportedEncoding", currentArg), e); //$NON-NLS-1$ + } + specifiedEncodings.add(currentArg); + this.options.put(CompilerOptions.OPTION_Encoding, currentArg); + mode = DEFAULT; + continue; + case INSIDE_DESTINATION_PATH : + setDestinationPath(currentArg.equals(NONE) ? NONE : currentArg); + mode = DEFAULT; + continue; + case INSIDE_SYSTEM: + mode = DEFAULT; + setJavaHome(currentArg); + continue; + case INSIDE_MODULEPATH_start: + mode = DEFAULT; + String[] modulepaths = new String[1]; + index += processPaths(newCommandLineArgs, index, currentArg, modulepaths); + modulepathArg = modulepaths[0]; + continue; + case INSIDE_MODULESOURCEPATH_start: + mode = DEFAULT; + String[] moduleSourcepaths = new String[1]; + index += processPaths(newCommandLineArgs, index, currentArg, moduleSourcepaths); + moduleSourcepathArg = moduleSourcepaths[0]; + continue; + case INSIDE_ADD_EXPORTS: + mode = DEFAULT; + // TODO: better to validate the option before processing it further? + if (this.addonExports == Collections.EMPTY_LIST) { + this.addonExports = new ArrayList<>(); + } + this.addonExports.add(currentArg); + continue; + case INSIDE_ADD_READS: + mode = DEFAULT; + if (this.addonReads == Collections.EMPTY_LIST) { + this.addonReads = new ArrayList<>(); + } + this.addonReads.add(currentArg); + continue; + case INSIDE_ADD_MODULES: + mode = DEFAULT; + if (this.rootModules == Collections.EMPTY_SET) { + this.rootModules = new HashSet<>(); + } + StringTokenizer tokenizer = new StringTokenizer(currentArg, ","); //$NON-NLS-1$ + while (tokenizer.hasMoreTokens()) { + this.rootModules.add(tokenizer.nextToken().trim()); + } + continue; + case INSIDE_LIMIT_MODULES: + mode = DEFAULT; + tokenizer = new StringTokenizer(currentArg, ","); //$NON-NLS-1$ + while (tokenizer.hasMoreTokens()) { + if (this.limitedModules == null) { + this.limitedModules = new HashSet<>(); + } + this.limitedModules.add(tokenizer.nextToken().trim()); + } + continue; + case INSIDE_MODULE_VERSION: + mode = DEFAULT; + this.moduleVersion = validateModuleVersion(currentArg); + continue; + case INSIDE_CLASSPATH_start: + mode = DEFAULT; + index += processPaths(newCommandLineArgs, index, currentArg, classpaths); + continue; + case INSIDE_BOOTCLASSPATH_start: + mode = DEFAULT; + index += processPaths(newCommandLineArgs, index, currentArg, bootclasspaths); + continue; + case INSIDE_SOURCE_PATH_start: + mode = DEFAULT; + String[] sourcePaths = new String[1]; + index += processPaths(newCommandLineArgs, index, currentArg, sourcePaths); + sourcepathClasspathArg = sourcePaths[0]; + continue; + case INSIDE_EXT_DIRS: + if (currentArg.indexOf("[-d") != -1) { //$NON-NLS-1$ + throw new IllegalArgumentException( + this.bind("configure.unexpectedDestinationPathEntry", //$NON-NLS-1$ + "-extdir")); //$NON-NLS-1$ + } + tokenizer = new StringTokenizer(currentArg, File.pathSeparator, false); + extdirsClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH); + while (tokenizer.hasMoreTokens()) + extdirsClasspaths.add(tokenizer.nextToken()); + mode = DEFAULT; + continue; + case INSIDE_ENDORSED_DIRS: + if (currentArg.indexOf("[-d") != -1) { //$NON-NLS-1$ + throw new IllegalArgumentException( + this.bind("configure.unexpectedDestinationPathEntry", //$NON-NLS-1$ + "-endorseddirs")); //$NON-NLS-1$ + } tokenizer = new StringTokenizer(currentArg, File.pathSeparator, false); + endorsedDirClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH); + while (tokenizer.hasMoreTokens()) + endorsedDirClasspaths.add(tokenizer.nextToken()); + mode = DEFAULT; + continue; + case INSIDE_SOURCE_DIRECTORY_DESTINATION_PATH: + if (currentArg.endsWith("]")) { //$NON-NLS-1$ + customDestinationPath = currentArg.substring(0, + currentArg.length() - 1); + } else { + throw new IllegalArgumentException( + this.bind("configure.incorrectDestinationPathEntry", //$NON-NLS-1$ + "[-d " + currentArg)); //$NON-NLS-1$ + } + break; + case INSIDE_PROCESSOR_PATH_start : + // nothing to do here. This is consumed again by the AnnotationProcessorManager + mode = DEFAULT; + continue; + case INSIDE_PROCESSOR_start : + // nothing to do here. This is consumed again by the AnnotationProcessorManager + mode = DEFAULT; + continue; + case INSIDE_PROCESSOR_MODULE_PATH_start : + mode = DEFAULT; + continue; + case INSIDE_S_start : + // nothing to do here. This is consumed again by the AnnotationProcessorManager + mode = DEFAULT; + continue; + case INSIDE_CLASS_NAMES : + tokenizer = new StringTokenizer(currentArg, ","); //$NON-NLS-1$ + if (this.classNames == null) { + this.classNames = new String[DEFAULT_SIZE_CLASSPATH]; + } + while (tokenizer.hasMoreTokens()) { + if (this.classNames.length == classCount) { + // resize + System.arraycopy( + this.classNames, + 0, + (this.classNames = new String[classCount * 2]), + 0, + classCount); + } + this.classNames[classCount++] = tokenizer.nextToken(); + } + mode = DEFAULT; + continue; + case INSIDE_WARNINGS_PROPERTIES : + initializeWarnings(currentArg); + mode = DEFAULT; + continue; + case INSIDE_ANNOTATIONPATH_start: + mode = DEFAULT; + if (currentArg.isEmpty() || currentArg.charAt(0) == '-') + throw new IllegalArgumentException(this.bind("configure.missingAnnotationPath", currentArg)); //$NON-NLS-1$ + if (ANNOTATION_SOURCE_CLASSPATH.equals(currentArg)) { + this.annotationsFromClasspath = true; + } else { + if (this.annotationPaths == null) + this.annotationPaths = new ArrayList(); + StringTokenizer tokens = new StringTokenizer(currentArg, File.pathSeparator); + while (tokens.hasMoreTokens()) + this.annotationPaths.add(tokens.nextToken()); + } + continue; + // GROOVY add + case INSIDE_CONFIG_SCRIPT: + if (currentArg.isEmpty() || currentArg.charAt(0) == '-') + throw new IllegalArgumentException(String.format("Missing argument to -configScript at ''%s''", currentArg)); //$NON-NLS-1$ + this.options.put(CompilerOptions.OPTIONG_GroovyCompilerConfigScript, currentArg); + mode = DEFAULT; + continue; + // GROOVY end + } + + // default is input directory, if no custom destination path exists + if (customDestinationPath == null) { + if (File.separatorChar != '/') { + currentArg = currentArg.replace('/', File.separatorChar); + } + if (currentArg.endsWith("[-d")) { //$NON-NLS-1$ + currentSourceDirectory = currentArg.substring(0, + currentArg.length() - 3); + mode = INSIDE_SOURCE_DIRECTORY_DESTINATION_PATH; + continue; + } + currentSourceDirectory = currentArg; + } + File dir = new File(currentSourceDirectory); + if (!dir.isDirectory()) { + throw new IllegalArgumentException( + this.bind("configure.unrecognizedOption", currentSourceDirectory)); //$NON-NLS-1$ + } + String[] result = FileFinder.find(dir, SuffixConstants.SUFFIX_STRING_java); + if (NONE.equals(customDestinationPath)) { + customDestinationPath = NONE; // ensure == comparison + } + if (this.filenames != null) { + // some source files were specified explicitly + int length = result.length; + System.arraycopy( + this.filenames, + 0, + (this.filenames = new String[length + filesCount]), + 0, + filesCount); + System.arraycopy( + this.encodings, + 0, + (this.encodings = new String[length + filesCount]), + 0, + filesCount); + System.arraycopy( + this.destinationPaths, + 0, + (this.destinationPaths = new String[length + filesCount]), + 0, + filesCount); + System.arraycopy( + this.modNames, + 0, + (this.modNames = new String[length + filesCount]), + 0, + filesCount); + System.arraycopy(result, 0, this.filenames, filesCount, length); + for (int i = 0; i < length; i++) { + this.encodings[filesCount + i] = customEncoding; + this.destinationPaths[filesCount + i] = customDestinationPath; + this.modNames[filesCount + i] = moduleName; + } + filesCount += length; + customEncoding = null; + customDestinationPath = null; + currentSourceDirectory = null; + } else { + this.filenames = result; + filesCount = this.filenames.length; + this.encodings = new String[filesCount]; + this.destinationPaths = new String[filesCount]; + this.modNames = new String[filesCount]; + for (int i = 0; i < filesCount; i++) { + this.encodings[i] = customEncoding; + this.destinationPaths[i] = customDestinationPath; + } + customEncoding = null; + customDestinationPath = null; + currentSourceDirectory = null; + } + mode = DEFAULT; + continue; + } + if (this.enablePreview) { + this.options.put( + CompilerOptions.OPTION_EnablePreviews, + CompilerOptions.ENABLED); + } + + // set DocCommentSupport, with appropriate side effects on defaults if + // javadoc is not enabled + if (this.enableJavadocOn) { + this.options.put( + CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + } else if (this.warnJavadocOn || this.warnAllJavadocOn) { + this.options.put( + CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + // override defaults: references that are embedded in javadoc are ignored + // from the perspective of parameters and thrown exceptions usage + this.options.put( + CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, + CompilerOptions.DISABLED); + this.options.put( + CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionIncludeDocCommentReference, + CompilerOptions.DISABLED); + } + // configure warnings for javadoc contents + if (this.warnJavadocOn) { + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTags, + CompilerOptions.ENABLED); + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef, + CompilerOptions.ENABLED); + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTagsNotVisibleRef, + CompilerOptions.ENABLED); + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, + CompilerOptions.PRIVATE); + } + + // GROOVY add + if (encounteredGroovySourceFile) { + this.options.put( + CompilerOptions.OPTIONG_BuildGroovyFiles, + CompilerOptions.ENABLED); + } else { + this.options.put( + CompilerOptions.OPTIONG_BuildGroovyFiles, + CompilerOptions.DISABLED); + } + // GROOVY end + + if (printUsageRequired || (filesCount == 0 && classCount == 0)) { + if (usageSection == null) { + printUsage(); // default + } else { + printUsage(usageSection); + } + this.proceed = false; + return; + } + + if (this.log != null) { + this.logger.setLog(this.log); + } else { + this.showProgress = false; + } + this.logger.logVersion(printVersionRequired); + + validateOptions(didSpecifyCompliance); + + // Enable annotation processing by default in batch mode when compliance is at least 1.6 + // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=185768 + if (!didSpecifyDisabledAnnotationProcessing + && CompilerOptions.versionToJdkLevel(this.options.get(CompilerOptions.OPTION_Compliance)) >= ClassFileConstants.JDK1_6) { + this.options.put(CompilerOptions.OPTION_Process_Annotations, CompilerOptions.ENABLED); + } + + this.logger.logCommandLineArguments(newCommandLineArgs); + this.logger.logOptions(this.options); + + if (this.maxRepetition == 0) { + this.maxRepetition = 1; + } + if (this.maxRepetition >= 3 && (this.timing & TIMING_ENABLED) != 0) { + this.compilerStats = new CompilerStats[this.maxRepetition]; + } + + if (filesCount != 0) { + System.arraycopy( + this.filenames, + 0, + (this.filenames = new String[filesCount]), + 0, + filesCount); + } + + if (classCount != 0) { + System.arraycopy( + this.classNames, + 0, + (this.classNames = new String[classCount]), + 0, + classCount); + } + + setPaths(bootclasspaths, + sourcepathClasspathArg, + sourcepathClasspaths, + classpaths, + modulepathArg, + moduleSourcepathArg, + extdirsClasspaths, + endorsedDirClasspaths, + customEncoding); + + if (specifiedEncodings != null && specifiedEncodings.size() > 1) { + this.logger.logWarning(this.bind("configure.multipleencodings", //$NON-NLS-1$ + this.options.get(CompilerOptions.OPTION_Encoding), + getAllEncodings(specifiedEncodings))); + } + if (this.pendingErrors != null) { + for (Iterator iterator = this.pendingErrors.iterator(); iterator.hasNext(); ) { + String message = iterator.next(); + this.logger.logPendingError(message); + } + this.pendingErrors = null; + } +} +/** Translates any supported standard version starting at 1.3 up-to latest into the corresponding constant from CompilerOptions */ +private String optionStringToVersion(String currentArg) { + switch (currentArg) { + case "1.3": return CompilerOptions.VERSION_1_3; //$NON-NLS-1$ + case "1.4": return CompilerOptions.VERSION_1_4; //$NON-NLS-1$ + case "1.5": //$NON-NLS-1$ + case "5": //$NON-NLS-1$ + case "5.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_1_5; + case "1.6": //$NON-NLS-1$ + case "6": //$NON-NLS-1$ + case "6.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_1_6; + case "1.7": //$NON-NLS-1$ + case "7": //$NON-NLS-1$ + case "7.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_1_7; + case "1.8": //$NON-NLS-1$ + case "8": //$NON-NLS-1$ + case "8.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_1_8; + case "1.9": //$NON-NLS-1$ + case "9": //$NON-NLS-1$ + case "9.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_9; + case "10": //$NON-NLS-1$ + case "10.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_10; + case "11": //$NON-NLS-1$ + case "11.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_11; + case "12": //$NON-NLS-1$ + case "12.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_12; + case "13": //$NON-NLS-1$ + case "13.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_13; + case "14": //$NON-NLS-1$ + case "14.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_14; + case "15": //$NON-NLS-1$ + case "15.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_15; + case "16": //$NON-NLS-1$ + case "16.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_16; + case "17": //$NON-NLS-1$ + case "17.0": //$NON-NLS-1$ + return CompilerOptions.VERSION_17; + default: + return null; + } +} +private String validateModuleVersion(String versionString) { + try { + Class versionClass = Class.forName("java.lang.module.ModuleDescriptor$Version"); //$NON-NLS-1$ + Method method = versionClass.getMethod("parse", String.class); //$NON-NLS-1$ + try { + method.invoke(null, versionString); + } catch (InvocationTargetException e) { + if (e.getCause() instanceof IllegalArgumentException) + throw (IllegalArgumentException) e.getCause(); + } + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException e) { + this.logger.logWarning(this.bind("configure.no.ModuleDescriptorVersionparse")); //$NON-NLS-1$ + } + return versionString; +} + +private Parser getNewParser() { + return new Parser(new ProblemReporter(getHandlingPolicy(), + new CompilerOptions(this.options), getProblemFactory()), false); +} +private IModule extractModuleDesc(String fileName) { + IModule mod = null; + // this.options may not be completely populated yet, and definitely not + // validated. Make sure the source level is set for the parser + Map opts = new HashMap(this.options); + opts.put(CompilerOptions.OPTION_Source, this.options.get(CompilerOptions.OPTION_Compliance)); + Parser parser = new Parser(new ProblemReporter(getHandlingPolicy(), + new CompilerOptions(opts), getProblemFactory()), false); + if (fileName.toLowerCase().endsWith(IModule.MODULE_INFO_JAVA)) { + + ICompilationUnit cu = new CompilationUnit(null, fileName, null); + CompilationResult compilationResult = new CompilationResult(cu, 0, 1, 10); + CompilationUnitDeclaration unit = parser.parse(cu, compilationResult); + if (unit.isModuleInfo() && unit.moduleDeclaration != null) { + mod = new BasicModule(unit.moduleDeclaration, null); + } + } else if (fileName.toLowerCase().endsWith(IModule.MODULE_INFO_CLASS)) { + try { + ClassFileReader reader = ClassFileReader.read(fileName); // Check the absolute path? + mod = reader.getModuleDeclaration(); + } catch (ClassFormatException | IOException e) { + e.printStackTrace(); + throw new IllegalArgumentException( + this.bind("configure.invalidModuleDescriptor", fileName)); //$NON-NLS-1$ + } + } + return mod; +} + +private static char[][] decodeIgnoreOptionalProblemsFromFolders(String folders) { + StringTokenizer tokenizer = new StringTokenizer(folders, File.pathSeparator); + char[][] result = new char[2 * tokenizer.countTokens()][]; + int count = 0; + while (tokenizer.hasMoreTokens()) { + String fileName = tokenizer.nextToken(); + // relative folder names are created relative to the current user dir + File file = new File(fileName); + if (file.exists()) { + String absolutePath = file.getAbsolutePath(); + result[count++] = absolutePath.toCharArray(); + // if the file exists, we should try to use its canonical path + try { + String canonicalPath = file.getCanonicalPath(); + if (!absolutePath.equals(canonicalPath)) { + result[count++] = canonicalPath.toCharArray(); + } + } catch (IOException e) { + // ignore + } + } else { + // if the file does not exist, use the name that was specified + result[count++] = fileName.toCharArray(); + } + } + if (count < result.length) { + char[][] shortened = new char[count][]; + System.arraycopy(result, 0, shortened, 0, count); + result = shortened; + } + return result; +} + +private static String getAllEncodings(Set encodings) { + int size = encodings.size(); + String[] allEncodings = new String[size]; + encodings.toArray(allEncodings); + Arrays.sort(allEncodings); + StringBuffer buffer = new StringBuffer(); + for (int i = 0; i < size; i++) { + if (i > 0) { + buffer.append(", "); //$NON-NLS-1$ + } + buffer.append(allEncodings[i]); + } + return String.valueOf(buffer); +} +@SuppressWarnings("rawtypes") +private void initializeWarnings(String propertiesFile) { + File file = new File(propertiesFile); + if (!file.exists()) { + throw new IllegalArgumentException(this.bind("configure.missingwarningspropertiesfile", propertiesFile)); //$NON-NLS-1$ + } + BufferedInputStream stream = null; + Properties properties = null; + try { + stream = new BufferedInputStream(new FileInputStream(propertiesFile)); + properties = new Properties(); + properties.load(stream); + } catch(IOException e) { + e.printStackTrace(); + throw new IllegalArgumentException(this.bind("configure.ioexceptionwarningspropertiesfile", propertiesFile)); //$NON-NLS-1$ + } finally { + if (stream != null) { + try { + stream.close(); + } catch(IOException e) { + // ignore + } + } + } + for(Iterator iterator = properties.entrySet().iterator(); iterator.hasNext(); ) { + Map.Entry entry = (Map.Entry) iterator.next(); + final String key = entry.getKey().toString(); + if (key.startsWith("org.eclipse.jdt.core.compiler.")) { //$NON-NLS-1$ + this.options.put(key, entry.getValue().toString()); + } + } + // when using a properties file mimic relevant defaults from JavaCorePreferenceInitializer: + if (!properties.containsKey(CompilerOptions.OPTION_LocalVariableAttribute)) { + this.options.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); + } + if (!properties.containsKey(CompilerOptions.OPTION_PreserveUnusedLocal)) { + this.options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); + } + if (!properties.containsKey(CompilerOptions.OPTION_DocCommentSupport)) { + this.options.put(CompilerOptions.OPTION_DocCommentSupport, CompilerOptions.ENABLED); + } + if (!properties.containsKey(CompilerOptions.OPTION_ReportForbiddenReference)) { + this.options.put(CompilerOptions.OPTION_ReportForbiddenReference, CompilerOptions.ERROR); + } +} +protected void enableAll(int severity) { + String newValue = null; + switch(severity) { + case ProblemSeverities.Error : + newValue = CompilerOptions.ERROR; + break; + case ProblemSeverities.Warning : + newValue = CompilerOptions.WARNING; + break; + } + Map.Entry[] entries = this.options.entrySet().toArray(new Map.Entry[this.options.size()]); + for (int i = 0, max = entries.length; i < max; i++) { + Map.Entry entry = entries[i]; + if (entry.getValue().equals(CompilerOptions.IGNORE)) { + this.options.put(entry.getKey(), newValue); + } + } + this.options.put(CompilerOptions.OPTION_TaskTags, Util.EMPTY_STRING); + if (newValue != null) { + this.options.remove(newValue); + } +} +protected void disableAll(int severity) { + String checkedValue = null; + switch(severity) { + case ProblemSeverities.Error : + checkedValue = CompilerOptions.ERROR; + break; + case ProblemSeverities.Warning : + checkedValue = CompilerOptions.WARNING; + break; + case ProblemSeverities.Info : + checkedValue = CompilerOptions.INFO; + break; + } + Set> entrySet = this.options.entrySet(); + for (Entry entry : entrySet) { + if (entry.getValue().equals(checkedValue)) { + this.options.put(entry.getKey(), CompilerOptions.IGNORE); + } + } + if (checkedValue != null) { + this.options.put(checkedValue, CompilerOptions.IGNORE); + } + if (severity == ProblemSeverities.Warning) { + disableAll(ProblemSeverities.Info); + } +} +public String extractDestinationPathFromSourceFile(CompilationResult result) { + ICompilationUnit compilationUnit = result.compilationUnit; + if (compilationUnit != null) { + char[] fileName = compilationUnit.getFileName(); + int lastIndex = CharOperation.lastIndexOf(java.io.File.separatorChar, fileName); + if (lastIndex != -1) { + final String outputPathName = new String(fileName, 0, lastIndex); + final File output = new File(outputPathName); + if (output.exists() && output.isDirectory()) { + return outputPathName; + } + } + } + return System.getProperty("user.dir"); //$NON-NLS-1$ +} +/* + * Answer the component to which will be handed back compilation results from the compiler + */ +public ICompilerRequestor getBatchRequestor() { + return new BatchCompilerRequestor(this); +} +/* + * Build the set of compilation source units + */ +public CompilationUnit[] getCompilationUnits() { + int fileCount = this.filenames.length; + CompilationUnit[] units = new CompilationUnit[fileCount]; + HashtableOfObject knownFileNames = new HashtableOfObject(fileCount); + + String defaultEncoding = this.options.get(CompilerOptions.OPTION_Encoding); + if (Util.EMPTY_STRING.equals(defaultEncoding)) + defaultEncoding = null; + + for (int round = 0; round < 2; round++) { + for (int i = 0; i < fileCount; i++) { + char[] charName = this.filenames[i].toCharArray(); + boolean isModuleInfo = CharOperation.endsWith(charName, TypeConstants.MODULE_INFO_FILE_NAME); + if (isModuleInfo == (round==0)) { // 1st round: modules, 2nd round others (to ensure populating pathToModCU well in time) + if (knownFileNames.get(charName) != null) + throw new IllegalArgumentException(this.bind("unit.more", this.filenames[i])); //$NON-NLS-1$ + knownFileNames.put(charName, charName); + File file = new File(this.filenames[i]); + if (!file.exists()) + throw new IllegalArgumentException(this.bind("unit.missing", this.filenames[i])); //$NON-NLS-1$ + String encoding = this.encodings[i]; + if (encoding == null) + encoding = defaultEncoding; + String fileName; + try { + fileName = file.getCanonicalPath(); + } catch (IOException e) { + // if we got exception during canonicalization, fall back to the name that was specified + fileName = this.filenames[i]; + } + Function annotationPathProvider = null; + if (this.annotationsFromClasspath) { + annotationPathProvider = (String qualifiedTypeName) -> { + for (Classpath classpathEntry : this.checkedClasspaths) { + if (classpathEntry.hasAnnotationFileFor(qualifiedTypeName.replace('.', '/'))) + return classpathEntry.getPath(); + } + return null; + }; + } else if (this.annotationPaths != null) { + annotationPathProvider = (String qualifiedTypeName) -> { + String eeaFileName = '/'+qualifiedTypeName.replace('.', '/')+ExternalAnnotationProvider.ANNOTATION_FILE_SUFFIX; + for (String annotationPath : this.annotationPaths) { + if (new File(annotationPath+eeaFileName).exists()) + return annotationPath; + } + return null; + }; + } + units[i] = new CompilationUnit(null, fileName, encoding, this.destinationPaths[i], + shouldIgnoreOptionalProblems(this.ignoreOptionalProblemsFromFolders, fileName.toCharArray()), + this.modNames[i], annotationPathProvider); + } + } + } + return units; +} + +/* + * Low-level API performing the actual compilation + */ +public IErrorHandlingPolicy getHandlingPolicy() { + + // passes the initial set of files to the batch oracle (to avoid finding more than once the same units when case insensitive match) + return new IErrorHandlingPolicy() { + @Override + public boolean proceedOnErrors() { + return Main.this.proceedOnError; // stop if there are some errors + } + @Override + public boolean stopOnFirstError() { + return false; + } + @Override + public boolean ignoreAllErrors() { + return false; + } + }; +} +private void setJavaHome(String javaHome) { + File release = new File(javaHome, "release"); //$NON-NLS-1$ + Properties prop = new Properties(); + try (FileReader reader = new FileReader(release)) { + prop.load(reader); + String ver = prop.getProperty("JAVA_VERSION"); //$NON-NLS-1$ + if (ver != null) + ver = ver.replace("\"", ""); //$NON-NLS-1$//$NON-NLS-2$ + this.javaHomeCache = new File(javaHome); + this.javaHomeChecked = true; + } catch (IOException e) { + throw new IllegalArgumentException(this.bind("configure.invalidSystem", javaHome)); //$NON-NLS-1$ + } +} +/* + * External API + */ +public File getJavaHome() { + if (!this.javaHomeChecked) { + this.javaHomeChecked = true; + this.javaHomeCache = Util.getJavaHome(); + } + return this.javaHomeCache; +} + +public FileSystem getLibraryAccess() { + FileSystem nameEnvironment = new FileSystem(this.checkedClasspaths, this.filenames, + this.annotationsFromClasspath && CompilerOptions.ENABLED.equals(this.options.get(CompilerOptions.OPTION_AnnotationBasedNullAnalysis)), + this.limitedModules); + nameEnvironment.module = this.module; + processAddonModuleOptions(nameEnvironment); + return nameEnvironment; +} + +/* + * Low-level API performing the actual compilation + */ +public IProblemFactory getProblemFactory() { + return new DefaultProblemFactory(this.compilerLocale); +} + +/* + * External API + */ +protected ArrayList handleBootclasspath(ArrayList bootclasspaths, String customEncoding) { + final int bootclasspathsSize; + ArrayList result = new ArrayList<>(DEFAULT_SIZE_CLASSPATH); + if ((bootclasspaths != null) + && ((bootclasspathsSize = bootclasspaths.size()) != 0)) { + result = new ArrayList<>(bootclasspathsSize); + for (String path : bootclasspaths) { + processPathEntries(DEFAULT_SIZE_CLASSPATH, result, path, customEncoding, false, true); + } + } else { + try { + Util.collectVMBootclasspath(result, this.javaHomeCache); + } catch(IllegalStateException e) { + throw new IllegalArgumentException(this.bind("configure.invalidSystem", this.javaHomeCache.toString())); //$NON-NLS-1$ + } + } + return result; +} +private void processAddonModuleOptions(FileSystem env) { + Map exports = new HashMap<>(); + for (String option : this.addonExports) { + AddExport addExport = ModuleFinder.extractAddonExport(option); + if (addExport != null) { + String modName = addExport.sourceModuleName; + IPackageExport export = addExport.export; + IPackageExport[] existing = exports.get(modName); + if (existing == null) { + existing = new IPackageExport[1]; + existing[0] = export; + exports.put(modName, existing); + } else { + for (IPackageExport iPackageExport : existing) { + if (CharOperation.equals(iPackageExport.name(), export.name())) { + throw new IllegalArgumentException(this.bind("configure.duplicateExport")); //$NON-NLS-1$ + } + } + IPackageExport[] updated = new IPackageExport[existing.length + 1]; + System.arraycopy(existing, 0, updated, 0, existing.length); + updated[existing.length] = export; + exports.put(modName, updated); + } + env.addModuleUpdate(modName, m -> m.addExports(export.name(), export.targets()), UpdateKind.PACKAGE); + } else { + throw new IllegalArgumentException(this.bind("configure.invalidModuleOption", "--add-exports " + option)); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + for (String option : this.addonReads) { + String[] result = ModuleFinder.extractAddonRead(option); + if (result != null && result.length == 2) { + env.addModuleUpdate(result[0], m -> m.addReads(result[1].toCharArray()), UpdateKind.MODULE); + } else { + throw new IllegalArgumentException(this.bind("configure.invalidModuleOption", "--add-reads " + option)); //$NON-NLS-1$ //$NON-NLS-2$ + } + } +} +protected ArrayList handleModulepath(String arg) { + ArrayList modulePaths = processModulePathEntries(arg); + ArrayList result = new ArrayList<>(); + if ((modulePaths != null && modulePaths.size() > 0)) { + for (String path : modulePaths) { + File file = new File(path); + if (file.isDirectory()) { + result.addAll( + ModuleFinder.findModules(file, null, getNewParser(), this.options, true, this.releaseVersion)); + } else { + Classpath modulePath = ModuleFinder.findModule(file, null, getNewParser(), this.options, true, this.releaseVersion); + if (modulePath != null) + result.add(modulePath); + } + } + } + // TODO: What about chained jars from MANIFEST.MF? Check with spec + return result; +} +protected ArrayList handleModuleSourcepath(String arg) { + ArrayList modulePaths = processModulePathEntries(arg); + ArrayList result = new ArrayList<>(); + if ((modulePaths != null) + && (modulePaths.size() != 0)) { + + if (this.destinationPath == null) { + addPendingErrors(this.bind("configure.missingDestinationPath"));//$NON-NLS-1$ + } + String[] paths = new String[modulePaths.size()]; + modulePaths.toArray(paths); + for (int i = 0; i < paths.length; i++) { + File dir = new File(paths[i]); + if (dir.isDirectory()) { + // 1. Create FileSystem.Classpath for each module + // 2. Iterator each module in case of directory for source files and add to this.fileNames + + List modules = ModuleFinder.findModules(dir, this.destinationPath, getNewParser(), this.options, false, this.releaseVersion); + for (Classpath classpath : modules) { + result.add(classpath); + Path modLocation = Paths.get(classpath.getPath()).toAbsolutePath(); + String destPath = classpath.getDestinationPath(); + IModule mod = classpath.getModule(); + String moduleName = mod == null ? null : new String(mod.name()); + for(int j = 0; j < this.filenames.length; j++) { + Path filePath; + try { + // Get canonical path just as the classpath location is stored with the same. + // To avoid mismatch of /USER_JAY and /USE~1 in windows systems. + filePath = new File(this.filenames[j]).getCanonicalFile().toPath(); + if (filePath.startsWith(modLocation)) { + this.modNames[j] = moduleName; + this.destinationPaths[j] = destPath; + } + } catch (IOException e) { + // Files doesn't exist and perhaps doesn't belong in a module, move on to other files + // Use empty module name to distinguish from missing module case + this.modNames[j] = ""; //$NON-NLS-1$ + } + } + } + } + } + for(int j = 0; j < this.filenames.length; j++) { + if (this.modNames[j] == null) { + throw new IllegalArgumentException(this.bind("configure.notOnModuleSourcePath", new String[] {this.filenames[j]})); //$NON-NLS-1$ + } + } + } + return result; +} +/* + * External API + */ +protected ArrayList handleClasspath(ArrayList classpaths, String customEncoding) { + ArrayList initial = new ArrayList<>(DEFAULT_SIZE_CLASSPATH); + if (classpaths != null && classpaths.size() > 0) { + for (String path : classpaths) { + processPathEntries(DEFAULT_SIZE_CLASSPATH, initial, path, customEncoding, false, true); + } + } else { + // no user classpath specified. + String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$ + if ((classProp == null) || (classProp.length() == 0)) { + addPendingErrors(this.bind("configure.noClasspath")); //$NON-NLS-1$ + final Classpath classpath = FileSystem.getClasspath(System.getProperty("user.dir"), customEncoding, null, this.options, this.releaseVersion);//$NON-NLS-1$ + if (classpath != null) { + initial.add(classpath); + } + } else { + StringTokenizer tokenizer = new StringTokenizer(classProp, File.pathSeparator); + String token; + while (tokenizer.hasMoreTokens()) { + token = tokenizer.nextToken(); + FileSystem.Classpath currentClasspath = FileSystem + .getClasspath(token, customEncoding, null, this.options, this.releaseVersion); + if (currentClasspath != null) { + initial.add(currentClasspath); + } else if (token.length() != 0) { + addPendingErrors(this.bind("configure.incorrectClasspath", token));//$NON-NLS-1$ + } + } + } + } + ArrayList result = new ArrayList<>(); + HashMap knownNames = new HashMap<>(); + FileSystem.ClasspathSectionProblemReporter problemReporter = + new FileSystem.ClasspathSectionProblemReporter() { + @Override + public void invalidClasspathSection(String jarFilePath) { + addPendingErrors(bind("configure.invalidClasspathSection", jarFilePath)); //$NON-NLS-1$ + } + @Override + public void multipleClasspathSections(String jarFilePath) { + addPendingErrors(bind("configure.multipleClasspathSections", jarFilePath)); //$NON-NLS-1$ + } + }; + while (! initial.isEmpty()) { + Classpath current = initial.remove(0); + String currentPath = current.getPath(); + if (knownNames.get(currentPath) == null) { + knownNames.put(currentPath, current); + result.add(current); + List linkedJars = current.fetchLinkedJars(problemReporter); + if (linkedJars != null) { + initial.addAll(0, linkedJars); + } + } + } + return result; +} +/* + * External API + */ +protected ArrayList handleEndorseddirs(ArrayList endorsedDirClasspaths) { + final File javaHome = getJavaHome(); + /* + * Feed endorsedDirClasspath according to: + * - -endorseddirs first if present; + * - else java.endorsed.dirs if defined; + * - else default extensions directory for the platform. (/lib/endorsed) + */ + if (endorsedDirClasspaths == null) { + endorsedDirClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH); + String endorsedDirsStr = System.getProperty("java.endorsed.dirs"); //$NON-NLS-1$ + if (endorsedDirsStr == null) { + if (javaHome != null) { + endorsedDirClasspaths.add(javaHome.getAbsolutePath() + "/lib/endorsed"); //$NON-NLS-1$ + } + } else { + StringTokenizer tokenizer = new StringTokenizer(endorsedDirsStr, File.pathSeparator); + while (tokenizer.hasMoreTokens()) { + endorsedDirClasspaths.add(tokenizer.nextToken()); + } + } + } + + /* + * Feed extdirsClasspath with the entries found into the directories listed by + * extdirsNames. + */ + if (endorsedDirClasspaths.size() != 0) { + ArrayList result = new ArrayList<>(); + File[] directoriesToCheck = new File[endorsedDirClasspaths.size()]; + for (int i = 0; i < directoriesToCheck.length; i++) + directoriesToCheck[i] = new File(endorsedDirClasspaths.get(i)); + File[][] endorsedDirsJars = getLibrariesFiles(directoriesToCheck); + if (endorsedDirsJars != null) { + for (int i = 0, max = endorsedDirsJars.length; i < max; i++) { + File[] current = endorsedDirsJars[i]; + if (current != null) { + for (int j = 0, max2 = current.length; j < max2; j++) { + FileSystem.Classpath classpath = + FileSystem.getClasspath( + current[j].getAbsolutePath(), + null, null, this.options, this.releaseVersion); + if (classpath != null) { + result.add(classpath); + } + } + } else if (directoriesToCheck[i].isFile()) { + addPendingErrors( + this.bind( + "configure.incorrectEndorsedDirsEntry", //$NON-NLS-1$ + directoriesToCheck[i].getAbsolutePath())); + } + } + } + return result; + } + return FileSystem.EMPTY_CLASSPATH; +} + +/* + * External API + * Handle extdirs processing + */ +protected ArrayList handleExtdirs(ArrayList extdirsClasspaths) { + final File javaHome = getJavaHome(); + + /* + * Feed extDirClasspath according to: + * - -extdirs first if present; + * - else java.ext.dirs if defined; + * - else default extensions directory for the platform. + */ + if (extdirsClasspaths == null) { + extdirsClasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH); + String extdirsStr = System.getProperty("java.ext.dirs"); //$NON-NLS-1$ + if (extdirsStr == null) { + extdirsClasspaths.add(javaHome.getAbsolutePath() + "/lib/ext"); //$NON-NLS-1$ + } else { + StringTokenizer tokenizer = new StringTokenizer(extdirsStr, File.pathSeparator); + while (tokenizer.hasMoreTokens()) + extdirsClasspaths.add(tokenizer.nextToken()); + } + } + + /* + * Feed extdirsClasspath with the entries found into the directories listed by + * extdirsNames. + */ + if (extdirsClasspaths.size() != 0) { + ArrayList result = new ArrayList<>(); + File[] directoriesToCheck = new File[extdirsClasspaths.size()]; + for (int i = 0; i < directoriesToCheck.length; i++) + directoriesToCheck[i] = new File(extdirsClasspaths.get(i)); + File[][] extdirsJars = getLibrariesFiles(directoriesToCheck); + if (extdirsJars != null) { + for (int i = 0, max = extdirsJars.length; i < max; i++) { + File[] current = extdirsJars[i]; + if (current != null) { + for (int j = 0, max2 = current.length; j < max2; j++) { + FileSystem.Classpath classpath = + FileSystem.getClasspath( + current[j].getAbsolutePath(), + null, null, this.options, this.releaseVersion); + if (classpath != null) { + result.add(classpath); + } + } + } else if (directoriesToCheck[i].isFile()) { + addPendingErrors(this.bind( + "configure.incorrectExtDirsEntry", //$NON-NLS-1$ + directoriesToCheck[i].getAbsolutePath())); + } + } + } + return result; + } + + return FileSystem.EMPTY_CLASSPATH; +} + +protected boolean isIgnored(IProblem problem) { + if (problem == null) { + return true; + } + if (problem.isError()) { + return false; + } + String key = problem.isInfo() ? CompilerOptions.INFO : CompilerOptions.WARNING; + if (CompilerOptions.IGNORE.equals(this.options.get(key))) { + return true; + } + if (this.ignoreOptionalProblemsFromFolders != null) { + char[] fileName = problem.getOriginatingFileName(); + if (fileName != null) { + return shouldIgnoreOptionalProblems(this.ignoreOptionalProblemsFromFolders, fileName); + } + } + return false; +} + +/* + * External API + * Handle a single warning token. +*/ +protected void handleInfoToken(String token, boolean isEnabling) { + handleErrorOrWarningToken(token, isEnabling, ProblemSeverities.Info); +} +protected void handleWarningToken(String token, boolean isEnabling) { + handleErrorOrWarningToken(token, isEnabling, ProblemSeverities.Warning); +} +protected void handleErrorToken(String token, boolean isEnabling) { + handleErrorOrWarningToken(token, isEnabling, ProblemSeverities.Error); +} +private void setSeverity(String compilerOptions, int severity, boolean isEnabling) { + if (isEnabling) { + switch(severity) { + case ProblemSeverities.Error : + this.options.put(compilerOptions, CompilerOptions.ERROR); + break; + case ProblemSeverities.Warning : + this.options.put(compilerOptions, CompilerOptions.WARNING); + break; + case ProblemSeverities.Info : + this.options.put(compilerOptions, CompilerOptions.INFO); + break; + default: + this.options.put(compilerOptions, CompilerOptions.IGNORE); + } + } else { + switch(severity) { + case ProblemSeverities.Error : + String currentValue = this.options.get(compilerOptions); + if (CompilerOptions.ERROR.equals(currentValue)) { + this.options.put(compilerOptions, CompilerOptions.IGNORE); + } + break; + case ProblemSeverities.Warning : + currentValue = this.options.get(compilerOptions); + if (CompilerOptions.WARNING.equals(currentValue)) { + this.options.put(compilerOptions, CompilerOptions.IGNORE); + } + break; + case ProblemSeverities.Info : + currentValue = this.options.get(compilerOptions); + if (CompilerOptions.INFO.equals(currentValue)) { + this.options.put(compilerOptions, CompilerOptions.IGNORE); + } + break; + default: + this.options.put(compilerOptions, CompilerOptions.IGNORE); + } + } +} +private void handleErrorOrWarningToken(String token, boolean isEnabling, int severity) { + if (token.length() == 0) return; + switch(token.charAt(0)) { + case 'a' : + if (token.equals("allDeprecation")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportDeprecation, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportTerminalDeprecation, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + this.options.put( + CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("allJavadoc")) { //$NON-NLS-1$ + this.warnAllJavadocOn = this.warnJavadocOn = isEnabling; + setSeverity(CompilerOptions.OPTION_ReportInvalidJavadoc, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportMissingJavadocTags, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportMissingJavadocComments, severity, isEnabling); + return; + } else if (token.equals("assertIdentifier")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportAssertIdentifier, severity, isEnabling); + return; + } else if (token.equals("allDeadCode")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportDeadCode, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("allOver-ann")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingOverrideAnnotation, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("all-static-method")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMethodCanBeStatic, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, severity, isEnabling); + return; + } else if (token.equals("all")) { //$NON-NLS-1$ + if (isEnabling) { + enableAll(severity); + } else { + disableAll(severity); + } + return; + } + break; + case 'b' : + if (token.equals("boxing")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportAutoboxing, severity, isEnabling); + return; + } + break; + case 'c' : + if (token.equals("constructorName")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMethodWithConstructorName, severity, isEnabling); + return; + } else if (token.equals("conditionAssign")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, severity, isEnabling); + return; + } else if (token.equals("compareIdentical")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportComparingIdentical, severity, isEnabling); + return; + } else if (token.equals("charConcat") /*|| token.equals("noImplicitStringConversion")/*backward compatible*/) {//$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNoImplicitStringConversion, severity, isEnabling); + return; + } + break; + case 'd' : + if (token.equals("deprecation")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportDeprecation, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, + CompilerOptions.DISABLED); + this.options.put( + CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, + CompilerOptions.DISABLED); + return; + } else if (token.equals("dep-ann")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingDeprecatedAnnotation, severity, isEnabling); + return; + } else if (token.equals("discouraged")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportDiscouragedReference, severity, isEnabling); + return; + } else if (token.equals("deadCode")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportDeadCode, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportDeadCodeInTrivialIfStatement, + CompilerOptions.DISABLED); + return; + } + break; + case 'e' : + if (token.equals("enumSwitch")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, severity, isEnabling); + return; + } else if (token.equals("enumSwitchPedantic")) { //$NON-NLS-1$ + if (isEnabling) { + switch (severity) { + case ProblemSeverities.Error: + setSeverity(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, severity, isEnabling); + break; + case ProblemSeverities.Warning: + if (CompilerOptions.IGNORE.equals(this.options.get(CompilerOptions.OPTION_ReportIncompleteEnumSwitch))) { + setSeverity(CompilerOptions.OPTION_ReportIncompleteEnumSwitch, severity, isEnabling); + } + break; + default: // no severity update + } + } + this.options.put(CompilerOptions.OPTION_ReportMissingEnumCaseDespiteDefault, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("emptyBlock")) {//$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUndocumentedEmptyBlock, severity, isEnabling); + return; + } else if (token.equals("enumIdentifier")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportEnumIdentifier, severity, isEnabling); + return; + } else if (token.equals("exports")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportAPILeak, severity, isEnabling); + return; + } + break; + case 'f' : + if (token.equals("fieldHiding")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportFieldHiding, severity, isEnabling); + return; + } else if (token.equals("finalBound")) {//$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportFinalParameterBound, severity, isEnabling); + return; + } else if (token.equals("finally")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportFinallyBlockNotCompletingNormally, severity, isEnabling); + return; + } else if (token.equals("forbidden")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportForbiddenReference, severity, isEnabling); + return; + } else if (token.equals("fallthrough")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportFallthroughCase, severity, isEnabling); + return; + } + break; + case 'h' : + if (token.equals("hiding")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportHiddenCatchBlock, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportLocalVariableHiding, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportFieldHiding, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportTypeParameterHiding, severity, isEnabling); + return; + } else if (token.equals("hashCode")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingHashCodeMethod, severity, isEnabling); + return; + } + break; + case 'i' : + if (token.equals("indirectStatic")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportIndirectStaticAccess, severity, isEnabling); + return; + } else if (token.equals("inheritNullAnnot")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_InheritNullAnnotations, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("intfNonInherited") || token.equals("interfaceNonInherited")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$ + setSeverity(CompilerOptions.OPTION_ReportIncompatibleNonInheritedInterfaceMethod, severity, isEnabling); + return; + } else if (token.equals("intfAnnotation")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportAnnotationSuperInterface, severity, isEnabling); + return; + } else if (token.equals("intfRedundant") /*|| token.equals("redundantSuperinterface")*/) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportRedundantSuperinterface, severity, isEnabling); + return; + } else if (token.equals("includeAssertNull")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_IncludeNullInfoFromAsserts, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("invalidJavadoc")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportInvalidJavadoc, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTags, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTagsNotVisibleRef, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + if (isEnabling) { + this.options.put( + CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, + CompilerOptions.PRIVATE); + } + return; + } else if (token.equals("invalidJavadocTag")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTags, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("invalidJavadocTagDep")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTagsDeprecatedRef, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("invalidJavadocTagNotVisible")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTagsNotVisibleRef, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.startsWith("invalidJavadocTagVisibility")) { //$NON-NLS-1$ + int start = token.indexOf('('); + int end = token.indexOf(')'); + String visibility = null; + if (isEnabling && start >= 0 && end >= 0 && start < end){ + visibility = token.substring(start+1, end).trim(); + } + if (visibility != null && visibility.equals(CompilerOptions.PUBLIC) + || visibility.equals(CompilerOptions.PRIVATE) + || visibility.equals(CompilerOptions.PROTECTED) + || visibility.equals(CompilerOptions.DEFAULT)) { + this.options.put( + CompilerOptions.OPTION_ReportInvalidJavadocTagsVisibility, + visibility); + return; + } else { + throw new IllegalArgumentException(this.bind("configure.invalidJavadocTagVisibility", token)); //$NON-NLS-1$ + } + } + break; + case 'j' : + if (token.equals("javadoc")) {//$NON-NLS-1$ + this.warnJavadocOn = isEnabling; + setSeverity(CompilerOptions.OPTION_ReportInvalidJavadoc, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportMissingJavadocTags, severity, isEnabling); + return; + } + break; + case 'l' : + if (token.equals("localHiding")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportLocalVariableHiding, severity, isEnabling); + return; + } + break; + case 'm' : + if (token.equals("maskedCatchBlock") || token.equals("maskedCatchBlocks")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$ + setSeverity(CompilerOptions.OPTION_ReportHiddenCatchBlock, severity, isEnabling); + return; + } else if (token.equals("missingJavadocTags")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingJavadocTags, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocTagsOverriding, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + if (isEnabling) { + this.options.put( + CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, + CompilerOptions.PRIVATE); + } + return; + } else if (token.equals("missingJavadocTagsOverriding")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocTagsOverriding, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("missingJavadocTagsMethod")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocTagsMethodTypeParameters, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.startsWith("missingJavadocTagsVisibility")) { //$NON-NLS-1$ + int start = token.indexOf('('); + int end = token.indexOf(')'); + String visibility = null; + if (isEnabling && start >= 0 && end >= 0 && start < end){ + visibility = token.substring(start+1, end).trim(); + } + if (visibility != null && visibility.equals(CompilerOptions.PUBLIC) + || visibility.equals(CompilerOptions.PRIVATE) + || visibility.equals(CompilerOptions.PROTECTED) + || visibility.equals(CompilerOptions.DEFAULT)) { + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocTagsVisibility, + visibility); + return; + } else { + throw new IllegalArgumentException(this.bind("configure.missingJavadocTagsVisibility", token)); //$NON-NLS-1$ + } + } else if (token.equals("missingJavadocComments")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingJavadocComments, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocCommentsOverriding, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + if (isEnabling) { + this.options.put( + CompilerOptions.OPTION_DocCommentSupport, + CompilerOptions.ENABLED); + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocCommentsVisibility, + CompilerOptions.PRIVATE); + } + return; + } else if (token.equals("missingJavadocCommentsOverriding")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingJavadocComments, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocCommentsOverriding, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.startsWith("missingJavadocCommentsVisibility")) { //$NON-NLS-1$ + int start = token.indexOf('('); + int end = token.indexOf(')'); + String visibility = null; + if (isEnabling && start >= 0 && end >= 0 && start < end){ + visibility = token.substring(start+1, end).trim(); + } + if (visibility != null && visibility.equals(CompilerOptions.PUBLIC) + || visibility.equals(CompilerOptions.PRIVATE) + || visibility.equals(CompilerOptions.PROTECTED) + || visibility.equals(CompilerOptions.DEFAULT)) { + this.options.put( + CompilerOptions.OPTION_ReportMissingJavadocCommentsVisibility, + visibility); + return; + } else { + throw new IllegalArgumentException(this.bind("configure.missingJavadocCommentsVisibility", token)); //$NON-NLS-1$ + } + } else if (token.equals("module")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnstableAutoModuleName, severity, isEnabling); + return; + } + break; + case 'n' : + if (token.equals("nls")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNonExternalizedStringLiteral, severity, isEnabling); + return; + } else if (token.equals("noEffectAssign")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNoEffectAssignment, severity, isEnabling); + return; + } else if (/*token.equals("charConcat") ||*/ token.equals("noImplicitStringConversion")/*backward compatible*/) {//$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNoImplicitStringConversion, severity, isEnabling); + return; + } else if (token.equals("null")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNullReference, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportPotentialNullReference, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportRedundantNullCheck, severity, isEnabling); + return; + } else if (token.equals("nullDereference")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNullReference, severity, isEnabling); + if (!isEnabling) { + setSeverity(CompilerOptions.OPTION_ReportPotentialNullReference, ProblemSeverities.Ignore, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportRedundantNullCheck, ProblemSeverities.Ignore, isEnabling); + } + return; + }else if (token.equals("nullAnnotConflict")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNullAnnotationInferenceConflict, severity, isEnabling); + return; + } else if (token.equals("nullAnnotRedundant")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportRedundantNullAnnotation, severity, isEnabling); + return; + } else if (token.startsWith("nullAnnot")) { //$NON-NLS-1$ + String annotationNames = Util.EMPTY_STRING; + int start = token.indexOf('('); + int end = token.indexOf(')'); + String nonNullAnnotName = null, nullableAnnotName = null, nonNullByDefaultAnnotName = null; + if (isEnabling && start >= 0 && end >= 0 && start < end){ + boolean isPrimarySet = !this.primaryNullAnnotationsSeen; + annotationNames = token.substring(start+1, end).trim(); + int separator1 = annotationNames.indexOf('|'); + if (separator1 == -1) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$ + nullableAnnotName = annotationNames.substring(0, separator1).trim(); + if (isPrimarySet && nullableAnnotName.length() == 0) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$ + int separator2 = annotationNames.indexOf('|', separator1 + 1); + if (separator2 == -1) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$ + nonNullAnnotName = annotationNames.substring(separator1 + 1, separator2).trim(); + if (isPrimarySet && nonNullAnnotName.length() == 0) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$ + nonNullByDefaultAnnotName = annotationNames.substring(separator2 + 1).trim(); + if (isPrimarySet && nonNullByDefaultAnnotName.length() == 0) throw new IllegalArgumentException(this.bind("configure.invalidNullAnnot", token)); //$NON-NLS-1$ + if (isPrimarySet) { + this.primaryNullAnnotationsSeen = true; + this.options.put(CompilerOptions.OPTION_NullableAnnotationName, nullableAnnotName); + this.options.put(CompilerOptions.OPTION_NonNullAnnotationName, nonNullAnnotName); + this.options.put(CompilerOptions.OPTION_NonNullByDefaultAnnotationName, nonNullByDefaultAnnotName); + } else { + if (nullableAnnotName.length() > 0) { + String nullableList = this.options.get(CompilerOptions.OPTION_NullableAnnotationSecondaryNames); + nullableList = nullableList.isEmpty() ? nullableAnnotName : nullableList + ',' + nullableAnnotName; + this.options.put(CompilerOptions.OPTION_NullableAnnotationSecondaryNames, nullableList); + } + if (nonNullAnnotName.length() > 0) { + String nonnullList = this.options.get(CompilerOptions.OPTION_NonNullAnnotationSecondaryNames); + nonnullList = nonnullList.isEmpty() ? nonNullAnnotName : nonnullList + ',' + nonNullAnnotName; + this.options.put(CompilerOptions.OPTION_NonNullAnnotationSecondaryNames, nonnullList); + } + if (nonNullByDefaultAnnotName.length() > 0) { + String nnbdList = this.options.get(CompilerOptions.OPTION_NonNullByDefaultAnnotationSecondaryNames); + nnbdList = nnbdList.isEmpty() ? nonNullByDefaultAnnotName : nnbdList + ',' + nonNullByDefaultAnnotName; + this.options.put(CompilerOptions.OPTION_NonNullByDefaultAnnotationSecondaryNames, nnbdList); + } + } + } + this.options.put( + CompilerOptions.OPTION_AnnotationBasedNullAnalysis, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + setSeverity(CompilerOptions.OPTION_ReportNullSpecViolation, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportNullAnnotationInferenceConflict, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportNullUncheckedConversion, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportRedundantNullAnnotation, severity, isEnabling); + return; + } else if (token.equals("nullUncheckedConversion")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNullUncheckedConversion, severity, isEnabling); + return; + } else if (token.equals("nonnullNotRepeated")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNonnullParameterAnnotationDropped, severity, isEnabling); + return; + } + + break; + case 'o' : + if (token.equals("over-sync") /*|| token.equals("syncOverride")*/) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingSynchronizedOnInheritedMethod, severity, isEnabling); + return; + } else if (token.equals("over-ann")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingOverrideAnnotation, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation, + CompilerOptions.DISABLED); + return; + } + break; + case 'p' : + if (token.equals("pkgDefaultMethod") || token.equals("packageDefaultMethod")/*backward compatible*/ ) { //$NON-NLS-1$ //$NON-NLS-2$ + setSeverity(CompilerOptions.OPTION_ReportOverridingPackageDefaultMethod, severity, isEnabling); + return; + } else if (token.equals("paramAssign")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportParameterAssignment, severity, isEnabling); + return; + } + break; + case 'r' : + if (token.equals("raw")) {//$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportRawTypeReference, severity, isEnabling); + return; + } else if (/*token.equals("intfRedundant") ||*/ token.equals("redundantSuperinterface")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportRedundantSuperinterface, severity, isEnabling); + return; + } else if (token.equals("resource")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnclosedCloseable, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportPotentiallyUnclosedCloseable, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportExplicitlyClosedAutoCloseable, severity, isEnabling); + return; + } else if (token.equals("removal")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportTerminalDeprecation, severity, isEnabling); + this.options.put( + CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, + CompilerOptions.DISABLED); + this.options.put( + CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, + CompilerOptions.DISABLED); + return; + } + break; + case 's' : + if (token.equals("specialParamHiding")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportSpecialParameterHidingField, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("syntheticAccess") || token.equals("synthetic-access")) { //$NON-NLS-1$ //$NON-NLS-2$ + setSeverity(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, severity, isEnabling); + return; + } else if (token.equals("staticReceiver")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, severity, isEnabling); + return; + } else if (/*token.equals("over-sync") ||*/ token.equals("syncOverride")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingSynchronizedOnInheritedMethod, severity, isEnabling); + return; + } else if (token.equals("semicolon")) {//$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportEmptyStatement, severity, isEnabling); + return; + } else if (token.equals("serial")) {//$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingSerialVersion, severity, isEnabling); + return; + } else if (token.equals("suppress")) {//$NON-NLS-1$ + switch(severity) { + case ProblemSeverities.Warning : + this.options.put( + CompilerOptions.OPTION_SuppressWarnings, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + this.options.put( + CompilerOptions.OPTION_SuppressOptionalErrors, + CompilerOptions.DISABLED); + break; + case ProblemSeverities.Error : + this.options.put( + CompilerOptions.OPTION_SuppressWarnings, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + this.options.put( + CompilerOptions.OPTION_SuppressOptionalErrors, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + } + return; + } else if (token.equals("static-access")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportIndirectStaticAccess, severity, isEnabling); + return; + } else if (token.equals("super")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportOverridingMethodWithoutSuperInvocation, severity, isEnabling); + return; + } else if (token.equals("static-method")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMethodCanBeStatic, severity, isEnabling); + return; + } else if (token.equals("switchDefault")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportMissingDefaultCase, severity, isEnabling); + return; + } else if (token.equals("syntacticAnalysis")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_SyntacticNullAnalysisForFields, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } + break; + case 't' : + if (token.startsWith("tasks")) { //$NON-NLS-1$ + String taskTags = Util.EMPTY_STRING; + int start = token.indexOf('('); + int end = token.indexOf(')'); + if (start >= 0 && end >= 0 && start < end){ + taskTags = token.substring(start+1, end).trim(); + taskTags = taskTags.replace('|',','); + } + if (taskTags.length() == 0){ + throw new IllegalArgumentException(this.bind("configure.invalidTaskTag", token)); //$NON-NLS-1$ + } + this.options.put( + CompilerOptions.OPTION_TaskTags, + isEnabling ? taskTags : Util.EMPTY_STRING); + + setSeverity(CompilerOptions.OPTION_ReportTasks, severity, isEnabling); + return; + } else if (token.equals("typeHiding")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportTypeParameterHiding, severity, isEnabling); + return; + } + break; + case 'u' : + if (token.equals("unusedLocal") || token.equals("unusedLocals")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$ + setSeverity(CompilerOptions.OPTION_ReportUnusedLocal, severity, isEnabling); + return; + } else if (token.equals("unusedArgument") || token.equals("unusedArguments")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$ + setSeverity(CompilerOptions.OPTION_ReportUnusedParameter, severity, isEnabling); + return; + } else if (token.equals("unusedExceptionParam")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnusedExceptionParameter, severity, isEnabling); + return; + } else if (token.equals("unusedImport") || token.equals("unusedImports")/*backward compatible*/) { //$NON-NLS-1$ //$NON-NLS-2$ + setSeverity(CompilerOptions.OPTION_ReportUnusedImport, severity, isEnabling); + return; + } else if (token.equals("unusedAllocation")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnusedObjectAllocation, severity, isEnabling); + return; + } else if (token.equals("unusedPrivate")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnusedPrivateMember, severity, isEnabling); + return; + } else if (token.equals("unusedLabel")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnusedLabel, severity, isEnabling); + return; + } else if (token.equals("uselessTypeCheck")) {//$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, severity, isEnabling); + return; + } else if (token.equals("unchecked") || token.equals("unsafe")) {//$NON-NLS-1$ //$NON-NLS-2$ + setSeverity(CompilerOptions.OPTION_ReportUncheckedTypeOperation, severity, isEnabling); + return; + } else if (token.equals("unlikelyCollectionMethodArgumentType")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnlikelyCollectionMethodArgumentType, severity, isEnabling); + return; + } else if (token.equals("unlikelyEqualsArgumentType")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnlikelyEqualsArgumentType, severity, isEnabling); + return; + } else if (token.equals("unnecessaryElse")) {//$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnnecessaryElse, severity, isEnabling); + return; + } else if (token.equals("unusedThrown")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnusedDeclaredThrownException, severity, isEnabling); + return; + } else if (token.equals("unusedThrownWhenOverriding")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionWhenOverriding, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("unusedThrownIncludeDocComment")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionIncludeDocCommentReference, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("unusedThrownExemptExceptionThrowable")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("unqualifiedField") || token.equals("unqualified-field-access")) { //$NON-NLS-1$ //$NON-NLS-2$ + setSeverity(CompilerOptions.OPTION_ReportUnqualifiedFieldAccess, severity, isEnabling); + return; + } else if (token.equals("unused")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportDeadCode, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportRedundantSuperinterface, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedDeclaredThrownException, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedExceptionParameter, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedImport, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedLabel, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedLocal, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedObjectAllocation, severity,isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedParameter, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedPrivateMember, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedTypeArgumentsForMethodInvocation, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedTypeParameter, severity,isEnabling); + return; + } else if (token.equals("unusedParam")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnusedParameter, severity, isEnabling); + return; + } else if (token.equals("unusedTypeParameter")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnusedTypeParameter, severity, isEnabling); + return; + } else if (token.equals("unusedParamIncludeDoc")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportUnusedParameterIncludeDocCommentReference, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("unusedParamOverriding")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportUnusedParameterWhenOverridingConcrete, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("unusedParamImplementing")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportUnusedParameterWhenImplementingAbstract, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } else if (token.equals("unusedTypeArgs")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnusedTypeArgumentsForMethodInvocation, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, severity, isEnabling); + return; + } else if (token.equals("unavoidableGenericProblems")) { //$NON-NLS-1$ + this.options.put( + CompilerOptions.OPTION_ReportUnavoidableGenericTypeProblems, + isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED); + return; + } + break; + case 'v' : + if (token.equals("varargsCast")) { //$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportVarargsArgumentNeedCast, severity, isEnabling); + return; + } + break; + case 'w' : + if (token.equals("warningToken")) {//$NON-NLS-1$ + setSeverity(CompilerOptions.OPTION_ReportUnhandledWarningToken, severity, isEnabling); + setSeverity(CompilerOptions.OPTION_ReportUnusedWarningToken, severity, isEnabling); + return; + } + break; + } + String message = null; + switch(severity) { + case ProblemSeverities.Info: + message = this.bind("configure.invalidInfo", token); //$NON-NLS-1$ + break; + case ProblemSeverities.Warning : + message = this.bind("configure.invalidWarning", token); //$NON-NLS-1$ + break; + case ProblemSeverities.Error : + message = this.bind("configure.invalidError", token); //$NON-NLS-1$ + } + addPendingErrors(message); +} +/** + * @deprecated - use {@link #initialize(PrintWriter, PrintWriter, boolean, Map, CompilationProgress)} instead + * e.g. initialize(outWriter, errWriter, systemExit, null, null) + */ +protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit) { + this.initialize(outWriter, errWriter, systemExit, null /* options */, null /* progress */); +} +/** + * @deprecated - use {@link #initialize(PrintWriter, PrintWriter, boolean, Map, CompilationProgress)} instead + * e.g. initialize(outWriter, errWriter, systemExit, customDefaultOptions, null) + */ +protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map customDefaultOptions) { + this.initialize(outWriter, errWriter, systemExit, customDefaultOptions, null /* progress */); +} +protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map customDefaultOptions, CompilationProgress compilationProgress) { + this.logger = new Logger(this, outWriter, errWriter); + this.proceed = true; + this.out = outWriter; + this.err = errWriter; + this.systemExitWhenFinished = systemExit; + this.options = new CompilerOptions().getMap(); + this.ignoreOptionalProblemsFromFolders = null; + + this.progress = compilationProgress; + if (customDefaultOptions != null) { + this.didSpecifySource = customDefaultOptions.get(CompilerOptions.OPTION_Source) != null; + this.didSpecifyTarget = customDefaultOptions.get(CompilerOptions.OPTION_TargetPlatform) != null; + for (Iterator> iter = customDefaultOptions.entrySet().iterator(); iter.hasNext();) { + Map.Entry entry = iter.next(); + this.options.put(entry.getKey(), entry.getValue()); + } + } else { + this.didSpecifySource = false; + this.didSpecifyTarget = false; + } + this.classNames = null; +} +protected void initializeAnnotationProcessorManager() { + String className = "org.eclipse.jdt.internal.compiler.apt.dispatch.BatchAnnotationProcessorManager"; //$NON-NLS-1$ + try { + Class c = Class.forName(className); + AbstractAnnotationProcessorManager annotationManager = (AbstractAnnotationProcessorManager) c.getDeclaredConstructor().newInstance(); + annotationManager.configure(this, this.expandedCommandLine); + annotationManager.setErr(this.err); + annotationManager.setOut(this.out); + this.batchCompiler.annotationProcessorManager = annotationManager; + } catch (ClassNotFoundException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { + this.logger.logUnavaibleAPT(className); + throw new org.eclipse.jdt.internal.compiler.problem.AbortCompilation(); + } catch (IllegalAccessException e) { + // should not happen + throw new org.eclipse.jdt.internal.compiler.problem.AbortCompilation(); + } catch(UnsupportedClassVersionError e) { + // report a warning + this.logger.logIncorrectVMVersionForAnnotationProcessing(); + } +} +private static boolean isParentOf(char[] folderName, char[] fileName) { + if (folderName.length >= fileName.length) { + return false; + } + if (fileName[folderName.length] != '\\' && fileName[folderName.length] != '/') { + return false; + } + for (int i = folderName.length - 1; i >= 0; i--) { + if (folderName[i] != fileName[i]) { + return false; + } + } + return true; +} +// Dump classfiles onto disk for all compilation units that where successful +// and do not carry a -d none spec, either directly or inherited from Main. +public void outputClassFiles(CompilationResult unitResult) { + if (!((unitResult == null) || (unitResult.hasErrors() && !this.proceedOnError))) { + ClassFile[] classFiles = unitResult.getClassFiles(); + String currentDestinationPath = null; + boolean generateClasspathStructure = false; + CompilationUnit compilationUnit = + (CompilationUnit) unitResult.compilationUnit; + if (compilationUnit.destinationPath == null) { + if (this.destinationPath == null) { + currentDestinationPath = + extractDestinationPathFromSourceFile(unitResult); + } else if (this.destinationPath != NONE) { + currentDestinationPath = this.destinationPath; + generateClasspathStructure = true; + } // else leave currentDestinationPath null + } else if (compilationUnit.destinationPath != NONE) { + currentDestinationPath = compilationUnit.destinationPath; + generateClasspathStructure = true; + } // else leave currentDestinationPath null + if (currentDestinationPath != null) { + for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) { + // retrieve the key and the corresponding classfile + ClassFile classFile = classFiles[i]; + char[] filename = classFile.fileName(); + int length = filename.length; + char[] relativeName = new char[length + 6]; + System.arraycopy(filename, 0, relativeName, 0, length); + System.arraycopy(SuffixConstants.SUFFIX_class, 0, relativeName, length, 6); + CharOperation.replace(relativeName, '/', File.separatorChar); + String relativeStringName = new String(relativeName); + try { + if (this.compilerOptions.verbose) + this.out.println( + Messages.bind( + Messages.compilation_write, + new String[] { + String.valueOf(this.exportedClassFilesCounter+1), + relativeStringName + })); + Util.writeToDisk( + generateClasspathStructure, + currentDestinationPath, + relativeStringName, + classFile); + this.logger.logClassFile( + generateClasspathStructure, + currentDestinationPath, + relativeStringName); + this.exportedClassFilesCounter++; + } catch (IOException e) { + this.logger.logNoClassFileCreated(currentDestinationPath, relativeStringName, e); + } + } + this.batchCompiler.lookupEnvironment.releaseClassFiles(classFiles); + } + } +} +/* + * Low-level API performing the actual compilation + */ +public void performCompilation() { + this.startTime = System.currentTimeMillis(); + + FileSystem environment = getLibraryAccess(); + try { + this.compilerOptions = new CompilerOptions(this.options); + this.compilerOptions.performMethodsFullRecovery = false; + this.compilerOptions.performStatementsRecovery = false; + this.batchCompiler = + new Compiler( + environment, + getHandlingPolicy(), + this.compilerOptions, + getBatchRequestor(), + getProblemFactory(), + this.out, + this.progress); + this.batchCompiler.remainingIterations = this.maxRepetition-this.currentRepetition/*remaining iterations including this one*/; + // temporary code to allow the compiler to revert to a single thread + String setting = System.getProperty("jdt.compiler.useSingleThread"); //$NON-NLS-1$ + this.batchCompiler.useSingleThread = setting != null && setting.equals("true"); //$NON-NLS-1$ + + if (this.compilerOptions.complianceLevel >= ClassFileConstants.JDK1_6 + && this.compilerOptions.processAnnotations) { + if (checkVMVersion(ClassFileConstants.JDK1_6)) { + initializeAnnotationProcessorManager(); + if (this.classNames != null) { + this.batchCompiler.setBinaryTypes(processClassNames(this.batchCompiler.lookupEnvironment)); + } + } else { + // report a warning + this.logger.logIncorrectVMVersionForAnnotationProcessing(); + } + if (checkVMVersion(ClassFileConstants.JDK9)) { + initRootModules(this.batchCompiler.lookupEnvironment, environment); + } + } + + // set the non-externally configurable options. + this.compilerOptions.verbose = this.verbose; + this.compilerOptions.produceReferenceInfo = this.produceRefInfo; + try { + this.logger.startLoggingSources(); + this.batchCompiler.compile(getCompilationUnits()); + } finally { + this.logger.endLoggingSources(); + } + + if (this.extraProblems != null) { + loggingExtraProblems(); + this.extraProblems = null; + } + if (this.compilerStats != null) { + this.compilerStats[this.currentRepetition] = this.batchCompiler.stats; + } + this.logger.printStats(); + } + finally { + // cleanup + environment.cleanup(); + } +} +protected void loggingExtraProblems() { + this.logger.loggingExtraProblems(this); +} +public void printUsage() { + printUsage("misc.usage"); //$NON-NLS-1$ +} +private void printUsage(String sectionID) { + this.logger.logUsage( + this.bind( + sectionID, + new String[] { + System.getProperty("path.separator"), //$NON-NLS-1$ + this.bind("compiler.name"), //$NON-NLS-1$ + this.bind("compiler.version"), //$NON-NLS-1$ + this.bind("compiler.copyright") //$NON-NLS-1$ + })); + this.logger.flush(); +} +private void initRootModules(LookupEnvironment environment, FileSystem fileSystem) { + Map map = new HashMap<>(); + for (String m : this.rootModules) { + ModuleBinding mod = environment.getModule(m.toCharArray()); + if (mod == null) { + throw new IllegalArgumentException(this.bind("configure.invalidModuleName", m)); //$NON-NLS-1$ + } + PackageBinding[] exports = mod.getExports(); + for (PackageBinding packageBinding : exports) { + String qName = CharOperation.toString(packageBinding.compoundName); + String existing = map.get(qName); + if (existing != null) { + throw new IllegalArgumentException(this.bind("configure.packageConflict", new String[] {qName, existing, m})); //$NON-NLS-1$ + // report an error and bail out + } + map.put(qName, m); + } + } + if (this.limitedModules != null) { + for (String m : this.limitedModules) { + ModuleBinding mod = environment.getModule(m.toCharArray()); + if (mod == null) { + throw new IllegalArgumentException(this.bind("configure.invalidModuleName", m)); //$NON-NLS-1$ + } + } + } + environment.moduleVersion = this.moduleVersion; +} +private ReferenceBinding[] processClassNames(LookupEnvironment environment) { + // check for .class file presence in case of apt processing + int length = this.classNames.length; + ReferenceBinding[] referenceBindings = new ReferenceBinding[length]; + ModuleBinding[] modules = new ModuleBinding[length]; + Set modSet = new HashSet<>(); + String[] typeNames = new String[length]; + if (this.complianceLevel <= ClassFileConstants.JDK1_8) { + typeNames = this.classNames; + } else { + for (int i = 0; i < length; i++) { + String currentName = this.classNames[i]; + int idx = currentName.indexOf('/'); + ModuleBinding mod = null; + if (idx > 0) { + String m = currentName.substring(0, idx); + mod = environment.getModule(m.toCharArray()); + if (mod == null) { + throw new IllegalArgumentException(this.bind("configure.invalidModuleName", m)); //$NON-NLS-1$ + } + modules[i] = mod; + modSet.add(mod); + currentName = currentName.substring(idx + 1); + } + typeNames[i] = currentName; + } + } + + for (int i = 0; i < length; i++) { + char[][] compoundName = null; + String cls = typeNames[i]; + if (cls.indexOf('.') != -1) { + // consider names with '.' as fully qualified names + char[] typeName = cls.toCharArray(); + compoundName = CharOperation.splitOn('.', typeName); + } else { + compoundName = new char[][] { cls.toCharArray() }; + } + ModuleBinding mod = modules[i]; + ReferenceBinding type = mod != null ? environment.getType(compoundName, mod) : environment.getType(compoundName); + if (type != null && type.isValidBinding()) { + if (type.isBinaryBinding()) { + referenceBindings[i] = type; + type.superclass(); + } + } else { + throw new IllegalArgumentException( + this.bind("configure.invalidClassName", this.classNames[i]));//$NON-NLS-1$ + } + } + return referenceBindings; +} +private ArrayList processModulePathEntries(String arg) { + ArrayList paths = new ArrayList<>(); + if (arg == null) + return paths; + StringTokenizer tokenizer = new StringTokenizer(arg, File.pathSeparator, false); + while (tokenizer.hasMoreTokens()) { + paths.add(tokenizer.nextToken()); + } + return paths; +} +/* + * External API + */ +public void processPathEntries(final int defaultSize, final ArrayList paths, + final String currentPath, String customEncoding, boolean isSourceOnly, + boolean rejectDestinationPathOnJars) { + String currentClasspathName = null; + String currentDestinationPath = null; + ArrayList currentRuleSpecs = new ArrayList<>(defaultSize); + StringTokenizer tokenizer = new StringTokenizer(currentPath, + File.pathSeparator + "[]", true); //$NON-NLS-1$ + ArrayList tokens = new ArrayList<>(); + while (tokenizer.hasMoreTokens()) { + tokens.add(tokenizer.nextToken()); + } + // state machine + final int start = 0; + final int readyToClose = 1; + // 'path' 'path1[rule];path2' + final int readyToCloseEndingWithRules = 2; + // 'path[rule]' 'path1;path2[rule]' + final int readyToCloseOrOtherEntry = 3; + // 'path[rule];' 'path;' 'path1;path2;' + final int rulesNeedAnotherRule = 4; + // 'path[rule1;' + final int rulesStart = 5; + // 'path[' 'path1;path2[' + final int rulesReadyToClose = 6; + // 'path[rule' 'path[rule1;rule2' + final int destinationPathReadyToClose = 7; + // 'path[-d bin' + final int readyToCloseEndingWithDestinationPath = 8; + // 'path[-d bin]' 'path[rule][-d bin]' + final int destinationPathStart = 9; + // 'path[rule][' + final int bracketOpened = 10; + // '.*[.*' + final int bracketClosed = 11; + // '.*([.*])+' + + final int error = 99; + int state = start; + String token = null; + int cursor = 0, tokensNb = tokens.size(), bracket = -1; + while (cursor < tokensNb && state != error) { + token = tokens.get(cursor++); + if (token.equals(File.pathSeparator)) { + switch (state) { + case start: + case readyToCloseOrOtherEntry: + case bracketOpened: + break; + case readyToClose: + case readyToCloseEndingWithRules: + case readyToCloseEndingWithDestinationPath: + state = readyToCloseOrOtherEntry; + addNewEntry(paths, currentClasspathName, currentRuleSpecs, + customEncoding, currentDestinationPath, isSourceOnly, + rejectDestinationPathOnJars); + currentRuleSpecs.clear(); + break; + case rulesReadyToClose: + state = rulesNeedAnotherRule; + break; + case destinationPathReadyToClose: + throw new IllegalArgumentException( + this.bind("configure.incorrectDestinationPathEntry", //$NON-NLS-1$ + currentPath)); + case bracketClosed: + cursor = bracket + 1; + state = rulesStart; + break; + default: + state = error; + } + } else if (token.equals("[")) { //$NON-NLS-1$ + switch (state) { + case start: + currentClasspathName = ""; //$NON-NLS-1$ + //$FALL-THROUGH$ + case readyToClose: + bracket = cursor - 1; + //$FALL-THROUGH$ + case bracketClosed: + state = bracketOpened; + break; + case readyToCloseEndingWithRules: + state = destinationPathStart; + break; + case readyToCloseEndingWithDestinationPath: + state = rulesStart; + break; + case bracketOpened: + default: + state = error; + } + } else if (token.equals("]")) { //$NON-NLS-1$ + switch (state) { + case rulesReadyToClose: + state = readyToCloseEndingWithRules; + break; + case destinationPathReadyToClose: + state = readyToCloseEndingWithDestinationPath; + break; + case bracketOpened: + state = bracketClosed; + break; + case bracketClosed: + default: + state = error; + } + } else { + // regular word + switch (state) { + case start: + case readyToCloseOrOtherEntry: + state = readyToClose; + currentClasspathName = token; + break; + case rulesStart: + if (token.startsWith("-d ")) { //$NON-NLS-1$ + if (currentDestinationPath != null) { + throw new IllegalArgumentException( + this.bind("configure.duplicateDestinationPathEntry", //$NON-NLS-1$ + currentPath)); + } + currentDestinationPath = token.substring(3).trim(); + state = destinationPathReadyToClose; + break; + } // else we proceed with a rule + //$FALL-THROUGH$ + case rulesNeedAnotherRule: + if (currentDestinationPath != null) { + throw new IllegalArgumentException( + this.bind("configure.accessRuleAfterDestinationPath", //$NON-NLS-1$ + currentPath)); + } + state = rulesReadyToClose; + currentRuleSpecs.add(token); + break; + case destinationPathStart: + if (!token.startsWith("-d ")) { //$NON-NLS-1$ + state = error; + } else { + currentDestinationPath = token.substring(3).trim(); + state = destinationPathReadyToClose; + } + break; + case bracketClosed: + for (int i = bracket; i < cursor ; i++) { + currentClasspathName += tokens.get(i); + } + state = readyToClose; + break; + case bracketOpened: + break; + default: + state = error; + } + } + if (state == bracketClosed && cursor == tokensNb) { + cursor = bracket + 1; + state = rulesStart; + } + } + switch(state) { + case readyToCloseOrOtherEntry: + break; + case readyToClose: + case readyToCloseEndingWithRules: + case readyToCloseEndingWithDestinationPath: + addNewEntry(paths, currentClasspathName, currentRuleSpecs, + customEncoding, currentDestinationPath, isSourceOnly, + rejectDestinationPathOnJars); + break; + case bracketOpened: + case bracketClosed: + default : + // we go on anyway + if (currentPath.length() != 0) { + addPendingErrors(this.bind("configure.incorrectClasspath", currentPath));//$NON-NLS-1$ + } + } +} + +private int processPaths(String[] args, int index, String currentArg, ArrayList paths) { + int localIndex = index; + int count = 0; + for (int i = 0, max = currentArg.length(); i < max; i++) { + switch(currentArg.charAt(i)) { + case '[' : + count++; + break; + case ']' : + count--; + break; + } + } + if (count == 0) { + paths.add(currentArg); + } else if (count > 1) { + throw new IllegalArgumentException( + this.bind("configure.unexpectedBracket", //$NON-NLS-1$ + currentArg)); + } else { + StringBuilder currentPath = new StringBuilder(currentArg); + while (true) { + if (localIndex >= args.length) { + throw new IllegalArgumentException( + this.bind("configure.unexpectedBracket", //$NON-NLS-1$ + currentArg)); + } + localIndex++; + String nextArg = args[localIndex]; + for (int i = 0, max = nextArg.length(); i < max; i++) { + switch(nextArg.charAt(i)) { + case '[' : + if (count > 1) { + throw new IllegalArgumentException( + this.bind("configure.unexpectedBracket", //$NON-NLS-1$ + nextArg)); + } + count++; + break; + case ']' : + count--; + break; + } + } + if (count == 0) { + currentPath.append(' '); + currentPath.append(nextArg); + paths.add(currentPath.toString()); + return localIndex - index; + } else if (count < 0) { + throw new IllegalArgumentException( + this.bind("configure.unexpectedBracket", //$NON-NLS-1$ + nextArg)); + } else { + currentPath.append(' '); + currentPath.append(nextArg); + } + } + + } + return localIndex - index; +} +private int processPaths(String[] args, int index, String currentArg, String[] paths) { + int localIndex = index; + int count = 0; + for (int i = 0, max = currentArg.length(); i < max; i++) { + switch(currentArg.charAt(i)) { + case '[' : + count++; + break; + case ']' : + count--; + break; + } + } + if (count == 0) { + paths[0] = currentArg; + } else { + StringBuilder currentPath = new StringBuilder(currentArg); + while (true) { + localIndex++; + if (localIndex >= args.length) { + throw new IllegalArgumentException( + this.bind("configure.unexpectedBracket", //$NON-NLS-1$ + currentArg)); + } + String nextArg = args[localIndex]; + for (int i = 0, max = nextArg.length(); i < max; i++) { + switch(nextArg.charAt(i)) { + case '[' : + if (count > 1) { + throw new IllegalArgumentException( + this.bind("configure.unexpectedBracket", //$NON-NLS-1$ + currentArg)); + } + count++; + break; + case ']' : + count--; + break; + } + } + if (count == 0) { + currentPath.append(' '); + currentPath.append(nextArg); + paths[0] = currentPath.toString(); + return localIndex - index; + } else if (count < 0) { + throw new IllegalArgumentException( + this.bind("configure.unexpectedBracket", //$NON-NLS-1$ + currentArg)); + } else { + currentPath.append(' '); + currentPath.append(nextArg); + } + } + + } + return localIndex - index; +} +/** + * Creates a NLS catalog for the given locale. + */ +public void relocalize() { + relocalize(Locale.getDefault()); +} + +private void relocalize(Locale locale) { + this.compilerLocale = locale; + try { + this.bundle = ResourceBundleFactory.getBundle(locale); + } catch(MissingResourceException e) { + System.out.println("Missing resource : " + Main.bundleName.replace('.', '/') + ".properties for locale " + locale); //$NON-NLS-1$//$NON-NLS-2$ + throw e; + } +} +/* + * External API + */ +public void setDestinationPath(String dest) { + this.destinationPath = dest; +} +/* + * External API + */ +public void setLocale(Locale locale) { + relocalize(locale); +} +/* + * External API + */ +protected void setPaths(ArrayList bootclasspaths, + String sourcepathClasspathArg, + ArrayList sourcepathClasspaths, + ArrayList classpaths, + String modulePath, + String moduleSourcepath, + ArrayList extdirsClasspaths, + ArrayList endorsedDirClasspaths, + String customEncoding) { + + if (this.complianceLevel == 0) { + String version = this.options.get(CompilerOptions.OPTION_Compliance); + this.complianceLevel = CompilerOptions.versionToJdkLevel(version); + } + // process bootclasspath, classpath and sourcepaths + ArrayList allPaths = null; + long jdkLevel = validateClasspathOptions(bootclasspaths, endorsedDirClasspaths, extdirsClasspaths); + + if (this.releaseVersion != null && this.complianceLevel < jdkLevel) { + // TODO: Revisit for access rules + allPaths = new ArrayList(); + allPaths.add( + FileSystem.getOlderSystemRelease(this.javaHomeCache.getAbsolutePath(), this.releaseVersion, null)); + } else { + allPaths = handleBootclasspath(bootclasspaths, customEncoding); + } + + List cp = handleClasspath(classpaths, customEncoding); + + List mp = handleModulepath(modulePath); + + List msp = handleModuleSourcepath(moduleSourcepath); + + ArrayList sourcepaths = new ArrayList<>(); + if (sourcepathClasspathArg != null) { + processPathEntries(DEFAULT_SIZE_CLASSPATH, sourcepaths, + sourcepathClasspathArg, customEncoding, true, false); + } + + /* + * Feed endorsedDirClasspath according to: + * - -extdirs first if present; + * - else java.ext.dirs if defined; + * - else default extensions directory for the platform. + */ + List extdirs = handleExtdirs(extdirsClasspaths); + + List endorsed = handleEndorseddirs(endorsedDirClasspaths); + + /* + * Concatenate classpath entries + * We put the bootclasspath at the beginning of the classpath + * entries, followed by the extension libraries, followed by + * the sourcepath followed by the classpath. All classpath + * entries are searched for both sources and binaries except + * the sourcepath entries which are searched for sources only. + */ + allPaths.addAll(0, endorsed); + allPaths.addAll(extdirs); + allPaths.addAll(sourcepaths); + allPaths.addAll(cp); + allPaths.addAll(mp); + allPaths.addAll(msp); + allPaths = FileSystem.ClasspathNormalizer.normalize(allPaths); + this.checkedClasspaths = new FileSystem.Classpath[allPaths.size()]; + allPaths.toArray(this.checkedClasspaths); + this.logger.logClasspath(this.checkedClasspaths); + + if (this.annotationPaths != null && CompilerOptions.ENABLED.equals(this.options.get(CompilerOptions.OPTION_AnnotationBasedNullAnalysis))) { + for (FileSystem.Classpath c : this.checkedClasspaths) { + if (c instanceof ClasspathJar) + ((ClasspathJar) c).annotationPaths = this.annotationPaths; + else if (c instanceof ClasspathJrt) + ((ClasspathJrt) c).annotationPaths = this.annotationPaths; + } + } +} +public final static boolean shouldIgnoreOptionalProblems(char[][] folderNames, char[] fileName) { + if (folderNames == null || fileName == null) { + return false; + } + for (int i = 0, max = folderNames.length; i < max; i++) { + char[] folderName = folderNames[i]; + if (isParentOf(folderName, fileName)) { + return true; + } + } + return false; +} +protected long validateClasspathOptions(ArrayList bootclasspaths, ArrayList endorsedDirClasspaths, ArrayList extdirsClasspaths) { + if (this.complianceLevel > ClassFileConstants.JDK1_8) { + if (bootclasspaths != null && bootclasspaths.size() > 0) + throw new IllegalArgumentException( + this.bind("configure.unsupportedOption", "-bootclasspath")); //$NON-NLS-1$ //$NON-NLS-2$ + if (extdirsClasspaths != null && extdirsClasspaths.size() > 0) + throw new IllegalArgumentException( + this.bind("configure.unsupportedOption", "-extdirs")); //$NON-NLS-1$ //$NON-NLS-2$ + if (endorsedDirClasspaths != null && endorsedDirClasspaths.size() > 0) + throw new IllegalArgumentException( + this.bind("configure.unsupportedOption", "-endorseddirs")); //$NON-NLS-1$ //$NON-NLS-2$ + } + long jdkLevel = Util.getJDKLevel(getJavaHome()); + if (jdkLevel < ClassFileConstants.JDK9 && this.releaseVersion != null) { + throw new IllegalArgumentException( + this.bind("configure.unsupportedReleaseOption")); //$NON-NLS-1$ + } + return jdkLevel; +} +protected void validateOptions(boolean didSpecifyCompliance) { + if (didSpecifyCompliance) { + String version = this.options.get(CompilerOptions.OPTION_Compliance); + if (this.releaseVersion != null) { + throw new IllegalArgumentException( + this.bind("configure.unsupportedWithRelease", version));//$NON-NLS-1$ + } + if (CompilerOptions.VERSION_1_3.equals(version)) { + if (!this.didSpecifySource) this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1); + } else if (CompilerOptions.VERSION_1_4.equals(version)) { + if (this.didSpecifySource) { + Object source = this.options.get(CompilerOptions.OPTION_Source); + if (CompilerOptions.VERSION_1_3.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2); + } else if (CompilerOptions.VERSION_1_4.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + } + } else { + this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_2); + } + } else if (CompilerOptions.VERSION_1_5.equals(version)) { + if (this.didSpecifySource) { + Object source = this.options.get(CompilerOptions.OPTION_Source); + if (CompilerOptions.VERSION_1_3.equals(source) + || CompilerOptions.VERSION_1_4.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + } else if (CompilerOptions.VERSION_1_5.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + } + } else { + this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + } + } else if (CompilerOptions.VERSION_1_6.equals(version)) { + if (this.didSpecifySource) { + Object source = this.options.get(CompilerOptions.OPTION_Source); + if (CompilerOptions.VERSION_1_3.equals(source) + || CompilerOptions.VERSION_1_4.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + } else if (CompilerOptions.VERSION_1_5.equals(source) + || CompilerOptions.VERSION_1_6.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + } + } else { + this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + } + } else if (CompilerOptions.VERSION_1_7.equals(version)) { + if (this.didSpecifySource) { + Object source = this.options.get(CompilerOptions.OPTION_Source); + if (CompilerOptions.VERSION_1_3.equals(source) + || CompilerOptions.VERSION_1_4.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + } else if (CompilerOptions.VERSION_1_5.equals(source) + || CompilerOptions.VERSION_1_6.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + } else if (CompilerOptions.VERSION_1_7.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); + } + } else { + this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_7); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); + } + } else if (CompilerOptions.VERSION_1_8.equals(version)) { + if (this.didSpecifySource) { + Object source = this.options.get(CompilerOptions.OPTION_Source); + if (CompilerOptions.VERSION_1_3.equals(source) + || CompilerOptions.VERSION_1_4.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + } else if (CompilerOptions.VERSION_1_5.equals(source) + || CompilerOptions.VERSION_1_6.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + } else if (CompilerOptions.VERSION_1_7.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); + } else if (CompilerOptions.VERSION_1_8.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + } + } else { + this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + } + } else if (CompilerOptions.VERSION_9.equals(version)) { + if (this.didSpecifySource) { + Object source = this.options.get(CompilerOptions.OPTION_Source); + if (CompilerOptions.VERSION_1_3.equals(source) + || CompilerOptions.VERSION_1_4.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + } else if (CompilerOptions.VERSION_1_5.equals(source) + || CompilerOptions.VERSION_1_6.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + } else if (CompilerOptions.VERSION_1_7.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); + } else if (CompilerOptions.VERSION_1_8.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + } else if (CompilerOptions.VERSION_9.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); + } + } else { + this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_9); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); + } + } else if (CompilerOptions.VERSION_10.equals(version)) { + if (this.didSpecifySource) { + Object source = this.options.get(CompilerOptions.OPTION_Source); + if (CompilerOptions.VERSION_1_3.equals(source) + || CompilerOptions.VERSION_1_4.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + } else if (CompilerOptions.VERSION_1_5.equals(source) + || CompilerOptions.VERSION_1_6.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + } else if (CompilerOptions.VERSION_1_7.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); + } else if (CompilerOptions.VERSION_1_8.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + } else if (CompilerOptions.VERSION_9.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); + } else if (CompilerOptions.VERSION_10.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); + } + } else { + this.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_10); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); + } + } else { + if (!this.didSpecifyTarget) { + if (this.didSpecifySource) { + String source = this.options.get(CompilerOptions.OPTION_Source); + if (CompilerOptions.VERSION_1_3.equals(source) + || CompilerOptions.VERSION_1_4.equals(source)) { + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + } else if (CompilerOptions.VERSION_1_5.equals(source) + || CompilerOptions.VERSION_1_6.equals(source)) { + this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + } else { + // 1.3 is the lowest version that can be specified as -source + // The following check will ensure '0' is ignored. + if (CompilerOptions.versionToJdkLevel(source) >= ClassFileConstants.JDK1_7) + this.options.put(CompilerOptions.OPTION_TargetPlatform, source); + } + } else { + if (CompilerOptions.versionToJdkLevel(version) > ClassFileConstants.JDK10) { + this.options.put(CompilerOptions.OPTION_Source, version); + this.options.put(CompilerOptions.OPTION_TargetPlatform, version); + } + } + } + } + + } else if (this.didSpecifySource) { + String version = this.options.get(CompilerOptions.OPTION_Source); + // default is source 1.3 target 1.2 and compliance 1.4 + if (CompilerOptions.VERSION_1_4.equals(version)) { + if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4); + } else if (CompilerOptions.VERSION_1_5.equals(version)) { + if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5); + } else if (CompilerOptions.VERSION_1_6.equals(version)) { + if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_6); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6); + } else if (CompilerOptions.VERSION_1_7.equals(version)) { + if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_7); + } else if (CompilerOptions.VERSION_1_8.equals(version)) { + if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + } else if (CompilerOptions.VERSION_9.equals(version)) { + if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_9); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_9); + } else if (CompilerOptions.VERSION_10.equals(version)) { + if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_10); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_10); + } else { + if (CompilerOptions.versionToJdkLevel(version) > ClassFileConstants.JDK10) { + if (!didSpecifyCompliance) this.options.put(CompilerOptions.OPTION_Compliance, version); + if (!this.didSpecifyTarget) this.options.put(CompilerOptions.OPTION_TargetPlatform, version); + } + } + } + + final String sourceVersion = this.options.get(CompilerOptions.OPTION_Source); + if (this.complianceLevel == 0) { + final String compliance = this.options.get(CompilerOptions.OPTION_Compliance); + this.complianceLevel = CompilerOptions.versionToJdkLevel(compliance); + } + if (sourceVersion.equals(CompilerOptions.VERSION_10) + && this.complianceLevel < ClassFileConstants.JDK10) { + // compliance must be 10 if source is 10 + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForSource", this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_10)); //$NON-NLS-1$ + } else if (sourceVersion.equals(CompilerOptions.VERSION_9) + && this.complianceLevel < ClassFileConstants.JDK9) { + // compliance must be 9 if source is 9 + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForSource", this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_9)); //$NON-NLS-1$ + } else if (sourceVersion.equals(CompilerOptions.VERSION_1_8) + && this.complianceLevel < ClassFileConstants.JDK1_8) { + // compliance must be 1.8 if source is 1.8 + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForSource", this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_8)); //$NON-NLS-1$ + } else if (sourceVersion.equals(CompilerOptions.VERSION_1_7) + && this.complianceLevel < ClassFileConstants.JDK1_7) { + // compliance must be 1.7 if source is 1.7 + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForSource", this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_7)); //$NON-NLS-1$ + } else if (sourceVersion.equals(CompilerOptions.VERSION_1_6) + && this.complianceLevel < ClassFileConstants.JDK1_6) { + // compliance must be 1.6 if source is 1.6 + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForSource", this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_6)); //$NON-NLS-1$ + } else if (sourceVersion.equals(CompilerOptions.VERSION_1_5) + && this.complianceLevel < ClassFileConstants.JDK1_5) { + // compliance must be 1.5 if source is 1.5 + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForSource", this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_5)); //$NON-NLS-1$ + } else if (sourceVersion.equals(CompilerOptions.VERSION_1_4) + && this.complianceLevel < ClassFileConstants.JDK1_4) { + // compliance must be 1.4 if source is 1.4 + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForSource", this.options.get(CompilerOptions.OPTION_Compliance), CompilerOptions.VERSION_1_4)); //$NON-NLS-1$ + } else { + long ver = CompilerOptions.versionToJdkLevel(sourceVersion); + if(this.complianceLevel < ver) + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForSource", this.options.get(CompilerOptions.OPTION_Compliance), sourceVersion)); //$NON-NLS-1$ + } + if (this.enablePreview && this.complianceLevel != ClassFileConstants.getLatestJDKLevel()) { + throw new IllegalArgumentException(this.bind("configure.unsupportedPreview")); //$NON-NLS-1$ + } + + // check and set compliance/source/target compatibilities + if (this.didSpecifyTarget) { + final String targetVersion = this.options.get(CompilerOptions.OPTION_TargetPlatform); + // tolerate jsr14 target + if (CompilerOptions.VERSION_JSR14.equals(targetVersion)) { + // expecting source >= 1.5 + if (CompilerOptions.versionToJdkLevel(sourceVersion) < ClassFileConstants.JDK1_5) { + throw new IllegalArgumentException(this.bind("configure.incompatibleTargetForGenericSource", targetVersion, sourceVersion)); //$NON-NLS-1$ + } + } else if (CompilerOptions.VERSION_CLDC1_1.equals(targetVersion)) { + if (this.didSpecifySource && CompilerOptions.versionToJdkLevel(sourceVersion) >= ClassFileConstants.JDK1_4) { + throw new IllegalArgumentException(this.bind("configure.incompatibleSourceForCldcTarget", targetVersion, sourceVersion)); //$NON-NLS-1$ + } + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForCldcTarget", targetVersion, sourceVersion)); //$NON-NLS-1$ + } + } else { + // target must be 1.8 if source is 1.8 + if (CompilerOptions.versionToJdkLevel(sourceVersion) >= ClassFileConstants.JDK1_8 + && CompilerOptions.versionToJdkLevel(targetVersion) < ClassFileConstants.JDK1_8){ + throw new IllegalArgumentException(this.bind("configure.incompatibleTargetForSource", targetVersion, CompilerOptions.VERSION_1_8)); //$NON-NLS-1$ + } + // target must be 1.7 if source is 1.7 + if (CompilerOptions.versionToJdkLevel(sourceVersion) >= ClassFileConstants.JDK1_7 + && CompilerOptions.versionToJdkLevel(targetVersion) < ClassFileConstants.JDK1_7){ + throw new IllegalArgumentException(this.bind("configure.incompatibleTargetForSource", targetVersion, CompilerOptions.VERSION_1_7)); //$NON-NLS-1$ + } + // target must be 1.6 if source is 1.6 + if (CompilerOptions.versionToJdkLevel(sourceVersion) >= ClassFileConstants.JDK1_6 + && CompilerOptions.versionToJdkLevel(targetVersion) < ClassFileConstants.JDK1_6){ + throw new IllegalArgumentException(this.bind("configure.incompatibleTargetForSource", targetVersion, CompilerOptions.VERSION_1_6)); //$NON-NLS-1$ + } + // target must be 1.5 if source is 1.5 + if (CompilerOptions.versionToJdkLevel(sourceVersion) >= ClassFileConstants.JDK1_5 + && CompilerOptions.versionToJdkLevel(targetVersion) < ClassFileConstants.JDK1_5){ + throw new IllegalArgumentException(this.bind("configure.incompatibleTargetForSource", targetVersion, CompilerOptions.VERSION_1_5)); //$NON-NLS-1$ + } + // target must be 1.4 if source is 1.4 + if (CompilerOptions.versionToJdkLevel(sourceVersion) >= ClassFileConstants.JDK1_4 + && CompilerOptions.versionToJdkLevel(targetVersion) < ClassFileConstants.JDK1_4){ + throw new IllegalArgumentException(this.bind("configure.incompatibleTargetForSource", targetVersion, CompilerOptions.VERSION_1_4)); //$NON-NLS-1$ + } + // target cannot be greater than compliance level + if (this.complianceLevel < CompilerOptions.versionToJdkLevel(targetVersion)){ + throw new IllegalArgumentException(this.bind("configure.incompatibleComplianceForTarget", this.options.get(CompilerOptions.OPTION_Compliance), targetVersion)); //$NON-NLS-1$ + } + } + } +} +} \ No newline at end of file diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java new file mode 100644 index 0000000000..588f9767fe --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/ModuleFinder.java @@ -0,0 +1,295 @@ +/******************************************************************************* + * Copyright (c) 2016, 2020 IBM Corporation. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jdt.internal.compiler.batch; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; +import java.util.jar.JarFile; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; +import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.env.IModule; +import org.eclipse.jdt.internal.compiler.env.PackageExportImpl; +import org.eclipse.jdt.internal.compiler.env.IModule.IPackageExport; +import org.eclipse.jdt.internal.compiler.parser.Parser; +import org.eclipse.jdt.internal.compiler.util.Util; + +public class ModuleFinder { + + public static List findModules(File f, String destinationPath, Parser parser, Map options, boolean isModulepath, String release) { + List collector = new ArrayList<>(); + scanForModules(destinationPath, parser, options, isModulepath, false, collector, f, release); + return collector; + } + + protected static FileSystem.Classpath findModule(final File file, String destinationPath, Parser parser, + Map options, boolean isModulepath, String release) { + FileSystem.Classpath modulePath = FileSystem.getClasspath(file.getAbsolutePath(), null, !isModulepath, null, + destinationPath == null ? null : (destinationPath + File.separator + file.getName()), options, release); + if (modulePath != null) { + scanForModule(modulePath, file, parser, isModulepath, release); + } + return modulePath; + } + protected static void scanForModules(String destinationPath, Parser parser, Map options, boolean isModulepath, + boolean thisAnAutomodule, List collector, final File file, String release) { + FileSystem.Classpath entry = FileSystem.getClasspath( + file.getAbsolutePath(), + null, + !isModulepath, + null, + destinationPath == null ? null : (destinationPath + File.separator + file.getName()), + options, + release); + if (entry != null) { + IModule module = scanForModule(entry, file, parser, thisAnAutomodule, release); + if (module != null) { + collector.add(entry); + } else { + if (file.isDirectory()) { + File[] files = file.listFiles(); + for (File f : files) { + scanForModules(destinationPath, parser, options, isModulepath, isModulepath, collector, f, release); + } + } + } + } + } + protected static IModule scanForModule(FileSystem.Classpath modulePath, final File file, Parser parser, boolean considerAutoModules, String release) { + IModule module = null; + if (file.isDirectory()) { + String[] list = file.list(new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + if (dir == file && (name.equalsIgnoreCase(IModule.MODULE_INFO_CLASS) + || name.equalsIgnoreCase(IModule.MODULE_INFO_JAVA))) { + return true; + } + return false; + } + }); + if (list.length > 0) { + String fileName = list[0]; + switch (fileName) { + case IModule.MODULE_INFO_CLASS: + module = ModuleFinder.extractModuleFromClass(new File(file, fileName), modulePath); + break; + case IModule.MODULE_INFO_JAVA: + module = ModuleFinder.extractModuleFromSource(new File(file, fileName), parser, modulePath); + if (module == null) + return null; + String modName = new String(module.name()); + if (!modName.equals(file.getName())) { + throw new IllegalArgumentException("module name " + modName + " does not match expected name " + file.getName()); //$NON-NLS-1$ //$NON-NLS-2$ + } + break; + } + } + } else { + String moduleDescPath = getModulePathForArchive(file); + if (moduleDescPath != null) { + module = extractModuleFromArchive(file, modulePath, moduleDescPath, release); + } + } + if (considerAutoModules && module == null && !(modulePath instanceof ClasspathJrt)) { + if (!file.isDirectory()) { + String fileName = getFileName(file); + if (!fileName.isEmpty()) + module = IModule.createAutomatic(fileName, file.isFile(), getManifest(file)); + } + } + if (module != null) + modulePath.acceptModule(module); + return module; + } + private static Manifest getManifest(File file) { + if (getModulePathForArchive(file) == null) + return null; + try (JarFile jar = new JarFile(file)) { + return jar.getManifest(); + } catch (IOException e) { + return null; + } + } + private static String getFileName(File file) { + String name = file.getName(); + int index = name.lastIndexOf('.'); + if (index == -1) + return name; + return name.substring(0, index); + } + /** + * Extracts the single reads clause from the given + * command line option (--add-reads). The result is a String[] with two + * element, first being the source module and second being the target module. + * The expected format is: + * --add-reads = + * @param option + * @return a String[] with source and target module of the "reads" clause. + */ + protected static String[] extractAddonRead(String option) { + StringTokenizer tokenizer = new StringTokenizer(option, "="); //$NON-NLS-1$ + String source = null; + String target = null; + if (tokenizer.hasMoreTokens()) { + source = tokenizer.nextToken(); + } else { + // Handle error + return null; + } + if (tokenizer.hasMoreTokens()) { + target = tokenizer.nextToken(); + } else { + // Handle error + return null; + } + return new String[]{source, target}; + } + /** + * Simple structure representing one --add-exports value. + */ + static class AddExport { + /** the name of the exporting module. */ + public final String sourceModuleName; + /** the export structure */ + public final IModule.IPackageExport export; + public AddExport(String moduleName, IPackageExport export) { + this.sourceModuleName = moduleName; + this.export = export; + } + } + /** + * Parses the --add-exports command line option and returns the package export definitions. + * + *

    + * The expected format is: + *

    + *

    + * {@code + * --add-exports /=(,)* + * } + *

    + * @param option the option to parse + * @return an {@link AddExport} structure. + */ + protected static AddExport extractAddonExport(String option) { + StringTokenizer tokenizer = new StringTokenizer(option, "/"); //$NON-NLS-1$ + String source = null; + String pack = null; + List targets = new ArrayList<>(); + if (tokenizer.hasMoreTokens()) { + source = tokenizer.nextToken("/"); //$NON-NLS-1$ + } else { + // Handle error + return null; + } + if (tokenizer.hasMoreTokens()) { + pack = tokenizer.nextToken("/="); //$NON-NLS-1$ + } else { + // Handle error + return null; + } + while (tokenizer.hasMoreTokens()) { + targets.add(tokenizer.nextToken("=,")); //$NON-NLS-1$ + } + PackageExportImpl export = new PackageExportImpl(); + export.pack = pack.toCharArray(); + export.exportedTo = new char[targets.size()][]; + for(int i = 0; i < export.exportedTo.length; i++) { + export.exportedTo[i] = targets.get(i).toCharArray(); + } + return new AddExport(source, export); + } + + private static String getModulePathForArchive(File file) { + int format = Util.archiveFormat(file.getAbsolutePath()); + if (format == Util.ZIP_FILE) { + return IModule.MODULE_INFO_CLASS; + } else if(format == Util.JMOD_FILE) { + return "classes/" + IModule.MODULE_INFO_CLASS; //$NON-NLS-1$ + } + return null; + } + private static IModule extractModuleFromArchive(File file, Classpath pathEntry, String path, String release) { + ZipFile zipFile = null; + try { + zipFile = new ZipFile(file); + if (release != null) { + String releasePath = "META-INF/versions/" + release + "/" + path; //$NON-NLS-1$ //$NON-NLS-2$ + ZipEntry entry = zipFile.getEntry(releasePath); + if (entry != null) { + path = releasePath; + } + } + ClassFileReader reader = ClassFileReader.read(zipFile, path); + IModule module = getModule(reader); + if (module != null) { + return reader.getModuleDeclaration(); + } + return null; + } catch (ClassFormatException | IOException e) { + // Nothing to be done here + } finally { + if (zipFile != null) { + try { + zipFile.close(); + } catch (IOException e) { + // Nothing much to do here + } + } + } + return null; + } + private static IModule extractModuleFromClass(File classfilePath, Classpath pathEntry) { + ClassFileReader reader; + try { + reader = ClassFileReader.read(classfilePath); + IModule module = getModule(reader); + if (module != null) { + return reader.getModuleDeclaration(); + } + return null; + } catch (ClassFormatException | IOException e) { + e.printStackTrace(); + } + return null; + } + private static IModule getModule(ClassFileReader classfile) { + if (classfile != null) { + return classfile.getModuleDeclaration(); + } + return null; + } + private static IModule extractModuleFromSource(File file, Parser parser, Classpath pathEntry) { + CompilationUnit cu = new CompilationUnit(null, file.getAbsolutePath(), null, pathEntry.getDestinationPath()); + CompilationResult compilationResult = new CompilationResult(cu, 0, 1, 10); + CompilationUnitDeclaration unit = parser.parse(cu, compilationResult); + if (unit.isModuleInfo() && unit.moduleDeclaration != null) { + cu.module = unit.moduleDeclaration.moduleName; + return new BasicModule(unit.moduleDeclaration, pathEntry); + } + return null; + } +} diff --git a/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties new file mode 100644 index 0000000000..6c0343fe92 --- /dev/null +++ b/jdt-patch/e422/org.eclipse.jdt.core/batch/org/eclipse/jdt/internal/compiler/batch/messages.properties @@ -0,0 +1,509 @@ +############################################################################### +# Copyright (c) 2000, 2021 IBM Corporation and others. +# +# This program and the accompanying materials +# are made available under the terms of the Eclipse Public License 2.0 +# which accompanies this distribution, and is available at +# https://www.eclipse.org/legal/epl-2.0/ +# +# SPDX-License-Identifier: EPL-2.0 +# +# Contributors: +# IBM Corporation - initial API and implementation +# Benjamin Muskalla - Contribution for bug 239066 +# Stephan Herrmann - Contributions for +# bug 236385 - [compiler] Warn for potential programming problem if an object is created but not used +# bug 295551 - Add option to automatically promote all warnings to errors +# bug 359721 - [options] add command line option for new warning token "resource" +# bug 365208 - [compiler][batch] command line options for annotation based null analysis +# bug 374605 - Unreasonable warning for enum-based switch statements +# bug 388281 - [compiler][null] inheritance of null annotations as an option +# bug 440687 - [compiler][batch][null] improve command line option for external annotations +# Bug 408815 - [batch][null] Add CLI option for COMPILER_PB_SYNTACTIC_NULL_ANALYSIS_FOR_FIELDS +# Alan Moraes - Contribution for bug 383644 +# Jesper S Moller - Contribution for bug 407297 - [1.8][compiler] Control generation of parameter names by option +############################################################################### +### JavaBatchCompiler messages. + +### compiler +#Format: compiler.name = word1 word2 word3 +compiler.name = Eclipse Compiler for Java(TM) +#Format: compiler.version = (The place holders will be automatically filled. Do not remove or alter it) +compiler.version = bundle_qualifier, bundle_version +compiler.copyright = Copyright IBM Corp 2000, 2020. All rights reserved. + +### progress +progress.compiling = Compiling + +### compile +compile.repetition = [repetition {0}/{1}] +compile.instantTime = [compiled {0} lines in {1} ms: {2} lines/s] +compile.detailedTime = [parse: {0} ms ({1}%), resolve: {2} ms ({3}%), analyze: {4} ms ({5}%), generate: {6} ms ({7}%) ] +compile.ioTime = [i/o: read: {0} ms ({1}%), write: {2} ms ({3}%)] +compile.averageTime = [average, excluding min-max {0} lines in {1} ms: {2} lines/s] +compile.totalTime = [total compilation time: {0}] +compile.oneProblem = 1 problem ({0}) +compile.severalProblemsErrorsOrWarnings = {0} problems ({1}) +compile.severalProblemsErrorsAndWarnings = {0} problems ({1}, {2}) +compile.severalProblems = {0} problems ({1}, {2}, {3}) +compile.oneError = 1 error +compile.severalErrors = {0} errors +compile.oneWarning = 1 warning +compile.severalWarnings = {0} warnings +compile.oneInfo = 1 info +compile.severalInfos = {0} infos +compile.oneClassFileGenerated = [1 .class file generated] +compile.severalClassFilesGenerated = [{0} .class files generated] +compile.failOnWarning = error: warnings found and -failOnWarning specified + +### configure +configure.requiresJDK1.2orAbove = Need to use a JVM >= 1.2 +configure.duplicateLog = duplicate log specification: {0} +configure.duplicateRepeat = duplicate repeat specification: {0} +configure.duplicateMaxProblems = duplicate max problems specification: {0} +configure.duplicateCompliance = duplicate compliance setting specification: {0} +configure.duplicateSource = duplicate source compliance setting specification: {0} +configure.duplicateTarget = duplicate target compliance setting specification: {0} +configure.unsupportedReleaseOption = option --release is supported only when run with JDK 9 or above +configure.unsupportedWithRelease = option {0} is not supported when --release is used +configure.unsupportedReleaseVersion = release version {0} is not supported +configure.source = source level should be in ''1.1''...''1.8'',''9''...''17'' (or ''5.0''..''17.0''): {0} +configure.invalidSystem = invalid location for system libraries: {0} +configure.unsupportedOption = option {0} not supported at compliance level 9 and above +configure.duplicateOutputPath = duplicate output path specification: {0} +configure.duplicateModulePath = duplicate module path specification: {0} +configure.duplicateModuleSourcepath = duplicate source module path specification: {0} +configure.invalidModuleDescriptor = cannot open the module descriptor from {0} +configure.invalidModuleOption = incorrectly formatted option: {0} +configure.duplicateExport = can specify a package in a module only once with --add-export +configure.OneOfModuleOrSourcePath = cannot specify both -source-path and --module-source-path +configure.duplicateBootClasspath = duplicate bootclasspath specification: {0} +configure.duplicateExtDirs = duplicate extdirs specification: {0} +configure.duplicateSourcepath = duplicate sourcepath specification: {0} +configure.invalidDebugOption = invalid debug option: {0} +configure.invalidWarningConfiguration = invalid warning configuration: ''{0}'' +configure.invalidWarning = invalid warning token: ''{0}''. Ignoring warning and compiling +configure.invalidWarningOption = invalid warning option: ''{0}''. Must specify a warning token +configure.targetJDK = target level should be in ''1.1''...''1.8'',''9''...''17'' (or ''5.0''..''17.0'') or cldc1.1: {0} +configure.incompatibleTargetForSource = Target level ''{0}'' is incompatible with source level ''{1}''. A target level ''{1}'' or better is required +configure.incompatibleTargetForGenericSource = Target level ''{0}'' is incompatible with source level ''{1}''. A source level ''1.5'' or better is required +configure.incompatibleComplianceForSource = Compliance level ''{0}'' is incompatible with source level ''{1}''. A compliance level ''{1}'' or better is required +configure.incompatibleComplianceForTarget = Compliance level ''{0}'' is incompatible with target level ''{1}''. A compliance level ''{1}'' or better is required +configure.repetition = repetition must be a positive integer: {0} +configure.maxProblems = max problems must be a positive integer: {0} +configure.invalidNowarnOption = invalid syntax for nowarn option: {0} +configure.unsupportedPreview = Preview of features is supported only at the latest source level + +configure.invalidErrorConfiguration = invalid error configuration: ''{0}'' +configure.invalidError = invalid error token: ''{0}''. Ignoring this error token and compiling +configure.invalidErrorOption = invalid error option: ''{0}''. Must specify an error token + +configure.invalidInfoConfiguration = invalid info configuration: ''{0}'' +configure.invalidInfo = invalid info token: ''{0}''. Ignoring this info token and compiling +configure.invalidInfoOption = invalid info option: ''{0}''. Must specify an info token + +configure.notOnModuleSourcePath = ''{0}'' does not belong to a module on the module source path +configure.no.ModuleDescriptorVersionparse = Could not invoke method java.lang.module.ModuleDescriptor.Version.parse(), cannot validate module version. + +## configure.directoryNotExist = directory does not exist: {0} +configure.unrecognizedOption = Unrecognized option : {0} +configure.noClasspath = no classpath defined, using default directory instead +configure.incorrectClasspath = incorrect classpath: {0} +configure.invalidexpansionargumentname = expansion argument file {0} does not exist or cannot be read +configure.cannotOpenLog = cannot open .log file: {0} +configure.cannotOpenLogInvalidEncoding = cannot open .log file: {0}; because UTF-8 is not supported +configure.unexpectedCustomEncoding = unexpected custom encoding specification: {0}[{1}] +configure.unsupportedEncoding = unsupported encoding format: {0} +configure.duplicateDefaultEncoding = duplicate default encoding format specification: {0} +configure.invalidTaskTag ={0} is an invalid task tag +configure.incorrectExtDirsEntry = incorrect ext dir entry; {0} must be a directory +configure.incorrectEndorsedDirsEntry = incorrect endorsed dir entry; {0} must be a directory +configure.duplicateEndorsedDirs = duplicate endorseddirs specification: {0} +configure.missingDestinationPath = destination path must be provided with module source path +configure.incorrectDestinationPathEntry = incorrect destination path entry: {0} +configure.unexpectedBracket = unexpected bracket: {0} +configure.unexpectedDestinationPathEntry = unexpected destination path entry in {0} option +configure.unexpectedDestinationPathEntryFile = unexpected destination path entry for file: {0} +configure.accessRuleAfterDestinationPath = access rules cannot follow destination path entries: {0} +configure.duplicateDestinationPathEntry = duplicate destination path entry in {0} option +configure.invalidClassName = invalid class name: {0} +configure.invalidModuleName = invalid module name: {0} +configure.packageConflict = The package {0} is accessible from more than one module: {1}, {2} +configure.unavailableAPT = Unable to load annotation processing manager {0} from classpath. +configure.incorrectVMVersionforAPT = Annotation processing got disabled, since it requires a 1.6 compliant JVM +configure.incompatibleSourceForCldcTarget=Target level ''{0}'' is incompatible with source level ''{1}''. A source level ''1.3'' or lower is required +configure.incompatibleComplianceForCldcTarget=Target level ''{0}'' is incompatible with compliance level ''{1}''. A compliance level ''1.4''or lower is required +configure.invalidClasspathSection = invalid Class-Path header in manifest of jar file: {0} +configure.multipleClasspathSections = multiple Class-Path headers in manifest of jar file: {0} +configure.missingwarningspropertiesfile=properties file {0} does not exist +configure.ioexceptionwarningspropertiesfile=An IOException occurred while reading the properties file {0} +configure.multipleencodings=Multiple encoding specified: {1}. The default encoding has been set to {0} +configure.differentencodings=Found encoding {0}. Different encodings were specified: {1} +configure.differentencoding=Found encoding {0}. A different encoding was specified: {1} + +### null annotations +configure.invalidNullAnnot = Token {0} is not in the expected format "nullAnnot( | | )" +configure.missingAnnotationPath = Missing argument to -annotationpath at ''{0}'' + +### requestor +requestor.error = {0}. ERROR in {1} +requestor.warning = {0}. WARNING in {1} +requestor.info = {0}. INFO in {1} +requestor.extraerror = {0}. ERROR: +requestor.extrawarning = {0}. WARNING: +requestor.extrainfo = {0}. INFO: +requestor.notRetrieveErrorMessage = Cannot retrieve the error message for {0} +requestor.noFileNameSpecified = (original file name is not available) + +### EMACS STYLE +output.emacs.error=error +output.emacs.warning=warning +output.emacs.info=info + +### unit +unit.more = File {0} is specified more than once +unit.missing = File {0} is missing + +### output +output.noClassFileCreated = No .class file created for file {1} in {0} because of an IOException: {2} + +### miscellaneous +misc.version = {0} {1}, {2} +misc.usage = {1} {2}\n\ +{3}\n\ +\ \n\ +\ Usage: \n\ +\ If directories are specified, then their source contents are compiled.\n\ +\ Possible options are listed below. Options enabled by default are prefixed\n\ +\ with ''+''.\n\ +\ \n\ +\ Classpath options:\n\ +\ -cp -classpath \n\ +\ specify location for application classes and sources.\n\ +\ Each directory or file can specify access rules for\n\ +\ types between ''['' and '']'' (e.g. [-X] to forbid\n\ +\ access to type X, [~X] to discourage access to type X,\n\ +\ [+p/X{0}-p/*] to forbid access to all types in package p\n\ +\ but allow access to p/X)\n\ +\ -bootclasspath \n\ +\ specify location for system classes. Each directory or\n\ +\ file can specify access rules for types between ''[''\n\ +\ and '']''\n\ +\ -sourcepath \n\ +\ specify location for application sources. Each directory\n\ +\ or file can specify access rules for types between ''[''\n\ +\ and '']''. Each directory can further specify a specific\n\ +\ destination directory using a ''-d'' option between ''[''\n\ +\ and '']''; this overrides the general ''-d'' option.\n\ +\ .class files created from source files contained in a\n\ +\ jar file are put in the user.dir folder in case no\n\ +\ general ''-d'' option is specified. ZIP archives cannot\n\ +\ override the general ''-d'' option\n\ +\ -extdirs \n\ +\ specify location for extension ZIP archives\n\ +\ -endorseddirs \n\ +\ specify location for endorsed ZIP archives\n\ +\ -d destination directory (if omitted, no directory is\n\ +\ created); this option can be overridden per source\n\ +\ directory\n\ +\ -d none generate no .class files\n\ +\ -encoding specify default encoding for all source files. Each\n\ +\ file/directory can override it when suffixed with\n\ +\ ''['''']'' (e.g. X.java[utf8]).\n\ +\ If multiple default encodings are specified, the last\n\ +\ one will be used.\n\ +\ \n\ +\ Module compilation options:\n\ +\ These options are meaningful only in Java 9 environment or later.\n\ +\ --module-source-path \n\ +\ specify where to find source files for multiple modules\n\ +\ -p --module-path \n\ +\ specify where to find application modules\n\ +\ --processor-module-path \n\ +\ specify module path where annotation processors\n\ +\ can be found\n\ +\ --system Override location of system modules\n\ +\ --add-exports /=(,)*\n\ +\ specify additional package exports clauses to the\n\ +\ given modules\n\ +\ --add-reads =(,)*\n\ +\ specify additional modules to be considered as required\n\ +\ by given modules\n\ +\ --add-modules (,)*\n\ +\ specify the additional module names that should be\n\ +\ resolved to be root modules\n\ +\ --limit-modules (,)*\n\ +\ specify the observable module names\n\ +\ --release compile for a specific VM version\n\ +\ \n\ +\ Compliance options:\n\ +\ -1.3 use 1.3 compliance (-source 1.3 -target 1.1)\n\ +\ -1.4 + use 1.4 compliance (-source 1.3 -target 1.2)\n\ +\ -1.5 -5 -5.0 use 1.5 compliance (-source 1.5 -target 1.5)\n\ +\ -1.6 -6 -6.0 use 1.6 compliance (-source 1.6 -target 1.6)\n\ +\ -1.7 -7 -7.0 use 1.7 compliance (-source 1.7 -target 1.7)\n\ +\ -1.8 -8 -8.0 use 1.8 compliance (-source 1.8 -target 1.8)\n\ +\ -1.9 -9 -9.0 use 1.9 compliance (-source 1.9 -target 1.9)\n\ +\ -10 -10.0 use 10 compliance (-source 10 -target 10)\n\ +\ -11 -11.0 use 11 compliance (-source 11 -target 11)\n\ +\ -12 -12.0 use 12 compliance (-source 12 -target 12)\n\ +\ -13 -13.0 use 13 compliance (-source 13 -target 13)\n\ +\ -14 -14.0 use 14 compliance (-source 14 -target 14)\n\ +\ -15 -15.0 use 15 compliance (-source 15 -target 15)\n\ +\ -16 -16.0 use 16 compliance (-source 16 -target 16)\n\ +\ -17 -17.0 use 17 compliance (-source 17 -target 17)\n\ +\ -source set source level: 1.3 to 1.9, 10 to 17\n\ +\ (or 6, 6.0, etc)\n\ +\ -target set classfile target: 1.3 to 1.9, 10 to 17\n\ +\ (or 6, 6.0, etc)\n\ +\ cldc1.1 can also be used to generate the StackMap\n\ +\ attribute\n\ +\ --enable-preview enable support for preview features of the\n\ +\ latest Java release\n\ +\ \n\ +\ Warning options:\n\ +\ -deprecation + deprecation outside deprecated code (equivalent to\n\ +\ -warn:+deprecation)\n\ +\ -nowarn -warn:none disable all warnings\n\ +\ -nowarn:[]\n\ +\ specify directories from which optional problems should\n\ +\ be ignored\n\ +\ -?:warn -help:warn display advanced warning options\n\ +\ \n\ +\ Error options:\n\ +\ -err: convert exactly the listed warnings\n\ +\ to be reported as errors\n\ +\ -err:+ enable additional warnings to be\n\ +\ reported as errors\n\ +\ -err:- disable specific warnings to be\n\ +\ reported as errors\n\ +\ \n\ +\ Info options:\n\ +\ -info: convert exactly the listed warnings\n\ +\ to be reported as infos\n\ +\ -info:+ enable additional warnings to be\n\ +\ reported as infos\n\ +\ -info:- disable specific warnings to be\n\ +\ reported as infos\n\ +\ \n\ +\ Setting warning, error or info options using properties file:\n\ +\ -properties set warnings/errors/info option based on the properties\n\ +\ file contents. This option can be used with -nowarn,\n\ +\ -err:.., -info: or -warn:.. options, but the last one\n\ +\ on the command line sets the options to be used.\n\ +\ \n\ +\ Debug options:\n\ +\ -g[:lines,vars,source] custom debug info\n\ +\ -g:lines,source + both lines table and source debug info\n\ +\ -g all debug info\n\ +\ -g:none no debug info\n\ +\ -preserveAllLocals preserve unused local vars for debug purpose\n\ +\ \n\ +\ Annotation processing options:\n\ +\ These options are meaningful only in a 1.6 environment.\n\ +\ -Akey[=value] options that are passed to annotation processors\n\ +\ -processorpath \n\ +\ specify locations where to find annotation processors.\n\ +\ If this option is not used, the classpath will be\n\ +\ searched for processors\n\ +\ -processor \n\ +\ qualified names of the annotation processors to run.\n\ +\ This bypasses the default annotation discovery process\n\ +\ -proc:only run annotation processors, but do not compile\n\ +\ -proc:none perform compilation but do not run annotation\n\ +\ processors\n\ +\ -s destination directory for generated source files\n\ +\ -XprintProcessorInfo print information about which annotations and elements\n\ +\ a processor is asked to process\n\ +\ -XprintRounds print information about annotation processing rounds\n\ +\ -classNames \n\ +\ qualified names of binary classes to process\n\ +\ \n\ +\ Advanced options:\n\ +\ @ read command line arguments from file\n\ +\ -maxProblems max number of problems per compilation unit (100 by\n\ +\ default)\n\ +\ -log log to a file. If the file extension is ''.xml'', then\n\ +\ the log will be a xml file.\n\ +\ -proceedOnError[:Fatal]\n\ +\ do not stop at first error, dumping class files with\n\ +\ problem methods\n\ +\ With ":Fatal", all optional errors are treated as fatal\n\ +\ -failOnWarning fail compilation if there are warnings\n\ +\ -verbose enable verbose output\n\ +\ -referenceInfo compute reference info\n\ +\ -progress show progress (only in -log mode)\n\ +\ -time display speed information \n\ +\ -noExit do not call System.exit(n) at end of compilation (n==0\n\ +\ if no error)\n\ +\ -repeat repeat compilation process times for perf analysis\n\ +\ -inlineJSR inline JSR bytecode (implicit if target >= 1.5)\n\ +\ -enableJavadoc consider references in javadoc\n\ +\ -parameters generate method parameters attribute (for target >= 1.8)\n\ +\ -genericsignature generate generic signature for lambda expressions\n\ +\ -Xemacs used to enable emacs-style output in the console.\n\ +\ It does not affect the xml log output\n\ +\ -missingNullDefault report missing default nullness annotation\n\ +\ -annotationpath \n\ +\ specify locations where to find external annotations\n\ +\ to support annotation-based null analysis.\n\ +\ The special name CLASSPATH will cause lookup of\n\ +\ external annotations from the classpath and sourcepath.\n\ +\ \n\ +\ -? -help print this help message\n\ +\ -v -version print compiler version\n\ +\ -showversion print compiler version and continue\n\ +\ \n\ +\ Ignored options:\n\ +\ -J